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