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