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