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