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