1 // SPDX-License-Identifier: GPL-2.0-only
3 * BSS client mode implementation
4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright (C) 2018 - 2022 Intel Corporation
14 #include <linux/delay.h>
15 #include <linux/fips.h>
16 #include <linux/if_ether.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 #include <linux/moduleparam.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/crc32.h>
23 #include <linux/slab.h>
24 #include <linux/export.h>
25 #include <net/mac80211.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
32 #include "fils_aead.h"
34 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
35 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
36 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
37 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
40 #define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2)
41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
44 #define IEEE80211_ASSOC_MAX_TRIES 3
46 static int max_nullfunc_tries = 2;
47 module_param(max_nullfunc_tries, int, 0644);
48 MODULE_PARM_DESC(max_nullfunc_tries,
49 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51 static int max_probe_tries = 5;
52 module_param(max_probe_tries, int, 0644);
53 MODULE_PARM_DESC(max_probe_tries,
54 "Maximum probe tries before disconnecting (reason 4).");
57 * Beacon loss timeout is calculated as N frames times the
58 * advertised beacon interval. This may need to be somewhat
59 * higher than what hardware might detect to account for
60 * delays in the host processing frames. But since we also
61 * probe on beacon miss before declaring the connection lost
62 * default to what we want.
64 static int beacon_loss_count = 7;
65 module_param(beacon_loss_count, int, 0644);
66 MODULE_PARM_DESC(beacon_loss_count,
67 "Number of beacon intervals before we decide beacon was lost.");
70 * Time the connection can be idle before we probe
71 * it to see if we can still talk to the AP.
73 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
75 * Time we wait for a probe response after sending
76 * a probe request because of beacon loss or for
77 * checking the connection still works.
79 static int probe_wait_ms = 500;
80 module_param(probe_wait_ms, int, 0644);
81 MODULE_PARM_DESC(probe_wait_ms,
82 "Maximum time(ms) to wait for probe response"
83 " before disconnecting (reason 4).");
86 * How many Beacon frames need to have been used in average signal strength
87 * before starting to indicate signal change events.
89 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
92 * We can have multiple work items (and connection probing)
93 * scheduling this timer, but we need to take care to only
94 * reschedule it when it should fire _earlier_ than it was
95 * asked for before, or if it's not pending right now. This
96 * function ensures that. Note that it then is required to
97 * run this function for all timeouts after the first one
98 * has happened -- the work that runs from this timer will
101 static void run_again(struct ieee80211_sub_if_data *sdata,
102 unsigned long timeout)
104 sdata_assert_lock(sdata);
106 if (!timer_pending(&sdata->u.mgd.timer) ||
107 time_before(timeout, sdata->u.mgd.timer.expires))
108 mod_timer(&sdata->u.mgd.timer, timeout);
111 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
113 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
116 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
119 mod_timer(&sdata->u.mgd.bcn_mon_timer,
120 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
123 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
125 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
127 if (unlikely(!ifmgd->associated))
130 if (ifmgd->probe_send_count)
131 ifmgd->probe_send_count = 0;
133 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
136 mod_timer(&ifmgd->conn_mon_timer,
137 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
140 static int ecw2cw(int ecw)
142 return (1 << ecw) - 1;
145 static ieee80211_conn_flags_t
146 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
147 struct ieee80211_link_data *link,
148 ieee80211_conn_flags_t conn_flags,
149 struct ieee80211_supported_band *sband,
150 struct ieee80211_channel *channel,
152 const struct ieee80211_ht_operation *ht_oper,
153 const struct ieee80211_vht_operation *vht_oper,
154 const struct ieee80211_he_operation *he_oper,
155 const struct ieee80211_eht_operation *eht_oper,
156 const struct ieee80211_s1g_oper_ie *s1g_oper,
157 struct cfg80211_chan_def *chandef, bool tracking)
159 struct cfg80211_chan_def vht_chandef;
160 struct ieee80211_sta_ht_cap sta_ht_cap;
161 ieee80211_conn_flags_t ret;
164 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
165 chandef->chan = channel;
166 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
167 chandef->center_freq1 = channel->center_freq;
168 chandef->freq1_offset = channel->freq_offset;
170 if (channel->band == NL80211_BAND_6GHZ) {
171 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
174 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
175 ret = IEEE80211_CONN_DISABLE_HT |
176 IEEE80211_CONN_DISABLE_VHT |
177 IEEE80211_CONN_DISABLE_HE |
178 IEEE80211_CONN_DISABLE_EHT;
182 vht_chandef = *chandef;
184 } else if (sband->band == NL80211_BAND_S1GHZ) {
185 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
187 "Missing S1G Operation Element? Trying operating == primary\n");
188 chandef->width = ieee80211_s1g_channel_width(channel);
191 ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
192 IEEE80211_CONN_DISABLE_VHT |
193 IEEE80211_CONN_DISABLE_80P80MHZ |
194 IEEE80211_CONN_DISABLE_160MHZ;
198 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
199 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
201 if (!ht_oper || !sta_ht_cap.ht_supported) {
202 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
203 ret = IEEE80211_CONN_DISABLE_HT |
204 IEEE80211_CONN_DISABLE_VHT |
205 IEEE80211_CONN_DISABLE_HE |
206 IEEE80211_CONN_DISABLE_EHT;
210 chandef->width = NL80211_CHAN_WIDTH_20;
212 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
214 /* check that channel matches the right operating channel */
215 if (!tracking && channel->center_freq != ht_cfreq) {
217 * It's possible that some APs are confused here;
218 * Netgear WNDR3700 sometimes reports 4 higher than
219 * the actual channel in association responses, but
220 * since we look at probe response/beacon data here
224 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
225 channel->center_freq, ht_cfreq,
226 ht_oper->primary_chan, channel->band);
227 ret = IEEE80211_CONN_DISABLE_HT |
228 IEEE80211_CONN_DISABLE_VHT |
229 IEEE80211_CONN_DISABLE_HE |
230 IEEE80211_CONN_DISABLE_EHT;
234 /* check 40 MHz support, if we have it */
235 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
236 ieee80211_chandef_ht_oper(ht_oper, chandef);
238 mlme_dbg(sdata, "40 MHz not supported\n");
239 /* 40 MHz (and 80 MHz) must be supported for VHT */
240 ret = IEEE80211_CONN_DISABLE_VHT;
241 /* also mark 40 MHz disabled */
242 ret |= IEEE80211_CONN_DISABLE_40MHZ;
246 if (!vht_oper || !sband->vht_cap.vht_supported) {
247 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
248 ret = IEEE80211_CONN_DISABLE_VHT;
252 vht_chandef = *chandef;
253 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE) &&
255 (le32_to_cpu(he_oper->he_oper_params) &
256 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,
269 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE))
271 "HE AP VHT information is invalid, disabling HE\n");
272 ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
275 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
279 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
281 "AP VHT information is invalid, disabling VHT\n");
282 ret = IEEE80211_CONN_DISABLE_VHT;
286 if (!cfg80211_chandef_valid(&vht_chandef)) {
287 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
289 "AP VHT information is invalid, disabling VHT\n");
290 ret = IEEE80211_CONN_DISABLE_VHT;
294 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
299 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
300 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
302 "AP VHT information doesn't match HT, disabling VHT\n");
303 ret = IEEE80211_CONN_DISABLE_VHT;
307 *chandef = vht_chandef;
310 * handle the case that the EHT operation indicates that it holds EHT
311 * operation information (in case that the channel width differs from
312 * the channel width reported in HT/VHT/HE).
314 if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
315 struct cfg80211_chan_def eht_chandef = *chandef;
317 ieee80211_chandef_eht_oper(sdata, eht_oper,
319 NL80211_CHAN_WIDTH_160,
320 false, &eht_chandef);
322 if (!cfg80211_chandef_valid(&eht_chandef)) {
323 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
325 "AP EHT information is invalid, disabling EHT\n");
326 ret = IEEE80211_CONN_DISABLE_EHT;
330 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
331 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
333 "AP EHT information is incompatible, disabling EHT\n");
334 ret = IEEE80211_CONN_DISABLE_EHT;
338 *chandef = eht_chandef;
345 * When tracking the current AP, don't do any further checks if the
346 * new chandef is identical to the one we're currently using for the
347 * connection. This keeps us from playing ping-pong with regulatory,
348 * without it the following can happen (for example):
349 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
350 * - AP advertises regdom US
351 * - CRDA loads regdom US with 80 MHz prohibited (old database)
352 * - the code below detects an unsupported channel, downgrades, and
353 * we disconnect from the AP in the caller
354 * - disconnect causes CRDA to reload world regdomain and the game
356 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
358 * It seems possible that there are still scenarios with CSA or real
359 * bandwidth changes where a this could happen, but those cases are
360 * less common and wouldn't completely prevent using the AP.
363 cfg80211_chandef_identical(chandef, &link->conf->chandef))
366 /* don't print the message below for VHT mismatch if VHT is disabled */
367 if (ret & IEEE80211_CONN_DISABLE_VHT)
368 vht_chandef = *chandef;
371 * Ignore the DISABLED flag when we're already connected and only
372 * tracking the APs beacon for bandwidth changes - otherwise we
373 * might get disconnected here if we connect to an AP, update our
374 * regulatory information based on the AP's country IE and the
375 * information we have is wrong/outdated and disables the channel
376 * that we're actually using for the connection to the AP.
378 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
380 IEEE80211_CHAN_DISABLED)) {
381 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
382 ret = IEEE80211_CONN_DISABLE_HT |
383 IEEE80211_CONN_DISABLE_VHT |
384 IEEE80211_CONN_DISABLE_HE |
385 IEEE80211_CONN_DISABLE_EHT;
389 ret |= ieee80211_chandef_downgrade(chandef);
392 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
393 IEEE80211_CHAN_NO_HE))
394 ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
396 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
397 IEEE80211_CHAN_NO_EHT))
398 ret |= IEEE80211_CONN_DISABLE_EHT;
400 if (chandef->width != vht_chandef.width && !tracking)
402 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
404 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
408 static int ieee80211_config_bw(struct ieee80211_link_data *link,
409 const struct ieee80211_ht_cap *ht_cap,
410 const struct ieee80211_vht_cap *vht_cap,
411 const struct ieee80211_ht_operation *ht_oper,
412 const struct ieee80211_vht_operation *vht_oper,
413 const struct ieee80211_he_operation *he_oper,
414 const struct ieee80211_eht_operation *eht_oper,
415 const struct ieee80211_s1g_oper_ie *s1g_oper,
416 const u8 *bssid, u32 *changed)
418 struct ieee80211_sub_if_data *sdata = link->sdata;
419 struct ieee80211_local *local = sdata->local;
420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
421 struct ieee80211_channel *chan = link->conf->chandef.chan;
422 struct ieee80211_supported_band *sband =
423 local->hw.wiphy->bands[chan->band];
424 struct cfg80211_chan_def chandef;
426 ieee80211_conn_flags_t flags;
427 u32 vht_cap_info = 0;
430 /* if HT was/is disabled, don't track any bandwidth changes */
431 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
434 /* don't check VHT if we associated as non-VHT station */
435 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
438 /* don't check HE if we associated as non-HE station */
439 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
440 !ieee80211_get_he_iftype_cap(sband,
441 ieee80211_vif_type_p2p(&sdata->vif))) {
446 /* don't check EHT if we associated as non-EHT station */
447 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
448 !ieee80211_get_eht_iftype_cap(sband,
449 ieee80211_vif_type_p2p(&sdata->vif)))
453 * if bss configuration changed store the new one -
454 * this may be applicable even if channel is identical
456 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
457 if (link->conf->ht_operation_mode != ht_opmode) {
458 *changed |= BSS_CHANGED_HT;
459 link->conf->ht_operation_mode = ht_opmode;
463 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
465 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
466 flags = ieee80211_determine_chantype(sdata, link,
467 link->u.mgd.conn_flags,
468 sband, chan, vht_cap_info,
471 s1g_oper, &chandef, true);
474 * Downgrade the new channel if we associated with restricted
475 * capabilities. For example, if we associated as a 20 MHz STA
476 * to a 40 MHz AP (due to regulatory, capabilities or config
477 * reasons) then switching to a 40 MHz channel now won't do us
478 * any good -- we couldn't use it with the AP.
480 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
481 chandef.width == NL80211_CHAN_WIDTH_80P80)
482 flags |= ieee80211_chandef_downgrade(&chandef);
483 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
484 chandef.width == NL80211_CHAN_WIDTH_160)
485 flags |= ieee80211_chandef_downgrade(&chandef);
486 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
487 chandef.width > NL80211_CHAN_WIDTH_20)
488 flags |= ieee80211_chandef_downgrade(&chandef);
490 if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
494 "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
495 link->u.mgd.bssid, chandef.chan->center_freq,
496 chandef.chan->freq_offset, chandef.width,
497 chandef.center_freq1, chandef.freq1_offset,
498 chandef.center_freq2);
500 if (flags != (link->u.mgd.conn_flags &
501 (IEEE80211_CONN_DISABLE_HT |
502 IEEE80211_CONN_DISABLE_VHT |
503 IEEE80211_CONN_DISABLE_HE |
504 IEEE80211_CONN_DISABLE_EHT |
505 IEEE80211_CONN_DISABLE_40MHZ |
506 IEEE80211_CONN_DISABLE_80P80MHZ |
507 IEEE80211_CONN_DISABLE_160MHZ |
508 IEEE80211_CONN_DISABLE_320MHZ)) ||
509 !cfg80211_chandef_valid(&chandef)) {
511 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
512 link->u.mgd.bssid, flags, ifmgd->flags);
516 ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
520 "AP %pM changed bandwidth to incompatible one - disconnect\n",
528 /* frame sending functions */
530 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
531 struct sk_buff *skb, u8 ap_ht_param,
532 struct ieee80211_supported_band *sband,
533 struct ieee80211_channel *channel,
534 enum ieee80211_smps_mode smps,
535 ieee80211_conn_flags_t conn_flags)
538 u32 flags = channel->flags;
540 struct ieee80211_sta_ht_cap ht_cap;
542 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
544 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
545 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
547 /* determine capability flags */
550 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
551 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
552 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
553 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
554 cap &= ~IEEE80211_HT_CAP_SGI_40;
557 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
558 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
559 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
560 cap &= ~IEEE80211_HT_CAP_SGI_40;
566 * If 40 MHz was disabled associate as though we weren't
567 * capable of 40 MHz -- some broken APs will never fall
568 * back to trying to transmit in 20 MHz.
570 if (conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
571 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
572 cap &= ~IEEE80211_HT_CAP_SGI_40;
575 /* set SM PS mode properly */
576 cap &= ~IEEE80211_HT_CAP_SM_PS;
578 case IEEE80211_SMPS_AUTOMATIC:
579 case IEEE80211_SMPS_NUM_MODES:
582 case IEEE80211_SMPS_OFF:
583 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
584 IEEE80211_HT_CAP_SM_PS_SHIFT;
586 case IEEE80211_SMPS_STATIC:
587 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
588 IEEE80211_HT_CAP_SM_PS_SHIFT;
590 case IEEE80211_SMPS_DYNAMIC:
591 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
592 IEEE80211_HT_CAP_SM_PS_SHIFT;
596 /* reserve and fill IE */
597 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
598 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
601 /* This function determines vht capability flags for the association
603 * Note - the function returns true to own the MU-MIMO capability
605 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
607 struct ieee80211_supported_band *sband,
608 struct ieee80211_vht_cap *ap_vht_cap,
609 ieee80211_conn_flags_t conn_flags)
611 struct ieee80211_local *local = sdata->local;
614 struct ieee80211_sta_vht_cap vht_cap;
615 u32 mask, ap_bf_sts, our_bf_sts;
616 bool mu_mimo_owner = false;
618 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
620 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
621 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
623 /* determine capability flags */
626 if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
627 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
629 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
630 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
631 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
632 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
635 if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
636 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
637 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
641 * Some APs apparently get confused if our capabilities are better
642 * than theirs, so restrict what we advertise in the assoc request.
644 if (!(ap_vht_cap->vht_cap_info &
645 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
646 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
647 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
648 else if (!(ap_vht_cap->vht_cap_info &
649 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
650 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
653 * If some other vif is using the MU-MIMO capability we cannot associate
654 * using MU-MIMO - this will lead to contradictions in the group-id
656 * Ownership is defined since association request, in order to avoid
657 * simultaneous associations with MU-MIMO.
659 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
660 bool disable_mu_mimo = false;
661 struct ieee80211_sub_if_data *other;
663 list_for_each_entry_rcu(other, &local->interfaces, list) {
664 if (other->vif.bss_conf.mu_mimo_owner) {
665 disable_mu_mimo = true;
670 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
672 mu_mimo_owner = true;
675 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
677 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
678 our_bf_sts = cap & mask;
680 if (ap_bf_sts < our_bf_sts) {
685 /* reserve and fill IE */
686 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
687 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
689 return mu_mimo_owner;
692 /* This function determines HE capability flags for the association
695 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
697 struct ieee80211_supported_band *sband,
698 ieee80211_conn_flags_t conn_flags)
700 u8 *pos, *pre_he_pos;
701 const struct ieee80211_sta_he_cap *he_cap;
704 he_cap = ieee80211_get_he_iftype_cap(sband,
705 ieee80211_vif_type_p2p(&sdata->vif));
706 if (WARN_ON(!he_cap))
709 /* get a max size estimate */
711 2 + 1 + sizeof(he_cap->he_cap_elem) +
712 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
713 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
714 he_cap->he_cap_elem.phy_cap_info);
715 pos = skb_put(skb, he_cap_size);
717 pos = ieee80211_ie_build_he_cap(conn_flags,
718 pos, he_cap, pos + he_cap_size);
719 /* trim excess if any */
720 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
722 ieee80211_ie_build_he_6ghz_cap(sdata, skb);
725 static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
727 struct ieee80211_supported_band *sband)
730 const struct ieee80211_sta_he_cap *he_cap;
731 const struct ieee80211_sta_eht_cap *eht_cap;
734 he_cap = ieee80211_get_he_iftype_cap(sband,
735 ieee80211_vif_type_p2p(&sdata->vif));
736 eht_cap = ieee80211_get_eht_iftype_cap(sband,
737 ieee80211_vif_type_p2p(&sdata->vif));
740 * EHT capabilities element is only added if the HE capabilities element
741 * was added so assume that 'he_cap' is valid and don't check it.
743 if (WARN_ON(!he_cap || !eht_cap))
747 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
748 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
749 &eht_cap->eht_cap_elem) +
750 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
751 eht_cap->eht_cap_elem.phy_cap_info);
752 pos = skb_put(skb, eht_cap_size);
753 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size);
756 static void ieee80211_assoc_add_rates(struct sk_buff *skb,
757 enum nl80211_chan_width width,
758 struct ieee80211_supported_band *sband,
759 struct ieee80211_mgd_assoc_data *assoc_data)
761 unsigned int shift = ieee80211_chanwidth_get_shift(width);
762 unsigned int rates_len, supp_rates_len;
767 if (assoc_data->supp_rates_len) {
769 * Get all rates supported by the device and the AP as
770 * some APs don't like getting a superset of their rates
771 * in the association request (e.g. D-Link DAP 1353 in
774 rates_len = ieee80211_parse_bitrates(width, sband,
775 assoc_data->supp_rates,
776 assoc_data->supp_rates_len,
780 * In case AP not provide any supported rates information
781 * before association, we send information element(s) with
782 * all rates that we support.
784 rates_len = sband->n_bitrates;
785 for (i = 0; i < sband->n_bitrates; i++)
789 supp_rates_len = rates_len;
790 if (supp_rates_len > 8)
793 pos = skb_put(skb, supp_rates_len + 2);
794 *pos++ = WLAN_EID_SUPP_RATES;
795 *pos++ = supp_rates_len;
798 for (i = 0; i < sband->n_bitrates; i++) {
799 if (BIT(i) & rates) {
800 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
808 if (rates_len > count) {
809 pos = skb_put(skb, rates_len - count + 2);
810 *pos++ = WLAN_EID_EXT_SUPP_RATES;
811 *pos++ = rates_len - count;
813 for (i++; i < sband->n_bitrates; i++) {
814 if (BIT(i) & rates) {
817 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
825 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
832 static const u8 before_ht[] = {
835 WLAN_EID_EXT_SUPP_RATES,
836 WLAN_EID_PWR_CAPABILITY,
837 WLAN_EID_SUPPORTED_CHANNELS,
840 WLAN_EID_RRM_ENABLED_CAPABILITIES,
841 WLAN_EID_MOBILITY_DOMAIN,
842 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
843 WLAN_EID_RIC_DATA, /* reassoc only */
844 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
846 static const u8 after_ric[] = {
847 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
848 WLAN_EID_HT_CAPABILITY,
849 WLAN_EID_BSS_COEX_2040,
850 /* luckily this is almost always there */
851 WLAN_EID_EXT_CAPABILITY,
852 WLAN_EID_QOS_TRAFFIC_CAPA,
853 WLAN_EID_TIM_BCAST_REQ,
854 WLAN_EID_INTERWORKING,
855 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
856 WLAN_EID_VHT_CAPABILITY,
857 WLAN_EID_OPMODE_NOTIF,
863 noffset = ieee80211_ie_split_ric(elems, elems_len,
865 ARRAY_SIZE(before_ht),
867 ARRAY_SIZE(after_ric),
869 skb_put_data(skb, elems + offset, noffset - offset);
874 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
879 static const u8 before_vht[] = {
881 * no need to list the ones split off before HT
884 WLAN_EID_BSS_COEX_2040,
885 WLAN_EID_EXT_CAPABILITY,
886 WLAN_EID_QOS_TRAFFIC_CAPA,
887 WLAN_EID_TIM_BCAST_REQ,
888 WLAN_EID_INTERWORKING,
889 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
896 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
897 noffset = ieee80211_ie_split(elems, elems_len,
898 before_vht, ARRAY_SIZE(before_vht),
900 skb_put_data(skb, elems + offset, noffset - offset);
905 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
910 static const u8 before_he[] = {
912 * no need to list the ones split off before VHT
915 WLAN_EID_OPMODE_NOTIF,
916 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
918 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
919 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
920 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
921 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
922 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
923 /* TODO: add 11ah/11aj/11ak elements */
930 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
931 noffset = ieee80211_ie_split(elems, elems_len,
932 before_he, ARRAY_SIZE(before_he),
934 skb_put_data(skb, elems + offset, noffset - offset);
939 #define PRESENT_ELEMS_MAX 8
940 #define PRESENT_ELEM_EXT_OFFS 0x100
942 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
943 struct sk_buff *skb, u16 capab,
944 const struct element *ext_capa,
945 const u16 *present_elems);
947 static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata,
948 struct sk_buff *skb, u16 *capab,
949 const struct element *ext_capa,
950 const u8 *extra_elems,
951 size_t extra_elems_len,
952 unsigned int link_id,
953 struct ieee80211_link_data *link,
956 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
957 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
958 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
959 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
960 struct ieee80211_channel *chan = cbss->channel;
961 const struct ieee80211_sband_iftype_data *iftd;
962 struct ieee80211_local *local = sdata->local;
963 struct ieee80211_supported_band *sband;
964 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
965 struct ieee80211_chanctx_conf *chanctx_conf;
966 enum ieee80211_smps_mode smps_mode;
967 u16 orig_capab = *capab;
969 int present_elems_len = 0;
973 #define ADD_PRESENT_ELEM(id) do { \
974 /* need a last for termination - we use 0 == SSID */ \
975 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
976 present_elems[present_elems_len++] = (id); \
978 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
981 smps_mode = link->smps_mode;
982 else if (sdata->u.mgd.powersave)
983 smps_mode = IEEE80211_SMPS_DYNAMIC;
985 smps_mode = IEEE80211_SMPS_OFF;
989 * 5/10 MHz scenarios are only viable without MLO, in which
990 * case this pointer should be used ... All of this is a bit
991 * unclear though, not sure this even works at all.
994 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
996 width = chanctx_conf->def.width;
1000 sband = local->hw.wiphy->bands[chan->band];
1001 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1003 if (sband->band == NL80211_BAND_2GHZ) {
1004 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1005 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1008 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
1009 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
1010 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
1012 if (sband->band != NL80211_BAND_S1GHZ)
1013 ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
1015 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
1016 *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
1017 struct cfg80211_chan_def chandef = {
1022 pos = skb_put(skb, 4);
1023 *pos++ = WLAN_EID_PWR_CAPABILITY;
1025 *pos++ = 0; /* min tx power */
1027 *pos++ = ieee80211_chandef_max_power(&chandef);
1028 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
1032 * Per spec, we shouldn't include the list of channels if we advertise
1033 * support for extended channel switching, but we've always done that;
1034 * (for now?) apply this restriction only on the (new) 6 GHz band.
1036 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
1037 (sband->band != NL80211_BAND_6GHZ ||
1038 !ext_capa || ext_capa->datalen < 1 ||
1039 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
1040 /* TODO: get this in reg domain format */
1041 pos = skb_put(skb, 2 * sband->n_channels + 2);
1042 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
1043 *pos++ = 2 * sband->n_channels;
1044 for (i = 0; i < sband->n_channels; i++) {
1045 int cf = sband->channels[i].center_freq;
1047 *pos++ = ieee80211_frequency_to_channel(cf);
1048 *pos++ = 1; /* one channel in the subband*/
1050 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
1053 /* if present, add any custom IEs that go before HT */
1054 offset = ieee80211_add_before_ht_elems(skb, extra_elems,
1058 if (sband->band != NL80211_BAND_6GHZ &&
1059 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT)) {
1060 ieee80211_add_ht_ie(sdata, skb,
1061 assoc_data->link[link_id].ap_ht_param,
1062 sband, chan, smps_mode,
1063 assoc_data->link[link_id].conn_flags);
1064 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
1067 /* if present, add any custom IEs that go before VHT */
1068 offset = ieee80211_add_before_vht_elems(skb, extra_elems,
1072 if (sband->band != NL80211_BAND_6GHZ &&
1073 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
1074 bool mu_mimo_owner =
1075 ieee80211_add_vht_ie(sdata, skb, sband,
1076 &assoc_data->link[link_id].ap_vht_cap,
1077 assoc_data->link[link_id].conn_flags);
1080 link->conf->mu_mimo_owner = mu_mimo_owner;
1081 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
1085 * If AP doesn't support HT, mark HE and EHT as disabled.
1086 * If on the 5GHz band, make sure it supports VHT.
1088 if (assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT ||
1089 (sband->band == NL80211_BAND_5GHZ &&
1090 assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT))
1091 assoc_data->link[link_id].conn_flags |=
1092 IEEE80211_CONN_DISABLE_HE |
1093 IEEE80211_CONN_DISABLE_EHT;
1095 /* if present, add any custom IEs that go before HE */
1096 offset = ieee80211_add_before_he_elems(skb, extra_elems,
1100 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HE)) {
1101 ieee80211_add_he_ie(sdata, skb, sband,
1102 assoc_data->link[link_id].conn_flags);
1103 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
1107 * careful - need to know about all the present elems before
1108 * calling ieee80211_assoc_add_ml_elem(), so add this one if
1109 * we're going to put it after the ML element
1111 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1112 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
1114 if (link_id == assoc_data->assoc_link_id)
1115 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
1118 /* crash if somebody gets it wrong */
1119 present_elems = NULL;
1121 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1122 ieee80211_add_eht_ie(sdata, skb, sband);
1124 if (sband->band == NL80211_BAND_S1GHZ) {
1125 ieee80211_add_aid_request_ie(sdata, skb);
1126 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1129 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1130 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1133 link->u.mgd.conn_flags = assoc_data->link[link_id].conn_flags;
1138 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
1142 unsigned int skb_len = skb->len;
1145 u8 *len, *list_len = NULL;
1147 skb_put_u8(skb, WLAN_EID_EXTENSION);
1148 len = skb_put(skb, 1);
1149 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
1151 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
1152 u16 elem = outer[i];
1153 bool have_inner = false;
1154 bool at_extension = false;
1156 /* should at least be sorted in the sense of normal -> ext */
1157 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
1159 /* switch to extension list */
1160 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
1161 at_extension = true;
1167 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
1168 if (elem == inner[j]) {
1178 list_len = skb_put(skb, 1);
1182 skb_put_u8(skb, (u8)elem);
1186 skb_trim(skb, skb_len);
1188 *len = skb->len - skb_len - 2;
1191 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1192 struct sk_buff *skb, u16 capab,
1193 const struct element *ext_capa,
1194 const u16 *outer_present_elems)
1196 struct ieee80211_local *local = sdata->local;
1197 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1198 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1199 struct ieee80211_multi_link_elem *ml_elem;
1200 struct ieee80211_mle_basic_common_info *common;
1201 const struct wiphy_iftype_ext_capab *ift_ext_capa;
1202 __le16 eml_capa = 0, mld_capa_ops = 0;
1203 unsigned int link_id;
1207 if (!sdata->vif.valid_links)
1210 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
1211 ieee80211_vif_type_p2p(&sdata->vif));
1213 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
1214 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
1217 skb_put_u8(skb, WLAN_EID_EXTENSION);
1218 ml_elem_len = skb_put(skb, 1);
1219 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
1220 ml_elem = skb_put(skb, sizeof(*ml_elem));
1222 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
1223 IEEE80211_MLC_BASIC_PRES_EML_CAPA |
1224 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
1225 common = skb_put(skb, sizeof(*common));
1226 common->len = sizeof(*common) +
1227 2 + /* EML capabilities */
1228 2; /* MLD capa/ops */
1229 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
1230 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
1231 /* need indication from userspace to support this */
1232 mld_capa_ops &= ~cpu_to_le16(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP);
1233 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
1235 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1236 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
1237 const u8 *extra_elems;
1238 size_t extra_elems_len;
1240 u8 *subelem_len = NULL;
1243 if (!assoc_data->link[link_id].bss ||
1244 link_id == assoc_data->assoc_link_id)
1247 extra_elems = assoc_data->link[link_id].elems;
1248 extra_elems_len = assoc_data->link[link_id].elems_len;
1250 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
1251 subelem_len = skb_put(skb, 1);
1253 ctrl = cpu_to_le16(link_id |
1254 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
1255 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
1256 skb_put_data(skb, &ctrl, sizeof(ctrl));
1257 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
1258 skb_put_data(skb, assoc_data->link[link_id].addr,
1261 * Now add the contents of the (re)association request,
1262 * but the "listen interval" and "current AP address"
1263 * (if applicable) are skipped. So we only have
1264 * the capability field (remember the position and fill
1265 * later), followed by the elements added below by
1266 * calling ieee80211_assoc_link_elems().
1268 capab_pos = skb_put(skb, 2);
1270 extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab,
1275 link_present_elems);
1277 skb_put_data(skb, extra_elems + extra_used,
1278 extra_elems_len - extra_used);
1280 put_unaligned_le16(capab, capab_pos);
1282 ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
1283 link_present_elems);
1285 ieee80211_fragment_element(skb, subelem_len);
1288 ieee80211_fragment_element(skb, ml_elem_len);
1291 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
1293 struct ieee80211_local *local = sdata->local;
1294 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1295 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1296 struct ieee80211_link_data *link;
1297 struct sk_buff *skb;
1298 struct ieee80211_mgmt *mgmt;
1299 u8 *pos, qos_info, *ie_start;
1300 size_t offset, noffset;
1301 u16 capab = WLAN_CAPABILITY_ESS, link_capab;
1303 struct element *ext_capa = NULL;
1304 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1305 struct ieee80211_prep_tx_info info = {};
1306 unsigned int link_id, n_links = 0;
1307 u16 present_elems[PRESENT_ELEMS_MAX] = {};
1313 /* we know it's writable, cast away the const */
1314 if (assoc_data->ie_len)
1315 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
1317 assoc_data->ie_len);
1319 sdata_assert_lock(sdata);
1321 size = local->hw.extra_tx_headroom +
1322 sizeof(*mgmt) + /* bit too much but doesn't matter */
1323 2 + assoc_data->ssid_len + /* SSID */
1324 assoc_data->ie_len + /* extra IEs */
1325 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
1328 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1329 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1330 const struct ieee80211_sband_iftype_data *iftd;
1331 struct ieee80211_supported_band *sband;
1336 sband = local->hw.wiphy->bands[cbss->channel->band];
1339 /* add STA profile elements length */
1340 size += assoc_data->link[link_id].elems_len;
1341 /* and supported rates length */
1342 size += 4 + sband->n_bitrates;
1343 /* supported channels */
1344 size += 2 + 2 * sband->n_channels;
1346 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1348 size += iftd->vendor_elems.len;
1350 /* power capability */
1353 /* HT, VHT, HE, EHT */
1354 size += 2 + sizeof(struct ieee80211_ht_cap);
1355 size += 2 + sizeof(struct ieee80211_vht_cap);
1356 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
1357 sizeof(struct ieee80211_he_mcs_nss_supp) +
1358 IEEE80211_HE_PPE_THRES_MAX_LEN;
1360 if (sband->band == NL80211_BAND_6GHZ)
1361 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
1363 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
1364 sizeof(struct ieee80211_eht_mcs_nss_supp) +
1365 IEEE80211_EHT_PPE_THRES_MAX_LEN;
1367 /* non-inheritance element */
1368 size += 2 + 2 + PRESENT_ELEMS_MAX;
1370 /* should be the same across all BSSes */
1371 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
1372 capab |= WLAN_CAPABILITY_PRIVACY;
1375 if (sdata->vif.valid_links) {
1376 /* consider the multi-link element with STA profile */
1377 size += sizeof(struct ieee80211_multi_link_elem);
1378 /* max common info field in basic multi-link element */
1379 size += sizeof(struct ieee80211_mle_basic_common_info) +
1384 * The capability elements were already considered above;
1385 * note this over-estimates a bit because there's no
1386 * STA profile for the assoc link.
1388 size += (n_links - 1) *
1389 (1 + 1 + /* subelement ID/length */
1390 2 + /* STA control */
1391 1 + ETH_ALEN + 2 /* STA Info field */);
1394 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
1398 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
1401 bssid = assoc_data->link[assoc_data->assoc_link_id].bss->bssid;
1403 skb = alloc_skb(size, GFP_KERNEL);
1407 skb_reserve(skb, local->hw.extra_tx_headroom);
1409 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
1410 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
1412 /* Set MBSSID support for HE AP if needed */
1413 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
1414 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
1415 ext_capa && ext_capa->datalen >= 3)
1416 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1418 mgmt = skb_put_zero(skb, 24);
1419 memcpy(mgmt->da, bssid, ETH_ALEN);
1420 memcpy(mgmt->sa, link->conf->addr, ETH_ALEN);
1421 memcpy(mgmt->bssid, bssid, ETH_ALEN);
1423 listen_int = cpu_to_le16(assoc_data->s1g ?
1424 ieee80211_encode_usf(local->hw.conf.listen_interval) :
1425 local->hw.conf.listen_interval);
1426 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
1428 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1429 IEEE80211_STYPE_REASSOC_REQ);
1430 capab_pos = &mgmt->u.reassoc_req.capab_info;
1431 mgmt->u.reassoc_req.listen_interval = listen_int;
1432 memcpy(mgmt->u.reassoc_req.current_ap,
1433 assoc_data->prev_ap_addr, ETH_ALEN);
1434 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
1437 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1438 IEEE80211_STYPE_ASSOC_REQ);
1439 capab_pos = &mgmt->u.assoc_req.capab_info;
1440 mgmt->u.assoc_req.listen_interval = listen_int;
1441 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
1445 pos = skb_put(skb, 2 + assoc_data->ssid_len);
1447 *pos++ = WLAN_EID_SSID;
1448 *pos++ = assoc_data->ssid_len;
1449 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
1451 /* add the elements for the assoc (main) link */
1453 offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab,
1457 assoc_data->assoc_link_id, link,
1459 put_unaligned_le16(link_capab, capab_pos);
1461 /* if present, add any custom non-vendor IEs */
1462 if (assoc_data->ie_len) {
1463 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1466 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1470 if (assoc_data->wmm) {
1471 if (assoc_data->uapsd) {
1472 qos_info = ifmgd->uapsd_queues;
1473 qos_info |= (ifmgd->uapsd_max_sp_len <<
1474 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1479 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1482 /* add any remaining custom (i.e. vendor specific here) IEs */
1483 if (assoc_data->ie_len) {
1484 noffset = assoc_data->ie_len;
1485 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1488 if (assoc_data->fils_kek_len) {
1489 ret = fils_encrypt_assoc_req(skb, assoc_data);
1496 pos = skb_tail_pointer(skb);
1497 kfree(ifmgd->assoc_req_ies);
1498 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1499 if (!ifmgd->assoc_req_ies) {
1504 ifmgd->assoc_req_ies_len = pos - ie_start;
1506 drv_mgd_prepare_tx(local, sdata, &info);
1508 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1509 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1510 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1511 IEEE80211_TX_INTFL_MLME_CONN_TX;
1512 ieee80211_tx_skb(sdata, skb);
1517 void ieee80211_send_pspoll(struct ieee80211_local *local,
1518 struct ieee80211_sub_if_data *sdata)
1520 struct ieee80211_pspoll *pspoll;
1521 struct sk_buff *skb;
1523 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1527 pspoll = (struct ieee80211_pspoll *) skb->data;
1528 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1530 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1531 ieee80211_tx_skb(sdata, skb);
1534 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1535 struct ieee80211_sub_if_data *sdata,
1538 struct sk_buff *skb;
1539 struct ieee80211_hdr_3addr *nullfunc;
1540 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1542 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1543 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1547 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1549 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1551 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1552 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1554 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1555 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1557 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1558 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1560 ieee80211_tx_skb(sdata, skb);
1563 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1564 struct ieee80211_sub_if_data *sdata)
1566 struct sk_buff *skb;
1567 struct ieee80211_hdr *nullfunc;
1570 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1573 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1577 skb_reserve(skb, local->hw.extra_tx_headroom);
1579 nullfunc = skb_put_zero(skb, 30);
1580 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1581 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1582 nullfunc->frame_control = fc;
1583 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1584 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1585 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1586 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1588 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1589 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1590 ieee80211_tx_skb(sdata, skb);
1593 /* spectrum management related things */
1594 static void ieee80211_chswitch_work(struct work_struct *work)
1596 struct ieee80211_link_data *link =
1597 container_of(work, struct ieee80211_link_data, u.mgd.chswitch_work);
1598 struct ieee80211_sub_if_data *sdata = link->sdata;
1599 struct ieee80211_local *local = sdata->local;
1600 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1603 if (!ieee80211_sdata_running(sdata))
1607 mutex_lock(&local->mtx);
1608 mutex_lock(&local->chanctx_mtx);
1610 if (!ifmgd->associated)
1613 if (!link->conf->csa_active)
1617 * using reservation isn't immediate as it may be deferred until later
1618 * with multi-vif. once reservation is complete it will re-schedule the
1619 * work with no reserved_chanctx so verify chandef to check if it
1620 * completed successfully
1623 if (link->reserved_chanctx) {
1625 * with multi-vif csa driver may call ieee80211_csa_finish()
1626 * many times while waiting for other interfaces to use their
1629 if (link->reserved_ready)
1632 ret = ieee80211_link_use_reserved_context(link);
1635 "failed to use reserved channel context, disconnecting (err=%d)\n",
1637 ieee80211_queue_work(&sdata->local->hw,
1638 &ifmgd->csa_connection_drop_work);
1645 if (!cfg80211_chandef_identical(&link->conf->chandef,
1646 &link->csa_chandef)) {
1648 "failed to finalize channel switch, disconnecting\n");
1649 ieee80211_queue_work(&sdata->local->hw,
1650 &ifmgd->csa_connection_drop_work);
1654 link->u.mgd.csa_waiting_bcn = true;
1656 ieee80211_sta_reset_beacon_monitor(sdata);
1657 ieee80211_sta_reset_conn_monitor(sdata);
1660 mutex_unlock(&local->chanctx_mtx);
1661 mutex_unlock(&local->mtx);
1662 sdata_unlock(sdata);
1665 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
1667 struct ieee80211_sub_if_data *sdata = link->sdata;
1668 struct ieee80211_local *local = sdata->local;
1669 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1672 sdata_assert_lock(sdata);
1674 WARN_ON(!link->conf->csa_active);
1676 if (link->csa_block_tx) {
1677 ieee80211_wake_vif_queues(local, sdata,
1678 IEEE80211_QUEUE_STOP_REASON_CSA);
1679 link->csa_block_tx = false;
1682 link->conf->csa_active = false;
1683 link->u.mgd.csa_waiting_bcn = false;
1685 * If the CSA IE is still present on the beacon after the switch,
1686 * we need to consider it as a new CSA (possibly to self).
1688 link->u.mgd.beacon_crc_valid = false;
1690 ret = drv_post_channel_switch(sdata);
1693 "driver post channel switch failed, disconnecting\n");
1694 ieee80211_queue_work(&local->hw,
1695 &ifmgd->csa_connection_drop_work);
1699 cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef, 0);
1702 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1704 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1705 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1707 if (WARN_ON(sdata->vif.valid_links))
1710 trace_api_chswitch_done(sdata, success);
1713 "driver channel switch failed, disconnecting\n");
1714 ieee80211_queue_work(&sdata->local->hw,
1715 &ifmgd->csa_connection_drop_work);
1717 ieee80211_queue_work(&sdata->local->hw,
1718 &sdata->deflink.u.mgd.chswitch_work);
1721 EXPORT_SYMBOL(ieee80211_chswitch_done);
1723 static void ieee80211_chswitch_timer(struct timer_list *t)
1725 struct ieee80211_link_data *link =
1726 from_timer(link, t, u.mgd.chswitch_timer);
1728 ieee80211_queue_work(&link->sdata->local->hw,
1729 &link->u.mgd.chswitch_work);
1733 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
1735 struct ieee80211_sub_if_data *sdata = link->sdata;
1736 struct ieee80211_local *local = sdata->local;
1738 if (!local->ops->abort_channel_switch)
1741 mutex_lock(&local->mtx);
1743 mutex_lock(&local->chanctx_mtx);
1744 ieee80211_link_unreserve_chanctx(link);
1745 mutex_unlock(&local->chanctx_mtx);
1747 if (link->csa_block_tx)
1748 ieee80211_wake_vif_queues(local, sdata,
1749 IEEE80211_QUEUE_STOP_REASON_CSA);
1751 link->csa_block_tx = false;
1752 link->conf->csa_active = false;
1754 mutex_unlock(&local->mtx);
1756 drv_abort_channel_switch(sdata);
1760 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
1761 u64 timestamp, u32 device_timestamp,
1762 struct ieee802_11_elems *elems,
1765 struct ieee80211_sub_if_data *sdata = link->sdata;
1766 struct ieee80211_local *local = sdata->local;
1767 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1768 struct cfg80211_bss *cbss = link->u.mgd.bss;
1769 struct ieee80211_chanctx_conf *conf;
1770 struct ieee80211_chanctx *chanctx;
1771 enum nl80211_band current_band;
1772 struct ieee80211_csa_ie csa_ie;
1773 struct ieee80211_channel_switch ch_switch;
1774 struct ieee80211_bss *bss;
1777 sdata_assert_lock(sdata);
1782 if (local->scanning)
1785 current_band = cbss->channel->band;
1786 bss = (void *)cbss->priv;
1787 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1789 link->u.mgd.conn_flags,
1790 link->u.mgd.bssid, &csa_ie);
1793 ch_switch.timestamp = timestamp;
1794 ch_switch.device_timestamp = device_timestamp;
1795 ch_switch.block_tx = csa_ie.mode;
1796 ch_switch.chandef = csa_ie.chandef;
1797 ch_switch.count = csa_ie.count;
1798 ch_switch.delay = csa_ie.max_switch_time;
1802 goto lock_and_drop_connection;
1804 if (beacon && link->conf->csa_active &&
1805 !link->u.mgd.csa_waiting_bcn) {
1807 ieee80211_sta_abort_chanswitch(link);
1809 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1811 } else if (link->conf->csa_active || res) {
1812 /* disregard subsequent announcements if already processing */
1816 if (link->conf->chandef.chan->band !=
1817 csa_ie.chandef.chan->band) {
1819 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1821 csa_ie.chandef.chan->center_freq,
1822 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1823 csa_ie.chandef.center_freq2);
1824 goto lock_and_drop_connection;
1827 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1828 IEEE80211_CHAN_DISABLED)) {
1830 "AP %pM switches to unsupported channel "
1831 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1834 csa_ie.chandef.chan->center_freq,
1835 csa_ie.chandef.chan->freq_offset,
1836 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1837 csa_ie.chandef.freq1_offset,
1838 csa_ie.chandef.center_freq2);
1839 goto lock_and_drop_connection;
1842 if (cfg80211_chandef_identical(&csa_ie.chandef,
1843 &link->conf->chandef) &&
1844 (!csa_ie.mode || !beacon)) {
1845 if (link->u.mgd.csa_ignored_same_chan)
1848 "AP %pM tries to chanswitch to same channel, ignore\n",
1850 link->u.mgd.csa_ignored_same_chan = true;
1855 * Drop all TDLS peers - either we disconnect or move to a different
1856 * channel from this point on. There's no telling what our peer will do.
1857 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1858 * have an incompatible wider chandef.
1860 ieee80211_teardown_tdls_peers(sdata);
1862 mutex_lock(&local->mtx);
1863 mutex_lock(&local->chanctx_mtx);
1864 conf = rcu_dereference_protected(link->conf->chanctx_conf,
1865 lockdep_is_held(&local->chanctx_mtx));
1868 "no channel context assigned to vif?, disconnecting\n");
1869 goto drop_connection;
1872 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1874 if (local->use_chanctx &&
1875 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1877 "driver doesn't support chan-switch with channel contexts\n");
1878 goto drop_connection;
1881 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1883 "preparing for channel switch failed, disconnecting\n");
1884 goto drop_connection;
1887 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
1888 chanctx->mode, false);
1891 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1893 goto drop_connection;
1895 mutex_unlock(&local->chanctx_mtx);
1897 link->conf->csa_active = true;
1898 link->csa_chandef = csa_ie.chandef;
1899 link->csa_block_tx = csa_ie.mode;
1900 link->u.mgd.csa_ignored_same_chan = false;
1901 link->u.mgd.beacon_crc_valid = false;
1903 if (link->csa_block_tx)
1904 ieee80211_stop_vif_queues(local, sdata,
1905 IEEE80211_QUEUE_STOP_REASON_CSA);
1906 mutex_unlock(&local->mtx);
1908 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1909 csa_ie.count, csa_ie.mode);
1911 if (local->ops->channel_switch) {
1912 /* use driver's channel switch callback */
1913 drv_channel_switch(local, sdata, &ch_switch);
1917 /* channel switch handled in software */
1918 if (csa_ie.count <= 1)
1919 ieee80211_queue_work(&local->hw, &link->u.mgd.chswitch_work);
1921 mod_timer(&link->u.mgd.chswitch_timer,
1922 TU_TO_EXP_TIME((csa_ie.count - 1) *
1923 cbss->beacon_interval));
1925 lock_and_drop_connection:
1926 mutex_lock(&local->mtx);
1927 mutex_lock(&local->chanctx_mtx);
1930 * This is just so that the disconnect flow will know that
1931 * we were trying to switch channel and failed. In case the
1932 * mode is 1 (we are not allowed to Tx), we will know not to
1933 * send a deauthentication frame. Those two fields will be
1934 * reset when the disconnection worker runs.
1936 link->conf->csa_active = true;
1937 link->csa_block_tx = csa_ie.mode;
1939 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1940 mutex_unlock(&local->chanctx_mtx);
1941 mutex_unlock(&local->mtx);
1945 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1946 struct ieee80211_channel *channel,
1947 const u8 *country_ie, u8 country_ie_len,
1948 const u8 *pwr_constr_elem,
1949 int *chan_pwr, int *pwr_reduction)
1951 struct ieee80211_country_ie_triplet *triplet;
1952 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1953 int i, chan_increment;
1954 bool have_chan_pwr = false;
1957 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1960 triplet = (void *)(country_ie + 3);
1961 country_ie_len -= 3;
1963 switch (channel->band) {
1967 case NL80211_BAND_2GHZ:
1968 case NL80211_BAND_60GHZ:
1969 case NL80211_BAND_LC:
1972 case NL80211_BAND_5GHZ:
1975 case NL80211_BAND_6GHZ:
1977 * In the 6 GHz band, the "maximum transmit power level"
1978 * field in the triplets is reserved, and thus will be
1979 * zero and we shouldn't use it to control TX power.
1980 * The actual TX power will be given in the transmit
1981 * power envelope element instead.
1987 while (country_ie_len >= 3) {
1988 u8 first_channel = triplet->chans.first_channel;
1990 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1993 for (i = 0; i < triplet->chans.num_channels; i++) {
1994 if (first_channel + i * chan_increment == chan) {
1995 have_chan_pwr = true;
1996 *chan_pwr = triplet->chans.max_power;
2005 country_ie_len -= 3;
2008 if (have_chan_pwr && pwr_constr_elem)
2009 *pwr_reduction = *pwr_constr_elem;
2013 return have_chan_pwr;
2016 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
2017 struct ieee80211_channel *channel,
2018 const u8 *cisco_dtpc_ie,
2021 /* From practical testing, the first data byte of the DTPC element
2022 * seems to contain the requested dBm level, and the CLI on Cisco
2023 * APs clearly state the range is -127 to 127 dBm, which indicates
2024 * a signed byte, although it seemingly never actually goes negative.
2025 * The other byte seems to always be zero.
2027 *pwr_level = (__s8)cisco_dtpc_ie[4];
2030 static u32 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
2031 struct ieee80211_channel *channel,
2032 struct ieee80211_mgmt *mgmt,
2033 const u8 *country_ie, u8 country_ie_len,
2034 const u8 *pwr_constr_ie,
2035 const u8 *cisco_dtpc_ie)
2037 struct ieee80211_sub_if_data *sdata = link->sdata;
2038 bool has_80211h_pwr = false, has_cisco_pwr = false;
2039 int chan_pwr = 0, pwr_reduction_80211h = 0;
2040 int pwr_level_cisco, pwr_level_80211h;
2042 __le16 capab = mgmt->u.probe_resp.capab_info;
2044 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
2045 return 0; /* TODO */
2048 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
2049 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
2050 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
2051 sdata, channel, country_ie, country_ie_len,
2052 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
2054 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
2057 if (cisco_dtpc_ie) {
2058 ieee80211_find_cisco_dtpc(
2059 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
2060 has_cisco_pwr = true;
2063 if (!has_80211h_pwr && !has_cisco_pwr)
2066 /* If we have both 802.11h and Cisco DTPC, apply both limits
2067 * by picking the smallest of the two power levels advertised.
2069 if (has_80211h_pwr &&
2070 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
2071 new_ap_level = pwr_level_80211h;
2073 if (link->ap_power_level == new_ap_level)
2077 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
2078 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
2080 } else { /* has_cisco_pwr is always true here. */
2081 new_ap_level = pwr_level_cisco;
2083 if (link->ap_power_level == new_ap_level)
2087 "Limiting TX power to %d dBm as advertised by %pM\n",
2088 pwr_level_cisco, link->u.mgd.bssid);
2091 link->ap_power_level = new_ap_level;
2092 if (__ieee80211_recalc_txpower(sdata))
2093 return BSS_CHANGED_TXPOWER;
2098 static void ieee80211_enable_ps(struct ieee80211_local *local,
2099 struct ieee80211_sub_if_data *sdata)
2101 struct ieee80211_conf *conf = &local->hw.conf;
2104 * If we are scanning right now then the parameters will
2105 * take effect when scan finishes.
2107 if (local->scanning)
2110 if (conf->dynamic_ps_timeout > 0 &&
2111 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2112 mod_timer(&local->dynamic_ps_timer, jiffies +
2113 msecs_to_jiffies(conf->dynamic_ps_timeout));
2115 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
2116 ieee80211_send_nullfunc(local, sdata, true);
2118 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2119 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2122 conf->flags |= IEEE80211_CONF_PS;
2123 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2127 static void ieee80211_change_ps(struct ieee80211_local *local)
2129 struct ieee80211_conf *conf = &local->hw.conf;
2131 if (local->ps_sdata) {
2132 ieee80211_enable_ps(local, local->ps_sdata);
2133 } else if (conf->flags & IEEE80211_CONF_PS) {
2134 conf->flags &= ~IEEE80211_CONF_PS;
2135 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2136 del_timer_sync(&local->dynamic_ps_timer);
2137 cancel_work_sync(&local->dynamic_ps_enable_work);
2141 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
2143 struct ieee80211_local *local = sdata->local;
2144 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
2145 struct sta_info *sta = NULL;
2146 bool authorized = false;
2148 if (!mgd->powersave)
2154 if (!mgd->associated)
2157 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
2160 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
2161 !sdata->deflink.u.mgd.have_beacon)
2165 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2167 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2173 /* need to hold RTNL or interface lock */
2174 void ieee80211_recalc_ps(struct ieee80211_local *local)
2176 struct ieee80211_sub_if_data *sdata, *found = NULL;
2180 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
2181 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2182 local->ps_sdata = NULL;
2186 list_for_each_entry(sdata, &local->interfaces, list) {
2187 if (!ieee80211_sdata_running(sdata))
2189 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2190 /* If an AP vif is found, then disable PS
2191 * by setting the count to zero thereby setting
2197 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2203 if (count == 1 && ieee80211_powersave_allowed(found)) {
2204 u8 dtimper = found->deflink.u.mgd.dtim_period;
2206 timeout = local->dynamic_ps_forced_timeout;
2209 local->hw.conf.dynamic_ps_timeout = timeout;
2211 /* If the TIM IE is invalid, pretend the value is 1 */
2215 local->hw.conf.ps_dtim_period = dtimper;
2216 local->ps_sdata = found;
2218 local->ps_sdata = NULL;
2221 ieee80211_change_ps(local);
2224 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
2226 bool ps_allowed = ieee80211_powersave_allowed(sdata);
2228 if (sdata->vif.cfg.ps != ps_allowed) {
2229 sdata->vif.cfg.ps = ps_allowed;
2230 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
2234 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
2236 struct ieee80211_local *local =
2237 container_of(work, struct ieee80211_local,
2238 dynamic_ps_disable_work);
2240 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2241 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2242 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2245 ieee80211_wake_queues_by_reason(&local->hw,
2246 IEEE80211_MAX_QUEUE_MAP,
2247 IEEE80211_QUEUE_STOP_REASON_PS,
2251 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2253 struct ieee80211_local *local =
2254 container_of(work, struct ieee80211_local,
2255 dynamic_ps_enable_work);
2256 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
2257 struct ieee80211_if_managed *ifmgd;
2258 unsigned long flags;
2261 /* can only happen when PS was just disabled anyway */
2265 ifmgd = &sdata->u.mgd;
2267 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2270 if (local->hw.conf.dynamic_ps_timeout > 0) {
2271 /* don't enter PS if TX frames are pending */
2272 if (drv_tx_frames_pending(local)) {
2273 mod_timer(&local->dynamic_ps_timer, jiffies +
2275 local->hw.conf.dynamic_ps_timeout));
2280 * transmission can be stopped by others which leads to
2281 * dynamic_ps_timer expiry. Postpone the ps timer if it
2282 * is not the actual idle state.
2284 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
2285 for (q = 0; q < local->hw.queues; q++) {
2286 if (local->queue_stop_reasons[q]) {
2287 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
2289 mod_timer(&local->dynamic_ps_timer, jiffies +
2291 local->hw.conf.dynamic_ps_timeout));
2295 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
2298 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2299 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2300 if (drv_tx_frames_pending(local)) {
2301 mod_timer(&local->dynamic_ps_timer, jiffies +
2303 local->hw.conf.dynamic_ps_timeout));
2305 ieee80211_send_nullfunc(local, sdata, true);
2306 /* Flush to get the tx status of nullfunc frame */
2307 ieee80211_flush_queues(local, sdata, false);
2311 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
2312 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
2313 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2314 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2315 local->hw.conf.flags |= IEEE80211_CONF_PS;
2316 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2320 void ieee80211_dynamic_ps_timer(struct timer_list *t)
2322 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
2324 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
2327 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
2329 struct delayed_work *delayed_work = to_delayed_work(work);
2330 struct ieee80211_link_data *link =
2331 container_of(delayed_work, struct ieee80211_link_data,
2332 dfs_cac_timer_work);
2333 struct cfg80211_chan_def chandef = link->conf->chandef;
2334 struct ieee80211_sub_if_data *sdata = link->sdata;
2336 mutex_lock(&sdata->local->mtx);
2337 if (sdata->wdev.cac_started) {
2338 ieee80211_link_release_channel(link);
2339 cfg80211_cac_event(sdata->dev, &chandef,
2340 NL80211_RADAR_CAC_FINISHED,
2343 mutex_unlock(&sdata->local->mtx);
2347 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2349 struct ieee80211_local *local = sdata->local;
2350 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2354 if (local->hw.queues < IEEE80211_NUM_ACS)
2357 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2358 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2360 unsigned long now = jiffies;
2362 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
2363 tx_tspec->admitted_time &&
2364 time_after(now, tx_tspec->time_slice_start + HZ)) {
2365 tx_tspec->consumed_tx_time = 0;
2366 tx_tspec->time_slice_start = now;
2368 if (tx_tspec->downgraded)
2370 TX_TSPEC_ACTION_STOP_DOWNGRADE;
2373 switch (tx_tspec->action) {
2374 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
2375 /* take the original parameters */
2376 if (drv_conf_tx(local, &sdata->deflink, ac,
2377 &sdata->deflink.tx_conf[ac]))
2378 link_err(&sdata->deflink,
2379 "failed to set TX queue parameters for queue %d\n",
2381 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2382 tx_tspec->downgraded = false;
2385 case TX_TSPEC_ACTION_DOWNGRADE:
2386 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2387 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2391 /* downgrade next lower non-ACM AC */
2392 for (non_acm_ac = ac + 1;
2393 non_acm_ac < IEEE80211_NUM_ACS;
2395 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2397 /* Usually the loop will result in using BK even if it
2398 * requires admission control, but such a configuration
2399 * makes no sense and we have to transmit somehow - the
2400 * AC selection does the same thing.
2401 * If we started out trying to downgrade from BK, then
2402 * the extra condition here might be needed.
2404 if (non_acm_ac >= IEEE80211_NUM_ACS)
2405 non_acm_ac = IEEE80211_AC_BK;
2406 if (drv_conf_tx(local, &sdata->deflink, ac,
2407 &sdata->deflink.tx_conf[non_acm_ac]))
2408 link_err(&sdata->deflink,
2409 "failed to set TX queue parameters for queue %d\n",
2411 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2413 schedule_delayed_work(&ifmgd->tx_tspec_wk,
2414 tx_tspec->time_slice_start + HZ - now + 1);
2416 case TX_TSPEC_ACTION_NONE:
2425 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2427 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2428 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2432 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
2434 struct ieee80211_sub_if_data *sdata;
2436 sdata = container_of(work, struct ieee80211_sub_if_data,
2437 u.mgd.tx_tspec_wk.work);
2438 ieee80211_sta_handle_tspec_ac_params(sdata);
2443 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2444 struct ieee80211_link_data *link,
2445 const u8 *wmm_param, size_t wmm_param_len,
2446 const struct ieee80211_mu_edca_param_set *mu_edca)
2448 struct ieee80211_sub_if_data *sdata = link->sdata;
2449 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2450 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2452 int count, mu_edca_count, ac;
2454 u8 uapsd_queues = 0;
2456 if (!local->ops->conf_tx)
2459 if (local->hw.queues < IEEE80211_NUM_ACS)
2465 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2468 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2469 uapsd_queues = ifmgd->uapsd_queues;
2471 count = wmm_param[6] & 0x0f;
2472 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2473 * if mu_edca was preset before and now it disappeared tell
2474 * the driver about it.
2476 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2477 if (count == link->u.mgd.wmm_last_param_set &&
2478 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
2480 link->u.mgd.wmm_last_param_set = count;
2481 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
2483 pos = wmm_param + 8;
2484 left = wmm_param_len - 8;
2486 memset(¶ms, 0, sizeof(params));
2489 for (; left >= 4; left -= 4, pos += 4) {
2490 int aci = (pos[0] >> 5) & 0x03;
2491 int acm = (pos[0] >> 4) & 0x01;
2496 ac = IEEE80211_AC_BK;
2498 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2499 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2501 params[ac].mu_edca = !!mu_edca;
2503 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2506 ac = IEEE80211_AC_VI;
2508 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2509 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2511 params[ac].mu_edca = !!mu_edca;
2513 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2516 ac = IEEE80211_AC_VO;
2518 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2519 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2521 params[ac].mu_edca = !!mu_edca;
2523 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2527 ac = IEEE80211_AC_BE;
2529 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2530 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2532 params[ac].mu_edca = !!mu_edca;
2534 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2538 params[ac].aifs = pos[0] & 0x0f;
2540 if (params[ac].aifs < 2) {
2542 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2543 params[ac].aifs, aci);
2544 params[ac].aifs = 2;
2546 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2547 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2548 params[ac].txop = get_unaligned_le16(pos + 2);
2549 params[ac].acm = acm;
2550 params[ac].uapsd = uapsd;
2552 if (params[ac].cw_min == 0 ||
2553 params[ac].cw_min > params[ac].cw_max) {
2555 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2556 params[ac].cw_min, params[ac].cw_max, aci);
2559 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2562 /* WMM specification requires all 4 ACIs. */
2563 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2564 if (params[ac].cw_min == 0) {
2566 "AP has invalid WMM params (missing AC %d), using defaults\n",
2572 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2574 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2576 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2577 params[ac].txop, params[ac].uapsd,
2578 ifmgd->tx_tspec[ac].downgraded);
2579 link->tx_conf[ac] = params[ac];
2580 if (!ifmgd->tx_tspec[ac].downgraded &&
2581 drv_conf_tx(local, link, ac, ¶ms[ac]))
2583 "failed to set TX queue parameters for AC %d\n",
2587 /* enable WMM or activate new settings */
2588 link->conf->qos = true;
2592 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2594 lockdep_assert_held(&sdata->local->mtx);
2596 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2597 ieee80211_run_deferred_scan(sdata->local);
2600 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2602 mutex_lock(&sdata->local->mtx);
2603 __ieee80211_stop_poll(sdata);
2604 mutex_unlock(&sdata->local->mtx);
2607 static u32 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
2608 u16 capab, bool erp_valid, u8 erp)
2610 struct ieee80211_bss_conf *bss_conf = link->conf;
2611 struct ieee80211_supported_band *sband;
2613 bool use_protection;
2614 bool use_short_preamble;
2615 bool use_short_slot;
2617 sband = ieee80211_get_link_sband(link);
2622 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2623 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2625 use_protection = false;
2626 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2629 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2630 if (sband->band == NL80211_BAND_5GHZ ||
2631 sband->band == NL80211_BAND_6GHZ)
2632 use_short_slot = true;
2634 if (use_protection != bss_conf->use_cts_prot) {
2635 bss_conf->use_cts_prot = use_protection;
2636 changed |= BSS_CHANGED_ERP_CTS_PROT;
2639 if (use_short_preamble != bss_conf->use_short_preamble) {
2640 bss_conf->use_short_preamble = use_short_preamble;
2641 changed |= BSS_CHANGED_ERP_PREAMBLE;
2644 if (use_short_slot != bss_conf->use_short_slot) {
2645 bss_conf->use_short_slot = use_short_slot;
2646 changed |= BSS_CHANGED_ERP_SLOT;
2652 static u32 ieee80211_link_set_associated(struct ieee80211_link_data *link,
2653 struct cfg80211_bss *cbss)
2655 struct ieee80211_sub_if_data *sdata = link->sdata;
2656 struct ieee80211_bss_conf *bss_conf = link->conf;
2657 struct ieee80211_bss *bss = (void *)cbss->priv;
2658 u32 changed = BSS_CHANGED_QOS;
2660 /* not really used in MLO */
2661 sdata->u.mgd.beacon_timeout =
2662 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
2663 bss_conf->beacon_int));
2665 changed |= ieee80211_handle_bss_capability(link,
2666 bss_conf->assoc_capability,
2670 ieee80211_check_rate_mask(link);
2672 link->u.mgd.bss = cbss;
2673 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2675 if (sdata->vif.p2p ||
2676 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2677 const struct cfg80211_bss_ies *ies;
2680 ies = rcu_dereference(cbss->ies);
2684 ret = cfg80211_get_p2p_attr(
2685 ies->data, ies->len,
2686 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2687 (u8 *) &bss_conf->p2p_noa_attr,
2688 sizeof(bss_conf->p2p_noa_attr));
2690 link->u.mgd.p2p_noa_index =
2691 bss_conf->p2p_noa_attr.index;
2692 changed |= BSS_CHANGED_P2P_PS;
2698 if (link->u.mgd.have_beacon) {
2700 * If the AP is buggy we may get here with no DTIM period
2701 * known, so assume it's 1 which is the only safe assumption
2702 * in that case, although if the TIM IE is broken powersave
2703 * probably just won't work at all.
2705 bss_conf->dtim_period = link->u.mgd.dtim_period ?: 1;
2706 bss_conf->beacon_rate = bss->beacon_rate;
2707 changed |= BSS_CHANGED_BEACON_INFO;
2709 bss_conf->beacon_rate = NULL;
2710 bss_conf->dtim_period = 0;
2713 /* Tell the driver to monitor connection quality (if supported) */
2714 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2715 bss_conf->cqm_rssi_thold)
2716 changed |= BSS_CHANGED_CQM;
2721 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2722 struct ieee80211_mgd_assoc_data *assoc_data,
2723 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
2725 struct ieee80211_local *local = sdata->local;
2726 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
2727 u64 vif_changed = BSS_CHANGED_ASSOC;
2728 unsigned int link_id;
2730 sdata->u.mgd.associated = true;
2732 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
2733 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2734 struct ieee80211_link_data *link;
2739 link = sdata_dereference(sdata->link[link_id], sdata);
2743 changed[link_id] |= ieee80211_link_set_associated(link, cbss);
2746 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
2748 /* just to be sure */
2749 ieee80211_stop_poll(sdata);
2751 ieee80211_led_assoc(local, 1);
2755 /* Enable ARP filtering */
2756 if (vif_cfg->arp_addr_cnt)
2757 vif_changed |= BSS_CHANGED_ARP_FILTER;
2759 if (sdata->vif.valid_links) {
2761 link_id < IEEE80211_MLD_MAX_NUM_LINKS;
2763 struct ieee80211_link_data *link;
2764 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2769 link = sdata_dereference(sdata->link[link_id], sdata);
2773 ieee80211_link_info_change_notify(sdata, link,
2776 ieee80211_recalc_smps(sdata, link);
2779 ieee80211_vif_cfg_change_notify(sdata, vif_changed);
2781 ieee80211_bss_info_change_notify(sdata,
2782 vif_changed | changed[0]);
2785 mutex_lock(&local->iflist_mtx);
2786 ieee80211_recalc_ps(local);
2787 mutex_unlock(&local->iflist_mtx);
2789 /* leave this here to not change ordering in non-MLO cases */
2790 if (!sdata->vif.valid_links)
2791 ieee80211_recalc_smps(sdata, &sdata->deflink);
2792 ieee80211_recalc_ps_vif(sdata);
2794 netif_carrier_on(sdata->dev);
2797 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2798 u16 stype, u16 reason, bool tx,
2801 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2802 struct ieee80211_local *local = sdata->local;
2803 unsigned int link_id;
2805 struct ieee80211_prep_tx_info info = {
2809 sdata_assert_lock(sdata);
2811 if (WARN_ON_ONCE(tx && !frame_buf))
2814 if (WARN_ON(!ifmgd->associated))
2817 ieee80211_stop_poll(sdata);
2819 ifmgd->associated = false;
2821 /* other links will be destroyed */
2822 sdata->deflink.u.mgd.bss = NULL;
2824 netif_carrier_off(sdata->dev);
2827 * if we want to get out of ps before disassoc (why?) we have
2828 * to do it before sending disassoc, as otherwise the null-packet
2831 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2832 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2833 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2835 local->ps_sdata = NULL;
2837 /* disable per-vif ps */
2838 ieee80211_recalc_ps_vif(sdata);
2840 /* make sure ongoing transmission finishes */
2844 * drop any frame before deauth/disassoc, this can be data or
2845 * management frame. Since we are disconnecting, we should not
2846 * insist sending these frames which can take time and delay
2847 * the disconnection and possible the roaming.
2850 ieee80211_flush_queues(local, sdata, true);
2852 /* deauthenticate/disassociate now */
2853 if (tx || frame_buf) {
2855 * In multi channel scenarios guarantee that the virtual
2856 * interface is granted immediate airtime to transmit the
2857 * deauthentication frame by calling mgd_prepare_tx, if the
2858 * driver requested so.
2860 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2861 !sdata->deflink.u.mgd.have_beacon) {
2862 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2865 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
2866 sdata->vif.cfg.ap_addr, stype,
2867 reason, tx, frame_buf);
2870 /* flush out frame - make sure the deauth was actually sent */
2872 ieee80211_flush_queues(local, sdata, false);
2874 drv_mgd_complete_tx(sdata->local, sdata, &info);
2876 /* clear AP addr only after building the needed mgmt frames */
2877 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2878 eth_zero_addr(sdata->vif.cfg.ap_addr);
2880 sdata->vif.cfg.ssid_len = 0;
2882 /* remove AP and TDLS peers */
2883 sta_info_flush(sdata);
2885 /* finally reset all BSS / config parameters */
2886 changed |= ieee80211_reset_erp_info(sdata);
2888 ieee80211_led_assoc(local, 0);
2889 changed |= BSS_CHANGED_ASSOC;
2890 sdata->vif.cfg.assoc = false;
2892 sdata->deflink.u.mgd.p2p_noa_index = -1;
2893 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2894 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2896 /* on the next assoc, re-program HT/VHT parameters */
2897 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2898 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2899 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2900 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2903 * reset MU-MIMO ownership and group data in default link,
2904 * if used, other links are destroyed
2906 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2907 sizeof(sdata->vif.bss_conf.mu_group.membership));
2908 memset(sdata->vif.bss_conf.mu_group.position, 0,
2909 sizeof(sdata->vif.bss_conf.mu_group.position));
2910 if (!sdata->vif.valid_links)
2911 changed |= BSS_CHANGED_MU_GROUPS;
2912 sdata->vif.bss_conf.mu_mimo_owner = false;
2914 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2916 del_timer_sync(&local->dynamic_ps_timer);
2917 cancel_work_sync(&local->dynamic_ps_enable_work);
2919 /* Disable ARP filtering */
2920 if (sdata->vif.cfg.arp_addr_cnt)
2921 changed |= BSS_CHANGED_ARP_FILTER;
2923 sdata->vif.bss_conf.qos = false;
2924 if (!sdata->vif.valid_links) {
2925 changed |= BSS_CHANGED_QOS;
2926 /* The BSSID (not really interesting) and HT changed */
2927 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2930 ieee80211_bss_info_change_notify(sdata, changed);
2932 /* disassociated - set to defaults now */
2933 ieee80211_set_wmm_default(&sdata->deflink, false, false);
2935 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2936 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2937 del_timer_sync(&sdata->u.mgd.timer);
2938 del_timer_sync(&sdata->deflink.u.mgd.chswitch_timer);
2940 sdata->vif.bss_conf.dtim_period = 0;
2941 sdata->vif.bss_conf.beacon_rate = NULL;
2943 sdata->deflink.u.mgd.have_beacon = false;
2944 sdata->deflink.u.mgd.tracking_signal_avg = false;
2945 sdata->deflink.u.mgd.disable_wmm_tracking = false;
2948 sdata->deflink.u.mgd.conn_flags = 0;
2949 mutex_lock(&local->mtx);
2951 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
2952 struct ieee80211_link_data *link;
2954 link = sdata_dereference(sdata->link[link_id], sdata);
2957 ieee80211_link_release_channel(link);
2960 sdata->vif.bss_conf.csa_active = false;
2961 sdata->deflink.u.mgd.csa_waiting_bcn = false;
2962 sdata->deflink.u.mgd.csa_ignored_same_chan = false;
2963 if (sdata->deflink.csa_block_tx) {
2964 ieee80211_wake_vif_queues(local, sdata,
2965 IEEE80211_QUEUE_STOP_REASON_CSA);
2966 sdata->deflink.csa_block_tx = false;
2968 mutex_unlock(&local->mtx);
2970 /* existing TX TSPEC sessions no longer exist */
2971 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2972 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2974 sdata->vif.bss_conf.pwr_reduction = 0;
2975 sdata->vif.bss_conf.tx_pwr_env_num = 0;
2976 memset(sdata->vif.bss_conf.tx_pwr_env, 0,
2977 sizeof(sdata->vif.bss_conf.tx_pwr_env));
2979 ieee80211_vif_set_links(sdata, 0);
2982 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2984 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2985 struct ieee80211_local *local = sdata->local;
2987 mutex_lock(&local->mtx);
2988 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2991 __ieee80211_stop_poll(sdata);
2993 mutex_lock(&local->iflist_mtx);
2994 ieee80211_recalc_ps(local);
2995 mutex_unlock(&local->iflist_mtx);
2997 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3001 * We've received a probe response, but are not sure whether
3002 * we have or will be receiving any beacons or data, so let's
3003 * schedule the timers again, just in case.
3005 ieee80211_sta_reset_beacon_monitor(sdata);
3007 mod_timer(&ifmgd->conn_mon_timer,
3008 round_jiffies_up(jiffies +
3009 IEEE80211_CONNECTION_IDLE_TIME));
3011 mutex_unlock(&local->mtx);
3014 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
3015 struct ieee80211_hdr *hdr,
3018 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3021 struct ieee80211_sta_tx_tspec *tx_tspec;
3022 unsigned long now = jiffies;
3024 if (!ieee80211_is_data_qos(hdr->frame_control))
3027 tid = ieee80211_get_tid(hdr);
3028 ac = ieee80211_ac_from_tid(tid);
3029 tx_tspec = &ifmgd->tx_tspec[ac];
3031 if (likely(!tx_tspec->admitted_time))
3034 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3035 tx_tspec->consumed_tx_time = 0;
3036 tx_tspec->time_slice_start = now;
3038 if (tx_tspec->downgraded) {
3039 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3040 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3044 if (tx_tspec->downgraded)
3047 tx_tspec->consumed_tx_time += tx_time;
3049 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
3050 tx_tspec->downgraded = true;
3051 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
3052 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3056 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
3057 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
3059 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
3061 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
3062 !sdata->u.mgd.probe_send_count)
3066 sdata->u.mgd.probe_send_count = 0;
3068 sdata->u.mgd.nullfunc_failed = true;
3069 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3072 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
3073 const u8 *src, const u8 *dst,
3074 const u8 *ssid, size_t ssid_len,
3075 struct ieee80211_channel *channel)
3077 struct sk_buff *skb;
3079 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
3080 ssid, ssid_len, NULL, 0,
3081 IEEE80211_PROBE_FLAG_DIRECTED);
3083 ieee80211_tx_skb(sdata, skb);
3086 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
3088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3089 u8 *dst = sdata->vif.cfg.ap_addr;
3090 u8 unicast_limit = max(1, max_probe_tries - 3);
3091 struct sta_info *sta;
3093 if (WARN_ON(sdata->vif.valid_links))
3097 * Try sending broadcast probe requests for the last three
3098 * probe requests after the first ones failed since some
3099 * buggy APs only support broadcast probe requests.
3101 if (ifmgd->probe_send_count >= unicast_limit)
3105 * When the hardware reports an accurate Tx ACK status, it's
3106 * better to send a nullfunc frame instead of a probe request,
3107 * as it will kick us off the AP quickly if we aren't associated
3108 * anymore. The timeout will be reset if the frame is ACKed by
3111 ifmgd->probe_send_count++;
3114 mutex_lock(&sdata->local->sta_mtx);
3115 sta = sta_info_get(sdata, dst);
3117 ieee80211_check_fast_rx(sta);
3118 mutex_unlock(&sdata->local->sta_mtx);
3121 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
3122 ifmgd->nullfunc_failed = false;
3123 ieee80211_send_nullfunc(sdata->local, sdata, false);
3125 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
3126 sdata->vif.cfg.ssid,
3127 sdata->vif.cfg.ssid_len,
3128 sdata->deflink.u.mgd.bss->channel);
3131 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
3132 run_again(sdata, ifmgd->probe_timeout);
3135 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
3138 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3139 bool already = false;
3141 if (WARN_ON(sdata->vif.valid_links))
3144 if (!ieee80211_sdata_running(sdata))
3149 if (!ifmgd->associated)
3152 mutex_lock(&sdata->local->mtx);
3154 if (sdata->local->tmp_channel || sdata->local->scanning) {
3155 mutex_unlock(&sdata->local->mtx);
3159 if (sdata->local->suspending) {
3160 /* reschedule after resume */
3161 mutex_unlock(&sdata->local->mtx);
3162 ieee80211_reset_ap_probe(sdata);
3167 mlme_dbg_ratelimited(sdata,
3168 "detected beacon loss from AP (missed %d beacons) - probing\n",
3171 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
3175 * The driver/our work has already reported this event or the
3176 * connection monitoring has kicked in and we have already sent
3177 * a probe request. Or maybe the AP died and the driver keeps
3178 * reporting until we disassociate...
3180 * In either case we have to ignore the current call to this
3181 * function (except for setting the correct probe reason bit)
3182 * because otherwise we would reset the timer every time and
3183 * never check whether we received a probe response!
3185 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
3188 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
3190 mutex_unlock(&sdata->local->mtx);
3195 mutex_lock(&sdata->local->iflist_mtx);
3196 ieee80211_recalc_ps(sdata->local);
3197 mutex_unlock(&sdata->local->iflist_mtx);
3199 ifmgd->probe_send_count = 0;
3200 ieee80211_mgd_probe_ap_send(sdata);
3202 sdata_unlock(sdata);
3205 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
3206 struct ieee80211_vif *vif)
3208 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3209 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3210 struct cfg80211_bss *cbss;
3211 struct sk_buff *skb;
3212 const struct element *ssid;
3215 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
3216 sdata->vif.valid_links))
3219 sdata_assert_lock(sdata);
3221 if (ifmgd->associated)
3222 cbss = sdata->deflink.u.mgd.bss;
3223 else if (ifmgd->auth_data)
3224 cbss = ifmgd->auth_data->bss;
3225 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
3226 cbss = ifmgd->assoc_data->link[0].bss;
3231 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
3232 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
3233 "invalid SSID element (len=%d)",
3234 ssid ? ssid->datalen : -1))
3237 ssid_len = ssid->datalen;
3239 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
3240 (u32) -1, cbss->channel,
3241 ssid->data, ssid_len,
3242 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
3247 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
3249 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
3250 const u8 *buf, size_t len, bool tx,
3251 u16 reason, bool reconnect)
3253 struct ieee80211_event event = {
3255 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
3256 .u.mlme.reason = reason,
3260 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
3262 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
3264 drv_event_callback(sdata->local, sdata, &event);
3267 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
3269 struct ieee80211_local *local = sdata->local;
3270 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3271 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3275 if (!ifmgd->associated) {
3276 sdata_unlock(sdata);
3280 /* in MLO assume we have a link where we can TX the frame */
3281 tx = sdata->vif.valid_links || !sdata->deflink.csa_block_tx;
3283 if (!ifmgd->driver_disconnect) {
3284 unsigned int link_id;
3287 * AP is probably out of range (or not reachable for another
3288 * reason) so remove the bss structs for that AP. In the case
3289 * of multi-link, it's not clear that all of them really are
3290 * out of range, but if they weren't the driver likely would
3291 * have switched to just have a single link active?
3294 link_id < ARRAY_SIZE(sdata->link);
3296 struct ieee80211_link_data *link;
3298 link = sdata_dereference(sdata->link[link_id], sdata);
3301 cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
3302 link->u.mgd.bss = NULL;
3306 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3307 ifmgd->driver_disconnect ?
3308 WLAN_REASON_DEAUTH_LEAVING :
3309 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3311 mutex_lock(&local->mtx);
3312 /* the other links will be destroyed */
3313 sdata->vif.bss_conf.csa_active = false;
3314 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3315 if (sdata->deflink.csa_block_tx) {
3316 ieee80211_wake_vif_queues(local, sdata,
3317 IEEE80211_QUEUE_STOP_REASON_CSA);
3318 sdata->deflink.csa_block_tx = false;
3320 mutex_unlock(&local->mtx);
3322 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
3323 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3325 ifmgd->reconnect = false;
3327 sdata_unlock(sdata);
3330 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
3332 struct ieee80211_sub_if_data *sdata =
3333 container_of(work, struct ieee80211_sub_if_data,
3334 u.mgd.beacon_connection_loss_work);
3335 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3337 if (ifmgd->connection_loss) {
3338 sdata_info(sdata, "Connection to AP %pM lost\n",
3339 sdata->vif.cfg.ap_addr);
3340 __ieee80211_disconnect(sdata);
3341 ifmgd->connection_loss = false;
3342 } else if (ifmgd->driver_disconnect) {
3344 "Driver requested disconnection from AP %pM\n",
3345 sdata->vif.cfg.ap_addr);
3346 __ieee80211_disconnect(sdata);
3347 ifmgd->driver_disconnect = false;
3349 if (ifmgd->associated)
3350 sdata->deflink.u.mgd.beacon_loss_count++;
3351 ieee80211_mgd_probe_ap(sdata, true);
3355 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
3357 struct ieee80211_sub_if_data *sdata =
3358 container_of(work, struct ieee80211_sub_if_data,
3359 u.mgd.csa_connection_drop_work);
3361 __ieee80211_disconnect(sdata);
3364 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
3366 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3367 struct ieee80211_hw *hw = &sdata->local->hw;
3369 trace_api_beacon_loss(sdata);
3371 sdata->u.mgd.connection_loss = false;
3372 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3374 EXPORT_SYMBOL(ieee80211_beacon_loss);
3376 void ieee80211_connection_loss(struct ieee80211_vif *vif)
3378 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3379 struct ieee80211_hw *hw = &sdata->local->hw;
3381 trace_api_connection_loss(sdata);
3383 sdata->u.mgd.connection_loss = true;
3384 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3386 EXPORT_SYMBOL(ieee80211_connection_loss);
3388 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
3390 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3391 struct ieee80211_hw *hw = &sdata->local->hw;
3393 trace_api_disconnect(sdata, reconnect);
3395 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
3398 sdata->u.mgd.driver_disconnect = true;
3399 sdata->u.mgd.reconnect = reconnect;
3400 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3402 EXPORT_SYMBOL(ieee80211_disconnect);
3404 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
3407 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3409 sdata_assert_lock(sdata);
3413 * we are not authenticated yet, the only timer that could be
3414 * running is the timeout for the authentication response which
3415 * which is not relevant anymore.
3417 del_timer_sync(&sdata->u.mgd.timer);
3418 sta_info_destroy_addr(sdata, auth_data->ap_addr);
3420 /* other links are destroyed */
3421 sdata->deflink.u.mgd.conn_flags = 0;
3422 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3423 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3425 sdata->u.mgd.flags = 0;
3426 mutex_lock(&sdata->local->mtx);
3427 ieee80211_link_release_channel(&sdata->deflink);
3428 mutex_unlock(&sdata->local->mtx);
3430 ieee80211_vif_set_links(sdata, 0);
3433 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
3435 sdata->u.mgd.auth_data = NULL;
3445 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3446 enum assoc_status status)
3448 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3450 sdata_assert_lock(sdata);
3452 if (status != ASSOC_SUCCESS) {
3454 * we are not associated yet, the only timer that could be
3455 * running is the timeout for the association response which
3456 * which is not relevant anymore.
3458 del_timer_sync(&sdata->u.mgd.timer);
3459 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
3461 sdata->deflink.u.mgd.conn_flags = 0;
3462 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3463 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3465 sdata->u.mgd.flags = 0;
3466 sdata->vif.bss_conf.mu_mimo_owner = false;
3468 mutex_lock(&sdata->local->mtx);
3469 ieee80211_link_release_channel(&sdata->deflink);
3470 mutex_unlock(&sdata->local->mtx);
3472 if (status != ASSOC_REJECTED) {
3473 struct cfg80211_assoc_failure data = {
3474 .timeout = status == ASSOC_TIMEOUT,
3478 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
3479 ARRAY_SIZE(assoc_data->link));
3481 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
3482 data.bss[i] = assoc_data->link[i].bss;
3484 if (sdata->vif.valid_links)
3485 data.ap_mld_addr = assoc_data->ap_addr;
3487 cfg80211_assoc_failure(sdata->dev, &data);
3490 ieee80211_vif_set_links(sdata, 0);
3494 sdata->u.mgd.assoc_data = NULL;
3497 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3498 struct ieee80211_mgmt *mgmt, size_t len)
3500 struct ieee80211_local *local = sdata->local;
3501 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3502 const struct element *challenge;
3505 struct ieee80211_prep_tx_info info = {
3506 .subtype = IEEE80211_STYPE_AUTH,
3509 pos = mgmt->u.auth.variable;
3510 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3511 len - (pos - (u8 *)mgmt));
3514 auth_data->expected_transaction = 4;
3515 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3516 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3517 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3518 IEEE80211_TX_INTFL_MLME_CONN_TX;
3519 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3521 challenge->datalen + sizeof(*challenge),
3522 auth_data->ap_addr, auth_data->ap_addr,
3523 auth_data->key, auth_data->key_len,
3524 auth_data->key_idx, tx_flags);
3527 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
3529 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3530 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
3531 struct sta_info *sta;
3534 sdata_info(sdata, "authenticated\n");
3535 ifmgd->auth_data->done = true;
3536 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3537 ifmgd->auth_data->timeout_started = true;
3538 run_again(sdata, ifmgd->auth_data->timeout);
3540 /* move station state to auth */
3541 mutex_lock(&sdata->local->sta_mtx);
3542 sta = sta_info_get(sdata, ap_addr);
3544 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3548 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3549 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3555 mutex_unlock(&sdata->local->sta_mtx);
3559 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3560 struct ieee80211_mgmt *mgmt, size_t len)
3562 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3563 u16 auth_alg, auth_transaction, status_code;
3564 struct ieee80211_event event = {
3566 .u.mlme.data = AUTH_EVENT,
3568 struct ieee80211_prep_tx_info info = {
3569 .subtype = IEEE80211_STYPE_AUTH,
3572 sdata_assert_lock(sdata);
3577 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3580 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
3583 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3584 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3585 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3587 if (auth_alg != ifmgd->auth_data->algorithm ||
3588 (auth_alg != WLAN_AUTH_SAE &&
3589 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3590 (auth_alg == WLAN_AUTH_SAE &&
3591 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3592 auth_transaction > 2))) {
3593 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3594 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3596 ifmgd->auth_data->expected_transaction);
3600 if (status_code != WLAN_STATUS_SUCCESS) {
3601 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3603 if (auth_alg == WLAN_AUTH_SAE &&
3604 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3605 (auth_transaction == 1 &&
3606 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3607 status_code == WLAN_STATUS_SAE_PK)))) {
3608 /* waiting for userspace now */
3609 ifmgd->auth_data->waiting = true;
3610 ifmgd->auth_data->timeout =
3611 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3612 ifmgd->auth_data->timeout_started = true;
3613 run_again(sdata, ifmgd->auth_data->timeout);
3617 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3618 mgmt->sa, status_code);
3619 ieee80211_destroy_auth_data(sdata, false);
3620 event.u.mlme.status = MLME_DENIED;
3621 event.u.mlme.reason = status_code;
3622 drv_event_callback(sdata->local, sdata, &event);
3626 switch (ifmgd->auth_data->algorithm) {
3627 case WLAN_AUTH_OPEN:
3628 case WLAN_AUTH_LEAP:
3631 case WLAN_AUTH_FILS_SK:
3632 case WLAN_AUTH_FILS_SK_PFS:
3633 case WLAN_AUTH_FILS_PK:
3635 case WLAN_AUTH_SHARED_KEY:
3636 if (ifmgd->auth_data->expected_transaction != 4) {
3637 ieee80211_auth_challenge(sdata, mgmt, len);
3638 /* need another frame */
3643 WARN_ONCE(1, "invalid auth alg %d",
3644 ifmgd->auth_data->algorithm);
3648 event.u.mlme.status = MLME_SUCCESS;
3650 drv_event_callback(sdata->local, sdata, &event);
3651 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3652 (auth_transaction == 2 &&
3653 ifmgd->auth_data->expected_transaction == 2)) {
3654 if (!ieee80211_mark_sta_auth(sdata))
3655 return; /* ignore frame -- wait for timeout */
3656 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3657 auth_transaction == 2) {
3658 sdata_info(sdata, "SAE peer confirmed\n");
3659 ifmgd->auth_data->peer_confirmed = true;
3662 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3664 drv_mgd_complete_tx(sdata->local, sdata, &info);
3667 #define case_WLAN(type) \
3668 case WLAN_REASON_##type: return #type
3670 const char *ieee80211_get_reason_code_string(u16 reason_code)
3672 switch (reason_code) {
3673 case_WLAN(UNSPECIFIED);
3674 case_WLAN(PREV_AUTH_NOT_VALID);
3675 case_WLAN(DEAUTH_LEAVING);
3676 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3677 case_WLAN(DISASSOC_AP_BUSY);
3678 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3679 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3680 case_WLAN(DISASSOC_STA_HAS_LEFT);
3681 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3682 case_WLAN(DISASSOC_BAD_POWER);
3683 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3684 case_WLAN(INVALID_IE);
3685 case_WLAN(MIC_FAILURE);
3686 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3687 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3688 case_WLAN(IE_DIFFERENT);
3689 case_WLAN(INVALID_GROUP_CIPHER);
3690 case_WLAN(INVALID_PAIRWISE_CIPHER);
3691 case_WLAN(INVALID_AKMP);
3692 case_WLAN(UNSUPP_RSN_VERSION);
3693 case_WLAN(INVALID_RSN_IE_CAP);
3694 case_WLAN(IEEE8021X_FAILED);
3695 case_WLAN(CIPHER_SUITE_REJECTED);
3696 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3697 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3698 case_WLAN(DISASSOC_LOW_ACK);
3699 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3700 case_WLAN(QSTA_LEAVE_QBSS);
3701 case_WLAN(QSTA_NOT_USE);
3702 case_WLAN(QSTA_REQUIRE_SETUP);
3703 case_WLAN(QSTA_TIMEOUT);
3704 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3705 case_WLAN(MESH_PEER_CANCELED);
3706 case_WLAN(MESH_MAX_PEERS);
3707 case_WLAN(MESH_CONFIG);
3708 case_WLAN(MESH_CLOSE);
3709 case_WLAN(MESH_MAX_RETRIES);
3710 case_WLAN(MESH_CONFIRM_TIMEOUT);
3711 case_WLAN(MESH_INVALID_GTK);
3712 case_WLAN(MESH_INCONSISTENT_PARAM);
3713 case_WLAN(MESH_INVALID_SECURITY);
3714 case_WLAN(MESH_PATH_ERROR);
3715 case_WLAN(MESH_PATH_NOFORWARD);
3716 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3717 case_WLAN(MAC_EXISTS_IN_MBSS);
3718 case_WLAN(MESH_CHAN_REGULATORY);
3719 case_WLAN(MESH_CHAN);
3720 default: return "<unknown>";
3724 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3725 struct ieee80211_mgmt *mgmt, size_t len)
3727 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3728 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3730 sdata_assert_lock(sdata);
3735 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3736 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3740 if (ifmgd->associated &&
3741 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
3742 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3743 sdata->vif.cfg.ap_addr, reason_code,
3744 ieee80211_get_reason_code_string(reason_code));
3746 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3748 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3749 reason_code, false);
3753 if (ifmgd->assoc_data &&
3754 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
3756 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3757 ifmgd->assoc_data->ap_addr, reason_code,
3758 ieee80211_get_reason_code_string(reason_code));
3760 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3762 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3768 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3769 struct ieee80211_mgmt *mgmt, size_t len)
3771 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3774 sdata_assert_lock(sdata);
3779 if (!ifmgd->associated ||
3780 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
3783 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3785 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3786 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3790 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3791 sdata->vif.cfg.ap_addr, reason_code,
3792 ieee80211_get_reason_code_string(reason_code));
3794 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3796 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3800 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3801 u8 *supp_rates, unsigned int supp_rates_len,
3802 u32 *rates, u32 *basic_rates,
3803 bool *have_higher_than_11mbit,
3804 int *min_rate, int *min_rate_index,
3809 for (i = 0; i < supp_rates_len; i++) {
3810 int rate = supp_rates[i] & 0x7f;
3811 bool is_basic = !!(supp_rates[i] & 0x80);
3813 if ((rate * 5 * (1 << shift)) > 110)
3814 *have_higher_than_11mbit = true;
3817 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3818 * since they're not rates.
3820 * Note: Even though the membership selector and the basic
3821 * rate flag share the same bit, they are not exactly
3824 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3825 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3826 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3827 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3830 for (j = 0; j < sband->n_bitrates; j++) {
3831 struct ieee80211_rate *br;
3834 br = &sband->bitrates[j];
3836 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3837 if (brate == rate) {
3840 *basic_rates |= BIT(j);
3841 if ((rate * 5) < *min_rate) {
3842 *min_rate = rate * 5;
3843 *min_rate_index = j;
3851 static bool ieee80211_twt_req_supported(const struct link_sta_info *link_sta,
3852 const struct ieee802_11_elems *elems)
3854 if (elems->ext_capab_len < 10)
3857 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3860 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3861 IEEE80211_HE_MAC_CAP0_TWT_RES;
3864 static int ieee80211_recalc_twt_req(struct ieee80211_link_data *link,
3865 struct link_sta_info *link_sta,
3866 struct ieee802_11_elems *elems)
3868 bool twt = ieee80211_twt_req_supported(link_sta, elems);
3870 if (link->conf->twt_requester != twt) {
3871 link->conf->twt_requester = twt;
3872 return BSS_CHANGED_TWT;
3877 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3878 struct ieee80211_bss_conf *bss_conf,
3879 struct ieee80211_supported_band *sband,
3880 struct link_sta_info *link_sta)
3882 const struct ieee80211_sta_he_cap *own_he_cap =
3883 ieee80211_get_he_iftype_cap(sband,
3884 ieee80211_vif_type_p2p(&sdata->vif));
3886 return bss_conf->he_support &&
3887 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3888 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3890 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3891 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3894 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
3895 struct link_sta_info *link_sta,
3896 struct cfg80211_bss *cbss,
3897 struct ieee80211_mgmt *mgmt,
3898 const u8 *elem_start,
3899 unsigned int elem_len,
3902 struct ieee80211_sub_if_data *sdata = link->sdata;
3903 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3904 struct ieee80211_bss_conf *bss_conf = link->conf;
3905 struct ieee80211_local *local = sdata->local;
3906 struct ieee80211_elems_parse_params parse_params = {
3907 .start = elem_start,
3910 .link_id = link == &sdata->deflink ? -1 : link->link_id,
3912 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3913 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3914 const struct cfg80211_bss_ies *bss_ies = NULL;
3915 struct ieee80211_supported_band *sband;
3916 struct ieee802_11_elems *elems;
3920 elems = ieee802_11_parse_elems_full(&parse_params);
3924 /* FIXME: use from STA profile element after parsing that */
3925 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3927 if (!is_s1g && !elems->supp_rates) {
3928 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3933 link->u.mgd.tdls_chan_switch_prohibited =
3934 elems->ext_capab && elems->ext_capab_len >= 5 &&
3935 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3938 * Some APs are erroneously not including some information in their
3939 * (re)association response frames. Try to recover by using the data
3940 * from the beacon or probe response. This seems to afflict mobile
3941 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3942 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3945 ((assoc_data->wmm && !elems->wmm_param) ||
3946 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
3947 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3948 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
3949 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3950 const struct cfg80211_bss_ies *ies;
3951 struct ieee802_11_elems *bss_elems;
3954 ies = rcu_dereference(cbss->ies);
3956 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3964 parse_params.start = bss_ies->data;
3965 parse_params.len = bss_ies->len;
3966 bss_elems = ieee802_11_parse_elems_full(&parse_params);
3972 if (assoc_data->wmm &&
3973 !elems->wmm_param && bss_elems->wmm_param) {
3974 elems->wmm_param = bss_elems->wmm_param;
3976 "AP bug: WMM param missing from AssocResp\n");
3980 * Also check if we requested HT/VHT, otherwise the AP doesn't
3981 * have to include the IEs in the (re)association response.
3983 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
3984 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
3985 elems->ht_cap_elem = bss_elems->ht_cap_elem;
3987 "AP bug: HT capability missing from AssocResp\n");
3989 if (!elems->ht_operation && bss_elems->ht_operation &&
3990 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
3991 elems->ht_operation = bss_elems->ht_operation;
3993 "AP bug: HT operation missing from AssocResp\n");
3995 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
3996 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
3997 elems->vht_cap_elem = bss_elems->vht_cap_elem;
3999 "AP bug: VHT capa missing from AssocResp\n");
4001 if (!elems->vht_operation && bss_elems->vht_operation &&
4002 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4003 elems->vht_operation = bss_elems->vht_operation;
4005 "AP bug: VHT operation missing from AssocResp\n");
4012 * We previously checked these in the beacon/probe response, so
4013 * they should be present here. This is just a safety net.
4015 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4016 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
4018 "HT AP is missing WMM params or HT capability/operation\n");
4023 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4024 (!elems->vht_cap_elem || !elems->vht_operation)) {
4026 "VHT AP is missing VHT capability/operation\n");
4031 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4032 !elems->he_6ghz_capa) {
4034 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
4039 sband = ieee80211_get_link_sband(link);
4045 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4046 (!elems->he_cap || !elems->he_operation)) {
4047 mutex_unlock(&sdata->local->sta_mtx);
4049 "HE AP is missing HE capability/operation\n");
4054 /* Set up internal HT/VHT capabilities */
4055 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
4056 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
4060 if (elems->vht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
4061 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4062 elems->vht_cap_elem,
4065 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4067 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
4070 elems->he_6ghz_capa,
4073 bss_conf->he_support = link_sta->pub->he_cap.has_he;
4074 if (elems->rsnx && elems->rsnx_len &&
4075 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
4076 wiphy_ext_feature_isset(local->hw.wiphy,
4077 NL80211_EXT_FEATURE_PROTECTED_TWT))
4078 bss_conf->twt_protected = true;
4080 bss_conf->twt_protected = false;
4082 *changed |= ieee80211_recalc_twt_req(link, link_sta, elems);
4084 if (elems->eht_operation && elems->eht_cap &&
4085 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
4086 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
4093 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
4095 bss_conf->eht_support = false;
4098 bss_conf->he_support = false;
4099 bss_conf->twt_requester = false;
4100 bss_conf->twt_protected = false;
4101 bss_conf->eht_support = false;
4104 bss_conf->twt_broadcast =
4105 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
4107 if (bss_conf->he_support) {
4108 bss_conf->he_bss_color.color =
4109 le32_get_bits(elems->he_operation->he_oper_params,
4110 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
4111 bss_conf->he_bss_color.partial =
4112 le32_get_bits(elems->he_operation->he_oper_params,
4113 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
4114 bss_conf->he_bss_color.enabled =
4115 !le32_get_bits(elems->he_operation->he_oper_params,
4116 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
4118 if (bss_conf->he_bss_color.enabled)
4119 *changed |= BSS_CHANGED_HE_BSS_COLOR;
4121 bss_conf->htc_trig_based_pkt_ext =
4122 le32_get_bits(elems->he_operation->he_oper_params,
4123 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
4124 bss_conf->frame_time_rts_th =
4125 le32_get_bits(elems->he_operation->he_oper_params,
4126 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
4128 bss_conf->uora_exists = !!elems->uora_element;
4129 if (elems->uora_element)
4130 bss_conf->uora_ocw_range = elems->uora_element[0];
4132 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
4133 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
4134 /* TODO: OPEN: what happens if BSS color disable is set? */
4137 if (cbss->transmitted_bss) {
4138 bss_conf->nontransmitted = true;
4139 ether_addr_copy(bss_conf->transmitter_bssid,
4140 cbss->transmitted_bss->bssid);
4141 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
4142 bss_conf->bssid_index = cbss->bssid_index;
4146 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
4147 * in their association response, so ignore that data for our own
4148 * configuration. If it changed since the last beacon, we'll get the
4149 * next beacon and update then.
4153 * If an operating mode notification IE is present, override the
4154 * NSS calculation (that would be done in rate_control_rate_init())
4155 * and use the # of streams from that element.
4157 if (elems->opmode_notif &&
4158 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
4161 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
4162 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
4164 link_sta->pub->rx_nss = nss;
4168 * Always handle WMM once after association regardless
4169 * of the first value the AP uses. Setting -1 here has
4170 * that effect because the AP values is an unsigned
4173 link->u.mgd.wmm_last_param_set = -1;
4174 link->u.mgd.mu_edca_last_param_set = -1;
4176 if (link->u.mgd.disable_wmm_tracking) {
4177 ieee80211_set_wmm_default(link, false, false);
4178 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4179 elems->wmm_param_len,
4180 elems->mu_edca_param_set)) {
4181 /* still enable QoS since we might have HT/VHT */
4182 ieee80211_set_wmm_default(link, false, true);
4183 /* disable WMM tracking in this case to disable
4184 * tracking WMM parameter changes in the beacon if
4185 * the parameters weren't actually valid. Doing so
4186 * avoids changing parameters very strangely when
4187 * the AP is going back and forth between valid and
4188 * invalid parameters.
4190 link->u.mgd.disable_wmm_tracking = true;
4193 if (elems->max_idle_period_ie) {
4194 bss_conf->max_idle_period =
4195 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
4196 bss_conf->protected_keep_alive =
4197 !!(elems->max_idle_period_ie->idle_options &
4198 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
4199 *changed |= BSS_CHANGED_KEEP_ALIVE;
4201 bss_conf->max_idle_period = 0;
4202 bss_conf->protected_keep_alive = false;
4205 /* set assoc capability (AID was already set earlier),
4206 * ieee80211_set_associated() will tell the driver */
4207 bss_conf->assoc_capability = capab_info;
4216 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
4217 struct sta_info *sta,
4218 struct ieee80211_link_sta *link_sta,
4219 struct cfg80211_bss *cbss)
4221 struct ieee80211_sub_if_data *sdata = link->sdata;
4222 struct ieee80211_local *local = sdata->local;
4223 struct ieee80211_bss *bss = (void *)cbss->priv;
4224 u32 rates = 0, basic_rates = 0;
4225 bool have_higher_than_11mbit = false;
4226 int min_rate = INT_MAX, min_rate_index = -1;
4227 /* this is clearly wrong for MLO but we'll just remove it later */
4228 int shift = ieee80211_vif_get_shift(&sdata->vif);
4229 struct ieee80211_supported_band *sband;
4231 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
4233 /* TODO: S1G Basic Rate Set is expressed elsewhere */
4234 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
4235 ieee80211_s1g_sta_rate_init(sta);
4239 sband = local->hw.wiphy->bands[cbss->channel->band];
4241 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
4242 &rates, &basic_rates, &have_higher_than_11mbit,
4243 &min_rate, &min_rate_index, shift);
4246 * This used to be a workaround for basic rates missing
4247 * in the association response frame. Now that we no
4248 * longer use the basic rates from there, it probably
4249 * doesn't happen any more, but keep the workaround so
4250 * in case some *other* APs are buggy in different ways
4251 * we can connect -- with a warning.
4252 * Allow this workaround only in case the AP provided at least
4255 if (min_rate_index < 0) {
4256 link_info(link, "No legacy rates in association response\n");
4258 } else if (!basic_rates) {
4259 link_info(link, "No basic rates, using min rate instead\n");
4260 basic_rates = BIT(min_rate_index);
4264 link_sta->supp_rates[cbss->channel->band] = rates;
4266 link_info(link, "No rates found, keeping mandatory only\n");
4268 link->conf->basic_rates = basic_rates;
4270 /* cf. IEEE 802.11 9.2.12 */
4271 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
4272 have_higher_than_11mbit;
4277 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
4278 struct cfg80211_bss *cbss)
4280 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4281 const struct element *ht_cap_elem, *vht_cap_elem;
4282 const struct cfg80211_bss_ies *ies;
4283 const struct ieee80211_ht_cap *ht_cap;
4284 const struct ieee80211_vht_cap *vht_cap;
4285 const struct ieee80211_he_cap_elem *he_cap;
4286 const struct element *he_cap_elem;
4287 u16 mcs_80_map, mcs_160_map;
4288 int i, mcs_nss_size;
4292 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
4295 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4296 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4297 ht_cap = (void *)ht_cap_elem->data;
4298 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4300 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4301 * "Tx Unequal Modulation Supported" fields.
4305 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
4308 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4309 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4313 vht_cap = (void *)vht_cap_elem->data;
4314 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4315 for (nss = 8; nss > 0; nss--) {
4316 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4317 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4320 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4321 chains = max(chains, nss);
4324 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
4327 ies = rcu_dereference(cbss->ies);
4328 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4329 ies->data, ies->len);
4331 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
4334 /* skip one byte ext_tag_id */
4335 he_cap = (void *)(he_cap_elem->data + 1);
4336 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4339 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
4342 /* mcs_nss is right after he_cap info */
4343 he_mcs_nss_supp = (void *)(he_cap + 1);
4345 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4347 for (i = 7; i >= 0; i--) {
4348 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
4350 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4351 chains = max_t(u8, chains, i + 1);
4356 support_160 = he_cap->phy_cap_info[0] &
4357 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
4362 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
4363 for (i = 7; i >= 0; i--) {
4364 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
4366 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4367 chains = max_t(u8, chains, i + 1);
4376 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4377 const struct cfg80211_bss_ies *ies,
4378 const struct ieee80211_he_operation *he_op)
4380 const struct element *he_cap_elem;
4381 const struct ieee80211_he_cap_elem *he_cap;
4382 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4383 u16 mcs_80_map_tx, mcs_80_map_rx;
4388 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4389 ies->data, ies->len);
4392 if (!he_cap_elem || he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
4394 "Invalid HE elem, Disable HE\n");
4398 /* skip one byte ext_tag_id */
4399 he_cap = (void *)(he_cap_elem->data + 1);
4400 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4403 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
4405 "Invalid HE elem with nss size, Disable HE\n");
4409 /* mcs_nss is right after he_cap info */
4410 he_mcs_nss_supp = (void *)(he_cap + 1);
4412 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4413 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
4415 /* P802.11-REVme/D0.3
4416 * 27.1.1 Introduction to the HE PHY
4418 * An HE STA shall support the following features:
4420 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
4421 * supported channel widths for HE SU PPDUs
4423 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4424 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
4426 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
4427 mcs_80_map_tx, mcs_80_map_rx);
4434 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4437 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4438 * zeroes, which is nonsense, and completely inconsistent with itself
4439 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4441 if (!ap_min_req_set)
4444 /* make sure the AP is consistent with itself
4446 * P802.11-REVme/D0.3
4447 * 26.17.1 Basic HE BSS operation
4449 * A STA that is operating in an HE BSS shall be able to receive and
4450 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
4451 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
4452 * MLME-START.request primitive and shall be able to receive at each of
4453 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
4454 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
4457 for (nss = 8; nss > 0; nss--) {
4458 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4462 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4465 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
4466 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
4468 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4469 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4470 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
4472 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
4473 nss, ap_rx_val, ap_rx_val, ap_op_val);
4482 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4483 struct ieee80211_supported_band *sband,
4484 const struct ieee80211_he_operation *he_op)
4486 const struct ieee80211_sta_he_cap *sta_he_cap =
4487 ieee80211_get_he_iftype_cap(sband,
4488 ieee80211_vif_type_p2p(&sdata->vif));
4492 if (!sta_he_cap || !he_op)
4495 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4498 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4499 * zeroes, which is nonsense, and completely inconsistent with itself
4500 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4502 if (!ap_min_req_set)
4505 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4506 for (i = 0; i < 3; i++) {
4507 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4508 &sta_he_cap->he_mcs_nss_supp;
4509 u16 sta_mcs_map_rx =
4510 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4511 u16 sta_mcs_map_tx =
4512 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4514 bool verified = true;
4517 * For each band there is a maximum of 8 spatial streams
4518 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4519 * of 2 bits per NSS (1-8), with the values defined in enum
4520 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4521 * capabilities aren't less than the AP's minimum requirements
4522 * for this HE BSS per SS.
4523 * It is enough to find one such band that meets the reqs.
4525 for (nss = 8; nss > 0; nss--) {
4526 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4527 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4528 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4530 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4534 * Make sure the HE AP doesn't require MCSs that aren't
4535 * supported by the client as required by spec
4537 * P802.11-REVme/D0.3
4538 * 26.17.1 Basic HE BSS operation
4540 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
4541 * a BSS, unless it supports (i.e., is able to both transmit and
4542 * receive using) all of the <HE-MCS, NSS> tuples in the basic
4543 * HE-MCS and NSS set.
4545 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4546 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4547 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4557 /* If here, STA doesn't meet AP's HE min requirements */
4561 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4562 struct ieee80211_link_data *link,
4563 struct cfg80211_bss *cbss,
4564 ieee80211_conn_flags_t *conn_flags)
4566 struct ieee80211_local *local = sdata->local;
4567 const struct ieee80211_ht_cap *ht_cap = NULL;
4568 const struct ieee80211_ht_operation *ht_oper = NULL;
4569 const struct ieee80211_vht_operation *vht_oper = NULL;
4570 const struct ieee80211_he_operation *he_oper = NULL;
4571 const struct ieee80211_eht_operation *eht_oper = NULL;
4572 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4573 struct ieee80211_supported_band *sband;
4574 struct cfg80211_chan_def chandef;
4575 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4576 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4577 struct ieee80211_bss *bss = (void *)cbss->priv;
4578 struct ieee802_11_elems *elems;
4579 const struct cfg80211_bss_ies *ies;
4586 ies = rcu_dereference(cbss->ies);
4587 elems = ieee802_11_parse_elems(ies->data, ies->len, false, cbss);
4593 sband = local->hw.wiphy->bands[cbss->channel->band];
4595 *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
4596 IEEE80211_CONN_DISABLE_80P80MHZ |
4597 IEEE80211_CONN_DISABLE_160MHZ);
4599 /* disable HT/VHT/HE if we don't support them */
4600 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4601 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
4602 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4603 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4604 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4605 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4608 if (!sband->vht_cap.vht_supported && is_5ghz) {
4609 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
4610 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4611 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4612 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4615 if (!ieee80211_get_he_iftype_cap(sband,
4616 ieee80211_vif_type_p2p(&sdata->vif))) {
4617 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
4618 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4619 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4622 if (!ieee80211_get_eht_iftype_cap(sband,
4623 ieee80211_vif_type_p2p(&sdata->vif))) {
4624 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
4625 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4628 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
4629 ht_oper = elems->ht_operation;
4630 ht_cap = elems->ht_cap_elem;
4633 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4638 if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
4639 vht_oper = elems->vht_operation;
4640 if (vht_oper && !ht_oper) {
4643 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
4644 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4645 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4646 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4647 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4650 if (!elems->vht_cap_elem) {
4652 "bad VHT capabilities, disabling VHT\n");
4653 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4658 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
4659 he_oper = elems->he_operation;
4661 if (link && is_6ghz) {
4662 struct ieee80211_bss_conf *bss_conf;
4665 bss_conf = link->conf;
4667 if (elems->pwr_constr_elem)
4668 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
4670 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
4671 ARRAY_SIZE(elems->tx_pwr_env));
4673 for (i = 0; i < elems->tx_pwr_env_num; i++) {
4674 if (elems->tx_pwr_env_len[i] >
4675 sizeof(bss_conf->tx_pwr_env[j]))
4678 bss_conf->tx_pwr_env_num++;
4679 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
4680 elems->tx_pwr_env_len[i]);
4685 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
4686 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
4687 *conn_flags |= IEEE80211_CONN_DISABLE_HE |
4688 IEEE80211_CONN_DISABLE_EHT;
4692 * EHT requires HE to be supported as well. Specifically for 6 GHz
4693 * channels, the operation channel information can only be deduced from
4694 * both the 6 GHz operation information (from the HE operation IE) and
4698 (IEEE80211_CONN_DISABLE_HE |
4699 IEEE80211_CONN_DISABLE_EHT)) &&
4701 const struct cfg80211_bss_ies *cbss_ies;
4702 const u8 *eht_oper_ie;
4704 cbss_ies = rcu_dereference(cbss->ies);
4705 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
4706 cbss_ies->data, cbss_ies->len);
4707 if (eht_oper_ie && eht_oper_ie[1] >=
4708 1 + sizeof(struct ieee80211_eht_operation))
4709 eht_oper = (void *)(eht_oper_ie + 3);
4714 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4716 for (i = 0; i < sband->n_channels; i++) {
4717 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4718 IEEE80211_CHAN_NO_80MHZ))
4726 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
4727 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4730 if (sband->band == NL80211_BAND_S1GHZ) {
4731 s1g_oper = elems->s1g_oper;
4734 "AP missing S1G operation element?\n");
4738 ieee80211_determine_chantype(sdata, link, *conn_flags,
4748 link->needed_rx_chains =
4749 min(ieee80211_max_rx_chains(link, cbss),
4753 /* the element data was RCU protected so no longer valid anyway */
4757 if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
4758 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
4765 /* will change later if needed */
4766 link->smps_mode = IEEE80211_SMPS_OFF;
4768 mutex_lock(&local->mtx);
4770 * If this fails (possibly due to channel context sharing
4771 * on incompatible channels, e.g. 80+80 and 160 sharing the
4772 * same control channel) try to use a smaller bandwidth.
4774 ret = ieee80211_link_use_channel(link, &chandef,
4775 IEEE80211_CHANCTX_SHARED);
4777 /* don't downgrade for 5 and 10 MHz channels, though. */
4778 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4779 chandef.width == NL80211_CHAN_WIDTH_10)
4782 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4784 ieee80211_chandef_downgrade(&chandef);
4785 ret = ieee80211_link_use_channel(link, &chandef,
4786 IEEE80211_CHANCTX_SHARED);
4789 mutex_unlock(&local->mtx);
4793 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
4794 struct ieee80211_mgmt *mgmt,
4795 struct ieee802_11_elems *elems,
4796 const u8 *elem_start, unsigned int elem_len)
4798 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4799 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
4800 struct ieee80211_local *local = sdata->local;
4801 unsigned int link_id;
4802 struct sta_info *sta;
4803 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
4806 mutex_lock(&sdata->local->sta_mtx);
4808 * station info was already allocated and inserted before
4809 * the association and should be available to us
4811 sta = sta_info_get(sdata, assoc_data->ap_addr);
4815 if (sdata->vif.valid_links) {
4816 u16 valid_links = 0;
4818 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
4819 if (!assoc_data->link[link_id].bss)
4821 valid_links |= BIT(link_id);
4823 if (link_id != assoc_data->assoc_link_id) {
4824 err = ieee80211_sta_allocate_link(sta, link_id);
4830 ieee80211_vif_set_links(sdata, valid_links);
4833 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
4834 struct ieee80211_link_data *link;
4835 struct link_sta_info *link_sta;
4837 if (!assoc_data->link[link_id].bss)
4840 link = sdata_dereference(sdata->link[link_id], sdata);
4844 if (sdata->vif.valid_links)
4846 "local address %pM, AP link address %pM\n",
4848 assoc_data->link[link_id].bss->bssid);
4850 link_sta = rcu_dereference_protected(sta->link[link_id],
4851 lockdep_is_held(&local->sta_mtx));
4852 if (WARN_ON(!link_sta))
4855 if (link_id != assoc_data->assoc_link_id) {
4856 err = ieee80211_prep_channel(sdata, link,
4857 assoc_data->link[link_id].bss,
4858 &link->u.mgd.conn_flags);
4863 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta->pub,
4864 assoc_data->link[link_id].bss);
4868 if (!ieee80211_assoc_config_link(link, link_sta,
4869 assoc_data->link[link_id].bss,
4870 mgmt, elem_start, elem_len,
4874 if (link_id != assoc_data->assoc_link_id) {
4875 err = ieee80211_sta_activate_link(sta, link_id);
4881 rate_control_rate_init(sta);
4883 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
4884 set_sta_flag(sta, WLAN_STA_MFP);
4885 sta->sta.mfp = true;
4887 sta->sta.mfp = false;
4890 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
4891 elems->ext_capab_len);
4893 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
4894 local->hw.queues >= IEEE80211_NUM_ACS;
4896 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
4897 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
4898 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
4901 "failed to move station %pM to desired state\n",
4903 WARN_ON(__sta_info_destroy(sta));
4907 if (sdata->wdev.use_4addr)
4908 drv_sta_set_4addr(local, sdata, &sta->sta, true);
4910 mutex_unlock(&sdata->local->sta_mtx);
4912 ieee80211_set_associated(sdata, assoc_data, changed);
4915 * If we're using 4-addr mode, let the AP know that we're
4916 * doing so, so that it can create the STA VLAN on its side
4918 if (ifmgd->use_4addr)
4919 ieee80211_send_4addr_nullfunc(local, sdata);
4922 * Start timer to probe the connection to the AP now.
4923 * Also start the timer that will detect beacon loss.
4925 ieee80211_sta_reset_beacon_monitor(sdata);
4926 ieee80211_sta_reset_conn_monitor(sdata);
4930 mutex_unlock(&sdata->local->sta_mtx);
4934 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
4935 struct ieee80211_mgmt *mgmt,
4938 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4939 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
4940 u16 capab_info, status_code, aid;
4941 struct ieee802_11_elems *elems;
4943 const u8 *elem_start;
4944 unsigned int elem_len;
4946 struct ieee80211_event event = {
4948 .u.mlme.data = ASSOC_EVENT,
4950 struct ieee80211_prep_tx_info info = {};
4951 struct cfg80211_rx_assoc_resp resp = {
4954 unsigned int link_id;
4956 sdata_assert_lock(sdata);
4961 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
4962 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
4966 * AssocResp and ReassocResp have identical structure, so process both
4967 * of them in this function.
4973 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
4974 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
4975 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
4976 if (assoc_data->s1g)
4977 elem_start = mgmt->u.s1g_assoc_resp.variable;
4979 elem_start = mgmt->u.assoc_resp.variable;
4982 * Note: this may not be perfect, AP might misbehave - if
4983 * anyone needs to rely on perfect complete notification
4984 * with the exact right subtype, then we need to track what
4985 * we actually transmitted.
4987 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
4988 IEEE80211_STYPE_ASSOC_REQ;
4990 if (assoc_data->fils_kek_len &&
4991 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
4994 elem_len = len - (elem_start - (u8 *)mgmt);
4995 elems = ieee802_11_parse_elems(elem_start, elem_len, false, NULL);
4999 if (elems->aid_resp)
5000 aid = le16_to_cpu(elems->aid_resp->aid);
5001 else if (assoc_data->s1g)
5004 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
5007 * The 5 MSB of the AID field are reserved
5008 * (802.11-2016 9.4.1.8 AID field)
5013 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
5014 reassoc ? "Rea" : "A", assoc_data->ap_addr,
5015 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
5017 ifmgd->broken_ap = false;
5019 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
5020 elems->timeout_int &&
5021 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
5024 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
5025 le32_to_cpu(elems->timeout_int->value));
5027 tu = le32_to_cpu(elems->timeout_int->value);
5028 ms = tu * 1024 / 1000;
5030 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
5031 assoc_data->ap_addr, tu, ms);
5032 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
5033 assoc_data->timeout_started = true;
5034 if (ms > IEEE80211_ASSOC_TIMEOUT)
5035 run_again(sdata, assoc_data->timeout);
5039 if (status_code != WLAN_STATUS_SUCCESS) {
5040 sdata_info(sdata, "%pM denied association (code=%d)\n",
5041 assoc_data->ap_addr, status_code);
5042 event.u.mlme.status = MLME_DENIED;
5043 event.u.mlme.reason = status_code;
5044 drv_event_callback(sdata->local, sdata, &event);
5046 if (aid == 0 || aid > IEEE80211_MAX_AID) {
5048 "invalid AID value %d (out of range), turn off PS\n",
5051 ifmgd->broken_ap = true;
5054 if (sdata->vif.valid_links) {
5055 if (!elems->multi_link) {
5057 "MLO association with %pM but no multi-link element in response!\n",
5058 assoc_data->ap_addr);
5062 if (le16_get_bits(elems->multi_link->control,
5063 IEEE80211_ML_CONTROL_TYPE) !=
5064 IEEE80211_ML_CONTROL_TYPE_BASIC) {
5066 "bad multi-link element (control=0x%x)\n",
5067 le16_to_cpu(elems->multi_link->control));
5070 struct ieee80211_mle_basic_common_info *common;
5072 common = (void *)elems->multi_link->variable;
5074 if (memcmp(assoc_data->ap_addr,
5075 common->mld_mac_addr, ETH_ALEN)) {
5077 "AP MLD MAC address mismatch: got %pM expected %pM\n",
5078 common->mld_mac_addr,
5079 assoc_data->ap_addr);
5085 sdata->vif.cfg.aid = aid;
5087 if (!ieee80211_assoc_success(sdata, mgmt, elems,
5088 elem_start, elem_len)) {
5089 /* oops -- internal error -- send timeout for now */
5090 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5093 event.u.mlme.status = MLME_SUCCESS;
5094 drv_event_callback(sdata->local, sdata, &event);
5095 sdata_info(sdata, "associated\n");
5100 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5101 struct ieee80211_link_data *link;
5103 link = sdata_dereference(sdata->link[link_id], sdata);
5106 if (!assoc_data->link[link_id].bss)
5108 resp.links[link_id].bss = assoc_data->link[link_id].bss;
5109 resp.links[link_id].addr = link->conf->addr;
5111 /* get uapsd queues configuration - same for all links */
5112 resp.uapsd_queues = 0;
5113 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
5114 if (link->tx_conf[ac].uapsd)
5115 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
5118 ieee80211_destroy_assoc_data(sdata,
5119 status_code == WLAN_STATUS_SUCCESS ?
5123 resp.buf = (u8 *)mgmt;
5125 resp.req_ies = ifmgd->assoc_req_ies;
5126 resp.req_ies_len = ifmgd->assoc_req_ies_len;
5127 if (sdata->vif.valid_links)
5128 resp.ap_mld_addr = assoc_data->ap_addr;
5129 cfg80211_rx_assoc_resp(sdata->dev, &resp);
5131 drv_mgd_complete_tx(sdata->local, sdata, &info);
5135 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5139 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
5140 struct ieee80211_mgmt *mgmt, size_t len,
5141 struct ieee80211_rx_status *rx_status)
5143 struct ieee80211_sub_if_data *sdata = link->sdata;
5144 struct ieee80211_local *local = sdata->local;
5145 struct ieee80211_bss *bss;
5146 struct ieee80211_channel *channel;
5148 sdata_assert_lock(sdata);
5150 channel = ieee80211_get_channel_khz(local->hw.wiphy,
5151 ieee80211_rx_status_to_khz(rx_status));
5155 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
5157 link->conf->beacon_rate = bss->beacon_rate;
5158 ieee80211_rx_bss_put(local, bss);
5163 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
5164 struct sk_buff *skb)
5166 struct ieee80211_sub_if_data *sdata = link->sdata;
5167 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5168 struct ieee80211_if_managed *ifmgd;
5169 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
5170 struct ieee80211_channel *channel;
5171 size_t baselen, len = skb->len;
5173 ifmgd = &sdata->u.mgd;
5175 sdata_assert_lock(sdata);
5178 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
5179 * "If a 6 GHz AP receives a Probe Request frame and responds with
5180 * a Probe Response frame [..], the Address 1 field of the Probe
5181 * Response frame shall be set to the broadcast address [..]"
5182 * So, on 6GHz band we should also accept broadcast responses.
5184 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
5189 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
5190 (channel->band != NL80211_BAND_6GHZ ||
5191 !is_broadcast_ether_addr(mgmt->da)))
5192 return; /* ignore ProbeResp to foreign address */
5194 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
5198 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5200 if (ifmgd->associated &&
5201 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
5202 ieee80211_reset_ap_probe(sdata);
5206 * This is the canonical list of information elements we care about,
5207 * the filter code also gives us all changes to the Microsoft OUI
5208 * (00:50:F2) vendor IE which is used for WMM which we need to track,
5209 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
5210 * changes to requested client power.
5212 * We implement beacon filtering in software since that means we can
5213 * avoid processing the frame here and in cfg80211, and userspace
5214 * will not be able to tell whether the hardware supports it or not.
5216 * XXX: This list needs to be dynamic -- userspace needs to be able to
5217 * add items it requires. It also needs to be able to tell us to
5218 * look out for other vendor IEs.
5220 static const u64 care_about_ies =
5221 (1ULL << WLAN_EID_COUNTRY) |
5222 (1ULL << WLAN_EID_ERP_INFO) |
5223 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
5224 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
5225 (1ULL << WLAN_EID_HT_CAPABILITY) |
5226 (1ULL << WLAN_EID_HT_OPERATION) |
5227 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
5229 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
5230 struct ieee80211_if_managed *ifmgd,
5231 struct ieee80211_bss_conf *bss_conf,
5232 struct ieee80211_local *local,
5233 struct ieee80211_rx_status *rx_status)
5235 struct ieee80211_sub_if_data *sdata = link->sdata;
5237 /* Track average RSSI from the Beacon frames of the current AP */
5239 if (!link->u.mgd.tracking_signal_avg) {
5240 link->u.mgd.tracking_signal_avg = true;
5241 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
5242 link->u.mgd.last_cqm_event_signal = 0;
5243 link->u.mgd.count_beacon_signal = 1;
5244 link->u.mgd.last_ave_beacon_signal = 0;
5246 link->u.mgd.count_beacon_signal++;
5249 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
5250 -rx_status->signal);
5252 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
5253 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5254 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5255 int last_sig = link->u.mgd.last_ave_beacon_signal;
5256 struct ieee80211_event event = {
5261 * if signal crosses either of the boundaries, invoke callback
5262 * with appropriate parameters
5264 if (sig > ifmgd->rssi_max_thold &&
5265 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
5266 link->u.mgd.last_ave_beacon_signal = sig;
5267 event.u.rssi.data = RSSI_EVENT_HIGH;
5268 drv_event_callback(local, sdata, &event);
5269 } else if (sig < ifmgd->rssi_min_thold &&
5270 (last_sig >= ifmgd->rssi_max_thold ||
5272 link->u.mgd.last_ave_beacon_signal = sig;
5273 event.u.rssi.data = RSSI_EVENT_LOW;
5274 drv_event_callback(local, sdata, &event);
5278 if (bss_conf->cqm_rssi_thold &&
5279 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
5280 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
5281 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5282 int last_event = link->u.mgd.last_cqm_event_signal;
5283 int thold = bss_conf->cqm_rssi_thold;
5284 int hyst = bss_conf->cqm_rssi_hyst;
5287 (last_event == 0 || sig < last_event - hyst)) {
5288 link->u.mgd.last_cqm_event_signal = sig;
5289 ieee80211_cqm_rssi_notify(
5291 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5293 } else if (sig > thold &&
5294 (last_event == 0 || sig > last_event + hyst)) {
5295 link->u.mgd.last_cqm_event_signal = sig;
5296 ieee80211_cqm_rssi_notify(
5298 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5303 if (bss_conf->cqm_rssi_low &&
5304 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5305 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5306 int last_event = link->u.mgd.last_cqm_event_signal;
5307 int low = bss_conf->cqm_rssi_low;
5308 int high = bss_conf->cqm_rssi_high;
5311 (last_event == 0 || last_event >= low)) {
5312 link->u.mgd.last_cqm_event_signal = sig;
5313 ieee80211_cqm_rssi_notify(
5315 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5317 } else if (sig > high &&
5318 (last_event == 0 || last_event <= high)) {
5319 link->u.mgd.last_cqm_event_signal = sig;
5320 ieee80211_cqm_rssi_notify(
5322 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5328 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
5329 struct cfg80211_bss *bss)
5331 if (ether_addr_equal(tx_bssid, bss->bssid))
5333 if (!bss->transmitted_bss)
5335 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
5338 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
5339 struct ieee80211_hdr *hdr, size_t len,
5340 struct ieee80211_rx_status *rx_status)
5342 struct ieee80211_sub_if_data *sdata = link->sdata;
5343 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5344 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5345 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
5346 struct ieee80211_mgmt *mgmt = (void *) hdr;
5348 struct ieee802_11_elems *elems;
5349 struct ieee80211_local *local = sdata->local;
5350 struct ieee80211_chanctx_conf *chanctx_conf;
5351 struct ieee80211_channel *chan;
5352 struct link_sta_info *link_sta;
5353 struct sta_info *sta;
5358 u8 *bssid, *variable = mgmt->u.beacon.variable;
5359 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
5361 sdata_assert_lock(sdata);
5363 /* Process beacon from the current BSS */
5364 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
5365 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
5366 struct ieee80211_ext *ext = (void *) mgmt;
5368 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
5369 variable = ext->u.s1g_short_beacon.variable;
5371 variable = ext->u.s1g_beacon.variable;
5374 baselen = (u8 *) variable - (u8 *) mgmt;
5379 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
5380 if (!chanctx_conf) {
5385 if (ieee80211_rx_status_to_khz(rx_status) !=
5386 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
5390 chan = chanctx_conf->def.chan;
5393 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
5394 !WARN_ON(sdata->vif.valid_links) &&
5395 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
5396 elems = ieee802_11_parse_elems(variable, len - baselen, false,
5397 ifmgd->assoc_data->link[0].bss);
5401 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5403 if (elems->dtim_period)
5404 link->u.mgd.dtim_period = elems->dtim_period;
5405 link->u.mgd.have_beacon = true;
5406 ifmgd->assoc_data->need_beacon = false;
5407 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5408 link->conf->sync_tsf =
5409 le64_to_cpu(mgmt->u.beacon.timestamp);
5410 link->conf->sync_device_ts =
5411 rx_status->device_timestamp;
5412 link->conf->sync_dtim_count = elems->dtim_count;
5415 if (elems->mbssid_config_ie)
5416 bss_conf->profile_periodicity =
5417 elems->mbssid_config_ie->profile_periodicity;
5419 bss_conf->profile_periodicity = 0;
5421 if (elems->ext_capab_len >= 11 &&
5422 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5423 bss_conf->ema_ap = true;
5425 bss_conf->ema_ap = false;
5427 /* continue assoc process */
5428 ifmgd->assoc_data->timeout = jiffies;
5429 ifmgd->assoc_data->timeout_started = true;
5430 run_again(sdata, ifmgd->assoc_data->timeout);
5435 if (!ifmgd->associated ||
5436 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
5438 bssid = link->u.mgd.bssid;
5440 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
5441 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
5444 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
5445 mlme_dbg_ratelimited(sdata,
5446 "cancelling AP probe due to a received beacon\n");
5447 ieee80211_reset_ap_probe(sdata);
5451 * Push the beacon loss detection into the future since
5452 * we are processing a beacon from the AP just now.
5454 ieee80211_sta_reset_beacon_monitor(sdata);
5456 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
5457 * element (which carries the beacon interval). Don't forget to add a
5458 * bit to care_about_ies[] above if mac80211 is interested in a
5459 * changing S1G element.
5461 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5462 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
5463 elems = ieee802_11_parse_elems_crc(variable, len - baselen,
5464 false, care_about_ies, ncrc,
5470 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
5471 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
5472 if (local->hw.conf.dynamic_ps_timeout > 0) {
5473 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
5474 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
5475 ieee80211_hw_config(local,
5476 IEEE80211_CONF_CHANGE_PS);
5478 ieee80211_send_nullfunc(local, sdata, false);
5479 } else if (!local->pspolling && sdata->u.mgd.powersave) {
5480 local->pspolling = true;
5483 * Here is assumed that the driver will be
5484 * able to send ps-poll frame and receive a
5485 * response even though power save mode is
5486 * enabled, but some drivers might require
5487 * to disable power save here. This needs
5488 * to be investigated.
5490 ieee80211_send_pspoll(local, sdata);
5494 if (sdata->vif.p2p ||
5495 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
5496 struct ieee80211_p2p_noa_attr noa = {};
5499 ret = cfg80211_get_p2p_attr(variable,
5501 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
5502 (u8 *) &noa, sizeof(noa));
5504 if (link->u.mgd.p2p_noa_index != noa.index) {
5505 /* valid noa_attr and index changed */
5506 link->u.mgd.p2p_noa_index = noa.index;
5507 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
5508 changed |= BSS_CHANGED_P2P_PS;
5510 * make sure we update all information, the CRC
5511 * mechanism doesn't look at P2P attributes.
5513 link->u.mgd.beacon_crc_valid = false;
5515 } else if (link->u.mgd.p2p_noa_index != -1) {
5516 /* noa_attr not found and we had valid noa_attr before */
5517 link->u.mgd.p2p_noa_index = -1;
5518 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
5519 changed |= BSS_CHANGED_P2P_PS;
5520 link->u.mgd.beacon_crc_valid = false;
5524 if (link->u.mgd.csa_waiting_bcn)
5525 ieee80211_chswitch_post_beacon(link);
5528 * Update beacon timing and dtim count on every beacon appearance. This
5529 * will allow the driver to use the most updated values. Do it before
5530 * comparing this one with last received beacon.
5531 * IMPORTANT: These parameters would possibly be out of sync by the time
5532 * the driver will use them. The synchronized view is currently
5533 * guaranteed only in certain callbacks.
5535 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
5536 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
5537 link->conf->sync_tsf =
5538 le64_to_cpu(mgmt->u.beacon.timestamp);
5539 link->conf->sync_device_ts =
5540 rx_status->device_timestamp;
5541 link->conf->sync_dtim_count = elems->dtim_count;
5544 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
5545 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
5547 link->u.mgd.beacon_crc = ncrc;
5548 link->u.mgd.beacon_crc_valid = true;
5550 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5552 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
5553 rx_status->device_timestamp,
5556 if (!link->u.mgd.disable_wmm_tracking &&
5557 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
5558 elems->wmm_param_len,
5559 elems->mu_edca_param_set))
5560 changed |= BSS_CHANGED_QOS;
5563 * If we haven't had a beacon before, tell the driver about the
5564 * DTIM period (and beacon timing if desired) now.
5566 if (!link->u.mgd.have_beacon) {
5567 /* a few bogus AP send dtim_period = 0 or no TIM IE */
5568 bss_conf->dtim_period = elems->dtim_period ?: 1;
5570 changed |= BSS_CHANGED_BEACON_INFO;
5571 link->u.mgd.have_beacon = true;
5573 mutex_lock(&local->iflist_mtx);
5574 ieee80211_recalc_ps(local);
5575 mutex_unlock(&local->iflist_mtx);
5577 ieee80211_recalc_ps_vif(sdata);
5580 if (elems->erp_info) {
5582 erp_value = elems->erp_info[0];
5587 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5588 changed |= ieee80211_handle_bss_capability(link,
5589 le16_to_cpu(mgmt->u.beacon.capab_info),
5590 erp_valid, erp_value);
5592 mutex_lock(&local->sta_mtx);
5593 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
5596 link_sta = rcu_dereference_protected(sta->link[link->link_id],
5597 lockdep_is_held(&local->sta_mtx));
5598 if (WARN_ON(!link_sta))
5601 changed |= ieee80211_recalc_twt_req(link, link_sta, elems);
5603 if (ieee80211_config_bw(link, elems->ht_cap_elem,
5604 elems->vht_cap_elem, elems->ht_operation,
5605 elems->vht_operation, elems->he_operation,
5606 elems->eht_operation,
5607 elems->s1g_oper, bssid, &changed)) {
5608 mutex_unlock(&local->sta_mtx);
5610 "failed to follow AP %pM bandwidth change, disconnect\n",
5612 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5613 WLAN_REASON_DEAUTH_LEAVING,
5615 ieee80211_report_disconnect(sdata, deauth_buf,
5616 sizeof(deauth_buf), true,
5617 WLAN_REASON_DEAUTH_LEAVING,
5622 if (sta && elems->opmode_notif)
5623 ieee80211_vht_handle_opmode(sdata, link_sta,
5624 *elems->opmode_notif,
5626 mutex_unlock(&local->sta_mtx);
5628 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
5629 elems->country_elem,
5630 elems->country_elem_len,
5631 elems->pwr_constr_elem,
5632 elems->cisco_dtpc_elem);
5634 ieee80211_link_info_change_notify(sdata, link, changed);
5639 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
5640 struct sk_buff *skb)
5642 struct ieee80211_link_data *link = &sdata->deflink;
5643 struct ieee80211_rx_status *rx_status;
5644 struct ieee80211_hdr *hdr;
5647 rx_status = (struct ieee80211_rx_status *) skb->cb;
5648 hdr = (struct ieee80211_hdr *) skb->data;
5649 fc = le16_to_cpu(hdr->frame_control);
5652 switch (fc & IEEE80211_FCTL_STYPE) {
5653 case IEEE80211_STYPE_S1G_BEACON:
5654 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
5657 sdata_unlock(sdata);
5660 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
5661 struct sk_buff *skb)
5663 struct ieee80211_link_data *link = &sdata->deflink;
5664 struct ieee80211_rx_status *rx_status;
5665 struct ieee80211_mgmt *mgmt;
5669 rx_status = (struct ieee80211_rx_status *) skb->cb;
5670 mgmt = (struct ieee80211_mgmt *) skb->data;
5671 fc = le16_to_cpu(mgmt->frame_control);
5675 switch (fc & IEEE80211_FCTL_STYPE) {
5676 case IEEE80211_STYPE_BEACON:
5677 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
5678 skb->len, rx_status);
5680 case IEEE80211_STYPE_PROBE_RESP:
5681 ieee80211_rx_mgmt_probe_resp(link, skb);
5683 case IEEE80211_STYPE_AUTH:
5684 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
5686 case IEEE80211_STYPE_DEAUTH:
5687 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
5689 case IEEE80211_STYPE_DISASSOC:
5690 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
5692 case IEEE80211_STYPE_ASSOC_RESP:
5693 case IEEE80211_STYPE_REASSOC_RESP:
5694 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
5696 case IEEE80211_STYPE_ACTION:
5697 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
5698 struct ieee802_11_elems *elems;
5700 ies_len = skb->len -
5701 offsetof(struct ieee80211_mgmt,
5702 u.action.u.chan_switch.variable);
5707 /* CSA IE cannot be overridden, no need for BSSID */
5708 elems = ieee802_11_parse_elems(
5709 mgmt->u.action.u.chan_switch.variable,
5710 ies_len, true, NULL);
5712 if (elems && !elems->parse_error)
5713 ieee80211_sta_process_chanswitch(link,
5715 rx_status->device_timestamp,
5718 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
5719 struct ieee802_11_elems *elems;
5721 ies_len = skb->len -
5722 offsetof(struct ieee80211_mgmt,
5723 u.action.u.ext_chan_switch.variable);
5729 * extended CSA IE can't be overridden, no need for
5732 elems = ieee802_11_parse_elems(
5733 mgmt->u.action.u.ext_chan_switch.variable,
5734 ies_len, true, NULL);
5736 if (elems && !elems->parse_error) {
5737 /* for the handling code pretend it was an IE */
5738 elems->ext_chansw_ie =
5739 &mgmt->u.action.u.ext_chan_switch.data;
5741 ieee80211_sta_process_chanswitch(link,
5743 rx_status->device_timestamp,
5751 sdata_unlock(sdata);
5754 static void ieee80211_sta_timer(struct timer_list *t)
5756 struct ieee80211_sub_if_data *sdata =
5757 from_timer(sdata, t, u.mgd.timer);
5759 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
5762 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
5765 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5767 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
5770 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5774 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
5776 struct ieee80211_local *local = sdata->local;
5777 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5778 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
5782 struct ieee80211_prep_tx_info info = {
5783 .subtype = IEEE80211_STYPE_AUTH,
5786 sdata_assert_lock(sdata);
5788 if (WARN_ON_ONCE(!auth_data))
5793 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
5794 sdata_info(sdata, "authentication with %pM timed out\n",
5795 auth_data->ap_addr);
5798 * Most likely AP is not in the range so remove the
5799 * bss struct for that AP.
5801 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
5806 if (auth_data->algorithm == WLAN_AUTH_SAE)
5807 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
5809 drv_mgd_prepare_tx(local, sdata, &info);
5811 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
5812 auth_data->ap_addr, auth_data->tries,
5813 IEEE80211_AUTH_MAX_TRIES);
5815 auth_data->expected_transaction = 2;
5817 if (auth_data->algorithm == WLAN_AUTH_SAE) {
5818 trans = auth_data->sae_trans;
5819 status = auth_data->sae_status;
5820 auth_data->expected_transaction = trans;
5823 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
5824 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
5825 IEEE80211_TX_INTFL_MLME_CONN_TX;
5827 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
5828 auth_data->data, auth_data->data_len,
5829 auth_data->ap_addr, auth_data->ap_addr,
5830 NULL, 0, 0, tx_flags);
5832 if (tx_flags == 0) {
5833 if (auth_data->algorithm == WLAN_AUTH_SAE)
5834 auth_data->timeout = jiffies +
5835 IEEE80211_AUTH_TIMEOUT_SAE;
5837 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
5839 auth_data->timeout =
5840 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
5843 auth_data->timeout_started = true;
5844 run_again(sdata, auth_data->timeout);
5849 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
5851 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
5852 struct ieee80211_local *local = sdata->local;
5855 sdata_assert_lock(sdata);
5857 assoc_data->tries++;
5858 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
5859 sdata_info(sdata, "association with %pM timed out\n",
5860 assoc_data->ap_addr);
5863 * Most likely AP is not in the range so remove the
5864 * bss struct for that AP.
5866 cfg80211_unlink_bss(local->hw.wiphy,
5867 assoc_data->link[assoc_data->assoc_link_id].bss);
5872 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
5873 assoc_data->ap_addr, assoc_data->tries,
5874 IEEE80211_ASSOC_MAX_TRIES);
5875 ret = ieee80211_send_assoc(sdata);
5879 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
5880 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
5881 assoc_data->timeout_started = true;
5882 run_again(sdata, assoc_data->timeout);
5884 assoc_data->timeout =
5885 round_jiffies_up(jiffies +
5886 IEEE80211_ASSOC_TIMEOUT_LONG);
5887 assoc_data->timeout_started = true;
5888 run_again(sdata, assoc_data->timeout);
5894 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
5895 __le16 fc, bool acked)
5897 struct ieee80211_local *local = sdata->local;
5899 sdata->u.mgd.status_fc = fc;
5900 sdata->u.mgd.status_acked = acked;
5901 sdata->u.mgd.status_received = true;
5903 ieee80211_queue_work(&local->hw, &sdata->work);
5906 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
5908 struct ieee80211_local *local = sdata->local;
5909 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5913 if (ifmgd->status_received) {
5914 __le16 fc = ifmgd->status_fc;
5915 bool status_acked = ifmgd->status_acked;
5917 ifmgd->status_received = false;
5918 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
5920 if (ifmgd->auth_data->algorithm ==
5922 ifmgd->auth_data->timeout =
5924 IEEE80211_AUTH_TIMEOUT_SAE;
5926 ifmgd->auth_data->timeout =
5928 IEEE80211_AUTH_TIMEOUT_SHORT;
5929 run_again(sdata, ifmgd->auth_data->timeout);
5931 ifmgd->auth_data->timeout = jiffies - 1;
5933 ifmgd->auth_data->timeout_started = true;
5934 } else if (ifmgd->assoc_data &&
5935 (ieee80211_is_assoc_req(fc) ||
5936 ieee80211_is_reassoc_req(fc))) {
5938 ifmgd->assoc_data->timeout =
5939 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
5940 run_again(sdata, ifmgd->assoc_data->timeout);
5942 ifmgd->assoc_data->timeout = jiffies - 1;
5944 ifmgd->assoc_data->timeout_started = true;
5948 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
5949 time_after(jiffies, ifmgd->auth_data->timeout)) {
5950 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
5952 * ok ... we waited for assoc or continuation but
5953 * userspace didn't do it, so kill the auth data
5955 ieee80211_destroy_auth_data(sdata, false);
5956 } else if (ieee80211_auth(sdata)) {
5957 u8 ap_addr[ETH_ALEN];
5958 struct ieee80211_event event = {
5960 .u.mlme.data = AUTH_EVENT,
5961 .u.mlme.status = MLME_TIMEOUT,
5964 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
5966 ieee80211_destroy_auth_data(sdata, false);
5968 cfg80211_auth_timeout(sdata->dev, ap_addr);
5969 drv_event_callback(sdata->local, sdata, &event);
5971 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
5972 run_again(sdata, ifmgd->auth_data->timeout);
5974 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
5975 time_after(jiffies, ifmgd->assoc_data->timeout)) {
5976 if ((ifmgd->assoc_data->need_beacon &&
5977 !sdata->deflink.u.mgd.have_beacon) ||
5978 ieee80211_do_assoc(sdata)) {
5979 struct ieee80211_event event = {
5981 .u.mlme.data = ASSOC_EVENT,
5982 .u.mlme.status = MLME_TIMEOUT,
5985 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5986 drv_event_callback(sdata->local, sdata, &event);
5988 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
5989 run_again(sdata, ifmgd->assoc_data->timeout);
5991 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
5992 ifmgd->associated) {
5993 u8 *bssid = sdata->deflink.u.mgd.bssid;
5996 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
5997 max_tries = max_nullfunc_tries;
5999 max_tries = max_probe_tries;
6001 /* ACK received for nullfunc probing frame */
6002 if (!ifmgd->probe_send_count)
6003 ieee80211_reset_ap_probe(sdata);
6004 else if (ifmgd->nullfunc_failed) {
6005 if (ifmgd->probe_send_count < max_tries) {
6007 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
6008 bssid, ifmgd->probe_send_count,
6010 ieee80211_mgd_probe_ap_send(sdata);
6013 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
6015 ieee80211_sta_connection_lost(sdata,
6016 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
6019 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
6020 run_again(sdata, ifmgd->probe_timeout);
6021 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6023 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
6024 bssid, probe_wait_ms);
6025 ieee80211_sta_connection_lost(sdata,
6026 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6027 } else if (ifmgd->probe_send_count < max_tries) {
6029 "No probe response from AP %pM after %dms, try %d/%i\n",
6030 bssid, probe_wait_ms,
6031 ifmgd->probe_send_count, max_tries);
6032 ieee80211_mgd_probe_ap_send(sdata);
6035 * We actually lost the connection ... or did we?
6039 "No probe response from AP %pM after %dms, disconnecting.\n",
6040 bssid, probe_wait_ms);
6042 ieee80211_sta_connection_lost(sdata,
6043 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6047 sdata_unlock(sdata);
6050 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
6052 struct ieee80211_sub_if_data *sdata =
6053 from_timer(sdata, t, u.mgd.bcn_mon_timer);
6055 if (WARN_ON(sdata->vif.valid_links))
6058 if (sdata->vif.bss_conf.csa_active &&
6059 !sdata->deflink.u.mgd.csa_waiting_bcn)
6062 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
6065 sdata->u.mgd.connection_loss = false;
6066 ieee80211_queue_work(&sdata->local->hw,
6067 &sdata->u.mgd.beacon_connection_loss_work);
6070 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
6072 struct ieee80211_sub_if_data *sdata =
6073 from_timer(sdata, t, u.mgd.conn_mon_timer);
6074 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6075 struct ieee80211_local *local = sdata->local;
6076 struct sta_info *sta;
6077 unsigned long timeout;
6079 if (WARN_ON(sdata->vif.valid_links))
6082 if (sdata->vif.bss_conf.csa_active &&
6083 !sdata->deflink.u.mgd.csa_waiting_bcn)
6086 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6090 timeout = sta->deflink.status_stats.last_ack;
6091 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
6092 timeout = sta->deflink.rx_stats.last_rx;
6093 timeout += IEEE80211_CONNECTION_IDLE_TIME;
6095 /* If timeout is after now, then update timer to fire at
6096 * the later date, but do not actually probe at this time.
6098 if (time_is_after_jiffies(timeout)) {
6099 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
6103 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
6106 static void ieee80211_sta_monitor_work(struct work_struct *work)
6108 struct ieee80211_sub_if_data *sdata =
6109 container_of(work, struct ieee80211_sub_if_data,
6110 u.mgd.monitor_work);
6112 ieee80211_mgd_probe_ap(sdata, false);
6115 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
6117 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
6118 __ieee80211_stop_poll(sdata);
6120 /* let's probe the connection once */
6121 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
6122 ieee80211_queue_work(&sdata->local->hw,
6123 &sdata->u.mgd.monitor_work);
6128 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
6130 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6131 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6135 if (ifmgd->auth_data || ifmgd->assoc_data) {
6136 const u8 *ap_addr = ifmgd->auth_data ?
6137 ifmgd->auth_data->ap_addr :
6138 ifmgd->assoc_data->ap_addr;
6141 * If we are trying to authenticate / associate while suspending,
6142 * cfg80211 won't know and won't actually abort those attempts,
6143 * thus we need to do that ourselves.
6145 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
6146 IEEE80211_STYPE_DEAUTH,
6147 WLAN_REASON_DEAUTH_LEAVING,
6149 if (ifmgd->assoc_data)
6150 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6151 if (ifmgd->auth_data)
6152 ieee80211_destroy_auth_data(sdata, false);
6153 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
6154 IEEE80211_DEAUTH_FRAME_LEN,
6158 /* This is a bit of a hack - we should find a better and more generic
6159 * solution to this. Normally when suspending, cfg80211 will in fact
6160 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
6161 * auth (not so important) or assoc (this is the problem) process.
6163 * As a consequence, it can happen that we are in the process of both
6164 * associating and suspending, and receive an association response
6165 * after cfg80211 has checked if it needs to disconnect, but before
6166 * we actually set the flag to drop incoming frames. This will then
6167 * cause the workqueue flush to process the association response in
6168 * the suspend, resulting in a successful association just before it
6169 * tries to remove the interface from the driver, which now though
6170 * has a channel context assigned ... this results in issues.
6172 * To work around this (for now) simply deauth here again if we're
6175 if (ifmgd->associated && !sdata->local->wowlan) {
6177 struct cfg80211_deauth_request req = {
6178 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
6182 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
6183 ieee80211_mgd_deauth(sdata, &req);
6186 sdata_unlock(sdata);
6190 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
6192 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6195 if (!ifmgd->associated) {
6196 sdata_unlock(sdata);
6200 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
6201 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
6202 mlme_dbg(sdata, "driver requested disconnect after resume\n");
6203 ieee80211_sta_connection_lost(sdata,
6204 WLAN_REASON_UNSPECIFIED,
6206 sdata_unlock(sdata);
6210 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
6211 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
6212 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
6213 ieee80211_sta_connection_lost(sdata,
6214 WLAN_REASON_UNSPECIFIED,
6216 sdata_unlock(sdata);
6220 sdata_unlock(sdata);
6223 static void ieee80211_request_smps_mgd_work(struct work_struct *work)
6225 struct ieee80211_link_data *link =
6226 container_of(work, struct ieee80211_link_data,
6227 u.mgd.request_smps_work);
6229 sdata_lock(link->sdata);
6230 __ieee80211_request_smps_mgd(link->sdata, link,
6231 link->u.mgd.driver_smps_mode);
6232 sdata_unlock(link->sdata);
6235 /* interface setup */
6236 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
6238 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6240 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
6241 INIT_WORK(&ifmgd->beacon_connection_loss_work,
6242 ieee80211_beacon_connection_loss_work);
6243 INIT_WORK(&ifmgd->csa_connection_drop_work,
6244 ieee80211_csa_connection_drop_work);
6245 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
6246 ieee80211_tdls_peer_del_work);
6247 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
6248 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
6249 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
6250 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
6251 ieee80211_sta_handle_tspec_ac_params_wk);
6254 ifmgd->powersave = sdata->wdev.ps;
6255 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
6256 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
6257 /* Setup TDLS data */
6258 spin_lock_init(&ifmgd->teardown_lock);
6259 ifmgd->teardown_skb = NULL;
6260 ifmgd->orig_teardown_skb = NULL;
6263 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
6265 struct ieee80211_sub_if_data *sdata = link->sdata;
6266 struct ieee80211_local *local = sdata->local;
6267 unsigned int link_id = link->link_id;
6269 link->u.mgd.p2p_noa_index = -1;
6270 link->u.mgd.conn_flags = 0;
6271 link->conf->bssid = link->u.mgd.bssid;
6273 INIT_WORK(&link->u.mgd.request_smps_work,
6274 ieee80211_request_smps_mgd_work);
6275 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
6276 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
6278 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
6280 INIT_WORK(&link->u.mgd.chswitch_work, ieee80211_chswitch_work);
6281 timer_setup(&link->u.mgd.chswitch_timer, ieee80211_chswitch_timer, 0);
6283 if (sdata->u.mgd.assoc_data)
6284 ether_addr_copy(link->conf->addr,
6285 sdata->u.mgd.assoc_data->link[link_id].addr);
6288 /* scan finished notification */
6289 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
6291 struct ieee80211_sub_if_data *sdata;
6293 /* Restart STA timers */
6295 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
6296 if (ieee80211_sdata_running(sdata))
6297 ieee80211_restart_sta_timer(sdata);
6302 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
6303 u8 *dtim_count, u8 *dtim_period)
6305 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
6306 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
6308 const struct ieee80211_tim_ie *tim = NULL;
6309 const struct ieee80211_bssid_index *idx;
6310 bool valid = tim_ie && tim_ie[1] >= 2;
6313 tim = (void *)(tim_ie + 2);
6316 *dtim_count = valid ? tim->dtim_count : 0;
6319 *dtim_period = valid ? tim->dtim_period : 0;
6321 /* Check if value is overridden by non-transmitted profile */
6322 if (!idx_ie || idx_ie[1] < 3)
6325 idx = (void *)(idx_ie + 2);
6328 *dtim_count = idx->dtim_count;
6331 *dtim_period = idx->dtim_period;
6336 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
6337 struct cfg80211_bss *cbss, s8 link_id,
6338 const u8 *ap_mld_addr, bool assoc,
6341 struct ieee80211_local *local = sdata->local;
6342 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6343 struct ieee80211_bss *bss = (void *)cbss->priv;
6344 struct sta_info *new_sta = NULL;
6345 struct ieee80211_link_data *link;
6346 bool have_sta = false;
6352 if (WARN_ON(!ap_mld_addr))
6354 err = ieee80211_vif_set_links(sdata, BIT(link_id));
6356 if (WARN_ON(ap_mld_addr))
6358 ap_mld_addr = cbss->bssid;
6359 err = ieee80211_vif_set_links(sdata, 0);
6367 link = sdata_dereference(sdata->link[link_id], sdata);
6368 if (WARN_ON(!link)) {
6373 if (mlo && !is_valid_ether_addr(link->conf->addr))
6374 eth_random_addr(link->conf->addr);
6376 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
6381 /* If a reconfig is happening, bail out */
6382 if (local->in_reconfig) {
6389 have_sta = sta_info_get(sdata, ap_mld_addr);
6395 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
6396 link_id, cbss->bssid,
6399 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
6406 new_sta->sta.mlo = link_id >= 0;
6410 * Set up the information for the new channel before setting the
6411 * new channel. We can't - completely race-free - change the basic
6412 * rates bitmap and the channel (sband) that it refers to, but if
6413 * we set it up before we at least avoid calling into the driver's
6414 * bss_info_changed() method with invalid information (since we do
6415 * call that from changing the channel - only for IDLE and perhaps
6416 * some others, but ...).
6418 * So to avoid that, just set up all the new information before the
6419 * channel, but tell the driver to apply it only afterwards, since
6420 * it might need the new channel for that.
6423 const struct cfg80211_bss_ies *ies;
6424 struct ieee80211_link_sta *link_sta;
6427 link_sta = rcu_dereference(new_sta->sta.link[link_id]);
6428 if (WARN_ON(!link_sta)) {
6430 sta_info_free(local, new_sta);
6435 err = ieee80211_mgd_setup_link_sta(link, new_sta,
6439 sta_info_free(local, new_sta);
6443 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
6445 /* set timing information */
6446 link->conf->beacon_int = cbss->beacon_interval;
6447 ies = rcu_dereference(cbss->beacon_ies);
6449 link->conf->sync_tsf = ies->tsf;
6450 link->conf->sync_device_ts =
6451 bss->device_ts_beacon;
6453 ieee80211_get_dtim(ies,
6454 &link->conf->sync_dtim_count,
6456 } else if (!ieee80211_hw_check(&sdata->local->hw,
6457 TIMING_BEACON_ONLY)) {
6458 ies = rcu_dereference(cbss->proberesp_ies);
6459 /* must be non-NULL since beacon IEs were NULL */
6460 link->conf->sync_tsf = ies->tsf;
6461 link->conf->sync_device_ts =
6462 bss->device_ts_presp;
6463 link->conf->sync_dtim_count = 0;
6465 link->conf->sync_tsf = 0;
6466 link->conf->sync_device_ts = 0;
6467 link->conf->sync_dtim_count = 0;
6472 if (new_sta || override) {
6473 err = ieee80211_prep_channel(sdata, link, cbss,
6474 &link->u.mgd.conn_flags);
6477 sta_info_free(local, new_sta);
6484 * tell driver about BSSID, basic rates and timing
6485 * this was set up above, before setting the channel
6487 ieee80211_link_info_change_notify(sdata, link,
6489 BSS_CHANGED_BASIC_RATES |
6490 BSS_CHANGED_BEACON_INT);
6493 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
6495 err = sta_info_insert(new_sta);
6499 "failed to insert STA entry for the AP (error %d)\n",
6504 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
6506 /* Cancel scan to ensure that nothing interferes with connection */
6507 if (local->scanning)
6508 ieee80211_scan_cancel(local);
6513 ieee80211_vif_set_links(sdata, 0);
6518 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
6519 struct cfg80211_auth_request *req)
6521 struct ieee80211_local *local = sdata->local;
6522 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6523 struct ieee80211_mgd_auth_data *auth_data;
6528 /* prepare auth data structure */
6530 switch (req->auth_type) {
6531 case NL80211_AUTHTYPE_OPEN_SYSTEM:
6532 auth_alg = WLAN_AUTH_OPEN;
6534 case NL80211_AUTHTYPE_SHARED_KEY:
6537 auth_alg = WLAN_AUTH_SHARED_KEY;
6539 case NL80211_AUTHTYPE_FT:
6540 auth_alg = WLAN_AUTH_FT;
6542 case NL80211_AUTHTYPE_NETWORK_EAP:
6543 auth_alg = WLAN_AUTH_LEAP;
6545 case NL80211_AUTHTYPE_SAE:
6546 auth_alg = WLAN_AUTH_SAE;
6548 case NL80211_AUTHTYPE_FILS_SK:
6549 auth_alg = WLAN_AUTH_FILS_SK;
6551 case NL80211_AUTHTYPE_FILS_SK_PFS:
6552 auth_alg = WLAN_AUTH_FILS_SK_PFS;
6554 case NL80211_AUTHTYPE_FILS_PK:
6555 auth_alg = WLAN_AUTH_FILS_PK;
6561 if (ifmgd->assoc_data)
6564 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
6565 req->ie_len, GFP_KERNEL);
6569 memcpy(auth_data->ap_addr,
6570 req->ap_mld_addr ?: req->bss->bssid,
6572 auth_data->bss = req->bss;
6574 if (req->auth_data_len >= 4) {
6575 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
6576 __le16 *pos = (__le16 *) req->auth_data;
6578 auth_data->sae_trans = le16_to_cpu(pos[0]);
6579 auth_data->sae_status = le16_to_cpu(pos[1]);
6581 memcpy(auth_data->data, req->auth_data + 4,
6582 req->auth_data_len - 4);
6583 auth_data->data_len += req->auth_data_len - 4;
6586 /* Check if continuing authentication or trying to authenticate with the
6587 * same BSS that we were in the process of authenticating with and avoid
6588 * removal and re-addition of the STA entry in
6589 * ieee80211_prep_connection().
6591 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
6593 if (req->ie && req->ie_len) {
6594 memcpy(&auth_data->data[auth_data->data_len],
6595 req->ie, req->ie_len);
6596 auth_data->data_len += req->ie_len;
6599 if (req->key && req->key_len) {
6600 auth_data->key_len = req->key_len;
6601 auth_data->key_idx = req->key_idx;
6602 memcpy(auth_data->key, req->key, req->key_len);
6605 auth_data->algorithm = auth_alg;
6607 /* try to authenticate/probe */
6609 if (ifmgd->auth_data) {
6610 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
6611 auth_data->peer_confirmed =
6612 ifmgd->auth_data->peer_confirmed;
6614 ieee80211_destroy_auth_data(sdata, cont_auth);
6617 /* prep auth_data so we don't go into idle on disassoc */
6618 ifmgd->auth_data = auth_data;
6620 /* If this is continuation of an ongoing SAE authentication exchange
6621 * (i.e., request to send SAE Confirm) and the peer has already
6622 * confirmed, mark authentication completed since we are about to send
6625 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
6626 auth_data->peer_confirmed && auth_data->sae_trans == 2)
6627 ieee80211_mark_sta_auth(sdata);
6629 if (ifmgd->associated) {
6630 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6633 "disconnect from AP %pM for new auth to %pM\n",
6634 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
6635 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6636 WLAN_REASON_UNSPECIFIED,
6639 ieee80211_report_disconnect(sdata, frame_buf,
6640 sizeof(frame_buf), true,
6641 WLAN_REASON_UNSPECIFIED,
6645 sdata_info(sdata, "authenticate with %pM\n", auth_data->ap_addr);
6647 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
6648 req->ap_mld_addr, cont_auth, false);
6652 err = ieee80211_auth(sdata);
6654 sta_info_destroy_addr(sdata, auth_data->ap_addr);
6658 /* hold our own reference */
6659 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
6663 if (!sdata->vif.valid_links) {
6664 eth_zero_addr(sdata->deflink.u.mgd.bssid);
6665 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
6667 mutex_lock(&sdata->local->mtx);
6668 ieee80211_link_release_channel(&sdata->deflink);
6669 mutex_unlock(&sdata->local->mtx);
6671 ifmgd->auth_data = NULL;
6676 static ieee80211_conn_flags_t
6677 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
6678 struct ieee80211_mgd_assoc_data *assoc_data,
6679 struct cfg80211_assoc_request *req,
6680 ieee80211_conn_flags_t conn_flags,
6681 unsigned int link_id)
6683 struct ieee80211_local *local = sdata->local;
6684 const struct cfg80211_bss_ies *beacon_ies;
6685 struct ieee80211_supported_band *sband;
6686 const struct element *ht_elem, *vht_elem;
6687 struct ieee80211_link_data *link;
6688 struct cfg80211_bss *cbss;
6689 struct ieee80211_bss *bss;
6690 bool is_5ghz, is_6ghz;
6692 cbss = assoc_data->link[link_id].bss;
6696 bss = (void *)cbss->priv;
6698 sband = local->hw.wiphy->bands[cbss->channel->band];
6699 if (WARN_ON(!sband))
6702 link = sdata_dereference(sdata->link[link_id], sdata);
6706 is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
6707 is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
6709 /* for MLO connections assume advertising all rates is OK */
6710 if (!req->ap_mld_addr) {
6711 assoc_data->supp_rates = bss->supp_rates;
6712 assoc_data->supp_rates_len = bss->supp_rates_len;
6715 /* copy and link elems for the STA profile */
6716 if (req->links[link_id].elems_len) {
6717 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
6718 req->links[link_id].elems_len);
6719 assoc_data->link[link_id].elems = assoc_data->ie_pos;
6720 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
6721 assoc_data->ie_pos += req->links[link_id].elems_len;
6725 ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
6726 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
6727 assoc_data->link[link_id].ap_ht_param =
6728 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
6730 conn_flags |= IEEE80211_CONN_DISABLE_HT;
6731 vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
6732 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
6733 memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
6734 sizeof(struct ieee80211_vht_cap));
6735 } else if (is_5ghz) {
6737 "VHT capa missing/short, disabling VHT/HE/EHT\n");
6738 conn_flags |= IEEE80211_CONN_DISABLE_VHT |
6739 IEEE80211_CONN_DISABLE_HE |
6740 IEEE80211_CONN_DISABLE_EHT;
6744 link->u.mgd.beacon_crc_valid = false;
6745 link->u.mgd.dtim_period = 0;
6746 link->u.mgd.have_beacon = false;
6748 /* override HT/VHT configuration only if the AP and we support it */
6749 if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
6750 struct ieee80211_sta_ht_cap sta_ht_cap;
6752 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
6753 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
6757 beacon_ies = rcu_dereference(cbss->beacon_ies);
6759 const struct element *elem;
6762 ieee80211_get_dtim(beacon_ies, &dtim_count,
6763 &link->u.mgd.dtim_period);
6765 sdata->deflink.u.mgd.have_beacon = true;
6767 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
6768 link->conf->sync_tsf = beacon_ies->tsf;
6769 link->conf->sync_device_ts = bss->device_ts_beacon;
6770 link->conf->sync_dtim_count = dtim_count;
6773 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
6774 beacon_ies->data, beacon_ies->len);
6775 if (elem && elem->datalen >= 3)
6776 link->conf->profile_periodicity = elem->data[2];
6778 link->conf->profile_periodicity = 0;
6780 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
6781 beacon_ies->data, beacon_ies->len);
6782 if (elem && elem->datalen >= 11 &&
6783 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
6784 link->conf->ema_ap = true;
6786 link->conf->ema_ap = false;
6790 if (bss->corrupt_data) {
6791 char *corrupt_type = "data";
6793 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
6794 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
6795 corrupt_type = "beacon and probe response";
6797 corrupt_type = "beacon";
6798 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
6799 corrupt_type = "probe response";
6801 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
6802 cbss->bssid, corrupt_type);
6805 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
6806 if (sdata->u.mgd.powersave)
6807 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
6809 link->smps_mode = IEEE80211_SMPS_OFF;
6811 link->smps_mode = link->u.mgd.req_smps;
6817 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
6818 struct cfg80211_assoc_request *req)
6820 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
6821 struct ieee80211_local *local = sdata->local;
6822 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6823 struct ieee80211_mgd_assoc_data *assoc_data;
6824 const struct element *ssid_elem;
6825 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
6826 ieee80211_conn_flags_t conn_flags = 0;
6827 struct ieee80211_link_data *link;
6828 struct cfg80211_bss *cbss;
6829 struct ieee80211_bss *bss;
6832 size_t size = sizeof(*assoc_data) + req->ie_len;
6834 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
6835 size += req->links[i].elems_len;
6837 if (req->ap_mld_addr) {
6838 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
6839 if (!req->links[i].bss)
6841 if (i == assoc_link_id)
6844 * For now, support only a single link in MLO, we
6845 * don't have the necessary parsing of the multi-
6846 * link element in the association response, etc.
6849 "refusing MLO association with >1 links\n");
6854 assoc_data = kzalloc(size, GFP_KERNEL);
6858 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
6861 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
6862 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
6867 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
6868 assoc_data->ssid_len = ssid_elem->datalen;
6869 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
6870 vif_cfg->ssid_len = assoc_data->ssid_len;
6873 if (req->ap_mld_addr) {
6874 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
6875 if (!req->links[i].bss)
6877 link = sdata_dereference(sdata->link[i], sdata);
6879 ether_addr_copy(assoc_data->link[i].addr,
6882 eth_random_addr(assoc_data->link[i].addr);
6885 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
6888 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
6890 memcpy(assoc_data->ap_addr,
6891 req->ap_mld_addr ?: req->bss->bssid,
6894 if (ifmgd->associated) {
6895 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6898 "disconnect from AP %pM for new assoc to %pM\n",
6899 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
6900 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6901 WLAN_REASON_UNSPECIFIED,
6904 ieee80211_report_disconnect(sdata, frame_buf,
6905 sizeof(frame_buf), true,
6906 WLAN_REASON_UNSPECIFIED,
6910 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
6915 if (ifmgd->assoc_data) {
6920 if (ifmgd->auth_data) {
6923 /* keep sta info, bssid if matching */
6924 match = ether_addr_equal(ifmgd->auth_data->ap_addr,
6925 assoc_data->ap_addr);
6926 ieee80211_destroy_auth_data(sdata, match);
6929 /* prepare assoc data */
6931 bss = (void *)cbss->priv;
6932 assoc_data->wmm = bss->wmm_used &&
6933 (local->hw.queues >= IEEE80211_NUM_ACS);
6936 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
6937 * We still associate in non-HT mode (11a/b/g) if any one of these
6938 * ciphers is configured as pairwise.
6939 * We can set this to true for non-11n hardware, that'll be checked
6940 * separately along with the peer capabilities.
6942 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
6943 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
6944 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
6945 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
6946 conn_flags |= IEEE80211_CONN_DISABLE_HT;
6947 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6948 conn_flags |= IEEE80211_CONN_DISABLE_HE;
6949 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6950 netdev_info(sdata->dev,
6951 "disabling HT/VHT/HE due to WEP/TKIP use\n");
6955 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
6956 if (!bss->wmm_used) {
6957 conn_flags |= IEEE80211_CONN_DISABLE_HT;
6958 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6959 conn_flags |= IEEE80211_CONN_DISABLE_HE;
6960 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6961 netdev_info(sdata->dev,
6962 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
6965 if (req->flags & ASSOC_REQ_DISABLE_HT) {
6966 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
6967 conn_flags |= IEEE80211_CONN_DISABLE_HT;
6968 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6969 conn_flags |= IEEE80211_CONN_DISABLE_HE;
6970 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6973 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
6974 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
6975 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6978 if (req->flags & ASSOC_REQ_DISABLE_HE) {
6979 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
6980 conn_flags |= IEEE80211_CONN_DISABLE_HE;
6981 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6984 if (req->flags & ASSOC_REQ_DISABLE_EHT)
6985 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6987 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
6988 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
6989 sizeof(ifmgd->ht_capa_mask));
6991 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
6992 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
6993 sizeof(ifmgd->vht_capa_mask));
6995 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
6996 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
6997 sizeof(ifmgd->s1g_capa_mask));
6999 if (req->ie && req->ie_len) {
7000 memcpy(assoc_data->ie, req->ie, req->ie_len);
7001 assoc_data->ie_len = req->ie_len;
7002 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
7004 assoc_data->ie_pos = assoc_data->ie;
7007 if (req->fils_kek) {
7008 /* should already be checked in cfg80211 - so warn */
7009 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
7013 memcpy(assoc_data->fils_kek, req->fils_kek,
7015 assoc_data->fils_kek_len = req->fils_kek_len;
7018 if (req->fils_nonces)
7019 memcpy(assoc_data->fils_nonces, req->fils_nonces,
7020 2 * FILS_NONCE_LEN);
7022 /* default timeout */
7023 assoc_data->timeout = jiffies;
7024 assoc_data->timeout_started = true;
7026 assoc_data->assoc_link_id = assoc_link_id;
7028 if (req->ap_mld_addr) {
7029 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7030 assoc_data->link[i].conn_flags = conn_flags;
7031 assoc_data->link[i].bss = req->links[i].bss;
7034 /* if there was no authentication, set up the link */
7035 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id));
7039 assoc_data->link[0].conn_flags = conn_flags;
7040 assoc_data->link[0].bss = cbss;
7043 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
7044 if (WARN_ON(!link)) {
7049 conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
7050 conn_flags, assoc_link_id);
7051 override = link->u.mgd.conn_flags != conn_flags;
7052 link->u.mgd.conn_flags |= conn_flags;
7054 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
7055 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
7056 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
7057 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
7059 if (bss->wmm_used && bss->uapsd_supported &&
7060 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
7061 assoc_data->uapsd = true;
7062 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
7064 assoc_data->uapsd = false;
7065 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
7068 if (req->prev_bssid)
7069 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
7072 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
7073 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
7075 ifmgd->mfp = IEEE80211_MFP_DISABLED;
7076 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
7079 if (req->flags & ASSOC_REQ_USE_RRM)
7080 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
7082 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
7084 if (req->crypto.control_port)
7085 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
7087 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
7089 sdata->control_port_protocol = req->crypto.control_port_ethertype;
7090 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
7091 sdata->control_port_over_nl80211 =
7092 req->crypto.control_port_over_nl80211;
7093 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
7095 /* kick off associate process */
7096 ifmgd->assoc_data = assoc_data;
7098 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7099 if (!assoc_data->link[i].bss)
7101 if (i == assoc_data->assoc_link_id)
7103 /* only calculate the flags, hence link == NULL */
7104 err = ieee80211_prep_channel(sdata, NULL, assoc_data->link[i].bss,
7105 &assoc_data->link[i].conn_flags);
7110 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
7111 req->ap_mld_addr, true, override);
7115 assoc_data->link[assoc_data->assoc_link_id].conn_flags =
7116 link->u.mgd.conn_flags;
7118 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
7119 const struct cfg80211_bss_ies *beacon_ies;
7122 beacon_ies = rcu_dereference(req->bss->beacon_ies);
7126 * Wait up to one beacon interval ...
7127 * should this be more if we miss one?
7129 sdata_info(sdata, "waiting for beacon from %pM\n",
7131 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
7132 assoc_data->timeout_started = true;
7133 assoc_data->need_beacon = true;
7138 run_again(sdata, assoc_data->timeout);
7142 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7143 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7145 ifmgd->assoc_data = NULL;
7151 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
7152 struct cfg80211_deauth_request *req)
7154 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7155 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7156 bool tx = !req->local_state_change;
7157 struct ieee80211_prep_tx_info info = {
7158 .subtype = IEEE80211_STYPE_DEAUTH,
7161 if (ifmgd->auth_data &&
7162 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
7164 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
7165 req->bssid, req->reason_code,
7166 ieee80211_get_reason_code_string(req->reason_code));
7168 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7169 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7170 IEEE80211_STYPE_DEAUTH,
7171 req->reason_code, tx,
7173 ieee80211_destroy_auth_data(sdata, false);
7174 ieee80211_report_disconnect(sdata, frame_buf,
7175 sizeof(frame_buf), true,
7176 req->reason_code, false);
7177 drv_mgd_complete_tx(sdata->local, sdata, &info);
7181 if (ifmgd->assoc_data &&
7182 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
7184 "aborting association with %pM by local choice (Reason: %u=%s)\n",
7185 req->bssid, req->reason_code,
7186 ieee80211_get_reason_code_string(req->reason_code));
7188 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7189 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7190 IEEE80211_STYPE_DEAUTH,
7191 req->reason_code, tx,
7193 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
7194 ieee80211_report_disconnect(sdata, frame_buf,
7195 sizeof(frame_buf), true,
7196 req->reason_code, false);
7200 if (ifmgd->associated &&
7201 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
7203 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
7204 req->bssid, req->reason_code,
7205 ieee80211_get_reason_code_string(req->reason_code));
7207 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7208 req->reason_code, tx, frame_buf);
7209 ieee80211_report_disconnect(sdata, frame_buf,
7210 sizeof(frame_buf), true,
7211 req->reason_code, false);
7212 drv_mgd_complete_tx(sdata->local, sdata, &info);
7219 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
7220 struct cfg80211_disassoc_request *req)
7222 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7224 if (!sdata->u.mgd.associated ||
7225 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
7229 "disassociating from %pM by local choice (Reason: %u=%s)\n",
7230 req->ap_addr, req->reason_code,
7231 ieee80211_get_reason_code_string(req->reason_code));
7233 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
7234 req->reason_code, !req->local_state_change,
7237 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
7238 req->reason_code, false);
7243 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
7245 cancel_work_sync(&link->u.mgd.request_smps_work);
7246 cancel_work_sync(&link->u.mgd.chswitch_work);
7249 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
7251 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7254 * Make sure some work items will not run after this,
7255 * they will not do anything but might not have been
7256 * cancelled when disconnecting.
7258 cancel_work_sync(&ifmgd->monitor_work);
7259 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
7260 cancel_work_sync(&ifmgd->csa_connection_drop_work);
7261 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
7264 if (ifmgd->assoc_data)
7265 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
7266 if (ifmgd->auth_data)
7267 ieee80211_destroy_auth_data(sdata, false);
7268 spin_lock_bh(&ifmgd->teardown_lock);
7269 if (ifmgd->teardown_skb) {
7270 kfree_skb(ifmgd->teardown_skb);
7271 ifmgd->teardown_skb = NULL;
7272 ifmgd->orig_teardown_skb = NULL;
7274 kfree(ifmgd->assoc_req_ies);
7275 ifmgd->assoc_req_ies = NULL;
7276 ifmgd->assoc_req_ies_len = 0;
7277 spin_unlock_bh(&ifmgd->teardown_lock);
7278 del_timer_sync(&ifmgd->timer);
7279 sdata_unlock(sdata);
7282 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
7283 enum nl80211_cqm_rssi_threshold_event rssi_event,
7287 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7289 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
7291 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
7293 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
7295 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
7297 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7299 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
7301 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
7303 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
7305 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
7309 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
7311 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
7315 * Scale up threshold values before storing it, as the RSSI averaging
7316 * algorithm uses a scaled up value as well. Change this scaling
7317 * factor if the RSSI averaging algorithm changes.
7319 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
7320 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
7323 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
7327 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7329 WARN_ON(rssi_min_thold == rssi_max_thold ||
7330 rssi_min_thold > rssi_max_thold);
7332 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
7335 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
7337 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
7339 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7341 _ieee80211_enable_rssi_reports(sdata, 0, 0);
7343 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);