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