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
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
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>
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"
50 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
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);
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));
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;
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)) {
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);
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)
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;
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;
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;
128 /* Reserve enough space to fit maximum frame length */
129 skb = dev_alloc_skb(ieee->dev->mtu +
130 sizeof(struct ieee80211_hdr_4addr) +
135 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
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;
149 entry->last_frag = frag;
151 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
152 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
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,
159 entry->last_frag = frag;
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;
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;
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;
194 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
198 IEEE80211_DEBUG_FRAG(
199 "could not invalidate fragment cache "
200 "entry (seq=%u)\n", seq);
210 /* ieee80211_rx_frame_mgtmt
212 * Responsible for handling management control frames
214 * Called by ieee80211_rx */
216 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
217 struct ieee80211_rx_stats *rx_stats, u16 type,
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);
235 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
237 dev_kfree_skb_any(skb);
242 if (ieee->iw_mode == IW_MODE_MASTER) {
243 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
247 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
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);
259 hostap_rx(skb2->dev, skb2, rx_stats);
262 /* send management frames to the user space daemon for
264 ieee->apdevstats.rx_packets++;
265 ieee->apdevstats.rx_bytes += skb->len;
266 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
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);
278 hostap_rx(skb->dev, skb, rx_stats);
282 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
283 "received in non-Host AP mode\n", skb->dev->name);
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;
305 struct ieee80211_hdr_4addr *hdr;
312 if (ieee->hwsec_active)
314 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
315 tcb_desc->bHwSec = 1;
317 if(ieee->need_sw_enc)
318 tcb_desc->bHwSec = 0;
322 hdr = (struct ieee80211_hdr_4addr *) skb->data;
323 fc = le16_to_cpu(hdr->frame_ctl);
325 /* check that the frame is unicast frame to us */
326 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
327 IEEE80211_FCTL_TODS &&
328 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
329 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
330 /* ToDS frame with own addr BSSID and DA */
331 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
332 IEEE80211_FCTL_FROMDS &&
333 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
334 /* FromDS frame with own addr as DA */
338 if (skb->len < 24 + 8)
341 /* check for port access entity Ethernet type */
342 // pos = skb->data + 24;
343 pos = skb->data + hdrlen;
344 ethertype = (pos[6] << 8) | pos[7];
345 if (ethertype == ETH_P_PAE)
351 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
353 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
354 struct ieee80211_crypt_data *crypt)
356 struct ieee80211_hdr_4addr *hdr;
359 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
362 if (ieee->hwsec_active)
364 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
365 tcb_desc->bHwSec = 1;
368 hdr = (struct ieee80211_hdr_4addr *) skb->data;
369 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
371 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
372 if (ieee->tkip_countermeasures &&
373 strcmp(crypt->ops->name, "TKIP") == 0) {
374 if (net_ratelimit()) {
375 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
376 "received packet from %pM\n",
377 ieee->dev->name, hdr->addr2);
383 atomic_inc(&crypt->refcnt);
384 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
385 atomic_dec(&crypt->refcnt);
387 IEEE80211_DEBUG_DROP(
388 "decryption failed (SA=%pM"
389 ") res=%d\n", hdr->addr2, res);
391 IEEE80211_DEBUG_DROP("Decryption failed ICV "
392 "mismatch (key %d)\n",
393 skb->data[hdrlen + 3] >> 6);
394 ieee->ieee_stats.rx_discards_undecryptable++;
402 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
404 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
405 int keyidx, struct ieee80211_crypt_data *crypt)
407 struct ieee80211_hdr_4addr *hdr;
410 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
412 if (ieee->hwsec_active)
414 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
415 tcb_desc->bHwSec = 1;
417 if(ieee->need_sw_enc)
418 tcb_desc->bHwSec = 0;
422 hdr = (struct ieee80211_hdr_4addr *) skb->data;
423 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
425 atomic_inc(&crypt->refcnt);
426 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
427 atomic_dec(&crypt->refcnt);
429 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
430 " (SA=%pM keyidx=%d)\n",
431 ieee->dev->name, hdr->addr2, keyidx);
439 /* this function is stolen from ipw2200 driver*/
440 #define IEEE_PACKET_RETRY_TIME (5*HZ)
441 static int is_duplicate_packet(struct ieee80211_device *ieee,
442 struct ieee80211_hdr_4addr *header)
444 u16 fc = le16_to_cpu(header->frame_ctl);
445 u16 sc = le16_to_cpu(header->seq_ctl);
446 u16 seq = WLAN_GET_SEQ_SEQ(sc);
447 u16 frag = WLAN_GET_SEQ_FRAG(sc);
448 u16 *last_seq, *last_frag;
449 unsigned long *last_time;
450 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
451 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
456 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
457 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
458 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
461 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
462 hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
463 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
470 switch (ieee->iw_mode) {
474 struct ieee_ibss_seq *entry = NULL;
475 u8 *mac = header->addr2;
476 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
477 //for (pos = (head)->next; pos != (head); pos = pos->next)
478 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
479 list_for_each(p, &ieee->ibss_mac_hash[index]) {
480 entry = list_entry(p, struct ieee_ibss_seq, list);
481 if (!memcmp(entry->mac, mac, ETH_ALEN))
484 // if (memcmp(entry->mac, mac, ETH_ALEN)){
485 if (p == &ieee->ibss_mac_hash[index]) {
486 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
488 printk(KERN_WARNING "Cannot malloc new mac entry\n");
491 memcpy(entry->mac, mac, ETH_ALEN);
492 entry->seq_num[tid] = seq;
493 entry->frag_num[tid] = frag;
494 entry->packet_time[tid] = jiffies;
495 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
498 last_seq = &entry->seq_num[tid];
499 last_frag = &entry->frag_num[tid];
500 last_time = &entry->packet_time[tid];
505 last_seq = &ieee->last_rxseq_num[tid];
506 last_frag = &ieee->last_rxfrag_num[tid];
507 last_time = &ieee->last_packet_time[tid];
515 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
517 if ((*last_seq == seq) &&
518 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
519 if (*last_frag == frag){
520 //printk(KERN_WARNING "[1] go drop!\n");
524 if (*last_frag + 1 != frag)
525 /* out-of-order fragment */
526 //printk(KERN_WARNING "[2] go drop!\n");
532 *last_time = jiffies;
536 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
544 PRX_REORDER_ENTRY pReorderEntry
547 struct list_head *pList = &pTS->RxPendingPktList;
549 while(pList->next != &pTS->RxPendingPktList)
551 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
555 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
565 pReorderEntry->List.next = pList->next;
566 pReorderEntry->List.next->prev = &pReorderEntry->List;
567 pReorderEntry->List.prev = pList;
568 pList->next = &pReorderEntry->List;
573 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index)
578 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
579 for(j = 0; j<index; j++)
581 //added by amy for reorder
582 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
583 for(i = 0; i<prxb->nr_subframes; i++) {
584 struct sk_buff *sub_skb = prxb->subframes[i];
586 /* convert hdr + possible LLC headers into Ethernet header */
587 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
588 if (sub_skb->len >= 8 &&
589 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
590 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
591 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
592 /* remove RFC1042 or Bridge-Tunnel encapsulation and
593 * replace EtherType */
594 skb_pull(sub_skb, SNAP_SIZE);
595 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
596 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
599 /* Leave Ethernet header part of hdr and full payload */
600 len = htons(sub_skb->len);
601 memcpy(skb_push(sub_skb, 2), &len, 2);
602 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
603 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
605 //stats->rx_packets++;
606 //stats->rx_bytes += sub_skb->len;
608 /* Indicat the packets to upper layer */
610 //printk("0skb_len(%d)\n", skb->len);
611 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
612 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
613 sub_skb->dev = ieee->dev;
614 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
615 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
616 ieee->last_rx_ps_time = jiffies;
617 //printk("1skb_len(%d)\n", skb->len);
627 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
628 struct ieee80211_rxb* prxb,
632 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
633 PRX_REORDER_ENTRY pReorderEntry = NULL;
634 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
635 u8 WinSize = pHTInfo->RxReorderWinSize;
636 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
638 bool bMatchWinStart = false, bPktInBuf = false;
639 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
641 if(!list_empty(&ieee->RxReorder_Unused_List))
642 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): ieee->RxReorder_Unused_List is nut NULL\n");
644 /* Rx Reorder initialize condition.*/
645 if(pTS->RxIndicateSeq == 0xffff) {
646 pTS->RxIndicateSeq = SeqNum;
649 /* Drop out the packet which SeqNum is smaller than WinStart */
650 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
651 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
652 pTS->RxIndicateSeq, SeqNum);
653 pHTInfo->RxReorderDropCounter++;
656 for(i =0; i < prxb->nr_subframes; i++) {
657 dev_kfree_skb(prxb->subframes[i]);
666 * Sliding window manipulation. Conditions includes:
667 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
668 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
670 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
671 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
672 bMatchWinStart = true;
673 } else if(SN_LESS(WinEnd, SeqNum)) {
674 if(SeqNum >= (WinSize - 1)) {
675 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
677 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
679 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
683 * Indication process.
684 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
685 * with the SeqNum smaller than latest WinStart and buffer other packets.
687 /* For Rx Reorder condition:
688 * 1. All packets with SeqNum smaller than WinStart => Indicate
689 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
692 /* Current packet is going to be indicated.*/
693 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
694 pTS->RxIndicateSeq, SeqNum);
695 prxbIndicateArray[0] = prxb;
696 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
699 /* Current packet is going to be inserted into pending list.*/
700 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
701 if(!list_empty(&ieee->RxReorder_Unused_List)) {
702 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
703 list_del_init(&pReorderEntry->List);
705 /* Make a reorder entry and insert into a the packet list.*/
706 pReorderEntry->SeqNum = SeqNum;
707 pReorderEntry->prxb = prxb;
708 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
711 if(!AddReorderEntry(pTS, pReorderEntry)) {
712 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
713 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
714 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
717 for(i =0; i < prxb->nr_subframes; i++) {
718 dev_kfree_skb(prxb->subframes[i]);
724 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
725 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
731 * Packets are dropped if there is not enough reorder entries.
732 * This part shall be modified!! We can just indicate all the
733 * packets in buffer and get reorder entries.
735 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
738 for(i =0; i < prxb->nr_subframes; i++) {
739 dev_kfree_skb(prxb->subframes[i]);
747 /* Check if there is any packet need indicate.*/
748 while(!list_empty(&pTS->RxPendingPktList)) {
749 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
751 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
752 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
753 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
755 /* This protect buffer from overflow. */
756 if(index >= REORDER_WIN_SIZE) {
757 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
762 list_del_init(&pReorderEntry->List);
764 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
765 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
767 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
768 prxbIndicateArray[index] = pReorderEntry->prxb;
769 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
772 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
780 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
782 // Cancel previous pending timer.
783 if (timer_pending(&pTS->RxPktPendingTimer))
784 del_timer_sync(&pTS->RxPktPendingTimer);
785 pTS->RxTimeoutIndicateSeq = 0xffff;
788 if(index>REORDER_WIN_SIZE){
789 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
792 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
797 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
798 // Set new pending timer.
799 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
800 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
802 if(timer_pending(&pTS->RxPktPendingTimer))
803 del_timer_sync(&pTS->RxPktPendingTimer);
804 pTS->RxPktPendingTimer.expires = jiffies + MSECS(pHTInfo->RxReorderPendingTime);
805 add_timer(&pTS->RxPktPendingTimer);
807 mod_timer(&pTS->RxPktPendingTimer, jiffies + MSECS(pHTInfo->RxReorderPendingTime));
813 u8 parse_subframe(struct ieee80211_device* ieee,struct sk_buff *skb,
814 struct ieee80211_rx_stats *rx_stats,
815 struct ieee80211_rxb *rxb,u8* src,u8* dst)
817 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
818 u16 fc = le16_to_cpu(hdr->frame_ctl);
820 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
822 bool bIsAggregateFrame = false;
823 u16 nSubframe_Length;
824 u8 nPadding_Length = 0;
827 struct sk_buff *sub_skb;
829 /* just for debug purpose */
830 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
832 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
833 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
834 bIsAggregateFrame = true;
837 if(IEEE80211_QOS_HAS_SEQ(fc)) {
841 if(rx_stats->bContainHTC) {
842 LLCOffset += sHTCLng;
844 //printk("ChkLength = %d\n", LLCOffset);
845 // Null packet, don't indicate it to upper layer
846 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
848 if( skb->len <= ChkLength ) {
852 skb_pull(skb, LLCOffset);
853 ieee->bIsAggregateFrame = bIsAggregateFrame;//added by amy for Leisure PS
855 if(!bIsAggregateFrame) {
856 rxb->nr_subframes = 1;
858 rxb->subframes[0] = skb;
860 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
863 memcpy(rxb->src,src,ETH_ALEN);
864 memcpy(rxb->dst,dst,ETH_ALEN);
865 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
868 rxb->nr_subframes = 0;
869 memcpy(rxb->src,src,ETH_ALEN);
870 memcpy(rxb->dst,dst,ETH_ALEN);
871 while(skb->len > ETHERNET_HEADER_SIZE) {
872 /* Offset 12 denote 2 mac address */
873 nSubframe_Length = *((u16*)(skb->data + 12));
874 //==m==>change the length order
875 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
877 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
880 (nRemain_Length>=(ETHERNET_HEADER_SIZE + nSubframe_Length)),
881 ("ParseSubframe(): A-MSDU subframe parse error!! Subframe Length: %d\n", nSubframe_Length) );
883 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
884 __FUNCTION__,rxb->nr_subframes);
885 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
886 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
887 printk("The Packet SeqNum is %d\n",SeqNum);
891 /* move the data point to data content */
892 skb_pull(skb, ETHERNET_HEADER_SIZE);
895 sub_skb = skb_clone(skb, GFP_ATOMIC);
896 sub_skb->len = nSubframe_Length;
897 sub_skb->tail = sub_skb->data + nSubframe_Length;
899 /* Allocate new skb for releasing to upper layer */
900 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
901 skb_reserve(sub_skb, 12);
902 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
903 memcpy(data_ptr,skb->data,nSubframe_Length);
905 rxb->subframes[rxb->nr_subframes++] = sub_skb;
906 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
907 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
910 skb_pull(skb,nSubframe_Length);
913 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
914 if(nPadding_Length == 4) {
918 if(skb->len < nPadding_Length) {
922 skb_pull(skb,nPadding_Length);
928 //{just for debug added by david
929 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
931 return rxb->nr_subframes;
935 /* All received frames are sent to this function. @skb contains the frame in
936 * IEEE 802.11 format, i.e., in the format it was sent over air.
937 * This function is called only as a tasklet (software IRQ). */
938 int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
939 struct ieee80211_rx_stats *rx_stats)
941 struct net_device *dev = ieee->dev;
942 struct ieee80211_hdr_4addr *hdr;
943 //struct ieee80211_hdr_3addrqos *hdr;
946 u16 fc, type, stype, sc;
947 struct net_device_stats *stats;
951 //added by amy for reorder
954 PRX_TS_RECORD pTS = NULL;
955 bool unicast_packet = false;
956 //bool bIsAggregateFrame = false;
957 //added by amy for reorder
959 struct net_device *wds = NULL;
960 struct sk_buff *skb2 = NULL;
961 struct net_device *wds = NULL;
962 int frame_authorized = 0;
963 int from_assoc_ap = 0;
970 struct ieee80211_crypt_data *crypt = NULL;
974 struct ieee80211_rxb* rxb = NULL;
975 // cheat the the hdr type
976 hdr = (struct ieee80211_hdr_4addr *)skb->data;
977 stats = &ieee->stats;
980 printk(KERN_INFO "%s: SKB length < 10\n",
985 fc = le16_to_cpu(hdr->frame_ctl);
986 type = WLAN_FC_GET_TYPE(fc);
987 stype = WLAN_FC_GET_STYPE(fc);
988 sc = le16_to_cpu(hdr->seq_ctl);
990 frag = WLAN_GET_SEQ_FRAG(sc);
991 hdrlen = ieee80211_get_hdrlen(fc);
993 if(HTCCheck(ieee, skb->data))
996 printk("find HTCControl\n");
998 rx_stats->bContainHTC = 1;
1001 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1003 #if WIRELESS_EXT > 15
1004 /* Put this code here so that we avoid duplicating it in all
1005 * Rx paths. - Jean II */
1006 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
1007 /* If spy monitoring on */
1008 if (iface->spy_data.spy_number > 0) {
1009 struct iw_quality wstats;
1010 wstats.level = rx_stats->rssi;
1011 wstats.noise = rx_stats->noise;
1012 wstats.updated = 6; /* No qual value */
1013 /* Update spy records */
1014 wireless_spy_update(dev, hdr->addr2, &wstats);
1016 #endif /* IW_WIRELESS_SPY */
1017 #endif /* WIRELESS_EXT > 15 */
1018 hostap_update_rx_stats(local->ap, hdr, rx_stats);
1021 #if WIRELESS_EXT > 15
1022 if (ieee->iw_mode == IW_MODE_MONITOR) {
1023 ieee80211_monitor_rx(ieee, skb, rx_stats);
1024 stats->rx_packets++;
1025 stats->rx_bytes += skb->len;
1029 if (ieee->host_decrypt) {
1031 if (skb->len >= hdrlen + 3)
1032 idx = skb->data[hdrlen + 3] >> 6;
1033 crypt = ieee->crypt[idx];
1037 /* Use station specific key to override default keys if the
1038 * receiver address is a unicast address ("individual RA"). If
1039 * bcrx_sta_key parameter is set, station specific key is used
1040 * even with broad/multicast targets (this is against IEEE
1041 * 802.11, but makes it easier to use different keys with
1042 * stations that do not support WEP key mapping). */
1044 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1045 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1049 /* allow NULL decrypt to indicate an station specific override
1050 * for default encryption */
1051 if (crypt && (crypt->ops == NULL ||
1052 crypt->ops->decrypt_mpdu == NULL))
1055 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
1056 /* This seems to be triggered by some (multicast?)
1057 * frames from other than current BSS, so just drop the
1058 * frames silently instead of filling system log with
1060 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1063 ieee->ieee_stats.rx_discards_undecryptable++;
1068 if (skb->len < IEEE80211_DATA_HDR3_LEN)
1071 // if QoS enabled, should check the sequence for each of the AC
1072 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
1073 if (is_duplicate_packet(ieee, hdr))
1079 PRX_TS_RECORD pRxTS = NULL;
1081 struct ieee80211_hdr_3addr *hdr;
1083 hdr = (struct ieee80211_hdr_3addr *)skb->data;
1084 fc = le16_to_cpu(hdr->frame_ctl);
1085 u8 tmp = (fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS);
1087 u8 tid = (*((u8*)skb->data + (((fc& IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))?30:24)))&0xf;
1088 printk("====================>fc:%x, tid:%d, tmp:%d\n", fc, tid, tmp);
1089 //u8 tid = (u8)((frameqos*)(buf + ((fc & IEEE80211_FCTL_TODS)&&(fc & IEEE80211_FCTL_FROMDS))? 30 : 24))->field.tid;
1091 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1095 (PTS_COMMON_INFO*) &pRxTS,
1097 (u8)Frame_QoSTID((u8*)(skb->data)),
1102 // 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));
1103 if( (fc & (1<<11)) &&
1104 (frag == pRxTS->RxLastFragNum) &&
1105 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
1111 pRxTS->RxLastFragNum = frag;
1112 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1117 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
1122 if (type == IEEE80211_FTYPE_MGMT) {
1125 if ( stype == IEEE80211_STYPE_AUTH &&
1126 fc & IEEE80211_FCTL_WEP && ieee->host_decrypt &&
1127 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1129 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
1130 "from %pM\n", dev->name,
1132 /* TODO: could inform hostapd about this so that it
1133 * could send auth failure report */
1138 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1139 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1145 /* Data frame - extract src/dst addresses */
1146 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1147 case IEEE80211_FCTL_FROMDS:
1148 memcpy(dst, hdr->addr1, ETH_ALEN);
1149 memcpy(src, hdr->addr3, ETH_ALEN);
1150 memcpy(bssid, hdr->addr2, ETH_ALEN);
1152 case IEEE80211_FCTL_TODS:
1153 memcpy(dst, hdr->addr3, ETH_ALEN);
1154 memcpy(src, hdr->addr2, ETH_ALEN);
1155 memcpy(bssid, hdr->addr1, ETH_ALEN);
1157 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1158 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1160 memcpy(dst, hdr->addr3, ETH_ALEN);
1161 memcpy(src, hdr->addr4, ETH_ALEN);
1162 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1165 memcpy(dst, hdr->addr1, ETH_ALEN);
1166 memcpy(src, hdr->addr2, ETH_ALEN);
1167 memcpy(bssid, hdr->addr3, ETH_ALEN);
1172 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1175 skb->dev = dev = wds;
1176 stats = hostap_get_stats(dev);
1179 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1180 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1182 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1183 /* Frame from BSSID of the AP for which we are a client */
1184 skb->dev = dev = ieee->stadev;
1185 stats = hostap_get_stats(dev);
1190 dev->last_rx = jiffies;
1193 if ((ieee->iw_mode == IW_MODE_MASTER ||
1194 ieee->iw_mode == IW_MODE_REPEAT) &&
1196 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1198 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1199 frame_authorized = 0;
1201 case AP_RX_CONTINUE:
1202 frame_authorized = 1;
1211 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1212 /* Nullfunc frames may have PS-bit set, so they must be passed to
1213 * hostap_handle_sta_rx() before being dropped here. */
1214 if (stype != IEEE80211_STYPE_DATA &&
1215 stype != IEEE80211_STYPE_DATA_CFACK &&
1216 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1217 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1218 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1220 if (stype != IEEE80211_STYPE_NULLFUNC)
1221 IEEE80211_DEBUG_DROP(
1222 "RX: dropped data frame "
1223 "with no data (type=0x%02x, "
1224 "subtype=0x%02x, len=%d)\n",
1225 type, stype, skb->len);
1228 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1232 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == 1)
1233 && (ieee->polling)) {
1234 if (WLAN_FC_MORE_DATA(fc)) {
1235 /* more data bit is set, let's request a new frame from the AP */
1236 ieee80211_sta_ps_send_pspoll_frame(ieee);
1238 ieee->polling = false;
1243 ieee->need_sw_enc = 0;
1245 if((!rx_stats->Decrypted)){
1246 ieee->need_sw_enc = 1;
1249 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1251 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1252 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1254 printk("decrypt frame error\n");
1259 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1261 /* skb: hdr + (possibly fragmented) plaintext payload */
1262 // PR: FIXME: hostap has additional conditions in the "if" below:
1263 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1264 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1266 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1267 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1270 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1271 "Rx cannot get skb from fragment "
1272 "cache (morefrag=%d seq=%u frag=%u)\n",
1273 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1274 WLAN_GET_SEQ_SEQ(sc), frag);
1281 if (frag_skb->tail + flen > frag_skb->end) {
1282 printk(KERN_WARNING "%s: host decrypted and "
1283 "reassembled frame did not fit skb\n",
1285 ieee80211_frag_cache_invalidate(ieee, hdr);
1290 /* copy first fragment (including full headers) into
1291 * beginning of the fragment cache skb */
1292 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1294 /* append frame payload to the end of the fragment
1296 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1299 dev_kfree_skb_any(skb);
1302 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1303 /* more fragments expected - leave the skb in fragment
1304 * cache for now; it will be delivered to upper layers
1305 * after all fragments have been received */
1309 /* this was the last fragment and the frame will be
1310 * delivered, so remove skb from fragment cache */
1312 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1313 ieee80211_frag_cache_invalidate(ieee, hdr);
1316 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1317 * encrypted/authenticated */
1318 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1319 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1321 printk("==>decrypt msdu error\n");
1325 //added by amy for AP roaming
1326 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1327 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1329 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1330 if((!is_multicast_ether_addr(hdr->addr1)) && (!is_broadcast_ether_addr(hdr->addr1)))
1331 unicast_packet = true;
1333 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1334 if (/*ieee->ieee802_1x &&*/
1335 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1337 #ifdef CONFIG_IEEE80211_DEBUG
1338 /* pass unencrypted EAPOL frames even if encryption is
1340 struct eapol *eap = (struct eapol *)(skb->data +
1342 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1343 eap_get_type(eap->type));
1346 IEEE80211_DEBUG_DROP(
1347 "encryption configured, but RX "
1348 "frame not encrypted (SA=%pM)\n",
1354 #ifdef CONFIG_IEEE80211_DEBUG
1355 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1356 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1357 struct eapol *eap = (struct eapol *)(skb->data +
1359 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1360 eap_get_type(eap->type));
1364 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1365 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1366 IEEE80211_DEBUG_DROP(
1367 "dropped unencrypted RX data "
1369 " (drop_unencrypted=1)\n",
1374 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1375 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1378 //added by amy for reorder
1380 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1381 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1383 TID = Frame_QoSTID(skb->data);
1384 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1385 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1386 if(TID !=0 && TID !=3)
1388 ieee->bis_any_nonbepkts = true;
1392 //added by amy for reorder
1393 /* skb: hdr + (possible reassembled) full plaintext payload */
1394 payload = skb->data + hdrlen;
1395 //ethertype = (payload[6] << 8) | payload[7];
1396 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1399 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1402 /* to parse amsdu packets */
1403 /* qos data packets & reserved bit is 1 */
1404 if(parse_subframe(ieee, skb,rx_stats,rxb,src,dst) == 0) {
1405 /* only to free rxb, and not submit the packets to upper layer */
1406 for(i =0; i < rxb->nr_subframes; i++) {
1407 dev_kfree_skb(rxb->subframes[i]);
1417 if (type == IEEE80211_FTYPE_DATA)
1420 if(ieee->bIsAggregateFrame)
1421 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod+=rxb->nr_subframes;
1423 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod++;
1425 // 2009.03.03 Leave DC mode immediately when detect high traffic
1426 // DbgPrint("ending Seq %d\n", Frame_SeqNum(pduOS));
1427 if((ieee->state == IEEE80211_LINKED) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/)
1429 if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
1430 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
1432 if(ieee->LeisurePSLeave)
1433 ieee->LeisurePSLeave(dev);
1440 ieee->last_rx_ps_time = jiffies;
1441 //added by amy for reorder
1442 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1443 //added by amy for reorder
1444 for(i = 0; i<rxb->nr_subframes; i++) {
1445 struct sk_buff *sub_skb = rxb->subframes[i];
1448 /* convert hdr + possible LLC headers into Ethernet header */
1449 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1450 if (sub_skb->len >= 8 &&
1451 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1452 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1453 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1454 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1455 * replace EtherType */
1456 skb_pull(sub_skb, SNAP_SIZE);
1457 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1458 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1461 /* Leave Ethernet header part of hdr and full payload */
1462 len = htons(sub_skb->len);
1463 memcpy(skb_push(sub_skb, 2), &len, 2);
1464 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1465 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1468 stats->rx_packets++;
1469 stats->rx_bytes += sub_skb->len;
1470 if(is_multicast_ether_addr(dst)) {
1474 /* Indicat the packets to upper layer */
1475 //printk("0skb_len(%d)\n", skb->len);
1476 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1477 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1479 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1480 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1481 //printk("1skb_len(%d)\n", skb->len);
1491 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1492 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1501 hostap_handle_sta_release(sta);
1511 stats->rx_dropped++;
1513 /* Returning 0 indicates to caller that we have not handled the SKB--
1514 * so it is still allocated and can be used again by underlying
1515 * hardware as a DMA target */
1519 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1521 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1524 * Make ther structure we read from the beacon packet has
1527 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1528 *info_element, int sub_type)
1531 if (info_element->qui_subtype != sub_type)
1533 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1535 if (info_element->qui_type != QOS_OUI_TYPE)
1537 if (info_element->version != QOS_VERSION_1)
1545 * Parse a QoS parameter element
1547 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1548 *element_param, struct ieee80211_info_element
1552 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1554 if ((info_element == NULL) || (element_param == NULL))
1557 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1558 memcpy(element_param->info_element.qui, info_element->data,
1560 element_param->info_element.elementID = info_element->id;
1561 element_param->info_element.length = info_element->len;
1565 ret = ieee80211_verify_qos_info(&element_param->info_element,
1566 QOS_OUI_PARAM_SUB_TYPE);
1571 * Parse a QoS information element
1573 static int ieee80211_read_qos_info_element(struct
1574 ieee80211_qos_information_element
1575 *element_info, struct ieee80211_info_element
1579 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1581 if (element_info == NULL)
1583 if (info_element == NULL)
1586 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1587 memcpy(element_info->qui, info_element->data,
1589 element_info->elementID = info_element->id;
1590 element_info->length = info_element->len;
1595 ret = ieee80211_verify_qos_info(element_info,
1596 QOS_OUI_INFO_SUB_TYPE);
1602 * Write QoS parameters from the ac parameters.
1604 static int ieee80211_qos_convert_ac_to_parameters(struct
1605 ieee80211_qos_parameter_info
1607 ieee80211_qos_parameters
1612 struct ieee80211_qos_ac_parameter *ac_params;
1617 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1618 ac_params = &(param_elm->ac_params_record[i]);
1620 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1622 if(aci >= QOS_QUEUE_NUM)
1624 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1626 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1627 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1629 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1631 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1633 qos_param->flag[aci] =
1634 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1635 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1641 * we have a generic data element which it may contain QoS information or
1642 * parameters element. check the information element length to decide
1643 * which type to read
1645 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1647 struct ieee80211_network *network)
1650 struct ieee80211_qos_parameters *qos_param = NULL;
1651 struct ieee80211_qos_information_element qos_info_element;
1653 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1656 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1657 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1659 struct ieee80211_qos_parameter_info param_element;
1661 rc = ieee80211_read_qos_param_element(¶m_element,
1664 qos_param = &(network->qos_data.parameters);
1665 ieee80211_qos_convert_ac_to_parameters(¶m_element,
1667 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1668 network->qos_data.param_count =
1669 param_element.info_element.ac_info & 0x0F;
1674 IEEE80211_DEBUG_QOS("QoS is supported\n");
1675 network->qos_data.supported = 1;
1680 #ifdef CONFIG_IEEE80211_DEBUG
1681 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1683 static const char *get_info_element_string(u16 id)
1688 MFIE_STRING(FH_SET);
1689 MFIE_STRING(DS_SET);
1690 MFIE_STRING(CF_SET);
1692 MFIE_STRING(IBSS_SET);
1693 MFIE_STRING(COUNTRY);
1694 MFIE_STRING(HOP_PARAMS);
1695 MFIE_STRING(HOP_TABLE);
1696 MFIE_STRING(REQUEST);
1697 MFIE_STRING(CHALLENGE);
1698 MFIE_STRING(POWER_CONSTRAINT);
1699 MFIE_STRING(POWER_CAPABILITY);
1700 MFIE_STRING(TPC_REQUEST);
1701 MFIE_STRING(TPC_REPORT);
1702 MFIE_STRING(SUPP_CHANNELS);
1704 MFIE_STRING(MEASURE_REQUEST);
1705 MFIE_STRING(MEASURE_REPORT);
1707 MFIE_STRING(IBSS_DFS);
1708 // MFIE_STRING(ERP_INFO);
1710 MFIE_STRING(RATES_EX);
1711 MFIE_STRING(GENERIC);
1712 MFIE_STRING(QOS_PARAMETER);
1719 #ifdef ENABLE_DOT11D
1720 static inline void ieee80211_extract_country_ie(
1721 struct ieee80211_device *ieee,
1722 struct ieee80211_info_element *info_element,
1723 struct ieee80211_network *network,
1727 if(IS_DOT11D_ENABLE(ieee))
1729 if(info_element->len!= 0)
1731 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1732 network->CountryIeLen = info_element->len;
1734 if(!IS_COUNTRY_IE_VALID(ieee))
1736 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1741 // 070305, rcnjko: I update country IE watch dog here because
1742 // some AP (e.g. Cisco 1242) don't include country IE in their
1743 // probe response frame.
1745 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1747 UPDATE_CIE_WATCHDOG(ieee);
1754 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1755 struct ieee80211_info_element *info_element,
1757 struct ieee80211_network *network,
1758 struct ieee80211_rx_stats *stats)
1762 u16 tmp_htcap_len=0;
1763 u16 tmp_htinfo_len=0;
1764 u16 ht_realtek_agg_len=0;
1765 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1766 // u16 broadcom_len = 0;
1767 #ifdef CONFIG_IEEE80211_DEBUG
1772 while (length >= sizeof(*info_element)) {
1773 if (sizeof(*info_element) + info_element->len > length) {
1774 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1775 "info_element->len + 2 > left : "
1776 "info_element->len+2=%zd left=%d, id=%d.\n",
1778 sizeof(*info_element),
1779 length, info_element->id);
1780 /* We stop processing but don't return an error here
1781 * because some misbehaviour APs break this rule. ie.
1782 * Orinoco AP1000. */
1786 switch (info_element->id) {
1787 case MFIE_TYPE_SSID:
1788 if (ieee80211_is_empty_essid(info_element->data,
1789 info_element->len)) {
1790 network->flags |= NETWORK_EMPTY_ESSID;
1794 network->ssid_len = min(info_element->len,
1795 (u8) IW_ESSID_MAX_SIZE);
1796 memcpy(network->ssid, info_element->data, network->ssid_len);
1797 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1798 memset(network->ssid + network->ssid_len, 0,
1799 IW_ESSID_MAX_SIZE - network->ssid_len);
1801 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1802 network->ssid, network->ssid_len);
1805 case MFIE_TYPE_RATES:
1806 #ifdef CONFIG_IEEE80211_DEBUG
1809 network->rates_len = min(info_element->len,
1811 for (i = 0; i < network->rates_len; i++) {
1812 network->rates[i] = info_element->data[i];
1813 #ifdef CONFIG_IEEE80211_DEBUG
1814 p += snprintf(p, sizeof(rates_str) -
1815 (p - rates_str), "%02X ",
1818 if (ieee80211_is_ofdm_rate
1819 (info_element->data[i])) {
1820 network->flags |= NETWORK_HAS_OFDM;
1821 if (info_element->data[i] &
1822 IEEE80211_BASIC_RATE_MASK)
1828 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1829 rates_str, network->rates_len);
1832 case MFIE_TYPE_RATES_EX:
1833 #ifdef CONFIG_IEEE80211_DEBUG
1836 network->rates_ex_len = min(info_element->len,
1837 MAX_RATES_EX_LENGTH);
1838 for (i = 0; i < network->rates_ex_len; i++) {
1839 network->rates_ex[i] = info_element->data[i];
1840 #ifdef CONFIG_IEEE80211_DEBUG
1841 p += snprintf(p, sizeof(rates_str) -
1842 (p - rates_str), "%02X ",
1845 if (ieee80211_is_ofdm_rate
1846 (info_element->data[i])) {
1847 network->flags |= NETWORK_HAS_OFDM;
1848 if (info_element->data[i] &
1849 IEEE80211_BASIC_RATE_MASK)
1855 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1856 rates_str, network->rates_ex_len);
1859 case MFIE_TYPE_DS_SET:
1860 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1861 info_element->data[0]);
1862 network->channel = info_element->data[0];
1865 case MFIE_TYPE_FH_SET:
1866 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1869 case MFIE_TYPE_CF_SET:
1870 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1874 if(info_element->len < 4)
1877 network->tim.tim_count = info_element->data[0];
1878 network->tim.tim_period = info_element->data[1];
1880 network->dtim_period = info_element->data[1];
1881 if(ieee->state != IEEE80211_LINKED)
1884 network->last_dtim_sta_time[0] = stats->mac_time[0];
1886 //we use jiffies for legacy Power save
1887 network->last_dtim_sta_time[0] = jiffies;
1889 network->last_dtim_sta_time[1] = stats->mac_time[1];
1891 network->dtim_data = IEEE80211_DTIM_VALID;
1893 if(info_element->data[0] != 0)
1896 if(info_element->data[2] & 1)
1897 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1899 offset = (info_element->data[2] >> 1)*2;
1901 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1903 if(ieee->assoc_id < 8*offset ||
1904 ieee->assoc_id > 8*(offset + info_element->len -3))
1908 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1910 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1911 network->dtim_data |= IEEE80211_DTIM_UCAST;
1913 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1917 network->erp_value = info_element->data[0];
1918 network->flags |= NETWORK_HAS_ERP_VALUE;
1919 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1920 network->erp_value);
1922 case MFIE_TYPE_IBSS_SET:
1923 network->atim_window = info_element->data[0];
1924 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1925 network->atim_window);
1928 case MFIE_TYPE_CHALLENGE:
1929 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1932 case MFIE_TYPE_GENERIC:
1933 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1935 if (!ieee80211_parse_qos_info_param_IE(info_element,
1939 if (info_element->len >= 4 &&
1940 info_element->data[0] == 0x00 &&
1941 info_element->data[1] == 0x50 &&
1942 info_element->data[2] == 0xf2 &&
1943 info_element->data[3] == 0x01) {
1944 network->wpa_ie_len = min(info_element->len + 2,
1946 memcpy(network->wpa_ie, info_element,
1947 network->wpa_ie_len);
1952 if (info_element->len == 7 &&
1953 info_element->data[0] == 0x00 &&
1954 info_element->data[1] == 0xe0 &&
1955 info_element->data[2] == 0x4c &&
1956 info_element->data[3] == 0x01 &&
1957 info_element->data[4] == 0x02) {
1958 network->Turbo_Enable = 1;
1962 //for HTcap and HTinfo parameters
1963 if(tmp_htcap_len == 0){
1964 if(info_element->len >= 4 &&
1965 info_element->data[0] == 0x00 &&
1966 info_element->data[1] == 0x90 &&
1967 info_element->data[2] == 0x4c &&
1968 info_element->data[3] == 0x033){
1970 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1971 if(tmp_htcap_len != 0){
1972 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1973 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1974 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1975 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1978 if(tmp_htcap_len != 0)
1979 network->bssht.bdSupportHT = true;
1981 network->bssht.bdSupportHT = false;
1985 if(tmp_htinfo_len == 0){
1986 if(info_element->len >= 4 &&
1987 info_element->data[0] == 0x00 &&
1988 info_element->data[1] == 0x90 &&
1989 info_element->data[2] == 0x4c &&
1990 info_element->data[3] == 0x034){
1992 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1993 if(tmp_htinfo_len != 0){
1994 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1996 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1997 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1998 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2006 if(ieee->aggregation){
2007 if(network->bssht.bdSupportHT){
2008 if(info_element->len >= 4 &&
2009 info_element->data[0] == 0x00 &&
2010 info_element->data[1] == 0xe0 &&
2011 info_element->data[2] == 0x4c &&
2012 info_element->data[3] == 0x02){
2014 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
2015 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
2018 if(ht_realtek_agg_len >= 5){
2019 network->bssht.bdRT2RTAggregation = true;
2021 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
2022 network->bssht.bdRT2RTLongSlotTime = true;
2028 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
2030 if((info_element->len >= 3 &&
2031 info_element->data[0] == 0x00 &&
2032 info_element->data[1] == 0x05 &&
2033 info_element->data[2] == 0xb5) ||
2034 (info_element->len >= 3 &&
2035 info_element->data[0] == 0x00 &&
2036 info_element->data[1] == 0x0a &&
2037 info_element->data[2] == 0xf7) ||
2038 (info_element->len >= 3 &&
2039 info_element->data[0] == 0x00 &&
2040 info_element->data[1] == 0x10 &&
2041 info_element->data[2] == 0x18)){
2043 network->broadcom_cap_exist = true;
2048 if (tmp_htcap_len !=0)
2050 u16 cap_ext = ((PHT_CAPABILITY_ELE)&info_element->data[0])->ExtHTCapInfo;
2051 if ((cap_ext & 0x0c00) == 0x0c00)
2053 network->ralink_cap_exist = true;
2057 if(info_element->len >= 3 &&
2058 info_element->data[0] == 0x00 &&
2059 info_element->data[1] == 0x0c &&
2060 info_element->data[2] == 0x43)
2062 network->ralink_cap_exist = true;
2065 network->ralink_cap_exist = false;
2066 //added by amy for atheros AP
2067 if((info_element->len >= 3 &&
2068 info_element->data[0] == 0x00 &&
2069 info_element->data[1] == 0x03 &&
2070 info_element->data[2] == 0x7f) ||
2071 (info_element->len >= 3 &&
2072 info_element->data[0] == 0x00 &&
2073 info_element->data[1] == 0x13 &&
2074 info_element->data[2] == 0x74))
2076 //printk("========>%s(): athros AP is exist\n",__FUNCTION__);
2077 network->atheros_cap_exist = true;
2080 network->atheros_cap_exist = false;
2082 if ((info_element->len >= 3 &&
2083 info_element->data[0] == 0x00 &&
2084 info_element->data[1] == 0x50 &&
2085 info_element->data[2] == 0x43) )
2087 network->marvell_cap_exist = true;
2088 //printk("========>%s(): marvel AP is exist\n",__FUNCTION__);
2092 if(info_element->len >= 3 &&
2093 info_element->data[0] == 0x00 &&
2094 info_element->data[1] == 0x40 &&
2095 info_element->data[2] == 0x96)
2097 network->cisco_cap_exist = true;
2100 network->cisco_cap_exist = false;
2101 //added by amy for LEAP of cisco
2102 if(info_element->len > 4 &&
2103 info_element->data[0] == 0x00 &&
2104 info_element->data[1] == 0x40 &&
2105 info_element->data[2] == 0x96 &&
2106 info_element->data[3] == 0x01)
2108 if(info_element->len == 6)
2110 memcpy(network->CcxRmState, &info_element[4], 2);
2111 if(network->CcxRmState[0] != 0)
2113 network->bCcxRmEnable = true;
2116 network->bCcxRmEnable = false;
2118 // CCXv4 Table 59-1 MBSSID Masks.
2120 network->MBssidMask = network->CcxRmState[1] & 0x07;
2121 if(network->MBssidMask != 0)
2123 network->bMBssidValid = true;
2124 network->MBssidMask = 0xff << (network->MBssidMask);
2125 cpMacAddr(network->MBssid, network->bssid);
2126 network->MBssid[5] &= network->MBssidMask;
2130 network->bMBssidValid = false;
2135 network->bCcxRmEnable = false;
2138 if(info_element->len > 4 &&
2139 info_element->data[0] == 0x00 &&
2140 info_element->data[1] == 0x40 &&
2141 info_element->data[2] == 0x96 &&
2142 info_element->data[3] == 0x03)
2144 if(info_element->len == 5)
2146 network->bWithCcxVerNum = true;
2147 network->BssCcxVerNumber = info_element->data[4];
2151 network->bWithCcxVerNum = false;
2152 network->BssCcxVerNumber = 0;
2158 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2160 network->rsn_ie_len = min(info_element->len + 2,
2162 memcpy(network->rsn_ie, info_element,
2163 network->rsn_ie_len);
2166 //HT related element.
2167 case MFIE_TYPE_HT_CAP:
2168 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2170 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2171 if(tmp_htcap_len != 0){
2172 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2173 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2174 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2175 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2177 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2178 // windows driver will update WMM parameters each beacon received once connected
2179 // Linux driver is a bit different.
2180 network->bssht.bdSupportHT = true;
2183 network->bssht.bdSupportHT = false;
2187 case MFIE_TYPE_HT_INFO:
2188 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2190 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2192 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2193 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2194 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2195 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2199 case MFIE_TYPE_AIRONET:
2200 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2202 if(info_element->len >IE_CISCO_FLAG_POSITION)
2204 network->bWithAironetIE = true;
2206 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2207 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2208 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2209 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
2210 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
2212 network->bCkipSupported = true;
2216 network->bCkipSupported = false;
2221 network->bWithAironetIE = false;
2222 network->bCkipSupported = false;
2225 case MFIE_TYPE_QOS_PARAMETER:
2227 "QoS Error need to parse QOS_PARAMETER IE\n");
2230 #ifdef ENABLE_DOT11D
2231 case MFIE_TYPE_COUNTRY:
2232 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2234 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2235 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2241 case MFIE_TYPE_POWER_CONSTRAINT:
2242 network->power_constraint = info_element->data[0];
2243 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
2247 network->power_constraint = info_element->data[0];
2248 network->flags |= NETWORK_HAS_CSA;
2251 case MFIE_TYPE_QUIET:
2252 network->quiet.count = info_element->data[0];
2253 network->quiet.period = info_element->data[1];
2254 network->quiet.duration = info_element->data[2];
2255 network->quiet.offset = info_element->data[3];
2256 network->flags |= NETWORK_HAS_QUIET;
2259 case MFIE_TYPE_IBSS_DFS:
2260 if (network->ibss_dfs)
2262 network->ibss_dfs = kmemdup(info_element->data,
2265 if (!network->ibss_dfs)
2267 network->flags |= NETWORK_HAS_IBSS_DFS;
2270 case MFIE_TYPE_TPC_REPORT:
2271 network->tpc_report.transmit_power =
2272 info_element->data[0];
2273 network->tpc_report.link_margin = info_element->data[1];
2274 network->flags |= NETWORK_HAS_TPC_REPORT;
2278 IEEE80211_DEBUG_MGMT
2279 ("Unsupported info element: %s (%d)\n",
2280 get_info_element_string(info_element->id),
2285 length -= sizeof(*info_element) + info_element->len;
2287 (struct ieee80211_info_element *)&info_element->
2288 data[info_element->len];
2291 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2292 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation &&
2293 !network->marvell_cap_exist)
2295 network->unknown_cap_exist = true;
2299 network->unknown_cap_exist = false;
2304 static inline u8 ieee80211_SignalStrengthTranslate(
2310 // Step 1. Scale mapping.
2311 if(CurrSS >= 71 && CurrSS <= 100)
2313 RetSS = 90 + ((CurrSS - 70) / 3);
2315 else if(CurrSS >= 41 && CurrSS <= 70)
2317 RetSS = 78 + ((CurrSS - 40) / 3);
2319 else if(CurrSS >= 31 && CurrSS <= 40)
2321 RetSS = 66 + (CurrSS - 30);
2323 else if(CurrSS >= 21 && CurrSS <= 30)
2325 RetSS = 54 + (CurrSS - 20);
2327 else if(CurrSS >= 5 && CurrSS <= 20)
2329 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2331 else if(CurrSS == 4)
2335 else if(CurrSS == 3)
2339 else if(CurrSS == 2)
2343 else if(CurrSS == 1)
2351 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2353 // Step 2. Smoothing.
2355 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2360 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2362 long signal_power; // in dBm.
2364 // Translate to dBm (x=0.5y-95).
2365 signal_power = (long)((signal_strength_index + 1) >> 1);
2368 return signal_power;
2371 static inline int ieee80211_network_init(
2372 struct ieee80211_device *ieee,
2373 struct ieee80211_probe_response *beacon,
2374 struct ieee80211_network *network,
2375 struct ieee80211_rx_stats *stats)
2377 #ifdef CONFIG_IEEE80211_DEBUG
2378 //char rates_str[64];
2382 network->qos_data.active = 0;
2383 network->qos_data.supported = 0;
2384 network->qos_data.param_count = 0;
2385 network->qos_data.old_param_count = 0;
2387 /* Pull out fixed field data */
2388 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2389 network->capability = le16_to_cpu(beacon->capability);
2390 network->last_scanned = jiffies;
2391 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2392 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2393 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2394 /* Where to pull this? beacon->listen_interval;*/
2395 network->listen_interval = 0x0A;
2396 network->rates_len = network->rates_ex_len = 0;
2397 network->last_associate = 0;
2398 network->ssid_len = 0;
2400 network->atim_window = 0;
2401 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2403 network->berp_info_valid = false;
2404 network->broadcom_cap_exist = false;
2405 network->ralink_cap_exist = false;
2406 network->atheros_cap_exist = false;
2407 network->marvell_cap_exist = false;
2408 network->cisco_cap_exist = false;
2409 network->unknown_cap_exist = false;
2411 network->Turbo_Enable = 0;
2413 #ifdef ENABLE_DOT11D
2414 network->CountryIeLen = 0;
2415 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2417 //Initialize HT parameters
2418 //ieee80211_ht_initialize(&network->bssht);
2419 HTInitializeBssDesc(&network->bssht);
2420 if (stats->freq == IEEE80211_52GHZ_BAND) {
2421 /* for A band (No DS info) */
2422 network->channel = stats->received_channel;
2424 network->flags |= NETWORK_HAS_CCK;
2426 network->wpa_ie_len = 0;
2427 network->rsn_ie_len = 0;
2429 if (ieee80211_parse_info_param
2430 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2434 if (stats->freq == IEEE80211_52GHZ_BAND)
2435 network->mode = IEEE_A;
2437 if (network->flags & NETWORK_HAS_OFDM)
2438 network->mode |= IEEE_G;
2439 if (network->flags & NETWORK_HAS_CCK)
2440 network->mode |= IEEE_B;
2443 if (network->mode == 0) {
2444 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2446 escape_essid(network->ssid,
2452 if(network->bssht.bdSupportHT){
2453 if(network->mode == IEEE_A)
2454 network->mode = IEEE_N_5G;
2455 else if(network->mode & (IEEE_G | IEEE_B))
2456 network->mode = IEEE_N_24G;
2458 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2459 network->flags |= NETWORK_EMPTY_ESSID;
2462 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2463 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2464 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2467 memcpy(&network->stats, stats, sizeof(network->stats));
2472 static inline int is_same_network(struct ieee80211_network *src,
2473 struct ieee80211_network *dst, struct ieee80211_device* ieee)
2475 /* A network is only a duplicate if the channel, BSSID, ESSID
2476 * and the capability field (in particular IBSS and BSS) all match.
2477 * We treat all <hidden> with the same BSSID and channel
2479 return //((src->ssid_len == dst->ssid_len) &&
2480 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2481 (src->channel == dst->channel) &&
2482 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2483 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2484 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2485 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2486 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2487 ((src->capability & WLAN_CAPABILITY_BSS) ==
2488 (dst->capability & WLAN_CAPABILITY_BSS)));
2491 static inline void update_network(struct ieee80211_network *dst,
2492 struct ieee80211_network *src)
2497 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2498 dst->capability = src->capability;
2499 memcpy(dst->rates, src->rates, src->rates_len);
2500 dst->rates_len = src->rates_len;
2501 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2502 dst->rates_ex_len = src->rates_ex_len;
2503 if(src->ssid_len > 0)
2505 memset(dst->ssid, 0, dst->ssid_len);
2506 dst->ssid_len = src->ssid_len;
2507 memcpy(dst->ssid, src->ssid, src->ssid_len);
2509 dst->mode = src->mode;
2510 dst->flags = src->flags;
2511 dst->time_stamp[0] = src->time_stamp[0];
2512 dst->time_stamp[1] = src->time_stamp[1];
2513 if (src->flags & NETWORK_HAS_ERP_VALUE)
2515 dst->erp_value = src->erp_value;
2516 dst->berp_info_valid = src->berp_info_valid = true;
2518 dst->beacon_interval = src->beacon_interval;
2519 dst->listen_interval = src->listen_interval;
2520 dst->atim_window = src->atim_window;
2521 dst->dtim_period = src->dtim_period;
2522 dst->dtim_data = src->dtim_data;
2523 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2524 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2525 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2527 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2528 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2529 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2530 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2531 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2532 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2533 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2534 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2535 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2536 dst->ralink_cap_exist = src->ralink_cap_exist;
2537 dst->atheros_cap_exist = src->atheros_cap_exist;
2538 dst->marvell_cap_exist = src->marvell_cap_exist;
2539 dst->cisco_cap_exist = src->cisco_cap_exist;
2540 dst->unknown_cap_exist = src->unknown_cap_exist;
2541 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2542 dst->wpa_ie_len = src->wpa_ie_len;
2543 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2544 dst->rsn_ie_len = src->rsn_ie_len;
2546 dst->last_scanned = jiffies;
2547 /* qos related parameters */
2548 //qos_active = src->qos_data.active;
2549 qos_active = dst->qos_data.active;
2550 //old_param = dst->qos_data.old_param_count;
2551 old_param = dst->qos_data.param_count;
2552 if(dst->flags & NETWORK_HAS_QOS_MASK){
2553 //not update QOS paramter in beacon, as most AP will set all these parameter to 0.//WB
2554 // printk("====>%s(), aifs:%x, %x\n", __FUNCTION__, dst->qos_data.parameters.aifs[0], src->qos_data.parameters.aifs[0]);
2555 // memcpy(&dst->qos_data, &src->qos_data,
2556 // sizeof(struct ieee80211_qos_data));
2559 dst->qos_data.supported = src->qos_data.supported;
2560 dst->qos_data.param_count = src->qos_data.param_count;
2563 if(dst->qos_data.supported == 1) {
2564 dst->QoS_Enable = 1;
2567 ("QoS the network %s is QoS supported\n",
2571 ("QoS the network is QoS supported\n");
2573 dst->qos_data.active = qos_active;
2574 dst->qos_data.old_param_count = old_param;
2576 /* dst->last_associate is not overwritten */
2578 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2579 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2580 src->wmm_param[1].ac_aci_acm_aifsn|| \
2581 src->wmm_param[2].ac_aci_acm_aifsn|| \
2582 src->wmm_param[1].ac_aci_acm_aifsn) {
2583 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2585 //dst->QoS_Enable = src->QoS_Enable;
2587 dst->QoS_Enable = 1;//for Rtl8187 simulation
2590 dst->Turbo_Enable = src->Turbo_Enable;
2593 #ifdef ENABLE_DOT11D
2594 dst->CountryIeLen = src->CountryIeLen;
2595 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2598 //added by amy for LEAP
2599 dst->bWithAironetIE = src->bWithAironetIE;
2600 dst->bCkipSupported = src->bCkipSupported;
2601 memcpy(dst->CcxRmState,src->CcxRmState,2);
2602 dst->bCcxRmEnable = src->bCcxRmEnable;
2603 dst->MBssidMask = src->MBssidMask;
2604 dst->bMBssidValid = src->bMBssidValid;
2605 memcpy(dst->MBssid,src->MBssid,6);
2606 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2607 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2611 static inline int is_beacon(__le16 fc)
2613 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2616 static inline void ieee80211_process_probe_response(
2617 struct ieee80211_device *ieee,
2618 struct ieee80211_probe_response *beacon,
2619 struct ieee80211_rx_stats *stats)
2621 struct ieee80211_network network;
2622 struct ieee80211_network *target;
2623 struct ieee80211_network *oldest = NULL;
2624 #ifdef CONFIG_IEEE80211_DEBUG
2625 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2627 unsigned long flags;
2631 memset(&network, 0, sizeof(struct ieee80211_network));
2632 IEEE80211_DEBUG_SCAN(
2633 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2634 escape_essid(info_element->data, info_element->len),
2635 beacon->header.addr3,
2636 (beacon->capability & (1<<0xf)) ? '1' : '0',
2637 (beacon->capability & (1<<0xe)) ? '1' : '0',
2638 (beacon->capability & (1<<0xd)) ? '1' : '0',
2639 (beacon->capability & (1<<0xc)) ? '1' : '0',
2640 (beacon->capability & (1<<0xb)) ? '1' : '0',
2641 (beacon->capability & (1<<0xa)) ? '1' : '0',
2642 (beacon->capability & (1<<0x9)) ? '1' : '0',
2643 (beacon->capability & (1<<0x8)) ? '1' : '0',
2644 (beacon->capability & (1<<0x7)) ? '1' : '0',
2645 (beacon->capability & (1<<0x6)) ? '1' : '0',
2646 (beacon->capability & (1<<0x5)) ? '1' : '0',
2647 (beacon->capability & (1<<0x4)) ? '1' : '0',
2648 (beacon->capability & (1<<0x3)) ? '1' : '0',
2649 (beacon->capability & (1<<0x2)) ? '1' : '0',
2650 (beacon->capability & (1<<0x1)) ? '1' : '0',
2651 (beacon->capability & (1<<0x0)) ? '1' : '0');
2653 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2654 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2655 escape_essid(info_element->data,
2657 beacon->header.addr3,
2658 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2659 IEEE80211_STYPE_PROBE_RESP ?
2660 "PROBE RESPONSE" : "BEACON");
2664 #ifdef ENABLE_DOT11D
2665 // For Asus EeePc request,
2666 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2667 // wireless adapter should follow the country code.
2668 // (2) If there is no any country code in beacon,
2669 // then wireless adapter should do active scan from ch1~11 and
2670 // passive scan from ch12~14
2672 if( !IsLegalChannel(ieee, network.channel) )
2674 if(ieee->bGlobalDomain)
2676 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2678 // Case 1: Country code
2679 if(IS_COUNTRY_IE_VALID(ieee) )
2681 if( !IsLegalChannel(ieee, network.channel) )
2683 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2687 // Case 2: No any country code.
2690 // Filter over channel ch12~14
2691 if(network.channel > 11)
2693 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2700 // Case 1: Country code
2701 if(IS_COUNTRY_IE_VALID(ieee) )
2703 if( !IsLegalChannel(ieee, network.channel) )
2705 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2709 // Case 2: No any country code.
2712 // Filter over channel ch12~14
2713 if(network.channel > 14)
2715 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2723 /* The network parsed correctly -- so now we scan our known networks
2724 * to see if we can find it in our list.
2726 * NOTE: This search is definitely not optimized. Once its doing
2727 * the "right thing" we'll optimize it for efficiency if
2730 /* Search for this entry in the list and update it if it is
2733 spin_lock_irqsave(&ieee->lock, flags);
2735 if(is_same_network(&ieee->current_network, &network, ieee)) {
2736 update_network(&ieee->current_network, &network);
2737 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2738 && ieee->current_network.berp_info_valid){
2739 if(ieee->current_network.erp_value& ERP_UseProtection)
2740 ieee->current_network.buseprotection = true;
2742 ieee->current_network.buseprotection = false;
2744 if(is_beacon(beacon->header.frame_ctl))
2746 if(ieee->state == IEEE80211_LINKED)
2747 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2750 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2753 list_for_each_entry(target, &ieee->network_list, list) {
2754 if (is_same_network(target, &network, ieee))
2756 if ((oldest == NULL) ||
2757 (target->last_scanned < oldest->last_scanned))
2761 /* If we didn't find a match, then get a new network slot to initialize
2762 * with this beacon's information */
2763 if (&target->list == &ieee->network_list) {
2764 if (list_empty(&ieee->network_free_list)) {
2765 /* If there are no more slots, expire the oldest */
2766 list_del(&oldest->list);
2768 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2770 escape_essid(target->ssid,
2774 /* Otherwise just pull from the free list */
2775 target = list_entry(ieee->network_free_list.next,
2776 struct ieee80211_network, list);
2777 list_del(ieee->network_free_list.next);
2781 #ifdef CONFIG_IEEE80211_DEBUG
2782 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2783 escape_essid(network.ssid,
2786 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2787 IEEE80211_STYPE_PROBE_RESP ?
2788 "PROBE RESPONSE" : "BEACON");
2790 memcpy(target, &network, sizeof(*target));
2791 list_add_tail(&target->list, &ieee->network_list);
2793 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2794 escape_essid(target->ssid,
2797 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2798 IEEE80211_STYPE_PROBE_RESP ?
2799 "PROBE RESPONSE" : "BEACON");
2801 /* we have an entry and we are going to update it. But this entry may
2802 * be already expired. In this case we do the same as we found a new
2803 * net and call the new_net handler
2805 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2806 //YJ,add,080819,for hidden ap
2807 if(is_beacon(beacon->header.frame_ctl) == 0)
2808 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2809 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2810 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2811 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2812 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2813 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2815 //YJ,add,080819,for hidden ap,end
2817 update_network(target, &network);
2820 spin_unlock_irqrestore(&ieee->lock, flags);
2821 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2822 (ieee->state == IEEE80211_LINKED)) {
2823 if(ieee->handle_beacon != NULL) {
2824 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2829 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2830 struct ieee80211_hdr_4addr *header,
2831 struct ieee80211_rx_stats *stats)
2834 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2835 ieee->iw_mode == IW_MODE_INFRA &&
2836 ieee->state == IEEE80211_LINKED))
2838 tasklet_schedule(&ieee->ps_task);
2842 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2843 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2844 ieee->last_rx_ps_time = jiffies;
2846 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2848 case IEEE80211_STYPE_BEACON:
2849 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2850 WLAN_FC_GET_STYPE(header->frame_ctl));
2851 IEEE80211_DEBUG_SCAN("Beacon\n");
2852 ieee80211_process_probe_response(
2853 ieee, (struct ieee80211_probe_response *)header, stats);
2855 //printk("----------->%s()\n", __func__);
2856 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2857 ieee->iw_mode == IW_MODE_INFRA &&
2858 ieee->state == IEEE80211_LINKED))
2860 tasklet_schedule(&ieee->ps_task);
2865 case IEEE80211_STYPE_PROBE_RESP:
2866 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2867 WLAN_FC_GET_STYPE(header->frame_ctl));
2868 IEEE80211_DEBUG_SCAN("Probe response\n");
2869 ieee80211_process_probe_response(
2870 ieee, (struct ieee80211_probe_response *)header, stats);