GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / rtl8192su / ieee80211 / ieee80211_rx.c
blob8a0d6a9eb13472f2438e07bf9eeb43c4e00af50f
1 /*
2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <jkmaline@cc.hut.fi>
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
13 * more details.
14 ******************************************************************************
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
19 A special thanks goes to Realtek for their support !
21 ******************************************************************************/
24 #include <linux/compiler.h>
25 //#include <linux/config.h>
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/wireless.h>
41 #include <linux/etherdevice.h>
42 #include <asm/uaccess.h>
43 #include <linux/ctype.h>
45 #include "ieee80211.h"
46 #include "dot11d.h"
47 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
48 struct sk_buff *skb,
49 struct ieee80211_rx_stats *rx_stats)
51 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *)skb->data;
52 u16 fc = le16_to_cpu(hdr->frame_ctl);
54 skb->dev = ieee->dev;
55 skb_reset_mac_header(skb);
57 skb_pull(skb, ieee80211_get_hdrlen(fc));
58 skb->pkt_type = PACKET_OTHERHOST;
59 skb->protocol = __constant_htons(ETH_P_80211_RAW);
60 memset(skb->cb, 0, sizeof(skb->cb));
61 netif_rx(skb);
65 /* Called only as a tasklet (software IRQ) */
66 static struct ieee80211_frag_entry *
67 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
68 unsigned int frag, u8 tid,u8 *src, u8 *dst)
70 struct ieee80211_frag_entry *entry;
71 int i;
73 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
74 entry = &ieee->frag_cache[tid][i];
75 if (entry->skb != NULL &&
76 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
77 IEEE80211_DEBUG_FRAG(
78 "expiring fragment cache entry "
79 "seq=%u last_frag=%u\n",
80 entry->seq, entry->last_frag);
81 dev_kfree_skb_any(entry->skb);
82 entry->skb = NULL;
85 if (entry->skb != NULL && entry->seq == seq &&
86 (entry->last_frag + 1 == frag || frag == -1) &&
87 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
88 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
89 return entry;
92 return NULL;
95 /* Called only as a tasklet (software IRQ) */
96 static struct sk_buff *
97 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
98 struct ieee80211_hdr_4addr *hdr)
100 struct sk_buff *skb = NULL;
101 u16 fc = le16_to_cpu(hdr->frame_ctl);
102 u16 sc = le16_to_cpu(hdr->seq_ctl);
103 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
104 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
105 struct ieee80211_frag_entry *entry;
106 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
107 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
108 u8 tid;
110 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
111 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
112 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
113 tid = UP2AC(tid);
114 tid ++;
115 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
116 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
117 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
118 tid = UP2AC(tid);
119 tid ++;
120 } else {
121 tid = 0;
124 if (frag == 0) {
125 /* Reserve enough space to fit maximum frame length */
126 skb = dev_alloc_skb(ieee->dev->mtu +
127 sizeof(struct ieee80211_hdr_4addr) +
128 8 /* LLC */ +
129 2 /* alignment */ +
130 8 /* WEP */ +
131 ETH_ALEN /* WDS */ +
132 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
133 if (skb == NULL)
134 return NULL;
136 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
137 ieee->frag_next_idx[tid]++;
138 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
139 ieee->frag_next_idx[tid] = 0;
141 if (entry->skb != NULL)
142 dev_kfree_skb_any(entry->skb);
144 entry->first_frag_time = jiffies;
145 entry->seq = seq;
146 entry->last_frag = frag;
147 entry->skb = skb;
148 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
149 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
150 } else {
151 /* received a fragment of a frame for which the head fragment
152 * should have already been received */
153 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
154 hdr->addr1);
155 if (entry != NULL) {
156 entry->last_frag = frag;
157 skb = entry->skb;
161 return skb;
165 /* Called only as a tasklet (software IRQ) */
166 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
167 struct ieee80211_hdr_4addr *hdr)
169 u16 fc = le16_to_cpu(hdr->frame_ctl);
170 u16 sc = le16_to_cpu(hdr->seq_ctl);
171 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
172 struct ieee80211_frag_entry *entry;
173 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
174 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
175 u8 tid;
177 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
178 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
179 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
180 tid = UP2AC(tid);
181 tid ++;
182 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
183 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
184 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
185 tid = UP2AC(tid);
186 tid ++;
187 } else {
188 tid = 0;
191 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
192 hdr->addr1);
194 if (entry == NULL) {
195 IEEE80211_DEBUG_FRAG(
196 "could not invalidate fragment cache "
197 "entry (seq=%u)\n", seq);
198 return -1;
201 entry->skb = NULL;
202 return 0;
207 /* ieee80211_rx_frame_mgtmt
209 * Responsible for handling management control frames
211 * Called by ieee80211_rtl_rx */
212 static inline int
213 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
214 struct ieee80211_rx_stats *rx_stats, u16 type,
215 u16 stype)
217 /* On the struct stats definition there is written that
218 * this is not mandatory.... but seems that the probe
219 * response parser uses it
221 struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data;
223 rx_stats->len = skb->len;
224 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
225 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
226 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames
228 dev_kfree_skb_any(skb);
229 return 0;
232 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
234 dev_kfree_skb_any(skb);
236 return 0;
242 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
243 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
244 static unsigned char rfc1042_header[] =
245 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
246 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
247 static unsigned char bridge_tunnel_header[] =
248 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
249 /* No encapsulation header if EtherType < 0x600 (=length) */
251 /* Called by ieee80211_rx_frame_decrypt */
252 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
253 struct sk_buff *skb, size_t hdrlen)
255 struct net_device *dev = ieee->dev;
256 u16 fc, ethertype;
257 struct ieee80211_hdr_4addr *hdr;
258 u8 *pos;
260 if (skb->len < 24)
261 return 0;
263 hdr = (struct ieee80211_hdr_4addr *) skb->data;
264 fc = le16_to_cpu(hdr->frame_ctl);
266 /* check that the frame is unicast frame to us */
267 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
268 IEEE80211_FCTL_TODS &&
269 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
270 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
271 /* ToDS frame with own addr BSSID and DA */
272 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
273 IEEE80211_FCTL_FROMDS &&
274 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
275 /* FromDS frame with own addr as DA */
276 } else
277 return 0;
279 if (skb->len < 24 + 8)
280 return 0;
282 /* check for port access entity Ethernet type */
283 // pos = skb->data + 24;
284 pos = skb->data + hdrlen;
285 ethertype = (pos[6] << 8) | pos[7];
286 if (ethertype == ETH_P_PAE)
287 return 1;
289 return 0;
292 /* Called only as a tasklet (software IRQ), by ieee80211_rtl_rx */
293 static inline int
294 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
295 struct ieee80211_crypt_data *crypt)
297 struct ieee80211_hdr_4addr *hdr;
298 int res, hdrlen;
300 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
301 return 0;
302 if (ieee->hwsec_active)
304 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
305 tcb_desc->bHwSec = 1;
307 hdr = (struct ieee80211_hdr_4addr *) skb->data;
308 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
310 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
311 if (ieee->tkip_countermeasures &&
312 strcmp(crypt->ops->name, "TKIP") == 0) {
313 if (net_ratelimit()) {
314 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
315 "received packet from %pM\n",
316 ieee->dev->name, hdr->addr2);
318 return -1;
320 #endif
322 atomic_inc(&crypt->refcnt);
323 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
324 atomic_dec(&crypt->refcnt);
325 if (res < 0) {
326 IEEE80211_DEBUG_DROP(
327 "decryption failed (SA=%pM"
328 ") res=%d\n", hdr->addr2, res);
329 if (res == -2)
330 IEEE80211_DEBUG_DROP("Decryption failed ICV "
331 "mismatch (key %d)\n",
332 skb->data[hdrlen + 3] >> 6);
333 ieee->ieee_stats.rx_discards_undecryptable++;
334 return -1;
337 return res;
341 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
342 static inline int
343 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
344 int keyidx, struct ieee80211_crypt_data *crypt)
346 struct ieee80211_hdr_4addr *hdr;
347 int res, hdrlen;
349 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
350 return 0;
351 if (ieee->hwsec_active)
353 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
354 tcb_desc->bHwSec = 1;
357 hdr = (struct ieee80211_hdr_4addr *) skb->data;
358 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
360 atomic_inc(&crypt->refcnt);
361 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv,ieee);
362 atomic_dec(&crypt->refcnt);
363 if (res < 0) {
364 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
365 " (SA=%pM keyidx=%d)\n",
366 ieee->dev->name, hdr->addr2, keyidx);
367 return -1;
370 return 0;
374 /* this function is stolen from ipw2200 driver*/
375 #define IEEE_PACKET_RETRY_TIME (5*HZ)
376 static int is_duplicate_packet(struct ieee80211_device *ieee,
377 struct ieee80211_hdr_4addr *header)
379 u16 fc = le16_to_cpu(header->frame_ctl);
380 u16 sc = le16_to_cpu(header->seq_ctl);
381 u16 seq = WLAN_GET_SEQ_SEQ(sc);
382 u16 frag = WLAN_GET_SEQ_FRAG(sc);
383 u16 *last_seq, *last_frag;
384 unsigned long *last_time;
385 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
386 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
387 u8 tid;
390 //TO2DS and QoS
391 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
392 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
393 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
394 tid = UP2AC(tid);
395 tid ++;
396 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
397 hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
398 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
399 tid = UP2AC(tid);
400 tid ++;
401 } else { // no QoS
402 tid = 0;
405 switch (ieee->iw_mode) {
406 case IW_MODE_ADHOC:
408 struct list_head *p;
409 struct ieee_ibss_seq *entry = NULL;
410 u8 *mac = header->addr2;
411 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
412 //for (pos = (head)->next; pos != (head); pos = pos->next)
413 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
414 list_for_each(p, &ieee->ibss_mac_hash[index]) {
415 entry = list_entry(p, struct ieee_ibss_seq, list);
416 if (!memcmp(entry->mac, mac, ETH_ALEN))
417 break;
419 // if (memcmp(entry->mac, mac, ETH_ALEN)){
420 if (p == &ieee->ibss_mac_hash[index]) {
421 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
422 if (!entry) {
423 printk(KERN_WARNING "Cannot malloc new mac entry\n");
424 return 0;
426 memcpy(entry->mac, mac, ETH_ALEN);
427 entry->seq_num[tid] = seq;
428 entry->frag_num[tid] = frag;
429 entry->packet_time[tid] = jiffies;
430 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
431 return 0;
433 last_seq = &entry->seq_num[tid];
434 last_frag = &entry->frag_num[tid];
435 last_time = &entry->packet_time[tid];
436 break;
439 case IW_MODE_INFRA:
440 last_seq = &ieee->last_rxseq_num[tid];
441 last_frag = &ieee->last_rxfrag_num[tid];
442 last_time = &ieee->last_packet_time[tid];
444 break;
445 default:
446 return 0;
449 // if(tid != 0) {
450 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
451 // }
452 if ((*last_seq == seq) &&
453 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
454 if (*last_frag == frag){
455 //printk(KERN_WARNING "[1] go drop!\n");
456 goto drop;
459 if (*last_frag + 1 != frag)
460 /* out-of-order fragment */
461 //printk(KERN_WARNING "[2] go drop!\n");
462 goto drop;
463 } else
464 *last_seq = seq;
466 *last_frag = frag;
467 *last_time = jiffies;
468 return 0;
470 drop:
471 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
472 // printk("DUP\n");
474 return 1;
476 bool
477 AddReorderEntry(
478 PRX_TS_RECORD pTS,
479 PRX_REORDER_ENTRY pReorderEntry
482 struct list_head *pList = &pTS->RxPendingPktList;
483 while(pList->next != &pTS->RxPendingPktList)
485 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
487 pList = pList->next;
489 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
491 return false;
493 else
495 break;
498 pReorderEntry->List.next = pList->next;
499 pReorderEntry->List.next->prev = &pReorderEntry->List;
500 pReorderEntry->List.prev = pList;
501 pList->next = &pReorderEntry->List;
503 return true;
506 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index)
508 u8 i = 0 , j=0;
509 u16 ethertype;
510 // if(index > 1)
511 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
512 for(j = 0; j<index; j++)
514 //added by amy for reorder
515 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
516 for(i = 0; i<prxb->nr_subframes; i++) {
517 struct sk_buff *sub_skb = prxb->subframes[i];
519 /* convert hdr + possible LLC headers into Ethernet header */
520 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
521 if (sub_skb->len >= 8 &&
522 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
523 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
524 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
525 /* remove RFC1042 or Bridge-Tunnel encapsulation and
526 * replace EtherType */
527 skb_pull(sub_skb, SNAP_SIZE);
528 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
529 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
530 } else {
531 u16 len;
532 /* Leave Ethernet header part of hdr and full payload */
533 len = htons(sub_skb->len);
534 memcpy(skb_push(sub_skb, 2), &len, 2);
535 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
536 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
538 //stats->rx_packets++;
539 //stats->rx_bytes += sub_skb->len;
541 /* Indicat the packets to upper layer */
542 if (sub_skb) {
543 //printk("0skb_len(%d)\n", skb->len);
544 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
545 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
546 sub_skb->dev = ieee->dev;
547 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
548 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
549 ieee->last_rx_ps_time = jiffies;
550 //printk("1skb_len(%d)\n", skb->len);
551 netif_rx(sub_skb);
554 kfree(prxb);
555 prxb = NULL;
560 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
561 struct ieee80211_rxb* prxb,
562 PRX_TS_RECORD pTS,
563 u16 SeqNum)
565 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
566 PRX_REORDER_ENTRY pReorderEntry = NULL;
567 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
568 u8 WinSize = pHTInfo->RxReorderWinSize;
569 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
570 u8 index = 0;
571 bool bMatchWinStart = false, bPktInBuf = false;
572 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
573 /* Rx Reorder initialize condition.*/
574 if(pTS->RxIndicateSeq == 0xffff) {
575 pTS->RxIndicateSeq = SeqNum;
578 /* Drop out the packet which SeqNum is smaller than WinStart */
579 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
580 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
581 pTS->RxIndicateSeq, SeqNum);
582 pHTInfo->RxReorderDropCounter++;
584 int i;
585 for(i =0; i < prxb->nr_subframes; i++) {
586 dev_kfree_skb(prxb->subframes[i]);
588 kfree(prxb);
589 prxb = NULL;
591 return;
595 * Sliding window manipulation. Conditions includes:
596 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
597 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
599 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
600 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
601 bMatchWinStart = true;
602 } else if(SN_LESS(WinEnd, SeqNum)) {
603 if(SeqNum >= (WinSize - 1)) {
604 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
605 } else {
606 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
608 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
612 * Indication process.
613 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
614 * with the SeqNum smaller than latest WinStart and buffer other packets.
616 /* For Rx Reorder condition:
617 * 1. All packets with SeqNum smaller than WinStart => Indicate
618 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
620 if(bMatchWinStart) {
621 /* Current packet is going to be indicated.*/
622 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
623 pTS->RxIndicateSeq, SeqNum);
624 prxbIndicateArray[0] = prxb;
625 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
626 index = 1;
627 } else {
628 /* Current packet is going to be inserted into pending list.*/
629 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
630 if(!list_empty(&ieee->RxReorder_Unused_List)) {
631 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
632 list_del_init(&pReorderEntry->List);
634 /* Make a reorder entry and insert into a the packet list.*/
635 pReorderEntry->SeqNum = SeqNum;
636 pReorderEntry->prxb = prxb;
637 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
639 if(!AddReorderEntry(pTS, pReorderEntry)) {
640 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
641 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
642 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
644 int i;
645 for(i =0; i < prxb->nr_subframes; i++) {
646 dev_kfree_skb(prxb->subframes[i]);
648 kfree(prxb);
649 prxb = NULL;
651 } else {
652 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
653 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
656 else {
658 * Packets are dropped if there is not enough reorder entries.
659 * This part shall be modified!! We can just indicate all the
660 * packets in buffer and get reorder entries.
662 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
664 int i;
665 for(i =0; i < prxb->nr_subframes; i++) {
666 dev_kfree_skb(prxb->subframes[i]);
668 kfree(prxb);
669 prxb = NULL;
674 /* Check if there is any packet need indicate.*/
675 while(!list_empty(&pTS->RxPendingPktList)) {
676 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
677 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
678 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
679 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
681 /* This protect buffer from overflow. */
682 if(index >= REORDER_WIN_SIZE) {
683 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
684 bPktInBuf = true;
685 break;
688 list_del_init(&pReorderEntry->List);
690 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
691 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
693 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
694 prxbIndicateArray[index] = pReorderEntry->prxb;
695 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
696 index++;
698 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
699 } else {
700 bPktInBuf = true;
701 break;
705 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
706 if(index>0) {
707 // Cancel previous pending timer.
708 if(timer_pending(&pTS->RxPktPendingTimer))
710 del_timer_sync(&pTS->RxPktPendingTimer);
712 // del_timer_sync(&pTS->RxPktPendingTimer);
713 pTS->RxTimeoutIndicateSeq = 0xffff;
715 // Indicate packets
716 if(index>REORDER_WIN_SIZE){
717 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
718 return;
720 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
721 bPktInBuf = false;
724 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
725 // Set new pending timer.
726 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
727 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
728 mod_timer(&pTS->RxPktPendingTimer, jiffies + MSECS(pHTInfo->RxReorderPendingTime));
732 u8 parse_subframe(struct sk_buff *skb,
733 struct ieee80211_rx_stats *rx_stats,
734 struct ieee80211_rxb *rxb,u8* src,u8* dst)
736 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
737 u16 fc = le16_to_cpu(hdr->frame_control);
739 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
740 u16 ChkLength;
741 bool bIsAggregateFrame = false;
742 u16 nSubframe_Length;
743 u8 nPadding_Length = 0;
744 u16 SeqNum=0;
746 struct sk_buff *sub_skb;
747 u8 *data_ptr;
748 /* just for debug purpose */
749 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctrl));
751 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
752 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
753 bIsAggregateFrame = true;
756 if(IEEE80211_QOS_HAS_SEQ(fc)) {
757 LLCOffset += 2;
760 if(rx_stats->bContainHTC) {
761 LLCOffset += sHTCLng;
763 //printk("ChkLength = %d\n", LLCOffset);
764 // Null packet, don't indicate it to upper layer
765 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
767 if( skb->len <= ChkLength ) {
768 return 0;
771 skb_pull(skb, LLCOffset);
773 if(!bIsAggregateFrame) {
774 rxb->nr_subframes = 1;
775 #ifdef JOHN_NOCPY
776 rxb->subframes[0] = skb;
777 #else
778 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
779 #endif
781 memcpy(rxb->src,src,ETH_ALEN);
782 memcpy(rxb->dst,dst,ETH_ALEN);
783 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
784 return 1;
785 } else {
786 rxb->nr_subframes = 0;
787 memcpy(rxb->src,src,ETH_ALEN);
788 memcpy(rxb->dst,dst,ETH_ALEN);
789 while(skb->len > ETHERNET_HEADER_SIZE) {
790 /* Offset 12 denote 2 mac address */
791 nSubframe_Length = *((u16*)(skb->data + 12));
792 //==m==>change the length order
793 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
795 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
796 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
797 __FUNCTION__,rxb->nr_subframes);
798 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
799 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
800 printk("The Packet SeqNum is %d\n",SeqNum);
801 return 0;
804 /* move the data point to data content */
805 skb_pull(skb, ETHERNET_HEADER_SIZE);
807 #ifdef JOHN_NOCPY
808 sub_skb = skb_clone(skb, GFP_ATOMIC);
809 sub_skb->len = nSubframe_Length;
810 sub_skb->tail = sub_skb->data + nSubframe_Length;
811 #else
812 /* Allocate new skb for releasing to upper layer */
813 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
814 skb_reserve(sub_skb, 12);
815 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
816 memcpy(data_ptr,skb->data,nSubframe_Length);
817 #endif
818 rxb->subframes[rxb->nr_subframes++] = sub_skb;
819 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
820 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
821 break;
823 skb_pull(skb,nSubframe_Length);
825 if(skb->len != 0) {
826 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
827 if(nPadding_Length == 4) {
828 nPadding_Length = 0;
831 if(skb->len < nPadding_Length) {
832 return 0;
835 skb_pull(skb,nPadding_Length);
838 #ifdef JOHN_NOCPY
839 dev_kfree_skb(skb);
840 #endif
841 //{just for debug added by david
842 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
844 return rxb->nr_subframes;
848 /* All received frames are sent to this function. @skb contains the frame in
849 * IEEE 802.11 format, i.e., in the format it was sent over air.
850 * This function is called only as a tasklet (software IRQ). */
851 int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
852 struct ieee80211_rx_stats *rx_stats)
854 struct net_device *dev = ieee->dev;
855 struct ieee80211_hdr_4addr *hdr;
856 //struct ieee80211_hdr_3addrqos *hdr;
858 size_t hdrlen;
859 u16 fc, type, stype, sc;
860 struct net_device_stats *stats;
861 unsigned int frag;
862 u8 *payload;
863 u16 ethertype;
864 //added by amy for reorder
865 u8 TID = 0;
866 u16 SeqNum = 0;
867 PRX_TS_RECORD pTS = NULL;
868 //bool bIsAggregateFrame = false;
869 //added by amy for reorder
870 // u16 qos_ctl = 0;
871 u8 dst[ETH_ALEN];
872 u8 src[ETH_ALEN];
873 u8 bssid[ETH_ALEN];
874 struct ieee80211_crypt_data *crypt = NULL;
875 int keyidx = 0;
877 int i;
878 struct ieee80211_rxb* rxb = NULL;
879 // cheat the the hdr type
880 hdr = (struct ieee80211_hdr_4addr *)skb->data;
881 stats = &ieee->stats;
883 if (skb->len < 10) {
884 printk(KERN_INFO "%s: SKB length < 10\n",
885 dev->name);
886 goto rx_dropped;
889 fc = le16_to_cpu(hdr->frame_ctl);
890 type = WLAN_FC_GET_TYPE(fc);
891 stype = WLAN_FC_GET_STYPE(fc);
892 sc = le16_to_cpu(hdr->seq_ctl);
894 frag = WLAN_GET_SEQ_FRAG(sc);
895 hdrlen = ieee80211_get_hdrlen(fc);
897 if(HTCCheck(ieee, skb->data))
899 if(net_ratelimit())
900 printk("find HTCControl\n");
901 hdrlen += 4;
902 rx_stats->bContainHTC = 1;
905 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
907 if (ieee->iw_mode == IW_MODE_MONITOR) {
908 ieee80211_monitor_rx(ieee, skb, rx_stats);
909 stats->rx_packets++;
910 stats->rx_bytes += skb->len;
911 return 1;
914 if (ieee->host_decrypt) {
915 int idx = 0;
916 if (skb->len >= hdrlen + 3)
917 idx = skb->data[hdrlen + 3] >> 6;
918 crypt = ieee->crypt[idx];
920 /* allow NULL decrypt to indicate an station specific override
921 * for default encryption */
922 if (crypt && (crypt->ops == NULL ||
923 crypt->ops->decrypt_mpdu == NULL))
924 crypt = NULL;
926 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
927 /* This seems to be triggered by some (multicast?)
928 * frames from other than current BSS, so just drop the
929 * frames silently instead of filling system log with
930 * these reports. */
931 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
932 " (SA=%pM)\n",
933 hdr->addr2);
934 ieee->ieee_stats.rx_discards_undecryptable++;
935 goto rx_dropped;
939 if (skb->len < IEEE80211_DATA_HDR3_LEN)
940 goto rx_dropped;
942 // if QoS enabled, should check the sequence for each of the AC
943 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
944 if (is_duplicate_packet(ieee, hdr))
945 goto rx_dropped;
948 else
950 PRX_TS_RECORD pRxTS = NULL;
951 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
952 if(GetTs(
953 ieee,
954 (PTS_COMMON_INFO*) &pRxTS,
955 hdr->addr2,
956 (u8)Frame_QoSTID((u8*)(skb->data)),
957 RX_DIR,
958 true))
961 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__FUNCTION__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc));
962 if( (fc & (1<<11)) &&
963 (frag == pRxTS->RxLastFragNum) &&
964 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
966 goto rx_dropped;
968 else
970 pRxTS->RxLastFragNum = frag;
971 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
974 else
976 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
977 goto rx_dropped;
980 if (type == IEEE80211_FTYPE_MGMT) {
982 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
983 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
984 goto rx_dropped;
985 else
986 goto rx_exit;
989 /* Data frame - extract src/dst addresses */
990 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
991 case IEEE80211_FCTL_FROMDS:
992 memcpy(dst, hdr->addr1, ETH_ALEN);
993 memcpy(src, hdr->addr3, ETH_ALEN);
994 memcpy(bssid, hdr->addr2, ETH_ALEN);
995 break;
996 case IEEE80211_FCTL_TODS:
997 memcpy(dst, hdr->addr3, ETH_ALEN);
998 memcpy(src, hdr->addr2, ETH_ALEN);
999 memcpy(bssid, hdr->addr1, ETH_ALEN);
1000 break;
1001 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1002 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1003 goto rx_dropped;
1004 memcpy(dst, hdr->addr3, ETH_ALEN);
1005 memcpy(src, hdr->addr4, ETH_ALEN);
1006 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1007 break;
1008 case 0:
1009 memcpy(dst, hdr->addr1, ETH_ALEN);
1010 memcpy(src, hdr->addr2, ETH_ALEN);
1011 memcpy(bssid, hdr->addr3, ETH_ALEN);
1012 break;
1016 dev->last_rx = jiffies;
1018 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1019 /* Nullfunc frames may have PS-bit set, so they must be passed to
1020 * hostap_handle_sta_rx() before being dropped here. */
1021 if (stype != IEEE80211_STYPE_DATA &&
1022 stype != IEEE80211_STYPE_DATA_CFACK &&
1023 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1024 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1025 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1027 if (stype != IEEE80211_STYPE_NULLFUNC)
1028 IEEE80211_DEBUG_DROP(
1029 "RX: dropped data frame "
1030 "with no data (type=0x%02x, "
1031 "subtype=0x%02x, len=%d)\n",
1032 type, stype, skb->len);
1033 goto rx_dropped;
1035 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1036 goto rx_dropped;
1038 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1040 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1041 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1043 printk("decrypt frame error\n");
1044 goto rx_dropped;
1048 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1050 /* skb: hdr + (possibly fragmented) plaintext payload */
1051 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1052 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1053 int flen;
1054 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1055 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1057 if (!frag_skb) {
1058 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1059 "Rx cannot get skb from fragment "
1060 "cache (morefrag=%d seq=%u frag=%u)\n",
1061 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1062 WLAN_GET_SEQ_SEQ(sc), frag);
1063 goto rx_dropped;
1065 flen = skb->len;
1066 if (frag != 0)
1067 flen -= hdrlen;
1069 if (frag_skb->tail + flen > frag_skb->end) {
1070 printk(KERN_WARNING "%s: host decrypted and "
1071 "reassembled frame did not fit skb\n",
1072 dev->name);
1073 ieee80211_frag_cache_invalidate(ieee, hdr);
1074 goto rx_dropped;
1077 if (frag == 0) {
1078 /* copy first fragment (including full headers) into
1079 * beginning of the fragment cache skb */
1080 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1081 } else {
1082 /* append frame payload to the end of the fragment
1083 * cache skb */
1084 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1085 flen);
1087 dev_kfree_skb_any(skb);
1088 skb = NULL;
1090 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1091 /* more fragments expected - leave the skb in fragment
1092 * cache for now; it will be delivered to upper layers
1093 * after all fragments have been received */
1094 goto rx_exit;
1097 /* this was the last fragment and the frame will be
1098 * delivered, so remove skb from fragment cache */
1099 skb = frag_skb;
1100 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1101 ieee80211_frag_cache_invalidate(ieee, hdr);
1104 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1105 * encrypted/authenticated */
1106 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1107 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1109 printk("==>decrypt msdu error\n");
1110 goto rx_dropped;
1113 //added by amy for AP roaming
1114 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1115 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1117 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1118 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1119 if (/*ieee->ieee802_1x &&*/
1120 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1122 #ifdef CONFIG_IEEE80211_DEBUG
1123 /* pass unencrypted EAPOL frames even if encryption is
1124 * configured */
1125 struct eapol *eap = (struct eapol *)(skb->data +
1126 24);
1127 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1128 eap_get_type(eap->type));
1129 #endif
1130 } else {
1131 IEEE80211_DEBUG_DROP(
1132 "encryption configured, but RX "
1133 "frame not encrypted (SA=%pM)\n",
1134 hdr->addr2);
1135 goto rx_dropped;
1139 #ifdef CONFIG_IEEE80211_DEBUG
1140 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1141 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1142 struct eapol *eap = (struct eapol *)(skb->data +
1143 24);
1144 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1145 eap_get_type(eap->type));
1147 #endif
1149 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1150 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1151 IEEE80211_DEBUG_DROP(
1152 "dropped unencrypted RX data "
1153 "frame from %pM"
1154 " (drop_unencrypted=1)\n",
1155 hdr->addr2);
1156 goto rx_dropped;
1159 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1160 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1163 //added by amy for reorder
1164 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1165 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1167 TID = Frame_QoSTID(skb->data);
1168 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1169 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1170 if(TID !=0 && TID !=3)
1172 ieee->bis_any_nonbepkts = true;
1175 //added by amy for reorder
1176 /* skb: hdr + (possible reassembled) full plaintext payload */
1177 payload = skb->data + hdrlen;
1178 //ethertype = (payload[6] << 8) | payload[7];
1179 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1180 if(rxb == NULL)
1182 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1183 goto rx_dropped;
1185 /* to parse amsdu packets */
1186 /* qos data packets & reserved bit is 1 */
1187 if(parse_subframe(skb,rx_stats,rxb,src,dst) == 0) {
1188 /* only to free rxb, and not submit the packets to upper layer */
1189 for(i =0; i < rxb->nr_subframes; i++) {
1190 dev_kfree_skb(rxb->subframes[i]);
1192 kfree(rxb);
1193 rxb = NULL;
1194 goto rx_dropped;
1197 ieee->last_rx_ps_time = jiffies;
1198 //added by amy for reorder
1199 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1200 //added by amy for reorder
1201 for(i = 0; i<rxb->nr_subframes; i++) {
1202 struct sk_buff *sub_skb = rxb->subframes[i];
1204 if (sub_skb) {
1205 /* convert hdr + possible LLC headers into Ethernet header */
1206 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1207 if (sub_skb->len >= 8 &&
1208 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1209 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1210 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1211 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1212 * replace EtherType */
1213 skb_pull(sub_skb, SNAP_SIZE);
1214 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1215 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1216 } else {
1217 u16 len;
1218 /* Leave Ethernet header part of hdr and full payload */
1219 len = htons(sub_skb->len);
1220 memcpy(skb_push(sub_skb, 2), &len, 2);
1221 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1222 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1225 stats->rx_packets++;
1226 stats->rx_bytes += sub_skb->len;
1227 if(is_multicast_ether_addr(dst)) {
1228 stats->multicast++;
1231 /* Indicat the packets to upper layer */
1232 //printk("0skb_len(%d)\n", skb->len);
1233 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1234 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1235 sub_skb->dev = dev;
1236 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1237 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1238 //printk("1skb_len(%d)\n", skb->len);
1239 netif_rx(sub_skb);
1242 kfree(rxb);
1243 rxb = NULL;
1246 else
1248 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1249 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1251 #ifndef JOHN_NOCPY
1252 dev_kfree_skb(skb);
1253 #endif
1255 rx_exit:
1256 return 1;
1258 rx_dropped:
1259 if (rxb != NULL)
1261 kfree(rxb);
1262 rxb = NULL;
1264 stats->rx_dropped++;
1266 /* Returning 0 indicates to caller that we have not handled the SKB--
1267 * so it is still allocated and can be used again by underlying
1268 * hardware as a DMA target */
1269 return 0;
1272 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1274 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1277 * Make ther structure we read from the beacon packet has
1278 * the right values
1280 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1281 *info_element, int sub_type)
1284 if (info_element->qui_subtype != sub_type)
1285 return -1;
1286 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1287 return -1;
1288 if (info_element->qui_type != QOS_OUI_TYPE)
1289 return -1;
1290 if (info_element->version != QOS_VERSION_1)
1291 return -1;
1293 return 0;
1298 * Parse a QoS parameter element
1300 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1301 *element_param, struct ieee80211_info_element
1302 *info_element)
1304 int ret = 0;
1305 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1307 if ((info_element == NULL) || (element_param == NULL))
1308 return -1;
1310 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1311 memcpy(element_param->info_element.qui, info_element->data,
1312 info_element->len);
1313 element_param->info_element.elementID = info_element->id;
1314 element_param->info_element.length = info_element->len;
1315 } else
1316 ret = -1;
1317 if (ret == 0)
1318 ret = ieee80211_verify_qos_info(&element_param->info_element,
1319 QOS_OUI_PARAM_SUB_TYPE);
1320 return ret;
1324 * Parse a QoS information element
1326 static int ieee80211_read_qos_info_element(struct
1327 ieee80211_qos_information_element
1328 *element_info, struct ieee80211_info_element
1329 *info_element)
1331 int ret = 0;
1332 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1334 if (element_info == NULL)
1335 return -1;
1336 if (info_element == NULL)
1337 return -1;
1339 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1340 memcpy(element_info->qui, info_element->data,
1341 info_element->len);
1342 element_info->elementID = info_element->id;
1343 element_info->length = info_element->len;
1344 } else
1345 ret = -1;
1347 if (ret == 0)
1348 ret = ieee80211_verify_qos_info(element_info,
1349 QOS_OUI_INFO_SUB_TYPE);
1350 return ret;
1355 * Write QoS parameters from the ac parameters.
1357 static int ieee80211_qos_convert_ac_to_parameters(struct
1358 ieee80211_qos_parameter_info
1359 *param_elm, struct
1360 ieee80211_qos_parameters
1361 *qos_param)
1363 int rc = 0;
1364 int i;
1365 struct ieee80211_qos_ac_parameter *ac_params;
1366 u8 aci;
1367 //u8 cw_min;
1368 //u8 cw_max;
1370 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1371 ac_params = &(param_elm->ac_params_record[i]);
1373 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1375 if(aci >= QOS_QUEUE_NUM)
1376 continue;
1377 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1379 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1380 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1382 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1384 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1386 qos_param->flag[aci] =
1387 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1388 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1390 return rc;
1394 * we have a generic data element which it may contain QoS information or
1395 * parameters element. check the information element length to decide
1396 * which type to read
1398 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1399 *info_element,
1400 struct ieee80211_network *network)
1402 int rc = 0;
1403 struct ieee80211_qos_parameters *qos_param = NULL;
1404 struct ieee80211_qos_information_element qos_info_element;
1406 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1408 if (rc == 0) {
1409 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1410 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1411 } else {
1412 struct ieee80211_qos_parameter_info param_element;
1414 rc = ieee80211_read_qos_param_element(&param_element,
1415 info_element);
1416 if (rc == 0) {
1417 qos_param = &(network->qos_data.parameters);
1418 ieee80211_qos_convert_ac_to_parameters(&param_element,
1419 qos_param);
1420 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1421 network->qos_data.param_count =
1422 param_element.info_element.ac_info & 0x0F;
1426 if (rc == 0) {
1427 IEEE80211_DEBUG_QOS("QoS is supported\n");
1428 network->qos_data.supported = 1;
1430 return rc;
1433 #ifdef CONFIG_IEEE80211_DEBUG
1434 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1436 static const char *get_info_element_string(u16 id)
1438 switch (id) {
1439 MFIE_STRING(SSID);
1440 MFIE_STRING(RATES);
1441 MFIE_STRING(FH_SET);
1442 MFIE_STRING(DS_SET);
1443 MFIE_STRING(CF_SET);
1444 MFIE_STRING(TIM);
1445 MFIE_STRING(IBSS_SET);
1446 MFIE_STRING(COUNTRY);
1447 MFIE_STRING(HOP_PARAMS);
1448 MFIE_STRING(HOP_TABLE);
1449 MFIE_STRING(REQUEST);
1450 MFIE_STRING(CHALLENGE);
1451 MFIE_STRING(POWER_CONSTRAINT);
1452 MFIE_STRING(POWER_CAPABILITY);
1453 MFIE_STRING(TPC_REQUEST);
1454 MFIE_STRING(TPC_REPORT);
1455 MFIE_STRING(SUPP_CHANNELS);
1456 MFIE_STRING(CSA);
1457 MFIE_STRING(MEASURE_REQUEST);
1458 MFIE_STRING(MEASURE_REPORT);
1459 MFIE_STRING(QUIET);
1460 MFIE_STRING(IBSS_DFS);
1461 // MFIE_STRING(ERP_INFO);
1462 MFIE_STRING(RSN);
1463 MFIE_STRING(RATES_EX);
1464 MFIE_STRING(GENERIC);
1465 MFIE_STRING(QOS_PARAMETER);
1466 default:
1467 return "UNKNOWN";
1470 #endif
1472 static inline void ieee80211_extract_country_ie(
1473 struct ieee80211_device *ieee,
1474 struct ieee80211_info_element *info_element,
1475 struct ieee80211_network *network,
1476 u8 * addr2
1479 if(IS_DOT11D_ENABLE(ieee))
1481 if(info_element->len!= 0)
1483 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1484 network->CountryIeLen = info_element->len;
1486 if(!IS_COUNTRY_IE_VALID(ieee))
1488 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1493 // 070305, rcnjko: I update country IE watch dog here because
1494 // some AP (e.g. Cisco 1242) don't include country IE in their
1495 // probe response frame.
1497 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1499 UPDATE_CIE_WATCHDOG(ieee);
1505 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1506 struct ieee80211_info_element *info_element,
1507 u16 length,
1508 struct ieee80211_network *network,
1509 struct ieee80211_rx_stats *stats)
1511 u8 i;
1512 short offset;
1513 u16 tmp_htcap_len=0;
1514 u16 tmp_htinfo_len=0;
1515 u16 ht_realtek_agg_len=0;
1516 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1517 // u16 broadcom_len = 0;
1518 #ifdef CONFIG_IEEE80211_DEBUG
1519 char rates_str[64];
1520 char *p;
1521 #endif
1523 while (length >= sizeof(*info_element)) {
1524 if (sizeof(*info_element) + info_element->len > length) {
1525 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1526 "info_element->len + 2 > left : "
1527 "info_element->len+2=%zd left=%d, id=%d.\n",
1528 info_element->len +
1529 sizeof(*info_element),
1530 length, info_element->id);
1531 /* We stop processing but don't return an error here
1532 * because some misbehaviour APs break this rule. ie.
1533 * Orinoco AP1000. */
1534 break;
1537 switch (info_element->id) {
1538 case MFIE_TYPE_SSID:
1539 if (ieee80211_is_empty_essid(info_element->data,
1540 info_element->len)) {
1541 network->flags |= NETWORK_EMPTY_ESSID;
1542 break;
1545 network->ssid_len = min(info_element->len,
1546 (u8) IW_ESSID_MAX_SIZE);
1547 memcpy(network->ssid, info_element->data, network->ssid_len);
1548 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1549 memset(network->ssid + network->ssid_len, 0,
1550 IW_ESSID_MAX_SIZE - network->ssid_len);
1552 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1553 network->ssid, network->ssid_len);
1554 break;
1556 case MFIE_TYPE_RATES:
1557 #ifdef CONFIG_IEEE80211_DEBUG
1558 p = rates_str;
1559 #endif
1560 network->rates_len = min(info_element->len,
1561 MAX_RATES_LENGTH);
1562 for (i = 0; i < network->rates_len; i++) {
1563 network->rates[i] = info_element->data[i];
1564 #ifdef CONFIG_IEEE80211_DEBUG
1565 p += snprintf(p, sizeof(rates_str) -
1566 (p - rates_str), "%02X ",
1567 network->rates[i]);
1568 #endif
1569 if (ieee80211_is_ofdm_rate
1570 (info_element->data[i])) {
1571 network->flags |= NETWORK_HAS_OFDM;
1572 if (info_element->data[i] &
1573 IEEE80211_BASIC_RATE_MASK)
1574 network->flags &=
1575 ~NETWORK_HAS_CCK;
1579 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1580 rates_str, network->rates_len);
1581 break;
1583 case MFIE_TYPE_RATES_EX:
1584 #ifdef CONFIG_IEEE80211_DEBUG
1585 p = rates_str;
1586 #endif
1587 network->rates_ex_len = min(info_element->len,
1588 MAX_RATES_EX_LENGTH);
1589 for (i = 0; i < network->rates_ex_len; i++) {
1590 network->rates_ex[i] = info_element->data[i];
1591 #ifdef CONFIG_IEEE80211_DEBUG
1592 p += snprintf(p, sizeof(rates_str) -
1593 (p - rates_str), "%02X ",
1594 network->rates[i]);
1595 #endif
1596 if (ieee80211_is_ofdm_rate
1597 (info_element->data[i])) {
1598 network->flags |= NETWORK_HAS_OFDM;
1599 if (info_element->data[i] &
1600 IEEE80211_BASIC_RATE_MASK)
1601 network->flags &=
1602 ~NETWORK_HAS_CCK;
1606 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1607 rates_str, network->rates_ex_len);
1608 break;
1610 case MFIE_TYPE_DS_SET:
1611 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1612 info_element->data[0]);
1613 network->channel = info_element->data[0];
1614 break;
1616 case MFIE_TYPE_FH_SET:
1617 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1618 break;
1620 case MFIE_TYPE_CF_SET:
1621 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1622 break;
1624 case MFIE_TYPE_TIM:
1625 if(info_element->len < 4)
1626 break;
1628 network->tim.tim_count = info_element->data[0];
1629 network->tim.tim_period = info_element->data[1];
1631 network->dtim_period = info_element->data[1];
1632 if(ieee->state != IEEE80211_LINKED)
1633 break;
1634 //we use jiffies for legacy Power save
1635 network->last_dtim_sta_time[0] = jiffies;
1636 network->last_dtim_sta_time[1] = stats->mac_time[1];
1638 network->dtim_data = IEEE80211_DTIM_VALID;
1640 if(info_element->data[0] != 0)
1641 break;
1643 if(info_element->data[2] & 1)
1644 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1646 offset = (info_element->data[2] >> 1)*2;
1648 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1650 if(ieee->assoc_id < 8*offset ||
1651 ieee->assoc_id > 8*(offset + info_element->len -3))
1653 break;
1655 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1657 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1658 network->dtim_data |= IEEE80211_DTIM_UCAST;
1660 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1661 break;
1663 case MFIE_TYPE_ERP:
1664 network->erp_value = info_element->data[0];
1665 network->flags |= NETWORK_HAS_ERP_VALUE;
1666 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1667 network->erp_value);
1668 break;
1669 case MFIE_TYPE_IBSS_SET:
1670 network->atim_window = info_element->data[0];
1671 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1672 network->atim_window);
1673 break;
1675 case MFIE_TYPE_CHALLENGE:
1676 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1677 break;
1679 case MFIE_TYPE_GENERIC:
1680 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1681 info_element->len);
1682 if (!ieee80211_parse_qos_info_param_IE(info_element,
1683 network))
1684 break;
1686 if (info_element->len >= 4 &&
1687 info_element->data[0] == 0x00 &&
1688 info_element->data[1] == 0x50 &&
1689 info_element->data[2] == 0xf2 &&
1690 info_element->data[3] == 0x01) {
1691 network->wpa_ie_len = min(info_element->len + 2,
1692 MAX_WPA_IE_LEN);
1693 memcpy(network->wpa_ie, info_element,
1694 network->wpa_ie_len);
1695 break;
1698 if (info_element->len == 7 &&
1699 info_element->data[0] == 0x00 &&
1700 info_element->data[1] == 0xe0 &&
1701 info_element->data[2] == 0x4c &&
1702 info_element->data[3] == 0x01 &&
1703 info_element->data[4] == 0x02) {
1704 network->Turbo_Enable = 1;
1707 //for HTcap and HTinfo parameters
1708 if(tmp_htcap_len == 0){
1709 if(info_element->len >= 4 &&
1710 info_element->data[0] == 0x00 &&
1711 info_element->data[1] == 0x90 &&
1712 info_element->data[2] == 0x4c &&
1713 info_element->data[3] == 0x033){
1715 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1716 if(tmp_htcap_len != 0){
1717 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1718 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1719 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1720 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1723 if(tmp_htcap_len != 0){
1724 network->bssht.bdSupportHT = true;
1725 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1726 }else{
1727 network->bssht.bdSupportHT = false;
1728 network->bssht.bdHT1R = false;
1733 if(tmp_htinfo_len == 0){
1734 if(info_element->len >= 4 &&
1735 info_element->data[0] == 0x00 &&
1736 info_element->data[1] == 0x90 &&
1737 info_element->data[2] == 0x4c &&
1738 info_element->data[3] == 0x034){
1740 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1741 if(tmp_htinfo_len != 0){
1742 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1743 if(tmp_htinfo_len){
1744 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1745 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1746 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1754 if(ieee->aggregation){
1755 if(network->bssht.bdSupportHT){
1756 if(info_element->len >= 4 &&
1757 info_element->data[0] == 0x00 &&
1758 info_element->data[1] == 0xe0 &&
1759 info_element->data[2] == 0x4c &&
1760 info_element->data[3] == 0x02){
1762 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
1763 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
1766 if(ht_realtek_agg_len >= 5){
1767 network->realtek_cap_exit = true;
1768 network->bssht.bdRT2RTAggregation = true;
1770 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1771 network->bssht.bdRT2RTLongSlotTime = true;
1773 if((ht_realtek_agg_buf[4]==1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
1775 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
1776 //bssDesc->Vender = HT_IOT_PEER_REALTEK_92SE;
1783 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1785 if((info_element->len >= 3 &&
1786 info_element->data[0] == 0x00 &&
1787 info_element->data[1] == 0x05 &&
1788 info_element->data[2] == 0xb5) ||
1789 (info_element->len >= 3 &&
1790 info_element->data[0] == 0x00 &&
1791 info_element->data[1] == 0x0a &&
1792 info_element->data[2] == 0xf7) ||
1793 (info_element->len >= 3 &&
1794 info_element->data[0] == 0x00 &&
1795 info_element->data[1] == 0x10 &&
1796 info_element->data[2] == 0x18)){
1798 network->broadcom_cap_exist = true;
1802 if(info_element->len >= 3 &&
1803 info_element->data[0] == 0x00 &&
1804 info_element->data[1] == 0x0c &&
1805 info_element->data[2] == 0x43)
1807 network->ralink_cap_exist = true;
1809 else
1810 network->ralink_cap_exist = false;
1811 //added by amy for atheros AP
1812 if((info_element->len >= 3 &&
1813 info_element->data[0] == 0x00 &&
1814 info_element->data[1] == 0x03 &&
1815 info_element->data[2] == 0x7f) ||
1816 (info_element->len >= 3 &&
1817 info_element->data[0] == 0x00 &&
1818 info_element->data[1] == 0x13 &&
1819 info_element->data[2] == 0x74))
1821 // printk("========>%s(): athros AP is exist\n",__FUNCTION__);
1822 network->atheros_cap_exist = true;
1824 else
1825 network->atheros_cap_exist = false;
1827 if ((info_element->len >= 3 &&
1828 info_element->data[0] == 0x00 &&
1829 info_element->data[1] == 0x50 &&
1830 info_element->data[2] == 0x43) )
1832 network->marvell_cap_exist = true;
1834 else
1835 network->marvell_cap_exist = false;
1837 if(info_element->len >= 3 &&
1838 info_element->data[0] == 0x00 &&
1839 info_element->data[1] == 0x40 &&
1840 info_element->data[2] == 0x96)
1842 network->cisco_cap_exist = true;
1844 else
1845 network->cisco_cap_exist = false;
1846 //added by amy for LEAP of cisco
1847 if(info_element->len > 4 &&
1848 info_element->data[0] == 0x00 &&
1849 info_element->data[1] == 0x40 &&
1850 info_element->data[2] == 0x96 &&
1851 info_element->data[3] == 0x01)
1853 if(info_element->len == 6)
1855 memcpy(network->CcxRmState, &info_element[4], 2);
1856 if(network->CcxRmState[0] != 0)
1858 network->bCcxRmEnable = true;
1860 else
1861 network->bCcxRmEnable = false;
1863 // CCXv4 Table 59-1 MBSSID Masks.
1865 network->MBssidMask = network->CcxRmState[1] & 0x07;
1866 if(network->MBssidMask != 0)
1868 network->bMBssidValid = true;
1869 network->MBssidMask = 0xff << (network->MBssidMask);
1870 cpMacAddr(network->MBssid, network->bssid);
1871 network->MBssid[5] &= network->MBssidMask;
1873 else
1875 network->bMBssidValid = false;
1878 else
1880 network->bCcxRmEnable = false;
1883 if(info_element->len > 4 &&
1884 info_element->data[0] == 0x00 &&
1885 info_element->data[1] == 0x40 &&
1886 info_element->data[2] == 0x96 &&
1887 info_element->data[3] == 0x03)
1889 if(info_element->len == 5)
1891 network->bWithCcxVerNum = true;
1892 network->BssCcxVerNumber = info_element->data[4];
1894 else
1896 network->bWithCcxVerNum = false;
1897 network->BssCcxVerNumber = 0;
1900 break;
1902 case MFIE_TYPE_RSN:
1903 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1904 info_element->len);
1905 network->rsn_ie_len = min(info_element->len + 2,
1906 MAX_WPA_IE_LEN);
1907 memcpy(network->rsn_ie, info_element,
1908 network->rsn_ie_len);
1909 break;
1911 //HT related element.
1912 case MFIE_TYPE_HT_CAP:
1913 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
1914 info_element->len);
1915 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1916 if(tmp_htcap_len != 0){
1917 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1918 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1919 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1920 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1922 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1923 // windows driver will update WMM parameters each beacon received once connected
1924 // Linux driver is a bit different.
1925 network->bssht.bdSupportHT = true;
1926 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1928 else{
1929 network->bssht.bdSupportHT = false;
1930 network->bssht.bdHT1R = false;
1932 break;
1935 case MFIE_TYPE_HT_INFO:
1936 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
1937 info_element->len);
1938 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1939 if(tmp_htinfo_len){
1940 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
1941 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1942 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1943 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1945 break;
1947 case MFIE_TYPE_AIRONET:
1948 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
1949 info_element->len);
1950 if(info_element->len >IE_CISCO_FLAG_POSITION)
1952 network->bWithAironetIE = true;
1954 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
1955 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
1956 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
1957 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
1958 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
1960 network->bCkipSupported = true;
1962 else
1964 network->bCkipSupported = false;
1967 else
1969 network->bWithAironetIE = false;
1970 network->bCkipSupported = false;
1972 break;
1973 case MFIE_TYPE_QOS_PARAMETER:
1974 printk(KERN_ERR
1975 "QoS Error need to parse QOS_PARAMETER IE\n");
1976 break;
1978 case MFIE_TYPE_COUNTRY:
1979 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
1980 info_element->len);
1981 //printk("=====>Receive <%s> Country IE\n",network->ssid);
1982 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
1983 break;
1984 default:
1985 IEEE80211_DEBUG_MGMT
1986 ("Unsupported info element: %s (%d)\n",
1987 get_info_element_string(info_element->id),
1988 info_element->id);
1989 break;
1992 length -= sizeof(*info_element) + info_element->len;
1993 info_element =
1994 (struct ieee80211_info_element *)&info_element->
1995 data[info_element->len];
1998 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
1999 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation)
2001 network->unknown_cap_exist = true;
2003 else
2005 network->unknown_cap_exist = false;
2007 return 0;
2010 static inline u8 ieee80211_SignalStrengthTranslate(
2011 u8 CurrSS
2014 u8 RetSS;
2016 // Step 1. Scale mapping.
2017 if(CurrSS >= 71 && CurrSS <= 100)
2019 RetSS = 90 + ((CurrSS - 70) / 3);
2021 else if(CurrSS >= 41 && CurrSS <= 70)
2023 RetSS = 78 + ((CurrSS - 40) / 3);
2025 else if(CurrSS >= 31 && CurrSS <= 40)
2027 RetSS = 66 + (CurrSS - 30);
2029 else if(CurrSS >= 21 && CurrSS <= 30)
2031 RetSS = 54 + (CurrSS - 20);
2033 else if(CurrSS >= 5 && CurrSS <= 20)
2035 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2037 else if(CurrSS == 4)
2039 RetSS = 36;
2041 else if(CurrSS == 3)
2043 RetSS = 27;
2045 else if(CurrSS == 2)
2047 RetSS = 18;
2049 else if(CurrSS == 1)
2051 RetSS = 9;
2053 else
2055 RetSS = CurrSS;
2057 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2059 // Step 2. Smoothing.
2061 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2063 return RetSS;
2066 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2068 long signal_power; // in dBm.
2070 // Translate to dBm (x=0.5y-95).
2071 signal_power = (long)((signal_strength_index + 1) >> 1);
2072 signal_power -= 95;
2074 return signal_power;
2077 static inline int ieee80211_network_init(
2078 struct ieee80211_device *ieee,
2079 struct ieee80211_probe_response *beacon,
2080 struct ieee80211_network *network,
2081 struct ieee80211_rx_stats *stats)
2083 #ifdef CONFIG_IEEE80211_DEBUG
2084 //char rates_str[64];
2085 //char *p;
2086 #endif
2088 network->qos_data.active = 0;
2089 network->qos_data.supported = 0;
2090 network->qos_data.param_count = 0;
2091 network->qos_data.old_param_count = 0;
2093 /* Pull out fixed field data */
2094 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2095 network->capability = le16_to_cpu(beacon->capability);
2096 network->last_scanned = jiffies;
2097 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2098 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2099 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2100 /* Where to pull this? beacon->listen_interval;*/
2101 network->listen_interval = 0x0A;
2102 network->rates_len = network->rates_ex_len = 0;
2103 network->last_associate = 0;
2104 network->ssid_len = 0;
2105 network->flags = 0;
2106 network->atim_window = 0;
2107 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2108 0x3 : 0x0;
2109 network->berp_info_valid = false;
2110 network->broadcom_cap_exist = false;
2111 network->ralink_cap_exist = false;
2112 network->atheros_cap_exist = false;
2113 network->cisco_cap_exist = false;
2114 network->unknown_cap_exist = false;
2115 network->realtek_cap_exit = false;
2116 network->marvell_cap_exist = false;
2117 network->Turbo_Enable = 0;
2118 network->CountryIeLen = 0;
2119 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2120 //Initialize HT parameters
2121 //ieee80211_ht_initialize(&network->bssht);
2122 HTInitializeBssDesc(&network->bssht);
2123 if (stats->freq == IEEE80211_52GHZ_BAND) {
2124 /* for A band (No DS info) */
2125 network->channel = stats->received_channel;
2126 } else
2127 network->flags |= NETWORK_HAS_CCK;
2129 network->wpa_ie_len = 0;
2130 network->rsn_ie_len = 0;
2132 if (ieee80211_parse_info_param
2133 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2134 return 1;
2136 network->mode = 0;
2137 if (stats->freq == IEEE80211_52GHZ_BAND)
2138 network->mode = IEEE_A;
2139 else {
2140 if (network->flags & NETWORK_HAS_OFDM)
2141 network->mode |= IEEE_G;
2142 if (network->flags & NETWORK_HAS_CCK)
2143 network->mode |= IEEE_B;
2146 if (network->mode == 0) {
2147 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2148 "network.\n",
2149 escape_essid(network->ssid,
2150 network->ssid_len),
2151 network->bssid);
2152 return 1;
2155 if(network->bssht.bdSupportHT){
2156 if(network->mode == IEEE_A)
2157 network->mode = IEEE_N_5G;
2158 else if(network->mode & (IEEE_G | IEEE_B))
2159 network->mode = IEEE_N_24G;
2161 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2162 network->flags |= NETWORK_EMPTY_ESSID;
2164 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2165 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2166 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2168 memcpy(&network->stats, stats, sizeof(network->stats));
2170 return 0;
2173 static inline int is_same_network(struct ieee80211_network *src,
2174 struct ieee80211_network *dst, struct ieee80211_device* ieee)
2176 /* A network is only a duplicate if the channel, BSSID, ESSID
2177 * and the capability field (in particular IBSS and BSS) all match.
2178 * We treat all <hidden> with the same BSSID and channel
2179 * as one network */
2180 return //((src->ssid_len == dst->ssid_len) &&
2181 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2182 (src->channel == dst->channel) &&
2183 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2184 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2185 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2186 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2187 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2188 ((src->capability & WLAN_CAPABILITY_BSS) ==
2189 (dst->capability & WLAN_CAPABILITY_BSS)));
2192 static inline void update_network(struct ieee80211_network *dst,
2193 struct ieee80211_network *src)
2195 int qos_active;
2196 u8 old_param;
2198 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2199 dst->capability = src->capability;
2200 memcpy(dst->rates, src->rates, src->rates_len);
2201 dst->rates_len = src->rates_len;
2202 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2203 dst->rates_ex_len = src->rates_ex_len;
2204 if(src->ssid_len > 0)
2206 memset(dst->ssid, 0, dst->ssid_len);
2207 dst->ssid_len = src->ssid_len;
2208 memcpy(dst->ssid, src->ssid, src->ssid_len);
2210 dst->mode = src->mode;
2211 dst->flags = src->flags;
2212 dst->time_stamp[0] = src->time_stamp[0];
2213 dst->time_stamp[1] = src->time_stamp[1];
2214 if (src->flags & NETWORK_HAS_ERP_VALUE)
2216 dst->erp_value = src->erp_value;
2217 dst->berp_info_valid = src->berp_info_valid = true;
2219 dst->beacon_interval = src->beacon_interval;
2220 dst->listen_interval = src->listen_interval;
2221 dst->atim_window = src->atim_window;
2222 dst->dtim_period = src->dtim_period;
2223 dst->dtim_data = src->dtim_data;
2224 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2225 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2226 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2228 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2229 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2230 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2231 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2232 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2233 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2234 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2235 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2236 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2237 dst->ralink_cap_exist = src->ralink_cap_exist;
2238 dst->atheros_cap_exist = src->atheros_cap_exist;
2239 dst->realtek_cap_exit = src->realtek_cap_exit;
2240 dst->marvell_cap_exist = src->marvell_cap_exist;
2241 dst->cisco_cap_exist = src->cisco_cap_exist;
2242 dst->unknown_cap_exist = src->unknown_cap_exist;
2243 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2244 dst->wpa_ie_len = src->wpa_ie_len;
2245 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2246 dst->rsn_ie_len = src->rsn_ie_len;
2248 dst->last_scanned = jiffies;
2249 /* qos related parameters */
2250 //qos_active = src->qos_data.active;
2251 qos_active = dst->qos_data.active;
2252 //old_param = dst->qos_data.old_param_count;
2253 old_param = dst->qos_data.param_count;
2254 if(dst->flags & NETWORK_HAS_QOS_MASK){
2255 //not update QOS paramter in beacon, as most AP will set all these parameter to 0.//WB
2256 // printk("====>%s(), aifs:%x, %x\n", __FUNCTION__, dst->qos_data.parameters.aifs[0], src->qos_data.parameters.aifs[0]);
2257 // memcpy(&dst->qos_data, &src->qos_data,
2258 // sizeof(struct ieee80211_qos_data));
2260 else {
2261 dst->qos_data.supported = src->qos_data.supported;
2262 dst->qos_data.param_count = src->qos_data.param_count;
2265 if(dst->qos_data.supported == 1) {
2266 dst->QoS_Enable = 1;
2267 if(dst->ssid_len)
2268 IEEE80211_DEBUG_QOS
2269 ("QoS the network %s is QoS supported\n",
2270 dst->ssid);
2271 else
2272 IEEE80211_DEBUG_QOS
2273 ("QoS the network is QoS supported\n");
2275 dst->qos_data.active = qos_active;
2276 dst->qos_data.old_param_count = old_param;
2278 /* dst->last_associate is not overwritten */
2279 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2280 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2281 src->wmm_param[1].ac_aci_acm_aifsn|| \
2282 src->wmm_param[2].ac_aci_acm_aifsn|| \
2283 src->wmm_param[1].ac_aci_acm_aifsn) {
2284 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2286 //dst->QoS_Enable = src->QoS_Enable;
2287 dst->Turbo_Enable = src->Turbo_Enable;
2289 dst->CountryIeLen = src->CountryIeLen;
2290 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2292 //added by amy for LEAP
2293 dst->bWithAironetIE = src->bWithAironetIE;
2294 dst->bCkipSupported = src->bCkipSupported;
2295 memcpy(dst->CcxRmState,src->CcxRmState,2);
2296 dst->bCcxRmEnable = src->bCcxRmEnable;
2297 dst->MBssidMask = src->MBssidMask;
2298 dst->bMBssidValid = src->bMBssidValid;
2299 memcpy(dst->MBssid,src->MBssid,6);
2300 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2301 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2305 static inline int is_beacon(__le16 fc)
2307 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2310 static inline void ieee80211_process_probe_response(
2311 struct ieee80211_device *ieee,
2312 struct ieee80211_probe_response *beacon,
2313 struct ieee80211_rx_stats *stats)
2315 struct ieee80211_network network;
2316 struct ieee80211_network *target;
2317 struct ieee80211_network *oldest = NULL;
2318 #ifdef CONFIG_IEEE80211_DEBUG
2319 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2320 #endif
2321 unsigned long flags;
2322 short renew;
2323 //u8 wmm_info;
2325 memset(&network, 0, sizeof(struct ieee80211_network));
2326 IEEE80211_DEBUG_SCAN(
2327 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2328 escape_essid(info_element->data, info_element->len),
2329 beacon->header.addr3,
2330 (beacon->capability & (1<<0xf)) ? '1' : '0',
2331 (beacon->capability & (1<<0xe)) ? '1' : '0',
2332 (beacon->capability & (1<<0xd)) ? '1' : '0',
2333 (beacon->capability & (1<<0xc)) ? '1' : '0',
2334 (beacon->capability & (1<<0xb)) ? '1' : '0',
2335 (beacon->capability & (1<<0xa)) ? '1' : '0',
2336 (beacon->capability & (1<<0x9)) ? '1' : '0',
2337 (beacon->capability & (1<<0x8)) ? '1' : '0',
2338 (beacon->capability & (1<<0x7)) ? '1' : '0',
2339 (beacon->capability & (1<<0x6)) ? '1' : '0',
2340 (beacon->capability & (1<<0x5)) ? '1' : '0',
2341 (beacon->capability & (1<<0x4)) ? '1' : '0',
2342 (beacon->capability & (1<<0x3)) ? '1' : '0',
2343 (beacon->capability & (1<<0x2)) ? '1' : '0',
2344 (beacon->capability & (1<<0x1)) ? '1' : '0',
2345 (beacon->capability & (1<<0x0)) ? '1' : '0');
2347 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2348 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2349 escape_essid(info_element->data,
2350 info_element->len),
2351 beacon->header.addr3,
2352 WLAN_FC_GET_STYPE(beacon->header.frame_control) ==
2353 IEEE80211_STYPE_PROBE_RESP ?
2354 "PROBE RESPONSE" : "BEACON");
2355 return;
2358 // For Asus EeePc request,
2359 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2360 // wireless adapter should follow the country code.
2361 // (2) If there is no any country code in beacon,
2362 // then wireless adapter should do active scan from ch1~11 and
2363 // passive scan from ch12~14
2365 if( !IsLegalChannel(ieee, network.channel) )
2366 return;
2367 if(ieee->bGlobalDomain)
2369 if (WLAN_FC_GET_STYPE(beacon->header.frame_control) == IEEE80211_STYPE_PROBE_RESP)
2371 // Case 1: Country code
2372 if(IS_COUNTRY_IE_VALID(ieee) )
2374 if( !IsLegalChannel(ieee, network.channel) )
2376 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2377 return;
2380 // Case 2: No any country code.
2381 else
2383 // Filter over channel ch12~14
2384 if(network.channel > 11)
2386 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2387 return;
2391 else
2393 // Case 1: Country code
2394 if(IS_COUNTRY_IE_VALID(ieee) )
2396 if( !IsLegalChannel(ieee, network.channel) )
2398 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2399 return;
2402 // Case 2: No any country code.
2403 else
2405 // Filter over channel ch12~14
2406 if(network.channel > 14)
2408 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2409 return;
2415 /* The network parsed correctly -- so now we scan our known networks
2416 * to see if we can find it in our list.
2418 * NOTE: This search is definitely not optimized. Once its doing
2419 * the "right thing" we'll optimize it for efficiency if
2420 * necessary */
2422 /* Search for this entry in the list and update it if it is
2423 * already there. */
2425 spin_lock_irqsave(&ieee->lock, flags);
2427 if(is_same_network(&ieee->current_network, &network, ieee)) {
2428 update_network(&ieee->current_network, &network);
2429 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2430 && ieee->current_network.berp_info_valid){
2431 if(ieee->current_network.erp_value& ERP_UseProtection)
2432 ieee->current_network.buseprotection = true;
2433 else
2434 ieee->current_network.buseprotection = false;
2436 if(is_beacon(beacon->header.frame_control))
2438 if(ieee->state == IEEE80211_LINKED)
2439 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2441 else //hidden AP
2442 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2445 list_for_each_entry(target, &ieee->network_list, list) {
2446 if (is_same_network(target, &network, ieee))
2447 break;
2448 if ((oldest == NULL) ||
2449 (target->last_scanned < oldest->last_scanned))
2450 oldest = target;
2453 /* If we didn't find a match, then get a new network slot to initialize
2454 * with this beacon's information */
2455 if (&target->list == &ieee->network_list) {
2456 if (list_empty(&ieee->network_free_list)) {
2457 /* If there are no more slots, expire the oldest */
2458 list_del(&oldest->list);
2459 target = oldest;
2460 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2461 "network list.\n",
2462 escape_essid(target->ssid,
2463 target->ssid_len),
2464 target->bssid);
2465 } else {
2466 /* Otherwise just pull from the free list */
2467 target = list_entry(ieee->network_free_list.next,
2468 struct ieee80211_network, list);
2469 list_del(ieee->network_free_list.next);
2473 #ifdef CONFIG_IEEE80211_DEBUG
2474 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2475 escape_essid(network.ssid,
2476 network.ssid_len),
2477 network.bssid,
2478 WLAN_FC_GET_STYPE(beacon->header.frame_control) ==
2479 IEEE80211_STYPE_PROBE_RESP ?
2480 "PROBE RESPONSE" : "BEACON");
2481 #endif
2482 memcpy(target, &network, sizeof(*target));
2483 list_add_tail(&target->list, &ieee->network_list);
2484 if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2485 ieee80211_softmac_new_net(ieee,&network);
2486 } else {
2487 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2488 escape_essid(target->ssid,
2489 target->ssid_len),
2490 target->bssid,
2491 WLAN_FC_GET_STYPE(beacon->header.frame_control) ==
2492 IEEE80211_STYPE_PROBE_RESP ?
2493 "PROBE RESPONSE" : "BEACON");
2495 /* we have an entry and we are going to update it. But this entry may
2496 * be already expired. In this case we do the same as we found a new
2497 * net and call the new_net handler
2499 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2500 //YJ,add,080819,for hidden ap
2501 if(is_beacon(beacon->header.frame_control) == 0)
2502 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2503 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2504 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2505 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2506 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2507 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2508 renew = 1;
2509 //YJ,add,080819,for hidden ap,end
2511 update_network(target, &network);
2512 if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2513 ieee80211_softmac_new_net(ieee,&network);
2516 spin_unlock_irqrestore(&ieee->lock, flags);
2517 if (is_beacon(beacon->header.frame_control)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2518 (ieee->state == IEEE80211_LINKED)) {
2519 if(ieee->handle_beacon != NULL) {
2520 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2525 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2526 struct ieee80211_hdr_4addr *header,
2527 struct ieee80211_rx_stats *stats)
2529 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2530 ieee->iw_mode == IW_MODE_INFRA &&
2531 ieee->state == IEEE80211_LINKED))
2533 tasklet_schedule(&ieee->ps_task);
2536 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2537 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2538 ieee->last_rx_ps_time = jiffies;
2540 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2542 case IEEE80211_STYPE_BEACON:
2543 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2544 WLAN_FC_GET_STYPE(header->frame_ctl));
2545 IEEE80211_DEBUG_SCAN("Beacon\n");
2546 ieee80211_process_probe_response(
2547 ieee, (struct ieee80211_probe_response *)header, stats);
2548 break;
2550 case IEEE80211_STYPE_PROBE_RESP:
2551 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2552 WLAN_FC_GET_STYPE(header->frame_ctl));
2553 IEEE80211_DEBUG_SCAN("Probe response\n");
2554 ieee80211_process_probe_response(
2555 ieee, (struct ieee80211_probe_response *)header, stats);
2556 break;