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