Commit | Line | Data |
---|---|---|
f0706e82 JB |
1 | /* |
2 | * BSS client mode implementation | |
5394af4d | 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
f0706e82 JB |
4 | * Copyright 2004, Instant802 Networks, Inc. |
5 | * Copyright 2005, Devicescape Software, Inc. | |
6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> | |
7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
5b323edb | 14 | #include <linux/delay.h> |
f0706e82 JB |
15 | #include <linux/if_ether.h> |
16 | #include <linux/skbuff.h> | |
f0706e82 | 17 | #include <linux/if_arp.h> |
f0706e82 | 18 | #include <linux/etherdevice.h> |
d9b93842 | 19 | #include <linux/moduleparam.h> |
d0709a65 | 20 | #include <linux/rtnetlink.h> |
e8db0be1 | 21 | #include <linux/pm_qos.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" | |
f0706e82 | 32 | |
66e67e41 JB |
33 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
34 | #define IEEE80211_AUTH_MAX_TRIES 3 | |
35 | #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5) | |
36 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) | |
37 | #define IEEE80211_ASSOC_MAX_TRIES 3 | |
38 | ||
180205bd BG |
39 | static int max_nullfunc_tries = 2; |
40 | module_param(max_nullfunc_tries, int, 0644); | |
41 | MODULE_PARM_DESC(max_nullfunc_tries, | |
42 | "Maximum nullfunc tx tries before disconnecting (reason 4)."); | |
43 | ||
44 | static int max_probe_tries = 5; | |
45 | module_param(max_probe_tries, int, 0644); | |
46 | MODULE_PARM_DESC(max_probe_tries, | |
47 | "Maximum probe tries before disconnecting (reason 4)."); | |
b291ba11 JB |
48 | |
49 | /* | |
7ccc8bd7 FF |
50 | * Beacon loss timeout is calculated as N frames times the |
51 | * advertised beacon interval. This may need to be somewhat | |
52 | * higher than what hardware might detect to account for | |
53 | * delays in the host processing frames. But since we also | |
54 | * probe on beacon miss before declaring the connection lost | |
55 | * default to what we want. | |
b291ba11 | 56 | */ |
7ccc8bd7 FF |
57 | #define IEEE80211_BEACON_LOSS_COUNT 7 |
58 | ||
b291ba11 JB |
59 | /* |
60 | * Time the connection can be idle before we probe | |
61 | * it to see if we can still talk to the AP. | |
62 | */ | |
d1c5091f | 63 | #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) |
b291ba11 JB |
64 | /* |
65 | * Time we wait for a probe response after sending | |
66 | * a probe request because of beacon loss or for | |
67 | * checking the connection still works. | |
68 | */ | |
180205bd BG |
69 | static int probe_wait_ms = 500; |
70 | module_param(probe_wait_ms, int, 0644); | |
71 | MODULE_PARM_DESC(probe_wait_ms, | |
72 | "Maximum time(ms) to wait for probe response" | |
73 | " before disconnecting (reason 4)."); | |
f0706e82 | 74 | |
17e4ec14 JM |
75 | /* |
76 | * Weight given to the latest Beacon frame when calculating average signal | |
77 | * strength for Beacon frames received in the current BSS. This must be | |
78 | * between 1 and 15. | |
79 | */ | |
80 | #define IEEE80211_SIGNAL_AVE_WEIGHT 3 | |
81 | ||
391a200a JM |
82 | /* |
83 | * How many Beacon frames need to have been used in average signal strength | |
84 | * before starting to indicate signal change events. | |
85 | */ | |
86 | #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 | |
87 | ||
5bb644a0 JB |
88 | #define TMR_RUNNING_TIMER 0 |
89 | #define TMR_RUNNING_CHANSW 1 | |
90 | ||
77fdaa12 JB |
91 | /* |
92 | * All cfg80211 functions have to be called outside a locked | |
93 | * section so that they can acquire a lock themselves... This | |
94 | * is much simpler than queuing up things in cfg80211, but we | |
95 | * do need some indirection for that here. | |
96 | */ | |
97 | enum rx_mgmt_action { | |
98 | /* no action required */ | |
99 | RX_MGMT_NONE, | |
100 | ||
77fdaa12 JB |
101 | /* caller must call cfg80211_send_deauth() */ |
102 | RX_MGMT_CFG80211_DEAUTH, | |
103 | ||
104 | /* caller must call cfg80211_send_disassoc() */ | |
105 | RX_MGMT_CFG80211_DISASSOC, | |
66e67e41 JB |
106 | |
107 | /* caller must call cfg80211_send_rx_auth() */ | |
108 | RX_MGMT_CFG80211_RX_AUTH, | |
109 | ||
110 | /* caller must call cfg80211_send_rx_assoc() */ | |
111 | RX_MGMT_CFG80211_RX_ASSOC, | |
112 | ||
113 | /* caller must call cfg80211_send_assoc_timeout() */ | |
114 | RX_MGMT_CFG80211_ASSOC_TIMEOUT, | |
77fdaa12 JB |
115 | }; |
116 | ||
5484e237 | 117 | /* utils */ |
77fdaa12 JB |
118 | static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd) |
119 | { | |
46a5ebaf | 120 | lockdep_assert_held(&ifmgd->mtx); |
77fdaa12 JB |
121 | } |
122 | ||
ca386f31 JB |
123 | /* |
124 | * We can have multiple work items (and connection probing) | |
125 | * scheduling this timer, but we need to take care to only | |
126 | * reschedule it when it should fire _earlier_ than it was | |
127 | * asked for before, or if it's not pending right now. This | |
128 | * function ensures that. Note that it then is required to | |
129 | * run this function for all timeouts after the first one | |
130 | * has happened -- the work that runs from this timer will | |
131 | * do that. | |
132 | */ | |
66e67e41 | 133 | static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout) |
ca386f31 JB |
134 | { |
135 | ASSERT_MGD_MTX(ifmgd); | |
136 | ||
137 | if (!timer_pending(&ifmgd->timer) || | |
138 | time_before(timeout, ifmgd->timer.expires)) | |
139 | mod_timer(&ifmgd->timer, timeout); | |
140 | } | |
141 | ||
d3a910a8 | 142 | void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) |
b291ba11 | 143 | { |
c1288b12 | 144 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
b291ba11 JB |
145 | return; |
146 | ||
7eeff74c JB |
147 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
148 | return; | |
149 | ||
b291ba11 | 150 | mod_timer(&sdata->u.mgd.bcn_mon_timer, |
7ccc8bd7 | 151 | round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); |
b291ba11 JB |
152 | } |
153 | ||
be099e82 LR |
154 | void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) |
155 | { | |
0c699c3a LR |
156 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
157 | ||
8628172f SG |
158 | if (unlikely(!sdata->u.mgd.associated)) |
159 | return; | |
160 | ||
be099e82 LR |
161 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
162 | return; | |
163 | ||
164 | mod_timer(&sdata->u.mgd.conn_mon_timer, | |
165 | round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); | |
0c699c3a LR |
166 | |
167 | ifmgd->probe_send_count = 0; | |
be099e82 LR |
168 | } |
169 | ||
5484e237 | 170 | static int ecw2cw(int ecw) |
60f8b39c | 171 | { |
5484e237 | 172 | return (1 << ecw) - 1; |
60f8b39c JB |
173 | } |
174 | ||
24398e39 JB |
175 | static u32 ieee80211_config_ht_tx(struct ieee80211_sub_if_data *sdata, |
176 | struct ieee80211_ht_operation *ht_oper, | |
177 | const u8 *bssid, bool reconfig) | |
d5522e03 JB |
178 | { |
179 | struct ieee80211_local *local = sdata->local; | |
180 | struct ieee80211_supported_band *sband; | |
55de908a JB |
181 | struct ieee80211_chanctx_conf *chanctx_conf; |
182 | struct ieee80211_channel *chan; | |
d5522e03 JB |
183 | struct sta_info *sta; |
184 | u32 changed = 0; | |
9ed6bcce | 185 | u16 ht_opmode; |
64f68e5d | 186 | bool disable_40 = false; |
d5522e03 | 187 | |
55de908a JB |
188 | rcu_read_lock(); |
189 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
190 | if (WARN_ON(!chanctx_conf)) { | |
191 | rcu_read_unlock(); | |
192 | return 0; | |
193 | } | |
4bf88530 | 194 | chan = chanctx_conf->def.chan; |
55de908a JB |
195 | rcu_read_unlock(); |
196 | sband = local->hw.wiphy->bands[chan->band]; | |
d5522e03 | 197 | |
4bf88530 JB |
198 | switch (sdata->vif.bss_conf.chandef.width) { |
199 | case NL80211_CHAN_WIDTH_40: | |
200 | if (sdata->vif.bss_conf.chandef.chan->center_freq > | |
201 | sdata->vif.bss_conf.chandef.center_freq1 && | |
202 | chan->flags & IEEE80211_CHAN_NO_HT40PLUS) | |
64f68e5d | 203 | disable_40 = true; |
4bf88530 JB |
204 | if (sdata->vif.bss_conf.chandef.chan->center_freq < |
205 | sdata->vif.bss_conf.chandef.center_freq1 && | |
206 | chan->flags & IEEE80211_CHAN_NO_HT40MINUS) | |
64f68e5d JB |
207 | disable_40 = true; |
208 | break; | |
209 | default: | |
210 | break; | |
211 | } | |
d5522e03 | 212 | |
24398e39 JB |
213 | /* This can change during the lifetime of the BSS */ |
214 | if (!(ht_oper->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) | |
64f68e5d JB |
215 | disable_40 = true; |
216 | ||
217 | mutex_lock(&local->sta_mtx); | |
218 | sta = sta_info_get(sdata, bssid); | |
d5522e03 | 219 | |
64f68e5d JB |
220 | WARN_ON_ONCE(!sta); |
221 | ||
222 | if (sta && !sta->supports_40mhz) | |
223 | disable_40 = true; | |
224 | ||
225 | if (sta && (!reconfig || | |
91a0099c | 226 | (disable_40 != !(sta->sta.ht_cap.cap & |
64f68e5d | 227 | IEEE80211_HT_CAP_SUP_WIDTH_20_40)))) { |
d5522e03 | 228 | |
64f68e5d JB |
229 | if (disable_40) |
230 | sta->sta.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
231 | else | |
232 | sta->sta.ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
7cc44ed4 | 233 | |
64f68e5d | 234 | rate_control_rate_update(local, sband, sta, |
8f727ef3 | 235 | IEEE80211_RC_BW_CHANGED); |
0aaffa9b | 236 | } |
64f68e5d | 237 | mutex_unlock(&local->sta_mtx); |
d5522e03 | 238 | |
074d46d1 | 239 | ht_opmode = le16_to_cpu(ht_oper->operation_mode); |
d5522e03 JB |
240 | |
241 | /* if bss configuration changed store the new one */ | |
24398e39 | 242 | if (!reconfig || (sdata->vif.bss_conf.ht_operation_mode != ht_opmode)) { |
d5522e03 | 243 | changed |= BSS_CHANGED_HT; |
9ed6bcce | 244 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
d5522e03 JB |
245 | } |
246 | ||
247 | return changed; | |
248 | } | |
249 | ||
9c6bd790 JB |
250 | /* frame sending functions */ |
251 | ||
66e67e41 JB |
252 | static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len, |
253 | struct ieee80211_supported_band *sband, | |
254 | u32 *rates) | |
255 | { | |
256 | int i, j, count; | |
257 | *rates = 0; | |
258 | count = 0; | |
259 | for (i = 0; i < supp_rates_len; i++) { | |
260 | int rate = (supp_rates[i] & 0x7F) * 5; | |
261 | ||
262 | for (j = 0; j < sband->n_bitrates; j++) | |
263 | if (sband->bitrates[j].bitrate == rate) { | |
264 | *rates |= BIT(j); | |
265 | count++; | |
266 | break; | |
267 | } | |
268 | } | |
269 | ||
270 | return count; | |
271 | } | |
272 | ||
273 | static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, | |
9dde6423 | 274 | struct sk_buff *skb, u8 ap_ht_param, |
66e67e41 JB |
275 | struct ieee80211_supported_band *sband, |
276 | struct ieee80211_channel *channel, | |
277 | enum ieee80211_smps_mode smps) | |
278 | { | |
66e67e41 JB |
279 | u8 *pos; |
280 | u32 flags = channel->flags; | |
281 | u16 cap; | |
282 | struct ieee80211_sta_ht_cap ht_cap; | |
283 | ||
284 | BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); | |
285 | ||
66e67e41 JB |
286 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
287 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); | |
288 | ||
66e67e41 JB |
289 | /* determine capability flags */ |
290 | cap = ht_cap.cap; | |
291 | ||
9dde6423 | 292 | switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
66e67e41 JB |
293 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
294 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { | |
295 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
296 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
297 | } | |
298 | break; | |
299 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
300 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { | |
301 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
302 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
303 | } | |
304 | break; | |
305 | } | |
306 | ||
24398e39 JB |
307 | /* |
308 | * If 40 MHz was disabled associate as though we weren't | |
309 | * capable of 40 MHz -- some broken APs will never fall | |
310 | * back to trying to transmit in 20 MHz. | |
311 | */ | |
312 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) { | |
313 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
314 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
315 | } | |
316 | ||
66e67e41 JB |
317 | /* set SM PS mode properly */ |
318 | cap &= ~IEEE80211_HT_CAP_SM_PS; | |
319 | switch (smps) { | |
320 | case IEEE80211_SMPS_AUTOMATIC: | |
321 | case IEEE80211_SMPS_NUM_MODES: | |
322 | WARN_ON(1); | |
323 | case IEEE80211_SMPS_OFF: | |
324 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << | |
325 | IEEE80211_HT_CAP_SM_PS_SHIFT; | |
326 | break; | |
327 | case IEEE80211_SMPS_STATIC: | |
328 | cap |= WLAN_HT_CAP_SM_PS_STATIC << | |
329 | IEEE80211_HT_CAP_SM_PS_SHIFT; | |
330 | break; | |
331 | case IEEE80211_SMPS_DYNAMIC: | |
332 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << | |
333 | IEEE80211_HT_CAP_SM_PS_SHIFT; | |
334 | break; | |
335 | } | |
336 | ||
337 | /* reserve and fill IE */ | |
338 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); | |
339 | ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); | |
340 | } | |
341 | ||
d545daba MP |
342 | static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, |
343 | struct sk_buff *skb, | |
344 | struct ieee80211_supported_band *sband) | |
345 | { | |
346 | u8 *pos; | |
347 | u32 cap; | |
348 | struct ieee80211_sta_vht_cap vht_cap; | |
349 | ||
350 | BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); | |
351 | ||
352 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); | |
353 | ||
354 | /* determine capability flags */ | |
355 | cap = vht_cap.cap; | |
356 | ||
357 | /* reserve and fill IE */ | |
d4950281 | 358 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
d545daba MP |
359 | ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); |
360 | } | |
361 | ||
66e67e41 JB |
362 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
363 | { | |
364 | struct ieee80211_local *local = sdata->local; | |
365 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
366 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; | |
367 | struct sk_buff *skb; | |
368 | struct ieee80211_mgmt *mgmt; | |
369 | u8 *pos, qos_info; | |
370 | size_t offset = 0, noffset; | |
371 | int i, count, rates_len, supp_rates_len; | |
372 | u16 capab; | |
373 | struct ieee80211_supported_band *sband; | |
55de908a JB |
374 | struct ieee80211_chanctx_conf *chanctx_conf; |
375 | struct ieee80211_channel *chan; | |
66e67e41 | 376 | u32 rates = 0; |
66e67e41 JB |
377 | |
378 | lockdep_assert_held(&ifmgd->mtx); | |
379 | ||
55de908a JB |
380 | rcu_read_lock(); |
381 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
382 | if (WARN_ON(!chanctx_conf)) { | |
383 | rcu_read_unlock(); | |
384 | return; | |
385 | } | |
4bf88530 | 386 | chan = chanctx_conf->def.chan; |
55de908a JB |
387 | rcu_read_unlock(); |
388 | sband = local->hw.wiphy->bands[chan->band]; | |
66e67e41 JB |
389 | |
390 | if (assoc_data->supp_rates_len) { | |
391 | /* | |
392 | * Get all rates supported by the device and the AP as | |
393 | * some APs don't like getting a superset of their rates | |
394 | * in the association request (e.g. D-Link DAP 1353 in | |
395 | * b-only mode)... | |
396 | */ | |
397 | rates_len = ieee80211_compatible_rates(assoc_data->supp_rates, | |
398 | assoc_data->supp_rates_len, | |
399 | sband, &rates); | |
400 | } else { | |
401 | /* | |
402 | * In case AP not provide any supported rates information | |
403 | * before association, we send information element(s) with | |
404 | * all rates that we support. | |
405 | */ | |
406 | rates = ~0; | |
407 | rates_len = sband->n_bitrates; | |
408 | } | |
409 | ||
410 | skb = alloc_skb(local->hw.extra_tx_headroom + | |
411 | sizeof(*mgmt) + /* bit too much but doesn't matter */ | |
412 | 2 + assoc_data->ssid_len + /* SSID */ | |
413 | 4 + rates_len + /* (extended) rates */ | |
414 | 4 + /* power capability */ | |
415 | 2 + 2 * sband->n_channels + /* supported channels */ | |
416 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ | |
d4950281 | 417 | 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */ |
66e67e41 JB |
418 | assoc_data->ie_len + /* extra IEs */ |
419 | 9, /* WMM */ | |
420 | GFP_KERNEL); | |
421 | if (!skb) | |
422 | return; | |
423 | ||
424 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
425 | ||
426 | capab = WLAN_CAPABILITY_ESS; | |
427 | ||
428 | if (sband->band == IEEE80211_BAND_2GHZ) { | |
429 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) | |
430 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; | |
431 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) | |
432 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
433 | } | |
434 | ||
435 | if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY) | |
436 | capab |= WLAN_CAPABILITY_PRIVACY; | |
437 | ||
438 | if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && | |
439 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) | |
440 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; | |
441 | ||
442 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
443 | memset(mgmt, 0, 24); | |
444 | memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN); | |
445 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); | |
446 | memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN); | |
447 | ||
448 | if (!is_zero_ether_addr(assoc_data->prev_bssid)) { | |
449 | skb_put(skb, 10); | |
450 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
451 | IEEE80211_STYPE_REASSOC_REQ); | |
452 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); | |
453 | mgmt->u.reassoc_req.listen_interval = | |
454 | cpu_to_le16(local->hw.conf.listen_interval); | |
455 | memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid, | |
456 | ETH_ALEN); | |
457 | } else { | |
458 | skb_put(skb, 4); | |
459 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
460 | IEEE80211_STYPE_ASSOC_REQ); | |
461 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); | |
462 | mgmt->u.assoc_req.listen_interval = | |
463 | cpu_to_le16(local->hw.conf.listen_interval); | |
464 | } | |
465 | ||
466 | /* SSID */ | |
467 | pos = skb_put(skb, 2 + assoc_data->ssid_len); | |
468 | *pos++ = WLAN_EID_SSID; | |
469 | *pos++ = assoc_data->ssid_len; | |
470 | memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); | |
471 | ||
472 | /* add all rates which were marked to be used above */ | |
473 | supp_rates_len = rates_len; | |
474 | if (supp_rates_len > 8) | |
475 | supp_rates_len = 8; | |
476 | ||
477 | pos = skb_put(skb, supp_rates_len + 2); | |
478 | *pos++ = WLAN_EID_SUPP_RATES; | |
479 | *pos++ = supp_rates_len; | |
480 | ||
481 | count = 0; | |
482 | for (i = 0; i < sband->n_bitrates; i++) { | |
483 | if (BIT(i) & rates) { | |
484 | int rate = sband->bitrates[i].bitrate; | |
485 | *pos++ = (u8) (rate / 5); | |
486 | if (++count == 8) | |
487 | break; | |
488 | } | |
489 | } | |
490 | ||
491 | if (rates_len > count) { | |
492 | pos = skb_put(skb, rates_len - count + 2); | |
493 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
494 | *pos++ = rates_len - count; | |
495 | ||
496 | for (i++; i < sband->n_bitrates; i++) { | |
497 | if (BIT(i) & rates) { | |
498 | int rate = sband->bitrates[i].bitrate; | |
499 | *pos++ = (u8) (rate / 5); | |
500 | } | |
501 | } | |
502 | } | |
503 | ||
504 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { | |
505 | /* 1. power capabilities */ | |
506 | pos = skb_put(skb, 4); | |
507 | *pos++ = WLAN_EID_PWR_CAPABILITY; | |
508 | *pos++ = 2; | |
509 | *pos++ = 0; /* min tx power */ | |
55de908a | 510 | *pos++ = chan->max_power; /* max tx power */ |
66e67e41 JB |
511 | |
512 | /* 2. supported channels */ | |
513 | /* TODO: get this in reg domain format */ | |
514 | pos = skb_put(skb, 2 * sband->n_channels + 2); | |
515 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; | |
516 | *pos++ = 2 * sband->n_channels; | |
517 | for (i = 0; i < sband->n_channels; i++) { | |
518 | *pos++ = ieee80211_frequency_to_channel( | |
519 | sband->channels[i].center_freq); | |
520 | *pos++ = 1; /* one channel in the subband*/ | |
521 | } | |
522 | } | |
523 | ||
524 | /* if present, add any custom IEs that go before HT */ | |
525 | if (assoc_data->ie_len && assoc_data->ie) { | |
526 | static const u8 before_ht[] = { | |
527 | WLAN_EID_SSID, | |
528 | WLAN_EID_SUPP_RATES, | |
529 | WLAN_EID_EXT_SUPP_RATES, | |
530 | WLAN_EID_PWR_CAPABILITY, | |
531 | WLAN_EID_SUPPORTED_CHANNELS, | |
532 | WLAN_EID_RSN, | |
533 | WLAN_EID_QOS_CAPA, | |
534 | WLAN_EID_RRM_ENABLED_CAPABILITIES, | |
535 | WLAN_EID_MOBILITY_DOMAIN, | |
536 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, | |
537 | }; | |
538 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, | |
539 | before_ht, ARRAY_SIZE(before_ht), | |
540 | offset); | |
541 | pos = skb_put(skb, noffset - offset); | |
542 | memcpy(pos, assoc_data->ie + offset, noffset - offset); | |
543 | offset = noffset; | |
544 | } | |
545 | ||
a8243b72 | 546 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
9dde6423 | 547 | ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, |
04ecd257 | 548 | sband, chan, sdata->smps_mode); |
66e67e41 | 549 | |
d545daba MP |
550 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
551 | ieee80211_add_vht_ie(sdata, skb, sband); | |
552 | ||
66e67e41 JB |
553 | /* if present, add any custom non-vendor IEs that go after HT */ |
554 | if (assoc_data->ie_len && assoc_data->ie) { | |
555 | noffset = ieee80211_ie_split_vendor(assoc_data->ie, | |
556 | assoc_data->ie_len, | |
557 | offset); | |
558 | pos = skb_put(skb, noffset - offset); | |
559 | memcpy(pos, assoc_data->ie + offset, noffset - offset); | |
560 | offset = noffset; | |
561 | } | |
562 | ||
76f0303d JB |
563 | if (assoc_data->wmm) { |
564 | if (assoc_data->uapsd) { | |
dc41e4d4 EP |
565 | qos_info = ifmgd->uapsd_queues; |
566 | qos_info |= (ifmgd->uapsd_max_sp_len << | |
66e67e41 JB |
567 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
568 | } else { | |
569 | qos_info = 0; | |
570 | } | |
571 | ||
572 | pos = skb_put(skb, 9); | |
573 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; | |
574 | *pos++ = 7; /* len */ | |
575 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ | |
576 | *pos++ = 0x50; | |
577 | *pos++ = 0xf2; | |
578 | *pos++ = 2; /* WME */ | |
579 | *pos++ = 0; /* WME info */ | |
580 | *pos++ = 1; /* WME ver */ | |
581 | *pos++ = qos_info; | |
582 | } | |
583 | ||
584 | /* add any remaining custom (i.e. vendor specific here) IEs */ | |
585 | if (assoc_data->ie_len && assoc_data->ie) { | |
586 | noffset = assoc_data->ie_len; | |
587 | pos = skb_put(skb, noffset - offset); | |
588 | memcpy(pos, assoc_data->ie + offset, noffset - offset); | |
589 | } | |
590 | ||
a1845fc7 JB |
591 | drv_mgd_prepare_tx(local, sdata); |
592 | ||
66e67e41 JB |
593 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
594 | ieee80211_tx_skb(sdata, skb); | |
595 | } | |
596 | ||
572e0012 KV |
597 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
598 | struct ieee80211_sub_if_data *sdata) | |
599 | { | |
572e0012 KV |
600 | struct ieee80211_pspoll *pspoll; |
601 | struct sk_buff *skb; | |
572e0012 | 602 | |
d8cd189e KV |
603 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
604 | if (!skb) | |
572e0012 | 605 | return; |
572e0012 | 606 | |
d8cd189e KV |
607 | pspoll = (struct ieee80211_pspoll *) skb->data; |
608 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | |
572e0012 | 609 | |
62ae67be JB |
610 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
611 | ieee80211_tx_skb(sdata, skb); | |
572e0012 KV |
612 | } |
613 | ||
965bedad JB |
614 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
615 | struct ieee80211_sub_if_data *sdata, | |
616 | int powersave) | |
617 | { | |
618 | struct sk_buff *skb; | |
d8cd189e | 619 | struct ieee80211_hdr_3addr *nullfunc; |
b6f35301 | 620 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
965bedad | 621 | |
d8cd189e KV |
622 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif); |
623 | if (!skb) | |
965bedad | 624 | return; |
965bedad | 625 | |
d8cd189e | 626 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
965bedad | 627 | if (powersave) |
d8cd189e | 628 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
965bedad | 629 | |
62ae67be | 630 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
b6f35301 RM |
631 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
632 | IEEE80211_STA_CONNECTION_POLL)) | |
633 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; | |
634 | ||
62ae67be | 635 | ieee80211_tx_skb(sdata, skb); |
965bedad JB |
636 | } |
637 | ||
d524215f FF |
638 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
639 | struct ieee80211_sub_if_data *sdata) | |
640 | { | |
641 | struct sk_buff *skb; | |
642 | struct ieee80211_hdr *nullfunc; | |
643 | __le16 fc; | |
644 | ||
645 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) | |
646 | return; | |
647 | ||
648 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); | |
d15b8459 | 649 | if (!skb) |
d524215f | 650 | return; |
d15b8459 | 651 | |
d524215f FF |
652 | skb_reserve(skb, local->hw.extra_tx_headroom); |
653 | ||
654 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30); | |
655 | memset(nullfunc, 0, 30); | |
656 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | | |
657 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); | |
658 | nullfunc->frame_control = fc; | |
659 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); | |
660 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); | |
661 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); | |
662 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); | |
663 | ||
664 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; | |
665 | ieee80211_tx_skb(sdata, skb); | |
666 | } | |
667 | ||
cc32abd4 JB |
668 | /* spectrum management related things */ |
669 | static void ieee80211_chswitch_work(struct work_struct *work) | |
670 | { | |
671 | struct ieee80211_sub_if_data *sdata = | |
672 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); | |
cc32abd4 JB |
673 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
674 | ||
9607e6b6 | 675 | if (!ieee80211_sdata_running(sdata)) |
cc32abd4 JB |
676 | return; |
677 | ||
77fdaa12 JB |
678 | mutex_lock(&ifmgd->mtx); |
679 | if (!ifmgd->associated) | |
680 | goto out; | |
cc32abd4 | 681 | |
55de908a | 682 | sdata->local->_oper_channel = sdata->local->csa_channel; |
5ce6e438 JB |
683 | if (!sdata->local->ops->channel_switch) { |
684 | /* call "hw_config" only if doing sw channel switch */ | |
685 | ieee80211_hw_config(sdata->local, | |
686 | IEEE80211_CONF_CHANGE_CHANNEL); | |
1ea57b1f SL |
687 | } else { |
688 | /* update the device channel directly */ | |
55de908a | 689 | sdata->local->hw.conf.channel = sdata->local->_oper_channel; |
5ce6e438 | 690 | } |
77fdaa12 | 691 | |
cc32abd4 | 692 | /* XXX: shouldn't really modify cfg80211-owned data! */ |
55de908a | 693 | ifmgd->associated->channel = sdata->local->_oper_channel; |
cc32abd4 | 694 | |
57eebdf3 | 695 | /* XXX: wait for a beacon first? */ |
cc32abd4 JB |
696 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
697 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
77fdaa12 JB |
698 | out: |
699 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; | |
700 | mutex_unlock(&ifmgd->mtx); | |
cc32abd4 JB |
701 | } |
702 | ||
5ce6e438 JB |
703 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
704 | { | |
55de908a JB |
705 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
706 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
5ce6e438 JB |
707 | |
708 | trace_api_chswitch_done(sdata, success); | |
709 | if (!success) { | |
882a7c69 JB |
710 | sdata_info(sdata, |
711 | "driver channel switch failed, disconnecting\n"); | |
712 | ieee80211_queue_work(&sdata->local->hw, | |
713 | &ifmgd->csa_connection_drop_work); | |
714 | } else { | |
715 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); | |
5ce6e438 | 716 | } |
5ce6e438 JB |
717 | } |
718 | EXPORT_SYMBOL(ieee80211_chswitch_done); | |
719 | ||
cc32abd4 JB |
720 | static void ieee80211_chswitch_timer(unsigned long data) |
721 | { | |
722 | struct ieee80211_sub_if_data *sdata = | |
723 | (struct ieee80211_sub_if_data *) data; | |
724 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
725 | ||
5bb644a0 JB |
726 | if (sdata->local->quiescing) { |
727 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); | |
728 | return; | |
729 | } | |
730 | ||
42935eca | 731 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
cc32abd4 JB |
732 | } |
733 | ||
734 | void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, | |
735 | struct ieee80211_channel_sw_ie *sw_elem, | |
5ce6e438 JB |
736 | struct ieee80211_bss *bss, |
737 | u64 timestamp) | |
cc32abd4 | 738 | { |
0c1ad2ca JB |
739 | struct cfg80211_bss *cbss = |
740 | container_of((void *)bss, struct cfg80211_bss, priv); | |
cc32abd4 JB |
741 | struct ieee80211_channel *new_ch; |
742 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
59eb21a6 BR |
743 | int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num, |
744 | cbss->channel->band); | |
55de908a | 745 | struct ieee80211_chanctx *chanctx; |
cc32abd4 | 746 | |
77fdaa12 JB |
747 | ASSERT_MGD_MTX(ifmgd); |
748 | ||
749 | if (!ifmgd->associated) | |
cc32abd4 JB |
750 | return; |
751 | ||
fbe9c429 | 752 | if (sdata->local->scanning) |
cc32abd4 JB |
753 | return; |
754 | ||
755 | /* Disregard subsequent beacons if we are already running a timer | |
756 | processing a CSA */ | |
757 | ||
758 | if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED) | |
759 | return; | |
760 | ||
761 | new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq); | |
882a7c69 JB |
762 | if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) { |
763 | sdata_info(sdata, | |
764 | "AP %pM switches to unsupported channel (%d MHz), disconnecting\n", | |
765 | ifmgd->associated->bssid, new_freq); | |
766 | ieee80211_queue_work(&sdata->local->hw, | |
767 | &ifmgd->csa_connection_drop_work); | |
cc32abd4 | 768 | return; |
882a7c69 | 769 | } |
cc32abd4 | 770 | |
57eebdf3 JB |
771 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; |
772 | ||
55de908a JB |
773 | if (sdata->local->use_chanctx) { |
774 | sdata_info(sdata, | |
775 | "not handling channel switch with channel contexts\n"); | |
776 | ieee80211_queue_work(&sdata->local->hw, | |
777 | &ifmgd->csa_connection_drop_work); | |
778 | } | |
779 | ||
780 | mutex_lock(&sdata->local->chanctx_mtx); | |
781 | if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) { | |
782 | mutex_unlock(&sdata->local->chanctx_mtx); | |
783 | return; | |
784 | } | |
785 | chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf), | |
786 | struct ieee80211_chanctx, conf); | |
787 | if (chanctx->refcount > 1) { | |
788 | sdata_info(sdata, | |
789 | "channel switch with multiple interfaces on the same channel, disconnecting\n"); | |
790 | ieee80211_queue_work(&sdata->local->hw, | |
791 | &ifmgd->csa_connection_drop_work); | |
792 | mutex_unlock(&sdata->local->chanctx_mtx); | |
793 | return; | |
794 | } | |
795 | mutex_unlock(&sdata->local->chanctx_mtx); | |
796 | ||
797 | sdata->local->csa_channel = new_ch; | |
798 | ||
57eebdf3 JB |
799 | if (sw_elem->mode) |
800 | ieee80211_stop_queues_by_reason(&sdata->local->hw, | |
801 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
802 | ||
5ce6e438 JB |
803 | if (sdata->local->ops->channel_switch) { |
804 | /* use driver's channel switch callback */ | |
57eebdf3 JB |
805 | struct ieee80211_channel_switch ch_switch = { |
806 | .timestamp = timestamp, | |
807 | .block_tx = sw_elem->mode, | |
808 | .channel = new_ch, | |
809 | .count = sw_elem->count, | |
810 | }; | |
811 | ||
5ce6e438 JB |
812 | drv_channel_switch(sdata->local, &ch_switch); |
813 | return; | |
814 | } | |
815 | ||
816 | /* channel switch handled in software */ | |
57eebdf3 | 817 | if (sw_elem->count <= 1) |
42935eca | 818 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
57eebdf3 | 819 | else |
cc32abd4 | 820 | mod_timer(&ifmgd->chswitch_timer, |
3049000b JB |
821 | TU_TO_EXP_TIME(sw_elem->count * |
822 | cbss->beacon_interval)); | |
cc32abd4 JB |
823 | } |
824 | ||
1ea6f9c0 JB |
825 | static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
826 | struct ieee80211_channel *channel, | |
827 | const u8 *country_ie, u8 country_ie_len, | |
828 | const u8 *pwr_constr_elem) | |
cc32abd4 | 829 | { |
04b7b2ff JB |
830 | struct ieee80211_country_ie_triplet *triplet; |
831 | int chan = ieee80211_frequency_to_channel(channel->center_freq); | |
832 | int i, chan_pwr, chan_increment, new_ap_level; | |
833 | bool have_chan_pwr = false; | |
cc32abd4 | 834 | |
04b7b2ff JB |
835 | /* Invalid IE */ |
836 | if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) | |
1ea6f9c0 | 837 | return 0; |
cc32abd4 | 838 | |
04b7b2ff JB |
839 | triplet = (void *)(country_ie + 3); |
840 | country_ie_len -= 3; | |
841 | ||
842 | switch (channel->band) { | |
843 | default: | |
844 | WARN_ON_ONCE(1); | |
845 | /* fall through */ | |
846 | case IEEE80211_BAND_2GHZ: | |
847 | case IEEE80211_BAND_60GHZ: | |
848 | chan_increment = 1; | |
849 | break; | |
850 | case IEEE80211_BAND_5GHZ: | |
851 | chan_increment = 4; | |
852 | break; | |
cc32abd4 | 853 | } |
04b7b2ff JB |
854 | |
855 | /* find channel */ | |
856 | while (country_ie_len >= 3) { | |
857 | u8 first_channel = triplet->chans.first_channel; | |
858 | ||
859 | if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) | |
860 | goto next; | |
861 | ||
862 | for (i = 0; i < triplet->chans.num_channels; i++) { | |
863 | if (first_channel + i * chan_increment == chan) { | |
864 | have_chan_pwr = true; | |
865 | chan_pwr = triplet->chans.max_power; | |
866 | break; | |
867 | } | |
868 | } | |
869 | if (have_chan_pwr) | |
870 | break; | |
871 | ||
872 | next: | |
873 | triplet++; | |
874 | country_ie_len -= 3; | |
875 | } | |
876 | ||
877 | if (!have_chan_pwr) | |
1ea6f9c0 | 878 | return 0; |
04b7b2ff JB |
879 | |
880 | new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem); | |
881 | ||
1ea6f9c0 JB |
882 | if (sdata->ap_power_level == new_ap_level) |
883 | return 0; | |
04b7b2ff JB |
884 | |
885 | sdata_info(sdata, | |
886 | "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", | |
887 | new_ap_level, chan_pwr, *pwr_constr_elem, | |
888 | sdata->u.mgd.bssid); | |
1ea6f9c0 JB |
889 | sdata->ap_power_level = new_ap_level; |
890 | if (__ieee80211_recalc_txpower(sdata)) | |
891 | return BSS_CHANGED_TXPOWER; | |
892 | return 0; | |
cc32abd4 JB |
893 | } |
894 | ||
f90754c1 JO |
895 | void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif) |
896 | { | |
897 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
898 | struct ieee80211_local *local = sdata->local; | |
899 | struct ieee80211_conf *conf = &local->hw.conf; | |
900 | ||
901 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || | |
902 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || | |
903 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); | |
904 | ||
905 | local->disable_dynamic_ps = false; | |
906 | conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout; | |
907 | } | |
908 | EXPORT_SYMBOL(ieee80211_enable_dyn_ps); | |
909 | ||
910 | void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif) | |
911 | { | |
912 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
913 | struct ieee80211_local *local = sdata->local; | |
914 | struct ieee80211_conf *conf = &local->hw.conf; | |
915 | ||
916 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || | |
917 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || | |
918 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); | |
919 | ||
920 | local->disable_dynamic_ps = true; | |
921 | conf->dynamic_ps_timeout = 0; | |
922 | del_timer_sync(&local->dynamic_ps_timer); | |
923 | ieee80211_queue_work(&local->hw, | |
924 | &local->dynamic_ps_enable_work); | |
925 | } | |
926 | EXPORT_SYMBOL(ieee80211_disable_dyn_ps); | |
927 | ||
965bedad JB |
928 | /* powersave */ |
929 | static void ieee80211_enable_ps(struct ieee80211_local *local, | |
930 | struct ieee80211_sub_if_data *sdata) | |
931 | { | |
932 | struct ieee80211_conf *conf = &local->hw.conf; | |
933 | ||
d5edaedc JB |
934 | /* |
935 | * If we are scanning right now then the parameters will | |
936 | * take effect when scan finishes. | |
937 | */ | |
fbe9c429 | 938 | if (local->scanning) |
d5edaedc JB |
939 | return; |
940 | ||
965bedad JB |
941 | if (conf->dynamic_ps_timeout > 0 && |
942 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { | |
943 | mod_timer(&local->dynamic_ps_timer, jiffies + | |
944 | msecs_to_jiffies(conf->dynamic_ps_timeout)); | |
945 | } else { | |
946 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) | |
947 | ieee80211_send_nullfunc(local, sdata, 1); | |
375177bf | 948 | |
2a13052f JO |
949 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
950 | (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) | |
951 | return; | |
952 | ||
953 | conf->flags |= IEEE80211_CONF_PS; | |
954 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
965bedad JB |
955 | } |
956 | } | |
957 | ||
958 | static void ieee80211_change_ps(struct ieee80211_local *local) | |
959 | { | |
960 | struct ieee80211_conf *conf = &local->hw.conf; | |
961 | ||
962 | if (local->ps_sdata) { | |
965bedad JB |
963 | ieee80211_enable_ps(local, local->ps_sdata); |
964 | } else if (conf->flags & IEEE80211_CONF_PS) { | |
965 | conf->flags &= ~IEEE80211_CONF_PS; | |
966 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
967 | del_timer_sync(&local->dynamic_ps_timer); | |
968 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
969 | } | |
970 | } | |
971 | ||
808118cb JY |
972 | static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) |
973 | { | |
974 | struct ieee80211_if_managed *mgd = &sdata->u.mgd; | |
975 | struct sta_info *sta = NULL; | |
c2c98fde | 976 | bool authorized = false; |
808118cb JY |
977 | |
978 | if (!mgd->powersave) | |
979 | return false; | |
980 | ||
05cb9108 JB |
981 | if (mgd->broken_ap) |
982 | return false; | |
983 | ||
808118cb JY |
984 | if (!mgd->associated) |
985 | return false; | |
986 | ||
808118cb JY |
987 | if (mgd->flags & (IEEE80211_STA_BEACON_POLL | |
988 | IEEE80211_STA_CONNECTION_POLL)) | |
989 | return false; | |
990 | ||
991 | rcu_read_lock(); | |
992 | sta = sta_info_get(sdata, mgd->bssid); | |
993 | if (sta) | |
c2c98fde | 994 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
808118cb JY |
995 | rcu_read_unlock(); |
996 | ||
c2c98fde | 997 | return authorized; |
808118cb JY |
998 | } |
999 | ||
965bedad | 1000 | /* need to hold RTNL or interface lock */ |
10f644a4 | 1001 | void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency) |
965bedad JB |
1002 | { |
1003 | struct ieee80211_sub_if_data *sdata, *found = NULL; | |
1004 | int count = 0; | |
195e294d | 1005 | int timeout; |
965bedad JB |
1006 | |
1007 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) { | |
1008 | local->ps_sdata = NULL; | |
1009 | return; | |
1010 | } | |
1011 | ||
1012 | list_for_each_entry(sdata, &local->interfaces, list) { | |
9607e6b6 | 1013 | if (!ieee80211_sdata_running(sdata)) |
965bedad | 1014 | continue; |
8c7914de RM |
1015 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
1016 | /* If an AP vif is found, then disable PS | |
1017 | * by setting the count to zero thereby setting | |
1018 | * ps_sdata to NULL. | |
1019 | */ | |
1020 | count = 0; | |
1021 | break; | |
1022 | } | |
965bedad JB |
1023 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
1024 | continue; | |
1025 | found = sdata; | |
1026 | count++; | |
1027 | } | |
1028 | ||
808118cb | 1029 | if (count == 1 && ieee80211_powersave_allowed(found)) { |
f90754c1 | 1030 | struct ieee80211_conf *conf = &local->hw.conf; |
10f644a4 JB |
1031 | s32 beaconint_us; |
1032 | ||
1033 | if (latency < 0) | |
ed77134b | 1034 | latency = pm_qos_request(PM_QOS_NETWORK_LATENCY); |
10f644a4 JB |
1035 | |
1036 | beaconint_us = ieee80211_tu_to_usec( | |
1037 | found->vif.bss_conf.beacon_int); | |
1038 | ||
ff616381 | 1039 | timeout = local->dynamic_ps_forced_timeout; |
195e294d JO |
1040 | if (timeout < 0) { |
1041 | /* | |
ff616381 JO |
1042 | * Go to full PSM if the user configures a very low |
1043 | * latency requirement. | |
0ab82b04 EP |
1044 | * The 2000 second value is there for compatibility |
1045 | * until the PM_QOS_NETWORK_LATENCY is configured | |
1046 | * with real values. | |
195e294d | 1047 | */ |
0ab82b04 EP |
1048 | if (latency > (1900 * USEC_PER_MSEC) && |
1049 | latency != (2000 * USEC_PER_SEC)) | |
195e294d | 1050 | timeout = 0; |
ff616381 JO |
1051 | else |
1052 | timeout = 100; | |
195e294d | 1053 | } |
f90754c1 JO |
1054 | local->dynamic_ps_user_timeout = timeout; |
1055 | if (!local->disable_dynamic_ps) | |
1056 | conf->dynamic_ps_timeout = | |
1057 | local->dynamic_ps_user_timeout; | |
195e294d | 1058 | |
04fe2037 | 1059 | if (beaconint_us > latency) { |
10f644a4 | 1060 | local->ps_sdata = NULL; |
04fe2037 | 1061 | } else { |
56007a02 | 1062 | struct ieee80211_bss *bss; |
04fe2037 | 1063 | int maxslp = 1; |
56007a02 | 1064 | u8 dtimper; |
04fe2037 | 1065 | |
56007a02 JB |
1066 | bss = (void *)found->u.mgd.associated->priv; |
1067 | dtimper = bss->dtim_period; | |
1068 | ||
1069 | /* If the TIM IE is invalid, pretend the value is 1 */ | |
1070 | if (!dtimper) | |
1071 | dtimper = 1; | |
1072 | else if (dtimper > 1) | |
04fe2037 JB |
1073 | maxslp = min_t(int, dtimper, |
1074 | latency / beaconint_us); | |
1075 | ||
9ccebe61 | 1076 | local->hw.conf.max_sleep_period = maxslp; |
56007a02 | 1077 | local->hw.conf.ps_dtim_period = dtimper; |
10f644a4 | 1078 | local->ps_sdata = found; |
04fe2037 | 1079 | } |
10f644a4 | 1080 | } else { |
965bedad | 1081 | local->ps_sdata = NULL; |
10f644a4 | 1082 | } |
965bedad JB |
1083 | |
1084 | ieee80211_change_ps(local); | |
1085 | } | |
1086 | ||
ab095877 EP |
1087 | void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) |
1088 | { | |
1089 | bool ps_allowed = ieee80211_powersave_allowed(sdata); | |
1090 | ||
1091 | if (sdata->vif.bss_conf.ps != ps_allowed) { | |
1092 | sdata->vif.bss_conf.ps = ps_allowed; | |
1093 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS); | |
1094 | } | |
1095 | } | |
1096 | ||
965bedad JB |
1097 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
1098 | { | |
1099 | struct ieee80211_local *local = | |
1100 | container_of(work, struct ieee80211_local, | |
1101 | dynamic_ps_disable_work); | |
1102 | ||
1103 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { | |
1104 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
1105 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
1106 | } | |
1107 | ||
1108 | ieee80211_wake_queues_by_reason(&local->hw, | |
1109 | IEEE80211_QUEUE_STOP_REASON_PS); | |
1110 | } | |
1111 | ||
1112 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) | |
1113 | { | |
1114 | struct ieee80211_local *local = | |
1115 | container_of(work, struct ieee80211_local, | |
1116 | dynamic_ps_enable_work); | |
1117 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; | |
5e34069c | 1118 | struct ieee80211_if_managed *ifmgd; |
1ddc2867 RM |
1119 | unsigned long flags; |
1120 | int q; | |
965bedad JB |
1121 | |
1122 | /* can only happen when PS was just disabled anyway */ | |
1123 | if (!sdata) | |
1124 | return; | |
1125 | ||
5e34069c CL |
1126 | ifmgd = &sdata->u.mgd; |
1127 | ||
965bedad JB |
1128 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
1129 | return; | |
1130 | ||
77b7023a AN |
1131 | if (!local->disable_dynamic_ps && |
1132 | local->hw.conf.dynamic_ps_timeout > 0) { | |
1133 | /* don't enter PS if TX frames are pending */ | |
1134 | if (drv_tx_frames_pending(local)) { | |
1ddc2867 RM |
1135 | mod_timer(&local->dynamic_ps_timer, jiffies + |
1136 | msecs_to_jiffies( | |
1137 | local->hw.conf.dynamic_ps_timeout)); | |
1138 | return; | |
1139 | } | |
77b7023a AN |
1140 | |
1141 | /* | |
1142 | * transmission can be stopped by others which leads to | |
1143 | * dynamic_ps_timer expiry. Postpone the ps timer if it | |
1144 | * is not the actual idle state. | |
1145 | */ | |
1146 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
1147 | for (q = 0; q < local->hw.queues; q++) { | |
1148 | if (local->queue_stop_reasons[q]) { | |
1149 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, | |
1150 | flags); | |
1151 | mod_timer(&local->dynamic_ps_timer, jiffies + | |
1152 | msecs_to_jiffies( | |
1153 | local->hw.conf.dynamic_ps_timeout)); | |
1154 | return; | |
1155 | } | |
1156 | } | |
1157 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
1ddc2867 | 1158 | } |
1ddc2867 | 1159 | |
375177bf | 1160 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
9c38a8b4 | 1161 | !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
f3e85b9e | 1162 | netif_tx_stop_all_queues(sdata->dev); |
965bedad | 1163 | |
e8306f98 VN |
1164 | if (drv_tx_frames_pending(local)) |
1165 | mod_timer(&local->dynamic_ps_timer, jiffies + | |
1166 | msecs_to_jiffies( | |
1167 | local->hw.conf.dynamic_ps_timeout)); | |
1168 | else { | |
1169 | ieee80211_send_nullfunc(local, sdata, 1); | |
1170 | /* Flush to get the tx status of nullfunc frame */ | |
1171 | drv_flush(local, false); | |
1172 | } | |
f3e85b9e VN |
1173 | } |
1174 | ||
2a13052f JO |
1175 | if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) && |
1176 | (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) || | |
375177bf VN |
1177 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
1178 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; | |
1179 | local->hw.conf.flags |= IEEE80211_CONF_PS; | |
1180 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
1181 | } | |
f3e85b9e | 1182 | |
77b7023a AN |
1183 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
1184 | netif_tx_wake_all_queues(sdata->dev); | |
965bedad JB |
1185 | } |
1186 | ||
1187 | void ieee80211_dynamic_ps_timer(unsigned long data) | |
1188 | { | |
1189 | struct ieee80211_local *local = (void *) data; | |
1190 | ||
78f1a8b7 | 1191 | if (local->quiescing || local->suspended) |
5bb644a0 JB |
1192 | return; |
1193 | ||
42935eca | 1194 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
965bedad JB |
1195 | } |
1196 | ||
60f8b39c | 1197 | /* MLME */ |
7d25745d | 1198 | static bool ieee80211_sta_wmm_params(struct ieee80211_local *local, |
4ced3f74 | 1199 | struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1200 | u8 *wmm_param, size_t wmm_param_len) |
1201 | { | |
f0706e82 | 1202 | struct ieee80211_tx_queue_params params; |
4ced3f74 | 1203 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 JB |
1204 | size_t left; |
1205 | int count; | |
ab13315a | 1206 | u8 *pos, uapsd_queues = 0; |
f0706e82 | 1207 | |
e1b3ec1a | 1208 | if (!local->ops->conf_tx) |
7d25745d | 1209 | return false; |
e1b3ec1a | 1210 | |
32c5057b | 1211 | if (local->hw.queues < IEEE80211_NUM_ACS) |
7d25745d | 1212 | return false; |
3434fbd3 JB |
1213 | |
1214 | if (!wmm_param) | |
7d25745d | 1215 | return false; |
3434fbd3 | 1216 | |
f0706e82 | 1217 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
7d25745d | 1218 | return false; |
ab13315a KV |
1219 | |
1220 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) | |
dc41e4d4 | 1221 | uapsd_queues = ifmgd->uapsd_queues; |
ab13315a | 1222 | |
f0706e82 | 1223 | count = wmm_param[6] & 0x0f; |
46900298 | 1224 | if (count == ifmgd->wmm_last_param_set) |
7d25745d | 1225 | return false; |
46900298 | 1226 | ifmgd->wmm_last_param_set = count; |
f0706e82 JB |
1227 | |
1228 | pos = wmm_param + 8; | |
1229 | left = wmm_param_len - 8; | |
1230 | ||
1231 | memset(¶ms, 0, sizeof(params)); | |
1232 | ||
00e96dec | 1233 | sdata->wmm_acm = 0; |
f0706e82 JB |
1234 | for (; left >= 4; left -= 4, pos += 4) { |
1235 | int aci = (pos[0] >> 5) & 0x03; | |
1236 | int acm = (pos[0] >> 4) & 0x01; | |
ab13315a | 1237 | bool uapsd = false; |
f0706e82 JB |
1238 | int queue; |
1239 | ||
1240 | switch (aci) { | |
0eeb59fe | 1241 | case 1: /* AC_BK */ |
e100bb64 | 1242 | queue = 3; |
988c0f72 | 1243 | if (acm) |
00e96dec | 1244 | sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
ab13315a KV |
1245 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
1246 | uapsd = true; | |
f0706e82 | 1247 | break; |
0eeb59fe | 1248 | case 2: /* AC_VI */ |
e100bb64 | 1249 | queue = 1; |
988c0f72 | 1250 | if (acm) |
00e96dec | 1251 | sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
ab13315a KV |
1252 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
1253 | uapsd = true; | |
f0706e82 | 1254 | break; |
0eeb59fe | 1255 | case 3: /* AC_VO */ |
e100bb64 | 1256 | queue = 0; |
988c0f72 | 1257 | if (acm) |
00e96dec | 1258 | sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
ab13315a KV |
1259 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
1260 | uapsd = true; | |
f0706e82 | 1261 | break; |
0eeb59fe | 1262 | case 0: /* AC_BE */ |
f0706e82 | 1263 | default: |
e100bb64 | 1264 | queue = 2; |
988c0f72 | 1265 | if (acm) |
00e96dec | 1266 | sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
ab13315a KV |
1267 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
1268 | uapsd = true; | |
f0706e82 JB |
1269 | break; |
1270 | } | |
1271 | ||
1272 | params.aifs = pos[0] & 0x0f; | |
1273 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); | |
1274 | params.cw_min = ecw2cw(pos[1] & 0x0f); | |
f434b2d1 | 1275 | params.txop = get_unaligned_le16(pos + 2); |
ab13315a KV |
1276 | params.uapsd = uapsd; |
1277 | ||
bdcbd8e0 JB |
1278 | mlme_dbg(sdata, |
1279 | "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n", | |
1280 | queue, aci, acm, | |
1281 | params.aifs, params.cw_min, params.cw_max, | |
1282 | params.txop, params.uapsd); | |
f6f3def3 EP |
1283 | sdata->tx_conf[queue] = params; |
1284 | if (drv_conf_tx(local, sdata, queue, ¶ms)) | |
bdcbd8e0 JB |
1285 | sdata_err(sdata, |
1286 | "failed to set TX queue parameters for queue %d\n", | |
1287 | queue); | |
f0706e82 | 1288 | } |
e1b3ec1a SG |
1289 | |
1290 | /* enable WMM or activate new settings */ | |
4ced3f74 | 1291 | sdata->vif.bss_conf.qos = true; |
7d25745d | 1292 | return true; |
f0706e82 JB |
1293 | } |
1294 | ||
925e64c3 SG |
1295 | static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
1296 | { | |
1297 | lockdep_assert_held(&sdata->local->mtx); | |
1298 | ||
1299 | sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | | |
1300 | IEEE80211_STA_BEACON_POLL); | |
1301 | ieee80211_run_deferred_scan(sdata->local); | |
1302 | } | |
1303 | ||
1304 | static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) | |
1305 | { | |
1306 | mutex_lock(&sdata->local->mtx); | |
1307 | __ieee80211_stop_poll(sdata); | |
1308 | mutex_unlock(&sdata->local->mtx); | |
1309 | } | |
1310 | ||
7a5158ef JB |
1311 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
1312 | u16 capab, bool erp_valid, u8 erp) | |
5628221c | 1313 | { |
bda3933a | 1314 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
471b3efd | 1315 | u32 changed = 0; |
7a5158ef JB |
1316 | bool use_protection; |
1317 | bool use_short_preamble; | |
1318 | bool use_short_slot; | |
1319 | ||
1320 | if (erp_valid) { | |
1321 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; | |
1322 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; | |
1323 | } else { | |
1324 | use_protection = false; | |
1325 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); | |
1326 | } | |
1327 | ||
1328 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); | |
55de908a | 1329 | if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ) |
43d35343 | 1330 | use_short_slot = true; |
5628221c | 1331 | |
471b3efd | 1332 | if (use_protection != bss_conf->use_cts_prot) { |
471b3efd JB |
1333 | bss_conf->use_cts_prot = use_protection; |
1334 | changed |= BSS_CHANGED_ERP_CTS_PROT; | |
5628221c | 1335 | } |
7e9ed188 | 1336 | |
d43c7b37 | 1337 | if (use_short_preamble != bss_conf->use_short_preamble) { |
d43c7b37 | 1338 | bss_conf->use_short_preamble = use_short_preamble; |
471b3efd | 1339 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
7e9ed188 | 1340 | } |
d9430a32 | 1341 | |
7a5158ef | 1342 | if (use_short_slot != bss_conf->use_short_slot) { |
7a5158ef JB |
1343 | bss_conf->use_short_slot = use_short_slot; |
1344 | changed |= BSS_CHANGED_ERP_SLOT; | |
50c4afb9 JL |
1345 | } |
1346 | ||
1347 | return changed; | |
1348 | } | |
1349 | ||
f698d856 | 1350 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
0c1ad2ca | 1351 | struct cfg80211_bss *cbss, |
ae5eb026 | 1352 | u32 bss_info_changed) |
f0706e82 | 1353 | { |
0c1ad2ca | 1354 | struct ieee80211_bss *bss = (void *)cbss->priv; |
471b3efd | 1355 | struct ieee80211_local *local = sdata->local; |
68542962 | 1356 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
d6f2da5b | 1357 | |
ae5eb026 | 1358 | bss_info_changed |= BSS_CHANGED_ASSOC; |
77fdaa12 | 1359 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
50ae34a2 | 1360 | bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); |
21c0cbe7 | 1361 | |
7ccc8bd7 FF |
1362 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
1363 | IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int)); | |
1364 | ||
0c1ad2ca JB |
1365 | sdata->u.mgd.associated = cbss; |
1366 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); | |
f0706e82 | 1367 | |
17e4ec14 JM |
1368 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
1369 | ||
488dd7b5 JB |
1370 | if (sdata->vif.p2p) { |
1371 | u8 noa[2]; | |
1372 | int ret; | |
1373 | ||
1374 | ret = cfg80211_get_p2p_attr(cbss->information_elements, | |
1375 | cbss->len_information_elements, | |
1376 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, | |
1377 | noa, sizeof(noa)); | |
1378 | if (ret >= 2) { | |
1379 | bss_conf->p2p_oppps = noa[1] & 0x80; | |
1380 | bss_conf->p2p_ctwindow = noa[1] & 0x7f; | |
1381 | bss_info_changed |= BSS_CHANGED_P2P_PS; | |
1382 | sdata->u.mgd.p2p_noa_index = noa[0]; | |
1383 | } | |
1384 | } | |
1385 | ||
b291ba11 | 1386 | /* just to be sure */ |
925e64c3 | 1387 | ieee80211_stop_poll(sdata); |
b291ba11 | 1388 | |
9ac19a90 | 1389 | ieee80211_led_assoc(local, 1); |
9306102e | 1390 | |
e5b900d2 JB |
1391 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) |
1392 | bss_conf->dtim_period = bss->dtim_period; | |
1393 | else | |
1394 | bss_conf->dtim_period = 0; | |
1395 | ||
68542962 | 1396 | bss_conf->assoc = 1; |
9cef8737 | 1397 | |
a97c13c3 | 1398 | /* Tell the driver to monitor connection quality (if supported) */ |
ea086359 | 1399 | if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && |
68542962 | 1400 | bss_conf->cqm_rssi_thold) |
a97c13c3 JO |
1401 | bss_info_changed |= BSS_CHANGED_CQM; |
1402 | ||
68542962 JO |
1403 | /* Enable ARP filtering */ |
1404 | if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) { | |
1405 | bss_conf->arp_filter_enabled = sdata->arp_filter_state; | |
1406 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; | |
1407 | } | |
1408 | ||
ae5eb026 | 1409 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
f0706e82 | 1410 | |
056508dc JB |
1411 | mutex_lock(&local->iflist_mtx); |
1412 | ieee80211_recalc_ps(local, -1); | |
1413 | mutex_unlock(&local->iflist_mtx); | |
e0cb686f | 1414 | |
04ecd257 | 1415 | ieee80211_recalc_smps(sdata); |
ab095877 EP |
1416 | ieee80211_recalc_ps_vif(sdata); |
1417 | ||
8a5b33f5 | 1418 | netif_tx_start_all_queues(sdata->dev); |
9ac19a90 | 1419 | netif_carrier_on(sdata->dev); |
f0706e82 JB |
1420 | } |
1421 | ||
e69e95db | 1422 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
37ad3888 JB |
1423 | u16 stype, u16 reason, bool tx, |
1424 | u8 *frame_buf) | |
aa458d17 | 1425 | { |
46900298 | 1426 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
aa458d17 TW |
1427 | struct ieee80211_local *local = sdata->local; |
1428 | struct sta_info *sta; | |
3cc5240b | 1429 | u32 changed = 0; |
aa458d17 | 1430 | |
77fdaa12 JB |
1431 | ASSERT_MGD_MTX(ifmgd); |
1432 | ||
37ad3888 JB |
1433 | if (WARN_ON_ONCE(tx && !frame_buf)) |
1434 | return; | |
1435 | ||
b291ba11 JB |
1436 | if (WARN_ON(!ifmgd->associated)) |
1437 | return; | |
1438 | ||
79543d8e DS |
1439 | ieee80211_stop_poll(sdata); |
1440 | ||
77fdaa12 | 1441 | ifmgd->associated = NULL; |
77fdaa12 JB |
1442 | |
1443 | /* | |
1444 | * we need to commit the associated = NULL change because the | |
1445 | * scan code uses that to determine whether this iface should | |
1446 | * go to/wake up from powersave or not -- and could otherwise | |
1447 | * wake the queues erroneously. | |
1448 | */ | |
1449 | smp_mb(); | |
1450 | ||
1451 | /* | |
1452 | * Thus, we can only afterwards stop the queues -- to account | |
1453 | * for the case where another CPU is finishing a scan at this | |
1454 | * time -- we don't want the scan code to enable queues. | |
1455 | */ | |
aa458d17 | 1456 | |
8a5b33f5 | 1457 | netif_tx_stop_all_queues(sdata->dev); |
aa458d17 TW |
1458 | netif_carrier_off(sdata->dev); |
1459 | ||
2a419056 | 1460 | mutex_lock(&local->sta_mtx); |
88a9e31c | 1461 | sta = sta_info_get(sdata, ifmgd->bssid); |
4cad6c7c | 1462 | if (sta) { |
c2c98fde | 1463 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
7f161146 | 1464 | ieee80211_sta_tear_down_BA_sessions(sta, false); |
4cad6c7c | 1465 | } |
2a419056 | 1466 | mutex_unlock(&local->sta_mtx); |
aa458d17 | 1467 | |
88bc40e8 EP |
1468 | /* |
1469 | * if we want to get out of ps before disassoc (why?) we have | |
1470 | * to do it before sending disassoc, as otherwise the null-packet | |
1471 | * won't be valid. | |
1472 | */ | |
1473 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { | |
1474 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
1475 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
1476 | } | |
1477 | local->ps_sdata = NULL; | |
1478 | ||
ab095877 EP |
1479 | /* disable per-vif ps */ |
1480 | ieee80211_recalc_ps_vif(sdata); | |
1481 | ||
f823981e EP |
1482 | /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */ |
1483 | if (tx) | |
1484 | drv_flush(local, false); | |
1485 | ||
37ad3888 JB |
1486 | /* deauthenticate/disassociate now */ |
1487 | if (tx || frame_buf) | |
88a9e31c EP |
1488 | ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype, |
1489 | reason, tx, frame_buf); | |
37ad3888 JB |
1490 | |
1491 | /* flush out frame */ | |
1492 | if (tx) | |
1493 | drv_flush(local, false); | |
1494 | ||
88a9e31c EP |
1495 | /* clear bssid only after building the needed mgmt frames */ |
1496 | memset(ifmgd->bssid, 0, ETH_ALEN); | |
1497 | ||
37ad3888 JB |
1498 | /* remove AP and TDLS peers */ |
1499 | sta_info_flush(local, sdata); | |
1500 | ||
1501 | /* finally reset all BSS / config parameters */ | |
f5e5bf25 TW |
1502 | changed |= ieee80211_reset_erp_info(sdata); |
1503 | ||
f5e5bf25 | 1504 | ieee80211_led_assoc(local, 0); |
ae5eb026 JB |
1505 | changed |= BSS_CHANGED_ASSOC; |
1506 | sdata->vif.bss_conf.assoc = false; | |
f5e5bf25 | 1507 | |
488dd7b5 JB |
1508 | sdata->vif.bss_conf.p2p_ctwindow = 0; |
1509 | sdata->vif.bss_conf.p2p_oppps = false; | |
1510 | ||
413ad50a | 1511 | /* on the next assoc, re-program HT parameters */ |
ef96a842 BG |
1512 | memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); |
1513 | memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); | |
413ad50a | 1514 | |
1ea6f9c0 | 1515 | sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; |
a8302de9 | 1516 | |
520eb820 KV |
1517 | del_timer_sync(&local->dynamic_ps_timer); |
1518 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
1519 | ||
68542962 JO |
1520 | /* Disable ARP filtering */ |
1521 | if (sdata->vif.bss_conf.arp_filter_enabled) { | |
1522 | sdata->vif.bss_conf.arp_filter_enabled = false; | |
1523 | changed |= BSS_CHANGED_ARP_FILTER; | |
1524 | } | |
1525 | ||
3abead59 JB |
1526 | sdata->vif.bss_conf.qos = false; |
1527 | changed |= BSS_CHANGED_QOS; | |
1528 | ||
0aaffa9b JB |
1529 | /* The BSSID (not really interesting) and HT changed */ |
1530 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; | |
ae5eb026 | 1531 | ieee80211_bss_info_change_notify(sdata, changed); |
8e268e47 | 1532 | |
3abead59 JB |
1533 | /* disassociated - set to defaults now */ |
1534 | ieee80211_set_wmm_default(sdata, false); | |
1535 | ||
b9dcf712 JB |
1536 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
1537 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); | |
1538 | del_timer_sync(&sdata->u.mgd.timer); | |
1539 | del_timer_sync(&sdata->u.mgd.chswitch_timer); | |
2d9957cc JB |
1540 | |
1541 | sdata->u.mgd.timers_running = 0; | |
028e8da0 JB |
1542 | |
1543 | ifmgd->flags = 0; | |
1544 | ieee80211_vif_release_channel(sdata); | |
aa458d17 | 1545 | } |
f0706e82 | 1546 | |
3cf335d5 KV |
1547 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
1548 | struct ieee80211_hdr *hdr) | |
1549 | { | |
1550 | /* | |
1551 | * We can postpone the mgd.timer whenever receiving unicast frames | |
1552 | * from AP because we know that the connection is working both ways | |
1553 | * at that time. But multicast frames (and hence also beacons) must | |
1554 | * be ignored here, because we need to trigger the timer during | |
b291ba11 JB |
1555 | * data idle periods for sending the periodic probe request to the |
1556 | * AP we're connected to. | |
3cf335d5 | 1557 | */ |
b291ba11 JB |
1558 | if (is_multicast_ether_addr(hdr->addr1)) |
1559 | return; | |
1560 | ||
be099e82 | 1561 | ieee80211_sta_reset_conn_monitor(sdata); |
3cf335d5 | 1562 | } |
f0706e82 | 1563 | |
4e5ff376 FF |
1564 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
1565 | { | |
1566 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
133d40f9 | 1567 | struct ieee80211_local *local = sdata->local; |
4e5ff376 | 1568 | |
133d40f9 | 1569 | mutex_lock(&local->mtx); |
4e5ff376 | 1570 | if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
133d40f9 SG |
1571 | IEEE80211_STA_CONNECTION_POLL))) { |
1572 | mutex_unlock(&local->mtx); | |
1573 | return; | |
1574 | } | |
4e5ff376 | 1575 | |
925e64c3 | 1576 | __ieee80211_stop_poll(sdata); |
133d40f9 SG |
1577 | |
1578 | mutex_lock(&local->iflist_mtx); | |
1579 | ieee80211_recalc_ps(local, -1); | |
1580 | mutex_unlock(&local->iflist_mtx); | |
4e5ff376 FF |
1581 | |
1582 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) | |
133d40f9 | 1583 | goto out; |
4e5ff376 FF |
1584 | |
1585 | /* | |
1586 | * We've received a probe response, but are not sure whether | |
1587 | * we have or will be receiving any beacons or data, so let's | |
1588 | * schedule the timers again, just in case. | |
1589 | */ | |
1590 | ieee80211_sta_reset_beacon_monitor(sdata); | |
1591 | ||
1592 | mod_timer(&ifmgd->conn_mon_timer, | |
1593 | round_jiffies_up(jiffies + | |
1594 | IEEE80211_CONNECTION_IDLE_TIME)); | |
133d40f9 | 1595 | out: |
133d40f9 | 1596 | mutex_unlock(&local->mtx); |
4e5ff376 FF |
1597 | } |
1598 | ||
1599 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, | |
04ac3c0e | 1600 | struct ieee80211_hdr *hdr, bool ack) |
4e5ff376 | 1601 | { |
75706d0e | 1602 | if (!ieee80211_is_data(hdr->frame_control)) |
4e5ff376 FF |
1603 | return; |
1604 | ||
04ac3c0e FF |
1605 | if (ack) |
1606 | ieee80211_sta_reset_conn_monitor(sdata); | |
4e5ff376 FF |
1607 | |
1608 | if (ieee80211_is_nullfunc(hdr->frame_control) && | |
1609 | sdata->u.mgd.probe_send_count > 0) { | |
04ac3c0e FF |
1610 | if (ack) |
1611 | sdata->u.mgd.probe_send_count = 0; | |
1612 | else | |
1613 | sdata->u.mgd.nullfunc_failed = true; | |
4e5ff376 FF |
1614 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
1615 | } | |
1616 | } | |
1617 | ||
a43abf29 ML |
1618 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
1619 | { | |
1620 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1621 | const u8 *ssid; | |
f01a067d | 1622 | u8 *dst = ifmgd->associated->bssid; |
180205bd | 1623 | u8 unicast_limit = max(1, max_probe_tries - 3); |
f01a067d LR |
1624 | |
1625 | /* | |
1626 | * Try sending broadcast probe requests for the last three | |
1627 | * probe requests after the first ones failed since some | |
1628 | * buggy APs only support broadcast probe requests. | |
1629 | */ | |
1630 | if (ifmgd->probe_send_count >= unicast_limit) | |
1631 | dst = NULL; | |
a43abf29 | 1632 | |
4e5ff376 FF |
1633 | /* |
1634 | * When the hardware reports an accurate Tx ACK status, it's | |
1635 | * better to send a nullfunc frame instead of a probe request, | |
1636 | * as it will kick us off the AP quickly if we aren't associated | |
1637 | * anymore. The timeout will be reset if the frame is ACKed by | |
1638 | * the AP. | |
1639 | */ | |
992e68bf SD |
1640 | ifmgd->probe_send_count++; |
1641 | ||
04ac3c0e FF |
1642 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
1643 | ifmgd->nullfunc_failed = false; | |
4e5ff376 | 1644 | ieee80211_send_nullfunc(sdata->local, sdata, 0); |
04ac3c0e | 1645 | } else { |
88c868c4 SG |
1646 | int ssid_len; |
1647 | ||
4e5ff376 | 1648 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
88c868c4 SG |
1649 | if (WARN_ON_ONCE(ssid == NULL)) |
1650 | ssid_len = 0; | |
1651 | else | |
1652 | ssid_len = ssid[1]; | |
1653 | ||
1654 | ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL, | |
fe94fe05 | 1655 | 0, (u32) -1, true, false, |
55de908a | 1656 | ifmgd->associated->channel, false); |
4e5ff376 | 1657 | } |
a43abf29 | 1658 | |
180205bd | 1659 | ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); |
a43abf29 | 1660 | run_again(ifmgd, ifmgd->probe_timeout); |
f69b9c79 RM |
1661 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
1662 | drv_flush(sdata->local, false); | |
a43abf29 ML |
1663 | } |
1664 | ||
b291ba11 JB |
1665 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
1666 | bool beacon) | |
04de8381 | 1667 | { |
04de8381 | 1668 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
b291ba11 | 1669 | bool already = false; |
34bfc411 | 1670 | |
9607e6b6 | 1671 | if (!ieee80211_sdata_running(sdata)) |
0e2b6286 JB |
1672 | return; |
1673 | ||
77fdaa12 JB |
1674 | mutex_lock(&ifmgd->mtx); |
1675 | ||
1676 | if (!ifmgd->associated) | |
1677 | goto out; | |
1678 | ||
133d40f9 SG |
1679 | mutex_lock(&sdata->local->mtx); |
1680 | ||
1681 | if (sdata->local->tmp_channel || sdata->local->scanning) { | |
1682 | mutex_unlock(&sdata->local->mtx); | |
1683 | goto out; | |
1684 | } | |
1685 | ||
e87cc472 | 1686 | if (beacon) |
bdcbd8e0 JB |
1687 | mlme_dbg_ratelimited(sdata, |
1688 | "detected beacon loss from AP - sending probe request\n"); | |
1689 | ||
6efb71b0 HS |
1690 | ieee80211_cqm_rssi_notify(&sdata->vif, |
1691 | NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL); | |
04de8381 | 1692 | |
b291ba11 JB |
1693 | /* |
1694 | * The driver/our work has already reported this event or the | |
1695 | * connection monitoring has kicked in and we have already sent | |
1696 | * a probe request. Or maybe the AP died and the driver keeps | |
1697 | * reporting until we disassociate... | |
1698 | * | |
1699 | * In either case we have to ignore the current call to this | |
1700 | * function (except for setting the correct probe reason bit) | |
1701 | * because otherwise we would reset the timer every time and | |
1702 | * never check whether we received a probe response! | |
1703 | */ | |
1704 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | | |
1705 | IEEE80211_STA_CONNECTION_POLL)) | |
1706 | already = true; | |
1707 | ||
1708 | if (beacon) | |
1709 | ifmgd->flags |= IEEE80211_STA_BEACON_POLL; | |
1710 | else | |
1711 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; | |
1712 | ||
133d40f9 SG |
1713 | mutex_unlock(&sdata->local->mtx); |
1714 | ||
b291ba11 JB |
1715 | if (already) |
1716 | goto out; | |
1717 | ||
4e751843 JB |
1718 | mutex_lock(&sdata->local->iflist_mtx); |
1719 | ieee80211_recalc_ps(sdata->local, -1); | |
1720 | mutex_unlock(&sdata->local->iflist_mtx); | |
1721 | ||
a43abf29 ML |
1722 | ifmgd->probe_send_count = 0; |
1723 | ieee80211_mgd_probe_ap_send(sdata); | |
77fdaa12 JB |
1724 | out: |
1725 | mutex_unlock(&ifmgd->mtx); | |
04de8381 KV |
1726 | } |
1727 | ||
a619a4c0 JO |
1728 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
1729 | struct ieee80211_vif *vif) | |
1730 | { | |
1731 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1732 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
d9b3b28b | 1733 | struct cfg80211_bss *cbss; |
a619a4c0 JO |
1734 | struct sk_buff *skb; |
1735 | const u8 *ssid; | |
88c868c4 | 1736 | int ssid_len; |
a619a4c0 JO |
1737 | |
1738 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) | |
1739 | return NULL; | |
1740 | ||
1741 | ASSERT_MGD_MTX(ifmgd); | |
1742 | ||
d9b3b28b EP |
1743 | if (ifmgd->associated) |
1744 | cbss = ifmgd->associated; | |
1745 | else if (ifmgd->auth_data) | |
1746 | cbss = ifmgd->auth_data->bss; | |
1747 | else if (ifmgd->assoc_data) | |
1748 | cbss = ifmgd->assoc_data->bss; | |
1749 | else | |
a619a4c0 JO |
1750 | return NULL; |
1751 | ||
d9b3b28b | 1752 | ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID); |
88c868c4 SG |
1753 | if (WARN_ON_ONCE(ssid == NULL)) |
1754 | ssid_len = 0; | |
1755 | else | |
1756 | ssid_len = ssid[1]; | |
1757 | ||
d9b3b28b | 1758 | skb = ieee80211_build_probe_req(sdata, cbss->bssid, |
55de908a | 1759 | (u32) -1, cbss->channel, |
6b77863b | 1760 | ssid + 2, ssid_len, |
85a237fe | 1761 | NULL, 0, true); |
a619a4c0 JO |
1762 | |
1763 | return skb; | |
1764 | } | |
1765 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); | |
1766 | ||
882a7c69 JB |
1767 | static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata, |
1768 | bool transmit_frame) | |
1e4dcd01 JO |
1769 | { |
1770 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1771 | struct ieee80211_local *local = sdata->local; | |
6ae16775 | 1772 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
1e4dcd01 JO |
1773 | |
1774 | mutex_lock(&ifmgd->mtx); | |
1775 | if (!ifmgd->associated) { | |
1776 | mutex_unlock(&ifmgd->mtx); | |
1777 | return; | |
1778 | } | |
1779 | ||
37ad3888 JB |
1780 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
1781 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, | |
882a7c69 JB |
1782 | transmit_frame, frame_buf); |
1783 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; | |
1e4dcd01 | 1784 | mutex_unlock(&ifmgd->mtx); |
7da7cc1d | 1785 | |
1e4dcd01 JO |
1786 | /* |
1787 | * must be outside lock due to cfg80211, | |
1788 | * but that's not a problem. | |
1789 | */ | |
6ae16775 | 1790 | cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN); |
fcac4fb0 FF |
1791 | |
1792 | mutex_lock(&local->mtx); | |
1793 | ieee80211_recalc_idle(local); | |
1794 | mutex_unlock(&local->mtx); | |
1e4dcd01 JO |
1795 | } |
1796 | ||
cc74c0c7 | 1797 | static void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
b291ba11 JB |
1798 | { |
1799 | struct ieee80211_sub_if_data *sdata = | |
1800 | container_of(work, struct ieee80211_sub_if_data, | |
1e4dcd01 | 1801 | u.mgd.beacon_connection_loss_work); |
a85e1d55 PS |
1802 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
1803 | struct sta_info *sta; | |
1804 | ||
1805 | if (ifmgd->associated) { | |
30fa9047 | 1806 | rcu_read_lock(); |
a85e1d55 PS |
1807 | sta = sta_info_get(sdata, ifmgd->bssid); |
1808 | if (sta) | |
1809 | sta->beacon_loss_count++; | |
30fa9047 | 1810 | rcu_read_unlock(); |
a85e1d55 | 1811 | } |
b291ba11 | 1812 | |
882a7c69 JB |
1813 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) { |
1814 | sdata_info(sdata, "Connection to AP %pM lost\n", | |
1815 | ifmgd->bssid); | |
1816 | __ieee80211_disconnect(sdata, false); | |
1817 | } else { | |
1e4dcd01 | 1818 | ieee80211_mgd_probe_ap(sdata, true); |
882a7c69 JB |
1819 | } |
1820 | } | |
1821 | ||
1822 | static void ieee80211_csa_connection_drop_work(struct work_struct *work) | |
1823 | { | |
1824 | struct ieee80211_sub_if_data *sdata = | |
1825 | container_of(work, struct ieee80211_sub_if_data, | |
1826 | u.mgd.csa_connection_drop_work); | |
1827 | ||
1828 | ieee80211_wake_queues_by_reason(&sdata->local->hw, | |
1829 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
1830 | __ieee80211_disconnect(sdata, true); | |
b291ba11 JB |
1831 | } |
1832 | ||
04de8381 KV |
1833 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
1834 | { | |
1835 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1e4dcd01 | 1836 | struct ieee80211_hw *hw = &sdata->local->hw; |
04de8381 | 1837 | |
b5878a2d JB |
1838 | trace_api_beacon_loss(sdata); |
1839 | ||
1e4dcd01 JO |
1840 | WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR); |
1841 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); | |
04de8381 KV |
1842 | } |
1843 | EXPORT_SYMBOL(ieee80211_beacon_loss); | |
1844 | ||
1e4dcd01 JO |
1845 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
1846 | { | |
1847 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1848 | struct ieee80211_hw *hw = &sdata->local->hw; | |
1849 | ||
b5878a2d JB |
1850 | trace_api_connection_loss(sdata); |
1851 | ||
1e4dcd01 JO |
1852 | WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR)); |
1853 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); | |
1854 | } | |
1855 | EXPORT_SYMBOL(ieee80211_connection_loss); | |
1856 | ||
1857 | ||
66e67e41 JB |
1858 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
1859 | bool assoc) | |
1860 | { | |
1861 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; | |
1862 | ||
1863 | lockdep_assert_held(&sdata->u.mgd.mtx); | |
1864 | ||
66e67e41 JB |
1865 | if (!assoc) { |
1866 | sta_info_destroy_addr(sdata, auth_data->bss->bssid); | |
1867 | ||
1868 | memset(sdata->u.mgd.bssid, 0, ETH_ALEN); | |
1869 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); | |
028e8da0 | 1870 | sdata->u.mgd.flags = 0; |
55de908a | 1871 | ieee80211_vif_release_channel(sdata); |
66e67e41 JB |
1872 | } |
1873 | ||
1874 | cfg80211_put_bss(auth_data->bss); | |
1875 | kfree(auth_data); | |
1876 | sdata->u.mgd.auth_data = NULL; | |
1877 | } | |
1878 | ||
1879 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, | |
1880 | struct ieee80211_mgmt *mgmt, size_t len) | |
1881 | { | |
1882 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; | |
1883 | u8 *pos; | |
1884 | struct ieee802_11_elems elems; | |
1885 | ||
1886 | pos = mgmt->u.auth.variable; | |
1887 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); | |
1888 | if (!elems.challenge) | |
1889 | return; | |
1890 | auth_data->expected_transaction = 4; | |
a1845fc7 | 1891 | drv_mgd_prepare_tx(sdata->local, sdata); |
700e8ea6 | 1892 | ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, |
66e67e41 JB |
1893 | elems.challenge - 2, elems.challenge_len + 2, |
1894 | auth_data->bss->bssid, auth_data->bss->bssid, | |
1895 | auth_data->key, auth_data->key_len, | |
1896 | auth_data->key_idx); | |
1897 | } | |
1898 | ||
1899 | static enum rx_mgmt_action __must_check | |
1900 | ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, | |
1901 | struct ieee80211_mgmt *mgmt, size_t len) | |
1902 | { | |
1903 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1904 | u8 bssid[ETH_ALEN]; | |
1905 | u16 auth_alg, auth_transaction, status_code; | |
1906 | struct sta_info *sta; | |
1907 | ||
1908 | lockdep_assert_held(&ifmgd->mtx); | |
1909 | ||
1910 | if (len < 24 + 6) | |
1911 | return RX_MGMT_NONE; | |
1912 | ||
1913 | if (!ifmgd->auth_data || ifmgd->auth_data->done) | |
1914 | return RX_MGMT_NONE; | |
1915 | ||
1916 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); | |
1917 | ||
b203ca39 | 1918 | if (!ether_addr_equal(bssid, mgmt->bssid)) |
66e67e41 JB |
1919 | return RX_MGMT_NONE; |
1920 | ||
1921 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); | |
1922 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); | |
1923 | status_code = le16_to_cpu(mgmt->u.auth.status_code); | |
1924 | ||
1925 | if (auth_alg != ifmgd->auth_data->algorithm || | |
0f4126e8 JM |
1926 | auth_transaction != ifmgd->auth_data->expected_transaction) { |
1927 | sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", | |
1928 | mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, | |
1929 | auth_transaction, | |
1930 | ifmgd->auth_data->expected_transaction); | |
66e67e41 | 1931 | return RX_MGMT_NONE; |
0f4126e8 | 1932 | } |
66e67e41 JB |
1933 | |
1934 | if (status_code != WLAN_STATUS_SUCCESS) { | |
bdcbd8e0 JB |
1935 | sdata_info(sdata, "%pM denied authentication (status %d)\n", |
1936 | mgmt->sa, status_code); | |
dac211ec EP |
1937 | ieee80211_destroy_auth_data(sdata, false); |
1938 | return RX_MGMT_CFG80211_RX_AUTH; | |
66e67e41 JB |
1939 | } |
1940 | ||
1941 | switch (ifmgd->auth_data->algorithm) { | |
1942 | case WLAN_AUTH_OPEN: | |
1943 | case WLAN_AUTH_LEAP: | |
1944 | case WLAN_AUTH_FT: | |
6b8ece3a | 1945 | case WLAN_AUTH_SAE: |
66e67e41 JB |
1946 | break; |
1947 | case WLAN_AUTH_SHARED_KEY: | |
1948 | if (ifmgd->auth_data->expected_transaction != 4) { | |
1949 | ieee80211_auth_challenge(sdata, mgmt, len); | |
1950 | /* need another frame */ | |
1951 | return RX_MGMT_NONE; | |
1952 | } | |
1953 | break; | |
1954 | default: | |
1955 | WARN_ONCE(1, "invalid auth alg %d", | |
1956 | ifmgd->auth_data->algorithm); | |
1957 | return RX_MGMT_NONE; | |
1958 | } | |
1959 | ||
bdcbd8e0 | 1960 | sdata_info(sdata, "authenticated\n"); |
66e67e41 JB |
1961 | ifmgd->auth_data->done = true; |
1962 | ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; | |
1963 | run_again(ifmgd, ifmgd->auth_data->timeout); | |
1964 | ||
6b8ece3a JM |
1965 | if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && |
1966 | ifmgd->auth_data->expected_transaction != 2) { | |
1967 | /* | |
1968 | * Report auth frame to user space for processing since another | |
1969 | * round of Authentication frames is still needed. | |
1970 | */ | |
1971 | return RX_MGMT_CFG80211_RX_AUTH; | |
1972 | } | |
1973 | ||
66e67e41 JB |
1974 | /* move station state to auth */ |
1975 | mutex_lock(&sdata->local->sta_mtx); | |
1976 | sta = sta_info_get(sdata, bssid); | |
1977 | if (!sta) { | |
1978 | WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid); | |
1979 | goto out_err; | |
1980 | } | |
1981 | if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { | |
bdcbd8e0 | 1982 | sdata_info(sdata, "failed moving %pM to auth\n", bssid); |
66e67e41 JB |
1983 | goto out_err; |
1984 | } | |
1985 | mutex_unlock(&sdata->local->sta_mtx); | |
1986 | ||
1987 | return RX_MGMT_CFG80211_RX_AUTH; | |
1988 | out_err: | |
1989 | mutex_unlock(&sdata->local->sta_mtx); | |
1990 | /* ignore frame -- wait for timeout */ | |
1991 | return RX_MGMT_NONE; | |
1992 | } | |
1993 | ||
1994 | ||
77fdaa12 JB |
1995 | static enum rx_mgmt_action __must_check |
1996 | ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, | |
77fdaa12 | 1997 | struct ieee80211_mgmt *mgmt, size_t len) |
f0706e82 | 1998 | { |
46900298 | 1999 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
77fdaa12 | 2000 | const u8 *bssid = NULL; |
f0706e82 JB |
2001 | u16 reason_code; |
2002 | ||
66e67e41 JB |
2003 | lockdep_assert_held(&ifmgd->mtx); |
2004 | ||
f4ea83dd | 2005 | if (len < 24 + 2) |
77fdaa12 | 2006 | return RX_MGMT_NONE; |
f0706e82 | 2007 | |
66e67e41 | 2008 | if (!ifmgd->associated || |
b203ca39 | 2009 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
66e67e41 | 2010 | return RX_MGMT_NONE; |
77fdaa12 | 2011 | |
0c1ad2ca | 2012 | bssid = ifmgd->associated->bssid; |
f0706e82 JB |
2013 | |
2014 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | |
2015 | ||
bdcbd8e0 JB |
2016 | sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n", |
2017 | bssid, reason_code); | |
77fdaa12 | 2018 | |
37ad3888 JB |
2019 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
2020 | ||
7da7cc1d | 2021 | mutex_lock(&sdata->local->mtx); |
63f170e0 | 2022 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 2023 | mutex_unlock(&sdata->local->mtx); |
f0706e82 | 2024 | |
77fdaa12 | 2025 | return RX_MGMT_CFG80211_DEAUTH; |
f0706e82 JB |
2026 | } |
2027 | ||
2028 | ||
77fdaa12 JB |
2029 | static enum rx_mgmt_action __must_check |
2030 | ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, | |
2031 | struct ieee80211_mgmt *mgmt, size_t len) | |
f0706e82 | 2032 | { |
46900298 | 2033 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 JB |
2034 | u16 reason_code; |
2035 | ||
66e67e41 | 2036 | lockdep_assert_held(&ifmgd->mtx); |
77fdaa12 | 2037 | |
66e67e41 | 2038 | if (len < 24 + 2) |
77fdaa12 JB |
2039 | return RX_MGMT_NONE; |
2040 | ||
66e67e41 | 2041 | if (!ifmgd->associated || |
b203ca39 | 2042 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
77fdaa12 | 2043 | return RX_MGMT_NONE; |
f0706e82 JB |
2044 | |
2045 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); | |
2046 | ||
bdcbd8e0 JB |
2047 | sdata_info(sdata, "disassociated from %pM (Reason: %u)\n", |
2048 | mgmt->sa, reason_code); | |
f0706e82 | 2049 | |
37ad3888 JB |
2050 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
2051 | ||
7da7cc1d | 2052 | mutex_lock(&sdata->local->mtx); |
bc83b681 | 2053 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 2054 | mutex_unlock(&sdata->local->mtx); |
37ad3888 | 2055 | |
77fdaa12 | 2056 | return RX_MGMT_CFG80211_DISASSOC; |
f0706e82 JB |
2057 | } |
2058 | ||
c74d084f CL |
2059 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
2060 | u8 *supp_rates, unsigned int supp_rates_len, | |
2061 | u32 *rates, u32 *basic_rates, | |
2062 | bool *have_higher_than_11mbit, | |
2063 | int *min_rate, int *min_rate_index) | |
2064 | { | |
2065 | int i, j; | |
2066 | ||
2067 | for (i = 0; i < supp_rates_len; i++) { | |
2068 | int rate = (supp_rates[i] & 0x7f) * 5; | |
2069 | bool is_basic = !!(supp_rates[i] & 0x80); | |
2070 | ||
2071 | if (rate > 110) | |
2072 | *have_higher_than_11mbit = true; | |
2073 | ||
2074 | /* | |
2075 | * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009 | |
2076 | * 7.3.2.2 as a magic value instead of a rate. Hence, skip it. | |
2077 | * | |
2078 | * Note: Even through the membership selector and the basic | |
2079 | * rate flag share the same bit, they are not exactly | |
2080 | * the same. | |
2081 | */ | |
2082 | if (!!(supp_rates[i] & 0x80) && | |
2083 | (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY) | |
2084 | continue; | |
2085 | ||
2086 | for (j = 0; j < sband->n_bitrates; j++) { | |
2087 | if (sband->bitrates[j].bitrate == rate) { | |
2088 | *rates |= BIT(j); | |
2089 | if (is_basic) | |
2090 | *basic_rates |= BIT(j); | |
2091 | if (rate < *min_rate) { | |
2092 | *min_rate = rate; | |
2093 | *min_rate_index = j; | |
2094 | } | |
2095 | break; | |
2096 | } | |
2097 | } | |
2098 | } | |
2099 | } | |
f0706e82 | 2100 | |
66e67e41 JB |
2101 | static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, |
2102 | bool assoc) | |
2103 | { | |
2104 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; | |
2105 | ||
2106 | lockdep_assert_held(&sdata->u.mgd.mtx); | |
2107 | ||
66e67e41 JB |
2108 | if (!assoc) { |
2109 | sta_info_destroy_addr(sdata, assoc_data->bss->bssid); | |
2110 | ||
2111 | memset(sdata->u.mgd.bssid, 0, ETH_ALEN); | |
2112 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); | |
028e8da0 | 2113 | sdata->u.mgd.flags = 0; |
55de908a | 2114 | ieee80211_vif_release_channel(sdata); |
66e67e41 JB |
2115 | } |
2116 | ||
2117 | kfree(assoc_data); | |
2118 | sdata->u.mgd.assoc_data = NULL; | |
2119 | } | |
2120 | ||
2121 | static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, | |
2122 | struct cfg80211_bss *cbss, | |
af6b6374 | 2123 | struct ieee80211_mgmt *mgmt, size_t len) |
f0706e82 | 2124 | { |
46900298 | 2125 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
471b3efd | 2126 | struct ieee80211_local *local = sdata->local; |
8318d78a | 2127 | struct ieee80211_supported_band *sband; |
f0706e82 | 2128 | struct sta_info *sta; |
af6b6374 | 2129 | u8 *pos; |
af6b6374 | 2130 | u16 capab_info, aid; |
f0706e82 | 2131 | struct ieee802_11_elems elems; |
bda3933a | 2132 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
ae5eb026 | 2133 | u32 changed = 0; |
c74d084f | 2134 | int err; |
f0706e82 | 2135 | |
af6b6374 | 2136 | /* AssocResp and ReassocResp have identical structure */ |
f0706e82 | 2137 | |
f0706e82 | 2138 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
af6b6374 | 2139 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
f0706e82 | 2140 | |
1dd84aa2 | 2141 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
bdcbd8e0 JB |
2142 | sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n", |
2143 | aid); | |
1dd84aa2 JB |
2144 | aid &= ~(BIT(15) | BIT(14)); |
2145 | ||
05cb9108 JB |
2146 | ifmgd->broken_ap = false; |
2147 | ||
2148 | if (aid == 0 || aid > IEEE80211_MAX_AID) { | |
bdcbd8e0 JB |
2149 | sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n", |
2150 | aid); | |
05cb9108 JB |
2151 | aid = 0; |
2152 | ifmgd->broken_ap = true; | |
2153 | } | |
2154 | ||
af6b6374 JB |
2155 | pos = mgmt->u.assoc_resp.variable; |
2156 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); | |
2157 | ||
f0706e82 | 2158 | if (!elems.supp_rates) { |
bdcbd8e0 | 2159 | sdata_info(sdata, "no SuppRates element in AssocResp\n"); |
af6b6374 | 2160 | return false; |
f0706e82 JB |
2161 | } |
2162 | ||
46900298 | 2163 | ifmgd->aid = aid; |
f0706e82 | 2164 | |
2a33bee2 GE |
2165 | mutex_lock(&sdata->local->sta_mtx); |
2166 | /* | |
2167 | * station info was already allocated and inserted before | |
2168 | * the association and should be available to us | |
2169 | */ | |
7852e361 | 2170 | sta = sta_info_get(sdata, cbss->bssid); |
2a33bee2 GE |
2171 | if (WARN_ON(!sta)) { |
2172 | mutex_unlock(&sdata->local->sta_mtx); | |
af6b6374 | 2173 | return false; |
77fdaa12 | 2174 | } |
05e5e883 | 2175 | |
55de908a | 2176 | sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)]; |
f709fc69 | 2177 | |
a8243b72 | 2178 | if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
ef96a842 | 2179 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
d9fe60de | 2180 | elems.ht_cap_elem, &sta->sta.ht_cap); |
ae5eb026 | 2181 | |
64f68e5d JB |
2182 | sta->supports_40mhz = |
2183 | sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
2184 | ||
818255ea MP |
2185 | if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
2186 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, | |
2187 | elems.vht_cap_elem, | |
2188 | &sta->sta.vht_cap); | |
2189 | ||
4b7679a5 | 2190 | rate_control_rate_init(sta); |
f0706e82 | 2191 | |
46900298 | 2192 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) |
c2c98fde | 2193 | set_sta_flag(sta, WLAN_STA_MFP); |
5394af4d | 2194 | |
ddf4ac53 | 2195 | if (elems.wmm_param) |
c2c98fde | 2196 | set_sta_flag(sta, WLAN_STA_WME); |
ddf4ac53 | 2197 | |
c8987876 JB |
2198 | err = sta_info_move_state(sta, IEEE80211_STA_AUTH); |
2199 | if (!err) | |
2200 | err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); | |
2201 | if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) | |
2202 | err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); | |
2203 | if (err) { | |
bdcbd8e0 JB |
2204 | sdata_info(sdata, |
2205 | "failed to move station %pM to desired state\n", | |
2206 | sta->sta.addr); | |
c8987876 JB |
2207 | WARN_ON(__sta_info_destroy(sta)); |
2208 | mutex_unlock(&sdata->local->sta_mtx); | |
2209 | return false; | |
2210 | } | |
2211 | ||
7852e361 | 2212 | mutex_unlock(&sdata->local->sta_mtx); |
ddf4ac53 | 2213 | |
f2176d72 JO |
2214 | /* |
2215 | * Always handle WMM once after association regardless | |
2216 | * of the first value the AP uses. Setting -1 here has | |
2217 | * that effect because the AP values is an unsigned | |
2218 | * 4-bit value. | |
2219 | */ | |
2220 | ifmgd->wmm_last_param_set = -1; | |
2221 | ||
ddf4ac53 | 2222 | if (elems.wmm_param) |
4ced3f74 | 2223 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
60f8b39c | 2224 | elems.wmm_param_len); |
aa837e1d | 2225 | else |
3abead59 JB |
2226 | ieee80211_set_wmm_default(sdata, false); |
2227 | changed |= BSS_CHANGED_QOS; | |
f0706e82 | 2228 | |
074d46d1 | 2229 | if (elems.ht_operation && elems.wmm_param && |
a8243b72 | 2230 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
24398e39 JB |
2231 | changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation, |
2232 | cbss->bssid, false); | |
ae5eb026 | 2233 | |
60f8b39c JB |
2234 | /* set AID and assoc capability, |
2235 | * ieee80211_set_associated() will tell the driver */ | |
2236 | bss_conf->aid = aid; | |
2237 | bss_conf->assoc_capability = capab_info; | |
0c1ad2ca | 2238 | ieee80211_set_associated(sdata, cbss, changed); |
f0706e82 | 2239 | |
d524215f FF |
2240 | /* |
2241 | * If we're using 4-addr mode, let the AP know that we're | |
2242 | * doing so, so that it can create the STA VLAN on its side | |
2243 | */ | |
2244 | if (ifmgd->use_4addr) | |
2245 | ieee80211_send_4addr_nullfunc(local, sdata); | |
2246 | ||
15b7b062 | 2247 | /* |
b291ba11 JB |
2248 | * Start timer to probe the connection to the AP now. |
2249 | * Also start the timer that will detect beacon loss. | |
15b7b062 | 2250 | */ |
b291ba11 | 2251 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
d3a910a8 | 2252 | ieee80211_sta_reset_beacon_monitor(sdata); |
15b7b062 | 2253 | |
af6b6374 | 2254 | return true; |
f0706e82 JB |
2255 | } |
2256 | ||
66e67e41 JB |
2257 | static enum rx_mgmt_action __must_check |
2258 | ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, | |
2259 | struct ieee80211_mgmt *mgmt, size_t len, | |
2260 | struct cfg80211_bss **bss) | |
2261 | { | |
2262 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2263 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; | |
2264 | u16 capab_info, status_code, aid; | |
2265 | struct ieee802_11_elems elems; | |
2266 | u8 *pos; | |
2267 | bool reassoc; | |
2268 | ||
2269 | lockdep_assert_held(&ifmgd->mtx); | |
2270 | ||
2271 | if (!assoc_data) | |
2272 | return RX_MGMT_NONE; | |
b203ca39 | 2273 | if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid)) |
66e67e41 JB |
2274 | return RX_MGMT_NONE; |
2275 | ||
2276 | /* | |
2277 | * AssocResp and ReassocResp have identical structure, so process both | |
2278 | * of them in this function. | |
2279 | */ | |
2280 | ||
2281 | if (len < 24 + 6) | |
2282 | return RX_MGMT_NONE; | |
2283 | ||
2284 | reassoc = ieee80211_is_reassoc_req(mgmt->frame_control); | |
2285 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); | |
2286 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); | |
2287 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); | |
2288 | ||
bdcbd8e0 JB |
2289 | sdata_info(sdata, |
2290 | "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", | |
2291 | reassoc ? "Rea" : "A", mgmt->sa, | |
2292 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); | |
66e67e41 JB |
2293 | |
2294 | pos = mgmt->u.assoc_resp.variable; | |
2295 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); | |
2296 | ||
2297 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && | |
2298 | elems.timeout_int && elems.timeout_int_len == 5 && | |
2299 | elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) { | |
2300 | u32 tu, ms; | |
2301 | tu = get_unaligned_le32(elems.timeout_int + 1); | |
2302 | ms = tu * 1024 / 1000; | |
bdcbd8e0 JB |
2303 | sdata_info(sdata, |
2304 | "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", | |
2305 | mgmt->sa, tu, ms); | |
66e67e41 JB |
2306 | assoc_data->timeout = jiffies + msecs_to_jiffies(ms); |
2307 | if (ms > IEEE80211_ASSOC_TIMEOUT) | |
2308 | run_again(ifmgd, assoc_data->timeout); | |
2309 | return RX_MGMT_NONE; | |
2310 | } | |
2311 | ||
2312 | *bss = assoc_data->bss; | |
2313 | ||
2314 | if (status_code != WLAN_STATUS_SUCCESS) { | |
bdcbd8e0 JB |
2315 | sdata_info(sdata, "%pM denied association (code=%d)\n", |
2316 | mgmt->sa, status_code); | |
66e67e41 JB |
2317 | ieee80211_destroy_assoc_data(sdata, false); |
2318 | } else { | |
66e67e41 JB |
2319 | if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) { |
2320 | /* oops -- internal error -- send timeout for now */ | |
10a9109f | 2321 | ieee80211_destroy_assoc_data(sdata, false); |
66e67e41 JB |
2322 | cfg80211_put_bss(*bss); |
2323 | return RX_MGMT_CFG80211_ASSOC_TIMEOUT; | |
2324 | } | |
635d999f | 2325 | sdata_info(sdata, "associated\n"); |
79ebfb85 JB |
2326 | |
2327 | /* | |
2328 | * destroy assoc_data afterwards, as otherwise an idle | |
2329 | * recalc after assoc_data is NULL but before associated | |
2330 | * is set can cause the interface to go idle | |
2331 | */ | |
2332 | ieee80211_destroy_assoc_data(sdata, true); | |
66e67e41 JB |
2333 | } |
2334 | ||
2335 | return RX_MGMT_CFG80211_RX_ASSOC; | |
2336 | } | |
98c8fccf JB |
2337 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
2338 | struct ieee80211_mgmt *mgmt, | |
2339 | size_t len, | |
2340 | struct ieee80211_rx_status *rx_status, | |
2341 | struct ieee802_11_elems *elems, | |
2342 | bool beacon) | |
2343 | { | |
2344 | struct ieee80211_local *local = sdata->local; | |
2345 | int freq; | |
c2b13452 | 2346 | struct ieee80211_bss *bss; |
98c8fccf | 2347 | struct ieee80211_channel *channel; |
56007a02 JB |
2348 | bool need_ps = false; |
2349 | ||
66e67e41 | 2350 | if (sdata->u.mgd.associated && |
b203ca39 | 2351 | ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) { |
56007a02 JB |
2352 | bss = (void *)sdata->u.mgd.associated->priv; |
2353 | /* not previously set so we may need to recalc */ | |
2354 | need_ps = !bss->dtim_period; | |
2355 | } | |
98c8fccf JB |
2356 | |
2357 | if (elems->ds_params && elems->ds_params_len == 1) | |
59eb21a6 BR |
2358 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], |
2359 | rx_status->band); | |
98c8fccf JB |
2360 | else |
2361 | freq = rx_status->freq; | |
2362 | ||
2363 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
2364 | ||
2365 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
2366 | return; | |
2367 | ||
98c8fccf | 2368 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
2a519311 | 2369 | channel, beacon); |
77fdaa12 JB |
2370 | if (bss) |
2371 | ieee80211_rx_bss_put(local, bss); | |
2372 | ||
2373 | if (!sdata->u.mgd.associated) | |
98c8fccf JB |
2374 | return; |
2375 | ||
56007a02 JB |
2376 | if (need_ps) { |
2377 | mutex_lock(&local->iflist_mtx); | |
2378 | ieee80211_recalc_ps(local, -1); | |
2379 | mutex_unlock(&local->iflist_mtx); | |
2380 | } | |
2381 | ||
5bc1420b JB |
2382 | if (elems->ch_switch_ie && |
2383 | memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0) | |
2384 | ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie, | |
5ce6e438 | 2385 | bss, rx_status->mactime); |
f0706e82 JB |
2386 | } |
2387 | ||
2388 | ||
f698d856 | 2389 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
af6b6374 | 2390 | struct sk_buff *skb) |
f0706e82 | 2391 | { |
af6b6374 | 2392 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
15b7b062 | 2393 | struct ieee80211_if_managed *ifmgd; |
af6b6374 JB |
2394 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
2395 | size_t baselen, len = skb->len; | |
ae6a44e3 EK |
2396 | struct ieee802_11_elems elems; |
2397 | ||
15b7b062 KV |
2398 | ifmgd = &sdata->u.mgd; |
2399 | ||
77fdaa12 JB |
2400 | ASSERT_MGD_MTX(ifmgd); |
2401 | ||
b203ca39 | 2402 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) |
8e7cdbb6 TW |
2403 | return; /* ignore ProbeResp to foreign address */ |
2404 | ||
ae6a44e3 EK |
2405 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
2406 | if (baselen > len) | |
2407 | return; | |
2408 | ||
2409 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
2410 | &elems); | |
2411 | ||
98c8fccf | 2412 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
9859b81e | 2413 | |
77fdaa12 | 2414 | if (ifmgd->associated && |
b203ca39 | 2415 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
4e5ff376 | 2416 | ieee80211_reset_ap_probe(sdata); |
66e67e41 JB |
2417 | |
2418 | if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies && | |
b203ca39 | 2419 | ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) { |
66e67e41 | 2420 | /* got probe response, continue with auth */ |
bdcbd8e0 | 2421 | sdata_info(sdata, "direct probe responded\n"); |
66e67e41 JB |
2422 | ifmgd->auth_data->tries = 0; |
2423 | ifmgd->auth_data->timeout = jiffies; | |
2424 | run_again(ifmgd, ifmgd->auth_data->timeout); | |
2425 | } | |
f0706e82 JB |
2426 | } |
2427 | ||
d91f36db JB |
2428 | /* |
2429 | * This is the canonical list of information elements we care about, | |
2430 | * the filter code also gives us all changes to the Microsoft OUI | |
2431 | * (00:50:F2) vendor IE which is used for WMM which we need to track. | |
2432 | * | |
2433 | * We implement beacon filtering in software since that means we can | |
2434 | * avoid processing the frame here and in cfg80211, and userspace | |
2435 | * will not be able to tell whether the hardware supports it or not. | |
2436 | * | |
2437 | * XXX: This list needs to be dynamic -- userspace needs to be able to | |
2438 | * add items it requires. It also needs to be able to tell us to | |
2439 | * look out for other vendor IEs. | |
2440 | */ | |
2441 | static const u64 care_about_ies = | |
1d4df3a5 JB |
2442 | (1ULL << WLAN_EID_COUNTRY) | |
2443 | (1ULL << WLAN_EID_ERP_INFO) | | |
2444 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | | |
2445 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | | |
2446 | (1ULL << WLAN_EID_HT_CAPABILITY) | | |
074d46d1 | 2447 | (1ULL << WLAN_EID_HT_OPERATION); |
d91f36db | 2448 | |
f698d856 | 2449 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2450 | struct ieee80211_mgmt *mgmt, |
2451 | size_t len, | |
2452 | struct ieee80211_rx_status *rx_status) | |
2453 | { | |
d91f36db | 2454 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
17e4ec14 | 2455 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
f0706e82 JB |
2456 | size_t baselen; |
2457 | struct ieee802_11_elems elems; | |
f698d856 | 2458 | struct ieee80211_local *local = sdata->local; |
55de908a JB |
2459 | struct ieee80211_chanctx_conf *chanctx_conf; |
2460 | struct ieee80211_channel *chan; | |
471b3efd | 2461 | u32 changed = 0; |
f87ad637 | 2462 | bool erp_valid; |
7a5158ef | 2463 | u8 erp_value = 0; |
d91f36db | 2464 | u32 ncrc; |
77fdaa12 JB |
2465 | u8 *bssid; |
2466 | ||
66e67e41 | 2467 | lockdep_assert_held(&ifmgd->mtx); |
f0706e82 | 2468 | |
ae6a44e3 EK |
2469 | /* Process beacon from the current BSS */ |
2470 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | |
2471 | if (baselen > len) | |
2472 | return; | |
2473 | ||
55de908a JB |
2474 | rcu_read_lock(); |
2475 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
2476 | if (!chanctx_conf) { | |
2477 | rcu_read_unlock(); | |
f0706e82 | 2478 | return; |
55de908a JB |
2479 | } |
2480 | ||
4bf88530 | 2481 | if (rx_status->freq != chanctx_conf->def.chan->center_freq) { |
55de908a JB |
2482 | rcu_read_unlock(); |
2483 | return; | |
2484 | } | |
4bf88530 | 2485 | chan = chanctx_conf->def.chan; |
55de908a | 2486 | rcu_read_unlock(); |
f0706e82 | 2487 | |
66e67e41 | 2488 | if (ifmgd->assoc_data && !ifmgd->assoc_data->have_beacon && |
b203ca39 | 2489 | ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { |
66e67e41 JB |
2490 | ieee802_11_parse_elems(mgmt->u.beacon.variable, |
2491 | len - baselen, &elems); | |
77fdaa12 | 2492 | |
66e67e41 JB |
2493 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
2494 | false); | |
2495 | ifmgd->assoc_data->have_beacon = true; | |
2496 | ifmgd->assoc_data->sent_assoc = false; | |
2497 | /* continue assoc process */ | |
2498 | ifmgd->assoc_data->timeout = jiffies; | |
2499 | run_again(ifmgd, ifmgd->assoc_data->timeout); | |
2500 | return; | |
2501 | } | |
77fdaa12 | 2502 | |
66e67e41 | 2503 | if (!ifmgd->associated || |
b203ca39 | 2504 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
f0706e82 | 2505 | return; |
66e67e41 | 2506 | bssid = ifmgd->associated->bssid; |
f0706e82 | 2507 | |
17e4ec14 JM |
2508 | /* Track average RSSI from the Beacon frames of the current AP */ |
2509 | ifmgd->last_beacon_signal = rx_status->signal; | |
2510 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { | |
2511 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; | |
3ba06c6f | 2512 | ifmgd->ave_beacon_signal = rx_status->signal * 16; |
17e4ec14 | 2513 | ifmgd->last_cqm_event_signal = 0; |
391a200a | 2514 | ifmgd->count_beacon_signal = 1; |
615f7b9b | 2515 | ifmgd->last_ave_beacon_signal = 0; |
17e4ec14 JM |
2516 | } else { |
2517 | ifmgd->ave_beacon_signal = | |
2518 | (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 + | |
2519 | (16 - IEEE80211_SIGNAL_AVE_WEIGHT) * | |
2520 | ifmgd->ave_beacon_signal) / 16; | |
391a200a | 2521 | ifmgd->count_beacon_signal++; |
17e4ec14 | 2522 | } |
615f7b9b MV |
2523 | |
2524 | if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && | |
2525 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { | |
2526 | int sig = ifmgd->ave_beacon_signal; | |
2527 | int last_sig = ifmgd->last_ave_beacon_signal; | |
2528 | ||
2529 | /* | |
2530 | * if signal crosses either of the boundaries, invoke callback | |
2531 | * with appropriate parameters | |
2532 | */ | |
2533 | if (sig > ifmgd->rssi_max_thold && | |
2534 | (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { | |
2535 | ifmgd->last_ave_beacon_signal = sig; | |
2536 | drv_rssi_callback(local, RSSI_EVENT_HIGH); | |
2537 | } else if (sig < ifmgd->rssi_min_thold && | |
2538 | (last_sig >= ifmgd->rssi_max_thold || | |
2539 | last_sig == 0)) { | |
2540 | ifmgd->last_ave_beacon_signal = sig; | |
2541 | drv_rssi_callback(local, RSSI_EVENT_LOW); | |
2542 | } | |
2543 | } | |
2544 | ||
17e4ec14 | 2545 | if (bss_conf->cqm_rssi_thold && |
391a200a | 2546 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
ea086359 | 2547 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { |
17e4ec14 JM |
2548 | int sig = ifmgd->ave_beacon_signal / 16; |
2549 | int last_event = ifmgd->last_cqm_event_signal; | |
2550 | int thold = bss_conf->cqm_rssi_thold; | |
2551 | int hyst = bss_conf->cqm_rssi_hyst; | |
2552 | if (sig < thold && | |
2553 | (last_event == 0 || sig < last_event - hyst)) { | |
2554 | ifmgd->last_cqm_event_signal = sig; | |
2555 | ieee80211_cqm_rssi_notify( | |
2556 | &sdata->vif, | |
2557 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, | |
2558 | GFP_KERNEL); | |
2559 | } else if (sig > thold && | |
2560 | (last_event == 0 || sig > last_event + hyst)) { | |
2561 | ifmgd->last_cqm_event_signal = sig; | |
2562 | ieee80211_cqm_rssi_notify( | |
2563 | &sdata->vif, | |
2564 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, | |
2565 | GFP_KERNEL); | |
2566 | } | |
2567 | } | |
2568 | ||
b291ba11 | 2569 | if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) { |
bdcbd8e0 JB |
2570 | mlme_dbg_ratelimited(sdata, |
2571 | "cancelling probereq poll due to a received beacon\n"); | |
925e64c3 | 2572 | mutex_lock(&local->mtx); |
b291ba11 | 2573 | ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; |
925e64c3 SG |
2574 | ieee80211_run_deferred_scan(local); |
2575 | mutex_unlock(&local->mtx); | |
2576 | ||
4e751843 JB |
2577 | mutex_lock(&local->iflist_mtx); |
2578 | ieee80211_recalc_ps(local, -1); | |
2579 | mutex_unlock(&local->iflist_mtx); | |
92778180 JM |
2580 | } |
2581 | ||
b291ba11 JB |
2582 | /* |
2583 | * Push the beacon loss detection into the future since | |
2584 | * we are processing a beacon from the AP just now. | |
2585 | */ | |
d3a910a8 | 2586 | ieee80211_sta_reset_beacon_monitor(sdata); |
b291ba11 | 2587 | |
d91f36db JB |
2588 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
2589 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, | |
2590 | len - baselen, &elems, | |
2591 | care_about_ies, ncrc); | |
2592 | ||
25c9c875 | 2593 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { |
f87ad637 RR |
2594 | bool directed_tim = ieee80211_check_tim(elems.tim, |
2595 | elems.tim_len, | |
2596 | ifmgd->aid); | |
1fb3606b | 2597 | if (directed_tim) { |
572e0012 | 2598 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
70b12f26 RW |
2599 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
2600 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
2601 | ieee80211_hw_config(local, | |
2602 | IEEE80211_CONF_CHANGE_PS); | |
2603 | } | |
572e0012 | 2604 | ieee80211_send_nullfunc(local, sdata, 0); |
6f0756a3 | 2605 | } else if (!local->pspolling && sdata->u.mgd.powersave) { |
572e0012 KV |
2606 | local->pspolling = true; |
2607 | ||
2608 | /* | |
2609 | * Here is assumed that the driver will be | |
2610 | * able to send ps-poll frame and receive a | |
2611 | * response even though power save mode is | |
2612 | * enabled, but some drivers might require | |
2613 | * to disable power save here. This needs | |
2614 | * to be investigated. | |
2615 | */ | |
2616 | ieee80211_send_pspoll(local, sdata); | |
2617 | } | |
a97b77b9 VN |
2618 | } |
2619 | } | |
7a5158ef | 2620 | |
488dd7b5 JB |
2621 | if (sdata->vif.p2p) { |
2622 | u8 noa[2]; | |
2623 | int ret; | |
2624 | ||
2625 | ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable, | |
2626 | len - baselen, | |
2627 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, | |
2628 | noa, sizeof(noa)); | |
2629 | if (ret >= 2 && sdata->u.mgd.p2p_noa_index != noa[0]) { | |
2630 | bss_conf->p2p_oppps = noa[1] & 0x80; | |
2631 | bss_conf->p2p_ctwindow = noa[1] & 0x7f; | |
2632 | changed |= BSS_CHANGED_P2P_PS; | |
2633 | sdata->u.mgd.p2p_noa_index = noa[0]; | |
2634 | /* | |
2635 | * make sure we update all information, the CRC | |
2636 | * mechanism doesn't look at P2P attributes. | |
2637 | */ | |
2638 | ifmgd->beacon_crc_valid = false; | |
2639 | } | |
2640 | } | |
2641 | ||
d8ec4433 | 2642 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
30196673 JM |
2643 | return; |
2644 | ifmgd->beacon_crc = ncrc; | |
d8ec4433 | 2645 | ifmgd->beacon_crc_valid = true; |
30196673 | 2646 | |
7d25745d JB |
2647 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
2648 | true); | |
2649 | ||
2650 | if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, | |
2651 | elems.wmm_param_len)) | |
2652 | changed |= BSS_CHANGED_QOS; | |
2653 | ||
7a5158ef JB |
2654 | if (elems.erp_info && elems.erp_info_len >= 1) { |
2655 | erp_valid = true; | |
2656 | erp_value = elems.erp_info[0]; | |
2657 | } else { | |
2658 | erp_valid = false; | |
50c4afb9 | 2659 | } |
7a5158ef JB |
2660 | changed |= ieee80211_handle_bss_capability(sdata, |
2661 | le16_to_cpu(mgmt->u.beacon.capab_info), | |
2662 | erp_valid, erp_value); | |
f0706e82 | 2663 | |
d3c990fb | 2664 | |
074d46d1 | 2665 | if (elems.ht_cap_elem && elems.ht_operation && elems.wmm_param && |
a8243b72 | 2666 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
24398e39 JB |
2667 | changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation, |
2668 | bssid, true); | |
d3c990fb | 2669 | |
04b7b2ff JB |
2670 | if (elems.country_elem && elems.pwr_constr_elem && |
2671 | mgmt->u.probe_resp.capab_info & | |
2672 | cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) | |
1ea6f9c0 JB |
2673 | changed |= ieee80211_handle_pwr_constr(sdata, chan, |
2674 | elems.country_elem, | |
2675 | elems.country_elem_len, | |
2676 | elems.pwr_constr_elem); | |
3f2355cb | 2677 | |
471b3efd | 2678 | ieee80211_bss_info_change_notify(sdata, changed); |
f0706e82 JB |
2679 | } |
2680 | ||
1fa57d01 JB |
2681 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
2682 | struct sk_buff *skb) | |
f0706e82 | 2683 | { |
77fdaa12 | 2684 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 | 2685 | struct ieee80211_rx_status *rx_status; |
f0706e82 | 2686 | struct ieee80211_mgmt *mgmt; |
66e67e41 | 2687 | struct cfg80211_bss *bss = NULL; |
77fdaa12 | 2688 | enum rx_mgmt_action rma = RX_MGMT_NONE; |
f0706e82 JB |
2689 | u16 fc; |
2690 | ||
f0706e82 JB |
2691 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
2692 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
2693 | fc = le16_to_cpu(mgmt->frame_control); | |
2694 | ||
77fdaa12 JB |
2695 | mutex_lock(&ifmgd->mtx); |
2696 | ||
66e67e41 JB |
2697 | switch (fc & IEEE80211_FCTL_STYPE) { |
2698 | case IEEE80211_STYPE_BEACON: | |
2699 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); | |
2700 | break; | |
2701 | case IEEE80211_STYPE_PROBE_RESP: | |
2702 | ieee80211_rx_mgmt_probe_resp(sdata, skb); | |
2703 | break; | |
2704 | case IEEE80211_STYPE_AUTH: | |
2705 | rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); | |
2706 | break; | |
2707 | case IEEE80211_STYPE_DEAUTH: | |
2708 | rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); | |
2709 | break; | |
2710 | case IEEE80211_STYPE_DISASSOC: | |
2711 | rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); | |
2712 | break; | |
2713 | case IEEE80211_STYPE_ASSOC_RESP: | |
2714 | case IEEE80211_STYPE_REASSOC_RESP: | |
2715 | rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss); | |
2716 | break; | |
2717 | case IEEE80211_STYPE_ACTION: | |
2718 | switch (mgmt->u.action.category) { | |
2719 | case WLAN_CATEGORY_SPECTRUM_MGMT: | |
2720 | ieee80211_sta_process_chanswitch(sdata, | |
2721 | &mgmt->u.action.u.chan_switch.sw_elem, | |
2722 | (void *)ifmgd->associated->priv, | |
2723 | rx_status->mactime); | |
77fdaa12 | 2724 | break; |
77fdaa12 | 2725 | } |
77fdaa12 | 2726 | } |
77fdaa12 JB |
2727 | mutex_unlock(&ifmgd->mtx); |
2728 | ||
66e67e41 JB |
2729 | switch (rma) { |
2730 | case RX_MGMT_NONE: | |
2731 | /* no action */ | |
2732 | break; | |
2733 | case RX_MGMT_CFG80211_DEAUTH: | |
ce470613 | 2734 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
66e67e41 JB |
2735 | break; |
2736 | case RX_MGMT_CFG80211_DISASSOC: | |
2737 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); | |
2738 | break; | |
2739 | case RX_MGMT_CFG80211_RX_AUTH: | |
2740 | cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len); | |
2741 | break; | |
2742 | case RX_MGMT_CFG80211_RX_ASSOC: | |
2743 | cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len); | |
2744 | break; | |
2745 | case RX_MGMT_CFG80211_ASSOC_TIMEOUT: | |
2746 | cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid); | |
2747 | break; | |
2748 | default: | |
2749 | WARN(1, "unexpected: %d", rma); | |
b054b747 | 2750 | } |
f0706e82 JB |
2751 | } |
2752 | ||
9c6bd790 | 2753 | static void ieee80211_sta_timer(unsigned long data) |
f0706e82 | 2754 | { |
60f8b39c JB |
2755 | struct ieee80211_sub_if_data *sdata = |
2756 | (struct ieee80211_sub_if_data *) data; | |
46900298 | 2757 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
60f8b39c | 2758 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 2759 | |
5bb644a0 JB |
2760 | if (local->quiescing) { |
2761 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); | |
2762 | return; | |
2763 | } | |
2764 | ||
64592c8f | 2765 | ieee80211_queue_work(&local->hw, &sdata->work); |
f0706e82 JB |
2766 | } |
2767 | ||
04ac3c0e | 2768 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
95acac61 | 2769 | u8 *bssid, u8 reason) |
04ac3c0e FF |
2770 | { |
2771 | struct ieee80211_local *local = sdata->local; | |
2772 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
6ae16775 | 2773 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
04ac3c0e | 2774 | |
37ad3888 JB |
2775 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, |
2776 | false, frame_buf); | |
04ac3c0e | 2777 | mutex_unlock(&ifmgd->mtx); |
37ad3888 | 2778 | |
04ac3c0e FF |
2779 | /* |
2780 | * must be outside lock due to cfg80211, | |
2781 | * but that's not a problem. | |
2782 | */ | |
6ae16775 | 2783 | cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN); |
fcac4fb0 FF |
2784 | |
2785 | mutex_lock(&local->mtx); | |
2786 | ieee80211_recalc_idle(local); | |
2787 | mutex_unlock(&local->mtx); | |
2788 | ||
04ac3c0e FF |
2789 | mutex_lock(&ifmgd->mtx); |
2790 | } | |
2791 | ||
66e67e41 JB |
2792 | static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata) |
2793 | { | |
2794 | struct ieee80211_local *local = sdata->local; | |
2795 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2796 | struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; | |
2797 | ||
2798 | lockdep_assert_held(&ifmgd->mtx); | |
2799 | ||
2800 | if (WARN_ON_ONCE(!auth_data)) | |
2801 | return -EINVAL; | |
2802 | ||
66e67e41 JB |
2803 | auth_data->tries++; |
2804 | ||
2805 | if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { | |
bdcbd8e0 JB |
2806 | sdata_info(sdata, "authentication with %pM timed out\n", |
2807 | auth_data->bss->bssid); | |
66e67e41 JB |
2808 | |
2809 | /* | |
2810 | * Most likely AP is not in the range so remove the | |
2811 | * bss struct for that AP. | |
2812 | */ | |
2813 | cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); | |
2814 | ||
2815 | return -ETIMEDOUT; | |
2816 | } | |
2817 | ||
a1845fc7 JB |
2818 | drv_mgd_prepare_tx(local, sdata); |
2819 | ||
66e67e41 | 2820 | if (auth_data->bss->proberesp_ies) { |
6b8ece3a JM |
2821 | u16 trans = 1; |
2822 | u16 status = 0; | |
2823 | ||
bdcbd8e0 JB |
2824 | sdata_info(sdata, "send auth to %pM (try %d/%d)\n", |
2825 | auth_data->bss->bssid, auth_data->tries, | |
2826 | IEEE80211_AUTH_MAX_TRIES); | |
66e67e41 JB |
2827 | |
2828 | auth_data->expected_transaction = 2; | |
6b8ece3a JM |
2829 | |
2830 | if (auth_data->algorithm == WLAN_AUTH_SAE) { | |
2831 | trans = auth_data->sae_trans; | |
2832 | status = auth_data->sae_status; | |
2833 | auth_data->expected_transaction = trans; | |
2834 | } | |
2835 | ||
2836 | ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, | |
2837 | auth_data->data, auth_data->data_len, | |
66e67e41 JB |
2838 | auth_data->bss->bssid, |
2839 | auth_data->bss->bssid, NULL, 0, 0); | |
2840 | } else { | |
2841 | const u8 *ssidie; | |
2842 | ||
bdcbd8e0 JB |
2843 | sdata_info(sdata, "direct probe to %pM (try %d/%i)\n", |
2844 | auth_data->bss->bssid, auth_data->tries, | |
2845 | IEEE80211_AUTH_MAX_TRIES); | |
66e67e41 JB |
2846 | |
2847 | ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID); | |
2848 | if (!ssidie) | |
2849 | return -EINVAL; | |
2850 | /* | |
2851 | * Direct probe is sent to broadcast address as some APs | |
2852 | * will not answer to direct packet in unassociated state. | |
2853 | */ | |
2854 | ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1], | |
fe94fe05 | 2855 | NULL, 0, (u32) -1, true, false, |
55de908a | 2856 | auth_data->bss->channel, false); |
66e67e41 JB |
2857 | } |
2858 | ||
2859 | auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; | |
2860 | run_again(ifmgd, auth_data->timeout); | |
2861 | ||
2862 | return 0; | |
2863 | } | |
2864 | ||
2865 | static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) | |
2866 | { | |
2867 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; | |
2868 | struct ieee80211_local *local = sdata->local; | |
2869 | ||
2870 | lockdep_assert_held(&sdata->u.mgd.mtx); | |
2871 | ||
66e67e41 JB |
2872 | assoc_data->tries++; |
2873 | if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { | |
bdcbd8e0 JB |
2874 | sdata_info(sdata, "association with %pM timed out\n", |
2875 | assoc_data->bss->bssid); | |
66e67e41 JB |
2876 | |
2877 | /* | |
2878 | * Most likely AP is not in the range so remove the | |
2879 | * bss struct for that AP. | |
2880 | */ | |
2881 | cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss); | |
2882 | ||
2883 | return -ETIMEDOUT; | |
2884 | } | |
2885 | ||
bdcbd8e0 JB |
2886 | sdata_info(sdata, "associate with %pM (try %d/%d)\n", |
2887 | assoc_data->bss->bssid, assoc_data->tries, | |
2888 | IEEE80211_ASSOC_MAX_TRIES); | |
66e67e41 JB |
2889 | ieee80211_send_assoc(sdata); |
2890 | ||
2891 | assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; | |
2892 | run_again(&sdata->u.mgd, assoc_data->timeout); | |
2893 | ||
2894 | return 0; | |
2895 | } | |
2896 | ||
1fa57d01 | 2897 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
9c6bd790 | 2898 | { |
9c6bd790 | 2899 | struct ieee80211_local *local = sdata->local; |
1fa57d01 | 2900 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
9c6bd790 | 2901 | |
77fdaa12 JB |
2902 | mutex_lock(&ifmgd->mtx); |
2903 | ||
66e67e41 JB |
2904 | if (ifmgd->auth_data && |
2905 | time_after(jiffies, ifmgd->auth_data->timeout)) { | |
2906 | if (ifmgd->auth_data->done) { | |
2907 | /* | |
2908 | * ok ... we waited for assoc but userspace didn't, | |
2909 | * so let's just kill the auth data | |
2910 | */ | |
2911 | ieee80211_destroy_auth_data(sdata, false); | |
2912 | } else if (ieee80211_probe_auth(sdata)) { | |
2913 | u8 bssid[ETH_ALEN]; | |
2914 | ||
2915 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); | |
2916 | ||
2917 | ieee80211_destroy_auth_data(sdata, false); | |
2918 | ||
2919 | mutex_unlock(&ifmgd->mtx); | |
2920 | cfg80211_send_auth_timeout(sdata->dev, bssid); | |
2921 | mutex_lock(&ifmgd->mtx); | |
2922 | } | |
2923 | } else if (ifmgd->auth_data) | |
2924 | run_again(ifmgd, ifmgd->auth_data->timeout); | |
2925 | ||
2926 | if (ifmgd->assoc_data && | |
2927 | time_after(jiffies, ifmgd->assoc_data->timeout)) { | |
2928 | if (!ifmgd->assoc_data->have_beacon || | |
2929 | ieee80211_do_assoc(sdata)) { | |
2930 | u8 bssid[ETH_ALEN]; | |
2931 | ||
2932 | memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN); | |
2933 | ||
2934 | ieee80211_destroy_assoc_data(sdata, false); | |
2935 | ||
2936 | mutex_unlock(&ifmgd->mtx); | |
2937 | cfg80211_send_assoc_timeout(sdata->dev, bssid); | |
2938 | mutex_lock(&ifmgd->mtx); | |
2939 | } | |
2940 | } else if (ifmgd->assoc_data) | |
2941 | run_again(ifmgd, ifmgd->assoc_data->timeout); | |
2942 | ||
b291ba11 JB |
2943 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
2944 | IEEE80211_STA_CONNECTION_POLL) && | |
2945 | ifmgd->associated) { | |
a43abf29 | 2946 | u8 bssid[ETH_ALEN]; |
72a8a3ed | 2947 | int max_tries; |
a43abf29 | 2948 | |
0c1ad2ca | 2949 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
4e5ff376 | 2950 | |
72a8a3ed | 2951 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
180205bd | 2952 | max_tries = max_nullfunc_tries; |
72a8a3ed | 2953 | else |
180205bd | 2954 | max_tries = max_probe_tries; |
72a8a3ed | 2955 | |
4e5ff376 FF |
2956 | /* ACK received for nullfunc probing frame */ |
2957 | if (!ifmgd->probe_send_count) | |
2958 | ieee80211_reset_ap_probe(sdata); | |
04ac3c0e FF |
2959 | else if (ifmgd->nullfunc_failed) { |
2960 | if (ifmgd->probe_send_count < max_tries) { | |
bdcbd8e0 JB |
2961 | mlme_dbg(sdata, |
2962 | "No ack for nullfunc frame to AP %pM, try %d/%i\n", | |
2963 | bssid, ifmgd->probe_send_count, | |
2964 | max_tries); | |
04ac3c0e FF |
2965 | ieee80211_mgd_probe_ap_send(sdata); |
2966 | } else { | |
bdcbd8e0 JB |
2967 | mlme_dbg(sdata, |
2968 | "No ack for nullfunc frame to AP %pM, disconnecting.\n", | |
2969 | bssid); | |
95acac61 JB |
2970 | ieee80211_sta_connection_lost(sdata, bssid, |
2971 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); | |
04ac3c0e FF |
2972 | } |
2973 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) | |
b291ba11 | 2974 | run_again(ifmgd, ifmgd->probe_timeout); |
04ac3c0e | 2975 | else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
bdcbd8e0 JB |
2976 | mlme_dbg(sdata, |
2977 | "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", | |
2978 | bssid, probe_wait_ms); | |
95acac61 JB |
2979 | ieee80211_sta_connection_lost(sdata, bssid, |
2980 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); | |
04ac3c0e | 2981 | } else if (ifmgd->probe_send_count < max_tries) { |
bdcbd8e0 JB |
2982 | mlme_dbg(sdata, |
2983 | "No probe response from AP %pM after %dms, try %d/%i\n", | |
2984 | bssid, probe_wait_ms, | |
2985 | ifmgd->probe_send_count, max_tries); | |
a43abf29 ML |
2986 | ieee80211_mgd_probe_ap_send(sdata); |
2987 | } else { | |
b291ba11 JB |
2988 | /* |
2989 | * We actually lost the connection ... or did we? | |
2990 | * Let's make sure! | |
2991 | */ | |
b38afa87 BG |
2992 | wiphy_debug(local->hw.wiphy, |
2993 | "%s: No probe response from AP %pM" | |
2994 | " after %dms, disconnecting.\n", | |
2995 | sdata->name, | |
180205bd | 2996 | bssid, probe_wait_ms); |
04ac3c0e | 2997 | |
95acac61 JB |
2998 | ieee80211_sta_connection_lost(sdata, bssid, |
2999 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); | |
b291ba11 JB |
3000 | } |
3001 | } | |
3002 | ||
77fdaa12 | 3003 | mutex_unlock(&ifmgd->mtx); |
66e67e41 JB |
3004 | |
3005 | mutex_lock(&local->mtx); | |
3006 | ieee80211_recalc_idle(local); | |
3007 | mutex_unlock(&local->mtx); | |
f0706e82 JB |
3008 | } |
3009 | ||
b291ba11 JB |
3010 | static void ieee80211_sta_bcn_mon_timer(unsigned long data) |
3011 | { | |
3012 | struct ieee80211_sub_if_data *sdata = | |
3013 | (struct ieee80211_sub_if_data *) data; | |
3014 | struct ieee80211_local *local = sdata->local; | |
3015 | ||
3016 | if (local->quiescing) | |
3017 | return; | |
3018 | ||
1e4dcd01 JO |
3019 | ieee80211_queue_work(&sdata->local->hw, |
3020 | &sdata->u.mgd.beacon_connection_loss_work); | |
b291ba11 JB |
3021 | } |
3022 | ||
3023 | static void ieee80211_sta_conn_mon_timer(unsigned long data) | |
3024 | { | |
3025 | struct ieee80211_sub_if_data *sdata = | |
3026 | (struct ieee80211_sub_if_data *) data; | |
3027 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3028 | struct ieee80211_local *local = sdata->local; | |
3029 | ||
3030 | if (local->quiescing) | |
3031 | return; | |
3032 | ||
42935eca | 3033 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
b291ba11 JB |
3034 | } |
3035 | ||
3036 | static void ieee80211_sta_monitor_work(struct work_struct *work) | |
3037 | { | |
3038 | struct ieee80211_sub_if_data *sdata = | |
3039 | container_of(work, struct ieee80211_sub_if_data, | |
3040 | u.mgd.monitor_work); | |
3041 | ||
3042 | ieee80211_mgd_probe_ap(sdata, false); | |
3043 | } | |
3044 | ||
9c6bd790 JB |
3045 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
3046 | { | |
494f1fe5 EP |
3047 | u32 flags; |
3048 | ||
ad935687 | 3049 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
925e64c3 | 3050 | __ieee80211_stop_poll(sdata); |
ad935687 | 3051 | |
b291ba11 | 3052 | /* let's probe the connection once */ |
494f1fe5 EP |
3053 | flags = sdata->local->hw.flags; |
3054 | if (!(flags & IEEE80211_HW_CONNECTION_MONITOR)) | |
3055 | ieee80211_queue_work(&sdata->local->hw, | |
3056 | &sdata->u.mgd.monitor_work); | |
b291ba11 | 3057 | /* and do all the other regular work too */ |
64592c8f | 3058 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
ad935687 | 3059 | } |
9c6bd790 | 3060 | } |
f0706e82 | 3061 | |
5bb644a0 JB |
3062 | #ifdef CONFIG_PM |
3063 | void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata) | |
3064 | { | |
3065 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3066 | ||
3067 | /* | |
3068 | * we need to use atomic bitops for the running bits | |
3069 | * only because both timers might fire at the same | |
3070 | * time -- the code here is properly synchronised. | |
3071 | */ | |
3072 | ||
d1f5b7a3 JB |
3073 | cancel_work_sync(&ifmgd->request_smps_work); |
3074 | ||
0ecfe806 | 3075 | cancel_work_sync(&ifmgd->monitor_work); |
1e4dcd01 | 3076 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
882a7c69 | 3077 | cancel_work_sync(&ifmgd->csa_connection_drop_work); |
5bb644a0 JB |
3078 | if (del_timer_sync(&ifmgd->timer)) |
3079 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); | |
3080 | ||
3081 | cancel_work_sync(&ifmgd->chswitch_work); | |
3082 | if (del_timer_sync(&ifmgd->chswitch_timer)) | |
3083 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); | |
b291ba11 | 3084 | |
b291ba11 JB |
3085 | /* these will just be re-established on connection */ |
3086 | del_timer_sync(&ifmgd->conn_mon_timer); | |
3087 | del_timer_sync(&ifmgd->bcn_mon_timer); | |
5bb644a0 JB |
3088 | } |
3089 | ||
3090 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) | |
3091 | { | |
3092 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3093 | ||
676b58c2 RM |
3094 | if (!ifmgd->associated) |
3095 | return; | |
3096 | ||
95acac61 JB |
3097 | if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { |
3098 | sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; | |
3099 | mutex_lock(&ifmgd->mtx); | |
3100 | if (ifmgd->associated) { | |
bdcbd8e0 JB |
3101 | mlme_dbg(sdata, |
3102 | "driver requested disconnect after resume\n"); | |
95acac61 JB |
3103 | ieee80211_sta_connection_lost(sdata, |
3104 | ifmgd->associated->bssid, | |
3105 | WLAN_REASON_UNSPECIFIED); | |
3106 | mutex_unlock(&ifmgd->mtx); | |
3107 | return; | |
3108 | } | |
3109 | mutex_unlock(&ifmgd->mtx); | |
3110 | } | |
3111 | ||
5bb644a0 JB |
3112 | if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running)) |
3113 | add_timer(&ifmgd->timer); | |
3114 | if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running)) | |
3115 | add_timer(&ifmgd->chswitch_timer); | |
c8a7972c | 3116 | ieee80211_sta_reset_beacon_monitor(sdata); |
925e64c3 SG |
3117 | |
3118 | mutex_lock(&sdata->local->mtx); | |
46090979 | 3119 | ieee80211_restart_sta_timer(sdata); |
925e64c3 | 3120 | mutex_unlock(&sdata->local->mtx); |
5bb644a0 JB |
3121 | } |
3122 | #endif | |
3123 | ||
9c6bd790 JB |
3124 | /* interface setup */ |
3125 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) | |
f0706e82 | 3126 | { |
46900298 | 3127 | struct ieee80211_if_managed *ifmgd; |
988c0f72 | 3128 | |
46900298 | 3129 | ifmgd = &sdata->u.mgd; |
b291ba11 | 3130 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
46900298 | 3131 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
1e4dcd01 JO |
3132 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
3133 | ieee80211_beacon_connection_loss_work); | |
882a7c69 JB |
3134 | INIT_WORK(&ifmgd->csa_connection_drop_work, |
3135 | ieee80211_csa_connection_drop_work); | |
d1f5b7a3 | 3136 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work); |
46900298 | 3137 | setup_timer(&ifmgd->timer, ieee80211_sta_timer, |
c481ec97 | 3138 | (unsigned long) sdata); |
b291ba11 JB |
3139 | setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, |
3140 | (unsigned long) sdata); | |
3141 | setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, | |
3142 | (unsigned long) sdata); | |
46900298 | 3143 | setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, |
9c6bd790 | 3144 | (unsigned long) sdata); |
9c6bd790 | 3145 | |
ab1faead | 3146 | ifmgd->flags = 0; |
1478acb3 | 3147 | ifmgd->powersave = sdata->wdev.ps; |
dc41e4d4 EP |
3148 | ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES; |
3149 | ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN; | |
bbbdff9e | 3150 | |
77fdaa12 | 3151 | mutex_init(&ifmgd->mtx); |
0f78231b JB |
3152 | |
3153 | if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) | |
3154 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; | |
3155 | else | |
3156 | ifmgd->req_smps = IEEE80211_SMPS_OFF; | |
f0706e82 JB |
3157 | } |
3158 | ||
77fdaa12 JB |
3159 | /* scan finished notification */ |
3160 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) | |
60f8b39c | 3161 | { |
31ee67a1 | 3162 | struct ieee80211_sub_if_data *sdata; |
60f8b39c | 3163 | |
77fdaa12 JB |
3164 | /* Restart STA timers */ |
3165 | rcu_read_lock(); | |
3166 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
3167 | ieee80211_restart_sta_timer(sdata); | |
3168 | rcu_read_unlock(); | |
3169 | } | |
60f8b39c | 3170 | |
77fdaa12 JB |
3171 | int ieee80211_max_network_latency(struct notifier_block *nb, |
3172 | unsigned long data, void *dummy) | |
3173 | { | |
3174 | s32 latency_usec = (s32) data; | |
3175 | struct ieee80211_local *local = | |
3176 | container_of(nb, struct ieee80211_local, | |
3177 | network_latency_notifier); | |
1fa6f4af | 3178 | |
77fdaa12 JB |
3179 | mutex_lock(&local->iflist_mtx); |
3180 | ieee80211_recalc_ps(local, latency_usec); | |
3181 | mutex_unlock(&local->iflist_mtx); | |
dfe67012 | 3182 | |
77fdaa12 | 3183 | return 0; |
9c6bd790 JB |
3184 | } |
3185 | ||
b17166a7 JB |
3186 | static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, |
3187 | struct cfg80211_bss *cbss) | |
a1cf775d JB |
3188 | { |
3189 | struct ieee80211_local *local = sdata->local; | |
3190 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
24398e39 JB |
3191 | int ht_cfreq; |
3192 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
3193 | const u8 *ht_oper_ie; | |
3194 | const struct ieee80211_ht_operation *ht_oper = NULL; | |
3195 | struct ieee80211_supported_band *sband; | |
4bf88530 | 3196 | struct cfg80211_chan_def chandef; |
a1cf775d | 3197 | |
24398e39 JB |
3198 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
3199 | ||
3200 | ifmgd->flags &= ~IEEE80211_STA_DISABLE_40MHZ; | |
3201 | ||
3202 | if (sband->ht_cap.ht_supported) { | |
3203 | ht_oper_ie = cfg80211_find_ie(WLAN_EID_HT_OPERATION, | |
3204 | cbss->information_elements, | |
3205 | cbss->len_information_elements); | |
3206 | if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper)) | |
3207 | ht_oper = (void *)(ht_oper_ie + 2); | |
3208 | } | |
3209 | ||
3210 | if (ht_oper) { | |
3211 | ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, | |
3212 | cbss->channel->band); | |
3213 | /* check that channel matches the right operating channel */ | |
3214 | if (cbss->channel->center_freq != ht_cfreq) { | |
3215 | /* | |
3216 | * It's possible that some APs are confused here; | |
3217 | * Netgear WNDR3700 sometimes reports 4 higher than | |
3218 | * the actual channel in association responses, but | |
3219 | * since we look at probe response/beacon data here | |
3220 | * it should be OK. | |
3221 | */ | |
bdcbd8e0 JB |
3222 | sdata_info(sdata, |
3223 | "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", | |
3224 | cbss->channel->center_freq, | |
3225 | ht_cfreq, ht_oper->primary_chan, | |
3226 | cbss->channel->band); | |
24398e39 JB |
3227 | ht_oper = NULL; |
3228 | } | |
3229 | } | |
3230 | ||
76c5fa0f | 3231 | if (ht_oper) { |
3a40414f JB |
3232 | /* |
3233 | * cfg80211 already verified that the channel itself can | |
3234 | * be used, but it didn't check that we can do the right | |
3235 | * HT type, so do that here as well. If HT40 isn't allowed | |
3236 | * on this channel, disable 40 MHz operation. | |
3237 | */ | |
04ecd257 JB |
3238 | const u8 *ht_cap_ie; |
3239 | const struct ieee80211_ht_cap *ht_cap; | |
3240 | u8 chains = 1; | |
3241 | ||
24398e39 JB |
3242 | channel_type = NL80211_CHAN_HT20; |
3243 | ||
76c5fa0f JB |
3244 | if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
3245 | switch (ht_oper->ht_param & | |
3246 | IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { | |
3247 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | |
3248 | if (cbss->channel->flags & | |
3249 | IEEE80211_CHAN_NO_HT40PLUS) | |
3250 | ifmgd->flags |= | |
3251 | IEEE80211_STA_DISABLE_40MHZ; | |
3252 | else | |
3253 | channel_type = NL80211_CHAN_HT40PLUS; | |
3254 | break; | |
3255 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
3256 | if (cbss->channel->flags & | |
3257 | IEEE80211_CHAN_NO_HT40MINUS) | |
3258 | ifmgd->flags |= | |
3259 | IEEE80211_STA_DISABLE_40MHZ; | |
3260 | else | |
3261 | channel_type = NL80211_CHAN_HT40MINUS; | |
3262 | break; | |
3263 | } | |
24398e39 | 3264 | } |
04ecd257 JB |
3265 | |
3266 | ht_cap_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, | |
3267 | cbss->information_elements, | |
3268 | cbss->len_information_elements); | |
3269 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) { | |
3270 | ht_cap = (void *)(ht_cap_ie + 2); | |
3271 | chains = ieee80211_mcs_to_chains(&ht_cap->mcs); | |
3272 | } | |
3273 | sdata->needed_rx_chains = min(chains, local->rx_chains); | |
3274 | } else { | |
3275 | sdata->needed_rx_chains = 1; | |
03ae834f | 3276 | sdata->u.mgd.flags |= IEEE80211_STA_DISABLE_HT; |
24398e39 JB |
3277 | } |
3278 | ||
04ecd257 JB |
3279 | /* will change later if needed */ |
3280 | sdata->smps_mode = IEEE80211_SMPS_OFF; | |
3281 | ||
55de908a | 3282 | ieee80211_vif_release_channel(sdata); |
4bf88530 JB |
3283 | cfg80211_chandef_create(&chandef, cbss->channel, channel_type); |
3284 | return ieee80211_vif_use_channel(sdata, &chandef, | |
55de908a | 3285 | IEEE80211_CHANCTX_SHARED); |
b17166a7 JB |
3286 | } |
3287 | ||
3288 | static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, | |
3289 | struct cfg80211_bss *cbss, bool assoc) | |
3290 | { | |
3291 | struct ieee80211_local *local = sdata->local; | |
3292 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3293 | struct ieee80211_bss *bss = (void *)cbss->priv; | |
3294 | struct sta_info *new_sta = NULL; | |
3295 | bool have_sta = false; | |
3296 | int err; | |
3297 | ||
3298 | if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) | |
3299 | return -EINVAL; | |
3300 | ||
3301 | if (assoc) { | |
3302 | rcu_read_lock(); | |
3303 | have_sta = sta_info_get(sdata, cbss->bssid); | |
3304 | rcu_read_unlock(); | |
3305 | } | |
3306 | ||
3307 | if (!have_sta) { | |
3308 | new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); | |
3309 | if (!new_sta) | |
3310 | return -ENOMEM; | |
3311 | } | |
3312 | ||
3313 | mutex_lock(&local->mtx); | |
3314 | ieee80211_recalc_idle(sdata->local); | |
3315 | mutex_unlock(&local->mtx); | |
3316 | ||
13e0c8e3 | 3317 | if (new_sta) { |
5d6a1b06 JB |
3318 | u32 rates = 0, basic_rates = 0; |
3319 | bool have_higher_than_11mbit; | |
3320 | int min_rate = INT_MAX, min_rate_index = -1; | |
b17166a7 JB |
3321 | struct ieee80211_supported_band *sband; |
3322 | ||
3323 | sband = local->hw.wiphy->bands[cbss->channel->band]; | |
3324 | ||
3325 | err = ieee80211_prep_channel(sdata, cbss); | |
3326 | if (err) { | |
3327 | sta_info_free(local, new_sta); | |
3328 | return err; | |
3329 | } | |
5d6a1b06 | 3330 | |
5d6a1b06 JB |
3331 | ieee80211_get_rates(sband, bss->supp_rates, |
3332 | bss->supp_rates_len, | |
3333 | &rates, &basic_rates, | |
3334 | &have_higher_than_11mbit, | |
3335 | &min_rate, &min_rate_index); | |
3336 | ||
3337 | /* | |
3338 | * This used to be a workaround for basic rates missing | |
3339 | * in the association response frame. Now that we no | |
3340 | * longer use the basic rates from there, it probably | |
3341 | * doesn't happen any more, but keep the workaround so | |
3342 | * in case some *other* APs are buggy in different ways | |
3343 | * we can connect -- with a warning. | |
3344 | */ | |
3345 | if (!basic_rates && min_rate_index >= 0) { | |
bdcbd8e0 JB |
3346 | sdata_info(sdata, |
3347 | "No basic rates, using min rate instead\n"); | |
5d6a1b06 JB |
3348 | basic_rates = BIT(min_rate_index); |
3349 | } | |
3350 | ||
13e0c8e3 | 3351 | new_sta->sta.supp_rates[cbss->channel->band] = rates; |
5d6a1b06 JB |
3352 | sdata->vif.bss_conf.basic_rates = basic_rates; |
3353 | ||
3354 | /* cf. IEEE 802.11 9.2.12 */ | |
55de908a | 3355 | if (cbss->channel->band == IEEE80211_BAND_2GHZ && |
5d6a1b06 JB |
3356 | have_higher_than_11mbit) |
3357 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
3358 | else | |
3359 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
3360 | ||
3361 | memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN); | |
3362 | ||
8c358bcd JB |
3363 | /* set timing information */ |
3364 | sdata->vif.bss_conf.beacon_int = cbss->beacon_interval; | |
3365 | sdata->vif.bss_conf.sync_tsf = cbss->tsf; | |
3366 | sdata->vif.bss_conf.sync_device_ts = bss->device_ts; | |
3367 | ||
3368 | /* tell driver about BSSID, basic rates and timing */ | |
5d6a1b06 | 3369 | ieee80211_bss_info_change_notify(sdata, |
8c358bcd JB |
3370 | BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES | |
3371 | BSS_CHANGED_BEACON_INT); | |
a1cf775d JB |
3372 | |
3373 | if (assoc) | |
13e0c8e3 | 3374 | sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); |
a1cf775d | 3375 | |
13e0c8e3 JB |
3376 | err = sta_info_insert(new_sta); |
3377 | new_sta = NULL; | |
a1cf775d | 3378 | if (err) { |
bdcbd8e0 JB |
3379 | sdata_info(sdata, |
3380 | "failed to insert STA entry for the AP (error %d)\n", | |
3381 | err); | |
a1cf775d JB |
3382 | return err; |
3383 | } | |
3384 | } else | |
b203ca39 | 3385 | WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid)); |
a1cf775d JB |
3386 | |
3387 | return 0; | |
3388 | } | |
3389 | ||
77fdaa12 JB |
3390 | /* config hooks */ |
3391 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, | |
3392 | struct cfg80211_auth_request *req) | |
9c6bd790 | 3393 | { |
66e67e41 JB |
3394 | struct ieee80211_local *local = sdata->local; |
3395 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3396 | struct ieee80211_mgd_auth_data *auth_data; | |
77fdaa12 | 3397 | u16 auth_alg; |
66e67e41 JB |
3398 | int err; |
3399 | ||
3400 | /* prepare auth data structure */ | |
9c6bd790 | 3401 | |
77fdaa12 JB |
3402 | switch (req->auth_type) { |
3403 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
3404 | auth_alg = WLAN_AUTH_OPEN; | |
3405 | break; | |
3406 | case NL80211_AUTHTYPE_SHARED_KEY: | |
66e67e41 | 3407 | if (IS_ERR(local->wep_tx_tfm)) |
9dca9c49 | 3408 | return -EOPNOTSUPP; |
77fdaa12 JB |
3409 | auth_alg = WLAN_AUTH_SHARED_KEY; |
3410 | break; | |
3411 | case NL80211_AUTHTYPE_FT: | |
3412 | auth_alg = WLAN_AUTH_FT; | |
3413 | break; | |
3414 | case NL80211_AUTHTYPE_NETWORK_EAP: | |
3415 | auth_alg = WLAN_AUTH_LEAP; | |
3416 | break; | |
6b8ece3a JM |
3417 | case NL80211_AUTHTYPE_SAE: |
3418 | auth_alg = WLAN_AUTH_SAE; | |
3419 | break; | |
77fdaa12 JB |
3420 | default: |
3421 | return -EOPNOTSUPP; | |
60f8b39c | 3422 | } |
77fdaa12 | 3423 | |
6b8ece3a JM |
3424 | auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len + |
3425 | req->ie_len, GFP_KERNEL); | |
66e67e41 | 3426 | if (!auth_data) |
9c6bd790 | 3427 | return -ENOMEM; |
77fdaa12 | 3428 | |
66e67e41 | 3429 | auth_data->bss = req->bss; |
77fdaa12 | 3430 | |
6b8ece3a JM |
3431 | if (req->sae_data_len >= 4) { |
3432 | __le16 *pos = (__le16 *) req->sae_data; | |
3433 | auth_data->sae_trans = le16_to_cpu(pos[0]); | |
3434 | auth_data->sae_status = le16_to_cpu(pos[1]); | |
3435 | memcpy(auth_data->data, req->sae_data + 4, | |
3436 | req->sae_data_len - 4); | |
3437 | auth_data->data_len += req->sae_data_len - 4; | |
3438 | } | |
3439 | ||
77fdaa12 | 3440 | if (req->ie && req->ie_len) { |
6b8ece3a JM |
3441 | memcpy(&auth_data->data[auth_data->data_len], |
3442 | req->ie, req->ie_len); | |
3443 | auth_data->data_len += req->ie_len; | |
9c6bd790 | 3444 | } |
77fdaa12 | 3445 | |
fffd0934 | 3446 | if (req->key && req->key_len) { |
66e67e41 JB |
3447 | auth_data->key_len = req->key_len; |
3448 | auth_data->key_idx = req->key_idx; | |
3449 | memcpy(auth_data->key, req->key, req->key_len); | |
fffd0934 JB |
3450 | } |
3451 | ||
66e67e41 | 3452 | auth_data->algorithm = auth_alg; |
60f8b39c | 3453 | |
66e67e41 | 3454 | /* try to authenticate/probe */ |
2a33bee2 | 3455 | |
66e67e41 | 3456 | mutex_lock(&ifmgd->mtx); |
2a33bee2 | 3457 | |
66e67e41 JB |
3458 | if ((ifmgd->auth_data && !ifmgd->auth_data->done) || |
3459 | ifmgd->assoc_data) { | |
3460 | err = -EBUSY; | |
3461 | goto err_free; | |
2a33bee2 GE |
3462 | } |
3463 | ||
66e67e41 JB |
3464 | if (ifmgd->auth_data) |
3465 | ieee80211_destroy_auth_data(sdata, false); | |
2a33bee2 | 3466 | |
66e67e41 JB |
3467 | /* prep auth_data so we don't go into idle on disassoc */ |
3468 | ifmgd->auth_data = auth_data; | |
af6b6374 | 3469 | |
66e67e41 | 3470 | if (ifmgd->associated) |
37ad3888 | 3471 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
af6b6374 | 3472 | |
bdcbd8e0 | 3473 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
e5b900d2 | 3474 | |
a1cf775d JB |
3475 | err = ieee80211_prep_connection(sdata, req->bss, false); |
3476 | if (err) | |
66e67e41 | 3477 | goto err_clear; |
af6b6374 | 3478 | |
66e67e41 JB |
3479 | err = ieee80211_probe_auth(sdata); |
3480 | if (err) { | |
66e67e41 JB |
3481 | sta_info_destroy_addr(sdata, req->bss->bssid); |
3482 | goto err_clear; | |
3483 | } | |
3484 | ||
3485 | /* hold our own reference */ | |
3486 | cfg80211_ref_bss(auth_data->bss); | |
3487 | err = 0; | |
3488 | goto out_unlock; | |
3489 | ||
3490 | err_clear: | |
3d2abdfd EP |
3491 | memset(ifmgd->bssid, 0, ETH_ALEN); |
3492 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); | |
66e67e41 JB |
3493 | ifmgd->auth_data = NULL; |
3494 | err_free: | |
3495 | kfree(auth_data); | |
3496 | out_unlock: | |
3497 | mutex_unlock(&ifmgd->mtx); | |
b2abb6e2 | 3498 | |
66e67e41 | 3499 | return err; |
af6b6374 JB |
3500 | } |
3501 | ||
77fdaa12 JB |
3502 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
3503 | struct cfg80211_assoc_request *req) | |
f0706e82 | 3504 | { |
66e67e41 | 3505 | struct ieee80211_local *local = sdata->local; |
77fdaa12 | 3506 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
0c1ad2ca | 3507 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
66e67e41 | 3508 | struct ieee80211_mgd_assoc_data *assoc_data; |
4e74bfdb | 3509 | struct ieee80211_supported_band *sband; |
9dde6423 | 3510 | const u8 *ssidie, *ht_ie; |
2a33bee2 | 3511 | int i, err; |
f0706e82 | 3512 | |
66e67e41 JB |
3513 | ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
3514 | if (!ssidie) | |
3515 | return -EINVAL; | |
3516 | ||
3517 | assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); | |
3518 | if (!assoc_data) | |
3519 | return -ENOMEM; | |
3520 | ||
77fdaa12 | 3521 | mutex_lock(&ifmgd->mtx); |
9c87ba67 | 3522 | |
66e67e41 | 3523 | if (ifmgd->associated) |
37ad3888 | 3524 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
66e67e41 JB |
3525 | |
3526 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { | |
3527 | err = -EBUSY; | |
3528 | goto err_free; | |
af6b6374 | 3529 | } |
77fdaa12 | 3530 | |
66e67e41 JB |
3531 | if (ifmgd->assoc_data) { |
3532 | err = -EBUSY; | |
3533 | goto err_free; | |
3534 | } | |
77fdaa12 | 3535 | |
66e67e41 JB |
3536 | if (ifmgd->auth_data) { |
3537 | bool match; | |
3538 | ||
3539 | /* keep sta info, bssid if matching */ | |
b203ca39 | 3540 | match = ether_addr_equal(ifmgd->bssid, req->bss->bssid); |
66e67e41 | 3541 | ieee80211_destroy_auth_data(sdata, match); |
2a33bee2 GE |
3542 | } |
3543 | ||
66e67e41 | 3544 | /* prepare assoc data */ |
19c3b830 | 3545 | |
d8ec4433 JO |
3546 | ifmgd->beacon_crc_valid = false; |
3547 | ||
de5036aa JB |
3548 | /* |
3549 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. | |
3550 | * We still associate in non-HT mode (11a/b/g) if any one of these | |
3551 | * ciphers is configured as pairwise. | |
3552 | * We can set this to true for non-11n hardware, that'll be checked | |
3553 | * separately along with the peer capabilities. | |
3554 | */ | |
1c4cb928 | 3555 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { |
77fdaa12 JB |
3556 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
3557 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || | |
1c4cb928 | 3558 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { |
a8243b72 | 3559 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
d545daba | 3560 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
1c4cb928 | 3561 | netdev_info(sdata->dev, |
d545daba | 3562 | "disabling HT/VHT due to WEP/TKIP use\n"); |
1c4cb928 JB |
3563 | } |
3564 | } | |
77fdaa12 | 3565 | |
d545daba | 3566 | if (req->flags & ASSOC_REQ_DISABLE_HT) { |
a8243b72 | 3567 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
d545daba MP |
3568 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
3569 | } | |
ef96a842 | 3570 | |
4e74bfdb JB |
3571 | /* Also disable HT if we don't support it or the AP doesn't use WMM */ |
3572 | sband = local->hw.wiphy->bands[req->bss->channel->band]; | |
3573 | if (!sband->ht_cap.ht_supported || | |
1c4cb928 | 3574 | local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) { |
a8243b72 | 3575 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
1b49de26 JB |
3576 | if (!bss->wmm_used) |
3577 | netdev_info(sdata->dev, | |
3578 | "disabling HT as WMM/QoS is not supported by the AP\n"); | |
1c4cb928 | 3579 | } |
4e74bfdb | 3580 | |
d545daba MP |
3581 | /* disable VHT if we don't support it or the AP doesn't use WMM */ |
3582 | if (!sband->vht_cap.vht_supported || | |
3583 | local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) { | |
3584 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; | |
1b49de26 JB |
3585 | if (!bss->wmm_used) |
3586 | netdev_info(sdata->dev, | |
3587 | "disabling VHT as WMM/QoS is not supported by the AP\n"); | |
d545daba MP |
3588 | } |
3589 | ||
ef96a842 BG |
3590 | memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); |
3591 | memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, | |
3592 | sizeof(ifmgd->ht_capa_mask)); | |
3593 | ||
77fdaa12 | 3594 | if (req->ie && req->ie_len) { |
66e67e41 JB |
3595 | memcpy(assoc_data->ie, req->ie, req->ie_len); |
3596 | assoc_data->ie_len = req->ie_len; | |
3597 | } | |
f679f65d | 3598 | |
66e67e41 | 3599 | assoc_data->bss = req->bss; |
f679f65d | 3600 | |
af6b6374 JB |
3601 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
3602 | if (ifmgd->powersave) | |
04ecd257 | 3603 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
af6b6374 | 3604 | else |
04ecd257 | 3605 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
af6b6374 | 3606 | } else |
04ecd257 | 3607 | sdata->smps_mode = ifmgd->req_smps; |
af6b6374 | 3608 | |
66e67e41 | 3609 | assoc_data->capability = req->bss->capability; |
32c5057b JB |
3610 | assoc_data->wmm = bss->wmm_used && |
3611 | (local->hw.queues >= IEEE80211_NUM_ACS); | |
66e67e41 JB |
3612 | assoc_data->supp_rates = bss->supp_rates; |
3613 | assoc_data->supp_rates_len = bss->supp_rates_len; | |
9dde6423 JB |
3614 | |
3615 | ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION); | |
3616 | if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation)) | |
3617 | assoc_data->ap_ht_param = | |
3618 | ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param; | |
3619 | else | |
a8243b72 | 3620 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
63f170e0 | 3621 | |
ab13315a KV |
3622 | if (bss->wmm_used && bss->uapsd_supported && |
3623 | (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) { | |
76f0303d | 3624 | assoc_data->uapsd = true; |
ab13315a KV |
3625 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
3626 | } else { | |
76f0303d | 3627 | assoc_data->uapsd = false; |
ab13315a KV |
3628 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
3629 | } | |
3630 | ||
66e67e41 JB |
3631 | memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]); |
3632 | assoc_data->ssid_len = ssidie[1]; | |
63f170e0 | 3633 | |
77fdaa12 | 3634 | if (req->prev_bssid) |
66e67e41 | 3635 | memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN); |
77fdaa12 JB |
3636 | |
3637 | if (req->use_mfp) { | |
3638 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; | |
3639 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; | |
3640 | } else { | |
3641 | ifmgd->mfp = IEEE80211_MFP_DISABLED; | |
3642 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; | |
3643 | } | |
3644 | ||
3645 | if (req->crypto.control_port) | |
3646 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; | |
3647 | else | |
3648 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; | |
3649 | ||
a621fa4d JB |
3650 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
3651 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; | |
3652 | ||
66e67e41 JB |
3653 | /* kick off associate process */ |
3654 | ||
3655 | ifmgd->assoc_data = assoc_data; | |
3656 | ||
a1cf775d JB |
3657 | err = ieee80211_prep_connection(sdata, req->bss, true); |
3658 | if (err) | |
3659 | goto err_clear; | |
66e67e41 JB |
3660 | |
3661 | if (!bss->dtim_period && | |
3662 | sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) { | |
3663 | /* | |
3664 | * Wait up to one beacon interval ... | |
3665 | * should this be more if we miss one? | |
3666 | */ | |
bdcbd8e0 JB |
3667 | sdata_info(sdata, "waiting for beacon from %pM\n", |
3668 | ifmgd->bssid); | |
3f9768a5 | 3669 | assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); |
66e67e41 JB |
3670 | } else { |
3671 | assoc_data->have_beacon = true; | |
3672 | assoc_data->sent_assoc = false; | |
3673 | assoc_data->timeout = jiffies; | |
3674 | } | |
3675 | run_again(ifmgd, assoc_data->timeout); | |
3676 | ||
fcff4f10 PS |
3677 | if (bss->corrupt_data) { |
3678 | char *corrupt_type = "data"; | |
3679 | if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { | |
3680 | if (bss->corrupt_data & | |
3681 | IEEE80211_BSS_CORRUPT_PROBE_RESP) | |
3682 | corrupt_type = "beacon and probe response"; | |
3683 | else | |
3684 | corrupt_type = "beacon"; | |
3685 | } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) | |
3686 | corrupt_type = "probe response"; | |
bdcbd8e0 JB |
3687 | sdata_info(sdata, "associating with AP with corrupt %s\n", |
3688 | corrupt_type); | |
fcff4f10 PS |
3689 | } |
3690 | ||
66e67e41 JB |
3691 | err = 0; |
3692 | goto out; | |
3693 | err_clear: | |
3d2abdfd EP |
3694 | memset(ifmgd->bssid, 0, ETH_ALEN); |
3695 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); | |
66e67e41 JB |
3696 | ifmgd->assoc_data = NULL; |
3697 | err_free: | |
3698 | kfree(assoc_data); | |
3699 | out: | |
3700 | mutex_unlock(&ifmgd->mtx); | |
3701 | ||
3702 | return err; | |
f0706e82 JB |
3703 | } |
3704 | ||
77fdaa12 | 3705 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
63c9c5e7 | 3706 | struct cfg80211_deauth_request *req) |
f0706e82 | 3707 | { |
46900298 | 3708 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
6ae16775 | 3709 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
6863255b | 3710 | bool tx = !req->local_state_change; |
86552017 | 3711 | bool sent_frame = false; |
f0706e82 | 3712 | |
77fdaa12 JB |
3713 | mutex_lock(&ifmgd->mtx); |
3714 | ||
bdcbd8e0 JB |
3715 | sdata_info(sdata, |
3716 | "deauthenticating from %pM by local choice (reason=%d)\n", | |
3717 | req->bssid, req->reason_code); | |
0ff71613 | 3718 | |
86552017 | 3719 | if (ifmgd->auth_data) { |
8c7d857c | 3720 | drv_mgd_prepare_tx(sdata->local, sdata); |
37ad3888 JB |
3721 | ieee80211_send_deauth_disassoc(sdata, req->bssid, |
3722 | IEEE80211_STYPE_DEAUTH, | |
6863255b | 3723 | req->reason_code, tx, |
37ad3888 | 3724 | frame_buf); |
86552017 JB |
3725 | ieee80211_destroy_auth_data(sdata, false); |
3726 | mutex_unlock(&ifmgd->mtx); | |
3727 | ||
3728 | sent_frame = tx; | |
3729 | goto out; | |
8c7d857c EG |
3730 | } |
3731 | ||
86552017 JB |
3732 | if (ifmgd->associated && |
3733 | ether_addr_equal(ifmgd->associated->bssid, req->bssid)) { | |
3734 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, | |
3735 | req->reason_code, tx, frame_buf); | |
3736 | sent_frame = tx; | |
3737 | } | |
37ad3888 JB |
3738 | mutex_unlock(&ifmgd->mtx); |
3739 | ||
86552017 | 3740 | out: |
7da7cc1d | 3741 | mutex_lock(&sdata->local->mtx); |
bc83b681 | 3742 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 3743 | mutex_unlock(&sdata->local->mtx); |
bc83b681 | 3744 | |
86552017 JB |
3745 | if (sent_frame) |
3746 | __cfg80211_send_deauth(sdata->dev, frame_buf, | |
3747 | IEEE80211_DEAUTH_FRAME_LEN); | |
3748 | ||
f0706e82 JB |
3749 | return 0; |
3750 | } | |
84363e6e | 3751 | |
77fdaa12 | 3752 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
63c9c5e7 | 3753 | struct cfg80211_disassoc_request *req) |
9c6bd790 | 3754 | { |
77fdaa12 | 3755 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
e69e95db | 3756 | u8 bssid[ETH_ALEN]; |
6ae16775 | 3757 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
9c6bd790 | 3758 | |
77fdaa12 | 3759 | mutex_lock(&ifmgd->mtx); |
10f644a4 | 3760 | |
8d8b261a JB |
3761 | /* |
3762 | * cfg80211 should catch this ... but it's racy since | |
3763 | * we can receive a disassoc frame, process it, hand it | |
3764 | * to cfg80211 while that's in a locked section already | |
3765 | * trying to tell us that the user wants to disconnect. | |
3766 | */ | |
0c1ad2ca | 3767 | if (ifmgd->associated != req->bss) { |
77fdaa12 JB |
3768 | mutex_unlock(&ifmgd->mtx); |
3769 | return -ENOLINK; | |
3770 | } | |
3771 | ||
bdcbd8e0 JB |
3772 | sdata_info(sdata, |
3773 | "disassociating from %pM by local choice (reason=%d)\n", | |
3774 | req->bss->bssid, req->reason_code); | |
0ff71613 | 3775 | |
e69e95db | 3776 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
37ad3888 JB |
3777 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, |
3778 | req->reason_code, !req->local_state_change, | |
3779 | frame_buf); | |
77fdaa12 | 3780 | mutex_unlock(&ifmgd->mtx); |
10f644a4 | 3781 | |
6ae16775 AQ |
3782 | __cfg80211_send_disassoc(sdata->dev, frame_buf, |
3783 | IEEE80211_DEAUTH_FRAME_LEN); | |
bc83b681 | 3784 | |
7da7cc1d | 3785 | mutex_lock(&sdata->local->mtx); |
bc83b681 | 3786 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 3787 | mutex_unlock(&sdata->local->mtx); |
bc83b681 | 3788 | |
10f644a4 JB |
3789 | return 0; |
3790 | } | |
026331c4 | 3791 | |
afa762f6 | 3792 | void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) |
54e4ffb2 JB |
3793 | { |
3794 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3795 | ||
3796 | mutex_lock(&ifmgd->mtx); | |
3797 | if (ifmgd->assoc_data) | |
3798 | ieee80211_destroy_assoc_data(sdata, false); | |
3799 | if (ifmgd->auth_data) | |
3800 | ieee80211_destroy_auth_data(sdata, false); | |
3801 | del_timer_sync(&ifmgd->timer); | |
3802 | mutex_unlock(&ifmgd->mtx); | |
3803 | } | |
3804 | ||
a97c13c3 JO |
3805 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
3806 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
3807 | gfp_t gfp) | |
3808 | { | |
3809 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
3810 | ||
b5878a2d JB |
3811 | trace_api_cqm_rssi_notify(sdata, rssi_event); |
3812 | ||
a97c13c3 JO |
3813 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp); |
3814 | } | |
3815 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |