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> |
d0709a65 | 19 | #include <linux/rtnetlink.h> |
10f644a4 | 20 | #include <linux/pm_qos_params.h> |
d91f36db | 21 | #include <linux/crc32.h> |
f0706e82 | 22 | #include <net/mac80211.h> |
472dbc45 | 23 | #include <asm/unaligned.h> |
60f8b39c | 24 | |
f0706e82 | 25 | #include "ieee80211_i.h" |
24487981 | 26 | #include "driver-ops.h" |
2c8dccc7 JB |
27 | #include "rate.h" |
28 | #include "led.h" | |
f0706e82 JB |
29 | |
30 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) | |
31 | #define IEEE80211_AUTH_MAX_TRIES 3 | |
32 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) | |
33 | #define IEEE80211_ASSOC_MAX_TRIES 3 | |
a43abf29 | 34 | #define IEEE80211_MAX_PROBE_TRIES 5 |
b291ba11 JB |
35 | |
36 | /* | |
37 | * beacon loss detection timeout | |
38 | * XXX: should depend on beacon interval | |
39 | */ | |
40 | #define IEEE80211_BEACON_LOSS_TIME (2 * HZ) | |
41 | /* | |
42 | * Time the connection can be idle before we probe | |
43 | * it to see if we can still talk to the AP. | |
44 | */ | |
d1c5091f | 45 | #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) |
b291ba11 JB |
46 | /* |
47 | * Time we wait for a probe response after sending | |
48 | * a probe request because of beacon loss or for | |
49 | * checking the connection still works. | |
50 | */ | |
d1c5091f | 51 | #define IEEE80211_PROBE_WAIT (HZ / 2) |
f0706e82 | 52 | |
5bb644a0 JB |
53 | #define TMR_RUNNING_TIMER 0 |
54 | #define TMR_RUNNING_CHANSW 1 | |
55 | ||
77fdaa12 JB |
56 | /* |
57 | * All cfg80211 functions have to be called outside a locked | |
58 | * section so that they can acquire a lock themselves... This | |
59 | * is much simpler than queuing up things in cfg80211, but we | |
60 | * do need some indirection for that here. | |
61 | */ | |
62 | enum rx_mgmt_action { | |
63 | /* no action required */ | |
64 | RX_MGMT_NONE, | |
65 | ||
66 | /* caller must call cfg80211_send_rx_auth() */ | |
67 | RX_MGMT_CFG80211_AUTH, | |
68 | ||
69 | /* caller must call cfg80211_send_rx_assoc() */ | |
70 | RX_MGMT_CFG80211_ASSOC, | |
71 | ||
72 | /* caller must call cfg80211_send_deauth() */ | |
73 | RX_MGMT_CFG80211_DEAUTH, | |
74 | ||
75 | /* caller must call cfg80211_send_disassoc() */ | |
76 | RX_MGMT_CFG80211_DISASSOC, | |
77 | ||
5d1ec85f JB |
78 | /* caller must tell cfg80211 about internal error */ |
79 | RX_MGMT_CFG80211_ASSOC_ERROR, | |
80 | ||
77fdaa12 JB |
81 | /* caller must call cfg80211_auth_timeout() & free work */ |
82 | RX_MGMT_CFG80211_AUTH_TO, | |
83 | ||
84 | /* caller must call cfg80211_assoc_timeout() & free work */ | |
85 | RX_MGMT_CFG80211_ASSOC_TO, | |
86 | }; | |
87 | ||
5484e237 | 88 | /* utils */ |
77fdaa12 JB |
89 | static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd) |
90 | { | |
91 | WARN_ON(!mutex_is_locked(&ifmgd->mtx)); | |
92 | } | |
93 | ||
ca386f31 JB |
94 | /* |
95 | * We can have multiple work items (and connection probing) | |
96 | * scheduling this timer, but we need to take care to only | |
97 | * reschedule it when it should fire _earlier_ than it was | |
98 | * asked for before, or if it's not pending right now. This | |
99 | * function ensures that. Note that it then is required to | |
100 | * run this function for all timeouts after the first one | |
101 | * has happened -- the work that runs from this timer will | |
102 | * do that. | |
103 | */ | |
104 | static void run_again(struct ieee80211_if_managed *ifmgd, | |
105 | unsigned long timeout) | |
106 | { | |
107 | ASSERT_MGD_MTX(ifmgd); | |
108 | ||
109 | if (!timer_pending(&ifmgd->timer) || | |
110 | time_before(timeout, ifmgd->timer.expires)) | |
111 | mod_timer(&ifmgd->timer, timeout); | |
112 | } | |
113 | ||
b291ba11 JB |
114 | static void mod_beacon_timer(struct ieee80211_sub_if_data *sdata) |
115 | { | |
116 | if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER) | |
117 | return; | |
118 | ||
119 | mod_timer(&sdata->u.mgd.bcn_mon_timer, | |
120 | round_jiffies_up(jiffies + IEEE80211_BEACON_LOSS_TIME)); | |
121 | } | |
122 | ||
5484e237 | 123 | static int ecw2cw(int ecw) |
60f8b39c | 124 | { |
5484e237 | 125 | return (1 << ecw) - 1; |
60f8b39c JB |
126 | } |
127 | ||
f679f65d | 128 | static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len, |
9ac19a90 | 129 | struct ieee80211_supported_band *sband, |
881d948c | 130 | u32 *rates) |
9ac19a90 JB |
131 | { |
132 | int i, j, count; | |
133 | *rates = 0; | |
134 | count = 0; | |
f679f65d JB |
135 | for (i = 0; i < supp_rates_len; i++) { |
136 | int rate = (supp_rates[i] & 0x7F) * 5; | |
9ac19a90 JB |
137 | |
138 | for (j = 0; j < sband->n_bitrates; j++) | |
139 | if (sband->bitrates[j].bitrate == rate) { | |
140 | *rates |= BIT(j); | |
141 | count++; | |
142 | break; | |
143 | } | |
144 | } | |
145 | ||
146 | return count; | |
147 | } | |
148 | ||
d5522e03 JB |
149 | /* |
150 | * ieee80211_enable_ht should be called only after the operating band | |
151 | * has been determined as ht configuration depends on the hw's | |
152 | * HT abilities for a specific band. | |
153 | */ | |
154 | static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata, | |
155 | struct ieee80211_ht_info *hti, | |
77fdaa12 | 156 | const u8 *bssid, u16 ap_ht_cap_flags) |
d5522e03 JB |
157 | { |
158 | struct ieee80211_local *local = sdata->local; | |
159 | struct ieee80211_supported_band *sband; | |
d5522e03 JB |
160 | struct sta_info *sta; |
161 | u32 changed = 0; | |
9ed6bcce | 162 | u16 ht_opmode; |
d5522e03 JB |
163 | bool enable_ht = true, ht_changed; |
164 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
165 | ||
166 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
167 | ||
d5522e03 JB |
168 | /* HT is not supported */ |
169 | if (!sband->ht_cap.ht_supported) | |
170 | enable_ht = false; | |
171 | ||
172 | /* check that channel matches the right operating channel */ | |
173 | if (local->hw.conf.channel->center_freq != | |
174 | ieee80211_channel_to_frequency(hti->control_chan)) | |
175 | enable_ht = false; | |
176 | ||
177 | if (enable_ht) { | |
178 | channel_type = NL80211_CHAN_HT20; | |
179 | ||
180 | if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) && | |
181 | (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && | |
182 | (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) { | |
183 | switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { | |
184 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | |
768777ea LR |
185 | if (!(local->hw.conf.channel->flags & |
186 | IEEE80211_CHAN_NO_HT40PLUS)) | |
187 | channel_type = NL80211_CHAN_HT40PLUS; | |
d5522e03 JB |
188 | break; |
189 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
768777ea LR |
190 | if (!(local->hw.conf.channel->flags & |
191 | IEEE80211_CHAN_NO_HT40MINUS)) | |
192 | channel_type = NL80211_CHAN_HT40MINUS; | |
d5522e03 JB |
193 | break; |
194 | } | |
195 | } | |
196 | } | |
197 | ||
198 | ht_changed = conf_is_ht(&local->hw.conf) != enable_ht || | |
199 | channel_type != local->hw.conf.channel_type; | |
200 | ||
201 | local->oper_channel_type = channel_type; | |
202 | ||
203 | if (ht_changed) { | |
204 | /* channel_type change automatically detected */ | |
205 | ieee80211_hw_config(local, 0); | |
206 | ||
207 | rcu_read_lock(); | |
abe60632 | 208 | sta = sta_info_get(sdata, bssid); |
d5522e03 JB |
209 | if (sta) |
210 | rate_control_rate_update(local, sband, sta, | |
211 | IEEE80211_RC_HT_CHANGED); | |
d5522e03 | 212 | rcu_read_unlock(); |
d5522e03 JB |
213 | } |
214 | ||
215 | /* disable HT */ | |
216 | if (!enable_ht) | |
217 | return 0; | |
218 | ||
9ed6bcce | 219 | ht_opmode = le16_to_cpu(hti->operation_mode); |
d5522e03 JB |
220 | |
221 | /* if bss configuration changed store the new one */ | |
413ad50a JB |
222 | if (!sdata->ht_opmode_valid || |
223 | sdata->vif.bss_conf.ht_operation_mode != ht_opmode) { | |
d5522e03 | 224 | changed |= BSS_CHANGED_HT; |
9ed6bcce | 225 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
413ad50a | 226 | sdata->ht_opmode_valid = true; |
d5522e03 JB |
227 | } |
228 | ||
229 | return changed; | |
230 | } | |
231 | ||
9c6bd790 JB |
232 | /* frame sending functions */ |
233 | ||
77fdaa12 | 234 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata, |
f679f65d | 235 | struct ieee80211_work *wk) |
9ac19a90 | 236 | { |
46900298 | 237 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
9ac19a90 JB |
238 | struct ieee80211_local *local = sdata->local; |
239 | struct sk_buff *skb; | |
240 | struct ieee80211_mgmt *mgmt; | |
517357c6 JB |
241 | u8 *pos; |
242 | const u8 *ies, *ht_ie; | |
9ac19a90 JB |
243 | int i, len, count, rates_len, supp_rates_len; |
244 | u16 capab; | |
9ac19a90 JB |
245 | int wmm = 0; |
246 | struct ieee80211_supported_band *sband; | |
881d948c | 247 | u32 rates = 0; |
9ac19a90 JB |
248 | |
249 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
77fdaa12 | 250 | sizeof(*mgmt) + 200 + wk->ie_len + |
f679f65d | 251 | wk->assoc.ssid_len); |
9ac19a90 JB |
252 | if (!skb) { |
253 | printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " | |
47846c9b | 254 | "frame\n", sdata->name); |
9ac19a90 JB |
255 | return; |
256 | } | |
257 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
258 | ||
259 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
260 | ||
46900298 | 261 | capab = ifmgd->capab; |
9ac19a90 JB |
262 | |
263 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) { | |
264 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) | |
265 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; | |
266 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) | |
267 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
268 | } | |
269 | ||
f679f65d | 270 | if (wk->assoc.capability & WLAN_CAPABILITY_PRIVACY) |
77fdaa12 | 271 | capab |= WLAN_CAPABILITY_PRIVACY; |
f679f65d | 272 | if (wk->assoc.wmm_used) |
77fdaa12 | 273 | wmm = 1; |
9ac19a90 | 274 | |
77fdaa12 JB |
275 | /* get all rates supported by the device and the AP as |
276 | * some APs don't like getting a superset of their rates | |
277 | * in the association request (e.g. D-Link DAP 1353 in | |
278 | * b-only mode) */ | |
f679f65d JB |
279 | rates_len = ieee80211_compatible_rates(wk->assoc.supp_rates, |
280 | wk->assoc.supp_rates_len, | |
281 | sband, &rates); | |
9ac19a90 | 282 | |
f679f65d | 283 | if ((wk->assoc.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
77fdaa12 JB |
284 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) |
285 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; | |
9ac19a90 JB |
286 | |
287 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
288 | memset(mgmt, 0, 24); | |
f679f65d | 289 | memcpy(mgmt->da, wk->assoc.bssid, ETH_ALEN); |
47846c9b | 290 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
f679f65d | 291 | memcpy(mgmt->bssid, wk->assoc.bssid, ETH_ALEN); |
9ac19a90 | 292 | |
f679f65d | 293 | if (!is_zero_ether_addr(wk->assoc.prev_bssid)) { |
9ac19a90 JB |
294 | skb_put(skb, 10); |
295 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
296 | IEEE80211_STYPE_REASSOC_REQ); | |
297 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); | |
298 | mgmt->u.reassoc_req.listen_interval = | |
299 | cpu_to_le16(local->hw.conf.listen_interval); | |
f679f65d | 300 | memcpy(mgmt->u.reassoc_req.current_ap, wk->assoc.prev_bssid, |
9ac19a90 JB |
301 | ETH_ALEN); |
302 | } else { | |
303 | skb_put(skb, 4); | |
304 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
305 | IEEE80211_STYPE_ASSOC_REQ); | |
306 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); | |
13554121 | 307 | mgmt->u.assoc_req.listen_interval = |
9ac19a90 JB |
308 | cpu_to_le16(local->hw.conf.listen_interval); |
309 | } | |
310 | ||
311 | /* SSID */ | |
f679f65d | 312 | ies = pos = skb_put(skb, 2 + wk->assoc.ssid_len); |
9ac19a90 | 313 | *pos++ = WLAN_EID_SSID; |
f679f65d JB |
314 | *pos++ = wk->assoc.ssid_len; |
315 | memcpy(pos, wk->assoc.ssid, wk->assoc.ssid_len); | |
9ac19a90 JB |
316 | |
317 | /* add all rates which were marked to be used above */ | |
318 | supp_rates_len = rates_len; | |
319 | if (supp_rates_len > 8) | |
320 | supp_rates_len = 8; | |
321 | ||
322 | len = sband->n_bitrates; | |
323 | pos = skb_put(skb, supp_rates_len + 2); | |
324 | *pos++ = WLAN_EID_SUPP_RATES; | |
325 | *pos++ = supp_rates_len; | |
326 | ||
327 | count = 0; | |
328 | for (i = 0; i < sband->n_bitrates; i++) { | |
329 | if (BIT(i) & rates) { | |
330 | int rate = sband->bitrates[i].bitrate; | |
331 | *pos++ = (u8) (rate / 5); | |
332 | if (++count == 8) | |
333 | break; | |
334 | } | |
335 | } | |
336 | ||
337 | if (rates_len > count) { | |
338 | pos = skb_put(skb, rates_len - count + 2); | |
339 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
340 | *pos++ = rates_len - count; | |
341 | ||
342 | for (i++; i < sband->n_bitrates; i++) { | |
343 | if (BIT(i) & rates) { | |
344 | int rate = sband->bitrates[i].bitrate; | |
345 | *pos++ = (u8) (rate / 5); | |
346 | } | |
347 | } | |
348 | } | |
349 | ||
350 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { | |
351 | /* 1. power capabilities */ | |
352 | pos = skb_put(skb, 4); | |
353 | *pos++ = WLAN_EID_PWR_CAPABILITY; | |
354 | *pos++ = 2; | |
355 | *pos++ = 0; /* min tx power */ | |
356 | *pos++ = local->hw.conf.channel->max_power; /* max tx power */ | |
357 | ||
358 | /* 2. supported channels */ | |
359 | /* TODO: get this in reg domain format */ | |
360 | pos = skb_put(skb, 2 * sband->n_channels + 2); | |
361 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; | |
362 | *pos++ = 2 * sband->n_channels; | |
363 | for (i = 0; i < sband->n_channels; i++) { | |
364 | *pos++ = ieee80211_frequency_to_channel( | |
365 | sband->channels[i].center_freq); | |
366 | *pos++ = 1; /* one channel in the subband*/ | |
367 | } | |
368 | } | |
369 | ||
77fdaa12 JB |
370 | if (wk->ie_len && wk->ie) { |
371 | pos = skb_put(skb, wk->ie_len); | |
372 | memcpy(pos, wk->ie, wk->ie_len); | |
9ac19a90 JB |
373 | } |
374 | ||
46900298 | 375 | if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) { |
9ac19a90 JB |
376 | pos = skb_put(skb, 9); |
377 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; | |
378 | *pos++ = 7; /* len */ | |
379 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ | |
380 | *pos++ = 0x50; | |
381 | *pos++ = 0xf2; | |
382 | *pos++ = 2; /* WME */ | |
383 | *pos++ = 0; /* WME info */ | |
384 | *pos++ = 1; /* WME ver */ | |
385 | *pos++ = 0; | |
386 | } | |
387 | ||
388 | /* wmm support is a must to HT */ | |
eb46936b VT |
389 | /* |
390 | * IEEE802.11n does not allow TKIP/WEP as pairwise | |
391 | * ciphers in HT mode. We still associate in non-ht | |
392 | * mode (11a/b/g) if any one of these ciphers is | |
393 | * configured as pairwise. | |
394 | */ | |
46900298 | 395 | if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && |
d9fe60de | 396 | sband->ht_cap.ht_supported && |
f679f65d | 397 | (ht_ie = wk->assoc.ht_information_ie) && |
eb46936b | 398 | ht_ie[1] >= sizeof(struct ieee80211_ht_info) && |
ab1faead | 399 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))) { |
d9fe60de JB |
400 | struct ieee80211_ht_info *ht_info = |
401 | (struct ieee80211_ht_info *)(ht_ie + 2); | |
402 | u16 cap = sband->ht_cap.cap; | |
9ac19a90 JB |
403 | __le16 tmp; |
404 | u32 flags = local->hw.conf.channel->flags; | |
405 | ||
0f78231b JB |
406 | /* determine capability flags */ |
407 | ||
f38fd12f JB |
408 | if (ieee80211_disable_40mhz_24ghz && |
409 | sband->band == IEEE80211_BAND_2GHZ) { | |
410 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
411 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
412 | } | |
413 | ||
d9fe60de JB |
414 | switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
415 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | |
689da1b3 | 416 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
d9fe60de | 417 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
9ac19a90 JB |
418 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
419 | } | |
420 | break; | |
d9fe60de | 421 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
689da1b3 | 422 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
d9fe60de | 423 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
9ac19a90 JB |
424 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
425 | } | |
426 | break; | |
427 | } | |
428 | ||
0f78231b JB |
429 | /* set SM PS mode properly */ |
430 | cap &= ~IEEE80211_HT_CAP_SM_PS; | |
431 | /* new association always uses requested smps mode */ | |
432 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { | |
433 | if (ifmgd->powersave) | |
434 | ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC; | |
435 | else | |
436 | ifmgd->ap_smps = IEEE80211_SMPS_OFF; | |
437 | } else | |
438 | ifmgd->ap_smps = ifmgd->req_smps; | |
439 | ||
440 | switch (ifmgd->ap_smps) { | |
441 | case IEEE80211_SMPS_AUTOMATIC: | |
442 | case IEEE80211_SMPS_NUM_MODES: | |
443 | WARN_ON(1); | |
444 | case IEEE80211_SMPS_OFF: | |
445 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << | |
446 | IEEE80211_HT_CAP_SM_PS_SHIFT; | |
447 | break; | |
448 | case IEEE80211_SMPS_STATIC: | |
449 | cap |= WLAN_HT_CAP_SM_PS_STATIC << | |
450 | IEEE80211_HT_CAP_SM_PS_SHIFT; | |
451 | break; | |
452 | case IEEE80211_SMPS_DYNAMIC: | |
453 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << | |
454 | IEEE80211_HT_CAP_SM_PS_SHIFT; | |
455 | break; | |
456 | } | |
457 | ||
458 | /* reserve and fill IE */ | |
459 | ||
460 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); | |
9ac19a90 JB |
461 | *pos++ = WLAN_EID_HT_CAPABILITY; |
462 | *pos++ = sizeof(struct ieee80211_ht_cap); | |
463 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); | |
0f78231b JB |
464 | |
465 | /* capability flags */ | |
466 | tmp = cpu_to_le16(cap); | |
9ac19a90 JB |
467 | memcpy(pos, &tmp, sizeof(u16)); |
468 | pos += sizeof(u16); | |
0f78231b JB |
469 | |
470 | /* AMPDU parameters */ | |
d9fe60de | 471 | *pos++ = sband->ht_cap.ampdu_factor | |
0f78231b JB |
472 | (sband->ht_cap.ampdu_density << |
473 | IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT); | |
474 | ||
475 | /* MCS set */ | |
d9fe60de | 476 | memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); |
0f78231b JB |
477 | pos += sizeof(sband->ht_cap.mcs); |
478 | ||
479 | /* extended capabilities */ | |
480 | pos += sizeof(__le16); | |
481 | ||
482 | /* BF capabilities */ | |
483 | pos += sizeof(__le32); | |
484 | ||
485 | /* antenna selection */ | |
486 | pos += sizeof(u8); | |
9ac19a90 JB |
487 | } |
488 | ||
62ae67be JB |
489 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
490 | ieee80211_tx_skb(sdata, skb); | |
9ac19a90 JB |
491 | } |
492 | ||
493 | ||
ef422bc0 | 494 | static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, |
667503dd JB |
495 | const u8 *bssid, u16 stype, u16 reason, |
496 | void *cookie) | |
9ac19a90 JB |
497 | { |
498 | struct ieee80211_local *local = sdata->local; | |
46900298 | 499 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
9ac19a90 JB |
500 | struct sk_buff *skb; |
501 | struct ieee80211_mgmt *mgmt; | |
9aed3cc1 | 502 | |
65fc73ac | 503 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
9ac19a90 | 504 | if (!skb) { |
ef422bc0 | 505 | printk(KERN_DEBUG "%s: failed to allocate buffer for " |
47846c9b | 506 | "deauth/disassoc frame\n", sdata->name); |
9ac19a90 JB |
507 | return; |
508 | } | |
509 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
510 | ||
511 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
512 | memset(mgmt, 0, 24); | |
77fdaa12 | 513 | memcpy(mgmt->da, bssid, ETH_ALEN); |
47846c9b | 514 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
77fdaa12 | 515 | memcpy(mgmt->bssid, bssid, ETH_ALEN); |
ef422bc0 | 516 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); |
9ac19a90 | 517 | skb_put(skb, 2); |
ef422bc0 | 518 | /* u.deauth.reason_code == u.disassoc.reason_code */ |
9ac19a90 JB |
519 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
520 | ||
53b46b84 | 521 | if (stype == IEEE80211_STYPE_DEAUTH) |
ce470613 HS |
522 | if (cookie) |
523 | __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); | |
524 | else | |
525 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); | |
53b46b84 | 526 | else |
ce470613 HS |
527 | if (cookie) |
528 | __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); | |
529 | else | |
530 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); | |
62ae67be JB |
531 | if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED)) |
532 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; | |
533 | ieee80211_tx_skb(sdata, skb); | |
9ac19a90 JB |
534 | } |
535 | ||
572e0012 KV |
536 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
537 | struct ieee80211_sub_if_data *sdata) | |
538 | { | |
46900298 | 539 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
572e0012 KV |
540 | struct ieee80211_pspoll *pspoll; |
541 | struct sk_buff *skb; | |
542 | u16 fc; | |
543 | ||
544 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); | |
545 | if (!skb) { | |
546 | printk(KERN_DEBUG "%s: failed to allocate buffer for " | |
47846c9b | 547 | "pspoll frame\n", sdata->name); |
572e0012 KV |
548 | return; |
549 | } | |
550 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
551 | ||
552 | pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll)); | |
553 | memset(pspoll, 0, sizeof(*pspoll)); | |
554 | fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM; | |
555 | pspoll->frame_control = cpu_to_le16(fc); | |
46900298 | 556 | pspoll->aid = cpu_to_le16(ifmgd->aid); |
572e0012 KV |
557 | |
558 | /* aid in PS-Poll has its two MSBs each set to 1 */ | |
559 | pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14); | |
560 | ||
46900298 | 561 | memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN); |
47846c9b | 562 | memcpy(pspoll->ta, sdata->vif.addr, ETH_ALEN); |
572e0012 | 563 | |
62ae67be JB |
564 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
565 | ieee80211_tx_skb(sdata, skb); | |
572e0012 KV |
566 | } |
567 | ||
965bedad JB |
568 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
569 | struct ieee80211_sub_if_data *sdata, | |
570 | int powersave) | |
571 | { | |
572 | struct sk_buff *skb; | |
573 | struct ieee80211_hdr *nullfunc; | |
574 | __le16 fc; | |
575 | ||
576 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) | |
577 | return; | |
578 | ||
579 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); | |
580 | if (!skb) { | |
581 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " | |
47846c9b | 582 | "frame\n", sdata->name); |
965bedad JB |
583 | return; |
584 | } | |
585 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
586 | ||
587 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); | |
588 | memset(nullfunc, 0, 24); | |
589 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | | |
590 | IEEE80211_FCTL_TODS); | |
591 | if (powersave) | |
592 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); | |
593 | nullfunc->frame_control = fc; | |
594 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); | |
47846c9b | 595 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
965bedad JB |
596 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
597 | ||
62ae67be JB |
598 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
599 | ieee80211_tx_skb(sdata, skb); | |
965bedad JB |
600 | } |
601 | ||
cc32abd4 JB |
602 | /* spectrum management related things */ |
603 | static void ieee80211_chswitch_work(struct work_struct *work) | |
604 | { | |
605 | struct ieee80211_sub_if_data *sdata = | |
606 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); | |
cc32abd4 JB |
607 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
608 | ||
9607e6b6 | 609 | if (!ieee80211_sdata_running(sdata)) |
cc32abd4 JB |
610 | return; |
611 | ||
77fdaa12 JB |
612 | mutex_lock(&ifmgd->mtx); |
613 | if (!ifmgd->associated) | |
614 | goto out; | |
cc32abd4 JB |
615 | |
616 | sdata->local->oper_channel = sdata->local->csa_channel; | |
77fdaa12 JB |
617 | ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL); |
618 | ||
cc32abd4 | 619 | /* XXX: shouldn't really modify cfg80211-owned data! */ |
77fdaa12 | 620 | ifmgd->associated->cbss.channel = sdata->local->oper_channel; |
cc32abd4 | 621 | |
cc32abd4 JB |
622 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
623 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
77fdaa12 JB |
624 | out: |
625 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; | |
626 | mutex_unlock(&ifmgd->mtx); | |
cc32abd4 JB |
627 | } |
628 | ||
629 | static void ieee80211_chswitch_timer(unsigned long data) | |
630 | { | |
631 | struct ieee80211_sub_if_data *sdata = | |
632 | (struct ieee80211_sub_if_data *) data; | |
633 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
634 | ||
5bb644a0 JB |
635 | if (sdata->local->quiescing) { |
636 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); | |
637 | return; | |
638 | } | |
639 | ||
42935eca | 640 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
cc32abd4 JB |
641 | } |
642 | ||
643 | void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, | |
644 | struct ieee80211_channel_sw_ie *sw_elem, | |
645 | struct ieee80211_bss *bss) | |
646 | { | |
647 | struct ieee80211_channel *new_ch; | |
648 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
649 | int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num); | |
650 | ||
77fdaa12 JB |
651 | ASSERT_MGD_MTX(ifmgd); |
652 | ||
653 | if (!ifmgd->associated) | |
cc32abd4 JB |
654 | return; |
655 | ||
fbe9c429 | 656 | if (sdata->local->scanning) |
cc32abd4 JB |
657 | return; |
658 | ||
659 | /* Disregard subsequent beacons if we are already running a timer | |
660 | processing a CSA */ | |
661 | ||
662 | if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED) | |
663 | return; | |
664 | ||
665 | new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq); | |
666 | if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) | |
667 | return; | |
668 | ||
669 | sdata->local->csa_channel = new_ch; | |
670 | ||
671 | if (sw_elem->count <= 1) { | |
42935eca | 672 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
cc32abd4 JB |
673 | } else { |
674 | ieee80211_stop_queues_by_reason(&sdata->local->hw, | |
675 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
676 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; | |
677 | mod_timer(&ifmgd->chswitch_timer, | |
678 | jiffies + | |
679 | msecs_to_jiffies(sw_elem->count * | |
680 | bss->cbss.beacon_interval)); | |
681 | } | |
682 | } | |
683 | ||
684 | static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, | |
685 | u16 capab_info, u8 *pwr_constr_elem, | |
686 | u8 pwr_constr_elem_len) | |
687 | { | |
688 | struct ieee80211_conf *conf = &sdata->local->hw.conf; | |
689 | ||
690 | if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT)) | |
691 | return; | |
692 | ||
693 | /* Power constraint IE length should be 1 octet */ | |
694 | if (pwr_constr_elem_len != 1) | |
695 | return; | |
696 | ||
697 | if ((*pwr_constr_elem <= conf->channel->max_power) && | |
698 | (*pwr_constr_elem != sdata->local->power_constr_level)) { | |
699 | sdata->local->power_constr_level = *pwr_constr_elem; | |
700 | ieee80211_hw_config(sdata->local, 0); | |
701 | } | |
702 | } | |
703 | ||
965bedad JB |
704 | /* powersave */ |
705 | static void ieee80211_enable_ps(struct ieee80211_local *local, | |
706 | struct ieee80211_sub_if_data *sdata) | |
707 | { | |
708 | struct ieee80211_conf *conf = &local->hw.conf; | |
709 | ||
d5edaedc JB |
710 | /* |
711 | * If we are scanning right now then the parameters will | |
712 | * take effect when scan finishes. | |
713 | */ | |
fbe9c429 | 714 | if (local->scanning) |
d5edaedc JB |
715 | return; |
716 | ||
965bedad JB |
717 | if (conf->dynamic_ps_timeout > 0 && |
718 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { | |
719 | mod_timer(&local->dynamic_ps_timer, jiffies + | |
720 | msecs_to_jiffies(conf->dynamic_ps_timeout)); | |
721 | } else { | |
722 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) | |
723 | ieee80211_send_nullfunc(local, sdata, 1); | |
724 | conf->flags |= IEEE80211_CONF_PS; | |
725 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
726 | } | |
727 | } | |
728 | ||
729 | static void ieee80211_change_ps(struct ieee80211_local *local) | |
730 | { | |
731 | struct ieee80211_conf *conf = &local->hw.conf; | |
732 | ||
733 | if (local->ps_sdata) { | |
965bedad JB |
734 | ieee80211_enable_ps(local, local->ps_sdata); |
735 | } else if (conf->flags & IEEE80211_CONF_PS) { | |
736 | conf->flags &= ~IEEE80211_CONF_PS; | |
737 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
738 | del_timer_sync(&local->dynamic_ps_timer); | |
739 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
740 | } | |
741 | } | |
742 | ||
743 | /* need to hold RTNL or interface lock */ | |
10f644a4 | 744 | void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency) |
965bedad JB |
745 | { |
746 | struct ieee80211_sub_if_data *sdata, *found = NULL; | |
747 | int count = 0; | |
748 | ||
749 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) { | |
750 | local->ps_sdata = NULL; | |
751 | return; | |
752 | } | |
753 | ||
754 | list_for_each_entry(sdata, &local->interfaces, list) { | |
9607e6b6 | 755 | if (!ieee80211_sdata_running(sdata)) |
965bedad JB |
756 | continue; |
757 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
758 | continue; | |
759 | found = sdata; | |
760 | count++; | |
761 | } | |
762 | ||
43f78531 | 763 | if (count == 1 && found->u.mgd.powersave && |
77fdaa12 | 764 | found->u.mgd.associated && list_empty(&found->u.mgd.work_list) && |
b291ba11 JB |
765 | !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL | |
766 | IEEE80211_STA_CONNECTION_POLL))) { | |
10f644a4 JB |
767 | s32 beaconint_us; |
768 | ||
769 | if (latency < 0) | |
770 | latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY); | |
771 | ||
772 | beaconint_us = ieee80211_tu_to_usec( | |
773 | found->vif.bss_conf.beacon_int); | |
774 | ||
04fe2037 | 775 | if (beaconint_us > latency) { |
10f644a4 | 776 | local->ps_sdata = NULL; |
04fe2037 JB |
777 | } else { |
778 | u8 dtimper = found->vif.bss_conf.dtim_period; | |
779 | int maxslp = 1; | |
780 | ||
781 | if (dtimper > 1) | |
782 | maxslp = min_t(int, dtimper, | |
783 | latency / beaconint_us); | |
784 | ||
9ccebe61 | 785 | local->hw.conf.max_sleep_period = maxslp; |
10f644a4 | 786 | local->ps_sdata = found; |
04fe2037 | 787 | } |
10f644a4 | 788 | } else { |
965bedad | 789 | local->ps_sdata = NULL; |
10f644a4 | 790 | } |
965bedad JB |
791 | |
792 | ieee80211_change_ps(local); | |
793 | } | |
794 | ||
795 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) | |
796 | { | |
797 | struct ieee80211_local *local = | |
798 | container_of(work, struct ieee80211_local, | |
799 | dynamic_ps_disable_work); | |
800 | ||
801 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { | |
802 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
803 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
804 | } | |
805 | ||
806 | ieee80211_wake_queues_by_reason(&local->hw, | |
807 | IEEE80211_QUEUE_STOP_REASON_PS); | |
808 | } | |
809 | ||
810 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) | |
811 | { | |
812 | struct ieee80211_local *local = | |
813 | container_of(work, struct ieee80211_local, | |
814 | dynamic_ps_enable_work); | |
815 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; | |
816 | ||
817 | /* can only happen when PS was just disabled anyway */ | |
818 | if (!sdata) | |
819 | return; | |
820 | ||
821 | if (local->hw.conf.flags & IEEE80211_CONF_PS) | |
822 | return; | |
823 | ||
824 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) | |
825 | ieee80211_send_nullfunc(local, sdata, 1); | |
826 | ||
827 | local->hw.conf.flags |= IEEE80211_CONF_PS; | |
828 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
829 | } | |
830 | ||
831 | void ieee80211_dynamic_ps_timer(unsigned long data) | |
832 | { | |
833 | struct ieee80211_local *local = (void *) data; | |
834 | ||
78f1a8b7 | 835 | if (local->quiescing || local->suspended) |
5bb644a0 JB |
836 | return; |
837 | ||
42935eca | 838 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
965bedad JB |
839 | } |
840 | ||
60f8b39c | 841 | /* MLME */ |
f698d856 | 842 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
46900298 | 843 | struct ieee80211_if_managed *ifmgd, |
f0706e82 JB |
844 | u8 *wmm_param, size_t wmm_param_len) |
845 | { | |
f0706e82 JB |
846 | struct ieee80211_tx_queue_params params; |
847 | size_t left; | |
848 | int count; | |
849 | u8 *pos; | |
850 | ||
46900298 | 851 | if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) |
3434fbd3 JB |
852 | return; |
853 | ||
854 | if (!wmm_param) | |
855 | return; | |
856 | ||
f0706e82 JB |
857 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
858 | return; | |
859 | count = wmm_param[6] & 0x0f; | |
46900298 | 860 | if (count == ifmgd->wmm_last_param_set) |
f0706e82 | 861 | return; |
46900298 | 862 | ifmgd->wmm_last_param_set = count; |
f0706e82 JB |
863 | |
864 | pos = wmm_param + 8; | |
865 | left = wmm_param_len - 8; | |
866 | ||
867 | memset(¶ms, 0, sizeof(params)); | |
868 | ||
f0706e82 JB |
869 | local->wmm_acm = 0; |
870 | for (; left >= 4; left -= 4, pos += 4) { | |
871 | int aci = (pos[0] >> 5) & 0x03; | |
872 | int acm = (pos[0] >> 4) & 0x01; | |
873 | int queue; | |
874 | ||
875 | switch (aci) { | |
0eeb59fe | 876 | case 1: /* AC_BK */ |
e100bb64 | 877 | queue = 3; |
988c0f72 | 878 | if (acm) |
0eeb59fe | 879 | local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
f0706e82 | 880 | break; |
0eeb59fe | 881 | case 2: /* AC_VI */ |
e100bb64 | 882 | queue = 1; |
988c0f72 | 883 | if (acm) |
0eeb59fe | 884 | local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
f0706e82 | 885 | break; |
0eeb59fe | 886 | case 3: /* AC_VO */ |
e100bb64 | 887 | queue = 0; |
988c0f72 | 888 | if (acm) |
0eeb59fe | 889 | local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
f0706e82 | 890 | break; |
0eeb59fe | 891 | case 0: /* AC_BE */ |
f0706e82 | 892 | default: |
e100bb64 | 893 | queue = 2; |
988c0f72 | 894 | if (acm) |
0eeb59fe | 895 | local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
f0706e82 JB |
896 | break; |
897 | } | |
898 | ||
899 | params.aifs = pos[0] & 0x0f; | |
900 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); | |
901 | params.cw_min = ecw2cw(pos[1] & 0x0f); | |
f434b2d1 | 902 | params.txop = get_unaligned_le16(pos + 2); |
f4ea83dd | 903 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
f0706e82 | 904 | printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " |
3330d7be | 905 | "cWmin=%d cWmax=%d txop=%d\n", |
0bffe40f JB |
906 | wiphy_name(local->hw.wiphy), queue, aci, acm, |
907 | params.aifs, params.cw_min, params.cw_max, params.txop); | |
3330d7be | 908 | #endif |
24487981 | 909 | if (drv_conf_tx(local, queue, ¶ms) && local->ops->conf_tx) |
f0706e82 | 910 | printk(KERN_DEBUG "%s: failed to set TX queue " |
0bffe40f JB |
911 | "parameters for queue %d\n", |
912 | wiphy_name(local->hw.wiphy), queue); | |
f0706e82 JB |
913 | } |
914 | } | |
915 | ||
7a5158ef JB |
916 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
917 | u16 capab, bool erp_valid, u8 erp) | |
5628221c | 918 | { |
bda3933a | 919 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
471b3efd | 920 | u32 changed = 0; |
7a5158ef JB |
921 | bool use_protection; |
922 | bool use_short_preamble; | |
923 | bool use_short_slot; | |
924 | ||
925 | if (erp_valid) { | |
926 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; | |
927 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; | |
928 | } else { | |
929 | use_protection = false; | |
930 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); | |
931 | } | |
932 | ||
933 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); | |
5628221c | 934 | |
471b3efd | 935 | if (use_protection != bss_conf->use_cts_prot) { |
471b3efd JB |
936 | bss_conf->use_cts_prot = use_protection; |
937 | changed |= BSS_CHANGED_ERP_CTS_PROT; | |
5628221c | 938 | } |
7e9ed188 | 939 | |
d43c7b37 | 940 | if (use_short_preamble != bss_conf->use_short_preamble) { |
d43c7b37 | 941 | bss_conf->use_short_preamble = use_short_preamble; |
471b3efd | 942 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
7e9ed188 | 943 | } |
d9430a32 | 944 | |
7a5158ef | 945 | if (use_short_slot != bss_conf->use_short_slot) { |
7a5158ef JB |
946 | bss_conf->use_short_slot = use_short_slot; |
947 | changed |= BSS_CHANGED_ERP_SLOT; | |
50c4afb9 JL |
948 | } |
949 | ||
950 | return changed; | |
951 | } | |
952 | ||
f698d856 | 953 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
63f170e0 | 954 | struct ieee80211_bss *bss, |
ae5eb026 | 955 | u32 bss_info_changed) |
f0706e82 | 956 | { |
471b3efd | 957 | struct ieee80211_local *local = sdata->local; |
d6f2da5b | 958 | |
ae5eb026 | 959 | bss_info_changed |= BSS_CHANGED_ASSOC; |
77fdaa12 JB |
960 | /* set timing information */ |
961 | sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval; | |
962 | sdata->vif.bss_conf.timestamp = bss->cbss.tsf; | |
963 | sdata->vif.bss_conf.dtim_period = bss->dtim_period; | |
5628221c | 964 | |
77fdaa12 JB |
965 | bss_info_changed |= BSS_CHANGED_BEACON_INT; |
966 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, | |
967 | bss->cbss.capability, bss->has_erp_value, bss->erp_value); | |
21c0cbe7 | 968 | |
77fdaa12 JB |
969 | sdata->u.mgd.associated = bss; |
970 | memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN); | |
f0706e82 | 971 | |
b291ba11 JB |
972 | /* just to be sure */ |
973 | sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | | |
974 | IEEE80211_STA_BEACON_POLL); | |
975 | ||
0183826b JB |
976 | /* |
977 | * Always handle WMM once after association regardless | |
978 | * of the first value the AP uses. Setting -1 here has | |
979 | * that effect because the AP values is an unsigned | |
980 | * 4-bit value. | |
981 | */ | |
982 | sdata->u.mgd.wmm_last_param_set = -1; | |
983 | ||
9ac19a90 | 984 | ieee80211_led_assoc(local, 1); |
9306102e | 985 | |
bda3933a | 986 | sdata->vif.bss_conf.assoc = 1; |
96dd22ac JB |
987 | /* |
988 | * For now just always ask the driver to update the basic rateset | |
989 | * when we have associated, we aren't checking whether it actually | |
990 | * changed or not. | |
991 | */ | |
ae5eb026 | 992 | bss_info_changed |= BSS_CHANGED_BASIC_RATES; |
9cef8737 JB |
993 | |
994 | /* And the BSSID changed - we're associated now */ | |
995 | bss_info_changed |= BSS_CHANGED_BSSID; | |
996 | ||
ae5eb026 | 997 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
f0706e82 | 998 | |
056508dc JB |
999 | mutex_lock(&local->iflist_mtx); |
1000 | ieee80211_recalc_ps(local, -1); | |
0f78231b | 1001 | ieee80211_recalc_smps(local, sdata); |
056508dc | 1002 | mutex_unlock(&local->iflist_mtx); |
e0cb686f | 1003 | |
53623f1a | 1004 | netif_start_queue(sdata->dev); |
9ac19a90 | 1005 | netif_carrier_on(sdata->dev); |
f0706e82 JB |
1006 | } |
1007 | ||
f679f65d JB |
1008 | static void ieee80211_remove_auth_bss(struct ieee80211_local *local, |
1009 | struct ieee80211_work *wk) | |
1010 | { | |
1011 | struct cfg80211_bss *cbss; | |
1012 | u16 capa_val = WLAN_CAPABILITY_ESS; | |
1013 | ||
1014 | if (wk->auth.privacy) | |
1015 | capa_val |= WLAN_CAPABILITY_PRIVACY; | |
1016 | ||
1017 | cbss = cfg80211_get_bss(local->hw.wiphy, wk->chan, wk->auth.bssid, | |
1018 | wk->auth.ssid, wk->auth.ssid_len, | |
1019 | WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, | |
1020 | capa_val); | |
1021 | if (!cbss) | |
1022 | return; | |
1023 | ||
1024 | cfg80211_unlink_bss(local->hw.wiphy, cbss); | |
1025 | cfg80211_put_bss(cbss); | |
1026 | } | |
1027 | ||
77fdaa12 JB |
1028 | static enum rx_mgmt_action __must_check |
1029 | ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata, | |
f679f65d | 1030 | struct ieee80211_work *wk) |
f0706e82 | 1031 | { |
46900298 | 1032 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
11432379 | 1033 | struct ieee80211_local *local = sdata->local; |
46900298 | 1034 | |
f679f65d JB |
1035 | wk->auth.tries++; |
1036 | if (wk->auth.tries > IEEE80211_AUTH_MAX_TRIES) { | |
0c68ae26 | 1037 | printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n", |
f679f65d | 1038 | sdata->name, wk->auth.bssid); |
7a947080 VT |
1039 | |
1040 | /* | |
1041 | * Most likely AP is not in the range so remove the | |
77fdaa12 | 1042 | * bss struct for that AP. |
7a947080 | 1043 | */ |
f679f65d | 1044 | ieee80211_remove_auth_bss(local, wk); |
11432379 HS |
1045 | |
1046 | /* | |
1047 | * We might have a pending scan which had no chance to run yet | |
77fdaa12 JB |
1048 | * due to work needing to be done. Hence, queue the STAs work |
1049 | * again for that. | |
11432379 | 1050 | */ |
42935eca | 1051 | ieee80211_queue_work(&local->hw, &ifmgd->work); |
77fdaa12 | 1052 | return RX_MGMT_CFG80211_AUTH_TO; |
f0706e82 | 1053 | } |
f0706e82 | 1054 | |
77fdaa12 | 1055 | printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n", |
f679f65d | 1056 | sdata->name, wk->auth.bssid, wk->auth.tries); |
f0706e82 | 1057 | |
77fdaa12 JB |
1058 | /* |
1059 | * Direct probe is sent to broadcast address as some APs | |
9ac19a90 JB |
1060 | * will not answer to direct packet in unassociated state. |
1061 | */ | |
f679f65d JB |
1062 | ieee80211_send_probe_req(sdata, NULL, wk->auth.ssid, wk->auth.ssid_len, |
1063 | NULL, 0); | |
77fdaa12 JB |
1064 | |
1065 | wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; | |
ca386f31 | 1066 | run_again(ifmgd, wk->timeout); |
9ac19a90 | 1067 | |
77fdaa12 | 1068 | return RX_MGMT_NONE; |
60f8b39c | 1069 | } |
f0706e82 | 1070 | |
9ac19a90 | 1071 | |
77fdaa12 JB |
1072 | static enum rx_mgmt_action __must_check |
1073 | ieee80211_authenticate(struct ieee80211_sub_if_data *sdata, | |
f679f65d | 1074 | struct ieee80211_work *wk) |
f0706e82 | 1075 | { |
46900298 | 1076 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
11432379 | 1077 | struct ieee80211_local *local = sdata->local; |
46900298 | 1078 | |
f679f65d JB |
1079 | wk->auth.tries++; |
1080 | if (wk->auth.tries > IEEE80211_AUTH_MAX_TRIES) { | |
0c68ae26 | 1081 | printk(KERN_DEBUG "%s: authentication with AP %pM" |
f679f65d | 1082 | " timed out\n", sdata->name, wk->auth.bssid); |
77fdaa12 JB |
1083 | |
1084 | /* | |
1085 | * Most likely AP is not in the range so remove the | |
1086 | * bss struct for that AP. | |
1087 | */ | |
f679f65d | 1088 | ieee80211_remove_auth_bss(local, wk); |
11432379 HS |
1089 | |
1090 | /* | |
1091 | * We might have a pending scan which had no chance to run yet | |
77fdaa12 JB |
1092 | * due to work needing to be done. Hence, queue the STAs work |
1093 | * again for that. | |
11432379 | 1094 | */ |
42935eca | 1095 | ieee80211_queue_work(&local->hw, &ifmgd->work); |
77fdaa12 | 1096 | return RX_MGMT_CFG80211_AUTH_TO; |
f0706e82 | 1097 | } |
f0706e82 | 1098 | |
77fdaa12 | 1099 | printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n", |
f679f65d | 1100 | sdata->name, wk->auth.bssid, wk->auth.tries); |
77fdaa12 | 1101 | |
f679f65d JB |
1102 | ieee80211_send_auth(sdata, 1, wk->auth.algorithm, wk->ie, wk->ie_len, |
1103 | wk->auth.bssid, NULL, 0, 0); | |
1104 | wk->auth.transaction = 2; | |
f0706e82 | 1105 | |
77fdaa12 | 1106 | wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
ca386f31 | 1107 | run_again(ifmgd, wk->timeout); |
9ac19a90 | 1108 | |
77fdaa12 | 1109 | return RX_MGMT_NONE; |
f0706e82 JB |
1110 | } |
1111 | ||
63f170e0 | 1112 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata) |
aa458d17 | 1113 | { |
46900298 | 1114 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
aa458d17 TW |
1115 | struct ieee80211_local *local = sdata->local; |
1116 | struct sta_info *sta; | |
e0cb686f | 1117 | u32 changed = 0, config_changed = 0; |
b291ba11 | 1118 | u8 bssid[ETH_ALEN]; |
aa458d17 | 1119 | |
77fdaa12 JB |
1120 | ASSERT_MGD_MTX(ifmgd); |
1121 | ||
b291ba11 JB |
1122 | if (WARN_ON(!ifmgd->associated)) |
1123 | return; | |
1124 | ||
1125 | memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); | |
1126 | ||
77fdaa12 JB |
1127 | ifmgd->associated = NULL; |
1128 | memset(ifmgd->bssid, 0, ETH_ALEN); | |
1129 | ||
1130 | /* | |
1131 | * we need to commit the associated = NULL change because the | |
1132 | * scan code uses that to determine whether this iface should | |
1133 | * go to/wake up from powersave or not -- and could otherwise | |
1134 | * wake the queues erroneously. | |
1135 | */ | |
1136 | smp_mb(); | |
1137 | ||
1138 | /* | |
1139 | * Thus, we can only afterwards stop the queues -- to account | |
1140 | * for the case where another CPU is finishing a scan at this | |
1141 | * time -- we don't want the scan code to enable queues. | |
1142 | */ | |
aa458d17 | 1143 | |
53623f1a | 1144 | netif_stop_queue(sdata->dev); |
aa458d17 TW |
1145 | netif_carrier_off(sdata->dev); |
1146 | ||
1fa6f4af | 1147 | rcu_read_lock(); |
abe60632 | 1148 | sta = sta_info_get(sdata, bssid); |
1fa6f4af JB |
1149 | if (sta) |
1150 | ieee80211_sta_tear_down_BA_sessions(sta); | |
1151 | rcu_read_unlock(); | |
aa458d17 | 1152 | |
f5e5bf25 TW |
1153 | changed |= ieee80211_reset_erp_info(sdata); |
1154 | ||
f5e5bf25 | 1155 | ieee80211_led_assoc(local, 0); |
ae5eb026 JB |
1156 | changed |= BSS_CHANGED_ASSOC; |
1157 | sdata->vif.bss_conf.assoc = false; | |
f5e5bf25 | 1158 | |
aa837e1d JB |
1159 | ieee80211_set_wmm_default(sdata); |
1160 | ||
4797938c | 1161 | /* channel(_type) changes are handled by ieee80211_hw_config */ |
094d05dc | 1162 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
e0cb686f | 1163 | |
413ad50a JB |
1164 | /* on the next assoc, re-program HT parameters */ |
1165 | sdata->ht_opmode_valid = false; | |
1166 | ||
a8302de9 VT |
1167 | local->power_constr_level = 0; |
1168 | ||
520eb820 KV |
1169 | del_timer_sync(&local->dynamic_ps_timer); |
1170 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
1171 | ||
e0cb686f KV |
1172 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
1173 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
1174 | config_changed |= IEEE80211_CONF_CHANGE_PS; | |
1175 | } | |
ae5eb026 | 1176 | |
e0cb686f | 1177 | ieee80211_hw_config(local, config_changed); |
9cef8737 JB |
1178 | |
1179 | /* And the BSSID changed -- not very interesting here */ | |
1180 | changed |= BSS_CHANGED_BSSID; | |
ae5eb026 | 1181 | ieee80211_bss_info_change_notify(sdata, changed); |
8e268e47 TW |
1182 | |
1183 | rcu_read_lock(); | |
1184 | ||
abe60632 | 1185 | sta = sta_info_get(sdata, bssid); |
8e268e47 TW |
1186 | if (!sta) { |
1187 | rcu_read_unlock(); | |
1188 | return; | |
1189 | } | |
1190 | ||
1191 | sta_info_unlink(&sta); | |
1192 | ||
1193 | rcu_read_unlock(); | |
1194 | ||
1195 | sta_info_destroy(sta); | |
aa458d17 | 1196 | } |
f0706e82 | 1197 | |
77fdaa12 JB |
1198 | static enum rx_mgmt_action __must_check |
1199 | ieee80211_associate(struct ieee80211_sub_if_data *sdata, | |
f679f65d | 1200 | struct ieee80211_work *wk) |
f0706e82 | 1201 | { |
46900298 | 1202 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
11432379 | 1203 | struct ieee80211_local *local = sdata->local; |
46900298 | 1204 | |
f679f65d JB |
1205 | wk->assoc.tries++; |
1206 | if (wk->assoc.tries > IEEE80211_ASSOC_MAX_TRIES) { | |
0c68ae26 | 1207 | printk(KERN_DEBUG "%s: association with AP %pM" |
f0706e82 | 1208 | " timed out\n", |
f679f65d | 1209 | sdata->name, wk->assoc.bssid); |
77fdaa12 JB |
1210 | |
1211 | /* | |
1212 | * Most likely AP is not in the range so remove the | |
1213 | * bss struct for that AP. | |
1214 | */ | |
f679f65d | 1215 | cfg80211_unlink_bss(local->hw.wiphy, &wk->assoc.bss->cbss); |
77fdaa12 | 1216 | |
11432379 HS |
1217 | /* |
1218 | * We might have a pending scan which had no chance to run yet | |
77fdaa12 JB |
1219 | * due to work needing to be done. Hence, queue the STAs work |
1220 | * again for that. | |
11432379 | 1221 | */ |
42935eca | 1222 | ieee80211_queue_work(&local->hw, &ifmgd->work); |
77fdaa12 | 1223 | return RX_MGMT_CFG80211_ASSOC_TO; |
f0706e82 JB |
1224 | } |
1225 | ||
77fdaa12 | 1226 | printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n", |
f679f65d | 1227 | sdata->name, wk->assoc.bssid, wk->assoc.tries); |
77fdaa12 JB |
1228 | ieee80211_send_assoc(sdata, wk); |
1229 | ||
1230 | wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; | |
ca386f31 | 1231 | run_again(ifmgd, wk->timeout); |
f0706e82 | 1232 | |
77fdaa12 | 1233 | return RX_MGMT_NONE; |
f0706e82 JB |
1234 | } |
1235 | ||
3cf335d5 KV |
1236 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
1237 | struct ieee80211_hdr *hdr) | |
1238 | { | |
1239 | /* | |
1240 | * We can postpone the mgd.timer whenever receiving unicast frames | |
1241 | * from AP because we know that the connection is working both ways | |
1242 | * at that time. But multicast frames (and hence also beacons) must | |
1243 | * be ignored here, because we need to trigger the timer during | |
b291ba11 JB |
1244 | * data idle periods for sending the periodic probe request to the |
1245 | * AP we're connected to. | |
3cf335d5 | 1246 | */ |
b291ba11 JB |
1247 | if (is_multicast_ether_addr(hdr->addr1)) |
1248 | return; | |
1249 | ||
1250 | mod_timer(&sdata->u.mgd.conn_mon_timer, | |
1251 | round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); | |
3cf335d5 | 1252 | } |
f0706e82 | 1253 | |
a43abf29 ML |
1254 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
1255 | { | |
1256 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1257 | const u8 *ssid; | |
1258 | ||
1259 | ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID); | |
1260 | ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid, | |
1261 | ssid + 2, ssid[1], NULL, 0); | |
1262 | ||
1263 | ifmgd->probe_send_count++; | |
1264 | ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT; | |
1265 | run_again(ifmgd, ifmgd->probe_timeout); | |
1266 | } | |
1267 | ||
b291ba11 JB |
1268 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
1269 | bool beacon) | |
04de8381 | 1270 | { |
04de8381 | 1271 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
b291ba11 | 1272 | bool already = false; |
34bfc411 | 1273 | |
9607e6b6 | 1274 | if (!ieee80211_sdata_running(sdata)) |
0e2b6286 JB |
1275 | return; |
1276 | ||
91a3bd76 LR |
1277 | if (sdata->local->scanning) |
1278 | return; | |
1279 | ||
77fdaa12 JB |
1280 | mutex_lock(&ifmgd->mtx); |
1281 | ||
1282 | if (!ifmgd->associated) | |
1283 | goto out; | |
1284 | ||
a860402d | 1285 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
b291ba11 JB |
1286 | if (beacon && net_ratelimit()) |
1287 | printk(KERN_DEBUG "%s: detected beacon loss from AP " | |
47846c9b | 1288 | "- sending probe request\n", sdata->name); |
a860402d | 1289 | #endif |
04de8381 | 1290 | |
b291ba11 JB |
1291 | /* |
1292 | * The driver/our work has already reported this event or the | |
1293 | * connection monitoring has kicked in and we have already sent | |
1294 | * a probe request. Or maybe the AP died and the driver keeps | |
1295 | * reporting until we disassociate... | |
1296 | * | |
1297 | * In either case we have to ignore the current call to this | |
1298 | * function (except for setting the correct probe reason bit) | |
1299 | * because otherwise we would reset the timer every time and | |
1300 | * never check whether we received a probe response! | |
1301 | */ | |
1302 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | | |
1303 | IEEE80211_STA_CONNECTION_POLL)) | |
1304 | already = true; | |
1305 | ||
1306 | if (beacon) | |
1307 | ifmgd->flags |= IEEE80211_STA_BEACON_POLL; | |
1308 | else | |
1309 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; | |
1310 | ||
1311 | if (already) | |
1312 | goto out; | |
1313 | ||
4e751843 JB |
1314 | mutex_lock(&sdata->local->iflist_mtx); |
1315 | ieee80211_recalc_ps(sdata->local, -1); | |
1316 | mutex_unlock(&sdata->local->iflist_mtx); | |
1317 | ||
a43abf29 ML |
1318 | ifmgd->probe_send_count = 0; |
1319 | ieee80211_mgd_probe_ap_send(sdata); | |
77fdaa12 JB |
1320 | out: |
1321 | mutex_unlock(&ifmgd->mtx); | |
04de8381 KV |
1322 | } |
1323 | ||
b291ba11 JB |
1324 | void ieee80211_beacon_loss_work(struct work_struct *work) |
1325 | { | |
1326 | struct ieee80211_sub_if_data *sdata = | |
1327 | container_of(work, struct ieee80211_sub_if_data, | |
1328 | u.mgd.beacon_loss_work); | |
1329 | ||
1330 | ieee80211_mgd_probe_ap(sdata, true); | |
1331 | } | |
1332 | ||
04de8381 KV |
1333 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
1334 | { | |
1335 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1336 | ||
42935eca | 1337 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.beacon_loss_work); |
04de8381 KV |
1338 | } |
1339 | EXPORT_SYMBOL(ieee80211_beacon_loss); | |
1340 | ||
77fdaa12 | 1341 | static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata, |
f679f65d | 1342 | struct ieee80211_work *wk) |
f0706e82 | 1343 | { |
63f170e0 JB |
1344 | list_del(&wk->list); |
1345 | kfree(wk); | |
47846c9b | 1346 | printk(KERN_DEBUG "%s: authenticated\n", sdata->name); |
f0706e82 JB |
1347 | } |
1348 | ||
1349 | ||
f698d856 | 1350 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
f679f65d | 1351 | struct ieee80211_work *wk, |
f0706e82 JB |
1352 | struct ieee80211_mgmt *mgmt, |
1353 | size_t len) | |
1354 | { | |
1355 | u8 *pos; | |
1356 | struct ieee802_11_elems elems; | |
1357 | ||
f0706e82 | 1358 | pos = mgmt->u.auth.variable; |
67a4cce4 | 1359 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
f4ea83dd | 1360 | if (!elems.challenge) |
f0706e82 | 1361 | return; |
f679f65d | 1362 | ieee80211_send_auth(sdata, 3, wk->auth.algorithm, |
46900298 | 1363 | elems.challenge - 2, elems.challenge_len + 2, |
f679f65d JB |
1364 | wk->auth.bssid, wk->auth.key, wk->auth.key_len, |
1365 | wk->auth.key_idx); | |
1366 | wk->auth.transaction = 4; | |
fe3d2c3f JB |
1367 | } |
1368 | ||
77fdaa12 JB |
1369 | static enum rx_mgmt_action __must_check |
1370 | ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, | |
f679f65d | 1371 | struct ieee80211_work *wk, |
77fdaa12 | 1372 | struct ieee80211_mgmt *mgmt, size_t len) |
f0706e82 | 1373 | { |
f0706e82 JB |
1374 | u16 auth_alg, auth_transaction, status_code; |
1375 | ||
f679f65d | 1376 | if (wk->type != IEEE80211_WORK_AUTH) |
77fdaa12 | 1377 | return RX_MGMT_NONE; |
f0706e82 | 1378 | |
f4ea83dd | 1379 | if (len < 24 + 6) |
77fdaa12 | 1380 | return RX_MGMT_NONE; |
f0706e82 | 1381 | |
f679f65d | 1382 | if (memcmp(wk->auth.bssid, mgmt->sa, ETH_ALEN) != 0) |
77fdaa12 | 1383 | return RX_MGMT_NONE; |
f0706e82 | 1384 | |
f679f65d | 1385 | if (memcmp(wk->auth.bssid, mgmt->bssid, ETH_ALEN) != 0) |
77fdaa12 | 1386 | return RX_MGMT_NONE; |
f0706e82 JB |
1387 | |
1388 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); | |
1389 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); | |
1390 | status_code = le16_to_cpu(mgmt->u.auth.status_code); | |
1391 | ||
f679f65d JB |
1392 | if (auth_alg != wk->auth.algorithm || |
1393 | auth_transaction != wk->auth.transaction) | |
77fdaa12 | 1394 | return RX_MGMT_NONE; |
f0706e82 JB |
1395 | |
1396 | if (status_code != WLAN_STATUS_SUCCESS) { | |
77fdaa12 JB |
1397 | list_del(&wk->list); |
1398 | kfree(wk); | |
1399 | return RX_MGMT_CFG80211_AUTH; | |
f0706e82 JB |
1400 | } |
1401 | ||
f679f65d | 1402 | switch (wk->auth.algorithm) { |
f0706e82 JB |
1403 | case WLAN_AUTH_OPEN: |
1404 | case WLAN_AUTH_LEAP: | |
636a5d36 | 1405 | case WLAN_AUTH_FT: |
77fdaa12 JB |
1406 | ieee80211_auth_completed(sdata, wk); |
1407 | return RX_MGMT_CFG80211_AUTH; | |
f0706e82 | 1408 | case WLAN_AUTH_SHARED_KEY: |
f679f65d | 1409 | if (wk->auth.transaction == 4) { |
77fdaa12 JB |
1410 | ieee80211_auth_completed(sdata, wk); |
1411 | return RX_MGMT_CFG80211_AUTH; | |
6039f6d2 | 1412 | } else |
77fdaa12 | 1413 | ieee80211_auth_challenge(sdata, wk, mgmt, len); |
f0706e82 JB |
1414 | break; |
1415 | } | |
77fdaa12 JB |
1416 | |
1417 | return RX_MGMT_NONE; | |
f0706e82 JB |
1418 | } |
1419 | ||
1420 | ||
77fdaa12 JB |
1421 | static enum rx_mgmt_action __must_check |
1422 | ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, | |
77fdaa12 | 1423 | struct ieee80211_mgmt *mgmt, size_t len) |
f0706e82 | 1424 | { |
46900298 | 1425 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
77fdaa12 | 1426 | const u8 *bssid = NULL; |
f0706e82 JB |
1427 | u16 reason_code; |
1428 | ||
f4ea83dd | 1429 | if (len < 24 + 2) |
77fdaa12 | 1430 | return RX_MGMT_NONE; |
f0706e82 | 1431 | |
77fdaa12 JB |
1432 | ASSERT_MGD_MTX(ifmgd); |
1433 | ||
63f170e0 | 1434 | bssid = ifmgd->associated->cbss.bssid; |
f0706e82 JB |
1435 | |
1436 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | |
1437 | ||
77fdaa12 | 1438 | printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n", |
47846c9b | 1439 | sdata->name, bssid, reason_code); |
77fdaa12 | 1440 | |
63f170e0 JB |
1441 | ieee80211_set_disassoc(sdata); |
1442 | ieee80211_recalc_idle(sdata->local); | |
f0706e82 | 1443 | |
77fdaa12 | 1444 | return RX_MGMT_CFG80211_DEAUTH; |
f0706e82 JB |
1445 | } |
1446 | ||
1447 | ||
77fdaa12 JB |
1448 | static enum rx_mgmt_action __must_check |
1449 | ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, | |
1450 | struct ieee80211_mgmt *mgmt, size_t len) | |
f0706e82 | 1451 | { |
46900298 | 1452 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 JB |
1453 | u16 reason_code; |
1454 | ||
f4ea83dd | 1455 | if (len < 24 + 2) |
77fdaa12 | 1456 | return RX_MGMT_NONE; |
f0706e82 | 1457 | |
77fdaa12 JB |
1458 | ASSERT_MGD_MTX(ifmgd); |
1459 | ||
1460 | if (WARN_ON(!ifmgd->associated)) | |
1461 | return RX_MGMT_NONE; | |
1462 | ||
1463 | if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN))) | |
1464 | return RX_MGMT_NONE; | |
f0706e82 JB |
1465 | |
1466 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); | |
1467 | ||
0ff71613 | 1468 | printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n", |
47846c9b | 1469 | sdata->name, mgmt->sa, reason_code); |
f0706e82 | 1470 | |
63f170e0 | 1471 | ieee80211_set_disassoc(sdata); |
bc83b681 | 1472 | ieee80211_recalc_idle(sdata->local); |
77fdaa12 | 1473 | return RX_MGMT_CFG80211_DISASSOC; |
f0706e82 JB |
1474 | } |
1475 | ||
1476 | ||
77fdaa12 JB |
1477 | static enum rx_mgmt_action __must_check |
1478 | ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, | |
f679f65d | 1479 | struct ieee80211_work *wk, |
77fdaa12 JB |
1480 | struct ieee80211_mgmt *mgmt, size_t len, |
1481 | bool reassoc) | |
f0706e82 | 1482 | { |
46900298 | 1483 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
471b3efd | 1484 | struct ieee80211_local *local = sdata->local; |
8318d78a | 1485 | struct ieee80211_supported_band *sband; |
f0706e82 | 1486 | struct sta_info *sta; |
f679f65d | 1487 | struct ieee80211_bss *bss = wk->assoc.bss; |
881d948c | 1488 | u32 rates, basic_rates; |
f0706e82 JB |
1489 | u16 capab_info, status_code, aid; |
1490 | struct ieee802_11_elems elems; | |
bda3933a | 1491 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
f0706e82 | 1492 | u8 *pos; |
ae5eb026 | 1493 | u32 changed = 0; |
5d1ec85f JB |
1494 | int i, j, err; |
1495 | bool have_higher_than_11mbit = false; | |
ae5eb026 | 1496 | u16 ap_ht_cap_flags; |
f0706e82 | 1497 | |
77fdaa12 JB |
1498 | /* |
1499 | * AssocResp and ReassocResp have identical structure, so process both | |
1500 | * of them in this function. | |
1501 | */ | |
f0706e82 | 1502 | |
f4ea83dd | 1503 | if (len < 24 + 6) |
77fdaa12 | 1504 | return RX_MGMT_NONE; |
f0706e82 | 1505 | |
63f170e0 | 1506 | if (memcmp(bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0) |
77fdaa12 | 1507 | return RX_MGMT_NONE; |
f0706e82 JB |
1508 | |
1509 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); | |
1510 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); | |
1511 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); | |
f0706e82 | 1512 | |
0c68ae26 | 1513 | printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x " |
f0706e82 | 1514 | "status=%d aid=%d)\n", |
47846c9b | 1515 | sdata->name, reassoc ? "Rea" : "A", mgmt->sa, |
ddd68587 | 1516 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
f0706e82 | 1517 | |
63a5ab82 JM |
1518 | pos = mgmt->u.assoc_resp.variable; |
1519 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); | |
1520 | ||
1521 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && | |
f797eb7e JM |
1522 | elems.timeout_int && elems.timeout_int_len == 5 && |
1523 | elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) { | |
63a5ab82 | 1524 | u32 tu, ms; |
f797eb7e | 1525 | tu = get_unaligned_le32(elems.timeout_int + 1); |
63a5ab82 JM |
1526 | ms = tu * 1024 / 1000; |
1527 | printk(KERN_DEBUG "%s: AP rejected association temporarily; " | |
1528 | "comeback duration %u TU (%u ms)\n", | |
47846c9b | 1529 | sdata->name, tu, ms); |
77fdaa12 | 1530 | wk->timeout = jiffies + msecs_to_jiffies(ms); |
63a5ab82 | 1531 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
ca386f31 | 1532 | run_again(ifmgd, jiffies + msecs_to_jiffies(ms)); |
77fdaa12 | 1533 | return RX_MGMT_NONE; |
63a5ab82 JM |
1534 | } |
1535 | ||
63f170e0 JB |
1536 | /* |
1537 | * Here the association was either successful or not. | |
1538 | */ | |
1539 | ||
1540 | /* delete work item -- must be before set_associated for PS */ | |
1541 | list_del(&wk->list); | |
1542 | kfree(wk); | |
1543 | ||
f0706e82 JB |
1544 | if (status_code != WLAN_STATUS_SUCCESS) { |
1545 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", | |
47846c9b | 1546 | sdata->name, status_code); |
77fdaa12 | 1547 | return RX_MGMT_CFG80211_ASSOC; |
f0706e82 JB |
1548 | } |
1549 | ||
1dd84aa2 JB |
1550 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
1551 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " | |
47846c9b | 1552 | "set\n", sdata->name, aid); |
1dd84aa2 JB |
1553 | aid &= ~(BIT(15) | BIT(14)); |
1554 | ||
f0706e82 JB |
1555 | if (!elems.supp_rates) { |
1556 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", | |
47846c9b | 1557 | sdata->name); |
77fdaa12 | 1558 | return RX_MGMT_NONE; |
f0706e82 JB |
1559 | } |
1560 | ||
47846c9b | 1561 | printk(KERN_DEBUG "%s: associated\n", sdata->name); |
46900298 | 1562 | ifmgd->aid = aid; |
f0706e82 | 1563 | |
63f170e0 | 1564 | sta = sta_info_alloc(sdata, bss->cbss.bssid, GFP_KERNEL); |
f0706e82 | 1565 | if (!sta) { |
5d1ec85f JB |
1566 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" |
1567 | " the AP\n", sdata->name); | |
1568 | return RX_MGMT_CFG80211_ASSOC_ERROR; | |
77fdaa12 | 1569 | } |
05e5e883 | 1570 | |
5d1ec85f JB |
1571 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | |
1572 | WLAN_STA_ASSOC_AP); | |
1573 | if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) | |
1574 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); | |
1575 | ||
60f8b39c JB |
1576 | rates = 0; |
1577 | basic_rates = 0; | |
1578 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
f709fc69 | 1579 | |
60f8b39c JB |
1580 | for (i = 0; i < elems.supp_rates_len; i++) { |
1581 | int rate = (elems.supp_rates[i] & 0x7f) * 5; | |
d61272cb | 1582 | bool is_basic = !!(elems.supp_rates[i] & 0x80); |
f709fc69 | 1583 | |
60f8b39c JB |
1584 | if (rate > 110) |
1585 | have_higher_than_11mbit = true; | |
1586 | ||
1587 | for (j = 0; j < sband->n_bitrates; j++) { | |
d61272cb | 1588 | if (sband->bitrates[j].bitrate == rate) { |
60f8b39c | 1589 | rates |= BIT(j); |
d61272cb TW |
1590 | if (is_basic) |
1591 | basic_rates |= BIT(j); | |
1592 | break; | |
1593 | } | |
f709fc69 | 1594 | } |
f709fc69 LCC |
1595 | } |
1596 | ||
60f8b39c JB |
1597 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
1598 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; | |
7e0986c1 | 1599 | bool is_basic = !!(elems.ext_supp_rates[i] & 0x80); |
f0706e82 | 1600 | |
60f8b39c JB |
1601 | if (rate > 110) |
1602 | have_higher_than_11mbit = true; | |
f0706e82 | 1603 | |
60f8b39c | 1604 | for (j = 0; j < sband->n_bitrates; j++) { |
d61272cb | 1605 | if (sband->bitrates[j].bitrate == rate) { |
60f8b39c | 1606 | rates |= BIT(j); |
d61272cb TW |
1607 | if (is_basic) |
1608 | basic_rates |= BIT(j); | |
1609 | break; | |
1610 | } | |
60f8b39c | 1611 | } |
1ebebea8 | 1612 | } |
f0706e82 | 1613 | |
323ce79a | 1614 | sta->sta.supp_rates[local->hw.conf.channel->band] = rates; |
bda3933a | 1615 | sdata->vif.bss_conf.basic_rates = basic_rates; |
60f8b39c JB |
1616 | |
1617 | /* cf. IEEE 802.11 9.2.12 */ | |
1618 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
1619 | have_higher_than_11mbit) | |
1620 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
1621 | else | |
1622 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
f0706e82 | 1623 | |
ab1faead | 1624 | if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
ae5eb026 | 1625 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
d9fe60de | 1626 | elems.ht_cap_elem, &sta->sta.ht_cap); |
ae5eb026 JB |
1627 | |
1628 | ap_ht_cap_flags = sta->sta.ht_cap.cap; | |
f0706e82 | 1629 | |
4b7679a5 | 1630 | rate_control_rate_init(sta); |
f0706e82 | 1631 | |
46900298 | 1632 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) |
5394af4d JM |
1633 | set_sta_flags(sta, WLAN_STA_MFP); |
1634 | ||
ddf4ac53 | 1635 | if (elems.wmm_param) |
60f8b39c | 1636 | set_sta_flags(sta, WLAN_STA_WME); |
ddf4ac53 | 1637 | |
5d1ec85f JB |
1638 | err = sta_info_insert(sta); |
1639 | sta = NULL; | |
1640 | if (err) { | |
1641 | printk(KERN_DEBUG "%s: failed to insert STA entry for" | |
1642 | " the AP (error %d)\n", sdata->name, err); | |
1643 | return RX_MGMT_CFG80211_ASSOC_ERROR; | |
ddf4ac53 JB |
1644 | } |
1645 | ||
ddf4ac53 | 1646 | if (elems.wmm_param) |
46900298 | 1647 | ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, |
60f8b39c | 1648 | elems.wmm_param_len); |
aa837e1d JB |
1649 | else |
1650 | ieee80211_set_wmm_default(sdata); | |
f0706e82 | 1651 | |
ae5eb026 | 1652 | if (elems.ht_info_elem && elems.wmm_param && |
46900298 | 1653 | (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && |
ab1faead | 1654 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
ae5eb026 | 1655 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, |
63f170e0 | 1656 | bss->cbss.bssid, |
ae5eb026 JB |
1657 | ap_ht_cap_flags); |
1658 | ||
60f8b39c JB |
1659 | /* set AID and assoc capability, |
1660 | * ieee80211_set_associated() will tell the driver */ | |
1661 | bss_conf->aid = aid; | |
1662 | bss_conf->assoc_capability = capab_info; | |
63f170e0 | 1663 | ieee80211_set_associated(sdata, bss, changed); |
f0706e82 | 1664 | |
15b7b062 | 1665 | /* |
b291ba11 JB |
1666 | * Start timer to probe the connection to the AP now. |
1667 | * Also start the timer that will detect beacon loss. | |
15b7b062 | 1668 | */ |
b291ba11 JB |
1669 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
1670 | mod_beacon_timer(sdata); | |
15b7b062 | 1671 | |
77fdaa12 | 1672 | return RX_MGMT_CFG80211_ASSOC; |
f0706e82 JB |
1673 | } |
1674 | ||
1675 | ||
98c8fccf JB |
1676 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
1677 | struct ieee80211_mgmt *mgmt, | |
1678 | size_t len, | |
1679 | struct ieee80211_rx_status *rx_status, | |
1680 | struct ieee802_11_elems *elems, | |
1681 | bool beacon) | |
1682 | { | |
1683 | struct ieee80211_local *local = sdata->local; | |
1684 | int freq; | |
c2b13452 | 1685 | struct ieee80211_bss *bss; |
98c8fccf | 1686 | struct ieee80211_channel *channel; |
98c8fccf JB |
1687 | |
1688 | if (elems->ds_params && elems->ds_params_len == 1) | |
1689 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); | |
1690 | else | |
1691 | freq = rx_status->freq; | |
1692 | ||
1693 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
1694 | ||
1695 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
1696 | return; | |
1697 | ||
98c8fccf | 1698 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
2a519311 | 1699 | channel, beacon); |
77fdaa12 JB |
1700 | if (bss) |
1701 | ieee80211_rx_bss_put(local, bss); | |
1702 | ||
1703 | if (!sdata->u.mgd.associated) | |
98c8fccf JB |
1704 | return; |
1705 | ||
c481ec97 | 1706 | if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && |
77fdaa12 JB |
1707 | (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid, |
1708 | ETH_ALEN) == 0)) { | |
c481ec97 S |
1709 | struct ieee80211_channel_sw_ie *sw_elem = |
1710 | (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; | |
cc32abd4 | 1711 | ieee80211_sta_process_chanswitch(sdata, sw_elem, bss); |
c481ec97 | 1712 | } |
f0706e82 JB |
1713 | } |
1714 | ||
1715 | ||
f698d856 | 1716 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
f679f65d | 1717 | struct ieee80211_work *wk, |
77fdaa12 | 1718 | struct ieee80211_mgmt *mgmt, size_t len, |
f0706e82 JB |
1719 | struct ieee80211_rx_status *rx_status) |
1720 | { | |
15b7b062 | 1721 | struct ieee80211_if_managed *ifmgd; |
ae6a44e3 EK |
1722 | size_t baselen; |
1723 | struct ieee802_11_elems elems; | |
1724 | ||
15b7b062 KV |
1725 | ifmgd = &sdata->u.mgd; |
1726 | ||
77fdaa12 JB |
1727 | ASSERT_MGD_MTX(ifmgd); |
1728 | ||
47846c9b | 1729 | if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN)) |
8e7cdbb6 TW |
1730 | return; /* ignore ProbeResp to foreign address */ |
1731 | ||
ae6a44e3 EK |
1732 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
1733 | if (baselen > len) | |
1734 | return; | |
1735 | ||
1736 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
1737 | &elems); | |
1738 | ||
98c8fccf | 1739 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
9859b81e RR |
1740 | |
1741 | /* direct probe may be part of the association flow */ | |
f679f65d | 1742 | if (wk && wk->type == IEEE80211_WORK_AUTH_PROBE) { |
0ff71613 | 1743 | printk(KERN_DEBUG "%s: direct probe responded\n", |
47846c9b | 1744 | sdata->name); |
f679f65d JB |
1745 | wk->auth.tries = 0; |
1746 | wk->type = IEEE80211_WORK_AUTH; | |
77fdaa12 | 1747 | WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE); |
9859b81e | 1748 | } |
15b7b062 | 1749 | |
77fdaa12 JB |
1750 | if (ifmgd->associated && |
1751 | memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 && | |
b291ba11 JB |
1752 | ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
1753 | IEEE80211_STA_CONNECTION_POLL)) { | |
1754 | ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | | |
1755 | IEEE80211_STA_BEACON_POLL); | |
4e751843 JB |
1756 | mutex_lock(&sdata->local->iflist_mtx); |
1757 | ieee80211_recalc_ps(sdata->local, -1); | |
1758 | mutex_unlock(&sdata->local->iflist_mtx); | |
b291ba11 JB |
1759 | /* |
1760 | * We've received a probe response, but are not sure whether | |
1761 | * we have or will be receiving any beacons or data, so let's | |
1762 | * schedule the timers again, just in case. | |
1763 | */ | |
1764 | mod_beacon_timer(sdata); | |
1765 | mod_timer(&ifmgd->conn_mon_timer, | |
1766 | round_jiffies_up(jiffies + | |
1767 | IEEE80211_CONNECTION_IDLE_TIME)); | |
4e751843 | 1768 | } |
f0706e82 JB |
1769 | } |
1770 | ||
d91f36db JB |
1771 | /* |
1772 | * This is the canonical list of information elements we care about, | |
1773 | * the filter code also gives us all changes to the Microsoft OUI | |
1774 | * (00:50:F2) vendor IE which is used for WMM which we need to track. | |
1775 | * | |
1776 | * We implement beacon filtering in software since that means we can | |
1777 | * avoid processing the frame here and in cfg80211, and userspace | |
1778 | * will not be able to tell whether the hardware supports it or not. | |
1779 | * | |
1780 | * XXX: This list needs to be dynamic -- userspace needs to be able to | |
1781 | * add items it requires. It also needs to be able to tell us to | |
1782 | * look out for other vendor IEs. | |
1783 | */ | |
1784 | static const u64 care_about_ies = | |
1d4df3a5 JB |
1785 | (1ULL << WLAN_EID_COUNTRY) | |
1786 | (1ULL << WLAN_EID_ERP_INFO) | | |
1787 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | | |
1788 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | | |
1789 | (1ULL << WLAN_EID_HT_CAPABILITY) | | |
1790 | (1ULL << WLAN_EID_HT_INFORMATION); | |
d91f36db | 1791 | |
f698d856 | 1792 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1793 | struct ieee80211_mgmt *mgmt, |
1794 | size_t len, | |
1795 | struct ieee80211_rx_status *rx_status) | |
1796 | { | |
d91f36db | 1797 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 JB |
1798 | size_t baselen; |
1799 | struct ieee802_11_elems elems; | |
f698d856 | 1800 | struct ieee80211_local *local = sdata->local; |
471b3efd | 1801 | u32 changed = 0; |
d91f36db | 1802 | bool erp_valid, directed_tim = false; |
7a5158ef | 1803 | u8 erp_value = 0; |
d91f36db | 1804 | u32 ncrc; |
77fdaa12 JB |
1805 | u8 *bssid; |
1806 | ||
1807 | ASSERT_MGD_MTX(ifmgd); | |
f0706e82 | 1808 | |
ae6a44e3 EK |
1809 | /* Process beacon from the current BSS */ |
1810 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | |
1811 | if (baselen > len) | |
1812 | return; | |
1813 | ||
d91f36db | 1814 | if (rx_status->freq != local->hw.conf.channel->center_freq) |
f0706e82 | 1815 | return; |
f0706e82 | 1816 | |
b291ba11 JB |
1817 | /* |
1818 | * We might have received a number of frames, among them a | |
1819 | * disassoc frame and a beacon... | |
1820 | */ | |
1821 | if (!ifmgd->associated) | |
77fdaa12 JB |
1822 | return; |
1823 | ||
1824 | bssid = ifmgd->associated->cbss.bssid; | |
1825 | ||
b291ba11 JB |
1826 | /* |
1827 | * And in theory even frames from a different AP we were just | |
1828 | * associated to a split-second ago! | |
1829 | */ | |
1830 | if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0) | |
f0706e82 JB |
1831 | return; |
1832 | ||
b291ba11 | 1833 | if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) { |
92778180 JM |
1834 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
1835 | if (net_ratelimit()) { | |
1836 | printk(KERN_DEBUG "%s: cancelling probereq poll due " | |
47846c9b | 1837 | "to a received beacon\n", sdata->name); |
92778180 JM |
1838 | } |
1839 | #endif | |
b291ba11 | 1840 | ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; |
4e751843 JB |
1841 | mutex_lock(&local->iflist_mtx); |
1842 | ieee80211_recalc_ps(local, -1); | |
1843 | mutex_unlock(&local->iflist_mtx); | |
92778180 JM |
1844 | } |
1845 | ||
b291ba11 JB |
1846 | /* |
1847 | * Push the beacon loss detection into the future since | |
1848 | * we are processing a beacon from the AP just now. | |
1849 | */ | |
1850 | mod_beacon_timer(sdata); | |
1851 | ||
d91f36db JB |
1852 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
1853 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, | |
1854 | len - baselen, &elems, | |
1855 | care_about_ies, ncrc); | |
1856 | ||
1857 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) | |
e7ec86f5 JB |
1858 | directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len, |
1859 | ifmgd->aid); | |
d91f36db | 1860 | |
30196673 JM |
1861 | if (ncrc != ifmgd->beacon_crc) { |
1862 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, | |
1863 | true); | |
d91f36db | 1864 | |
30196673 JM |
1865 | ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, |
1866 | elems.wmm_param_len); | |
1867 | } | |
fe3fa827 | 1868 | |
25c9c875 | 1869 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { |
1fb3606b | 1870 | if (directed_tim) { |
572e0012 KV |
1871 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
1872 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
1873 | ieee80211_hw_config(local, | |
1874 | IEEE80211_CONF_CHANGE_PS); | |
1875 | ieee80211_send_nullfunc(local, sdata, 0); | |
1876 | } else { | |
1877 | local->pspolling = true; | |
1878 | ||
1879 | /* | |
1880 | * Here is assumed that the driver will be | |
1881 | * able to send ps-poll frame and receive a | |
1882 | * response even though power save mode is | |
1883 | * enabled, but some drivers might require | |
1884 | * to disable power save here. This needs | |
1885 | * to be investigated. | |
1886 | */ | |
1887 | ieee80211_send_pspoll(local, sdata); | |
1888 | } | |
a97b77b9 VN |
1889 | } |
1890 | } | |
7a5158ef | 1891 | |
30196673 JM |
1892 | if (ncrc == ifmgd->beacon_crc) |
1893 | return; | |
1894 | ifmgd->beacon_crc = ncrc; | |
1895 | ||
7a5158ef JB |
1896 | if (elems.erp_info && elems.erp_info_len >= 1) { |
1897 | erp_valid = true; | |
1898 | erp_value = elems.erp_info[0]; | |
1899 | } else { | |
1900 | erp_valid = false; | |
50c4afb9 | 1901 | } |
7a5158ef JB |
1902 | changed |= ieee80211_handle_bss_capability(sdata, |
1903 | le16_to_cpu(mgmt->u.beacon.capab_info), | |
1904 | erp_valid, erp_value); | |
f0706e82 | 1905 | |
d3c990fb | 1906 | |
53d6f81c | 1907 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
ab1faead | 1908 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) { |
ae5eb026 JB |
1909 | struct sta_info *sta; |
1910 | struct ieee80211_supported_band *sband; | |
1911 | u16 ap_ht_cap_flags; | |
1912 | ||
1913 | rcu_read_lock(); | |
1914 | ||
abe60632 | 1915 | sta = sta_info_get(sdata, bssid); |
77fdaa12 | 1916 | if (WARN_ON(!sta)) { |
ae5eb026 JB |
1917 | rcu_read_unlock(); |
1918 | return; | |
1919 | } | |
1920 | ||
1921 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
1922 | ||
1923 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, | |
1924 | elems.ht_cap_elem, &sta->sta.ht_cap); | |
1925 | ||
1926 | ap_ht_cap_flags = sta->sta.ht_cap.cap; | |
1927 | ||
1928 | rcu_read_unlock(); | |
1929 | ||
1930 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, | |
77fdaa12 | 1931 | bssid, ap_ht_cap_flags); |
d3c990fb RR |
1932 | } |
1933 | ||
8b19e6ca | 1934 | /* Note: country IE parsing is done for us by cfg80211 */ |
3f2355cb | 1935 | if (elems.country_elem) { |
a8302de9 VT |
1936 | /* TODO: IBSS also needs this */ |
1937 | if (elems.pwr_constr_elem) | |
1938 | ieee80211_handle_pwr_constr(sdata, | |
1939 | le16_to_cpu(mgmt->u.probe_resp.capab_info), | |
1940 | elems.pwr_constr_elem, | |
1941 | elems.pwr_constr_elem_len); | |
3f2355cb LR |
1942 | } |
1943 | ||
471b3efd | 1944 | ieee80211_bss_info_change_notify(sdata, changed); |
f0706e82 JB |
1945 | } |
1946 | ||
46900298 | 1947 | ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, |
f1d58c25 | 1948 | struct sk_buff *skb) |
f0706e82 | 1949 | { |
f698d856 | 1950 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1951 | struct ieee80211_mgmt *mgmt; |
1952 | u16 fc; | |
1953 | ||
1954 | if (skb->len < 24) | |
46900298 | 1955 | return RX_DROP_MONITOR; |
f0706e82 JB |
1956 | |
1957 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
1958 | fc = le16_to_cpu(mgmt->frame_control); | |
1959 | ||
1960 | switch (fc & IEEE80211_FCTL_STYPE) { | |
f0706e82 JB |
1961 | case IEEE80211_STYPE_PROBE_RESP: |
1962 | case IEEE80211_STYPE_BEACON: | |
f0706e82 JB |
1963 | case IEEE80211_STYPE_AUTH: |
1964 | case IEEE80211_STYPE_ASSOC_RESP: | |
1965 | case IEEE80211_STYPE_REASSOC_RESP: | |
1966 | case IEEE80211_STYPE_DEAUTH: | |
1967 | case IEEE80211_STYPE_DISASSOC: | |
77fdaa12 | 1968 | case IEEE80211_STYPE_ACTION: |
46900298 | 1969 | skb_queue_tail(&sdata->u.mgd.skb_queue, skb); |
42935eca | 1970 | ieee80211_queue_work(&local->hw, &sdata->u.mgd.work); |
46900298 | 1971 | return RX_QUEUED; |
f0706e82 JB |
1972 | } |
1973 | ||
46900298 | 1974 | return RX_DROP_MONITOR; |
f0706e82 JB |
1975 | } |
1976 | ||
f698d856 | 1977 | static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1978 | struct sk_buff *skb) |
1979 | { | |
77fdaa12 | 1980 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 | 1981 | struct ieee80211_rx_status *rx_status; |
f0706e82 | 1982 | struct ieee80211_mgmt *mgmt; |
f679f65d | 1983 | struct ieee80211_work *wk; |
77fdaa12 | 1984 | enum rx_mgmt_action rma = RX_MGMT_NONE; |
f0706e82 JB |
1985 | u16 fc; |
1986 | ||
f0706e82 JB |
1987 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
1988 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
1989 | fc = le16_to_cpu(mgmt->frame_control); | |
1990 | ||
77fdaa12 JB |
1991 | mutex_lock(&ifmgd->mtx); |
1992 | ||
1993 | if (ifmgd->associated && | |
1994 | memcmp(ifmgd->associated->cbss.bssid, mgmt->bssid, | |
1995 | ETH_ALEN) == 0) { | |
1996 | switch (fc & IEEE80211_FCTL_STYPE) { | |
1997 | case IEEE80211_STYPE_BEACON: | |
1998 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, | |
1999 | rx_status); | |
2000 | break; | |
2001 | case IEEE80211_STYPE_PROBE_RESP: | |
2002 | ieee80211_rx_mgmt_probe_resp(sdata, NULL, mgmt, | |
2003 | skb->len, rx_status); | |
2004 | break; | |
2005 | case IEEE80211_STYPE_DEAUTH: | |
63f170e0 | 2006 | rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
77fdaa12 JB |
2007 | break; |
2008 | case IEEE80211_STYPE_DISASSOC: | |
2009 | rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); | |
2010 | break; | |
2011 | case IEEE80211_STYPE_ACTION: | |
2012 | /* XXX: differentiate, can only happen for CSA now! */ | |
2013 | ieee80211_sta_process_chanswitch(sdata, | |
2014 | &mgmt->u.action.u.chan_switch.sw_elem, | |
2015 | ifmgd->associated); | |
2016 | break; | |
2017 | } | |
2018 | mutex_unlock(&ifmgd->mtx); | |
2019 | ||
2020 | switch (rma) { | |
2021 | case RX_MGMT_NONE: | |
2022 | /* no action */ | |
2023 | break; | |
2024 | case RX_MGMT_CFG80211_DEAUTH: | |
ce470613 | 2025 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
77fdaa12 JB |
2026 | break; |
2027 | case RX_MGMT_CFG80211_DISASSOC: | |
ce470613 | 2028 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); |
77fdaa12 JB |
2029 | break; |
2030 | default: | |
2031 | WARN(1, "unexpected: %d", rma); | |
2032 | } | |
2033 | goto out; | |
2034 | } | |
2035 | ||
2036 | list_for_each_entry(wk, &ifmgd->work_list, list) { | |
f679f65d JB |
2037 | const u8 *bssid = NULL; |
2038 | ||
2039 | switch (wk->type) { | |
2040 | case IEEE80211_WORK_AUTH_PROBE: | |
2041 | case IEEE80211_WORK_AUTH: | |
2042 | bssid = wk->auth.bssid; | |
2043 | break; | |
2044 | case IEEE80211_WORK_ASSOC: | |
2045 | bssid = wk->assoc.bssid; | |
2046 | break; | |
2047 | default: | |
2048 | continue; | |
2049 | } | |
2050 | if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0) | |
77fdaa12 JB |
2051 | continue; |
2052 | ||
2053 | switch (fc & IEEE80211_FCTL_STYPE) { | |
2054 | case IEEE80211_STYPE_PROBE_RESP: | |
2055 | ieee80211_rx_mgmt_probe_resp(sdata, wk, mgmt, skb->len, | |
2056 | rx_status); | |
2057 | break; | |
2058 | case IEEE80211_STYPE_AUTH: | |
2059 | rma = ieee80211_rx_mgmt_auth(sdata, wk, mgmt, skb->len); | |
2060 | break; | |
2061 | case IEEE80211_STYPE_ASSOC_RESP: | |
2062 | rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt, | |
2063 | skb->len, false); | |
2064 | break; | |
2065 | case IEEE80211_STYPE_REASSOC_RESP: | |
2066 | rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt, | |
2067 | skb->len, true); | |
2068 | break; | |
2069 | case IEEE80211_STYPE_DEAUTH: | |
63f170e0 JB |
2070 | if (skb->len >= 24 + 2 /* mgmt + deauth reason */) { |
2071 | /* | |
2072 | * We get here if we get deauth while | |
2073 | * trying to auth/assoc. Telling cfg80211 | |
2074 | * is handled below, unconditionally. | |
2075 | */ | |
2076 | list_del(&wk->list); | |
2077 | kfree(wk); | |
2078 | } | |
77fdaa12 JB |
2079 | break; |
2080 | } | |
2081 | /* | |
2082 | * We've processed this frame for that work, so it can't | |
2083 | * belong to another work struct. | |
2084 | * NB: this is also required for correctness because the | |
2085 | * called functions can free 'wk', and for 'rma'! | |
2086 | */ | |
46900298 | 2087 | break; |
77fdaa12 JB |
2088 | } |
2089 | ||
2090 | mutex_unlock(&ifmgd->mtx); | |
2091 | ||
63f170e0 JB |
2092 | if (skb->len >= 24 + 2 /* mgmt + deauth reason */ && |
2093 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) { | |
2094 | WARN_ON(rma != RX_MGMT_NONE); | |
2095 | rma = RX_MGMT_CFG80211_DEAUTH; | |
2096 | } | |
2097 | ||
77fdaa12 JB |
2098 | switch (rma) { |
2099 | case RX_MGMT_NONE: | |
2100 | /* no action */ | |
46900298 | 2101 | break; |
77fdaa12 | 2102 | case RX_MGMT_CFG80211_AUTH: |
cb0b4beb | 2103 | cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, skb->len); |
46900298 | 2104 | break; |
77fdaa12 | 2105 | case RX_MGMT_CFG80211_ASSOC: |
cb0b4beb | 2106 | cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, skb->len); |
46900298 | 2107 | break; |
8d8b261a | 2108 | case RX_MGMT_CFG80211_DEAUTH: |
ce470613 | 2109 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
8d8b261a | 2110 | break; |
5d1ec85f JB |
2111 | case RX_MGMT_CFG80211_ASSOC_ERROR: |
2112 | /* an internal error -- pretend timeout for now */ | |
2113 | cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid); | |
2114 | break; | |
77fdaa12 JB |
2115 | default: |
2116 | WARN(1, "unexpected: %d", rma); | |
f0706e82 JB |
2117 | } |
2118 | ||
77fdaa12 | 2119 | out: |
f0706e82 JB |
2120 | kfree_skb(skb); |
2121 | } | |
2122 | ||
9c6bd790 | 2123 | static void ieee80211_sta_timer(unsigned long data) |
f0706e82 | 2124 | { |
60f8b39c JB |
2125 | struct ieee80211_sub_if_data *sdata = |
2126 | (struct ieee80211_sub_if_data *) data; | |
46900298 | 2127 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
60f8b39c | 2128 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 2129 | |
5bb644a0 JB |
2130 | if (local->quiescing) { |
2131 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); | |
2132 | return; | |
2133 | } | |
2134 | ||
42935eca | 2135 | ieee80211_queue_work(&local->hw, &ifmgd->work); |
f0706e82 JB |
2136 | } |
2137 | ||
9c6bd790 JB |
2138 | static void ieee80211_sta_work(struct work_struct *work) |
2139 | { | |
2140 | struct ieee80211_sub_if_data *sdata = | |
46900298 | 2141 | container_of(work, struct ieee80211_sub_if_data, u.mgd.work); |
9c6bd790 | 2142 | struct ieee80211_local *local = sdata->local; |
46900298 | 2143 | struct ieee80211_if_managed *ifmgd; |
9c6bd790 | 2144 | struct sk_buff *skb; |
f679f65d | 2145 | struct ieee80211_work *wk, *tmp; |
77fdaa12 JB |
2146 | LIST_HEAD(free_work); |
2147 | enum rx_mgmt_action rma; | |
9c6bd790 | 2148 | |
9607e6b6 | 2149 | if (!ieee80211_sdata_running(sdata)) |
9c6bd790 JB |
2150 | return; |
2151 | ||
fbe9c429 | 2152 | if (local->scanning) |
9c6bd790 JB |
2153 | return; |
2154 | ||
46900298 | 2155 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
9c6bd790 | 2156 | return; |
5bb644a0 JB |
2157 | |
2158 | /* | |
42935eca LR |
2159 | * ieee80211_queue_work() should have picked up most cases, |
2160 | * here we'll pick the the rest. | |
5bb644a0 | 2161 | */ |
42935eca LR |
2162 | if (WARN(local->suspended, "STA MLME work scheduled while " |
2163 | "going to suspend\n")) | |
5bb644a0 JB |
2164 | return; |
2165 | ||
46900298 | 2166 | ifmgd = &sdata->u.mgd; |
f0706e82 | 2167 | |
77fdaa12 | 2168 | /* first process frames to avoid timing out while a frame is pending */ |
46900298 | 2169 | while ((skb = skb_dequeue(&ifmgd->skb_queue))) |
9c6bd790 JB |
2170 | ieee80211_sta_rx_queued_mgmt(sdata, skb); |
2171 | ||
77fdaa12 JB |
2172 | /* then process the rest of the work */ |
2173 | mutex_lock(&ifmgd->mtx); | |
2174 | ||
b291ba11 JB |
2175 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
2176 | IEEE80211_STA_CONNECTION_POLL) && | |
2177 | ifmgd->associated) { | |
a43abf29 ML |
2178 | u8 bssid[ETH_ALEN]; |
2179 | ||
2180 | memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); | |
b291ba11 JB |
2181 | if (time_is_after_jiffies(ifmgd->probe_timeout)) |
2182 | run_again(ifmgd, ifmgd->probe_timeout); | |
a43abf29 ML |
2183 | |
2184 | else if (ifmgd->probe_send_count < IEEE80211_MAX_PROBE_TRIES) { | |
2185 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
2186 | printk(KERN_DEBUG "No probe response from AP %pM" | |
2187 | " after %dms, try %d\n", bssid, | |
2188 | (1000 * IEEE80211_PROBE_WAIT)/HZ, | |
2189 | ifmgd->probe_send_count); | |
2190 | #endif | |
2191 | ieee80211_mgd_probe_ap_send(sdata); | |
2192 | } else { | |
b291ba11 JB |
2193 | /* |
2194 | * We actually lost the connection ... or did we? | |
2195 | * Let's make sure! | |
2196 | */ | |
2197 | ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | | |
2198 | IEEE80211_STA_BEACON_POLL); | |
b291ba11 JB |
2199 | printk(KERN_DEBUG "No probe response from AP %pM" |
2200 | " after %dms, disconnecting.\n", | |
2201 | bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); | |
63f170e0 | 2202 | ieee80211_set_disassoc(sdata); |
bc83b681 | 2203 | ieee80211_recalc_idle(local); |
b291ba11 JB |
2204 | mutex_unlock(&ifmgd->mtx); |
2205 | /* | |
2206 | * must be outside lock due to cfg80211, | |
2207 | * but that's not a problem. | |
2208 | */ | |
2209 | ieee80211_send_deauth_disassoc(sdata, bssid, | |
2210 | IEEE80211_STYPE_DEAUTH, | |
2211 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, | |
2212 | NULL); | |
2213 | mutex_lock(&ifmgd->mtx); | |
2214 | } | |
2215 | } | |
2216 | ||
f0706e82 | 2217 | |
77fdaa12 JB |
2218 | ieee80211_recalc_idle(local); |
2219 | ||
77fdaa12 | 2220 | list_for_each_entry_safe(wk, tmp, &ifmgd->work_list, list) { |
ca386f31 JB |
2221 | if (time_is_after_jiffies(wk->timeout)) { |
2222 | /* | |
2223 | * This work item isn't supposed to be worked on | |
2224 | * right now, but take care to adjust the timer | |
2225 | * properly. | |
2226 | */ | |
2227 | run_again(ifmgd, wk->timeout); | |
77fdaa12 | 2228 | continue; |
ca386f31 | 2229 | } |
5cff20e6 | 2230 | |
f679f65d | 2231 | switch (wk->type) { |
77fdaa12 JB |
2232 | default: |
2233 | WARN_ON(1); | |
77fdaa12 JB |
2234 | /* nothing */ |
2235 | rma = RX_MGMT_NONE; | |
2236 | break; | |
f679f65d | 2237 | case IEEE80211_WORK_AUTH_PROBE: |
77fdaa12 JB |
2238 | rma = ieee80211_direct_probe(sdata, wk); |
2239 | break; | |
f679f65d | 2240 | case IEEE80211_WORK_AUTH: |
77fdaa12 JB |
2241 | rma = ieee80211_authenticate(sdata, wk); |
2242 | break; | |
f679f65d | 2243 | case IEEE80211_WORK_ASSOC: |
77fdaa12 JB |
2244 | rma = ieee80211_associate(sdata, wk); |
2245 | break; | |
2246 | } | |
2247 | ||
2248 | switch (rma) { | |
2249 | case RX_MGMT_NONE: | |
2250 | /* no action required */ | |
2251 | break; | |
2252 | case RX_MGMT_CFG80211_AUTH_TO: | |
2253 | case RX_MGMT_CFG80211_ASSOC_TO: | |
2254 | list_del(&wk->list); | |
2255 | list_add(&wk->list, &free_work); | |
63f170e0 JB |
2256 | /* |
2257 | * small abuse but only local -- keep the | |
2258 | * action type in wk->timeout while the item | |
2259 | * is on the cleanup list | |
2260 | */ | |
2261 | wk->timeout = rma; | |
77fdaa12 JB |
2262 | break; |
2263 | default: | |
2264 | WARN(1, "unexpected: %d", rma); | |
2265 | } | |
2266 | } | |
2267 | ||
63f170e0 | 2268 | if (list_empty(&ifmgd->work_list) && |
5bf6fcc2 JM |
2269 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) |
2270 | ieee80211_queue_delayed_work(&local->hw, | |
2271 | &local->scan_work, | |
2272 | round_jiffies_relative(0)); | |
2273 | ||
77fdaa12 JB |
2274 | mutex_unlock(&ifmgd->mtx); |
2275 | ||
2276 | list_for_each_entry_safe(wk, tmp, &free_work, list) { | |
63f170e0 JB |
2277 | /* see above how we're using wk->timeout */ |
2278 | switch (wk->timeout) { | |
77fdaa12 | 2279 | case RX_MGMT_CFG80211_AUTH_TO: |
f679f65d | 2280 | cfg80211_send_auth_timeout(sdata->dev, wk->auth.bssid); |
77fdaa12 JB |
2281 | break; |
2282 | case RX_MGMT_CFG80211_ASSOC_TO: | |
cb0b4beb | 2283 | cfg80211_send_assoc_timeout(sdata->dev, |
f679f65d | 2284 | wk->assoc.bssid); |
77fdaa12 JB |
2285 | break; |
2286 | default: | |
63f170e0 | 2287 | WARN(1, "unexpected: %lu", wk->timeout); |
77fdaa12 JB |
2288 | } |
2289 | ||
2290 | list_del(&wk->list); | |
2291 | kfree(wk); | |
9c6bd790 | 2292 | } |
77fdaa12 JB |
2293 | |
2294 | ieee80211_recalc_idle(local); | |
f0706e82 JB |
2295 | } |
2296 | ||
b291ba11 JB |
2297 | static void ieee80211_sta_bcn_mon_timer(unsigned long data) |
2298 | { | |
2299 | struct ieee80211_sub_if_data *sdata = | |
2300 | (struct ieee80211_sub_if_data *) data; | |
2301 | struct ieee80211_local *local = sdata->local; | |
2302 | ||
2303 | if (local->quiescing) | |
2304 | return; | |
2305 | ||
42935eca | 2306 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.beacon_loss_work); |
b291ba11 JB |
2307 | } |
2308 | ||
2309 | static void ieee80211_sta_conn_mon_timer(unsigned long data) | |
2310 | { | |
2311 | struct ieee80211_sub_if_data *sdata = | |
2312 | (struct ieee80211_sub_if_data *) data; | |
2313 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2314 | struct ieee80211_local *local = sdata->local; | |
2315 | ||
2316 | if (local->quiescing) | |
2317 | return; | |
2318 | ||
42935eca | 2319 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
b291ba11 JB |
2320 | } |
2321 | ||
2322 | static void ieee80211_sta_monitor_work(struct work_struct *work) | |
2323 | { | |
2324 | struct ieee80211_sub_if_data *sdata = | |
2325 | container_of(work, struct ieee80211_sub_if_data, | |
2326 | u.mgd.monitor_work); | |
2327 | ||
2328 | ieee80211_mgd_probe_ap(sdata, false); | |
2329 | } | |
2330 | ||
9c6bd790 JB |
2331 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
2332 | { | |
ad935687 | 2333 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
b291ba11 JB |
2334 | sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL | |
2335 | IEEE80211_STA_CONNECTION_POLL); | |
ad935687 | 2336 | |
b291ba11 | 2337 | /* let's probe the connection once */ |
42935eca | 2338 | ieee80211_queue_work(&sdata->local->hw, |
b291ba11 JB |
2339 | &sdata->u.mgd.monitor_work); |
2340 | /* and do all the other regular work too */ | |
42935eca | 2341 | ieee80211_queue_work(&sdata->local->hw, |
46900298 | 2342 | &sdata->u.mgd.work); |
ad935687 | 2343 | } |
9c6bd790 | 2344 | } |
f0706e82 | 2345 | |
5bb644a0 JB |
2346 | #ifdef CONFIG_PM |
2347 | void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata) | |
2348 | { | |
2349 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2350 | ||
2351 | /* | |
2352 | * we need to use atomic bitops for the running bits | |
2353 | * only because both timers might fire at the same | |
2354 | * time -- the code here is properly synchronised. | |
2355 | */ | |
2356 | ||
2357 | cancel_work_sync(&ifmgd->work); | |
2358 | cancel_work_sync(&ifmgd->beacon_loss_work); | |
2359 | if (del_timer_sync(&ifmgd->timer)) | |
2360 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); | |
2361 | ||
2362 | cancel_work_sync(&ifmgd->chswitch_work); | |
2363 | if (del_timer_sync(&ifmgd->chswitch_timer)) | |
2364 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); | |
b291ba11 JB |
2365 | |
2366 | cancel_work_sync(&ifmgd->monitor_work); | |
2367 | /* these will just be re-established on connection */ | |
2368 | del_timer_sync(&ifmgd->conn_mon_timer); | |
2369 | del_timer_sync(&ifmgd->bcn_mon_timer); | |
5bb644a0 JB |
2370 | } |
2371 | ||
2372 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) | |
2373 | { | |
2374 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2375 | ||
2376 | if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running)) | |
2377 | add_timer(&ifmgd->timer); | |
2378 | if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running)) | |
2379 | add_timer(&ifmgd->chswitch_timer); | |
2380 | } | |
2381 | #endif | |
2382 | ||
9c6bd790 JB |
2383 | /* interface setup */ |
2384 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) | |
f0706e82 | 2385 | { |
46900298 | 2386 | struct ieee80211_if_managed *ifmgd; |
988c0f72 | 2387 | |
46900298 JB |
2388 | ifmgd = &sdata->u.mgd; |
2389 | INIT_WORK(&ifmgd->work, ieee80211_sta_work); | |
b291ba11 | 2390 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
46900298 | 2391 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
04de8381 | 2392 | INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work); |
46900298 | 2393 | setup_timer(&ifmgd->timer, ieee80211_sta_timer, |
c481ec97 | 2394 | (unsigned long) sdata); |
b291ba11 JB |
2395 | setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, |
2396 | (unsigned long) sdata); | |
2397 | setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, | |
2398 | (unsigned long) sdata); | |
46900298 | 2399 | setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, |
9c6bd790 | 2400 | (unsigned long) sdata); |
46900298 | 2401 | skb_queue_head_init(&ifmgd->skb_queue); |
9c6bd790 | 2402 | |
77fdaa12 JB |
2403 | INIT_LIST_HEAD(&ifmgd->work_list); |
2404 | ||
46900298 | 2405 | ifmgd->capab = WLAN_CAPABILITY_ESS; |
ab1faead | 2406 | ifmgd->flags = 0; |
176be728 | 2407 | if (sdata->local->hw.queues >= 4) |
46900298 | 2408 | ifmgd->flags |= IEEE80211_STA_WMM_ENABLED; |
bbbdff9e | 2409 | |
77fdaa12 | 2410 | mutex_init(&ifmgd->mtx); |
0f78231b JB |
2411 | |
2412 | if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) | |
2413 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; | |
2414 | else | |
2415 | ifmgd->req_smps = IEEE80211_SMPS_OFF; | |
f0706e82 JB |
2416 | } |
2417 | ||
77fdaa12 JB |
2418 | /* scan finished notification */ |
2419 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) | |
60f8b39c | 2420 | { |
77fdaa12 | 2421 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
60f8b39c | 2422 | |
77fdaa12 JB |
2423 | /* Restart STA timers */ |
2424 | rcu_read_lock(); | |
2425 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
2426 | ieee80211_restart_sta_timer(sdata); | |
2427 | rcu_read_unlock(); | |
2428 | } | |
60f8b39c | 2429 | |
77fdaa12 JB |
2430 | int ieee80211_max_network_latency(struct notifier_block *nb, |
2431 | unsigned long data, void *dummy) | |
2432 | { | |
2433 | s32 latency_usec = (s32) data; | |
2434 | struct ieee80211_local *local = | |
2435 | container_of(nb, struct ieee80211_local, | |
2436 | network_latency_notifier); | |
1fa6f4af | 2437 | |
77fdaa12 JB |
2438 | mutex_lock(&local->iflist_mtx); |
2439 | ieee80211_recalc_ps(local, latency_usec); | |
2440 | mutex_unlock(&local->iflist_mtx); | |
dfe67012 | 2441 | |
77fdaa12 | 2442 | return 0; |
9c6bd790 JB |
2443 | } |
2444 | ||
77fdaa12 JB |
2445 | /* config hooks */ |
2446 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, | |
2447 | struct cfg80211_auth_request *req) | |
9c6bd790 | 2448 | { |
46900298 | 2449 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
77fdaa12 | 2450 | const u8 *ssid; |
f679f65d | 2451 | struct ieee80211_work *wk; |
77fdaa12 | 2452 | u16 auth_alg; |
9c6bd790 | 2453 | |
77fdaa12 JB |
2454 | switch (req->auth_type) { |
2455 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
2456 | auth_alg = WLAN_AUTH_OPEN; | |
2457 | break; | |
2458 | case NL80211_AUTHTYPE_SHARED_KEY: | |
2459 | auth_alg = WLAN_AUTH_SHARED_KEY; | |
2460 | break; | |
2461 | case NL80211_AUTHTYPE_FT: | |
2462 | auth_alg = WLAN_AUTH_FT; | |
2463 | break; | |
2464 | case NL80211_AUTHTYPE_NETWORK_EAP: | |
2465 | auth_alg = WLAN_AUTH_LEAP; | |
2466 | break; | |
2467 | default: | |
2468 | return -EOPNOTSUPP; | |
60f8b39c | 2469 | } |
77fdaa12 JB |
2470 | |
2471 | wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL); | |
2472 | if (!wk) | |
9c6bd790 | 2473 | return -ENOMEM; |
77fdaa12 | 2474 | |
f679f65d | 2475 | memcpy(wk->auth.bssid, req->bss->bssid, ETH_ALEN);; |
77fdaa12 JB |
2476 | |
2477 | if (req->ie && req->ie_len) { | |
2478 | memcpy(wk->ie, req->ie, req->ie_len); | |
2479 | wk->ie_len = req->ie_len; | |
9c6bd790 | 2480 | } |
77fdaa12 | 2481 | |
fffd0934 | 2482 | if (req->key && req->key_len) { |
f679f65d JB |
2483 | wk->auth.key_len = req->key_len; |
2484 | wk->auth.key_idx = req->key_idx; | |
2485 | memcpy(wk->auth.key, req->key, req->key_len); | |
fffd0934 JB |
2486 | } |
2487 | ||
77fdaa12 | 2488 | ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
f679f65d JB |
2489 | memcpy(wk->auth.ssid, ssid + 2, ssid[1]); |
2490 | wk->auth.ssid_len = ssid[1]; | |
2491 | ||
2492 | wk->auth.algorithm = auth_alg; | |
2493 | wk->auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY; | |
77fdaa12 | 2494 | |
f679f65d | 2495 | wk->type = IEEE80211_WORK_AUTH_PROBE; |
48531847 | 2496 | wk->timeout = jiffies; /* run right away */ |
f679f65d | 2497 | wk->chan = req->bss->channel; |
77fdaa12 JB |
2498 | |
2499 | /* | |
2500 | * XXX: if still associated need to tell AP that we're going | |
2501 | * to sleep and then change channel etc. | |
f679f65d JB |
2502 | * For now switch channel here, later will be handled |
2503 | * by submitting this as an off-channel work item. | |
77fdaa12 JB |
2504 | */ |
2505 | sdata->local->oper_channel = req->bss->channel; | |
2506 | ieee80211_hw_config(sdata->local, 0); | |
2507 | ||
2508 | mutex_lock(&ifmgd->mtx); | |
2509 | list_add(&wk->list, &sdata->u.mgd.work_list); | |
2510 | mutex_unlock(&ifmgd->mtx); | |
2511 | ||
42935eca | 2512 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); |
9c6bd790 | 2513 | return 0; |
60f8b39c JB |
2514 | } |
2515 | ||
77fdaa12 JB |
2516 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
2517 | struct cfg80211_assoc_request *req) | |
f0706e82 | 2518 | { |
77fdaa12 | 2519 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f679f65d | 2520 | struct ieee80211_work *wk; |
63f170e0 | 2521 | const u8 *ssid; |
77fdaa12 | 2522 | int i, err; |
f0706e82 | 2523 | |
77fdaa12 JB |
2524 | mutex_lock(&ifmgd->mtx); |
2525 | ||
63f170e0 | 2526 | wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL); |
77fdaa12 | 2527 | if (!wk) { |
77fdaa12 JB |
2528 | err = -ENOMEM; |
2529 | goto out; | |
2530 | } | |
2531 | ||
77fdaa12 JB |
2532 | ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N; |
2533 | ||
2534 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) | |
2535 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || | |
2536 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || | |
2537 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) | |
2538 | ifmgd->flags |= IEEE80211_STA_DISABLE_11N; | |
2539 | ||
77fdaa12 JB |
2540 | |
2541 | if (req->ie && req->ie_len) { | |
2542 | memcpy(wk->ie, req->ie, req->ie_len); | |
2543 | wk->ie_len = req->ie_len; | |
2544 | } else | |
2545 | wk->ie_len = 0; | |
2546 | ||
f679f65d JB |
2547 | wk->assoc.bss = (void *)req->bss; |
2548 | ||
2549 | memcpy(wk->assoc.bssid, req->bss->bssid, ETH_ALEN); | |
2550 | ||
2551 | wk->assoc.capability = req->bss->capability; | |
2552 | wk->assoc.wmm_used = wk->assoc.bss->wmm_used; | |
2553 | wk->assoc.supp_rates = wk->assoc.bss->supp_rates; | |
2554 | wk->assoc.supp_rates_len = wk->assoc.bss->supp_rates_len; | |
2555 | wk->assoc.ht_information_ie = | |
2556 | ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION); | |
63f170e0 JB |
2557 | |
2558 | ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); | |
f679f65d JB |
2559 | memcpy(wk->assoc.ssid, ssid + 2, ssid[1]); |
2560 | wk->assoc.ssid_len = ssid[1]; | |
63f170e0 | 2561 | |
77fdaa12 | 2562 | if (req->prev_bssid) |
f679f65d | 2563 | memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN); |
77fdaa12 | 2564 | |
f679f65d | 2565 | wk->type = IEEE80211_WORK_ASSOC; |
48531847 | 2566 | wk->timeout = jiffies; /* run right away */ |
f679f65d | 2567 | wk->chan = req->bss->channel; |
77fdaa12 JB |
2568 | |
2569 | if (req->use_mfp) { | |
2570 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; | |
2571 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; | |
2572 | } else { | |
2573 | ifmgd->mfp = IEEE80211_MFP_DISABLED; | |
2574 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; | |
2575 | } | |
2576 | ||
2577 | if (req->crypto.control_port) | |
2578 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; | |
2579 | else | |
2580 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; | |
2581 | ||
63f170e0 JB |
2582 | sdata->local->oper_channel = req->bss->channel; |
2583 | ieee80211_hw_config(sdata->local, 0); | |
2584 | ||
2585 | list_add(&wk->list, &ifmgd->work_list); | |
42935eca | 2586 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); |
77fdaa12 JB |
2587 | |
2588 | err = 0; | |
2589 | ||
2590 | out: | |
2591 | mutex_unlock(&ifmgd->mtx); | |
2592 | return err; | |
f0706e82 JB |
2593 | } |
2594 | ||
77fdaa12 | 2595 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
667503dd JB |
2596 | struct cfg80211_deauth_request *req, |
2597 | void *cookie) | |
f0706e82 | 2598 | { |
46900298 | 2599 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f679f65d | 2600 | struct ieee80211_work *wk; |
63f170e0 | 2601 | const u8 *bssid = req->bss->bssid; |
a58ce43f | 2602 | bool not_auth_yet = false; |
f0706e82 | 2603 | |
77fdaa12 JB |
2604 | mutex_lock(&ifmgd->mtx); |
2605 | ||
2606 | if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) { | |
2607 | bssid = req->bss->bssid; | |
63f170e0 | 2608 | ieee80211_set_disassoc(sdata); |
77fdaa12 | 2609 | } else list_for_each_entry(wk, &ifmgd->work_list, list) { |
f679f65d | 2610 | if (wk->type != IEEE80211_WORK_AUTH_PROBE) |
63f170e0 | 2611 | continue; |
f679f65d | 2612 | if (memcmp(req->bss->bssid, wk->auth.bssid, ETH_ALEN)) |
63f170e0 JB |
2613 | continue; |
2614 | not_auth_yet = true; | |
2615 | list_del(&wk->list); | |
2616 | kfree(wk); | |
2617 | break; | |
77fdaa12 | 2618 | } |
f0706e82 | 2619 | |
a58ce43f JB |
2620 | /* |
2621 | * If somebody requests authentication and we haven't | |
2622 | * sent out an auth frame yet there's no need to send | |
2623 | * out a deauth frame either. If the state was PROBE, | |
2624 | * then this is the case. If it's AUTH we have sent a | |
2625 | * frame, and if it's IDLE we have completed the auth | |
2626 | * process already. | |
2627 | */ | |
2628 | if (not_auth_yet) { | |
2629 | mutex_unlock(&ifmgd->mtx); | |
2630 | __cfg80211_auth_canceled(sdata->dev, bssid); | |
2631 | return 0; | |
2632 | } | |
2633 | ||
77fdaa12 JB |
2634 | mutex_unlock(&ifmgd->mtx); |
2635 | ||
0ff71613 | 2636 | printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n", |
47846c9b | 2637 | sdata->name, bssid, req->reason_code); |
0ff71613 | 2638 | |
77fdaa12 | 2639 | ieee80211_send_deauth_disassoc(sdata, bssid, |
667503dd JB |
2640 | IEEE80211_STYPE_DEAUTH, req->reason_code, |
2641 | cookie); | |
f0706e82 | 2642 | |
bc83b681 JB |
2643 | ieee80211_recalc_idle(sdata->local); |
2644 | ||
f0706e82 JB |
2645 | return 0; |
2646 | } | |
84363e6e | 2647 | |
77fdaa12 | 2648 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
667503dd JB |
2649 | struct cfg80211_disassoc_request *req, |
2650 | void *cookie) | |
9c6bd790 | 2651 | { |
77fdaa12 | 2652 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
9c6bd790 | 2653 | |
77fdaa12 | 2654 | mutex_lock(&ifmgd->mtx); |
10f644a4 | 2655 | |
8d8b261a JB |
2656 | /* |
2657 | * cfg80211 should catch this ... but it's racy since | |
2658 | * we can receive a disassoc frame, process it, hand it | |
2659 | * to cfg80211 while that's in a locked section already | |
2660 | * trying to tell us that the user wants to disconnect. | |
2661 | */ | |
2662 | if (&ifmgd->associated->cbss != req->bss) { | |
77fdaa12 JB |
2663 | mutex_unlock(&ifmgd->mtx); |
2664 | return -ENOLINK; | |
2665 | } | |
2666 | ||
0ff71613 | 2667 | printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n", |
47846c9b | 2668 | sdata->name, req->bss->bssid, req->reason_code); |
0ff71613 | 2669 | |
63f170e0 | 2670 | ieee80211_set_disassoc(sdata); |
77fdaa12 JB |
2671 | |
2672 | mutex_unlock(&ifmgd->mtx); | |
10f644a4 | 2673 | |
77fdaa12 | 2674 | ieee80211_send_deauth_disassoc(sdata, req->bss->bssid, |
667503dd JB |
2675 | IEEE80211_STYPE_DISASSOC, req->reason_code, |
2676 | cookie); | |
bc83b681 JB |
2677 | |
2678 | ieee80211_recalc_idle(sdata->local); | |
2679 | ||
10f644a4 JB |
2680 | return 0; |
2681 | } |