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/if_ether.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_arp.h>
18 #include <linux/etherdevice.h>
19 #include <linux/moduleparam.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/crc32.h>
22 #include <linux/slab.h>
23 #include <linux/export.h>
24 #include <net/mac80211.h>
25 #include <asm/unaligned.h>
27 #include "ieee80211_i.h"
28 #include "driver-ops.h"
31 #include "fils_aead.h"
33 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
34 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
35 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
36 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
37 #define IEEE80211_AUTH_MAX_TRIES 3
38 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
39 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
40 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
41 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
42 #define IEEE80211_ASSOC_MAX_TRIES 3
44 static int max_nullfunc_tries = 2;
45 module_param(max_nullfunc_tries, int, 0644);
46 MODULE_PARM_DESC(max_nullfunc_tries,
47 "Maximum nullfunc tx tries before disconnecting (reason 4).");
49 static int max_probe_tries = 5;
50 module_param(max_probe_tries, int, 0644);
51 MODULE_PARM_DESC(max_probe_tries,
52 "Maximum probe tries before disconnecting (reason 4).");
55 * Beacon loss timeout is calculated as N frames times the
56 * advertised beacon interval. This may need to be somewhat
57 * higher than what hardware might detect to account for
58 * delays in the host processing frames. But since we also
59 * probe on beacon miss before declaring the connection lost
60 * default to what we want.
62 static int beacon_loss_count = 7;
63 module_param(beacon_loss_count, int, 0644);
64 MODULE_PARM_DESC(beacon_loss_count,
65 "Number of beacon intervals before we decide beacon was lost.");
68 * Time the connection can be idle before we probe
69 * it to see if we can still talk to the AP.
71 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
73 * Time we wait for a probe response after sending
74 * a probe request because of beacon loss or for
75 * checking the connection still works.
77 static int probe_wait_ms = 500;
78 module_param(probe_wait_ms, int, 0644);
79 MODULE_PARM_DESC(probe_wait_ms,
80 "Maximum time(ms) to wait for probe response"
81 " before disconnecting (reason 4).");
84 * How many Beacon frames need to have been used in average signal strength
85 * before starting to indicate signal change events.
87 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
90 * We can have multiple work items (and connection probing)
91 * scheduling this timer, but we need to take care to only
92 * reschedule it when it should fire _earlier_ than it was
93 * asked for before, or if it's not pending right now. This
94 * function ensures that. Note that it then is required to
95 * run this function for all timeouts after the first one
96 * has happened -- the work that runs from this timer will
99 static void run_again(struct ieee80211_sub_if_data *sdata,
100 unsigned long timeout)
102 sdata_assert_lock(sdata);
104 if (!timer_pending(&sdata->u.mgd.timer) ||
105 time_before(timeout, sdata->u.mgd.timer.expires))
106 mod_timer(&sdata->u.mgd.timer, timeout);
109 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
111 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
114 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
117 mod_timer(&sdata->u.mgd.bcn_mon_timer,
118 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
121 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
123 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
125 if (unlikely(!ifmgd->associated))
128 if (ifmgd->probe_send_count)
129 ifmgd->probe_send_count = 0;
131 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
134 mod_timer(&ifmgd->conn_mon_timer,
135 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
138 static int ecw2cw(int ecw)
140 return (1 << ecw) - 1;
144 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
145 struct ieee80211_supported_band *sband,
146 struct ieee80211_channel *channel,
147 const struct ieee80211_ht_operation *ht_oper,
148 const struct ieee80211_vht_operation *vht_oper,
149 const struct ieee80211_he_operation *he_oper,
150 struct cfg80211_chan_def *chandef, bool tracking)
152 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
153 struct cfg80211_chan_def vht_chandef;
154 struct ieee80211_sta_ht_cap sta_ht_cap;
157 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
158 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
160 chandef->chan = channel;
161 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
162 chandef->center_freq1 = channel->center_freq;
163 chandef->center_freq2 = 0;
165 if (!ht_oper || !sta_ht_cap.ht_supported) {
166 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
170 chandef->width = NL80211_CHAN_WIDTH_20;
172 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
174 /* check that channel matches the right operating channel */
175 if (!tracking && channel->center_freq != ht_cfreq) {
177 * It's possible that some APs are confused here;
178 * Netgear WNDR3700 sometimes reports 4 higher than
179 * the actual channel in association responses, but
180 * since we look at probe response/beacon data here
184 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
185 channel->center_freq, ht_cfreq,
186 ht_oper->primary_chan, channel->band);
187 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
191 /* check 40 MHz support, if we have it */
192 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
193 ieee80211_chandef_ht_oper(ht_oper, chandef);
195 /* 40 MHz (and 80 MHz) must be supported for VHT */
196 ret = IEEE80211_STA_DISABLE_VHT;
197 /* also mark 40 MHz disabled */
198 ret |= IEEE80211_STA_DISABLE_40MHZ;
202 if (!vht_oper || !sband->vht_cap.vht_supported) {
203 ret = IEEE80211_STA_DISABLE_VHT;
207 vht_chandef = *chandef;
208 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
209 (le32_to_cpu(he_oper->he_oper_params) &
210 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
211 struct ieee80211_vht_operation he_oper_vht_cap;
214 * Set only first 3 bytes (other 2 aren't used in
215 * ieee80211_chandef_vht_oper() anyway)
217 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
218 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
220 if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
221 &he_oper_vht_cap, ht_oper,
223 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
225 "HE AP VHT information is invalid, disable HE\n");
226 ret = IEEE80211_STA_DISABLE_HE;
229 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_oper,
230 ht_oper, &vht_chandef)) {
231 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
233 "AP VHT information is invalid, disable VHT\n");
234 ret = IEEE80211_STA_DISABLE_VHT;
238 if (!cfg80211_chandef_valid(&vht_chandef)) {
239 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
241 "AP VHT information is invalid, disable VHT\n");
242 ret = IEEE80211_STA_DISABLE_VHT;
246 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
251 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
252 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
254 "AP VHT information doesn't match HT, disable VHT\n");
255 ret = IEEE80211_STA_DISABLE_VHT;
259 *chandef = vht_chandef;
265 * When tracking the current AP, don't do any further checks if the
266 * new chandef is identical to the one we're currently using for the
267 * connection. This keeps us from playing ping-pong with regulatory,
268 * without it the following can happen (for example):
269 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
270 * - AP advertises regdom US
271 * - CRDA loads regdom US with 80 MHz prohibited (old database)
272 * - the code below detects an unsupported channel, downgrades, and
273 * we disconnect from the AP in the caller
274 * - disconnect causes CRDA to reload world regdomain and the game
276 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
278 * It seems possible that there are still scenarios with CSA or real
279 * bandwidth changes where a this could happen, but those cases are
280 * less common and wouldn't completely prevent using the AP.
283 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
286 /* don't print the message below for VHT mismatch if VHT is disabled */
287 if (ret & IEEE80211_STA_DISABLE_VHT)
288 vht_chandef = *chandef;
291 * Ignore the DISABLED flag when we're already connected and only
292 * tracking the APs beacon for bandwidth changes - otherwise we
293 * might get disconnected here if we connect to an AP, update our
294 * regulatory information based on the AP's country IE and the
295 * information we have is wrong/outdated and disables the channel
296 * that we're actually using for the connection to the AP.
298 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
300 IEEE80211_CHAN_DISABLED)) {
301 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
302 ret = IEEE80211_STA_DISABLE_HT |
303 IEEE80211_STA_DISABLE_VHT;
307 ret |= ieee80211_chandef_downgrade(chandef);
310 if (chandef->width != vht_chandef.width && !tracking)
312 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
314 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
318 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
319 struct sta_info *sta,
320 const struct ieee80211_ht_cap *ht_cap,
321 const struct ieee80211_ht_operation *ht_oper,
322 const struct ieee80211_vht_operation *vht_oper,
323 const struct ieee80211_he_operation *he_oper,
324 const u8 *bssid, u32 *changed)
326 struct ieee80211_local *local = sdata->local;
327 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
328 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
329 struct ieee80211_supported_band *sband =
330 local->hw.wiphy->bands[chan->band];
331 struct cfg80211_chan_def chandef;
334 enum ieee80211_sta_rx_bandwidth new_sta_bw;
337 /* if HT was/is disabled, don't track any bandwidth changes */
338 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
341 /* don't check VHT if we associated as non-VHT station */
342 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
345 /* don't check HE if we associated as non-HE station */
346 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
347 !ieee80211_get_he_sta_cap(sband))
350 if (WARN_ON_ONCE(!sta))
354 * if bss configuration changed store the new one -
355 * this may be applicable even if channel is identical
357 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
358 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
359 *changed |= BSS_CHANGED_HT;
360 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
363 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
364 flags = ieee80211_determine_chantype(sdata, sband, chan,
365 ht_oper, vht_oper, he_oper,
369 * Downgrade the new channel if we associated with restricted
370 * capabilities. For example, if we associated as a 20 MHz STA
371 * to a 40 MHz AP (due to regulatory, capabilities or config
372 * reasons) then switching to a 40 MHz channel now won't do us
373 * any good -- we couldn't use it with the AP.
375 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
376 chandef.width == NL80211_CHAN_WIDTH_80P80)
377 flags |= ieee80211_chandef_downgrade(&chandef);
378 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
379 chandef.width == NL80211_CHAN_WIDTH_160)
380 flags |= ieee80211_chandef_downgrade(&chandef);
381 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
382 chandef.width > NL80211_CHAN_WIDTH_20)
383 flags |= ieee80211_chandef_downgrade(&chandef);
385 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
389 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
390 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
391 chandef.center_freq1, chandef.center_freq2);
393 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
394 IEEE80211_STA_DISABLE_VHT |
395 IEEE80211_STA_DISABLE_40MHZ |
396 IEEE80211_STA_DISABLE_80P80MHZ |
397 IEEE80211_STA_DISABLE_160MHZ)) ||
398 !cfg80211_chandef_valid(&chandef)) {
400 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
405 switch (chandef.width) {
406 case NL80211_CHAN_WIDTH_20_NOHT:
407 case NL80211_CHAN_WIDTH_20:
408 new_sta_bw = IEEE80211_STA_RX_BW_20;
410 case NL80211_CHAN_WIDTH_40:
411 new_sta_bw = IEEE80211_STA_RX_BW_40;
413 case NL80211_CHAN_WIDTH_80:
414 new_sta_bw = IEEE80211_STA_RX_BW_80;
416 case NL80211_CHAN_WIDTH_80P80:
417 case NL80211_CHAN_WIDTH_160:
418 new_sta_bw = IEEE80211_STA_RX_BW_160;
424 if (new_sta_bw > sta->cur_max_bandwidth)
425 new_sta_bw = sta->cur_max_bandwidth;
427 if (new_sta_bw < sta->sta.bandwidth) {
428 sta->sta.bandwidth = new_sta_bw;
429 rate_control_rate_update(local, sband, sta,
430 IEEE80211_RC_BW_CHANGED);
433 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
436 "AP %pM changed bandwidth to incompatible one - disconnect\n",
441 if (new_sta_bw > sta->sta.bandwidth) {
442 sta->sta.bandwidth = new_sta_bw;
443 rate_control_rate_update(local, sband, sta,
444 IEEE80211_RC_BW_CHANGED);
450 /* frame sending functions */
452 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
453 struct sk_buff *skb, u8 ap_ht_param,
454 struct ieee80211_supported_band *sband,
455 struct ieee80211_channel *channel,
456 enum ieee80211_smps_mode smps)
459 u32 flags = channel->flags;
461 struct ieee80211_sta_ht_cap ht_cap;
463 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
465 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
466 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
468 /* determine capability flags */
471 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
472 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
473 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
474 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
475 cap &= ~IEEE80211_HT_CAP_SGI_40;
478 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
479 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
480 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
481 cap &= ~IEEE80211_HT_CAP_SGI_40;
487 * If 40 MHz was disabled associate as though we weren't
488 * capable of 40 MHz -- some broken APs will never fall
489 * back to trying to transmit in 20 MHz.
491 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
492 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
493 cap &= ~IEEE80211_HT_CAP_SGI_40;
496 /* set SM PS mode properly */
497 cap &= ~IEEE80211_HT_CAP_SM_PS;
499 case IEEE80211_SMPS_AUTOMATIC:
500 case IEEE80211_SMPS_NUM_MODES:
503 case IEEE80211_SMPS_OFF:
504 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
505 IEEE80211_HT_CAP_SM_PS_SHIFT;
507 case IEEE80211_SMPS_STATIC:
508 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
509 IEEE80211_HT_CAP_SM_PS_SHIFT;
511 case IEEE80211_SMPS_DYNAMIC:
512 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
513 IEEE80211_HT_CAP_SM_PS_SHIFT;
517 /* reserve and fill IE */
518 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
519 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
522 /* This function determines vht capability flags for the association
524 * Note - the function may set the owner of the MU-MIMO capability
526 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
528 struct ieee80211_supported_band *sband,
529 struct ieee80211_vht_cap *ap_vht_cap)
531 struct ieee80211_local *local = sdata->local;
534 struct ieee80211_sta_vht_cap vht_cap;
535 u32 mask, ap_bf_sts, our_bf_sts;
537 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
539 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
540 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
542 /* determine capability flags */
545 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
546 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
548 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
549 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
550 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
551 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
554 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
555 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
556 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
560 * Some APs apparently get confused if our capabilities are better
561 * than theirs, so restrict what we advertise in the assoc request.
563 if (!(ap_vht_cap->vht_cap_info &
564 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
565 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
566 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
567 else if (!(ap_vht_cap->vht_cap_info &
568 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
569 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
572 * If some other vif is using the MU-MIMO capablity we cannot associate
573 * using MU-MIMO - this will lead to contradictions in the group-id
575 * Ownership is defined since association request, in order to avoid
576 * simultaneous associations with MU-MIMO.
578 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
579 bool disable_mu_mimo = false;
580 struct ieee80211_sub_if_data *other;
582 list_for_each_entry_rcu(other, &local->interfaces, list) {
583 if (other->vif.mu_mimo_owner) {
584 disable_mu_mimo = true;
589 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
591 sdata->vif.mu_mimo_owner = true;
594 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
596 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
597 our_bf_sts = cap & mask;
599 if (ap_bf_sts < our_bf_sts) {
604 /* reserve and fill IE */
605 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
606 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
609 /* This function determines HE capability flags for the association
612 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
614 struct ieee80211_supported_band *sband)
617 const struct ieee80211_sta_he_cap *he_cap = NULL;
620 he_cap = ieee80211_get_he_sta_cap(sband);
625 * TODO: the 1 added is because this temporarily is under the EXTENSION
626 * IE. Get rid of it when it moves.
629 2 + 1 + sizeof(he_cap->he_cap_elem) +
630 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
631 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
632 he_cap->he_cap_elem.phy_cap_info);
633 pos = skb_put(skb, he_cap_size);
634 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
637 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
639 struct ieee80211_local *local = sdata->local;
640 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
641 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
643 struct ieee80211_mgmt *mgmt;
644 u8 *pos, qos_info, *ie_start;
645 size_t offset = 0, noffset;
646 int i, count, rates_len, supp_rates_len, shift;
648 struct ieee80211_supported_band *sband;
649 struct ieee80211_chanctx_conf *chanctx_conf;
650 struct ieee80211_channel *chan;
653 sdata_assert_lock(sdata);
656 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
657 if (WARN_ON(!chanctx_conf)) {
661 chan = chanctx_conf->def.chan;
663 sband = local->hw.wiphy->bands[chan->band];
664 shift = ieee80211_vif_get_shift(&sdata->vif);
666 if (assoc_data->supp_rates_len) {
668 * Get all rates supported by the device and the AP as
669 * some APs don't like getting a superset of their rates
670 * in the association request (e.g. D-Link DAP 1353 in
673 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
674 assoc_data->supp_rates,
675 assoc_data->supp_rates_len,
679 * In case AP not provide any supported rates information
680 * before association, we send information element(s) with
681 * all rates that we support.
684 for (i = 0; i < sband->n_bitrates; i++) {
690 skb = alloc_skb(local->hw.extra_tx_headroom +
691 sizeof(*mgmt) + /* bit too much but doesn't matter */
692 2 + assoc_data->ssid_len + /* SSID */
693 4 + rates_len + /* (extended) rates */
694 4 + /* power capability */
695 2 + 2 * sband->n_channels + /* supported channels */
696 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
697 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
698 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
699 sizeof(struct ieee80211_he_mcs_nss_supp) +
700 IEEE80211_HE_PPE_THRES_MAX_LEN +
701 assoc_data->ie_len + /* extra IEs */
702 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
708 skb_reserve(skb, local->hw.extra_tx_headroom);
710 capab = WLAN_CAPABILITY_ESS;
712 if (sband->band == NL80211_BAND_2GHZ) {
713 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
714 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
717 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
718 capab |= WLAN_CAPABILITY_PRIVACY;
720 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
721 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
722 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
724 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
725 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
727 mgmt = skb_put_zero(skb, 24);
728 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
729 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
730 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
732 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
734 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
735 IEEE80211_STYPE_REASSOC_REQ);
736 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
737 mgmt->u.reassoc_req.listen_interval =
738 cpu_to_le16(local->hw.conf.listen_interval);
739 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
743 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
744 IEEE80211_STYPE_ASSOC_REQ);
745 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
746 mgmt->u.assoc_req.listen_interval =
747 cpu_to_le16(local->hw.conf.listen_interval);
751 pos = skb_put(skb, 2 + assoc_data->ssid_len);
753 *pos++ = WLAN_EID_SSID;
754 *pos++ = assoc_data->ssid_len;
755 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
757 /* add all rates which were marked to be used above */
758 supp_rates_len = rates_len;
759 if (supp_rates_len > 8)
762 pos = skb_put(skb, supp_rates_len + 2);
763 *pos++ = WLAN_EID_SUPP_RATES;
764 *pos++ = supp_rates_len;
767 for (i = 0; i < sband->n_bitrates; i++) {
768 if (BIT(i) & rates) {
769 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
777 if (rates_len > count) {
778 pos = skb_put(skb, rates_len - count + 2);
779 *pos++ = WLAN_EID_EXT_SUPP_RATES;
780 *pos++ = rates_len - count;
782 for (i++; i < sband->n_bitrates; i++) {
783 if (BIT(i) & rates) {
785 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
792 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
793 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
794 pos = skb_put(skb, 4);
795 *pos++ = WLAN_EID_PWR_CAPABILITY;
797 *pos++ = 0; /* min tx power */
799 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
802 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
803 /* TODO: get this in reg domain format */
804 pos = skb_put(skb, 2 * sband->n_channels + 2);
805 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
806 *pos++ = 2 * sband->n_channels;
807 for (i = 0; i < sband->n_channels; i++) {
808 *pos++ = ieee80211_frequency_to_channel(
809 sband->channels[i].center_freq);
810 *pos++ = 1; /* one channel in the subband*/
814 /* Set MBSSID support for HE AP if needed */
815 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
816 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len) {
817 struct element *elem;
819 /* we know it's writable, cast away the const */
820 elem = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
824 /* We can probably assume both always true */
825 if (elem && elem->datalen >= 3)
826 elem->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
829 /* if present, add any custom IEs that go before HT */
830 if (assoc_data->ie_len) {
831 static const u8 before_ht[] = {
834 WLAN_EID_EXT_SUPP_RATES,
835 WLAN_EID_PWR_CAPABILITY,
836 WLAN_EID_SUPPORTED_CHANNELS,
839 WLAN_EID_RRM_ENABLED_CAPABILITIES,
840 WLAN_EID_MOBILITY_DOMAIN,
841 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
842 WLAN_EID_RIC_DATA, /* reassoc only */
843 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
845 static const u8 after_ric[] = {
846 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
847 WLAN_EID_HT_CAPABILITY,
848 WLAN_EID_BSS_COEX_2040,
849 /* luckily this is almost always there */
850 WLAN_EID_EXT_CAPABILITY,
851 WLAN_EID_QOS_TRAFFIC_CAPA,
852 WLAN_EID_TIM_BCAST_REQ,
853 WLAN_EID_INTERWORKING,
854 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
855 WLAN_EID_VHT_CAPABILITY,
856 WLAN_EID_OPMODE_NOTIF,
859 noffset = ieee80211_ie_split_ric(assoc_data->ie,
862 ARRAY_SIZE(before_ht),
864 ARRAY_SIZE(after_ric),
866 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
870 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
871 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
872 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
874 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
875 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
876 sband, chan, sdata->smps_mode);
878 /* if present, add any custom IEs that go before VHT */
879 if (assoc_data->ie_len) {
880 static const u8 before_vht[] = {
882 * no need to list the ones split off before HT
885 WLAN_EID_BSS_COEX_2040,
886 WLAN_EID_EXT_CAPABILITY,
887 WLAN_EID_QOS_TRAFFIC_CAPA,
888 WLAN_EID_TIM_BCAST_REQ,
889 WLAN_EID_INTERWORKING,
890 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
893 /* RIC already taken above, so no need to handle here anymore */
894 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
895 before_vht, ARRAY_SIZE(before_vht),
897 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
901 /* if present, add any custom IEs that go before HE */
902 if (assoc_data->ie_len) {
903 static const u8 before_he[] = {
905 * no need to list the ones split off before VHT
908 WLAN_EID_OPMODE_NOTIF,
909 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
911 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
912 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
913 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
914 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
915 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
916 /* TODO: add 11ah/11aj/11ak elements */
919 /* RIC already taken above, so no need to handle here anymore */
920 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
921 before_he, ARRAY_SIZE(before_he),
923 pos = skb_put(skb, noffset - offset);
924 memcpy(pos, assoc_data->ie + offset, noffset - offset);
928 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
929 ieee80211_add_vht_ie(sdata, skb, sband,
930 &assoc_data->ap_vht_cap);
933 * If AP doesn't support HT, mark HE as disabled.
934 * If on the 5GHz band, make sure it supports VHT.
936 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
937 (sband->band == NL80211_BAND_5GHZ &&
938 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
939 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
941 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
942 ieee80211_add_he_ie(sdata, skb, sband);
944 /* if present, add any custom non-vendor IEs that go after HE */
945 if (assoc_data->ie_len) {
946 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
949 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
953 if (assoc_data->wmm) {
954 if (assoc_data->uapsd) {
955 qos_info = ifmgd->uapsd_queues;
956 qos_info |= (ifmgd->uapsd_max_sp_len <<
957 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
962 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
965 /* add any remaining custom (i.e. vendor specific here) IEs */
966 if (assoc_data->ie_len) {
967 noffset = assoc_data->ie_len;
968 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
971 if (assoc_data->fils_kek_len &&
972 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
977 pos = skb_tail_pointer(skb);
978 kfree(ifmgd->assoc_req_ies);
979 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
980 ifmgd->assoc_req_ies_len = pos - ie_start;
982 drv_mgd_prepare_tx(local, sdata, 0);
984 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
985 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
986 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
987 IEEE80211_TX_INTFL_MLME_CONN_TX;
988 ieee80211_tx_skb(sdata, skb);
991 void ieee80211_send_pspoll(struct ieee80211_local *local,
992 struct ieee80211_sub_if_data *sdata)
994 struct ieee80211_pspoll *pspoll;
997 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1001 pspoll = (struct ieee80211_pspoll *) skb->data;
1002 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1004 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1005 ieee80211_tx_skb(sdata, skb);
1008 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1009 struct ieee80211_sub_if_data *sdata,
1012 struct sk_buff *skb;
1013 struct ieee80211_hdr_3addr *nullfunc;
1014 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1016 /* Don't send NDPs when STA is connected HE */
1017 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1018 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
1021 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1022 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1026 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1028 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1030 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1031 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1033 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1034 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1036 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1037 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1039 ieee80211_tx_skb(sdata, skb);
1042 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1043 struct ieee80211_sub_if_data *sdata)
1045 struct sk_buff *skb;
1046 struct ieee80211_hdr *nullfunc;
1049 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1052 /* Don't send NDPs when connected HE */
1053 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1056 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1060 skb_reserve(skb, local->hw.extra_tx_headroom);
1062 nullfunc = skb_put_zero(skb, 30);
1063 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1064 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1065 nullfunc->frame_control = fc;
1066 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1067 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1068 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1069 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1071 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1072 ieee80211_tx_skb(sdata, skb);
1075 /* spectrum management related things */
1076 static void ieee80211_chswitch_work(struct work_struct *work)
1078 struct ieee80211_sub_if_data *sdata =
1079 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
1080 struct ieee80211_local *local = sdata->local;
1081 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1084 if (!ieee80211_sdata_running(sdata))
1088 mutex_lock(&local->mtx);
1089 mutex_lock(&local->chanctx_mtx);
1091 if (!ifmgd->associated)
1094 if (!sdata->vif.csa_active)
1098 * using reservation isn't immediate as it may be deferred until later
1099 * with multi-vif. once reservation is complete it will re-schedule the
1100 * work with no reserved_chanctx so verify chandef to check if it
1101 * completed successfully
1104 if (sdata->reserved_chanctx) {
1105 struct ieee80211_supported_band *sband = NULL;
1106 struct sta_info *mgd_sta = NULL;
1107 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1110 * with multi-vif csa driver may call ieee80211_csa_finish()
1111 * many times while waiting for other interfaces to use their
1114 if (sdata->reserved_ready)
1117 if (sdata->vif.bss_conf.chandef.width !=
1118 sdata->csa_chandef.width) {
1120 * For managed interface, we need to also update the AP
1121 * station bandwidth and align the rate scale algorithm
1122 * on the bandwidth change. Here we only consider the
1123 * bandwidth of the new channel definition (as channel
1124 * switch flow does not have the full HT/VHT/HE
1125 * information), assuming that if additional changes are
1126 * required they would be done as part of the processing
1127 * of the next beacon from the AP.
1129 switch (sdata->csa_chandef.width) {
1130 case NL80211_CHAN_WIDTH_20_NOHT:
1131 case NL80211_CHAN_WIDTH_20:
1133 bw = IEEE80211_STA_RX_BW_20;
1135 case NL80211_CHAN_WIDTH_40:
1136 bw = IEEE80211_STA_RX_BW_40;
1138 case NL80211_CHAN_WIDTH_80:
1139 bw = IEEE80211_STA_RX_BW_80;
1141 case NL80211_CHAN_WIDTH_80P80:
1142 case NL80211_CHAN_WIDTH_160:
1143 bw = IEEE80211_STA_RX_BW_160;
1147 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1149 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1152 if (sdata->vif.bss_conf.chandef.width >
1153 sdata->csa_chandef.width) {
1154 mgd_sta->sta.bandwidth = bw;
1155 rate_control_rate_update(local, sband, mgd_sta,
1156 IEEE80211_RC_BW_CHANGED);
1159 ret = ieee80211_vif_use_reserved_context(sdata);
1162 "failed to use reserved channel context, disconnecting (err=%d)\n",
1164 ieee80211_queue_work(&sdata->local->hw,
1165 &ifmgd->csa_connection_drop_work);
1169 if (sdata->vif.bss_conf.chandef.width <
1170 sdata->csa_chandef.width) {
1171 mgd_sta->sta.bandwidth = bw;
1172 rate_control_rate_update(local, sband, mgd_sta,
1173 IEEE80211_RC_BW_CHANGED);
1179 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1180 &sdata->csa_chandef)) {
1182 "failed to finalize channel switch, disconnecting\n");
1183 ieee80211_queue_work(&sdata->local->hw,
1184 &ifmgd->csa_connection_drop_work);
1188 ifmgd->csa_waiting_bcn = true;
1190 ieee80211_sta_reset_beacon_monitor(sdata);
1191 ieee80211_sta_reset_conn_monitor(sdata);
1194 mutex_unlock(&local->chanctx_mtx);
1195 mutex_unlock(&local->mtx);
1196 sdata_unlock(sdata);
1199 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1201 struct ieee80211_local *local = sdata->local;
1202 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1205 sdata_assert_lock(sdata);
1207 WARN_ON(!sdata->vif.csa_active);
1209 if (sdata->csa_block_tx) {
1210 ieee80211_wake_vif_queues(local, sdata,
1211 IEEE80211_QUEUE_STOP_REASON_CSA);
1212 sdata->csa_block_tx = false;
1215 sdata->vif.csa_active = false;
1216 ifmgd->csa_waiting_bcn = false;
1218 ret = drv_post_channel_switch(sdata);
1221 "driver post channel switch failed, disconnecting\n");
1222 ieee80211_queue_work(&local->hw,
1223 &ifmgd->csa_connection_drop_work);
1227 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1230 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1232 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1233 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1235 trace_api_chswitch_done(sdata, success);
1238 "driver channel switch failed, disconnecting\n");
1239 ieee80211_queue_work(&sdata->local->hw,
1240 &ifmgd->csa_connection_drop_work);
1242 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1245 EXPORT_SYMBOL(ieee80211_chswitch_done);
1247 static void ieee80211_chswitch_timer(struct timer_list *t)
1249 struct ieee80211_sub_if_data *sdata =
1250 from_timer(sdata, t, u.mgd.chswitch_timer);
1252 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1256 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1258 struct ieee80211_local *local = sdata->local;
1260 if (!local->ops->abort_channel_switch)
1263 mutex_lock(&local->mtx);
1265 mutex_lock(&local->chanctx_mtx);
1266 ieee80211_vif_unreserve_chanctx(sdata);
1267 mutex_unlock(&local->chanctx_mtx);
1269 if (sdata->csa_block_tx)
1270 ieee80211_wake_vif_queues(local, sdata,
1271 IEEE80211_QUEUE_STOP_REASON_CSA);
1273 sdata->csa_block_tx = false;
1274 sdata->vif.csa_active = false;
1276 mutex_unlock(&local->mtx);
1278 drv_abort_channel_switch(sdata);
1282 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1283 u64 timestamp, u32 device_timestamp,
1284 struct ieee802_11_elems *elems,
1287 struct ieee80211_local *local = sdata->local;
1288 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1289 struct cfg80211_bss *cbss = ifmgd->associated;
1290 struct ieee80211_chanctx_conf *conf;
1291 struct ieee80211_chanctx *chanctx;
1292 enum nl80211_band current_band;
1293 struct ieee80211_csa_ie csa_ie;
1294 struct ieee80211_channel_switch ch_switch;
1297 sdata_assert_lock(sdata);
1302 if (local->scanning)
1305 current_band = cbss->channel->band;
1306 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1308 ifmgd->associated->bssid, &csa_ie);
1311 ch_switch.timestamp = timestamp;
1312 ch_switch.device_timestamp = device_timestamp;
1313 ch_switch.block_tx = beacon ? csa_ie.mode : 0;
1314 ch_switch.chandef = csa_ie.chandef;
1315 ch_switch.count = csa_ie.count;
1316 ch_switch.delay = csa_ie.max_switch_time;
1320 ieee80211_queue_work(&local->hw,
1321 &ifmgd->csa_connection_drop_work);
1325 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1327 ieee80211_sta_abort_chanswitch(sdata);
1329 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1331 } else if (sdata->vif.csa_active || res) {
1332 /* disregard subsequent announcements if already processing */
1336 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1337 IEEE80211_CHAN_DISABLED)) {
1339 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1340 ifmgd->associated->bssid,
1341 csa_ie.chandef.chan->center_freq,
1342 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1343 csa_ie.chandef.center_freq2);
1344 ieee80211_queue_work(&local->hw,
1345 &ifmgd->csa_connection_drop_work);
1349 if (cfg80211_chandef_identical(&csa_ie.chandef,
1350 &sdata->vif.bss_conf.chandef) &&
1351 (!csa_ie.mode || !beacon)) {
1352 if (ifmgd->csa_ignored_same_chan)
1355 "AP %pM tries to chanswitch to same channel, ignore\n",
1356 ifmgd->associated->bssid);
1357 ifmgd->csa_ignored_same_chan = true;
1362 * Drop all TDLS peers - either we disconnect or move to a different
1363 * channel from this point on. There's no telling what our peer will do.
1364 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1365 * have an incompatible wider chandef.
1367 ieee80211_teardown_tdls_peers(sdata);
1369 mutex_lock(&local->mtx);
1370 mutex_lock(&local->chanctx_mtx);
1371 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1372 lockdep_is_held(&local->chanctx_mtx));
1375 "no channel context assigned to vif?, disconnecting\n");
1376 goto drop_connection;
1379 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1381 if (local->use_chanctx &&
1382 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1384 "driver doesn't support chan-switch with channel contexts\n");
1385 goto drop_connection;
1388 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1390 "preparing for channel switch failed, disconnecting\n");
1391 goto drop_connection;
1394 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1395 chanctx->mode, false);
1398 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1400 goto drop_connection;
1402 mutex_unlock(&local->chanctx_mtx);
1404 sdata->vif.csa_active = true;
1405 sdata->csa_chandef = csa_ie.chandef;
1406 sdata->csa_block_tx = ch_switch.block_tx;
1407 ifmgd->csa_ignored_same_chan = false;
1409 if (sdata->csa_block_tx)
1410 ieee80211_stop_vif_queues(local, sdata,
1411 IEEE80211_QUEUE_STOP_REASON_CSA);
1412 mutex_unlock(&local->mtx);
1414 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1417 if (local->ops->channel_switch) {
1418 /* use driver's channel switch callback */
1419 drv_channel_switch(local, sdata, &ch_switch);
1423 /* channel switch handled in software */
1424 if (csa_ie.count <= 1)
1425 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1427 mod_timer(&ifmgd->chswitch_timer,
1428 TU_TO_EXP_TIME((csa_ie.count - 1) *
1429 cbss->beacon_interval));
1433 * This is just so that the disconnect flow will know that
1434 * we were trying to switch channel and failed. In case the
1435 * mode is 1 (we are not allowed to Tx), we will know not to
1436 * send a deauthentication frame. Those two fields will be
1437 * reset when the disconnection worker runs.
1439 sdata->vif.csa_active = true;
1440 sdata->csa_block_tx = ch_switch.block_tx;
1442 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1443 mutex_unlock(&local->chanctx_mtx);
1444 mutex_unlock(&local->mtx);
1448 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1449 struct ieee80211_channel *channel,
1450 const u8 *country_ie, u8 country_ie_len,
1451 const u8 *pwr_constr_elem,
1452 int *chan_pwr, int *pwr_reduction)
1454 struct ieee80211_country_ie_triplet *triplet;
1455 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1456 int i, chan_increment;
1457 bool have_chan_pwr = false;
1460 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1463 triplet = (void *)(country_ie + 3);
1464 country_ie_len -= 3;
1466 switch (channel->band) {
1470 case NL80211_BAND_2GHZ:
1471 case NL80211_BAND_60GHZ:
1474 case NL80211_BAND_5GHZ:
1480 while (country_ie_len >= 3) {
1481 u8 first_channel = triplet->chans.first_channel;
1483 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1486 for (i = 0; i < triplet->chans.num_channels; i++) {
1487 if (first_channel + i * chan_increment == chan) {
1488 have_chan_pwr = true;
1489 *chan_pwr = triplet->chans.max_power;
1498 country_ie_len -= 3;
1501 if (have_chan_pwr && pwr_constr_elem)
1502 *pwr_reduction = *pwr_constr_elem;
1506 return have_chan_pwr;
1509 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1510 struct ieee80211_channel *channel,
1511 const u8 *cisco_dtpc_ie,
1514 /* From practical testing, the first data byte of the DTPC element
1515 * seems to contain the requested dBm level, and the CLI on Cisco
1516 * APs clearly state the range is -127 to 127 dBm, which indicates
1517 * a signed byte, although it seemingly never actually goes negative.
1518 * The other byte seems to always be zero.
1520 *pwr_level = (__s8)cisco_dtpc_ie[4];
1523 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1524 struct ieee80211_channel *channel,
1525 struct ieee80211_mgmt *mgmt,
1526 const u8 *country_ie, u8 country_ie_len,
1527 const u8 *pwr_constr_ie,
1528 const u8 *cisco_dtpc_ie)
1530 bool has_80211h_pwr = false, has_cisco_pwr = false;
1531 int chan_pwr = 0, pwr_reduction_80211h = 0;
1532 int pwr_level_cisco, pwr_level_80211h;
1534 __le16 capab = mgmt->u.probe_resp.capab_info;
1537 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1538 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1539 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1540 sdata, channel, country_ie, country_ie_len,
1541 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1543 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1546 if (cisco_dtpc_ie) {
1547 ieee80211_find_cisco_dtpc(
1548 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1549 has_cisco_pwr = true;
1552 if (!has_80211h_pwr && !has_cisco_pwr)
1555 /* If we have both 802.11h and Cisco DTPC, apply both limits
1556 * by picking the smallest of the two power levels advertised.
1558 if (has_80211h_pwr &&
1559 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1560 new_ap_level = pwr_level_80211h;
1562 if (sdata->ap_power_level == new_ap_level)
1566 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1567 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1568 sdata->u.mgd.bssid);
1569 } else { /* has_cisco_pwr is always true here. */
1570 new_ap_level = pwr_level_cisco;
1572 if (sdata->ap_power_level == new_ap_level)
1576 "Limiting TX power to %d dBm as advertised by %pM\n",
1577 pwr_level_cisco, sdata->u.mgd.bssid);
1580 sdata->ap_power_level = new_ap_level;
1581 if (__ieee80211_recalc_txpower(sdata))
1582 return BSS_CHANGED_TXPOWER;
1587 static void ieee80211_enable_ps(struct ieee80211_local *local,
1588 struct ieee80211_sub_if_data *sdata)
1590 struct ieee80211_conf *conf = &local->hw.conf;
1593 * If we are scanning right now then the parameters will
1594 * take effect when scan finishes.
1596 if (local->scanning)
1599 if (conf->dynamic_ps_timeout > 0 &&
1600 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1601 mod_timer(&local->dynamic_ps_timer, jiffies +
1602 msecs_to_jiffies(conf->dynamic_ps_timeout));
1604 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1605 ieee80211_send_nullfunc(local, sdata, true);
1607 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1608 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1611 conf->flags |= IEEE80211_CONF_PS;
1612 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1616 static void ieee80211_change_ps(struct ieee80211_local *local)
1618 struct ieee80211_conf *conf = &local->hw.conf;
1620 if (local->ps_sdata) {
1621 ieee80211_enable_ps(local, local->ps_sdata);
1622 } else if (conf->flags & IEEE80211_CONF_PS) {
1623 conf->flags &= ~IEEE80211_CONF_PS;
1624 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1625 del_timer_sync(&local->dynamic_ps_timer);
1626 cancel_work_sync(&local->dynamic_ps_enable_work);
1630 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1632 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1633 struct sta_info *sta = NULL;
1634 bool authorized = false;
1636 if (!mgd->powersave)
1642 if (!mgd->associated)
1645 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1648 if (!mgd->have_beacon)
1652 sta = sta_info_get(sdata, mgd->bssid);
1654 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1660 /* need to hold RTNL or interface lock */
1661 void ieee80211_recalc_ps(struct ieee80211_local *local)
1663 struct ieee80211_sub_if_data *sdata, *found = NULL;
1667 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1668 local->ps_sdata = NULL;
1672 list_for_each_entry(sdata, &local->interfaces, list) {
1673 if (!ieee80211_sdata_running(sdata))
1675 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1676 /* If an AP vif is found, then disable PS
1677 * by setting the count to zero thereby setting
1683 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1689 if (count == 1 && ieee80211_powersave_allowed(found)) {
1690 u8 dtimper = found->u.mgd.dtim_period;
1692 timeout = local->dynamic_ps_forced_timeout;
1695 local->hw.conf.dynamic_ps_timeout = timeout;
1697 /* If the TIM IE is invalid, pretend the value is 1 */
1701 local->hw.conf.ps_dtim_period = dtimper;
1702 local->ps_sdata = found;
1704 local->ps_sdata = NULL;
1707 ieee80211_change_ps(local);
1710 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1712 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1714 if (sdata->vif.bss_conf.ps != ps_allowed) {
1715 sdata->vif.bss_conf.ps = ps_allowed;
1716 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1720 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1722 struct ieee80211_local *local =
1723 container_of(work, struct ieee80211_local,
1724 dynamic_ps_disable_work);
1726 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1727 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1728 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1731 ieee80211_wake_queues_by_reason(&local->hw,
1732 IEEE80211_MAX_QUEUE_MAP,
1733 IEEE80211_QUEUE_STOP_REASON_PS,
1737 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1739 struct ieee80211_local *local =
1740 container_of(work, struct ieee80211_local,
1741 dynamic_ps_enable_work);
1742 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1743 struct ieee80211_if_managed *ifmgd;
1744 unsigned long flags;
1747 /* can only happen when PS was just disabled anyway */
1751 ifmgd = &sdata->u.mgd;
1753 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1756 if (local->hw.conf.dynamic_ps_timeout > 0) {
1757 /* don't enter PS if TX frames are pending */
1758 if (drv_tx_frames_pending(local)) {
1759 mod_timer(&local->dynamic_ps_timer, jiffies +
1761 local->hw.conf.dynamic_ps_timeout));
1766 * transmission can be stopped by others which leads to
1767 * dynamic_ps_timer expiry. Postpone the ps timer if it
1768 * is not the actual idle state.
1770 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1771 for (q = 0; q < local->hw.queues; q++) {
1772 if (local->queue_stop_reasons[q]) {
1773 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1775 mod_timer(&local->dynamic_ps_timer, jiffies +
1777 local->hw.conf.dynamic_ps_timeout));
1781 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1784 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1785 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1786 if (drv_tx_frames_pending(local)) {
1787 mod_timer(&local->dynamic_ps_timer, jiffies +
1789 local->hw.conf.dynamic_ps_timeout));
1791 ieee80211_send_nullfunc(local, sdata, true);
1792 /* Flush to get the tx status of nullfunc frame */
1793 ieee80211_flush_queues(local, sdata, false);
1797 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1798 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1799 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1800 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1801 local->hw.conf.flags |= IEEE80211_CONF_PS;
1802 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1806 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1808 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1810 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1813 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1815 struct delayed_work *delayed_work = to_delayed_work(work);
1816 struct ieee80211_sub_if_data *sdata =
1817 container_of(delayed_work, struct ieee80211_sub_if_data,
1818 dfs_cac_timer_work);
1819 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1821 mutex_lock(&sdata->local->mtx);
1822 if (sdata->wdev.cac_started) {
1823 ieee80211_vif_release_channel(sdata);
1824 cfg80211_cac_event(sdata->dev, &chandef,
1825 NL80211_RADAR_CAC_FINISHED,
1828 mutex_unlock(&sdata->local->mtx);
1832 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1834 struct ieee80211_local *local = sdata->local;
1835 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1839 if (local->hw.queues < IEEE80211_NUM_ACS)
1842 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1843 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1845 unsigned long now = jiffies;
1847 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1848 tx_tspec->admitted_time &&
1849 time_after(now, tx_tspec->time_slice_start + HZ)) {
1850 tx_tspec->consumed_tx_time = 0;
1851 tx_tspec->time_slice_start = now;
1853 if (tx_tspec->downgraded)
1855 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1858 switch (tx_tspec->action) {
1859 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1860 /* take the original parameters */
1861 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1863 "failed to set TX queue parameters for queue %d\n",
1865 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1866 tx_tspec->downgraded = false;
1869 case TX_TSPEC_ACTION_DOWNGRADE:
1870 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1871 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1875 /* downgrade next lower non-ACM AC */
1876 for (non_acm_ac = ac + 1;
1877 non_acm_ac < IEEE80211_NUM_ACS;
1879 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1881 /* Usually the loop will result in using BK even if it
1882 * requires admission control, but such a configuration
1883 * makes no sense and we have to transmit somehow - the
1884 * AC selection does the same thing.
1885 * If we started out trying to downgrade from BK, then
1886 * the extra condition here might be needed.
1888 if (non_acm_ac >= IEEE80211_NUM_ACS)
1889 non_acm_ac = IEEE80211_AC_BK;
1890 if (drv_conf_tx(local, sdata, ac,
1891 &sdata->tx_conf[non_acm_ac]))
1893 "failed to set TX queue parameters for queue %d\n",
1895 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1897 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1898 tx_tspec->time_slice_start + HZ - now + 1);
1900 case TX_TSPEC_ACTION_NONE:
1909 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1911 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1912 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1915 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1917 struct ieee80211_sub_if_data *sdata;
1919 sdata = container_of(work, struct ieee80211_sub_if_data,
1920 u.mgd.tx_tspec_wk.work);
1921 ieee80211_sta_handle_tspec_ac_params(sdata);
1926 ieee80211_sta_wmm_params(struct ieee80211_local *local,
1927 struct ieee80211_sub_if_data *sdata,
1928 const u8 *wmm_param, size_t wmm_param_len,
1929 const struct ieee80211_mu_edca_param_set *mu_edca)
1931 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1932 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1934 int count, mu_edca_count, ac;
1936 u8 uapsd_queues = 0;
1938 if (!local->ops->conf_tx)
1941 if (local->hw.queues < IEEE80211_NUM_ACS)
1947 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1950 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1951 uapsd_queues = ifmgd->uapsd_queues;
1953 count = wmm_param[6] & 0x0f;
1954 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1955 * if mu_edca was preset before and now it disappeared tell
1956 * the driver about it.
1958 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1959 if (count == ifmgd->wmm_last_param_set &&
1960 mu_edca_count == ifmgd->mu_edca_last_param_set)
1962 ifmgd->wmm_last_param_set = count;
1963 ifmgd->mu_edca_last_param_set = mu_edca_count;
1965 pos = wmm_param + 8;
1966 left = wmm_param_len - 8;
1968 memset(¶ms, 0, sizeof(params));
1971 for (; left >= 4; left -= 4, pos += 4) {
1972 int aci = (pos[0] >> 5) & 0x03;
1973 int acm = (pos[0] >> 4) & 0x01;
1978 ac = IEEE80211_AC_BK;
1980 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
1981 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1983 params[ac].mu_edca = !!mu_edca;
1985 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
1988 ac = IEEE80211_AC_VI;
1990 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
1991 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1993 params[ac].mu_edca = !!mu_edca;
1995 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
1998 ac = IEEE80211_AC_VO;
2000 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2001 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2003 params[ac].mu_edca = !!mu_edca;
2005 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2009 ac = IEEE80211_AC_BE;
2011 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2012 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2014 params[ac].mu_edca = !!mu_edca;
2016 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2020 params[ac].aifs = pos[0] & 0x0f;
2022 if (params[ac].aifs < 2) {
2024 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2025 params[ac].aifs, aci);
2026 params[ac].aifs = 2;
2028 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2029 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2030 params[ac].txop = get_unaligned_le16(pos + 2);
2031 params[ac].acm = acm;
2032 params[ac].uapsd = uapsd;
2034 if (params[ac].cw_min == 0 ||
2035 params[ac].cw_min > params[ac].cw_max) {
2037 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2038 params[ac].cw_min, params[ac].cw_max, aci);
2041 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2044 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2046 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2048 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2049 params[ac].txop, params[ac].uapsd,
2050 ifmgd->tx_tspec[ac].downgraded);
2051 sdata->tx_conf[ac] = params[ac];
2052 if (!ifmgd->tx_tspec[ac].downgraded &&
2053 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2055 "failed to set TX queue parameters for AC %d\n",
2059 /* enable WMM or activate new settings */
2060 sdata->vif.bss_conf.qos = true;
2064 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2066 lockdep_assert_held(&sdata->local->mtx);
2068 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2069 ieee80211_run_deferred_scan(sdata->local);
2072 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2074 mutex_lock(&sdata->local->mtx);
2075 __ieee80211_stop_poll(sdata);
2076 mutex_unlock(&sdata->local->mtx);
2079 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2080 u16 capab, bool erp_valid, u8 erp)
2082 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2083 struct ieee80211_supported_band *sband;
2085 bool use_protection;
2086 bool use_short_preamble;
2087 bool use_short_slot;
2089 sband = ieee80211_get_sband(sdata);
2094 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2095 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2097 use_protection = false;
2098 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2101 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2102 if (sband->band == NL80211_BAND_5GHZ)
2103 use_short_slot = true;
2105 if (use_protection != bss_conf->use_cts_prot) {
2106 bss_conf->use_cts_prot = use_protection;
2107 changed |= BSS_CHANGED_ERP_CTS_PROT;
2110 if (use_short_preamble != bss_conf->use_short_preamble) {
2111 bss_conf->use_short_preamble = use_short_preamble;
2112 changed |= BSS_CHANGED_ERP_PREAMBLE;
2115 if (use_short_slot != bss_conf->use_short_slot) {
2116 bss_conf->use_short_slot = use_short_slot;
2117 changed |= BSS_CHANGED_ERP_SLOT;
2123 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2124 struct cfg80211_bss *cbss,
2125 u32 bss_info_changed)
2127 struct ieee80211_bss *bss = (void *)cbss->priv;
2128 struct ieee80211_local *local = sdata->local;
2129 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2131 bss_info_changed |= BSS_CHANGED_ASSOC;
2132 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2133 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2135 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2136 beacon_loss_count * bss_conf->beacon_int));
2138 sdata->u.mgd.associated = cbss;
2139 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2141 ieee80211_check_rate_mask(sdata);
2143 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2145 if (sdata->vif.p2p ||
2146 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2147 const struct cfg80211_bss_ies *ies;
2150 ies = rcu_dereference(cbss->ies);
2154 ret = cfg80211_get_p2p_attr(
2155 ies->data, ies->len,
2156 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2157 (u8 *) &bss_conf->p2p_noa_attr,
2158 sizeof(bss_conf->p2p_noa_attr));
2160 sdata->u.mgd.p2p_noa_index =
2161 bss_conf->p2p_noa_attr.index;
2162 bss_info_changed |= BSS_CHANGED_P2P_PS;
2168 /* just to be sure */
2169 ieee80211_stop_poll(sdata);
2171 ieee80211_led_assoc(local, 1);
2173 if (sdata->u.mgd.have_beacon) {
2175 * If the AP is buggy we may get here with no DTIM period
2176 * known, so assume it's 1 which is the only safe assumption
2177 * in that case, although if the TIM IE is broken powersave
2178 * probably just won't work at all.
2180 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2181 bss_conf->beacon_rate = bss->beacon_rate;
2182 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2184 bss_conf->beacon_rate = NULL;
2185 bss_conf->dtim_period = 0;
2188 bss_conf->assoc = 1;
2190 /* Tell the driver to monitor connection quality (if supported) */
2191 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2192 bss_conf->cqm_rssi_thold)
2193 bss_info_changed |= BSS_CHANGED_CQM;
2195 /* Enable ARP filtering */
2196 if (bss_conf->arp_addr_cnt)
2197 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2199 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2201 mutex_lock(&local->iflist_mtx);
2202 ieee80211_recalc_ps(local);
2203 mutex_unlock(&local->iflist_mtx);
2205 ieee80211_recalc_smps(sdata);
2206 ieee80211_recalc_ps_vif(sdata);
2208 netif_carrier_on(sdata->dev);
2211 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2212 u16 stype, u16 reason, bool tx,
2215 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2216 struct ieee80211_local *local = sdata->local;
2219 sdata_assert_lock(sdata);
2221 if (WARN_ON_ONCE(tx && !frame_buf))
2224 if (WARN_ON(!ifmgd->associated))
2227 ieee80211_stop_poll(sdata);
2229 ifmgd->associated = NULL;
2230 netif_carrier_off(sdata->dev);
2233 * if we want to get out of ps before disassoc (why?) we have
2234 * to do it before sending disassoc, as otherwise the null-packet
2237 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2238 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2239 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2241 local->ps_sdata = NULL;
2243 /* disable per-vif ps */
2244 ieee80211_recalc_ps_vif(sdata);
2246 /* make sure ongoing transmission finishes */
2250 * drop any frame before deauth/disassoc, this can be data or
2251 * management frame. Since we are disconnecting, we should not
2252 * insist sending these frames which can take time and delay
2253 * the disconnection and possible the roaming.
2256 ieee80211_flush_queues(local, sdata, true);
2258 /* deauthenticate/disassociate now */
2259 if (tx || frame_buf) {
2261 * In multi channel scenarios guarantee that the virtual
2262 * interface is granted immediate airtime to transmit the
2263 * deauthentication frame by calling mgd_prepare_tx, if the
2264 * driver requested so.
2266 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2267 !ifmgd->have_beacon)
2268 drv_mgd_prepare_tx(sdata->local, sdata, 0);
2270 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
2271 reason, tx, frame_buf);
2274 /* flush out frame - make sure the deauth was actually sent */
2276 ieee80211_flush_queues(local, sdata, false);
2278 /* clear bssid only after building the needed mgmt frames */
2279 eth_zero_addr(ifmgd->bssid);
2281 /* remove AP and TDLS peers */
2282 sta_info_flush(sdata);
2284 /* finally reset all BSS / config parameters */
2285 changed |= ieee80211_reset_erp_info(sdata);
2287 ieee80211_led_assoc(local, 0);
2288 changed |= BSS_CHANGED_ASSOC;
2289 sdata->vif.bss_conf.assoc = false;
2291 ifmgd->p2p_noa_index = -1;
2292 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2293 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2295 /* on the next assoc, re-program HT/VHT parameters */
2296 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2297 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2298 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2299 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2301 /* reset MU-MIMO ownership and group data */
2302 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2303 sizeof(sdata->vif.bss_conf.mu_group.membership));
2304 memset(sdata->vif.bss_conf.mu_group.position, 0,
2305 sizeof(sdata->vif.bss_conf.mu_group.position));
2306 changed |= BSS_CHANGED_MU_GROUPS;
2307 sdata->vif.mu_mimo_owner = false;
2309 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2311 del_timer_sync(&local->dynamic_ps_timer);
2312 cancel_work_sync(&local->dynamic_ps_enable_work);
2314 /* Disable ARP filtering */
2315 if (sdata->vif.bss_conf.arp_addr_cnt)
2316 changed |= BSS_CHANGED_ARP_FILTER;
2318 sdata->vif.bss_conf.qos = false;
2319 changed |= BSS_CHANGED_QOS;
2321 /* The BSSID (not really interesting) and HT changed */
2322 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2323 ieee80211_bss_info_change_notify(sdata, changed);
2325 /* disassociated - set to defaults now */
2326 ieee80211_set_wmm_default(sdata, false, false);
2328 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2329 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2330 del_timer_sync(&sdata->u.mgd.timer);
2331 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2333 sdata->vif.bss_conf.dtim_period = 0;
2334 sdata->vif.bss_conf.beacon_rate = NULL;
2336 ifmgd->have_beacon = false;
2339 mutex_lock(&local->mtx);
2340 ieee80211_vif_release_channel(sdata);
2342 sdata->vif.csa_active = false;
2343 ifmgd->csa_waiting_bcn = false;
2344 ifmgd->csa_ignored_same_chan = false;
2345 if (sdata->csa_block_tx) {
2346 ieee80211_wake_vif_queues(local, sdata,
2347 IEEE80211_QUEUE_STOP_REASON_CSA);
2348 sdata->csa_block_tx = false;
2350 mutex_unlock(&local->mtx);
2352 /* existing TX TSPEC sessions no longer exist */
2353 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2354 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2356 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2359 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2360 struct ieee80211_hdr *hdr)
2363 * We can postpone the mgd.timer whenever receiving unicast frames
2364 * from AP because we know that the connection is working both ways
2365 * at that time. But multicast frames (and hence also beacons) must
2366 * be ignored here, because we need to trigger the timer during
2367 * data idle periods for sending the periodic probe request to the
2368 * AP we're connected to.
2370 if (is_multicast_ether_addr(hdr->addr1))
2373 ieee80211_sta_reset_conn_monitor(sdata);
2376 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2378 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2379 struct ieee80211_local *local = sdata->local;
2381 mutex_lock(&local->mtx);
2382 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2385 __ieee80211_stop_poll(sdata);
2387 mutex_lock(&local->iflist_mtx);
2388 ieee80211_recalc_ps(local);
2389 mutex_unlock(&local->iflist_mtx);
2391 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2395 * We've received a probe response, but are not sure whether
2396 * we have or will be receiving any beacons or data, so let's
2397 * schedule the timers again, just in case.
2399 ieee80211_sta_reset_beacon_monitor(sdata);
2401 mod_timer(&ifmgd->conn_mon_timer,
2402 round_jiffies_up(jiffies +
2403 IEEE80211_CONNECTION_IDLE_TIME));
2405 mutex_unlock(&local->mtx);
2408 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2409 struct ieee80211_hdr *hdr,
2412 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2413 u16 tid = ieee80211_get_tid(hdr);
2414 int ac = ieee80211_ac_from_tid(tid);
2415 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2416 unsigned long now = jiffies;
2418 if (likely(!tx_tspec->admitted_time))
2421 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2422 tx_tspec->consumed_tx_time = 0;
2423 tx_tspec->time_slice_start = now;
2425 if (tx_tspec->downgraded) {
2426 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2427 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2431 if (tx_tspec->downgraded)
2434 tx_tspec->consumed_tx_time += tx_time;
2436 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2437 tx_tspec->downgraded = true;
2438 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2439 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2443 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2444 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2446 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2448 if (!ieee80211_is_data(hdr->frame_control))
2451 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2452 sdata->u.mgd.probe_send_count > 0) {
2454 ieee80211_sta_reset_conn_monitor(sdata);
2456 sdata->u.mgd.nullfunc_failed = true;
2457 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2462 ieee80211_sta_reset_conn_monitor(sdata);
2465 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2466 const u8 *src, const u8 *dst,
2467 const u8 *ssid, size_t ssid_len,
2468 struct ieee80211_channel *channel)
2470 struct sk_buff *skb;
2472 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2473 ssid, ssid_len, NULL, 0,
2474 IEEE80211_PROBE_FLAG_DIRECTED);
2476 ieee80211_tx_skb(sdata, skb);
2479 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2481 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2483 u8 *dst = ifmgd->associated->bssid;
2484 u8 unicast_limit = max(1, max_probe_tries - 3);
2485 struct sta_info *sta;
2488 * Try sending broadcast probe requests for the last three
2489 * probe requests after the first ones failed since some
2490 * buggy APs only support broadcast probe requests.
2492 if (ifmgd->probe_send_count >= unicast_limit)
2496 * When the hardware reports an accurate Tx ACK status, it's
2497 * better to send a nullfunc frame instead of a probe request,
2498 * as it will kick us off the AP quickly if we aren't associated
2499 * anymore. The timeout will be reset if the frame is ACKed by
2502 ifmgd->probe_send_count++;
2505 mutex_lock(&sdata->local->sta_mtx);
2506 sta = sta_info_get(sdata, dst);
2508 ieee80211_check_fast_rx(sta);
2509 mutex_unlock(&sdata->local->sta_mtx);
2512 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2513 ifmgd->nullfunc_failed = false;
2514 ieee80211_send_nullfunc(sdata->local, sdata, false);
2519 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
2520 if (WARN_ON_ONCE(ssid == NULL))
2525 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2527 ifmgd->associated->channel);
2531 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2532 run_again(sdata, ifmgd->probe_timeout);
2535 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2538 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2539 bool already = false;
2541 if (!ieee80211_sdata_running(sdata))
2546 if (!ifmgd->associated)
2549 mutex_lock(&sdata->local->mtx);
2551 if (sdata->local->tmp_channel || sdata->local->scanning) {
2552 mutex_unlock(&sdata->local->mtx);
2557 mlme_dbg_ratelimited(sdata,
2558 "detected beacon loss from AP (missed %d beacons) - probing\n",
2561 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2565 * The driver/our work has already reported this event or the
2566 * connection monitoring has kicked in and we have already sent
2567 * a probe request. Or maybe the AP died and the driver keeps
2568 * reporting until we disassociate...
2570 * In either case we have to ignore the current call to this
2571 * function (except for setting the correct probe reason bit)
2572 * because otherwise we would reset the timer every time and
2573 * never check whether we received a probe response!
2575 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2578 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2580 mutex_unlock(&sdata->local->mtx);
2585 mutex_lock(&sdata->local->iflist_mtx);
2586 ieee80211_recalc_ps(sdata->local);
2587 mutex_unlock(&sdata->local->iflist_mtx);
2589 ifmgd->probe_send_count = 0;
2590 ieee80211_mgd_probe_ap_send(sdata);
2592 sdata_unlock(sdata);
2595 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2596 struct ieee80211_vif *vif)
2598 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2599 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2600 struct cfg80211_bss *cbss;
2601 struct sk_buff *skb;
2605 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2608 sdata_assert_lock(sdata);
2610 if (ifmgd->associated)
2611 cbss = ifmgd->associated;
2612 else if (ifmgd->auth_data)
2613 cbss = ifmgd->auth_data->bss;
2614 else if (ifmgd->assoc_data)
2615 cbss = ifmgd->assoc_data->bss;
2620 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2621 if (WARN_ON_ONCE(ssid == NULL))
2626 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2627 (u32) -1, cbss->channel,
2629 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2634 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2636 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2637 const u8 *buf, size_t len, bool tx,
2640 struct ieee80211_event event = {
2642 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2643 .u.mlme.reason = reason,
2647 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2649 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2651 drv_event_callback(sdata->local, sdata, &event);
2654 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2656 struct ieee80211_local *local = sdata->local;
2657 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2658 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2662 if (!ifmgd->associated) {
2663 sdata_unlock(sdata);
2667 tx = !sdata->csa_block_tx;
2669 /* AP is probably out of range (or not reachable for another reason) so
2670 * remove the bss struct for that AP.
2672 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2674 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2675 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2677 mutex_lock(&local->mtx);
2678 sdata->vif.csa_active = false;
2679 ifmgd->csa_waiting_bcn = false;
2680 if (sdata->csa_block_tx) {
2681 ieee80211_wake_vif_queues(local, sdata,
2682 IEEE80211_QUEUE_STOP_REASON_CSA);
2683 sdata->csa_block_tx = false;
2685 mutex_unlock(&local->mtx);
2687 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2688 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2690 sdata_unlock(sdata);
2693 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2695 struct ieee80211_sub_if_data *sdata =
2696 container_of(work, struct ieee80211_sub_if_data,
2697 u.mgd.beacon_connection_loss_work);
2698 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2700 if (ifmgd->associated)
2701 ifmgd->beacon_loss_count++;
2703 if (ifmgd->connection_loss) {
2704 sdata_info(sdata, "Connection to AP %pM lost\n",
2706 __ieee80211_disconnect(sdata);
2708 ieee80211_mgd_probe_ap(sdata, true);
2712 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2714 struct ieee80211_sub_if_data *sdata =
2715 container_of(work, struct ieee80211_sub_if_data,
2716 u.mgd.csa_connection_drop_work);
2718 __ieee80211_disconnect(sdata);
2721 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2723 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2724 struct ieee80211_hw *hw = &sdata->local->hw;
2726 trace_api_beacon_loss(sdata);
2728 sdata->u.mgd.connection_loss = false;
2729 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2731 EXPORT_SYMBOL(ieee80211_beacon_loss);
2733 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2735 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2736 struct ieee80211_hw *hw = &sdata->local->hw;
2738 trace_api_connection_loss(sdata);
2740 sdata->u.mgd.connection_loss = true;
2741 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2743 EXPORT_SYMBOL(ieee80211_connection_loss);
2746 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2749 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2751 sdata_assert_lock(sdata);
2755 * we are not authenticated yet, the only timer that could be
2756 * running is the timeout for the authentication response which
2757 * which is not relevant anymore.
2759 del_timer_sync(&sdata->u.mgd.timer);
2760 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2762 eth_zero_addr(sdata->u.mgd.bssid);
2763 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2764 sdata->u.mgd.flags = 0;
2765 mutex_lock(&sdata->local->mtx);
2766 ieee80211_vif_release_channel(sdata);
2767 mutex_unlock(&sdata->local->mtx);
2770 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2772 sdata->u.mgd.auth_data = NULL;
2775 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2776 bool assoc, bool abandon)
2778 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2780 sdata_assert_lock(sdata);
2784 * we are not associated yet, the only timer that could be
2785 * running is the timeout for the association response which
2786 * which is not relevant anymore.
2788 del_timer_sync(&sdata->u.mgd.timer);
2789 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2791 eth_zero_addr(sdata->u.mgd.bssid);
2792 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2793 sdata->u.mgd.flags = 0;
2794 sdata->vif.mu_mimo_owner = false;
2796 mutex_lock(&sdata->local->mtx);
2797 ieee80211_vif_release_channel(sdata);
2798 mutex_unlock(&sdata->local->mtx);
2801 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2805 sdata->u.mgd.assoc_data = NULL;
2808 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2809 struct ieee80211_mgmt *mgmt, size_t len)
2811 struct ieee80211_local *local = sdata->local;
2812 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2814 struct ieee802_11_elems elems;
2817 pos = mgmt->u.auth.variable;
2818 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2819 mgmt->bssid, auth_data->bss->bssid);
2820 if (!elems.challenge)
2822 auth_data->expected_transaction = 4;
2823 drv_mgd_prepare_tx(sdata->local, sdata, 0);
2824 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2825 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2826 IEEE80211_TX_INTFL_MLME_CONN_TX;
2827 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2828 elems.challenge - 2, elems.challenge_len + 2,
2829 auth_data->bss->bssid, auth_data->bss->bssid,
2830 auth_data->key, auth_data->key_len,
2831 auth_data->key_idx, tx_flags);
2834 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2837 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2838 struct sta_info *sta;
2841 sdata_info(sdata, "authenticated\n");
2842 ifmgd->auth_data->done = true;
2843 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2844 ifmgd->auth_data->timeout_started = true;
2845 run_again(sdata, ifmgd->auth_data->timeout);
2847 /* move station state to auth */
2848 mutex_lock(&sdata->local->sta_mtx);
2849 sta = sta_info_get(sdata, bssid);
2851 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2855 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2856 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2862 mutex_unlock(&sdata->local->sta_mtx);
2866 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2867 struct ieee80211_mgmt *mgmt, size_t len)
2869 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2871 u16 auth_alg, auth_transaction, status_code;
2872 struct ieee80211_event event = {
2874 .u.mlme.data = AUTH_EVENT,
2877 sdata_assert_lock(sdata);
2882 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2885 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2887 if (!ether_addr_equal(bssid, mgmt->bssid))
2890 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2891 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2892 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2894 if (auth_alg != ifmgd->auth_data->algorithm ||
2895 (auth_alg != WLAN_AUTH_SAE &&
2896 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2897 (auth_alg == WLAN_AUTH_SAE &&
2898 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2899 auth_transaction > 2))) {
2900 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2901 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2903 ifmgd->auth_data->expected_transaction);
2907 if (status_code != WLAN_STATUS_SUCCESS) {
2908 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2909 mgmt->sa, status_code);
2910 ieee80211_destroy_auth_data(sdata, false);
2911 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2912 event.u.mlme.status = MLME_DENIED;
2913 event.u.mlme.reason = status_code;
2914 drv_event_callback(sdata->local, sdata, &event);
2918 switch (ifmgd->auth_data->algorithm) {
2919 case WLAN_AUTH_OPEN:
2920 case WLAN_AUTH_LEAP:
2923 case WLAN_AUTH_FILS_SK:
2924 case WLAN_AUTH_FILS_SK_PFS:
2925 case WLAN_AUTH_FILS_PK:
2927 case WLAN_AUTH_SHARED_KEY:
2928 if (ifmgd->auth_data->expected_transaction != 4) {
2929 ieee80211_auth_challenge(sdata, mgmt, len);
2930 /* need another frame */
2935 WARN_ONCE(1, "invalid auth alg %d",
2936 ifmgd->auth_data->algorithm);
2940 event.u.mlme.status = MLME_SUCCESS;
2941 drv_event_callback(sdata->local, sdata, &event);
2942 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
2943 (auth_transaction == 2 &&
2944 ifmgd->auth_data->expected_transaction == 2)) {
2945 if (!ieee80211_mark_sta_auth(sdata, bssid))
2947 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2948 auth_transaction == 2) {
2949 sdata_info(sdata, "SAE peer confirmed\n");
2950 ifmgd->auth_data->peer_confirmed = true;
2953 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2956 mutex_unlock(&sdata->local->sta_mtx);
2957 /* ignore frame -- wait for timeout */
2960 #define case_WLAN(type) \
2961 case WLAN_REASON_##type: return #type
2963 static const char *ieee80211_get_reason_code_string(u16 reason_code)
2965 switch (reason_code) {
2966 case_WLAN(UNSPECIFIED);
2967 case_WLAN(PREV_AUTH_NOT_VALID);
2968 case_WLAN(DEAUTH_LEAVING);
2969 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2970 case_WLAN(DISASSOC_AP_BUSY);
2971 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2972 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2973 case_WLAN(DISASSOC_STA_HAS_LEFT);
2974 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2975 case_WLAN(DISASSOC_BAD_POWER);
2976 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2977 case_WLAN(INVALID_IE);
2978 case_WLAN(MIC_FAILURE);
2979 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2980 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2981 case_WLAN(IE_DIFFERENT);
2982 case_WLAN(INVALID_GROUP_CIPHER);
2983 case_WLAN(INVALID_PAIRWISE_CIPHER);
2984 case_WLAN(INVALID_AKMP);
2985 case_WLAN(UNSUPP_RSN_VERSION);
2986 case_WLAN(INVALID_RSN_IE_CAP);
2987 case_WLAN(IEEE8021X_FAILED);
2988 case_WLAN(CIPHER_SUITE_REJECTED);
2989 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2990 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2991 case_WLAN(DISASSOC_LOW_ACK);
2992 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2993 case_WLAN(QSTA_LEAVE_QBSS);
2994 case_WLAN(QSTA_NOT_USE);
2995 case_WLAN(QSTA_REQUIRE_SETUP);
2996 case_WLAN(QSTA_TIMEOUT);
2997 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2998 case_WLAN(MESH_PEER_CANCELED);
2999 case_WLAN(MESH_MAX_PEERS);
3000 case_WLAN(MESH_CONFIG);
3001 case_WLAN(MESH_CLOSE);
3002 case_WLAN(MESH_MAX_RETRIES);
3003 case_WLAN(MESH_CONFIRM_TIMEOUT);
3004 case_WLAN(MESH_INVALID_GTK);
3005 case_WLAN(MESH_INCONSISTENT_PARAM);
3006 case_WLAN(MESH_INVALID_SECURITY);
3007 case_WLAN(MESH_PATH_ERROR);
3008 case_WLAN(MESH_PATH_NOFORWARD);
3009 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3010 case_WLAN(MAC_EXISTS_IN_MBSS);
3011 case_WLAN(MESH_CHAN_REGULATORY);
3012 case_WLAN(MESH_CHAN);
3013 default: return "<unknown>";
3017 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3018 struct ieee80211_mgmt *mgmt, size_t len)
3020 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3021 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3023 sdata_assert_lock(sdata);
3028 if (ifmgd->associated &&
3029 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3030 const u8 *bssid = ifmgd->associated->bssid;
3032 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3034 ieee80211_get_reason_code_string(reason_code));
3036 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3038 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3043 if (ifmgd->assoc_data &&
3044 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3045 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3048 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3050 ieee80211_get_reason_code_string(reason_code));
3052 ieee80211_destroy_assoc_data(sdata, false, true);
3054 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3060 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3061 struct ieee80211_mgmt *mgmt, size_t len)
3063 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3066 sdata_assert_lock(sdata);
3071 if (!ifmgd->associated ||
3072 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3075 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3077 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3078 mgmt->sa, reason_code,
3079 ieee80211_get_reason_code_string(reason_code));
3081 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3083 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
3086 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3087 u8 *supp_rates, unsigned int supp_rates_len,
3088 u32 *rates, u32 *basic_rates,
3089 bool *have_higher_than_11mbit,
3090 int *min_rate, int *min_rate_index,
3095 for (i = 0; i < supp_rates_len; i++) {
3096 int rate = supp_rates[i] & 0x7f;
3097 bool is_basic = !!(supp_rates[i] & 0x80);
3099 if ((rate * 5 * (1 << shift)) > 110)
3100 *have_higher_than_11mbit = true;
3103 * Skip HT and VHT BSS membership selectors since they're not
3106 * Note: Even though the membership selector and the basic
3107 * rate flag share the same bit, they are not exactly
3110 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3111 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
3114 for (j = 0; j < sband->n_bitrates; j++) {
3115 struct ieee80211_rate *br;
3118 br = &sband->bitrates[j];
3120 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3121 if (brate == rate) {
3124 *basic_rates |= BIT(j);
3125 if ((rate * 5) < *min_rate) {
3126 *min_rate = rate * 5;
3127 *min_rate_index = j;
3135 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3136 const struct ieee802_11_elems *elems)
3138 if (elems->ext_capab_len < 10)
3141 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3144 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3145 IEEE80211_HE_MAC_CAP0_TWT_RES;
3148 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3149 struct cfg80211_bss *cbss,
3150 struct ieee80211_mgmt *mgmt, size_t len)
3152 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3153 struct ieee80211_local *local = sdata->local;
3154 struct ieee80211_supported_band *sband;
3155 struct sta_info *sta;
3157 u16 capab_info, aid;
3158 struct ieee802_11_elems elems;
3159 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3160 const struct cfg80211_bss_ies *bss_ies = NULL;
3161 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3166 /* AssocResp and ReassocResp have identical structure */
3168 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3169 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3172 * The 5 MSB of the AID field are reserved
3173 * (802.11-2016 9.4.1.8 AID field)
3177 ifmgd->broken_ap = false;
3179 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3180 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3183 ifmgd->broken_ap = true;
3186 pos = mgmt->u.assoc_resp.variable;
3187 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3188 mgmt->bssid, assoc_data->bss->bssid);
3190 if (!elems.supp_rates) {
3191 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3196 ifmgd->tdls_chan_switch_prohibited =
3197 elems.ext_capab && elems.ext_capab_len >= 5 &&
3198 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3201 * Some APs are erroneously not including some information in their
3202 * (re)association response frames. Try to recover by using the data
3203 * from the beacon or probe response. This seems to afflict mobile
3204 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3205 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3207 if ((assoc_data->wmm && !elems.wmm_param) ||
3208 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3209 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3210 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3211 (!elems.vht_cap_elem || !elems.vht_operation))) {
3212 const struct cfg80211_bss_ies *ies;
3213 struct ieee802_11_elems bss_elems;
3216 ies = rcu_dereference(cbss->ies);
3218 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3224 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3227 assoc_data->bss->bssid);
3228 if (assoc_data->wmm &&
3229 !elems.wmm_param && bss_elems.wmm_param) {
3230 elems.wmm_param = bss_elems.wmm_param;
3232 "AP bug: WMM param missing from AssocResp\n");
3236 * Also check if we requested HT/VHT, otherwise the AP doesn't
3237 * have to include the IEs in the (re)association response.
3239 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3240 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3241 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3243 "AP bug: HT capability missing from AssocResp\n");
3245 if (!elems.ht_operation && bss_elems.ht_operation &&
3246 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3247 elems.ht_operation = bss_elems.ht_operation;
3249 "AP bug: HT operation missing from AssocResp\n");
3251 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3252 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3253 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3255 "AP bug: VHT capa missing from AssocResp\n");
3257 if (!elems.vht_operation && bss_elems.vht_operation &&
3258 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3259 elems.vht_operation = bss_elems.vht_operation;
3261 "AP bug: VHT operation missing from AssocResp\n");
3266 * We previously checked these in the beacon/probe response, so
3267 * they should be present here. This is just a safety net.
3269 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3270 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3272 "HT AP is missing WMM params or HT capability/operation\n");
3277 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3278 (!elems.vht_cap_elem || !elems.vht_operation)) {
3280 "VHT AP is missing VHT capability/operation\n");
3285 mutex_lock(&sdata->local->sta_mtx);
3287 * station info was already allocated and inserted before
3288 * the association and should be available to us
3290 sta = sta_info_get(sdata, cbss->bssid);
3291 if (WARN_ON(!sta)) {
3292 mutex_unlock(&sdata->local->sta_mtx);
3297 sband = ieee80211_get_sband(sdata);
3299 mutex_unlock(&sdata->local->sta_mtx);
3304 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3305 (!elems.he_cap || !elems.he_operation)) {
3306 mutex_unlock(&sdata->local->sta_mtx);
3308 "HE AP is missing HE capability/operation\n");
3313 /* Set up internal HT/VHT capabilities */
3314 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3315 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3316 elems.ht_cap_elem, sta);
3318 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3319 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3320 elems.vht_cap_elem, sta);
3322 if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3324 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3329 bss_conf->he_support = sta->sta.he_cap.has_he;
3330 bss_conf->twt_requester =
3331 ieee80211_twt_req_supported(sta, &elems);
3333 bss_conf->he_support = false;
3334 bss_conf->twt_requester = false;
3337 if (bss_conf->he_support) {
3338 bss_conf->bss_color =
3339 le32_get_bits(elems.he_operation->he_oper_params,
3340 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3342 bss_conf->htc_trig_based_pkt_ext =
3343 le32_get_bits(elems.he_operation->he_oper_params,
3344 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3345 bss_conf->frame_time_rts_th =
3346 le32_get_bits(elems.he_operation->he_oper_params,
3347 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3349 bss_conf->multi_sta_back_32bit =
3350 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3351 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3353 bss_conf->ack_enabled =
3354 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3355 IEEE80211_HE_MAC_CAP2_ACK_EN;
3357 bss_conf->uora_exists = !!elems.uora_element;
3358 if (elems.uora_element)
3359 bss_conf->uora_ocw_range = elems.uora_element[0];
3361 /* TODO: OPEN: what happens if BSS color disable is set? */
3364 if (cbss->transmitted_bss) {
3365 bss_conf->nontransmitted = true;
3366 ether_addr_copy(bss_conf->transmitter_bssid,
3367 cbss->transmitted_bss->bssid);
3368 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3369 bss_conf->bssid_index = cbss->bssid_index;
3373 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3374 * in their association response, so ignore that data for our own
3375 * configuration. If it changed since the last beacon, we'll get the
3376 * next beacon and update then.
3380 * If an operating mode notification IE is present, override the
3381 * NSS calculation (that would be done in rate_control_rate_init())
3382 * and use the # of streams from that element.
3384 if (elems.opmode_notif &&
3385 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3388 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3389 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3391 sta->sta.rx_nss = nss;
3394 rate_control_rate_init(sta);
3396 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3397 set_sta_flag(sta, WLAN_STA_MFP);
3398 sta->sta.mfp = true;
3400 sta->sta.mfp = false;
3403 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
3405 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3406 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3407 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3410 "failed to move station %pM to desired state\n",
3412 WARN_ON(__sta_info_destroy(sta));
3413 mutex_unlock(&sdata->local->sta_mtx);
3418 mutex_unlock(&sdata->local->sta_mtx);
3421 * Always handle WMM once after association regardless
3422 * of the first value the AP uses. Setting -1 here has
3423 * that effect because the AP values is an unsigned
3426 ifmgd->wmm_last_param_set = -1;
3427 ifmgd->mu_edca_last_param_set = -1;
3429 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3430 ieee80211_set_wmm_default(sdata, false, false);
3431 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3432 elems.wmm_param_len,
3433 elems.mu_edca_param_set)) {
3434 /* still enable QoS since we might have HT/VHT */
3435 ieee80211_set_wmm_default(sdata, false, true);
3436 /* set the disable-WMM flag in this case to disable
3437 * tracking WMM parameter changes in the beacon if
3438 * the parameters weren't actually valid. Doing so
3439 * avoids changing parameters very strangely when
3440 * the AP is going back and forth between valid and
3441 * invalid parameters.
3443 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3445 changed |= BSS_CHANGED_QOS;
3447 if (elems.max_idle_period_ie) {
3448 bss_conf->max_idle_period =
3449 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3450 bss_conf->protected_keep_alive =
3451 !!(elems.max_idle_period_ie->idle_options &
3452 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3453 changed |= BSS_CHANGED_KEEP_ALIVE;
3455 bss_conf->max_idle_period = 0;
3456 bss_conf->protected_keep_alive = false;
3459 /* set AID and assoc capability,
3460 * ieee80211_set_associated() will tell the driver */
3461 bss_conf->aid = aid;
3462 bss_conf->assoc_capability = capab_info;
3463 ieee80211_set_associated(sdata, cbss, changed);
3466 * If we're using 4-addr mode, let the AP know that we're
3467 * doing so, so that it can create the STA VLAN on its side
3469 if (ifmgd->use_4addr)
3470 ieee80211_send_4addr_nullfunc(local, sdata);
3473 * Start timer to probe the connection to the AP now.
3474 * Also start the timer that will detect beacon loss.
3476 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
3477 ieee80211_sta_reset_beacon_monitor(sdata);
3485 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3486 struct ieee80211_mgmt *mgmt,
3489 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3490 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3491 u16 capab_info, status_code, aid;
3492 struct ieee802_11_elems elems;
3493 int ac, uapsd_queues = -1;
3496 struct cfg80211_bss *bss;
3497 struct ieee80211_event event = {
3499 .u.mlme.data = ASSOC_EVENT,
3502 sdata_assert_lock(sdata);
3506 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3510 * AssocResp and ReassocResp have identical structure, so process both
3511 * of them in this function.
3517 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3518 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3519 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3520 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3523 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3524 reassoc ? "Rea" : "A", mgmt->sa,
3525 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3527 if (assoc_data->fils_kek_len &&
3528 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3531 pos = mgmt->u.assoc_resp.variable;
3532 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3533 mgmt->bssid, assoc_data->bss->bssid);
3535 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3536 elems.timeout_int &&
3537 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3539 tu = le32_to_cpu(elems.timeout_int->value);
3540 ms = tu * 1024 / 1000;
3542 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3544 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3545 assoc_data->timeout_started = true;
3546 if (ms > IEEE80211_ASSOC_TIMEOUT)
3547 run_again(sdata, assoc_data->timeout);
3551 bss = assoc_data->bss;
3553 if (status_code != WLAN_STATUS_SUCCESS) {
3554 sdata_info(sdata, "%pM denied association (code=%d)\n",
3555 mgmt->sa, status_code);
3556 ieee80211_destroy_assoc_data(sdata, false, false);
3557 event.u.mlme.status = MLME_DENIED;
3558 event.u.mlme.reason = status_code;
3559 drv_event_callback(sdata->local, sdata, &event);
3561 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
3562 /* oops -- internal error -- send timeout for now */
3563 ieee80211_destroy_assoc_data(sdata, false, false);
3564 cfg80211_assoc_timeout(sdata->dev, bss);
3567 event.u.mlme.status = MLME_SUCCESS;
3568 drv_event_callback(sdata->local, sdata, &event);
3569 sdata_info(sdata, "associated\n");
3572 * destroy assoc_data afterwards, as otherwise an idle
3573 * recalc after assoc_data is NULL but before associated
3574 * is set can cause the interface to go idle
3576 ieee80211_destroy_assoc_data(sdata, true, false);
3578 /* get uapsd queues configuration */
3580 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3581 if (sdata->tx_conf[ac].uapsd)
3582 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3585 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues,
3586 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3589 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3590 struct ieee80211_mgmt *mgmt, size_t len,
3591 struct ieee80211_rx_status *rx_status)
3593 struct ieee80211_local *local = sdata->local;
3594 struct ieee80211_bss *bss;
3595 struct ieee80211_channel *channel;
3597 sdata_assert_lock(sdata);
3599 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3603 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3605 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3606 ieee80211_rx_bss_put(local, bss);
3611 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3612 struct sk_buff *skb)
3614 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3615 struct ieee80211_if_managed *ifmgd;
3616 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3617 size_t baselen, len = skb->len;
3619 ifmgd = &sdata->u.mgd;
3621 sdata_assert_lock(sdata);
3623 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
3624 return; /* ignore ProbeResp to foreign address */
3626 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3630 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3632 if (ifmgd->associated &&
3633 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3634 ieee80211_reset_ap_probe(sdata);
3638 * This is the canonical list of information elements we care about,
3639 * the filter code also gives us all changes to the Microsoft OUI
3640 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3641 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3642 * changes to requested client power.
3644 * We implement beacon filtering in software since that means we can
3645 * avoid processing the frame here and in cfg80211, and userspace
3646 * will not be able to tell whether the hardware supports it or not.
3648 * XXX: This list needs to be dynamic -- userspace needs to be able to
3649 * add items it requires. It also needs to be able to tell us to
3650 * look out for other vendor IEs.
3652 static const u64 care_about_ies =
3653 (1ULL << WLAN_EID_COUNTRY) |
3654 (1ULL << WLAN_EID_ERP_INFO) |
3655 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3656 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3657 (1ULL << WLAN_EID_HT_CAPABILITY) |
3658 (1ULL << WLAN_EID_HT_OPERATION) |
3659 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3661 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3662 struct ieee80211_if_managed *ifmgd,
3663 struct ieee80211_bss_conf *bss_conf,
3664 struct ieee80211_local *local,
3665 struct ieee80211_rx_status *rx_status)
3667 /* Track average RSSI from the Beacon frames of the current AP */
3669 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3670 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3671 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3672 ifmgd->last_cqm_event_signal = 0;
3673 ifmgd->count_beacon_signal = 1;
3674 ifmgd->last_ave_beacon_signal = 0;
3676 ifmgd->count_beacon_signal++;
3679 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3681 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3682 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3683 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3684 int last_sig = ifmgd->last_ave_beacon_signal;
3685 struct ieee80211_event event = {
3690 * if signal crosses either of the boundaries, invoke callback
3691 * with appropriate parameters
3693 if (sig > ifmgd->rssi_max_thold &&
3694 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3695 ifmgd->last_ave_beacon_signal = sig;
3696 event.u.rssi.data = RSSI_EVENT_HIGH;
3697 drv_event_callback(local, sdata, &event);
3698 } else if (sig < ifmgd->rssi_min_thold &&
3699 (last_sig >= ifmgd->rssi_max_thold ||
3701 ifmgd->last_ave_beacon_signal = sig;
3702 event.u.rssi.data = RSSI_EVENT_LOW;
3703 drv_event_callback(local, sdata, &event);
3707 if (bss_conf->cqm_rssi_thold &&
3708 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3709 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3710 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3711 int last_event = ifmgd->last_cqm_event_signal;
3712 int thold = bss_conf->cqm_rssi_thold;
3713 int hyst = bss_conf->cqm_rssi_hyst;
3716 (last_event == 0 || sig < last_event - hyst)) {
3717 ifmgd->last_cqm_event_signal = sig;
3718 ieee80211_cqm_rssi_notify(
3720 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3722 } else if (sig > thold &&
3723 (last_event == 0 || sig > last_event + hyst)) {
3724 ifmgd->last_cqm_event_signal = sig;
3725 ieee80211_cqm_rssi_notify(
3727 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3732 if (bss_conf->cqm_rssi_low &&
3733 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3734 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3735 int last_event = ifmgd->last_cqm_event_signal;
3736 int low = bss_conf->cqm_rssi_low;
3737 int high = bss_conf->cqm_rssi_high;
3740 (last_event == 0 || last_event >= low)) {
3741 ifmgd->last_cqm_event_signal = sig;
3742 ieee80211_cqm_rssi_notify(
3744 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3746 } else if (sig > high &&
3747 (last_event == 0 || last_event <= high)) {
3748 ifmgd->last_cqm_event_signal = sig;
3749 ieee80211_cqm_rssi_notify(
3751 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3757 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3758 struct cfg80211_bss *bss)
3760 if (ether_addr_equal(tx_bssid, bss->bssid))
3762 if (!bss->transmitted_bss)
3764 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3767 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3768 struct ieee80211_mgmt *mgmt, size_t len,
3769 struct ieee80211_rx_status *rx_status)
3771 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3772 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3774 struct ieee802_11_elems elems;
3775 struct ieee80211_local *local = sdata->local;
3776 struct ieee80211_chanctx_conf *chanctx_conf;
3777 struct ieee80211_channel *chan;
3778 struct sta_info *sta;
3784 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3786 sdata_assert_lock(sdata);
3788 /* Process beacon from the current BSS */
3789 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3794 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3795 if (!chanctx_conf) {
3800 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3804 chan = chanctx_conf->def.chan;
3807 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3808 ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) {
3809 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3810 len - baselen, false, &elems,
3812 ifmgd->assoc_data->bss->bssid);
3814 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3816 if (elems.dtim_period)
3817 ifmgd->dtim_period = elems.dtim_period;
3818 ifmgd->have_beacon = true;
3819 ifmgd->assoc_data->need_beacon = false;
3820 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3821 sdata->vif.bss_conf.sync_tsf =
3822 le64_to_cpu(mgmt->u.beacon.timestamp);
3823 sdata->vif.bss_conf.sync_device_ts =
3824 rx_status->device_timestamp;
3825 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
3828 if (elems.mbssid_config_ie)
3829 bss_conf->profile_periodicity =
3830 elems.mbssid_config_ie->profile_periodicity;
3832 if (elems.ext_capab_len >= 11 &&
3833 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
3834 bss_conf->ema_ap = true;
3836 /* continue assoc process */
3837 ifmgd->assoc_data->timeout = jiffies;
3838 ifmgd->assoc_data->timeout_started = true;
3839 run_again(sdata, ifmgd->assoc_data->timeout);
3843 if (!ifmgd->associated ||
3844 !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated))
3846 bssid = ifmgd->associated->bssid;
3848 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3849 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3852 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
3853 mlme_dbg_ratelimited(sdata,
3854 "cancelling AP probe due to a received beacon\n");
3855 ieee80211_reset_ap_probe(sdata);
3859 * Push the beacon loss detection into the future since
3860 * we are processing a beacon from the AP just now.
3862 ieee80211_sta_reset_beacon_monitor(sdata);
3864 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3865 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
3866 len - baselen, false, &elems,
3867 care_about_ies, ncrc,
3868 mgmt->bssid, bssid);
3870 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3871 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3872 if (local->hw.conf.dynamic_ps_timeout > 0) {
3873 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3874 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3875 ieee80211_hw_config(local,
3876 IEEE80211_CONF_CHANGE_PS);
3878 ieee80211_send_nullfunc(local, sdata, false);
3879 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3880 local->pspolling = true;
3883 * Here is assumed that the driver will be
3884 * able to send ps-poll frame and receive a
3885 * response even though power save mode is
3886 * enabled, but some drivers might require
3887 * to disable power save here. This needs
3888 * to be investigated.
3890 ieee80211_send_pspoll(local, sdata);
3894 if (sdata->vif.p2p ||
3895 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
3896 struct ieee80211_p2p_noa_attr noa = {};
3899 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3901 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
3902 (u8 *) &noa, sizeof(noa));
3904 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3905 /* valid noa_attr and index changed */
3906 sdata->u.mgd.p2p_noa_index = noa.index;
3907 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3908 changed |= BSS_CHANGED_P2P_PS;
3910 * make sure we update all information, the CRC
3911 * mechanism doesn't look at P2P attributes.
3913 ifmgd->beacon_crc_valid = false;
3915 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3916 /* noa_attr not found and we had valid noa_attr before */
3917 sdata->u.mgd.p2p_noa_index = -1;
3918 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
3919 changed |= BSS_CHANGED_P2P_PS;
3920 ifmgd->beacon_crc_valid = false;
3924 if (ifmgd->csa_waiting_bcn)
3925 ieee80211_chswitch_post_beacon(sdata);
3928 * Update beacon timing and dtim count on every beacon appearance. This
3929 * will allow the driver to use the most updated values. Do it before
3930 * comparing this one with last received beacon.
3931 * IMPORTANT: These parameters would possibly be out of sync by the time
3932 * the driver will use them. The synchronized view is currently
3933 * guaranteed only in certain callbacks.
3935 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3936 sdata->vif.bss_conf.sync_tsf =
3937 le64_to_cpu(mgmt->u.beacon.timestamp);
3938 sdata->vif.bss_conf.sync_device_ts =
3939 rx_status->device_timestamp;
3940 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
3943 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
3945 ifmgd->beacon_crc = ncrc;
3946 ifmgd->beacon_crc_valid = true;
3948 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3950 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
3951 rx_status->device_timestamp,
3954 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3955 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3956 elems.wmm_param_len,
3957 elems.mu_edca_param_set))
3958 changed |= BSS_CHANGED_QOS;
3961 * If we haven't had a beacon before, tell the driver about the
3962 * DTIM period (and beacon timing if desired) now.
3964 if (!ifmgd->have_beacon) {
3965 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3966 bss_conf->dtim_period = elems.dtim_period ?: 1;
3968 changed |= BSS_CHANGED_BEACON_INFO;
3969 ifmgd->have_beacon = true;
3971 mutex_lock(&local->iflist_mtx);
3972 ieee80211_recalc_ps(local);
3973 mutex_unlock(&local->iflist_mtx);
3975 ieee80211_recalc_ps_vif(sdata);
3978 if (elems.erp_info) {
3980 erp_value = elems.erp_info[0];
3984 changed |= ieee80211_handle_bss_capability(sdata,
3985 le16_to_cpu(mgmt->u.beacon.capab_info),
3986 erp_valid, erp_value);
3988 mutex_lock(&local->sta_mtx);
3989 sta = sta_info_get(sdata, bssid);
3991 if (ieee80211_config_bw(sdata, sta,
3992 elems.ht_cap_elem, elems.ht_operation,
3993 elems.vht_operation, elems.he_operation,
3995 mutex_unlock(&local->sta_mtx);
3997 "failed to follow AP %pM bandwidth change, disconnect\n",
3999 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4000 WLAN_REASON_DEAUTH_LEAVING,
4002 ieee80211_report_disconnect(sdata, deauth_buf,
4003 sizeof(deauth_buf), true,
4004 WLAN_REASON_DEAUTH_LEAVING);
4008 if (sta && elems.opmode_notif)
4009 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
4011 mutex_unlock(&local->sta_mtx);
4013 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4015 elems.country_elem_len,
4016 elems.pwr_constr_elem,
4017 elems.cisco_dtpc_elem);
4019 ieee80211_bss_info_change_notify(sdata, changed);
4022 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4023 struct sk_buff *skb)
4025 struct ieee80211_rx_status *rx_status;
4026 struct ieee80211_mgmt *mgmt;
4028 struct ieee802_11_elems elems;
4031 rx_status = (struct ieee80211_rx_status *) skb->cb;
4032 mgmt = (struct ieee80211_mgmt *) skb->data;
4033 fc = le16_to_cpu(mgmt->frame_control);
4037 switch (fc & IEEE80211_FCTL_STYPE) {
4038 case IEEE80211_STYPE_BEACON:
4039 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
4041 case IEEE80211_STYPE_PROBE_RESP:
4042 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4044 case IEEE80211_STYPE_AUTH:
4045 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4047 case IEEE80211_STYPE_DEAUTH:
4048 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4050 case IEEE80211_STYPE_DISASSOC:
4051 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4053 case IEEE80211_STYPE_ASSOC_RESP:
4054 case IEEE80211_STYPE_REASSOC_RESP:
4055 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4057 case IEEE80211_STYPE_ACTION:
4058 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4059 ies_len = skb->len -
4060 offsetof(struct ieee80211_mgmt,
4061 u.action.u.chan_switch.variable);
4066 /* CSA IE cannot be overridden, no need for BSSID */
4067 ieee802_11_parse_elems(
4068 mgmt->u.action.u.chan_switch.variable,
4069 ies_len, true, &elems, mgmt->bssid, NULL);
4071 if (elems.parse_error)
4074 ieee80211_sta_process_chanswitch(sdata,
4076 rx_status->device_timestamp,
4078 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4079 ies_len = skb->len -
4080 offsetof(struct ieee80211_mgmt,
4081 u.action.u.ext_chan_switch.variable);
4087 * extended CSA IE can't be overridden, no need for
4090 ieee802_11_parse_elems(
4091 mgmt->u.action.u.ext_chan_switch.variable,
4092 ies_len, true, &elems, mgmt->bssid, NULL);
4094 if (elems.parse_error)
4097 /* for the handling code pretend this was also an IE */
4098 elems.ext_chansw_ie =
4099 &mgmt->u.action.u.ext_chan_switch.data;
4101 ieee80211_sta_process_chanswitch(sdata,
4103 rx_status->device_timestamp,
4108 sdata_unlock(sdata);
4111 static void ieee80211_sta_timer(struct timer_list *t)
4113 struct ieee80211_sub_if_data *sdata =
4114 from_timer(sdata, t, u.mgd.timer);
4116 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4119 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4120 u8 *bssid, u8 reason, bool tx)
4122 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4124 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4127 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4131 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4133 struct ieee80211_local *local = sdata->local;
4134 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4135 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4139 u16 prepare_tx_duration = 0;
4141 sdata_assert_lock(sdata);
4143 if (WARN_ON_ONCE(!auth_data))
4148 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4149 sdata_info(sdata, "authentication with %pM timed out\n",
4150 auth_data->bss->bssid);
4153 * Most likely AP is not in the range so remove the
4154 * bss struct for that AP.
4156 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4161 if (auth_data->algorithm == WLAN_AUTH_SAE)
4162 prepare_tx_duration =
4163 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4165 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
4167 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4168 auth_data->bss->bssid, auth_data->tries,
4169 IEEE80211_AUTH_MAX_TRIES);
4171 auth_data->expected_transaction = 2;
4173 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4174 trans = auth_data->sae_trans;
4175 status = auth_data->sae_status;
4176 auth_data->expected_transaction = trans;
4179 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4180 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4181 IEEE80211_TX_INTFL_MLME_CONN_TX;
4183 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4184 auth_data->data, auth_data->data_len,
4185 auth_data->bss->bssid,
4186 auth_data->bss->bssid, NULL, 0, 0,
4189 if (tx_flags == 0) {
4190 if (auth_data->algorithm == WLAN_AUTH_SAE)
4191 auth_data->timeout = jiffies +
4192 IEEE80211_AUTH_TIMEOUT_SAE;
4194 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4196 auth_data->timeout =
4197 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4200 auth_data->timeout_started = true;
4201 run_again(sdata, auth_data->timeout);
4206 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4208 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4209 struct ieee80211_local *local = sdata->local;
4211 sdata_assert_lock(sdata);
4213 assoc_data->tries++;
4214 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4215 sdata_info(sdata, "association with %pM timed out\n",
4216 assoc_data->bss->bssid);
4219 * Most likely AP is not in the range so remove the
4220 * bss struct for that AP.
4222 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4227 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4228 assoc_data->bss->bssid, assoc_data->tries,
4229 IEEE80211_ASSOC_MAX_TRIES);
4230 ieee80211_send_assoc(sdata);
4232 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4233 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4234 assoc_data->timeout_started = true;
4235 run_again(sdata, assoc_data->timeout);
4237 assoc_data->timeout =
4238 round_jiffies_up(jiffies +
4239 IEEE80211_ASSOC_TIMEOUT_LONG);
4240 assoc_data->timeout_started = true;
4241 run_again(sdata, assoc_data->timeout);
4247 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4248 __le16 fc, bool acked)
4250 struct ieee80211_local *local = sdata->local;
4252 sdata->u.mgd.status_fc = fc;
4253 sdata->u.mgd.status_acked = acked;
4254 sdata->u.mgd.status_received = true;
4256 ieee80211_queue_work(&local->hw, &sdata->work);
4259 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4261 struct ieee80211_local *local = sdata->local;
4262 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4266 if (ifmgd->status_received) {
4267 __le16 fc = ifmgd->status_fc;
4268 bool status_acked = ifmgd->status_acked;
4270 ifmgd->status_received = false;
4271 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4273 if (ifmgd->auth_data->algorithm ==
4275 ifmgd->auth_data->timeout =
4277 IEEE80211_AUTH_TIMEOUT_SAE;
4279 ifmgd->auth_data->timeout =
4281 IEEE80211_AUTH_TIMEOUT_SHORT;
4282 run_again(sdata, ifmgd->auth_data->timeout);
4284 ifmgd->auth_data->timeout = jiffies - 1;
4286 ifmgd->auth_data->timeout_started = true;
4287 } else if (ifmgd->assoc_data &&
4288 (ieee80211_is_assoc_req(fc) ||
4289 ieee80211_is_reassoc_req(fc))) {
4291 ifmgd->assoc_data->timeout =
4292 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4293 run_again(sdata, ifmgd->assoc_data->timeout);
4295 ifmgd->assoc_data->timeout = jiffies - 1;
4297 ifmgd->assoc_data->timeout_started = true;
4301 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4302 time_after(jiffies, ifmgd->auth_data->timeout)) {
4303 if (ifmgd->auth_data->done) {
4305 * ok ... we waited for assoc but userspace didn't,
4306 * so let's just kill the auth data
4308 ieee80211_destroy_auth_data(sdata, false);
4309 } else if (ieee80211_auth(sdata)) {
4311 struct ieee80211_event event = {
4313 .u.mlme.data = AUTH_EVENT,
4314 .u.mlme.status = MLME_TIMEOUT,
4317 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4319 ieee80211_destroy_auth_data(sdata, false);
4321 cfg80211_auth_timeout(sdata->dev, bssid);
4322 drv_event_callback(sdata->local, sdata, &event);
4324 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4325 run_again(sdata, ifmgd->auth_data->timeout);
4327 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4328 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4329 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4330 ieee80211_do_assoc(sdata)) {
4331 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4332 struct ieee80211_event event = {
4334 .u.mlme.data = ASSOC_EVENT,
4335 .u.mlme.status = MLME_TIMEOUT,
4338 ieee80211_destroy_assoc_data(sdata, false, false);
4339 cfg80211_assoc_timeout(sdata->dev, bss);
4340 drv_event_callback(sdata->local, sdata, &event);
4342 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4343 run_again(sdata, ifmgd->assoc_data->timeout);
4345 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4346 ifmgd->associated) {
4350 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4352 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4353 max_tries = max_nullfunc_tries;
4355 max_tries = max_probe_tries;
4357 /* ACK received for nullfunc probing frame */
4358 if (!ifmgd->probe_send_count)
4359 ieee80211_reset_ap_probe(sdata);
4360 else if (ifmgd->nullfunc_failed) {
4361 if (ifmgd->probe_send_count < max_tries) {
4363 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4364 bssid, ifmgd->probe_send_count,
4366 ieee80211_mgd_probe_ap_send(sdata);
4369 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4371 ieee80211_sta_connection_lost(sdata, bssid,
4372 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4375 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4376 run_again(sdata, ifmgd->probe_timeout);
4377 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4379 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4380 bssid, probe_wait_ms);
4381 ieee80211_sta_connection_lost(sdata, bssid,
4382 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4383 } else if (ifmgd->probe_send_count < max_tries) {
4385 "No probe response from AP %pM after %dms, try %d/%i\n",
4386 bssid, probe_wait_ms,
4387 ifmgd->probe_send_count, max_tries);
4388 ieee80211_mgd_probe_ap_send(sdata);
4391 * We actually lost the connection ... or did we?
4395 "No probe response from AP %pM after %dms, disconnecting.\n",
4396 bssid, probe_wait_ms);
4398 ieee80211_sta_connection_lost(sdata, bssid,
4399 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4403 sdata_unlock(sdata);
4406 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4408 struct ieee80211_sub_if_data *sdata =
4409 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4410 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4412 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4415 sdata->u.mgd.connection_loss = false;
4416 ieee80211_queue_work(&sdata->local->hw,
4417 &sdata->u.mgd.beacon_connection_loss_work);
4420 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4422 struct ieee80211_sub_if_data *sdata =
4423 from_timer(sdata, t, u.mgd.conn_mon_timer);
4424 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4425 struct ieee80211_local *local = sdata->local;
4427 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4430 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4433 static void ieee80211_sta_monitor_work(struct work_struct *work)
4435 struct ieee80211_sub_if_data *sdata =
4436 container_of(work, struct ieee80211_sub_if_data,
4437 u.mgd.monitor_work);
4439 ieee80211_mgd_probe_ap(sdata, false);
4442 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4444 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4445 __ieee80211_stop_poll(sdata);
4447 /* let's probe the connection once */
4448 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4449 ieee80211_queue_work(&sdata->local->hw,
4450 &sdata->u.mgd.monitor_work);
4455 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4457 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4458 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4462 if (ifmgd->auth_data || ifmgd->assoc_data) {
4463 const u8 *bssid = ifmgd->auth_data ?
4464 ifmgd->auth_data->bss->bssid :
4465 ifmgd->assoc_data->bss->bssid;
4468 * If we are trying to authenticate / associate while suspending,
4469 * cfg80211 won't know and won't actually abort those attempts,
4470 * thus we need to do that ourselves.
4472 ieee80211_send_deauth_disassoc(sdata, bssid,
4473 IEEE80211_STYPE_DEAUTH,
4474 WLAN_REASON_DEAUTH_LEAVING,
4476 if (ifmgd->assoc_data)
4477 ieee80211_destroy_assoc_data(sdata, false, true);
4478 if (ifmgd->auth_data)
4479 ieee80211_destroy_auth_data(sdata, false);
4480 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4481 IEEE80211_DEAUTH_FRAME_LEN);
4484 /* This is a bit of a hack - we should find a better and more generic
4485 * solution to this. Normally when suspending, cfg80211 will in fact
4486 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4487 * auth (not so important) or assoc (this is the problem) process.
4489 * As a consequence, it can happen that we are in the process of both
4490 * associating and suspending, and receive an association response
4491 * after cfg80211 has checked if it needs to disconnect, but before
4492 * we actually set the flag to drop incoming frames. This will then
4493 * cause the workqueue flush to process the association response in
4494 * the suspend, resulting in a successful association just before it
4495 * tries to remove the interface from the driver, which now though
4496 * has a channel context assigned ... this results in issues.
4498 * To work around this (for now) simply deauth here again if we're
4501 if (ifmgd->associated && !sdata->local->wowlan) {
4503 struct cfg80211_deauth_request req = {
4504 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4508 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4509 ieee80211_mgd_deauth(sdata, &req);
4512 sdata_unlock(sdata);
4515 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4517 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4520 if (!ifmgd->associated) {
4521 sdata_unlock(sdata);
4525 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4526 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4527 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4528 ieee80211_sta_connection_lost(sdata,
4529 ifmgd->associated->bssid,
4530 WLAN_REASON_UNSPECIFIED,
4532 sdata_unlock(sdata);
4535 sdata_unlock(sdata);
4539 /* interface setup */
4540 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4542 struct ieee80211_if_managed *ifmgd;
4544 ifmgd = &sdata->u.mgd;
4545 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4546 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4547 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4548 ieee80211_beacon_connection_loss_work);
4549 INIT_WORK(&ifmgd->csa_connection_drop_work,
4550 ieee80211_csa_connection_drop_work);
4551 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4552 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4553 ieee80211_tdls_peer_del_work);
4554 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4555 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4556 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4557 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4558 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4559 ieee80211_sta_handle_tspec_ac_params_wk);
4562 ifmgd->powersave = sdata->wdev.ps;
4563 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4564 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4565 ifmgd->p2p_noa_index = -1;
4567 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4568 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4570 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4572 /* Setup TDLS data */
4573 spin_lock_init(&ifmgd->teardown_lock);
4574 ifmgd->teardown_skb = NULL;
4575 ifmgd->orig_teardown_skb = NULL;
4578 /* scan finished notification */
4579 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4581 struct ieee80211_sub_if_data *sdata;
4583 /* Restart STA timers */
4585 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4586 if (ieee80211_sdata_running(sdata))
4587 ieee80211_restart_sta_timer(sdata);
4592 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4593 struct cfg80211_bss *cbss)
4595 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4596 const u8 *ht_cap_ie, *vht_cap_ie;
4597 const struct ieee80211_ht_cap *ht_cap;
4598 const struct ieee80211_vht_cap *vht_cap;
4601 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4604 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4605 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4606 ht_cap = (void *)(ht_cap_ie + 2);
4607 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4609 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4610 * "Tx Unequal Modulation Supported" fields.
4614 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4617 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4618 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4622 vht_cap = (void *)(vht_cap_ie + 2);
4623 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4624 for (nss = 8; nss > 0; nss--) {
4625 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4626 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4629 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4630 chains = max(chains, nss);
4637 ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4638 const struct ieee80211_he_operation *he_op)
4640 const struct ieee80211_sta_he_cap *sta_he_cap =
4641 ieee80211_get_he_sta_cap(sband);
4645 if (!sta_he_cap || !he_op)
4648 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4650 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4651 for (i = 0; i < 3; i++) {
4652 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4653 &sta_he_cap->he_mcs_nss_supp;
4654 u16 sta_mcs_map_rx =
4655 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4656 u16 sta_mcs_map_tx =
4657 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4659 bool verified = true;
4662 * For each band there is a maximum of 8 spatial streams
4663 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4664 * of 2 bits per NSS (1-8), with the values defined in enum
4665 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4666 * capabilities aren't less than the AP's minimum requirements
4667 * for this HE BSS per SS.
4668 * It is enough to find one such band that meets the reqs.
4670 for (nss = 8; nss > 0; nss--) {
4671 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4672 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4673 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4675 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4679 * Make sure the HE AP doesn't require MCSs that aren't
4680 * supported by the client
4682 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4683 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4684 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4694 /* If here, STA doesn't meet AP's HE min requirements */
4698 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4699 struct cfg80211_bss *cbss)
4701 struct ieee80211_local *local = sdata->local;
4702 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4703 const struct ieee80211_ht_cap *ht_cap = NULL;
4704 const struct ieee80211_ht_operation *ht_oper = NULL;
4705 const struct ieee80211_vht_operation *vht_oper = NULL;
4706 const struct ieee80211_he_operation *he_oper = NULL;
4707 struct ieee80211_supported_band *sband;
4708 struct cfg80211_chan_def chandef;
4713 sband = local->hw.wiphy->bands[cbss->channel->band];
4715 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4716 IEEE80211_STA_DISABLE_80P80MHZ |
4717 IEEE80211_STA_DISABLE_160MHZ);
4721 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4722 sband->ht_cap.ht_supported) {
4723 const u8 *ht_oper_ie, *ht_cap_ie;
4725 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
4726 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4727 ht_oper = (void *)(ht_oper_ie + 2);
4729 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4730 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4731 ht_cap = (void *)(ht_cap_ie + 2);
4734 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4739 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4740 sband->vht_cap.vht_supported) {
4741 const u8 *vht_oper_ie, *vht_cap;
4743 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4744 WLAN_EID_VHT_OPERATION);
4745 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4746 vht_oper = (void *)(vht_oper_ie + 2);
4747 if (vht_oper && !ht_oper) {
4750 "AP advertised VHT without HT, disabling both\n");
4751 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4752 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4755 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4756 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4757 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4762 if (!ieee80211_get_he_sta_cap(sband))
4763 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4765 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
4766 const struct cfg80211_bss_ies *ies;
4767 const u8 *he_oper_ie;
4769 ies = rcu_dereference(cbss->ies);
4770 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4771 ies->data, ies->len);
4773 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4774 he_oper = (void *)(he_oper_ie + 3);
4778 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
4779 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4782 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4784 for (i = 0; i < sband->n_channels; i++) {
4785 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4786 IEEE80211_CHAN_NO_80MHZ))
4794 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4796 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4798 ht_oper, vht_oper, he_oper,
4801 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4806 /* will change later if needed */
4807 sdata->smps_mode = IEEE80211_SMPS_OFF;
4809 mutex_lock(&local->mtx);
4811 * If this fails (possibly due to channel context sharing
4812 * on incompatible channels, e.g. 80+80 and 160 sharing the
4813 * same control channel) try to use a smaller bandwidth.
4815 ret = ieee80211_vif_use_channel(sdata, &chandef,
4816 IEEE80211_CHANCTX_SHARED);
4818 /* don't downgrade for 5 and 10 MHz channels, though. */
4819 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4820 chandef.width == NL80211_CHAN_WIDTH_10)
4823 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4824 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
4825 ret = ieee80211_vif_use_channel(sdata, &chandef,
4826 IEEE80211_CHANCTX_SHARED);
4829 mutex_unlock(&local->mtx);
4833 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4834 u8 *dtim_count, u8 *dtim_period)
4836 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4837 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4839 const struct ieee80211_tim_ie *tim = NULL;
4840 const struct ieee80211_bssid_index *idx;
4841 bool valid = tim_ie && tim_ie[1] >= 2;
4844 tim = (void *)(tim_ie + 2);
4847 *dtim_count = valid ? tim->dtim_count : 0;
4850 *dtim_period = valid ? tim->dtim_period : 0;
4852 /* Check if value is overridden by non-transmitted profile */
4853 if (!idx_ie || idx_ie[1] < 3)
4856 idx = (void *)(idx_ie + 2);
4859 *dtim_count = idx->dtim_count;
4862 *dtim_period = idx->dtim_period;
4867 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
4868 struct cfg80211_bss *cbss, bool assoc,
4871 struct ieee80211_local *local = sdata->local;
4872 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4873 struct ieee80211_bss *bss = (void *)cbss->priv;
4874 struct sta_info *new_sta = NULL;
4875 struct ieee80211_supported_band *sband;
4876 bool have_sta = false;
4879 sband = local->hw.wiphy->bands[cbss->channel->band];
4881 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4884 /* If a reconfig is happening, bail out */
4885 if (local->in_reconfig)
4890 have_sta = sta_info_get(sdata, cbss->bssid);
4895 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4901 * Set up the information for the new channel before setting the
4902 * new channel. We can't - completely race-free - change the basic
4903 * rates bitmap and the channel (sband) that it refers to, but if
4904 * we set it up before we at least avoid calling into the driver's
4905 * bss_info_changed() method with invalid information (since we do
4906 * call that from changing the channel - only for IDLE and perhaps
4907 * some others, but ...).
4909 * So to avoid that, just set up all the new information before the
4910 * channel, but tell the driver to apply it only afterwards, since
4911 * it might need the new channel for that.
4914 u32 rates = 0, basic_rates = 0;
4915 bool have_higher_than_11mbit;
4916 int min_rate = INT_MAX, min_rate_index = -1;
4917 const struct cfg80211_bss_ies *ies;
4918 int shift = ieee80211_vif_get_shift(&sdata->vif);
4920 ieee80211_get_rates(sband, bss->supp_rates,
4921 bss->supp_rates_len,
4922 &rates, &basic_rates,
4923 &have_higher_than_11mbit,
4924 &min_rate, &min_rate_index,
4928 * This used to be a workaround for basic rates missing
4929 * in the association response frame. Now that we no
4930 * longer use the basic rates from there, it probably
4931 * doesn't happen any more, but keep the workaround so
4932 * in case some *other* APs are buggy in different ways
4933 * we can connect -- with a warning.
4935 if (!basic_rates && min_rate_index >= 0) {
4937 "No basic rates, using min rate instead\n");
4938 basic_rates = BIT(min_rate_index);
4941 new_sta->sta.supp_rates[cbss->channel->band] = rates;
4942 sdata->vif.bss_conf.basic_rates = basic_rates;
4944 /* cf. IEEE 802.11 9.2.12 */
4945 if (cbss->channel->band == NL80211_BAND_2GHZ &&
4946 have_higher_than_11mbit)
4947 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4949 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4951 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4953 /* set timing information */
4954 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
4956 ies = rcu_dereference(cbss->beacon_ies);
4958 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4959 sdata->vif.bss_conf.sync_device_ts =
4960 bss->device_ts_beacon;
4962 ieee80211_get_dtim(ies,
4963 &sdata->vif.bss_conf.sync_dtim_count,
4965 } else if (!ieee80211_hw_check(&sdata->local->hw,
4966 TIMING_BEACON_ONLY)) {
4967 ies = rcu_dereference(cbss->proberesp_ies);
4968 /* must be non-NULL since beacon IEs were NULL */
4969 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4970 sdata->vif.bss_conf.sync_device_ts =
4971 bss->device_ts_presp;
4972 sdata->vif.bss_conf.sync_dtim_count = 0;
4974 sdata->vif.bss_conf.sync_tsf = 0;
4975 sdata->vif.bss_conf.sync_device_ts = 0;
4976 sdata->vif.bss_conf.sync_dtim_count = 0;
4981 if (new_sta || override) {
4982 err = ieee80211_prep_channel(sdata, cbss);
4985 sta_info_free(local, new_sta);
4992 * tell driver about BSSID, basic rates and timing
4993 * this was set up above, before setting the channel
4995 ieee80211_bss_info_change_notify(sdata,
4996 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4997 BSS_CHANGED_BEACON_INT);
5000 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5002 err = sta_info_insert(new_sta);
5006 "failed to insert STA entry for the AP (error %d)\n",
5011 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5013 /* Cancel scan to ensure that nothing interferes with connection */
5014 if (local->scanning)
5015 ieee80211_scan_cancel(local);
5021 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5022 struct cfg80211_auth_request *req)
5024 struct ieee80211_local *local = sdata->local;
5025 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5026 struct ieee80211_mgd_auth_data *auth_data;
5031 /* prepare auth data structure */
5033 switch (req->auth_type) {
5034 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5035 auth_alg = WLAN_AUTH_OPEN;
5037 case NL80211_AUTHTYPE_SHARED_KEY:
5038 if (IS_ERR(local->wep_tx_tfm))
5040 auth_alg = WLAN_AUTH_SHARED_KEY;
5042 case NL80211_AUTHTYPE_FT:
5043 auth_alg = WLAN_AUTH_FT;
5045 case NL80211_AUTHTYPE_NETWORK_EAP:
5046 auth_alg = WLAN_AUTH_LEAP;
5048 case NL80211_AUTHTYPE_SAE:
5049 auth_alg = WLAN_AUTH_SAE;
5051 case NL80211_AUTHTYPE_FILS_SK:
5052 auth_alg = WLAN_AUTH_FILS_SK;
5054 case NL80211_AUTHTYPE_FILS_SK_PFS:
5055 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5057 case NL80211_AUTHTYPE_FILS_PK:
5058 auth_alg = WLAN_AUTH_FILS_PK;
5064 if (ifmgd->assoc_data)
5067 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5068 req->ie_len, GFP_KERNEL);
5072 auth_data->bss = req->bss;
5074 if (req->auth_data_len >= 4) {
5075 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5076 __le16 *pos = (__le16 *) req->auth_data;
5078 auth_data->sae_trans = le16_to_cpu(pos[0]);
5079 auth_data->sae_status = le16_to_cpu(pos[1]);
5081 memcpy(auth_data->data, req->auth_data + 4,
5082 req->auth_data_len - 4);
5083 auth_data->data_len += req->auth_data_len - 4;
5086 /* Check if continuing authentication or trying to authenticate with the
5087 * same BSS that we were in the process of authenticating with and avoid
5088 * removal and re-addition of the STA entry in
5089 * ieee80211_prep_connection().
5091 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5093 if (req->ie && req->ie_len) {
5094 memcpy(&auth_data->data[auth_data->data_len],
5095 req->ie, req->ie_len);
5096 auth_data->data_len += req->ie_len;
5099 if (req->key && req->key_len) {
5100 auth_data->key_len = req->key_len;
5101 auth_data->key_idx = req->key_idx;
5102 memcpy(auth_data->key, req->key, req->key_len);
5105 auth_data->algorithm = auth_alg;
5107 /* try to authenticate/probe */
5109 if (ifmgd->auth_data) {
5110 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5111 auth_data->peer_confirmed =
5112 ifmgd->auth_data->peer_confirmed;
5114 ieee80211_destroy_auth_data(sdata, cont_auth);
5117 /* prep auth_data so we don't go into idle on disassoc */
5118 ifmgd->auth_data = auth_data;
5120 /* If this is continuation of an ongoing SAE authentication exchange
5121 * (i.e., request to send SAE Confirm) and the peer has already
5122 * confirmed, mark authentication completed since we are about to send
5125 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5126 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5127 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5129 if (ifmgd->associated) {
5130 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5133 "disconnect from AP %pM for new auth to %pM\n",
5134 ifmgd->associated->bssid, req->bss->bssid);
5135 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5136 WLAN_REASON_UNSPECIFIED,
5139 ieee80211_report_disconnect(sdata, frame_buf,
5140 sizeof(frame_buf), true,
5141 WLAN_REASON_UNSPECIFIED);
5144 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5146 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5150 err = ieee80211_auth(sdata);
5152 sta_info_destroy_addr(sdata, req->bss->bssid);
5156 /* hold our own reference */
5157 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5161 eth_zero_addr(ifmgd->bssid);
5162 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5163 ifmgd->auth_data = NULL;
5164 mutex_lock(&sdata->local->mtx);
5165 ieee80211_vif_release_channel(sdata);
5166 mutex_unlock(&sdata->local->mtx);
5171 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5172 struct cfg80211_assoc_request *req)
5174 struct ieee80211_local *local = sdata->local;
5175 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5176 struct ieee80211_bss *bss = (void *)req->bss->priv;
5177 struct ieee80211_mgd_assoc_data *assoc_data;
5178 const struct cfg80211_bss_ies *beacon_ies;
5179 struct ieee80211_supported_band *sband;
5180 const u8 *ssidie, *ht_ie, *vht_ie;
5182 bool override = false;
5184 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5189 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5195 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5196 assoc_data->ssid_len = ssidie[1];
5199 if (ifmgd->associated) {
5200 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5203 "disconnect from AP %pM for new assoc to %pM\n",
5204 ifmgd->associated->bssid, req->bss->bssid);
5205 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5206 WLAN_REASON_UNSPECIFIED,
5209 ieee80211_report_disconnect(sdata, frame_buf,
5210 sizeof(frame_buf), true,
5211 WLAN_REASON_UNSPECIFIED);
5214 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5219 if (ifmgd->assoc_data) {
5224 if (ifmgd->auth_data) {
5227 /* keep sta info, bssid if matching */
5228 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5229 ieee80211_destroy_auth_data(sdata, match);
5232 /* prepare assoc data */
5234 ifmgd->beacon_crc_valid = false;
5236 assoc_data->wmm = bss->wmm_used &&
5237 (local->hw.queues >= IEEE80211_NUM_ACS);
5240 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5241 * We still associate in non-HT mode (11a/b/g) if any one of these
5242 * ciphers is configured as pairwise.
5243 * We can set this to true for non-11n hardware, that'll be checked
5244 * separately along with the peer capabilities.
5246 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5247 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5248 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5249 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5250 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5251 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5252 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5253 netdev_info(sdata->dev,
5254 "disabling HE/HT/VHT due to WEP/TKIP use\n");
5258 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5259 sband = local->hw.wiphy->bands[req->bss->channel->band];
5260 if (!sband->ht_cap.ht_supported ||
5261 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5262 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
5263 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5264 if (!bss->wmm_used &&
5265 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
5266 netdev_info(sdata->dev,
5267 "disabling HT as WMM/QoS is not supported by the AP\n");
5270 /* disable VHT if we don't support it or the AP doesn't use WMM */
5271 if (!sband->vht_cap.vht_supported ||
5272 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5273 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
5274 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5275 if (!bss->wmm_used &&
5276 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
5277 netdev_info(sdata->dev,
5278 "disabling VHT as WMM/QoS is not supported by the AP\n");
5281 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5282 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5283 sizeof(ifmgd->ht_capa_mask));
5285 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5286 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5287 sizeof(ifmgd->vht_capa_mask));
5289 if (req->ie && req->ie_len) {
5290 memcpy(assoc_data->ie, req->ie, req->ie_len);
5291 assoc_data->ie_len = req->ie_len;
5294 if (req->fils_kek) {
5295 /* should already be checked in cfg80211 - so warn */
5296 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5300 memcpy(assoc_data->fils_kek, req->fils_kek,
5302 assoc_data->fils_kek_len = req->fils_kek_len;
5305 if (req->fils_nonces)
5306 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5307 2 * FILS_NONCE_LEN);
5309 assoc_data->bss = req->bss;
5311 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5312 if (ifmgd->powersave)
5313 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5315 sdata->smps_mode = IEEE80211_SMPS_OFF;
5317 sdata->smps_mode = ifmgd->req_smps;
5319 assoc_data->capability = req->bss->capability;
5320 assoc_data->supp_rates = bss->supp_rates;
5321 assoc_data->supp_rates_len = bss->supp_rates_len;
5324 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5325 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5326 assoc_data->ap_ht_param =
5327 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5329 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5330 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5331 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5332 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5333 sizeof(struct ieee80211_vht_cap));
5335 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5338 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5339 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5340 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5341 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5343 if (bss->wmm_used && bss->uapsd_supported &&
5344 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5345 assoc_data->uapsd = true;
5346 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5348 assoc_data->uapsd = false;
5349 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5352 if (req->prev_bssid)
5353 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5356 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5357 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5359 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5360 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5363 if (req->flags & ASSOC_REQ_USE_RRM)
5364 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5366 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5368 if (req->crypto.control_port)
5369 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5371 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5373 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5374 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5375 sdata->control_port_over_nl80211 =
5376 req->crypto.control_port_over_nl80211;
5377 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5380 /* kick off associate process */
5382 ifmgd->assoc_data = assoc_data;
5383 ifmgd->dtim_period = 0;
5384 ifmgd->have_beacon = false;
5386 /* override HT/VHT configuration only if the AP and we support it */
5387 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5388 struct ieee80211_sta_ht_cap sta_ht_cap;
5390 if (req->flags & ASSOC_REQ_DISABLE_HT)
5393 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5394 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5396 /* check for 40 MHz disable override */
5397 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5398 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5399 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5402 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5403 req->flags & ASSOC_REQ_DISABLE_VHT)
5407 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5408 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5409 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5412 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5413 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5415 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5420 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5422 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5425 * Wait up to one beacon interval ...
5426 * should this be more if we miss one?
5428 sdata_info(sdata, "waiting for beacon from %pM\n",
5430 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5431 assoc_data->timeout_started = true;
5432 assoc_data->need_beacon = true;
5433 } else if (beacon_ies) {
5437 ieee80211_get_dtim(beacon_ies, &dtim_count,
5438 &ifmgd->dtim_period);
5440 ifmgd->have_beacon = true;
5441 assoc_data->timeout = jiffies;
5442 assoc_data->timeout_started = true;
5444 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5445 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5446 sdata->vif.bss_conf.sync_device_ts =
5447 bss->device_ts_beacon;
5448 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5451 ie = cfg80211_find_ext_ie(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5452 beacon_ies->data, beacon_ies->len);
5453 if (ie && ie[1] >= 3)
5454 sdata->vif.bss_conf.profile_periodicity = ie[4];
5456 ie = cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY,
5457 beacon_ies->data, beacon_ies->len);
5458 if (ie && ie[1] >= 11 &&
5459 (ie[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5460 sdata->vif.bss_conf.ema_ap = true;
5462 assoc_data->timeout = jiffies;
5463 assoc_data->timeout_started = true;
5467 run_again(sdata, assoc_data->timeout);
5469 if (bss->corrupt_data) {
5470 char *corrupt_type = "data";
5471 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5472 if (bss->corrupt_data &
5473 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5474 corrupt_type = "beacon and probe response";
5476 corrupt_type = "beacon";
5477 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5478 corrupt_type = "probe response";
5479 sdata_info(sdata, "associating with AP with corrupt %s\n",
5485 eth_zero_addr(ifmgd->bssid);
5486 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5487 ifmgd->assoc_data = NULL;
5493 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5494 struct cfg80211_deauth_request *req)
5496 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5497 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5498 bool tx = !req->local_state_change;
5500 if (ifmgd->auth_data &&
5501 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5503 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5504 req->bssid, req->reason_code,
5505 ieee80211_get_reason_code_string(req->reason_code));
5507 drv_mgd_prepare_tx(sdata->local, sdata, 0);
5508 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5509 IEEE80211_STYPE_DEAUTH,
5510 req->reason_code, tx,
5512 ieee80211_destroy_auth_data(sdata, false);
5513 ieee80211_report_disconnect(sdata, frame_buf,
5514 sizeof(frame_buf), true,
5520 if (ifmgd->assoc_data &&
5521 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5523 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5524 req->bssid, req->reason_code,
5525 ieee80211_get_reason_code_string(req->reason_code));
5527 drv_mgd_prepare_tx(sdata->local, sdata, 0);
5528 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5529 IEEE80211_STYPE_DEAUTH,
5530 req->reason_code, tx,
5532 ieee80211_destroy_assoc_data(sdata, false, true);
5533 ieee80211_report_disconnect(sdata, frame_buf,
5534 sizeof(frame_buf), true,
5539 if (ifmgd->associated &&
5540 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5542 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5543 req->bssid, req->reason_code,
5544 ieee80211_get_reason_code_string(req->reason_code));
5546 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5547 req->reason_code, tx, frame_buf);
5548 ieee80211_report_disconnect(sdata, frame_buf,
5549 sizeof(frame_buf), true,
5557 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5558 struct cfg80211_disassoc_request *req)
5560 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5562 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5565 * cfg80211 should catch this ... but it's racy since
5566 * we can receive a disassoc frame, process it, hand it
5567 * to cfg80211 while that's in a locked section already
5568 * trying to tell us that the user wants to disconnect.
5570 if (ifmgd->associated != req->bss)
5574 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5575 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5577 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5578 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5579 req->reason_code, !req->local_state_change,
5582 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5588 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5590 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5593 * Make sure some work items will not run after this,
5594 * they will not do anything but might not have been
5595 * cancelled when disconnecting.
5597 cancel_work_sync(&ifmgd->monitor_work);
5598 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5599 cancel_work_sync(&ifmgd->request_smps_work);
5600 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5601 cancel_work_sync(&ifmgd->chswitch_work);
5602 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5605 if (ifmgd->assoc_data) {
5606 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5607 ieee80211_destroy_assoc_data(sdata, false, false);
5608 cfg80211_assoc_timeout(sdata->dev, bss);
5610 if (ifmgd->auth_data)
5611 ieee80211_destroy_auth_data(sdata, false);
5612 spin_lock_bh(&ifmgd->teardown_lock);
5613 if (ifmgd->teardown_skb) {
5614 kfree_skb(ifmgd->teardown_skb);
5615 ifmgd->teardown_skb = NULL;
5616 ifmgd->orig_teardown_skb = NULL;
5618 kfree(ifmgd->assoc_req_ies);
5619 ifmgd->assoc_req_ies = NULL;
5620 ifmgd->assoc_req_ies_len = 0;
5621 spin_unlock_bh(&ifmgd->teardown_lock);
5622 del_timer_sync(&ifmgd->timer);
5623 sdata_unlock(sdata);
5626 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5627 enum nl80211_cqm_rssi_threshold_event rssi_event,
5631 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5633 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
5635 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
5637 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
5639 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5641 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5643 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5645 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5647 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);