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