cfg80211: regulatory: reset regdomain in case of error
[deliverable/linux.git] / net / mac80211 / mlme.c
CommitLineData
f0706e82
JB
1/*
2 * BSS client mode implementation
5394af4d 3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
f0706e82
JB
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
5b323edb 14#include <linux/delay.h>
f0706e82
JB
15#include <linux/if_ether.h>
16#include <linux/skbuff.h>
f0706e82 17#include <linux/if_arp.h>
f0706e82 18#include <linux/etherdevice.h>
d9b93842 19#include <linux/moduleparam.h>
d0709a65 20#include <linux/rtnetlink.h>
e8db0be1 21#include <linux/pm_qos.h>
d91f36db 22#include <linux/crc32.h>
5a0e3ad6 23#include <linux/slab.h>
bc3b2d7f 24#include <linux/export.h>
f0706e82 25#include <net/mac80211.h>
472dbc45 26#include <asm/unaligned.h>
60f8b39c 27
f0706e82 28#include "ieee80211_i.h"
24487981 29#include "driver-ops.h"
2c8dccc7
JB
30#include "rate.h"
31#include "led.h"
f0706e82 32
1672c0e3 33#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
cb236d2d 34#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
1672c0e3
JB
35#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
36#define IEEE80211_AUTH_MAX_TRIES 3
37#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
38#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
cb236d2d 39#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
1672c0e3
JB
40#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
41#define IEEE80211_ASSOC_MAX_TRIES 3
66e67e41 42
180205bd
BG
43static int max_nullfunc_tries = 2;
44module_param(max_nullfunc_tries, int, 0644);
45MODULE_PARM_DESC(max_nullfunc_tries,
46 "Maximum nullfunc tx tries before disconnecting (reason 4).");
47
48static int max_probe_tries = 5;
49module_param(max_probe_tries, int, 0644);
50MODULE_PARM_DESC(max_probe_tries,
51 "Maximum probe tries before disconnecting (reason 4).");
b291ba11
JB
52
53/*
7ccc8bd7
FF
54 * Beacon loss timeout is calculated as N frames times the
55 * advertised beacon interval. This may need to be somewhat
56 * higher than what hardware might detect to account for
57 * delays in the host processing frames. But since we also
58 * probe on beacon miss before declaring the connection lost
59 * default to what we want.
b291ba11 60 */
59c1ec2b
BG
61static int beacon_loss_count = 7;
62module_param(beacon_loss_count, int, 0644);
63MODULE_PARM_DESC(beacon_loss_count,
64 "Number of beacon intervals before we decide beacon was lost.");
7ccc8bd7 65
b291ba11
JB
66/*
67 * Time the connection can be idle before we probe
68 * it to see if we can still talk to the AP.
69 */
d1c5091f 70#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
b291ba11
JB
71/*
72 * Time we wait for a probe response after sending
73 * a probe request because of beacon loss or for
74 * checking the connection still works.
75 */
180205bd
BG
76static int probe_wait_ms = 500;
77module_param(probe_wait_ms, int, 0644);
78MODULE_PARM_DESC(probe_wait_ms,
79 "Maximum time(ms) to wait for probe response"
80 " before disconnecting (reason 4).");
f0706e82 81
17e4ec14
JM
82/*
83 * Weight given to the latest Beacon frame when calculating average signal
84 * strength for Beacon frames received in the current BSS. This must be
85 * between 1 and 15.
86 */
87#define IEEE80211_SIGNAL_AVE_WEIGHT 3
88
391a200a
JM
89/*
90 * How many Beacon frames need to have been used in average signal strength
91 * before starting to indicate signal change events.
92 */
93#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
94
ca386f31
JB
95/*
96 * We can have multiple work items (and connection probing)
97 * scheduling this timer, but we need to take care to only
98 * reschedule it when it should fire _earlier_ than it was
99 * asked for before, or if it's not pending right now. This
100 * function ensures that. Note that it then is required to
101 * run this function for all timeouts after the first one
102 * has happened -- the work that runs from this timer will
103 * do that.
104 */
8d61ffa5
JB
105static void run_again(struct ieee80211_sub_if_data *sdata,
106 unsigned long timeout)
ca386f31 107{
8d61ffa5 108 sdata_assert_lock(sdata);
ca386f31 109
8d61ffa5
JB
110 if (!timer_pending(&sdata->u.mgd.timer) ||
111 time_before(timeout, sdata->u.mgd.timer.expires))
112 mod_timer(&sdata->u.mgd.timer, timeout);
ca386f31
JB
113}
114
d3a910a8 115void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
b291ba11 116{
c1288b12 117 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
b291ba11
JB
118 return;
119
7eeff74c
JB
120 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
121 return;
122
b291ba11 123 mod_timer(&sdata->u.mgd.bcn_mon_timer,
7ccc8bd7 124 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
b291ba11
JB
125}
126
be099e82
LR
127void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
128{
0c699c3a
LR
129 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
130
8628172f
SG
131 if (unlikely(!sdata->u.mgd.associated))
132 return;
133
be099e82
LR
134 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
135 return;
136
137 mod_timer(&sdata->u.mgd.conn_mon_timer,
138 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
0c699c3a
LR
139
140 ifmgd->probe_send_count = 0;
be099e82
LR
141}
142
5484e237 143static int ecw2cw(int ecw)
60f8b39c 144{
5484e237 145 return (1 << ecw) - 1;
60f8b39c
JB
146}
147
6565ec9b
JB
148static u32
149ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
150 struct ieee80211_supported_band *sband,
151 struct ieee80211_channel *channel,
152 const struct ieee80211_ht_operation *ht_oper,
153 const struct ieee80211_vht_operation *vht_oper,
5cdaed1e 154 struct cfg80211_chan_def *chandef, bool tracking)
6565ec9b 155{
5cdaed1e 156 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6565ec9b
JB
157 struct cfg80211_chan_def vht_chandef;
158 u32 ht_cfreq, ret;
159
160 chandef->chan = channel;
161 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
162 chandef->center_freq1 = channel->center_freq;
163 chandef->center_freq2 = 0;
164
165 if (!ht_oper || !sband->ht_cap.ht_supported) {
166 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
167 goto out;
168 }
169
170 chandef->width = NL80211_CHAN_WIDTH_20;
171
172 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
173 channel->band);
174 /* check that channel matches the right operating channel */
5cdaed1e 175 if (!tracking && channel->center_freq != ht_cfreq) {
6565ec9b
JB
176 /*
177 * It's possible that some APs are confused here;
178 * Netgear WNDR3700 sometimes reports 4 higher than
179 * the actual channel in association responses, but
180 * since we look at probe response/beacon data here
181 * it should be OK.
182 */
5cdaed1e
JB
183 sdata_info(sdata,
184 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
185 channel->center_freq, ht_cfreq,
186 ht_oper->primary_chan, channel->band);
6565ec9b
JB
187 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
188 goto out;
189 }
190
191 /* check 40 MHz support, if we have it */
192 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
193 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
194 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
195 chandef->width = NL80211_CHAN_WIDTH_40;
196 chandef->center_freq1 += 10;
197 break;
198 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
199 chandef->width = NL80211_CHAN_WIDTH_40;
200 chandef->center_freq1 -= 10;
201 break;
202 }
203 } else {
204 /* 40 MHz (and 80 MHz) must be supported for VHT */
205 ret = IEEE80211_STA_DISABLE_VHT;
85220d71
JB
206 /* also mark 40 MHz disabled */
207 ret |= IEEE80211_STA_DISABLE_40MHZ;
6565ec9b
JB
208 goto out;
209 }
210
211 if (!vht_oper || !sband->vht_cap.vht_supported) {
212 ret = IEEE80211_STA_DISABLE_VHT;
213 goto out;
214 }
215
216 vht_chandef.chan = channel;
217 vht_chandef.center_freq1 =
218 ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
219 channel->band);
220 vht_chandef.center_freq2 = 0;
221
6565ec9b
JB
222 switch (vht_oper->chan_width) {
223 case IEEE80211_VHT_CHANWIDTH_USE_HT:
224 vht_chandef.width = chandef->width;
225 break;
226 case IEEE80211_VHT_CHANWIDTH_80MHZ:
227 vht_chandef.width = NL80211_CHAN_WIDTH_80;
228 break;
229 case IEEE80211_VHT_CHANWIDTH_160MHZ:
230 vht_chandef.width = NL80211_CHAN_WIDTH_160;
231 break;
232 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
233 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
6553bf04
JB
234 vht_chandef.center_freq2 =
235 ieee80211_channel_to_frequency(
236 vht_oper->center_freq_seg2_idx,
237 channel->band);
6565ec9b
JB
238 break;
239 default:
5cdaed1e 240 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
30eb1dc2
JB
241 sdata_info(sdata,
242 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
243 vht_oper->chan_width);
6565ec9b
JB
244 ret = IEEE80211_STA_DISABLE_VHT;
245 goto out;
246 }
247
248 if (!cfg80211_chandef_valid(&vht_chandef)) {
5cdaed1e 249 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
30eb1dc2
JB
250 sdata_info(sdata,
251 "AP VHT information is invalid, disable VHT\n");
6565ec9b
JB
252 ret = IEEE80211_STA_DISABLE_VHT;
253 goto out;
254 }
255
256 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
257 ret = 0;
258 goto out;
259 }
260
261 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
5cdaed1e 262 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
30eb1dc2
JB
263 sdata_info(sdata,
264 "AP VHT information doesn't match HT, disable VHT\n");
6565ec9b
JB
265 ret = IEEE80211_STA_DISABLE_VHT;
266 goto out;
267 }
268
269 *chandef = vht_chandef;
270
271 ret = 0;
272
273out:
963a1852
JB
274 /*
275 * When tracking the current AP, don't do any further checks if the
276 * new chandef is identical to the one we're currently using for the
277 * connection. This keeps us from playing ping-pong with regulatory,
278 * without it the following can happen (for example):
279 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
280 * - AP advertises regdom US
281 * - CRDA loads regdom US with 80 MHz prohibited (old database)
282 * - the code below detects an unsupported channel, downgrades, and
283 * we disconnect from the AP in the caller
284 * - disconnect causes CRDA to reload world regdomain and the game
285 * starts anew.
286 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
287 *
288 * It seems possible that there are still scenarios with CSA or real
289 * bandwidth changes where a this could happen, but those cases are
290 * less common and wouldn't completely prevent using the AP.
291 */
292 if (tracking &&
293 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
294 return ret;
295
586e01ed
JB
296 /* don't print the message below for VHT mismatch if VHT is disabled */
297 if (ret & IEEE80211_STA_DISABLE_VHT)
298 vht_chandef = *chandef;
299
ddfe49b4
JB
300 /*
301 * Ignore the DISABLED flag when we're already connected and only
302 * tracking the APs beacon for bandwidth changes - otherwise we
303 * might get disconnected here if we connect to an AP, update our
304 * regulatory information based on the AP's country IE and the
305 * information we have is wrong/outdated and disables the channel
306 * that we're actually using for the connection to the AP.
307 */
6565ec9b 308 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
ddfe49b4
JB
309 tracking ? 0 :
310 IEEE80211_CHAN_DISABLED)) {
6565ec9b
JB
311 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
312 ret = IEEE80211_STA_DISABLE_HT |
313 IEEE80211_STA_DISABLE_VHT;
b56e4b85 314 break;
6565ec9b
JB
315 }
316
e6b7cde4 317 ret |= ieee80211_chandef_downgrade(chandef);
6565ec9b
JB
318 }
319
5cdaed1e 320 if (chandef->width != vht_chandef.width && !tracking)
6565ec9b
JB
321 sdata_info(sdata,
322 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
323
324 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
325 return ret;
326}
327
30eb1dc2
JB
328static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
329 struct sta_info *sta,
330 const struct ieee80211_ht_operation *ht_oper,
331 const struct ieee80211_vht_operation *vht_oper,
332 const u8 *bssid, u32 *changed)
d5522e03
JB
333{
334 struct ieee80211_local *local = sdata->local;
30eb1dc2 335 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
d5522e03 336 struct ieee80211_supported_band *sband;
55de908a 337 struct ieee80211_channel *chan;
30eb1dc2 338 struct cfg80211_chan_def chandef;
9ed6bcce 339 u16 ht_opmode;
30eb1dc2
JB
340 u32 flags;
341 enum ieee80211_sta_rx_bandwidth new_sta_bw;
342 int ret;
d5522e03 343
30eb1dc2
JB
344 /* if HT was/is disabled, don't track any bandwidth changes */
345 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
1128958d
JB
346 return 0;
347
30eb1dc2
JB
348 /* don't check VHT if we associated as non-VHT station */
349 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
350 vht_oper = NULL;
351
352 if (WARN_ON_ONCE(!sta))
353 return -EINVAL;
354
017b45bb
AA
355 /*
356 * if bss configuration changed store the new one -
357 * this may be applicable even if channel is identical
358 */
359 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
360 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
361 *changed |= BSS_CHANGED_HT;
362 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
363 }
364
f2d9330e 365 chan = sdata->vif.bss_conf.chandef.chan;
55de908a 366 sband = local->hw.wiphy->bands[chan->band];
d5522e03 367
30eb1dc2
JB
368 /* calculate new channel (type) based on HT/VHT operation IEs */
369 flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
5cdaed1e 370 vht_oper, &chandef, true);
30eb1dc2
JB
371
372 /*
373 * Downgrade the new channel if we associated with restricted
374 * capabilities. For example, if we associated as a 20 MHz STA
375 * to a 40 MHz AP (due to regulatory, capabilities or config
376 * reasons) then switching to a 40 MHz channel now won't do us
377 * any good -- we couldn't use it with the AP.
378 */
379 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
380 chandef.width == NL80211_CHAN_WIDTH_80P80)
e6b7cde4 381 flags |= ieee80211_chandef_downgrade(&chandef);
30eb1dc2
JB
382 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
383 chandef.width == NL80211_CHAN_WIDTH_160)
e6b7cde4 384 flags |= ieee80211_chandef_downgrade(&chandef);
30eb1dc2
JB
385 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
386 chandef.width > NL80211_CHAN_WIDTH_20)
e6b7cde4 387 flags |= ieee80211_chandef_downgrade(&chandef);
30eb1dc2
JB
388
389 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
390 return 0;
391
392 sdata_info(sdata,
393 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
394 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
395 chandef.center_freq1, chandef.center_freq2);
396
397 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
398 IEEE80211_STA_DISABLE_VHT |
399 IEEE80211_STA_DISABLE_40MHZ |
400 IEEE80211_STA_DISABLE_80P80MHZ |
401 IEEE80211_STA_DISABLE_160MHZ)) ||
402 !cfg80211_chandef_valid(&chandef)) {
403 sdata_info(sdata,
404 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
405 ifmgd->bssid);
406 return -EINVAL;
407 }
408
409 switch (chandef.width) {
410 case NL80211_CHAN_WIDTH_20_NOHT:
411 case NL80211_CHAN_WIDTH_20:
412 new_sta_bw = IEEE80211_STA_RX_BW_20;
413 break;
4bf88530 414 case NL80211_CHAN_WIDTH_40:
30eb1dc2 415 new_sta_bw = IEEE80211_STA_RX_BW_40;
64f68e5d 416 break;
30eb1dc2
JB
417 case NL80211_CHAN_WIDTH_80:
418 new_sta_bw = IEEE80211_STA_RX_BW_80;
419 break;
420 case NL80211_CHAN_WIDTH_80P80:
421 case NL80211_CHAN_WIDTH_160:
422 new_sta_bw = IEEE80211_STA_RX_BW_160;
64f68e5d 423 break;
30eb1dc2
JB
424 default:
425 return -EINVAL;
64f68e5d 426 }
d5522e03 427
30eb1dc2
JB
428 if (new_sta_bw > sta->cur_max_bandwidth)
429 new_sta_bw = sta->cur_max_bandwidth;
64f68e5d 430
30eb1dc2
JB
431 if (new_sta_bw < sta->sta.bandwidth) {
432 sta->sta.bandwidth = new_sta_bw;
433 rate_control_rate_update(local, sband, sta,
434 IEEE80211_RC_BW_CHANGED);
435 }
64f68e5d 436
30eb1dc2
JB
437 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
438 if (ret) {
439 sdata_info(sdata,
440 "AP %pM changed bandwidth to incompatible one - disconnect\n",
441 ifmgd->bssid);
442 return ret;
443 }
7cc44ed4 444
30eb1dc2
JB
445 if (new_sta_bw > sta->sta.bandwidth) {
446 sta->sta.bandwidth = new_sta_bw;
447 rate_control_rate_update(local, sband, sta,
448 IEEE80211_RC_BW_CHANGED);
0aaffa9b 449 }
d5522e03 450
30eb1dc2 451 return 0;
d5522e03
JB
452}
453
9c6bd790
JB
454/* frame sending functions */
455
66e67e41 456static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
9dde6423 457 struct sk_buff *skb, u8 ap_ht_param,
66e67e41
JB
458 struct ieee80211_supported_band *sband,
459 struct ieee80211_channel *channel,
460 enum ieee80211_smps_mode smps)
461{
66e67e41
JB
462 u8 *pos;
463 u32 flags = channel->flags;
464 u16 cap;
465 struct ieee80211_sta_ht_cap ht_cap;
466
467 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
468
66e67e41
JB
469 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
470 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
471
66e67e41
JB
472 /* determine capability flags */
473 cap = ht_cap.cap;
474
9dde6423 475 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
66e67e41
JB
476 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
477 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
478 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
479 cap &= ~IEEE80211_HT_CAP_SGI_40;
480 }
481 break;
482 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
483 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
484 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
485 cap &= ~IEEE80211_HT_CAP_SGI_40;
486 }
487 break;
488 }
489
24398e39
JB
490 /*
491 * If 40 MHz was disabled associate as though we weren't
492 * capable of 40 MHz -- some broken APs will never fall
493 * back to trying to transmit in 20 MHz.
494 */
495 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
496 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
497 cap &= ~IEEE80211_HT_CAP_SGI_40;
498 }
499
66e67e41
JB
500 /* set SM PS mode properly */
501 cap &= ~IEEE80211_HT_CAP_SM_PS;
502 switch (smps) {
503 case IEEE80211_SMPS_AUTOMATIC:
504 case IEEE80211_SMPS_NUM_MODES:
505 WARN_ON(1);
506 case IEEE80211_SMPS_OFF:
507 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
508 IEEE80211_HT_CAP_SM_PS_SHIFT;
509 break;
510 case IEEE80211_SMPS_STATIC:
511 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
512 IEEE80211_HT_CAP_SM_PS_SHIFT;
513 break;
514 case IEEE80211_SMPS_DYNAMIC:
515 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
516 IEEE80211_HT_CAP_SM_PS_SHIFT;
517 break;
518 }
519
520 /* reserve and fill IE */
521 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
522 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
523}
524
d545daba
MP
525static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
526 struct sk_buff *skb,
b08fbbd8
JB
527 struct ieee80211_supported_band *sband,
528 struct ieee80211_vht_cap *ap_vht_cap)
d545daba
MP
529{
530 u8 *pos;
531 u32 cap;
532 struct ieee80211_sta_vht_cap vht_cap;
533
534 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
535
536 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
dd5ecfea 537 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
d545daba
MP
538
539 /* determine capability flags */
540 cap = vht_cap.cap;
541
f2d9d270
JB
542 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
543 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
544 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
545 }
546
547 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
548 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
549 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
550 }
551
b08fbbd8
JB
552 /*
553 * Some APs apparently get confused if our capabilities are better
554 * than theirs, so restrict what we advertise in the assoc request.
555 */
556 if (!(ap_vht_cap->vht_cap_info &
557 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
558 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
559
d545daba 560 /* reserve and fill IE */
d4950281 561 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
d545daba
MP
562 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
563}
564
66e67e41
JB
565static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
566{
567 struct ieee80211_local *local = sdata->local;
568 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
569 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
570 struct sk_buff *skb;
571 struct ieee80211_mgmt *mgmt;
572 u8 *pos, qos_info;
573 size_t offset = 0, noffset;
2103dec1 574 int i, count, rates_len, supp_rates_len, shift;
66e67e41
JB
575 u16 capab;
576 struct ieee80211_supported_band *sband;
55de908a
JB
577 struct ieee80211_chanctx_conf *chanctx_conf;
578 struct ieee80211_channel *chan;
2103dec1 579 u32 rate_flags, rates = 0;
66e67e41 580
8d61ffa5 581 sdata_assert_lock(sdata);
66e67e41 582
55de908a
JB
583 rcu_read_lock();
584 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
585 if (WARN_ON(!chanctx_conf)) {
586 rcu_read_unlock();
587 return;
588 }
4bf88530 589 chan = chanctx_conf->def.chan;
2103dec1 590 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
55de908a
JB
591 rcu_read_unlock();
592 sband = local->hw.wiphy->bands[chan->band];
2103dec1 593 shift = ieee80211_vif_get_shift(&sdata->vif);
66e67e41
JB
594
595 if (assoc_data->supp_rates_len) {
596 /*
597 * Get all rates supported by the device and the AP as
598 * some APs don't like getting a superset of their rates
599 * in the association request (e.g. D-Link DAP 1353 in
600 * b-only mode)...
601 */
2103dec1
SW
602 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
603 assoc_data->supp_rates,
604 assoc_data->supp_rates_len,
605 &rates);
66e67e41
JB
606 } else {
607 /*
608 * In case AP not provide any supported rates information
609 * before association, we send information element(s) with
610 * all rates that we support.
611 */
2103dec1
SW
612 rates_len = 0;
613 for (i = 0; i < sband->n_bitrates; i++) {
614 if ((rate_flags & sband->bitrates[i].flags)
615 != rate_flags)
616 continue;
617 rates |= BIT(i);
618 rates_len++;
619 }
66e67e41
JB
620 }
621
622 skb = alloc_skb(local->hw.extra_tx_headroom +
623 sizeof(*mgmt) + /* bit too much but doesn't matter */
624 2 + assoc_data->ssid_len + /* SSID */
625 4 + rates_len + /* (extended) rates */
626 4 + /* power capability */
627 2 + 2 * sband->n_channels + /* supported channels */
628 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
d4950281 629 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
66e67e41
JB
630 assoc_data->ie_len + /* extra IEs */
631 9, /* WMM */
632 GFP_KERNEL);
633 if (!skb)
634 return;
635
636 skb_reserve(skb, local->hw.extra_tx_headroom);
637
638 capab = WLAN_CAPABILITY_ESS;
639
640 if (sband->band == IEEE80211_BAND_2GHZ) {
641 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
642 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
643 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
644 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
645 }
646
647 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
648 capab |= WLAN_CAPABILITY_PRIVACY;
649
650 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
651 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
652 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
653
654 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
655 memset(mgmt, 0, 24);
656 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
657 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
658 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
659
660 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
661 skb_put(skb, 10);
662 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
663 IEEE80211_STYPE_REASSOC_REQ);
664 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
665 mgmt->u.reassoc_req.listen_interval =
666 cpu_to_le16(local->hw.conf.listen_interval);
667 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
668 ETH_ALEN);
669 } else {
670 skb_put(skb, 4);
671 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
672 IEEE80211_STYPE_ASSOC_REQ);
673 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
674 mgmt->u.assoc_req.listen_interval =
675 cpu_to_le16(local->hw.conf.listen_interval);
676 }
677
678 /* SSID */
679 pos = skb_put(skb, 2 + assoc_data->ssid_len);
680 *pos++ = WLAN_EID_SSID;
681 *pos++ = assoc_data->ssid_len;
682 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
683
684 /* add all rates which were marked to be used above */
685 supp_rates_len = rates_len;
686 if (supp_rates_len > 8)
687 supp_rates_len = 8;
688
689 pos = skb_put(skb, supp_rates_len + 2);
690 *pos++ = WLAN_EID_SUPP_RATES;
691 *pos++ = supp_rates_len;
692
693 count = 0;
694 for (i = 0; i < sband->n_bitrates; i++) {
695 if (BIT(i) & rates) {
2103dec1
SW
696 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
697 5 * (1 << shift));
698 *pos++ = (u8) rate;
66e67e41
JB
699 if (++count == 8)
700 break;
701 }
702 }
703
704 if (rates_len > count) {
705 pos = skb_put(skb, rates_len - count + 2);
706 *pos++ = WLAN_EID_EXT_SUPP_RATES;
707 *pos++ = rates_len - count;
708
709 for (i++; i < sband->n_bitrates; i++) {
710 if (BIT(i) & rates) {
2103dec1
SW
711 int rate;
712 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
713 5 * (1 << shift));
714 *pos++ = (u8) rate;
66e67e41
JB
715 }
716 }
717 }
718
719 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
720 /* 1. power capabilities */
721 pos = skb_put(skb, 4);
722 *pos++ = WLAN_EID_PWR_CAPABILITY;
723 *pos++ = 2;
724 *pos++ = 0; /* min tx power */
0430c883
SW
725 /* max tx power */
726 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
66e67e41
JB
727
728 /* 2. supported channels */
729 /* TODO: get this in reg domain format */
730 pos = skb_put(skb, 2 * sband->n_channels + 2);
731 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
732 *pos++ = 2 * sband->n_channels;
733 for (i = 0; i < sband->n_channels; i++) {
734 *pos++ = ieee80211_frequency_to_channel(
735 sband->channels[i].center_freq);
736 *pos++ = 1; /* one channel in the subband*/
737 }
738 }
739
740 /* if present, add any custom IEs that go before HT */
b3f51e94 741 if (assoc_data->ie_len) {
66e67e41
JB
742 static const u8 before_ht[] = {
743 WLAN_EID_SSID,
744 WLAN_EID_SUPP_RATES,
745 WLAN_EID_EXT_SUPP_RATES,
746 WLAN_EID_PWR_CAPABILITY,
747 WLAN_EID_SUPPORTED_CHANNELS,
748 WLAN_EID_RSN,
749 WLAN_EID_QOS_CAPA,
750 WLAN_EID_RRM_ENABLED_CAPABILITIES,
751 WLAN_EID_MOBILITY_DOMAIN,
752 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
753 };
754 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
755 before_ht, ARRAY_SIZE(before_ht),
756 offset);
757 pos = skb_put(skb, noffset - offset);
758 memcpy(pos, assoc_data->ie + offset, noffset - offset);
759 offset = noffset;
760 }
761
f2d9d270
JB
762 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
763 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
764 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
765
a8243b72 766 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
9dde6423 767 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
04ecd257 768 sband, chan, sdata->smps_mode);
66e67e41 769
d545daba 770 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
b08fbbd8
JB
771 ieee80211_add_vht_ie(sdata, skb, sband,
772 &assoc_data->ap_vht_cap);
d545daba 773
66e67e41 774 /* if present, add any custom non-vendor IEs that go after HT */
b3f51e94 775 if (assoc_data->ie_len) {
66e67e41
JB
776 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
777 assoc_data->ie_len,
778 offset);
779 pos = skb_put(skb, noffset - offset);
780 memcpy(pos, assoc_data->ie + offset, noffset - offset);
781 offset = noffset;
782 }
783
76f0303d
JB
784 if (assoc_data->wmm) {
785 if (assoc_data->uapsd) {
dc41e4d4
EP
786 qos_info = ifmgd->uapsd_queues;
787 qos_info |= (ifmgd->uapsd_max_sp_len <<
66e67e41
JB
788 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
789 } else {
790 qos_info = 0;
791 }
792
793 pos = skb_put(skb, 9);
794 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
795 *pos++ = 7; /* len */
796 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
797 *pos++ = 0x50;
798 *pos++ = 0xf2;
799 *pos++ = 2; /* WME */
800 *pos++ = 0; /* WME info */
801 *pos++ = 1; /* WME ver */
802 *pos++ = qos_info;
803 }
804
805 /* add any remaining custom (i.e. vendor specific here) IEs */
b3f51e94 806 if (assoc_data->ie_len) {
66e67e41
JB
807 noffset = assoc_data->ie_len;
808 pos = skb_put(skb, noffset - offset);
809 memcpy(pos, assoc_data->ie + offset, noffset - offset);
810 }
811
a1845fc7
JB
812 drv_mgd_prepare_tx(local, sdata);
813
66e67e41 814 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1672c0e3
JB
815 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
816 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
817 IEEE80211_TX_INTFL_MLME_CONN_TX;
66e67e41
JB
818 ieee80211_tx_skb(sdata, skb);
819}
820
572e0012
KV
821void ieee80211_send_pspoll(struct ieee80211_local *local,
822 struct ieee80211_sub_if_data *sdata)
823{
572e0012
KV
824 struct ieee80211_pspoll *pspoll;
825 struct sk_buff *skb;
572e0012 826
d8cd189e
KV
827 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
828 if (!skb)
572e0012 829 return;
572e0012 830
d8cd189e
KV
831 pspoll = (struct ieee80211_pspoll *) skb->data;
832 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
572e0012 833
62ae67be
JB
834 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
835 ieee80211_tx_skb(sdata, skb);
572e0012
KV
836}
837
965bedad
JB
838void ieee80211_send_nullfunc(struct ieee80211_local *local,
839 struct ieee80211_sub_if_data *sdata,
840 int powersave)
841{
842 struct sk_buff *skb;
d8cd189e 843 struct ieee80211_hdr_3addr *nullfunc;
b6f35301 844 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
965bedad 845
d8cd189e
KV
846 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
847 if (!skb)
965bedad 848 return;
965bedad 849
d8cd189e 850 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
965bedad 851 if (powersave)
d8cd189e 852 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
965bedad 853
6c17b77b
SF
854 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
855 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
ff40b425
PF
856
857 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
858 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
859
392b9ffb 860 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
b6f35301
RM
861 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
862
62ae67be 863 ieee80211_tx_skb(sdata, skb);
965bedad
JB
864}
865
d524215f
FF
866static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
867 struct ieee80211_sub_if_data *sdata)
868{
869 struct sk_buff *skb;
870 struct ieee80211_hdr *nullfunc;
871 __le16 fc;
872
873 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
874 return;
875
876 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
d15b8459 877 if (!skb)
d524215f 878 return;
d15b8459 879
d524215f
FF
880 skb_reserve(skb, local->hw.extra_tx_headroom);
881
882 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
883 memset(nullfunc, 0, 30);
884 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
885 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
886 nullfunc->frame_control = fc;
887 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
888 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
889 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
890 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
891
892 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
893 ieee80211_tx_skb(sdata, skb);
894}
895
cc32abd4
JB
896/* spectrum management related things */
897static void ieee80211_chswitch_work(struct work_struct *work)
898{
899 struct ieee80211_sub_if_data *sdata =
900 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
675a0b04 901 struct ieee80211_local *local = sdata->local;
cc32abd4 902 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7578d575
AN
903 u32 changed = 0;
904 int ret;
cc32abd4 905
9607e6b6 906 if (!ieee80211_sdata_running(sdata))
cc32abd4
JB
907 return;
908
8d61ffa5 909 sdata_lock(sdata);
77fdaa12
JB
910 if (!ifmgd->associated)
911 goto out;
cc32abd4 912
34a3740d 913 mutex_lock(&local->mtx);
33787fc4 914 ret = ieee80211_vif_change_channel(sdata, &changed);
34a3740d 915 mutex_unlock(&local->mtx);
7578d575
AN
916 if (ret) {
917 sdata_info(sdata,
918 "vif channel switch failed, disconnecting\n");
919 ieee80211_queue_work(&sdata->local->hw,
920 &ifmgd->csa_connection_drop_work);
921 goto out;
922 }
675a0b04 923
7578d575 924 if (!local->use_chanctx) {
33787fc4 925 local->_oper_chandef = sdata->csa_chandef;
7578d575
AN
926 /* Call "hw_config" only if doing sw channel switch.
927 * Otherwise update the channel directly
928 */
929 if (!local->ops->channel_switch)
930 ieee80211_hw_config(local, 0);
931 else
932 local->hw.conf.chandef = local->_oper_chandef;
5ce6e438 933 }
77fdaa12 934
cc32abd4 935 /* XXX: shouldn't really modify cfg80211-owned data! */
33787fc4 936 ifmgd->associated->channel = sdata->csa_chandef.chan;
cc32abd4 937
57eebdf3 938 /* XXX: wait for a beacon first? */
675a0b04 939 ieee80211_wake_queues_by_reason(&local->hw,
445ea4e8 940 IEEE80211_MAX_QUEUE_MAP,
cc32abd4 941 IEEE80211_QUEUE_STOP_REASON_CSA);
7578d575
AN
942
943 ieee80211_bss_info_change_notify(sdata, changed);
944
77fdaa12 945 out:
7578d575 946 sdata->vif.csa_active = false;
77fdaa12 947 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
8d61ffa5 948 sdata_unlock(sdata);
cc32abd4
JB
949}
950
5ce6e438
JB
951void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
952{
55de908a
JB
953 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
954 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5ce6e438
JB
955
956 trace_api_chswitch_done(sdata, success);
957 if (!success) {
882a7c69
JB
958 sdata_info(sdata,
959 "driver channel switch failed, disconnecting\n");
960 ieee80211_queue_work(&sdata->local->hw,
961 &ifmgd->csa_connection_drop_work);
962 } else {
963 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
5ce6e438 964 }
5ce6e438
JB
965}
966EXPORT_SYMBOL(ieee80211_chswitch_done);
967
cc32abd4
JB
968static void ieee80211_chswitch_timer(unsigned long data)
969{
970 struct ieee80211_sub_if_data *sdata =
971 (struct ieee80211_sub_if_data *) data;
5bb644a0 972
9b7d72c1 973 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
cc32abd4
JB
974}
975
37799e52 976static void
4a3cb702 977ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
04a161f4
JB
978 u64 timestamp, struct ieee802_11_elems *elems,
979 bool beacon)
cc32abd4 980{
b4f286a1 981 struct ieee80211_local *local = sdata->local;
cc32abd4 982 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
37799e52 983 struct cfg80211_bss *cbss = ifmgd->associated;
55de908a 984 struct ieee80211_chanctx *chanctx;
e6b7cde4 985 enum ieee80211_band current_band;
c0f17eb9 986 struct ieee80211_csa_ie csa_ie;
e6b7cde4 987 int res;
cc32abd4 988
8d61ffa5 989 sdata_assert_lock(sdata);
77fdaa12 990
37799e52 991 if (!cbss)
cc32abd4
JB
992 return;
993
b4f286a1 994 if (local->scanning)
cc32abd4
JB
995 return;
996
37799e52 997 /* disregard subsequent announcements if we are already processing */
cc32abd4
JB
998 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
999 return;
1000
e6b7cde4 1001 current_band = cbss->channel->band;
c0f17eb9 1002 memset(&csa_ie, 0, sizeof(csa_ie));
e6b7cde4
SW
1003 res = ieee80211_parse_ch_switch_ie(sdata, elems, beacon, current_band,
1004 ifmgd->flags,
c0f17eb9 1005 ifmgd->associated->bssid, &csa_ie);
e6b7cde4 1006 if (res < 0)
b4f286a1 1007 ieee80211_queue_work(&local->hw,
882a7c69 1008 &ifmgd->csa_connection_drop_work);
e6b7cde4 1009 if (res)
cc32abd4 1010 return;
cd64f2a9 1011
c0f17eb9 1012 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
85220d71
JB
1013 IEEE80211_CHAN_DISABLED)) {
1014 sdata_info(sdata,
1015 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
e6b7cde4 1016 ifmgd->associated->bssid,
c0f17eb9
CYY
1017 csa_ie.chandef.chan->center_freq,
1018 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1019 csa_ie.chandef.center_freq2);
85220d71
JB
1020 ieee80211_queue_work(&local->hw,
1021 &ifmgd->csa_connection_drop_work);
1022 return;
1023 }
1024
57eebdf3 1025 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
7578d575 1026 sdata->vif.csa_active = true;
57eebdf3 1027
7578d575 1028 mutex_lock(&local->chanctx_mtx);
b4f286a1 1029 if (local->use_chanctx) {
7578d575
AN
1030 u32 num_chanctx = 0;
1031 list_for_each_entry(chanctx, &local->chanctx_list, list)
1032 num_chanctx++;
1033
1034 if (num_chanctx > 1 ||
1035 !(local->hw.flags & IEEE80211_HW_CHANCTX_STA_CSA)) {
1036 sdata_info(sdata,
1037 "not handling chan-switch with channel contexts\n");
1038 ieee80211_queue_work(&local->hw,
1039 &ifmgd->csa_connection_drop_work);
1040 mutex_unlock(&local->chanctx_mtx);
1041 return;
1042 }
55de908a
JB
1043 }
1044
55de908a 1045 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
7578d575
AN
1046 ieee80211_queue_work(&local->hw,
1047 &ifmgd->csa_connection_drop_work);
b4f286a1 1048 mutex_unlock(&local->chanctx_mtx);
55de908a
JB
1049 return;
1050 }
1051 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
1052 struct ieee80211_chanctx, conf);
1053 if (chanctx->refcount > 1) {
1054 sdata_info(sdata,
1055 "channel switch with multiple interfaces on the same channel, disconnecting\n");
b4f286a1 1056 ieee80211_queue_work(&local->hw,
55de908a 1057 &ifmgd->csa_connection_drop_work);
b4f286a1 1058 mutex_unlock(&local->chanctx_mtx);
55de908a
JB
1059 return;
1060 }
b4f286a1 1061 mutex_unlock(&local->chanctx_mtx);
55de908a 1062
33787fc4 1063 sdata->csa_chandef = csa_ie.chandef;
55de908a 1064
c0f17eb9 1065 if (csa_ie.mode)
b4f286a1 1066 ieee80211_stop_queues_by_reason(&local->hw,
445ea4e8 1067 IEEE80211_MAX_QUEUE_MAP,
57eebdf3
JB
1068 IEEE80211_QUEUE_STOP_REASON_CSA);
1069
b4f286a1 1070 if (local->ops->channel_switch) {
5ce6e438 1071 /* use driver's channel switch callback */
57eebdf3
JB
1072 struct ieee80211_channel_switch ch_switch = {
1073 .timestamp = timestamp,
c0f17eb9
CYY
1074 .block_tx = csa_ie.mode,
1075 .chandef = csa_ie.chandef,
1076 .count = csa_ie.count,
57eebdf3
JB
1077 };
1078
b4f286a1 1079 drv_channel_switch(local, &ch_switch);
5ce6e438
JB
1080 return;
1081 }
1082
1083 /* channel switch handled in software */
c0f17eb9 1084 if (csa_ie.count <= 1)
b4f286a1 1085 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
57eebdf3 1086 else
cc32abd4 1087 mod_timer(&ifmgd->chswitch_timer,
c0f17eb9 1088 TU_TO_EXP_TIME(csa_ie.count * cbss->beacon_interval));
cc32abd4
JB
1089}
1090
1ea6f9c0
JB
1091static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1092 struct ieee80211_channel *channel,
1093 const u8 *country_ie, u8 country_ie_len,
1094 const u8 *pwr_constr_elem)
cc32abd4 1095{
04b7b2ff
JB
1096 struct ieee80211_country_ie_triplet *triplet;
1097 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1098 int i, chan_pwr, chan_increment, new_ap_level;
1099 bool have_chan_pwr = false;
cc32abd4 1100
04b7b2ff
JB
1101 /* Invalid IE */
1102 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1ea6f9c0 1103 return 0;
cc32abd4 1104
04b7b2ff
JB
1105 triplet = (void *)(country_ie + 3);
1106 country_ie_len -= 3;
1107
1108 switch (channel->band) {
1109 default:
1110 WARN_ON_ONCE(1);
1111 /* fall through */
1112 case IEEE80211_BAND_2GHZ:
1113 case IEEE80211_BAND_60GHZ:
1114 chan_increment = 1;
1115 break;
1116 case IEEE80211_BAND_5GHZ:
1117 chan_increment = 4;
1118 break;
cc32abd4 1119 }
04b7b2ff
JB
1120
1121 /* find channel */
1122 while (country_ie_len >= 3) {
1123 u8 first_channel = triplet->chans.first_channel;
1124
1125 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1126 goto next;
1127
1128 for (i = 0; i < triplet->chans.num_channels; i++) {
1129 if (first_channel + i * chan_increment == chan) {
1130 have_chan_pwr = true;
1131 chan_pwr = triplet->chans.max_power;
1132 break;
1133 }
1134 }
1135 if (have_chan_pwr)
1136 break;
1137
1138 next:
1139 triplet++;
1140 country_ie_len -= 3;
1141 }
1142
1143 if (!have_chan_pwr)
1ea6f9c0 1144 return 0;
04b7b2ff
JB
1145
1146 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
1147
1ea6f9c0
JB
1148 if (sdata->ap_power_level == new_ap_level)
1149 return 0;
04b7b2ff
JB
1150
1151 sdata_info(sdata,
1152 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1153 new_ap_level, chan_pwr, *pwr_constr_elem,
1154 sdata->u.mgd.bssid);
1ea6f9c0
JB
1155 sdata->ap_power_level = new_ap_level;
1156 if (__ieee80211_recalc_txpower(sdata))
1157 return BSS_CHANGED_TXPOWER;
1158 return 0;
cc32abd4
JB
1159}
1160
965bedad
JB
1161/* powersave */
1162static void ieee80211_enable_ps(struct ieee80211_local *local,
1163 struct ieee80211_sub_if_data *sdata)
1164{
1165 struct ieee80211_conf *conf = &local->hw.conf;
1166
d5edaedc
JB
1167 /*
1168 * If we are scanning right now then the parameters will
1169 * take effect when scan finishes.
1170 */
fbe9c429 1171 if (local->scanning)
d5edaedc
JB
1172 return;
1173
965bedad
JB
1174 if (conf->dynamic_ps_timeout > 0 &&
1175 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
1176 mod_timer(&local->dynamic_ps_timer, jiffies +
1177 msecs_to_jiffies(conf->dynamic_ps_timeout));
1178 } else {
1179 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1180 ieee80211_send_nullfunc(local, sdata, 1);
375177bf 1181
2a13052f
JO
1182 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1183 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
1184 return;
1185
1186 conf->flags |= IEEE80211_CONF_PS;
1187 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
965bedad
JB
1188 }
1189}
1190
1191static void ieee80211_change_ps(struct ieee80211_local *local)
1192{
1193 struct ieee80211_conf *conf = &local->hw.conf;
1194
1195 if (local->ps_sdata) {
965bedad
JB
1196 ieee80211_enable_ps(local, local->ps_sdata);
1197 } else if (conf->flags & IEEE80211_CONF_PS) {
1198 conf->flags &= ~IEEE80211_CONF_PS;
1199 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1200 del_timer_sync(&local->dynamic_ps_timer);
1201 cancel_work_sync(&local->dynamic_ps_enable_work);
1202 }
1203}
1204
808118cb
JY
1205static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1206{
1207 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1208 struct sta_info *sta = NULL;
c2c98fde 1209 bool authorized = false;
808118cb
JY
1210
1211 if (!mgd->powersave)
1212 return false;
1213
05cb9108
JB
1214 if (mgd->broken_ap)
1215 return false;
1216
808118cb
JY
1217 if (!mgd->associated)
1218 return false;
1219
392b9ffb 1220 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
808118cb
JY
1221 return false;
1222
989c6505 1223 if (!mgd->have_beacon)
ce857888
AB
1224 return false;
1225
808118cb
JY
1226 rcu_read_lock();
1227 sta = sta_info_get(sdata, mgd->bssid);
1228 if (sta)
c2c98fde 1229 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
808118cb
JY
1230 rcu_read_unlock();
1231
c2c98fde 1232 return authorized;
808118cb
JY
1233}
1234
965bedad 1235/* need to hold RTNL or interface lock */
10f644a4 1236void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
965bedad
JB
1237{
1238 struct ieee80211_sub_if_data *sdata, *found = NULL;
1239 int count = 0;
195e294d 1240 int timeout;
965bedad
JB
1241
1242 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1243 local->ps_sdata = NULL;
1244 return;
1245 }
1246
1247 list_for_each_entry(sdata, &local->interfaces, list) {
9607e6b6 1248 if (!ieee80211_sdata_running(sdata))
965bedad 1249 continue;
8c7914de
RM
1250 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1251 /* If an AP vif is found, then disable PS
1252 * by setting the count to zero thereby setting
1253 * ps_sdata to NULL.
1254 */
1255 count = 0;
1256 break;
1257 }
965bedad
JB
1258 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1259 continue;
1260 found = sdata;
1261 count++;
1262 }
1263
808118cb 1264 if (count == 1 && ieee80211_powersave_allowed(found)) {
10f644a4
JB
1265 s32 beaconint_us;
1266
1267 if (latency < 0)
ed77134b 1268 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
10f644a4
JB
1269
1270 beaconint_us = ieee80211_tu_to_usec(
1271 found->vif.bss_conf.beacon_int);
1272
ff616381 1273 timeout = local->dynamic_ps_forced_timeout;
195e294d
JO
1274 if (timeout < 0) {
1275 /*
ff616381
JO
1276 * Go to full PSM if the user configures a very low
1277 * latency requirement.
0ab82b04
EP
1278 * The 2000 second value is there for compatibility
1279 * until the PM_QOS_NETWORK_LATENCY is configured
1280 * with real values.
195e294d 1281 */
0ab82b04
EP
1282 if (latency > (1900 * USEC_PER_MSEC) &&
1283 latency != (2000 * USEC_PER_SEC))
195e294d 1284 timeout = 0;
ff616381
JO
1285 else
1286 timeout = 100;
195e294d 1287 }
09b85568 1288 local->hw.conf.dynamic_ps_timeout = timeout;
195e294d 1289
04fe2037 1290 if (beaconint_us > latency) {
10f644a4 1291 local->ps_sdata = NULL;
04fe2037 1292 } else {
04fe2037 1293 int maxslp = 1;
826262c3 1294 u8 dtimper = found->u.mgd.dtim_period;
56007a02
JB
1295
1296 /* If the TIM IE is invalid, pretend the value is 1 */
1297 if (!dtimper)
1298 dtimper = 1;
1299 else if (dtimper > 1)
04fe2037
JB
1300 maxslp = min_t(int, dtimper,
1301 latency / beaconint_us);
1302
9ccebe61 1303 local->hw.conf.max_sleep_period = maxslp;
56007a02 1304 local->hw.conf.ps_dtim_period = dtimper;
10f644a4 1305 local->ps_sdata = found;
04fe2037 1306 }
10f644a4 1307 } else {
965bedad 1308 local->ps_sdata = NULL;
10f644a4 1309 }
965bedad
JB
1310
1311 ieee80211_change_ps(local);
1312}
1313
ab095877
EP
1314void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1315{
1316 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1317
1318 if (sdata->vif.bss_conf.ps != ps_allowed) {
1319 sdata->vif.bss_conf.ps = ps_allowed;
1320 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1321 }
1322}
1323
965bedad
JB
1324void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1325{
1326 struct ieee80211_local *local =
1327 container_of(work, struct ieee80211_local,
1328 dynamic_ps_disable_work);
1329
1330 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1331 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1332 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1333 }
1334
1335 ieee80211_wake_queues_by_reason(&local->hw,
445ea4e8 1336 IEEE80211_MAX_QUEUE_MAP,
965bedad
JB
1337 IEEE80211_QUEUE_STOP_REASON_PS);
1338}
1339
1340void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1341{
1342 struct ieee80211_local *local =
1343 container_of(work, struct ieee80211_local,
1344 dynamic_ps_enable_work);
1345 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
5e34069c 1346 struct ieee80211_if_managed *ifmgd;
1ddc2867
RM
1347 unsigned long flags;
1348 int q;
965bedad
JB
1349
1350 /* can only happen when PS was just disabled anyway */
1351 if (!sdata)
1352 return;
1353
5e34069c
CL
1354 ifmgd = &sdata->u.mgd;
1355
965bedad
JB
1356 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1357 return;
1358
09b85568 1359 if (local->hw.conf.dynamic_ps_timeout > 0) {
77b7023a
AN
1360 /* don't enter PS if TX frames are pending */
1361 if (drv_tx_frames_pending(local)) {
1ddc2867
RM
1362 mod_timer(&local->dynamic_ps_timer, jiffies +
1363 msecs_to_jiffies(
1364 local->hw.conf.dynamic_ps_timeout));
1365 return;
1366 }
77b7023a
AN
1367
1368 /*
1369 * transmission can be stopped by others which leads to
1370 * dynamic_ps_timer expiry. Postpone the ps timer if it
1371 * is not the actual idle state.
1372 */
1373 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1374 for (q = 0; q < local->hw.queues; q++) {
1375 if (local->queue_stop_reasons[q]) {
1376 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1377 flags);
1378 mod_timer(&local->dynamic_ps_timer, jiffies +
1379 msecs_to_jiffies(
1380 local->hw.conf.dynamic_ps_timeout));
1381 return;
1382 }
1383 }
1384 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1ddc2867 1385 }
1ddc2867 1386
375177bf 1387 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
9c38a8b4 1388 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
a1598383 1389 if (drv_tx_frames_pending(local)) {
e8306f98
VN
1390 mod_timer(&local->dynamic_ps_timer, jiffies +
1391 msecs_to_jiffies(
1392 local->hw.conf.dynamic_ps_timeout));
a1598383 1393 } else {
e8306f98
VN
1394 ieee80211_send_nullfunc(local, sdata, 1);
1395 /* Flush to get the tx status of nullfunc frame */
39ecc01d 1396 ieee80211_flush_queues(local, sdata);
e8306f98 1397 }
f3e85b9e
VN
1398 }
1399
2a13052f
JO
1400 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1401 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
375177bf
VN
1402 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1403 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1404 local->hw.conf.flags |= IEEE80211_CONF_PS;
1405 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1406 }
965bedad
JB
1407}
1408
1409void ieee80211_dynamic_ps_timer(unsigned long data)
1410{
1411 struct ieee80211_local *local = (void *) data;
1412
78f1a8b7 1413 if (local->quiescing || local->suspended)
5bb644a0
JB
1414 return;
1415
42935eca 1416 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
965bedad
JB
1417}
1418
164eb02d
SW
1419void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1420{
1421 struct delayed_work *delayed_work =
1422 container_of(work, struct delayed_work, work);
1423 struct ieee80211_sub_if_data *sdata =
1424 container_of(delayed_work, struct ieee80211_sub_if_data,
1425 dfs_cac_timer_work);
d2859df5 1426 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
164eb02d 1427
34a3740d
JB
1428 mutex_lock(&sdata->local->mtx);
1429 if (sdata->wdev.cac_started) {
1430 ieee80211_vif_release_channel(sdata);
1431 cfg80211_cac_event(sdata->dev, &chandef,
1432 NL80211_RADAR_CAC_FINISHED,
1433 GFP_KERNEL);
1434 }
1435 mutex_unlock(&sdata->local->mtx);
164eb02d
SW
1436}
1437
60f8b39c 1438/* MLME */
7d25745d 1439static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
4ced3f74 1440 struct ieee80211_sub_if_data *sdata,
4a3cb702 1441 const u8 *wmm_param, size_t wmm_param_len)
f0706e82 1442{
f0706e82 1443 struct ieee80211_tx_queue_params params;
4ced3f74 1444 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f0706e82
JB
1445 size_t left;
1446 int count;
4a3cb702
JB
1447 const u8 *pos;
1448 u8 uapsd_queues = 0;
f0706e82 1449
e1b3ec1a 1450 if (!local->ops->conf_tx)
7d25745d 1451 return false;
e1b3ec1a 1452
32c5057b 1453 if (local->hw.queues < IEEE80211_NUM_ACS)
7d25745d 1454 return false;
3434fbd3
JB
1455
1456 if (!wmm_param)
7d25745d 1457 return false;
3434fbd3 1458
f0706e82 1459 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
7d25745d 1460 return false;
ab13315a
KV
1461
1462 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
dc41e4d4 1463 uapsd_queues = ifmgd->uapsd_queues;
ab13315a 1464
f0706e82 1465 count = wmm_param[6] & 0x0f;
46900298 1466 if (count == ifmgd->wmm_last_param_set)
7d25745d 1467 return false;
46900298 1468 ifmgd->wmm_last_param_set = count;
f0706e82
JB
1469
1470 pos = wmm_param + 8;
1471 left = wmm_param_len - 8;
1472
1473 memset(&params, 0, sizeof(params));
1474
00e96dec 1475 sdata->wmm_acm = 0;
f0706e82
JB
1476 for (; left >= 4; left -= 4, pos += 4) {
1477 int aci = (pos[0] >> 5) & 0x03;
1478 int acm = (pos[0] >> 4) & 0x01;
ab13315a 1479 bool uapsd = false;
f0706e82
JB
1480 int queue;
1481
1482 switch (aci) {
0eeb59fe 1483 case 1: /* AC_BK */
e100bb64 1484 queue = 3;
988c0f72 1485 if (acm)
00e96dec 1486 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
ab13315a
KV
1487 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1488 uapsd = true;
f0706e82 1489 break;
0eeb59fe 1490 case 2: /* AC_VI */
e100bb64 1491 queue = 1;
988c0f72 1492 if (acm)
00e96dec 1493 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
ab13315a
KV
1494 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1495 uapsd = true;
f0706e82 1496 break;
0eeb59fe 1497 case 3: /* AC_VO */
e100bb64 1498 queue = 0;
988c0f72 1499 if (acm)
00e96dec 1500 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
ab13315a
KV
1501 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1502 uapsd = true;
f0706e82 1503 break;
0eeb59fe 1504 case 0: /* AC_BE */
f0706e82 1505 default:
e100bb64 1506 queue = 2;
988c0f72 1507 if (acm)
00e96dec 1508 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
ab13315a
KV
1509 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1510 uapsd = true;
f0706e82
JB
1511 break;
1512 }
1513
1514 params.aifs = pos[0] & 0x0f;
1515 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1516 params.cw_min = ecw2cw(pos[1] & 0x0f);
f434b2d1 1517 params.txop = get_unaligned_le16(pos + 2);
908f8d07 1518 params.acm = acm;
ab13315a
KV
1519 params.uapsd = uapsd;
1520
bdcbd8e0
JB
1521 mlme_dbg(sdata,
1522 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1523 queue, aci, acm,
1524 params.aifs, params.cw_min, params.cw_max,
1525 params.txop, params.uapsd);
f6f3def3
EP
1526 sdata->tx_conf[queue] = params;
1527 if (drv_conf_tx(local, sdata, queue, &params))
bdcbd8e0
JB
1528 sdata_err(sdata,
1529 "failed to set TX queue parameters for queue %d\n",
1530 queue);
f0706e82 1531 }
e1b3ec1a
SG
1532
1533 /* enable WMM or activate new settings */
4ced3f74 1534 sdata->vif.bss_conf.qos = true;
7d25745d 1535 return true;
f0706e82
JB
1536}
1537
925e64c3
SG
1538static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1539{
1540 lockdep_assert_held(&sdata->local->mtx);
1541
392b9ffb 1542 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
925e64c3
SG
1543 ieee80211_run_deferred_scan(sdata->local);
1544}
1545
1546static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1547{
1548 mutex_lock(&sdata->local->mtx);
1549 __ieee80211_stop_poll(sdata);
1550 mutex_unlock(&sdata->local->mtx);
1551}
1552
7a5158ef
JB
1553static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1554 u16 capab, bool erp_valid, u8 erp)
5628221c 1555{
bda3933a 1556 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
471b3efd 1557 u32 changed = 0;
7a5158ef
JB
1558 bool use_protection;
1559 bool use_short_preamble;
1560 bool use_short_slot;
1561
1562 if (erp_valid) {
1563 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1564 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1565 } else {
1566 use_protection = false;
1567 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1568 }
1569
1570 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
55de908a 1571 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
43d35343 1572 use_short_slot = true;
5628221c 1573
471b3efd 1574 if (use_protection != bss_conf->use_cts_prot) {
471b3efd
JB
1575 bss_conf->use_cts_prot = use_protection;
1576 changed |= BSS_CHANGED_ERP_CTS_PROT;
5628221c 1577 }
7e9ed188 1578
d43c7b37 1579 if (use_short_preamble != bss_conf->use_short_preamble) {
d43c7b37 1580 bss_conf->use_short_preamble = use_short_preamble;
471b3efd 1581 changed |= BSS_CHANGED_ERP_PREAMBLE;
7e9ed188 1582 }
d9430a32 1583
7a5158ef 1584 if (use_short_slot != bss_conf->use_short_slot) {
7a5158ef
JB
1585 bss_conf->use_short_slot = use_short_slot;
1586 changed |= BSS_CHANGED_ERP_SLOT;
50c4afb9
JL
1587 }
1588
1589 return changed;
1590}
1591
f698d856 1592static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
0c1ad2ca 1593 struct cfg80211_bss *cbss,
ae5eb026 1594 u32 bss_info_changed)
f0706e82 1595{
0c1ad2ca 1596 struct ieee80211_bss *bss = (void *)cbss->priv;
471b3efd 1597 struct ieee80211_local *local = sdata->local;
68542962 1598 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
d6f2da5b 1599
ae5eb026 1600 bss_info_changed |= BSS_CHANGED_ASSOC;
77fdaa12 1601 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
50ae34a2 1602 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
21c0cbe7 1603
7ccc8bd7 1604 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
59c1ec2b 1605 beacon_loss_count * bss_conf->beacon_int));
7ccc8bd7 1606
0c1ad2ca
JB
1607 sdata->u.mgd.associated = cbss;
1608 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
f0706e82 1609
17e4ec14
JM
1610 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1611
488dd7b5 1612 if (sdata->vif.p2p) {
9caf0364 1613 const struct cfg80211_bss_ies *ies;
488dd7b5 1614
9caf0364
JB
1615 rcu_read_lock();
1616 ies = rcu_dereference(cbss->ies);
1617 if (ies) {
9caf0364
JB
1618 int ret;
1619
1620 ret = cfg80211_get_p2p_attr(
1621 ies->data, ies->len,
1622 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
67baf663
JD
1623 (u8 *) &bss_conf->p2p_noa_attr,
1624 sizeof(bss_conf->p2p_noa_attr));
9caf0364 1625 if (ret >= 2) {
67baf663
JD
1626 sdata->u.mgd.p2p_noa_index =
1627 bss_conf->p2p_noa_attr.index;
9caf0364 1628 bss_info_changed |= BSS_CHANGED_P2P_PS;
9caf0364 1629 }
488dd7b5 1630 }
9caf0364 1631 rcu_read_unlock();
488dd7b5
JB
1632 }
1633
b291ba11 1634 /* just to be sure */
925e64c3 1635 ieee80211_stop_poll(sdata);
b291ba11 1636
9ac19a90 1637 ieee80211_led_assoc(local, 1);
9306102e 1638
989c6505 1639 if (sdata->u.mgd.have_beacon) {
826262c3
JB
1640 /*
1641 * If the AP is buggy we may get here with no DTIM period
1642 * known, so assume it's 1 which is the only safe assumption
1643 * in that case, although if the TIM IE is broken powersave
1644 * probably just won't work at all.
1645 */
1646 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
817cee76 1647 bss_conf->beacon_rate = bss->beacon_rate;
989c6505 1648 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
826262c3 1649 } else {
817cee76 1650 bss_conf->beacon_rate = NULL;
e5b900d2 1651 bss_conf->dtim_period = 0;
826262c3 1652 }
e5b900d2 1653
68542962 1654 bss_conf->assoc = 1;
9cef8737 1655
a97c13c3 1656 /* Tell the driver to monitor connection quality (if supported) */
ea086359 1657 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
68542962 1658 bss_conf->cqm_rssi_thold)
a97c13c3
JO
1659 bss_info_changed |= BSS_CHANGED_CQM;
1660
68542962 1661 /* Enable ARP filtering */
0f19b41e 1662 if (bss_conf->arp_addr_cnt)
68542962 1663 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
68542962 1664
ae5eb026 1665 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
f0706e82 1666
056508dc
JB
1667 mutex_lock(&local->iflist_mtx);
1668 ieee80211_recalc_ps(local, -1);
1669 mutex_unlock(&local->iflist_mtx);
e0cb686f 1670
04ecd257 1671 ieee80211_recalc_smps(sdata);
ab095877
EP
1672 ieee80211_recalc_ps_vif(sdata);
1673
9ac19a90 1674 netif_carrier_on(sdata->dev);
f0706e82
JB
1675}
1676
e69e95db 1677static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
37ad3888
JB
1678 u16 stype, u16 reason, bool tx,
1679 u8 *frame_buf)
aa458d17 1680{
46900298 1681 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
aa458d17 1682 struct ieee80211_local *local = sdata->local;
3cc5240b 1683 u32 changed = 0;
aa458d17 1684
8d61ffa5 1685 sdata_assert_lock(sdata);
77fdaa12 1686
37ad3888
JB
1687 if (WARN_ON_ONCE(tx && !frame_buf))
1688 return;
1689
b291ba11
JB
1690 if (WARN_ON(!ifmgd->associated))
1691 return;
1692
79543d8e
DS
1693 ieee80211_stop_poll(sdata);
1694
77fdaa12 1695 ifmgd->associated = NULL;
aa458d17
TW
1696 netif_carrier_off(sdata->dev);
1697
88bc40e8
EP
1698 /*
1699 * if we want to get out of ps before disassoc (why?) we have
1700 * to do it before sending disassoc, as otherwise the null-packet
1701 * won't be valid.
1702 */
1703 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1704 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1705 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1706 }
1707 local->ps_sdata = NULL;
1708
ab095877
EP
1709 /* disable per-vif ps */
1710 ieee80211_recalc_ps_vif(sdata);
1711
f823981e
EP
1712 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1713 if (tx)
39ecc01d 1714 ieee80211_flush_queues(local, sdata);
f823981e 1715
37ad3888
JB
1716 /* deauthenticate/disassociate now */
1717 if (tx || frame_buf)
88a9e31c
EP
1718 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1719 reason, tx, frame_buf);
37ad3888
JB
1720
1721 /* flush out frame */
1722 if (tx)
39ecc01d 1723 ieee80211_flush_queues(local, sdata);
37ad3888 1724
88a9e31c
EP
1725 /* clear bssid only after building the needed mgmt frames */
1726 memset(ifmgd->bssid, 0, ETH_ALEN);
1727
37ad3888 1728 /* remove AP and TDLS peers */
d34ba216 1729 sta_info_flush(sdata);
37ad3888
JB
1730
1731 /* finally reset all BSS / config parameters */
f5e5bf25
TW
1732 changed |= ieee80211_reset_erp_info(sdata);
1733
f5e5bf25 1734 ieee80211_led_assoc(local, 0);
ae5eb026
JB
1735 changed |= BSS_CHANGED_ASSOC;
1736 sdata->vif.bss_conf.assoc = false;
f5e5bf25 1737
67baf663
JD
1738 ifmgd->p2p_noa_index = -1;
1739 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1740 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
488dd7b5 1741
dd5ecfea 1742 /* on the next assoc, re-program HT/VHT parameters */
ef96a842
BG
1743 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1744 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
dd5ecfea
JB
1745 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
1746 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
413ad50a 1747
1ea6f9c0 1748 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
a8302de9 1749
520eb820
KV
1750 del_timer_sync(&local->dynamic_ps_timer);
1751 cancel_work_sync(&local->dynamic_ps_enable_work);
1752
68542962 1753 /* Disable ARP filtering */
0f19b41e 1754 if (sdata->vif.bss_conf.arp_addr_cnt)
68542962 1755 changed |= BSS_CHANGED_ARP_FILTER;
68542962 1756
3abead59
JB
1757 sdata->vif.bss_conf.qos = false;
1758 changed |= BSS_CHANGED_QOS;
1759
0aaffa9b
JB
1760 /* The BSSID (not really interesting) and HT changed */
1761 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
ae5eb026 1762 ieee80211_bss_info_change_notify(sdata, changed);
8e268e47 1763
3abead59
JB
1764 /* disassociated - set to defaults now */
1765 ieee80211_set_wmm_default(sdata, false);
1766
b9dcf712
JB
1767 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1768 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1769 del_timer_sync(&sdata->u.mgd.timer);
1770 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2d9957cc 1771
826262c3 1772 sdata->vif.bss_conf.dtim_period = 0;
817cee76
AB
1773 sdata->vif.bss_conf.beacon_rate = NULL;
1774
989c6505 1775 ifmgd->have_beacon = false;
826262c3 1776
028e8da0 1777 ifmgd->flags = 0;
34a3740d 1778 mutex_lock(&local->mtx);
028e8da0 1779 ieee80211_vif_release_channel(sdata);
34a3740d 1780 mutex_unlock(&local->mtx);
2475b1cc
MS
1781
1782 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
aa458d17 1783}
f0706e82 1784
3cf335d5
KV
1785void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1786 struct ieee80211_hdr *hdr)
1787{
1788 /*
1789 * We can postpone the mgd.timer whenever receiving unicast frames
1790 * from AP because we know that the connection is working both ways
1791 * at that time. But multicast frames (and hence also beacons) must
1792 * be ignored here, because we need to trigger the timer during
b291ba11
JB
1793 * data idle periods for sending the periodic probe request to the
1794 * AP we're connected to.
3cf335d5 1795 */
b291ba11
JB
1796 if (is_multicast_ether_addr(hdr->addr1))
1797 return;
1798
be099e82 1799 ieee80211_sta_reset_conn_monitor(sdata);
3cf335d5 1800}
f0706e82 1801
4e5ff376
FF
1802static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1803{
1804 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
133d40f9 1805 struct ieee80211_local *local = sdata->local;
4e5ff376 1806
133d40f9 1807 mutex_lock(&local->mtx);
392b9ffb
SG
1808 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
1809 goto out;
4e5ff376 1810
925e64c3 1811 __ieee80211_stop_poll(sdata);
133d40f9
SG
1812
1813 mutex_lock(&local->iflist_mtx);
1814 ieee80211_recalc_ps(local, -1);
1815 mutex_unlock(&local->iflist_mtx);
4e5ff376
FF
1816
1817 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
133d40f9 1818 goto out;
4e5ff376
FF
1819
1820 /*
1821 * We've received a probe response, but are not sure whether
1822 * we have or will be receiving any beacons or data, so let's
1823 * schedule the timers again, just in case.
1824 */
1825 ieee80211_sta_reset_beacon_monitor(sdata);
1826
1827 mod_timer(&ifmgd->conn_mon_timer,
1828 round_jiffies_up(jiffies +
1829 IEEE80211_CONNECTION_IDLE_TIME));
133d40f9 1830out:
133d40f9 1831 mutex_unlock(&local->mtx);
4e5ff376
FF
1832}
1833
1834void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
04ac3c0e 1835 struct ieee80211_hdr *hdr, bool ack)
4e5ff376 1836{
75706d0e 1837 if (!ieee80211_is_data(hdr->frame_control))
4e5ff376
FF
1838 return;
1839
4e5ff376
FF
1840 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1841 sdata->u.mgd.probe_send_count > 0) {
04ac3c0e 1842 if (ack)
cab1c7fd 1843 ieee80211_sta_reset_conn_monitor(sdata);
04ac3c0e
FF
1844 else
1845 sdata->u.mgd.nullfunc_failed = true;
4e5ff376 1846 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
cab1c7fd 1847 return;
4e5ff376 1848 }
cab1c7fd
WD
1849
1850 if (ack)
1851 ieee80211_sta_reset_conn_monitor(sdata);
4e5ff376
FF
1852}
1853
a43abf29
ML
1854static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1855{
1856 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1857 const u8 *ssid;
f01a067d 1858 u8 *dst = ifmgd->associated->bssid;
180205bd 1859 u8 unicast_limit = max(1, max_probe_tries - 3);
f01a067d
LR
1860
1861 /*
1862 * Try sending broadcast probe requests for the last three
1863 * probe requests after the first ones failed since some
1864 * buggy APs only support broadcast probe requests.
1865 */
1866 if (ifmgd->probe_send_count >= unicast_limit)
1867 dst = NULL;
a43abf29 1868
4e5ff376
FF
1869 /*
1870 * When the hardware reports an accurate Tx ACK status, it's
1871 * better to send a nullfunc frame instead of a probe request,
1872 * as it will kick us off the AP quickly if we aren't associated
1873 * anymore. The timeout will be reset if the frame is ACKed by
1874 * the AP.
1875 */
992e68bf
SD
1876 ifmgd->probe_send_count++;
1877
04ac3c0e
FF
1878 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1879 ifmgd->nullfunc_failed = false;
4e5ff376 1880 ieee80211_send_nullfunc(sdata->local, sdata, 0);
04ac3c0e 1881 } else {
88c868c4
SG
1882 int ssid_len;
1883
9caf0364 1884 rcu_read_lock();
4e5ff376 1885 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
88c868c4
SG
1886 if (WARN_ON_ONCE(ssid == NULL))
1887 ssid_len = 0;
1888 else
1889 ssid_len = ssid[1];
1890
1891 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
1672c0e3 1892 0, (u32) -1, true, 0,
55de908a 1893 ifmgd->associated->channel, false);
9caf0364 1894 rcu_read_unlock();
4e5ff376 1895 }
a43abf29 1896
180205bd 1897 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
8d61ffa5 1898 run_again(sdata, ifmgd->probe_timeout);
f69b9c79 1899 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
39ecc01d 1900 ieee80211_flush_queues(sdata->local, sdata);
a43abf29
ML
1901}
1902
b291ba11
JB
1903static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1904 bool beacon)
04de8381 1905{
04de8381 1906 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
b291ba11 1907 bool already = false;
34bfc411 1908
9607e6b6 1909 if (!ieee80211_sdata_running(sdata))
0e2b6286
JB
1910 return;
1911
8d61ffa5 1912 sdata_lock(sdata);
77fdaa12
JB
1913
1914 if (!ifmgd->associated)
1915 goto out;
1916
133d40f9
SG
1917 mutex_lock(&sdata->local->mtx);
1918
1919 if (sdata->local->tmp_channel || sdata->local->scanning) {
1920 mutex_unlock(&sdata->local->mtx);
1921 goto out;
1922 }
1923
a13fbe54 1924 if (beacon) {
bdcbd8e0 1925 mlme_dbg_ratelimited(sdata,
59c1ec2b
BG
1926 "detected beacon loss from AP (missed %d beacons) - probing\n",
1927 beacon_loss_count);
bdcbd8e0 1928
a13fbe54
BG
1929 ieee80211_cqm_rssi_notify(&sdata->vif,
1930 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
1931 GFP_KERNEL);
1932 }
04de8381 1933
b291ba11
JB
1934 /*
1935 * The driver/our work has already reported this event or the
1936 * connection monitoring has kicked in and we have already sent
1937 * a probe request. Or maybe the AP died and the driver keeps
1938 * reporting until we disassociate...
1939 *
1940 * In either case we have to ignore the current call to this
1941 * function (except for setting the correct probe reason bit)
1942 * because otherwise we would reset the timer every time and
1943 * never check whether we received a probe response!
1944 */
392b9ffb 1945 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
b291ba11
JB
1946 already = true;
1947
12b5f34d
EP
1948 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1949
133d40f9
SG
1950 mutex_unlock(&sdata->local->mtx);
1951
b291ba11
JB
1952 if (already)
1953 goto out;
1954
4e751843
JB
1955 mutex_lock(&sdata->local->iflist_mtx);
1956 ieee80211_recalc_ps(sdata->local, -1);
1957 mutex_unlock(&sdata->local->iflist_mtx);
1958
a43abf29
ML
1959 ifmgd->probe_send_count = 0;
1960 ieee80211_mgd_probe_ap_send(sdata);
77fdaa12 1961 out:
8d61ffa5 1962 sdata_unlock(sdata);
04de8381
KV
1963}
1964
a619a4c0
JO
1965struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1966 struct ieee80211_vif *vif)
1967{
1968 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1969 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
d9b3b28b 1970 struct cfg80211_bss *cbss;
a619a4c0
JO
1971 struct sk_buff *skb;
1972 const u8 *ssid;
88c868c4 1973 int ssid_len;
a619a4c0
JO
1974
1975 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1976 return NULL;
1977
8d61ffa5 1978 sdata_assert_lock(sdata);
a619a4c0 1979
d9b3b28b
EP
1980 if (ifmgd->associated)
1981 cbss = ifmgd->associated;
1982 else if (ifmgd->auth_data)
1983 cbss = ifmgd->auth_data->bss;
1984 else if (ifmgd->assoc_data)
1985 cbss = ifmgd->assoc_data->bss;
1986 else
a619a4c0
JO
1987 return NULL;
1988
9caf0364 1989 rcu_read_lock();
d9b3b28b 1990 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
88c868c4
SG
1991 if (WARN_ON_ONCE(ssid == NULL))
1992 ssid_len = 0;
1993 else
1994 ssid_len = ssid[1];
1995
d9b3b28b 1996 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
55de908a 1997 (u32) -1, cbss->channel,
6b77863b 1998 ssid + 2, ssid_len,
85a237fe 1999 NULL, 0, true);
9caf0364 2000 rcu_read_unlock();
a619a4c0
JO
2001
2002 return skb;
2003}
2004EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2005
eef9e54c 2006static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
1e4dcd01
JO
2007{
2008 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6ae16775 2009 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
1e4dcd01 2010
8d61ffa5 2011 sdata_lock(sdata);
1e4dcd01 2012 if (!ifmgd->associated) {
8d61ffa5 2013 sdata_unlock(sdata);
1e4dcd01
JO
2014 return;
2015 }
2016
37ad3888
JB
2017 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2018 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
eef9e54c 2019 true, frame_buf);
882a7c69 2020 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
7578d575 2021 sdata->vif.csa_active = false;
5b36ebd8 2022 ieee80211_wake_queues_by_reason(&sdata->local->hw,
445ea4e8 2023 IEEE80211_MAX_QUEUE_MAP,
5b36ebd8 2024 IEEE80211_QUEUE_STOP_REASON_CSA);
7da7cc1d 2025
6ff57cf8
JB
2026 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
2027 IEEE80211_DEAUTH_FRAME_LEN);
8d61ffa5 2028 sdata_unlock(sdata);
1e4dcd01
JO
2029}
2030
cc74c0c7 2031static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
b291ba11
JB
2032{
2033 struct ieee80211_sub_if_data *sdata =
2034 container_of(work, struct ieee80211_sub_if_data,
1e4dcd01 2035 u.mgd.beacon_connection_loss_work);
a85e1d55
PS
2036 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2037 struct sta_info *sta;
2038
2039 if (ifmgd->associated) {
30fa9047 2040 rcu_read_lock();
a85e1d55
PS
2041 sta = sta_info_get(sdata, ifmgd->bssid);
2042 if (sta)
2043 sta->beacon_loss_count++;
30fa9047 2044 rcu_read_unlock();
a85e1d55 2045 }
b291ba11 2046
682bd38b 2047 if (ifmgd->connection_loss) {
882a7c69
JB
2048 sdata_info(sdata, "Connection to AP %pM lost\n",
2049 ifmgd->bssid);
eef9e54c 2050 __ieee80211_disconnect(sdata);
882a7c69 2051 } else {
1e4dcd01 2052 ieee80211_mgd_probe_ap(sdata, true);
882a7c69
JB
2053 }
2054}
2055
2056static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2057{
2058 struct ieee80211_sub_if_data *sdata =
2059 container_of(work, struct ieee80211_sub_if_data,
2060 u.mgd.csa_connection_drop_work);
2061
eef9e54c 2062 __ieee80211_disconnect(sdata);
b291ba11
JB
2063}
2064
04de8381
KV
2065void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2066{
2067 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1e4dcd01 2068 struct ieee80211_hw *hw = &sdata->local->hw;
04de8381 2069
b5878a2d
JB
2070 trace_api_beacon_loss(sdata);
2071
682bd38b 2072 sdata->u.mgd.connection_loss = false;
1e4dcd01 2073 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
04de8381
KV
2074}
2075EXPORT_SYMBOL(ieee80211_beacon_loss);
2076
1e4dcd01
JO
2077void ieee80211_connection_loss(struct ieee80211_vif *vif)
2078{
2079 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2080 struct ieee80211_hw *hw = &sdata->local->hw;
2081
b5878a2d
JB
2082 trace_api_connection_loss(sdata);
2083
682bd38b 2084 sdata->u.mgd.connection_loss = true;
1e4dcd01
JO
2085 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2086}
2087EXPORT_SYMBOL(ieee80211_connection_loss);
2088
2089
66e67e41
JB
2090static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2091 bool assoc)
2092{
2093 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2094
8d61ffa5 2095 sdata_assert_lock(sdata);
66e67e41 2096
66e67e41
JB
2097 if (!assoc) {
2098 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2099
2100 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2101 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
028e8da0 2102 sdata->u.mgd.flags = 0;
34a3740d 2103 mutex_lock(&sdata->local->mtx);
55de908a 2104 ieee80211_vif_release_channel(sdata);
34a3740d 2105 mutex_unlock(&sdata->local->mtx);
66e67e41
JB
2106 }
2107
5b112d3d 2108 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
66e67e41
JB
2109 kfree(auth_data);
2110 sdata->u.mgd.auth_data = NULL;
2111}
2112
2113static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2114 struct ieee80211_mgmt *mgmt, size_t len)
2115{
1672c0e3 2116 struct ieee80211_local *local = sdata->local;
66e67e41
JB
2117 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2118 u8 *pos;
2119 struct ieee802_11_elems elems;
1672c0e3 2120 u32 tx_flags = 0;
66e67e41
JB
2121
2122 pos = mgmt->u.auth.variable;
b2e506bf 2123 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
66e67e41
JB
2124 if (!elems.challenge)
2125 return;
2126 auth_data->expected_transaction = 4;
a1845fc7 2127 drv_mgd_prepare_tx(sdata->local, sdata);
1672c0e3
JB
2128 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
2129 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2130 IEEE80211_TX_INTFL_MLME_CONN_TX;
700e8ea6 2131 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
66e67e41
JB
2132 elems.challenge - 2, elems.challenge_len + 2,
2133 auth_data->bss->bssid, auth_data->bss->bssid,
2134 auth_data->key, auth_data->key_len,
1672c0e3 2135 auth_data->key_idx, tx_flags);
66e67e41
JB
2136}
2137
8d61ffa5
JB
2138static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2139 struct ieee80211_mgmt *mgmt, size_t len)
66e67e41
JB
2140{
2141 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2142 u8 bssid[ETH_ALEN];
2143 u16 auth_alg, auth_transaction, status_code;
2144 struct sta_info *sta;
2145
8d61ffa5 2146 sdata_assert_lock(sdata);
66e67e41
JB
2147
2148 if (len < 24 + 6)
8d61ffa5 2149 return;
66e67e41
JB
2150
2151 if (!ifmgd->auth_data || ifmgd->auth_data->done)
8d61ffa5 2152 return;
66e67e41
JB
2153
2154 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2155
b203ca39 2156 if (!ether_addr_equal(bssid, mgmt->bssid))
8d61ffa5 2157 return;
66e67e41
JB
2158
2159 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2160 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2161 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2162
2163 if (auth_alg != ifmgd->auth_data->algorithm ||
0f4126e8
JM
2164 auth_transaction != ifmgd->auth_data->expected_transaction) {
2165 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2166 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2167 auth_transaction,
2168 ifmgd->auth_data->expected_transaction);
8d61ffa5 2169 return;
0f4126e8 2170 }
66e67e41
JB
2171
2172 if (status_code != WLAN_STATUS_SUCCESS) {
bdcbd8e0
JB
2173 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2174 mgmt->sa, status_code);
dac211ec 2175 ieee80211_destroy_auth_data(sdata, false);
6ff57cf8 2176 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
8d61ffa5 2177 return;
66e67e41
JB
2178 }
2179
2180 switch (ifmgd->auth_data->algorithm) {
2181 case WLAN_AUTH_OPEN:
2182 case WLAN_AUTH_LEAP:
2183 case WLAN_AUTH_FT:
6b8ece3a 2184 case WLAN_AUTH_SAE:
66e67e41
JB
2185 break;
2186 case WLAN_AUTH_SHARED_KEY:
2187 if (ifmgd->auth_data->expected_transaction != 4) {
2188 ieee80211_auth_challenge(sdata, mgmt, len);
2189 /* need another frame */
8d61ffa5 2190 return;
66e67e41
JB
2191 }
2192 break;
2193 default:
2194 WARN_ONCE(1, "invalid auth alg %d",
2195 ifmgd->auth_data->algorithm);
8d61ffa5 2196 return;
66e67e41
JB
2197 }
2198
bdcbd8e0 2199 sdata_info(sdata, "authenticated\n");
66e67e41
JB
2200 ifmgd->auth_data->done = true;
2201 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
89afe614 2202 ifmgd->auth_data->timeout_started = true;
8d61ffa5 2203 run_again(sdata, ifmgd->auth_data->timeout);
66e67e41 2204
6b8ece3a
JM
2205 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2206 ifmgd->auth_data->expected_transaction != 2) {
2207 /*
2208 * Report auth frame to user space for processing since another
2209 * round of Authentication frames is still needed.
2210 */
6ff57cf8 2211 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
8d61ffa5 2212 return;
6b8ece3a
JM
2213 }
2214
66e67e41
JB
2215 /* move station state to auth */
2216 mutex_lock(&sdata->local->sta_mtx);
2217 sta = sta_info_get(sdata, bssid);
2218 if (!sta) {
2219 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2220 goto out_err;
2221 }
2222 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
bdcbd8e0 2223 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
66e67e41
JB
2224 goto out_err;
2225 }
2226 mutex_unlock(&sdata->local->sta_mtx);
2227
6ff57cf8 2228 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
8d61ffa5 2229 return;
66e67e41
JB
2230 out_err:
2231 mutex_unlock(&sdata->local->sta_mtx);
2232 /* ignore frame -- wait for timeout */
66e67e41
JB
2233}
2234
2235
8d61ffa5
JB
2236static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2237 struct ieee80211_mgmt *mgmt, size_t len)
f0706e82 2238{
46900298 2239 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
77fdaa12 2240 const u8 *bssid = NULL;
f0706e82
JB
2241 u16 reason_code;
2242
8d61ffa5 2243 sdata_assert_lock(sdata);
66e67e41 2244
f4ea83dd 2245 if (len < 24 + 2)
8d61ffa5 2246 return;
f0706e82 2247
66e67e41 2248 if (!ifmgd->associated ||
b203ca39 2249 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
8d61ffa5 2250 return;
77fdaa12 2251
0c1ad2ca 2252 bssid = ifmgd->associated->bssid;
f0706e82
JB
2253
2254 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2255
bdcbd8e0
JB
2256 sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
2257 bssid, reason_code);
77fdaa12 2258
37ad3888
JB
2259 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2260
6ff57cf8 2261 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
f0706e82
JB
2262}
2263
2264
8d61ffa5
JB
2265static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2266 struct ieee80211_mgmt *mgmt, size_t len)
f0706e82 2267{
46900298 2268 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f0706e82
JB
2269 u16 reason_code;
2270
8d61ffa5 2271 sdata_assert_lock(sdata);
77fdaa12 2272
66e67e41 2273 if (len < 24 + 2)
8d61ffa5 2274 return;
77fdaa12 2275
66e67e41 2276 if (!ifmgd->associated ||
b203ca39 2277 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
8d61ffa5 2278 return;
f0706e82
JB
2279
2280 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2281
bdcbd8e0
JB
2282 sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
2283 mgmt->sa, reason_code);
f0706e82 2284
37ad3888
JB
2285 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2286
6ff57cf8 2287 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
f0706e82
JB
2288}
2289
c74d084f
CL
2290static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2291 u8 *supp_rates, unsigned int supp_rates_len,
2292 u32 *rates, u32 *basic_rates,
2293 bool *have_higher_than_11mbit,
2103dec1
SW
2294 int *min_rate, int *min_rate_index,
2295 int shift, u32 rate_flags)
c74d084f
CL
2296{
2297 int i, j;
2298
2299 for (i = 0; i < supp_rates_len; i++) {
2103dec1 2300 int rate = supp_rates[i] & 0x7f;
c74d084f
CL
2301 bool is_basic = !!(supp_rates[i] & 0x80);
2302
2103dec1 2303 if ((rate * 5 * (1 << shift)) > 110)
c74d084f
CL
2304 *have_higher_than_11mbit = true;
2305
2306 /*
2307 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2308 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2309 *
2310 * Note: Even through the membership selector and the basic
2311 * rate flag share the same bit, they are not exactly
2312 * the same.
2313 */
2314 if (!!(supp_rates[i] & 0x80) &&
2315 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
2316 continue;
2317
2318 for (j = 0; j < sband->n_bitrates; j++) {
2103dec1
SW
2319 struct ieee80211_rate *br;
2320 int brate;
2321
2322 br = &sband->bitrates[j];
2323 if ((rate_flags & br->flags) != rate_flags)
2324 continue;
2325
2326 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
2327 if (brate == rate) {
c74d084f
CL
2328 *rates |= BIT(j);
2329 if (is_basic)
2330 *basic_rates |= BIT(j);
2103dec1
SW
2331 if ((rate * 5) < *min_rate) {
2332 *min_rate = rate * 5;
c74d084f
CL
2333 *min_rate_index = j;
2334 }
2335 break;
2336 }
2337 }
2338 }
2339}
f0706e82 2340
66e67e41
JB
2341static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2342 bool assoc)
2343{
2344 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2345
8d61ffa5 2346 sdata_assert_lock(sdata);
66e67e41 2347
66e67e41
JB
2348 if (!assoc) {
2349 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2350
2351 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2352 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
028e8da0 2353 sdata->u.mgd.flags = 0;
34a3740d 2354 mutex_lock(&sdata->local->mtx);
55de908a 2355 ieee80211_vif_release_channel(sdata);
34a3740d 2356 mutex_unlock(&sdata->local->mtx);
66e67e41
JB
2357 }
2358
2359 kfree(assoc_data);
2360 sdata->u.mgd.assoc_data = NULL;
2361}
2362
2363static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2364 struct cfg80211_bss *cbss,
af6b6374 2365 struct ieee80211_mgmt *mgmt, size_t len)
f0706e82 2366{
46900298 2367 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
471b3efd 2368 struct ieee80211_local *local = sdata->local;
8318d78a 2369 struct ieee80211_supported_band *sband;
f0706e82 2370 struct sta_info *sta;
af6b6374 2371 u8 *pos;
af6b6374 2372 u16 capab_info, aid;
f0706e82 2373 struct ieee802_11_elems elems;
bda3933a 2374 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
35d865af
JB
2375 const struct cfg80211_bss_ies *bss_ies = NULL;
2376 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
ae5eb026 2377 u32 changed = 0;
c74d084f 2378 int err;
35d865af 2379 bool ret;
f0706e82 2380
af6b6374 2381 /* AssocResp and ReassocResp have identical structure */
f0706e82 2382
f0706e82 2383 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
af6b6374 2384 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
f0706e82 2385
1dd84aa2 2386 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
bdcbd8e0
JB
2387 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2388 aid);
1dd84aa2
JB
2389 aid &= ~(BIT(15) | BIT(14));
2390
05cb9108
JB
2391 ifmgd->broken_ap = false;
2392
2393 if (aid == 0 || aid > IEEE80211_MAX_AID) {
bdcbd8e0
JB
2394 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2395 aid);
05cb9108
JB
2396 aid = 0;
2397 ifmgd->broken_ap = true;
2398 }
2399
af6b6374 2400 pos = mgmt->u.assoc_resp.variable;
b2e506bf 2401 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
af6b6374 2402
f0706e82 2403 if (!elems.supp_rates) {
bdcbd8e0 2404 sdata_info(sdata, "no SuppRates element in AssocResp\n");
af6b6374 2405 return false;
f0706e82
JB
2406 }
2407
46900298 2408 ifmgd->aid = aid;
f0706e82 2409
35d865af
JB
2410 /*
2411 * Some APs are erroneously not including some information in their
2412 * (re)association response frames. Try to recover by using the data
2413 * from the beacon or probe response. This seems to afflict mobile
2414 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
2415 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
2416 */
2417 if ((assoc_data->wmm && !elems.wmm_param) ||
2418 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2419 (!elems.ht_cap_elem || !elems.ht_operation)) ||
2420 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2421 (!elems.vht_cap_elem || !elems.vht_operation))) {
2422 const struct cfg80211_bss_ies *ies;
2423 struct ieee802_11_elems bss_elems;
2424
2425 rcu_read_lock();
2426 ies = rcu_dereference(cbss->ies);
2427 if (ies)
2428 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
2429 GFP_ATOMIC);
2430 rcu_read_unlock();
2431 if (!bss_ies)
2432 return false;
2433
2434 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
2435 false, &bss_elems);
2436 if (assoc_data->wmm &&
2437 !elems.wmm_param && bss_elems.wmm_param) {
2438 elems.wmm_param = bss_elems.wmm_param;
2439 sdata_info(sdata,
2440 "AP bug: WMM param missing from AssocResp\n");
2441 }
2442
2443 /*
2444 * Also check if we requested HT/VHT, otherwise the AP doesn't
2445 * have to include the IEs in the (re)association response.
2446 */
2447 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
2448 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
2449 elems.ht_cap_elem = bss_elems.ht_cap_elem;
2450 sdata_info(sdata,
2451 "AP bug: HT capability missing from AssocResp\n");
2452 }
2453 if (!elems.ht_operation && bss_elems.ht_operation &&
2454 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
2455 elems.ht_operation = bss_elems.ht_operation;
2456 sdata_info(sdata,
2457 "AP bug: HT operation missing from AssocResp\n");
2458 }
2459 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
2460 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
2461 elems.vht_cap_elem = bss_elems.vht_cap_elem;
2462 sdata_info(sdata,
2463 "AP bug: VHT capa missing from AssocResp\n");
2464 }
2465 if (!elems.vht_operation && bss_elems.vht_operation &&
2466 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
2467 elems.vht_operation = bss_elems.vht_operation;
2468 sdata_info(sdata,
2469 "AP bug: VHT operation missing from AssocResp\n");
2470 }
2471 }
2472
30eb1dc2
JB
2473 /*
2474 * We previously checked these in the beacon/probe response, so
2475 * they should be present here. This is just a safety net.
2476 */
2477 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2478 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
2479 sdata_info(sdata,
35d865af
JB
2480 "HT AP is missing WMM params or HT capability/operation\n");
2481 ret = false;
2482 goto out;
30eb1dc2
JB
2483 }
2484
2485 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2486 (!elems.vht_cap_elem || !elems.vht_operation)) {
2487 sdata_info(sdata,
35d865af
JB
2488 "VHT AP is missing VHT capability/operation\n");
2489 ret = false;
2490 goto out;
30eb1dc2
JB
2491 }
2492
2a33bee2
GE
2493 mutex_lock(&sdata->local->sta_mtx);
2494 /*
2495 * station info was already allocated and inserted before
2496 * the association and should be available to us
2497 */
7852e361 2498 sta = sta_info_get(sdata, cbss->bssid);
2a33bee2
GE
2499 if (WARN_ON(!sta)) {
2500 mutex_unlock(&sdata->local->sta_mtx);
35d865af
JB
2501 ret = false;
2502 goto out;
77fdaa12 2503 }
05e5e883 2504
55de908a 2505 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
f709fc69 2506
30eb1dc2 2507 /* Set up internal HT/VHT capabilities */
a8243b72 2508 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
ef96a842 2509 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
e1a0c6b3 2510 elems.ht_cap_elem, sta);
64f68e5d 2511
818255ea
MP
2512 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2513 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4a34215e 2514 elems.vht_cap_elem, sta);
818255ea 2515
30eb1dc2
JB
2516 /*
2517 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
2518 * in their association response, so ignore that data for our own
2519 * configuration. If it changed since the last beacon, we'll get the
2520 * next beacon and update then.
2521 */
1128958d 2522
bee7f586
JB
2523 /*
2524 * If an operating mode notification IE is present, override the
2525 * NSS calculation (that would be done in rate_control_rate_init())
2526 * and use the # of streams from that element.
2527 */
2528 if (elems.opmode_notif &&
2529 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
2530 u8 nss;
2531
2532 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
2533 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
2534 nss += 1;
2535 sta->sta.rx_nss = nss;
2536 }
2537
4b7679a5 2538 rate_control_rate_init(sta);
f0706e82 2539
46900298 2540 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
c2c98fde 2541 set_sta_flag(sta, WLAN_STA_MFP);
5394af4d 2542
ddf4ac53 2543 if (elems.wmm_param)
c2c98fde 2544 set_sta_flag(sta, WLAN_STA_WME);
ddf4ac53 2545
3e4d40fa 2546 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
c8987876
JB
2547 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2548 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2549 if (err) {
bdcbd8e0
JB
2550 sdata_info(sdata,
2551 "failed to move station %pM to desired state\n",
2552 sta->sta.addr);
c8987876
JB
2553 WARN_ON(__sta_info_destroy(sta));
2554 mutex_unlock(&sdata->local->sta_mtx);
35d865af
JB
2555 ret = false;
2556 goto out;
c8987876
JB
2557 }
2558
7852e361 2559 mutex_unlock(&sdata->local->sta_mtx);
ddf4ac53 2560
f2176d72
JO
2561 /*
2562 * Always handle WMM once after association regardless
2563 * of the first value the AP uses. Setting -1 here has
2564 * that effect because the AP values is an unsigned
2565 * 4-bit value.
2566 */
2567 ifmgd->wmm_last_param_set = -1;
2568
095d81ce 2569 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) && elems.wmm_param)
4ced3f74 2570 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
60f8b39c 2571 elems.wmm_param_len);
aa837e1d 2572 else
3abead59
JB
2573 ieee80211_set_wmm_default(sdata, false);
2574 changed |= BSS_CHANGED_QOS;
f0706e82 2575
60f8b39c
JB
2576 /* set AID and assoc capability,
2577 * ieee80211_set_associated() will tell the driver */
2578 bss_conf->aid = aid;
2579 bss_conf->assoc_capability = capab_info;
0c1ad2ca 2580 ieee80211_set_associated(sdata, cbss, changed);
f0706e82 2581
d524215f
FF
2582 /*
2583 * If we're using 4-addr mode, let the AP know that we're
2584 * doing so, so that it can create the STA VLAN on its side
2585 */
2586 if (ifmgd->use_4addr)
2587 ieee80211_send_4addr_nullfunc(local, sdata);
2588
15b7b062 2589 /*
b291ba11
JB
2590 * Start timer to probe the connection to the AP now.
2591 * Also start the timer that will detect beacon loss.
15b7b062 2592 */
b291ba11 2593 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
d3a910a8 2594 ieee80211_sta_reset_beacon_monitor(sdata);
15b7b062 2595
35d865af
JB
2596 ret = true;
2597 out:
2598 kfree(bss_ies);
2599 return ret;
f0706e82
JB
2600}
2601
8d61ffa5
JB
2602static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2603 struct ieee80211_mgmt *mgmt,
2604 size_t len)
66e67e41
JB
2605{
2606 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2607 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2608 u16 capab_info, status_code, aid;
2609 struct ieee802_11_elems elems;
2610 u8 *pos;
2611 bool reassoc;
8d61ffa5 2612 struct cfg80211_bss *bss;
66e67e41 2613
8d61ffa5 2614 sdata_assert_lock(sdata);
66e67e41
JB
2615
2616 if (!assoc_data)
8d61ffa5 2617 return;
b203ca39 2618 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
8d61ffa5 2619 return;
66e67e41
JB
2620
2621 /*
2622 * AssocResp and ReassocResp have identical structure, so process both
2623 * of them in this function.
2624 */
2625
2626 if (len < 24 + 6)
8d61ffa5 2627 return;
66e67e41
JB
2628
2629 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2630 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2631 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2632 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2633
bdcbd8e0
JB
2634 sdata_info(sdata,
2635 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2636 reassoc ? "Rea" : "A", mgmt->sa,
2637 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
66e67e41
JB
2638
2639 pos = mgmt->u.assoc_resp.variable;
b2e506bf 2640 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
66e67e41
JB
2641
2642 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
79ba1d89
JB
2643 elems.timeout_int &&
2644 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
66e67e41 2645 u32 tu, ms;
79ba1d89 2646 tu = le32_to_cpu(elems.timeout_int->value);
66e67e41 2647 ms = tu * 1024 / 1000;
bdcbd8e0
JB
2648 sdata_info(sdata,
2649 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2650 mgmt->sa, tu, ms);
66e67e41 2651 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
89afe614 2652 assoc_data->timeout_started = true;
66e67e41 2653 if (ms > IEEE80211_ASSOC_TIMEOUT)
8d61ffa5
JB
2654 run_again(sdata, assoc_data->timeout);
2655 return;
66e67e41
JB
2656 }
2657
8d61ffa5 2658 bss = assoc_data->bss;
66e67e41
JB
2659
2660 if (status_code != WLAN_STATUS_SUCCESS) {
bdcbd8e0
JB
2661 sdata_info(sdata, "%pM denied association (code=%d)\n",
2662 mgmt->sa, status_code);
66e67e41
JB
2663 ieee80211_destroy_assoc_data(sdata, false);
2664 } else {
8d61ffa5 2665 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
66e67e41 2666 /* oops -- internal error -- send timeout for now */
10a9109f 2667 ieee80211_destroy_assoc_data(sdata, false);
959867fa 2668 cfg80211_assoc_timeout(sdata->dev, bss);
8d61ffa5 2669 return;
66e67e41 2670 }
635d999f 2671 sdata_info(sdata, "associated\n");
79ebfb85
JB
2672
2673 /*
2674 * destroy assoc_data afterwards, as otherwise an idle
2675 * recalc after assoc_data is NULL but before associated
2676 * is set can cause the interface to go idle
2677 */
2678 ieee80211_destroy_assoc_data(sdata, true);
66e67e41
JB
2679 }
2680
6ff57cf8 2681 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len);
66e67e41 2682}
8e3c1b77 2683
98c8fccf 2684static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
8e3c1b77 2685 struct ieee80211_mgmt *mgmt, size_t len,
98c8fccf 2686 struct ieee80211_rx_status *rx_status,
d45c4172 2687 struct ieee802_11_elems *elems)
98c8fccf
JB
2688{
2689 struct ieee80211_local *local = sdata->local;
2690 int freq;
c2b13452 2691 struct ieee80211_bss *bss;
98c8fccf 2692 struct ieee80211_channel *channel;
56007a02 2693
8d61ffa5 2694 sdata_assert_lock(sdata);
b4f286a1 2695
1cd8e88e 2696 if (elems->ds_params)
59eb21a6
BR
2697 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2698 rx_status->band);
98c8fccf
JB
2699 else
2700 freq = rx_status->freq;
2701
2702 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2703
2704 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2705 return;
2706
98c8fccf 2707 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
d45c4172 2708 channel);
817cee76 2709 if (bss) {
77fdaa12 2710 ieee80211_rx_bss_put(local, bss);
817cee76
AB
2711 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
2712 }
f0706e82
JB
2713}
2714
2715
f698d856 2716static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
af6b6374 2717 struct sk_buff *skb)
f0706e82 2718{
af6b6374 2719 struct ieee80211_mgmt *mgmt = (void *)skb->data;
15b7b062 2720 struct ieee80211_if_managed *ifmgd;
af6b6374
JB
2721 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2722 size_t baselen, len = skb->len;
ae6a44e3
EK
2723 struct ieee802_11_elems elems;
2724
15b7b062
KV
2725 ifmgd = &sdata->u.mgd;
2726
8d61ffa5 2727 sdata_assert_lock(sdata);
77fdaa12 2728
b203ca39 2729 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
8e7cdbb6
TW
2730 return; /* ignore ProbeResp to foreign address */
2731
ae6a44e3
EK
2732 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2733 if (baselen > len)
2734 return;
2735
2736 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
b2e506bf 2737 false, &elems);
ae6a44e3 2738
d45c4172 2739 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
9859b81e 2740
77fdaa12 2741 if (ifmgd->associated &&
b203ca39 2742 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
4e5ff376 2743 ieee80211_reset_ap_probe(sdata);
66e67e41
JB
2744
2745 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
b203ca39 2746 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
66e67e41 2747 /* got probe response, continue with auth */
bdcbd8e0 2748 sdata_info(sdata, "direct probe responded\n");
66e67e41
JB
2749 ifmgd->auth_data->tries = 0;
2750 ifmgd->auth_data->timeout = jiffies;
89afe614 2751 ifmgd->auth_data->timeout_started = true;
8d61ffa5 2752 run_again(sdata, ifmgd->auth_data->timeout);
66e67e41 2753 }
f0706e82
JB
2754}
2755
d91f36db
JB
2756/*
2757 * This is the canonical list of information elements we care about,
2758 * the filter code also gives us all changes to the Microsoft OUI
2759 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2760 *
2761 * We implement beacon filtering in software since that means we can
2762 * avoid processing the frame here and in cfg80211, and userspace
2763 * will not be able to tell whether the hardware supports it or not.
2764 *
2765 * XXX: This list needs to be dynamic -- userspace needs to be able to
2766 * add items it requires. It also needs to be able to tell us to
2767 * look out for other vendor IEs.
2768 */
2769static const u64 care_about_ies =
1d4df3a5
JB
2770 (1ULL << WLAN_EID_COUNTRY) |
2771 (1ULL << WLAN_EID_ERP_INFO) |
2772 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2773 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2774 (1ULL << WLAN_EID_HT_CAPABILITY) |
074d46d1 2775 (1ULL << WLAN_EID_HT_OPERATION);
d91f36db 2776
8d61ffa5
JB
2777static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2778 struct ieee80211_mgmt *mgmt, size_t len,
2779 struct ieee80211_rx_status *rx_status)
f0706e82 2780{
d91f36db 2781 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
17e4ec14 2782 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
f0706e82
JB
2783 size_t baselen;
2784 struct ieee802_11_elems elems;
f698d856 2785 struct ieee80211_local *local = sdata->local;
55de908a
JB
2786 struct ieee80211_chanctx_conf *chanctx_conf;
2787 struct ieee80211_channel *chan;
bee7f586 2788 struct sta_info *sta;
471b3efd 2789 u32 changed = 0;
f87ad637 2790 bool erp_valid;
7a5158ef 2791 u8 erp_value = 0;
d91f36db 2792 u32 ncrc;
77fdaa12 2793 u8 *bssid;
8d61ffa5 2794 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
77fdaa12 2795
8d61ffa5 2796 sdata_assert_lock(sdata);
f0706e82 2797
ae6a44e3
EK
2798 /* Process beacon from the current BSS */
2799 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2800 if (baselen > len)
8d61ffa5 2801 return;
ae6a44e3 2802
55de908a
JB
2803 rcu_read_lock();
2804 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2805 if (!chanctx_conf) {
2806 rcu_read_unlock();
8d61ffa5 2807 return;
55de908a
JB
2808 }
2809
4bf88530 2810 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
55de908a 2811 rcu_read_unlock();
8d61ffa5 2812 return;
55de908a 2813 }
4bf88530 2814 chan = chanctx_conf->def.chan;
55de908a 2815 rcu_read_unlock();
f0706e82 2816
c65dd147 2817 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
b203ca39 2818 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
66e67e41 2819 ieee802_11_parse_elems(mgmt->u.beacon.variable,
b2e506bf 2820 len - baselen, false, &elems);
77fdaa12 2821
d45c4172 2822 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
482a9c74
AB
2823 if (elems.tim && !elems.parse_error) {
2824 const struct ieee80211_tim_ie *tim_ie = elems.tim;
2825 ifmgd->dtim_period = tim_ie->dtim_period;
2826 }
989c6505 2827 ifmgd->have_beacon = true;
c65dd147 2828 ifmgd->assoc_data->need_beacon = false;
ef429dad
JB
2829 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
2830 sdata->vif.bss_conf.sync_tsf =
2831 le64_to_cpu(mgmt->u.beacon.timestamp);
2832 sdata->vif.bss_conf.sync_device_ts =
2833 rx_status->device_timestamp;
2834 if (elems.tim)
2835 sdata->vif.bss_conf.sync_dtim_count =
2836 elems.tim->dtim_count;
2837 else
2838 sdata->vif.bss_conf.sync_dtim_count = 0;
2839 }
66e67e41
JB
2840 /* continue assoc process */
2841 ifmgd->assoc_data->timeout = jiffies;
89afe614 2842 ifmgd->assoc_data->timeout_started = true;
8d61ffa5
JB
2843 run_again(sdata, ifmgd->assoc_data->timeout);
2844 return;
66e67e41 2845 }
77fdaa12 2846
66e67e41 2847 if (!ifmgd->associated ||
b203ca39 2848 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
8d61ffa5 2849 return;
66e67e41 2850 bssid = ifmgd->associated->bssid;
f0706e82 2851
17e4ec14
JM
2852 /* Track average RSSI from the Beacon frames of the current AP */
2853 ifmgd->last_beacon_signal = rx_status->signal;
2854 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2855 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3ba06c6f 2856 ifmgd->ave_beacon_signal = rx_status->signal * 16;
17e4ec14 2857 ifmgd->last_cqm_event_signal = 0;
391a200a 2858 ifmgd->count_beacon_signal = 1;
615f7b9b 2859 ifmgd->last_ave_beacon_signal = 0;
17e4ec14
JM
2860 } else {
2861 ifmgd->ave_beacon_signal =
2862 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
2863 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
2864 ifmgd->ave_beacon_signal) / 16;
391a200a 2865 ifmgd->count_beacon_signal++;
17e4ec14 2866 }
615f7b9b
MV
2867
2868 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
2869 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
2870 int sig = ifmgd->ave_beacon_signal;
2871 int last_sig = ifmgd->last_ave_beacon_signal;
2872
2873 /*
2874 * if signal crosses either of the boundaries, invoke callback
2875 * with appropriate parameters
2876 */
2877 if (sig > ifmgd->rssi_max_thold &&
2878 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
2879 ifmgd->last_ave_beacon_signal = sig;
887da917 2880 drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
615f7b9b
MV
2881 } else if (sig < ifmgd->rssi_min_thold &&
2882 (last_sig >= ifmgd->rssi_max_thold ||
2883 last_sig == 0)) {
2884 ifmgd->last_ave_beacon_signal = sig;
887da917 2885 drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
615f7b9b
MV
2886 }
2887 }
2888
17e4ec14 2889 if (bss_conf->cqm_rssi_thold &&
391a200a 2890 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
ea086359 2891 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
17e4ec14
JM
2892 int sig = ifmgd->ave_beacon_signal / 16;
2893 int last_event = ifmgd->last_cqm_event_signal;
2894 int thold = bss_conf->cqm_rssi_thold;
2895 int hyst = bss_conf->cqm_rssi_hyst;
2896 if (sig < thold &&
2897 (last_event == 0 || sig < last_event - hyst)) {
2898 ifmgd->last_cqm_event_signal = sig;
2899 ieee80211_cqm_rssi_notify(
2900 &sdata->vif,
2901 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2902 GFP_KERNEL);
2903 } else if (sig > thold &&
2904 (last_event == 0 || sig > last_event + hyst)) {
2905 ifmgd->last_cqm_event_signal = sig;
2906 ieee80211_cqm_rssi_notify(
2907 &sdata->vif,
2908 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2909 GFP_KERNEL);
2910 }
2911 }
2912
392b9ffb 2913 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
bdcbd8e0 2914 mlme_dbg_ratelimited(sdata,
112c31f0 2915 "cancelling AP probe due to a received beacon\n");
392b9ffb 2916 ieee80211_reset_ap_probe(sdata);
92778180
JM
2917 }
2918
b291ba11
JB
2919 /*
2920 * Push the beacon loss detection into the future since
2921 * we are processing a beacon from the AP just now.
2922 */
d3a910a8 2923 ieee80211_sta_reset_beacon_monitor(sdata);
b291ba11 2924
d91f36db
JB
2925 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2926 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
b2e506bf 2927 len - baselen, false, &elems,
d91f36db
JB
2928 care_about_ies, ncrc);
2929
25c9c875 2930 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
f87ad637
RR
2931 bool directed_tim = ieee80211_check_tim(elems.tim,
2932 elems.tim_len,
2933 ifmgd->aid);
1fb3606b 2934 if (directed_tim) {
572e0012 2935 if (local->hw.conf.dynamic_ps_timeout > 0) {
70b12f26
RW
2936 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2937 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2938 ieee80211_hw_config(local,
2939 IEEE80211_CONF_CHANGE_PS);
2940 }
572e0012 2941 ieee80211_send_nullfunc(local, sdata, 0);
6f0756a3 2942 } else if (!local->pspolling && sdata->u.mgd.powersave) {
572e0012
KV
2943 local->pspolling = true;
2944
2945 /*
2946 * Here is assumed that the driver will be
2947 * able to send ps-poll frame and receive a
2948 * response even though power save mode is
2949 * enabled, but some drivers might require
2950 * to disable power save here. This needs
2951 * to be investigated.
2952 */
2953 ieee80211_send_pspoll(local, sdata);
2954 }
a97b77b9
VN
2955 }
2956 }
7a5158ef 2957
488dd7b5 2958 if (sdata->vif.p2p) {
67baf663 2959 struct ieee80211_p2p_noa_attr noa = {};
488dd7b5
JB
2960 int ret;
2961
2962 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
2963 len - baselen,
2964 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
934457ee 2965 (u8 *) &noa, sizeof(noa));
67baf663
JD
2966 if (ret >= 2) {
2967 if (sdata->u.mgd.p2p_noa_index != noa.index) {
2968 /* valid noa_attr and index changed */
2969 sdata->u.mgd.p2p_noa_index = noa.index;
2970 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
2971 changed |= BSS_CHANGED_P2P_PS;
2972 /*
2973 * make sure we update all information, the CRC
2974 * mechanism doesn't look at P2P attributes.
2975 */
2976 ifmgd->beacon_crc_valid = false;
2977 }
2978 } else if (sdata->u.mgd.p2p_noa_index != -1) {
2979 /* noa_attr not found and we had valid noa_attr before */
2980 sdata->u.mgd.p2p_noa_index = -1;
2981 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
488dd7b5 2982 changed |= BSS_CHANGED_P2P_PS;
488dd7b5
JB
2983 ifmgd->beacon_crc_valid = false;
2984 }
2985 }
2986
d8ec4433 2987 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
8d61ffa5 2988 return;
30196673 2989 ifmgd->beacon_crc = ncrc;
d8ec4433 2990 ifmgd->beacon_crc_valid = true;
30196673 2991
d45c4172 2992 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
7d25745d 2993
d70b7616
JB
2994 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
2995 &elems, true);
2996
095d81ce
JB
2997 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
2998 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
7d25745d
JB
2999 elems.wmm_param_len))
3000 changed |= BSS_CHANGED_QOS;
3001
c65dd147
EG
3002 /*
3003 * If we haven't had a beacon before, tell the driver about the
ef429dad 3004 * DTIM period (and beacon timing if desired) now.
c65dd147 3005 */
989c6505 3006 if (!ifmgd->have_beacon) {
c65dd147
EG
3007 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3008 if (elems.tim)
3009 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3010 else
3011 bss_conf->dtim_period = 1;
ef429dad
JB
3012
3013 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
3014 sdata->vif.bss_conf.sync_tsf =
3015 le64_to_cpu(mgmt->u.beacon.timestamp);
3016 sdata->vif.bss_conf.sync_device_ts =
3017 rx_status->device_timestamp;
3018 if (elems.tim)
3019 sdata->vif.bss_conf.sync_dtim_count =
3020 elems.tim->dtim_count;
3021 else
3022 sdata->vif.bss_conf.sync_dtim_count = 0;
3023 }
3024
989c6505
AB
3025 changed |= BSS_CHANGED_BEACON_INFO;
3026 ifmgd->have_beacon = true;
482a9c74
AB
3027
3028 mutex_lock(&local->iflist_mtx);
3029 ieee80211_recalc_ps(local, -1);
3030 mutex_unlock(&local->iflist_mtx);
3031
ce857888 3032 ieee80211_recalc_ps_vif(sdata);
c65dd147
EG
3033 }
3034
1946bed9 3035 if (elems.erp_info) {
7a5158ef
JB
3036 erp_valid = true;
3037 erp_value = elems.erp_info[0];
3038 } else {
3039 erp_valid = false;
50c4afb9 3040 }
7a5158ef
JB
3041 changed |= ieee80211_handle_bss_capability(sdata,
3042 le16_to_cpu(mgmt->u.beacon.capab_info),
3043 erp_valid, erp_value);
f0706e82 3044
1128958d 3045 mutex_lock(&local->sta_mtx);
bee7f586
JB
3046 sta = sta_info_get(sdata, bssid);
3047
30eb1dc2
JB
3048 if (ieee80211_config_bw(sdata, sta, elems.ht_operation,
3049 elems.vht_operation, bssid, &changed)) {
3050 mutex_unlock(&local->sta_mtx);
3051 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3052 WLAN_REASON_DEAUTH_LEAVING,
3053 true, deauth_buf);
6ff57cf8
JB
3054 cfg80211_tx_mlme_mgmt(sdata->dev, deauth_buf,
3055 sizeof(deauth_buf));
8d61ffa5 3056 return;
30eb1dc2 3057 }
bee7f586
JB
3058
3059 if (sta && elems.opmode_notif)
3060 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
3061 rx_status->band, true);
1128958d 3062 mutex_unlock(&local->sta_mtx);
d3c990fb 3063
04b7b2ff
JB
3064 if (elems.country_elem && elems.pwr_constr_elem &&
3065 mgmt->u.probe_resp.capab_info &
3066 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
1ea6f9c0
JB
3067 changed |= ieee80211_handle_pwr_constr(sdata, chan,
3068 elems.country_elem,
3069 elems.country_elem_len,
3070 elems.pwr_constr_elem);
3f2355cb 3071
471b3efd 3072 ieee80211_bss_info_change_notify(sdata, changed);
f0706e82
JB
3073}
3074
1fa57d01
JB
3075void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3076 struct sk_buff *skb)
f0706e82
JB
3077{
3078 struct ieee80211_rx_status *rx_status;
f0706e82
JB
3079 struct ieee80211_mgmt *mgmt;
3080 u16 fc;
1b3a2e49
JB
3081 struct ieee802_11_elems elems;
3082 int ies_len;
f0706e82 3083
f0706e82
JB
3084 rx_status = (struct ieee80211_rx_status *) skb->cb;
3085 mgmt = (struct ieee80211_mgmt *) skb->data;
3086 fc = le16_to_cpu(mgmt->frame_control);
3087
8d61ffa5 3088 sdata_lock(sdata);
77fdaa12 3089
66e67e41
JB
3090 switch (fc & IEEE80211_FCTL_STYPE) {
3091 case IEEE80211_STYPE_BEACON:
8d61ffa5 3092 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
66e67e41
JB
3093 break;
3094 case IEEE80211_STYPE_PROBE_RESP:
3095 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3096 break;
3097 case IEEE80211_STYPE_AUTH:
8d61ffa5 3098 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
66e67e41
JB
3099 break;
3100 case IEEE80211_STYPE_DEAUTH:
8d61ffa5 3101 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
66e67e41
JB
3102 break;
3103 case IEEE80211_STYPE_DISASSOC:
8d61ffa5 3104 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
66e67e41
JB
3105 break;
3106 case IEEE80211_STYPE_ASSOC_RESP:
3107 case IEEE80211_STYPE_REASSOC_RESP:
8d61ffa5 3108 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
66e67e41
JB
3109 break;
3110 case IEEE80211_STYPE_ACTION:
37799e52 3111 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
1b3a2e49
JB
3112 ies_len = skb->len -
3113 offsetof(struct ieee80211_mgmt,
3114 u.action.u.chan_switch.variable);
37799e52
JB
3115
3116 if (ies_len < 0)
3117 break;
3118
3119 ieee802_11_parse_elems(
3120 mgmt->u.action.u.chan_switch.variable,
b2e506bf 3121 ies_len, true, &elems);
37799e52
JB
3122
3123 if (elems.parse_error)
3124 break;
3125
1b3a2e49
JB
3126 ieee80211_sta_process_chanswitch(sdata,
3127 rx_status->mactime,
04a161f4 3128 &elems, false);
1b3a2e49
JB
3129 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3130 ies_len = skb->len -
3131 offsetof(struct ieee80211_mgmt,
3132 u.action.u.ext_chan_switch.variable);
3133
3134 if (ies_len < 0)
3135 break;
3136
3137 ieee802_11_parse_elems(
3138 mgmt->u.action.u.ext_chan_switch.variable,
b2e506bf 3139 ies_len, true, &elems);
1b3a2e49
JB
3140
3141 if (elems.parse_error)
3142 break;
3143
3144 /* for the handling code pretend this was also an IE */
3145 elems.ext_chansw_ie =
3146 &mgmt->u.action.u.ext_chan_switch.data;
3147
66e67e41 3148 ieee80211_sta_process_chanswitch(sdata,
37799e52 3149 rx_status->mactime,
04a161f4 3150 &elems, false);
77fdaa12 3151 }
37799e52 3152 break;
77fdaa12 3153 }
8d61ffa5 3154 sdata_unlock(sdata);
f0706e82
JB
3155}
3156
9c6bd790 3157static void ieee80211_sta_timer(unsigned long data)
f0706e82 3158{
60f8b39c
JB
3159 struct ieee80211_sub_if_data *sdata =
3160 (struct ieee80211_sub_if_data *) data;
5bb644a0 3161
9b7d72c1 3162 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
f0706e82
JB
3163}
3164
04ac3c0e 3165static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
6b684db1 3166 u8 *bssid, u8 reason, bool tx)
04ac3c0e 3167{
6ae16775 3168 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
04ac3c0e 3169
37ad3888 3170 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
6b684db1 3171 tx, frame_buf);
37ad3888 3172
6ff57cf8
JB
3173 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
3174 IEEE80211_DEAUTH_FRAME_LEN);
04ac3c0e
FF
3175}
3176
66e67e41
JB
3177static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
3178{
3179 struct ieee80211_local *local = sdata->local;
3180 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3181 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
1672c0e3 3182 u32 tx_flags = 0;
66e67e41 3183
8d61ffa5 3184 sdata_assert_lock(sdata);
66e67e41
JB
3185
3186 if (WARN_ON_ONCE(!auth_data))
3187 return -EINVAL;
3188
66e67e41
JB
3189 auth_data->tries++;
3190
3191 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
bdcbd8e0
JB
3192 sdata_info(sdata, "authentication with %pM timed out\n",
3193 auth_data->bss->bssid);
66e67e41
JB
3194
3195 /*
3196 * Most likely AP is not in the range so remove the
3197 * bss struct for that AP.
3198 */
3199 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3200
3201 return -ETIMEDOUT;
3202 }
3203
a1845fc7
JB
3204 drv_mgd_prepare_tx(local, sdata);
3205
66e67e41 3206 if (auth_data->bss->proberesp_ies) {
6b8ece3a
JM
3207 u16 trans = 1;
3208 u16 status = 0;
3209
bdcbd8e0
JB
3210 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3211 auth_data->bss->bssid, auth_data->tries,
3212 IEEE80211_AUTH_MAX_TRIES);
66e67e41
JB
3213
3214 auth_data->expected_transaction = 2;
6b8ece3a
JM
3215
3216 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3217 trans = auth_data->sae_trans;
3218 status = auth_data->sae_status;
3219 auth_data->expected_transaction = trans;
3220 }
3221
6211dd12
SG
3222 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
3223 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3224 IEEE80211_TX_INTFL_MLME_CONN_TX;
3225
6b8ece3a
JM
3226 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
3227 auth_data->data, auth_data->data_len,
66e67e41 3228 auth_data->bss->bssid,
1672c0e3
JB
3229 auth_data->bss->bssid, NULL, 0, 0,
3230 tx_flags);
66e67e41
JB
3231 } else {
3232 const u8 *ssidie;
3233
bdcbd8e0
JB
3234 sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
3235 auth_data->bss->bssid, auth_data->tries,
3236 IEEE80211_AUTH_MAX_TRIES);
66e67e41 3237
9caf0364 3238 rcu_read_lock();
66e67e41 3239 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
9caf0364
JB
3240 if (!ssidie) {
3241 rcu_read_unlock();
66e67e41 3242 return -EINVAL;
9caf0364 3243 }
66e67e41
JB
3244 /*
3245 * Direct probe is sent to broadcast address as some APs
3246 * will not answer to direct packet in unassociated state.
3247 */
3248 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
6211dd12 3249 NULL, 0, (u32) -1, true, 0,
55de908a 3250 auth_data->bss->channel, false);
9caf0364 3251 rcu_read_unlock();
66e67e41
JB
3252 }
3253
6211dd12 3254 if (tx_flags == 0) {
1672c0e3 3255 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
cb236d2d 3256 auth_data->timeout_started = true;
8d61ffa5 3257 run_again(sdata, auth_data->timeout);
89afe614 3258 } else {
cb236d2d
JB
3259 auth_data->timeout =
3260 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
3261 auth_data->timeout_started = true;
3262 run_again(sdata, auth_data->timeout);
1672c0e3 3263 }
66e67e41
JB
3264
3265 return 0;
3266}
3267
3268static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
3269{
3270 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3271 struct ieee80211_local *local = sdata->local;
3272
8d61ffa5 3273 sdata_assert_lock(sdata);
66e67e41 3274
66e67e41
JB
3275 assoc_data->tries++;
3276 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
bdcbd8e0
JB
3277 sdata_info(sdata, "association with %pM timed out\n",
3278 assoc_data->bss->bssid);
66e67e41
JB
3279
3280 /*
3281 * Most likely AP is not in the range so remove the
3282 * bss struct for that AP.
3283 */
3284 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
3285
3286 return -ETIMEDOUT;
3287 }
3288
bdcbd8e0
JB
3289 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
3290 assoc_data->bss->bssid, assoc_data->tries,
3291 IEEE80211_ASSOC_MAX_TRIES);
66e67e41
JB
3292 ieee80211_send_assoc(sdata);
3293
1672c0e3
JB
3294 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
3295 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
89afe614 3296 assoc_data->timeout_started = true;
8d61ffa5 3297 run_again(sdata, assoc_data->timeout);
89afe614 3298 } else {
cb236d2d
JB
3299 assoc_data->timeout =
3300 round_jiffies_up(jiffies +
3301 IEEE80211_ASSOC_TIMEOUT_LONG);
3302 assoc_data->timeout_started = true;
3303 run_again(sdata, assoc_data->timeout);
1672c0e3 3304 }
66e67e41
JB
3305
3306 return 0;
3307}
3308
1672c0e3
JB
3309void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
3310 __le16 fc, bool acked)
3311{
3312 struct ieee80211_local *local = sdata->local;
3313
3314 sdata->u.mgd.status_fc = fc;
3315 sdata->u.mgd.status_acked = acked;
3316 sdata->u.mgd.status_received = true;
3317
3318 ieee80211_queue_work(&local->hw, &sdata->work);
3319}
3320
1fa57d01 3321void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
9c6bd790 3322{
9c6bd790 3323 struct ieee80211_local *local = sdata->local;
1fa57d01 3324 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9c6bd790 3325
8d61ffa5 3326 sdata_lock(sdata);
77fdaa12 3327
1672c0e3
JB
3328 if (ifmgd->status_received) {
3329 __le16 fc = ifmgd->status_fc;
3330 bool status_acked = ifmgd->status_acked;
3331
3332 ifmgd->status_received = false;
3333 if (ifmgd->auth_data &&
3334 (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
3335 if (status_acked) {
3336 ifmgd->auth_data->timeout =
3337 jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
8d61ffa5 3338 run_again(sdata, ifmgd->auth_data->timeout);
1672c0e3
JB
3339 } else {
3340 ifmgd->auth_data->timeout = jiffies - 1;
3341 }
89afe614 3342 ifmgd->auth_data->timeout_started = true;
1672c0e3
JB
3343 } else if (ifmgd->assoc_data &&
3344 (ieee80211_is_assoc_req(fc) ||
3345 ieee80211_is_reassoc_req(fc))) {
3346 if (status_acked) {
3347 ifmgd->assoc_data->timeout =
3348 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
8d61ffa5 3349 run_again(sdata, ifmgd->assoc_data->timeout);
1672c0e3
JB
3350 } else {
3351 ifmgd->assoc_data->timeout = jiffies - 1;
3352 }
89afe614 3353 ifmgd->assoc_data->timeout_started = true;
1672c0e3
JB
3354 }
3355 }
3356
89afe614 3357 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
66e67e41
JB
3358 time_after(jiffies, ifmgd->auth_data->timeout)) {
3359 if (ifmgd->auth_data->done) {
3360 /*
3361 * ok ... we waited for assoc but userspace didn't,
3362 * so let's just kill the auth data
3363 */
3364 ieee80211_destroy_auth_data(sdata, false);
3365 } else if (ieee80211_probe_auth(sdata)) {
3366 u8 bssid[ETH_ALEN];
3367
3368 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3369
3370 ieee80211_destroy_auth_data(sdata, false);
3371
6ff57cf8 3372 cfg80211_auth_timeout(sdata->dev, bssid);
66e67e41 3373 }
89afe614 3374 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
8d61ffa5 3375 run_again(sdata, ifmgd->auth_data->timeout);
66e67e41 3376
89afe614 3377 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
66e67e41 3378 time_after(jiffies, ifmgd->assoc_data->timeout)) {
989c6505 3379 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
66e67e41 3380 ieee80211_do_assoc(sdata)) {
959867fa 3381 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
66e67e41
JB
3382
3383 ieee80211_destroy_assoc_data(sdata, false);
959867fa 3384 cfg80211_assoc_timeout(sdata->dev, bss);
66e67e41 3385 }
89afe614 3386 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
8d61ffa5 3387 run_again(sdata, ifmgd->assoc_data->timeout);
66e67e41 3388
392b9ffb 3389 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
b291ba11 3390 ifmgd->associated) {
a43abf29 3391 u8 bssid[ETH_ALEN];
72a8a3ed 3392 int max_tries;
a43abf29 3393
0c1ad2ca 3394 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4e5ff376 3395
72a8a3ed 3396 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
180205bd 3397 max_tries = max_nullfunc_tries;
72a8a3ed 3398 else
180205bd 3399 max_tries = max_probe_tries;
72a8a3ed 3400
4e5ff376
FF
3401 /* ACK received for nullfunc probing frame */
3402 if (!ifmgd->probe_send_count)
3403 ieee80211_reset_ap_probe(sdata);
04ac3c0e
FF
3404 else if (ifmgd->nullfunc_failed) {
3405 if (ifmgd->probe_send_count < max_tries) {
bdcbd8e0
JB
3406 mlme_dbg(sdata,
3407 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3408 bssid, ifmgd->probe_send_count,
3409 max_tries);
04ac3c0e
FF
3410 ieee80211_mgd_probe_ap_send(sdata);
3411 } else {
bdcbd8e0
JB
3412 mlme_dbg(sdata,
3413 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3414 bssid);
95acac61 3415 ieee80211_sta_connection_lost(sdata, bssid,
6b684db1
JB
3416 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3417 false);
04ac3c0e
FF
3418 }
3419 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
8d61ffa5 3420 run_again(sdata, ifmgd->probe_timeout);
04ac3c0e 3421 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
bdcbd8e0
JB
3422 mlme_dbg(sdata,
3423 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3424 bssid, probe_wait_ms);
95acac61 3425 ieee80211_sta_connection_lost(sdata, bssid,
6b684db1 3426 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
04ac3c0e 3427 } else if (ifmgd->probe_send_count < max_tries) {
bdcbd8e0
JB
3428 mlme_dbg(sdata,
3429 "No probe response from AP %pM after %dms, try %d/%i\n",
3430 bssid, probe_wait_ms,
3431 ifmgd->probe_send_count, max_tries);
a43abf29
ML
3432 ieee80211_mgd_probe_ap_send(sdata);
3433 } else {
b291ba11
JB
3434 /*
3435 * We actually lost the connection ... or did we?
3436 * Let's make sure!
3437 */
b38afa87
BG
3438 wiphy_debug(local->hw.wiphy,
3439 "%s: No probe response from AP %pM"
3440 " after %dms, disconnecting.\n",
3441 sdata->name,
180205bd 3442 bssid, probe_wait_ms);
04ac3c0e 3443
95acac61 3444 ieee80211_sta_connection_lost(sdata, bssid,
6b684db1 3445 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
b291ba11
JB
3446 }
3447 }
3448
8d61ffa5 3449 sdata_unlock(sdata);
f0706e82
JB
3450}
3451
b291ba11
JB
3452static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3453{
3454 struct ieee80211_sub_if_data *sdata =
3455 (struct ieee80211_sub_if_data *) data;
3456 struct ieee80211_local *local = sdata->local;
3457
3458 if (local->quiescing)
3459 return;
3460
682bd38b 3461 sdata->u.mgd.connection_loss = false;
1e4dcd01
JO
3462 ieee80211_queue_work(&sdata->local->hw,
3463 &sdata->u.mgd.beacon_connection_loss_work);
b291ba11
JB
3464}
3465
3466static void ieee80211_sta_conn_mon_timer(unsigned long data)
3467{
3468 struct ieee80211_sub_if_data *sdata =
3469 (struct ieee80211_sub_if_data *) data;
3470 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3471 struct ieee80211_local *local = sdata->local;
3472
3473 if (local->quiescing)
3474 return;
3475
42935eca 3476 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
b291ba11
JB
3477}
3478
3479static void ieee80211_sta_monitor_work(struct work_struct *work)
3480{
3481 struct ieee80211_sub_if_data *sdata =
3482 container_of(work, struct ieee80211_sub_if_data,
3483 u.mgd.monitor_work);
3484
3485 ieee80211_mgd_probe_ap(sdata, false);
3486}
3487
9c6bd790
JB
3488static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3489{
494f1fe5
EP
3490 u32 flags;
3491
ad935687 3492 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
925e64c3 3493 __ieee80211_stop_poll(sdata);
ad935687 3494
b291ba11 3495 /* let's probe the connection once */
494f1fe5
EP
3496 flags = sdata->local->hw.flags;
3497 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
3498 ieee80211_queue_work(&sdata->local->hw,
3499 &sdata->u.mgd.monitor_work);
b291ba11 3500 /* and do all the other regular work too */
64592c8f 3501 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
ad935687 3502 }
9c6bd790 3503}
f0706e82 3504
b8360ab8
JB
3505#ifdef CONFIG_PM
3506void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
3507{
3508 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3509
8d61ffa5 3510 sdata_lock(sdata);
b8360ab8 3511 if (!ifmgd->associated) {
8d61ffa5 3512 sdata_unlock(sdata);
b8360ab8
JB
3513 return;
3514 }
3515
3516 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
3517 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
3518 mlme_dbg(sdata, "driver requested disconnect after resume\n");
3519 ieee80211_sta_connection_lost(sdata,
3520 ifmgd->associated->bssid,
3521 WLAN_REASON_UNSPECIFIED,
3522 true);
8d61ffa5 3523 sdata_unlock(sdata);
b8360ab8
JB
3524 return;
3525 }
8d61ffa5 3526 sdata_unlock(sdata);
b8360ab8
JB
3527}
3528#endif
3529
9c6bd790
JB
3530/* interface setup */
3531void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
f0706e82 3532{
46900298 3533 struct ieee80211_if_managed *ifmgd;
988c0f72 3534
46900298 3535 ifmgd = &sdata->u.mgd;
b291ba11 3536 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
46900298 3537 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
1e4dcd01
JO
3538 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3539 ieee80211_beacon_connection_loss_work);
882a7c69
JB
3540 INIT_WORK(&ifmgd->csa_connection_drop_work,
3541 ieee80211_csa_connection_drop_work);
687da132 3542 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
46900298 3543 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
c481ec97 3544 (unsigned long) sdata);
b291ba11
JB
3545 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3546 (unsigned long) sdata);
3547 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3548 (unsigned long) sdata);
46900298 3549 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
9c6bd790 3550 (unsigned long) sdata);
9c6bd790 3551
ab1faead 3552 ifmgd->flags = 0;
1478acb3 3553 ifmgd->powersave = sdata->wdev.ps;
219c3867
AB
3554 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
3555 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
67baf663 3556 ifmgd->p2p_noa_index = -1;
bbbdff9e 3557
0f78231b
JB
3558 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3559 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3560 else
3561 ifmgd->req_smps = IEEE80211_SMPS_OFF;
f0706e82
JB
3562}
3563
77fdaa12
JB
3564/* scan finished notification */
3565void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
60f8b39c 3566{
31ee67a1 3567 struct ieee80211_sub_if_data *sdata;
60f8b39c 3568
77fdaa12
JB
3569 /* Restart STA timers */
3570 rcu_read_lock();
370bd005
BG
3571 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3572 if (ieee80211_sdata_running(sdata))
3573 ieee80211_restart_sta_timer(sdata);
3574 }
77fdaa12
JB
3575 rcu_read_unlock();
3576}
60f8b39c 3577
77fdaa12
JB
3578int ieee80211_max_network_latency(struct notifier_block *nb,
3579 unsigned long data, void *dummy)
3580{
3581 s32 latency_usec = (s32) data;
3582 struct ieee80211_local *local =
3583 container_of(nb, struct ieee80211_local,
3584 network_latency_notifier);
1fa6f4af 3585
77fdaa12
JB
3586 mutex_lock(&local->iflist_mtx);
3587 ieee80211_recalc_ps(local, latency_usec);
3588 mutex_unlock(&local->iflist_mtx);
dfe67012 3589
77fdaa12 3590 return 0;
9c6bd790
JB
3591}
3592
f2d9d270
JB
3593static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
3594 struct cfg80211_bss *cbss)
3595{
3596 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3597 const u8 *ht_cap_ie, *vht_cap_ie;
3598 const struct ieee80211_ht_cap *ht_cap;
3599 const struct ieee80211_vht_cap *vht_cap;
3600 u8 chains = 1;
3601
3602 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
3603 return chains;
3604
9caf0364 3605 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
f2d9d270
JB
3606 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3607 ht_cap = (void *)(ht_cap_ie + 2);
3608 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3609 /*
3610 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
3611 * "Tx Unequal Modulation Supported" fields.
3612 */
3613 }
3614
3615 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
3616 return chains;
3617
9caf0364 3618 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
f2d9d270
JB
3619 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
3620 u8 nss;
3621 u16 tx_mcs_map;
3622
3623 vht_cap = (void *)(vht_cap_ie + 2);
3624 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
3625 for (nss = 8; nss > 0; nss--) {
3626 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
3627 IEEE80211_VHT_MCS_NOT_SUPPORTED)
3628 break;
3629 }
3630 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
3631 chains = max(chains, nss);
3632 }
3633
3634 return chains;
3635}
3636
b17166a7
JB
3637static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3638 struct cfg80211_bss *cbss)
a1cf775d
JB
3639{
3640 struct ieee80211_local *local = sdata->local;
3641 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
24398e39 3642 const struct ieee80211_ht_operation *ht_oper = NULL;
f2d9d270 3643 const struct ieee80211_vht_operation *vht_oper = NULL;
24398e39 3644 struct ieee80211_supported_band *sband;
4bf88530 3645 struct cfg80211_chan_def chandef;
f2d9d270 3646 int ret;
a1cf775d 3647
24398e39
JB
3648 sband = local->hw.wiphy->bands[cbss->channel->band];
3649
f2d9d270
JB
3650 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
3651 IEEE80211_STA_DISABLE_80P80MHZ |
3652 IEEE80211_STA_DISABLE_160MHZ);
3653
9caf0364
JB
3654 rcu_read_lock();
3655
f2d9d270
JB
3656 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3657 sband->ht_cap.ht_supported) {
08e6effa 3658 const u8 *ht_oper_ie, *ht_cap;
24398e39 3659
9caf0364 3660 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
24398e39
JB
3661 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
3662 ht_oper = (void *)(ht_oper_ie + 2);
08e6effa
JB
3663
3664 ht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
3665 if (!ht_cap || ht_cap[1] < sizeof(struct ieee80211_ht_cap)) {
3666 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3667 ht_oper = NULL;
3668 }
24398e39
JB
3669 }
3670
f2d9d270
JB
3671 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3672 sband->vht_cap.vht_supported) {
08e6effa 3673 const u8 *vht_oper_ie, *vht_cap;
f2d9d270 3674
9caf0364
JB
3675 vht_oper_ie = ieee80211_bss_get_ie(cbss,
3676 WLAN_EID_VHT_OPERATION);
f2d9d270
JB
3677 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
3678 vht_oper = (void *)(vht_oper_ie + 2);
3679 if (vht_oper && !ht_oper) {
3680 vht_oper = NULL;
bdcbd8e0 3681 sdata_info(sdata,
f2d9d270 3682 "AP advertised VHT without HT, disabling both\n");
cb145022
JB
3683 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3684 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
24398e39 3685 }
08e6effa
JB
3686
3687 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
3688 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
3689 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3690 vht_oper = NULL;
3691 }
24398e39
JB
3692 }
3693
f2d9d270
JB
3694 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
3695 cbss->channel,
3696 ht_oper, vht_oper,
5cdaed1e 3697 &chandef, false);
04ecd257 3698
f2d9d270
JB
3699 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
3700 local->rx_chains);
24398e39 3701
9caf0364
JB
3702 rcu_read_unlock();
3703
04ecd257
JB
3704 /* will change later if needed */
3705 sdata->smps_mode = IEEE80211_SMPS_OFF;
3706
34a3740d 3707 mutex_lock(&local->mtx);
f2d9d270
JB
3708 /*
3709 * If this fails (possibly due to channel context sharing
3710 * on incompatible channels, e.g. 80+80 and 160 sharing the
3711 * same control channel) try to use a smaller bandwidth.
3712 */
3713 ret = ieee80211_vif_use_channel(sdata, &chandef,
3714 IEEE80211_CHANCTX_SHARED);
0418a445
SW
3715
3716 /* don't downgrade for 5 and 10 MHz channels, though. */
3717 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
3718 chandef.width == NL80211_CHAN_WIDTH_10)
34a3740d 3719 goto out;
0418a445 3720
d601cd8d 3721 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
e6b7cde4 3722 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
d601cd8d
JB
3723 ret = ieee80211_vif_use_channel(sdata, &chandef,
3724 IEEE80211_CHANCTX_SHARED);
3725 }
34a3740d
JB
3726 out:
3727 mutex_unlock(&local->mtx);
f2d9d270 3728 return ret;
b17166a7
JB
3729}
3730
3731static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3732 struct cfg80211_bss *cbss, bool assoc)
3733{
3734 struct ieee80211_local *local = sdata->local;
3735 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3736 struct ieee80211_bss *bss = (void *)cbss->priv;
3737 struct sta_info *new_sta = NULL;
3738 bool have_sta = false;
3739 int err;
3740
3741 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3742 return -EINVAL;
3743
3744 if (assoc) {
3745 rcu_read_lock();
3746 have_sta = sta_info_get(sdata, cbss->bssid);
3747 rcu_read_unlock();
3748 }
3749
3750 if (!have_sta) {
3751 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
3752 if (!new_sta)
3753 return -ENOMEM;
3754 }
13e0c8e3 3755 if (new_sta) {
5d6a1b06
JB
3756 u32 rates = 0, basic_rates = 0;
3757 bool have_higher_than_11mbit;
3758 int min_rate = INT_MAX, min_rate_index = -1;
2103dec1 3759 struct ieee80211_chanctx_conf *chanctx_conf;
b17166a7 3760 struct ieee80211_supported_band *sband;
8cef2c9d 3761 const struct cfg80211_bss_ies *ies;
2103dec1
SW
3762 int shift;
3763 u32 rate_flags;
b17166a7
JB
3764
3765 sband = local->hw.wiphy->bands[cbss->channel->band];
3766
3767 err = ieee80211_prep_channel(sdata, cbss);
3768 if (err) {
3769 sta_info_free(local, new_sta);
2103dec1 3770 return -EINVAL;
b17166a7 3771 }
2103dec1
SW
3772 shift = ieee80211_vif_get_shift(&sdata->vif);
3773
3774 rcu_read_lock();
3775 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3776 if (WARN_ON(!chanctx_conf)) {
3777 rcu_read_unlock();
c368ddaa 3778 sta_info_free(local, new_sta);
2103dec1
SW
3779 return -EINVAL;
3780 }
3781 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
3782 rcu_read_unlock();
5d6a1b06 3783
5d6a1b06
JB
3784 ieee80211_get_rates(sband, bss->supp_rates,
3785 bss->supp_rates_len,
3786 &rates, &basic_rates,
3787 &have_higher_than_11mbit,
2103dec1
SW
3788 &min_rate, &min_rate_index,
3789 shift, rate_flags);
5d6a1b06
JB
3790
3791 /*
3792 * This used to be a workaround for basic rates missing
3793 * in the association response frame. Now that we no
3794 * longer use the basic rates from there, it probably
3795 * doesn't happen any more, but keep the workaround so
3796 * in case some *other* APs are buggy in different ways
3797 * we can connect -- with a warning.
3798 */
3799 if (!basic_rates && min_rate_index >= 0) {
bdcbd8e0
JB
3800 sdata_info(sdata,
3801 "No basic rates, using min rate instead\n");
5d6a1b06
JB
3802 basic_rates = BIT(min_rate_index);
3803 }
3804
13e0c8e3 3805 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5d6a1b06
JB
3806 sdata->vif.bss_conf.basic_rates = basic_rates;
3807
3808 /* cf. IEEE 802.11 9.2.12 */
55de908a 3809 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
5d6a1b06
JB
3810 have_higher_than_11mbit)
3811 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3812 else
3813 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3814
3815 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3816
8c358bcd
JB
3817 /* set timing information */
3818 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
8cef2c9d 3819 rcu_read_lock();
ef429dad
JB
3820 ies = rcu_dereference(cbss->beacon_ies);
3821 if (ies) {
3822 const u8 *tim_ie;
3823
3824 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3825 sdata->vif.bss_conf.sync_device_ts =
3826 bss->device_ts_beacon;
3827 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
3828 ies->data, ies->len);
3829 if (tim_ie && tim_ie[1] >= 2)
3830 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
3831 else
3832 sdata->vif.bss_conf.sync_dtim_count = 0;
3833 } else if (!(local->hw.flags &
3834 IEEE80211_HW_TIMING_BEACON_ONLY)) {
3835 ies = rcu_dereference(cbss->proberesp_ies);
3836 /* must be non-NULL since beacon IEs were NULL */
3837 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3838 sdata->vif.bss_conf.sync_device_ts =
3839 bss->device_ts_presp;
3840 sdata->vif.bss_conf.sync_dtim_count = 0;
3841 } else {
3842 sdata->vif.bss_conf.sync_tsf = 0;
3843 sdata->vif.bss_conf.sync_device_ts = 0;
3844 sdata->vif.bss_conf.sync_dtim_count = 0;
3845 }
8cef2c9d 3846 rcu_read_unlock();
8c358bcd
JB
3847
3848 /* tell driver about BSSID, basic rates and timing */
5d6a1b06 3849 ieee80211_bss_info_change_notify(sdata,
8c358bcd
JB
3850 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
3851 BSS_CHANGED_BEACON_INT);
a1cf775d
JB
3852
3853 if (assoc)
13e0c8e3 3854 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
a1cf775d 3855
13e0c8e3
JB
3856 err = sta_info_insert(new_sta);
3857 new_sta = NULL;
a1cf775d 3858 if (err) {
bdcbd8e0
JB
3859 sdata_info(sdata,
3860 "failed to insert STA entry for the AP (error %d)\n",
3861 err);
a1cf775d
JB
3862 return err;
3863 }
3864 } else
b203ca39 3865 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
a1cf775d
JB
3866
3867 return 0;
3868}
3869
77fdaa12
JB
3870/* config hooks */
3871int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3872 struct cfg80211_auth_request *req)
9c6bd790 3873{
66e67e41
JB
3874 struct ieee80211_local *local = sdata->local;
3875 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3876 struct ieee80211_mgd_auth_data *auth_data;
77fdaa12 3877 u16 auth_alg;
66e67e41
JB
3878 int err;
3879
3880 /* prepare auth data structure */
9c6bd790 3881
77fdaa12
JB
3882 switch (req->auth_type) {
3883 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3884 auth_alg = WLAN_AUTH_OPEN;
3885 break;
3886 case NL80211_AUTHTYPE_SHARED_KEY:
66e67e41 3887 if (IS_ERR(local->wep_tx_tfm))
9dca9c49 3888 return -EOPNOTSUPP;
77fdaa12
JB
3889 auth_alg = WLAN_AUTH_SHARED_KEY;
3890 break;
3891 case NL80211_AUTHTYPE_FT:
3892 auth_alg = WLAN_AUTH_FT;
3893 break;
3894 case NL80211_AUTHTYPE_NETWORK_EAP:
3895 auth_alg = WLAN_AUTH_LEAP;
3896 break;
6b8ece3a
JM
3897 case NL80211_AUTHTYPE_SAE:
3898 auth_alg = WLAN_AUTH_SAE;
3899 break;
77fdaa12
JB
3900 default:
3901 return -EOPNOTSUPP;
60f8b39c 3902 }
77fdaa12 3903
6b8ece3a
JM
3904 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
3905 req->ie_len, GFP_KERNEL);
66e67e41 3906 if (!auth_data)
9c6bd790 3907 return -ENOMEM;
77fdaa12 3908
66e67e41 3909 auth_data->bss = req->bss;
77fdaa12 3910
6b8ece3a
JM
3911 if (req->sae_data_len >= 4) {
3912 __le16 *pos = (__le16 *) req->sae_data;
3913 auth_data->sae_trans = le16_to_cpu(pos[0]);
3914 auth_data->sae_status = le16_to_cpu(pos[1]);
3915 memcpy(auth_data->data, req->sae_data + 4,
3916 req->sae_data_len - 4);
3917 auth_data->data_len += req->sae_data_len - 4;
3918 }
3919
77fdaa12 3920 if (req->ie && req->ie_len) {
6b8ece3a
JM
3921 memcpy(&auth_data->data[auth_data->data_len],
3922 req->ie, req->ie_len);
3923 auth_data->data_len += req->ie_len;
9c6bd790 3924 }
77fdaa12 3925
fffd0934 3926 if (req->key && req->key_len) {
66e67e41
JB
3927 auth_data->key_len = req->key_len;
3928 auth_data->key_idx = req->key_idx;
3929 memcpy(auth_data->key, req->key, req->key_len);
fffd0934
JB
3930 }
3931
66e67e41 3932 auth_data->algorithm = auth_alg;
60f8b39c 3933
66e67e41 3934 /* try to authenticate/probe */
2a33bee2 3935
66e67e41
JB
3936 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
3937 ifmgd->assoc_data) {
3938 err = -EBUSY;
3939 goto err_free;
2a33bee2
GE
3940 }
3941
66e67e41
JB
3942 if (ifmgd->auth_data)
3943 ieee80211_destroy_auth_data(sdata, false);
2a33bee2 3944
66e67e41
JB
3945 /* prep auth_data so we don't go into idle on disassoc */
3946 ifmgd->auth_data = auth_data;
af6b6374 3947
7b119dc0
JB
3948 if (ifmgd->associated) {
3949 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3950
3951 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3952 WLAN_REASON_UNSPECIFIED,
3953 false, frame_buf);
3954
6ff57cf8
JB
3955 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
3956 sizeof(frame_buf));
7b119dc0 3957 }
af6b6374 3958
bdcbd8e0 3959 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
e5b900d2 3960
a1cf775d
JB
3961 err = ieee80211_prep_connection(sdata, req->bss, false);
3962 if (err)
66e67e41 3963 goto err_clear;
af6b6374 3964
66e67e41
JB
3965 err = ieee80211_probe_auth(sdata);
3966 if (err) {
66e67e41
JB
3967 sta_info_destroy_addr(sdata, req->bss->bssid);
3968 goto err_clear;
3969 }
3970
3971 /* hold our own reference */
5b112d3d 3972 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
8d61ffa5 3973 return 0;
66e67e41
JB
3974
3975 err_clear:
3d2abdfd
EP
3976 memset(ifmgd->bssid, 0, ETH_ALEN);
3977 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
66e67e41
JB
3978 ifmgd->auth_data = NULL;
3979 err_free:
3980 kfree(auth_data);
66e67e41 3981 return err;
af6b6374
JB
3982}
3983
095d81ce
JB
3984static bool ieee80211_usable_wmm_params(struct ieee80211_sub_if_data *sdata,
3985 const u8 *wmm_param, int len)
3986{
3987 const u8 *pos;
3988 size_t left;
3989
3990 if (len < 8)
3991 return false;
3992
3993 if (wmm_param[5] != 1 /* version */)
3994 return false;
3995
3996 pos = wmm_param + 8;
3997 left = len - 8;
3998
3999 for (; left >= 4; left -= 4, pos += 4) {
4000 u8 aifsn = pos[0] & 0x0f;
4001 u8 ecwmin = pos[1] & 0x0f;
4002 u8 ecwmax = (pos[1] & 0xf0) >> 4;
4003 int aci = (pos[0] >> 5) & 0x03;
4004
4005 if (aifsn < 2) {
4006 sdata_info(sdata,
4007 "AP has invalid WMM params (AIFSN=%d for ACI %d), disabling WMM\n",
4008 aifsn, aci);
4009 return false;
4010 }
4011 if (ecwmin > ecwmax) {
4012 sdata_info(sdata,
4013 "AP has invalid WMM params (ECWmin/max=%d/%d for ACI %d), disabling WMM\n",
4014 ecwmin, ecwmax, aci);
4015 return false;
4016 }
4017 }
4018
4019 return true;
4020}
4021
77fdaa12
JB
4022int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4023 struct cfg80211_assoc_request *req)
f0706e82 4024{
66e67e41 4025 struct ieee80211_local *local = sdata->local;
77fdaa12 4026 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
0c1ad2ca 4027 struct ieee80211_bss *bss = (void *)req->bss->priv;
66e67e41 4028 struct ieee80211_mgd_assoc_data *assoc_data;
c65dd147 4029 const struct cfg80211_bss_ies *beacon_ies;
4e74bfdb 4030 struct ieee80211_supported_band *sband;
b08fbbd8 4031 const u8 *ssidie, *ht_ie, *vht_ie;
2a33bee2 4032 int i, err;
f0706e82 4033
66e67e41
JB
4034 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
4035 if (!assoc_data)
4036 return -ENOMEM;
4037
9caf0364
JB
4038 rcu_read_lock();
4039 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4040 if (!ssidie) {
4041 rcu_read_unlock();
4042 kfree(assoc_data);
4043 return -EINVAL;
4044 }
4045 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
4046 assoc_data->ssid_len = ssidie[1];
4047 rcu_read_unlock();
4048
7b119dc0
JB
4049 if (ifmgd->associated) {
4050 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4051
4052 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4053 WLAN_REASON_UNSPECIFIED,
4054 false, frame_buf);
4055
6ff57cf8
JB
4056 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4057 sizeof(frame_buf));
7b119dc0 4058 }
66e67e41
JB
4059
4060 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
4061 err = -EBUSY;
4062 goto err_free;
af6b6374 4063 }
77fdaa12 4064
66e67e41
JB
4065 if (ifmgd->assoc_data) {
4066 err = -EBUSY;
4067 goto err_free;
4068 }
77fdaa12 4069
66e67e41
JB
4070 if (ifmgd->auth_data) {
4071 bool match;
4072
4073 /* keep sta info, bssid if matching */
b203ca39 4074 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
66e67e41 4075 ieee80211_destroy_auth_data(sdata, match);
2a33bee2
GE
4076 }
4077
66e67e41 4078 /* prepare assoc data */
095d81ce 4079
d8ec4433
JO
4080 ifmgd->beacon_crc_valid = false;
4081
095d81ce
JB
4082 assoc_data->wmm = bss->wmm_used &&
4083 (local->hw.queues >= IEEE80211_NUM_ACS);
4084 if (assoc_data->wmm) {
4085 /* try to check validity of WMM params IE */
4086 const struct cfg80211_bss_ies *ies;
4087 const u8 *wp, *start, *end;
4088
4089 rcu_read_lock();
4090 ies = rcu_dereference(req->bss->ies);
4091 start = ies->data;
4092 end = start + ies->len;
4093
4094 while (true) {
4095 wp = cfg80211_find_vendor_ie(
4096 WLAN_OUI_MICROSOFT,
4097 WLAN_OUI_TYPE_MICROSOFT_WMM,
4098 start, end - start);
4099 if (!wp)
4100 break;
4101 start = wp + wp[1] + 2;
4102 /* if this IE is too short, try the next */
4103 if (wp[1] <= 4)
4104 continue;
4105 /* if this IE is WMM params, we found what we wanted */
4106 if (wp[6] == 1)
4107 break;
4108 }
4109
4110 if (!wp || !ieee80211_usable_wmm_params(sdata, wp + 2,
4111 wp[1] - 2)) {
4112 assoc_data->wmm = false;
4113 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
4114 }
4115 rcu_read_unlock();
4116 }
4117
de5036aa
JB
4118 /*
4119 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4120 * We still associate in non-HT mode (11a/b/g) if any one of these
4121 * ciphers is configured as pairwise.
4122 * We can set this to true for non-11n hardware, that'll be checked
4123 * separately along with the peer capabilities.
4124 */
1c4cb928 4125 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
77fdaa12
JB
4126 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
4127 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
1c4cb928 4128 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
a8243b72 4129 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
d545daba 4130 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
1c4cb928 4131 netdev_info(sdata->dev,
d545daba 4132 "disabling HT/VHT due to WEP/TKIP use\n");
1c4cb928
JB
4133 }
4134 }
77fdaa12 4135
d545daba 4136 if (req->flags & ASSOC_REQ_DISABLE_HT) {
a8243b72 4137 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
d545daba
MP
4138 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4139 }
ef96a842 4140
dd5ecfea
JB
4141 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4142 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4143
4e74bfdb
JB
4144 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4145 sband = local->hw.wiphy->bands[req->bss->channel->band];
4146 if (!sband->ht_cap.ht_supported ||
095d81ce
JB
4147 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
4148 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
a8243b72 4149 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
095d81ce
JB
4150 if (!bss->wmm_used &&
4151 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
1b49de26
JB
4152 netdev_info(sdata->dev,
4153 "disabling HT as WMM/QoS is not supported by the AP\n");
1c4cb928 4154 }
4e74bfdb 4155
d545daba
MP
4156 /* disable VHT if we don't support it or the AP doesn't use WMM */
4157 if (!sband->vht_cap.vht_supported ||
095d81ce
JB
4158 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
4159 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
d545daba 4160 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
095d81ce
JB
4161 if (!bss->wmm_used &&
4162 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
1b49de26
JB
4163 netdev_info(sdata->dev,
4164 "disabling VHT as WMM/QoS is not supported by the AP\n");
d545daba
MP
4165 }
4166
ef96a842
BG
4167 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
4168 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4169 sizeof(ifmgd->ht_capa_mask));
4170
dd5ecfea
JB
4171 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4172 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4173 sizeof(ifmgd->vht_capa_mask));
4174
77fdaa12 4175 if (req->ie && req->ie_len) {
66e67e41
JB
4176 memcpy(assoc_data->ie, req->ie, req->ie_len);
4177 assoc_data->ie_len = req->ie_len;
4178 }
f679f65d 4179
66e67e41 4180 assoc_data->bss = req->bss;
f679f65d 4181
af6b6374
JB
4182 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
4183 if (ifmgd->powersave)
04ecd257 4184 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
af6b6374 4185 else
04ecd257 4186 sdata->smps_mode = IEEE80211_SMPS_OFF;
af6b6374 4187 } else
04ecd257 4188 sdata->smps_mode = ifmgd->req_smps;
af6b6374 4189
66e67e41 4190 assoc_data->capability = req->bss->capability;
66e67e41
JB
4191 assoc_data->supp_rates = bss->supp_rates;
4192 assoc_data->supp_rates_len = bss->supp_rates_len;
9dde6423 4193
9caf0364 4194 rcu_read_lock();
9dde6423
JB
4195 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
4196 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
4197 assoc_data->ap_ht_param =
4198 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
4199 else
a8243b72 4200 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
b08fbbd8
JB
4201 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
4202 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
4203 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
4204 sizeof(struct ieee80211_vht_cap));
4205 else
4206 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
9caf0364 4207 rcu_read_unlock();
63f170e0 4208
ab13315a 4209 if (bss->wmm_used && bss->uapsd_supported &&
24aa11ab
AB
4210 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) &&
4211 sdata->wmm_acm != 0xff) {
76f0303d 4212 assoc_data->uapsd = true;
ab13315a
KV
4213 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4214 } else {
76f0303d 4215 assoc_data->uapsd = false;
ab13315a
KV
4216 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
4217 }
4218
77fdaa12 4219 if (req->prev_bssid)
66e67e41 4220 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
77fdaa12
JB
4221
4222 if (req->use_mfp) {
4223 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
4224 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4225 } else {
4226 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4227 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4228 }
4229
4230 if (req->crypto.control_port)
4231 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4232 else
4233 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4234
a621fa4d
JB
4235 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4236 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
2475b1cc
MS
4237 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
4238 sdata->vif.type);
a621fa4d 4239
66e67e41
JB
4240 /* kick off associate process */
4241
4242 ifmgd->assoc_data = assoc_data;
826262c3 4243 ifmgd->dtim_period = 0;
989c6505 4244 ifmgd->have_beacon = false;
66e67e41 4245
a1cf775d
JB
4246 err = ieee80211_prep_connection(sdata, req->bss, true);
4247 if (err)
4248 goto err_clear;
66e67e41 4249
c65dd147
EG
4250 rcu_read_lock();
4251 beacon_ies = rcu_dereference(req->bss->beacon_ies);
826262c3 4252
c65dd147
EG
4253 if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
4254 !beacon_ies) {
4255 /*
4256 * Wait up to one beacon interval ...
4257 * should this be more if we miss one?
4258 */
4259 sdata_info(sdata, "waiting for beacon from %pM\n",
4260 ifmgd->bssid);
4261 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
89afe614 4262 assoc_data->timeout_started = true;
c65dd147
EG
4263 assoc_data->need_beacon = true;
4264 } else if (beacon_ies) {
4265 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4266 beacon_ies->data,
4267 beacon_ies->len);
ef429dad
JB
4268 u8 dtim_count = 0;
4269
c65dd147
EG
4270 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
4271 const struct ieee80211_tim_ie *tim;
4272 tim = (void *)(tim_ie + 2);
4273 ifmgd->dtim_period = tim->dtim_period;
ef429dad 4274 dtim_count = tim->dtim_count;
826262c3 4275 }
989c6505 4276 ifmgd->have_beacon = true;
66e67e41 4277 assoc_data->timeout = jiffies;
89afe614 4278 assoc_data->timeout_started = true;
ef429dad
JB
4279
4280 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
4281 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
4282 sdata->vif.bss_conf.sync_device_ts =
4283 bss->device_ts_beacon;
4284 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
4285 }
c65dd147
EG
4286 } else {
4287 assoc_data->timeout = jiffies;
89afe614 4288 assoc_data->timeout_started = true;
66e67e41 4289 }
c65dd147
EG
4290 rcu_read_unlock();
4291
8d61ffa5 4292 run_again(sdata, assoc_data->timeout);
66e67e41 4293
fcff4f10
PS
4294 if (bss->corrupt_data) {
4295 char *corrupt_type = "data";
4296 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
4297 if (bss->corrupt_data &
4298 IEEE80211_BSS_CORRUPT_PROBE_RESP)
4299 corrupt_type = "beacon and probe response";
4300 else
4301 corrupt_type = "beacon";
4302 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
4303 corrupt_type = "probe response";
bdcbd8e0
JB
4304 sdata_info(sdata, "associating with AP with corrupt %s\n",
4305 corrupt_type);
fcff4f10
PS
4306 }
4307
8d61ffa5 4308 return 0;
66e67e41 4309 err_clear:
3d2abdfd
EP
4310 memset(ifmgd->bssid, 0, ETH_ALEN);
4311 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
66e67e41
JB
4312 ifmgd->assoc_data = NULL;
4313 err_free:
4314 kfree(assoc_data);
66e67e41 4315 return err;
f0706e82
JB
4316}
4317
77fdaa12 4318int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
63c9c5e7 4319 struct cfg80211_deauth_request *req)
f0706e82 4320{
46900298 4321 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6ae16775 4322 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6863255b 4323 bool tx = !req->local_state_change;
de3d43a3 4324 bool report_frame = false;
f0706e82 4325
bdcbd8e0
JB
4326 sdata_info(sdata,
4327 "deauthenticating from %pM by local choice (reason=%d)\n",
4328 req->bssid, req->reason_code);
0ff71613 4329
86552017 4330 if (ifmgd->auth_data) {
8c7d857c 4331 drv_mgd_prepare_tx(sdata->local, sdata);
37ad3888
JB
4332 ieee80211_send_deauth_disassoc(sdata, req->bssid,
4333 IEEE80211_STYPE_DEAUTH,
6863255b 4334 req->reason_code, tx,
37ad3888 4335 frame_buf);
86552017 4336 ieee80211_destroy_auth_data(sdata, false);
86552017 4337
de3d43a3 4338 report_frame = true;
86552017 4339 goto out;
8c7d857c
EG
4340 }
4341
86552017
JB
4342 if (ifmgd->associated &&
4343 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
4344 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4345 req->reason_code, tx, frame_buf);
de3d43a3 4346 report_frame = true;
86552017 4347 }
37ad3888 4348
86552017 4349 out:
de3d43a3 4350 if (report_frame)
6ff57cf8
JB
4351 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4352 IEEE80211_DEAUTH_FRAME_LEN);
86552017 4353
f0706e82
JB
4354 return 0;
4355}
84363e6e 4356
77fdaa12 4357int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
63c9c5e7 4358 struct cfg80211_disassoc_request *req)
9c6bd790 4359{
77fdaa12 4360 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
e69e95db 4361 u8 bssid[ETH_ALEN];
6ae16775 4362 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
9c6bd790 4363
8d8b261a
JB
4364 /*
4365 * cfg80211 should catch this ... but it's racy since
4366 * we can receive a disassoc frame, process it, hand it
4367 * to cfg80211 while that's in a locked section already
4368 * trying to tell us that the user wants to disconnect.
4369 */
8d61ffa5 4370 if (ifmgd->associated != req->bss)
77fdaa12 4371 return -ENOLINK;
77fdaa12 4372
bdcbd8e0
JB
4373 sdata_info(sdata,
4374 "disassociating from %pM by local choice (reason=%d)\n",
4375 req->bss->bssid, req->reason_code);
0ff71613 4376
e69e95db 4377 memcpy(bssid, req->bss->bssid, ETH_ALEN);
37ad3888
JB
4378 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
4379 req->reason_code, !req->local_state_change,
4380 frame_buf);
10f644a4 4381
6ff57cf8
JB
4382 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4383 IEEE80211_DEAUTH_FRAME_LEN);
bc83b681 4384
10f644a4
JB
4385 return 0;
4386}
026331c4 4387
afa762f6 4388void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
54e4ffb2
JB
4389{
4390 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4391
49921859
BG
4392 /*
4393 * Make sure some work items will not run after this,
4394 * they will not do anything but might not have been
4395 * cancelled when disconnecting.
4396 */
4397 cancel_work_sync(&ifmgd->monitor_work);
4398 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
4399 cancel_work_sync(&ifmgd->request_smps_work);
4400 cancel_work_sync(&ifmgd->csa_connection_drop_work);
4401 cancel_work_sync(&ifmgd->chswitch_work);
4402
8d61ffa5 4403 sdata_lock(sdata);
959867fa
JB
4404 if (ifmgd->assoc_data) {
4405 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
54e4ffb2 4406 ieee80211_destroy_assoc_data(sdata, false);
959867fa
JB
4407 cfg80211_assoc_timeout(sdata->dev, bss);
4408 }
54e4ffb2
JB
4409 if (ifmgd->auth_data)
4410 ieee80211_destroy_auth_data(sdata, false);
4411 del_timer_sync(&ifmgd->timer);
8d61ffa5 4412 sdata_unlock(sdata);
54e4ffb2
JB
4413}
4414
a97c13c3
JO
4415void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
4416 enum nl80211_cqm_rssi_threshold_event rssi_event,
4417 gfp_t gfp)
4418{
4419 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4420
b5878a2d
JB
4421 trace_api_cqm_rssi_notify(sdata, rssi_event);
4422
a97c13c3
JO
4423 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
4424}
4425EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
This page took 1.048557 seconds and 5 git commands to generate.