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 - 2023 Intel Corporation
14 #include <linux/delay.h>
15 #include <linux/fips.h>
16 #include <linux/if_ether.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 #include <linux/moduleparam.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/crc32.h>
23 #include <linux/slab.h>
24 #include <linux/export.h>
25 #include <net/mac80211.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
32 #include "fils_aead.h"
34 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
35 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
36 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
37 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
40 #define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2)
41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
44 #define IEEE80211_ASSOC_MAX_TRIES 3
46 static int max_nullfunc_tries = 2;
47 module_param(max_nullfunc_tries, int, 0644);
48 MODULE_PARM_DESC(max_nullfunc_tries,
49 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51 static int max_probe_tries = 5;
52 module_param(max_probe_tries, int, 0644);
53 MODULE_PARM_DESC(max_probe_tries,
54 "Maximum probe tries before disconnecting (reason 4).");
57 * Beacon loss timeout is calculated as N frames times the
58 * advertised beacon interval. This may need to be somewhat
59 * higher than what hardware might detect to account for
60 * delays in the host processing frames. But since we also
61 * probe on beacon miss before declaring the connection lost
62 * default to what we want.
64 static int beacon_loss_count = 7;
65 module_param(beacon_loss_count, int, 0644);
66 MODULE_PARM_DESC(beacon_loss_count,
67 "Number of beacon intervals before we decide beacon was lost.");
70 * Time the connection can be idle before we probe
71 * it to see if we can still talk to the AP.
73 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
75 * Time we wait for a probe response after sending
76 * a probe request because of beacon loss or for
77 * checking the connection still works.
79 static int probe_wait_ms = 500;
80 module_param(probe_wait_ms, int, 0644);
81 MODULE_PARM_DESC(probe_wait_ms,
82 "Maximum time(ms) to wait for probe response"
83 " before disconnecting (reason 4).");
86 * How many Beacon frames need to have been used in average signal strength
87 * before starting to indicate signal change events.
89 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
92 * Extract from the given disabled subchannel bitmap (raw format
93 * from the EHT Operation Element) the bits for the subchannel
94 * we're using right now.
97 ieee80211_extract_dis_subch_bmap(const struct ieee80211_eht_operation *eht_oper,
98 struct cfg80211_chan_def *chandef, u16 bitmap)
100 struct ieee80211_eht_operation_info *info = (void *)eht_oper->optional;
101 struct cfg80211_chan_def ap_chandef = *chandef;
102 u32 ap_center_freq, local_center_freq;
104 int ap_start_freq, local_start_freq;
107 if (!(eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) ||
109 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT))
112 /* set 160/320 supported to get the full AP definition */
113 ieee80211_chandef_eht_oper((const void *)eht_oper->optional,
114 true, true, &ap_chandef);
115 ap_center_freq = ap_chandef.center_freq1;
116 ap_bw = 20 * BIT(u8_get_bits(info->control,
117 IEEE80211_EHT_OPER_CHAN_WIDTH));
118 ap_start_freq = ap_center_freq - ap_bw / 2;
119 local_center_freq = chandef->center_freq1;
120 local_bw = 20 * BIT(ieee80211_chan_width_to_rx_bw(chandef->width));
121 local_start_freq = local_center_freq - local_bw / 2;
122 shift = (local_start_freq - ap_start_freq) / 20;
123 mask = BIT(local_bw / 20) - 1;
125 return (bitmap >> shift) & mask;
129 * Handle the puncturing bitmap, possibly downgrading bandwidth to get a
133 ieee80211_handle_puncturing_bitmap(struct ieee80211_link_data *link,
134 const struct ieee80211_eht_operation *eht_oper,
135 u16 bitmap, u64 *changed)
137 struct cfg80211_chan_def *chandef = &link->conf->chandef;
144 while (chandef->width > NL80211_CHAN_WIDTH_40) {
146 ieee80211_extract_dis_subch_bmap(eht_oper, chandef,
149 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
152 link->u.mgd.conn_flags |=
153 ieee80211_chandef_downgrade(chandef);
154 *changed |= BSS_CHANGED_BANDWIDTH;
157 if (chandef->width <= NL80211_CHAN_WIDTH_40)
160 if (link->conf->eht_puncturing != extracted) {
161 link->conf->eht_puncturing = extracted;
162 *changed |= BSS_CHANGED_EHT_PUNCTURING;
167 * We can have multiple work items (and connection probing)
168 * scheduling this timer, but we need to take care to only
169 * reschedule it when it should fire _earlier_ than it was
170 * asked for before, or if it's not pending right now. This
171 * function ensures that. Note that it then is required to
172 * run this function for all timeouts after the first one
173 * has happened -- the work that runs from this timer will
176 static void run_again(struct ieee80211_sub_if_data *sdata,
177 unsigned long timeout)
179 lockdep_assert_wiphy(sdata->local->hw.wiphy);
181 if (!timer_pending(&sdata->u.mgd.timer) ||
182 time_before(timeout, sdata->u.mgd.timer.expires))
183 mod_timer(&sdata->u.mgd.timer, timeout);
186 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
188 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
191 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
194 mod_timer(&sdata->u.mgd.bcn_mon_timer,
195 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
198 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
200 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
202 if (unlikely(!ifmgd->associated))
205 if (ifmgd->probe_send_count)
206 ifmgd->probe_send_count = 0;
208 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
211 mod_timer(&ifmgd->conn_mon_timer,
212 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
215 static int ecw2cw(int ecw)
217 return (1 << ecw) - 1;
220 static ieee80211_conn_flags_t
221 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
222 struct ieee80211_link_data *link,
223 ieee80211_conn_flags_t conn_flags,
224 struct ieee80211_supported_band *sband,
225 struct ieee80211_channel *channel,
227 const struct ieee80211_ht_operation *ht_oper,
228 const struct ieee80211_vht_operation *vht_oper,
229 const struct ieee80211_he_operation *he_oper,
230 const struct ieee80211_eht_operation *eht_oper,
231 const struct ieee80211_s1g_oper_ie *s1g_oper,
232 struct cfg80211_chan_def *chandef, bool tracking)
234 struct cfg80211_chan_def vht_chandef;
235 struct ieee80211_sta_ht_cap sta_ht_cap;
236 ieee80211_conn_flags_t ret;
239 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
240 chandef->chan = channel;
241 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
242 chandef->center_freq1 = channel->center_freq;
243 chandef->freq1_offset = channel->freq_offset;
245 if (channel->band == NL80211_BAND_6GHZ) {
246 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
249 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
250 ret = IEEE80211_CONN_DISABLE_HT |
251 IEEE80211_CONN_DISABLE_VHT |
252 IEEE80211_CONN_DISABLE_HE |
253 IEEE80211_CONN_DISABLE_EHT;
257 vht_chandef = *chandef;
259 } else if (sband->band == NL80211_BAND_S1GHZ) {
260 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
262 "Missing S1G Operation Element? Trying operating == primary\n");
263 chandef->width = ieee80211_s1g_channel_width(channel);
266 ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
267 IEEE80211_CONN_DISABLE_VHT |
268 IEEE80211_CONN_DISABLE_80P80MHZ |
269 IEEE80211_CONN_DISABLE_160MHZ;
273 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
274 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
276 if (!ht_oper || !sta_ht_cap.ht_supported) {
277 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
278 ret = IEEE80211_CONN_DISABLE_HT |
279 IEEE80211_CONN_DISABLE_VHT |
280 IEEE80211_CONN_DISABLE_HE |
281 IEEE80211_CONN_DISABLE_EHT;
285 chandef->width = NL80211_CHAN_WIDTH_20;
287 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
289 /* check that channel matches the right operating channel */
290 if (!tracking && channel->center_freq != ht_cfreq) {
292 * It's possible that some APs are confused here;
293 * Netgear WNDR3700 sometimes reports 4 higher than
294 * the actual channel in association responses, but
295 * since we look at probe response/beacon data here
299 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
300 channel->center_freq, ht_cfreq,
301 ht_oper->primary_chan, channel->band);
302 ret = IEEE80211_CONN_DISABLE_HT |
303 IEEE80211_CONN_DISABLE_VHT |
304 IEEE80211_CONN_DISABLE_HE |
305 IEEE80211_CONN_DISABLE_EHT;
309 /* check 40 MHz support, if we have it */
310 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
311 ieee80211_chandef_ht_oper(ht_oper, chandef);
313 mlme_dbg(sdata, "40 MHz not supported\n");
314 /* 40 MHz (and 80 MHz) must be supported for VHT */
315 ret = IEEE80211_CONN_DISABLE_VHT;
316 /* also mark 40 MHz disabled */
317 ret |= IEEE80211_CONN_DISABLE_40MHZ;
321 if (!vht_oper || !sband->vht_cap.vht_supported) {
322 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
323 ret = IEEE80211_CONN_DISABLE_VHT;
327 vht_chandef = *chandef;
328 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE) &&
330 (le32_to_cpu(he_oper->he_oper_params) &
331 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
332 struct ieee80211_vht_operation he_oper_vht_cap;
335 * Set only first 3 bytes (other 2 aren't used in
336 * ieee80211_chandef_vht_oper() anyway)
338 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
339 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
341 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
342 &he_oper_vht_cap, ht_oper,
344 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE))
346 "HE AP VHT information is invalid, disabling HE\n");
347 ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
350 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
354 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
356 "AP VHT information is invalid, disabling VHT\n");
357 ret = IEEE80211_CONN_DISABLE_VHT;
361 if (!cfg80211_chandef_valid(&vht_chandef)) {
362 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
364 "AP VHT information is invalid, disabling VHT\n");
365 ret = IEEE80211_CONN_DISABLE_VHT;
369 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
374 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
375 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
377 "AP VHT information doesn't match HT, disabling VHT\n");
378 ret = IEEE80211_CONN_DISABLE_VHT;
382 *chandef = vht_chandef;
385 * handle the case that the EHT operation indicates that it holds EHT
386 * operation information (in case that the channel width differs from
387 * the channel width reported in HT/VHT/HE).
389 if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
390 struct cfg80211_chan_def eht_chandef = *chandef;
392 ieee80211_chandef_eht_oper((const void *)eht_oper->optional,
394 NL80211_CHAN_WIDTH_160,
395 false, &eht_chandef);
397 if (!cfg80211_chandef_valid(&eht_chandef)) {
398 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
400 "AP EHT information is invalid, disabling EHT\n");
401 ret = IEEE80211_CONN_DISABLE_EHT;
405 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
406 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
408 "AP EHT information is incompatible, disabling EHT\n");
409 ret = IEEE80211_CONN_DISABLE_EHT;
413 *chandef = eht_chandef;
420 * When tracking the current AP, don't do any further checks if the
421 * new chandef is identical to the one we're currently using for the
422 * connection. This keeps us from playing ping-pong with regulatory,
423 * without it the following can happen (for example):
424 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
425 * - AP advertises regdom US
426 * - CRDA loads regdom US with 80 MHz prohibited (old database)
427 * - the code below detects an unsupported channel, downgrades, and
428 * we disconnect from the AP in the caller
429 * - disconnect causes CRDA to reload world regdomain and the game
431 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
433 * It seems possible that there are still scenarios with CSA or real
434 * bandwidth changes where a this could happen, but those cases are
435 * less common and wouldn't completely prevent using the AP.
438 cfg80211_chandef_identical(chandef, &link->conf->chandef))
441 /* don't print the message below for VHT mismatch if VHT is disabled */
442 if (ret & IEEE80211_CONN_DISABLE_VHT)
443 vht_chandef = *chandef;
446 * Ignore the DISABLED flag when we're already connected and only
447 * tracking the APs beacon for bandwidth changes - otherwise we
448 * might get disconnected here if we connect to an AP, update our
449 * regulatory information based on the AP's country IE and the
450 * information we have is wrong/outdated and disables the channel
451 * that we're actually using for the connection to the AP.
453 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
455 IEEE80211_CHAN_DISABLED)) {
456 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
457 ret = IEEE80211_CONN_DISABLE_HT |
458 IEEE80211_CONN_DISABLE_VHT |
459 IEEE80211_CONN_DISABLE_HE |
460 IEEE80211_CONN_DISABLE_EHT;
464 ret |= ieee80211_chandef_downgrade(chandef);
467 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
468 IEEE80211_CHAN_NO_HE))
469 ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
471 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
472 IEEE80211_CHAN_NO_EHT))
473 ret |= IEEE80211_CONN_DISABLE_EHT;
475 if (chandef->width != vht_chandef.width && !tracking)
477 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
479 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
483 static int ieee80211_config_bw(struct ieee80211_link_data *link,
484 const struct ieee80211_ht_cap *ht_cap,
485 const struct ieee80211_vht_cap *vht_cap,
486 const struct ieee80211_ht_operation *ht_oper,
487 const struct ieee80211_vht_operation *vht_oper,
488 const struct ieee80211_he_operation *he_oper,
489 const struct ieee80211_eht_operation *eht_oper,
490 const struct ieee80211_s1g_oper_ie *s1g_oper,
491 const u8 *bssid, u64 *changed)
493 struct ieee80211_sub_if_data *sdata = link->sdata;
494 struct ieee80211_local *local = sdata->local;
495 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
496 struct ieee80211_channel *chan = link->conf->chandef.chan;
497 struct ieee80211_supported_band *sband =
498 local->hw.wiphy->bands[chan->band];
499 struct cfg80211_chan_def chandef;
501 ieee80211_conn_flags_t flags;
502 u32 vht_cap_info = 0;
505 /* if HT was/is disabled, don't track any bandwidth changes */
506 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
509 /* don't check VHT if we associated as non-VHT station */
510 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
513 /* don't check HE if we associated as non-HE station */
514 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
515 !ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif)) {
520 /* don't check EHT if we associated as non-EHT station */
521 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
522 !ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif))
526 * if bss configuration changed store the new one -
527 * this may be applicable even if channel is identical
529 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
530 if (link->conf->ht_operation_mode != ht_opmode) {
531 *changed |= BSS_CHANGED_HT;
532 link->conf->ht_operation_mode = ht_opmode;
536 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
538 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
539 flags = ieee80211_determine_chantype(sdata, link,
540 link->u.mgd.conn_flags,
541 sband, chan, vht_cap_info,
544 s1g_oper, &chandef, true);
547 * Downgrade the new channel if we associated with restricted
548 * capabilities. For example, if we associated as a 20 MHz STA
549 * to a 40 MHz AP (due to regulatory, capabilities or config
550 * reasons) then switching to a 40 MHz channel now won't do us
551 * any good -- we couldn't use it with the AP.
553 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
554 chandef.width == NL80211_CHAN_WIDTH_80P80)
555 flags |= ieee80211_chandef_downgrade(&chandef);
556 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
557 chandef.width == NL80211_CHAN_WIDTH_160)
558 flags |= ieee80211_chandef_downgrade(&chandef);
559 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
560 chandef.width > NL80211_CHAN_WIDTH_20)
561 flags |= ieee80211_chandef_downgrade(&chandef);
563 if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
567 "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
568 link->u.mgd.bssid, chandef.chan->center_freq,
569 chandef.chan->freq_offset, chandef.width,
570 chandef.center_freq1, chandef.freq1_offset,
571 chandef.center_freq2);
573 if (flags != (link->u.mgd.conn_flags &
574 (IEEE80211_CONN_DISABLE_HT |
575 IEEE80211_CONN_DISABLE_VHT |
576 IEEE80211_CONN_DISABLE_HE |
577 IEEE80211_CONN_DISABLE_EHT |
578 IEEE80211_CONN_DISABLE_40MHZ |
579 IEEE80211_CONN_DISABLE_80P80MHZ |
580 IEEE80211_CONN_DISABLE_160MHZ |
581 IEEE80211_CONN_DISABLE_320MHZ)) ||
582 !cfg80211_chandef_valid(&chandef)) {
584 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
585 link->u.mgd.bssid, flags, ifmgd->flags);
589 ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
593 "AP %pM changed bandwidth to incompatible one - disconnect\n",
601 /* frame sending functions */
603 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
604 struct sk_buff *skb, u8 ap_ht_param,
605 struct ieee80211_supported_band *sband,
606 struct ieee80211_channel *channel,
607 enum ieee80211_smps_mode smps,
608 ieee80211_conn_flags_t conn_flags)
611 u32 flags = channel->flags;
613 struct ieee80211_sta_ht_cap ht_cap;
615 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
617 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
618 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
620 /* determine capability flags */
623 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
624 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
625 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
626 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
627 cap &= ~IEEE80211_HT_CAP_SGI_40;
630 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
631 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
632 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
633 cap &= ~IEEE80211_HT_CAP_SGI_40;
639 * If 40 MHz was disabled associate as though we weren't
640 * capable of 40 MHz -- some broken APs will never fall
641 * back to trying to transmit in 20 MHz.
643 if (conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
644 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
645 cap &= ~IEEE80211_HT_CAP_SGI_40;
648 /* set SM PS mode properly */
649 cap &= ~IEEE80211_HT_CAP_SM_PS;
651 case IEEE80211_SMPS_AUTOMATIC:
652 case IEEE80211_SMPS_NUM_MODES:
655 case IEEE80211_SMPS_OFF:
656 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
657 IEEE80211_HT_CAP_SM_PS_SHIFT;
659 case IEEE80211_SMPS_STATIC:
660 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
661 IEEE80211_HT_CAP_SM_PS_SHIFT;
663 case IEEE80211_SMPS_DYNAMIC:
664 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
665 IEEE80211_HT_CAP_SM_PS_SHIFT;
669 /* reserve and fill IE */
670 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
671 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
674 /* This function determines vht capability flags for the association
676 * Note - the function returns true to own the MU-MIMO capability
678 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
680 struct ieee80211_supported_band *sband,
681 struct ieee80211_vht_cap *ap_vht_cap,
682 ieee80211_conn_flags_t conn_flags)
684 struct ieee80211_local *local = sdata->local;
687 struct ieee80211_sta_vht_cap vht_cap;
688 u32 mask, ap_bf_sts, our_bf_sts;
689 bool mu_mimo_owner = false;
691 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
693 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
694 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
696 /* determine capability flags */
699 if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
700 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
702 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
703 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
704 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
705 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
708 if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
709 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
710 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
714 * Some APs apparently get confused if our capabilities are better
715 * than theirs, so restrict what we advertise in the assoc request.
717 if (!(ap_vht_cap->vht_cap_info &
718 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
719 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
720 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
721 else if (!(ap_vht_cap->vht_cap_info &
722 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
723 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
726 * If some other vif is using the MU-MIMO capability we cannot associate
727 * using MU-MIMO - this will lead to contradictions in the group-id
729 * Ownership is defined since association request, in order to avoid
730 * simultaneous associations with MU-MIMO.
732 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
733 bool disable_mu_mimo = false;
734 struct ieee80211_sub_if_data *other;
736 list_for_each_entry_rcu(other, &local->interfaces, list) {
737 if (other->vif.bss_conf.mu_mimo_owner) {
738 disable_mu_mimo = true;
743 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
745 mu_mimo_owner = true;
748 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
750 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
751 our_bf_sts = cap & mask;
753 if (ap_bf_sts < our_bf_sts) {
758 /* reserve and fill IE */
759 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
760 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
762 return mu_mimo_owner;
765 /* This function determines HE capability flags for the association
768 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
770 struct ieee80211_supported_band *sband,
771 enum ieee80211_smps_mode smps_mode,
772 ieee80211_conn_flags_t conn_flags)
774 u8 *pos, *pre_he_pos;
775 const struct ieee80211_sta_he_cap *he_cap;
778 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
779 if (WARN_ON(!he_cap))
782 /* get a max size estimate */
784 2 + 1 + sizeof(he_cap->he_cap_elem) +
785 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
786 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
787 he_cap->he_cap_elem.phy_cap_info);
788 pos = skb_put(skb, he_cap_size);
790 pos = ieee80211_ie_build_he_cap(conn_flags,
791 pos, he_cap, pos + he_cap_size);
792 /* trim excess if any */
793 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
795 ieee80211_ie_build_he_6ghz_cap(sdata, smps_mode, skb);
798 static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
800 struct ieee80211_supported_band *sband)
803 const struct ieee80211_sta_he_cap *he_cap;
804 const struct ieee80211_sta_eht_cap *eht_cap;
807 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
808 eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
811 * EHT capabilities element is only added if the HE capabilities element
812 * was added so assume that 'he_cap' is valid and don't check it.
814 if (WARN_ON(!he_cap || !eht_cap))
818 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
819 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
820 &eht_cap->eht_cap_elem,
822 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
823 eht_cap->eht_cap_elem.phy_cap_info);
824 pos = skb_put(skb, eht_cap_size);
825 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size,
829 static void ieee80211_assoc_add_rates(struct sk_buff *skb,
830 enum nl80211_chan_width width,
831 struct ieee80211_supported_band *sband,
832 struct ieee80211_mgd_assoc_data *assoc_data)
834 unsigned int rates_len, supp_rates_len;
839 if (assoc_data->supp_rates_len) {
841 * Get all rates supported by the device and the AP as
842 * some APs don't like getting a superset of their rates
843 * in the association request (e.g. D-Link DAP 1353 in
846 rates_len = ieee80211_parse_bitrates(width, sband,
847 assoc_data->supp_rates,
848 assoc_data->supp_rates_len,
852 * In case AP not provide any supported rates information
853 * before association, we send information element(s) with
854 * all rates that we support.
856 rates_len = sband->n_bitrates;
857 for (i = 0; i < sband->n_bitrates; i++)
861 supp_rates_len = rates_len;
862 if (supp_rates_len > 8)
865 pos = skb_put(skb, supp_rates_len + 2);
866 *pos++ = WLAN_EID_SUPP_RATES;
867 *pos++ = supp_rates_len;
870 for (i = 0; i < sband->n_bitrates; i++) {
871 if (BIT(i) & rates) {
872 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 5);
879 if (rates_len > count) {
880 pos = skb_put(skb, rates_len - count + 2);
881 *pos++ = WLAN_EID_EXT_SUPP_RATES;
882 *pos++ = rates_len - count;
884 for (i++; i < sband->n_bitrates; i++) {
885 if (BIT(i) & rates) {
888 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 5);
895 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
902 static const u8 before_ht[] = {
905 WLAN_EID_EXT_SUPP_RATES,
906 WLAN_EID_PWR_CAPABILITY,
907 WLAN_EID_SUPPORTED_CHANNELS,
910 WLAN_EID_RRM_ENABLED_CAPABILITIES,
911 WLAN_EID_MOBILITY_DOMAIN,
912 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
913 WLAN_EID_RIC_DATA, /* reassoc only */
914 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
916 static const u8 after_ric[] = {
917 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
918 WLAN_EID_HT_CAPABILITY,
919 WLAN_EID_BSS_COEX_2040,
920 /* luckily this is almost always there */
921 WLAN_EID_EXT_CAPABILITY,
922 WLAN_EID_QOS_TRAFFIC_CAPA,
923 WLAN_EID_TIM_BCAST_REQ,
924 WLAN_EID_INTERWORKING,
925 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
926 WLAN_EID_VHT_CAPABILITY,
927 WLAN_EID_OPMODE_NOTIF,
933 noffset = ieee80211_ie_split_ric(elems, elems_len,
935 ARRAY_SIZE(before_ht),
937 ARRAY_SIZE(after_ric),
939 skb_put_data(skb, elems + offset, noffset - offset);
944 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
949 static const u8 before_vht[] = {
951 * no need to list the ones split off before HT
954 WLAN_EID_BSS_COEX_2040,
955 WLAN_EID_EXT_CAPABILITY,
956 WLAN_EID_QOS_TRAFFIC_CAPA,
957 WLAN_EID_TIM_BCAST_REQ,
958 WLAN_EID_INTERWORKING,
959 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
966 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
967 noffset = ieee80211_ie_split(elems, elems_len,
968 before_vht, ARRAY_SIZE(before_vht),
970 skb_put_data(skb, elems + offset, noffset - offset);
975 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
980 static const u8 before_he[] = {
982 * no need to list the ones split off before VHT
985 WLAN_EID_OPMODE_NOTIF,
986 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
988 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
989 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
990 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
991 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
992 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
993 /* TODO: add 11ah/11aj/11ak elements */
1000 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
1001 noffset = ieee80211_ie_split(elems, elems_len,
1002 before_he, ARRAY_SIZE(before_he),
1004 skb_put_data(skb, elems + offset, noffset - offset);
1009 #define PRESENT_ELEMS_MAX 8
1010 #define PRESENT_ELEM_EXT_OFFS 0x100
1012 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1013 struct sk_buff *skb, u16 capab,
1014 const struct element *ext_capa,
1015 const u16 *present_elems);
1017 static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata,
1018 struct sk_buff *skb, u16 *capab,
1019 const struct element *ext_capa,
1020 const u8 *extra_elems,
1021 size_t extra_elems_len,
1022 unsigned int link_id,
1023 struct ieee80211_link_data *link,
1026 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1027 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1028 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1029 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1030 struct ieee80211_channel *chan = cbss->channel;
1031 const struct ieee80211_sband_iftype_data *iftd;
1032 struct ieee80211_local *local = sdata->local;
1033 struct ieee80211_supported_band *sband;
1034 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
1035 struct ieee80211_chanctx_conf *chanctx_conf;
1036 enum ieee80211_smps_mode smps_mode;
1037 u16 orig_capab = *capab;
1039 int present_elems_len = 0;
1043 #define ADD_PRESENT_ELEM(id) do { \
1044 /* need a last for termination - we use 0 == SSID */ \
1045 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
1046 present_elems[present_elems_len++] = (id); \
1048 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
1051 smps_mode = link->smps_mode;
1052 else if (sdata->u.mgd.powersave)
1053 smps_mode = IEEE80211_SMPS_DYNAMIC;
1055 smps_mode = IEEE80211_SMPS_OFF;
1059 * 5/10 MHz scenarios are only viable without MLO, in which
1060 * case this pointer should be used ... All of this is a bit
1061 * unclear though, not sure this even works at all.
1064 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
1066 width = chanctx_conf->def.width;
1070 sband = local->hw.wiphy->bands[chan->band];
1071 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1073 if (sband->band == NL80211_BAND_2GHZ) {
1074 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1075 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1078 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
1079 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
1080 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
1082 if (sband->band != NL80211_BAND_S1GHZ)
1083 ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
1085 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
1086 *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
1087 struct cfg80211_chan_def chandef = {
1092 pos = skb_put(skb, 4);
1093 *pos++ = WLAN_EID_PWR_CAPABILITY;
1095 *pos++ = 0; /* min tx power */
1097 *pos++ = ieee80211_chandef_max_power(&chandef);
1098 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
1102 * Per spec, we shouldn't include the list of channels if we advertise
1103 * support for extended channel switching, but we've always done that;
1104 * (for now?) apply this restriction only on the (new) 6 GHz band.
1106 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
1107 (sband->band != NL80211_BAND_6GHZ ||
1108 !ext_capa || ext_capa->datalen < 1 ||
1109 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
1110 /* TODO: get this in reg domain format */
1111 pos = skb_put(skb, 2 * sband->n_channels + 2);
1112 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
1113 *pos++ = 2 * sband->n_channels;
1114 for (i = 0; i < sband->n_channels; i++) {
1115 int cf = sband->channels[i].center_freq;
1117 *pos++ = ieee80211_frequency_to_channel(cf);
1118 *pos++ = 1; /* one channel in the subband*/
1120 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
1123 /* if present, add any custom IEs that go before HT */
1124 offset = ieee80211_add_before_ht_elems(skb, extra_elems,
1128 if (sband->band != NL80211_BAND_6GHZ &&
1129 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT)) {
1130 ieee80211_add_ht_ie(sdata, skb,
1131 assoc_data->link[link_id].ap_ht_param,
1132 sband, chan, smps_mode,
1133 assoc_data->link[link_id].conn_flags);
1134 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
1137 /* if present, add any custom IEs that go before VHT */
1138 offset = ieee80211_add_before_vht_elems(skb, extra_elems,
1142 if (sband->band != NL80211_BAND_6GHZ &&
1143 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
1144 bool mu_mimo_owner =
1145 ieee80211_add_vht_ie(sdata, skb, sband,
1146 &assoc_data->link[link_id].ap_vht_cap,
1147 assoc_data->link[link_id].conn_flags);
1150 link->conf->mu_mimo_owner = mu_mimo_owner;
1151 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
1155 * If AP doesn't support HT, mark HE and EHT as disabled.
1156 * If on the 5GHz band, make sure it supports VHT.
1158 if (assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT ||
1159 (sband->band == NL80211_BAND_5GHZ &&
1160 assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT))
1161 assoc_data->link[link_id].conn_flags |=
1162 IEEE80211_CONN_DISABLE_HE |
1163 IEEE80211_CONN_DISABLE_EHT;
1165 /* if present, add any custom IEs that go before HE */
1166 offset = ieee80211_add_before_he_elems(skb, extra_elems,
1170 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HE)) {
1171 ieee80211_add_he_ie(sdata, skb, sband, smps_mode,
1172 assoc_data->link[link_id].conn_flags);
1173 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
1177 * careful - need to know about all the present elems before
1178 * calling ieee80211_assoc_add_ml_elem(), so add this one if
1179 * we're going to put it after the ML element
1181 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1182 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
1184 if (link_id == assoc_data->assoc_link_id)
1185 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
1188 /* crash if somebody gets it wrong */
1189 present_elems = NULL;
1191 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1192 ieee80211_add_eht_ie(sdata, skb, sband);
1194 if (sband->band == NL80211_BAND_S1GHZ) {
1195 ieee80211_add_aid_request_ie(sdata, skb);
1196 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1199 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1200 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1203 link->u.mgd.conn_flags = assoc_data->link[link_id].conn_flags;
1208 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
1212 unsigned int skb_len = skb->len;
1213 bool at_extension = false;
1216 u8 *len, *list_len = NULL;
1218 skb_put_u8(skb, WLAN_EID_EXTENSION);
1219 len = skb_put(skb, 1);
1220 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
1222 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
1223 u16 elem = outer[i];
1224 bool have_inner = false;
1226 /* should at least be sorted in the sense of normal -> ext */
1227 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
1229 /* switch to extension list */
1230 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
1231 at_extension = true;
1237 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
1238 if (elem == inner[j]) {
1248 list_len = skb_put(skb, 1);
1252 skb_put_u8(skb, (u8)elem);
1256 /* if we added a list but no extension list, make a zero-len one */
1257 if (added && (!at_extension || !list_len))
1260 /* if nothing added remove extension element completely */
1262 skb_trim(skb, skb_len);
1264 *len = skb->len - skb_len - 2;
1267 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1268 struct sk_buff *skb, u16 capab,
1269 const struct element *ext_capa,
1270 const u16 *outer_present_elems)
1272 struct ieee80211_local *local = sdata->local;
1273 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1274 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1275 struct ieee80211_multi_link_elem *ml_elem;
1276 struct ieee80211_mle_basic_common_info *common;
1277 const struct wiphy_iftype_ext_capab *ift_ext_capa;
1278 __le16 eml_capa = 0, mld_capa_ops = 0;
1279 unsigned int link_id;
1283 if (!ieee80211_vif_is_mld(&sdata->vif))
1286 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
1287 ieee80211_vif_type_p2p(&sdata->vif));
1289 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
1290 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
1293 skb_put_u8(skb, WLAN_EID_EXTENSION);
1294 ml_elem_len = skb_put(skb, 1);
1295 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
1296 ml_elem = skb_put(skb, sizeof(*ml_elem));
1298 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
1299 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
1300 common = skb_put(skb, sizeof(*common));
1301 common->len = sizeof(*common) +
1302 2; /* MLD capa/ops */
1303 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
1305 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
1307 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
1308 IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
1309 common->len += 2; /* EML capabilities */
1311 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
1312 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
1314 /* need indication from userspace to support this */
1315 mld_capa_ops &= ~cpu_to_le16(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP);
1316 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
1318 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1319 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
1320 const u8 *extra_elems;
1321 size_t extra_elems_len;
1323 u8 *subelem_len = NULL;
1326 if (!assoc_data->link[link_id].bss ||
1327 link_id == assoc_data->assoc_link_id)
1330 extra_elems = assoc_data->link[link_id].elems;
1331 extra_elems_len = assoc_data->link[link_id].elems_len;
1333 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
1334 subelem_len = skb_put(skb, 1);
1336 ctrl = cpu_to_le16(link_id |
1337 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
1338 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
1339 skb_put_data(skb, &ctrl, sizeof(ctrl));
1340 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
1341 skb_put_data(skb, assoc_data->link[link_id].addr,
1344 * Now add the contents of the (re)association request,
1345 * but the "listen interval" and "current AP address"
1346 * (if applicable) are skipped. So we only have
1347 * the capability field (remember the position and fill
1348 * later), followed by the elements added below by
1349 * calling ieee80211_assoc_link_elems().
1351 capab_pos = skb_put(skb, 2);
1353 extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab,
1358 link_present_elems);
1360 skb_put_data(skb, extra_elems + extra_used,
1361 extra_elems_len - extra_used);
1363 put_unaligned_le16(capab, capab_pos);
1365 ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
1366 link_present_elems);
1368 ieee80211_fragment_element(skb, subelem_len,
1369 IEEE80211_MLE_SUBELEM_FRAGMENT);
1372 ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT);
1375 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
1377 struct ieee80211_local *local = sdata->local;
1378 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1379 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1380 struct ieee80211_link_data *link;
1381 struct sk_buff *skb;
1382 struct ieee80211_mgmt *mgmt;
1383 u8 *pos, qos_info, *ie_start;
1384 size_t offset, noffset;
1385 u16 capab = WLAN_CAPABILITY_ESS, link_capab;
1387 struct element *ext_capa = NULL;
1388 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1389 struct ieee80211_prep_tx_info info = {};
1390 unsigned int link_id, n_links = 0;
1391 u16 present_elems[PRESENT_ELEMS_MAX] = {};
1396 /* we know it's writable, cast away the const */
1397 if (assoc_data->ie_len)
1398 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
1400 assoc_data->ie_len);
1402 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1404 size = local->hw.extra_tx_headroom +
1405 sizeof(*mgmt) + /* bit too much but doesn't matter */
1406 2 + assoc_data->ssid_len + /* SSID */
1407 assoc_data->ie_len + /* extra IEs */
1408 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
1411 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1412 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1413 const struct ieee80211_sband_iftype_data *iftd;
1414 struct ieee80211_supported_band *sband;
1419 sband = local->hw.wiphy->bands[cbss->channel->band];
1422 /* add STA profile elements length */
1423 size += assoc_data->link[link_id].elems_len;
1424 /* and supported rates length */
1425 size += 4 + sband->n_bitrates;
1426 /* supported channels */
1427 size += 2 + 2 * sband->n_channels;
1429 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1431 size += iftd->vendor_elems.len;
1433 /* power capability */
1436 /* HT, VHT, HE, EHT */
1437 size += 2 + sizeof(struct ieee80211_ht_cap);
1438 size += 2 + sizeof(struct ieee80211_vht_cap);
1439 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
1440 sizeof(struct ieee80211_he_mcs_nss_supp) +
1441 IEEE80211_HE_PPE_THRES_MAX_LEN;
1443 if (sband->band == NL80211_BAND_6GHZ)
1444 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
1446 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
1447 sizeof(struct ieee80211_eht_mcs_nss_supp) +
1448 IEEE80211_EHT_PPE_THRES_MAX_LEN;
1450 /* non-inheritance element */
1451 size += 2 + 2 + PRESENT_ELEMS_MAX;
1453 /* should be the same across all BSSes */
1454 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
1455 capab |= WLAN_CAPABILITY_PRIVACY;
1458 if (ieee80211_vif_is_mld(&sdata->vif)) {
1459 /* consider the multi-link element with STA profile */
1460 size += sizeof(struct ieee80211_multi_link_elem);
1461 /* max common info field in basic multi-link element */
1462 size += sizeof(struct ieee80211_mle_basic_common_info) +
1467 * The capability elements were already considered above;
1468 * note this over-estimates a bit because there's no
1469 * STA profile for the assoc link.
1471 size += (n_links - 1) *
1472 (1 + 1 + /* subelement ID/length */
1473 2 + /* STA control */
1474 1 + ETH_ALEN + 2 /* STA Info field */);
1477 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
1481 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
1484 skb = alloc_skb(size, GFP_KERNEL);
1488 skb_reserve(skb, local->hw.extra_tx_headroom);
1490 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
1491 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
1493 /* Set MBSSID support for HE AP if needed */
1494 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
1495 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
1496 ext_capa && ext_capa->datalen >= 3)
1497 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1499 mgmt = skb_put_zero(skb, 24);
1500 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
1501 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1502 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
1504 listen_int = cpu_to_le16(assoc_data->s1g ?
1505 ieee80211_encode_usf(local->hw.conf.listen_interval) :
1506 local->hw.conf.listen_interval);
1507 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
1509 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1510 IEEE80211_STYPE_REASSOC_REQ);
1511 capab_pos = &mgmt->u.reassoc_req.capab_info;
1512 mgmt->u.reassoc_req.listen_interval = listen_int;
1513 memcpy(mgmt->u.reassoc_req.current_ap,
1514 assoc_data->prev_ap_addr, ETH_ALEN);
1515 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
1518 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1519 IEEE80211_STYPE_ASSOC_REQ);
1520 capab_pos = &mgmt->u.assoc_req.capab_info;
1521 mgmt->u.assoc_req.listen_interval = listen_int;
1522 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
1526 pos = skb_put(skb, 2 + assoc_data->ssid_len);
1528 *pos++ = WLAN_EID_SSID;
1529 *pos++ = assoc_data->ssid_len;
1530 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
1532 /* add the elements for the assoc (main) link */
1534 offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab,
1538 assoc_data->assoc_link_id, link,
1540 put_unaligned_le16(link_capab, capab_pos);
1542 /* if present, add any custom non-vendor IEs */
1543 if (assoc_data->ie_len) {
1544 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1547 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1551 if (assoc_data->wmm) {
1552 if (assoc_data->uapsd) {
1553 qos_info = ifmgd->uapsd_queues;
1554 qos_info |= (ifmgd->uapsd_max_sp_len <<
1555 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1560 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1563 /* add any remaining custom (i.e. vendor specific here) IEs */
1564 if (assoc_data->ie_len) {
1565 noffset = assoc_data->ie_len;
1566 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1569 if (assoc_data->fils_kek_len) {
1570 ret = fils_encrypt_assoc_req(skb, assoc_data);
1577 pos = skb_tail_pointer(skb);
1578 kfree(ifmgd->assoc_req_ies);
1579 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1580 if (!ifmgd->assoc_req_ies) {
1585 ifmgd->assoc_req_ies_len = pos - ie_start;
1587 info.link_id = assoc_data->assoc_link_id;
1588 drv_mgd_prepare_tx(local, sdata, &info);
1590 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1591 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1592 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1593 IEEE80211_TX_INTFL_MLME_CONN_TX;
1594 ieee80211_tx_skb(sdata, skb);
1599 void ieee80211_send_pspoll(struct ieee80211_local *local,
1600 struct ieee80211_sub_if_data *sdata)
1602 struct ieee80211_pspoll *pspoll;
1603 struct sk_buff *skb;
1605 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1609 pspoll = (struct ieee80211_pspoll *) skb->data;
1610 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1612 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1613 ieee80211_tx_skb(sdata, skb);
1616 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1617 struct ieee80211_sub_if_data *sdata,
1620 struct sk_buff *skb;
1621 struct ieee80211_hdr_3addr *nullfunc;
1622 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1624 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1,
1625 !ieee80211_hw_check(&local->hw,
1626 DOESNT_SUPPORT_QOS_NDP));
1630 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1632 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1634 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1635 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1637 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1638 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1640 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1641 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1643 ieee80211_tx_skb(sdata, skb);
1646 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1647 struct ieee80211_sub_if_data *sdata)
1649 struct sk_buff *skb;
1650 struct ieee80211_hdr *nullfunc;
1653 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1656 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1660 skb_reserve(skb, local->hw.extra_tx_headroom);
1662 nullfunc = skb_put_zero(skb, 30);
1663 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1664 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1665 nullfunc->frame_control = fc;
1666 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1667 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1668 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1669 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1671 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1672 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1673 ieee80211_tx_skb(sdata, skb);
1676 /* spectrum management related things */
1677 static void ieee80211_chswitch_work(struct wiphy *wiphy,
1678 struct wiphy_work *work)
1680 struct ieee80211_link_data *link =
1681 container_of(work, struct ieee80211_link_data,
1682 u.mgd.chswitch_work.work);
1683 struct ieee80211_sub_if_data *sdata = link->sdata;
1684 struct ieee80211_local *local = sdata->local;
1685 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1688 if (!ieee80211_sdata_running(sdata))
1691 lockdep_assert_wiphy(local->hw.wiphy);
1693 if (!ifmgd->associated)
1696 if (!link->conf->csa_active)
1700 * using reservation isn't immediate as it may be deferred until later
1701 * with multi-vif. once reservation is complete it will re-schedule the
1702 * work with no reserved_chanctx so verify chandef to check if it
1703 * completed successfully
1706 if (link->reserved_chanctx) {
1708 * with multi-vif csa driver may call ieee80211_csa_finish()
1709 * many times while waiting for other interfaces to use their
1712 if (link->reserved_ready)
1715 ret = ieee80211_link_use_reserved_context(link);
1718 "failed to use reserved channel context, disconnecting (err=%d)\n",
1720 wiphy_work_queue(sdata->local->hw.wiphy,
1721 &ifmgd->csa_connection_drop_work);
1726 if (!cfg80211_chandef_identical(&link->conf->chandef,
1727 &link->csa_chandef)) {
1729 "failed to finalize channel switch, disconnecting\n");
1730 wiphy_work_queue(sdata->local->hw.wiphy,
1731 &ifmgd->csa_connection_drop_work);
1735 link->u.mgd.csa_waiting_bcn = true;
1737 ieee80211_sta_reset_beacon_monitor(sdata);
1738 ieee80211_sta_reset_conn_monitor(sdata);
1741 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
1743 struct ieee80211_sub_if_data *sdata = link->sdata;
1744 struct ieee80211_local *local = sdata->local;
1745 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1748 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1750 WARN_ON(!link->conf->csa_active);
1752 if (link->csa_block_tx) {
1753 ieee80211_wake_vif_queues(local, sdata,
1754 IEEE80211_QUEUE_STOP_REASON_CSA);
1755 link->csa_block_tx = false;
1758 link->conf->csa_active = false;
1759 link->u.mgd.csa_waiting_bcn = false;
1761 * If the CSA IE is still present on the beacon after the switch,
1762 * we need to consider it as a new CSA (possibly to self).
1764 link->u.mgd.beacon_crc_valid = false;
1766 ret = drv_post_channel_switch(link);
1769 "driver post channel switch failed, disconnecting\n");
1770 wiphy_work_queue(sdata->local->hw.wiphy,
1771 &ifmgd->csa_connection_drop_work);
1775 cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef,
1779 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success,
1780 unsigned int link_id)
1782 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1784 trace_api_chswitch_done(sdata, success, link_id);
1790 "driver channel switch failed, disconnecting\n");
1791 wiphy_work_queue(sdata->local->hw.wiphy,
1792 &sdata->u.mgd.csa_connection_drop_work);
1794 struct ieee80211_link_data *link =
1795 rcu_dereference(sdata->link[link_id]);
1797 if (WARN_ON(!link)) {
1802 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
1803 &link->u.mgd.chswitch_work, 0);
1808 EXPORT_SYMBOL(ieee80211_chswitch_done);
1811 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
1813 struct ieee80211_sub_if_data *sdata = link->sdata;
1814 struct ieee80211_local *local = sdata->local;
1816 lockdep_assert_wiphy(local->hw.wiphy);
1818 if (!local->ops->abort_channel_switch)
1821 ieee80211_link_unreserve_chanctx(link);
1823 if (link->csa_block_tx)
1824 ieee80211_wake_vif_queues(local, sdata,
1825 IEEE80211_QUEUE_STOP_REASON_CSA);
1827 link->csa_block_tx = false;
1828 link->conf->csa_active = false;
1830 drv_abort_channel_switch(sdata);
1834 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
1835 u64 timestamp, u32 device_timestamp,
1836 struct ieee802_11_elems *elems,
1839 struct ieee80211_sub_if_data *sdata = link->sdata;
1840 struct ieee80211_local *local = sdata->local;
1841 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1842 struct cfg80211_bss *cbss = link->u.mgd.bss;
1843 struct ieee80211_chanctx_conf *conf;
1844 struct ieee80211_chanctx *chanctx;
1845 enum nl80211_band current_band;
1846 struct ieee80211_csa_ie csa_ie;
1847 struct ieee80211_channel_switch ch_switch;
1848 struct ieee80211_bss *bss;
1849 unsigned long timeout;
1852 lockdep_assert_wiphy(local->hw.wiphy);
1857 current_band = cbss->channel->band;
1858 bss = (void *)cbss->priv;
1859 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1861 link->u.mgd.conn_flags,
1862 link->u.mgd.bssid, &csa_ie);
1865 ch_switch.timestamp = timestamp;
1866 ch_switch.device_timestamp = device_timestamp;
1867 ch_switch.block_tx = csa_ie.mode;
1868 ch_switch.chandef = csa_ie.chandef;
1869 ch_switch.count = csa_ie.count;
1870 ch_switch.delay = csa_ie.max_switch_time;
1874 goto drop_connection;
1876 if (beacon && link->conf->csa_active &&
1877 !link->u.mgd.csa_waiting_bcn) {
1879 ieee80211_sta_abort_chanswitch(link);
1881 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1883 } else if (link->conf->csa_active || res) {
1884 /* disregard subsequent announcements if already processing */
1888 if (link->conf->chandef.chan->band !=
1889 csa_ie.chandef.chan->band) {
1891 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1893 csa_ie.chandef.chan->center_freq,
1894 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1895 csa_ie.chandef.center_freq2);
1896 goto drop_connection;
1899 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1900 IEEE80211_CHAN_DISABLED)) {
1902 "AP %pM switches to unsupported channel "
1903 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1906 csa_ie.chandef.chan->center_freq,
1907 csa_ie.chandef.chan->freq_offset,
1908 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1909 csa_ie.chandef.freq1_offset,
1910 csa_ie.chandef.center_freq2);
1911 goto drop_connection;
1914 if (cfg80211_chandef_identical(&csa_ie.chandef,
1915 &link->conf->chandef) &&
1916 (!csa_ie.mode || !beacon)) {
1917 if (link->u.mgd.csa_ignored_same_chan)
1920 "AP %pM tries to chanswitch to same channel, ignore\n",
1922 link->u.mgd.csa_ignored_same_chan = true;
1927 * Drop all TDLS peers - either we disconnect or move to a different
1928 * channel from this point on. There's no telling what our peer will do.
1929 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1930 * have an incompatible wider chandef.
1932 ieee80211_teardown_tdls_peers(sdata);
1934 conf = rcu_dereference_protected(link->conf->chanctx_conf,
1935 lockdep_is_held(&local->hw.wiphy->mtx));
1938 "no channel context assigned to vif?, disconnecting\n");
1939 goto drop_connection;
1942 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1944 if (local->use_chanctx &&
1945 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1947 "driver doesn't support chan-switch with channel contexts\n");
1948 goto drop_connection;
1951 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1953 "preparing for channel switch failed, disconnecting\n");
1954 goto drop_connection;
1957 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
1958 chanctx->mode, false);
1961 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1963 goto drop_connection;
1966 link->conf->csa_active = true;
1967 link->csa_chandef = csa_ie.chandef;
1968 link->csa_block_tx = csa_ie.mode;
1969 link->u.mgd.csa_ignored_same_chan = false;
1970 link->u.mgd.beacon_crc_valid = false;
1972 if (link->csa_block_tx)
1973 ieee80211_stop_vif_queues(local, sdata,
1974 IEEE80211_QUEUE_STOP_REASON_CSA);
1976 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1977 link->link_id, csa_ie.count,
1980 if (local->ops->channel_switch) {
1981 /* use driver's channel switch callback */
1982 drv_channel_switch(local, sdata, &ch_switch);
1986 /* channel switch handled in software */
1987 timeout = TU_TO_JIFFIES((max_t(int, csa_ie.count, 1) - 1) *
1988 cbss->beacon_interval);
1989 wiphy_delayed_work_queue(local->hw.wiphy,
1990 &link->u.mgd.chswitch_work,
1995 * This is just so that the disconnect flow will know that
1996 * we were trying to switch channel and failed. In case the
1997 * mode is 1 (we are not allowed to Tx), we will know not to
1998 * send a deauthentication frame. Those two fields will be
1999 * reset when the disconnection worker runs.
2001 link->conf->csa_active = true;
2002 link->csa_block_tx = csa_ie.mode;
2004 wiphy_work_queue(sdata->local->hw.wiphy,
2005 &ifmgd->csa_connection_drop_work);
2009 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
2010 struct ieee80211_channel *channel,
2011 const u8 *country_ie, u8 country_ie_len,
2012 const u8 *pwr_constr_elem,
2013 int *chan_pwr, int *pwr_reduction)
2015 struct ieee80211_country_ie_triplet *triplet;
2016 int chan = ieee80211_frequency_to_channel(channel->center_freq);
2017 int i, chan_increment;
2018 bool have_chan_pwr = false;
2021 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
2024 triplet = (void *)(country_ie + 3);
2025 country_ie_len -= 3;
2027 switch (channel->band) {
2031 case NL80211_BAND_2GHZ:
2032 case NL80211_BAND_60GHZ:
2033 case NL80211_BAND_LC:
2036 case NL80211_BAND_5GHZ:
2039 case NL80211_BAND_6GHZ:
2041 * In the 6 GHz band, the "maximum transmit power level"
2042 * field in the triplets is reserved, and thus will be
2043 * zero and we shouldn't use it to control TX power.
2044 * The actual TX power will be given in the transmit
2045 * power envelope element instead.
2051 while (country_ie_len >= 3) {
2052 u8 first_channel = triplet->chans.first_channel;
2054 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
2057 for (i = 0; i < triplet->chans.num_channels; i++) {
2058 if (first_channel + i * chan_increment == chan) {
2059 have_chan_pwr = true;
2060 *chan_pwr = triplet->chans.max_power;
2069 country_ie_len -= 3;
2072 if (have_chan_pwr && pwr_constr_elem)
2073 *pwr_reduction = *pwr_constr_elem;
2077 return have_chan_pwr;
2080 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
2081 struct ieee80211_channel *channel,
2082 const u8 *cisco_dtpc_ie,
2085 /* From practical testing, the first data byte of the DTPC element
2086 * seems to contain the requested dBm level, and the CLI on Cisco
2087 * APs clearly state the range is -127 to 127 dBm, which indicates
2088 * a signed byte, although it seemingly never actually goes negative.
2089 * The other byte seems to always be zero.
2091 *pwr_level = (__s8)cisco_dtpc_ie[4];
2094 static u64 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
2095 struct ieee80211_channel *channel,
2096 struct ieee80211_mgmt *mgmt,
2097 const u8 *country_ie, u8 country_ie_len,
2098 const u8 *pwr_constr_ie,
2099 const u8 *cisco_dtpc_ie)
2101 struct ieee80211_sub_if_data *sdata = link->sdata;
2102 bool has_80211h_pwr = false, has_cisco_pwr = false;
2103 int chan_pwr = 0, pwr_reduction_80211h = 0;
2104 int pwr_level_cisco, pwr_level_80211h;
2106 __le16 capab = mgmt->u.probe_resp.capab_info;
2108 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
2109 return 0; /* TODO */
2112 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
2113 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
2114 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
2115 sdata, channel, country_ie, country_ie_len,
2116 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
2118 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
2121 if (cisco_dtpc_ie) {
2122 ieee80211_find_cisco_dtpc(
2123 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
2124 has_cisco_pwr = true;
2127 if (!has_80211h_pwr && !has_cisco_pwr)
2130 /* If we have both 802.11h and Cisco DTPC, apply both limits
2131 * by picking the smallest of the two power levels advertised.
2133 if (has_80211h_pwr &&
2134 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
2135 new_ap_level = pwr_level_80211h;
2137 if (link->ap_power_level == new_ap_level)
2141 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
2142 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
2144 } else { /* has_cisco_pwr is always true here. */
2145 new_ap_level = pwr_level_cisco;
2147 if (link->ap_power_level == new_ap_level)
2151 "Limiting TX power to %d dBm as advertised by %pM\n",
2152 pwr_level_cisco, link->u.mgd.bssid);
2155 link->ap_power_level = new_ap_level;
2156 if (__ieee80211_recalc_txpower(sdata))
2157 return BSS_CHANGED_TXPOWER;
2162 static void ieee80211_enable_ps(struct ieee80211_local *local,
2163 struct ieee80211_sub_if_data *sdata)
2165 struct ieee80211_conf *conf = &local->hw.conf;
2168 * If we are scanning right now then the parameters will
2169 * take effect when scan finishes.
2171 if (local->scanning)
2174 if (conf->dynamic_ps_timeout > 0 &&
2175 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2176 mod_timer(&local->dynamic_ps_timer, jiffies +
2177 msecs_to_jiffies(conf->dynamic_ps_timeout));
2179 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
2180 ieee80211_send_nullfunc(local, sdata, true);
2182 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2183 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2186 conf->flags |= IEEE80211_CONF_PS;
2187 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2191 static void ieee80211_change_ps(struct ieee80211_local *local)
2193 struct ieee80211_conf *conf = &local->hw.conf;
2195 if (local->ps_sdata) {
2196 ieee80211_enable_ps(local, local->ps_sdata);
2197 } else if (conf->flags & IEEE80211_CONF_PS) {
2198 conf->flags &= ~IEEE80211_CONF_PS;
2199 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2200 del_timer_sync(&local->dynamic_ps_timer);
2201 wiphy_work_cancel(local->hw.wiphy,
2202 &local->dynamic_ps_enable_work);
2206 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
2208 struct ieee80211_local *local = sdata->local;
2209 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
2210 struct sta_info *sta = NULL;
2211 bool authorized = false;
2213 if (!mgd->powersave)
2219 if (!mgd->associated)
2222 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
2225 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
2226 !sdata->deflink.u.mgd.have_beacon)
2230 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2232 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2238 /* need to hold RTNL or interface lock */
2239 void ieee80211_recalc_ps(struct ieee80211_local *local)
2241 struct ieee80211_sub_if_data *sdata, *found = NULL;
2245 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
2246 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2247 local->ps_sdata = NULL;
2251 list_for_each_entry(sdata, &local->interfaces, list) {
2252 if (!ieee80211_sdata_running(sdata))
2254 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2255 /* If an AP vif is found, then disable PS
2256 * by setting the count to zero thereby setting
2262 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2268 if (count == 1 && ieee80211_powersave_allowed(found)) {
2269 u8 dtimper = found->deflink.u.mgd.dtim_period;
2271 timeout = local->dynamic_ps_forced_timeout;
2274 local->hw.conf.dynamic_ps_timeout = timeout;
2276 /* If the TIM IE is invalid, pretend the value is 1 */
2280 local->hw.conf.ps_dtim_period = dtimper;
2281 local->ps_sdata = found;
2283 local->ps_sdata = NULL;
2286 ieee80211_change_ps(local);
2289 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
2291 bool ps_allowed = ieee80211_powersave_allowed(sdata);
2293 if (sdata->vif.cfg.ps != ps_allowed) {
2294 sdata->vif.cfg.ps = ps_allowed;
2295 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
2299 void ieee80211_dynamic_ps_disable_work(struct wiphy *wiphy,
2300 struct wiphy_work *work)
2302 struct ieee80211_local *local =
2303 container_of(work, struct ieee80211_local,
2304 dynamic_ps_disable_work);
2306 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2307 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2308 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2311 ieee80211_wake_queues_by_reason(&local->hw,
2312 IEEE80211_MAX_QUEUE_MAP,
2313 IEEE80211_QUEUE_STOP_REASON_PS,
2317 void ieee80211_dynamic_ps_enable_work(struct wiphy *wiphy,
2318 struct wiphy_work *work)
2320 struct ieee80211_local *local =
2321 container_of(work, struct ieee80211_local,
2322 dynamic_ps_enable_work);
2323 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
2324 struct ieee80211_if_managed *ifmgd;
2325 unsigned long flags;
2328 /* can only happen when PS was just disabled anyway */
2332 ifmgd = &sdata->u.mgd;
2334 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2337 if (local->hw.conf.dynamic_ps_timeout > 0) {
2338 /* don't enter PS if TX frames are pending */
2339 if (drv_tx_frames_pending(local)) {
2340 mod_timer(&local->dynamic_ps_timer, jiffies +
2342 local->hw.conf.dynamic_ps_timeout));
2347 * transmission can be stopped by others which leads to
2348 * dynamic_ps_timer expiry. Postpone the ps timer if it
2349 * is not the actual idle state.
2351 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
2352 for (q = 0; q < local->hw.queues; q++) {
2353 if (local->queue_stop_reasons[q]) {
2354 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
2356 mod_timer(&local->dynamic_ps_timer, jiffies +
2358 local->hw.conf.dynamic_ps_timeout));
2362 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
2365 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2366 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2367 if (drv_tx_frames_pending(local)) {
2368 mod_timer(&local->dynamic_ps_timer, jiffies +
2370 local->hw.conf.dynamic_ps_timeout));
2372 ieee80211_send_nullfunc(local, sdata, true);
2373 /* Flush to get the tx status of nullfunc frame */
2374 ieee80211_flush_queues(local, sdata, false);
2378 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
2379 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
2380 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2381 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2382 local->hw.conf.flags |= IEEE80211_CONF_PS;
2383 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2387 void ieee80211_dynamic_ps_timer(struct timer_list *t)
2389 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
2391 wiphy_work_queue(local->hw.wiphy, &local->dynamic_ps_enable_work);
2394 void ieee80211_dfs_cac_timer_work(struct wiphy *wiphy, struct wiphy_work *work)
2396 struct ieee80211_link_data *link =
2397 container_of(work, struct ieee80211_link_data,
2398 dfs_cac_timer_work.work);
2399 struct cfg80211_chan_def chandef = link->conf->chandef;
2400 struct ieee80211_sub_if_data *sdata = link->sdata;
2402 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2404 if (sdata->wdev.cac_started) {
2405 ieee80211_link_release_channel(link);
2406 cfg80211_cac_event(sdata->dev, &chandef,
2407 NL80211_RADAR_CAC_FINISHED,
2413 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2415 struct ieee80211_local *local = sdata->local;
2416 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2420 if (local->hw.queues < IEEE80211_NUM_ACS)
2423 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2424 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2426 unsigned long now = jiffies;
2428 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
2429 tx_tspec->admitted_time &&
2430 time_after(now, tx_tspec->time_slice_start + HZ)) {
2431 tx_tspec->consumed_tx_time = 0;
2432 tx_tspec->time_slice_start = now;
2434 if (tx_tspec->downgraded)
2436 TX_TSPEC_ACTION_STOP_DOWNGRADE;
2439 switch (tx_tspec->action) {
2440 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
2441 /* take the original parameters */
2442 if (drv_conf_tx(local, &sdata->deflink, ac,
2443 &sdata->deflink.tx_conf[ac]))
2444 link_err(&sdata->deflink,
2445 "failed to set TX queue parameters for queue %d\n",
2447 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2448 tx_tspec->downgraded = false;
2451 case TX_TSPEC_ACTION_DOWNGRADE:
2452 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2453 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2457 /* downgrade next lower non-ACM AC */
2458 for (non_acm_ac = ac + 1;
2459 non_acm_ac < IEEE80211_NUM_ACS;
2461 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2463 /* Usually the loop will result in using BK even if it
2464 * requires admission control, but such a configuration
2465 * makes no sense and we have to transmit somehow - the
2466 * AC selection does the same thing.
2467 * If we started out trying to downgrade from BK, then
2468 * the extra condition here might be needed.
2470 if (non_acm_ac >= IEEE80211_NUM_ACS)
2471 non_acm_ac = IEEE80211_AC_BK;
2472 if (drv_conf_tx(local, &sdata->deflink, ac,
2473 &sdata->deflink.tx_conf[non_acm_ac]))
2474 link_err(&sdata->deflink,
2475 "failed to set TX queue parameters for queue %d\n",
2477 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2479 wiphy_delayed_work_queue(local->hw.wiphy,
2480 &ifmgd->tx_tspec_wk,
2481 tx_tspec->time_slice_start +
2484 case TX_TSPEC_ACTION_NONE:
2493 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2495 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2496 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2500 static void ieee80211_sta_handle_tspec_ac_params_wk(struct wiphy *wiphy,
2501 struct wiphy_work *work)
2503 struct ieee80211_sub_if_data *sdata;
2505 sdata = container_of(work, struct ieee80211_sub_if_data,
2506 u.mgd.tx_tspec_wk.work);
2507 ieee80211_sta_handle_tspec_ac_params(sdata);
2510 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
2512 struct ieee80211_sub_if_data *sdata = link->sdata;
2513 struct ieee80211_local *local = sdata->local;
2514 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2515 struct ieee80211_tx_queue_params *params = link->tx_conf;
2518 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2520 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2522 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2523 params[ac].txop, params[ac].uapsd,
2524 ifmgd->tx_tspec[ac].downgraded);
2525 if (!ifmgd->tx_tspec[ac].downgraded &&
2526 drv_conf_tx(local, link, ac, ¶ms[ac]))
2528 "failed to set TX queue parameters for AC %d\n",
2535 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2536 struct ieee80211_link_data *link,
2537 const u8 *wmm_param, size_t wmm_param_len,
2538 const struct ieee80211_mu_edca_param_set *mu_edca)
2540 struct ieee80211_sub_if_data *sdata = link->sdata;
2541 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2542 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2544 int count, mu_edca_count, ac;
2546 u8 uapsd_queues = 0;
2548 if (!local->ops->conf_tx)
2551 if (local->hw.queues < IEEE80211_NUM_ACS)
2557 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2560 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2561 uapsd_queues = ifmgd->uapsd_queues;
2563 count = wmm_param[6] & 0x0f;
2564 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2565 * if mu_edca was preset before and now it disappeared tell
2566 * the driver about it.
2568 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2569 if (count == link->u.mgd.wmm_last_param_set &&
2570 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
2572 link->u.mgd.wmm_last_param_set = count;
2573 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
2575 pos = wmm_param + 8;
2576 left = wmm_param_len - 8;
2578 memset(¶ms, 0, sizeof(params));
2581 for (; left >= 4; left -= 4, pos += 4) {
2582 int aci = (pos[0] >> 5) & 0x03;
2583 int acm = (pos[0] >> 4) & 0x01;
2588 ac = IEEE80211_AC_BK;
2590 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2591 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2593 params[ac].mu_edca = !!mu_edca;
2595 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2598 ac = IEEE80211_AC_VI;
2600 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2601 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2603 params[ac].mu_edca = !!mu_edca;
2605 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2608 ac = IEEE80211_AC_VO;
2610 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2611 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2613 params[ac].mu_edca = !!mu_edca;
2615 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2619 ac = IEEE80211_AC_BE;
2621 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2622 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2624 params[ac].mu_edca = !!mu_edca;
2626 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2630 params[ac].aifs = pos[0] & 0x0f;
2632 if (params[ac].aifs < 2) {
2634 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2635 params[ac].aifs, aci);
2636 params[ac].aifs = 2;
2638 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2639 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2640 params[ac].txop = get_unaligned_le16(pos + 2);
2641 params[ac].acm = acm;
2642 params[ac].uapsd = uapsd;
2644 if (params[ac].cw_min == 0 ||
2645 params[ac].cw_min > params[ac].cw_max) {
2647 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2648 params[ac].cw_min, params[ac].cw_max, aci);
2651 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2654 /* WMM specification requires all 4 ACIs. */
2655 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2656 if (params[ac].cw_min == 0) {
2658 "AP has invalid WMM params (missing AC %d), using defaults\n",
2664 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2665 link->tx_conf[ac] = params[ac];
2667 ieee80211_mgd_set_link_qos_params(link);
2669 /* enable WMM or activate new settings */
2670 link->conf->qos = true;
2674 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2676 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2678 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2679 ieee80211_run_deferred_scan(sdata->local);
2682 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2684 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2686 __ieee80211_stop_poll(sdata);
2689 static u64 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
2690 u16 capab, bool erp_valid, u8 erp)
2692 struct ieee80211_bss_conf *bss_conf = link->conf;
2693 struct ieee80211_supported_band *sband;
2695 bool use_protection;
2696 bool use_short_preamble;
2697 bool use_short_slot;
2699 sband = ieee80211_get_link_sband(link);
2704 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2705 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2707 use_protection = false;
2708 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2711 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2712 if (sband->band == NL80211_BAND_5GHZ ||
2713 sband->band == NL80211_BAND_6GHZ)
2714 use_short_slot = true;
2716 if (use_protection != bss_conf->use_cts_prot) {
2717 bss_conf->use_cts_prot = use_protection;
2718 changed |= BSS_CHANGED_ERP_CTS_PROT;
2721 if (use_short_preamble != bss_conf->use_short_preamble) {
2722 bss_conf->use_short_preamble = use_short_preamble;
2723 changed |= BSS_CHANGED_ERP_PREAMBLE;
2726 if (use_short_slot != bss_conf->use_short_slot) {
2727 bss_conf->use_short_slot = use_short_slot;
2728 changed |= BSS_CHANGED_ERP_SLOT;
2734 static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link,
2735 struct cfg80211_bss *cbss)
2737 struct ieee80211_sub_if_data *sdata = link->sdata;
2738 struct ieee80211_bss_conf *bss_conf = link->conf;
2739 struct ieee80211_bss *bss = (void *)cbss->priv;
2740 u64 changed = BSS_CHANGED_QOS;
2742 /* not really used in MLO */
2743 sdata->u.mgd.beacon_timeout =
2744 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
2745 bss_conf->beacon_int));
2747 changed |= ieee80211_handle_bss_capability(link,
2748 bss_conf->assoc_capability,
2752 ieee80211_check_rate_mask(link);
2754 link->u.mgd.bss = cbss;
2755 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2757 if (sdata->vif.p2p ||
2758 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2759 const struct cfg80211_bss_ies *ies;
2762 ies = rcu_dereference(cbss->ies);
2766 ret = cfg80211_get_p2p_attr(
2767 ies->data, ies->len,
2768 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2769 (u8 *) &bss_conf->p2p_noa_attr,
2770 sizeof(bss_conf->p2p_noa_attr));
2772 link->u.mgd.p2p_noa_index =
2773 bss_conf->p2p_noa_attr.index;
2774 changed |= BSS_CHANGED_P2P_PS;
2780 if (link->u.mgd.have_beacon) {
2781 bss_conf->beacon_rate = bss->beacon_rate;
2782 changed |= BSS_CHANGED_BEACON_INFO;
2784 bss_conf->beacon_rate = NULL;
2787 /* Tell the driver to monitor connection quality (if supported) */
2788 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2789 bss_conf->cqm_rssi_thold)
2790 changed |= BSS_CHANGED_CQM;
2795 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2796 struct ieee80211_mgd_assoc_data *assoc_data,
2797 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
2799 struct ieee80211_local *local = sdata->local;
2800 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
2801 u64 vif_changed = BSS_CHANGED_ASSOC;
2802 unsigned int link_id;
2804 lockdep_assert_wiphy(local->hw.wiphy);
2806 sdata->u.mgd.associated = true;
2808 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
2809 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2810 struct ieee80211_link_data *link;
2813 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2816 if (ieee80211_vif_is_mld(&sdata->vif) &&
2817 !(ieee80211_vif_usable_links(&sdata->vif) & BIT(link_id)))
2820 link = sdata_dereference(sdata->link[link_id], sdata);
2824 changed[link_id] |= ieee80211_link_set_associated(link, cbss);
2827 /* just to be sure */
2828 ieee80211_stop_poll(sdata);
2830 ieee80211_led_assoc(local, 1);
2834 /* Enable ARP filtering */
2835 if (vif_cfg->arp_addr_cnt)
2836 vif_changed |= BSS_CHANGED_ARP_FILTER;
2838 if (ieee80211_vif_is_mld(&sdata->vif)) {
2840 link_id < IEEE80211_MLD_MAX_NUM_LINKS;
2842 struct ieee80211_link_data *link;
2843 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2847 ieee80211_vif_usable_links(&sdata->vif)) ||
2848 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2851 link = sdata_dereference(sdata->link[link_id], sdata);
2855 ieee80211_link_info_change_notify(sdata, link,
2858 ieee80211_recalc_smps(sdata, link);
2861 ieee80211_vif_cfg_change_notify(sdata, vif_changed);
2863 ieee80211_bss_info_change_notify(sdata,
2864 vif_changed | changed[0]);
2867 ieee80211_recalc_ps(local);
2869 /* leave this here to not change ordering in non-MLO cases */
2870 if (!ieee80211_vif_is_mld(&sdata->vif))
2871 ieee80211_recalc_smps(sdata, &sdata->deflink);
2872 ieee80211_recalc_ps_vif(sdata);
2874 netif_carrier_on(sdata->dev);
2877 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2878 u16 stype, u16 reason, bool tx,
2881 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2882 struct ieee80211_local *local = sdata->local;
2883 unsigned int link_id;
2885 struct ieee80211_prep_tx_info info = {
2889 lockdep_assert_wiphy(local->hw.wiphy);
2891 if (WARN_ON_ONCE(tx && !frame_buf))
2894 if (WARN_ON(!ifmgd->associated))
2897 ieee80211_stop_poll(sdata);
2899 ifmgd->associated = false;
2901 /* other links will be destroyed */
2902 sdata->deflink.u.mgd.bss = NULL;
2904 netif_carrier_off(sdata->dev);
2907 * if we want to get out of ps before disassoc (why?) we have
2908 * to do it before sending disassoc, as otherwise the null-packet
2911 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2912 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2913 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2915 local->ps_sdata = NULL;
2917 /* disable per-vif ps */
2918 ieee80211_recalc_ps_vif(sdata);
2920 /* make sure ongoing transmission finishes */
2924 * drop any frame before deauth/disassoc, this can be data or
2925 * management frame. Since we are disconnecting, we should not
2926 * insist sending these frames which can take time and delay
2927 * the disconnection and possible the roaming.
2930 ieee80211_flush_queues(local, sdata, true);
2932 /* deauthenticate/disassociate now */
2933 if (tx || frame_buf) {
2935 * In multi channel scenarios guarantee that the virtual
2936 * interface is granted immediate airtime to transmit the
2937 * deauthentication frame by calling mgd_prepare_tx, if the
2938 * driver requested so.
2940 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP)) {
2941 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link);
2943 struct ieee80211_link_data *link;
2945 link = sdata_dereference(sdata->link[link_id],
2949 if (link->u.mgd.have_beacon)
2952 if (link_id == IEEE80211_MLD_MAX_NUM_LINKS) {
2953 info.link_id = ffs(sdata->vif.active_links) - 1;
2954 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2958 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
2959 sdata->vif.cfg.ap_addr, stype,
2960 reason, tx, frame_buf);
2963 /* flush out frame - make sure the deauth was actually sent */
2965 ieee80211_flush_queues(local, sdata, false);
2967 drv_mgd_complete_tx(sdata->local, sdata, &info);
2969 /* clear AP addr only after building the needed mgmt frames */
2970 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2971 eth_zero_addr(sdata->vif.cfg.ap_addr);
2973 sdata->vif.cfg.ssid_len = 0;
2975 /* remove AP and TDLS peers */
2976 sta_info_flush(sdata);
2978 /* finally reset all BSS / config parameters */
2979 if (!ieee80211_vif_is_mld(&sdata->vif))
2980 changed |= ieee80211_reset_erp_info(sdata);
2982 ieee80211_led_assoc(local, 0);
2983 changed |= BSS_CHANGED_ASSOC;
2984 sdata->vif.cfg.assoc = false;
2986 sdata->deflink.u.mgd.p2p_noa_index = -1;
2987 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2988 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2990 /* on the next assoc, re-program HT/VHT parameters */
2991 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2992 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2993 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2994 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2997 * reset MU-MIMO ownership and group data in default link,
2998 * if used, other links are destroyed
3000 memset(sdata->vif.bss_conf.mu_group.membership, 0,
3001 sizeof(sdata->vif.bss_conf.mu_group.membership));
3002 memset(sdata->vif.bss_conf.mu_group.position, 0,
3003 sizeof(sdata->vif.bss_conf.mu_group.position));
3004 if (!ieee80211_vif_is_mld(&sdata->vif))
3005 changed |= BSS_CHANGED_MU_GROUPS;
3006 sdata->vif.bss_conf.mu_mimo_owner = false;
3008 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
3010 del_timer_sync(&local->dynamic_ps_timer);
3011 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work);
3013 /* Disable ARP filtering */
3014 if (sdata->vif.cfg.arp_addr_cnt)
3015 changed |= BSS_CHANGED_ARP_FILTER;
3017 sdata->vif.bss_conf.qos = false;
3018 if (!ieee80211_vif_is_mld(&sdata->vif)) {
3019 changed |= BSS_CHANGED_QOS;
3020 /* The BSSID (not really interesting) and HT changed */
3021 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
3022 ieee80211_bss_info_change_notify(sdata, changed);
3024 ieee80211_vif_cfg_change_notify(sdata, changed);
3027 /* disassociated - set to defaults now */
3028 ieee80211_set_wmm_default(&sdata->deflink, false, false);
3030 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
3031 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
3032 del_timer_sync(&sdata->u.mgd.timer);
3034 sdata->vif.bss_conf.dtim_period = 0;
3035 sdata->vif.bss_conf.beacon_rate = NULL;
3037 sdata->deflink.u.mgd.have_beacon = false;
3038 sdata->deflink.u.mgd.tracking_signal_avg = false;
3039 sdata->deflink.u.mgd.disable_wmm_tracking = false;
3042 sdata->deflink.u.mgd.conn_flags = 0;
3044 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3045 struct ieee80211_link_data *link;
3047 link = sdata_dereference(sdata->link[link_id], sdata);
3050 ieee80211_link_release_channel(link);
3053 sdata->vif.bss_conf.csa_active = false;
3054 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3055 sdata->deflink.u.mgd.csa_ignored_same_chan = false;
3056 if (sdata->deflink.csa_block_tx) {
3057 ieee80211_wake_vif_queues(local, sdata,
3058 IEEE80211_QUEUE_STOP_REASON_CSA);
3059 sdata->deflink.csa_block_tx = false;
3062 /* existing TX TSPEC sessions no longer exist */
3063 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
3064 wiphy_delayed_work_cancel(local->hw.wiphy, &ifmgd->tx_tspec_wk);
3066 sdata->vif.bss_conf.pwr_reduction = 0;
3067 sdata->vif.bss_conf.tx_pwr_env_num = 0;
3068 memset(sdata->vif.bss_conf.tx_pwr_env, 0,
3069 sizeof(sdata->vif.bss_conf.tx_pwr_env));
3071 memset(&sdata->u.mgd.ttlm_info, 0,
3072 sizeof(sdata->u.mgd.ttlm_info));
3073 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
3074 ieee80211_vif_set_links(sdata, 0, 0);
3077 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
3079 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3080 struct ieee80211_local *local = sdata->local;
3082 lockdep_assert_wiphy(local->hw.wiphy);
3084 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
3087 __ieee80211_stop_poll(sdata);
3089 ieee80211_recalc_ps(local);
3091 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3095 * We've received a probe response, but are not sure whether
3096 * we have or will be receiving any beacons or data, so let's
3097 * schedule the timers again, just in case.
3099 ieee80211_sta_reset_beacon_monitor(sdata);
3101 mod_timer(&ifmgd->conn_mon_timer,
3102 round_jiffies_up(jiffies +
3103 IEEE80211_CONNECTION_IDLE_TIME));
3106 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
3107 struct ieee80211_hdr *hdr,
3110 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3113 struct ieee80211_sta_tx_tspec *tx_tspec;
3114 unsigned long now = jiffies;
3116 if (!ieee80211_is_data_qos(hdr->frame_control))
3119 tid = ieee80211_get_tid(hdr);
3120 ac = ieee80211_ac_from_tid(tid);
3121 tx_tspec = &ifmgd->tx_tspec[ac];
3123 if (likely(!tx_tspec->admitted_time))
3126 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3127 tx_tspec->consumed_tx_time = 0;
3128 tx_tspec->time_slice_start = now;
3130 if (tx_tspec->downgraded) {
3131 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3132 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
3133 &ifmgd->tx_tspec_wk, 0);
3137 if (tx_tspec->downgraded)
3140 tx_tspec->consumed_tx_time += tx_time;
3142 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
3143 tx_tspec->downgraded = true;
3144 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
3145 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
3146 &ifmgd->tx_tspec_wk, 0);
3150 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
3151 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
3153 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
3155 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
3156 !sdata->u.mgd.probe_send_count)
3160 sdata->u.mgd.probe_send_count = 0;
3162 sdata->u.mgd.nullfunc_failed = true;
3163 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
3166 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
3167 const u8 *src, const u8 *dst,
3168 const u8 *ssid, size_t ssid_len,
3169 struct ieee80211_channel *channel)
3171 struct sk_buff *skb;
3173 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
3174 ssid, ssid_len, NULL, 0,
3175 IEEE80211_PROBE_FLAG_DIRECTED);
3177 ieee80211_tx_skb(sdata, skb);
3180 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
3182 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3183 u8 *dst = sdata->vif.cfg.ap_addr;
3184 u8 unicast_limit = max(1, max_probe_tries - 3);
3185 struct sta_info *sta;
3187 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3189 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
3193 * Try sending broadcast probe requests for the last three
3194 * probe requests after the first ones failed since some
3195 * buggy APs only support broadcast probe requests.
3197 if (ifmgd->probe_send_count >= unicast_limit)
3201 * When the hardware reports an accurate Tx ACK status, it's
3202 * better to send a nullfunc frame instead of a probe request,
3203 * as it will kick us off the AP quickly if we aren't associated
3204 * anymore. The timeout will be reset if the frame is ACKed by
3207 ifmgd->probe_send_count++;
3210 sta = sta_info_get(sdata, dst);
3212 ieee80211_check_fast_rx(sta);
3215 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
3216 ifmgd->nullfunc_failed = false;
3217 ieee80211_send_nullfunc(sdata->local, sdata, false);
3219 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
3220 sdata->vif.cfg.ssid,
3221 sdata->vif.cfg.ssid_len,
3222 sdata->deflink.u.mgd.bss->channel);
3225 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
3226 run_again(sdata, ifmgd->probe_timeout);
3229 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
3232 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3233 bool already = false;
3235 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3237 if (WARN_ON_ONCE(ieee80211_vif_is_mld(&sdata->vif)))
3240 if (!ieee80211_sdata_running(sdata))
3243 if (!ifmgd->associated)
3246 if (sdata->local->tmp_channel || sdata->local->scanning)
3249 if (sdata->local->suspending) {
3250 /* reschedule after resume */
3251 ieee80211_reset_ap_probe(sdata);
3256 mlme_dbg_ratelimited(sdata,
3257 "detected beacon loss from AP (missed %d beacons) - probing\n",
3260 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
3264 * The driver/our work has already reported this event or the
3265 * connection monitoring has kicked in and we have already sent
3266 * a probe request. Or maybe the AP died and the driver keeps
3267 * reporting until we disassociate...
3269 * In either case we have to ignore the current call to this
3270 * function (except for setting the correct probe reason bit)
3271 * because otherwise we would reset the timer every time and
3272 * never check whether we received a probe response!
3274 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
3277 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
3282 ieee80211_recalc_ps(sdata->local);
3284 ifmgd->probe_send_count = 0;
3285 ieee80211_mgd_probe_ap_send(sdata);
3288 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
3289 struct ieee80211_vif *vif)
3291 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3292 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3293 struct cfg80211_bss *cbss;
3294 struct sk_buff *skb;
3295 const struct element *ssid;
3298 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3300 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
3301 ieee80211_vif_is_mld(&sdata->vif)))
3304 if (ifmgd->associated)
3305 cbss = sdata->deflink.u.mgd.bss;
3306 else if (ifmgd->auth_data)
3307 cbss = ifmgd->auth_data->bss;
3308 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
3309 cbss = ifmgd->assoc_data->link[0].bss;
3314 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
3315 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
3316 "invalid SSID element (len=%d)",
3317 ssid ? ssid->datalen : -1))
3320 ssid_len = ssid->datalen;
3322 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
3323 (u32) -1, cbss->channel,
3324 ssid->data, ssid_len,
3325 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
3330 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
3332 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
3333 const u8 *buf, size_t len, bool tx,
3334 u16 reason, bool reconnect)
3336 struct ieee80211_event event = {
3338 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
3339 .u.mlme.reason = reason,
3343 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
3345 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
3347 drv_event_callback(sdata->local, sdata, &event);
3350 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
3352 struct ieee80211_local *local = sdata->local;
3353 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3354 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3357 lockdep_assert_wiphy(local->hw.wiphy);
3359 if (!ifmgd->associated)
3362 /* in MLO assume we have a link where we can TX the frame */
3363 tx = ieee80211_vif_is_mld(&sdata->vif) ||
3364 !sdata->deflink.csa_block_tx;
3366 if (!ifmgd->driver_disconnect) {
3367 unsigned int link_id;
3370 * AP is probably out of range (or not reachable for another
3371 * reason) so remove the bss structs for that AP. In the case
3372 * of multi-link, it's not clear that all of them really are
3373 * out of range, but if they weren't the driver likely would
3374 * have switched to just have a single link active?
3377 link_id < ARRAY_SIZE(sdata->link);
3379 struct ieee80211_link_data *link;
3381 link = sdata_dereference(sdata->link[link_id], sdata);
3384 cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
3385 link->u.mgd.bss = NULL;
3389 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3390 ifmgd->driver_disconnect ?
3391 WLAN_REASON_DEAUTH_LEAVING :
3392 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3394 /* the other links will be destroyed */
3395 sdata->vif.bss_conf.csa_active = false;
3396 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3397 if (sdata->deflink.csa_block_tx) {
3398 ieee80211_wake_vif_queues(local, sdata,
3399 IEEE80211_QUEUE_STOP_REASON_CSA);
3400 sdata->deflink.csa_block_tx = false;
3403 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
3404 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3406 ifmgd->reconnect = false;
3409 static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy,
3410 struct wiphy_work *work)
3412 struct ieee80211_sub_if_data *sdata =
3413 container_of(work, struct ieee80211_sub_if_data,
3414 u.mgd.beacon_connection_loss_work);
3415 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3417 if (ifmgd->connection_loss) {
3418 sdata_info(sdata, "Connection to AP %pM lost\n",
3419 sdata->vif.cfg.ap_addr);
3420 __ieee80211_disconnect(sdata);
3421 ifmgd->connection_loss = false;
3422 } else if (ifmgd->driver_disconnect) {
3424 "Driver requested disconnection from AP %pM\n",
3425 sdata->vif.cfg.ap_addr);
3426 __ieee80211_disconnect(sdata);
3427 ifmgd->driver_disconnect = false;
3429 if (ifmgd->associated)
3430 sdata->deflink.u.mgd.beacon_loss_count++;
3431 ieee80211_mgd_probe_ap(sdata, true);
3435 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy,
3436 struct wiphy_work *work)
3438 struct ieee80211_sub_if_data *sdata =
3439 container_of(work, struct ieee80211_sub_if_data,
3440 u.mgd.csa_connection_drop_work);
3442 __ieee80211_disconnect(sdata);
3445 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
3447 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3448 struct ieee80211_hw *hw = &sdata->local->hw;
3450 trace_api_beacon_loss(sdata);
3452 sdata->u.mgd.connection_loss = false;
3453 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3455 EXPORT_SYMBOL(ieee80211_beacon_loss);
3457 void ieee80211_connection_loss(struct ieee80211_vif *vif)
3459 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3460 struct ieee80211_hw *hw = &sdata->local->hw;
3462 trace_api_connection_loss(sdata);
3464 sdata->u.mgd.connection_loss = true;
3465 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3467 EXPORT_SYMBOL(ieee80211_connection_loss);
3469 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
3471 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3472 struct ieee80211_hw *hw = &sdata->local->hw;
3474 trace_api_disconnect(sdata, reconnect);
3476 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
3479 sdata->u.mgd.driver_disconnect = true;
3480 sdata->u.mgd.reconnect = reconnect;
3481 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3483 EXPORT_SYMBOL(ieee80211_disconnect);
3485 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
3488 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3490 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3494 * we are not authenticated yet, the only timer that could be
3495 * running is the timeout for the authentication response which
3496 * which is not relevant anymore.
3498 del_timer_sync(&sdata->u.mgd.timer);
3499 sta_info_destroy_addr(sdata, auth_data->ap_addr);
3501 /* other links are destroyed */
3502 sdata->deflink.u.mgd.conn_flags = 0;
3503 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3504 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3506 sdata->u.mgd.flags = 0;
3508 ieee80211_link_release_channel(&sdata->deflink);
3509 ieee80211_vif_set_links(sdata, 0, 0);
3512 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
3514 sdata->u.mgd.auth_data = NULL;
3524 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3525 enum assoc_status status)
3527 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3529 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3531 if (status != ASSOC_SUCCESS) {
3533 * we are not associated yet, the only timer that could be
3534 * running is the timeout for the association response which
3535 * which is not relevant anymore.
3537 del_timer_sync(&sdata->u.mgd.timer);
3538 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
3540 sdata->deflink.u.mgd.conn_flags = 0;
3541 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3542 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3544 sdata->u.mgd.flags = 0;
3545 sdata->vif.bss_conf.mu_mimo_owner = false;
3547 if (status != ASSOC_REJECTED) {
3548 struct cfg80211_assoc_failure data = {
3549 .timeout = status == ASSOC_TIMEOUT,
3553 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
3554 ARRAY_SIZE(assoc_data->link));
3556 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
3557 data.bss[i] = assoc_data->link[i].bss;
3559 if (ieee80211_vif_is_mld(&sdata->vif))
3560 data.ap_mld_addr = assoc_data->ap_addr;
3562 cfg80211_assoc_failure(sdata->dev, &data);
3565 ieee80211_link_release_channel(&sdata->deflink);
3566 ieee80211_vif_set_links(sdata, 0, 0);
3570 sdata->u.mgd.assoc_data = NULL;
3573 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3574 struct ieee80211_mgmt *mgmt, size_t len)
3576 struct ieee80211_local *local = sdata->local;
3577 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3578 const struct element *challenge;
3581 struct ieee80211_prep_tx_info info = {
3582 .subtype = IEEE80211_STYPE_AUTH,
3583 .link_id = auth_data->link_id,
3586 pos = mgmt->u.auth.variable;
3587 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3588 len - (pos - (u8 *)mgmt));
3591 auth_data->expected_transaction = 4;
3592 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3593 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3594 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3595 IEEE80211_TX_INTFL_MLME_CONN_TX;
3596 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3598 challenge->datalen + sizeof(*challenge),
3599 auth_data->ap_addr, auth_data->ap_addr,
3600 auth_data->key, auth_data->key_len,
3601 auth_data->key_idx, tx_flags);
3604 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
3606 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3607 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
3608 struct sta_info *sta;
3610 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3612 sdata_info(sdata, "authenticated\n");
3613 ifmgd->auth_data->done = true;
3614 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3615 ifmgd->auth_data->timeout_started = true;
3616 run_again(sdata, ifmgd->auth_data->timeout);
3618 /* move station state to auth */
3619 sta = sta_info_get(sdata, ap_addr);
3621 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3624 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3625 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3632 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3633 struct ieee80211_mgmt *mgmt, size_t len)
3635 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3636 u16 auth_alg, auth_transaction, status_code;
3637 struct ieee80211_event event = {
3639 .u.mlme.data = AUTH_EVENT,
3641 struct ieee80211_prep_tx_info info = {
3642 .subtype = IEEE80211_STYPE_AUTH,
3645 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3650 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3653 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
3656 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3657 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3658 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3660 if (auth_alg != ifmgd->auth_data->algorithm ||
3661 (auth_alg != WLAN_AUTH_SAE &&
3662 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3663 (auth_alg == WLAN_AUTH_SAE &&
3664 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3665 auth_transaction > 2))) {
3666 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3667 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3669 ifmgd->auth_data->expected_transaction);
3673 if (status_code != WLAN_STATUS_SUCCESS) {
3674 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3676 if (auth_alg == WLAN_AUTH_SAE &&
3677 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3678 (auth_transaction == 1 &&
3679 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3680 status_code == WLAN_STATUS_SAE_PK)))) {
3681 /* waiting for userspace now */
3682 ifmgd->auth_data->waiting = true;
3683 ifmgd->auth_data->timeout =
3684 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3685 ifmgd->auth_data->timeout_started = true;
3686 run_again(sdata, ifmgd->auth_data->timeout);
3690 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3691 mgmt->sa, status_code);
3692 ieee80211_destroy_auth_data(sdata, false);
3693 event.u.mlme.status = MLME_DENIED;
3694 event.u.mlme.reason = status_code;
3695 drv_event_callback(sdata->local, sdata, &event);
3699 switch (ifmgd->auth_data->algorithm) {
3700 case WLAN_AUTH_OPEN:
3701 case WLAN_AUTH_LEAP:
3704 case WLAN_AUTH_FILS_SK:
3705 case WLAN_AUTH_FILS_SK_PFS:
3706 case WLAN_AUTH_FILS_PK:
3708 case WLAN_AUTH_SHARED_KEY:
3709 if (ifmgd->auth_data->expected_transaction != 4) {
3710 ieee80211_auth_challenge(sdata, mgmt, len);
3711 /* need another frame */
3716 WARN_ONCE(1, "invalid auth alg %d",
3717 ifmgd->auth_data->algorithm);
3721 event.u.mlme.status = MLME_SUCCESS;
3723 drv_event_callback(sdata->local, sdata, &event);
3724 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3725 (auth_transaction == 2 &&
3726 ifmgd->auth_data->expected_transaction == 2)) {
3727 if (!ieee80211_mark_sta_auth(sdata))
3728 return; /* ignore frame -- wait for timeout */
3729 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3730 auth_transaction == 2) {
3731 sdata_info(sdata, "SAE peer confirmed\n");
3732 ifmgd->auth_data->peer_confirmed = true;
3735 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3737 drv_mgd_complete_tx(sdata->local, sdata, &info);
3740 #define case_WLAN(type) \
3741 case WLAN_REASON_##type: return #type
3743 const char *ieee80211_get_reason_code_string(u16 reason_code)
3745 switch (reason_code) {
3746 case_WLAN(UNSPECIFIED);
3747 case_WLAN(PREV_AUTH_NOT_VALID);
3748 case_WLAN(DEAUTH_LEAVING);
3749 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3750 case_WLAN(DISASSOC_AP_BUSY);
3751 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3752 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3753 case_WLAN(DISASSOC_STA_HAS_LEFT);
3754 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3755 case_WLAN(DISASSOC_BAD_POWER);
3756 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3757 case_WLAN(INVALID_IE);
3758 case_WLAN(MIC_FAILURE);
3759 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3760 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3761 case_WLAN(IE_DIFFERENT);
3762 case_WLAN(INVALID_GROUP_CIPHER);
3763 case_WLAN(INVALID_PAIRWISE_CIPHER);
3764 case_WLAN(INVALID_AKMP);
3765 case_WLAN(UNSUPP_RSN_VERSION);
3766 case_WLAN(INVALID_RSN_IE_CAP);
3767 case_WLAN(IEEE8021X_FAILED);
3768 case_WLAN(CIPHER_SUITE_REJECTED);
3769 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3770 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3771 case_WLAN(DISASSOC_LOW_ACK);
3772 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3773 case_WLAN(QSTA_LEAVE_QBSS);
3774 case_WLAN(QSTA_NOT_USE);
3775 case_WLAN(QSTA_REQUIRE_SETUP);
3776 case_WLAN(QSTA_TIMEOUT);
3777 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3778 case_WLAN(MESH_PEER_CANCELED);
3779 case_WLAN(MESH_MAX_PEERS);
3780 case_WLAN(MESH_CONFIG);
3781 case_WLAN(MESH_CLOSE);
3782 case_WLAN(MESH_MAX_RETRIES);
3783 case_WLAN(MESH_CONFIRM_TIMEOUT);
3784 case_WLAN(MESH_INVALID_GTK);
3785 case_WLAN(MESH_INCONSISTENT_PARAM);
3786 case_WLAN(MESH_INVALID_SECURITY);
3787 case_WLAN(MESH_PATH_ERROR);
3788 case_WLAN(MESH_PATH_NOFORWARD);
3789 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3790 case_WLAN(MAC_EXISTS_IN_MBSS);
3791 case_WLAN(MESH_CHAN_REGULATORY);
3792 case_WLAN(MESH_CHAN);
3793 default: return "<unknown>";
3797 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3798 struct ieee80211_mgmt *mgmt, size_t len)
3800 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3801 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3803 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3808 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3809 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3813 if (ifmgd->associated &&
3814 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
3815 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3816 sdata->vif.cfg.ap_addr, reason_code,
3817 ieee80211_get_reason_code_string(reason_code));
3819 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3821 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3822 reason_code, false);
3826 if (ifmgd->assoc_data &&
3827 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
3829 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3830 ifmgd->assoc_data->ap_addr, reason_code,
3831 ieee80211_get_reason_code_string(reason_code));
3833 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3835 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3841 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3842 struct ieee80211_mgmt *mgmt, size_t len)
3844 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3847 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3852 if (!ifmgd->associated ||
3853 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
3856 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3858 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3859 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3863 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3864 sdata->vif.cfg.ap_addr, reason_code,
3865 ieee80211_get_reason_code_string(reason_code));
3867 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3869 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3873 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3874 u8 *supp_rates, unsigned int supp_rates_len,
3875 u32 *rates, u32 *basic_rates,
3876 bool *have_higher_than_11mbit,
3877 int *min_rate, int *min_rate_index)
3881 for (i = 0; i < supp_rates_len; i++) {
3882 int rate = supp_rates[i] & 0x7f;
3883 bool is_basic = !!(supp_rates[i] & 0x80);
3885 if ((rate * 5) > 110)
3886 *have_higher_than_11mbit = true;
3889 * Skip HT, VHT, HE, EHT and SAE H2E only BSS membership
3890 * selectors since they're not rates.
3892 * Note: Even though the membership selector and the basic
3893 * rate flag share the same bit, they are not exactly
3896 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3897 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3898 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3899 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_EHT_PHY) ||
3900 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3903 for (j = 0; j < sband->n_bitrates; j++) {
3904 struct ieee80211_rate *br;
3907 br = &sband->bitrates[j];
3909 brate = DIV_ROUND_UP(br->bitrate, 5);
3910 if (brate == rate) {
3913 *basic_rates |= BIT(j);
3914 if ((rate * 5) < *min_rate) {
3915 *min_rate = rate * 5;
3916 *min_rate_index = j;
3924 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
3925 struct ieee80211_supported_band *sband,
3926 const struct link_sta_info *link_sta,
3927 const struct ieee802_11_elems *elems)
3929 const struct ieee80211_sta_he_cap *own_he_cap =
3930 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3932 if (elems->ext_capab_len < 10)
3935 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3938 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3939 IEEE80211_HE_MAC_CAP0_TWT_RES &&
3941 (own_he_cap->he_cap_elem.mac_cap_info[0] &
3942 IEEE80211_HE_MAC_CAP0_TWT_REQ);
3945 static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3946 struct ieee80211_supported_band *sband,
3947 struct ieee80211_link_data *link,
3948 struct link_sta_info *link_sta,
3949 struct ieee802_11_elems *elems)
3951 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
3953 if (link->conf->twt_requester != twt) {
3954 link->conf->twt_requester = twt;
3955 return BSS_CHANGED_TWT;
3960 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3961 struct ieee80211_bss_conf *bss_conf,
3962 struct ieee80211_supported_band *sband,
3963 struct link_sta_info *link_sta)
3965 const struct ieee80211_sta_he_cap *own_he_cap =
3966 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3968 return bss_conf->he_support &&
3969 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3970 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3972 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3973 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3976 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
3977 struct link_sta_info *link_sta,
3978 struct cfg80211_bss *cbss,
3979 struct ieee80211_mgmt *mgmt,
3980 const u8 *elem_start,
3981 unsigned int elem_len,
3984 struct ieee80211_sub_if_data *sdata = link->sdata;
3985 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3986 struct ieee80211_bss_conf *bss_conf = link->conf;
3987 struct ieee80211_local *local = sdata->local;
3988 unsigned int link_id = link->link_id;
3989 struct ieee80211_elems_parse_params parse_params = {
3990 .start = elem_start,
3992 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
3995 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3996 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3997 const struct cfg80211_bss_ies *bss_ies = NULL;
3998 struct ieee80211_supported_band *sband;
3999 struct ieee802_11_elems *elems;
4000 const __le16 prof_bss_param_ch_present =
4001 cpu_to_le16(IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT);
4005 elems = ieee802_11_parse_elems_full(&parse_params);
4009 if (link_id == assoc_data->assoc_link_id) {
4010 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
4013 * we should not get to this flow unless the association was
4014 * successful, so set the status directly to success
4016 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
4017 if (elems->ml_basic) {
4018 if (!(elems->ml_basic->control &
4019 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT))) {
4023 link->u.mgd.bss_param_ch_cnt =
4024 ieee80211_mle_get_bss_param_ch_cnt(elems->ml_basic);
4026 } else if (!elems->prof ||
4027 !(elems->prof->control & prof_bss_param_ch_present)) {
4031 const u8 *ptr = elems->prof->variable +
4032 elems->prof->sta_info_len - 1;
4035 * During parsing, we validated that these fields exist,
4036 * otherwise elems->prof would have been set to NULL.
4038 capab_info = get_unaligned_le16(ptr);
4039 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
4040 link->u.mgd.bss_param_ch_cnt =
4041 ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(elems->prof);
4043 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
4044 link_info(link, "association response status code=%u\n",
4045 assoc_data->link[link_id].status);
4051 if (!is_s1g && !elems->supp_rates) {
4052 sdata_info(sdata, "no SuppRates element in AssocResp\n");
4057 link->u.mgd.tdls_chan_switch_prohibited =
4058 elems->ext_capab && elems->ext_capab_len >= 5 &&
4059 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
4062 * Some APs are erroneously not including some information in their
4063 * (re)association response frames. Try to recover by using the data
4064 * from the beacon or probe response. This seems to afflict mobile
4065 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
4066 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
4069 ((assoc_data->wmm && !elems->wmm_param) ||
4070 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4071 (!elems->ht_cap_elem || !elems->ht_operation)) ||
4072 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4073 (!elems->vht_cap_elem || !elems->vht_operation)))) {
4074 const struct cfg80211_bss_ies *ies;
4075 struct ieee802_11_elems *bss_elems;
4078 ies = rcu_dereference(cbss->ies);
4080 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
4088 parse_params.start = bss_ies->data;
4089 parse_params.len = bss_ies->len;
4090 parse_params.bss = cbss;
4091 bss_elems = ieee802_11_parse_elems_full(&parse_params);
4097 if (assoc_data->wmm &&
4098 !elems->wmm_param && bss_elems->wmm_param) {
4099 elems->wmm_param = bss_elems->wmm_param;
4101 "AP bug: WMM param missing from AssocResp\n");
4105 * Also check if we requested HT/VHT, otherwise the AP doesn't
4106 * have to include the IEs in the (re)association response.
4108 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
4109 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4110 elems->ht_cap_elem = bss_elems->ht_cap_elem;
4112 "AP bug: HT capability missing from AssocResp\n");
4114 if (!elems->ht_operation && bss_elems->ht_operation &&
4115 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4116 elems->ht_operation = bss_elems->ht_operation;
4118 "AP bug: HT operation missing from AssocResp\n");
4120 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
4121 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4122 elems->vht_cap_elem = bss_elems->vht_cap_elem;
4124 "AP bug: VHT capa missing from AssocResp\n");
4126 if (!elems->vht_operation && bss_elems->vht_operation &&
4127 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4128 elems->vht_operation = bss_elems->vht_operation;
4130 "AP bug: VHT operation missing from AssocResp\n");
4137 * We previously checked these in the beacon/probe response, so
4138 * they should be present here. This is just a safety net.
4140 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4141 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
4143 "HT AP is missing WMM params or HT capability/operation\n");
4148 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4149 (!elems->vht_cap_elem || !elems->vht_operation)) {
4151 "VHT AP is missing VHT capability/operation\n");
4156 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4157 !elems->he_6ghz_capa) {
4159 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
4164 if (WARN_ON(!link->conf->chandef.chan)) {
4168 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
4170 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4171 (!elems->he_cap || !elems->he_operation)) {
4173 "HE AP is missing HE capability/operation\n");
4178 /* Set up internal HT/VHT capabilities */
4179 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
4180 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
4184 if (elems->vht_cap_elem &&
4185 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4186 const struct ieee80211_vht_cap *bss_vht_cap = NULL;
4187 const struct cfg80211_bss_ies *ies;
4190 * Cisco AP module 9115 with FW 17.3 has a bug and sends a
4191 * too large maximum MPDU length in the association response
4192 * (indicating 12k) that it cannot actually process ...
4196 ies = rcu_dereference(cbss->ies);
4198 const struct element *elem;
4200 elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY,
4201 ies->data, ies->len);
4202 if (elem && elem->datalen >= sizeof(*bss_vht_cap))
4203 bss_vht_cap = (const void *)elem->data;
4206 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4207 elems->vht_cap_elem,
4208 bss_vht_cap, link_sta);
4212 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4214 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
4217 elems->he_6ghz_capa,
4220 bss_conf->he_support = link_sta->pub->he_cap.has_he;
4221 if (elems->rsnx && elems->rsnx_len &&
4222 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
4223 wiphy_ext_feature_isset(local->hw.wiphy,
4224 NL80211_EXT_FEATURE_PROTECTED_TWT))
4225 bss_conf->twt_protected = true;
4227 bss_conf->twt_protected = false;
4229 *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
4232 if (elems->eht_operation && elems->eht_cap &&
4233 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
4234 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
4241 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
4242 *changed |= BSS_CHANGED_EHT_PUNCTURING;
4244 bss_conf->eht_support = false;
4247 bss_conf->he_support = false;
4248 bss_conf->twt_requester = false;
4249 bss_conf->twt_protected = false;
4250 bss_conf->eht_support = false;
4253 bss_conf->twt_broadcast =
4254 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
4256 if (bss_conf->he_support) {
4257 bss_conf->he_bss_color.color =
4258 le32_get_bits(elems->he_operation->he_oper_params,
4259 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
4260 bss_conf->he_bss_color.partial =
4261 le32_get_bits(elems->he_operation->he_oper_params,
4262 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
4263 bss_conf->he_bss_color.enabled =
4264 !le32_get_bits(elems->he_operation->he_oper_params,
4265 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
4267 if (bss_conf->he_bss_color.enabled)
4268 *changed |= BSS_CHANGED_HE_BSS_COLOR;
4270 bss_conf->htc_trig_based_pkt_ext =
4271 le32_get_bits(elems->he_operation->he_oper_params,
4272 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
4273 bss_conf->frame_time_rts_th =
4274 le32_get_bits(elems->he_operation->he_oper_params,
4275 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
4277 bss_conf->uora_exists = !!elems->uora_element;
4278 if (elems->uora_element)
4279 bss_conf->uora_ocw_range = elems->uora_element[0];
4281 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
4282 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
4283 /* TODO: OPEN: what happens if BSS color disable is set? */
4286 if (cbss->transmitted_bss) {
4287 bss_conf->nontransmitted = true;
4288 ether_addr_copy(bss_conf->transmitter_bssid,
4289 cbss->transmitted_bss->bssid);
4290 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
4291 bss_conf->bssid_index = cbss->bssid_index;
4295 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
4296 * in their association response, so ignore that data for our own
4297 * configuration. If it changed since the last beacon, we'll get the
4298 * next beacon and update then.
4302 * If an operating mode notification IE is present, override the
4303 * NSS calculation (that would be done in rate_control_rate_init())
4304 * and use the # of streams from that element.
4306 if (elems->opmode_notif &&
4307 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
4310 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
4311 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
4313 link_sta->pub->rx_nss = nss;
4317 * Always handle WMM once after association regardless
4318 * of the first value the AP uses. Setting -1 here has
4319 * that effect because the AP values is an unsigned
4322 link->u.mgd.wmm_last_param_set = -1;
4323 link->u.mgd.mu_edca_last_param_set = -1;
4325 if (link->u.mgd.disable_wmm_tracking) {
4326 ieee80211_set_wmm_default(link, false, false);
4327 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4328 elems->wmm_param_len,
4329 elems->mu_edca_param_set)) {
4330 /* still enable QoS since we might have HT/VHT */
4331 ieee80211_set_wmm_default(link, false, true);
4332 /* disable WMM tracking in this case to disable
4333 * tracking WMM parameter changes in the beacon if
4334 * the parameters weren't actually valid. Doing so
4335 * avoids changing parameters very strangely when
4336 * the AP is going back and forth between valid and
4337 * invalid parameters.
4339 link->u.mgd.disable_wmm_tracking = true;
4342 if (elems->max_idle_period_ie) {
4343 bss_conf->max_idle_period =
4344 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
4345 bss_conf->protected_keep_alive =
4346 !!(elems->max_idle_period_ie->idle_options &
4347 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
4348 *changed |= BSS_CHANGED_KEEP_ALIVE;
4350 bss_conf->max_idle_period = 0;
4351 bss_conf->protected_keep_alive = false;
4354 /* set assoc capability (AID was already set earlier),
4355 * ieee80211_set_associated() will tell the driver */
4356 bss_conf->assoc_capability = capab_info;
4365 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
4366 struct sta_info *sta,
4367 struct link_sta_info *link_sta,
4368 struct cfg80211_bss *cbss)
4370 struct ieee80211_sub_if_data *sdata = link->sdata;
4371 struct ieee80211_local *local = sdata->local;
4372 struct ieee80211_bss *bss = (void *)cbss->priv;
4373 u32 rates = 0, basic_rates = 0;
4374 bool have_higher_than_11mbit = false;
4375 int min_rate = INT_MAX, min_rate_index = -1;
4376 struct ieee80211_supported_band *sband;
4378 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
4379 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
4381 /* TODO: S1G Basic Rate Set is expressed elsewhere */
4382 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
4383 ieee80211_s1g_sta_rate_init(sta);
4387 sband = local->hw.wiphy->bands[cbss->channel->band];
4389 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
4390 &rates, &basic_rates, &have_higher_than_11mbit,
4391 &min_rate, &min_rate_index);
4394 * This used to be a workaround for basic rates missing
4395 * in the association response frame. Now that we no
4396 * longer use the basic rates from there, it probably
4397 * doesn't happen any more, but keep the workaround so
4398 * in case some *other* APs are buggy in different ways
4399 * we can connect -- with a warning.
4400 * Allow this workaround only in case the AP provided at least
4403 if (min_rate_index < 0) {
4404 link_info(link, "No legacy rates in association response\n");
4406 } else if (!basic_rates) {
4407 link_info(link, "No basic rates, using min rate instead\n");
4408 basic_rates = BIT(min_rate_index);
4412 link_sta->pub->supp_rates[cbss->channel->band] = rates;
4414 link_info(link, "No rates found, keeping mandatory only\n");
4416 link->conf->basic_rates = basic_rates;
4418 /* cf. IEEE 802.11 9.2.12 */
4419 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
4420 have_higher_than_11mbit;
4425 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
4426 struct cfg80211_bss *cbss)
4428 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4429 const struct element *ht_cap_elem, *vht_cap_elem;
4430 const struct cfg80211_bss_ies *ies;
4431 const struct ieee80211_ht_cap *ht_cap;
4432 const struct ieee80211_vht_cap *vht_cap;
4433 const struct ieee80211_he_cap_elem *he_cap;
4434 const struct element *he_cap_elem;
4435 u16 mcs_80_map, mcs_160_map;
4436 int i, mcs_nss_size;
4440 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
4443 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4444 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4445 ht_cap = (void *)ht_cap_elem->data;
4446 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4448 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4449 * "Tx Unequal Modulation Supported" fields.
4453 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
4456 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4457 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4461 vht_cap = (void *)vht_cap_elem->data;
4462 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4463 for (nss = 8; nss > 0; nss--) {
4464 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4465 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4468 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4469 chains = max(chains, nss);
4472 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
4475 ies = rcu_dereference(cbss->ies);
4476 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4477 ies->data, ies->len);
4479 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
4482 /* skip one byte ext_tag_id */
4483 he_cap = (void *)(he_cap_elem->data + 1);
4484 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4487 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
4490 /* mcs_nss is right after he_cap info */
4491 he_mcs_nss_supp = (void *)(he_cap + 1);
4493 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4495 for (i = 7; i >= 0; i--) {
4496 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
4498 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4499 chains = max_t(u8, chains, i + 1);
4504 support_160 = he_cap->phy_cap_info[0] &
4505 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
4510 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
4511 for (i = 7; i >= 0; i--) {
4512 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
4514 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4515 chains = max_t(u8, chains, i + 1);
4524 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4525 const struct cfg80211_bss_ies *ies,
4526 const struct ieee80211_he_operation *he_op)
4528 const struct element *he_cap_elem;
4529 const struct ieee80211_he_cap_elem *he_cap;
4530 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4531 u16 mcs_80_map_tx, mcs_80_map_rx;
4536 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4537 ies->data, ies->len);
4543 if (he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
4545 "Invalid HE elem, Disable HE\n");
4549 /* skip one byte ext_tag_id */
4550 he_cap = (void *)(he_cap_elem->data + 1);
4551 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4554 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
4556 "Invalid HE elem with nss size, Disable HE\n");
4560 /* mcs_nss is right after he_cap info */
4561 he_mcs_nss_supp = (void *)(he_cap + 1);
4563 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4564 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
4566 /* P802.11-REVme/D0.3
4567 * 27.1.1 Introduction to the HE PHY
4569 * An HE STA shall support the following features:
4571 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
4572 * supported channel widths for HE SU PPDUs
4574 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4575 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
4577 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
4578 mcs_80_map_tx, mcs_80_map_rx);
4585 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4588 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4589 * zeroes, which is nonsense, and completely inconsistent with itself
4590 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4592 if (!ap_min_req_set)
4595 /* make sure the AP is consistent with itself
4597 * P802.11-REVme/D0.3
4598 * 26.17.1 Basic HE BSS operation
4600 * A STA that is operating in an HE BSS shall be able to receive and
4601 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
4602 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
4603 * MLME-START.request primitive and shall be able to receive at each of
4604 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
4605 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
4608 for (nss = 8; nss > 0; nss--) {
4609 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4613 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4616 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
4617 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
4619 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4620 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4621 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
4623 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
4624 nss, ap_rx_val, ap_rx_val, ap_op_val);
4633 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4634 struct ieee80211_supported_band *sband,
4635 const struct ieee80211_he_operation *he_op)
4637 const struct ieee80211_sta_he_cap *sta_he_cap =
4638 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4642 if (!sta_he_cap || !he_op)
4645 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4648 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4649 * zeroes, which is nonsense, and completely inconsistent with itself
4650 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4652 if (!ap_min_req_set)
4655 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4656 for (i = 0; i < 3; i++) {
4657 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4658 &sta_he_cap->he_mcs_nss_supp;
4659 u16 sta_mcs_map_rx =
4660 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4661 u16 sta_mcs_map_tx =
4662 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4664 bool verified = true;
4667 * For each band there is a maximum of 8 spatial streams
4668 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4669 * of 2 bits per NSS (1-8), with the values defined in enum
4670 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4671 * capabilities aren't less than the AP's minimum requirements
4672 * for this HE BSS per SS.
4673 * It is enough to find one such band that meets the reqs.
4675 for (nss = 8; nss > 0; nss--) {
4676 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4677 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4678 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4680 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4684 * Make sure the HE AP doesn't require MCSs that aren't
4685 * supported by the client as required by spec
4687 * P802.11-REVme/D0.3
4688 * 26.17.1 Basic HE BSS operation
4690 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
4691 * a BSS, unless it supports (i.e., is able to both transmit and
4692 * receive using) all of the <HE-MCS, NSS> tuples in the basic
4693 * HE-MCS and NSS set.
4695 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4696 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4697 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4707 /* If here, STA doesn't meet AP's HE min requirements */
4712 ieee80211_get_eht_cap_mcs_nss(const struct ieee80211_sta_he_cap *sta_he_cap,
4713 const struct ieee80211_sta_eht_cap *sta_eht_cap,
4714 unsigned int idx, int bw)
4716 u8 he_phy_cap0 = sta_he_cap->he_cap_elem.phy_cap_info[0];
4717 u8 eht_phy_cap0 = sta_eht_cap->eht_cap_elem.phy_cap_info[0];
4719 /* handle us being a 20 MHz-only EHT STA - with four values
4720 * for MCS 0-7, 8-9, 10-11, 12-13.
4722 if (!(he_phy_cap0 & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL))
4723 return sta_eht_cap->eht_mcs_nss_supp.only_20mhz.rx_tx_max_nss[idx];
4725 /* the others have MCS 0-9 together, rather than separately from 0-7 */
4731 return sta_eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_max_nss[idx];
4734 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4735 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)))
4736 return 0xff; /* pass check */
4737 return sta_eht_cap->eht_mcs_nss_supp.bw._160.rx_tx_max_nss[idx];
4739 if (!(eht_phy_cap0 & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ))
4740 return 0xff; /* pass check */
4741 return sta_eht_cap->eht_mcs_nss_supp.bw._320.rx_tx_max_nss[idx];
4749 ieee80211_verify_sta_eht_mcs_support(struct ieee80211_sub_if_data *sdata,
4750 struct ieee80211_supported_band *sband,
4751 const struct ieee80211_eht_operation *eht_op)
4753 const struct ieee80211_sta_he_cap *sta_he_cap =
4754 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4755 const struct ieee80211_sta_eht_cap *sta_eht_cap =
4756 ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
4757 const struct ieee80211_eht_mcs_nss_supp_20mhz_only *req;
4760 if (!sta_he_cap || !sta_eht_cap || !eht_op)
4763 req = &eht_op->basic_mcs_nss;
4765 for (i = 0; i < ARRAY_SIZE(req->rx_tx_max_nss); i++) {
4766 u8 req_rx_nss, req_tx_nss;
4769 req_rx_nss = u8_get_bits(req->rx_tx_max_nss[i],
4770 IEEE80211_EHT_MCS_NSS_RX);
4771 req_tx_nss = u8_get_bits(req->rx_tx_max_nss[i],
4772 IEEE80211_EHT_MCS_NSS_TX);
4774 for (bw = 0; bw < 3; bw++) {
4775 u8 have, have_rx_nss, have_tx_nss;
4777 have = ieee80211_get_eht_cap_mcs_nss(sta_he_cap,
4780 have_rx_nss = u8_get_bits(have,
4781 IEEE80211_EHT_MCS_NSS_RX);
4782 have_tx_nss = u8_get_bits(have,
4783 IEEE80211_EHT_MCS_NSS_TX);
4785 if (req_rx_nss > have_rx_nss ||
4786 req_tx_nss > have_tx_nss)
4794 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4795 struct ieee80211_link_data *link,
4796 struct cfg80211_bss *cbss,
4798 ieee80211_conn_flags_t *conn_flags)
4800 struct ieee80211_local *local = sdata->local;
4801 const struct ieee80211_ht_cap *ht_cap = NULL;
4802 const struct ieee80211_ht_operation *ht_oper = NULL;
4803 const struct ieee80211_vht_operation *vht_oper = NULL;
4804 const struct ieee80211_he_operation *he_oper = NULL;
4805 const struct ieee80211_eht_operation *eht_oper = NULL;
4806 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4807 struct ieee80211_supported_band *sband;
4808 struct cfg80211_chan_def chandef;
4809 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4810 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4811 bool supports_mlo = false;
4812 struct ieee80211_bss *bss = (void *)cbss->priv;
4813 struct ieee80211_elems_parse_params parse_params = {
4817 struct ieee802_11_elems *elems;
4818 const struct cfg80211_bss_ies *ies;
4823 lockdep_assert_wiphy(local->hw.wiphy);
4827 ies = rcu_dereference(cbss->ies);
4828 parse_params.start = ies->data;
4829 parse_params.len = ies->len;
4830 elems = ieee802_11_parse_elems_full(&parse_params);
4836 sband = local->hw.wiphy->bands[cbss->channel->band];
4838 *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
4839 IEEE80211_CONN_DISABLE_80P80MHZ |
4840 IEEE80211_CONN_DISABLE_160MHZ);
4842 /* disable HT/VHT/HE if we don't support them */
4843 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4844 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
4845 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4846 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4847 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4848 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4851 if (!sband->vht_cap.vht_supported && is_5ghz) {
4852 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
4853 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4854 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4855 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4858 if (!ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif)) {
4859 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
4860 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4861 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4864 if (!ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif)) {
4865 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
4866 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4869 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
4870 ht_oper = elems->ht_operation;
4871 ht_cap = elems->ht_cap_elem;
4874 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4879 if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
4880 vht_oper = elems->vht_operation;
4881 if (vht_oper && !ht_oper) {
4884 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
4885 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4886 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4887 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4888 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4891 if (!elems->vht_cap_elem) {
4892 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4897 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
4898 he_oper = elems->he_operation;
4900 if (link && is_6ghz) {
4901 struct ieee80211_bss_conf *bss_conf;
4904 bss_conf = link->conf;
4906 if (elems->pwr_constr_elem)
4907 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
4909 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
4910 ARRAY_SIZE(elems->tx_pwr_env));
4912 for (i = 0; i < elems->tx_pwr_env_num; i++) {
4913 if (elems->tx_pwr_env_len[i] >
4914 sizeof(bss_conf->tx_pwr_env[j]))
4917 bss_conf->tx_pwr_env_num++;
4918 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
4919 elems->tx_pwr_env_len[i]);
4924 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
4925 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
4926 *conn_flags |= IEEE80211_CONN_DISABLE_HE |
4927 IEEE80211_CONN_DISABLE_EHT;
4931 * EHT requires HE to be supported as well. Specifically for 6 GHz
4932 * channels, the operation channel information can only be deduced from
4933 * both the 6 GHz operation information (from the HE operation IE) and
4937 (IEEE80211_CONN_DISABLE_HE |
4938 IEEE80211_CONN_DISABLE_EHT)) &&
4940 const struct cfg80211_bss_ies *cbss_ies;
4941 const struct element *eht_ml_elem;
4942 const u8 *eht_oper_ie;
4944 cbss_ies = rcu_dereference(cbss->ies);
4945 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
4946 cbss_ies->data, cbss_ies->len);
4947 if (eht_oper_ie && eht_oper_ie[1] >=
4948 1 + sizeof(struct ieee80211_eht_operation))
4949 eht_oper = (void *)(eht_oper_ie + 3);
4953 if (!ieee80211_verify_sta_eht_mcs_support(sdata, sband, eht_oper))
4954 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4956 eht_ml_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_MULTI_LINK,
4957 cbss_ies->data, cbss_ies->len);
4959 /* data + 1 / datalen - 1 since it's an extended element */
4960 if (!(*conn_flags & IEEE80211_CONN_DISABLE_EHT) &&
4962 ieee80211_mle_type_ok(eht_ml_elem->data + 1,
4963 IEEE80211_ML_CONTROL_TYPE_BASIC,
4964 eht_ml_elem->datalen - 1)) {
4965 supports_mlo = true;
4967 sdata->vif.cfg.eml_cap =
4968 ieee80211_mle_get_eml_cap(eht_ml_elem->data + 1);
4969 sdata->vif.cfg.eml_med_sync_delay =
4970 ieee80211_mle_get_eml_med_sync_delay(eht_ml_elem->data + 1);
4974 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4976 for (i = 0; i < sband->n_channels; i++) {
4977 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4978 IEEE80211_CHAN_NO_80MHZ))
4986 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
4987 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4990 if (sband->band == NL80211_BAND_S1GHZ) {
4991 s1g_oper = elems->s1g_oper;
4994 "AP missing S1G operation element?\n");
4998 ieee80211_determine_chantype(sdata, link, *conn_flags,
5008 link->needed_rx_chains =
5009 min(ieee80211_max_rx_chains(link, cbss),
5013 /* the element data was RCU protected so no longer valid anyway */
5017 if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
5018 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5022 if (mlo && !supports_mlo) {
5023 sdata_info(sdata, "Rejecting MLO as it is not supported by AP\n");
5030 /* will change later if needed */
5031 link->smps_mode = IEEE80211_SMPS_OFF;
5034 * If this fails (possibly due to channel context sharing
5035 * on incompatible channels, e.g. 80+80 and 160 sharing the
5036 * same control channel) try to use a smaller bandwidth.
5038 ret = ieee80211_link_use_channel(link, &chandef,
5039 IEEE80211_CHANCTX_SHARED);
5041 /* don't downgrade for 5 and 10 MHz channels, though. */
5042 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5043 chandef.width == NL80211_CHAN_WIDTH_10)
5046 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5048 ieee80211_chandef_downgrade(&chandef);
5049 ret = ieee80211_link_use_channel(link, &chandef,
5050 IEEE80211_CHANCTX_SHARED);
5056 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5057 u8 *dtim_count, u8 *dtim_period)
5059 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5060 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5062 const struct ieee80211_tim_ie *tim = NULL;
5063 const struct ieee80211_bssid_index *idx;
5064 bool valid = tim_ie && tim_ie[1] >= 2;
5067 tim = (void *)(tim_ie + 2);
5070 *dtim_count = valid ? tim->dtim_count : 0;
5073 *dtim_period = valid ? tim->dtim_period : 0;
5075 /* Check if value is overridden by non-transmitted profile */
5076 if (!idx_ie || idx_ie[1] < 3)
5079 idx = (void *)(idx_ie + 2);
5082 *dtim_count = idx->dtim_count;
5085 *dtim_period = idx->dtim_period;
5090 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
5091 struct ieee80211_mgmt *mgmt,
5092 struct ieee802_11_elems *elems,
5093 const u8 *elem_start, unsigned int elem_len)
5095 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5096 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5097 struct ieee80211_local *local = sdata->local;
5098 unsigned int link_id;
5099 struct sta_info *sta;
5100 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
5101 u16 valid_links = 0, dormant_links = 0;
5104 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5106 * station info was already allocated and inserted before
5107 * the association and should be available to us
5109 sta = sta_info_get(sdata, assoc_data->ap_addr);
5113 if (ieee80211_vif_is_mld(&sdata->vif)) {
5114 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5115 if (!assoc_data->link[link_id].bss)
5118 valid_links |= BIT(link_id);
5119 if (assoc_data->link[link_id].disabled)
5120 dormant_links |= BIT(link_id);
5122 if (link_id != assoc_data->assoc_link_id) {
5123 err = ieee80211_sta_allocate_link(sta, link_id);
5129 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5132 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5133 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
5134 struct ieee80211_link_data *link;
5135 struct link_sta_info *link_sta;
5140 link = sdata_dereference(sdata->link[link_id], sdata);
5144 if (ieee80211_vif_is_mld(&sdata->vif))
5146 "local address %pM, AP link address %pM%s\n",
5148 assoc_data->link[link_id].bss->bssid,
5149 link_id == assoc_data->assoc_link_id ?
5152 link_sta = rcu_dereference_protected(sta->link[link_id],
5153 lockdep_is_held(&local->hw.wiphy->mtx));
5154 if (WARN_ON(!link_sta))
5157 if (!link->u.mgd.have_beacon) {
5158 const struct cfg80211_bss_ies *ies;
5161 ies = rcu_dereference(cbss->beacon_ies);
5163 link->u.mgd.have_beacon = true;
5165 ies = rcu_dereference(cbss->ies);
5166 ieee80211_get_dtim(ies,
5167 &link->conf->sync_dtim_count,
5168 &link->u.mgd.dtim_period);
5169 link->conf->beacon_int = cbss->beacon_interval;
5173 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
5175 if (link_id != assoc_data->assoc_link_id) {
5176 err = ieee80211_prep_channel(sdata, link, cbss, true,
5177 &link->u.mgd.conn_flags);
5179 link_info(link, "prep_channel failed\n");
5184 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
5185 assoc_data->link[link_id].bss);
5189 if (!ieee80211_assoc_config_link(link, link_sta,
5190 assoc_data->link[link_id].bss,
5191 mgmt, elem_start, elem_len,
5195 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
5196 valid_links &= ~BIT(link_id);
5197 ieee80211_sta_remove_link(sta, link_id);
5201 if (link_id != assoc_data->assoc_link_id) {
5202 err = ieee80211_sta_activate_link(sta, link_id);
5208 /* links might have changed due to rejected ones, set them again */
5209 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5211 rate_control_rate_init(sta);
5213 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
5214 set_sta_flag(sta, WLAN_STA_MFP);
5215 sta->sta.mfp = true;
5217 sta->sta.mfp = false;
5220 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
5221 elems->ext_capab_len);
5223 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
5224 local->hw.queues >= IEEE80211_NUM_ACS;
5226 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
5227 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
5228 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
5231 "failed to move station %pM to desired state\n",
5233 WARN_ON(__sta_info_destroy(sta));
5237 if (sdata->wdev.use_4addr)
5238 drv_sta_set_4addr(local, sdata, &sta->sta, true);
5240 ieee80211_set_associated(sdata, assoc_data, changed);
5243 * If we're using 4-addr mode, let the AP know that we're
5244 * doing so, so that it can create the STA VLAN on its side
5246 if (ifmgd->use_4addr)
5247 ieee80211_send_4addr_nullfunc(local, sdata);
5250 * Start timer to probe the connection to the AP now.
5251 * Also start the timer that will detect beacon loss.
5253 ieee80211_sta_reset_beacon_monitor(sdata);
5254 ieee80211_sta_reset_conn_monitor(sdata);
5258 eth_zero_addr(sdata->vif.cfg.ap_addr);
5262 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
5263 struct ieee80211_mgmt *mgmt,
5266 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5267 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5268 u16 capab_info, status_code, aid;
5269 struct ieee80211_elems_parse_params parse_params = {
5274 struct ieee802_11_elems *elems;
5276 const u8 *elem_start;
5277 unsigned int elem_len;
5279 struct ieee80211_event event = {
5281 .u.mlme.data = ASSOC_EVENT,
5283 struct ieee80211_prep_tx_info info = {};
5284 struct cfg80211_rx_assoc_resp_data resp = {
5287 u8 ap_mld_addr[ETH_ALEN] __aligned(2);
5288 unsigned int link_id;
5290 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5295 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
5296 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
5300 * AssocResp and ReassocResp have identical structure, so process both
5301 * of them in this function.
5307 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
5308 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
5309 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
5310 if (assoc_data->s1g)
5311 elem_start = mgmt->u.s1g_assoc_resp.variable;
5313 elem_start = mgmt->u.assoc_resp.variable;
5316 * Note: this may not be perfect, AP might misbehave - if
5317 * anyone needs to rely on perfect complete notification
5318 * with the exact right subtype, then we need to track what
5319 * we actually transmitted.
5321 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
5322 IEEE80211_STYPE_ASSOC_REQ;
5324 if (assoc_data->fils_kek_len &&
5325 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
5328 elem_len = len - (elem_start - (u8 *)mgmt);
5329 parse_params.start = elem_start;
5330 parse_params.len = elem_len;
5331 elems = ieee802_11_parse_elems_full(&parse_params);
5335 if (elems->aid_resp)
5336 aid = le16_to_cpu(elems->aid_resp->aid);
5337 else if (assoc_data->s1g)
5340 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
5343 * The 5 MSB of the AID field are reserved
5344 * (802.11-2016 9.4.1.8 AID field)
5349 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
5350 reassoc ? "Rea" : "A", assoc_data->ap_addr,
5351 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
5353 ifmgd->broken_ap = false;
5355 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
5356 elems->timeout_int &&
5357 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
5360 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
5361 le32_to_cpu(elems->timeout_int->value));
5363 tu = le32_to_cpu(elems->timeout_int->value);
5364 ms = tu * 1024 / 1000;
5366 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
5367 assoc_data->ap_addr, tu, ms);
5368 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
5369 assoc_data->timeout_started = true;
5370 if (ms > IEEE80211_ASSOC_TIMEOUT)
5371 run_again(sdata, assoc_data->timeout);
5375 if (status_code != WLAN_STATUS_SUCCESS) {
5376 sdata_info(sdata, "%pM denied association (code=%d)\n",
5377 assoc_data->ap_addr, status_code);
5378 event.u.mlme.status = MLME_DENIED;
5379 event.u.mlme.reason = status_code;
5380 drv_event_callback(sdata->local, sdata, &event);
5382 if (aid == 0 || aid > IEEE80211_MAX_AID) {
5384 "invalid AID value %d (out of range), turn off PS\n",
5387 ifmgd->broken_ap = true;
5390 if (ieee80211_vif_is_mld(&sdata->vif)) {
5391 if (!elems->ml_basic) {
5393 "MLO association with %pM but no multi-link element in response!\n",
5394 assoc_data->ap_addr);
5398 if (le16_get_bits(elems->ml_basic->control,
5399 IEEE80211_ML_CONTROL_TYPE) !=
5400 IEEE80211_ML_CONTROL_TYPE_BASIC) {
5402 "bad multi-link element (control=0x%x)\n",
5403 le16_to_cpu(elems->ml_basic->control));
5406 struct ieee80211_mle_basic_common_info *common;
5408 common = (void *)elems->ml_basic->variable;
5410 if (memcmp(assoc_data->ap_addr,
5411 common->mld_mac_addr, ETH_ALEN)) {
5413 "AP MLD MAC address mismatch: got %pM expected %pM\n",
5414 common->mld_mac_addr,
5415 assoc_data->ap_addr);
5421 sdata->vif.cfg.aid = aid;
5423 if (!ieee80211_assoc_success(sdata, mgmt, elems,
5424 elem_start, elem_len)) {
5425 /* oops -- internal error -- send timeout for now */
5426 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5429 event.u.mlme.status = MLME_SUCCESS;
5430 drv_event_callback(sdata->local, sdata, &event);
5431 sdata_info(sdata, "associated\n");
5436 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5437 struct ieee80211_link_data *link;
5439 if (!assoc_data->link[link_id].bss)
5442 resp.links[link_id].bss = assoc_data->link[link_id].bss;
5443 ether_addr_copy(resp.links[link_id].addr,
5444 assoc_data->link[link_id].addr);
5445 resp.links[link_id].status = assoc_data->link[link_id].status;
5447 link = sdata_dereference(sdata->link[link_id], sdata);
5451 /* get uapsd queues configuration - same for all links */
5452 resp.uapsd_queues = 0;
5453 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
5454 if (link->tx_conf[ac].uapsd)
5455 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
5458 if (ieee80211_vif_is_mld(&sdata->vif)) {
5459 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
5460 resp.ap_mld_addr = ap_mld_addr;
5463 ieee80211_destroy_assoc_data(sdata,
5464 status_code == WLAN_STATUS_SUCCESS ?
5468 resp.buf = (u8 *)mgmt;
5470 resp.req_ies = ifmgd->assoc_req_ies;
5471 resp.req_ies_len = ifmgd->assoc_req_ies_len;
5472 cfg80211_rx_assoc_resp(sdata->dev, &resp);
5474 drv_mgd_complete_tx(sdata->local, sdata, &info);
5478 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5482 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
5483 struct ieee80211_mgmt *mgmt, size_t len,
5484 struct ieee80211_rx_status *rx_status)
5486 struct ieee80211_sub_if_data *sdata = link->sdata;
5487 struct ieee80211_local *local = sdata->local;
5488 struct ieee80211_bss *bss;
5489 struct ieee80211_channel *channel;
5491 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5493 channel = ieee80211_get_channel_khz(local->hw.wiphy,
5494 ieee80211_rx_status_to_khz(rx_status));
5498 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
5500 link->conf->beacon_rate = bss->beacon_rate;
5501 ieee80211_rx_bss_put(local, bss);
5506 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
5507 struct sk_buff *skb)
5509 struct ieee80211_sub_if_data *sdata = link->sdata;
5510 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5511 struct ieee80211_if_managed *ifmgd;
5512 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
5513 struct ieee80211_channel *channel;
5514 size_t baselen, len = skb->len;
5516 ifmgd = &sdata->u.mgd;
5518 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5521 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
5522 * "If a 6 GHz AP receives a Probe Request frame and responds with
5523 * a Probe Response frame [..], the Address 1 field of the Probe
5524 * Response frame shall be set to the broadcast address [..]"
5525 * So, on 6GHz band we should also accept broadcast responses.
5527 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
5532 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
5533 (channel->band != NL80211_BAND_6GHZ ||
5534 !is_broadcast_ether_addr(mgmt->da)))
5535 return; /* ignore ProbeResp to foreign address */
5537 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
5541 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5543 if (ifmgd->associated &&
5544 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
5545 ieee80211_reset_ap_probe(sdata);
5549 * This is the canonical list of information elements we care about,
5550 * the filter code also gives us all changes to the Microsoft OUI
5551 * (00:50:F2) vendor IE which is used for WMM which we need to track,
5552 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
5553 * changes to requested client power.
5555 * We implement beacon filtering in software since that means we can
5556 * avoid processing the frame here and in cfg80211, and userspace
5557 * will not be able to tell whether the hardware supports it or not.
5559 * XXX: This list needs to be dynamic -- userspace needs to be able to
5560 * add items it requires. It also needs to be able to tell us to
5561 * look out for other vendor IEs.
5563 static const u64 care_about_ies =
5564 (1ULL << WLAN_EID_COUNTRY) |
5565 (1ULL << WLAN_EID_ERP_INFO) |
5566 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
5567 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
5568 (1ULL << WLAN_EID_HT_CAPABILITY) |
5569 (1ULL << WLAN_EID_HT_OPERATION) |
5570 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
5572 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
5573 struct ieee80211_if_managed *ifmgd,
5574 struct ieee80211_bss_conf *bss_conf,
5575 struct ieee80211_local *local,
5576 struct ieee80211_rx_status *rx_status)
5578 struct ieee80211_sub_if_data *sdata = link->sdata;
5580 /* Track average RSSI from the Beacon frames of the current AP */
5582 if (!link->u.mgd.tracking_signal_avg) {
5583 link->u.mgd.tracking_signal_avg = true;
5584 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
5585 link->u.mgd.last_cqm_event_signal = 0;
5586 link->u.mgd.count_beacon_signal = 1;
5587 link->u.mgd.last_ave_beacon_signal = 0;
5589 link->u.mgd.count_beacon_signal++;
5592 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
5593 -rx_status->signal);
5595 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
5596 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5597 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5598 int last_sig = link->u.mgd.last_ave_beacon_signal;
5599 struct ieee80211_event event = {
5604 * if signal crosses either of the boundaries, invoke callback
5605 * with appropriate parameters
5607 if (sig > ifmgd->rssi_max_thold &&
5608 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
5609 link->u.mgd.last_ave_beacon_signal = sig;
5610 event.u.rssi.data = RSSI_EVENT_HIGH;
5611 drv_event_callback(local, sdata, &event);
5612 } else if (sig < ifmgd->rssi_min_thold &&
5613 (last_sig >= ifmgd->rssi_max_thold ||
5615 link->u.mgd.last_ave_beacon_signal = sig;
5616 event.u.rssi.data = RSSI_EVENT_LOW;
5617 drv_event_callback(local, sdata, &event);
5621 if (bss_conf->cqm_rssi_thold &&
5622 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
5623 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
5624 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5625 int last_event = link->u.mgd.last_cqm_event_signal;
5626 int thold = bss_conf->cqm_rssi_thold;
5627 int hyst = bss_conf->cqm_rssi_hyst;
5630 (last_event == 0 || sig < last_event - hyst)) {
5631 link->u.mgd.last_cqm_event_signal = sig;
5632 ieee80211_cqm_rssi_notify(
5634 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5636 } else if (sig > thold &&
5637 (last_event == 0 || sig > last_event + hyst)) {
5638 link->u.mgd.last_cqm_event_signal = sig;
5639 ieee80211_cqm_rssi_notify(
5641 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5646 if (bss_conf->cqm_rssi_low &&
5647 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5648 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5649 int last_event = link->u.mgd.last_cqm_event_signal;
5650 int low = bss_conf->cqm_rssi_low;
5651 int high = bss_conf->cqm_rssi_high;
5654 (last_event == 0 || last_event >= low)) {
5655 link->u.mgd.last_cqm_event_signal = sig;
5656 ieee80211_cqm_rssi_notify(
5658 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5660 } else if (sig > high &&
5661 (last_event == 0 || last_event <= high)) {
5662 link->u.mgd.last_cqm_event_signal = sig;
5663 ieee80211_cqm_rssi_notify(
5665 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5671 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
5672 struct cfg80211_bss *bss)
5674 if (ether_addr_equal(tx_bssid, bss->bssid))
5676 if (!bss->transmitted_bss)
5678 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
5681 static bool ieee80211_config_puncturing(struct ieee80211_link_data *link,
5682 const struct ieee80211_eht_operation *eht_oper,
5685 u16 bitmap = 0, extracted;
5687 if ((eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
5689 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
5690 const struct ieee80211_eht_operation_info *info =
5691 (void *)eht_oper->optional;
5692 const u8 *disable_subchannel_bitmap = info->optional;
5694 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
5697 extracted = ieee80211_extract_dis_subch_bmap(eht_oper,
5698 &link->conf->chandef,
5701 /* accept if there are no changes */
5702 if (!(*changed & BSS_CHANGED_BANDWIDTH) &&
5703 extracted == link->conf->eht_puncturing)
5706 if (!cfg80211_valid_disable_subchannel_bitmap(&bitmap,
5707 &link->conf->chandef)) {
5709 "Got an invalid disable subchannel bitmap from AP %pM: bitmap = 0x%x, bw = 0x%x. disconnect\n",
5712 link->conf->chandef.width);
5716 ieee80211_handle_puncturing_bitmap(link, eht_oper, bitmap, changed);
5720 static void ieee80211_ml_reconf_work(struct wiphy *wiphy,
5721 struct wiphy_work *work)
5723 struct ieee80211_sub_if_data *sdata =
5724 container_of(work, struct ieee80211_sub_if_data,
5725 u.mgd.ml_reconf_work.work);
5726 u16 new_valid_links, new_active_links, new_dormant_links;
5729 if (!sdata->u.mgd.removed_links)
5733 "MLO Reconfiguration: work: valid=0x%x, removed=0x%x\n",
5734 sdata->vif.valid_links, sdata->u.mgd.removed_links);
5736 new_valid_links = sdata->vif.valid_links & ~sdata->u.mgd.removed_links;
5737 if (new_valid_links == sdata->vif.valid_links)
5740 if (!new_valid_links ||
5741 !(new_valid_links & ~sdata->vif.dormant_links)) {
5742 sdata_info(sdata, "No valid links after reconfiguration\n");
5747 new_active_links = sdata->vif.active_links & ~sdata->u.mgd.removed_links;
5748 if (new_active_links != sdata->vif.active_links) {
5749 if (!new_active_links)
5751 BIT(ffs(new_valid_links &
5752 ~sdata->vif.dormant_links) - 1);
5754 ret = ieee80211_set_active_links(&sdata->vif, new_active_links);
5757 "Failed setting active links\n");
5762 new_dormant_links = sdata->vif.dormant_links & ~sdata->u.mgd.removed_links;
5764 ret = ieee80211_vif_set_links(sdata, new_valid_links,
5767 sdata_info(sdata, "Failed setting valid links\n");
5769 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS);
5773 cfg80211_links_removed(sdata->dev, sdata->u.mgd.removed_links);
5775 __ieee80211_disconnect(sdata);
5777 sdata->u.mgd.removed_links = 0;
5780 static void ieee80211_ml_reconfiguration(struct ieee80211_sub_if_data *sdata,
5781 struct ieee802_11_elems *elems)
5783 const struct ieee80211_multi_link_elem *ml;
5784 const struct element *sub;
5786 unsigned long removed_links = 0;
5787 u16 link_removal_timeout[IEEE80211_MLD_MAX_NUM_LINKS] = {};
5791 if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_reconf)
5794 ml_len = cfg80211_defragment_element(elems->ml_reconf_elem,
5798 elems->scratch + elems->scratch_len -
5804 elems->ml_reconf = (const void *)elems->scratch_pos;
5805 elems->ml_reconf_len = ml_len;
5806 ml = elems->ml_reconf;
5808 /* Directly parse the sub elements as the common information doesn't
5809 * hold any useful information.
5811 for_each_mle_subelement(sub, (u8 *)ml, ml_len) {
5812 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
5813 u8 *pos = prof->variable;
5816 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE)
5819 if (!ieee80211_mle_reconf_sta_prof_size_ok(sub->data,
5823 control = le16_to_cpu(prof->control);
5824 link_id = control & IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID;
5826 removed_links |= BIT(link_id);
5828 /* the MAC address should not be included, but handle it */
5830 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT)
5833 /* According to Draft P802.11be_D3.0, the control should
5834 * include the AP Removal Timer present. If the AP Removal Timer
5835 * is not present assume immediate removal.
5838 IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT)
5839 link_removal_timeout[link_id] = le16_to_cpu(*(__le16 *)pos);
5842 removed_links &= sdata->vif.valid_links;
5843 if (!removed_links) {
5844 /* In case the removal was cancelled, abort it */
5845 if (sdata->u.mgd.removed_links) {
5846 sdata->u.mgd.removed_links = 0;
5847 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
5848 &sdata->u.mgd.ml_reconf_work);
5854 for_each_set_bit(link_id, &removed_links, IEEE80211_MLD_MAX_NUM_LINKS) {
5855 struct ieee80211_bss_conf *link_conf =
5856 sdata_dereference(sdata->vif.link_conf[link_id], sdata);
5860 removed_links &= ~BIT(link_id);
5864 link_delay = link_conf->beacon_int *
5865 link_removal_timeout[link_id];
5870 delay = min(delay, link_delay);
5873 sdata->u.mgd.removed_links = removed_links;
5874 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
5875 &sdata->u.mgd.ml_reconf_work,
5876 TU_TO_JIFFIES(delay));
5879 static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy,
5880 struct wiphy_work *work)
5882 u16 new_active_links, new_dormant_links;
5883 struct ieee80211_sub_if_data *sdata =
5884 container_of(work, struct ieee80211_sub_if_data,
5885 u.mgd.ttlm_work.work);
5888 new_active_links = sdata->u.mgd.ttlm_info.map &
5889 sdata->vif.valid_links;
5890 new_dormant_links = ~sdata->u.mgd.ttlm_info.map &
5891 sdata->vif.valid_links;
5892 if (!new_active_links) {
5893 ieee80211_disconnect(&sdata->vif, false);
5897 ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 0);
5898 new_active_links = BIT(ffs(new_active_links) - 1);
5899 ieee80211_set_active_links(&sdata->vif, new_active_links);
5901 ret = ieee80211_vif_set_links(sdata, sdata->vif.valid_links,
5904 sdata->u.mgd.ttlm_info.active = true;
5905 sdata->u.mgd.ttlm_info.switch_time = 0;
5908 ieee80211_vif_cfg_change_notify(sdata,
5909 BSS_CHANGED_MLD_VALID_LINKS);
5912 static u16 ieee80211_get_ttlm(u8 bm_size, u8 *data)
5917 return get_unaligned_le16(data);
5921 ieee80211_parse_adv_t2l(struct ieee80211_sub_if_data *sdata,
5922 const struct ieee80211_ttlm_elem *ttlm,
5923 struct ieee80211_adv_ttlm_info *ttlm_info)
5925 /* The element size was already validated in
5926 * ieee80211_tid_to_link_map_size_ok()
5928 u8 control, link_map_presence, map_size, tid;
5931 memset(ttlm_info, 0, sizeof(*ttlm_info));
5932 pos = (void *)ttlm->optional;
5933 control = ttlm->control;
5935 if ((control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) ||
5936 !(control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT))
5939 if ((control & IEEE80211_TTLM_CONTROL_DIRECTION) !=
5940 IEEE80211_TTLM_DIRECTION_BOTH) {
5941 sdata_info(sdata, "Invalid advertised T2L map direction\n");
5945 link_map_presence = *pos;
5948 ttlm_info->switch_time = get_unaligned_le16(pos);
5951 if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT) {
5952 ttlm_info->duration = pos[0] | pos[1] << 8 | pos[2] << 16;
5956 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
5961 /* According to Draft P802.11be_D3.0 clause 35.3.7.1.7, an AP MLD shall
5962 * not advertise a TID-to-link mapping that does not map all TIDs to the
5963 * same link set, reject frame if not all links have mapping
5965 if (link_map_presence != 0xff) {
5967 "Invalid advertised T2L mapping presence indicator\n");
5971 ttlm_info->map = ieee80211_get_ttlm(map_size, pos);
5972 if (!ttlm_info->map) {
5974 "Invalid advertised T2L map for TID 0\n");
5980 for (tid = 1; tid < 8; tid++) {
5981 u16 map = ieee80211_get_ttlm(map_size, pos);
5983 if (map != ttlm_info->map) {
5984 sdata_info(sdata, "Invalid advertised T2L map for tid %d\n",
5994 static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata,
5995 struct ieee802_11_elems *elems,
6001 if (!ieee80211_vif_is_mld(&sdata->vif))
6004 if (!elems->ttlm_num) {
6005 if (sdata->u.mgd.ttlm_info.switch_time) {
6006 /* if a planned TID-to-link mapping was cancelled -
6009 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6010 &sdata->u.mgd.ttlm_work);
6011 } else if (sdata->u.mgd.ttlm_info.active) {
6012 /* if no TID-to-link element, set to default mapping in
6013 * which all TIDs are mapped to all setup links
6015 ret = ieee80211_vif_set_links(sdata,
6016 sdata->vif.valid_links,
6019 sdata_info(sdata, "Failed setting valid/dormant links\n");
6022 ieee80211_vif_cfg_change_notify(sdata,
6023 BSS_CHANGED_MLD_VALID_LINKS);
6025 memset(&sdata->u.mgd.ttlm_info, 0,
6026 sizeof(sdata->u.mgd.ttlm_info));
6030 for (i = 0; i < elems->ttlm_num; i++) {
6031 struct ieee80211_adv_ttlm_info ttlm_info;
6034 res = ieee80211_parse_adv_t2l(sdata, elems->ttlm[i],
6038 __ieee80211_disconnect(sdata);
6042 if (ttlm_info.switch_time) {
6043 u32 st_us, delay = 0;
6044 u32 ts_l26 = beacon_ts & GENMASK(25, 0);
6046 /* The t2l map switch time is indicated with a partial
6047 * TSF value, convert it to TSF and calc the delay
6048 * to the start time.
6050 st_us = ieee80211_tu_to_usec(ttlm_info.switch_time);
6052 delay = st_us - ts_l26;
6056 sdata->u.mgd.ttlm_info = ttlm_info;
6057 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6058 &sdata->u.mgd.ttlm_work);
6059 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
6060 &sdata->u.mgd.ttlm_work,
6061 usecs_to_jiffies(delay));
6067 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
6068 struct ieee80211_hdr *hdr, size_t len,
6069 struct ieee80211_rx_status *rx_status)
6071 struct ieee80211_sub_if_data *sdata = link->sdata;
6072 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6073 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
6074 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
6075 struct ieee80211_mgmt *mgmt = (void *) hdr;
6077 struct ieee802_11_elems *elems;
6078 struct ieee80211_local *local = sdata->local;
6079 struct ieee80211_chanctx_conf *chanctx_conf;
6080 struct ieee80211_supported_band *sband;
6081 struct ieee80211_channel *chan;
6082 struct link_sta_info *link_sta;
6083 struct sta_info *sta;
6088 u8 *bssid, *variable = mgmt->u.beacon.variable;
6089 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
6090 struct ieee80211_elems_parse_params parse_params = {
6095 lockdep_assert_wiphy(local->hw.wiphy);
6097 /* Process beacon from the current BSS */
6098 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
6099 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
6100 struct ieee80211_ext *ext = (void *) mgmt;
6102 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
6103 variable = ext->u.s1g_short_beacon.variable;
6105 variable = ext->u.s1g_beacon.variable;
6108 baselen = (u8 *) variable - (u8 *) mgmt;
6112 parse_params.start = variable;
6113 parse_params.len = len - baselen;
6116 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
6117 if (!chanctx_conf) {
6122 if (ieee80211_rx_status_to_khz(rx_status) !=
6123 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
6127 chan = chanctx_conf->def.chan;
6130 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
6131 !WARN_ON(ieee80211_vif_is_mld(&sdata->vif)) &&
6132 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
6133 parse_params.bss = ifmgd->assoc_data->link[0].bss;
6134 elems = ieee802_11_parse_elems_full(&parse_params);
6138 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6140 if (elems->dtim_period)
6141 link->u.mgd.dtim_period = elems->dtim_period;
6142 link->u.mgd.have_beacon = true;
6143 ifmgd->assoc_data->need_beacon = false;
6144 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
6145 link->conf->sync_tsf =
6146 le64_to_cpu(mgmt->u.beacon.timestamp);
6147 link->conf->sync_device_ts =
6148 rx_status->device_timestamp;
6149 link->conf->sync_dtim_count = elems->dtim_count;
6152 if (elems->mbssid_config_ie)
6153 bss_conf->profile_periodicity =
6154 elems->mbssid_config_ie->profile_periodicity;
6156 bss_conf->profile_periodicity = 0;
6158 if (elems->ext_capab_len >= 11 &&
6159 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
6160 bss_conf->ema_ap = true;
6162 bss_conf->ema_ap = false;
6164 /* continue assoc process */
6165 ifmgd->assoc_data->timeout = jiffies;
6166 ifmgd->assoc_data->timeout_started = true;
6167 run_again(sdata, ifmgd->assoc_data->timeout);
6172 if (!ifmgd->associated ||
6173 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
6175 bssid = link->u.mgd.bssid;
6177 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
6178 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
6181 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
6182 mlme_dbg_ratelimited(sdata,
6183 "cancelling AP probe due to a received beacon\n");
6184 ieee80211_reset_ap_probe(sdata);
6188 * Push the beacon loss detection into the future since
6189 * we are processing a beacon from the AP just now.
6191 ieee80211_sta_reset_beacon_monitor(sdata);
6193 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
6194 * element (which carries the beacon interval). Don't forget to add a
6195 * bit to care_about_ies[] above if mac80211 is interested in a
6196 * changing S1G element.
6198 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
6199 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
6200 parse_params.bss = link->u.mgd.bss;
6201 parse_params.filter = care_about_ies;
6202 parse_params.crc = ncrc;
6203 elems = ieee802_11_parse_elems_full(&parse_params);
6208 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
6209 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
6210 if (local->hw.conf.dynamic_ps_timeout > 0) {
6211 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
6212 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
6213 ieee80211_hw_config(local,
6214 IEEE80211_CONF_CHANGE_PS);
6216 ieee80211_send_nullfunc(local, sdata, false);
6217 } else if (!local->pspolling && sdata->u.mgd.powersave) {
6218 local->pspolling = true;
6221 * Here is assumed that the driver will be
6222 * able to send ps-poll frame and receive a
6223 * response even though power save mode is
6224 * enabled, but some drivers might require
6225 * to disable power save here. This needs
6226 * to be investigated.
6228 ieee80211_send_pspoll(local, sdata);
6232 if (sdata->vif.p2p ||
6233 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
6234 struct ieee80211_p2p_noa_attr noa = {};
6237 ret = cfg80211_get_p2p_attr(variable,
6239 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
6240 (u8 *) &noa, sizeof(noa));
6242 if (link->u.mgd.p2p_noa_index != noa.index) {
6243 /* valid noa_attr and index changed */
6244 link->u.mgd.p2p_noa_index = noa.index;
6245 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
6246 changed |= BSS_CHANGED_P2P_PS;
6248 * make sure we update all information, the CRC
6249 * mechanism doesn't look at P2P attributes.
6251 link->u.mgd.beacon_crc_valid = false;
6253 } else if (link->u.mgd.p2p_noa_index != -1) {
6254 /* noa_attr not found and we had valid noa_attr before */
6255 link->u.mgd.p2p_noa_index = -1;
6256 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
6257 changed |= BSS_CHANGED_P2P_PS;
6258 link->u.mgd.beacon_crc_valid = false;
6262 if (link->u.mgd.csa_waiting_bcn)
6263 ieee80211_chswitch_post_beacon(link);
6266 * Update beacon timing and dtim count on every beacon appearance. This
6267 * will allow the driver to use the most updated values. Do it before
6268 * comparing this one with last received beacon.
6269 * IMPORTANT: These parameters would possibly be out of sync by the time
6270 * the driver will use them. The synchronized view is currently
6271 * guaranteed only in certain callbacks.
6273 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
6274 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
6275 link->conf->sync_tsf =
6276 le64_to_cpu(mgmt->u.beacon.timestamp);
6277 link->conf->sync_device_ts =
6278 rx_status->device_timestamp;
6279 link->conf->sync_dtim_count = elems->dtim_count;
6282 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
6283 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
6285 link->u.mgd.beacon_crc = ncrc;
6286 link->u.mgd.beacon_crc_valid = true;
6288 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6290 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
6291 rx_status->device_timestamp,
6294 if (!link->u.mgd.disable_wmm_tracking &&
6295 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
6296 elems->wmm_param_len,
6297 elems->mu_edca_param_set))
6298 changed |= BSS_CHANGED_QOS;
6301 * If we haven't had a beacon before, tell the driver about the
6302 * DTIM period (and beacon timing if desired) now.
6304 if (!link->u.mgd.have_beacon) {
6305 /* a few bogus AP send dtim_period = 0 or no TIM IE */
6306 bss_conf->dtim_period = elems->dtim_period ?: 1;
6308 changed |= BSS_CHANGED_BEACON_INFO;
6309 link->u.mgd.have_beacon = true;
6311 ieee80211_recalc_ps(local);
6313 ieee80211_recalc_ps_vif(sdata);
6316 if (elems->erp_info) {
6318 erp_value = elems->erp_info[0];
6323 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
6324 changed |= ieee80211_handle_bss_capability(link,
6325 le16_to_cpu(mgmt->u.beacon.capab_info),
6326 erp_valid, erp_value);
6328 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6329 if (WARN_ON(!sta)) {
6332 link_sta = rcu_dereference_protected(sta->link[link->link_id],
6333 lockdep_is_held(&local->hw.wiphy->mtx));
6334 if (WARN_ON(!link_sta)) {
6338 if (WARN_ON(!link->conf->chandef.chan))
6341 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
6343 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
6345 if (ieee80211_config_bw(link, elems->ht_cap_elem,
6346 elems->vht_cap_elem, elems->ht_operation,
6347 elems->vht_operation, elems->he_operation,
6348 elems->eht_operation,
6349 elems->s1g_oper, bssid, &changed)) {
6351 "failed to follow AP %pM bandwidth change, disconnect\n",
6353 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6354 WLAN_REASON_DEAUTH_LEAVING,
6356 ieee80211_report_disconnect(sdata, deauth_buf,
6357 sizeof(deauth_buf), true,
6358 WLAN_REASON_DEAUTH_LEAVING,
6363 if (elems->opmode_notif)
6364 ieee80211_vht_handle_opmode(sdata, link_sta,
6365 *elems->opmode_notif,
6368 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
6369 elems->country_elem,
6370 elems->country_elem_len,
6371 elems->pwr_constr_elem,
6372 elems->cisco_dtpc_elem);
6374 if (elems->eht_operation &&
6375 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
6376 if (!ieee80211_config_puncturing(link, elems->eht_operation,
6378 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6379 WLAN_REASON_DEAUTH_LEAVING,
6381 ieee80211_report_disconnect(sdata, deauth_buf,
6382 sizeof(deauth_buf), true,
6383 WLAN_REASON_DEAUTH_LEAVING,
6389 ieee80211_ml_reconfiguration(sdata, elems);
6390 ieee80211_process_adv_ttlm(sdata, elems,
6391 le64_to_cpu(mgmt->u.beacon.timestamp));
6393 ieee80211_link_info_change_notify(sdata, link, changed);
6398 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
6399 struct sk_buff *skb)
6401 struct ieee80211_link_data *link = &sdata->deflink;
6402 struct ieee80211_rx_status *rx_status;
6403 struct ieee80211_hdr *hdr;
6406 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6408 rx_status = (struct ieee80211_rx_status *) skb->cb;
6409 hdr = (struct ieee80211_hdr *) skb->data;
6410 fc = le16_to_cpu(hdr->frame_control);
6412 switch (fc & IEEE80211_FCTL_STYPE) {
6413 case IEEE80211_STYPE_S1G_BEACON:
6414 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
6419 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
6420 struct sk_buff *skb)
6422 struct ieee80211_link_data *link = &sdata->deflink;
6423 struct ieee80211_rx_status *rx_status;
6424 struct ieee80211_mgmt *mgmt;
6428 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6430 rx_status = (struct ieee80211_rx_status *) skb->cb;
6431 mgmt = (struct ieee80211_mgmt *) skb->data;
6432 fc = le16_to_cpu(mgmt->frame_control);
6434 if (rx_status->link_valid) {
6435 link = sdata_dereference(sdata->link[rx_status->link_id],
6441 switch (fc & IEEE80211_FCTL_STYPE) {
6442 case IEEE80211_STYPE_BEACON:
6443 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
6444 skb->len, rx_status);
6446 case IEEE80211_STYPE_PROBE_RESP:
6447 ieee80211_rx_mgmt_probe_resp(link, skb);
6449 case IEEE80211_STYPE_AUTH:
6450 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
6452 case IEEE80211_STYPE_DEAUTH:
6453 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
6455 case IEEE80211_STYPE_DISASSOC:
6456 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
6458 case IEEE80211_STYPE_ASSOC_RESP:
6459 case IEEE80211_STYPE_REASSOC_RESP:
6460 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
6462 case IEEE80211_STYPE_ACTION:
6463 if (!sdata->u.mgd.associated ||
6464 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
6467 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
6468 struct ieee802_11_elems *elems;
6470 ies_len = skb->len -
6471 offsetof(struct ieee80211_mgmt,
6472 u.action.u.chan_switch.variable);
6477 /* CSA IE cannot be overridden, no need for BSSID */
6478 elems = ieee802_11_parse_elems(
6479 mgmt->u.action.u.chan_switch.variable,
6480 ies_len, true, NULL);
6482 if (elems && !elems->parse_error)
6483 ieee80211_sta_process_chanswitch(link,
6485 rx_status->device_timestamp,
6488 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
6489 struct ieee802_11_elems *elems;
6491 ies_len = skb->len -
6492 offsetof(struct ieee80211_mgmt,
6493 u.action.u.ext_chan_switch.variable);
6499 * extended CSA IE can't be overridden, no need for
6502 elems = ieee802_11_parse_elems(
6503 mgmt->u.action.u.ext_chan_switch.variable,
6504 ies_len, true, NULL);
6506 if (elems && !elems->parse_error) {
6507 /* for the handling code pretend it was an IE */
6508 elems->ext_chansw_ie =
6509 &mgmt->u.action.u.ext_chan_switch.data;
6511 ieee80211_sta_process_chanswitch(link,
6513 rx_status->device_timestamp,
6523 static void ieee80211_sta_timer(struct timer_list *t)
6525 struct ieee80211_sub_if_data *sdata =
6526 from_timer(sdata, t, u.mgd.timer);
6528 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
6531 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
6534 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6536 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
6539 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6543 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
6545 struct ieee80211_local *local = sdata->local;
6546 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6547 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
6551 struct ieee80211_prep_tx_info info = {
6552 .subtype = IEEE80211_STYPE_AUTH,
6555 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6557 if (WARN_ON_ONCE(!auth_data))
6562 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
6563 sdata_info(sdata, "authentication with %pM timed out\n",
6564 auth_data->ap_addr);
6567 * Most likely AP is not in the range so remove the
6568 * bss struct for that AP.
6570 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
6575 if (auth_data->algorithm == WLAN_AUTH_SAE)
6576 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
6578 info.link_id = auth_data->link_id;
6579 drv_mgd_prepare_tx(local, sdata, &info);
6581 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
6582 auth_data->ap_addr, auth_data->tries,
6583 IEEE80211_AUTH_MAX_TRIES);
6585 auth_data->expected_transaction = 2;
6587 if (auth_data->algorithm == WLAN_AUTH_SAE) {
6588 trans = auth_data->sae_trans;
6589 status = auth_data->sae_status;
6590 auth_data->expected_transaction = trans;
6593 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6594 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
6595 IEEE80211_TX_INTFL_MLME_CONN_TX;
6597 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
6598 auth_data->data, auth_data->data_len,
6599 auth_data->ap_addr, auth_data->ap_addr,
6600 NULL, 0, 0, tx_flags);
6602 if (tx_flags == 0) {
6603 if (auth_data->algorithm == WLAN_AUTH_SAE)
6604 auth_data->timeout = jiffies +
6605 IEEE80211_AUTH_TIMEOUT_SAE;
6607 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
6609 auth_data->timeout =
6610 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
6613 auth_data->timeout_started = true;
6614 run_again(sdata, auth_data->timeout);
6619 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
6621 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
6622 struct ieee80211_local *local = sdata->local;
6625 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6627 assoc_data->tries++;
6628 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
6629 sdata_info(sdata, "association with %pM timed out\n",
6630 assoc_data->ap_addr);
6633 * Most likely AP is not in the range so remove the
6634 * bss struct for that AP.
6636 cfg80211_unlink_bss(local->hw.wiphy,
6637 assoc_data->link[assoc_data->assoc_link_id].bss);
6642 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
6643 assoc_data->ap_addr, assoc_data->tries,
6644 IEEE80211_ASSOC_MAX_TRIES);
6645 ret = ieee80211_send_assoc(sdata);
6649 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6650 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
6651 assoc_data->timeout_started = true;
6652 run_again(sdata, assoc_data->timeout);
6654 assoc_data->timeout =
6655 round_jiffies_up(jiffies +
6656 IEEE80211_ASSOC_TIMEOUT_LONG);
6657 assoc_data->timeout_started = true;
6658 run_again(sdata, assoc_data->timeout);
6664 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
6665 __le16 fc, bool acked)
6667 struct ieee80211_local *local = sdata->local;
6669 sdata->u.mgd.status_fc = fc;
6670 sdata->u.mgd.status_acked = acked;
6671 sdata->u.mgd.status_received = true;
6673 wiphy_work_queue(local->hw.wiphy, &sdata->work);
6676 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
6678 struct ieee80211_local *local = sdata->local;
6679 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6681 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6683 if (ifmgd->status_received) {
6684 __le16 fc = ifmgd->status_fc;
6685 bool status_acked = ifmgd->status_acked;
6687 ifmgd->status_received = false;
6688 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
6690 if (ifmgd->auth_data->algorithm ==
6692 ifmgd->auth_data->timeout =
6694 IEEE80211_AUTH_TIMEOUT_SAE;
6696 ifmgd->auth_data->timeout =
6698 IEEE80211_AUTH_TIMEOUT_SHORT;
6699 run_again(sdata, ifmgd->auth_data->timeout);
6701 ifmgd->auth_data->timeout = jiffies - 1;
6703 ifmgd->auth_data->timeout_started = true;
6704 } else if (ifmgd->assoc_data &&
6705 (ieee80211_is_assoc_req(fc) ||
6706 ieee80211_is_reassoc_req(fc))) {
6708 ifmgd->assoc_data->timeout =
6709 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
6710 run_again(sdata, ifmgd->assoc_data->timeout);
6712 ifmgd->assoc_data->timeout = jiffies - 1;
6714 ifmgd->assoc_data->timeout_started = true;
6718 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
6719 time_after(jiffies, ifmgd->auth_data->timeout)) {
6720 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
6722 * ok ... we waited for assoc or continuation but
6723 * userspace didn't do it, so kill the auth data
6725 ieee80211_destroy_auth_data(sdata, false);
6726 } else if (ieee80211_auth(sdata)) {
6727 u8 ap_addr[ETH_ALEN];
6728 struct ieee80211_event event = {
6730 .u.mlme.data = AUTH_EVENT,
6731 .u.mlme.status = MLME_TIMEOUT,
6734 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
6736 ieee80211_destroy_auth_data(sdata, false);
6738 cfg80211_auth_timeout(sdata->dev, ap_addr);
6739 drv_event_callback(sdata->local, sdata, &event);
6741 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
6742 run_again(sdata, ifmgd->auth_data->timeout);
6744 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
6745 time_after(jiffies, ifmgd->assoc_data->timeout)) {
6746 if ((ifmgd->assoc_data->need_beacon &&
6747 !sdata->deflink.u.mgd.have_beacon) ||
6748 ieee80211_do_assoc(sdata)) {
6749 struct ieee80211_event event = {
6751 .u.mlme.data = ASSOC_EVENT,
6752 .u.mlme.status = MLME_TIMEOUT,
6755 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6756 drv_event_callback(sdata->local, sdata, &event);
6758 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
6759 run_again(sdata, ifmgd->assoc_data->timeout);
6761 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
6762 ifmgd->associated) {
6763 u8 *bssid = sdata->deflink.u.mgd.bssid;
6766 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6767 max_tries = max_nullfunc_tries;
6769 max_tries = max_probe_tries;
6771 /* ACK received for nullfunc probing frame */
6772 if (!ifmgd->probe_send_count)
6773 ieee80211_reset_ap_probe(sdata);
6774 else if (ifmgd->nullfunc_failed) {
6775 if (ifmgd->probe_send_count < max_tries) {
6777 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
6778 bssid, ifmgd->probe_send_count,
6780 ieee80211_mgd_probe_ap_send(sdata);
6783 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
6785 ieee80211_sta_connection_lost(sdata,
6786 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
6789 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
6790 run_again(sdata, ifmgd->probe_timeout);
6791 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6793 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
6794 bssid, probe_wait_ms);
6795 ieee80211_sta_connection_lost(sdata,
6796 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6797 } else if (ifmgd->probe_send_count < max_tries) {
6799 "No probe response from AP %pM after %dms, try %d/%i\n",
6800 bssid, probe_wait_ms,
6801 ifmgd->probe_send_count, max_tries);
6802 ieee80211_mgd_probe_ap_send(sdata);
6805 * We actually lost the connection ... or did we?
6809 "No probe response from AP %pM after %dms, disconnecting.\n",
6810 bssid, probe_wait_ms);
6812 ieee80211_sta_connection_lost(sdata,
6813 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6818 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
6820 struct ieee80211_sub_if_data *sdata =
6821 from_timer(sdata, t, u.mgd.bcn_mon_timer);
6823 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
6826 if (sdata->vif.bss_conf.csa_active &&
6827 !sdata->deflink.u.mgd.csa_waiting_bcn)
6830 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
6833 sdata->u.mgd.connection_loss = false;
6834 wiphy_work_queue(sdata->local->hw.wiphy,
6835 &sdata->u.mgd.beacon_connection_loss_work);
6838 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
6840 struct ieee80211_sub_if_data *sdata =
6841 from_timer(sdata, t, u.mgd.conn_mon_timer);
6842 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6843 struct ieee80211_local *local = sdata->local;
6844 struct sta_info *sta;
6845 unsigned long timeout;
6847 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
6850 if (sdata->vif.bss_conf.csa_active &&
6851 !sdata->deflink.u.mgd.csa_waiting_bcn)
6854 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6858 timeout = sta->deflink.status_stats.last_ack;
6859 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
6860 timeout = sta->deflink.rx_stats.last_rx;
6861 timeout += IEEE80211_CONNECTION_IDLE_TIME;
6863 /* If timeout is after now, then update timer to fire at
6864 * the later date, but do not actually probe at this time.
6866 if (time_is_after_jiffies(timeout)) {
6867 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
6871 wiphy_work_queue(local->hw.wiphy, &sdata->u.mgd.monitor_work);
6874 static void ieee80211_sta_monitor_work(struct wiphy *wiphy,
6875 struct wiphy_work *work)
6877 struct ieee80211_sub_if_data *sdata =
6878 container_of(work, struct ieee80211_sub_if_data,
6879 u.mgd.monitor_work);
6881 ieee80211_mgd_probe_ap(sdata, false);
6884 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
6886 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
6887 __ieee80211_stop_poll(sdata);
6889 /* let's probe the connection once */
6890 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
6891 wiphy_work_queue(sdata->local->hw.wiphy,
6892 &sdata->u.mgd.monitor_work);
6897 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
6899 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6900 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6902 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6904 if (ifmgd->auth_data || ifmgd->assoc_data) {
6905 const u8 *ap_addr = ifmgd->auth_data ?
6906 ifmgd->auth_data->ap_addr :
6907 ifmgd->assoc_data->ap_addr;
6910 * If we are trying to authenticate / associate while suspending,
6911 * cfg80211 won't know and won't actually abort those attempts,
6912 * thus we need to do that ourselves.
6914 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
6915 IEEE80211_STYPE_DEAUTH,
6916 WLAN_REASON_DEAUTH_LEAVING,
6918 if (ifmgd->assoc_data)
6919 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6920 if (ifmgd->auth_data)
6921 ieee80211_destroy_auth_data(sdata, false);
6922 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
6923 IEEE80211_DEAUTH_FRAME_LEN,
6927 /* This is a bit of a hack - we should find a better and more generic
6928 * solution to this. Normally when suspending, cfg80211 will in fact
6929 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
6930 * auth (not so important) or assoc (this is the problem) process.
6932 * As a consequence, it can happen that we are in the process of both
6933 * associating and suspending, and receive an association response
6934 * after cfg80211 has checked if it needs to disconnect, but before
6935 * we actually set the flag to drop incoming frames. This will then
6936 * cause the workqueue flush to process the association response in
6937 * the suspend, resulting in a successful association just before it
6938 * tries to remove the interface from the driver, which now though
6939 * has a channel context assigned ... this results in issues.
6941 * To work around this (for now) simply deauth here again if we're
6944 if (ifmgd->associated && !sdata->local->wowlan) {
6946 struct cfg80211_deauth_request req = {
6947 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
6951 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
6952 ieee80211_mgd_deauth(sdata, &req);
6957 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
6959 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6961 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6963 if (!ifmgd->associated)
6966 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
6967 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
6968 mlme_dbg(sdata, "driver requested disconnect after resume\n");
6969 ieee80211_sta_connection_lost(sdata,
6970 WLAN_REASON_UNSPECIFIED,
6975 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
6976 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
6977 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
6978 ieee80211_sta_connection_lost(sdata,
6979 WLAN_REASON_UNSPECIFIED,
6985 static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy,
6986 struct wiphy_work *work)
6988 struct ieee80211_link_data *link =
6989 container_of(work, struct ieee80211_link_data,
6990 u.mgd.request_smps_work);
6992 __ieee80211_request_smps_mgd(link->sdata, link,
6993 link->u.mgd.driver_smps_mode);
6996 /* interface setup */
6997 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
6999 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7001 wiphy_work_init(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
7002 wiphy_work_init(&ifmgd->beacon_connection_loss_work,
7003 ieee80211_beacon_connection_loss_work);
7004 wiphy_work_init(&ifmgd->csa_connection_drop_work,
7005 ieee80211_csa_connection_drop_work);
7006 wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work,
7007 ieee80211_tdls_peer_del_work);
7008 wiphy_delayed_work_init(&ifmgd->ml_reconf_work,
7009 ieee80211_ml_reconf_work);
7010 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
7011 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
7012 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
7013 wiphy_delayed_work_init(&ifmgd->tx_tspec_wk,
7014 ieee80211_sta_handle_tspec_ac_params_wk);
7015 wiphy_delayed_work_init(&ifmgd->ttlm_work,
7016 ieee80211_tid_to_link_map_work);
7019 ifmgd->powersave = sdata->wdev.ps;
7020 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
7021 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
7022 /* Setup TDLS data */
7023 spin_lock_init(&ifmgd->teardown_lock);
7024 ifmgd->teardown_skb = NULL;
7025 ifmgd->orig_teardown_skb = NULL;
7028 static void ieee80211_recalc_smps_work(struct wiphy *wiphy,
7029 struct wiphy_work *work)
7031 struct ieee80211_link_data *link =
7032 container_of(work, struct ieee80211_link_data,
7035 ieee80211_recalc_smps(link->sdata, link);
7038 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
7040 struct ieee80211_sub_if_data *sdata = link->sdata;
7041 struct ieee80211_local *local = sdata->local;
7042 unsigned int link_id = link->link_id;
7044 link->u.mgd.p2p_noa_index = -1;
7045 link->u.mgd.conn_flags = 0;
7046 link->conf->bssid = link->u.mgd.bssid;
7048 wiphy_work_init(&link->u.mgd.request_smps_work,
7049 ieee80211_request_smps_mgd_work);
7050 wiphy_work_init(&link->u.mgd.recalc_smps,
7051 ieee80211_recalc_smps_work);
7052 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
7053 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
7055 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
7057 wiphy_delayed_work_init(&link->u.mgd.chswitch_work,
7058 ieee80211_chswitch_work);
7060 if (sdata->u.mgd.assoc_data)
7061 ether_addr_copy(link->conf->addr,
7062 sdata->u.mgd.assoc_data->link[link_id].addr);
7063 else if (!is_valid_ether_addr(link->conf->addr))
7064 eth_random_addr(link->conf->addr);
7067 /* scan finished notification */
7068 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
7070 struct ieee80211_sub_if_data *sdata;
7072 /* Restart STA timers */
7074 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
7075 if (ieee80211_sdata_running(sdata))
7076 ieee80211_restart_sta_timer(sdata);
7081 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
7082 struct cfg80211_bss *cbss, s8 link_id,
7083 const u8 *ap_mld_addr, bool assoc,
7086 struct ieee80211_local *local = sdata->local;
7087 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7088 struct ieee80211_bss *bss = (void *)cbss->priv;
7089 struct sta_info *new_sta = NULL;
7090 struct ieee80211_link_data *link;
7091 bool have_sta = false;
7097 if (WARN_ON(!ap_mld_addr))
7099 err = ieee80211_vif_set_links(sdata, BIT(link_id), 0);
7101 if (WARN_ON(ap_mld_addr))
7103 ap_mld_addr = cbss->bssid;
7104 err = ieee80211_vif_set_links(sdata, 0, 0);
7112 link = sdata_dereference(sdata->link[link_id], sdata);
7113 if (WARN_ON(!link)) {
7118 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
7123 /* If a reconfig is happening, bail out */
7124 if (local->in_reconfig) {
7131 have_sta = sta_info_get(sdata, ap_mld_addr);
7137 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
7138 link_id, cbss->bssid,
7141 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
7148 new_sta->sta.mlo = mlo;
7152 * Set up the information for the new channel before setting the
7153 * new channel. We can't - completely race-free - change the basic
7154 * rates bitmap and the channel (sband) that it refers to, but if
7155 * we set it up before we at least avoid calling into the driver's
7156 * bss_info_changed() method with invalid information (since we do
7157 * call that from changing the channel - only for IDLE and perhaps
7158 * some others, but ...).
7160 * So to avoid that, just set up all the new information before the
7161 * channel, but tell the driver to apply it only afterwards, since
7162 * it might need the new channel for that.
7165 const struct cfg80211_bss_ies *ies;
7166 struct link_sta_info *link_sta;
7169 link_sta = rcu_dereference(new_sta->link[link_id]);
7170 if (WARN_ON(!link_sta)) {
7172 sta_info_free(local, new_sta);
7177 err = ieee80211_mgd_setup_link_sta(link, new_sta,
7181 sta_info_free(local, new_sta);
7185 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
7187 /* set timing information */
7188 link->conf->beacon_int = cbss->beacon_interval;
7189 ies = rcu_dereference(cbss->beacon_ies);
7191 link->conf->sync_tsf = ies->tsf;
7192 link->conf->sync_device_ts =
7193 bss->device_ts_beacon;
7195 ieee80211_get_dtim(ies,
7196 &link->conf->sync_dtim_count,
7198 } else if (!ieee80211_hw_check(&sdata->local->hw,
7199 TIMING_BEACON_ONLY)) {
7200 ies = rcu_dereference(cbss->proberesp_ies);
7201 /* must be non-NULL since beacon IEs were NULL */
7202 link->conf->sync_tsf = ies->tsf;
7203 link->conf->sync_device_ts =
7204 bss->device_ts_presp;
7205 link->conf->sync_dtim_count = 0;
7207 link->conf->sync_tsf = 0;
7208 link->conf->sync_device_ts = 0;
7209 link->conf->sync_dtim_count = 0;
7214 if (new_sta || override) {
7215 err = ieee80211_prep_channel(sdata, link, cbss, mlo,
7216 &link->u.mgd.conn_flags);
7219 sta_info_free(local, new_sta);
7226 * tell driver about BSSID, basic rates and timing
7227 * this was set up above, before setting the channel
7229 ieee80211_link_info_change_notify(sdata, link,
7231 BSS_CHANGED_BASIC_RATES |
7232 BSS_CHANGED_BEACON_INT);
7235 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
7237 err = sta_info_insert(new_sta);
7241 "failed to insert STA entry for the AP (error %d)\n",
7246 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
7248 /* Cancel scan to ensure that nothing interferes with connection */
7249 if (local->scanning)
7250 ieee80211_scan_cancel(local);
7255 ieee80211_link_release_channel(&sdata->deflink);
7256 ieee80211_vif_set_links(sdata, 0, 0);
7261 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
7262 struct cfg80211_auth_request *req)
7264 struct ieee80211_local *local = sdata->local;
7265 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7266 struct ieee80211_mgd_auth_data *auth_data;
7267 struct ieee80211_link_data *link;
7268 const struct element *csa_elem, *ecsa_elem;
7273 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7275 /* prepare auth data structure */
7277 switch (req->auth_type) {
7278 case NL80211_AUTHTYPE_OPEN_SYSTEM:
7279 auth_alg = WLAN_AUTH_OPEN;
7281 case NL80211_AUTHTYPE_SHARED_KEY:
7284 auth_alg = WLAN_AUTH_SHARED_KEY;
7286 case NL80211_AUTHTYPE_FT:
7287 auth_alg = WLAN_AUTH_FT;
7289 case NL80211_AUTHTYPE_NETWORK_EAP:
7290 auth_alg = WLAN_AUTH_LEAP;
7292 case NL80211_AUTHTYPE_SAE:
7293 auth_alg = WLAN_AUTH_SAE;
7295 case NL80211_AUTHTYPE_FILS_SK:
7296 auth_alg = WLAN_AUTH_FILS_SK;
7298 case NL80211_AUTHTYPE_FILS_SK_PFS:
7299 auth_alg = WLAN_AUTH_FILS_SK_PFS;
7301 case NL80211_AUTHTYPE_FILS_PK:
7302 auth_alg = WLAN_AUTH_FILS_PK;
7308 if (ifmgd->assoc_data)
7312 csa_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_CHANNEL_SWITCH);
7313 ecsa_elem = ieee80211_bss_get_elem(req->bss,
7314 WLAN_EID_EXT_CHANSWITCH_ANN);
7316 csa_elem->datalen == sizeof(struct ieee80211_channel_sw_ie) &&
7317 ((struct ieee80211_channel_sw_ie *)csa_elem->data)->count != 0) ||
7319 ecsa_elem->datalen == sizeof(struct ieee80211_ext_chansw_ie) &&
7320 ((struct ieee80211_ext_chansw_ie *)ecsa_elem->data)->count != 0)) {
7322 sdata_info(sdata, "AP is in CSA process, reject auth\n");
7327 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
7328 req->ie_len, GFP_KERNEL);
7332 memcpy(auth_data->ap_addr,
7333 req->ap_mld_addr ?: req->bss->bssid,
7335 auth_data->bss = req->bss;
7336 auth_data->link_id = req->link_id;
7338 if (req->auth_data_len >= 4) {
7339 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
7340 __le16 *pos = (__le16 *) req->auth_data;
7342 auth_data->sae_trans = le16_to_cpu(pos[0]);
7343 auth_data->sae_status = le16_to_cpu(pos[1]);
7345 memcpy(auth_data->data, req->auth_data + 4,
7346 req->auth_data_len - 4);
7347 auth_data->data_len += req->auth_data_len - 4;
7350 /* Check if continuing authentication or trying to authenticate with the
7351 * same BSS that we were in the process of authenticating with and avoid
7352 * removal and re-addition of the STA entry in
7353 * ieee80211_prep_connection().
7355 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
7356 ifmgd->auth_data->link_id == req->link_id;
7358 if (req->ie && req->ie_len) {
7359 memcpy(&auth_data->data[auth_data->data_len],
7360 req->ie, req->ie_len);
7361 auth_data->data_len += req->ie_len;
7364 if (req->key && req->key_len) {
7365 auth_data->key_len = req->key_len;
7366 auth_data->key_idx = req->key_idx;
7367 memcpy(auth_data->key, req->key, req->key_len);
7370 auth_data->algorithm = auth_alg;
7372 /* try to authenticate/probe */
7374 if (ifmgd->auth_data) {
7375 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
7376 auth_data->peer_confirmed =
7377 ifmgd->auth_data->peer_confirmed;
7379 ieee80211_destroy_auth_data(sdata, cont_auth);
7382 /* prep auth_data so we don't go into idle on disassoc */
7383 ifmgd->auth_data = auth_data;
7385 /* If this is continuation of an ongoing SAE authentication exchange
7386 * (i.e., request to send SAE Confirm) and the peer has already
7387 * confirmed, mark authentication completed since we are about to send
7390 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
7391 auth_data->peer_confirmed && auth_data->sae_trans == 2)
7392 ieee80211_mark_sta_auth(sdata);
7394 if (ifmgd->associated) {
7395 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7398 "disconnect from AP %pM for new auth to %pM\n",
7399 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
7400 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7401 WLAN_REASON_UNSPECIFIED,
7404 ieee80211_report_disconnect(sdata, frame_buf,
7405 sizeof(frame_buf), true,
7406 WLAN_REASON_UNSPECIFIED,
7410 /* needed for transmitting the auth frame(s) properly */
7411 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
7413 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
7414 req->ap_mld_addr, cont_auth, false);
7418 if (req->link_id > 0)
7419 link = sdata_dereference(sdata->link[req->link_id], sdata);
7421 link = sdata_dereference(sdata->link[0], sdata);
7423 if (WARN_ON(!link)) {
7428 sdata_info(sdata, "authenticate with %pM (local address=%pM)\n",
7429 auth_data->ap_addr, link->conf->addr);
7431 err = ieee80211_auth(sdata);
7433 sta_info_destroy_addr(sdata, auth_data->ap_addr);
7437 /* hold our own reference */
7438 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
7442 if (!ieee80211_vif_is_mld(&sdata->vif)) {
7443 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7444 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7446 ieee80211_link_release_channel(&sdata->deflink);
7448 ifmgd->auth_data = NULL;
7453 static ieee80211_conn_flags_t
7454 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
7455 struct ieee80211_mgd_assoc_data *assoc_data,
7456 struct cfg80211_assoc_request *req,
7457 ieee80211_conn_flags_t conn_flags,
7458 unsigned int link_id)
7460 struct ieee80211_local *local = sdata->local;
7461 const struct cfg80211_bss_ies *bss_ies;
7462 struct ieee80211_supported_band *sband;
7463 const struct element *ht_elem, *vht_elem;
7464 struct ieee80211_link_data *link;
7465 struct cfg80211_bss *cbss;
7466 struct ieee80211_bss *bss;
7467 bool is_5ghz, is_6ghz;
7469 cbss = assoc_data->link[link_id].bss;
7473 bss = (void *)cbss->priv;
7475 sband = local->hw.wiphy->bands[cbss->channel->band];
7476 if (WARN_ON(!sband))
7479 link = sdata_dereference(sdata->link[link_id], sdata);
7483 is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
7484 is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
7486 /* for MLO connections assume advertising all rates is OK */
7487 if (!req->ap_mld_addr) {
7488 assoc_data->supp_rates = bss->supp_rates;
7489 assoc_data->supp_rates_len = bss->supp_rates_len;
7492 /* copy and link elems for the STA profile */
7493 if (req->links[link_id].elems_len) {
7494 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
7495 req->links[link_id].elems_len);
7496 assoc_data->link[link_id].elems = assoc_data->ie_pos;
7497 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
7498 assoc_data->ie_pos += req->links[link_id].elems_len;
7502 ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
7503 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
7504 assoc_data->link[link_id].ap_ht_param =
7505 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
7507 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7508 vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
7509 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
7510 memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
7511 sizeof(struct ieee80211_vht_cap));
7512 } else if (is_5ghz) {
7514 "VHT capa missing/short, disabling VHT/HE/EHT\n");
7515 conn_flags |= IEEE80211_CONN_DISABLE_VHT |
7516 IEEE80211_CONN_DISABLE_HE |
7517 IEEE80211_CONN_DISABLE_EHT;
7521 link->u.mgd.beacon_crc_valid = false;
7522 link->u.mgd.dtim_period = 0;
7523 link->u.mgd.have_beacon = false;
7525 /* override HT/VHT configuration only if the AP and we support it */
7526 if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
7527 struct ieee80211_sta_ht_cap sta_ht_cap;
7529 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
7530 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
7533 link->conf->eht_puncturing = 0;
7536 bss_ies = rcu_dereference(cbss->beacon_ies);
7540 ieee80211_get_dtim(bss_ies, &dtim_count,
7541 &link->u.mgd.dtim_period);
7543 sdata->deflink.u.mgd.have_beacon = true;
7545 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
7546 link->conf->sync_tsf = bss_ies->tsf;
7547 link->conf->sync_device_ts = bss->device_ts_beacon;
7548 link->conf->sync_dtim_count = dtim_count;
7551 bss_ies = rcu_dereference(cbss->ies);
7555 const struct ieee80211_eht_operation *eht_oper;
7556 const struct element *elem;
7558 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
7559 bss_ies->data, bss_ies->len);
7560 if (elem && elem->datalen >= 3)
7561 link->conf->profile_periodicity = elem->data[2];
7563 link->conf->profile_periodicity = 0;
7565 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
7566 bss_ies->data, bss_ies->len);
7567 if (elem && elem->datalen >= 11 &&
7568 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
7569 link->conf->ema_ap = true;
7571 link->conf->ema_ap = false;
7573 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION,
7574 bss_ies->data, bss_ies->len);
7575 eht_oper = (const void *)(elem->data + 1);
7578 ieee80211_eht_oper_size_ok((const void *)(elem->data + 1),
7579 elem->datalen - 1) &&
7580 (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
7581 (eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
7582 const struct ieee80211_eht_operation_info *info =
7583 (void *)eht_oper->optional;
7584 const u8 *disable_subchannel_bitmap = info->optional;
7587 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
7588 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
7589 &link->conf->chandef))
7590 ieee80211_handle_puncturing_bitmap(link,
7595 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7600 if (bss->corrupt_data) {
7601 char *corrupt_type = "data";
7603 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
7604 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
7605 corrupt_type = "beacon and probe response";
7607 corrupt_type = "beacon";
7608 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
7609 corrupt_type = "probe response";
7611 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
7612 cbss->bssid, corrupt_type);
7615 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
7616 if (sdata->u.mgd.powersave)
7617 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
7619 link->smps_mode = IEEE80211_SMPS_OFF;
7621 link->smps_mode = link->u.mgd.req_smps;
7627 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
7628 struct cfg80211_assoc_request *req)
7630 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
7631 struct ieee80211_local *local = sdata->local;
7632 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7633 struct ieee80211_mgd_assoc_data *assoc_data;
7634 const struct element *ssid_elem, *csa_elem, *ecsa_elem;
7635 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
7636 ieee80211_conn_flags_t conn_flags = 0;
7637 struct ieee80211_link_data *link;
7638 struct cfg80211_bss *cbss;
7639 struct ieee80211_bss *bss;
7642 size_t size = sizeof(*assoc_data) + req->ie_len;
7644 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
7645 size += req->links[i].elems_len;
7647 /* FIXME: no support for 4-addr MLO yet */
7648 if (sdata->u.mgd.use_4addr && req->link_id >= 0)
7651 assoc_data = kzalloc(size, GFP_KERNEL);
7655 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
7658 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
7659 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
7665 csa_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_CHANNEL_SWITCH);
7666 ecsa_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_EXT_CHANSWITCH_ANN);
7668 csa_elem->datalen == sizeof(struct ieee80211_channel_sw_ie) &&
7669 ((struct ieee80211_channel_sw_ie *)csa_elem->data)->count != 0) ||
7671 ecsa_elem->datalen == sizeof(struct ieee80211_ext_chansw_ie) &&
7672 ((struct ieee80211_ext_chansw_ie *)ecsa_elem->data)->count != 0)) {
7673 sdata_info(sdata, "AP is in CSA process, reject assoc\n");
7679 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
7680 assoc_data->ssid_len = ssid_elem->datalen;
7681 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
7682 vif_cfg->ssid_len = assoc_data->ssid_len;
7685 if (req->ap_mld_addr) {
7686 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
7687 if (!req->links[i].bss)
7689 link = sdata_dereference(sdata->link[i], sdata);
7691 ether_addr_copy(assoc_data->link[i].addr,
7694 eth_random_addr(assoc_data->link[i].addr);
7697 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
7700 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
7702 memcpy(assoc_data->ap_addr,
7703 req->ap_mld_addr ?: req->bss->bssid,
7706 if (ifmgd->associated) {
7707 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7710 "disconnect from AP %pM for new assoc to %pM\n",
7711 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
7712 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7713 WLAN_REASON_UNSPECIFIED,
7716 ieee80211_report_disconnect(sdata, frame_buf,
7717 sizeof(frame_buf), true,
7718 WLAN_REASON_UNSPECIFIED,
7722 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
7727 if (ifmgd->assoc_data) {
7732 if (ifmgd->auth_data) {
7735 /* keep sta info, bssid if matching */
7736 match = ether_addr_equal(ifmgd->auth_data->ap_addr,
7737 assoc_data->ap_addr) &&
7738 ifmgd->auth_data->link_id == req->link_id;
7740 /* Cleanup is delayed if auth_data matches */
7742 ieee80211_destroy_auth_data(sdata, false);
7745 /* prepare assoc data */
7747 bss = (void *)cbss->priv;
7748 assoc_data->wmm = bss->wmm_used &&
7749 (local->hw.queues >= IEEE80211_NUM_ACS);
7752 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
7753 * We still associate in non-HT mode (11a/b/g) if any one of these
7754 * ciphers is configured as pairwise.
7755 * We can set this to true for non-11n hardware, that'll be checked
7756 * separately along with the peer capabilities.
7758 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
7759 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
7760 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
7761 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
7762 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7763 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7764 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7765 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7766 netdev_info(sdata->dev,
7767 "disabling HT/VHT/HE due to WEP/TKIP use\n");
7771 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
7772 if (!bss->wmm_used) {
7773 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7774 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7775 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7776 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7777 netdev_info(sdata->dev,
7778 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
7781 if (req->flags & ASSOC_REQ_DISABLE_HT) {
7782 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
7783 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7784 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7785 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7786 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7789 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
7790 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
7791 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7794 if (req->flags & ASSOC_REQ_DISABLE_HE) {
7795 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
7796 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7797 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7800 if (req->flags & ASSOC_REQ_DISABLE_EHT)
7801 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7803 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
7804 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
7805 sizeof(ifmgd->ht_capa_mask));
7807 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
7808 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
7809 sizeof(ifmgd->vht_capa_mask));
7811 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
7812 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
7813 sizeof(ifmgd->s1g_capa_mask));
7815 if (req->ie && req->ie_len) {
7816 memcpy(assoc_data->ie, req->ie, req->ie_len);
7817 assoc_data->ie_len = req->ie_len;
7818 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
7820 assoc_data->ie_pos = assoc_data->ie;
7823 if (req->fils_kek) {
7824 /* should already be checked in cfg80211 - so warn */
7825 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
7829 memcpy(assoc_data->fils_kek, req->fils_kek,
7831 assoc_data->fils_kek_len = req->fils_kek_len;
7834 if (req->fils_nonces)
7835 memcpy(assoc_data->fils_nonces, req->fils_nonces,
7836 2 * FILS_NONCE_LEN);
7838 /* default timeout */
7839 assoc_data->timeout = jiffies;
7840 assoc_data->timeout_started = true;
7842 assoc_data->assoc_link_id = assoc_link_id;
7844 if (req->ap_mld_addr) {
7845 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7846 assoc_data->link[i].conn_flags = conn_flags;
7847 assoc_data->link[i].bss = req->links[i].bss;
7848 assoc_data->link[i].disabled = req->links[i].disabled;
7851 /* if there was no authentication, set up the link */
7852 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id), 0);
7856 assoc_data->link[0].conn_flags = conn_flags;
7857 assoc_data->link[0].bss = cbss;
7860 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
7861 if (WARN_ON(!link)) {
7866 /* keep old conn_flags from ieee80211_prep_channel() from auth */
7867 conn_flags |= link->u.mgd.conn_flags;
7868 conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
7869 conn_flags, assoc_link_id);
7870 override = link->u.mgd.conn_flags != conn_flags;
7871 link->u.mgd.conn_flags |= conn_flags;
7873 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
7874 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
7875 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
7876 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
7878 if (bss->wmm_used && bss->uapsd_supported &&
7879 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
7880 assoc_data->uapsd = true;
7881 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
7883 assoc_data->uapsd = false;
7884 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
7887 if (req->prev_bssid)
7888 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
7891 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
7892 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
7894 ifmgd->mfp = IEEE80211_MFP_DISABLED;
7895 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
7898 if (req->flags & ASSOC_REQ_USE_RRM)
7899 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
7901 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
7903 if (req->crypto.control_port)
7904 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
7906 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
7908 sdata->control_port_protocol = req->crypto.control_port_ethertype;
7909 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
7910 sdata->control_port_over_nl80211 =
7911 req->crypto.control_port_over_nl80211;
7912 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
7914 /* kick off associate process */
7915 ifmgd->assoc_data = assoc_data;
7917 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7918 if (!assoc_data->link[i].bss)
7920 if (i == assoc_data->assoc_link_id)
7922 /* only calculate the flags, hence link == NULL */
7923 err = ieee80211_prep_channel(sdata, NULL,
7924 assoc_data->link[i].bss, true,
7925 &assoc_data->link[i].conn_flags);
7927 req->links[i].error = err;
7932 /* needed for transmitting the assoc frames properly */
7933 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
7935 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
7936 req->ap_mld_addr, true, override);
7940 assoc_data->link[assoc_data->assoc_link_id].conn_flags =
7941 link->u.mgd.conn_flags;
7943 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
7944 const struct cfg80211_bss_ies *beacon_ies;
7947 beacon_ies = rcu_dereference(req->bss->beacon_ies);
7951 * Wait up to one beacon interval ...
7952 * should this be more if we miss one?
7954 sdata_info(sdata, "waiting for beacon from %pM\n",
7956 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
7957 assoc_data->timeout_started = true;
7958 assoc_data->need_beacon = true;
7963 run_again(sdata, assoc_data->timeout);
7965 /* We are associating, clean up auth_data */
7966 if (ifmgd->auth_data)
7967 ieee80211_destroy_auth_data(sdata, true);
7971 if (!ifmgd->auth_data) {
7972 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7973 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7976 ifmgd->assoc_data = NULL;
7982 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
7983 struct cfg80211_deauth_request *req)
7985 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7986 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7987 bool tx = !req->local_state_change;
7988 struct ieee80211_prep_tx_info info = {
7989 .subtype = IEEE80211_STYPE_DEAUTH,
7992 if (ifmgd->auth_data &&
7993 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
7995 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
7996 req->bssid, req->reason_code,
7997 ieee80211_get_reason_code_string(req->reason_code));
7999 info.link_id = ifmgd->auth_data->link_id;
8000 drv_mgd_prepare_tx(sdata->local, sdata, &info);
8001 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
8002 IEEE80211_STYPE_DEAUTH,
8003 req->reason_code, tx,
8005 ieee80211_destroy_auth_data(sdata, false);
8006 ieee80211_report_disconnect(sdata, frame_buf,
8007 sizeof(frame_buf), true,
8008 req->reason_code, false);
8009 drv_mgd_complete_tx(sdata->local, sdata, &info);
8013 if (ifmgd->assoc_data &&
8014 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
8016 "aborting association with %pM by local choice (Reason: %u=%s)\n",
8017 req->bssid, req->reason_code,
8018 ieee80211_get_reason_code_string(req->reason_code));
8020 info.link_id = ifmgd->assoc_data->assoc_link_id;
8021 drv_mgd_prepare_tx(sdata->local, sdata, &info);
8022 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
8023 IEEE80211_STYPE_DEAUTH,
8024 req->reason_code, tx,
8026 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
8027 ieee80211_report_disconnect(sdata, frame_buf,
8028 sizeof(frame_buf), true,
8029 req->reason_code, false);
8033 if (ifmgd->associated &&
8034 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
8036 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
8037 req->bssid, req->reason_code,
8038 ieee80211_get_reason_code_string(req->reason_code));
8040 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
8041 req->reason_code, tx, frame_buf);
8042 ieee80211_report_disconnect(sdata, frame_buf,
8043 sizeof(frame_buf), true,
8044 req->reason_code, false);
8045 drv_mgd_complete_tx(sdata->local, sdata, &info);
8052 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
8053 struct cfg80211_disassoc_request *req)
8055 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
8057 if (!sdata->u.mgd.associated ||
8058 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
8062 "disassociating from %pM by local choice (Reason: %u=%s)\n",
8063 req->ap_addr, req->reason_code,
8064 ieee80211_get_reason_code_string(req->reason_code));
8066 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
8067 req->reason_code, !req->local_state_change,
8070 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
8071 req->reason_code, false);
8076 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
8078 wiphy_work_cancel(link->sdata->local->hw.wiphy,
8079 &link->u.mgd.request_smps_work);
8080 wiphy_work_cancel(link->sdata->local->hw.wiphy,
8081 &link->u.mgd.recalc_smps);
8082 wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy,
8083 &link->u.mgd.chswitch_work);
8086 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
8088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8091 * Make sure some work items will not run after this,
8092 * they will not do anything but might not have been
8093 * cancelled when disconnecting.
8095 wiphy_work_cancel(sdata->local->hw.wiphy,
8096 &ifmgd->monitor_work);
8097 wiphy_work_cancel(sdata->local->hw.wiphy,
8098 &ifmgd->beacon_connection_loss_work);
8099 wiphy_work_cancel(sdata->local->hw.wiphy,
8100 &ifmgd->csa_connection_drop_work);
8101 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
8102 &ifmgd->tdls_peer_del_work);
8103 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
8104 &ifmgd->ml_reconf_work);
8105 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
8107 if (ifmgd->assoc_data)
8108 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
8109 if (ifmgd->auth_data)
8110 ieee80211_destroy_auth_data(sdata, false);
8111 spin_lock_bh(&ifmgd->teardown_lock);
8112 if (ifmgd->teardown_skb) {
8113 kfree_skb(ifmgd->teardown_skb);
8114 ifmgd->teardown_skb = NULL;
8115 ifmgd->orig_teardown_skb = NULL;
8117 kfree(ifmgd->assoc_req_ies);
8118 ifmgd->assoc_req_ies = NULL;
8119 ifmgd->assoc_req_ies_len = 0;
8120 spin_unlock_bh(&ifmgd->teardown_lock);
8121 del_timer_sync(&ifmgd->timer);
8124 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
8125 enum nl80211_cqm_rssi_threshold_event rssi_event,
8129 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8131 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
8133 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
8135 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
8137 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
8139 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8141 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
8143 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
8145 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
8147 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
8151 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
8153 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
8157 * Scale up threshold values before storing it, as the RSSI averaging
8158 * algorithm uses a scaled up value as well. Change this scaling
8159 * factor if the RSSI averaging algorithm changes.
8161 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
8162 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
8165 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
8169 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8171 WARN_ON(rssi_min_thold == rssi_max_thold ||
8172 rssi_min_thold > rssi_max_thold);
8174 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
8177 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
8179 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
8181 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8183 _ieee80211_enable_rssi_reports(sdata, 0, 0);
8185 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);