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