Commit | Line | Data |
---|---|---|
b453872c JG |
1 | /* |
2 | * Original code based Host AP (software wireless LAN access point) driver | |
3 | * for Intersil Prism2/2.5/3 - hostap.o module, common routines | |
4 | * | |
5 | * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen | |
6 | * <jkmaline@cc.hut.fi> | |
7 | * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> | |
8 | * Copyright (c) 2004, Intel Corporation | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License version 2 as | |
12 | * published by the Free Software Foundation. See README and COPYING for | |
13 | * more details. | |
14 | */ | |
15 | ||
16 | #include <linux/compiler.h> | |
17 | #include <linux/config.h> | |
18 | #include <linux/errno.h> | |
19 | #include <linux/if_arp.h> | |
20 | #include <linux/in6.h> | |
21 | #include <linux/in.h> | |
22 | #include <linux/ip.h> | |
23 | #include <linux/kernel.h> | |
24 | #include <linux/module.h> | |
25 | #include <linux/netdevice.h> | |
b453872c JG |
26 | #include <linux/proc_fs.h> |
27 | #include <linux/skbuff.h> | |
28 | #include <linux/slab.h> | |
29 | #include <linux/tcp.h> | |
30 | #include <linux/types.h> | |
31 | #include <linux/version.h> | |
32 | #include <linux/wireless.h> | |
33 | #include <linux/etherdevice.h> | |
34 | #include <asm/uaccess.h> | |
35 | #include <linux/ctype.h> | |
36 | ||
37 | #include <net/ieee80211.h> | |
38 | ||
39 | static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee, | |
40 | struct sk_buff *skb, | |
41 | struct ieee80211_rx_stats *rx_stats) | |
42 | { | |
43 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
44 | u16 fc = le16_to_cpu(hdr->frame_ctl); | |
45 | ||
46 | skb->dev = ieee->dev; | |
47 | skb->mac.raw = skb->data; | |
48 | skb_pull(skb, ieee80211_get_hdrlen(fc)); | |
49 | skb->pkt_type = PACKET_OTHERHOST; | |
50 | skb->protocol = __constant_htons(ETH_P_80211_RAW); | |
51 | memset(skb->cb, 0, sizeof(skb->cb)); | |
52 | netif_rx(skb); | |
53 | } | |
54 | ||
55 | ||
56 | /* Called only as a tasklet (software IRQ) */ | |
57 | static struct ieee80211_frag_entry * | |
58 | ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq, | |
59 | unsigned int frag, u8 *src, u8 *dst) | |
60 | { | |
61 | struct ieee80211_frag_entry *entry; | |
62 | int i; | |
63 | ||
64 | for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) { | |
65 | entry = &ieee->frag_cache[i]; | |
66 | if (entry->skb != NULL && | |
67 | time_after(jiffies, entry->first_frag_time + 2 * HZ)) { | |
68 | IEEE80211_DEBUG_FRAG( | |
69 | "expiring fragment cache entry " | |
70 | "seq=%u last_frag=%u\n", | |
71 | entry->seq, entry->last_frag); | |
72 | dev_kfree_skb_any(entry->skb); | |
73 | entry->skb = NULL; | |
74 | } | |
75 | ||
76 | if (entry->skb != NULL && entry->seq == seq && | |
77 | (entry->last_frag + 1 == frag || frag == -1) && | |
78 | memcmp(entry->src_addr, src, ETH_ALEN) == 0 && | |
79 | memcmp(entry->dst_addr, dst, ETH_ALEN) == 0) | |
80 | return entry; | |
81 | } | |
82 | ||
83 | return NULL; | |
84 | } | |
85 | ||
86 | /* Called only as a tasklet (software IRQ) */ | |
87 | static struct sk_buff * | |
88 | ieee80211_frag_cache_get(struct ieee80211_device *ieee, | |
89 | struct ieee80211_hdr *hdr) | |
90 | { | |
91 | struct sk_buff *skb = NULL; | |
92 | u16 sc; | |
93 | unsigned int frag, seq; | |
94 | struct ieee80211_frag_entry *entry; | |
95 | ||
96 | sc = le16_to_cpu(hdr->seq_ctl); | |
97 | frag = WLAN_GET_SEQ_FRAG(sc); | |
98 | seq = WLAN_GET_SEQ_SEQ(sc); | |
99 | ||
100 | if (frag == 0) { | |
101 | /* Reserve enough space to fit maximum frame length */ | |
102 | skb = dev_alloc_skb(ieee->dev->mtu + | |
103 | sizeof(struct ieee80211_hdr) + | |
104 | 8 /* LLC */ + | |
105 | 2 /* alignment */ + | |
106 | 8 /* WEP */ + ETH_ALEN /* WDS */); | |
107 | if (skb == NULL) | |
108 | return NULL; | |
109 | ||
110 | entry = &ieee->frag_cache[ieee->frag_next_idx]; | |
111 | ieee->frag_next_idx++; | |
112 | if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN) | |
113 | ieee->frag_next_idx = 0; | |
114 | ||
115 | if (entry->skb != NULL) | |
116 | dev_kfree_skb_any(entry->skb); | |
117 | ||
118 | entry->first_frag_time = jiffies; | |
119 | entry->seq = seq; | |
120 | entry->last_frag = frag; | |
121 | entry->skb = skb; | |
122 | memcpy(entry->src_addr, hdr->addr2, ETH_ALEN); | |
123 | memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN); | |
124 | } else { | |
125 | /* received a fragment of a frame for which the head fragment | |
126 | * should have already been received */ | |
127 | entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2, | |
128 | hdr->addr1); | |
129 | if (entry != NULL) { | |
130 | entry->last_frag = frag; | |
131 | skb = entry->skb; | |
132 | } | |
133 | } | |
134 | ||
135 | return skb; | |
136 | } | |
137 | ||
138 | ||
139 | /* Called only as a tasklet (software IRQ) */ | |
140 | static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee, | |
141 | struct ieee80211_hdr *hdr) | |
142 | { | |
143 | u16 sc; | |
144 | unsigned int seq; | |
145 | struct ieee80211_frag_entry *entry; | |
146 | ||
147 | sc = le16_to_cpu(hdr->seq_ctl); | |
148 | seq = WLAN_GET_SEQ_SEQ(sc); | |
149 | ||
150 | entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2, | |
151 | hdr->addr1); | |
152 | ||
153 | if (entry == NULL) { | |
154 | IEEE80211_DEBUG_FRAG( | |
155 | "could not invalidate fragment cache " | |
156 | "entry (seq=%u)\n", seq); | |
157 | return -1; | |
158 | } | |
159 | ||
160 | entry->skb = NULL; | |
161 | return 0; | |
162 | } | |
163 | ||
164 | ||
165 | #ifdef NOT_YET | |
166 | /* ieee80211_rx_frame_mgtmt | |
167 | * | |
168 | * Responsible for handling management control frames | |
169 | * | |
170 | * Called by ieee80211_rx */ | |
171 | static inline int | |
172 | ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb, | |
173 | struct ieee80211_rx_stats *rx_stats, u16 type, | |
174 | u16 stype) | |
175 | { | |
176 | if (ieee->iw_mode == IW_MODE_MASTER) { | |
177 | printk(KERN_DEBUG "%s: Master mode not yet suppported.\n", | |
178 | ieee->dev->name); | |
179 | return 0; | |
180 | /* | |
181 | hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr *) | |
182 | skb->data);*/ | |
183 | } | |
184 | ||
185 | if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) { | |
186 | if (stype == WLAN_FC_STYPE_BEACON && | |
187 | ieee->iw_mode == IW_MODE_MASTER) { | |
188 | struct sk_buff *skb2; | |
189 | /* Process beacon frames also in kernel driver to | |
190 | * update STA(AP) table statistics */ | |
191 | skb2 = skb_clone(skb, GFP_ATOMIC); | |
192 | if (skb2) | |
193 | hostap_rx(skb2->dev, skb2, rx_stats); | |
194 | } | |
195 | ||
196 | /* send management frames to the user space daemon for | |
197 | * processing */ | |
198 | ieee->apdevstats.rx_packets++; | |
199 | ieee->apdevstats.rx_bytes += skb->len; | |
200 | prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT); | |
201 | return 0; | |
202 | } | |
203 | ||
204 | if (ieee->iw_mode == IW_MODE_MASTER) { | |
205 | if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) { | |
206 | printk(KERN_DEBUG "%s: unknown management frame " | |
207 | "(type=0x%02x, stype=0x%02x) dropped\n", | |
208 | skb->dev->name, type, stype); | |
209 | return -1; | |
210 | } | |
211 | ||
212 | hostap_rx(skb->dev, skb, rx_stats); | |
213 | return 0; | |
214 | } | |
215 | ||
216 | printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame " | |
217 | "received in non-Host AP mode\n", skb->dev->name); | |
218 | return -1; | |
219 | } | |
220 | #endif | |
221 | ||
222 | ||
223 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ | |
224 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ | |
225 | static unsigned char rfc1042_header[] = | |
226 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
227 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ | |
228 | static unsigned char bridge_tunnel_header[] = | |
229 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; | |
230 | /* No encapsulation header if EtherType < 0x600 (=length) */ | |
231 | ||
232 | /* Called by ieee80211_rx_frame_decrypt */ | |
233 | static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee, | |
234 | struct sk_buff *skb) | |
235 | { | |
236 | struct net_device *dev = ieee->dev; | |
237 | u16 fc, ethertype; | |
238 | struct ieee80211_hdr *hdr; | |
239 | u8 *pos; | |
240 | ||
241 | if (skb->len < 24) | |
242 | return 0; | |
243 | ||
244 | hdr = (struct ieee80211_hdr *) skb->data; | |
245 | fc = le16_to_cpu(hdr->frame_ctl); | |
246 | ||
247 | /* check that the frame is unicast frame to us */ | |
248 | if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == | |
249 | IEEE80211_FCTL_TODS && | |
250 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 && | |
251 | memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) { | |
252 | /* ToDS frame with own addr BSSID and DA */ | |
253 | } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == | |
254 | IEEE80211_FCTL_FROMDS && | |
255 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) { | |
256 | /* FromDS frame with own addr as DA */ | |
257 | } else | |
258 | return 0; | |
259 | ||
260 | if (skb->len < 24 + 8) | |
261 | return 0; | |
262 | ||
263 | /* check for port access entity Ethernet type */ | |
264 | pos = skb->data + 24; | |
265 | ethertype = (pos[6] << 8) | pos[7]; | |
266 | if (ethertype == ETH_P_PAE) | |
267 | return 1; | |
268 | ||
269 | return 0; | |
270 | } | |
271 | ||
272 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ | |
273 | static inline int | |
274 | ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb, | |
275 | struct ieee80211_crypt_data *crypt) | |
276 | { | |
277 | struct ieee80211_hdr *hdr; | |
278 | int res, hdrlen; | |
279 | ||
280 | if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL) | |
281 | return 0; | |
282 | ||
283 | hdr = (struct ieee80211_hdr *) skb->data; | |
284 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); | |
285 | ||
286 | #ifdef CONFIG_IEEE80211_CRYPT_TKIP | |
287 | if (ieee->tkip_countermeasures && | |
288 | strcmp(crypt->ops->name, "TKIP") == 0) { | |
289 | if (net_ratelimit()) { | |
290 | printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " | |
291 | "received packet from " MAC_FMT "\n", | |
292 | ieee->dev->name, MAC_ARG(hdr->addr2)); | |
293 | } | |
294 | return -1; | |
295 | } | |
296 | #endif | |
297 | ||
298 | atomic_inc(&crypt->refcnt); | |
299 | res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv); | |
300 | atomic_dec(&crypt->refcnt); | |
301 | if (res < 0) { | |
302 | IEEE80211_DEBUG_DROP( | |
303 | "decryption failed (SA=" MAC_FMT | |
304 | ") res=%d\n", MAC_ARG(hdr->addr2), res); | |
305 | if (res == -2) | |
306 | IEEE80211_DEBUG_DROP("Decryption failed ICV " | |
307 | "mismatch (key %d)\n", | |
308 | skb->data[hdrlen + 3] >> 6); | |
309 | ieee->ieee_stats.rx_discards_undecryptable++; | |
310 | return -1; | |
311 | } | |
312 | ||
313 | return res; | |
314 | } | |
315 | ||
316 | ||
317 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ | |
318 | static inline int | |
319 | ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb, | |
320 | int keyidx, struct ieee80211_crypt_data *crypt) | |
321 | { | |
322 | struct ieee80211_hdr *hdr; | |
323 | int res, hdrlen; | |
324 | ||
325 | if (crypt == NULL || crypt->ops->decrypt_msdu == NULL) | |
326 | return 0; | |
327 | ||
328 | hdr = (struct ieee80211_hdr *) skb->data; | |
329 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); | |
330 | ||
331 | atomic_inc(&crypt->refcnt); | |
332 | res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv); | |
333 | atomic_dec(&crypt->refcnt); | |
334 | if (res < 0) { | |
335 | printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed" | |
336 | " (SA=" MAC_FMT " keyidx=%d)\n", | |
337 | ieee->dev->name, MAC_ARG(hdr->addr2), keyidx); | |
338 | return -1; | |
339 | } | |
340 | ||
341 | return 0; | |
342 | } | |
343 | ||
344 | ||
345 | /* All received frames are sent to this function. @skb contains the frame in | |
346 | * IEEE 802.11 format, i.e., in the format it was sent over air. | |
347 | * This function is called only as a tasklet (software IRQ). */ | |
348 | int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, | |
349 | struct ieee80211_rx_stats *rx_stats) | |
350 | { | |
351 | struct net_device *dev = ieee->dev; | |
352 | struct ieee80211_hdr *hdr; | |
353 | size_t hdrlen; | |
354 | u16 fc, type, stype, sc; | |
355 | struct net_device_stats *stats; | |
356 | unsigned int frag; | |
357 | u8 *payload; | |
358 | u16 ethertype; | |
359 | #ifdef NOT_YET | |
360 | struct net_device *wds = NULL; | |
361 | struct sk_buff *skb2 = NULL; | |
362 | struct net_device *wds = NULL; | |
363 | int frame_authorized = 0; | |
364 | int from_assoc_ap = 0; | |
365 | void *sta = NULL; | |
366 | #endif | |
367 | u8 dst[ETH_ALEN]; | |
368 | u8 src[ETH_ALEN]; | |
369 | struct ieee80211_crypt_data *crypt = NULL; | |
370 | int keyidx = 0; | |
371 | ||
372 | hdr = (struct ieee80211_hdr *)skb->data; | |
373 | stats = &ieee->stats; | |
374 | ||
375 | if (skb->len < 10) { | |
376 | printk(KERN_INFO "%s: SKB length < 10\n", | |
377 | dev->name); | |
378 | goto rx_dropped; | |
379 | } | |
380 | ||
381 | fc = le16_to_cpu(hdr->frame_ctl); | |
382 | type = WLAN_FC_GET_TYPE(fc); | |
383 | stype = WLAN_FC_GET_STYPE(fc); | |
384 | sc = le16_to_cpu(hdr->seq_ctl); | |
385 | frag = WLAN_GET_SEQ_FRAG(sc); | |
386 | hdrlen = ieee80211_get_hdrlen(fc); | |
387 | ||
388 | #ifdef NOT_YET | |
389 | #if WIRELESS_EXT > 15 | |
390 | /* Put this code here so that we avoid duplicating it in all | |
391 | * Rx paths. - Jean II */ | |
392 | #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */ | |
393 | /* If spy monitoring on */ | |
394 | if (iface->spy_data.spy_number > 0) { | |
395 | struct iw_quality wstats; | |
396 | wstats.level = rx_stats->signal; | |
397 | wstats.noise = rx_stats->noise; | |
398 | wstats.updated = 6; /* No qual value */ | |
399 | /* Update spy records */ | |
400 | wireless_spy_update(dev, hdr->addr2, &wstats); | |
401 | } | |
402 | #endif /* IW_WIRELESS_SPY */ | |
403 | #endif /* WIRELESS_EXT > 15 */ | |
404 | hostap_update_rx_stats(local->ap, hdr, rx_stats); | |
405 | #endif | |
406 | ||
407 | #if WIRELESS_EXT > 15 | |
408 | if (ieee->iw_mode == IW_MODE_MONITOR) { | |
409 | ieee80211_monitor_rx(ieee, skb, rx_stats); | |
410 | stats->rx_packets++; | |
411 | stats->rx_bytes += skb->len; | |
412 | return 1; | |
413 | } | |
414 | #endif | |
415 | ||
416 | if (ieee->host_decrypt) { | |
417 | int idx = 0; | |
418 | if (skb->len >= hdrlen + 3) | |
419 | idx = skb->data[hdrlen + 3] >> 6; | |
420 | crypt = ieee->crypt[idx]; | |
421 | #ifdef NOT_YET | |
422 | sta = NULL; | |
423 | ||
424 | /* Use station specific key to override default keys if the | |
425 | * receiver address is a unicast address ("individual RA"). If | |
426 | * bcrx_sta_key parameter is set, station specific key is used | |
427 | * even with broad/multicast targets (this is against IEEE | |
428 | * 802.11, but makes it easier to use different keys with | |
429 | * stations that do not support WEP key mapping). */ | |
430 | ||
431 | if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key) | |
432 | (void) hostap_handle_sta_crypto(local, hdr, &crypt, | |
433 | &sta); | |
434 | #endif | |
435 | ||
436 | /* allow NULL decrypt to indicate an station specific override | |
437 | * for default encryption */ | |
438 | if (crypt && (crypt->ops == NULL || | |
439 | crypt->ops->decrypt_mpdu == NULL)) | |
440 | crypt = NULL; | |
441 | ||
f13baae4 | 442 | if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) { |
b453872c JG |
443 | /* This seems to be triggered by some (multicast?) |
444 | * frames from other than current BSS, so just drop the | |
445 | * frames silently instead of filling system log with | |
446 | * these reports. */ | |
447 | IEEE80211_DEBUG_DROP("Decryption failed (not set)" | |
448 | " (SA=" MAC_FMT ")\n", | |
449 | MAC_ARG(hdr->addr2)); | |
450 | ieee->ieee_stats.rx_discards_undecryptable++; | |
451 | goto rx_dropped; | |
452 | } | |
453 | } | |
454 | ||
455 | #ifdef NOT_YET | |
456 | if (type != WLAN_FC_TYPE_DATA) { | |
457 | if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH && | |
f13baae4 | 458 | fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt && |
b453872c JG |
459 | (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) |
460 | { | |
461 | printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth " | |
462 | "from " MAC_FMT "\n", dev->name, | |
463 | MAC_ARG(hdr->addr2)); | |
464 | /* TODO: could inform hostapd about this so that it | |
465 | * could send auth failure report */ | |
466 | goto rx_dropped; | |
467 | } | |
468 | ||
469 | if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype)) | |
470 | goto rx_dropped; | |
471 | else | |
472 | goto rx_exit; | |
473 | } | |
474 | #endif | |
475 | ||
476 | /* Data frame - extract src/dst addresses */ | |
286d9747 | 477 | if (skb->len < IEEE80211_3ADDR_LEN) |
b453872c JG |
478 | goto rx_dropped; |
479 | ||
480 | switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { | |
481 | case IEEE80211_FCTL_FROMDS: | |
482 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
483 | memcpy(src, hdr->addr3, ETH_ALEN); | |
484 | break; | |
485 | case IEEE80211_FCTL_TODS: | |
486 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
487 | memcpy(src, hdr->addr2, ETH_ALEN); | |
488 | break; | |
489 | case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: | |
286d9747 | 490 | if (skb->len < IEEE80211_4ADDR_LEN) |
b453872c JG |
491 | goto rx_dropped; |
492 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
493 | memcpy(src, hdr->addr4, ETH_ALEN); | |
494 | break; | |
495 | case 0: | |
496 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
497 | memcpy(src, hdr->addr2, ETH_ALEN); | |
498 | break; | |
499 | } | |
500 | ||
501 | #ifdef NOT_YET | |
502 | if (hostap_rx_frame_wds(ieee, hdr, fc, &wds)) | |
503 | goto rx_dropped; | |
504 | if (wds) { | |
505 | skb->dev = dev = wds; | |
506 | stats = hostap_get_stats(dev); | |
507 | } | |
508 | ||
509 | if (ieee->iw_mode == IW_MODE_MASTER && !wds && | |
510 | (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS && | |
511 | ieee->stadev && | |
512 | memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) { | |
513 | /* Frame from BSSID of the AP for which we are a client */ | |
514 | skb->dev = dev = ieee->stadev; | |
515 | stats = hostap_get_stats(dev); | |
516 | from_assoc_ap = 1; | |
517 | } | |
518 | #endif | |
519 | ||
520 | dev->last_rx = jiffies; | |
521 | ||
522 | #ifdef NOT_YET | |
523 | if ((ieee->iw_mode == IW_MODE_MASTER || | |
524 | ieee->iw_mode == IW_MODE_REPEAT) && | |
525 | !from_assoc_ap) { | |
526 | switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats, | |
527 | wds != NULL)) { | |
528 | case AP_RX_CONTINUE_NOT_AUTHORIZED: | |
529 | frame_authorized = 0; | |
530 | break; | |
531 | case AP_RX_CONTINUE: | |
532 | frame_authorized = 1; | |
533 | break; | |
534 | case AP_RX_DROP: | |
535 | goto rx_dropped; | |
536 | case AP_RX_EXIT: | |
537 | goto rx_exit; | |
538 | } | |
539 | } | |
540 | #endif | |
541 | ||
542 | /* Nullfunc frames may have PS-bit set, so they must be passed to | |
543 | * hostap_handle_sta_rx() before being dropped here. */ | |
544 | if (stype != IEEE80211_STYPE_DATA && | |
545 | stype != IEEE80211_STYPE_DATA_CFACK && | |
546 | stype != IEEE80211_STYPE_DATA_CFPOLL && | |
547 | stype != IEEE80211_STYPE_DATA_CFACKPOLL) { | |
548 | if (stype != IEEE80211_STYPE_NULLFUNC) | |
549 | IEEE80211_DEBUG_DROP( | |
550 | "RX: dropped data frame " | |
551 | "with no data (type=0x%02x, " | |
552 | "subtype=0x%02x, len=%d)\n", | |
553 | type, stype, skb->len); | |
554 | goto rx_dropped; | |
555 | } | |
556 | ||
557 | /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ | |
558 | ||
f13baae4 | 559 | if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && |
b453872c JG |
560 | (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) |
561 | goto rx_dropped; | |
562 | ||
563 | hdr = (struct ieee80211_hdr *) skb->data; | |
564 | ||
565 | /* skb: hdr + (possibly fragmented) plaintext payload */ | |
566 | // PR: FIXME: hostap has additional conditions in the "if" below: | |
f13baae4 | 567 | // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && |
b453872c JG |
568 | if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) { |
569 | int flen; | |
570 | struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr); | |
571 | IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag); | |
572 | ||
573 | if (!frag_skb) { | |
574 | IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG, | |
575 | "Rx cannot get skb from fragment " | |
576 | "cache (morefrag=%d seq=%u frag=%u)\n", | |
577 | (fc & IEEE80211_FCTL_MOREFRAGS) != 0, | |
578 | WLAN_GET_SEQ_SEQ(sc), frag); | |
579 | goto rx_dropped; | |
580 | } | |
581 | ||
582 | flen = skb->len; | |
583 | if (frag != 0) | |
584 | flen -= hdrlen; | |
585 | ||
586 | if (frag_skb->tail + flen > frag_skb->end) { | |
587 | printk(KERN_WARNING "%s: host decrypted and " | |
588 | "reassembled frame did not fit skb\n", | |
589 | dev->name); | |
590 | ieee80211_frag_cache_invalidate(ieee, hdr); | |
591 | goto rx_dropped; | |
592 | } | |
593 | ||
594 | if (frag == 0) { | |
595 | /* copy first fragment (including full headers) into | |
596 | * beginning of the fragment cache skb */ | |
597 | memcpy(skb_put(frag_skb, flen), skb->data, flen); | |
598 | } else { | |
599 | /* append frame payload to the end of the fragment | |
600 | * cache skb */ | |
601 | memcpy(skb_put(frag_skb, flen), skb->data + hdrlen, | |
602 | flen); | |
603 | } | |
604 | dev_kfree_skb_any(skb); | |
605 | skb = NULL; | |
606 | ||
607 | if (fc & IEEE80211_FCTL_MOREFRAGS) { | |
608 | /* more fragments expected - leave the skb in fragment | |
609 | * cache for now; it will be delivered to upper layers | |
610 | * after all fragments have been received */ | |
611 | goto rx_exit; | |
612 | } | |
613 | ||
614 | /* this was the last fragment and the frame will be | |
615 | * delivered, so remove skb from fragment cache */ | |
616 | skb = frag_skb; | |
617 | hdr = (struct ieee80211_hdr *) skb->data; | |
618 | ieee80211_frag_cache_invalidate(ieee, hdr); | |
619 | } | |
620 | ||
621 | /* skb: hdr + (possible reassembled) full MSDU payload; possibly still | |
622 | * encrypted/authenticated */ | |
f13baae4 | 623 | if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && |
b453872c JG |
624 | ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) |
625 | goto rx_dropped; | |
626 | ||
627 | hdr = (struct ieee80211_hdr *) skb->data; | |
f13baae4 | 628 | if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) { |
b453872c JG |
629 | if (/*ieee->ieee802_1x &&*/ |
630 | ieee80211_is_eapol_frame(ieee, skb)) { | |
b453872c JG |
631 | /* pass unencrypted EAPOL frames even if encryption is |
632 | * configured */ | |
b453872c JG |
633 | } else { |
634 | IEEE80211_DEBUG_DROP( | |
635 | "encryption configured, but RX " | |
636 | "frame not encrypted (SA=" MAC_FMT ")\n", | |
637 | MAC_ARG(hdr->addr2)); | |
638 | goto rx_dropped; | |
639 | } | |
640 | } | |
641 | ||
f13baae4 | 642 | if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep && |
b453872c JG |
643 | !ieee80211_is_eapol_frame(ieee, skb)) { |
644 | IEEE80211_DEBUG_DROP( | |
645 | "dropped unencrypted RX data " | |
646 | "frame from " MAC_FMT | |
647 | " (drop_unencrypted=1)\n", | |
648 | MAC_ARG(hdr->addr2)); | |
649 | goto rx_dropped; | |
650 | } | |
651 | ||
652 | /* skb: hdr + (possible reassembled) full plaintext payload */ | |
653 | ||
654 | payload = skb->data + hdrlen; | |
655 | ethertype = (payload[6] << 8) | payload[7]; | |
656 | ||
657 | #ifdef NOT_YET | |
658 | /* If IEEE 802.1X is used, check whether the port is authorized to send | |
659 | * the received frame. */ | |
660 | if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) { | |
661 | if (ethertype == ETH_P_PAE) { | |
662 | printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n", | |
663 | dev->name); | |
664 | if (ieee->hostapd && ieee->apdev) { | |
665 | /* Send IEEE 802.1X frames to the user | |
666 | * space daemon for processing */ | |
667 | prism2_rx_80211(ieee->apdev, skb, rx_stats, | |
668 | PRISM2_RX_MGMT); | |
669 | ieee->apdevstats.rx_packets++; | |
670 | ieee->apdevstats.rx_bytes += skb->len; | |
671 | goto rx_exit; | |
672 | } | |
673 | } else if (!frame_authorized) { | |
674 | printk(KERN_DEBUG "%s: dropped frame from " | |
675 | "unauthorized port (IEEE 802.1X): " | |
676 | "ethertype=0x%04x\n", | |
677 | dev->name, ethertype); | |
678 | goto rx_dropped; | |
679 | } | |
680 | } | |
681 | #endif | |
682 | ||
683 | /* convert hdr + possible LLC headers into Ethernet header */ | |
684 | if (skb->len - hdrlen >= 8 && | |
685 | ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 && | |
686 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | |
687 | memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) { | |
688 | /* remove RFC1042 or Bridge-Tunnel encapsulation and | |
689 | * replace EtherType */ | |
690 | skb_pull(skb, hdrlen + SNAP_SIZE); | |
691 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); | |
692 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); | |
693 | } else { | |
694 | u16 len; | |
695 | /* Leave Ethernet header part of hdr and full payload */ | |
696 | skb_pull(skb, hdrlen); | |
697 | len = htons(skb->len); | |
698 | memcpy(skb_push(skb, 2), &len, 2); | |
699 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); | |
700 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); | |
701 | } | |
702 | ||
703 | #ifdef NOT_YET | |
704 | if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == | |
705 | IEEE80211_FCTL_TODS) && | |
706 | skb->len >= ETH_HLEN + ETH_ALEN) { | |
707 | /* Non-standard frame: get addr4 from its bogus location after | |
708 | * the payload */ | |
709 | memcpy(skb->data + ETH_ALEN, | |
710 | skb->data + skb->len - ETH_ALEN, ETH_ALEN); | |
711 | skb_trim(skb, skb->len - ETH_ALEN); | |
712 | } | |
713 | #endif | |
714 | ||
715 | stats->rx_packets++; | |
716 | stats->rx_bytes += skb->len; | |
717 | ||
718 | #ifdef NOT_YET | |
719 | if (ieee->iw_mode == IW_MODE_MASTER && !wds && | |
720 | ieee->ap->bridge_packets) { | |
721 | if (dst[0] & 0x01) { | |
722 | /* copy multicast frame both to the higher layers and | |
723 | * to the wireless media */ | |
724 | ieee->ap->bridged_multicast++; | |
725 | skb2 = skb_clone(skb, GFP_ATOMIC); | |
726 | if (skb2 == NULL) | |
727 | printk(KERN_DEBUG "%s: skb_clone failed for " | |
728 | "multicast frame\n", dev->name); | |
729 | } else if (hostap_is_sta_assoc(ieee->ap, dst)) { | |
730 | /* send frame directly to the associated STA using | |
731 | * wireless media and not passing to higher layers */ | |
732 | ieee->ap->bridged_unicast++; | |
733 | skb2 = skb; | |
734 | skb = NULL; | |
735 | } | |
736 | } | |
737 | ||
738 | if (skb2 != NULL) { | |
739 | /* send to wireless media */ | |
740 | skb2->protocol = __constant_htons(ETH_P_802_3); | |
741 | skb2->mac.raw = skb2->nh.raw = skb2->data; | |
742 | /* skb2->nh.raw = skb2->data + ETH_HLEN; */ | |
743 | skb2->dev = dev; | |
744 | dev_queue_xmit(skb2); | |
745 | } | |
746 | ||
747 | #endif | |
748 | ||
749 | if (skb) { | |
750 | skb->protocol = eth_type_trans(skb, dev); | |
751 | memset(skb->cb, 0, sizeof(skb->cb)); | |
752 | skb->dev = dev; | |
753 | skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */ | |
754 | netif_rx(skb); | |
755 | } | |
756 | ||
757 | rx_exit: | |
758 | #ifdef NOT_YET | |
759 | if (sta) | |
760 | hostap_handle_sta_release(sta); | |
761 | #endif | |
762 | return 1; | |
763 | ||
764 | rx_dropped: | |
765 | stats->rx_dropped++; | |
766 | ||
767 | /* Returning 0 indicates to caller that we have not handled the SKB-- | |
768 | * so it is still allocated and can be used again by underlying | |
769 | * hardware as a DMA target */ | |
770 | return 0; | |
771 | } | |
772 | ||
773 | #define MGMT_FRAME_FIXED_PART_LENGTH 0x24 | |
774 | ||
775 | static inline int ieee80211_is_ofdm_rate(u8 rate) | |
776 | { | |
777 | switch (rate & ~IEEE80211_BASIC_RATE_MASK) { | |
778 | case IEEE80211_OFDM_RATE_6MB: | |
779 | case IEEE80211_OFDM_RATE_9MB: | |
780 | case IEEE80211_OFDM_RATE_12MB: | |
781 | case IEEE80211_OFDM_RATE_18MB: | |
782 | case IEEE80211_OFDM_RATE_24MB: | |
783 | case IEEE80211_OFDM_RATE_36MB: | |
784 | case IEEE80211_OFDM_RATE_48MB: | |
785 | case IEEE80211_OFDM_RATE_54MB: | |
786 | return 1; | |
787 | } | |
788 | return 0; | |
789 | } | |
790 | ||
791 | ||
792 | static inline int ieee80211_network_init( | |
793 | struct ieee80211_device *ieee, | |
794 | struct ieee80211_probe_response *beacon, | |
795 | struct ieee80211_network *network, | |
796 | struct ieee80211_rx_stats *stats) | |
797 | { | |
798 | #ifdef CONFIG_IEEE80211_DEBUG | |
799 | char rates_str[64]; | |
800 | char *p; | |
801 | #endif | |
802 | struct ieee80211_info_element *info_element; | |
803 | u16 left; | |
804 | u8 i; | |
805 | ||
806 | /* Pull out fixed field data */ | |
807 | memcpy(network->bssid, beacon->header.addr3, ETH_ALEN); | |
808 | network->capability = beacon->capability; | |
809 | network->last_scanned = jiffies; | |
810 | network->time_stamp[0] = beacon->time_stamp[0]; | |
811 | network->time_stamp[1] = beacon->time_stamp[1]; | |
812 | network->beacon_interval = beacon->beacon_interval; | |
813 | /* Where to pull this? beacon->listen_interval;*/ | |
814 | network->listen_interval = 0x0A; | |
815 | network->rates_len = network->rates_ex_len = 0; | |
816 | network->last_associate = 0; | |
817 | network->ssid_len = 0; | |
818 | network->flags = 0; | |
819 | network->atim_window = 0; | |
820 | ||
821 | if (stats->freq == IEEE80211_52GHZ_BAND) { | |
822 | /* for A band (No DS info) */ | |
823 | network->channel = stats->received_channel; | |
824 | } else | |
825 | network->flags |= NETWORK_HAS_CCK; | |
826 | ||
827 | network->wpa_ie_len = 0; | |
828 | network->rsn_ie_len = 0; | |
829 | ||
830 | info_element = &beacon->info_element; | |
831 | left = stats->len - ((void *)info_element - (void *)beacon); | |
832 | while (left >= sizeof(struct ieee80211_info_element_hdr)) { | |
833 | if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) { | |
834 | IEEE80211_DEBUG_SCAN("SCAN: parse failed: info_element->len + 2 > left : info_element->len+2=%d left=%d.\n", | |
835 | info_element->len + sizeof(struct ieee80211_info_element), | |
836 | left); | |
837 | return 1; | |
838 | } | |
839 | ||
840 | switch (info_element->id) { | |
841 | case MFIE_TYPE_SSID: | |
842 | if (ieee80211_is_empty_essid(info_element->data, | |
843 | info_element->len)) { | |
844 | network->flags |= NETWORK_EMPTY_ESSID; | |
845 | break; | |
846 | } | |
847 | ||
848 | network->ssid_len = min(info_element->len, | |
849 | (u8)IW_ESSID_MAX_SIZE); | |
850 | memcpy(network->ssid, info_element->data, network->ssid_len); | |
851 | if (network->ssid_len < IW_ESSID_MAX_SIZE) | |
852 | memset(network->ssid + network->ssid_len, 0, | |
853 | IW_ESSID_MAX_SIZE - network->ssid_len); | |
854 | ||
855 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_SSID: '%s' len=%d.\n", | |
856 | network->ssid, network->ssid_len); | |
857 | break; | |
858 | ||
859 | case MFIE_TYPE_RATES: | |
860 | #ifdef CONFIG_IEEE80211_DEBUG | |
861 | p = rates_str; | |
862 | #endif | |
863 | network->rates_len = min(info_element->len, MAX_RATES_LENGTH); | |
864 | for (i = 0; i < network->rates_len; i++) { | |
865 | network->rates[i] = info_element->data[i]; | |
866 | #ifdef CONFIG_IEEE80211_DEBUG | |
867 | p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]); | |
868 | #endif | |
869 | if (ieee80211_is_ofdm_rate(info_element->data[i])) { | |
870 | network->flags |= NETWORK_HAS_OFDM; | |
871 | if (info_element->data[i] & | |
872 | IEEE80211_BASIC_RATE_MASK) | |
873 | network->flags &= | |
874 | ~NETWORK_HAS_CCK; | |
875 | } | |
876 | } | |
877 | ||
878 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES: '%s' (%d)\n", | |
879 | rates_str, network->rates_len); | |
880 | break; | |
881 | ||
882 | case MFIE_TYPE_RATES_EX: | |
883 | #ifdef CONFIG_IEEE80211_DEBUG | |
884 | p = rates_str; | |
885 | #endif | |
886 | network->rates_ex_len = min(info_element->len, MAX_RATES_EX_LENGTH); | |
887 | for (i = 0; i < network->rates_ex_len; i++) { | |
888 | network->rates_ex[i] = info_element->data[i]; | |
889 | #ifdef CONFIG_IEEE80211_DEBUG | |
890 | p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]); | |
891 | #endif | |
892 | if (ieee80211_is_ofdm_rate(info_element->data[i])) { | |
893 | network->flags |= NETWORK_HAS_OFDM; | |
894 | if (info_element->data[i] & | |
895 | IEEE80211_BASIC_RATE_MASK) | |
896 | network->flags &= | |
897 | ~NETWORK_HAS_CCK; | |
898 | } | |
899 | } | |
900 | ||
901 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES_EX: '%s' (%d)\n", | |
902 | rates_str, network->rates_ex_len); | |
903 | break; | |
904 | ||
905 | case MFIE_TYPE_DS_SET: | |
906 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_DS_SET: %d\n", | |
907 | info_element->data[0]); | |
908 | if (stats->freq == IEEE80211_24GHZ_BAND) | |
909 | network->channel = info_element->data[0]; | |
910 | break; | |
911 | ||
912 | case MFIE_TYPE_FH_SET: | |
913 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_FH_SET: ignored\n"); | |
914 | break; | |
915 | ||
916 | case MFIE_TYPE_CF_SET: | |
917 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_CF_SET: ignored\n"); | |
918 | break; | |
919 | ||
920 | case MFIE_TYPE_TIM: | |
921 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_TIM: ignored\n"); | |
922 | break; | |
923 | ||
924 | case MFIE_TYPE_IBSS_SET: | |
925 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_IBSS_SET: ignored\n"); | |
926 | break; | |
927 | ||
928 | case MFIE_TYPE_CHALLENGE: | |
929 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_CHALLENGE: ignored\n"); | |
930 | break; | |
931 | ||
932 | case MFIE_TYPE_GENERIC: | |
933 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", | |
934 | info_element->len); | |
935 | if (info_element->len >= 4 && | |
936 | info_element->data[0] == 0x00 && | |
937 | info_element->data[1] == 0x50 && | |
938 | info_element->data[2] == 0xf2 && | |
939 | info_element->data[3] == 0x01) { | |
940 | network->wpa_ie_len = min(info_element->len + 2, | |
941 | MAX_WPA_IE_LEN); | |
942 | memcpy(network->wpa_ie, info_element, | |
943 | network->wpa_ie_len); | |
944 | } | |
945 | break; | |
946 | ||
947 | case MFIE_TYPE_RSN: | |
948 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_RSN: %d bytes\n", | |
949 | info_element->len); | |
950 | network->rsn_ie_len = min(info_element->len + 2, | |
951 | MAX_WPA_IE_LEN); | |
952 | memcpy(network->rsn_ie, info_element, | |
953 | network->rsn_ie_len); | |
954 | break; | |
955 | ||
956 | default: | |
957 | IEEE80211_DEBUG_SCAN("unsupported IE %d\n", | |
958 | info_element->id); | |
959 | break; | |
960 | } | |
961 | ||
962 | left -= sizeof(struct ieee80211_info_element_hdr) + | |
963 | info_element->len; | |
964 | info_element = (struct ieee80211_info_element *) | |
965 | &info_element->data[info_element->len]; | |
966 | } | |
967 | ||
968 | network->mode = 0; | |
969 | if (stats->freq == IEEE80211_52GHZ_BAND) | |
970 | network->mode = IEEE_A; | |
971 | else { | |
972 | if (network->flags & NETWORK_HAS_OFDM) | |
973 | network->mode |= IEEE_G; | |
974 | if (network->flags & NETWORK_HAS_CCK) | |
975 | network->mode |= IEEE_B; | |
976 | } | |
977 | ||
978 | if (network->mode == 0) { | |
979 | IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' " | |
980 | "network.\n", | |
981 | escape_essid(network->ssid, | |
982 | network->ssid_len), | |
983 | MAC_ARG(network->bssid)); | |
984 | return 1; | |
985 | } | |
986 | ||
987 | if (ieee80211_is_empty_essid(network->ssid, network->ssid_len)) | |
988 | network->flags |= NETWORK_EMPTY_ESSID; | |
989 | ||
990 | memcpy(&network->stats, stats, sizeof(network->stats)); | |
991 | ||
992 | return 0; | |
993 | } | |
994 | ||
995 | static inline int is_same_network(struct ieee80211_network *src, | |
996 | struct ieee80211_network *dst) | |
997 | { | |
998 | /* A network is only a duplicate if the channel, BSSID, and ESSID | |
999 | * all match. We treat all <hidden> with the same BSSID and channel | |
1000 | * as one network */ | |
1001 | return ((src->ssid_len == dst->ssid_len) && | |
1002 | (src->channel == dst->channel) && | |
1003 | !memcmp(src->bssid, dst->bssid, ETH_ALEN) && | |
1004 | !memcmp(src->ssid, dst->ssid, src->ssid_len)); | |
1005 | } | |
1006 | ||
1007 | static inline void update_network(struct ieee80211_network *dst, | |
1008 | struct ieee80211_network *src) | |
1009 | { | |
1010 | memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats)); | |
1011 | dst->capability = src->capability; | |
1012 | memcpy(dst->rates, src->rates, src->rates_len); | |
1013 | dst->rates_len = src->rates_len; | |
1014 | memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len); | |
1015 | dst->rates_ex_len = src->rates_ex_len; | |
1016 | ||
1017 | dst->mode = src->mode; | |
1018 | dst->flags = src->flags; | |
1019 | dst->time_stamp[0] = src->time_stamp[0]; | |
1020 | dst->time_stamp[1] = src->time_stamp[1]; | |
1021 | ||
1022 | dst->beacon_interval = src->beacon_interval; | |
1023 | dst->listen_interval = src->listen_interval; | |
1024 | dst->atim_window = src->atim_window; | |
1025 | ||
1026 | memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len); | |
1027 | dst->wpa_ie_len = src->wpa_ie_len; | |
1028 | memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len); | |
1029 | dst->rsn_ie_len = src->rsn_ie_len; | |
1030 | ||
1031 | dst->last_scanned = jiffies; | |
1032 | /* dst->last_associate is not overwritten */ | |
1033 | } | |
1034 | ||
1035 | static inline void ieee80211_process_probe_response( | |
1036 | struct ieee80211_device *ieee, | |
1037 | struct ieee80211_probe_response *beacon, | |
1038 | struct ieee80211_rx_stats *stats) | |
1039 | { | |
1040 | struct ieee80211_network network; | |
1041 | struct ieee80211_network *target; | |
1042 | struct ieee80211_network *oldest = NULL; | |
1043 | #ifdef CONFIG_IEEE80211_DEBUG | |
1044 | struct ieee80211_info_element *info_element = &beacon->info_element; | |
1045 | #endif | |
1046 | unsigned long flags; | |
1047 | ||
1048 | IEEE80211_DEBUG_SCAN( | |
1049 | "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n", | |
1050 | escape_essid(info_element->data, info_element->len), | |
1051 | MAC_ARG(beacon->header.addr3), | |
1052 | (beacon->capability & (1<<0xf)) ? '1' : '0', | |
1053 | (beacon->capability & (1<<0xe)) ? '1' : '0', | |
1054 | (beacon->capability & (1<<0xd)) ? '1' : '0', | |
1055 | (beacon->capability & (1<<0xc)) ? '1' : '0', | |
1056 | (beacon->capability & (1<<0xb)) ? '1' : '0', | |
1057 | (beacon->capability & (1<<0xa)) ? '1' : '0', | |
1058 | (beacon->capability & (1<<0x9)) ? '1' : '0', | |
1059 | (beacon->capability & (1<<0x8)) ? '1' : '0', | |
1060 | (beacon->capability & (1<<0x7)) ? '1' : '0', | |
1061 | (beacon->capability & (1<<0x6)) ? '1' : '0', | |
1062 | (beacon->capability & (1<<0x5)) ? '1' : '0', | |
1063 | (beacon->capability & (1<<0x4)) ? '1' : '0', | |
1064 | (beacon->capability & (1<<0x3)) ? '1' : '0', | |
1065 | (beacon->capability & (1<<0x2)) ? '1' : '0', | |
1066 | (beacon->capability & (1<<0x1)) ? '1' : '0', | |
1067 | (beacon->capability & (1<<0x0)) ? '1' : '0'); | |
1068 | ||
1069 | if (ieee80211_network_init(ieee, beacon, &network, stats)) { | |
1070 | IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n", | |
1071 | escape_essid(info_element->data, | |
1072 | info_element->len), | |
1073 | MAC_ARG(beacon->header.addr3), | |
1074 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == | |
1075 | IEEE80211_STYPE_PROBE_RESP ? | |
1076 | "PROBE RESPONSE" : "BEACON"); | |
1077 | return; | |
1078 | } | |
1079 | ||
1080 | /* The network parsed correctly -- so now we scan our known networks | |
1081 | * to see if we can find it in our list. | |
1082 | * | |
1083 | * NOTE: This search is definitely not optimized. Once its doing | |
1084 | * the "right thing" we'll optimize it for efficiency if | |
1085 | * necessary */ | |
1086 | ||
1087 | /* Search for this entry in the list and update it if it is | |
1088 | * already there. */ | |
1089 | ||
1090 | spin_lock_irqsave(&ieee->lock, flags); | |
1091 | ||
1092 | list_for_each_entry(target, &ieee->network_list, list) { | |
1093 | if (is_same_network(target, &network)) | |
1094 | break; | |
1095 | ||
1096 | if ((oldest == NULL) || | |
1097 | (target->last_scanned < oldest->last_scanned)) | |
1098 | oldest = target; | |
1099 | } | |
1100 | ||
1101 | /* If we didn't find a match, then get a new network slot to initialize | |
1102 | * with this beacon's information */ | |
1103 | if (&target->list == &ieee->network_list) { | |
1104 | if (list_empty(&ieee->network_free_list)) { | |
1105 | /* If there are no more slots, expire the oldest */ | |
1106 | list_del(&oldest->list); | |
1107 | target = oldest; | |
1108 | IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from " | |
1109 | "network list.\n", | |
1110 | escape_essid(target->ssid, | |
1111 | target->ssid_len), | |
1112 | MAC_ARG(target->bssid)); | |
1113 | } else { | |
1114 | /* Otherwise just pull from the free list */ | |
1115 | target = list_entry(ieee->network_free_list.next, | |
1116 | struct ieee80211_network, list); | |
1117 | list_del(ieee->network_free_list.next); | |
1118 | } | |
1119 | ||
1120 | ||
1121 | #ifdef CONFIG_IEEE80211_DEBUG | |
1122 | IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n", | |
1123 | escape_essid(network.ssid, | |
1124 | network.ssid_len), | |
1125 | MAC_ARG(network.bssid), | |
1126 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == | |
1127 | IEEE80211_STYPE_PROBE_RESP ? | |
1128 | "PROBE RESPONSE" : "BEACON"); | |
1129 | #endif | |
1130 | memcpy(target, &network, sizeof(*target)); | |
1131 | list_add_tail(&target->list, &ieee->network_list); | |
1132 | } else { | |
1133 | IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n", | |
1134 | escape_essid(target->ssid, | |
1135 | target->ssid_len), | |
1136 | MAC_ARG(target->bssid), | |
1137 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == | |
1138 | IEEE80211_STYPE_PROBE_RESP ? | |
1139 | "PROBE RESPONSE" : "BEACON"); | |
1140 | update_network(target, &network); | |
1141 | } | |
1142 | ||
1143 | spin_unlock_irqrestore(&ieee->lock, flags); | |
1144 | } | |
1145 | ||
1146 | void ieee80211_rx_mgt(struct ieee80211_device *ieee, | |
1147 | struct ieee80211_hdr *header, | |
1148 | struct ieee80211_rx_stats *stats) | |
1149 | { | |
1150 | switch (WLAN_FC_GET_STYPE(header->frame_ctl)) { | |
1151 | case IEEE80211_STYPE_ASSOC_RESP: | |
1152 | IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n", | |
1153 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
1154 | break; | |
1155 | ||
1156 | case IEEE80211_STYPE_REASSOC_RESP: | |
1157 | IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n", | |
1158 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
1159 | break; | |
1160 | ||
1161 | case IEEE80211_STYPE_PROBE_RESP: | |
1162 | IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n", | |
1163 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
1164 | IEEE80211_DEBUG_SCAN("Probe response\n"); | |
1165 | ieee80211_process_probe_response( | |
1166 | ieee, (struct ieee80211_probe_response *)header, stats); | |
1167 | break; | |
1168 | ||
1169 | case IEEE80211_STYPE_BEACON: | |
1170 | IEEE80211_DEBUG_MGMT("received BEACON (%d)\n", | |
1171 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
1172 | IEEE80211_DEBUG_SCAN("Beacon\n"); | |
1173 | ieee80211_process_probe_response( | |
1174 | ieee, (struct ieee80211_probe_response *)header, stats); | |
1175 | break; | |
1176 | ||
1177 | default: | |
1178 | IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n", | |
1179 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
1180 | IEEE80211_WARNING("%s: Unknown management packet: %d\n", | |
1181 | ieee->dev->name, | |
1182 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
1183 | break; | |
1184 | } | |
1185 | } | |
1186 | ||
1187 | ||
1188 | EXPORT_SYMBOL(ieee80211_rx_mgt); | |
1189 | EXPORT_SYMBOL(ieee80211_rx); |