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>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/delay.h>
15 #include <linux/if_ether.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_arp.h>
18 #include <linux/etherdevice.h>
19 #include <linux/moduleparam.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/pm_qos.h>
22 #include <linux/crc32.h>
23 #include <linux/slab.h>
24 #include <linux/export.h>
25 #include <net/mac80211.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
33 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
34 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
35 #define IEEE80211_AUTH_MAX_TRIES 3
36 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
37 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
38 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
39 #define IEEE80211_ASSOC_MAX_TRIES 3
41 static int max_nullfunc_tries = 2;
42 module_param(max_nullfunc_tries, int, 0644);
43 MODULE_PARM_DESC(max_nullfunc_tries,
44 "Maximum nullfunc tx tries before disconnecting (reason 4).");
46 static int max_probe_tries = 5;
47 module_param(max_probe_tries, int, 0644);
48 MODULE_PARM_DESC(max_probe_tries,
49 "Maximum probe tries before disconnecting (reason 4).");
52 * Beacon loss timeout is calculated as N frames times the
53 * advertised beacon interval. This may need to be somewhat
54 * higher than what hardware might detect to account for
55 * delays in the host processing frames. But since we also
56 * probe on beacon miss before declaring the connection lost
57 * default to what we want.
59 #define IEEE80211_BEACON_LOSS_COUNT 7
62 * Time the connection can be idle before we probe
63 * it to see if we can still talk to the AP.
65 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
67 * Time we wait for a probe response after sending
68 * a probe request because of beacon loss or for
69 * checking the connection still works.
71 static int probe_wait_ms = 500;
72 module_param(probe_wait_ms, int, 0644);
73 MODULE_PARM_DESC(probe_wait_ms,
74 "Maximum time(ms) to wait for probe response"
75 " before disconnecting (reason 4).");
78 * Weight given to the latest Beacon frame when calculating average signal
79 * strength for Beacon frames received in the current BSS. This must be
82 #define IEEE80211_SIGNAL_AVE_WEIGHT 3
85 * How many Beacon frames need to have been used in average signal strength
86 * before starting to indicate signal change events.
88 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
91 * All cfg80211 functions have to be called outside a locked
92 * section so that they can acquire a lock themselves... This
93 * is much simpler than queuing up things in cfg80211, but we
94 * do need some indirection for that here.
97 /* no action required */
100 /* caller must call cfg80211_send_deauth() */
101 RX_MGMT_CFG80211_DEAUTH,
103 /* caller must call cfg80211_send_disassoc() */
104 RX_MGMT_CFG80211_DISASSOC,
106 /* caller must call cfg80211_send_rx_auth() */
107 RX_MGMT_CFG80211_RX_AUTH,
109 /* caller must call cfg80211_send_rx_assoc() */
110 RX_MGMT_CFG80211_RX_ASSOC,
112 /* caller must call cfg80211_send_assoc_timeout() */
113 RX_MGMT_CFG80211_ASSOC_TIMEOUT,
115 /* used when a processed beacon causes a deauth */
116 RX_MGMT_CFG80211_TX_DEAUTH,
120 static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
122 lockdep_assert_held(&ifmgd->mtx);
126 * We can have multiple work items (and connection probing)
127 * scheduling this timer, but we need to take care to only
128 * reschedule it when it should fire _earlier_ than it was
129 * asked for before, or if it's not pending right now. This
130 * function ensures that. Note that it then is required to
131 * run this function for all timeouts after the first one
132 * has happened -- the work that runs from this timer will
135 static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout)
137 ASSERT_MGD_MTX(ifmgd);
139 if (!timer_pending(&ifmgd->timer) ||
140 time_before(timeout, ifmgd->timer.expires))
141 mod_timer(&ifmgd->timer, timeout);
144 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
146 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
149 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
152 mod_timer(&sdata->u.mgd.bcn_mon_timer,
153 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
156 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
158 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
160 if (unlikely(!sdata->u.mgd.associated))
163 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
166 mod_timer(&sdata->u.mgd.conn_mon_timer,
167 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
169 ifmgd->probe_send_count = 0;
172 static int ecw2cw(int ecw)
174 return (1 << ecw) - 1;
177 static u32 chandef_downgrade(struct cfg80211_chan_def *c)
183 case NL80211_CHAN_WIDTH_20:
184 c->width = NL80211_CHAN_WIDTH_20_NOHT;
185 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
187 case NL80211_CHAN_WIDTH_40:
188 c->width = NL80211_CHAN_WIDTH_20;
189 c->center_freq1 = c->chan->center_freq;
190 ret = IEEE80211_STA_DISABLE_40MHZ |
191 IEEE80211_STA_DISABLE_VHT;
193 case NL80211_CHAN_WIDTH_80:
194 tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
198 c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
199 c->width = NL80211_CHAN_WIDTH_40;
200 ret = IEEE80211_STA_DISABLE_VHT;
202 case NL80211_CHAN_WIDTH_80P80:
204 c->width = NL80211_CHAN_WIDTH_80;
205 ret = IEEE80211_STA_DISABLE_80P80MHZ |
206 IEEE80211_STA_DISABLE_160MHZ;
208 case NL80211_CHAN_WIDTH_160:
210 tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
213 c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
214 c->width = NL80211_CHAN_WIDTH_80;
215 ret = IEEE80211_STA_DISABLE_80P80MHZ |
216 IEEE80211_STA_DISABLE_160MHZ;
219 case NL80211_CHAN_WIDTH_20_NOHT:
221 c->width = NL80211_CHAN_WIDTH_20_NOHT;
222 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
226 WARN_ON_ONCE(!cfg80211_chandef_valid(c));
232 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
233 struct ieee80211_supported_band *sband,
234 struct ieee80211_channel *channel,
235 const struct ieee80211_ht_operation *ht_oper,
236 const struct ieee80211_vht_operation *vht_oper,
237 struct cfg80211_chan_def *chandef, bool verbose)
239 struct cfg80211_chan_def vht_chandef;
242 chandef->chan = channel;
243 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
244 chandef->center_freq1 = channel->center_freq;
245 chandef->center_freq2 = 0;
247 if (!ht_oper || !sband->ht_cap.ht_supported) {
248 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
252 chandef->width = NL80211_CHAN_WIDTH_20;
254 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
256 /* check that channel matches the right operating channel */
257 if (channel->center_freq != ht_cfreq) {
259 * It's possible that some APs are confused here;
260 * Netgear WNDR3700 sometimes reports 4 higher than
261 * the actual channel in association responses, but
262 * since we look at probe response/beacon data here
267 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
268 channel->center_freq, ht_cfreq,
269 ht_oper->primary_chan, channel->band);
270 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
274 /* check 40 MHz support, if we have it */
275 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
276 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
277 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
278 chandef->width = NL80211_CHAN_WIDTH_40;
279 chandef->center_freq1 += 10;
281 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
282 chandef->width = NL80211_CHAN_WIDTH_40;
283 chandef->center_freq1 -= 10;
287 /* 40 MHz (and 80 MHz) must be supported for VHT */
288 ret = IEEE80211_STA_DISABLE_VHT;
292 if (!vht_oper || !sband->vht_cap.vht_supported) {
293 ret = IEEE80211_STA_DISABLE_VHT;
297 vht_chandef.chan = channel;
298 vht_chandef.center_freq1 =
299 ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
301 vht_chandef.center_freq2 = 0;
303 if (vht_oper->center_freq_seg2_idx)
304 vht_chandef.center_freq2 =
305 ieee80211_channel_to_frequency(
306 vht_oper->center_freq_seg2_idx,
309 switch (vht_oper->chan_width) {
310 case IEEE80211_VHT_CHANWIDTH_USE_HT:
311 vht_chandef.width = chandef->width;
313 case IEEE80211_VHT_CHANWIDTH_80MHZ:
314 vht_chandef.width = NL80211_CHAN_WIDTH_80;
316 case IEEE80211_VHT_CHANWIDTH_160MHZ:
317 vht_chandef.width = NL80211_CHAN_WIDTH_160;
319 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
320 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
325 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
326 vht_oper->chan_width);
327 ret = IEEE80211_STA_DISABLE_VHT;
331 if (!cfg80211_chandef_valid(&vht_chandef)) {
334 "AP VHT information is invalid, disable VHT\n");
335 ret = IEEE80211_STA_DISABLE_VHT;
339 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
344 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
347 "AP VHT information doesn't match HT, disable VHT\n");
348 ret = IEEE80211_STA_DISABLE_VHT;
352 *chandef = vht_chandef;
357 /* don't print the message below for VHT mismatch if VHT is disabled */
358 if (ret & IEEE80211_STA_DISABLE_VHT)
359 vht_chandef = *chandef;
361 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
362 IEEE80211_CHAN_DISABLED)) {
363 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
364 ret = IEEE80211_STA_DISABLE_HT |
365 IEEE80211_STA_DISABLE_VHT;
369 ret |= chandef_downgrade(chandef);
372 if (chandef->width != vht_chandef.width && verbose)
374 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
376 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
380 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
381 struct sta_info *sta,
382 const struct ieee80211_ht_operation *ht_oper,
383 const struct ieee80211_vht_operation *vht_oper,
384 const u8 *bssid, u32 *changed)
386 struct ieee80211_local *local = sdata->local;
387 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
388 struct ieee80211_supported_band *sband;
389 struct ieee80211_channel *chan;
390 struct cfg80211_chan_def chandef;
393 enum ieee80211_sta_rx_bandwidth new_sta_bw;
396 /* if HT was/is disabled, don't track any bandwidth changes */
397 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
400 /* don't check VHT if we associated as non-VHT station */
401 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
404 if (WARN_ON_ONCE(!sta))
407 chan = sdata->vif.bss_conf.chandef.chan;
408 sband = local->hw.wiphy->bands[chan->band];
410 /* calculate new channel (type) based on HT/VHT operation IEs */
411 flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
412 vht_oper, &chandef, false);
415 * Downgrade the new channel if we associated with restricted
416 * capabilities. For example, if we associated as a 20 MHz STA
417 * to a 40 MHz AP (due to regulatory, capabilities or config
418 * reasons) then switching to a 40 MHz channel now won't do us
419 * any good -- we couldn't use it with the AP.
421 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
422 chandef.width == NL80211_CHAN_WIDTH_80P80)
423 flags |= chandef_downgrade(&chandef);
424 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
425 chandef.width == NL80211_CHAN_WIDTH_160)
426 flags |= chandef_downgrade(&chandef);
427 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
428 chandef.width > NL80211_CHAN_WIDTH_20)
429 flags |= chandef_downgrade(&chandef);
431 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
435 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
436 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
437 chandef.center_freq1, chandef.center_freq2);
439 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
440 IEEE80211_STA_DISABLE_VHT |
441 IEEE80211_STA_DISABLE_40MHZ |
442 IEEE80211_STA_DISABLE_80P80MHZ |
443 IEEE80211_STA_DISABLE_160MHZ)) ||
444 !cfg80211_chandef_valid(&chandef)) {
446 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
451 switch (chandef.width) {
452 case NL80211_CHAN_WIDTH_20_NOHT:
453 case NL80211_CHAN_WIDTH_20:
454 new_sta_bw = IEEE80211_STA_RX_BW_20;
456 case NL80211_CHAN_WIDTH_40:
457 new_sta_bw = IEEE80211_STA_RX_BW_40;
459 case NL80211_CHAN_WIDTH_80:
460 new_sta_bw = IEEE80211_STA_RX_BW_80;
462 case NL80211_CHAN_WIDTH_80P80:
463 case NL80211_CHAN_WIDTH_160:
464 new_sta_bw = IEEE80211_STA_RX_BW_160;
470 if (new_sta_bw > sta->cur_max_bandwidth)
471 new_sta_bw = sta->cur_max_bandwidth;
473 if (new_sta_bw < sta->sta.bandwidth) {
474 sta->sta.bandwidth = new_sta_bw;
475 rate_control_rate_update(local, sband, sta,
476 IEEE80211_RC_BW_CHANGED);
479 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
482 "AP %pM changed bandwidth to incompatible one - disconnect\n",
487 if (new_sta_bw > sta->sta.bandwidth) {
488 sta->sta.bandwidth = new_sta_bw;
489 rate_control_rate_update(local, sband, sta,
490 IEEE80211_RC_BW_CHANGED);
493 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
495 /* if bss configuration changed store the new one */
496 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
497 *changed |= BSS_CHANGED_HT;
498 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
504 /* frame sending functions */
506 static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
507 struct ieee80211_supported_band *sband,
513 for (i = 0; i < supp_rates_len; i++) {
514 int rate = (supp_rates[i] & 0x7F) * 5;
516 for (j = 0; j < sband->n_bitrates; j++)
517 if (sband->bitrates[j].bitrate == rate) {
527 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
528 struct sk_buff *skb, u8 ap_ht_param,
529 struct ieee80211_supported_band *sband,
530 struct ieee80211_channel *channel,
531 enum ieee80211_smps_mode smps)
534 u32 flags = channel->flags;
536 struct ieee80211_sta_ht_cap ht_cap;
538 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
540 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
541 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
543 /* determine capability flags */
546 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
547 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
548 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
549 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
550 cap &= ~IEEE80211_HT_CAP_SGI_40;
553 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
554 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
555 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
556 cap &= ~IEEE80211_HT_CAP_SGI_40;
562 * If 40 MHz was disabled associate as though we weren't
563 * capable of 40 MHz -- some broken APs will never fall
564 * back to trying to transmit in 20 MHz.
566 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
567 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
568 cap &= ~IEEE80211_HT_CAP_SGI_40;
571 /* set SM PS mode properly */
572 cap &= ~IEEE80211_HT_CAP_SM_PS;
574 case IEEE80211_SMPS_AUTOMATIC:
575 case IEEE80211_SMPS_NUM_MODES:
577 case IEEE80211_SMPS_OFF:
578 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
579 IEEE80211_HT_CAP_SM_PS_SHIFT;
581 case IEEE80211_SMPS_STATIC:
582 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
583 IEEE80211_HT_CAP_SM_PS_SHIFT;
585 case IEEE80211_SMPS_DYNAMIC:
586 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
587 IEEE80211_HT_CAP_SM_PS_SHIFT;
591 /* reserve and fill IE */
592 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
593 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
596 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
598 struct ieee80211_supported_band *sband,
599 struct ieee80211_vht_cap *ap_vht_cap)
603 struct ieee80211_sta_vht_cap vht_cap;
606 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
608 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
609 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
611 /* determine capability flags */
614 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
615 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
616 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
619 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
620 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
621 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
625 * Some APs apparently get confused if our capabilities are better
626 * than theirs, so restrict what we advertise in the assoc request.
628 if (!(ap_vht_cap->vht_cap_info &
629 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
630 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
632 if (!(ap_vht_cap->vht_cap_info &
633 cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
634 cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
635 IEEE80211_VHT_CAP_RXSTBC_3 |
636 IEEE80211_VHT_CAP_RXSTBC_4);
638 for (i = 0; i < 8; i++) {
640 u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
643 ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
645 our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
648 if (our_mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
653 if (our_mcs <= ap_mcs)
656 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
657 vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
658 vht_cap.vht_mcs.rx_mcs_map |=
659 cpu_to_le16(ap_mcs << shift);
663 /* reserve and fill IE */
664 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
665 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
668 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
670 struct ieee80211_local *local = sdata->local;
671 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
672 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
674 struct ieee80211_mgmt *mgmt;
676 size_t offset = 0, noffset;
677 int i, count, rates_len, supp_rates_len;
679 struct ieee80211_supported_band *sband;
680 struct ieee80211_chanctx_conf *chanctx_conf;
681 struct ieee80211_channel *chan;
684 lockdep_assert_held(&ifmgd->mtx);
687 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
688 if (WARN_ON(!chanctx_conf)) {
692 chan = chanctx_conf->def.chan;
694 sband = local->hw.wiphy->bands[chan->band];
696 if (assoc_data->supp_rates_len) {
698 * Get all rates supported by the device and the AP as
699 * some APs don't like getting a superset of their rates
700 * in the association request (e.g. D-Link DAP 1353 in
703 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates,
704 assoc_data->supp_rates_len,
708 * In case AP not provide any supported rates information
709 * before association, we send information element(s) with
710 * all rates that we support.
713 rates_len = sband->n_bitrates;
716 skb = alloc_skb(local->hw.extra_tx_headroom +
717 sizeof(*mgmt) + /* bit too much but doesn't matter */
718 2 + assoc_data->ssid_len + /* SSID */
719 4 + rates_len + /* (extended) rates */
720 4 + /* power capability */
721 2 + 2 * sband->n_channels + /* supported channels */
722 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
723 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
724 assoc_data->ie_len + /* extra IEs */
730 skb_reserve(skb, local->hw.extra_tx_headroom);
732 capab = WLAN_CAPABILITY_ESS;
734 if (sband->band == IEEE80211_BAND_2GHZ) {
735 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
736 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
737 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
738 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
741 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
742 capab |= WLAN_CAPABILITY_PRIVACY;
744 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
745 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
746 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
748 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
750 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
751 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
752 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
754 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
756 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
757 IEEE80211_STYPE_REASSOC_REQ);
758 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
759 mgmt->u.reassoc_req.listen_interval =
760 cpu_to_le16(local->hw.conf.listen_interval);
761 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
765 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
766 IEEE80211_STYPE_ASSOC_REQ);
767 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
768 mgmt->u.assoc_req.listen_interval =
769 cpu_to_le16(local->hw.conf.listen_interval);
773 pos = skb_put(skb, 2 + assoc_data->ssid_len);
774 *pos++ = WLAN_EID_SSID;
775 *pos++ = assoc_data->ssid_len;
776 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
778 /* add all rates which were marked to be used above */
779 supp_rates_len = rates_len;
780 if (supp_rates_len > 8)
783 pos = skb_put(skb, supp_rates_len + 2);
784 *pos++ = WLAN_EID_SUPP_RATES;
785 *pos++ = supp_rates_len;
788 for (i = 0; i < sband->n_bitrates; i++) {
789 if (BIT(i) & rates) {
790 int rate = sband->bitrates[i].bitrate;
791 *pos++ = (u8) (rate / 5);
797 if (rates_len > count) {
798 pos = skb_put(skb, rates_len - count + 2);
799 *pos++ = WLAN_EID_EXT_SUPP_RATES;
800 *pos++ = rates_len - count;
802 for (i++; i < sband->n_bitrates; i++) {
803 if (BIT(i) & rates) {
804 int rate = sband->bitrates[i].bitrate;
805 *pos++ = (u8) (rate / 5);
810 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
811 /* 1. power capabilities */
812 pos = skb_put(skb, 4);
813 *pos++ = WLAN_EID_PWR_CAPABILITY;
815 *pos++ = 0; /* min tx power */
816 *pos++ = chan->max_power; /* max tx power */
818 /* 2. supported channels */
819 /* TODO: get this in reg domain format */
820 pos = skb_put(skb, 2 * sband->n_channels + 2);
821 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
822 *pos++ = 2 * sband->n_channels;
823 for (i = 0; i < sband->n_channels; i++) {
824 *pos++ = ieee80211_frequency_to_channel(
825 sband->channels[i].center_freq);
826 *pos++ = 1; /* one channel in the subband*/
830 /* if present, add any custom IEs that go before HT */
831 if (assoc_data->ie_len && assoc_data->ie) {
832 static const u8 before_ht[] = {
835 WLAN_EID_EXT_SUPP_RATES,
836 WLAN_EID_PWR_CAPABILITY,
837 WLAN_EID_SUPPORTED_CHANNELS,
840 WLAN_EID_RRM_ENABLED_CAPABILITIES,
841 WLAN_EID_MOBILITY_DOMAIN,
842 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
844 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
845 before_ht, ARRAY_SIZE(before_ht),
847 pos = skb_put(skb, noffset - offset);
848 memcpy(pos, assoc_data->ie + offset, noffset - offset);
852 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
853 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
854 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
856 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
857 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
858 sband, chan, sdata->smps_mode);
860 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
861 ieee80211_add_vht_ie(sdata, skb, sband,
862 &assoc_data->ap_vht_cap);
864 /* if present, add any custom non-vendor IEs that go after HT */
865 if (assoc_data->ie_len && assoc_data->ie) {
866 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
869 pos = skb_put(skb, noffset - offset);
870 memcpy(pos, assoc_data->ie + offset, noffset - offset);
874 if (assoc_data->wmm) {
875 if (assoc_data->uapsd) {
876 qos_info = ifmgd->uapsd_queues;
877 qos_info |= (ifmgd->uapsd_max_sp_len <<
878 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
883 pos = skb_put(skb, 9);
884 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
885 *pos++ = 7; /* len */
886 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
889 *pos++ = 2; /* WME */
890 *pos++ = 0; /* WME info */
891 *pos++ = 1; /* WME ver */
895 /* add any remaining custom (i.e. vendor specific here) IEs */
896 if (assoc_data->ie_len && assoc_data->ie) {
897 noffset = assoc_data->ie_len;
898 pos = skb_put(skb, noffset - offset);
899 memcpy(pos, assoc_data->ie + offset, noffset - offset);
902 drv_mgd_prepare_tx(local, sdata);
904 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
905 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
906 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
907 IEEE80211_TX_INTFL_MLME_CONN_TX;
908 ieee80211_tx_skb(sdata, skb);
911 void ieee80211_send_pspoll(struct ieee80211_local *local,
912 struct ieee80211_sub_if_data *sdata)
914 struct ieee80211_pspoll *pspoll;
917 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
921 pspoll = (struct ieee80211_pspoll *) skb->data;
922 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
924 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
925 ieee80211_tx_skb(sdata, skb);
928 void ieee80211_send_nullfunc(struct ieee80211_local *local,
929 struct ieee80211_sub_if_data *sdata,
933 struct ieee80211_hdr_3addr *nullfunc;
934 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
936 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
940 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
942 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
944 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
945 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
946 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
947 IEEE80211_STA_CONNECTION_POLL))
948 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
950 ieee80211_tx_skb(sdata, skb);
953 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
954 struct ieee80211_sub_if_data *sdata)
957 struct ieee80211_hdr *nullfunc;
960 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
963 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
967 skb_reserve(skb, local->hw.extra_tx_headroom);
969 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
970 memset(nullfunc, 0, 30);
971 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
972 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
973 nullfunc->frame_control = fc;
974 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
975 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
976 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
977 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
979 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
980 ieee80211_tx_skb(sdata, skb);
983 /* spectrum management related things */
984 static void ieee80211_chswitch_work(struct work_struct *work)
986 struct ieee80211_sub_if_data *sdata =
987 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
988 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
990 if (!ieee80211_sdata_running(sdata))
993 mutex_lock(&ifmgd->mtx);
994 if (!ifmgd->associated)
997 sdata->local->_oper_channel = sdata->local->csa_channel;
998 if (!sdata->local->ops->channel_switch) {
999 /* call "hw_config" only if doing sw channel switch */
1000 ieee80211_hw_config(sdata->local,
1001 IEEE80211_CONF_CHANGE_CHANNEL);
1003 /* update the device channel directly */
1004 sdata->local->hw.conf.channel = sdata->local->_oper_channel;
1007 /* XXX: shouldn't really modify cfg80211-owned data! */
1008 ifmgd->associated->channel = sdata->local->_oper_channel;
1010 /* XXX: wait for a beacon first? */
1011 ieee80211_wake_queues_by_reason(&sdata->local->hw,
1012 IEEE80211_MAX_QUEUE_MAP,
1013 IEEE80211_QUEUE_STOP_REASON_CSA);
1015 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
1016 mutex_unlock(&ifmgd->mtx);
1019 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1021 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1022 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1024 trace_api_chswitch_done(sdata, success);
1027 "driver channel switch failed, disconnecting\n");
1028 ieee80211_queue_work(&sdata->local->hw,
1029 &ifmgd->csa_connection_drop_work);
1031 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1034 EXPORT_SYMBOL(ieee80211_chswitch_done);
1036 static void ieee80211_chswitch_timer(unsigned long data)
1038 struct ieee80211_sub_if_data *sdata =
1039 (struct ieee80211_sub_if_data *) data;
1041 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1045 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1046 const struct ieee80211_channel_sw_ie *sw_elem,
1047 struct ieee80211_bss *bss, u64 timestamp)
1049 struct cfg80211_bss *cbss =
1050 container_of((void *)bss, struct cfg80211_bss, priv);
1051 struct ieee80211_channel *new_ch;
1052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1053 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
1054 cbss->channel->band);
1055 struct ieee80211_chanctx *chanctx;
1057 ASSERT_MGD_MTX(ifmgd);
1059 if (!ifmgd->associated)
1062 if (sdata->local->scanning)
1065 /* Disregard subsequent beacons if we are already running a timer
1068 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1071 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1072 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) {
1074 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1075 ifmgd->associated->bssid, new_freq);
1076 ieee80211_queue_work(&sdata->local->hw,
1077 &ifmgd->csa_connection_drop_work);
1081 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1083 if (sdata->local->use_chanctx) {
1085 "not handling channel switch with channel contexts\n");
1086 ieee80211_queue_work(&sdata->local->hw,
1087 &ifmgd->csa_connection_drop_work);
1091 mutex_lock(&sdata->local->chanctx_mtx);
1092 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
1093 mutex_unlock(&sdata->local->chanctx_mtx);
1096 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
1097 struct ieee80211_chanctx, conf);
1098 if (chanctx->refcount > 1) {
1100 "channel switch with multiple interfaces on the same channel, disconnecting\n");
1101 ieee80211_queue_work(&sdata->local->hw,
1102 &ifmgd->csa_connection_drop_work);
1103 mutex_unlock(&sdata->local->chanctx_mtx);
1106 mutex_unlock(&sdata->local->chanctx_mtx);
1108 sdata->local->csa_channel = new_ch;
1111 ieee80211_stop_queues_by_reason(&sdata->local->hw,
1112 IEEE80211_MAX_QUEUE_MAP,
1113 IEEE80211_QUEUE_STOP_REASON_CSA);
1115 if (sdata->local->ops->channel_switch) {
1116 /* use driver's channel switch callback */
1117 struct ieee80211_channel_switch ch_switch = {
1118 .timestamp = timestamp,
1119 .block_tx = sw_elem->mode,
1121 .count = sw_elem->count,
1124 drv_channel_switch(sdata->local, &ch_switch);
1128 /* channel switch handled in software */
1129 if (sw_elem->count <= 1)
1130 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1132 mod_timer(&ifmgd->chswitch_timer,
1133 TU_TO_EXP_TIME(sw_elem->count *
1134 cbss->beacon_interval));
1137 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1138 struct ieee80211_channel *channel,
1139 const u8 *country_ie, u8 country_ie_len,
1140 const u8 *pwr_constr_elem)
1142 struct ieee80211_country_ie_triplet *triplet;
1143 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1144 int i, chan_pwr, chan_increment, new_ap_level;
1145 bool have_chan_pwr = false;
1148 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1151 triplet = (void *)(country_ie + 3);
1152 country_ie_len -= 3;
1154 switch (channel->band) {
1158 case IEEE80211_BAND_2GHZ:
1159 case IEEE80211_BAND_60GHZ:
1162 case IEEE80211_BAND_5GHZ:
1168 while (country_ie_len >= 3) {
1169 u8 first_channel = triplet->chans.first_channel;
1171 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1174 for (i = 0; i < triplet->chans.num_channels; i++) {
1175 if (first_channel + i * chan_increment == chan) {
1176 have_chan_pwr = true;
1177 chan_pwr = triplet->chans.max_power;
1186 country_ie_len -= 3;
1192 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
1194 if (sdata->ap_power_level == new_ap_level)
1198 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1199 new_ap_level, chan_pwr, *pwr_constr_elem,
1200 sdata->u.mgd.bssid);
1201 sdata->ap_power_level = new_ap_level;
1202 if (__ieee80211_recalc_txpower(sdata))
1203 return BSS_CHANGED_TXPOWER;
1208 static void ieee80211_enable_ps(struct ieee80211_local *local,
1209 struct ieee80211_sub_if_data *sdata)
1211 struct ieee80211_conf *conf = &local->hw.conf;
1214 * If we are scanning right now then the parameters will
1215 * take effect when scan finishes.
1217 if (local->scanning)
1220 if (conf->dynamic_ps_timeout > 0 &&
1221 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
1222 mod_timer(&local->dynamic_ps_timer, jiffies +
1223 msecs_to_jiffies(conf->dynamic_ps_timeout));
1225 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1226 ieee80211_send_nullfunc(local, sdata, 1);
1228 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1229 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
1232 conf->flags |= IEEE80211_CONF_PS;
1233 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1237 static void ieee80211_change_ps(struct ieee80211_local *local)
1239 struct ieee80211_conf *conf = &local->hw.conf;
1241 if (local->ps_sdata) {
1242 ieee80211_enable_ps(local, local->ps_sdata);
1243 } else if (conf->flags & IEEE80211_CONF_PS) {
1244 conf->flags &= ~IEEE80211_CONF_PS;
1245 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1246 del_timer_sync(&local->dynamic_ps_timer);
1247 cancel_work_sync(&local->dynamic_ps_enable_work);
1251 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1253 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1254 struct sta_info *sta = NULL;
1255 bool authorized = false;
1257 if (!mgd->powersave)
1263 if (!mgd->associated)
1266 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
1267 IEEE80211_STA_CONNECTION_POLL))
1271 sta = sta_info_get(sdata, mgd->bssid);
1273 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1279 /* need to hold RTNL or interface lock */
1280 void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
1282 struct ieee80211_sub_if_data *sdata, *found = NULL;
1286 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1287 local->ps_sdata = NULL;
1291 list_for_each_entry(sdata, &local->interfaces, list) {
1292 if (!ieee80211_sdata_running(sdata))
1294 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1295 /* If an AP vif is found, then disable PS
1296 * by setting the count to zero thereby setting
1302 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1308 if (count == 1 && ieee80211_powersave_allowed(found)) {
1312 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
1314 beaconint_us = ieee80211_tu_to_usec(
1315 found->vif.bss_conf.beacon_int);
1317 timeout = local->dynamic_ps_forced_timeout;
1320 * Go to full PSM if the user configures a very low
1321 * latency requirement.
1322 * The 2000 second value is there for compatibility
1323 * until the PM_QOS_NETWORK_LATENCY is configured
1326 if (latency > (1900 * USEC_PER_MSEC) &&
1327 latency != (2000 * USEC_PER_SEC))
1332 local->hw.conf.dynamic_ps_timeout = timeout;
1334 if (beaconint_us > latency) {
1335 local->ps_sdata = NULL;
1338 u8 dtimper = found->u.mgd.dtim_period;
1340 /* If the TIM IE is invalid, pretend the value is 1 */
1343 else if (dtimper > 1)
1344 maxslp = min_t(int, dtimper,
1345 latency / beaconint_us);
1347 local->hw.conf.max_sleep_period = maxslp;
1348 local->hw.conf.ps_dtim_period = dtimper;
1349 local->ps_sdata = found;
1352 local->ps_sdata = NULL;
1355 ieee80211_change_ps(local);
1358 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1360 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1362 if (sdata->vif.bss_conf.ps != ps_allowed) {
1363 sdata->vif.bss_conf.ps = ps_allowed;
1364 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1368 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1370 struct ieee80211_local *local =
1371 container_of(work, struct ieee80211_local,
1372 dynamic_ps_disable_work);
1374 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1375 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1376 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1379 ieee80211_wake_queues_by_reason(&local->hw,
1380 IEEE80211_MAX_QUEUE_MAP,
1381 IEEE80211_QUEUE_STOP_REASON_PS);
1384 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1386 struct ieee80211_local *local =
1387 container_of(work, struct ieee80211_local,
1388 dynamic_ps_enable_work);
1389 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1390 struct ieee80211_if_managed *ifmgd;
1391 unsigned long flags;
1394 /* can only happen when PS was just disabled anyway */
1398 ifmgd = &sdata->u.mgd;
1400 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1403 if (local->hw.conf.dynamic_ps_timeout > 0) {
1404 /* don't enter PS if TX frames are pending */
1405 if (drv_tx_frames_pending(local)) {
1406 mod_timer(&local->dynamic_ps_timer, jiffies +
1408 local->hw.conf.dynamic_ps_timeout));
1413 * transmission can be stopped by others which leads to
1414 * dynamic_ps_timer expiry. Postpone the ps timer if it
1415 * is not the actual idle state.
1417 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1418 for (q = 0; q < local->hw.queues; q++) {
1419 if (local->queue_stop_reasons[q]) {
1420 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1422 mod_timer(&local->dynamic_ps_timer, jiffies +
1424 local->hw.conf.dynamic_ps_timeout));
1428 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1431 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1432 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1433 netif_tx_stop_all_queues(sdata->dev);
1435 if (drv_tx_frames_pending(local))
1436 mod_timer(&local->dynamic_ps_timer, jiffies +
1438 local->hw.conf.dynamic_ps_timeout));
1440 ieee80211_send_nullfunc(local, sdata, 1);
1441 /* Flush to get the tx status of nullfunc frame */
1442 ieee80211_flush_queues(local, sdata);
1446 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1447 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
1448 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1449 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1450 local->hw.conf.flags |= IEEE80211_CONF_PS;
1451 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1454 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1455 netif_tx_wake_all_queues(sdata->dev);
1458 void ieee80211_dynamic_ps_timer(unsigned long data)
1460 struct ieee80211_local *local = (void *) data;
1462 if (local->quiescing || local->suspended)
1465 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1468 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1470 struct delayed_work *delayed_work =
1471 container_of(work, struct delayed_work, work);
1472 struct ieee80211_sub_if_data *sdata =
1473 container_of(delayed_work, struct ieee80211_sub_if_data,
1474 dfs_cac_timer_work);
1476 ieee80211_vif_release_channel(sdata);
1478 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
1482 static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
1483 struct ieee80211_sub_if_data *sdata,
1484 const u8 *wmm_param, size_t wmm_param_len)
1486 struct ieee80211_tx_queue_params params;
1487 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1491 u8 uapsd_queues = 0;
1493 if (!local->ops->conf_tx)
1496 if (local->hw.queues < IEEE80211_NUM_ACS)
1502 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1505 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1506 uapsd_queues = ifmgd->uapsd_queues;
1508 count = wmm_param[6] & 0x0f;
1509 if (count == ifmgd->wmm_last_param_set)
1511 ifmgd->wmm_last_param_set = count;
1513 pos = wmm_param + 8;
1514 left = wmm_param_len - 8;
1516 memset(¶ms, 0, sizeof(params));
1519 for (; left >= 4; left -= 4, pos += 4) {
1520 int aci = (pos[0] >> 5) & 0x03;
1521 int acm = (pos[0] >> 4) & 0x01;
1529 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
1530 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1536 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
1537 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1543 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
1544 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1551 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
1552 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1557 params.aifs = pos[0] & 0x0f;
1558 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1559 params.cw_min = ecw2cw(pos[1] & 0x0f);
1560 params.txop = get_unaligned_le16(pos + 2);
1561 params.uapsd = uapsd;
1564 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1566 params.aifs, params.cw_min, params.cw_max,
1567 params.txop, params.uapsd);
1568 sdata->tx_conf[queue] = params;
1569 if (drv_conf_tx(local, sdata, queue, ¶ms))
1571 "failed to set TX queue parameters for queue %d\n",
1575 /* enable WMM or activate new settings */
1576 sdata->vif.bss_conf.qos = true;
1580 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1582 lockdep_assert_held(&sdata->local->mtx);
1584 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1585 IEEE80211_STA_BEACON_POLL);
1586 ieee80211_run_deferred_scan(sdata->local);
1589 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1591 mutex_lock(&sdata->local->mtx);
1592 __ieee80211_stop_poll(sdata);
1593 mutex_unlock(&sdata->local->mtx);
1596 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1597 u16 capab, bool erp_valid, u8 erp)
1599 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1601 bool use_protection;
1602 bool use_short_preamble;
1603 bool use_short_slot;
1606 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1607 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1609 use_protection = false;
1610 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1613 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
1614 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
1615 use_short_slot = true;
1617 if (use_protection != bss_conf->use_cts_prot) {
1618 bss_conf->use_cts_prot = use_protection;
1619 changed |= BSS_CHANGED_ERP_CTS_PROT;
1622 if (use_short_preamble != bss_conf->use_short_preamble) {
1623 bss_conf->use_short_preamble = use_short_preamble;
1624 changed |= BSS_CHANGED_ERP_PREAMBLE;
1627 if (use_short_slot != bss_conf->use_short_slot) {
1628 bss_conf->use_short_slot = use_short_slot;
1629 changed |= BSS_CHANGED_ERP_SLOT;
1635 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1636 struct cfg80211_bss *cbss,
1637 u32 bss_info_changed)
1639 struct ieee80211_bss *bss = (void *)cbss->priv;
1640 struct ieee80211_local *local = sdata->local;
1641 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1643 bss_info_changed |= BSS_CHANGED_ASSOC;
1644 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
1645 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
1647 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1648 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
1650 sdata->u.mgd.associated = cbss;
1651 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
1653 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1655 if (sdata->vif.p2p) {
1656 const struct cfg80211_bss_ies *ies;
1659 ies = rcu_dereference(cbss->ies);
1664 ret = cfg80211_get_p2p_attr(
1665 ies->data, ies->len,
1666 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1669 bss_conf->p2p_oppps = noa[1] & 0x80;
1670 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
1671 bss_info_changed |= BSS_CHANGED_P2P_PS;
1672 sdata->u.mgd.p2p_noa_index = noa[0];
1678 /* just to be sure */
1679 ieee80211_stop_poll(sdata);
1681 ieee80211_led_assoc(local, 1);
1683 if (sdata->u.mgd.assoc_data->have_beacon) {
1685 * If the AP is buggy we may get here with no DTIM period
1686 * known, so assume it's 1 which is the only safe assumption
1687 * in that case, although if the TIM IE is broken powersave
1688 * probably just won't work at all.
1690 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
1691 bss_info_changed |= BSS_CHANGED_DTIM_PERIOD;
1693 bss_conf->dtim_period = 0;
1696 bss_conf->assoc = 1;
1698 /* Tell the driver to monitor connection quality (if supported) */
1699 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
1700 bss_conf->cqm_rssi_thold)
1701 bss_info_changed |= BSS_CHANGED_CQM;
1703 /* Enable ARP filtering */
1704 if (bss_conf->arp_addr_cnt)
1705 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
1707 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
1709 mutex_lock(&local->iflist_mtx);
1710 ieee80211_recalc_ps(local, -1);
1711 mutex_unlock(&local->iflist_mtx);
1713 ieee80211_recalc_smps(sdata);
1714 ieee80211_recalc_ps_vif(sdata);
1716 netif_tx_start_all_queues(sdata->dev);
1717 netif_carrier_on(sdata->dev);
1720 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1721 u16 stype, u16 reason, bool tx,
1724 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1725 struct ieee80211_local *local = sdata->local;
1728 ASSERT_MGD_MTX(ifmgd);
1730 if (WARN_ON_ONCE(tx && !frame_buf))
1733 if (WARN_ON(!ifmgd->associated))
1736 ieee80211_stop_poll(sdata);
1738 ifmgd->associated = NULL;
1741 * we need to commit the associated = NULL change because the
1742 * scan code uses that to determine whether this iface should
1743 * go to/wake up from powersave or not -- and could otherwise
1744 * wake the queues erroneously.
1749 * Thus, we can only afterwards stop the queues -- to account
1750 * for the case where another CPU is finishing a scan at this
1751 * time -- we don't want the scan code to enable queues.
1754 netif_tx_stop_all_queues(sdata->dev);
1755 netif_carrier_off(sdata->dev);
1758 * if we want to get out of ps before disassoc (why?) we have
1759 * to do it before sending disassoc, as otherwise the null-packet
1762 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1763 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1764 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1766 local->ps_sdata = NULL;
1768 /* disable per-vif ps */
1769 ieee80211_recalc_ps_vif(sdata);
1771 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1773 ieee80211_flush_queues(local, sdata);
1775 /* deauthenticate/disassociate now */
1776 if (tx || frame_buf)
1777 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1778 reason, tx, frame_buf);
1780 /* flush out frame */
1782 ieee80211_flush_queues(local, sdata);
1784 /* clear bssid only after building the needed mgmt frames */
1785 memset(ifmgd->bssid, 0, ETH_ALEN);
1787 /* remove AP and TDLS peers */
1788 sta_info_flush_defer(sdata);
1790 /* finally reset all BSS / config parameters */
1791 changed |= ieee80211_reset_erp_info(sdata);
1793 ieee80211_led_assoc(local, 0);
1794 changed |= BSS_CHANGED_ASSOC;
1795 sdata->vif.bss_conf.assoc = false;
1797 sdata->vif.bss_conf.p2p_ctwindow = 0;
1798 sdata->vif.bss_conf.p2p_oppps = false;
1800 /* on the next assoc, re-program HT/VHT parameters */
1801 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1802 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
1803 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
1804 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
1806 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
1808 del_timer_sync(&local->dynamic_ps_timer);
1809 cancel_work_sync(&local->dynamic_ps_enable_work);
1811 /* Disable ARP filtering */
1812 if (sdata->vif.bss_conf.arp_addr_cnt)
1813 changed |= BSS_CHANGED_ARP_FILTER;
1815 sdata->vif.bss_conf.qos = false;
1816 changed |= BSS_CHANGED_QOS;
1818 /* The BSSID (not really interesting) and HT changed */
1819 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
1820 ieee80211_bss_info_change_notify(sdata, changed);
1822 /* disassociated - set to defaults now */
1823 ieee80211_set_wmm_default(sdata, false);
1825 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1826 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1827 del_timer_sync(&sdata->u.mgd.timer);
1828 del_timer_sync(&sdata->u.mgd.chswitch_timer);
1830 sdata->vif.bss_conf.dtim_period = 0;
1833 ieee80211_vif_release_channel(sdata);
1836 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1837 struct ieee80211_hdr *hdr)
1840 * We can postpone the mgd.timer whenever receiving unicast frames
1841 * from AP because we know that the connection is working both ways
1842 * at that time. But multicast frames (and hence also beacons) must
1843 * be ignored here, because we need to trigger the timer during
1844 * data idle periods for sending the periodic probe request to the
1845 * AP we're connected to.
1847 if (is_multicast_ether_addr(hdr->addr1))
1850 ieee80211_sta_reset_conn_monitor(sdata);
1853 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1855 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1856 struct ieee80211_local *local = sdata->local;
1858 mutex_lock(&local->mtx);
1859 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1860 IEEE80211_STA_CONNECTION_POLL))) {
1861 mutex_unlock(&local->mtx);
1865 __ieee80211_stop_poll(sdata);
1867 mutex_lock(&local->iflist_mtx);
1868 ieee80211_recalc_ps(local, -1);
1869 mutex_unlock(&local->iflist_mtx);
1871 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1875 * We've received a probe response, but are not sure whether
1876 * we have or will be receiving any beacons or data, so let's
1877 * schedule the timers again, just in case.
1879 ieee80211_sta_reset_beacon_monitor(sdata);
1881 mod_timer(&ifmgd->conn_mon_timer,
1882 round_jiffies_up(jiffies +
1883 IEEE80211_CONNECTION_IDLE_TIME));
1885 mutex_unlock(&local->mtx);
1888 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
1889 struct ieee80211_hdr *hdr, bool ack)
1891 if (!ieee80211_is_data(hdr->frame_control))
1894 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1895 sdata->u.mgd.probe_send_count > 0) {
1897 ieee80211_sta_reset_conn_monitor(sdata);
1899 sdata->u.mgd.nullfunc_failed = true;
1900 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1905 ieee80211_sta_reset_conn_monitor(sdata);
1908 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1910 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1912 u8 *dst = ifmgd->associated->bssid;
1913 u8 unicast_limit = max(1, max_probe_tries - 3);
1916 * Try sending broadcast probe requests for the last three
1917 * probe requests after the first ones failed since some
1918 * buggy APs only support broadcast probe requests.
1920 if (ifmgd->probe_send_count >= unicast_limit)
1924 * When the hardware reports an accurate Tx ACK status, it's
1925 * better to send a nullfunc frame instead of a probe request,
1926 * as it will kick us off the AP quickly if we aren't associated
1927 * anymore. The timeout will be reset if the frame is ACKed by
1930 ifmgd->probe_send_count++;
1932 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1933 ifmgd->nullfunc_failed = false;
1934 ieee80211_send_nullfunc(sdata->local, sdata, 0);
1939 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1940 if (WARN_ON_ONCE(ssid == NULL))
1945 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
1946 0, (u32) -1, true, 0,
1947 ifmgd->associated->channel, false);
1951 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
1952 run_again(ifmgd, ifmgd->probe_timeout);
1953 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
1954 ieee80211_flush_queues(sdata->local, sdata);
1957 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1960 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1961 bool already = false;
1963 if (!ieee80211_sdata_running(sdata))
1966 mutex_lock(&ifmgd->mtx);
1968 if (!ifmgd->associated)
1971 mutex_lock(&sdata->local->mtx);
1973 if (sdata->local->tmp_channel || sdata->local->scanning) {
1974 mutex_unlock(&sdata->local->mtx);
1979 mlme_dbg_ratelimited(sdata,
1980 "detected beacon loss from AP - probing\n");
1982 ieee80211_cqm_rssi_notify(&sdata->vif,
1983 NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL);
1986 * The driver/our work has already reported this event or the
1987 * connection monitoring has kicked in and we have already sent
1988 * a probe request. Or maybe the AP died and the driver keeps
1989 * reporting until we disassociate...
1991 * In either case we have to ignore the current call to this
1992 * function (except for setting the correct probe reason bit)
1993 * because otherwise we would reset the timer every time and
1994 * never check whether we received a probe response!
1996 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1997 IEEE80211_STA_CONNECTION_POLL))
2001 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
2003 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2005 mutex_unlock(&sdata->local->mtx);
2010 mutex_lock(&sdata->local->iflist_mtx);
2011 ieee80211_recalc_ps(sdata->local, -1);
2012 mutex_unlock(&sdata->local->iflist_mtx);
2014 ifmgd->probe_send_count = 0;
2015 ieee80211_mgd_probe_ap_send(sdata);
2017 mutex_unlock(&ifmgd->mtx);
2020 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2021 struct ieee80211_vif *vif)
2023 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2024 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2025 struct cfg80211_bss *cbss;
2026 struct sk_buff *skb;
2030 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2033 ASSERT_MGD_MTX(ifmgd);
2035 if (ifmgd->associated)
2036 cbss = ifmgd->associated;
2037 else if (ifmgd->auth_data)
2038 cbss = ifmgd->auth_data->bss;
2039 else if (ifmgd->assoc_data)
2040 cbss = ifmgd->assoc_data->bss;
2045 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2046 if (WARN_ON_ONCE(ssid == NULL))
2051 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
2052 (u32) -1, cbss->channel,
2059 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2061 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2063 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2064 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2066 mutex_lock(&ifmgd->mtx);
2067 if (!ifmgd->associated) {
2068 mutex_unlock(&ifmgd->mtx);
2072 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2073 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2075 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
2076 ieee80211_wake_queues_by_reason(&sdata->local->hw,
2077 IEEE80211_MAX_QUEUE_MAP,
2078 IEEE80211_QUEUE_STOP_REASON_CSA);
2079 mutex_unlock(&ifmgd->mtx);
2082 * must be outside lock due to cfg80211,
2083 * but that's not a problem.
2085 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
2088 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2090 struct ieee80211_sub_if_data *sdata =
2091 container_of(work, struct ieee80211_sub_if_data,
2092 u.mgd.beacon_connection_loss_work);
2093 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2094 struct sta_info *sta;
2096 if (ifmgd->associated) {
2098 sta = sta_info_get(sdata, ifmgd->bssid);
2100 sta->beacon_loss_count++;
2104 if (ifmgd->connection_loss) {
2105 sdata_info(sdata, "Connection to AP %pM lost\n",
2107 __ieee80211_disconnect(sdata);
2109 ieee80211_mgd_probe_ap(sdata, true);
2113 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2115 struct ieee80211_sub_if_data *sdata =
2116 container_of(work, struct ieee80211_sub_if_data,
2117 u.mgd.csa_connection_drop_work);
2119 __ieee80211_disconnect(sdata);
2122 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2124 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2125 struct ieee80211_hw *hw = &sdata->local->hw;
2127 trace_api_beacon_loss(sdata);
2129 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
2130 sdata->u.mgd.connection_loss = false;
2131 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2133 EXPORT_SYMBOL(ieee80211_beacon_loss);
2135 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2137 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2138 struct ieee80211_hw *hw = &sdata->local->hw;
2140 trace_api_connection_loss(sdata);
2142 sdata->u.mgd.connection_loss = true;
2143 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2145 EXPORT_SYMBOL(ieee80211_connection_loss);
2148 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2151 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2153 lockdep_assert_held(&sdata->u.mgd.mtx);
2156 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2158 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2159 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2160 sdata->u.mgd.flags = 0;
2161 ieee80211_vif_release_channel(sdata);
2164 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2166 sdata->u.mgd.auth_data = NULL;
2169 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2170 struct ieee80211_mgmt *mgmt, size_t len)
2172 struct ieee80211_local *local = sdata->local;
2173 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2175 struct ieee802_11_elems elems;
2178 pos = mgmt->u.auth.variable;
2179 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2180 if (!elems.challenge)
2182 auth_data->expected_transaction = 4;
2183 drv_mgd_prepare_tx(sdata->local, sdata);
2184 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
2185 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2186 IEEE80211_TX_INTFL_MLME_CONN_TX;
2187 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2188 elems.challenge - 2, elems.challenge_len + 2,
2189 auth_data->bss->bssid, auth_data->bss->bssid,
2190 auth_data->key, auth_data->key_len,
2191 auth_data->key_idx, tx_flags);
2194 static enum rx_mgmt_action __must_check
2195 ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2196 struct ieee80211_mgmt *mgmt, size_t len)
2198 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2200 u16 auth_alg, auth_transaction, status_code;
2201 struct sta_info *sta;
2203 lockdep_assert_held(&ifmgd->mtx);
2206 return RX_MGMT_NONE;
2208 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2209 return RX_MGMT_NONE;
2211 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2213 if (!ether_addr_equal(bssid, mgmt->bssid))
2214 return RX_MGMT_NONE;
2216 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2217 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2218 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2220 if (auth_alg != ifmgd->auth_data->algorithm ||
2221 auth_transaction != ifmgd->auth_data->expected_transaction) {
2222 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2223 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2225 ifmgd->auth_data->expected_transaction);
2226 return RX_MGMT_NONE;
2229 if (status_code != WLAN_STATUS_SUCCESS) {
2230 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2231 mgmt->sa, status_code);
2232 ieee80211_destroy_auth_data(sdata, false);
2233 return RX_MGMT_CFG80211_RX_AUTH;
2236 switch (ifmgd->auth_data->algorithm) {
2237 case WLAN_AUTH_OPEN:
2238 case WLAN_AUTH_LEAP:
2242 case WLAN_AUTH_SHARED_KEY:
2243 if (ifmgd->auth_data->expected_transaction != 4) {
2244 ieee80211_auth_challenge(sdata, mgmt, len);
2245 /* need another frame */
2246 return RX_MGMT_NONE;
2250 WARN_ONCE(1, "invalid auth alg %d",
2251 ifmgd->auth_data->algorithm);
2252 return RX_MGMT_NONE;
2255 sdata_info(sdata, "authenticated\n");
2256 ifmgd->auth_data->done = true;
2257 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2258 ifmgd->auth_data->timeout_started = true;
2259 run_again(ifmgd, ifmgd->auth_data->timeout);
2261 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2262 ifmgd->auth_data->expected_transaction != 2) {
2264 * Report auth frame to user space for processing since another
2265 * round of Authentication frames is still needed.
2267 return RX_MGMT_CFG80211_RX_AUTH;
2270 /* move station state to auth */
2271 mutex_lock(&sdata->local->sta_mtx);
2272 sta = sta_info_get(sdata, bssid);
2274 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2277 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2278 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2281 mutex_unlock(&sdata->local->sta_mtx);
2283 return RX_MGMT_CFG80211_RX_AUTH;
2285 mutex_unlock(&sdata->local->sta_mtx);
2286 /* ignore frame -- wait for timeout */
2287 return RX_MGMT_NONE;
2291 static enum rx_mgmt_action __must_check
2292 ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2293 struct ieee80211_mgmt *mgmt, size_t len)
2295 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2296 const u8 *bssid = NULL;
2299 lockdep_assert_held(&ifmgd->mtx);
2302 return RX_MGMT_NONE;
2304 if (!ifmgd->associated ||
2305 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
2306 return RX_MGMT_NONE;
2308 bssid = ifmgd->associated->bssid;
2310 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2312 sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
2313 bssid, reason_code);
2315 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2317 return RX_MGMT_CFG80211_DEAUTH;
2321 static enum rx_mgmt_action __must_check
2322 ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2323 struct ieee80211_mgmt *mgmt, size_t len)
2325 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2328 lockdep_assert_held(&ifmgd->mtx);
2331 return RX_MGMT_NONE;
2333 if (!ifmgd->associated ||
2334 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
2335 return RX_MGMT_NONE;
2337 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2339 sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
2340 mgmt->sa, reason_code);
2342 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2344 return RX_MGMT_CFG80211_DISASSOC;
2347 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2348 u8 *supp_rates, unsigned int supp_rates_len,
2349 u32 *rates, u32 *basic_rates,
2350 bool *have_higher_than_11mbit,
2351 int *min_rate, int *min_rate_index)
2355 for (i = 0; i < supp_rates_len; i++) {
2356 int rate = (supp_rates[i] & 0x7f) * 5;
2357 bool is_basic = !!(supp_rates[i] & 0x80);
2360 *have_higher_than_11mbit = true;
2363 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2364 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2366 * Note: Even through the membership selector and the basic
2367 * rate flag share the same bit, they are not exactly
2370 if (!!(supp_rates[i] & 0x80) &&
2371 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
2374 for (j = 0; j < sband->n_bitrates; j++) {
2375 if (sband->bitrates[j].bitrate == rate) {
2378 *basic_rates |= BIT(j);
2379 if (rate < *min_rate) {
2381 *min_rate_index = j;
2389 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2392 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2394 lockdep_assert_held(&sdata->u.mgd.mtx);
2397 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2399 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2400 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2401 sdata->u.mgd.flags = 0;
2402 ieee80211_vif_release_channel(sdata);
2406 sdata->u.mgd.assoc_data = NULL;
2409 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2410 struct cfg80211_bss *cbss,
2411 struct ieee80211_mgmt *mgmt, size_t len)
2413 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2414 struct ieee80211_local *local = sdata->local;
2415 struct ieee80211_supported_band *sband;
2416 struct sta_info *sta;
2418 u16 capab_info, aid;
2419 struct ieee802_11_elems elems;
2420 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2424 /* AssocResp and ReassocResp have identical structure */
2426 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2427 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2429 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2430 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2432 aid &= ~(BIT(15) | BIT(14));
2434 ifmgd->broken_ap = false;
2436 if (aid == 0 || aid > IEEE80211_MAX_AID) {
2437 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2440 ifmgd->broken_ap = true;
2443 pos = mgmt->u.assoc_resp.variable;
2444 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2446 if (!elems.supp_rates) {
2447 sdata_info(sdata, "no SuppRates element in AssocResp\n");
2454 * We previously checked these in the beacon/probe response, so
2455 * they should be present here. This is just a safety net.
2457 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2458 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
2460 "HT AP is missing WMM params or HT capability/operation in AssocResp\n");
2464 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2465 (!elems.vht_cap_elem || !elems.vht_operation)) {
2467 "VHT AP is missing VHT capability/operation in AssocResp\n");
2471 mutex_lock(&sdata->local->sta_mtx);
2473 * station info was already allocated and inserted before
2474 * the association and should be available to us
2476 sta = sta_info_get(sdata, cbss->bssid);
2477 if (WARN_ON(!sta)) {
2478 mutex_unlock(&sdata->local->sta_mtx);
2482 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
2484 /* Set up internal HT/VHT capabilities */
2485 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
2486 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
2487 elems.ht_cap_elem, sta);
2489 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2490 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
2491 elems.vht_cap_elem, sta);
2494 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
2495 * in their association response, so ignore that data for our own
2496 * configuration. If it changed since the last beacon, we'll get the
2497 * next beacon and update then.
2501 * If an operating mode notification IE is present, override the
2502 * NSS calculation (that would be done in rate_control_rate_init())
2503 * and use the # of streams from that element.
2505 if (elems.opmode_notif &&
2506 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
2509 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
2510 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
2512 sta->sta.rx_nss = nss;
2515 rate_control_rate_init(sta);
2517 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
2518 set_sta_flag(sta, WLAN_STA_MFP);
2520 if (elems.wmm_param)
2521 set_sta_flag(sta, WLAN_STA_WME);
2523 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
2524 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2525 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2528 "failed to move station %pM to desired state\n",
2530 WARN_ON(__sta_info_destroy(sta));
2531 mutex_unlock(&sdata->local->sta_mtx);
2535 mutex_unlock(&sdata->local->sta_mtx);
2538 * Always handle WMM once after association regardless
2539 * of the first value the AP uses. Setting -1 here has
2540 * that effect because the AP values is an unsigned
2543 ifmgd->wmm_last_param_set = -1;
2545 if (elems.wmm_param)
2546 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
2547 elems.wmm_param_len);
2549 ieee80211_set_wmm_default(sdata, false);
2550 changed |= BSS_CHANGED_QOS;
2552 /* set AID and assoc capability,
2553 * ieee80211_set_associated() will tell the driver */
2554 bss_conf->aid = aid;
2555 bss_conf->assoc_capability = capab_info;
2556 ieee80211_set_associated(sdata, cbss, changed);
2559 * If we're using 4-addr mode, let the AP know that we're
2560 * doing so, so that it can create the STA VLAN on its side
2562 if (ifmgd->use_4addr)
2563 ieee80211_send_4addr_nullfunc(local, sdata);
2566 * Start timer to probe the connection to the AP now.
2567 * Also start the timer that will detect beacon loss.
2569 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
2570 ieee80211_sta_reset_beacon_monitor(sdata);
2575 static enum rx_mgmt_action __must_check
2576 ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2577 struct ieee80211_mgmt *mgmt, size_t len,
2578 struct cfg80211_bss **bss)
2580 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2581 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2582 u16 capab_info, status_code, aid;
2583 struct ieee802_11_elems elems;
2587 lockdep_assert_held(&ifmgd->mtx);
2590 return RX_MGMT_NONE;
2591 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
2592 return RX_MGMT_NONE;
2595 * AssocResp and ReassocResp have identical structure, so process both
2596 * of them in this function.
2600 return RX_MGMT_NONE;
2602 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2603 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2604 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2605 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2608 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2609 reassoc ? "Rea" : "A", mgmt->sa,
2610 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2612 pos = mgmt->u.assoc_resp.variable;
2613 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2615 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2616 elems.timeout_int && elems.timeout_int_len == 5 &&
2617 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
2619 tu = get_unaligned_le32(elems.timeout_int + 1);
2620 ms = tu * 1024 / 1000;
2622 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2624 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
2625 assoc_data->timeout_started = true;
2626 if (ms > IEEE80211_ASSOC_TIMEOUT)
2627 run_again(ifmgd, assoc_data->timeout);
2628 return RX_MGMT_NONE;
2631 *bss = assoc_data->bss;
2633 if (status_code != WLAN_STATUS_SUCCESS) {
2634 sdata_info(sdata, "%pM denied association (code=%d)\n",
2635 mgmt->sa, status_code);
2636 ieee80211_destroy_assoc_data(sdata, false);
2638 if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) {
2639 /* oops -- internal error -- send timeout for now */
2640 ieee80211_destroy_assoc_data(sdata, false);
2641 cfg80211_put_bss(sdata->local->hw.wiphy, *bss);
2642 return RX_MGMT_CFG80211_ASSOC_TIMEOUT;
2644 sdata_info(sdata, "associated\n");
2647 * destroy assoc_data afterwards, as otherwise an idle
2648 * recalc after assoc_data is NULL but before associated
2649 * is set can cause the interface to go idle
2651 ieee80211_destroy_assoc_data(sdata, true);
2654 return RX_MGMT_CFG80211_RX_ASSOC;
2657 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
2658 struct ieee80211_mgmt *mgmt, size_t len,
2659 struct ieee80211_rx_status *rx_status,
2660 struct ieee802_11_elems *elems)
2662 struct ieee80211_local *local = sdata->local;
2664 struct ieee80211_bss *bss;
2665 struct ieee80211_channel *channel;
2666 bool need_ps = false;
2668 if ((sdata->u.mgd.associated &&
2669 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2670 (sdata->u.mgd.assoc_data &&
2671 ether_addr_equal(mgmt->bssid,
2672 sdata->u.mgd.assoc_data->bss->bssid))) {
2673 /* not previously set so we may need to recalc */
2674 need_ps = sdata->u.mgd.associated && !sdata->u.mgd.dtim_period;
2676 if (elems->tim && !elems->parse_error) {
2677 const struct ieee80211_tim_ie *tim_ie = elems->tim;
2678 sdata->u.mgd.dtim_period = tim_ie->dtim_period;
2682 if (elems->ds_params && elems->ds_params_len == 1)
2683 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2686 freq = rx_status->freq;
2688 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2690 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2693 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
2696 ieee80211_rx_bss_put(local, bss);
2698 if (!sdata->u.mgd.associated)
2702 mutex_lock(&local->iflist_mtx);
2703 ieee80211_recalc_ps(local, -1);
2704 mutex_unlock(&local->iflist_mtx);
2707 if (elems->ch_switch_ie &&
2708 memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0)
2709 ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
2710 bss, rx_status->mactime);
2714 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
2715 struct sk_buff *skb)
2717 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2718 struct ieee80211_if_managed *ifmgd;
2719 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2720 size_t baselen, len = skb->len;
2721 struct ieee802_11_elems elems;
2723 ifmgd = &sdata->u.mgd;
2725 ASSERT_MGD_MTX(ifmgd);
2727 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
2728 return; /* ignore ProbeResp to foreign address */
2730 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2734 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2737 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2739 if (ifmgd->associated &&
2740 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
2741 ieee80211_reset_ap_probe(sdata);
2743 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
2744 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
2745 /* got probe response, continue with auth */
2746 sdata_info(sdata, "direct probe responded\n");
2747 ifmgd->auth_data->tries = 0;
2748 ifmgd->auth_data->timeout = jiffies;
2749 ifmgd->auth_data->timeout_started = true;
2750 run_again(ifmgd, ifmgd->auth_data->timeout);
2755 * This is the canonical list of information elements we care about,
2756 * the filter code also gives us all changes to the Microsoft OUI
2757 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2759 * We implement beacon filtering in software since that means we can
2760 * avoid processing the frame here and in cfg80211, and userspace
2761 * will not be able to tell whether the hardware supports it or not.
2763 * XXX: This list needs to be dynamic -- userspace needs to be able to
2764 * add items it requires. It also needs to be able to tell us to
2765 * look out for other vendor IEs.
2767 static const u64 care_about_ies =
2768 (1ULL << WLAN_EID_COUNTRY) |
2769 (1ULL << WLAN_EID_ERP_INFO) |
2770 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2771 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2772 (1ULL << WLAN_EID_HT_CAPABILITY) |
2773 (1ULL << WLAN_EID_HT_OPERATION);
2775 static enum rx_mgmt_action
2776 ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2777 struct ieee80211_mgmt *mgmt, size_t len,
2778 u8 *deauth_buf, struct ieee80211_rx_status *rx_status)
2780 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2781 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2783 struct ieee802_11_elems elems;
2784 struct ieee80211_local *local = sdata->local;
2785 struct ieee80211_chanctx_conf *chanctx_conf;
2786 struct ieee80211_channel *chan;
2787 struct sta_info *sta;
2794 lockdep_assert_held(&ifmgd->mtx);
2796 /* Process beacon from the current BSS */
2797 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2799 return RX_MGMT_NONE;
2802 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2803 if (!chanctx_conf) {
2805 return RX_MGMT_NONE;
2808 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
2810 return RX_MGMT_NONE;
2812 chan = chanctx_conf->def.chan;
2815 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
2816 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2817 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2818 len - baselen, &elems);
2820 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2821 ifmgd->assoc_data->have_beacon = true;
2822 ifmgd->assoc_data->need_beacon = false;
2823 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
2824 sdata->vif.bss_conf.sync_tsf =
2825 le64_to_cpu(mgmt->u.beacon.timestamp);
2826 sdata->vif.bss_conf.sync_device_ts =
2827 rx_status->device_timestamp;
2829 sdata->vif.bss_conf.sync_dtim_count =
2830 elems.tim->dtim_count;
2832 sdata->vif.bss_conf.sync_dtim_count = 0;
2834 /* continue assoc process */
2835 ifmgd->assoc_data->timeout = jiffies;
2836 ifmgd->assoc_data->timeout_started = true;
2837 run_again(ifmgd, ifmgd->assoc_data->timeout);
2838 return RX_MGMT_NONE;
2841 if (!ifmgd->associated ||
2842 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
2843 return RX_MGMT_NONE;
2844 bssid = ifmgd->associated->bssid;
2846 /* Track average RSSI from the Beacon frames of the current AP */
2847 ifmgd->last_beacon_signal = rx_status->signal;
2848 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2849 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
2850 ifmgd->ave_beacon_signal = rx_status->signal * 16;
2851 ifmgd->last_cqm_event_signal = 0;
2852 ifmgd->count_beacon_signal = 1;
2853 ifmgd->last_ave_beacon_signal = 0;
2855 ifmgd->ave_beacon_signal =
2856 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
2857 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
2858 ifmgd->ave_beacon_signal) / 16;
2859 ifmgd->count_beacon_signal++;
2862 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
2863 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
2864 int sig = ifmgd->ave_beacon_signal;
2865 int last_sig = ifmgd->last_ave_beacon_signal;
2868 * if signal crosses either of the boundaries, invoke callback
2869 * with appropriate parameters
2871 if (sig > ifmgd->rssi_max_thold &&
2872 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
2873 ifmgd->last_ave_beacon_signal = sig;
2874 drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
2875 } else if (sig < ifmgd->rssi_min_thold &&
2876 (last_sig >= ifmgd->rssi_max_thold ||
2878 ifmgd->last_ave_beacon_signal = sig;
2879 drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
2883 if (bss_conf->cqm_rssi_thold &&
2884 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
2885 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
2886 int sig = ifmgd->ave_beacon_signal / 16;
2887 int last_event = ifmgd->last_cqm_event_signal;
2888 int thold = bss_conf->cqm_rssi_thold;
2889 int hyst = bss_conf->cqm_rssi_hyst;
2891 (last_event == 0 || sig < last_event - hyst)) {
2892 ifmgd->last_cqm_event_signal = sig;
2893 ieee80211_cqm_rssi_notify(
2895 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2897 } else if (sig > thold &&
2898 (last_event == 0 || sig > last_event + hyst)) {
2899 ifmgd->last_cqm_event_signal = sig;
2900 ieee80211_cqm_rssi_notify(
2902 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2907 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
2908 mlme_dbg_ratelimited(sdata,
2909 "cancelling AP probe due to a received beacon\n");
2910 mutex_lock(&local->mtx);
2911 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
2912 ieee80211_run_deferred_scan(local);
2913 mutex_unlock(&local->mtx);
2915 mutex_lock(&local->iflist_mtx);
2916 ieee80211_recalc_ps(local, -1);
2917 mutex_unlock(&local->iflist_mtx);
2921 * Push the beacon loss detection into the future since
2922 * we are processing a beacon from the AP just now.
2924 ieee80211_sta_reset_beacon_monitor(sdata);
2926 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2927 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2928 len - baselen, &elems,
2929 care_about_ies, ncrc);
2931 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
2932 bool directed_tim = ieee80211_check_tim(elems.tim,
2936 if (local->hw.conf.dynamic_ps_timeout > 0) {
2937 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2938 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2939 ieee80211_hw_config(local,
2940 IEEE80211_CONF_CHANGE_PS);
2942 ieee80211_send_nullfunc(local, sdata, 0);
2943 } else if (!local->pspolling && sdata->u.mgd.powersave) {
2944 local->pspolling = true;
2947 * Here is assumed that the driver will be
2948 * able to send ps-poll frame and receive a
2949 * response even though power save mode is
2950 * enabled, but some drivers might require
2951 * to disable power save here. This needs
2952 * to be investigated.
2954 ieee80211_send_pspoll(local, sdata);
2959 if (sdata->vif.p2p) {
2963 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
2965 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2967 if (ret >= 2 && sdata->u.mgd.p2p_noa_index != noa[0]) {
2968 bss_conf->p2p_oppps = noa[1] & 0x80;
2969 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
2970 changed |= BSS_CHANGED_P2P_PS;
2971 sdata->u.mgd.p2p_noa_index = noa[0];
2973 * make sure we update all information, the CRC
2974 * mechanism doesn't look at P2P attributes.
2976 ifmgd->beacon_crc_valid = false;
2980 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
2981 return RX_MGMT_NONE;
2982 ifmgd->beacon_crc = ncrc;
2983 ifmgd->beacon_crc_valid = true;
2985 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2987 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
2988 elems.wmm_param_len))
2989 changed |= BSS_CHANGED_QOS;
2992 * If we haven't had a beacon before, tell the driver about the
2993 * DTIM period (and beacon timing if desired) now.
2995 if (!bss_conf->dtim_period) {
2996 /* a few bogus AP send dtim_period = 0 or no TIM IE */
2998 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3000 bss_conf->dtim_period = 1;
3002 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
3003 sdata->vif.bss_conf.sync_tsf =
3004 le64_to_cpu(mgmt->u.beacon.timestamp);
3005 sdata->vif.bss_conf.sync_device_ts =
3006 rx_status->device_timestamp;
3008 sdata->vif.bss_conf.sync_dtim_count =
3009 elems.tim->dtim_count;
3011 sdata->vif.bss_conf.sync_dtim_count = 0;
3014 changed |= BSS_CHANGED_DTIM_PERIOD;
3017 if (elems.erp_info && elems.erp_info_len >= 1) {
3019 erp_value = elems.erp_info[0];
3023 changed |= ieee80211_handle_bss_capability(sdata,
3024 le16_to_cpu(mgmt->u.beacon.capab_info),
3025 erp_valid, erp_value);
3027 mutex_lock(&local->sta_mtx);
3028 sta = sta_info_get(sdata, bssid);
3030 if (ieee80211_config_bw(sdata, sta, elems.ht_operation,
3031 elems.vht_operation, bssid, &changed)) {
3032 mutex_unlock(&local->sta_mtx);
3033 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3034 WLAN_REASON_DEAUTH_LEAVING,
3036 return RX_MGMT_CFG80211_TX_DEAUTH;
3039 if (sta && elems.opmode_notif)
3040 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
3041 rx_status->band, true);
3042 mutex_unlock(&local->sta_mtx);
3044 if (elems.country_elem && elems.pwr_constr_elem &&
3045 mgmt->u.probe_resp.capab_info &
3046 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
3047 changed |= ieee80211_handle_pwr_constr(sdata, chan,
3049 elems.country_elem_len,
3050 elems.pwr_constr_elem);
3052 ieee80211_bss_info_change_notify(sdata, changed);
3054 return RX_MGMT_NONE;
3057 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3058 struct sk_buff *skb)
3060 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3061 struct ieee80211_rx_status *rx_status;
3062 struct ieee80211_mgmt *mgmt;
3063 struct cfg80211_bss *bss = NULL;
3064 enum rx_mgmt_action rma = RX_MGMT_NONE;
3065 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3068 rx_status = (struct ieee80211_rx_status *) skb->cb;
3069 mgmt = (struct ieee80211_mgmt *) skb->data;
3070 fc = le16_to_cpu(mgmt->frame_control);
3072 mutex_lock(&ifmgd->mtx);
3074 switch (fc & IEEE80211_FCTL_STYPE) {
3075 case IEEE80211_STYPE_BEACON:
3076 rma = ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
3077 deauth_buf, rx_status);
3079 case IEEE80211_STYPE_PROBE_RESP:
3080 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3082 case IEEE80211_STYPE_AUTH:
3083 rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
3085 case IEEE80211_STYPE_DEAUTH:
3086 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
3088 case IEEE80211_STYPE_DISASSOC:
3089 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
3091 case IEEE80211_STYPE_ASSOC_RESP:
3092 case IEEE80211_STYPE_REASSOC_RESP:
3093 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
3095 case IEEE80211_STYPE_ACTION:
3096 switch (mgmt->u.action.category) {
3097 case WLAN_CATEGORY_SPECTRUM_MGMT:
3098 ieee80211_sta_process_chanswitch(sdata,
3099 &mgmt->u.action.u.chan_switch.sw_elem,
3100 (void *)ifmgd->associated->priv,
3101 rx_status->mactime);
3105 mutex_unlock(&ifmgd->mtx);
3111 case RX_MGMT_CFG80211_DEAUTH:
3112 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
3114 case RX_MGMT_CFG80211_DISASSOC:
3115 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
3117 case RX_MGMT_CFG80211_RX_AUTH:
3118 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len);
3120 case RX_MGMT_CFG80211_RX_ASSOC:
3121 cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len);
3123 case RX_MGMT_CFG80211_ASSOC_TIMEOUT:
3124 cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid);
3126 case RX_MGMT_CFG80211_TX_DEAUTH:
3127 cfg80211_send_deauth(sdata->dev, deauth_buf,
3128 sizeof(deauth_buf));
3131 WARN(1, "unexpected: %d", rma);
3135 static void ieee80211_sta_timer(unsigned long data)
3137 struct ieee80211_sub_if_data *sdata =
3138 (struct ieee80211_sub_if_data *) data;
3140 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3143 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
3144 u8 *bssid, u8 reason, bool tx)
3146 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3147 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3149 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
3151 mutex_unlock(&ifmgd->mtx);
3154 * must be outside lock due to cfg80211,
3155 * but that's not a problem.
3157 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
3159 mutex_lock(&ifmgd->mtx);
3162 static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
3164 struct ieee80211_local *local = sdata->local;
3165 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3166 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
3169 lockdep_assert_held(&ifmgd->mtx);
3171 if (WARN_ON_ONCE(!auth_data))
3174 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
3175 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3176 IEEE80211_TX_INTFL_MLME_CONN_TX;
3180 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
3181 sdata_info(sdata, "authentication with %pM timed out\n",
3182 auth_data->bss->bssid);
3185 * Most likely AP is not in the range so remove the
3186 * bss struct for that AP.
3188 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3193 drv_mgd_prepare_tx(local, sdata);
3195 if (auth_data->bss->proberesp_ies) {
3199 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3200 auth_data->bss->bssid, auth_data->tries,
3201 IEEE80211_AUTH_MAX_TRIES);
3203 auth_data->expected_transaction = 2;
3205 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3206 trans = auth_data->sae_trans;
3207 status = auth_data->sae_status;
3208 auth_data->expected_transaction = trans;
3211 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
3212 auth_data->data, auth_data->data_len,
3213 auth_data->bss->bssid,
3214 auth_data->bss->bssid, NULL, 0, 0,
3219 sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
3220 auth_data->bss->bssid, auth_data->tries,
3221 IEEE80211_AUTH_MAX_TRIES);
3224 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
3230 * Direct probe is sent to broadcast address as some APs
3231 * will not answer to direct packet in unassociated state.
3233 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
3234 NULL, 0, (u32) -1, true, tx_flags,
3235 auth_data->bss->channel, false);
3239 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
3240 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
3241 ifmgd->auth_data->timeout_started = true;
3242 run_again(ifmgd, auth_data->timeout);
3244 auth_data->timeout_started = false;
3250 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
3252 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3253 struct ieee80211_local *local = sdata->local;
3255 lockdep_assert_held(&sdata->u.mgd.mtx);
3257 assoc_data->tries++;
3258 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
3259 sdata_info(sdata, "association with %pM timed out\n",
3260 assoc_data->bss->bssid);
3263 * Most likely AP is not in the range so remove the
3264 * bss struct for that AP.
3266 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
3271 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
3272 assoc_data->bss->bssid, assoc_data->tries,
3273 IEEE80211_ASSOC_MAX_TRIES);
3274 ieee80211_send_assoc(sdata);
3276 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
3277 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
3278 assoc_data->timeout_started = true;
3279 run_again(&sdata->u.mgd, assoc_data->timeout);
3281 assoc_data->timeout_started = false;
3287 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
3288 __le16 fc, bool acked)
3290 struct ieee80211_local *local = sdata->local;
3292 sdata->u.mgd.status_fc = fc;
3293 sdata->u.mgd.status_acked = acked;
3294 sdata->u.mgd.status_received = true;
3296 ieee80211_queue_work(&local->hw, &sdata->work);
3299 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
3301 struct ieee80211_local *local = sdata->local;
3302 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3304 mutex_lock(&ifmgd->mtx);
3306 if (ifmgd->status_received) {
3307 __le16 fc = ifmgd->status_fc;
3308 bool status_acked = ifmgd->status_acked;
3310 ifmgd->status_received = false;
3311 if (ifmgd->auth_data &&
3312 (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
3314 ifmgd->auth_data->timeout =
3315 jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
3316 run_again(ifmgd, ifmgd->auth_data->timeout);
3318 ifmgd->auth_data->timeout = jiffies - 1;
3320 ifmgd->auth_data->timeout_started = true;
3321 } else if (ifmgd->assoc_data &&
3322 (ieee80211_is_assoc_req(fc) ||
3323 ieee80211_is_reassoc_req(fc))) {
3325 ifmgd->assoc_data->timeout =
3326 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
3327 run_again(ifmgd, ifmgd->assoc_data->timeout);
3329 ifmgd->assoc_data->timeout = jiffies - 1;
3331 ifmgd->assoc_data->timeout_started = true;
3335 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
3336 time_after(jiffies, ifmgd->auth_data->timeout)) {
3337 if (ifmgd->auth_data->done) {
3339 * ok ... we waited for assoc but userspace didn't,
3340 * so let's just kill the auth data
3342 ieee80211_destroy_auth_data(sdata, false);
3343 } else if (ieee80211_probe_auth(sdata)) {
3346 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3348 ieee80211_destroy_auth_data(sdata, false);
3350 mutex_unlock(&ifmgd->mtx);
3351 cfg80211_send_auth_timeout(sdata->dev, bssid);
3352 mutex_lock(&ifmgd->mtx);
3354 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
3355 run_again(ifmgd, ifmgd->auth_data->timeout);
3357 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
3358 time_after(jiffies, ifmgd->assoc_data->timeout)) {
3359 if ((ifmgd->assoc_data->need_beacon &&
3360 !ifmgd->assoc_data->have_beacon) ||
3361 ieee80211_do_assoc(sdata)) {
3364 memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN);
3366 ieee80211_destroy_assoc_data(sdata, false);
3368 mutex_unlock(&ifmgd->mtx);
3369 cfg80211_send_assoc_timeout(sdata->dev, bssid);
3370 mutex_lock(&ifmgd->mtx);
3372 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
3373 run_again(ifmgd, ifmgd->assoc_data->timeout);
3375 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
3376 IEEE80211_STA_CONNECTION_POLL) &&
3377 ifmgd->associated) {
3381 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
3383 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
3384 max_tries = max_nullfunc_tries;
3386 max_tries = max_probe_tries;
3388 /* ACK received for nullfunc probing frame */
3389 if (!ifmgd->probe_send_count)
3390 ieee80211_reset_ap_probe(sdata);
3391 else if (ifmgd->nullfunc_failed) {
3392 if (ifmgd->probe_send_count < max_tries) {
3394 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3395 bssid, ifmgd->probe_send_count,
3397 ieee80211_mgd_probe_ap_send(sdata);
3400 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3402 ieee80211_sta_connection_lost(sdata, bssid,
3403 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3406 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
3407 run_again(ifmgd, ifmgd->probe_timeout);
3408 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
3410 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3411 bssid, probe_wait_ms);
3412 ieee80211_sta_connection_lost(sdata, bssid,
3413 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
3414 } else if (ifmgd->probe_send_count < max_tries) {
3416 "No probe response from AP %pM after %dms, try %d/%i\n",
3417 bssid, probe_wait_ms,
3418 ifmgd->probe_send_count, max_tries);
3419 ieee80211_mgd_probe_ap_send(sdata);
3422 * We actually lost the connection ... or did we?
3425 wiphy_debug(local->hw.wiphy,
3426 "%s: No probe response from AP %pM"
3427 " after %dms, disconnecting.\n",
3429 bssid, probe_wait_ms);
3431 ieee80211_sta_connection_lost(sdata, bssid,
3432 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
3436 mutex_unlock(&ifmgd->mtx);
3439 static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3441 struct ieee80211_sub_if_data *sdata =
3442 (struct ieee80211_sub_if_data *) data;
3443 struct ieee80211_local *local = sdata->local;
3445 if (local->quiescing)
3448 sdata->u.mgd.connection_loss = false;
3449 ieee80211_queue_work(&sdata->local->hw,
3450 &sdata->u.mgd.beacon_connection_loss_work);
3453 static void ieee80211_sta_conn_mon_timer(unsigned long data)
3455 struct ieee80211_sub_if_data *sdata =
3456 (struct ieee80211_sub_if_data *) data;
3457 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3458 struct ieee80211_local *local = sdata->local;
3460 if (local->quiescing)
3463 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
3466 static void ieee80211_sta_monitor_work(struct work_struct *work)
3468 struct ieee80211_sub_if_data *sdata =
3469 container_of(work, struct ieee80211_sub_if_data,
3470 u.mgd.monitor_work);
3472 ieee80211_mgd_probe_ap(sdata, false);
3475 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3479 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
3480 __ieee80211_stop_poll(sdata);
3482 /* let's probe the connection once */
3483 flags = sdata->local->hw.flags;
3484 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
3485 ieee80211_queue_work(&sdata->local->hw,
3486 &sdata->u.mgd.monitor_work);
3487 /* and do all the other regular work too */
3488 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3492 /* interface setup */
3493 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3495 struct ieee80211_if_managed *ifmgd;
3497 ifmgd = &sdata->u.mgd;
3498 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
3499 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
3500 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3501 ieee80211_beacon_connection_loss_work);
3502 INIT_WORK(&ifmgd->csa_connection_drop_work,
3503 ieee80211_csa_connection_drop_work);
3504 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
3505 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
3506 (unsigned long) sdata);
3507 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3508 (unsigned long) sdata);
3509 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3510 (unsigned long) sdata);
3511 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
3512 (unsigned long) sdata);
3515 ifmgd->powersave = sdata->wdev.ps;
3516 ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
3517 ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
3519 mutex_init(&ifmgd->mtx);
3521 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3522 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3524 ifmgd->req_smps = IEEE80211_SMPS_OFF;
3527 /* scan finished notification */
3528 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
3530 struct ieee80211_sub_if_data *sdata;
3532 /* Restart STA timers */
3534 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3535 if (ieee80211_sdata_running(sdata))
3536 ieee80211_restart_sta_timer(sdata);
3541 int ieee80211_max_network_latency(struct notifier_block *nb,
3542 unsigned long data, void *dummy)
3544 s32 latency_usec = (s32) data;
3545 struct ieee80211_local *local =
3546 container_of(nb, struct ieee80211_local,
3547 network_latency_notifier);
3549 mutex_lock(&local->iflist_mtx);
3550 ieee80211_recalc_ps(local, latency_usec);
3551 mutex_unlock(&local->iflist_mtx);
3556 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
3557 struct cfg80211_bss *cbss)
3559 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3560 const u8 *ht_cap_ie, *vht_cap_ie;
3561 const struct ieee80211_ht_cap *ht_cap;
3562 const struct ieee80211_vht_cap *vht_cap;
3565 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
3568 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
3569 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3570 ht_cap = (void *)(ht_cap_ie + 2);
3571 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3573 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
3574 * "Tx Unequal Modulation Supported" fields.
3578 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
3581 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
3582 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
3586 vht_cap = (void *)(vht_cap_ie + 2);
3587 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
3588 for (nss = 8; nss > 0; nss--) {
3589 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
3590 IEEE80211_VHT_MCS_NOT_SUPPORTED)
3593 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
3594 chains = max(chains, nss);
3600 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3601 struct cfg80211_bss *cbss)
3603 struct ieee80211_local *local = sdata->local;
3604 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3605 const struct ieee80211_ht_operation *ht_oper = NULL;
3606 const struct ieee80211_vht_operation *vht_oper = NULL;
3607 struct ieee80211_supported_band *sband;
3608 struct cfg80211_chan_def chandef;
3611 sband = local->hw.wiphy->bands[cbss->channel->band];
3613 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
3614 IEEE80211_STA_DISABLE_80P80MHZ |
3615 IEEE80211_STA_DISABLE_160MHZ);
3619 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3620 sband->ht_cap.ht_supported) {
3621 const u8 *ht_oper_ie, *ht_cap;
3623 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
3624 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
3625 ht_oper = (void *)(ht_oper_ie + 2);
3627 ht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
3628 if (!ht_cap || ht_cap[1] < sizeof(struct ieee80211_ht_cap)) {
3629 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3634 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3635 sband->vht_cap.vht_supported) {
3636 const u8 *vht_oper_ie, *vht_cap;
3638 vht_oper_ie = ieee80211_bss_get_ie(cbss,
3639 WLAN_EID_VHT_OPERATION);
3640 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
3641 vht_oper = (void *)(vht_oper_ie + 2);
3642 if (vht_oper && !ht_oper) {
3645 "AP advertised VHT without HT, disabling both\n");
3646 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3647 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3650 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
3651 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
3652 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3657 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
3662 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
3667 /* will change later if needed */
3668 sdata->smps_mode = IEEE80211_SMPS_OFF;
3671 * If this fails (possibly due to channel context sharing
3672 * on incompatible channels, e.g. 80+80 and 160 sharing the
3673 * same control channel) try to use a smaller bandwidth.
3675 ret = ieee80211_vif_use_channel(sdata, &chandef,
3676 IEEE80211_CHANCTX_SHARED);
3677 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
3678 ifmgd->flags |= chandef_downgrade(&chandef);
3679 ret = ieee80211_vif_use_channel(sdata, &chandef,
3680 IEEE80211_CHANCTX_SHARED);
3685 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3686 struct cfg80211_bss *cbss, bool assoc)
3688 struct ieee80211_local *local = sdata->local;
3689 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3690 struct ieee80211_bss *bss = (void *)cbss->priv;
3691 struct sta_info *new_sta = NULL;
3692 bool have_sta = false;
3695 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3700 have_sta = sta_info_get(sdata, cbss->bssid);
3705 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
3711 u32 rates = 0, basic_rates = 0;
3712 bool have_higher_than_11mbit;
3713 int min_rate = INT_MAX, min_rate_index = -1;
3714 struct ieee80211_supported_band *sband;
3715 const struct cfg80211_bss_ies *ies;
3717 sband = local->hw.wiphy->bands[cbss->channel->band];
3719 err = ieee80211_prep_channel(sdata, cbss);
3721 sta_info_free(local, new_sta);
3725 ieee80211_get_rates(sband, bss->supp_rates,
3726 bss->supp_rates_len,
3727 &rates, &basic_rates,
3728 &have_higher_than_11mbit,
3729 &min_rate, &min_rate_index);
3732 * This used to be a workaround for basic rates missing
3733 * in the association response frame. Now that we no
3734 * longer use the basic rates from there, it probably
3735 * doesn't happen any more, but keep the workaround so
3736 * in case some *other* APs are buggy in different ways
3737 * we can connect -- with a warning.
3739 if (!basic_rates && min_rate_index >= 0) {
3741 "No basic rates, using min rate instead\n");
3742 basic_rates = BIT(min_rate_index);
3745 new_sta->sta.supp_rates[cbss->channel->band] = rates;
3746 sdata->vif.bss_conf.basic_rates = basic_rates;
3748 /* cf. IEEE 802.11 9.2.12 */
3749 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
3750 have_higher_than_11mbit)
3751 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3753 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3755 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3757 /* set timing information */
3758 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
3760 ies = rcu_dereference(cbss->beacon_ies);
3764 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3765 sdata->vif.bss_conf.sync_device_ts =
3766 bss->device_ts_beacon;
3767 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
3768 ies->data, ies->len);
3769 if (tim_ie && tim_ie[1] >= 2)
3770 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
3772 sdata->vif.bss_conf.sync_dtim_count = 0;
3773 } else if (!(local->hw.flags &
3774 IEEE80211_HW_TIMING_BEACON_ONLY)) {
3775 ies = rcu_dereference(cbss->proberesp_ies);
3776 /* must be non-NULL since beacon IEs were NULL */
3777 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3778 sdata->vif.bss_conf.sync_device_ts =
3779 bss->device_ts_presp;
3780 sdata->vif.bss_conf.sync_dtim_count = 0;
3782 sdata->vif.bss_conf.sync_tsf = 0;
3783 sdata->vif.bss_conf.sync_device_ts = 0;
3784 sdata->vif.bss_conf.sync_dtim_count = 0;
3788 /* tell driver about BSSID, basic rates and timing */
3789 ieee80211_bss_info_change_notify(sdata,
3790 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
3791 BSS_CHANGED_BEACON_INT);
3794 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
3796 err = sta_info_insert(new_sta);
3800 "failed to insert STA entry for the AP (error %d)\n",
3805 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
3811 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3812 struct cfg80211_auth_request *req)
3814 struct ieee80211_local *local = sdata->local;
3815 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3816 struct ieee80211_mgd_auth_data *auth_data;
3820 /* prepare auth data structure */
3822 switch (req->auth_type) {
3823 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3824 auth_alg = WLAN_AUTH_OPEN;
3826 case NL80211_AUTHTYPE_SHARED_KEY:
3827 if (IS_ERR(local->wep_tx_tfm))
3829 auth_alg = WLAN_AUTH_SHARED_KEY;
3831 case NL80211_AUTHTYPE_FT:
3832 auth_alg = WLAN_AUTH_FT;
3834 case NL80211_AUTHTYPE_NETWORK_EAP:
3835 auth_alg = WLAN_AUTH_LEAP;
3837 case NL80211_AUTHTYPE_SAE:
3838 auth_alg = WLAN_AUTH_SAE;
3844 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
3845 req->ie_len, GFP_KERNEL);
3849 auth_data->bss = req->bss;
3851 if (req->sae_data_len >= 4) {
3852 __le16 *pos = (__le16 *) req->sae_data;
3853 auth_data->sae_trans = le16_to_cpu(pos[0]);
3854 auth_data->sae_status = le16_to_cpu(pos[1]);
3855 memcpy(auth_data->data, req->sae_data + 4,
3856 req->sae_data_len - 4);
3857 auth_data->data_len += req->sae_data_len - 4;
3860 if (req->ie && req->ie_len) {
3861 memcpy(&auth_data->data[auth_data->data_len],
3862 req->ie, req->ie_len);
3863 auth_data->data_len += req->ie_len;
3866 if (req->key && req->key_len) {
3867 auth_data->key_len = req->key_len;
3868 auth_data->key_idx = req->key_idx;
3869 memcpy(auth_data->key, req->key, req->key_len);
3872 auth_data->algorithm = auth_alg;
3874 /* try to authenticate/probe */
3876 mutex_lock(&ifmgd->mtx);
3878 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
3879 ifmgd->assoc_data) {
3884 if (ifmgd->auth_data)
3885 ieee80211_destroy_auth_data(sdata, false);
3887 /* prep auth_data so we don't go into idle on disassoc */
3888 ifmgd->auth_data = auth_data;
3890 if (ifmgd->associated) {
3891 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3893 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3894 WLAN_REASON_UNSPECIFIED,
3897 __cfg80211_send_deauth(sdata->dev, frame_buf,
3901 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
3903 err = ieee80211_prep_connection(sdata, req->bss, false);
3907 err = ieee80211_probe_auth(sdata);
3909 sta_info_destroy_addr(sdata, req->bss->bssid);
3913 /* hold our own reference */
3914 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
3919 memset(ifmgd->bssid, 0, ETH_ALEN);
3920 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
3921 ifmgd->auth_data = NULL;
3925 mutex_unlock(&ifmgd->mtx);
3930 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3931 struct cfg80211_assoc_request *req)
3933 struct ieee80211_local *local = sdata->local;
3934 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3935 struct ieee80211_bss *bss = (void *)req->bss->priv;
3936 struct ieee80211_mgd_assoc_data *assoc_data;
3937 const struct cfg80211_bss_ies *beacon_ies;
3938 struct ieee80211_supported_band *sband;
3939 const u8 *ssidie, *ht_ie, *vht_ie;
3942 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
3947 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
3953 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
3954 assoc_data->ssid_len = ssidie[1];
3957 mutex_lock(&ifmgd->mtx);
3959 if (ifmgd->associated) {
3960 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3962 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3963 WLAN_REASON_UNSPECIFIED,
3966 __cfg80211_send_deauth(sdata->dev, frame_buf,
3970 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
3975 if (ifmgd->assoc_data) {
3980 if (ifmgd->auth_data) {
3983 /* keep sta info, bssid if matching */
3984 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
3985 ieee80211_destroy_auth_data(sdata, match);
3988 /* prepare assoc data */
3990 ifmgd->beacon_crc_valid = false;
3993 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
3994 * We still associate in non-HT mode (11a/b/g) if any one of these
3995 * ciphers is configured as pairwise.
3996 * We can set this to true for non-11n hardware, that'll be checked
3997 * separately along with the peer capabilities.
3999 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
4000 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
4001 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
4002 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
4003 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4004 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4005 netdev_info(sdata->dev,
4006 "disabling HT/VHT due to WEP/TKIP use\n");
4010 if (req->flags & ASSOC_REQ_DISABLE_HT) {
4011 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4012 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4015 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4016 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4018 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4019 sband = local->hw.wiphy->bands[req->bss->channel->band];
4020 if (!sband->ht_cap.ht_supported ||
4021 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
4022 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4024 netdev_info(sdata->dev,
4025 "disabling HT as WMM/QoS is not supported by the AP\n");
4028 /* disable VHT if we don't support it or the AP doesn't use WMM */
4029 if (!sband->vht_cap.vht_supported ||
4030 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
4031 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4033 netdev_info(sdata->dev,
4034 "disabling VHT as WMM/QoS is not supported by the AP\n");
4037 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
4038 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4039 sizeof(ifmgd->ht_capa_mask));
4041 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4042 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4043 sizeof(ifmgd->vht_capa_mask));
4045 if (req->ie && req->ie_len) {
4046 memcpy(assoc_data->ie, req->ie, req->ie_len);
4047 assoc_data->ie_len = req->ie_len;
4050 assoc_data->bss = req->bss;
4052 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
4053 if (ifmgd->powersave)
4054 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
4056 sdata->smps_mode = IEEE80211_SMPS_OFF;
4058 sdata->smps_mode = ifmgd->req_smps;
4060 assoc_data->capability = req->bss->capability;
4061 assoc_data->wmm = bss->wmm_used &&
4062 (local->hw.queues >= IEEE80211_NUM_ACS);
4063 assoc_data->supp_rates = bss->supp_rates;
4064 assoc_data->supp_rates_len = bss->supp_rates_len;
4067 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
4068 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
4069 assoc_data->ap_ht_param =
4070 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
4072 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4073 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
4074 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
4075 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
4076 sizeof(struct ieee80211_vht_cap));
4078 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4081 if (bss->wmm_used && bss->uapsd_supported &&
4082 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
4083 assoc_data->uapsd = true;
4084 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4086 assoc_data->uapsd = false;
4087 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
4090 if (req->prev_bssid)
4091 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
4094 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
4095 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4097 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4098 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4101 if (req->crypto.control_port)
4102 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4104 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4106 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4107 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
4109 /* kick off associate process */
4111 ifmgd->assoc_data = assoc_data;
4112 ifmgd->dtim_period = 0;
4114 err = ieee80211_prep_connection(sdata, req->bss, true);
4119 beacon_ies = rcu_dereference(req->bss->beacon_ies);
4121 if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
4124 * Wait up to one beacon interval ...
4125 * should this be more if we miss one?
4127 sdata_info(sdata, "waiting for beacon from %pM\n",
4129 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
4130 assoc_data->timeout_started = true;
4131 assoc_data->need_beacon = true;
4132 } else if (beacon_ies) {
4133 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4138 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
4139 const struct ieee80211_tim_ie *tim;
4140 tim = (void *)(tim_ie + 2);
4141 ifmgd->dtim_period = tim->dtim_period;
4142 dtim_count = tim->dtim_count;
4144 assoc_data->have_beacon = true;
4145 assoc_data->timeout = jiffies;
4146 assoc_data->timeout_started = true;
4148 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
4149 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
4150 sdata->vif.bss_conf.sync_device_ts =
4151 bss->device_ts_beacon;
4152 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
4155 assoc_data->timeout = jiffies;
4156 assoc_data->timeout_started = true;
4160 run_again(ifmgd, assoc_data->timeout);
4162 if (bss->corrupt_data) {
4163 char *corrupt_type = "data";
4164 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
4165 if (bss->corrupt_data &
4166 IEEE80211_BSS_CORRUPT_PROBE_RESP)
4167 corrupt_type = "beacon and probe response";
4169 corrupt_type = "beacon";
4170 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
4171 corrupt_type = "probe response";
4172 sdata_info(sdata, "associating with AP with corrupt %s\n",
4179 memset(ifmgd->bssid, 0, ETH_ALEN);
4180 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
4181 ifmgd->assoc_data = NULL;
4185 mutex_unlock(&ifmgd->mtx);
4190 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
4191 struct cfg80211_deauth_request *req)
4193 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4194 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4195 bool tx = !req->local_state_change;
4196 bool sent_frame = false;
4198 mutex_lock(&ifmgd->mtx);
4201 "deauthenticating from %pM by local choice (reason=%d)\n",
4202 req->bssid, req->reason_code);
4204 if (ifmgd->auth_data) {
4205 drv_mgd_prepare_tx(sdata->local, sdata);
4206 ieee80211_send_deauth_disassoc(sdata, req->bssid,
4207 IEEE80211_STYPE_DEAUTH,
4208 req->reason_code, tx,
4210 ieee80211_destroy_auth_data(sdata, false);
4211 mutex_unlock(&ifmgd->mtx);
4217 if (ifmgd->associated &&
4218 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
4219 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4220 req->reason_code, tx, frame_buf);
4223 mutex_unlock(&ifmgd->mtx);
4227 __cfg80211_send_deauth(sdata->dev, frame_buf,
4228 IEEE80211_DEAUTH_FRAME_LEN);
4233 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
4234 struct cfg80211_disassoc_request *req)
4236 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4238 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4240 mutex_lock(&ifmgd->mtx);
4243 * cfg80211 should catch this ... but it's racy since
4244 * we can receive a disassoc frame, process it, hand it
4245 * to cfg80211 while that's in a locked section already
4246 * trying to tell us that the user wants to disconnect.
4248 if (ifmgd->associated != req->bss) {
4249 mutex_unlock(&ifmgd->mtx);
4254 "disassociating from %pM by local choice (reason=%d)\n",
4255 req->bss->bssid, req->reason_code);
4257 memcpy(bssid, req->bss->bssid, ETH_ALEN);
4258 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
4259 req->reason_code, !req->local_state_change,
4261 mutex_unlock(&ifmgd->mtx);
4263 __cfg80211_send_disassoc(sdata->dev, frame_buf,
4264 IEEE80211_DEAUTH_FRAME_LEN);
4269 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
4271 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4274 * Make sure some work items will not run after this,
4275 * they will not do anything but might not have been
4276 * cancelled when disconnecting.
4278 cancel_work_sync(&ifmgd->monitor_work);
4279 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
4280 cancel_work_sync(&ifmgd->request_smps_work);
4281 cancel_work_sync(&ifmgd->csa_connection_drop_work);
4282 cancel_work_sync(&ifmgd->chswitch_work);
4284 mutex_lock(&ifmgd->mtx);
4285 if (ifmgd->assoc_data)
4286 ieee80211_destroy_assoc_data(sdata, false);
4287 if (ifmgd->auth_data)
4288 ieee80211_destroy_auth_data(sdata, false);
4289 del_timer_sync(&ifmgd->timer);
4290 mutex_unlock(&ifmgd->mtx);
4293 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
4294 enum nl80211_cqm_rssi_threshold_event rssi_event,
4297 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4299 trace_api_cqm_rssi_notify(sdata, rssi_event);
4301 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
4303 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);