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 - 2019 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_ASSOC_TIMEOUT (HZ / 5)
41 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
42 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
43 #define IEEE80211_ASSOC_MAX_TRIES 3
45 static int max_nullfunc_tries = 2;
46 module_param(max_nullfunc_tries, int, 0644);
47 MODULE_PARM_DESC(max_nullfunc_tries,
48 "Maximum nullfunc tx tries before disconnecting (reason 4).");
50 static int max_probe_tries = 5;
51 module_param(max_probe_tries, int, 0644);
52 MODULE_PARM_DESC(max_probe_tries,
53 "Maximum probe tries before disconnecting (reason 4).");
56 * Beacon loss timeout is calculated as N frames times the
57 * advertised beacon interval. This may need to be somewhat
58 * higher than what hardware might detect to account for
59 * delays in the host processing frames. But since we also
60 * probe on beacon miss before declaring the connection lost
61 * default to what we want.
63 static int beacon_loss_count = 7;
64 module_param(beacon_loss_count, int, 0644);
65 MODULE_PARM_DESC(beacon_loss_count,
66 "Number of beacon intervals before we decide beacon was lost.");
69 * Time the connection can be idle before we probe
70 * it to see if we can still talk to the AP.
72 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
74 * Time we wait for a probe response after sending
75 * a probe request because of beacon loss or for
76 * checking the connection still works.
78 static int probe_wait_ms = 500;
79 module_param(probe_wait_ms, int, 0644);
80 MODULE_PARM_DESC(probe_wait_ms,
81 "Maximum time(ms) to wait for probe response"
82 " before disconnecting (reason 4).");
85 * How many Beacon frames need to have been used in average signal strength
86 * before starting to indicate signal change events.
88 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
91 * We can have multiple work items (and connection probing)
92 * scheduling this timer, but we need to take care to only
93 * reschedule it when it should fire _earlier_ than it was
94 * asked for before, or if it's not pending right now. This
95 * function ensures that. Note that it then is required to
96 * run this function for all timeouts after the first one
97 * has happened -- the work that runs from this timer will
100 static void run_again(struct ieee80211_sub_if_data *sdata,
101 unsigned long timeout)
103 sdata_assert_lock(sdata);
105 if (!timer_pending(&sdata->u.mgd.timer) ||
106 time_before(timeout, sdata->u.mgd.timer.expires))
107 mod_timer(&sdata->u.mgd.timer, timeout);
110 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
112 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
115 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
118 mod_timer(&sdata->u.mgd.bcn_mon_timer,
119 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
122 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
124 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
126 if (unlikely(!ifmgd->associated))
129 if (ifmgd->probe_send_count)
130 ifmgd->probe_send_count = 0;
132 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
135 mod_timer(&ifmgd->conn_mon_timer,
136 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
139 static int ecw2cw(int ecw)
141 return (1 << ecw) - 1;
145 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
146 struct ieee80211_supported_band *sband,
147 struct ieee80211_channel *channel,
148 const struct ieee80211_ht_operation *ht_oper,
149 const struct ieee80211_vht_operation *vht_oper,
150 const struct ieee80211_he_operation *he_oper,
151 struct cfg80211_chan_def *chandef, bool tracking)
153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
154 struct cfg80211_chan_def vht_chandef;
155 struct ieee80211_sta_ht_cap sta_ht_cap;
158 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
159 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
161 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
162 chandef->chan = channel;
163 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
164 chandef->center_freq1 = channel->center_freq;
166 if (!ht_oper || !sta_ht_cap.ht_supported) {
167 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
171 chandef->width = NL80211_CHAN_WIDTH_20;
173 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
175 /* check that channel matches the right operating channel */
176 if (!tracking && channel->center_freq != ht_cfreq) {
178 * It's possible that some APs are confused here;
179 * Netgear WNDR3700 sometimes reports 4 higher than
180 * the actual channel in association responses, but
181 * since we look at probe response/beacon data here
185 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
186 channel->center_freq, ht_cfreq,
187 ht_oper->primary_chan, channel->band);
188 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
192 /* check 40 MHz support, if we have it */
193 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
194 ieee80211_chandef_ht_oper(ht_oper, chandef);
196 /* 40 MHz (and 80 MHz) must be supported for VHT */
197 ret = IEEE80211_STA_DISABLE_VHT;
198 /* also mark 40 MHz disabled */
199 ret |= IEEE80211_STA_DISABLE_40MHZ;
203 if (!vht_oper || !sband->vht_cap.vht_supported) {
204 ret = IEEE80211_STA_DISABLE_VHT;
208 vht_chandef = *chandef;
209 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
210 (le32_to_cpu(he_oper->he_oper_params) &
211 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
212 struct ieee80211_vht_operation he_oper_vht_cap;
215 * Set only first 3 bytes (other 2 aren't used in
216 * ieee80211_chandef_vht_oper() anyway)
218 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
219 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
221 if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
222 &he_oper_vht_cap, ht_oper,
224 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
226 "HE AP VHT information is invalid, disable HE\n");
227 ret = IEEE80211_STA_DISABLE_HE;
230 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_oper,
231 ht_oper, &vht_chandef)) {
232 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
234 "AP VHT information is invalid, disable VHT\n");
235 ret = IEEE80211_STA_DISABLE_VHT;
239 if (!cfg80211_chandef_valid(&vht_chandef)) {
240 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
242 "AP VHT information is invalid, disable VHT\n");
243 ret = IEEE80211_STA_DISABLE_VHT;
247 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
252 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
253 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
255 "AP VHT information doesn't match HT, disable VHT\n");
256 ret = IEEE80211_STA_DISABLE_VHT;
260 *chandef = vht_chandef;
266 * When tracking the current AP, don't do any further checks if the
267 * new chandef is identical to the one we're currently using for the
268 * connection. This keeps us from playing ping-pong with regulatory,
269 * without it the following can happen (for example):
270 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
271 * - AP advertises regdom US
272 * - CRDA loads regdom US with 80 MHz prohibited (old database)
273 * - the code below detects an unsupported channel, downgrades, and
274 * we disconnect from the AP in the caller
275 * - disconnect causes CRDA to reload world regdomain and the game
277 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
279 * It seems possible that there are still scenarios with CSA or real
280 * bandwidth changes where a this could happen, but those cases are
281 * less common and wouldn't completely prevent using the AP.
284 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
287 /* don't print the message below for VHT mismatch if VHT is disabled */
288 if (ret & IEEE80211_STA_DISABLE_VHT)
289 vht_chandef = *chandef;
292 * Ignore the DISABLED flag when we're already connected and only
293 * tracking the APs beacon for bandwidth changes - otherwise we
294 * might get disconnected here if we connect to an AP, update our
295 * regulatory information based on the AP's country IE and the
296 * information we have is wrong/outdated and disables the channel
297 * that we're actually using for the connection to the AP.
299 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
301 IEEE80211_CHAN_DISABLED)) {
302 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
303 ret = IEEE80211_STA_DISABLE_HT |
304 IEEE80211_STA_DISABLE_VHT;
308 ret |= ieee80211_chandef_downgrade(chandef);
311 if (chandef->width != vht_chandef.width && !tracking)
313 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
315 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
319 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
320 struct sta_info *sta,
321 const struct ieee80211_ht_cap *ht_cap,
322 const struct ieee80211_ht_operation *ht_oper,
323 const struct ieee80211_vht_operation *vht_oper,
324 const struct ieee80211_he_operation *he_oper,
325 const u8 *bssid, u32 *changed)
327 struct ieee80211_local *local = sdata->local;
328 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
329 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
330 struct ieee80211_supported_band *sband =
331 local->hw.wiphy->bands[chan->band];
332 struct cfg80211_chan_def chandef;
335 enum ieee80211_sta_rx_bandwidth new_sta_bw;
338 /* if HT was/is disabled, don't track any bandwidth changes */
339 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
342 /* don't check VHT if we associated as non-VHT station */
343 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
346 /* don't check HE if we associated as non-HE station */
347 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
348 !ieee80211_get_he_sta_cap(sband))
351 if (WARN_ON_ONCE(!sta))
355 * if bss configuration changed store the new one -
356 * this may be applicable even if channel is identical
358 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
359 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
360 *changed |= BSS_CHANGED_HT;
361 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
364 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
365 flags = ieee80211_determine_chantype(sdata, sband, chan,
366 ht_oper, vht_oper, he_oper,
370 * Downgrade the new channel if we associated with restricted
371 * capabilities. For example, if we associated as a 20 MHz STA
372 * to a 40 MHz AP (due to regulatory, capabilities or config
373 * reasons) then switching to a 40 MHz channel now won't do us
374 * any good -- we couldn't use it with the AP.
376 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
377 chandef.width == NL80211_CHAN_WIDTH_80P80)
378 flags |= ieee80211_chandef_downgrade(&chandef);
379 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
380 chandef.width == NL80211_CHAN_WIDTH_160)
381 flags |= ieee80211_chandef_downgrade(&chandef);
382 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
383 chandef.width > NL80211_CHAN_WIDTH_20)
384 flags |= ieee80211_chandef_downgrade(&chandef);
386 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
390 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
391 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
392 chandef.center_freq1, chandef.center_freq2);
394 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
395 IEEE80211_STA_DISABLE_VHT |
396 IEEE80211_STA_DISABLE_40MHZ |
397 IEEE80211_STA_DISABLE_80P80MHZ |
398 IEEE80211_STA_DISABLE_160MHZ)) ||
399 !cfg80211_chandef_valid(&chandef)) {
401 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
406 switch (chandef.width) {
407 case NL80211_CHAN_WIDTH_20_NOHT:
408 case NL80211_CHAN_WIDTH_20:
409 new_sta_bw = IEEE80211_STA_RX_BW_20;
411 case NL80211_CHAN_WIDTH_40:
412 new_sta_bw = IEEE80211_STA_RX_BW_40;
414 case NL80211_CHAN_WIDTH_80:
415 new_sta_bw = IEEE80211_STA_RX_BW_80;
417 case NL80211_CHAN_WIDTH_80P80:
418 case NL80211_CHAN_WIDTH_160:
419 new_sta_bw = IEEE80211_STA_RX_BW_160;
425 if (new_sta_bw > sta->cur_max_bandwidth)
426 new_sta_bw = sta->cur_max_bandwidth;
428 if (new_sta_bw < sta->sta.bandwidth) {
429 sta->sta.bandwidth = new_sta_bw;
430 rate_control_rate_update(local, sband, sta,
431 IEEE80211_RC_BW_CHANGED);
434 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
437 "AP %pM changed bandwidth to incompatible one - disconnect\n",
442 if (new_sta_bw > sta->sta.bandwidth) {
443 sta->sta.bandwidth = new_sta_bw;
444 rate_control_rate_update(local, sband, sta,
445 IEEE80211_RC_BW_CHANGED);
451 /* frame sending functions */
453 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
454 struct sk_buff *skb, u8 ap_ht_param,
455 struct ieee80211_supported_band *sband,
456 struct ieee80211_channel *channel,
457 enum ieee80211_smps_mode smps)
460 u32 flags = channel->flags;
462 struct ieee80211_sta_ht_cap ht_cap;
464 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
466 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
467 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
469 /* determine capability flags */
472 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
473 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
474 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
475 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
476 cap &= ~IEEE80211_HT_CAP_SGI_40;
479 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
480 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
481 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
482 cap &= ~IEEE80211_HT_CAP_SGI_40;
488 * If 40 MHz was disabled associate as though we weren't
489 * capable of 40 MHz -- some broken APs will never fall
490 * back to trying to transmit in 20 MHz.
492 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
493 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
494 cap &= ~IEEE80211_HT_CAP_SGI_40;
497 /* set SM PS mode properly */
498 cap &= ~IEEE80211_HT_CAP_SM_PS;
500 case IEEE80211_SMPS_AUTOMATIC:
501 case IEEE80211_SMPS_NUM_MODES:
504 case IEEE80211_SMPS_OFF:
505 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
506 IEEE80211_HT_CAP_SM_PS_SHIFT;
508 case IEEE80211_SMPS_STATIC:
509 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
510 IEEE80211_HT_CAP_SM_PS_SHIFT;
512 case IEEE80211_SMPS_DYNAMIC:
513 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
514 IEEE80211_HT_CAP_SM_PS_SHIFT;
518 /* reserve and fill IE */
519 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
520 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
523 /* This function determines vht capability flags for the association
525 * Note - the function may set the owner of the MU-MIMO capability
527 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
529 struct ieee80211_supported_band *sband,
530 struct ieee80211_vht_cap *ap_vht_cap)
532 struct ieee80211_local *local = sdata->local;
535 struct ieee80211_sta_vht_cap vht_cap;
536 u32 mask, ap_bf_sts, our_bf_sts;
538 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
540 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
541 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
543 /* determine capability flags */
546 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
547 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
549 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
550 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
551 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
552 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
555 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
556 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
557 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
561 * Some APs apparently get confused if our capabilities are better
562 * than theirs, so restrict what we advertise in the assoc request.
564 if (!(ap_vht_cap->vht_cap_info &
565 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
566 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
567 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
568 else if (!(ap_vht_cap->vht_cap_info &
569 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
570 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
573 * If some other vif is using the MU-MIMO capablity we cannot associate
574 * using MU-MIMO - this will lead to contradictions in the group-id
576 * Ownership is defined since association request, in order to avoid
577 * simultaneous associations with MU-MIMO.
579 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
580 bool disable_mu_mimo = false;
581 struct ieee80211_sub_if_data *other;
583 list_for_each_entry_rcu(other, &local->interfaces, list) {
584 if (other->vif.mu_mimo_owner) {
585 disable_mu_mimo = true;
590 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
592 sdata->vif.mu_mimo_owner = true;
595 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
597 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
598 our_bf_sts = cap & mask;
600 if (ap_bf_sts < our_bf_sts) {
605 /* reserve and fill IE */
606 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
607 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
610 /* This function determines HE capability flags for the association
613 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
615 struct ieee80211_supported_band *sband)
618 const struct ieee80211_sta_he_cap *he_cap = NULL;
621 he_cap = ieee80211_get_he_sta_cap(sband);
626 * TODO: the 1 added is because this temporarily is under the EXTENSION
627 * IE. Get rid of it when it moves.
630 2 + 1 + sizeof(he_cap->he_cap_elem) +
631 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
632 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
633 he_cap->he_cap_elem.phy_cap_info);
634 pos = skb_put(skb, he_cap_size);
635 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
638 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
640 struct ieee80211_local *local = sdata->local;
641 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
642 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
644 struct ieee80211_mgmt *mgmt;
645 u8 *pos, qos_info, *ie_start;
646 size_t offset = 0, noffset;
647 int i, count, rates_len, supp_rates_len, shift;
649 struct ieee80211_supported_band *sband;
650 struct ieee80211_chanctx_conf *chanctx_conf;
651 struct ieee80211_channel *chan;
654 sdata_assert_lock(sdata);
657 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
658 if (WARN_ON(!chanctx_conf)) {
662 chan = chanctx_conf->def.chan;
664 sband = local->hw.wiphy->bands[chan->band];
665 shift = ieee80211_vif_get_shift(&sdata->vif);
667 if (assoc_data->supp_rates_len) {
669 * Get all rates supported by the device and the AP as
670 * some APs don't like getting a superset of their rates
671 * in the association request (e.g. D-Link DAP 1353 in
674 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
675 assoc_data->supp_rates,
676 assoc_data->supp_rates_len,
680 * In case AP not provide any supported rates information
681 * before association, we send information element(s) with
682 * all rates that we support.
685 for (i = 0; i < sband->n_bitrates; i++) {
691 skb = alloc_skb(local->hw.extra_tx_headroom +
692 sizeof(*mgmt) + /* bit too much but doesn't matter */
693 2 + assoc_data->ssid_len + /* SSID */
694 4 + rates_len + /* (extended) rates */
695 4 + /* power capability */
696 2 + 2 * sband->n_channels + /* supported channels */
697 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
698 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
699 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
700 sizeof(struct ieee80211_he_mcs_nss_supp) +
701 IEEE80211_HE_PPE_THRES_MAX_LEN +
702 assoc_data->ie_len + /* extra IEs */
703 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
709 skb_reserve(skb, local->hw.extra_tx_headroom);
711 capab = WLAN_CAPABILITY_ESS;
713 if (sband->band == NL80211_BAND_2GHZ) {
714 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
715 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
718 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
719 capab |= WLAN_CAPABILITY_PRIVACY;
721 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
722 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
723 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
725 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
726 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
728 mgmt = skb_put_zero(skb, 24);
729 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
730 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
731 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
733 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
735 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
736 IEEE80211_STYPE_REASSOC_REQ);
737 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
738 mgmt->u.reassoc_req.listen_interval =
739 cpu_to_le16(local->hw.conf.listen_interval);
740 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
744 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
745 IEEE80211_STYPE_ASSOC_REQ);
746 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
747 mgmt->u.assoc_req.listen_interval =
748 cpu_to_le16(local->hw.conf.listen_interval);
752 pos = skb_put(skb, 2 + assoc_data->ssid_len);
754 *pos++ = WLAN_EID_SSID;
755 *pos++ = assoc_data->ssid_len;
756 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
758 /* add all rates which were marked to be used above */
759 supp_rates_len = rates_len;
760 if (supp_rates_len > 8)
763 pos = skb_put(skb, supp_rates_len + 2);
764 *pos++ = WLAN_EID_SUPP_RATES;
765 *pos++ = supp_rates_len;
768 for (i = 0; i < sband->n_bitrates; i++) {
769 if (BIT(i) & rates) {
770 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
778 if (rates_len > count) {
779 pos = skb_put(skb, rates_len - count + 2);
780 *pos++ = WLAN_EID_EXT_SUPP_RATES;
781 *pos++ = rates_len - count;
783 for (i++; i < sband->n_bitrates; i++) {
784 if (BIT(i) & rates) {
786 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
793 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
794 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
795 pos = skb_put(skb, 4);
796 *pos++ = WLAN_EID_PWR_CAPABILITY;
798 *pos++ = 0; /* min tx power */
800 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
803 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
804 /* TODO: get this in reg domain format */
805 pos = skb_put(skb, 2 * sband->n_channels + 2);
806 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
807 *pos++ = 2 * sband->n_channels;
808 for (i = 0; i < sband->n_channels; i++) {
809 *pos++ = ieee80211_frequency_to_channel(
810 sband->channels[i].center_freq);
811 *pos++ = 1; /* one channel in the subband*/
815 /* Set MBSSID support for HE AP if needed */
816 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
817 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len) {
818 struct element *elem;
820 /* we know it's writable, cast away the const */
821 elem = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
825 /* We can probably assume both always true */
826 if (elem && elem->datalen >= 3)
827 elem->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
830 /* if present, add any custom IEs that go before HT */
831 if (assoc_data->ie_len) {
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,
860 noffset = ieee80211_ie_split_ric(assoc_data->ie,
863 ARRAY_SIZE(before_ht),
865 ARRAY_SIZE(after_ric),
867 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
871 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
872 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
873 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
875 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
876 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
877 sband, chan, sdata->smps_mode);
879 /* if present, add any custom IEs that go before VHT */
880 if (assoc_data->ie_len) {
881 static const u8 before_vht[] = {
883 * no need to list the ones split off before HT
886 WLAN_EID_BSS_COEX_2040,
887 WLAN_EID_EXT_CAPABILITY,
888 WLAN_EID_QOS_TRAFFIC_CAPA,
889 WLAN_EID_TIM_BCAST_REQ,
890 WLAN_EID_INTERWORKING,
891 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
894 /* RIC already taken above, so no need to handle here anymore */
895 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
896 before_vht, ARRAY_SIZE(before_vht),
898 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
902 /* if present, add any custom IEs that go before HE */
903 if (assoc_data->ie_len) {
904 static const u8 before_he[] = {
906 * no need to list the ones split off before VHT
909 WLAN_EID_OPMODE_NOTIF,
910 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
912 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
913 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
914 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
915 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
916 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
917 /* TODO: add 11ah/11aj/11ak elements */
920 /* RIC already taken above, so no need to handle here anymore */
921 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
922 before_he, ARRAY_SIZE(before_he),
924 pos = skb_put(skb, noffset - offset);
925 memcpy(pos, assoc_data->ie + offset, noffset - offset);
929 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
930 ieee80211_add_vht_ie(sdata, skb, sband,
931 &assoc_data->ap_vht_cap);
934 * If AP doesn't support HT, mark HE as disabled.
935 * If on the 5GHz band, make sure it supports VHT.
937 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
938 (sband->band == NL80211_BAND_5GHZ &&
939 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
940 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
942 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
943 ieee80211_add_he_ie(sdata, skb, sband);
945 /* if present, add any custom non-vendor IEs that go after HE */
946 if (assoc_data->ie_len) {
947 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
950 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
954 if (assoc_data->wmm) {
955 if (assoc_data->uapsd) {
956 qos_info = ifmgd->uapsd_queues;
957 qos_info |= (ifmgd->uapsd_max_sp_len <<
958 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
963 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
966 /* add any remaining custom (i.e. vendor specific here) IEs */
967 if (assoc_data->ie_len) {
968 noffset = assoc_data->ie_len;
969 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
972 if (assoc_data->fils_kek_len &&
973 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
978 pos = skb_tail_pointer(skb);
979 kfree(ifmgd->assoc_req_ies);
980 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
981 ifmgd->assoc_req_ies_len = pos - ie_start;
983 drv_mgd_prepare_tx(local, sdata, 0);
985 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
986 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
987 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
988 IEEE80211_TX_INTFL_MLME_CONN_TX;
989 ieee80211_tx_skb(sdata, skb);
992 void ieee80211_send_pspoll(struct ieee80211_local *local,
993 struct ieee80211_sub_if_data *sdata)
995 struct ieee80211_pspoll *pspoll;
998 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1002 pspoll = (struct ieee80211_pspoll *) skb->data;
1003 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1005 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1006 ieee80211_tx_skb(sdata, skb);
1009 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1010 struct ieee80211_sub_if_data *sdata,
1013 struct sk_buff *skb;
1014 struct ieee80211_hdr_3addr *nullfunc;
1015 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1017 /* Don't send NDPs when STA is connected HE */
1018 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1019 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
1022 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1023 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1027 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1029 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1031 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1032 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1034 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1035 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1037 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1038 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1040 ieee80211_tx_skb(sdata, skb);
1043 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1044 struct ieee80211_sub_if_data *sdata)
1046 struct sk_buff *skb;
1047 struct ieee80211_hdr *nullfunc;
1050 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1053 /* Don't send NDPs when connected HE */
1054 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1057 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1061 skb_reserve(skb, local->hw.extra_tx_headroom);
1063 nullfunc = skb_put_zero(skb, 30);
1064 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1065 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1066 nullfunc->frame_control = fc;
1067 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1068 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1069 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1070 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1072 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1073 ieee80211_tx_skb(sdata, skb);
1076 /* spectrum management related things */
1077 static void ieee80211_chswitch_work(struct work_struct *work)
1079 struct ieee80211_sub_if_data *sdata =
1080 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
1081 struct ieee80211_local *local = sdata->local;
1082 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1085 if (!ieee80211_sdata_running(sdata))
1089 mutex_lock(&local->mtx);
1090 mutex_lock(&local->chanctx_mtx);
1092 if (!ifmgd->associated)
1095 if (!sdata->vif.csa_active)
1099 * using reservation isn't immediate as it may be deferred until later
1100 * with multi-vif. once reservation is complete it will re-schedule the
1101 * work with no reserved_chanctx so verify chandef to check if it
1102 * completed successfully
1105 if (sdata->reserved_chanctx) {
1106 struct ieee80211_supported_band *sband = NULL;
1107 struct sta_info *mgd_sta = NULL;
1108 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1111 * with multi-vif csa driver may call ieee80211_csa_finish()
1112 * many times while waiting for other interfaces to use their
1115 if (sdata->reserved_ready)
1118 if (sdata->vif.bss_conf.chandef.width !=
1119 sdata->csa_chandef.width) {
1121 * For managed interface, we need to also update the AP
1122 * station bandwidth and align the rate scale algorithm
1123 * on the bandwidth change. Here we only consider the
1124 * bandwidth of the new channel definition (as channel
1125 * switch flow does not have the full HT/VHT/HE
1126 * information), assuming that if additional changes are
1127 * required they would be done as part of the processing
1128 * of the next beacon from the AP.
1130 switch (sdata->csa_chandef.width) {
1131 case NL80211_CHAN_WIDTH_20_NOHT:
1132 case NL80211_CHAN_WIDTH_20:
1134 bw = IEEE80211_STA_RX_BW_20;
1136 case NL80211_CHAN_WIDTH_40:
1137 bw = IEEE80211_STA_RX_BW_40;
1139 case NL80211_CHAN_WIDTH_80:
1140 bw = IEEE80211_STA_RX_BW_80;
1142 case NL80211_CHAN_WIDTH_80P80:
1143 case NL80211_CHAN_WIDTH_160:
1144 bw = IEEE80211_STA_RX_BW_160;
1148 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1150 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1153 if (sdata->vif.bss_conf.chandef.width >
1154 sdata->csa_chandef.width) {
1155 mgd_sta->sta.bandwidth = bw;
1156 rate_control_rate_update(local, sband, mgd_sta,
1157 IEEE80211_RC_BW_CHANGED);
1160 ret = ieee80211_vif_use_reserved_context(sdata);
1163 "failed to use reserved channel context, disconnecting (err=%d)\n",
1165 ieee80211_queue_work(&sdata->local->hw,
1166 &ifmgd->csa_connection_drop_work);
1170 if (sdata->vif.bss_conf.chandef.width <
1171 sdata->csa_chandef.width) {
1172 mgd_sta->sta.bandwidth = bw;
1173 rate_control_rate_update(local, sband, mgd_sta,
1174 IEEE80211_RC_BW_CHANGED);
1180 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1181 &sdata->csa_chandef)) {
1183 "failed to finalize channel switch, disconnecting\n");
1184 ieee80211_queue_work(&sdata->local->hw,
1185 &ifmgd->csa_connection_drop_work);
1189 ifmgd->csa_waiting_bcn = true;
1191 ieee80211_sta_reset_beacon_monitor(sdata);
1192 ieee80211_sta_reset_conn_monitor(sdata);
1195 mutex_unlock(&local->chanctx_mtx);
1196 mutex_unlock(&local->mtx);
1197 sdata_unlock(sdata);
1200 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1202 struct ieee80211_local *local = sdata->local;
1203 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1206 sdata_assert_lock(sdata);
1208 WARN_ON(!sdata->vif.csa_active);
1210 if (sdata->csa_block_tx) {
1211 ieee80211_wake_vif_queues(local, sdata,
1212 IEEE80211_QUEUE_STOP_REASON_CSA);
1213 sdata->csa_block_tx = false;
1216 sdata->vif.csa_active = false;
1217 ifmgd->csa_waiting_bcn = false;
1219 ret = drv_post_channel_switch(sdata);
1222 "driver post channel switch failed, disconnecting\n");
1223 ieee80211_queue_work(&local->hw,
1224 &ifmgd->csa_connection_drop_work);
1228 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1231 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1233 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1236 trace_api_chswitch_done(sdata, success);
1239 "driver channel switch failed, disconnecting\n");
1240 ieee80211_queue_work(&sdata->local->hw,
1241 &ifmgd->csa_connection_drop_work);
1243 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1246 EXPORT_SYMBOL(ieee80211_chswitch_done);
1248 static void ieee80211_chswitch_timer(struct timer_list *t)
1250 struct ieee80211_sub_if_data *sdata =
1251 from_timer(sdata, t, u.mgd.chswitch_timer);
1253 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1257 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1259 struct ieee80211_local *local = sdata->local;
1261 if (!local->ops->abort_channel_switch)
1264 mutex_lock(&local->mtx);
1266 mutex_lock(&local->chanctx_mtx);
1267 ieee80211_vif_unreserve_chanctx(sdata);
1268 mutex_unlock(&local->chanctx_mtx);
1270 if (sdata->csa_block_tx)
1271 ieee80211_wake_vif_queues(local, sdata,
1272 IEEE80211_QUEUE_STOP_REASON_CSA);
1274 sdata->csa_block_tx = false;
1275 sdata->vif.csa_active = false;
1277 mutex_unlock(&local->mtx);
1279 drv_abort_channel_switch(sdata);
1283 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1284 u64 timestamp, u32 device_timestamp,
1285 struct ieee802_11_elems *elems,
1288 struct ieee80211_local *local = sdata->local;
1289 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1290 struct cfg80211_bss *cbss = ifmgd->associated;
1291 struct ieee80211_chanctx_conf *conf;
1292 struct ieee80211_chanctx *chanctx;
1293 enum nl80211_band current_band;
1294 struct ieee80211_csa_ie csa_ie;
1295 struct ieee80211_channel_switch ch_switch;
1298 sdata_assert_lock(sdata);
1303 if (local->scanning)
1306 current_band = cbss->channel->band;
1307 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1309 ifmgd->associated->bssid, &csa_ie);
1312 ch_switch.timestamp = timestamp;
1313 ch_switch.device_timestamp = device_timestamp;
1314 ch_switch.block_tx = beacon ? csa_ie.mode : 0;
1315 ch_switch.chandef = csa_ie.chandef;
1316 ch_switch.count = csa_ie.count;
1317 ch_switch.delay = csa_ie.max_switch_time;
1321 ieee80211_queue_work(&local->hw,
1322 &ifmgd->csa_connection_drop_work);
1326 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1328 ieee80211_sta_abort_chanswitch(sdata);
1330 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1332 } else if (sdata->vif.csa_active || res) {
1333 /* disregard subsequent announcements if already processing */
1337 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1338 IEEE80211_CHAN_DISABLED)) {
1340 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1341 ifmgd->associated->bssid,
1342 csa_ie.chandef.chan->center_freq,
1343 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1344 csa_ie.chandef.center_freq2);
1345 ieee80211_queue_work(&local->hw,
1346 &ifmgd->csa_connection_drop_work);
1350 if (cfg80211_chandef_identical(&csa_ie.chandef,
1351 &sdata->vif.bss_conf.chandef) &&
1352 (!csa_ie.mode || !beacon)) {
1353 if (ifmgd->csa_ignored_same_chan)
1356 "AP %pM tries to chanswitch to same channel, ignore\n",
1357 ifmgd->associated->bssid);
1358 ifmgd->csa_ignored_same_chan = true;
1363 * Drop all TDLS peers - either we disconnect or move to a different
1364 * channel from this point on. There's no telling what our peer will do.
1365 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1366 * have an incompatible wider chandef.
1368 ieee80211_teardown_tdls_peers(sdata);
1370 mutex_lock(&local->mtx);
1371 mutex_lock(&local->chanctx_mtx);
1372 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1373 lockdep_is_held(&local->chanctx_mtx));
1376 "no channel context assigned to vif?, disconnecting\n");
1377 goto drop_connection;
1380 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1382 if (local->use_chanctx &&
1383 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1385 "driver doesn't support chan-switch with channel contexts\n");
1386 goto drop_connection;
1389 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1391 "preparing for channel switch failed, disconnecting\n");
1392 goto drop_connection;
1395 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1396 chanctx->mode, false);
1399 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1401 goto drop_connection;
1403 mutex_unlock(&local->chanctx_mtx);
1405 sdata->vif.csa_active = true;
1406 sdata->csa_chandef = csa_ie.chandef;
1407 sdata->csa_block_tx = ch_switch.block_tx;
1408 ifmgd->csa_ignored_same_chan = false;
1410 if (sdata->csa_block_tx)
1411 ieee80211_stop_vif_queues(local, sdata,
1412 IEEE80211_QUEUE_STOP_REASON_CSA);
1413 mutex_unlock(&local->mtx);
1415 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1418 if (local->ops->channel_switch) {
1419 /* use driver's channel switch callback */
1420 drv_channel_switch(local, sdata, &ch_switch);
1424 /* channel switch handled in software */
1425 if (csa_ie.count <= 1)
1426 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1428 mod_timer(&ifmgd->chswitch_timer,
1429 TU_TO_EXP_TIME((csa_ie.count - 1) *
1430 cbss->beacon_interval));
1434 * This is just so that the disconnect flow will know that
1435 * we were trying to switch channel and failed. In case the
1436 * mode is 1 (we are not allowed to Tx), we will know not to
1437 * send a deauthentication frame. Those two fields will be
1438 * reset when the disconnection worker runs.
1440 sdata->vif.csa_active = true;
1441 sdata->csa_block_tx = ch_switch.block_tx;
1443 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1444 mutex_unlock(&local->chanctx_mtx);
1445 mutex_unlock(&local->mtx);
1449 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1450 struct ieee80211_channel *channel,
1451 const u8 *country_ie, u8 country_ie_len,
1452 const u8 *pwr_constr_elem,
1453 int *chan_pwr, int *pwr_reduction)
1455 struct ieee80211_country_ie_triplet *triplet;
1456 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1457 int i, chan_increment;
1458 bool have_chan_pwr = false;
1461 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1464 triplet = (void *)(country_ie + 3);
1465 country_ie_len -= 3;
1467 switch (channel->band) {
1471 case NL80211_BAND_2GHZ:
1472 case NL80211_BAND_60GHZ:
1475 case NL80211_BAND_5GHZ:
1481 while (country_ie_len >= 3) {
1482 u8 first_channel = triplet->chans.first_channel;
1484 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1487 for (i = 0; i < triplet->chans.num_channels; i++) {
1488 if (first_channel + i * chan_increment == chan) {
1489 have_chan_pwr = true;
1490 *chan_pwr = triplet->chans.max_power;
1499 country_ie_len -= 3;
1502 if (have_chan_pwr && pwr_constr_elem)
1503 *pwr_reduction = *pwr_constr_elem;
1507 return have_chan_pwr;
1510 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1511 struct ieee80211_channel *channel,
1512 const u8 *cisco_dtpc_ie,
1515 /* From practical testing, the first data byte of the DTPC element
1516 * seems to contain the requested dBm level, and the CLI on Cisco
1517 * APs clearly state the range is -127 to 127 dBm, which indicates
1518 * a signed byte, although it seemingly never actually goes negative.
1519 * The other byte seems to always be zero.
1521 *pwr_level = (__s8)cisco_dtpc_ie[4];
1524 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1525 struct ieee80211_channel *channel,
1526 struct ieee80211_mgmt *mgmt,
1527 const u8 *country_ie, u8 country_ie_len,
1528 const u8 *pwr_constr_ie,
1529 const u8 *cisco_dtpc_ie)
1531 bool has_80211h_pwr = false, has_cisco_pwr = false;
1532 int chan_pwr = 0, pwr_reduction_80211h = 0;
1533 int pwr_level_cisco, pwr_level_80211h;
1535 __le16 capab = mgmt->u.probe_resp.capab_info;
1538 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1539 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1540 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1541 sdata, channel, country_ie, country_ie_len,
1542 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1544 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1547 if (cisco_dtpc_ie) {
1548 ieee80211_find_cisco_dtpc(
1549 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1550 has_cisco_pwr = true;
1553 if (!has_80211h_pwr && !has_cisco_pwr)
1556 /* If we have both 802.11h and Cisco DTPC, apply both limits
1557 * by picking the smallest of the two power levels advertised.
1559 if (has_80211h_pwr &&
1560 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1561 new_ap_level = pwr_level_80211h;
1563 if (sdata->ap_power_level == new_ap_level)
1567 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1568 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1569 sdata->u.mgd.bssid);
1570 } else { /* has_cisco_pwr is always true here. */
1571 new_ap_level = pwr_level_cisco;
1573 if (sdata->ap_power_level == new_ap_level)
1577 "Limiting TX power to %d dBm as advertised by %pM\n",
1578 pwr_level_cisco, sdata->u.mgd.bssid);
1581 sdata->ap_power_level = new_ap_level;
1582 if (__ieee80211_recalc_txpower(sdata))
1583 return BSS_CHANGED_TXPOWER;
1588 static void ieee80211_enable_ps(struct ieee80211_local *local,
1589 struct ieee80211_sub_if_data *sdata)
1591 struct ieee80211_conf *conf = &local->hw.conf;
1594 * If we are scanning right now then the parameters will
1595 * take effect when scan finishes.
1597 if (local->scanning)
1600 if (conf->dynamic_ps_timeout > 0 &&
1601 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1602 mod_timer(&local->dynamic_ps_timer, jiffies +
1603 msecs_to_jiffies(conf->dynamic_ps_timeout));
1605 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1606 ieee80211_send_nullfunc(local, sdata, true);
1608 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1609 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1612 conf->flags |= IEEE80211_CONF_PS;
1613 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1617 static void ieee80211_change_ps(struct ieee80211_local *local)
1619 struct ieee80211_conf *conf = &local->hw.conf;
1621 if (local->ps_sdata) {
1622 ieee80211_enable_ps(local, local->ps_sdata);
1623 } else if (conf->flags & IEEE80211_CONF_PS) {
1624 conf->flags &= ~IEEE80211_CONF_PS;
1625 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1626 del_timer_sync(&local->dynamic_ps_timer);
1627 cancel_work_sync(&local->dynamic_ps_enable_work);
1631 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1633 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1634 struct sta_info *sta = NULL;
1635 bool authorized = false;
1637 if (!mgd->powersave)
1643 if (!mgd->associated)
1646 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1649 if (!mgd->have_beacon)
1653 sta = sta_info_get(sdata, mgd->bssid);
1655 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1661 /* need to hold RTNL or interface lock */
1662 void ieee80211_recalc_ps(struct ieee80211_local *local)
1664 struct ieee80211_sub_if_data *sdata, *found = NULL;
1668 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1669 local->ps_sdata = NULL;
1673 list_for_each_entry(sdata, &local->interfaces, list) {
1674 if (!ieee80211_sdata_running(sdata))
1676 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1677 /* If an AP vif is found, then disable PS
1678 * by setting the count to zero thereby setting
1684 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1690 if (count == 1 && ieee80211_powersave_allowed(found)) {
1691 u8 dtimper = found->u.mgd.dtim_period;
1693 timeout = local->dynamic_ps_forced_timeout;
1696 local->hw.conf.dynamic_ps_timeout = timeout;
1698 /* If the TIM IE is invalid, pretend the value is 1 */
1702 local->hw.conf.ps_dtim_period = dtimper;
1703 local->ps_sdata = found;
1705 local->ps_sdata = NULL;
1708 ieee80211_change_ps(local);
1711 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1713 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1715 if (sdata->vif.bss_conf.ps != ps_allowed) {
1716 sdata->vif.bss_conf.ps = ps_allowed;
1717 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1721 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1723 struct ieee80211_local *local =
1724 container_of(work, struct ieee80211_local,
1725 dynamic_ps_disable_work);
1727 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1728 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1729 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1732 ieee80211_wake_queues_by_reason(&local->hw,
1733 IEEE80211_MAX_QUEUE_MAP,
1734 IEEE80211_QUEUE_STOP_REASON_PS,
1738 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1740 struct ieee80211_local *local =
1741 container_of(work, struct ieee80211_local,
1742 dynamic_ps_enable_work);
1743 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1744 struct ieee80211_if_managed *ifmgd;
1745 unsigned long flags;
1748 /* can only happen when PS was just disabled anyway */
1752 ifmgd = &sdata->u.mgd;
1754 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1757 if (local->hw.conf.dynamic_ps_timeout > 0) {
1758 /* don't enter PS if TX frames are pending */
1759 if (drv_tx_frames_pending(local)) {
1760 mod_timer(&local->dynamic_ps_timer, jiffies +
1762 local->hw.conf.dynamic_ps_timeout));
1767 * transmission can be stopped by others which leads to
1768 * dynamic_ps_timer expiry. Postpone the ps timer if it
1769 * is not the actual idle state.
1771 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1772 for (q = 0; q < local->hw.queues; q++) {
1773 if (local->queue_stop_reasons[q]) {
1774 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1776 mod_timer(&local->dynamic_ps_timer, jiffies +
1778 local->hw.conf.dynamic_ps_timeout));
1782 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1785 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1786 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1787 if (drv_tx_frames_pending(local)) {
1788 mod_timer(&local->dynamic_ps_timer, jiffies +
1790 local->hw.conf.dynamic_ps_timeout));
1792 ieee80211_send_nullfunc(local, sdata, true);
1793 /* Flush to get the tx status of nullfunc frame */
1794 ieee80211_flush_queues(local, sdata, false);
1798 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1799 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1800 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1801 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1802 local->hw.conf.flags |= IEEE80211_CONF_PS;
1803 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1807 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1809 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1811 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1814 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1816 struct delayed_work *delayed_work = to_delayed_work(work);
1817 struct ieee80211_sub_if_data *sdata =
1818 container_of(delayed_work, struct ieee80211_sub_if_data,
1819 dfs_cac_timer_work);
1820 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1822 mutex_lock(&sdata->local->mtx);
1823 if (sdata->wdev.cac_started) {
1824 ieee80211_vif_release_channel(sdata);
1825 cfg80211_cac_event(sdata->dev, &chandef,
1826 NL80211_RADAR_CAC_FINISHED,
1829 mutex_unlock(&sdata->local->mtx);
1833 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1835 struct ieee80211_local *local = sdata->local;
1836 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1840 if (local->hw.queues < IEEE80211_NUM_ACS)
1843 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1844 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1846 unsigned long now = jiffies;
1848 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1849 tx_tspec->admitted_time &&
1850 time_after(now, tx_tspec->time_slice_start + HZ)) {
1851 tx_tspec->consumed_tx_time = 0;
1852 tx_tspec->time_slice_start = now;
1854 if (tx_tspec->downgraded)
1856 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1859 switch (tx_tspec->action) {
1860 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1861 /* take the original parameters */
1862 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1864 "failed to set TX queue parameters for queue %d\n",
1866 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1867 tx_tspec->downgraded = false;
1870 case TX_TSPEC_ACTION_DOWNGRADE:
1871 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1872 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1876 /* downgrade next lower non-ACM AC */
1877 for (non_acm_ac = ac + 1;
1878 non_acm_ac < IEEE80211_NUM_ACS;
1880 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1882 /* Usually the loop will result in using BK even if it
1883 * requires admission control, but such a configuration
1884 * makes no sense and we have to transmit somehow - the
1885 * AC selection does the same thing.
1886 * If we started out trying to downgrade from BK, then
1887 * the extra condition here might be needed.
1889 if (non_acm_ac >= IEEE80211_NUM_ACS)
1890 non_acm_ac = IEEE80211_AC_BK;
1891 if (drv_conf_tx(local, sdata, ac,
1892 &sdata->tx_conf[non_acm_ac]))
1894 "failed to set TX queue parameters for queue %d\n",
1896 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1898 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1899 tx_tspec->time_slice_start + HZ - now + 1);
1901 case TX_TSPEC_ACTION_NONE:
1910 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1912 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1913 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1916 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1918 struct ieee80211_sub_if_data *sdata;
1920 sdata = container_of(work, struct ieee80211_sub_if_data,
1921 u.mgd.tx_tspec_wk.work);
1922 ieee80211_sta_handle_tspec_ac_params(sdata);
1927 ieee80211_sta_wmm_params(struct ieee80211_local *local,
1928 struct ieee80211_sub_if_data *sdata,
1929 const u8 *wmm_param, size_t wmm_param_len,
1930 const struct ieee80211_mu_edca_param_set *mu_edca)
1932 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1933 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1935 int count, mu_edca_count, ac;
1937 u8 uapsd_queues = 0;
1939 if (!local->ops->conf_tx)
1942 if (local->hw.queues < IEEE80211_NUM_ACS)
1948 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1951 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1952 uapsd_queues = ifmgd->uapsd_queues;
1954 count = wmm_param[6] & 0x0f;
1955 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1956 * if mu_edca was preset before and now it disappeared tell
1957 * the driver about it.
1959 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1960 if (count == ifmgd->wmm_last_param_set &&
1961 mu_edca_count == ifmgd->mu_edca_last_param_set)
1963 ifmgd->wmm_last_param_set = count;
1964 ifmgd->mu_edca_last_param_set = mu_edca_count;
1966 pos = wmm_param + 8;
1967 left = wmm_param_len - 8;
1969 memset(¶ms, 0, sizeof(params));
1972 for (; left >= 4; left -= 4, pos += 4) {
1973 int aci = (pos[0] >> 5) & 0x03;
1974 int acm = (pos[0] >> 4) & 0x01;
1979 ac = IEEE80211_AC_BK;
1981 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
1982 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1984 params[ac].mu_edca = !!mu_edca;
1986 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
1989 ac = IEEE80211_AC_VI;
1991 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
1992 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1994 params[ac].mu_edca = !!mu_edca;
1996 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
1999 ac = IEEE80211_AC_VO;
2001 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2002 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2004 params[ac].mu_edca = !!mu_edca;
2006 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2010 ac = IEEE80211_AC_BE;
2012 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2013 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2015 params[ac].mu_edca = !!mu_edca;
2017 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2021 params[ac].aifs = pos[0] & 0x0f;
2023 if (params[ac].aifs < 2) {
2025 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2026 params[ac].aifs, aci);
2027 params[ac].aifs = 2;
2029 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2030 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2031 params[ac].txop = get_unaligned_le16(pos + 2);
2032 params[ac].acm = acm;
2033 params[ac].uapsd = uapsd;
2035 if (params[ac].cw_min == 0 ||
2036 params[ac].cw_min > params[ac].cw_max) {
2038 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2039 params[ac].cw_min, params[ac].cw_max, aci);
2042 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2045 /* WMM specification requires all 4 ACIs. */
2046 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2047 if (params[ac].cw_min == 0) {
2049 "AP has invalid WMM params (missing AC %d), using defaults\n",
2055 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2057 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2059 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2060 params[ac].txop, params[ac].uapsd,
2061 ifmgd->tx_tspec[ac].downgraded);
2062 sdata->tx_conf[ac] = params[ac];
2063 if (!ifmgd->tx_tspec[ac].downgraded &&
2064 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2066 "failed to set TX queue parameters for AC %d\n",
2070 /* enable WMM or activate new settings */
2071 sdata->vif.bss_conf.qos = true;
2075 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2077 lockdep_assert_held(&sdata->local->mtx);
2079 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2080 ieee80211_run_deferred_scan(sdata->local);
2083 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2085 mutex_lock(&sdata->local->mtx);
2086 __ieee80211_stop_poll(sdata);
2087 mutex_unlock(&sdata->local->mtx);
2090 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2091 u16 capab, bool erp_valid, u8 erp)
2093 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2094 struct ieee80211_supported_band *sband;
2096 bool use_protection;
2097 bool use_short_preamble;
2098 bool use_short_slot;
2100 sband = ieee80211_get_sband(sdata);
2105 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2106 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2108 use_protection = false;
2109 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2112 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2113 if (sband->band == NL80211_BAND_5GHZ)
2114 use_short_slot = true;
2116 if (use_protection != bss_conf->use_cts_prot) {
2117 bss_conf->use_cts_prot = use_protection;
2118 changed |= BSS_CHANGED_ERP_CTS_PROT;
2121 if (use_short_preamble != bss_conf->use_short_preamble) {
2122 bss_conf->use_short_preamble = use_short_preamble;
2123 changed |= BSS_CHANGED_ERP_PREAMBLE;
2126 if (use_short_slot != bss_conf->use_short_slot) {
2127 bss_conf->use_short_slot = use_short_slot;
2128 changed |= BSS_CHANGED_ERP_SLOT;
2134 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2135 struct cfg80211_bss *cbss,
2136 u32 bss_info_changed)
2138 struct ieee80211_bss *bss = (void *)cbss->priv;
2139 struct ieee80211_local *local = sdata->local;
2140 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2142 bss_info_changed |= BSS_CHANGED_ASSOC;
2143 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2144 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2146 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2147 beacon_loss_count * bss_conf->beacon_int));
2149 sdata->u.mgd.associated = cbss;
2150 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2152 ieee80211_check_rate_mask(sdata);
2154 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2156 if (sdata->vif.p2p ||
2157 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2158 const struct cfg80211_bss_ies *ies;
2161 ies = rcu_dereference(cbss->ies);
2165 ret = cfg80211_get_p2p_attr(
2166 ies->data, ies->len,
2167 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2168 (u8 *) &bss_conf->p2p_noa_attr,
2169 sizeof(bss_conf->p2p_noa_attr));
2171 sdata->u.mgd.p2p_noa_index =
2172 bss_conf->p2p_noa_attr.index;
2173 bss_info_changed |= BSS_CHANGED_P2P_PS;
2179 /* just to be sure */
2180 ieee80211_stop_poll(sdata);
2182 ieee80211_led_assoc(local, 1);
2184 if (sdata->u.mgd.have_beacon) {
2186 * If the AP is buggy we may get here with no DTIM period
2187 * known, so assume it's 1 which is the only safe assumption
2188 * in that case, although if the TIM IE is broken powersave
2189 * probably just won't work at all.
2191 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2192 bss_conf->beacon_rate = bss->beacon_rate;
2193 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2195 bss_conf->beacon_rate = NULL;
2196 bss_conf->dtim_period = 0;
2199 bss_conf->assoc = 1;
2201 /* Tell the driver to monitor connection quality (if supported) */
2202 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2203 bss_conf->cqm_rssi_thold)
2204 bss_info_changed |= BSS_CHANGED_CQM;
2206 /* Enable ARP filtering */
2207 if (bss_conf->arp_addr_cnt)
2208 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2210 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2212 mutex_lock(&local->iflist_mtx);
2213 ieee80211_recalc_ps(local);
2214 mutex_unlock(&local->iflist_mtx);
2216 ieee80211_recalc_smps(sdata);
2217 ieee80211_recalc_ps_vif(sdata);
2219 netif_carrier_on(sdata->dev);
2222 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2223 u16 stype, u16 reason, bool tx,
2226 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2227 struct ieee80211_local *local = sdata->local;
2230 sdata_assert_lock(sdata);
2232 if (WARN_ON_ONCE(tx && !frame_buf))
2235 if (WARN_ON(!ifmgd->associated))
2238 ieee80211_stop_poll(sdata);
2240 ifmgd->associated = NULL;
2241 netif_carrier_off(sdata->dev);
2244 * if we want to get out of ps before disassoc (why?) we have
2245 * to do it before sending disassoc, as otherwise the null-packet
2248 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2249 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2250 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2252 local->ps_sdata = NULL;
2254 /* disable per-vif ps */
2255 ieee80211_recalc_ps_vif(sdata);
2257 /* make sure ongoing transmission finishes */
2261 * drop any frame before deauth/disassoc, this can be data or
2262 * management frame. Since we are disconnecting, we should not
2263 * insist sending these frames which can take time and delay
2264 * the disconnection and possible the roaming.
2267 ieee80211_flush_queues(local, sdata, true);
2269 /* deauthenticate/disassociate now */
2270 if (tx || frame_buf) {
2272 * In multi channel scenarios guarantee that the virtual
2273 * interface is granted immediate airtime to transmit the
2274 * deauthentication frame by calling mgd_prepare_tx, if the
2275 * driver requested so.
2277 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2278 !ifmgd->have_beacon)
2279 drv_mgd_prepare_tx(sdata->local, sdata, 0);
2281 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2282 ifmgd->bssid, stype, reason,
2286 /* flush out frame - make sure the deauth was actually sent */
2288 ieee80211_flush_queues(local, sdata, false);
2290 /* clear bssid only after building the needed mgmt frames */
2291 eth_zero_addr(ifmgd->bssid);
2293 /* remove AP and TDLS peers */
2294 sta_info_flush(sdata);
2296 /* finally reset all BSS / config parameters */
2297 changed |= ieee80211_reset_erp_info(sdata);
2299 ieee80211_led_assoc(local, 0);
2300 changed |= BSS_CHANGED_ASSOC;
2301 sdata->vif.bss_conf.assoc = false;
2303 ifmgd->p2p_noa_index = -1;
2304 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2305 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2307 /* on the next assoc, re-program HT/VHT parameters */
2308 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2309 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2310 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2311 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2313 /* reset MU-MIMO ownership and group data */
2314 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2315 sizeof(sdata->vif.bss_conf.mu_group.membership));
2316 memset(sdata->vif.bss_conf.mu_group.position, 0,
2317 sizeof(sdata->vif.bss_conf.mu_group.position));
2318 changed |= BSS_CHANGED_MU_GROUPS;
2319 sdata->vif.mu_mimo_owner = false;
2321 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2323 del_timer_sync(&local->dynamic_ps_timer);
2324 cancel_work_sync(&local->dynamic_ps_enable_work);
2326 /* Disable ARP filtering */
2327 if (sdata->vif.bss_conf.arp_addr_cnt)
2328 changed |= BSS_CHANGED_ARP_FILTER;
2330 sdata->vif.bss_conf.qos = false;
2331 changed |= BSS_CHANGED_QOS;
2333 /* The BSSID (not really interesting) and HT changed */
2334 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2335 ieee80211_bss_info_change_notify(sdata, changed);
2337 /* disassociated - set to defaults now */
2338 ieee80211_set_wmm_default(sdata, false, false);
2340 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2341 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2342 del_timer_sync(&sdata->u.mgd.timer);
2343 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2345 sdata->vif.bss_conf.dtim_period = 0;
2346 sdata->vif.bss_conf.beacon_rate = NULL;
2348 ifmgd->have_beacon = false;
2351 mutex_lock(&local->mtx);
2352 ieee80211_vif_release_channel(sdata);
2354 sdata->vif.csa_active = false;
2355 ifmgd->csa_waiting_bcn = false;
2356 ifmgd->csa_ignored_same_chan = false;
2357 if (sdata->csa_block_tx) {
2358 ieee80211_wake_vif_queues(local, sdata,
2359 IEEE80211_QUEUE_STOP_REASON_CSA);
2360 sdata->csa_block_tx = false;
2362 mutex_unlock(&local->mtx);
2364 /* existing TX TSPEC sessions no longer exist */
2365 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2366 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2368 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2371 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2372 struct ieee80211_hdr *hdr)
2375 * We can postpone the mgd.timer whenever receiving unicast frames
2376 * from AP because we know that the connection is working both ways
2377 * at that time. But multicast frames (and hence also beacons) must
2378 * be ignored here, because we need to trigger the timer during
2379 * data idle periods for sending the periodic probe request to the
2380 * AP we're connected to.
2382 if (is_multicast_ether_addr(hdr->addr1))
2385 ieee80211_sta_reset_conn_monitor(sdata);
2388 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2390 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2391 struct ieee80211_local *local = sdata->local;
2393 mutex_lock(&local->mtx);
2394 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2397 __ieee80211_stop_poll(sdata);
2399 mutex_lock(&local->iflist_mtx);
2400 ieee80211_recalc_ps(local);
2401 mutex_unlock(&local->iflist_mtx);
2403 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2407 * We've received a probe response, but are not sure whether
2408 * we have or will be receiving any beacons or data, so let's
2409 * schedule the timers again, just in case.
2411 ieee80211_sta_reset_beacon_monitor(sdata);
2413 mod_timer(&ifmgd->conn_mon_timer,
2414 round_jiffies_up(jiffies +
2415 IEEE80211_CONNECTION_IDLE_TIME));
2417 mutex_unlock(&local->mtx);
2420 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2421 struct ieee80211_hdr *hdr,
2424 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2425 u16 tid = ieee80211_get_tid(hdr);
2426 int ac = ieee80211_ac_from_tid(tid);
2427 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2428 unsigned long now = jiffies;
2430 if (likely(!tx_tspec->admitted_time))
2433 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2434 tx_tspec->consumed_tx_time = 0;
2435 tx_tspec->time_slice_start = now;
2437 if (tx_tspec->downgraded) {
2438 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2439 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2443 if (tx_tspec->downgraded)
2446 tx_tspec->consumed_tx_time += tx_time;
2448 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2449 tx_tspec->downgraded = true;
2450 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2451 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2455 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2456 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2458 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2460 if (!ieee80211_is_data(hdr->frame_control))
2463 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2464 sdata->u.mgd.probe_send_count > 0) {
2466 ieee80211_sta_reset_conn_monitor(sdata);
2468 sdata->u.mgd.nullfunc_failed = true;
2469 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2474 ieee80211_sta_reset_conn_monitor(sdata);
2477 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2478 const u8 *src, const u8 *dst,
2479 const u8 *ssid, size_t ssid_len,
2480 struct ieee80211_channel *channel)
2482 struct sk_buff *skb;
2484 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2485 ssid, ssid_len, NULL, 0,
2486 IEEE80211_PROBE_FLAG_DIRECTED);
2488 ieee80211_tx_skb(sdata, skb);
2491 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2493 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2495 u8 *dst = ifmgd->associated->bssid;
2496 u8 unicast_limit = max(1, max_probe_tries - 3);
2497 struct sta_info *sta;
2500 * Try sending broadcast probe requests for the last three
2501 * probe requests after the first ones failed since some
2502 * buggy APs only support broadcast probe requests.
2504 if (ifmgd->probe_send_count >= unicast_limit)
2508 * When the hardware reports an accurate Tx ACK status, it's
2509 * better to send a nullfunc frame instead of a probe request,
2510 * as it will kick us off the AP quickly if we aren't associated
2511 * anymore. The timeout will be reset if the frame is ACKed by
2514 ifmgd->probe_send_count++;
2517 mutex_lock(&sdata->local->sta_mtx);
2518 sta = sta_info_get(sdata, dst);
2520 ieee80211_check_fast_rx(sta);
2521 mutex_unlock(&sdata->local->sta_mtx);
2524 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2525 ifmgd->nullfunc_failed = false;
2526 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
2527 ifmgd->probe_send_count--;
2529 ieee80211_send_nullfunc(sdata->local, sdata, false);
2534 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
2535 if (WARN_ON_ONCE(ssid == NULL))
2540 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2542 ifmgd->associated->channel);
2546 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2547 run_again(sdata, ifmgd->probe_timeout);
2550 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2553 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2554 bool already = false;
2556 if (!ieee80211_sdata_running(sdata))
2561 if (!ifmgd->associated)
2564 mutex_lock(&sdata->local->mtx);
2566 if (sdata->local->tmp_channel || sdata->local->scanning) {
2567 mutex_unlock(&sdata->local->mtx);
2572 mlme_dbg_ratelimited(sdata,
2573 "detected beacon loss from AP (missed %d beacons) - probing\n",
2576 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2580 * The driver/our work has already reported this event or the
2581 * connection monitoring has kicked in and we have already sent
2582 * a probe request. Or maybe the AP died and the driver keeps
2583 * reporting until we disassociate...
2585 * In either case we have to ignore the current call to this
2586 * function (except for setting the correct probe reason bit)
2587 * because otherwise we would reset the timer every time and
2588 * never check whether we received a probe response!
2590 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2593 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2595 mutex_unlock(&sdata->local->mtx);
2600 mutex_lock(&sdata->local->iflist_mtx);
2601 ieee80211_recalc_ps(sdata->local);
2602 mutex_unlock(&sdata->local->iflist_mtx);
2604 ifmgd->probe_send_count = 0;
2605 ieee80211_mgd_probe_ap_send(sdata);
2607 sdata_unlock(sdata);
2610 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2611 struct ieee80211_vif *vif)
2613 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2614 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2615 struct cfg80211_bss *cbss;
2616 struct sk_buff *skb;
2620 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2623 sdata_assert_lock(sdata);
2625 if (ifmgd->associated)
2626 cbss = ifmgd->associated;
2627 else if (ifmgd->auth_data)
2628 cbss = ifmgd->auth_data->bss;
2629 else if (ifmgd->assoc_data)
2630 cbss = ifmgd->assoc_data->bss;
2635 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2636 if (WARN_ON_ONCE(ssid == NULL))
2641 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2642 (u32) -1, cbss->channel,
2644 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2649 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2651 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2652 const u8 *buf, size_t len, bool tx,
2655 struct ieee80211_event event = {
2657 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2658 .u.mlme.reason = reason,
2662 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2664 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2666 drv_event_callback(sdata->local, sdata, &event);
2669 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2671 struct ieee80211_local *local = sdata->local;
2672 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2673 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2677 if (!ifmgd->associated) {
2678 sdata_unlock(sdata);
2682 tx = !sdata->csa_block_tx;
2684 /* AP is probably out of range (or not reachable for another reason) so
2685 * remove the bss struct for that AP.
2687 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2689 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2690 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2692 mutex_lock(&local->mtx);
2693 sdata->vif.csa_active = false;
2694 ifmgd->csa_waiting_bcn = false;
2695 if (sdata->csa_block_tx) {
2696 ieee80211_wake_vif_queues(local, sdata,
2697 IEEE80211_QUEUE_STOP_REASON_CSA);
2698 sdata->csa_block_tx = false;
2700 mutex_unlock(&local->mtx);
2702 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2703 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2705 sdata_unlock(sdata);
2708 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2710 struct ieee80211_sub_if_data *sdata =
2711 container_of(work, struct ieee80211_sub_if_data,
2712 u.mgd.beacon_connection_loss_work);
2713 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2715 if (ifmgd->associated)
2716 ifmgd->beacon_loss_count++;
2718 if (ifmgd->connection_loss) {
2719 sdata_info(sdata, "Connection to AP %pM lost\n",
2721 __ieee80211_disconnect(sdata);
2723 ieee80211_mgd_probe_ap(sdata, true);
2727 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2729 struct ieee80211_sub_if_data *sdata =
2730 container_of(work, struct ieee80211_sub_if_data,
2731 u.mgd.csa_connection_drop_work);
2733 __ieee80211_disconnect(sdata);
2736 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2738 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2739 struct ieee80211_hw *hw = &sdata->local->hw;
2741 trace_api_beacon_loss(sdata);
2743 sdata->u.mgd.connection_loss = false;
2744 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2746 EXPORT_SYMBOL(ieee80211_beacon_loss);
2748 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2750 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2751 struct ieee80211_hw *hw = &sdata->local->hw;
2753 trace_api_connection_loss(sdata);
2755 sdata->u.mgd.connection_loss = true;
2756 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2758 EXPORT_SYMBOL(ieee80211_connection_loss);
2761 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2764 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2766 sdata_assert_lock(sdata);
2770 * we are not authenticated yet, the only timer that could be
2771 * running is the timeout for the authentication response which
2772 * which is not relevant anymore.
2774 del_timer_sync(&sdata->u.mgd.timer);
2775 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2777 eth_zero_addr(sdata->u.mgd.bssid);
2778 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2779 sdata->u.mgd.flags = 0;
2780 mutex_lock(&sdata->local->mtx);
2781 ieee80211_vif_release_channel(sdata);
2782 mutex_unlock(&sdata->local->mtx);
2785 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2787 sdata->u.mgd.auth_data = NULL;
2790 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2791 bool assoc, bool abandon)
2793 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2795 sdata_assert_lock(sdata);
2799 * we are not associated yet, the only timer that could be
2800 * running is the timeout for the association response which
2801 * which is not relevant anymore.
2803 del_timer_sync(&sdata->u.mgd.timer);
2804 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2806 eth_zero_addr(sdata->u.mgd.bssid);
2807 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2808 sdata->u.mgd.flags = 0;
2809 sdata->vif.mu_mimo_owner = false;
2811 mutex_lock(&sdata->local->mtx);
2812 ieee80211_vif_release_channel(sdata);
2813 mutex_unlock(&sdata->local->mtx);
2816 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2820 sdata->u.mgd.assoc_data = NULL;
2823 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2824 struct ieee80211_mgmt *mgmt, size_t len)
2826 struct ieee80211_local *local = sdata->local;
2827 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2829 struct ieee802_11_elems elems;
2832 pos = mgmt->u.auth.variable;
2833 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2834 mgmt->bssid, auth_data->bss->bssid);
2835 if (!elems.challenge)
2837 auth_data->expected_transaction = 4;
2838 drv_mgd_prepare_tx(sdata->local, sdata, 0);
2839 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2840 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2841 IEEE80211_TX_INTFL_MLME_CONN_TX;
2842 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2843 elems.challenge - 2, elems.challenge_len + 2,
2844 auth_data->bss->bssid, auth_data->bss->bssid,
2845 auth_data->key, auth_data->key_len,
2846 auth_data->key_idx, tx_flags);
2849 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2852 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2853 struct sta_info *sta;
2856 sdata_info(sdata, "authenticated\n");
2857 ifmgd->auth_data->done = true;
2858 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2859 ifmgd->auth_data->timeout_started = true;
2860 run_again(sdata, ifmgd->auth_data->timeout);
2862 /* move station state to auth */
2863 mutex_lock(&sdata->local->sta_mtx);
2864 sta = sta_info_get(sdata, bssid);
2866 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2870 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2871 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2877 mutex_unlock(&sdata->local->sta_mtx);
2881 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2882 struct ieee80211_mgmt *mgmt, size_t len)
2884 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2886 u16 auth_alg, auth_transaction, status_code;
2887 struct ieee80211_event event = {
2889 .u.mlme.data = AUTH_EVENT,
2892 sdata_assert_lock(sdata);
2897 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2900 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2902 if (!ether_addr_equal(bssid, mgmt->bssid))
2905 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2906 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2907 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2909 if (auth_alg != ifmgd->auth_data->algorithm ||
2910 (auth_alg != WLAN_AUTH_SAE &&
2911 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2912 (auth_alg == WLAN_AUTH_SAE &&
2913 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2914 auth_transaction > 2))) {
2915 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2916 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2918 ifmgd->auth_data->expected_transaction);
2922 if (status_code != WLAN_STATUS_SUCCESS) {
2923 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2924 mgmt->sa, status_code);
2925 ieee80211_destroy_auth_data(sdata, false);
2926 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2927 event.u.mlme.status = MLME_DENIED;
2928 event.u.mlme.reason = status_code;
2929 drv_event_callback(sdata->local, sdata, &event);
2933 switch (ifmgd->auth_data->algorithm) {
2934 case WLAN_AUTH_OPEN:
2935 case WLAN_AUTH_LEAP:
2938 case WLAN_AUTH_FILS_SK:
2939 case WLAN_AUTH_FILS_SK_PFS:
2940 case WLAN_AUTH_FILS_PK:
2942 case WLAN_AUTH_SHARED_KEY:
2943 if (ifmgd->auth_data->expected_transaction != 4) {
2944 ieee80211_auth_challenge(sdata, mgmt, len);
2945 /* need another frame */
2950 WARN_ONCE(1, "invalid auth alg %d",
2951 ifmgd->auth_data->algorithm);
2955 event.u.mlme.status = MLME_SUCCESS;
2956 drv_event_callback(sdata->local, sdata, &event);
2957 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
2958 (auth_transaction == 2 &&
2959 ifmgd->auth_data->expected_transaction == 2)) {
2960 if (!ieee80211_mark_sta_auth(sdata, bssid))
2962 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2963 auth_transaction == 2) {
2964 sdata_info(sdata, "SAE peer confirmed\n");
2965 ifmgd->auth_data->peer_confirmed = true;
2968 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2971 mutex_unlock(&sdata->local->sta_mtx);
2972 /* ignore frame -- wait for timeout */
2975 #define case_WLAN(type) \
2976 case WLAN_REASON_##type: return #type
2978 const char *ieee80211_get_reason_code_string(u16 reason_code)
2980 switch (reason_code) {
2981 case_WLAN(UNSPECIFIED);
2982 case_WLAN(PREV_AUTH_NOT_VALID);
2983 case_WLAN(DEAUTH_LEAVING);
2984 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2985 case_WLAN(DISASSOC_AP_BUSY);
2986 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2987 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2988 case_WLAN(DISASSOC_STA_HAS_LEFT);
2989 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2990 case_WLAN(DISASSOC_BAD_POWER);
2991 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2992 case_WLAN(INVALID_IE);
2993 case_WLAN(MIC_FAILURE);
2994 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2995 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2996 case_WLAN(IE_DIFFERENT);
2997 case_WLAN(INVALID_GROUP_CIPHER);
2998 case_WLAN(INVALID_PAIRWISE_CIPHER);
2999 case_WLAN(INVALID_AKMP);
3000 case_WLAN(UNSUPP_RSN_VERSION);
3001 case_WLAN(INVALID_RSN_IE_CAP);
3002 case_WLAN(IEEE8021X_FAILED);
3003 case_WLAN(CIPHER_SUITE_REJECTED);
3004 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3005 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3006 case_WLAN(DISASSOC_LOW_ACK);
3007 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3008 case_WLAN(QSTA_LEAVE_QBSS);
3009 case_WLAN(QSTA_NOT_USE);
3010 case_WLAN(QSTA_REQUIRE_SETUP);
3011 case_WLAN(QSTA_TIMEOUT);
3012 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3013 case_WLAN(MESH_PEER_CANCELED);
3014 case_WLAN(MESH_MAX_PEERS);
3015 case_WLAN(MESH_CONFIG);
3016 case_WLAN(MESH_CLOSE);
3017 case_WLAN(MESH_MAX_RETRIES);
3018 case_WLAN(MESH_CONFIRM_TIMEOUT);
3019 case_WLAN(MESH_INVALID_GTK);
3020 case_WLAN(MESH_INCONSISTENT_PARAM);
3021 case_WLAN(MESH_INVALID_SECURITY);
3022 case_WLAN(MESH_PATH_ERROR);
3023 case_WLAN(MESH_PATH_NOFORWARD);
3024 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3025 case_WLAN(MAC_EXISTS_IN_MBSS);
3026 case_WLAN(MESH_CHAN_REGULATORY);
3027 case_WLAN(MESH_CHAN);
3028 default: return "<unknown>";
3032 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3033 struct ieee80211_mgmt *mgmt, size_t len)
3035 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3036 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3038 sdata_assert_lock(sdata);
3043 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3044 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3048 if (ifmgd->associated &&
3049 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3050 const u8 *bssid = ifmgd->associated->bssid;
3052 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3054 ieee80211_get_reason_code_string(reason_code));
3056 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3058 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3063 if (ifmgd->assoc_data &&
3064 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3065 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3068 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3070 ieee80211_get_reason_code_string(reason_code));
3072 ieee80211_destroy_assoc_data(sdata, false, true);
3074 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3080 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3081 struct ieee80211_mgmt *mgmt, size_t len)
3083 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3086 sdata_assert_lock(sdata);
3091 if (!ifmgd->associated ||
3092 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3095 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3097 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3098 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3102 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3103 mgmt->sa, reason_code,
3104 ieee80211_get_reason_code_string(reason_code));
3106 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3108 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
3111 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3112 u8 *supp_rates, unsigned int supp_rates_len,
3113 u32 *rates, u32 *basic_rates,
3114 bool *have_higher_than_11mbit,
3115 int *min_rate, int *min_rate_index,
3120 for (i = 0; i < supp_rates_len; i++) {
3121 int rate = supp_rates[i] & 0x7f;
3122 bool is_basic = !!(supp_rates[i] & 0x80);
3124 if ((rate * 5 * (1 << shift)) > 110)
3125 *have_higher_than_11mbit = true;
3128 * Skip HT and VHT BSS membership selectors since they're not
3131 * Note: Even though the membership selector and the basic
3132 * rate flag share the same bit, they are not exactly
3135 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3136 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
3139 for (j = 0; j < sband->n_bitrates; j++) {
3140 struct ieee80211_rate *br;
3143 br = &sband->bitrates[j];
3145 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3146 if (brate == rate) {
3149 *basic_rates |= BIT(j);
3150 if ((rate * 5) < *min_rate) {
3151 *min_rate = rate * 5;
3152 *min_rate_index = j;
3160 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3161 const struct ieee802_11_elems *elems)
3163 if (elems->ext_capab_len < 10)
3166 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3169 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3170 IEEE80211_HE_MAC_CAP0_TWT_RES;
3173 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3174 struct sta_info *sta,
3175 struct ieee802_11_elems *elems)
3177 bool twt = ieee80211_twt_req_supported(sta, elems);
3179 if (sdata->vif.bss_conf.twt_requester != twt) {
3180 sdata->vif.bss_conf.twt_requester = twt;
3181 return BSS_CHANGED_TWT;
3186 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3187 struct cfg80211_bss *cbss,
3188 struct ieee80211_mgmt *mgmt, size_t len)
3190 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3191 struct ieee80211_local *local = sdata->local;
3192 struct ieee80211_supported_band *sband;
3193 struct sta_info *sta;
3195 u16 capab_info, aid;
3196 struct ieee802_11_elems elems;
3197 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3198 const struct cfg80211_bss_ies *bss_ies = NULL;
3199 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3204 /* AssocResp and ReassocResp have identical structure */
3206 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3207 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3210 * The 5 MSB of the AID field are reserved
3211 * (802.11-2016 9.4.1.8 AID field)
3215 ifmgd->broken_ap = false;
3217 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3218 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3221 ifmgd->broken_ap = true;
3224 pos = mgmt->u.assoc_resp.variable;
3225 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3226 mgmt->bssid, assoc_data->bss->bssid);
3228 if (!elems.supp_rates) {
3229 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3234 ifmgd->tdls_chan_switch_prohibited =
3235 elems.ext_capab && elems.ext_capab_len >= 5 &&
3236 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3239 * Some APs are erroneously not including some information in their
3240 * (re)association response frames. Try to recover by using the data
3241 * from the beacon or probe response. This seems to afflict mobile
3242 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3243 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3245 if ((assoc_data->wmm && !elems.wmm_param) ||
3246 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3247 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3248 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3249 (!elems.vht_cap_elem || !elems.vht_operation))) {
3250 const struct cfg80211_bss_ies *ies;
3251 struct ieee802_11_elems bss_elems;
3254 ies = rcu_dereference(cbss->ies);
3256 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3262 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3265 assoc_data->bss->bssid);
3266 if (assoc_data->wmm &&
3267 !elems.wmm_param && bss_elems.wmm_param) {
3268 elems.wmm_param = bss_elems.wmm_param;
3270 "AP bug: WMM param missing from AssocResp\n");
3274 * Also check if we requested HT/VHT, otherwise the AP doesn't
3275 * have to include the IEs in the (re)association response.
3277 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3278 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3279 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3281 "AP bug: HT capability missing from AssocResp\n");
3283 if (!elems.ht_operation && bss_elems.ht_operation &&
3284 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3285 elems.ht_operation = bss_elems.ht_operation;
3287 "AP bug: HT operation missing from AssocResp\n");
3289 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3290 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3291 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3293 "AP bug: VHT capa missing from AssocResp\n");
3295 if (!elems.vht_operation && bss_elems.vht_operation &&
3296 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3297 elems.vht_operation = bss_elems.vht_operation;
3299 "AP bug: VHT operation missing from AssocResp\n");
3304 * We previously checked these in the beacon/probe response, so
3305 * they should be present here. This is just a safety net.
3307 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3308 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3310 "HT AP is missing WMM params or HT capability/operation\n");
3315 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3316 (!elems.vht_cap_elem || !elems.vht_operation)) {
3318 "VHT AP is missing VHT capability/operation\n");
3323 mutex_lock(&sdata->local->sta_mtx);
3325 * station info was already allocated and inserted before
3326 * the association and should be available to us
3328 sta = sta_info_get(sdata, cbss->bssid);
3329 if (WARN_ON(!sta)) {
3330 mutex_unlock(&sdata->local->sta_mtx);
3335 sband = ieee80211_get_sband(sdata);
3337 mutex_unlock(&sdata->local->sta_mtx);
3342 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3343 (!elems.he_cap || !elems.he_operation)) {
3344 mutex_unlock(&sdata->local->sta_mtx);
3346 "HE AP is missing HE capability/operation\n");
3351 /* Set up internal HT/VHT capabilities */
3352 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3353 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3354 elems.ht_cap_elem, sta);
3356 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3357 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3358 elems.vht_cap_elem, sta);
3360 if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3362 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3367 bss_conf->he_support = sta->sta.he_cap.has_he;
3368 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
3370 bss_conf->he_support = false;
3371 bss_conf->twt_requester = false;
3374 if (bss_conf->he_support) {
3375 bss_conf->bss_color =
3376 le32_get_bits(elems.he_operation->he_oper_params,
3377 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3379 bss_conf->htc_trig_based_pkt_ext =
3380 le32_get_bits(elems.he_operation->he_oper_params,
3381 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3382 bss_conf->frame_time_rts_th =
3383 le32_get_bits(elems.he_operation->he_oper_params,
3384 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3386 bss_conf->multi_sta_back_32bit =
3387 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3388 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3390 bss_conf->ack_enabled =
3391 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3392 IEEE80211_HE_MAC_CAP2_ACK_EN;
3394 bss_conf->uora_exists = !!elems.uora_element;
3395 if (elems.uora_element)
3396 bss_conf->uora_ocw_range = elems.uora_element[0];
3398 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems.he_operation);
3399 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems.he_spr);
3400 /* TODO: OPEN: what happens if BSS color disable is set? */
3403 if (cbss->transmitted_bss) {
3404 bss_conf->nontransmitted = true;
3405 ether_addr_copy(bss_conf->transmitter_bssid,
3406 cbss->transmitted_bss->bssid);
3407 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3408 bss_conf->bssid_index = cbss->bssid_index;
3412 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3413 * in their association response, so ignore that data for our own
3414 * configuration. If it changed since the last beacon, we'll get the
3415 * next beacon and update then.
3419 * If an operating mode notification IE is present, override the
3420 * NSS calculation (that would be done in rate_control_rate_init())
3421 * and use the # of streams from that element.
3423 if (elems.opmode_notif &&
3424 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3427 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3428 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3430 sta->sta.rx_nss = nss;
3433 rate_control_rate_init(sta);
3435 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3436 set_sta_flag(sta, WLAN_STA_MFP);
3437 sta->sta.mfp = true;
3439 sta->sta.mfp = false;
3442 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
3444 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3445 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3446 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3449 "failed to move station %pM to desired state\n",
3451 WARN_ON(__sta_info_destroy(sta));
3452 mutex_unlock(&sdata->local->sta_mtx);
3457 mutex_unlock(&sdata->local->sta_mtx);
3460 * Always handle WMM once after association regardless
3461 * of the first value the AP uses. Setting -1 here has
3462 * that effect because the AP values is an unsigned
3465 ifmgd->wmm_last_param_set = -1;
3466 ifmgd->mu_edca_last_param_set = -1;
3468 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3469 ieee80211_set_wmm_default(sdata, false, false);
3470 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3471 elems.wmm_param_len,
3472 elems.mu_edca_param_set)) {
3473 /* still enable QoS since we might have HT/VHT */
3474 ieee80211_set_wmm_default(sdata, false, true);
3475 /* set the disable-WMM flag in this case to disable
3476 * tracking WMM parameter changes in the beacon if
3477 * the parameters weren't actually valid. Doing so
3478 * avoids changing parameters very strangely when
3479 * the AP is going back and forth between valid and
3480 * invalid parameters.
3482 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3484 changed |= BSS_CHANGED_QOS;
3486 if (elems.max_idle_period_ie) {
3487 bss_conf->max_idle_period =
3488 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3489 bss_conf->protected_keep_alive =
3490 !!(elems.max_idle_period_ie->idle_options &
3491 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3492 changed |= BSS_CHANGED_KEEP_ALIVE;
3494 bss_conf->max_idle_period = 0;
3495 bss_conf->protected_keep_alive = false;
3498 /* set AID and assoc capability,
3499 * ieee80211_set_associated() will tell the driver */
3500 bss_conf->aid = aid;
3501 bss_conf->assoc_capability = capab_info;
3502 ieee80211_set_associated(sdata, cbss, changed);
3505 * If we're using 4-addr mode, let the AP know that we're
3506 * doing so, so that it can create the STA VLAN on its side
3508 if (ifmgd->use_4addr)
3509 ieee80211_send_4addr_nullfunc(local, sdata);
3512 * Start timer to probe the connection to the AP now.
3513 * Also start the timer that will detect beacon loss.
3515 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
3516 ieee80211_sta_reset_beacon_monitor(sdata);
3524 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3525 struct ieee80211_mgmt *mgmt,
3528 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3529 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3530 u16 capab_info, status_code, aid;
3531 struct ieee802_11_elems elems;
3532 int ac, uapsd_queues = -1;
3535 struct cfg80211_bss *bss;
3536 struct ieee80211_event event = {
3538 .u.mlme.data = ASSOC_EVENT,
3541 sdata_assert_lock(sdata);
3545 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3549 * AssocResp and ReassocResp have identical structure, so process both
3550 * of them in this function.
3556 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3557 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3558 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3559 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3562 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3563 reassoc ? "Rea" : "A", mgmt->sa,
3564 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3566 if (assoc_data->fils_kek_len &&
3567 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3570 pos = mgmt->u.assoc_resp.variable;
3571 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3572 mgmt->bssid, assoc_data->bss->bssid);
3574 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3575 elems.timeout_int &&
3576 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3578 tu = le32_to_cpu(elems.timeout_int->value);
3579 ms = tu * 1024 / 1000;
3581 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3583 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3584 assoc_data->timeout_started = true;
3585 if (ms > IEEE80211_ASSOC_TIMEOUT)
3586 run_again(sdata, assoc_data->timeout);
3590 bss = assoc_data->bss;
3592 if (status_code != WLAN_STATUS_SUCCESS) {
3593 sdata_info(sdata, "%pM denied association (code=%d)\n",
3594 mgmt->sa, status_code);
3595 ieee80211_destroy_assoc_data(sdata, false, false);
3596 event.u.mlme.status = MLME_DENIED;
3597 event.u.mlme.reason = status_code;
3598 drv_event_callback(sdata->local, sdata, &event);
3600 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
3601 /* oops -- internal error -- send timeout for now */
3602 ieee80211_destroy_assoc_data(sdata, false, false);
3603 cfg80211_assoc_timeout(sdata->dev, bss);
3606 event.u.mlme.status = MLME_SUCCESS;
3607 drv_event_callback(sdata->local, sdata, &event);
3608 sdata_info(sdata, "associated\n");
3611 * destroy assoc_data afterwards, as otherwise an idle
3612 * recalc after assoc_data is NULL but before associated
3613 * is set can cause the interface to go idle
3615 ieee80211_destroy_assoc_data(sdata, true, false);
3617 /* get uapsd queues configuration */
3619 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3620 if (sdata->tx_conf[ac].uapsd)
3621 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3624 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues,
3625 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3628 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3629 struct ieee80211_mgmt *mgmt, size_t len,
3630 struct ieee80211_rx_status *rx_status)
3632 struct ieee80211_local *local = sdata->local;
3633 struct ieee80211_bss *bss;
3634 struct ieee80211_channel *channel;
3636 sdata_assert_lock(sdata);
3638 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3642 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3644 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3645 ieee80211_rx_bss_put(local, bss);
3650 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3651 struct sk_buff *skb)
3653 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3654 struct ieee80211_if_managed *ifmgd;
3655 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3656 size_t baselen, len = skb->len;
3658 ifmgd = &sdata->u.mgd;
3660 sdata_assert_lock(sdata);
3662 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
3663 return; /* ignore ProbeResp to foreign address */
3665 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3669 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3671 if (ifmgd->associated &&
3672 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3673 ieee80211_reset_ap_probe(sdata);
3677 * This is the canonical list of information elements we care about,
3678 * the filter code also gives us all changes to the Microsoft OUI
3679 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3680 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3681 * changes to requested client power.
3683 * We implement beacon filtering in software since that means we can
3684 * avoid processing the frame here and in cfg80211, and userspace
3685 * will not be able to tell whether the hardware supports it or not.
3687 * XXX: This list needs to be dynamic -- userspace needs to be able to
3688 * add items it requires. It also needs to be able to tell us to
3689 * look out for other vendor IEs.
3691 static const u64 care_about_ies =
3692 (1ULL << WLAN_EID_COUNTRY) |
3693 (1ULL << WLAN_EID_ERP_INFO) |
3694 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3695 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3696 (1ULL << WLAN_EID_HT_CAPABILITY) |
3697 (1ULL << WLAN_EID_HT_OPERATION) |
3698 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3700 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3701 struct ieee80211_if_managed *ifmgd,
3702 struct ieee80211_bss_conf *bss_conf,
3703 struct ieee80211_local *local,
3704 struct ieee80211_rx_status *rx_status)
3706 /* Track average RSSI from the Beacon frames of the current AP */
3708 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3709 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3710 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3711 ifmgd->last_cqm_event_signal = 0;
3712 ifmgd->count_beacon_signal = 1;
3713 ifmgd->last_ave_beacon_signal = 0;
3715 ifmgd->count_beacon_signal++;
3718 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3720 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3721 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3722 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3723 int last_sig = ifmgd->last_ave_beacon_signal;
3724 struct ieee80211_event event = {
3729 * if signal crosses either of the boundaries, invoke callback
3730 * with appropriate parameters
3732 if (sig > ifmgd->rssi_max_thold &&
3733 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3734 ifmgd->last_ave_beacon_signal = sig;
3735 event.u.rssi.data = RSSI_EVENT_HIGH;
3736 drv_event_callback(local, sdata, &event);
3737 } else if (sig < ifmgd->rssi_min_thold &&
3738 (last_sig >= ifmgd->rssi_max_thold ||
3740 ifmgd->last_ave_beacon_signal = sig;
3741 event.u.rssi.data = RSSI_EVENT_LOW;
3742 drv_event_callback(local, sdata, &event);
3746 if (bss_conf->cqm_rssi_thold &&
3747 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3748 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3749 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3750 int last_event = ifmgd->last_cqm_event_signal;
3751 int thold = bss_conf->cqm_rssi_thold;
3752 int hyst = bss_conf->cqm_rssi_hyst;
3755 (last_event == 0 || sig < last_event - hyst)) {
3756 ifmgd->last_cqm_event_signal = sig;
3757 ieee80211_cqm_rssi_notify(
3759 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3761 } else if (sig > thold &&
3762 (last_event == 0 || sig > last_event + hyst)) {
3763 ifmgd->last_cqm_event_signal = sig;
3764 ieee80211_cqm_rssi_notify(
3766 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3771 if (bss_conf->cqm_rssi_low &&
3772 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3773 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3774 int last_event = ifmgd->last_cqm_event_signal;
3775 int low = bss_conf->cqm_rssi_low;
3776 int high = bss_conf->cqm_rssi_high;
3779 (last_event == 0 || last_event >= low)) {
3780 ifmgd->last_cqm_event_signal = sig;
3781 ieee80211_cqm_rssi_notify(
3783 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3785 } else if (sig > high &&
3786 (last_event == 0 || last_event <= high)) {
3787 ifmgd->last_cqm_event_signal = sig;
3788 ieee80211_cqm_rssi_notify(
3790 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3796 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3797 struct cfg80211_bss *bss)
3799 if (ether_addr_equal(tx_bssid, bss->bssid))
3801 if (!bss->transmitted_bss)
3803 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3806 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3807 struct ieee80211_mgmt *mgmt, size_t len,
3808 struct ieee80211_rx_status *rx_status)
3810 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3811 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3813 struct ieee802_11_elems elems;
3814 struct ieee80211_local *local = sdata->local;
3815 struct ieee80211_chanctx_conf *chanctx_conf;
3816 struct ieee80211_channel *chan;
3817 struct sta_info *sta;
3823 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3825 sdata_assert_lock(sdata);
3827 /* Process beacon from the current BSS */
3828 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3833 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3834 if (!chanctx_conf) {
3839 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3843 chan = chanctx_conf->def.chan;
3846 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3847 ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) {
3848 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3849 len - baselen, false, &elems,
3851 ifmgd->assoc_data->bss->bssid);
3853 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3855 if (elems.dtim_period)
3856 ifmgd->dtim_period = elems.dtim_period;
3857 ifmgd->have_beacon = true;
3858 ifmgd->assoc_data->need_beacon = false;
3859 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3860 sdata->vif.bss_conf.sync_tsf =
3861 le64_to_cpu(mgmt->u.beacon.timestamp);
3862 sdata->vif.bss_conf.sync_device_ts =
3863 rx_status->device_timestamp;
3864 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
3867 if (elems.mbssid_config_ie)
3868 bss_conf->profile_periodicity =
3869 elems.mbssid_config_ie->profile_periodicity;
3871 if (elems.ext_capab_len >= 11 &&
3872 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
3873 bss_conf->ema_ap = true;
3875 /* continue assoc process */
3876 ifmgd->assoc_data->timeout = jiffies;
3877 ifmgd->assoc_data->timeout_started = true;
3878 run_again(sdata, ifmgd->assoc_data->timeout);
3882 if (!ifmgd->associated ||
3883 !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated))
3885 bssid = ifmgd->associated->bssid;
3887 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3888 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3891 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
3892 mlme_dbg_ratelimited(sdata,
3893 "cancelling AP probe due to a received beacon\n");
3894 ieee80211_reset_ap_probe(sdata);
3898 * Push the beacon loss detection into the future since
3899 * we are processing a beacon from the AP just now.
3901 ieee80211_sta_reset_beacon_monitor(sdata);
3903 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3904 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
3905 len - baselen, false, &elems,
3906 care_about_ies, ncrc,
3907 mgmt->bssid, bssid);
3909 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3910 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3911 if (local->hw.conf.dynamic_ps_timeout > 0) {
3912 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3913 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3914 ieee80211_hw_config(local,
3915 IEEE80211_CONF_CHANGE_PS);
3917 ieee80211_send_nullfunc(local, sdata, false);
3918 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3919 local->pspolling = true;
3922 * Here is assumed that the driver will be
3923 * able to send ps-poll frame and receive a
3924 * response even though power save mode is
3925 * enabled, but some drivers might require
3926 * to disable power save here. This needs
3927 * to be investigated.
3929 ieee80211_send_pspoll(local, sdata);
3933 if (sdata->vif.p2p ||
3934 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
3935 struct ieee80211_p2p_noa_attr noa = {};
3938 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3940 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
3941 (u8 *) &noa, sizeof(noa));
3943 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3944 /* valid noa_attr and index changed */
3945 sdata->u.mgd.p2p_noa_index = noa.index;
3946 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3947 changed |= BSS_CHANGED_P2P_PS;
3949 * make sure we update all information, the CRC
3950 * mechanism doesn't look at P2P attributes.
3952 ifmgd->beacon_crc_valid = false;
3954 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3955 /* noa_attr not found and we had valid noa_attr before */
3956 sdata->u.mgd.p2p_noa_index = -1;
3957 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
3958 changed |= BSS_CHANGED_P2P_PS;
3959 ifmgd->beacon_crc_valid = false;
3963 if (ifmgd->csa_waiting_bcn)
3964 ieee80211_chswitch_post_beacon(sdata);
3967 * Update beacon timing and dtim count on every beacon appearance. This
3968 * will allow the driver to use the most updated values. Do it before
3969 * comparing this one with last received beacon.
3970 * IMPORTANT: These parameters would possibly be out of sync by the time
3971 * the driver will use them. The synchronized view is currently
3972 * guaranteed only in certain callbacks.
3974 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3975 sdata->vif.bss_conf.sync_tsf =
3976 le64_to_cpu(mgmt->u.beacon.timestamp);
3977 sdata->vif.bss_conf.sync_device_ts =
3978 rx_status->device_timestamp;
3979 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
3982 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
3984 ifmgd->beacon_crc = ncrc;
3985 ifmgd->beacon_crc_valid = true;
3987 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3989 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
3990 rx_status->device_timestamp,
3993 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3994 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3995 elems.wmm_param_len,
3996 elems.mu_edca_param_set))
3997 changed |= BSS_CHANGED_QOS;
4000 * If we haven't had a beacon before, tell the driver about the
4001 * DTIM period (and beacon timing if desired) now.
4003 if (!ifmgd->have_beacon) {
4004 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4005 bss_conf->dtim_period = elems.dtim_period ?: 1;
4007 changed |= BSS_CHANGED_BEACON_INFO;
4008 ifmgd->have_beacon = true;
4010 mutex_lock(&local->iflist_mtx);
4011 ieee80211_recalc_ps(local);
4012 mutex_unlock(&local->iflist_mtx);
4014 ieee80211_recalc_ps_vif(sdata);
4017 if (elems.erp_info) {
4019 erp_value = elems.erp_info[0];
4023 changed |= ieee80211_handle_bss_capability(sdata,
4024 le16_to_cpu(mgmt->u.beacon.capab_info),
4025 erp_valid, erp_value);
4027 mutex_lock(&local->sta_mtx);
4028 sta = sta_info_get(sdata, bssid);
4030 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
4032 if (ieee80211_config_bw(sdata, sta,
4033 elems.ht_cap_elem, elems.ht_operation,
4034 elems.vht_operation, elems.he_operation,
4036 mutex_unlock(&local->sta_mtx);
4038 "failed to follow AP %pM bandwidth change, disconnect\n",
4040 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4041 WLAN_REASON_DEAUTH_LEAVING,
4043 ieee80211_report_disconnect(sdata, deauth_buf,
4044 sizeof(deauth_buf), true,
4045 WLAN_REASON_DEAUTH_LEAVING);
4049 if (sta && elems.opmode_notif)
4050 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
4052 mutex_unlock(&local->sta_mtx);
4054 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4056 elems.country_elem_len,
4057 elems.pwr_constr_elem,
4058 elems.cisco_dtpc_elem);
4060 ieee80211_bss_info_change_notify(sdata, changed);
4063 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4064 struct sk_buff *skb)
4066 struct ieee80211_rx_status *rx_status;
4067 struct ieee80211_mgmt *mgmt;
4069 struct ieee802_11_elems elems;
4072 rx_status = (struct ieee80211_rx_status *) skb->cb;
4073 mgmt = (struct ieee80211_mgmt *) skb->data;
4074 fc = le16_to_cpu(mgmt->frame_control);
4078 switch (fc & IEEE80211_FCTL_STYPE) {
4079 case IEEE80211_STYPE_BEACON:
4080 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
4082 case IEEE80211_STYPE_PROBE_RESP:
4083 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4085 case IEEE80211_STYPE_AUTH:
4086 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4088 case IEEE80211_STYPE_DEAUTH:
4089 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4091 case IEEE80211_STYPE_DISASSOC:
4092 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4094 case IEEE80211_STYPE_ASSOC_RESP:
4095 case IEEE80211_STYPE_REASSOC_RESP:
4096 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4098 case IEEE80211_STYPE_ACTION:
4099 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4100 ies_len = skb->len -
4101 offsetof(struct ieee80211_mgmt,
4102 u.action.u.chan_switch.variable);
4107 /* CSA IE cannot be overridden, no need for BSSID */
4108 ieee802_11_parse_elems(
4109 mgmt->u.action.u.chan_switch.variable,
4110 ies_len, true, &elems, mgmt->bssid, NULL);
4112 if (elems.parse_error)
4115 ieee80211_sta_process_chanswitch(sdata,
4117 rx_status->device_timestamp,
4119 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4120 ies_len = skb->len -
4121 offsetof(struct ieee80211_mgmt,
4122 u.action.u.ext_chan_switch.variable);
4128 * extended CSA IE can't be overridden, no need for
4131 ieee802_11_parse_elems(
4132 mgmt->u.action.u.ext_chan_switch.variable,
4133 ies_len, true, &elems, mgmt->bssid, NULL);
4135 if (elems.parse_error)
4138 /* for the handling code pretend this was also an IE */
4139 elems.ext_chansw_ie =
4140 &mgmt->u.action.u.ext_chan_switch.data;
4142 ieee80211_sta_process_chanswitch(sdata,
4144 rx_status->device_timestamp,
4149 sdata_unlock(sdata);
4152 static void ieee80211_sta_timer(struct timer_list *t)
4154 struct ieee80211_sub_if_data *sdata =
4155 from_timer(sdata, t, u.mgd.timer);
4157 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4160 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4161 u8 *bssid, u8 reason, bool tx)
4163 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4165 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4168 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4172 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4174 struct ieee80211_local *local = sdata->local;
4175 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4176 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4180 u16 prepare_tx_duration = 0;
4182 sdata_assert_lock(sdata);
4184 if (WARN_ON_ONCE(!auth_data))
4189 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4190 sdata_info(sdata, "authentication with %pM timed out\n",
4191 auth_data->bss->bssid);
4194 * Most likely AP is not in the range so remove the
4195 * bss struct for that AP.
4197 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4202 if (auth_data->algorithm == WLAN_AUTH_SAE)
4203 prepare_tx_duration =
4204 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4206 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
4208 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4209 auth_data->bss->bssid, auth_data->tries,
4210 IEEE80211_AUTH_MAX_TRIES);
4212 auth_data->expected_transaction = 2;
4214 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4215 trans = auth_data->sae_trans;
4216 status = auth_data->sae_status;
4217 auth_data->expected_transaction = trans;
4220 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4221 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4222 IEEE80211_TX_INTFL_MLME_CONN_TX;
4224 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4225 auth_data->data, auth_data->data_len,
4226 auth_data->bss->bssid,
4227 auth_data->bss->bssid, NULL, 0, 0,
4230 if (tx_flags == 0) {
4231 if (auth_data->algorithm == WLAN_AUTH_SAE)
4232 auth_data->timeout = jiffies +
4233 IEEE80211_AUTH_TIMEOUT_SAE;
4235 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4237 auth_data->timeout =
4238 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4241 auth_data->timeout_started = true;
4242 run_again(sdata, auth_data->timeout);
4247 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4249 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4250 struct ieee80211_local *local = sdata->local;
4252 sdata_assert_lock(sdata);
4254 assoc_data->tries++;
4255 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4256 sdata_info(sdata, "association with %pM timed out\n",
4257 assoc_data->bss->bssid);
4260 * Most likely AP is not in the range so remove the
4261 * bss struct for that AP.
4263 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4268 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4269 assoc_data->bss->bssid, assoc_data->tries,
4270 IEEE80211_ASSOC_MAX_TRIES);
4271 ieee80211_send_assoc(sdata);
4273 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4274 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4275 assoc_data->timeout_started = true;
4276 run_again(sdata, assoc_data->timeout);
4278 assoc_data->timeout =
4279 round_jiffies_up(jiffies +
4280 IEEE80211_ASSOC_TIMEOUT_LONG);
4281 assoc_data->timeout_started = true;
4282 run_again(sdata, assoc_data->timeout);
4288 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4289 __le16 fc, bool acked)
4291 struct ieee80211_local *local = sdata->local;
4293 sdata->u.mgd.status_fc = fc;
4294 sdata->u.mgd.status_acked = acked;
4295 sdata->u.mgd.status_received = true;
4297 ieee80211_queue_work(&local->hw, &sdata->work);
4300 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4302 struct ieee80211_local *local = sdata->local;
4303 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4307 if (ifmgd->status_received) {
4308 __le16 fc = ifmgd->status_fc;
4309 bool status_acked = ifmgd->status_acked;
4311 ifmgd->status_received = false;
4312 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4314 if (ifmgd->auth_data->algorithm ==
4316 ifmgd->auth_data->timeout =
4318 IEEE80211_AUTH_TIMEOUT_SAE;
4320 ifmgd->auth_data->timeout =
4322 IEEE80211_AUTH_TIMEOUT_SHORT;
4323 run_again(sdata, ifmgd->auth_data->timeout);
4325 ifmgd->auth_data->timeout = jiffies - 1;
4327 ifmgd->auth_data->timeout_started = true;
4328 } else if (ifmgd->assoc_data &&
4329 (ieee80211_is_assoc_req(fc) ||
4330 ieee80211_is_reassoc_req(fc))) {
4332 ifmgd->assoc_data->timeout =
4333 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4334 run_again(sdata, ifmgd->assoc_data->timeout);
4336 ifmgd->assoc_data->timeout = jiffies - 1;
4338 ifmgd->assoc_data->timeout_started = true;
4342 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4343 time_after(jiffies, ifmgd->auth_data->timeout)) {
4344 if (ifmgd->auth_data->done) {
4346 * ok ... we waited for assoc but userspace didn't,
4347 * so let's just kill the auth data
4349 ieee80211_destroy_auth_data(sdata, false);
4350 } else if (ieee80211_auth(sdata)) {
4352 struct ieee80211_event event = {
4354 .u.mlme.data = AUTH_EVENT,
4355 .u.mlme.status = MLME_TIMEOUT,
4358 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4360 ieee80211_destroy_auth_data(sdata, false);
4362 cfg80211_auth_timeout(sdata->dev, bssid);
4363 drv_event_callback(sdata->local, sdata, &event);
4365 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4366 run_again(sdata, ifmgd->auth_data->timeout);
4368 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4369 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4370 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4371 ieee80211_do_assoc(sdata)) {
4372 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4373 struct ieee80211_event event = {
4375 .u.mlme.data = ASSOC_EVENT,
4376 .u.mlme.status = MLME_TIMEOUT,
4379 ieee80211_destroy_assoc_data(sdata, false, false);
4380 cfg80211_assoc_timeout(sdata->dev, bss);
4381 drv_event_callback(sdata->local, sdata, &event);
4383 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4384 run_again(sdata, ifmgd->assoc_data->timeout);
4386 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4387 ifmgd->associated) {
4391 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4393 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4394 max_tries = max_nullfunc_tries;
4396 max_tries = max_probe_tries;
4398 /* ACK received for nullfunc probing frame */
4399 if (!ifmgd->probe_send_count)
4400 ieee80211_reset_ap_probe(sdata);
4401 else if (ifmgd->nullfunc_failed) {
4402 if (ifmgd->probe_send_count < max_tries) {
4404 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4405 bssid, ifmgd->probe_send_count,
4407 ieee80211_mgd_probe_ap_send(sdata);
4410 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4412 ieee80211_sta_connection_lost(sdata, bssid,
4413 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4416 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4417 run_again(sdata, ifmgd->probe_timeout);
4418 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4420 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4421 bssid, probe_wait_ms);
4422 ieee80211_sta_connection_lost(sdata, bssid,
4423 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4424 } else if (ifmgd->probe_send_count < max_tries) {
4426 "No probe response from AP %pM after %dms, try %d/%i\n",
4427 bssid, probe_wait_ms,
4428 ifmgd->probe_send_count, max_tries);
4429 ieee80211_mgd_probe_ap_send(sdata);
4432 * We actually lost the connection ... or did we?
4436 "No probe response from AP %pM after %dms, disconnecting.\n",
4437 bssid, probe_wait_ms);
4439 ieee80211_sta_connection_lost(sdata, bssid,
4440 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4444 sdata_unlock(sdata);
4447 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4449 struct ieee80211_sub_if_data *sdata =
4450 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4451 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4453 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4456 sdata->u.mgd.connection_loss = false;
4457 ieee80211_queue_work(&sdata->local->hw,
4458 &sdata->u.mgd.beacon_connection_loss_work);
4461 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4463 struct ieee80211_sub_if_data *sdata =
4464 from_timer(sdata, t, u.mgd.conn_mon_timer);
4465 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4466 struct ieee80211_local *local = sdata->local;
4468 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4471 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4474 static void ieee80211_sta_monitor_work(struct work_struct *work)
4476 struct ieee80211_sub_if_data *sdata =
4477 container_of(work, struct ieee80211_sub_if_data,
4478 u.mgd.monitor_work);
4480 ieee80211_mgd_probe_ap(sdata, false);
4483 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4485 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4486 __ieee80211_stop_poll(sdata);
4488 /* let's probe the connection once */
4489 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4490 ieee80211_queue_work(&sdata->local->hw,
4491 &sdata->u.mgd.monitor_work);
4496 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4498 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4499 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4503 if (ifmgd->auth_data || ifmgd->assoc_data) {
4504 const u8 *bssid = ifmgd->auth_data ?
4505 ifmgd->auth_data->bss->bssid :
4506 ifmgd->assoc_data->bss->bssid;
4509 * If we are trying to authenticate / associate while suspending,
4510 * cfg80211 won't know and won't actually abort those attempts,
4511 * thus we need to do that ourselves.
4513 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4514 IEEE80211_STYPE_DEAUTH,
4515 WLAN_REASON_DEAUTH_LEAVING,
4517 if (ifmgd->assoc_data)
4518 ieee80211_destroy_assoc_data(sdata, false, true);
4519 if (ifmgd->auth_data)
4520 ieee80211_destroy_auth_data(sdata, false);
4521 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4522 IEEE80211_DEAUTH_FRAME_LEN);
4525 /* This is a bit of a hack - we should find a better and more generic
4526 * solution to this. Normally when suspending, cfg80211 will in fact
4527 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4528 * auth (not so important) or assoc (this is the problem) process.
4530 * As a consequence, it can happen that we are in the process of both
4531 * associating and suspending, and receive an association response
4532 * after cfg80211 has checked if it needs to disconnect, but before
4533 * we actually set the flag to drop incoming frames. This will then
4534 * cause the workqueue flush to process the association response in
4535 * the suspend, resulting in a successful association just before it
4536 * tries to remove the interface from the driver, which now though
4537 * has a channel context assigned ... this results in issues.
4539 * To work around this (for now) simply deauth here again if we're
4542 if (ifmgd->associated && !sdata->local->wowlan) {
4544 struct cfg80211_deauth_request req = {
4545 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4549 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4550 ieee80211_mgd_deauth(sdata, &req);
4553 sdata_unlock(sdata);
4556 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4558 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4561 if (!ifmgd->associated) {
4562 sdata_unlock(sdata);
4566 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4567 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4568 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4569 ieee80211_sta_connection_lost(sdata,
4570 ifmgd->associated->bssid,
4571 WLAN_REASON_UNSPECIFIED,
4573 sdata_unlock(sdata);
4576 sdata_unlock(sdata);
4580 /* interface setup */
4581 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4583 struct ieee80211_if_managed *ifmgd;
4585 ifmgd = &sdata->u.mgd;
4586 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4587 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4588 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4589 ieee80211_beacon_connection_loss_work);
4590 INIT_WORK(&ifmgd->csa_connection_drop_work,
4591 ieee80211_csa_connection_drop_work);
4592 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4593 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4594 ieee80211_tdls_peer_del_work);
4595 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4596 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4597 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4598 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4599 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4600 ieee80211_sta_handle_tspec_ac_params_wk);
4603 ifmgd->powersave = sdata->wdev.ps;
4604 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4605 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4606 ifmgd->p2p_noa_index = -1;
4608 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4609 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4611 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4613 /* Setup TDLS data */
4614 spin_lock_init(&ifmgd->teardown_lock);
4615 ifmgd->teardown_skb = NULL;
4616 ifmgd->orig_teardown_skb = NULL;
4619 /* scan finished notification */
4620 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4622 struct ieee80211_sub_if_data *sdata;
4624 /* Restart STA timers */
4626 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4627 if (ieee80211_sdata_running(sdata))
4628 ieee80211_restart_sta_timer(sdata);
4633 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4634 struct cfg80211_bss *cbss)
4636 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4637 const u8 *ht_cap_ie, *vht_cap_ie;
4638 const struct ieee80211_ht_cap *ht_cap;
4639 const struct ieee80211_vht_cap *vht_cap;
4642 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4645 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4646 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4647 ht_cap = (void *)(ht_cap_ie + 2);
4648 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4650 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4651 * "Tx Unequal Modulation Supported" fields.
4655 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4658 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4659 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4663 vht_cap = (void *)(vht_cap_ie + 2);
4664 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4665 for (nss = 8; nss > 0; nss--) {
4666 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4667 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4670 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4671 chains = max(chains, nss);
4678 ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4679 const struct ieee80211_he_operation *he_op)
4681 const struct ieee80211_sta_he_cap *sta_he_cap =
4682 ieee80211_get_he_sta_cap(sband);
4686 if (!sta_he_cap || !he_op)
4689 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4691 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4692 for (i = 0; i < 3; i++) {
4693 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4694 &sta_he_cap->he_mcs_nss_supp;
4695 u16 sta_mcs_map_rx =
4696 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4697 u16 sta_mcs_map_tx =
4698 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4700 bool verified = true;
4703 * For each band there is a maximum of 8 spatial streams
4704 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4705 * of 2 bits per NSS (1-8), with the values defined in enum
4706 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4707 * capabilities aren't less than the AP's minimum requirements
4708 * for this HE BSS per SS.
4709 * It is enough to find one such band that meets the reqs.
4711 for (nss = 8; nss > 0; nss--) {
4712 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4713 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4714 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4716 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4720 * Make sure the HE AP doesn't require MCSs that aren't
4721 * supported by the client
4723 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4724 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4725 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4735 /* If here, STA doesn't meet AP's HE min requirements */
4739 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4740 struct cfg80211_bss *cbss)
4742 struct ieee80211_local *local = sdata->local;
4743 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4744 const struct ieee80211_ht_cap *ht_cap = NULL;
4745 const struct ieee80211_ht_operation *ht_oper = NULL;
4746 const struct ieee80211_vht_operation *vht_oper = NULL;
4747 const struct ieee80211_he_operation *he_oper = NULL;
4748 struct ieee80211_supported_band *sband;
4749 struct cfg80211_chan_def chandef;
4754 sband = local->hw.wiphy->bands[cbss->channel->band];
4756 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4757 IEEE80211_STA_DISABLE_80P80MHZ |
4758 IEEE80211_STA_DISABLE_160MHZ);
4762 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4763 sband->ht_cap.ht_supported) {
4764 const u8 *ht_oper_ie, *ht_cap_ie;
4766 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
4767 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4768 ht_oper = (void *)(ht_oper_ie + 2);
4770 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4771 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4772 ht_cap = (void *)(ht_cap_ie + 2);
4775 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4780 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4781 sband->vht_cap.vht_supported) {
4782 const u8 *vht_oper_ie, *vht_cap;
4784 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4785 WLAN_EID_VHT_OPERATION);
4786 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4787 vht_oper = (void *)(vht_oper_ie + 2);
4788 if (vht_oper && !ht_oper) {
4791 "AP advertised VHT without HT, disabling both\n");
4792 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4793 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4796 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4797 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4798 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4803 if (!ieee80211_get_he_sta_cap(sband))
4804 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4806 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
4807 const struct cfg80211_bss_ies *ies;
4808 const u8 *he_oper_ie;
4810 ies = rcu_dereference(cbss->ies);
4811 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4812 ies->data, ies->len);
4814 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4815 he_oper = (void *)(he_oper_ie + 3);
4819 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
4820 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4823 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4825 for (i = 0; i < sband->n_channels; i++) {
4826 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4827 IEEE80211_CHAN_NO_80MHZ))
4835 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4837 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4839 ht_oper, vht_oper, he_oper,
4842 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4847 /* will change later if needed */
4848 sdata->smps_mode = IEEE80211_SMPS_OFF;
4850 mutex_lock(&local->mtx);
4852 * If this fails (possibly due to channel context sharing
4853 * on incompatible channels, e.g. 80+80 and 160 sharing the
4854 * same control channel) try to use a smaller bandwidth.
4856 ret = ieee80211_vif_use_channel(sdata, &chandef,
4857 IEEE80211_CHANCTX_SHARED);
4859 /* don't downgrade for 5 and 10 MHz channels, though. */
4860 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4861 chandef.width == NL80211_CHAN_WIDTH_10)
4864 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4865 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
4866 ret = ieee80211_vif_use_channel(sdata, &chandef,
4867 IEEE80211_CHANCTX_SHARED);
4870 mutex_unlock(&local->mtx);
4874 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4875 u8 *dtim_count, u8 *dtim_period)
4877 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4878 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4880 const struct ieee80211_tim_ie *tim = NULL;
4881 const struct ieee80211_bssid_index *idx;
4882 bool valid = tim_ie && tim_ie[1] >= 2;
4885 tim = (void *)(tim_ie + 2);
4888 *dtim_count = valid ? tim->dtim_count : 0;
4891 *dtim_period = valid ? tim->dtim_period : 0;
4893 /* Check if value is overridden by non-transmitted profile */
4894 if (!idx_ie || idx_ie[1] < 3)
4897 idx = (void *)(idx_ie + 2);
4900 *dtim_count = idx->dtim_count;
4903 *dtim_period = idx->dtim_period;
4908 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
4909 struct cfg80211_bss *cbss, bool assoc,
4912 struct ieee80211_local *local = sdata->local;
4913 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4914 struct ieee80211_bss *bss = (void *)cbss->priv;
4915 struct sta_info *new_sta = NULL;
4916 struct ieee80211_supported_band *sband;
4917 bool have_sta = false;
4920 sband = local->hw.wiphy->bands[cbss->channel->band];
4922 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4925 /* If a reconfig is happening, bail out */
4926 if (local->in_reconfig)
4931 have_sta = sta_info_get(sdata, cbss->bssid);
4936 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4942 * Set up the information for the new channel before setting the
4943 * new channel. We can't - completely race-free - change the basic
4944 * rates bitmap and the channel (sband) that it refers to, but if
4945 * we set it up before we at least avoid calling into the driver's
4946 * bss_info_changed() method with invalid information (since we do
4947 * call that from changing the channel - only for IDLE and perhaps
4948 * some others, but ...).
4950 * So to avoid that, just set up all the new information before the
4951 * channel, but tell the driver to apply it only afterwards, since
4952 * it might need the new channel for that.
4955 u32 rates = 0, basic_rates = 0;
4956 bool have_higher_than_11mbit;
4957 int min_rate = INT_MAX, min_rate_index = -1;
4958 const struct cfg80211_bss_ies *ies;
4959 int shift = ieee80211_vif_get_shift(&sdata->vif);
4961 ieee80211_get_rates(sband, bss->supp_rates,
4962 bss->supp_rates_len,
4963 &rates, &basic_rates,
4964 &have_higher_than_11mbit,
4965 &min_rate, &min_rate_index,
4969 * This used to be a workaround for basic rates missing
4970 * in the association response frame. Now that we no
4971 * longer use the basic rates from there, it probably
4972 * doesn't happen any more, but keep the workaround so
4973 * in case some *other* APs are buggy in different ways
4974 * we can connect -- with a warning.
4976 if (!basic_rates && min_rate_index >= 0) {
4978 "No basic rates, using min rate instead\n");
4979 basic_rates = BIT(min_rate_index);
4983 new_sta->sta.supp_rates[cbss->channel->band] = rates;
4986 "No rates found, keeping mandatory only\n");
4988 sdata->vif.bss_conf.basic_rates = basic_rates;
4990 /* cf. IEEE 802.11 9.2.12 */
4991 if (cbss->channel->band == NL80211_BAND_2GHZ &&
4992 have_higher_than_11mbit)
4993 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4995 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4997 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4999 /* set timing information */
5000 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5002 ies = rcu_dereference(cbss->beacon_ies);
5004 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5005 sdata->vif.bss_conf.sync_device_ts =
5006 bss->device_ts_beacon;
5008 ieee80211_get_dtim(ies,
5009 &sdata->vif.bss_conf.sync_dtim_count,
5011 } else if (!ieee80211_hw_check(&sdata->local->hw,
5012 TIMING_BEACON_ONLY)) {
5013 ies = rcu_dereference(cbss->proberesp_ies);
5014 /* must be non-NULL since beacon IEs were NULL */
5015 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5016 sdata->vif.bss_conf.sync_device_ts =
5017 bss->device_ts_presp;
5018 sdata->vif.bss_conf.sync_dtim_count = 0;
5020 sdata->vif.bss_conf.sync_tsf = 0;
5021 sdata->vif.bss_conf.sync_device_ts = 0;
5022 sdata->vif.bss_conf.sync_dtim_count = 0;
5027 if (new_sta || override) {
5028 err = ieee80211_prep_channel(sdata, cbss);
5031 sta_info_free(local, new_sta);
5038 * tell driver about BSSID, basic rates and timing
5039 * this was set up above, before setting the channel
5041 ieee80211_bss_info_change_notify(sdata,
5042 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5043 BSS_CHANGED_BEACON_INT);
5046 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5048 err = sta_info_insert(new_sta);
5052 "failed to insert STA entry for the AP (error %d)\n",
5057 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5059 /* Cancel scan to ensure that nothing interferes with connection */
5060 if (local->scanning)
5061 ieee80211_scan_cancel(local);
5067 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5068 struct cfg80211_auth_request *req)
5070 struct ieee80211_local *local = sdata->local;
5071 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5072 struct ieee80211_mgd_auth_data *auth_data;
5077 /* prepare auth data structure */
5079 switch (req->auth_type) {
5080 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5081 auth_alg = WLAN_AUTH_OPEN;
5083 case NL80211_AUTHTYPE_SHARED_KEY:
5086 auth_alg = WLAN_AUTH_SHARED_KEY;
5088 case NL80211_AUTHTYPE_FT:
5089 auth_alg = WLAN_AUTH_FT;
5091 case NL80211_AUTHTYPE_NETWORK_EAP:
5092 auth_alg = WLAN_AUTH_LEAP;
5094 case NL80211_AUTHTYPE_SAE:
5095 auth_alg = WLAN_AUTH_SAE;
5097 case NL80211_AUTHTYPE_FILS_SK:
5098 auth_alg = WLAN_AUTH_FILS_SK;
5100 case NL80211_AUTHTYPE_FILS_SK_PFS:
5101 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5103 case NL80211_AUTHTYPE_FILS_PK:
5104 auth_alg = WLAN_AUTH_FILS_PK;
5110 if (ifmgd->assoc_data)
5113 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5114 req->ie_len, GFP_KERNEL);
5118 auth_data->bss = req->bss;
5120 if (req->auth_data_len >= 4) {
5121 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5122 __le16 *pos = (__le16 *) req->auth_data;
5124 auth_data->sae_trans = le16_to_cpu(pos[0]);
5125 auth_data->sae_status = le16_to_cpu(pos[1]);
5127 memcpy(auth_data->data, req->auth_data + 4,
5128 req->auth_data_len - 4);
5129 auth_data->data_len += req->auth_data_len - 4;
5132 /* Check if continuing authentication or trying to authenticate with the
5133 * same BSS that we were in the process of authenticating with and avoid
5134 * removal and re-addition of the STA entry in
5135 * ieee80211_prep_connection().
5137 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5139 if (req->ie && req->ie_len) {
5140 memcpy(&auth_data->data[auth_data->data_len],
5141 req->ie, req->ie_len);
5142 auth_data->data_len += req->ie_len;
5145 if (req->key && req->key_len) {
5146 auth_data->key_len = req->key_len;
5147 auth_data->key_idx = req->key_idx;
5148 memcpy(auth_data->key, req->key, req->key_len);
5151 auth_data->algorithm = auth_alg;
5153 /* try to authenticate/probe */
5155 if (ifmgd->auth_data) {
5156 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5157 auth_data->peer_confirmed =
5158 ifmgd->auth_data->peer_confirmed;
5160 ieee80211_destroy_auth_data(sdata, cont_auth);
5163 /* prep auth_data so we don't go into idle on disassoc */
5164 ifmgd->auth_data = auth_data;
5166 /* If this is continuation of an ongoing SAE authentication exchange
5167 * (i.e., request to send SAE Confirm) and the peer has already
5168 * confirmed, mark authentication completed since we are about to send
5171 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5172 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5173 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5175 if (ifmgd->associated) {
5176 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5179 "disconnect from AP %pM for new auth to %pM\n",
5180 ifmgd->associated->bssid, req->bss->bssid);
5181 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5182 WLAN_REASON_UNSPECIFIED,
5185 ieee80211_report_disconnect(sdata, frame_buf,
5186 sizeof(frame_buf), true,
5187 WLAN_REASON_UNSPECIFIED);
5190 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5192 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5196 err = ieee80211_auth(sdata);
5198 sta_info_destroy_addr(sdata, req->bss->bssid);
5202 /* hold our own reference */
5203 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5207 eth_zero_addr(ifmgd->bssid);
5208 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5209 ifmgd->auth_data = NULL;
5210 mutex_lock(&sdata->local->mtx);
5211 ieee80211_vif_release_channel(sdata);
5212 mutex_unlock(&sdata->local->mtx);
5217 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5218 struct cfg80211_assoc_request *req)
5220 struct ieee80211_local *local = sdata->local;
5221 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5222 struct ieee80211_bss *bss = (void *)req->bss->priv;
5223 struct ieee80211_mgd_assoc_data *assoc_data;
5224 const struct cfg80211_bss_ies *beacon_ies;
5225 struct ieee80211_supported_band *sband;
5226 const u8 *ssidie, *ht_ie, *vht_ie;
5228 bool override = false;
5230 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5235 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5241 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5242 assoc_data->ssid_len = ssidie[1];
5245 if (ifmgd->associated) {
5246 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5249 "disconnect from AP %pM for new assoc to %pM\n",
5250 ifmgd->associated->bssid, req->bss->bssid);
5251 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5252 WLAN_REASON_UNSPECIFIED,
5255 ieee80211_report_disconnect(sdata, frame_buf,
5256 sizeof(frame_buf), true,
5257 WLAN_REASON_UNSPECIFIED);
5260 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5265 if (ifmgd->assoc_data) {
5270 if (ifmgd->auth_data) {
5273 /* keep sta info, bssid if matching */
5274 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5275 ieee80211_destroy_auth_data(sdata, match);
5278 /* prepare assoc data */
5280 ifmgd->beacon_crc_valid = false;
5282 assoc_data->wmm = bss->wmm_used &&
5283 (local->hw.queues >= IEEE80211_NUM_ACS);
5286 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5287 * We still associate in non-HT mode (11a/b/g) if any one of these
5288 * ciphers is configured as pairwise.
5289 * We can set this to true for non-11n hardware, that'll be checked
5290 * separately along with the peer capabilities.
5292 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5293 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5294 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5295 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5296 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5297 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5298 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5299 netdev_info(sdata->dev,
5300 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5304 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5305 sband = local->hw.wiphy->bands[req->bss->channel->band];
5306 if (!sband->ht_cap.ht_supported ||
5307 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5308 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
5309 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5310 if (!bss->wmm_used &&
5311 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
5312 netdev_info(sdata->dev,
5313 "disabling HT as WMM/QoS is not supported by the AP\n");
5316 /* disable VHT if we don't support it or the AP doesn't use WMM */
5317 if (!sband->vht_cap.vht_supported ||
5318 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5319 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
5320 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5321 if (!bss->wmm_used &&
5322 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
5323 netdev_info(sdata->dev,
5324 "disabling VHT as WMM/QoS is not supported by the AP\n");
5327 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5328 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5329 sizeof(ifmgd->ht_capa_mask));
5331 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5332 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5333 sizeof(ifmgd->vht_capa_mask));
5335 if (req->ie && req->ie_len) {
5336 memcpy(assoc_data->ie, req->ie, req->ie_len);
5337 assoc_data->ie_len = req->ie_len;
5340 if (req->fils_kek) {
5341 /* should already be checked in cfg80211 - so warn */
5342 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5346 memcpy(assoc_data->fils_kek, req->fils_kek,
5348 assoc_data->fils_kek_len = req->fils_kek_len;
5351 if (req->fils_nonces)
5352 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5353 2 * FILS_NONCE_LEN);
5355 assoc_data->bss = req->bss;
5357 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5358 if (ifmgd->powersave)
5359 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5361 sdata->smps_mode = IEEE80211_SMPS_OFF;
5363 sdata->smps_mode = ifmgd->req_smps;
5365 assoc_data->capability = req->bss->capability;
5366 assoc_data->supp_rates = bss->supp_rates;
5367 assoc_data->supp_rates_len = bss->supp_rates_len;
5370 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5371 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5372 assoc_data->ap_ht_param =
5373 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5375 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5376 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5377 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5378 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5379 sizeof(struct ieee80211_vht_cap));
5381 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5384 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5385 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5386 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5387 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5389 if (bss->wmm_used && bss->uapsd_supported &&
5390 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5391 assoc_data->uapsd = true;
5392 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5394 assoc_data->uapsd = false;
5395 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5398 if (req->prev_bssid)
5399 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5402 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5403 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5405 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5406 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5409 if (req->flags & ASSOC_REQ_USE_RRM)
5410 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5412 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5414 if (req->crypto.control_port)
5415 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5417 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5419 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5420 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5421 sdata->control_port_over_nl80211 =
5422 req->crypto.control_port_over_nl80211;
5423 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5426 /* kick off associate process */
5428 ifmgd->assoc_data = assoc_data;
5429 ifmgd->dtim_period = 0;
5430 ifmgd->have_beacon = false;
5432 /* override HT/VHT configuration only if the AP and we support it */
5433 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5434 struct ieee80211_sta_ht_cap sta_ht_cap;
5436 if (req->flags & ASSOC_REQ_DISABLE_HT)
5439 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5440 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5442 /* check for 40 MHz disable override */
5443 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5444 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5445 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5448 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5449 req->flags & ASSOC_REQ_DISABLE_VHT)
5453 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5454 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5455 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5458 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5459 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5461 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5466 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5468 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5471 * Wait up to one beacon interval ...
5472 * should this be more if we miss one?
5474 sdata_info(sdata, "waiting for beacon from %pM\n",
5476 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5477 assoc_data->timeout_started = true;
5478 assoc_data->need_beacon = true;
5479 } else if (beacon_ies) {
5483 ieee80211_get_dtim(beacon_ies, &dtim_count,
5484 &ifmgd->dtim_period);
5486 ifmgd->have_beacon = true;
5487 assoc_data->timeout = jiffies;
5488 assoc_data->timeout_started = true;
5490 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5491 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5492 sdata->vif.bss_conf.sync_device_ts =
5493 bss->device_ts_beacon;
5494 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5497 ie = cfg80211_find_ext_ie(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5498 beacon_ies->data, beacon_ies->len);
5499 if (ie && ie[1] >= 3)
5500 sdata->vif.bss_conf.profile_periodicity = ie[4];
5502 ie = cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY,
5503 beacon_ies->data, beacon_ies->len);
5504 if (ie && ie[1] >= 11 &&
5505 (ie[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5506 sdata->vif.bss_conf.ema_ap = true;
5508 assoc_data->timeout = jiffies;
5509 assoc_data->timeout_started = true;
5513 run_again(sdata, assoc_data->timeout);
5515 if (bss->corrupt_data) {
5516 char *corrupt_type = "data";
5517 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5518 if (bss->corrupt_data &
5519 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5520 corrupt_type = "beacon and probe response";
5522 corrupt_type = "beacon";
5523 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5524 corrupt_type = "probe response";
5525 sdata_info(sdata, "associating with AP with corrupt %s\n",
5531 eth_zero_addr(ifmgd->bssid);
5532 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5533 ifmgd->assoc_data = NULL;
5539 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5540 struct cfg80211_deauth_request *req)
5542 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5543 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5544 bool tx = !req->local_state_change;
5546 if (ifmgd->auth_data &&
5547 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5549 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5550 req->bssid, req->reason_code,
5551 ieee80211_get_reason_code_string(req->reason_code));
5553 drv_mgd_prepare_tx(sdata->local, sdata, 0);
5554 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5555 IEEE80211_STYPE_DEAUTH,
5556 req->reason_code, tx,
5558 ieee80211_destroy_auth_data(sdata, false);
5559 ieee80211_report_disconnect(sdata, frame_buf,
5560 sizeof(frame_buf), true,
5566 if (ifmgd->assoc_data &&
5567 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5569 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5570 req->bssid, req->reason_code,
5571 ieee80211_get_reason_code_string(req->reason_code));
5573 drv_mgd_prepare_tx(sdata->local, sdata, 0);
5574 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5575 IEEE80211_STYPE_DEAUTH,
5576 req->reason_code, tx,
5578 ieee80211_destroy_assoc_data(sdata, false, true);
5579 ieee80211_report_disconnect(sdata, frame_buf,
5580 sizeof(frame_buf), true,
5585 if (ifmgd->associated &&
5586 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5588 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5589 req->bssid, req->reason_code,
5590 ieee80211_get_reason_code_string(req->reason_code));
5592 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5593 req->reason_code, tx, frame_buf);
5594 ieee80211_report_disconnect(sdata, frame_buf,
5595 sizeof(frame_buf), true,
5603 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5604 struct cfg80211_disassoc_request *req)
5606 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5608 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5611 * cfg80211 should catch this ... but it's racy since
5612 * we can receive a disassoc frame, process it, hand it
5613 * to cfg80211 while that's in a locked section already
5614 * trying to tell us that the user wants to disconnect.
5616 if (ifmgd->associated != req->bss)
5620 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5621 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5623 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5624 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5625 req->reason_code, !req->local_state_change,
5628 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5634 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5636 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5639 * Make sure some work items will not run after this,
5640 * they will not do anything but might not have been
5641 * cancelled when disconnecting.
5643 cancel_work_sync(&ifmgd->monitor_work);
5644 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5645 cancel_work_sync(&ifmgd->request_smps_work);
5646 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5647 cancel_work_sync(&ifmgd->chswitch_work);
5648 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5651 if (ifmgd->assoc_data) {
5652 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5653 ieee80211_destroy_assoc_data(sdata, false, false);
5654 cfg80211_assoc_timeout(sdata->dev, bss);
5656 if (ifmgd->auth_data)
5657 ieee80211_destroy_auth_data(sdata, false);
5658 spin_lock_bh(&ifmgd->teardown_lock);
5659 if (ifmgd->teardown_skb) {
5660 kfree_skb(ifmgd->teardown_skb);
5661 ifmgd->teardown_skb = NULL;
5662 ifmgd->orig_teardown_skb = NULL;
5664 kfree(ifmgd->assoc_req_ies);
5665 ifmgd->assoc_req_ies = NULL;
5666 ifmgd->assoc_req_ies_len = 0;
5667 spin_unlock_bh(&ifmgd->teardown_lock);
5668 del_timer_sync(&ifmgd->timer);
5669 sdata_unlock(sdata);
5672 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5673 enum nl80211_cqm_rssi_threshold_event rssi_event,
5677 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5679 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
5681 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
5683 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
5685 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5687 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5689 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5691 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5693 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);