2 * BSS client mode implementation
3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 * Copyright 2013-2014 Intel Mobile Communications GmbH
9 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/delay.h>
17 #include <linux/if_ether.h>
18 #include <linux/skbuff.h>
19 #include <linux/if_arp.h>
20 #include <linux/etherdevice.h>
21 #include <linux/moduleparam.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/crc32.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
26 #include <net/mac80211.h>
27 #include <asm/unaligned.h>
29 #include "ieee80211_i.h"
30 #include "driver-ops.h"
33 #include "fils_aead.h"
35 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
36 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
37 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
38 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
39 #define IEEE80211_AUTH_MAX_TRIES 3
40 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
44 #define IEEE80211_ASSOC_MAX_TRIES 3
46 static int max_nullfunc_tries = 2;
47 module_param(max_nullfunc_tries, int, 0644);
48 MODULE_PARM_DESC(max_nullfunc_tries,
49 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51 static int max_probe_tries = 5;
52 module_param(max_probe_tries, int, 0644);
53 MODULE_PARM_DESC(max_probe_tries,
54 "Maximum probe tries before disconnecting (reason 4).");
57 * Beacon loss timeout is calculated as N frames times the
58 * advertised beacon interval. This may need to be somewhat
59 * higher than what hardware might detect to account for
60 * delays in the host processing frames. But since we also
61 * probe on beacon miss before declaring the connection lost
62 * default to what we want.
64 static int beacon_loss_count = 7;
65 module_param(beacon_loss_count, int, 0644);
66 MODULE_PARM_DESC(beacon_loss_count,
67 "Number of beacon intervals before we decide beacon was lost.");
70 * Time the connection can be idle before we probe
71 * it to see if we can still talk to the AP.
73 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
75 * Time we wait for a probe response after sending
76 * a probe request because of beacon loss or for
77 * checking the connection still works.
79 static int probe_wait_ms = 500;
80 module_param(probe_wait_ms, int, 0644);
81 MODULE_PARM_DESC(probe_wait_ms,
82 "Maximum time(ms) to wait for probe response"
83 " before disconnecting (reason 4).");
86 * How many Beacon frames need to have been used in average signal strength
87 * before starting to indicate signal change events.
89 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
92 * We can have multiple work items (and connection probing)
93 * scheduling this timer, but we need to take care to only
94 * reschedule it when it should fire _earlier_ than it was
95 * asked for before, or if it's not pending right now. This
96 * function ensures that. Note that it then is required to
97 * run this function for all timeouts after the first one
98 * has happened -- the work that runs from this timer will
101 static void run_again(struct ieee80211_sub_if_data *sdata,
102 unsigned long timeout)
104 sdata_assert_lock(sdata);
106 if (!timer_pending(&sdata->u.mgd.timer) ||
107 time_before(timeout, sdata->u.mgd.timer.expires))
108 mod_timer(&sdata->u.mgd.timer, timeout);
111 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
113 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
116 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
119 mod_timer(&sdata->u.mgd.bcn_mon_timer,
120 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
123 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
125 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
127 if (unlikely(!ifmgd->associated))
130 if (ifmgd->probe_send_count)
131 ifmgd->probe_send_count = 0;
133 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
136 mod_timer(&ifmgd->conn_mon_timer,
137 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
140 static int ecw2cw(int ecw)
142 return (1 << ecw) - 1;
146 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
147 struct ieee80211_supported_band *sband,
148 struct ieee80211_channel *channel,
149 const struct ieee80211_ht_cap *ht_cap,
150 const struct ieee80211_ht_operation *ht_oper,
151 const struct ieee80211_vht_operation *vht_oper,
152 struct cfg80211_chan_def *chandef, bool tracking)
154 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
155 struct cfg80211_chan_def vht_chandef;
156 struct ieee80211_sta_ht_cap sta_ht_cap;
159 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
160 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
162 chandef->chan = channel;
163 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
164 chandef->center_freq1 = channel->center_freq;
165 chandef->center_freq2 = 0;
167 if (!ht_cap || !ht_oper || !sta_ht_cap.ht_supported) {
168 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
172 chandef->width = NL80211_CHAN_WIDTH_20;
174 if (!(ht_cap->cap_info &
175 cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40))) {
176 ret = IEEE80211_STA_DISABLE_40MHZ;
177 vht_chandef = *chandef;
181 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
183 /* check that channel matches the right operating channel */
184 if (!tracking && channel->center_freq != ht_cfreq) {
186 * It's possible that some APs are confused here;
187 * Netgear WNDR3700 sometimes reports 4 higher than
188 * the actual channel in association responses, but
189 * since we look at probe response/beacon data here
193 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
194 channel->center_freq, ht_cfreq,
195 ht_oper->primary_chan, channel->band);
196 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
200 /* check 40 MHz support, if we have it */
201 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
202 ieee80211_chandef_ht_oper(ht_oper, chandef);
204 /* 40 MHz (and 80 MHz) must be supported for VHT */
205 ret = IEEE80211_STA_DISABLE_VHT;
206 /* also mark 40 MHz disabled */
207 ret |= IEEE80211_STA_DISABLE_40MHZ;
211 if (!vht_oper || !sband->vht_cap.vht_supported) {
212 ret = IEEE80211_STA_DISABLE_VHT;
216 vht_chandef = *chandef;
217 if (!ieee80211_chandef_vht_oper(vht_oper, &vht_chandef)) {
218 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
220 "AP VHT information is invalid, disable VHT\n");
221 ret = IEEE80211_STA_DISABLE_VHT;
225 if (!cfg80211_chandef_valid(&vht_chandef)) {
226 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
228 "AP VHT information is invalid, disable VHT\n");
229 ret = IEEE80211_STA_DISABLE_VHT;
233 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
238 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
239 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
241 "AP VHT information doesn't match HT, disable VHT\n");
242 ret = IEEE80211_STA_DISABLE_VHT;
246 *chandef = vht_chandef;
252 * When tracking the current AP, don't do any further checks if the
253 * new chandef is identical to the one we're currently using for the
254 * connection. This keeps us from playing ping-pong with regulatory,
255 * without it the following can happen (for example):
256 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
257 * - AP advertises regdom US
258 * - CRDA loads regdom US with 80 MHz prohibited (old database)
259 * - the code below detects an unsupported channel, downgrades, and
260 * we disconnect from the AP in the caller
261 * - disconnect causes CRDA to reload world regdomain and the game
263 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
265 * It seems possible that there are still scenarios with CSA or real
266 * bandwidth changes where a this could happen, but those cases are
267 * less common and wouldn't completely prevent using the AP.
270 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
273 /* don't print the message below for VHT mismatch if VHT is disabled */
274 if (ret & IEEE80211_STA_DISABLE_VHT)
275 vht_chandef = *chandef;
278 * Ignore the DISABLED flag when we're already connected and only
279 * tracking the APs beacon for bandwidth changes - otherwise we
280 * might get disconnected here if we connect to an AP, update our
281 * regulatory information based on the AP's country IE and the
282 * information we have is wrong/outdated and disables the channel
283 * that we're actually using for the connection to the AP.
285 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
287 IEEE80211_CHAN_DISABLED)) {
288 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
289 ret = IEEE80211_STA_DISABLE_HT |
290 IEEE80211_STA_DISABLE_VHT;
294 ret |= ieee80211_chandef_downgrade(chandef);
297 if (chandef->width != vht_chandef.width && !tracking)
299 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
301 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
305 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
306 struct sta_info *sta,
307 const struct ieee80211_ht_cap *ht_cap,
308 const struct ieee80211_ht_operation *ht_oper,
309 const struct ieee80211_vht_operation *vht_oper,
310 const u8 *bssid, u32 *changed)
312 struct ieee80211_local *local = sdata->local;
313 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
314 struct ieee80211_supported_band *sband;
315 struct ieee80211_channel *chan;
316 struct cfg80211_chan_def chandef;
319 enum ieee80211_sta_rx_bandwidth new_sta_bw;
322 /* if HT was/is disabled, don't track any bandwidth changes */
323 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
326 /* don't check VHT if we associated as non-VHT station */
327 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
330 if (WARN_ON_ONCE(!sta))
334 * if bss configuration changed store the new one -
335 * this may be applicable even if channel is identical
337 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
338 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
339 *changed |= BSS_CHANGED_HT;
340 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
343 chan = sdata->vif.bss_conf.chandef.chan;
344 sband = local->hw.wiphy->bands[chan->band];
346 /* calculate new channel (type) based on HT/VHT operation IEs */
347 flags = ieee80211_determine_chantype(sdata, sband, chan,
348 ht_cap, ht_oper, vht_oper,
352 * Downgrade the new channel if we associated with restricted
353 * capabilities. For example, if we associated as a 20 MHz STA
354 * to a 40 MHz AP (due to regulatory, capabilities or config
355 * reasons) then switching to a 40 MHz channel now won't do us
356 * any good -- we couldn't use it with the AP.
358 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
359 chandef.width == NL80211_CHAN_WIDTH_80P80)
360 flags |= ieee80211_chandef_downgrade(&chandef);
361 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
362 chandef.width == NL80211_CHAN_WIDTH_160)
363 flags |= ieee80211_chandef_downgrade(&chandef);
364 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
365 chandef.width > NL80211_CHAN_WIDTH_20)
366 flags |= ieee80211_chandef_downgrade(&chandef);
368 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
372 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
373 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
374 chandef.center_freq1, chandef.center_freq2);
376 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
377 IEEE80211_STA_DISABLE_VHT |
378 IEEE80211_STA_DISABLE_40MHZ |
379 IEEE80211_STA_DISABLE_80P80MHZ |
380 IEEE80211_STA_DISABLE_160MHZ)) ||
381 !cfg80211_chandef_valid(&chandef)) {
383 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
388 switch (chandef.width) {
389 case NL80211_CHAN_WIDTH_20_NOHT:
390 case NL80211_CHAN_WIDTH_20:
391 new_sta_bw = IEEE80211_STA_RX_BW_20;
393 case NL80211_CHAN_WIDTH_40:
394 new_sta_bw = IEEE80211_STA_RX_BW_40;
396 case NL80211_CHAN_WIDTH_80:
397 new_sta_bw = IEEE80211_STA_RX_BW_80;
399 case NL80211_CHAN_WIDTH_80P80:
400 case NL80211_CHAN_WIDTH_160:
401 new_sta_bw = IEEE80211_STA_RX_BW_160;
407 if (new_sta_bw > sta->cur_max_bandwidth)
408 new_sta_bw = sta->cur_max_bandwidth;
410 if (new_sta_bw < sta->sta.bandwidth) {
411 sta->sta.bandwidth = new_sta_bw;
412 rate_control_rate_update(local, sband, sta,
413 IEEE80211_RC_BW_CHANGED);
416 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
419 "AP %pM changed bandwidth to incompatible one - disconnect\n",
424 if (new_sta_bw > sta->sta.bandwidth) {
425 sta->sta.bandwidth = new_sta_bw;
426 rate_control_rate_update(local, sband, sta,
427 IEEE80211_RC_BW_CHANGED);
433 /* frame sending functions */
435 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
436 struct sk_buff *skb, u8 ap_ht_param,
437 struct ieee80211_supported_band *sband,
438 struct ieee80211_channel *channel,
439 enum ieee80211_smps_mode smps)
442 u32 flags = channel->flags;
444 struct ieee80211_sta_ht_cap ht_cap;
446 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
448 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
449 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
451 /* determine capability flags */
454 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
455 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
456 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
457 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
458 cap &= ~IEEE80211_HT_CAP_SGI_40;
461 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
462 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
463 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
464 cap &= ~IEEE80211_HT_CAP_SGI_40;
470 * If 40 MHz was disabled associate as though we weren't
471 * capable of 40 MHz -- some broken APs will never fall
472 * back to trying to transmit in 20 MHz.
474 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
475 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
476 cap &= ~IEEE80211_HT_CAP_SGI_40;
479 /* set SM PS mode properly */
480 cap &= ~IEEE80211_HT_CAP_SM_PS;
482 case IEEE80211_SMPS_AUTOMATIC:
483 case IEEE80211_SMPS_NUM_MODES:
485 case IEEE80211_SMPS_OFF:
486 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
487 IEEE80211_HT_CAP_SM_PS_SHIFT;
489 case IEEE80211_SMPS_STATIC:
490 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
491 IEEE80211_HT_CAP_SM_PS_SHIFT;
493 case IEEE80211_SMPS_DYNAMIC:
494 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
495 IEEE80211_HT_CAP_SM_PS_SHIFT;
499 /* reserve and fill IE */
500 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
501 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
504 /* This function determines vht capability flags for the association
506 * Note - the function may set the owner of the MU-MIMO capability
508 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
510 struct ieee80211_supported_band *sband,
511 struct ieee80211_vht_cap *ap_vht_cap)
513 struct ieee80211_local *local = sdata->local;
516 struct ieee80211_sta_vht_cap vht_cap;
517 u32 mask, ap_bf_sts, our_bf_sts;
519 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
521 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
522 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
524 /* determine capability flags */
527 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
528 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
530 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
531 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
532 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
533 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
536 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
537 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
538 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
542 * Some APs apparently get confused if our capabilities are better
543 * than theirs, so restrict what we advertise in the assoc request.
545 if (!(ap_vht_cap->vht_cap_info &
546 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
547 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
548 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
549 else if (!(ap_vht_cap->vht_cap_info &
550 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
551 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
554 * If some other vif is using the MU-MIMO capablity we cannot associate
555 * using MU-MIMO - this will lead to contradictions in the group-id
557 * Ownership is defined since association request, in order to avoid
558 * simultaneous associations with MU-MIMO.
560 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
561 bool disable_mu_mimo = false;
562 struct ieee80211_sub_if_data *other;
564 list_for_each_entry_rcu(other, &local->interfaces, list) {
565 if (other->vif.mu_mimo_owner) {
566 disable_mu_mimo = true;
571 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
573 sdata->vif.mu_mimo_owner = true;
576 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
578 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
579 our_bf_sts = cap & mask;
581 if (ap_bf_sts < our_bf_sts) {
586 /* reserve and fill IE */
587 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
588 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
591 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
593 struct ieee80211_local *local = sdata->local;
594 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
595 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
597 struct ieee80211_mgmt *mgmt;
599 size_t offset = 0, noffset;
600 int i, count, rates_len, supp_rates_len, shift;
602 struct ieee80211_supported_band *sband;
603 struct ieee80211_chanctx_conf *chanctx_conf;
604 struct ieee80211_channel *chan;
607 sdata_assert_lock(sdata);
610 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
611 if (WARN_ON(!chanctx_conf)) {
615 chan = chanctx_conf->def.chan;
617 sband = local->hw.wiphy->bands[chan->band];
618 shift = ieee80211_vif_get_shift(&sdata->vif);
620 if (assoc_data->supp_rates_len) {
622 * Get all rates supported by the device and the AP as
623 * some APs don't like getting a superset of their rates
624 * in the association request (e.g. D-Link DAP 1353 in
627 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
628 assoc_data->supp_rates,
629 assoc_data->supp_rates_len,
633 * In case AP not provide any supported rates information
634 * before association, we send information element(s) with
635 * all rates that we support.
638 for (i = 0; i < sband->n_bitrates; i++) {
644 skb = alloc_skb(local->hw.extra_tx_headroom +
645 sizeof(*mgmt) + /* bit too much but doesn't matter */
646 2 + assoc_data->ssid_len + /* SSID */
647 4 + rates_len + /* (extended) rates */
648 4 + /* power capability */
649 2 + 2 * sband->n_channels + /* supported channels */
650 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
651 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
652 assoc_data->ie_len + /* extra IEs */
653 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
659 skb_reserve(skb, local->hw.extra_tx_headroom);
661 capab = WLAN_CAPABILITY_ESS;
663 if (sband->band == NL80211_BAND_2GHZ) {
664 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
665 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
668 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
669 capab |= WLAN_CAPABILITY_PRIVACY;
671 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
672 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
673 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
675 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
676 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
678 mgmt = skb_put_zero(skb, 24);
679 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
680 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
681 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
683 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
685 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
686 IEEE80211_STYPE_REASSOC_REQ);
687 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
688 mgmt->u.reassoc_req.listen_interval =
689 cpu_to_le16(local->hw.conf.listen_interval);
690 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
694 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
695 IEEE80211_STYPE_ASSOC_REQ);
696 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
697 mgmt->u.assoc_req.listen_interval =
698 cpu_to_le16(local->hw.conf.listen_interval);
702 pos = skb_put(skb, 2 + assoc_data->ssid_len);
703 *pos++ = WLAN_EID_SSID;
704 *pos++ = assoc_data->ssid_len;
705 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
707 /* add all rates which were marked to be used above */
708 supp_rates_len = rates_len;
709 if (supp_rates_len > 8)
712 pos = skb_put(skb, supp_rates_len + 2);
713 *pos++ = WLAN_EID_SUPP_RATES;
714 *pos++ = supp_rates_len;
717 for (i = 0; i < sband->n_bitrates; i++) {
718 if (BIT(i) & rates) {
719 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
727 if (rates_len > count) {
728 pos = skb_put(skb, rates_len - count + 2);
729 *pos++ = WLAN_EID_EXT_SUPP_RATES;
730 *pos++ = rates_len - count;
732 for (i++; i < sband->n_bitrates; i++) {
733 if (BIT(i) & rates) {
735 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
742 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
743 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
744 pos = skb_put(skb, 4);
745 *pos++ = WLAN_EID_PWR_CAPABILITY;
747 *pos++ = 0; /* min tx power */
749 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
752 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
753 /* TODO: get this in reg domain format */
754 pos = skb_put(skb, 2 * sband->n_channels + 2);
755 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
756 *pos++ = 2 * sband->n_channels;
757 for (i = 0; i < sband->n_channels; i++) {
758 *pos++ = ieee80211_frequency_to_channel(
759 sband->channels[i].center_freq);
760 *pos++ = 1; /* one channel in the subband*/
764 /* if present, add any custom IEs that go before HT */
765 if (assoc_data->ie_len) {
766 static const u8 before_ht[] = {
769 WLAN_EID_EXT_SUPP_RATES,
770 WLAN_EID_PWR_CAPABILITY,
771 WLAN_EID_SUPPORTED_CHANNELS,
774 WLAN_EID_RRM_ENABLED_CAPABILITIES,
775 WLAN_EID_MOBILITY_DOMAIN,
776 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
777 WLAN_EID_RIC_DATA, /* reassoc only */
778 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
780 static const u8 after_ric[] = {
781 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
782 WLAN_EID_HT_CAPABILITY,
783 WLAN_EID_BSS_COEX_2040,
784 WLAN_EID_EXT_CAPABILITY,
785 WLAN_EID_QOS_TRAFFIC_CAPA,
786 WLAN_EID_TIM_BCAST_REQ,
787 WLAN_EID_INTERWORKING,
788 /* 60GHz doesn't happen right now */
789 WLAN_EID_VHT_CAPABILITY,
790 WLAN_EID_OPMODE_NOTIF,
793 noffset = ieee80211_ie_split_ric(assoc_data->ie,
796 ARRAY_SIZE(before_ht),
798 ARRAY_SIZE(after_ric),
800 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
804 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
805 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
806 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
808 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
809 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
810 sband, chan, sdata->smps_mode);
812 /* if present, add any custom IEs that go before VHT */
813 if (assoc_data->ie_len) {
814 static const u8 before_vht[] = {
817 WLAN_EID_EXT_SUPP_RATES,
818 WLAN_EID_PWR_CAPABILITY,
819 WLAN_EID_SUPPORTED_CHANNELS,
822 WLAN_EID_RRM_ENABLED_CAPABILITIES,
823 WLAN_EID_MOBILITY_DOMAIN,
824 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
825 WLAN_EID_HT_CAPABILITY,
826 WLAN_EID_BSS_COEX_2040,
827 WLAN_EID_EXT_CAPABILITY,
828 WLAN_EID_QOS_TRAFFIC_CAPA,
829 WLAN_EID_TIM_BCAST_REQ,
830 WLAN_EID_INTERWORKING,
833 /* RIC already taken above, so no need to handle here anymore */
834 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
835 before_vht, ARRAY_SIZE(before_vht),
837 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
841 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
842 ieee80211_add_vht_ie(sdata, skb, sband,
843 &assoc_data->ap_vht_cap);
845 /* if present, add any custom non-vendor IEs that go after HT */
846 if (assoc_data->ie_len) {
847 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
850 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
854 if (assoc_data->wmm) {
855 if (assoc_data->uapsd) {
856 qos_info = ifmgd->uapsd_queues;
857 qos_info |= (ifmgd->uapsd_max_sp_len <<
858 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
863 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
866 /* add any remaining custom (i.e. vendor specific here) IEs */
867 if (assoc_data->ie_len) {
868 noffset = assoc_data->ie_len;
869 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
872 if (assoc_data->fils_kek_len &&
873 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
878 drv_mgd_prepare_tx(local, sdata);
880 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
881 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
882 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
883 IEEE80211_TX_INTFL_MLME_CONN_TX;
884 ieee80211_tx_skb(sdata, skb);
887 void ieee80211_send_pspoll(struct ieee80211_local *local,
888 struct ieee80211_sub_if_data *sdata)
890 struct ieee80211_pspoll *pspoll;
893 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
897 pspoll = (struct ieee80211_pspoll *) skb->data;
898 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
900 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
901 ieee80211_tx_skb(sdata, skb);
904 void ieee80211_send_nullfunc(struct ieee80211_local *local,
905 struct ieee80211_sub_if_data *sdata,
909 struct ieee80211_hdr_3addr *nullfunc;
910 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
912 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, true);
916 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
918 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
920 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
921 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
923 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
924 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
926 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
927 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
929 ieee80211_tx_skb(sdata, skb);
932 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
933 struct ieee80211_sub_if_data *sdata)
936 struct ieee80211_hdr *nullfunc;
939 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
942 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
946 skb_reserve(skb, local->hw.extra_tx_headroom);
948 nullfunc = skb_put_zero(skb, 30);
949 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
950 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
951 nullfunc->frame_control = fc;
952 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
953 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
954 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
955 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
957 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
958 ieee80211_tx_skb(sdata, skb);
961 /* spectrum management related things */
962 static void ieee80211_chswitch_work(struct work_struct *work)
964 struct ieee80211_sub_if_data *sdata =
965 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
966 struct ieee80211_local *local = sdata->local;
967 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
970 if (!ieee80211_sdata_running(sdata))
974 mutex_lock(&local->mtx);
975 mutex_lock(&local->chanctx_mtx);
977 if (!ifmgd->associated)
980 if (!sdata->vif.csa_active)
984 * using reservation isn't immediate as it may be deferred until later
985 * with multi-vif. once reservation is complete it will re-schedule the
986 * work with no reserved_chanctx so verify chandef to check if it
987 * completed successfully
990 if (sdata->reserved_chanctx) {
991 struct ieee80211_supported_band *sband = NULL;
992 struct sta_info *mgd_sta = NULL;
993 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
996 * with multi-vif csa driver may call ieee80211_csa_finish()
997 * many times while waiting for other interfaces to use their
1000 if (sdata->reserved_ready)
1003 if (sdata->vif.bss_conf.chandef.width !=
1004 sdata->csa_chandef.width) {
1006 * For managed interface, we need to also update the AP
1007 * station bandwidth and align the rate scale algorithm
1008 * on the bandwidth change. Here we only consider the
1009 * bandwidth of the new channel definition (as channel
1010 * switch flow does not have the full HT/VHT/HE
1011 * information), assuming that if additional changes are
1012 * required they would be done as part of the processing
1013 * of the next beacon from the AP.
1015 switch (sdata->csa_chandef.width) {
1016 case NL80211_CHAN_WIDTH_20_NOHT:
1017 case NL80211_CHAN_WIDTH_20:
1019 bw = IEEE80211_STA_RX_BW_20;
1021 case NL80211_CHAN_WIDTH_40:
1022 bw = IEEE80211_STA_RX_BW_40;
1024 case NL80211_CHAN_WIDTH_80:
1025 bw = IEEE80211_STA_RX_BW_80;
1027 case NL80211_CHAN_WIDTH_80P80:
1028 case NL80211_CHAN_WIDTH_160:
1029 bw = IEEE80211_STA_RX_BW_160;
1033 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1035 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1038 if (sdata->vif.bss_conf.chandef.width >
1039 sdata->csa_chandef.width) {
1040 mgd_sta->sta.bandwidth = bw;
1041 rate_control_rate_update(local, sband, mgd_sta,
1042 IEEE80211_RC_BW_CHANGED);
1045 ret = ieee80211_vif_use_reserved_context(sdata);
1048 "failed to use reserved channel context, disconnecting (err=%d)\n",
1050 ieee80211_queue_work(&sdata->local->hw,
1051 &ifmgd->csa_connection_drop_work);
1055 if (sdata->vif.bss_conf.chandef.width <
1056 sdata->csa_chandef.width) {
1057 mgd_sta->sta.bandwidth = bw;
1058 rate_control_rate_update(local, sband, mgd_sta,
1059 IEEE80211_RC_BW_CHANGED);
1065 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1066 &sdata->csa_chandef)) {
1068 "failed to finalize channel switch, disconnecting\n");
1069 ieee80211_queue_work(&sdata->local->hw,
1070 &ifmgd->csa_connection_drop_work);
1074 ifmgd->csa_waiting_bcn = true;
1076 ieee80211_sta_reset_beacon_monitor(sdata);
1077 ieee80211_sta_reset_conn_monitor(sdata);
1080 mutex_unlock(&local->chanctx_mtx);
1081 mutex_unlock(&local->mtx);
1082 sdata_unlock(sdata);
1085 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1087 struct ieee80211_local *local = sdata->local;
1088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1091 sdata_assert_lock(sdata);
1093 WARN_ON(!sdata->vif.csa_active);
1095 if (sdata->csa_block_tx) {
1096 ieee80211_wake_vif_queues(local, sdata,
1097 IEEE80211_QUEUE_STOP_REASON_CSA);
1098 sdata->csa_block_tx = false;
1101 sdata->vif.csa_active = false;
1102 ifmgd->csa_waiting_bcn = false;
1104 * If the CSA IE is still present on the beacon after the switch,
1105 * we need to consider it as a new CSA (possibly to self).
1107 ifmgd->beacon_crc_valid = false;
1109 ret = drv_post_channel_switch(sdata);
1112 "driver post channel switch failed, disconnecting\n");
1113 ieee80211_queue_work(&local->hw,
1114 &ifmgd->csa_connection_drop_work);
1118 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1121 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1123 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1124 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1126 trace_api_chswitch_done(sdata, success);
1129 "driver channel switch failed, disconnecting\n");
1130 ieee80211_queue_work(&sdata->local->hw,
1131 &ifmgd->csa_connection_drop_work);
1133 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1136 EXPORT_SYMBOL(ieee80211_chswitch_done);
1138 static void ieee80211_chswitch_timer(unsigned long data)
1140 struct ieee80211_sub_if_data *sdata =
1141 (struct ieee80211_sub_if_data *) data;
1143 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1147 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1148 u64 timestamp, u32 device_timestamp,
1149 struct ieee802_11_elems *elems,
1152 struct ieee80211_local *local = sdata->local;
1153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1154 struct cfg80211_bss *cbss = ifmgd->associated;
1155 struct ieee80211_chanctx_conf *conf;
1156 struct ieee80211_chanctx *chanctx;
1157 enum nl80211_band current_band;
1158 struct ieee80211_csa_ie csa_ie;
1159 struct ieee80211_channel_switch ch_switch;
1162 sdata_assert_lock(sdata);
1167 if (local->scanning)
1170 /* disregard subsequent announcements if we are already processing */
1171 if (sdata->vif.csa_active)
1174 current_band = cbss->channel->band;
1175 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1177 ifmgd->associated->bssid, &csa_ie);
1179 ieee80211_queue_work(&local->hw,
1180 &ifmgd->csa_connection_drop_work);
1184 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1185 IEEE80211_CHAN_DISABLED)) {
1187 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1188 ifmgd->associated->bssid,
1189 csa_ie.chandef.chan->center_freq,
1190 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1191 csa_ie.chandef.center_freq2);
1192 ieee80211_queue_work(&local->hw,
1193 &ifmgd->csa_connection_drop_work);
1197 if (cfg80211_chandef_identical(&csa_ie.chandef,
1198 &sdata->vif.bss_conf.chandef)) {
1199 if (ifmgd->csa_ignored_same_chan)
1202 "AP %pM tries to chanswitch to same channel, ignore\n",
1203 ifmgd->associated->bssid);
1204 ifmgd->csa_ignored_same_chan = true;
1209 * Drop all TDLS peers - either we disconnect or move to a different
1210 * channel from this point on. There's no telling what our peer will do.
1211 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1212 * have an incompatible wider chandef.
1214 ieee80211_teardown_tdls_peers(sdata);
1216 mutex_lock(&local->mtx);
1217 mutex_lock(&local->chanctx_mtx);
1218 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1219 lockdep_is_held(&local->chanctx_mtx));
1222 "no channel context assigned to vif?, disconnecting\n");
1223 goto drop_connection;
1226 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1228 if (local->use_chanctx &&
1229 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1231 "driver doesn't support chan-switch with channel contexts\n");
1232 goto drop_connection;
1235 ch_switch.timestamp = timestamp;
1236 ch_switch.device_timestamp = device_timestamp;
1237 ch_switch.block_tx = csa_ie.mode;
1238 ch_switch.chandef = csa_ie.chandef;
1239 ch_switch.count = csa_ie.count;
1241 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1243 "preparing for channel switch failed, disconnecting\n");
1244 goto drop_connection;
1247 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1248 chanctx->mode, false);
1251 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1253 goto drop_connection;
1255 mutex_unlock(&local->chanctx_mtx);
1257 sdata->vif.csa_active = true;
1258 sdata->csa_chandef = csa_ie.chandef;
1259 sdata->csa_block_tx = csa_ie.mode;
1260 ifmgd->csa_ignored_same_chan = false;
1262 if (sdata->csa_block_tx)
1263 ieee80211_stop_vif_queues(local, sdata,
1264 IEEE80211_QUEUE_STOP_REASON_CSA);
1265 mutex_unlock(&local->mtx);
1267 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1270 if (local->ops->channel_switch) {
1271 /* use driver's channel switch callback */
1272 drv_channel_switch(local, sdata, &ch_switch);
1276 /* channel switch handled in software */
1277 if (csa_ie.count <= 1)
1278 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1280 mod_timer(&ifmgd->chswitch_timer,
1281 TU_TO_EXP_TIME((csa_ie.count - 1) *
1282 cbss->beacon_interval));
1286 * This is just so that the disconnect flow will know that
1287 * we were trying to switch channel and failed. In case the
1288 * mode is 1 (we are not allowed to Tx), we will know not to
1289 * send a deauthentication frame. Those two fields will be
1290 * reset when the disconnection worker runs.
1292 sdata->vif.csa_active = true;
1293 sdata->csa_block_tx = csa_ie.mode;
1295 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1296 mutex_unlock(&local->chanctx_mtx);
1297 mutex_unlock(&local->mtx);
1301 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1302 struct ieee80211_channel *channel,
1303 const u8 *country_ie, u8 country_ie_len,
1304 const u8 *pwr_constr_elem,
1305 int *chan_pwr, int *pwr_reduction)
1307 struct ieee80211_country_ie_triplet *triplet;
1308 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1309 int i, chan_increment;
1310 bool have_chan_pwr = false;
1313 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1316 triplet = (void *)(country_ie + 3);
1317 country_ie_len -= 3;
1319 switch (channel->band) {
1323 case NL80211_BAND_2GHZ:
1324 case NL80211_BAND_60GHZ:
1327 case NL80211_BAND_5GHZ:
1333 while (country_ie_len >= 3) {
1334 u8 first_channel = triplet->chans.first_channel;
1336 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1339 for (i = 0; i < triplet->chans.num_channels; i++) {
1340 if (first_channel + i * chan_increment == chan) {
1341 have_chan_pwr = true;
1342 *chan_pwr = triplet->chans.max_power;
1351 country_ie_len -= 3;
1354 if (have_chan_pwr && pwr_constr_elem)
1355 *pwr_reduction = *pwr_constr_elem;
1359 return have_chan_pwr;
1362 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1363 struct ieee80211_channel *channel,
1364 const u8 *cisco_dtpc_ie,
1367 /* From practical testing, the first data byte of the DTPC element
1368 * seems to contain the requested dBm level, and the CLI on Cisco
1369 * APs clearly state the range is -127 to 127 dBm, which indicates
1370 * a signed byte, although it seemingly never actually goes negative.
1371 * The other byte seems to always be zero.
1373 *pwr_level = (__s8)cisco_dtpc_ie[4];
1376 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1377 struct ieee80211_channel *channel,
1378 struct ieee80211_mgmt *mgmt,
1379 const u8 *country_ie, u8 country_ie_len,
1380 const u8 *pwr_constr_ie,
1381 const u8 *cisco_dtpc_ie)
1383 bool has_80211h_pwr = false, has_cisco_pwr = false;
1384 int chan_pwr = 0, pwr_reduction_80211h = 0;
1385 int pwr_level_cisco, pwr_level_80211h;
1387 __le16 capab = mgmt->u.probe_resp.capab_info;
1390 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1391 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1392 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1393 sdata, channel, country_ie, country_ie_len,
1394 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1396 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1399 if (cisco_dtpc_ie) {
1400 ieee80211_find_cisco_dtpc(
1401 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1402 has_cisco_pwr = true;
1405 if (!has_80211h_pwr && !has_cisco_pwr)
1408 /* If we have both 802.11h and Cisco DTPC, apply both limits
1409 * by picking the smallest of the two power levels advertised.
1411 if (has_80211h_pwr &&
1412 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1413 new_ap_level = pwr_level_80211h;
1415 if (sdata->ap_power_level == new_ap_level)
1419 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1420 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1421 sdata->u.mgd.bssid);
1422 } else { /* has_cisco_pwr is always true here. */
1423 new_ap_level = pwr_level_cisco;
1425 if (sdata->ap_power_level == new_ap_level)
1429 "Limiting TX power to %d dBm as advertised by %pM\n",
1430 pwr_level_cisco, sdata->u.mgd.bssid);
1433 sdata->ap_power_level = new_ap_level;
1434 if (__ieee80211_recalc_txpower(sdata))
1435 return BSS_CHANGED_TXPOWER;
1440 static void ieee80211_enable_ps(struct ieee80211_local *local,
1441 struct ieee80211_sub_if_data *sdata)
1443 struct ieee80211_conf *conf = &local->hw.conf;
1446 * If we are scanning right now then the parameters will
1447 * take effect when scan finishes.
1449 if (local->scanning)
1452 if (conf->dynamic_ps_timeout > 0 &&
1453 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1454 mod_timer(&local->dynamic_ps_timer, jiffies +
1455 msecs_to_jiffies(conf->dynamic_ps_timeout));
1457 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1458 ieee80211_send_nullfunc(local, sdata, true);
1460 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1461 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1464 conf->flags |= IEEE80211_CONF_PS;
1465 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1469 static void ieee80211_change_ps(struct ieee80211_local *local)
1471 struct ieee80211_conf *conf = &local->hw.conf;
1473 if (local->ps_sdata) {
1474 ieee80211_enable_ps(local, local->ps_sdata);
1475 } else if (conf->flags & IEEE80211_CONF_PS) {
1476 conf->flags &= ~IEEE80211_CONF_PS;
1477 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1478 del_timer_sync(&local->dynamic_ps_timer);
1479 cancel_work_sync(&local->dynamic_ps_enable_work);
1483 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1485 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1486 struct sta_info *sta = NULL;
1487 bool authorized = false;
1489 if (!mgd->powersave)
1495 if (!mgd->associated)
1498 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1501 if (!mgd->have_beacon)
1505 sta = sta_info_get(sdata, mgd->bssid);
1507 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1513 /* need to hold RTNL or interface lock */
1514 void ieee80211_recalc_ps(struct ieee80211_local *local)
1516 struct ieee80211_sub_if_data *sdata, *found = NULL;
1520 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1521 local->ps_sdata = NULL;
1525 list_for_each_entry(sdata, &local->interfaces, list) {
1526 if (!ieee80211_sdata_running(sdata))
1528 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1529 /* If an AP vif is found, then disable PS
1530 * by setting the count to zero thereby setting
1536 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1542 if (count == 1 && ieee80211_powersave_allowed(found)) {
1543 u8 dtimper = found->u.mgd.dtim_period;
1545 timeout = local->dynamic_ps_forced_timeout;
1548 local->hw.conf.dynamic_ps_timeout = timeout;
1550 /* If the TIM IE is invalid, pretend the value is 1 */
1554 local->hw.conf.ps_dtim_period = dtimper;
1555 local->ps_sdata = found;
1557 local->ps_sdata = NULL;
1560 ieee80211_change_ps(local);
1563 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1565 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1567 if (sdata->vif.bss_conf.ps != ps_allowed) {
1568 sdata->vif.bss_conf.ps = ps_allowed;
1569 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1573 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1575 struct ieee80211_local *local =
1576 container_of(work, struct ieee80211_local,
1577 dynamic_ps_disable_work);
1579 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1580 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1581 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1584 ieee80211_wake_queues_by_reason(&local->hw,
1585 IEEE80211_MAX_QUEUE_MAP,
1586 IEEE80211_QUEUE_STOP_REASON_PS,
1590 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1592 struct ieee80211_local *local =
1593 container_of(work, struct ieee80211_local,
1594 dynamic_ps_enable_work);
1595 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1596 struct ieee80211_if_managed *ifmgd;
1597 unsigned long flags;
1600 /* can only happen when PS was just disabled anyway */
1604 ifmgd = &sdata->u.mgd;
1606 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1609 if (local->hw.conf.dynamic_ps_timeout > 0) {
1610 /* don't enter PS if TX frames are pending */
1611 if (drv_tx_frames_pending(local)) {
1612 mod_timer(&local->dynamic_ps_timer, jiffies +
1614 local->hw.conf.dynamic_ps_timeout));
1619 * transmission can be stopped by others which leads to
1620 * dynamic_ps_timer expiry. Postpone the ps timer if it
1621 * is not the actual idle state.
1623 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1624 for (q = 0; q < local->hw.queues; q++) {
1625 if (local->queue_stop_reasons[q]) {
1626 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1628 mod_timer(&local->dynamic_ps_timer, jiffies +
1630 local->hw.conf.dynamic_ps_timeout));
1634 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1637 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1638 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1639 if (drv_tx_frames_pending(local)) {
1640 mod_timer(&local->dynamic_ps_timer, jiffies +
1642 local->hw.conf.dynamic_ps_timeout));
1644 ieee80211_send_nullfunc(local, sdata, true);
1645 /* Flush to get the tx status of nullfunc frame */
1646 ieee80211_flush_queues(local, sdata, false);
1650 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1651 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1652 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1653 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1654 local->hw.conf.flags |= IEEE80211_CONF_PS;
1655 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1659 void ieee80211_dynamic_ps_timer(unsigned long data)
1661 struct ieee80211_local *local = (void *) data;
1663 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1666 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1668 struct delayed_work *delayed_work = to_delayed_work(work);
1669 struct ieee80211_sub_if_data *sdata =
1670 container_of(delayed_work, struct ieee80211_sub_if_data,
1671 dfs_cac_timer_work);
1672 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1674 mutex_lock(&sdata->local->mtx);
1675 if (sdata->wdev.cac_started) {
1676 ieee80211_vif_release_channel(sdata);
1677 cfg80211_cac_event(sdata->dev, &chandef,
1678 NL80211_RADAR_CAC_FINISHED,
1681 mutex_unlock(&sdata->local->mtx);
1685 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1687 struct ieee80211_local *local = sdata->local;
1688 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1692 if (local->hw.queues < IEEE80211_NUM_ACS)
1695 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1696 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1698 unsigned long now = jiffies;
1700 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1701 tx_tspec->admitted_time &&
1702 time_after(now, tx_tspec->time_slice_start + HZ)) {
1703 tx_tspec->consumed_tx_time = 0;
1704 tx_tspec->time_slice_start = now;
1706 if (tx_tspec->downgraded)
1708 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1711 switch (tx_tspec->action) {
1712 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1713 /* take the original parameters */
1714 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1716 "failed to set TX queue parameters for queue %d\n",
1718 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1719 tx_tspec->downgraded = false;
1722 case TX_TSPEC_ACTION_DOWNGRADE:
1723 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1724 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1728 /* downgrade next lower non-ACM AC */
1729 for (non_acm_ac = ac + 1;
1730 non_acm_ac < IEEE80211_NUM_ACS;
1732 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1734 /* Usually the loop will result in using BK even if it
1735 * requires admission control, but such a configuration
1736 * makes no sense and we have to transmit somehow - the
1737 * AC selection does the same thing.
1738 * If we started out trying to downgrade from BK, then
1739 * the extra condition here might be needed.
1741 if (non_acm_ac >= IEEE80211_NUM_ACS)
1742 non_acm_ac = IEEE80211_AC_BK;
1743 if (drv_conf_tx(local, sdata, ac,
1744 &sdata->tx_conf[non_acm_ac]))
1746 "failed to set TX queue parameters for queue %d\n",
1748 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1750 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1751 tx_tspec->time_slice_start + HZ - now + 1);
1753 case TX_TSPEC_ACTION_NONE:
1762 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1764 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1765 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1768 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1770 struct ieee80211_sub_if_data *sdata;
1772 sdata = container_of(work, struct ieee80211_sub_if_data,
1773 u.mgd.tx_tspec_wk.work);
1774 ieee80211_sta_handle_tspec_ac_params(sdata);
1778 static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
1779 struct ieee80211_sub_if_data *sdata,
1780 const u8 *wmm_param, size_t wmm_param_len)
1782 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1783 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1787 u8 uapsd_queues = 0;
1789 if (!local->ops->conf_tx)
1792 if (local->hw.queues < IEEE80211_NUM_ACS)
1798 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1801 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1802 uapsd_queues = ifmgd->uapsd_queues;
1804 count = wmm_param[6] & 0x0f;
1805 if (count == ifmgd->wmm_last_param_set)
1807 ifmgd->wmm_last_param_set = count;
1809 pos = wmm_param + 8;
1810 left = wmm_param_len - 8;
1812 memset(¶ms, 0, sizeof(params));
1815 for (; left >= 4; left -= 4, pos += 4) {
1816 int aci = (pos[0] >> 5) & 0x03;
1817 int acm = (pos[0] >> 4) & 0x01;
1822 ac = IEEE80211_AC_BK;
1824 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
1825 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1829 ac = IEEE80211_AC_VI;
1831 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
1832 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1836 ac = IEEE80211_AC_VO;
1838 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
1839 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1844 ac = IEEE80211_AC_BE;
1846 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
1847 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1852 params[ac].aifs = pos[0] & 0x0f;
1854 if (params[ac].aifs < 2) {
1856 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
1857 params[ac].aifs, aci);
1858 params[ac].aifs = 2;
1860 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1861 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
1862 params[ac].txop = get_unaligned_le16(pos + 2);
1863 params[ac].acm = acm;
1864 params[ac].uapsd = uapsd;
1866 if (params[ac].cw_min == 0 ||
1867 params[ac].cw_min > params[ac].cw_max) {
1869 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1870 params[ac].cw_min, params[ac].cw_max, aci);
1875 /* WMM specification requires all 4 ACIs. */
1876 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1877 if (params[ac].cw_min == 0) {
1879 "AP has invalid WMM params (missing AC %d), using defaults\n",
1885 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1887 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1889 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
1890 params[ac].txop, params[ac].uapsd,
1891 ifmgd->tx_tspec[ac].downgraded);
1892 sdata->tx_conf[ac] = params[ac];
1893 if (!ifmgd->tx_tspec[ac].downgraded &&
1894 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
1896 "failed to set TX queue parameters for AC %d\n",
1900 /* enable WMM or activate new settings */
1901 sdata->vif.bss_conf.qos = true;
1905 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1907 lockdep_assert_held(&sdata->local->mtx);
1909 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
1910 ieee80211_run_deferred_scan(sdata->local);
1913 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1915 mutex_lock(&sdata->local->mtx);
1916 __ieee80211_stop_poll(sdata);
1917 mutex_unlock(&sdata->local->mtx);
1920 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1921 u16 capab, bool erp_valid, u8 erp)
1923 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1924 struct ieee80211_supported_band *sband;
1926 bool use_protection;
1927 bool use_short_preamble;
1928 bool use_short_slot;
1930 sband = ieee80211_get_sband(sdata);
1935 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1936 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1938 use_protection = false;
1939 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1942 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
1943 if (sband->band == NL80211_BAND_5GHZ)
1944 use_short_slot = true;
1946 if (use_protection != bss_conf->use_cts_prot) {
1947 bss_conf->use_cts_prot = use_protection;
1948 changed |= BSS_CHANGED_ERP_CTS_PROT;
1951 if (use_short_preamble != bss_conf->use_short_preamble) {
1952 bss_conf->use_short_preamble = use_short_preamble;
1953 changed |= BSS_CHANGED_ERP_PREAMBLE;
1956 if (use_short_slot != bss_conf->use_short_slot) {
1957 bss_conf->use_short_slot = use_short_slot;
1958 changed |= BSS_CHANGED_ERP_SLOT;
1964 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1965 struct cfg80211_bss *cbss,
1966 u32 bss_info_changed)
1968 struct ieee80211_bss *bss = (void *)cbss->priv;
1969 struct ieee80211_local *local = sdata->local;
1970 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1972 bss_info_changed |= BSS_CHANGED_ASSOC;
1973 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
1974 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
1976 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1977 beacon_loss_count * bss_conf->beacon_int));
1979 sdata->u.mgd.associated = cbss;
1980 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
1982 ieee80211_check_rate_mask(sdata);
1984 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1986 if (sdata->vif.p2p ||
1987 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
1988 const struct cfg80211_bss_ies *ies;
1991 ies = rcu_dereference(cbss->ies);
1995 ret = cfg80211_get_p2p_attr(
1996 ies->data, ies->len,
1997 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1998 (u8 *) &bss_conf->p2p_noa_attr,
1999 sizeof(bss_conf->p2p_noa_attr));
2001 sdata->u.mgd.p2p_noa_index =
2002 bss_conf->p2p_noa_attr.index;
2003 bss_info_changed |= BSS_CHANGED_P2P_PS;
2009 /* just to be sure */
2010 ieee80211_stop_poll(sdata);
2012 ieee80211_led_assoc(local, 1);
2014 if (sdata->u.mgd.have_beacon) {
2016 * If the AP is buggy we may get here with no DTIM period
2017 * known, so assume it's 1 which is the only safe assumption
2018 * in that case, although if the TIM IE is broken powersave
2019 * probably just won't work at all.
2021 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2022 bss_conf->beacon_rate = bss->beacon_rate;
2023 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2025 bss_conf->beacon_rate = NULL;
2026 bss_conf->dtim_period = 0;
2029 bss_conf->assoc = 1;
2031 /* Tell the driver to monitor connection quality (if supported) */
2032 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2033 bss_conf->cqm_rssi_thold)
2034 bss_info_changed |= BSS_CHANGED_CQM;
2036 /* Enable ARP filtering */
2037 if (bss_conf->arp_addr_cnt)
2038 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2040 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2042 mutex_lock(&local->iflist_mtx);
2043 ieee80211_recalc_ps(local);
2044 mutex_unlock(&local->iflist_mtx);
2046 ieee80211_recalc_smps(sdata);
2047 ieee80211_recalc_ps_vif(sdata);
2049 netif_carrier_on(sdata->dev);
2052 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2053 u16 stype, u16 reason, bool tx,
2056 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2057 struct ieee80211_local *local = sdata->local;
2060 sdata_assert_lock(sdata);
2062 if (WARN_ON_ONCE(tx && !frame_buf))
2065 if (WARN_ON(!ifmgd->associated))
2068 ieee80211_stop_poll(sdata);
2070 ifmgd->associated = NULL;
2071 netif_carrier_off(sdata->dev);
2074 * if we want to get out of ps before disassoc (why?) we have
2075 * to do it before sending disassoc, as otherwise the null-packet
2078 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2079 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2080 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2082 local->ps_sdata = NULL;
2084 /* disable per-vif ps */
2085 ieee80211_recalc_ps_vif(sdata);
2087 /* make sure ongoing transmission finishes */
2091 * drop any frame before deauth/disassoc, this can be data or
2092 * management frame. Since we are disconnecting, we should not
2093 * insist sending these frames which can take time and delay
2094 * the disconnection and possible the roaming.
2097 ieee80211_flush_queues(local, sdata, true);
2099 /* deauthenticate/disassociate now */
2100 if (tx || frame_buf)
2101 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
2102 reason, tx, frame_buf);
2104 /* flush out frame - make sure the deauth was actually sent */
2106 ieee80211_flush_queues(local, sdata, false);
2108 /* clear bssid only after building the needed mgmt frames */
2109 eth_zero_addr(ifmgd->bssid);
2111 /* remove AP and TDLS peers */
2112 sta_info_flush(sdata);
2114 /* finally reset all BSS / config parameters */
2115 changed |= ieee80211_reset_erp_info(sdata);
2117 ieee80211_led_assoc(local, 0);
2118 changed |= BSS_CHANGED_ASSOC;
2119 sdata->vif.bss_conf.assoc = false;
2121 ifmgd->p2p_noa_index = -1;
2122 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2123 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2125 /* on the next assoc, re-program HT/VHT parameters */
2126 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2127 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2128 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2129 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2131 /* reset MU-MIMO ownership and group data */
2132 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2133 sizeof(sdata->vif.bss_conf.mu_group.membership));
2134 memset(sdata->vif.bss_conf.mu_group.position, 0,
2135 sizeof(sdata->vif.bss_conf.mu_group.position));
2136 changed |= BSS_CHANGED_MU_GROUPS;
2137 sdata->vif.mu_mimo_owner = false;
2139 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2141 del_timer_sync(&local->dynamic_ps_timer);
2142 cancel_work_sync(&local->dynamic_ps_enable_work);
2144 /* Disable ARP filtering */
2145 if (sdata->vif.bss_conf.arp_addr_cnt)
2146 changed |= BSS_CHANGED_ARP_FILTER;
2148 sdata->vif.bss_conf.qos = false;
2149 changed |= BSS_CHANGED_QOS;
2151 /* The BSSID (not really interesting) and HT changed */
2152 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2153 ieee80211_bss_info_change_notify(sdata, changed);
2155 /* disassociated - set to defaults now */
2156 ieee80211_set_wmm_default(sdata, false, false);
2158 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2159 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2160 del_timer_sync(&sdata->u.mgd.timer);
2161 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2163 sdata->vif.bss_conf.dtim_period = 0;
2164 sdata->vif.bss_conf.beacon_rate = NULL;
2166 ifmgd->have_beacon = false;
2169 mutex_lock(&local->mtx);
2170 ieee80211_vif_release_channel(sdata);
2172 sdata->vif.csa_active = false;
2173 ifmgd->csa_waiting_bcn = false;
2174 ifmgd->csa_ignored_same_chan = false;
2175 if (sdata->csa_block_tx) {
2176 ieee80211_wake_vif_queues(local, sdata,
2177 IEEE80211_QUEUE_STOP_REASON_CSA);
2178 sdata->csa_block_tx = false;
2180 mutex_unlock(&local->mtx);
2182 /* existing TX TSPEC sessions no longer exist */
2183 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2184 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2186 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2189 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2190 struct ieee80211_hdr *hdr)
2193 * We can postpone the mgd.timer whenever receiving unicast frames
2194 * from AP because we know that the connection is working both ways
2195 * at that time. But multicast frames (and hence also beacons) must
2196 * be ignored here, because we need to trigger the timer during
2197 * data idle periods for sending the periodic probe request to the
2198 * AP we're connected to.
2200 if (is_multicast_ether_addr(hdr->addr1))
2203 ieee80211_sta_reset_conn_monitor(sdata);
2206 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2208 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2209 struct ieee80211_local *local = sdata->local;
2211 mutex_lock(&local->mtx);
2212 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2215 __ieee80211_stop_poll(sdata);
2217 mutex_lock(&local->iflist_mtx);
2218 ieee80211_recalc_ps(local);
2219 mutex_unlock(&local->iflist_mtx);
2221 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2225 * We've received a probe response, but are not sure whether
2226 * we have or will be receiving any beacons or data, so let's
2227 * schedule the timers again, just in case.
2229 ieee80211_sta_reset_beacon_monitor(sdata);
2231 mod_timer(&ifmgd->conn_mon_timer,
2232 round_jiffies_up(jiffies +
2233 IEEE80211_CONNECTION_IDLE_TIME));
2235 mutex_unlock(&local->mtx);
2238 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2239 struct ieee80211_hdr *hdr,
2242 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2243 u16 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
2244 int ac = ieee80211_ac_from_tid(tid);
2245 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2246 unsigned long now = jiffies;
2248 if (likely(!tx_tspec->admitted_time))
2251 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2252 tx_tspec->consumed_tx_time = 0;
2253 tx_tspec->time_slice_start = now;
2255 if (tx_tspec->downgraded) {
2256 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2257 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2261 if (tx_tspec->downgraded)
2264 tx_tspec->consumed_tx_time += tx_time;
2266 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2267 tx_tspec->downgraded = true;
2268 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2269 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2273 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2274 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2276 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2278 if (!ieee80211_is_data(hdr->frame_control))
2281 if (ieee80211_is_any_nullfunc(hdr->frame_control) &&
2282 sdata->u.mgd.probe_send_count > 0) {
2284 ieee80211_sta_reset_conn_monitor(sdata);
2286 sdata->u.mgd.nullfunc_failed = true;
2287 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2292 ieee80211_sta_reset_conn_monitor(sdata);
2295 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2297 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2299 u8 *dst = ifmgd->associated->bssid;
2300 u8 unicast_limit = max(1, max_probe_tries - 3);
2301 struct sta_info *sta;
2304 * Try sending broadcast probe requests for the last three
2305 * probe requests after the first ones failed since some
2306 * buggy APs only support broadcast probe requests.
2308 if (ifmgd->probe_send_count >= unicast_limit)
2312 * When the hardware reports an accurate Tx ACK status, it's
2313 * better to send a nullfunc frame instead of a probe request,
2314 * as it will kick us off the AP quickly if we aren't associated
2315 * anymore. The timeout will be reset if the frame is ACKed by
2318 ifmgd->probe_send_count++;
2321 mutex_lock(&sdata->local->sta_mtx);
2322 sta = sta_info_get(sdata, dst);
2324 ieee80211_check_fast_rx(sta);
2325 mutex_unlock(&sdata->local->sta_mtx);
2328 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2329 ifmgd->nullfunc_failed = false;
2330 ieee80211_send_nullfunc(sdata->local, sdata, false);
2335 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
2336 if (WARN_ON_ONCE(ssid == NULL))
2341 ieee80211_send_probe_req(sdata, sdata->vif.addr, dst,
2342 ssid + 2, ssid_len, NULL,
2343 0, (u32) -1, true, 0,
2344 ifmgd->associated->channel, false);
2348 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2349 run_again(sdata, ifmgd->probe_timeout);
2352 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2355 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2356 bool already = false;
2358 if (!ieee80211_sdata_running(sdata))
2363 if (!ifmgd->associated)
2366 mutex_lock(&sdata->local->mtx);
2368 if (sdata->local->tmp_channel || sdata->local->scanning) {
2369 mutex_unlock(&sdata->local->mtx);
2374 mlme_dbg_ratelimited(sdata,
2375 "detected beacon loss from AP (missed %d beacons) - probing\n",
2378 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2382 * The driver/our work has already reported this event or the
2383 * connection monitoring has kicked in and we have already sent
2384 * a probe request. Or maybe the AP died and the driver keeps
2385 * reporting until we disassociate...
2387 * In either case we have to ignore the current call to this
2388 * function (except for setting the correct probe reason bit)
2389 * because otherwise we would reset the timer every time and
2390 * never check whether we received a probe response!
2392 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2395 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2397 mutex_unlock(&sdata->local->mtx);
2402 mutex_lock(&sdata->local->iflist_mtx);
2403 ieee80211_recalc_ps(sdata->local);
2404 mutex_unlock(&sdata->local->iflist_mtx);
2406 ifmgd->probe_send_count = 0;
2407 ieee80211_mgd_probe_ap_send(sdata);
2409 sdata_unlock(sdata);
2412 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2413 struct ieee80211_vif *vif)
2415 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2416 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2417 struct cfg80211_bss *cbss;
2418 struct sk_buff *skb;
2422 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2425 sdata_assert_lock(sdata);
2427 if (ifmgd->associated)
2428 cbss = ifmgd->associated;
2429 else if (ifmgd->auth_data)
2430 cbss = ifmgd->auth_data->bss;
2431 else if (ifmgd->assoc_data)
2432 cbss = ifmgd->assoc_data->bss;
2437 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2438 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2439 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
2444 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2445 (u32) -1, cbss->channel,
2452 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2454 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2455 const u8 *buf, size_t len, bool tx,
2458 struct ieee80211_event event = {
2460 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2461 .u.mlme.reason = reason,
2465 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2467 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2469 drv_event_callback(sdata->local, sdata, &event);
2472 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2474 struct ieee80211_local *local = sdata->local;
2475 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2476 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2480 if (!ifmgd->associated) {
2481 sdata_unlock(sdata);
2485 tx = !sdata->csa_block_tx;
2487 /* AP is probably out of range (or not reachable for another reason) so
2488 * remove the bss struct for that AP.
2490 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2492 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2493 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2495 mutex_lock(&local->mtx);
2496 sdata->vif.csa_active = false;
2497 ifmgd->csa_waiting_bcn = false;
2498 if (sdata->csa_block_tx) {
2499 ieee80211_wake_vif_queues(local, sdata,
2500 IEEE80211_QUEUE_STOP_REASON_CSA);
2501 sdata->csa_block_tx = false;
2503 mutex_unlock(&local->mtx);
2505 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2506 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2508 sdata_unlock(sdata);
2511 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2513 struct ieee80211_sub_if_data *sdata =
2514 container_of(work, struct ieee80211_sub_if_data,
2515 u.mgd.beacon_connection_loss_work);
2516 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2518 if (ifmgd->associated)
2519 ifmgd->beacon_loss_count++;
2521 if (ifmgd->connection_loss) {
2522 sdata_info(sdata, "Connection to AP %pM lost\n",
2524 __ieee80211_disconnect(sdata);
2526 ieee80211_mgd_probe_ap(sdata, true);
2530 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2532 struct ieee80211_sub_if_data *sdata =
2533 container_of(work, struct ieee80211_sub_if_data,
2534 u.mgd.csa_connection_drop_work);
2536 __ieee80211_disconnect(sdata);
2539 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2541 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2542 struct ieee80211_hw *hw = &sdata->local->hw;
2544 trace_api_beacon_loss(sdata);
2546 sdata->u.mgd.connection_loss = false;
2547 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2549 EXPORT_SYMBOL(ieee80211_beacon_loss);
2551 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2553 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2554 struct ieee80211_hw *hw = &sdata->local->hw;
2556 trace_api_connection_loss(sdata);
2558 sdata->u.mgd.connection_loss = true;
2559 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2561 EXPORT_SYMBOL(ieee80211_connection_loss);
2564 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2567 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2569 sdata_assert_lock(sdata);
2573 * we are not authenticated yet, the only timer that could be
2574 * running is the timeout for the authentication response which
2575 * which is not relevant anymore.
2577 del_timer_sync(&sdata->u.mgd.timer);
2578 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2580 eth_zero_addr(sdata->u.mgd.bssid);
2581 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2582 sdata->u.mgd.flags = 0;
2583 mutex_lock(&sdata->local->mtx);
2584 ieee80211_vif_release_channel(sdata);
2585 mutex_unlock(&sdata->local->mtx);
2588 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2590 sdata->u.mgd.auth_data = NULL;
2593 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2594 bool assoc, bool abandon)
2596 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2598 sdata_assert_lock(sdata);
2602 * we are not associated yet, the only timer that could be
2603 * running is the timeout for the association response which
2604 * which is not relevant anymore.
2606 del_timer_sync(&sdata->u.mgd.timer);
2607 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2609 eth_zero_addr(sdata->u.mgd.bssid);
2610 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2611 sdata->u.mgd.flags = 0;
2612 sdata->vif.mu_mimo_owner = false;
2614 mutex_lock(&sdata->local->mtx);
2615 ieee80211_vif_release_channel(sdata);
2616 mutex_unlock(&sdata->local->mtx);
2619 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2623 sdata->u.mgd.assoc_data = NULL;
2626 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2627 struct ieee80211_mgmt *mgmt, size_t len)
2629 struct ieee80211_local *local = sdata->local;
2630 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2632 struct ieee802_11_elems elems;
2635 pos = mgmt->u.auth.variable;
2636 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2637 if (!elems.challenge)
2639 auth_data->expected_transaction = 4;
2640 drv_mgd_prepare_tx(sdata->local, sdata);
2641 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2642 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2643 IEEE80211_TX_INTFL_MLME_CONN_TX;
2644 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2645 elems.challenge - 2, elems.challenge_len + 2,
2646 auth_data->bss->bssid, auth_data->bss->bssid,
2647 auth_data->key, auth_data->key_len,
2648 auth_data->key_idx, tx_flags);
2651 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2652 struct ieee80211_mgmt *mgmt, size_t len)
2654 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2656 u16 auth_alg, auth_transaction, status_code;
2657 struct sta_info *sta;
2658 struct ieee80211_event event = {
2660 .u.mlme.data = AUTH_EVENT,
2663 sdata_assert_lock(sdata);
2668 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2671 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2673 if (!ether_addr_equal(bssid, mgmt->bssid))
2676 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2677 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2678 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2680 if (auth_alg != ifmgd->auth_data->algorithm ||
2681 auth_transaction != ifmgd->auth_data->expected_transaction) {
2682 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2683 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2685 ifmgd->auth_data->expected_transaction);
2689 if (status_code != WLAN_STATUS_SUCCESS) {
2690 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2691 mgmt->sa, status_code);
2692 ieee80211_destroy_auth_data(sdata, false);
2693 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2694 event.u.mlme.status = MLME_DENIED;
2695 event.u.mlme.reason = status_code;
2696 drv_event_callback(sdata->local, sdata, &event);
2700 switch (ifmgd->auth_data->algorithm) {
2701 case WLAN_AUTH_OPEN:
2702 case WLAN_AUTH_LEAP:
2705 case WLAN_AUTH_FILS_SK:
2706 case WLAN_AUTH_FILS_SK_PFS:
2707 case WLAN_AUTH_FILS_PK:
2709 case WLAN_AUTH_SHARED_KEY:
2710 if (ifmgd->auth_data->expected_transaction != 4) {
2711 ieee80211_auth_challenge(sdata, mgmt, len);
2712 /* need another frame */
2717 WARN_ONCE(1, "invalid auth alg %d",
2718 ifmgd->auth_data->algorithm);
2722 event.u.mlme.status = MLME_SUCCESS;
2723 drv_event_callback(sdata->local, sdata, &event);
2724 sdata_info(sdata, "authenticated\n");
2725 ifmgd->auth_data->done = true;
2726 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2727 ifmgd->auth_data->timeout_started = true;
2728 run_again(sdata, ifmgd->auth_data->timeout);
2730 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2731 ifmgd->auth_data->expected_transaction != 2) {
2733 * Report auth frame to user space for processing since another
2734 * round of Authentication frames is still needed.
2736 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2740 /* move station state to auth */
2741 mutex_lock(&sdata->local->sta_mtx);
2742 sta = sta_info_get(sdata, bssid);
2744 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2747 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2748 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2751 mutex_unlock(&sdata->local->sta_mtx);
2753 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2756 mutex_unlock(&sdata->local->sta_mtx);
2757 /* ignore frame -- wait for timeout */
2760 #define case_WLAN(type) \
2761 case WLAN_REASON_##type: return #type
2763 const char *ieee80211_get_reason_code_string(u16 reason_code)
2765 switch (reason_code) {
2766 case_WLAN(UNSPECIFIED);
2767 case_WLAN(PREV_AUTH_NOT_VALID);
2768 case_WLAN(DEAUTH_LEAVING);
2769 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2770 case_WLAN(DISASSOC_AP_BUSY);
2771 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2772 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2773 case_WLAN(DISASSOC_STA_HAS_LEFT);
2774 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2775 case_WLAN(DISASSOC_BAD_POWER);
2776 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2777 case_WLAN(INVALID_IE);
2778 case_WLAN(MIC_FAILURE);
2779 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2780 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2781 case_WLAN(IE_DIFFERENT);
2782 case_WLAN(INVALID_GROUP_CIPHER);
2783 case_WLAN(INVALID_PAIRWISE_CIPHER);
2784 case_WLAN(INVALID_AKMP);
2785 case_WLAN(UNSUPP_RSN_VERSION);
2786 case_WLAN(INVALID_RSN_IE_CAP);
2787 case_WLAN(IEEE8021X_FAILED);
2788 case_WLAN(CIPHER_SUITE_REJECTED);
2789 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2790 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2791 case_WLAN(DISASSOC_LOW_ACK);
2792 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2793 case_WLAN(QSTA_LEAVE_QBSS);
2794 case_WLAN(QSTA_NOT_USE);
2795 case_WLAN(QSTA_REQUIRE_SETUP);
2796 case_WLAN(QSTA_TIMEOUT);
2797 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2798 case_WLAN(MESH_PEER_CANCELED);
2799 case_WLAN(MESH_MAX_PEERS);
2800 case_WLAN(MESH_CONFIG);
2801 case_WLAN(MESH_CLOSE);
2802 case_WLAN(MESH_MAX_RETRIES);
2803 case_WLAN(MESH_CONFIRM_TIMEOUT);
2804 case_WLAN(MESH_INVALID_GTK);
2805 case_WLAN(MESH_INCONSISTENT_PARAM);
2806 case_WLAN(MESH_INVALID_SECURITY);
2807 case_WLAN(MESH_PATH_ERROR);
2808 case_WLAN(MESH_PATH_NOFORWARD);
2809 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
2810 case_WLAN(MAC_EXISTS_IN_MBSS);
2811 case_WLAN(MESH_CHAN_REGULATORY);
2812 case_WLAN(MESH_CHAN);
2813 default: return "<unknown>";
2817 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2818 struct ieee80211_mgmt *mgmt, size_t len)
2820 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2821 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2823 sdata_assert_lock(sdata);
2828 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
2829 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
2833 if (ifmgd->associated &&
2834 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
2835 const u8 *bssid = ifmgd->associated->bssid;
2837 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
2839 ieee80211_get_reason_code_string(reason_code));
2841 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2843 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
2848 if (ifmgd->assoc_data &&
2849 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2850 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
2853 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2855 ieee80211_get_reason_code_string(reason_code));
2857 ieee80211_destroy_assoc_data(sdata, false, true);
2859 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2865 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2866 struct ieee80211_mgmt *mgmt, size_t len)
2868 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2871 sdata_assert_lock(sdata);
2876 if (!ifmgd->associated ||
2877 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
2880 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2882 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
2883 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
2887 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
2888 mgmt->sa, reason_code,
2889 ieee80211_get_reason_code_string(reason_code));
2891 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2893 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
2896 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2897 u8 *supp_rates, unsigned int supp_rates_len,
2898 u32 *rates, u32 *basic_rates,
2899 bool *have_higher_than_11mbit,
2900 int *min_rate, int *min_rate_index,
2905 for (i = 0; i < supp_rates_len; i++) {
2906 int rate = supp_rates[i] & 0x7f;
2907 bool is_basic = !!(supp_rates[i] & 0x80);
2909 if ((rate * 5 * (1 << shift)) > 110)
2910 *have_higher_than_11mbit = true;
2913 * Skip HT and VHT BSS membership selectors since they're not
2916 * Note: Even though the membership selector and the basic
2917 * rate flag share the same bit, they are not exactly
2920 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
2921 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
2924 for (j = 0; j < sband->n_bitrates; j++) {
2925 struct ieee80211_rate *br;
2928 br = &sband->bitrates[j];
2930 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
2931 if (brate == rate) {
2934 *basic_rates |= BIT(j);
2935 if ((rate * 5) < *min_rate) {
2936 *min_rate = rate * 5;
2937 *min_rate_index = j;
2945 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2946 struct cfg80211_bss *cbss,
2947 struct ieee80211_mgmt *mgmt, size_t len)
2949 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2950 struct ieee80211_local *local = sdata->local;
2951 struct ieee80211_supported_band *sband;
2952 struct sta_info *sta;
2954 u16 capab_info, aid;
2955 struct ieee802_11_elems elems;
2956 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2957 const struct cfg80211_bss_ies *bss_ies = NULL;
2958 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2963 /* AssocResp and ReassocResp have identical structure */
2965 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2966 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2968 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2969 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2971 aid &= ~(BIT(15) | BIT(14));
2973 ifmgd->broken_ap = false;
2975 if (aid == 0 || aid > IEEE80211_MAX_AID) {
2976 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2979 ifmgd->broken_ap = true;
2982 pos = mgmt->u.assoc_resp.variable;
2983 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2985 if (!elems.supp_rates) {
2986 sdata_info(sdata, "no SuppRates element in AssocResp\n");
2991 ifmgd->tdls_chan_switch_prohibited =
2992 elems.ext_capab && elems.ext_capab_len >= 5 &&
2993 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
2996 * Some APs are erroneously not including some information in their
2997 * (re)association response frames. Try to recover by using the data
2998 * from the beacon or probe response. This seems to afflict mobile
2999 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3000 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3002 if ((assoc_data->wmm && !elems.wmm_param) ||
3003 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3004 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3005 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3006 (!elems.vht_cap_elem || !elems.vht_operation))) {
3007 const struct cfg80211_bss_ies *ies;
3008 struct ieee802_11_elems bss_elems;
3011 ies = rcu_dereference(cbss->ies);
3013 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3019 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3021 if (assoc_data->wmm &&
3022 !elems.wmm_param && bss_elems.wmm_param) {
3023 elems.wmm_param = bss_elems.wmm_param;
3025 "AP bug: WMM param missing from AssocResp\n");
3029 * Also check if we requested HT/VHT, otherwise the AP doesn't
3030 * have to include the IEs in the (re)association response.
3032 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3033 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3034 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3036 "AP bug: HT capability missing from AssocResp\n");
3038 if (!elems.ht_operation && bss_elems.ht_operation &&
3039 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3040 elems.ht_operation = bss_elems.ht_operation;
3042 "AP bug: HT operation missing from AssocResp\n");
3044 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3045 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3046 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3048 "AP bug: VHT capa missing from AssocResp\n");
3050 if (!elems.vht_operation && bss_elems.vht_operation &&
3051 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3052 elems.vht_operation = bss_elems.vht_operation;
3054 "AP bug: VHT operation missing from AssocResp\n");
3059 * We previously checked these in the beacon/probe response, so
3060 * they should be present here. This is just a safety net.
3062 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3063 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3065 "HT AP is missing WMM params or HT capability/operation\n");
3070 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3071 (!elems.vht_cap_elem || !elems.vht_operation)) {
3073 "VHT AP is missing VHT capability/operation\n");
3078 mutex_lock(&sdata->local->sta_mtx);
3080 * station info was already allocated and inserted before
3081 * the association and should be available to us
3083 sta = sta_info_get(sdata, cbss->bssid);
3084 if (WARN_ON(!sta)) {
3085 mutex_unlock(&sdata->local->sta_mtx);
3090 sband = ieee80211_get_sband(sdata);
3092 mutex_unlock(&sdata->local->sta_mtx);
3097 /* Set up internal HT/VHT capabilities */
3098 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3099 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3100 elems.ht_cap_elem, sta);
3102 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3103 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3104 elems.vht_cap_elem, sta);
3107 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3108 * in their association response, so ignore that data for our own
3109 * configuration. If it changed since the last beacon, we'll get the
3110 * next beacon and update then.
3114 * If an operating mode notification IE is present, override the
3115 * NSS calculation (that would be done in rate_control_rate_init())
3116 * and use the # of streams from that element.
3118 if (elems.opmode_notif &&
3119 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3122 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3123 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3125 sta->sta.rx_nss = nss;
3128 rate_control_rate_init(sta);
3130 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3131 set_sta_flag(sta, WLAN_STA_MFP);
3132 sta->sta.mfp = true;
3134 sta->sta.mfp = false;
3137 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
3139 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3140 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3141 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3144 "failed to move station %pM to desired state\n",
3146 WARN_ON(__sta_info_destroy(sta));
3147 mutex_unlock(&sdata->local->sta_mtx);
3152 mutex_unlock(&sdata->local->sta_mtx);
3155 * Always handle WMM once after association regardless
3156 * of the first value the AP uses. Setting -1 here has
3157 * that effect because the AP values is an unsigned
3160 ifmgd->wmm_last_param_set = -1;
3162 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3163 ieee80211_set_wmm_default(sdata, false, false);
3164 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3165 elems.wmm_param_len)) {
3166 /* still enable QoS since we might have HT/VHT */
3167 ieee80211_set_wmm_default(sdata, false, true);
3168 /* set the disable-WMM flag in this case to disable
3169 * tracking WMM parameter changes in the beacon if
3170 * the parameters weren't actually valid. Doing so
3171 * avoids changing parameters very strangely when
3172 * the AP is going back and forth between valid and
3173 * invalid parameters.
3175 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3177 changed |= BSS_CHANGED_QOS;
3179 if (elems.max_idle_period_ie) {
3180 bss_conf->max_idle_period =
3181 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3182 bss_conf->protected_keep_alive =
3183 !!(elems.max_idle_period_ie->idle_options &
3184 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3185 changed |= BSS_CHANGED_KEEP_ALIVE;
3187 bss_conf->max_idle_period = 0;
3188 bss_conf->protected_keep_alive = false;
3191 /* set AID and assoc capability,
3192 * ieee80211_set_associated() will tell the driver */
3193 bss_conf->aid = aid;
3194 bss_conf->assoc_capability = capab_info;
3195 ieee80211_set_associated(sdata, cbss, changed);
3198 * If we're using 4-addr mode, let the AP know that we're
3199 * doing so, so that it can create the STA VLAN on its side
3201 if (ifmgd->use_4addr)
3202 ieee80211_send_4addr_nullfunc(local, sdata);
3205 * Start timer to probe the connection to the AP now.
3206 * Also start the timer that will detect beacon loss.
3208 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
3209 ieee80211_sta_reset_beacon_monitor(sdata);
3217 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3218 struct ieee80211_mgmt *mgmt,
3221 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3222 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3223 u16 capab_info, status_code, aid;
3224 struct ieee802_11_elems elems;
3225 int ac, uapsd_queues = -1;
3228 struct cfg80211_bss *bss;
3229 struct ieee80211_event event = {
3231 .u.mlme.data = ASSOC_EVENT,
3234 sdata_assert_lock(sdata);
3238 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3242 * AssocResp and ReassocResp have identical structure, so process both
3243 * of them in this function.
3249 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3250 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3251 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3252 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3255 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3256 reassoc ? "Rea" : "A", mgmt->sa,
3257 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3259 if (assoc_data->fils_kek_len &&
3260 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3263 pos = mgmt->u.assoc_resp.variable;
3264 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
3266 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3267 elems.timeout_int &&
3268 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3270 tu = le32_to_cpu(elems.timeout_int->value);
3271 ms = tu * 1024 / 1000;
3273 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3275 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3276 assoc_data->timeout_started = true;
3277 if (ms > IEEE80211_ASSOC_TIMEOUT)
3278 run_again(sdata, assoc_data->timeout);
3282 bss = assoc_data->bss;
3284 if (status_code != WLAN_STATUS_SUCCESS) {
3285 sdata_info(sdata, "%pM denied association (code=%d)\n",
3286 mgmt->sa, status_code);
3287 ieee80211_destroy_assoc_data(sdata, false, false);
3288 event.u.mlme.status = MLME_DENIED;
3289 event.u.mlme.reason = status_code;
3290 drv_event_callback(sdata->local, sdata, &event);
3292 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
3293 /* oops -- internal error -- send timeout for now */
3294 ieee80211_destroy_assoc_data(sdata, false, false);
3295 cfg80211_assoc_timeout(sdata->dev, bss);
3298 event.u.mlme.status = MLME_SUCCESS;
3299 drv_event_callback(sdata->local, sdata, &event);
3300 sdata_info(sdata, "associated\n");
3303 * destroy assoc_data afterwards, as otherwise an idle
3304 * recalc after assoc_data is NULL but before associated
3305 * is set can cause the interface to go idle
3307 ieee80211_destroy_assoc_data(sdata, true, false);
3309 /* get uapsd queues configuration */
3311 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3312 if (sdata->tx_conf[ac].uapsd)
3313 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3316 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
3319 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3320 struct ieee80211_mgmt *mgmt, size_t len,
3321 struct ieee80211_rx_status *rx_status,
3322 struct ieee802_11_elems *elems)
3324 struct ieee80211_local *local = sdata->local;
3325 struct ieee80211_bss *bss;
3326 struct ieee80211_channel *channel;
3328 sdata_assert_lock(sdata);
3330 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3334 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
3337 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3338 ieee80211_rx_bss_put(local, bss);
3343 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3344 struct sk_buff *skb)
3346 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3347 struct ieee80211_if_managed *ifmgd;
3348 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3349 size_t baselen, len = skb->len;
3350 struct ieee802_11_elems elems;
3352 ifmgd = &sdata->u.mgd;
3354 sdata_assert_lock(sdata);
3356 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
3357 return; /* ignore ProbeResp to foreign address */
3359 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3363 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
3366 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3368 if (ifmgd->associated &&
3369 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3370 ieee80211_reset_ap_probe(sdata);
3374 * This is the canonical list of information elements we care about,
3375 * the filter code also gives us all changes to the Microsoft OUI
3376 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3377 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3378 * changes to requested client power.
3380 * We implement beacon filtering in software since that means we can
3381 * avoid processing the frame here and in cfg80211, and userspace
3382 * will not be able to tell whether the hardware supports it or not.
3384 * XXX: This list needs to be dynamic -- userspace needs to be able to
3385 * add items it requires. It also needs to be able to tell us to
3386 * look out for other vendor IEs.
3388 static const u64 care_about_ies =
3389 (1ULL << WLAN_EID_COUNTRY) |
3390 (1ULL << WLAN_EID_ERP_INFO) |
3391 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3392 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3393 (1ULL << WLAN_EID_HT_CAPABILITY) |
3394 (1ULL << WLAN_EID_HT_OPERATION) |
3395 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3397 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3398 struct ieee80211_mgmt *mgmt, size_t len,
3399 struct ieee80211_rx_status *rx_status)
3401 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3402 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3404 struct ieee802_11_elems elems;
3405 struct ieee80211_local *local = sdata->local;
3406 struct ieee80211_chanctx_conf *chanctx_conf;
3407 struct ieee80211_channel *chan;
3408 struct sta_info *sta;
3414 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3416 sdata_assert_lock(sdata);
3418 /* Process beacon from the current BSS */
3419 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3424 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3425 if (!chanctx_conf) {
3430 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3434 chan = chanctx_conf->def.chan;
3437 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3438 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3439 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3440 len - baselen, false, &elems);
3442 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3443 if (elems.tim && !elems.parse_error) {
3444 const struct ieee80211_tim_ie *tim_ie = elems.tim;
3445 ifmgd->dtim_period = tim_ie->dtim_period;
3447 ifmgd->have_beacon = true;
3448 ifmgd->assoc_data->need_beacon = false;
3449 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3450 sdata->vif.bss_conf.sync_tsf =
3451 le64_to_cpu(mgmt->u.beacon.timestamp);
3452 sdata->vif.bss_conf.sync_device_ts =
3453 rx_status->device_timestamp;
3455 sdata->vif.bss_conf.sync_dtim_count =
3456 elems.tim->dtim_count;
3458 sdata->vif.bss_conf.sync_dtim_count = 0;
3460 /* continue assoc process */
3461 ifmgd->assoc_data->timeout = jiffies;
3462 ifmgd->assoc_data->timeout_started = true;
3463 run_again(sdata, ifmgd->assoc_data->timeout);
3467 if (!ifmgd->associated ||
3468 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3470 bssid = ifmgd->associated->bssid;
3472 /* Track average RSSI from the Beacon frames of the current AP */
3473 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3474 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3475 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3476 ifmgd->last_cqm_event_signal = 0;
3477 ifmgd->count_beacon_signal = 1;
3478 ifmgd->last_ave_beacon_signal = 0;
3480 ifmgd->count_beacon_signal++;
3483 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3485 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3486 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3487 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3488 int last_sig = ifmgd->last_ave_beacon_signal;
3489 struct ieee80211_event event = {
3494 * if signal crosses either of the boundaries, invoke callback
3495 * with appropriate parameters
3497 if (sig > ifmgd->rssi_max_thold &&
3498 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3499 ifmgd->last_ave_beacon_signal = sig;
3500 event.u.rssi.data = RSSI_EVENT_HIGH;
3501 drv_event_callback(local, sdata, &event);
3502 } else if (sig < ifmgd->rssi_min_thold &&
3503 (last_sig >= ifmgd->rssi_max_thold ||
3505 ifmgd->last_ave_beacon_signal = sig;
3506 event.u.rssi.data = RSSI_EVENT_LOW;
3507 drv_event_callback(local, sdata, &event);
3511 if (bss_conf->cqm_rssi_thold &&
3512 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3513 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3514 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3515 int last_event = ifmgd->last_cqm_event_signal;
3516 int thold = bss_conf->cqm_rssi_thold;
3517 int hyst = bss_conf->cqm_rssi_hyst;
3520 (last_event == 0 || sig < last_event - hyst)) {
3521 ifmgd->last_cqm_event_signal = sig;
3522 ieee80211_cqm_rssi_notify(
3524 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3526 } else if (sig > thold &&
3527 (last_event == 0 || sig > last_event + hyst)) {
3528 ifmgd->last_cqm_event_signal = sig;
3529 ieee80211_cqm_rssi_notify(
3531 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3536 if (bss_conf->cqm_rssi_low &&
3537 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3538 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3539 int last_event = ifmgd->last_cqm_event_signal;
3540 int low = bss_conf->cqm_rssi_low;
3541 int high = bss_conf->cqm_rssi_high;
3544 (last_event == 0 || last_event >= low)) {
3545 ifmgd->last_cqm_event_signal = sig;
3546 ieee80211_cqm_rssi_notify(
3548 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3550 } else if (sig > high &&
3551 (last_event == 0 || last_event <= high)) {
3552 ifmgd->last_cqm_event_signal = sig;
3553 ieee80211_cqm_rssi_notify(
3555 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3560 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
3561 mlme_dbg_ratelimited(sdata,
3562 "cancelling AP probe due to a received beacon\n");
3563 ieee80211_reset_ap_probe(sdata);
3567 * Push the beacon loss detection into the future since
3568 * we are processing a beacon from the AP just now.
3570 ieee80211_sta_reset_beacon_monitor(sdata);
3572 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3573 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
3574 len - baselen, false, &elems,
3575 care_about_ies, ncrc);
3577 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3578 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3579 if (local->hw.conf.dynamic_ps_timeout > 0) {
3580 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3581 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3582 ieee80211_hw_config(local,
3583 IEEE80211_CONF_CHANGE_PS);
3585 ieee80211_send_nullfunc(local, sdata, false);
3586 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3587 local->pspolling = true;
3590 * Here is assumed that the driver will be
3591 * able to send ps-poll frame and receive a
3592 * response even though power save mode is
3593 * enabled, but some drivers might require
3594 * to disable power save here. This needs
3595 * to be investigated.
3597 ieee80211_send_pspoll(local, sdata);
3601 if (sdata->vif.p2p ||
3602 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
3603 struct ieee80211_p2p_noa_attr noa = {};
3606 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3608 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
3609 (u8 *) &noa, sizeof(noa));
3611 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3612 /* valid noa_attr and index changed */
3613 sdata->u.mgd.p2p_noa_index = noa.index;
3614 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3615 changed |= BSS_CHANGED_P2P_PS;
3617 * make sure we update all information, the CRC
3618 * mechanism doesn't look at P2P attributes.
3620 ifmgd->beacon_crc_valid = false;
3622 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3623 /* noa_attr not found and we had valid noa_attr before */
3624 sdata->u.mgd.p2p_noa_index = -1;
3625 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
3626 changed |= BSS_CHANGED_P2P_PS;
3627 ifmgd->beacon_crc_valid = false;
3631 if (ifmgd->csa_waiting_bcn)
3632 ieee80211_chswitch_post_beacon(sdata);
3635 * Update beacon timing and dtim count on every beacon appearance. This
3636 * will allow the driver to use the most updated values. Do it before
3637 * comparing this one with last received beacon.
3638 * IMPORTANT: These parameters would possibly be out of sync by the time
3639 * the driver will use them. The synchronized view is currently
3640 * guaranteed only in certain callbacks.
3642 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3643 sdata->vif.bss_conf.sync_tsf =
3644 le64_to_cpu(mgmt->u.beacon.timestamp);
3645 sdata->vif.bss_conf.sync_device_ts =
3646 rx_status->device_timestamp;
3648 sdata->vif.bss_conf.sync_dtim_count =
3649 elems.tim->dtim_count;
3651 sdata->vif.bss_conf.sync_dtim_count = 0;
3654 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
3656 ifmgd->beacon_crc = ncrc;
3657 ifmgd->beacon_crc_valid = true;
3659 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3661 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
3662 rx_status->device_timestamp,
3665 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3666 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3667 elems.wmm_param_len))
3668 changed |= BSS_CHANGED_QOS;
3671 * If we haven't had a beacon before, tell the driver about the
3672 * DTIM period (and beacon timing if desired) now.
3674 if (!ifmgd->have_beacon) {
3675 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3677 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3679 bss_conf->dtim_period = 1;
3681 changed |= BSS_CHANGED_BEACON_INFO;
3682 ifmgd->have_beacon = true;
3684 mutex_lock(&local->iflist_mtx);
3685 ieee80211_recalc_ps(local);
3686 mutex_unlock(&local->iflist_mtx);
3688 ieee80211_recalc_ps_vif(sdata);
3691 if (elems.erp_info) {
3693 erp_value = elems.erp_info[0];
3697 changed |= ieee80211_handle_bss_capability(sdata,
3698 le16_to_cpu(mgmt->u.beacon.capab_info),
3699 erp_valid, erp_value);
3701 mutex_lock(&local->sta_mtx);
3702 sta = sta_info_get(sdata, bssid);
3704 if (ieee80211_config_bw(sdata, sta,
3705 elems.ht_cap_elem, elems.ht_operation,
3706 elems.vht_operation, bssid, &changed)) {
3707 mutex_unlock(&local->sta_mtx);
3709 "failed to follow AP %pM bandwidth change, disconnect\n",
3711 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3712 WLAN_REASON_DEAUTH_LEAVING,
3714 ieee80211_report_disconnect(sdata, deauth_buf,
3715 sizeof(deauth_buf), true,
3716 WLAN_REASON_DEAUTH_LEAVING);
3720 if (sta && elems.opmode_notif)
3721 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
3723 mutex_unlock(&local->sta_mtx);
3725 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
3727 elems.country_elem_len,
3728 elems.pwr_constr_elem,
3729 elems.cisco_dtpc_elem);
3731 ieee80211_bss_info_change_notify(sdata, changed);
3734 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3735 struct sk_buff *skb)
3737 struct ieee80211_rx_status *rx_status;
3738 struct ieee80211_mgmt *mgmt;
3740 struct ieee802_11_elems elems;
3743 rx_status = (struct ieee80211_rx_status *) skb->cb;
3744 mgmt = (struct ieee80211_mgmt *) skb->data;
3745 fc = le16_to_cpu(mgmt->frame_control);
3749 switch (fc & IEEE80211_FCTL_STYPE) {
3750 case IEEE80211_STYPE_BEACON:
3751 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
3753 case IEEE80211_STYPE_PROBE_RESP:
3754 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3756 case IEEE80211_STYPE_AUTH:
3757 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
3759 case IEEE80211_STYPE_DEAUTH:
3760 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
3762 case IEEE80211_STYPE_DISASSOC:
3763 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
3765 case IEEE80211_STYPE_ASSOC_RESP:
3766 case IEEE80211_STYPE_REASSOC_RESP:
3767 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
3769 case IEEE80211_STYPE_ACTION:
3770 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
3771 ies_len = skb->len -
3772 offsetof(struct ieee80211_mgmt,
3773 u.action.u.chan_switch.variable);
3778 ieee802_11_parse_elems(
3779 mgmt->u.action.u.chan_switch.variable,
3780 ies_len, true, &elems);
3782 if (elems.parse_error)
3785 ieee80211_sta_process_chanswitch(sdata,
3787 rx_status->device_timestamp,
3789 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3790 ies_len = skb->len -
3791 offsetof(struct ieee80211_mgmt,
3792 u.action.u.ext_chan_switch.variable);
3797 ieee802_11_parse_elems(
3798 mgmt->u.action.u.ext_chan_switch.variable,
3799 ies_len, true, &elems);
3801 if (elems.parse_error)
3804 /* for the handling code pretend this was also an IE */
3805 elems.ext_chansw_ie =
3806 &mgmt->u.action.u.ext_chan_switch.data;
3808 ieee80211_sta_process_chanswitch(sdata,
3810 rx_status->device_timestamp,
3815 sdata_unlock(sdata);
3818 static void ieee80211_sta_timer(unsigned long data)
3820 struct ieee80211_sub_if_data *sdata =
3821 (struct ieee80211_sub_if_data *) data;
3823 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3826 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
3827 u8 *bssid, u8 reason, bool tx)
3829 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3831 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
3834 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
3838 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
3840 struct ieee80211_local *local = sdata->local;
3841 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3842 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
3847 sdata_assert_lock(sdata);
3849 if (WARN_ON_ONCE(!auth_data))
3854 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
3855 sdata_info(sdata, "authentication with %pM timed out\n",
3856 auth_data->bss->bssid);
3859 * Most likely AP is not in the range so remove the
3860 * bss struct for that AP.
3862 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3867 drv_mgd_prepare_tx(local, sdata);
3869 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3870 auth_data->bss->bssid, auth_data->tries,
3871 IEEE80211_AUTH_MAX_TRIES);
3873 auth_data->expected_transaction = 2;
3875 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3876 trans = auth_data->sae_trans;
3877 status = auth_data->sae_status;
3878 auth_data->expected_transaction = trans;
3881 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3882 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3883 IEEE80211_TX_INTFL_MLME_CONN_TX;
3885 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
3886 auth_data->data, auth_data->data_len,
3887 auth_data->bss->bssid,
3888 auth_data->bss->bssid, NULL, 0, 0,
3891 if (tx_flags == 0) {
3892 if (auth_data->algorithm == WLAN_AUTH_SAE)
3893 auth_data->timeout = jiffies +
3894 IEEE80211_AUTH_TIMEOUT_SAE;
3896 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
3898 auth_data->timeout =
3899 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
3902 auth_data->timeout_started = true;
3903 run_again(sdata, auth_data->timeout);
3908 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
3910 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3911 struct ieee80211_local *local = sdata->local;
3913 sdata_assert_lock(sdata);
3915 assoc_data->tries++;
3916 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
3917 sdata_info(sdata, "association with %pM timed out\n",
3918 assoc_data->bss->bssid);
3921 * Most likely AP is not in the range so remove the
3922 * bss struct for that AP.
3924 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
3929 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
3930 assoc_data->bss->bssid, assoc_data->tries,
3931 IEEE80211_ASSOC_MAX_TRIES);
3932 ieee80211_send_assoc(sdata);
3934 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
3935 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
3936 assoc_data->timeout_started = true;
3937 run_again(sdata, assoc_data->timeout);
3939 assoc_data->timeout =
3940 round_jiffies_up(jiffies +
3941 IEEE80211_ASSOC_TIMEOUT_LONG);
3942 assoc_data->timeout_started = true;
3943 run_again(sdata, assoc_data->timeout);
3949 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
3950 __le16 fc, bool acked)
3952 struct ieee80211_local *local = sdata->local;
3954 sdata->u.mgd.status_fc = fc;
3955 sdata->u.mgd.status_acked = acked;
3956 sdata->u.mgd.status_received = true;
3958 ieee80211_queue_work(&local->hw, &sdata->work);
3961 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
3963 struct ieee80211_local *local = sdata->local;
3964 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3968 if (ifmgd->status_received) {
3969 __le16 fc = ifmgd->status_fc;
3970 bool status_acked = ifmgd->status_acked;
3972 ifmgd->status_received = false;
3973 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
3975 if (ifmgd->auth_data->algorithm ==
3977 ifmgd->auth_data->timeout =
3979 IEEE80211_AUTH_TIMEOUT_SAE;
3981 ifmgd->auth_data->timeout =
3983 IEEE80211_AUTH_TIMEOUT_SHORT;
3984 run_again(sdata, ifmgd->auth_data->timeout);
3986 ifmgd->auth_data->timeout = jiffies - 1;
3988 ifmgd->auth_data->timeout_started = true;
3989 } else if (ifmgd->assoc_data &&
3990 (ieee80211_is_assoc_req(fc) ||
3991 ieee80211_is_reassoc_req(fc))) {
3993 ifmgd->assoc_data->timeout =
3994 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
3995 run_again(sdata, ifmgd->assoc_data->timeout);
3997 ifmgd->assoc_data->timeout = jiffies - 1;
3999 ifmgd->assoc_data->timeout_started = true;
4003 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4004 time_after(jiffies, ifmgd->auth_data->timeout)) {
4005 if (ifmgd->auth_data->done) {
4007 * ok ... we waited for assoc but userspace didn't,
4008 * so let's just kill the auth data
4010 ieee80211_destroy_auth_data(sdata, false);
4011 } else if (ieee80211_auth(sdata)) {
4013 struct ieee80211_event event = {
4015 .u.mlme.data = AUTH_EVENT,
4016 .u.mlme.status = MLME_TIMEOUT,
4019 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4021 ieee80211_destroy_auth_data(sdata, false);
4023 cfg80211_auth_timeout(sdata->dev, bssid);
4024 drv_event_callback(sdata->local, sdata, &event);
4026 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4027 run_again(sdata, ifmgd->auth_data->timeout);
4029 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4030 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4031 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4032 ieee80211_do_assoc(sdata)) {
4033 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4034 struct ieee80211_event event = {
4036 .u.mlme.data = ASSOC_EVENT,
4037 .u.mlme.status = MLME_TIMEOUT,
4040 ieee80211_destroy_assoc_data(sdata, false, false);
4041 cfg80211_assoc_timeout(sdata->dev, bss);
4042 drv_event_callback(sdata->local, sdata, &event);
4044 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4045 run_again(sdata, ifmgd->assoc_data->timeout);
4047 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4048 ifmgd->associated) {
4052 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4054 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4055 max_tries = max_nullfunc_tries;
4057 max_tries = max_probe_tries;
4059 /* ACK received for nullfunc probing frame */
4060 if (!ifmgd->probe_send_count)
4061 ieee80211_reset_ap_probe(sdata);
4062 else if (ifmgd->nullfunc_failed) {
4063 if (ifmgd->probe_send_count < max_tries) {
4065 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4066 bssid, ifmgd->probe_send_count,
4068 ieee80211_mgd_probe_ap_send(sdata);
4071 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4073 ieee80211_sta_connection_lost(sdata, bssid,
4074 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4077 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4078 run_again(sdata, ifmgd->probe_timeout);
4079 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4081 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4082 bssid, probe_wait_ms);
4083 ieee80211_sta_connection_lost(sdata, bssid,
4084 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4085 } else if (ifmgd->probe_send_count < max_tries) {
4087 "No probe response from AP %pM after %dms, try %d/%i\n",
4088 bssid, probe_wait_ms,
4089 ifmgd->probe_send_count, max_tries);
4090 ieee80211_mgd_probe_ap_send(sdata);
4093 * We actually lost the connection ... or did we?
4097 "No probe response from AP %pM after %dms, disconnecting.\n",
4098 bssid, probe_wait_ms);
4100 ieee80211_sta_connection_lost(sdata, bssid,
4101 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4105 sdata_unlock(sdata);
4108 static void ieee80211_sta_bcn_mon_timer(unsigned long data)
4110 struct ieee80211_sub_if_data *sdata =
4111 (struct ieee80211_sub_if_data *) data;
4112 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4114 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4117 sdata->u.mgd.connection_loss = false;
4118 ieee80211_queue_work(&sdata->local->hw,
4119 &sdata->u.mgd.beacon_connection_loss_work);
4122 static void ieee80211_sta_conn_mon_timer(unsigned long data)
4124 struct ieee80211_sub_if_data *sdata =
4125 (struct ieee80211_sub_if_data *) data;
4126 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4127 struct ieee80211_local *local = sdata->local;
4129 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4132 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4135 static void ieee80211_sta_monitor_work(struct work_struct *work)
4137 struct ieee80211_sub_if_data *sdata =
4138 container_of(work, struct ieee80211_sub_if_data,
4139 u.mgd.monitor_work);
4141 ieee80211_mgd_probe_ap(sdata, false);
4144 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4146 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4147 __ieee80211_stop_poll(sdata);
4149 /* let's probe the connection once */
4150 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4151 ieee80211_queue_work(&sdata->local->hw,
4152 &sdata->u.mgd.monitor_work);
4157 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4159 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4160 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4164 if (ifmgd->auth_data || ifmgd->assoc_data) {
4165 const u8 *bssid = ifmgd->auth_data ?
4166 ifmgd->auth_data->bss->bssid :
4167 ifmgd->assoc_data->bss->bssid;
4170 * If we are trying to authenticate / associate while suspending,
4171 * cfg80211 won't know and won't actually abort those attempts,
4172 * thus we need to do that ourselves.
4174 ieee80211_send_deauth_disassoc(sdata, bssid,
4175 IEEE80211_STYPE_DEAUTH,
4176 WLAN_REASON_DEAUTH_LEAVING,
4178 if (ifmgd->assoc_data)
4179 ieee80211_destroy_assoc_data(sdata, false, true);
4180 if (ifmgd->auth_data)
4181 ieee80211_destroy_auth_data(sdata, false);
4182 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4183 IEEE80211_DEAUTH_FRAME_LEN);
4186 /* This is a bit of a hack - we should find a better and more generic
4187 * solution to this. Normally when suspending, cfg80211 will in fact
4188 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4189 * auth (not so important) or assoc (this is the problem) process.
4191 * As a consequence, it can happen that we are in the process of both
4192 * associating and suspending, and receive an association response
4193 * after cfg80211 has checked if it needs to disconnect, but before
4194 * we actually set the flag to drop incoming frames. This will then
4195 * cause the workqueue flush to process the association response in
4196 * the suspend, resulting in a successful association just before it
4197 * tries to remove the interface from the driver, which now though
4198 * has a channel context assigned ... this results in issues.
4200 * To work around this (for now) simply deauth here again if we're
4203 if (ifmgd->associated && !sdata->local->wowlan) {
4205 struct cfg80211_deauth_request req = {
4206 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4210 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4211 ieee80211_mgd_deauth(sdata, &req);
4214 sdata_unlock(sdata);
4217 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4219 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4222 if (!ifmgd->associated) {
4223 sdata_unlock(sdata);
4227 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4228 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4229 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4230 ieee80211_sta_connection_lost(sdata,
4231 ifmgd->associated->bssid,
4232 WLAN_REASON_UNSPECIFIED,
4234 sdata_unlock(sdata);
4237 sdata_unlock(sdata);
4241 /* interface setup */
4242 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4244 struct ieee80211_if_managed *ifmgd;
4246 ifmgd = &sdata->u.mgd;
4247 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4248 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4249 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4250 ieee80211_beacon_connection_loss_work);
4251 INIT_WORK(&ifmgd->csa_connection_drop_work,
4252 ieee80211_csa_connection_drop_work);
4253 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4254 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4255 ieee80211_tdls_peer_del_work);
4256 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
4257 (unsigned long) sdata);
4258 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
4259 (unsigned long) sdata);
4260 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
4261 (unsigned long) sdata);
4262 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
4263 (unsigned long) sdata);
4264 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4265 ieee80211_sta_handle_tspec_ac_params_wk);
4268 ifmgd->powersave = sdata->wdev.ps;
4269 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4270 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4271 ifmgd->p2p_noa_index = -1;
4273 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4274 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4276 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4278 /* Setup TDLS data */
4279 spin_lock_init(&ifmgd->teardown_lock);
4280 ifmgd->teardown_skb = NULL;
4281 ifmgd->orig_teardown_skb = NULL;
4284 /* scan finished notification */
4285 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4287 struct ieee80211_sub_if_data *sdata;
4289 /* Restart STA timers */
4291 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4292 if (ieee80211_sdata_running(sdata))
4293 ieee80211_restart_sta_timer(sdata);
4298 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4299 struct cfg80211_bss *cbss)
4301 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4302 const u8 *ht_cap_ie, *vht_cap_ie;
4303 const struct ieee80211_ht_cap *ht_cap;
4304 const struct ieee80211_vht_cap *vht_cap;
4307 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4310 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4311 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4312 ht_cap = (void *)(ht_cap_ie + 2);
4313 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4315 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4316 * "Tx Unequal Modulation Supported" fields.
4320 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4323 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4324 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4328 vht_cap = (void *)(vht_cap_ie + 2);
4329 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4330 for (nss = 8; nss > 0; nss--) {
4331 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4332 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4335 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4336 chains = max(chains, nss);
4342 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4343 struct cfg80211_bss *cbss)
4345 struct ieee80211_local *local = sdata->local;
4346 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4347 const struct ieee80211_ht_cap *ht_cap = NULL;
4348 const struct ieee80211_ht_operation *ht_oper = NULL;
4349 const struct ieee80211_vht_operation *vht_oper = NULL;
4350 struct ieee80211_supported_band *sband;
4351 struct cfg80211_chan_def chandef;
4356 sband = local->hw.wiphy->bands[cbss->channel->band];
4358 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4359 IEEE80211_STA_DISABLE_80P80MHZ |
4360 IEEE80211_STA_DISABLE_160MHZ);
4364 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4365 sband->ht_cap.ht_supported) {
4366 const u8 *ht_oper_ie, *ht_cap_ie;
4368 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
4369 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4370 ht_oper = (void *)(ht_oper_ie + 2);
4372 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4373 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4374 ht_cap = (void *)(ht_cap_ie + 2);
4377 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4382 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4383 sband->vht_cap.vht_supported) {
4384 const u8 *vht_oper_ie, *vht_cap;
4386 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4387 WLAN_EID_VHT_OPERATION);
4388 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4389 vht_oper = (void *)(vht_oper_ie + 2);
4390 if (vht_oper && !ht_oper) {
4393 "AP advertised VHT without HT, disabling both\n");
4394 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4395 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4398 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4399 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4400 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4405 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4407 for (i = 0; i < sband->n_channels; i++) {
4408 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4409 IEEE80211_CHAN_NO_80MHZ))
4417 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4419 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4421 ht_cap, ht_oper, vht_oper,
4424 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4429 /* will change later if needed */
4430 sdata->smps_mode = IEEE80211_SMPS_OFF;
4432 mutex_lock(&local->mtx);
4434 * If this fails (possibly due to channel context sharing
4435 * on incompatible channels, e.g. 80+80 and 160 sharing the
4436 * same control channel) try to use a smaller bandwidth.
4438 ret = ieee80211_vif_use_channel(sdata, &chandef,
4439 IEEE80211_CHANCTX_SHARED);
4441 /* don't downgrade for 5 and 10 MHz channels, though. */
4442 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4443 chandef.width == NL80211_CHAN_WIDTH_10)
4446 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4447 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
4448 ret = ieee80211_vif_use_channel(sdata, &chandef,
4449 IEEE80211_CHANCTX_SHARED);
4452 mutex_unlock(&local->mtx);
4456 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
4457 struct cfg80211_bss *cbss, bool assoc,
4460 struct ieee80211_local *local = sdata->local;
4461 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4462 struct ieee80211_bss *bss = (void *)cbss->priv;
4463 struct sta_info *new_sta = NULL;
4464 struct ieee80211_supported_band *sband;
4465 bool have_sta = false;
4468 sband = local->hw.wiphy->bands[cbss->channel->band];
4470 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4473 /* If a reconfig is happening, bail out */
4474 if (local->in_reconfig)
4479 have_sta = sta_info_get(sdata, cbss->bssid);
4484 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4490 * Set up the information for the new channel before setting the
4491 * new channel. We can't - completely race-free - change the basic
4492 * rates bitmap and the channel (sband) that it refers to, but if
4493 * we set it up before we at least avoid calling into the driver's
4494 * bss_info_changed() method with invalid information (since we do
4495 * call that from changing the channel - only for IDLE and perhaps
4496 * some others, but ...).
4498 * So to avoid that, just set up all the new information before the
4499 * channel, but tell the driver to apply it only afterwards, since
4500 * it might need the new channel for that.
4503 u32 rates = 0, basic_rates = 0;
4504 bool have_higher_than_11mbit = false;
4505 int min_rate = INT_MAX, min_rate_index = -1;
4506 const struct cfg80211_bss_ies *ies;
4507 int shift = ieee80211_vif_get_shift(&sdata->vif);
4509 ieee80211_get_rates(sband, bss->supp_rates,
4510 bss->supp_rates_len,
4511 &rates, &basic_rates,
4512 &have_higher_than_11mbit,
4513 &min_rate, &min_rate_index,
4517 * This used to be a workaround for basic rates missing
4518 * in the association response frame. Now that we no
4519 * longer use the basic rates from there, it probably
4520 * doesn't happen any more, but keep the workaround so
4521 * in case some *other* APs are buggy in different ways
4522 * we can connect -- with a warning.
4524 if (!basic_rates && min_rate_index >= 0) {
4526 "No basic rates, using min rate instead\n");
4527 basic_rates = BIT(min_rate_index);
4530 new_sta->sta.supp_rates[cbss->channel->band] = rates;
4531 sdata->vif.bss_conf.basic_rates = basic_rates;
4533 /* cf. IEEE 802.11 9.2.12 */
4534 if (cbss->channel->band == NL80211_BAND_2GHZ &&
4535 have_higher_than_11mbit)
4536 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4538 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4540 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4542 /* set timing information */
4543 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
4545 ies = rcu_dereference(cbss->beacon_ies);
4549 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4550 sdata->vif.bss_conf.sync_device_ts =
4551 bss->device_ts_beacon;
4552 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4553 ies->data, ies->len);
4554 if (tim_ie && tim_ie[1] >= 2)
4555 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
4557 sdata->vif.bss_conf.sync_dtim_count = 0;
4558 } else if (!ieee80211_hw_check(&sdata->local->hw,
4559 TIMING_BEACON_ONLY)) {
4560 ies = rcu_dereference(cbss->proberesp_ies);
4561 /* must be non-NULL since beacon IEs were NULL */
4562 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4563 sdata->vif.bss_conf.sync_device_ts =
4564 bss->device_ts_presp;
4565 sdata->vif.bss_conf.sync_dtim_count = 0;
4567 sdata->vif.bss_conf.sync_tsf = 0;
4568 sdata->vif.bss_conf.sync_device_ts = 0;
4569 sdata->vif.bss_conf.sync_dtim_count = 0;
4574 if (new_sta || override) {
4575 err = ieee80211_prep_channel(sdata, cbss);
4578 sta_info_free(local, new_sta);
4585 * tell driver about BSSID, basic rates and timing
4586 * this was set up above, before setting the channel
4588 ieee80211_bss_info_change_notify(sdata,
4589 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4590 BSS_CHANGED_BEACON_INT);
4593 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
4595 err = sta_info_insert(new_sta);
4599 "failed to insert STA entry for the AP (error %d)\n",
4604 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
4606 /* Cancel scan to ensure that nothing interferes with connection */
4607 if (local->scanning)
4608 ieee80211_scan_cancel(local);
4614 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4615 struct cfg80211_auth_request *req)
4617 struct ieee80211_local *local = sdata->local;
4618 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4619 struct ieee80211_mgd_auth_data *auth_data;
4623 /* prepare auth data structure */
4625 switch (req->auth_type) {
4626 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4627 auth_alg = WLAN_AUTH_OPEN;
4629 case NL80211_AUTHTYPE_SHARED_KEY:
4630 if (IS_ERR(local->wep_tx_tfm))
4632 auth_alg = WLAN_AUTH_SHARED_KEY;
4634 case NL80211_AUTHTYPE_FT:
4635 auth_alg = WLAN_AUTH_FT;
4637 case NL80211_AUTHTYPE_NETWORK_EAP:
4638 auth_alg = WLAN_AUTH_LEAP;
4640 case NL80211_AUTHTYPE_SAE:
4641 auth_alg = WLAN_AUTH_SAE;
4643 case NL80211_AUTHTYPE_FILS_SK:
4644 auth_alg = WLAN_AUTH_FILS_SK;
4646 case NL80211_AUTHTYPE_FILS_SK_PFS:
4647 auth_alg = WLAN_AUTH_FILS_SK_PFS;
4649 case NL80211_AUTHTYPE_FILS_PK:
4650 auth_alg = WLAN_AUTH_FILS_PK;
4656 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
4657 req->ie_len, GFP_KERNEL);
4661 auth_data->bss = req->bss;
4663 if (req->auth_data_len >= 4) {
4664 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4665 __le16 *pos = (__le16 *) req->auth_data;
4667 auth_data->sae_trans = le16_to_cpu(pos[0]);
4668 auth_data->sae_status = le16_to_cpu(pos[1]);
4670 memcpy(auth_data->data, req->auth_data + 4,
4671 req->auth_data_len - 4);
4672 auth_data->data_len += req->auth_data_len - 4;
4675 if (req->ie && req->ie_len) {
4676 memcpy(&auth_data->data[auth_data->data_len],
4677 req->ie, req->ie_len);
4678 auth_data->data_len += req->ie_len;
4681 if (req->key && req->key_len) {
4682 auth_data->key_len = req->key_len;
4683 auth_data->key_idx = req->key_idx;
4684 memcpy(auth_data->key, req->key, req->key_len);
4687 auth_data->algorithm = auth_alg;
4689 /* try to authenticate/probe */
4691 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4692 ifmgd->assoc_data) {
4697 if (ifmgd->auth_data)
4698 ieee80211_destroy_auth_data(sdata, false);
4700 /* prep auth_data so we don't go into idle on disassoc */
4701 ifmgd->auth_data = auth_data;
4703 if (ifmgd->associated) {
4704 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4707 "disconnect from AP %pM for new auth to %pM\n",
4708 ifmgd->associated->bssid, req->bss->bssid);
4709 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4710 WLAN_REASON_UNSPECIFIED,
4713 ieee80211_report_disconnect(sdata, frame_buf,
4714 sizeof(frame_buf), true,
4715 WLAN_REASON_UNSPECIFIED);
4718 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
4720 err = ieee80211_prep_connection(sdata, req->bss, false, false);
4724 err = ieee80211_auth(sdata);
4726 sta_info_destroy_addr(sdata, req->bss->bssid);
4730 /* hold our own reference */
4731 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
4735 eth_zero_addr(ifmgd->bssid);
4736 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
4737 ifmgd->auth_data = NULL;
4738 mutex_lock(&sdata->local->mtx);
4739 ieee80211_vif_release_channel(sdata);
4740 mutex_unlock(&sdata->local->mtx);
4746 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4747 struct cfg80211_assoc_request *req)
4749 struct ieee80211_local *local = sdata->local;
4750 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4751 struct ieee80211_bss *bss = (void *)req->bss->priv;
4752 struct ieee80211_mgd_assoc_data *assoc_data;
4753 const struct cfg80211_bss_ies *beacon_ies;
4754 struct ieee80211_supported_band *sband;
4755 const u8 *ssidie, *ht_ie, *vht_ie;
4757 bool override = false;
4759 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
4764 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4765 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
4770 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
4771 assoc_data->ssid_len = ssidie[1];
4774 if (ifmgd->associated) {
4775 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4778 "disconnect from AP %pM for new assoc to %pM\n",
4779 ifmgd->associated->bssid, req->bss->bssid);
4780 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4781 WLAN_REASON_UNSPECIFIED,
4784 ieee80211_report_disconnect(sdata, frame_buf,
4785 sizeof(frame_buf), true,
4786 WLAN_REASON_UNSPECIFIED);
4789 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
4794 if (ifmgd->assoc_data) {
4799 if (ifmgd->auth_data) {
4802 /* keep sta info, bssid if matching */
4803 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
4804 ieee80211_destroy_auth_data(sdata, match);
4807 /* prepare assoc data */
4809 ifmgd->beacon_crc_valid = false;
4811 assoc_data->wmm = bss->wmm_used &&
4812 (local->hw.queues >= IEEE80211_NUM_ACS);
4815 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4816 * We still associate in non-HT mode (11a/b/g) if any one of these
4817 * ciphers is configured as pairwise.
4818 * We can set this to true for non-11n hardware, that'll be checked
4819 * separately along with the peer capabilities.
4821 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
4822 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
4823 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
4824 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
4825 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4826 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4827 netdev_info(sdata->dev,
4828 "disabling HT/VHT due to WEP/TKIP use\n");
4832 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4833 sband = local->hw.wiphy->bands[req->bss->channel->band];
4834 if (!sband->ht_cap.ht_supported ||
4835 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
4836 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
4837 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4838 if (!bss->wmm_used &&
4839 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
4840 netdev_info(sdata->dev,
4841 "disabling HT as WMM/QoS is not supported by the AP\n");
4844 /* disable VHT if we don't support it or the AP doesn't use WMM */
4845 if (!sband->vht_cap.vht_supported ||
4846 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
4847 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
4848 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4849 if (!bss->wmm_used &&
4850 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
4851 netdev_info(sdata->dev,
4852 "disabling VHT as WMM/QoS is not supported by the AP\n");
4855 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
4856 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4857 sizeof(ifmgd->ht_capa_mask));
4859 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4860 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4861 sizeof(ifmgd->vht_capa_mask));
4863 if (req->ie && req->ie_len) {
4864 memcpy(assoc_data->ie, req->ie, req->ie_len);
4865 assoc_data->ie_len = req->ie_len;
4868 if (req->fils_kek) {
4869 /* should already be checked in cfg80211 - so warn */
4870 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
4874 memcpy(assoc_data->fils_kek, req->fils_kek,
4876 assoc_data->fils_kek_len = req->fils_kek_len;
4879 if (req->fils_nonces)
4880 memcpy(assoc_data->fils_nonces, req->fils_nonces,
4881 2 * FILS_NONCE_LEN);
4883 assoc_data->bss = req->bss;
4885 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
4886 if (ifmgd->powersave)
4887 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
4889 sdata->smps_mode = IEEE80211_SMPS_OFF;
4891 sdata->smps_mode = ifmgd->req_smps;
4893 assoc_data->capability = req->bss->capability;
4894 assoc_data->supp_rates = bss->supp_rates;
4895 assoc_data->supp_rates_len = bss->supp_rates_len;
4898 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
4899 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
4900 assoc_data->ap_ht_param =
4901 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
4903 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4904 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
4905 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
4906 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
4907 sizeof(struct ieee80211_vht_cap));
4909 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4912 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
4913 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
4914 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
4915 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
4917 if (bss->wmm_used && bss->uapsd_supported &&
4918 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
4919 assoc_data->uapsd = true;
4920 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4922 assoc_data->uapsd = false;
4923 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
4926 if (req->prev_bssid)
4927 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
4930 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
4931 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4933 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4934 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4937 if (req->flags & ASSOC_REQ_USE_RRM)
4938 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
4940 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
4942 if (req->crypto.control_port)
4943 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4945 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4947 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4948 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
4949 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
4952 /* kick off associate process */
4954 ifmgd->assoc_data = assoc_data;
4955 ifmgd->dtim_period = 0;
4956 ifmgd->have_beacon = false;
4958 /* override HT/VHT configuration only if the AP and we support it */
4959 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
4960 struct ieee80211_sta_ht_cap sta_ht_cap;
4962 if (req->flags & ASSOC_REQ_DISABLE_HT)
4965 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
4966 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
4968 /* check for 40 MHz disable override */
4969 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
4970 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
4971 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
4974 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4975 req->flags & ASSOC_REQ_DISABLE_VHT)
4979 if (req->flags & ASSOC_REQ_DISABLE_HT) {
4980 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4981 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4984 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4985 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4987 err = ieee80211_prep_connection(sdata, req->bss, true, override);
4992 beacon_ies = rcu_dereference(req->bss->beacon_ies);
4994 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
4997 * Wait up to one beacon interval ...
4998 * should this be more if we miss one?
5000 sdata_info(sdata, "waiting for beacon from %pM\n",
5002 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5003 assoc_data->timeout_started = true;
5004 assoc_data->need_beacon = true;
5005 } else if (beacon_ies) {
5006 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
5011 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
5012 const struct ieee80211_tim_ie *tim;
5013 tim = (void *)(tim_ie + 2);
5014 ifmgd->dtim_period = tim->dtim_period;
5015 dtim_count = tim->dtim_count;
5017 ifmgd->have_beacon = true;
5018 assoc_data->timeout = jiffies;
5019 assoc_data->timeout_started = true;
5021 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5022 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5023 sdata->vif.bss_conf.sync_device_ts =
5024 bss->device_ts_beacon;
5025 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5028 assoc_data->timeout = jiffies;
5029 assoc_data->timeout_started = true;
5033 run_again(sdata, assoc_data->timeout);
5035 if (bss->corrupt_data) {
5036 char *corrupt_type = "data";
5037 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5038 if (bss->corrupt_data &
5039 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5040 corrupt_type = "beacon and probe response";
5042 corrupt_type = "beacon";
5043 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5044 corrupt_type = "probe response";
5045 sdata_info(sdata, "associating with AP with corrupt %s\n",
5051 eth_zero_addr(ifmgd->bssid);
5052 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5053 ifmgd->assoc_data = NULL;
5059 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5060 struct cfg80211_deauth_request *req)
5062 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5063 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5064 bool tx = !req->local_state_change;
5066 if (ifmgd->auth_data &&
5067 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5069 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5070 req->bssid, req->reason_code,
5071 ieee80211_get_reason_code_string(req->reason_code));
5073 drv_mgd_prepare_tx(sdata->local, sdata);
5074 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5075 IEEE80211_STYPE_DEAUTH,
5076 req->reason_code, tx,
5078 ieee80211_destroy_auth_data(sdata, false);
5079 ieee80211_report_disconnect(sdata, frame_buf,
5080 sizeof(frame_buf), true,
5086 if (ifmgd->assoc_data &&
5087 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5089 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5090 req->bssid, req->reason_code,
5091 ieee80211_get_reason_code_string(req->reason_code));
5093 drv_mgd_prepare_tx(sdata->local, sdata);
5094 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5095 IEEE80211_STYPE_DEAUTH,
5096 req->reason_code, tx,
5098 ieee80211_destroy_assoc_data(sdata, false, true);
5099 ieee80211_report_disconnect(sdata, frame_buf,
5100 sizeof(frame_buf), true,
5105 if (ifmgd->associated &&
5106 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5108 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5109 req->bssid, req->reason_code,
5110 ieee80211_get_reason_code_string(req->reason_code));
5112 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5113 req->reason_code, tx, frame_buf);
5114 ieee80211_report_disconnect(sdata, frame_buf,
5115 sizeof(frame_buf), true,
5123 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5124 struct cfg80211_disassoc_request *req)
5126 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5128 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5131 * cfg80211 should catch this ... but it's racy since
5132 * we can receive a disassoc frame, process it, hand it
5133 * to cfg80211 while that's in a locked section already
5134 * trying to tell us that the user wants to disconnect.
5136 if (ifmgd->associated != req->bss)
5140 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5141 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5143 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5144 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5145 req->reason_code, !req->local_state_change,
5148 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5154 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5156 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5159 * Make sure some work items will not run after this,
5160 * they will not do anything but might not have been
5161 * cancelled when disconnecting.
5163 cancel_work_sync(&ifmgd->monitor_work);
5164 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5165 cancel_work_sync(&ifmgd->request_smps_work);
5166 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5167 cancel_work_sync(&ifmgd->chswitch_work);
5168 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5171 if (ifmgd->assoc_data) {
5172 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5173 ieee80211_destroy_assoc_data(sdata, false, false);
5174 cfg80211_assoc_timeout(sdata->dev, bss);
5176 if (ifmgd->auth_data)
5177 ieee80211_destroy_auth_data(sdata, false);
5178 spin_lock_bh(&ifmgd->teardown_lock);
5179 if (ifmgd->teardown_skb) {
5180 kfree_skb(ifmgd->teardown_skb);
5181 ifmgd->teardown_skb = NULL;
5182 ifmgd->orig_teardown_skb = NULL;
5184 spin_unlock_bh(&ifmgd->teardown_lock);
5185 del_timer_sync(&ifmgd->timer);
5186 sdata_unlock(sdata);
5189 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5190 enum nl80211_cqm_rssi_threshold_event rssi_event,
5194 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5196 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
5198 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
5200 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
5202 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5204 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5206 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5208 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5210 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);