]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - net/mac80211/mlme.c
c623aba09f3fdfe96d1561cc2befc7b0f73698cb
[mirror_ubuntu-bionic-kernel.git] / net / mac80211 / mlme.c
1 /*
2 * BSS client mode implementation
3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 * Copyright 2013-2014 Intel Mobile Communications GmbH
9 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16 #include <linux/delay.h>
17 #include <linux/if_ether.h>
18 #include <linux/skbuff.h>
19 #include <linux/if_arp.h>
20 #include <linux/etherdevice.h>
21 #include <linux/moduleparam.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/crc32.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
26 #include <net/mac80211.h>
27 #include <asm/unaligned.h>
28
29 #include "ieee80211_i.h"
30 #include "driver-ops.h"
31 #include "rate.h"
32 #include "led.h"
33 #include "fils_aead.h"
34
35 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
36 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
37 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
38 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
39 #define IEEE80211_AUTH_MAX_TRIES 3
40 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
44 #define IEEE80211_ASSOC_MAX_TRIES 3
45
46 static int max_nullfunc_tries = 2;
47 module_param(max_nullfunc_tries, int, 0644);
48 MODULE_PARM_DESC(max_nullfunc_tries,
49 "Maximum nullfunc tx tries before disconnecting (reason 4).");
50
51 static int max_probe_tries = 5;
52 module_param(max_probe_tries, int, 0644);
53 MODULE_PARM_DESC(max_probe_tries,
54 "Maximum probe tries before disconnecting (reason 4).");
55
56 /*
57 * Beacon loss timeout is calculated as N frames times the
58 * advertised beacon interval. This may need to be somewhat
59 * higher than what hardware might detect to account for
60 * delays in the host processing frames. But since we also
61 * probe on beacon miss before declaring the connection lost
62 * default to what we want.
63 */
64 static int beacon_loss_count = 7;
65 module_param(beacon_loss_count, int, 0644);
66 MODULE_PARM_DESC(beacon_loss_count,
67 "Number of beacon intervals before we decide beacon was lost.");
68
69 /*
70 * Time the connection can be idle before we probe
71 * it to see if we can still talk to the AP.
72 */
73 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
74 /*
75 * Time we wait for a probe response after sending
76 * a probe request because of beacon loss or for
77 * checking the connection still works.
78 */
79 static int probe_wait_ms = 500;
80 module_param(probe_wait_ms, int, 0644);
81 MODULE_PARM_DESC(probe_wait_ms,
82 "Maximum time(ms) to wait for probe response"
83 " before disconnecting (reason 4).");
84
85 /*
86 * How many Beacon frames need to have been used in average signal strength
87 * before starting to indicate signal change events.
88 */
89 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
90
91 /*
92 * We can have multiple work items (and connection probing)
93 * scheduling this timer, but we need to take care to only
94 * reschedule it when it should fire _earlier_ than it was
95 * asked for before, or if it's not pending right now. This
96 * function ensures that. Note that it then is required to
97 * run this function for all timeouts after the first one
98 * has happened -- the work that runs from this timer will
99 * do that.
100 */
101 static void run_again(struct ieee80211_sub_if_data *sdata,
102 unsigned long timeout)
103 {
104 sdata_assert_lock(sdata);
105
106 if (!timer_pending(&sdata->u.mgd.timer) ||
107 time_before(timeout, sdata->u.mgd.timer.expires))
108 mod_timer(&sdata->u.mgd.timer, timeout);
109 }
110
111 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
112 {
113 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
114 return;
115
116 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
117 return;
118
119 mod_timer(&sdata->u.mgd.bcn_mon_timer,
120 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
121 }
122
123 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
124 {
125 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
126
127 if (unlikely(!ifmgd->associated))
128 return;
129
130 if (ifmgd->probe_send_count)
131 ifmgd->probe_send_count = 0;
132
133 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
134 return;
135
136 mod_timer(&ifmgd->conn_mon_timer,
137 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
138 }
139
140 static int ecw2cw(int ecw)
141 {
142 return (1 << ecw) - 1;
143 }
144
145 static u32
146 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
147 struct ieee80211_supported_band *sband,
148 struct ieee80211_channel *channel,
149 const struct ieee80211_ht_operation *ht_oper,
150 const struct ieee80211_vht_operation *vht_oper,
151 struct cfg80211_chan_def *chandef, bool tracking)
152 {
153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
154 struct cfg80211_chan_def vht_chandef;
155 struct ieee80211_sta_ht_cap sta_ht_cap;
156 u32 ht_cfreq, ret;
157
158 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
159 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
160
161 chandef->chan = channel;
162 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
163 chandef->center_freq1 = channel->center_freq;
164 chandef->center_freq2 = 0;
165
166 if (!ht_oper || !sta_ht_cap.ht_supported) {
167 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
168 goto out;
169 }
170
171 chandef->width = NL80211_CHAN_WIDTH_20;
172
173 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
174 channel->band);
175 /* check that channel matches the right operating channel */
176 if (!tracking && channel->center_freq != ht_cfreq) {
177 /*
178 * It's possible that some APs are confused here;
179 * Netgear WNDR3700 sometimes reports 4 higher than
180 * the actual channel in association responses, but
181 * since we look at probe response/beacon data here
182 * it should be OK.
183 */
184 sdata_info(sdata,
185 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
186 channel->center_freq, ht_cfreq,
187 ht_oper->primary_chan, channel->band);
188 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
189 goto out;
190 }
191
192 /* check 40 MHz support, if we have it */
193 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
194 ieee80211_chandef_ht_oper(ht_oper, chandef);
195 } else {
196 /* 40 MHz (and 80 MHz) must be supported for VHT */
197 ret = IEEE80211_STA_DISABLE_VHT;
198 /* also mark 40 MHz disabled */
199 ret |= IEEE80211_STA_DISABLE_40MHZ;
200 goto out;
201 }
202
203 if (!vht_oper || !sband->vht_cap.vht_supported) {
204 ret = IEEE80211_STA_DISABLE_VHT;
205 goto out;
206 }
207
208 vht_chandef = *chandef;
209 if (!ieee80211_chandef_vht_oper(vht_oper, &vht_chandef)) {
210 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
211 sdata_info(sdata,
212 "AP VHT information is invalid, disable VHT\n");
213 ret = IEEE80211_STA_DISABLE_VHT;
214 goto out;
215 }
216
217 if (!cfg80211_chandef_valid(&vht_chandef)) {
218 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
219 sdata_info(sdata,
220 "AP VHT information is invalid, disable VHT\n");
221 ret = IEEE80211_STA_DISABLE_VHT;
222 goto out;
223 }
224
225 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
226 ret = 0;
227 goto out;
228 }
229
230 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
231 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
232 sdata_info(sdata,
233 "AP VHT information doesn't match HT, disable VHT\n");
234 ret = IEEE80211_STA_DISABLE_VHT;
235 goto out;
236 }
237
238 *chandef = vht_chandef;
239
240 ret = 0;
241
242 out:
243 /*
244 * When tracking the current AP, don't do any further checks if the
245 * new chandef is identical to the one we're currently using for the
246 * connection. This keeps us from playing ping-pong with regulatory,
247 * without it the following can happen (for example):
248 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
249 * - AP advertises regdom US
250 * - CRDA loads regdom US with 80 MHz prohibited (old database)
251 * - the code below detects an unsupported channel, downgrades, and
252 * we disconnect from the AP in the caller
253 * - disconnect causes CRDA to reload world regdomain and the game
254 * starts anew.
255 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
256 *
257 * It seems possible that there are still scenarios with CSA or real
258 * bandwidth changes where a this could happen, but those cases are
259 * less common and wouldn't completely prevent using the AP.
260 */
261 if (tracking &&
262 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
263 return ret;
264
265 /* don't print the message below for VHT mismatch if VHT is disabled */
266 if (ret & IEEE80211_STA_DISABLE_VHT)
267 vht_chandef = *chandef;
268
269 /*
270 * Ignore the DISABLED flag when we're already connected and only
271 * tracking the APs beacon for bandwidth changes - otherwise we
272 * might get disconnected here if we connect to an AP, update our
273 * regulatory information based on the AP's country IE and the
274 * information we have is wrong/outdated and disables the channel
275 * that we're actually using for the connection to the AP.
276 */
277 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
278 tracking ? 0 :
279 IEEE80211_CHAN_DISABLED)) {
280 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
281 ret = IEEE80211_STA_DISABLE_HT |
282 IEEE80211_STA_DISABLE_VHT;
283 break;
284 }
285
286 ret |= ieee80211_chandef_downgrade(chandef);
287 }
288
289 if (chandef->width != vht_chandef.width && !tracking)
290 sdata_info(sdata,
291 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
292
293 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
294 return ret;
295 }
296
297 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
298 struct sta_info *sta,
299 const struct ieee80211_ht_cap *ht_cap,
300 const struct ieee80211_ht_operation *ht_oper,
301 const struct ieee80211_vht_operation *vht_oper,
302 const u8 *bssid, u32 *changed)
303 {
304 struct ieee80211_local *local = sdata->local;
305 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
306 struct ieee80211_supported_band *sband;
307 struct ieee80211_channel *chan;
308 struct cfg80211_chan_def chandef;
309 u16 ht_opmode;
310 u32 flags;
311 enum ieee80211_sta_rx_bandwidth new_sta_bw;
312 int ret;
313
314 /* if HT was/is disabled, don't track any bandwidth changes */
315 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
316 return 0;
317
318 /* don't check VHT if we associated as non-VHT station */
319 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
320 vht_oper = NULL;
321
322 if (WARN_ON_ONCE(!sta))
323 return -EINVAL;
324
325 /*
326 * if bss configuration changed store the new one -
327 * this may be applicable even if channel is identical
328 */
329 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
330 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
331 *changed |= BSS_CHANGED_HT;
332 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
333 }
334
335 chan = sdata->vif.bss_conf.chandef.chan;
336 sband = local->hw.wiphy->bands[chan->band];
337
338 /* calculate new channel (type) based on HT/VHT operation IEs */
339 flags = ieee80211_determine_chantype(sdata, sband, chan,
340 ht_oper, vht_oper,
341 &chandef, true);
342
343 /*
344 * Downgrade the new channel if we associated with restricted
345 * capabilities. For example, if we associated as a 20 MHz STA
346 * to a 40 MHz AP (due to regulatory, capabilities or config
347 * reasons) then switching to a 40 MHz channel now won't do us
348 * any good -- we couldn't use it with the AP.
349 */
350 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
351 chandef.width == NL80211_CHAN_WIDTH_80P80)
352 flags |= ieee80211_chandef_downgrade(&chandef);
353 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
354 chandef.width == NL80211_CHAN_WIDTH_160)
355 flags |= ieee80211_chandef_downgrade(&chandef);
356 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
357 chandef.width > NL80211_CHAN_WIDTH_20)
358 flags |= ieee80211_chandef_downgrade(&chandef);
359
360 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
361 return 0;
362
363 sdata_info(sdata,
364 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
365 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
366 chandef.center_freq1, chandef.center_freq2);
367
368 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
369 IEEE80211_STA_DISABLE_VHT |
370 IEEE80211_STA_DISABLE_40MHZ |
371 IEEE80211_STA_DISABLE_80P80MHZ |
372 IEEE80211_STA_DISABLE_160MHZ)) ||
373 !cfg80211_chandef_valid(&chandef)) {
374 sdata_info(sdata,
375 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
376 ifmgd->bssid);
377 return -EINVAL;
378 }
379
380 switch (chandef.width) {
381 case NL80211_CHAN_WIDTH_20_NOHT:
382 case NL80211_CHAN_WIDTH_20:
383 new_sta_bw = IEEE80211_STA_RX_BW_20;
384 break;
385 case NL80211_CHAN_WIDTH_40:
386 new_sta_bw = IEEE80211_STA_RX_BW_40;
387 break;
388 case NL80211_CHAN_WIDTH_80:
389 new_sta_bw = IEEE80211_STA_RX_BW_80;
390 break;
391 case NL80211_CHAN_WIDTH_80P80:
392 case NL80211_CHAN_WIDTH_160:
393 new_sta_bw = IEEE80211_STA_RX_BW_160;
394 break;
395 default:
396 return -EINVAL;
397 }
398
399 if (new_sta_bw > sta->cur_max_bandwidth)
400 new_sta_bw = sta->cur_max_bandwidth;
401
402 if (new_sta_bw < sta->sta.bandwidth) {
403 sta->sta.bandwidth = new_sta_bw;
404 rate_control_rate_update(local, sband, sta,
405 IEEE80211_RC_BW_CHANGED);
406 }
407
408 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
409 if (ret) {
410 sdata_info(sdata,
411 "AP %pM changed bandwidth to incompatible one - disconnect\n",
412 ifmgd->bssid);
413 return ret;
414 }
415
416 if (new_sta_bw > sta->sta.bandwidth) {
417 sta->sta.bandwidth = new_sta_bw;
418 rate_control_rate_update(local, sband, sta,
419 IEEE80211_RC_BW_CHANGED);
420 }
421
422 return 0;
423 }
424
425 /* frame sending functions */
426
427 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
428 struct sk_buff *skb, u8 ap_ht_param,
429 struct ieee80211_supported_band *sband,
430 struct ieee80211_channel *channel,
431 enum ieee80211_smps_mode smps)
432 {
433 u8 *pos;
434 u32 flags = channel->flags;
435 u16 cap;
436 struct ieee80211_sta_ht_cap ht_cap;
437
438 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
439
440 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
441 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
442
443 /* determine capability flags */
444 cap = ht_cap.cap;
445
446 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
447 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
448 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
449 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
450 cap &= ~IEEE80211_HT_CAP_SGI_40;
451 }
452 break;
453 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
454 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
455 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
456 cap &= ~IEEE80211_HT_CAP_SGI_40;
457 }
458 break;
459 }
460
461 /*
462 * If 40 MHz was disabled associate as though we weren't
463 * capable of 40 MHz -- some broken APs will never fall
464 * back to trying to transmit in 20 MHz.
465 */
466 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
467 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
468 cap &= ~IEEE80211_HT_CAP_SGI_40;
469 }
470
471 /* set SM PS mode properly */
472 cap &= ~IEEE80211_HT_CAP_SM_PS;
473 switch (smps) {
474 case IEEE80211_SMPS_AUTOMATIC:
475 case IEEE80211_SMPS_NUM_MODES:
476 WARN_ON(1);
477 case IEEE80211_SMPS_OFF:
478 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
479 IEEE80211_HT_CAP_SM_PS_SHIFT;
480 break;
481 case IEEE80211_SMPS_STATIC:
482 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
483 IEEE80211_HT_CAP_SM_PS_SHIFT;
484 break;
485 case IEEE80211_SMPS_DYNAMIC:
486 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
487 IEEE80211_HT_CAP_SM_PS_SHIFT;
488 break;
489 }
490
491 /* reserve and fill IE */
492 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
493 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
494 }
495
496 /* This function determines vht capability flags for the association
497 * and builds the IE.
498 * Note - the function may set the owner of the MU-MIMO capability
499 */
500 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
501 struct sk_buff *skb,
502 struct ieee80211_supported_band *sband,
503 struct ieee80211_vht_cap *ap_vht_cap)
504 {
505 struct ieee80211_local *local = sdata->local;
506 u8 *pos;
507 u32 cap;
508 struct ieee80211_sta_vht_cap vht_cap;
509 u32 mask, ap_bf_sts, our_bf_sts;
510
511 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
512
513 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
514 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
515
516 /* determine capability flags */
517 cap = vht_cap.cap;
518
519 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
520 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
521
522 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
523 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
524 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
525 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
526 }
527
528 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
529 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
530 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
531 }
532
533 /*
534 * Some APs apparently get confused if our capabilities are better
535 * than theirs, so restrict what we advertise in the assoc request.
536 */
537 if (!(ap_vht_cap->vht_cap_info &
538 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
539 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
540 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
541 else if (!(ap_vht_cap->vht_cap_info &
542 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
543 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
544
545 /*
546 * If some other vif is using the MU-MIMO capablity we cannot associate
547 * using MU-MIMO - this will lead to contradictions in the group-id
548 * mechanism.
549 * Ownership is defined since association request, in order to avoid
550 * simultaneous associations with MU-MIMO.
551 */
552 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
553 bool disable_mu_mimo = false;
554 struct ieee80211_sub_if_data *other;
555
556 list_for_each_entry_rcu(other, &local->interfaces, list) {
557 if (other->vif.mu_mimo_owner) {
558 disable_mu_mimo = true;
559 break;
560 }
561 }
562 if (disable_mu_mimo)
563 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
564 else
565 sdata->vif.mu_mimo_owner = true;
566 }
567
568 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
569
570 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
571 our_bf_sts = cap & mask;
572
573 if (ap_bf_sts < our_bf_sts) {
574 cap &= ~mask;
575 cap |= ap_bf_sts;
576 }
577
578 /* reserve and fill IE */
579 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
580 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
581 }
582
583 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
584 {
585 struct ieee80211_local *local = sdata->local;
586 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
587 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
588 struct sk_buff *skb;
589 struct ieee80211_mgmt *mgmt;
590 u8 *pos, qos_info;
591 size_t offset = 0, noffset;
592 int i, count, rates_len, supp_rates_len, shift;
593 u16 capab;
594 struct ieee80211_supported_band *sband;
595 struct ieee80211_chanctx_conf *chanctx_conf;
596 struct ieee80211_channel *chan;
597 u32 rates = 0;
598
599 sdata_assert_lock(sdata);
600
601 rcu_read_lock();
602 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
603 if (WARN_ON(!chanctx_conf)) {
604 rcu_read_unlock();
605 return;
606 }
607 chan = chanctx_conf->def.chan;
608 rcu_read_unlock();
609 sband = local->hw.wiphy->bands[chan->band];
610 shift = ieee80211_vif_get_shift(&sdata->vif);
611
612 if (assoc_data->supp_rates_len) {
613 /*
614 * Get all rates supported by the device and the AP as
615 * some APs don't like getting a superset of their rates
616 * in the association request (e.g. D-Link DAP 1353 in
617 * b-only mode)...
618 */
619 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
620 assoc_data->supp_rates,
621 assoc_data->supp_rates_len,
622 &rates);
623 } else {
624 /*
625 * In case AP not provide any supported rates information
626 * before association, we send information element(s) with
627 * all rates that we support.
628 */
629 rates_len = 0;
630 for (i = 0; i < sband->n_bitrates; i++) {
631 rates |= BIT(i);
632 rates_len++;
633 }
634 }
635
636 skb = alloc_skb(local->hw.extra_tx_headroom +
637 sizeof(*mgmt) + /* bit too much but doesn't matter */
638 2 + assoc_data->ssid_len + /* SSID */
639 4 + rates_len + /* (extended) rates */
640 4 + /* power capability */
641 2 + 2 * sband->n_channels + /* supported channels */
642 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
643 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
644 assoc_data->ie_len + /* extra IEs */
645 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
646 9, /* WMM */
647 GFP_KERNEL);
648 if (!skb)
649 return;
650
651 skb_reserve(skb, local->hw.extra_tx_headroom);
652
653 capab = WLAN_CAPABILITY_ESS;
654
655 if (sband->band == NL80211_BAND_2GHZ) {
656 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
657 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
658 }
659
660 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
661 capab |= WLAN_CAPABILITY_PRIVACY;
662
663 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
664 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
665 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
666
667 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
668 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
669
670 mgmt = skb_put_zero(skb, 24);
671 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
672 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
673 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
674
675 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
676 skb_put(skb, 10);
677 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
678 IEEE80211_STYPE_REASSOC_REQ);
679 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
680 mgmt->u.reassoc_req.listen_interval =
681 cpu_to_le16(local->hw.conf.listen_interval);
682 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
683 ETH_ALEN);
684 } else {
685 skb_put(skb, 4);
686 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
687 IEEE80211_STYPE_ASSOC_REQ);
688 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
689 mgmt->u.assoc_req.listen_interval =
690 cpu_to_le16(local->hw.conf.listen_interval);
691 }
692
693 /* SSID */
694 pos = skb_put(skb, 2 + assoc_data->ssid_len);
695 *pos++ = WLAN_EID_SSID;
696 *pos++ = assoc_data->ssid_len;
697 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
698
699 /* add all rates which were marked to be used above */
700 supp_rates_len = rates_len;
701 if (supp_rates_len > 8)
702 supp_rates_len = 8;
703
704 pos = skb_put(skb, supp_rates_len + 2);
705 *pos++ = WLAN_EID_SUPP_RATES;
706 *pos++ = supp_rates_len;
707
708 count = 0;
709 for (i = 0; i < sband->n_bitrates; i++) {
710 if (BIT(i) & rates) {
711 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
712 5 * (1 << shift));
713 *pos++ = (u8) rate;
714 if (++count == 8)
715 break;
716 }
717 }
718
719 if (rates_len > count) {
720 pos = skb_put(skb, rates_len - count + 2);
721 *pos++ = WLAN_EID_EXT_SUPP_RATES;
722 *pos++ = rates_len - count;
723
724 for (i++; i < sband->n_bitrates; i++) {
725 if (BIT(i) & rates) {
726 int rate;
727 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
728 5 * (1 << shift));
729 *pos++ = (u8) rate;
730 }
731 }
732 }
733
734 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
735 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
736 pos = skb_put(skb, 4);
737 *pos++ = WLAN_EID_PWR_CAPABILITY;
738 *pos++ = 2;
739 *pos++ = 0; /* min tx power */
740 /* max tx power */
741 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
742 }
743
744 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
745 /* TODO: get this in reg domain format */
746 pos = skb_put(skb, 2 * sband->n_channels + 2);
747 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
748 *pos++ = 2 * sband->n_channels;
749 for (i = 0; i < sband->n_channels; i++) {
750 *pos++ = ieee80211_frequency_to_channel(
751 sband->channels[i].center_freq);
752 *pos++ = 1; /* one channel in the subband*/
753 }
754 }
755
756 /* if present, add any custom IEs that go before HT */
757 if (assoc_data->ie_len) {
758 static const u8 before_ht[] = {
759 WLAN_EID_SSID,
760 WLAN_EID_SUPP_RATES,
761 WLAN_EID_EXT_SUPP_RATES,
762 WLAN_EID_PWR_CAPABILITY,
763 WLAN_EID_SUPPORTED_CHANNELS,
764 WLAN_EID_RSN,
765 WLAN_EID_QOS_CAPA,
766 WLAN_EID_RRM_ENABLED_CAPABILITIES,
767 WLAN_EID_MOBILITY_DOMAIN,
768 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
769 WLAN_EID_RIC_DATA, /* reassoc only */
770 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
771 };
772 static const u8 after_ric[] = {
773 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
774 WLAN_EID_HT_CAPABILITY,
775 WLAN_EID_BSS_COEX_2040,
776 /* luckily this is almost always there */
777 WLAN_EID_EXT_CAPABILITY,
778 WLAN_EID_QOS_TRAFFIC_CAPA,
779 WLAN_EID_TIM_BCAST_REQ,
780 WLAN_EID_INTERWORKING,
781 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
782 WLAN_EID_VHT_CAPABILITY,
783 WLAN_EID_OPMODE_NOTIF,
784 };
785
786 noffset = ieee80211_ie_split_ric(assoc_data->ie,
787 assoc_data->ie_len,
788 before_ht,
789 ARRAY_SIZE(before_ht),
790 after_ric,
791 ARRAY_SIZE(after_ric),
792 offset);
793 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
794 offset = noffset;
795 }
796
797 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
798 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
799 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
800
801 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
802 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
803 sband, chan, sdata->smps_mode);
804
805 /* if present, add any custom IEs that go before VHT */
806 if (assoc_data->ie_len) {
807 static const u8 before_vht[] = {
808 /*
809 * no need to list the ones split off before HT
810 * or generated here
811 */
812 WLAN_EID_BSS_COEX_2040,
813 WLAN_EID_EXT_CAPABILITY,
814 WLAN_EID_QOS_TRAFFIC_CAPA,
815 WLAN_EID_TIM_BCAST_REQ,
816 WLAN_EID_INTERWORKING,
817 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
818 };
819
820 /* RIC already taken above, so no need to handle here anymore */
821 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
822 before_vht, ARRAY_SIZE(before_vht),
823 offset);
824 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
825 offset = noffset;
826 }
827
828 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
829 ieee80211_add_vht_ie(sdata, skb, sband,
830 &assoc_data->ap_vht_cap);
831
832 /* if present, add any custom non-vendor IEs that go after HT */
833 if (assoc_data->ie_len) {
834 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
835 assoc_data->ie_len,
836 offset);
837 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
838 offset = noffset;
839 }
840
841 if (assoc_data->wmm) {
842 if (assoc_data->uapsd) {
843 qos_info = ifmgd->uapsd_queues;
844 qos_info |= (ifmgd->uapsd_max_sp_len <<
845 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
846 } else {
847 qos_info = 0;
848 }
849
850 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
851 }
852
853 /* add any remaining custom (i.e. vendor specific here) IEs */
854 if (assoc_data->ie_len) {
855 noffset = assoc_data->ie_len;
856 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
857 }
858
859 if (assoc_data->fils_kek_len &&
860 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
861 dev_kfree_skb(skb);
862 return;
863 }
864
865 drv_mgd_prepare_tx(local, sdata);
866
867 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
868 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
869 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
870 IEEE80211_TX_INTFL_MLME_CONN_TX;
871 ieee80211_tx_skb(sdata, skb);
872 }
873
874 void ieee80211_send_pspoll(struct ieee80211_local *local,
875 struct ieee80211_sub_if_data *sdata)
876 {
877 struct ieee80211_pspoll *pspoll;
878 struct sk_buff *skb;
879
880 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
881 if (!skb)
882 return;
883
884 pspoll = (struct ieee80211_pspoll *) skb->data;
885 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
886
887 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
888 ieee80211_tx_skb(sdata, skb);
889 }
890
891 void ieee80211_send_nullfunc(struct ieee80211_local *local,
892 struct ieee80211_sub_if_data *sdata,
893 bool powersave)
894 {
895 struct sk_buff *skb;
896 struct ieee80211_hdr_3addr *nullfunc;
897 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
898
899 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, true);
900 if (!skb)
901 return;
902
903 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
904 if (powersave)
905 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
906
907 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
908 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
909
910 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
911 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
912
913 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
914 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
915
916 ieee80211_tx_skb(sdata, skb);
917 }
918
919 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
920 struct ieee80211_sub_if_data *sdata)
921 {
922 struct sk_buff *skb;
923 struct ieee80211_hdr *nullfunc;
924 __le16 fc;
925
926 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
927 return;
928
929 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
930 if (!skb)
931 return;
932
933 skb_reserve(skb, local->hw.extra_tx_headroom);
934
935 nullfunc = skb_put_zero(skb, 30);
936 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
937 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
938 nullfunc->frame_control = fc;
939 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
940 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
941 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
942 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
943
944 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
945 ieee80211_tx_skb(sdata, skb);
946 }
947
948 /* spectrum management related things */
949 static void ieee80211_chswitch_work(struct work_struct *work)
950 {
951 struct ieee80211_sub_if_data *sdata =
952 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
953 struct ieee80211_local *local = sdata->local;
954 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
955 int ret;
956
957 if (!ieee80211_sdata_running(sdata))
958 return;
959
960 sdata_lock(sdata);
961 mutex_lock(&local->mtx);
962 mutex_lock(&local->chanctx_mtx);
963
964 if (!ifmgd->associated)
965 goto out;
966
967 if (!sdata->vif.csa_active)
968 goto out;
969
970 /*
971 * using reservation isn't immediate as it may be deferred until later
972 * with multi-vif. once reservation is complete it will re-schedule the
973 * work with no reserved_chanctx so verify chandef to check if it
974 * completed successfully
975 */
976
977 if (sdata->reserved_chanctx) {
978 struct ieee80211_supported_band *sband = NULL;
979 struct sta_info *mgd_sta = NULL;
980 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
981
982 /*
983 * with multi-vif csa driver may call ieee80211_csa_finish()
984 * many times while waiting for other interfaces to use their
985 * reservations
986 */
987 if (sdata->reserved_ready)
988 goto out;
989
990 if (sdata->vif.bss_conf.chandef.width !=
991 sdata->csa_chandef.width) {
992 /*
993 * For managed interface, we need to also update the AP
994 * station bandwidth and align the rate scale algorithm
995 * on the bandwidth change. Here we only consider the
996 * bandwidth of the new channel definition (as channel
997 * switch flow does not have the full HT/VHT/HE
998 * information), assuming that if additional changes are
999 * required they would be done as part of the processing
1000 * of the next beacon from the AP.
1001 */
1002 switch (sdata->csa_chandef.width) {
1003 case NL80211_CHAN_WIDTH_20_NOHT:
1004 case NL80211_CHAN_WIDTH_20:
1005 default:
1006 bw = IEEE80211_STA_RX_BW_20;
1007 break;
1008 case NL80211_CHAN_WIDTH_40:
1009 bw = IEEE80211_STA_RX_BW_40;
1010 break;
1011 case NL80211_CHAN_WIDTH_80:
1012 bw = IEEE80211_STA_RX_BW_80;
1013 break;
1014 case NL80211_CHAN_WIDTH_80P80:
1015 case NL80211_CHAN_WIDTH_160:
1016 bw = IEEE80211_STA_RX_BW_160;
1017 break;
1018 }
1019
1020 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1021 sband =
1022 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1023 }
1024
1025 if (sdata->vif.bss_conf.chandef.width >
1026 sdata->csa_chandef.width) {
1027 mgd_sta->sta.bandwidth = bw;
1028 rate_control_rate_update(local, sband, mgd_sta,
1029 IEEE80211_RC_BW_CHANGED);
1030 }
1031
1032 ret = ieee80211_vif_use_reserved_context(sdata);
1033 if (ret) {
1034 sdata_info(sdata,
1035 "failed to use reserved channel context, disconnecting (err=%d)\n",
1036 ret);
1037 ieee80211_queue_work(&sdata->local->hw,
1038 &ifmgd->csa_connection_drop_work);
1039 goto out;
1040 }
1041
1042 if (sdata->vif.bss_conf.chandef.width <
1043 sdata->csa_chandef.width) {
1044 mgd_sta->sta.bandwidth = bw;
1045 rate_control_rate_update(local, sband, mgd_sta,
1046 IEEE80211_RC_BW_CHANGED);
1047 }
1048
1049 goto out;
1050 }
1051
1052 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1053 &sdata->csa_chandef)) {
1054 sdata_info(sdata,
1055 "failed to finalize channel switch, disconnecting\n");
1056 ieee80211_queue_work(&sdata->local->hw,
1057 &ifmgd->csa_connection_drop_work);
1058 goto out;
1059 }
1060
1061 /* XXX: shouldn't really modify cfg80211-owned data! */
1062 ifmgd->associated->channel = sdata->csa_chandef.chan;
1063
1064 ifmgd->csa_waiting_bcn = true;
1065
1066 ieee80211_sta_reset_beacon_monitor(sdata);
1067 ieee80211_sta_reset_conn_monitor(sdata);
1068
1069 out:
1070 mutex_unlock(&local->chanctx_mtx);
1071 mutex_unlock(&local->mtx);
1072 sdata_unlock(sdata);
1073 }
1074
1075 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1076 {
1077 struct ieee80211_local *local = sdata->local;
1078 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1079 int ret;
1080
1081 sdata_assert_lock(sdata);
1082
1083 WARN_ON(!sdata->vif.csa_active);
1084
1085 if (sdata->csa_block_tx) {
1086 ieee80211_wake_vif_queues(local, sdata,
1087 IEEE80211_QUEUE_STOP_REASON_CSA);
1088 sdata->csa_block_tx = false;
1089 }
1090
1091 sdata->vif.csa_active = false;
1092 ifmgd->csa_waiting_bcn = false;
1093
1094 ret = drv_post_channel_switch(sdata);
1095 if (ret) {
1096 sdata_info(sdata,
1097 "driver post channel switch failed, disconnecting\n");
1098 ieee80211_queue_work(&local->hw,
1099 &ifmgd->csa_connection_drop_work);
1100 return;
1101 }
1102
1103 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1104 }
1105
1106 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1107 {
1108 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1109 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1110
1111 trace_api_chswitch_done(sdata, success);
1112 if (!success) {
1113 sdata_info(sdata,
1114 "driver channel switch failed, disconnecting\n");
1115 ieee80211_queue_work(&sdata->local->hw,
1116 &ifmgd->csa_connection_drop_work);
1117 } else {
1118 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1119 }
1120 }
1121 EXPORT_SYMBOL(ieee80211_chswitch_done);
1122
1123 static void ieee80211_chswitch_timer(struct timer_list *t)
1124 {
1125 struct ieee80211_sub_if_data *sdata =
1126 from_timer(sdata, t, u.mgd.chswitch_timer);
1127
1128 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1129 }
1130
1131 static void
1132 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1133 u64 timestamp, u32 device_timestamp,
1134 struct ieee802_11_elems *elems,
1135 bool beacon)
1136 {
1137 struct ieee80211_local *local = sdata->local;
1138 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1139 struct cfg80211_bss *cbss = ifmgd->associated;
1140 struct ieee80211_chanctx_conf *conf;
1141 struct ieee80211_chanctx *chanctx;
1142 enum nl80211_band current_band;
1143 struct ieee80211_csa_ie csa_ie;
1144 struct ieee80211_channel_switch ch_switch;
1145 int res;
1146
1147 sdata_assert_lock(sdata);
1148
1149 if (!cbss)
1150 return;
1151
1152 if (local->scanning)
1153 return;
1154
1155 /* disregard subsequent announcements if we are already processing */
1156 if (sdata->vif.csa_active)
1157 return;
1158
1159 current_band = cbss->channel->band;
1160 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1161 ifmgd->flags,
1162 ifmgd->associated->bssid, &csa_ie);
1163 if (res < 0)
1164 ieee80211_queue_work(&local->hw,
1165 &ifmgd->csa_connection_drop_work);
1166 if (res)
1167 return;
1168
1169 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1170 IEEE80211_CHAN_DISABLED)) {
1171 sdata_info(sdata,
1172 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1173 ifmgd->associated->bssid,
1174 csa_ie.chandef.chan->center_freq,
1175 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1176 csa_ie.chandef.center_freq2);
1177 ieee80211_queue_work(&local->hw,
1178 &ifmgd->csa_connection_drop_work);
1179 return;
1180 }
1181
1182 if (cfg80211_chandef_identical(&csa_ie.chandef,
1183 &sdata->vif.bss_conf.chandef)) {
1184 if (ifmgd->csa_ignored_same_chan)
1185 return;
1186 sdata_info(sdata,
1187 "AP %pM tries to chanswitch to same channel, ignore\n",
1188 ifmgd->associated->bssid);
1189 ifmgd->csa_ignored_same_chan = true;
1190 return;
1191 }
1192
1193 /*
1194 * Drop all TDLS peers - either we disconnect or move to a different
1195 * channel from this point on. There's no telling what our peer will do.
1196 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1197 * have an incompatible wider chandef.
1198 */
1199 ieee80211_teardown_tdls_peers(sdata);
1200
1201 mutex_lock(&local->mtx);
1202 mutex_lock(&local->chanctx_mtx);
1203 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1204 lockdep_is_held(&local->chanctx_mtx));
1205 if (!conf) {
1206 sdata_info(sdata,
1207 "no channel context assigned to vif?, disconnecting\n");
1208 goto drop_connection;
1209 }
1210
1211 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1212
1213 if (local->use_chanctx &&
1214 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1215 sdata_info(sdata,
1216 "driver doesn't support chan-switch with channel contexts\n");
1217 goto drop_connection;
1218 }
1219
1220 ch_switch.timestamp = timestamp;
1221 ch_switch.device_timestamp = device_timestamp;
1222 ch_switch.block_tx = csa_ie.mode;
1223 ch_switch.chandef = csa_ie.chandef;
1224 ch_switch.count = csa_ie.count;
1225
1226 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1227 sdata_info(sdata,
1228 "preparing for channel switch failed, disconnecting\n");
1229 goto drop_connection;
1230 }
1231
1232 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1233 chanctx->mode, false);
1234 if (res) {
1235 sdata_info(sdata,
1236 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1237 res);
1238 goto drop_connection;
1239 }
1240 mutex_unlock(&local->chanctx_mtx);
1241
1242 sdata->vif.csa_active = true;
1243 sdata->csa_chandef = csa_ie.chandef;
1244 sdata->csa_block_tx = csa_ie.mode;
1245 ifmgd->csa_ignored_same_chan = false;
1246
1247 if (sdata->csa_block_tx)
1248 ieee80211_stop_vif_queues(local, sdata,
1249 IEEE80211_QUEUE_STOP_REASON_CSA);
1250 mutex_unlock(&local->mtx);
1251
1252 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1253 csa_ie.count);
1254
1255 if (local->ops->channel_switch) {
1256 /* use driver's channel switch callback */
1257 drv_channel_switch(local, sdata, &ch_switch);
1258 return;
1259 }
1260
1261 /* channel switch handled in software */
1262 if (csa_ie.count <= 1)
1263 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1264 else
1265 mod_timer(&ifmgd->chswitch_timer,
1266 TU_TO_EXP_TIME((csa_ie.count - 1) *
1267 cbss->beacon_interval));
1268 return;
1269 drop_connection:
1270 /*
1271 * This is just so that the disconnect flow will know that
1272 * we were trying to switch channel and failed. In case the
1273 * mode is 1 (we are not allowed to Tx), we will know not to
1274 * send a deauthentication frame. Those two fields will be
1275 * reset when the disconnection worker runs.
1276 */
1277 sdata->vif.csa_active = true;
1278 sdata->csa_block_tx = csa_ie.mode;
1279
1280 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1281 mutex_unlock(&local->chanctx_mtx);
1282 mutex_unlock(&local->mtx);
1283 }
1284
1285 static bool
1286 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1287 struct ieee80211_channel *channel,
1288 const u8 *country_ie, u8 country_ie_len,
1289 const u8 *pwr_constr_elem,
1290 int *chan_pwr, int *pwr_reduction)
1291 {
1292 struct ieee80211_country_ie_triplet *triplet;
1293 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1294 int i, chan_increment;
1295 bool have_chan_pwr = false;
1296
1297 /* Invalid IE */
1298 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1299 return false;
1300
1301 triplet = (void *)(country_ie + 3);
1302 country_ie_len -= 3;
1303
1304 switch (channel->band) {
1305 default:
1306 WARN_ON_ONCE(1);
1307 /* fall through */
1308 case NL80211_BAND_2GHZ:
1309 case NL80211_BAND_60GHZ:
1310 chan_increment = 1;
1311 break;
1312 case NL80211_BAND_5GHZ:
1313 chan_increment = 4;
1314 break;
1315 }
1316
1317 /* find channel */
1318 while (country_ie_len >= 3) {
1319 u8 first_channel = triplet->chans.first_channel;
1320
1321 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1322 goto next;
1323
1324 for (i = 0; i < triplet->chans.num_channels; i++) {
1325 if (first_channel + i * chan_increment == chan) {
1326 have_chan_pwr = true;
1327 *chan_pwr = triplet->chans.max_power;
1328 break;
1329 }
1330 }
1331 if (have_chan_pwr)
1332 break;
1333
1334 next:
1335 triplet++;
1336 country_ie_len -= 3;
1337 }
1338
1339 if (have_chan_pwr && pwr_constr_elem)
1340 *pwr_reduction = *pwr_constr_elem;
1341 else
1342 *pwr_reduction = 0;
1343
1344 return have_chan_pwr;
1345 }
1346
1347 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1348 struct ieee80211_channel *channel,
1349 const u8 *cisco_dtpc_ie,
1350 int *pwr_level)
1351 {
1352 /* From practical testing, the first data byte of the DTPC element
1353 * seems to contain the requested dBm level, and the CLI on Cisco
1354 * APs clearly state the range is -127 to 127 dBm, which indicates
1355 * a signed byte, although it seemingly never actually goes negative.
1356 * The other byte seems to always be zero.
1357 */
1358 *pwr_level = (__s8)cisco_dtpc_ie[4];
1359 }
1360
1361 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1362 struct ieee80211_channel *channel,
1363 struct ieee80211_mgmt *mgmt,
1364 const u8 *country_ie, u8 country_ie_len,
1365 const u8 *pwr_constr_ie,
1366 const u8 *cisco_dtpc_ie)
1367 {
1368 bool has_80211h_pwr = false, has_cisco_pwr = false;
1369 int chan_pwr = 0, pwr_reduction_80211h = 0;
1370 int pwr_level_cisco, pwr_level_80211h;
1371 int new_ap_level;
1372 __le16 capab = mgmt->u.probe_resp.capab_info;
1373
1374 if (country_ie &&
1375 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1376 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1377 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1378 sdata, channel, country_ie, country_ie_len,
1379 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1380 pwr_level_80211h =
1381 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1382 }
1383
1384 if (cisco_dtpc_ie) {
1385 ieee80211_find_cisco_dtpc(
1386 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1387 has_cisco_pwr = true;
1388 }
1389
1390 if (!has_80211h_pwr && !has_cisco_pwr)
1391 return 0;
1392
1393 /* If we have both 802.11h and Cisco DTPC, apply both limits
1394 * by picking the smallest of the two power levels advertised.
1395 */
1396 if (has_80211h_pwr &&
1397 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1398 new_ap_level = pwr_level_80211h;
1399
1400 if (sdata->ap_power_level == new_ap_level)
1401 return 0;
1402
1403 sdata_dbg(sdata,
1404 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1405 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1406 sdata->u.mgd.bssid);
1407 } else { /* has_cisco_pwr is always true here. */
1408 new_ap_level = pwr_level_cisco;
1409
1410 if (sdata->ap_power_level == new_ap_level)
1411 return 0;
1412
1413 sdata_dbg(sdata,
1414 "Limiting TX power to %d dBm as advertised by %pM\n",
1415 pwr_level_cisco, sdata->u.mgd.bssid);
1416 }
1417
1418 sdata->ap_power_level = new_ap_level;
1419 if (__ieee80211_recalc_txpower(sdata))
1420 return BSS_CHANGED_TXPOWER;
1421 return 0;
1422 }
1423
1424 /* powersave */
1425 static void ieee80211_enable_ps(struct ieee80211_local *local,
1426 struct ieee80211_sub_if_data *sdata)
1427 {
1428 struct ieee80211_conf *conf = &local->hw.conf;
1429
1430 /*
1431 * If we are scanning right now then the parameters will
1432 * take effect when scan finishes.
1433 */
1434 if (local->scanning)
1435 return;
1436
1437 if (conf->dynamic_ps_timeout > 0 &&
1438 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1439 mod_timer(&local->dynamic_ps_timer, jiffies +
1440 msecs_to_jiffies(conf->dynamic_ps_timeout));
1441 } else {
1442 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1443 ieee80211_send_nullfunc(local, sdata, true);
1444
1445 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1446 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1447 return;
1448
1449 conf->flags |= IEEE80211_CONF_PS;
1450 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1451 }
1452 }
1453
1454 static void ieee80211_change_ps(struct ieee80211_local *local)
1455 {
1456 struct ieee80211_conf *conf = &local->hw.conf;
1457
1458 if (local->ps_sdata) {
1459 ieee80211_enable_ps(local, local->ps_sdata);
1460 } else if (conf->flags & IEEE80211_CONF_PS) {
1461 conf->flags &= ~IEEE80211_CONF_PS;
1462 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1463 del_timer_sync(&local->dynamic_ps_timer);
1464 cancel_work_sync(&local->dynamic_ps_enable_work);
1465 }
1466 }
1467
1468 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1469 {
1470 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1471 struct sta_info *sta = NULL;
1472 bool authorized = false;
1473
1474 if (!mgd->powersave)
1475 return false;
1476
1477 if (mgd->broken_ap)
1478 return false;
1479
1480 if (!mgd->associated)
1481 return false;
1482
1483 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1484 return false;
1485
1486 if (!mgd->have_beacon)
1487 return false;
1488
1489 rcu_read_lock();
1490 sta = sta_info_get(sdata, mgd->bssid);
1491 if (sta)
1492 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1493 rcu_read_unlock();
1494
1495 return authorized;
1496 }
1497
1498 /* need to hold RTNL or interface lock */
1499 void ieee80211_recalc_ps(struct ieee80211_local *local)
1500 {
1501 struct ieee80211_sub_if_data *sdata, *found = NULL;
1502 int count = 0;
1503 int timeout;
1504
1505 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1506 local->ps_sdata = NULL;
1507 return;
1508 }
1509
1510 list_for_each_entry(sdata, &local->interfaces, list) {
1511 if (!ieee80211_sdata_running(sdata))
1512 continue;
1513 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1514 /* If an AP vif is found, then disable PS
1515 * by setting the count to zero thereby setting
1516 * ps_sdata to NULL.
1517 */
1518 count = 0;
1519 break;
1520 }
1521 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1522 continue;
1523 found = sdata;
1524 count++;
1525 }
1526
1527 if (count == 1 && ieee80211_powersave_allowed(found)) {
1528 u8 dtimper = found->u.mgd.dtim_period;
1529
1530 timeout = local->dynamic_ps_forced_timeout;
1531 if (timeout < 0)
1532 timeout = 100;
1533 local->hw.conf.dynamic_ps_timeout = timeout;
1534
1535 /* If the TIM IE is invalid, pretend the value is 1 */
1536 if (!dtimper)
1537 dtimper = 1;
1538
1539 local->hw.conf.ps_dtim_period = dtimper;
1540 local->ps_sdata = found;
1541 } else {
1542 local->ps_sdata = NULL;
1543 }
1544
1545 ieee80211_change_ps(local);
1546 }
1547
1548 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1549 {
1550 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1551
1552 if (sdata->vif.bss_conf.ps != ps_allowed) {
1553 sdata->vif.bss_conf.ps = ps_allowed;
1554 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1555 }
1556 }
1557
1558 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1559 {
1560 struct ieee80211_local *local =
1561 container_of(work, struct ieee80211_local,
1562 dynamic_ps_disable_work);
1563
1564 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1565 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1566 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1567 }
1568
1569 ieee80211_wake_queues_by_reason(&local->hw,
1570 IEEE80211_MAX_QUEUE_MAP,
1571 IEEE80211_QUEUE_STOP_REASON_PS,
1572 false);
1573 }
1574
1575 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1576 {
1577 struct ieee80211_local *local =
1578 container_of(work, struct ieee80211_local,
1579 dynamic_ps_enable_work);
1580 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1581 struct ieee80211_if_managed *ifmgd;
1582 unsigned long flags;
1583 int q;
1584
1585 /* can only happen when PS was just disabled anyway */
1586 if (!sdata)
1587 return;
1588
1589 ifmgd = &sdata->u.mgd;
1590
1591 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1592 return;
1593
1594 if (local->hw.conf.dynamic_ps_timeout > 0) {
1595 /* don't enter PS if TX frames are pending */
1596 if (drv_tx_frames_pending(local)) {
1597 mod_timer(&local->dynamic_ps_timer, jiffies +
1598 msecs_to_jiffies(
1599 local->hw.conf.dynamic_ps_timeout));
1600 return;
1601 }
1602
1603 /*
1604 * transmission can be stopped by others which leads to
1605 * dynamic_ps_timer expiry. Postpone the ps timer if it
1606 * is not the actual idle state.
1607 */
1608 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1609 for (q = 0; q < local->hw.queues; q++) {
1610 if (local->queue_stop_reasons[q]) {
1611 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1612 flags);
1613 mod_timer(&local->dynamic_ps_timer, jiffies +
1614 msecs_to_jiffies(
1615 local->hw.conf.dynamic_ps_timeout));
1616 return;
1617 }
1618 }
1619 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1620 }
1621
1622 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1623 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1624 if (drv_tx_frames_pending(local)) {
1625 mod_timer(&local->dynamic_ps_timer, jiffies +
1626 msecs_to_jiffies(
1627 local->hw.conf.dynamic_ps_timeout));
1628 } else {
1629 ieee80211_send_nullfunc(local, sdata, true);
1630 /* Flush to get the tx status of nullfunc frame */
1631 ieee80211_flush_queues(local, sdata, false);
1632 }
1633 }
1634
1635 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1636 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1637 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1638 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1639 local->hw.conf.flags |= IEEE80211_CONF_PS;
1640 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1641 }
1642 }
1643
1644 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1645 {
1646 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1647
1648 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1649 }
1650
1651 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1652 {
1653 struct delayed_work *delayed_work = to_delayed_work(work);
1654 struct ieee80211_sub_if_data *sdata =
1655 container_of(delayed_work, struct ieee80211_sub_if_data,
1656 dfs_cac_timer_work);
1657 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1658
1659 mutex_lock(&sdata->local->mtx);
1660 if (sdata->wdev.cac_started) {
1661 ieee80211_vif_release_channel(sdata);
1662 cfg80211_cac_event(sdata->dev, &chandef,
1663 NL80211_RADAR_CAC_FINISHED,
1664 GFP_KERNEL);
1665 }
1666 mutex_unlock(&sdata->local->mtx);
1667 }
1668
1669 static bool
1670 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1671 {
1672 struct ieee80211_local *local = sdata->local;
1673 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1674 bool ret = false;
1675 int ac;
1676
1677 if (local->hw.queues < IEEE80211_NUM_ACS)
1678 return false;
1679
1680 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1681 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1682 int non_acm_ac;
1683 unsigned long now = jiffies;
1684
1685 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1686 tx_tspec->admitted_time &&
1687 time_after(now, tx_tspec->time_slice_start + HZ)) {
1688 tx_tspec->consumed_tx_time = 0;
1689 tx_tspec->time_slice_start = now;
1690
1691 if (tx_tspec->downgraded)
1692 tx_tspec->action =
1693 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1694 }
1695
1696 switch (tx_tspec->action) {
1697 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1698 /* take the original parameters */
1699 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1700 sdata_err(sdata,
1701 "failed to set TX queue parameters for queue %d\n",
1702 ac);
1703 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1704 tx_tspec->downgraded = false;
1705 ret = true;
1706 break;
1707 case TX_TSPEC_ACTION_DOWNGRADE:
1708 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1709 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1710 ret = true;
1711 break;
1712 }
1713 /* downgrade next lower non-ACM AC */
1714 for (non_acm_ac = ac + 1;
1715 non_acm_ac < IEEE80211_NUM_ACS;
1716 non_acm_ac++)
1717 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1718 break;
1719 /* Usually the loop will result in using BK even if it
1720 * requires admission control, but such a configuration
1721 * makes no sense and we have to transmit somehow - the
1722 * AC selection does the same thing.
1723 * If we started out trying to downgrade from BK, then
1724 * the extra condition here might be needed.
1725 */
1726 if (non_acm_ac >= IEEE80211_NUM_ACS)
1727 non_acm_ac = IEEE80211_AC_BK;
1728 if (drv_conf_tx(local, sdata, ac,
1729 &sdata->tx_conf[non_acm_ac]))
1730 sdata_err(sdata,
1731 "failed to set TX queue parameters for queue %d\n",
1732 ac);
1733 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1734 ret = true;
1735 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1736 tx_tspec->time_slice_start + HZ - now + 1);
1737 break;
1738 case TX_TSPEC_ACTION_NONE:
1739 /* nothing now */
1740 break;
1741 }
1742 }
1743
1744 return ret;
1745 }
1746
1747 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1748 {
1749 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1750 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1751 }
1752
1753 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1754 {
1755 struct ieee80211_sub_if_data *sdata;
1756
1757 sdata = container_of(work, struct ieee80211_sub_if_data,
1758 u.mgd.tx_tspec_wk.work);
1759 ieee80211_sta_handle_tspec_ac_params(sdata);
1760 }
1761
1762 /* MLME */
1763 static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
1764 struct ieee80211_sub_if_data *sdata,
1765 const u8 *wmm_param, size_t wmm_param_len)
1766 {
1767 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1768 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1769 size_t left;
1770 int count, ac;
1771 const u8 *pos;
1772 u8 uapsd_queues = 0;
1773
1774 if (!local->ops->conf_tx)
1775 return false;
1776
1777 if (local->hw.queues < IEEE80211_NUM_ACS)
1778 return false;
1779
1780 if (!wmm_param)
1781 return false;
1782
1783 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1784 return false;
1785
1786 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1787 uapsd_queues = ifmgd->uapsd_queues;
1788
1789 count = wmm_param[6] & 0x0f;
1790 if (count == ifmgd->wmm_last_param_set)
1791 return false;
1792 ifmgd->wmm_last_param_set = count;
1793
1794 pos = wmm_param + 8;
1795 left = wmm_param_len - 8;
1796
1797 memset(&params, 0, sizeof(params));
1798
1799 sdata->wmm_acm = 0;
1800 for (; left >= 4; left -= 4, pos += 4) {
1801 int aci = (pos[0] >> 5) & 0x03;
1802 int acm = (pos[0] >> 4) & 0x01;
1803 bool uapsd = false;
1804
1805 switch (aci) {
1806 case 1: /* AC_BK */
1807 ac = IEEE80211_AC_BK;
1808 if (acm)
1809 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
1810 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1811 uapsd = true;
1812 break;
1813 case 2: /* AC_VI */
1814 ac = IEEE80211_AC_VI;
1815 if (acm)
1816 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
1817 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1818 uapsd = true;
1819 break;
1820 case 3: /* AC_VO */
1821 ac = IEEE80211_AC_VO;
1822 if (acm)
1823 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
1824 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1825 uapsd = true;
1826 break;
1827 case 0: /* AC_BE */
1828 default:
1829 ac = IEEE80211_AC_BE;
1830 if (acm)
1831 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
1832 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1833 uapsd = true;
1834 break;
1835 }
1836
1837 params[ac].aifs = pos[0] & 0x0f;
1838
1839 if (params[ac].aifs < 2) {
1840 sdata_info(sdata,
1841 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
1842 params[ac].aifs, aci);
1843 params[ac].aifs = 2;
1844 }
1845 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1846 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
1847 params[ac].txop = get_unaligned_le16(pos + 2);
1848 params[ac].acm = acm;
1849 params[ac].uapsd = uapsd;
1850
1851 if (params->cw_min == 0 ||
1852 params[ac].cw_min > params[ac].cw_max) {
1853 sdata_info(sdata,
1854 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1855 params[ac].cw_min, params[ac].cw_max, aci);
1856 return false;
1857 }
1858 }
1859
1860 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1861 mlme_dbg(sdata,
1862 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1863 ac, params[ac].acm,
1864 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
1865 params[ac].txop, params[ac].uapsd,
1866 ifmgd->tx_tspec[ac].downgraded);
1867 sdata->tx_conf[ac] = params[ac];
1868 if (!ifmgd->tx_tspec[ac].downgraded &&
1869 drv_conf_tx(local, sdata, ac, &params[ac]))
1870 sdata_err(sdata,
1871 "failed to set TX queue parameters for AC %d\n",
1872 ac);
1873 }
1874
1875 /* enable WMM or activate new settings */
1876 sdata->vif.bss_conf.qos = true;
1877 return true;
1878 }
1879
1880 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1881 {
1882 lockdep_assert_held(&sdata->local->mtx);
1883
1884 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
1885 ieee80211_run_deferred_scan(sdata->local);
1886 }
1887
1888 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1889 {
1890 mutex_lock(&sdata->local->mtx);
1891 __ieee80211_stop_poll(sdata);
1892 mutex_unlock(&sdata->local->mtx);
1893 }
1894
1895 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1896 u16 capab, bool erp_valid, u8 erp)
1897 {
1898 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1899 struct ieee80211_supported_band *sband;
1900 u32 changed = 0;
1901 bool use_protection;
1902 bool use_short_preamble;
1903 bool use_short_slot;
1904
1905 sband = ieee80211_get_sband(sdata);
1906 if (!sband)
1907 return changed;
1908
1909 if (erp_valid) {
1910 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1911 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1912 } else {
1913 use_protection = false;
1914 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1915 }
1916
1917 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
1918 if (sband->band == NL80211_BAND_5GHZ)
1919 use_short_slot = true;
1920
1921 if (use_protection != bss_conf->use_cts_prot) {
1922 bss_conf->use_cts_prot = use_protection;
1923 changed |= BSS_CHANGED_ERP_CTS_PROT;
1924 }
1925
1926 if (use_short_preamble != bss_conf->use_short_preamble) {
1927 bss_conf->use_short_preamble = use_short_preamble;
1928 changed |= BSS_CHANGED_ERP_PREAMBLE;
1929 }
1930
1931 if (use_short_slot != bss_conf->use_short_slot) {
1932 bss_conf->use_short_slot = use_short_slot;
1933 changed |= BSS_CHANGED_ERP_SLOT;
1934 }
1935
1936 return changed;
1937 }
1938
1939 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
1940 struct cfg80211_bss *cbss,
1941 u32 bss_info_changed)
1942 {
1943 struct ieee80211_bss *bss = (void *)cbss->priv;
1944 struct ieee80211_local *local = sdata->local;
1945 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1946
1947 bss_info_changed |= BSS_CHANGED_ASSOC;
1948 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
1949 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
1950
1951 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1952 beacon_loss_count * bss_conf->beacon_int));
1953
1954 sdata->u.mgd.associated = cbss;
1955 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
1956
1957 ieee80211_check_rate_mask(sdata);
1958
1959 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1960
1961 if (sdata->vif.p2p ||
1962 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
1963 const struct cfg80211_bss_ies *ies;
1964
1965 rcu_read_lock();
1966 ies = rcu_dereference(cbss->ies);
1967 if (ies) {
1968 int ret;
1969
1970 ret = cfg80211_get_p2p_attr(
1971 ies->data, ies->len,
1972 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1973 (u8 *) &bss_conf->p2p_noa_attr,
1974 sizeof(bss_conf->p2p_noa_attr));
1975 if (ret >= 2) {
1976 sdata->u.mgd.p2p_noa_index =
1977 bss_conf->p2p_noa_attr.index;
1978 bss_info_changed |= BSS_CHANGED_P2P_PS;
1979 }
1980 }
1981 rcu_read_unlock();
1982 }
1983
1984 /* just to be sure */
1985 ieee80211_stop_poll(sdata);
1986
1987 ieee80211_led_assoc(local, 1);
1988
1989 if (sdata->u.mgd.have_beacon) {
1990 /*
1991 * If the AP is buggy we may get here with no DTIM period
1992 * known, so assume it's 1 which is the only safe assumption
1993 * in that case, although if the TIM IE is broken powersave
1994 * probably just won't work at all.
1995 */
1996 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
1997 bss_conf->beacon_rate = bss->beacon_rate;
1998 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
1999 } else {
2000 bss_conf->beacon_rate = NULL;
2001 bss_conf->dtim_period = 0;
2002 }
2003
2004 bss_conf->assoc = 1;
2005
2006 /* Tell the driver to monitor connection quality (if supported) */
2007 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2008 bss_conf->cqm_rssi_thold)
2009 bss_info_changed |= BSS_CHANGED_CQM;
2010
2011 /* Enable ARP filtering */
2012 if (bss_conf->arp_addr_cnt)
2013 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2014
2015 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2016
2017 mutex_lock(&local->iflist_mtx);
2018 ieee80211_recalc_ps(local);
2019 mutex_unlock(&local->iflist_mtx);
2020
2021 ieee80211_recalc_smps(sdata);
2022 ieee80211_recalc_ps_vif(sdata);
2023
2024 netif_carrier_on(sdata->dev);
2025 }
2026
2027 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2028 u16 stype, u16 reason, bool tx,
2029 u8 *frame_buf)
2030 {
2031 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2032 struct ieee80211_local *local = sdata->local;
2033 u32 changed = 0;
2034
2035 sdata_assert_lock(sdata);
2036
2037 if (WARN_ON_ONCE(tx && !frame_buf))
2038 return;
2039
2040 if (WARN_ON(!ifmgd->associated))
2041 return;
2042
2043 ieee80211_stop_poll(sdata);
2044
2045 ifmgd->associated = NULL;
2046 netif_carrier_off(sdata->dev);
2047
2048 /*
2049 * if we want to get out of ps before disassoc (why?) we have
2050 * to do it before sending disassoc, as otherwise the null-packet
2051 * won't be valid.
2052 */
2053 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2054 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2055 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2056 }
2057 local->ps_sdata = NULL;
2058
2059 /* disable per-vif ps */
2060 ieee80211_recalc_ps_vif(sdata);
2061
2062 /* make sure ongoing transmission finishes */
2063 synchronize_net();
2064
2065 /*
2066 * drop any frame before deauth/disassoc, this can be data or
2067 * management frame. Since we are disconnecting, we should not
2068 * insist sending these frames which can take time and delay
2069 * the disconnection and possible the roaming.
2070 */
2071 if (tx)
2072 ieee80211_flush_queues(local, sdata, true);
2073
2074 /* deauthenticate/disassociate now */
2075 if (tx || frame_buf)
2076 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
2077 reason, tx, frame_buf);
2078
2079 /* flush out frame - make sure the deauth was actually sent */
2080 if (tx)
2081 ieee80211_flush_queues(local, sdata, false);
2082
2083 /* clear bssid only after building the needed mgmt frames */
2084 eth_zero_addr(ifmgd->bssid);
2085
2086 /* remove AP and TDLS peers */
2087 sta_info_flush(sdata);
2088
2089 /* finally reset all BSS / config parameters */
2090 changed |= ieee80211_reset_erp_info(sdata);
2091
2092 ieee80211_led_assoc(local, 0);
2093 changed |= BSS_CHANGED_ASSOC;
2094 sdata->vif.bss_conf.assoc = false;
2095
2096 ifmgd->p2p_noa_index = -1;
2097 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2098 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2099
2100 /* on the next assoc, re-program HT/VHT parameters */
2101 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2102 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2103 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2104 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2105
2106 /* reset MU-MIMO ownership and group data */
2107 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2108 sizeof(sdata->vif.bss_conf.mu_group.membership));
2109 memset(sdata->vif.bss_conf.mu_group.position, 0,
2110 sizeof(sdata->vif.bss_conf.mu_group.position));
2111 changed |= BSS_CHANGED_MU_GROUPS;
2112 sdata->vif.mu_mimo_owner = false;
2113
2114 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2115
2116 del_timer_sync(&local->dynamic_ps_timer);
2117 cancel_work_sync(&local->dynamic_ps_enable_work);
2118
2119 /* Disable ARP filtering */
2120 if (sdata->vif.bss_conf.arp_addr_cnt)
2121 changed |= BSS_CHANGED_ARP_FILTER;
2122
2123 sdata->vif.bss_conf.qos = false;
2124 changed |= BSS_CHANGED_QOS;
2125
2126 /* The BSSID (not really interesting) and HT changed */
2127 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2128 ieee80211_bss_info_change_notify(sdata, changed);
2129
2130 /* disassociated - set to defaults now */
2131 ieee80211_set_wmm_default(sdata, false, false);
2132
2133 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2134 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2135 del_timer_sync(&sdata->u.mgd.timer);
2136 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2137
2138 sdata->vif.bss_conf.dtim_period = 0;
2139 sdata->vif.bss_conf.beacon_rate = NULL;
2140
2141 ifmgd->have_beacon = false;
2142
2143 ifmgd->flags = 0;
2144 mutex_lock(&local->mtx);
2145 ieee80211_vif_release_channel(sdata);
2146
2147 sdata->vif.csa_active = false;
2148 ifmgd->csa_waiting_bcn = false;
2149 ifmgd->csa_ignored_same_chan = false;
2150 if (sdata->csa_block_tx) {
2151 ieee80211_wake_vif_queues(local, sdata,
2152 IEEE80211_QUEUE_STOP_REASON_CSA);
2153 sdata->csa_block_tx = false;
2154 }
2155 mutex_unlock(&local->mtx);
2156
2157 /* existing TX TSPEC sessions no longer exist */
2158 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2159 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2160
2161 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2162 }
2163
2164 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2165 struct ieee80211_hdr *hdr)
2166 {
2167 /*
2168 * We can postpone the mgd.timer whenever receiving unicast frames
2169 * from AP because we know that the connection is working both ways
2170 * at that time. But multicast frames (and hence also beacons) must
2171 * be ignored here, because we need to trigger the timer during
2172 * data idle periods for sending the periodic probe request to the
2173 * AP we're connected to.
2174 */
2175 if (is_multicast_ether_addr(hdr->addr1))
2176 return;
2177
2178 ieee80211_sta_reset_conn_monitor(sdata);
2179 }
2180
2181 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2182 {
2183 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2184 struct ieee80211_local *local = sdata->local;
2185
2186 mutex_lock(&local->mtx);
2187 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2188 goto out;
2189
2190 __ieee80211_stop_poll(sdata);
2191
2192 mutex_lock(&local->iflist_mtx);
2193 ieee80211_recalc_ps(local);
2194 mutex_unlock(&local->iflist_mtx);
2195
2196 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2197 goto out;
2198
2199 /*
2200 * We've received a probe response, but are not sure whether
2201 * we have or will be receiving any beacons or data, so let's
2202 * schedule the timers again, just in case.
2203 */
2204 ieee80211_sta_reset_beacon_monitor(sdata);
2205
2206 mod_timer(&ifmgd->conn_mon_timer,
2207 round_jiffies_up(jiffies +
2208 IEEE80211_CONNECTION_IDLE_TIME));
2209 out:
2210 mutex_unlock(&local->mtx);
2211 }
2212
2213 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2214 struct ieee80211_hdr *hdr,
2215 u16 tx_time)
2216 {
2217 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2218 u16 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
2219 int ac = ieee80211_ac_from_tid(tid);
2220 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2221 unsigned long now = jiffies;
2222
2223 if (likely(!tx_tspec->admitted_time))
2224 return;
2225
2226 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2227 tx_tspec->consumed_tx_time = 0;
2228 tx_tspec->time_slice_start = now;
2229
2230 if (tx_tspec->downgraded) {
2231 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2232 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2233 }
2234 }
2235
2236 if (tx_tspec->downgraded)
2237 return;
2238
2239 tx_tspec->consumed_tx_time += tx_time;
2240
2241 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2242 tx_tspec->downgraded = true;
2243 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2244 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2245 }
2246 }
2247
2248 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2249 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2250 {
2251 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2252
2253 if (!ieee80211_is_data(hdr->frame_control))
2254 return;
2255
2256 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2257 sdata->u.mgd.probe_send_count > 0) {
2258 if (ack)
2259 ieee80211_sta_reset_conn_monitor(sdata);
2260 else
2261 sdata->u.mgd.nullfunc_failed = true;
2262 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2263 return;
2264 }
2265
2266 if (ack)
2267 ieee80211_sta_reset_conn_monitor(sdata);
2268 }
2269
2270 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2271 {
2272 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2273 const u8 *ssid;
2274 u8 *dst = ifmgd->associated->bssid;
2275 u8 unicast_limit = max(1, max_probe_tries - 3);
2276 struct sta_info *sta;
2277
2278 /*
2279 * Try sending broadcast probe requests for the last three
2280 * probe requests after the first ones failed since some
2281 * buggy APs only support broadcast probe requests.
2282 */
2283 if (ifmgd->probe_send_count >= unicast_limit)
2284 dst = NULL;
2285
2286 /*
2287 * When the hardware reports an accurate Tx ACK status, it's
2288 * better to send a nullfunc frame instead of a probe request,
2289 * as it will kick us off the AP quickly if we aren't associated
2290 * anymore. The timeout will be reset if the frame is ACKed by
2291 * the AP.
2292 */
2293 ifmgd->probe_send_count++;
2294
2295 if (dst) {
2296 mutex_lock(&sdata->local->sta_mtx);
2297 sta = sta_info_get(sdata, dst);
2298 if (!WARN_ON(!sta))
2299 ieee80211_check_fast_rx(sta);
2300 mutex_unlock(&sdata->local->sta_mtx);
2301 }
2302
2303 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2304 ifmgd->nullfunc_failed = false;
2305 ieee80211_send_nullfunc(sdata->local, sdata, false);
2306 } else {
2307 int ssid_len;
2308
2309 rcu_read_lock();
2310 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
2311 if (WARN_ON_ONCE(ssid == NULL))
2312 ssid_len = 0;
2313 else
2314 ssid_len = ssid[1];
2315
2316 ieee80211_send_probe_req(sdata, sdata->vif.addr, dst,
2317 ssid + 2, ssid_len, NULL,
2318 0, (u32) -1, true, 0,
2319 ifmgd->associated->channel, false);
2320 rcu_read_unlock();
2321 }
2322
2323 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2324 run_again(sdata, ifmgd->probe_timeout);
2325 }
2326
2327 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2328 bool beacon)
2329 {
2330 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2331 bool already = false;
2332
2333 if (!ieee80211_sdata_running(sdata))
2334 return;
2335
2336 sdata_lock(sdata);
2337
2338 if (!ifmgd->associated)
2339 goto out;
2340
2341 mutex_lock(&sdata->local->mtx);
2342
2343 if (sdata->local->tmp_channel || sdata->local->scanning) {
2344 mutex_unlock(&sdata->local->mtx);
2345 goto out;
2346 }
2347
2348 if (beacon) {
2349 mlme_dbg_ratelimited(sdata,
2350 "detected beacon loss from AP (missed %d beacons) - probing\n",
2351 beacon_loss_count);
2352
2353 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2354 }
2355
2356 /*
2357 * The driver/our work has already reported this event or the
2358 * connection monitoring has kicked in and we have already sent
2359 * a probe request. Or maybe the AP died and the driver keeps
2360 * reporting until we disassociate...
2361 *
2362 * In either case we have to ignore the current call to this
2363 * function (except for setting the correct probe reason bit)
2364 * because otherwise we would reset the timer every time and
2365 * never check whether we received a probe response!
2366 */
2367 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2368 already = true;
2369
2370 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2371
2372 mutex_unlock(&sdata->local->mtx);
2373
2374 if (already)
2375 goto out;
2376
2377 mutex_lock(&sdata->local->iflist_mtx);
2378 ieee80211_recalc_ps(sdata->local);
2379 mutex_unlock(&sdata->local->iflist_mtx);
2380
2381 ifmgd->probe_send_count = 0;
2382 ieee80211_mgd_probe_ap_send(sdata);
2383 out:
2384 sdata_unlock(sdata);
2385 }
2386
2387 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2388 struct ieee80211_vif *vif)
2389 {
2390 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2391 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2392 struct cfg80211_bss *cbss;
2393 struct sk_buff *skb;
2394 const u8 *ssid;
2395 int ssid_len;
2396
2397 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2398 return NULL;
2399
2400 sdata_assert_lock(sdata);
2401
2402 if (ifmgd->associated)
2403 cbss = ifmgd->associated;
2404 else if (ifmgd->auth_data)
2405 cbss = ifmgd->auth_data->bss;
2406 else if (ifmgd->assoc_data)
2407 cbss = ifmgd->assoc_data->bss;
2408 else
2409 return NULL;
2410
2411 rcu_read_lock();
2412 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2413 if (WARN_ON_ONCE(ssid == NULL))
2414 ssid_len = 0;
2415 else
2416 ssid_len = ssid[1];
2417
2418 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2419 (u32) -1, cbss->channel,
2420 ssid + 2, ssid_len,
2421 NULL, 0, true);
2422 rcu_read_unlock();
2423
2424 return skb;
2425 }
2426 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2427
2428 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2429 const u8 *buf, size_t len, bool tx,
2430 u16 reason)
2431 {
2432 struct ieee80211_event event = {
2433 .type = MLME_EVENT,
2434 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2435 .u.mlme.reason = reason,
2436 };
2437
2438 if (tx)
2439 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2440 else
2441 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2442
2443 drv_event_callback(sdata->local, sdata, &event);
2444 }
2445
2446 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2447 {
2448 struct ieee80211_local *local = sdata->local;
2449 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2450 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2451 bool tx;
2452
2453 sdata_lock(sdata);
2454 if (!ifmgd->associated) {
2455 sdata_unlock(sdata);
2456 return;
2457 }
2458
2459 tx = !sdata->csa_block_tx;
2460
2461 /* AP is probably out of range (or not reachable for another reason) so
2462 * remove the bss struct for that AP.
2463 */
2464 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2465
2466 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2467 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2468 tx, frame_buf);
2469 mutex_lock(&local->mtx);
2470 sdata->vif.csa_active = false;
2471 ifmgd->csa_waiting_bcn = false;
2472 if (sdata->csa_block_tx) {
2473 ieee80211_wake_vif_queues(local, sdata,
2474 IEEE80211_QUEUE_STOP_REASON_CSA);
2475 sdata->csa_block_tx = false;
2476 }
2477 mutex_unlock(&local->mtx);
2478
2479 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2480 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2481
2482 sdata_unlock(sdata);
2483 }
2484
2485 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2486 {
2487 struct ieee80211_sub_if_data *sdata =
2488 container_of(work, struct ieee80211_sub_if_data,
2489 u.mgd.beacon_connection_loss_work);
2490 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2491
2492 if (ifmgd->associated)
2493 ifmgd->beacon_loss_count++;
2494
2495 if (ifmgd->connection_loss) {
2496 sdata_info(sdata, "Connection to AP %pM lost\n",
2497 ifmgd->bssid);
2498 __ieee80211_disconnect(sdata);
2499 } else {
2500 ieee80211_mgd_probe_ap(sdata, true);
2501 }
2502 }
2503
2504 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2505 {
2506 struct ieee80211_sub_if_data *sdata =
2507 container_of(work, struct ieee80211_sub_if_data,
2508 u.mgd.csa_connection_drop_work);
2509
2510 __ieee80211_disconnect(sdata);
2511 }
2512
2513 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2514 {
2515 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2516 struct ieee80211_hw *hw = &sdata->local->hw;
2517
2518 trace_api_beacon_loss(sdata);
2519
2520 sdata->u.mgd.connection_loss = false;
2521 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2522 }
2523 EXPORT_SYMBOL(ieee80211_beacon_loss);
2524
2525 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2526 {
2527 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2528 struct ieee80211_hw *hw = &sdata->local->hw;
2529
2530 trace_api_connection_loss(sdata);
2531
2532 sdata->u.mgd.connection_loss = true;
2533 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2534 }
2535 EXPORT_SYMBOL(ieee80211_connection_loss);
2536
2537
2538 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2539 bool assoc)
2540 {
2541 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2542
2543 sdata_assert_lock(sdata);
2544
2545 if (!assoc) {
2546 /*
2547 * we are not authenticated yet, the only timer that could be
2548 * running is the timeout for the authentication response which
2549 * which is not relevant anymore.
2550 */
2551 del_timer_sync(&sdata->u.mgd.timer);
2552 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2553
2554 eth_zero_addr(sdata->u.mgd.bssid);
2555 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2556 sdata->u.mgd.flags = 0;
2557 mutex_lock(&sdata->local->mtx);
2558 ieee80211_vif_release_channel(sdata);
2559 mutex_unlock(&sdata->local->mtx);
2560 }
2561
2562 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2563 kfree(auth_data);
2564 sdata->u.mgd.auth_data = NULL;
2565 }
2566
2567 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2568 bool assoc, bool abandon)
2569 {
2570 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2571
2572 sdata_assert_lock(sdata);
2573
2574 if (!assoc) {
2575 /*
2576 * we are not associated yet, the only timer that could be
2577 * running is the timeout for the association response which
2578 * which is not relevant anymore.
2579 */
2580 del_timer_sync(&sdata->u.mgd.timer);
2581 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2582
2583 eth_zero_addr(sdata->u.mgd.bssid);
2584 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2585 sdata->u.mgd.flags = 0;
2586 sdata->vif.mu_mimo_owner = false;
2587
2588 mutex_lock(&sdata->local->mtx);
2589 ieee80211_vif_release_channel(sdata);
2590 mutex_unlock(&sdata->local->mtx);
2591
2592 if (abandon)
2593 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2594 }
2595
2596 kfree(assoc_data);
2597 sdata->u.mgd.assoc_data = NULL;
2598 }
2599
2600 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2601 struct ieee80211_mgmt *mgmt, size_t len)
2602 {
2603 struct ieee80211_local *local = sdata->local;
2604 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2605 u8 *pos;
2606 struct ieee802_11_elems elems;
2607 u32 tx_flags = 0;
2608
2609 pos = mgmt->u.auth.variable;
2610 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2611 if (!elems.challenge)
2612 return;
2613 auth_data->expected_transaction = 4;
2614 drv_mgd_prepare_tx(sdata->local, sdata);
2615 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2616 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2617 IEEE80211_TX_INTFL_MLME_CONN_TX;
2618 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2619 elems.challenge - 2, elems.challenge_len + 2,
2620 auth_data->bss->bssid, auth_data->bss->bssid,
2621 auth_data->key, auth_data->key_len,
2622 auth_data->key_idx, tx_flags);
2623 }
2624
2625 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2626 struct ieee80211_mgmt *mgmt, size_t len)
2627 {
2628 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2629 u8 bssid[ETH_ALEN];
2630 u16 auth_alg, auth_transaction, status_code;
2631 struct sta_info *sta;
2632 struct ieee80211_event event = {
2633 .type = MLME_EVENT,
2634 .u.mlme.data = AUTH_EVENT,
2635 };
2636
2637 sdata_assert_lock(sdata);
2638
2639 if (len < 24 + 6)
2640 return;
2641
2642 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2643 return;
2644
2645 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2646
2647 if (!ether_addr_equal(bssid, mgmt->bssid))
2648 return;
2649
2650 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2651 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2652 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2653
2654 if (auth_alg != ifmgd->auth_data->algorithm ||
2655 auth_transaction != ifmgd->auth_data->expected_transaction) {
2656 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2657 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2658 auth_transaction,
2659 ifmgd->auth_data->expected_transaction);
2660 return;
2661 }
2662
2663 if (status_code != WLAN_STATUS_SUCCESS) {
2664 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2665 mgmt->sa, status_code);
2666 ieee80211_destroy_auth_data(sdata, false);
2667 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2668 event.u.mlme.status = MLME_DENIED;
2669 event.u.mlme.reason = status_code;
2670 drv_event_callback(sdata->local, sdata, &event);
2671 return;
2672 }
2673
2674 switch (ifmgd->auth_data->algorithm) {
2675 case WLAN_AUTH_OPEN:
2676 case WLAN_AUTH_LEAP:
2677 case WLAN_AUTH_FT:
2678 case WLAN_AUTH_SAE:
2679 case WLAN_AUTH_FILS_SK:
2680 case WLAN_AUTH_FILS_SK_PFS:
2681 case WLAN_AUTH_FILS_PK:
2682 break;
2683 case WLAN_AUTH_SHARED_KEY:
2684 if (ifmgd->auth_data->expected_transaction != 4) {
2685 ieee80211_auth_challenge(sdata, mgmt, len);
2686 /* need another frame */
2687 return;
2688 }
2689 break;
2690 default:
2691 WARN_ONCE(1, "invalid auth alg %d",
2692 ifmgd->auth_data->algorithm);
2693 return;
2694 }
2695
2696 event.u.mlme.status = MLME_SUCCESS;
2697 drv_event_callback(sdata->local, sdata, &event);
2698 sdata_info(sdata, "authenticated\n");
2699 ifmgd->auth_data->done = true;
2700 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2701 ifmgd->auth_data->timeout_started = true;
2702 run_again(sdata, ifmgd->auth_data->timeout);
2703
2704 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2705 ifmgd->auth_data->expected_transaction != 2) {
2706 /*
2707 * Report auth frame to user space for processing since another
2708 * round of Authentication frames is still needed.
2709 */
2710 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2711 return;
2712 }
2713
2714 /* move station state to auth */
2715 mutex_lock(&sdata->local->sta_mtx);
2716 sta = sta_info_get(sdata, bssid);
2717 if (!sta) {
2718 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2719 goto out_err;
2720 }
2721 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2722 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2723 goto out_err;
2724 }
2725 mutex_unlock(&sdata->local->sta_mtx);
2726
2727 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2728 return;
2729 out_err:
2730 mutex_unlock(&sdata->local->sta_mtx);
2731 /* ignore frame -- wait for timeout */
2732 }
2733
2734 #define case_WLAN(type) \
2735 case WLAN_REASON_##type: return #type
2736
2737 static const char *ieee80211_get_reason_code_string(u16 reason_code)
2738 {
2739 switch (reason_code) {
2740 case_WLAN(UNSPECIFIED);
2741 case_WLAN(PREV_AUTH_NOT_VALID);
2742 case_WLAN(DEAUTH_LEAVING);
2743 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2744 case_WLAN(DISASSOC_AP_BUSY);
2745 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2746 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2747 case_WLAN(DISASSOC_STA_HAS_LEFT);
2748 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2749 case_WLAN(DISASSOC_BAD_POWER);
2750 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2751 case_WLAN(INVALID_IE);
2752 case_WLAN(MIC_FAILURE);
2753 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2754 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2755 case_WLAN(IE_DIFFERENT);
2756 case_WLAN(INVALID_GROUP_CIPHER);
2757 case_WLAN(INVALID_PAIRWISE_CIPHER);
2758 case_WLAN(INVALID_AKMP);
2759 case_WLAN(UNSUPP_RSN_VERSION);
2760 case_WLAN(INVALID_RSN_IE_CAP);
2761 case_WLAN(IEEE8021X_FAILED);
2762 case_WLAN(CIPHER_SUITE_REJECTED);
2763 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2764 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2765 case_WLAN(DISASSOC_LOW_ACK);
2766 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2767 case_WLAN(QSTA_LEAVE_QBSS);
2768 case_WLAN(QSTA_NOT_USE);
2769 case_WLAN(QSTA_REQUIRE_SETUP);
2770 case_WLAN(QSTA_TIMEOUT);
2771 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2772 case_WLAN(MESH_PEER_CANCELED);
2773 case_WLAN(MESH_MAX_PEERS);
2774 case_WLAN(MESH_CONFIG);
2775 case_WLAN(MESH_CLOSE);
2776 case_WLAN(MESH_MAX_RETRIES);
2777 case_WLAN(MESH_CONFIRM_TIMEOUT);
2778 case_WLAN(MESH_INVALID_GTK);
2779 case_WLAN(MESH_INCONSISTENT_PARAM);
2780 case_WLAN(MESH_INVALID_SECURITY);
2781 case_WLAN(MESH_PATH_ERROR);
2782 case_WLAN(MESH_PATH_NOFORWARD);
2783 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
2784 case_WLAN(MAC_EXISTS_IN_MBSS);
2785 case_WLAN(MESH_CHAN_REGULATORY);
2786 case_WLAN(MESH_CHAN);
2787 default: return "<unknown>";
2788 }
2789 }
2790
2791 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2792 struct ieee80211_mgmt *mgmt, size_t len)
2793 {
2794 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2795 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2796
2797 sdata_assert_lock(sdata);
2798
2799 if (len < 24 + 2)
2800 return;
2801
2802 if (ifmgd->associated &&
2803 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
2804 const u8 *bssid = ifmgd->associated->bssid;
2805
2806 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
2807 bssid, reason_code,
2808 ieee80211_get_reason_code_string(reason_code));
2809
2810 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2811
2812 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
2813 reason_code);
2814 return;
2815 }
2816
2817 if (ifmgd->assoc_data &&
2818 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2819 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
2820
2821 sdata_info(sdata,
2822 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2823 bssid, reason_code,
2824 ieee80211_get_reason_code_string(reason_code));
2825
2826 ieee80211_destroy_assoc_data(sdata, false, true);
2827
2828 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2829 return;
2830 }
2831 }
2832
2833
2834 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2835 struct ieee80211_mgmt *mgmt, size_t len)
2836 {
2837 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2838 u16 reason_code;
2839
2840 sdata_assert_lock(sdata);
2841
2842 if (len < 24 + 2)
2843 return;
2844
2845 if (!ifmgd->associated ||
2846 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
2847 return;
2848
2849 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2850
2851 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
2852 mgmt->sa, reason_code,
2853 ieee80211_get_reason_code_string(reason_code));
2854
2855 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2856
2857 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
2858 }
2859
2860 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2861 u8 *supp_rates, unsigned int supp_rates_len,
2862 u32 *rates, u32 *basic_rates,
2863 bool *have_higher_than_11mbit,
2864 int *min_rate, int *min_rate_index,
2865 int shift)
2866 {
2867 int i, j;
2868
2869 for (i = 0; i < supp_rates_len; i++) {
2870 int rate = supp_rates[i] & 0x7f;
2871 bool is_basic = !!(supp_rates[i] & 0x80);
2872
2873 if ((rate * 5 * (1 << shift)) > 110)
2874 *have_higher_than_11mbit = true;
2875
2876 /*
2877 * Skip HT and VHT BSS membership selectors since they're not
2878 * rates.
2879 *
2880 * Note: Even though the membership selector and the basic
2881 * rate flag share the same bit, they are not exactly
2882 * the same.
2883 */
2884 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
2885 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
2886 continue;
2887
2888 for (j = 0; j < sband->n_bitrates; j++) {
2889 struct ieee80211_rate *br;
2890 int brate;
2891
2892 br = &sband->bitrates[j];
2893
2894 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
2895 if (brate == rate) {
2896 *rates |= BIT(j);
2897 if (is_basic)
2898 *basic_rates |= BIT(j);
2899 if ((rate * 5) < *min_rate) {
2900 *min_rate = rate * 5;
2901 *min_rate_index = j;
2902 }
2903 break;
2904 }
2905 }
2906 }
2907 }
2908
2909 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2910 struct cfg80211_bss *cbss,
2911 struct ieee80211_mgmt *mgmt, size_t len)
2912 {
2913 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2914 struct ieee80211_local *local = sdata->local;
2915 struct ieee80211_supported_band *sband;
2916 struct sta_info *sta;
2917 u8 *pos;
2918 u16 capab_info, aid;
2919 struct ieee802_11_elems elems;
2920 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2921 const struct cfg80211_bss_ies *bss_ies = NULL;
2922 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2923 u32 changed = 0;
2924 int err;
2925 bool ret;
2926
2927 /* AssocResp and ReassocResp have identical structure */
2928
2929 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2930 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2931
2932 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2933 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2934 aid);
2935 aid &= ~(BIT(15) | BIT(14));
2936
2937 ifmgd->broken_ap = false;
2938
2939 if (aid == 0 || aid > IEEE80211_MAX_AID) {
2940 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2941 aid);
2942 aid = 0;
2943 ifmgd->broken_ap = true;
2944 }
2945
2946 pos = mgmt->u.assoc_resp.variable;
2947 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2948
2949 if (!elems.supp_rates) {
2950 sdata_info(sdata, "no SuppRates element in AssocResp\n");
2951 return false;
2952 }
2953
2954 ifmgd->aid = aid;
2955 ifmgd->tdls_chan_switch_prohibited =
2956 elems.ext_capab && elems.ext_capab_len >= 5 &&
2957 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
2958
2959 /*
2960 * Some APs are erroneously not including some information in their
2961 * (re)association response frames. Try to recover by using the data
2962 * from the beacon or probe response. This seems to afflict mobile
2963 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
2964 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
2965 */
2966 if ((assoc_data->wmm && !elems.wmm_param) ||
2967 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2968 (!elems.ht_cap_elem || !elems.ht_operation)) ||
2969 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2970 (!elems.vht_cap_elem || !elems.vht_operation))) {
2971 const struct cfg80211_bss_ies *ies;
2972 struct ieee802_11_elems bss_elems;
2973
2974 rcu_read_lock();
2975 ies = rcu_dereference(cbss->ies);
2976 if (ies)
2977 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
2978 GFP_ATOMIC);
2979 rcu_read_unlock();
2980 if (!bss_ies)
2981 return false;
2982
2983 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
2984 false, &bss_elems);
2985 if (assoc_data->wmm &&
2986 !elems.wmm_param && bss_elems.wmm_param) {
2987 elems.wmm_param = bss_elems.wmm_param;
2988 sdata_info(sdata,
2989 "AP bug: WMM param missing from AssocResp\n");
2990 }
2991
2992 /*
2993 * Also check if we requested HT/VHT, otherwise the AP doesn't
2994 * have to include the IEs in the (re)association response.
2995 */
2996 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
2997 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
2998 elems.ht_cap_elem = bss_elems.ht_cap_elem;
2999 sdata_info(sdata,
3000 "AP bug: HT capability missing from AssocResp\n");
3001 }
3002 if (!elems.ht_operation && bss_elems.ht_operation &&
3003 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3004 elems.ht_operation = bss_elems.ht_operation;
3005 sdata_info(sdata,
3006 "AP bug: HT operation missing from AssocResp\n");
3007 }
3008 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3009 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3010 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3011 sdata_info(sdata,
3012 "AP bug: VHT capa missing from AssocResp\n");
3013 }
3014 if (!elems.vht_operation && bss_elems.vht_operation &&
3015 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3016 elems.vht_operation = bss_elems.vht_operation;
3017 sdata_info(sdata,
3018 "AP bug: VHT operation missing from AssocResp\n");
3019 }
3020 }
3021
3022 /*
3023 * We previously checked these in the beacon/probe response, so
3024 * they should be present here. This is just a safety net.
3025 */
3026 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3027 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3028 sdata_info(sdata,
3029 "HT AP is missing WMM params or HT capability/operation\n");
3030 ret = false;
3031 goto out;
3032 }
3033
3034 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3035 (!elems.vht_cap_elem || !elems.vht_operation)) {
3036 sdata_info(sdata,
3037 "VHT AP is missing VHT capability/operation\n");
3038 ret = false;
3039 goto out;
3040 }
3041
3042 mutex_lock(&sdata->local->sta_mtx);
3043 /*
3044 * station info was already allocated and inserted before
3045 * the association and should be available to us
3046 */
3047 sta = sta_info_get(sdata, cbss->bssid);
3048 if (WARN_ON(!sta)) {
3049 mutex_unlock(&sdata->local->sta_mtx);
3050 ret = false;
3051 goto out;
3052 }
3053
3054 sband = ieee80211_get_sband(sdata);
3055 if (!sband) {
3056 mutex_unlock(&sdata->local->sta_mtx);
3057 ret = false;
3058 goto out;
3059 }
3060
3061 /* Set up internal HT/VHT capabilities */
3062 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3063 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3064 elems.ht_cap_elem, sta);
3065
3066 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3067 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3068 elems.vht_cap_elem, sta);
3069
3070 /*
3071 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3072 * in their association response, so ignore that data for our own
3073 * configuration. If it changed since the last beacon, we'll get the
3074 * next beacon and update then.
3075 */
3076
3077 /*
3078 * If an operating mode notification IE is present, override the
3079 * NSS calculation (that would be done in rate_control_rate_init())
3080 * and use the # of streams from that element.
3081 */
3082 if (elems.opmode_notif &&
3083 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3084 u8 nss;
3085
3086 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3087 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3088 nss += 1;
3089 sta->sta.rx_nss = nss;
3090 }
3091
3092 rate_control_rate_init(sta);
3093
3094 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3095 set_sta_flag(sta, WLAN_STA_MFP);
3096 sta->sta.mfp = true;
3097 } else {
3098 sta->sta.mfp = false;
3099 }
3100
3101 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
3102
3103 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3104 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3105 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3106 if (err) {
3107 sdata_info(sdata,
3108 "failed to move station %pM to desired state\n",
3109 sta->sta.addr);
3110 WARN_ON(__sta_info_destroy(sta));
3111 mutex_unlock(&sdata->local->sta_mtx);
3112 ret = false;
3113 goto out;
3114 }
3115
3116 mutex_unlock(&sdata->local->sta_mtx);
3117
3118 /*
3119 * Always handle WMM once after association regardless
3120 * of the first value the AP uses. Setting -1 here has
3121 * that effect because the AP values is an unsigned
3122 * 4-bit value.
3123 */
3124 ifmgd->wmm_last_param_set = -1;
3125
3126 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3127 ieee80211_set_wmm_default(sdata, false, false);
3128 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3129 elems.wmm_param_len)) {
3130 /* still enable QoS since we might have HT/VHT */
3131 ieee80211_set_wmm_default(sdata, false, true);
3132 /* set the disable-WMM flag in this case to disable
3133 * tracking WMM parameter changes in the beacon if
3134 * the parameters weren't actually valid. Doing so
3135 * avoids changing parameters very strangely when
3136 * the AP is going back and forth between valid and
3137 * invalid parameters.
3138 */
3139 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3140 }
3141 changed |= BSS_CHANGED_QOS;
3142
3143 if (elems.max_idle_period_ie) {
3144 bss_conf->max_idle_period =
3145 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3146 bss_conf->protected_keep_alive =
3147 !!(elems.max_idle_period_ie->idle_options &
3148 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3149 changed |= BSS_CHANGED_KEEP_ALIVE;
3150 } else {
3151 bss_conf->max_idle_period = 0;
3152 bss_conf->protected_keep_alive = false;
3153 }
3154
3155 /* set AID and assoc capability,
3156 * ieee80211_set_associated() will tell the driver */
3157 bss_conf->aid = aid;
3158 bss_conf->assoc_capability = capab_info;
3159 ieee80211_set_associated(sdata, cbss, changed);
3160
3161 /*
3162 * If we're using 4-addr mode, let the AP know that we're
3163 * doing so, so that it can create the STA VLAN on its side
3164 */
3165 if (ifmgd->use_4addr)
3166 ieee80211_send_4addr_nullfunc(local, sdata);
3167
3168 /*
3169 * Start timer to probe the connection to the AP now.
3170 * Also start the timer that will detect beacon loss.
3171 */
3172 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
3173 ieee80211_sta_reset_beacon_monitor(sdata);
3174
3175 ret = true;
3176 out:
3177 kfree(bss_ies);
3178 return ret;
3179 }
3180
3181 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3182 struct ieee80211_mgmt *mgmt,
3183 size_t len)
3184 {
3185 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3186 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3187 u16 capab_info, status_code, aid;
3188 struct ieee802_11_elems elems;
3189 int ac, uapsd_queues = -1;
3190 u8 *pos;
3191 bool reassoc;
3192 struct cfg80211_bss *bss;
3193 struct ieee80211_event event = {
3194 .type = MLME_EVENT,
3195 .u.mlme.data = ASSOC_EVENT,
3196 };
3197
3198 sdata_assert_lock(sdata);
3199
3200 if (!assoc_data)
3201 return;
3202 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3203 return;
3204
3205 /*
3206 * AssocResp and ReassocResp have identical structure, so process both
3207 * of them in this function.
3208 */
3209
3210 if (len < 24 + 6)
3211 return;
3212
3213 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3214 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3215 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3216 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3217
3218 sdata_info(sdata,
3219 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3220 reassoc ? "Rea" : "A", mgmt->sa,
3221 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3222
3223 if (assoc_data->fils_kek_len &&
3224 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3225 return;
3226
3227 pos = mgmt->u.assoc_resp.variable;
3228 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
3229
3230 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3231 elems.timeout_int &&
3232 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3233 u32 tu, ms;
3234 tu = le32_to_cpu(elems.timeout_int->value);
3235 ms = tu * 1024 / 1000;
3236 sdata_info(sdata,
3237 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3238 mgmt->sa, tu, ms);
3239 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3240 assoc_data->timeout_started = true;
3241 if (ms > IEEE80211_ASSOC_TIMEOUT)
3242 run_again(sdata, assoc_data->timeout);
3243 return;
3244 }
3245
3246 bss = assoc_data->bss;
3247
3248 if (status_code != WLAN_STATUS_SUCCESS) {
3249 sdata_info(sdata, "%pM denied association (code=%d)\n",
3250 mgmt->sa, status_code);
3251 ieee80211_destroy_assoc_data(sdata, false, false);
3252 event.u.mlme.status = MLME_DENIED;
3253 event.u.mlme.reason = status_code;
3254 drv_event_callback(sdata->local, sdata, &event);
3255 } else {
3256 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
3257 /* oops -- internal error -- send timeout for now */
3258 ieee80211_destroy_assoc_data(sdata, false, false);
3259 cfg80211_assoc_timeout(sdata->dev, bss);
3260 return;
3261 }
3262 event.u.mlme.status = MLME_SUCCESS;
3263 drv_event_callback(sdata->local, sdata, &event);
3264 sdata_info(sdata, "associated\n");
3265
3266 /*
3267 * destroy assoc_data afterwards, as otherwise an idle
3268 * recalc after assoc_data is NULL but before associated
3269 * is set can cause the interface to go idle
3270 */
3271 ieee80211_destroy_assoc_data(sdata, true, false);
3272
3273 /* get uapsd queues configuration */
3274 uapsd_queues = 0;
3275 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3276 if (sdata->tx_conf[ac].uapsd)
3277 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3278 }
3279
3280 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
3281 }
3282
3283 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3284 struct ieee80211_mgmt *mgmt, size_t len,
3285 struct ieee80211_rx_status *rx_status,
3286 struct ieee802_11_elems *elems)
3287 {
3288 struct ieee80211_local *local = sdata->local;
3289 struct ieee80211_bss *bss;
3290 struct ieee80211_channel *channel;
3291
3292 sdata_assert_lock(sdata);
3293
3294 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3295 if (!channel)
3296 return;
3297
3298 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
3299 channel);
3300 if (bss) {
3301 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3302 ieee80211_rx_bss_put(local, bss);
3303 }
3304 }
3305
3306
3307 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3308 struct sk_buff *skb)
3309 {
3310 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3311 struct ieee80211_if_managed *ifmgd;
3312 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3313 size_t baselen, len = skb->len;
3314 struct ieee802_11_elems elems;
3315
3316 ifmgd = &sdata->u.mgd;
3317
3318 sdata_assert_lock(sdata);
3319
3320 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
3321 return; /* ignore ProbeResp to foreign address */
3322
3323 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3324 if (baselen > len)
3325 return;
3326
3327 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
3328 false, &elems);
3329
3330 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3331
3332 if (ifmgd->associated &&
3333 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3334 ieee80211_reset_ap_probe(sdata);
3335 }
3336
3337 /*
3338 * This is the canonical list of information elements we care about,
3339 * the filter code also gives us all changes to the Microsoft OUI
3340 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3341 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3342 * changes to requested client power.
3343 *
3344 * We implement beacon filtering in software since that means we can
3345 * avoid processing the frame here and in cfg80211, and userspace
3346 * will not be able to tell whether the hardware supports it or not.
3347 *
3348 * XXX: This list needs to be dynamic -- userspace needs to be able to
3349 * add items it requires. It also needs to be able to tell us to
3350 * look out for other vendor IEs.
3351 */
3352 static const u64 care_about_ies =
3353 (1ULL << WLAN_EID_COUNTRY) |
3354 (1ULL << WLAN_EID_ERP_INFO) |
3355 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3356 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3357 (1ULL << WLAN_EID_HT_CAPABILITY) |
3358 (1ULL << WLAN_EID_HT_OPERATION) |
3359 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3360
3361 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3362 struct ieee80211_mgmt *mgmt, size_t len,
3363 struct ieee80211_rx_status *rx_status)
3364 {
3365 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3366 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3367 size_t baselen;
3368 struct ieee802_11_elems elems;
3369 struct ieee80211_local *local = sdata->local;
3370 struct ieee80211_chanctx_conf *chanctx_conf;
3371 struct ieee80211_channel *chan;
3372 struct sta_info *sta;
3373 u32 changed = 0;
3374 bool erp_valid;
3375 u8 erp_value = 0;
3376 u32 ncrc;
3377 u8 *bssid;
3378 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3379
3380 sdata_assert_lock(sdata);
3381
3382 /* Process beacon from the current BSS */
3383 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3384 if (baselen > len)
3385 return;
3386
3387 rcu_read_lock();
3388 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3389 if (!chanctx_conf) {
3390 rcu_read_unlock();
3391 return;
3392 }
3393
3394 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3395 rcu_read_unlock();
3396 return;
3397 }
3398 chan = chanctx_conf->def.chan;
3399 rcu_read_unlock();
3400
3401 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3402 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3403 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3404 len - baselen, false, &elems);
3405
3406 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3407 if (elems.tim && !elems.parse_error) {
3408 const struct ieee80211_tim_ie *tim_ie = elems.tim;
3409 ifmgd->dtim_period = tim_ie->dtim_period;
3410 }
3411 ifmgd->have_beacon = true;
3412 ifmgd->assoc_data->need_beacon = false;
3413 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3414 sdata->vif.bss_conf.sync_tsf =
3415 le64_to_cpu(mgmt->u.beacon.timestamp);
3416 sdata->vif.bss_conf.sync_device_ts =
3417 rx_status->device_timestamp;
3418 if (elems.tim)
3419 sdata->vif.bss_conf.sync_dtim_count =
3420 elems.tim->dtim_count;
3421 else
3422 sdata->vif.bss_conf.sync_dtim_count = 0;
3423 }
3424 /* continue assoc process */
3425 ifmgd->assoc_data->timeout = jiffies;
3426 ifmgd->assoc_data->timeout_started = true;
3427 run_again(sdata, ifmgd->assoc_data->timeout);
3428 return;
3429 }
3430
3431 if (!ifmgd->associated ||
3432 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3433 return;
3434 bssid = ifmgd->associated->bssid;
3435
3436 /* Track average RSSI from the Beacon frames of the current AP */
3437 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3438 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3439 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3440 ifmgd->last_cqm_event_signal = 0;
3441 ifmgd->count_beacon_signal = 1;
3442 ifmgd->last_ave_beacon_signal = 0;
3443 } else {
3444 ifmgd->count_beacon_signal++;
3445 }
3446
3447 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3448
3449 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3450 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3451 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3452 int last_sig = ifmgd->last_ave_beacon_signal;
3453 struct ieee80211_event event = {
3454 .type = RSSI_EVENT,
3455 };
3456
3457 /*
3458 * if signal crosses either of the boundaries, invoke callback
3459 * with appropriate parameters
3460 */
3461 if (sig > ifmgd->rssi_max_thold &&
3462 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3463 ifmgd->last_ave_beacon_signal = sig;
3464 event.u.rssi.data = RSSI_EVENT_HIGH;
3465 drv_event_callback(local, sdata, &event);
3466 } else if (sig < ifmgd->rssi_min_thold &&
3467 (last_sig >= ifmgd->rssi_max_thold ||
3468 last_sig == 0)) {
3469 ifmgd->last_ave_beacon_signal = sig;
3470 event.u.rssi.data = RSSI_EVENT_LOW;
3471 drv_event_callback(local, sdata, &event);
3472 }
3473 }
3474
3475 if (bss_conf->cqm_rssi_thold &&
3476 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3477 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3478 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3479 int last_event = ifmgd->last_cqm_event_signal;
3480 int thold = bss_conf->cqm_rssi_thold;
3481 int hyst = bss_conf->cqm_rssi_hyst;
3482
3483 if (sig < thold &&
3484 (last_event == 0 || sig < last_event - hyst)) {
3485 ifmgd->last_cqm_event_signal = sig;
3486 ieee80211_cqm_rssi_notify(
3487 &sdata->vif,
3488 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3489 sig, GFP_KERNEL);
3490 } else if (sig > thold &&
3491 (last_event == 0 || sig > last_event + hyst)) {
3492 ifmgd->last_cqm_event_signal = sig;
3493 ieee80211_cqm_rssi_notify(
3494 &sdata->vif,
3495 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3496 sig, GFP_KERNEL);
3497 }
3498 }
3499
3500 if (bss_conf->cqm_rssi_low &&
3501 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3502 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3503 int last_event = ifmgd->last_cqm_event_signal;
3504 int low = bss_conf->cqm_rssi_low;
3505 int high = bss_conf->cqm_rssi_high;
3506
3507 if (sig < low &&
3508 (last_event == 0 || last_event >= low)) {
3509 ifmgd->last_cqm_event_signal = sig;
3510 ieee80211_cqm_rssi_notify(
3511 &sdata->vif,
3512 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3513 sig, GFP_KERNEL);
3514 } else if (sig > high &&
3515 (last_event == 0 || last_event <= high)) {
3516 ifmgd->last_cqm_event_signal = sig;
3517 ieee80211_cqm_rssi_notify(
3518 &sdata->vif,
3519 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3520 sig, GFP_KERNEL);
3521 }
3522 }
3523
3524 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
3525 mlme_dbg_ratelimited(sdata,
3526 "cancelling AP probe due to a received beacon\n");
3527 ieee80211_reset_ap_probe(sdata);
3528 }
3529
3530 /*
3531 * Push the beacon loss detection into the future since
3532 * we are processing a beacon from the AP just now.
3533 */
3534 ieee80211_sta_reset_beacon_monitor(sdata);
3535
3536 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3537 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
3538 len - baselen, false, &elems,
3539 care_about_ies, ncrc);
3540
3541 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3542 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3543 if (local->hw.conf.dynamic_ps_timeout > 0) {
3544 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3545 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3546 ieee80211_hw_config(local,
3547 IEEE80211_CONF_CHANGE_PS);
3548 }
3549 ieee80211_send_nullfunc(local, sdata, false);
3550 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3551 local->pspolling = true;
3552
3553 /*
3554 * Here is assumed that the driver will be
3555 * able to send ps-poll frame and receive a
3556 * response even though power save mode is
3557 * enabled, but some drivers might require
3558 * to disable power save here. This needs
3559 * to be investigated.
3560 */
3561 ieee80211_send_pspoll(local, sdata);
3562 }
3563 }
3564
3565 if (sdata->vif.p2p ||
3566 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
3567 struct ieee80211_p2p_noa_attr noa = {};
3568 int ret;
3569
3570 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3571 len - baselen,
3572 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
3573 (u8 *) &noa, sizeof(noa));
3574 if (ret >= 2) {
3575 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3576 /* valid noa_attr and index changed */
3577 sdata->u.mgd.p2p_noa_index = noa.index;
3578 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3579 changed |= BSS_CHANGED_P2P_PS;
3580 /*
3581 * make sure we update all information, the CRC
3582 * mechanism doesn't look at P2P attributes.
3583 */
3584 ifmgd->beacon_crc_valid = false;
3585 }
3586 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3587 /* noa_attr not found and we had valid noa_attr before */
3588 sdata->u.mgd.p2p_noa_index = -1;
3589 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
3590 changed |= BSS_CHANGED_P2P_PS;
3591 ifmgd->beacon_crc_valid = false;
3592 }
3593 }
3594
3595 if (ifmgd->csa_waiting_bcn)
3596 ieee80211_chswitch_post_beacon(sdata);
3597
3598 /*
3599 * Update beacon timing and dtim count on every beacon appearance. This
3600 * will allow the driver to use the most updated values. Do it before
3601 * comparing this one with last received beacon.
3602 * IMPORTANT: These parameters would possibly be out of sync by the time
3603 * the driver will use them. The synchronized view is currently
3604 * guaranteed only in certain callbacks.
3605 */
3606 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3607 sdata->vif.bss_conf.sync_tsf =
3608 le64_to_cpu(mgmt->u.beacon.timestamp);
3609 sdata->vif.bss_conf.sync_device_ts =
3610 rx_status->device_timestamp;
3611 if (elems.tim)
3612 sdata->vif.bss_conf.sync_dtim_count =
3613 elems.tim->dtim_count;
3614 else
3615 sdata->vif.bss_conf.sync_dtim_count = 0;
3616 }
3617
3618 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
3619 return;
3620 ifmgd->beacon_crc = ncrc;
3621 ifmgd->beacon_crc_valid = true;
3622
3623 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3624
3625 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
3626 rx_status->device_timestamp,
3627 &elems, true);
3628
3629 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3630 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3631 elems.wmm_param_len))
3632 changed |= BSS_CHANGED_QOS;
3633
3634 /*
3635 * If we haven't had a beacon before, tell the driver about the
3636 * DTIM period (and beacon timing if desired) now.
3637 */
3638 if (!ifmgd->have_beacon) {
3639 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3640 if (elems.tim)
3641 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3642 else
3643 bss_conf->dtim_period = 1;
3644
3645 changed |= BSS_CHANGED_BEACON_INFO;
3646 ifmgd->have_beacon = true;
3647
3648 mutex_lock(&local->iflist_mtx);
3649 ieee80211_recalc_ps(local);
3650 mutex_unlock(&local->iflist_mtx);
3651
3652 ieee80211_recalc_ps_vif(sdata);
3653 }
3654
3655 if (elems.erp_info) {
3656 erp_valid = true;
3657 erp_value = elems.erp_info[0];
3658 } else {
3659 erp_valid = false;
3660 }
3661 changed |= ieee80211_handle_bss_capability(sdata,
3662 le16_to_cpu(mgmt->u.beacon.capab_info),
3663 erp_valid, erp_value);
3664
3665 mutex_lock(&local->sta_mtx);
3666 sta = sta_info_get(sdata, bssid);
3667
3668 if (ieee80211_config_bw(sdata, sta,
3669 elems.ht_cap_elem, elems.ht_operation,
3670 elems.vht_operation, bssid, &changed)) {
3671 mutex_unlock(&local->sta_mtx);
3672 sdata_info(sdata,
3673 "failed to follow AP %pM bandwidth change, disconnect\n",
3674 bssid);
3675 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3676 WLAN_REASON_DEAUTH_LEAVING,
3677 true, deauth_buf);
3678 ieee80211_report_disconnect(sdata, deauth_buf,
3679 sizeof(deauth_buf), true,
3680 WLAN_REASON_DEAUTH_LEAVING);
3681 return;
3682 }
3683
3684 if (sta && elems.opmode_notif)
3685 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
3686 rx_status->band);
3687 mutex_unlock(&local->sta_mtx);
3688
3689 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
3690 elems.country_elem,
3691 elems.country_elem_len,
3692 elems.pwr_constr_elem,
3693 elems.cisco_dtpc_elem);
3694
3695 ieee80211_bss_info_change_notify(sdata, changed);
3696 }
3697
3698 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3699 struct sk_buff *skb)
3700 {
3701 struct ieee80211_rx_status *rx_status;
3702 struct ieee80211_mgmt *mgmt;
3703 u16 fc;
3704 struct ieee802_11_elems elems;
3705 int ies_len;
3706
3707 rx_status = (struct ieee80211_rx_status *) skb->cb;
3708 mgmt = (struct ieee80211_mgmt *) skb->data;
3709 fc = le16_to_cpu(mgmt->frame_control);
3710
3711 sdata_lock(sdata);
3712
3713 switch (fc & IEEE80211_FCTL_STYPE) {
3714 case IEEE80211_STYPE_BEACON:
3715 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
3716 break;
3717 case IEEE80211_STYPE_PROBE_RESP:
3718 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3719 break;
3720 case IEEE80211_STYPE_AUTH:
3721 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
3722 break;
3723 case IEEE80211_STYPE_DEAUTH:
3724 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
3725 break;
3726 case IEEE80211_STYPE_DISASSOC:
3727 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
3728 break;
3729 case IEEE80211_STYPE_ASSOC_RESP:
3730 case IEEE80211_STYPE_REASSOC_RESP:
3731 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
3732 break;
3733 case IEEE80211_STYPE_ACTION:
3734 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
3735 ies_len = skb->len -
3736 offsetof(struct ieee80211_mgmt,
3737 u.action.u.chan_switch.variable);
3738
3739 if (ies_len < 0)
3740 break;
3741
3742 ieee802_11_parse_elems(
3743 mgmt->u.action.u.chan_switch.variable,
3744 ies_len, true, &elems);
3745
3746 if (elems.parse_error)
3747 break;
3748
3749 ieee80211_sta_process_chanswitch(sdata,
3750 rx_status->mactime,
3751 rx_status->device_timestamp,
3752 &elems, false);
3753 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3754 ies_len = skb->len -
3755 offsetof(struct ieee80211_mgmt,
3756 u.action.u.ext_chan_switch.variable);
3757
3758 if (ies_len < 0)
3759 break;
3760
3761 ieee802_11_parse_elems(
3762 mgmt->u.action.u.ext_chan_switch.variable,
3763 ies_len, true, &elems);
3764
3765 if (elems.parse_error)
3766 break;
3767
3768 /* for the handling code pretend this was also an IE */
3769 elems.ext_chansw_ie =
3770 &mgmt->u.action.u.ext_chan_switch.data;
3771
3772 ieee80211_sta_process_chanswitch(sdata,
3773 rx_status->mactime,
3774 rx_status->device_timestamp,
3775 &elems, false);
3776 }
3777 break;
3778 }
3779 sdata_unlock(sdata);
3780 }
3781
3782 static void ieee80211_sta_timer(struct timer_list *t)
3783 {
3784 struct ieee80211_sub_if_data *sdata =
3785 from_timer(sdata, t, u.mgd.timer);
3786
3787 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3788 }
3789
3790 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
3791 u8 *bssid, u8 reason, bool tx)
3792 {
3793 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3794
3795 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
3796 tx, frame_buf);
3797
3798 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
3799 reason);
3800 }
3801
3802 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
3803 {
3804 struct ieee80211_local *local = sdata->local;
3805 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3806 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
3807 u32 tx_flags = 0;
3808 u16 trans = 1;
3809 u16 status = 0;
3810
3811 sdata_assert_lock(sdata);
3812
3813 if (WARN_ON_ONCE(!auth_data))
3814 return -EINVAL;
3815
3816 auth_data->tries++;
3817
3818 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
3819 sdata_info(sdata, "authentication with %pM timed out\n",
3820 auth_data->bss->bssid);
3821
3822 /*
3823 * Most likely AP is not in the range so remove the
3824 * bss struct for that AP.
3825 */
3826 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3827
3828 return -ETIMEDOUT;
3829 }
3830
3831 drv_mgd_prepare_tx(local, sdata);
3832
3833 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3834 auth_data->bss->bssid, auth_data->tries,
3835 IEEE80211_AUTH_MAX_TRIES);
3836
3837 auth_data->expected_transaction = 2;
3838
3839 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3840 trans = auth_data->sae_trans;
3841 status = auth_data->sae_status;
3842 auth_data->expected_transaction = trans;
3843 }
3844
3845 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3846 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3847 IEEE80211_TX_INTFL_MLME_CONN_TX;
3848
3849 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
3850 auth_data->data, auth_data->data_len,
3851 auth_data->bss->bssid,
3852 auth_data->bss->bssid, NULL, 0, 0,
3853 tx_flags);
3854
3855 if (tx_flags == 0) {
3856 if (auth_data->algorithm == WLAN_AUTH_SAE)
3857 auth_data->timeout = jiffies +
3858 IEEE80211_AUTH_TIMEOUT_SAE;
3859 else
3860 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
3861 } else {
3862 auth_data->timeout =
3863 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
3864 }
3865
3866 auth_data->timeout_started = true;
3867 run_again(sdata, auth_data->timeout);
3868
3869 return 0;
3870 }
3871
3872 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
3873 {
3874 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3875 struct ieee80211_local *local = sdata->local;
3876
3877 sdata_assert_lock(sdata);
3878
3879 assoc_data->tries++;
3880 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
3881 sdata_info(sdata, "association with %pM timed out\n",
3882 assoc_data->bss->bssid);
3883
3884 /*
3885 * Most likely AP is not in the range so remove the
3886 * bss struct for that AP.
3887 */
3888 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
3889
3890 return -ETIMEDOUT;
3891 }
3892
3893 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
3894 assoc_data->bss->bssid, assoc_data->tries,
3895 IEEE80211_ASSOC_MAX_TRIES);
3896 ieee80211_send_assoc(sdata);
3897
3898 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
3899 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
3900 assoc_data->timeout_started = true;
3901 run_again(sdata, assoc_data->timeout);
3902 } else {
3903 assoc_data->timeout =
3904 round_jiffies_up(jiffies +
3905 IEEE80211_ASSOC_TIMEOUT_LONG);
3906 assoc_data->timeout_started = true;
3907 run_again(sdata, assoc_data->timeout);
3908 }
3909
3910 return 0;
3911 }
3912
3913 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
3914 __le16 fc, bool acked)
3915 {
3916 struct ieee80211_local *local = sdata->local;
3917
3918 sdata->u.mgd.status_fc = fc;
3919 sdata->u.mgd.status_acked = acked;
3920 sdata->u.mgd.status_received = true;
3921
3922 ieee80211_queue_work(&local->hw, &sdata->work);
3923 }
3924
3925 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
3926 {
3927 struct ieee80211_local *local = sdata->local;
3928 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3929
3930 sdata_lock(sdata);
3931
3932 if (ifmgd->status_received) {
3933 __le16 fc = ifmgd->status_fc;
3934 bool status_acked = ifmgd->status_acked;
3935
3936 ifmgd->status_received = false;
3937 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
3938 if (status_acked) {
3939 if (ifmgd->auth_data->algorithm ==
3940 WLAN_AUTH_SAE)
3941 ifmgd->auth_data->timeout =
3942 jiffies +
3943 IEEE80211_AUTH_TIMEOUT_SAE;
3944 else
3945 ifmgd->auth_data->timeout =
3946 jiffies +
3947 IEEE80211_AUTH_TIMEOUT_SHORT;
3948 run_again(sdata, ifmgd->auth_data->timeout);
3949 } else {
3950 ifmgd->auth_data->timeout = jiffies - 1;
3951 }
3952 ifmgd->auth_data->timeout_started = true;
3953 } else if (ifmgd->assoc_data &&
3954 (ieee80211_is_assoc_req(fc) ||
3955 ieee80211_is_reassoc_req(fc))) {
3956 if (status_acked) {
3957 ifmgd->assoc_data->timeout =
3958 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
3959 run_again(sdata, ifmgd->assoc_data->timeout);
3960 } else {
3961 ifmgd->assoc_data->timeout = jiffies - 1;
3962 }
3963 ifmgd->assoc_data->timeout_started = true;
3964 }
3965 }
3966
3967 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
3968 time_after(jiffies, ifmgd->auth_data->timeout)) {
3969 if (ifmgd->auth_data->done) {
3970 /*
3971 * ok ... we waited for assoc but userspace didn't,
3972 * so let's just kill the auth data
3973 */
3974 ieee80211_destroy_auth_data(sdata, false);
3975 } else if (ieee80211_auth(sdata)) {
3976 u8 bssid[ETH_ALEN];
3977 struct ieee80211_event event = {
3978 .type = MLME_EVENT,
3979 .u.mlme.data = AUTH_EVENT,
3980 .u.mlme.status = MLME_TIMEOUT,
3981 };
3982
3983 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3984
3985 ieee80211_destroy_auth_data(sdata, false);
3986
3987 cfg80211_auth_timeout(sdata->dev, bssid);
3988 drv_event_callback(sdata->local, sdata, &event);
3989 }
3990 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
3991 run_again(sdata, ifmgd->auth_data->timeout);
3992
3993 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
3994 time_after(jiffies, ifmgd->assoc_data->timeout)) {
3995 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
3996 ieee80211_do_assoc(sdata)) {
3997 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
3998 struct ieee80211_event event = {
3999 .type = MLME_EVENT,
4000 .u.mlme.data = ASSOC_EVENT,
4001 .u.mlme.status = MLME_TIMEOUT,
4002 };
4003
4004 ieee80211_destroy_assoc_data(sdata, false, false);
4005 cfg80211_assoc_timeout(sdata->dev, bss);
4006 drv_event_callback(sdata->local, sdata, &event);
4007 }
4008 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4009 run_again(sdata, ifmgd->assoc_data->timeout);
4010
4011 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4012 ifmgd->associated) {
4013 u8 bssid[ETH_ALEN];
4014 int max_tries;
4015
4016 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4017
4018 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4019 max_tries = max_nullfunc_tries;
4020 else
4021 max_tries = max_probe_tries;
4022
4023 /* ACK received for nullfunc probing frame */
4024 if (!ifmgd->probe_send_count)
4025 ieee80211_reset_ap_probe(sdata);
4026 else if (ifmgd->nullfunc_failed) {
4027 if (ifmgd->probe_send_count < max_tries) {
4028 mlme_dbg(sdata,
4029 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4030 bssid, ifmgd->probe_send_count,
4031 max_tries);
4032 ieee80211_mgd_probe_ap_send(sdata);
4033 } else {
4034 mlme_dbg(sdata,
4035 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4036 bssid);
4037 ieee80211_sta_connection_lost(sdata, bssid,
4038 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4039 false);
4040 }
4041 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4042 run_again(sdata, ifmgd->probe_timeout);
4043 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4044 mlme_dbg(sdata,
4045 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4046 bssid, probe_wait_ms);
4047 ieee80211_sta_connection_lost(sdata, bssid,
4048 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4049 } else if (ifmgd->probe_send_count < max_tries) {
4050 mlme_dbg(sdata,
4051 "No probe response from AP %pM after %dms, try %d/%i\n",
4052 bssid, probe_wait_ms,
4053 ifmgd->probe_send_count, max_tries);
4054 ieee80211_mgd_probe_ap_send(sdata);
4055 } else {
4056 /*
4057 * We actually lost the connection ... or did we?
4058 * Let's make sure!
4059 */
4060 mlme_dbg(sdata,
4061 "No probe response from AP %pM after %dms, disconnecting.\n",
4062 bssid, probe_wait_ms);
4063
4064 ieee80211_sta_connection_lost(sdata, bssid,
4065 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4066 }
4067 }
4068
4069 sdata_unlock(sdata);
4070 }
4071
4072 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4073 {
4074 struct ieee80211_sub_if_data *sdata =
4075 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4076 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4077
4078 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4079 return;
4080
4081 sdata->u.mgd.connection_loss = false;
4082 ieee80211_queue_work(&sdata->local->hw,
4083 &sdata->u.mgd.beacon_connection_loss_work);
4084 }
4085
4086 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4087 {
4088 struct ieee80211_sub_if_data *sdata =
4089 from_timer(sdata, t, u.mgd.conn_mon_timer);
4090 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4091 struct ieee80211_local *local = sdata->local;
4092
4093 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4094 return;
4095
4096 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4097 }
4098
4099 static void ieee80211_sta_monitor_work(struct work_struct *work)
4100 {
4101 struct ieee80211_sub_if_data *sdata =
4102 container_of(work, struct ieee80211_sub_if_data,
4103 u.mgd.monitor_work);
4104
4105 ieee80211_mgd_probe_ap(sdata, false);
4106 }
4107
4108 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4109 {
4110 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4111 __ieee80211_stop_poll(sdata);
4112
4113 /* let's probe the connection once */
4114 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4115 ieee80211_queue_work(&sdata->local->hw,
4116 &sdata->u.mgd.monitor_work);
4117 }
4118 }
4119
4120 #ifdef CONFIG_PM
4121 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4122 {
4123 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4124 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4125
4126 sdata_lock(sdata);
4127
4128 if (ifmgd->auth_data || ifmgd->assoc_data) {
4129 const u8 *bssid = ifmgd->auth_data ?
4130 ifmgd->auth_data->bss->bssid :
4131 ifmgd->assoc_data->bss->bssid;
4132
4133 /*
4134 * If we are trying to authenticate / associate while suspending,
4135 * cfg80211 won't know and won't actually abort those attempts,
4136 * thus we need to do that ourselves.
4137 */
4138 ieee80211_send_deauth_disassoc(sdata, bssid,
4139 IEEE80211_STYPE_DEAUTH,
4140 WLAN_REASON_DEAUTH_LEAVING,
4141 false, frame_buf);
4142 if (ifmgd->assoc_data)
4143 ieee80211_destroy_assoc_data(sdata, false, true);
4144 if (ifmgd->auth_data)
4145 ieee80211_destroy_auth_data(sdata, false);
4146 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4147 IEEE80211_DEAUTH_FRAME_LEN);
4148 }
4149
4150 /* This is a bit of a hack - we should find a better and more generic
4151 * solution to this. Normally when suspending, cfg80211 will in fact
4152 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4153 * auth (not so important) or assoc (this is the problem) process.
4154 *
4155 * As a consequence, it can happen that we are in the process of both
4156 * associating and suspending, and receive an association response
4157 * after cfg80211 has checked if it needs to disconnect, but before
4158 * we actually set the flag to drop incoming frames. This will then
4159 * cause the workqueue flush to process the association response in
4160 * the suspend, resulting in a successful association just before it
4161 * tries to remove the interface from the driver, which now though
4162 * has a channel context assigned ... this results in issues.
4163 *
4164 * To work around this (for now) simply deauth here again if we're
4165 * now connected.
4166 */
4167 if (ifmgd->associated && !sdata->local->wowlan) {
4168 u8 bssid[ETH_ALEN];
4169 struct cfg80211_deauth_request req = {
4170 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4171 .bssid = bssid,
4172 };
4173
4174 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4175 ieee80211_mgd_deauth(sdata, &req);
4176 }
4177
4178 sdata_unlock(sdata);
4179 }
4180
4181 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4182 {
4183 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4184
4185 sdata_lock(sdata);
4186 if (!ifmgd->associated) {
4187 sdata_unlock(sdata);
4188 return;
4189 }
4190
4191 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4192 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4193 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4194 ieee80211_sta_connection_lost(sdata,
4195 ifmgd->associated->bssid,
4196 WLAN_REASON_UNSPECIFIED,
4197 true);
4198 sdata_unlock(sdata);
4199 return;
4200 }
4201 sdata_unlock(sdata);
4202 }
4203 #endif
4204
4205 /* interface setup */
4206 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4207 {
4208 struct ieee80211_if_managed *ifmgd;
4209
4210 ifmgd = &sdata->u.mgd;
4211 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4212 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4213 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4214 ieee80211_beacon_connection_loss_work);
4215 INIT_WORK(&ifmgd->csa_connection_drop_work,
4216 ieee80211_csa_connection_drop_work);
4217 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4218 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4219 ieee80211_tdls_peer_del_work);
4220 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4221 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4222 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4223 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4224 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4225 ieee80211_sta_handle_tspec_ac_params_wk);
4226
4227 ifmgd->flags = 0;
4228 ifmgd->powersave = sdata->wdev.ps;
4229 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4230 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4231 ifmgd->p2p_noa_index = -1;
4232
4233 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4234 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4235 else
4236 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4237
4238 /* Setup TDLS data */
4239 spin_lock_init(&ifmgd->teardown_lock);
4240 ifmgd->teardown_skb = NULL;
4241 ifmgd->orig_teardown_skb = NULL;
4242 }
4243
4244 /* scan finished notification */
4245 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4246 {
4247 struct ieee80211_sub_if_data *sdata;
4248
4249 /* Restart STA timers */
4250 rcu_read_lock();
4251 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4252 if (ieee80211_sdata_running(sdata))
4253 ieee80211_restart_sta_timer(sdata);
4254 }
4255 rcu_read_unlock();
4256 }
4257
4258 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4259 struct cfg80211_bss *cbss)
4260 {
4261 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4262 const u8 *ht_cap_ie, *vht_cap_ie;
4263 const struct ieee80211_ht_cap *ht_cap;
4264 const struct ieee80211_vht_cap *vht_cap;
4265 u8 chains = 1;
4266
4267 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4268 return chains;
4269
4270 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4271 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4272 ht_cap = (void *)(ht_cap_ie + 2);
4273 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4274 /*
4275 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4276 * "Tx Unequal Modulation Supported" fields.
4277 */
4278 }
4279
4280 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4281 return chains;
4282
4283 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4284 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4285 u8 nss;
4286 u16 tx_mcs_map;
4287
4288 vht_cap = (void *)(vht_cap_ie + 2);
4289 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4290 for (nss = 8; nss > 0; nss--) {
4291 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4292 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4293 break;
4294 }
4295 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4296 chains = max(chains, nss);
4297 }
4298
4299 return chains;
4300 }
4301
4302 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4303 struct cfg80211_bss *cbss)
4304 {
4305 struct ieee80211_local *local = sdata->local;
4306 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4307 const struct ieee80211_ht_cap *ht_cap = NULL;
4308 const struct ieee80211_ht_operation *ht_oper = NULL;
4309 const struct ieee80211_vht_operation *vht_oper = NULL;
4310 struct ieee80211_supported_band *sband;
4311 struct cfg80211_chan_def chandef;
4312 int ret;
4313 u32 i;
4314 bool have_80mhz;
4315
4316 sband = local->hw.wiphy->bands[cbss->channel->band];
4317
4318 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4319 IEEE80211_STA_DISABLE_80P80MHZ |
4320 IEEE80211_STA_DISABLE_160MHZ);
4321
4322 rcu_read_lock();
4323
4324 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4325 sband->ht_cap.ht_supported) {
4326 const u8 *ht_oper_ie, *ht_cap_ie;
4327
4328 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
4329 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4330 ht_oper = (void *)(ht_oper_ie + 2);
4331
4332 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4333 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4334 ht_cap = (void *)(ht_cap_ie + 2);
4335
4336 if (!ht_cap) {
4337 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4338 ht_oper = NULL;
4339 }
4340 }
4341
4342 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4343 sband->vht_cap.vht_supported) {
4344 const u8 *vht_oper_ie, *vht_cap;
4345
4346 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4347 WLAN_EID_VHT_OPERATION);
4348 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4349 vht_oper = (void *)(vht_oper_ie + 2);
4350 if (vht_oper && !ht_oper) {
4351 vht_oper = NULL;
4352 sdata_info(sdata,
4353 "AP advertised VHT without HT, disabling both\n");
4354 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4355 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4356 }
4357
4358 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4359 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4360 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4361 vht_oper = NULL;
4362 }
4363 }
4364
4365 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4366 have_80mhz = false;
4367 for (i = 0; i < sband->n_channels; i++) {
4368 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4369 IEEE80211_CHAN_NO_80MHZ))
4370 continue;
4371
4372 have_80mhz = true;
4373 break;
4374 }
4375
4376 if (!have_80mhz)
4377 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4378
4379 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4380 cbss->channel,
4381 ht_oper, vht_oper,
4382 &chandef, false);
4383
4384 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4385 local->rx_chains);
4386
4387 rcu_read_unlock();
4388
4389 /* will change later if needed */
4390 sdata->smps_mode = IEEE80211_SMPS_OFF;
4391
4392 mutex_lock(&local->mtx);
4393 /*
4394 * If this fails (possibly due to channel context sharing
4395 * on incompatible channels, e.g. 80+80 and 160 sharing the
4396 * same control channel) try to use a smaller bandwidth.
4397 */
4398 ret = ieee80211_vif_use_channel(sdata, &chandef,
4399 IEEE80211_CHANCTX_SHARED);
4400
4401 /* don't downgrade for 5 and 10 MHz channels, though. */
4402 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4403 chandef.width == NL80211_CHAN_WIDTH_10)
4404 goto out;
4405
4406 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4407 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
4408 ret = ieee80211_vif_use_channel(sdata, &chandef,
4409 IEEE80211_CHANCTX_SHARED);
4410 }
4411 out:
4412 mutex_unlock(&local->mtx);
4413 return ret;
4414 }
4415
4416 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
4417 struct cfg80211_bss *cbss, bool assoc,
4418 bool override)
4419 {
4420 struct ieee80211_local *local = sdata->local;
4421 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4422 struct ieee80211_bss *bss = (void *)cbss->priv;
4423 struct sta_info *new_sta = NULL;
4424 struct ieee80211_supported_band *sband;
4425 bool have_sta = false;
4426 int err;
4427
4428 sband = local->hw.wiphy->bands[cbss->channel->band];
4429
4430 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4431 return -EINVAL;
4432
4433 /* If a reconfig is happening, bail out */
4434 if (local->in_reconfig)
4435 return -EBUSY;
4436
4437 if (assoc) {
4438 rcu_read_lock();
4439 have_sta = sta_info_get(sdata, cbss->bssid);
4440 rcu_read_unlock();
4441 }
4442
4443 if (!have_sta) {
4444 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4445 if (!new_sta)
4446 return -ENOMEM;
4447 }
4448
4449 /*
4450 * Set up the information for the new channel before setting the
4451 * new channel. We can't - completely race-free - change the basic
4452 * rates bitmap and the channel (sband) that it refers to, but if
4453 * we set it up before we at least avoid calling into the driver's
4454 * bss_info_changed() method with invalid information (since we do
4455 * call that from changing the channel - only for IDLE and perhaps
4456 * some others, but ...).
4457 *
4458 * So to avoid that, just set up all the new information before the
4459 * channel, but tell the driver to apply it only afterwards, since
4460 * it might need the new channel for that.
4461 */
4462 if (new_sta) {
4463 u32 rates = 0, basic_rates = 0;
4464 bool have_higher_than_11mbit;
4465 int min_rate = INT_MAX, min_rate_index = -1;
4466 const struct cfg80211_bss_ies *ies;
4467 int shift = ieee80211_vif_get_shift(&sdata->vif);
4468
4469 ieee80211_get_rates(sband, bss->supp_rates,
4470 bss->supp_rates_len,
4471 &rates, &basic_rates,
4472 &have_higher_than_11mbit,
4473 &min_rate, &min_rate_index,
4474 shift);
4475
4476 /*
4477 * This used to be a workaround for basic rates missing
4478 * in the association response frame. Now that we no
4479 * longer use the basic rates from there, it probably
4480 * doesn't happen any more, but keep the workaround so
4481 * in case some *other* APs are buggy in different ways
4482 * we can connect -- with a warning.
4483 */
4484 if (!basic_rates && min_rate_index >= 0) {
4485 sdata_info(sdata,
4486 "No basic rates, using min rate instead\n");
4487 basic_rates = BIT(min_rate_index);
4488 }
4489
4490 new_sta->sta.supp_rates[cbss->channel->band] = rates;
4491 sdata->vif.bss_conf.basic_rates = basic_rates;
4492
4493 /* cf. IEEE 802.11 9.2.12 */
4494 if (cbss->channel->band == NL80211_BAND_2GHZ &&
4495 have_higher_than_11mbit)
4496 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4497 else
4498 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4499
4500 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4501
4502 /* set timing information */
4503 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
4504 rcu_read_lock();
4505 ies = rcu_dereference(cbss->beacon_ies);
4506 if (ies) {
4507 const u8 *tim_ie;
4508
4509 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4510 sdata->vif.bss_conf.sync_device_ts =
4511 bss->device_ts_beacon;
4512 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4513 ies->data, ies->len);
4514 if (tim_ie && tim_ie[1] >= 2)
4515 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
4516 else
4517 sdata->vif.bss_conf.sync_dtim_count = 0;
4518 } else if (!ieee80211_hw_check(&sdata->local->hw,
4519 TIMING_BEACON_ONLY)) {
4520 ies = rcu_dereference(cbss->proberesp_ies);
4521 /* must be non-NULL since beacon IEs were NULL */
4522 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4523 sdata->vif.bss_conf.sync_device_ts =
4524 bss->device_ts_presp;
4525 sdata->vif.bss_conf.sync_dtim_count = 0;
4526 } else {
4527 sdata->vif.bss_conf.sync_tsf = 0;
4528 sdata->vif.bss_conf.sync_device_ts = 0;
4529 sdata->vif.bss_conf.sync_dtim_count = 0;
4530 }
4531 rcu_read_unlock();
4532 }
4533
4534 if (new_sta || override) {
4535 err = ieee80211_prep_channel(sdata, cbss);
4536 if (err) {
4537 if (new_sta)
4538 sta_info_free(local, new_sta);
4539 return -EINVAL;
4540 }
4541 }
4542
4543 if (new_sta) {
4544 /*
4545 * tell driver about BSSID, basic rates and timing
4546 * this was set up above, before setting the channel
4547 */
4548 ieee80211_bss_info_change_notify(sdata,
4549 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4550 BSS_CHANGED_BEACON_INT);
4551
4552 if (assoc)
4553 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
4554
4555 err = sta_info_insert(new_sta);
4556 new_sta = NULL;
4557 if (err) {
4558 sdata_info(sdata,
4559 "failed to insert STA entry for the AP (error %d)\n",
4560 err);
4561 return err;
4562 }
4563 } else
4564 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
4565
4566 /* Cancel scan to ensure that nothing interferes with connection */
4567 if (local->scanning)
4568 ieee80211_scan_cancel(local);
4569
4570 return 0;
4571 }
4572
4573 /* config hooks */
4574 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4575 struct cfg80211_auth_request *req)
4576 {
4577 struct ieee80211_local *local = sdata->local;
4578 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4579 struct ieee80211_mgd_auth_data *auth_data;
4580 u16 auth_alg;
4581 int err;
4582
4583 /* prepare auth data structure */
4584
4585 switch (req->auth_type) {
4586 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4587 auth_alg = WLAN_AUTH_OPEN;
4588 break;
4589 case NL80211_AUTHTYPE_SHARED_KEY:
4590 if (IS_ERR(local->wep_tx_tfm))
4591 return -EOPNOTSUPP;
4592 auth_alg = WLAN_AUTH_SHARED_KEY;
4593 break;
4594 case NL80211_AUTHTYPE_FT:
4595 auth_alg = WLAN_AUTH_FT;
4596 break;
4597 case NL80211_AUTHTYPE_NETWORK_EAP:
4598 auth_alg = WLAN_AUTH_LEAP;
4599 break;
4600 case NL80211_AUTHTYPE_SAE:
4601 auth_alg = WLAN_AUTH_SAE;
4602 break;
4603 case NL80211_AUTHTYPE_FILS_SK:
4604 auth_alg = WLAN_AUTH_FILS_SK;
4605 break;
4606 case NL80211_AUTHTYPE_FILS_SK_PFS:
4607 auth_alg = WLAN_AUTH_FILS_SK_PFS;
4608 break;
4609 case NL80211_AUTHTYPE_FILS_PK:
4610 auth_alg = WLAN_AUTH_FILS_PK;
4611 break;
4612 default:
4613 return -EOPNOTSUPP;
4614 }
4615
4616 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
4617 req->ie_len, GFP_KERNEL);
4618 if (!auth_data)
4619 return -ENOMEM;
4620
4621 auth_data->bss = req->bss;
4622
4623 if (req->auth_data_len >= 4) {
4624 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4625 __le16 *pos = (__le16 *) req->auth_data;
4626
4627 auth_data->sae_trans = le16_to_cpu(pos[0]);
4628 auth_data->sae_status = le16_to_cpu(pos[1]);
4629 }
4630 memcpy(auth_data->data, req->auth_data + 4,
4631 req->auth_data_len - 4);
4632 auth_data->data_len += req->auth_data_len - 4;
4633 }
4634
4635 if (req->ie && req->ie_len) {
4636 memcpy(&auth_data->data[auth_data->data_len],
4637 req->ie, req->ie_len);
4638 auth_data->data_len += req->ie_len;
4639 }
4640
4641 if (req->key && req->key_len) {
4642 auth_data->key_len = req->key_len;
4643 auth_data->key_idx = req->key_idx;
4644 memcpy(auth_data->key, req->key, req->key_len);
4645 }
4646
4647 auth_data->algorithm = auth_alg;
4648
4649 /* try to authenticate/probe */
4650
4651 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4652 ifmgd->assoc_data) {
4653 err = -EBUSY;
4654 goto err_free;
4655 }
4656
4657 if (ifmgd->auth_data)
4658 ieee80211_destroy_auth_data(sdata, false);
4659
4660 /* prep auth_data so we don't go into idle on disassoc */
4661 ifmgd->auth_data = auth_data;
4662
4663 if (ifmgd->associated) {
4664 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4665
4666 sdata_info(sdata,
4667 "disconnect from AP %pM for new auth to %pM\n",
4668 ifmgd->associated->bssid, req->bss->bssid);
4669 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4670 WLAN_REASON_UNSPECIFIED,
4671 false, frame_buf);
4672
4673 ieee80211_report_disconnect(sdata, frame_buf,
4674 sizeof(frame_buf), true,
4675 WLAN_REASON_UNSPECIFIED);
4676 }
4677
4678 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
4679
4680 err = ieee80211_prep_connection(sdata, req->bss, false, false);
4681 if (err)
4682 goto err_clear;
4683
4684 err = ieee80211_auth(sdata);
4685 if (err) {
4686 sta_info_destroy_addr(sdata, req->bss->bssid);
4687 goto err_clear;
4688 }
4689
4690 /* hold our own reference */
4691 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
4692 return 0;
4693
4694 err_clear:
4695 eth_zero_addr(ifmgd->bssid);
4696 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
4697 ifmgd->auth_data = NULL;
4698 mutex_lock(&sdata->local->mtx);
4699 ieee80211_vif_release_channel(sdata);
4700 mutex_unlock(&sdata->local->mtx);
4701 err_free:
4702 kfree(auth_data);
4703 return err;
4704 }
4705
4706 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4707 struct cfg80211_assoc_request *req)
4708 {
4709 struct ieee80211_local *local = sdata->local;
4710 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4711 struct ieee80211_bss *bss = (void *)req->bss->priv;
4712 struct ieee80211_mgd_assoc_data *assoc_data;
4713 const struct cfg80211_bss_ies *beacon_ies;
4714 struct ieee80211_supported_band *sband;
4715 const u8 *ssidie, *ht_ie, *vht_ie;
4716 int i, err;
4717 bool override = false;
4718
4719 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
4720 if (!assoc_data)
4721 return -ENOMEM;
4722
4723 rcu_read_lock();
4724 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4725 if (!ssidie) {
4726 rcu_read_unlock();
4727 kfree(assoc_data);
4728 return -EINVAL;
4729 }
4730 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
4731 assoc_data->ssid_len = ssidie[1];
4732 rcu_read_unlock();
4733
4734 if (ifmgd->associated) {
4735 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4736
4737 sdata_info(sdata,
4738 "disconnect from AP %pM for new assoc to %pM\n",
4739 ifmgd->associated->bssid, req->bss->bssid);
4740 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4741 WLAN_REASON_UNSPECIFIED,
4742 false, frame_buf);
4743
4744 ieee80211_report_disconnect(sdata, frame_buf,
4745 sizeof(frame_buf), true,
4746 WLAN_REASON_UNSPECIFIED);
4747 }
4748
4749 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
4750 err = -EBUSY;
4751 goto err_free;
4752 }
4753
4754 if (ifmgd->assoc_data) {
4755 err = -EBUSY;
4756 goto err_free;
4757 }
4758
4759 if (ifmgd->auth_data) {
4760 bool match;
4761
4762 /* keep sta info, bssid if matching */
4763 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
4764 ieee80211_destroy_auth_data(sdata, match);
4765 }
4766
4767 /* prepare assoc data */
4768
4769 ifmgd->beacon_crc_valid = false;
4770
4771 assoc_data->wmm = bss->wmm_used &&
4772 (local->hw.queues >= IEEE80211_NUM_ACS);
4773
4774 /*
4775 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4776 * We still associate in non-HT mode (11a/b/g) if any one of these
4777 * ciphers is configured as pairwise.
4778 * We can set this to true for non-11n hardware, that'll be checked
4779 * separately along with the peer capabilities.
4780 */
4781 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
4782 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
4783 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
4784 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
4785 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4786 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4787 netdev_info(sdata->dev,
4788 "disabling HT/VHT due to WEP/TKIP use\n");
4789 }
4790 }
4791
4792 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4793 sband = local->hw.wiphy->bands[req->bss->channel->band];
4794 if (!sband->ht_cap.ht_supported ||
4795 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
4796 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
4797 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4798 if (!bss->wmm_used &&
4799 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
4800 netdev_info(sdata->dev,
4801 "disabling HT as WMM/QoS is not supported by the AP\n");
4802 }
4803
4804 /* disable VHT if we don't support it or the AP doesn't use WMM */
4805 if (!sband->vht_cap.vht_supported ||
4806 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
4807 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
4808 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4809 if (!bss->wmm_used &&
4810 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
4811 netdev_info(sdata->dev,
4812 "disabling VHT as WMM/QoS is not supported by the AP\n");
4813 }
4814
4815 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
4816 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4817 sizeof(ifmgd->ht_capa_mask));
4818
4819 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4820 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4821 sizeof(ifmgd->vht_capa_mask));
4822
4823 if (req->ie && req->ie_len) {
4824 memcpy(assoc_data->ie, req->ie, req->ie_len);
4825 assoc_data->ie_len = req->ie_len;
4826 }
4827
4828 if (req->fils_kek) {
4829 /* should already be checked in cfg80211 - so warn */
4830 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
4831 err = -EINVAL;
4832 goto err_free;
4833 }
4834 memcpy(assoc_data->fils_kek, req->fils_kek,
4835 req->fils_kek_len);
4836 assoc_data->fils_kek_len = req->fils_kek_len;
4837 }
4838
4839 if (req->fils_nonces)
4840 memcpy(assoc_data->fils_nonces, req->fils_nonces,
4841 2 * FILS_NONCE_LEN);
4842
4843 assoc_data->bss = req->bss;
4844
4845 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
4846 if (ifmgd->powersave)
4847 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
4848 else
4849 sdata->smps_mode = IEEE80211_SMPS_OFF;
4850 } else
4851 sdata->smps_mode = ifmgd->req_smps;
4852
4853 assoc_data->capability = req->bss->capability;
4854 assoc_data->supp_rates = bss->supp_rates;
4855 assoc_data->supp_rates_len = bss->supp_rates_len;
4856
4857 rcu_read_lock();
4858 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
4859 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
4860 assoc_data->ap_ht_param =
4861 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
4862 else
4863 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4864 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
4865 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
4866 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
4867 sizeof(struct ieee80211_vht_cap));
4868 else
4869 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4870 rcu_read_unlock();
4871
4872 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
4873 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
4874 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
4875 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
4876
4877 if (bss->wmm_used && bss->uapsd_supported &&
4878 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
4879 assoc_data->uapsd = true;
4880 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4881 } else {
4882 assoc_data->uapsd = false;
4883 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
4884 }
4885
4886 if (req->prev_bssid)
4887 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
4888
4889 if (req->use_mfp) {
4890 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
4891 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4892 } else {
4893 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4894 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4895 }
4896
4897 if (req->flags & ASSOC_REQ_USE_RRM)
4898 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
4899 else
4900 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
4901
4902 if (req->crypto.control_port)
4903 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4904 else
4905 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4906
4907 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4908 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
4909 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
4910 sdata->vif.type);
4911
4912 /* kick off associate process */
4913
4914 ifmgd->assoc_data = assoc_data;
4915 ifmgd->dtim_period = 0;
4916 ifmgd->have_beacon = false;
4917
4918 /* override HT/VHT configuration only if the AP and we support it */
4919 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
4920 struct ieee80211_sta_ht_cap sta_ht_cap;
4921
4922 if (req->flags & ASSOC_REQ_DISABLE_HT)
4923 override = true;
4924
4925 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
4926 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
4927
4928 /* check for 40 MHz disable override */
4929 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
4930 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
4931 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
4932 override = true;
4933
4934 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4935 req->flags & ASSOC_REQ_DISABLE_VHT)
4936 override = true;
4937 }
4938
4939 if (req->flags & ASSOC_REQ_DISABLE_HT) {
4940 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4941 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4942 }
4943
4944 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4945 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4946
4947 err = ieee80211_prep_connection(sdata, req->bss, true, override);
4948 if (err)
4949 goto err_clear;
4950
4951 rcu_read_lock();
4952 beacon_ies = rcu_dereference(req->bss->beacon_ies);
4953
4954 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
4955 !beacon_ies) {
4956 /*
4957 * Wait up to one beacon interval ...
4958 * should this be more if we miss one?
4959 */
4960 sdata_info(sdata, "waiting for beacon from %pM\n",
4961 ifmgd->bssid);
4962 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
4963 assoc_data->timeout_started = true;
4964 assoc_data->need_beacon = true;
4965 } else if (beacon_ies) {
4966 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4967 beacon_ies->data,
4968 beacon_ies->len);
4969 u8 dtim_count = 0;
4970
4971 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
4972 const struct ieee80211_tim_ie *tim;
4973 tim = (void *)(tim_ie + 2);
4974 ifmgd->dtim_period = tim->dtim_period;
4975 dtim_count = tim->dtim_count;
4976 }
4977 ifmgd->have_beacon = true;
4978 assoc_data->timeout = jiffies;
4979 assoc_data->timeout_started = true;
4980
4981 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4982 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
4983 sdata->vif.bss_conf.sync_device_ts =
4984 bss->device_ts_beacon;
4985 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
4986 }
4987 } else {
4988 assoc_data->timeout = jiffies;
4989 assoc_data->timeout_started = true;
4990 }
4991 rcu_read_unlock();
4992
4993 run_again(sdata, assoc_data->timeout);
4994
4995 if (bss->corrupt_data) {
4996 char *corrupt_type = "data";
4997 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
4998 if (bss->corrupt_data &
4999 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5000 corrupt_type = "beacon and probe response";
5001 else
5002 corrupt_type = "beacon";
5003 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5004 corrupt_type = "probe response";
5005 sdata_info(sdata, "associating with AP with corrupt %s\n",
5006 corrupt_type);
5007 }
5008
5009 return 0;
5010 err_clear:
5011 eth_zero_addr(ifmgd->bssid);
5012 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5013 ifmgd->assoc_data = NULL;
5014 err_free:
5015 kfree(assoc_data);
5016 return err;
5017 }
5018
5019 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5020 struct cfg80211_deauth_request *req)
5021 {
5022 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5023 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5024 bool tx = !req->local_state_change;
5025
5026 if (ifmgd->auth_data &&
5027 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5028 sdata_info(sdata,
5029 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5030 req->bssid, req->reason_code,
5031 ieee80211_get_reason_code_string(req->reason_code));
5032
5033 drv_mgd_prepare_tx(sdata->local, sdata);
5034 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5035 IEEE80211_STYPE_DEAUTH,
5036 req->reason_code, tx,
5037 frame_buf);
5038 ieee80211_destroy_auth_data(sdata, false);
5039 ieee80211_report_disconnect(sdata, frame_buf,
5040 sizeof(frame_buf), true,
5041 req->reason_code);
5042
5043 return 0;
5044 }
5045
5046 if (ifmgd->assoc_data &&
5047 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5048 sdata_info(sdata,
5049 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5050 req->bssid, req->reason_code,
5051 ieee80211_get_reason_code_string(req->reason_code));
5052
5053 drv_mgd_prepare_tx(sdata->local, sdata);
5054 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5055 IEEE80211_STYPE_DEAUTH,
5056 req->reason_code, tx,
5057 frame_buf);
5058 ieee80211_destroy_assoc_data(sdata, false, true);
5059 ieee80211_report_disconnect(sdata, frame_buf,
5060 sizeof(frame_buf), true,
5061 req->reason_code);
5062 return 0;
5063 }
5064
5065 if (ifmgd->associated &&
5066 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5067 sdata_info(sdata,
5068 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5069 req->bssid, req->reason_code,
5070 ieee80211_get_reason_code_string(req->reason_code));
5071
5072 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5073 req->reason_code, tx, frame_buf);
5074 ieee80211_report_disconnect(sdata, frame_buf,
5075 sizeof(frame_buf), true,
5076 req->reason_code);
5077 return 0;
5078 }
5079
5080 return -ENOTCONN;
5081 }
5082
5083 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5084 struct cfg80211_disassoc_request *req)
5085 {
5086 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5087 u8 bssid[ETH_ALEN];
5088 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5089
5090 /*
5091 * cfg80211 should catch this ... but it's racy since
5092 * we can receive a disassoc frame, process it, hand it
5093 * to cfg80211 while that's in a locked section already
5094 * trying to tell us that the user wants to disconnect.
5095 */
5096 if (ifmgd->associated != req->bss)
5097 return -ENOLINK;
5098
5099 sdata_info(sdata,
5100 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5101 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5102
5103 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5104 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5105 req->reason_code, !req->local_state_change,
5106 frame_buf);
5107
5108 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5109 req->reason_code);
5110
5111 return 0;
5112 }
5113
5114 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5115 {
5116 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5117
5118 /*
5119 * Make sure some work items will not run after this,
5120 * they will not do anything but might not have been
5121 * cancelled when disconnecting.
5122 */
5123 cancel_work_sync(&ifmgd->monitor_work);
5124 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5125 cancel_work_sync(&ifmgd->request_smps_work);
5126 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5127 cancel_work_sync(&ifmgd->chswitch_work);
5128 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5129
5130 sdata_lock(sdata);
5131 if (ifmgd->assoc_data) {
5132 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5133 ieee80211_destroy_assoc_data(sdata, false, false);
5134 cfg80211_assoc_timeout(sdata->dev, bss);
5135 }
5136 if (ifmgd->auth_data)
5137 ieee80211_destroy_auth_data(sdata, false);
5138 spin_lock_bh(&ifmgd->teardown_lock);
5139 if (ifmgd->teardown_skb) {
5140 kfree_skb(ifmgd->teardown_skb);
5141 ifmgd->teardown_skb = NULL;
5142 ifmgd->orig_teardown_skb = NULL;
5143 }
5144 spin_unlock_bh(&ifmgd->teardown_lock);
5145 del_timer_sync(&ifmgd->timer);
5146 sdata_unlock(sdata);
5147 }
5148
5149 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5150 enum nl80211_cqm_rssi_threshold_event rssi_event,
5151 s32 rssi_level,
5152 gfp_t gfp)
5153 {
5154 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5155
5156 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
5157
5158 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
5159 }
5160 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
5161
5162 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5163 {
5164 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5165
5166 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5167
5168 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5169 }
5170 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);