1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/compiler.h>
25
26#include <linux/errno.h>
27#include <linux/if_arp.h>
28#include <linux/in6.h>
29#include <linux/in.h>
30#include <linux/ip.h>
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/netdevice.h>
34#include <linux/pci.h>
35#include <linux/proc_fs.h>
36#include <linux/skbuff.h>
37#include <linux/slab.h>
38#include <linux/tcp.h>
39#include <linux/types.h>
40#include <linux/version.h>
41#include <linux/wireless.h>
42#include <linux/etherdevice.h>
43#include <asm/uaccess.h>
44#include <linux/ctype.h>
45
46#include "ieee80211.h"
47#ifdef ENABLE_DOT11D
48#include "dot11d.h"
49#endif
50static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
51 struct sk_buff *skb,
52 struct ieee80211_rx_stats *rx_stats)
53{
54 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *)skb->data;
55 u16 fc = le16_to_cpu(hdr->frame_ctl);
56
57 skb->dev = ieee->dev;
58 skb_reset_mac_header(skb);
59
60 skb_pull(skb, ieee80211_get_hdrlen(fc));
61 skb->pkt_type = PACKET_OTHERHOST;
62 skb->protocol = __constant_htons(ETH_P_80211_RAW);
63 memset(skb->cb, 0, sizeof(skb->cb));
64 netif_rx(skb);
65}
66
67
68
69static struct ieee80211_frag_entry *
70ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
71 unsigned int frag, u8 tid,u8 *src, u8 *dst)
72{
73 struct ieee80211_frag_entry *entry;
74 int i;
75
76 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
77 entry = &ieee->frag_cache[tid][i];
78 if (entry->skb != NULL &&
79 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
80 IEEE80211_DEBUG_FRAG(
81 "expiring fragment cache entry "
82 "seq=%u last_frag=%u\n",
83 entry->seq, entry->last_frag);
84 dev_kfree_skb_any(entry->skb);
85 entry->skb = NULL;
86 }
87
88 if (entry->skb != NULL && entry->seq == seq &&
89 (entry->last_frag + 1 == frag || frag == -1) &&
90 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
91 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
92 return entry;
93 }
94
95 return NULL;
96}
97
98
99static struct sk_buff *
100ieee80211_frag_cache_get(struct ieee80211_device *ieee,
101 struct ieee80211_hdr_4addr *hdr)
102{
103 struct sk_buff *skb = NULL;
104 u16 fc = le16_to_cpu(hdr->frame_ctl);
105 u16 sc = le16_to_cpu(hdr->seq_ctl);
106 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
107 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
108 struct ieee80211_frag_entry *entry;
109 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
110 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
111 u8 tid;
112
113 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
114 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
115 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
116 tid = UP2AC(tid);
117 tid ++;
118 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
119 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
120 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
121 tid = UP2AC(tid);
122 tid ++;
123 } else {
124 tid = 0;
125 }
126
127 if (frag == 0) {
128
129 skb = dev_alloc_skb(ieee->dev->mtu +
130 sizeof(struct ieee80211_hdr_4addr) +
131 8 +
132 2 +
133 8 +
134 ETH_ALEN +
135 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) );
136 if (skb == NULL)
137 return NULL;
138
139 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
140 ieee->frag_next_idx[tid]++;
141 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
142 ieee->frag_next_idx[tid] = 0;
143
144 if (entry->skb != NULL)
145 dev_kfree_skb_any(entry->skb);
146
147 entry->first_frag_time = jiffies;
148 entry->seq = seq;
149 entry->last_frag = frag;
150 entry->skb = skb;
151 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
152 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
153 } else {
154
155
156 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
157 hdr->addr1);
158 if (entry != NULL) {
159 entry->last_frag = frag;
160 skb = entry->skb;
161 }
162 }
163
164 return skb;
165}
166
167
168
169static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
170 struct ieee80211_hdr_4addr *hdr)
171{
172 u16 fc = le16_to_cpu(hdr->frame_ctl);
173 u16 sc = le16_to_cpu(hdr->seq_ctl);
174 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
175 struct ieee80211_frag_entry *entry;
176 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
177 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
178 u8 tid;
179
180 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
181 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
182 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
183 tid = UP2AC(tid);
184 tid ++;
185 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
186 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
187 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
188 tid = UP2AC(tid);
189 tid ++;
190 } else {
191 tid = 0;
192 }
193
194 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
195 hdr->addr1);
196
197 if (entry == NULL) {
198 IEEE80211_DEBUG_FRAG(
199 "could not invalidate fragment cache "
200 "entry (seq=%u)\n", seq);
201 return -1;
202 }
203
204 entry->skb = NULL;
205 return 0;
206}
207
208
209
210
211
212
213
214
215static inline int
216ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
217 struct ieee80211_rx_stats *rx_stats, u16 type,
218 u16 stype)
219{
220
221
222
223
224 struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data;
225
226 rx_stats->len = skb->len;
227 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
228
229 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))
230 {
231 dev_kfree_skb_any(skb);
232 return 0;
233 }
234
235 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
236
237 dev_kfree_skb_any(skb);
238
239 return 0;
240
241 #ifdef NOT_YET
242 if (ieee->iw_mode == IW_MODE_MASTER) {
243 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
244 ieee->dev->name);
245 return 0;
246
247
248
249 }
250
251 if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) {
252 if (stype == WLAN_FC_STYPE_BEACON &&
253 ieee->iw_mode == IW_MODE_MASTER) {
254 struct sk_buff *skb2;
255
256
257 skb2 = skb_clone(skb, GFP_ATOMIC);
258 if (skb2)
259 hostap_rx(skb2->dev, skb2, rx_stats);
260 }
261
262
263
264 ieee->apdevstats.rx_packets++;
265 ieee->apdevstats.rx_bytes += skb->len;
266 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
267 return 0;
268 }
269
270 if (ieee->iw_mode == IW_MODE_MASTER) {
271 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
272 printk(KERN_DEBUG "%s: unknown management frame "
273 "(type=0x%02x, stype=0x%02x) dropped\n",
274 skb->dev->name, type, stype);
275 return -1;
276 }
277
278 hostap_rx(skb->dev, skb, rx_stats);
279 return 0;
280 }
281
282 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
283 "received in non-Host AP mode\n", skb->dev->name);
284 return -1;
285 #endif
286}
287
288
289
290
291
292static unsigned char rfc1042_header[] =
293{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
294
295static unsigned char bridge_tunnel_header[] =
296{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
297
298
299
300static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
301 struct sk_buff *skb, size_t hdrlen)
302{
303 struct net_device *dev = ieee->dev;
304 u16 fc, ethertype;
305 struct ieee80211_hdr_4addr *hdr;
306 u8 *pos;
307
308 if (skb->len < 24)
309 return 0;
310
311#if 1
312 if (ieee->hwsec_active)
313 {
314 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
315 tcb_desc->bHwSec = 1;
316
317 if(ieee->need_sw_enc)
318 tcb_desc->bHwSec = 0;
319 }
320#endif
321
322 hdr = (struct ieee80211_hdr_4addr *) skb->data;
323 fc = le16_to_cpu(hdr->frame_ctl);
324
325
326 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
327 IEEE80211_FCTL_TODS &&
328 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
329 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
330
331 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
332 IEEE80211_FCTL_FROMDS &&
333 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
334
335 } else
336 return 0;
337
338 if (skb->len < 24 + 8)
339 return 0;
340
341
342
343 pos = skb->data + hdrlen;
344 ethertype = (pos[6] << 8) | pos[7];
345 if (ethertype == ETH_P_PAE)
346 return 1;
347
348 return 0;
349}
350
351
352static inline int
353ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
354 struct ieee80211_crypt_data *crypt)
355{
356 struct ieee80211_hdr_4addr *hdr;
357 int res, hdrlen;
358
359 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
360 return 0;
361#if 1
362 if (ieee->hwsec_active)
363 {
364 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
365 tcb_desc->bHwSec = 1;
366 }
367#endif
368 hdr = (struct ieee80211_hdr_4addr *) skb->data;
369 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
370
371#ifdef CONFIG_IEEE80211_CRYPT_TKIP
372 if (ieee->tkip_countermeasures &&
373 strcmp(crypt->ops->name, "TKIP") == 0) {
374 if (net_ratelimit()) {
375 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
376 "received packet from %pM\n",
377 ieee->dev->name, hdr->addr2);
378 }
379 return -1;
380 }
381#endif
382
383 atomic_inc(&crypt->refcnt);
384 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
385 atomic_dec(&crypt->refcnt);
386 if (res < 0) {
387 IEEE80211_DEBUG_DROP(
388 "decryption failed (SA=%pM"
389 ") res=%d\n", hdr->addr2, res);
390 if (res == -2)
391 IEEE80211_DEBUG_DROP("Decryption failed ICV "
392 "mismatch (key %d)\n",
393 skb->data[hdrlen + 3] >> 6);
394 ieee->ieee_stats.rx_discards_undecryptable++;
395 return -1;
396 }
397
398 return res;
399}
400
401
402
403static inline int
404ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
405 int keyidx, struct ieee80211_crypt_data *crypt)
406{
407 struct ieee80211_hdr_4addr *hdr;
408 int res, hdrlen;
409
410 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
411 return 0;
412 if (ieee->hwsec_active)
413 {
414 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
415 tcb_desc->bHwSec = 1;
416
417 if(ieee->need_sw_enc)
418 tcb_desc->bHwSec = 0;
419
420 }
421
422 hdr = (struct ieee80211_hdr_4addr *) skb->data;
423 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
424
425 atomic_inc(&crypt->refcnt);
426 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
427 atomic_dec(&crypt->refcnt);
428 if (res < 0) {
429 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
430 " (SA=%pM keyidx=%d)\n",
431 ieee->dev->name, hdr->addr2, keyidx);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439
440#define IEEE_PACKET_RETRY_TIME (5*HZ)
441static int is_duplicate_packet(struct ieee80211_device *ieee,
442 struct ieee80211_hdr_4addr *header)
443{
444 u16 fc = le16_to_cpu(header->frame_ctl);
445 u16 sc = le16_to_cpu(header->seq_ctl);
446 u16 seq = WLAN_GET_SEQ_SEQ(sc);
447 u16 frag = WLAN_GET_SEQ_FRAG(sc);
448 u16 *last_seq, *last_frag;
449 unsigned long *last_time;
450 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
451 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
452 u8 tid;
453
454
455
456 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
457 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
458 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
459 tid = UP2AC(tid);
460 tid ++;
461 } else if(IEEE80211_QOS_HAS_SEQ(fc)) {
462 hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
463 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
464 tid = UP2AC(tid);
465 tid ++;
466 } else {
467 tid = 0;
468 }
469
470 switch (ieee->iw_mode) {
471 case IW_MODE_ADHOC:
472 {
473 struct list_head *p;
474 struct ieee_ibss_seq *entry = NULL;
475 u8 *mac = header->addr2;
476 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
477
478
479 list_for_each(p, &ieee->ibss_mac_hash[index]) {
480 entry = list_entry(p, struct ieee_ibss_seq, list);
481 if (!memcmp(entry->mac, mac, ETH_ALEN))
482 break;
483 }
484
485 if (p == &ieee->ibss_mac_hash[index]) {
486 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
487 if (!entry) {
488 printk(KERN_WARNING "Cannot malloc new mac entry\n");
489 return 0;
490 }
491 memcpy(entry->mac, mac, ETH_ALEN);
492 entry->seq_num[tid] = seq;
493 entry->frag_num[tid] = frag;
494 entry->packet_time[tid] = jiffies;
495 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
496 return 0;
497 }
498 last_seq = &entry->seq_num[tid];
499 last_frag = &entry->frag_num[tid];
500 last_time = &entry->packet_time[tid];
501 break;
502 }
503
504 case IW_MODE_INFRA:
505 last_seq = &ieee->last_rxseq_num[tid];
506 last_frag = &ieee->last_rxfrag_num[tid];
507 last_time = &ieee->last_packet_time[tid];
508
509 break;
510 default:
511 return 0;
512 }
513
514
515
516
517 if ((*last_seq == seq) &&
518 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
519 if (*last_frag == frag){
520
521 goto drop;
522
523 }
524 if (*last_frag + 1 != frag)
525
526
527 goto drop;
528 } else
529 *last_seq = seq;
530
531 *last_frag = frag;
532 *last_time = jiffies;
533 return 0;
534
535drop:
536
537
538
539 return 1;
540}
541bool
542AddReorderEntry(
543 PRX_TS_RECORD pTS,
544 PRX_REORDER_ENTRY pReorderEntry
545 )
546{
547 struct list_head *pList = &pTS->RxPendingPktList;
548#if 1
549 while(pList->next != &pTS->RxPendingPktList)
550 {
551 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
552 {
553 pList = pList->next;
554 }
555 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
556 {
557 return false;
558 }
559 else
560 {
561 break;
562 }
563 }
564#endif
565 pReorderEntry->List.next = pList->next;
566 pReorderEntry->List.next->prev = &pReorderEntry->List;
567 pReorderEntry->List.prev = pList;
568 pList->next = &pReorderEntry->List;
569
570 return true;
571}
572
573void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index)
574{
575 u8 i = 0 , j=0;
576 u16 ethertype;
577
578
579 for(j = 0; j<index; j++)
580 {
581
582 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
583 for(i = 0; i<prxb->nr_subframes; i++) {
584 struct sk_buff *sub_skb = prxb->subframes[i];
585
586
587 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
588 if (sub_skb->len >= 8 &&
589 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
590 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
591 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
592
593
594 skb_pull(sub_skb, SNAP_SIZE);
595 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
596 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
597 } else {
598 u16 len;
599
600 len = htons(sub_skb->len);
601 memcpy(skb_push(sub_skb, 2), &len, 2);
602 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
603 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
604 }
605
606
607
608
609 if (sub_skb) {
610
611 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
612 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
613 sub_skb->dev = ieee->dev;
614 sub_skb->ip_summed = CHECKSUM_NONE;
615
616 ieee->last_rx_ps_time = jiffies;
617
618 netif_rx(sub_skb);
619 }
620 }
621 kfree(prxb);
622 prxb = NULL;
623 }
624}
625
626
627void RxReorderIndicatePacket( struct ieee80211_device *ieee,
628 struct ieee80211_rxb* prxb,
629 PRX_TS_RECORD pTS,
630 u16 SeqNum)
631{
632 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
633 PRX_REORDER_ENTRY pReorderEntry = NULL;
634 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
635 u8 WinSize = pHTInfo->RxReorderWinSize;
636 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
637 u8 index = 0;
638 bool bMatchWinStart = false, bPktInBuf = false;
639 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
640#if 0
641 if(!list_empty(&ieee->RxReorder_Unused_List))
642 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): ieee->RxReorder_Unused_List is nut NULL\n");
643#endif
644
645 if(pTS->RxIndicateSeq == 0xffff) {
646 pTS->RxIndicateSeq = SeqNum;
647 }
648
649
650 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
651 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
652 pTS->RxIndicateSeq, SeqNum);
653 pHTInfo->RxReorderDropCounter++;
654 {
655 int i;
656 for(i =0; i < prxb->nr_subframes; i++) {
657 dev_kfree_skb(prxb->subframes[i]);
658 }
659 kfree(prxb);
660 prxb = NULL;
661 }
662 return;
663 }
664
665
666
667
668
669
670 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
671 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
672 bMatchWinStart = true;
673 } else if(SN_LESS(WinEnd, SeqNum)) {
674 if(SeqNum >= (WinSize - 1)) {
675 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
676 } else {
677 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
678 }
679 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
680 }
681
682
683
684
685
686
687
688
689
690
691 if(bMatchWinStart) {
692
693 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
694 pTS->RxIndicateSeq, SeqNum);
695 prxbIndicateArray[0] = prxb;
696
697 index = 1;
698 } else {
699
700
701 if(!list_empty(&ieee->RxReorder_Unused_List)) {
702 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
703 list_del_init(&pReorderEntry->List);
704
705
706 pReorderEntry->SeqNum = SeqNum;
707 pReorderEntry->prxb = prxb;
708
709
710#if 1
711 if(!AddReorderEntry(pTS, pReorderEntry)) {
712 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
713 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
714 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
715 {
716 int i;
717 for(i =0; i < prxb->nr_subframes; i++) {
718 dev_kfree_skb(prxb->subframes[i]);
719 }
720 kfree(prxb);
721 prxb = NULL;
722 }
723 } else {
724 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
725 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
726 }
727#endif
728 }
729 else {
730
731
732
733
734
735 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
736 {
737 int i;
738 for(i =0; i < prxb->nr_subframes; i++) {
739 dev_kfree_skb(prxb->subframes[i]);
740 }
741 kfree(prxb);
742 prxb = NULL;
743 }
744 }
745 }
746
747
748 while(!list_empty(&pTS->RxPendingPktList)) {
749 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
750#if 1
751 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
752 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
753 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
754 {
755
756 if(index >= REORDER_WIN_SIZE) {
757 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
758 bPktInBuf = true;
759 break;
760 }
761
762 list_del_init(&pReorderEntry->List);
763
764 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
765 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
766
767 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
768 prxbIndicateArray[index] = pReorderEntry->prxb;
769
770 index++;
771
772 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
773 } else {
774 bPktInBuf = true;
775 break;
776 }
777#endif
778 }
779
780
781 if(index>0) {
782
783 if (timer_pending(&pTS->RxPktPendingTimer))
784 del_timer_sync(&pTS->RxPktPendingTimer);
785 pTS->RxTimeoutIndicateSeq = 0xffff;
786
787
788 if(index>REORDER_WIN_SIZE){
789 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
790 return;
791 }
792 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
793 bPktInBuf = false;
794 }
795
796#if 1
797 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
798
799 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
800 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
801#if 0
802 if(timer_pending(&pTS->RxPktPendingTimer))
803 del_timer_sync(&pTS->RxPktPendingTimer);
804 pTS->RxPktPendingTimer.expires = jiffies + MSECS(pHTInfo->RxReorderPendingTime);
805 add_timer(&pTS->RxPktPendingTimer);
806#else
807 mod_timer(&pTS->RxPktPendingTimer, jiffies + MSECS(pHTInfo->RxReorderPendingTime));
808#endif
809 }
810#endif
811}
812
813u8 parse_subframe(struct ieee80211_device* ieee,struct sk_buff *skb,
814 struct ieee80211_rx_stats *rx_stats,
815 struct ieee80211_rxb *rxb,u8* src,u8* dst)
816{
817 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
818 u16 fc = le16_to_cpu(hdr->frame_ctl);
819
820 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
821 u16 ChkLength;
822 bool bIsAggregateFrame = false;
823 u16 nSubframe_Length;
824 u8 nPadding_Length = 0;
825 u16 SeqNum=0;
826
827 struct sk_buff *sub_skb;
828 u8 *data_ptr;
829
830 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
831
832 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
833 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
834 bIsAggregateFrame = true;
835 }
836
837 if(IEEE80211_QOS_HAS_SEQ(fc)) {
838 LLCOffset += 2;
839 }
840
841 if(rx_stats->bContainHTC) {
842 LLCOffset += sHTCLng;
843 }
844
845
846 ChkLength = LLCOffset;
847
848 if( skb->len <= ChkLength ) {
849 return 0;
850 }
851
852 skb_pull(skb, LLCOffset);
853 ieee->bIsAggregateFrame = bIsAggregateFrame;
854
855 if(!bIsAggregateFrame) {
856 rxb->nr_subframes = 1;
857#ifdef JOHN_NOCPY
858 rxb->subframes[0] = skb;
859#else
860 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
861#endif
862
863 memcpy(rxb->src,src,ETH_ALEN);
864 memcpy(rxb->dst,dst,ETH_ALEN);
865
866 return 1;
867 } else {
868 rxb->nr_subframes = 0;
869 memcpy(rxb->src,src,ETH_ALEN);
870 memcpy(rxb->dst,dst,ETH_ALEN);
871 while(skb->len > ETHERNET_HEADER_SIZE) {
872
873 nSubframe_Length = *((u16*)(skb->data + 12));
874
875 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
876
877 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
878#if 0
879 RT_ASSERT(
880 (nRemain_Length>=(ETHERNET_HEADER_SIZE + nSubframe_Length)),
881 ("ParseSubframe(): A-MSDU subframe parse error!! Subframe Length: %d\n", nSubframe_Length) );
882#endif
883 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
884 __FUNCTION__,rxb->nr_subframes);
885 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
886 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
887 printk("The Packet SeqNum is %d\n",SeqNum);
888 return 0;
889 }
890
891
892 skb_pull(skb, ETHERNET_HEADER_SIZE);
893
894#ifdef JOHN_NOCPY
895 sub_skb = skb_clone(skb, GFP_ATOMIC);
896 sub_skb->len = nSubframe_Length;
897 sub_skb->tail = sub_skb->data + nSubframe_Length;
898#else
899
900 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
901 skb_reserve(sub_skb, 12);
902 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
903 memcpy(data_ptr,skb->data,nSubframe_Length);
904#endif
905 rxb->subframes[rxb->nr_subframes++] = sub_skb;
906 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
907 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
908 break;
909 }
910 skb_pull(skb,nSubframe_Length);
911
912 if(skb->len != 0) {
913 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
914 if(nPadding_Length == 4) {
915 nPadding_Length = 0;
916 }
917
918 if(skb->len < nPadding_Length) {
919 return 0;
920 }
921
922 skb_pull(skb,nPadding_Length);
923 }
924 }
925#ifdef JOHN_NOCPY
926 dev_kfree_skb(skb);
927#endif
928
929
930
931 return rxb->nr_subframes;
932 }
933}
934
935
936
937
938int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
939 struct ieee80211_rx_stats *rx_stats)
940{
941 struct net_device *dev = ieee->dev;
942 struct ieee80211_hdr_4addr *hdr;
943
944
945 size_t hdrlen;
946 u16 fc, type, stype, sc;
947 struct net_device_stats *stats;
948 unsigned int frag;
949 u8 *payload;
950 u16 ethertype;
951
952 u8 TID = 0;
953 u16 SeqNum = 0;
954 PRX_TS_RECORD pTS = NULL;
955 bool unicast_packet = false;
956
957
958#ifdef NOT_YET
959 struct net_device *wds = NULL;
960 struct sk_buff *skb2 = NULL;
961 struct net_device *wds = NULL;
962 int frame_authorized = 0;
963 int from_assoc_ap = 0;
964 void *sta = NULL;
965#endif
966
967 u8 dst[ETH_ALEN];
968 u8 src[ETH_ALEN];
969 u8 bssid[ETH_ALEN];
970 struct ieee80211_crypt_data *crypt = NULL;
971 int keyidx = 0;
972
973 int i;
974 struct ieee80211_rxb* rxb = NULL;
975
976 hdr = (struct ieee80211_hdr_4addr *)skb->data;
977 stats = &ieee->stats;
978
979 if (skb->len < 10) {
980 printk(KERN_INFO "%s: SKB length < 10\n",
981 dev->name);
982 goto rx_dropped;
983 }
984
985 fc = le16_to_cpu(hdr->frame_ctl);
986 type = WLAN_FC_GET_TYPE(fc);
987 stype = WLAN_FC_GET_STYPE(fc);
988 sc = le16_to_cpu(hdr->seq_ctl);
989
990 frag = WLAN_GET_SEQ_FRAG(sc);
991 hdrlen = ieee80211_get_hdrlen(fc);
992
993 if(HTCCheck(ieee, skb->data))
994 {
995 if(net_ratelimit())
996 printk("find HTCControl\n");
997 hdrlen += 4;
998 rx_stats->bContainHTC = 1;
999 }
1000
1001
1002#ifdef NOT_YET
1003#if WIRELESS_EXT > 15
1004
1005
1006#ifdef IW_WIRELESS_SPY
1007
1008 if (iface->spy_data.spy_number > 0) {
1009 struct iw_quality wstats;
1010 wstats.level = rx_stats->rssi;
1011 wstats.noise = rx_stats->noise;
1012 wstats.updated = 6;
1013
1014 wireless_spy_update(dev, hdr->addr2, &wstats);
1015 }
1016#endif
1017#endif
1018 hostap_update_rx_stats(local->ap, hdr, rx_stats);
1019#endif
1020
1021#if WIRELESS_EXT > 15
1022 if (ieee->iw_mode == IW_MODE_MONITOR) {
1023 ieee80211_monitor_rx(ieee, skb, rx_stats);
1024 stats->rx_packets++;
1025 stats->rx_bytes += skb->len;
1026 return 1;
1027 }
1028#endif
1029 if (ieee->host_decrypt) {
1030 int idx = 0;
1031 if (skb->len >= hdrlen + 3)
1032 idx = skb->data[hdrlen + 3] >> 6;
1033 crypt = ieee->crypt[idx];
1034#ifdef NOT_YET
1035 sta = NULL;
1036
1037
1038
1039
1040
1041
1042
1043
1044 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1045 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1046 &sta);
1047#endif
1048
1049
1050
1051 if (crypt && (crypt->ops == NULL ||
1052 crypt->ops->decrypt_mpdu == NULL))
1053 crypt = NULL;
1054
1055 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
1056
1057
1058
1059
1060 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1061 " (SA=%pM)\n",
1062 hdr->addr2);
1063 ieee->ieee_stats.rx_discards_undecryptable++;
1064 goto rx_dropped;
1065 }
1066 }
1067
1068 if (skb->len < IEEE80211_DATA_HDR3_LEN)
1069 goto rx_dropped;
1070
1071
1072 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
1073 if (is_duplicate_packet(ieee, hdr))
1074 goto rx_dropped;
1075
1076 }
1077 else
1078 {
1079 PRX_TS_RECORD pRxTS = NULL;
1080 #if 0
1081 struct ieee80211_hdr_3addr *hdr;
1082 u16 fc;
1083 hdr = (struct ieee80211_hdr_3addr *)skb->data;
1084 fc = le16_to_cpu(hdr->frame_ctl);
1085 u8 tmp = (fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS);
1086
1087 u8 tid = (*((u8*)skb->data + (((fc& IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))?30:24)))&0xf;
1088 printk("====================>fc:%x, tid:%d, tmp:%d\n", fc, tid, tmp);
1089
1090 #endif
1091
1092#if 1
1093 if(GetTs(
1094 ieee,
1095 (PTS_COMMON_INFO*) &pRxTS,
1096 hdr->addr2,
1097 (u8)Frame_QoSTID((u8*)(skb->data)),
1098 RX_DIR,
1099 true))
1100 {
1101
1102
1103 if( (fc & (1<<11)) &&
1104 (frag == pRxTS->RxLastFragNum) &&
1105 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
1106 {
1107 goto rx_dropped;
1108 }
1109 else
1110 {
1111 pRxTS->RxLastFragNum = frag;
1112 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1113 }
1114 }
1115 else
1116 {
1117 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
1118 goto rx_dropped;
1119 }
1120 }
1121#endif
1122 if (type == IEEE80211_FTYPE_MGMT) {
1123
1124 #if 0
1125 if ( stype == IEEE80211_STYPE_AUTH &&
1126 fc & IEEE80211_FCTL_WEP && ieee->host_decrypt &&
1127 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1128 {
1129 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
1130 "from %pM\n", dev->name,
1131 hdr->addr2);
1132
1133
1134 goto rx_dropped;
1135 }
1136 #endif
1137
1138
1139 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1140 goto rx_dropped;
1141 else
1142 goto rx_exit;
1143 }
1144
1145
1146 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1147 case IEEE80211_FCTL_FROMDS:
1148 memcpy(dst, hdr->addr1, ETH_ALEN);
1149 memcpy(src, hdr->addr3, ETH_ALEN);
1150 memcpy(bssid, hdr->addr2, ETH_ALEN);
1151 break;
1152 case IEEE80211_FCTL_TODS:
1153 memcpy(dst, hdr->addr3, ETH_ALEN);
1154 memcpy(src, hdr->addr2, ETH_ALEN);
1155 memcpy(bssid, hdr->addr1, ETH_ALEN);
1156 break;
1157 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1158 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1159 goto rx_dropped;
1160 memcpy(dst, hdr->addr3, ETH_ALEN);
1161 memcpy(src, hdr->addr4, ETH_ALEN);
1162 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1163 break;
1164 case 0:
1165 memcpy(dst, hdr->addr1, ETH_ALEN);
1166 memcpy(src, hdr->addr2, ETH_ALEN);
1167 memcpy(bssid, hdr->addr3, ETH_ALEN);
1168 break;
1169 }
1170
1171#ifdef NOT_YET
1172 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1173 goto rx_dropped;
1174 if (wds) {
1175 skb->dev = dev = wds;
1176 stats = hostap_get_stats(dev);
1177 }
1178
1179 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1180 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1181 ieee->stadev &&
1182 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1183
1184 skb->dev = dev = ieee->stadev;
1185 stats = hostap_get_stats(dev);
1186 from_assoc_ap = 1;
1187 }
1188#endif
1189
1190 dev->last_rx = jiffies;
1191
1192#ifdef NOT_YET
1193 if ((ieee->iw_mode == IW_MODE_MASTER ||
1194 ieee->iw_mode == IW_MODE_REPEAT) &&
1195 !from_assoc_ap) {
1196 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1197 wds != NULL)) {
1198 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1199 frame_authorized = 0;
1200 break;
1201 case AP_RX_CONTINUE:
1202 frame_authorized = 1;
1203 break;
1204 case AP_RX_DROP:
1205 goto rx_dropped;
1206 case AP_RX_EXIT:
1207 goto rx_exit;
1208 }
1209 }
1210#endif
1211
1212
1213
1214 if (stype != IEEE80211_STYPE_DATA &&
1215 stype != IEEE80211_STYPE_DATA_CFACK &&
1216 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1217 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1218 stype != IEEE80211_STYPE_QOS_DATA
1219 ) {
1220 if (stype != IEEE80211_STYPE_NULLFUNC)
1221 IEEE80211_DEBUG_DROP(
1222 "RX: dropped data frame "
1223 "with no data (type=0x%02x, "
1224 "subtype=0x%02x, len=%d)\n",
1225 type, stype, skb->len);
1226 goto rx_dropped;
1227 }
1228 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1229 goto rx_dropped;
1230
1231#ifdef ENABLE_LPS
1232 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == 1)
1233 && (ieee->polling)) {
1234 if (WLAN_FC_MORE_DATA(fc)) {
1235
1236 ieee80211_sta_ps_send_pspoll_frame(ieee);
1237 } else {
1238 ieee->polling = false;
1239 }
1240 }
1241#endif
1242
1243 ieee->need_sw_enc = 0;
1244
1245 if((!rx_stats->Decrypted)){
1246 ieee->need_sw_enc = 1;
1247 }
1248
1249
1250
1251 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1252 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1253 {
1254 printk("decrypt frame error\n");
1255 goto rx_dropped;
1256 }
1257
1258
1259 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1260
1261
1262
1263
1264 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1265 int flen;
1266 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1267 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1268
1269 if (!frag_skb) {
1270 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1271 "Rx cannot get skb from fragment "
1272 "cache (morefrag=%d seq=%u frag=%u)\n",
1273 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1274 WLAN_GET_SEQ_SEQ(sc), frag);
1275 goto rx_dropped;
1276 }
1277 flen = skb->len;
1278 if (frag != 0)
1279 flen -= hdrlen;
1280
1281 if (frag_skb->tail + flen > frag_skb->end) {
1282 printk(KERN_WARNING "%s: host decrypted and "
1283 "reassembled frame did not fit skb\n",
1284 dev->name);
1285 ieee80211_frag_cache_invalidate(ieee, hdr);
1286 goto rx_dropped;
1287 }
1288
1289 if (frag == 0) {
1290
1291
1292 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1293 } else {
1294
1295
1296 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1297 flen);
1298 }
1299 dev_kfree_skb_any(skb);
1300 skb = NULL;
1301
1302 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1303
1304
1305
1306 goto rx_exit;
1307 }
1308
1309
1310
1311 skb = frag_skb;
1312 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1313 ieee80211_frag_cache_invalidate(ieee, hdr);
1314 }
1315
1316
1317
1318 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1319 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1320 {
1321 printk("==>decrypt msdu error\n");
1322 goto rx_dropped;
1323 }
1324
1325
1326 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1327 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1328
1329 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1330 if((!is_multicast_ether_addr(hdr->addr1)) && (!is_broadcast_ether_addr(hdr->addr1)))
1331 unicast_packet = true;
1332
1333 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1334 if (
1335 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1336
1337#ifdef CONFIG_IEEE80211_DEBUG
1338
1339
1340 struct eapol *eap = (struct eapol *)(skb->data +
1341 24);
1342 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1343 eap_get_type(eap->type));
1344#endif
1345 } else {
1346 IEEE80211_DEBUG_DROP(
1347 "encryption configured, but RX "
1348 "frame not encrypted (SA=%pM)\n",
1349 hdr->addr2);
1350 goto rx_dropped;
1351 }
1352 }
1353
1354#ifdef CONFIG_IEEE80211_DEBUG
1355 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1356 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1357 struct eapol *eap = (struct eapol *)(skb->data +
1358 24);
1359 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1360 eap_get_type(eap->type));
1361 }
1362#endif
1363
1364 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1365 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1366 IEEE80211_DEBUG_DROP(
1367 "dropped unencrypted RX data "
1368 "frame from %pM"
1369 " (drop_unencrypted=1)\n",
1370 hdr->addr2);
1371 goto rx_dropped;
1372 }
1373
1374
1375
1376
1377
1378
1379#if 1
1380 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1381 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1382 {
1383 TID = Frame_QoSTID(skb->data);
1384 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1385 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1386 if(TID !=0 && TID !=3)
1387 {
1388 ieee->bis_any_nonbepkts = true;
1389 }
1390 }
1391#endif
1392
1393
1394 payload = skb->data + hdrlen;
1395
1396 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1397 if(rxb == NULL)
1398 {
1399 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1400 goto rx_dropped;
1401 }
1402
1403
1404 if(parse_subframe(ieee, skb,rx_stats,rxb,src,dst) == 0) {
1405
1406 for(i =0; i < rxb->nr_subframes; i++) {
1407 dev_kfree_skb(rxb->subframes[i]);
1408 }
1409 kfree(rxb);
1410 rxb = NULL;
1411 goto rx_dropped;
1412 }
1413
1414#ifdef ENABLE_LPS
1415 if(unicast_packet)
1416 {
1417 if (type == IEEE80211_FTYPE_DATA)
1418 {
1419
1420 if(ieee->bIsAggregateFrame)
1421 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod+=rxb->nr_subframes;
1422 else
1423 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod++;
1424
1425
1426
1427 if((ieee->state == IEEE80211_LINKED) )
1428 {
1429 if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
1430 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
1431 {
1432 if(ieee->LeisurePSLeave)
1433 ieee->LeisurePSLeave(dev);
1434 }
1435 }
1436 }
1437 }
1438#endif
1439
1440 ieee->last_rx_ps_time = jiffies;
1441
1442 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1443
1444 for(i = 0; i<rxb->nr_subframes; i++) {
1445 struct sk_buff *sub_skb = rxb->subframes[i];
1446
1447 if (sub_skb) {
1448
1449 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1450 if (sub_skb->len >= 8 &&
1451 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1452 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1453 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1454
1455
1456 skb_pull(sub_skb, SNAP_SIZE);
1457 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1458 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1459 } else {
1460 u16 len;
1461
1462 len = htons(sub_skb->len);
1463 memcpy(skb_push(sub_skb, 2), &len, 2);
1464 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1465 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1466 }
1467
1468 stats->rx_packets++;
1469 stats->rx_bytes += sub_skb->len;
1470 if(is_multicast_ether_addr(dst)) {
1471 stats->multicast++;
1472 }
1473
1474
1475
1476 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1477 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1478 sub_skb->dev = dev;
1479 sub_skb->ip_summed = CHECKSUM_NONE;
1480
1481
1482 netif_rx(sub_skb);
1483 }
1484 }
1485 kfree(rxb);
1486 rxb = NULL;
1487
1488 }
1489 else
1490 {
1491 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1492 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1493 }
1494#ifndef JOHN_NOCPY
1495 dev_kfree_skb(skb);
1496#endif
1497
1498 rx_exit:
1499#ifdef NOT_YET
1500 if (sta)
1501 hostap_handle_sta_release(sta);
1502#endif
1503 return 1;
1504
1505 rx_dropped:
1506 if (rxb != NULL)
1507 {
1508 kfree(rxb);
1509 rxb = NULL;
1510 }
1511 stats->rx_dropped++;
1512
1513
1514
1515
1516 return 0;
1517}
1518
1519#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1520
1521static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1522
1523
1524
1525
1526
1527static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1528 *info_element, int sub_type)
1529{
1530
1531 if (info_element->qui_subtype != sub_type)
1532 return -1;
1533 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1534 return -1;
1535 if (info_element->qui_type != QOS_OUI_TYPE)
1536 return -1;
1537 if (info_element->version != QOS_VERSION_1)
1538 return -1;
1539
1540 return 0;
1541}
1542
1543
1544
1545
1546
1547static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1548 *element_param, struct ieee80211_info_element
1549 *info_element)
1550{
1551 int ret = 0;
1552 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1553
1554 if ((info_element == NULL) || (element_param == NULL))
1555 return -1;
1556
1557 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1558 memcpy(element_param->info_element.qui, info_element->data,
1559 info_element->len);
1560 element_param->info_element.elementID = info_element->id;
1561 element_param->info_element.length = info_element->len;
1562 } else
1563 ret = -1;
1564 if (ret == 0)
1565 ret = ieee80211_verify_qos_info(&element_param->info_element,
1566 QOS_OUI_PARAM_SUB_TYPE);
1567 return ret;
1568}
1569
1570
1571
1572
1573static int ieee80211_read_qos_info_element(struct
1574 ieee80211_qos_information_element
1575 *element_info, struct ieee80211_info_element
1576 *info_element)
1577{
1578 int ret = 0;
1579 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1580
1581 if (element_info == NULL)
1582 return -1;
1583 if (info_element == NULL)
1584 return -1;
1585
1586 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1587 memcpy(element_info->qui, info_element->data,
1588 info_element->len);
1589 element_info->elementID = info_element->id;
1590 element_info->length = info_element->len;
1591 } else
1592 ret = -1;
1593
1594 if (ret == 0)
1595 ret = ieee80211_verify_qos_info(element_info,
1596 QOS_OUI_INFO_SUB_TYPE);
1597 return ret;
1598}
1599
1600
1601
1602
1603
1604static int ieee80211_qos_convert_ac_to_parameters(struct
1605 ieee80211_qos_parameter_info
1606 *param_elm, struct
1607 ieee80211_qos_parameters
1608 *qos_param)
1609{
1610 int rc = 0;
1611 int i;
1612 struct ieee80211_qos_ac_parameter *ac_params;
1613 u8 aci;
1614
1615
1616
1617 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1618 ac_params = &(param_elm->ac_params_record[i]);
1619
1620 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1621
1622 if(aci >= QOS_QUEUE_NUM)
1623 continue;
1624 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1625
1626
1627 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1628
1629 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1630
1631 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1632
1633 qos_param->flag[aci] =
1634 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1635 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1636 }
1637 return rc;
1638}
1639
1640
1641
1642
1643
1644
1645static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1646 *info_element,
1647 struct ieee80211_network *network)
1648{
1649 int rc = 0;
1650 struct ieee80211_qos_parameters *qos_param = NULL;
1651 struct ieee80211_qos_information_element qos_info_element;
1652
1653 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1654
1655 if (rc == 0) {
1656 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1657 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1658 } else {
1659 struct ieee80211_qos_parameter_info param_element;
1660
1661 rc = ieee80211_read_qos_param_element(¶m_element,
1662 info_element);
1663 if (rc == 0) {
1664 qos_param = &(network->qos_data.parameters);
1665 ieee80211_qos_convert_ac_to_parameters(¶m_element,
1666 qos_param);
1667 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1668 network->qos_data.param_count =
1669 param_element.info_element.ac_info & 0x0F;
1670 }
1671 }
1672
1673 if (rc == 0) {
1674 IEEE80211_DEBUG_QOS("QoS is supported\n");
1675 network->qos_data.supported = 1;
1676 }
1677 return rc;
1678}
1679
1680#ifdef CONFIG_IEEE80211_DEBUG
1681#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1682
1683static const char *get_info_element_string(u16 id)
1684{
1685 switch (id) {
1686 MFIE_STRING(SSID);
1687 MFIE_STRING(RATES);
1688 MFIE_STRING(FH_SET);
1689 MFIE_STRING(DS_SET);
1690 MFIE_STRING(CF_SET);
1691 MFIE_STRING(TIM);
1692 MFIE_STRING(IBSS_SET);
1693 MFIE_STRING(COUNTRY);
1694 MFIE_STRING(HOP_PARAMS);
1695 MFIE_STRING(HOP_TABLE);
1696 MFIE_STRING(REQUEST);
1697 MFIE_STRING(CHALLENGE);
1698 MFIE_STRING(POWER_CONSTRAINT);
1699 MFIE_STRING(POWER_CAPABILITY);
1700 MFIE_STRING(TPC_REQUEST);
1701 MFIE_STRING(TPC_REPORT);
1702 MFIE_STRING(SUPP_CHANNELS);
1703 MFIE_STRING(CSA);
1704 MFIE_STRING(MEASURE_REQUEST);
1705 MFIE_STRING(MEASURE_REPORT);
1706 MFIE_STRING(QUIET);
1707 MFIE_STRING(IBSS_DFS);
1708
1709 MFIE_STRING(RSN);
1710 MFIE_STRING(RATES_EX);
1711 MFIE_STRING(GENERIC);
1712 MFIE_STRING(QOS_PARAMETER);
1713 default:
1714 return "UNKNOWN";
1715 }
1716}
1717#endif
1718
1719#ifdef ENABLE_DOT11D
1720static inline void ieee80211_extract_country_ie(
1721 struct ieee80211_device *ieee,
1722 struct ieee80211_info_element *info_element,
1723 struct ieee80211_network *network,
1724 u8 * addr2
1725)
1726{
1727 if(IS_DOT11D_ENABLE(ieee))
1728 {
1729 if(info_element->len!= 0)
1730 {
1731 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1732 network->CountryIeLen = info_element->len;
1733
1734 if(!IS_COUNTRY_IE_VALID(ieee))
1735 {
1736 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1737 }
1738 }
1739
1740
1741
1742
1743
1744
1745 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1746 {
1747 UPDATE_CIE_WATCHDOG(ieee);
1748 }
1749 }
1750
1751}
1752#endif
1753
1754int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1755 struct ieee80211_info_element *info_element,
1756 u16 length,
1757 struct ieee80211_network *network,
1758 struct ieee80211_rx_stats *stats)
1759{
1760 u8 i;
1761 short offset;
1762 u16 tmp_htcap_len=0;
1763 u16 tmp_htinfo_len=0;
1764 u16 ht_realtek_agg_len=0;
1765 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1766
1767#ifdef CONFIG_IEEE80211_DEBUG
1768 char rates_str[64];
1769 char *p;
1770#endif
1771
1772 while (length >= sizeof(*info_element)) {
1773 if (sizeof(*info_element) + info_element->len > length) {
1774 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1775 "info_element->len + 2 > left : "
1776 "info_element->len+2=%zd left=%d, id=%d.\n",
1777 info_element->len +
1778 sizeof(*info_element),
1779 length, info_element->id);
1780
1781
1782
1783 break;
1784 }
1785
1786 switch (info_element->id) {
1787 case MFIE_TYPE_SSID:
1788 if (ieee80211_is_empty_essid(info_element->data,
1789 info_element->len)) {
1790 network->flags |= NETWORK_EMPTY_ESSID;
1791 break;
1792 }
1793
1794 network->ssid_len = min(info_element->len,
1795 (u8) IW_ESSID_MAX_SIZE);
1796 memcpy(network->ssid, info_element->data, network->ssid_len);
1797 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1798 memset(network->ssid + network->ssid_len, 0,
1799 IW_ESSID_MAX_SIZE - network->ssid_len);
1800
1801 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1802 network->ssid, network->ssid_len);
1803 break;
1804
1805 case MFIE_TYPE_RATES:
1806#ifdef CONFIG_IEEE80211_DEBUG
1807 p = rates_str;
1808#endif
1809 network->rates_len = min(info_element->len,
1810 MAX_RATES_LENGTH);
1811 for (i = 0; i < network->rates_len; i++) {
1812 network->rates[i] = info_element->data[i];
1813#ifdef CONFIG_IEEE80211_DEBUG
1814 p += snprintf(p, sizeof(rates_str) -
1815 (p - rates_str), "%02X ",
1816 network->rates[i]);
1817#endif
1818 if (ieee80211_is_ofdm_rate
1819 (info_element->data[i])) {
1820 network->flags |= NETWORK_HAS_OFDM;
1821 if (info_element->data[i] &
1822 IEEE80211_BASIC_RATE_MASK)
1823 network->flags &=
1824 ~NETWORK_HAS_CCK;
1825 }
1826 }
1827
1828 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1829 rates_str, network->rates_len);
1830 break;
1831
1832 case MFIE_TYPE_RATES_EX:
1833#ifdef CONFIG_IEEE80211_DEBUG
1834 p = rates_str;
1835#endif
1836 network->rates_ex_len = min(info_element->len,
1837 MAX_RATES_EX_LENGTH);
1838 for (i = 0; i < network->rates_ex_len; i++) {
1839 network->rates_ex[i] = info_element->data[i];
1840#ifdef CONFIG_IEEE80211_DEBUG
1841 p += snprintf(p, sizeof(rates_str) -
1842 (p - rates_str), "%02X ",
1843 network->rates[i]);
1844#endif
1845 if (ieee80211_is_ofdm_rate
1846 (info_element->data[i])) {
1847 network->flags |= NETWORK_HAS_OFDM;
1848 if (info_element->data[i] &
1849 IEEE80211_BASIC_RATE_MASK)
1850 network->flags &=
1851 ~NETWORK_HAS_CCK;
1852 }
1853 }
1854
1855 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1856 rates_str, network->rates_ex_len);
1857 break;
1858
1859 case MFIE_TYPE_DS_SET:
1860 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1861 info_element->data[0]);
1862 network->channel = info_element->data[0];
1863 break;
1864
1865 case MFIE_TYPE_FH_SET:
1866 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1867 break;
1868
1869 case MFIE_TYPE_CF_SET:
1870 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1871 break;
1872
1873 case MFIE_TYPE_TIM:
1874 if(info_element->len < 4)
1875 break;
1876
1877 network->tim.tim_count = info_element->data[0];
1878 network->tim.tim_period = info_element->data[1];
1879
1880 network->dtim_period = info_element->data[1];
1881 if(ieee->state != IEEE80211_LINKED)
1882 break;
1883#if 0
1884 network->last_dtim_sta_time[0] = stats->mac_time[0];
1885#else
1886
1887 network->last_dtim_sta_time[0] = jiffies;
1888#endif
1889 network->last_dtim_sta_time[1] = stats->mac_time[1];
1890
1891 network->dtim_data = IEEE80211_DTIM_VALID;
1892
1893 if(info_element->data[0] != 0)
1894 break;
1895
1896 if(info_element->data[2] & 1)
1897 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1898
1899 offset = (info_element->data[2] >> 1)*2;
1900
1901
1902
1903 if(ieee->assoc_id < 8*offset ||
1904 ieee->assoc_id > 8*(offset + info_element->len -3))
1905
1906 break;
1907
1908 offset = (ieee->assoc_id / 8) - offset;
1909
1910 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1911 network->dtim_data |= IEEE80211_DTIM_UCAST;
1912
1913
1914 break;
1915
1916 case MFIE_TYPE_ERP:
1917 network->erp_value = info_element->data[0];
1918 network->flags |= NETWORK_HAS_ERP_VALUE;
1919 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1920 network->erp_value);
1921 break;
1922 case MFIE_TYPE_IBSS_SET:
1923 network->atim_window = info_element->data[0];
1924 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1925 network->atim_window);
1926 break;
1927
1928 case MFIE_TYPE_CHALLENGE:
1929 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1930 break;
1931
1932 case MFIE_TYPE_GENERIC:
1933 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1934 info_element->len);
1935 if (!ieee80211_parse_qos_info_param_IE(info_element,
1936 network))
1937 break;
1938
1939 if (info_element->len >= 4 &&
1940 info_element->data[0] == 0x00 &&
1941 info_element->data[1] == 0x50 &&
1942 info_element->data[2] == 0xf2 &&
1943 info_element->data[3] == 0x01) {
1944 network->wpa_ie_len = min(info_element->len + 2,
1945 MAX_WPA_IE_LEN);
1946 memcpy(network->wpa_ie, info_element,
1947 network->wpa_ie_len);
1948 break;
1949 }
1950
1951#ifdef THOMAS_TURBO
1952 if (info_element->len == 7 &&
1953 info_element->data[0] == 0x00 &&
1954 info_element->data[1] == 0xe0 &&
1955 info_element->data[2] == 0x4c &&
1956 info_element->data[3] == 0x01 &&
1957 info_element->data[4] == 0x02) {
1958 network->Turbo_Enable = 1;
1959 }
1960#endif
1961
1962
1963 if(tmp_htcap_len == 0){
1964 if(info_element->len >= 4 &&
1965 info_element->data[0] == 0x00 &&
1966 info_element->data[1] == 0x90 &&
1967 info_element->data[2] == 0x4c &&
1968 info_element->data[3] == 0x033){
1969
1970 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1971 if(tmp_htcap_len != 0){
1972 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1973 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1974 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1975 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1976 }
1977 }
1978 if(tmp_htcap_len != 0)
1979 network->bssht.bdSupportHT = true;
1980 else
1981 network->bssht.bdSupportHT = false;
1982 }
1983
1984
1985 if(tmp_htinfo_len == 0){
1986 if(info_element->len >= 4 &&
1987 info_element->data[0] == 0x00 &&
1988 info_element->data[1] == 0x90 &&
1989 info_element->data[2] == 0x4c &&
1990 info_element->data[3] == 0x034){
1991
1992 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1993 if(tmp_htinfo_len != 0){
1994 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1995 if(tmp_htinfo_len){
1996 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1997 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1998 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1999 }
2000
2001 }
2002
2003 }
2004 }
2005
2006 if(ieee->aggregation){
2007 if(network->bssht.bdSupportHT){
2008 if(info_element->len >= 4 &&
2009 info_element->data[0] == 0x00 &&
2010 info_element->data[1] == 0xe0 &&
2011 info_element->data[2] == 0x4c &&
2012 info_element->data[3] == 0x02){
2013
2014 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
2015 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
2016
2017 }
2018 if(ht_realtek_agg_len >= 5){
2019 network->bssht.bdRT2RTAggregation = true;
2020
2021 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
2022 network->bssht.bdRT2RTLongSlotTime = true;
2023 }
2024 }
2025
2026 }
2027
2028
2029 {
2030 if((info_element->len >= 3 &&
2031 info_element->data[0] == 0x00 &&
2032 info_element->data[1] == 0x05 &&
2033 info_element->data[2] == 0xb5) ||
2034 (info_element->len >= 3 &&
2035 info_element->data[0] == 0x00 &&
2036 info_element->data[1] == 0x0a &&
2037 info_element->data[2] == 0xf7) ||
2038 (info_element->len >= 3 &&
2039 info_element->data[0] == 0x00 &&
2040 info_element->data[1] == 0x10 &&
2041 info_element->data[2] == 0x18)){
2042
2043 network->broadcom_cap_exist = true;
2044
2045 }
2046 }
2047#if 0
2048 if (tmp_htcap_len !=0)
2049 {
2050 u16 cap_ext = ((PHT_CAPABILITY_ELE)&info_element->data[0])->ExtHTCapInfo;
2051 if ((cap_ext & 0x0c00) == 0x0c00)
2052 {
2053 network->ralink_cap_exist = true;
2054 }
2055 }
2056#endif
2057 if(info_element->len >= 3 &&
2058 info_element->data[0] == 0x00 &&
2059 info_element->data[1] == 0x0c &&
2060 info_element->data[2] == 0x43)
2061 {
2062 network->ralink_cap_exist = true;
2063 }
2064 else
2065 network->ralink_cap_exist = false;
2066
2067 if((info_element->len >= 3 &&
2068 info_element->data[0] == 0x00 &&
2069 info_element->data[1] == 0x03 &&
2070 info_element->data[2] == 0x7f) ||
2071 (info_element->len >= 3 &&
2072 info_element->data[0] == 0x00 &&
2073 info_element->data[1] == 0x13 &&
2074 info_element->data[2] == 0x74))
2075 {
2076
2077 network->atheros_cap_exist = true;
2078 }
2079 else
2080 network->atheros_cap_exist = false;
2081
2082 if ((info_element->len >= 3 &&
2083 info_element->data[0] == 0x00 &&
2084 info_element->data[1] == 0x50 &&
2085 info_element->data[2] == 0x43) )
2086 {
2087 network->marvell_cap_exist = true;
2088
2089 }
2090
2091
2092 if(info_element->len >= 3 &&
2093 info_element->data[0] == 0x00 &&
2094 info_element->data[1] == 0x40 &&
2095 info_element->data[2] == 0x96)
2096 {
2097 network->cisco_cap_exist = true;
2098 }
2099 else
2100 network->cisco_cap_exist = false;
2101
2102 if(info_element->len > 4 &&
2103 info_element->data[0] == 0x00 &&
2104 info_element->data[1] == 0x40 &&
2105 info_element->data[2] == 0x96 &&
2106 info_element->data[3] == 0x01)
2107 {
2108 if(info_element->len == 6)
2109 {
2110 memcpy(network->CcxRmState, &info_element[4], 2);
2111 if(network->CcxRmState[0] != 0)
2112 {
2113 network->bCcxRmEnable = true;
2114 }
2115 else
2116 network->bCcxRmEnable = false;
2117
2118
2119
2120 network->MBssidMask = network->CcxRmState[1] & 0x07;
2121 if(network->MBssidMask != 0)
2122 {
2123 network->bMBssidValid = true;
2124 network->MBssidMask = 0xff << (network->MBssidMask);
2125 cpMacAddr(network->MBssid, network->bssid);
2126 network->MBssid[5] &= network->MBssidMask;
2127 }
2128 else
2129 {
2130 network->bMBssidValid = false;
2131 }
2132 }
2133 else
2134 {
2135 network->bCcxRmEnable = false;
2136 }
2137 }
2138 if(info_element->len > 4 &&
2139 info_element->data[0] == 0x00 &&
2140 info_element->data[1] == 0x40 &&
2141 info_element->data[2] == 0x96 &&
2142 info_element->data[3] == 0x03)
2143 {
2144 if(info_element->len == 5)
2145 {
2146 network->bWithCcxVerNum = true;
2147 network->BssCcxVerNumber = info_element->data[4];
2148 }
2149 else
2150 {
2151 network->bWithCcxVerNum = false;
2152 network->BssCcxVerNumber = 0;
2153 }
2154 }
2155 break;
2156
2157 case MFIE_TYPE_RSN:
2158 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2159 info_element->len);
2160 network->rsn_ie_len = min(info_element->len + 2,
2161 MAX_WPA_IE_LEN);
2162 memcpy(network->rsn_ie, info_element,
2163 network->rsn_ie_len);
2164 break;
2165
2166
2167 case MFIE_TYPE_HT_CAP:
2168 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2169 info_element->len);
2170 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2171 if(tmp_htcap_len != 0){
2172 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2173 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2174 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2175 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2176
2177
2178
2179
2180 network->bssht.bdSupportHT = true;
2181 }
2182 else
2183 network->bssht.bdSupportHT = false;
2184 break;
2185
2186
2187 case MFIE_TYPE_HT_INFO:
2188 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2189 info_element->len);
2190 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2191 if(tmp_htinfo_len){
2192 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2193 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2194 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2195 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2196 }
2197 break;
2198
2199 case MFIE_TYPE_AIRONET:
2200 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2201 info_element->len);
2202 if(info_element->len >IE_CISCO_FLAG_POSITION)
2203 {
2204 network->bWithAironetIE = true;
2205
2206
2207
2208
2209 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
2210 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
2211 {
2212 network->bCkipSupported = true;
2213 }
2214 else
2215 {
2216 network->bCkipSupported = false;
2217 }
2218 }
2219 else
2220 {
2221 network->bWithAironetIE = false;
2222 network->bCkipSupported = false;
2223 }
2224 break;
2225 case MFIE_TYPE_QOS_PARAMETER:
2226 printk(KERN_ERR
2227 "QoS Error need to parse QOS_PARAMETER IE\n");
2228 break;
2229
2230#ifdef ENABLE_DOT11D
2231 case MFIE_TYPE_COUNTRY:
2232 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2233 info_element->len);
2234
2235 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);
2236 break;
2237#endif
2238
2239#if 0
2240
2241 case MFIE_TYPE_POWER_CONSTRAINT:
2242 network->power_constraint = info_element->data[0];
2243 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
2244 break;
2245
2246 case MFIE_TYPE_CSA:
2247 network->power_constraint = info_element->data[0];
2248 network->flags |= NETWORK_HAS_CSA;
2249 break;
2250
2251 case MFIE_TYPE_QUIET:
2252 network->quiet.count = info_element->data[0];
2253 network->quiet.period = info_element->data[1];
2254 network->quiet.duration = info_element->data[2];
2255 network->quiet.offset = info_element->data[3];
2256 network->flags |= NETWORK_HAS_QUIET;
2257 break;
2258
2259 case MFIE_TYPE_IBSS_DFS:
2260 if (network->ibss_dfs)
2261 break;
2262 network->ibss_dfs = kmemdup(info_element->data,
2263 info_element->len,
2264 GFP_ATOMIC);
2265 if (!network->ibss_dfs)
2266 return 1;
2267 network->flags |= NETWORK_HAS_IBSS_DFS;
2268 break;
2269
2270 case MFIE_TYPE_TPC_REPORT:
2271 network->tpc_report.transmit_power =
2272 info_element->data[0];
2273 network->tpc_report.link_margin = info_element->data[1];
2274 network->flags |= NETWORK_HAS_TPC_REPORT;
2275 break;
2276#endif
2277 default:
2278 IEEE80211_DEBUG_MGMT
2279 ("Unsupported info element: %s (%d)\n",
2280 get_info_element_string(info_element->id),
2281 info_element->id);
2282 break;
2283 }
2284
2285 length -= sizeof(*info_element) + info_element->len;
2286 info_element =
2287 (struct ieee80211_info_element *)&info_element->
2288 data[info_element->len];
2289 }
2290
2291 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2292 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation &&
2293 !network->marvell_cap_exist)
2294 {
2295 network->unknown_cap_exist = true;
2296 }
2297 else
2298 {
2299 network->unknown_cap_exist = false;
2300 }
2301 return 0;
2302}
2303
2304static inline u8 ieee80211_SignalStrengthTranslate(
2305 u8 CurrSS
2306 )
2307{
2308 u8 RetSS;
2309
2310
2311 if(CurrSS >= 71 && CurrSS <= 100)
2312 {
2313 RetSS = 90 + ((CurrSS - 70) / 3);
2314 }
2315 else if(CurrSS >= 41 && CurrSS <= 70)
2316 {
2317 RetSS = 78 + ((CurrSS - 40) / 3);
2318 }
2319 else if(CurrSS >= 31 && CurrSS <= 40)
2320 {
2321 RetSS = 66 + (CurrSS - 30);
2322 }
2323 else if(CurrSS >= 21 && CurrSS <= 30)
2324 {
2325 RetSS = 54 + (CurrSS - 20);
2326 }
2327 else if(CurrSS >= 5 && CurrSS <= 20)
2328 {
2329 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2330 }
2331 else if(CurrSS == 4)
2332 {
2333 RetSS = 36;
2334 }
2335 else if(CurrSS == 3)
2336 {
2337 RetSS = 27;
2338 }
2339 else if(CurrSS == 2)
2340 {
2341 RetSS = 18;
2342 }
2343 else if(CurrSS == 1)
2344 {
2345 RetSS = 9;
2346 }
2347 else
2348 {
2349 RetSS = CurrSS;
2350 }
2351
2352
2353
2354
2355
2356
2357 return RetSS;
2358}
2359
2360long ieee80211_translate_todbm(u8 signal_strength_index )
2361{
2362 long signal_power;
2363
2364
2365 signal_power = (long)((signal_strength_index + 1) >> 1);
2366 signal_power -= 95;
2367
2368 return signal_power;
2369}
2370
2371static inline int ieee80211_network_init(
2372 struct ieee80211_device *ieee,
2373 struct ieee80211_probe_response *beacon,
2374 struct ieee80211_network *network,
2375 struct ieee80211_rx_stats *stats)
2376{
2377#ifdef CONFIG_IEEE80211_DEBUG
2378
2379
2380#endif
2381
2382 network->qos_data.active = 0;
2383 network->qos_data.supported = 0;
2384 network->qos_data.param_count = 0;
2385 network->qos_data.old_param_count = 0;
2386
2387
2388 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2389 network->capability = le16_to_cpu(beacon->capability);
2390 network->last_scanned = jiffies;
2391 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2392 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2393 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2394
2395 network->listen_interval = 0x0A;
2396 network->rates_len = network->rates_ex_len = 0;
2397 network->last_associate = 0;
2398 network->ssid_len = 0;
2399 network->flags = 0;
2400 network->atim_window = 0;
2401 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2402 0x3 : 0x0;
2403 network->berp_info_valid = false;
2404 network->broadcom_cap_exist = false;
2405 network->ralink_cap_exist = false;
2406 network->atheros_cap_exist = false;
2407 network->marvell_cap_exist = false;
2408 network->cisco_cap_exist = false;
2409 network->unknown_cap_exist = false;
2410#ifdef THOMAS_TURBO
2411 network->Turbo_Enable = 0;
2412#endif
2413#ifdef ENABLE_DOT11D
2414 network->CountryIeLen = 0;
2415 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2416#endif
2417
2418
2419 HTInitializeBssDesc(&network->bssht);
2420 if (stats->freq == IEEE80211_52GHZ_BAND) {
2421
2422 network->channel = stats->received_channel;
2423 } else
2424 network->flags |= NETWORK_HAS_CCK;
2425
2426 network->wpa_ie_len = 0;
2427 network->rsn_ie_len = 0;
2428
2429 if (ieee80211_parse_info_param
2430 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2431 return 1;
2432
2433 network->mode = 0;
2434 if (stats->freq == IEEE80211_52GHZ_BAND)
2435 network->mode = IEEE_A;
2436 else {
2437 if (network->flags & NETWORK_HAS_OFDM)
2438 network->mode |= IEEE_G;
2439 if (network->flags & NETWORK_HAS_CCK)
2440 network->mode |= IEEE_B;
2441 }
2442
2443 if (network->mode == 0) {
2444 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2445 "network.\n",
2446 escape_essid(network->ssid,
2447 network->ssid_len),
2448 network->bssid);
2449 return 1;
2450 }
2451
2452 if(network->bssht.bdSupportHT){
2453 if(network->mode == IEEE_A)
2454 network->mode = IEEE_N_5G;
2455 else if(network->mode & (IEEE_G | IEEE_B))
2456 network->mode = IEEE_N_24G;
2457 }
2458 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2459 network->flags |= NETWORK_EMPTY_ESSID;
2460
2461#if 1
2462 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2463
2464 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2465#endif
2466
2467 memcpy(&network->stats, stats, sizeof(network->stats));
2468
2469 return 0;
2470}
2471
2472static inline int is_same_network(struct ieee80211_network *src,
2473 struct ieee80211_network *dst, struct ieee80211_device* ieee)
2474{
2475
2476
2477
2478
2479 return
2480 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2481 (src->channel == dst->channel) &&
2482 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2483
2484 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2485 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2486 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2487 ((src->capability & WLAN_CAPABILITY_BSS) ==
2488 (dst->capability & WLAN_CAPABILITY_BSS)));
2489}
2490
2491static inline void update_network(struct ieee80211_network *dst,
2492 struct ieee80211_network *src)
2493{
2494 int qos_active;
2495 u8 old_param;
2496
2497 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2498 dst->capability = src->capability;
2499 memcpy(dst->rates, src->rates, src->rates_len);
2500 dst->rates_len = src->rates_len;
2501 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2502 dst->rates_ex_len = src->rates_ex_len;
2503 if(src->ssid_len > 0)
2504 {
2505 memset(dst->ssid, 0, dst->ssid_len);
2506 dst->ssid_len = src->ssid_len;
2507 memcpy(dst->ssid, src->ssid, src->ssid_len);
2508 }
2509 dst->mode = src->mode;
2510 dst->flags = src->flags;
2511 dst->time_stamp[0] = src->time_stamp[0];
2512 dst->time_stamp[1] = src->time_stamp[1];
2513 if (src->flags & NETWORK_HAS_ERP_VALUE)
2514 {
2515 dst->erp_value = src->erp_value;
2516 dst->berp_info_valid = src->berp_info_valid = true;
2517 }
2518 dst->beacon_interval = src->beacon_interval;
2519 dst->listen_interval = src->listen_interval;
2520 dst->atim_window = src->atim_window;
2521 dst->dtim_period = src->dtim_period;
2522 dst->dtim_data = src->dtim_data;
2523 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2524 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2525 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2526
2527 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2528 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2529 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2530 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2531 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2532 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2533 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2534 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2535 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2536 dst->ralink_cap_exist = src->ralink_cap_exist;
2537 dst->atheros_cap_exist = src->atheros_cap_exist;
2538 dst->marvell_cap_exist = src->marvell_cap_exist;
2539 dst->cisco_cap_exist = src->cisco_cap_exist;
2540 dst->unknown_cap_exist = src->unknown_cap_exist;
2541 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2542 dst->wpa_ie_len = src->wpa_ie_len;
2543 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2544 dst->rsn_ie_len = src->rsn_ie_len;
2545
2546 dst->last_scanned = jiffies;
2547
2548
2549 qos_active = dst->qos_data.active;
2550
2551 old_param = dst->qos_data.param_count;
2552 if(dst->flags & NETWORK_HAS_QOS_MASK){
2553
2554
2555
2556
2557 }
2558 else {
2559 dst->qos_data.supported = src->qos_data.supported;
2560 dst->qos_data.param_count = src->qos_data.param_count;
2561 }
2562
2563 if(dst->qos_data.supported == 1) {
2564 dst->QoS_Enable = 1;
2565 if(dst->ssid_len)
2566 IEEE80211_DEBUG_QOS
2567 ("QoS the network %s is QoS supported\n",
2568 dst->ssid);
2569 else
2570 IEEE80211_DEBUG_QOS
2571 ("QoS the network is QoS supported\n");
2572 }
2573 dst->qos_data.active = qos_active;
2574 dst->qos_data.old_param_count = old_param;
2575
2576
2577#if 1
2578 dst->wmm_info = src->wmm_info;
2579 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2580 src->wmm_param[1].ac_aci_acm_aifsn|| \
2581 src->wmm_param[2].ac_aci_acm_aifsn|| \
2582 src->wmm_param[3].ac_aci_acm_aifsn) {
2583 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2584 }
2585
2586#else
2587 dst->QoS_Enable = 1;
2588#endif
2589#ifdef THOMAS_TURBO
2590 dst->Turbo_Enable = src->Turbo_Enable;
2591#endif
2592
2593#ifdef ENABLE_DOT11D
2594 dst->CountryIeLen = src->CountryIeLen;
2595 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2596#endif
2597
2598
2599 dst->bWithAironetIE = src->bWithAironetIE;
2600 dst->bCkipSupported = src->bCkipSupported;
2601 memcpy(dst->CcxRmState,src->CcxRmState,2);
2602 dst->bCcxRmEnable = src->bCcxRmEnable;
2603 dst->MBssidMask = src->MBssidMask;
2604 dst->bMBssidValid = src->bMBssidValid;
2605 memcpy(dst->MBssid,src->MBssid,6);
2606 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2607 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2608
2609}
2610
2611static inline int is_beacon(__le16 fc)
2612{
2613 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2614}
2615
2616static inline void ieee80211_process_probe_response(
2617 struct ieee80211_device *ieee,
2618 struct ieee80211_probe_response *beacon,
2619 struct ieee80211_rx_stats *stats)
2620{
2621 struct ieee80211_network network;
2622 struct ieee80211_network *target;
2623 struct ieee80211_network *oldest = NULL;
2624#ifdef CONFIG_IEEE80211_DEBUG
2625 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2626#endif
2627 unsigned long flags;
2628 short renew;
2629
2630
2631 memset(&network, 0, sizeof(struct ieee80211_network));
2632 IEEE80211_DEBUG_SCAN(
2633 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2634 escape_essid(info_element->data, info_element->len),
2635 beacon->header.addr3,
2636 (beacon->capability & (1<<0xf)) ? '1' : '0',
2637 (beacon->capability & (1<<0xe)) ? '1' : '0',
2638 (beacon->capability & (1<<0xd)) ? '1' : '0',
2639 (beacon->capability & (1<<0xc)) ? '1' : '0',
2640 (beacon->capability & (1<<0xb)) ? '1' : '0',
2641 (beacon->capability & (1<<0xa)) ? '1' : '0',
2642 (beacon->capability & (1<<0x9)) ? '1' : '0',
2643 (beacon->capability & (1<<0x8)) ? '1' : '0',
2644 (beacon->capability & (1<<0x7)) ? '1' : '0',
2645 (beacon->capability & (1<<0x6)) ? '1' : '0',
2646 (beacon->capability & (1<<0x5)) ? '1' : '0',
2647 (beacon->capability & (1<<0x4)) ? '1' : '0',
2648 (beacon->capability & (1<<0x3)) ? '1' : '0',
2649 (beacon->capability & (1<<0x2)) ? '1' : '0',
2650 (beacon->capability & (1<<0x1)) ? '1' : '0',
2651 (beacon->capability & (1<<0x0)) ? '1' : '0');
2652
2653 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2654 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2655 escape_essid(info_element->data,
2656 info_element->len),
2657 beacon->header.addr3,
2658 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2659 IEEE80211_STYPE_PROBE_RESP ?
2660 "PROBE RESPONSE" : "BEACON");
2661 return;
2662 }
2663
2664#ifdef ENABLE_DOT11D
2665
2666
2667
2668
2669
2670
2671
2672 if( !IsLegalChannel(ieee, network.channel) )
2673 return;
2674 if(ieee->bGlobalDomain)
2675 {
2676 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2677 {
2678
2679 if(IS_COUNTRY_IE_VALID(ieee) )
2680 {
2681 if( !IsLegalChannel(ieee, network.channel) )
2682 {
2683 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2684 return;
2685 }
2686 }
2687
2688 else
2689 {
2690
2691 if(network.channel > 11)
2692 {
2693 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2694 return;
2695 }
2696 }
2697 }
2698 else
2699 {
2700
2701 if(IS_COUNTRY_IE_VALID(ieee) )
2702 {
2703 if( !IsLegalChannel(ieee, network.channel) )
2704 {
2705 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2706 return;
2707 }
2708 }
2709
2710 else
2711 {
2712
2713 if(network.channel > 14)
2714 {
2715 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2716 return;
2717 }
2718 }
2719 }
2720 }
2721#endif
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733 spin_lock_irqsave(&ieee->lock, flags);
2734
2735 if(is_same_network(&ieee->current_network, &network, ieee)) {
2736 update_network(&ieee->current_network, &network);
2737 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2738 && ieee->current_network.berp_info_valid){
2739 if(ieee->current_network.erp_value& ERP_UseProtection)
2740 ieee->current_network.buseprotection = true;
2741 else
2742 ieee->current_network.buseprotection = false;
2743 }
2744 if(is_beacon(beacon->header.frame_ctl))
2745 {
2746 if(ieee->state == IEEE80211_LINKED)
2747 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2748 }
2749 else
2750 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2751 }
2752
2753 list_for_each_entry(target, &ieee->network_list, list) {
2754 if (is_same_network(target, &network, ieee))
2755 break;
2756 if ((oldest == NULL) ||
2757 (target->last_scanned < oldest->last_scanned))
2758 oldest = target;
2759 }
2760
2761
2762
2763 if (&target->list == &ieee->network_list) {
2764 if (list_empty(&ieee->network_free_list)) {
2765
2766 list_del(&oldest->list);
2767 target = oldest;
2768 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2769 "network list.\n",
2770 escape_essid(target->ssid,
2771 target->ssid_len),
2772 target->bssid);
2773 } else {
2774
2775 target = list_entry(ieee->network_free_list.next,
2776 struct ieee80211_network, list);
2777 list_del(ieee->network_free_list.next);
2778 }
2779
2780
2781#ifdef CONFIG_IEEE80211_DEBUG
2782 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2783 escape_essid(network.ssid,
2784 network.ssid_len),
2785 network.bssid,
2786 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2787 IEEE80211_STYPE_PROBE_RESP ?
2788 "PROBE RESPONSE" : "BEACON");
2789#endif
2790 memcpy(target, &network, sizeof(*target));
2791 list_add_tail(&target->list, &ieee->network_list);
2792 } else {
2793 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2794 escape_essid(target->ssid,
2795 target->ssid_len),
2796 target->bssid,
2797 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2798 IEEE80211_STYPE_PROBE_RESP ?
2799 "PROBE RESPONSE" : "BEACON");
2800
2801
2802
2803
2804
2805 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2806
2807 if(is_beacon(beacon->header.frame_ctl) == 0)
2808 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2809
2810
2811 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2812 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2813 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2814 renew = 1;
2815
2816
2817 update_network(target, &network);
2818 }
2819
2820 spin_unlock_irqrestore(&ieee->lock, flags);
2821 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2822 (ieee->state == IEEE80211_LINKED)) {
2823 if(ieee->handle_beacon != NULL) {
2824 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2825 }
2826 }
2827}
2828
2829void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2830 struct ieee80211_hdr_4addr *header,
2831 struct ieee80211_rx_stats *stats)
2832{
2833#if 0
2834 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2835 ieee->iw_mode == IW_MODE_INFRA &&
2836 ieee->state == IEEE80211_LINKED))
2837 {
2838 tasklet_schedule(&ieee->ps_task);
2839 }
2840#endif
2841
2842 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2843 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2844 ieee->last_rx_ps_time = jiffies;
2845
2846 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2847
2848 case IEEE80211_STYPE_BEACON:
2849 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2850 WLAN_FC_GET_STYPE(header->frame_ctl));
2851 IEEE80211_DEBUG_SCAN("Beacon\n");
2852 ieee80211_process_probe_response(
2853 ieee, (struct ieee80211_probe_response *)header, stats);
2854
2855
2856 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2857 ieee->iw_mode == IW_MODE_INFRA &&
2858 ieee->state == IEEE80211_LINKED))
2859 {
2860 tasklet_schedule(&ieee->ps_task);
2861 }
2862
2863 break;
2864
2865 case IEEE80211_STYPE_PROBE_RESP:
2866 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2867 WLAN_FC_GET_STYPE(header->frame_ctl));
2868 IEEE80211_DEBUG_SCAN("Probe response\n");
2869 ieee80211_process_probe_response(
2870 ieee, (struct ieee80211_probe_response *)header, stats);
2871 break;
2872
2873 }
2874}
2875