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;
311 hdr = (struct ieee80211_hdr_4addr *) skb->data;
312 fc = le16_to_cpu(hdr->frame_ctl);
314 /* check that the frame is unicast frame to us */
315 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
316 IEEE80211_FCTL_TODS &&
317 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
318 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
319 /* ToDS frame with own addr BSSID and DA */
320 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
321 IEEE80211_FCTL_FROMDS &&
322 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
323 /* FromDS frame with own addr as DA */
327 if (skb->len < 24 + 8)
330 /* check for port access entity Ethernet type */
331 // pos = skb->data + 24;
332 pos = skb->data + hdrlen;
333 ethertype = (pos[6] << 8) | pos[7];
334 if (ethertype == ETH_P_PAE)
340 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
342 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
343 struct ieee80211_crypt_data *crypt)
345 struct ieee80211_hdr_4addr *hdr;
348 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
350 if (ieee->hwsec_active)
352 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
353 tcb_desc->bHwSec = 1;
355 hdr = (struct ieee80211_hdr_4addr *) skb->data;
356 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
358 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
359 if (ieee->tkip_countermeasures &&
360 strcmp(crypt->ops->name, "TKIP") == 0) {
361 if (net_ratelimit()) {
362 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
363 "received packet from %pM\n",
364 ieee->dev->name, hdr->addr2);
370 atomic_inc(&crypt->refcnt);
371 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
372 atomic_dec(&crypt->refcnt);
374 IEEE80211_DEBUG_DROP(
375 "decryption failed (SA=%pM"
376 ") res=%d\n", hdr->addr2, res);
378 IEEE80211_DEBUG_DROP("Decryption failed ICV "
379 "mismatch (key %d)\n",
380 skb->data[hdrlen + 3] >> 6);
381 ieee->ieee_stats.rx_discards_undecryptable++;
389 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
391 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
392 int keyidx, struct ieee80211_crypt_data *crypt)
394 struct ieee80211_hdr_4addr *hdr;
397 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
399 if (ieee->hwsec_active)
401 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
402 tcb_desc->bHwSec = 1;
405 hdr = (struct ieee80211_hdr_4addr *) skb->data;
406 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
408 atomic_inc(&crypt->refcnt);
409 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
410 atomic_dec(&crypt->refcnt);
412 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
413 " (SA=%pM keyidx=%d)\n",
414 ieee->dev->name, hdr->addr2, keyidx);
422 /* this function is stolen from ipw2200 driver*/
423 #define IEEE_PACKET_RETRY_TIME (5*HZ)
424 static int is_duplicate_packet(struct ieee80211_device *ieee,
425 struct ieee80211_hdr_4addr *header)
427 u16 fc = le16_to_cpu(header->frame_ctl);
428 u16 sc = le16_to_cpu(header->seq_ctl);
429 u16 seq = WLAN_GET_SEQ_SEQ(sc);
430 u16 frag = WLAN_GET_SEQ_FRAG(sc);
431 u16 *last_seq, *last_frag;
432 unsigned long *last_time;
433 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
434 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
439 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
440 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
441 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
444 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
445 hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
446 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
453 switch (ieee->iw_mode) {
457 struct ieee_ibss_seq *entry = NULL;
458 u8 *mac = header->addr2;
459 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
460 //for (pos = (head)->next; pos != (head); pos = pos->next)
461 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
462 list_for_each(p, &ieee->ibss_mac_hash[index]) {
463 entry = list_entry(p, struct ieee_ibss_seq, list);
464 if (!memcmp(entry->mac, mac, ETH_ALEN))
467 // if (memcmp(entry->mac, mac, ETH_ALEN)){
468 if (p == &ieee->ibss_mac_hash[index]) {
469 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
471 printk(KERN_WARNING "Cannot malloc new mac entry\n");
474 memcpy(entry->mac, mac, ETH_ALEN);
475 entry->seq_num[tid] = seq;
476 entry->frag_num[tid] = frag;
477 entry->packet_time[tid] = jiffies;
478 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
481 last_seq = &entry->seq_num[tid];
482 last_frag = &entry->frag_num[tid];
483 last_time = &entry->packet_time[tid];
488 last_seq = &ieee->last_rxseq_num[tid];
489 last_frag = &ieee->last_rxfrag_num[tid];
490 last_time = &ieee->last_packet_time[tid];
498 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
500 if ((*last_seq == seq) &&
501 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
502 if (*last_frag == frag){
503 //printk(KERN_WARNING "[1] go drop!\n");
507 if (*last_frag + 1 != frag)
508 /* out-of-order fragment */
509 //printk(KERN_WARNING "[2] go drop!\n");
515 *last_time = jiffies;
519 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
527 PRX_REORDER_ENTRY pReorderEntry
530 struct list_head *pList = &pTS->RxPendingPktList;
531 while(pList->next != &pTS->RxPendingPktList)
533 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
537 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
546 pReorderEntry->List.next = pList->next;
547 pReorderEntry->List.next->prev = &pReorderEntry->List;
548 pReorderEntry->List.prev = pList;
549 pList->next = &pReorderEntry->List;
554 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index)
559 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
560 for(j = 0; j<index; j++)
562 //added by amy for reorder
563 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
564 for(i = 0; i<prxb->nr_subframes; i++) {
565 struct sk_buff *sub_skb = prxb->subframes[i];
567 /* convert hdr + possible LLC headers into Ethernet header */
568 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
569 if (sub_skb->len >= 8 &&
570 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
571 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
572 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
573 /* remove RFC1042 or Bridge-Tunnel encapsulation and
574 * replace EtherType */
575 skb_pull(sub_skb, SNAP_SIZE);
576 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
577 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
580 /* Leave Ethernet header part of hdr and full payload */
581 len = htons(sub_skb->len);
582 memcpy(skb_push(sub_skb, 2), &len, 2);
583 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
584 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
586 //stats->rx_packets++;
587 //stats->rx_bytes += sub_skb->len;
589 /* Indicat the packets to upper layer */
591 //printk("0skb_len(%d)\n", skb->len);
592 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
593 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
594 sub_skb->dev = ieee->dev;
595 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
596 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
597 ieee->last_rx_ps_time = jiffies;
598 //printk("1skb_len(%d)\n", skb->len);
608 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
609 struct ieee80211_rxb* prxb,
613 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
614 PRX_REORDER_ENTRY pReorderEntry = NULL;
615 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
616 u8 WinSize = pHTInfo->RxReorderWinSize;
617 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
619 bool bMatchWinStart = false, bPktInBuf = false;
620 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
621 /* Rx Reorder initialize condition.*/
622 if(pTS->RxIndicateSeq == 0xffff) {
623 pTS->RxIndicateSeq = SeqNum;
626 /* Drop out the packet which SeqNum is smaller than WinStart */
627 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
628 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
629 pTS->RxIndicateSeq, SeqNum);
630 pHTInfo->RxReorderDropCounter++;
633 for(i =0; i < prxb->nr_subframes; i++) {
634 dev_kfree_skb(prxb->subframes[i]);
643 * Sliding window manipulation. Conditions includes:
644 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
645 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
647 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
648 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
649 bMatchWinStart = true;
650 } else if(SN_LESS(WinEnd, SeqNum)) {
651 if(SeqNum >= (WinSize - 1)) {
652 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
654 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
656 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
660 * Indication process.
661 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
662 * with the SeqNum smaller than latest WinStart and buffer other packets.
664 /* For Rx Reorder condition:
665 * 1. All packets with SeqNum smaller than WinStart => Indicate
666 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
669 /* Current packet is going to be indicated.*/
670 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
671 pTS->RxIndicateSeq, SeqNum);
672 prxbIndicateArray[0] = prxb;
673 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
676 /* Current packet is going to be inserted into pending list.*/
677 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
678 if(!list_empty(&ieee->RxReorder_Unused_List)) {
679 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
680 list_del_init(&pReorderEntry->List);
682 /* Make a reorder entry and insert into a the packet list.*/
683 pReorderEntry->SeqNum = SeqNum;
684 pReorderEntry->prxb = prxb;
685 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
687 if(!AddReorderEntry(pTS, pReorderEntry)) {
688 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
689 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
690 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
693 for(i =0; i < prxb->nr_subframes; i++) {
694 dev_kfree_skb(prxb->subframes[i]);
700 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
701 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
706 * Packets are dropped if there is not enough reorder entries.
707 * This part shall be modified!! We can just indicate all the
708 * packets in buffer and get reorder entries.
710 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
713 for(i =0; i < prxb->nr_subframes; i++) {
714 dev_kfree_skb(prxb->subframes[i]);
722 /* Check if there is any packet need indicate.*/
723 while(!list_empty(&pTS->RxPendingPktList)) {
724 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
725 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
726 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
727 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
729 /* This protect buffer from overflow. */
730 if(index >= REORDER_WIN_SIZE) {
731 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
736 list_del_init(&pReorderEntry->List);
738 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
739 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
741 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
742 prxbIndicateArray[index] = pReorderEntry->prxb;
743 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
746 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
753 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
755 // Cancel previous pending timer.
756 // del_timer_sync(&pTS->RxPktPendingTimer);
757 pTS->RxTimeoutIndicateSeq = 0xffff;
760 if(index>REORDER_WIN_SIZE){
761 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
764 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
767 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
768 // Set new pending timer.
769 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
770 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
771 if(timer_pending(&pTS->RxPktPendingTimer))
772 del_timer_sync(&pTS->RxPktPendingTimer);
773 pTS->RxPktPendingTimer.expires = jiffies + MSECS(pHTInfo->RxReorderPendingTime);
774 add_timer(&pTS->RxPktPendingTimer);
778 u8 parse_subframe(struct sk_buff *skb,
779 struct ieee80211_rx_stats *rx_stats,
780 struct ieee80211_rxb *rxb,u8* src,u8* dst)
782 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
783 u16 fc = le16_to_cpu(hdr->frame_ctl);
785 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
787 bool bIsAggregateFrame = false;
788 u16 nSubframe_Length;
789 u8 nPadding_Length = 0;
792 struct sk_buff *sub_skb;
794 /* just for debug purpose */
795 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
797 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
798 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
799 bIsAggregateFrame = true;
802 if(IEEE80211_QOS_HAS_SEQ(fc)) {
806 if(rx_stats->bContainHTC) {
807 LLCOffset += sHTCLng;
809 //printk("ChkLength = %d\n", LLCOffset);
810 // Null packet, don't indicate it to upper layer
811 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
813 if( skb->len <= ChkLength ) {
817 skb_pull(skb, LLCOffset);
819 if(!bIsAggregateFrame) {
820 rxb->nr_subframes = 1;
822 rxb->subframes[0] = skb;
824 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
827 memcpy(rxb->src,src,ETH_ALEN);
828 memcpy(rxb->dst,dst,ETH_ALEN);
829 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
832 rxb->nr_subframes = 0;
833 memcpy(rxb->src,src,ETH_ALEN);
834 memcpy(rxb->dst,dst,ETH_ALEN);
835 while(skb->len > ETHERNET_HEADER_SIZE) {
836 /* Offset 12 denote 2 mac address */
837 nSubframe_Length = *((u16*)(skb->data + 12));
838 //==m==>change the length order
839 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
841 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
842 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
843 __FUNCTION__,rxb->nr_subframes);
844 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
845 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
846 printk("The Packet SeqNum is %d\n",SeqNum);
850 /* move the data point to data content */
851 skb_pull(skb, ETHERNET_HEADER_SIZE);
854 sub_skb = skb_clone(skb, GFP_ATOMIC);
855 sub_skb->len = nSubframe_Length;
856 sub_skb->tail = sub_skb->data + nSubframe_Length;
858 /* Allocate new skb for releasing to upper layer */
859 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
860 skb_reserve(sub_skb, 12);
861 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
862 memcpy(data_ptr,skb->data,nSubframe_Length);
864 rxb->subframes[rxb->nr_subframes++] = sub_skb;
865 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
866 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
869 skb_pull(skb,nSubframe_Length);
872 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
873 if(nPadding_Length == 4) {
877 if(skb->len < nPadding_Length) {
881 skb_pull(skb,nPadding_Length);
887 //{just for debug added by david
888 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
890 return rxb->nr_subframes;
894 /* All received frames are sent to this function. @skb contains the frame in
895 * IEEE 802.11 format, i.e., in the format it was sent over air.
896 * This function is called only as a tasklet (software IRQ). */
897 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
898 struct ieee80211_rx_stats *rx_stats)
900 struct net_device *dev = ieee->dev;
901 struct ieee80211_hdr_4addr *hdr;
902 //struct ieee80211_hdr_3addrqos *hdr;
905 u16 fc, type, stype, sc;
906 struct net_device_stats *stats;
910 //added by amy for reorder
913 PRX_TS_RECORD pTS = NULL;
914 //bool bIsAggregateFrame = false;
915 //added by amy for reorder
917 struct net_device *wds = NULL;
918 struct sk_buff *skb2 = NULL;
919 struct net_device *wds = NULL;
920 int frame_authorized = 0;
921 int from_assoc_ap = 0;
928 struct ieee80211_crypt_data *crypt = NULL;
932 struct ieee80211_rxb* rxb = NULL;
933 // cheat the the hdr type
934 hdr = (struct ieee80211_hdr_4addr *)skb->data;
935 stats = &ieee->stats;
938 printk(KERN_INFO "%s: SKB length < 10\n",
943 fc = le16_to_cpu(hdr->frame_ctl);
944 type = WLAN_FC_GET_TYPE(fc);
945 stype = WLAN_FC_GET_STYPE(fc);
946 sc = le16_to_cpu(hdr->seq_ctl);
948 frag = WLAN_GET_SEQ_FRAG(sc);
949 hdrlen = ieee80211_get_hdrlen(fc);
951 if(HTCCheck(ieee, skb->data))
954 printk("find HTCControl\n");
956 rx_stats->bContainHTC = 1;
959 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
961 #if WIRELESS_EXT > 15
962 /* Put this code here so that we avoid duplicating it in all
963 * Rx paths. - Jean II */
964 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
965 /* If spy monitoring on */
966 if (iface->spy_data.spy_number > 0) {
967 struct iw_quality wstats;
968 wstats.level = rx_stats->rssi;
969 wstats.noise = rx_stats->noise;
970 wstats.updated = 6; /* No qual value */
971 /* Update spy records */
972 wireless_spy_update(dev, hdr->addr2, &wstats);
974 #endif /* IW_WIRELESS_SPY */
975 #endif /* WIRELESS_EXT > 15 */
976 hostap_update_rx_stats(local->ap, hdr, rx_stats);
979 #if WIRELESS_EXT > 15
980 if (ieee->iw_mode == IW_MODE_MONITOR) {
981 ieee80211_monitor_rx(ieee, skb, rx_stats);
983 stats->rx_bytes += skb->len;
987 if (ieee->host_decrypt) {
989 if (skb->len >= hdrlen + 3)
990 idx = skb->data[hdrlen + 3] >> 6;
991 crypt = ieee->crypt[idx];
995 /* Use station specific key to override default keys if the
996 * receiver address is a unicast address ("individual RA"). If
997 * bcrx_sta_key parameter is set, station specific key is used
998 * even with broad/multicast targets (this is against IEEE
999 * 802.11, but makes it easier to use different keys with
1000 * stations that do not support WEP key mapping). */
1002 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1003 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1007 /* allow NULL decrypt to indicate an station specific override
1008 * for default encryption */
1009 if (crypt && (crypt->ops == NULL ||
1010 crypt->ops->decrypt_mpdu == NULL))
1013 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
1014 /* This seems to be triggered by some (multicast?)
1015 * frames from other than current BSS, so just drop the
1016 * frames silently instead of filling system log with
1018 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1021 ieee->ieee_stats.rx_discards_undecryptable++;
1026 if (skb->len < IEEE80211_DATA_HDR3_LEN)
1029 // if QoS enabled, should check the sequence for each of the AC
1030 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
1031 if (is_duplicate_packet(ieee, hdr))
1037 PRX_TS_RECORD pRxTS = NULL;
1038 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1041 (PTS_COMMON_INFO*) &pRxTS,
1043 (u8)Frame_QoSTID((u8*)(skb->data)),
1048 // 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));
1049 if( (fc & (1<<11)) &&
1050 (frag == pRxTS->RxLastFragNum) &&
1051 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
1057 pRxTS->RxLastFragNum = frag;
1058 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1063 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
1067 if (type == IEEE80211_FTYPE_MGMT) {
1070 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1071 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1077 /* Data frame - extract src/dst addresses */
1078 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1079 case IEEE80211_FCTL_FROMDS:
1080 memcpy(dst, hdr->addr1, ETH_ALEN);
1081 memcpy(src, hdr->addr3, ETH_ALEN);
1082 memcpy(bssid, hdr->addr2, ETH_ALEN);
1084 case IEEE80211_FCTL_TODS:
1085 memcpy(dst, hdr->addr3, ETH_ALEN);
1086 memcpy(src, hdr->addr2, ETH_ALEN);
1087 memcpy(bssid, hdr->addr1, ETH_ALEN);
1089 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1090 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1092 memcpy(dst, hdr->addr3, ETH_ALEN);
1093 memcpy(src, hdr->addr4, ETH_ALEN);
1094 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1097 memcpy(dst, hdr->addr1, ETH_ALEN);
1098 memcpy(src, hdr->addr2, ETH_ALEN);
1099 memcpy(bssid, hdr->addr3, ETH_ALEN);
1104 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1107 skb->dev = dev = wds;
1108 stats = hostap_get_stats(dev);
1111 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1112 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1114 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1115 /* Frame from BSSID of the AP for which we are a client */
1116 skb->dev = dev = ieee->stadev;
1117 stats = hostap_get_stats(dev);
1122 dev->last_rx = jiffies;
1125 if ((ieee->iw_mode == IW_MODE_MASTER ||
1126 ieee->iw_mode == IW_MODE_REPEAT) &&
1128 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1130 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1131 frame_authorized = 0;
1133 case AP_RX_CONTINUE:
1134 frame_authorized = 1;
1143 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1144 /* Nullfunc frames may have PS-bit set, so they must be passed to
1145 * hostap_handle_sta_rx() before being dropped here. */
1146 if (stype != IEEE80211_STYPE_DATA &&
1147 stype != IEEE80211_STYPE_DATA_CFACK &&
1148 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1149 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1150 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1152 if (stype != IEEE80211_STYPE_NULLFUNC)
1153 IEEE80211_DEBUG_DROP(
1154 "RX: dropped data frame "
1155 "with no data (type=0x%02x, "
1156 "subtype=0x%02x, len=%d)\n",
1157 type, stype, skb->len);
1160 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1163 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1165 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1166 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1168 printk("decrypt frame error\n");
1173 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1175 /* skb: hdr + (possibly fragmented) plaintext payload */
1176 // PR: FIXME: hostap has additional conditions in the "if" below:
1177 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1178 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1180 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1181 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1184 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1185 "Rx cannot get skb from fragment "
1186 "cache (morefrag=%d seq=%u frag=%u)\n",
1187 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1188 WLAN_GET_SEQ_SEQ(sc), frag);
1195 if (frag_skb->tail + flen > frag_skb->end) {
1196 printk(KERN_WARNING "%s: host decrypted and "
1197 "reassembled frame did not fit skb\n",
1199 ieee80211_frag_cache_invalidate(ieee, hdr);
1204 /* copy first fragment (including full headers) into
1205 * beginning of the fragment cache skb */
1206 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1208 /* append frame payload to the end of the fragment
1210 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1213 dev_kfree_skb_any(skb);
1216 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1217 /* more fragments expected - leave the skb in fragment
1218 * cache for now; it will be delivered to upper layers
1219 * after all fragments have been received */
1223 /* this was the last fragment and the frame will be
1224 * delivered, so remove skb from fragment cache */
1226 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1227 ieee80211_frag_cache_invalidate(ieee, hdr);
1230 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1231 * encrypted/authenticated */
1232 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1233 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1235 printk("==>decrypt msdu error\n");
1239 //added by amy for AP roaming
1240 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1241 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1243 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1244 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1245 if (/*ieee->ieee802_1x &&*/
1246 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1248 #ifdef CONFIG_IEEE80211_DEBUG
1249 /* pass unencrypted EAPOL frames even if encryption is
1251 struct eapol *eap = (struct eapol *)(skb->data +
1253 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1254 eap_get_type(eap->type));
1257 IEEE80211_DEBUG_DROP(
1258 "encryption configured, but RX "
1259 "frame not encrypted (SA=%pM)\n",
1265 #ifdef CONFIG_IEEE80211_DEBUG
1266 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1267 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1268 struct eapol *eap = (struct eapol *)(skb->data +
1270 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1271 eap_get_type(eap->type));
1275 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1276 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1277 IEEE80211_DEBUG_DROP(
1278 "dropped unencrypted RX data "
1280 " (drop_unencrypted=1)\n",
1285 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1286 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1289 //added by amy for reorder
1290 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1291 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1293 TID = Frame_QoSTID(skb->data);
1294 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1295 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1296 if(TID !=0 && TID !=3)
1298 ieee->bis_any_nonbepkts = true;
1301 //added by amy for reorder
1302 /* skb: hdr + (possible reassembled) full plaintext payload */
1303 payload = skb->data + hdrlen;
1304 //ethertype = (payload[6] << 8) | payload[7];
1305 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1308 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1311 /* to parse amsdu packets */
1312 /* qos data packets & reserved bit is 1 */
1313 if(parse_subframe(skb,rx_stats,rxb,src,dst) == 0) {
1314 /* only to free rxb, and not submit the packets to upper layer */
1315 for(i =0; i < rxb->nr_subframes; i++) {
1316 dev_kfree_skb(rxb->subframes[i]);
1323 //added by amy for reorder
1324 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1325 //added by amy for reorder
1326 for(i = 0; i<rxb->nr_subframes; i++) {
1327 struct sk_buff *sub_skb = rxb->subframes[i];
1330 /* convert hdr + possible LLC headers into Ethernet header */
1331 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1332 if (sub_skb->len >= 8 &&
1333 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1334 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1335 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1336 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1337 * replace EtherType */
1338 skb_pull(sub_skb, SNAP_SIZE);
1339 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1340 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1343 /* Leave Ethernet header part of hdr and full payload */
1344 len = htons(sub_skb->len);
1345 memcpy(skb_push(sub_skb, 2), &len, 2);
1346 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1347 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1350 stats->rx_packets++;
1351 stats->rx_bytes += sub_skb->len;
1352 if(is_multicast_ether_addr(dst)) {
1356 /* Indicat the packets to upper layer */
1357 //printk("0skb_len(%d)\n", skb->len);
1358 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1359 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1361 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1362 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1363 ieee->last_rx_ps_time = jiffies;
1364 //printk("1skb_len(%d)\n", skb->len);
1374 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1375 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1384 hostap_handle_sta_release(sta);
1394 stats->rx_dropped++;
1396 /* Returning 0 indicates to caller that we have not handled the SKB--
1397 * so it is still allocated and can be used again by underlying
1398 * hardware as a DMA target */
1402 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1404 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1407 * Make ther structure we read from the beacon packet has
1410 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1411 *info_element, int sub_type)
1414 if (info_element->qui_subtype != sub_type)
1416 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1418 if (info_element->qui_type != QOS_OUI_TYPE)
1420 if (info_element->version != QOS_VERSION_1)
1428 * Parse a QoS parameter element
1430 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1431 *element_param, struct ieee80211_info_element
1435 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1437 if ((info_element == NULL) || (element_param == NULL))
1440 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1441 memcpy(element_param->info_element.qui, info_element->data,
1443 element_param->info_element.elementID = info_element->id;
1444 element_param->info_element.length = info_element->len;
1448 ret = ieee80211_verify_qos_info(&element_param->info_element,
1449 QOS_OUI_PARAM_SUB_TYPE);
1454 * Parse a QoS information element
1456 static int ieee80211_read_qos_info_element(struct
1457 ieee80211_qos_information_element
1458 *element_info, struct ieee80211_info_element
1462 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1464 if (element_info == NULL)
1466 if (info_element == NULL)
1469 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1470 memcpy(element_info->qui, info_element->data,
1472 element_info->elementID = info_element->id;
1473 element_info->length = info_element->len;
1478 ret = ieee80211_verify_qos_info(element_info,
1479 QOS_OUI_INFO_SUB_TYPE);
1485 * Write QoS parameters from the ac parameters.
1487 static int ieee80211_qos_convert_ac_to_parameters(struct
1488 ieee80211_qos_parameter_info
1490 ieee80211_qos_parameters
1495 struct ieee80211_qos_ac_parameter *ac_params;
1500 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1501 ac_params = &(param_elm->ac_params_record[i]);
1503 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1505 if(aci >= QOS_QUEUE_NUM)
1507 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1509 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1510 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1512 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1514 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1516 qos_param->flag[aci] =
1517 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1518 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1524 * we have a generic data element which it may contain QoS information or
1525 * parameters element. check the information element length to decide
1526 * which type to read
1528 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1530 struct ieee80211_network *network)
1533 struct ieee80211_qos_parameters *qos_param = NULL;
1534 struct ieee80211_qos_information_element qos_info_element;
1536 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1539 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1540 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1542 struct ieee80211_qos_parameter_info param_element;
1544 rc = ieee80211_read_qos_param_element(¶m_element,
1547 qos_param = &(network->qos_data.parameters);
1548 ieee80211_qos_convert_ac_to_parameters(¶m_element,
1550 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1551 network->qos_data.param_count =
1552 param_element.info_element.ac_info & 0x0F;
1557 IEEE80211_DEBUG_QOS("QoS is supported\n");
1558 network->qos_data.supported = 1;
1563 #ifdef CONFIG_IEEE80211_DEBUG
1564 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1566 static const char *get_info_element_string(u16 id)
1571 MFIE_STRING(FH_SET);
1572 MFIE_STRING(DS_SET);
1573 MFIE_STRING(CF_SET);
1575 MFIE_STRING(IBSS_SET);
1576 MFIE_STRING(COUNTRY);
1577 MFIE_STRING(HOP_PARAMS);
1578 MFIE_STRING(HOP_TABLE);
1579 MFIE_STRING(REQUEST);
1580 MFIE_STRING(CHALLENGE);
1581 MFIE_STRING(POWER_CONSTRAINT);
1582 MFIE_STRING(POWER_CAPABILITY);
1583 MFIE_STRING(TPC_REQUEST);
1584 MFIE_STRING(TPC_REPORT);
1585 MFIE_STRING(SUPP_CHANNELS);
1587 MFIE_STRING(MEASURE_REQUEST);
1588 MFIE_STRING(MEASURE_REPORT);
1590 MFIE_STRING(IBSS_DFS);
1591 // MFIE_STRING(ERP_INFO);
1593 MFIE_STRING(RATES_EX);
1594 MFIE_STRING(GENERIC);
1595 MFIE_STRING(QOS_PARAMETER);
1602 #ifdef ENABLE_DOT11D
1603 static inline void ieee80211_extract_country_ie(
1604 struct ieee80211_device *ieee,
1605 struct ieee80211_info_element *info_element,
1606 struct ieee80211_network *network,
1610 if(IS_DOT11D_ENABLE(ieee))
1612 if(info_element->len!= 0)
1614 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1615 network->CountryIeLen = info_element->len;
1617 if(!IS_COUNTRY_IE_VALID(ieee))
1619 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1624 // 070305, rcnjko: I update country IE watch dog here because
1625 // some AP (e.g. Cisco 1242) don't include country IE in their
1626 // probe response frame.
1628 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1630 UPDATE_CIE_WATCHDOG(ieee);
1637 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1638 struct ieee80211_info_element *info_element,
1640 struct ieee80211_network *network,
1641 struct ieee80211_rx_stats *stats)
1645 u16 tmp_htcap_len=0;
1646 u16 tmp_htinfo_len=0;
1647 u16 ht_realtek_agg_len=0;
1648 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1649 // u16 broadcom_len = 0;
1650 #ifdef CONFIG_IEEE80211_DEBUG
1655 while (length >= sizeof(*info_element)) {
1656 if (sizeof(*info_element) + info_element->len > length) {
1657 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1658 "info_element->len + 2 > left : "
1659 "info_element->len+2=%zd left=%d, id=%d.\n",
1661 sizeof(*info_element),
1662 length, info_element->id);
1663 /* We stop processing but don't return an error here
1664 * because some misbehaviour APs break this rule. ie.
1665 * Orinoco AP1000. */
1669 switch (info_element->id) {
1670 case MFIE_TYPE_SSID:
1671 if (ieee80211_is_empty_essid(info_element->data,
1672 info_element->len)) {
1673 network->flags |= NETWORK_EMPTY_ESSID;
1677 network->ssid_len = min(info_element->len,
1678 (u8) IW_ESSID_MAX_SIZE);
1679 memcpy(network->ssid, info_element->data, network->ssid_len);
1680 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1681 memset(network->ssid + network->ssid_len, 0,
1682 IW_ESSID_MAX_SIZE - network->ssid_len);
1684 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1685 network->ssid, network->ssid_len);
1688 case MFIE_TYPE_RATES:
1689 #ifdef CONFIG_IEEE80211_DEBUG
1692 network->rates_len = min(info_element->len,
1694 for (i = 0; i < network->rates_len; i++) {
1695 network->rates[i] = info_element->data[i];
1696 #ifdef CONFIG_IEEE80211_DEBUG
1697 p += snprintf(p, sizeof(rates_str) -
1698 (p - rates_str), "%02X ",
1701 if (ieee80211_is_ofdm_rate
1702 (info_element->data[i])) {
1703 network->flags |= NETWORK_HAS_OFDM;
1704 if (info_element->data[i] &
1705 IEEE80211_BASIC_RATE_MASK)
1711 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1712 rates_str, network->rates_len);
1715 case MFIE_TYPE_RATES_EX:
1716 #ifdef CONFIG_IEEE80211_DEBUG
1719 network->rates_ex_len = min(info_element->len,
1720 MAX_RATES_EX_LENGTH);
1721 for (i = 0; i < network->rates_ex_len; i++) {
1722 network->rates_ex[i] = info_element->data[i];
1723 #ifdef CONFIG_IEEE80211_DEBUG
1724 p += snprintf(p, sizeof(rates_str) -
1725 (p - rates_str), "%02X ",
1728 if (ieee80211_is_ofdm_rate
1729 (info_element->data[i])) {
1730 network->flags |= NETWORK_HAS_OFDM;
1731 if (info_element->data[i] &
1732 IEEE80211_BASIC_RATE_MASK)
1738 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1739 rates_str, network->rates_ex_len);
1742 case MFIE_TYPE_DS_SET:
1743 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1744 info_element->data[0]);
1745 network->channel = info_element->data[0];
1748 case MFIE_TYPE_FH_SET:
1749 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1752 case MFIE_TYPE_CF_SET:
1753 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1757 if(info_element->len < 4)
1760 network->tim.tim_count = info_element->data[0];
1761 network->tim.tim_period = info_element->data[1];
1763 network->dtim_period = info_element->data[1];
1764 if(ieee->state != IEEE80211_LINKED)
1767 network->last_dtim_sta_time[0] = stats->mac_time[0];
1768 network->last_dtim_sta_time[1] = stats->mac_time[1];
1770 network->dtim_data = IEEE80211_DTIM_VALID;
1772 if(info_element->data[0] != 0)
1775 if(info_element->data[2] & 1)
1776 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1778 offset = (info_element->data[2] >> 1)*2;
1780 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1782 if(ieee->assoc_id < 8*offset ||
1783 ieee->assoc_id > 8*(offset + info_element->len -3))
1787 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1789 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1790 network->dtim_data |= IEEE80211_DTIM_UCAST;
1792 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1796 network->erp_value = info_element->data[0];
1797 network->flags |= NETWORK_HAS_ERP_VALUE;
1798 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1799 network->erp_value);
1801 case MFIE_TYPE_IBSS_SET:
1802 network->atim_window = info_element->data[0];
1803 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1804 network->atim_window);
1807 case MFIE_TYPE_CHALLENGE:
1808 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1811 case MFIE_TYPE_GENERIC:
1812 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1814 if (!ieee80211_parse_qos_info_param_IE(info_element,
1818 if (info_element->len >= 4 &&
1819 info_element->data[0] == 0x00 &&
1820 info_element->data[1] == 0x50 &&
1821 info_element->data[2] == 0xf2 &&
1822 info_element->data[3] == 0x01) {
1823 network->wpa_ie_len = min(info_element->len + 2,
1825 memcpy(network->wpa_ie, info_element,
1826 network->wpa_ie_len);
1831 if (info_element->len == 7 &&
1832 info_element->data[0] == 0x00 &&
1833 info_element->data[1] == 0xe0 &&
1834 info_element->data[2] == 0x4c &&
1835 info_element->data[3] == 0x01 &&
1836 info_element->data[4] == 0x02) {
1837 network->Turbo_Enable = 1;
1841 //for HTcap and HTinfo parameters
1842 if(tmp_htcap_len == 0){
1843 if(info_element->len >= 4 &&
1844 info_element->data[0] == 0x00 &&
1845 info_element->data[1] == 0x90 &&
1846 info_element->data[2] == 0x4c &&
1847 info_element->data[3] == 0x033){
1849 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1850 if(tmp_htcap_len != 0){
1851 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1852 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1853 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1854 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1857 if(tmp_htcap_len != 0)
1858 network->bssht.bdSupportHT = true;
1860 network->bssht.bdSupportHT = false;
1864 if(tmp_htinfo_len == 0){
1865 if(info_element->len >= 4 &&
1866 info_element->data[0] == 0x00 &&
1867 info_element->data[1] == 0x90 &&
1868 info_element->data[2] == 0x4c &&
1869 info_element->data[3] == 0x034){
1871 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1872 if(tmp_htinfo_len != 0){
1873 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1875 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1876 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1877 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1885 if(ieee->aggregation){
1886 if(network->bssht.bdSupportHT){
1887 if(info_element->len >= 4 &&
1888 info_element->data[0] == 0x00 &&
1889 info_element->data[1] == 0xe0 &&
1890 info_element->data[2] == 0x4c &&
1891 info_element->data[3] == 0x02){
1893 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
1894 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
1897 if(ht_realtek_agg_len >= 5){
1898 network->bssht.bdRT2RTAggregation = true;
1900 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1901 network->bssht.bdRT2RTLongSlotTime = true;
1907 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1909 if((info_element->len >= 3 &&
1910 info_element->data[0] == 0x00 &&
1911 info_element->data[1] == 0x05 &&
1912 info_element->data[2] == 0xb5) ||
1913 (info_element->len >= 3 &&
1914 info_element->data[0] == 0x00 &&
1915 info_element->data[1] == 0x0a &&
1916 info_element->data[2] == 0xf7) ||
1917 (info_element->len >= 3 &&
1918 info_element->data[0] == 0x00 &&
1919 info_element->data[1] == 0x10 &&
1920 info_element->data[2] == 0x18)){
1922 network->broadcom_cap_exist = true;
1926 if(info_element->len >= 3 &&
1927 info_element->data[0] == 0x00 &&
1928 info_element->data[1] == 0x0c &&
1929 info_element->data[2] == 0x43)
1931 network->ralink_cap_exist = true;
1934 network->ralink_cap_exist = false;
1935 //added by amy for atheros AP
1936 if((info_element->len >= 3 &&
1937 info_element->data[0] == 0x00 &&
1938 info_element->data[1] == 0x03 &&
1939 info_element->data[2] == 0x7f) ||
1940 (info_element->len >= 3 &&
1941 info_element->data[0] == 0x00 &&
1942 info_element->data[1] == 0x13 &&
1943 info_element->data[2] == 0x74))
1945 printk("========>%s(): athros AP is exist\n",__FUNCTION__);
1946 network->atheros_cap_exist = true;
1949 network->atheros_cap_exist = false;
1951 if(info_element->len >= 3 &&
1952 info_element->data[0] == 0x00 &&
1953 info_element->data[1] == 0x40 &&
1954 info_element->data[2] == 0x96)
1956 network->cisco_cap_exist = true;
1959 network->cisco_cap_exist = false;
1960 //added by amy for LEAP of cisco
1961 if(info_element->len > 4 &&
1962 info_element->data[0] == 0x00 &&
1963 info_element->data[1] == 0x40 &&
1964 info_element->data[2] == 0x96 &&
1965 info_element->data[3] == 0x01)
1967 if(info_element->len == 6)
1969 memcpy(network->CcxRmState, &info_element[4], 2);
1970 if(network->CcxRmState[0] != 0)
1972 network->bCcxRmEnable = true;
1975 network->bCcxRmEnable = false;
1977 // CCXv4 Table 59-1 MBSSID Masks.
1979 network->MBssidMask = network->CcxRmState[1] & 0x07;
1980 if(network->MBssidMask != 0)
1982 network->bMBssidValid = true;
1983 network->MBssidMask = 0xff << (network->MBssidMask);
1984 cpMacAddr(network->MBssid, network->bssid);
1985 network->MBssid[5] &= network->MBssidMask;
1989 network->bMBssidValid = false;
1994 network->bCcxRmEnable = false;
1997 if(info_element->len > 4 &&
1998 info_element->data[0] == 0x00 &&
1999 info_element->data[1] == 0x40 &&
2000 info_element->data[2] == 0x96 &&
2001 info_element->data[3] == 0x03)
2003 if(info_element->len == 5)
2005 network->bWithCcxVerNum = true;
2006 network->BssCcxVerNumber = info_element->data[4];
2010 network->bWithCcxVerNum = false;
2011 network->BssCcxVerNumber = 0;
2017 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2019 network->rsn_ie_len = min(info_element->len + 2,
2021 memcpy(network->rsn_ie, info_element,
2022 network->rsn_ie_len);
2025 //HT related element.
2026 case MFIE_TYPE_HT_CAP:
2027 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2029 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2030 if(tmp_htcap_len != 0){
2031 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2032 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2033 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2034 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2036 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2037 // windows driver will update WMM parameters each beacon received once connected
2038 // Linux driver is a bit different.
2039 network->bssht.bdSupportHT = true;
2042 network->bssht.bdSupportHT = false;
2046 case MFIE_TYPE_HT_INFO:
2047 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2049 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2051 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2052 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2053 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2054 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2058 case MFIE_TYPE_AIRONET:
2059 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2061 if(info_element->len >IE_CISCO_FLAG_POSITION)
2063 network->bWithAironetIE = true;
2065 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2066 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2067 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2068 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
2069 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
2071 network->bCkipSupported = true;
2075 network->bCkipSupported = false;
2080 network->bWithAironetIE = false;
2081 network->bCkipSupported = false;
2084 case MFIE_TYPE_QOS_PARAMETER:
2086 "QoS Error need to parse QOS_PARAMETER IE\n");
2089 #ifdef ENABLE_DOT11D
2090 case MFIE_TYPE_COUNTRY:
2091 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2093 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2094 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2099 IEEE80211_DEBUG_MGMT
2100 ("Unsupported info element: %s (%d)\n",
2101 get_info_element_string(info_element->id),
2106 length -= sizeof(*info_element) + info_element->len;
2108 (struct ieee80211_info_element *)&info_element->
2109 data[info_element->len];
2112 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2113 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation)
2115 network->unknown_cap_exist = true;
2119 network->unknown_cap_exist = false;
2124 static inline u8 ieee80211_SignalStrengthTranslate(
2130 // Step 1. Scale mapping.
2131 if(CurrSS >= 71 && CurrSS <= 100)
2133 RetSS = 90 + ((CurrSS - 70) / 3);
2135 else if(CurrSS >= 41 && CurrSS <= 70)
2137 RetSS = 78 + ((CurrSS - 40) / 3);
2139 else if(CurrSS >= 31 && CurrSS <= 40)
2141 RetSS = 66 + (CurrSS - 30);
2143 else if(CurrSS >= 21 && CurrSS <= 30)
2145 RetSS = 54 + (CurrSS - 20);
2147 else if(CurrSS >= 5 && CurrSS <= 20)
2149 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2151 else if(CurrSS == 4)
2155 else if(CurrSS == 3)
2159 else if(CurrSS == 2)
2163 else if(CurrSS == 1)
2171 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2173 // Step 2. Smoothing.
2175 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2180 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2182 long signal_power; // in dBm.
2184 // Translate to dBm (x=0.5y-95).
2185 signal_power = (long)((signal_strength_index + 1) >> 1);
2188 return signal_power;
2191 static inline int ieee80211_network_init(
2192 struct ieee80211_device *ieee,
2193 struct ieee80211_probe_response *beacon,
2194 struct ieee80211_network *network,
2195 struct ieee80211_rx_stats *stats)
2197 #ifdef CONFIG_IEEE80211_DEBUG
2198 //char rates_str[64];
2202 network->qos_data.active = 0;
2203 network->qos_data.supported = 0;
2204 network->qos_data.param_count = 0;
2205 network->qos_data.old_param_count = 0;
2207 /* Pull out fixed field data */
2208 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2209 network->capability = le16_to_cpu(beacon->capability);
2210 network->last_scanned = jiffies;
2211 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2212 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2213 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2214 /* Where to pull this? beacon->listen_interval;*/
2215 network->listen_interval = 0x0A;
2216 network->rates_len = network->rates_ex_len = 0;
2217 network->last_associate = 0;
2218 network->ssid_len = 0;
2220 network->atim_window = 0;
2221 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2223 network->berp_info_valid = false;
2224 network->broadcom_cap_exist = false;
2225 network->ralink_cap_exist = false;
2226 network->atheros_cap_exist = false;
2227 network->cisco_cap_exist = false;
2228 network->unknown_cap_exist = false;
2230 network->Turbo_Enable = 0;
2232 #ifdef ENABLE_DOT11D
2233 network->CountryIeLen = 0;
2234 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2236 //Initialize HT parameters
2237 //ieee80211_ht_initialize(&network->bssht);
2238 HTInitializeBssDesc(&network->bssht);
2239 if (stats->freq == IEEE80211_52GHZ_BAND) {
2240 /* for A band (No DS info) */
2241 network->channel = stats->received_channel;
2243 network->flags |= NETWORK_HAS_CCK;
2245 network->wpa_ie_len = 0;
2246 network->rsn_ie_len = 0;
2248 if (ieee80211_parse_info_param
2249 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2253 if (stats->freq == IEEE80211_52GHZ_BAND)
2254 network->mode = IEEE_A;
2256 if (network->flags & NETWORK_HAS_OFDM)
2257 network->mode |= IEEE_G;
2258 if (network->flags & NETWORK_HAS_CCK)
2259 network->mode |= IEEE_B;
2262 if (network->mode == 0) {
2263 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2265 escape_essid(network->ssid,
2271 if(network->bssht.bdSupportHT){
2272 if(network->mode == IEEE_A)
2273 network->mode = IEEE_N_5G;
2274 else if(network->mode & (IEEE_G | IEEE_B))
2275 network->mode = IEEE_N_24G;
2277 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2278 network->flags |= NETWORK_EMPTY_ESSID;
2280 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2281 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2282 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2284 memcpy(&network->stats, stats, sizeof(network->stats));
2289 static inline int is_same_network(struct ieee80211_network *src,
2290 struct ieee80211_network *dst, struct ieee80211_device* ieee)
2292 /* A network is only a duplicate if the channel, BSSID, ESSID
2293 * and the capability field (in particular IBSS and BSS) all match.
2294 * We treat all <hidden> with the same BSSID and channel
2296 return //((src->ssid_len == dst->ssid_len) &&
2297 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2298 (src->channel == dst->channel) &&
2299 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2300 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2301 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2302 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2303 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2304 ((src->capability & WLAN_CAPABILITY_BSS) ==
2305 (dst->capability & WLAN_CAPABILITY_BSS)));
2308 static inline void update_network(struct ieee80211_network *dst,
2309 struct ieee80211_network *src)
2314 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2315 dst->capability = src->capability;
2316 memcpy(dst->rates, src->rates, src->rates_len);
2317 dst->rates_len = src->rates_len;
2318 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2319 dst->rates_ex_len = src->rates_ex_len;
2320 if(src->ssid_len > 0)
2322 memset(dst->ssid, 0, dst->ssid_len);
2323 dst->ssid_len = src->ssid_len;
2324 memcpy(dst->ssid, src->ssid, src->ssid_len);
2326 dst->mode = src->mode;
2327 dst->flags = src->flags;
2328 dst->time_stamp[0] = src->time_stamp[0];
2329 dst->time_stamp[1] = src->time_stamp[1];
2330 if (src->flags & NETWORK_HAS_ERP_VALUE)
2332 dst->erp_value = src->erp_value;
2333 dst->berp_info_valid = src->berp_info_valid = true;
2335 dst->beacon_interval = src->beacon_interval;
2336 dst->listen_interval = src->listen_interval;
2337 dst->atim_window = src->atim_window;
2338 dst->dtim_period = src->dtim_period;
2339 dst->dtim_data = src->dtim_data;
2340 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2341 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2342 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2344 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2345 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2346 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2347 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2348 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2349 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2350 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2351 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2352 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2353 dst->ralink_cap_exist = src->ralink_cap_exist;
2354 dst->atheros_cap_exist = src->atheros_cap_exist;
2355 dst->cisco_cap_exist = src->cisco_cap_exist;
2356 dst->unknown_cap_exist = src->unknown_cap_exist;
2357 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2358 dst->wpa_ie_len = src->wpa_ie_len;
2359 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2360 dst->rsn_ie_len = src->rsn_ie_len;
2362 dst->last_scanned = jiffies;
2363 /* qos related parameters */
2364 //qos_active = src->qos_data.active;
2365 qos_active = dst->qos_data.active;
2366 //old_param = dst->qos_data.old_param_count;
2367 old_param = dst->qos_data.param_count;
2368 if(dst->flags & NETWORK_HAS_QOS_MASK)
2369 memcpy(&dst->qos_data, &src->qos_data,
2370 sizeof(struct ieee80211_qos_data));
2372 dst->qos_data.supported = src->qos_data.supported;
2373 dst->qos_data.param_count = src->qos_data.param_count;
2376 if(dst->qos_data.supported == 1) {
2377 dst->QoS_Enable = 1;
2380 ("QoS the network %s is QoS supported\n",
2384 ("QoS the network is QoS supported\n");
2386 dst->qos_data.active = qos_active;
2387 dst->qos_data.old_param_count = old_param;
2389 /* dst->last_associate is not overwritten */
2390 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2391 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2392 src->wmm_param[1].ac_aci_acm_aifsn|| \
2393 src->wmm_param[2].ac_aci_acm_aifsn|| \
2394 src->wmm_param[1].ac_aci_acm_aifsn) {
2395 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2397 //dst->QoS_Enable = src->QoS_Enable;
2399 dst->Turbo_Enable = src->Turbo_Enable;
2402 #ifdef ENABLE_DOT11D
2403 dst->CountryIeLen = src->CountryIeLen;
2404 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2407 //added by amy for LEAP
2408 dst->bWithAironetIE = src->bWithAironetIE;
2409 dst->bCkipSupported = src->bCkipSupported;
2410 memcpy(dst->CcxRmState,src->CcxRmState,2);
2411 dst->bCcxRmEnable = src->bCcxRmEnable;
2412 dst->MBssidMask = src->MBssidMask;
2413 dst->bMBssidValid = src->bMBssidValid;
2414 memcpy(dst->MBssid,src->MBssid,6);
2415 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2416 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2420 static inline int is_beacon(__le16 fc)
2422 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2425 static inline void ieee80211_process_probe_response(
2426 struct ieee80211_device *ieee,
2427 struct ieee80211_probe_response *beacon,
2428 struct ieee80211_rx_stats *stats)
2430 struct ieee80211_network network;
2431 struct ieee80211_network *target;
2432 struct ieee80211_network *oldest = NULL;
2433 #ifdef CONFIG_IEEE80211_DEBUG
2434 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2436 unsigned long flags;
2440 memset(&network, 0, sizeof(struct ieee80211_network));
2441 IEEE80211_DEBUG_SCAN(
2442 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2443 escape_essid(info_element->data, info_element->len),
2444 beacon->header.addr3,
2445 (beacon->capability & (1<<0xf)) ? '1' : '0',
2446 (beacon->capability & (1<<0xe)) ? '1' : '0',
2447 (beacon->capability & (1<<0xd)) ? '1' : '0',
2448 (beacon->capability & (1<<0xc)) ? '1' : '0',
2449 (beacon->capability & (1<<0xb)) ? '1' : '0',
2450 (beacon->capability & (1<<0xa)) ? '1' : '0',
2451 (beacon->capability & (1<<0x9)) ? '1' : '0',
2452 (beacon->capability & (1<<0x8)) ? '1' : '0',
2453 (beacon->capability & (1<<0x7)) ? '1' : '0',
2454 (beacon->capability & (1<<0x6)) ? '1' : '0',
2455 (beacon->capability & (1<<0x5)) ? '1' : '0',
2456 (beacon->capability & (1<<0x4)) ? '1' : '0',
2457 (beacon->capability & (1<<0x3)) ? '1' : '0',
2458 (beacon->capability & (1<<0x2)) ? '1' : '0',
2459 (beacon->capability & (1<<0x1)) ? '1' : '0',
2460 (beacon->capability & (1<<0x0)) ? '1' : '0');
2462 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2463 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2464 escape_essid(info_element->data,
2466 beacon->header.addr3,
2467 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2468 IEEE80211_STYPE_PROBE_RESP ?
2469 "PROBE RESPONSE" : "BEACON");
2473 #ifdef ENABLE_DOT11D
2474 // For Asus EeePc request,
2475 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2476 // wireless adapter should follow the country code.
2477 // (2) If there is no any country code in beacon,
2478 // then wireless adapter should do active scan from ch1~11 and
2479 // passive scan from ch12~14
2481 if( !IsLegalChannel(ieee, network.channel) )
2483 if(ieee->bGlobalDomain)
2485 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2487 // Case 1: Country code
2488 if(IS_COUNTRY_IE_VALID(ieee) )
2490 if( !IsLegalChannel(ieee, network.channel) )
2492 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2496 // Case 2: No any country code.
2499 // Filter over channel ch12~14
2500 if(network.channel > 11)
2502 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2509 // Case 1: Country code
2510 if(IS_COUNTRY_IE_VALID(ieee) )
2512 if( !IsLegalChannel(ieee, network.channel) )
2514 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2518 // Case 2: No any country code.
2521 // Filter over channel ch12~14
2522 if(network.channel > 14)
2524 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2532 /* The network parsed correctly -- so now we scan our known networks
2533 * to see if we can find it in our list.
2535 * NOTE: This search is definitely not optimized. Once its doing
2536 * the "right thing" we'll optimize it for efficiency if
2539 /* Search for this entry in the list and update it if it is
2542 spin_lock_irqsave(&ieee->lock, flags);
2544 if(is_same_network(&ieee->current_network, &network, ieee)) {
2545 update_network(&ieee->current_network, &network);
2546 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2547 && ieee->current_network.berp_info_valid){
2548 if(ieee->current_network.erp_value& ERP_UseProtection)
2549 ieee->current_network.buseprotection = true;
2551 ieee->current_network.buseprotection = false;
2553 if(is_beacon(beacon->header.frame_ctl))
2555 if(ieee->state == IEEE80211_LINKED)
2556 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2559 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2562 list_for_each_entry(target, &ieee->network_list, list) {
2563 if (is_same_network(target, &network, ieee))
2565 if ((oldest == NULL) ||
2566 (target->last_scanned < oldest->last_scanned))
2570 /* If we didn't find a match, then get a new network slot to initialize
2571 * with this beacon's information */
2572 if (&target->list == &ieee->network_list) {
2573 if (list_empty(&ieee->network_free_list)) {
2574 /* If there are no more slots, expire the oldest */
2575 list_del(&oldest->list);
2577 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2579 escape_essid(target->ssid,
2583 /* Otherwise just pull from the free list */
2584 target = list_entry(ieee->network_free_list.next,
2585 struct ieee80211_network, list);
2586 list_del(ieee->network_free_list.next);
2590 #ifdef CONFIG_IEEE80211_DEBUG
2591 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2592 escape_essid(network.ssid,
2595 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2596 IEEE80211_STYPE_PROBE_RESP ?
2597 "PROBE RESPONSE" : "BEACON");
2599 memcpy(target, &network, sizeof(*target));
2600 list_add_tail(&target->list, &ieee->network_list);
2601 if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2602 ieee80211_softmac_new_net(ieee,&network);
2604 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2605 escape_essid(target->ssid,
2608 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2609 IEEE80211_STYPE_PROBE_RESP ?
2610 "PROBE RESPONSE" : "BEACON");
2612 /* we have an entry and we are going to update it. But this entry may
2613 * be already expired. In this case we do the same as we found a new
2614 * net and call the new_net handler
2616 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2617 //YJ,add,080819,for hidden ap
2618 if(is_beacon(beacon->header.frame_ctl) == 0)
2619 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2620 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2621 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2622 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2623 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2624 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2626 //YJ,add,080819,for hidden ap,end
2628 update_network(target, &network);
2629 if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2630 ieee80211_softmac_new_net(ieee,&network);
2633 spin_unlock_irqrestore(&ieee->lock, flags);
2634 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2635 (ieee->state == IEEE80211_LINKED)) {
2636 if(ieee->handle_beacon != NULL) {
2637 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2642 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2643 struct ieee80211_hdr_4addr *header,
2644 struct ieee80211_rx_stats *stats)
2646 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2648 case IEEE80211_STYPE_BEACON:
2649 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2650 WLAN_FC_GET_STYPE(header->frame_ctl));
2651 IEEE80211_DEBUG_SCAN("Beacon\n");
2652 ieee80211_process_probe_response(
2653 ieee, (struct ieee80211_probe_response *)header, stats);
2656 case IEEE80211_STYPE_PROBE_RESP:
2657 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2658 WLAN_FC_GET_STYPE(header->frame_ctl));
2659 IEEE80211_DEBUG_SCAN("Probe response\n");
2660 ieee80211_process_probe_response(
2661 ieee, (struct ieee80211_probe_response *)header, stats);
2667 EXPORT_SYMBOL(ieee80211_rx_mgt);
2668 EXPORT_SYMBOL(ieee80211_rx);