]>
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 | ||
14 | /* TODO: | |
f0706e82 JB |
15 | * order BSS list by RSSI(?) ("quality of AP") |
16 | * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE, | |
17 | * SSID) | |
18 | */ | |
5b323edb | 19 | #include <linux/delay.h> |
f0706e82 JB |
20 | #include <linux/if_ether.h> |
21 | #include <linux/skbuff.h> | |
22 | #include <linux/netdevice.h> | |
23 | #include <linux/if_arp.h> | |
24 | #include <linux/wireless.h> | |
25 | #include <linux/random.h> | |
26 | #include <linux/etherdevice.h> | |
d0709a65 | 27 | #include <linux/rtnetlink.h> |
f0706e82 | 28 | #include <net/iw_handler.h> |
f0706e82 | 29 | #include <net/mac80211.h> |
60f8b39c | 30 | |
f0706e82 | 31 | #include "ieee80211_i.h" |
2c8dccc7 JB |
32 | #include "rate.h" |
33 | #include "led.h" | |
f709fc69 | 34 | #include "mesh.h" |
f0706e82 | 35 | |
6042a3e3 | 36 | #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2 |
f0706e82 JB |
37 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
38 | #define IEEE80211_AUTH_MAX_TRIES 3 | |
39 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) | |
40 | #define IEEE80211_ASSOC_MAX_TRIES 3 | |
41 | #define IEEE80211_MONITORING_INTERVAL (2 * HZ) | |
f709fc69 | 42 | #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ) |
f0706e82 JB |
43 | #define IEEE80211_PROBE_INTERVAL (60 * HZ) |
44 | #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) | |
45 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) | |
46 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) | |
872ba533 | 47 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) |
f0706e82 JB |
48 | |
49 | #define IEEE80211_PROBE_DELAY (HZ / 33) | |
50 | #define IEEE80211_CHANNEL_TIME (HZ / 33) | |
51 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) | |
52 | #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) | |
53 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) | |
54 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) | |
f709fc69 | 55 | #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) |
f0706e82 JB |
56 | |
57 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 | |
58 | ||
59 | ||
9c80d3dc | 60 | /* mgmt header + 1 byte category code */ |
9f985b0e RR |
61 | #define IEEE80211_MIN_ACTION_SIZE (24 + 1) |
62 | ||
63 | #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002 | |
64 | #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C | |
65 | #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0 | |
688b88a4 RR |
66 | #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000 |
67 | #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800 | |
9f985b0e | 68 | |
07db2183 RR |
69 | /* next values represent the buffer size for A-MPDU frame. |
70 | * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */ | |
71 | #define IEEE80211_MIN_AMPDU_BUF 0x8 | |
72 | #define IEEE80211_MAX_AMPDU_BUF 0x40 | |
73 | ||
60f8b39c | 74 | /* BSS handling */ |
f0706e82 | 75 | static struct ieee80211_sta_bss * |
f698d856 | 76 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, |
60f8b39c JB |
77 | u8 *ssid, u8 ssid_len) |
78 | { | |
79 | struct ieee80211_sta_bss *bss; | |
80 | ||
81 | spin_lock_bh(&local->sta_bss_lock); | |
82 | bss = local->sta_bss_hash[STA_HASH(bssid)]; | |
83 | while (bss) { | |
84 | if (!bss_mesh_cfg(bss) && | |
85 | !memcmp(bss->bssid, bssid, ETH_ALEN) && | |
86 | bss->freq == freq && | |
87 | bss->ssid_len == ssid_len && | |
88 | (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { | |
89 | atomic_inc(&bss->users); | |
90 | break; | |
91 | } | |
92 | bss = bss->hnext; | |
93 | } | |
94 | spin_unlock_bh(&local->sta_bss_lock); | |
95 | return bss; | |
96 | } | |
97 | ||
98 | /* Caller must hold local->sta_bss_lock */ | |
99 | static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local, | |
100 | struct ieee80211_sta_bss *bss) | |
101 | { | |
102 | u8 hash_idx; | |
103 | ||
104 | if (bss_mesh_cfg(bss)) | |
105 | hash_idx = mesh_id_hash(bss_mesh_id(bss), | |
106 | bss_mesh_id_len(bss)); | |
107 | else | |
108 | hash_idx = STA_HASH(bss->bssid); | |
109 | ||
110 | bss->hnext = local->sta_bss_hash[hash_idx]; | |
111 | local->sta_bss_hash[hash_idx] = bss; | |
112 | } | |
113 | ||
114 | /* Caller must hold local->sta_bss_lock */ | |
115 | static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local, | |
116 | struct ieee80211_sta_bss *bss) | |
117 | { | |
118 | struct ieee80211_sta_bss *b, *prev = NULL; | |
119 | b = local->sta_bss_hash[STA_HASH(bss->bssid)]; | |
120 | while (b) { | |
121 | if (b == bss) { | |
122 | if (!prev) | |
123 | local->sta_bss_hash[STA_HASH(bss->bssid)] = | |
124 | bss->hnext; | |
125 | else | |
126 | prev->hnext = bss->hnext; | |
127 | break; | |
128 | } | |
129 | prev = b; | |
130 | b = b->hnext; | |
131 | } | |
132 | } | |
133 | ||
134 | static struct ieee80211_sta_bss * | |
135 | ieee80211_rx_bss_add(struct ieee80211_sub_if_data *sdata, u8 *bssid, int freq, | |
136 | u8 *ssid, u8 ssid_len) | |
137 | { | |
138 | struct ieee80211_local *local = sdata->local; | |
139 | struct ieee80211_sta_bss *bss; | |
140 | ||
141 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); | |
142 | if (!bss) | |
143 | return NULL; | |
144 | atomic_inc(&bss->users); | |
145 | atomic_inc(&bss->users); | |
146 | memcpy(bss->bssid, bssid, ETH_ALEN); | |
147 | bss->freq = freq; | |
148 | if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { | |
149 | memcpy(bss->ssid, ssid, ssid_len); | |
150 | bss->ssid_len = ssid_len; | |
151 | } | |
152 | ||
153 | spin_lock_bh(&local->sta_bss_lock); | |
154 | /* TODO: order by RSSI? */ | |
155 | list_add_tail(&bss->list, &local->sta_bss_list); | |
156 | __ieee80211_rx_bss_hash_add(local, bss); | |
157 | spin_unlock_bh(&local->sta_bss_lock); | |
158 | return bss; | |
159 | } | |
160 | ||
161 | #ifdef CONFIG_MAC80211_MESH | |
162 | static struct ieee80211_sta_bss * | |
163 | ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, | |
164 | u8 *mesh_cfg, int freq) | |
165 | { | |
166 | struct ieee80211_sta_bss *bss; | |
167 | ||
168 | spin_lock_bh(&local->sta_bss_lock); | |
169 | bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)]; | |
170 | while (bss) { | |
171 | if (bss_mesh_cfg(bss) && | |
172 | !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) && | |
173 | bss->freq == freq && | |
174 | mesh_id_len == bss->mesh_id_len && | |
175 | (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id, | |
176 | mesh_id_len))) { | |
177 | atomic_inc(&bss->users); | |
178 | break; | |
179 | } | |
180 | bss = bss->hnext; | |
181 | } | |
182 | spin_unlock_bh(&local->sta_bss_lock); | |
183 | return bss; | |
184 | } | |
185 | ||
186 | static struct ieee80211_sta_bss * | |
187 | ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, | |
188 | u8 *mesh_cfg, int mesh_config_len, int freq) | |
189 | { | |
190 | struct ieee80211_sta_bss *bss; | |
191 | ||
192 | if (mesh_config_len != MESH_CFG_LEN) | |
193 | return NULL; | |
194 | ||
195 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); | |
196 | if (!bss) | |
197 | return NULL; | |
198 | ||
199 | bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC); | |
200 | if (!bss->mesh_cfg) { | |
201 | kfree(bss); | |
202 | return NULL; | |
203 | } | |
204 | ||
205 | if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) { | |
206 | bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC); | |
207 | if (!bss->mesh_id) { | |
208 | kfree(bss->mesh_cfg); | |
209 | kfree(bss); | |
210 | return NULL; | |
211 | } | |
212 | memcpy(bss->mesh_id, mesh_id, mesh_id_len); | |
213 | } | |
214 | ||
215 | atomic_inc(&bss->users); | |
216 | atomic_inc(&bss->users); | |
217 | memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN); | |
218 | bss->mesh_id_len = mesh_id_len; | |
219 | bss->freq = freq; | |
220 | spin_lock_bh(&local->sta_bss_lock); | |
221 | /* TODO: order by RSSI? */ | |
222 | list_add_tail(&bss->list, &local->sta_bss_list); | |
223 | __ieee80211_rx_bss_hash_add(local, bss); | |
224 | spin_unlock_bh(&local->sta_bss_lock); | |
225 | return bss; | |
226 | } | |
227 | #endif | |
228 | ||
229 | static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) | |
230 | { | |
231 | kfree(bss->ies); | |
232 | kfree(bss_mesh_id(bss)); | |
233 | kfree(bss_mesh_cfg(bss)); | |
234 | kfree(bss); | |
235 | } | |
236 | ||
3e122be0 | 237 | static void ieee80211_rx_bss_put(struct ieee80211_local *local, |
60f8b39c JB |
238 | struct ieee80211_sta_bss *bss) |
239 | { | |
240 | local_bh_disable(); | |
241 | if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) { | |
242 | local_bh_enable(); | |
243 | return; | |
244 | } | |
245 | ||
246 | __ieee80211_rx_bss_hash_del(local, bss); | |
247 | list_del(&bss->list); | |
248 | spin_unlock_bh(&local->sta_bss_lock); | |
249 | ieee80211_rx_bss_free(bss); | |
250 | } | |
f0706e82 | 251 | |
60f8b39c JB |
252 | void ieee80211_rx_bss_list_init(struct ieee80211_local *local) |
253 | { | |
254 | spin_lock_init(&local->sta_bss_lock); | |
255 | INIT_LIST_HEAD(&local->sta_bss_list); | |
256 | } | |
257 | ||
258 | void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local) | |
259 | { | |
260 | struct ieee80211_sta_bss *bss, *tmp; | |
f0706e82 | 261 | |
60f8b39c JB |
262 | list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) |
263 | ieee80211_rx_bss_put(local, bss); | |
264 | } | |
265 | ||
266 | static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie) | |
43ac2ca3 JM |
267 | { |
268 | u8 *end, *pos; | |
269 | ||
270 | pos = bss->ies; | |
271 | if (pos == NULL) | |
272 | return NULL; | |
273 | end = pos + bss->ies_len; | |
274 | ||
275 | while (pos + 1 < end) { | |
276 | if (pos + 2 + pos[1] > end) | |
277 | break; | |
278 | if (pos[0] == ie) | |
279 | return pos; | |
280 | pos += 2 + pos[1]; | |
281 | } | |
282 | ||
283 | return NULL; | |
284 | } | |
285 | ||
60f8b39c | 286 | /* utils */ |
f0706e82 JB |
287 | static int ecw2cw(int ecw) |
288 | { | |
ac2bf324 | 289 | return (1 << ecw) - 1; |
f0706e82 JB |
290 | } |
291 | ||
60f8b39c JB |
292 | /* frame sending functions */ |
293 | void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | |
294 | int encrypt) | |
295 | { | |
296 | skb->dev = sdata->local->mdev; | |
297 | skb_set_mac_header(skb, 0); | |
298 | skb_set_network_header(skb, 0); | |
299 | skb_set_transport_header(skb, 0); | |
e2839d8f | 300 | |
60f8b39c JB |
301 | skb->iif = sdata->dev->ifindex; |
302 | skb->do_not_encrypt = !encrypt; | |
303 | ||
304 | dev_queue_xmit(skb); | |
305 | } | |
306 | ||
307 | static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, | |
308 | struct ieee80211_if_sta *ifsta, | |
309 | int transaction, u8 *extra, size_t extra_len, | |
310 | int encrypt) | |
311 | { | |
312 | struct ieee80211_local *local = sdata->local; | |
313 | struct sk_buff *skb; | |
314 | struct ieee80211_mgmt *mgmt; | |
315 | ||
316 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
317 | sizeof(*mgmt) + 6 + extra_len); | |
318 | if (!skb) { | |
319 | printk(KERN_DEBUG "%s: failed to allocate buffer for auth " | |
320 | "frame\n", sdata->dev->name); | |
321 | return; | |
322 | } | |
323 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
324 | ||
325 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); | |
326 | memset(mgmt, 0, 24 + 6); | |
327 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
328 | IEEE80211_STYPE_AUTH); | |
329 | if (encrypt) | |
330 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
331 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | |
332 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
333 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
334 | mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg); | |
335 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); | |
336 | ifsta->auth_transaction = transaction + 1; | |
337 | mgmt->u.auth.status_code = cpu_to_le16(0); | |
338 | if (extra) | |
339 | memcpy(skb_put(skb, extra_len), extra, extra_len); | |
340 | ||
341 | ieee80211_sta_tx(sdata, skb, encrypt); | |
342 | } | |
343 | ||
344 | static void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, | |
345 | u8 *ssid, size_t ssid_len) | |
346 | { | |
347 | struct ieee80211_local *local = sdata->local; | |
348 | struct ieee80211_supported_band *sband; | |
349 | struct sk_buff *skb; | |
350 | struct ieee80211_mgmt *mgmt; | |
351 | u8 *pos, *supp_rates, *esupp_rates = NULL; | |
352 | int i; | |
353 | ||
354 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200); | |
355 | if (!skb) { | |
356 | printk(KERN_DEBUG "%s: failed to allocate buffer for probe " | |
357 | "request\n", sdata->dev->name); | |
358 | return; | |
359 | } | |
360 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
361 | ||
362 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
363 | memset(mgmt, 0, 24); | |
364 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
365 | IEEE80211_STYPE_PROBE_REQ); | |
366 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
367 | if (dst) { | |
368 | memcpy(mgmt->da, dst, ETH_ALEN); | |
369 | memcpy(mgmt->bssid, dst, ETH_ALEN); | |
370 | } else { | |
371 | memset(mgmt->da, 0xff, ETH_ALEN); | |
372 | memset(mgmt->bssid, 0xff, ETH_ALEN); | |
373 | } | |
374 | pos = skb_put(skb, 2 + ssid_len); | |
375 | *pos++ = WLAN_EID_SSID; | |
376 | *pos++ = ssid_len; | |
377 | memcpy(pos, ssid, ssid_len); | |
378 | ||
379 | supp_rates = skb_put(skb, 2); | |
380 | supp_rates[0] = WLAN_EID_SUPP_RATES; | |
381 | supp_rates[1] = 0; | |
382 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
383 | ||
384 | for (i = 0; i < sband->n_bitrates; i++) { | |
385 | struct ieee80211_rate *rate = &sband->bitrates[i]; | |
386 | if (esupp_rates) { | |
387 | pos = skb_put(skb, 1); | |
388 | esupp_rates[1]++; | |
389 | } else if (supp_rates[1] == 8) { | |
390 | esupp_rates = skb_put(skb, 3); | |
391 | esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES; | |
392 | esupp_rates[1] = 1; | |
393 | pos = &esupp_rates[2]; | |
394 | } else { | |
395 | pos = skb_put(skb, 1); | |
396 | supp_rates[1]++; | |
397 | } | |
398 | *pos = rate->bitrate / 5; | |
399 | } | |
400 | ||
401 | ieee80211_sta_tx(sdata, skb, 0); | |
402 | } | |
403 | ||
404 | /* MLME */ | |
f698d856 | 405 | static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
e2839d8f VK |
406 | struct ieee80211_sta_bss *bss, |
407 | int ibss) | |
408 | { | |
e2839d8f VK |
409 | struct ieee80211_local *local = sdata->local; |
410 | int i, have_higher_than_11mbit = 0; | |
411 | ||
412 | ||
413 | /* cf. IEEE 802.11 9.2.12 */ | |
414 | for (i = 0; i < bss->supp_rates_len; i++) | |
415 | if ((bss->supp_rates[i] & 0x7f) * 5 > 110) | |
416 | have_higher_than_11mbit = 1; | |
417 | ||
418 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
419 | have_higher_than_11mbit) | |
420 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
421 | else | |
422 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
423 | ||
424 | ||
425 | if (local->ops->conf_tx) { | |
426 | struct ieee80211_tx_queue_params qparam; | |
e2839d8f VK |
427 | |
428 | memset(&qparam, 0, sizeof(qparam)); | |
429 | ||
430 | qparam.aifs = 2; | |
431 | ||
432 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
433 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)) | |
434 | qparam.cw_min = 31; | |
435 | else | |
436 | qparam.cw_min = 15; | |
437 | ||
438 | qparam.cw_max = 1023; | |
439 | qparam.txop = 0; | |
440 | ||
e100bb64 JB |
441 | for (i = 0; i < local_to_hw(local)->queues; i++) |
442 | local->ops->conf_tx(local_to_hw(local), i, &qparam); | |
e2839d8f VK |
443 | } |
444 | } | |
445 | ||
f698d856 | 446 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
f0706e82 JB |
447 | struct ieee80211_if_sta *ifsta, |
448 | u8 *wmm_param, size_t wmm_param_len) | |
449 | { | |
f0706e82 JB |
450 | struct ieee80211_tx_queue_params params; |
451 | size_t left; | |
452 | int count; | |
453 | u8 *pos; | |
454 | ||
3434fbd3 JB |
455 | if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED)) |
456 | return; | |
457 | ||
458 | if (!wmm_param) | |
459 | return; | |
460 | ||
f0706e82 JB |
461 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
462 | return; | |
463 | count = wmm_param[6] & 0x0f; | |
464 | if (count == ifsta->wmm_last_param_set) | |
465 | return; | |
466 | ifsta->wmm_last_param_set = count; | |
467 | ||
468 | pos = wmm_param + 8; | |
469 | left = wmm_param_len - 8; | |
470 | ||
471 | memset(¶ms, 0, sizeof(params)); | |
472 | ||
473 | if (!local->ops->conf_tx) | |
474 | return; | |
475 | ||
476 | local->wmm_acm = 0; | |
477 | for (; left >= 4; left -= 4, pos += 4) { | |
478 | int aci = (pos[0] >> 5) & 0x03; | |
479 | int acm = (pos[0] >> 4) & 0x01; | |
480 | int queue; | |
481 | ||
482 | switch (aci) { | |
483 | case 1: | |
e100bb64 | 484 | queue = 3; |
988c0f72 | 485 | if (acm) |
f0706e82 | 486 | local->wmm_acm |= BIT(0) | BIT(3); |
f0706e82 JB |
487 | break; |
488 | case 2: | |
e100bb64 | 489 | queue = 1; |
988c0f72 | 490 | if (acm) |
f0706e82 | 491 | local->wmm_acm |= BIT(4) | BIT(5); |
f0706e82 JB |
492 | break; |
493 | case 3: | |
e100bb64 | 494 | queue = 0; |
988c0f72 | 495 | if (acm) |
f0706e82 | 496 | local->wmm_acm |= BIT(6) | BIT(7); |
f0706e82 JB |
497 | break; |
498 | case 0: | |
499 | default: | |
e100bb64 | 500 | queue = 2; |
988c0f72 | 501 | if (acm) |
f0706e82 | 502 | local->wmm_acm |= BIT(1) | BIT(2); |
f0706e82 JB |
503 | break; |
504 | } | |
505 | ||
506 | params.aifs = pos[0] & 0x0f; | |
507 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); | |
508 | params.cw_min = ecw2cw(pos[1] & 0x0f); | |
f434b2d1 | 509 | params.txop = get_unaligned_le16(pos + 2); |
f4ea83dd | 510 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
f0706e82 | 511 | printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " |
3330d7be | 512 | "cWmin=%d cWmax=%d txop=%d\n", |
f698d856 | 513 | local->mdev->name, queue, aci, acm, params.aifs, params.cw_min, |
3330d7be JB |
514 | params.cw_max, params.txop); |
515 | #endif | |
f0706e82 JB |
516 | /* TODO: handle ACM (block TX, fallback to next lowest allowed |
517 | * AC for now) */ | |
518 | if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) { | |
519 | printk(KERN_DEBUG "%s: failed to set TX queue " | |
f698d856 | 520 | "parameters for queue %d\n", local->mdev->name, queue); |
f0706e82 JB |
521 | } |
522 | } | |
523 | } | |
524 | ||
50c4afb9 JL |
525 | static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata, |
526 | bool use_protection, | |
527 | bool use_short_preamble) | |
5628221c | 528 | { |
471b3efd | 529 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
ebd74487 | 530 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
5628221c | 531 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
0795af57 | 532 | DECLARE_MAC_BUF(mac); |
ebd74487 | 533 | #endif |
471b3efd | 534 | u32 changed = 0; |
5628221c | 535 | |
471b3efd | 536 | if (use_protection != bss_conf->use_cts_prot) { |
f4ea83dd | 537 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
5628221c DD |
538 | if (net_ratelimit()) { |
539 | printk(KERN_DEBUG "%s: CTS protection %s (BSSID=" | |
0795af57 | 540 | "%s)\n", |
471b3efd | 541 | sdata->dev->name, |
5628221c | 542 | use_protection ? "enabled" : "disabled", |
0795af57 | 543 | print_mac(mac, ifsta->bssid)); |
5628221c | 544 | } |
f4ea83dd | 545 | #endif |
471b3efd JB |
546 | bss_conf->use_cts_prot = use_protection; |
547 | changed |= BSS_CHANGED_ERP_CTS_PROT; | |
5628221c | 548 | } |
7e9ed188 | 549 | |
d43c7b37 | 550 | if (use_short_preamble != bss_conf->use_short_preamble) { |
f4ea83dd | 551 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
7e9ed188 DD |
552 | if (net_ratelimit()) { |
553 | printk(KERN_DEBUG "%s: switched to %s barker preamble" | |
0795af57 | 554 | " (BSSID=%s)\n", |
471b3efd | 555 | sdata->dev->name, |
d43c7b37 | 556 | use_short_preamble ? "short" : "long", |
0795af57 | 557 | print_mac(mac, ifsta->bssid)); |
7e9ed188 | 558 | } |
f4ea83dd | 559 | #endif |
d43c7b37 | 560 | bss_conf->use_short_preamble = use_short_preamble; |
471b3efd | 561 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
7e9ed188 | 562 | } |
d9430a32 | 563 | |
471b3efd | 564 | return changed; |
5628221c DD |
565 | } |
566 | ||
50c4afb9 JL |
567 | static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata, |
568 | u8 erp_value) | |
569 | { | |
570 | bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; | |
571 | bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0; | |
572 | ||
573 | return ieee80211_handle_protect_preamb(sdata, | |
574 | use_protection, use_short_preamble); | |
575 | } | |
576 | ||
577 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, | |
578 | struct ieee80211_sta_bss *bss) | |
579 | { | |
580 | u32 changed = 0; | |
581 | ||
582 | if (bss->has_erp_value) | |
583 | changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value); | |
584 | else { | |
585 | u16 capab = bss->capability; | |
586 | changed |= ieee80211_handle_protect_preamb(sdata, false, | |
587 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); | |
588 | } | |
589 | ||
590 | return changed; | |
591 | } | |
592 | ||
c7153508 RR |
593 | int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie, |
594 | struct ieee80211_ht_info *ht_info) | |
595 | { | |
596 | ||
597 | if (ht_info == NULL) | |
598 | return -EINVAL; | |
599 | ||
600 | memset(ht_info, 0, sizeof(*ht_info)); | |
601 | ||
602 | if (ht_cap_ie) { | |
603 | u8 ampdu_info = ht_cap_ie->ampdu_params_info; | |
604 | ||
605 | ht_info->ht_supported = 1; | |
606 | ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info); | |
607 | ht_info->ampdu_factor = | |
608 | ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR; | |
609 | ht_info->ampdu_density = | |
610 | (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2; | |
611 | memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16); | |
612 | } else | |
613 | ht_info->ht_supported = 0; | |
614 | ||
615 | return 0; | |
616 | } | |
617 | ||
618 | int ieee80211_ht_addt_info_ie_to_ht_bss_info( | |
619 | struct ieee80211_ht_addt_info *ht_add_info_ie, | |
620 | struct ieee80211_ht_bss_info *bss_info) | |
621 | { | |
622 | if (bss_info == NULL) | |
623 | return -EINVAL; | |
624 | ||
625 | memset(bss_info, 0, sizeof(*bss_info)); | |
626 | ||
627 | if (ht_add_info_ie) { | |
628 | u16 op_mode; | |
629 | op_mode = le16_to_cpu(ht_add_info_ie->operation_mode); | |
630 | ||
631 | bss_info->primary_channel = ht_add_info_ie->control_chan; | |
632 | bss_info->bss_cap = ht_add_info_ie->ht_param; | |
633 | bss_info->bss_op_mode = (u8)(op_mode & 0xff); | |
634 | } | |
635 | ||
636 | return 0; | |
637 | } | |
5628221c | 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); |
5628221c | 694 | |
f5e5bf25 TW |
695 | ieee80211_rx_bss_put(local, bss); |
696 | } | |
38668c05 | 697 | |
f5e5bf25 TW |
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; | |
703 | } | |
38668c05 | 704 | |
f5e5bf25 TW |
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); | |
38668c05 | 708 | |
f0706e82 | 709 | ifsta->last_probe = jiffies; |
f5e5bf25 | 710 | ieee80211_led_assoc(local, 1); |
471b3efd | 711 | |
f5e5bf25 | 712 | sdata->bss_conf.assoc = 1; |
471b3efd | 713 | ieee80211_bss_info_change_notify(sdata, changed); |
8db9369f | 714 | |
24e64622 | 715 | netif_tx_start_all_queues(sdata->dev); |
f5e5bf25 | 716 | netif_carrier_on(sdata->dev); |
8db9369f | 717 | |
f5e5bf25 | 718 | ieee80211_sta_send_apinfo(sdata, ifsta); |
f0706e82 JB |
719 | } |
720 | ||
9859b81e RR |
721 | static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata, |
722 | struct ieee80211_if_sta *ifsta) | |
723 | { | |
724 | DECLARE_MAC_BUF(mac); | |
725 | ||
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; | |
731 | return; | |
732 | } | |
733 | ||
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); | |
737 | ||
738 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; | |
739 | ||
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); | |
749 | } | |
750 | ||
f0706e82 | 751 | |
f698d856 | 752 | static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
753 | struct ieee80211_if_sta *ifsta) |
754 | { | |
0795af57 JP |
755 | DECLARE_MAC_BUF(mac); |
756 | ||
f0706e82 JB |
757 | ifsta->auth_tries++; |
758 | if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) { | |
0795af57 | 759 | printk(KERN_DEBUG "%s: authentication with AP %s" |
f0706e82 | 760 | " timed out\n", |
f698d856 | 761 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
48c2fc59 | 762 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
f0706e82 JB |
763 | return; |
764 | } | |
765 | ||
48c2fc59 | 766 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
0795af57 | 767 | printk(KERN_DEBUG "%s: authenticate with AP %s\n", |
f698d856 | 768 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
f0706e82 | 769 | |
f698d856 | 770 | ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0); |
f0706e82 JB |
771 | |
772 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); | |
773 | } | |
774 | ||
36d16ae7 HS |
775 | static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss, |
776 | struct ieee80211_supported_band *sband, | |
777 | u64 *rates) | |
778 | { | |
779 | int i, j, count; | |
780 | *rates = 0; | |
781 | count = 0; | |
782 | for (i = 0; i < bss->supp_rates_len; i++) { | |
783 | int rate = (bss->supp_rates[i] & 0x7F) * 5; | |
784 | ||
785 | for (j = 0; j < sband->n_bitrates; j++) | |
786 | if (sband->bitrates[j].bitrate == rate) { | |
787 | *rates |= BIT(j); | |
788 | count++; | |
789 | break; | |
790 | } | |
791 | } | |
792 | ||
793 | return count; | |
794 | } | |
f0706e82 | 795 | |
f698d856 | 796 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
797 | struct ieee80211_if_sta *ifsta) |
798 | { | |
f698d856 | 799 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
800 | struct sk_buff *skb; |
801 | struct ieee80211_mgmt *mgmt; | |
43ac2ca3 | 802 | u8 *pos, *ies, *ht_add_ie; |
36d16ae7 | 803 | int i, len, count, rates_len, supp_rates_len; |
f0706e82 JB |
804 | u16 capab; |
805 | struct ieee80211_sta_bss *bss; | |
806 | int wmm = 0; | |
8318d78a | 807 | struct ieee80211_supported_band *sband; |
36d16ae7 | 808 | u64 rates = 0; |
f0706e82 JB |
809 | |
810 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
811 | sizeof(*mgmt) + 200 + ifsta->extra_ie_len + | |
812 | ifsta->ssid_len); | |
813 | if (!skb) { | |
814 | printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " | |
f698d856 | 815 | "frame\n", sdata->dev->name); |
f0706e82 JB |
816 | return; |
817 | } | |
818 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
819 | ||
8318d78a JB |
820 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
821 | ||
f0706e82 | 822 | capab = ifsta->capab; |
8318d78a JB |
823 | |
824 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) { | |
825 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) | |
826 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; | |
827 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) | |
828 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
f0706e82 | 829 | } |
8318d78a | 830 | |
f698d856 | 831 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
8318d78a | 832 | local->hw.conf.channel->center_freq, |
cffdd30d | 833 | ifsta->ssid, ifsta->ssid_len); |
f0706e82 JB |
834 | if (bss) { |
835 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) | |
836 | capab |= WLAN_CAPABILITY_PRIVACY; | |
43ac2ca3 | 837 | if (bss->wmm_used) |
f0706e82 | 838 | wmm = 1; |
0d580a77 HS |
839 | |
840 | /* get all rates supported by the device and the AP as | |
841 | * some APs don't like getting a superset of their rates | |
842 | * in the association request (e.g. D-Link DAP 1353 in | |
843 | * b-only mode) */ | |
844 | rates_len = ieee80211_compatible_rates(bss, sband, &rates); | |
845 | ||
06ff47bc TW |
846 | if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
847 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) | |
848 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; | |
849 | ||
3e122be0 | 850 | ieee80211_rx_bss_put(local, bss); |
0d580a77 HS |
851 | } else { |
852 | rates = ~0; | |
853 | rates_len = sband->n_bitrates; | |
f0706e82 JB |
854 | } |
855 | ||
856 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
857 | memset(mgmt, 0, 24); | |
858 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | |
f698d856 | 859 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
f0706e82 JB |
860 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
861 | ||
d6f2da5b | 862 | if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) { |
f0706e82 | 863 | skb_put(skb, 10); |
e7827a70 HH |
864 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
865 | IEEE80211_STYPE_REASSOC_REQ); | |
f0706e82 | 866 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
ea95bba4 TW |
867 | mgmt->u.reassoc_req.listen_interval = |
868 | cpu_to_le16(local->hw.conf.listen_interval); | |
f0706e82 JB |
869 | memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid, |
870 | ETH_ALEN); | |
871 | } else { | |
872 | skb_put(skb, 4); | |
e7827a70 HH |
873 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
874 | IEEE80211_STYPE_ASSOC_REQ); | |
f0706e82 | 875 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
ea95bba4 TW |
876 | mgmt->u.reassoc_req.listen_interval = |
877 | cpu_to_le16(local->hw.conf.listen_interval); | |
f0706e82 JB |
878 | } |
879 | ||
880 | /* SSID */ | |
881 | ies = pos = skb_put(skb, 2 + ifsta->ssid_len); | |
882 | *pos++ = WLAN_EID_SSID; | |
883 | *pos++ = ifsta->ssid_len; | |
884 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); | |
885 | ||
0d580a77 | 886 | /* add all rates which were marked to be used above */ |
36d16ae7 HS |
887 | supp_rates_len = rates_len; |
888 | if (supp_rates_len > 8) | |
889 | supp_rates_len = 8; | |
890 | ||
8318d78a | 891 | len = sband->n_bitrates; |
36d16ae7 | 892 | pos = skb_put(skb, supp_rates_len + 2); |
f0706e82 | 893 | *pos++ = WLAN_EID_SUPP_RATES; |
36d16ae7 | 894 | *pos++ = supp_rates_len; |
f0706e82 | 895 | |
36d16ae7 HS |
896 | count = 0; |
897 | for (i = 0; i < sband->n_bitrates; i++) { | |
898 | if (BIT(i) & rates) { | |
8318d78a | 899 | int rate = sband->bitrates[i].bitrate; |
f0706e82 | 900 | *pos++ = (u8) (rate / 5); |
36d16ae7 HS |
901 | if (++count == 8) |
902 | break; | |
903 | } | |
904 | } | |
905 | ||
8ab65b03 | 906 | if (rates_len > count) { |
36d16ae7 HS |
907 | pos = skb_put(skb, rates_len - count + 2); |
908 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
909 | *pos++ = rates_len - count; | |
910 | ||
911 | for (i++; i < sband->n_bitrates; i++) { | |
912 | if (BIT(i) & rates) { | |
913 | int rate = sband->bitrates[i].bitrate; | |
914 | *pos++ = (u8) (rate / 5); | |
915 | } | |
f0706e82 JB |
916 | } |
917 | } | |
918 | ||
06ff47bc TW |
919 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { |
920 | /* 1. power capabilities */ | |
921 | pos = skb_put(skb, 4); | |
922 | *pos++ = WLAN_EID_PWR_CAPABILITY; | |
923 | *pos++ = 2; | |
924 | *pos++ = 0; /* min tx power */ | |
925 | *pos++ = local->hw.conf.channel->max_power; /* max tx power */ | |
926 | ||
927 | /* 2. supported channels */ | |
928 | /* TODO: get this in reg domain format */ | |
929 | pos = skb_put(skb, 2 * sband->n_channels + 2); | |
930 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; | |
931 | *pos++ = 2 * sband->n_channels; | |
932 | for (i = 0; i < sband->n_channels; i++) { | |
933 | *pos++ = ieee80211_frequency_to_channel( | |
934 | sband->channels[i].center_freq); | |
935 | *pos++ = 1; /* one channel in the subband*/ | |
936 | } | |
937 | } | |
938 | ||
f0706e82 JB |
939 | if (ifsta->extra_ie) { |
940 | pos = skb_put(skb, ifsta->extra_ie_len); | |
941 | memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len); | |
942 | } | |
943 | ||
d6f2da5b | 944 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
f0706e82 JB |
945 | pos = skb_put(skb, 9); |
946 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; | |
947 | *pos++ = 7; /* len */ | |
948 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ | |
949 | *pos++ = 0x50; | |
950 | *pos++ = 0xf2; | |
951 | *pos++ = 2; /* WME */ | |
952 | *pos++ = 0; /* WME info */ | |
953 | *pos++ = 1; /* WME ver */ | |
954 | *pos++ = 0; | |
955 | } | |
3434fbd3 | 956 | |
c7153508 | 957 | /* wmm support is a must to HT */ |
3434fbd3 | 958 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) && |
43ac2ca3 JM |
959 | sband->ht_info.ht_supported && |
960 | (ht_add_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_EXTRA_INFO))) { | |
9306102e | 961 | struct ieee80211_ht_addt_info *ht_add_info = |
43ac2ca3 | 962 | (struct ieee80211_ht_addt_info *)ht_add_ie; |
9306102e EG |
963 | u16 cap = sband->ht_info.cap; |
964 | __le16 tmp; | |
965 | u32 flags = local->hw.conf.channel->flags; | |
966 | ||
967 | switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) { | |
968 | case IEEE80211_HT_IE_CHA_SEC_ABOVE: | |
969 | if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) { | |
970 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; | |
971 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
972 | } | |
973 | break; | |
974 | case IEEE80211_HT_IE_CHA_SEC_BELOW: | |
975 | if (flags & IEEE80211_CHAN_NO_FAT_BELOW) { | |
976 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; | |
977 | cap &= ~IEEE80211_HT_CAP_SGI_40; | |
978 | } | |
979 | break; | |
980 | } | |
981 | ||
982 | tmp = cpu_to_le16(cap); | |
c7153508 RR |
983 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2); |
984 | *pos++ = WLAN_EID_HT_CAPABILITY; | |
985 | *pos++ = sizeof(struct ieee80211_ht_cap); | |
986 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); | |
987 | memcpy(pos, &tmp, sizeof(u16)); | |
988 | pos += sizeof(u16); | |
8318d78a JB |
989 | /* TODO: needs a define here for << 2 */ |
990 | *pos++ = sband->ht_info.ampdu_factor | | |
991 | (sband->ht_info.ampdu_density << 2); | |
992 | memcpy(pos, sband->ht_info.supp_mcs_set, 16); | |
c7153508 | 993 | } |
f0706e82 JB |
994 | |
995 | kfree(ifsta->assocreq_ies); | |
996 | ifsta->assocreq_ies_len = (skb->data + skb->len) - ies; | |
0ec0b7ac | 997 | ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL); |
f0706e82 JB |
998 | if (ifsta->assocreq_ies) |
999 | memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len); | |
1000 | ||
f698d856 | 1001 | ieee80211_sta_tx(sdata, skb, 0); |
f0706e82 JB |
1002 | } |
1003 | ||
1004 | ||
f698d856 | 1005 | static void ieee80211_send_deauth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1006 | struct ieee80211_if_sta *ifsta, u16 reason) |
1007 | { | |
f698d856 | 1008 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1009 | struct sk_buff *skb; |
1010 | struct ieee80211_mgmt *mgmt; | |
1011 | ||
1012 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); | |
1013 | if (!skb) { | |
1014 | printk(KERN_DEBUG "%s: failed to allocate buffer for deauth " | |
f698d856 | 1015 | "frame\n", sdata->dev->name); |
f0706e82 JB |
1016 | return; |
1017 | } | |
1018 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1019 | ||
1020 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
1021 | memset(mgmt, 0, 24); | |
1022 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | |
f698d856 | 1023 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
f0706e82 | 1024 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
e7827a70 HH |
1025 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
1026 | IEEE80211_STYPE_DEAUTH); | |
f0706e82 JB |
1027 | skb_put(skb, 2); |
1028 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); | |
1029 | ||
f698d856 | 1030 | ieee80211_sta_tx(sdata, skb, 0); |
f0706e82 JB |
1031 | } |
1032 | ||
60f8b39c JB |
1033 | static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata) |
1034 | { | |
1035 | if (!sdata || !sdata->default_key || | |
1036 | sdata->default_key->conf.alg != ALG_WEP) | |
1037 | return 0; | |
1038 | return 1; | |
1039 | } | |
f0706e82 | 1040 | |
f698d856 | 1041 | static void ieee80211_send_disassoc(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1042 | struct ieee80211_if_sta *ifsta, u16 reason) |
1043 | { | |
f698d856 | 1044 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1045 | struct sk_buff *skb; |
1046 | struct ieee80211_mgmt *mgmt; | |
1047 | ||
1048 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); | |
1049 | if (!skb) { | |
1050 | printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc " | |
f698d856 | 1051 | "frame\n", sdata->dev->name); |
f0706e82 JB |
1052 | return; |
1053 | } | |
1054 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1055 | ||
1056 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
1057 | memset(mgmt, 0, 24); | |
1058 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | |
f698d856 | 1059 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
f0706e82 | 1060 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
e7827a70 HH |
1061 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
1062 | IEEE80211_STYPE_DISASSOC); | |
f0706e82 JB |
1063 | skb_put(skb, 2); |
1064 | mgmt->u.disassoc.reason_code = cpu_to_le16(reason); | |
1065 | ||
f698d856 | 1066 | ieee80211_sta_tx(sdata, skb, 0); |
f0706e82 JB |
1067 | } |
1068 | ||
aa458d17 TW |
1069 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
1070 | struct ieee80211_if_sta *ifsta, bool deauth, | |
1071 | bool self_disconnected, u16 reason) | |
1072 | { | |
1073 | struct ieee80211_local *local = sdata->local; | |
1074 | struct sta_info *sta; | |
f5e5bf25 | 1075 | u32 changed = BSS_CHANGED_ASSOC; |
aa458d17 TW |
1076 | |
1077 | rcu_read_lock(); | |
1078 | ||
1079 | sta = sta_info_get(local, ifsta->bssid); | |
1080 | if (!sta) { | |
1081 | rcu_read_unlock(); | |
1082 | return; | |
1083 | } | |
1084 | ||
1085 | if (deauth) { | |
1086 | ifsta->direct_probe_tries = 0; | |
1087 | ifsta->auth_tries = 0; | |
1088 | } | |
1089 | ifsta->assoc_scan_tries = 0; | |
1090 | ifsta->assoc_tries = 0; | |
1091 | ||
24e64622 | 1092 | netif_tx_stop_all_queues(sdata->dev); |
aa458d17 TW |
1093 | netif_carrier_off(sdata->dev); |
1094 | ||
1095 | ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr); | |
1096 | ||
1097 | if (self_disconnected) { | |
1098 | if (deauth) | |
1099 | ieee80211_send_deauth(sdata, ifsta, reason); | |
1100 | else | |
1101 | ieee80211_send_disassoc(sdata, ifsta, reason); | |
1102 | } | |
1103 | ||
f5e5bf25 TW |
1104 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
1105 | changed |= ieee80211_reset_erp_info(sdata); | |
1106 | ||
1107 | if (sdata->bss_conf.assoc_ht) | |
1108 | changed |= BSS_CHANGED_HT; | |
1109 | ||
1110 | sdata->bss_conf.assoc_ht = 0; | |
1111 | sdata->bss_conf.ht_conf = NULL; | |
1112 | sdata->bss_conf.ht_bss_conf = NULL; | |
1113 | ||
1114 | ieee80211_led_assoc(local, 0); | |
1115 | sdata->bss_conf.assoc = 0; | |
1116 | ||
1117 | ieee80211_sta_send_apinfo(sdata, ifsta); | |
aa458d17 TW |
1118 | |
1119 | if (self_disconnected) | |
1120 | ifsta->state = IEEE80211_STA_MLME_DISABLED; | |
1121 | ||
1122 | sta_info_unlink(&sta); | |
1123 | ||
1124 | rcu_read_unlock(); | |
1125 | ||
1126 | sta_info_destroy(sta); | |
1127 | } | |
f0706e82 | 1128 | |
f698d856 | 1129 | static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1130 | struct ieee80211_if_sta *ifsta) |
1131 | { | |
f698d856 | 1132 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 1133 | struct ieee80211_sta_bss *bss; |
5b98b1f7 JB |
1134 | int bss_privacy; |
1135 | int wep_privacy; | |
1136 | int privacy_invoked; | |
f0706e82 | 1137 | |
5b98b1f7 | 1138 | if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL)) |
f0706e82 JB |
1139 | return 0; |
1140 | ||
f698d856 | 1141 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
8318d78a | 1142 | local->hw.conf.channel->center_freq, |
cffdd30d | 1143 | ifsta->ssid, ifsta->ssid_len); |
f0706e82 JB |
1144 | if (!bss) |
1145 | return 0; | |
1146 | ||
5b98b1f7 | 1147 | bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY); |
f698d856 | 1148 | wep_privacy = !!ieee80211_sta_wep_configured(sdata); |
5b98b1f7 | 1149 | privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED); |
f0706e82 | 1150 | |
3e122be0 | 1151 | ieee80211_rx_bss_put(local, bss); |
f0706e82 | 1152 | |
5b98b1f7 JB |
1153 | if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked)) |
1154 | return 0; | |
1155 | ||
1156 | return 1; | |
f0706e82 JB |
1157 | } |
1158 | ||
f698d856 | 1159 | static void ieee80211_associate(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1160 | struct ieee80211_if_sta *ifsta) |
1161 | { | |
0795af57 JP |
1162 | DECLARE_MAC_BUF(mac); |
1163 | ||
f0706e82 JB |
1164 | ifsta->assoc_tries++; |
1165 | if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { | |
0795af57 | 1166 | printk(KERN_DEBUG "%s: association with AP %s" |
f0706e82 | 1167 | " timed out\n", |
f698d856 | 1168 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
48c2fc59 | 1169 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
f0706e82 JB |
1170 | return; |
1171 | } | |
1172 | ||
48c2fc59 | 1173 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; |
0795af57 | 1174 | printk(KERN_DEBUG "%s: associate with AP %s\n", |
f698d856 JBG |
1175 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
1176 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { | |
f0706e82 | 1177 | printk(KERN_DEBUG "%s: mismatch in privacy configuration and " |
f698d856 | 1178 | "mixed-cell disabled - abort association\n", sdata->dev->name); |
48c2fc59 | 1179 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
f0706e82 JB |
1180 | return; |
1181 | } | |
1182 | ||
f698d856 | 1183 | ieee80211_send_assoc(sdata, ifsta); |
f0706e82 JB |
1184 | |
1185 | mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); | |
1186 | } | |
1187 | ||
1188 | ||
f698d856 | 1189 | static void ieee80211_associated(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1190 | struct ieee80211_if_sta *ifsta) |
1191 | { | |
f698d856 | 1192 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
1193 | struct sta_info *sta; |
1194 | int disassoc; | |
0795af57 | 1195 | DECLARE_MAC_BUF(mac); |
f0706e82 JB |
1196 | |
1197 | /* TODO: start monitoring current AP signal quality and number of | |
1198 | * missed beacons. Scan other channels every now and then and search | |
1199 | * for better APs. */ | |
1200 | /* TODO: remove expired BSSes */ | |
1201 | ||
48c2fc59 | 1202 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATED; |
f0706e82 | 1203 | |
d0709a65 JB |
1204 | rcu_read_lock(); |
1205 | ||
f0706e82 JB |
1206 | sta = sta_info_get(local, ifsta->bssid); |
1207 | if (!sta) { | |
0795af57 | 1208 | printk(KERN_DEBUG "%s: No STA entry for own AP %s\n", |
f698d856 | 1209 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
f0706e82 JB |
1210 | disassoc = 1; |
1211 | } else { | |
1212 | disassoc = 0; | |
1213 | if (time_after(jiffies, | |
1214 | sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { | |
d6f2da5b | 1215 | if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) { |
f0706e82 | 1216 | printk(KERN_DEBUG "%s: No ProbeResp from " |
0795af57 | 1217 | "current AP %s - assume out of " |
f0706e82 | 1218 | "range\n", |
f698d856 | 1219 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
f0706e82 | 1220 | disassoc = 1; |
d6f2da5b | 1221 | } else |
f698d856 | 1222 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
f0706e82 JB |
1223 | local->scan_ssid, |
1224 | local->scan_ssid_len); | |
d6f2da5b | 1225 | ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL; |
f0706e82 | 1226 | } else { |
d6f2da5b | 1227 | ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL; |
f0706e82 JB |
1228 | if (time_after(jiffies, ifsta->last_probe + |
1229 | IEEE80211_PROBE_INTERVAL)) { | |
1230 | ifsta->last_probe = jiffies; | |
f698d856 | 1231 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
f0706e82 JB |
1232 | ifsta->ssid, |
1233 | ifsta->ssid_len); | |
1234 | } | |
1235 | } | |
f0706e82 | 1236 | } |
d0709a65 JB |
1237 | |
1238 | rcu_read_unlock(); | |
1239 | ||
60f8b39c JB |
1240 | if (disassoc) |
1241 | ieee80211_set_disassoc(sdata, ifsta, true, true, | |
1242 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
1243 | else | |
1244 | mod_timer(&ifsta->timer, jiffies + | |
1245 | IEEE80211_MONITORING_INTERVAL); | |
f0706e82 JB |
1246 | } |
1247 | ||
1248 | ||
f698d856 | 1249 | static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1250 | struct ieee80211_if_sta *ifsta) |
1251 | { | |
f698d856 | 1252 | printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name); |
d6f2da5b | 1253 | ifsta->flags |= IEEE80211_STA_AUTHENTICATED; |
f698d856 | 1254 | ieee80211_associate(sdata, ifsta); |
f0706e82 JB |
1255 | } |
1256 | ||
1257 | ||
f698d856 | 1258 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1259 | struct ieee80211_if_sta *ifsta, |
1260 | struct ieee80211_mgmt *mgmt, | |
1261 | size_t len) | |
1262 | { | |
1263 | u8 *pos; | |
1264 | struct ieee802_11_elems elems; | |
1265 | ||
f0706e82 | 1266 | pos = mgmt->u.auth.variable; |
67a4cce4 | 1267 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
f4ea83dd | 1268 | if (!elems.challenge) |
f0706e82 | 1269 | return; |
f698d856 | 1270 | ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2, |
f0706e82 JB |
1271 | elems.challenge_len + 2, 1); |
1272 | } | |
1273 | ||
f698d856 | 1274 | static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid, |
9f985b0e RR |
1275 | u8 dialog_token, u16 status, u16 policy, |
1276 | u16 buf_size, u16 timeout) | |
1277 | { | |
9f985b0e | 1278 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
f698d856 | 1279 | struct ieee80211_local *local = sdata->local; |
9f985b0e RR |
1280 | struct sk_buff *skb; |
1281 | struct ieee80211_mgmt *mgmt; | |
1282 | u16 capab; | |
1283 | ||
3acea5b6 EK |
1284 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
1285 | ||
9f985b0e RR |
1286 | if (!skb) { |
1287 | printk(KERN_DEBUG "%s: failed to allocate buffer " | |
f698d856 | 1288 | "for addba resp frame\n", sdata->dev->name); |
9f985b0e RR |
1289 | return; |
1290 | } | |
1291 | ||
1292 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1293 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
1294 | memset(mgmt, 0, 24); | |
1295 | memcpy(mgmt->da, da, ETH_ALEN); | |
f698d856 | 1296 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
51fb61e7 | 1297 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) |
f698d856 | 1298 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
9f985b0e RR |
1299 | else |
1300 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
e7827a70 HH |
1301 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
1302 | IEEE80211_STYPE_ACTION); | |
9f985b0e RR |
1303 | |
1304 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp)); | |
1305 | mgmt->u.action.category = WLAN_CATEGORY_BACK; | |
1306 | mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP; | |
1307 | mgmt->u.action.u.addba_resp.dialog_token = dialog_token; | |
1308 | ||
1309 | capab = (u16)(policy << 1); /* bit 1 aggregation policy */ | |
1310 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ | |
1311 | capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */ | |
1312 | ||
1313 | mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab); | |
1314 | mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout); | |
1315 | mgmt->u.action.u.addba_resp.status = cpu_to_le16(status); | |
1316 | ||
f698d856 | 1317 | ieee80211_sta_tx(sdata, skb, 0); |
9f985b0e RR |
1318 | |
1319 | return; | |
1320 | } | |
1321 | ||
f698d856 | 1322 | void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, const u8 *da, |
eadc8d9e RR |
1323 | u16 tid, u8 dialog_token, u16 start_seq_num, |
1324 | u16 agg_size, u16 timeout) | |
1325 | { | |
f698d856 | 1326 | struct ieee80211_local *local = sdata->local; |
eadc8d9e RR |
1327 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
1328 | struct sk_buff *skb; | |
1329 | struct ieee80211_mgmt *mgmt; | |
1330 | u16 capab; | |
1331 | ||
3acea5b6 | 1332 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
eadc8d9e RR |
1333 | |
1334 | if (!skb) { | |
1335 | printk(KERN_ERR "%s: failed to allocate buffer " | |
f698d856 | 1336 | "for addba request frame\n", sdata->dev->name); |
eadc8d9e RR |
1337 | return; |
1338 | } | |
1339 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1340 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
1341 | memset(mgmt, 0, 24); | |
1342 | memcpy(mgmt->da, da, ETH_ALEN); | |
f698d856 | 1343 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
eadc8d9e | 1344 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) |
f698d856 | 1345 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
eadc8d9e RR |
1346 | else |
1347 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
1348 | ||
e7827a70 HH |
1349 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
1350 | IEEE80211_STYPE_ACTION); | |
eadc8d9e RR |
1351 | |
1352 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req)); | |
1353 | ||
1354 | mgmt->u.action.category = WLAN_CATEGORY_BACK; | |
1355 | mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ; | |
1356 | ||
1357 | mgmt->u.action.u.addba_req.dialog_token = dialog_token; | |
1358 | capab = (u16)(1 << 1); /* bit 1 aggregation policy */ | |
1359 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ | |
1360 | capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */ | |
1361 | ||
1362 | mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab); | |
1363 | ||
1364 | mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout); | |
1365 | mgmt->u.action.u.addba_req.start_seq_num = | |
1366 | cpu_to_le16(start_seq_num << 4); | |
1367 | ||
f698d856 | 1368 | ieee80211_sta_tx(sdata, skb, 0); |
eadc8d9e RR |
1369 | } |
1370 | ||
60f8b39c JB |
1371 | /* |
1372 | * After accepting the AddBA Request we activated a timer, | |
1373 | * resetting it after each frame that arrives from the originator. | |
1374 | * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed. | |
1375 | */ | |
1376 | static void sta_rx_agg_session_timer_expired(unsigned long data) | |
1377 | { | |
1378 | /* not an elegant detour, but there is no choice as the timer passes | |
1379 | * only one argument, and various sta_info are needed here, so init | |
1380 | * flow in sta_info_create gives the TID as data, while the timer_to_id | |
1381 | * array gives the sta through container_of */ | |
1382 | u8 *ptid = (u8 *)data; | |
1383 | u8 *timer_to_id = ptid - *ptid; | |
1384 | struct sta_info *sta = container_of(timer_to_id, struct sta_info, | |
1385 | timer_to_tid[0]); | |
1386 | ||
1387 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
1388 | printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); | |
1389 | #endif | |
1390 | ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->addr, | |
1391 | (u16)*ptid, WLAN_BACK_TIMER, | |
1392 | WLAN_REASON_QSTA_TIMEOUT); | |
1393 | } | |
1394 | ||
f698d856 | 1395 | static void ieee80211_sta_process_addba_request(struct ieee80211_local *local, |
9f985b0e RR |
1396 | struct ieee80211_mgmt *mgmt, |
1397 | size_t len) | |
1398 | { | |
07db2183 RR |
1399 | struct ieee80211_hw *hw = &local->hw; |
1400 | struct ieee80211_conf *conf = &hw->conf; | |
9f985b0e | 1401 | struct sta_info *sta; |
07db2183 RR |
1402 | struct tid_ampdu_rx *tid_agg_rx; |
1403 | u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status; | |
9f985b0e | 1404 | u8 dialog_token; |
07db2183 RR |
1405 | int ret = -EOPNOTSUPP; |
1406 | DECLARE_MAC_BUF(mac); | |
9f985b0e | 1407 | |
d0709a65 JB |
1408 | rcu_read_lock(); |
1409 | ||
9f985b0e | 1410 | sta = sta_info_get(local, mgmt->sa); |
d0709a65 JB |
1411 | if (!sta) { |
1412 | rcu_read_unlock(); | |
9f985b0e | 1413 | return; |
d0709a65 | 1414 | } |
9f985b0e RR |
1415 | |
1416 | /* extract session parameters from addba request frame */ | |
1417 | dialog_token = mgmt->u.action.u.addba_req.dialog_token; | |
1418 | timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout); | |
07db2183 RR |
1419 | start_seq_num = |
1420 | le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4; | |
9f985b0e RR |
1421 | |
1422 | capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); | |
1423 | ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1; | |
1424 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; | |
1425 | buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6; | |
1426 | ||
9f985b0e RR |
1427 | status = WLAN_STATUS_REQUEST_DECLINED; |
1428 | ||
07db2183 RR |
1429 | /* sanity check for incoming parameters: |
1430 | * check if configuration can support the BA policy | |
1431 | * and if buffer size does not exceeds max value */ | |
1432 | if (((ba_policy != 1) | |
1433 | && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA))) | |
1434 | || (buf_size > IEEE80211_MAX_AMPDU_BUF)) { | |
1435 | status = WLAN_STATUS_INVALID_QOS_PARAM; | |
1436 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
1437 | if (net_ratelimit()) | |
7b9d44cd | 1438 | printk(KERN_DEBUG "AddBA Req with bad params from " |
07db2183 RR |
1439 | "%s on tid %u. policy %d, buffer size %d\n", |
1440 | print_mac(mac, mgmt->sa), tid, ba_policy, | |
1441 | buf_size); | |
1442 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
1443 | goto end_no_lock; | |
1444 | } | |
1445 | /* determine default buffer size */ | |
1446 | if (buf_size == 0) { | |
8318d78a JB |
1447 | struct ieee80211_supported_band *sband; |
1448 | ||
1449 | sband = local->hw.wiphy->bands[conf->channel->band]; | |
07db2183 | 1450 | buf_size = IEEE80211_MIN_AMPDU_BUF; |
8318d78a | 1451 | buf_size = buf_size << sband->ht_info.ampdu_factor; |
07db2183 RR |
1452 | } |
1453 | ||
07db2183 RR |
1454 | |
1455 | /* examine state machine */ | |
07346f81 | 1456 | spin_lock_bh(&sta->lock); |
07db2183 | 1457 | |
cee24a3e | 1458 | if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) { |
07db2183 RR |
1459 | #ifdef CONFIG_MAC80211_HT_DEBUG |
1460 | if (net_ratelimit()) | |
7b9d44cd | 1461 | printk(KERN_DEBUG "unexpected AddBA Req from " |
07db2183 RR |
1462 | "%s on tid %u\n", |
1463 | print_mac(mac, mgmt->sa), tid); | |
1464 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
1465 | goto end; | |
1466 | } | |
1467 | ||
cee24a3e RR |
1468 | /* prepare A-MPDU MLME for Rx aggregation */ |
1469 | sta->ampdu_mlme.tid_rx[tid] = | |
1470 | kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC); | |
1471 | if (!sta->ampdu_mlme.tid_rx[tid]) { | |
f4ea83dd | 1472 | #ifdef CONFIG_MAC80211_HT_DEBUG |
cee24a3e RR |
1473 | if (net_ratelimit()) |
1474 | printk(KERN_ERR "allocate rx mlme to tid %d failed\n", | |
1475 | tid); | |
f4ea83dd | 1476 | #endif |
cee24a3e RR |
1477 | goto end; |
1478 | } | |
1479 | /* rx timer */ | |
1480 | sta->ampdu_mlme.tid_rx[tid]->session_timer.function = | |
1481 | sta_rx_agg_session_timer_expired; | |
1482 | sta->ampdu_mlme.tid_rx[tid]->session_timer.data = | |
1483 | (unsigned long)&sta->timer_to_tid[tid]; | |
1484 | init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer); | |
1485 | ||
1486 | tid_agg_rx = sta->ampdu_mlme.tid_rx[tid]; | |
1487 | ||
07db2183 RR |
1488 | /* prepare reordering buffer */ |
1489 | tid_agg_rx->reorder_buf = | |
c97c23e3 | 1490 | kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC); |
03147dfc | 1491 | if (!tid_agg_rx->reorder_buf) { |
f4ea83dd | 1492 | #ifdef CONFIG_MAC80211_HT_DEBUG |
03147dfc JB |
1493 | if (net_ratelimit()) |
1494 | printk(KERN_ERR "can not allocate reordering buffer " | |
1495 | "to tid %d\n", tid); | |
f4ea83dd | 1496 | #endif |
cee24a3e | 1497 | kfree(sta->ampdu_mlme.tid_rx[tid]); |
07db2183 RR |
1498 | goto end; |
1499 | } | |
1500 | memset(tid_agg_rx->reorder_buf, 0, | |
c97c23e3 | 1501 | buf_size * sizeof(struct sk_buff *)); |
07db2183 RR |
1502 | |
1503 | if (local->ops->ampdu_action) | |
1504 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START, | |
0df3ef45 | 1505 | sta->addr, tid, &start_seq_num); |
07db2183 | 1506 | #ifdef CONFIG_MAC80211_HT_DEBUG |
513a1025 | 1507 | printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret); |
07db2183 RR |
1508 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
1509 | ||
1510 | if (ret) { | |
1511 | kfree(tid_agg_rx->reorder_buf); | |
cee24a3e RR |
1512 | kfree(tid_agg_rx); |
1513 | sta->ampdu_mlme.tid_rx[tid] = NULL; | |
07db2183 RR |
1514 | goto end; |
1515 | } | |
1516 | ||
1517 | /* change state and send addba resp */ | |
cee24a3e | 1518 | sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL; |
07db2183 RR |
1519 | tid_agg_rx->dialog_token = dialog_token; |
1520 | tid_agg_rx->ssn = start_seq_num; | |
1521 | tid_agg_rx->head_seq_num = start_seq_num; | |
1522 | tid_agg_rx->buf_size = buf_size; | |
1523 | tid_agg_rx->timeout = timeout; | |
1524 | tid_agg_rx->stored_mpdu_num = 0; | |
1525 | status = WLAN_STATUS_SUCCESS; | |
1526 | end: | |
07346f81 | 1527 | spin_unlock_bh(&sta->lock); |
07db2183 RR |
1528 | |
1529 | end_no_lock: | |
f698d856 | 1530 | ieee80211_send_addba_resp(sta->sdata, sta->addr, tid, |
d0709a65 JB |
1531 | dialog_token, status, 1, buf_size, timeout); |
1532 | rcu_read_unlock(); | |
9f985b0e | 1533 | } |
f0706e82 | 1534 | |
f698d856 | 1535 | static void ieee80211_sta_process_addba_resp(struct ieee80211_local *local, |
eadc8d9e RR |
1536 | struct ieee80211_mgmt *mgmt, |
1537 | size_t len) | |
1538 | { | |
eadc8d9e RR |
1539 | struct ieee80211_hw *hw = &local->hw; |
1540 | struct sta_info *sta; | |
1541 | u16 capab; | |
1542 | u16 tid; | |
1543 | u8 *state; | |
1544 | ||
d0709a65 JB |
1545 | rcu_read_lock(); |
1546 | ||
eadc8d9e | 1547 | sta = sta_info_get(local, mgmt->sa); |
d0709a65 JB |
1548 | if (!sta) { |
1549 | rcu_read_unlock(); | |
eadc8d9e | 1550 | return; |
d0709a65 | 1551 | } |
eadc8d9e RR |
1552 | |
1553 | capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); | |
1554 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; | |
1555 | ||
cee24a3e | 1556 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
eadc8d9e | 1557 | |
07346f81 | 1558 | spin_lock_bh(&sta->lock); |
eadc8d9e | 1559 | |
cee24a3e | 1560 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
07346f81 | 1561 | spin_unlock_bh(&sta->lock); |
cee24a3e RR |
1562 | goto addba_resp_exit; |
1563 | } | |
1564 | ||
eadc8d9e | 1565 | if (mgmt->u.action.u.addba_resp.dialog_token != |
cee24a3e | 1566 | sta->ampdu_mlme.tid_tx[tid]->dialog_token) { |
07346f81 | 1567 | spin_unlock_bh(&sta->lock); |
eadc8d9e RR |
1568 | #ifdef CONFIG_MAC80211_HT_DEBUG |
1569 | printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid); | |
1570 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
cee24a3e | 1571 | goto addba_resp_exit; |
eadc8d9e RR |
1572 | } |
1573 | ||
cee24a3e | 1574 | del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
eadc8d9e RR |
1575 | #ifdef CONFIG_MAC80211_HT_DEBUG |
1576 | printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid); | |
1577 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
1578 | if (le16_to_cpu(mgmt->u.action.u.addba_resp.status) | |
1579 | == WLAN_STATUS_SUCCESS) { | |
eadc8d9e | 1580 | *state |= HT_ADDBA_RECEIVED_MSK; |
cee24a3e | 1581 | sta->ampdu_mlme.addba_req_num[tid] = 0; |
eadc8d9e | 1582 | |
f4ea83dd | 1583 | if (*state == HT_AGG_STATE_OPERATIONAL) |
eadc8d9e | 1584 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); |
eadc8d9e | 1585 | |
07346f81 | 1586 | spin_unlock_bh(&sta->lock); |
eadc8d9e | 1587 | } else { |
cee24a3e | 1588 | sta->ampdu_mlme.addba_req_num[tid]++; |
eadc8d9e RR |
1589 | /* this will allow the state check in stop_BA_session */ |
1590 | *state = HT_AGG_STATE_OPERATIONAL; | |
07346f81 | 1591 | spin_unlock_bh(&sta->lock); |
eadc8d9e RR |
1592 | ieee80211_stop_tx_ba_session(hw, sta->addr, tid, |
1593 | WLAN_BACK_INITIATOR); | |
1594 | } | |
cee24a3e RR |
1595 | |
1596 | addba_resp_exit: | |
d0709a65 | 1597 | rcu_read_unlock(); |
eadc8d9e RR |
1598 | } |
1599 | ||
f698d856 | 1600 | void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, const u8 *da, u16 tid, |
eadc8d9e | 1601 | u16 initiator, u16 reason_code) |
07db2183 | 1602 | { |
f698d856 | 1603 | struct ieee80211_local *local = sdata->local; |
07db2183 RR |
1604 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
1605 | struct sk_buff *skb; | |
1606 | struct ieee80211_mgmt *mgmt; | |
1607 | u16 params; | |
1608 | ||
3acea5b6 | 1609 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
07db2183 RR |
1610 | |
1611 | if (!skb) { | |
1612 | printk(KERN_ERR "%s: failed to allocate buffer " | |
f698d856 | 1613 | "for delba frame\n", sdata->dev->name); |
07db2183 RR |
1614 | return; |
1615 | } | |
1616 | ||
1617 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1618 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
1619 | memset(mgmt, 0, 24); | |
1620 | memcpy(mgmt->da, da, ETH_ALEN); | |
f698d856 | 1621 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
51fb61e7 | 1622 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) |
f698d856 | 1623 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
07db2183 RR |
1624 | else |
1625 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
e7827a70 HH |
1626 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
1627 | IEEE80211_STYPE_ACTION); | |
07db2183 RR |
1628 | |
1629 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba)); | |
1630 | ||
1631 | mgmt->u.action.category = WLAN_CATEGORY_BACK; | |
1632 | mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA; | |
1633 | params = (u16)(initiator << 11); /* bit 11 initiator */ | |
1634 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ | |
1635 | ||
1636 | mgmt->u.action.u.delba.params = cpu_to_le16(params); | |
1637 | mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code); | |
1638 | ||
f698d856 | 1639 | ieee80211_sta_tx(sdata, skb, 0); |
07db2183 RR |
1640 | } |
1641 | ||
f698d856 | 1642 | void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn) |
429a3805 | 1643 | { |
f698d856 | 1644 | struct ieee80211_local *local = sdata->local; |
429a3805 RR |
1645 | struct sk_buff *skb; |
1646 | struct ieee80211_bar *bar; | |
1647 | u16 bar_control = 0; | |
1648 | ||
1649 | skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom); | |
1650 | if (!skb) { | |
1651 | printk(KERN_ERR "%s: failed to allocate buffer for " | |
f698d856 | 1652 | "bar frame\n", sdata->dev->name); |
429a3805 RR |
1653 | return; |
1654 | } | |
1655 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1656 | bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar)); | |
1657 | memset(bar, 0, sizeof(*bar)); | |
e7827a70 HH |
1658 | bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
1659 | IEEE80211_STYPE_BACK_REQ); | |
429a3805 | 1660 | memcpy(bar->ra, ra, ETH_ALEN); |
f698d856 | 1661 | memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN); |
429a3805 RR |
1662 | bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL; |
1663 | bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA; | |
1664 | bar_control |= (u16)(tid << 12); | |
1665 | bar->control = cpu_to_le16(bar_control); | |
1666 | bar->start_seq_num = cpu_to_le16(ssn); | |
1667 | ||
f698d856 | 1668 | ieee80211_sta_tx(sdata, skb, 0); |
429a3805 RR |
1669 | } |
1670 | ||
f698d856 | 1671 | void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, |
07db2183 RR |
1672 | u16 initiator, u16 reason) |
1673 | { | |
f698d856 | 1674 | struct ieee80211_local *local = sdata->local; |
07db2183 RR |
1675 | struct ieee80211_hw *hw = &local->hw; |
1676 | struct sta_info *sta; | |
b580781e | 1677 | int ret, i; |
513a1025 | 1678 | DECLARE_MAC_BUF(mac); |
07db2183 | 1679 | |
d0709a65 JB |
1680 | rcu_read_lock(); |
1681 | ||
07db2183 | 1682 | sta = sta_info_get(local, ra); |
d0709a65 JB |
1683 | if (!sta) { |
1684 | rcu_read_unlock(); | |
07db2183 | 1685 | return; |
d0709a65 | 1686 | } |
07db2183 RR |
1687 | |
1688 | /* check if TID is in operational state */ | |
07346f81 | 1689 | spin_lock_bh(&sta->lock); |
cee24a3e | 1690 | if (sta->ampdu_mlme.tid_state_rx[tid] |
07db2183 | 1691 | != HT_AGG_STATE_OPERATIONAL) { |
07346f81 | 1692 | spin_unlock_bh(&sta->lock); |
d0709a65 | 1693 | rcu_read_unlock(); |
07db2183 RR |
1694 | return; |
1695 | } | |
cee24a3e | 1696 | sta->ampdu_mlme.tid_state_rx[tid] = |
07db2183 RR |
1697 | HT_AGG_STATE_REQ_STOP_BA_MSK | |
1698 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); | |
07346f81 | 1699 | spin_unlock_bh(&sta->lock); |
07db2183 RR |
1700 | |
1701 | /* stop HW Rx aggregation. ampdu_action existence | |
1702 | * already verified in session init so we add the BUG_ON */ | |
1703 | BUG_ON(!local->ops->ampdu_action); | |
1704 | ||
513a1025 RR |
1705 | #ifdef CONFIG_MAC80211_HT_DEBUG |
1706 | printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n", | |
1707 | print_mac(mac, ra), tid); | |
1708 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
1709 | ||
07db2183 | 1710 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, |
0df3ef45 | 1711 | ra, tid, NULL); |
07db2183 RR |
1712 | if (ret) |
1713 | printk(KERN_DEBUG "HW problem - can not stop rx " | |
f4ea83dd | 1714 | "aggregation for tid %d\n", tid); |
07db2183 RR |
1715 | |
1716 | /* shutdown timer has not expired */ | |
1717 | if (initiator != WLAN_BACK_TIMER) | |
cee24a3e | 1718 | del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer); |
07db2183 RR |
1719 | |
1720 | /* check if this is a self generated aggregation halt */ | |
1721 | if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER) | |
f698d856 | 1722 | ieee80211_send_delba(sdata, ra, tid, 0, reason); |
07db2183 RR |
1723 | |
1724 | /* free the reordering buffer */ | |
cee24a3e RR |
1725 | for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) { |
1726 | if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) { | |
b580781e | 1727 | /* release the reordered frames */ |
cee24a3e RR |
1728 | dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]); |
1729 | sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--; | |
1730 | sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL; | |
b580781e RR |
1731 | } |
1732 | } | |
cee24a3e RR |
1733 | /* free resources */ |
1734 | kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf); | |
1735 | kfree(sta->ampdu_mlme.tid_rx[tid]); | |
1736 | sta->ampdu_mlme.tid_rx[tid] = NULL; | |
1737 | sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE; | |
07db2183 | 1738 | |
d0709a65 | 1739 | rcu_read_unlock(); |
07db2183 RR |
1740 | } |
1741 | ||
eadc8d9e | 1742 | |
f698d856 | 1743 | static void ieee80211_sta_process_delba(struct ieee80211_sub_if_data *sdata, |
688b88a4 RR |
1744 | struct ieee80211_mgmt *mgmt, size_t len) |
1745 | { | |
f698d856 | 1746 | struct ieee80211_local *local = sdata->local; |
688b88a4 RR |
1747 | struct sta_info *sta; |
1748 | u16 tid, params; | |
1749 | u16 initiator; | |
1750 | DECLARE_MAC_BUF(mac); | |
1751 | ||
d0709a65 JB |
1752 | rcu_read_lock(); |
1753 | ||
688b88a4 | 1754 | sta = sta_info_get(local, mgmt->sa); |
d0709a65 JB |
1755 | if (!sta) { |
1756 | rcu_read_unlock(); | |
688b88a4 | 1757 | return; |
d0709a65 | 1758 | } |
688b88a4 RR |
1759 | |
1760 | params = le16_to_cpu(mgmt->u.action.u.delba.params); | |
1761 | tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12; | |
1762 | initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11; | |
1763 | ||
1764 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
1765 | if (net_ratelimit()) | |
d92684e6 RR |
1766 | printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n", |
1767 | print_mac(mac, mgmt->sa), | |
2e354ed7 | 1768 | initiator ? "initiator" : "recipient", tid, |
688b88a4 RR |
1769 | mgmt->u.action.u.delba.reason_code); |
1770 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
1771 | ||
1772 | if (initiator == WLAN_BACK_INITIATOR) | |
f698d856 | 1773 | ieee80211_sta_stop_rx_ba_session(sdata, sta->addr, tid, |
688b88a4 | 1774 | WLAN_BACK_INITIATOR, 0); |
d92684e6 | 1775 | else { /* WLAN_BACK_RECIPIENT */ |
07346f81 | 1776 | spin_lock_bh(&sta->lock); |
cee24a3e | 1777 | sta->ampdu_mlme.tid_state_tx[tid] = |
d92684e6 | 1778 | HT_AGG_STATE_OPERATIONAL; |
07346f81 | 1779 | spin_unlock_bh(&sta->lock); |
d92684e6 RR |
1780 | ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid, |
1781 | WLAN_BACK_RECIPIENT); | |
1782 | } | |
d0709a65 | 1783 | rcu_read_unlock(); |
688b88a4 RR |
1784 | } |
1785 | ||
eadc8d9e RR |
1786 | /* |
1787 | * After sending add Block Ack request we activated a timer until | |
1788 | * add Block Ack response will arrive from the recipient. | |
1789 | * If this timer expires sta_addba_resp_timer_expired will be executed. | |
1790 | */ | |
1791 | void sta_addba_resp_timer_expired(unsigned long data) | |
1792 | { | |
1793 | /* not an elegant detour, but there is no choice as the timer passes | |
1794 | * only one argument, and both sta_info and TID are needed, so init | |
73651ee6 | 1795 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
eadc8d9e | 1796 | * array gives the sta through container_of */ |
70d251b2 | 1797 | u16 tid = *(u8 *)data; |
eadc8d9e RR |
1798 | struct sta_info *temp_sta = container_of((void *)data, |
1799 | struct sta_info, timer_to_tid[tid]); | |
1800 | ||
1801 | struct ieee80211_local *local = temp_sta->local; | |
1802 | struct ieee80211_hw *hw = &local->hw; | |
1803 | struct sta_info *sta; | |
1804 | u8 *state; | |
1805 | ||
d0709a65 JB |
1806 | rcu_read_lock(); |
1807 | ||
eadc8d9e | 1808 | sta = sta_info_get(local, temp_sta->addr); |
d0709a65 JB |
1809 | if (!sta) { |
1810 | rcu_read_unlock(); | |
eadc8d9e | 1811 | return; |
d0709a65 | 1812 | } |
eadc8d9e | 1813 | |
cee24a3e | 1814 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
eadc8d9e | 1815 | /* check if the TID waits for addBA response */ |
07346f81 | 1816 | spin_lock_bh(&sta->lock); |
eadc8d9e | 1817 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
07346f81 | 1818 | spin_unlock_bh(&sta->lock); |
eadc8d9e | 1819 | *state = HT_AGG_STATE_IDLE; |
f4ea83dd | 1820 | #ifdef CONFIG_MAC80211_HT_DEBUG |
eadc8d9e RR |
1821 | printk(KERN_DEBUG "timer expired on tid %d but we are not " |
1822 | "expecting addBA response there", tid); | |
f4ea83dd | 1823 | #endif |
eadc8d9e RR |
1824 | goto timer_expired_exit; |
1825 | } | |
1826 | ||
f4ea83dd | 1827 | #ifdef CONFIG_MAC80211_HT_DEBUG |
eadc8d9e | 1828 | printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid); |
f4ea83dd | 1829 | #endif |
eadc8d9e RR |
1830 | |
1831 | /* go through the state check in stop_BA_session */ | |
1832 | *state = HT_AGG_STATE_OPERATIONAL; | |
07346f81 | 1833 | spin_unlock_bh(&sta->lock); |
eadc8d9e RR |
1834 | ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid, |
1835 | WLAN_BACK_INITIATOR); | |
1836 | ||
1837 | timer_expired_exit: | |
d0709a65 | 1838 | rcu_read_unlock(); |
eadc8d9e RR |
1839 | } |
1840 | ||
f698d856 | 1841 | void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr) |
85249e5f | 1842 | { |
f698d856 | 1843 | struct ieee80211_local *local = sdata->local; |
85249e5f RR |
1844 | int i; |
1845 | ||
1846 | for (i = 0; i < STA_TID_NUM; i++) { | |
1847 | ieee80211_stop_tx_ba_session(&local->hw, addr, i, | |
1848 | WLAN_BACK_INITIATOR); | |
f698d856 | 1849 | ieee80211_sta_stop_rx_ba_session(sdata, addr, i, |
85249e5f RR |
1850 | WLAN_BACK_RECIPIENT, |
1851 | WLAN_REASON_QSTA_LEAVE_QBSS); | |
1852 | } | |
1853 | } | |
07db2183 | 1854 | |
f698d856 | 1855 | static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_data *sdata, |
b6623486 AK |
1856 | struct ieee80211_msrment_ie *request_ie, |
1857 | const u8 *da, const u8 *bssid, | |
1858 | u8 dialog_token) | |
1859 | { | |
f698d856 | 1860 | struct ieee80211_local *local = sdata->local; |
b6623486 AK |
1861 | struct sk_buff *skb; |
1862 | struct ieee80211_mgmt *msr_report; | |
1863 | ||
1864 | skb = dev_alloc_skb(sizeof(*msr_report) + local->hw.extra_tx_headroom + | |
1865 | sizeof(struct ieee80211_msrment_ie)); | |
1866 | ||
1867 | if (!skb) { | |
1868 | printk(KERN_ERR "%s: failed to allocate buffer for " | |
f698d856 | 1869 | "measurement report frame\n", sdata->dev->name); |
b6623486 AK |
1870 | return; |
1871 | } | |
1872 | ||
1873 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1874 | msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24); | |
1875 | memset(msr_report, 0, 24); | |
1876 | memcpy(msr_report->da, da, ETH_ALEN); | |
f698d856 | 1877 | memcpy(msr_report->sa, sdata->dev->dev_addr, ETH_ALEN); |
b6623486 | 1878 | memcpy(msr_report->bssid, bssid, ETH_ALEN); |
e7827a70 | 1879 | msr_report->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
b6623486 AK |
1880 | IEEE80211_STYPE_ACTION); |
1881 | ||
1882 | skb_put(skb, 1 + sizeof(msr_report->u.action.u.measurement)); | |
1883 | msr_report->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT; | |
1884 | msr_report->u.action.u.measurement.action_code = | |
1885 | WLAN_ACTION_SPCT_MSR_RPRT; | |
1886 | msr_report->u.action.u.measurement.dialog_token = dialog_token; | |
1887 | ||
1888 | msr_report->u.action.u.measurement.element_id = WLAN_EID_MEASURE_REPORT; | |
1889 | msr_report->u.action.u.measurement.length = | |
1890 | sizeof(struct ieee80211_msrment_ie); | |
1891 | ||
1892 | memset(&msr_report->u.action.u.measurement.msr_elem, 0, | |
1893 | sizeof(struct ieee80211_msrment_ie)); | |
1894 | msr_report->u.action.u.measurement.msr_elem.token = request_ie->token; | |
1895 | msr_report->u.action.u.measurement.msr_elem.mode |= | |
1896 | IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED; | |
1897 | msr_report->u.action.u.measurement.msr_elem.type = request_ie->type; | |
1898 | ||
f698d856 | 1899 | ieee80211_sta_tx(sdata, skb, 0); |
b6623486 AK |
1900 | } |
1901 | ||
f698d856 | 1902 | static void ieee80211_sta_process_measurement_req(struct ieee80211_sub_if_data *sdata, |
b6623486 AK |
1903 | struct ieee80211_mgmt *mgmt, |
1904 | size_t len) | |
1905 | { | |
1906 | /* | |
1907 | * Ignoring measurement request is spec violation. | |
1908 | * Mandatory measurements must be reported optional | |
1909 | * measurements might be refused or reported incapable | |
1910 | * For now just refuse | |
1911 | * TODO: Answer basic measurement as unmeasured | |
1912 | */ | |
f698d856 | 1913 | ieee80211_send_refuse_measurement_request(sdata, |
b6623486 AK |
1914 | &mgmt->u.action.u.measurement.msr_elem, |
1915 | mgmt->sa, mgmt->bssid, | |
1916 | mgmt->u.action.u.measurement.dialog_token); | |
1917 | } | |
1918 | ||
1919 | ||
f698d856 | 1920 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1921 | struct ieee80211_if_sta *ifsta, |
1922 | struct ieee80211_mgmt *mgmt, | |
1923 | size_t len) | |
1924 | { | |
f0706e82 | 1925 | u16 auth_alg, auth_transaction, status_code; |
0795af57 | 1926 | DECLARE_MAC_BUF(mac); |
f0706e82 | 1927 | |
48c2fc59 | 1928 | if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && |
f4ea83dd | 1929 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) |
f0706e82 | 1930 | return; |
f0706e82 | 1931 | |
f4ea83dd | 1932 | if (len < 24 + 6) |
f0706e82 | 1933 | return; |
f0706e82 | 1934 | |
51fb61e7 | 1935 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
f4ea83dd | 1936 | memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
f0706e82 | 1937 | return; |
f0706e82 | 1938 | |
51fb61e7 | 1939 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
f4ea83dd | 1940 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
f0706e82 | 1941 | return; |
f0706e82 JB |
1942 | |
1943 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); | |
1944 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); | |
1945 | status_code = le16_to_cpu(mgmt->u.auth.status_code); | |
1946 | ||
51fb61e7 | 1947 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
135a2110 JB |
1948 | /* |
1949 | * IEEE 802.11 standard does not require authentication in IBSS | |
f0706e82 JB |
1950 | * networks and most implementations do not seem to use it. |
1951 | * However, try to reply to authentication attempts if someone | |
1952 | * has actually implemented this. | |
135a2110 | 1953 | */ |
f4ea83dd | 1954 | if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) |
f0706e82 | 1955 | return; |
f698d856 | 1956 | ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0); |
f0706e82 JB |
1957 | } |
1958 | ||
1959 | if (auth_alg != ifsta->auth_alg || | |
f4ea83dd | 1960 | auth_transaction != ifsta->auth_transaction) |
f0706e82 | 1961 | return; |
f0706e82 JB |
1962 | |
1963 | if (status_code != WLAN_STATUS_SUCCESS) { | |
f0706e82 JB |
1964 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { |
1965 | u8 algs[3]; | |
1966 | const int num_algs = ARRAY_SIZE(algs); | |
1967 | int i, pos; | |
1968 | algs[0] = algs[1] = algs[2] = 0xff; | |
1969 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) | |
1970 | algs[0] = WLAN_AUTH_OPEN; | |
1971 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) | |
1972 | algs[1] = WLAN_AUTH_SHARED_KEY; | |
1973 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) | |
1974 | algs[2] = WLAN_AUTH_LEAP; | |
1975 | if (ifsta->auth_alg == WLAN_AUTH_OPEN) | |
1976 | pos = 0; | |
1977 | else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY) | |
1978 | pos = 1; | |
1979 | else | |
1980 | pos = 2; | |
1981 | for (i = 0; i < num_algs; i++) { | |
1982 | pos++; | |
1983 | if (pos >= num_algs) | |
1984 | pos = 0; | |
1985 | if (algs[pos] == ifsta->auth_alg || | |
1986 | algs[pos] == 0xff) | |
1987 | continue; | |
1988 | if (algs[pos] == WLAN_AUTH_SHARED_KEY && | |
f698d856 | 1989 | !ieee80211_sta_wep_configured(sdata)) |
f0706e82 JB |
1990 | continue; |
1991 | ifsta->auth_alg = algs[pos]; | |
f0706e82 JB |
1992 | break; |
1993 | } | |
1994 | } | |
1995 | return; | |
1996 | } | |
1997 | ||
1998 | switch (ifsta->auth_alg) { | |
1999 | case WLAN_AUTH_OPEN: | |
2000 | case WLAN_AUTH_LEAP: | |
f698d856 | 2001 | ieee80211_auth_completed(sdata, ifsta); |
f0706e82 JB |
2002 | break; |
2003 | case WLAN_AUTH_SHARED_KEY: | |
2004 | if (ifsta->auth_transaction == 4) | |
f698d856 | 2005 | ieee80211_auth_completed(sdata, ifsta); |
f0706e82 | 2006 | else |
f698d856 | 2007 | ieee80211_auth_challenge(sdata, ifsta, mgmt, len); |
f0706e82 JB |
2008 | break; |
2009 | } | |
2010 | } | |
2011 | ||
2012 | ||
f698d856 | 2013 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2014 | struct ieee80211_if_sta *ifsta, |
2015 | struct ieee80211_mgmt *mgmt, | |
2016 | size_t len) | |
2017 | { | |
2018 | u16 reason_code; | |
0795af57 | 2019 | DECLARE_MAC_BUF(mac); |
f0706e82 | 2020 | |
f4ea83dd | 2021 | if (len < 24 + 2) |
f0706e82 | 2022 | return; |
f0706e82 | 2023 | |
f4ea83dd | 2024 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
f0706e82 | 2025 | return; |
f0706e82 JB |
2026 | |
2027 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | |
2028 | ||
988c0f72 | 2029 | if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) |
f698d856 | 2030 | printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name); |
f0706e82 | 2031 | |
48c2fc59 TW |
2032 | if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE || |
2033 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATE || | |
2034 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { | |
9859b81e | 2035 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
f0706e82 JB |
2036 | mod_timer(&ifsta->timer, jiffies + |
2037 | IEEE80211_RETRY_AUTH_INTERVAL); | |
2038 | } | |
2039 | ||
aa458d17 | 2040 | ieee80211_set_disassoc(sdata, ifsta, true, false, 0); |
d6f2da5b | 2041 | ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED; |
f0706e82 JB |
2042 | } |
2043 | ||
2044 | ||
f698d856 | 2045 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2046 | struct ieee80211_if_sta *ifsta, |
2047 | struct ieee80211_mgmt *mgmt, | |
2048 | size_t len) | |
2049 | { | |
2050 | u16 reason_code; | |
0795af57 | 2051 | DECLARE_MAC_BUF(mac); |
f0706e82 | 2052 | |
f4ea83dd | 2053 | if (len < 24 + 2) |
f0706e82 | 2054 | return; |
f0706e82 | 2055 | |
f4ea83dd | 2056 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
f0706e82 | 2057 | return; |
f0706e82 JB |
2058 | |
2059 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); | |
2060 | ||
d6f2da5b | 2061 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
f698d856 | 2062 | printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name); |
f0706e82 | 2063 | |
48c2fc59 TW |
2064 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { |
2065 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; | |
f0706e82 JB |
2066 | mod_timer(&ifsta->timer, jiffies + |
2067 | IEEE80211_RETRY_AUTH_INTERVAL); | |
2068 | } | |
2069 | ||
aa458d17 | 2070 | ieee80211_set_disassoc(sdata, ifsta, false, false, 0); |
f0706e82 JB |
2071 | } |
2072 | ||
2073 | ||
471b3efd | 2074 | static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2075 | struct ieee80211_if_sta *ifsta, |
2076 | struct ieee80211_mgmt *mgmt, | |
2077 | size_t len, | |
2078 | int reassoc) | |
2079 | { | |
471b3efd | 2080 | struct ieee80211_local *local = sdata->local; |
8318d78a | 2081 | struct ieee80211_supported_band *sband; |
f0706e82 | 2082 | struct sta_info *sta; |
8318d78a | 2083 | u64 rates, basic_rates; |
f0706e82 JB |
2084 | u16 capab_info, status_code, aid; |
2085 | struct ieee802_11_elems elems; | |
471b3efd | 2086 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
f0706e82 JB |
2087 | u8 *pos; |
2088 | int i, j; | |
0795af57 | 2089 | DECLARE_MAC_BUF(mac); |
8318d78a | 2090 | bool have_higher_than_11mbit = false; |
f0706e82 JB |
2091 | |
2092 | /* AssocResp and ReassocResp have identical structure, so process both | |
2093 | * of them in this function. */ | |
2094 | ||
48c2fc59 | 2095 | if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE) |
f0706e82 | 2096 | return; |
f0706e82 | 2097 | |
f4ea83dd | 2098 | if (len < 24 + 6) |
f0706e82 | 2099 | return; |
f0706e82 | 2100 | |
f4ea83dd | 2101 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
f0706e82 | 2102 | return; |
f0706e82 JB |
2103 | |
2104 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); | |
2105 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); | |
2106 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); | |
f0706e82 | 2107 | |
0795af57 | 2108 | printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x " |
f0706e82 | 2109 | "status=%d aid=%d)\n", |
f698d856 | 2110 | sdata->dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa), |
ddd68587 | 2111 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
f0706e82 JB |
2112 | |
2113 | if (status_code != WLAN_STATUS_SUCCESS) { | |
2114 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", | |
f698d856 | 2115 | sdata->dev->name, status_code); |
8a69aa93 DD |
2116 | /* if this was a reassociation, ensure we try a "full" |
2117 | * association next time. This works around some broken APs | |
2118 | * which do not correctly reject reassociation requests. */ | |
d6f2da5b | 2119 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
f0706e82 JB |
2120 | return; |
2121 | } | |
2122 | ||
1dd84aa2 JB |
2123 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
2124 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " | |
f698d856 | 2125 | "set\n", sdata->dev->name, aid); |
1dd84aa2 JB |
2126 | aid &= ~(BIT(15) | BIT(14)); |
2127 | ||
f0706e82 | 2128 | pos = mgmt->u.assoc_resp.variable; |
67a4cce4 | 2129 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
f0706e82 JB |
2130 | |
2131 | if (!elems.supp_rates) { | |
2132 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", | |
f698d856 | 2133 | sdata->dev->name); |
f0706e82 JB |
2134 | return; |
2135 | } | |
2136 | ||
f698d856 | 2137 | printk(KERN_DEBUG "%s: associated\n", sdata->dev->name); |
f0706e82 JB |
2138 | ifsta->aid = aid; |
2139 | ifsta->ap_capab = capab_info; | |
2140 | ||
2141 | kfree(ifsta->assocresp_ies); | |
2142 | ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt); | |
0ec0b7ac | 2143 | ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL); |
f0706e82 JB |
2144 | if (ifsta->assocresp_ies) |
2145 | memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); | |
2146 | ||
d0709a65 JB |
2147 | rcu_read_lock(); |
2148 | ||
f0706e82 JB |
2149 | /* Add STA entry for the AP */ |
2150 | sta = sta_info_get(local, ifsta->bssid); | |
2151 | if (!sta) { | |
2152 | struct ieee80211_sta_bss *bss; | |
73651ee6 | 2153 | int err; |
d0709a65 | 2154 | |
73651ee6 JB |
2155 | sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC); |
2156 | if (!sta) { | |
2157 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" | |
f698d856 | 2158 | " the AP\n", sdata->dev->name); |
d0709a65 | 2159 | rcu_read_unlock(); |
f0706e82 JB |
2160 | return; |
2161 | } | |
60f8b39c JB |
2162 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
2163 | local->hw.conf.channel->center_freq, | |
2164 | ifsta->ssid, ifsta->ssid_len); | |
2165 | if (bss) { | |
2166 | sta->last_signal = bss->signal; | |
2167 | sta->last_qual = bss->qual; | |
2168 | sta->last_noise = bss->noise; | |
2169 | ieee80211_rx_bss_put(local, bss); | |
2170 | } | |
f709fc69 | 2171 | |
60f8b39c JB |
2172 | err = sta_info_insert(sta); |
2173 | if (err) { | |
2174 | printk(KERN_DEBUG "%s: failed to insert STA entry for" | |
2175 | " the AP (error %d)\n", sdata->dev->name, err); | |
2176 | rcu_read_unlock(); | |
2177 | return; | |
f709fc69 | 2178 | } |
60f8b39c JB |
2179 | /* update new sta with its last rx activity */ |
2180 | sta->last_rx = jiffies; | |
f709fc69 | 2181 | } |
f709fc69 | 2182 | |
60f8b39c JB |
2183 | /* |
2184 | * FIXME: Do we really need to update the sta_info's information here? | |
2185 | * We already know about the AP (we found it in our list) so it | |
2186 | * should already be filled with the right info, no? | |
2187 | * As is stands, all this is racy because typically we assume | |
2188 | * the information that is filled in here (except flags) doesn't | |
2189 | * change while a STA structure is alive. As such, it should move | |
2190 | * to between the sta_info_alloc() and sta_info_insert() above. | |
2191 | */ | |
f709fc69 | 2192 | |
60f8b39c JB |
2193 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | |
2194 | WLAN_STA_AUTHORIZED); | |
05e5e883 | 2195 | |
60f8b39c JB |
2196 | rates = 0; |
2197 | basic_rates = 0; | |
2198 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
f709fc69 | 2199 | |
60f8b39c JB |
2200 | for (i = 0; i < elems.supp_rates_len; i++) { |
2201 | int rate = (elems.supp_rates[i] & 0x7f) * 5; | |
f709fc69 | 2202 | |
60f8b39c JB |
2203 | if (rate > 110) |
2204 | have_higher_than_11mbit = true; | |
2205 | ||
2206 | for (j = 0; j < sband->n_bitrates; j++) { | |
2207 | if (sband->bitrates[j].bitrate == rate) | |
2208 | rates |= BIT(j); | |
2209 | if (elems.supp_rates[i] & 0x80) | |
2210 | basic_rates |= BIT(j); | |
f709fc69 | 2211 | } |
f709fc69 LCC |
2212 | } |
2213 | ||
60f8b39c JB |
2214 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
2215 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; | |
f0706e82 | 2216 | |
60f8b39c JB |
2217 | if (rate > 110) |
2218 | have_higher_than_11mbit = true; | |
f0706e82 | 2219 | |
60f8b39c JB |
2220 | for (j = 0; j < sband->n_bitrates; j++) { |
2221 | if (sband->bitrates[j].bitrate == rate) | |
2222 | rates |= BIT(j); | |
2223 | if (elems.ext_supp_rates[i] & 0x80) | |
2224 | basic_rates |= BIT(j); | |
2225 | } | |
1ebebea8 | 2226 | } |
f0706e82 | 2227 | |
60f8b39c JB |
2228 | sta->supp_rates[local->hw.conf.channel->band] = rates; |
2229 | sdata->basic_rates = basic_rates; | |
2230 | ||
2231 | /* cf. IEEE 802.11 9.2.12 */ | |
2232 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
2233 | have_higher_than_11mbit) | |
2234 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
2235 | else | |
2236 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
f0706e82 | 2237 | |
60f8b39c JB |
2238 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
2239 | (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { | |
2240 | struct ieee80211_ht_bss_info bss_info; | |
2241 | ieee80211_ht_cap_ie_to_ht_info( | |
2242 | (struct ieee80211_ht_cap *) | |
2243 | elems.ht_cap_elem, &sta->ht_info); | |
2244 | ieee80211_ht_addt_info_ie_to_ht_bss_info( | |
2245 | (struct ieee80211_ht_addt_info *) | |
2246 | elems.ht_info_elem, &bss_info); | |
2247 | ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info); | |
2248 | } | |
f0706e82 | 2249 | |
60f8b39c | 2250 | rate_control_rate_init(sta, local); |
f0706e82 | 2251 | |
60f8b39c JB |
2252 | if (elems.wmm_param) { |
2253 | set_sta_flags(sta, WLAN_STA_WME); | |
2254 | rcu_read_unlock(); | |
2255 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, | |
2256 | elems.wmm_param_len); | |
2257 | } else | |
2258 | rcu_read_unlock(); | |
f0706e82 | 2259 | |
60f8b39c JB |
2260 | /* set AID and assoc capability, |
2261 | * ieee80211_set_associated() will tell the driver */ | |
2262 | bss_conf->aid = aid; | |
2263 | bss_conf->assoc_capability = capab_info; | |
2264 | ieee80211_set_associated(sdata, ifsta); | |
f0706e82 | 2265 | |
60f8b39c | 2266 | ieee80211_associated(sdata, ifsta); |
f0706e82 JB |
2267 | } |
2268 | ||
2269 | ||
f698d856 | 2270 | static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
a607268a BR |
2271 | struct ieee80211_if_sta *ifsta, |
2272 | struct ieee80211_sta_bss *bss) | |
2273 | { | |
f698d856 | 2274 | struct ieee80211_local *local = sdata->local; |
a607268a BR |
2275 | int res, rates, i, j; |
2276 | struct sk_buff *skb; | |
2277 | struct ieee80211_mgmt *mgmt; | |
a607268a | 2278 | u8 *pos; |
a607268a | 2279 | struct ieee80211_supported_band *sband; |
507b06d0 | 2280 | union iwreq_data wrqu; |
a607268a BR |
2281 | |
2282 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
2283 | ||
2284 | /* Remove possible STA entries from other IBSS networks. */ | |
dc6676b7 | 2285 | sta_info_flush_delayed(sdata); |
a607268a BR |
2286 | |
2287 | if (local->ops->reset_tsf) { | |
2288 | /* Reset own TSF to allow time synchronization work. */ | |
2289 | local->ops->reset_tsf(local_to_hw(local)); | |
2290 | } | |
2291 | memcpy(ifsta->bssid, bss->bssid, ETH_ALEN); | |
9d139c81 | 2292 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); |
a607268a BR |
2293 | if (res) |
2294 | return res; | |
2295 | ||
2296 | local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10; | |
2297 | ||
a607268a BR |
2298 | sdata->drop_unencrypted = bss->capability & |
2299 | WLAN_CAPABILITY_PRIVACY ? 1 : 0; | |
2300 | ||
f698d856 | 2301 | res = ieee80211_set_freq(sdata, bss->freq); |
a607268a | 2302 | |
be038b37 AK |
2303 | if (res) |
2304 | return res; | |
a607268a | 2305 | |
9d139c81 | 2306 | /* Build IBSS probe response */ |
a607268a | 2307 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
9d139c81 | 2308 | if (skb) { |
a607268a BR |
2309 | skb_reserve(skb, local->hw.extra_tx_headroom); |
2310 | ||
2311 | mgmt = (struct ieee80211_mgmt *) | |
2312 | skb_put(skb, 24 + sizeof(mgmt->u.beacon)); | |
2313 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); | |
e7827a70 HH |
2314 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
2315 | IEEE80211_STYPE_PROBE_RESP); | |
a607268a | 2316 | memset(mgmt->da, 0xff, ETH_ALEN); |
f698d856 | 2317 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
a607268a BR |
2318 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
2319 | mgmt->u.beacon.beacon_int = | |
2320 | cpu_to_le16(local->hw.conf.beacon_int); | |
4faeb860 | 2321 | mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp); |
a607268a BR |
2322 | mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability); |
2323 | ||
2324 | pos = skb_put(skb, 2 + ifsta->ssid_len); | |
2325 | *pos++ = WLAN_EID_SSID; | |
2326 | *pos++ = ifsta->ssid_len; | |
2327 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); | |
2328 | ||
2329 | rates = bss->supp_rates_len; | |
2330 | if (rates > 8) | |
2331 | rates = 8; | |
2332 | pos = skb_put(skb, 2 + rates); | |
2333 | *pos++ = WLAN_EID_SUPP_RATES; | |
2334 | *pos++ = rates; | |
2335 | memcpy(pos, bss->supp_rates, rates); | |
2336 | ||
2337 | if (bss->band == IEEE80211_BAND_2GHZ) { | |
2338 | pos = skb_put(skb, 2 + 1); | |
2339 | *pos++ = WLAN_EID_DS_PARAMS; | |
2340 | *pos++ = 1; | |
2341 | *pos++ = ieee80211_frequency_to_channel(bss->freq); | |
2342 | } | |
2343 | ||
2344 | pos = skb_put(skb, 2 + 2); | |
2345 | *pos++ = WLAN_EID_IBSS_PARAMS; | |
2346 | *pos++ = 2; | |
2347 | /* FIX: set ATIM window based on scan results */ | |
2348 | *pos++ = 0; | |
2349 | *pos++ = 0; | |
2350 | ||
2351 | if (bss->supp_rates_len > 8) { | |
2352 | rates = bss->supp_rates_len - 8; | |
2353 | pos = skb_put(skb, 2 + rates); | |
2354 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
2355 | *pos++ = rates; | |
2356 | memcpy(pos, &bss->supp_rates[8], rates); | |
2357 | } | |
2358 | ||
9d139c81 | 2359 | ifsta->probe_resp = skb; |
e039fa4a | 2360 | |
9d139c81 JB |
2361 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
2362 | } | |
a607268a | 2363 | |
9d139c81 JB |
2364 | rates = 0; |
2365 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
2366 | for (i = 0; i < bss->supp_rates_len; i++) { | |
2367 | int bitrate = (bss->supp_rates[i] & 0x7f) * 5; | |
2368 | for (j = 0; j < sband->n_bitrates; j++) | |
2369 | if (sband->bitrates[j].bitrate == bitrate) | |
2370 | rates |= BIT(j); | |
a607268a | 2371 | } |
9d139c81 JB |
2372 | ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates; |
2373 | ||
f698d856 | 2374 | ieee80211_sta_def_wmm_params(sdata, bss, 1); |
a607268a | 2375 | |
48c2fc59 | 2376 | ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED; |
a607268a BR |
2377 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
2378 | ||
507b06d0 DW |
2379 | memset(&wrqu, 0, sizeof(wrqu)); |
2380 | memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); | |
f698d856 | 2381 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); |
a607268a BR |
2382 | |
2383 | return res; | |
2384 | } | |
2385 | ||
f709fc69 LCC |
2386 | u64 ieee80211_sta_get_rates(struct ieee80211_local *local, |
2387 | struct ieee802_11_elems *elems, | |
2388 | enum ieee80211_band band) | |
2389 | { | |
2390 | struct ieee80211_supported_band *sband; | |
2391 | struct ieee80211_rate *bitrates; | |
2392 | size_t num_rates; | |
2393 | u64 supp_rates; | |
2394 | int i, j; | |
2395 | sband = local->hw.wiphy->bands[band]; | |
2396 | ||
2397 | if (!sband) { | |
2398 | WARN_ON(1); | |
2399 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
2400 | } | |
2401 | ||
2402 | bitrates = sband->bitrates; | |
2403 | num_rates = sband->n_bitrates; | |
2404 | supp_rates = 0; | |
2405 | for (i = 0; i < elems->supp_rates_len + | |
2406 | elems->ext_supp_rates_len; i++) { | |
2407 | u8 rate = 0; | |
2408 | int own_rate; | |
2409 | if (i < elems->supp_rates_len) | |
2410 | rate = elems->supp_rates[i]; | |
2411 | else if (elems->ext_supp_rates) | |
2412 | rate = elems->ext_supp_rates | |
2413 | [i - elems->supp_rates_len]; | |
2414 | own_rate = 5 * (rate & 0x7f); | |
2415 | for (j = 0; j < num_rates; j++) | |
2416 | if (bitrates[j].bitrate == own_rate) | |
2417 | supp_rates |= BIT(j); | |
2418 | } | |
2419 | return supp_rates; | |
2420 | } | |
2421 | ||
8e1535d5 EG |
2422 | static u64 ieee80211_sta_get_mandatory_rates(struct ieee80211_local *local, |
2423 | enum ieee80211_band band) | |
2424 | { | |
2425 | struct ieee80211_supported_band *sband; | |
2426 | struct ieee80211_rate *bitrates; | |
2427 | u64 mandatory_rates; | |
2428 | enum ieee80211_rate_flags mandatory_flag; | |
2429 | int i; | |
2430 | ||
2431 | sband = local->hw.wiphy->bands[band]; | |
2432 | if (!sband) { | |
2433 | WARN_ON(1); | |
2434 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
2435 | } | |
2436 | ||
2437 | if (band == IEEE80211_BAND_2GHZ) | |
2438 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; | |
2439 | else | |
2440 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; | |
2441 | ||
2442 | bitrates = sband->bitrates; | |
2443 | mandatory_rates = 0; | |
2444 | for (i = 0; i < sband->n_bitrates; i++) | |
2445 | if (bitrates[i].flags & mandatory_flag) | |
2446 | mandatory_rates |= BIT(i); | |
2447 | return mandatory_rates; | |
2448 | } | |
a607268a | 2449 | |
f698d856 | 2450 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2451 | struct ieee80211_mgmt *mgmt, |
2452 | size_t len, | |
2453 | struct ieee80211_rx_status *rx_status, | |
9859b81e | 2454 | struct ieee802_11_elems *elems) |
f0706e82 | 2455 | { |
f698d856 | 2456 | struct ieee80211_local *local = sdata->local; |
8318d78a | 2457 | int freq, clen; |
f0706e82 JB |
2458 | struct ieee80211_sta_bss *bss; |
2459 | struct sta_info *sta; | |
fab7d4a2 | 2460 | struct ieee80211_channel *channel; |
8e1535d5 EG |
2461 | u64 beacon_timestamp, rx_timestamp; |
2462 | u64 supp_rates = 0; | |
9859b81e | 2463 | bool beacon = ieee80211_is_beacon(mgmt->frame_control); |
8e1535d5 | 2464 | enum ieee80211_band band = rx_status->band; |
0795af57 JP |
2465 | DECLARE_MAC_BUF(mac); |
2466 | DECLARE_MAC_BUF(mac2); | |
f0706e82 | 2467 | |
5bda6175 JB |
2468 | if (elems->ds_params && elems->ds_params_len == 1) |
2469 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); | |
2470 | else | |
2471 | freq = rx_status->freq; | |
2472 | ||
2473 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
2474 | ||
2475 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
2476 | return; | |
f0706e82 | 2477 | |
ae6a44e3 | 2478 | if (ieee80211_vif_is_mesh(&sdata->vif) && elems->mesh_id && |
f698d856 | 2479 | elems->mesh_config && mesh_matches_local(elems, sdata)) { |
8e1535d5 | 2480 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
902acc78 | 2481 | |
8e1535d5 | 2482 | mesh_neighbour_update(mgmt->sa, supp_rates, sdata, |
f698d856 | 2483 | mesh_peer_accepts_plinks(elems)); |
902acc78 | 2484 | } |
f709fc69 | 2485 | |
ae6a44e3 | 2486 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems->supp_rates && |
8e1535d5 | 2487 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { |
8e1535d5 EG |
2488 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
2489 | ||
69e6c010 JB |
2490 | rcu_read_lock(); |
2491 | ||
8e1535d5 EG |
2492 | sta = sta_info_get(local, mgmt->sa); |
2493 | if (sta) { | |
2494 | u64 prev_rates; | |
2495 | ||
2496 | prev_rates = sta->supp_rates[band]; | |
2497 | /* make sure mandatory rates are always added */ | |
2498 | sta->supp_rates[band] = supp_rates | | |
2499 | ieee80211_sta_get_mandatory_rates(local, band); | |
2500 | ||
2501 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
2502 | if (sta->supp_rates[band] != prev_rates) | |
2503 | printk(KERN_DEBUG "%s: updated supp_rates set " | |
2504 | "for %s based on beacon info (0x%llx | " | |
2505 | "0x%llx -> 0x%llx)\n", | |
2506 | sdata->dev->name, print_mac(mac, sta->addr), | |
2507 | (unsigned long long) prev_rates, | |
2508 | (unsigned long long) supp_rates, | |
2509 | (unsigned long long) sta->supp_rates[band]); | |
2510 | #endif | |
2511 | } else { | |
2512 | ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid, | |
2513 | mgmt->sa, supp_rates); | |
f0706e82 | 2514 | } |
f0706e82 | 2515 | |
69e6c010 JB |
2516 | rcu_read_unlock(); |
2517 | } | |
d0709a65 | 2518 | |
f709fc69 | 2519 | #ifdef CONFIG_MAC80211_MESH |
ae6a44e3 | 2520 | if (elems->mesh_config) |
f698d856 | 2521 | bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id, |
ae6a44e3 | 2522 | elems->mesh_id_len, elems->mesh_config, freq); |
f709fc69 LCC |
2523 | else |
2524 | #endif | |
f698d856 | 2525 | bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq, |
ae6a44e3 | 2526 | elems->ssid, elems->ssid_len); |
f709fc69 LCC |
2527 | if (!bss) { |
2528 | #ifdef CONFIG_MAC80211_MESH | |
ae6a44e3 | 2529 | if (elems->mesh_config) |
f698d856 | 2530 | bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id, |
ae6a44e3 EK |
2531 | elems->mesh_id_len, elems->mesh_config, |
2532 | elems->mesh_config_len, freq); | |
f709fc69 LCC |
2533 | else |
2534 | #endif | |
f698d856 | 2535 | bss = ieee80211_rx_bss_add(sdata, mgmt->bssid, freq, |
ae6a44e3 | 2536 | elems->ssid, elems->ssid_len); |
f0706e82 JB |
2537 | if (!bss) |
2538 | return; | |
2539 | } else { | |
2540 | #if 0 | |
2541 | /* TODO: order by RSSI? */ | |
2542 | spin_lock_bh(&local->sta_bss_lock); | |
2543 | list_move_tail(&bss->list, &local->sta_bss_list); | |
2544 | spin_unlock_bh(&local->sta_bss_lock); | |
2545 | #endif | |
2546 | } | |
2547 | ||
5628221c | 2548 | /* save the ERP value so that it is available at association time */ |
ae6a44e3 EK |
2549 | if (elems->erp_info && elems->erp_info_len >= 1) { |
2550 | bss->erp_value = elems->erp_info[0]; | |
5628221c DD |
2551 | bss->has_erp_value = 1; |
2552 | } | |
2553 | ||
f0706e82 JB |
2554 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); |
2555 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); | |
f0706e82 | 2556 | |
98f7dfd8 EG |
2557 | if (elems->tim) { |
2558 | struct ieee80211_tim_ie *tim_ie = | |
2559 | (struct ieee80211_tim_ie *)elems->tim; | |
2560 | bss->dtim_period = tim_ie->dtim_period; | |
2561 | } | |
2562 | ||
2563 | /* set default value for buggy APs */ | |
2564 | if (!elems->tim || bss->dtim_period == 0) | |
2565 | bss->dtim_period = 1; | |
2566 | ||
f0706e82 | 2567 | bss->supp_rates_len = 0; |
ae6a44e3 | 2568 | if (elems->supp_rates) { |
f0706e82 | 2569 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
ae6a44e3 EK |
2570 | if (clen > elems->supp_rates_len) |
2571 | clen = elems->supp_rates_len; | |
2572 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates, | |
f0706e82 JB |
2573 | clen); |
2574 | bss->supp_rates_len += clen; | |
2575 | } | |
ae6a44e3 | 2576 | if (elems->ext_supp_rates) { |
f0706e82 | 2577 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
ae6a44e3 EK |
2578 | if (clen > elems->ext_supp_rates_len) |
2579 | clen = elems->ext_supp_rates_len; | |
f0706e82 | 2580 | memcpy(&bss->supp_rates[bss->supp_rates_len], |
ae6a44e3 | 2581 | elems->ext_supp_rates, clen); |
f0706e82 JB |
2582 | bss->supp_rates_len += clen; |
2583 | } | |
2584 | ||
8e1535d5 | 2585 | bss->band = band; |
30b89b0f | 2586 | |
5bda6175 JB |
2587 | beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); |
2588 | ||
30b89b0f JB |
2589 | bss->timestamp = beacon_timestamp; |
2590 | bss->last_update = jiffies; | |
30b89b0f JB |
2591 | bss->signal = rx_status->signal; |
2592 | bss->noise = rx_status->noise; | |
566bfe5a | 2593 | bss->qual = rx_status->qual; |
9859b81e RR |
2594 | if (!beacon) |
2595 | bss->last_probe_resp = jiffies; | |
30b89b0f JB |
2596 | /* |
2597 | * In STA mode, the remaining parameters should not be overridden | |
2598 | * by beacons because they're not necessarily accurate there. | |
2599 | */ | |
2600 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && | |
9859b81e | 2601 | bss->last_probe_resp && beacon) { |
3e122be0 | 2602 | ieee80211_rx_bss_put(local, bss); |
30b89b0f JB |
2603 | return; |
2604 | } | |
2605 | ||
43ac2ca3 JM |
2606 | if (bss->ies == NULL || bss->ies_len < elems->total_len) { |
2607 | kfree(bss->ies); | |
2608 | bss->ies = kmalloc(elems->total_len, GFP_ATOMIC); | |
f0706e82 | 2609 | } |
43ac2ca3 JM |
2610 | if (bss->ies) { |
2611 | memcpy(bss->ies, elems->ie_start, elems->total_len); | |
2612 | bss->ies_len = elems->total_len; | |
2613 | } else | |
2614 | bss->ies_len = 0; | |
f0706e82 | 2615 | |
43ac2ca3 | 2616 | bss->wmm_used = elems->wmm_param || elems->wmm_info; |
9d9bf77d BR |
2617 | |
2618 | /* check if we need to merge IBSS */ | |
2619 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon && | |
2620 | !local->sta_sw_scanning && !local->sta_hw_scanning && | |
fba4a1e6 | 2621 | bss->capability & WLAN_CAPABILITY_IBSS && |
9d9bf77d | 2622 | bss->freq == local->oper_channel->center_freq && |
ae6a44e3 EK |
2623 | elems->ssid_len == sdata->u.sta.ssid_len && |
2624 | memcmp(elems->ssid, sdata->u.sta.ssid, | |
2625 | sdata->u.sta.ssid_len) == 0) { | |
9d9bf77d BR |
2626 | if (rx_status->flag & RX_FLAG_TSFT) { |
2627 | /* in order for correct IBSS merging we need mactime | |
2628 | * | |
2629 | * since mactime is defined as the time the first data | |
2630 | * symbol of the frame hits the PHY, and the timestamp | |
2631 | * of the beacon is defined as "the time that the data | |
2632 | * symbol containing the first bit of the timestamp is | |
2633 | * transmitted to the PHY plus the transmitting STA’s | |
2634 | * delays through its local PHY from the MAC-PHY | |
2635 | * interface to its interface with the WM" | |
2636 | * (802.11 11.1.2) - equals the time this bit arrives at | |
2637 | * the receiver - we have to take into account the | |
2638 | * offset between the two. | |
2639 | * e.g: at 1 MBit that means mactime is 192 usec earlier | |
2640 | * (=24 bytes * 8 usecs/byte) than the beacon timestamp. | |
2641 | */ | |
8e1535d5 | 2642 | int rate = local->hw.wiphy->bands[band]-> |
9d9bf77d BR |
2643 | bitrates[rx_status->rate_idx].bitrate; |
2644 | rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); | |
2645 | } else if (local && local->ops && local->ops->get_tsf) | |
2646 | /* second best option: get current TSF */ | |
2647 | rx_timestamp = local->ops->get_tsf(local_to_hw(local)); | |
2648 | else | |
2649 | /* can't merge without knowing the TSF */ | |
2650 | rx_timestamp = -1LLU; | |
2651 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
2652 | printk(KERN_DEBUG "RX beacon SA=%s BSSID=" | |
2653 | "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", | |
2654 | print_mac(mac, mgmt->sa), | |
2655 | print_mac(mac2, mgmt->bssid), | |
2656 | (unsigned long long)rx_timestamp, | |
2657 | (unsigned long long)beacon_timestamp, | |
2658 | (unsigned long long)(rx_timestamp - beacon_timestamp), | |
2659 | jiffies); | |
2660 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | |
2661 | if (beacon_timestamp > rx_timestamp) { | |
576fdeae | 2662 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
f4ea83dd JB |
2663 | printk(KERN_DEBUG "%s: beacon TSF higher than " |
2664 | "local TSF - IBSS merge with BSSID %s\n", | |
f698d856 | 2665 | sdata->dev->name, print_mac(mac, mgmt->bssid)); |
fba4a1e6 | 2666 | #endif |
f698d856 JBG |
2667 | ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss); |
2668 | ieee80211_ibss_add_sta(sdata, NULL, | |
87291c02 | 2669 | mgmt->bssid, mgmt->sa, |
8e1535d5 | 2670 | supp_rates); |
9d9bf77d BR |
2671 | } |
2672 | } | |
2673 | ||
3e122be0 | 2674 | ieee80211_rx_bss_put(local, bss); |
f0706e82 JB |
2675 | } |
2676 | ||
2677 | ||
f698d856 | 2678 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2679 | struct ieee80211_mgmt *mgmt, |
2680 | size_t len, | |
2681 | struct ieee80211_rx_status *rx_status) | |
2682 | { | |
ae6a44e3 EK |
2683 | size_t baselen; |
2684 | struct ieee802_11_elems elems; | |
9859b81e | 2685 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
ae6a44e3 | 2686 | |
8e7cdbb6 TW |
2687 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) |
2688 | return; /* ignore ProbeResp to foreign address */ | |
2689 | ||
ae6a44e3 EK |
2690 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
2691 | if (baselen > len) | |
2692 | return; | |
2693 | ||
2694 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
2695 | &elems); | |
2696 | ||
9859b81e RR |
2697 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); |
2698 | ||
2699 | /* direct probe may be part of the association flow */ | |
2700 | if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE, | |
2701 | &ifsta->request)) { | |
2702 | printk(KERN_DEBUG "%s direct probe responded\n", | |
2703 | sdata->dev->name); | |
2704 | ieee80211_authenticate(sdata, ifsta); | |
2705 | } | |
f0706e82 JB |
2706 | } |
2707 | ||
2708 | ||
f698d856 | 2709 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2710 | struct ieee80211_mgmt *mgmt, |
2711 | size_t len, | |
2712 | struct ieee80211_rx_status *rx_status) | |
2713 | { | |
f0706e82 | 2714 | struct ieee80211_if_sta *ifsta; |
f0706e82 JB |
2715 | size_t baselen; |
2716 | struct ieee802_11_elems elems; | |
f698d856 | 2717 | struct ieee80211_local *local = sdata->local; |
d3c990fb | 2718 | struct ieee80211_conf *conf = &local->hw.conf; |
471b3efd | 2719 | u32 changed = 0; |
f0706e82 | 2720 | |
ae6a44e3 EK |
2721 | /* Process beacon from the current BSS */ |
2722 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | |
2723 | if (baselen > len) | |
2724 | return; | |
2725 | ||
2726 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); | |
2727 | ||
9859b81e | 2728 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); |
f0706e82 | 2729 | |
51fb61e7 | 2730 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
f0706e82 JB |
2731 | return; |
2732 | ifsta = &sdata->u.sta; | |
2733 | ||
d6f2da5b | 2734 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) || |
f0706e82 JB |
2735 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
2736 | return; | |
2737 | ||
d18ef29f | 2738 | /* Do not send changes to driver if we are scanning. This removes |
fe3fa827 JB |
2739 | * requirement that a driver's bss_info_changed/conf_tx functions |
2740 | * need to be atomic. | |
2741 | * This is really ugly code, we should rewrite scanning and make | |
2742 | * all this more understandable for humans. | |
2743 | */ | |
d18ef29f RC |
2744 | if (local->sta_sw_scanning || local->sta_hw_scanning) |
2745 | return; | |
2746 | ||
fe3fa827 JB |
2747 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, |
2748 | elems.wmm_param_len); | |
2749 | ||
5628221c | 2750 | if (elems.erp_info && elems.erp_info_len >= 1) |
471b3efd | 2751 | changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]); |
50c4afb9 JL |
2752 | else { |
2753 | u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info); | |
2754 | changed |= ieee80211_handle_protect_preamb(sdata, false, | |
2755 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); | |
2756 | } | |
f0706e82 | 2757 | |
d3c990fb | 2758 | if (elems.ht_cap_elem && elems.ht_info_elem && |
38668c05 | 2759 | elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
d3c990fb RR |
2760 | struct ieee80211_ht_bss_info bss_info; |
2761 | ||
2762 | ieee80211_ht_addt_info_ie_to_ht_bss_info( | |
2763 | (struct ieee80211_ht_addt_info *) | |
2764 | elems.ht_info_elem, &bss_info); | |
38668c05 TW |
2765 | changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf, |
2766 | &bss_info); | |
d3c990fb RR |
2767 | } |
2768 | ||
471b3efd | 2769 | ieee80211_bss_info_change_notify(sdata, changed); |
f0706e82 JB |
2770 | } |
2771 | ||
2772 | ||
f698d856 | 2773 | static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2774 | struct ieee80211_if_sta *ifsta, |
2775 | struct ieee80211_mgmt *mgmt, | |
2776 | size_t len, | |
2777 | struct ieee80211_rx_status *rx_status) | |
2778 | { | |
f698d856 | 2779 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
2780 | int tx_last_beacon; |
2781 | struct sk_buff *skb; | |
2782 | struct ieee80211_mgmt *resp; | |
2783 | u8 *pos, *end; | |
0795af57 JP |
2784 | DECLARE_MAC_BUF(mac); |
2785 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
2786 | DECLARE_MAC_BUF(mac2); | |
2787 | DECLARE_MAC_BUF(mac3); | |
2788 | #endif | |
f0706e82 | 2789 | |
51fb61e7 | 2790 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS || |
48c2fc59 | 2791 | ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED || |
f0706e82 JB |
2792 | len < 24 + 2 || !ifsta->probe_resp) |
2793 | return; | |
2794 | ||
2795 | if (local->ops->tx_last_beacon) | |
2796 | tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local)); | |
2797 | else | |
2798 | tx_last_beacon = 1; | |
2799 | ||
2800 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
0795af57 JP |
2801 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID=" |
2802 | "%s (tx_last_beacon=%d)\n", | |
f698d856 | 2803 | sdata->dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da), |
0795af57 | 2804 | print_mac(mac3, mgmt->bssid), tx_last_beacon); |
f0706e82 JB |
2805 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
2806 | ||
2807 | if (!tx_last_beacon) | |
2808 | return; | |
2809 | ||
2810 | if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 && | |
2811 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) | |
2812 | return; | |
2813 | ||
2814 | end = ((u8 *) mgmt) + len; | |
2815 | pos = mgmt->u.probe_req.variable; | |
2816 | if (pos[0] != WLAN_EID_SSID || | |
2817 | pos + 2 + pos[1] > end) { | |
f4ea83dd JB |
2818 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
2819 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " | |
2820 | "from %s\n", | |
f698d856 | 2821 | sdata->dev->name, print_mac(mac, mgmt->sa)); |
f4ea83dd | 2822 | #endif |
f0706e82 JB |
2823 | return; |
2824 | } | |
2825 | if (pos[1] != 0 && | |
2826 | (pos[1] != ifsta->ssid_len || | |
2827 | memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) { | |
2828 | /* Ignore ProbeReq for foreign SSID */ | |
2829 | return; | |
2830 | } | |
2831 | ||
2832 | /* Reply with ProbeResp */ | |
0ec0b7ac | 2833 | skb = skb_copy(ifsta->probe_resp, GFP_KERNEL); |
f0706e82 JB |
2834 | if (!skb) |
2835 | return; | |
2836 | ||
2837 | resp = (struct ieee80211_mgmt *) skb->data; | |
2838 | memcpy(resp->da, mgmt->sa, ETH_ALEN); | |
2839 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
0795af57 | 2840 | printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n", |
f698d856 | 2841 | sdata->dev->name, print_mac(mac, resp->da)); |
f0706e82 | 2842 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
f698d856 | 2843 | ieee80211_sta_tx(sdata, skb, 0); |
f0706e82 JB |
2844 | } |
2845 | ||
f698d856 | 2846 | static void ieee80211_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, |
4e20cb29 JB |
2847 | struct ieee80211_if_sta *ifsta, |
2848 | struct ieee80211_mgmt *mgmt, | |
f709fc69 LCC |
2849 | size_t len, |
2850 | struct ieee80211_rx_status *rx_status) | |
9f985b0e | 2851 | { |
f698d856 | 2852 | struct ieee80211_local *local = sdata->local; |
f709fc69 | 2853 | |
9c80d3dc JB |
2854 | /* all categories we currently handle have action_code */ |
2855 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) | |
9f985b0e RR |
2856 | return; |
2857 | ||
2858 | switch (mgmt->u.action.category) { | |
b6623486 AK |
2859 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
2860 | if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ) | |
2861 | break; | |
5fd12d4d | 2862 | switch (mgmt->u.action.u.measurement.action_code) { |
b6623486 AK |
2863 | case WLAN_ACTION_SPCT_MSR_REQ: |
2864 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
2865 | sizeof(mgmt->u.action.u.measurement))) | |
2866 | break; | |
f698d856 | 2867 | ieee80211_sta_process_measurement_req(sdata, mgmt, len); |
b6623486 AK |
2868 | break; |
2869 | } | |
2870 | break; | |
9f985b0e RR |
2871 | case WLAN_CATEGORY_BACK: |
2872 | switch (mgmt->u.action.u.addba_req.action_code) { | |
2873 | case WLAN_ACTION_ADDBA_REQ: | |
2874 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
2875 | sizeof(mgmt->u.action.u.addba_req))) | |
2876 | break; | |
f698d856 | 2877 | ieee80211_sta_process_addba_request(local, mgmt, len); |
9f985b0e | 2878 | break; |
eadc8d9e RR |
2879 | case WLAN_ACTION_ADDBA_RESP: |
2880 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
2881 | sizeof(mgmt->u.action.u.addba_resp))) | |
2882 | break; | |
f698d856 | 2883 | ieee80211_sta_process_addba_resp(local, mgmt, len); |
eadc8d9e | 2884 | break; |
688b88a4 RR |
2885 | case WLAN_ACTION_DELBA: |
2886 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
2887 | sizeof(mgmt->u.action.u.delba))) | |
2888 | break; | |
f698d856 | 2889 | ieee80211_sta_process_delba(sdata, mgmt, len); |
688b88a4 | 2890 | break; |
9f985b0e RR |
2891 | } |
2892 | break; | |
f709fc69 | 2893 | case PLINK_CATEGORY: |
902acc78 | 2894 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
f698d856 | 2895 | mesh_rx_plink_frame(sdata, mgmt, len, rx_status); |
f709fc69 | 2896 | break; |
f709fc69 | 2897 | case MESH_PATH_SEL_CATEGORY: |
902acc78 | 2898 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
f698d856 | 2899 | mesh_rx_path_sel_frame(sdata, mgmt, len); |
f709fc69 | 2900 | break; |
9f985b0e RR |
2901 | } |
2902 | } | |
f0706e82 | 2903 | |
f698d856 | 2904 | void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
f0706e82 JB |
2905 | struct ieee80211_rx_status *rx_status) |
2906 | { | |
f698d856 | 2907 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
2908 | struct ieee80211_if_sta *ifsta; |
2909 | struct ieee80211_mgmt *mgmt; | |
2910 | u16 fc; | |
2911 | ||
2912 | if (skb->len < 24) | |
2913 | goto fail; | |
2914 | ||
f0706e82 JB |
2915 | ifsta = &sdata->u.sta; |
2916 | ||
2917 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
2918 | fc = le16_to_cpu(mgmt->frame_control); | |
2919 | ||
2920 | switch (fc & IEEE80211_FCTL_STYPE) { | |
2921 | case IEEE80211_STYPE_PROBE_REQ: | |
2922 | case IEEE80211_STYPE_PROBE_RESP: | |
2923 | case IEEE80211_STYPE_BEACON: | |
f709fc69 | 2924 | case IEEE80211_STYPE_ACTION: |
f0706e82 JB |
2925 | memcpy(skb->cb, rx_status, sizeof(*rx_status)); |
2926 | case IEEE80211_STYPE_AUTH: | |
2927 | case IEEE80211_STYPE_ASSOC_RESP: | |
2928 | case IEEE80211_STYPE_REASSOC_RESP: | |
2929 | case IEEE80211_STYPE_DEAUTH: | |
2930 | case IEEE80211_STYPE_DISASSOC: | |
2931 | skb_queue_tail(&ifsta->skb_queue, skb); | |
2932 | queue_work(local->hw.workqueue, &ifsta->work); | |
2933 | return; | |
f0706e82 JB |
2934 | } |
2935 | ||
2936 | fail: | |
2937 | kfree_skb(skb); | |
2938 | } | |
2939 | ||
f698d856 | 2940 | static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
2941 | struct sk_buff *skb) |
2942 | { | |
2943 | struct ieee80211_rx_status *rx_status; | |
f0706e82 JB |
2944 | struct ieee80211_if_sta *ifsta; |
2945 | struct ieee80211_mgmt *mgmt; | |
2946 | u16 fc; | |
2947 | ||
f0706e82 JB |
2948 | ifsta = &sdata->u.sta; |
2949 | ||
2950 | rx_status = (struct ieee80211_rx_status *) skb->cb; | |
2951 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
2952 | fc = le16_to_cpu(mgmt->frame_control); | |
2953 | ||
2954 | switch (fc & IEEE80211_FCTL_STYPE) { | |
2955 | case IEEE80211_STYPE_PROBE_REQ: | |
f698d856 | 2956 | ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len, |
f0706e82 JB |
2957 | rx_status); |
2958 | break; | |
2959 | case IEEE80211_STYPE_PROBE_RESP: | |
f698d856 | 2960 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status); |
f0706e82 JB |
2961 | break; |
2962 | case IEEE80211_STYPE_BEACON: | |
f698d856 | 2963 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
f0706e82 JB |
2964 | break; |
2965 | case IEEE80211_STYPE_AUTH: | |
f698d856 | 2966 | ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len); |
f0706e82 JB |
2967 | break; |
2968 | case IEEE80211_STYPE_ASSOC_RESP: | |
471b3efd | 2969 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0); |
f0706e82 JB |
2970 | break; |
2971 | case IEEE80211_STYPE_REASSOC_RESP: | |
471b3efd | 2972 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1); |
f0706e82 JB |
2973 | break; |
2974 | case IEEE80211_STYPE_DEAUTH: | |
f698d856 | 2975 | ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len); |
f0706e82 JB |
2976 | break; |
2977 | case IEEE80211_STYPE_DISASSOC: | |
f698d856 | 2978 | ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len); |
f0706e82 | 2979 | break; |
9f985b0e | 2980 | case IEEE80211_STYPE_ACTION: |
f698d856 | 2981 | ieee80211_rx_mgmt_action(sdata, ifsta, mgmt, skb->len, rx_status); |
9f985b0e | 2982 | break; |
f0706e82 JB |
2983 | } |
2984 | ||
2985 | kfree_skb(skb); | |
2986 | } | |
2987 | ||
2988 | ||
9ae54c84 | 2989 | ieee80211_rx_result |
f698d856 | 2990 | ieee80211_sta_rx_scan(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
ece8eddd | 2991 | struct ieee80211_rx_status *rx_status) |
f0706e82 JB |
2992 | { |
2993 | struct ieee80211_mgmt *mgmt; | |
4e3996fe | 2994 | __le16 fc; |
f0706e82 | 2995 | |
ece8eddd | 2996 | if (skb->len < 2) |
e4c26add | 2997 | return RX_DROP_UNUSABLE; |
f0706e82 JB |
2998 | |
2999 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
4e3996fe | 3000 | fc = mgmt->frame_control; |
f0706e82 | 3001 | |
4e3996fe | 3002 | if (ieee80211_is_ctl(fc)) |
9ae54c84 | 3003 | return RX_CONTINUE; |
ece8eddd ZY |
3004 | |
3005 | if (skb->len < 24) | |
e4c26add | 3006 | return RX_DROP_MONITOR; |
ece8eddd | 3007 | |
4e3996fe | 3008 | if (ieee80211_is_probe_resp(fc)) { |
f698d856 | 3009 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status); |
4e3996fe HH |
3010 | dev_kfree_skb(skb); |
3011 | return RX_QUEUED; | |
f0706e82 | 3012 | } |
4e3996fe HH |
3013 | |
3014 | if (ieee80211_is_beacon(fc)) { | |
f698d856 | 3015 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
4e3996fe HH |
3016 | dev_kfree_skb(skb); |
3017 | return RX_QUEUED; | |
3018 | } | |
3019 | ||
9ae54c84 | 3020 | return RX_CONTINUE; |
f0706e82 JB |
3021 | } |
3022 | ||
3023 | ||
f698d856 | 3024 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) |
f0706e82 | 3025 | { |
f698d856 | 3026 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
3027 | int active = 0; |
3028 | struct sta_info *sta; | |
3029 | ||
d0709a65 JB |
3030 | rcu_read_lock(); |
3031 | ||
3032 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | |
3033 | if (sta->sdata == sdata && | |
f0706e82 JB |
3034 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
3035 | jiffies)) { | |
3036 | active++; | |
3037 | break; | |
3038 | } | |
3039 | } | |
d0709a65 JB |
3040 | |
3041 | rcu_read_unlock(); | |
f0706e82 JB |
3042 | |
3043 | return active; | |
3044 | } | |
3045 | ||
3046 | ||
f698d856 | 3047 | static void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, unsigned long exp_time) |
f0706e82 | 3048 | { |
f698d856 | 3049 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 3050 | struct sta_info *sta, *tmp; |
be8755e1 | 3051 | LIST_HEAD(tmp_list); |
0795af57 | 3052 | DECLARE_MAC_BUF(mac); |
d0709a65 | 3053 | unsigned long flags; |
f0706e82 | 3054 | |
d0709a65 | 3055 | spin_lock_irqsave(&local->sta_lock, flags); |
f0706e82 | 3056 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
f709fc69 | 3057 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
f4ea83dd | 3058 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
0795af57 | 3059 | printk(KERN_DEBUG "%s: expiring inactive STA %s\n", |
f698d856 | 3060 | sdata->dev->name, print_mac(mac, sta->addr)); |
f4ea83dd | 3061 | #endif |
cb585bcc | 3062 | __sta_info_unlink(&sta); |
d0709a65 JB |
3063 | if (sta) |
3064 | list_add(&sta->list, &tmp_list); | |
f0706e82 | 3065 | } |
d0709a65 | 3066 | spin_unlock_irqrestore(&local->sta_lock, flags); |
be8755e1 | 3067 | |
d0709a65 JB |
3068 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) |
3069 | sta_info_destroy(sta); | |
f0706e82 JB |
3070 | } |
3071 | ||
3072 | ||
f698d856 | 3073 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
3074 | struct ieee80211_if_sta *ifsta) |
3075 | { | |
3076 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); | |
3077 | ||
f698d856 JBG |
3078 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); |
3079 | if (ieee80211_sta_active_ibss(sdata)) | |
f0706e82 JB |
3080 | return; |
3081 | ||
3082 | printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " | |
f698d856 JBG |
3083 | "IBSS networks with same SSID (merge)\n", sdata->dev->name); |
3084 | ieee80211_sta_req_scan(sdata, ifsta->ssid, ifsta->ssid_len); | |
f0706e82 JB |
3085 | } |
3086 | ||
3087 | ||
f709fc69 | 3088 | #ifdef CONFIG_MAC80211_MESH |
f698d856 | 3089 | static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata, |
f709fc69 LCC |
3090 | struct ieee80211_if_sta *ifsta) |
3091 | { | |
f709fc69 LCC |
3092 | bool free_plinks; |
3093 | ||
f698d856 JBG |
3094 | ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); |
3095 | mesh_path_expire(sdata); | |
f709fc69 LCC |
3096 | |
3097 | free_plinks = mesh_plink_availables(sdata); | |
3098 | if (free_plinks != sdata->u.sta.accepting_plinks) | |
9d139c81 | 3099 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
f709fc69 LCC |
3100 | |
3101 | mod_timer(&ifsta->timer, jiffies + | |
3102 | IEEE80211_MESH_HOUSEKEEPING_INTERVAL); | |
3103 | } | |
3104 | ||
3105 | ||
f698d856 | 3106 | void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) |
f709fc69 LCC |
3107 | { |
3108 | struct ieee80211_if_sta *ifsta; | |
f709fc69 | 3109 | ifsta = &sdata->u.sta; |
48c2fc59 | 3110 | ifsta->state = IEEE80211_STA_MLME_MESH_UP; |
f709fc69 | 3111 | ieee80211_sta_timer((unsigned long)sdata); |
56a6d13d | 3112 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
f709fc69 LCC |
3113 | } |
3114 | #endif | |
3115 | ||
3116 | ||
f0706e82 JB |
3117 | void ieee80211_sta_timer(unsigned long data) |
3118 | { | |
60f8b39c JB |
3119 | struct ieee80211_sub_if_data *sdata = |
3120 | (struct ieee80211_sub_if_data *) data; | |
3121 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | |
3122 | struct ieee80211_local *local = sdata->local; | |
f0706e82 | 3123 | |
60f8b39c JB |
3124 | set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
3125 | queue_work(local->hw.workqueue, &ifsta->work); | |
f0706e82 JB |
3126 | } |
3127 | ||
f698d856 | 3128 | static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
3129 | struct ieee80211_if_sta *ifsta) |
3130 | { | |
f698d856 | 3131 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
3132 | |
3133 | if (local->ops->reset_tsf) { | |
3134 | /* Reset own TSF to allow time synchronization work. */ | |
3135 | local->ops->reset_tsf(local_to_hw(local)); | |
3136 | } | |
3137 | ||
3138 | ifsta->wmm_last_param_set = -1; /* allow any WMM update */ | |
3139 | ||
3140 | ||
3141 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) | |
3142 | ifsta->auth_alg = WLAN_AUTH_OPEN; | |
3143 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) | |
3144 | ifsta->auth_alg = WLAN_AUTH_SHARED_KEY; | |
3145 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) | |
3146 | ifsta->auth_alg = WLAN_AUTH_LEAP; | |
3147 | else | |
3148 | ifsta->auth_alg = WLAN_AUTH_OPEN; | |
f0706e82 | 3149 | ifsta->auth_transaction = -1; |
d6f2da5b | 3150 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
6042a3e3 | 3151 | ifsta->assoc_scan_tries = 0; |
9859b81e | 3152 | ifsta->direct_probe_tries = 0; |
6042a3e3 RR |
3153 | ifsta->auth_tries = 0; |
3154 | ifsta->assoc_tries = 0; | |
24e64622 | 3155 | netif_tx_stop_all_queues(sdata->dev); |
f698d856 | 3156 | netif_carrier_off(sdata->dev); |
f0706e82 JB |
3157 | } |
3158 | ||
3159 | ||
f698d856 | 3160 | void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
3161 | struct ieee80211_if_sta *ifsta) |
3162 | { | |
f698d856 | 3163 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 3164 | |
51fb61e7 | 3165 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
f0706e82 JB |
3166 | return; |
3167 | ||
d6f2da5b | 3168 | if ((ifsta->flags & (IEEE80211_STA_BSSID_SET | |
3b7ee69d | 3169 | IEEE80211_STA_AUTO_BSSID_SEL)) && |
d6f2da5b | 3170 | (ifsta->flags & (IEEE80211_STA_SSID_SET | |
3b7ee69d TW |
3171 | IEEE80211_STA_AUTO_SSID_SEL))) { |
3172 | ||
3173 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) | |
3174 | ieee80211_set_disassoc(sdata, ifsta, true, true, | |
3175 | WLAN_REASON_DEAUTH_LEAVING); | |
3176 | ||
f0706e82 JB |
3177 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
3178 | queue_work(local->hw.workqueue, &ifsta->work); | |
3179 | } | |
3180 | } | |
3181 | ||
3182 | static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, | |
3183 | const char *ssid, int ssid_len) | |
3184 | { | |
3185 | int tmp, hidden_ssid; | |
3186 | ||
48225709 MW |
3187 | if (ssid_len == ifsta->ssid_len && |
3188 | !memcmp(ifsta->ssid, ssid, ssid_len)) | |
f0706e82 JB |
3189 | return 1; |
3190 | ||
d6f2da5b | 3191 | if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) |
f0706e82 JB |
3192 | return 0; |
3193 | ||
3194 | hidden_ssid = 1; | |
3195 | tmp = ssid_len; | |
3196 | while (tmp--) { | |
3197 | if (ssid[tmp] != '\0') { | |
3198 | hidden_ssid = 0; | |
3199 | break; | |
3200 | } | |
3201 | } | |
3202 | ||
3203 | if (hidden_ssid && ifsta->ssid_len == ssid_len) | |
3204 | return 1; | |
3205 | ||
3206 | if (ssid_len == 1 && ssid[0] == ' ') | |
3207 | return 1; | |
3208 | ||
3209 | return 0; | |
3210 | } | |
3211 | ||
f698d856 | 3212 | static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
3213 | struct ieee80211_if_sta *ifsta) |
3214 | { | |
f698d856 | 3215 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 3216 | struct ieee80211_sta_bss *bss; |
8318d78a | 3217 | struct ieee80211_supported_band *sband; |
f0706e82 JB |
3218 | u8 bssid[ETH_ALEN], *pos; |
3219 | int i; | |
167ad6f7 | 3220 | int ret; |
0795af57 | 3221 | DECLARE_MAC_BUF(mac); |
f0706e82 JB |
3222 | |
3223 | #if 0 | |
3224 | /* Easier testing, use fixed BSSID. */ | |
3225 | memset(bssid, 0xfe, ETH_ALEN); | |
3226 | #else | |
3227 | /* Generate random, not broadcast, locally administered BSSID. Mix in | |
3228 | * own MAC address to make sure that devices that do not have proper | |
3229 | * random number generator get different BSSID. */ | |
3230 | get_random_bytes(bssid, ETH_ALEN); | |
3231 | for (i = 0; i < ETH_ALEN; i++) | |
f698d856 | 3232 | bssid[i] ^= sdata->dev->dev_addr[i]; |
f0706e82 JB |
3233 | bssid[0] &= ~0x01; |
3234 | bssid[0] |= 0x02; | |
3235 | #endif | |
3236 | ||
0795af57 | 3237 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", |
f698d856 | 3238 | sdata->dev->name, print_mac(mac, bssid)); |
f0706e82 | 3239 | |
f698d856 | 3240 | bss = ieee80211_rx_bss_add(sdata, bssid, |
8318d78a | 3241 | local->hw.conf.channel->center_freq, |
cffdd30d | 3242 | sdata->u.sta.ssid, sdata->u.sta.ssid_len); |
f0706e82 JB |
3243 | if (!bss) |
3244 | return -ENOMEM; | |
3245 | ||
8318d78a JB |
3246 | bss->band = local->hw.conf.channel->band; |
3247 | sband = local->hw.wiphy->bands[bss->band]; | |
f0706e82 JB |
3248 | |
3249 | if (local->hw.conf.beacon_int == 0) | |
dc0ae30c | 3250 | local->hw.conf.beacon_int = 100; |
f0706e82 | 3251 | bss->beacon_int = local->hw.conf.beacon_int; |
f0706e82 JB |
3252 | bss->last_update = jiffies; |
3253 | bss->capability = WLAN_CAPABILITY_IBSS; | |
988c0f72 JB |
3254 | |
3255 | if (sdata->default_key) | |
f0706e82 | 3256 | bss->capability |= WLAN_CAPABILITY_PRIVACY; |
988c0f72 | 3257 | else |
f0706e82 | 3258 | sdata->drop_unencrypted = 0; |
988c0f72 | 3259 | |
8318d78a | 3260 | bss->supp_rates_len = sband->n_bitrates; |
f0706e82 | 3261 | pos = bss->supp_rates; |
8318d78a JB |
3262 | for (i = 0; i < sband->n_bitrates; i++) { |
3263 | int rate = sband->bitrates[i].bitrate; | |
f0706e82 JB |
3264 | *pos++ = (u8) (rate / 5); |
3265 | } | |
3266 | ||
f698d856 | 3267 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); |
3e122be0 | 3268 | ieee80211_rx_bss_put(local, bss); |
167ad6f7 | 3269 | return ret; |
f0706e82 JB |
3270 | } |
3271 | ||
3272 | ||
f698d856 | 3273 | static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
3274 | struct ieee80211_if_sta *ifsta) |
3275 | { | |
f698d856 | 3276 | struct ieee80211_local *local = sdata->local; |
f0706e82 JB |
3277 | struct ieee80211_sta_bss *bss; |
3278 | int found = 0; | |
3279 | u8 bssid[ETH_ALEN]; | |
3280 | int active_ibss; | |
0795af57 JP |
3281 | DECLARE_MAC_BUF(mac); |
3282 | DECLARE_MAC_BUF(mac2); | |
f0706e82 JB |
3283 | |
3284 | if (ifsta->ssid_len == 0) | |
3285 | return -EINVAL; | |
3286 | ||
f698d856 | 3287 | active_ibss = ieee80211_sta_active_ibss(sdata); |
f0706e82 JB |
3288 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
3289 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", | |
f698d856 | 3290 | sdata->dev->name, active_ibss); |
f0706e82 JB |
3291 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
3292 | spin_lock_bh(&local->sta_bss_lock); | |
3293 | list_for_each_entry(bss, &local->sta_bss_list, list) { | |
3294 | if (ifsta->ssid_len != bss->ssid_len || | |
3295 | memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 | |
3296 | || !(bss->capability & WLAN_CAPABILITY_IBSS)) | |
3297 | continue; | |
3298 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
0795af57 JP |
3299 | printk(KERN_DEBUG " bssid=%s found\n", |
3300 | print_mac(mac, bss->bssid)); | |
f0706e82 JB |
3301 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
3302 | memcpy(bssid, bss->bssid, ETH_ALEN); | |
3303 | found = 1; | |
3304 | if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) | |
3305 | break; | |
3306 | } | |
3307 | spin_unlock_bh(&local->sta_bss_lock); | |
3308 | ||
3309 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
6e43829b VK |
3310 | if (found) |
3311 | printk(KERN_DEBUG " sta_find_ibss: selected %s current " | |
3312 | "%s\n", print_mac(mac, bssid), | |
3313 | print_mac(mac2, ifsta->bssid)); | |
f0706e82 | 3314 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
80693ceb DD |
3315 | |
3316 | if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { | |
167ad6f7 | 3317 | int ret; |
80693ceb DD |
3318 | int search_freq; |
3319 | ||
3320 | if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) | |
3321 | search_freq = bss->freq; | |
3322 | else | |
3323 | search_freq = local->hw.conf.channel->center_freq; | |
3324 | ||
f698d856 | 3325 | bss = ieee80211_rx_bss_get(local, bssid, search_freq, |
80693ceb DD |
3326 | ifsta->ssid, ifsta->ssid_len); |
3327 | if (!bss) | |
3328 | goto dont_join; | |
3329 | ||
0795af57 | 3330 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" |
f0706e82 | 3331 | " based on configured SSID\n", |
f698d856 JBG |
3332 | sdata->dev->name, print_mac(mac, bssid)); |
3333 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); | |
3e122be0 | 3334 | ieee80211_rx_bss_put(local, bss); |
167ad6f7 | 3335 | return ret; |
f0706e82 | 3336 | } |
80693ceb DD |
3337 | |
3338 | dont_join: | |
f0706e82 JB |
3339 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
3340 | printk(KERN_DEBUG " did not try to join ibss\n"); | |
3341 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | |
3342 | ||
3343 | /* Selected IBSS not found in current scan results - try to scan */ | |
48c2fc59 | 3344 | if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED && |
f698d856 | 3345 | !ieee80211_sta_active_ibss(sdata)) { |
f0706e82 JB |
3346 | mod_timer(&ifsta->timer, jiffies + |
3347 | IEEE80211_IBSS_MERGE_INTERVAL); | |
3348 | } else if (time_after(jiffies, local->last_scan_completed + | |
3349 | IEEE80211_SCAN_INTERVAL)) { | |
3350 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " | |
f698d856 JBG |
3351 | "join\n", sdata->dev->name); |
3352 | return ieee80211_sta_req_scan(sdata, ifsta->ssid, | |
f0706e82 | 3353 | ifsta->ssid_len); |
48c2fc59 | 3354 | } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) { |
f0706e82 JB |
3355 | int interval = IEEE80211_SCAN_INTERVAL; |
3356 | ||
3357 | if (time_after(jiffies, ifsta->ibss_join_req + | |
3358 | IEEE80211_IBSS_JOIN_TIMEOUT)) { | |
d6f2da5b | 3359 | if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && |
8318d78a JB |
3360 | (!(local->oper_channel->flags & |
3361 | IEEE80211_CHAN_NO_IBSS))) | |
f698d856 | 3362 | return ieee80211_sta_create_ibss(sdata, ifsta); |
d6f2da5b | 3363 | if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { |
8318d78a | 3364 | printk(KERN_DEBUG "%s: IBSS not allowed on" |
f698d856 | 3365 | " %d MHz\n", sdata->dev->name, |
8318d78a | 3366 | local->hw.conf.channel->center_freq); |
f0706e82 JB |
3367 | } |
3368 | ||
3369 | /* No IBSS found - decrease scan interval and continue | |
3370 | * scanning. */ | |
3371 | interval = IEEE80211_SCAN_INTERVAL_SLOW; | |
3372 | } | |
3373 | ||
48c2fc59 | 3374 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; |
f0706e82 JB |
3375 | mod_timer(&ifsta->timer, jiffies + interval); |
3376 | return 0; | |
3377 | } | |
3378 | ||
3379 | return 0; | |
3380 | } | |
3381 | ||
3382 | ||
f698d856 | 3383 | int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) |
f0706e82 | 3384 | { |
f0706e82 | 3385 | struct ieee80211_if_sta *ifsta; |
9d139c81 | 3386 | int res; |
f0706e82 JB |
3387 | |
3388 | if (len > IEEE80211_MAX_SSID_LEN) | |
3389 | return -EINVAL; | |
3390 | ||
f0706e82 JB |
3391 | ifsta = &sdata->u.sta; |
3392 | ||
9d139c81 JB |
3393 | if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) { |
3394 | memset(ifsta->ssid, 0, sizeof(ifsta->ssid)); | |
3395 | memcpy(ifsta->ssid, ssid, len); | |
3396 | ifsta->ssid_len = len; | |
d6f2da5b | 3397 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
9d139c81 JB |
3398 | |
3399 | res = 0; | |
3400 | /* | |
3401 | * Hack! MLME code needs to be cleaned up to have different | |
3402 | * entry points for configuration and internal selection change | |
3403 | */ | |
3404 | if (netif_running(sdata->dev)) | |
3405 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID); | |
3406 | if (res) { | |
3407 | printk(KERN_DEBUG "%s: Failed to config new SSID to " | |
f698d856 | 3408 | "the low-level driver\n", sdata->dev->name); |
9d139c81 JB |
3409 | return res; |
3410 | } | |
3411 | } | |
f0706e82 | 3412 | |
d6f2da5b JS |
3413 | if (len) |
3414 | ifsta->flags |= IEEE80211_STA_SSID_SET; | |
3415 | else | |
3416 | ifsta->flags &= ~IEEE80211_STA_SSID_SET; | |
9d139c81 | 3417 | |
51fb61e7 | 3418 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
d6f2da5b | 3419 | !(ifsta->flags & IEEE80211_STA_BSSID_SET)) { |
f0706e82 | 3420 | ifsta->ibss_join_req = jiffies; |
48c2fc59 | 3421 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; |
f698d856 | 3422 | return ieee80211_sta_find_ibss(sdata, ifsta); |
f0706e82 | 3423 | } |
9d139c81 | 3424 | |
f0706e82 JB |
3425 | return 0; |
3426 | } | |
3427 | ||
3428 | ||
f698d856 | 3429 | int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len) |
f0706e82 | 3430 | { |
f0706e82 JB |
3431 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
3432 | memcpy(ssid, ifsta->ssid, ifsta->ssid_len); | |
3433 | *len = ifsta->ssid_len; | |
3434 | return 0; | |
3435 | } | |
3436 | ||
3437 | ||
f698d856 | 3438 | int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) |
f0706e82 | 3439 | { |
f0706e82 JB |
3440 | struct ieee80211_if_sta *ifsta; |
3441 | int res; | |
3442 | ||
f0706e82 JB |
3443 | ifsta = &sdata->u.sta; |
3444 | ||
3445 | if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { | |
3446 | memcpy(ifsta->bssid, bssid, ETH_ALEN); | |
9d139c81 JB |
3447 | res = 0; |
3448 | /* | |
3449 | * Hack! See also ieee80211_sta_set_ssid. | |
3450 | */ | |
3451 | if (netif_running(sdata->dev)) | |
3452 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); | |
f0706e82 JB |
3453 | if (res) { |
3454 | printk(KERN_DEBUG "%s: Failed to config new BSSID to " | |
f698d856 | 3455 | "the low-level driver\n", sdata->dev->name); |
f0706e82 JB |
3456 | return res; |
3457 | } | |
3458 | } | |
3459 | ||
d6f2da5b JS |
3460 | if (is_valid_ether_addr(bssid)) |
3461 | ifsta->flags |= IEEE80211_STA_BSSID_SET; | |
f0706e82 | 3462 | else |
d6f2da5b JS |
3463 | ifsta->flags &= ~IEEE80211_STA_BSSID_SET; |
3464 | ||
f0706e82 JB |
3465 | return 0; |
3466 | } | |
3467 | ||
3468 | ||
3469 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, | |
3470 | struct ieee80211_sub_if_data *sdata, | |
3471 | int powersave) | |
3472 | { | |
3473 | struct sk_buff *skb; | |
3474 | struct ieee80211_hdr *nullfunc; | |
4e3996fe | 3475 | __le16 fc; |
f0706e82 JB |
3476 | |
3477 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); | |
3478 | if (!skb) { | |
3479 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " | |
3480 | "frame\n", sdata->dev->name); | |
3481 | return; | |
3482 | } | |
3483 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
3484 | ||
3485 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); | |
3486 | memset(nullfunc, 0, 24); | |
4e3996fe HH |
3487 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
3488 | IEEE80211_FCTL_TODS); | |
f0706e82 | 3489 | if (powersave) |
4e3996fe HH |
3490 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); |
3491 | nullfunc->frame_control = fc; | |
f0706e82 JB |
3492 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); |
3493 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); | |
3494 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); | |
3495 | ||
f698d856 | 3496 | ieee80211_sta_tx(sdata, skb, 0); |
f0706e82 JB |
3497 | } |
3498 | ||
3499 | ||
69d3b6f4 JB |
3500 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
3501 | { | |
3502 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || | |
3503 | ieee80211_vif_is_mesh(&sdata->vif)) | |
3504 | ieee80211_sta_timer((unsigned long)sdata); | |
3505 | } | |
3506 | ||
f0706e82 JB |
3507 | void ieee80211_scan_completed(struct ieee80211_hw *hw) |
3508 | { | |
3509 | struct ieee80211_local *local = hw_to_local(hw); | |
f0706e82 JB |
3510 | struct ieee80211_sub_if_data *sdata; |
3511 | union iwreq_data wrqu; | |
3512 | ||
3513 | local->last_scan_completed = jiffies; | |
ece8eddd | 3514 | memset(&wrqu, 0, sizeof(wrqu)); |
491775a5 | 3515 | wireless_send_event(local->scan_sdata->dev, SIOCGIWSCAN, &wrqu, NULL); |
f0706e82 | 3516 | |
ece8eddd ZY |
3517 | if (local->sta_hw_scanning) { |
3518 | local->sta_hw_scanning = 0; | |
675ef586 MA |
3519 | if (ieee80211_hw_config(local)) |
3520 | printk(KERN_DEBUG "%s: failed to restore operational " | |
491775a5 | 3521 | "channel after scan\n", wiphy_name(local->hw.wiphy)); |
69d3b6f4 JB |
3522 | /* Restart STA timer for HW scan case */ |
3523 | rcu_read_lock(); | |
3524 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
3525 | ieee80211_restart_sta_timer(sdata); | |
3526 | rcu_read_unlock(); | |
3527 | ||
ece8eddd ZY |
3528 | goto done; |
3529 | } | |
3530 | ||
3531 | local->sta_sw_scanning = 0; | |
f0706e82 | 3532 | if (ieee80211_hw_config(local)) |
4b50e388 | 3533 | printk(KERN_DEBUG "%s: failed to restore operational " |
491775a5 | 3534 | "channel after scan\n", wiphy_name(local->hw.wiphy)); |
f0706e82 | 3535 | |
4150c572 JB |
3536 | |
3537 | netif_tx_lock_bh(local->mdev); | |
e308a5d8 | 3538 | netif_addr_lock(local->mdev); |
4150c572 JB |
3539 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; |
3540 | local->ops->configure_filter(local_to_hw(local), | |
3541 | FIF_BCN_PRBRESP_PROMISC, | |
3542 | &local->filter_flags, | |
3543 | local->mdev->mc_count, | |
3544 | local->mdev->mc_list); | |
3545 | ||
e308a5d8 | 3546 | netif_addr_unlock(local->mdev); |
4150c572 | 3547 | netif_tx_unlock_bh(local->mdev); |
f0706e82 | 3548 | |
79010420 JB |
3549 | rcu_read_lock(); |
3550 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
69d3b6f4 | 3551 | /* Tell AP we're back */ |
24e64622 TW |
3552 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
3553 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | |
3554 | ieee80211_send_nullfunc(local, sdata, 0); | |
3555 | netif_tx_wake_all_queues(sdata->dev); | |
3556 | } | |
3557 | } else | |
3558 | netif_tx_wake_all_queues(sdata->dev); | |
14042cbe | 3559 | |
69d3b6f4 | 3560 | ieee80211_restart_sta_timer(sdata); |
f0706e82 | 3561 | } |
79010420 | 3562 | rcu_read_unlock(); |
f0706e82 | 3563 | |
491775a5 JB |
3564 | done: |
3565 | sdata = local->scan_sdata; | |
51fb61e7 | 3566 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
f0706e82 | 3567 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
d6f2da5b | 3568 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || |
48c2fc59 | 3569 | (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) && |
f698d856 JBG |
3570 | !ieee80211_sta_active_ibss(sdata))) |
3571 | ieee80211_sta_find_ibss(sdata, ifsta); | |
f0706e82 JB |
3572 | } |
3573 | } | |
3574 | EXPORT_SYMBOL(ieee80211_scan_completed); | |
3575 | ||
3576 | void ieee80211_sta_scan_work(struct work_struct *work) | |
3577 | { | |
3578 | struct ieee80211_local *local = | |
3579 | container_of(work, struct ieee80211_local, scan_work.work); | |
491775a5 | 3580 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
8318d78a | 3581 | struct ieee80211_supported_band *sband; |
f0706e82 JB |
3582 | struct ieee80211_channel *chan; |
3583 | int skip; | |
3584 | unsigned long next_delay = 0; | |
3585 | ||
ece8eddd | 3586 | if (!local->sta_sw_scanning) |
f0706e82 JB |
3587 | return; |
3588 | ||
3589 | switch (local->scan_state) { | |
3590 | case SCAN_SET_CHANNEL: | |
69d464d5 JB |
3591 | /* |
3592 | * Get current scan band. scan_band may be IEEE80211_NUM_BANDS | |
3593 | * after we successfully scanned the last channel of the last | |
3594 | * band (and the last band is supported by the hw) | |
3595 | */ | |
8318d78a JB |
3596 | if (local->scan_band < IEEE80211_NUM_BANDS) |
3597 | sband = local->hw.wiphy->bands[local->scan_band]; | |
3598 | else | |
3599 | sband = NULL; | |
3600 | ||
69d464d5 JB |
3601 | /* |
3602 | * If we are at an unsupported band and have more bands | |
3603 | * left to scan, advance to the next supported one. | |
3604 | */ | |
3605 | while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) { | |
8318d78a JB |
3606 | local->scan_band++; |
3607 | sband = local->hw.wiphy->bands[local->scan_band]; | |
3608 | local->scan_channel_idx = 0; | |
3609 | } | |
3610 | ||
69d464d5 JB |
3611 | /* if no more bands/channels left, complete scan */ |
3612 | if (!sband || local->scan_channel_idx >= sband->n_channels) { | |
f0706e82 JB |
3613 | ieee80211_scan_completed(local_to_hw(local)); |
3614 | return; | |
3615 | } | |
8318d78a JB |
3616 | skip = 0; |
3617 | chan = &sband->channels[local->scan_channel_idx]; | |
3618 | ||
3619 | if (chan->flags & IEEE80211_CHAN_DISABLED || | |
51fb61e7 | 3620 | (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
8318d78a | 3621 | chan->flags & IEEE80211_CHAN_NO_IBSS)) |
f0706e82 JB |
3622 | skip = 1; |
3623 | ||
3624 | if (!skip) { | |
f0706e82 JB |
3625 | local->scan_channel = chan; |
3626 | if (ieee80211_hw_config(local)) { | |
8318d78a | 3627 | printk(KERN_DEBUG "%s: failed to set freq to " |
491775a5 | 3628 | "%d MHz for scan\n", wiphy_name(local->hw.wiphy), |
8318d78a | 3629 | chan->center_freq); |
f0706e82 JB |
3630 | skip = 1; |
3631 | } | |
3632 | } | |
3633 | ||
69d464d5 | 3634 | /* advance state machine to next channel/band */ |
f0706e82 | 3635 | local->scan_channel_idx++; |
8318d78a | 3636 | if (local->scan_channel_idx >= sband->n_channels) { |
69d464d5 JB |
3637 | /* |
3638 | * scan_band may end up == IEEE80211_NUM_BANDS, but | |
3639 | * we'll catch that case above and complete the scan | |
3640 | * if that is the case. | |
3641 | */ | |
8318d78a JB |
3642 | local->scan_band++; |
3643 | local->scan_channel_idx = 0; | |
f0706e82 JB |
3644 | } |
3645 | ||
3646 | if (skip) | |
3647 | break; | |
3648 | ||
3649 | next_delay = IEEE80211_PROBE_DELAY + | |
3650 | usecs_to_jiffies(local->hw.channel_change_time); | |
3651 | local->scan_state = SCAN_SEND_PROBE; | |
3652 | break; | |
3653 | case SCAN_SEND_PROBE: | |
8318d78a | 3654 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; |
f0706e82 | 3655 | local->scan_state = SCAN_SET_CHANNEL; |
8318d78a JB |
3656 | |
3657 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN) | |
3658 | break; | |
f698d856 | 3659 | ieee80211_send_probe_req(sdata, NULL, local->scan_ssid, |
8318d78a JB |
3660 | local->scan_ssid_len); |
3661 | next_delay = IEEE80211_CHANNEL_TIME; | |
f0706e82 JB |
3662 | break; |
3663 | } | |
3664 | ||
ece8eddd | 3665 | if (local->sta_sw_scanning) |
f0706e82 JB |
3666 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
3667 | next_delay); | |
3668 | } | |
3669 | ||
3670 | ||
f698d856 | 3671 | static int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, |
f0706e82 JB |
3672 | u8 *ssid, size_t ssid_len) |
3673 | { | |
f698d856 | 3674 | struct ieee80211_local *local = scan_sdata->local; |
f0706e82 JB |
3675 | struct ieee80211_sub_if_data *sdata; |
3676 | ||
3677 | if (ssid_len > IEEE80211_MAX_SSID_LEN) | |
3678 | return -EINVAL; | |
3679 | ||
3680 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) | |
3681 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS | |
3682 | * BSSID: MACAddress | |
3683 | * SSID | |
3684 | * ScanType: ACTIVE, PASSIVE | |
3685 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting | |
3686 | * a Probe frame during active scanning | |
3687 | * ChannelList | |
3688 | * MinChannelTime (>= ProbeDelay), in TU | |
3689 | * MaxChannelTime: (>= MinChannelTime), in TU | |
3690 | */ | |
3691 | ||
3692 | /* MLME-SCAN.confirm | |
3693 | * BSSDescriptionSet | |
3694 | * ResultCode: SUCCESS, INVALID_PARAMETERS | |
3695 | */ | |
3696 | ||
ece8eddd | 3697 | if (local->sta_sw_scanning || local->sta_hw_scanning) { |
491775a5 | 3698 | if (local->scan_sdata == scan_sdata) |
f0706e82 JB |
3699 | return 0; |
3700 | return -EBUSY; | |
3701 | } | |
3702 | ||
3703 | if (local->ops->hw_scan) { | |
3704 | int rc = local->ops->hw_scan(local_to_hw(local), | |
ece8eddd | 3705 | ssid, ssid_len); |
f0706e82 | 3706 | if (!rc) { |
ece8eddd | 3707 | local->sta_hw_scanning = 1; |
491775a5 | 3708 | local->scan_sdata = scan_sdata; |
f0706e82 JB |
3709 | } |
3710 | return rc; | |
3711 | } | |
3712 | ||
ece8eddd | 3713 | local->sta_sw_scanning = 1; |
f0706e82 | 3714 | |
79010420 JB |
3715 | rcu_read_lock(); |
3716 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
24e64622 TW |
3717 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
3718 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | |
3719 | netif_tx_stop_all_queues(sdata->dev); | |
3720 | ieee80211_send_nullfunc(local, sdata, 1); | |
3721 | } | |
3722 | } else | |
3723 | netif_tx_stop_all_queues(sdata->dev); | |
f0706e82 | 3724 | } |
79010420 | 3725 | rcu_read_unlock(); |
f0706e82 JB |
3726 | |
3727 | if (ssid) { | |
3728 | local->scan_ssid_len = ssid_len; | |
3729 | memcpy(local->scan_ssid, ssid, ssid_len); | |
3730 | } else | |
3731 | local->scan_ssid_len = 0; | |
3732 | local->scan_state = SCAN_SET_CHANNEL; | |
f0706e82 | 3733 | local->scan_channel_idx = 0; |
8318d78a | 3734 | local->scan_band = IEEE80211_BAND_2GHZ; |
491775a5 | 3735 | local->scan_sdata = scan_sdata; |
f0706e82 | 3736 | |
b9e40857 | 3737 | netif_addr_lock_bh(local->mdev); |
4150c572 JB |
3738 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; |
3739 | local->ops->configure_filter(local_to_hw(local), | |
3740 | FIF_BCN_PRBRESP_PROMISC, | |
3741 | &local->filter_flags, | |
3742 | local->mdev->mc_count, | |
3743 | local->mdev->mc_list); | |
b9e40857 | 3744 | netif_addr_unlock_bh(local->mdev); |
f0706e82 JB |
3745 | |
3746 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ | |
3747 | queue_delayed_work(local->hw.workqueue, &local->scan_work, | |
3748 | IEEE80211_CHANNEL_TIME); | |
3749 | ||
3750 | return 0; | |
3751 | } | |
3752 | ||
3753 | ||
f698d856 | 3754 | int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len) |
f0706e82 | 3755 | { |
f0706e82 | 3756 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
f698d856 | 3757 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 3758 | |
51fb61e7 | 3759 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
f698d856 | 3760 | return ieee80211_sta_start_scan(sdata, ssid, ssid_len); |
f0706e82 | 3761 | |
ece8eddd | 3762 | if (local->sta_sw_scanning || local->sta_hw_scanning) { |
491775a5 | 3763 | if (local->scan_sdata == sdata) |
f0706e82 JB |
3764 | return 0; |
3765 | return -EBUSY; | |
3766 | } | |
3767 | ||
a0af5f14 HS |
3768 | ifsta->scan_ssid_len = ssid_len; |
3769 | if (ssid_len) | |
3770 | memcpy(ifsta->scan_ssid, ssid, ssid_len); | |
f0706e82 JB |
3771 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); |
3772 | queue_work(local->hw.workqueue, &ifsta->work); | |
3773 | return 0; | |
3774 | } | |
3775 | ||
43ac2ca3 JM |
3776 | |
3777 | static void ieee80211_sta_add_scan_ies(struct iw_request_info *info, | |
3778 | struct ieee80211_sta_bss *bss, | |
3779 | char **current_ev, char *end_buf) | |
3780 | { | |
3781 | u8 *pos, *end, *next; | |
3782 | struct iw_event iwe; | |
3783 | ||
3784 | if (bss == NULL || bss->ies == NULL) | |
3785 | return; | |
3786 | ||
3787 | /* | |
3788 | * If needed, fragment the IEs buffer (at IE boundaries) into short | |
3789 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. | |
3790 | */ | |
3791 | pos = bss->ies; | |
3792 | end = pos + bss->ies_len; | |
3793 | ||
3794 | while (end - pos > IW_GENERIC_IE_MAX) { | |
3795 | next = pos + 2 + pos[1]; | |
3796 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) | |
3797 | next = next + 2 + next[1]; | |
3798 | ||
3799 | memset(&iwe, 0, sizeof(iwe)); | |
3800 | iwe.cmd = IWEVGENIE; | |
3801 | iwe.u.data.length = next - pos; | |
3802 | *current_ev = iwe_stream_add_point(info, *current_ev, | |
3803 | end_buf, &iwe, pos); | |
3804 | ||
3805 | pos = next; | |
3806 | } | |
3807 | ||
3808 | if (end > pos) { | |
3809 | memset(&iwe, 0, sizeof(iwe)); | |
3810 | iwe.cmd = IWEVGENIE; | |
3811 | iwe.u.data.length = end - pos; | |
3812 | *current_ev = iwe_stream_add_point(info, *current_ev, | |
3813 | end_buf, &iwe, pos); | |
3814 | } | |
3815 | } | |
3816 | ||
3817 | ||
f0706e82 | 3818 | static char * |
f698d856 | 3819 | ieee80211_sta_scan_result(struct ieee80211_local *local, |
ccc58057 | 3820 | struct iw_request_info *info, |
f0706e82 JB |
3821 | struct ieee80211_sta_bss *bss, |
3822 | char *current_ev, char *end_buf) | |
3823 | { | |
f0706e82 | 3824 | struct iw_event iwe; |
ee96d6ef | 3825 | char *buf; |
f0706e82 JB |
3826 | |
3827 | if (time_after(jiffies, | |
3828 | bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) | |
3829 | return current_ev; | |
3830 | ||
f0706e82 JB |
3831 | memset(&iwe, 0, sizeof(iwe)); |
3832 | iwe.cmd = SIOCGIWAP; | |
3833 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
3834 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); | |
ccc58057 | 3835 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
f0706e82 JB |
3836 | IW_EV_ADDR_LEN); |
3837 | ||
3838 | memset(&iwe, 0, sizeof(iwe)); | |
3839 | iwe.cmd = SIOCGIWESSID; | |
902acc78 JB |
3840 | if (bss_mesh_cfg(bss)) { |
3841 | iwe.u.data.length = bss_mesh_id_len(bss); | |
f709fc69 | 3842 | iwe.u.data.flags = 1; |
ccc58057 DM |
3843 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
3844 | &iwe, bss_mesh_id(bss)); | |
f709fc69 LCC |
3845 | } else { |
3846 | iwe.u.data.length = bss->ssid_len; | |
3847 | iwe.u.data.flags = 1; | |
ccc58057 DM |
3848 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
3849 | &iwe, bss->ssid); | |
f709fc69 | 3850 | } |
f0706e82 | 3851 | |
1d1b5359 LCC |
3852 | if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) |
3853 | || bss_mesh_cfg(bss)) { | |
f0706e82 JB |
3854 | memset(&iwe, 0, sizeof(iwe)); |
3855 | iwe.cmd = SIOCGIWMODE; | |
902acc78 | 3856 | if (bss_mesh_cfg(bss)) |
f709fc69 LCC |
3857 | iwe.u.mode = IW_MODE_MESH; |
3858 | else if (bss->capability & WLAN_CAPABILITY_ESS) | |
f0706e82 JB |
3859 | iwe.u.mode = IW_MODE_MASTER; |
3860 | else | |
3861 | iwe.u.mode = IW_MODE_ADHOC; | |
ccc58057 DM |
3862 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
3863 | &iwe, IW_EV_UINT_LEN); | |
f0706e82 JB |
3864 | } |
3865 | ||
3866 | memset(&iwe, 0, sizeof(iwe)); | |
3867 | iwe.cmd = SIOCGIWFREQ; | |
9381be05 TW |
3868 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq); |
3869 | iwe.u.freq.e = 0; | |
ccc58057 | 3870 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
f0706e82 | 3871 | IW_EV_FREQ_LEN); |
8318d78a JB |
3872 | |
3873 | memset(&iwe, 0, sizeof(iwe)); | |
3874 | iwe.cmd = SIOCGIWFREQ; | |
9381be05 TW |
3875 | iwe.u.freq.m = bss->freq; |
3876 | iwe.u.freq.e = 6; | |
ccc58057 | 3877 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
f0706e82 | 3878 | IW_EV_FREQ_LEN); |
f0706e82 JB |
3879 | memset(&iwe, 0, sizeof(iwe)); |
3880 | iwe.cmd = IWEVQUAL; | |
566bfe5a BR |
3881 | iwe.u.qual.qual = bss->qual; |
3882 | iwe.u.qual.level = bss->signal; | |
f0706e82 JB |
3883 | iwe.u.qual.noise = bss->noise; |
3884 | iwe.u.qual.updated = local->wstats_flags; | |
ccc58057 | 3885 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
f0706e82 JB |
3886 | IW_EV_QUAL_LEN); |
3887 | ||
3888 | memset(&iwe, 0, sizeof(iwe)); | |
3889 | iwe.cmd = SIOCGIWENCODE; | |
3890 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) | |
3891 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
3892 | else | |
3893 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
3894 | iwe.u.data.length = 0; | |
ccc58057 DM |
3895 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
3896 | &iwe, ""); | |
f0706e82 | 3897 | |
43ac2ca3 | 3898 | ieee80211_sta_add_scan_ies(info, bss, ¤t_ev, end_buf); |
e623157b | 3899 | |
ee96d6ef | 3900 | if (bss->supp_rates_len > 0) { |
f0706e82 | 3901 | /* display all supported rates in readable format */ |
ccc58057 | 3902 | char *p = current_ev + iwe_stream_lcp_len(info); |
f0706e82 JB |
3903 | int i; |
3904 | ||
3905 | memset(&iwe, 0, sizeof(iwe)); | |
3906 | iwe.cmd = SIOCGIWRATE; | |
3907 | /* Those two flags are ignored... */ | |
3908 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | |
3909 | ||
3910 | for (i = 0; i < bss->supp_rates_len; i++) { | |
3911 | iwe.u.bitrate.value = ((bss->supp_rates[i] & | |
3912 | 0x7f) * 500000); | |
ccc58057 | 3913 | p = iwe_stream_add_value(info, current_ev, p, |
f0706e82 JB |
3914 | end_buf, &iwe, IW_EV_PARAM_LEN); |
3915 | } | |
3916 | current_ev = p; | |
3917 | } | |
3918 | ||
ee96d6ef JB |
3919 | buf = kmalloc(30, GFP_ATOMIC); |
3920 | if (buf) { | |
3921 | memset(&iwe, 0, sizeof(iwe)); | |
3922 | iwe.cmd = IWEVCUSTOM; | |
3923 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); | |
3924 | iwe.u.data.length = strlen(buf); | |
3925 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
3926 | &iwe, buf); | |
3927 | memset(&iwe, 0, sizeof(iwe)); | |
3928 | iwe.cmd = IWEVCUSTOM; | |
3929 | sprintf(buf, " Last beacon: %dms ago", | |
3930 | jiffies_to_msecs(jiffies - bss->last_update)); | |
3931 | iwe.u.data.length = strlen(buf); | |
3932 | current_ev = iwe_stream_add_point(info, current_ev, | |
3933 | end_buf, &iwe, buf); | |
3934 | kfree(buf); | |
f0706e82 JB |
3935 | } |
3936 | ||
902acc78 | 3937 | if (bss_mesh_cfg(bss)) { |
24736701 | 3938 | u8 *cfg = bss_mesh_cfg(bss); |
4f5d4c4d | 3939 | buf = kmalloc(50, GFP_ATOMIC); |
f709fc69 LCC |
3940 | if (buf) { |
3941 | memset(&iwe, 0, sizeof(iwe)); | |
3942 | iwe.cmd = IWEVCUSTOM; | |
24736701 | 3943 | sprintf(buf, "Mesh network (version %d)", cfg[0]); |
4f5d4c4d | 3944 | iwe.u.data.length = strlen(buf); |
ccc58057 DM |
3945 | current_ev = iwe_stream_add_point(info, current_ev, |
3946 | end_buf, | |
4f5d4c4d LCC |
3947 | &iwe, buf); |
3948 | sprintf(buf, "Path Selection Protocol ID: " | |
24736701 JL |
3949 | "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3], |
3950 | cfg[4]); | |
4f5d4c4d | 3951 | iwe.u.data.length = strlen(buf); |
ccc58057 DM |
3952 | current_ev = iwe_stream_add_point(info, current_ev, |
3953 | end_buf, | |
4f5d4c4d LCC |
3954 | &iwe, buf); |
3955 | sprintf(buf, "Path Selection Metric ID: " | |
24736701 JL |
3956 | "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7], |
3957 | cfg[8]); | |
4f5d4c4d | 3958 | iwe.u.data.length = strlen(buf); |
ccc58057 DM |
3959 | current_ev = iwe_stream_add_point(info, current_ev, |
3960 | end_buf, | |
4f5d4c4d LCC |
3961 | &iwe, buf); |
3962 | sprintf(buf, "Congestion Control Mode ID: " | |
24736701 JL |
3963 | "0x%02X%02X%02X%02X", cfg[9], cfg[10], |
3964 | cfg[11], cfg[12]); | |
4f5d4c4d | 3965 | iwe.u.data.length = strlen(buf); |
ccc58057 DM |
3966 | current_ev = iwe_stream_add_point(info, current_ev, |
3967 | end_buf, | |
4f5d4c4d LCC |
3968 | &iwe, buf); |
3969 | sprintf(buf, "Channel Precedence: " | |
24736701 JL |
3970 | "0x%02X%02X%02X%02X", cfg[13], cfg[14], |
3971 | cfg[15], cfg[16]); | |
f709fc69 | 3972 | iwe.u.data.length = strlen(buf); |
ccc58057 DM |
3973 | current_ev = iwe_stream_add_point(info, current_ev, |
3974 | end_buf, | |
f709fc69 LCC |
3975 | &iwe, buf); |
3976 | kfree(buf); | |
3977 | } | |
3978 | } | |
3979 | ||
f0706e82 JB |
3980 | return current_ev; |
3981 | } | |
3982 | ||
3983 | ||
f698d856 | 3984 | int ieee80211_sta_scan_results(struct ieee80211_local *local, |
ccc58057 DM |
3985 | struct iw_request_info *info, |
3986 | char *buf, size_t len) | |
f0706e82 | 3987 | { |
f0706e82 JB |
3988 | char *current_ev = buf; |
3989 | char *end_buf = buf + len; | |
3990 | struct ieee80211_sta_bss *bss; | |
3991 | ||
3992 | spin_lock_bh(&local->sta_bss_lock); | |
3993 | list_for_each_entry(bss, &local->sta_bss_list, list) { | |
3994 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { | |
3995 | spin_unlock_bh(&local->sta_bss_lock); | |
3996 | return -E2BIG; | |
3997 | } | |
f698d856 | 3998 | current_ev = ieee80211_sta_scan_result(local, info, bss, |
ccc58057 | 3999 | current_ev, end_buf); |
f0706e82 JB |
4000 | } |
4001 | spin_unlock_bh(&local->sta_bss_lock); | |
4002 | return current_ev - buf; | |
4003 | } | |
4004 | ||
4005 | ||
f698d856 | 4006 | int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len) |
f0706e82 | 4007 | { |
f0706e82 | 4008 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
988c0f72 | 4009 | |
f0706e82 JB |
4010 | kfree(ifsta->extra_ie); |
4011 | if (len == 0) { | |
4012 | ifsta->extra_ie = NULL; | |
4013 | ifsta->extra_ie_len = 0; | |
4014 | return 0; | |
4015 | } | |
4016 | ifsta->extra_ie = kmalloc(len, GFP_KERNEL); | |
4017 | if (!ifsta->extra_ie) { | |
4018 | ifsta->extra_ie_len = 0; | |
4019 | return -ENOMEM; | |
4020 | } | |
4021 | memcpy(ifsta->extra_ie, ie, len); | |
4022 | ifsta->extra_ie_len = len; | |
4023 | return 0; | |
4024 | } | |
4025 | ||
4026 | ||
f698d856 | 4027 | struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, |
988c0f72 | 4028 | struct sk_buff *skb, u8 *bssid, |
87291c02 | 4029 | u8 *addr, u64 supp_rates) |
f0706e82 | 4030 | { |
f698d856 | 4031 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 4032 | struct sta_info *sta; |
0795af57 | 4033 | DECLARE_MAC_BUF(mac); |
87291c02 | 4034 | int band = local->hw.conf.channel->band; |
f0706e82 JB |
4035 | |
4036 | /* TODO: Could consider removing the least recently used entry and | |
4037 | * allow new one to be added. */ | |
4038 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { | |
4039 | if (net_ratelimit()) { | |
4040 | printk(KERN_DEBUG "%s: No room for a new IBSS STA " | |
f698d856 | 4041 | "entry %s\n", sdata->dev->name, print_mac(mac, addr)); |
f0706e82 JB |
4042 | } |
4043 | return NULL; | |
4044 | } | |
4045 | ||
1e188637 | 4046 | if (compare_ether_addr(bssid, sdata->u.sta.bssid)) |
87291c02 VK |
4047 | return NULL; |
4048 | ||
f4ea83dd | 4049 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
0795af57 | 4050 | printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", |
f698d856 | 4051 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name); |
f4ea83dd | 4052 | #endif |
f0706e82 | 4053 | |
73651ee6 JB |
4054 | sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); |
4055 | if (!sta) | |
f0706e82 JB |
4056 | return NULL; |
4057 | ||
07346f81 | 4058 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); |
238814fd | 4059 | |
8e1535d5 EG |
4060 | /* make sure mandatory rates are always added */ |
4061 | sta->supp_rates[band] = supp_rates | | |
4062 | ieee80211_sta_get_mandatory_rates(local, band); | |
f0706e82 JB |
4063 | |
4064 | rate_control_rate_init(sta, local); | |
4065 | ||
93e5deb1 | 4066 | if (sta_info_insert(sta)) |
73651ee6 | 4067 | return NULL; |
73651ee6 | 4068 | |
d0709a65 | 4069 | return sta; |
f0706e82 JB |
4070 | } |
4071 | ||
4072 | ||
60f8b39c JB |
4073 | static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata, |
4074 | struct ieee80211_if_sta *ifsta) | |
4075 | { | |
4076 | struct ieee80211_local *local = sdata->local; | |
4077 | struct ieee80211_sta_bss *bss, *selected = NULL; | |
4078 | int top_rssi = 0, freq; | |
4079 | ||
4080 | spin_lock_bh(&local->sta_bss_lock); | |
4081 | freq = local->oper_channel->center_freq; | |
4082 | list_for_each_entry(bss, &local->sta_bss_list, list) { | |
4083 | if (!(bss->capability & WLAN_CAPABILITY_ESS)) | |
4084 | continue; | |
4085 | ||
4086 | if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL | | |
4087 | IEEE80211_STA_AUTO_BSSID_SEL | | |
4088 | IEEE80211_STA_AUTO_CHANNEL_SEL)) && | |
4089 | (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^ | |
4090 | !!sdata->default_key)) | |
4091 | continue; | |
4092 | ||
4093 | if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) && | |
4094 | bss->freq != freq) | |
4095 | continue; | |
4096 | ||
4097 | if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) && | |
4098 | memcmp(bss->bssid, ifsta->bssid, ETH_ALEN)) | |
4099 | continue; | |
4100 | ||
4101 | if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) && | |
4102 | !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len)) | |
4103 | continue; | |
4104 | ||
4105 | if (!selected || top_rssi < bss->signal) { | |
4106 | selected = bss; | |
4107 | top_rssi = bss->signal; | |
4108 | } | |
4109 | } | |
4110 | if (selected) | |
4111 | atomic_inc(&selected->users); | |
4112 | spin_unlock_bh(&local->sta_bss_lock); | |
4113 | ||
4114 | if (selected) { | |
4115 | ieee80211_set_freq(sdata, selected->freq); | |
4116 | if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) | |
4117 | ieee80211_sta_set_ssid(sdata, selected->ssid, | |
4118 | selected->ssid_len); | |
4119 | ieee80211_sta_set_bssid(sdata, selected->bssid); | |
4120 | ieee80211_sta_def_wmm_params(sdata, selected, 0); | |
4121 | ||
4122 | /* Send out direct probe if no probe resp was received or | |
4123 | * the one we have is outdated | |
4124 | */ | |
4125 | if (!selected->last_probe_resp || | |
4126 | time_after(jiffies, selected->last_probe_resp | |
4127 | + IEEE80211_SCAN_RESULT_EXPIRE)) | |
4128 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; | |
4129 | else | |
4130 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; | |
4131 | ||
4132 | ieee80211_rx_bss_put(local, selected); | |
4133 | ieee80211_sta_reset_auth(sdata, ifsta); | |
4134 | return 0; | |
4135 | } else { | |
4136 | if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { | |
4137 | ifsta->assoc_scan_tries++; | |
4138 | if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) | |
4139 | ieee80211_sta_start_scan(sdata, NULL, 0); | |
4140 | else | |
4141 | ieee80211_sta_start_scan(sdata, ifsta->ssid, | |
4142 | ifsta->ssid_len); | |
4143 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; | |
4144 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); | |
4145 | } else | |
4146 | ifsta->state = IEEE80211_STA_MLME_DISABLED; | |
4147 | } | |
4148 | return -1; | |
4149 | } | |
4150 | ||
4151 | ||
f698d856 | 4152 | int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) |
f0706e82 | 4153 | { |
f0706e82 JB |
4154 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
4155 | ||
f4ea83dd | 4156 | printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", |
f698d856 | 4157 | sdata->dev->name, reason); |
f0706e82 | 4158 | |
51fb61e7 JB |
4159 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
4160 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) | |
f0706e82 JB |
4161 | return -EINVAL; |
4162 | ||
aa458d17 | 4163 | ieee80211_set_disassoc(sdata, ifsta, true, true, reason); |
f0706e82 JB |
4164 | return 0; |
4165 | } | |
4166 | ||
4167 | ||
f698d856 | 4168 | int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason) |
f0706e82 | 4169 | { |
f0706e82 JB |
4170 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
4171 | ||
f4ea83dd | 4172 | printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", |
f698d856 | 4173 | sdata->dev->name, reason); |
f0706e82 | 4174 | |
51fb61e7 | 4175 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
f0706e82 JB |
4176 | return -EINVAL; |
4177 | ||
d6f2da5b | 4178 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED)) |
f0706e82 JB |
4179 | return -1; |
4180 | ||
aa458d17 | 4181 | ieee80211_set_disassoc(sdata, ifsta, false, true, reason); |
f0706e82 JB |
4182 | return 0; |
4183 | } | |
84363e6e MA |
4184 | |
4185 | void ieee80211_notify_mac(struct ieee80211_hw *hw, | |
4186 | enum ieee80211_notification_types notif_type) | |
4187 | { | |
4188 | struct ieee80211_local *local = hw_to_local(hw); | |
4189 | struct ieee80211_sub_if_data *sdata; | |
4190 | ||
4191 | switch (notif_type) { | |
4192 | case IEEE80211_NOTIFY_RE_ASSOC: | |
4193 | rcu_read_lock(); | |
4194 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
3e122be0 JB |
4195 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
4196 | continue; | |
84363e6e | 4197 | |
f698d856 | 4198 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
84363e6e MA |
4199 | } |
4200 | rcu_read_unlock(); | |
4201 | break; | |
4202 | } | |
4203 | } | |
4204 | EXPORT_SYMBOL(ieee80211_notify_mac); | |
60f8b39c JB |
4205 | |
4206 | void ieee80211_sta_work(struct work_struct *work) | |
4207 | { | |
4208 | struct ieee80211_sub_if_data *sdata = | |
4209 | container_of(work, struct ieee80211_sub_if_data, u.sta.work); | |
4210 | struct ieee80211_local *local = sdata->local; | |
4211 | struct ieee80211_if_sta *ifsta; | |
4212 | struct sk_buff *skb; | |
4213 | ||
4214 | if (!netif_running(sdata->dev)) | |
4215 | return; | |
4216 | ||
4217 | if (local->sta_sw_scanning || local->sta_hw_scanning) | |
4218 | return; | |
4219 | ||
4220 | if (WARN_ON(sdata->vif.type != IEEE80211_IF_TYPE_STA && | |
4221 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS && | |
4222 | sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) | |
4223 | return; | |
4224 | ifsta = &sdata->u.sta; | |
4225 | ||
4226 | while ((skb = skb_dequeue(&ifsta->skb_queue))) | |
4227 | ieee80211_sta_rx_queued_mgmt(sdata, skb); | |
4228 | ||
4229 | #ifdef CONFIG_MAC80211_MESH | |
4230 | if (ifsta->preq_queue_len && | |
4231 | time_after(jiffies, | |
4232 | ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval))) | |
4233 | mesh_path_start_discovery(sdata); | |
4234 | #endif | |
4235 | ||
4236 | if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE && | |
4237 | ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && | |
4238 | ifsta->state != IEEE80211_STA_MLME_ASSOCIATE && | |
4239 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { | |
4240 | if (ifsta->scan_ssid_len) | |
4241 | ieee80211_sta_start_scan(sdata, ifsta->scan_ssid, ifsta->scan_ssid_len); | |
4242 | else | |
4243 | ieee80211_sta_start_scan(sdata, NULL, 0); | |
4244 | return; | |
4245 | } | |
4246 | ||
4247 | if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) { | |
4248 | if (ieee80211_sta_config_auth(sdata, ifsta)) | |
4249 | return; | |
4250 | clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); | |
4251 | } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request)) | |
4252 | return; | |
4253 | ||
4254 | switch (ifsta->state) { | |
4255 | case IEEE80211_STA_MLME_DISABLED: | |
4256 | break; | |
4257 | case IEEE80211_STA_MLME_DIRECT_PROBE: | |
4258 | ieee80211_direct_probe(sdata, ifsta); | |
4259 | break; | |
4260 | case IEEE80211_STA_MLME_AUTHENTICATE: | |
4261 | ieee80211_authenticate(sdata, ifsta); | |
4262 | break; | |
4263 | case IEEE80211_STA_MLME_ASSOCIATE: | |
4264 | ieee80211_associate(sdata, ifsta); | |
4265 | break; | |
4266 | case IEEE80211_STA_MLME_ASSOCIATED: | |
4267 | ieee80211_associated(sdata, ifsta); | |
4268 | break; | |
4269 | case IEEE80211_STA_MLME_IBSS_SEARCH: | |
4270 | ieee80211_sta_find_ibss(sdata, ifsta); | |
4271 | break; | |
4272 | case IEEE80211_STA_MLME_IBSS_JOINED: | |
4273 | ieee80211_sta_merge_ibss(sdata, ifsta); | |
4274 | break; | |
4275 | #ifdef CONFIG_MAC80211_MESH | |
4276 | case IEEE80211_STA_MLME_MESH_UP: | |
4277 | ieee80211_mesh_housekeeping(sdata, ifsta); | |
4278 | break; | |
4279 | #endif | |
4280 | default: | |
4281 | WARN_ON(1); | |
4282 | break; | |
4283 | } | |
4284 | ||
4285 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { | |
4286 | printk(KERN_DEBUG "%s: privacy configuration mismatch and " | |
4287 | "mixed-cell disabled - disassociate\n", sdata->dev->name); | |
4288 | ||
4289 | ieee80211_set_disassoc(sdata, ifsta, false, true, | |
4290 | WLAN_REASON_UNSPECIFIED); | |
4291 | } | |
4292 | } |