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