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 / rtl8192e / ieee80211 / ieee80211_rx.c
blob8d215c91bfa1888d013b9143bcf806e95f2cf522
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/version.h>
41 #include <linux/wireless.h>
42 #include <linux/etherdevice.h>
43 #include <asm/uaccess.h>
44 #include <linux/ctype.h>
46 #include "ieee80211.h"
47 #ifdef ENABLE_DOT11D
48 #include "dot11d.h"
49 #endif
50 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
51 struct sk_buff *skb,
52 struct ieee80211_rx_stats *rx_stats)
54 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *)skb->data;
55 u16 fc = le16_to_cpu(hdr->frame_ctl);
57 skb->dev = ieee->dev;
58 skb_reset_mac_header(skb);
60 skb_pull(skb, ieee80211_get_hdrlen(fc));
61 skb->pkt_type = PACKET_OTHERHOST;
62 skb->protocol = __constant_htons(ETH_P_80211_RAW);
63 memset(skb->cb, 0, sizeof(skb->cb));
64 netif_rx(skb);
68 /* Called only as a tasklet (software IRQ) */
69 static struct ieee80211_frag_entry *
70 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
71 unsigned int frag, u8 tid,u8 *src, u8 *dst)
73 struct ieee80211_frag_entry *entry;
74 int i;
76 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
77 entry = &ieee->frag_cache[tid][i];
78 if (entry->skb != NULL &&
79 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
80 IEEE80211_DEBUG_FRAG(
81 "expiring fragment cache entry "
82 "seq=%u last_frag=%u\n",
83 entry->seq, entry->last_frag);
84 dev_kfree_skb_any(entry->skb);
85 entry->skb = NULL;
88 if (entry->skb != NULL && entry->seq == seq &&
89 (entry->last_frag + 1 == frag || frag == -1) &&
90 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
91 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
92 return entry;
95 return NULL;
98 /* Called only as a tasklet (software IRQ) */
99 static struct sk_buff *
100 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
101 struct ieee80211_hdr_4addr *hdr)
103 struct sk_buff *skb = NULL;
104 u16 fc = le16_to_cpu(hdr->frame_ctl);
105 u16 sc = le16_to_cpu(hdr->seq_ctl);
106 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
107 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
108 struct ieee80211_frag_entry *entry;
109 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
110 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
111 u8 tid;
113 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
114 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
115 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
116 tid = UP2AC(tid);
117 tid ++;
118 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
119 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
120 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
121 tid = UP2AC(tid);
122 tid ++;
123 } else {
124 tid = 0;
127 if (frag == 0) {
128 /* Reserve enough space to fit maximum frame length */
129 skb = dev_alloc_skb(ieee->dev->mtu +
130 sizeof(struct ieee80211_hdr_4addr) +
131 8 /* LLC */ +
132 2 /* alignment */ +
133 8 /* WEP */ +
134 ETH_ALEN /* WDS */ +
135 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
136 if (skb == NULL)
137 return NULL;
139 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
140 ieee->frag_next_idx[tid]++;
141 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
142 ieee->frag_next_idx[tid] = 0;
144 if (entry->skb != NULL)
145 dev_kfree_skb_any(entry->skb);
147 entry->first_frag_time = jiffies;
148 entry->seq = seq;
149 entry->last_frag = frag;
150 entry->skb = skb;
151 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
152 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
153 } else {
154 /* received a fragment of a frame for which the head fragment
155 * should have already been received */
156 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
157 hdr->addr1);
158 if (entry != NULL) {
159 entry->last_frag = frag;
160 skb = entry->skb;
164 return skb;
168 /* Called only as a tasklet (software IRQ) */
169 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
170 struct ieee80211_hdr_4addr *hdr)
172 u16 fc = le16_to_cpu(hdr->frame_ctl);
173 u16 sc = le16_to_cpu(hdr->seq_ctl);
174 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
175 struct ieee80211_frag_entry *entry;
176 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
177 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
178 u8 tid;
180 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
181 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
182 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
183 tid = UP2AC(tid);
184 tid ++;
185 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
186 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
187 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
188 tid = UP2AC(tid);
189 tid ++;
190 } else {
191 tid = 0;
194 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
195 hdr->addr1);
197 if (entry == NULL) {
198 IEEE80211_DEBUG_FRAG(
199 "could not invalidate fragment cache "
200 "entry (seq=%u)\n", seq);
201 return -1;
204 entry->skb = NULL;
205 return 0;
210 /* ieee80211_rx_frame_mgtmt
212 * Responsible for handling management control frames
214 * Called by ieee80211_rx */
215 static inline int
216 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
217 struct ieee80211_rx_stats *rx_stats, u16 type,
218 u16 stype)
220 /* On the struct stats definition there is written that
221 * this is not mandatory.... but seems that the probe
222 * response parser uses it
224 struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data;
226 rx_stats->len = skb->len;
227 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
228 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
229 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames
231 dev_kfree_skb_any(skb);
232 return 0;
235 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
237 dev_kfree_skb_any(skb);
239 return 0;
241 #ifdef NOT_YET
242 if (ieee->iw_mode == IW_MODE_MASTER) {
243 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
244 ieee->dev->name);
245 return 0;
247 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
248 skb->data);*/
251 if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) {
252 if (stype == WLAN_FC_STYPE_BEACON &&
253 ieee->iw_mode == IW_MODE_MASTER) {
254 struct sk_buff *skb2;
255 /* Process beacon frames also in kernel driver to
256 * update STA(AP) table statistics */
257 skb2 = skb_clone(skb, GFP_ATOMIC);
258 if (skb2)
259 hostap_rx(skb2->dev, skb2, rx_stats);
262 /* send management frames to the user space daemon for
263 * processing */
264 ieee->apdevstats.rx_packets++;
265 ieee->apdevstats.rx_bytes += skb->len;
266 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
267 return 0;
270 if (ieee->iw_mode == IW_MODE_MASTER) {
271 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
272 printk(KERN_DEBUG "%s: unknown management frame "
273 "(type=0x%02x, stype=0x%02x) dropped\n",
274 skb->dev->name, type, stype);
275 return -1;
278 hostap_rx(skb->dev, skb, rx_stats);
279 return 0;
282 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
283 "received in non-Host AP mode\n", skb->dev->name);
284 return -1;
285 #endif
290 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
291 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
292 static unsigned char rfc1042_header[] =
293 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
294 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
295 static unsigned char bridge_tunnel_header[] =
296 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
297 /* No encapsulation header if EtherType < 0x600 (=length) */
299 /* Called by ieee80211_rx_frame_decrypt */
300 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
301 struct sk_buff *skb, size_t hdrlen)
303 struct net_device *dev = ieee->dev;
304 u16 fc, ethertype;
305 struct ieee80211_hdr_4addr *hdr;
306 u8 *pos;
308 if (skb->len < 24)
309 return 0;
311 if (ieee->hwsec_active)
313 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
314 tcb_desc->bHwSec = 1;
316 if(ieee->need_sw_enc)
317 tcb_desc->bHwSec = 0;
320 hdr = (struct ieee80211_hdr_4addr *) skb->data;
321 fc = le16_to_cpu(hdr->frame_ctl);
323 /* check that the frame is unicast frame to us */
324 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
325 IEEE80211_FCTL_TODS &&
326 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
327 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
328 /* ToDS frame with own addr BSSID and DA */
329 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
330 IEEE80211_FCTL_FROMDS &&
331 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
332 /* FromDS frame with own addr as DA */
333 } else
334 return 0;
336 if (skb->len < 24 + 8)
337 return 0;
339 /* check for port access entity Ethernet type */
340 // pos = skb->data + 24;
341 pos = skb->data + hdrlen;
342 ethertype = (pos[6] << 8) | pos[7];
343 if (ethertype == ETH_P_PAE)
344 return 1;
346 return 0;
349 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
350 static inline int
351 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
352 struct ieee80211_crypt_data *crypt)
354 struct ieee80211_hdr_4addr *hdr;
355 int res, hdrlen;
357 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
358 return 0;
359 if (ieee->hwsec_active)
361 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
362 tcb_desc->bHwSec = 1;
364 hdr = (struct ieee80211_hdr_4addr *) skb->data;
365 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
367 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
368 if (ieee->tkip_countermeasures &&
369 strcmp(crypt->ops->name, "TKIP") == 0) {
370 if (net_ratelimit()) {
371 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
372 "received packet from %pM\n",
373 ieee->dev->name, hdr->addr2);
375 return -1;
377 #endif
379 atomic_inc(&crypt->refcnt);
380 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
381 atomic_dec(&crypt->refcnt);
382 if (res < 0) {
383 IEEE80211_DEBUG_DROP(
384 "decryption failed (SA=%pM"
385 ") res=%d\n", hdr->addr2, res);
386 if (res == -2)
387 IEEE80211_DEBUG_DROP("Decryption failed ICV "
388 "mismatch (key %d)\n",
389 skb->data[hdrlen + 3] >> 6);
390 ieee->ieee_stats.rx_discards_undecryptable++;
391 return -1;
394 return res;
398 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
399 static inline int
400 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
401 int keyidx, struct ieee80211_crypt_data *crypt)
403 struct ieee80211_hdr_4addr *hdr;
404 int res, hdrlen;
406 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
407 return 0;
408 if (ieee->hwsec_active)
410 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
411 tcb_desc->bHwSec = 1;
413 if(ieee->need_sw_enc)
414 tcb_desc->bHwSec = 0;
418 hdr = (struct ieee80211_hdr_4addr *) skb->data;
419 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
421 atomic_inc(&crypt->refcnt);
422 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
423 atomic_dec(&crypt->refcnt);
424 if (res < 0) {
425 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
426 " (SA=%pM keyidx=%d)\n",
427 ieee->dev->name, hdr->addr2, keyidx);
428 return -1;
431 return 0;
435 /* this function is stolen from ipw2200 driver*/
436 #define IEEE_PACKET_RETRY_TIME (5*HZ)
437 static int is_duplicate_packet(struct ieee80211_device *ieee,
438 struct ieee80211_hdr_4addr *header)
440 u16 fc = le16_to_cpu(header->frame_ctl);
441 u16 sc = le16_to_cpu(header->seq_ctl);
442 u16 seq = WLAN_GET_SEQ_SEQ(sc);
443 u16 frag = WLAN_GET_SEQ_FRAG(sc);
444 u16 *last_seq, *last_frag;
445 unsigned long *last_time;
446 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
447 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
448 u8 tid;
451 //TO2DS and QoS
452 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
453 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
454 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
455 tid = UP2AC(tid);
456 tid ++;
457 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
458 hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
459 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
460 tid = UP2AC(tid);
461 tid ++;
462 } else { // no QoS
463 tid = 0;
466 switch (ieee->iw_mode) {
467 case IW_MODE_ADHOC:
469 struct list_head *p;
470 struct ieee_ibss_seq *entry = NULL;
471 u8 *mac = header->addr2;
472 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
473 //for (pos = (head)->next; pos != (head); pos = pos->next)
474 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
475 list_for_each(p, &ieee->ibss_mac_hash[index]) {
476 entry = list_entry(p, struct ieee_ibss_seq, list);
477 if (!memcmp(entry->mac, mac, ETH_ALEN))
478 break;
480 // if (memcmp(entry->mac, mac, ETH_ALEN)){
481 if (p == &ieee->ibss_mac_hash[index]) {
482 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
483 if (!entry) {
484 printk(KERN_WARNING "Cannot malloc new mac entry\n");
485 return 0;
487 memcpy(entry->mac, mac, ETH_ALEN);
488 entry->seq_num[tid] = seq;
489 entry->frag_num[tid] = frag;
490 entry->packet_time[tid] = jiffies;
491 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
492 return 0;
494 last_seq = &entry->seq_num[tid];
495 last_frag = &entry->frag_num[tid];
496 last_time = &entry->packet_time[tid];
497 break;
500 case IW_MODE_INFRA:
501 last_seq = &ieee->last_rxseq_num[tid];
502 last_frag = &ieee->last_rxfrag_num[tid];
503 last_time = &ieee->last_packet_time[tid];
505 break;
506 default:
507 return 0;
510 // if(tid != 0) {
511 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
512 // }
513 if ((*last_seq == seq) &&
514 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
515 if (*last_frag == frag){
516 //printk(KERN_WARNING "[1] go drop!\n");
517 goto drop;
520 if (*last_frag + 1 != frag)
521 /* out-of-order fragment */
522 //printk(KERN_WARNING "[2] go drop!\n");
523 goto drop;
524 } else
525 *last_seq = seq;
527 *last_frag = frag;
528 *last_time = jiffies;
529 return 0;
531 drop:
532 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
533 // printk("DUP\n");
535 return 1;
537 bool
538 AddReorderEntry(
539 PRX_TS_RECORD pTS,
540 PRX_REORDER_ENTRY pReorderEntry
543 struct list_head *pList = &pTS->RxPendingPktList;
544 while(pList->next != &pTS->RxPendingPktList)
546 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
548 pList = pList->next;
550 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
552 return false;
554 else
556 break;
559 pReorderEntry->List.next = pList->next;
560 pReorderEntry->List.next->prev = &pReorderEntry->List;
561 pReorderEntry->List.prev = pList;
562 pList->next = &pReorderEntry->List;
564 return true;
567 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index)
569 u8 i = 0 , j=0;
570 u16 ethertype;
571 // if(index > 1)
572 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
573 for(j = 0; j<index; j++)
575 //added by amy for reorder
576 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
577 for(i = 0; i<prxb->nr_subframes; i++) {
578 struct sk_buff *sub_skb = prxb->subframes[i];
580 /* convert hdr + possible LLC headers into Ethernet header */
581 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
582 if (sub_skb->len >= 8 &&
583 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
584 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
585 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
586 /* remove RFC1042 or Bridge-Tunnel encapsulation and
587 * replace EtherType */
588 skb_pull(sub_skb, SNAP_SIZE);
589 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
590 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
591 } else {
592 u16 len;
593 /* Leave Ethernet header part of hdr and full payload */
594 len = htons(sub_skb->len);
595 memcpy(skb_push(sub_skb, 2), &len, 2);
596 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
597 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
599 //stats->rx_packets++;
600 //stats->rx_bytes += sub_skb->len;
602 /* Indicat the packets to upper layer */
603 if (sub_skb) {
604 //printk("0skb_len(%d)\n", skb->len);
605 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
606 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
607 sub_skb->dev = ieee->dev;
608 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
609 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
610 ieee->last_rx_ps_time = jiffies;
611 //printk("1skb_len(%d)\n", skb->len);
612 netif_rx(sub_skb);
615 kfree(prxb);
616 prxb = NULL;
621 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
622 struct ieee80211_rxb* prxb,
623 PRX_TS_RECORD pTS,
624 u16 SeqNum)
626 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
627 PRX_REORDER_ENTRY pReorderEntry = NULL;
628 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
629 u8 WinSize = pHTInfo->RxReorderWinSize;
630 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
631 u8 index = 0;
632 bool bMatchWinStart = false, bPktInBuf = false;
633 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
634 /* Rx Reorder initialize condition.*/
635 if(pTS->RxIndicateSeq == 0xffff) {
636 pTS->RxIndicateSeq = SeqNum;
639 /* Drop out the packet which SeqNum is smaller than WinStart */
640 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
641 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
642 pTS->RxIndicateSeq, SeqNum);
643 pHTInfo->RxReorderDropCounter++;
645 int i;
646 for(i =0; i < prxb->nr_subframes; i++) {
647 dev_kfree_skb(prxb->subframes[i]);
649 kfree(prxb);
650 prxb = NULL;
652 return;
656 * Sliding window manipulation. Conditions includes:
657 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
658 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
660 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
661 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
662 bMatchWinStart = true;
663 } else if(SN_LESS(WinEnd, SeqNum)) {
664 if(SeqNum >= (WinSize - 1)) {
665 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
666 } else {
667 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
669 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
673 * Indication process.
674 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
675 * with the SeqNum smaller than latest WinStart and buffer other packets.
677 /* For Rx Reorder condition:
678 * 1. All packets with SeqNum smaller than WinStart => Indicate
679 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
681 if(bMatchWinStart) {
682 /* Current packet is going to be indicated.*/
683 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
684 pTS->RxIndicateSeq, SeqNum);
685 prxbIndicateArray[0] = prxb;
686 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
687 index = 1;
688 } else {
689 /* Current packet is going to be inserted into pending list.*/
690 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
691 if(!list_empty(&ieee->RxReorder_Unused_List)) {
692 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
693 list_del_init(&pReorderEntry->List);
695 /* Make a reorder entry and insert into a the packet list.*/
696 pReorderEntry->SeqNum = SeqNum;
697 pReorderEntry->prxb = prxb;
698 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
700 if(!AddReorderEntry(pTS, pReorderEntry)) {
701 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
702 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
703 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
705 int i;
706 for(i =0; i < prxb->nr_subframes; i++) {
707 dev_kfree_skb(prxb->subframes[i]);
709 kfree(prxb);
710 prxb = NULL;
712 } else {
713 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
714 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
717 else {
719 * Packets are dropped if there is not enough reorder entries.
720 * This part shall be modified!! We can just indicate all the
721 * packets in buffer and get reorder entries.
723 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
725 int i;
726 for(i =0; i < prxb->nr_subframes; i++) {
727 dev_kfree_skb(prxb->subframes[i]);
729 kfree(prxb);
730 prxb = NULL;
735 /* Check if there is any packet need indicate.*/
736 while(!list_empty(&pTS->RxPendingPktList)) {
737 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
738 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
739 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
740 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
742 /* This protect buffer from overflow. */
743 if(index >= REORDER_WIN_SIZE) {
744 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
745 bPktInBuf = true;
746 break;
749 list_del_init(&pReorderEntry->List);
751 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
752 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
754 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
755 prxbIndicateArray[index] = pReorderEntry->prxb;
756 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
757 index++;
759 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
760 } else {
761 bPktInBuf = true;
762 break;
766 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
767 if(index>0) {
768 // Cancel previous pending timer.
769 if (timer_pending(&pTS->RxPktPendingTimer))
770 del_timer_sync(&pTS->RxPktPendingTimer);
771 pTS->RxTimeoutIndicateSeq = 0xffff;
773 // Indicate packets
774 if(index>REORDER_WIN_SIZE){
775 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
776 return;
778 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
779 bPktInBuf = false;
782 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
783 // Set new pending timer.
784 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
785 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
786 mod_timer(&pTS->RxPktPendingTimer, jiffies + MSECS(pHTInfo->RxReorderPendingTime));
790 u8 parse_subframe(struct ieee80211_device* ieee,struct sk_buff *skb,
791 struct ieee80211_rx_stats *rx_stats,
792 struct ieee80211_rxb *rxb,u8* src,u8* dst)
794 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
795 u16 fc = le16_to_cpu(hdr->frame_ctl);
797 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
798 u16 ChkLength;
799 bool bIsAggregateFrame = false;
800 u16 nSubframe_Length;
801 u8 nPadding_Length = 0;
802 u16 SeqNum=0;
804 struct sk_buff *sub_skb;
805 u8 *data_ptr;
806 /* just for debug purpose */
807 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
809 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
810 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
811 bIsAggregateFrame = true;
814 if(IEEE80211_QOS_HAS_SEQ(fc)) {
815 LLCOffset += 2;
818 if(rx_stats->bContainHTC) {
819 LLCOffset += sHTCLng;
821 //printk("ChkLength = %d\n", LLCOffset);
822 // Null packet, don't indicate it to upper layer
823 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
825 if( skb->len <= ChkLength ) {
826 return 0;
829 skb_pull(skb, LLCOffset);
830 ieee->bIsAggregateFrame = bIsAggregateFrame;//added by amy for Leisure PS
832 if(!bIsAggregateFrame) {
833 rxb->nr_subframes = 1;
834 #ifdef JOHN_NOCPY
835 rxb->subframes[0] = skb;
836 #else
837 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
838 #endif
840 memcpy(rxb->src,src,ETH_ALEN);
841 memcpy(rxb->dst,dst,ETH_ALEN);
842 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
843 return 1;
844 } else {
845 rxb->nr_subframes = 0;
846 memcpy(rxb->src,src,ETH_ALEN);
847 memcpy(rxb->dst,dst,ETH_ALEN);
848 while(skb->len > ETHERNET_HEADER_SIZE) {
849 /* Offset 12 denote 2 mac address */
850 nSubframe_Length = *((u16*)(skb->data + 12));
851 //==m==>change the length order
852 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
854 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
855 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
856 __FUNCTION__,rxb->nr_subframes);
857 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
858 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
859 printk("The Packet SeqNum is %d\n",SeqNum);
860 return 0;
863 /* move the data point to data content */
864 skb_pull(skb, ETHERNET_HEADER_SIZE);
866 #ifdef JOHN_NOCPY
867 sub_skb = skb_clone(skb, GFP_ATOMIC);
868 sub_skb->len = nSubframe_Length;
869 sub_skb->tail = sub_skb->data + nSubframe_Length;
870 #else
871 /* Allocate new skb for releasing to upper layer */
872 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
873 skb_reserve(sub_skb, 12);
874 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
875 memcpy(data_ptr,skb->data,nSubframe_Length);
876 #endif
877 rxb->subframes[rxb->nr_subframes++] = sub_skb;
878 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
879 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
880 break;
882 skb_pull(skb,nSubframe_Length);
884 if(skb->len != 0) {
885 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
886 if(nPadding_Length == 4) {
887 nPadding_Length = 0;
890 if(skb->len < nPadding_Length) {
891 return 0;
894 skb_pull(skb,nPadding_Length);
897 #ifdef JOHN_NOCPY
898 dev_kfree_skb(skb);
899 #endif
900 //{just for debug added by david
901 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
903 return rxb->nr_subframes;
907 /* All received frames are sent to this function. @skb contains the frame in
908 * IEEE 802.11 format, i.e., in the format it was sent over air.
909 * This function is called only as a tasklet (software IRQ). */
910 int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
911 struct ieee80211_rx_stats *rx_stats)
913 struct net_device *dev = ieee->dev;
914 struct ieee80211_hdr_4addr *hdr;
915 //struct ieee80211_hdr_3addrqos *hdr;
917 size_t hdrlen;
918 u16 fc, type, stype, sc;
919 struct net_device_stats *stats;
920 unsigned int frag;
921 u8 *payload;
922 u16 ethertype;
923 //added by amy for reorder
924 u8 TID = 0;
925 u16 SeqNum = 0;
926 PRX_TS_RECORD pTS = NULL;
927 bool unicast_packet = false;
928 //bool bIsAggregateFrame = false;
929 //added by amy for reorder
930 #ifdef NOT_YET
931 struct net_device *wds = NULL;
932 struct sk_buff *skb2 = NULL;
933 struct net_device *wds = NULL;
934 int frame_authorized = 0;
935 int from_assoc_ap = 0;
936 void *sta = NULL;
937 #endif
938 // u16 qos_ctl = 0;
939 u8 dst[ETH_ALEN];
940 u8 src[ETH_ALEN];
941 u8 bssid[ETH_ALEN];
942 struct ieee80211_crypt_data *crypt = NULL;
943 int keyidx = 0;
945 int i;
946 struct ieee80211_rxb* rxb = NULL;
947 // cheat the the hdr type
948 hdr = (struct ieee80211_hdr_4addr *)skb->data;
949 stats = &ieee->stats;
951 if (skb->len < 10) {
952 printk(KERN_INFO "%s: SKB length < 10\n",
953 dev->name);
954 goto rx_dropped;
957 fc = le16_to_cpu(hdr->frame_ctl);
958 type = WLAN_FC_GET_TYPE(fc);
959 stype = WLAN_FC_GET_STYPE(fc);
960 sc = le16_to_cpu(hdr->seq_ctl);
962 frag = WLAN_GET_SEQ_FRAG(sc);
963 hdrlen = ieee80211_get_hdrlen(fc);
965 if(HTCCheck(ieee, skb->data))
967 if(net_ratelimit())
968 printk("find HTCControl\n");
969 hdrlen += 4;
970 rx_stats->bContainHTC = 1;
973 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
974 #ifdef NOT_YET
975 #if WIRELESS_EXT > 15
976 /* Put this code here so that we avoid duplicating it in all
977 * Rx paths. - Jean II */
978 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
979 /* If spy monitoring on */
980 if (iface->spy_data.spy_number > 0) {
981 struct iw_quality wstats;
982 wstats.level = rx_stats->rssi;
983 wstats.noise = rx_stats->noise;
984 wstats.updated = 6; /* No qual value */
985 /* Update spy records */
986 wireless_spy_update(dev, hdr->addr2, &wstats);
988 #endif /* IW_WIRELESS_SPY */
989 #endif /* WIRELESS_EXT > 15 */
990 hostap_update_rx_stats(local->ap, hdr, rx_stats);
991 #endif
993 #if WIRELESS_EXT > 15
994 if (ieee->iw_mode == IW_MODE_MONITOR) {
995 ieee80211_monitor_rx(ieee, skb, rx_stats);
996 stats->rx_packets++;
997 stats->rx_bytes += skb->len;
998 return 1;
1000 #endif
1001 if (ieee->host_decrypt) {
1002 int idx = 0;
1003 if (skb->len >= hdrlen + 3)
1004 idx = skb->data[hdrlen + 3] >> 6;
1005 crypt = ieee->crypt[idx];
1006 #ifdef NOT_YET
1007 sta = NULL;
1009 /* Use station specific key to override default keys if the
1010 * receiver address is a unicast address ("individual RA"). If
1011 * bcrx_sta_key parameter is set, station specific key is used
1012 * even with broad/multicast targets (this is against IEEE
1013 * 802.11, but makes it easier to use different keys with
1014 * stations that do not support WEP key mapping). */
1016 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1017 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1018 &sta);
1019 #endif
1021 /* allow NULL decrypt to indicate an station specific override
1022 * for default encryption */
1023 if (crypt && (crypt->ops == NULL ||
1024 crypt->ops->decrypt_mpdu == NULL))
1025 crypt = NULL;
1027 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
1028 /* This seems to be triggered by some (multicast?)
1029 * frames from other than current BSS, so just drop the
1030 * frames silently instead of filling system log with
1031 * these reports. */
1032 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1033 " (SA=%pM)\n",
1034 hdr->addr2);
1035 ieee->ieee_stats.rx_discards_undecryptable++;
1036 goto rx_dropped;
1040 if (skb->len < IEEE80211_DATA_HDR3_LEN)
1041 goto rx_dropped;
1043 // if QoS enabled, should check the sequence for each of the AC
1044 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
1045 if (is_duplicate_packet(ieee, hdr))
1046 goto rx_dropped;
1049 else
1051 PRX_TS_RECORD pRxTS = NULL;
1052 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1053 if(GetTs(
1054 ieee,
1055 (PTS_COMMON_INFO*) &pRxTS,
1056 hdr->addr2,
1057 (u8)Frame_QoSTID((u8*)(skb->data)),
1058 RX_DIR,
1059 true))
1062 // 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));
1063 if( (fc & (1<<11)) &&
1064 (frag == pRxTS->RxLastFragNum) &&
1065 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
1067 goto rx_dropped;
1069 else
1071 pRxTS->RxLastFragNum = frag;
1072 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1075 else
1077 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
1078 goto rx_dropped;
1081 if (type == IEEE80211_FTYPE_MGMT) {
1084 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1085 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1086 goto rx_dropped;
1087 else
1088 goto rx_exit;
1091 /* Data frame - extract src/dst addresses */
1092 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1093 case IEEE80211_FCTL_FROMDS:
1094 memcpy(dst, hdr->addr1, ETH_ALEN);
1095 memcpy(src, hdr->addr3, ETH_ALEN);
1096 memcpy(bssid, hdr->addr2, ETH_ALEN);
1097 break;
1098 case IEEE80211_FCTL_TODS:
1099 memcpy(dst, hdr->addr3, ETH_ALEN);
1100 memcpy(src, hdr->addr2, ETH_ALEN);
1101 memcpy(bssid, hdr->addr1, ETH_ALEN);
1102 break;
1103 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1104 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1105 goto rx_dropped;
1106 memcpy(dst, hdr->addr3, ETH_ALEN);
1107 memcpy(src, hdr->addr4, ETH_ALEN);
1108 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1109 break;
1110 case 0:
1111 memcpy(dst, hdr->addr1, ETH_ALEN);
1112 memcpy(src, hdr->addr2, ETH_ALEN);
1113 memcpy(bssid, hdr->addr3, ETH_ALEN);
1114 break;
1117 #ifdef NOT_YET
1118 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1119 goto rx_dropped;
1120 if (wds) {
1121 skb->dev = dev = wds;
1122 stats = hostap_get_stats(dev);
1125 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1126 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1127 ieee->stadev &&
1128 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1129 /* Frame from BSSID of the AP for which we are a client */
1130 skb->dev = dev = ieee->stadev;
1131 stats = hostap_get_stats(dev);
1132 from_assoc_ap = 1;
1134 #endif
1136 dev->last_rx = jiffies;
1138 #ifdef NOT_YET
1139 if ((ieee->iw_mode == IW_MODE_MASTER ||
1140 ieee->iw_mode == IW_MODE_REPEAT) &&
1141 !from_assoc_ap) {
1142 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1143 wds != NULL)) {
1144 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1145 frame_authorized = 0;
1146 break;
1147 case AP_RX_CONTINUE:
1148 frame_authorized = 1;
1149 break;
1150 case AP_RX_DROP:
1151 goto rx_dropped;
1152 case AP_RX_EXIT:
1153 goto rx_exit;
1156 #endif
1157 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1158 /* Nullfunc frames may have PS-bit set, so they must be passed to
1159 * hostap_handle_sta_rx() before being dropped here. */
1160 if (stype != IEEE80211_STYPE_DATA &&
1161 stype != IEEE80211_STYPE_DATA_CFACK &&
1162 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1163 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1164 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1166 if (stype != IEEE80211_STYPE_NULLFUNC)
1167 IEEE80211_DEBUG_DROP(
1168 "RX: dropped data frame "
1169 "with no data (type=0x%02x, "
1170 "subtype=0x%02x, len=%d)\n",
1171 type, stype, skb->len);
1172 goto rx_dropped;
1174 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1175 goto rx_dropped;
1177 #ifdef ENABLE_LPS
1178 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == 1)
1179 && (ieee->polling)) {
1180 if (WLAN_FC_MORE_DATA(fc)) {
1181 /* more data bit is set, let's request a new frame from the AP */
1182 ieee80211_sta_ps_send_pspoll_frame(ieee);
1183 } else {
1184 ieee->polling = false;
1187 #endif
1189 ieee->need_sw_enc = 0;
1191 if((!rx_stats->Decrypted)){
1192 ieee->need_sw_enc = 1;
1195 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1197 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1198 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1200 printk("decrypt frame error\n");
1201 goto rx_dropped;
1205 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1207 /* skb: hdr + (possibly fragmented) plaintext payload */
1208 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1209 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1210 int flen;
1211 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1212 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1214 if (!frag_skb) {
1215 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1216 "Rx cannot get skb from fragment "
1217 "cache (morefrag=%d seq=%u frag=%u)\n",
1218 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1219 WLAN_GET_SEQ_SEQ(sc), frag);
1220 goto rx_dropped;
1222 flen = skb->len;
1223 if (frag != 0)
1224 flen -= hdrlen;
1226 if (frag_skb->tail + flen > frag_skb->end) {
1227 printk(KERN_WARNING "%s: host decrypted and "
1228 "reassembled frame did not fit skb\n",
1229 dev->name);
1230 ieee80211_frag_cache_invalidate(ieee, hdr);
1231 goto rx_dropped;
1234 if (frag == 0) {
1235 /* copy first fragment (including full headers) into
1236 * beginning of the fragment cache skb */
1237 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1238 } else {
1239 /* append frame payload to the end of the fragment
1240 * cache skb */
1241 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1242 flen);
1244 dev_kfree_skb_any(skb);
1245 skb = NULL;
1247 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1248 /* more fragments expected - leave the skb in fragment
1249 * cache for now; it will be delivered to upper layers
1250 * after all fragments have been received */
1251 goto rx_exit;
1254 /* this was the last fragment and the frame will be
1255 * delivered, so remove skb from fragment cache */
1256 skb = frag_skb;
1257 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1258 ieee80211_frag_cache_invalidate(ieee, hdr);
1261 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1262 * encrypted/authenticated */
1263 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1264 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1266 printk("==>decrypt msdu error\n");
1267 goto rx_dropped;
1270 //added by amy for AP roaming
1271 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1272 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1274 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1275 if((!is_multicast_ether_addr(hdr->addr1)) && (!is_broadcast_ether_addr(hdr->addr1)))
1276 unicast_packet = true;
1278 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1279 if (/*ieee->ieee802_1x &&*/
1280 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1282 #ifdef CONFIG_IEEE80211_DEBUG
1283 /* pass unencrypted EAPOL frames even if encryption is
1284 * configured */
1285 struct eapol *eap = (struct eapol *)(skb->data +
1286 24);
1287 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1288 eap_get_type(eap->type));
1289 #endif
1290 } else {
1291 IEEE80211_DEBUG_DROP(
1292 "encryption configured, but RX "
1293 "frame not encrypted (SA=%pM)\n",
1294 hdr->addr2);
1295 goto rx_dropped;
1299 #ifdef CONFIG_IEEE80211_DEBUG
1300 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1301 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1302 struct eapol *eap = (struct eapol *)(skb->data +
1303 24);
1304 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1305 eap_get_type(eap->type));
1307 #endif
1309 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1310 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1311 IEEE80211_DEBUG_DROP(
1312 "dropped unencrypted RX data "
1313 "frame from %pM"
1314 " (drop_unencrypted=1)\n",
1315 hdr->addr2);
1316 goto rx_dropped;
1319 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1320 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1323 //added by amy for reorder
1324 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1325 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1327 TID = Frame_QoSTID(skb->data);
1328 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1329 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1330 if(TID !=0 && TID !=3)
1332 ieee->bis_any_nonbepkts = true;
1335 //added by amy for reorder
1336 /* skb: hdr + (possible reassembled) full plaintext payload */
1337 payload = skb->data + hdrlen;
1338 //ethertype = (payload[6] << 8) | payload[7];
1339 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1340 if(rxb == NULL)
1342 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1343 goto rx_dropped;
1345 /* to parse amsdu packets */
1346 /* qos data packets & reserved bit is 1 */
1347 if(parse_subframe(ieee, skb,rx_stats,rxb,src,dst) == 0) {
1348 /* only to free rxb, and not submit the packets to upper layer */
1349 for(i =0; i < rxb->nr_subframes; i++) {
1350 dev_kfree_skb(rxb->subframes[i]);
1352 kfree(rxb);
1353 rxb = NULL;
1354 goto rx_dropped;
1357 #ifdef ENABLE_LPS
1358 if(unicast_packet)
1360 if (type == IEEE80211_FTYPE_DATA)
1363 if(ieee->bIsAggregateFrame)
1364 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod+=rxb->nr_subframes;
1365 else
1366 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod++;
1368 // 2009.03.03 Leave DC mode immediately when detect high traffic
1369 // DbgPrint("ending Seq %d\n", Frame_SeqNum(pduOS));
1370 if((ieee->state == IEEE80211_LINKED) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/)
1372 if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
1373 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
1375 if(ieee->LeisurePSLeave)
1376 ieee->LeisurePSLeave(dev);
1381 #endif
1383 ieee->last_rx_ps_time = jiffies;
1384 //added by amy for reorder
1385 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1386 //added by amy for reorder
1387 for(i = 0; i<rxb->nr_subframes; i++) {
1388 struct sk_buff *sub_skb = rxb->subframes[i];
1390 if (sub_skb) {
1391 /* convert hdr + possible LLC headers into Ethernet header */
1392 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1393 if (sub_skb->len >= 8 &&
1394 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1395 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1396 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1397 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1398 * replace EtherType */
1399 skb_pull(sub_skb, SNAP_SIZE);
1400 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1401 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1402 } else {
1403 u16 len;
1404 /* Leave Ethernet header part of hdr and full payload */
1405 len = htons(sub_skb->len);
1406 memcpy(skb_push(sub_skb, 2), &len, 2);
1407 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1408 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1411 stats->rx_packets++;
1412 stats->rx_bytes += sub_skb->len;
1413 if(is_multicast_ether_addr(dst)) {
1414 stats->multicast++;
1417 /* Indicat the packets to upper layer */
1418 //printk("0skb_len(%d)\n", skb->len);
1419 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1420 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1421 sub_skb->dev = dev;
1422 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1423 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1424 //printk("1skb_len(%d)\n", skb->len);
1425 netif_rx(sub_skb);
1428 kfree(rxb);
1429 rxb = NULL;
1432 else
1434 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1435 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1437 #ifndef JOHN_NOCPY
1438 dev_kfree_skb(skb);
1439 #endif
1441 rx_exit:
1442 #ifdef NOT_YET
1443 if (sta)
1444 hostap_handle_sta_release(sta);
1445 #endif
1446 return 1;
1448 rx_dropped:
1449 if (rxb != NULL)
1451 kfree(rxb);
1452 rxb = NULL;
1454 stats->rx_dropped++;
1456 /* Returning 0 indicates to caller that we have not handled the SKB--
1457 * so it is still allocated and can be used again by underlying
1458 * hardware as a DMA target */
1459 return 0;
1462 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1464 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1467 * Make ther structure we read from the beacon packet has
1468 * the right values
1470 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1471 *info_element, int sub_type)
1474 if (info_element->qui_subtype != sub_type)
1475 return -1;
1476 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1477 return -1;
1478 if (info_element->qui_type != QOS_OUI_TYPE)
1479 return -1;
1480 if (info_element->version != QOS_VERSION_1)
1481 return -1;
1483 return 0;
1488 * Parse a QoS parameter element
1490 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1491 *element_param, struct ieee80211_info_element
1492 *info_element)
1494 int ret = 0;
1495 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1497 if ((info_element == NULL) || (element_param == NULL))
1498 return -1;
1500 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1501 memcpy(element_param->info_element.qui, info_element->data,
1502 info_element->len);
1503 element_param->info_element.elementID = info_element->id;
1504 element_param->info_element.length = info_element->len;
1505 } else
1506 ret = -1;
1507 if (ret == 0)
1508 ret = ieee80211_verify_qos_info(&element_param->info_element,
1509 QOS_OUI_PARAM_SUB_TYPE);
1510 return ret;
1514 * Parse a QoS information element
1516 static int ieee80211_read_qos_info_element(struct
1517 ieee80211_qos_information_element
1518 *element_info, struct ieee80211_info_element
1519 *info_element)
1521 int ret = 0;
1522 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1524 if (element_info == NULL)
1525 return -1;
1526 if (info_element == NULL)
1527 return -1;
1529 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1530 memcpy(element_info->qui, info_element->data,
1531 info_element->len);
1532 element_info->elementID = info_element->id;
1533 element_info->length = info_element->len;
1534 } else
1535 ret = -1;
1537 if (ret == 0)
1538 ret = ieee80211_verify_qos_info(element_info,
1539 QOS_OUI_INFO_SUB_TYPE);
1540 return ret;
1545 * Write QoS parameters from the ac parameters.
1547 static int ieee80211_qos_convert_ac_to_parameters(struct
1548 ieee80211_qos_parameter_info
1549 *param_elm, struct
1550 ieee80211_qos_parameters
1551 *qos_param)
1553 int rc = 0;
1554 int i;
1555 struct ieee80211_qos_ac_parameter *ac_params;
1556 u8 aci;
1557 //u8 cw_min;
1558 //u8 cw_max;
1560 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1561 ac_params = &(param_elm->ac_params_record[i]);
1563 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1565 if(aci >= QOS_QUEUE_NUM)
1566 continue;
1567 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1569 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1570 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1572 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1574 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1576 qos_param->flag[aci] =
1577 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1578 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1580 return rc;
1584 * we have a generic data element which it may contain QoS information or
1585 * parameters element. check the information element length to decide
1586 * which type to read
1588 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1589 *info_element,
1590 struct ieee80211_network *network)
1592 int rc = 0;
1593 struct ieee80211_qos_parameters *qos_param = NULL;
1594 struct ieee80211_qos_information_element qos_info_element;
1596 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1598 if (rc == 0) {
1599 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1600 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1601 } else {
1602 struct ieee80211_qos_parameter_info param_element;
1604 rc = ieee80211_read_qos_param_element(&param_element,
1605 info_element);
1606 if (rc == 0) {
1607 qos_param = &(network->qos_data.parameters);
1608 ieee80211_qos_convert_ac_to_parameters(&param_element,
1609 qos_param);
1610 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1611 network->qos_data.param_count =
1612 param_element.info_element.ac_info & 0x0F;
1616 if (rc == 0) {
1617 IEEE80211_DEBUG_QOS("QoS is supported\n");
1618 network->qos_data.supported = 1;
1620 return rc;
1623 #ifdef CONFIG_IEEE80211_DEBUG
1624 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1626 static const char *get_info_element_string(u16 id)
1628 switch (id) {
1629 MFIE_STRING(SSID);
1630 MFIE_STRING(RATES);
1631 MFIE_STRING(FH_SET);
1632 MFIE_STRING(DS_SET);
1633 MFIE_STRING(CF_SET);
1634 MFIE_STRING(TIM);
1635 MFIE_STRING(IBSS_SET);
1636 MFIE_STRING(COUNTRY);
1637 MFIE_STRING(HOP_PARAMS);
1638 MFIE_STRING(HOP_TABLE);
1639 MFIE_STRING(REQUEST);
1640 MFIE_STRING(CHALLENGE);
1641 MFIE_STRING(POWER_CONSTRAINT);
1642 MFIE_STRING(POWER_CAPABILITY);
1643 MFIE_STRING(TPC_REQUEST);
1644 MFIE_STRING(TPC_REPORT);
1645 MFIE_STRING(SUPP_CHANNELS);
1646 MFIE_STRING(CSA);
1647 MFIE_STRING(MEASURE_REQUEST);
1648 MFIE_STRING(MEASURE_REPORT);
1649 MFIE_STRING(QUIET);
1650 MFIE_STRING(IBSS_DFS);
1651 // MFIE_STRING(ERP_INFO);
1652 MFIE_STRING(RSN);
1653 MFIE_STRING(RATES_EX);
1654 MFIE_STRING(GENERIC);
1655 MFIE_STRING(QOS_PARAMETER);
1656 default:
1657 return "UNKNOWN";
1660 #endif
1662 #ifdef ENABLE_DOT11D
1663 static inline void ieee80211_extract_country_ie(
1664 struct ieee80211_device *ieee,
1665 struct ieee80211_info_element *info_element,
1666 struct ieee80211_network *network,
1667 u8 * addr2
1670 if(IS_DOT11D_ENABLE(ieee))
1672 if(info_element->len!= 0)
1674 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1675 network->CountryIeLen = info_element->len;
1677 if(!IS_COUNTRY_IE_VALID(ieee))
1679 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1684 // 070305, rcnjko: I update country IE watch dog here because
1685 // some AP (e.g. Cisco 1242) don't include country IE in their
1686 // probe response frame.
1688 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1690 UPDATE_CIE_WATCHDOG(ieee);
1695 #endif
1697 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1698 struct ieee80211_info_element *info_element,
1699 u16 length,
1700 struct ieee80211_network *network,
1701 struct ieee80211_rx_stats *stats)
1703 u8 i;
1704 short offset;
1705 u16 tmp_htcap_len=0;
1706 u16 tmp_htinfo_len=0;
1707 u16 ht_realtek_agg_len=0;
1708 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1709 // u16 broadcom_len = 0;
1710 #ifdef CONFIG_IEEE80211_DEBUG
1711 char rates_str[64];
1712 char *p;
1713 #endif
1715 while (length >= sizeof(*info_element)) {
1716 if (sizeof(*info_element) + info_element->len > length) {
1717 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1718 "info_element->len + 2 > left : "
1719 "info_element->len+2=%zd left=%d, id=%d.\n",
1720 info_element->len +
1721 sizeof(*info_element),
1722 length, info_element->id);
1723 /* We stop processing but don't return an error here
1724 * because some misbehaviour APs break this rule. ie.
1725 * Orinoco AP1000. */
1726 break;
1729 switch (info_element->id) {
1730 case MFIE_TYPE_SSID:
1731 if (ieee80211_is_empty_essid(info_element->data,
1732 info_element->len)) {
1733 network->flags |= NETWORK_EMPTY_ESSID;
1734 break;
1737 network->ssid_len = min(info_element->len,
1738 (u8) IW_ESSID_MAX_SIZE);
1739 memcpy(network->ssid, info_element->data, network->ssid_len);
1740 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1741 memset(network->ssid + network->ssid_len, 0,
1742 IW_ESSID_MAX_SIZE - network->ssid_len);
1744 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1745 network->ssid, network->ssid_len);
1746 break;
1748 case MFIE_TYPE_RATES:
1749 #ifdef CONFIG_IEEE80211_DEBUG
1750 p = rates_str;
1751 #endif
1752 network->rates_len = min(info_element->len,
1753 MAX_RATES_LENGTH);
1754 for (i = 0; i < network->rates_len; i++) {
1755 network->rates[i] = info_element->data[i];
1756 #ifdef CONFIG_IEEE80211_DEBUG
1757 p += snprintf(p, sizeof(rates_str) -
1758 (p - rates_str), "%02X ",
1759 network->rates[i]);
1760 #endif
1761 if (ieee80211_is_ofdm_rate
1762 (info_element->data[i])) {
1763 network->flags |= NETWORK_HAS_OFDM;
1764 if (info_element->data[i] &
1765 IEEE80211_BASIC_RATE_MASK)
1766 network->flags &=
1767 ~NETWORK_HAS_CCK;
1771 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1772 rates_str, network->rates_len);
1773 break;
1775 case MFIE_TYPE_RATES_EX:
1776 #ifdef CONFIG_IEEE80211_DEBUG
1777 p = rates_str;
1778 #endif
1779 network->rates_ex_len = min(info_element->len,
1780 MAX_RATES_EX_LENGTH);
1781 for (i = 0; i < network->rates_ex_len; i++) {
1782 network->rates_ex[i] = info_element->data[i];
1783 #ifdef CONFIG_IEEE80211_DEBUG
1784 p += snprintf(p, sizeof(rates_str) -
1785 (p - rates_str), "%02X ",
1786 network->rates[i]);
1787 #endif
1788 if (ieee80211_is_ofdm_rate
1789 (info_element->data[i])) {
1790 network->flags |= NETWORK_HAS_OFDM;
1791 if (info_element->data[i] &
1792 IEEE80211_BASIC_RATE_MASK)
1793 network->flags &=
1794 ~NETWORK_HAS_CCK;
1798 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1799 rates_str, network->rates_ex_len);
1800 break;
1802 case MFIE_TYPE_DS_SET:
1803 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1804 info_element->data[0]);
1805 network->channel = info_element->data[0];
1806 break;
1808 case MFIE_TYPE_FH_SET:
1809 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1810 break;
1812 case MFIE_TYPE_CF_SET:
1813 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1814 break;
1816 case MFIE_TYPE_TIM:
1817 if(info_element->len < 4)
1818 break;
1820 network->tim.tim_count = info_element->data[0];
1821 network->tim.tim_period = info_element->data[1];
1823 network->dtim_period = info_element->data[1];
1824 if(ieee->state != IEEE80211_LINKED)
1825 break;
1826 //we use jiffies for legacy Power save
1827 network->last_dtim_sta_time[0] = jiffies;
1828 network->last_dtim_sta_time[1] = stats->mac_time[1];
1830 network->dtim_data = IEEE80211_DTIM_VALID;
1832 if(info_element->data[0] != 0)
1833 break;
1835 if(info_element->data[2] & 1)
1836 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1838 offset = (info_element->data[2] >> 1)*2;
1840 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1842 if(ieee->assoc_id < 8*offset ||
1843 ieee->assoc_id > 8*(offset + info_element->len -3))
1845 break;
1847 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1849 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1850 network->dtim_data |= IEEE80211_DTIM_UCAST;
1852 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1853 break;
1855 case MFIE_TYPE_ERP:
1856 network->erp_value = info_element->data[0];
1857 network->flags |= NETWORK_HAS_ERP_VALUE;
1858 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1859 network->erp_value);
1860 break;
1861 case MFIE_TYPE_IBSS_SET:
1862 network->atim_window = info_element->data[0];
1863 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1864 network->atim_window);
1865 break;
1867 case MFIE_TYPE_CHALLENGE:
1868 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1869 break;
1871 case MFIE_TYPE_GENERIC:
1872 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1873 info_element->len);
1874 if (!ieee80211_parse_qos_info_param_IE(info_element,
1875 network))
1876 break;
1878 if (info_element->len >= 4 &&
1879 info_element->data[0] == 0x00 &&
1880 info_element->data[1] == 0x50 &&
1881 info_element->data[2] == 0xf2 &&
1882 info_element->data[3] == 0x01) {
1883 network->wpa_ie_len = min(info_element->len + 2,
1884 MAX_WPA_IE_LEN);
1885 memcpy(network->wpa_ie, info_element,
1886 network->wpa_ie_len);
1887 break;
1890 #ifdef THOMAS_TURBO
1891 if (info_element->len == 7 &&
1892 info_element->data[0] == 0x00 &&
1893 info_element->data[1] == 0xe0 &&
1894 info_element->data[2] == 0x4c &&
1895 info_element->data[3] == 0x01 &&
1896 info_element->data[4] == 0x02) {
1897 network->Turbo_Enable = 1;
1899 #endif
1901 //for HTcap and HTinfo parameters
1902 if(tmp_htcap_len == 0){
1903 if(info_element->len >= 4 &&
1904 info_element->data[0] == 0x00 &&
1905 info_element->data[1] == 0x90 &&
1906 info_element->data[2] == 0x4c &&
1907 info_element->data[3] == 0x033){
1909 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1910 if(tmp_htcap_len != 0){
1911 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1912 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1913 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1914 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1917 if(tmp_htcap_len != 0)
1918 network->bssht.bdSupportHT = true;
1919 else
1920 network->bssht.bdSupportHT = false;
1924 if(tmp_htinfo_len == 0){
1925 if(info_element->len >= 4 &&
1926 info_element->data[0] == 0x00 &&
1927 info_element->data[1] == 0x90 &&
1928 info_element->data[2] == 0x4c &&
1929 info_element->data[3] == 0x034){
1931 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1932 if(tmp_htinfo_len != 0){
1933 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1934 if(tmp_htinfo_len){
1935 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1936 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1937 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1945 if(ieee->aggregation){
1946 if(network->bssht.bdSupportHT){
1947 if(info_element->len >= 4 &&
1948 info_element->data[0] == 0x00 &&
1949 info_element->data[1] == 0xe0 &&
1950 info_element->data[2] == 0x4c &&
1951 info_element->data[3] == 0x02){
1953 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
1954 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
1957 if(ht_realtek_agg_len >= 5){
1958 network->bssht.bdRT2RTAggregation = true;
1960 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1961 network->bssht.bdRT2RTLongSlotTime = true;
1967 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1969 if((info_element->len >= 3 &&
1970 info_element->data[0] == 0x00 &&
1971 info_element->data[1] == 0x05 &&
1972 info_element->data[2] == 0xb5) ||
1973 (info_element->len >= 3 &&
1974 info_element->data[0] == 0x00 &&
1975 info_element->data[1] == 0x0a &&
1976 info_element->data[2] == 0xf7) ||
1977 (info_element->len >= 3 &&
1978 info_element->data[0] == 0x00 &&
1979 info_element->data[1] == 0x10 &&
1980 info_element->data[2] == 0x18)){
1982 network->broadcom_cap_exist = true;
1986 if(info_element->len >= 3 &&
1987 info_element->data[0] == 0x00 &&
1988 info_element->data[1] == 0x0c &&
1989 info_element->data[2] == 0x43)
1991 network->ralink_cap_exist = true;
1993 else
1994 network->ralink_cap_exist = false;
1995 //added by amy for atheros AP
1996 if((info_element->len >= 3 &&
1997 info_element->data[0] == 0x00 &&
1998 info_element->data[1] == 0x03 &&
1999 info_element->data[2] == 0x7f) ||
2000 (info_element->len >= 3 &&
2001 info_element->data[0] == 0x00 &&
2002 info_element->data[1] == 0x13 &&
2003 info_element->data[2] == 0x74))
2005 //printk("========>%s(): athros AP is exist\n",__FUNCTION__);
2006 network->atheros_cap_exist = true;
2008 else
2009 network->atheros_cap_exist = false;
2011 if ((info_element->len >= 3 &&
2012 info_element->data[0] == 0x00 &&
2013 info_element->data[1] == 0x50 &&
2014 info_element->data[2] == 0x43) )
2016 network->marvell_cap_exist = true;
2017 //printk("========>%s(): marvel AP is exist\n",__FUNCTION__);
2021 if(info_element->len >= 3 &&
2022 info_element->data[0] == 0x00 &&
2023 info_element->data[1] == 0x40 &&
2024 info_element->data[2] == 0x96)
2026 network->cisco_cap_exist = true;
2028 else
2029 network->cisco_cap_exist = false;
2030 //added by amy for LEAP of cisco
2031 if(info_element->len > 4 &&
2032 info_element->data[0] == 0x00 &&
2033 info_element->data[1] == 0x40 &&
2034 info_element->data[2] == 0x96 &&
2035 info_element->data[3] == 0x01)
2037 if(info_element->len == 6)
2039 memcpy(network->CcxRmState, &info_element[4], 2);
2040 if(network->CcxRmState[0] != 0)
2042 network->bCcxRmEnable = true;
2044 else
2045 network->bCcxRmEnable = false;
2047 // CCXv4 Table 59-1 MBSSID Masks.
2049 network->MBssidMask = network->CcxRmState[1] & 0x07;
2050 if(network->MBssidMask != 0)
2052 network->bMBssidValid = true;
2053 network->MBssidMask = 0xff << (network->MBssidMask);
2054 cpMacAddr(network->MBssid, network->bssid);
2055 network->MBssid[5] &= network->MBssidMask;
2057 else
2059 network->bMBssidValid = false;
2062 else
2064 network->bCcxRmEnable = false;
2067 if(info_element->len > 4 &&
2068 info_element->data[0] == 0x00 &&
2069 info_element->data[1] == 0x40 &&
2070 info_element->data[2] == 0x96 &&
2071 info_element->data[3] == 0x03)
2073 if(info_element->len == 5)
2075 network->bWithCcxVerNum = true;
2076 network->BssCcxVerNumber = info_element->data[4];
2078 else
2080 network->bWithCcxVerNum = false;
2081 network->BssCcxVerNumber = 0;
2084 break;
2086 case MFIE_TYPE_RSN:
2087 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2088 info_element->len);
2089 network->rsn_ie_len = min(info_element->len + 2,
2090 MAX_WPA_IE_LEN);
2091 memcpy(network->rsn_ie, info_element,
2092 network->rsn_ie_len);
2093 break;
2095 //HT related element.
2096 case MFIE_TYPE_HT_CAP:
2097 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2098 info_element->len);
2099 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2100 if(tmp_htcap_len != 0){
2101 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2102 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2103 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2104 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2106 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2107 // windows driver will update WMM parameters each beacon received once connected
2108 // Linux driver is a bit different.
2109 network->bssht.bdSupportHT = true;
2111 else
2112 network->bssht.bdSupportHT = false;
2113 break;
2116 case MFIE_TYPE_HT_INFO:
2117 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2118 info_element->len);
2119 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2120 if(tmp_htinfo_len){
2121 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2122 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2123 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2124 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2126 break;
2128 case MFIE_TYPE_AIRONET:
2129 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2130 info_element->len);
2131 if(info_element->len >IE_CISCO_FLAG_POSITION)
2133 network->bWithAironetIE = true;
2135 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2136 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2137 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2138 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
2139 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
2141 network->bCkipSupported = true;
2143 else
2145 network->bCkipSupported = false;
2148 else
2150 network->bWithAironetIE = false;
2151 network->bCkipSupported = false;
2153 break;
2154 case MFIE_TYPE_QOS_PARAMETER:
2155 printk(KERN_ERR
2156 "QoS Error need to parse QOS_PARAMETER IE\n");
2157 break;
2159 #ifdef ENABLE_DOT11D
2160 case MFIE_TYPE_COUNTRY:
2161 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2162 info_element->len);
2163 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2164 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2165 break;
2166 #endif
2167 /* TODO */
2168 default:
2169 IEEE80211_DEBUG_MGMT
2170 ("Unsupported info element: %s (%d)\n",
2171 get_info_element_string(info_element->id),
2172 info_element->id);
2173 break;
2176 length -= sizeof(*info_element) + info_element->len;
2177 info_element =
2178 (struct ieee80211_info_element *)&info_element->
2179 data[info_element->len];
2182 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2183 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation &&
2184 !network->marvell_cap_exist)
2186 network->unknown_cap_exist = true;
2188 else
2190 network->unknown_cap_exist = false;
2192 return 0;
2195 static inline u8 ieee80211_SignalStrengthTranslate(
2196 u8 CurrSS
2199 u8 RetSS;
2201 // Step 1. Scale mapping.
2202 if(CurrSS >= 71 && CurrSS <= 100)
2204 RetSS = 90 + ((CurrSS - 70) / 3);
2206 else if(CurrSS >= 41 && CurrSS <= 70)
2208 RetSS = 78 + ((CurrSS - 40) / 3);
2210 else if(CurrSS >= 31 && CurrSS <= 40)
2212 RetSS = 66 + (CurrSS - 30);
2214 else if(CurrSS >= 21 && CurrSS <= 30)
2216 RetSS = 54 + (CurrSS - 20);
2218 else if(CurrSS >= 5 && CurrSS <= 20)
2220 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2222 else if(CurrSS == 4)
2224 RetSS = 36;
2226 else if(CurrSS == 3)
2228 RetSS = 27;
2230 else if(CurrSS == 2)
2232 RetSS = 18;
2234 else if(CurrSS == 1)
2236 RetSS = 9;
2238 else
2240 RetSS = CurrSS;
2242 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2244 // Step 2. Smoothing.
2246 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2248 return RetSS;
2251 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2253 long signal_power; // in dBm.
2255 // Translate to dBm (x=0.5y-95).
2256 signal_power = (long)((signal_strength_index + 1) >> 1);
2257 signal_power -= 95;
2259 return signal_power;
2262 static inline int ieee80211_network_init(
2263 struct ieee80211_device *ieee,
2264 struct ieee80211_probe_response *beacon,
2265 struct ieee80211_network *network,
2266 struct ieee80211_rx_stats *stats)
2268 #ifdef CONFIG_IEEE80211_DEBUG
2269 //char rates_str[64];
2270 //char *p;
2271 #endif
2273 network->qos_data.active = 0;
2274 network->qos_data.supported = 0;
2275 network->qos_data.param_count = 0;
2276 network->qos_data.old_param_count = 0;
2278 /* Pull out fixed field data */
2279 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2280 network->capability = le16_to_cpu(beacon->capability);
2281 network->last_scanned = jiffies;
2282 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2283 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2284 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2285 /* Where to pull this? beacon->listen_interval;*/
2286 network->listen_interval = 0x0A;
2287 network->rates_len = network->rates_ex_len = 0;
2288 network->last_associate = 0;
2289 network->ssid_len = 0;
2290 network->flags = 0;
2291 network->atim_window = 0;
2292 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2293 0x3 : 0x0;
2294 network->berp_info_valid = false;
2295 network->broadcom_cap_exist = false;
2296 network->ralink_cap_exist = false;
2297 network->atheros_cap_exist = false;
2298 network->marvell_cap_exist = false;
2299 network->cisco_cap_exist = false;
2300 network->unknown_cap_exist = false;
2301 #ifdef THOMAS_TURBO
2302 network->Turbo_Enable = 0;
2303 #endif
2304 #ifdef ENABLE_DOT11D
2305 network->CountryIeLen = 0;
2306 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2307 #endif
2308 //Initialize HT parameters
2309 //ieee80211_ht_initialize(&network->bssht);
2310 HTInitializeBssDesc(&network->bssht);
2311 if (stats->freq == IEEE80211_52GHZ_BAND) {
2312 /* for A band (No DS info) */
2313 network->channel = stats->received_channel;
2314 } else
2315 network->flags |= NETWORK_HAS_CCK;
2317 network->wpa_ie_len = 0;
2318 network->rsn_ie_len = 0;
2320 if (ieee80211_parse_info_param
2321 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2322 return 1;
2324 network->mode = 0;
2325 if (stats->freq == IEEE80211_52GHZ_BAND)
2326 network->mode = IEEE_A;
2327 else {
2328 if (network->flags & NETWORK_HAS_OFDM)
2329 network->mode |= IEEE_G;
2330 if (network->flags & NETWORK_HAS_CCK)
2331 network->mode |= IEEE_B;
2334 if (network->mode == 0) {
2335 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2336 "network.\n",
2337 escape_essid(network->ssid,
2338 network->ssid_len),
2339 network->bssid);
2340 return 1;
2343 if(network->bssht.bdSupportHT){
2344 if(network->mode == IEEE_A)
2345 network->mode = IEEE_N_5G;
2346 else if(network->mode & (IEEE_G | IEEE_B))
2347 network->mode = IEEE_N_24G;
2349 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2350 network->flags |= NETWORK_EMPTY_ESSID;
2352 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2353 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2354 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2356 memcpy(&network->stats, stats, sizeof(network->stats));
2358 return 0;
2361 static inline int is_same_network(struct ieee80211_network *src,
2362 struct ieee80211_network *dst, struct ieee80211_device* ieee)
2364 /* A network is only a duplicate if the channel, BSSID, ESSID
2365 * and the capability field (in particular IBSS and BSS) all match.
2366 * We treat all <hidden> with the same BSSID and channel
2367 * as one network */
2368 return //((src->ssid_len == dst->ssid_len) &&
2369 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2370 (src->channel == dst->channel) &&
2371 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2372 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2373 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2374 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2375 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2376 ((src->capability & WLAN_CAPABILITY_BSS) ==
2377 (dst->capability & WLAN_CAPABILITY_BSS)));
2380 static inline void update_network(struct ieee80211_network *dst,
2381 struct ieee80211_network *src)
2383 int qos_active;
2384 u8 old_param;
2386 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2387 dst->capability = src->capability;
2388 memcpy(dst->rates, src->rates, src->rates_len);
2389 dst->rates_len = src->rates_len;
2390 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2391 dst->rates_ex_len = src->rates_ex_len;
2392 if(src->ssid_len > 0)
2394 memset(dst->ssid, 0, dst->ssid_len);
2395 dst->ssid_len = src->ssid_len;
2396 memcpy(dst->ssid, src->ssid, src->ssid_len);
2398 dst->mode = src->mode;
2399 dst->flags = src->flags;
2400 dst->time_stamp[0] = src->time_stamp[0];
2401 dst->time_stamp[1] = src->time_stamp[1];
2402 if (src->flags & NETWORK_HAS_ERP_VALUE)
2404 dst->erp_value = src->erp_value;
2405 dst->berp_info_valid = src->berp_info_valid = true;
2407 dst->beacon_interval = src->beacon_interval;
2408 dst->listen_interval = src->listen_interval;
2409 dst->atim_window = src->atim_window;
2410 dst->dtim_period = src->dtim_period;
2411 dst->dtim_data = src->dtim_data;
2412 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2413 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2414 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2416 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2417 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2418 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2419 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2420 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2421 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2422 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2423 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2424 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2425 dst->ralink_cap_exist = src->ralink_cap_exist;
2426 dst->atheros_cap_exist = src->atheros_cap_exist;
2427 dst->marvell_cap_exist = src->marvell_cap_exist;
2428 dst->cisco_cap_exist = src->cisco_cap_exist;
2429 dst->unknown_cap_exist = src->unknown_cap_exist;
2430 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2431 dst->wpa_ie_len = src->wpa_ie_len;
2432 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2433 dst->rsn_ie_len = src->rsn_ie_len;
2435 dst->last_scanned = jiffies;
2436 /* qos related parameters */
2437 //qos_active = src->qos_data.active;
2438 qos_active = dst->qos_data.active;
2439 //old_param = dst->qos_data.old_param_count;
2440 old_param = dst->qos_data.param_count;
2441 if(dst->flags & NETWORK_HAS_QOS_MASK){
2442 //not update QOS paramter in beacon, as most AP will set all these parameter to 0.//WB
2443 // printk("====>%s(), aifs:%x, %x\n", __FUNCTION__, dst->qos_data.parameters.aifs[0], src->qos_data.parameters.aifs[0]);
2444 // memcpy(&dst->qos_data, &src->qos_data,
2445 // sizeof(struct ieee80211_qos_data));
2447 else {
2448 dst->qos_data.supported = src->qos_data.supported;
2449 dst->qos_data.param_count = src->qos_data.param_count;
2452 if(dst->qos_data.supported == 1) {
2453 dst->QoS_Enable = 1;
2454 if(dst->ssid_len)
2455 IEEE80211_DEBUG_QOS
2456 ("QoS the network %s is QoS supported\n",
2457 dst->ssid);
2458 else
2459 IEEE80211_DEBUG_QOS
2460 ("QoS the network is QoS supported\n");
2462 dst->qos_data.active = qos_active;
2463 dst->qos_data.old_param_count = old_param;
2465 /* dst->last_associate is not overwritten */
2466 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2467 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2468 src->wmm_param[1].ac_aci_acm_aifsn|| \
2469 src->wmm_param[2].ac_aci_acm_aifsn|| \
2470 src->wmm_param[1].ac_aci_acm_aifsn) {
2471 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2473 //dst->QoS_Enable = src->QoS_Enable;
2474 #ifdef THOMAS_TURBO
2475 dst->Turbo_Enable = src->Turbo_Enable;
2476 #endif
2478 #ifdef ENABLE_DOT11D
2479 dst->CountryIeLen = src->CountryIeLen;
2480 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2481 #endif
2483 //added by amy for LEAP
2484 dst->bWithAironetIE = src->bWithAironetIE;
2485 dst->bCkipSupported = src->bCkipSupported;
2486 memcpy(dst->CcxRmState,src->CcxRmState,2);
2487 dst->bCcxRmEnable = src->bCcxRmEnable;
2488 dst->MBssidMask = src->MBssidMask;
2489 dst->bMBssidValid = src->bMBssidValid;
2490 memcpy(dst->MBssid,src->MBssid,6);
2491 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2492 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2496 static inline int is_beacon(__le16 fc)
2498 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2501 static inline void ieee80211_process_probe_response(
2502 struct ieee80211_device *ieee,
2503 struct ieee80211_probe_response *beacon,
2504 struct ieee80211_rx_stats *stats)
2506 struct ieee80211_network network;
2507 struct ieee80211_network *target;
2508 struct ieee80211_network *oldest = NULL;
2509 #ifdef CONFIG_IEEE80211_DEBUG
2510 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2511 #endif
2512 unsigned long flags;
2513 short renew;
2514 //u8 wmm_info;
2516 memset(&network, 0, sizeof(struct ieee80211_network));
2517 IEEE80211_DEBUG_SCAN(
2518 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2519 escape_essid(info_element->data, info_element->len),
2520 beacon->header.addr3,
2521 (beacon->capability & (1<<0xf)) ? '1' : '0',
2522 (beacon->capability & (1<<0xe)) ? '1' : '0',
2523 (beacon->capability & (1<<0xd)) ? '1' : '0',
2524 (beacon->capability & (1<<0xc)) ? '1' : '0',
2525 (beacon->capability & (1<<0xb)) ? '1' : '0',
2526 (beacon->capability & (1<<0xa)) ? '1' : '0',
2527 (beacon->capability & (1<<0x9)) ? '1' : '0',
2528 (beacon->capability & (1<<0x8)) ? '1' : '0',
2529 (beacon->capability & (1<<0x7)) ? '1' : '0',
2530 (beacon->capability & (1<<0x6)) ? '1' : '0',
2531 (beacon->capability & (1<<0x5)) ? '1' : '0',
2532 (beacon->capability & (1<<0x4)) ? '1' : '0',
2533 (beacon->capability & (1<<0x3)) ? '1' : '0',
2534 (beacon->capability & (1<<0x2)) ? '1' : '0',
2535 (beacon->capability & (1<<0x1)) ? '1' : '0',
2536 (beacon->capability & (1<<0x0)) ? '1' : '0');
2538 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2539 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2540 escape_essid(info_element->data,
2541 info_element->len),
2542 beacon->header.addr3,
2543 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2544 IEEE80211_STYPE_PROBE_RESP ?
2545 "PROBE RESPONSE" : "BEACON");
2546 return;
2549 #ifdef ENABLE_DOT11D
2550 // For Asus EeePc request,
2551 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2552 // wireless adapter should follow the country code.
2553 // (2) If there is no any country code in beacon,
2554 // then wireless adapter should do active scan from ch1~11 and
2555 // passive scan from ch12~14
2557 if( !IsLegalChannel(ieee, network.channel) )
2558 return;
2559 if(ieee->bGlobalDomain)
2561 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2563 // Case 1: Country code
2564 if(IS_COUNTRY_IE_VALID(ieee) )
2566 if( !IsLegalChannel(ieee, network.channel) )
2568 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2569 return;
2572 // Case 2: No any country code.
2573 else
2575 // Filter over channel ch12~14
2576 if(network.channel > 11)
2578 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2579 return;
2583 else
2585 // Case 1: Country code
2586 if(IS_COUNTRY_IE_VALID(ieee) )
2588 if( !IsLegalChannel(ieee, network.channel) )
2590 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2591 return;
2594 // Case 2: No any country code.
2595 else
2597 // Filter over channel ch12~14
2598 if(network.channel > 14)
2600 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2601 return;
2606 #endif
2608 /* The network parsed correctly -- so now we scan our known networks
2609 * to see if we can find it in our list.
2611 * NOTE: This search is definitely not optimized. Once its doing
2612 * the "right thing" we'll optimize it for efficiency if
2613 * necessary */
2615 /* Search for this entry in the list and update it if it is
2616 * already there. */
2618 spin_lock_irqsave(&ieee->lock, flags);
2620 if(is_same_network(&ieee->current_network, &network, ieee)) {
2621 update_network(&ieee->current_network, &network);
2622 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2623 && ieee->current_network.berp_info_valid){
2624 if(ieee->current_network.erp_value& ERP_UseProtection)
2625 ieee->current_network.buseprotection = true;
2626 else
2627 ieee->current_network.buseprotection = false;
2629 if(is_beacon(beacon->header.frame_ctl))
2631 if(ieee->state == IEEE80211_LINKED)
2632 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2634 else //hidden AP
2635 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2638 list_for_each_entry(target, &ieee->network_list, list) {
2639 if (is_same_network(target, &network, ieee))
2640 break;
2641 if ((oldest == NULL) ||
2642 (target->last_scanned < oldest->last_scanned))
2643 oldest = target;
2646 /* If we didn't find a match, then get a new network slot to initialize
2647 * with this beacon's information */
2648 if (&target->list == &ieee->network_list) {
2649 if (list_empty(&ieee->network_free_list)) {
2650 /* If there are no more slots, expire the oldest */
2651 list_del(&oldest->list);
2652 target = oldest;
2653 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2654 "network list.\n",
2655 escape_essid(target->ssid,
2656 target->ssid_len),
2657 target->bssid);
2658 } else {
2659 /* Otherwise just pull from the free list */
2660 target = list_entry(ieee->network_free_list.next,
2661 struct ieee80211_network, list);
2662 list_del(ieee->network_free_list.next);
2666 #ifdef CONFIG_IEEE80211_DEBUG
2667 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2668 escape_essid(network.ssid,
2669 network.ssid_len),
2670 network.bssid,
2671 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2672 IEEE80211_STYPE_PROBE_RESP ?
2673 "PROBE RESPONSE" : "BEACON");
2674 #endif
2675 memcpy(target, &network, sizeof(*target));
2676 list_add_tail(&target->list, &ieee->network_list);
2677 } else {
2678 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2679 escape_essid(target->ssid,
2680 target->ssid_len),
2681 target->bssid,
2682 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2683 IEEE80211_STYPE_PROBE_RESP ?
2684 "PROBE RESPONSE" : "BEACON");
2686 /* we have an entry and we are going to update it. But this entry may
2687 * be already expired. In this case we do the same as we found a new
2688 * net and call the new_net handler
2690 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2691 //YJ,add,080819,for hidden ap
2692 if(is_beacon(beacon->header.frame_ctl) == 0)
2693 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2694 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2695 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2696 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2697 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2698 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2699 renew = 1;
2700 //YJ,add,080819,for hidden ap,end
2702 update_network(target, &network);
2705 spin_unlock_irqrestore(&ieee->lock, flags);
2706 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2707 (ieee->state == IEEE80211_LINKED)) {
2708 if(ieee->handle_beacon != NULL) {
2709 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2714 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2715 struct ieee80211_hdr_4addr *header,
2716 struct ieee80211_rx_stats *stats)
2719 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2720 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2721 ieee->last_rx_ps_time = jiffies;
2723 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2725 case IEEE80211_STYPE_BEACON:
2726 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2727 WLAN_FC_GET_STYPE(header->frame_ctl));
2728 IEEE80211_DEBUG_SCAN("Beacon\n");
2729 ieee80211_process_probe_response(
2730 ieee, (struct ieee80211_probe_response *)header, stats);
2732 //printk("----------->%s()\n", __func__);
2733 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2734 ieee->iw_mode == IW_MODE_INFRA &&
2735 ieee->state == IEEE80211_LINKED))
2737 tasklet_schedule(&ieee->ps_task);
2740 break;
2742 case IEEE80211_STYPE_PROBE_RESP:
2743 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2744 WLAN_FC_GET_STYPE(header->frame_ctl));
2745 IEEE80211_DEBUG_SCAN("Probe response\n");
2746 ieee80211_process_probe_response(
2747 ieee, (struct ieee80211_probe_response *)header, stats);
2748 break;