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