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