1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/compiler.h>
17#include <linux/errno.h>
18#include <linux/if_arp.h>
19#include <linux/in6.h>
20#include <linux/in.h>
21#include <linux/ip.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/netdevice.h>
25#include <linux/proc_fs.h>
26#include <linux/skbuff.h>
27#include <linux/slab.h>
28#include <linux/tcp.h>
29#include <linux/types.h>
30#include <linux/wireless.h>
31#include <linux/etherdevice.h>
32#include <asm/uaccess.h>
33#include <linux/ctype.h>
34
35#include <net/lib80211.h>
36
37#include "libipw.h"
38
39static void libipw_monitor_rx(struct libipw_device *ieee,
40 struct sk_buff *skb,
41 struct libipw_rx_stats *rx_stats)
42{
43 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
44 u16 fc = le16_to_cpu(hdr->frame_control);
45
46 skb->dev = ieee->dev;
47 skb_reset_mac_header(skb);
48 skb_pull(skb, libipw_get_hdrlen(fc));
49 skb->pkt_type = PACKET_OTHERHOST;
50 skb->protocol = htons(ETH_P_80211_RAW);
51 memset(skb->cb, 0, sizeof(skb->cb));
52 netif_rx(skb);
53}
54
55
56static struct libipw_frag_entry *libipw_frag_cache_find(struct
57 libipw_device
58 *ieee,
59 unsigned int seq,
60 unsigned int frag,
61 u8 * src,
62 u8 * dst)
63{
64 struct libipw_frag_entry *entry;
65 int i;
66
67 for (i = 0; i < LIBIPW_FRAG_CACHE_LEN; i++) {
68 entry = &ieee->frag_cache[i];
69 if (entry->skb != NULL &&
70 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
71 LIBIPW_DEBUG_FRAG("expiring fragment cache entry "
72 "seq=%u last_frag=%u\n",
73 entry->seq, entry->last_frag);
74 dev_kfree_skb_any(entry->skb);
75 entry->skb = NULL;
76 }
77
78 if (entry->skb != NULL && entry->seq == seq &&
79 (entry->last_frag + 1 == frag || frag == -1) &&
80 !compare_ether_addr(entry->src_addr, src) &&
81 !compare_ether_addr(entry->dst_addr, dst))
82 return entry;
83 }
84
85 return NULL;
86}
87
88
89static struct sk_buff *libipw_frag_cache_get(struct libipw_device *ieee,
90 struct libipw_hdr_4addr *hdr)
91{
92 struct sk_buff *skb = NULL;
93 u16 sc;
94 unsigned int frag, seq;
95 struct libipw_frag_entry *entry;
96
97 sc = le16_to_cpu(hdr->seq_ctl);
98 frag = WLAN_GET_SEQ_FRAG(sc);
99 seq = WLAN_GET_SEQ_SEQ(sc);
100
101 if (frag == 0) {
102
103 skb = dev_alloc_skb(ieee->dev->mtu +
104 sizeof(struct libipw_hdr_4addr) +
105 8 +
106 2 +
107 8 + ETH_ALEN );
108 if (skb == NULL)
109 return NULL;
110
111 entry = &ieee->frag_cache[ieee->frag_next_idx];
112 ieee->frag_next_idx++;
113 if (ieee->frag_next_idx >= LIBIPW_FRAG_CACHE_LEN)
114 ieee->frag_next_idx = 0;
115
116 if (entry->skb != NULL)
117 dev_kfree_skb_any(entry->skb);
118
119 entry->first_frag_time = jiffies;
120 entry->seq = seq;
121 entry->last_frag = frag;
122 entry->skb = skb;
123 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
124 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
125 } else {
126
127
128 entry = libipw_frag_cache_find(ieee, seq, frag, hdr->addr2,
129 hdr->addr1);
130 if (entry != NULL) {
131 entry->last_frag = frag;
132 skb = entry->skb;
133 }
134 }
135
136 return skb;
137}
138
139
140static int libipw_frag_cache_invalidate(struct libipw_device *ieee,
141 struct libipw_hdr_4addr *hdr)
142{
143 u16 sc;
144 unsigned int seq;
145 struct libipw_frag_entry *entry;
146
147 sc = le16_to_cpu(hdr->seq_ctl);
148 seq = WLAN_GET_SEQ_SEQ(sc);
149
150 entry = libipw_frag_cache_find(ieee, seq, -1, hdr->addr2,
151 hdr->addr1);
152
153 if (entry == NULL) {
154 LIBIPW_DEBUG_FRAG("could not invalidate fragment cache "
155 "entry (seq=%u)\n", seq);
156 return -1;
157 }
158
159 entry->skb = NULL;
160 return 0;
161}
162
163#ifdef NOT_YET
164
165
166
167
168
169static int
170libipw_rx_frame_mgmt(struct libipw_device *ieee, struct sk_buff *skb,
171 struct libipw_rx_stats *rx_stats, u16 type,
172 u16 stype)
173{
174 if (ieee->iw_mode == IW_MODE_MASTER) {
175 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
176 ieee->dev->name);
177 return 0;
178
179
180
181 }
182
183 if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
184 if (stype == WLAN_FC_STYPE_BEACON &&
185 ieee->iw_mode == IW_MODE_MASTER) {
186 struct sk_buff *skb2;
187
188
189 skb2 = skb_clone(skb, GFP_ATOMIC);
190 if (skb2)
191 hostap_rx(skb2->dev, skb2, rx_stats);
192 }
193
194
195
196 ieee->apdevstats.rx_packets++;
197 ieee->apdevstats.rx_bytes += skb->len;
198 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
199 return 0;
200 }
201
202 if (ieee->iw_mode == IW_MODE_MASTER) {
203 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
204 printk(KERN_DEBUG "%s: unknown management frame "
205 "(type=0x%02x, stype=0x%02x) dropped\n",
206 skb->dev->name, type, stype);
207 return -1;
208 }
209
210 hostap_rx(skb->dev, skb, rx_stats);
211 return 0;
212 }
213
214 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
215 "received in non-Host AP mode\n", skb->dev->name);
216 return -1;
217}
218#endif
219
220
221
222static unsigned char libipw_rfc1042_header[] =
223 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
224
225
226static unsigned char libipw_bridge_tunnel_header[] =
227 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
228
229
230
231static int libipw_is_eapol_frame(struct libipw_device *ieee,
232 struct sk_buff *skb)
233{
234 struct net_device *dev = ieee->dev;
235 u16 fc, ethertype;
236 struct libipw_hdr_3addr *hdr;
237 u8 *pos;
238
239 if (skb->len < 24)
240 return 0;
241
242 hdr = (struct libipw_hdr_3addr *)skb->data;
243 fc = le16_to_cpu(hdr->frame_ctl);
244
245
246 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
247 IEEE80211_FCTL_TODS &&
248 !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
249 !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
250
251 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
252 IEEE80211_FCTL_FROMDS &&
253 !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
254
255 } else
256 return 0;
257
258 if (skb->len < 24 + 8)
259 return 0;
260
261
262 pos = skb->data + 24;
263 ethertype = (pos[6] << 8) | pos[7];
264 if (ethertype == ETH_P_PAE)
265 return 1;
266
267 return 0;
268}
269
270
271static int
272libipw_rx_frame_decrypt(struct libipw_device *ieee, struct sk_buff *skb,
273 struct lib80211_crypt_data *crypt)
274{
275 struct libipw_hdr_3addr *hdr;
276 int res, hdrlen;
277
278 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
279 return 0;
280
281 hdr = (struct libipw_hdr_3addr *)skb->data;
282 hdrlen = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
283
284 atomic_inc(&crypt->refcnt);
285 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
286 atomic_dec(&crypt->refcnt);
287 if (res < 0) {
288 LIBIPW_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
289 hdr->addr2, res);
290 if (res == -2)
291 LIBIPW_DEBUG_DROP("Decryption failed ICV "
292 "mismatch (key %d)\n",
293 skb->data[hdrlen + 3] >> 6);
294 ieee->ieee_stats.rx_discards_undecryptable++;
295 return -1;
296 }
297
298 return res;
299}
300
301
302static int
303libipw_rx_frame_decrypt_msdu(struct libipw_device *ieee,
304 struct sk_buff *skb, int keyidx,
305 struct lib80211_crypt_data *crypt)
306{
307 struct libipw_hdr_3addr *hdr;
308 int res, hdrlen;
309
310 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
311 return 0;
312
313 hdr = (struct libipw_hdr_3addr *)skb->data;
314 hdrlen = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
315
316 atomic_inc(&crypt->refcnt);
317 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
318 atomic_dec(&crypt->refcnt);
319 if (res < 0) {
320 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
321 " (SA=%pM keyidx=%d)\n", ieee->dev->name, hdr->addr2,
322 keyidx);
323 return -1;
324 }
325
326 return 0;
327}
328
329
330
331
332int libipw_rx(struct libipw_device *ieee, struct sk_buff *skb,
333 struct libipw_rx_stats *rx_stats)
334{
335 struct net_device *dev = ieee->dev;
336 struct libipw_hdr_4addr *hdr;
337 size_t hdrlen;
338 u16 fc, type, stype, sc;
339 unsigned int frag;
340 u8 *payload;
341 u16 ethertype;
342#ifdef NOT_YET
343 struct net_device *wds = NULL;
344 struct sk_buff *skb2 = NULL;
345 struct net_device *wds = NULL;
346 int frame_authorized = 0;
347 int from_assoc_ap = 0;
348 void *sta = NULL;
349#endif
350 u8 dst[ETH_ALEN];
351 u8 src[ETH_ALEN];
352 struct lib80211_crypt_data *crypt = NULL;
353 int keyidx = 0;
354 int can_be_decrypted = 0;
355
356 hdr = (struct libipw_hdr_4addr *)skb->data;
357 if (skb->len < 10) {
358 printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
359 goto rx_dropped;
360 }
361
362 fc = le16_to_cpu(hdr->frame_ctl);
363 type = WLAN_FC_GET_TYPE(fc);
364 stype = WLAN_FC_GET_STYPE(fc);
365 sc = le16_to_cpu(hdr->seq_ctl);
366 frag = WLAN_GET_SEQ_FRAG(sc);
367 hdrlen = libipw_get_hdrlen(fc);
368
369 if (skb->len < hdrlen) {
370 printk(KERN_INFO "%s: invalid SKB length %d\n",
371 dev->name, skb->len);
372 goto rx_dropped;
373 }
374
375
376
377#ifdef CONFIG_WIRELESS_EXT
378#ifdef IW_WIRELESS_SPY
379
380 if (ieee->spy_data.spy_number > 0) {
381 struct iw_quality wstats;
382
383 wstats.updated = 0;
384 if (rx_stats->mask & LIBIPW_STATMASK_RSSI) {
385 wstats.level = rx_stats->signal;
386 wstats.updated |= IW_QUAL_LEVEL_UPDATED;
387 } else
388 wstats.updated |= IW_QUAL_LEVEL_INVALID;
389
390 if (rx_stats->mask & LIBIPW_STATMASK_NOISE) {
391 wstats.noise = rx_stats->noise;
392 wstats.updated |= IW_QUAL_NOISE_UPDATED;
393 } else
394 wstats.updated |= IW_QUAL_NOISE_INVALID;
395
396 if (rx_stats->mask & LIBIPW_STATMASK_SIGNAL) {
397 wstats.qual = rx_stats->signal;
398 wstats.updated |= IW_QUAL_QUAL_UPDATED;
399 } else
400 wstats.updated |= IW_QUAL_QUAL_INVALID;
401
402
403 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
404 }
405#endif
406#endif
407
408#ifdef NOT_YET
409 hostap_update_rx_stats(local->ap, hdr, rx_stats);
410#endif
411
412 if (ieee->iw_mode == IW_MODE_MONITOR) {
413 dev->stats.rx_packets++;
414 dev->stats.rx_bytes += skb->len;
415 libipw_monitor_rx(ieee, skb, rx_stats);
416 return 1;
417 }
418
419 can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
420 is_broadcast_ether_addr(hdr->addr2)) ?
421 ieee->host_mc_decrypt : ieee->host_decrypt;
422
423 if (can_be_decrypted) {
424 if (skb->len >= hdrlen + 3) {
425
426 keyidx = skb->data[hdrlen + 3] >> 6;
427 }
428
429
430
431
432
433 crypt = ieee->crypt_info.crypt[keyidx];
434
435#ifdef NOT_YET
436 sta = NULL;
437
438
439
440
441
442
443
444
445 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
446 (void)hostap_handle_sta_crypto(local, hdr, &crypt,
447 &sta);
448#endif
449
450
451
452 if (crypt && (crypt->ops == NULL ||
453 crypt->ops->decrypt_mpdu == NULL))
454 crypt = NULL;
455
456 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
457
458
459
460
461 LIBIPW_DEBUG_DROP("Decryption failed (not set)"
462 " (SA=%pM)\n", hdr->addr2);
463 ieee->ieee_stats.rx_discards_undecryptable++;
464 goto rx_dropped;
465 }
466 }
467#ifdef NOT_YET
468 if (type != WLAN_FC_TYPE_DATA) {
469 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
470 fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
471 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
472 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
473 "from %pM\n", dev->name, hdr->addr2);
474
475
476 goto rx_dropped;
477 }
478
479 if (libipw_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
480 goto rx_dropped;
481 else
482 goto rx_exit;
483 }
484#endif
485
486 if (sc == ieee->prev_seq_ctl)
487 goto rx_dropped;
488 else
489 ieee->prev_seq_ctl = sc;
490
491
492 if (skb->len < LIBIPW_3ADDR_LEN)
493 goto rx_dropped;
494
495 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
496 case IEEE80211_FCTL_FROMDS:
497 memcpy(dst, hdr->addr1, ETH_ALEN);
498 memcpy(src, hdr->addr3, ETH_ALEN);
499 break;
500 case IEEE80211_FCTL_TODS:
501 memcpy(dst, hdr->addr3, ETH_ALEN);
502 memcpy(src, hdr->addr2, ETH_ALEN);
503 break;
504 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
505 if (skb->len < LIBIPW_4ADDR_LEN)
506 goto rx_dropped;
507 memcpy(dst, hdr->addr3, ETH_ALEN);
508 memcpy(src, hdr->addr4, ETH_ALEN);
509 break;
510 case 0:
511 memcpy(dst, hdr->addr1, ETH_ALEN);
512 memcpy(src, hdr->addr2, ETH_ALEN);
513 break;
514 }
515
516#ifdef NOT_YET
517 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
518 goto rx_dropped;
519 if (wds) {
520 skb->dev = dev = wds;
521 stats = hostap_get_stats(dev);
522 }
523
524 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
525 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
526 IEEE80211_FCTL_FROMDS && ieee->stadev
527 && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
528
529 skb->dev = dev = ieee->stadev;
530 stats = hostap_get_stats(dev);
531 from_assoc_ap = 1;
532 }
533#endif
534
535#ifdef NOT_YET
536 if ((ieee->iw_mode == IW_MODE_MASTER ||
537 ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
538 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
539 wds != NULL)) {
540 case AP_RX_CONTINUE_NOT_AUTHORIZED:
541 frame_authorized = 0;
542 break;
543 case AP_RX_CONTINUE:
544 frame_authorized = 1;
545 break;
546 case AP_RX_DROP:
547 goto rx_dropped;
548 case AP_RX_EXIT:
549 goto rx_exit;
550 }
551 }
552#endif
553
554
555
556
557 stype &= ~IEEE80211_STYPE_QOS_DATA;
558
559 if (stype != IEEE80211_STYPE_DATA &&
560 stype != IEEE80211_STYPE_DATA_CFACK &&
561 stype != IEEE80211_STYPE_DATA_CFPOLL &&
562 stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
563 if (stype != IEEE80211_STYPE_NULLFUNC)
564 LIBIPW_DEBUG_DROP("RX: dropped data frame "
565 "with no data (type=0x%02x, "
566 "subtype=0x%02x, len=%d)\n",
567 type, stype, skb->len);
568 goto rx_dropped;
569 }
570
571
572
573 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
574 (keyidx = libipw_rx_frame_decrypt(ieee, skb, crypt)) < 0)
575 goto rx_dropped;
576
577 hdr = (struct libipw_hdr_4addr *)skb->data;
578
579
580
581
582 if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
583 int flen;
584 struct sk_buff *frag_skb = libipw_frag_cache_get(ieee, hdr);
585 LIBIPW_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
586
587 if (!frag_skb) {
588 LIBIPW_DEBUG(LIBIPW_DL_RX | LIBIPW_DL_FRAG,
589 "Rx cannot get skb from fragment "
590 "cache (morefrag=%d seq=%u frag=%u)\n",
591 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
592 WLAN_GET_SEQ_SEQ(sc), frag);
593 goto rx_dropped;
594 }
595
596 flen = skb->len;
597 if (frag != 0)
598 flen -= hdrlen;
599
600 if (frag_skb->tail + flen > frag_skb->end) {
601 printk(KERN_WARNING "%s: host decrypted and "
602 "reassembled frame did not fit skb\n",
603 dev->name);
604 libipw_frag_cache_invalidate(ieee, hdr);
605 goto rx_dropped;
606 }
607
608 if (frag == 0) {
609
610
611 skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
612 } else {
613
614
615 skb_copy_from_linear_data_offset(skb, hdrlen,
616 skb_put(frag_skb, flen), flen);
617 }
618 dev_kfree_skb_any(skb);
619 skb = NULL;
620
621 if (fc & IEEE80211_FCTL_MOREFRAGS) {
622
623
624
625 goto rx_exit;
626 }
627
628
629
630 skb = frag_skb;
631 hdr = (struct libipw_hdr_4addr *)skb->data;
632 libipw_frag_cache_invalidate(ieee, hdr);
633 }
634
635
636
637 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
638 libipw_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
639 goto rx_dropped;
640
641 hdr = (struct libipw_hdr_4addr *)skb->data;
642 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
643 if (
644 libipw_is_eapol_frame(ieee, skb)) {
645
646
647 } else {
648 LIBIPW_DEBUG_DROP("encryption configured, but RX "
649 "frame not encrypted (SA=%pM)\n",
650 hdr->addr2);
651 goto rx_dropped;
652 }
653 }
654
655 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
656 !libipw_is_eapol_frame(ieee, skb)) {
657 LIBIPW_DEBUG_DROP("dropped unencrypted RX data "
658 "frame from %pM (drop_unencrypted=1)\n",
659 hdr->addr2);
660 goto rx_dropped;
661 }
662
663
664
665 if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
666 ieee->host_strip_iv_icv) {
667 int trimlen = 0;
668
669
670 if (skb->len >= hdrlen + 3)
671 keyidx = skb->data[hdrlen + 3] >> 6;
672
673
674
675
676
677
678 switch (ieee->sec.encode_alg[keyidx]) {
679 case SEC_ALG_WEP:
680
681 hdrlen += 4;
682
683 trimlen = 4;
684 break;
685 case SEC_ALG_TKIP:
686
687 hdrlen += 8;
688
689 trimlen = 12;
690 break;
691 case SEC_ALG_CCMP:
692
693 hdrlen += 8;
694
695 trimlen = 8;
696 break;
697 }
698
699 if (skb->len < trimlen)
700 goto rx_dropped;
701
702 __skb_trim(skb, skb->len - trimlen);
703
704 if (skb->len < hdrlen)
705 goto rx_dropped;
706 }
707
708
709
710 payload = skb->data + hdrlen;
711 ethertype = (payload[6] << 8) | payload[7];
712
713#ifdef NOT_YET
714
715
716 if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
717 if (ethertype == ETH_P_PAE) {
718 printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
719 dev->name);
720 if (ieee->hostapd && ieee->apdev) {
721
722
723 prism2_rx_80211(ieee->apdev, skb, rx_stats,
724 PRISM2_RX_MGMT);
725 ieee->apdevstats.rx_packets++;
726 ieee->apdevstats.rx_bytes += skb->len;
727 goto rx_exit;
728 }
729 } else if (!frame_authorized) {
730 printk(KERN_DEBUG "%s: dropped frame from "
731 "unauthorized port (IEEE 802.1X): "
732 "ethertype=0x%04x\n", dev->name, ethertype);
733 goto rx_dropped;
734 }
735 }
736#endif
737
738
739 if (skb->len - hdrlen >= 8 &&
740 ((memcmp(payload, libipw_rfc1042_header, SNAP_SIZE) == 0 &&
741 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
742 memcmp(payload, libipw_bridge_tunnel_header, SNAP_SIZE) == 0)) {
743
744
745 skb_pull(skb, hdrlen + SNAP_SIZE);
746 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
747 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
748 } else {
749 __be16 len;
750
751 skb_pull(skb, hdrlen);
752 len = htons(skb->len);
753 memcpy(skb_push(skb, 2), &len, 2);
754 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
755 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
756 }
757
758#ifdef NOT_YET
759 if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
760 IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
761
762
763 skb_copy_to_linear_data_offset(skb, ETH_ALEN,
764 skb->data + skb->len - ETH_ALEN,
765 ETH_ALEN);
766 skb_trim(skb, skb->len - ETH_ALEN);
767 }
768#endif
769
770 dev->stats.rx_packets++;
771 dev->stats.rx_bytes += skb->len;
772
773#ifdef NOT_YET
774 if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
775 if (dst[0] & 0x01) {
776
777
778 ieee->ap->bridged_multicast++;
779 skb2 = skb_clone(skb, GFP_ATOMIC);
780 if (skb2 == NULL)
781 printk(KERN_DEBUG "%s: skb_clone failed for "
782 "multicast frame\n", dev->name);
783 } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
784
785
786 ieee->ap->bridged_unicast++;
787 skb2 = skb;
788 skb = NULL;
789 }
790 }
791
792 if (skb2 != NULL) {
793
794 skb2->dev = dev;
795 skb2->protocol = htons(ETH_P_802_3);
796 skb_reset_mac_header(skb2);
797 skb_reset_network_header(skb2);
798
799 dev_queue_xmit(skb2);
800 }
801#endif
802
803 if (skb) {
804 skb->protocol = eth_type_trans(skb, dev);
805 memset(skb->cb, 0, sizeof(skb->cb));
806 skb->ip_summed = CHECKSUM_NONE;
807 if (netif_rx(skb) == NET_RX_DROP) {
808
809
810
811 LIBIPW_DEBUG_DROP
812 ("RX: netif_rx dropped the packet\n");
813 dev->stats.rx_dropped++;
814 }
815 }
816
817 rx_exit:
818#ifdef NOT_YET
819 if (sta)
820 hostap_handle_sta_release(sta);
821#endif
822 return 1;
823
824 rx_dropped:
825 dev->stats.rx_dropped++;
826
827
828
829
830 return 0;
831}
832
833
834
835
836void libipw_rx_any(struct libipw_device *ieee,
837 struct sk_buff *skb, struct libipw_rx_stats *stats)
838{
839 struct libipw_hdr_4addr *hdr;
840 int is_packet_for_us;
841 u16 fc;
842
843 if (ieee->iw_mode == IW_MODE_MONITOR) {
844 if (!libipw_rx(ieee, skb, stats))
845 dev_kfree_skb_irq(skb);
846 return;
847 }
848
849 if (skb->len < sizeof(struct ieee80211_hdr))
850 goto drop_free;
851
852 hdr = (struct libipw_hdr_4addr *)skb->data;
853 fc = le16_to_cpu(hdr->frame_ctl);
854
855 if ((fc & IEEE80211_FCTL_VERS) != 0)
856 goto drop_free;
857
858 switch (fc & IEEE80211_FCTL_FTYPE) {
859 case IEEE80211_FTYPE_MGMT:
860 if (skb->len < sizeof(struct libipw_hdr_3addr))
861 goto drop_free;
862 libipw_rx_mgt(ieee, hdr, stats);
863 dev_kfree_skb_irq(skb);
864 return;
865 case IEEE80211_FTYPE_DATA:
866 break;
867 case IEEE80211_FTYPE_CTL:
868 return;
869 default:
870 return;
871 }
872
873 is_packet_for_us = 0;
874 switch (ieee->iw_mode) {
875 case IW_MODE_ADHOC:
876
877 if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0)
878 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
879
880 if (ieee->dev->flags & IFF_PROMISC)
881 is_packet_for_us = 1;
882
883 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
884 is_packet_for_us = 1;
885
886 else if (is_multicast_ether_addr(hdr->addr1))
887 is_packet_for_us = 1;
888 }
889 break;
890 case IW_MODE_INFRA:
891
892 if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0)
893 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
894
895 if (ieee->dev->flags & IFF_PROMISC)
896 is_packet_for_us = 1;
897
898 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
899 is_packet_for_us = 1;
900
901 else if (is_multicast_ether_addr(hdr->addr1)) {
902
903 if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN))
904 is_packet_for_us = 1;
905 }
906 }
907 break;
908 default:
909
910 break;
911 }
912
913 if (is_packet_for_us)
914 if (!libipw_rx(ieee, skb, stats))
915 dev_kfree_skb_irq(skb);
916 return;
917
918drop_free:
919 dev_kfree_skb_irq(skb);
920 ieee->dev->stats.rx_dropped++;
921 return;
922}
923
924#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
925
926static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
927
928
929
930
931
932static int libipw_verify_qos_info(struct libipw_qos_information_element
933 *info_element, int sub_type)
934{
935
936 if (info_element->qui_subtype != sub_type)
937 return -1;
938 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
939 return -1;
940 if (info_element->qui_type != QOS_OUI_TYPE)
941 return -1;
942 if (info_element->version != QOS_VERSION_1)
943 return -1;
944
945 return 0;
946}
947
948
949
950
951static int libipw_read_qos_param_element(struct libipw_qos_parameter_info
952 *element_param, struct libipw_info_element
953 *info_element)
954{
955 int ret = 0;
956 u16 size = sizeof(struct libipw_qos_parameter_info) - 2;
957
958 if ((info_element == NULL) || (element_param == NULL))
959 return -1;
960
961 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
962 memcpy(element_param->info_element.qui, info_element->data,
963 info_element->len);
964 element_param->info_element.elementID = info_element->id;
965 element_param->info_element.length = info_element->len;
966 } else
967 ret = -1;
968 if (ret == 0)
969 ret = libipw_verify_qos_info(&element_param->info_element,
970 QOS_OUI_PARAM_SUB_TYPE);
971 return ret;
972}
973
974
975
976
977static int libipw_read_qos_info_element(struct
978 libipw_qos_information_element
979 *element_info, struct libipw_info_element
980 *info_element)
981{
982 int ret = 0;
983 u16 size = sizeof(struct libipw_qos_information_element) - 2;
984
985 if (element_info == NULL)
986 return -1;
987 if (info_element == NULL)
988 return -1;
989
990 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
991 memcpy(element_info->qui, info_element->data,
992 info_element->len);
993 element_info->elementID = info_element->id;
994 element_info->length = info_element->len;
995 } else
996 ret = -1;
997
998 if (ret == 0)
999 ret = libipw_verify_qos_info(element_info,
1000 QOS_OUI_INFO_SUB_TYPE);
1001 return ret;
1002}
1003
1004
1005
1006
1007static int libipw_qos_convert_ac_to_parameters(struct
1008 libipw_qos_parameter_info
1009 *param_elm, struct
1010 libipw_qos_parameters
1011 *qos_param)
1012{
1013 int rc = 0;
1014 int i;
1015 struct libipw_qos_ac_parameter *ac_params;
1016 u32 txop;
1017 u8 cw_min;
1018 u8 cw_max;
1019
1020 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1021 ac_params = &(param_elm->ac_params_record[i]);
1022
1023 qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
1024 qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
1025
1026 cw_min = ac_params->ecw_min_max & 0x0F;
1027 qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
1028
1029 cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
1030 qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
1031
1032 qos_param->flag[i] =
1033 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1034
1035 txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
1036 qos_param->tx_op_limit[i] = cpu_to_le16(txop);
1037 }
1038 return rc;
1039}
1040
1041
1042
1043
1044
1045
1046static int libipw_parse_qos_info_param_IE(struct libipw_info_element
1047 *info_element,
1048 struct libipw_network *network)
1049{
1050 int rc = 0;
1051 struct libipw_qos_parameters *qos_param = NULL;
1052 struct libipw_qos_information_element qos_info_element;
1053
1054 rc = libipw_read_qos_info_element(&qos_info_element, info_element);
1055
1056 if (rc == 0) {
1057 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1058 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1059 } else {
1060 struct libipw_qos_parameter_info param_element;
1061
1062 rc = libipw_read_qos_param_element(¶m_element,
1063 info_element);
1064 if (rc == 0) {
1065 qos_param = &(network->qos_data.parameters);
1066 libipw_qos_convert_ac_to_parameters(¶m_element,
1067 qos_param);
1068 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1069 network->qos_data.param_count =
1070 param_element.info_element.ac_info & 0x0F;
1071 }
1072 }
1073
1074 if (rc == 0) {
1075 LIBIPW_DEBUG_QOS("QoS is supported\n");
1076 network->qos_data.supported = 1;
1077 }
1078 return rc;
1079}
1080
1081#ifdef CONFIG_LIBIPW_DEBUG
1082#define MFIE_STRING(x) case WLAN_EID_ ##x: return #x
1083
1084static const char *get_info_element_string(u16 id)
1085{
1086 switch (id) {
1087 MFIE_STRING(SSID);
1088 MFIE_STRING(SUPP_RATES);
1089 MFIE_STRING(FH_PARAMS);
1090 MFIE_STRING(DS_PARAMS);
1091 MFIE_STRING(CF_PARAMS);
1092 MFIE_STRING(TIM);
1093 MFIE_STRING(IBSS_PARAMS);
1094 MFIE_STRING(COUNTRY);
1095 MFIE_STRING(HP_PARAMS);
1096 MFIE_STRING(HP_TABLE);
1097 MFIE_STRING(REQUEST);
1098 MFIE_STRING(CHALLENGE);
1099 MFIE_STRING(PWR_CONSTRAINT);
1100 MFIE_STRING(PWR_CAPABILITY);
1101 MFIE_STRING(TPC_REQUEST);
1102 MFIE_STRING(TPC_REPORT);
1103 MFIE_STRING(SUPPORTED_CHANNELS);
1104 MFIE_STRING(CHANNEL_SWITCH);
1105 MFIE_STRING(MEASURE_REQUEST);
1106 MFIE_STRING(MEASURE_REPORT);
1107 MFIE_STRING(QUIET);
1108 MFIE_STRING(IBSS_DFS);
1109 MFIE_STRING(ERP_INFO);
1110 MFIE_STRING(RSN);
1111 MFIE_STRING(EXT_SUPP_RATES);
1112 MFIE_STRING(GENERIC);
1113 MFIE_STRING(QOS_PARAMETER);
1114 default:
1115 return "UNKNOWN";
1116 }
1117}
1118#endif
1119
1120static int libipw_parse_info_param(struct libipw_info_element
1121 *info_element, u16 length,
1122 struct libipw_network *network)
1123{
1124 DECLARE_SSID_BUF(ssid);
1125 u8 i;
1126#ifdef CONFIG_LIBIPW_DEBUG
1127 char rates_str[64];
1128 char *p;
1129#endif
1130
1131 while (length >= sizeof(*info_element)) {
1132 if (sizeof(*info_element) + info_element->len > length) {
1133 LIBIPW_DEBUG_MGMT("Info elem: parse failed: "
1134 "info_element->len + 2 > left : "
1135 "info_element->len+2=%zd left=%d, id=%d.\n",
1136 info_element->len +
1137 sizeof(*info_element),
1138 length, info_element->id);
1139
1140
1141
1142 break;
1143 }
1144
1145 switch (info_element->id) {
1146 case WLAN_EID_SSID:
1147 network->ssid_len = min(info_element->len,
1148 (u8) IW_ESSID_MAX_SIZE);
1149 memcpy(network->ssid, info_element->data,
1150 network->ssid_len);
1151 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1152 memset(network->ssid + network->ssid_len, 0,
1153 IW_ESSID_MAX_SIZE - network->ssid_len);
1154
1155 LIBIPW_DEBUG_MGMT("WLAN_EID_SSID: '%s' len=%d.\n",
1156 print_ssid(ssid, network->ssid,
1157 network->ssid_len),
1158 network->ssid_len);
1159 break;
1160
1161 case WLAN_EID_SUPP_RATES:
1162#ifdef CONFIG_LIBIPW_DEBUG
1163 p = rates_str;
1164#endif
1165 network->rates_len = min(info_element->len,
1166 MAX_RATES_LENGTH);
1167 for (i = 0; i < network->rates_len; i++) {
1168 network->rates[i] = info_element->data[i];
1169#ifdef CONFIG_LIBIPW_DEBUG
1170 p += snprintf(p, sizeof(rates_str) -
1171 (p - rates_str), "%02X ",
1172 network->rates[i]);
1173#endif
1174 if (libipw_is_ofdm_rate
1175 (info_element->data[i])) {
1176 network->flags |= NETWORK_HAS_OFDM;
1177 if (info_element->data[i] &
1178 LIBIPW_BASIC_RATE_MASK)
1179 network->flags &=
1180 ~NETWORK_HAS_CCK;
1181 }
1182 }
1183
1184 LIBIPW_DEBUG_MGMT("WLAN_EID_SUPP_RATES: '%s' (%d)\n",
1185 rates_str, network->rates_len);
1186 break;
1187
1188 case WLAN_EID_EXT_SUPP_RATES:
1189#ifdef CONFIG_LIBIPW_DEBUG
1190 p = rates_str;
1191#endif
1192 network->rates_ex_len = min(info_element->len,
1193 MAX_RATES_EX_LENGTH);
1194 for (i = 0; i < network->rates_ex_len; i++) {
1195 network->rates_ex[i] = info_element->data[i];
1196#ifdef CONFIG_LIBIPW_DEBUG
1197 p += snprintf(p, sizeof(rates_str) -
1198 (p - rates_str), "%02X ",
1199 network->rates[i]);
1200#endif
1201 if (libipw_is_ofdm_rate
1202 (info_element->data[i])) {
1203 network->flags |= NETWORK_HAS_OFDM;
1204 if (info_element->data[i] &
1205 LIBIPW_BASIC_RATE_MASK)
1206 network->flags &=
1207 ~NETWORK_HAS_CCK;
1208 }
1209 }
1210
1211 LIBIPW_DEBUG_MGMT("WLAN_EID_EXT_SUPP_RATES: '%s' (%d)\n",
1212 rates_str, network->rates_ex_len);
1213 break;
1214
1215 case WLAN_EID_DS_PARAMS:
1216 LIBIPW_DEBUG_MGMT("WLAN_EID_DS_PARAMS: %d\n",
1217 info_element->data[0]);
1218 network->channel = info_element->data[0];
1219 break;
1220
1221 case WLAN_EID_FH_PARAMS:
1222 LIBIPW_DEBUG_MGMT("WLAN_EID_FH_PARAMS: ignored\n");
1223 break;
1224
1225 case WLAN_EID_CF_PARAMS:
1226 LIBIPW_DEBUG_MGMT("WLAN_EID_CF_PARAMS: ignored\n");
1227 break;
1228
1229 case WLAN_EID_TIM:
1230 network->tim.tim_count = info_element->data[0];
1231 network->tim.tim_period = info_element->data[1];
1232 LIBIPW_DEBUG_MGMT("WLAN_EID_TIM: partially ignored\n");
1233 break;
1234
1235 case WLAN_EID_ERP_INFO:
1236 network->erp_value = info_element->data[0];
1237 network->flags |= NETWORK_HAS_ERP_VALUE;
1238 LIBIPW_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1239 network->erp_value);
1240 break;
1241
1242 case WLAN_EID_IBSS_PARAMS:
1243 network->atim_window = info_element->data[0];
1244 LIBIPW_DEBUG_MGMT("WLAN_EID_IBSS_PARAMS: %d\n",
1245 network->atim_window);
1246 break;
1247
1248 case WLAN_EID_CHALLENGE:
1249 LIBIPW_DEBUG_MGMT("WLAN_EID_CHALLENGE: ignored\n");
1250 break;
1251
1252 case WLAN_EID_GENERIC:
1253 LIBIPW_DEBUG_MGMT("WLAN_EID_GENERIC: %d bytes\n",
1254 info_element->len);
1255 if (!libipw_parse_qos_info_param_IE(info_element,
1256 network))
1257 break;
1258
1259 if (info_element->len >= 4 &&
1260 info_element->data[0] == 0x00 &&
1261 info_element->data[1] == 0x50 &&
1262 info_element->data[2] == 0xf2 &&
1263 info_element->data[3] == 0x01) {
1264 network->wpa_ie_len = min(info_element->len + 2,
1265 MAX_WPA_IE_LEN);
1266 memcpy(network->wpa_ie, info_element,
1267 network->wpa_ie_len);
1268 }
1269 break;
1270
1271 case WLAN_EID_RSN:
1272 LIBIPW_DEBUG_MGMT("WLAN_EID_RSN: %d bytes\n",
1273 info_element->len);
1274 network->rsn_ie_len = min(info_element->len + 2,
1275 MAX_WPA_IE_LEN);
1276 memcpy(network->rsn_ie, info_element,
1277 network->rsn_ie_len);
1278 break;
1279
1280 case WLAN_EID_QOS_PARAMETER:
1281 printk(KERN_ERR
1282 "QoS Error need to parse QOS_PARAMETER IE\n");
1283 break;
1284
1285 case WLAN_EID_PWR_CONSTRAINT:
1286 network->power_constraint = info_element->data[0];
1287 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
1288 break;
1289
1290 case WLAN_EID_CHANNEL_SWITCH:
1291 network->power_constraint = info_element->data[0];
1292 network->flags |= NETWORK_HAS_CSA;
1293 break;
1294
1295 case WLAN_EID_QUIET:
1296 network->quiet.count = info_element->data[0];
1297 network->quiet.period = info_element->data[1];
1298 network->quiet.duration = info_element->data[2];
1299 network->quiet.offset = info_element->data[3];
1300 network->flags |= NETWORK_HAS_QUIET;
1301 break;
1302
1303 case WLAN_EID_IBSS_DFS:
1304 if (network->ibss_dfs)
1305 break;
1306 network->ibss_dfs = kmemdup(info_element->data,
1307 info_element->len,
1308 GFP_ATOMIC);
1309 if (!network->ibss_dfs)
1310 return 1;
1311 network->flags |= NETWORK_HAS_IBSS_DFS;
1312 break;
1313
1314 case WLAN_EID_TPC_REPORT:
1315 network->tpc_report.transmit_power =
1316 info_element->data[0];
1317 network->tpc_report.link_margin = info_element->data[1];
1318 network->flags |= NETWORK_HAS_TPC_REPORT;
1319 break;
1320
1321 default:
1322 LIBIPW_DEBUG_MGMT
1323 ("Unsupported info element: %s (%d)\n",
1324 get_info_element_string(info_element->id),
1325 info_element->id);
1326 break;
1327 }
1328
1329 length -= sizeof(*info_element) + info_element->len;
1330 info_element =
1331 (struct libipw_info_element *)&info_element->
1332 data[info_element->len];
1333 }
1334
1335 return 0;
1336}
1337
1338static int libipw_handle_assoc_resp(struct libipw_device *ieee, struct libipw_assoc_response
1339 *frame, struct libipw_rx_stats *stats)
1340{
1341 struct libipw_network network_resp = {
1342 .ibss_dfs = NULL,
1343 };
1344 struct libipw_network *network = &network_resp;
1345 struct net_device *dev = ieee->dev;
1346
1347 network->flags = 0;
1348 network->qos_data.active = 0;
1349 network->qos_data.supported = 0;
1350 network->qos_data.param_count = 0;
1351 network->qos_data.old_param_count = 0;
1352
1353
1354 network->atim_window = le16_to_cpu(frame->aid);
1355 network->listen_interval = le16_to_cpu(frame->status);
1356 memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
1357 network->capability = le16_to_cpu(frame->capability);
1358 network->last_scanned = jiffies;
1359 network->rates_len = network->rates_ex_len = 0;
1360 network->last_associate = 0;
1361 network->ssid_len = 0;
1362 network->erp_value =
1363 (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
1364
1365 if (stats->freq == LIBIPW_52GHZ_BAND) {
1366
1367 network->channel = stats->received_channel;
1368 } else
1369 network->flags |= NETWORK_HAS_CCK;
1370
1371 network->wpa_ie_len = 0;
1372 network->rsn_ie_len = 0;
1373
1374 if (libipw_parse_info_param
1375 (frame->info_element, stats->len - sizeof(*frame), network))
1376 return 1;
1377
1378 network->mode = 0;
1379 if (stats->freq == LIBIPW_52GHZ_BAND)
1380 network->mode = IEEE_A;
1381 else {
1382 if (network->flags & NETWORK_HAS_OFDM)
1383 network->mode |= IEEE_G;
1384 if (network->flags & NETWORK_HAS_CCK)
1385 network->mode |= IEEE_B;
1386 }
1387
1388 memcpy(&network->stats, stats, sizeof(network->stats));
1389
1390 if (ieee->handle_assoc_response != NULL)
1391 ieee->handle_assoc_response(dev, frame, network);
1392
1393 return 0;
1394}
1395
1396
1397
1398static int libipw_network_init(struct libipw_device *ieee, struct libipw_probe_response
1399 *beacon,
1400 struct libipw_network *network,
1401 struct libipw_rx_stats *stats)
1402{
1403 DECLARE_SSID_BUF(ssid);
1404
1405 network->qos_data.active = 0;
1406 network->qos_data.supported = 0;
1407 network->qos_data.param_count = 0;
1408 network->qos_data.old_param_count = 0;
1409
1410
1411 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
1412 network->capability = le16_to_cpu(beacon->capability);
1413 network->last_scanned = jiffies;
1414 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
1415 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
1416 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
1417
1418 network->listen_interval = 0x0A;
1419 network->rates_len = network->rates_ex_len = 0;
1420 network->last_associate = 0;
1421 network->ssid_len = 0;
1422 network->flags = 0;
1423 network->atim_window = 0;
1424 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
1425 0x3 : 0x0;
1426
1427 if (stats->freq == LIBIPW_52GHZ_BAND) {
1428
1429 network->channel = stats->received_channel;
1430 } else
1431 network->flags |= NETWORK_HAS_CCK;
1432
1433 network->wpa_ie_len = 0;
1434 network->rsn_ie_len = 0;
1435
1436 if (libipw_parse_info_param
1437 (beacon->info_element, stats->len - sizeof(*beacon), network))
1438 return 1;
1439
1440 network->mode = 0;
1441 if (stats->freq == LIBIPW_52GHZ_BAND)
1442 network->mode = IEEE_A;
1443 else {
1444 if (network->flags & NETWORK_HAS_OFDM)
1445 network->mode |= IEEE_G;
1446 if (network->flags & NETWORK_HAS_CCK)
1447 network->mode |= IEEE_B;
1448 }
1449
1450 if (network->mode == 0) {
1451 LIBIPW_DEBUG_SCAN("Filtered out '%s (%pM)' "
1452 "network.\n",
1453 print_ssid(ssid, network->ssid,
1454 network->ssid_len),
1455 network->bssid);
1456 return 1;
1457 }
1458
1459 memcpy(&network->stats, stats, sizeof(network->stats));
1460
1461 return 0;
1462}
1463
1464static inline int is_same_network(struct libipw_network *src,
1465 struct libipw_network *dst)
1466{
1467
1468
1469
1470 return ((src->ssid_len == dst->ssid_len) &&
1471 (src->channel == dst->channel) &&
1472 !compare_ether_addr(src->bssid, dst->bssid) &&
1473 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1474}
1475
1476static void update_network(struct libipw_network *dst,
1477 struct libipw_network *src)
1478{
1479 int qos_active;
1480 u8 old_param;
1481
1482 libipw_network_reset(dst);
1483 dst->ibss_dfs = src->ibss_dfs;
1484
1485
1486
1487
1488
1489
1490 if (dst->channel == src->stats.received_channel)
1491 memcpy(&dst->stats, &src->stats,
1492 sizeof(struct libipw_rx_stats));
1493 else
1494 LIBIPW_DEBUG_SCAN("Network %pM info received "
1495 "off channel (%d vs. %d)\n", src->bssid,
1496 dst->channel, src->stats.received_channel);
1497
1498 dst->capability = src->capability;
1499 memcpy(dst->rates, src->rates, src->rates_len);
1500 dst->rates_len = src->rates_len;
1501 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1502 dst->rates_ex_len = src->rates_ex_len;
1503
1504 dst->mode = src->mode;
1505 dst->flags = src->flags;
1506 dst->time_stamp[0] = src->time_stamp[0];
1507 dst->time_stamp[1] = src->time_stamp[1];
1508
1509 dst->beacon_interval = src->beacon_interval;
1510 dst->listen_interval = src->listen_interval;
1511 dst->atim_window = src->atim_window;
1512 dst->erp_value = src->erp_value;
1513 dst->tim = src->tim;
1514
1515 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1516 dst->wpa_ie_len = src->wpa_ie_len;
1517 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1518 dst->rsn_ie_len = src->rsn_ie_len;
1519
1520 dst->last_scanned = jiffies;
1521 qos_active = src->qos_data.active;
1522 old_param = dst->qos_data.old_param_count;
1523 if (dst->flags & NETWORK_HAS_QOS_MASK)
1524 memcpy(&dst->qos_data, &src->qos_data,
1525 sizeof(struct libipw_qos_data));
1526 else {
1527 dst->qos_data.supported = src->qos_data.supported;
1528 dst->qos_data.param_count = src->qos_data.param_count;
1529 }
1530
1531 if (dst->qos_data.supported == 1) {
1532 if (dst->ssid_len)
1533 LIBIPW_DEBUG_QOS
1534 ("QoS the network %s is QoS supported\n",
1535 dst->ssid);
1536 else
1537 LIBIPW_DEBUG_QOS
1538 ("QoS the network is QoS supported\n");
1539 }
1540 dst->qos_data.active = qos_active;
1541 dst->qos_data.old_param_count = old_param;
1542
1543
1544}
1545
1546static inline int is_beacon(__le16 fc)
1547{
1548 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
1549}
1550
1551static void libipw_process_probe_response(struct libipw_device
1552 *ieee, struct
1553 libipw_probe_response
1554 *beacon, struct libipw_rx_stats
1555 *stats)
1556{
1557 struct net_device *dev = ieee->dev;
1558 struct libipw_network network = {
1559 .ibss_dfs = NULL,
1560 };
1561 struct libipw_network *target;
1562 struct libipw_network *oldest = NULL;
1563#ifdef CONFIG_LIBIPW_DEBUG
1564 struct libipw_info_element *info_element = beacon->info_element;
1565#endif
1566 unsigned long flags;
1567 DECLARE_SSID_BUF(ssid);
1568
1569 LIBIPW_DEBUG_SCAN("'%s' (%pM"
1570 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1571 print_ssid(ssid, info_element->data, info_element->len),
1572 beacon->header.addr3,
1573 (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
1574 (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
1575 (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
1576 (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
1577 (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
1578 (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
1579 (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
1580 (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
1581 (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
1582 (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
1583 (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
1584 (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
1585 (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
1586 (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
1587 (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
1588 (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
1589
1590 if (libipw_network_init(ieee, beacon, &network, stats)) {
1591 LIBIPW_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
1592 print_ssid(ssid, info_element->data,
1593 info_element->len),
1594 beacon->header.addr3,
1595 is_beacon(beacon->header.frame_ctl) ?
1596 "BEACON" : "PROBE RESPONSE");
1597 return;
1598 }
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610 spin_lock_irqsave(&ieee->lock, flags);
1611
1612 list_for_each_entry(target, &ieee->network_list, list) {
1613 if (is_same_network(target, &network))
1614 break;
1615
1616 if ((oldest == NULL) ||
1617 time_before(target->last_scanned, oldest->last_scanned))
1618 oldest = target;
1619 }
1620
1621
1622
1623 if (&target->list == &ieee->network_list) {
1624 if (list_empty(&ieee->network_free_list)) {
1625
1626 list_del(&oldest->list);
1627 target = oldest;
1628 LIBIPW_DEBUG_SCAN("Expired '%s' (%pM) from "
1629 "network list.\n",
1630 print_ssid(ssid, target->ssid,
1631 target->ssid_len),
1632 target->bssid);
1633 libipw_network_reset(target);
1634 } else {
1635
1636 target = list_entry(ieee->network_free_list.next,
1637 struct libipw_network, list);
1638 list_del(ieee->network_free_list.next);
1639 }
1640
1641#ifdef CONFIG_LIBIPW_DEBUG
1642 LIBIPW_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
1643 print_ssid(ssid, network.ssid,
1644 network.ssid_len),
1645 network.bssid,
1646 is_beacon(beacon->header.frame_ctl) ?
1647 "BEACON" : "PROBE RESPONSE");
1648#endif
1649 memcpy(target, &network, sizeof(*target));
1650 network.ibss_dfs = NULL;
1651 list_add_tail(&target->list, &ieee->network_list);
1652 } else {
1653 LIBIPW_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
1654 print_ssid(ssid, target->ssid,
1655 target->ssid_len),
1656 target->bssid,
1657 is_beacon(beacon->header.frame_ctl) ?
1658 "BEACON" : "PROBE RESPONSE");
1659 update_network(target, &network);
1660 network.ibss_dfs = NULL;
1661 }
1662
1663 spin_unlock_irqrestore(&ieee->lock, flags);
1664
1665 if (is_beacon(beacon->header.frame_ctl)) {
1666 if (ieee->handle_beacon != NULL)
1667 ieee->handle_beacon(dev, beacon, target);
1668 } else {
1669 if (ieee->handle_probe_response != NULL)
1670 ieee->handle_probe_response(dev, beacon, target);
1671 }
1672}
1673
1674void libipw_rx_mgt(struct libipw_device *ieee,
1675 struct libipw_hdr_4addr *header,
1676 struct libipw_rx_stats *stats)
1677{
1678 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
1679 case IEEE80211_STYPE_ASSOC_RESP:
1680 LIBIPW_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
1681 WLAN_FC_GET_STYPE(le16_to_cpu
1682 (header->frame_ctl)));
1683 libipw_handle_assoc_resp(ieee,
1684 (struct libipw_assoc_response *)
1685 header, stats);
1686 break;
1687
1688 case IEEE80211_STYPE_REASSOC_RESP:
1689 LIBIPW_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
1690 WLAN_FC_GET_STYPE(le16_to_cpu
1691 (header->frame_ctl)));
1692 break;
1693
1694 case IEEE80211_STYPE_PROBE_REQ:
1695 LIBIPW_DEBUG_MGMT("received auth (%d)\n",
1696 WLAN_FC_GET_STYPE(le16_to_cpu
1697 (header->frame_ctl)));
1698
1699 if (ieee->handle_probe_request != NULL)
1700 ieee->handle_probe_request(ieee->dev,
1701 (struct
1702 libipw_probe_request *)
1703 header, stats);
1704 break;
1705
1706 case IEEE80211_STYPE_PROBE_RESP:
1707 LIBIPW_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1708 WLAN_FC_GET_STYPE(le16_to_cpu
1709 (header->frame_ctl)));
1710 LIBIPW_DEBUG_SCAN("Probe response\n");
1711 libipw_process_probe_response(ieee,
1712 (struct
1713 libipw_probe_response *)
1714 header, stats);
1715 break;
1716
1717 case IEEE80211_STYPE_BEACON:
1718 LIBIPW_DEBUG_MGMT("received BEACON (%d)\n",
1719 WLAN_FC_GET_STYPE(le16_to_cpu
1720 (header->frame_ctl)));
1721 LIBIPW_DEBUG_SCAN("Beacon\n");
1722 libipw_process_probe_response(ieee,
1723 (struct
1724 libipw_probe_response *)
1725 header, stats);
1726 break;
1727 case IEEE80211_STYPE_AUTH:
1728
1729 LIBIPW_DEBUG_MGMT("received auth (%d)\n",
1730 WLAN_FC_GET_STYPE(le16_to_cpu
1731 (header->frame_ctl)));
1732
1733 if (ieee->handle_auth != NULL)
1734 ieee->handle_auth(ieee->dev,
1735 (struct libipw_auth *)header);
1736 break;
1737
1738 case IEEE80211_STYPE_DISASSOC:
1739 if (ieee->handle_disassoc != NULL)
1740 ieee->handle_disassoc(ieee->dev,
1741 (struct libipw_disassoc *)
1742 header);
1743 break;
1744
1745 case IEEE80211_STYPE_ACTION:
1746 LIBIPW_DEBUG_MGMT("ACTION\n");
1747 if (ieee->handle_action)
1748 ieee->handle_action(ieee->dev,
1749 (struct libipw_action *)
1750 header, stats);
1751 break;
1752
1753 case IEEE80211_STYPE_REASSOC_REQ:
1754 LIBIPW_DEBUG_MGMT("received reassoc (%d)\n",
1755 WLAN_FC_GET_STYPE(le16_to_cpu
1756 (header->frame_ctl)));
1757
1758 LIBIPW_DEBUG_MGMT("%s: LIBIPW_REASSOC_REQ received\n",
1759 ieee->dev->name);
1760 if (ieee->handle_reassoc_request != NULL)
1761 ieee->handle_reassoc_request(ieee->dev,
1762 (struct libipw_reassoc_request *)
1763 header);
1764 break;
1765
1766 case IEEE80211_STYPE_ASSOC_REQ:
1767 LIBIPW_DEBUG_MGMT("received assoc (%d)\n",
1768 WLAN_FC_GET_STYPE(le16_to_cpu
1769 (header->frame_ctl)));
1770
1771 LIBIPW_DEBUG_MGMT("%s: LIBIPW_ASSOC_REQ received\n",
1772 ieee->dev->name);
1773 if (ieee->handle_assoc_request != NULL)
1774 ieee->handle_assoc_request(ieee->dev);
1775 break;
1776
1777 case IEEE80211_STYPE_DEAUTH:
1778 LIBIPW_DEBUG_MGMT("DEAUTH\n");
1779 if (ieee->handle_deauth != NULL)
1780 ieee->handle_deauth(ieee->dev,
1781 (struct libipw_deauth *)
1782 header);
1783 break;
1784 default:
1785 LIBIPW_DEBUG_MGMT("received UNKNOWN (%d)\n",
1786 WLAN_FC_GET_STYPE(le16_to_cpu
1787 (header->frame_ctl)));
1788 LIBIPW_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1789 ieee->dev->name,
1790 WLAN_FC_GET_STYPE(le16_to_cpu
1791 (header->frame_ctl)));
1792 break;
1793 }
1794}
1795
1796EXPORT_SYMBOL_GPL(libipw_rx_any);
1797EXPORT_SYMBOL(libipw_rx_mgt);
1798EXPORT_SYMBOL(libipw_rx);
1799