1 // SPDX-License-Identifier: GPL-2.0-only
3 * BSS client mode implementation
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright (C) 2018 - 2024 Intel Corporation
14 #include <linux/delay.h>
15 #include <linux/fips.h>
16 #include <linux/if_ether.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 #include <linux/moduleparam.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/crc32.h>
23 #include <linux/slab.h>
24 #include <linux/export.h>
25 #include <net/mac80211.h>
26 #include <linux/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
32 #include "fils_aead.h"
34 #include <kunit/static_stub.h>
36 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
37 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
38 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
39 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
40 #define IEEE80211_AUTH_MAX_TRIES 3
41 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
42 #define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2)
43 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
44 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
45 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
46 #define IEEE80211_ASSOC_MAX_TRIES 3
48 #define IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS msecs_to_jiffies(100)
49 #define IEEE80211_ADV_TTLM_ST_UNDERFLOW 0xff00
51 #define IEEE80211_NEG_TTLM_REQ_TIMEOUT (HZ / 5)
53 static int max_nullfunc_tries = 2;
54 module_param(max_nullfunc_tries, int, 0644);
55 MODULE_PARM_DESC(max_nullfunc_tries,
56 "Maximum nullfunc tx tries before disconnecting (reason 4).");
58 static int max_probe_tries = 5;
59 module_param(max_probe_tries, int, 0644);
60 MODULE_PARM_DESC(max_probe_tries,
61 "Maximum probe tries before disconnecting (reason 4).");
64 * Beacon loss timeout is calculated as N frames times the
65 * advertised beacon interval. This may need to be somewhat
66 * higher than what hardware might detect to account for
67 * delays in the host processing frames. But since we also
68 * probe on beacon miss before declaring the connection lost
69 * default to what we want.
71 static int beacon_loss_count = 7;
72 module_param(beacon_loss_count, int, 0644);
73 MODULE_PARM_DESC(beacon_loss_count,
74 "Number of beacon intervals before we decide beacon was lost.");
77 * Time the connection can be idle before we probe
78 * it to see if we can still talk to the AP.
80 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
82 * Time we wait for a probe response after sending
83 * a probe request because of beacon loss or for
84 * checking the connection still works.
86 static int probe_wait_ms = 500;
87 module_param(probe_wait_ms, int, 0644);
88 MODULE_PARM_DESC(probe_wait_ms,
89 "Maximum time(ms) to wait for probe response"
90 " before disconnecting (reason 4).");
93 * How many Beacon frames need to have been used in average signal strength
94 * before starting to indicate signal change events.
96 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
99 * We can have multiple work items (and connection probing)
100 * scheduling this timer, but we need to take care to only
101 * reschedule it when it should fire _earlier_ than it was
102 * asked for before, or if it's not pending right now. This
103 * function ensures that. Note that it then is required to
104 * run this function for all timeouts after the first one
105 * has happened -- the work that runs from this timer will
108 static void run_again(struct ieee80211_sub_if_data *sdata,
109 unsigned long timeout)
111 lockdep_assert_wiphy(sdata->local->hw.wiphy);
113 if (!timer_pending(&sdata->u.mgd.timer) ||
114 time_before(timeout, sdata->u.mgd.timer.expires))
115 mod_timer(&sdata->u.mgd.timer, timeout);
118 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
120 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
123 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
126 mod_timer(&sdata->u.mgd.bcn_mon_timer,
127 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
130 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
132 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
134 if (unlikely(!ifmgd->associated))
137 if (ifmgd->probe_send_count)
138 ifmgd->probe_send_count = 0;
140 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
143 mod_timer(&ifmgd->conn_mon_timer,
144 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
147 static int ecw2cw(int ecw)
149 return (1 << ecw) - 1;
152 static enum ieee80211_conn_mode
153 ieee80211_determine_ap_chan(struct ieee80211_sub_if_data *sdata,
154 struct ieee80211_channel *channel,
156 const struct ieee802_11_elems *elems,
157 bool ignore_ht_channel_mismatch,
158 const struct ieee80211_conn_settings *conn,
159 struct cfg80211_chan_def *chandef)
161 const struct ieee80211_ht_operation *ht_oper = elems->ht_operation;
162 const struct ieee80211_vht_operation *vht_oper = elems->vht_operation;
163 const struct ieee80211_he_operation *he_oper = elems->he_operation;
164 const struct ieee80211_eht_operation *eht_oper = elems->eht_operation;
165 struct ieee80211_supported_band *sband =
166 sdata->local->hw.wiphy->bands[channel->band];
167 struct cfg80211_chan_def vht_chandef;
171 *chandef = (struct cfg80211_chan_def) {
173 .width = NL80211_CHAN_WIDTH_20_NOHT,
174 .center_freq1 = channel->center_freq,
175 .freq1_offset = channel->freq_offset,
178 /* get special S1G case out of the way */
179 if (sband->band == NL80211_BAND_S1GHZ) {
180 if (!ieee80211_chandef_s1g_oper(elems->s1g_oper, chandef)) {
182 "Missing S1G Operation Element? Trying operating == primary\n");
183 chandef->width = ieee80211_s1g_channel_width(channel);
186 return IEEE80211_CONN_MODE_S1G;
189 /* get special 6 GHz case out of the way */
190 if (sband->band == NL80211_BAND_6GHZ) {
191 enum ieee80211_conn_mode mode = IEEE80211_CONN_MODE_EHT;
193 /* this is an error */
194 if (conn->mode < IEEE80211_CONN_MODE_HE)
195 return IEEE80211_CONN_MODE_LEGACY;
197 if (!elems->he_6ghz_capa || !elems->he_cap) {
199 "HE 6 GHz AP is missing HE/HE 6 GHz band capability\n");
200 return IEEE80211_CONN_MODE_LEGACY;
203 if (!eht_oper || !elems->eht_cap) {
205 mode = IEEE80211_CONN_MODE_HE;
208 if (!ieee80211_chandef_he_6ghz_oper(sdata->local, he_oper,
209 eht_oper, chandef)) {
210 sdata_info(sdata, "bad HE/EHT 6 GHz operation\n");
211 return IEEE80211_CONN_MODE_LEGACY;
217 /* now we have the progression HT, VHT, ... */
218 if (conn->mode < IEEE80211_CONN_MODE_HT)
219 return IEEE80211_CONN_MODE_LEGACY;
221 if (!ht_oper || !elems->ht_cap_elem)
222 return IEEE80211_CONN_MODE_LEGACY;
224 chandef->width = NL80211_CHAN_WIDTH_20;
226 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
228 /* check that channel matches the right operating channel */
229 if (!ignore_ht_channel_mismatch && channel->center_freq != ht_cfreq) {
231 * It's possible that some APs are confused here;
232 * Netgear WNDR3700 sometimes reports 4 higher than
233 * the actual channel in association responses, but
234 * since we look at probe response/beacon data here
238 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
239 channel->center_freq, ht_cfreq,
240 ht_oper->primary_chan, channel->band);
241 return IEEE80211_CONN_MODE_LEGACY;
244 ieee80211_chandef_ht_oper(ht_oper, chandef);
246 if (conn->mode < IEEE80211_CONN_MODE_VHT)
247 return IEEE80211_CONN_MODE_HT;
249 vht_chandef = *chandef;
252 * having he_cap/he_oper parsed out implies we're at
253 * least operating as HE STA
255 if (elems->he_cap && he_oper &&
256 he_oper->he_oper_params & cpu_to_le32(IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
257 struct ieee80211_vht_operation he_oper_vht_cap;
260 * Set only first 3 bytes (other 2 aren't used in
261 * ieee80211_chandef_vht_oper() anyway)
263 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
264 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
266 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
267 &he_oper_vht_cap, ht_oper,
270 "HE AP VHT information is invalid, disabling HE\n");
271 /* this will cause us to re-parse as VHT STA */
272 return IEEE80211_CONN_MODE_VHT;
274 } else if (!vht_oper || !elems->vht_cap_elem) {
275 if (sband->band == NL80211_BAND_5GHZ) {
277 "VHT information is missing, disabling VHT\n");
278 return IEEE80211_CONN_MODE_HT;
281 } else if (sband->band == NL80211_BAND_2GHZ) {
283 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
288 "AP VHT information is invalid, disabling VHT\n");
289 return IEEE80211_CONN_MODE_HT;
292 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
294 "AP VHT information doesn't match HT, disabling VHT\n");
295 return IEEE80211_CONN_MODE_HT;
298 *chandef = vht_chandef;
300 /* stick to current max mode if we or the AP don't have HE */
301 if (conn->mode < IEEE80211_CONN_MODE_HE ||
302 !elems->he_operation || !elems->he_cap) {
304 return IEEE80211_CONN_MODE_HT;
305 return IEEE80211_CONN_MODE_VHT;
308 /* stick to HE if we or the AP don't have EHT */
309 if (conn->mode < IEEE80211_CONN_MODE_EHT ||
310 !eht_oper || !elems->eht_cap)
311 return IEEE80211_CONN_MODE_HE;
314 * handle the case that the EHT operation indicates that it holds EHT
315 * operation information (in case that the channel width differs from
316 * the channel width reported in HT/VHT/HE).
318 if (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) {
319 struct cfg80211_chan_def eht_chandef = *chandef;
321 ieee80211_chandef_eht_oper((const void *)eht_oper->optional,
324 eht_chandef.punctured =
325 ieee80211_eht_oper_dis_subchan_bitmap(eht_oper);
327 if (!cfg80211_chandef_valid(&eht_chandef)) {
329 "AP EHT information is invalid, disabling EHT\n");
330 return IEEE80211_CONN_MODE_HE;
333 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
335 "AP EHT information doesn't match HT/VHT/HE, disabling EHT\n");
336 return IEEE80211_CONN_MODE_HE;
339 *chandef = eht_chandef;
342 return IEEE80211_CONN_MODE_EHT;
346 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
348 const struct ieee80211_he_cap_elem *he_cap,
349 const struct ieee80211_he_operation *he_op)
351 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
352 u16 mcs_80_map_tx, mcs_80_map_rx;
359 /* mcs_nss is right after he_cap info */
360 he_mcs_nss_supp = (void *)(he_cap + 1);
362 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
363 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
365 /* P802.11-REVme/D0.3
366 * 27.1.1 Introduction to the HE PHY
368 * An HE STA shall support the following features:
370 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
371 * supported channel widths for HE SU PPDUs
373 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
374 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
375 link_id_info(sdata, link_id,
376 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
377 mcs_80_map_tx, mcs_80_map_rx);
384 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
387 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
388 * zeroes, which is nonsense, and completely inconsistent with itself
389 * (it doesn't have 8 streams). Accept the settings in this case anyway.
394 /* make sure the AP is consistent with itself
397 * 26.17.1 Basic HE BSS operation
399 * A STA that is operating in an HE BSS shall be able to receive and
400 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
401 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
402 * MLME-START.request primitive and shall be able to receive at each of
403 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
404 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
407 for (nss = 8; nss > 0; nss--) {
408 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
412 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
415 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
416 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
418 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
419 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
420 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
421 link_id_info(sdata, link_id,
422 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
423 nss, ap_rx_val, ap_tx_val, ap_op_val);
432 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
433 struct ieee80211_supported_band *sband,
434 const struct ieee80211_he_operation *he_op)
436 const struct ieee80211_sta_he_cap *sta_he_cap =
437 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
441 if (!sta_he_cap || !he_op)
444 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
447 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
448 * zeroes, which is nonsense, and completely inconsistent with itself
449 * (it doesn't have 8 streams). Accept the settings in this case anyway.
454 /* Need to go over for 80MHz, 160MHz and for 80+80 */
455 for (i = 0; i < 3; i++) {
456 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
457 &sta_he_cap->he_mcs_nss_supp;
459 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
461 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
463 bool verified = true;
466 * For each band there is a maximum of 8 spatial streams
467 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
468 * of 2 bits per NSS (1-8), with the values defined in enum
469 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
470 * capabilities aren't less than the AP's minimum requirements
471 * for this HE BSS per SS.
472 * It is enough to find one such band that meets the reqs.
474 for (nss = 8; nss > 0; nss--) {
475 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
476 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
477 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
479 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
483 * Make sure the HE AP doesn't require MCSs that aren't
484 * supported by the client as required by spec
487 * 26.17.1 Basic HE BSS operation
489 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
490 * a BSS, unless it supports (i.e., is able to both transmit and
491 * receive using) all of the <HE-MCS, NSS> tuples in the basic
492 * HE-MCS and NSS set.
494 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
495 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
496 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
506 /* If here, STA doesn't meet AP's HE min requirements */
511 ieee80211_get_eht_cap_mcs_nss(const struct ieee80211_sta_he_cap *sta_he_cap,
512 const struct ieee80211_sta_eht_cap *sta_eht_cap,
513 unsigned int idx, int bw)
515 u8 he_phy_cap0 = sta_he_cap->he_cap_elem.phy_cap_info[0];
516 u8 eht_phy_cap0 = sta_eht_cap->eht_cap_elem.phy_cap_info[0];
518 /* handle us being a 20 MHz-only EHT STA - with four values
519 * for MCS 0-7, 8-9, 10-11, 12-13.
521 if (!(he_phy_cap0 & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL))
522 return sta_eht_cap->eht_mcs_nss_supp.only_20mhz.rx_tx_max_nss[idx];
524 /* the others have MCS 0-9 together, rather than separately from 0-7 */
530 return sta_eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_max_nss[idx];
533 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
534 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)))
535 return 0xff; /* pass check */
536 return sta_eht_cap->eht_mcs_nss_supp.bw._160.rx_tx_max_nss[idx];
538 if (!(eht_phy_cap0 & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ))
539 return 0xff; /* pass check */
540 return sta_eht_cap->eht_mcs_nss_supp.bw._320.rx_tx_max_nss[idx];
548 ieee80211_verify_sta_eht_mcs_support(struct ieee80211_sub_if_data *sdata,
549 struct ieee80211_supported_band *sband,
550 const struct ieee80211_eht_operation *eht_op)
552 const struct ieee80211_sta_he_cap *sta_he_cap =
553 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
554 const struct ieee80211_sta_eht_cap *sta_eht_cap =
555 ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
556 const struct ieee80211_eht_mcs_nss_supp_20mhz_only *req;
559 if (!sta_he_cap || !sta_eht_cap || !eht_op)
562 req = &eht_op->basic_mcs_nss;
564 for (i = 0; i < ARRAY_SIZE(req->rx_tx_max_nss); i++) {
565 u8 req_rx_nss, req_tx_nss;
568 req_rx_nss = u8_get_bits(req->rx_tx_max_nss[i],
569 IEEE80211_EHT_MCS_NSS_RX);
570 req_tx_nss = u8_get_bits(req->rx_tx_max_nss[i],
571 IEEE80211_EHT_MCS_NSS_TX);
573 for (bw = 0; bw < 3; bw++) {
574 u8 have, have_rx_nss, have_tx_nss;
576 have = ieee80211_get_eht_cap_mcs_nss(sta_he_cap,
579 have_rx_nss = u8_get_bits(have,
580 IEEE80211_EHT_MCS_NSS_RX);
581 have_tx_nss = u8_get_bits(have,
582 IEEE80211_EHT_MCS_NSS_TX);
584 if (req_rx_nss > have_rx_nss ||
585 req_tx_nss > have_tx_nss)
593 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
594 const u8 *supp_rates,
595 unsigned int supp_rates_len,
596 const u8 *ext_supp_rates,
597 unsigned int ext_supp_rates_len,
598 u32 *rates, u32 *basic_rates,
599 unsigned long *unknown_rates_selectors,
600 bool *have_higher_than_11mbit,
601 int *min_rate, int *min_rate_index)
605 for (i = 0; i < supp_rates_len + ext_supp_rates_len; i++) {
606 u8 supp_rate = i < supp_rates_len ?
608 ext_supp_rates[i - supp_rates_len];
609 int rate = supp_rate & 0x7f;
610 bool is_basic = !!(supp_rate & 0x80);
612 if ((rate * 5) > 110 && have_higher_than_11mbit)
613 *have_higher_than_11mbit = true;
616 * Skip membership selectors since they're not rates.
618 * Note: Even though the membership selector and the basic
619 * rate flag share the same bit, they are not exactly
622 if (is_basic && rate >= BSS_MEMBERSHIP_SELECTOR_MIN) {
623 if (unknown_rates_selectors)
624 set_bit(rate, unknown_rates_selectors);
628 for (j = 0; j < sband->n_bitrates; j++) {
629 struct ieee80211_rate *br;
632 br = &sband->bitrates[j];
634 brate = DIV_ROUND_UP(br->bitrate, 5);
638 if (is_basic && basic_rates)
639 *basic_rates |= BIT(j);
640 if (min_rate && (rate * 5) < *min_rate) {
641 *min_rate = rate * 5;
649 /* Handle an unknown entry as if it is an unknown selector */
650 if (is_basic && unknown_rates_selectors && j == sband->n_bitrates)
651 set_bit(rate, unknown_rates_selectors);
655 static bool ieee80211_chandef_usable(struct ieee80211_sub_if_data *sdata,
656 const struct cfg80211_chan_def *chandef,
657 u32 prohibited_flags)
659 if (!cfg80211_chandef_usable(sdata->local->hw.wiphy,
660 chandef, prohibited_flags))
663 if (chandef->punctured &&
664 ieee80211_hw_check(&sdata->local->hw, DISALLOW_PUNCTURING))
667 if (chandef->punctured && chandef->chan->band == NL80211_BAND_5GHZ &&
668 ieee80211_hw_check(&sdata->local->hw, DISALLOW_PUNCTURING_5GHZ))
674 static int ieee80211_chandef_num_subchans(const struct cfg80211_chan_def *c)
676 if (c->width == NL80211_CHAN_WIDTH_80P80)
679 return nl80211_chan_width_to_mhz(c->width) / 20;
682 static int ieee80211_chandef_num_widths(const struct cfg80211_chan_def *c)
685 case NL80211_CHAN_WIDTH_20:
686 case NL80211_CHAN_WIDTH_20_NOHT:
688 case NL80211_CHAN_WIDTH_40:
690 case NL80211_CHAN_WIDTH_80P80:
691 case NL80211_CHAN_WIDTH_80:
693 case NL80211_CHAN_WIDTH_160:
695 case NL80211_CHAN_WIDTH_320:
703 VISIBLE_IF_MAC80211_KUNIT int
704 ieee80211_calc_chandef_subchan_offset(const struct cfg80211_chan_def *ap,
705 u8 n_partial_subchans)
707 int n = ieee80211_chandef_num_subchans(ap);
708 struct cfg80211_chan_def tmp = *ap;
712 * Given a chandef (in this context, it's the AP's) and a number
713 * of subchannels that we want to look at ('n_partial_subchans'),
714 * calculate the offset in number of subchannels between the full
715 * and the subset with the desired width.
718 /* same number of subchannels means no offset, obviously */
719 if (n == n_partial_subchans)
722 /* don't WARN - misconfigured APs could cause this if their N > width */
723 if (n < n_partial_subchans)
726 while (ieee80211_chandef_num_subchans(&tmp) > n_partial_subchans) {
727 u32 prev = tmp.center_freq1;
729 ieee80211_chandef_downgrade(&tmp, NULL);
732 * if center_freq moved up, half the original channels
733 * are gone now but were below, so increase offset
735 if (prev < tmp.center_freq1)
736 offset += ieee80211_chandef_num_subchans(&tmp);
740 * 80+80 with secondary 80 below primary - four subchannels for it
741 * (we cannot downgrade *to* 80+80, so no need to consider 'tmp')
743 if (ap->width == NL80211_CHAN_WIDTH_80P80 &&
744 ap->center_freq2 < ap->center_freq1)
749 EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_calc_chandef_subchan_offset);
751 VISIBLE_IF_MAC80211_KUNIT void
752 ieee80211_rearrange_tpe_psd(struct ieee80211_parsed_tpe_psd *psd,
753 const struct cfg80211_chan_def *ap,
754 const struct cfg80211_chan_def *used)
756 u8 needed = ieee80211_chandef_num_subchans(used);
757 u8 have = ieee80211_chandef_num_subchans(ap);
758 u8 tmp[IEEE80211_TPE_PSD_ENTRIES_320MHZ];
764 /* if N is zero, all defaults were used, no point in rearranging */
768 BUILD_BUG_ON(sizeof(tmp) != sizeof(psd->power));
771 * This assumes that 'N' is consistent with the HE channel, as
772 * it should be (otherwise the AP is broken).
774 * In psd->power we have values in the order 0..N, 0..K, where
775 * N+K should cover the entire channel per 'ap', but even if it
776 * doesn't then we've pre-filled 'unlimited' as defaults.
778 * But this is all the wrong order, we want to have them in the
779 * order of the 'used' channel.
781 * So for example, we could have a 320 MHz EHT AP, which has the
782 * HE channel as 80 MHz (e.g. due to puncturing, which doesn't
783 * seem to be considered for the TPE), as follows:
785 * EHT 320: | | | | | | | | | | | | | | | | |
787 * used 160: | | | | | | | | |
789 * N entries: |--|--|--|--|
790 * K entries: |--|--|--|--|--|--|--|--| |--|--|--|--|
791 * power idx: 4 5 6 7 8 9 10 11 0 1 2 3 12 13 14 15
792 * full chan: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
793 * used chan: 0 1 2 3 4 5 6 7
795 * The idx in the power array ('power idx') is like this since it
796 * comes directly from the element's N and K entries in their
797 * element order, and those are this way for HE compatibility.
799 * Rearrange them as desired here, first by putting them into the
800 * 'full chan' order, and then selecting the necessary subset for
804 /* first reorder according to AP channel */
805 offset = ieee80211_calc_chandef_subchan_offset(ap, psd->n);
806 for (int i = 0; i < have; i++) {
808 tmp[i] = psd->power[i + psd->n];
809 else if (i < offset + psd->n)
810 tmp[i] = psd->power[i - offset];
812 tmp[i] = psd->power[i];
816 * and then select the subset for the used channel
817 * (set everything to defaults first in case a driver is confused)
819 memset(psd->power, IEEE80211_TPE_PSD_NO_LIMIT, sizeof(psd->power));
820 offset = ieee80211_calc_chandef_subchan_offset(ap, needed);
821 for (int i = 0; i < needed; i++)
822 psd->power[i] = tmp[offset + i];
825 /* limit, but don't lie if there are defaults in the data */
826 if (needed < psd->count)
829 EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_rearrange_tpe_psd);
831 static void ieee80211_rearrange_tpe(struct ieee80211_parsed_tpe *tpe,
832 const struct cfg80211_chan_def *ap,
833 const struct cfg80211_chan_def *used)
835 /* ignore this completely for narrow/invalid channels */
836 if (!ieee80211_chandef_num_subchans(ap) ||
837 !ieee80211_chandef_num_subchans(used)) {
838 ieee80211_clear_tpe(tpe);
842 for (int i = 0; i < 2; i++) {
843 int needed_pwr_count;
845 ieee80211_rearrange_tpe_psd(&tpe->psd_local[i], ap, used);
846 ieee80211_rearrange_tpe_psd(&tpe->psd_reg_client[i], ap, used);
848 /* limit this to the widths we actually need */
849 needed_pwr_count = ieee80211_chandef_num_widths(used);
850 if (needed_pwr_count < tpe->max_local[i].count)
851 tpe->max_local[i].count = needed_pwr_count;
852 if (needed_pwr_count < tpe->max_reg_client[i].count)
853 tpe->max_reg_client[i].count = needed_pwr_count;
858 * The AP part of the channel request is used to distinguish settings
859 * to the device used for wider bandwidth OFDMA. This is used in the
860 * channel context code to assign two channel contexts even if they're
861 * both for the same channel, if the AP bandwidths are incompatible.
862 * If not EHT (or driver override) then ap.chan == NULL indicates that
863 * there's no wider BW OFDMA used.
865 static void ieee80211_set_chanreq_ap(struct ieee80211_sub_if_data *sdata,
866 struct ieee80211_chan_req *chanreq,
867 struct ieee80211_conn_settings *conn,
868 struct cfg80211_chan_def *ap_chandef)
870 chanreq->ap.chan = NULL;
872 if (conn->mode < IEEE80211_CONN_MODE_EHT)
874 if (sdata->vif.driver_flags & IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW)
877 chanreq->ap = *ap_chandef;
880 static struct ieee802_11_elems *
881 ieee80211_determine_chan_mode(struct ieee80211_sub_if_data *sdata,
882 struct ieee80211_conn_settings *conn,
883 struct cfg80211_bss *cbss, int link_id,
884 struct ieee80211_chan_req *chanreq,
885 struct cfg80211_chan_def *ap_chandef,
886 unsigned long *userspace_selectors)
888 const struct cfg80211_bss_ies *ies = rcu_dereference(cbss->ies);
889 struct ieee80211_bss *bss = (void *)cbss->priv;
890 struct ieee80211_channel *channel = cbss->channel;
891 struct ieee80211_elems_parse_params parse_params = {
897 struct ieee802_11_elems *elems;
898 struct ieee80211_supported_band *sband;
899 enum ieee80211_conn_mode ap_mode;
900 unsigned long unknown_rates_selectors[BITS_TO_LONGS(128)] = {};
901 unsigned long sta_selectors[BITS_TO_LONGS(128)] = {};
905 parse_params.mode = conn->mode;
906 elems = ieee802_11_parse_elems_full(&parse_params);
908 return ERR_PTR(-ENOMEM);
910 ap_mode = ieee80211_determine_ap_chan(sdata, channel, bss->vht_cap_info,
911 elems, false, conn, ap_chandef);
913 /* this should be impossible since parsing depends on our mode */
914 if (WARN_ON(ap_mode > conn->mode)) {
919 if (conn->mode != ap_mode) {
920 conn->mode = ap_mode;
925 mlme_link_id_dbg(sdata, link_id, "determined AP %pM to be %s\n",
926 cbss->bssid, ieee80211_conn_mode_str(ap_mode));
928 sband = sdata->local->hw.wiphy->bands[channel->band];
930 ieee80211_get_rates(sband, elems->supp_rates, elems->supp_rates_len,
931 elems->ext_supp_rates, elems->ext_supp_rates_len,
932 NULL, NULL, unknown_rates_selectors, NULL, NULL,
935 switch (channel->band) {
936 case NL80211_BAND_S1GHZ:
937 if (WARN_ON(ap_mode != IEEE80211_CONN_MODE_S1G)) {
942 case NL80211_BAND_6GHZ:
943 if (ap_mode < IEEE80211_CONN_MODE_HE) {
944 link_id_info(sdata, link_id,
945 "Rejecting non-HE 6/7 GHz connection");
951 if (WARN_ON(ap_mode == IEEE80211_CONN_MODE_S1G)) {
958 case IEEE80211_CONN_MODE_S1G:
962 case IEEE80211_CONN_MODE_LEGACY:
963 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
965 case IEEE80211_CONN_MODE_HT:
966 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
968 IEEE80211_CONN_BW_LIMIT_40);
970 case IEEE80211_CONN_MODE_VHT:
971 case IEEE80211_CONN_MODE_HE:
972 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
974 IEEE80211_CONN_BW_LIMIT_160);
976 case IEEE80211_CONN_MODE_EHT:
977 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
979 IEEE80211_CONN_BW_LIMIT_320);
983 chanreq->oper = *ap_chandef;
985 bitmap_copy(sta_selectors, userspace_selectors, 128);
986 if (conn->mode >= IEEE80211_CONN_MODE_HT)
987 set_bit(BSS_MEMBERSHIP_SELECTOR_HT_PHY, sta_selectors);
988 if (conn->mode >= IEEE80211_CONN_MODE_VHT)
989 set_bit(BSS_MEMBERSHIP_SELECTOR_VHT_PHY, sta_selectors);
990 if (conn->mode >= IEEE80211_CONN_MODE_HE)
991 set_bit(BSS_MEMBERSHIP_SELECTOR_HE_PHY, sta_selectors);
992 if (conn->mode >= IEEE80211_CONN_MODE_EHT)
993 set_bit(BSS_MEMBERSHIP_SELECTOR_EHT_PHY, sta_selectors);
996 * We do not support EPD or GLK so never add them.
997 * SAE_H2E is handled through userspace_selectors.
1000 /* Check if we support all required features */
1001 if (!bitmap_subset(unknown_rates_selectors, sta_selectors, 128)) {
1002 link_id_info(sdata, link_id,
1003 "required basic rate or BSS membership selectors not supported or disabled, rejecting connection\n");
1008 ieee80211_set_chanreq_ap(sdata, chanreq, conn, ap_chandef);
1010 while (!ieee80211_chandef_usable(sdata, &chanreq->oper,
1011 IEEE80211_CHAN_DISABLED)) {
1012 if (WARN_ON(chanreq->oper.width == NL80211_CHAN_WIDTH_20_NOHT)) {
1017 ieee80211_chanreq_downgrade(chanreq, conn);
1020 if (conn->mode >= IEEE80211_CONN_MODE_HE &&
1021 !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper,
1022 IEEE80211_CHAN_NO_HE)) {
1023 conn->mode = IEEE80211_CONN_MODE_VHT;
1024 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
1026 IEEE80211_CONN_BW_LIMIT_160);
1029 if (conn->mode >= IEEE80211_CONN_MODE_EHT &&
1030 !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper,
1031 IEEE80211_CHAN_NO_EHT)) {
1032 conn->mode = IEEE80211_CONN_MODE_HE;
1033 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
1035 IEEE80211_CONN_BW_LIMIT_160);
1038 if (chanreq->oper.width != ap_chandef->width || ap_mode != conn->mode)
1039 link_id_info(sdata, link_id,
1040 "regulatory prevented using AP config, downgraded\n");
1042 if (conn->mode >= IEEE80211_CONN_MODE_HE &&
1043 (!ieee80211_verify_peer_he_mcs_support(sdata, link_id,
1044 (void *)elems->he_cap,
1045 elems->he_operation) ||
1046 !ieee80211_verify_sta_he_mcs_support(sdata, sband,
1047 elems->he_operation))) {
1048 conn->mode = IEEE80211_CONN_MODE_VHT;
1049 link_id_info(sdata, link_id,
1050 "required MCSes not supported, disabling HE\n");
1053 if (conn->mode >= IEEE80211_CONN_MODE_EHT &&
1054 !ieee80211_verify_sta_eht_mcs_support(sdata, sband,
1055 elems->eht_operation)) {
1056 conn->mode = IEEE80211_CONN_MODE_HE;
1057 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
1059 IEEE80211_CONN_BW_LIMIT_160);
1060 link_id_info(sdata, link_id,
1061 "required MCSes not supported, disabling EHT\n");
1064 /* the mode can only decrease, so this must terminate */
1065 if (ap_mode != conn->mode) {
1070 mlme_link_id_dbg(sdata, link_id,
1071 "connecting with %s mode, max bandwidth %d MHz\n",
1072 ieee80211_conn_mode_str(conn->mode),
1073 20 * (1 << conn->bw_limit));
1075 if (WARN_ON_ONCE(!cfg80211_chandef_valid(&chanreq->oper))) {
1083 return ERR_PTR(ret);
1086 static int ieee80211_config_bw(struct ieee80211_link_data *link,
1087 struct ieee802_11_elems *elems,
1088 bool update, u64 *changed,
1091 struct ieee80211_channel *channel = link->conf->chanreq.oper.chan;
1092 struct ieee80211_sub_if_data *sdata = link->sdata;
1093 struct ieee80211_chan_req chanreq = {};
1094 struct cfg80211_chan_def ap_chandef;
1095 enum ieee80211_conn_mode ap_mode;
1096 u32 vht_cap_info = 0;
1100 /* don't track any bandwidth changes in legacy/S1G modes */
1101 if (link->u.mgd.conn.mode == IEEE80211_CONN_MODE_LEGACY ||
1102 link->u.mgd.conn.mode == IEEE80211_CONN_MODE_S1G)
1105 if (elems->vht_cap_elem)
1106 vht_cap_info = le32_to_cpu(elems->vht_cap_elem->vht_cap_info);
1108 ap_mode = ieee80211_determine_ap_chan(sdata, channel, vht_cap_info,
1109 elems, true, &link->u.mgd.conn,
1112 if (ap_mode != link->u.mgd.conn.mode) {
1114 "AP %pM appears to change mode (expected %s, found %s) in %s, disconnect\n",
1116 ieee80211_conn_mode_str(link->u.mgd.conn.mode),
1117 ieee80211_conn_mode_str(ap_mode), frame);
1121 chanreq.oper = ap_chandef;
1122 ieee80211_set_chanreq_ap(sdata, &chanreq, &link->u.mgd.conn,
1126 * if HT operation mode changed store the new one -
1127 * this may be applicable even if channel is identical
1129 if (elems->ht_operation) {
1130 ht_opmode = le16_to_cpu(elems->ht_operation->operation_mode);
1131 if (link->conf->ht_operation_mode != ht_opmode) {
1132 *changed |= BSS_CHANGED_HT;
1133 link->conf->ht_operation_mode = ht_opmode;
1138 * Downgrade the new channel if we associated with restricted
1139 * bandwidth capabilities. For example, if we associated as a
1140 * 20 MHz STA to a 40 MHz AP (due to regulatory, capabilities
1141 * or config reasons) then switching to a 40 MHz channel now
1142 * won't do us any good -- we couldn't use it with the AP.
1144 while (link->u.mgd.conn.bw_limit <
1145 ieee80211_min_bw_limit_from_chandef(&chanreq.oper))
1146 ieee80211_chandef_downgrade(&chanreq.oper, NULL);
1148 if (ap_chandef.chan->band == NL80211_BAND_6GHZ &&
1149 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE) {
1150 ieee80211_rearrange_tpe(&elems->tpe, &ap_chandef,
1152 if (memcmp(&link->conf->tpe, &elems->tpe, sizeof(elems->tpe))) {
1153 link->conf->tpe = elems->tpe;
1154 *changed |= BSS_CHANGED_TPE;
1158 if (ieee80211_chanreq_identical(&chanreq, &link->conf->chanreq))
1162 "AP %pM changed bandwidth in %s, new used config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
1163 link->u.mgd.bssid, frame, chanreq.oper.chan->center_freq,
1164 chanreq.oper.chan->freq_offset, chanreq.oper.width,
1165 chanreq.oper.center_freq1, chanreq.oper.freq1_offset,
1166 chanreq.oper.center_freq2);
1168 if (!cfg80211_chandef_valid(&chanreq.oper)) {
1170 "AP %pM changed caps/bw in %s in a way we can't support - disconnect\n",
1171 link->u.mgd.bssid, frame);
1176 link->conf->chanreq = chanreq;
1181 * We're tracking the current AP here, so don't do any further checks
1182 * here. This keeps us from playing ping-pong with regulatory, without
1183 * it the following can happen (for example):
1184 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
1185 * - AP advertises regdom US
1186 * - CRDA loads regdom US with 80 MHz prohibited (old database)
1187 * - we detect an unsupported channel and disconnect
1188 * - disconnect causes CRDA to reload world regdomain and the game
1190 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
1192 * It seems possible that there are still scenarios with CSA or real
1193 * bandwidth changes where a this could happen, but those cases are
1194 * less common and wouldn't completely prevent using the AP.
1197 ret = ieee80211_link_change_chanreq(link, &chanreq, changed);
1200 "AP %pM changed bandwidth in %s to incompatible one - disconnect\n",
1201 link->u.mgd.bssid, frame);
1205 cfg80211_schedule_channels_check(&sdata->wdev);
1209 /* frame sending functions */
1211 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
1212 struct sk_buff *skb, u8 ap_ht_param,
1213 struct ieee80211_supported_band *sband,
1214 struct ieee80211_channel *channel,
1215 enum ieee80211_smps_mode smps,
1216 const struct ieee80211_conn_settings *conn)
1219 u32 flags = channel->flags;
1221 struct ieee80211_sta_ht_cap ht_cap;
1223 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
1225 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
1226 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
1228 /* determine capability flags */
1231 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
1232 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
1233 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
1234 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1235 cap &= ~IEEE80211_HT_CAP_SGI_40;
1238 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
1239 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
1240 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1241 cap &= ~IEEE80211_HT_CAP_SGI_40;
1247 * If 40 MHz was disabled associate as though we weren't
1248 * capable of 40 MHz -- some broken APs will never fall
1249 * back to trying to transmit in 20 MHz.
1251 if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_20) {
1252 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1253 cap &= ~IEEE80211_HT_CAP_SGI_40;
1256 /* set SM PS mode properly */
1257 cap &= ~IEEE80211_HT_CAP_SM_PS;
1259 case IEEE80211_SMPS_AUTOMATIC:
1260 case IEEE80211_SMPS_NUM_MODES:
1263 case IEEE80211_SMPS_OFF:
1264 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
1265 IEEE80211_HT_CAP_SM_PS_SHIFT;
1267 case IEEE80211_SMPS_STATIC:
1268 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
1269 IEEE80211_HT_CAP_SM_PS_SHIFT;
1271 case IEEE80211_SMPS_DYNAMIC:
1272 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
1273 IEEE80211_HT_CAP_SM_PS_SHIFT;
1277 /* reserve and fill IE */
1278 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
1279 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
1282 /* This function determines vht capability flags for the association
1283 * and builds the IE.
1284 * Note - the function returns true to own the MU-MIMO capability
1286 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
1287 struct sk_buff *skb,
1288 struct ieee80211_supported_band *sband,
1289 struct ieee80211_vht_cap *ap_vht_cap,
1290 const struct ieee80211_conn_settings *conn)
1292 struct ieee80211_local *local = sdata->local;
1295 struct ieee80211_sta_vht_cap vht_cap;
1296 u32 mask, ap_bf_sts, our_bf_sts;
1297 bool mu_mimo_owner = false;
1299 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
1301 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
1302 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
1304 /* determine capability flags */
1307 if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_80) {
1308 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
1309 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
1313 * Some APs apparently get confused if our capabilities are better
1314 * than theirs, so restrict what we advertise in the assoc request.
1316 if (!(ap_vht_cap->vht_cap_info &
1317 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
1318 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1319 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
1320 else if (!(ap_vht_cap->vht_cap_info &
1321 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
1322 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1325 * If some other vif is using the MU-MIMO capability we cannot associate
1326 * using MU-MIMO - this will lead to contradictions in the group-id
1328 * Ownership is defined since association request, in order to avoid
1329 * simultaneous associations with MU-MIMO.
1331 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
1332 bool disable_mu_mimo = false;
1333 struct ieee80211_sub_if_data *other;
1335 list_for_each_entry(other, &local->interfaces, list) {
1336 if (other->vif.bss_conf.mu_mimo_owner) {
1337 disable_mu_mimo = true;
1341 if (disable_mu_mimo)
1342 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1344 mu_mimo_owner = true;
1347 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
1349 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
1350 our_bf_sts = cap & mask;
1352 if (ap_bf_sts < our_bf_sts) {
1357 /* reserve and fill IE */
1358 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
1359 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
1361 return mu_mimo_owner;
1364 static void ieee80211_assoc_add_rates(struct sk_buff *skb,
1365 enum nl80211_chan_width width,
1366 struct ieee80211_supported_band *sband,
1367 struct ieee80211_mgd_assoc_data *assoc_data)
1371 if (assoc_data->supp_rates_len) {
1373 * Get all rates supported by the device and the AP as
1374 * some APs don't like getting a superset of their rates
1375 * in the association request (e.g. D-Link DAP 1353 in
1378 ieee80211_parse_bitrates(width, sband,
1379 assoc_data->supp_rates,
1380 assoc_data->supp_rates_len,
1384 * In case AP not provide any supported rates information
1385 * before association, we send information element(s) with
1386 * all rates that we support.
1391 ieee80211_put_srates_elem(skb, sband, 0, 0, ~rates,
1392 WLAN_EID_SUPP_RATES);
1393 ieee80211_put_srates_elem(skb, sband, 0, 0, ~rates,
1394 WLAN_EID_EXT_SUPP_RATES);
1397 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
1404 static const u8 before_ht[] = {
1406 WLAN_EID_SUPP_RATES,
1407 WLAN_EID_EXT_SUPP_RATES,
1408 WLAN_EID_PWR_CAPABILITY,
1409 WLAN_EID_SUPPORTED_CHANNELS,
1412 WLAN_EID_RRM_ENABLED_CAPABILITIES,
1413 WLAN_EID_MOBILITY_DOMAIN,
1414 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
1415 WLAN_EID_RIC_DATA, /* reassoc only */
1416 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
1418 static const u8 after_ric[] = {
1419 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
1420 WLAN_EID_HT_CAPABILITY,
1421 WLAN_EID_BSS_COEX_2040,
1422 /* luckily this is almost always there */
1423 WLAN_EID_EXT_CAPABILITY,
1424 WLAN_EID_QOS_TRAFFIC_CAPA,
1425 WLAN_EID_TIM_BCAST_REQ,
1426 WLAN_EID_INTERWORKING,
1427 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
1428 WLAN_EID_VHT_CAPABILITY,
1429 WLAN_EID_OPMODE_NOTIF,
1435 noffset = ieee80211_ie_split_ric(elems, elems_len,
1437 ARRAY_SIZE(before_ht),
1439 ARRAY_SIZE(after_ric),
1441 skb_put_data(skb, elems + offset, noffset - offset);
1446 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
1451 static const u8 before_vht[] = {
1453 * no need to list the ones split off before HT
1456 WLAN_EID_BSS_COEX_2040,
1457 WLAN_EID_EXT_CAPABILITY,
1458 WLAN_EID_QOS_TRAFFIC_CAPA,
1459 WLAN_EID_TIM_BCAST_REQ,
1460 WLAN_EID_INTERWORKING,
1461 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
1468 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
1469 noffset = ieee80211_ie_split(elems, elems_len,
1470 before_vht, ARRAY_SIZE(before_vht),
1472 skb_put_data(skb, elems + offset, noffset - offset);
1477 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
1482 static const u8 before_he[] = {
1484 * no need to list the ones split off before VHT
1487 WLAN_EID_OPMODE_NOTIF,
1488 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
1490 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
1491 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
1492 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
1493 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
1494 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
1495 /* TODO: add 11ah/11aj/11ak elements */
1502 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
1503 noffset = ieee80211_ie_split(elems, elems_len,
1504 before_he, ARRAY_SIZE(before_he),
1506 skb_put_data(skb, elems + offset, noffset - offset);
1511 #define PRESENT_ELEMS_MAX 8
1512 #define PRESENT_ELEM_EXT_OFFS 0x100
1515 ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1516 struct sk_buff *skb, u16 capab,
1517 const struct element *ext_capa,
1518 const u16 *present_elems,
1519 struct ieee80211_mgd_assoc_data *assoc_data);
1522 ieee80211_add_link_elems(struct ieee80211_sub_if_data *sdata,
1523 struct sk_buff *skb, u16 *capab,
1524 const struct element *ext_capa,
1525 const u8 *extra_elems,
1526 size_t extra_elems_len,
1527 unsigned int link_id,
1528 struct ieee80211_link_data *link,
1530 struct ieee80211_mgd_assoc_data *assoc_data)
1532 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1533 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1534 struct ieee80211_channel *chan = cbss->channel;
1535 const struct ieee80211_sband_iftype_data *iftd;
1536 struct ieee80211_local *local = sdata->local;
1537 struct ieee80211_supported_band *sband;
1538 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
1539 struct ieee80211_chanctx_conf *chanctx_conf;
1540 enum ieee80211_smps_mode smps_mode;
1541 u16 orig_capab = *capab;
1543 int present_elems_len = 0;
1547 #define ADD_PRESENT_ELEM(id) do { \
1548 /* need a last for termination - we use 0 == SSID */ \
1549 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
1550 present_elems[present_elems_len++] = (id); \
1552 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
1555 smps_mode = link->smps_mode;
1556 else if (sdata->u.mgd.powersave)
1557 smps_mode = IEEE80211_SMPS_DYNAMIC;
1559 smps_mode = IEEE80211_SMPS_OFF;
1563 * 5/10 MHz scenarios are only viable without MLO, in which
1564 * case this pointer should be used ... All of this is a bit
1565 * unclear though, not sure this even works at all.
1568 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
1570 width = chanctx_conf->def.width;
1574 sband = local->hw.wiphy->bands[chan->band];
1575 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1577 if (sband->band == NL80211_BAND_2GHZ) {
1578 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1579 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1582 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
1583 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
1584 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
1586 if (sband->band != NL80211_BAND_S1GHZ)
1587 ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
1589 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
1590 *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
1591 struct cfg80211_chan_def chandef = {
1596 pos = skb_put(skb, 4);
1597 *pos++ = WLAN_EID_PWR_CAPABILITY;
1599 *pos++ = 0; /* min tx power */
1601 *pos++ = ieee80211_chandef_max_power(&chandef);
1602 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
1606 * Per spec, we shouldn't include the list of channels if we advertise
1607 * support for extended channel switching, but we've always done that;
1608 * (for now?) apply this restriction only on the (new) 6 GHz band.
1610 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
1611 (sband->band != NL80211_BAND_6GHZ ||
1612 !ext_capa || ext_capa->datalen < 1 ||
1613 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
1614 /* TODO: get this in reg domain format */
1615 pos = skb_put(skb, 2 * sband->n_channels + 2);
1616 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
1617 *pos++ = 2 * sband->n_channels;
1618 for (i = 0; i < sband->n_channels; i++) {
1619 int cf = sband->channels[i].center_freq;
1621 *pos++ = ieee80211_frequency_to_channel(cf);
1622 *pos++ = 1; /* one channel in the subband*/
1624 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
1627 /* if present, add any custom IEs that go before HT */
1628 offset = ieee80211_add_before_ht_elems(skb, extra_elems,
1632 if (sband->band != NL80211_BAND_6GHZ &&
1633 assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HT) {
1634 ieee80211_add_ht_ie(sdata, skb,
1635 assoc_data->link[link_id].ap_ht_param,
1636 sband, chan, smps_mode,
1637 &assoc_data->link[link_id].conn);
1638 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
1641 /* if present, add any custom IEs that go before VHT */
1642 offset = ieee80211_add_before_vht_elems(skb, extra_elems,
1646 if (sband->band != NL80211_BAND_6GHZ &&
1647 assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_VHT &&
1648 sband->vht_cap.vht_supported) {
1649 bool mu_mimo_owner =
1650 ieee80211_add_vht_ie(sdata, skb, sband,
1651 &assoc_data->link[link_id].ap_vht_cap,
1652 &assoc_data->link[link_id].conn);
1655 link->conf->mu_mimo_owner = mu_mimo_owner;
1656 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
1659 /* if present, add any custom IEs that go before HE */
1660 offset = ieee80211_add_before_he_elems(skb, extra_elems,
1664 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HE) {
1665 ieee80211_put_he_cap(skb, sdata, sband,
1666 &assoc_data->link[link_id].conn);
1667 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
1668 ieee80211_put_he_6ghz_cap(skb, sdata, smps_mode);
1672 * careful - need to know about all the present elems before
1673 * calling ieee80211_assoc_add_ml_elem(), so add this one if
1674 * we're going to put it after the ML element
1676 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT)
1677 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
1679 if (link_id == assoc_data->assoc_link_id)
1680 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
1681 present_elems, assoc_data);
1683 /* crash if somebody gets it wrong */
1684 present_elems = NULL;
1686 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT)
1687 ieee80211_put_eht_cap(skb, sdata, sband,
1688 &assoc_data->link[link_id].conn);
1690 if (sband->band == NL80211_BAND_S1GHZ) {
1691 ieee80211_add_aid_request_ie(sdata, skb);
1692 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1695 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1696 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1701 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
1705 unsigned int skb_len = skb->len;
1706 bool at_extension = false;
1709 u8 *len, *list_len = NULL;
1711 skb_put_u8(skb, WLAN_EID_EXTENSION);
1712 len = skb_put(skb, 1);
1713 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
1715 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
1716 u16 elem = outer[i];
1717 bool have_inner = false;
1719 /* should at least be sorted in the sense of normal -> ext */
1720 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
1722 /* switch to extension list */
1723 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
1724 at_extension = true;
1730 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
1731 if (elem == inner[j]) {
1741 list_len = skb_put(skb, 1);
1745 skb_put_u8(skb, (u8)elem);
1749 /* if we added a list but no extension list, make a zero-len one */
1750 if (added && (!at_extension || !list_len))
1753 /* if nothing added remove extension element completely */
1755 skb_trim(skb, skb_len);
1757 *len = skb->len - skb_len - 2;
1761 ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1762 struct sk_buff *skb, u16 capab,
1763 const struct element *ext_capa,
1764 const u16 *outer_present_elems,
1765 struct ieee80211_mgd_assoc_data *assoc_data)
1767 struct ieee80211_local *local = sdata->local;
1768 struct ieee80211_multi_link_elem *ml_elem;
1769 struct ieee80211_mle_basic_common_info *common;
1770 const struct wiphy_iftype_ext_capab *ift_ext_capa;
1771 __le16 eml_capa = 0, mld_capa_ops = 0;
1772 unsigned int link_id;
1776 if (!ieee80211_vif_is_mld(&sdata->vif))
1779 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
1780 ieee80211_vif_type_p2p(&sdata->vif));
1782 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
1783 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
1786 skb_put_u8(skb, WLAN_EID_EXTENSION);
1787 ml_elem_len = skb_put(skb, 1);
1788 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
1789 ml_elem = skb_put(skb, sizeof(*ml_elem));
1791 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
1792 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
1793 common = skb_put(skb, sizeof(*common));
1794 common->len = sizeof(*common) +
1795 2; /* MLD capa/ops */
1796 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
1798 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
1800 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
1801 IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
1802 common->len += 2; /* EML capabilities */
1804 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
1805 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
1807 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
1809 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1810 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
1811 const u8 *extra_elems;
1812 size_t extra_elems_len;
1814 u8 *subelem_len = NULL;
1817 if (!assoc_data->link[link_id].bss ||
1818 link_id == assoc_data->assoc_link_id)
1821 extra_elems = assoc_data->link[link_id].elems;
1822 extra_elems_len = assoc_data->link[link_id].elems_len;
1824 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
1825 subelem_len = skb_put(skb, 1);
1827 ctrl = cpu_to_le16(link_id |
1828 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
1829 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
1830 skb_put_data(skb, &ctrl, sizeof(ctrl));
1831 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
1832 skb_put_data(skb, assoc_data->link[link_id].addr,
1835 * Now add the contents of the (re)association request,
1836 * but the "listen interval" and "current AP address"
1837 * (if applicable) are skipped. So we only have
1838 * the capability field (remember the position and fill
1839 * later), followed by the elements added below by
1840 * calling ieee80211_add_link_elems().
1842 capab_pos = skb_put(skb, 2);
1844 extra_used = ieee80211_add_link_elems(sdata, skb, &capab,
1852 skb_put_data(skb, extra_elems + extra_used,
1853 extra_elems_len - extra_used);
1855 put_unaligned_le16(capab, capab_pos);
1857 ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
1858 link_present_elems);
1860 ieee80211_fragment_element(skb, subelem_len,
1861 IEEE80211_MLE_SUBELEM_FRAGMENT);
1864 ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT);
1868 ieee80211_link_common_elems_size(struct ieee80211_sub_if_data *sdata,
1869 enum nl80211_iftype iftype,
1870 struct cfg80211_bss *cbss,
1873 struct ieee80211_local *local = sdata->local;
1874 const struct ieee80211_sband_iftype_data *iftd;
1875 struct ieee80211_supported_band *sband;
1881 sband = local->hw.wiphy->bands[cbss->channel->band];
1883 /* add STA profile elements length */
1886 /* and supported rates length */
1887 size += 4 + sband->n_bitrates;
1889 /* supported channels */
1890 size += 2 + 2 * sband->n_channels;
1892 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1894 size += iftd->vendor_elems.len;
1896 /* power capability */
1899 /* HT, VHT, HE, EHT */
1900 size += 2 + sizeof(struct ieee80211_ht_cap);
1901 size += 2 + sizeof(struct ieee80211_vht_cap);
1902 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
1903 sizeof(struct ieee80211_he_mcs_nss_supp) +
1904 IEEE80211_HE_PPE_THRES_MAX_LEN;
1906 if (sband->band == NL80211_BAND_6GHZ)
1907 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
1909 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
1910 sizeof(struct ieee80211_eht_mcs_nss_supp) +
1911 IEEE80211_EHT_PPE_THRES_MAX_LEN;
1916 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
1918 struct ieee80211_local *local = sdata->local;
1919 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1920 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1921 struct ieee80211_link_data *link;
1922 struct sk_buff *skb;
1923 struct ieee80211_mgmt *mgmt;
1924 u8 *pos, qos_info, *ie_start;
1925 size_t offset, noffset;
1926 u16 capab = 0, link_capab;
1928 struct element *ext_capa = NULL;
1929 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1930 struct ieee80211_prep_tx_info info = {};
1931 unsigned int link_id, n_links = 0;
1932 u16 present_elems[PRESENT_ELEMS_MAX] = {};
1937 /* we know it's writable, cast away the const */
1938 if (assoc_data->ie_len)
1939 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
1941 assoc_data->ie_len);
1943 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1945 size = local->hw.extra_tx_headroom +
1946 sizeof(*mgmt) + /* bit too much but doesn't matter */
1947 2 + assoc_data->ssid_len + /* SSID */
1948 assoc_data->ie_len + /* extra IEs */
1949 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
1952 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1953 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1954 size_t elems_len = assoc_data->link[link_id].elems_len;
1961 size += ieee80211_link_common_elems_size(sdata, iftype, cbss,
1964 /* non-inheritance element */
1965 size += 2 + 2 + PRESENT_ELEMS_MAX;
1967 /* should be the same across all BSSes */
1968 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
1969 capab |= WLAN_CAPABILITY_PRIVACY;
1972 if (ieee80211_vif_is_mld(&sdata->vif)) {
1973 /* consider the multi-link element with STA profile */
1974 size += sizeof(struct ieee80211_multi_link_elem);
1975 /* max common info field in basic multi-link element */
1976 size += sizeof(struct ieee80211_mle_basic_common_info) +
1981 * The capability elements were already considered above;
1982 * note this over-estimates a bit because there's no
1983 * STA profile for the assoc link.
1985 size += (n_links - 1) *
1986 (1 + 1 + /* subelement ID/length */
1987 2 + /* STA control */
1988 1 + ETH_ALEN + 2 /* STA Info field */);
1991 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
1995 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
1998 skb = alloc_skb(size, GFP_KERNEL);
2002 skb_reserve(skb, local->hw.extra_tx_headroom);
2004 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
2005 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
2007 /* Set MBSSID support for HE AP if needed */
2008 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
2009 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE &&
2010 ext_capa && ext_capa->datalen >= 3)
2011 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
2013 mgmt = skb_put_zero(skb, 24);
2014 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
2015 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2016 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
2018 listen_int = cpu_to_le16(assoc_data->s1g ?
2019 ieee80211_encode_usf(local->hw.conf.listen_interval) :
2020 local->hw.conf.listen_interval);
2021 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
2023 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2024 IEEE80211_STYPE_REASSOC_REQ);
2025 capab_pos = &mgmt->u.reassoc_req.capab_info;
2026 mgmt->u.reassoc_req.listen_interval = listen_int;
2027 memcpy(mgmt->u.reassoc_req.current_ap,
2028 assoc_data->prev_ap_addr, ETH_ALEN);
2029 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
2032 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2033 IEEE80211_STYPE_ASSOC_REQ);
2034 capab_pos = &mgmt->u.assoc_req.capab_info;
2035 mgmt->u.assoc_req.listen_interval = listen_int;
2036 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
2040 pos = skb_put(skb, 2 + assoc_data->ssid_len);
2042 *pos++ = WLAN_EID_SSID;
2043 *pos++ = assoc_data->ssid_len;
2044 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
2047 * This bit is technically reserved, so it shouldn't matter for either
2048 * the AP or us, but it also means we shouldn't set it. However, we've
2049 * always set it in the past, and apparently some EHT APs check that
2050 * we don't set it. To avoid interoperability issues with old APs that
2051 * for some reason check it and want it to be set, set the bit for all
2052 * pre-EHT connections as we used to do.
2054 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_EHT)
2055 capab |= WLAN_CAPABILITY_ESS;
2057 /* add the elements for the assoc (main) link */
2059 offset = ieee80211_add_link_elems(sdata, skb, &link_capab,
2063 assoc_data->assoc_link_id, link,
2064 present_elems, assoc_data);
2065 put_unaligned_le16(link_capab, capab_pos);
2067 /* if present, add any custom non-vendor IEs */
2068 if (assoc_data->ie_len) {
2069 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
2072 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
2076 if (assoc_data->wmm) {
2077 if (assoc_data->uapsd) {
2078 qos_info = ifmgd->uapsd_queues;
2079 qos_info |= (ifmgd->uapsd_max_sp_len <<
2080 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
2085 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
2088 /* add any remaining custom (i.e. vendor specific here) IEs */
2089 if (assoc_data->ie_len) {
2090 noffset = assoc_data->ie_len;
2091 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
2094 if (assoc_data->fils_kek_len) {
2095 ret = fils_encrypt_assoc_req(skb, assoc_data);
2102 pos = skb_tail_pointer(skb);
2103 kfree(ifmgd->assoc_req_ies);
2104 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
2105 if (!ifmgd->assoc_req_ies) {
2110 ifmgd->assoc_req_ies_len = pos - ie_start;
2112 info.link_id = assoc_data->assoc_link_id;
2113 drv_mgd_prepare_tx(local, sdata, &info);
2115 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2116 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2117 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2118 IEEE80211_TX_INTFL_MLME_CONN_TX;
2119 ieee80211_tx_skb(sdata, skb);
2124 void ieee80211_send_pspoll(struct ieee80211_local *local,
2125 struct ieee80211_sub_if_data *sdata)
2127 struct ieee80211_pspoll *pspoll;
2128 struct sk_buff *skb;
2130 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
2134 pspoll = (struct ieee80211_pspoll *) skb->data;
2135 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2137 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2138 ieee80211_tx_skb(sdata, skb);
2141 void ieee80211_send_nullfunc(struct ieee80211_local *local,
2142 struct ieee80211_sub_if_data *sdata,
2145 struct sk_buff *skb;
2146 struct ieee80211_hdr_3addr *nullfunc;
2147 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2149 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1,
2150 !ieee80211_hw_check(&local->hw,
2151 DOESNT_SUPPORT_QOS_NDP));
2155 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
2157 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2159 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
2160 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
2162 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2163 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2165 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2166 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
2168 ieee80211_tx_skb(sdata, skb);
2171 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
2172 struct ieee80211_sub_if_data *sdata)
2174 struct sk_buff *skb;
2175 struct ieee80211_hdr *nullfunc;
2178 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2181 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
2185 skb_reserve(skb, local->hw.extra_tx_headroom);
2187 nullfunc = skb_put_zero(skb, 30);
2188 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
2189 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2190 nullfunc->frame_control = fc;
2191 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2192 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2193 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2194 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
2196 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2197 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
2198 ieee80211_tx_skb(sdata, skb);
2201 /* spectrum management related things */
2202 static void ieee80211_csa_switch_work(struct wiphy *wiphy,
2203 struct wiphy_work *work)
2205 struct ieee80211_link_data *link =
2206 container_of(work, struct ieee80211_link_data,
2207 u.mgd.csa.switch_work.work);
2208 struct ieee80211_sub_if_data *sdata = link->sdata;
2209 struct ieee80211_local *local = sdata->local;
2210 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2213 if (!ieee80211_sdata_running(sdata))
2216 lockdep_assert_wiphy(local->hw.wiphy);
2218 if (!ifmgd->associated)
2221 if (!link->conf->csa_active)
2225 * If the link isn't active (now), we cannot wait for beacons, won't
2226 * have a reserved chanctx, etc. Just switch over the chandef and
2227 * update cfg80211 directly.
2229 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) {
2230 link->conf->chanreq = link->csa.chanreq;
2231 cfg80211_ch_switch_notify(sdata->dev, &link->csa.chanreq.oper,
2237 * using reservation isn't immediate as it may be deferred until later
2238 * with multi-vif. once reservation is complete it will re-schedule the
2239 * work with no reserved_chanctx so verify chandef to check if it
2240 * completed successfully
2243 if (link->reserved_chanctx) {
2245 * with multi-vif csa driver may call ieee80211_csa_finish()
2246 * many times while waiting for other interfaces to use their
2249 if (link->reserved_ready)
2252 ret = ieee80211_link_use_reserved_context(link);
2255 "failed to use reserved channel context, disconnecting (err=%d)\n",
2257 wiphy_work_queue(sdata->local->hw.wiphy,
2258 &ifmgd->csa_connection_drop_work);
2263 if (!ieee80211_chanreq_identical(&link->conf->chanreq,
2264 &link->csa.chanreq)) {
2266 "failed to finalize channel switch, disconnecting\n");
2267 wiphy_work_queue(sdata->local->hw.wiphy,
2268 &ifmgd->csa_connection_drop_work);
2272 link->u.mgd.csa.waiting_bcn = true;
2274 /* apply new TPE restrictions immediately on the new channel */
2275 if (link->u.mgd.csa.ap_chandef.chan->band == NL80211_BAND_6GHZ &&
2276 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE) {
2277 ieee80211_rearrange_tpe(&link->u.mgd.csa.tpe,
2278 &link->u.mgd.csa.ap_chandef,
2279 &link->conf->chanreq.oper);
2280 if (memcmp(&link->conf->tpe, &link->u.mgd.csa.tpe,
2281 sizeof(link->u.mgd.csa.tpe))) {
2282 link->conf->tpe = link->u.mgd.csa.tpe;
2283 ieee80211_link_info_change_notify(sdata, link,
2288 ieee80211_sta_reset_beacon_monitor(sdata);
2289 ieee80211_sta_reset_conn_monitor(sdata);
2292 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
2294 struct ieee80211_sub_if_data *sdata = link->sdata;
2295 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2298 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2300 WARN_ON(!link->conf->csa_active);
2302 ieee80211_vif_unblock_queues_csa(sdata);
2304 link->conf->csa_active = false;
2305 link->u.mgd.csa.blocked_tx = false;
2306 link->u.mgd.csa.waiting_bcn = false;
2308 ret = drv_post_channel_switch(link);
2311 "driver post channel switch failed, disconnecting\n");
2312 wiphy_work_queue(sdata->local->hw.wiphy,
2313 &ifmgd->csa_connection_drop_work);
2317 cfg80211_ch_switch_notify(sdata->dev, &link->conf->chanreq.oper,
2321 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success,
2322 unsigned int link_id)
2324 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2326 trace_api_chswitch_done(sdata, success, link_id);
2332 "driver channel switch failed (link %d), disconnecting\n",
2334 wiphy_work_queue(sdata->local->hw.wiphy,
2335 &sdata->u.mgd.csa_connection_drop_work);
2337 struct ieee80211_link_data *link =
2338 rcu_dereference(sdata->link[link_id]);
2340 if (WARN_ON(!link)) {
2345 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
2346 &link->u.mgd.csa.switch_work, 0);
2351 EXPORT_SYMBOL(ieee80211_chswitch_done);
2354 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
2356 struct ieee80211_sub_if_data *sdata = link->sdata;
2357 struct ieee80211_local *local = sdata->local;
2359 lockdep_assert_wiphy(local->hw.wiphy);
2361 if (!local->ops->abort_channel_switch)
2364 ieee80211_link_unreserve_chanctx(link);
2366 ieee80211_vif_unblock_queues_csa(sdata);
2368 link->conf->csa_active = false;
2369 link->u.mgd.csa.blocked_tx = false;
2371 drv_abort_channel_switch(link);
2374 struct sta_csa_rnr_iter_data {
2375 struct ieee80211_link_data *link;
2376 struct ieee80211_channel *chan;
2380 static enum cfg80211_rnr_iter_ret
2381 ieee80211_sta_csa_rnr_iter(void *_data, u8 type,
2382 const struct ieee80211_neighbor_ap_info *info,
2383 const u8 *tbtt_info, u8 tbtt_info_len)
2385 struct sta_csa_rnr_iter_data *data = _data;
2386 struct ieee80211_link_data *link = data->link;
2387 struct ieee80211_sub_if_data *sdata = link->sdata;
2388 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2389 const struct ieee80211_tbtt_info_ge_11 *ti;
2390 enum nl80211_band band;
2391 unsigned int center_freq;
2394 if (type != IEEE80211_TBTT_INFO_TYPE_TBTT)
2395 return RNR_ITER_CONTINUE;
2397 if (tbtt_info_len < sizeof(*ti))
2398 return RNR_ITER_CONTINUE;
2400 ti = (const void *)tbtt_info;
2402 if (ti->mld_params.mld_id != data->mld_id)
2403 return RNR_ITER_CONTINUE;
2405 link_id = le16_get_bits(ti->mld_params.params,
2406 IEEE80211_RNR_MLD_PARAMS_LINK_ID);
2407 if (link_id != data->link->link_id)
2408 return RNR_ITER_CONTINUE;
2410 /* we found the entry for our link! */
2412 /* this AP is confused, it had this right before ... just disconnect */
2413 if (!ieee80211_operating_class_to_band(info->op_class, &band)) {
2415 "AP now has invalid operating class in RNR, disconnect\n");
2416 wiphy_work_queue(sdata->local->hw.wiphy,
2417 &ifmgd->csa_connection_drop_work);
2418 return RNR_ITER_BREAK;
2421 center_freq = ieee80211_channel_to_frequency(info->channel, band);
2422 data->chan = ieee80211_get_channel(sdata->local->hw.wiphy, center_freq);
2424 return RNR_ITER_BREAK;
2428 ieee80211_sta_other_link_csa_disappeared(struct ieee80211_link_data *link,
2429 struct ieee802_11_elems *elems)
2431 struct ieee80211_sub_if_data *sdata = link->sdata;
2432 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2433 struct sta_csa_rnr_iter_data data = {
2438 * If we get here, we see a beacon from another link without
2439 * CSA still being reported for it, so now we have to check
2440 * if the CSA was aborted or completed. This may not even be
2441 * perfectly possible if the CSA was only done for changing
2442 * the puncturing, but in that case if the link in inactive
2443 * we don't really care, and if it's an active link (or when
2444 * it's activated later) we'll get a beacon and adjust.
2447 if (WARN_ON(!elems->ml_basic))
2450 data.mld_id = ieee80211_mle_get_mld_id((const void *)elems->ml_basic);
2453 * So in order to do this, iterate the RNR element(s) and see
2454 * what channel is reported now.
2456 cfg80211_iter_rnr(elems->ie_start, elems->total_len,
2457 ieee80211_sta_csa_rnr_iter, &data);
2461 "couldn't find (valid) channel in RNR for CSA, disconnect\n");
2462 wiphy_work_queue(sdata->local->hw.wiphy,
2463 &ifmgd->csa_connection_drop_work);
2468 * If it doesn't match the CSA, then assume it aborted. This
2469 * may erroneously detect that it was _not_ aborted when it
2470 * was in fact aborted, but only changed the bandwidth or the
2471 * puncturing configuration, but we don't have enough data to
2474 if (data.chan != link->csa.chanreq.oper.chan)
2475 ieee80211_sta_abort_chanswitch(link);
2478 enum ieee80211_csa_source {
2479 IEEE80211_CSA_SOURCE_BEACON,
2480 IEEE80211_CSA_SOURCE_OTHER_LINK,
2481 IEEE80211_CSA_SOURCE_PROT_ACTION,
2482 IEEE80211_CSA_SOURCE_UNPROT_ACTION,
2486 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
2487 u64 timestamp, u32 device_timestamp,
2488 struct ieee802_11_elems *full_elems,
2489 struct ieee802_11_elems *csa_elems,
2490 enum ieee80211_csa_source source)
2492 struct ieee80211_sub_if_data *sdata = link->sdata;
2493 struct ieee80211_local *local = sdata->local;
2494 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2495 struct ieee80211_chanctx *chanctx = NULL;
2496 struct ieee80211_chanctx_conf *conf;
2497 struct ieee80211_csa_ie csa_ie = {};
2498 struct ieee80211_channel_switch ch_switch = {
2499 .link_id = link->link_id,
2500 .timestamp = timestamp,
2501 .device_timestamp = device_timestamp,
2506 lockdep_assert_wiphy(local->hw.wiphy);
2509 struct cfg80211_bss *cbss = link->conf->bss;
2510 enum nl80211_band current_band;
2511 struct ieee80211_bss *bss;
2516 current_band = cbss->channel->band;
2517 bss = (void *)cbss->priv;
2519 res = ieee80211_parse_ch_switch_ie(sdata, csa_elems,
2524 source == IEEE80211_CSA_SOURCE_UNPROT_ACTION,
2527 ch_switch.block_tx = csa_ie.mode;
2528 ch_switch.chandef = csa_ie.chanreq.oper;
2529 ch_switch.count = csa_ie.count;
2530 ch_switch.delay = csa_ie.max_switch_time;
2533 link->u.mgd.csa.tpe = csa_elems->csa_tpe;
2536 * If there was no per-STA profile for this link, we
2537 * get called with csa_elems == NULL. This of course means
2538 * there are no CSA elements, so set res=1 indicating
2545 /* ignore this case, not a protected frame */
2546 if (source == IEEE80211_CSA_SOURCE_UNPROT_ACTION)
2548 goto drop_connection;
2551 if (link->conf->csa_active) {
2553 case IEEE80211_CSA_SOURCE_PROT_ACTION:
2554 case IEEE80211_CSA_SOURCE_UNPROT_ACTION:
2555 /* already processing - disregard action frames */
2557 case IEEE80211_CSA_SOURCE_BEACON:
2558 if (link->u.mgd.csa.waiting_bcn) {
2559 ieee80211_chswitch_post_beacon(link);
2561 * If the CSA is still present after the switch
2562 * we need to consider it as a new CSA (possibly
2563 * to self). This happens by not returning here
2564 * so we'll get to the check below.
2567 ieee80211_sta_abort_chanswitch(link);
2570 drv_channel_switch_rx_beacon(sdata, &ch_switch);
2574 case IEEE80211_CSA_SOURCE_OTHER_LINK:
2575 /* active link: we want to see the beacon to continue */
2576 if (ieee80211_vif_link_active(&sdata->vif,
2580 /* switch work ran, so just complete the process */
2581 if (link->u.mgd.csa.waiting_bcn) {
2582 ieee80211_chswitch_post_beacon(link);
2584 * If the CSA is still present after the switch
2585 * we need to consider it as a new CSA (possibly
2586 * to self). This happens by not returning here
2587 * so we'll get to the check below.
2592 /* link still has CSA but we already know, do nothing */
2596 /* check in the RNR if the CSA aborted */
2597 ieee80211_sta_other_link_csa_disappeared(link,
2603 /* no active CSA nor a new one */
2606 * However, we may have stopped queues when receiving a public
2607 * action frame that couldn't be protected, if it had the quiet
2608 * bit set. This is a trade-off, we want to be quiet as soon as
2609 * possible, but also don't trust the public action frame much,
2610 * as it can't be protected.
2612 if (unlikely(link->u.mgd.csa.blocked_tx)) {
2613 link->u.mgd.csa.blocked_tx = false;
2614 ieee80211_vif_unblock_queues_csa(sdata);
2620 * We don't really trust public action frames, but block queues (go to
2621 * quiet mode) for them anyway, we should get a beacon soon to either
2622 * know what the CSA really is, or figure out the public action frame
2623 * was actually an attack.
2625 if (source == IEEE80211_CSA_SOURCE_UNPROT_ACTION) {
2627 link->u.mgd.csa.blocked_tx = true;
2628 ieee80211_vif_block_queues_csa(sdata);
2633 if (link->conf->chanreq.oper.chan->band !=
2634 csa_ie.chanreq.oper.chan->band) {
2636 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
2638 csa_ie.chanreq.oper.chan->center_freq,
2639 csa_ie.chanreq.oper.width,
2640 csa_ie.chanreq.oper.center_freq1,
2641 csa_ie.chanreq.oper.center_freq2);
2642 goto drop_connection;
2645 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chanreq.oper,
2646 IEEE80211_CHAN_DISABLED)) {
2648 "AP %pM switches to unsupported channel (%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), disconnecting\n",
2650 csa_ie.chanreq.oper.chan->center_freq,
2651 csa_ie.chanreq.oper.chan->freq_offset,
2652 csa_ie.chanreq.oper.width,
2653 csa_ie.chanreq.oper.center_freq1,
2654 csa_ie.chanreq.oper.freq1_offset,
2655 csa_ie.chanreq.oper.center_freq2);
2656 goto drop_connection;
2659 if (cfg80211_chandef_identical(&csa_ie.chanreq.oper,
2660 &link->conf->chanreq.oper) &&
2661 (!csa_ie.mode || source != IEEE80211_CSA_SOURCE_BEACON)) {
2662 if (link->u.mgd.csa.ignored_same_chan)
2665 "AP %pM tries to chanswitch to same channel, ignore\n",
2667 link->u.mgd.csa.ignored_same_chan = true;
2672 * Drop all TDLS peers on the affected link - either we disconnect or
2673 * move to a different channel from this point on. There's no telling
2674 * what our peer will do.
2675 * The TDLS WIDER_BW scenario is also problematic, as peers might now
2676 * have an incompatible wider chandef.
2678 ieee80211_teardown_tdls_peers(link);
2680 conf = rcu_dereference_protected(link->conf->chanctx_conf,
2681 lockdep_is_held(&local->hw.wiphy->mtx));
2682 if (ieee80211_vif_link_active(&sdata->vif, link->link_id) && !conf) {
2684 "no channel context assigned to vif?, disconnecting\n");
2685 goto drop_connection;
2689 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
2691 if (!ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
2693 "driver doesn't support chan-switch with channel contexts\n");
2694 goto drop_connection;
2697 if (drv_pre_channel_switch(sdata, &ch_switch)) {
2699 "preparing for channel switch failed, disconnecting\n");
2700 goto drop_connection;
2703 link->u.mgd.csa.ap_chandef = csa_ie.chanreq.ap;
2705 link->csa.chanreq.oper = csa_ie.chanreq.oper;
2706 ieee80211_set_chanreq_ap(sdata, &link->csa.chanreq, &link->u.mgd.conn,
2707 &csa_ie.chanreq.ap);
2710 res = ieee80211_link_reserve_chanctx(link, &link->csa.chanreq,
2711 chanctx->mode, false);
2714 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
2716 goto drop_connection;
2720 link->conf->csa_active = true;
2721 link->u.mgd.csa.ignored_same_chan = false;
2722 link->u.mgd.beacon_crc_valid = false;
2723 link->u.mgd.csa.blocked_tx = csa_ie.mode;
2726 ieee80211_vif_block_queues_csa(sdata);
2728 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chanreq.oper,
2729 link->link_id, csa_ie.count,
2732 /* we may have to handle timeout for deactivated link in software */
2734 link->u.mgd.csa.time = now +
2735 TU_TO_JIFFIES((max_t(int, csa_ie.count, 1) - 1) *
2736 link->conf->beacon_int);
2738 if (ieee80211_vif_link_active(&sdata->vif, link->link_id) &&
2739 local->ops->channel_switch) {
2741 * Use driver's channel switch callback, the driver will
2742 * later call ieee80211_chswitch_done(). It may deactivate
2743 * the link as well, we handle that elsewhere and queue
2744 * the csa.switch_work for the calculated time then.
2746 drv_channel_switch(local, sdata, &ch_switch);
2750 /* channel switch handled in software */
2751 wiphy_delayed_work_queue(local->hw.wiphy,
2752 &link->u.mgd.csa.switch_work,
2753 link->u.mgd.csa.time - now);
2757 * This is just so that the disconnect flow will know that
2758 * we were trying to switch channel and failed. In case the
2759 * mode is 1 (we are not allowed to Tx), we will know not to
2760 * send a deauthentication frame. Those two fields will be
2761 * reset when the disconnection worker runs.
2763 link->conf->csa_active = true;
2764 link->u.mgd.csa.blocked_tx = csa_ie.mode;
2766 wiphy_work_queue(sdata->local->hw.wiphy,
2767 &ifmgd->csa_connection_drop_work);
2770 struct sta_bss_param_ch_cnt_data {
2771 struct ieee80211_sub_if_data *sdata;
2772 u8 reporting_link_id;
2776 static enum cfg80211_rnr_iter_ret
2777 ieee80211_sta_bss_param_ch_cnt_iter(void *_data, u8 type,
2778 const struct ieee80211_neighbor_ap_info *info,
2779 const u8 *tbtt_info, u8 tbtt_info_len)
2781 struct sta_bss_param_ch_cnt_data *data = _data;
2782 struct ieee80211_sub_if_data *sdata = data->sdata;
2783 const struct ieee80211_tbtt_info_ge_11 *ti;
2784 u8 bss_param_ch_cnt;
2787 if (type != IEEE80211_TBTT_INFO_TYPE_TBTT)
2788 return RNR_ITER_CONTINUE;
2790 if (tbtt_info_len < sizeof(*ti))
2791 return RNR_ITER_CONTINUE;
2793 ti = (const void *)tbtt_info;
2795 if (ti->mld_params.mld_id != data->mld_id)
2796 return RNR_ITER_CONTINUE;
2798 link_id = le16_get_bits(ti->mld_params.params,
2799 IEEE80211_RNR_MLD_PARAMS_LINK_ID);
2801 le16_get_bits(ti->mld_params.params,
2802 IEEE80211_RNR_MLD_PARAMS_BSS_CHANGE_COUNT);
2804 if (bss_param_ch_cnt != 255 &&
2805 link_id < ARRAY_SIZE(sdata->link)) {
2806 struct ieee80211_link_data *link =
2807 sdata_dereference(sdata->link[link_id], sdata);
2809 if (link && link->conf->bss_param_ch_cnt != bss_param_ch_cnt) {
2810 link->conf->bss_param_ch_cnt = bss_param_ch_cnt;
2811 link->conf->bss_param_ch_cnt_link_id =
2812 data->reporting_link_id;
2816 return RNR_ITER_CONTINUE;
2820 ieee80211_mgd_update_bss_param_ch_cnt(struct ieee80211_sub_if_data *sdata,
2821 struct ieee80211_bss_conf *bss_conf,
2822 struct ieee802_11_elems *elems)
2824 struct sta_bss_param_ch_cnt_data data = {
2825 .reporting_link_id = bss_conf->link_id,
2828 int bss_param_ch_cnt;
2830 if (!elems->ml_basic)
2833 data.mld_id = ieee80211_mle_get_mld_id((const void *)elems->ml_basic);
2835 cfg80211_iter_rnr(elems->ie_start, elems->total_len,
2836 ieee80211_sta_bss_param_ch_cnt_iter, &data);
2839 ieee80211_mle_get_bss_param_ch_cnt((const void *)elems->ml_basic);
2842 * Update bss_param_ch_cnt_link_id even if bss_param_ch_cnt
2843 * didn't change to indicate that we got a beacon on our own
2846 if (bss_param_ch_cnt >= 0 && bss_param_ch_cnt != 255) {
2847 bss_conf->bss_param_ch_cnt = bss_param_ch_cnt;
2848 bss_conf->bss_param_ch_cnt_link_id =
2854 ieee80211_find_80211h_pwr_constr(struct ieee80211_channel *channel,
2855 const u8 *country_ie, u8 country_ie_len,
2856 const u8 *pwr_constr_elem,
2857 int *chan_pwr, int *pwr_reduction)
2859 struct ieee80211_country_ie_triplet *triplet;
2860 int chan = ieee80211_frequency_to_channel(channel->center_freq);
2861 int i, chan_increment;
2862 bool have_chan_pwr = false;
2865 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
2868 triplet = (void *)(country_ie + 3);
2869 country_ie_len -= 3;
2871 switch (channel->band) {
2875 case NL80211_BAND_2GHZ:
2876 case NL80211_BAND_60GHZ:
2877 case NL80211_BAND_LC:
2880 case NL80211_BAND_5GHZ:
2883 case NL80211_BAND_6GHZ:
2885 * In the 6 GHz band, the "maximum transmit power level"
2886 * field in the triplets is reserved, and thus will be
2887 * zero and we shouldn't use it to control TX power.
2888 * The actual TX power will be given in the transmit
2889 * power envelope element instead.
2895 while (country_ie_len >= 3) {
2896 u8 first_channel = triplet->chans.first_channel;
2898 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
2901 for (i = 0; i < triplet->chans.num_channels; i++) {
2902 if (first_channel + i * chan_increment == chan) {
2903 have_chan_pwr = true;
2904 *chan_pwr = triplet->chans.max_power;
2913 country_ie_len -= 3;
2916 if (have_chan_pwr && pwr_constr_elem)
2917 *pwr_reduction = *pwr_constr_elem;
2921 return have_chan_pwr;
2924 static void ieee80211_find_cisco_dtpc(struct ieee80211_channel *channel,
2925 const u8 *cisco_dtpc_ie,
2928 /* From practical testing, the first data byte of the DTPC element
2929 * seems to contain the requested dBm level, and the CLI on Cisco
2930 * APs clearly state the range is -127 to 127 dBm, which indicates
2931 * a signed byte, although it seemingly never actually goes negative.
2932 * The other byte seems to always be zero.
2934 *pwr_level = (__s8)cisco_dtpc_ie[4];
2937 static u64 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
2938 struct ieee80211_channel *channel,
2939 struct ieee80211_mgmt *mgmt,
2940 const u8 *country_ie, u8 country_ie_len,
2941 const u8 *pwr_constr_ie,
2942 const u8 *cisco_dtpc_ie)
2944 struct ieee80211_sub_if_data *sdata = link->sdata;
2945 bool has_80211h_pwr = false, has_cisco_pwr = false;
2946 int chan_pwr = 0, pwr_reduction_80211h = 0;
2947 int pwr_level_cisco, pwr_level_80211h;
2949 __le16 capab = mgmt->u.probe_resp.capab_info;
2951 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
2952 return 0; /* TODO */
2955 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
2956 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
2957 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
2958 channel, country_ie, country_ie_len,
2959 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
2961 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
2964 if (cisco_dtpc_ie) {
2965 ieee80211_find_cisco_dtpc(
2966 channel, cisco_dtpc_ie, &pwr_level_cisco);
2967 has_cisco_pwr = true;
2970 if (!has_80211h_pwr && !has_cisco_pwr)
2973 /* If we have both 802.11h and Cisco DTPC, apply both limits
2974 * by picking the smallest of the two power levels advertised.
2976 if (has_80211h_pwr &&
2977 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
2978 new_ap_level = pwr_level_80211h;
2980 if (link->ap_power_level == new_ap_level)
2984 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
2985 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
2987 } else { /* has_cisco_pwr is always true here. */
2988 new_ap_level = pwr_level_cisco;
2990 if (link->ap_power_level == new_ap_level)
2994 "Limiting TX power to %d dBm as advertised by %pM\n",
2995 pwr_level_cisco, link->u.mgd.bssid);
2998 link->ap_power_level = new_ap_level;
2999 if (__ieee80211_recalc_txpower(link))
3000 return BSS_CHANGED_TXPOWER;
3005 static void ieee80211_enable_ps(struct ieee80211_local *local,
3006 struct ieee80211_sub_if_data *sdata)
3008 struct ieee80211_conf *conf = &local->hw.conf;
3011 * If we are scanning right now then the parameters will
3012 * take effect when scan finishes.
3014 if (local->scanning)
3017 if (conf->dynamic_ps_timeout > 0 &&
3018 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
3019 mod_timer(&local->dynamic_ps_timer, jiffies +
3020 msecs_to_jiffies(conf->dynamic_ps_timeout));
3022 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
3023 ieee80211_send_nullfunc(local, sdata, true);
3025 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3026 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3029 conf->flags |= IEEE80211_CONF_PS;
3030 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3034 static void ieee80211_change_ps(struct ieee80211_local *local)
3036 struct ieee80211_conf *conf = &local->hw.conf;
3038 if (local->ps_sdata) {
3039 ieee80211_enable_ps(local, local->ps_sdata);
3040 } else if (conf->flags & IEEE80211_CONF_PS) {
3041 conf->flags &= ~IEEE80211_CONF_PS;
3042 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3043 del_timer_sync(&local->dynamic_ps_timer);
3044 wiphy_work_cancel(local->hw.wiphy,
3045 &local->dynamic_ps_enable_work);
3049 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
3051 struct ieee80211_local *local = sdata->local;
3052 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
3053 struct sta_info *sta = NULL;
3054 bool authorized = false;
3056 if (!mgd->powersave)
3062 if (!mgd->associated)
3065 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
3068 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
3069 !sdata->deflink.u.mgd.have_beacon)
3073 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
3075 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
3081 /* need to hold RTNL or interface lock */
3082 void ieee80211_recalc_ps(struct ieee80211_local *local)
3084 struct ieee80211_sub_if_data *sdata, *found = NULL;
3088 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
3089 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
3090 local->ps_sdata = NULL;
3094 list_for_each_entry(sdata, &local->interfaces, list) {
3095 if (!ieee80211_sdata_running(sdata))
3097 if (sdata->vif.type == NL80211_IFTYPE_AP) {
3098 /* If an AP vif is found, then disable PS
3099 * by setting the count to zero thereby setting
3105 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3111 if (count == 1 && ieee80211_powersave_allowed(found)) {
3112 u8 dtimper = found->deflink.u.mgd.dtim_period;
3114 timeout = local->dynamic_ps_forced_timeout;
3117 local->hw.conf.dynamic_ps_timeout = timeout;
3119 /* If the TIM IE is invalid, pretend the value is 1 */
3123 local->hw.conf.ps_dtim_period = dtimper;
3124 local->ps_sdata = found;
3126 local->ps_sdata = NULL;
3129 ieee80211_change_ps(local);
3132 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
3134 bool ps_allowed = ieee80211_powersave_allowed(sdata);
3136 if (sdata->vif.cfg.ps != ps_allowed) {
3137 sdata->vif.cfg.ps = ps_allowed;
3138 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
3142 void ieee80211_dynamic_ps_disable_work(struct wiphy *wiphy,
3143 struct wiphy_work *work)
3145 struct ieee80211_local *local =
3146 container_of(work, struct ieee80211_local,
3147 dynamic_ps_disable_work);
3149 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3150 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3151 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3154 ieee80211_wake_queues_by_reason(&local->hw,
3155 IEEE80211_MAX_QUEUE_MAP,
3156 IEEE80211_QUEUE_STOP_REASON_PS,
3160 void ieee80211_dynamic_ps_enable_work(struct wiphy *wiphy,
3161 struct wiphy_work *work)
3163 struct ieee80211_local *local =
3164 container_of(work, struct ieee80211_local,
3165 dynamic_ps_enable_work);
3166 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
3167 struct ieee80211_if_managed *ifmgd;
3168 unsigned long flags;
3171 /* can only happen when PS was just disabled anyway */
3175 ifmgd = &sdata->u.mgd;
3177 if (local->hw.conf.flags & IEEE80211_CONF_PS)
3180 if (local->hw.conf.dynamic_ps_timeout > 0) {
3181 /* don't enter PS if TX frames are pending */
3182 if (drv_tx_frames_pending(local)) {
3183 mod_timer(&local->dynamic_ps_timer, jiffies +
3185 local->hw.conf.dynamic_ps_timeout));
3190 * transmission can be stopped by others which leads to
3191 * dynamic_ps_timer expiry. Postpone the ps timer if it
3192 * is not the actual idle state.
3194 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3195 for (q = 0; q < local->hw.queues; q++) {
3196 if (local->queue_stop_reasons[q]) {
3197 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
3199 mod_timer(&local->dynamic_ps_timer, jiffies +
3201 local->hw.conf.dynamic_ps_timeout));
3205 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3208 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3209 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
3210 if (drv_tx_frames_pending(local)) {
3211 mod_timer(&local->dynamic_ps_timer, jiffies +
3213 local->hw.conf.dynamic_ps_timeout));
3215 ieee80211_send_nullfunc(local, sdata, true);
3216 /* Flush to get the tx status of nullfunc frame */
3217 ieee80211_flush_queues(local, sdata, false);
3221 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
3222 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
3223 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
3224 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
3225 local->hw.conf.flags |= IEEE80211_CONF_PS;
3226 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3230 void ieee80211_dynamic_ps_timer(struct timer_list *t)
3232 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
3234 wiphy_work_queue(local->hw.wiphy, &local->dynamic_ps_enable_work);
3237 void ieee80211_dfs_cac_timer_work(struct wiphy *wiphy, struct wiphy_work *work)
3239 struct ieee80211_link_data *link =
3240 container_of(work, struct ieee80211_link_data,
3241 dfs_cac_timer_work.work);
3242 struct cfg80211_chan_def chandef = link->conf->chanreq.oper;
3243 struct ieee80211_sub_if_data *sdata = link->sdata;
3245 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3247 if (sdata->wdev.links[link->link_id].cac_started) {
3248 ieee80211_link_release_channel(link);
3249 cfg80211_cac_event(sdata->dev, &chandef,
3250 NL80211_RADAR_CAC_FINISHED,
3251 GFP_KERNEL, link->link_id);
3256 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
3258 struct ieee80211_local *local = sdata->local;
3259 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3263 if (local->hw.queues < IEEE80211_NUM_ACS)
3266 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3267 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3269 unsigned long now = jiffies;
3271 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
3272 tx_tspec->admitted_time &&
3273 time_after(now, tx_tspec->time_slice_start + HZ)) {
3274 tx_tspec->consumed_tx_time = 0;
3275 tx_tspec->time_slice_start = now;
3277 if (tx_tspec->downgraded)
3279 TX_TSPEC_ACTION_STOP_DOWNGRADE;
3282 switch (tx_tspec->action) {
3283 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
3284 /* take the original parameters */
3285 if (drv_conf_tx(local, &sdata->deflink, ac,
3286 &sdata->deflink.tx_conf[ac]))
3287 link_err(&sdata->deflink,
3288 "failed to set TX queue parameters for queue %d\n",
3290 tx_tspec->action = TX_TSPEC_ACTION_NONE;
3291 tx_tspec->downgraded = false;
3294 case TX_TSPEC_ACTION_DOWNGRADE:
3295 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3296 tx_tspec->action = TX_TSPEC_ACTION_NONE;
3300 /* downgrade next lower non-ACM AC */
3301 for (non_acm_ac = ac + 1;
3302 non_acm_ac < IEEE80211_NUM_ACS;
3304 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
3306 /* Usually the loop will result in using BK even if it
3307 * requires admission control, but such a configuration
3308 * makes no sense and we have to transmit somehow - the
3309 * AC selection does the same thing.
3310 * If we started out trying to downgrade from BK, then
3311 * the extra condition here might be needed.
3313 if (non_acm_ac >= IEEE80211_NUM_ACS)
3314 non_acm_ac = IEEE80211_AC_BK;
3315 if (drv_conf_tx(local, &sdata->deflink, ac,
3316 &sdata->deflink.tx_conf[non_acm_ac]))
3317 link_err(&sdata->deflink,
3318 "failed to set TX queue parameters for queue %d\n",
3320 tx_tspec->action = TX_TSPEC_ACTION_NONE;
3322 wiphy_delayed_work_queue(local->hw.wiphy,
3323 &ifmgd->tx_tspec_wk,
3324 tx_tspec->time_slice_start +
3327 case TX_TSPEC_ACTION_NONE:
3336 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
3338 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
3339 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3343 static void ieee80211_sta_handle_tspec_ac_params_wk(struct wiphy *wiphy,
3344 struct wiphy_work *work)
3346 struct ieee80211_sub_if_data *sdata;
3348 sdata = container_of(work, struct ieee80211_sub_if_data,
3349 u.mgd.tx_tspec_wk.work);
3350 ieee80211_sta_handle_tspec_ac_params(sdata);
3353 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
3355 struct ieee80211_sub_if_data *sdata = link->sdata;
3356 struct ieee80211_local *local = sdata->local;
3357 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3358 struct ieee80211_tx_queue_params *params = link->tx_conf;
3361 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3363 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
3365 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
3366 params[ac].txop, params[ac].uapsd,
3367 ifmgd->tx_tspec[ac].downgraded);
3368 if (!ifmgd->tx_tspec[ac].downgraded &&
3369 drv_conf_tx(local, link, ac, ¶ms[ac]))
3371 "failed to set TX queue parameters for AC %d\n",
3378 ieee80211_sta_wmm_params(struct ieee80211_local *local,
3379 struct ieee80211_link_data *link,
3380 const u8 *wmm_param, size_t wmm_param_len,
3381 const struct ieee80211_mu_edca_param_set *mu_edca)
3383 struct ieee80211_sub_if_data *sdata = link->sdata;
3384 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
3385 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3387 int count, mu_edca_count, ac;
3389 u8 uapsd_queues = 0;
3391 if (!local->ops->conf_tx)
3394 if (local->hw.queues < IEEE80211_NUM_ACS)
3400 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
3403 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
3404 uapsd_queues = ifmgd->uapsd_queues;
3406 count = wmm_param[6] & 0x0f;
3407 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
3408 * if mu_edca was preset before and now it disappeared tell
3409 * the driver about it.
3411 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
3412 if (count == link->u.mgd.wmm_last_param_set &&
3413 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
3415 link->u.mgd.wmm_last_param_set = count;
3416 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
3418 pos = wmm_param + 8;
3419 left = wmm_param_len - 8;
3421 memset(¶ms, 0, sizeof(params));
3424 for (; left >= 4; left -= 4, pos += 4) {
3425 int aci = (pos[0] >> 5) & 0x03;
3426 int acm = (pos[0] >> 4) & 0x01;
3431 ac = IEEE80211_AC_BK;
3433 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
3434 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
3436 params[ac].mu_edca = !!mu_edca;
3438 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
3441 ac = IEEE80211_AC_VI;
3443 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
3444 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
3446 params[ac].mu_edca = !!mu_edca;
3448 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
3451 ac = IEEE80211_AC_VO;
3453 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
3454 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
3456 params[ac].mu_edca = !!mu_edca;
3458 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
3462 ac = IEEE80211_AC_BE;
3464 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
3465 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
3467 params[ac].mu_edca = !!mu_edca;
3469 params[ac].mu_edca_param_rec = mu_edca->ac_be;
3473 params[ac].aifs = pos[0] & 0x0f;
3475 if (params[ac].aifs < 2) {
3477 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
3478 params[ac].aifs, aci);
3479 params[ac].aifs = 2;
3481 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
3482 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
3483 params[ac].txop = get_unaligned_le16(pos + 2);
3484 params[ac].acm = acm;
3485 params[ac].uapsd = uapsd;
3487 if (params[ac].cw_min == 0 ||
3488 params[ac].cw_min > params[ac].cw_max) {
3490 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
3491 params[ac].cw_min, params[ac].cw_max, aci);
3494 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
3497 /* WMM specification requires all 4 ACIs. */
3498 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3499 if (params[ac].cw_min == 0) {
3501 "AP has invalid WMM params (missing AC %d), using defaults\n",
3507 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3508 link->tx_conf[ac] = params[ac];
3510 ieee80211_mgd_set_link_qos_params(link);
3512 /* enable WMM or activate new settings */
3513 link->conf->qos = true;
3517 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
3519 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3521 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
3522 ieee80211_run_deferred_scan(sdata->local);
3525 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
3527 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3529 __ieee80211_stop_poll(sdata);
3532 static u64 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
3533 u16 capab, bool erp_valid, u8 erp)
3535 struct ieee80211_bss_conf *bss_conf = link->conf;
3536 struct ieee80211_supported_band *sband;
3538 bool use_protection;
3539 bool use_short_preamble;
3540 bool use_short_slot;
3542 sband = ieee80211_get_link_sband(link);
3547 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
3548 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
3550 use_protection = false;
3551 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
3554 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
3555 if (sband->band == NL80211_BAND_5GHZ ||
3556 sband->band == NL80211_BAND_6GHZ)
3557 use_short_slot = true;
3559 if (use_protection != bss_conf->use_cts_prot) {
3560 bss_conf->use_cts_prot = use_protection;
3561 changed |= BSS_CHANGED_ERP_CTS_PROT;
3564 if (use_short_preamble != bss_conf->use_short_preamble) {
3565 bss_conf->use_short_preamble = use_short_preamble;
3566 changed |= BSS_CHANGED_ERP_PREAMBLE;
3569 if (use_short_slot != bss_conf->use_short_slot) {
3570 bss_conf->use_short_slot = use_short_slot;
3571 changed |= BSS_CHANGED_ERP_SLOT;
3577 static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link,
3578 struct cfg80211_bss *cbss)
3580 struct ieee80211_sub_if_data *sdata = link->sdata;
3581 struct ieee80211_bss_conf *bss_conf = link->conf;
3582 struct ieee80211_bss *bss = (void *)cbss->priv;
3583 u64 changed = BSS_CHANGED_QOS;
3585 /* not really used in MLO */
3586 sdata->u.mgd.beacon_timeout =
3587 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
3588 bss_conf->beacon_int));
3590 changed |= ieee80211_handle_bss_capability(link,
3591 bss_conf->assoc_capability,
3595 ieee80211_check_rate_mask(link);
3597 link->conf->bss = cbss;
3598 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
3600 if (sdata->vif.p2p ||
3601 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
3602 const struct cfg80211_bss_ies *ies;
3605 ies = rcu_dereference(cbss->ies);
3609 ret = cfg80211_get_p2p_attr(
3610 ies->data, ies->len,
3611 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
3612 (u8 *) &bss_conf->p2p_noa_attr,
3613 sizeof(bss_conf->p2p_noa_attr));
3615 link->u.mgd.p2p_noa_index =
3616 bss_conf->p2p_noa_attr.index;
3617 changed |= BSS_CHANGED_P2P_PS;
3623 if (link->u.mgd.have_beacon) {
3624 bss_conf->beacon_rate = bss->beacon_rate;
3625 changed |= BSS_CHANGED_BEACON_INFO;
3627 bss_conf->beacon_rate = NULL;
3630 /* Tell the driver to monitor connection quality (if supported) */
3631 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
3632 bss_conf->cqm_rssi_thold)
3633 changed |= BSS_CHANGED_CQM;
3638 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
3639 struct ieee80211_mgd_assoc_data *assoc_data,
3640 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
3642 struct ieee80211_local *local = sdata->local;
3643 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
3644 u64 vif_changed = BSS_CHANGED_ASSOC;
3645 unsigned int link_id;
3647 lockdep_assert_wiphy(local->hw.wiphy);
3649 sdata->u.mgd.associated = true;
3651 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
3652 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
3653 struct ieee80211_link_data *link;
3656 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
3659 if (ieee80211_vif_is_mld(&sdata->vif) &&
3660 !(ieee80211_vif_usable_links(&sdata->vif) & BIT(link_id)))
3663 link = sdata_dereference(sdata->link[link_id], sdata);
3667 changed[link_id] |= ieee80211_link_set_associated(link, cbss);
3670 /* just to be sure */
3671 ieee80211_stop_poll(sdata);
3673 ieee80211_led_assoc(local, 1);
3677 /* Enable ARP filtering */
3678 if (vif_cfg->arp_addr_cnt)
3679 vif_changed |= BSS_CHANGED_ARP_FILTER;
3681 if (ieee80211_vif_is_mld(&sdata->vif)) {
3683 link_id < IEEE80211_MLD_MAX_NUM_LINKS;
3685 struct ieee80211_link_data *link;
3686 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
3690 ieee80211_vif_usable_links(&sdata->vif)) ||
3691 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
3694 link = sdata_dereference(sdata->link[link_id], sdata);
3698 ieee80211_link_info_change_notify(sdata, link,
3701 ieee80211_recalc_smps(sdata, link);
3704 ieee80211_vif_cfg_change_notify(sdata, vif_changed);
3706 ieee80211_bss_info_change_notify(sdata,
3707 vif_changed | changed[0]);
3710 ieee80211_recalc_ps(local);
3712 /* leave this here to not change ordering in non-MLO cases */
3713 if (!ieee80211_vif_is_mld(&sdata->vif))
3714 ieee80211_recalc_smps(sdata, &sdata->deflink);
3715 ieee80211_recalc_ps_vif(sdata);
3717 netif_carrier_on(sdata->dev);
3720 static void ieee80211_ml_reconf_reset(struct ieee80211_sub_if_data *sdata)
3722 struct ieee80211_mgd_assoc_data *add_links_data =
3723 sdata->u.mgd.reconf.add_links_data;
3725 if (!ieee80211_vif_is_mld(&sdata->vif) ||
3726 !(sdata->u.mgd.reconf.added_links |
3727 sdata->u.mgd.reconf.removed_links))
3730 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
3731 &sdata->u.mgd.reconf.wk);
3732 sdata->u.mgd.reconf.added_links = 0;
3733 sdata->u.mgd.reconf.removed_links = 0;
3734 sdata->u.mgd.reconf.dialog_token = 0;
3736 if (add_links_data) {
3737 struct cfg80211_mlo_reconf_done_data done_data = {};
3740 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
3742 done_data.links[link_id].bss =
3743 add_links_data->link[link_id].bss;
3745 cfg80211_mlo_reconf_add_done(sdata->dev, &done_data);
3747 kfree(sdata->u.mgd.reconf.add_links_data);
3748 sdata->u.mgd.reconf.add_links_data = NULL;
3752 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
3753 u16 stype, u16 reason, bool tx,
3756 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3757 struct ieee80211_local *local = sdata->local;
3758 struct sta_info *ap_sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
3759 unsigned int link_id;
3761 struct ieee80211_prep_tx_info info = {
3764 .link_id = ffs(sdata->vif.active_links) - 1,
3767 lockdep_assert_wiphy(local->hw.wiphy);
3769 if (WARN_ON(!ap_sta))
3772 if (WARN_ON_ONCE(tx && !frame_buf))
3775 if (WARN_ON(!ifmgd->associated))
3778 ieee80211_stop_poll(sdata);
3780 ifmgd->associated = false;
3782 /* other links will be destroyed */
3783 sdata->deflink.conf->bss = NULL;
3784 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3786 netif_carrier_off(sdata->dev);
3789 * if we want to get out of ps before disassoc (why?) we have
3790 * to do it before sending disassoc, as otherwise the null-packet
3793 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3794 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3795 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3797 local->ps_sdata = NULL;
3799 /* disable per-vif ps */
3800 ieee80211_recalc_ps_vif(sdata);
3802 /* make sure ongoing transmission finishes */
3806 * drop any frame before deauth/disassoc, this can be data or
3807 * management frame. Since we are disconnecting, we should not
3808 * insist sending these frames which can take time and delay
3809 * the disconnection and possible the roaming.
3812 ieee80211_flush_queues(local, sdata, true);
3814 /* deauthenticate/disassociate now */
3815 if (tx || frame_buf) {
3816 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3818 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
3819 sdata->vif.cfg.ap_addr, stype,
3820 reason, tx, frame_buf);
3823 /* flush out frame - make sure the deauth was actually sent */
3825 ieee80211_flush_queues(local, sdata, false);
3827 drv_mgd_complete_tx(sdata->local, sdata, &info);
3829 /* clear AP addr only after building the needed mgmt frames */
3830 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3831 eth_zero_addr(sdata->vif.cfg.ap_addr);
3833 sdata->vif.cfg.ssid_len = 0;
3835 /* Remove TDLS peers */
3836 __sta_info_flush(sdata, false, -1, ap_sta);
3838 if (sdata->vif.driver_flags & IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC) {
3839 /* Only move the AP state */
3840 sta_info_move_state(ap_sta, IEEE80211_STA_NONE);
3842 /* Remove AP peer */
3843 sta_info_flush(sdata, -1);
3846 /* finally reset all BSS / config parameters */
3847 if (!ieee80211_vif_is_mld(&sdata->vif))
3848 changed |= ieee80211_reset_erp_info(sdata);
3850 ieee80211_led_assoc(local, 0);
3851 changed |= BSS_CHANGED_ASSOC;
3852 sdata->vif.cfg.assoc = false;
3854 sdata->deflink.u.mgd.p2p_noa_index = -1;
3855 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
3856 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
3858 /* on the next assoc, re-program HT/VHT parameters */
3859 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
3860 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
3861 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
3862 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
3865 * reset MU-MIMO ownership and group data in default link,
3866 * if used, other links are destroyed
3868 memset(sdata->vif.bss_conf.mu_group.membership, 0,
3869 sizeof(sdata->vif.bss_conf.mu_group.membership));
3870 memset(sdata->vif.bss_conf.mu_group.position, 0,
3871 sizeof(sdata->vif.bss_conf.mu_group.position));
3872 if (!ieee80211_vif_is_mld(&sdata->vif))
3873 changed |= BSS_CHANGED_MU_GROUPS;
3874 sdata->vif.bss_conf.mu_mimo_owner = false;
3876 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
3878 del_timer_sync(&local->dynamic_ps_timer);
3879 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work);
3881 /* Disable ARP filtering */
3882 if (sdata->vif.cfg.arp_addr_cnt)
3883 changed |= BSS_CHANGED_ARP_FILTER;
3885 sdata->vif.bss_conf.qos = false;
3886 if (!ieee80211_vif_is_mld(&sdata->vif)) {
3887 changed |= BSS_CHANGED_QOS;
3888 /* The BSSID (not really interesting) and HT changed */
3889 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
3890 ieee80211_bss_info_change_notify(sdata, changed);
3892 ieee80211_vif_cfg_change_notify(sdata, changed);
3895 if (sdata->vif.driver_flags & IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC) {
3897 * After notifying the driver about the disassoc,
3898 * remove the ap sta.
3900 sta_info_flush(sdata, -1);
3903 /* disassociated - set to defaults now */
3904 ieee80211_set_wmm_default(&sdata->deflink, false, false);
3906 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
3907 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
3908 del_timer_sync(&sdata->u.mgd.timer);
3910 sdata->vif.bss_conf.dtim_period = 0;
3911 sdata->vif.bss_conf.beacon_rate = NULL;
3913 sdata->deflink.u.mgd.have_beacon = false;
3914 sdata->deflink.u.mgd.tracking_signal_avg = false;
3915 sdata->deflink.u.mgd.disable_wmm_tracking = false;
3919 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3920 struct ieee80211_link_data *link;
3922 link = sdata_dereference(sdata->link[link_id], sdata);
3925 ieee80211_link_release_channel(link);
3928 sdata->vif.bss_conf.csa_active = false;
3929 sdata->deflink.u.mgd.csa.blocked_tx = false;
3930 sdata->deflink.u.mgd.csa.waiting_bcn = false;
3931 sdata->deflink.u.mgd.csa.ignored_same_chan = false;
3932 ieee80211_vif_unblock_queues_csa(sdata);
3934 /* existing TX TSPEC sessions no longer exist */
3935 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
3936 wiphy_delayed_work_cancel(local->hw.wiphy, &ifmgd->tx_tspec_wk);
3938 sdata->vif.bss_conf.power_type = IEEE80211_REG_UNSET_AP;
3939 sdata->vif.bss_conf.pwr_reduction = 0;
3940 ieee80211_clear_tpe(&sdata->vif.bss_conf.tpe);
3942 sdata->vif.cfg.eml_cap = 0;
3943 sdata->vif.cfg.eml_med_sync_delay = 0;
3944 sdata->vif.cfg.mld_capa_op = 0;
3946 memset(&sdata->u.mgd.ttlm_info, 0,
3947 sizeof(sdata->u.mgd.ttlm_info));
3948 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
3950 memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm));
3951 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
3952 &ifmgd->neg_ttlm_timeout_work);
3954 sdata->u.mgd.removed_links = 0;
3955 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
3956 &sdata->u.mgd.ml_reconf_work);
3958 wiphy_work_cancel(sdata->local->hw.wiphy,
3959 &ifmgd->teardown_ttlm_work);
3961 ieee80211_vif_set_links(sdata, 0, 0);
3963 ifmgd->mcast_seq_last = IEEE80211_SN_MODULO;
3965 /* if disconnection happens in the middle of the ML reconfiguration
3966 * flow, cfg80211 must called to release the BSS references obtained
3967 * when the flow started.
3969 ieee80211_ml_reconf_reset(sdata);
3972 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
3974 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3975 struct ieee80211_local *local = sdata->local;
3977 lockdep_assert_wiphy(local->hw.wiphy);
3979 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
3982 __ieee80211_stop_poll(sdata);
3984 ieee80211_recalc_ps(local);
3986 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3990 * We've received a probe response, but are not sure whether
3991 * we have or will be receiving any beacons or data, so let's
3992 * schedule the timers again, just in case.
3994 ieee80211_sta_reset_beacon_monitor(sdata);
3996 mod_timer(&ifmgd->conn_mon_timer,
3997 round_jiffies_up(jiffies +
3998 IEEE80211_CONNECTION_IDLE_TIME));
4001 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
4002 struct ieee80211_hdr *hdr,
4005 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4008 struct ieee80211_sta_tx_tspec *tx_tspec;
4009 unsigned long now = jiffies;
4011 if (!ieee80211_is_data_qos(hdr->frame_control))
4014 tid = ieee80211_get_tid(hdr);
4015 ac = ieee80211_ac_from_tid(tid);
4016 tx_tspec = &ifmgd->tx_tspec[ac];
4018 if (likely(!tx_tspec->admitted_time))
4021 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
4022 tx_tspec->consumed_tx_time = 0;
4023 tx_tspec->time_slice_start = now;
4025 if (tx_tspec->downgraded) {
4026 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4027 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
4028 &ifmgd->tx_tspec_wk, 0);
4032 if (tx_tspec->downgraded)
4035 tx_tspec->consumed_tx_time += tx_time;
4037 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
4038 tx_tspec->downgraded = true;
4039 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
4040 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
4041 &ifmgd->tx_tspec_wk, 0);
4045 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
4046 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
4048 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
4050 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
4051 !sdata->u.mgd.probe_send_count)
4055 sdata->u.mgd.probe_send_count = 0;
4057 sdata->u.mgd.nullfunc_failed = true;
4058 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
4061 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
4062 const u8 *src, const u8 *dst,
4063 const u8 *ssid, size_t ssid_len,
4064 struct ieee80211_channel *channel)
4066 struct sk_buff *skb;
4068 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
4069 ssid, ssid_len, NULL, 0,
4070 IEEE80211_PROBE_FLAG_DIRECTED);
4072 ieee80211_tx_skb(sdata, skb);
4075 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
4077 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4078 u8 *dst = sdata->vif.cfg.ap_addr;
4079 u8 unicast_limit = max(1, max_probe_tries - 3);
4080 struct sta_info *sta;
4082 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4084 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
4088 * Try sending broadcast probe requests for the last three
4089 * probe requests after the first ones failed since some
4090 * buggy APs only support broadcast probe requests.
4092 if (ifmgd->probe_send_count >= unicast_limit)
4096 * When the hardware reports an accurate Tx ACK status, it's
4097 * better to send a nullfunc frame instead of a probe request,
4098 * as it will kick us off the AP quickly if we aren't associated
4099 * anymore. The timeout will be reset if the frame is ACKed by
4102 ifmgd->probe_send_count++;
4105 sta = sta_info_get(sdata, dst);
4107 ieee80211_check_fast_rx(sta);
4110 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
4111 ifmgd->nullfunc_failed = false;
4112 ieee80211_send_nullfunc(sdata->local, sdata, false);
4114 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
4115 sdata->vif.cfg.ssid,
4116 sdata->vif.cfg.ssid_len,
4117 sdata->deflink.conf->bss->channel);
4120 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
4121 run_again(sdata, ifmgd->probe_timeout);
4124 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
4127 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4128 bool already = false;
4130 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4132 if (WARN_ON_ONCE(ieee80211_vif_is_mld(&sdata->vif)))
4135 if (!ieee80211_sdata_running(sdata))
4138 if (!ifmgd->associated)
4141 if (sdata->local->tmp_channel || sdata->local->scanning)
4144 if (sdata->local->suspending) {
4145 /* reschedule after resume */
4146 ieee80211_reset_ap_probe(sdata);
4151 mlme_dbg_ratelimited(sdata,
4152 "detected beacon loss from AP (missed %d beacons) - probing\n",
4155 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
4159 * The driver/our work has already reported this event or the
4160 * connection monitoring has kicked in and we have already sent
4161 * a probe request. Or maybe the AP died and the driver keeps
4162 * reporting until we disassociate...
4164 * In either case we have to ignore the current call to this
4165 * function (except for setting the correct probe reason bit)
4166 * because otherwise we would reset the timer every time and
4167 * never check whether we received a probe response!
4169 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
4172 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
4177 ieee80211_recalc_ps(sdata->local);
4179 ifmgd->probe_send_count = 0;
4180 ieee80211_mgd_probe_ap_send(sdata);
4183 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
4184 struct ieee80211_vif *vif)
4186 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4187 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4188 struct cfg80211_bss *cbss;
4189 struct sk_buff *skb;
4190 const struct element *ssid;
4193 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4195 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
4196 ieee80211_vif_is_mld(&sdata->vif)))
4199 if (ifmgd->associated)
4200 cbss = sdata->deflink.conf->bss;
4201 else if (ifmgd->auth_data)
4202 cbss = ifmgd->auth_data->bss;
4203 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
4204 cbss = ifmgd->assoc_data->link[0].bss;
4209 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
4210 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
4211 "invalid SSID element (len=%d)",
4212 ssid ? ssid->datalen : -1))
4215 ssid_len = ssid->datalen;
4217 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
4218 (u32) -1, cbss->channel,
4219 ssid->data, ssid_len,
4220 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
4225 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
4227 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
4228 const u8 *buf, size_t len, bool tx,
4229 u16 reason, bool reconnect)
4231 struct ieee80211_event event = {
4233 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
4234 .u.mlme.reason = reason,
4238 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
4240 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
4242 drv_event_callback(sdata->local, sdata, &event);
4245 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
4247 struct ieee80211_local *local = sdata->local;
4248 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4249 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4252 lockdep_assert_wiphy(local->hw.wiphy);
4254 if (!ifmgd->associated)
4257 /* only transmit if we have a link that makes that worthwhile */
4258 for (unsigned int link_id = 0;
4259 link_id < ARRAY_SIZE(sdata->link);
4261 struct ieee80211_link_data *link;
4263 if (!ieee80211_vif_link_active(&sdata->vif, link_id))
4266 link = sdata_dereference(sdata->link[link_id], sdata);
4267 if (WARN_ON_ONCE(!link))
4270 if (link->u.mgd.csa.blocked_tx)
4277 if (!ifmgd->driver_disconnect) {
4278 unsigned int link_id;
4281 * AP is probably out of range (or not reachable for another
4282 * reason) so remove the bss structs for that AP. In the case
4283 * of multi-link, it's not clear that all of them really are
4284 * out of range, but if they weren't the driver likely would
4285 * have switched to just have a single link active?
4288 link_id < ARRAY_SIZE(sdata->link);
4290 struct ieee80211_link_data *link;
4292 link = sdata_dereference(sdata->link[link_id], sdata);
4295 cfg80211_unlink_bss(local->hw.wiphy, link->conf->bss);
4296 link->conf->bss = NULL;
4300 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4301 ifmgd->driver_disconnect ?
4302 WLAN_REASON_DEAUTH_LEAVING :
4303 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4305 /* the other links will be destroyed */
4306 sdata->vif.bss_conf.csa_active = false;
4307 sdata->deflink.u.mgd.csa.waiting_bcn = false;
4308 sdata->deflink.u.mgd.csa.blocked_tx = false;
4309 ieee80211_vif_unblock_queues_csa(sdata);
4311 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
4312 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4314 ifmgd->reconnect = false;
4317 static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy,
4318 struct wiphy_work *work)
4320 struct ieee80211_sub_if_data *sdata =
4321 container_of(work, struct ieee80211_sub_if_data,
4322 u.mgd.beacon_connection_loss_work);
4323 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4325 if (ifmgd->connection_loss) {
4326 sdata_info(sdata, "Connection to AP %pM lost\n",
4327 sdata->vif.cfg.ap_addr);
4328 __ieee80211_disconnect(sdata);
4329 ifmgd->connection_loss = false;
4330 } else if (ifmgd->driver_disconnect) {
4332 "Driver requested disconnection from AP %pM\n",
4333 sdata->vif.cfg.ap_addr);
4334 __ieee80211_disconnect(sdata);
4335 ifmgd->driver_disconnect = false;
4337 if (ifmgd->associated)
4338 sdata->deflink.u.mgd.beacon_loss_count++;
4339 ieee80211_mgd_probe_ap(sdata, true);
4343 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy,
4344 struct wiphy_work *work)
4346 struct ieee80211_sub_if_data *sdata =
4347 container_of(work, struct ieee80211_sub_if_data,
4348 u.mgd.csa_connection_drop_work);
4350 __ieee80211_disconnect(sdata);
4353 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
4355 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4356 struct ieee80211_hw *hw = &sdata->local->hw;
4358 trace_api_beacon_loss(sdata);
4360 sdata->u.mgd.connection_loss = false;
4361 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
4363 EXPORT_SYMBOL(ieee80211_beacon_loss);
4365 void ieee80211_connection_loss(struct ieee80211_vif *vif)
4367 struct ieee80211_sub_if_data *sdata;
4368 struct ieee80211_hw *hw;
4370 KUNIT_STATIC_STUB_REDIRECT(ieee80211_connection_loss, vif);
4372 sdata = vif_to_sdata(vif);
4373 hw = &sdata->local->hw;
4375 trace_api_connection_loss(sdata);
4377 sdata->u.mgd.connection_loss = true;
4378 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
4380 EXPORT_SYMBOL(ieee80211_connection_loss);
4382 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
4384 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4385 struct ieee80211_hw *hw = &sdata->local->hw;
4387 trace_api_disconnect(sdata, reconnect);
4389 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
4392 sdata->u.mgd.driver_disconnect = true;
4393 sdata->u.mgd.reconnect = reconnect;
4394 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
4396 EXPORT_SYMBOL(ieee80211_disconnect);
4398 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
4401 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
4403 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4405 sdata->u.mgd.auth_data = NULL;
4409 * we are not authenticated yet, the only timer that could be
4410 * running is the timeout for the authentication response which
4411 * which is not relevant anymore.
4413 del_timer_sync(&sdata->u.mgd.timer);
4414 sta_info_destroy_addr(sdata, auth_data->ap_addr);
4416 /* other links are destroyed */
4417 eth_zero_addr(sdata->deflink.u.mgd.bssid);
4418 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
4420 sdata->u.mgd.flags = 0;
4422 ieee80211_link_release_channel(&sdata->deflink);
4423 ieee80211_vif_set_links(sdata, 0, 0);
4426 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
4437 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
4438 enum assoc_status status)
4440 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4442 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4444 sdata->u.mgd.assoc_data = NULL;
4446 if (status != ASSOC_SUCCESS) {
4448 * we are not associated yet, the only timer that could be
4449 * running is the timeout for the association response which
4450 * which is not relevant anymore.
4452 del_timer_sync(&sdata->u.mgd.timer);
4453 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
4455 eth_zero_addr(sdata->deflink.u.mgd.bssid);
4456 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
4458 sdata->u.mgd.flags = 0;
4459 sdata->vif.bss_conf.mu_mimo_owner = false;
4461 if (status != ASSOC_REJECTED) {
4462 struct cfg80211_assoc_failure data = {
4463 .timeout = status == ASSOC_TIMEOUT,
4467 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
4468 ARRAY_SIZE(assoc_data->link));
4470 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
4471 data.bss[i] = assoc_data->link[i].bss;
4473 if (ieee80211_vif_is_mld(&sdata->vif))
4474 data.ap_mld_addr = assoc_data->ap_addr;
4476 cfg80211_assoc_failure(sdata->dev, &data);
4479 ieee80211_link_release_channel(&sdata->deflink);
4480 ieee80211_vif_set_links(sdata, 0, 0);
4486 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
4487 struct ieee80211_mgmt *mgmt, size_t len)
4489 struct ieee80211_local *local = sdata->local;
4490 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
4491 const struct element *challenge;
4494 struct ieee80211_prep_tx_info info = {
4495 .subtype = IEEE80211_STYPE_AUTH,
4496 .link_id = auth_data->link_id,
4499 pos = mgmt->u.auth.variable;
4500 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
4501 len - (pos - (u8 *)mgmt));
4504 auth_data->expected_transaction = 4;
4505 drv_mgd_prepare_tx(sdata->local, sdata, &info);
4506 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4507 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4508 IEEE80211_TX_INTFL_MLME_CONN_TX;
4509 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
4511 challenge->datalen + sizeof(*challenge),
4512 auth_data->ap_addr, auth_data->ap_addr,
4513 auth_data->key, auth_data->key_len,
4514 auth_data->key_idx, tx_flags);
4517 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
4519 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4520 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
4521 struct sta_info *sta;
4523 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4525 sdata_info(sdata, "authenticated\n");
4526 ifmgd->auth_data->done = true;
4527 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
4528 ifmgd->auth_data->timeout_started = true;
4529 run_again(sdata, ifmgd->auth_data->timeout);
4531 /* move station state to auth */
4532 sta = sta_info_get(sdata, ap_addr);
4534 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
4537 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
4538 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
4545 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
4546 struct ieee80211_mgmt *mgmt, size_t len)
4548 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4549 u16 auth_alg, auth_transaction, status_code;
4550 struct ieee80211_event event = {
4552 .u.mlme.data = AUTH_EVENT,
4554 struct ieee80211_prep_tx_info info = {
4555 .subtype = IEEE80211_STYPE_AUTH,
4558 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4563 if (!ifmgd->auth_data || ifmgd->auth_data->done)
4566 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
4569 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
4570 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
4571 status_code = le16_to_cpu(mgmt->u.auth.status_code);
4573 if (auth_alg != ifmgd->auth_data->algorithm ||
4574 (auth_alg != WLAN_AUTH_SAE &&
4575 auth_transaction != ifmgd->auth_data->expected_transaction) ||
4576 (auth_alg == WLAN_AUTH_SAE &&
4577 (auth_transaction < ifmgd->auth_data->expected_transaction ||
4578 auth_transaction > 2))) {
4579 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
4580 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
4582 ifmgd->auth_data->expected_transaction);
4586 if (status_code != WLAN_STATUS_SUCCESS) {
4587 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
4589 if (auth_alg == WLAN_AUTH_SAE &&
4590 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
4591 (auth_transaction == 1 &&
4592 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
4593 status_code == WLAN_STATUS_SAE_PK)))) {
4594 /* waiting for userspace now */
4595 ifmgd->auth_data->waiting = true;
4596 ifmgd->auth_data->timeout =
4597 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
4598 ifmgd->auth_data->timeout_started = true;
4599 run_again(sdata, ifmgd->auth_data->timeout);
4603 sdata_info(sdata, "%pM denied authentication (status %d)\n",
4604 mgmt->sa, status_code);
4605 ieee80211_destroy_auth_data(sdata, false);
4606 event.u.mlme.status = MLME_DENIED;
4607 event.u.mlme.reason = status_code;
4608 drv_event_callback(sdata->local, sdata, &event);
4612 switch (ifmgd->auth_data->algorithm) {
4613 case WLAN_AUTH_OPEN:
4614 case WLAN_AUTH_LEAP:
4617 case WLAN_AUTH_FILS_SK:
4618 case WLAN_AUTH_FILS_SK_PFS:
4619 case WLAN_AUTH_FILS_PK:
4621 case WLAN_AUTH_SHARED_KEY:
4622 if (ifmgd->auth_data->expected_transaction != 4) {
4623 ieee80211_auth_challenge(sdata, mgmt, len);
4624 /* need another frame */
4629 WARN_ONCE(1, "invalid auth alg %d",
4630 ifmgd->auth_data->algorithm);
4634 event.u.mlme.status = MLME_SUCCESS;
4636 drv_event_callback(sdata->local, sdata, &event);
4637 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
4638 (auth_transaction == 2 &&
4639 ifmgd->auth_data->expected_transaction == 2)) {
4640 if (!ieee80211_mark_sta_auth(sdata))
4641 return; /* ignore frame -- wait for timeout */
4642 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
4643 auth_transaction == 2) {
4644 sdata_info(sdata, "SAE peer confirmed\n");
4645 ifmgd->auth_data->peer_confirmed = true;
4648 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
4650 drv_mgd_complete_tx(sdata->local, sdata, &info);
4653 #define case_WLAN(type) \
4654 case WLAN_REASON_##type: return #type
4656 const char *ieee80211_get_reason_code_string(u16 reason_code)
4658 switch (reason_code) {
4659 case_WLAN(UNSPECIFIED);
4660 case_WLAN(PREV_AUTH_NOT_VALID);
4661 case_WLAN(DEAUTH_LEAVING);
4662 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
4663 case_WLAN(DISASSOC_AP_BUSY);
4664 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
4665 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
4666 case_WLAN(DISASSOC_STA_HAS_LEFT);
4667 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
4668 case_WLAN(DISASSOC_BAD_POWER);
4669 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
4670 case_WLAN(INVALID_IE);
4671 case_WLAN(MIC_FAILURE);
4672 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
4673 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
4674 case_WLAN(IE_DIFFERENT);
4675 case_WLAN(INVALID_GROUP_CIPHER);
4676 case_WLAN(INVALID_PAIRWISE_CIPHER);
4677 case_WLAN(INVALID_AKMP);
4678 case_WLAN(UNSUPP_RSN_VERSION);
4679 case_WLAN(INVALID_RSN_IE_CAP);
4680 case_WLAN(IEEE8021X_FAILED);
4681 case_WLAN(CIPHER_SUITE_REJECTED);
4682 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
4683 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
4684 case_WLAN(DISASSOC_LOW_ACK);
4685 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
4686 case_WLAN(QSTA_LEAVE_QBSS);
4687 case_WLAN(QSTA_NOT_USE);
4688 case_WLAN(QSTA_REQUIRE_SETUP);
4689 case_WLAN(QSTA_TIMEOUT);
4690 case_WLAN(QSTA_CIPHER_NOT_SUPP);
4691 case_WLAN(MESH_PEER_CANCELED);
4692 case_WLAN(MESH_MAX_PEERS);
4693 case_WLAN(MESH_CONFIG);
4694 case_WLAN(MESH_CLOSE);
4695 case_WLAN(MESH_MAX_RETRIES);
4696 case_WLAN(MESH_CONFIRM_TIMEOUT);
4697 case_WLAN(MESH_INVALID_GTK);
4698 case_WLAN(MESH_INCONSISTENT_PARAM);
4699 case_WLAN(MESH_INVALID_SECURITY);
4700 case_WLAN(MESH_PATH_ERROR);
4701 case_WLAN(MESH_PATH_NOFORWARD);
4702 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
4703 case_WLAN(MAC_EXISTS_IN_MBSS);
4704 case_WLAN(MESH_CHAN_REGULATORY);
4705 case_WLAN(MESH_CHAN);
4706 default: return "<unknown>";
4710 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
4711 struct ieee80211_mgmt *mgmt, size_t len)
4713 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4714 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
4716 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4721 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
4722 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
4726 if (ifmgd->associated &&
4727 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
4728 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
4729 sdata->vif.cfg.ap_addr, reason_code,
4730 ieee80211_get_reason_code_string(reason_code));
4732 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
4734 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
4735 reason_code, false);
4739 if (ifmgd->assoc_data &&
4740 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
4742 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
4743 ifmgd->assoc_data->ap_addr, reason_code,
4744 ieee80211_get_reason_code_string(reason_code));
4746 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
4748 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
4754 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
4755 struct ieee80211_mgmt *mgmt, size_t len)
4757 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4760 lockdep_assert_wiphy(sdata->local->hw.wiphy);
4765 if (!ifmgd->associated ||
4766 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
4769 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
4771 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
4772 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
4776 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
4777 sdata->vif.cfg.ap_addr, reason_code,
4778 ieee80211_get_reason_code_string(reason_code));
4780 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
4782 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
4786 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
4787 struct ieee80211_supported_band *sband,
4788 const struct link_sta_info *link_sta,
4789 const struct ieee802_11_elems *elems)
4791 const struct ieee80211_sta_he_cap *own_he_cap =
4792 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4794 if (elems->ext_capab_len < 10)
4797 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
4800 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
4801 IEEE80211_HE_MAC_CAP0_TWT_RES &&
4803 (own_he_cap->he_cap_elem.mac_cap_info[0] &
4804 IEEE80211_HE_MAC_CAP0_TWT_REQ);
4807 static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
4808 struct ieee80211_supported_band *sband,
4809 struct ieee80211_link_data *link,
4810 struct link_sta_info *link_sta,
4811 struct ieee802_11_elems *elems)
4813 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
4815 if (link->conf->twt_requester != twt) {
4816 link->conf->twt_requester = twt;
4817 return BSS_CHANGED_TWT;
4822 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
4823 struct ieee80211_bss_conf *bss_conf,
4824 struct ieee80211_supported_band *sband,
4825 struct link_sta_info *link_sta)
4827 const struct ieee80211_sta_he_cap *own_he_cap =
4828 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4830 return bss_conf->he_support &&
4831 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
4832 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
4834 (own_he_cap->he_cap_elem.mac_cap_info[2] &
4835 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
4838 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
4839 struct link_sta_info *link_sta,
4840 struct cfg80211_bss *cbss,
4841 struct ieee80211_mgmt *mgmt,
4842 const u8 *elem_start,
4843 unsigned int elem_len,
4846 struct ieee80211_sub_if_data *sdata = link->sdata;
4847 struct ieee80211_mgd_assoc_data *assoc_data =
4848 sdata->u.mgd.assoc_data ?: sdata->u.mgd.reconf.add_links_data;
4849 struct ieee80211_bss_conf *bss_conf = link->conf;
4850 struct ieee80211_local *local = sdata->local;
4851 unsigned int link_id = link->link_id;
4852 struct ieee80211_elems_parse_params parse_params = {
4853 .mode = link->u.mgd.conn.mode,
4854 .start = elem_start,
4856 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
4859 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4860 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4861 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
4862 const struct cfg80211_bss_ies *bss_ies = NULL;
4863 struct ieee80211_supported_band *sband;
4864 struct ieee802_11_elems *elems;
4865 const __le16 prof_bss_param_ch_present =
4866 cpu_to_le16(IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT);
4870 elems = ieee802_11_parse_elems_full(&parse_params);
4874 if (link_id == assoc_data->assoc_link_id) {
4875 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
4878 * we should not get to this flow unless the association was
4879 * successful, so set the status directly to success
4881 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
4882 if (elems->ml_basic) {
4883 int bss_param_ch_cnt =
4884 ieee80211_mle_get_bss_param_ch_cnt((const void *)elems->ml_basic);
4886 if (bss_param_ch_cnt < 0) {
4890 bss_conf->bss_param_ch_cnt = bss_param_ch_cnt;
4891 bss_conf->bss_param_ch_cnt_link_id = link_id;
4893 } else if (elems->parse_error & IEEE80211_PARSE_ERR_DUP_NEST_ML_BASIC ||
4895 !(elems->prof->control & prof_bss_param_ch_present)) {
4899 const u8 *ptr = elems->prof->variable +
4900 elems->prof->sta_info_len - 1;
4901 int bss_param_ch_cnt;
4904 * During parsing, we validated that these fields exist,
4905 * otherwise elems->prof would have been set to NULL.
4907 capab_info = get_unaligned_le16(ptr);
4908 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
4910 ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(elems->prof);
4911 bss_conf->bss_param_ch_cnt = bss_param_ch_cnt;
4912 bss_conf->bss_param_ch_cnt_link_id = link_id;
4914 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
4915 link_info(link, "association response status code=%u\n",
4916 assoc_data->link[link_id].status);
4922 if (!is_s1g && !elems->supp_rates) {
4923 sdata_info(sdata, "no SuppRates element in AssocResp\n");
4928 link->u.mgd.tdls_chan_switch_prohibited =
4929 elems->ext_capab && elems->ext_capab_len >= 5 &&
4930 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
4933 * Some APs are erroneously not including some information in their
4934 * (re)association response frames. Try to recover by using the data
4935 * from the beacon or probe response. This seems to afflict mobile
4936 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
4937 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
4940 ((assoc_data->wmm && !elems->wmm_param) ||
4941 (link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT &&
4942 (!elems->ht_cap_elem || !elems->ht_operation)) ||
4943 (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT &&
4944 (!elems->vht_cap_elem || !elems->vht_operation)))) {
4945 const struct cfg80211_bss_ies *ies;
4946 struct ieee802_11_elems *bss_elems;
4949 ies = rcu_dereference(cbss->ies);
4951 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
4959 parse_params.start = bss_ies->data;
4960 parse_params.len = bss_ies->len;
4961 parse_params.bss = cbss;
4962 bss_elems = ieee802_11_parse_elems_full(&parse_params);
4968 if (assoc_data->wmm &&
4969 !elems->wmm_param && bss_elems->wmm_param) {
4970 elems->wmm_param = bss_elems->wmm_param;
4972 "AP bug: WMM param missing from AssocResp\n");
4976 * Also check if we requested HT/VHT, otherwise the AP doesn't
4977 * have to include the IEs in the (re)association response.
4979 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
4980 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) {
4981 elems->ht_cap_elem = bss_elems->ht_cap_elem;
4983 "AP bug: HT capability missing from AssocResp\n");
4985 if (!elems->ht_operation && bss_elems->ht_operation &&
4986 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) {
4987 elems->ht_operation = bss_elems->ht_operation;
4989 "AP bug: HT operation missing from AssocResp\n");
4993 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
4994 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) {
4995 elems->vht_cap_elem = bss_elems->vht_cap_elem;
4997 "AP bug: VHT capa missing from AssocResp\n");
5000 if (!elems->vht_operation && bss_elems->vht_operation &&
5001 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) {
5002 elems->vht_operation = bss_elems->vht_operation;
5004 "AP bug: VHT operation missing from AssocResp\n");
5011 * We previously checked these in the beacon/probe response, so
5012 * they should be present here. This is just a safety net.
5013 * Note that the ieee80211_config_bw() below would also check
5014 * for this (and more), but this has better error reporting.
5016 if (!is_6ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT &&
5017 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
5019 "HT AP is missing WMM params or HT capability/operation\n");
5024 if (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT &&
5025 (!elems->vht_cap_elem || !elems->vht_operation)) {
5027 "VHT AP is missing VHT capability/operation\n");
5032 /* check/update if AP changed anything in assoc response vs. scan */
5033 if (ieee80211_config_bw(link, elems,
5034 link_id == assoc_data->assoc_link_id,
5035 changed, "assoc response")) {
5040 if (WARN_ON(!link->conf->chanreq.oper.chan)) {
5044 sband = local->hw.wiphy->bands[link->conf->chanreq.oper.chan->band];
5046 /* Set up internal HT/VHT capabilities */
5047 if (elems->ht_cap_elem && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT)
5048 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
5052 if (elems->vht_cap_elem &&
5053 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) {
5054 const struct ieee80211_vht_cap *bss_vht_cap = NULL;
5055 const struct cfg80211_bss_ies *ies;
5058 * Cisco AP module 9115 with FW 17.3 has a bug and sends a
5059 * too large maximum MPDU length in the association response
5060 * (indicating 12k) that it cannot actually process ...
5064 ies = rcu_dereference(cbss->ies);
5066 const struct element *elem;
5068 elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY,
5069 ies->data, ies->len);
5070 if (elem && elem->datalen >= sizeof(*bss_vht_cap))
5071 bss_vht_cap = (const void *)elem->data;
5074 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
5075 elems->vht_cap_elem,
5076 bss_vht_cap, link_sta);
5080 if (elems->he_operation &&
5081 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE &&
5083 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
5086 elems->he_6ghz_capa,
5089 bss_conf->he_support = link_sta->pub->he_cap.has_he;
5090 if (elems->rsnx && elems->rsnx_len &&
5091 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
5092 wiphy_ext_feature_isset(local->hw.wiphy,
5093 NL80211_EXT_FEATURE_PROTECTED_TWT))
5094 bss_conf->twt_protected = true;
5096 bss_conf->twt_protected = false;
5098 *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
5101 if (elems->eht_operation && elems->eht_cap &&
5102 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_EHT) {
5103 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
5110 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
5112 bss_conf->eht_support = false;
5115 bss_conf->he_support = false;
5116 bss_conf->twt_requester = false;
5117 bss_conf->twt_protected = false;
5118 bss_conf->eht_support = false;
5121 bss_conf->twt_broadcast =
5122 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
5124 if (bss_conf->he_support) {
5125 bss_conf->he_bss_color.color =
5126 le32_get_bits(elems->he_operation->he_oper_params,
5127 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
5128 bss_conf->he_bss_color.partial =
5129 le32_get_bits(elems->he_operation->he_oper_params,
5130 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
5131 bss_conf->he_bss_color.enabled =
5132 !le32_get_bits(elems->he_operation->he_oper_params,
5133 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
5135 if (bss_conf->he_bss_color.enabled)
5136 *changed |= BSS_CHANGED_HE_BSS_COLOR;
5138 bss_conf->htc_trig_based_pkt_ext =
5139 le32_get_bits(elems->he_operation->he_oper_params,
5140 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
5141 bss_conf->frame_time_rts_th =
5142 le32_get_bits(elems->he_operation->he_oper_params,
5143 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
5145 bss_conf->uora_exists = !!elems->uora_element;
5146 if (elems->uora_element)
5147 bss_conf->uora_ocw_range = elems->uora_element[0];
5149 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
5150 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
5151 /* TODO: OPEN: what happens if BSS color disable is set? */
5154 if (cbss->transmitted_bss) {
5155 bss_conf->nontransmitted = true;
5156 ether_addr_copy(bss_conf->transmitter_bssid,
5157 cbss->transmitted_bss->bssid);
5158 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
5159 bss_conf->bssid_index = cbss->bssid_index;
5163 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
5164 * in their association response, so ignore that data for our own
5165 * configuration. If it changed since the last beacon, we'll get the
5166 * next beacon and update then.
5170 * If an operating mode notification IE is present, override the
5171 * NSS calculation (that would be done in rate_control_rate_init())
5172 * and use the # of streams from that element.
5174 if (elems->opmode_notif &&
5175 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
5178 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
5179 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
5181 link_sta->pub->rx_nss = nss;
5185 * Always handle WMM once after association regardless
5186 * of the first value the AP uses. Setting -1 here has
5187 * that effect because the AP values is an unsigned
5190 link->u.mgd.wmm_last_param_set = -1;
5191 link->u.mgd.mu_edca_last_param_set = -1;
5193 if (link->u.mgd.disable_wmm_tracking) {
5194 ieee80211_set_wmm_default(link, false, false);
5195 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
5196 elems->wmm_param_len,
5197 elems->mu_edca_param_set)) {
5198 /* still enable QoS since we might have HT/VHT */
5199 ieee80211_set_wmm_default(link, false, true);
5200 /* disable WMM tracking in this case to disable
5201 * tracking WMM parameter changes in the beacon if
5202 * the parameters weren't actually valid. Doing so
5203 * avoids changing parameters very strangely when
5204 * the AP is going back and forth between valid and
5205 * invalid parameters.
5207 link->u.mgd.disable_wmm_tracking = true;
5210 if (elems->max_idle_period_ie) {
5211 bss_conf->max_idle_period =
5212 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
5213 bss_conf->protected_keep_alive =
5214 !!(elems->max_idle_period_ie->idle_options &
5215 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
5216 *changed |= BSS_CHANGED_KEEP_ALIVE;
5218 bss_conf->max_idle_period = 0;
5219 bss_conf->protected_keep_alive = false;
5222 /* set assoc capability (AID was already set earlier),
5223 * ieee80211_set_associated() will tell the driver */
5224 bss_conf->assoc_capability = capab_info;
5233 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
5234 struct sta_info *sta,
5235 struct link_sta_info *link_sta,
5236 struct cfg80211_bss *cbss)
5238 struct ieee80211_sub_if_data *sdata = link->sdata;
5239 struct ieee80211_local *local = sdata->local;
5240 struct ieee80211_bss *bss = (void *)cbss->priv;
5241 u32 rates = 0, basic_rates = 0;
5242 bool have_higher_than_11mbit = false;
5243 int min_rate = INT_MAX, min_rate_index = -1;
5244 struct ieee80211_supported_band *sband;
5246 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
5247 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
5249 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5250 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5251 ieee80211_s1g_sta_rate_init(sta);
5255 sband = local->hw.wiphy->bands[cbss->channel->band];
5257 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
5259 &rates, &basic_rates, NULL,
5260 &have_higher_than_11mbit,
5261 &min_rate, &min_rate_index);
5264 * This used to be a workaround for basic rates missing
5265 * in the association response frame. Now that we no
5266 * longer use the basic rates from there, it probably
5267 * doesn't happen any more, but keep the workaround so
5268 * in case some *other* APs are buggy in different ways
5269 * we can connect -- with a warning.
5270 * Allow this workaround only in case the AP provided at least
5273 if (min_rate_index < 0) {
5274 link_info(link, "No legacy rates in association response\n");
5276 } else if (!basic_rates) {
5277 link_info(link, "No basic rates, using min rate instead\n");
5278 basic_rates = BIT(min_rate_index);
5282 link_sta->pub->supp_rates[cbss->channel->band] = rates;
5284 link_info(link, "No rates found, keeping mandatory only\n");
5286 link->conf->basic_rates = basic_rates;
5288 /* cf. IEEE 802.11 9.2.12 */
5289 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
5290 have_higher_than_11mbit;
5295 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
5296 struct cfg80211_bss *cbss)
5298 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
5299 const struct element *ht_cap_elem, *vht_cap_elem;
5300 const struct cfg80211_bss_ies *ies;
5301 const struct ieee80211_ht_cap *ht_cap;
5302 const struct ieee80211_vht_cap *vht_cap;
5303 const struct ieee80211_he_cap_elem *he_cap;
5304 const struct element *he_cap_elem;
5305 u16 mcs_80_map, mcs_160_map;
5306 int i, mcs_nss_size;
5310 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HT)
5313 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
5314 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
5315 ht_cap = (void *)ht_cap_elem->data;
5316 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
5318 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
5319 * "Tx Unequal Modulation Supported" fields.
5323 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_VHT)
5326 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
5327 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
5331 vht_cap = (void *)vht_cap_elem->data;
5332 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
5333 for (nss = 8; nss > 0; nss--) {
5334 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
5335 IEEE80211_VHT_MCS_NOT_SUPPORTED)
5338 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
5339 chains = max(chains, nss);
5342 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HE)
5345 ies = rcu_dereference(cbss->ies);
5346 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
5347 ies->data, ies->len);
5349 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
5352 /* skip one byte ext_tag_id */
5353 he_cap = (void *)(he_cap_elem->data + 1);
5354 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
5357 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
5360 /* mcs_nss is right after he_cap info */
5361 he_mcs_nss_supp = (void *)(he_cap + 1);
5363 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
5365 for (i = 7; i >= 0; i--) {
5366 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
5368 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
5369 chains = max_t(u8, chains, i + 1);
5374 support_160 = he_cap->phy_cap_info[0] &
5375 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
5380 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
5381 for (i = 7; i >= 0; i--) {
5382 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
5384 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
5385 chains = max_t(u8, chains, i + 1);
5394 ieee80211_determine_our_sta_mode(struct ieee80211_sub_if_data *sdata,
5395 struct ieee80211_supported_band *sband,
5396 struct cfg80211_assoc_request *req,
5397 bool wmm_used, int link_id,
5398 struct ieee80211_conn_settings *conn)
5400 struct ieee80211_sta_ht_cap sta_ht_cap = sband->ht_cap;
5401 bool is_5ghz = sband->band == NL80211_BAND_5GHZ;
5402 bool is_6ghz = sband->band == NL80211_BAND_6GHZ;
5403 const struct ieee80211_sta_he_cap *he_cap;
5404 const struct ieee80211_sta_eht_cap *eht_cap;
5405 struct ieee80211_sta_vht_cap vht_cap;
5407 if (sband->band == NL80211_BAND_S1GHZ) {
5408 conn->mode = IEEE80211_CONN_MODE_S1G;
5409 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
5410 mlme_dbg(sdata, "operating as S1G STA\n");
5414 conn->mode = IEEE80211_CONN_MODE_LEGACY;
5415 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
5417 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5419 if (req && req->flags & ASSOC_REQ_DISABLE_HT) {
5420 mlme_link_id_dbg(sdata, link_id,
5421 "HT disabled by flag, limiting to legacy\n");
5426 mlme_link_id_dbg(sdata, link_id,
5427 "WMM/QoS not supported, limiting to legacy\n");
5434 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5435 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5436 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5437 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5438 netdev_info(sdata->dev,
5439 "WEP/TKIP use, limiting to legacy\n");
5445 if (!sta_ht_cap.ht_supported && !is_6ghz) {
5446 mlme_link_id_dbg(sdata, link_id,
5447 "HT not supported (and not on 6 GHz), limiting to legacy\n");
5452 conn->mode = IEEE80211_CONN_MODE_HT;
5453 conn->bw_limit = sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
5454 IEEE80211_CONN_BW_LIMIT_40 :
5455 IEEE80211_CONN_BW_LIMIT_20;
5457 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
5458 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
5460 if (req && req->flags & ASSOC_REQ_DISABLE_VHT) {
5461 mlme_link_id_dbg(sdata, link_id,
5462 "VHT disabled by flag, limiting to HT\n");
5466 if (vht_cap.vht_supported && is_5ghz) {
5467 bool have_80mhz = false;
5470 if (conn->bw_limit == IEEE80211_CONN_BW_LIMIT_20) {
5471 mlme_link_id_dbg(sdata, link_id,
5472 "no 40 MHz support on 5 GHz, limiting to HT\n");
5476 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5477 for (i = 0; i < sband->n_channels; i++) {
5478 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5479 IEEE80211_CHAN_NO_80MHZ))
5487 mlme_link_id_dbg(sdata, link_id,
5488 "no 80 MHz channel support on 5 GHz, limiting to HT\n");
5491 } else if (is_5ghz) { /* !vht_supported but on 5 GHz */
5492 mlme_link_id_dbg(sdata, link_id,
5493 "no VHT support on 5 GHz, limiting to HT\n");
5497 /* VHT - if we have - is fine, including 80 MHz, check 160 below again */
5498 if (sband->band != NL80211_BAND_2GHZ) {
5499 conn->mode = IEEE80211_CONN_MODE_VHT;
5500 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_160;
5504 !(vht_cap.cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
5505 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) {
5506 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80;
5507 mlme_link_id_dbg(sdata, link_id,
5508 "no VHT 160 MHz capability on 5 GHz, limiting to 80 MHz");
5511 if (req && req->flags & ASSOC_REQ_DISABLE_HE) {
5512 mlme_link_id_dbg(sdata, link_id,
5513 "HE disabled by flag, limiting to HT/VHT\n");
5517 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
5520 mlme_link_id_dbg(sdata, link_id,
5521 "no HE support, limiting to HT/VHT\n");
5526 conn->mode = IEEE80211_CONN_MODE_HE;
5528 /* check bandwidth */
5529 switch (sband->band) {
5531 case NL80211_BAND_2GHZ:
5532 if (he_cap->he_cap_elem.phy_cap_info[0] &
5533 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G)
5535 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
5536 mlme_link_id_dbg(sdata, link_id,
5537 "no 40 MHz HE cap in 2.4 GHz, limiting to 20 MHz\n");
5539 case NL80211_BAND_5GHZ:
5540 if (!(he_cap->he_cap_elem.phy_cap_info[0] &
5541 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) {
5542 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
5543 mlme_link_id_dbg(sdata, link_id,
5544 "no 40/80 MHz HE cap in 5 GHz, limiting to 20 MHz\n");
5547 if (!(he_cap->he_cap_elem.phy_cap_info[0] &
5548 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)) {
5549 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
5551 IEEE80211_CONN_BW_LIMIT_80);
5552 mlme_link_id_dbg(sdata, link_id,
5553 "no 160 MHz HE cap in 5 GHz, limiting to 80 MHz\n");
5556 case NL80211_BAND_6GHZ:
5557 if (he_cap->he_cap_elem.phy_cap_info[0] &
5558 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
5560 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
5562 IEEE80211_CONN_BW_LIMIT_80);
5563 mlme_link_id_dbg(sdata, link_id,
5564 "no 160 MHz HE cap in 6 GHz, limiting to 80 MHz\n");
5568 if (req && req->flags & ASSOC_REQ_DISABLE_EHT) {
5569 mlme_link_id_dbg(sdata, link_id,
5570 "EHT disabled by flag, limiting to HE\n");
5574 eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
5576 mlme_link_id_dbg(sdata, link_id,
5577 "no EHT support, limiting to HE\n");
5583 conn->mode = IEEE80211_CONN_MODE_EHT;
5585 /* check bandwidth */
5587 eht_cap->eht_cap_elem.phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)
5588 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_320;
5590 mlme_link_id_dbg(sdata, link_id,
5591 "no EHT 320 MHz cap in 6 GHz, limiting to 160 MHz\n");
5594 mlme_link_id_dbg(sdata, link_id,
5595 "determined local STA to be %s, BW limited to %d MHz\n",
5596 ieee80211_conn_mode_str(conn->mode),
5597 20 * (1 << conn->bw_limit));
5601 ieee80211_determine_our_sta_mode_auth(struct ieee80211_sub_if_data *sdata,
5602 struct ieee80211_supported_band *sband,
5603 struct cfg80211_auth_request *req,
5605 struct ieee80211_conn_settings *conn)
5607 ieee80211_determine_our_sta_mode(sdata, sband, NULL, wmm_used,
5608 req->link_id > 0 ? req->link_id : 0,
5613 ieee80211_determine_our_sta_mode_assoc(struct ieee80211_sub_if_data *sdata,
5614 struct ieee80211_supported_band *sband,
5615 struct cfg80211_assoc_request *req,
5616 bool wmm_used, int link_id,
5617 struct ieee80211_conn_settings *conn)
5619 struct ieee80211_conn_settings tmp;
5623 ieee80211_determine_our_sta_mode(sdata, sband, req, wmm_used, link_id,
5626 conn->mode = min_t(enum ieee80211_conn_mode,
5627 conn->mode, tmp.mode);
5628 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
5629 conn->bw_limit, tmp.bw_limit);
5632 static enum ieee80211_ap_reg_power
5633 ieee80211_ap_power_type(u8 control)
5635 switch (u8_get_bits(control, IEEE80211_HE_6GHZ_OPER_CTRL_REG_INFO)) {
5636 case IEEE80211_6GHZ_CTRL_REG_LPI_AP:
5637 case IEEE80211_6GHZ_CTRL_REG_INDOOR_LPI_AP:
5638 return IEEE80211_REG_LPI_AP;
5639 case IEEE80211_6GHZ_CTRL_REG_SP_AP:
5640 case IEEE80211_6GHZ_CTRL_REG_INDOOR_SP_AP:
5641 return IEEE80211_REG_SP_AP;
5642 case IEEE80211_6GHZ_CTRL_REG_VLP_AP:
5643 return IEEE80211_REG_VLP_AP;
5645 return IEEE80211_REG_UNSET_AP;
5649 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
5650 struct ieee80211_link_data *link,
5652 struct cfg80211_bss *cbss, bool mlo,
5653 struct ieee80211_conn_settings *conn,
5654 unsigned long *userspace_selectors)
5656 struct ieee80211_local *local = sdata->local;
5657 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
5658 struct ieee80211_chan_req chanreq = {};
5659 struct cfg80211_chan_def ap_chandef;
5660 struct ieee802_11_elems *elems;
5663 lockdep_assert_wiphy(local->hw.wiphy);
5666 elems = ieee80211_determine_chan_mode(sdata, conn, cbss, link_id,
5667 &chanreq, &ap_chandef,
5668 userspace_selectors);
5670 if (IS_ERR(elems)) {
5672 return PTR_ERR(elems);
5675 if (mlo && !elems->ml_basic) {
5676 sdata_info(sdata, "Rejecting MLO as it is not supported by AP\n");
5682 if (link && is_6ghz && conn->mode >= IEEE80211_CONN_MODE_HE) {
5683 const struct ieee80211_he_6ghz_oper *he_6ghz_oper;
5685 if (elems->pwr_constr_elem)
5686 link->conf->pwr_reduction = *elems->pwr_constr_elem;
5688 he_6ghz_oper = ieee80211_he_6ghz_oper(elems->he_operation);
5690 link->conf->power_type =
5691 ieee80211_ap_power_type(he_6ghz_oper->control);
5694 "HE 6 GHz operation missing (on %d MHz), expect issues\n",
5695 cbss->channel->center_freq);
5697 link->conf->tpe = elems->tpe;
5698 ieee80211_rearrange_tpe(&link->conf->tpe, &ap_chandef,
5702 /* the element data was RCU protected so no longer valid anyway */
5710 link->needed_rx_chains = min(ieee80211_max_rx_chains(link, cbss),
5715 * If this fails (possibly due to channel context sharing
5716 * on incompatible channels, e.g. 80+80 and 160 sharing the
5717 * same control channel) try to use a smaller bandwidth.
5719 ret = ieee80211_link_use_channel(link, &chanreq,
5720 IEEE80211_CHANCTX_SHARED);
5722 /* don't downgrade for 5 and 10 MHz channels, though. */
5723 if (chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
5724 chanreq.oper.width == NL80211_CHAN_WIDTH_10)
5727 while (ret && chanreq.oper.width != NL80211_CHAN_WIDTH_20_NOHT) {
5728 ieee80211_chanreq_downgrade(&chanreq, conn);
5730 ret = ieee80211_link_use_channel(link, &chanreq,
5731 IEEE80211_CHANCTX_SHARED);
5737 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5738 u8 *dtim_count, u8 *dtim_period)
5740 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5741 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5743 const struct ieee80211_tim_ie *tim = NULL;
5744 const struct ieee80211_bssid_index *idx;
5745 bool valid = tim_ie && tim_ie[1] >= 2;
5748 tim = (void *)(tim_ie + 2);
5751 *dtim_count = valid ? tim->dtim_count : 0;
5754 *dtim_period = valid ? tim->dtim_period : 0;
5756 /* Check if value is overridden by non-transmitted profile */
5757 if (!idx_ie || idx_ie[1] < 3)
5760 idx = (void *)(idx_ie + 2);
5763 *dtim_count = idx->dtim_count;
5766 *dtim_period = idx->dtim_period;
5771 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
5772 struct ieee80211_mgmt *mgmt,
5773 struct ieee802_11_elems *elems,
5774 const u8 *elem_start, unsigned int elem_len)
5776 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5777 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5778 struct ieee80211_local *local = sdata->local;
5779 unsigned int link_id;
5780 struct sta_info *sta;
5781 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
5782 u16 valid_links = 0, dormant_links = 0;
5785 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5787 * station info was already allocated and inserted before
5788 * the association and should be available to us
5790 sta = sta_info_get(sdata, assoc_data->ap_addr);
5794 sta->sta.spp_amsdu = assoc_data->spp_amsdu;
5796 if (ieee80211_vif_is_mld(&sdata->vif)) {
5797 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5798 if (!assoc_data->link[link_id].bss)
5801 valid_links |= BIT(link_id);
5802 if (assoc_data->link[link_id].disabled)
5803 dormant_links |= BIT(link_id);
5805 if (link_id != assoc_data->assoc_link_id) {
5806 err = ieee80211_sta_allocate_link(sta, link_id);
5812 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5815 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5816 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
5817 struct ieee80211_link_data *link;
5818 struct link_sta_info *link_sta;
5823 link = sdata_dereference(sdata->link[link_id], sdata);
5827 if (ieee80211_vif_is_mld(&sdata->vif))
5829 "local address %pM, AP link address %pM%s\n",
5831 assoc_data->link[link_id].bss->bssid,
5832 link_id == assoc_data->assoc_link_id ?
5835 link_sta = rcu_dereference_protected(sta->link[link_id],
5836 lockdep_is_held(&local->hw.wiphy->mtx));
5837 if (WARN_ON(!link_sta))
5840 if (!link->u.mgd.have_beacon) {
5841 const struct cfg80211_bss_ies *ies;
5844 ies = rcu_dereference(cbss->beacon_ies);
5846 link->u.mgd.have_beacon = true;
5848 ies = rcu_dereference(cbss->ies);
5849 ieee80211_get_dtim(ies,
5850 &link->conf->sync_dtim_count,
5851 &link->u.mgd.dtim_period);
5852 link->conf->beacon_int = cbss->beacon_interval;
5856 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
5858 if (link_id != assoc_data->assoc_link_id) {
5859 link->u.mgd.conn = assoc_data->link[link_id].conn;
5861 err = ieee80211_prep_channel(sdata, link, link_id, cbss,
5862 true, &link->u.mgd.conn,
5863 assoc_data->userspace_selectors);
5865 link_info(link, "prep_channel failed\n");
5870 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
5871 assoc_data->link[link_id].bss);
5875 if (!ieee80211_assoc_config_link(link, link_sta,
5876 assoc_data->link[link_id].bss,
5877 mgmt, elem_start, elem_len,
5881 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
5882 valid_links &= ~BIT(link_id);
5883 ieee80211_sta_remove_link(sta, link_id);
5887 if (link_id != assoc_data->assoc_link_id) {
5888 err = ieee80211_sta_activate_link(sta, link_id);
5894 /* links might have changed due to rejected ones, set them again */
5895 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5897 rate_control_rate_init_all_links(sta);
5899 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
5900 set_sta_flag(sta, WLAN_STA_MFP);
5901 sta->sta.mfp = true;
5903 sta->sta.mfp = false;
5906 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
5907 elems->ext_capab_len);
5909 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
5910 local->hw.queues >= IEEE80211_NUM_ACS;
5912 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
5913 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
5914 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
5917 "failed to move station %pM to desired state\n",
5919 WARN_ON(__sta_info_destroy(sta));
5923 if (sdata->wdev.use_4addr)
5924 drv_sta_set_4addr(local, sdata, &sta->sta, true);
5926 ieee80211_set_associated(sdata, assoc_data, changed);
5929 * If we're using 4-addr mode, let the AP know that we're
5930 * doing so, so that it can create the STA VLAN on its side
5932 if (ifmgd->use_4addr)
5933 ieee80211_send_4addr_nullfunc(local, sdata);
5936 * Start timer to probe the connection to the AP now.
5937 * Also start the timer that will detect beacon loss.
5939 ieee80211_sta_reset_beacon_monitor(sdata);
5940 ieee80211_sta_reset_conn_monitor(sdata);
5944 eth_zero_addr(sdata->vif.cfg.ap_addr);
5948 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
5949 struct ieee80211_mgmt *mgmt,
5952 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5953 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5954 u16 capab_info, status_code, aid;
5955 struct ieee80211_elems_parse_params parse_params = {
5960 struct ieee802_11_elems *elems;
5962 const u8 *elem_start;
5963 unsigned int elem_len;
5965 struct ieee80211_event event = {
5967 .u.mlme.data = ASSOC_EVENT,
5969 struct ieee80211_prep_tx_info info = {};
5970 struct cfg80211_rx_assoc_resp_data resp = {
5973 u8 ap_mld_addr[ETH_ALEN] __aligned(2);
5974 unsigned int link_id;
5976 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5981 info.link_id = assoc_data->assoc_link_id;
5984 assoc_data->link[assoc_data->assoc_link_id].conn.mode;
5986 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
5987 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
5991 * AssocResp and ReassocResp have identical structure, so process both
5992 * of them in this function.
5998 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
5999 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
6000 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
6001 if (assoc_data->s1g)
6002 elem_start = mgmt->u.s1g_assoc_resp.variable;
6004 elem_start = mgmt->u.assoc_resp.variable;
6007 * Note: this may not be perfect, AP might misbehave - if
6008 * anyone needs to rely on perfect complete notification
6009 * with the exact right subtype, then we need to track what
6010 * we actually transmitted.
6012 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
6013 IEEE80211_STYPE_ASSOC_REQ;
6015 if (assoc_data->fils_kek_len &&
6016 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
6019 elem_len = len - (elem_start - (u8 *)mgmt);
6020 parse_params.start = elem_start;
6021 parse_params.len = elem_len;
6022 elems = ieee802_11_parse_elems_full(&parse_params);
6026 if (elems->aid_resp)
6027 aid = le16_to_cpu(elems->aid_resp->aid);
6028 else if (assoc_data->s1g)
6031 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
6034 * The 5 MSB of the AID field are reserved
6035 * (802.11-2016 9.4.1.8 AID field)
6040 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
6041 reassoc ? "Rea" : "A", assoc_data->ap_addr,
6042 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
6044 ifmgd->broken_ap = false;
6046 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
6047 elems->timeout_int &&
6048 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
6051 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
6052 le32_to_cpu(elems->timeout_int->value));
6054 tu = le32_to_cpu(elems->timeout_int->value);
6055 ms = tu * 1024 / 1000;
6057 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
6058 assoc_data->ap_addr, tu, ms);
6059 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
6060 assoc_data->timeout_started = true;
6061 assoc_data->comeback = true;
6062 if (ms > IEEE80211_ASSOC_TIMEOUT)
6063 run_again(sdata, assoc_data->timeout);
6067 if (status_code != WLAN_STATUS_SUCCESS) {
6068 sdata_info(sdata, "%pM denied association (code=%d)\n",
6069 assoc_data->ap_addr, status_code);
6070 event.u.mlme.status = MLME_DENIED;
6071 event.u.mlme.reason = status_code;
6072 drv_event_callback(sdata->local, sdata, &event);
6074 if (aid == 0 || aid > IEEE80211_MAX_AID) {
6076 "invalid AID value %d (out of range), turn off PS\n",
6079 ifmgd->broken_ap = true;
6082 if (ieee80211_vif_is_mld(&sdata->vif)) {
6083 struct ieee80211_mle_basic_common_info *common;
6085 if (!elems->ml_basic) {
6087 "MLO association with %pM but no (basic) multi-link element in response!\n",
6088 assoc_data->ap_addr);
6092 common = (void *)elems->ml_basic->variable;
6094 if (memcmp(assoc_data->ap_addr,
6095 common->mld_mac_addr, ETH_ALEN)) {
6097 "AP MLD MAC address mismatch: got %pM expected %pM\n",
6098 common->mld_mac_addr,
6099 assoc_data->ap_addr);
6103 sdata->vif.cfg.eml_cap =
6104 ieee80211_mle_get_eml_cap((const void *)elems->ml_basic);
6105 sdata->vif.cfg.eml_med_sync_delay =
6106 ieee80211_mle_get_eml_med_sync_delay((const void *)elems->ml_basic);
6107 sdata->vif.cfg.mld_capa_op =
6108 ieee80211_mle_get_mld_capa_op((const void *)elems->ml_basic);
6111 sdata->vif.cfg.aid = aid;
6113 if (!ieee80211_assoc_success(sdata, mgmt, elems,
6114 elem_start, elem_len)) {
6115 /* oops -- internal error -- send timeout for now */
6116 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6119 event.u.mlme.status = MLME_SUCCESS;
6120 drv_event_callback(sdata->local, sdata, &event);
6121 sdata_info(sdata, "associated\n");
6126 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
6127 struct ieee80211_link_data *link;
6129 if (!assoc_data->link[link_id].bss)
6132 resp.links[link_id].bss = assoc_data->link[link_id].bss;
6133 ether_addr_copy(resp.links[link_id].addr,
6134 assoc_data->link[link_id].addr);
6135 resp.links[link_id].status = assoc_data->link[link_id].status;
6137 link = sdata_dereference(sdata->link[link_id], sdata);
6141 /* get uapsd queues configuration - same for all links */
6142 resp.uapsd_queues = 0;
6143 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
6144 if (link->tx_conf[ac].uapsd)
6145 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
6148 if (ieee80211_vif_is_mld(&sdata->vif)) {
6149 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
6150 resp.ap_mld_addr = ap_mld_addr;
6153 ieee80211_destroy_assoc_data(sdata,
6154 status_code == WLAN_STATUS_SUCCESS ?
6158 resp.buf = (u8 *)mgmt;
6160 resp.req_ies = ifmgd->assoc_req_ies;
6161 resp.req_ies_len = ifmgd->assoc_req_ies_len;
6162 cfg80211_rx_assoc_resp(sdata->dev, &resp);
6164 drv_mgd_complete_tx(sdata->local, sdata, &info);
6168 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6172 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
6173 struct ieee80211_mgmt *mgmt, size_t len,
6174 struct ieee80211_rx_status *rx_status)
6176 struct ieee80211_sub_if_data *sdata = link->sdata;
6177 struct ieee80211_local *local = sdata->local;
6178 struct ieee80211_bss *bss;
6179 struct ieee80211_channel *channel;
6181 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6183 channel = ieee80211_get_channel_khz(local->hw.wiphy,
6184 ieee80211_rx_status_to_khz(rx_status));
6188 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
6190 link->conf->beacon_rate = bss->beacon_rate;
6191 ieee80211_rx_bss_put(local, bss);
6196 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
6197 struct sk_buff *skb)
6199 struct ieee80211_sub_if_data *sdata = link->sdata;
6200 struct ieee80211_mgmt *mgmt = (void *)skb->data;
6201 struct ieee80211_if_managed *ifmgd;
6202 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
6203 struct ieee80211_channel *channel;
6204 size_t baselen, len = skb->len;
6206 ifmgd = &sdata->u.mgd;
6208 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6211 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
6212 * "If a 6 GHz AP receives a Probe Request frame and responds with
6213 * a Probe Response frame [..], the Address 1 field of the Probe
6214 * Response frame shall be set to the broadcast address [..]"
6215 * So, on 6GHz band we should also accept broadcast responses.
6217 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
6222 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
6223 (channel->band != NL80211_BAND_6GHZ ||
6224 !is_broadcast_ether_addr(mgmt->da)))
6225 return; /* ignore ProbeResp to foreign address */
6227 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
6231 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6233 if (ifmgd->associated &&
6234 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
6235 ieee80211_reset_ap_probe(sdata);
6239 * This is the canonical list of information elements we care about,
6240 * the filter code also gives us all changes to the Microsoft OUI
6241 * (00:50:F2) vendor IE which is used for WMM which we need to track,
6242 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
6243 * changes to requested client power.
6245 * We implement beacon filtering in software since that means we can
6246 * avoid processing the frame here and in cfg80211, and userspace
6247 * will not be able to tell whether the hardware supports it or not.
6249 * XXX: This list needs to be dynamic -- userspace needs to be able to
6250 * add items it requires. It also needs to be able to tell us to
6251 * look out for other vendor IEs.
6253 static const u64 care_about_ies =
6254 (1ULL << WLAN_EID_COUNTRY) |
6255 (1ULL << WLAN_EID_ERP_INFO) |
6256 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
6257 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
6258 (1ULL << WLAN_EID_HT_CAPABILITY) |
6259 (1ULL << WLAN_EID_HT_OPERATION) |
6260 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
6262 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
6263 struct ieee80211_if_managed *ifmgd,
6264 struct ieee80211_bss_conf *bss_conf,
6265 struct ieee80211_local *local,
6266 struct ieee80211_rx_status *rx_status)
6268 struct ieee80211_sub_if_data *sdata = link->sdata;
6270 /* Track average RSSI from the Beacon frames of the current AP */
6272 if (!link->u.mgd.tracking_signal_avg) {
6273 link->u.mgd.tracking_signal_avg = true;
6274 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
6275 link->u.mgd.last_cqm_event_signal = 0;
6276 link->u.mgd.count_beacon_signal = 1;
6277 link->u.mgd.last_ave_beacon_signal = 0;
6279 link->u.mgd.count_beacon_signal++;
6282 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
6283 -rx_status->signal);
6285 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
6286 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
6287 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
6288 int last_sig = link->u.mgd.last_ave_beacon_signal;
6289 struct ieee80211_event event = {
6294 * if signal crosses either of the boundaries, invoke callback
6295 * with appropriate parameters
6297 if (sig > ifmgd->rssi_max_thold &&
6298 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
6299 link->u.mgd.last_ave_beacon_signal = sig;
6300 event.u.rssi.data = RSSI_EVENT_HIGH;
6301 drv_event_callback(local, sdata, &event);
6302 } else if (sig < ifmgd->rssi_min_thold &&
6303 (last_sig >= ifmgd->rssi_max_thold ||
6305 link->u.mgd.last_ave_beacon_signal = sig;
6306 event.u.rssi.data = RSSI_EVENT_LOW;
6307 drv_event_callback(local, sdata, &event);
6311 if (bss_conf->cqm_rssi_thold &&
6312 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
6313 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
6314 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
6315 int last_event = link->u.mgd.last_cqm_event_signal;
6316 int thold = bss_conf->cqm_rssi_thold;
6317 int hyst = bss_conf->cqm_rssi_hyst;
6320 (last_event == 0 || sig < last_event - hyst)) {
6321 link->u.mgd.last_cqm_event_signal = sig;
6322 ieee80211_cqm_rssi_notify(
6324 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
6326 } else if (sig > thold &&
6327 (last_event == 0 || sig > last_event + hyst)) {
6328 link->u.mgd.last_cqm_event_signal = sig;
6329 ieee80211_cqm_rssi_notify(
6331 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
6336 if (bss_conf->cqm_rssi_low &&
6337 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
6338 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
6339 int last_event = link->u.mgd.last_cqm_event_signal;
6340 int low = bss_conf->cqm_rssi_low;
6341 int high = bss_conf->cqm_rssi_high;
6344 (last_event == 0 || last_event >= low)) {
6345 link->u.mgd.last_cqm_event_signal = sig;
6346 ieee80211_cqm_rssi_notify(
6348 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
6350 } else if (sig > high &&
6351 (last_event == 0 || last_event <= high)) {
6352 link->u.mgd.last_cqm_event_signal = sig;
6353 ieee80211_cqm_rssi_notify(
6355 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
6361 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
6362 struct cfg80211_bss *bss)
6364 if (ether_addr_equal(tx_bssid, bss->bssid))
6366 if (!bss->transmitted_bss)
6368 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
6371 static void ieee80211_ml_reconf_work(struct wiphy *wiphy,
6372 struct wiphy_work *work)
6374 struct ieee80211_sub_if_data *sdata =
6375 container_of(work, struct ieee80211_sub_if_data,
6376 u.mgd.ml_reconf_work.work);
6377 u16 new_valid_links, new_active_links, new_dormant_links;
6380 if (!sdata->u.mgd.removed_links)
6384 "MLO Reconfiguration: work: valid=0x%x, removed=0x%x\n",
6385 sdata->vif.valid_links, sdata->u.mgd.removed_links);
6387 new_valid_links = sdata->vif.valid_links & ~sdata->u.mgd.removed_links;
6388 if (new_valid_links == sdata->vif.valid_links)
6391 if (!new_valid_links ||
6392 !(new_valid_links & ~sdata->vif.dormant_links)) {
6393 sdata_info(sdata, "No valid links after reconfiguration\n");
6398 new_active_links = sdata->vif.active_links & ~sdata->u.mgd.removed_links;
6399 if (new_active_links != sdata->vif.active_links) {
6400 if (!new_active_links)
6402 BIT(ffs(new_valid_links &
6403 ~sdata->vif.dormant_links) - 1);
6405 ret = ieee80211_set_active_links(&sdata->vif, new_active_links);
6408 "Failed setting active links\n");
6413 new_dormant_links = sdata->vif.dormant_links & ~sdata->u.mgd.removed_links;
6415 ret = ieee80211_vif_set_links(sdata, new_valid_links,
6418 sdata_info(sdata, "Failed setting valid links\n");
6420 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS);
6424 cfg80211_links_removed(sdata->dev, sdata->u.mgd.removed_links);
6426 __ieee80211_disconnect(sdata);
6428 sdata->u.mgd.removed_links = 0;
6431 static void ieee80211_ml_reconfiguration(struct ieee80211_sub_if_data *sdata,
6432 struct ieee802_11_elems *elems)
6434 const struct element *sub;
6435 unsigned long removed_links = 0;
6436 u16 link_removal_timeout[IEEE80211_MLD_MAX_NUM_LINKS] = {};
6440 if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_reconf)
6443 /* Directly parse the sub elements as the common information doesn't
6444 * hold any useful information.
6446 for_each_mle_subelement(sub, (const u8 *)elems->ml_reconf,
6447 elems->ml_reconf_len) {
6448 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
6449 u8 *pos = prof->variable;
6452 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE)
6455 if (!ieee80211_mle_reconf_sta_prof_size_ok(sub->data,
6459 control = le16_to_cpu(prof->control);
6460 link_id = control & IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID;
6462 removed_links |= BIT(link_id);
6464 /* the MAC address should not be included, but handle it */
6466 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT)
6469 /* According to Draft P802.11be_D3.0, the control should
6470 * include the AP Removal Timer present. If the AP Removal Timer
6471 * is not present assume immediate removal.
6474 IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT)
6475 link_removal_timeout[link_id] = get_unaligned_le16(pos);
6478 removed_links &= sdata->vif.valid_links;
6479 if (!removed_links) {
6480 /* In case the removal was cancelled, abort it */
6481 if (sdata->u.mgd.removed_links) {
6482 sdata->u.mgd.removed_links = 0;
6483 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6484 &sdata->u.mgd.ml_reconf_work);
6490 for_each_set_bit(link_id, &removed_links, IEEE80211_MLD_MAX_NUM_LINKS) {
6491 struct ieee80211_bss_conf *link_conf =
6492 sdata_dereference(sdata->vif.link_conf[link_id], sdata);
6496 removed_links &= ~BIT(link_id);
6500 if (link_removal_timeout[link_id] < 1)
6503 link_delay = link_conf->beacon_int *
6504 (link_removal_timeout[link_id] - 1);
6509 delay = min(delay, link_delay);
6512 sdata->u.mgd.removed_links = removed_links;
6513 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
6514 &sdata->u.mgd.ml_reconf_work,
6515 TU_TO_JIFFIES(delay));
6518 static int ieee80211_ttlm_set_links(struct ieee80211_sub_if_data *sdata,
6519 u16 active_links, u16 dormant_links,
6520 u16 suspended_links)
6525 if (!active_links) {
6530 /* If there is an active negotiated TTLM, it should be discarded by
6531 * the new negotiated/advertised TTLM.
6533 if (sdata->vif.neg_ttlm.valid) {
6534 memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm));
6535 sdata->vif.suspended_links = 0;
6536 changed = BSS_CHANGED_MLD_TTLM;
6539 if (sdata->vif.active_links != active_links) {
6540 /* usable links are affected when active_links are changed,
6541 * so notify the driver about the status change
6543 changed |= BSS_CHANGED_MLD_VALID_LINKS;
6544 active_links &= sdata->vif.active_links;
6547 BIT(__ffs(sdata->vif.valid_links &
6549 ret = ieee80211_set_active_links(&sdata->vif, active_links);
6551 sdata_info(sdata, "Failed to set TTLM active links\n");
6556 ret = ieee80211_vif_set_links(sdata, sdata->vif.valid_links,
6559 sdata_info(sdata, "Failed to set TTLM dormant links\n");
6563 sdata->vif.suspended_links = suspended_links;
6564 if (sdata->vif.suspended_links)
6565 changed |= BSS_CHANGED_MLD_TTLM;
6567 ieee80211_vif_cfg_change_notify(sdata, changed);
6571 ieee80211_disconnect(&sdata->vif, false);
6576 static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy,
6577 struct wiphy_work *work)
6579 u16 new_active_links, new_dormant_links;
6580 struct ieee80211_sub_if_data *sdata =
6581 container_of(work, struct ieee80211_sub_if_data,
6582 u.mgd.ttlm_work.work);
6584 new_active_links = sdata->u.mgd.ttlm_info.map &
6585 sdata->vif.valid_links;
6586 new_dormant_links = ~sdata->u.mgd.ttlm_info.map &
6587 sdata->vif.valid_links;
6589 ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 0);
6590 if (ieee80211_ttlm_set_links(sdata, new_active_links, new_dormant_links,
6594 sdata->u.mgd.ttlm_info.active = true;
6595 sdata->u.mgd.ttlm_info.switch_time = 0;
6598 static u16 ieee80211_get_ttlm(u8 bm_size, u8 *data)
6603 return get_unaligned_le16(data);
6607 ieee80211_parse_adv_t2l(struct ieee80211_sub_if_data *sdata,
6608 const struct ieee80211_ttlm_elem *ttlm,
6609 struct ieee80211_adv_ttlm_info *ttlm_info)
6611 /* The element size was already validated in
6612 * ieee80211_tid_to_link_map_size_ok()
6614 u8 control, link_map_presence, map_size, tid;
6617 memset(ttlm_info, 0, sizeof(*ttlm_info));
6618 pos = (void *)ttlm->optional;
6619 control = ttlm->control;
6621 if ((control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) ||
6622 !(control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT))
6625 if ((control & IEEE80211_TTLM_CONTROL_DIRECTION) !=
6626 IEEE80211_TTLM_DIRECTION_BOTH) {
6627 sdata_info(sdata, "Invalid advertised T2L map direction\n");
6631 link_map_presence = *pos;
6634 ttlm_info->switch_time = get_unaligned_le16(pos);
6636 /* Since ttlm_info->switch_time == 0 means no switch time, bump it
6639 if (!ttlm_info->switch_time)
6640 ttlm_info->switch_time = 1;
6644 if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT) {
6645 ttlm_info->duration = pos[0] | pos[1] << 8 | pos[2] << 16;
6649 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
6654 /* According to Draft P802.11be_D3.0 clause 35.3.7.1.7, an AP MLD shall
6655 * not advertise a TID-to-link mapping that does not map all TIDs to the
6656 * same link set, reject frame if not all links have mapping
6658 if (link_map_presence != 0xff) {
6660 "Invalid advertised T2L mapping presence indicator\n");
6664 ttlm_info->map = ieee80211_get_ttlm(map_size, pos);
6665 if (!ttlm_info->map) {
6667 "Invalid advertised T2L map for TID 0\n");
6673 for (tid = 1; tid < 8; tid++) {
6674 u16 map = ieee80211_get_ttlm(map_size, pos);
6676 if (map != ttlm_info->map) {
6677 sdata_info(sdata, "Invalid advertised T2L map for tid %d\n",
6687 static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata,
6688 struct ieee802_11_elems *elems,
6694 if (!ieee80211_vif_is_mld(&sdata->vif))
6697 if (!elems->ttlm_num) {
6698 if (sdata->u.mgd.ttlm_info.switch_time) {
6699 /* if a planned TID-to-link mapping was cancelled -
6702 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6703 &sdata->u.mgd.ttlm_work);
6704 } else if (sdata->u.mgd.ttlm_info.active) {
6705 /* if no TID-to-link element, set to default mapping in
6706 * which all TIDs are mapped to all setup links
6708 ret = ieee80211_vif_set_links(sdata,
6709 sdata->vif.valid_links,
6712 sdata_info(sdata, "Failed setting valid/dormant links\n");
6715 ieee80211_vif_cfg_change_notify(sdata,
6716 BSS_CHANGED_MLD_VALID_LINKS);
6718 memset(&sdata->u.mgd.ttlm_info, 0,
6719 sizeof(sdata->u.mgd.ttlm_info));
6723 for (i = 0; i < elems->ttlm_num; i++) {
6724 struct ieee80211_adv_ttlm_info ttlm_info;
6727 res = ieee80211_parse_adv_t2l(sdata, elems->ttlm[i],
6731 __ieee80211_disconnect(sdata);
6735 if (ttlm_info.switch_time) {
6736 u16 beacon_ts_tu, st_tu, delay;
6740 /* The t2l map switch time is indicated with a partial
6741 * TSF value (bits 10 to 25), get the partial beacon TS
6742 * as well, and calc the delay to the start time.
6744 mask = GENMASK_ULL(25, 10);
6745 beacon_ts_tu = (beacon_ts & mask) >> 10;
6746 st_tu = ttlm_info.switch_time;
6747 delay = st_tu - beacon_ts_tu;
6750 * If the switch time is far in the future, then it
6751 * could also be the previous switch still being
6753 * We can simply ignore it for now, if it is a future
6754 * switch the AP will continue to announce it anyway.
6756 if (delay > IEEE80211_ADV_TTLM_ST_UNDERFLOW)
6759 delay_jiffies = TU_TO_JIFFIES(delay);
6761 /* Link switching can take time, so schedule it
6762 * 100ms before to be ready on time
6764 if (delay_jiffies > IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS)
6766 IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS;
6770 sdata->u.mgd.ttlm_info = ttlm_info;
6771 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6772 &sdata->u.mgd.ttlm_work);
6773 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
6774 &sdata->u.mgd.ttlm_work,
6782 ieee80211_mgd_check_cross_link_csa(struct ieee80211_sub_if_data *sdata,
6783 int reporting_link_id,
6784 struct ieee802_11_elems *elems)
6786 const struct element *sta_profiles[IEEE80211_MLD_MAX_NUM_LINKS] = {};
6787 ssize_t sta_profiles_len[IEEE80211_MLD_MAX_NUM_LINKS] = {};
6788 const struct element *sub;
6790 size_t subelems_len;
6794 if (!ieee80211_mle_size_ok((u8 *)elems->ml_basic, elems->ml_basic_len))
6797 common_size = ieee80211_mle_common_size((u8 *)elems->ml_basic);
6798 subelems = (u8 *)elems->ml_basic + common_size;
6799 subelems_len = elems->ml_basic_len - common_size;
6801 for_each_element_id(sub, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE,
6802 subelems, subelems_len) {
6803 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
6804 struct ieee80211_link_data *link;
6807 if (!ieee80211_mle_basic_sta_prof_size_ok(sub->data,
6811 link_id = le16_get_bits(prof->control,
6812 IEEE80211_MLE_STA_CONTROL_LINK_ID);
6813 /* need a valid link ID, but also not our own, both AP bugs */
6814 if (link_id == reporting_link_id ||
6815 link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
6818 link = sdata_dereference(sdata->link[link_id], sdata);
6822 len = cfg80211_defragment_element(sub, subelems, subelems_len,
6824 IEEE80211_MLE_SUBELEM_FRAGMENT);
6825 if (WARN_ON(len < 0))
6828 sta_profiles[link_id] = sub;
6829 sta_profiles_len[link_id] = len;
6832 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
6833 struct ieee80211_mle_per_sta_profile *prof;
6834 struct ieee802_11_elems *prof_elems;
6835 struct ieee80211_link_data *link;
6838 if (link_id == reporting_link_id)
6841 link = sdata_dereference(sdata->link[link_id], sdata);
6845 if (!sta_profiles[link_id]) {
6850 /* we can defragment in-place, won't use the buffer again */
6851 len = cfg80211_defragment_element(sta_profiles[link_id],
6852 subelems, subelems_len,
6853 (void *)sta_profiles[link_id],
6854 sta_profiles_len[link_id],
6855 IEEE80211_MLE_SUBELEM_FRAGMENT);
6856 if (WARN_ON(len != sta_profiles_len[link_id]))
6859 prof = (void *)sta_profiles[link_id];
6860 prof_elems = ieee802_11_parse_elems(prof->variable +
6861 (prof->sta_info_len - 1),
6863 (prof->sta_info_len - 1),
6866 /* memory allocation failed - let's hope that's transient */
6872 * FIXME: the timings here are obviously incorrect,
6873 * but only older Intel drivers seem to care, and
6874 * those don't have MLO. If you really need this,
6875 * the problem is having to calculate it with the
6876 * TSF offset etc. The device_timestamp is still
6877 * correct, of course.
6879 ieee80211_sta_process_chanswitch(link, 0, 0, elems, prof_elems,
6880 IEEE80211_CSA_SOURCE_OTHER_LINK);
6885 static bool ieee80211_mgd_ssid_mismatch(struct ieee80211_sub_if_data *sdata,
6886 const struct ieee802_11_elems *elems)
6888 struct ieee80211_vif_cfg *cfg = &sdata->vif.cfg;
6889 static u8 zero_ssid[IEEE80211_MAX_SSID_LEN];
6894 /* hidden SSID: zero length */
6895 if (elems->ssid_len == 0)
6898 if (elems->ssid_len != cfg->ssid_len)
6901 /* hidden SSID: zeroed out */
6902 if (!memcmp(elems->ssid, zero_ssid, elems->ssid_len))
6905 return memcmp(elems->ssid, cfg->ssid, cfg->ssid_len);
6908 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
6909 struct ieee80211_hdr *hdr, size_t len,
6910 struct ieee80211_rx_status *rx_status)
6912 struct ieee80211_sub_if_data *sdata = link->sdata;
6913 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6914 struct ieee80211_bss_conf *bss_conf = link->conf;
6915 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
6916 struct ieee80211_mgmt *mgmt = (void *) hdr;
6918 struct ieee802_11_elems *elems;
6919 struct ieee80211_local *local = sdata->local;
6920 struct ieee80211_chanctx_conf *chanctx_conf;
6921 struct ieee80211_supported_band *sband;
6922 struct ieee80211_channel *chan;
6923 struct link_sta_info *link_sta;
6924 struct sta_info *sta;
6929 u8 *bssid, *variable = mgmt->u.beacon.variable;
6930 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
6931 struct ieee80211_elems_parse_params parse_params = {
6932 .mode = link->u.mgd.conn.mode,
6937 lockdep_assert_wiphy(local->hw.wiphy);
6939 /* Process beacon from the current BSS */
6940 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
6941 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
6942 struct ieee80211_ext *ext = (void *) mgmt;
6944 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
6945 variable = ext->u.s1g_short_beacon.variable;
6947 variable = ext->u.s1g_beacon.variable;
6950 baselen = (u8 *) variable - (u8 *) mgmt;
6954 parse_params.start = variable;
6955 parse_params.len = len - baselen;
6958 chanctx_conf = rcu_dereference(bss_conf->chanctx_conf);
6959 if (!chanctx_conf) {
6964 if (ieee80211_rx_status_to_khz(rx_status) !=
6965 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
6969 chan = chanctx_conf->def.chan;
6972 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
6973 !WARN_ON(ieee80211_vif_is_mld(&sdata->vif)) &&
6974 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
6975 parse_params.bss = ifmgd->assoc_data->link[0].bss;
6976 elems = ieee802_11_parse_elems_full(&parse_params);
6980 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6982 if (elems->dtim_period)
6983 link->u.mgd.dtim_period = elems->dtim_period;
6984 link->u.mgd.have_beacon = true;
6985 ifmgd->assoc_data->need_beacon = false;
6986 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
6987 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
6988 bss_conf->sync_tsf =
6989 le64_to_cpu(mgmt->u.beacon.timestamp);
6990 bss_conf->sync_device_ts =
6991 rx_status->device_timestamp;
6992 bss_conf->sync_dtim_count = elems->dtim_count;
6995 if (elems->mbssid_config_ie)
6996 bss_conf->profile_periodicity =
6997 elems->mbssid_config_ie->profile_periodicity;
6999 bss_conf->profile_periodicity = 0;
7001 if (elems->ext_capab_len >= 11 &&
7002 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
7003 bss_conf->ema_ap = true;
7005 bss_conf->ema_ap = false;
7007 /* continue assoc process */
7008 ifmgd->assoc_data->timeout = jiffies;
7009 ifmgd->assoc_data->timeout_started = true;
7010 run_again(sdata, ifmgd->assoc_data->timeout);
7015 if (!ifmgd->associated ||
7016 !ieee80211_rx_our_beacon(bssid, bss_conf->bss))
7018 bssid = link->u.mgd.bssid;
7020 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
7021 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
7024 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
7025 mlme_dbg_ratelimited(sdata,
7026 "cancelling AP probe due to a received beacon\n");
7027 ieee80211_reset_ap_probe(sdata);
7031 * Push the beacon loss detection into the future since
7032 * we are processing a beacon from the AP just now.
7034 ieee80211_sta_reset_beacon_monitor(sdata);
7036 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
7037 * element (which carries the beacon interval). Don't forget to add a
7038 * bit to care_about_ies[] above if mac80211 is interested in a
7039 * changing S1G element.
7041 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
7042 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
7043 parse_params.bss = bss_conf->bss;
7044 parse_params.filter = care_about_ies;
7045 parse_params.crc = ncrc;
7046 elems = ieee802_11_parse_elems_full(&parse_params);
7050 if (rx_status->flag & RX_FLAG_DECRYPTED &&
7051 ieee80211_mgd_ssid_mismatch(sdata, elems)) {
7052 sdata_info(sdata, "SSID mismatch for AP %pM, disconnect\n",
7053 sdata->vif.cfg.ap_addr);
7054 __ieee80211_disconnect(sdata);
7060 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
7061 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
7062 if (local->hw.conf.dynamic_ps_timeout > 0) {
7063 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
7064 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
7065 ieee80211_hw_config(local,
7066 IEEE80211_CONF_CHANGE_PS);
7068 ieee80211_send_nullfunc(local, sdata, false);
7069 } else if (!local->pspolling && sdata->u.mgd.powersave) {
7070 local->pspolling = true;
7073 * Here is assumed that the driver will be
7074 * able to send ps-poll frame and receive a
7075 * response even though power save mode is
7076 * enabled, but some drivers might require
7077 * to disable power save here. This needs
7078 * to be investigated.
7080 ieee80211_send_pspoll(local, sdata);
7084 if (sdata->vif.p2p ||
7085 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
7086 struct ieee80211_p2p_noa_attr noa = {};
7089 ret = cfg80211_get_p2p_attr(variable,
7091 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
7092 (u8 *) &noa, sizeof(noa));
7094 if (link->u.mgd.p2p_noa_index != noa.index) {
7095 /* valid noa_attr and index changed */
7096 link->u.mgd.p2p_noa_index = noa.index;
7097 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
7098 changed |= BSS_CHANGED_P2P_PS;
7100 * make sure we update all information, the CRC
7101 * mechanism doesn't look at P2P attributes.
7103 link->u.mgd.beacon_crc_valid = false;
7105 } else if (link->u.mgd.p2p_noa_index != -1) {
7106 /* noa_attr not found and we had valid noa_attr before */
7107 link->u.mgd.p2p_noa_index = -1;
7108 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
7109 changed |= BSS_CHANGED_P2P_PS;
7110 link->u.mgd.beacon_crc_valid = false;
7115 * Update beacon timing and dtim count on every beacon appearance. This
7116 * will allow the driver to use the most updated values. Do it before
7117 * comparing this one with last received beacon.
7118 * IMPORTANT: These parameters would possibly be out of sync by the time
7119 * the driver will use them. The synchronized view is currently
7120 * guaranteed only in certain callbacks.
7122 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
7123 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
7124 bss_conf->sync_tsf =
7125 le64_to_cpu(mgmt->u.beacon.timestamp);
7126 bss_conf->sync_device_ts =
7127 rx_status->device_timestamp;
7128 bss_conf->sync_dtim_count = elems->dtim_count;
7131 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
7132 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
7134 link->u.mgd.beacon_crc = ncrc;
7135 link->u.mgd.beacon_crc_valid = true;
7137 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
7139 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
7140 rx_status->device_timestamp,
7142 IEEE80211_CSA_SOURCE_BEACON);
7144 /* note that after this elems->ml_basic can no longer be used fully */
7145 ieee80211_mgd_check_cross_link_csa(sdata, rx_status->link_id, elems);
7147 ieee80211_mgd_update_bss_param_ch_cnt(sdata, bss_conf, elems);
7149 if (!link->u.mgd.disable_wmm_tracking &&
7150 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
7151 elems->wmm_param_len,
7152 elems->mu_edca_param_set))
7153 changed |= BSS_CHANGED_QOS;
7156 * If we haven't had a beacon before, tell the driver about the
7157 * DTIM period (and beacon timing if desired) now.
7159 if (!link->u.mgd.have_beacon) {
7160 /* a few bogus AP send dtim_period = 0 or no TIM IE */
7161 bss_conf->dtim_period = elems->dtim_period ?: 1;
7163 changed |= BSS_CHANGED_BEACON_INFO;
7164 link->u.mgd.have_beacon = true;
7166 ieee80211_recalc_ps(local);
7168 ieee80211_recalc_ps_vif(sdata);
7171 if (elems->erp_info) {
7173 erp_value = elems->erp_info[0];
7178 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
7179 changed |= ieee80211_handle_bss_capability(link,
7180 le16_to_cpu(mgmt->u.beacon.capab_info),
7181 erp_valid, erp_value);
7183 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
7184 if (WARN_ON(!sta)) {
7187 link_sta = rcu_dereference_protected(sta->link[link->link_id],
7188 lockdep_is_held(&local->hw.wiphy->mtx));
7189 if (WARN_ON(!link_sta)) {
7193 if (WARN_ON(!bss_conf->chanreq.oper.chan))
7196 sband = local->hw.wiphy->bands[bss_conf->chanreq.oper.chan->band];
7198 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
7200 if (ieee80211_config_bw(link, elems, true, &changed, "beacon")) {
7201 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7202 WLAN_REASON_DEAUTH_LEAVING,
7204 ieee80211_report_disconnect(sdata, deauth_buf,
7205 sizeof(deauth_buf), true,
7206 WLAN_REASON_DEAUTH_LEAVING,
7211 if (elems->opmode_notif)
7212 ieee80211_vht_handle_opmode(sdata, link_sta,
7213 *elems->opmode_notif,
7216 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
7217 elems->country_elem,
7218 elems->country_elem_len,
7219 elems->pwr_constr_elem,
7220 elems->cisco_dtpc_elem);
7222 ieee80211_ml_reconfiguration(sdata, elems);
7223 ieee80211_process_adv_ttlm(sdata, elems,
7224 le64_to_cpu(mgmt->u.beacon.timestamp));
7226 ieee80211_link_info_change_notify(sdata, link, changed);
7231 static void ieee80211_apply_neg_ttlm(struct ieee80211_sub_if_data *sdata,
7232 struct ieee80211_neg_ttlm neg_ttlm)
7234 u16 new_active_links, new_dormant_links, new_suspended_links, map = 0;
7237 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++)
7238 map |= neg_ttlm.downlink[i] | neg_ttlm.uplink[i];
7240 /* If there is an active TTLM, unset previously suspended links */
7241 if (sdata->vif.neg_ttlm.valid)
7242 sdata->vif.dormant_links &= ~sdata->vif.suspended_links;
7244 /* exclude links that are already disabled by advertised TTLM */
7246 map & sdata->vif.valid_links & ~sdata->vif.dormant_links;
7247 new_suspended_links =
7248 (~map & sdata->vif.valid_links) & ~sdata->vif.dormant_links;
7249 new_dormant_links = sdata->vif.dormant_links | new_suspended_links;
7250 if (ieee80211_ttlm_set_links(sdata, new_active_links,
7251 new_dormant_links, new_suspended_links))
7254 sdata->vif.neg_ttlm = neg_ttlm;
7255 sdata->vif.neg_ttlm.valid = true;
7258 static void ieee80211_neg_ttlm_timeout_work(struct wiphy *wiphy,
7259 struct wiphy_work *work)
7261 struct ieee80211_sub_if_data *sdata =
7262 container_of(work, struct ieee80211_sub_if_data,
7263 u.mgd.neg_ttlm_timeout_work.work);
7266 "No negotiated TTLM response from AP, disconnecting.\n");
7268 __ieee80211_disconnect(sdata);
7272 ieee80211_neg_ttlm_add_suggested_map(struct sk_buff *skb,
7273 struct ieee80211_neg_ttlm *neg_ttlm)
7275 u8 i, direction[IEEE80211_TTLM_MAX_CNT];
7277 if (memcmp(neg_ttlm->downlink, neg_ttlm->uplink,
7278 sizeof(neg_ttlm->downlink))) {
7279 direction[0] = IEEE80211_TTLM_DIRECTION_DOWN;
7280 direction[1] = IEEE80211_TTLM_DIRECTION_UP;
7282 direction[0] = IEEE80211_TTLM_DIRECTION_BOTH;
7285 for (i = 0; i < ARRAY_SIZE(direction); i++) {
7286 u8 tid, len, map_ind = 0, *len_pos, *map_ind_pos, *pos;
7289 len = sizeof(struct ieee80211_ttlm_elem) + 1 + 1;
7291 pos = skb_put(skb, len + 2);
7292 *pos++ = WLAN_EID_EXTENSION;
7294 *pos++ = WLAN_EID_EXT_TID_TO_LINK_MAPPING;
7295 *pos++ = direction[i];
7296 map_ind_pos = pos++;
7297 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) {
7298 map = direction[i] == IEEE80211_TTLM_DIRECTION_UP ?
7299 cpu_to_le16(neg_ttlm->uplink[tid]) :
7300 cpu_to_le16(neg_ttlm->downlink[tid]);
7305 map_ind |= BIT(tid);
7306 skb_put_data(skb, &map, sizeof(map));
7309 *map_ind_pos = map_ind;
7312 if (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH)
7318 ieee80211_send_neg_ttlm_req(struct ieee80211_sub_if_data *sdata,
7319 struct ieee80211_neg_ttlm *neg_ttlm,
7322 struct ieee80211_local *local = sdata->local;
7323 struct ieee80211_mgmt *mgmt;
7324 struct sk_buff *skb;
7325 int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_req);
7326 int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 +
7327 2 * 2 * IEEE80211_TTLM_NUM_TIDS;
7329 skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len);
7333 skb_reserve(skb, local->tx_headroom);
7334 mgmt = skb_put_zero(skb, hdr_len);
7335 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
7336 IEEE80211_STYPE_ACTION);
7337 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
7338 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
7339 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
7341 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
7342 mgmt->u.action.u.ttlm_req.action_code =
7343 WLAN_PROTECTED_EHT_ACTION_TTLM_REQ;
7344 mgmt->u.action.u.ttlm_req.dialog_token = dialog_token;
7345 ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm);
7346 ieee80211_tx_skb(sdata, skb);
7349 int ieee80211_req_neg_ttlm(struct ieee80211_sub_if_data *sdata,
7350 struct cfg80211_ttlm_params *params)
7352 struct ieee80211_neg_ttlm neg_ttlm = {};
7355 if (!ieee80211_vif_is_mld(&sdata->vif) ||
7356 !(sdata->vif.cfg.mld_capa_op &
7357 IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP))
7360 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
7361 if ((params->dlink[i] & ~sdata->vif.valid_links) ||
7362 (params->ulink[i] & ~sdata->vif.valid_links))
7365 neg_ttlm.downlink[i] = params->dlink[i];
7366 neg_ttlm.uplink[i] = params->ulink[i];
7369 if (drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm) !=
7370 NEG_TTLM_RES_ACCEPT)
7373 ieee80211_apply_neg_ttlm(sdata, neg_ttlm);
7374 sdata->u.mgd.dialog_token_alloc++;
7375 ieee80211_send_neg_ttlm_req(sdata, &sdata->vif.neg_ttlm,
7376 sdata->u.mgd.dialog_token_alloc);
7377 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
7378 &sdata->u.mgd.neg_ttlm_timeout_work);
7379 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
7380 &sdata->u.mgd.neg_ttlm_timeout_work,
7381 IEEE80211_NEG_TTLM_REQ_TIMEOUT);
7386 ieee80211_send_neg_ttlm_res(struct ieee80211_sub_if_data *sdata,
7387 enum ieee80211_neg_ttlm_res ttlm_res,
7389 struct ieee80211_neg_ttlm *neg_ttlm)
7391 struct ieee80211_local *local = sdata->local;
7392 struct ieee80211_mgmt *mgmt;
7393 struct sk_buff *skb;
7394 int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_res);
7395 int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 +
7396 2 * 2 * IEEE80211_TTLM_NUM_TIDS;
7398 skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len);
7402 skb_reserve(skb, local->tx_headroom);
7403 mgmt = skb_put_zero(skb, hdr_len);
7404 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
7405 IEEE80211_STYPE_ACTION);
7406 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
7407 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
7408 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
7410 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
7411 mgmt->u.action.u.ttlm_res.action_code =
7412 WLAN_PROTECTED_EHT_ACTION_TTLM_RES;
7413 mgmt->u.action.u.ttlm_res.dialog_token = dialog_token;
7418 case NEG_TTLM_RES_REJECT:
7419 mgmt->u.action.u.ttlm_res.status_code =
7420 WLAN_STATUS_DENIED_TID_TO_LINK_MAPPING;
7422 case NEG_TTLM_RES_ACCEPT:
7423 mgmt->u.action.u.ttlm_res.status_code = WLAN_STATUS_SUCCESS;
7425 case NEG_TTLM_RES_SUGGEST_PREFERRED:
7426 mgmt->u.action.u.ttlm_res.status_code =
7427 WLAN_STATUS_PREF_TID_TO_LINK_MAPPING_SUGGESTED;
7428 ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm);
7432 ieee80211_tx_skb(sdata, skb);
7436 ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata,
7437 const struct ieee80211_ttlm_elem *ttlm,
7438 struct ieee80211_neg_ttlm *neg_ttlm,
7441 u8 control, link_map_presence, map_size, tid;
7444 /* The element size was already validated in
7445 * ieee80211_tid_to_link_map_size_ok()
7447 pos = (void *)ttlm->optional;
7449 control = ttlm->control;
7451 /* mapping switch time and expected duration fields are not expected
7452 * in case of negotiated TTLM
7454 if (control & (IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT |
7455 IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT)) {
7457 "Invalid TTLM element in negotiated TTLM request\n");
7461 if (control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) {
7462 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) {
7463 neg_ttlm->downlink[tid] = sdata->vif.valid_links;
7464 neg_ttlm->uplink[tid] = sdata->vif.valid_links;
7466 *direction = IEEE80211_TTLM_DIRECTION_BOTH;
7470 *direction = u8_get_bits(control, IEEE80211_TTLM_CONTROL_DIRECTION);
7471 if (*direction != IEEE80211_TTLM_DIRECTION_DOWN &&
7472 *direction != IEEE80211_TTLM_DIRECTION_UP &&
7473 *direction != IEEE80211_TTLM_DIRECTION_BOTH)
7476 link_map_presence = *pos;
7479 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
7484 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) {
7487 if (link_map_presence & BIT(tid)) {
7488 map = ieee80211_get_ttlm(map_size, pos);
7491 "No active links for TID %d", tid);
7498 switch (*direction) {
7499 case IEEE80211_TTLM_DIRECTION_BOTH:
7500 neg_ttlm->downlink[tid] = map;
7501 neg_ttlm->uplink[tid] = map;
7503 case IEEE80211_TTLM_DIRECTION_DOWN:
7504 neg_ttlm->downlink[tid] = map;
7506 case IEEE80211_TTLM_DIRECTION_UP:
7507 neg_ttlm->uplink[tid] = map;
7517 void ieee80211_process_neg_ttlm_req(struct ieee80211_sub_if_data *sdata,
7518 struct ieee80211_mgmt *mgmt, size_t len)
7520 u8 dialog_token, direction[IEEE80211_TTLM_MAX_CNT] = {}, i;
7522 enum ieee80211_neg_ttlm_res ttlm_res = NEG_TTLM_RES_ACCEPT;
7523 struct ieee802_11_elems *elems = NULL;
7524 struct ieee80211_neg_ttlm neg_ttlm = {};
7526 BUILD_BUG_ON(ARRAY_SIZE(direction) != ARRAY_SIZE(elems->ttlm));
7528 if (!ieee80211_vif_is_mld(&sdata->vif))
7531 dialog_token = mgmt->u.action.u.ttlm_req.dialog_token;
7532 ies_len = len - offsetof(struct ieee80211_mgmt,
7533 u.action.u.ttlm_req.variable);
7534 elems = ieee802_11_parse_elems(mgmt->u.action.u.ttlm_req.variable,
7535 ies_len, true, NULL);
7537 ttlm_res = NEG_TTLM_RES_REJECT;
7541 for (i = 0; i < elems->ttlm_num; i++) {
7542 if (ieee80211_parse_neg_ttlm(sdata, elems->ttlm[i],
7543 &neg_ttlm, &direction[i]) ||
7544 (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH &&
7545 elems->ttlm_num != 1)) {
7546 ttlm_res = NEG_TTLM_RES_REJECT;
7551 if (!elems->ttlm_num ||
7552 (elems->ttlm_num == 2 && direction[0] == direction[1])) {
7553 ttlm_res = NEG_TTLM_RES_REJECT;
7557 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
7558 if ((neg_ttlm.downlink[i] &&
7559 (neg_ttlm.downlink[i] & ~sdata->vif.valid_links)) ||
7560 (neg_ttlm.uplink[i] &&
7561 (neg_ttlm.uplink[i] & ~sdata->vif.valid_links))) {
7562 ttlm_res = NEG_TTLM_RES_REJECT;
7567 ttlm_res = drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm);
7569 if (ttlm_res != NEG_TTLM_RES_ACCEPT)
7572 ieee80211_apply_neg_ttlm(sdata, neg_ttlm);
7575 ieee80211_send_neg_ttlm_res(sdata, ttlm_res, dialog_token, &neg_ttlm);
7578 void ieee80211_process_neg_ttlm_res(struct ieee80211_sub_if_data *sdata,
7579 struct ieee80211_mgmt *mgmt, size_t len)
7581 if (!ieee80211_vif_is_mld(&sdata->vif) ||
7582 mgmt->u.action.u.ttlm_req.dialog_token !=
7583 sdata->u.mgd.dialog_token_alloc)
7586 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
7587 &sdata->u.mgd.neg_ttlm_timeout_work);
7589 /* MLD station sends a TID to link mapping request, mainly to handle
7590 * BTM (BSS transition management) request, in which case it needs to
7591 * restrict the active links set.
7592 * In this case it's not expected that the MLD AP will reject the
7593 * negotiated TTLM request.
7594 * This can be better implemented in the future, to handle request
7597 if (mgmt->u.action.u.ttlm_res.status_code != WLAN_STATUS_SUCCESS)
7598 __ieee80211_disconnect(sdata);
7601 static void ieee80211_teardown_ttlm_work(struct wiphy *wiphy,
7602 struct wiphy_work *work)
7604 u16 new_dormant_links;
7605 struct ieee80211_sub_if_data *sdata =
7606 container_of(work, struct ieee80211_sub_if_data,
7607 u.mgd.teardown_ttlm_work);
7609 if (!sdata->vif.neg_ttlm.valid)
7612 memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm));
7614 sdata->vif.dormant_links & ~sdata->vif.suspended_links;
7615 sdata->vif.suspended_links = 0;
7616 ieee80211_vif_set_links(sdata, sdata->vif.valid_links,
7618 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_TTLM |
7619 BSS_CHANGED_MLD_VALID_LINKS);
7622 void ieee80211_send_teardown_neg_ttlm(struct ieee80211_vif *vif)
7624 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7625 struct ieee80211_local *local = sdata->local;
7626 struct ieee80211_mgmt *mgmt;
7627 struct sk_buff *skb;
7628 int frame_len = offsetofend(struct ieee80211_mgmt,
7629 u.action.u.ttlm_tear_down);
7630 struct ieee80211_tx_info *info;
7632 skb = dev_alloc_skb(local->hw.extra_tx_headroom + frame_len);
7636 skb_reserve(skb, local->hw.extra_tx_headroom);
7637 mgmt = skb_put_zero(skb, frame_len);
7638 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
7639 IEEE80211_STYPE_ACTION);
7640 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
7641 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
7642 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
7644 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
7645 mgmt->u.action.u.ttlm_tear_down.action_code =
7646 WLAN_PROTECTED_EHT_ACTION_TTLM_TEARDOWN;
7648 info = IEEE80211_SKB_CB(skb);
7649 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
7650 info->status_data = IEEE80211_STATUS_TYPE_NEG_TTLM;
7651 ieee80211_tx_skb(sdata, skb);
7653 EXPORT_SYMBOL(ieee80211_send_teardown_neg_ttlm);
7655 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
7656 struct sk_buff *skb)
7658 struct ieee80211_link_data *link = &sdata->deflink;
7659 struct ieee80211_rx_status *rx_status;
7660 struct ieee80211_hdr *hdr;
7663 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7665 rx_status = (struct ieee80211_rx_status *) skb->cb;
7666 hdr = (struct ieee80211_hdr *) skb->data;
7667 fc = le16_to_cpu(hdr->frame_control);
7669 switch (fc & IEEE80211_FCTL_STYPE) {
7670 case IEEE80211_STYPE_S1G_BEACON:
7671 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
7676 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
7677 struct sk_buff *skb)
7679 struct ieee80211_link_data *link = &sdata->deflink;
7680 struct ieee80211_rx_status *rx_status;
7681 struct ieee802_11_elems *elems;
7682 struct ieee80211_mgmt *mgmt;
7686 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7688 rx_status = (struct ieee80211_rx_status *) skb->cb;
7689 mgmt = (struct ieee80211_mgmt *) skb->data;
7690 fc = le16_to_cpu(mgmt->frame_control);
7692 if (rx_status->link_valid) {
7693 link = sdata_dereference(sdata->link[rx_status->link_id],
7699 switch (fc & IEEE80211_FCTL_STYPE) {
7700 case IEEE80211_STYPE_BEACON:
7701 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
7702 skb->len, rx_status);
7704 case IEEE80211_STYPE_PROBE_RESP:
7705 ieee80211_rx_mgmt_probe_resp(link, skb);
7707 case IEEE80211_STYPE_AUTH:
7708 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
7710 case IEEE80211_STYPE_DEAUTH:
7711 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
7713 case IEEE80211_STYPE_DISASSOC:
7714 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
7716 case IEEE80211_STYPE_ASSOC_RESP:
7717 case IEEE80211_STYPE_REASSOC_RESP:
7718 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
7720 case IEEE80211_STYPE_ACTION:
7721 if (!sdata->u.mgd.associated ||
7722 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
7725 switch (mgmt->u.action.category) {
7726 case WLAN_CATEGORY_SPECTRUM_MGMT:
7727 ies_len = skb->len -
7728 offsetof(struct ieee80211_mgmt,
7729 u.action.u.chan_switch.variable);
7734 /* CSA IE cannot be overridden, no need for BSSID */
7735 elems = ieee802_11_parse_elems(
7736 mgmt->u.action.u.chan_switch.variable,
7737 ies_len, true, NULL);
7739 if (elems && !elems->parse_error) {
7740 enum ieee80211_csa_source src =
7741 IEEE80211_CSA_SOURCE_PROT_ACTION;
7743 ieee80211_sta_process_chanswitch(link,
7745 rx_status->device_timestamp,
7751 case WLAN_CATEGORY_PUBLIC:
7752 case WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION:
7753 ies_len = skb->len -
7754 offsetof(struct ieee80211_mgmt,
7755 u.action.u.ext_chan_switch.variable);
7761 * extended CSA IE can't be overridden, no need for
7764 elems = ieee802_11_parse_elems(
7765 mgmt->u.action.u.ext_chan_switch.variable,
7766 ies_len, true, NULL);
7768 if (elems && !elems->parse_error) {
7769 enum ieee80211_csa_source src;
7771 if (mgmt->u.action.category ==
7772 WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION)
7773 src = IEEE80211_CSA_SOURCE_PROT_ACTION;
7775 src = IEEE80211_CSA_SOURCE_UNPROT_ACTION;
7777 /* for the handling code pretend it was an IE */
7778 elems->ext_chansw_ie =
7779 &mgmt->u.action.u.ext_chan_switch.data;
7781 ieee80211_sta_process_chanswitch(link,
7783 rx_status->device_timestamp,
7795 static void ieee80211_sta_timer(struct timer_list *t)
7797 struct ieee80211_sub_if_data *sdata =
7798 from_timer(sdata, t, u.mgd.timer);
7800 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
7803 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
7806 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7808 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
7811 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
7815 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
7817 struct ieee80211_local *local = sdata->local;
7818 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7819 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
7823 struct ieee80211_prep_tx_info info = {
7824 .subtype = IEEE80211_STYPE_AUTH,
7827 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7829 if (WARN_ON_ONCE(!auth_data))
7834 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
7835 sdata_info(sdata, "authentication with %pM timed out\n",
7836 auth_data->ap_addr);
7839 * Most likely AP is not in the range so remove the
7840 * bss struct for that AP.
7842 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
7847 if (auth_data->algorithm == WLAN_AUTH_SAE)
7848 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
7850 info.link_id = auth_data->link_id;
7851 drv_mgd_prepare_tx(local, sdata, &info);
7853 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
7854 auth_data->ap_addr, auth_data->tries,
7855 IEEE80211_AUTH_MAX_TRIES);
7857 auth_data->expected_transaction = 2;
7859 if (auth_data->algorithm == WLAN_AUTH_SAE) {
7860 trans = auth_data->sae_trans;
7861 status = auth_data->sae_status;
7862 auth_data->expected_transaction = trans;
7865 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
7866 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
7867 IEEE80211_TX_INTFL_MLME_CONN_TX;
7869 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
7870 auth_data->data, auth_data->data_len,
7871 auth_data->ap_addr, auth_data->ap_addr,
7872 NULL, 0, 0, tx_flags);
7874 if (tx_flags == 0) {
7875 if (auth_data->algorithm == WLAN_AUTH_SAE)
7876 auth_data->timeout = jiffies +
7877 IEEE80211_AUTH_TIMEOUT_SAE;
7879 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
7881 auth_data->timeout =
7882 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
7885 auth_data->timeout_started = true;
7886 run_again(sdata, auth_data->timeout);
7891 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
7893 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
7894 struct ieee80211_local *local = sdata->local;
7897 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7899 assoc_data->tries++;
7900 assoc_data->comeback = false;
7901 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
7902 sdata_info(sdata, "association with %pM timed out\n",
7903 assoc_data->ap_addr);
7906 * Most likely AP is not in the range so remove the
7907 * bss struct for that AP.
7909 cfg80211_unlink_bss(local->hw.wiphy,
7910 assoc_data->link[assoc_data->assoc_link_id].bss);
7915 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
7916 assoc_data->ap_addr, assoc_data->tries,
7917 IEEE80211_ASSOC_MAX_TRIES);
7918 ret = ieee80211_send_assoc(sdata);
7922 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
7923 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
7924 assoc_data->timeout_started = true;
7925 run_again(sdata, assoc_data->timeout);
7927 assoc_data->timeout =
7928 round_jiffies_up(jiffies +
7929 IEEE80211_ASSOC_TIMEOUT_LONG);
7930 assoc_data->timeout_started = true;
7931 run_again(sdata, assoc_data->timeout);
7937 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
7938 __le16 fc, bool acked)
7940 struct ieee80211_local *local = sdata->local;
7942 sdata->u.mgd.status_fc = fc;
7943 sdata->u.mgd.status_acked = acked;
7944 sdata->u.mgd.status_received = true;
7946 wiphy_work_queue(local->hw.wiphy, &sdata->work);
7949 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
7951 struct ieee80211_local *local = sdata->local;
7952 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7954 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7956 if (ifmgd->status_received) {
7957 __le16 fc = ifmgd->status_fc;
7958 bool status_acked = ifmgd->status_acked;
7960 ifmgd->status_received = false;
7961 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
7963 if (ifmgd->auth_data->algorithm ==
7965 ifmgd->auth_data->timeout =
7967 IEEE80211_AUTH_TIMEOUT_SAE;
7969 ifmgd->auth_data->timeout =
7971 IEEE80211_AUTH_TIMEOUT_SHORT;
7972 run_again(sdata, ifmgd->auth_data->timeout);
7974 ifmgd->auth_data->timeout = jiffies - 1;
7976 ifmgd->auth_data->timeout_started = true;
7977 } else if (ifmgd->assoc_data &&
7978 !ifmgd->assoc_data->comeback &&
7979 (ieee80211_is_assoc_req(fc) ||
7980 ieee80211_is_reassoc_req(fc))) {
7982 * Update association timeout based on the TX status
7983 * for the (Re)Association Request frame. Skip this if
7984 * we have already processed a (Re)Association Response
7985 * frame that indicated need for association comeback
7986 * at a specific time in the future. This could happen
7987 * if the TX status information is delayed enough for
7988 * the response to be received and processed first.
7991 ifmgd->assoc_data->timeout =
7992 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
7993 run_again(sdata, ifmgd->assoc_data->timeout);
7995 ifmgd->assoc_data->timeout = jiffies - 1;
7997 ifmgd->assoc_data->timeout_started = true;
8001 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
8002 time_after(jiffies, ifmgd->auth_data->timeout)) {
8003 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
8005 * ok ... we waited for assoc or continuation but
8006 * userspace didn't do it, so kill the auth data
8008 ieee80211_destroy_auth_data(sdata, false);
8009 } else if (ieee80211_auth(sdata)) {
8010 u8 ap_addr[ETH_ALEN];
8011 struct ieee80211_event event = {
8013 .u.mlme.data = AUTH_EVENT,
8014 .u.mlme.status = MLME_TIMEOUT,
8017 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
8019 ieee80211_destroy_auth_data(sdata, false);
8021 cfg80211_auth_timeout(sdata->dev, ap_addr);
8022 drv_event_callback(sdata->local, sdata, &event);
8024 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
8025 run_again(sdata, ifmgd->auth_data->timeout);
8027 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
8028 time_after(jiffies, ifmgd->assoc_data->timeout)) {
8029 if ((ifmgd->assoc_data->need_beacon &&
8030 !sdata->deflink.u.mgd.have_beacon) ||
8031 ieee80211_do_assoc(sdata)) {
8032 struct ieee80211_event event = {
8034 .u.mlme.data = ASSOC_EVENT,
8035 .u.mlme.status = MLME_TIMEOUT,
8038 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
8039 drv_event_callback(sdata->local, sdata, &event);
8041 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
8042 run_again(sdata, ifmgd->assoc_data->timeout);
8044 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
8045 ifmgd->associated) {
8046 u8 *bssid = sdata->deflink.u.mgd.bssid;
8049 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
8050 max_tries = max_nullfunc_tries;
8052 max_tries = max_probe_tries;
8054 /* ACK received for nullfunc probing frame */
8055 if (!ifmgd->probe_send_count)
8056 ieee80211_reset_ap_probe(sdata);
8057 else if (ifmgd->nullfunc_failed) {
8058 if (ifmgd->probe_send_count < max_tries) {
8060 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
8061 bssid, ifmgd->probe_send_count,
8063 ieee80211_mgd_probe_ap_send(sdata);
8066 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
8068 ieee80211_sta_connection_lost(sdata,
8069 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
8072 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
8073 run_again(sdata, ifmgd->probe_timeout);
8074 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
8076 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
8077 bssid, probe_wait_ms);
8078 ieee80211_sta_connection_lost(sdata,
8079 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
8080 } else if (ifmgd->probe_send_count < max_tries) {
8082 "No probe response from AP %pM after %dms, try %d/%i\n",
8083 bssid, probe_wait_ms,
8084 ifmgd->probe_send_count, max_tries);
8085 ieee80211_mgd_probe_ap_send(sdata);
8088 * We actually lost the connection ... or did we?
8092 "No probe response from AP %pM after %dms, disconnecting.\n",
8093 bssid, probe_wait_ms);
8095 ieee80211_sta_connection_lost(sdata,
8096 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
8101 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
8103 struct ieee80211_sub_if_data *sdata =
8104 from_timer(sdata, t, u.mgd.bcn_mon_timer);
8106 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
8109 if (sdata->vif.bss_conf.csa_active &&
8110 !sdata->deflink.u.mgd.csa.waiting_bcn)
8113 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
8116 sdata->u.mgd.connection_loss = false;
8117 wiphy_work_queue(sdata->local->hw.wiphy,
8118 &sdata->u.mgd.beacon_connection_loss_work);
8121 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
8123 struct ieee80211_sub_if_data *sdata =
8124 from_timer(sdata, t, u.mgd.conn_mon_timer);
8125 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8126 struct ieee80211_local *local = sdata->local;
8127 struct sta_info *sta;
8128 unsigned long timeout;
8130 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
8133 if (sdata->vif.bss_conf.csa_active &&
8134 !sdata->deflink.u.mgd.csa.waiting_bcn)
8137 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
8141 timeout = sta->deflink.status_stats.last_ack;
8142 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
8143 timeout = sta->deflink.rx_stats.last_rx;
8144 timeout += IEEE80211_CONNECTION_IDLE_TIME;
8146 /* If timeout is after now, then update timer to fire at
8147 * the later date, but do not actually probe at this time.
8149 if (time_is_after_jiffies(timeout)) {
8150 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
8154 wiphy_work_queue(local->hw.wiphy, &sdata->u.mgd.monitor_work);
8157 static void ieee80211_sta_monitor_work(struct wiphy *wiphy,
8158 struct wiphy_work *work)
8160 struct ieee80211_sub_if_data *sdata =
8161 container_of(work, struct ieee80211_sub_if_data,
8162 u.mgd.monitor_work);
8164 ieee80211_mgd_probe_ap(sdata, false);
8167 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
8169 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
8170 __ieee80211_stop_poll(sdata);
8172 /* let's probe the connection once */
8173 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
8174 wiphy_work_queue(sdata->local->hw.wiphy,
8175 &sdata->u.mgd.monitor_work);
8180 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
8182 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8183 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
8185 lockdep_assert_wiphy(sdata->local->hw.wiphy);
8187 if (ifmgd->auth_data || ifmgd->assoc_data) {
8188 const u8 *ap_addr = ifmgd->auth_data ?
8189 ifmgd->auth_data->ap_addr :
8190 ifmgd->assoc_data->ap_addr;
8193 * If we are trying to authenticate / associate while suspending,
8194 * cfg80211 won't know and won't actually abort those attempts,
8195 * thus we need to do that ourselves.
8197 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
8198 IEEE80211_STYPE_DEAUTH,
8199 WLAN_REASON_DEAUTH_LEAVING,
8201 if (ifmgd->assoc_data)
8202 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
8203 if (ifmgd->auth_data)
8204 ieee80211_destroy_auth_data(sdata, false);
8205 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
8206 IEEE80211_DEAUTH_FRAME_LEN,
8210 /* This is a bit of a hack - we should find a better and more generic
8211 * solution to this. Normally when suspending, cfg80211 will in fact
8212 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
8213 * auth (not so important) or assoc (this is the problem) process.
8215 * As a consequence, it can happen that we are in the process of both
8216 * associating and suspending, and receive an association response
8217 * after cfg80211 has checked if it needs to disconnect, but before
8218 * we actually set the flag to drop incoming frames. This will then
8219 * cause the workqueue flush to process the association response in
8220 * the suspend, resulting in a successful association just before it
8221 * tries to remove the interface from the driver, which now though
8222 * has a channel context assigned ... this results in issues.
8224 * To work around this (for now) simply deauth here again if we're
8227 if (ifmgd->associated && !sdata->local->wowlan) {
8229 struct cfg80211_deauth_request req = {
8230 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
8234 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
8235 ieee80211_mgd_deauth(sdata, &req);
8240 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
8242 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8244 lockdep_assert_wiphy(sdata->local->hw.wiphy);
8246 if (!ifmgd->associated)
8249 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
8250 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
8251 mlme_dbg(sdata, "driver requested disconnect after resume\n");
8252 ieee80211_sta_connection_lost(sdata,
8253 WLAN_REASON_UNSPECIFIED,
8258 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
8259 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
8260 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
8261 ieee80211_sta_connection_lost(sdata,
8262 WLAN_REASON_UNSPECIFIED,
8268 static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy,
8269 struct wiphy_work *work)
8271 struct ieee80211_link_data *link =
8272 container_of(work, struct ieee80211_link_data,
8273 u.mgd.request_smps_work);
8275 __ieee80211_request_smps_mgd(link->sdata, link,
8276 link->u.mgd.driver_smps_mode);
8279 static void ieee80211_ml_sta_reconf_timeout(struct wiphy *wiphy,
8280 struct wiphy_work *work)
8282 struct ieee80211_sub_if_data *sdata =
8283 container_of(work, struct ieee80211_sub_if_data,
8284 u.mgd.reconf.wk.work);
8286 if (!sdata->u.mgd.reconf.added_links &&
8287 !sdata->u.mgd.reconf.removed_links)
8291 "mlo: reconf: timeout: added=0x%x, removed=0x%x\n",
8292 sdata->u.mgd.reconf.added_links,
8293 sdata->u.mgd.reconf.removed_links);
8295 __ieee80211_disconnect(sdata);
8298 /* interface setup */
8299 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
8301 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8303 wiphy_work_init(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
8304 wiphy_work_init(&ifmgd->beacon_connection_loss_work,
8305 ieee80211_beacon_connection_loss_work);
8306 wiphy_work_init(&ifmgd->csa_connection_drop_work,
8307 ieee80211_csa_connection_drop_work);
8308 wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work,
8309 ieee80211_tdls_peer_del_work);
8310 wiphy_delayed_work_init(&ifmgd->ml_reconf_work,
8311 ieee80211_ml_reconf_work);
8312 wiphy_delayed_work_init(&ifmgd->reconf.wk,
8313 ieee80211_ml_sta_reconf_timeout);
8314 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
8315 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
8316 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
8317 wiphy_delayed_work_init(&ifmgd->tx_tspec_wk,
8318 ieee80211_sta_handle_tspec_ac_params_wk);
8319 wiphy_delayed_work_init(&ifmgd->ttlm_work,
8320 ieee80211_tid_to_link_map_work);
8321 wiphy_delayed_work_init(&ifmgd->neg_ttlm_timeout_work,
8322 ieee80211_neg_ttlm_timeout_work);
8323 wiphy_work_init(&ifmgd->teardown_ttlm_work,
8324 ieee80211_teardown_ttlm_work);
8327 ifmgd->powersave = sdata->wdev.ps;
8328 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
8329 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
8330 /* Setup TDLS data */
8331 spin_lock_init(&ifmgd->teardown_lock);
8332 ifmgd->teardown_skb = NULL;
8333 ifmgd->orig_teardown_skb = NULL;
8334 ifmgd->mcast_seq_last = IEEE80211_SN_MODULO;
8337 static void ieee80211_recalc_smps_work(struct wiphy *wiphy,
8338 struct wiphy_work *work)
8340 struct ieee80211_link_data *link =
8341 container_of(work, struct ieee80211_link_data,
8344 ieee80211_recalc_smps(link->sdata, link);
8347 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
8349 struct ieee80211_sub_if_data *sdata = link->sdata;
8350 struct ieee80211_local *local = sdata->local;
8351 unsigned int link_id = link->link_id;
8353 link->u.mgd.p2p_noa_index = -1;
8354 link->conf->bssid = link->u.mgd.bssid;
8355 link->smps_mode = IEEE80211_SMPS_OFF;
8357 wiphy_work_init(&link->u.mgd.request_smps_work,
8358 ieee80211_request_smps_mgd_work);
8359 wiphy_work_init(&link->u.mgd.recalc_smps,
8360 ieee80211_recalc_smps_work);
8361 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
8362 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
8364 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
8366 wiphy_delayed_work_init(&link->u.mgd.csa.switch_work,
8367 ieee80211_csa_switch_work);
8369 ieee80211_clear_tpe(&link->conf->tpe);
8371 if (sdata->u.mgd.assoc_data)
8372 ether_addr_copy(link->conf->addr,
8373 sdata->u.mgd.assoc_data->link[link_id].addr);
8374 else if (sdata->u.mgd.reconf.add_links_data)
8375 ether_addr_copy(link->conf->addr,
8376 sdata->u.mgd.reconf.add_links_data->link[link_id].addr);
8377 else if (!is_valid_ether_addr(link->conf->addr))
8378 eth_random_addr(link->conf->addr);
8381 /* scan finished notification */
8382 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
8384 struct ieee80211_sub_if_data *sdata;
8386 /* Restart STA timers */
8388 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
8389 if (ieee80211_sdata_running(sdata))
8390 ieee80211_restart_sta_timer(sdata);
8395 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
8396 struct cfg80211_bss *cbss, s8 link_id,
8397 const u8 *ap_mld_addr, bool assoc,
8398 struct ieee80211_conn_settings *conn,
8400 unsigned long *userspace_selectors)
8402 struct ieee80211_local *local = sdata->local;
8403 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8404 struct ieee80211_bss *bss = (void *)cbss->priv;
8405 struct sta_info *new_sta = NULL;
8406 struct ieee80211_link_data *link;
8407 bool have_sta = false;
8413 if (WARN_ON(!ap_mld_addr))
8415 err = ieee80211_vif_set_links(sdata, BIT(link_id), 0);
8417 if (WARN_ON(ap_mld_addr))
8419 ap_mld_addr = cbss->bssid;
8420 err = ieee80211_vif_set_links(sdata, 0, 0);
8428 link = sdata_dereference(sdata->link[link_id], sdata);
8429 if (WARN_ON(!link)) {
8434 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
8439 /* If a reconfig is happening, bail out */
8440 if (local->in_reconfig) {
8447 have_sta = sta_info_get(sdata, ap_mld_addr);
8453 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
8454 link_id, cbss->bssid,
8457 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
8464 new_sta->sta.mlo = mlo;
8468 * Set up the information for the new channel before setting the
8469 * new channel. We can't - completely race-free - change the basic
8470 * rates bitmap and the channel (sband) that it refers to, but if
8471 * we set it up before we at least avoid calling into the driver's
8472 * bss_info_changed() method with invalid information (since we do
8473 * call that from changing the channel - only for IDLE and perhaps
8474 * some others, but ...).
8476 * So to avoid that, just set up all the new information before the
8477 * channel, but tell the driver to apply it only afterwards, since
8478 * it might need the new channel for that.
8481 const struct cfg80211_bss_ies *ies;
8482 struct link_sta_info *link_sta;
8485 link_sta = rcu_dereference(new_sta->link[link_id]);
8486 if (WARN_ON(!link_sta)) {
8488 sta_info_free(local, new_sta);
8493 err = ieee80211_mgd_setup_link_sta(link, new_sta,
8497 sta_info_free(local, new_sta);
8501 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
8503 /* set timing information */
8504 link->conf->beacon_int = cbss->beacon_interval;
8505 ies = rcu_dereference(cbss->beacon_ies);
8507 link->conf->sync_tsf = ies->tsf;
8508 link->conf->sync_device_ts =
8509 bss->device_ts_beacon;
8511 ieee80211_get_dtim(ies,
8512 &link->conf->sync_dtim_count,
8514 } else if (!ieee80211_hw_check(&sdata->local->hw,
8515 TIMING_BEACON_ONLY)) {
8516 ies = rcu_dereference(cbss->proberesp_ies);
8517 /* must be non-NULL since beacon IEs were NULL */
8518 link->conf->sync_tsf = ies->tsf;
8519 link->conf->sync_device_ts =
8520 bss->device_ts_presp;
8521 link->conf->sync_dtim_count = 0;
8523 link->conf->sync_tsf = 0;
8524 link->conf->sync_device_ts = 0;
8525 link->conf->sync_dtim_count = 0;
8530 if (new_sta || override) {
8532 * Only set this if we're also going to calculate the AP
8533 * settings etc., otherwise this was set before in a
8534 * previous call. Note override is set to %true in assoc
8535 * if the settings were changed.
8537 link->u.mgd.conn = *conn;
8538 err = ieee80211_prep_channel(sdata, link, link->link_id, cbss,
8539 mlo, &link->u.mgd.conn,
8540 userspace_selectors);
8543 sta_info_free(local, new_sta);
8546 /* pass out for use in assoc */
8547 *conn = link->u.mgd.conn;
8552 * tell driver about BSSID, basic rates and timing
8553 * this was set up above, before setting the channel
8555 ieee80211_link_info_change_notify(sdata, link,
8557 BSS_CHANGED_BASIC_RATES |
8558 BSS_CHANGED_BEACON_INT);
8561 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
8563 err = sta_info_insert(new_sta);
8567 "failed to insert STA entry for the AP (error %d)\n",
8569 goto out_release_chan;
8572 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
8574 /* Cancel scan to ensure that nothing interferes with connection */
8575 if (local->scanning)
8576 ieee80211_scan_cancel(local);
8581 ieee80211_link_release_channel(link);
8583 ieee80211_vif_set_links(sdata, 0, 0);
8587 static bool ieee80211_mgd_csa_present(struct ieee80211_sub_if_data *sdata,
8588 const struct cfg80211_bss_ies *ies,
8589 u8 cur_channel, bool ignore_ecsa)
8591 const struct element *csa_elem, *ecsa_elem;
8592 struct ieee80211_channel_sw_ie *csa = NULL;
8593 struct ieee80211_ext_chansw_ie *ecsa = NULL;
8598 csa_elem = cfg80211_find_elem(WLAN_EID_CHANNEL_SWITCH,
8599 ies->data, ies->len);
8600 if (csa_elem && csa_elem->datalen == sizeof(*csa))
8601 csa = (void *)csa_elem->data;
8603 ecsa_elem = cfg80211_find_elem(WLAN_EID_EXT_CHANSWITCH_ANN,
8604 ies->data, ies->len);
8605 if (ecsa_elem && ecsa_elem->datalen == sizeof(*ecsa))
8606 ecsa = (void *)ecsa_elem->data;
8608 if (csa && csa->count == 0)
8610 if (csa && !csa->mode && csa->new_ch_num == cur_channel)
8613 if (ecsa && ecsa->count == 0)
8615 if (ecsa && !ecsa->mode && ecsa->new_ch_num == cur_channel)
8618 if (ignore_ecsa && ecsa) {
8620 "Ignoring ECSA in probe response - was considered stuck!\n");
8627 static bool ieee80211_mgd_csa_in_process(struct ieee80211_sub_if_data *sdata,
8628 struct cfg80211_bss *bss)
8633 cur_channel = ieee80211_frequency_to_channel(bss->channel->center_freq);
8636 if (ieee80211_mgd_csa_present(sdata,
8637 rcu_dereference(bss->beacon_ies),
8638 cur_channel, false)) {
8643 if (ieee80211_mgd_csa_present(sdata,
8644 rcu_dereference(bss->proberesp_ies),
8645 cur_channel, bss->proberesp_ecsa_stuck)) {
8656 static void ieee80211_parse_cfg_selectors(unsigned long *userspace_selectors,
8657 const u8 *supported_selectors,
8658 u8 supported_selectors_len)
8660 if (supported_selectors) {
8661 for (int i = 0; i < supported_selectors_len; i++) {
8662 set_bit(supported_selectors[i],
8663 userspace_selectors);
8666 /* Assume SAE_H2E support for backward compatibility. */
8667 set_bit(BSS_MEMBERSHIP_SELECTOR_SAE_H2E,
8668 userspace_selectors);
8673 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
8674 struct cfg80211_auth_request *req)
8676 struct ieee80211_local *local = sdata->local;
8677 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8678 struct ieee80211_mgd_auth_data *auth_data;
8679 struct ieee80211_conn_settings conn;
8680 struct ieee80211_link_data *link;
8681 struct ieee80211_supported_band *sband;
8682 struct ieee80211_bss *bss;
8685 bool cont_auth, wmm_used;
8687 lockdep_assert_wiphy(sdata->local->hw.wiphy);
8689 /* prepare auth data structure */
8691 switch (req->auth_type) {
8692 case NL80211_AUTHTYPE_OPEN_SYSTEM:
8693 auth_alg = WLAN_AUTH_OPEN;
8695 case NL80211_AUTHTYPE_SHARED_KEY:
8698 auth_alg = WLAN_AUTH_SHARED_KEY;
8700 case NL80211_AUTHTYPE_FT:
8701 auth_alg = WLAN_AUTH_FT;
8703 case NL80211_AUTHTYPE_NETWORK_EAP:
8704 auth_alg = WLAN_AUTH_LEAP;
8706 case NL80211_AUTHTYPE_SAE:
8707 auth_alg = WLAN_AUTH_SAE;
8709 case NL80211_AUTHTYPE_FILS_SK:
8710 auth_alg = WLAN_AUTH_FILS_SK;
8712 case NL80211_AUTHTYPE_FILS_SK_PFS:
8713 auth_alg = WLAN_AUTH_FILS_SK_PFS;
8715 case NL80211_AUTHTYPE_FILS_PK:
8716 auth_alg = WLAN_AUTH_FILS_PK;
8722 if (ifmgd->assoc_data)
8725 if (ieee80211_mgd_csa_in_process(sdata, req->bss)) {
8726 sdata_info(sdata, "AP is in CSA process, reject auth\n");
8730 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
8731 req->ie_len, GFP_KERNEL);
8735 memcpy(auth_data->ap_addr,
8736 req->ap_mld_addr ?: req->bss->bssid,
8738 auth_data->bss = req->bss;
8739 auth_data->link_id = req->link_id;
8741 if (req->auth_data_len >= 4) {
8742 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
8743 __le16 *pos = (__le16 *) req->auth_data;
8745 auth_data->sae_trans = le16_to_cpu(pos[0]);
8746 auth_data->sae_status = le16_to_cpu(pos[1]);
8748 memcpy(auth_data->data, req->auth_data + 4,
8749 req->auth_data_len - 4);
8750 auth_data->data_len += req->auth_data_len - 4;
8753 /* Check if continuing authentication or trying to authenticate with the
8754 * same BSS that we were in the process of authenticating with and avoid
8755 * removal and re-addition of the STA entry in
8756 * ieee80211_prep_connection().
8758 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
8759 ifmgd->auth_data->link_id == req->link_id;
8761 if (req->ie && req->ie_len) {
8762 memcpy(&auth_data->data[auth_data->data_len],
8763 req->ie, req->ie_len);
8764 auth_data->data_len += req->ie_len;
8767 if (req->key && req->key_len) {
8768 auth_data->key_len = req->key_len;
8769 auth_data->key_idx = req->key_idx;
8770 memcpy(auth_data->key, req->key, req->key_len);
8773 ieee80211_parse_cfg_selectors(auth_data->userspace_selectors,
8774 req->supported_selectors,
8775 req->supported_selectors_len);
8777 auth_data->algorithm = auth_alg;
8779 /* try to authenticate/probe */
8781 if (ifmgd->auth_data) {
8782 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
8783 auth_data->peer_confirmed =
8784 ifmgd->auth_data->peer_confirmed;
8786 ieee80211_destroy_auth_data(sdata, cont_auth);
8789 /* prep auth_data so we don't go into idle on disassoc */
8790 ifmgd->auth_data = auth_data;
8792 /* If this is continuation of an ongoing SAE authentication exchange
8793 * (i.e., request to send SAE Confirm) and the peer has already
8794 * confirmed, mark authentication completed since we are about to send
8797 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
8798 auth_data->peer_confirmed && auth_data->sae_trans == 2)
8799 ieee80211_mark_sta_auth(sdata);
8801 if (ifmgd->associated) {
8802 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
8805 "disconnect from AP %pM for new auth to %pM\n",
8806 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
8807 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
8808 WLAN_REASON_UNSPECIFIED,
8811 ieee80211_report_disconnect(sdata, frame_buf,
8812 sizeof(frame_buf), true,
8813 WLAN_REASON_UNSPECIFIED,
8817 /* needed for transmitting the auth frame(s) properly */
8818 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
8820 bss = (void *)req->bss->priv;
8821 wmm_used = bss->wmm_used && (local->hw.queues >= IEEE80211_NUM_ACS);
8823 sband = local->hw.wiphy->bands[req->bss->channel->band];
8825 ieee80211_determine_our_sta_mode_auth(sdata, sband, req, wmm_used,
8828 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
8829 req->ap_mld_addr, cont_auth,
8831 auth_data->userspace_selectors);
8835 if (req->link_id >= 0)
8836 link = sdata_dereference(sdata->link[req->link_id], sdata);
8838 link = &sdata->deflink;
8840 if (WARN_ON(!link)) {
8845 sdata_info(sdata, "authenticate with %pM (local address=%pM)\n",
8846 auth_data->ap_addr, link->conf->addr);
8848 err = ieee80211_auth(sdata);
8850 sta_info_destroy_addr(sdata, auth_data->ap_addr);
8854 /* hold our own reference */
8855 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
8859 if (!ieee80211_vif_is_mld(&sdata->vif)) {
8860 eth_zero_addr(sdata->deflink.u.mgd.bssid);
8861 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
8863 ieee80211_link_release_channel(&sdata->deflink);
8865 ifmgd->auth_data = NULL;
8871 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
8872 struct ieee80211_mgd_assoc_data *assoc_data,
8873 struct cfg80211_assoc_request *req,
8874 struct ieee80211_conn_settings *conn,
8875 unsigned int link_id)
8877 struct ieee80211_local *local = sdata->local;
8878 const struct cfg80211_bss_ies *bss_ies;
8879 struct ieee80211_supported_band *sband;
8880 struct ieee80211_link_data *link;
8881 struct cfg80211_bss *cbss;
8882 struct ieee80211_bss *bss;
8884 cbss = assoc_data->link[link_id].bss;
8888 bss = (void *)cbss->priv;
8890 sband = local->hw.wiphy->bands[cbss->channel->band];
8891 if (WARN_ON(!sband))
8894 link = sdata_dereference(sdata->link[link_id], sdata);
8898 /* for MLO connections assume advertising all rates is OK */
8899 if (!req->ap_mld_addr) {
8900 assoc_data->supp_rates = bss->supp_rates;
8901 assoc_data->supp_rates_len = bss->supp_rates_len;
8904 /* copy and link elems for the STA profile */
8905 if (req->links[link_id].elems_len) {
8906 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
8907 req->links[link_id].elems_len);
8908 assoc_data->link[link_id].elems = assoc_data->ie_pos;
8909 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
8910 assoc_data->ie_pos += req->links[link_id].elems_len;
8913 link->u.mgd.beacon_crc_valid = false;
8914 link->u.mgd.dtim_period = 0;
8915 link->u.mgd.have_beacon = false;
8917 /* override HT configuration only if the AP and we support it */
8918 if (conn->mode >= IEEE80211_CONN_MODE_HT) {
8919 struct ieee80211_sta_ht_cap sta_ht_cap;
8921 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
8922 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
8926 bss_ies = rcu_dereference(cbss->beacon_ies);
8930 ieee80211_get_dtim(bss_ies, &dtim_count,
8931 &link->u.mgd.dtim_period);
8933 sdata->deflink.u.mgd.have_beacon = true;
8935 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
8936 link->conf->sync_tsf = bss_ies->tsf;
8937 link->conf->sync_device_ts = bss->device_ts_beacon;
8938 link->conf->sync_dtim_count = dtim_count;
8941 bss_ies = rcu_dereference(cbss->ies);
8945 const struct element *elem;
8947 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
8948 bss_ies->data, bss_ies->len);
8949 if (elem && elem->datalen >= 3)
8950 link->conf->profile_periodicity = elem->data[2];
8952 link->conf->profile_periodicity = 0;
8954 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
8955 bss_ies->data, bss_ies->len);
8956 if (elem && elem->datalen >= 11 &&
8957 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
8958 link->conf->ema_ap = true;
8960 link->conf->ema_ap = false;
8964 if (bss->corrupt_data) {
8965 char *corrupt_type = "data";
8967 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
8968 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
8969 corrupt_type = "beacon and probe response";
8971 corrupt_type = "beacon";
8972 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
8973 corrupt_type = "probe response";
8975 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
8976 cbss->bssid, corrupt_type);
8979 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
8980 if (sdata->u.mgd.powersave)
8981 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
8983 link->smps_mode = IEEE80211_SMPS_OFF;
8985 link->smps_mode = link->u.mgd.req_smps;
8990 ieee80211_mgd_get_ap_ht_vht_capa(struct ieee80211_sub_if_data *sdata,
8991 struct ieee80211_mgd_assoc_data *assoc_data,
8994 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
8995 enum nl80211_band band = cbss->channel->band;
8996 struct ieee80211_supported_band *sband;
8997 const struct element *elem;
9000 /* neither HT nor VHT elements used on 6 GHz */
9001 if (band == NL80211_BAND_6GHZ)
9004 if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_HT)
9008 elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
9009 if (!elem || elem->datalen < sizeof(struct ieee80211_ht_operation)) {
9010 mlme_link_id_dbg(sdata, link_id, "no HT operation on BSS %pM\n",
9015 assoc_data->link[link_id].ap_ht_param =
9016 ((struct ieee80211_ht_operation *)(elem->data))->ht_param;
9019 if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_VHT)
9022 /* some drivers want to support VHT on 2.4 GHz even */
9023 sband = sdata->local->hw.wiphy->bands[band];
9024 if (!sband->vht_cap.vht_supported)
9028 elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
9029 /* but even then accept it not being present on the AP */
9030 if (!elem && band == NL80211_BAND_2GHZ) {
9034 if (!elem || elem->datalen < sizeof(struct ieee80211_vht_cap)) {
9035 mlme_link_id_dbg(sdata, link_id, "no VHT capa on BSS %pM\n",
9040 memcpy(&assoc_data->link[link_id].ap_vht_cap, elem->data,
9041 sizeof(struct ieee80211_vht_cap));
9050 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
9051 struct cfg80211_assoc_request *req)
9053 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
9054 struct ieee80211_local *local = sdata->local;
9055 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9056 struct ieee80211_mgd_assoc_data *assoc_data;
9057 const struct element *ssid_elem;
9058 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
9059 struct ieee80211_link_data *link;
9060 struct cfg80211_bss *cbss;
9061 bool override, uapsd_supported;
9064 size_t size = sizeof(*assoc_data) + req->ie_len;
9066 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
9067 size += req->links[i].elems_len;
9069 /* FIXME: no support for 4-addr MLO yet */
9070 if (sdata->u.mgd.use_4addr && req->link_id >= 0)
9073 assoc_data = kzalloc(size, GFP_KERNEL);
9077 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
9079 if (ieee80211_mgd_csa_in_process(sdata, cbss)) {
9080 sdata_info(sdata, "AP is in CSA process, reject assoc\n");
9086 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
9087 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
9093 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
9094 assoc_data->ssid_len = ssid_elem->datalen;
9097 if (req->ap_mld_addr)
9098 memcpy(assoc_data->ap_addr, req->ap_mld_addr, ETH_ALEN);
9100 memcpy(assoc_data->ap_addr, cbss->bssid, ETH_ALEN);
9102 if (ifmgd->associated) {
9103 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
9106 "disconnect from AP %pM for new assoc to %pM\n",
9107 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
9108 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
9109 WLAN_REASON_UNSPECIFIED,
9112 ieee80211_report_disconnect(sdata, frame_buf,
9113 sizeof(frame_buf), true,
9114 WLAN_REASON_UNSPECIFIED,
9118 ieee80211_parse_cfg_selectors(assoc_data->userspace_selectors,
9119 req->supported_selectors,
9120 req->supported_selectors_len);
9122 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
9123 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
9124 sizeof(ifmgd->ht_capa_mask));
9126 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
9127 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
9128 sizeof(ifmgd->vht_capa_mask));
9130 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
9131 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
9132 sizeof(ifmgd->s1g_capa_mask));
9134 /* keep some setup (AP STA, channel, ...) if matching */
9135 match_auth = ifmgd->auth_data &&
9136 ether_addr_equal(ifmgd->auth_data->ap_addr,
9137 assoc_data->ap_addr) &&
9138 ifmgd->auth_data->link_id == req->link_id;
9140 if (req->ap_mld_addr) {
9141 uapsd_supported = true;
9143 if (req->flags & (ASSOC_REQ_DISABLE_HT |
9144 ASSOC_REQ_DISABLE_VHT |
9145 ASSOC_REQ_DISABLE_HE |
9146 ASSOC_REQ_DISABLE_EHT)) {
9151 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
9152 struct ieee80211_supported_band *sband;
9153 struct cfg80211_bss *link_cbss = req->links[i].bss;
9154 struct ieee80211_bss *bss;
9159 bss = (void *)link_cbss->priv;
9161 if (!bss->wmm_used) {
9163 req->links[i].error = err;
9167 if (link_cbss->channel->band == NL80211_BAND_S1GHZ) {
9169 req->links[i].error = err;
9173 link = sdata_dereference(sdata->link[i], sdata);
9175 ether_addr_copy(assoc_data->link[i].addr,
9178 eth_random_addr(assoc_data->link[i].addr);
9179 sband = local->hw.wiphy->bands[link_cbss->channel->band];
9181 if (match_auth && i == assoc_link_id && link)
9182 assoc_data->link[i].conn = link->u.mgd.conn;
9184 assoc_data->link[i].conn =
9185 ieee80211_conn_settings_unlimited;
9186 ieee80211_determine_our_sta_mode_assoc(sdata, sband,
9188 &assoc_data->link[i].conn);
9189 assoc_data->link[i].bss = link_cbss;
9190 assoc_data->link[i].disabled = req->links[i].disabled;
9192 if (!bss->uapsd_supported)
9193 uapsd_supported = false;
9195 if (assoc_data->link[i].conn.mode < IEEE80211_CONN_MODE_EHT) {
9197 req->links[i].error = err;
9201 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata,
9205 req->links[i].error = err;
9210 assoc_data->wmm = true;
9212 struct ieee80211_supported_band *sband;
9213 struct ieee80211_bss *bss = (void *)cbss->priv;
9215 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
9216 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
9218 assoc_data->wmm = bss->wmm_used &&
9219 (local->hw.queues >= IEEE80211_NUM_ACS);
9221 if (cbss->channel->band == NL80211_BAND_6GHZ &&
9222 req->flags & (ASSOC_REQ_DISABLE_HT |
9223 ASSOC_REQ_DISABLE_VHT |
9224 ASSOC_REQ_DISABLE_HE)) {
9229 sband = local->hw.wiphy->bands[cbss->channel->band];
9231 assoc_data->link[0].bss = cbss;
9234 assoc_data->link[0].conn = sdata->deflink.u.mgd.conn;
9236 assoc_data->link[0].conn =
9237 ieee80211_conn_settings_unlimited;
9238 ieee80211_determine_our_sta_mode_assoc(sdata, sband, req,
9240 &assoc_data->link[0].conn);
9242 uapsd_supported = bss->uapsd_supported;
9244 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, assoc_data, 0);
9249 assoc_data->spp_amsdu = req->flags & ASSOC_REQ_SPP_AMSDU;
9251 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
9256 if (ifmgd->assoc_data) {
9261 /* Cleanup is delayed if auth_data matches */
9262 if (ifmgd->auth_data && !match_auth)
9263 ieee80211_destroy_auth_data(sdata, false);
9265 if (req->ie && req->ie_len) {
9266 memcpy(assoc_data->ie, req->ie, req->ie_len);
9267 assoc_data->ie_len = req->ie_len;
9268 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
9270 assoc_data->ie_pos = assoc_data->ie;
9273 if (req->fils_kek) {
9274 /* should already be checked in cfg80211 - so warn */
9275 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
9279 memcpy(assoc_data->fils_kek, req->fils_kek,
9281 assoc_data->fils_kek_len = req->fils_kek_len;
9284 if (req->fils_nonces)
9285 memcpy(assoc_data->fils_nonces, req->fils_nonces,
9286 2 * FILS_NONCE_LEN);
9288 /* default timeout */
9289 assoc_data->timeout = jiffies;
9290 assoc_data->timeout_started = true;
9292 assoc_data->assoc_link_id = assoc_link_id;
9294 if (req->ap_mld_addr) {
9295 /* if there was no authentication, set up the link */
9296 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id), 0);
9301 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
9302 if (WARN_ON(!link)) {
9307 override = link->u.mgd.conn.mode !=
9308 assoc_data->link[assoc_link_id].conn.mode ||
9309 link->u.mgd.conn.bw_limit !=
9310 assoc_data->link[assoc_link_id].conn.bw_limit;
9311 link->u.mgd.conn = assoc_data->link[assoc_link_id].conn;
9313 ieee80211_setup_assoc_link(sdata, assoc_data, req, &link->u.mgd.conn,
9316 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
9317 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
9318 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
9319 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
9321 if (assoc_data->wmm && uapsd_supported &&
9322 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
9323 assoc_data->uapsd = true;
9324 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
9326 assoc_data->uapsd = false;
9327 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
9330 if (req->prev_bssid)
9331 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
9334 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
9335 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
9337 ifmgd->mfp = IEEE80211_MFP_DISABLED;
9338 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
9341 if (req->flags & ASSOC_REQ_USE_RRM)
9342 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
9344 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
9346 if (req->crypto.control_port)
9347 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
9349 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
9351 sdata->control_port_protocol = req->crypto.control_port_ethertype;
9352 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
9353 sdata->control_port_over_nl80211 =
9354 req->crypto.control_port_over_nl80211;
9355 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
9357 /* kick off associate process */
9358 ifmgd->assoc_data = assoc_data;
9360 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
9361 if (!assoc_data->link[i].bss)
9363 if (i == assoc_data->assoc_link_id)
9365 /* only calculate the mode, hence link == NULL */
9366 err = ieee80211_prep_channel(sdata, NULL, i,
9367 assoc_data->link[i].bss, true,
9368 &assoc_data->link[i].conn,
9369 assoc_data->userspace_selectors);
9371 req->links[i].error = err;
9376 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
9377 vif_cfg->ssid_len = assoc_data->ssid_len;
9379 /* needed for transmitting the assoc frames properly */
9380 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
9382 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
9383 req->ap_mld_addr, true,
9384 &assoc_data->link[assoc_link_id].conn,
9386 assoc_data->userspace_selectors);
9390 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
9391 const struct cfg80211_bss_ies *beacon_ies;
9394 beacon_ies = rcu_dereference(req->bss->beacon_ies);
9397 * Wait up to one beacon interval ...
9398 * should this be more if we miss one?
9400 sdata_info(sdata, "waiting for beacon from %pM\n",
9402 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
9403 assoc_data->timeout_started = true;
9404 assoc_data->need_beacon = true;
9409 run_again(sdata, assoc_data->timeout);
9411 /* We are associating, clean up auth_data */
9412 if (ifmgd->auth_data)
9413 ieee80211_destroy_auth_data(sdata, true);
9417 if (!ifmgd->auth_data) {
9418 eth_zero_addr(sdata->deflink.u.mgd.bssid);
9419 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
9422 ifmgd->assoc_data = NULL;
9428 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
9429 struct cfg80211_deauth_request *req)
9431 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9432 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
9433 bool tx = !req->local_state_change;
9434 struct ieee80211_prep_tx_info info = {
9435 .subtype = IEEE80211_STYPE_DEAUTH,
9438 if (ifmgd->auth_data &&
9439 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
9441 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
9442 req->bssid, req->reason_code,
9443 ieee80211_get_reason_code_string(req->reason_code));
9445 info.link_id = ifmgd->auth_data->link_id;
9446 drv_mgd_prepare_tx(sdata->local, sdata, &info);
9447 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
9448 IEEE80211_STYPE_DEAUTH,
9449 req->reason_code, tx,
9451 ieee80211_destroy_auth_data(sdata, false);
9452 ieee80211_report_disconnect(sdata, frame_buf,
9453 sizeof(frame_buf), true,
9454 req->reason_code, false);
9455 drv_mgd_complete_tx(sdata->local, sdata, &info);
9459 if (ifmgd->assoc_data &&
9460 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
9462 "aborting association with %pM by local choice (Reason: %u=%s)\n",
9463 req->bssid, req->reason_code,
9464 ieee80211_get_reason_code_string(req->reason_code));
9466 info.link_id = ifmgd->assoc_data->assoc_link_id;
9467 drv_mgd_prepare_tx(sdata->local, sdata, &info);
9468 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
9469 IEEE80211_STYPE_DEAUTH,
9470 req->reason_code, tx,
9472 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
9473 ieee80211_report_disconnect(sdata, frame_buf,
9474 sizeof(frame_buf), true,
9475 req->reason_code, false);
9476 drv_mgd_complete_tx(sdata->local, sdata, &info);
9480 if (ifmgd->associated &&
9481 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
9483 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
9484 req->bssid, req->reason_code,
9485 ieee80211_get_reason_code_string(req->reason_code));
9487 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
9488 req->reason_code, tx, frame_buf);
9489 ieee80211_report_disconnect(sdata, frame_buf,
9490 sizeof(frame_buf), true,
9491 req->reason_code, false);
9492 drv_mgd_complete_tx(sdata->local, sdata, &info);
9499 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
9500 struct cfg80211_disassoc_request *req)
9502 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
9504 if (!sdata->u.mgd.associated ||
9505 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
9509 "disassociating from %pM by local choice (Reason: %u=%s)\n",
9510 req->ap_addr, req->reason_code,
9511 ieee80211_get_reason_code_string(req->reason_code));
9513 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
9514 req->reason_code, !req->local_state_change,
9517 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
9518 req->reason_code, false);
9523 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
9525 wiphy_work_cancel(link->sdata->local->hw.wiphy,
9526 &link->u.mgd.request_smps_work);
9527 wiphy_work_cancel(link->sdata->local->hw.wiphy,
9528 &link->u.mgd.recalc_smps);
9529 wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy,
9530 &link->u.mgd.csa.switch_work);
9533 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
9535 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9538 * Make sure some work items will not run after this,
9539 * they will not do anything but might not have been
9540 * cancelled when disconnecting.
9542 wiphy_work_cancel(sdata->local->hw.wiphy,
9543 &ifmgd->monitor_work);
9544 wiphy_work_cancel(sdata->local->hw.wiphy,
9545 &ifmgd->beacon_connection_loss_work);
9546 wiphy_work_cancel(sdata->local->hw.wiphy,
9547 &ifmgd->csa_connection_drop_work);
9548 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
9549 &ifmgd->tdls_peer_del_work);
9551 if (ifmgd->assoc_data)
9552 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
9553 if (ifmgd->auth_data)
9554 ieee80211_destroy_auth_data(sdata, false);
9555 spin_lock_bh(&ifmgd->teardown_lock);
9556 if (ifmgd->teardown_skb) {
9557 kfree_skb(ifmgd->teardown_skb);
9558 ifmgd->teardown_skb = NULL;
9559 ifmgd->orig_teardown_skb = NULL;
9561 kfree(ifmgd->assoc_req_ies);
9562 ifmgd->assoc_req_ies = NULL;
9563 ifmgd->assoc_req_ies_len = 0;
9564 spin_unlock_bh(&ifmgd->teardown_lock);
9565 del_timer_sync(&ifmgd->timer);
9568 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
9569 enum nl80211_cqm_rssi_threshold_event rssi_event,
9573 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
9575 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
9577 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
9579 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
9581 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
9583 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
9585 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
9587 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
9589 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
9591 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
9595 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
9597 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
9601 * Scale up threshold values before storing it, as the RSSI averaging
9602 * algorithm uses a scaled up value as well. Change this scaling
9603 * factor if the RSSI averaging algorithm changes.
9605 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
9606 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
9609 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
9613 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
9615 WARN_ON(rssi_min_thold == rssi_max_thold ||
9616 rssi_min_thold > rssi_max_thold);
9618 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
9621 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
9623 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
9625 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
9627 _ieee80211_enable_rssi_reports(sdata, 0, 0);
9629 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);
9631 static void ieee80211_ml_reconf_selectors(unsigned long *userspace_selectors)
9633 *userspace_selectors = 0;
9635 /* these selectors are mandatory for ML reconfiguration */
9636 set_bit(BSS_MEMBERSHIP_SELECTOR_SAE_H2E, userspace_selectors);
9637 set_bit(BSS_MEMBERSHIP_SELECTOR_HE_PHY, userspace_selectors);
9638 set_bit(BSS_MEMBERSHIP_SELECTOR_EHT_PHY, userspace_selectors);
9641 void ieee80211_process_ml_reconf_resp(struct ieee80211_sub_if_data *sdata,
9642 struct ieee80211_mgmt *mgmt, size_t len)
9644 struct ieee80211_local *local = sdata->local;
9645 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9646 struct ieee80211_mgd_assoc_data *add_links_data =
9647 ifmgd->reconf.add_links_data;
9648 struct sta_info *sta;
9649 struct cfg80211_mlo_reconf_done_data done_data = {};
9650 u16 sta_changed_links = sdata->u.mgd.reconf.added_links |
9651 sdata->u.mgd.reconf.removed_links;
9652 u16 link_mask, valid_links;
9653 unsigned int link_id;
9654 unsigned long userspace_selectors;
9655 size_t orig_len = len;
9656 u8 i, group_key_data_len;
9659 if (!ieee80211_vif_is_mld(&sdata->vif) ||
9660 len < offsetofend(typeof(*mgmt), u.action.u.ml_reconf_resp) ||
9661 mgmt->u.action.u.ml_reconf_resp.dialog_token !=
9662 sdata->u.mgd.reconf.dialog_token ||
9666 pos = mgmt->u.action.u.ml_reconf_resp.variable;
9667 len -= offsetofend(typeof(*mgmt), u.action.u.ml_reconf_resp);
9669 /* each status duple is 3 octets */
9670 if (len < mgmt->u.action.u.ml_reconf_resp.count * 3) {
9672 "mlo: reconf: unexpected len=%zu, count=%u\n",
9673 len, mgmt->u.action.u.ml_reconf_resp.count);
9677 link_mask = sta_changed_links;
9678 for (i = 0; i < mgmt->u.action.u.ml_reconf_resp.count; i++) {
9679 u16 status = get_unaligned_le16(pos + 1);
9683 if (!(link_mask & BIT(link_id))) {
9685 "mlo: reconf: unexpected link: %u, changed=0x%x\n",
9686 link_id, sta_changed_links);
9690 /* clear the corresponding link, to detect the case that
9691 * the same link was included more than one time
9693 link_mask &= ~BIT(link_id);
9695 /* Handle failure to remove links here. Failure to remove added
9696 * links will be done later in the flow.
9698 if (status != WLAN_STATUS_SUCCESS) {
9700 "mlo: reconf: failed on link=%u, status=%u\n",
9703 /* The AP MLD failed to remove a link that was already
9704 * removed locally. As this is not expected behavior,
9707 if (sdata->u.mgd.reconf.removed_links & BIT(link_id))
9710 /* The AP MLD failed to add a link. Remove it from the
9713 sdata->u.mgd.reconf.added_links &= ~BIT(link_id);
9722 "mlo: reconf: no response for links=0x%x\n",
9727 if (!sdata->u.mgd.reconf.added_links)
9730 if (len < 1 || len < 1 + *pos) {
9732 "mlo: reconf: invalid group key data length");
9736 /* The Group Key Data field must be present when links are added. This
9737 * field should be processed by userland.
9739 group_key_data_len = *pos++;
9741 pos += group_key_data_len;
9742 len -= group_key_data_len + 1;
9744 /* Process the information for the added links */
9745 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
9749 valid_links = sdata->vif.valid_links;
9750 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
9751 if (!add_links_data->link[link_id].bss ||
9752 !(sdata->u.mgd.reconf.added_links & BIT(link_id)))
9756 valid_links |= BIT(link_id);
9757 if (ieee80211_sta_allocate_link(sta, link_id))
9761 ieee80211_vif_set_links(sdata, valid_links, sdata->vif.dormant_links);
9762 ieee80211_ml_reconf_selectors(&userspace_selectors);
9764 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
9765 struct cfg80211_bss *cbss = add_links_data->link[link_id].bss;
9766 struct ieee80211_link_data *link;
9767 struct link_sta_info *link_sta;
9773 link = sdata_dereference(sdata->link[link_id], sdata);
9778 "mlo: reconf: local address %pM, AP link address %pM\n",
9779 add_links_data->link[link_id].addr,
9780 add_links_data->link[link_id].bss->bssid);
9782 link_sta = rcu_dereference_protected(sta->link[link_id],
9783 lockdep_is_held(&local->hw.wiphy->mtx));
9784 if (WARN_ON(!link_sta))
9787 if (!link->u.mgd.have_beacon) {
9788 const struct cfg80211_bss_ies *ies;
9791 ies = rcu_dereference(cbss->beacon_ies);
9793 link->u.mgd.have_beacon = true;
9795 ies = rcu_dereference(cbss->ies);
9796 ieee80211_get_dtim(ies,
9797 &link->conf->sync_dtim_count,
9798 &link->u.mgd.dtim_period);
9799 link->conf->beacon_int = cbss->beacon_interval;
9803 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
9805 link->u.mgd.conn = add_links_data->link[link_id].conn;
9806 if (ieee80211_prep_channel(sdata, link, link_id, cbss,
9807 true, &link->u.mgd.conn,
9808 &userspace_selectors)) {
9809 link_info(link, "mlo: reconf: prep_channel failed\n");
9813 if (ieee80211_mgd_setup_link_sta(link, sta, link_sta,
9814 add_links_data->link[link_id].bss))
9817 if (!ieee80211_assoc_config_link(link, link_sta,
9818 add_links_data->link[link_id].bss,
9823 /* The AP MLD indicated success for this link, but the station
9824 * profile status indicated otherwise. Since there is an
9825 * inconsistency in the ML reconfiguration response, disconnect
9827 if (add_links_data->link[link_id].status != WLAN_STATUS_SUCCESS)
9830 ieee80211_sta_init_nss(link_sta);
9831 if (ieee80211_sta_activate_link(sta, link_id))
9834 changed |= ieee80211_link_set_associated(link, cbss);
9835 ieee80211_link_info_change_notify(sdata, link, changed);
9837 ieee80211_recalc_smps(sdata, link);
9838 link_mask |= BIT(link_id);
9842 "mlo: reconf: current valid_links=0x%x, added=0x%x\n",
9843 valid_links, link_mask);
9845 /* links might have changed due to rejected ones, set them again */
9846 ieee80211_vif_set_links(sdata, valid_links, sdata->vif.dormant_links);
9847 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS);
9849 ieee80211_recalc_ps(local);
9850 ieee80211_recalc_ps_vif(sdata);
9852 done_data.buf = (const u8 *)mgmt;
9853 done_data.len = orig_len;
9854 done_data.added_links = link_mask;
9856 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++)
9857 done_data.links[link_id].bss = add_links_data->link[link_id].bss;
9859 cfg80211_mlo_reconf_add_done(sdata->dev, &done_data);
9860 kfree(sdata->u.mgd.reconf.add_links_data);
9861 sdata->u.mgd.reconf.add_links_data = NULL;
9863 ieee80211_ml_reconf_reset(sdata);
9867 __ieee80211_disconnect(sdata);
9870 static struct sk_buff *
9871 ieee80211_build_ml_reconf_req(struct ieee80211_sub_if_data *sdata,
9872 struct ieee80211_mgd_assoc_data *add_links_data,
9875 struct ieee80211_local *local = sdata->local;
9876 struct ieee80211_mgmt *mgmt;
9877 struct ieee80211_multi_link_elem *ml_elem;
9878 struct ieee80211_mle_basic_common_info *common;
9879 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
9880 struct sk_buff *skb;
9882 unsigned int link_id;
9883 __le16 eml_capa = 0, mld_capa_ops = 0;
9884 struct ieee80211_tx_info *info;
9885 u8 common_size, var_common_size;
9889 size = local->hw.extra_tx_headroom + sizeof(*mgmt);
9891 /* Consider the maximal length of the reconfiguration ML element */
9892 size += sizeof(struct ieee80211_multi_link_elem);
9894 /* The Basic ML element and the Reconfiguration ML element have the same
9895 * fixed common information fields in the context of ML reconfiguration
9896 * action frame. The AP MLD MAC address must always be present
9898 common_size = sizeof(*common);
9900 /* when adding links, the MLD capabilities must be present */
9901 var_common_size = 0;
9902 if (add_links_data) {
9903 const struct wiphy_iftype_ext_capab *ift_ext_capa =
9904 cfg80211_get_iftype_ext_capa(local->hw.wiphy,
9905 ieee80211_vif_type_p2p(&sdata->vif));
9908 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
9910 cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
9913 /* MLD capabilities and operation */
9914 var_common_size += 2;
9916 /* EML capabilities */
9917 if (eml_capa & cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
9918 IEEE80211_EML_CAP_EMLMR_SUPPORT)))
9919 var_common_size += 2;
9922 /* Add the common information length */
9923 size += common_size + var_common_size;
9925 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
9926 struct cfg80211_bss *cbss;
9929 if (removed_links & BIT(link_id)) {
9930 size += sizeof(struct ieee80211_mle_per_sta_profile) +
9935 if (!add_links_data || !add_links_data->link[link_id].bss)
9938 elems_len = add_links_data->link[link_id].elems_len;
9939 cbss = add_links_data->link[link_id].bss;
9941 /* should be the same across all BSSes */
9942 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
9943 capab |= WLAN_CAPABILITY_PRIVACY;
9945 size += 2 + sizeof(struct ieee80211_mle_per_sta_profile) +
9948 /* SSID element + WMM */
9949 size += 2 + sdata->vif.cfg.ssid_len + 9;
9950 size += ieee80211_link_common_elems_size(sdata, iftype, cbss,
9954 skb = alloc_skb(size, GFP_KERNEL);
9958 skb_reserve(skb, local->hw.extra_tx_headroom);
9959 mgmt = skb_put_zero(skb, offsetofend(struct ieee80211_mgmt,
9960 u.action.u.ml_reconf_req));
9962 /* Add the MAC header */
9963 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
9964 IEEE80211_STYPE_ACTION);
9965 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
9966 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
9967 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
9969 /* Add the action frame fixed fields */
9970 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
9971 mgmt->u.action.u.ml_reconf_req.action_code =
9972 WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_REQ;
9974 /* allocate a dialog token and store it */
9975 sdata->u.mgd.reconf.dialog_token = ++sdata->u.mgd.dialog_token_alloc;
9976 mgmt->u.action.u.ml_reconf_req.dialog_token =
9977 sdata->u.mgd.reconf.dialog_token;
9979 /* Add the ML reconfiguration element and the common information */
9980 skb_put_u8(skb, WLAN_EID_EXTENSION);
9981 ml_elem_len = skb_put(skb, 1);
9982 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
9983 ml_elem = skb_put(skb, sizeof(*ml_elem));
9985 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_RECONF |
9986 IEEE80211_MLC_RECONF_PRES_MLD_MAC_ADDR);
9987 common = skb_put(skb, common_size);
9988 common->len = common_size + var_common_size;
9989 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
9991 if (add_links_data) {
9993 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
9994 IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
9996 cpu_to_le16(IEEE80211_MLC_RECONF_PRES_EML_CAPA);
9997 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
10000 ml_elem->control |=
10001 cpu_to_le16(IEEE80211_MLC_RECONF_PRES_MLD_CAPA_OP);
10003 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
10006 if (sdata->u.mgd.flags & IEEE80211_STA_ENABLE_RRM)
10007 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
10009 /* Add the per station profile */
10010 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
10011 u8 *subelem_len = NULL;
10015 /* Skip links that are not changing */
10016 if (!(removed_links & BIT(link_id)) &&
10017 (!add_links_data || !add_links_data->link[link_id].bss))
10021 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT;
10023 if (removed_links & BIT(link_id)) {
10024 struct ieee80211_bss_conf *conf =
10025 sdata_dereference(sdata->vif.link_conf[link_id],
10031 ctrl |= u16_encode_bits(IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_DEL_LINK,
10032 IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE);
10034 addr = add_links_data->link[link_id].addr;
10035 ctrl |= IEEE80211_MLE_STA_RECONF_CONTROL_COMPLETE_PROFILE |
10036 u16_encode_bits(IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_ADD_LINK,
10037 IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE);
10040 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
10041 subelem_len = skb_put(skb, 1);
10043 put_unaligned_le16(ctrl, skb_put(skb, sizeof(ctrl)));
10044 skb_put_u8(skb, 1 + ETH_ALEN);
10045 skb_put_data(skb, addr, ETH_ALEN);
10047 if (!(removed_links & BIT(link_id))) {
10048 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
10053 capab_pos = skb_put(skb, 2);
10055 skb_put_u8(skb, WLAN_EID_SSID);
10056 skb_put_u8(skb, sdata->vif.cfg.ssid_len);
10057 skb_put_data(skb, sdata->vif.cfg.ssid,
10058 sdata->vif.cfg.ssid_len);
10061 ieee80211_add_link_elems(sdata, skb, &capab, NULL,
10062 add_links_data->link[link_id].elems,
10063 add_links_data->link[link_id].elems_len,
10065 link_present_elems,
10068 if (add_links_data->link[link_id].elems)
10070 add_links_data->link[link_id].elems +
10072 add_links_data->link[link_id].elems_len -
10074 if (sdata->u.mgd.flags & IEEE80211_STA_UAPSD_ENABLED) {
10075 qos_info = sdata->u.mgd.uapsd_queues;
10076 qos_info |= (sdata->u.mgd.uapsd_max_sp_len <<
10077 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
10082 ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
10083 put_unaligned_le16(capab, capab_pos);
10086 ieee80211_fragment_element(skb, subelem_len,
10087 IEEE80211_MLE_SUBELEM_FRAGMENT);
10090 ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT);
10092 info = IEEE80211_SKB_CB(skb);
10093 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
10098 int ieee80211_mgd_assoc_ml_reconf(struct ieee80211_sub_if_data *sdata,
10099 struct cfg80211_assoc_link *add_links,
10102 struct ieee80211_local *local = sdata->local;
10103 struct ieee80211_mgd_assoc_data *data = NULL;
10104 struct sta_info *sta;
10105 struct sk_buff *skb;
10106 u16 added_links, new_valid_links;
10109 if (!ieee80211_vif_is_mld(&sdata->vif) ||
10110 !(sdata->vif.cfg.mld_capa_op &
10111 IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT))
10114 /* No support for concurrent ML reconfiguration operation */
10115 if (sdata->u.mgd.reconf.added_links ||
10116 sdata->u.mgd.reconf.removed_links)
10120 for (link_id = 0; add_links && link_id < IEEE80211_MLD_MAX_NUM_LINKS;
10122 if (!add_links[link_id].bss)
10125 added_links |= BIT(link_id);
10128 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
10132 if (rem_links & BIT(sta->sta.deflink.link_id))
10135 /* Adding links to the set of valid link is done only after a successful
10136 * ML reconfiguration frame exchange. Here prepare the data for the ML
10137 * reconfiguration frame construction and allocate the required
10141 bool uapsd_supported;
10142 unsigned long userspace_selectors;
10144 data = kzalloc(sizeof(*data), GFP_KERNEL);
10148 uapsd_supported = true;
10149 ieee80211_ml_reconf_selectors(&userspace_selectors);
10150 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
10152 struct ieee80211_supported_band *sband;
10153 struct cfg80211_bss *link_cbss = add_links[link_id].bss;
10154 struct ieee80211_bss *bss;
10159 bss = (void *)link_cbss->priv;
10161 if (!bss->wmm_used) {
10166 if (link_cbss->channel->band == NL80211_BAND_S1GHZ) {
10171 eth_random_addr(data->link[link_id].addr);
10172 data->link[link_id].conn =
10173 ieee80211_conn_settings_unlimited;
10175 local->hw.wiphy->bands[link_cbss->channel->band];
10177 ieee80211_determine_our_sta_mode(sdata, sband,
10178 NULL, true, link_id,
10179 &data->link[link_id].conn);
10181 data->link[link_id].bss = link_cbss;
10182 data->link[link_id].disabled =
10183 add_links[link_id].disabled;
10184 data->link[link_id].elems =
10185 (u8 *)add_links[link_id].elems;
10186 data->link[link_id].elems_len =
10187 add_links[link_id].elems_len;
10189 if (!bss->uapsd_supported)
10190 uapsd_supported = false;
10192 if (data->link[link_id].conn.mode <
10193 IEEE80211_CONN_MODE_EHT) {
10198 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, data,
10206 /* Require U-APSD support to be similar to the current valid
10209 if (uapsd_supported !=
10210 !!(sdata->u.mgd.flags & IEEE80211_STA_UAPSD_ENABLED)) {
10215 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
10217 if (!data->link[link_id].bss)
10220 /* only used to verify the mode, nothing is allocated */
10221 err = ieee80211_prep_channel(sdata, NULL, link_id,
10222 data->link[link_id].bss,
10224 &data->link[link_id].conn,
10225 &userspace_selectors);
10231 /* link removal is done before the ML reconfiguration frame exchange so
10232 * that these links will not be used between their removal by the AP MLD
10233 * and before the station got the ML reconfiguration response. Based on
10234 * Section 35.3.6.4 in Draft P802.11be_D7.0 the AP MLD should accept the
10235 * link removal request.
10238 u16 new_active_links = sdata->vif.active_links & ~rem_links;
10240 new_valid_links = sdata->vif.valid_links & ~rem_links;
10242 /* Should not be left with no valid links to perform the
10243 * ML reconfiguration
10245 if (!new_valid_links ||
10246 !(new_valid_links & ~sdata->vif.dormant_links)) {
10247 sdata_info(sdata, "mlo: reconf: no valid links\n");
10252 if (new_active_links != sdata->vif.active_links) {
10253 if (!new_active_links)
10255 BIT(__ffs(new_valid_links &
10256 ~sdata->vif.dormant_links));
10258 err = ieee80211_set_active_links(&sdata->vif,
10262 "mlo: reconf: failed set active links\n");
10268 /* Build the SKB before the link removal as the construction of the
10269 * station info for removed links requires the local address.
10270 * Invalidate the removed links, so that the transmission of the ML
10271 * reconfiguration request frame would not be done using them, as the AP
10272 * is expected to send the ML reconfiguration response frame on the link
10273 * on which the request was received.
10275 skb = ieee80211_build_ml_reconf_req(sdata, data, rem_links);
10282 u16 new_dormant_links = sdata->vif.dormant_links & ~rem_links;
10284 err = ieee80211_vif_set_links(sdata, new_valid_links,
10285 new_dormant_links);
10288 "mlo: reconf: failed set valid links\n");
10293 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
10295 if (!(rem_links & BIT(link_id)))
10298 ieee80211_sta_remove_link(sta, link_id);
10301 /* notify the driver and upper layers */
10302 ieee80211_vif_cfg_change_notify(sdata,
10303 BSS_CHANGED_MLD_VALID_LINKS);
10304 cfg80211_links_removed(sdata->dev, rem_links);
10307 sdata_info(sdata, "mlo: reconf: adding=0x%x, removed=0x%x\n",
10308 added_links, rem_links);
10310 ieee80211_tx_skb(sdata, skb);
10312 sdata->u.mgd.reconf.added_links = added_links;
10313 sdata->u.mgd.reconf.add_links_data = data;
10314 sdata->u.mgd.reconf.removed_links = rem_links;
10315 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
10316 &sdata->u.mgd.reconf.wk,
10317 IEEE80211_ASSOC_TIMEOUT_SHORT);