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