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 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
59 skb_reset_mac_header(skb);
61 skb->mac.raw = skb->data;
64 skb_pull(skb, ieee80211_get_hdrlen(fc));
65 skb->pkt_type = PACKET_OTHERHOST;
66 skb->protocol = __constant_htons(ETH_P_80211_RAW);
67 memset(skb->cb, 0, sizeof(skb->cb));
72 /* Called only as a tasklet (software IRQ) */
73 static struct ieee80211_frag_entry *
74 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
75 unsigned int frag, u8 tid,u8 *src, u8 *dst)
77 struct ieee80211_frag_entry *entry;
80 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
81 entry = &ieee->frag_cache[tid][i];
82 if (entry->skb != NULL &&
83 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
85 "expiring fragment cache entry "
86 "seq=%u last_frag=%u\n",
87 entry->seq, entry->last_frag);
88 dev_kfree_skb_any(entry->skb);
92 if (entry->skb != NULL && entry->seq == seq &&
93 (entry->last_frag + 1 == frag || frag == -1) &&
94 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
95 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
102 /* Called only as a tasklet (software IRQ) */
103 static struct sk_buff *
104 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
105 struct ieee80211_hdr_4addr *hdr)
107 struct sk_buff *skb = NULL;
108 u16 fc = le16_to_cpu(hdr->frame_ctl);
109 u16 sc = le16_to_cpu(hdr->seq_ctl);
110 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
111 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
112 struct ieee80211_frag_entry *entry;
113 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
114 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
117 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
118 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
119 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
122 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
123 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
124 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
132 /* Reserve enough space to fit maximum frame length */
133 skb = dev_alloc_skb(ieee->dev->mtu +
134 sizeof(struct ieee80211_hdr_4addr) +
139 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
143 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
144 ieee->frag_next_idx[tid]++;
145 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
146 ieee->frag_next_idx[tid] = 0;
148 if (entry->skb != NULL)
149 dev_kfree_skb_any(entry->skb);
151 entry->first_frag_time = jiffies;
153 entry->last_frag = frag;
155 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
156 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
158 /* received a fragment of a frame for which the head fragment
159 * should have already been received */
160 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
163 entry->last_frag = frag;
172 /* Called only as a tasklet (software IRQ) */
173 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
174 struct ieee80211_hdr_4addr *hdr)
176 u16 fc = le16_to_cpu(hdr->frame_ctl);
177 u16 sc = le16_to_cpu(hdr->seq_ctl);
178 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
179 struct ieee80211_frag_entry *entry;
180 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
181 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
184 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
185 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
186 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
189 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
190 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
191 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
198 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
202 IEEE80211_DEBUG_FRAG(
203 "could not invalidate fragment cache "
204 "entry (seq=%u)\n", seq);
214 /* ieee80211_rx_frame_mgtmt
216 * Responsible for handling management control frames
218 * Called by ieee80211_rx */
220 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
221 struct ieee80211_rx_stats *rx_stats, u16 type,
224 /* On the struct stats definition there is written that
225 * this is not mandatory.... but seems that the probe
226 * response parser uses it
228 struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data;
230 rx_stats->len = skb->len;
231 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
232 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
233 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames
235 dev_kfree_skb_any(skb);
239 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
241 dev_kfree_skb_any(skb);
246 if (ieee->iw_mode == IW_MODE_MASTER) {
247 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
251 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
255 if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) {
256 if (stype == WLAN_FC_STYPE_BEACON &&
257 ieee->iw_mode == IW_MODE_MASTER) {
258 struct sk_buff *skb2;
259 /* Process beacon frames also in kernel driver to
260 * update STA(AP) table statistics */
261 skb2 = skb_clone(skb, GFP_ATOMIC);
263 hostap_rx(skb2->dev, skb2, rx_stats);
266 /* send management frames to the user space daemon for
268 ieee->apdevstats.rx_packets++;
269 ieee->apdevstats.rx_bytes += skb->len;
270 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
274 if (ieee->iw_mode == IW_MODE_MASTER) {
275 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
276 printk(KERN_DEBUG "%s: unknown management frame "
277 "(type=0x%02x, stype=0x%02x) dropped\n",
278 skb->dev->name, type, stype);
282 hostap_rx(skb->dev, skb, rx_stats);
286 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
287 "received in non-Host AP mode\n", skb->dev->name);
294 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
295 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
296 static unsigned char rfc1042_header[] =
297 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
298 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
299 static unsigned char bridge_tunnel_header[] =
300 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
301 /* No encapsulation header if EtherType < 0x600 (=length) */
303 /* Called by ieee80211_rx_frame_decrypt */
304 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
305 struct sk_buff *skb, size_t hdrlen)
307 struct net_device *dev = ieee->dev;
309 struct ieee80211_hdr_4addr *hdr;
316 if (ieee->hwsec_active)
318 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
319 tcb_desc->bHwSec = 1;
321 if(ieee->need_sw_enc)
322 tcb_desc->bHwSec = 0;
326 hdr = (struct ieee80211_hdr_4addr *) skb->data;
327 fc = le16_to_cpu(hdr->frame_ctl);
329 /* check that the frame is unicast frame to us */
330 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
331 IEEE80211_FCTL_TODS &&
332 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
333 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
334 /* ToDS frame with own addr BSSID and DA */
335 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
336 IEEE80211_FCTL_FROMDS &&
337 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
338 /* FromDS frame with own addr as DA */
342 if (skb->len < 24 + 8)
345 /* check for port access entity Ethernet type */
346 // pos = skb->data + 24;
347 pos = skb->data + hdrlen;
348 ethertype = (pos[6] << 8) | pos[7];
349 if (ethertype == ETH_P_PAE)
355 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
357 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
358 struct ieee80211_crypt_data *crypt)
360 struct ieee80211_hdr_4addr *hdr;
363 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
366 if (ieee->hwsec_active)
368 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
369 tcb_desc->bHwSec = 1;
372 hdr = (struct ieee80211_hdr_4addr *) skb->data;
373 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
375 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
376 if (ieee->tkip_countermeasures &&
377 strcmp(crypt->ops->name, "TKIP") == 0) {
378 if (net_ratelimit()) {
379 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
380 "received packet from %pM\n",
381 ieee->dev->name, hdr->addr2);
387 atomic_inc(&crypt->refcnt);
388 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
389 atomic_dec(&crypt->refcnt);
391 IEEE80211_DEBUG_DROP(
392 "decryption failed (SA=%pM"
393 ") res=%d\n", hdr->addr2, res);
395 IEEE80211_DEBUG_DROP("Decryption failed ICV "
396 "mismatch (key %d)\n",
397 skb->data[hdrlen + 3] >> 6);
398 ieee->ieee_stats.rx_discards_undecryptable++;
406 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
408 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
409 int keyidx, struct ieee80211_crypt_data *crypt)
411 struct ieee80211_hdr_4addr *hdr;
414 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
416 if (ieee->hwsec_active)
418 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
419 tcb_desc->bHwSec = 1;
421 if(ieee->need_sw_enc)
422 tcb_desc->bHwSec = 0;
426 hdr = (struct ieee80211_hdr_4addr *) skb->data;
427 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
429 atomic_inc(&crypt->refcnt);
430 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
431 atomic_dec(&crypt->refcnt);
433 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
434 " (SA=%pM keyidx=%d)\n",
435 ieee->dev->name, hdr->addr2, keyidx);
443 /* this function is stolen from ipw2200 driver*/
444 #define IEEE_PACKET_RETRY_TIME (5*HZ)
445 static int is_duplicate_packet(struct ieee80211_device *ieee,
446 struct ieee80211_hdr_4addr *header)
448 u16 fc = le16_to_cpu(header->frame_ctl);
449 u16 sc = le16_to_cpu(header->seq_ctl);
450 u16 seq = WLAN_GET_SEQ_SEQ(sc);
451 u16 frag = WLAN_GET_SEQ_FRAG(sc);
452 u16 *last_seq, *last_frag;
453 unsigned long *last_time;
454 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
455 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
460 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
461 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
462 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
465 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
466 hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
467 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
474 switch (ieee->iw_mode) {
478 struct ieee_ibss_seq *entry = NULL;
479 u8 *mac = header->addr2;
480 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
481 //for (pos = (head)->next; pos != (head); pos = pos->next)
482 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
483 list_for_each(p, &ieee->ibss_mac_hash[index]) {
484 entry = list_entry(p, struct ieee_ibss_seq, list);
485 if (!memcmp(entry->mac, mac, ETH_ALEN))
488 // if (memcmp(entry->mac, mac, ETH_ALEN)){
489 if (p == &ieee->ibss_mac_hash[index]) {
490 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
492 printk(KERN_WARNING "Cannot malloc new mac entry\n");
495 memcpy(entry->mac, mac, ETH_ALEN);
496 entry->seq_num[tid] = seq;
497 entry->frag_num[tid] = frag;
498 entry->packet_time[tid] = jiffies;
499 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
502 last_seq = &entry->seq_num[tid];
503 last_frag = &entry->frag_num[tid];
504 last_time = &entry->packet_time[tid];
509 last_seq = &ieee->last_rxseq_num[tid];
510 last_frag = &ieee->last_rxfrag_num[tid];
511 last_time = &ieee->last_packet_time[tid];
519 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
521 if ((*last_seq == seq) &&
522 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
523 if (*last_frag == frag){
524 //printk(KERN_WARNING "[1] go drop!\n");
528 if (*last_frag + 1 != frag)
529 /* out-of-order fragment */
530 //printk(KERN_WARNING "[2] go drop!\n");
536 *last_time = jiffies;
540 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
548 PRX_REORDER_ENTRY pReorderEntry
551 struct list_head *pList = &pTS->RxPendingPktList;
553 while(pList->next != &pTS->RxPendingPktList)
555 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
559 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
569 pReorderEntry->List.next = pList->next;
570 pReorderEntry->List.next->prev = &pReorderEntry->List;
571 pReorderEntry->List.prev = pList;
572 pList->next = &pReorderEntry->List;
577 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index)
582 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
583 for(j = 0; j<index; j++)
585 //added by amy for reorder
586 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
587 for(i = 0; i<prxb->nr_subframes; i++) {
588 struct sk_buff *sub_skb = prxb->subframes[i];
590 /* convert hdr + possible LLC headers into Ethernet header */
591 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
592 if (sub_skb->len >= 8 &&
593 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
594 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
595 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
596 /* remove RFC1042 or Bridge-Tunnel encapsulation and
597 * replace EtherType */
598 skb_pull(sub_skb, SNAP_SIZE);
599 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
600 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
603 /* Leave Ethernet header part of hdr and full payload */
604 len = htons(sub_skb->len);
605 memcpy(skb_push(sub_skb, 2), &len, 2);
606 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
607 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
609 //stats->rx_packets++;
610 //stats->rx_bytes += sub_skb->len;
612 /* Indicat the packets to upper layer */
614 //printk("0skb_len(%d)\n", skb->len);
615 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
616 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
617 sub_skb->dev = ieee->dev;
618 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
619 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
620 ieee->last_rx_ps_time = jiffies;
621 //printk("1skb_len(%d)\n", skb->len);
631 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
632 struct ieee80211_rxb* prxb,
636 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
637 PRX_REORDER_ENTRY pReorderEntry = NULL;
638 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
639 u8 WinSize = pHTInfo->RxReorderWinSize;
640 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
642 bool bMatchWinStart = false, bPktInBuf = false;
643 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
645 if(!list_empty(&ieee->RxReorder_Unused_List))
646 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): ieee->RxReorder_Unused_List is nut NULL\n");
648 /* Rx Reorder initialize condition.*/
649 if(pTS->RxIndicateSeq == 0xffff) {
650 pTS->RxIndicateSeq = SeqNum;
653 /* Drop out the packet which SeqNum is smaller than WinStart */
654 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
655 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
656 pTS->RxIndicateSeq, SeqNum);
657 pHTInfo->RxReorderDropCounter++;
660 for(i =0; i < prxb->nr_subframes; i++) {
661 dev_kfree_skb(prxb->subframes[i]);
670 * Sliding window manipulation. Conditions includes:
671 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
672 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
674 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
675 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
676 bMatchWinStart = true;
677 } else if(SN_LESS(WinEnd, SeqNum)) {
678 if(SeqNum >= (WinSize - 1)) {
679 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
681 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
683 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
687 * Indication process.
688 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
689 * with the SeqNum smaller than latest WinStart and buffer other packets.
691 /* For Rx Reorder condition:
692 * 1. All packets with SeqNum smaller than WinStart => Indicate
693 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
696 /* Current packet is going to be indicated.*/
697 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
698 pTS->RxIndicateSeq, SeqNum);
699 prxbIndicateArray[0] = prxb;
700 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
703 /* Current packet is going to be inserted into pending list.*/
704 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
705 if(!list_empty(&ieee->RxReorder_Unused_List)) {
706 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
707 list_del_init(&pReorderEntry->List);
709 /* Make a reorder entry and insert into a the packet list.*/
710 pReorderEntry->SeqNum = SeqNum;
711 pReorderEntry->prxb = prxb;
712 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
715 if(!AddReorderEntry(pTS, pReorderEntry)) {
716 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
717 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
718 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
721 for(i =0; i < prxb->nr_subframes; i++) {
722 dev_kfree_skb(prxb->subframes[i]);
728 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
729 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
735 * Packets are dropped if there is not enough reorder entries.
736 * This part shall be modified!! We can just indicate all the
737 * packets in buffer and get reorder entries.
739 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
742 for(i =0; i < prxb->nr_subframes; i++) {
743 dev_kfree_skb(prxb->subframes[i]);
751 /* Check if there is any packet need indicate.*/
752 while(!list_empty(&pTS->RxPendingPktList)) {
753 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
755 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
756 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
757 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
759 /* This protect buffer from overflow. */
760 if(index >= REORDER_WIN_SIZE) {
761 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
766 list_del_init(&pReorderEntry->List);
768 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
769 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
771 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
772 prxbIndicateArray[index] = pReorderEntry->prxb;
773 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
776 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
784 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
786 // Cancel previous pending timer.
787 if (timer_pending(&pTS->RxPktPendingTimer))
788 del_timer_sync(&pTS->RxPktPendingTimer);
789 pTS->RxTimeoutIndicateSeq = 0xffff;
792 if(index>REORDER_WIN_SIZE){
793 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
796 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
801 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
802 // Set new pending timer.
803 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
804 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
806 if(timer_pending(&pTS->RxPktPendingTimer))
807 del_timer_sync(&pTS->RxPktPendingTimer);
808 pTS->RxPktPendingTimer.expires = jiffies + MSECS(pHTInfo->RxReorderPendingTime);
809 add_timer(&pTS->RxPktPendingTimer);
811 mod_timer(&pTS->RxPktPendingTimer, jiffies + MSECS(pHTInfo->RxReorderPendingTime));
817 u8 parse_subframe(struct ieee80211_device* ieee,struct sk_buff *skb,
818 struct ieee80211_rx_stats *rx_stats,
819 struct ieee80211_rxb *rxb,u8* src,u8* dst)
821 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
822 u16 fc = le16_to_cpu(hdr->frame_ctl);
824 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
826 bool bIsAggregateFrame = false;
827 u16 nSubframe_Length;
828 u8 nPadding_Length = 0;
831 struct sk_buff *sub_skb;
833 /* just for debug purpose */
834 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
836 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
837 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
838 bIsAggregateFrame = true;
841 if(IEEE80211_QOS_HAS_SEQ(fc)) {
845 if(rx_stats->bContainHTC) {
846 LLCOffset += sHTCLng;
848 //printk("ChkLength = %d\n", LLCOffset);
849 // Null packet, don't indicate it to upper layer
850 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
852 if( skb->len <= ChkLength ) {
856 skb_pull(skb, LLCOffset);
857 ieee->bIsAggregateFrame = bIsAggregateFrame;//added by amy for Leisure PS
859 if(!bIsAggregateFrame) {
860 rxb->nr_subframes = 1;
862 rxb->subframes[0] = skb;
864 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
867 memcpy(rxb->src,src,ETH_ALEN);
868 memcpy(rxb->dst,dst,ETH_ALEN);
869 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
872 rxb->nr_subframes = 0;
873 memcpy(rxb->src,src,ETH_ALEN);
874 memcpy(rxb->dst,dst,ETH_ALEN);
875 while(skb->len > ETHERNET_HEADER_SIZE) {
876 /* Offset 12 denote 2 mac address */
877 nSubframe_Length = *((u16*)(skb->data + 12));
878 //==m==>change the length order
879 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
881 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
884 (nRemain_Length>=(ETHERNET_HEADER_SIZE + nSubframe_Length)),
885 ("ParseSubframe(): A-MSDU subframe parse error!! Subframe Length: %d\n", nSubframe_Length) );
887 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
888 __FUNCTION__,rxb->nr_subframes);
889 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
890 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
891 printk("The Packet SeqNum is %d\n",SeqNum);
895 /* move the data point to data content */
896 skb_pull(skb, ETHERNET_HEADER_SIZE);
899 sub_skb = skb_clone(skb, GFP_ATOMIC);
900 sub_skb->len = nSubframe_Length;
901 sub_skb->tail = sub_skb->data + nSubframe_Length;
903 /* Allocate new skb for releasing to upper layer */
904 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
905 skb_reserve(sub_skb, 12);
906 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
907 memcpy(data_ptr,skb->data,nSubframe_Length);
909 rxb->subframes[rxb->nr_subframes++] = sub_skb;
910 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
911 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
914 skb_pull(skb,nSubframe_Length);
917 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
918 if(nPadding_Length == 4) {
922 if(skb->len < nPadding_Length) {
926 skb_pull(skb,nPadding_Length);
932 //{just for debug added by david
933 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
935 return rxb->nr_subframes;
939 /* All received frames are sent to this function. @skb contains the frame in
940 * IEEE 802.11 format, i.e., in the format it was sent over air.
941 * This function is called only as a tasklet (software IRQ). */
942 int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
943 struct ieee80211_rx_stats *rx_stats)
945 struct net_device *dev = ieee->dev;
946 struct ieee80211_hdr_4addr *hdr;
947 //struct ieee80211_hdr_3addrqos *hdr;
950 u16 fc, type, stype, sc;
951 struct net_device_stats *stats;
955 //added by amy for reorder
958 PRX_TS_RECORD pTS = NULL;
959 bool unicast_packet = false;
960 //bool bIsAggregateFrame = false;
961 //added by amy for reorder
963 struct net_device *wds = NULL;
964 struct sk_buff *skb2 = NULL;
965 struct net_device *wds = NULL;
966 int frame_authorized = 0;
967 int from_assoc_ap = 0;
974 struct ieee80211_crypt_data *crypt = NULL;
978 struct ieee80211_rxb* rxb = NULL;
979 // cheat the the hdr type
980 hdr = (struct ieee80211_hdr_4addr *)skb->data;
981 stats = &ieee->stats;
984 printk(KERN_INFO "%s: SKB length < 10\n",
989 fc = le16_to_cpu(hdr->frame_ctl);
990 type = WLAN_FC_GET_TYPE(fc);
991 stype = WLAN_FC_GET_STYPE(fc);
992 sc = le16_to_cpu(hdr->seq_ctl);
994 frag = WLAN_GET_SEQ_FRAG(sc);
995 hdrlen = ieee80211_get_hdrlen(fc);
997 if(HTCCheck(ieee, skb->data))
1000 printk("find HTCControl\n");
1002 rx_stats->bContainHTC = 1;
1005 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1007 #if WIRELESS_EXT > 15
1008 /* Put this code here so that we avoid duplicating it in all
1009 * Rx paths. - Jean II */
1010 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
1011 /* If spy monitoring on */
1012 if (iface->spy_data.spy_number > 0) {
1013 struct iw_quality wstats;
1014 wstats.level = rx_stats->rssi;
1015 wstats.noise = rx_stats->noise;
1016 wstats.updated = 6; /* No qual value */
1017 /* Update spy records */
1018 wireless_spy_update(dev, hdr->addr2, &wstats);
1020 #endif /* IW_WIRELESS_SPY */
1021 #endif /* WIRELESS_EXT > 15 */
1022 hostap_update_rx_stats(local->ap, hdr, rx_stats);
1025 #if WIRELESS_EXT > 15
1026 if (ieee->iw_mode == IW_MODE_MONITOR) {
1027 ieee80211_monitor_rx(ieee, skb, rx_stats);
1028 stats->rx_packets++;
1029 stats->rx_bytes += skb->len;
1033 if (ieee->host_decrypt) {
1035 if (skb->len >= hdrlen + 3)
1036 idx = skb->data[hdrlen + 3] >> 6;
1037 crypt = ieee->crypt[idx];
1041 /* Use station specific key to override default keys if the
1042 * receiver address is a unicast address ("individual RA"). If
1043 * bcrx_sta_key parameter is set, station specific key is used
1044 * even with broad/multicast targets (this is against IEEE
1045 * 802.11, but makes it easier to use different keys with
1046 * stations that do not support WEP key mapping). */
1048 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1049 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1053 /* allow NULL decrypt to indicate an station specific override
1054 * for default encryption */
1055 if (crypt && (crypt->ops == NULL ||
1056 crypt->ops->decrypt_mpdu == NULL))
1059 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
1060 /* This seems to be triggered by some (multicast?)
1061 * frames from other than current BSS, so just drop the
1062 * frames silently instead of filling system log with
1064 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1067 ieee->ieee_stats.rx_discards_undecryptable++;
1072 if (skb->len < IEEE80211_DATA_HDR3_LEN)
1075 // if QoS enabled, should check the sequence for each of the AC
1076 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
1077 if (is_duplicate_packet(ieee, hdr))
1083 PRX_TS_RECORD pRxTS = NULL;
1085 struct ieee80211_hdr_3addr *hdr;
1087 hdr = (struct ieee80211_hdr_3addr *)skb->data;
1088 fc = le16_to_cpu(hdr->frame_ctl);
1089 u8 tmp = (fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS);
1091 u8 tid = (*((u8*)skb->data + (((fc& IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))?30:24)))&0xf;
1092 printk("====================>fc:%x, tid:%d, tmp:%d\n", fc, tid, tmp);
1093 //u8 tid = (u8)((frameqos*)(buf + ((fc & IEEE80211_FCTL_TODS)&&(fc & IEEE80211_FCTL_FROMDS))? 30 : 24))->field.tid;
1095 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1099 (PTS_COMMON_INFO*) &pRxTS,
1101 (u8)Frame_QoSTID((u8*)(skb->data)),
1106 // 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));
1107 if( (fc & (1<<11)) &&
1108 (frag == pRxTS->RxLastFragNum) &&
1109 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
1115 pRxTS->RxLastFragNum = frag;
1116 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1121 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
1126 if (type == IEEE80211_FTYPE_MGMT) {
1129 if ( stype == IEEE80211_STYPE_AUTH &&
1130 fc & IEEE80211_FCTL_WEP && ieee->host_decrypt &&
1131 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1133 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
1134 "from %pM\n", dev->name,
1136 /* TODO: could inform hostapd about this so that it
1137 * could send auth failure report */
1142 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1143 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1149 /* Data frame - extract src/dst addresses */
1150 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1151 case IEEE80211_FCTL_FROMDS:
1152 memcpy(dst, hdr->addr1, ETH_ALEN);
1153 memcpy(src, hdr->addr3, ETH_ALEN);
1154 memcpy(bssid, hdr->addr2, ETH_ALEN);
1156 case IEEE80211_FCTL_TODS:
1157 memcpy(dst, hdr->addr3, ETH_ALEN);
1158 memcpy(src, hdr->addr2, ETH_ALEN);
1159 memcpy(bssid, hdr->addr1, ETH_ALEN);
1161 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1162 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1164 memcpy(dst, hdr->addr3, ETH_ALEN);
1165 memcpy(src, hdr->addr4, ETH_ALEN);
1166 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1169 memcpy(dst, hdr->addr1, ETH_ALEN);
1170 memcpy(src, hdr->addr2, ETH_ALEN);
1171 memcpy(bssid, hdr->addr3, ETH_ALEN);
1176 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1179 skb->dev = dev = wds;
1180 stats = hostap_get_stats(dev);
1183 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1184 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1186 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1187 /* Frame from BSSID of the AP for which we are a client */
1188 skb->dev = dev = ieee->stadev;
1189 stats = hostap_get_stats(dev);
1194 dev->last_rx = jiffies;
1197 if ((ieee->iw_mode == IW_MODE_MASTER ||
1198 ieee->iw_mode == IW_MODE_REPEAT) &&
1200 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1202 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1203 frame_authorized = 0;
1205 case AP_RX_CONTINUE:
1206 frame_authorized = 1;
1215 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1216 /* Nullfunc frames may have PS-bit set, so they must be passed to
1217 * hostap_handle_sta_rx() before being dropped here. */
1218 if (stype != IEEE80211_STYPE_DATA &&
1219 stype != IEEE80211_STYPE_DATA_CFACK &&
1220 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1221 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1222 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1224 if (stype != IEEE80211_STYPE_NULLFUNC)
1225 IEEE80211_DEBUG_DROP(
1226 "RX: dropped data frame "
1227 "with no data (type=0x%02x, "
1228 "subtype=0x%02x, len=%d)\n",
1229 type, stype, skb->len);
1232 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1236 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == 1)
1237 && (ieee->polling)) {
1238 if (WLAN_FC_MORE_DATA(fc)) {
1239 /* more data bit is set, let's request a new frame from the AP */
1240 ieee80211_sta_ps_send_pspoll_frame(ieee);
1242 ieee->polling = false;
1247 ieee->need_sw_enc = 0;
1249 if((!rx_stats->Decrypted)){
1250 ieee->need_sw_enc = 1;
1253 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1255 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1256 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1258 printk("decrypt frame error\n");
1263 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1265 /* skb: hdr + (possibly fragmented) plaintext payload */
1266 // PR: FIXME: hostap has additional conditions in the "if" below:
1267 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1268 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1270 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1271 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1274 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1275 "Rx cannot get skb from fragment "
1276 "cache (morefrag=%d seq=%u frag=%u)\n",
1277 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1278 WLAN_GET_SEQ_SEQ(sc), frag);
1285 if (frag_skb->tail + flen > frag_skb->end) {
1286 printk(KERN_WARNING "%s: host decrypted and "
1287 "reassembled frame did not fit skb\n",
1289 ieee80211_frag_cache_invalidate(ieee, hdr);
1294 /* copy first fragment (including full headers) into
1295 * beginning of the fragment cache skb */
1296 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1298 /* append frame payload to the end of the fragment
1300 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1303 dev_kfree_skb_any(skb);
1306 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1307 /* more fragments expected - leave the skb in fragment
1308 * cache for now; it will be delivered to upper layers
1309 * after all fragments have been received */
1313 /* this was the last fragment and the frame will be
1314 * delivered, so remove skb from fragment cache */
1316 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1317 ieee80211_frag_cache_invalidate(ieee, hdr);
1320 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1321 * encrypted/authenticated */
1322 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1323 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1325 printk("==>decrypt msdu error\n");
1329 //added by amy for AP roaming
1330 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1331 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1333 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1334 if((!is_multicast_ether_addr(hdr->addr1)) && (!is_broadcast_ether_addr(hdr->addr1)))
1335 unicast_packet = true;
1337 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1338 if (/*ieee->ieee802_1x &&*/
1339 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1341 #ifdef CONFIG_IEEE80211_DEBUG
1342 /* pass unencrypted EAPOL frames even if encryption is
1344 struct eapol *eap = (struct eapol *)(skb->data +
1346 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1347 eap_get_type(eap->type));
1350 IEEE80211_DEBUG_DROP(
1351 "encryption configured, but RX "
1352 "frame not encrypted (SA=%pM)\n",
1358 #ifdef CONFIG_IEEE80211_DEBUG
1359 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1360 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1361 struct eapol *eap = (struct eapol *)(skb->data +
1363 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1364 eap_get_type(eap->type));
1368 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1369 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1370 IEEE80211_DEBUG_DROP(
1371 "dropped unencrypted RX data "
1373 " (drop_unencrypted=1)\n",
1378 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1379 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1382 //added by amy for reorder
1384 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1385 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1387 TID = Frame_QoSTID(skb->data);
1388 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1389 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1390 if(TID !=0 && TID !=3)
1392 ieee->bis_any_nonbepkts = true;
1396 //added by amy for reorder
1397 /* skb: hdr + (possible reassembled) full plaintext payload */
1398 payload = skb->data + hdrlen;
1399 //ethertype = (payload[6] << 8) | payload[7];
1400 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1403 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1406 /* to parse amsdu packets */
1407 /* qos data packets & reserved bit is 1 */
1408 if(parse_subframe(ieee, skb,rx_stats,rxb,src,dst) == 0) {
1409 /* only to free rxb, and not submit the packets to upper layer */
1410 for(i =0; i < rxb->nr_subframes; i++) {
1411 dev_kfree_skb(rxb->subframes[i]);
1421 if (type == IEEE80211_FTYPE_DATA)
1424 if(ieee->bIsAggregateFrame)
1425 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod+=rxb->nr_subframes;
1427 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod++;
1429 // 2009.03.03 Leave DC mode immediately when detect high traffic
1430 // DbgPrint("ending Seq %d\n", Frame_SeqNum(pduOS));
1431 if((ieee->state == IEEE80211_LINKED) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/)
1433 if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
1434 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
1436 if(ieee->LeisurePSLeave)
1437 ieee->LeisurePSLeave(dev);
1444 ieee->last_rx_ps_time = jiffies;
1445 //added by amy for reorder
1446 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1447 //added by amy for reorder
1448 for(i = 0; i<rxb->nr_subframes; i++) {
1449 struct sk_buff *sub_skb = rxb->subframes[i];
1452 /* convert hdr + possible LLC headers into Ethernet header */
1453 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1454 if (sub_skb->len >= 8 &&
1455 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1456 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1457 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1458 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1459 * replace EtherType */
1460 skb_pull(sub_skb, SNAP_SIZE);
1461 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1462 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1465 /* Leave Ethernet header part of hdr and full payload */
1466 len = htons(sub_skb->len);
1467 memcpy(skb_push(sub_skb, 2), &len, 2);
1468 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1469 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1472 stats->rx_packets++;
1473 stats->rx_bytes += sub_skb->len;
1474 if(is_multicast_ether_addr(dst)) {
1478 /* Indicat the packets to upper layer */
1479 //printk("0skb_len(%d)\n", skb->len);
1480 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1481 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1483 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1484 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1485 //printk("1skb_len(%d)\n", skb->len);
1495 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1496 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1505 hostap_handle_sta_release(sta);
1515 stats->rx_dropped++;
1517 /* Returning 0 indicates to caller that we have not handled the SKB--
1518 * so it is still allocated and can be used again by underlying
1519 * hardware as a DMA target */
1523 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1525 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1528 * Make ther structure we read from the beacon packet has
1531 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1532 *info_element, int sub_type)
1535 if (info_element->qui_subtype != sub_type)
1537 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1539 if (info_element->qui_type != QOS_OUI_TYPE)
1541 if (info_element->version != QOS_VERSION_1)
1549 * Parse a QoS parameter element
1551 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1552 *element_param, struct ieee80211_info_element
1556 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1558 if ((info_element == NULL) || (element_param == NULL))
1561 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1562 memcpy(element_param->info_element.qui, info_element->data,
1564 element_param->info_element.elementID = info_element->id;
1565 element_param->info_element.length = info_element->len;
1569 ret = ieee80211_verify_qos_info(&element_param->info_element,
1570 QOS_OUI_PARAM_SUB_TYPE);
1575 * Parse a QoS information element
1577 static int ieee80211_read_qos_info_element(struct
1578 ieee80211_qos_information_element
1579 *element_info, struct ieee80211_info_element
1583 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1585 if (element_info == NULL)
1587 if (info_element == NULL)
1590 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1591 memcpy(element_info->qui, info_element->data,
1593 element_info->elementID = info_element->id;
1594 element_info->length = info_element->len;
1599 ret = ieee80211_verify_qos_info(element_info,
1600 QOS_OUI_INFO_SUB_TYPE);
1606 * Write QoS parameters from the ac parameters.
1608 static int ieee80211_qos_convert_ac_to_parameters(struct
1609 ieee80211_qos_parameter_info
1611 ieee80211_qos_parameters
1616 struct ieee80211_qos_ac_parameter *ac_params;
1621 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1622 ac_params = &(param_elm->ac_params_record[i]);
1624 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1626 if(aci >= QOS_QUEUE_NUM)
1628 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1630 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1631 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1633 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1635 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1637 qos_param->flag[aci] =
1638 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1639 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1645 * we have a generic data element which it may contain QoS information or
1646 * parameters element. check the information element length to decide
1647 * which type to read
1649 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1651 struct ieee80211_network *network)
1654 struct ieee80211_qos_parameters *qos_param = NULL;
1655 struct ieee80211_qos_information_element qos_info_element;
1657 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1660 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1661 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1663 struct ieee80211_qos_parameter_info param_element;
1665 rc = ieee80211_read_qos_param_element(¶m_element,
1668 qos_param = &(network->qos_data.parameters);
1669 ieee80211_qos_convert_ac_to_parameters(¶m_element,
1671 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1672 network->qos_data.param_count =
1673 param_element.info_element.ac_info & 0x0F;
1678 IEEE80211_DEBUG_QOS("QoS is supported\n");
1679 network->qos_data.supported = 1;
1684 #ifdef CONFIG_IEEE80211_DEBUG
1685 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1687 static const char *get_info_element_string(u16 id)
1692 MFIE_STRING(FH_SET);
1693 MFIE_STRING(DS_SET);
1694 MFIE_STRING(CF_SET);
1696 MFIE_STRING(IBSS_SET);
1697 MFIE_STRING(COUNTRY);
1698 MFIE_STRING(HOP_PARAMS);
1699 MFIE_STRING(HOP_TABLE);
1700 MFIE_STRING(REQUEST);
1701 MFIE_STRING(CHALLENGE);
1702 MFIE_STRING(POWER_CONSTRAINT);
1703 MFIE_STRING(POWER_CAPABILITY);
1704 MFIE_STRING(TPC_REQUEST);
1705 MFIE_STRING(TPC_REPORT);
1706 MFIE_STRING(SUPP_CHANNELS);
1708 MFIE_STRING(MEASURE_REQUEST);
1709 MFIE_STRING(MEASURE_REPORT);
1711 MFIE_STRING(IBSS_DFS);
1712 // MFIE_STRING(ERP_INFO);
1714 MFIE_STRING(RATES_EX);
1715 MFIE_STRING(GENERIC);
1716 MFIE_STRING(QOS_PARAMETER);
1723 #ifdef ENABLE_DOT11D
1724 static inline void ieee80211_extract_country_ie(
1725 struct ieee80211_device *ieee,
1726 struct ieee80211_info_element *info_element,
1727 struct ieee80211_network *network,
1731 if(IS_DOT11D_ENABLE(ieee))
1733 if(info_element->len!= 0)
1735 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1736 network->CountryIeLen = info_element->len;
1738 if(!IS_COUNTRY_IE_VALID(ieee))
1740 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1745 // 070305, rcnjko: I update country IE watch dog here because
1746 // some AP (e.g. Cisco 1242) don't include country IE in their
1747 // probe response frame.
1749 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1751 UPDATE_CIE_WATCHDOG(ieee);
1758 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1759 struct ieee80211_info_element *info_element,
1761 struct ieee80211_network *network,
1762 struct ieee80211_rx_stats *stats)
1766 u16 tmp_htcap_len=0;
1767 u16 tmp_htinfo_len=0;
1768 u16 ht_realtek_agg_len=0;
1769 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1770 // u16 broadcom_len = 0;
1771 #ifdef CONFIG_IEEE80211_DEBUG
1776 while (length >= sizeof(*info_element)) {
1777 if (sizeof(*info_element) + info_element->len > length) {
1778 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1779 "info_element->len + 2 > left : "
1780 "info_element->len+2=%zd left=%d, id=%d.\n",
1782 sizeof(*info_element),
1783 length, info_element->id);
1784 /* We stop processing but don't return an error here
1785 * because some misbehaviour APs break this rule. ie.
1786 * Orinoco AP1000. */
1790 switch (info_element->id) {
1791 case MFIE_TYPE_SSID:
1792 if (ieee80211_is_empty_essid(info_element->data,
1793 info_element->len)) {
1794 network->flags |= NETWORK_EMPTY_ESSID;
1798 network->ssid_len = min(info_element->len,
1799 (u8) IW_ESSID_MAX_SIZE);
1800 memcpy(network->ssid, info_element->data, network->ssid_len);
1801 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1802 memset(network->ssid + network->ssid_len, 0,
1803 IW_ESSID_MAX_SIZE - network->ssid_len);
1805 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1806 network->ssid, network->ssid_len);
1809 case MFIE_TYPE_RATES:
1810 #ifdef CONFIG_IEEE80211_DEBUG
1813 network->rates_len = min(info_element->len,
1815 for (i = 0; i < network->rates_len; i++) {
1816 network->rates[i] = info_element->data[i];
1817 #ifdef CONFIG_IEEE80211_DEBUG
1818 p += snprintf(p, sizeof(rates_str) -
1819 (p - rates_str), "%02X ",
1822 if (ieee80211_is_ofdm_rate
1823 (info_element->data[i])) {
1824 network->flags |= NETWORK_HAS_OFDM;
1825 if (info_element->data[i] &
1826 IEEE80211_BASIC_RATE_MASK)
1832 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1833 rates_str, network->rates_len);
1836 case MFIE_TYPE_RATES_EX:
1837 #ifdef CONFIG_IEEE80211_DEBUG
1840 network->rates_ex_len = min(info_element->len,
1841 MAX_RATES_EX_LENGTH);
1842 for (i = 0; i < network->rates_ex_len; i++) {
1843 network->rates_ex[i] = info_element->data[i];
1844 #ifdef CONFIG_IEEE80211_DEBUG
1845 p += snprintf(p, sizeof(rates_str) -
1846 (p - rates_str), "%02X ",
1849 if (ieee80211_is_ofdm_rate
1850 (info_element->data[i])) {
1851 network->flags |= NETWORK_HAS_OFDM;
1852 if (info_element->data[i] &
1853 IEEE80211_BASIC_RATE_MASK)
1859 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1860 rates_str, network->rates_ex_len);
1863 case MFIE_TYPE_DS_SET:
1864 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1865 info_element->data[0]);
1866 network->channel = info_element->data[0];
1869 case MFIE_TYPE_FH_SET:
1870 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1873 case MFIE_TYPE_CF_SET:
1874 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1878 if(info_element->len < 4)
1881 network->tim.tim_count = info_element->data[0];
1882 network->tim.tim_period = info_element->data[1];
1884 network->dtim_period = info_element->data[1];
1885 if(ieee->state != IEEE80211_LINKED)
1888 network->last_dtim_sta_time[0] = stats->mac_time[0];
1890 //we use jiffies for legacy Power save
1891 network->last_dtim_sta_time[0] = jiffies;
1893 network->last_dtim_sta_time[1] = stats->mac_time[1];
1895 network->dtim_data = IEEE80211_DTIM_VALID;
1897 if(info_element->data[0] != 0)
1900 if(info_element->data[2] & 1)
1901 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1903 offset = (info_element->data[2] >> 1)*2;
1905 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1907 if(ieee->assoc_id < 8*offset ||
1908 ieee->assoc_id > 8*(offset + info_element->len -3))
1912 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1914 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1915 network->dtim_data |= IEEE80211_DTIM_UCAST;
1917 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1921 network->erp_value = info_element->data[0];
1922 network->flags |= NETWORK_HAS_ERP_VALUE;
1923 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1924 network->erp_value);
1926 case MFIE_TYPE_IBSS_SET:
1927 network->atim_window = info_element->data[0];
1928 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1929 network->atim_window);
1932 case MFIE_TYPE_CHALLENGE:
1933 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1936 case MFIE_TYPE_GENERIC:
1937 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1939 if (!ieee80211_parse_qos_info_param_IE(info_element,
1943 if (info_element->len >= 4 &&
1944 info_element->data[0] == 0x00 &&
1945 info_element->data[1] == 0x50 &&
1946 info_element->data[2] == 0xf2 &&
1947 info_element->data[3] == 0x01) {
1948 network->wpa_ie_len = min(info_element->len + 2,
1950 memcpy(network->wpa_ie, info_element,
1951 network->wpa_ie_len);
1956 if (info_element->len == 7 &&
1957 info_element->data[0] == 0x00 &&
1958 info_element->data[1] == 0xe0 &&
1959 info_element->data[2] == 0x4c &&
1960 info_element->data[3] == 0x01 &&
1961 info_element->data[4] == 0x02) {
1962 network->Turbo_Enable = 1;
1966 //for HTcap and HTinfo parameters
1967 if(tmp_htcap_len == 0){
1968 if(info_element->len >= 4 &&
1969 info_element->data[0] == 0x00 &&
1970 info_element->data[1] == 0x90 &&
1971 info_element->data[2] == 0x4c &&
1972 info_element->data[3] == 0x033){
1974 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1975 if(tmp_htcap_len != 0){
1976 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1977 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1978 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1979 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1982 if(tmp_htcap_len != 0)
1983 network->bssht.bdSupportHT = true;
1985 network->bssht.bdSupportHT = false;
1989 if(tmp_htinfo_len == 0){
1990 if(info_element->len >= 4 &&
1991 info_element->data[0] == 0x00 &&
1992 info_element->data[1] == 0x90 &&
1993 info_element->data[2] == 0x4c &&
1994 info_element->data[3] == 0x034){
1996 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1997 if(tmp_htinfo_len != 0){
1998 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2000 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2001 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2002 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2010 if(ieee->aggregation){
2011 if(network->bssht.bdSupportHT){
2012 if(info_element->len >= 4 &&
2013 info_element->data[0] == 0x00 &&
2014 info_element->data[1] == 0xe0 &&
2015 info_element->data[2] == 0x4c &&
2016 info_element->data[3] == 0x02){
2018 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
2019 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
2022 if(ht_realtek_agg_len >= 5){
2023 network->bssht.bdRT2RTAggregation = true;
2025 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
2026 network->bssht.bdRT2RTLongSlotTime = true;
2032 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
2034 if((info_element->len >= 3 &&
2035 info_element->data[0] == 0x00 &&
2036 info_element->data[1] == 0x05 &&
2037 info_element->data[2] == 0xb5) ||
2038 (info_element->len >= 3 &&
2039 info_element->data[0] == 0x00 &&
2040 info_element->data[1] == 0x0a &&
2041 info_element->data[2] == 0xf7) ||
2042 (info_element->len >= 3 &&
2043 info_element->data[0] == 0x00 &&
2044 info_element->data[1] == 0x10 &&
2045 info_element->data[2] == 0x18)){
2047 network->broadcom_cap_exist = true;
2052 if (tmp_htcap_len !=0)
2054 u16 cap_ext = ((PHT_CAPABILITY_ELE)&info_element->data[0])->ExtHTCapInfo;
2055 if ((cap_ext & 0x0c00) == 0x0c00)
2057 network->ralink_cap_exist = true;
2061 if(info_element->len >= 3 &&
2062 info_element->data[0] == 0x00 &&
2063 info_element->data[1] == 0x0c &&
2064 info_element->data[2] == 0x43)
2066 network->ralink_cap_exist = true;
2069 network->ralink_cap_exist = false;
2070 //added by amy for atheros AP
2071 if((info_element->len >= 3 &&
2072 info_element->data[0] == 0x00 &&
2073 info_element->data[1] == 0x03 &&
2074 info_element->data[2] == 0x7f) ||
2075 (info_element->len >= 3 &&
2076 info_element->data[0] == 0x00 &&
2077 info_element->data[1] == 0x13 &&
2078 info_element->data[2] == 0x74))
2080 //printk("========>%s(): athros AP is exist\n",__FUNCTION__);
2081 network->atheros_cap_exist = true;
2084 network->atheros_cap_exist = false;
2086 if ((info_element->len >= 3 &&
2087 info_element->data[0] == 0x00 &&
2088 info_element->data[1] == 0x50 &&
2089 info_element->data[2] == 0x43) )
2091 network->marvell_cap_exist = true;
2092 //printk("========>%s(): marvel AP is exist\n",__FUNCTION__);
2096 if(info_element->len >= 3 &&
2097 info_element->data[0] == 0x00 &&
2098 info_element->data[1] == 0x40 &&
2099 info_element->data[2] == 0x96)
2101 network->cisco_cap_exist = true;
2104 network->cisco_cap_exist = false;
2105 //added by amy for LEAP of cisco
2106 if(info_element->len > 4 &&
2107 info_element->data[0] == 0x00 &&
2108 info_element->data[1] == 0x40 &&
2109 info_element->data[2] == 0x96 &&
2110 info_element->data[3] == 0x01)
2112 if(info_element->len == 6)
2114 memcpy(network->CcxRmState, &info_element[4], 2);
2115 if(network->CcxRmState[0] != 0)
2117 network->bCcxRmEnable = true;
2120 network->bCcxRmEnable = false;
2122 // CCXv4 Table 59-1 MBSSID Masks.
2124 network->MBssidMask = network->CcxRmState[1] & 0x07;
2125 if(network->MBssidMask != 0)
2127 network->bMBssidValid = true;
2128 network->MBssidMask = 0xff << (network->MBssidMask);
2129 cpMacAddr(network->MBssid, network->bssid);
2130 network->MBssid[5] &= network->MBssidMask;
2134 network->bMBssidValid = false;
2139 network->bCcxRmEnable = false;
2142 if(info_element->len > 4 &&
2143 info_element->data[0] == 0x00 &&
2144 info_element->data[1] == 0x40 &&
2145 info_element->data[2] == 0x96 &&
2146 info_element->data[3] == 0x03)
2148 if(info_element->len == 5)
2150 network->bWithCcxVerNum = true;
2151 network->BssCcxVerNumber = info_element->data[4];
2155 network->bWithCcxVerNum = false;
2156 network->BssCcxVerNumber = 0;
2162 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2164 network->rsn_ie_len = min(info_element->len + 2,
2166 memcpy(network->rsn_ie, info_element,
2167 network->rsn_ie_len);
2170 //HT related element.
2171 case MFIE_TYPE_HT_CAP:
2172 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2174 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2175 if(tmp_htcap_len != 0){
2176 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2177 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2178 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2179 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2181 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2182 // windows driver will update WMM parameters each beacon received once connected
2183 // Linux driver is a bit different.
2184 network->bssht.bdSupportHT = true;
2187 network->bssht.bdSupportHT = false;
2191 case MFIE_TYPE_HT_INFO:
2192 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2194 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2196 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2197 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2198 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2199 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2203 case MFIE_TYPE_AIRONET:
2204 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2206 if(info_element->len >IE_CISCO_FLAG_POSITION)
2208 network->bWithAironetIE = true;
2210 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2211 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2212 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2213 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
2214 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
2216 network->bCkipSupported = true;
2220 network->bCkipSupported = false;
2225 network->bWithAironetIE = false;
2226 network->bCkipSupported = false;
2229 case MFIE_TYPE_QOS_PARAMETER:
2231 "QoS Error need to parse QOS_PARAMETER IE\n");
2234 #ifdef ENABLE_DOT11D
2235 case MFIE_TYPE_COUNTRY:
2236 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2238 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2239 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2245 case MFIE_TYPE_POWER_CONSTRAINT:
2246 network->power_constraint = info_element->data[0];
2247 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
2251 network->power_constraint = info_element->data[0];
2252 network->flags |= NETWORK_HAS_CSA;
2255 case MFIE_TYPE_QUIET:
2256 network->quiet.count = info_element->data[0];
2257 network->quiet.period = info_element->data[1];
2258 network->quiet.duration = info_element->data[2];
2259 network->quiet.offset = info_element->data[3];
2260 network->flags |= NETWORK_HAS_QUIET;
2263 case MFIE_TYPE_IBSS_DFS:
2264 if (network->ibss_dfs)
2266 network->ibss_dfs = kmemdup(info_element->data,
2269 if (!network->ibss_dfs)
2271 network->flags |= NETWORK_HAS_IBSS_DFS;
2274 case MFIE_TYPE_TPC_REPORT:
2275 network->tpc_report.transmit_power =
2276 info_element->data[0];
2277 network->tpc_report.link_margin = info_element->data[1];
2278 network->flags |= NETWORK_HAS_TPC_REPORT;
2282 IEEE80211_DEBUG_MGMT
2283 ("Unsupported info element: %s (%d)\n",
2284 get_info_element_string(info_element->id),
2289 length -= sizeof(*info_element) + info_element->len;
2291 (struct ieee80211_info_element *)&info_element->
2292 data[info_element->len];
2295 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2296 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation &&
2297 !network->marvell_cap_exist)
2299 network->unknown_cap_exist = true;
2303 network->unknown_cap_exist = false;
2308 static inline u8 ieee80211_SignalStrengthTranslate(
2314 // Step 1. Scale mapping.
2315 if(CurrSS >= 71 && CurrSS <= 100)
2317 RetSS = 90 + ((CurrSS - 70) / 3);
2319 else if(CurrSS >= 41 && CurrSS <= 70)
2321 RetSS = 78 + ((CurrSS - 40) / 3);
2323 else if(CurrSS >= 31 && CurrSS <= 40)
2325 RetSS = 66 + (CurrSS - 30);
2327 else if(CurrSS >= 21 && CurrSS <= 30)
2329 RetSS = 54 + (CurrSS - 20);
2331 else if(CurrSS >= 5 && CurrSS <= 20)
2333 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2335 else if(CurrSS == 4)
2339 else if(CurrSS == 3)
2343 else if(CurrSS == 2)
2347 else if(CurrSS == 1)
2355 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2357 // Step 2. Smoothing.
2359 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2364 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2366 long signal_power; // in dBm.
2368 // Translate to dBm (x=0.5y-95).
2369 signal_power = (long)((signal_strength_index + 1) >> 1);
2372 return signal_power;
2375 static inline int ieee80211_network_init(
2376 struct ieee80211_device *ieee,
2377 struct ieee80211_probe_response *beacon,
2378 struct ieee80211_network *network,
2379 struct ieee80211_rx_stats *stats)
2381 #ifdef CONFIG_IEEE80211_DEBUG
2382 //char rates_str[64];
2386 network->qos_data.active = 0;
2387 network->qos_data.supported = 0;
2388 network->qos_data.param_count = 0;
2389 network->qos_data.old_param_count = 0;
2391 /* Pull out fixed field data */
2392 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2393 network->capability = le16_to_cpu(beacon->capability);
2394 network->last_scanned = jiffies;
2395 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2396 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2397 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2398 /* Where to pull this? beacon->listen_interval;*/
2399 network->listen_interval = 0x0A;
2400 network->rates_len = network->rates_ex_len = 0;
2401 network->last_associate = 0;
2402 network->ssid_len = 0;
2404 network->atim_window = 0;
2405 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2407 network->berp_info_valid = false;
2408 network->broadcom_cap_exist = false;
2409 network->ralink_cap_exist = false;
2410 network->atheros_cap_exist = false;
2411 network->marvell_cap_exist = false;
2412 network->cisco_cap_exist = false;
2413 network->unknown_cap_exist = false;
2415 network->Turbo_Enable = 0;
2417 #ifdef ENABLE_DOT11D
2418 network->CountryIeLen = 0;
2419 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2421 //Initialize HT parameters
2422 //ieee80211_ht_initialize(&network->bssht);
2423 HTInitializeBssDesc(&network->bssht);
2424 if (stats->freq == IEEE80211_52GHZ_BAND) {
2425 /* for A band (No DS info) */
2426 network->channel = stats->received_channel;
2428 network->flags |= NETWORK_HAS_CCK;
2430 network->wpa_ie_len = 0;
2431 network->rsn_ie_len = 0;
2433 if (ieee80211_parse_info_param
2434 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2438 if (stats->freq == IEEE80211_52GHZ_BAND)
2439 network->mode = IEEE_A;
2441 if (network->flags & NETWORK_HAS_OFDM)
2442 network->mode |= IEEE_G;
2443 if (network->flags & NETWORK_HAS_CCK)
2444 network->mode |= IEEE_B;
2447 if (network->mode == 0) {
2448 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2450 escape_essid(network->ssid,
2456 if(network->bssht.bdSupportHT){
2457 if(network->mode == IEEE_A)
2458 network->mode = IEEE_N_5G;
2459 else if(network->mode & (IEEE_G | IEEE_B))
2460 network->mode = IEEE_N_24G;
2462 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2463 network->flags |= NETWORK_EMPTY_ESSID;
2466 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2467 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2468 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2471 memcpy(&network->stats, stats, sizeof(network->stats));
2476 static inline int is_same_network(struct ieee80211_network *src,
2477 struct ieee80211_network *dst, struct ieee80211_device* ieee)
2479 /* A network is only a duplicate if the channel, BSSID, ESSID
2480 * and the capability field (in particular IBSS and BSS) all match.
2481 * We treat all <hidden> with the same BSSID and channel
2483 return //((src->ssid_len == dst->ssid_len) &&
2484 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2485 (src->channel == dst->channel) &&
2486 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2487 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2488 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2489 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2490 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2491 ((src->capability & WLAN_CAPABILITY_BSS) ==
2492 (dst->capability & WLAN_CAPABILITY_BSS)));
2495 static inline void update_network(struct ieee80211_network *dst,
2496 struct ieee80211_network *src)
2501 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2502 dst->capability = src->capability;
2503 memcpy(dst->rates, src->rates, src->rates_len);
2504 dst->rates_len = src->rates_len;
2505 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2506 dst->rates_ex_len = src->rates_ex_len;
2507 if(src->ssid_len > 0)
2509 memset(dst->ssid, 0, dst->ssid_len);
2510 dst->ssid_len = src->ssid_len;
2511 memcpy(dst->ssid, src->ssid, src->ssid_len);
2513 dst->mode = src->mode;
2514 dst->flags = src->flags;
2515 dst->time_stamp[0] = src->time_stamp[0];
2516 dst->time_stamp[1] = src->time_stamp[1];
2517 if (src->flags & NETWORK_HAS_ERP_VALUE)
2519 dst->erp_value = src->erp_value;
2520 dst->berp_info_valid = src->berp_info_valid = true;
2522 dst->beacon_interval = src->beacon_interval;
2523 dst->listen_interval = src->listen_interval;
2524 dst->atim_window = src->atim_window;
2525 dst->dtim_period = src->dtim_period;
2526 dst->dtim_data = src->dtim_data;
2527 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2528 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2529 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2531 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2532 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2533 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2534 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2535 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2536 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2537 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2538 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2539 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2540 dst->ralink_cap_exist = src->ralink_cap_exist;
2541 dst->atheros_cap_exist = src->atheros_cap_exist;
2542 dst->marvell_cap_exist = src->marvell_cap_exist;
2543 dst->cisco_cap_exist = src->cisco_cap_exist;
2544 dst->unknown_cap_exist = src->unknown_cap_exist;
2545 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2546 dst->wpa_ie_len = src->wpa_ie_len;
2547 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2548 dst->rsn_ie_len = src->rsn_ie_len;
2550 dst->last_scanned = jiffies;
2551 /* qos related parameters */
2552 //qos_active = src->qos_data.active;
2553 qos_active = dst->qos_data.active;
2554 //old_param = dst->qos_data.old_param_count;
2555 old_param = dst->qos_data.param_count;
2556 if(dst->flags & NETWORK_HAS_QOS_MASK){
2557 //not update QOS paramter in beacon, as most AP will set all these parameter to 0.//WB
2558 // printk("====>%s(), aifs:%x, %x\n", __FUNCTION__, dst->qos_data.parameters.aifs[0], src->qos_data.parameters.aifs[0]);
2559 // memcpy(&dst->qos_data, &src->qos_data,
2560 // sizeof(struct ieee80211_qos_data));
2563 dst->qos_data.supported = src->qos_data.supported;
2564 dst->qos_data.param_count = src->qos_data.param_count;
2567 if(dst->qos_data.supported == 1) {
2568 dst->QoS_Enable = 1;
2571 ("QoS the network %s is QoS supported\n",
2575 ("QoS the network is QoS supported\n");
2577 dst->qos_data.active = qos_active;
2578 dst->qos_data.old_param_count = old_param;
2580 /* dst->last_associate is not overwritten */
2582 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2583 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2584 src->wmm_param[1].ac_aci_acm_aifsn|| \
2585 src->wmm_param[2].ac_aci_acm_aifsn|| \
2586 src->wmm_param[1].ac_aci_acm_aifsn) {
2587 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2589 //dst->QoS_Enable = src->QoS_Enable;
2591 dst->QoS_Enable = 1;//for Rtl8187 simulation
2594 dst->Turbo_Enable = src->Turbo_Enable;
2597 #ifdef ENABLE_DOT11D
2598 dst->CountryIeLen = src->CountryIeLen;
2599 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2602 //added by amy for LEAP
2603 dst->bWithAironetIE = src->bWithAironetIE;
2604 dst->bCkipSupported = src->bCkipSupported;
2605 memcpy(dst->CcxRmState,src->CcxRmState,2);
2606 dst->bCcxRmEnable = src->bCcxRmEnable;
2607 dst->MBssidMask = src->MBssidMask;
2608 dst->bMBssidValid = src->bMBssidValid;
2609 memcpy(dst->MBssid,src->MBssid,6);
2610 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2611 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2615 static inline int is_beacon(__le16 fc)
2617 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2620 static inline void ieee80211_process_probe_response(
2621 struct ieee80211_device *ieee,
2622 struct ieee80211_probe_response *beacon,
2623 struct ieee80211_rx_stats *stats)
2625 struct ieee80211_network network;
2626 struct ieee80211_network *target;
2627 struct ieee80211_network *oldest = NULL;
2628 #ifdef CONFIG_IEEE80211_DEBUG
2629 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2631 unsigned long flags;
2635 memset(&network, 0, sizeof(struct ieee80211_network));
2636 IEEE80211_DEBUG_SCAN(
2637 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2638 escape_essid(info_element->data, info_element->len),
2639 beacon->header.addr3,
2640 (beacon->capability & (1<<0xf)) ? '1' : '0',
2641 (beacon->capability & (1<<0xe)) ? '1' : '0',
2642 (beacon->capability & (1<<0xd)) ? '1' : '0',
2643 (beacon->capability & (1<<0xc)) ? '1' : '0',
2644 (beacon->capability & (1<<0xb)) ? '1' : '0',
2645 (beacon->capability & (1<<0xa)) ? '1' : '0',
2646 (beacon->capability & (1<<0x9)) ? '1' : '0',
2647 (beacon->capability & (1<<0x8)) ? '1' : '0',
2648 (beacon->capability & (1<<0x7)) ? '1' : '0',
2649 (beacon->capability & (1<<0x6)) ? '1' : '0',
2650 (beacon->capability & (1<<0x5)) ? '1' : '0',
2651 (beacon->capability & (1<<0x4)) ? '1' : '0',
2652 (beacon->capability & (1<<0x3)) ? '1' : '0',
2653 (beacon->capability & (1<<0x2)) ? '1' : '0',
2654 (beacon->capability & (1<<0x1)) ? '1' : '0',
2655 (beacon->capability & (1<<0x0)) ? '1' : '0');
2657 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2658 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2659 escape_essid(info_element->data,
2661 beacon->header.addr3,
2662 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2663 IEEE80211_STYPE_PROBE_RESP ?
2664 "PROBE RESPONSE" : "BEACON");
2668 #ifdef ENABLE_DOT11D
2669 // For Asus EeePc request,
2670 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2671 // wireless adapter should follow the country code.
2672 // (2) If there is no any country code in beacon,
2673 // then wireless adapter should do active scan from ch1~11 and
2674 // passive scan from ch12~14
2676 if( !IsLegalChannel(ieee, network.channel) )
2678 if(ieee->bGlobalDomain)
2680 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2682 // Case 1: Country code
2683 if(IS_COUNTRY_IE_VALID(ieee) )
2685 if( !IsLegalChannel(ieee, network.channel) )
2687 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2691 // Case 2: No any country code.
2694 // Filter over channel ch12~14
2695 if(network.channel > 11)
2697 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2704 // Case 1: Country code
2705 if(IS_COUNTRY_IE_VALID(ieee) )
2707 if( !IsLegalChannel(ieee, network.channel) )
2709 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2713 // Case 2: No any country code.
2716 // Filter over channel ch12~14
2717 if(network.channel > 14)
2719 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2727 /* The network parsed correctly -- so now we scan our known networks
2728 * to see if we can find it in our list.
2730 * NOTE: This search is definitely not optimized. Once its doing
2731 * the "right thing" we'll optimize it for efficiency if
2734 /* Search for this entry in the list and update it if it is
2737 spin_lock_irqsave(&ieee->lock, flags);
2739 if(is_same_network(&ieee->current_network, &network, ieee)) {
2740 update_network(&ieee->current_network, &network);
2741 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2742 && ieee->current_network.berp_info_valid){
2743 if(ieee->current_network.erp_value& ERP_UseProtection)
2744 ieee->current_network.buseprotection = true;
2746 ieee->current_network.buseprotection = false;
2748 if(is_beacon(beacon->header.frame_ctl))
2750 if(ieee->state == IEEE80211_LINKED)
2751 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2754 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2757 list_for_each_entry(target, &ieee->network_list, list) {
2758 if (is_same_network(target, &network, ieee))
2760 if ((oldest == NULL) ||
2761 (target->last_scanned < oldest->last_scanned))
2765 /* If we didn't find a match, then get a new network slot to initialize
2766 * with this beacon's information */
2767 if (&target->list == &ieee->network_list) {
2768 if (list_empty(&ieee->network_free_list)) {
2769 /* If there are no more slots, expire the oldest */
2770 list_del(&oldest->list);
2772 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2774 escape_essid(target->ssid,
2778 /* Otherwise just pull from the free list */
2779 target = list_entry(ieee->network_free_list.next,
2780 struct ieee80211_network, list);
2781 list_del(ieee->network_free_list.next);
2785 #ifdef CONFIG_IEEE80211_DEBUG
2786 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2787 escape_essid(network.ssid,
2790 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2791 IEEE80211_STYPE_PROBE_RESP ?
2792 "PROBE RESPONSE" : "BEACON");
2794 memcpy(target, &network, sizeof(*target));
2795 list_add_tail(&target->list, &ieee->network_list);
2797 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2798 escape_essid(target->ssid,
2801 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2802 IEEE80211_STYPE_PROBE_RESP ?
2803 "PROBE RESPONSE" : "BEACON");
2805 /* we have an entry and we are going to update it. But this entry may
2806 * be already expired. In this case we do the same as we found a new
2807 * net and call the new_net handler
2809 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2810 //YJ,add,080819,for hidden ap
2811 if(is_beacon(beacon->header.frame_ctl) == 0)
2812 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2813 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2814 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2815 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2816 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2817 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2819 //YJ,add,080819,for hidden ap,end
2821 update_network(target, &network);
2824 spin_unlock_irqrestore(&ieee->lock, flags);
2825 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2826 (ieee->state == IEEE80211_LINKED)) {
2827 if(ieee->handle_beacon != NULL) {
2828 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2833 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2834 struct ieee80211_hdr_4addr *header,
2835 struct ieee80211_rx_stats *stats)
2838 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2839 ieee->iw_mode == IW_MODE_INFRA &&
2840 ieee->state == IEEE80211_LINKED))
2842 tasklet_schedule(&ieee->ps_task);
2846 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2847 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2848 ieee->last_rx_ps_time = jiffies;
2850 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2852 case IEEE80211_STYPE_BEACON:
2853 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2854 WLAN_FC_GET_STYPE(header->frame_ctl));
2855 IEEE80211_DEBUG_SCAN("Beacon\n");
2856 ieee80211_process_probe_response(
2857 ieee, (struct ieee80211_probe_response *)header, stats);
2859 //printk("----------->%s()\n", __func__);
2860 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2861 ieee->iw_mode == IW_MODE_INFRA &&
2862 ieee->state == IEEE80211_LINKED))
2864 tasklet_schedule(&ieee->ps_task);
2869 case IEEE80211_STYPE_PROBE_RESP:
2870 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2871 WLAN_FC_GET_STYPE(header->frame_ctl));
2872 IEEE80211_DEBUG_SCAN("Probe response\n");
2873 ieee80211_process_probe_response(
2874 ieee, (struct ieee80211_probe_response *)header, stats);
2880 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2881 //EXPORT_SYMBOL(ieee80211_rx_mgt);
2882 //EXPORT_SYMBOL(ieee80211_rx);
2884 EXPORT_SYMBOL_NOVERS(ieee80211_rx_mgt);
2885 EXPORT_SYMBOL_NOVERS(ieee80211_rx);