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