]>
Commit | Line | Data |
---|---|---|
f0706e82 JB |
1 | /* |
2 | * BSS client mode implementation | |
3 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> | |
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> | |
17 | #include <linux/netdevice.h> | |
18 | #include <linux/if_arp.h> | |
19 | #include <linux/wireless.h> | |
20 | #include <linux/random.h> | |
21 | #include <linux/etherdevice.h> | |
d0709a65 | 22 | #include <linux/rtnetlink.h> |
f0706e82 | 23 | #include <net/iw_handler.h> |
f0706e82 | 24 | #include <net/mac80211.h> |
472dbc45 | 25 | #include <asm/unaligned.h> |
60f8b39c | 26 | |
f0706e82 | 27 | #include "ieee80211_i.h" |
2c8dccc7 JB |
28 | #include "rate.h" |
29 | #include "led.h" | |
f0706e82 | 30 | |
6042a3e3 | 31 | #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2 |
f0706e82 JB |
32 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
33 | #define IEEE80211_AUTH_MAX_TRIES 3 | |
34 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) | |
35 | #define IEEE80211_ASSOC_MAX_TRIES 3 | |
36 | #define IEEE80211_MONITORING_INTERVAL (2 * HZ) | |
37 | #define IEEE80211_PROBE_INTERVAL (60 * HZ) | |
38 | #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) | |
39 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) | |
40 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) | |
872ba533 | 41 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) |
f0706e82 | 42 | |
f0706e82 JB |
43 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) |
44 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) | |
45 | ||
46 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 | |
47 | ||
48 | ||
5484e237 JB |
49 | /* utils */ |
50 | static int ecw2cw(int ecw) | |
60f8b39c | 51 | { |
5484e237 | 52 | return (1 << ecw) - 1; |
60f8b39c JB |
53 | } |
54 | ||
55 | static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie) | |
43ac2ca3 JM |
56 | { |
57 | u8 *end, *pos; | |
58 | ||
59 | pos = bss->ies; | |
60 | if (pos == NULL) | |
61 | return NULL; | |
62 | end = pos + bss->ies_len; | |
63 | ||
64 | while (pos + 1 < end) { | |
65 | if (pos + 2 + pos[1] > end) | |
66 | break; | |
67 | if (pos[0] == ie) | |
68 | return pos; | |
69 | pos += 2 + pos[1]; | |
70 | } | |
71 | ||
72 | return NULL; | |
73 | } | |
74 | ||
9ac19a90 JB |
75 | static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss, |
76 | struct ieee80211_supported_band *sband, | |
77 | u64 *rates) | |
78 | { | |
79 | int i, j, count; | |
80 | *rates = 0; | |
81 | count = 0; | |
82 | for (i = 0; i < bss->supp_rates_len; i++) { | |
83 | int rate = (bss->supp_rates[i] & 0x7F) * 5; | |
84 | ||
85 | for (j = 0; j < sband->n_bitrates; j++) | |
86 | if (sband->bitrates[j].bitrate == rate) { | |
87 | *rates |= BIT(j); | |
88 | count++; | |
89 | break; | |
90 | } | |
91 | } | |
92 | ||
93 | return count; | |
94 | } | |
95 | ||
9c6bd790 JB |
96 | /* also used by mesh code */ |
97 | u64 ieee80211_sta_get_rates(struct ieee80211_local *local, | |
98 | struct ieee802_11_elems *elems, | |
99 | enum ieee80211_band band) | |
60f8b39c | 100 | { |
9c6bd790 JB |
101 | struct ieee80211_supported_band *sband; |
102 | struct ieee80211_rate *bitrates; | |
103 | size_t num_rates; | |
104 | u64 supp_rates; | |
105 | int i, j; | |
106 | sband = local->hw.wiphy->bands[band]; | |
60f8b39c | 107 | |
9c6bd790 JB |
108 | if (!sband) { |
109 | WARN_ON(1); | |
110 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
60f8b39c | 111 | } |
60f8b39c | 112 | |
9c6bd790 JB |
113 | bitrates = sband->bitrates; |
114 | num_rates = sband->n_bitrates; | |
115 | supp_rates = 0; | |
116 | for (i = 0; i < elems->supp_rates_len + | |
117 | elems->ext_supp_rates_len; i++) { | |
118 | u8 rate = 0; | |
119 | int own_rate; | |
120 | if (i < elems->supp_rates_len) | |
121 | rate = elems->supp_rates[i]; | |
122 | else if (elems->ext_supp_rates) | |
123 | rate = elems->ext_supp_rates | |
124 | [i - elems->supp_rates_len]; | |
125 | own_rate = 5 * (rate & 0x7f); | |
126 | for (j = 0; j < num_rates; j++) | |
127 | if (bitrates[j].bitrate == own_rate) | |
128 | supp_rates |= BIT(j); | |
129 | } | |
130 | return supp_rates; | |
60f8b39c JB |
131 | } |
132 | ||
9c6bd790 JB |
133 | /* frame sending functions */ |
134 | ||
135 | /* also used by scanning code */ | |
0a51b27e JB |
136 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, |
137 | u8 *ssid, size_t ssid_len) | |
60f8b39c JB |
138 | { |
139 | struct ieee80211_local *local = sdata->local; | |
140 | struct ieee80211_supported_band *sband; | |
141 | struct sk_buff *skb; | |
142 | struct ieee80211_mgmt *mgmt; | |
143 | u8 *pos, *supp_rates, *esupp_rates = NULL; | |
144 | int i; | |
145 | ||
146 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200); | |
147 | if (!skb) { | |
148 | printk(KERN_DEBUG "%s: failed to allocate buffer for probe " | |
149 | "request\n", sdata->dev->name); | |
150 | return; | |
151 | } | |
152 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
153 | ||
154 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
155 | memset(mgmt, 0, 24); | |
156 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
157 | IEEE80211_STYPE_PROBE_REQ); | |
158 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
159 | if (dst) { | |
160 | memcpy(mgmt->da, dst, ETH_ALEN); | |
161 | memcpy(mgmt->bssid, dst, ETH_ALEN); | |
162 | } else { | |
163 | memset(mgmt->da, 0xff, ETH_ALEN); | |
164 | memset(mgmt->bssid, 0xff, ETH_ALEN); | |
165 | } | |
166 | pos = skb_put(skb, 2 + ssid_len); | |
167 | *pos++ = WLAN_EID_SSID; | |
168 | *pos++ = ssid_len; | |
169 | memcpy(pos, ssid, ssid_len); | |
170 | ||
171 | supp_rates = skb_put(skb, 2); | |
172 | supp_rates[0] = WLAN_EID_SUPP_RATES; | |
173 | supp_rates[1] = 0; | |
174 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
175 | ||
176 | for (i = 0; i < sband->n_bitrates; i++) { | |
177 | struct ieee80211_rate *rate = &sband->bitrates[i]; | |
178 | if (esupp_rates) { | |
179 | pos = skb_put(skb, 1); | |
180 | esupp_rates[1]++; | |
181 | } else if (supp_rates[1] == 8) { | |
182 | esupp_rates = skb_put(skb, 3); | |
183 | esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES; | |
184 | esupp_rates[1] = 1; | |
185 | pos = &esupp_rates[2]; | |
186 | } else { | |
187 | pos = skb_put(skb, 1); | |
188 | supp_rates[1]++; | |
189 | } | |
190 | *pos = rate->bitrate / 5; | |
191 | } | |
192 | ||
e50db65c | 193 | ieee80211_tx_skb(sdata, skb, 0); |
60f8b39c JB |
194 | } |
195 | ||
9c6bd790 JB |
196 | static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, |
197 | struct ieee80211_if_sta *ifsta, | |
198 | int transaction, u8 *extra, size_t extra_len, | |
199 | int encrypt) | |
200 | { | |
201 | struct ieee80211_local *local = sdata->local; | |
202 | struct sk_buff *skb; | |
203 | struct ieee80211_mgmt *mgmt; | |
204 | ||
205 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
206 | sizeof(*mgmt) + 6 + extra_len); | |
207 | if (!skb) { | |
208 | printk(KERN_DEBUG "%s: failed to allocate buffer for auth " | |
209 | "frame\n", sdata->dev->name); | |
210 | return; | |
211 | } | |
212 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
213 | ||
214 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); | |
215 | memset(mgmt, 0, 24 + 6); | |
216 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
217 | IEEE80211_STYPE_AUTH); | |
218 | if (encrypt) | |
219 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
220 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | |
221 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
222 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
223 | mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg); | |
224 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); | |
225 | ifsta->auth_transaction = transaction + 1; | |
226 | mgmt->u.auth.status_code = cpu_to_le16(0); | |
227 | if (extra) | |
228 | memcpy(skb_put(skb, extra_len), extra, extra_len); | |
229 | ||
230 | ieee80211_tx_skb(sdata, skb, encrypt); | |
231 | } | |
232 | ||
9ac19a90 JB |
233 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata, |
234 | struct ieee80211_if_sta *ifsta) | |
235 | { | |
236 | struct ieee80211_local *local = sdata->local; | |
237 | struct sk_buff *skb; | |
238 | struct ieee80211_mgmt *mgmt; | |
239 | u8 *pos, *ies, *ht_add_ie; | |
240 | int i, len, count, rates_len, supp_rates_len; | |
241 | u16 capab; | |
242 | struct ieee80211_sta_bss *bss; | |
243 | int wmm = 0; | |
244 | struct ieee80211_supported_band *sband; | |
245 | u64 rates = 0; | |
246 | ||
247 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
248 | sizeof(*mgmt) + 200 + ifsta->extra_ie_len + | |
249 | ifsta->ssid_len); | |
250 | if (!skb) { | |
251 | printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " | |
252 | "frame\n", sdata->dev->name); | |
253 | return; | |
254 | } | |
255 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
256 | ||
257 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
258 | ||
259 | capab = ifsta->capab; | |
260 | ||
261 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) { | |
262 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) | |
263 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; | |
264 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) | |
265 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
266 | } | |
267 | ||
268 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, | |
269 | local->hw.conf.channel->center_freq, | |
270 | ifsta->ssid, ifsta->ssid_len); | |
271 | if (bss) { | |
272 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) | |
273 | capab |= WLAN_CAPABILITY_PRIVACY; | |
274 | if (bss->wmm_used) | |
275 | wmm = 1; | |
276 | ||
277 | /* get all rates supported by the device and the AP as | |
278 | * some APs don't like getting a superset of their rates | |
279 | * in the association request (e.g. D-Link DAP 1353 in | |
280 | * b-only mode) */ | |
281 | rates_len = ieee80211_compatible_rates(bss, sband, &rates); | |
282 | ||
283 | if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && | |
284 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) | |
285 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; | |
286 | ||
287 | ieee80211_rx_bss_put(local, bss); | |
288 | } else { | |
289 | rates = ~0; | |
290 | rates_len = sband->n_bitrates; | |
291 | } | |
292 | ||
293 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
294 | memset(mgmt, 0, 24); | |
295 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | |
296 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
297 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
298 | ||
299 | if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) { | |
300 | skb_put(skb, 10); | |
301 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
302 | IEEE80211_STYPE_REASSOC_REQ); | |
303 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); | |
304 | mgmt->u.reassoc_req.listen_interval = | |
305 | cpu_to_le16(local->hw.conf.listen_interval); | |
306 | memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid, | |
307 | ETH_ALEN); | |
308 | } else { | |
309 | skb_put(skb, 4); | |
310 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
311 | IEEE80211_STYPE_ASSOC_REQ); | |
312 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); | |
313 | mgmt->u.reassoc_req.listen_interval = | |
314 | cpu_to_le16(local->hw.conf.listen_interval); | |
315 | } | |
316 | ||
317 | /* SSID */ | |
318 | ies = pos = skb_put(skb, 2 + ifsta->ssid_len); | |
319 | *pos++ = WLAN_EID_SSID; | |
320 | *pos++ = ifsta->ssid_len; | |
321 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); | |
322 | ||
323 | /* add all rates which were marked to be used above */ | |
324 | supp_rates_len = rates_len; | |
325 | if (supp_rates_len > 8) | |
326 | supp_rates_len = 8; | |
327 | ||
328 | len = sband->n_bitrates; | |
329 | pos = skb_put(skb, supp_rates_len + 2); | |
330 | *pos++ = WLAN_EID_SUPP_RATES; | |
331 | *pos++ = supp_rates_len; | |
332 | ||
333 | count = 0; | |
334 | for (i = 0; i < sband->n_bitrates; i++) { | |
335 | if (BIT(i) & rates) { | |
336 | int rate = sband->bitrates[i].bitrate; | |
337 | *pos++ = (u8) (rate / 5); | |
338 | if (++count == 8) | |
339 | break; | |
340 | } | |
341 | } | |
342 | ||
343 | if (rates_len > count) { | |
344 | pos = skb_put(skb, rates_len - count + 2); | |
345 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
346 | *pos++ = rates_len - count; | |
347 | ||
348 | for (i++; i < sband->n_bitrates; i++) { | |
349 | if (BIT(i) & rates) { | |
350 | int rate = sband->bitrates[i].bitrate; | |
351 | *pos++ = (u8) (rate / 5); | |
352 | } | |
353 | } | |
354 | } | |
355 | ||
356 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { | |
357 | /* 1. power capabilities */ | |
358 | pos = skb_put(skb, 4); | |
359 | *pos++ = WLAN_EID_PWR_CAPABILITY; | |
360 | *pos++ = 2; | |
361 | *pos++ = 0; /* min tx power */ | |
362 | *pos++ = local->hw.conf.channel->max_power; /* max tx power */ | |
363 | ||
364 | /* 2. supported channels */ | |
365 | /* TODO: get this in reg domain format */ | |
366 | pos = skb_put(skb, 2 * sband->n_channels + 2); | |
367 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; | |
368 | *pos++ = 2 * sband->n_channels; | |
369 | for (i = 0; i < sband->n_channels; i++) { | |
370 | *pos++ = ieee80211_frequency_to_channel( | |
371 | sband->channels[i].center_freq); | |
372 | *pos++ = 1; /* one channel in the subband*/ | |
373 | } | |
374 | } | |
375 | ||
376 | if (ifsta->extra_ie) { | |
377 | pos = skb_put(skb, ifsta->extra_ie_len); | |
378 | memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len); | |
379 | } | |
380 | ||
381 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { | |
382 | pos = skb_put(skb, 9); | |
383 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; | |
384 | *pos++ = 7; /* len */ | |
385 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ | |
386 | *pos++ = 0x50; | |
387 | *pos++ = 0xf2; | |
388 | *pos++ = 2; /* WME */ | |
389 | *pos++ = 0; /* WME info */ | |
390 | *pos++ = 1; /* WME ver */ | |
391 | *pos++ = 0; | |
392 | } | |
393 | ||
394 | /* wmm support is a must to HT */ | |
395 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) && | |
396 | sband->ht_info.ht_supported && | |
397 | (ht_add_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_EXTRA_INFO))) { | |
398 | struct ieee80211_ht_addt_info *ht_add_info = | |
399 | (struct ieee80211_ht_addt_info *)ht_add_ie; | |
400 | u16 cap = sband->ht_info.cap; | |
401 | __le16 tmp; | |
402 | u32 flags = local->hw.conf.channel->flags; | |
403 | ||
404 | switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) { | |
405 | case IEEE80211_HT_IE_CHA_SEC_ABOVE: | |
406 | if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) { | |
407 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; | |
408 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
409 | } | |
410 | break; | |
411 | case IEEE80211_HT_IE_CHA_SEC_BELOW: | |
412 | if (flags & IEEE80211_CHAN_NO_FAT_BELOW) { | |
413 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; | |
414 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
415 | } | |
416 | break; | |
417 | } | |
418 | ||
419 | tmp = cpu_to_le16(cap); | |
420 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2); | |
421 | *pos++ = WLAN_EID_HT_CAPABILITY; | |
422 | *pos++ = sizeof(struct ieee80211_ht_cap); | |
423 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); | |
424 | memcpy(pos, &tmp, sizeof(u16)); | |
425 | pos += sizeof(u16); | |
426 | /* TODO: needs a define here for << 2 */ | |
427 | *pos++ = sband->ht_info.ampdu_factor | | |
428 | (sband->ht_info.ampdu_density << 2); | |
429 | memcpy(pos, sband->ht_info.supp_mcs_set, 16); | |
430 | } | |
431 | ||
432 | kfree(ifsta->assocreq_ies); | |
433 | ifsta->assocreq_ies_len = (skb->data + skb->len) - ies; | |
434 | ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL); | |
435 | if (ifsta->assocreq_ies) | |
436 | memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len); | |
437 | ||
e50db65c | 438 | ieee80211_tx_skb(sdata, skb, 0); |
9ac19a90 JB |
439 | } |
440 | ||
441 | ||
ef422bc0 JB |
442 | static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, |
443 | u16 stype, u16 reason) | |
9ac19a90 JB |
444 | { |
445 | struct ieee80211_local *local = sdata->local; | |
ef422bc0 | 446 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
9ac19a90 JB |
447 | struct sk_buff *skb; |
448 | struct ieee80211_mgmt *mgmt; | |
449 | ||
450 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); | |
451 | if (!skb) { | |
ef422bc0 JB |
452 | printk(KERN_DEBUG "%s: failed to allocate buffer for " |
453 | "deauth/disassoc frame\n", sdata->dev->name); | |
9ac19a90 JB |
454 | return; |
455 | } | |
456 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
457 | ||
458 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
459 | memset(mgmt, 0, 24); | |
460 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | |
461 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
462 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
ef422bc0 | 463 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); |
9ac19a90 | 464 | skb_put(skb, 2); |
ef422bc0 | 465 | /* u.deauth.reason_code == u.disassoc.reason_code */ |
9ac19a90 JB |
466 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
467 | ||
e50db65c | 468 | ieee80211_tx_skb(sdata, skb, 0); |
9ac19a90 JB |
469 | } |
470 | ||
60f8b39c | 471 | /* MLME */ |
f698d856 | 472 | static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
b079ada7 | 473 | struct ieee80211_sta_bss *bss) |
e2839d8f | 474 | { |
e2839d8f VK |
475 | struct ieee80211_local *local = sdata->local; |
476 | int i, have_higher_than_11mbit = 0; | |
477 | ||
e2839d8f VK |
478 | /* cf. IEEE 802.11 9.2.12 */ |
479 | for (i = 0; i < bss->supp_rates_len; i++) | |
480 | if ((bss->supp_rates[i] & 0x7f) * 5 > 110) | |
481 | have_higher_than_11mbit = 1; | |
482 | ||
483 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
484 | have_higher_than_11mbit) | |
485 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
486 | else | |
487 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
488 | ||
3d35f7c6 | 489 | ieee80211_set_wmm_default(sdata); |
e2839d8f VK |
490 | } |
491 | ||
f698d856 | 492 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
f0706e82 JB |
493 | struct ieee80211_if_sta *ifsta, |
494 | u8 *wmm_param, size_t wmm_param_len) | |
495 | { | |
f0706e82 JB |
496 | struct ieee80211_tx_queue_params params; |
497 | size_t left; | |
498 | int count; | |
499 | u8 *pos; | |
500 | ||
3434fbd3 JB |
501 | if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED)) |
502 | return; | |
503 | ||
504 | if (!wmm_param) | |
505 | return; | |
506 | ||
f0706e82 JB |
507 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
508 | return; | |
509 | count = wmm_param[6] & 0x0f; | |
510 | if (count == ifsta->wmm_last_param_set) | |
511 | return; | |
512 | ifsta->wmm_last_param_set = count; | |
513 | ||
514 | pos = wmm_param + 8; | |
515 | left = wmm_param_len - 8; | |
516 | ||
517 | memset(¶ms, 0, sizeof(params)); | |
518 | ||
519 | if (!local->ops->conf_tx) | |
520 | return; | |
521 | ||
522 | local->wmm_acm = 0; | |
523 | for (; left >= 4; left -= 4, pos += 4) { | |
524 | int aci = (pos[0] >> 5) & 0x03; | |
525 | int acm = (pos[0] >> 4) & 0x01; | |
526 | int queue; | |
527 | ||
528 | switch (aci) { | |
529 | case 1: | |
e100bb64 | 530 | queue = 3; |
988c0f72 | 531 | if (acm) |
f0706e82 | 532 | local->wmm_acm |= BIT(0) | BIT(3); |
f0706e82 JB |
533 | break; |
534 | case 2: | |
e100bb64 | 535 | queue = 1; |
988c0f72 | 536 | if (acm) |
f0706e82 | 537 | local->wmm_acm |= BIT(4) | BIT(5); |
f0706e82 JB |
538 | break; |
539 | case 3: | |
e100bb64 | 540 | queue = 0; |
988c0f72 | 541 | if (acm) |
f0706e82 | 542 | local->wmm_acm |= BIT(6) | BIT(7); |
f0706e82 JB |
543 | break; |
544 | case 0: | |
545 | default: | |
e100bb64 | 546 | queue = 2; |
988c0f72 | 547 | if (acm) |
f0706e82 | 548 | local->wmm_acm |= BIT(1) | BIT(2); |
f0706e82 JB |
549 | break; |
550 | } | |
551 | ||
552 | params.aifs = pos[0] & 0x0f; | |
553 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); | |
554 | params.cw_min = ecw2cw(pos[1] & 0x0f); | |
f434b2d1 | 555 | params.txop = get_unaligned_le16(pos + 2); |
f4ea83dd | 556 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
f0706e82 | 557 | printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " |
3330d7be | 558 | "cWmin=%d cWmax=%d txop=%d\n", |
f698d856 | 559 | local->mdev->name, queue, aci, acm, params.aifs, params.cw_min, |
3330d7be JB |
560 | params.cw_max, params.txop); |
561 | #endif | |
f0706e82 JB |
562 | /* TODO: handle ACM (block TX, fallback to next lowest allowed |
563 | * AC for now) */ | |
564 | if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) { | |
565 | printk(KERN_DEBUG "%s: failed to set TX queue " | |
f698d856 | 566 | "parameters for queue %d\n", local->mdev->name, queue); |
f0706e82 JB |
567 | } |
568 | } | |
569 | } | |
570 | ||
50c4afb9 JL |
571 | static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata, |
572 | bool use_protection, | |
573 | bool use_short_preamble) | |
5628221c | 574 | { |
471b3efd | 575 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
ebd74487 | 576 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
5628221c | 577 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
0795af57 | 578 | DECLARE_MAC_BUF(mac); |
ebd74487 | 579 | #endif |
471b3efd | 580 | u32 changed = 0; |
5628221c | 581 | |
471b3efd | 582 | if (use_protection != bss_conf->use_cts_prot) { |
f4ea83dd | 583 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
5628221c DD |
584 | if (net_ratelimit()) { |
585 | printk(KERN_DEBUG "%s: CTS protection %s (BSSID=" | |
0795af57 | 586 | "%s)\n", |
471b3efd | 587 | sdata->dev->name, |
5628221c | 588 | use_protection ? "enabled" : "disabled", |
0795af57 | 589 | print_mac(mac, ifsta->bssid)); |
5628221c | 590 | } |
f4ea83dd | 591 | #endif |
471b3efd JB |
592 | bss_conf->use_cts_prot = use_protection; |
593 | changed |= BSS_CHANGED_ERP_CTS_PROT; | |
5628221c | 594 | } |
7e9ed188 | 595 | |
d43c7b37 | 596 | if (use_short_preamble != bss_conf->use_short_preamble) { |
f4ea83dd | 597 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
7e9ed188 DD |
598 | if (net_ratelimit()) { |
599 | printk(KERN_DEBUG "%s: switched to %s barker preamble" | |
0795af57 | 600 | " (BSSID=%s)\n", |
471b3efd | 601 | sdata->dev->name, |
d43c7b37 | 602 | use_short_preamble ? "short" : "long", |
0795af57 | 603 | print_mac(mac, ifsta->bssid)); |
7e9ed188 | 604 | } |
f4ea83dd | 605 | #endif |
d43c7b37 | 606 | bss_conf->use_short_preamble = use_short_preamble; |
471b3efd | 607 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
7e9ed188 | 608 | } |
d9430a32 | 609 | |
471b3efd | 610 | return changed; |
5628221c DD |
611 | } |
612 | ||
50c4afb9 JL |
613 | static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata, |
614 | u8 erp_value) | |
615 | { | |
616 | bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; | |
617 | bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0; | |
618 | ||
619 | return ieee80211_handle_protect_preamb(sdata, | |
620 | use_protection, use_short_preamble); | |
621 | } | |
622 | ||
623 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, | |
624 | struct ieee80211_sta_bss *bss) | |
625 | { | |
626 | u32 changed = 0; | |
627 | ||
628 | if (bss->has_erp_value) | |
629 | changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value); | |
630 | else { | |
631 | u16 capab = bss->capability; | |
632 | changed |= ieee80211_handle_protect_preamb(sdata, false, | |
633 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); | |
634 | } | |
635 | ||
636 | return changed; | |
637 | } | |
638 | ||
f5e5bf25 TW |
639 | static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata, |
640 | struct ieee80211_if_sta *ifsta) | |
641 | { | |
642 | union iwreq_data wrqu; | |
643 | memset(&wrqu, 0, sizeof(wrqu)); | |
644 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) | |
645 | memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN); | |
646 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
647 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); | |
648 | } | |
649 | ||
f698d856 | 650 | static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
651 | struct ieee80211_if_sta *ifsta) |
652 | { | |
f0706e82 JB |
653 | union iwreq_data wrqu; |
654 | ||
f0706e82 | 655 | if (ifsta->assocreq_ies) { |
087d833e JM |
656 | memset(&wrqu, 0, sizeof(wrqu)); |
657 | wrqu.data.length = ifsta->assocreq_ies_len; | |
b171e19e | 658 | wireless_send_event(sdata->dev, IWEVASSOCREQIE, &wrqu, |
087d833e | 659 | ifsta->assocreq_ies); |
f0706e82 | 660 | } |
087d833e JM |
661 | if (ifsta->assocresp_ies) { |
662 | memset(&wrqu, 0, sizeof(wrqu)); | |
663 | wrqu.data.length = ifsta->assocresp_ies_len; | |
b171e19e | 664 | wireless_send_event(sdata->dev, IWEVASSOCRESPIE, &wrqu, |
087d833e | 665 | ifsta->assocresp_ies); |
f0706e82 | 666 | } |
f0706e82 JB |
667 | } |
668 | ||
669 | ||
f698d856 | 670 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
f5e5bf25 | 671 | struct ieee80211_if_sta *ifsta) |
f0706e82 | 672 | { |
471b3efd | 673 | struct ieee80211_local *local = sdata->local; |
38668c05 | 674 | struct ieee80211_conf *conf = &local_to_hw(local)->conf; |
471b3efd | 675 | u32 changed = BSS_CHANGED_ASSOC; |
f0706e82 | 676 | |
f5e5bf25 | 677 | struct ieee80211_sta_bss *bss; |
d6f2da5b | 678 | |
f5e5bf25 | 679 | ifsta->flags |= IEEE80211_STA_ASSOCIATED; |
5628221c | 680 | |
f5e5bf25 TW |
681 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
682 | return; | |
21c0cbe7 | 683 | |
f5e5bf25 TW |
684 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
685 | conf->channel->center_freq, | |
686 | ifsta->ssid, ifsta->ssid_len); | |
687 | if (bss) { | |
688 | /* set timing information */ | |
689 | sdata->bss_conf.beacon_int = bss->beacon_int; | |
690 | sdata->bss_conf.timestamp = bss->timestamp; | |
691 | sdata->bss_conf.dtim_period = bss->dtim_period; | |
21c0cbe7 | 692 | |
f5e5bf25 | 693 | changed |= ieee80211_handle_bss_capability(sdata, bss); |
9ac19a90 JB |
694 | |
695 | ieee80211_rx_bss_put(local, bss); | |
f0706e82 JB |
696 | } |
697 | ||
9ac19a90 JB |
698 | if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
699 | changed |= BSS_CHANGED_HT; | |
700 | sdata->bss_conf.assoc_ht = 1; | |
701 | sdata->bss_conf.ht_conf = &conf->ht_conf; | |
702 | sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf; | |
f0706e82 | 703 | } |
3434fbd3 | 704 | |
9ac19a90 JB |
705 | ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET; |
706 | memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN); | |
707 | ieee80211_sta_send_associnfo(sdata, ifsta); | |
9306102e | 708 | |
9ac19a90 JB |
709 | ifsta->last_probe = jiffies; |
710 | ieee80211_led_assoc(local, 1); | |
9306102e | 711 | |
9ac19a90 JB |
712 | sdata->bss_conf.assoc = 1; |
713 | ieee80211_bss_info_change_notify(sdata, changed); | |
f0706e82 | 714 | |
9ac19a90 JB |
715 | netif_tx_start_all_queues(sdata->dev); |
716 | netif_carrier_on(sdata->dev); | |
f0706e82 | 717 | |
9ac19a90 | 718 | ieee80211_sta_send_apinfo(sdata, ifsta); |
f0706e82 JB |
719 | } |
720 | ||
9ac19a90 JB |
721 | static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata, |
722 | struct ieee80211_if_sta *ifsta) | |
f0706e82 | 723 | { |
9ac19a90 | 724 | DECLARE_MAC_BUF(mac); |
f0706e82 | 725 | |
9ac19a90 JB |
726 | ifsta->direct_probe_tries++; |
727 | if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) { | |
728 | printk(KERN_DEBUG "%s: direct probe to AP %s timed out\n", | |
729 | sdata->dev->name, print_mac(mac, ifsta->bssid)); | |
730 | ifsta->state = IEEE80211_STA_MLME_DISABLED; | |
f0706e82 JB |
731 | return; |
732 | } | |
f0706e82 | 733 | |
9ac19a90 JB |
734 | printk(KERN_DEBUG "%s: direct probe to AP %s try %d\n", |
735 | sdata->dev->name, print_mac(mac, ifsta->bssid), | |
736 | ifsta->direct_probe_tries); | |
f0706e82 | 737 | |
9ac19a90 | 738 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
f0706e82 | 739 | |
9ac19a90 JB |
740 | set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifsta->request); |
741 | ||
742 | /* Direct probe is sent to broadcast address as some APs | |
743 | * will not answer to direct packet in unassociated state. | |
744 | */ | |
745 | ieee80211_send_probe_req(sdata, NULL, | |
746 | ifsta->ssid, ifsta->ssid_len); | |
747 | ||
748 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); | |
60f8b39c | 749 | } |
f0706e82 | 750 | |
9ac19a90 JB |
751 | |
752 | static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata, | |
753 | struct ieee80211_if_sta *ifsta) | |
f0706e82 | 754 | { |
9ac19a90 | 755 | DECLARE_MAC_BUF(mac); |
f0706e82 | 756 | |
9ac19a90 JB |
757 | ifsta->auth_tries++; |
758 | if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) { | |
759 | printk(KERN_DEBUG "%s: authentication with AP %s" | |
760 | " timed out\n", | |
761 | sdata->dev->name, print_mac(mac, ifsta->bssid)); | |
762 | ifsta->state = IEEE80211_STA_MLME_DISABLED; | |
f0706e82 JB |
763 | return; |
764 | } | |
f0706e82 | 765 | |
9ac19a90 JB |
766 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
767 | printk(KERN_DEBUG "%s: authenticate with AP %s\n", | |
768 | sdata->dev->name, print_mac(mac, ifsta->bssid)); | |
f0706e82 | 769 | |
9ac19a90 JB |
770 | ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0); |
771 | ||
772 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); | |
f0706e82 JB |
773 | } |
774 | ||
aa458d17 TW |
775 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
776 | struct ieee80211_if_sta *ifsta, bool deauth, | |
777 | bool self_disconnected, u16 reason) | |
778 | { | |
779 | struct ieee80211_local *local = sdata->local; | |
780 | struct sta_info *sta; | |
f5e5bf25 | 781 | u32 changed = BSS_CHANGED_ASSOC; |
aa458d17 TW |
782 | |
783 | rcu_read_lock(); | |
784 | ||
785 | sta = sta_info_get(local, ifsta->bssid); | |
786 | if (!sta) { | |
787 | rcu_read_unlock(); | |
788 | return; | |
789 | } | |
790 | ||
791 | if (deauth) { | |
792 | ifsta->direct_probe_tries = 0; | |
793 | ifsta->auth_tries = 0; | |
794 | } | |
795 | ifsta->assoc_scan_tries = 0; | |
796 | ifsta->assoc_tries = 0; | |
797 | ||
24e64622 | 798 | netif_tx_stop_all_queues(sdata->dev); |
aa458d17 TW |
799 | netif_carrier_off(sdata->dev); |
800 | ||
801 | ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr); | |
802 | ||
803 | if (self_disconnected) { | |
804 | if (deauth) | |
ef422bc0 JB |
805 | ieee80211_send_deauth_disassoc(sdata, |
806 | IEEE80211_STYPE_DEAUTH, reason); | |
aa458d17 | 807 | else |
ef422bc0 JB |
808 | ieee80211_send_deauth_disassoc(sdata, |
809 | IEEE80211_STYPE_DISASSOC, reason); | |
aa458d17 TW |
810 | } |
811 | ||
f5e5bf25 TW |
812 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
813 | changed |= ieee80211_reset_erp_info(sdata); | |
814 | ||
815 | if (sdata->bss_conf.assoc_ht) | |
816 | changed |= BSS_CHANGED_HT; | |
817 | ||
818 | sdata->bss_conf.assoc_ht = 0; | |
819 | sdata->bss_conf.ht_conf = NULL; | |
820 | sdata->bss_conf.ht_bss_conf = NULL; | |
821 | ||
822 | ieee80211_led_assoc(local, 0); | |
823 | sdata->bss_conf.assoc = 0; | |
824 | ||
825 | ieee80211_sta_send_apinfo(sdata, ifsta); | |
aa458d17 TW |
826 | |
827 | if (self_disconnected) | |
828 | ifsta->state = IEEE80211_STA_MLME_DISABLED; | |
829 | ||
830 | sta_info_unlink(&sta); | |
831 | ||
832 | rcu_read_unlock(); | |
833 | ||
834 | sta_info_destroy(sta); | |
835 | } | |
f0706e82 | 836 | |
9ac19a90 JB |
837 | static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata) |
838 | { | |
839 | if (!sdata || !sdata->default_key || | |
840 | sdata->default_key->conf.alg != ALG_WEP) | |
841 | return 0; | |
842 | return 1; | |
843 | } | |
844 | ||
f698d856 | 845 | static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
846 | struct ieee80211_if_sta *ifsta) |
847 | { | |
f698d856 | 848 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 849 | struct ieee80211_sta_bss *bss; |
5b98b1f7 JB |
850 | int bss_privacy; |
851 | int wep_privacy; | |
852 | int privacy_invoked; | |
f0706e82 | 853 | |
5b98b1f7 | 854 | if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL)) |
f0706e82 JB |
855 | return 0; |
856 | ||
f698d856 | 857 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
8318d78a | 858 | local->hw.conf.channel->center_freq, |
cffdd30d | 859 | ifsta->ssid, ifsta->ssid_len); |
f0706e82 JB |
860 | if (!bss) |
861 | return 0; | |
862 | ||
5b98b1f7 | 863 | bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY); |
f698d856 | 864 | wep_privacy = !!ieee80211_sta_wep_configured(sdata); |
5b98b1f7 | 865 | privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED); |
f0706e82 | 866 | |
3e122be0 | 867 | ieee80211_rx_bss_put(local, bss); |
f0706e82 | 868 | |
5b98b1f7 JB |
869 | if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked)) |
870 | return 0; | |
871 | ||
872 | return 1; | |
f0706e82 JB |
873 | } |
874 | ||
f698d856 | 875 | static void ieee80211_associate(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
876 | struct ieee80211_if_sta *ifsta) |
877 | { | |
0795af57 JP |
878 | DECLARE_MAC_BUF(mac); |
879 | ||
f0706e82 JB |
880 | ifsta->assoc_tries++; |
881 | if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { | |
0795af57 | 882 | printk(KERN_DEBUG "%s: association with AP %s" |
f0706e82 | 883 | " timed out\n", |
f698d856 | 884 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
48c2fc59 | 885 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
f0706e82 JB |
886 | return; |
887 | } | |
888 | ||
48c2fc59 | 889 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; |
0795af57 | 890 | printk(KERN_DEBUG "%s: associate with AP %s\n", |
f698d856 JBG |
891 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
892 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { | |
f0706e82 | 893 | printk(KERN_DEBUG "%s: mismatch in privacy configuration and " |
f698d856 | 894 | "mixed-cell disabled - abort association\n", sdata->dev->name); |
48c2fc59 | 895 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
f0706e82 JB |
896 | return; |
897 | } | |
898 | ||
f698d856 | 899 | ieee80211_send_assoc(sdata, ifsta); |
f0706e82 JB |
900 | |
901 | mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); | |
902 | } | |
903 | ||
904 | ||
f698d856 | 905 | static void ieee80211_associated(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
906 | struct ieee80211_if_sta *ifsta) |
907 | { | |
f698d856 | 908 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
909 | struct sta_info *sta; |
910 | int disassoc; | |
0795af57 | 911 | DECLARE_MAC_BUF(mac); |
f0706e82 JB |
912 | |
913 | /* TODO: start monitoring current AP signal quality and number of | |
914 | * missed beacons. Scan other channels every now and then and search | |
915 | * for better APs. */ | |
916 | /* TODO: remove expired BSSes */ | |
917 | ||
48c2fc59 | 918 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATED; |
f0706e82 | 919 | |
d0709a65 JB |
920 | rcu_read_lock(); |
921 | ||
f0706e82 JB |
922 | sta = sta_info_get(local, ifsta->bssid); |
923 | if (!sta) { | |
0795af57 | 924 | printk(KERN_DEBUG "%s: No STA entry for own AP %s\n", |
f698d856 | 925 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
f0706e82 JB |
926 | disassoc = 1; |
927 | } else { | |
928 | disassoc = 0; | |
929 | if (time_after(jiffies, | |
930 | sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { | |
d6f2da5b | 931 | if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) { |
f0706e82 | 932 | printk(KERN_DEBUG "%s: No ProbeResp from " |
0795af57 | 933 | "current AP %s - assume out of " |
f0706e82 | 934 | "range\n", |
f698d856 | 935 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
f0706e82 | 936 | disassoc = 1; |
d6f2da5b | 937 | } else |
f698d856 | 938 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
f0706e82 JB |
939 | local->scan_ssid, |
940 | local->scan_ssid_len); | |
d6f2da5b | 941 | ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL; |
f0706e82 | 942 | } else { |
d6f2da5b | 943 | ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL; |
f0706e82 JB |
944 | if (time_after(jiffies, ifsta->last_probe + |
945 | IEEE80211_PROBE_INTERVAL)) { | |
946 | ifsta->last_probe = jiffies; | |
f698d856 | 947 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
f0706e82 JB |
948 | ifsta->ssid, |
949 | ifsta->ssid_len); | |
950 | } | |
951 | } | |
f0706e82 | 952 | } |
d0709a65 JB |
953 | |
954 | rcu_read_unlock(); | |
955 | ||
60f8b39c JB |
956 | if (disassoc) |
957 | ieee80211_set_disassoc(sdata, ifsta, true, true, | |
958 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
959 | else | |
960 | mod_timer(&ifsta->timer, jiffies + | |
961 | IEEE80211_MONITORING_INTERVAL); | |
f0706e82 JB |
962 | } |
963 | ||
964 | ||
f698d856 | 965 | static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
966 | struct ieee80211_if_sta *ifsta) |
967 | { | |
f698d856 | 968 | printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name); |
d6f2da5b | 969 | ifsta->flags |= IEEE80211_STA_AUTHENTICATED; |
f698d856 | 970 | ieee80211_associate(sdata, ifsta); |
f0706e82 JB |
971 | } |
972 | ||
973 | ||
f698d856 | 974 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
975 | struct ieee80211_if_sta *ifsta, |
976 | struct ieee80211_mgmt *mgmt, | |
977 | size_t len) | |
978 | { | |
979 | u8 *pos; | |
980 | struct ieee802_11_elems elems; | |
981 | ||
f0706e82 | 982 | pos = mgmt->u.auth.variable; |
67a4cce4 | 983 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
f4ea83dd | 984 | if (!elems.challenge) |
f0706e82 | 985 | return; |
f698d856 | 986 | ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2, |
f0706e82 JB |
987 | elems.challenge_len + 2, 1); |
988 | } | |
989 | ||
f698d856 | 990 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
991 | struct ieee80211_if_sta *ifsta, |
992 | struct ieee80211_mgmt *mgmt, | |
993 | size_t len) | |
994 | { | |
f0706e82 | 995 | u16 auth_alg, auth_transaction, status_code; |
0795af57 | 996 | DECLARE_MAC_BUF(mac); |
f0706e82 | 997 | |
48c2fc59 | 998 | if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && |
f4ea83dd | 999 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) |
f0706e82 | 1000 | return; |
f0706e82 | 1001 | |
f4ea83dd | 1002 | if (len < 24 + 6) |
f0706e82 | 1003 | return; |
f0706e82 | 1004 | |
51fb61e7 | 1005 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
f4ea83dd | 1006 | memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
f0706e82 | 1007 | return; |
f0706e82 | 1008 | |
51fb61e7 | 1009 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
f4ea83dd | 1010 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
f0706e82 | 1011 | return; |
f0706e82 JB |
1012 | |
1013 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); | |
1014 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); | |
1015 | status_code = le16_to_cpu(mgmt->u.auth.status_code); | |
1016 | ||
51fb61e7 | 1017 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
135a2110 JB |
1018 | /* |
1019 | * IEEE 802.11 standard does not require authentication in IBSS | |
f0706e82 JB |
1020 | * networks and most implementations do not seem to use it. |
1021 | * However, try to reply to authentication attempts if someone | |
1022 | * has actually implemented this. | |
135a2110 | 1023 | */ |
f4ea83dd | 1024 | if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) |
f0706e82 | 1025 | return; |
f698d856 | 1026 | ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0); |
f0706e82 JB |
1027 | } |
1028 | ||
1029 | if (auth_alg != ifsta->auth_alg || | |
f4ea83dd | 1030 | auth_transaction != ifsta->auth_transaction) |
f0706e82 | 1031 | return; |
f0706e82 JB |
1032 | |
1033 | if (status_code != WLAN_STATUS_SUCCESS) { | |
f0706e82 JB |
1034 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { |
1035 | u8 algs[3]; | |
1036 | const int num_algs = ARRAY_SIZE(algs); | |
1037 | int i, pos; | |
1038 | algs[0] = algs[1] = algs[2] = 0xff; | |
1039 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) | |
1040 | algs[0] = WLAN_AUTH_OPEN; | |
1041 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) | |
1042 | algs[1] = WLAN_AUTH_SHARED_KEY; | |
1043 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) | |
1044 | algs[2] = WLAN_AUTH_LEAP; | |
1045 | if (ifsta->auth_alg == WLAN_AUTH_OPEN) | |
1046 | pos = 0; | |
1047 | else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY) | |
1048 | pos = 1; | |
1049 | else | |
1050 | pos = 2; | |
1051 | for (i = 0; i < num_algs; i++) { | |
1052 | pos++; | |
1053 | if (pos >= num_algs) | |
1054 | pos = 0; | |
1055 | if (algs[pos] == ifsta->auth_alg || | |
1056 | algs[pos] == 0xff) | |
1057 | continue; | |
1058 | if (algs[pos] == WLAN_AUTH_SHARED_KEY && | |
f698d856 | 1059 | !ieee80211_sta_wep_configured(sdata)) |
f0706e82 JB |
1060 | continue; |
1061 | ifsta->auth_alg = algs[pos]; | |
f0706e82 JB |
1062 | break; |
1063 | } | |
1064 | } | |
1065 | return; | |
1066 | } | |
1067 | ||
1068 | switch (ifsta->auth_alg) { | |
1069 | case WLAN_AUTH_OPEN: | |
1070 | case WLAN_AUTH_LEAP: | |
f698d856 | 1071 | ieee80211_auth_completed(sdata, ifsta); |
f0706e82 JB |
1072 | break; |
1073 | case WLAN_AUTH_SHARED_KEY: | |
1074 | if (ifsta->auth_transaction == 4) | |
f698d856 | 1075 | ieee80211_auth_completed(sdata, ifsta); |
f0706e82 | 1076 | else |
f698d856 | 1077 | ieee80211_auth_challenge(sdata, ifsta, mgmt, len); |
f0706e82 JB |
1078 | break; |
1079 | } | |
1080 | } | |
1081 | ||
1082 | ||
f698d856 | 1083 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1084 | struct ieee80211_if_sta *ifsta, |
1085 | struct ieee80211_mgmt *mgmt, | |
1086 | size_t len) | |
1087 | { | |
1088 | u16 reason_code; | |
0795af57 | 1089 | DECLARE_MAC_BUF(mac); |
f0706e82 | 1090 | |
f4ea83dd | 1091 | if (len < 24 + 2) |
f0706e82 | 1092 | return; |
f0706e82 | 1093 | |
f4ea83dd | 1094 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
f0706e82 | 1095 | return; |
f0706e82 JB |
1096 | |
1097 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | |
1098 | ||
988c0f72 | 1099 | if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) |
f698d856 | 1100 | printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name); |
f0706e82 | 1101 | |
48c2fc59 TW |
1102 | if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE || |
1103 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATE || | |
1104 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { | |
9859b81e | 1105 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
f0706e82 JB |
1106 | mod_timer(&ifsta->timer, jiffies + |
1107 | IEEE80211_RETRY_AUTH_INTERVAL); | |
1108 | } | |
1109 | ||
aa458d17 | 1110 | ieee80211_set_disassoc(sdata, ifsta, true, false, 0); |
d6f2da5b | 1111 | ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED; |
f0706e82 JB |
1112 | } |
1113 | ||
1114 | ||
f698d856 | 1115 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1116 | struct ieee80211_if_sta *ifsta, |
1117 | struct ieee80211_mgmt *mgmt, | |
1118 | size_t len) | |
1119 | { | |
1120 | u16 reason_code; | |
0795af57 | 1121 | DECLARE_MAC_BUF(mac); |
f0706e82 | 1122 | |
f4ea83dd | 1123 | if (len < 24 + 2) |
f0706e82 | 1124 | return; |
f0706e82 | 1125 | |
f4ea83dd | 1126 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
f0706e82 | 1127 | return; |
f0706e82 JB |
1128 | |
1129 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); | |
1130 | ||
d6f2da5b | 1131 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
f698d856 | 1132 | printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name); |
f0706e82 | 1133 | |
48c2fc59 TW |
1134 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { |
1135 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; | |
f0706e82 JB |
1136 | mod_timer(&ifsta->timer, jiffies + |
1137 | IEEE80211_RETRY_AUTH_INTERVAL); | |
1138 | } | |
1139 | ||
aa458d17 | 1140 | ieee80211_set_disassoc(sdata, ifsta, false, false, 0); |
f0706e82 JB |
1141 | } |
1142 | ||
1143 | ||
471b3efd | 1144 | static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1145 | struct ieee80211_if_sta *ifsta, |
1146 | struct ieee80211_mgmt *mgmt, | |
1147 | size_t len, | |
1148 | int reassoc) | |
1149 | { | |
471b3efd | 1150 | struct ieee80211_local *local = sdata->local; |
8318d78a | 1151 | struct ieee80211_supported_band *sband; |
f0706e82 | 1152 | struct sta_info *sta; |
8318d78a | 1153 | u64 rates, basic_rates; |
f0706e82 JB |
1154 | u16 capab_info, status_code, aid; |
1155 | struct ieee802_11_elems elems; | |
471b3efd | 1156 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
f0706e82 JB |
1157 | u8 *pos; |
1158 | int i, j; | |
0795af57 | 1159 | DECLARE_MAC_BUF(mac); |
8318d78a | 1160 | bool have_higher_than_11mbit = false; |
f0706e82 JB |
1161 | |
1162 | /* AssocResp and ReassocResp have identical structure, so process both | |
1163 | * of them in this function. */ | |
1164 | ||
48c2fc59 | 1165 | if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE) |
f0706e82 | 1166 | return; |
f0706e82 | 1167 | |
f4ea83dd | 1168 | if (len < 24 + 6) |
f0706e82 | 1169 | return; |
f0706e82 | 1170 | |
f4ea83dd | 1171 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
f0706e82 | 1172 | return; |
f0706e82 JB |
1173 | |
1174 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); | |
1175 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); | |
1176 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); | |
f0706e82 | 1177 | |
0795af57 | 1178 | printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x " |
f0706e82 | 1179 | "status=%d aid=%d)\n", |
f698d856 | 1180 | sdata->dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa), |
ddd68587 | 1181 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
f0706e82 JB |
1182 | |
1183 | if (status_code != WLAN_STATUS_SUCCESS) { | |
1184 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", | |
f698d856 | 1185 | sdata->dev->name, status_code); |
8a69aa93 DD |
1186 | /* if this was a reassociation, ensure we try a "full" |
1187 | * association next time. This works around some broken APs | |
1188 | * which do not correctly reject reassociation requests. */ | |
d6f2da5b | 1189 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
f0706e82 JB |
1190 | return; |
1191 | } | |
1192 | ||
1dd84aa2 JB |
1193 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
1194 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " | |
f698d856 | 1195 | "set\n", sdata->dev->name, aid); |
1dd84aa2 JB |
1196 | aid &= ~(BIT(15) | BIT(14)); |
1197 | ||
f0706e82 | 1198 | pos = mgmt->u.assoc_resp.variable; |
67a4cce4 | 1199 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
f0706e82 JB |
1200 | |
1201 | if (!elems.supp_rates) { | |
1202 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", | |
f698d856 | 1203 | sdata->dev->name); |
f0706e82 JB |
1204 | return; |
1205 | } | |
1206 | ||
f698d856 | 1207 | printk(KERN_DEBUG "%s: associated\n", sdata->dev->name); |
f0706e82 JB |
1208 | ifsta->aid = aid; |
1209 | ifsta->ap_capab = capab_info; | |
1210 | ||
1211 | kfree(ifsta->assocresp_ies); | |
1212 | ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt); | |
0ec0b7ac | 1213 | ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL); |
f0706e82 JB |
1214 | if (ifsta->assocresp_ies) |
1215 | memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); | |
1216 | ||
d0709a65 JB |
1217 | rcu_read_lock(); |
1218 | ||
f0706e82 JB |
1219 | /* Add STA entry for the AP */ |
1220 | sta = sta_info_get(local, ifsta->bssid); | |
1221 | if (!sta) { | |
1222 | struct ieee80211_sta_bss *bss; | |
73651ee6 | 1223 | int err; |
d0709a65 | 1224 | |
73651ee6 JB |
1225 | sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC); |
1226 | if (!sta) { | |
1227 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" | |
f698d856 | 1228 | " the AP\n", sdata->dev->name); |
d0709a65 | 1229 | rcu_read_unlock(); |
f0706e82 JB |
1230 | return; |
1231 | } | |
60f8b39c JB |
1232 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
1233 | local->hw.conf.channel->center_freq, | |
1234 | ifsta->ssid, ifsta->ssid_len); | |
1235 | if (bss) { | |
1236 | sta->last_signal = bss->signal; | |
1237 | sta->last_qual = bss->qual; | |
1238 | sta->last_noise = bss->noise; | |
1239 | ieee80211_rx_bss_put(local, bss); | |
1240 | } | |
f709fc69 | 1241 | |
60f8b39c JB |
1242 | err = sta_info_insert(sta); |
1243 | if (err) { | |
1244 | printk(KERN_DEBUG "%s: failed to insert STA entry for" | |
1245 | " the AP (error %d)\n", sdata->dev->name, err); | |
1246 | rcu_read_unlock(); | |
1247 | return; | |
f709fc69 | 1248 | } |
60f8b39c JB |
1249 | /* update new sta with its last rx activity */ |
1250 | sta->last_rx = jiffies; | |
f709fc69 | 1251 | } |
f709fc69 | 1252 | |
60f8b39c JB |
1253 | /* |
1254 | * FIXME: Do we really need to update the sta_info's information here? | |
1255 | * We already know about the AP (we found it in our list) so it | |
1256 | * should already be filled with the right info, no? | |
1257 | * As is stands, all this is racy because typically we assume | |
1258 | * the information that is filled in here (except flags) doesn't | |
1259 | * change while a STA structure is alive. As such, it should move | |
1260 | * to between the sta_info_alloc() and sta_info_insert() above. | |
1261 | */ | |
f709fc69 | 1262 | |
60f8b39c JB |
1263 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | |
1264 | WLAN_STA_AUTHORIZED); | |
05e5e883 | 1265 | |
60f8b39c JB |
1266 | rates = 0; |
1267 | basic_rates = 0; | |
1268 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
f709fc69 | 1269 | |
60f8b39c JB |
1270 | for (i = 0; i < elems.supp_rates_len; i++) { |
1271 | int rate = (elems.supp_rates[i] & 0x7f) * 5; | |
f709fc69 | 1272 | |
60f8b39c JB |
1273 | if (rate > 110) |
1274 | have_higher_than_11mbit = true; | |
1275 | ||
1276 | for (j = 0; j < sband->n_bitrates; j++) { | |
1277 | if (sband->bitrates[j].bitrate == rate) | |
1278 | rates |= BIT(j); | |
1279 | if (elems.supp_rates[i] & 0x80) | |
1280 | basic_rates |= BIT(j); | |
f709fc69 | 1281 | } |
f709fc69 LCC |
1282 | } |
1283 | ||
60f8b39c JB |
1284 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
1285 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; | |
f0706e82 | 1286 | |
60f8b39c JB |
1287 | if (rate > 110) |
1288 | have_higher_than_11mbit = true; | |
f0706e82 | 1289 | |
60f8b39c JB |
1290 | for (j = 0; j < sband->n_bitrates; j++) { |
1291 | if (sband->bitrates[j].bitrate == rate) | |
1292 | rates |= BIT(j); | |
1293 | if (elems.ext_supp_rates[i] & 0x80) | |
1294 | basic_rates |= BIT(j); | |
1295 | } | |
1ebebea8 | 1296 | } |
f0706e82 | 1297 | |
60f8b39c JB |
1298 | sta->supp_rates[local->hw.conf.channel->band] = rates; |
1299 | sdata->basic_rates = basic_rates; | |
1300 | ||
1301 | /* cf. IEEE 802.11 9.2.12 */ | |
1302 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
1303 | have_higher_than_11mbit) | |
1304 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
1305 | else | |
1306 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
f0706e82 | 1307 | |
60f8b39c JB |
1308 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
1309 | (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { | |
1310 | struct ieee80211_ht_bss_info bss_info; | |
1311 | ieee80211_ht_cap_ie_to_ht_info( | |
1312 | (struct ieee80211_ht_cap *) | |
1313 | elems.ht_cap_elem, &sta->ht_info); | |
1314 | ieee80211_ht_addt_info_ie_to_ht_bss_info( | |
1315 | (struct ieee80211_ht_addt_info *) | |
1316 | elems.ht_info_elem, &bss_info); | |
1317 | ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info); | |
1318 | } | |
f0706e82 | 1319 | |
60f8b39c | 1320 | rate_control_rate_init(sta, local); |
f0706e82 | 1321 | |
60f8b39c JB |
1322 | if (elems.wmm_param) { |
1323 | set_sta_flags(sta, WLAN_STA_WME); | |
1324 | rcu_read_unlock(); | |
1325 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, | |
1326 | elems.wmm_param_len); | |
1327 | } else | |
1328 | rcu_read_unlock(); | |
f0706e82 | 1329 | |
60f8b39c JB |
1330 | /* set AID and assoc capability, |
1331 | * ieee80211_set_associated() will tell the driver */ | |
1332 | bss_conf->aid = aid; | |
1333 | bss_conf->assoc_capability = capab_info; | |
1334 | ieee80211_set_associated(sdata, ifsta); | |
f0706e82 | 1335 | |
60f8b39c | 1336 | ieee80211_associated(sdata, ifsta); |
f0706e82 JB |
1337 | } |
1338 | ||
1339 | ||
f698d856 | 1340 | static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
a607268a BR |
1341 | struct ieee80211_if_sta *ifsta, |
1342 | struct ieee80211_sta_bss *bss) | |
1343 | { | |
f698d856 | 1344 | struct ieee80211_local *local = sdata->local; |
a607268a BR |
1345 | int res, rates, i, j; |
1346 | struct sk_buff *skb; | |
1347 | struct ieee80211_mgmt *mgmt; | |
a607268a | 1348 | u8 *pos; |
a607268a | 1349 | struct ieee80211_supported_band *sband; |
507b06d0 | 1350 | union iwreq_data wrqu; |
a607268a BR |
1351 | |
1352 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
1353 | ||
1354 | /* Remove possible STA entries from other IBSS networks. */ | |
dc6676b7 | 1355 | sta_info_flush_delayed(sdata); |
a607268a BR |
1356 | |
1357 | if (local->ops->reset_tsf) { | |
1358 | /* Reset own TSF to allow time synchronization work. */ | |
1359 | local->ops->reset_tsf(local_to_hw(local)); | |
1360 | } | |
1361 | memcpy(ifsta->bssid, bss->bssid, ETH_ALEN); | |
9d139c81 | 1362 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); |
a607268a BR |
1363 | if (res) |
1364 | return res; | |
1365 | ||
1366 | local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10; | |
1367 | ||
a607268a BR |
1368 | sdata->drop_unencrypted = bss->capability & |
1369 | WLAN_CAPABILITY_PRIVACY ? 1 : 0; | |
1370 | ||
f698d856 | 1371 | res = ieee80211_set_freq(sdata, bss->freq); |
a607268a | 1372 | |
be038b37 AK |
1373 | if (res) |
1374 | return res; | |
a607268a | 1375 | |
9d139c81 | 1376 | /* Build IBSS probe response */ |
a607268a | 1377 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
9d139c81 | 1378 | if (skb) { |
a607268a BR |
1379 | skb_reserve(skb, local->hw.extra_tx_headroom); |
1380 | ||
1381 | mgmt = (struct ieee80211_mgmt *) | |
1382 | skb_put(skb, 24 + sizeof(mgmt->u.beacon)); | |
1383 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); | |
e7827a70 HH |
1384 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
1385 | IEEE80211_STYPE_PROBE_RESP); | |
a607268a | 1386 | memset(mgmt->da, 0xff, ETH_ALEN); |
f698d856 | 1387 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
a607268a BR |
1388 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
1389 | mgmt->u.beacon.beacon_int = | |
1390 | cpu_to_le16(local->hw.conf.beacon_int); | |
4faeb860 | 1391 | mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp); |
a607268a BR |
1392 | mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability); |
1393 | ||
1394 | pos = skb_put(skb, 2 + ifsta->ssid_len); | |
1395 | *pos++ = WLAN_EID_SSID; | |
1396 | *pos++ = ifsta->ssid_len; | |
1397 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); | |
1398 | ||
1399 | rates = bss->supp_rates_len; | |
1400 | if (rates > 8) | |
1401 | rates = 8; | |
1402 | pos = skb_put(skb, 2 + rates); | |
1403 | *pos++ = WLAN_EID_SUPP_RATES; | |
1404 | *pos++ = rates; | |
1405 | memcpy(pos, bss->supp_rates, rates); | |
1406 | ||
1407 | if (bss->band == IEEE80211_BAND_2GHZ) { | |
1408 | pos = skb_put(skb, 2 + 1); | |
1409 | *pos++ = WLAN_EID_DS_PARAMS; | |
1410 | *pos++ = 1; | |
1411 | *pos++ = ieee80211_frequency_to_channel(bss->freq); | |
1412 | } | |
1413 | ||
1414 | pos = skb_put(skb, 2 + 2); | |
1415 | *pos++ = WLAN_EID_IBSS_PARAMS; | |
1416 | *pos++ = 2; | |
1417 | /* FIX: set ATIM window based on scan results */ | |
1418 | *pos++ = 0; | |
1419 | *pos++ = 0; | |
1420 | ||
1421 | if (bss->supp_rates_len > 8) { | |
1422 | rates = bss->supp_rates_len - 8; | |
1423 | pos = skb_put(skb, 2 + rates); | |
1424 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
1425 | *pos++ = rates; | |
1426 | memcpy(pos, &bss->supp_rates[8], rates); | |
1427 | } | |
1428 | ||
9d139c81 | 1429 | ifsta->probe_resp = skb; |
e039fa4a | 1430 | |
9d139c81 JB |
1431 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
1432 | } | |
a607268a | 1433 | |
9d139c81 JB |
1434 | rates = 0; |
1435 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
1436 | for (i = 0; i < bss->supp_rates_len; i++) { | |
1437 | int bitrate = (bss->supp_rates[i] & 0x7f) * 5; | |
1438 | for (j = 0; j < sband->n_bitrates; j++) | |
1439 | if (sband->bitrates[j].bitrate == bitrate) | |
1440 | rates |= BIT(j); | |
a607268a | 1441 | } |
9d139c81 JB |
1442 | ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates; |
1443 | ||
b079ada7 | 1444 | ieee80211_sta_def_wmm_params(sdata, bss); |
a607268a | 1445 | |
48c2fc59 | 1446 | ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED; |
a607268a BR |
1447 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
1448 | ||
507b06d0 DW |
1449 | memset(&wrqu, 0, sizeof(wrqu)); |
1450 | memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); | |
f698d856 | 1451 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); |
a607268a BR |
1452 | |
1453 | return res; | |
1454 | } | |
1455 | ||
8e1535d5 EG |
1456 | static u64 ieee80211_sta_get_mandatory_rates(struct ieee80211_local *local, |
1457 | enum ieee80211_band band) | |
1458 | { | |
1459 | struct ieee80211_supported_band *sband; | |
1460 | struct ieee80211_rate *bitrates; | |
1461 | u64 mandatory_rates; | |
1462 | enum ieee80211_rate_flags mandatory_flag; | |
1463 | int i; | |
1464 | ||
1465 | sband = local->hw.wiphy->bands[band]; | |
1466 | if (!sband) { | |
1467 | WARN_ON(1); | |
1468 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
1469 | } | |
1470 | ||
1471 | if (band == IEEE80211_BAND_2GHZ) | |
1472 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; | |
1473 | else | |
1474 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; | |
1475 | ||
1476 | bitrates = sband->bitrates; | |
1477 | mandatory_rates = 0; | |
1478 | for (i = 0; i < sband->n_bitrates; i++) | |
1479 | if (bitrates[i].flags & mandatory_flag) | |
1480 | mandatory_rates |= BIT(i); | |
1481 | return mandatory_rates; | |
1482 | } | |
a607268a | 1483 | |
98c8fccf JB |
1484 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
1485 | struct ieee80211_mgmt *mgmt, | |
1486 | size_t len, | |
1487 | struct ieee80211_rx_status *rx_status, | |
1488 | struct ieee802_11_elems *elems, | |
1489 | bool beacon) | |
1490 | { | |
1491 | struct ieee80211_local *local = sdata->local; | |
1492 | int freq; | |
1493 | struct ieee80211_sta_bss *bss; | |
1494 | struct sta_info *sta; | |
1495 | struct ieee80211_channel *channel; | |
1496 | u64 beacon_timestamp, rx_timestamp; | |
1497 | u64 supp_rates = 0; | |
1498 | enum ieee80211_band band = rx_status->band; | |
1499 | DECLARE_MAC_BUF(mac); | |
1500 | DECLARE_MAC_BUF(mac2); | |
1501 | ||
1502 | if (elems->ds_params && elems->ds_params_len == 1) | |
1503 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); | |
1504 | else | |
1505 | freq = rx_status->freq; | |
1506 | ||
1507 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
1508 | ||
1509 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
1510 | return; | |
1511 | ||
98c8fccf JB |
1512 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems->supp_rates && |
1513 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { | |
1514 | supp_rates = ieee80211_sta_get_rates(local, elems, band); | |
1515 | ||
1516 | rcu_read_lock(); | |
1517 | ||
1518 | sta = sta_info_get(local, mgmt->sa); | |
1519 | if (sta) { | |
1520 | u64 prev_rates; | |
1521 | ||
1522 | prev_rates = sta->supp_rates[band]; | |
1523 | /* make sure mandatory rates are always added */ | |
1524 | sta->supp_rates[band] = supp_rates | | |
1525 | ieee80211_sta_get_mandatory_rates(local, band); | |
1526 | ||
1527 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
1528 | if (sta->supp_rates[band] != prev_rates) | |
1529 | printk(KERN_DEBUG "%s: updated supp_rates set " | |
1530 | "for %s based on beacon info (0x%llx | " | |
1531 | "0x%llx -> 0x%llx)\n", | |
1532 | sdata->dev->name, print_mac(mac, sta->addr), | |
1533 | (unsigned long long) prev_rates, | |
1534 | (unsigned long long) supp_rates, | |
1535 | (unsigned long long) sta->supp_rates[band]); | |
1536 | #endif | |
1537 | } else { | |
1538 | ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid, | |
1539 | mgmt->sa, supp_rates); | |
1540 | } | |
1541 | ||
1542 | rcu_read_unlock(); | |
1543 | } | |
1544 | ||
1545 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, | |
1546 | freq, beacon); | |
1547 | if (!bss) | |
1548 | return; | |
1549 | ||
1550 | /* was just updated in ieee80211_bss_info_update */ | |
1551 | beacon_timestamp = bss->timestamp; | |
1552 | ||
30b89b0f JB |
1553 | /* |
1554 | * In STA mode, the remaining parameters should not be overridden | |
1555 | * by beacons because they're not necessarily accurate there. | |
1556 | */ | |
1557 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && | |
9859b81e | 1558 | bss->last_probe_resp && beacon) { |
3e122be0 | 1559 | ieee80211_rx_bss_put(local, bss); |
30b89b0f JB |
1560 | return; |
1561 | } | |
1562 | ||
9d9bf77d BR |
1563 | /* check if we need to merge IBSS */ |
1564 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon && | |
fba4a1e6 | 1565 | bss->capability & WLAN_CAPABILITY_IBSS && |
9d9bf77d | 1566 | bss->freq == local->oper_channel->center_freq && |
ae6a44e3 EK |
1567 | elems->ssid_len == sdata->u.sta.ssid_len && |
1568 | memcmp(elems->ssid, sdata->u.sta.ssid, | |
1569 | sdata->u.sta.ssid_len) == 0) { | |
9d9bf77d BR |
1570 | if (rx_status->flag & RX_FLAG_TSFT) { |
1571 | /* in order for correct IBSS merging we need mactime | |
1572 | * | |
1573 | * since mactime is defined as the time the first data | |
1574 | * symbol of the frame hits the PHY, and the timestamp | |
1575 | * of the beacon is defined as "the time that the data | |
1576 | * symbol containing the first bit of the timestamp is | |
1577 | * transmitted to the PHY plus the transmitting STA’s | |
1578 | * delays through its local PHY from the MAC-PHY | |
1579 | * interface to its interface with the WM" | |
1580 | * (802.11 11.1.2) - equals the time this bit arrives at | |
1581 | * the receiver - we have to take into account the | |
1582 | * offset between the two. | |
1583 | * e.g: at 1 MBit that means mactime is 192 usec earlier | |
1584 | * (=24 bytes * 8 usecs/byte) than the beacon timestamp. | |
1585 | */ | |
8e1535d5 | 1586 | int rate = local->hw.wiphy->bands[band]-> |
9d9bf77d BR |
1587 | bitrates[rx_status->rate_idx].bitrate; |
1588 | rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); | |
1589 | } else if (local && local->ops && local->ops->get_tsf) | |
1590 | /* second best option: get current TSF */ | |
1591 | rx_timestamp = local->ops->get_tsf(local_to_hw(local)); | |
1592 | else | |
1593 | /* can't merge without knowing the TSF */ | |
1594 | rx_timestamp = -1LLU; | |
1595 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
1596 | printk(KERN_DEBUG "RX beacon SA=%s BSSID=" | |
1597 | "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", | |
1598 | print_mac(mac, mgmt->sa), | |
1599 | print_mac(mac2, mgmt->bssid), | |
1600 | (unsigned long long)rx_timestamp, | |
1601 | (unsigned long long)beacon_timestamp, | |
1602 | (unsigned long long)(rx_timestamp - beacon_timestamp), | |
1603 | jiffies); | |
1604 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | |
1605 | if (beacon_timestamp > rx_timestamp) { | |
576fdeae | 1606 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
f4ea83dd JB |
1607 | printk(KERN_DEBUG "%s: beacon TSF higher than " |
1608 | "local TSF - IBSS merge with BSSID %s\n", | |
f698d856 | 1609 | sdata->dev->name, print_mac(mac, mgmt->bssid)); |
fba4a1e6 | 1610 | #endif |
f698d856 JBG |
1611 | ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss); |
1612 | ieee80211_ibss_add_sta(sdata, NULL, | |
87291c02 | 1613 | mgmt->bssid, mgmt->sa, |
8e1535d5 | 1614 | supp_rates); |
9d9bf77d BR |
1615 | } |
1616 | } | |
1617 | ||
3e122be0 | 1618 | ieee80211_rx_bss_put(local, bss); |
f0706e82 JB |
1619 | } |
1620 | ||
1621 | ||
f698d856 | 1622 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1623 | struct ieee80211_mgmt *mgmt, |
1624 | size_t len, | |
1625 | struct ieee80211_rx_status *rx_status) | |
1626 | { | |
ae6a44e3 EK |
1627 | size_t baselen; |
1628 | struct ieee802_11_elems elems; | |
9859b81e | 1629 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
ae6a44e3 | 1630 | |
8e7cdbb6 TW |
1631 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) |
1632 | return; /* ignore ProbeResp to foreign address */ | |
1633 | ||
ae6a44e3 EK |
1634 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
1635 | if (baselen > len) | |
1636 | return; | |
1637 | ||
1638 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
1639 | &elems); | |
1640 | ||
98c8fccf | 1641 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
9859b81e RR |
1642 | |
1643 | /* direct probe may be part of the association flow */ | |
1644 | if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE, | |
1645 | &ifsta->request)) { | |
1646 | printk(KERN_DEBUG "%s direct probe responded\n", | |
1647 | sdata->dev->name); | |
1648 | ieee80211_authenticate(sdata, ifsta); | |
1649 | } | |
f0706e82 JB |
1650 | } |
1651 | ||
1652 | ||
f698d856 | 1653 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1654 | struct ieee80211_mgmt *mgmt, |
1655 | size_t len, | |
1656 | struct ieee80211_rx_status *rx_status) | |
1657 | { | |
f0706e82 | 1658 | struct ieee80211_if_sta *ifsta; |
f0706e82 JB |
1659 | size_t baselen; |
1660 | struct ieee802_11_elems elems; | |
f698d856 | 1661 | struct ieee80211_local *local = sdata->local; |
d3c990fb | 1662 | struct ieee80211_conf *conf = &local->hw.conf; |
471b3efd | 1663 | u32 changed = 0; |
f0706e82 | 1664 | |
ae6a44e3 EK |
1665 | /* Process beacon from the current BSS */ |
1666 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | |
1667 | if (baselen > len) | |
1668 | return; | |
1669 | ||
1670 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); | |
1671 | ||
98c8fccf | 1672 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true); |
f0706e82 | 1673 | |
51fb61e7 | 1674 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
f0706e82 JB |
1675 | return; |
1676 | ifsta = &sdata->u.sta; | |
1677 | ||
d6f2da5b | 1678 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) || |
f0706e82 JB |
1679 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
1680 | return; | |
1681 | ||
fe3fa827 JB |
1682 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, |
1683 | elems.wmm_param_len); | |
1684 | ||
5628221c | 1685 | if (elems.erp_info && elems.erp_info_len >= 1) |
471b3efd | 1686 | changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]); |
50c4afb9 JL |
1687 | else { |
1688 | u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info); | |
1689 | changed |= ieee80211_handle_protect_preamb(sdata, false, | |
1690 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); | |
1691 | } | |
f0706e82 | 1692 | |
d3c990fb | 1693 | if (elems.ht_cap_elem && elems.ht_info_elem && |
38668c05 | 1694 | elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
d3c990fb RR |
1695 | struct ieee80211_ht_bss_info bss_info; |
1696 | ||
1697 | ieee80211_ht_addt_info_ie_to_ht_bss_info( | |
1698 | (struct ieee80211_ht_addt_info *) | |
1699 | elems.ht_info_elem, &bss_info); | |
38668c05 TW |
1700 | changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf, |
1701 | &bss_info); | |
d3c990fb RR |
1702 | } |
1703 | ||
471b3efd | 1704 | ieee80211_bss_info_change_notify(sdata, changed); |
f0706e82 JB |
1705 | } |
1706 | ||
1707 | ||
f698d856 | 1708 | static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1709 | struct ieee80211_if_sta *ifsta, |
1710 | struct ieee80211_mgmt *mgmt, | |
1711 | size_t len, | |
1712 | struct ieee80211_rx_status *rx_status) | |
1713 | { | |
f698d856 | 1714 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1715 | int tx_last_beacon; |
1716 | struct sk_buff *skb; | |
1717 | struct ieee80211_mgmt *resp; | |
1718 | u8 *pos, *end; | |
0795af57 JP |
1719 | DECLARE_MAC_BUF(mac); |
1720 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
1721 | DECLARE_MAC_BUF(mac2); | |
1722 | DECLARE_MAC_BUF(mac3); | |
1723 | #endif | |
f0706e82 | 1724 | |
51fb61e7 | 1725 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS || |
48c2fc59 | 1726 | ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED || |
f0706e82 JB |
1727 | len < 24 + 2 || !ifsta->probe_resp) |
1728 | return; | |
1729 | ||
1730 | if (local->ops->tx_last_beacon) | |
1731 | tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local)); | |
1732 | else | |
1733 | tx_last_beacon = 1; | |
1734 | ||
1735 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
0795af57 JP |
1736 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID=" |
1737 | "%s (tx_last_beacon=%d)\n", | |
f698d856 | 1738 | sdata->dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da), |
0795af57 | 1739 | print_mac(mac3, mgmt->bssid), tx_last_beacon); |
f0706e82 JB |
1740 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
1741 | ||
1742 | if (!tx_last_beacon) | |
1743 | return; | |
1744 | ||
1745 | if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 && | |
1746 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) | |
1747 | return; | |
1748 | ||
1749 | end = ((u8 *) mgmt) + len; | |
1750 | pos = mgmt->u.probe_req.variable; | |
1751 | if (pos[0] != WLAN_EID_SSID || | |
1752 | pos + 2 + pos[1] > end) { | |
f4ea83dd JB |
1753 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
1754 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " | |
1755 | "from %s\n", | |
f698d856 | 1756 | sdata->dev->name, print_mac(mac, mgmt->sa)); |
f4ea83dd | 1757 | #endif |
f0706e82 JB |
1758 | return; |
1759 | } | |
1760 | if (pos[1] != 0 && | |
1761 | (pos[1] != ifsta->ssid_len || | |
1762 | memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) { | |
1763 | /* Ignore ProbeReq for foreign SSID */ | |
1764 | return; | |
1765 | } | |
1766 | ||
1767 | /* Reply with ProbeResp */ | |
0ec0b7ac | 1768 | skb = skb_copy(ifsta->probe_resp, GFP_KERNEL); |
f0706e82 JB |
1769 | if (!skb) |
1770 | return; | |
1771 | ||
1772 | resp = (struct ieee80211_mgmt *) skb->data; | |
1773 | memcpy(resp->da, mgmt->sa, ETH_ALEN); | |
1774 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
0795af57 | 1775 | printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n", |
f698d856 | 1776 | sdata->dev->name, print_mac(mac, resp->da)); |
f0706e82 | 1777 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
e50db65c | 1778 | ieee80211_tx_skb(sdata, skb, 0); |
f0706e82 JB |
1779 | } |
1780 | ||
f698d856 | 1781 | void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
f0706e82 JB |
1782 | struct ieee80211_rx_status *rx_status) |
1783 | { | |
f698d856 | 1784 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1785 | struct ieee80211_if_sta *ifsta; |
1786 | struct ieee80211_mgmt *mgmt; | |
1787 | u16 fc; | |
1788 | ||
1789 | if (skb->len < 24) | |
1790 | goto fail; | |
1791 | ||
f0706e82 JB |
1792 | ifsta = &sdata->u.sta; |
1793 | ||
1794 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
1795 | fc = le16_to_cpu(mgmt->frame_control); | |
1796 | ||
1797 | switch (fc & IEEE80211_FCTL_STYPE) { | |
1798 | case IEEE80211_STYPE_PROBE_REQ: | |
1799 | case IEEE80211_STYPE_PROBE_RESP: | |
1800 | case IEEE80211_STYPE_BEACON: | |
1801 | memcpy(skb->cb, rx_status, sizeof(*rx_status)); | |
1802 | case IEEE80211_STYPE_AUTH: | |
1803 | case IEEE80211_STYPE_ASSOC_RESP: | |
1804 | case IEEE80211_STYPE_REASSOC_RESP: | |
1805 | case IEEE80211_STYPE_DEAUTH: | |
1806 | case IEEE80211_STYPE_DISASSOC: | |
1807 | skb_queue_tail(&ifsta->skb_queue, skb); | |
1808 | queue_work(local->hw.workqueue, &ifsta->work); | |
1809 | return; | |
f0706e82 JB |
1810 | } |
1811 | ||
1812 | fail: | |
1813 | kfree_skb(skb); | |
1814 | } | |
1815 | ||
f698d856 | 1816 | static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1817 | struct sk_buff *skb) |
1818 | { | |
1819 | struct ieee80211_rx_status *rx_status; | |
f0706e82 JB |
1820 | struct ieee80211_if_sta *ifsta; |
1821 | struct ieee80211_mgmt *mgmt; | |
1822 | u16 fc; | |
1823 | ||
f0706e82 JB |
1824 | ifsta = &sdata->u.sta; |
1825 | ||
1826 | rx_status = (struct ieee80211_rx_status *) skb->cb; | |
1827 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
1828 | fc = le16_to_cpu(mgmt->frame_control); | |
1829 | ||
1830 | switch (fc & IEEE80211_FCTL_STYPE) { | |
1831 | case IEEE80211_STYPE_PROBE_REQ: | |
f698d856 | 1832 | ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len, |
f0706e82 JB |
1833 | rx_status); |
1834 | break; | |
1835 | case IEEE80211_STYPE_PROBE_RESP: | |
f698d856 | 1836 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status); |
f0706e82 JB |
1837 | break; |
1838 | case IEEE80211_STYPE_BEACON: | |
f698d856 | 1839 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
f0706e82 JB |
1840 | break; |
1841 | case IEEE80211_STYPE_AUTH: | |
f698d856 | 1842 | ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len); |
f0706e82 JB |
1843 | break; |
1844 | case IEEE80211_STYPE_ASSOC_RESP: | |
471b3efd | 1845 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0); |
f0706e82 JB |
1846 | break; |
1847 | case IEEE80211_STYPE_REASSOC_RESP: | |
471b3efd | 1848 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1); |
f0706e82 JB |
1849 | break; |
1850 | case IEEE80211_STYPE_DEAUTH: | |
f698d856 | 1851 | ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len); |
f0706e82 JB |
1852 | break; |
1853 | case IEEE80211_STYPE_DISASSOC: | |
f698d856 | 1854 | ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len); |
f0706e82 JB |
1855 | break; |
1856 | } | |
1857 | ||
1858 | kfree_skb(skb); | |
1859 | } | |
1860 | ||
1861 | ||
f698d856 | 1862 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) |
f0706e82 | 1863 | { |
f698d856 | 1864 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1865 | int active = 0; |
1866 | struct sta_info *sta; | |
1867 | ||
d0709a65 JB |
1868 | rcu_read_lock(); |
1869 | ||
1870 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | |
1871 | if (sta->sdata == sdata && | |
f0706e82 JB |
1872 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
1873 | jiffies)) { | |
1874 | active++; | |
1875 | break; | |
1876 | } | |
1877 | } | |
d0709a65 JB |
1878 | |
1879 | rcu_read_unlock(); | |
f0706e82 JB |
1880 | |
1881 | return active; | |
1882 | } | |
1883 | ||
1884 | ||
f698d856 | 1885 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1886 | struct ieee80211_if_sta *ifsta) |
1887 | { | |
1888 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); | |
1889 | ||
f698d856 JBG |
1890 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); |
1891 | if (ieee80211_sta_active_ibss(sdata)) | |
f0706e82 JB |
1892 | return; |
1893 | ||
1894 | printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " | |
f698d856 JBG |
1895 | "IBSS networks with same SSID (merge)\n", sdata->dev->name); |
1896 | ieee80211_sta_req_scan(sdata, ifsta->ssid, ifsta->ssid_len); | |
f0706e82 JB |
1897 | } |
1898 | ||
1899 | ||
9c6bd790 | 1900 | static void ieee80211_sta_timer(unsigned long data) |
f0706e82 | 1901 | { |
60f8b39c JB |
1902 | struct ieee80211_sub_if_data *sdata = |
1903 | (struct ieee80211_sub_if_data *) data; | |
1904 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | |
1905 | struct ieee80211_local *local = sdata->local; | |
f0706e82 | 1906 | |
60f8b39c JB |
1907 | set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
1908 | queue_work(local->hw.workqueue, &ifsta->work); | |
f0706e82 JB |
1909 | } |
1910 | ||
f698d856 | 1911 | static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1912 | struct ieee80211_if_sta *ifsta) |
1913 | { | |
f698d856 | 1914 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1915 | |
1916 | if (local->ops->reset_tsf) { | |
1917 | /* Reset own TSF to allow time synchronization work. */ | |
1918 | local->ops->reset_tsf(local_to_hw(local)); | |
1919 | } | |
1920 | ||
1921 | ifsta->wmm_last_param_set = -1; /* allow any WMM update */ | |
1922 | ||
1923 | ||
1924 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) | |
1925 | ifsta->auth_alg = WLAN_AUTH_OPEN; | |
1926 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) | |
1927 | ifsta->auth_alg = WLAN_AUTH_SHARED_KEY; | |
1928 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) | |
1929 | ifsta->auth_alg = WLAN_AUTH_LEAP; | |
1930 | else | |
1931 | ifsta->auth_alg = WLAN_AUTH_OPEN; | |
f0706e82 | 1932 | ifsta->auth_transaction = -1; |
d6f2da5b | 1933 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
6042a3e3 | 1934 | ifsta->assoc_scan_tries = 0; |
9859b81e | 1935 | ifsta->direct_probe_tries = 0; |
6042a3e3 RR |
1936 | ifsta->auth_tries = 0; |
1937 | ifsta->assoc_tries = 0; | |
24e64622 | 1938 | netif_tx_stop_all_queues(sdata->dev); |
f698d856 | 1939 | netif_carrier_off(sdata->dev); |
f0706e82 JB |
1940 | } |
1941 | ||
1942 | ||
f0706e82 JB |
1943 | static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, |
1944 | const char *ssid, int ssid_len) | |
1945 | { | |
1946 | int tmp, hidden_ssid; | |
1947 | ||
48225709 MW |
1948 | if (ssid_len == ifsta->ssid_len && |
1949 | !memcmp(ifsta->ssid, ssid, ssid_len)) | |
f0706e82 JB |
1950 | return 1; |
1951 | ||
d6f2da5b | 1952 | if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) |
f0706e82 JB |
1953 | return 0; |
1954 | ||
1955 | hidden_ssid = 1; | |
1956 | tmp = ssid_len; | |
1957 | while (tmp--) { | |
1958 | if (ssid[tmp] != '\0') { | |
1959 | hidden_ssid = 0; | |
1960 | break; | |
1961 | } | |
1962 | } | |
1963 | ||
1964 | if (hidden_ssid && ifsta->ssid_len == ssid_len) | |
1965 | return 1; | |
1966 | ||
1967 | if (ssid_len == 1 && ssid[0] == ' ') | |
1968 | return 1; | |
1969 | ||
1970 | return 0; | |
1971 | } | |
1972 | ||
f698d856 | 1973 | static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1974 | struct ieee80211_if_sta *ifsta) |
1975 | { | |
f698d856 | 1976 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 1977 | struct ieee80211_sta_bss *bss; |
8318d78a | 1978 | struct ieee80211_supported_band *sband; |
f0706e82 JB |
1979 | u8 bssid[ETH_ALEN], *pos; |
1980 | int i; | |
167ad6f7 | 1981 | int ret; |
0795af57 | 1982 | DECLARE_MAC_BUF(mac); |
f0706e82 JB |
1983 | |
1984 | #if 0 | |
1985 | /* Easier testing, use fixed BSSID. */ | |
1986 | memset(bssid, 0xfe, ETH_ALEN); | |
1987 | #else | |
1988 | /* Generate random, not broadcast, locally administered BSSID. Mix in | |
1989 | * own MAC address to make sure that devices that do not have proper | |
1990 | * random number generator get different BSSID. */ | |
1991 | get_random_bytes(bssid, ETH_ALEN); | |
1992 | for (i = 0; i < ETH_ALEN; i++) | |
f698d856 | 1993 | bssid[i] ^= sdata->dev->dev_addr[i]; |
f0706e82 JB |
1994 | bssid[0] &= ~0x01; |
1995 | bssid[0] |= 0x02; | |
1996 | #endif | |
1997 | ||
0795af57 | 1998 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", |
f698d856 | 1999 | sdata->dev->name, print_mac(mac, bssid)); |
f0706e82 | 2000 | |
98c8fccf | 2001 | bss = ieee80211_rx_bss_add(local, bssid, |
8318d78a | 2002 | local->hw.conf.channel->center_freq, |
cffdd30d | 2003 | sdata->u.sta.ssid, sdata->u.sta.ssid_len); |
f0706e82 JB |
2004 | if (!bss) |
2005 | return -ENOMEM; | |
2006 | ||
8318d78a JB |
2007 | bss->band = local->hw.conf.channel->band; |
2008 | sband = local->hw.wiphy->bands[bss->band]; | |
f0706e82 JB |
2009 | |
2010 | if (local->hw.conf.beacon_int == 0) | |
dc0ae30c | 2011 | local->hw.conf.beacon_int = 100; |
f0706e82 | 2012 | bss->beacon_int = local->hw.conf.beacon_int; |
f0706e82 JB |
2013 | bss->last_update = jiffies; |
2014 | bss->capability = WLAN_CAPABILITY_IBSS; | |
988c0f72 JB |
2015 | |
2016 | if (sdata->default_key) | |
f0706e82 | 2017 | bss->capability |= WLAN_CAPABILITY_PRIVACY; |
988c0f72 | 2018 | else |
f0706e82 | 2019 | sdata->drop_unencrypted = 0; |
988c0f72 | 2020 | |
8318d78a | 2021 | bss->supp_rates_len = sband->n_bitrates; |
f0706e82 | 2022 | pos = bss->supp_rates; |
8318d78a JB |
2023 | for (i = 0; i < sband->n_bitrates; i++) { |
2024 | int rate = sband->bitrates[i].bitrate; | |
f0706e82 JB |
2025 | *pos++ = (u8) (rate / 5); |
2026 | } | |
2027 | ||
f698d856 | 2028 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); |
3e122be0 | 2029 | ieee80211_rx_bss_put(local, bss); |
167ad6f7 | 2030 | return ret; |
f0706e82 JB |
2031 | } |
2032 | ||
2033 | ||
f698d856 | 2034 | static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2035 | struct ieee80211_if_sta *ifsta) |
2036 | { | |
f698d856 | 2037 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
2038 | struct ieee80211_sta_bss *bss; |
2039 | int found = 0; | |
2040 | u8 bssid[ETH_ALEN]; | |
2041 | int active_ibss; | |
0795af57 JP |
2042 | DECLARE_MAC_BUF(mac); |
2043 | DECLARE_MAC_BUF(mac2); | |
f0706e82 JB |
2044 | |
2045 | if (ifsta->ssid_len == 0) | |
2046 | return -EINVAL; | |
2047 | ||
f698d856 | 2048 | active_ibss = ieee80211_sta_active_ibss(sdata); |
f0706e82 JB |
2049 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
2050 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", | |
f698d856 | 2051 | sdata->dev->name, active_ibss); |
f0706e82 JB |
2052 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
2053 | spin_lock_bh(&local->sta_bss_lock); | |
2054 | list_for_each_entry(bss, &local->sta_bss_list, list) { | |
2055 | if (ifsta->ssid_len != bss->ssid_len || | |
2056 | memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 | |
2057 | || !(bss->capability & WLAN_CAPABILITY_IBSS)) | |
2058 | continue; | |
2059 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
0795af57 JP |
2060 | printk(KERN_DEBUG " bssid=%s found\n", |
2061 | print_mac(mac, bss->bssid)); | |
f0706e82 JB |
2062 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
2063 | memcpy(bssid, bss->bssid, ETH_ALEN); | |
2064 | found = 1; | |
2065 | if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) | |
2066 | break; | |
2067 | } | |
2068 | spin_unlock_bh(&local->sta_bss_lock); | |
2069 | ||
2070 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
6e43829b VK |
2071 | if (found) |
2072 | printk(KERN_DEBUG " sta_find_ibss: selected %s current " | |
2073 | "%s\n", print_mac(mac, bssid), | |
2074 | print_mac(mac2, ifsta->bssid)); | |
f0706e82 | 2075 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
80693ceb DD |
2076 | |
2077 | if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { | |
167ad6f7 | 2078 | int ret; |
80693ceb DD |
2079 | int search_freq; |
2080 | ||
2081 | if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) | |
2082 | search_freq = bss->freq; | |
2083 | else | |
2084 | search_freq = local->hw.conf.channel->center_freq; | |
2085 | ||
f698d856 | 2086 | bss = ieee80211_rx_bss_get(local, bssid, search_freq, |
80693ceb DD |
2087 | ifsta->ssid, ifsta->ssid_len); |
2088 | if (!bss) | |
2089 | goto dont_join; | |
2090 | ||
0795af57 | 2091 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" |
f0706e82 | 2092 | " based on configured SSID\n", |
f698d856 JBG |
2093 | sdata->dev->name, print_mac(mac, bssid)); |
2094 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); | |
3e122be0 | 2095 | ieee80211_rx_bss_put(local, bss); |
167ad6f7 | 2096 | return ret; |
f0706e82 | 2097 | } |
80693ceb DD |
2098 | |
2099 | dont_join: | |
f0706e82 JB |
2100 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
2101 | printk(KERN_DEBUG " did not try to join ibss\n"); | |
2102 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | |
2103 | ||
2104 | /* Selected IBSS not found in current scan results - try to scan */ | |
48c2fc59 | 2105 | if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED && |
f698d856 | 2106 | !ieee80211_sta_active_ibss(sdata)) { |
f0706e82 JB |
2107 | mod_timer(&ifsta->timer, jiffies + |
2108 | IEEE80211_IBSS_MERGE_INTERVAL); | |
2109 | } else if (time_after(jiffies, local->last_scan_completed + | |
2110 | IEEE80211_SCAN_INTERVAL)) { | |
2111 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " | |
f698d856 JBG |
2112 | "join\n", sdata->dev->name); |
2113 | return ieee80211_sta_req_scan(sdata, ifsta->ssid, | |
f0706e82 | 2114 | ifsta->ssid_len); |
48c2fc59 | 2115 | } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) { |
f0706e82 JB |
2116 | int interval = IEEE80211_SCAN_INTERVAL; |
2117 | ||
2118 | if (time_after(jiffies, ifsta->ibss_join_req + | |
2119 | IEEE80211_IBSS_JOIN_TIMEOUT)) { | |
d6f2da5b | 2120 | if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && |
8318d78a JB |
2121 | (!(local->oper_channel->flags & |
2122 | IEEE80211_CHAN_NO_IBSS))) | |
f698d856 | 2123 | return ieee80211_sta_create_ibss(sdata, ifsta); |
d6f2da5b | 2124 | if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { |
8318d78a | 2125 | printk(KERN_DEBUG "%s: IBSS not allowed on" |
f698d856 | 2126 | " %d MHz\n", sdata->dev->name, |
8318d78a | 2127 | local->hw.conf.channel->center_freq); |
f0706e82 JB |
2128 | } |
2129 | ||
2130 | /* No IBSS found - decrease scan interval and continue | |
2131 | * scanning. */ | |
2132 | interval = IEEE80211_SCAN_INTERVAL_SLOW; | |
2133 | } | |
2134 | ||
48c2fc59 | 2135 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; |
f0706e82 JB |
2136 | mod_timer(&ifsta->timer, jiffies + interval); |
2137 | return 0; | |
2138 | } | |
2139 | ||
2140 | return 0; | |
2141 | } | |
2142 | ||
2143 | ||
9c6bd790 JB |
2144 | static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata, |
2145 | struct ieee80211_if_sta *ifsta) | |
f0706e82 | 2146 | { |
9c6bd790 JB |
2147 | struct ieee80211_local *local = sdata->local; |
2148 | struct ieee80211_sta_bss *bss, *selected = NULL; | |
2149 | int top_rssi = 0, freq; | |
f0706e82 | 2150 | |
9c6bd790 JB |
2151 | spin_lock_bh(&local->sta_bss_lock); |
2152 | freq = local->oper_channel->center_freq; | |
2153 | list_for_each_entry(bss, &local->sta_bss_list, list) { | |
2154 | if (!(bss->capability & WLAN_CAPABILITY_ESS)) | |
2155 | continue; | |
f0706e82 | 2156 | |
9c6bd790 JB |
2157 | if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL | |
2158 | IEEE80211_STA_AUTO_BSSID_SEL | | |
2159 | IEEE80211_STA_AUTO_CHANNEL_SEL)) && | |
2160 | (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^ | |
2161 | !!sdata->default_key)) | |
2162 | continue; | |
f0706e82 | 2163 | |
9c6bd790 JB |
2164 | if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) && |
2165 | bss->freq != freq) | |
2166 | continue; | |
9d139c81 | 2167 | |
9c6bd790 JB |
2168 | if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) && |
2169 | memcmp(bss->bssid, ifsta->bssid, ETH_ALEN)) | |
2170 | continue; | |
f0706e82 | 2171 | |
9c6bd790 JB |
2172 | if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) && |
2173 | !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len)) | |
2174 | continue; | |
9d139c81 | 2175 | |
9c6bd790 JB |
2176 | if (!selected || top_rssi < bss->signal) { |
2177 | selected = bss; | |
2178 | top_rssi = bss->signal; | |
2179 | } | |
f0706e82 | 2180 | } |
9c6bd790 JB |
2181 | if (selected) |
2182 | atomic_inc(&selected->users); | |
2183 | spin_unlock_bh(&local->sta_bss_lock); | |
9d139c81 | 2184 | |
9c6bd790 JB |
2185 | if (selected) { |
2186 | ieee80211_set_freq(sdata, selected->freq); | |
2187 | if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) | |
2188 | ieee80211_sta_set_ssid(sdata, selected->ssid, | |
2189 | selected->ssid_len); | |
2190 | ieee80211_sta_set_bssid(sdata, selected->bssid); | |
2191 | ieee80211_sta_def_wmm_params(sdata, selected); | |
f0706e82 | 2192 | |
9c6bd790 JB |
2193 | /* Send out direct probe if no probe resp was received or |
2194 | * the one we have is outdated | |
2195 | */ | |
2196 | if (!selected->last_probe_resp || | |
2197 | time_after(jiffies, selected->last_probe_resp | |
2198 | + IEEE80211_SCAN_RESULT_EXPIRE)) | |
2199 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; | |
2200 | else | |
2201 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; | |
f0706e82 | 2202 | |
9c6bd790 JB |
2203 | ieee80211_rx_bss_put(local, selected); |
2204 | ieee80211_sta_reset_auth(sdata, ifsta); | |
2205 | return 0; | |
2206 | } else { | |
2207 | if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { | |
2208 | ifsta->assoc_scan_tries++; | |
2209 | if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) | |
2210 | ieee80211_sta_start_scan(sdata, NULL, 0); | |
2211 | else | |
2212 | ieee80211_sta_start_scan(sdata, ifsta->ssid, | |
2213 | ifsta->ssid_len); | |
2214 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; | |
2215 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); | |
2216 | } else | |
2217 | ifsta->state = IEEE80211_STA_MLME_DISABLED; | |
2218 | } | |
2219 | return -1; | |
2220 | } | |
2221 | ||
2222 | ||
2223 | static void ieee80211_sta_work(struct work_struct *work) | |
2224 | { | |
2225 | struct ieee80211_sub_if_data *sdata = | |
2226 | container_of(work, struct ieee80211_sub_if_data, u.sta.work); | |
2227 | struct ieee80211_local *local = sdata->local; | |
2228 | struct ieee80211_if_sta *ifsta; | |
2229 | struct sk_buff *skb; | |
2230 | ||
2231 | if (!netif_running(sdata->dev)) | |
2232 | return; | |
2233 | ||
2234 | if (local->sta_sw_scanning || local->sta_hw_scanning) | |
2235 | return; | |
2236 | ||
2237 | if (WARN_ON(sdata->vif.type != IEEE80211_IF_TYPE_STA && | |
2238 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS)) | |
2239 | return; | |
f0706e82 JB |
2240 | ifsta = &sdata->u.sta; |
2241 | ||
9c6bd790 JB |
2242 | while ((skb = skb_dequeue(&ifsta->skb_queue))) |
2243 | ieee80211_sta_rx_queued_mgmt(sdata, skb); | |
2244 | ||
2245 | if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE && | |
2246 | ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && | |
2247 | ifsta->state != IEEE80211_STA_MLME_ASSOCIATE && | |
2248 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { | |
2249 | ieee80211_sta_start_scan(sdata, ifsta->scan_ssid, ifsta->scan_ssid_len); | |
2250 | return; | |
f0706e82 JB |
2251 | } |
2252 | ||
9c6bd790 JB |
2253 | if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) { |
2254 | if (ieee80211_sta_config_auth(sdata, ifsta)) | |
2255 | return; | |
2256 | clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); | |
2257 | } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request)) | |
2258 | return; | |
d6f2da5b | 2259 | |
9c6bd790 JB |
2260 | switch (ifsta->state) { |
2261 | case IEEE80211_STA_MLME_DISABLED: | |
2262 | break; | |
2263 | case IEEE80211_STA_MLME_DIRECT_PROBE: | |
2264 | ieee80211_direct_probe(sdata, ifsta); | |
2265 | break; | |
2266 | case IEEE80211_STA_MLME_AUTHENTICATE: | |
2267 | ieee80211_authenticate(sdata, ifsta); | |
2268 | break; | |
2269 | case IEEE80211_STA_MLME_ASSOCIATE: | |
2270 | ieee80211_associate(sdata, ifsta); | |
2271 | break; | |
2272 | case IEEE80211_STA_MLME_ASSOCIATED: | |
2273 | ieee80211_associated(sdata, ifsta); | |
2274 | break; | |
2275 | case IEEE80211_STA_MLME_IBSS_SEARCH: | |
2276 | ieee80211_sta_find_ibss(sdata, ifsta); | |
2277 | break; | |
2278 | case IEEE80211_STA_MLME_IBSS_JOINED: | |
2279 | ieee80211_sta_merge_ibss(sdata, ifsta); | |
2280 | break; | |
2281 | default: | |
2282 | WARN_ON(1); | |
2283 | break; | |
2284 | } | |
2285 | ||
2286 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { | |
2287 | printk(KERN_DEBUG "%s: privacy configuration mismatch and " | |
2288 | "mixed-cell disabled - disassociate\n", sdata->dev->name); | |
2289 | ||
2290 | ieee80211_set_disassoc(sdata, ifsta, false, true, | |
2291 | WLAN_REASON_UNSPECIFIED); | |
2292 | } | |
f0706e82 JB |
2293 | } |
2294 | ||
9c6bd790 JB |
2295 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
2296 | { | |
2297 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) | |
2298 | queue_work(sdata->local->hw.workqueue, | |
2299 | &sdata->u.sta.work); | |
2300 | } | |
f0706e82 | 2301 | |
9c6bd790 JB |
2302 | /* interface setup */ |
2303 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) | |
f0706e82 | 2304 | { |
9c6bd790 | 2305 | struct ieee80211_if_sta *ifsta; |
988c0f72 | 2306 | |
9c6bd790 JB |
2307 | ifsta = &sdata->u.sta; |
2308 | INIT_WORK(&ifsta->work, ieee80211_sta_work); | |
2309 | setup_timer(&ifsta->timer, ieee80211_sta_timer, | |
2310 | (unsigned long) sdata); | |
2311 | skb_queue_head_init(&ifsta->skb_queue); | |
2312 | ||
2313 | ifsta->capab = WLAN_CAPABILITY_ESS; | |
2314 | ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN | | |
2315 | IEEE80211_AUTH_ALG_SHARED_KEY; | |
2316 | ifsta->flags |= IEEE80211_STA_CREATE_IBSS | | |
2317 | IEEE80211_STA_AUTO_BSSID_SEL | | |
2318 | IEEE80211_STA_AUTO_CHANNEL_SEL; | |
2319 | if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4) | |
2320 | ifsta->flags |= IEEE80211_STA_WMM_ENABLED; | |
f0706e82 JB |
2321 | } |
2322 | ||
9c6bd790 JB |
2323 | /* |
2324 | * Add a new IBSS station, will also be called by the RX code when, | |
2325 | * in IBSS mode, receiving a frame from a yet-unknown station, hence | |
2326 | * must be callable in atomic context. | |
2327 | */ | |
f698d856 | 2328 | struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, |
988c0f72 | 2329 | struct sk_buff *skb, u8 *bssid, |
87291c02 | 2330 | u8 *addr, u64 supp_rates) |
f0706e82 | 2331 | { |
f698d856 | 2332 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 2333 | struct sta_info *sta; |
0795af57 | 2334 | DECLARE_MAC_BUF(mac); |
87291c02 | 2335 | int band = local->hw.conf.channel->band; |
f0706e82 JB |
2336 | |
2337 | /* TODO: Could consider removing the least recently used entry and | |
2338 | * allow new one to be added. */ | |
2339 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { | |
2340 | if (net_ratelimit()) { | |
2341 | printk(KERN_DEBUG "%s: No room for a new IBSS STA " | |
f698d856 | 2342 | "entry %s\n", sdata->dev->name, print_mac(mac, addr)); |
f0706e82 JB |
2343 | } |
2344 | return NULL; | |
2345 | } | |
2346 | ||
1e188637 | 2347 | if (compare_ether_addr(bssid, sdata->u.sta.bssid)) |
87291c02 VK |
2348 | return NULL; |
2349 | ||
f4ea83dd | 2350 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
0795af57 | 2351 | printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", |
f698d856 | 2352 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name); |
f4ea83dd | 2353 | #endif |
f0706e82 | 2354 | |
73651ee6 JB |
2355 | sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); |
2356 | if (!sta) | |
f0706e82 JB |
2357 | return NULL; |
2358 | ||
07346f81 | 2359 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); |
238814fd | 2360 | |
8e1535d5 EG |
2361 | /* make sure mandatory rates are always added */ |
2362 | sta->supp_rates[band] = supp_rates | | |
2363 | ieee80211_sta_get_mandatory_rates(local, band); | |
f0706e82 JB |
2364 | |
2365 | rate_control_rate_init(sta, local); | |
2366 | ||
93e5deb1 | 2367 | if (sta_info_insert(sta)) |
73651ee6 | 2368 | return NULL; |
73651ee6 | 2369 | |
d0709a65 | 2370 | return sta; |
f0706e82 JB |
2371 | } |
2372 | ||
9c6bd790 JB |
2373 | /* configuration hooks */ |
2374 | void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata, | |
2375 | struct ieee80211_if_sta *ifsta) | |
60f8b39c JB |
2376 | { |
2377 | struct ieee80211_local *local = sdata->local; | |
60f8b39c | 2378 | |
9c6bd790 JB |
2379 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
2380 | return; | |
60f8b39c | 2381 | |
9c6bd790 JB |
2382 | if ((ifsta->flags & (IEEE80211_STA_BSSID_SET | |
2383 | IEEE80211_STA_AUTO_BSSID_SEL)) && | |
2384 | (ifsta->flags & (IEEE80211_STA_SSID_SET | | |
2385 | IEEE80211_STA_AUTO_SSID_SEL))) { | |
60f8b39c | 2386 | |
9c6bd790 JB |
2387 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) |
2388 | ieee80211_set_disassoc(sdata, ifsta, true, true, | |
2389 | WLAN_REASON_DEAUTH_LEAVING); | |
60f8b39c | 2390 | |
9c6bd790 JB |
2391 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
2392 | queue_work(local->hw.workqueue, &ifsta->work); | |
2393 | } | |
2394 | } | |
60f8b39c | 2395 | |
9c6bd790 JB |
2396 | int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) |
2397 | { | |
2398 | struct ieee80211_if_sta *ifsta; | |
2399 | int res; | |
60f8b39c | 2400 | |
9c6bd790 JB |
2401 | if (len > IEEE80211_MAX_SSID_LEN) |
2402 | return -EINVAL; | |
2403 | ||
2404 | ifsta = &sdata->u.sta; | |
2405 | ||
2406 | if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) { | |
2407 | memset(ifsta->ssid, 0, sizeof(ifsta->ssid)); | |
2408 | memcpy(ifsta->ssid, ssid, len); | |
2409 | ifsta->ssid_len = len; | |
2410 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; | |
2411 | ||
2412 | res = 0; | |
2413 | /* | |
2414 | * Hack! MLME code needs to be cleaned up to have different | |
2415 | * entry points for configuration and internal selection change | |
2416 | */ | |
2417 | if (netif_running(sdata->dev)) | |
2418 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID); | |
2419 | if (res) { | |
2420 | printk(KERN_DEBUG "%s: Failed to config new SSID to " | |
2421 | "the low-level driver\n", sdata->dev->name); | |
2422 | return res; | |
60f8b39c JB |
2423 | } |
2424 | } | |
60f8b39c | 2425 | |
9c6bd790 JB |
2426 | if (len) |
2427 | ifsta->flags |= IEEE80211_STA_SSID_SET; | |
2428 | else | |
2429 | ifsta->flags &= ~IEEE80211_STA_SSID_SET; | |
60f8b39c | 2430 | |
9c6bd790 JB |
2431 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
2432 | !(ifsta->flags & IEEE80211_STA_BSSID_SET)) { | |
2433 | ifsta->ibss_join_req = jiffies; | |
2434 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; | |
2435 | return ieee80211_sta_find_ibss(sdata, ifsta); | |
2436 | } | |
2437 | ||
2438 | return 0; | |
2439 | } | |
2440 | ||
2441 | int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len) | |
2442 | { | |
2443 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | |
2444 | memcpy(ssid, ifsta->ssid, ifsta->ssid_len); | |
2445 | *len = ifsta->ssid_len; | |
2446 | return 0; | |
2447 | } | |
2448 | ||
2449 | int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) | |
2450 | { | |
2451 | struct ieee80211_if_sta *ifsta; | |
2452 | int res; | |
2453 | ||
2454 | ifsta = &sdata->u.sta; | |
2455 | ||
2456 | if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { | |
2457 | memcpy(ifsta->bssid, bssid, ETH_ALEN); | |
2458 | res = 0; | |
2459 | /* | |
2460 | * Hack! See also ieee80211_sta_set_ssid. | |
60f8b39c | 2461 | */ |
9c6bd790 JB |
2462 | if (netif_running(sdata->dev)) |
2463 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); | |
2464 | if (res) { | |
2465 | printk(KERN_DEBUG "%s: Failed to config new BSSID to " | |
2466 | "the low-level driver\n", sdata->dev->name); | |
2467 | return res; | |
2468 | } | |
2469 | } | |
60f8b39c | 2470 | |
9c6bd790 JB |
2471 | if (is_valid_ether_addr(bssid)) |
2472 | ifsta->flags |= IEEE80211_STA_BSSID_SET; | |
2473 | else | |
2474 | ifsta->flags &= ~IEEE80211_STA_BSSID_SET; | |
2475 | ||
2476 | return 0; | |
2477 | } | |
2478 | ||
2479 | int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len) | |
2480 | { | |
2481 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | |
2482 | ||
2483 | kfree(ifsta->extra_ie); | |
2484 | if (len == 0) { | |
2485 | ifsta->extra_ie = NULL; | |
2486 | ifsta->extra_ie_len = 0; | |
60f8b39c | 2487 | return 0; |
60f8b39c | 2488 | } |
9c6bd790 JB |
2489 | ifsta->extra_ie = kmalloc(len, GFP_KERNEL); |
2490 | if (!ifsta->extra_ie) { | |
2491 | ifsta->extra_ie_len = 0; | |
2492 | return -ENOMEM; | |
2493 | } | |
2494 | memcpy(ifsta->extra_ie, ie, len); | |
2495 | ifsta->extra_ie_len = len; | |
2496 | return 0; | |
60f8b39c JB |
2497 | } |
2498 | ||
f698d856 | 2499 | int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) |
f0706e82 | 2500 | { |
f0706e82 JB |
2501 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
2502 | ||
f4ea83dd | 2503 | printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", |
f698d856 | 2504 | sdata->dev->name, reason); |
f0706e82 | 2505 | |
51fb61e7 JB |
2506 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
2507 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) | |
f0706e82 JB |
2508 | return -EINVAL; |
2509 | ||
aa458d17 | 2510 | ieee80211_set_disassoc(sdata, ifsta, true, true, reason); |
f0706e82 JB |
2511 | return 0; |
2512 | } | |
2513 | ||
f698d856 | 2514 | int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason) |
f0706e82 | 2515 | { |
f0706e82 JB |
2516 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
2517 | ||
f4ea83dd | 2518 | printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", |
f698d856 | 2519 | sdata->dev->name, reason); |
f0706e82 | 2520 | |
51fb61e7 | 2521 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
f0706e82 JB |
2522 | return -EINVAL; |
2523 | ||
d6f2da5b | 2524 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED)) |
f0706e82 JB |
2525 | return -1; |
2526 | ||
aa458d17 | 2527 | ieee80211_set_disassoc(sdata, ifsta, false, true, reason); |
f0706e82 JB |
2528 | return 0; |
2529 | } | |
84363e6e | 2530 | |
9c6bd790 JB |
2531 | /* scan finished notification */ |
2532 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) | |
2533 | { | |
2534 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; | |
2535 | struct ieee80211_if_sta *ifsta; | |
2536 | ||
2537 | if (sdata && sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
2538 | ifsta = &sdata->u.sta; | |
2539 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || | |
2540 | (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) && | |
2541 | !ieee80211_sta_active_ibss(sdata))) | |
2542 | ieee80211_sta_find_ibss(sdata, ifsta); | |
2543 | } | |
2544 | ||
2545 | /* Restart STA timers */ | |
2546 | rcu_read_lock(); | |
2547 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
2548 | ieee80211_restart_sta_timer(sdata); | |
2549 | rcu_read_unlock(); | |
2550 | } | |
2551 | ||
2552 | /* driver notification call */ | |
84363e6e MA |
2553 | void ieee80211_notify_mac(struct ieee80211_hw *hw, |
2554 | enum ieee80211_notification_types notif_type) | |
2555 | { | |
2556 | struct ieee80211_local *local = hw_to_local(hw); | |
2557 | struct ieee80211_sub_if_data *sdata; | |
2558 | ||
2559 | switch (notif_type) { | |
2560 | case IEEE80211_NOTIFY_RE_ASSOC: | |
2561 | rcu_read_lock(); | |
2562 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
3e122be0 JB |
2563 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
2564 | continue; | |
84363e6e | 2565 | |
f698d856 | 2566 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
84363e6e MA |
2567 | } |
2568 | rcu_read_unlock(); | |
2569 | break; | |
2570 | } | |
2571 | } | |
2572 | EXPORT_SYMBOL(ieee80211_notify_mac); |