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(eht_oper, true, true, &ap_chandef);
114 ap_center_freq = ap_chandef.center_freq1;
115 ap_bw = 20 * BIT(u8_get_bits(info->control,
116 IEEE80211_EHT_OPER_CHAN_WIDTH));
117 ap_start_freq = ap_center_freq - ap_bw / 2;
118 local_center_freq = chandef->center_freq1;
119 local_bw = 20 * BIT(ieee80211_chan_width_to_rx_bw(chandef->width));
120 local_start_freq = local_center_freq - local_bw / 2;
121 shift = (local_start_freq - ap_start_freq) / 20;
122 mask = BIT(local_bw / 20) - 1;
124 return (bitmap >> shift) & mask;
128 * Handle the puncturing bitmap, possibly downgrading bandwidth to get a
132 ieee80211_handle_puncturing_bitmap(struct ieee80211_link_data *link,
133 const struct ieee80211_eht_operation *eht_oper,
134 u16 bitmap, u64 *changed)
136 struct cfg80211_chan_def *chandef = &link->conf->chandef;
143 while (chandef->width > NL80211_CHAN_WIDTH_40) {
145 ieee80211_extract_dis_subch_bmap(eht_oper, chandef,
148 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
151 link->u.mgd.conn_flags |=
152 ieee80211_chandef_downgrade(chandef);
153 *changed |= BSS_CHANGED_BANDWIDTH;
156 if (chandef->width <= NL80211_CHAN_WIDTH_40)
159 if (link->conf->eht_puncturing != extracted) {
160 link->conf->eht_puncturing = extracted;
161 *changed |= BSS_CHANGED_EHT_PUNCTURING;
166 * We can have multiple work items (and connection probing)
167 * scheduling this timer, but we need to take care to only
168 * reschedule it when it should fire _earlier_ than it was
169 * asked for before, or if it's not pending right now. This
170 * function ensures that. Note that it then is required to
171 * run this function for all timeouts after the first one
172 * has happened -- the work that runs from this timer will
175 static void run_again(struct ieee80211_sub_if_data *sdata,
176 unsigned long timeout)
178 sdata_assert_lock(sdata);
180 if (!timer_pending(&sdata->u.mgd.timer) ||
181 time_before(timeout, sdata->u.mgd.timer.expires))
182 mod_timer(&sdata->u.mgd.timer, timeout);
185 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
187 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
190 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
193 mod_timer(&sdata->u.mgd.bcn_mon_timer,
194 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
197 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
199 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
201 if (unlikely(!ifmgd->associated))
204 if (ifmgd->probe_send_count)
205 ifmgd->probe_send_count = 0;
207 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
210 mod_timer(&ifmgd->conn_mon_timer,
211 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
214 static int ecw2cw(int ecw)
216 return (1 << ecw) - 1;
219 static ieee80211_conn_flags_t
220 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
221 struct ieee80211_link_data *link,
222 ieee80211_conn_flags_t conn_flags,
223 struct ieee80211_supported_band *sband,
224 struct ieee80211_channel *channel,
226 const struct ieee80211_ht_operation *ht_oper,
227 const struct ieee80211_vht_operation *vht_oper,
228 const struct ieee80211_he_operation *he_oper,
229 const struct ieee80211_eht_operation *eht_oper,
230 const struct ieee80211_s1g_oper_ie *s1g_oper,
231 struct cfg80211_chan_def *chandef, bool tracking)
233 struct cfg80211_chan_def vht_chandef;
234 struct ieee80211_sta_ht_cap sta_ht_cap;
235 ieee80211_conn_flags_t ret;
238 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
239 chandef->chan = channel;
240 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
241 chandef->center_freq1 = channel->center_freq;
242 chandef->freq1_offset = channel->freq_offset;
244 if (channel->band == NL80211_BAND_6GHZ) {
245 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
248 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
249 ret = IEEE80211_CONN_DISABLE_HT |
250 IEEE80211_CONN_DISABLE_VHT |
251 IEEE80211_CONN_DISABLE_HE |
252 IEEE80211_CONN_DISABLE_EHT;
256 vht_chandef = *chandef;
258 } else if (sband->band == NL80211_BAND_S1GHZ) {
259 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
261 "Missing S1G Operation Element? Trying operating == primary\n");
262 chandef->width = ieee80211_s1g_channel_width(channel);
265 ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
266 IEEE80211_CONN_DISABLE_VHT |
267 IEEE80211_CONN_DISABLE_80P80MHZ |
268 IEEE80211_CONN_DISABLE_160MHZ;
272 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
273 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
275 if (!ht_oper || !sta_ht_cap.ht_supported) {
276 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
277 ret = IEEE80211_CONN_DISABLE_HT |
278 IEEE80211_CONN_DISABLE_VHT |
279 IEEE80211_CONN_DISABLE_HE |
280 IEEE80211_CONN_DISABLE_EHT;
284 chandef->width = NL80211_CHAN_WIDTH_20;
286 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
288 /* check that channel matches the right operating channel */
289 if (!tracking && channel->center_freq != ht_cfreq) {
291 * It's possible that some APs are confused here;
292 * Netgear WNDR3700 sometimes reports 4 higher than
293 * the actual channel in association responses, but
294 * since we look at probe response/beacon data here
298 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
299 channel->center_freq, ht_cfreq,
300 ht_oper->primary_chan, channel->band);
301 ret = IEEE80211_CONN_DISABLE_HT |
302 IEEE80211_CONN_DISABLE_VHT |
303 IEEE80211_CONN_DISABLE_HE |
304 IEEE80211_CONN_DISABLE_EHT;
308 /* check 40 MHz support, if we have it */
309 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
310 ieee80211_chandef_ht_oper(ht_oper, chandef);
312 mlme_dbg(sdata, "40 MHz not supported\n");
313 /* 40 MHz (and 80 MHz) must be supported for VHT */
314 ret = IEEE80211_CONN_DISABLE_VHT;
315 /* also mark 40 MHz disabled */
316 ret |= IEEE80211_CONN_DISABLE_40MHZ;
320 if (!vht_oper || !sband->vht_cap.vht_supported) {
321 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
322 ret = IEEE80211_CONN_DISABLE_VHT;
326 vht_chandef = *chandef;
327 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE) &&
329 (le32_to_cpu(he_oper->he_oper_params) &
330 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
331 struct ieee80211_vht_operation he_oper_vht_cap;
334 * Set only first 3 bytes (other 2 aren't used in
335 * ieee80211_chandef_vht_oper() anyway)
337 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
338 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
340 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
341 &he_oper_vht_cap, ht_oper,
343 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE))
345 "HE AP VHT information is invalid, disabling HE\n");
346 ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
349 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
353 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
355 "AP VHT information is invalid, disabling VHT\n");
356 ret = IEEE80211_CONN_DISABLE_VHT;
360 if (!cfg80211_chandef_valid(&vht_chandef)) {
361 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
363 "AP VHT information is invalid, disabling VHT\n");
364 ret = IEEE80211_CONN_DISABLE_VHT;
368 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
373 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
374 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
376 "AP VHT information doesn't match HT, disabling VHT\n");
377 ret = IEEE80211_CONN_DISABLE_VHT;
381 *chandef = vht_chandef;
384 * handle the case that the EHT operation indicates that it holds EHT
385 * operation information (in case that the channel width differs from
386 * the channel width reported in HT/VHT/HE).
388 if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
389 struct cfg80211_chan_def eht_chandef = *chandef;
391 ieee80211_chandef_eht_oper(eht_oper,
393 NL80211_CHAN_WIDTH_160,
394 false, &eht_chandef);
396 if (!cfg80211_chandef_valid(&eht_chandef)) {
397 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
399 "AP EHT information is invalid, disabling EHT\n");
400 ret = IEEE80211_CONN_DISABLE_EHT;
404 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
405 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
407 "AP EHT information is incompatible, disabling EHT\n");
408 ret = IEEE80211_CONN_DISABLE_EHT;
412 *chandef = eht_chandef;
419 * When tracking the current AP, don't do any further checks if the
420 * new chandef is identical to the one we're currently using for the
421 * connection. This keeps us from playing ping-pong with regulatory,
422 * without it the following can happen (for example):
423 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
424 * - AP advertises regdom US
425 * - CRDA loads regdom US with 80 MHz prohibited (old database)
426 * - the code below detects an unsupported channel, downgrades, and
427 * we disconnect from the AP in the caller
428 * - disconnect causes CRDA to reload world regdomain and the game
430 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
432 * It seems possible that there are still scenarios with CSA or real
433 * bandwidth changes where a this could happen, but those cases are
434 * less common and wouldn't completely prevent using the AP.
437 cfg80211_chandef_identical(chandef, &link->conf->chandef))
440 /* don't print the message below for VHT mismatch if VHT is disabled */
441 if (ret & IEEE80211_CONN_DISABLE_VHT)
442 vht_chandef = *chandef;
445 * Ignore the DISABLED flag when we're already connected and only
446 * tracking the APs beacon for bandwidth changes - otherwise we
447 * might get disconnected here if we connect to an AP, update our
448 * regulatory information based on the AP's country IE and the
449 * information we have is wrong/outdated and disables the channel
450 * that we're actually using for the connection to the AP.
452 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
454 IEEE80211_CHAN_DISABLED)) {
455 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
456 ret = IEEE80211_CONN_DISABLE_HT |
457 IEEE80211_CONN_DISABLE_VHT |
458 IEEE80211_CONN_DISABLE_HE |
459 IEEE80211_CONN_DISABLE_EHT;
463 ret |= ieee80211_chandef_downgrade(chandef);
466 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
467 IEEE80211_CHAN_NO_HE))
468 ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
470 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
471 IEEE80211_CHAN_NO_EHT))
472 ret |= IEEE80211_CONN_DISABLE_EHT;
474 if (chandef->width != vht_chandef.width && !tracking)
476 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
478 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
482 static int ieee80211_config_bw(struct ieee80211_link_data *link,
483 const struct ieee80211_ht_cap *ht_cap,
484 const struct ieee80211_vht_cap *vht_cap,
485 const struct ieee80211_ht_operation *ht_oper,
486 const struct ieee80211_vht_operation *vht_oper,
487 const struct ieee80211_he_operation *he_oper,
488 const struct ieee80211_eht_operation *eht_oper,
489 const struct ieee80211_s1g_oper_ie *s1g_oper,
490 const u8 *bssid, u64 *changed)
492 struct ieee80211_sub_if_data *sdata = link->sdata;
493 struct ieee80211_local *local = sdata->local;
494 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
495 struct ieee80211_channel *chan = link->conf->chandef.chan;
496 struct ieee80211_supported_band *sband =
497 local->hw.wiphy->bands[chan->band];
498 struct cfg80211_chan_def chandef;
500 ieee80211_conn_flags_t flags;
501 u32 vht_cap_info = 0;
504 /* if HT was/is disabled, don't track any bandwidth changes */
505 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
508 /* don't check VHT if we associated as non-VHT station */
509 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
512 /* don't check HE if we associated as non-HE station */
513 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
514 !ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif)) {
519 /* don't check EHT if we associated as non-EHT station */
520 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
521 !ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif))
525 * if bss configuration changed store the new one -
526 * this may be applicable even if channel is identical
528 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
529 if (link->conf->ht_operation_mode != ht_opmode) {
530 *changed |= BSS_CHANGED_HT;
531 link->conf->ht_operation_mode = ht_opmode;
535 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
537 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
538 flags = ieee80211_determine_chantype(sdata, link,
539 link->u.mgd.conn_flags,
540 sband, chan, vht_cap_info,
543 s1g_oper, &chandef, true);
546 * Downgrade the new channel if we associated with restricted
547 * capabilities. For example, if we associated as a 20 MHz STA
548 * to a 40 MHz AP (due to regulatory, capabilities or config
549 * reasons) then switching to a 40 MHz channel now won't do us
550 * any good -- we couldn't use it with the AP.
552 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
553 chandef.width == NL80211_CHAN_WIDTH_80P80)
554 flags |= ieee80211_chandef_downgrade(&chandef);
555 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
556 chandef.width == NL80211_CHAN_WIDTH_160)
557 flags |= ieee80211_chandef_downgrade(&chandef);
558 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
559 chandef.width > NL80211_CHAN_WIDTH_20)
560 flags |= ieee80211_chandef_downgrade(&chandef);
562 if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
566 "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
567 link->u.mgd.bssid, chandef.chan->center_freq,
568 chandef.chan->freq_offset, chandef.width,
569 chandef.center_freq1, chandef.freq1_offset,
570 chandef.center_freq2);
572 if (flags != (link->u.mgd.conn_flags &
573 (IEEE80211_CONN_DISABLE_HT |
574 IEEE80211_CONN_DISABLE_VHT |
575 IEEE80211_CONN_DISABLE_HE |
576 IEEE80211_CONN_DISABLE_EHT |
577 IEEE80211_CONN_DISABLE_40MHZ |
578 IEEE80211_CONN_DISABLE_80P80MHZ |
579 IEEE80211_CONN_DISABLE_160MHZ |
580 IEEE80211_CONN_DISABLE_320MHZ)) ||
581 !cfg80211_chandef_valid(&chandef)) {
583 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
584 link->u.mgd.bssid, flags, ifmgd->flags);
588 ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
592 "AP %pM changed bandwidth to incompatible one - disconnect\n",
600 /* frame sending functions */
602 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
603 struct sk_buff *skb, u8 ap_ht_param,
604 struct ieee80211_supported_band *sband,
605 struct ieee80211_channel *channel,
606 enum ieee80211_smps_mode smps,
607 ieee80211_conn_flags_t conn_flags)
610 u32 flags = channel->flags;
612 struct ieee80211_sta_ht_cap ht_cap;
614 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
616 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
617 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
619 /* determine capability flags */
622 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
623 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
624 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
625 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
626 cap &= ~IEEE80211_HT_CAP_SGI_40;
629 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
630 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
631 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
632 cap &= ~IEEE80211_HT_CAP_SGI_40;
638 * If 40 MHz was disabled associate as though we weren't
639 * capable of 40 MHz -- some broken APs will never fall
640 * back to trying to transmit in 20 MHz.
642 if (conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
643 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
644 cap &= ~IEEE80211_HT_CAP_SGI_40;
647 /* set SM PS mode properly */
648 cap &= ~IEEE80211_HT_CAP_SM_PS;
650 case IEEE80211_SMPS_AUTOMATIC:
651 case IEEE80211_SMPS_NUM_MODES:
654 case IEEE80211_SMPS_OFF:
655 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
656 IEEE80211_HT_CAP_SM_PS_SHIFT;
658 case IEEE80211_SMPS_STATIC:
659 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
660 IEEE80211_HT_CAP_SM_PS_SHIFT;
662 case IEEE80211_SMPS_DYNAMIC:
663 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
664 IEEE80211_HT_CAP_SM_PS_SHIFT;
668 /* reserve and fill IE */
669 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
670 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
673 /* This function determines vht capability flags for the association
675 * Note - the function returns true to own the MU-MIMO capability
677 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
679 struct ieee80211_supported_band *sband,
680 struct ieee80211_vht_cap *ap_vht_cap,
681 ieee80211_conn_flags_t conn_flags)
683 struct ieee80211_local *local = sdata->local;
686 struct ieee80211_sta_vht_cap vht_cap;
687 u32 mask, ap_bf_sts, our_bf_sts;
688 bool mu_mimo_owner = false;
690 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
692 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
693 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
695 /* determine capability flags */
698 if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
699 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
701 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
702 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
703 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
704 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
707 if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
708 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
709 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
713 * Some APs apparently get confused if our capabilities are better
714 * than theirs, so restrict what we advertise in the assoc request.
716 if (!(ap_vht_cap->vht_cap_info &
717 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
718 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
719 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
720 else if (!(ap_vht_cap->vht_cap_info &
721 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
722 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
725 * If some other vif is using the MU-MIMO capability we cannot associate
726 * using MU-MIMO - this will lead to contradictions in the group-id
728 * Ownership is defined since association request, in order to avoid
729 * simultaneous associations with MU-MIMO.
731 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
732 bool disable_mu_mimo = false;
733 struct ieee80211_sub_if_data *other;
735 list_for_each_entry_rcu(other, &local->interfaces, list) {
736 if (other->vif.bss_conf.mu_mimo_owner) {
737 disable_mu_mimo = true;
742 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
744 mu_mimo_owner = true;
747 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
749 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
750 our_bf_sts = cap & mask;
752 if (ap_bf_sts < our_bf_sts) {
757 /* reserve and fill IE */
758 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
759 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
761 return mu_mimo_owner;
764 /* This function determines HE capability flags for the association
767 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
769 struct ieee80211_supported_band *sband,
770 enum ieee80211_smps_mode smps_mode,
771 ieee80211_conn_flags_t conn_flags)
773 u8 *pos, *pre_he_pos;
774 const struct ieee80211_sta_he_cap *he_cap;
777 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
778 if (WARN_ON(!he_cap))
781 /* get a max size estimate */
783 2 + 1 + sizeof(he_cap->he_cap_elem) +
784 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
785 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
786 he_cap->he_cap_elem.phy_cap_info);
787 pos = skb_put(skb, he_cap_size);
789 pos = ieee80211_ie_build_he_cap(conn_flags,
790 pos, he_cap, pos + he_cap_size);
791 /* trim excess if any */
792 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
794 ieee80211_ie_build_he_6ghz_cap(sdata, smps_mode, skb);
797 static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
799 struct ieee80211_supported_band *sband)
802 const struct ieee80211_sta_he_cap *he_cap;
803 const struct ieee80211_sta_eht_cap *eht_cap;
806 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
807 eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
810 * EHT capabilities element is only added if the HE capabilities element
811 * was added so assume that 'he_cap' is valid and don't check it.
813 if (WARN_ON(!he_cap || !eht_cap))
817 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
818 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
819 &eht_cap->eht_cap_elem,
821 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
822 eht_cap->eht_cap_elem.phy_cap_info);
823 pos = skb_put(skb, eht_cap_size);
824 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size,
828 static void ieee80211_assoc_add_rates(struct sk_buff *skb,
829 enum nl80211_chan_width width,
830 struct ieee80211_supported_band *sband,
831 struct ieee80211_mgd_assoc_data *assoc_data)
833 unsigned int shift = ieee80211_chanwidth_get_shift(width);
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,
880 if (rates_len > count) {
881 pos = skb_put(skb, rates_len - count + 2);
882 *pos++ = WLAN_EID_EXT_SUPP_RATES;
883 *pos++ = rates_len - count;
885 for (i++; i < sband->n_bitrates; i++) {
886 if (BIT(i) & rates) {
889 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
897 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
904 static const u8 before_ht[] = {
907 WLAN_EID_EXT_SUPP_RATES,
908 WLAN_EID_PWR_CAPABILITY,
909 WLAN_EID_SUPPORTED_CHANNELS,
912 WLAN_EID_RRM_ENABLED_CAPABILITIES,
913 WLAN_EID_MOBILITY_DOMAIN,
914 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
915 WLAN_EID_RIC_DATA, /* reassoc only */
916 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
918 static const u8 after_ric[] = {
919 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
920 WLAN_EID_HT_CAPABILITY,
921 WLAN_EID_BSS_COEX_2040,
922 /* luckily this is almost always there */
923 WLAN_EID_EXT_CAPABILITY,
924 WLAN_EID_QOS_TRAFFIC_CAPA,
925 WLAN_EID_TIM_BCAST_REQ,
926 WLAN_EID_INTERWORKING,
927 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
928 WLAN_EID_VHT_CAPABILITY,
929 WLAN_EID_OPMODE_NOTIF,
935 noffset = ieee80211_ie_split_ric(elems, elems_len,
937 ARRAY_SIZE(before_ht),
939 ARRAY_SIZE(after_ric),
941 skb_put_data(skb, elems + offset, noffset - offset);
946 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
951 static const u8 before_vht[] = {
953 * no need to list the ones split off before HT
956 WLAN_EID_BSS_COEX_2040,
957 WLAN_EID_EXT_CAPABILITY,
958 WLAN_EID_QOS_TRAFFIC_CAPA,
959 WLAN_EID_TIM_BCAST_REQ,
960 WLAN_EID_INTERWORKING,
961 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
968 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
969 noffset = ieee80211_ie_split(elems, elems_len,
970 before_vht, ARRAY_SIZE(before_vht),
972 skb_put_data(skb, elems + offset, noffset - offset);
977 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
982 static const u8 before_he[] = {
984 * no need to list the ones split off before VHT
987 WLAN_EID_OPMODE_NOTIF,
988 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
990 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
991 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
992 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
993 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
994 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
995 /* TODO: add 11ah/11aj/11ak elements */
1002 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
1003 noffset = ieee80211_ie_split(elems, elems_len,
1004 before_he, ARRAY_SIZE(before_he),
1006 skb_put_data(skb, elems + offset, noffset - offset);
1011 #define PRESENT_ELEMS_MAX 8
1012 #define PRESENT_ELEM_EXT_OFFS 0x100
1014 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1015 struct sk_buff *skb, u16 capab,
1016 const struct element *ext_capa,
1017 const u16 *present_elems);
1019 static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata,
1020 struct sk_buff *skb, u16 *capab,
1021 const struct element *ext_capa,
1022 const u8 *extra_elems,
1023 size_t extra_elems_len,
1024 unsigned int link_id,
1025 struct ieee80211_link_data *link,
1028 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1029 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1030 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1031 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1032 struct ieee80211_channel *chan = cbss->channel;
1033 const struct ieee80211_sband_iftype_data *iftd;
1034 struct ieee80211_local *local = sdata->local;
1035 struct ieee80211_supported_band *sband;
1036 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
1037 struct ieee80211_chanctx_conf *chanctx_conf;
1038 enum ieee80211_smps_mode smps_mode;
1039 u16 orig_capab = *capab;
1041 int present_elems_len = 0;
1045 #define ADD_PRESENT_ELEM(id) do { \
1046 /* need a last for termination - we use 0 == SSID */ \
1047 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
1048 present_elems[present_elems_len++] = (id); \
1050 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
1053 smps_mode = link->smps_mode;
1054 else if (sdata->u.mgd.powersave)
1055 smps_mode = IEEE80211_SMPS_DYNAMIC;
1057 smps_mode = IEEE80211_SMPS_OFF;
1061 * 5/10 MHz scenarios are only viable without MLO, in which
1062 * case this pointer should be used ... All of this is a bit
1063 * unclear though, not sure this even works at all.
1066 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
1068 width = chanctx_conf->def.width;
1072 sband = local->hw.wiphy->bands[chan->band];
1073 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1075 if (sband->band == NL80211_BAND_2GHZ) {
1076 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1077 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1080 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
1081 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
1082 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
1084 if (sband->band != NL80211_BAND_S1GHZ)
1085 ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
1087 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
1088 *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
1089 struct cfg80211_chan_def chandef = {
1094 pos = skb_put(skb, 4);
1095 *pos++ = WLAN_EID_PWR_CAPABILITY;
1097 *pos++ = 0; /* min tx power */
1099 *pos++ = ieee80211_chandef_max_power(&chandef);
1100 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
1104 * Per spec, we shouldn't include the list of channels if we advertise
1105 * support for extended channel switching, but we've always done that;
1106 * (for now?) apply this restriction only on the (new) 6 GHz band.
1108 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
1109 (sband->band != NL80211_BAND_6GHZ ||
1110 !ext_capa || ext_capa->datalen < 1 ||
1111 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
1112 /* TODO: get this in reg domain format */
1113 pos = skb_put(skb, 2 * sband->n_channels + 2);
1114 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
1115 *pos++ = 2 * sband->n_channels;
1116 for (i = 0; i < sband->n_channels; i++) {
1117 int cf = sband->channels[i].center_freq;
1119 *pos++ = ieee80211_frequency_to_channel(cf);
1120 *pos++ = 1; /* one channel in the subband*/
1122 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
1125 /* if present, add any custom IEs that go before HT */
1126 offset = ieee80211_add_before_ht_elems(skb, extra_elems,
1130 if (sband->band != NL80211_BAND_6GHZ &&
1131 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT)) {
1132 ieee80211_add_ht_ie(sdata, skb,
1133 assoc_data->link[link_id].ap_ht_param,
1134 sband, chan, smps_mode,
1135 assoc_data->link[link_id].conn_flags);
1136 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
1139 /* if present, add any custom IEs that go before VHT */
1140 offset = ieee80211_add_before_vht_elems(skb, extra_elems,
1144 if (sband->band != NL80211_BAND_6GHZ &&
1145 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
1146 bool mu_mimo_owner =
1147 ieee80211_add_vht_ie(sdata, skb, sband,
1148 &assoc_data->link[link_id].ap_vht_cap,
1149 assoc_data->link[link_id].conn_flags);
1152 link->conf->mu_mimo_owner = mu_mimo_owner;
1153 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
1157 * If AP doesn't support HT, mark HE and EHT as disabled.
1158 * If on the 5GHz band, make sure it supports VHT.
1160 if (assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT ||
1161 (sband->band == NL80211_BAND_5GHZ &&
1162 assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT))
1163 assoc_data->link[link_id].conn_flags |=
1164 IEEE80211_CONN_DISABLE_HE |
1165 IEEE80211_CONN_DISABLE_EHT;
1167 /* if present, add any custom IEs that go before HE */
1168 offset = ieee80211_add_before_he_elems(skb, extra_elems,
1172 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HE)) {
1173 ieee80211_add_he_ie(sdata, skb, sband, smps_mode,
1174 assoc_data->link[link_id].conn_flags);
1175 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
1179 * careful - need to know about all the present elems before
1180 * calling ieee80211_assoc_add_ml_elem(), so add this one if
1181 * we're going to put it after the ML element
1183 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1184 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
1186 if (link_id == assoc_data->assoc_link_id)
1187 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
1190 /* crash if somebody gets it wrong */
1191 present_elems = NULL;
1193 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1194 ieee80211_add_eht_ie(sdata, skb, sband);
1196 if (sband->band == NL80211_BAND_S1GHZ) {
1197 ieee80211_add_aid_request_ie(sdata, skb);
1198 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1201 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1202 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1205 link->u.mgd.conn_flags = assoc_data->link[link_id].conn_flags;
1210 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
1214 unsigned int skb_len = skb->len;
1215 bool at_extension = false;
1218 u8 *len, *list_len = NULL;
1220 skb_put_u8(skb, WLAN_EID_EXTENSION);
1221 len = skb_put(skb, 1);
1222 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
1224 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
1225 u16 elem = outer[i];
1226 bool have_inner = false;
1228 /* should at least be sorted in the sense of normal -> ext */
1229 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
1231 /* switch to extension list */
1232 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
1233 at_extension = true;
1239 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
1240 if (elem == inner[j]) {
1250 list_len = skb_put(skb, 1);
1254 skb_put_u8(skb, (u8)elem);
1258 /* if we added a list but no extension list, make a zero-len one */
1259 if (added && (!at_extension || !list_len))
1262 /* if nothing added remove extension element completely */
1264 skb_trim(skb, skb_len);
1266 *len = skb->len - skb_len - 2;
1269 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1270 struct sk_buff *skb, u16 capab,
1271 const struct element *ext_capa,
1272 const u16 *outer_present_elems)
1274 struct ieee80211_local *local = sdata->local;
1275 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1276 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1277 struct ieee80211_multi_link_elem *ml_elem;
1278 struct ieee80211_mle_basic_common_info *common;
1279 const struct wiphy_iftype_ext_capab *ift_ext_capa;
1280 __le16 eml_capa = 0, mld_capa_ops = 0;
1281 unsigned int link_id;
1285 if (!sdata->vif.valid_links)
1288 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
1289 ieee80211_vif_type_p2p(&sdata->vif));
1291 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
1292 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
1295 skb_put_u8(skb, WLAN_EID_EXTENSION);
1296 ml_elem_len = skb_put(skb, 1);
1297 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
1298 ml_elem = skb_put(skb, sizeof(*ml_elem));
1300 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
1301 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
1302 common = skb_put(skb, sizeof(*common));
1303 common->len = sizeof(*common) +
1304 2; /* MLD capa/ops */
1305 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
1307 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
1309 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
1310 IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
1311 common->len += 2; /* EML capabilities */
1313 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
1314 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
1316 /* need indication from userspace to support this */
1317 mld_capa_ops &= ~cpu_to_le16(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP);
1318 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
1320 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1321 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
1322 const u8 *extra_elems;
1323 size_t extra_elems_len;
1325 u8 *subelem_len = NULL;
1328 if (!assoc_data->link[link_id].bss ||
1329 link_id == assoc_data->assoc_link_id)
1332 extra_elems = assoc_data->link[link_id].elems;
1333 extra_elems_len = assoc_data->link[link_id].elems_len;
1335 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
1336 subelem_len = skb_put(skb, 1);
1338 ctrl = cpu_to_le16(link_id |
1339 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
1340 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
1341 skb_put_data(skb, &ctrl, sizeof(ctrl));
1342 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
1343 skb_put_data(skb, assoc_data->link[link_id].addr,
1346 * Now add the contents of the (re)association request,
1347 * but the "listen interval" and "current AP address"
1348 * (if applicable) are skipped. So we only have
1349 * the capability field (remember the position and fill
1350 * later), followed by the elements added below by
1351 * calling ieee80211_assoc_link_elems().
1353 capab_pos = skb_put(skb, 2);
1355 extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab,
1360 link_present_elems);
1362 skb_put_data(skb, extra_elems + extra_used,
1363 extra_elems_len - extra_used);
1365 put_unaligned_le16(capab, capab_pos);
1367 ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
1368 link_present_elems);
1370 ieee80211_fragment_element(skb, subelem_len);
1373 ieee80211_fragment_element(skb, ml_elem_len);
1376 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
1378 struct ieee80211_local *local = sdata->local;
1379 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1380 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1381 struct ieee80211_link_data *link;
1382 struct sk_buff *skb;
1383 struct ieee80211_mgmt *mgmt;
1384 u8 *pos, qos_info, *ie_start;
1385 size_t offset, noffset;
1386 u16 capab = WLAN_CAPABILITY_ESS, link_capab;
1388 struct element *ext_capa = NULL;
1389 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1390 struct ieee80211_prep_tx_info info = {};
1391 unsigned int link_id, n_links = 0;
1392 u16 present_elems[PRESENT_ELEMS_MAX] = {};
1397 /* we know it's writable, cast away the const */
1398 if (assoc_data->ie_len)
1399 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
1401 assoc_data->ie_len);
1403 sdata_assert_lock(sdata);
1405 size = local->hw.extra_tx_headroom +
1406 sizeof(*mgmt) + /* bit too much but doesn't matter */
1407 2 + assoc_data->ssid_len + /* SSID */
1408 assoc_data->ie_len + /* extra IEs */
1409 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
1412 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1413 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1414 const struct ieee80211_sband_iftype_data *iftd;
1415 struct ieee80211_supported_band *sband;
1420 sband = local->hw.wiphy->bands[cbss->channel->band];
1423 /* add STA profile elements length */
1424 size += assoc_data->link[link_id].elems_len;
1425 /* and supported rates length */
1426 size += 4 + sband->n_bitrates;
1427 /* supported channels */
1428 size += 2 + 2 * sband->n_channels;
1430 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1432 size += iftd->vendor_elems.len;
1434 /* power capability */
1437 /* HT, VHT, HE, EHT */
1438 size += 2 + sizeof(struct ieee80211_ht_cap);
1439 size += 2 + sizeof(struct ieee80211_vht_cap);
1440 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
1441 sizeof(struct ieee80211_he_mcs_nss_supp) +
1442 IEEE80211_HE_PPE_THRES_MAX_LEN;
1444 if (sband->band == NL80211_BAND_6GHZ)
1445 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
1447 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
1448 sizeof(struct ieee80211_eht_mcs_nss_supp) +
1449 IEEE80211_EHT_PPE_THRES_MAX_LEN;
1451 /* non-inheritance element */
1452 size += 2 + 2 + PRESENT_ELEMS_MAX;
1454 /* should be the same across all BSSes */
1455 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
1456 capab |= WLAN_CAPABILITY_PRIVACY;
1459 if (sdata->vif.valid_links) {
1460 /* consider the multi-link element with STA profile */
1461 size += sizeof(struct ieee80211_multi_link_elem);
1462 /* max common info field in basic multi-link element */
1463 size += sizeof(struct ieee80211_mle_basic_common_info) +
1468 * The capability elements were already considered above;
1469 * note this over-estimates a bit because there's no
1470 * STA profile for the assoc link.
1472 size += (n_links - 1) *
1473 (1 + 1 + /* subelement ID/length */
1474 2 + /* STA control */
1475 1 + ETH_ALEN + 2 /* STA Info field */);
1478 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
1482 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
1485 skb = alloc_skb(size, GFP_KERNEL);
1489 skb_reserve(skb, local->hw.extra_tx_headroom);
1491 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
1492 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
1494 /* Set MBSSID support for HE AP if needed */
1495 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
1496 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
1497 ext_capa && ext_capa->datalen >= 3)
1498 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1500 mgmt = skb_put_zero(skb, 24);
1501 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
1502 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1503 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
1505 listen_int = cpu_to_le16(assoc_data->s1g ?
1506 ieee80211_encode_usf(local->hw.conf.listen_interval) :
1507 local->hw.conf.listen_interval);
1508 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
1510 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1511 IEEE80211_STYPE_REASSOC_REQ);
1512 capab_pos = &mgmt->u.reassoc_req.capab_info;
1513 mgmt->u.reassoc_req.listen_interval = listen_int;
1514 memcpy(mgmt->u.reassoc_req.current_ap,
1515 assoc_data->prev_ap_addr, ETH_ALEN);
1516 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
1519 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1520 IEEE80211_STYPE_ASSOC_REQ);
1521 capab_pos = &mgmt->u.assoc_req.capab_info;
1522 mgmt->u.assoc_req.listen_interval = listen_int;
1523 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
1527 pos = skb_put(skb, 2 + assoc_data->ssid_len);
1529 *pos++ = WLAN_EID_SSID;
1530 *pos++ = assoc_data->ssid_len;
1531 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
1533 /* add the elements for the assoc (main) link */
1535 offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab,
1539 assoc_data->assoc_link_id, link,
1541 put_unaligned_le16(link_capab, capab_pos);
1543 /* if present, add any custom non-vendor IEs */
1544 if (assoc_data->ie_len) {
1545 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1548 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1552 if (assoc_data->wmm) {
1553 if (assoc_data->uapsd) {
1554 qos_info = ifmgd->uapsd_queues;
1555 qos_info |= (ifmgd->uapsd_max_sp_len <<
1556 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1561 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1564 /* add any remaining custom (i.e. vendor specific here) IEs */
1565 if (assoc_data->ie_len) {
1566 noffset = assoc_data->ie_len;
1567 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1570 if (assoc_data->fils_kek_len) {
1571 ret = fils_encrypt_assoc_req(skb, assoc_data);
1578 pos = skb_tail_pointer(skb);
1579 kfree(ifmgd->assoc_req_ies);
1580 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1581 if (!ifmgd->assoc_req_ies) {
1586 ifmgd->assoc_req_ies_len = pos - ie_start;
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))
1692 mutex_lock(&local->mtx);
1693 mutex_lock(&local->chanctx_mtx);
1695 if (!ifmgd->associated)
1698 if (!link->conf->csa_active)
1702 * using reservation isn't immediate as it may be deferred until later
1703 * with multi-vif. once reservation is complete it will re-schedule the
1704 * work with no reserved_chanctx so verify chandef to check if it
1705 * completed successfully
1708 if (link->reserved_chanctx) {
1710 * with multi-vif csa driver may call ieee80211_csa_finish()
1711 * many times while waiting for other interfaces to use their
1714 if (link->reserved_ready)
1717 ret = ieee80211_link_use_reserved_context(link);
1720 "failed to use reserved channel context, disconnecting (err=%d)\n",
1722 wiphy_work_queue(sdata->local->hw.wiphy,
1723 &ifmgd->csa_connection_drop_work);
1730 if (!cfg80211_chandef_identical(&link->conf->chandef,
1731 &link->csa_chandef)) {
1733 "failed to finalize channel switch, disconnecting\n");
1734 wiphy_work_queue(sdata->local->hw.wiphy,
1735 &ifmgd->csa_connection_drop_work);
1739 link->u.mgd.csa_waiting_bcn = true;
1741 ieee80211_sta_reset_beacon_monitor(sdata);
1742 ieee80211_sta_reset_conn_monitor(sdata);
1745 mutex_unlock(&local->chanctx_mtx);
1746 mutex_unlock(&local->mtx);
1747 sdata_unlock(sdata);
1750 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
1752 struct ieee80211_sub_if_data *sdata = link->sdata;
1753 struct ieee80211_local *local = sdata->local;
1754 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1757 sdata_assert_lock(sdata);
1759 WARN_ON(!link->conf->csa_active);
1761 if (link->csa_block_tx) {
1762 ieee80211_wake_vif_queues(local, sdata,
1763 IEEE80211_QUEUE_STOP_REASON_CSA);
1764 link->csa_block_tx = false;
1767 link->conf->csa_active = false;
1768 link->u.mgd.csa_waiting_bcn = false;
1770 * If the CSA IE is still present on the beacon after the switch,
1771 * we need to consider it as a new CSA (possibly to self).
1773 link->u.mgd.beacon_crc_valid = false;
1775 ret = drv_post_channel_switch(sdata);
1778 "driver post channel switch failed, disconnecting\n");
1779 wiphy_work_queue(sdata->local->hw.wiphy,
1780 &ifmgd->csa_connection_drop_work);
1784 cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef, 0, 0);
1787 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1789 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1790 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1792 if (WARN_ON(sdata->vif.valid_links))
1795 trace_api_chswitch_done(sdata, success);
1798 "driver channel switch failed, disconnecting\n");
1799 wiphy_work_queue(sdata->local->hw.wiphy,
1800 &ifmgd->csa_connection_drop_work);
1802 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
1803 &sdata->deflink.u.mgd.chswitch_work,
1807 EXPORT_SYMBOL(ieee80211_chswitch_done);
1810 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
1812 struct ieee80211_sub_if_data *sdata = link->sdata;
1813 struct ieee80211_local *local = sdata->local;
1815 if (!local->ops->abort_channel_switch)
1818 mutex_lock(&local->mtx);
1820 mutex_lock(&local->chanctx_mtx);
1821 ieee80211_link_unreserve_chanctx(link);
1822 mutex_unlock(&local->chanctx_mtx);
1824 if (link->csa_block_tx)
1825 ieee80211_wake_vif_queues(local, sdata,
1826 IEEE80211_QUEUE_STOP_REASON_CSA);
1828 link->csa_block_tx = false;
1829 link->conf->csa_active = false;
1831 mutex_unlock(&local->mtx);
1833 drv_abort_channel_switch(sdata);
1837 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
1838 u64 timestamp, u32 device_timestamp,
1839 struct ieee802_11_elems *elems,
1842 struct ieee80211_sub_if_data *sdata = link->sdata;
1843 struct ieee80211_local *local = sdata->local;
1844 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1845 struct cfg80211_bss *cbss = link->u.mgd.bss;
1846 struct ieee80211_chanctx_conf *conf;
1847 struct ieee80211_chanctx *chanctx;
1848 enum nl80211_band current_band;
1849 struct ieee80211_csa_ie csa_ie;
1850 struct ieee80211_channel_switch ch_switch;
1851 struct ieee80211_bss *bss;
1852 unsigned long timeout;
1855 sdata_assert_lock(sdata);
1860 if (local->scanning)
1863 current_band = cbss->channel->band;
1864 bss = (void *)cbss->priv;
1865 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1867 link->u.mgd.conn_flags,
1868 link->u.mgd.bssid, &csa_ie);
1871 ch_switch.timestamp = timestamp;
1872 ch_switch.device_timestamp = device_timestamp;
1873 ch_switch.block_tx = csa_ie.mode;
1874 ch_switch.chandef = csa_ie.chandef;
1875 ch_switch.count = csa_ie.count;
1876 ch_switch.delay = csa_ie.max_switch_time;
1880 goto lock_and_drop_connection;
1882 if (beacon && link->conf->csa_active &&
1883 !link->u.mgd.csa_waiting_bcn) {
1885 ieee80211_sta_abort_chanswitch(link);
1887 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1889 } else if (link->conf->csa_active || res) {
1890 /* disregard subsequent announcements if already processing */
1894 if (link->conf->chandef.chan->band !=
1895 csa_ie.chandef.chan->band) {
1897 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1899 csa_ie.chandef.chan->center_freq,
1900 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1901 csa_ie.chandef.center_freq2);
1902 goto lock_and_drop_connection;
1905 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1906 IEEE80211_CHAN_DISABLED)) {
1908 "AP %pM switches to unsupported channel "
1909 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1912 csa_ie.chandef.chan->center_freq,
1913 csa_ie.chandef.chan->freq_offset,
1914 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1915 csa_ie.chandef.freq1_offset,
1916 csa_ie.chandef.center_freq2);
1917 goto lock_and_drop_connection;
1920 if (cfg80211_chandef_identical(&csa_ie.chandef,
1921 &link->conf->chandef) &&
1922 (!csa_ie.mode || !beacon)) {
1923 if (link->u.mgd.csa_ignored_same_chan)
1926 "AP %pM tries to chanswitch to same channel, ignore\n",
1928 link->u.mgd.csa_ignored_same_chan = true;
1933 * Drop all TDLS peers - either we disconnect or move to a different
1934 * channel from this point on. There's no telling what our peer will do.
1935 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1936 * have an incompatible wider chandef.
1938 ieee80211_teardown_tdls_peers(sdata);
1940 mutex_lock(&local->mtx);
1941 mutex_lock(&local->chanctx_mtx);
1942 conf = rcu_dereference_protected(link->conf->chanctx_conf,
1943 lockdep_is_held(&local->chanctx_mtx));
1946 "no channel context assigned to vif?, disconnecting\n");
1947 goto drop_connection;
1950 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1952 if (local->use_chanctx &&
1953 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1955 "driver doesn't support chan-switch with channel contexts\n");
1956 goto drop_connection;
1959 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1961 "preparing for channel switch failed, disconnecting\n");
1962 goto drop_connection;
1965 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
1966 chanctx->mode, false);
1969 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1971 goto drop_connection;
1973 mutex_unlock(&local->chanctx_mtx);
1975 link->conf->csa_active = true;
1976 link->csa_chandef = csa_ie.chandef;
1977 link->csa_block_tx = csa_ie.mode;
1978 link->u.mgd.csa_ignored_same_chan = false;
1979 link->u.mgd.beacon_crc_valid = false;
1981 if (link->csa_block_tx)
1982 ieee80211_stop_vif_queues(local, sdata,
1983 IEEE80211_QUEUE_STOP_REASON_CSA);
1984 mutex_unlock(&local->mtx);
1986 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, 0,
1987 csa_ie.count, csa_ie.mode, 0);
1989 if (local->ops->channel_switch) {
1990 /* use driver's channel switch callback */
1991 drv_channel_switch(local, sdata, &ch_switch);
1995 /* channel switch handled in software */
1996 timeout = TU_TO_JIFFIES((max_t(int, csa_ie.count, 1) - 1) *
1997 cbss->beacon_interval);
1998 wiphy_delayed_work_queue(local->hw.wiphy,
1999 &link->u.mgd.chswitch_work,
2002 lock_and_drop_connection:
2003 mutex_lock(&local->mtx);
2004 mutex_lock(&local->chanctx_mtx);
2007 * This is just so that the disconnect flow will know that
2008 * we were trying to switch channel and failed. In case the
2009 * mode is 1 (we are not allowed to Tx), we will know not to
2010 * send a deauthentication frame. Those two fields will be
2011 * reset when the disconnection worker runs.
2013 link->conf->csa_active = true;
2014 link->csa_block_tx = csa_ie.mode;
2016 wiphy_work_queue(sdata->local->hw.wiphy,
2017 &ifmgd->csa_connection_drop_work);
2018 mutex_unlock(&local->chanctx_mtx);
2019 mutex_unlock(&local->mtx);
2023 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
2024 struct ieee80211_channel *channel,
2025 const u8 *country_ie, u8 country_ie_len,
2026 const u8 *pwr_constr_elem,
2027 int *chan_pwr, int *pwr_reduction)
2029 struct ieee80211_country_ie_triplet *triplet;
2030 int chan = ieee80211_frequency_to_channel(channel->center_freq);
2031 int i, chan_increment;
2032 bool have_chan_pwr = false;
2035 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
2038 triplet = (void *)(country_ie + 3);
2039 country_ie_len -= 3;
2041 switch (channel->band) {
2045 case NL80211_BAND_2GHZ:
2046 case NL80211_BAND_60GHZ:
2047 case NL80211_BAND_LC:
2050 case NL80211_BAND_5GHZ:
2053 case NL80211_BAND_6GHZ:
2055 * In the 6 GHz band, the "maximum transmit power level"
2056 * field in the triplets is reserved, and thus will be
2057 * zero and we shouldn't use it to control TX power.
2058 * The actual TX power will be given in the transmit
2059 * power envelope element instead.
2065 while (country_ie_len >= 3) {
2066 u8 first_channel = triplet->chans.first_channel;
2068 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
2071 for (i = 0; i < triplet->chans.num_channels; i++) {
2072 if (first_channel + i * chan_increment == chan) {
2073 have_chan_pwr = true;
2074 *chan_pwr = triplet->chans.max_power;
2083 country_ie_len -= 3;
2086 if (have_chan_pwr && pwr_constr_elem)
2087 *pwr_reduction = *pwr_constr_elem;
2091 return have_chan_pwr;
2094 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
2095 struct ieee80211_channel *channel,
2096 const u8 *cisco_dtpc_ie,
2099 /* From practical testing, the first data byte of the DTPC element
2100 * seems to contain the requested dBm level, and the CLI on Cisco
2101 * APs clearly state the range is -127 to 127 dBm, which indicates
2102 * a signed byte, although it seemingly never actually goes negative.
2103 * The other byte seems to always be zero.
2105 *pwr_level = (__s8)cisco_dtpc_ie[4];
2108 static u64 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
2109 struct ieee80211_channel *channel,
2110 struct ieee80211_mgmt *mgmt,
2111 const u8 *country_ie, u8 country_ie_len,
2112 const u8 *pwr_constr_ie,
2113 const u8 *cisco_dtpc_ie)
2115 struct ieee80211_sub_if_data *sdata = link->sdata;
2116 bool has_80211h_pwr = false, has_cisco_pwr = false;
2117 int chan_pwr = 0, pwr_reduction_80211h = 0;
2118 int pwr_level_cisco, pwr_level_80211h;
2120 __le16 capab = mgmt->u.probe_resp.capab_info;
2122 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
2123 return 0; /* TODO */
2126 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
2127 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
2128 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
2129 sdata, channel, country_ie, country_ie_len,
2130 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
2132 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
2135 if (cisco_dtpc_ie) {
2136 ieee80211_find_cisco_dtpc(
2137 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
2138 has_cisco_pwr = true;
2141 if (!has_80211h_pwr && !has_cisco_pwr)
2144 /* If we have both 802.11h and Cisco DTPC, apply both limits
2145 * by picking the smallest of the two power levels advertised.
2147 if (has_80211h_pwr &&
2148 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
2149 new_ap_level = pwr_level_80211h;
2151 if (link->ap_power_level == new_ap_level)
2155 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
2156 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
2158 } else { /* has_cisco_pwr is always true here. */
2159 new_ap_level = pwr_level_cisco;
2161 if (link->ap_power_level == new_ap_level)
2165 "Limiting TX power to %d dBm as advertised by %pM\n",
2166 pwr_level_cisco, link->u.mgd.bssid);
2169 link->ap_power_level = new_ap_level;
2170 if (__ieee80211_recalc_txpower(sdata))
2171 return BSS_CHANGED_TXPOWER;
2176 static void ieee80211_enable_ps(struct ieee80211_local *local,
2177 struct ieee80211_sub_if_data *sdata)
2179 struct ieee80211_conf *conf = &local->hw.conf;
2182 * If we are scanning right now then the parameters will
2183 * take effect when scan finishes.
2185 if (local->scanning)
2188 if (conf->dynamic_ps_timeout > 0 &&
2189 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2190 mod_timer(&local->dynamic_ps_timer, jiffies +
2191 msecs_to_jiffies(conf->dynamic_ps_timeout));
2193 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
2194 ieee80211_send_nullfunc(local, sdata, true);
2196 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2197 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2200 conf->flags |= IEEE80211_CONF_PS;
2201 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2205 static void ieee80211_change_ps(struct ieee80211_local *local)
2207 struct ieee80211_conf *conf = &local->hw.conf;
2209 if (local->ps_sdata) {
2210 ieee80211_enable_ps(local, local->ps_sdata);
2211 } else if (conf->flags & IEEE80211_CONF_PS) {
2212 conf->flags &= ~IEEE80211_CONF_PS;
2213 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2214 del_timer_sync(&local->dynamic_ps_timer);
2215 cancel_work_sync(&local->dynamic_ps_enable_work);
2219 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
2221 struct ieee80211_local *local = sdata->local;
2222 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
2223 struct sta_info *sta = NULL;
2224 bool authorized = false;
2226 if (!mgd->powersave)
2232 if (!mgd->associated)
2235 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
2238 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
2239 !sdata->deflink.u.mgd.have_beacon)
2243 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2245 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2251 /* need to hold RTNL or interface lock */
2252 void ieee80211_recalc_ps(struct ieee80211_local *local)
2254 struct ieee80211_sub_if_data *sdata, *found = NULL;
2258 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
2259 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2260 local->ps_sdata = NULL;
2264 list_for_each_entry(sdata, &local->interfaces, list) {
2265 if (!ieee80211_sdata_running(sdata))
2267 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2268 /* If an AP vif is found, then disable PS
2269 * by setting the count to zero thereby setting
2275 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2281 if (count == 1 && ieee80211_powersave_allowed(found)) {
2282 u8 dtimper = found->deflink.u.mgd.dtim_period;
2284 timeout = local->dynamic_ps_forced_timeout;
2287 local->hw.conf.dynamic_ps_timeout = timeout;
2289 /* If the TIM IE is invalid, pretend the value is 1 */
2293 local->hw.conf.ps_dtim_period = dtimper;
2294 local->ps_sdata = found;
2296 local->ps_sdata = NULL;
2299 ieee80211_change_ps(local);
2302 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
2304 bool ps_allowed = ieee80211_powersave_allowed(sdata);
2306 if (sdata->vif.cfg.ps != ps_allowed) {
2307 sdata->vif.cfg.ps = ps_allowed;
2308 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
2312 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
2314 struct ieee80211_local *local =
2315 container_of(work, struct ieee80211_local,
2316 dynamic_ps_disable_work);
2318 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2319 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2320 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2323 ieee80211_wake_queues_by_reason(&local->hw,
2324 IEEE80211_MAX_QUEUE_MAP,
2325 IEEE80211_QUEUE_STOP_REASON_PS,
2329 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2331 struct ieee80211_local *local =
2332 container_of(work, struct ieee80211_local,
2333 dynamic_ps_enable_work);
2334 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
2335 struct ieee80211_if_managed *ifmgd;
2336 unsigned long flags;
2339 /* can only happen when PS was just disabled anyway */
2343 ifmgd = &sdata->u.mgd;
2345 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2348 if (local->hw.conf.dynamic_ps_timeout > 0) {
2349 /* don't enter PS if TX frames are pending */
2350 if (drv_tx_frames_pending(local)) {
2351 mod_timer(&local->dynamic_ps_timer, jiffies +
2353 local->hw.conf.dynamic_ps_timeout));
2358 * transmission can be stopped by others which leads to
2359 * dynamic_ps_timer expiry. Postpone the ps timer if it
2360 * is not the actual idle state.
2362 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
2363 for (q = 0; q < local->hw.queues; q++) {
2364 if (local->queue_stop_reasons[q]) {
2365 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
2367 mod_timer(&local->dynamic_ps_timer, jiffies +
2369 local->hw.conf.dynamic_ps_timeout));
2373 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
2376 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2377 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2378 if (drv_tx_frames_pending(local)) {
2379 mod_timer(&local->dynamic_ps_timer, jiffies +
2381 local->hw.conf.dynamic_ps_timeout));
2383 ieee80211_send_nullfunc(local, sdata, true);
2384 /* Flush to get the tx status of nullfunc frame */
2385 ieee80211_flush_queues(local, sdata, false);
2389 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
2390 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
2391 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2392 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2393 local->hw.conf.flags |= IEEE80211_CONF_PS;
2394 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2398 void ieee80211_dynamic_ps_timer(struct timer_list *t)
2400 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
2402 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
2405 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
2407 struct delayed_work *delayed_work = to_delayed_work(work);
2408 struct ieee80211_link_data *link =
2409 container_of(delayed_work, struct ieee80211_link_data,
2410 dfs_cac_timer_work);
2411 struct cfg80211_chan_def chandef = link->conf->chandef;
2412 struct ieee80211_sub_if_data *sdata = link->sdata;
2414 mutex_lock(&sdata->local->mtx);
2415 if (sdata->wdev.cac_started) {
2416 ieee80211_link_release_channel(link);
2417 cfg80211_cac_event(sdata->dev, &chandef,
2418 NL80211_RADAR_CAC_FINISHED,
2421 mutex_unlock(&sdata->local->mtx);
2425 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2427 struct ieee80211_local *local = sdata->local;
2428 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2432 if (local->hw.queues < IEEE80211_NUM_ACS)
2435 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2436 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2438 unsigned long now = jiffies;
2440 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
2441 tx_tspec->admitted_time &&
2442 time_after(now, tx_tspec->time_slice_start + HZ)) {
2443 tx_tspec->consumed_tx_time = 0;
2444 tx_tspec->time_slice_start = now;
2446 if (tx_tspec->downgraded)
2448 TX_TSPEC_ACTION_STOP_DOWNGRADE;
2451 switch (tx_tspec->action) {
2452 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
2453 /* take the original parameters */
2454 if (drv_conf_tx(local, &sdata->deflink, ac,
2455 &sdata->deflink.tx_conf[ac]))
2456 link_err(&sdata->deflink,
2457 "failed to set TX queue parameters for queue %d\n",
2459 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2460 tx_tspec->downgraded = false;
2463 case TX_TSPEC_ACTION_DOWNGRADE:
2464 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2465 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2469 /* downgrade next lower non-ACM AC */
2470 for (non_acm_ac = ac + 1;
2471 non_acm_ac < IEEE80211_NUM_ACS;
2473 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2475 /* Usually the loop will result in using BK even if it
2476 * requires admission control, but such a configuration
2477 * makes no sense and we have to transmit somehow - the
2478 * AC selection does the same thing.
2479 * If we started out trying to downgrade from BK, then
2480 * the extra condition here might be needed.
2482 if (non_acm_ac >= IEEE80211_NUM_ACS)
2483 non_acm_ac = IEEE80211_AC_BK;
2484 if (drv_conf_tx(local, &sdata->deflink, ac,
2485 &sdata->deflink.tx_conf[non_acm_ac]))
2486 link_err(&sdata->deflink,
2487 "failed to set TX queue parameters for queue %d\n",
2489 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2491 schedule_delayed_work(&ifmgd->tx_tspec_wk,
2492 tx_tspec->time_slice_start + HZ - now + 1);
2494 case TX_TSPEC_ACTION_NONE:
2503 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2505 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2506 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2510 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
2512 struct ieee80211_sub_if_data *sdata;
2514 sdata = container_of(work, struct ieee80211_sub_if_data,
2515 u.mgd.tx_tspec_wk.work);
2516 ieee80211_sta_handle_tspec_ac_params(sdata);
2519 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
2521 struct ieee80211_sub_if_data *sdata = link->sdata;
2522 struct ieee80211_local *local = sdata->local;
2523 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2524 struct ieee80211_tx_queue_params *params = link->tx_conf;
2527 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2529 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2531 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2532 params[ac].txop, params[ac].uapsd,
2533 ifmgd->tx_tspec[ac].downgraded);
2534 if (!ifmgd->tx_tspec[ac].downgraded &&
2535 drv_conf_tx(local, link, ac, ¶ms[ac]))
2537 "failed to set TX queue parameters for AC %d\n",
2544 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2545 struct ieee80211_link_data *link,
2546 const u8 *wmm_param, size_t wmm_param_len,
2547 const struct ieee80211_mu_edca_param_set *mu_edca)
2549 struct ieee80211_sub_if_data *sdata = link->sdata;
2550 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2551 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2553 int count, mu_edca_count, ac;
2555 u8 uapsd_queues = 0;
2557 if (!local->ops->conf_tx)
2560 if (local->hw.queues < IEEE80211_NUM_ACS)
2566 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2569 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2570 uapsd_queues = ifmgd->uapsd_queues;
2572 count = wmm_param[6] & 0x0f;
2573 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2574 * if mu_edca was preset before and now it disappeared tell
2575 * the driver about it.
2577 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2578 if (count == link->u.mgd.wmm_last_param_set &&
2579 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
2581 link->u.mgd.wmm_last_param_set = count;
2582 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
2584 pos = wmm_param + 8;
2585 left = wmm_param_len - 8;
2587 memset(¶ms, 0, sizeof(params));
2590 for (; left >= 4; left -= 4, pos += 4) {
2591 int aci = (pos[0] >> 5) & 0x03;
2592 int acm = (pos[0] >> 4) & 0x01;
2597 ac = IEEE80211_AC_BK;
2599 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2600 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2602 params[ac].mu_edca = !!mu_edca;
2604 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2607 ac = IEEE80211_AC_VI;
2609 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2610 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2612 params[ac].mu_edca = !!mu_edca;
2614 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2617 ac = IEEE80211_AC_VO;
2619 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2620 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2622 params[ac].mu_edca = !!mu_edca;
2624 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2628 ac = IEEE80211_AC_BE;
2630 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2631 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2633 params[ac].mu_edca = !!mu_edca;
2635 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2639 params[ac].aifs = pos[0] & 0x0f;
2641 if (params[ac].aifs < 2) {
2643 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2644 params[ac].aifs, aci);
2645 params[ac].aifs = 2;
2647 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2648 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2649 params[ac].txop = get_unaligned_le16(pos + 2);
2650 params[ac].acm = acm;
2651 params[ac].uapsd = uapsd;
2653 if (params[ac].cw_min == 0 ||
2654 params[ac].cw_min > params[ac].cw_max) {
2656 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2657 params[ac].cw_min, params[ac].cw_max, aci);
2660 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2663 /* WMM specification requires all 4 ACIs. */
2664 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2665 if (params[ac].cw_min == 0) {
2667 "AP has invalid WMM params (missing AC %d), using defaults\n",
2673 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2674 link->tx_conf[ac] = params[ac];
2676 ieee80211_mgd_set_link_qos_params(link);
2678 /* enable WMM or activate new settings */
2679 link->conf->qos = true;
2683 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2685 lockdep_assert_held(&sdata->local->mtx);
2687 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2688 ieee80211_run_deferred_scan(sdata->local);
2691 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2693 mutex_lock(&sdata->local->mtx);
2694 __ieee80211_stop_poll(sdata);
2695 mutex_unlock(&sdata->local->mtx);
2698 static u64 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
2699 u16 capab, bool erp_valid, u8 erp)
2701 struct ieee80211_bss_conf *bss_conf = link->conf;
2702 struct ieee80211_supported_band *sband;
2704 bool use_protection;
2705 bool use_short_preamble;
2706 bool use_short_slot;
2708 sband = ieee80211_get_link_sband(link);
2713 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2714 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2716 use_protection = false;
2717 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2720 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2721 if (sband->band == NL80211_BAND_5GHZ ||
2722 sband->band == NL80211_BAND_6GHZ)
2723 use_short_slot = true;
2725 if (use_protection != bss_conf->use_cts_prot) {
2726 bss_conf->use_cts_prot = use_protection;
2727 changed |= BSS_CHANGED_ERP_CTS_PROT;
2730 if (use_short_preamble != bss_conf->use_short_preamble) {
2731 bss_conf->use_short_preamble = use_short_preamble;
2732 changed |= BSS_CHANGED_ERP_PREAMBLE;
2735 if (use_short_slot != bss_conf->use_short_slot) {
2736 bss_conf->use_short_slot = use_short_slot;
2737 changed |= BSS_CHANGED_ERP_SLOT;
2743 static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link,
2744 struct cfg80211_bss *cbss)
2746 struct ieee80211_sub_if_data *sdata = link->sdata;
2747 struct ieee80211_bss_conf *bss_conf = link->conf;
2748 struct ieee80211_bss *bss = (void *)cbss->priv;
2749 u64 changed = BSS_CHANGED_QOS;
2751 /* not really used in MLO */
2752 sdata->u.mgd.beacon_timeout =
2753 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
2754 bss_conf->beacon_int));
2756 changed |= ieee80211_handle_bss_capability(link,
2757 bss_conf->assoc_capability,
2761 ieee80211_check_rate_mask(link);
2763 link->u.mgd.bss = cbss;
2764 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2766 if (sdata->vif.p2p ||
2767 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2768 const struct cfg80211_bss_ies *ies;
2771 ies = rcu_dereference(cbss->ies);
2775 ret = cfg80211_get_p2p_attr(
2776 ies->data, ies->len,
2777 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2778 (u8 *) &bss_conf->p2p_noa_attr,
2779 sizeof(bss_conf->p2p_noa_attr));
2781 link->u.mgd.p2p_noa_index =
2782 bss_conf->p2p_noa_attr.index;
2783 changed |= BSS_CHANGED_P2P_PS;
2789 if (link->u.mgd.have_beacon) {
2790 bss_conf->beacon_rate = bss->beacon_rate;
2791 changed |= BSS_CHANGED_BEACON_INFO;
2793 bss_conf->beacon_rate = NULL;
2796 /* Tell the driver to monitor connection quality (if supported) */
2797 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2798 bss_conf->cqm_rssi_thold)
2799 changed |= BSS_CHANGED_CQM;
2804 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2805 struct ieee80211_mgd_assoc_data *assoc_data,
2806 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
2808 struct ieee80211_local *local = sdata->local;
2809 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
2810 u64 vif_changed = BSS_CHANGED_ASSOC;
2811 unsigned int link_id;
2813 sdata->u.mgd.associated = true;
2815 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
2816 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2817 struct ieee80211_link_data *link;
2820 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2823 link = sdata_dereference(sdata->link[link_id], sdata);
2827 changed[link_id] |= ieee80211_link_set_associated(link, cbss);
2830 /* just to be sure */
2831 ieee80211_stop_poll(sdata);
2833 ieee80211_led_assoc(local, 1);
2837 /* Enable ARP filtering */
2838 if (vif_cfg->arp_addr_cnt)
2839 vif_changed |= BSS_CHANGED_ARP_FILTER;
2841 if (sdata->vif.valid_links) {
2843 link_id < IEEE80211_MLD_MAX_NUM_LINKS;
2845 struct ieee80211_link_data *link;
2846 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2849 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2852 link = sdata_dereference(sdata->link[link_id], sdata);
2856 ieee80211_link_info_change_notify(sdata, link,
2859 ieee80211_recalc_smps(sdata, link);
2862 ieee80211_vif_cfg_change_notify(sdata, vif_changed);
2864 ieee80211_bss_info_change_notify(sdata,
2865 vif_changed | changed[0]);
2868 mutex_lock(&local->iflist_mtx);
2869 ieee80211_recalc_ps(local);
2870 mutex_unlock(&local->iflist_mtx);
2872 /* leave this here to not change ordering in non-MLO cases */
2873 if (!sdata->vif.valid_links)
2874 ieee80211_recalc_smps(sdata, &sdata->deflink);
2875 ieee80211_recalc_ps_vif(sdata);
2877 netif_carrier_on(sdata->dev);
2880 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2881 u16 stype, u16 reason, bool tx,
2884 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2885 struct ieee80211_local *local = sdata->local;
2886 unsigned int link_id;
2888 struct ieee80211_prep_tx_info info = {
2892 sdata_assert_lock(sdata);
2894 if (WARN_ON_ONCE(tx && !frame_buf))
2897 if (WARN_ON(!ifmgd->associated))
2900 ieee80211_stop_poll(sdata);
2902 ifmgd->associated = false;
2904 /* other links will be destroyed */
2905 sdata->deflink.u.mgd.bss = NULL;
2907 netif_carrier_off(sdata->dev);
2910 * if we want to get out of ps before disassoc (why?) we have
2911 * to do it before sending disassoc, as otherwise the null-packet
2914 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2915 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2916 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2918 local->ps_sdata = NULL;
2920 /* disable per-vif ps */
2921 ieee80211_recalc_ps_vif(sdata);
2923 /* make sure ongoing transmission finishes */
2927 * drop any frame before deauth/disassoc, this can be data or
2928 * management frame. Since we are disconnecting, we should not
2929 * insist sending these frames which can take time and delay
2930 * the disconnection and possible the roaming.
2933 ieee80211_flush_queues(local, sdata, true);
2935 /* deauthenticate/disassociate now */
2936 if (tx || frame_buf) {
2938 * In multi channel scenarios guarantee that the virtual
2939 * interface is granted immediate airtime to transmit the
2940 * deauthentication frame by calling mgd_prepare_tx, if the
2941 * driver requested so.
2943 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2944 !sdata->deflink.u.mgd.have_beacon) {
2945 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2948 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
2949 sdata->vif.cfg.ap_addr, stype,
2950 reason, tx, frame_buf);
2953 /* flush out frame - make sure the deauth was actually sent */
2955 ieee80211_flush_queues(local, sdata, false);
2957 drv_mgd_complete_tx(sdata->local, sdata, &info);
2959 /* clear AP addr only after building the needed mgmt frames */
2960 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2961 eth_zero_addr(sdata->vif.cfg.ap_addr);
2963 sdata->vif.cfg.ssid_len = 0;
2965 /* remove AP and TDLS peers */
2966 sta_info_flush(sdata);
2968 /* finally reset all BSS / config parameters */
2969 if (!sdata->vif.valid_links)
2970 changed |= ieee80211_reset_erp_info(sdata);
2972 ieee80211_led_assoc(local, 0);
2973 changed |= BSS_CHANGED_ASSOC;
2974 sdata->vif.cfg.assoc = false;
2976 sdata->deflink.u.mgd.p2p_noa_index = -1;
2977 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2978 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2980 /* on the next assoc, re-program HT/VHT parameters */
2981 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2982 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2983 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2984 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2987 * reset MU-MIMO ownership and group data in default link,
2988 * if used, other links are destroyed
2990 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2991 sizeof(sdata->vif.bss_conf.mu_group.membership));
2992 memset(sdata->vif.bss_conf.mu_group.position, 0,
2993 sizeof(sdata->vif.bss_conf.mu_group.position));
2994 if (!sdata->vif.valid_links)
2995 changed |= BSS_CHANGED_MU_GROUPS;
2996 sdata->vif.bss_conf.mu_mimo_owner = false;
2998 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
3000 del_timer_sync(&local->dynamic_ps_timer);
3001 cancel_work_sync(&local->dynamic_ps_enable_work);
3003 /* Disable ARP filtering */
3004 if (sdata->vif.cfg.arp_addr_cnt)
3005 changed |= BSS_CHANGED_ARP_FILTER;
3007 sdata->vif.bss_conf.qos = false;
3008 if (!sdata->vif.valid_links) {
3009 changed |= BSS_CHANGED_QOS;
3010 /* The BSSID (not really interesting) and HT changed */
3011 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
3012 ieee80211_bss_info_change_notify(sdata, changed);
3014 ieee80211_vif_cfg_change_notify(sdata, changed);
3017 /* disassociated - set to defaults now */
3018 ieee80211_set_wmm_default(&sdata->deflink, false, false);
3020 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
3021 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
3022 del_timer_sync(&sdata->u.mgd.timer);
3024 sdata->vif.bss_conf.dtim_period = 0;
3025 sdata->vif.bss_conf.beacon_rate = NULL;
3027 sdata->deflink.u.mgd.have_beacon = false;
3028 sdata->deflink.u.mgd.tracking_signal_avg = false;
3029 sdata->deflink.u.mgd.disable_wmm_tracking = false;
3032 sdata->deflink.u.mgd.conn_flags = 0;
3033 mutex_lock(&local->mtx);
3035 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3036 struct ieee80211_link_data *link;
3038 link = sdata_dereference(sdata->link[link_id], sdata);
3041 ieee80211_link_release_channel(link);
3044 sdata->vif.bss_conf.csa_active = false;
3045 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3046 sdata->deflink.u.mgd.csa_ignored_same_chan = false;
3047 if (sdata->deflink.csa_block_tx) {
3048 ieee80211_wake_vif_queues(local, sdata,
3049 IEEE80211_QUEUE_STOP_REASON_CSA);
3050 sdata->deflink.csa_block_tx = false;
3052 mutex_unlock(&local->mtx);
3054 /* existing TX TSPEC sessions no longer exist */
3055 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
3056 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
3058 sdata->vif.bss_conf.pwr_reduction = 0;
3059 sdata->vif.bss_conf.tx_pwr_env_num = 0;
3060 memset(sdata->vif.bss_conf.tx_pwr_env, 0,
3061 sizeof(sdata->vif.bss_conf.tx_pwr_env));
3063 ieee80211_vif_set_links(sdata, 0);
3066 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
3068 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3069 struct ieee80211_local *local = sdata->local;
3071 mutex_lock(&local->mtx);
3072 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
3075 __ieee80211_stop_poll(sdata);
3077 mutex_lock(&local->iflist_mtx);
3078 ieee80211_recalc_ps(local);
3079 mutex_unlock(&local->iflist_mtx);
3081 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3085 * We've received a probe response, but are not sure whether
3086 * we have or will be receiving any beacons or data, so let's
3087 * schedule the timers again, just in case.
3089 ieee80211_sta_reset_beacon_monitor(sdata);
3091 mod_timer(&ifmgd->conn_mon_timer,
3092 round_jiffies_up(jiffies +
3093 IEEE80211_CONNECTION_IDLE_TIME));
3095 mutex_unlock(&local->mtx);
3098 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
3099 struct ieee80211_hdr *hdr,
3102 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3105 struct ieee80211_sta_tx_tspec *tx_tspec;
3106 unsigned long now = jiffies;
3108 if (!ieee80211_is_data_qos(hdr->frame_control))
3111 tid = ieee80211_get_tid(hdr);
3112 ac = ieee80211_ac_from_tid(tid);
3113 tx_tspec = &ifmgd->tx_tspec[ac];
3115 if (likely(!tx_tspec->admitted_time))
3118 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3119 tx_tspec->consumed_tx_time = 0;
3120 tx_tspec->time_slice_start = now;
3122 if (tx_tspec->downgraded) {
3123 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3124 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3128 if (tx_tspec->downgraded)
3131 tx_tspec->consumed_tx_time += tx_time;
3133 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
3134 tx_tspec->downgraded = true;
3135 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
3136 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3140 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
3141 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
3143 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
3145 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
3146 !sdata->u.mgd.probe_send_count)
3150 sdata->u.mgd.probe_send_count = 0;
3152 sdata->u.mgd.nullfunc_failed = true;
3153 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
3156 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
3157 const u8 *src, const u8 *dst,
3158 const u8 *ssid, size_t ssid_len,
3159 struct ieee80211_channel *channel)
3161 struct sk_buff *skb;
3163 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
3164 ssid, ssid_len, NULL, 0,
3165 IEEE80211_PROBE_FLAG_DIRECTED);
3167 ieee80211_tx_skb(sdata, skb);
3170 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
3172 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3173 u8 *dst = sdata->vif.cfg.ap_addr;
3174 u8 unicast_limit = max(1, max_probe_tries - 3);
3175 struct sta_info *sta;
3177 if (WARN_ON(sdata->vif.valid_links))
3181 * Try sending broadcast probe requests for the last three
3182 * probe requests after the first ones failed since some
3183 * buggy APs only support broadcast probe requests.
3185 if (ifmgd->probe_send_count >= unicast_limit)
3189 * When the hardware reports an accurate Tx ACK status, it's
3190 * better to send a nullfunc frame instead of a probe request,
3191 * as it will kick us off the AP quickly if we aren't associated
3192 * anymore. The timeout will be reset if the frame is ACKed by
3195 ifmgd->probe_send_count++;
3198 mutex_lock(&sdata->local->sta_mtx);
3199 sta = sta_info_get(sdata, dst);
3201 ieee80211_check_fast_rx(sta);
3202 mutex_unlock(&sdata->local->sta_mtx);
3205 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
3206 ifmgd->nullfunc_failed = false;
3207 ieee80211_send_nullfunc(sdata->local, sdata, false);
3209 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
3210 sdata->vif.cfg.ssid,
3211 sdata->vif.cfg.ssid_len,
3212 sdata->deflink.u.mgd.bss->channel);
3215 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
3216 run_again(sdata, ifmgd->probe_timeout);
3219 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
3222 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3223 bool already = false;
3225 if (WARN_ON_ONCE(sdata->vif.valid_links))
3228 if (!ieee80211_sdata_running(sdata))
3233 if (!ifmgd->associated)
3236 mutex_lock(&sdata->local->mtx);
3238 if (sdata->local->tmp_channel || sdata->local->scanning) {
3239 mutex_unlock(&sdata->local->mtx);
3243 if (sdata->local->suspending) {
3244 /* reschedule after resume */
3245 mutex_unlock(&sdata->local->mtx);
3246 ieee80211_reset_ap_probe(sdata);
3251 mlme_dbg_ratelimited(sdata,
3252 "detected beacon loss from AP (missed %d beacons) - probing\n",
3255 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
3259 * The driver/our work has already reported this event or the
3260 * connection monitoring has kicked in and we have already sent
3261 * a probe request. Or maybe the AP died and the driver keeps
3262 * reporting until we disassociate...
3264 * In either case we have to ignore the current call to this
3265 * function (except for setting the correct probe reason bit)
3266 * because otherwise we would reset the timer every time and
3267 * never check whether we received a probe response!
3269 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
3272 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
3274 mutex_unlock(&sdata->local->mtx);
3279 mutex_lock(&sdata->local->iflist_mtx);
3280 ieee80211_recalc_ps(sdata->local);
3281 mutex_unlock(&sdata->local->iflist_mtx);
3283 ifmgd->probe_send_count = 0;
3284 ieee80211_mgd_probe_ap_send(sdata);
3286 sdata_unlock(sdata);
3289 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
3290 struct ieee80211_vif *vif)
3292 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3293 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3294 struct cfg80211_bss *cbss;
3295 struct sk_buff *skb;
3296 const struct element *ssid;
3299 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
3300 sdata->vif.valid_links))
3303 sdata_assert_lock(sdata);
3305 if (ifmgd->associated)
3306 cbss = sdata->deflink.u.mgd.bss;
3307 else if (ifmgd->auth_data)
3308 cbss = ifmgd->auth_data->bss;
3309 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
3310 cbss = ifmgd->assoc_data->link[0].bss;
3315 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
3316 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
3317 "invalid SSID element (len=%d)",
3318 ssid ? ssid->datalen : -1))
3321 ssid_len = ssid->datalen;
3323 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
3324 (u32) -1, cbss->channel,
3325 ssid->data, ssid_len,
3326 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
3331 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
3333 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
3334 const u8 *buf, size_t len, bool tx,
3335 u16 reason, bool reconnect)
3337 struct ieee80211_event event = {
3339 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
3340 .u.mlme.reason = reason,
3344 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
3346 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
3348 drv_event_callback(sdata->local, sdata, &event);
3351 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
3353 struct ieee80211_local *local = sdata->local;
3354 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3355 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3359 if (!ifmgd->associated) {
3360 sdata_unlock(sdata);
3364 /* in MLO assume we have a link where we can TX the frame */
3365 tx = sdata->vif.valid_links || !sdata->deflink.csa_block_tx;
3367 if (!ifmgd->driver_disconnect) {
3368 unsigned int link_id;
3371 * AP is probably out of range (or not reachable for another
3372 * reason) so remove the bss structs for that AP. In the case
3373 * of multi-link, it's not clear that all of them really are
3374 * out of range, but if they weren't the driver likely would
3375 * have switched to just have a single link active?
3378 link_id < ARRAY_SIZE(sdata->link);
3380 struct ieee80211_link_data *link;
3382 link = sdata_dereference(sdata->link[link_id], sdata);
3385 cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
3386 link->u.mgd.bss = NULL;
3390 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3391 ifmgd->driver_disconnect ?
3392 WLAN_REASON_DEAUTH_LEAVING :
3393 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3395 mutex_lock(&local->mtx);
3396 /* the other links will be destroyed */
3397 sdata->vif.bss_conf.csa_active = false;
3398 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3399 if (sdata->deflink.csa_block_tx) {
3400 ieee80211_wake_vif_queues(local, sdata,
3401 IEEE80211_QUEUE_STOP_REASON_CSA);
3402 sdata->deflink.csa_block_tx = false;
3404 mutex_unlock(&local->mtx);
3406 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
3407 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3409 ifmgd->reconnect = false;
3411 sdata_unlock(sdata);
3414 static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy,
3415 struct wiphy_work *work)
3417 struct ieee80211_sub_if_data *sdata =
3418 container_of(work, struct ieee80211_sub_if_data,
3419 u.mgd.beacon_connection_loss_work);
3420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3422 if (ifmgd->connection_loss) {
3423 sdata_info(sdata, "Connection to AP %pM lost\n",
3424 sdata->vif.cfg.ap_addr);
3425 __ieee80211_disconnect(sdata);
3426 ifmgd->connection_loss = false;
3427 } else if (ifmgd->driver_disconnect) {
3429 "Driver requested disconnection from AP %pM\n",
3430 sdata->vif.cfg.ap_addr);
3431 __ieee80211_disconnect(sdata);
3432 ifmgd->driver_disconnect = false;
3434 if (ifmgd->associated)
3435 sdata->deflink.u.mgd.beacon_loss_count++;
3436 ieee80211_mgd_probe_ap(sdata, true);
3440 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy,
3441 struct wiphy_work *work)
3443 struct ieee80211_sub_if_data *sdata =
3444 container_of(work, struct ieee80211_sub_if_data,
3445 u.mgd.csa_connection_drop_work);
3447 __ieee80211_disconnect(sdata);
3450 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
3452 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3453 struct ieee80211_hw *hw = &sdata->local->hw;
3455 trace_api_beacon_loss(sdata);
3457 sdata->u.mgd.connection_loss = false;
3458 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3460 EXPORT_SYMBOL(ieee80211_beacon_loss);
3462 void ieee80211_connection_loss(struct ieee80211_vif *vif)
3464 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3465 struct ieee80211_hw *hw = &sdata->local->hw;
3467 trace_api_connection_loss(sdata);
3469 sdata->u.mgd.connection_loss = true;
3470 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3472 EXPORT_SYMBOL(ieee80211_connection_loss);
3474 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
3476 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3477 struct ieee80211_hw *hw = &sdata->local->hw;
3479 trace_api_disconnect(sdata, reconnect);
3481 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
3484 sdata->u.mgd.driver_disconnect = true;
3485 sdata->u.mgd.reconnect = reconnect;
3486 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3488 EXPORT_SYMBOL(ieee80211_disconnect);
3490 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
3493 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3495 sdata_assert_lock(sdata);
3499 * we are not authenticated yet, the only timer that could be
3500 * running is the timeout for the authentication response which
3501 * which is not relevant anymore.
3503 del_timer_sync(&sdata->u.mgd.timer);
3504 sta_info_destroy_addr(sdata, auth_data->ap_addr);
3506 /* other links are destroyed */
3507 sdata->deflink.u.mgd.conn_flags = 0;
3508 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3509 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3511 sdata->u.mgd.flags = 0;
3513 mutex_lock(&sdata->local->mtx);
3514 ieee80211_link_release_channel(&sdata->deflink);
3515 ieee80211_vif_set_links(sdata, 0);
3516 mutex_unlock(&sdata->local->mtx);
3519 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
3521 sdata->u.mgd.auth_data = NULL;
3531 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3532 enum assoc_status status)
3534 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3536 sdata_assert_lock(sdata);
3538 if (status != ASSOC_SUCCESS) {
3540 * we are not associated yet, the only timer that could be
3541 * running is the timeout for the association response which
3542 * which is not relevant anymore.
3544 del_timer_sync(&sdata->u.mgd.timer);
3545 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
3547 sdata->deflink.u.mgd.conn_flags = 0;
3548 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3549 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3551 sdata->u.mgd.flags = 0;
3552 sdata->vif.bss_conf.mu_mimo_owner = false;
3554 if (status != ASSOC_REJECTED) {
3555 struct cfg80211_assoc_failure data = {
3556 .timeout = status == ASSOC_TIMEOUT,
3560 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
3561 ARRAY_SIZE(assoc_data->link));
3563 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
3564 data.bss[i] = assoc_data->link[i].bss;
3566 if (sdata->vif.valid_links)
3567 data.ap_mld_addr = assoc_data->ap_addr;
3569 cfg80211_assoc_failure(sdata->dev, &data);
3572 mutex_lock(&sdata->local->mtx);
3573 ieee80211_link_release_channel(&sdata->deflink);
3574 ieee80211_vif_set_links(sdata, 0);
3575 mutex_unlock(&sdata->local->mtx);
3579 sdata->u.mgd.assoc_data = NULL;
3582 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3583 struct ieee80211_mgmt *mgmt, size_t len)
3585 struct ieee80211_local *local = sdata->local;
3586 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3587 const struct element *challenge;
3590 struct ieee80211_prep_tx_info info = {
3591 .subtype = IEEE80211_STYPE_AUTH,
3594 pos = mgmt->u.auth.variable;
3595 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3596 len - (pos - (u8 *)mgmt));
3599 auth_data->expected_transaction = 4;
3600 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3601 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3602 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3603 IEEE80211_TX_INTFL_MLME_CONN_TX;
3604 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3606 challenge->datalen + sizeof(*challenge),
3607 auth_data->ap_addr, auth_data->ap_addr,
3608 auth_data->key, auth_data->key_len,
3609 auth_data->key_idx, tx_flags);
3612 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
3614 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3615 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
3616 struct sta_info *sta;
3619 sdata_info(sdata, "authenticated\n");
3620 ifmgd->auth_data->done = true;
3621 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3622 ifmgd->auth_data->timeout_started = true;
3623 run_again(sdata, ifmgd->auth_data->timeout);
3625 /* move station state to auth */
3626 mutex_lock(&sdata->local->sta_mtx);
3627 sta = sta_info_get(sdata, ap_addr);
3629 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3633 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3634 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3640 mutex_unlock(&sdata->local->sta_mtx);
3644 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3645 struct ieee80211_mgmt *mgmt, size_t len)
3647 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3648 u16 auth_alg, auth_transaction, status_code;
3649 struct ieee80211_event event = {
3651 .u.mlme.data = AUTH_EVENT,
3653 struct ieee80211_prep_tx_info info = {
3654 .subtype = IEEE80211_STYPE_AUTH,
3657 sdata_assert_lock(sdata);
3662 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3665 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
3668 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3669 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3670 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3672 if (auth_alg != ifmgd->auth_data->algorithm ||
3673 (auth_alg != WLAN_AUTH_SAE &&
3674 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3675 (auth_alg == WLAN_AUTH_SAE &&
3676 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3677 auth_transaction > 2))) {
3678 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3679 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3681 ifmgd->auth_data->expected_transaction);
3685 if (status_code != WLAN_STATUS_SUCCESS) {
3686 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3688 if (auth_alg == WLAN_AUTH_SAE &&
3689 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3690 (auth_transaction == 1 &&
3691 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3692 status_code == WLAN_STATUS_SAE_PK)))) {
3693 /* waiting for userspace now */
3694 ifmgd->auth_data->waiting = true;
3695 ifmgd->auth_data->timeout =
3696 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3697 ifmgd->auth_data->timeout_started = true;
3698 run_again(sdata, ifmgd->auth_data->timeout);
3702 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3703 mgmt->sa, status_code);
3704 ieee80211_destroy_auth_data(sdata, false);
3705 event.u.mlme.status = MLME_DENIED;
3706 event.u.mlme.reason = status_code;
3707 drv_event_callback(sdata->local, sdata, &event);
3711 switch (ifmgd->auth_data->algorithm) {
3712 case WLAN_AUTH_OPEN:
3713 case WLAN_AUTH_LEAP:
3716 case WLAN_AUTH_FILS_SK:
3717 case WLAN_AUTH_FILS_SK_PFS:
3718 case WLAN_AUTH_FILS_PK:
3720 case WLAN_AUTH_SHARED_KEY:
3721 if (ifmgd->auth_data->expected_transaction != 4) {
3722 ieee80211_auth_challenge(sdata, mgmt, len);
3723 /* need another frame */
3728 WARN_ONCE(1, "invalid auth alg %d",
3729 ifmgd->auth_data->algorithm);
3733 event.u.mlme.status = MLME_SUCCESS;
3735 drv_event_callback(sdata->local, sdata, &event);
3736 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3737 (auth_transaction == 2 &&
3738 ifmgd->auth_data->expected_transaction == 2)) {
3739 if (!ieee80211_mark_sta_auth(sdata))
3740 return; /* ignore frame -- wait for timeout */
3741 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3742 auth_transaction == 2) {
3743 sdata_info(sdata, "SAE peer confirmed\n");
3744 ifmgd->auth_data->peer_confirmed = true;
3747 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3749 drv_mgd_complete_tx(sdata->local, sdata, &info);
3752 #define case_WLAN(type) \
3753 case WLAN_REASON_##type: return #type
3755 const char *ieee80211_get_reason_code_string(u16 reason_code)
3757 switch (reason_code) {
3758 case_WLAN(UNSPECIFIED);
3759 case_WLAN(PREV_AUTH_NOT_VALID);
3760 case_WLAN(DEAUTH_LEAVING);
3761 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3762 case_WLAN(DISASSOC_AP_BUSY);
3763 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3764 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3765 case_WLAN(DISASSOC_STA_HAS_LEFT);
3766 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3767 case_WLAN(DISASSOC_BAD_POWER);
3768 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3769 case_WLAN(INVALID_IE);
3770 case_WLAN(MIC_FAILURE);
3771 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3772 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3773 case_WLAN(IE_DIFFERENT);
3774 case_WLAN(INVALID_GROUP_CIPHER);
3775 case_WLAN(INVALID_PAIRWISE_CIPHER);
3776 case_WLAN(INVALID_AKMP);
3777 case_WLAN(UNSUPP_RSN_VERSION);
3778 case_WLAN(INVALID_RSN_IE_CAP);
3779 case_WLAN(IEEE8021X_FAILED);
3780 case_WLAN(CIPHER_SUITE_REJECTED);
3781 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3782 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3783 case_WLAN(DISASSOC_LOW_ACK);
3784 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3785 case_WLAN(QSTA_LEAVE_QBSS);
3786 case_WLAN(QSTA_NOT_USE);
3787 case_WLAN(QSTA_REQUIRE_SETUP);
3788 case_WLAN(QSTA_TIMEOUT);
3789 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3790 case_WLAN(MESH_PEER_CANCELED);
3791 case_WLAN(MESH_MAX_PEERS);
3792 case_WLAN(MESH_CONFIG);
3793 case_WLAN(MESH_CLOSE);
3794 case_WLAN(MESH_MAX_RETRIES);
3795 case_WLAN(MESH_CONFIRM_TIMEOUT);
3796 case_WLAN(MESH_INVALID_GTK);
3797 case_WLAN(MESH_INCONSISTENT_PARAM);
3798 case_WLAN(MESH_INVALID_SECURITY);
3799 case_WLAN(MESH_PATH_ERROR);
3800 case_WLAN(MESH_PATH_NOFORWARD);
3801 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3802 case_WLAN(MAC_EXISTS_IN_MBSS);
3803 case_WLAN(MESH_CHAN_REGULATORY);
3804 case_WLAN(MESH_CHAN);
3805 default: return "<unknown>";
3809 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3810 struct ieee80211_mgmt *mgmt, size_t len)
3812 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3813 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3815 sdata_assert_lock(sdata);
3820 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3821 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3825 if (ifmgd->associated &&
3826 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
3827 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3828 sdata->vif.cfg.ap_addr, reason_code,
3829 ieee80211_get_reason_code_string(reason_code));
3831 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3833 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3834 reason_code, false);
3838 if (ifmgd->assoc_data &&
3839 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
3841 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3842 ifmgd->assoc_data->ap_addr, reason_code,
3843 ieee80211_get_reason_code_string(reason_code));
3845 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3847 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3853 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3854 struct ieee80211_mgmt *mgmt, size_t len)
3856 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3859 sdata_assert_lock(sdata);
3864 if (!ifmgd->associated ||
3865 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
3868 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3870 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3871 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3875 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3876 sdata->vif.cfg.ap_addr, reason_code,
3877 ieee80211_get_reason_code_string(reason_code));
3879 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3881 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3885 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3886 u8 *supp_rates, unsigned int supp_rates_len,
3887 u32 *rates, u32 *basic_rates,
3888 bool *have_higher_than_11mbit,
3889 int *min_rate, int *min_rate_index,
3894 for (i = 0; i < supp_rates_len; i++) {
3895 int rate = supp_rates[i] & 0x7f;
3896 bool is_basic = !!(supp_rates[i] & 0x80);
3898 if ((rate * 5 * (1 << shift)) > 110)
3899 *have_higher_than_11mbit = true;
3902 * Skip HT, VHT, HE, EHT and SAE H2E only BSS membership
3903 * selectors since they're not rates.
3905 * Note: Even though the membership selector and the basic
3906 * rate flag share the same bit, they are not exactly
3909 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3910 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3911 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3912 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_EHT_PHY) ||
3913 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3916 for (j = 0; j < sband->n_bitrates; j++) {
3917 struct ieee80211_rate *br;
3920 br = &sband->bitrates[j];
3922 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3923 if (brate == rate) {
3926 *basic_rates |= BIT(j);
3927 if ((rate * 5) < *min_rate) {
3928 *min_rate = rate * 5;
3929 *min_rate_index = j;
3937 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
3938 struct ieee80211_supported_band *sband,
3939 const struct link_sta_info *link_sta,
3940 const struct ieee802_11_elems *elems)
3942 const struct ieee80211_sta_he_cap *own_he_cap =
3943 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3945 if (elems->ext_capab_len < 10)
3948 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3951 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3952 IEEE80211_HE_MAC_CAP0_TWT_RES &&
3954 (own_he_cap->he_cap_elem.mac_cap_info[0] &
3955 IEEE80211_HE_MAC_CAP0_TWT_REQ);
3958 static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3959 struct ieee80211_supported_band *sband,
3960 struct ieee80211_link_data *link,
3961 struct link_sta_info *link_sta,
3962 struct ieee802_11_elems *elems)
3964 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
3966 if (link->conf->twt_requester != twt) {
3967 link->conf->twt_requester = twt;
3968 return BSS_CHANGED_TWT;
3973 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3974 struct ieee80211_bss_conf *bss_conf,
3975 struct ieee80211_supported_band *sband,
3976 struct link_sta_info *link_sta)
3978 const struct ieee80211_sta_he_cap *own_he_cap =
3979 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3981 return bss_conf->he_support &&
3982 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3983 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3985 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3986 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3989 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
3990 struct link_sta_info *link_sta,
3991 struct cfg80211_bss *cbss,
3992 struct ieee80211_mgmt *mgmt,
3993 const u8 *elem_start,
3994 unsigned int elem_len,
3997 struct ieee80211_sub_if_data *sdata = link->sdata;
3998 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3999 struct ieee80211_bss_conf *bss_conf = link->conf;
4000 struct ieee80211_local *local = sdata->local;
4001 unsigned int link_id = link->link_id;
4002 struct ieee80211_elems_parse_params parse_params = {
4003 .start = elem_start,
4005 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
4008 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4009 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
4010 const struct cfg80211_bss_ies *bss_ies = NULL;
4011 struct ieee80211_supported_band *sband;
4012 struct ieee802_11_elems *elems;
4016 elems = ieee802_11_parse_elems_full(&parse_params);
4020 if (link_id == assoc_data->assoc_link_id) {
4021 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
4024 * we should not get to this flow unless the association was
4025 * successful, so set the status directly to success
4027 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
4028 } else if (!elems->prof) {
4032 const u8 *ptr = elems->prof->variable +
4033 elems->prof->sta_info_len - 1;
4036 * During parsing, we validated that these fields exist,
4037 * otherwise elems->prof would have been set to NULL.
4039 capab_info = get_unaligned_le16(ptr);
4040 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
4042 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
4043 link_info(link, "association response status code=%u\n",
4044 assoc_data->link[link_id].status);
4050 if (!is_s1g && !elems->supp_rates) {
4051 sdata_info(sdata, "no SuppRates element in AssocResp\n");
4056 link->u.mgd.tdls_chan_switch_prohibited =
4057 elems->ext_capab && elems->ext_capab_len >= 5 &&
4058 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
4061 * Some APs are erroneously not including some information in their
4062 * (re)association response frames. Try to recover by using the data
4063 * from the beacon or probe response. This seems to afflict mobile
4064 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
4065 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
4068 ((assoc_data->wmm && !elems->wmm_param) ||
4069 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4070 (!elems->ht_cap_elem || !elems->ht_operation)) ||
4071 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4072 (!elems->vht_cap_elem || !elems->vht_operation)))) {
4073 const struct cfg80211_bss_ies *ies;
4074 struct ieee802_11_elems *bss_elems;
4077 ies = rcu_dereference(cbss->ies);
4079 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
4087 parse_params.start = bss_ies->data;
4088 parse_params.len = bss_ies->len;
4089 parse_params.bss = cbss;
4090 bss_elems = ieee802_11_parse_elems_full(&parse_params);
4096 if (assoc_data->wmm &&
4097 !elems->wmm_param && bss_elems->wmm_param) {
4098 elems->wmm_param = bss_elems->wmm_param;
4100 "AP bug: WMM param missing from AssocResp\n");
4104 * Also check if we requested HT/VHT, otherwise the AP doesn't
4105 * have to include the IEs in the (re)association response.
4107 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
4108 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4109 elems->ht_cap_elem = bss_elems->ht_cap_elem;
4111 "AP bug: HT capability missing from AssocResp\n");
4113 if (!elems->ht_operation && bss_elems->ht_operation &&
4114 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4115 elems->ht_operation = bss_elems->ht_operation;
4117 "AP bug: HT operation missing from AssocResp\n");
4119 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
4120 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4121 elems->vht_cap_elem = bss_elems->vht_cap_elem;
4123 "AP bug: VHT capa missing from AssocResp\n");
4125 if (!elems->vht_operation && bss_elems->vht_operation &&
4126 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4127 elems->vht_operation = bss_elems->vht_operation;
4129 "AP bug: VHT operation missing from AssocResp\n");
4136 * We previously checked these in the beacon/probe response, so
4137 * they should be present here. This is just a safety net.
4139 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4140 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
4142 "HT AP is missing WMM params or HT capability/operation\n");
4147 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4148 (!elems->vht_cap_elem || !elems->vht_operation)) {
4150 "VHT AP is missing VHT capability/operation\n");
4155 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4156 !elems->he_6ghz_capa) {
4158 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
4163 if (WARN_ON(!link->conf->chandef.chan)) {
4167 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
4169 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4170 (!elems->he_cap || !elems->he_operation)) {
4172 "HE AP is missing HE capability/operation\n");
4177 /* Set up internal HT/VHT capabilities */
4178 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
4179 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
4183 if (elems->vht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
4184 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4185 elems->vht_cap_elem,
4188 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4190 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
4193 elems->he_6ghz_capa,
4196 bss_conf->he_support = link_sta->pub->he_cap.has_he;
4197 if (elems->rsnx && elems->rsnx_len &&
4198 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
4199 wiphy_ext_feature_isset(local->hw.wiphy,
4200 NL80211_EXT_FEATURE_PROTECTED_TWT))
4201 bss_conf->twt_protected = true;
4203 bss_conf->twt_protected = false;
4205 *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
4208 if (elems->eht_operation && elems->eht_cap &&
4209 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
4210 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
4217 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
4218 *changed |= BSS_CHANGED_EHT_PUNCTURING;
4220 bss_conf->eht_support = false;
4223 bss_conf->he_support = false;
4224 bss_conf->twt_requester = false;
4225 bss_conf->twt_protected = false;
4226 bss_conf->eht_support = false;
4229 bss_conf->twt_broadcast =
4230 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
4232 if (bss_conf->he_support) {
4233 bss_conf->he_bss_color.color =
4234 le32_get_bits(elems->he_operation->he_oper_params,
4235 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
4236 bss_conf->he_bss_color.partial =
4237 le32_get_bits(elems->he_operation->he_oper_params,
4238 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
4239 bss_conf->he_bss_color.enabled =
4240 !le32_get_bits(elems->he_operation->he_oper_params,
4241 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
4243 if (bss_conf->he_bss_color.enabled)
4244 *changed |= BSS_CHANGED_HE_BSS_COLOR;
4246 bss_conf->htc_trig_based_pkt_ext =
4247 le32_get_bits(elems->he_operation->he_oper_params,
4248 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
4249 bss_conf->frame_time_rts_th =
4250 le32_get_bits(elems->he_operation->he_oper_params,
4251 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
4253 bss_conf->uora_exists = !!elems->uora_element;
4254 if (elems->uora_element)
4255 bss_conf->uora_ocw_range = elems->uora_element[0];
4257 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
4258 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
4259 /* TODO: OPEN: what happens if BSS color disable is set? */
4262 if (cbss->transmitted_bss) {
4263 bss_conf->nontransmitted = true;
4264 ether_addr_copy(bss_conf->transmitter_bssid,
4265 cbss->transmitted_bss->bssid);
4266 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
4267 bss_conf->bssid_index = cbss->bssid_index;
4271 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
4272 * in their association response, so ignore that data for our own
4273 * configuration. If it changed since the last beacon, we'll get the
4274 * next beacon and update then.
4278 * If an operating mode notification IE is present, override the
4279 * NSS calculation (that would be done in rate_control_rate_init())
4280 * and use the # of streams from that element.
4282 if (elems->opmode_notif &&
4283 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
4286 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
4287 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
4289 link_sta->pub->rx_nss = nss;
4293 * Always handle WMM once after association regardless
4294 * of the first value the AP uses. Setting -1 here has
4295 * that effect because the AP values is an unsigned
4298 link->u.mgd.wmm_last_param_set = -1;
4299 link->u.mgd.mu_edca_last_param_set = -1;
4301 if (link->u.mgd.disable_wmm_tracking) {
4302 ieee80211_set_wmm_default(link, false, false);
4303 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4304 elems->wmm_param_len,
4305 elems->mu_edca_param_set)) {
4306 /* still enable QoS since we might have HT/VHT */
4307 ieee80211_set_wmm_default(link, false, true);
4308 /* disable WMM tracking in this case to disable
4309 * tracking WMM parameter changes in the beacon if
4310 * the parameters weren't actually valid. Doing so
4311 * avoids changing parameters very strangely when
4312 * the AP is going back and forth between valid and
4313 * invalid parameters.
4315 link->u.mgd.disable_wmm_tracking = true;
4318 if (elems->max_idle_period_ie) {
4319 bss_conf->max_idle_period =
4320 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
4321 bss_conf->protected_keep_alive =
4322 !!(elems->max_idle_period_ie->idle_options &
4323 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
4324 *changed |= BSS_CHANGED_KEEP_ALIVE;
4326 bss_conf->max_idle_period = 0;
4327 bss_conf->protected_keep_alive = false;
4330 /* set assoc capability (AID was already set earlier),
4331 * ieee80211_set_associated() will tell the driver */
4332 bss_conf->assoc_capability = capab_info;
4341 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
4342 struct sta_info *sta,
4343 struct link_sta_info *link_sta,
4344 struct cfg80211_bss *cbss)
4346 struct ieee80211_sub_if_data *sdata = link->sdata;
4347 struct ieee80211_local *local = sdata->local;
4348 struct ieee80211_bss *bss = (void *)cbss->priv;
4349 u32 rates = 0, basic_rates = 0;
4350 bool have_higher_than_11mbit = false;
4351 int min_rate = INT_MAX, min_rate_index = -1;
4352 /* this is clearly wrong for MLO but we'll just remove it later */
4353 int shift = ieee80211_vif_get_shift(&sdata->vif);
4354 struct ieee80211_supported_band *sband;
4356 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
4357 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
4359 /* TODO: S1G Basic Rate Set is expressed elsewhere */
4360 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
4361 ieee80211_s1g_sta_rate_init(sta);
4365 sband = local->hw.wiphy->bands[cbss->channel->band];
4367 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
4368 &rates, &basic_rates, &have_higher_than_11mbit,
4369 &min_rate, &min_rate_index, shift);
4372 * This used to be a workaround for basic rates missing
4373 * in the association response frame. Now that we no
4374 * longer use the basic rates from there, it probably
4375 * doesn't happen any more, but keep the workaround so
4376 * in case some *other* APs are buggy in different ways
4377 * we can connect -- with a warning.
4378 * Allow this workaround only in case the AP provided at least
4381 if (min_rate_index < 0) {
4382 link_info(link, "No legacy rates in association response\n");
4384 } else if (!basic_rates) {
4385 link_info(link, "No basic rates, using min rate instead\n");
4386 basic_rates = BIT(min_rate_index);
4390 link_sta->pub->supp_rates[cbss->channel->band] = rates;
4392 link_info(link, "No rates found, keeping mandatory only\n");
4394 link->conf->basic_rates = basic_rates;
4396 /* cf. IEEE 802.11 9.2.12 */
4397 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
4398 have_higher_than_11mbit;
4403 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
4404 struct cfg80211_bss *cbss)
4406 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4407 const struct element *ht_cap_elem, *vht_cap_elem;
4408 const struct cfg80211_bss_ies *ies;
4409 const struct ieee80211_ht_cap *ht_cap;
4410 const struct ieee80211_vht_cap *vht_cap;
4411 const struct ieee80211_he_cap_elem *he_cap;
4412 const struct element *he_cap_elem;
4413 u16 mcs_80_map, mcs_160_map;
4414 int i, mcs_nss_size;
4418 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
4421 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4422 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4423 ht_cap = (void *)ht_cap_elem->data;
4424 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4426 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4427 * "Tx Unequal Modulation Supported" fields.
4431 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
4434 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4435 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4439 vht_cap = (void *)vht_cap_elem->data;
4440 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4441 for (nss = 8; nss > 0; nss--) {
4442 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4443 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4446 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4447 chains = max(chains, nss);
4450 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
4453 ies = rcu_dereference(cbss->ies);
4454 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4455 ies->data, ies->len);
4457 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
4460 /* skip one byte ext_tag_id */
4461 he_cap = (void *)(he_cap_elem->data + 1);
4462 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4465 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
4468 /* mcs_nss is right after he_cap info */
4469 he_mcs_nss_supp = (void *)(he_cap + 1);
4471 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4473 for (i = 7; i >= 0; i--) {
4474 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
4476 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4477 chains = max_t(u8, chains, i + 1);
4482 support_160 = he_cap->phy_cap_info[0] &
4483 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
4488 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
4489 for (i = 7; i >= 0; i--) {
4490 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
4492 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4493 chains = max_t(u8, chains, i + 1);
4502 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4503 const struct cfg80211_bss_ies *ies,
4504 const struct ieee80211_he_operation *he_op)
4506 const struct element *he_cap_elem;
4507 const struct ieee80211_he_cap_elem *he_cap;
4508 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4509 u16 mcs_80_map_tx, mcs_80_map_rx;
4514 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4515 ies->data, ies->len);
4521 if (he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
4523 "Invalid HE elem, Disable HE\n");
4527 /* skip one byte ext_tag_id */
4528 he_cap = (void *)(he_cap_elem->data + 1);
4529 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4532 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
4534 "Invalid HE elem with nss size, Disable HE\n");
4538 /* mcs_nss is right after he_cap info */
4539 he_mcs_nss_supp = (void *)(he_cap + 1);
4541 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4542 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
4544 /* P802.11-REVme/D0.3
4545 * 27.1.1 Introduction to the HE PHY
4547 * An HE STA shall support the following features:
4549 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
4550 * supported channel widths for HE SU PPDUs
4552 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4553 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
4555 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
4556 mcs_80_map_tx, mcs_80_map_rx);
4563 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4566 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4567 * zeroes, which is nonsense, and completely inconsistent with itself
4568 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4570 if (!ap_min_req_set)
4573 /* make sure the AP is consistent with itself
4575 * P802.11-REVme/D0.3
4576 * 26.17.1 Basic HE BSS operation
4578 * A STA that is operating in an HE BSS shall be able to receive and
4579 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
4580 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
4581 * MLME-START.request primitive and shall be able to receive at each of
4582 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
4583 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
4586 for (nss = 8; nss > 0; nss--) {
4587 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4591 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4594 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
4595 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
4597 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4598 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4599 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
4601 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
4602 nss, ap_rx_val, ap_rx_val, ap_op_val);
4611 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4612 struct ieee80211_supported_band *sband,
4613 const struct ieee80211_he_operation *he_op)
4615 const struct ieee80211_sta_he_cap *sta_he_cap =
4616 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4620 if (!sta_he_cap || !he_op)
4623 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4626 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4627 * zeroes, which is nonsense, and completely inconsistent with itself
4628 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4630 if (!ap_min_req_set)
4633 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4634 for (i = 0; i < 3; i++) {
4635 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4636 &sta_he_cap->he_mcs_nss_supp;
4637 u16 sta_mcs_map_rx =
4638 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4639 u16 sta_mcs_map_tx =
4640 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4642 bool verified = true;
4645 * For each band there is a maximum of 8 spatial streams
4646 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4647 * of 2 bits per NSS (1-8), with the values defined in enum
4648 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4649 * capabilities aren't less than the AP's minimum requirements
4650 * for this HE BSS per SS.
4651 * It is enough to find one such band that meets the reqs.
4653 for (nss = 8; nss > 0; nss--) {
4654 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4655 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4656 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4658 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4662 * Make sure the HE AP doesn't require MCSs that aren't
4663 * supported by the client as required by spec
4665 * P802.11-REVme/D0.3
4666 * 26.17.1 Basic HE BSS operation
4668 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
4669 * a BSS, unless it supports (i.e., is able to both transmit and
4670 * receive using) all of the <HE-MCS, NSS> tuples in the basic
4671 * HE-MCS and NSS set.
4673 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4674 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4675 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4685 /* If here, STA doesn't meet AP's HE min requirements */
4689 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4690 struct ieee80211_link_data *link,
4691 struct cfg80211_bss *cbss,
4692 ieee80211_conn_flags_t *conn_flags)
4694 struct ieee80211_local *local = sdata->local;
4695 const struct ieee80211_ht_cap *ht_cap = NULL;
4696 const struct ieee80211_ht_operation *ht_oper = NULL;
4697 const struct ieee80211_vht_operation *vht_oper = NULL;
4698 const struct ieee80211_he_operation *he_oper = NULL;
4699 const struct ieee80211_eht_operation *eht_oper = NULL;
4700 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4701 struct ieee80211_supported_band *sband;
4702 struct cfg80211_chan_def chandef;
4703 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4704 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4705 struct ieee80211_bss *bss = (void *)cbss->priv;
4706 struct ieee80211_elems_parse_params parse_params = {
4711 struct ieee802_11_elems *elems;
4712 const struct cfg80211_bss_ies *ies;
4719 ies = rcu_dereference(cbss->ies);
4720 parse_params.start = ies->data;
4721 parse_params.len = ies->len;
4722 elems = ieee802_11_parse_elems_full(&parse_params);
4728 sband = local->hw.wiphy->bands[cbss->channel->band];
4730 *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
4731 IEEE80211_CONN_DISABLE_80P80MHZ |
4732 IEEE80211_CONN_DISABLE_160MHZ);
4734 /* disable HT/VHT/HE if we don't support them */
4735 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4736 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
4737 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4738 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4739 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4740 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4743 if (!sband->vht_cap.vht_supported && is_5ghz) {
4744 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
4745 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4746 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4747 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4750 if (!ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif)) {
4751 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
4752 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4753 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4756 if (!ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif)) {
4757 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
4758 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4761 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
4762 ht_oper = elems->ht_operation;
4763 ht_cap = elems->ht_cap_elem;
4766 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4771 if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
4772 vht_oper = elems->vht_operation;
4773 if (vht_oper && !ht_oper) {
4776 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
4777 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4778 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4779 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4780 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4783 if (!elems->vht_cap_elem) {
4784 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4789 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
4790 he_oper = elems->he_operation;
4792 if (link && is_6ghz) {
4793 struct ieee80211_bss_conf *bss_conf;
4796 bss_conf = link->conf;
4798 if (elems->pwr_constr_elem)
4799 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
4801 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
4802 ARRAY_SIZE(elems->tx_pwr_env));
4804 for (i = 0; i < elems->tx_pwr_env_num; i++) {
4805 if (elems->tx_pwr_env_len[i] >
4806 sizeof(bss_conf->tx_pwr_env[j]))
4809 bss_conf->tx_pwr_env_num++;
4810 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
4811 elems->tx_pwr_env_len[i]);
4816 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
4817 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
4818 *conn_flags |= IEEE80211_CONN_DISABLE_HE |
4819 IEEE80211_CONN_DISABLE_EHT;
4823 * EHT requires HE to be supported as well. Specifically for 6 GHz
4824 * channels, the operation channel information can only be deduced from
4825 * both the 6 GHz operation information (from the HE operation IE) and
4829 (IEEE80211_CONN_DISABLE_HE |
4830 IEEE80211_CONN_DISABLE_EHT)) &&
4832 const struct cfg80211_bss_ies *cbss_ies;
4833 const struct element *eht_ml_elem;
4834 const u8 *eht_oper_ie;
4836 cbss_ies = rcu_dereference(cbss->ies);
4837 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
4838 cbss_ies->data, cbss_ies->len);
4839 if (eht_oper_ie && eht_oper_ie[1] >=
4840 1 + sizeof(struct ieee80211_eht_operation))
4841 eht_oper = (void *)(eht_oper_ie + 3);
4845 eht_ml_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_MULTI_LINK,
4846 cbss_ies->data, cbss_ies->len);
4848 /* data + 1 / datalen - 1 since it's an extended element */
4850 ieee80211_mle_size_ok(eht_ml_elem->data + 1,
4851 eht_ml_elem->datalen - 1)) {
4852 sdata->vif.cfg.eml_cap =
4853 ieee80211_mle_get_eml_cap(eht_ml_elem->data + 1);
4854 sdata->vif.cfg.eml_med_sync_delay =
4855 ieee80211_mle_get_eml_med_sync_delay(eht_ml_elem->data + 1);
4859 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4861 for (i = 0; i < sband->n_channels; i++) {
4862 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4863 IEEE80211_CHAN_NO_80MHZ))
4871 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
4872 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4875 if (sband->band == NL80211_BAND_S1GHZ) {
4876 s1g_oper = elems->s1g_oper;
4879 "AP missing S1G operation element?\n");
4883 ieee80211_determine_chantype(sdata, link, *conn_flags,
4893 link->needed_rx_chains =
4894 min(ieee80211_max_rx_chains(link, cbss),
4898 /* the element data was RCU protected so no longer valid anyway */
4902 if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
4903 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
4910 /* will change later if needed */
4911 link->smps_mode = IEEE80211_SMPS_OFF;
4913 mutex_lock(&local->mtx);
4915 * If this fails (possibly due to channel context sharing
4916 * on incompatible channels, e.g. 80+80 and 160 sharing the
4917 * same control channel) try to use a smaller bandwidth.
4919 ret = ieee80211_link_use_channel(link, &chandef,
4920 IEEE80211_CHANCTX_SHARED);
4922 /* don't downgrade for 5 and 10 MHz channels, though. */
4923 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4924 chandef.width == NL80211_CHAN_WIDTH_10)
4927 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4929 ieee80211_chandef_downgrade(&chandef);
4930 ret = ieee80211_link_use_channel(link, &chandef,
4931 IEEE80211_CHANCTX_SHARED);
4934 mutex_unlock(&local->mtx);
4938 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4939 u8 *dtim_count, u8 *dtim_period)
4941 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4942 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4944 const struct ieee80211_tim_ie *tim = NULL;
4945 const struct ieee80211_bssid_index *idx;
4946 bool valid = tim_ie && tim_ie[1] >= 2;
4949 tim = (void *)(tim_ie + 2);
4952 *dtim_count = valid ? tim->dtim_count : 0;
4955 *dtim_period = valid ? tim->dtim_period : 0;
4957 /* Check if value is overridden by non-transmitted profile */
4958 if (!idx_ie || idx_ie[1] < 3)
4961 idx = (void *)(idx_ie + 2);
4964 *dtim_count = idx->dtim_count;
4967 *dtim_period = idx->dtim_period;
4972 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
4973 struct ieee80211_mgmt *mgmt,
4974 struct ieee802_11_elems *elems,
4975 const u8 *elem_start, unsigned int elem_len)
4977 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4978 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
4979 struct ieee80211_local *local = sdata->local;
4980 unsigned int link_id;
4981 struct sta_info *sta;
4982 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
4983 u16 valid_links = 0;
4986 mutex_lock(&sdata->local->sta_mtx);
4988 * station info was already allocated and inserted before
4989 * the association and should be available to us
4991 sta = sta_info_get(sdata, assoc_data->ap_addr);
4995 if (sdata->vif.valid_links) {
4996 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
4997 if (!assoc_data->link[link_id].bss)
4999 valid_links |= BIT(link_id);
5001 if (link_id != assoc_data->assoc_link_id) {
5002 err = ieee80211_sta_allocate_link(sta, link_id);
5008 ieee80211_vif_set_links(sdata, valid_links);
5011 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5012 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
5013 struct ieee80211_link_data *link;
5014 struct link_sta_info *link_sta;
5019 link = sdata_dereference(sdata->link[link_id], sdata);
5023 if (sdata->vif.valid_links)
5025 "local address %pM, AP link address %pM%s\n",
5027 assoc_data->link[link_id].bss->bssid,
5028 link_id == assoc_data->assoc_link_id ?
5031 link_sta = rcu_dereference_protected(sta->link[link_id],
5032 lockdep_is_held(&local->sta_mtx));
5033 if (WARN_ON(!link_sta))
5036 if (!link->u.mgd.have_beacon) {
5037 const struct cfg80211_bss_ies *ies;
5040 ies = rcu_dereference(cbss->beacon_ies);
5042 link->u.mgd.have_beacon = true;
5044 ies = rcu_dereference(cbss->ies);
5045 ieee80211_get_dtim(ies,
5046 &link->conf->sync_dtim_count,
5047 &link->u.mgd.dtim_period);
5048 link->conf->beacon_int = cbss->beacon_interval;
5052 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
5054 if (link_id != assoc_data->assoc_link_id) {
5055 err = ieee80211_prep_channel(sdata, link, cbss,
5056 &link->u.mgd.conn_flags);
5058 link_info(link, "prep_channel failed\n");
5063 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
5064 assoc_data->link[link_id].bss);
5068 if (!ieee80211_assoc_config_link(link, link_sta,
5069 assoc_data->link[link_id].bss,
5070 mgmt, elem_start, elem_len,
5074 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
5075 valid_links &= ~BIT(link_id);
5076 ieee80211_sta_remove_link(sta, link_id);
5080 if (link_id != assoc_data->assoc_link_id) {
5081 err = ieee80211_sta_activate_link(sta, link_id);
5087 /* links might have changed due to rejected ones, set them again */
5088 ieee80211_vif_set_links(sdata, valid_links);
5090 rate_control_rate_init(sta);
5092 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
5093 set_sta_flag(sta, WLAN_STA_MFP);
5094 sta->sta.mfp = true;
5096 sta->sta.mfp = false;
5099 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
5100 elems->ext_capab_len);
5102 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
5103 local->hw.queues >= IEEE80211_NUM_ACS;
5105 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
5106 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
5107 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
5110 "failed to move station %pM to desired state\n",
5112 WARN_ON(__sta_info_destroy(sta));
5116 if (sdata->wdev.use_4addr)
5117 drv_sta_set_4addr(local, sdata, &sta->sta, true);
5119 mutex_unlock(&sdata->local->sta_mtx);
5121 ieee80211_set_associated(sdata, assoc_data, changed);
5124 * If we're using 4-addr mode, let the AP know that we're
5125 * doing so, so that it can create the STA VLAN on its side
5127 if (ifmgd->use_4addr)
5128 ieee80211_send_4addr_nullfunc(local, sdata);
5131 * Start timer to probe the connection to the AP now.
5132 * Also start the timer that will detect beacon loss.
5134 ieee80211_sta_reset_beacon_monitor(sdata);
5135 ieee80211_sta_reset_conn_monitor(sdata);
5139 eth_zero_addr(sdata->vif.cfg.ap_addr);
5140 mutex_unlock(&sdata->local->sta_mtx);
5144 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
5145 struct ieee80211_mgmt *mgmt,
5148 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5149 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5150 u16 capab_info, status_code, aid;
5151 struct ieee80211_elems_parse_params parse_params = {
5156 struct ieee802_11_elems *elems;
5158 const u8 *elem_start;
5159 unsigned int elem_len;
5161 struct ieee80211_event event = {
5163 .u.mlme.data = ASSOC_EVENT,
5165 struct ieee80211_prep_tx_info info = {};
5166 struct cfg80211_rx_assoc_resp resp = {
5169 u8 ap_mld_addr[ETH_ALEN] __aligned(2);
5170 unsigned int link_id;
5172 sdata_assert_lock(sdata);
5177 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
5178 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
5182 * AssocResp and ReassocResp have identical structure, so process both
5183 * of them in this function.
5189 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
5190 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
5191 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
5192 if (assoc_data->s1g)
5193 elem_start = mgmt->u.s1g_assoc_resp.variable;
5195 elem_start = mgmt->u.assoc_resp.variable;
5198 * Note: this may not be perfect, AP might misbehave - if
5199 * anyone needs to rely on perfect complete notification
5200 * with the exact right subtype, then we need to track what
5201 * we actually transmitted.
5203 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
5204 IEEE80211_STYPE_ASSOC_REQ;
5206 if (assoc_data->fils_kek_len &&
5207 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
5210 elem_len = len - (elem_start - (u8 *)mgmt);
5211 parse_params.start = elem_start;
5212 parse_params.len = elem_len;
5213 elems = ieee802_11_parse_elems_full(&parse_params);
5217 if (elems->aid_resp)
5218 aid = le16_to_cpu(elems->aid_resp->aid);
5219 else if (assoc_data->s1g)
5222 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
5225 * The 5 MSB of the AID field are reserved
5226 * (802.11-2016 9.4.1.8 AID field)
5231 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
5232 reassoc ? "Rea" : "A", assoc_data->ap_addr,
5233 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
5235 ifmgd->broken_ap = false;
5237 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
5238 elems->timeout_int &&
5239 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
5242 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
5243 le32_to_cpu(elems->timeout_int->value));
5245 tu = le32_to_cpu(elems->timeout_int->value);
5246 ms = tu * 1024 / 1000;
5248 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
5249 assoc_data->ap_addr, tu, ms);
5250 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
5251 assoc_data->timeout_started = true;
5252 if (ms > IEEE80211_ASSOC_TIMEOUT)
5253 run_again(sdata, assoc_data->timeout);
5257 if (status_code != WLAN_STATUS_SUCCESS) {
5258 sdata_info(sdata, "%pM denied association (code=%d)\n",
5259 assoc_data->ap_addr, status_code);
5260 event.u.mlme.status = MLME_DENIED;
5261 event.u.mlme.reason = status_code;
5262 drv_event_callback(sdata->local, sdata, &event);
5264 if (aid == 0 || aid > IEEE80211_MAX_AID) {
5266 "invalid AID value %d (out of range), turn off PS\n",
5269 ifmgd->broken_ap = true;
5272 if (sdata->vif.valid_links) {
5273 if (!elems->multi_link) {
5275 "MLO association with %pM but no multi-link element in response!\n",
5276 assoc_data->ap_addr);
5280 if (le16_get_bits(elems->multi_link->control,
5281 IEEE80211_ML_CONTROL_TYPE) !=
5282 IEEE80211_ML_CONTROL_TYPE_BASIC) {
5284 "bad multi-link element (control=0x%x)\n",
5285 le16_to_cpu(elems->multi_link->control));
5288 struct ieee80211_mle_basic_common_info *common;
5290 common = (void *)elems->multi_link->variable;
5292 if (memcmp(assoc_data->ap_addr,
5293 common->mld_mac_addr, ETH_ALEN)) {
5295 "AP MLD MAC address mismatch: got %pM expected %pM\n",
5296 common->mld_mac_addr,
5297 assoc_data->ap_addr);
5303 sdata->vif.cfg.aid = aid;
5305 if (!ieee80211_assoc_success(sdata, mgmt, elems,
5306 elem_start, elem_len)) {
5307 /* oops -- internal error -- send timeout for now */
5308 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5311 event.u.mlme.status = MLME_SUCCESS;
5312 drv_event_callback(sdata->local, sdata, &event);
5313 sdata_info(sdata, "associated\n");
5318 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5319 struct ieee80211_link_data *link;
5321 link = sdata_dereference(sdata->link[link_id], sdata);
5325 if (!assoc_data->link[link_id].bss)
5328 resp.links[link_id].bss = assoc_data->link[link_id].bss;
5329 resp.links[link_id].addr = link->conf->addr;
5330 resp.links[link_id].status = assoc_data->link[link_id].status;
5332 /* get uapsd queues configuration - same for all links */
5333 resp.uapsd_queues = 0;
5334 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
5335 if (link->tx_conf[ac].uapsd)
5336 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
5339 if (sdata->vif.valid_links) {
5340 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
5341 resp.ap_mld_addr = ap_mld_addr;
5344 ieee80211_destroy_assoc_data(sdata,
5345 status_code == WLAN_STATUS_SUCCESS ?
5349 resp.buf = (u8 *)mgmt;
5351 resp.req_ies = ifmgd->assoc_req_ies;
5352 resp.req_ies_len = ifmgd->assoc_req_ies_len;
5353 cfg80211_rx_assoc_resp(sdata->dev, &resp);
5355 drv_mgd_complete_tx(sdata->local, sdata, &info);
5359 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5363 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
5364 struct ieee80211_mgmt *mgmt, size_t len,
5365 struct ieee80211_rx_status *rx_status)
5367 struct ieee80211_sub_if_data *sdata = link->sdata;
5368 struct ieee80211_local *local = sdata->local;
5369 struct ieee80211_bss *bss;
5370 struct ieee80211_channel *channel;
5372 sdata_assert_lock(sdata);
5374 channel = ieee80211_get_channel_khz(local->hw.wiphy,
5375 ieee80211_rx_status_to_khz(rx_status));
5379 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
5381 link->conf->beacon_rate = bss->beacon_rate;
5382 ieee80211_rx_bss_put(local, bss);
5387 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
5388 struct sk_buff *skb)
5390 struct ieee80211_sub_if_data *sdata = link->sdata;
5391 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5392 struct ieee80211_if_managed *ifmgd;
5393 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
5394 struct ieee80211_channel *channel;
5395 size_t baselen, len = skb->len;
5397 ifmgd = &sdata->u.mgd;
5399 sdata_assert_lock(sdata);
5402 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
5403 * "If a 6 GHz AP receives a Probe Request frame and responds with
5404 * a Probe Response frame [..], the Address 1 field of the Probe
5405 * Response frame shall be set to the broadcast address [..]"
5406 * So, on 6GHz band we should also accept broadcast responses.
5408 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
5413 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
5414 (channel->band != NL80211_BAND_6GHZ ||
5415 !is_broadcast_ether_addr(mgmt->da)))
5416 return; /* ignore ProbeResp to foreign address */
5418 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
5422 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5424 if (ifmgd->associated &&
5425 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
5426 ieee80211_reset_ap_probe(sdata);
5430 * This is the canonical list of information elements we care about,
5431 * the filter code also gives us all changes to the Microsoft OUI
5432 * (00:50:F2) vendor IE which is used for WMM which we need to track,
5433 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
5434 * changes to requested client power.
5436 * We implement beacon filtering in software since that means we can
5437 * avoid processing the frame here and in cfg80211, and userspace
5438 * will not be able to tell whether the hardware supports it or not.
5440 * XXX: This list needs to be dynamic -- userspace needs to be able to
5441 * add items it requires. It also needs to be able to tell us to
5442 * look out for other vendor IEs.
5444 static const u64 care_about_ies =
5445 (1ULL << WLAN_EID_COUNTRY) |
5446 (1ULL << WLAN_EID_ERP_INFO) |
5447 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
5448 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
5449 (1ULL << WLAN_EID_HT_CAPABILITY) |
5450 (1ULL << WLAN_EID_HT_OPERATION) |
5451 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
5453 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
5454 struct ieee80211_if_managed *ifmgd,
5455 struct ieee80211_bss_conf *bss_conf,
5456 struct ieee80211_local *local,
5457 struct ieee80211_rx_status *rx_status)
5459 struct ieee80211_sub_if_data *sdata = link->sdata;
5461 /* Track average RSSI from the Beacon frames of the current AP */
5463 if (!link->u.mgd.tracking_signal_avg) {
5464 link->u.mgd.tracking_signal_avg = true;
5465 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
5466 link->u.mgd.last_cqm_event_signal = 0;
5467 link->u.mgd.count_beacon_signal = 1;
5468 link->u.mgd.last_ave_beacon_signal = 0;
5470 link->u.mgd.count_beacon_signal++;
5473 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
5474 -rx_status->signal);
5476 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
5477 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5478 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5479 int last_sig = link->u.mgd.last_ave_beacon_signal;
5480 struct ieee80211_event event = {
5485 * if signal crosses either of the boundaries, invoke callback
5486 * with appropriate parameters
5488 if (sig > ifmgd->rssi_max_thold &&
5489 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
5490 link->u.mgd.last_ave_beacon_signal = sig;
5491 event.u.rssi.data = RSSI_EVENT_HIGH;
5492 drv_event_callback(local, sdata, &event);
5493 } else if (sig < ifmgd->rssi_min_thold &&
5494 (last_sig >= ifmgd->rssi_max_thold ||
5496 link->u.mgd.last_ave_beacon_signal = sig;
5497 event.u.rssi.data = RSSI_EVENT_LOW;
5498 drv_event_callback(local, sdata, &event);
5502 if (bss_conf->cqm_rssi_thold &&
5503 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
5504 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
5505 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5506 int last_event = link->u.mgd.last_cqm_event_signal;
5507 int thold = bss_conf->cqm_rssi_thold;
5508 int hyst = bss_conf->cqm_rssi_hyst;
5511 (last_event == 0 || sig < last_event - hyst)) {
5512 link->u.mgd.last_cqm_event_signal = sig;
5513 ieee80211_cqm_rssi_notify(
5515 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5517 } else if (sig > thold &&
5518 (last_event == 0 || sig > last_event + hyst)) {
5519 link->u.mgd.last_cqm_event_signal = sig;
5520 ieee80211_cqm_rssi_notify(
5522 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5527 if (bss_conf->cqm_rssi_low &&
5528 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5529 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5530 int last_event = link->u.mgd.last_cqm_event_signal;
5531 int low = bss_conf->cqm_rssi_low;
5532 int high = bss_conf->cqm_rssi_high;
5535 (last_event == 0 || last_event >= low)) {
5536 link->u.mgd.last_cqm_event_signal = sig;
5537 ieee80211_cqm_rssi_notify(
5539 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5541 } else if (sig > high &&
5542 (last_event == 0 || last_event <= high)) {
5543 link->u.mgd.last_cqm_event_signal = sig;
5544 ieee80211_cqm_rssi_notify(
5546 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5552 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
5553 struct cfg80211_bss *bss)
5555 if (ether_addr_equal(tx_bssid, bss->bssid))
5557 if (!bss->transmitted_bss)
5559 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
5562 static bool ieee80211_config_puncturing(struct ieee80211_link_data *link,
5563 const struct ieee80211_eht_operation *eht_oper,
5566 u16 bitmap = 0, extracted;
5568 if ((eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
5570 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
5571 const struct ieee80211_eht_operation_info *info =
5572 (void *)eht_oper->optional;
5573 const u8 *disable_subchannel_bitmap = info->optional;
5575 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
5578 extracted = ieee80211_extract_dis_subch_bmap(eht_oper,
5579 &link->conf->chandef,
5582 /* accept if there are no changes */
5583 if (!(*changed & BSS_CHANGED_BANDWIDTH) &&
5584 extracted == link->conf->eht_puncturing)
5587 if (!cfg80211_valid_disable_subchannel_bitmap(&bitmap,
5588 &link->conf->chandef)) {
5590 "Got an invalid disable subchannel bitmap from AP %pM: bitmap = 0x%x, bw = 0x%x. disconnect\n",
5593 link->conf->chandef.width);
5597 ieee80211_handle_puncturing_bitmap(link, eht_oper, bitmap, changed);
5601 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
5602 struct ieee80211_hdr *hdr, size_t len,
5603 struct ieee80211_rx_status *rx_status)
5605 struct ieee80211_sub_if_data *sdata = link->sdata;
5606 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5607 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5608 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
5609 struct ieee80211_mgmt *mgmt = (void *) hdr;
5611 struct ieee802_11_elems *elems;
5612 struct ieee80211_local *local = sdata->local;
5613 struct ieee80211_chanctx_conf *chanctx_conf;
5614 struct ieee80211_supported_band *sband;
5615 struct ieee80211_channel *chan;
5616 struct link_sta_info *link_sta;
5617 struct sta_info *sta;
5622 u8 *bssid, *variable = mgmt->u.beacon.variable;
5623 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
5624 struct ieee80211_elems_parse_params parse_params = {
5629 sdata_assert_lock(sdata);
5631 /* Process beacon from the current BSS */
5632 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
5633 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
5634 struct ieee80211_ext *ext = (void *) mgmt;
5636 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
5637 variable = ext->u.s1g_short_beacon.variable;
5639 variable = ext->u.s1g_beacon.variable;
5642 baselen = (u8 *) variable - (u8 *) mgmt;
5646 parse_params.start = variable;
5647 parse_params.len = len - baselen;
5650 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
5651 if (!chanctx_conf) {
5656 if (ieee80211_rx_status_to_khz(rx_status) !=
5657 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
5661 chan = chanctx_conf->def.chan;
5664 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
5665 !WARN_ON(sdata->vif.valid_links) &&
5666 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
5667 parse_params.bss = ifmgd->assoc_data->link[0].bss;
5668 elems = ieee802_11_parse_elems_full(&parse_params);
5672 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5674 if (elems->dtim_period)
5675 link->u.mgd.dtim_period = elems->dtim_period;
5676 link->u.mgd.have_beacon = true;
5677 ifmgd->assoc_data->need_beacon = false;
5678 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5679 link->conf->sync_tsf =
5680 le64_to_cpu(mgmt->u.beacon.timestamp);
5681 link->conf->sync_device_ts =
5682 rx_status->device_timestamp;
5683 link->conf->sync_dtim_count = elems->dtim_count;
5686 if (elems->mbssid_config_ie)
5687 bss_conf->profile_periodicity =
5688 elems->mbssid_config_ie->profile_periodicity;
5690 bss_conf->profile_periodicity = 0;
5692 if (elems->ext_capab_len >= 11 &&
5693 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5694 bss_conf->ema_ap = true;
5696 bss_conf->ema_ap = false;
5698 /* continue assoc process */
5699 ifmgd->assoc_data->timeout = jiffies;
5700 ifmgd->assoc_data->timeout_started = true;
5701 run_again(sdata, ifmgd->assoc_data->timeout);
5706 if (!ifmgd->associated ||
5707 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
5709 bssid = link->u.mgd.bssid;
5711 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
5712 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
5715 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
5716 mlme_dbg_ratelimited(sdata,
5717 "cancelling AP probe due to a received beacon\n");
5718 ieee80211_reset_ap_probe(sdata);
5722 * Push the beacon loss detection into the future since
5723 * we are processing a beacon from the AP just now.
5725 ieee80211_sta_reset_beacon_monitor(sdata);
5727 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
5728 * element (which carries the beacon interval). Don't forget to add a
5729 * bit to care_about_ies[] above if mac80211 is interested in a
5730 * changing S1G element.
5732 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5733 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
5734 parse_params.bss = link->u.mgd.bss;
5735 parse_params.filter = care_about_ies;
5736 parse_params.crc = ncrc;
5737 elems = ieee802_11_parse_elems_full(&parse_params);
5742 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
5743 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
5744 if (local->hw.conf.dynamic_ps_timeout > 0) {
5745 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
5746 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
5747 ieee80211_hw_config(local,
5748 IEEE80211_CONF_CHANGE_PS);
5750 ieee80211_send_nullfunc(local, sdata, false);
5751 } else if (!local->pspolling && sdata->u.mgd.powersave) {
5752 local->pspolling = true;
5755 * Here is assumed that the driver will be
5756 * able to send ps-poll frame and receive a
5757 * response even though power save mode is
5758 * enabled, but some drivers might require
5759 * to disable power save here. This needs
5760 * to be investigated.
5762 ieee80211_send_pspoll(local, sdata);
5766 if (sdata->vif.p2p ||
5767 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
5768 struct ieee80211_p2p_noa_attr noa = {};
5771 ret = cfg80211_get_p2p_attr(variable,
5773 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
5774 (u8 *) &noa, sizeof(noa));
5776 if (link->u.mgd.p2p_noa_index != noa.index) {
5777 /* valid noa_attr and index changed */
5778 link->u.mgd.p2p_noa_index = noa.index;
5779 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
5780 changed |= BSS_CHANGED_P2P_PS;
5782 * make sure we update all information, the CRC
5783 * mechanism doesn't look at P2P attributes.
5785 link->u.mgd.beacon_crc_valid = false;
5787 } else if (link->u.mgd.p2p_noa_index != -1) {
5788 /* noa_attr not found and we had valid noa_attr before */
5789 link->u.mgd.p2p_noa_index = -1;
5790 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
5791 changed |= BSS_CHANGED_P2P_PS;
5792 link->u.mgd.beacon_crc_valid = false;
5796 if (link->u.mgd.csa_waiting_bcn)
5797 ieee80211_chswitch_post_beacon(link);
5800 * Update beacon timing and dtim count on every beacon appearance. This
5801 * will allow the driver to use the most updated values. Do it before
5802 * comparing this one with last received beacon.
5803 * IMPORTANT: These parameters would possibly be out of sync by the time
5804 * the driver will use them. The synchronized view is currently
5805 * guaranteed only in certain callbacks.
5807 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
5808 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
5809 link->conf->sync_tsf =
5810 le64_to_cpu(mgmt->u.beacon.timestamp);
5811 link->conf->sync_device_ts =
5812 rx_status->device_timestamp;
5813 link->conf->sync_dtim_count = elems->dtim_count;
5816 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
5817 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
5819 link->u.mgd.beacon_crc = ncrc;
5820 link->u.mgd.beacon_crc_valid = true;
5822 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5824 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
5825 rx_status->device_timestamp,
5828 if (!link->u.mgd.disable_wmm_tracking &&
5829 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
5830 elems->wmm_param_len,
5831 elems->mu_edca_param_set))
5832 changed |= BSS_CHANGED_QOS;
5835 * If we haven't had a beacon before, tell the driver about the
5836 * DTIM period (and beacon timing if desired) now.
5838 if (!link->u.mgd.have_beacon) {
5839 /* a few bogus AP send dtim_period = 0 or no TIM IE */
5840 bss_conf->dtim_period = elems->dtim_period ?: 1;
5842 changed |= BSS_CHANGED_BEACON_INFO;
5843 link->u.mgd.have_beacon = true;
5845 mutex_lock(&local->iflist_mtx);
5846 ieee80211_recalc_ps(local);
5847 mutex_unlock(&local->iflist_mtx);
5849 ieee80211_recalc_ps_vif(sdata);
5852 if (elems->erp_info) {
5854 erp_value = elems->erp_info[0];
5859 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5860 changed |= ieee80211_handle_bss_capability(link,
5861 le16_to_cpu(mgmt->u.beacon.capab_info),
5862 erp_valid, erp_value);
5864 mutex_lock(&local->sta_mtx);
5865 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
5866 if (WARN_ON(!sta)) {
5867 mutex_unlock(&local->sta_mtx);
5870 link_sta = rcu_dereference_protected(sta->link[link->link_id],
5871 lockdep_is_held(&local->sta_mtx));
5872 if (WARN_ON(!link_sta)) {
5873 mutex_unlock(&local->sta_mtx);
5877 if (WARN_ON(!link->conf->chandef.chan))
5880 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
5882 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
5884 if (ieee80211_config_bw(link, elems->ht_cap_elem,
5885 elems->vht_cap_elem, elems->ht_operation,
5886 elems->vht_operation, elems->he_operation,
5887 elems->eht_operation,
5888 elems->s1g_oper, bssid, &changed)) {
5889 mutex_unlock(&local->sta_mtx);
5891 "failed to follow AP %pM bandwidth change, disconnect\n",
5893 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5894 WLAN_REASON_DEAUTH_LEAVING,
5896 ieee80211_report_disconnect(sdata, deauth_buf,
5897 sizeof(deauth_buf), true,
5898 WLAN_REASON_DEAUTH_LEAVING,
5903 if (elems->opmode_notif)
5904 ieee80211_vht_handle_opmode(sdata, link_sta,
5905 *elems->opmode_notif,
5907 mutex_unlock(&local->sta_mtx);
5909 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
5910 elems->country_elem,
5911 elems->country_elem_len,
5912 elems->pwr_constr_elem,
5913 elems->cisco_dtpc_elem);
5915 if (elems->eht_operation &&
5916 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
5917 if (!ieee80211_config_puncturing(link, elems->eht_operation,
5919 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5920 WLAN_REASON_DEAUTH_LEAVING,
5922 ieee80211_report_disconnect(sdata, deauth_buf,
5923 sizeof(deauth_buf), true,
5924 WLAN_REASON_DEAUTH_LEAVING,
5930 ieee80211_link_info_change_notify(sdata, link, changed);
5935 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
5936 struct sk_buff *skb)
5938 struct ieee80211_link_data *link = &sdata->deflink;
5939 struct ieee80211_rx_status *rx_status;
5940 struct ieee80211_hdr *hdr;
5943 rx_status = (struct ieee80211_rx_status *) skb->cb;
5944 hdr = (struct ieee80211_hdr *) skb->data;
5945 fc = le16_to_cpu(hdr->frame_control);
5948 switch (fc & IEEE80211_FCTL_STYPE) {
5949 case IEEE80211_STYPE_S1G_BEACON:
5950 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
5953 sdata_unlock(sdata);
5956 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
5957 struct sk_buff *skb)
5959 struct ieee80211_link_data *link = &sdata->deflink;
5960 struct ieee80211_rx_status *rx_status;
5961 struct ieee80211_mgmt *mgmt;
5965 rx_status = (struct ieee80211_rx_status *) skb->cb;
5966 mgmt = (struct ieee80211_mgmt *) skb->data;
5967 fc = le16_to_cpu(mgmt->frame_control);
5971 if (rx_status->link_valid) {
5972 link = sdata_dereference(sdata->link[rx_status->link_id],
5978 switch (fc & IEEE80211_FCTL_STYPE) {
5979 case IEEE80211_STYPE_BEACON:
5980 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
5981 skb->len, rx_status);
5983 case IEEE80211_STYPE_PROBE_RESP:
5984 ieee80211_rx_mgmt_probe_resp(link, skb);
5986 case IEEE80211_STYPE_AUTH:
5987 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
5989 case IEEE80211_STYPE_DEAUTH:
5990 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
5992 case IEEE80211_STYPE_DISASSOC:
5993 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
5995 case IEEE80211_STYPE_ASSOC_RESP:
5996 case IEEE80211_STYPE_REASSOC_RESP:
5997 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
5999 case IEEE80211_STYPE_ACTION:
6000 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
6001 struct ieee802_11_elems *elems;
6003 ies_len = skb->len -
6004 offsetof(struct ieee80211_mgmt,
6005 u.action.u.chan_switch.variable);
6010 /* CSA IE cannot be overridden, no need for BSSID */
6011 elems = ieee802_11_parse_elems(
6012 mgmt->u.action.u.chan_switch.variable,
6013 ies_len, true, NULL);
6015 if (elems && !elems->parse_error)
6016 ieee80211_sta_process_chanswitch(link,
6018 rx_status->device_timestamp,
6021 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
6022 struct ieee802_11_elems *elems;
6024 ies_len = skb->len -
6025 offsetof(struct ieee80211_mgmt,
6026 u.action.u.ext_chan_switch.variable);
6032 * extended CSA IE can't be overridden, no need for
6035 elems = ieee802_11_parse_elems(
6036 mgmt->u.action.u.ext_chan_switch.variable,
6037 ies_len, true, NULL);
6039 if (elems && !elems->parse_error) {
6040 /* for the handling code pretend it was an IE */
6041 elems->ext_chansw_ie =
6042 &mgmt->u.action.u.ext_chan_switch.data;
6044 ieee80211_sta_process_chanswitch(link,
6046 rx_status->device_timestamp,
6055 sdata_unlock(sdata);
6058 static void ieee80211_sta_timer(struct timer_list *t)
6060 struct ieee80211_sub_if_data *sdata =
6061 from_timer(sdata, t, u.mgd.timer);
6063 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
6066 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
6069 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6071 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
6074 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6078 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
6080 struct ieee80211_local *local = sdata->local;
6081 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6082 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
6086 struct ieee80211_prep_tx_info info = {
6087 .subtype = IEEE80211_STYPE_AUTH,
6090 sdata_assert_lock(sdata);
6092 if (WARN_ON_ONCE(!auth_data))
6097 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
6098 sdata_info(sdata, "authentication with %pM timed out\n",
6099 auth_data->ap_addr);
6102 * Most likely AP is not in the range so remove the
6103 * bss struct for that AP.
6105 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
6110 if (auth_data->algorithm == WLAN_AUTH_SAE)
6111 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
6113 drv_mgd_prepare_tx(local, sdata, &info);
6115 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
6116 auth_data->ap_addr, auth_data->tries,
6117 IEEE80211_AUTH_MAX_TRIES);
6119 auth_data->expected_transaction = 2;
6121 if (auth_data->algorithm == WLAN_AUTH_SAE) {
6122 trans = auth_data->sae_trans;
6123 status = auth_data->sae_status;
6124 auth_data->expected_transaction = trans;
6127 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6128 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
6129 IEEE80211_TX_INTFL_MLME_CONN_TX;
6131 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
6132 auth_data->data, auth_data->data_len,
6133 auth_data->ap_addr, auth_data->ap_addr,
6134 NULL, 0, 0, tx_flags);
6136 if (tx_flags == 0) {
6137 if (auth_data->algorithm == WLAN_AUTH_SAE)
6138 auth_data->timeout = jiffies +
6139 IEEE80211_AUTH_TIMEOUT_SAE;
6141 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
6143 auth_data->timeout =
6144 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
6147 auth_data->timeout_started = true;
6148 run_again(sdata, auth_data->timeout);
6153 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
6155 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
6156 struct ieee80211_local *local = sdata->local;
6159 sdata_assert_lock(sdata);
6161 assoc_data->tries++;
6162 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
6163 sdata_info(sdata, "association with %pM timed out\n",
6164 assoc_data->ap_addr);
6167 * Most likely AP is not in the range so remove the
6168 * bss struct for that AP.
6170 cfg80211_unlink_bss(local->hw.wiphy,
6171 assoc_data->link[assoc_data->assoc_link_id].bss);
6176 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
6177 assoc_data->ap_addr, assoc_data->tries,
6178 IEEE80211_ASSOC_MAX_TRIES);
6179 ret = ieee80211_send_assoc(sdata);
6183 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6184 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
6185 assoc_data->timeout_started = true;
6186 run_again(sdata, assoc_data->timeout);
6188 assoc_data->timeout =
6189 round_jiffies_up(jiffies +
6190 IEEE80211_ASSOC_TIMEOUT_LONG);
6191 assoc_data->timeout_started = true;
6192 run_again(sdata, assoc_data->timeout);
6198 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
6199 __le16 fc, bool acked)
6201 struct ieee80211_local *local = sdata->local;
6203 sdata->u.mgd.status_fc = fc;
6204 sdata->u.mgd.status_acked = acked;
6205 sdata->u.mgd.status_received = true;
6207 wiphy_work_queue(local->hw.wiphy, &sdata->work);
6210 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
6212 struct ieee80211_local *local = sdata->local;
6213 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6217 if (ifmgd->status_received) {
6218 __le16 fc = ifmgd->status_fc;
6219 bool status_acked = ifmgd->status_acked;
6221 ifmgd->status_received = false;
6222 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
6224 if (ifmgd->auth_data->algorithm ==
6226 ifmgd->auth_data->timeout =
6228 IEEE80211_AUTH_TIMEOUT_SAE;
6230 ifmgd->auth_data->timeout =
6232 IEEE80211_AUTH_TIMEOUT_SHORT;
6233 run_again(sdata, ifmgd->auth_data->timeout);
6235 ifmgd->auth_data->timeout = jiffies - 1;
6237 ifmgd->auth_data->timeout_started = true;
6238 } else if (ifmgd->assoc_data &&
6239 (ieee80211_is_assoc_req(fc) ||
6240 ieee80211_is_reassoc_req(fc))) {
6242 ifmgd->assoc_data->timeout =
6243 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
6244 run_again(sdata, ifmgd->assoc_data->timeout);
6246 ifmgd->assoc_data->timeout = jiffies - 1;
6248 ifmgd->assoc_data->timeout_started = true;
6252 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
6253 time_after(jiffies, ifmgd->auth_data->timeout)) {
6254 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
6256 * ok ... we waited for assoc or continuation but
6257 * userspace didn't do it, so kill the auth data
6259 ieee80211_destroy_auth_data(sdata, false);
6260 } else if (ieee80211_auth(sdata)) {
6261 u8 ap_addr[ETH_ALEN];
6262 struct ieee80211_event event = {
6264 .u.mlme.data = AUTH_EVENT,
6265 .u.mlme.status = MLME_TIMEOUT,
6268 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
6270 ieee80211_destroy_auth_data(sdata, false);
6272 cfg80211_auth_timeout(sdata->dev, ap_addr);
6273 drv_event_callback(sdata->local, sdata, &event);
6275 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
6276 run_again(sdata, ifmgd->auth_data->timeout);
6278 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
6279 time_after(jiffies, ifmgd->assoc_data->timeout)) {
6280 if ((ifmgd->assoc_data->need_beacon &&
6281 !sdata->deflink.u.mgd.have_beacon) ||
6282 ieee80211_do_assoc(sdata)) {
6283 struct ieee80211_event event = {
6285 .u.mlme.data = ASSOC_EVENT,
6286 .u.mlme.status = MLME_TIMEOUT,
6289 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6290 drv_event_callback(sdata->local, sdata, &event);
6292 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
6293 run_again(sdata, ifmgd->assoc_data->timeout);
6295 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
6296 ifmgd->associated) {
6297 u8 *bssid = sdata->deflink.u.mgd.bssid;
6300 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6301 max_tries = max_nullfunc_tries;
6303 max_tries = max_probe_tries;
6305 /* ACK received for nullfunc probing frame */
6306 if (!ifmgd->probe_send_count)
6307 ieee80211_reset_ap_probe(sdata);
6308 else if (ifmgd->nullfunc_failed) {
6309 if (ifmgd->probe_send_count < max_tries) {
6311 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
6312 bssid, ifmgd->probe_send_count,
6314 ieee80211_mgd_probe_ap_send(sdata);
6317 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
6319 ieee80211_sta_connection_lost(sdata,
6320 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
6323 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
6324 run_again(sdata, ifmgd->probe_timeout);
6325 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6327 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
6328 bssid, probe_wait_ms);
6329 ieee80211_sta_connection_lost(sdata,
6330 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6331 } else if (ifmgd->probe_send_count < max_tries) {
6333 "No probe response from AP %pM after %dms, try %d/%i\n",
6334 bssid, probe_wait_ms,
6335 ifmgd->probe_send_count, max_tries);
6336 ieee80211_mgd_probe_ap_send(sdata);
6339 * We actually lost the connection ... or did we?
6343 "No probe response from AP %pM after %dms, disconnecting.\n",
6344 bssid, probe_wait_ms);
6346 ieee80211_sta_connection_lost(sdata,
6347 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6351 sdata_unlock(sdata);
6354 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
6356 struct ieee80211_sub_if_data *sdata =
6357 from_timer(sdata, t, u.mgd.bcn_mon_timer);
6359 if (WARN_ON(sdata->vif.valid_links))
6362 if (sdata->vif.bss_conf.csa_active &&
6363 !sdata->deflink.u.mgd.csa_waiting_bcn)
6366 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
6369 sdata->u.mgd.connection_loss = false;
6370 wiphy_work_queue(sdata->local->hw.wiphy,
6371 &sdata->u.mgd.beacon_connection_loss_work);
6374 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
6376 struct ieee80211_sub_if_data *sdata =
6377 from_timer(sdata, t, u.mgd.conn_mon_timer);
6378 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6379 struct ieee80211_local *local = sdata->local;
6380 struct sta_info *sta;
6381 unsigned long timeout;
6383 if (WARN_ON(sdata->vif.valid_links))
6386 if (sdata->vif.bss_conf.csa_active &&
6387 !sdata->deflink.u.mgd.csa_waiting_bcn)
6390 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6394 timeout = sta->deflink.status_stats.last_ack;
6395 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
6396 timeout = sta->deflink.rx_stats.last_rx;
6397 timeout += IEEE80211_CONNECTION_IDLE_TIME;
6399 /* If timeout is after now, then update timer to fire at
6400 * the later date, but do not actually probe at this time.
6402 if (time_is_after_jiffies(timeout)) {
6403 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
6407 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
6410 static void ieee80211_sta_monitor_work(struct work_struct *work)
6412 struct ieee80211_sub_if_data *sdata =
6413 container_of(work, struct ieee80211_sub_if_data,
6414 u.mgd.monitor_work);
6416 ieee80211_mgd_probe_ap(sdata, false);
6419 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
6421 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
6422 __ieee80211_stop_poll(sdata);
6424 /* let's probe the connection once */
6425 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
6426 ieee80211_queue_work(&sdata->local->hw,
6427 &sdata->u.mgd.monitor_work);
6432 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
6434 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6435 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6439 if (ifmgd->auth_data || ifmgd->assoc_data) {
6440 const u8 *ap_addr = ifmgd->auth_data ?
6441 ifmgd->auth_data->ap_addr :
6442 ifmgd->assoc_data->ap_addr;
6445 * If we are trying to authenticate / associate while suspending,
6446 * cfg80211 won't know and won't actually abort those attempts,
6447 * thus we need to do that ourselves.
6449 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
6450 IEEE80211_STYPE_DEAUTH,
6451 WLAN_REASON_DEAUTH_LEAVING,
6453 if (ifmgd->assoc_data)
6454 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6455 if (ifmgd->auth_data)
6456 ieee80211_destroy_auth_data(sdata, false);
6457 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
6458 IEEE80211_DEAUTH_FRAME_LEN,
6462 /* This is a bit of a hack - we should find a better and more generic
6463 * solution to this. Normally when suspending, cfg80211 will in fact
6464 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
6465 * auth (not so important) or assoc (this is the problem) process.
6467 * As a consequence, it can happen that we are in the process of both
6468 * associating and suspending, and receive an association response
6469 * after cfg80211 has checked if it needs to disconnect, but before
6470 * we actually set the flag to drop incoming frames. This will then
6471 * cause the workqueue flush to process the association response in
6472 * the suspend, resulting in a successful association just before it
6473 * tries to remove the interface from the driver, which now though
6474 * has a channel context assigned ... this results in issues.
6476 * To work around this (for now) simply deauth here again if we're
6479 if (ifmgd->associated && !sdata->local->wowlan) {
6481 struct cfg80211_deauth_request req = {
6482 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
6486 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
6487 ieee80211_mgd_deauth(sdata, &req);
6490 sdata_unlock(sdata);
6494 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
6496 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6499 if (!ifmgd->associated) {
6500 sdata_unlock(sdata);
6504 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
6505 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
6506 mlme_dbg(sdata, "driver requested disconnect after resume\n");
6507 ieee80211_sta_connection_lost(sdata,
6508 WLAN_REASON_UNSPECIFIED,
6510 sdata_unlock(sdata);
6514 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
6515 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
6516 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
6517 ieee80211_sta_connection_lost(sdata,
6518 WLAN_REASON_UNSPECIFIED,
6520 sdata_unlock(sdata);
6524 sdata_unlock(sdata);
6527 static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy,
6528 struct wiphy_work *work)
6530 struct ieee80211_link_data *link =
6531 container_of(work, struct ieee80211_link_data,
6532 u.mgd.request_smps_work);
6534 sdata_lock(link->sdata);
6535 __ieee80211_request_smps_mgd(link->sdata, link,
6536 link->u.mgd.driver_smps_mode);
6537 sdata_unlock(link->sdata);
6540 /* interface setup */
6541 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
6543 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6545 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
6546 wiphy_work_init(&ifmgd->beacon_connection_loss_work,
6547 ieee80211_beacon_connection_loss_work);
6548 wiphy_work_init(&ifmgd->csa_connection_drop_work,
6549 ieee80211_csa_connection_drop_work);
6550 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
6551 ieee80211_tdls_peer_del_work);
6552 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
6553 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
6554 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
6555 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
6556 ieee80211_sta_handle_tspec_ac_params_wk);
6559 ifmgd->powersave = sdata->wdev.ps;
6560 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
6561 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
6562 /* Setup TDLS data */
6563 spin_lock_init(&ifmgd->teardown_lock);
6564 ifmgd->teardown_skb = NULL;
6565 ifmgd->orig_teardown_skb = NULL;
6568 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
6570 struct ieee80211_sub_if_data *sdata = link->sdata;
6571 struct ieee80211_local *local = sdata->local;
6572 unsigned int link_id = link->link_id;
6574 link->u.mgd.p2p_noa_index = -1;
6575 link->u.mgd.conn_flags = 0;
6576 link->conf->bssid = link->u.mgd.bssid;
6578 wiphy_work_init(&link->u.mgd.request_smps_work,
6579 ieee80211_request_smps_mgd_work);
6580 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
6581 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
6583 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
6585 wiphy_delayed_work_init(&link->u.mgd.chswitch_work,
6586 ieee80211_chswitch_work);
6588 if (sdata->u.mgd.assoc_data)
6589 ether_addr_copy(link->conf->addr,
6590 sdata->u.mgd.assoc_data->link[link_id].addr);
6591 else if (!is_valid_ether_addr(link->conf->addr))
6592 eth_random_addr(link->conf->addr);
6595 /* scan finished notification */
6596 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
6598 struct ieee80211_sub_if_data *sdata;
6600 /* Restart STA timers */
6602 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
6603 if (ieee80211_sdata_running(sdata))
6604 ieee80211_restart_sta_timer(sdata);
6609 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
6610 struct cfg80211_bss *cbss, s8 link_id,
6611 const u8 *ap_mld_addr, bool assoc,
6614 struct ieee80211_local *local = sdata->local;
6615 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6616 struct ieee80211_bss *bss = (void *)cbss->priv;
6617 struct sta_info *new_sta = NULL;
6618 struct ieee80211_link_data *link;
6619 bool have_sta = false;
6625 if (WARN_ON(!ap_mld_addr))
6627 err = ieee80211_vif_set_links(sdata, BIT(link_id));
6629 if (WARN_ON(ap_mld_addr))
6631 ap_mld_addr = cbss->bssid;
6632 err = ieee80211_vif_set_links(sdata, 0);
6640 link = sdata_dereference(sdata->link[link_id], sdata);
6641 if (WARN_ON(!link)) {
6646 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
6651 /* If a reconfig is happening, bail out */
6652 if (local->in_reconfig) {
6659 have_sta = sta_info_get(sdata, ap_mld_addr);
6665 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
6666 link_id, cbss->bssid,
6669 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
6676 new_sta->sta.mlo = mlo;
6680 * Set up the information for the new channel before setting the
6681 * new channel. We can't - completely race-free - change the basic
6682 * rates bitmap and the channel (sband) that it refers to, but if
6683 * we set it up before we at least avoid calling into the driver's
6684 * bss_info_changed() method with invalid information (since we do
6685 * call that from changing the channel - only for IDLE and perhaps
6686 * some others, but ...).
6688 * So to avoid that, just set up all the new information before the
6689 * channel, but tell the driver to apply it only afterwards, since
6690 * it might need the new channel for that.
6693 const struct cfg80211_bss_ies *ies;
6694 struct link_sta_info *link_sta;
6697 link_sta = rcu_dereference(new_sta->link[link_id]);
6698 if (WARN_ON(!link_sta)) {
6700 sta_info_free(local, new_sta);
6705 err = ieee80211_mgd_setup_link_sta(link, new_sta,
6709 sta_info_free(local, new_sta);
6713 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
6715 /* set timing information */
6716 link->conf->beacon_int = cbss->beacon_interval;
6717 ies = rcu_dereference(cbss->beacon_ies);
6719 link->conf->sync_tsf = ies->tsf;
6720 link->conf->sync_device_ts =
6721 bss->device_ts_beacon;
6723 ieee80211_get_dtim(ies,
6724 &link->conf->sync_dtim_count,
6726 } else if (!ieee80211_hw_check(&sdata->local->hw,
6727 TIMING_BEACON_ONLY)) {
6728 ies = rcu_dereference(cbss->proberesp_ies);
6729 /* must be non-NULL since beacon IEs were NULL */
6730 link->conf->sync_tsf = ies->tsf;
6731 link->conf->sync_device_ts =
6732 bss->device_ts_presp;
6733 link->conf->sync_dtim_count = 0;
6735 link->conf->sync_tsf = 0;
6736 link->conf->sync_device_ts = 0;
6737 link->conf->sync_dtim_count = 0;
6742 if (new_sta || override) {
6743 err = ieee80211_prep_channel(sdata, link, cbss,
6744 &link->u.mgd.conn_flags);
6747 sta_info_free(local, new_sta);
6754 * tell driver about BSSID, basic rates and timing
6755 * this was set up above, before setting the channel
6757 ieee80211_link_info_change_notify(sdata, link,
6759 BSS_CHANGED_BASIC_RATES |
6760 BSS_CHANGED_BEACON_INT);
6763 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
6765 err = sta_info_insert(new_sta);
6769 "failed to insert STA entry for the AP (error %d)\n",
6774 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
6776 /* Cancel scan to ensure that nothing interferes with connection */
6777 if (local->scanning)
6778 ieee80211_scan_cancel(local);
6783 ieee80211_link_release_channel(&sdata->deflink);
6784 ieee80211_vif_set_links(sdata, 0);
6789 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
6790 struct cfg80211_auth_request *req)
6792 struct ieee80211_local *local = sdata->local;
6793 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6794 struct ieee80211_mgd_auth_data *auth_data;
6799 /* prepare auth data structure */
6801 switch (req->auth_type) {
6802 case NL80211_AUTHTYPE_OPEN_SYSTEM:
6803 auth_alg = WLAN_AUTH_OPEN;
6805 case NL80211_AUTHTYPE_SHARED_KEY:
6808 auth_alg = WLAN_AUTH_SHARED_KEY;
6810 case NL80211_AUTHTYPE_FT:
6811 auth_alg = WLAN_AUTH_FT;
6813 case NL80211_AUTHTYPE_NETWORK_EAP:
6814 auth_alg = WLAN_AUTH_LEAP;
6816 case NL80211_AUTHTYPE_SAE:
6817 auth_alg = WLAN_AUTH_SAE;
6819 case NL80211_AUTHTYPE_FILS_SK:
6820 auth_alg = WLAN_AUTH_FILS_SK;
6822 case NL80211_AUTHTYPE_FILS_SK_PFS:
6823 auth_alg = WLAN_AUTH_FILS_SK_PFS;
6825 case NL80211_AUTHTYPE_FILS_PK:
6826 auth_alg = WLAN_AUTH_FILS_PK;
6832 if (ifmgd->assoc_data)
6835 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
6836 req->ie_len, GFP_KERNEL);
6840 memcpy(auth_data->ap_addr,
6841 req->ap_mld_addr ?: req->bss->bssid,
6843 auth_data->bss = req->bss;
6844 auth_data->link_id = req->link_id;
6846 if (req->auth_data_len >= 4) {
6847 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
6848 __le16 *pos = (__le16 *) req->auth_data;
6850 auth_data->sae_trans = le16_to_cpu(pos[0]);
6851 auth_data->sae_status = le16_to_cpu(pos[1]);
6853 memcpy(auth_data->data, req->auth_data + 4,
6854 req->auth_data_len - 4);
6855 auth_data->data_len += req->auth_data_len - 4;
6858 /* Check if continuing authentication or trying to authenticate with the
6859 * same BSS that we were in the process of authenticating with and avoid
6860 * removal and re-addition of the STA entry in
6861 * ieee80211_prep_connection().
6863 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
6864 ifmgd->auth_data->link_id == req->link_id;
6866 if (req->ie && req->ie_len) {
6867 memcpy(&auth_data->data[auth_data->data_len],
6868 req->ie, req->ie_len);
6869 auth_data->data_len += req->ie_len;
6872 if (req->key && req->key_len) {
6873 auth_data->key_len = req->key_len;
6874 auth_data->key_idx = req->key_idx;
6875 memcpy(auth_data->key, req->key, req->key_len);
6878 auth_data->algorithm = auth_alg;
6880 /* try to authenticate/probe */
6882 if (ifmgd->auth_data) {
6883 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
6884 auth_data->peer_confirmed =
6885 ifmgd->auth_data->peer_confirmed;
6887 ieee80211_destroy_auth_data(sdata, cont_auth);
6890 /* prep auth_data so we don't go into idle on disassoc */
6891 ifmgd->auth_data = auth_data;
6893 /* If this is continuation of an ongoing SAE authentication exchange
6894 * (i.e., request to send SAE Confirm) and the peer has already
6895 * confirmed, mark authentication completed since we are about to send
6898 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
6899 auth_data->peer_confirmed && auth_data->sae_trans == 2)
6900 ieee80211_mark_sta_auth(sdata);
6902 if (ifmgd->associated) {
6903 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6906 "disconnect from AP %pM for new auth to %pM\n",
6907 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
6908 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6909 WLAN_REASON_UNSPECIFIED,
6912 ieee80211_report_disconnect(sdata, frame_buf,
6913 sizeof(frame_buf), true,
6914 WLAN_REASON_UNSPECIFIED,
6918 sdata_info(sdata, "authenticate with %pM\n", auth_data->ap_addr);
6920 /* needed for transmitting the auth frame(s) properly */
6921 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
6923 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
6924 req->ap_mld_addr, cont_auth, false);
6928 err = ieee80211_auth(sdata);
6930 sta_info_destroy_addr(sdata, auth_data->ap_addr);
6934 /* hold our own reference */
6935 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
6939 if (!sdata->vif.valid_links) {
6940 eth_zero_addr(sdata->deflink.u.mgd.bssid);
6941 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
6943 mutex_lock(&sdata->local->mtx);
6944 ieee80211_link_release_channel(&sdata->deflink);
6945 mutex_unlock(&sdata->local->mtx);
6947 ifmgd->auth_data = NULL;
6952 static ieee80211_conn_flags_t
6953 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
6954 struct ieee80211_mgd_assoc_data *assoc_data,
6955 struct cfg80211_assoc_request *req,
6956 ieee80211_conn_flags_t conn_flags,
6957 unsigned int link_id)
6959 struct ieee80211_local *local = sdata->local;
6960 const struct cfg80211_bss_ies *beacon_ies;
6961 struct ieee80211_supported_band *sband;
6962 const struct element *ht_elem, *vht_elem;
6963 struct ieee80211_link_data *link;
6964 struct cfg80211_bss *cbss;
6965 struct ieee80211_bss *bss;
6966 bool is_5ghz, is_6ghz;
6968 cbss = assoc_data->link[link_id].bss;
6972 bss = (void *)cbss->priv;
6974 sband = local->hw.wiphy->bands[cbss->channel->band];
6975 if (WARN_ON(!sband))
6978 link = sdata_dereference(sdata->link[link_id], sdata);
6982 is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
6983 is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
6985 /* for MLO connections assume advertising all rates is OK */
6986 if (!req->ap_mld_addr) {
6987 assoc_data->supp_rates = bss->supp_rates;
6988 assoc_data->supp_rates_len = bss->supp_rates_len;
6991 /* copy and link elems for the STA profile */
6992 if (req->links[link_id].elems_len) {
6993 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
6994 req->links[link_id].elems_len);
6995 assoc_data->link[link_id].elems = assoc_data->ie_pos;
6996 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
6997 assoc_data->ie_pos += req->links[link_id].elems_len;
7001 ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
7002 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
7003 assoc_data->link[link_id].ap_ht_param =
7004 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
7006 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7007 vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
7008 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
7009 memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
7010 sizeof(struct ieee80211_vht_cap));
7011 } else if (is_5ghz) {
7013 "VHT capa missing/short, disabling VHT/HE/EHT\n");
7014 conn_flags |= IEEE80211_CONN_DISABLE_VHT |
7015 IEEE80211_CONN_DISABLE_HE |
7016 IEEE80211_CONN_DISABLE_EHT;
7020 link->u.mgd.beacon_crc_valid = false;
7021 link->u.mgd.dtim_period = 0;
7022 link->u.mgd.have_beacon = false;
7024 /* override HT/VHT configuration only if the AP and we support it */
7025 if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
7026 struct ieee80211_sta_ht_cap sta_ht_cap;
7028 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
7029 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
7032 link->conf->eht_puncturing = 0;
7035 beacon_ies = rcu_dereference(cbss->beacon_ies);
7037 const struct ieee80211_eht_operation *eht_oper;
7038 const struct element *elem;
7041 ieee80211_get_dtim(beacon_ies, &dtim_count,
7042 &link->u.mgd.dtim_period);
7044 sdata->deflink.u.mgd.have_beacon = true;
7046 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
7047 link->conf->sync_tsf = beacon_ies->tsf;
7048 link->conf->sync_device_ts = bss->device_ts_beacon;
7049 link->conf->sync_dtim_count = dtim_count;
7052 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
7053 beacon_ies->data, beacon_ies->len);
7054 if (elem && elem->datalen >= 3)
7055 link->conf->profile_periodicity = elem->data[2];
7057 link->conf->profile_periodicity = 0;
7059 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
7060 beacon_ies->data, beacon_ies->len);
7061 if (elem && elem->datalen >= 11 &&
7062 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
7063 link->conf->ema_ap = true;
7065 link->conf->ema_ap = false;
7067 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION,
7068 beacon_ies->data, beacon_ies->len);
7069 eht_oper = (const void *)(elem->data + 1);
7072 ieee80211_eht_oper_size_ok((const void *)(elem->data + 1),
7073 elem->datalen - 1) &&
7074 (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
7075 (eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
7076 const struct ieee80211_eht_operation_info *info =
7077 (void *)eht_oper->optional;
7078 const u8 *disable_subchannel_bitmap = info->optional;
7081 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
7082 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
7083 &link->conf->chandef))
7084 ieee80211_handle_puncturing_bitmap(link,
7089 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7094 if (bss->corrupt_data) {
7095 char *corrupt_type = "data";
7097 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
7098 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
7099 corrupt_type = "beacon and probe response";
7101 corrupt_type = "beacon";
7102 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
7103 corrupt_type = "probe response";
7105 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
7106 cbss->bssid, corrupt_type);
7109 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
7110 if (sdata->u.mgd.powersave)
7111 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
7113 link->smps_mode = IEEE80211_SMPS_OFF;
7115 link->smps_mode = link->u.mgd.req_smps;
7121 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
7122 struct cfg80211_assoc_request *req)
7124 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
7125 struct ieee80211_local *local = sdata->local;
7126 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7127 struct ieee80211_mgd_assoc_data *assoc_data;
7128 const struct element *ssid_elem;
7129 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
7130 ieee80211_conn_flags_t conn_flags = 0;
7131 struct ieee80211_link_data *link;
7132 struct cfg80211_bss *cbss;
7133 struct ieee80211_bss *bss;
7136 size_t size = sizeof(*assoc_data) + req->ie_len;
7138 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
7139 size += req->links[i].elems_len;
7141 /* FIXME: no support for 4-addr MLO yet */
7142 if (sdata->u.mgd.use_4addr && req->link_id >= 0)
7145 assoc_data = kzalloc(size, GFP_KERNEL);
7149 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
7152 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
7153 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
7158 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
7159 assoc_data->ssid_len = ssid_elem->datalen;
7160 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
7161 vif_cfg->ssid_len = assoc_data->ssid_len;
7164 if (req->ap_mld_addr) {
7165 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
7166 if (!req->links[i].bss)
7168 link = sdata_dereference(sdata->link[i], sdata);
7170 ether_addr_copy(assoc_data->link[i].addr,
7173 eth_random_addr(assoc_data->link[i].addr);
7176 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
7179 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
7181 memcpy(assoc_data->ap_addr,
7182 req->ap_mld_addr ?: req->bss->bssid,
7185 if (ifmgd->associated) {
7186 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7189 "disconnect from AP %pM for new assoc to %pM\n",
7190 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
7191 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7192 WLAN_REASON_UNSPECIFIED,
7195 ieee80211_report_disconnect(sdata, frame_buf,
7196 sizeof(frame_buf), true,
7197 WLAN_REASON_UNSPECIFIED,
7201 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
7206 if (ifmgd->assoc_data) {
7211 if (ifmgd->auth_data) {
7214 /* keep sta info, bssid if matching */
7215 match = ether_addr_equal(ifmgd->auth_data->ap_addr,
7216 assoc_data->ap_addr) &&
7217 ifmgd->auth_data->link_id == req->link_id;
7218 ieee80211_destroy_auth_data(sdata, match);
7221 /* prepare assoc data */
7223 bss = (void *)cbss->priv;
7224 assoc_data->wmm = bss->wmm_used &&
7225 (local->hw.queues >= IEEE80211_NUM_ACS);
7228 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
7229 * We still associate in non-HT mode (11a/b/g) if any one of these
7230 * ciphers is configured as pairwise.
7231 * We can set this to true for non-11n hardware, that'll be checked
7232 * separately along with the peer capabilities.
7234 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
7235 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
7236 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
7237 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
7238 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7239 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7240 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7241 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7242 netdev_info(sdata->dev,
7243 "disabling HT/VHT/HE due to WEP/TKIP use\n");
7247 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
7248 if (!bss->wmm_used) {
7249 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7250 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7251 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7252 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7253 netdev_info(sdata->dev,
7254 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
7257 if (req->flags & ASSOC_REQ_DISABLE_HT) {
7258 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
7259 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7260 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7261 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7262 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7265 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
7266 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
7267 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7270 if (req->flags & ASSOC_REQ_DISABLE_HE) {
7271 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
7272 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7273 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7276 if (req->flags & ASSOC_REQ_DISABLE_EHT)
7277 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7279 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
7280 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
7281 sizeof(ifmgd->ht_capa_mask));
7283 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
7284 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
7285 sizeof(ifmgd->vht_capa_mask));
7287 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
7288 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
7289 sizeof(ifmgd->s1g_capa_mask));
7291 if (req->ie && req->ie_len) {
7292 memcpy(assoc_data->ie, req->ie, req->ie_len);
7293 assoc_data->ie_len = req->ie_len;
7294 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
7296 assoc_data->ie_pos = assoc_data->ie;
7299 if (req->fils_kek) {
7300 /* should already be checked in cfg80211 - so warn */
7301 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
7305 memcpy(assoc_data->fils_kek, req->fils_kek,
7307 assoc_data->fils_kek_len = req->fils_kek_len;
7310 if (req->fils_nonces)
7311 memcpy(assoc_data->fils_nonces, req->fils_nonces,
7312 2 * FILS_NONCE_LEN);
7314 /* default timeout */
7315 assoc_data->timeout = jiffies;
7316 assoc_data->timeout_started = true;
7318 assoc_data->assoc_link_id = assoc_link_id;
7320 if (req->ap_mld_addr) {
7321 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7322 assoc_data->link[i].conn_flags = conn_flags;
7323 assoc_data->link[i].bss = req->links[i].bss;
7326 /* if there was no authentication, set up the link */
7327 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id));
7331 assoc_data->link[0].conn_flags = conn_flags;
7332 assoc_data->link[0].bss = cbss;
7335 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
7336 if (WARN_ON(!link)) {
7341 /* keep old conn_flags from ieee80211_prep_channel() from auth */
7342 conn_flags |= link->u.mgd.conn_flags;
7343 conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
7344 conn_flags, assoc_link_id);
7345 override = link->u.mgd.conn_flags != conn_flags;
7346 link->u.mgd.conn_flags |= conn_flags;
7348 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
7349 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
7350 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
7351 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
7353 if (bss->wmm_used && bss->uapsd_supported &&
7354 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
7355 assoc_data->uapsd = true;
7356 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
7358 assoc_data->uapsd = false;
7359 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
7362 if (req->prev_bssid)
7363 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
7366 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
7367 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
7369 ifmgd->mfp = IEEE80211_MFP_DISABLED;
7370 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
7373 if (req->flags & ASSOC_REQ_USE_RRM)
7374 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
7376 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
7378 if (req->crypto.control_port)
7379 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
7381 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
7383 sdata->control_port_protocol = req->crypto.control_port_ethertype;
7384 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
7385 sdata->control_port_over_nl80211 =
7386 req->crypto.control_port_over_nl80211;
7387 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
7389 /* kick off associate process */
7390 ifmgd->assoc_data = assoc_data;
7392 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7393 if (!assoc_data->link[i].bss)
7395 if (i == assoc_data->assoc_link_id)
7397 /* only calculate the flags, hence link == NULL */
7398 err = ieee80211_prep_channel(sdata, NULL, assoc_data->link[i].bss,
7399 &assoc_data->link[i].conn_flags);
7404 /* needed for transmitting the assoc frames properly */
7405 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
7407 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
7408 req->ap_mld_addr, true, override);
7412 assoc_data->link[assoc_data->assoc_link_id].conn_flags =
7413 link->u.mgd.conn_flags;
7415 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
7416 const struct cfg80211_bss_ies *beacon_ies;
7419 beacon_ies = rcu_dereference(req->bss->beacon_ies);
7423 * Wait up to one beacon interval ...
7424 * should this be more if we miss one?
7426 sdata_info(sdata, "waiting for beacon from %pM\n",
7428 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
7429 assoc_data->timeout_started = true;
7430 assoc_data->need_beacon = true;
7435 run_again(sdata, assoc_data->timeout);
7439 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7440 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7442 ifmgd->assoc_data = NULL;
7448 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
7449 struct cfg80211_deauth_request *req)
7451 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7452 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7453 bool tx = !req->local_state_change;
7454 struct ieee80211_prep_tx_info info = {
7455 .subtype = IEEE80211_STYPE_DEAUTH,
7458 if (ifmgd->auth_data &&
7459 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
7461 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
7462 req->bssid, req->reason_code,
7463 ieee80211_get_reason_code_string(req->reason_code));
7465 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7466 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7467 IEEE80211_STYPE_DEAUTH,
7468 req->reason_code, tx,
7470 ieee80211_destroy_auth_data(sdata, false);
7471 ieee80211_report_disconnect(sdata, frame_buf,
7472 sizeof(frame_buf), true,
7473 req->reason_code, false);
7474 drv_mgd_complete_tx(sdata->local, sdata, &info);
7478 if (ifmgd->assoc_data &&
7479 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
7481 "aborting association with %pM by local choice (Reason: %u=%s)\n",
7482 req->bssid, req->reason_code,
7483 ieee80211_get_reason_code_string(req->reason_code));
7485 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7486 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7487 IEEE80211_STYPE_DEAUTH,
7488 req->reason_code, tx,
7490 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
7491 ieee80211_report_disconnect(sdata, frame_buf,
7492 sizeof(frame_buf), true,
7493 req->reason_code, false);
7497 if (ifmgd->associated &&
7498 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
7500 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
7501 req->bssid, req->reason_code,
7502 ieee80211_get_reason_code_string(req->reason_code));
7504 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7505 req->reason_code, tx, frame_buf);
7506 ieee80211_report_disconnect(sdata, frame_buf,
7507 sizeof(frame_buf), true,
7508 req->reason_code, false);
7509 drv_mgd_complete_tx(sdata->local, sdata, &info);
7516 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
7517 struct cfg80211_disassoc_request *req)
7519 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7521 if (!sdata->u.mgd.associated ||
7522 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
7526 "disassociating from %pM by local choice (Reason: %u=%s)\n",
7527 req->ap_addr, req->reason_code,
7528 ieee80211_get_reason_code_string(req->reason_code));
7530 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
7531 req->reason_code, !req->local_state_change,
7534 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
7535 req->reason_code, false);
7540 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
7542 wiphy_work_cancel(link->sdata->local->hw.wiphy,
7543 &link->u.mgd.request_smps_work);
7544 wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy,
7545 &link->u.mgd.chswitch_work);
7548 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
7550 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7553 * Make sure some work items will not run after this,
7554 * they will not do anything but might not have been
7555 * cancelled when disconnecting.
7557 cancel_work_sync(&ifmgd->monitor_work);
7558 wiphy_work_cancel(sdata->local->hw.wiphy,
7559 &ifmgd->beacon_connection_loss_work);
7560 wiphy_work_cancel(sdata->local->hw.wiphy,
7561 &ifmgd->csa_connection_drop_work);
7562 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
7565 if (ifmgd->assoc_data)
7566 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
7567 if (ifmgd->auth_data)
7568 ieee80211_destroy_auth_data(sdata, false);
7569 spin_lock_bh(&ifmgd->teardown_lock);
7570 if (ifmgd->teardown_skb) {
7571 kfree_skb(ifmgd->teardown_skb);
7572 ifmgd->teardown_skb = NULL;
7573 ifmgd->orig_teardown_skb = NULL;
7575 kfree(ifmgd->assoc_req_ies);
7576 ifmgd->assoc_req_ies = NULL;
7577 ifmgd->assoc_req_ies_len = 0;
7578 spin_unlock_bh(&ifmgd->teardown_lock);
7579 del_timer_sync(&ifmgd->timer);
7580 sdata_unlock(sdata);
7583 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
7584 enum nl80211_cqm_rssi_threshold_event rssi_event,
7588 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7590 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
7592 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
7594 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
7596 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
7598 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7600 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
7602 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
7604 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
7606 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
7610 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
7612 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
7616 * Scale up threshold values before storing it, as the RSSI averaging
7617 * algorithm uses a scaled up value as well. Change this scaling
7618 * factor if the RSSI averaging algorithm changes.
7620 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
7621 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
7624 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
7628 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7630 WARN_ON(rssi_min_thold == rssi_max_thold ||
7631 rssi_min_thold > rssi_max_thold);
7633 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
7636 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
7638 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
7640 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7642 _ieee80211_enable_rssi_reports(sdata, 0, 0);
7644 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);