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