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/wireless.h>
41 #include <linux/etherdevice.h>
42 #include <asm/uaccess.h>
43 #include <linux/ctype.h>
45 #include "ieee80211.h"
47 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
49 struct ieee80211_rx_stats *rx_stats)
51 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *)skb->data;
52 u16 fc = le16_to_cpu(hdr->frame_ctl);
55 skb_reset_mac_header(skb);
57 skb_pull(skb, ieee80211_get_hdrlen(fc));
58 skb->pkt_type = PACKET_OTHERHOST;
59 skb->protocol = __constant_htons(ETH_P_80211_RAW);
60 memset(skb->cb, 0, sizeof(skb->cb));
65 /* Called only as a tasklet (software IRQ) */
66 static struct ieee80211_frag_entry *
67 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
68 unsigned int frag, u8 tid,u8 *src, u8 *dst)
70 struct ieee80211_frag_entry *entry;
73 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
74 entry = &ieee->frag_cache[tid][i];
75 if (entry->skb != NULL &&
76 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
78 "expiring fragment cache entry "
79 "seq=%u last_frag=%u\n",
80 entry->seq, entry->last_frag);
81 dev_kfree_skb_any(entry->skb);
85 if (entry->skb != NULL && entry->seq == seq &&
86 (entry->last_frag + 1 == frag || frag == -1) &&
87 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
88 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
95 /* Called only as a tasklet (software IRQ) */
96 static struct sk_buff *
97 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
98 struct ieee80211_hdr_4addr *hdr)
100 struct sk_buff *skb = NULL;
101 u16 fc = le16_to_cpu(hdr->frame_ctl);
102 u16 sc = le16_to_cpu(hdr->seq_ctl);
103 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
104 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
105 struct ieee80211_frag_entry *entry;
106 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
107 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
110 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
111 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
112 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
115 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
116 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
117 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
125 /* Reserve enough space to fit maximum frame length */
126 skb = dev_alloc_skb(ieee->dev->mtu +
127 sizeof(struct ieee80211_hdr_4addr) +
132 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
136 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
137 ieee->frag_next_idx[tid]++;
138 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
139 ieee->frag_next_idx[tid] = 0;
141 if (entry->skb != NULL)
142 dev_kfree_skb_any(entry->skb);
144 entry->first_frag_time = jiffies;
146 entry->last_frag = frag;
148 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
149 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
151 /* received a fragment of a frame for which the head fragment
152 * should have already been received */
153 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
156 entry->last_frag = frag;
165 /* Called only as a tasklet (software IRQ) */
166 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
167 struct ieee80211_hdr_4addr *hdr)
169 u16 fc = le16_to_cpu(hdr->frame_ctl);
170 u16 sc = le16_to_cpu(hdr->seq_ctl);
171 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
172 struct ieee80211_frag_entry *entry;
173 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
174 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
177 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
178 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
179 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
182 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
183 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
184 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
191 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
195 IEEE80211_DEBUG_FRAG(
196 "could not invalidate fragment cache "
197 "entry (seq=%u)\n", seq);
207 /* ieee80211_rx_frame_mgtmt
209 * Responsible for handling management control frames
211 * Called by ieee80211_rx */
213 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
214 struct ieee80211_rx_stats *rx_stats, u16 type,
217 /* On the struct stats definition there is written that
218 * this is not mandatory.... but seems that the probe
219 * response parser uses it
221 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)skb->data;
223 rx_stats->len = skb->len;
224 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
225 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
226 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames
228 dev_kfree_skb_any(skb);
232 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
234 dev_kfree_skb_any(skb);
239 if (ieee->iw_mode == IW_MODE_MASTER) {
240 printk(KERN_DEBUG "%s: Master mode not yet supported.\n",
244 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
248 if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) {
249 if (stype == WLAN_FC_STYPE_BEACON &&
250 ieee->iw_mode == IW_MODE_MASTER) {
251 struct sk_buff *skb2;
252 /* Process beacon frames also in kernel driver to
253 * update STA(AP) table statistics */
254 skb2 = skb_clone(skb, GFP_ATOMIC);
256 hostap_rx(skb2->dev, skb2, rx_stats);
259 /* send management frames to the user space daemon for
261 ieee->apdevstats.rx_packets++;
262 ieee->apdevstats.rx_bytes += skb->len;
263 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
267 if (ieee->iw_mode == IW_MODE_MASTER) {
268 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
269 printk(KERN_DEBUG "%s: unknown management frame "
270 "(type=0x%02x, stype=0x%02x) dropped\n",
271 skb->dev->name, type, stype);
275 hostap_rx(skb->dev, skb, rx_stats);
279 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
280 "received in non-Host AP mode\n", skb->dev->name);
287 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
288 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
289 static unsigned char rfc1042_header[] =
290 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
291 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
292 static unsigned char bridge_tunnel_header[] =
293 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
294 /* No encapsulation header if EtherType < 0x600 (=length) */
296 /* Called by ieee80211_rx_frame_decrypt */
297 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
298 struct sk_buff *skb, size_t hdrlen)
300 struct net_device *dev = ieee->dev;
302 struct ieee80211_hdr_4addr *hdr;
308 hdr = (struct ieee80211_hdr_4addr *) skb->data;
309 fc = le16_to_cpu(hdr->frame_ctl);
311 /* check that the frame is unicast frame to us */
312 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
313 IEEE80211_FCTL_TODS &&
314 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
315 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
316 /* ToDS frame with own addr BSSID and DA */
317 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
318 IEEE80211_FCTL_FROMDS &&
319 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
320 /* FromDS frame with own addr as DA */
324 if (skb->len < 24 + 8)
327 /* check for port access entity Ethernet type */
328 // pos = skb->data + 24;
329 pos = skb->data + hdrlen;
330 ethertype = (pos[6] << 8) | pos[7];
331 if (ethertype == ETH_P_PAE)
337 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
339 ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
340 struct ieee80211_crypt_data *crypt)
342 struct ieee80211_hdr_4addr *hdr;
345 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
347 if (ieee->hwsec_active)
349 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
350 tcb_desc->bHwSec = 1;
352 hdr = (struct ieee80211_hdr_4addr *) skb->data;
353 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
355 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
356 if (ieee->tkip_countermeasures &&
357 strcmp(crypt->ops->name, "TKIP") == 0) {
358 if (net_ratelimit()) {
359 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
360 "received packet from %pM\n",
361 ieee->dev->name, hdr->addr2);
367 atomic_inc(&crypt->refcnt);
368 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
369 atomic_dec(&crypt->refcnt);
371 IEEE80211_DEBUG_DROP(
372 "decryption failed (SA=%pM"
373 ") res=%d\n", hdr->addr2, res);
375 IEEE80211_DEBUG_DROP("Decryption failed ICV "
376 "mismatch (key %d)\n",
377 skb->data[hdrlen + 3] >> 6);
378 ieee->ieee_stats.rx_discards_undecryptable++;
386 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
388 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, struct sk_buff *skb,
389 int keyidx, struct ieee80211_crypt_data *crypt)
391 struct ieee80211_hdr_4addr *hdr;
394 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
396 if (ieee->hwsec_active)
398 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
399 tcb_desc->bHwSec = 1;
402 hdr = (struct ieee80211_hdr_4addr *) skb->data;
403 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
405 atomic_inc(&crypt->refcnt);
406 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
407 atomic_dec(&crypt->refcnt);
409 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
410 " (SA=%pM keyidx=%d)\n",
411 ieee->dev->name, hdr->addr2, keyidx);
419 /* this function is stolen from ipw2200 driver*/
420 #define IEEE_PACKET_RETRY_TIME (5*HZ)
421 static int is_duplicate_packet(struct ieee80211_device *ieee,
422 struct ieee80211_hdr_4addr *header)
424 u16 fc = le16_to_cpu(header->frame_ctl);
425 u16 sc = le16_to_cpu(header->seq_ctl);
426 u16 seq = WLAN_GET_SEQ_SEQ(sc);
427 u16 frag = WLAN_GET_SEQ_FRAG(sc);
428 u16 *last_seq, *last_frag;
429 unsigned long *last_time;
430 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
431 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
436 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
437 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
438 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
441 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
442 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)header;
443 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
450 switch (ieee->iw_mode) {
454 struct ieee_ibss_seq *entry = NULL;
455 u8 *mac = header->addr2;
456 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
458 list_for_each(p, &ieee->ibss_mac_hash[index]) {
459 entry = list_entry(p, struct ieee_ibss_seq, list);
460 if (!memcmp(entry->mac, mac, ETH_ALEN))
463 // if (memcmp(entry->mac, mac, ETH_ALEN)){
464 if (p == &ieee->ibss_mac_hash[index]) {
465 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
467 printk(KERN_WARNING "Cannot malloc new mac entry\n");
470 memcpy(entry->mac, mac, ETH_ALEN);
471 entry->seq_num[tid] = seq;
472 entry->frag_num[tid] = frag;
473 entry->packet_time[tid] = jiffies;
474 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
477 last_seq = &entry->seq_num[tid];
478 last_frag = &entry->frag_num[tid];
479 last_time = &entry->packet_time[tid];
484 last_seq = &ieee->last_rxseq_num[tid];
485 last_frag = &ieee->last_rxfrag_num[tid];
486 last_time = &ieee->last_packet_time[tid];
494 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
496 if ((*last_seq == seq) &&
497 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
498 if (*last_frag == frag){
499 //printk(KERN_WARNING "[1] go drop!\n");
503 if (*last_frag + 1 != frag)
504 /* out-of-order fragment */
505 //printk(KERN_WARNING "[2] go drop!\n");
511 *last_time = jiffies;
515 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
523 PRX_REORDER_ENTRY pReorderEntry
526 struct list_head *pList = &pTS->RxPendingPktList;
527 while(pList->next != &pTS->RxPendingPktList)
529 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
533 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
542 pReorderEntry->List.next = pList->next;
543 pReorderEntry->List.next->prev = &pReorderEntry->List;
544 pReorderEntry->List.prev = pList;
545 pList->next = &pReorderEntry->List;
550 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb **prxbIndicateArray,u8 index)
555 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
556 for(j = 0; j<index; j++)
558 //added by amy for reorder
559 struct ieee80211_rxb *prxb = prxbIndicateArray[j];
560 for(i = 0; i<prxb->nr_subframes; i++) {
561 struct sk_buff *sub_skb = prxb->subframes[i];
563 /* convert hdr + possible LLC headers into Ethernet header */
564 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
565 if (sub_skb->len >= 8 &&
566 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
567 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
568 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
569 /* remove RFC1042 or Bridge-Tunnel encapsulation and
570 * replace EtherType */
571 skb_pull(sub_skb, SNAP_SIZE);
572 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
573 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
576 /* Leave Ethernet header part of hdr and full payload */
577 len = htons(sub_skb->len);
578 memcpy(skb_push(sub_skb, 2), &len, 2);
579 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
580 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
582 //stats->rx_packets++;
583 //stats->rx_bytes += sub_skb->len;
585 /* Indicat the packets to upper layer */
587 //printk("0skb_len(%d)\n", skb->len);
588 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
589 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
590 sub_skb->dev = ieee->dev;
591 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
592 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
593 ieee->last_rx_ps_time = jiffies;
594 //printk("1skb_len(%d)\n", skb->len);
604 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
605 struct ieee80211_rxb *prxb,
609 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
610 PRX_REORDER_ENTRY pReorderEntry = NULL;
611 struct ieee80211_rxb *prxbIndicateArray[REORDER_WIN_SIZE];
612 u8 WinSize = pHTInfo->RxReorderWinSize;
613 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
615 bool bMatchWinStart = false, bPktInBuf = false;
616 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
617 /* Rx Reorder initialize condition.*/
618 if(pTS->RxIndicateSeq == 0xffff) {
619 pTS->RxIndicateSeq = SeqNum;
622 /* Drop out the packet which SeqNum is smaller than WinStart */
623 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
624 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
625 pTS->RxIndicateSeq, SeqNum);
626 pHTInfo->RxReorderDropCounter++;
629 for(i =0; i < prxb->nr_subframes; i++) {
630 dev_kfree_skb(prxb->subframes[i]);
639 * Sliding window manipulation. Conditions includes:
640 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
641 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
643 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
644 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
645 bMatchWinStart = true;
646 } else if(SN_LESS(WinEnd, SeqNum)) {
647 if(SeqNum >= (WinSize - 1)) {
648 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
650 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
652 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
656 * Indication process.
657 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
658 * with the SeqNum smaller than latest WinStart and buffer other packets.
660 /* For Rx Reorder condition:
661 * 1. All packets with SeqNum smaller than WinStart => Indicate
662 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
665 /* Current packet is going to be indicated.*/
666 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
667 pTS->RxIndicateSeq, SeqNum);
668 prxbIndicateArray[0] = prxb;
669 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
672 /* Current packet is going to be inserted into pending list.*/
673 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to ordered list\n",__FUNCTION__);
674 if(!list_empty(&ieee->RxReorder_Unused_List)) {
675 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
676 list_del_init(&pReorderEntry->List);
678 /* Make a reorder entry and insert into a the packet list.*/
679 pReorderEntry->SeqNum = SeqNum;
680 pReorderEntry->prxb = prxb;
681 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
683 if(!AddReorderEntry(pTS, pReorderEntry)) {
684 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
685 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
686 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
689 for(i =0; i < prxb->nr_subframes; i++) {
690 dev_kfree_skb(prxb->subframes[i]);
696 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
697 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
702 * Packets are dropped if there is not enough reorder entries.
703 * This part shall be modified!! We can just indicate all the
704 * packets in buffer and get reorder entries.
706 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
709 for(i =0; i < prxb->nr_subframes; i++) {
710 dev_kfree_skb(prxb->subframes[i]);
718 /* Check if there is any packet need indicate.*/
719 while(!list_empty(&pTS->RxPendingPktList)) {
720 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
721 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
722 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
723 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
725 /* This protect buffer from overflow. */
726 if(index >= REORDER_WIN_SIZE) {
727 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
732 list_del_init(&pReorderEntry->List);
734 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
735 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
737 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
738 prxbIndicateArray[index] = pReorderEntry->prxb;
739 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
742 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
749 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
751 // Cancel previous pending timer.
752 // del_timer_sync(&pTS->RxPktPendingTimer);
753 pTS->RxTimeoutIndicateSeq = 0xffff;
756 if(index>REORDER_WIN_SIZE){
757 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
760 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
763 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
764 // Set new pending timer.
765 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
766 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
767 if(timer_pending(&pTS->RxPktPendingTimer))
768 del_timer_sync(&pTS->RxPktPendingTimer);
769 pTS->RxPktPendingTimer.expires = jiffies + MSECS(pHTInfo->RxReorderPendingTime);
770 add_timer(&pTS->RxPktPendingTimer);
774 u8 parse_subframe(struct sk_buff *skb,
775 struct ieee80211_rx_stats *rx_stats,
776 struct ieee80211_rxb *rxb,u8 *src,u8 *dst)
778 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)skb->data;
779 u16 fc = le16_to_cpu(hdr->frame_ctl);
781 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
783 bool bIsAggregateFrame = false;
784 u16 nSubframe_Length;
785 u8 nPadding_Length = 0;
788 struct sk_buff *sub_skb;
790 /* just for debug purpose */
791 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
793 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
794 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
795 bIsAggregateFrame = true;
798 if(IEEE80211_QOS_HAS_SEQ(fc)) {
802 if(rx_stats->bContainHTC) {
803 LLCOffset += sHTCLng;
805 //printk("ChkLength = %d\n", LLCOffset);
806 // Null packet, don't indicate it to upper layer
807 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
809 if( skb->len <= ChkLength ) {
813 skb_pull(skb, LLCOffset);
815 if(!bIsAggregateFrame) {
816 rxb->nr_subframes = 1;
818 rxb->subframes[0] = skb;
820 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
823 memcpy(rxb->src,src,ETH_ALEN);
824 memcpy(rxb->dst,dst,ETH_ALEN);
825 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
828 rxb->nr_subframes = 0;
829 memcpy(rxb->src,src,ETH_ALEN);
830 memcpy(rxb->dst,dst,ETH_ALEN);
831 while(skb->len > ETHERNET_HEADER_SIZE) {
832 /* Offset 12 denote 2 mac address */
833 nSubframe_Length = *((u16 *)(skb->data + 12));
834 //==m==>change the length order
835 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
837 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
838 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
839 __FUNCTION__,rxb->nr_subframes);
840 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
841 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
842 printk("The Packet SeqNum is %d\n",SeqNum);
846 /* move the data point to data content */
847 skb_pull(skb, ETHERNET_HEADER_SIZE);
850 sub_skb = skb_clone(skb, GFP_ATOMIC);
851 sub_skb->len = nSubframe_Length;
852 sub_skb->tail = sub_skb->data + nSubframe_Length;
854 /* Allocate new skb for releasing to upper layer */
855 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
856 skb_reserve(sub_skb, 12);
857 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
858 memcpy(data_ptr,skb->data,nSubframe_Length);
860 rxb->subframes[rxb->nr_subframes++] = sub_skb;
861 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
862 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
865 skb_pull(skb,nSubframe_Length);
868 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
869 if(nPadding_Length == 4) {
873 if(skb->len < nPadding_Length) {
877 skb_pull(skb,nPadding_Length);
883 //{just for debug added by david
884 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
886 return rxb->nr_subframes;
890 /* All received frames are sent to this function. @skb contains the frame in
891 * IEEE 802.11 format, i.e., in the format it was sent over air.
892 * This function is called only as a tasklet (software IRQ). */
893 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
894 struct ieee80211_rx_stats *rx_stats)
896 struct net_device *dev = ieee->dev;
897 struct ieee80211_hdr_4addr *hdr;
898 //struct ieee80211_hdr_3addrqos *hdr;
901 u16 fc, type, stype, sc;
902 struct net_device_stats *stats;
906 //added by amy for reorder
909 PRX_TS_RECORD pTS = NULL;
910 //bool bIsAggregateFrame = false;
911 //added by amy for reorder
913 struct net_device *wds = NULL;
914 struct sk_buff *skb2 = NULL;
915 struct net_device *wds = NULL;
916 int frame_authorized = 0;
917 int from_assoc_ap = 0;
924 struct ieee80211_crypt_data *crypt = NULL;
928 struct ieee80211_rxb *rxb = NULL;
929 // cheat the the hdr type
930 hdr = (struct ieee80211_hdr_4addr *)skb->data;
931 stats = &ieee->stats;
934 printk(KERN_INFO "%s: SKB length < 10\n",
939 fc = le16_to_cpu(hdr->frame_ctl);
940 type = WLAN_FC_GET_TYPE(fc);
941 stype = WLAN_FC_GET_STYPE(fc);
942 sc = le16_to_cpu(hdr->seq_ctl);
944 frag = WLAN_GET_SEQ_FRAG(sc);
945 hdrlen = ieee80211_get_hdrlen(fc);
947 if(HTCCheck(ieee, skb->data))
950 printk("find HTCControl\n");
952 rx_stats->bContainHTC = 1;
955 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
957 #if WIRELESS_EXT > 15
958 /* Put this code here so that we avoid duplicating it in all
959 * Rx paths. - Jean II */
960 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
961 /* If spy monitoring on */
962 if (iface->spy_data.spy_number > 0) {
963 struct iw_quality wstats;
964 wstats.level = rx_stats->rssi;
965 wstats.noise = rx_stats->noise;
966 wstats.updated = 6; /* No qual value */
967 /* Update spy records */
968 wireless_spy_update(dev, hdr->addr2, &wstats);
970 #endif /* IW_WIRELESS_SPY */
971 #endif /* WIRELESS_EXT > 15 */
972 hostap_update_rx_stats(local->ap, hdr, rx_stats);
975 #if WIRELESS_EXT > 15
976 if (ieee->iw_mode == IW_MODE_MONITOR) {
977 ieee80211_monitor_rx(ieee, skb, rx_stats);
979 stats->rx_bytes += skb->len;
983 if (ieee->host_decrypt) {
985 if (skb->len >= hdrlen + 3)
986 idx = skb->data[hdrlen + 3] >> 6;
987 crypt = ieee->crypt[idx];
991 /* Use station specific key to override default keys if the
992 * receiver address is a unicast address ("individual RA"). If
993 * bcrx_sta_key parameter is set, station specific key is used
994 * even with broad/multicast targets (this is against IEEE
995 * 802.11, but makes it easier to use different keys with
996 * stations that do not support WEP key mapping). */
998 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
999 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1003 /* allow NULL decrypt to indicate an station specific override
1004 * for default encryption */
1005 if (crypt && (crypt->ops == NULL ||
1006 crypt->ops->decrypt_mpdu == NULL))
1009 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
1010 /* This seems to be triggered by some (multicast?)
1011 * frames from other than current BSS, so just drop the
1012 * frames silently instead of filling system log with
1014 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1017 ieee->ieee_stats.rx_discards_undecryptable++;
1022 if (skb->len < IEEE80211_DATA_HDR3_LEN)
1025 // if QoS enabled, should check the sequence for each of the AC
1026 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
1027 if (is_duplicate_packet(ieee, hdr))
1033 PRX_TS_RECORD pRxTS = NULL;
1034 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1037 (PTS_COMMON_INFO *) &pRxTS,
1039 (u8)Frame_QoSTID((u8 *)(skb->data)),
1044 // 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));
1045 if( (fc & (1<<11)) &&
1046 (frag == pRxTS->RxLastFragNum) &&
1047 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
1053 pRxTS->RxLastFragNum = frag;
1054 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1059 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
1063 if (type == IEEE80211_FTYPE_MGMT) {
1066 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1067 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1073 /* Data frame - extract src/dst addresses */
1074 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1075 case IEEE80211_FCTL_FROMDS:
1076 memcpy(dst, hdr->addr1, ETH_ALEN);
1077 memcpy(src, hdr->addr3, ETH_ALEN);
1078 memcpy(bssid, hdr->addr2, ETH_ALEN);
1080 case IEEE80211_FCTL_TODS:
1081 memcpy(dst, hdr->addr3, ETH_ALEN);
1082 memcpy(src, hdr->addr2, ETH_ALEN);
1083 memcpy(bssid, hdr->addr1, ETH_ALEN);
1085 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1086 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1088 memcpy(dst, hdr->addr3, ETH_ALEN);
1089 memcpy(src, hdr->addr4, ETH_ALEN);
1090 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1093 memcpy(dst, hdr->addr1, ETH_ALEN);
1094 memcpy(src, hdr->addr2, ETH_ALEN);
1095 memcpy(bssid, hdr->addr3, ETH_ALEN);
1100 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1103 skb->dev = dev = wds;
1104 stats = hostap_get_stats(dev);
1107 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1108 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1110 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1111 /* Frame from BSSID of the AP for which we are a client */
1112 skb->dev = dev = ieee->stadev;
1113 stats = hostap_get_stats(dev);
1118 dev->last_rx = jiffies;
1121 if ((ieee->iw_mode == IW_MODE_MASTER ||
1122 ieee->iw_mode == IW_MODE_REPEAT) &&
1124 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1126 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1127 frame_authorized = 0;
1129 case AP_RX_CONTINUE:
1130 frame_authorized = 1;
1139 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1140 /* Nullfunc frames may have PS-bit set, so they must be passed to
1141 * hostap_handle_sta_rx() before being dropped here. */
1142 if (stype != IEEE80211_STYPE_DATA &&
1143 stype != IEEE80211_STYPE_DATA_CFACK &&
1144 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1145 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1146 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1148 if (stype != IEEE80211_STYPE_NULLFUNC)
1149 IEEE80211_DEBUG_DROP(
1150 "RX: dropped data frame "
1151 "with no data (type=0x%02x, "
1152 "subtype=0x%02x, len=%d)\n",
1153 type, stype, skb->len);
1156 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1159 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1161 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1162 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1164 printk("decrypt frame error\n");
1169 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1171 /* skb: hdr + (possibly fragmented) plaintext payload */
1172 // PR: FIXME: hostap has additional conditions in the "if" below:
1173 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1174 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1176 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1177 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1180 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1181 "Rx cannot get skb from fragment "
1182 "cache (morefrag=%d seq=%u frag=%u)\n",
1183 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1184 WLAN_GET_SEQ_SEQ(sc), frag);
1191 if (frag_skb->tail + flen > frag_skb->end) {
1192 printk(KERN_WARNING "%s: host decrypted and "
1193 "reassembled frame did not fit skb\n",
1195 ieee80211_frag_cache_invalidate(ieee, hdr);
1200 /* copy first fragment (including full headers) into
1201 * beginning of the fragment cache skb */
1202 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1204 /* append frame payload to the end of the fragment
1206 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1209 dev_kfree_skb_any(skb);
1212 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1213 /* more fragments expected - leave the skb in fragment
1214 * cache for now; it will be delivered to upper layers
1215 * after all fragments have been received */
1219 /* this was the last fragment and the frame will be
1220 * delivered, so remove skb from fragment cache */
1222 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1223 ieee80211_frag_cache_invalidate(ieee, hdr);
1226 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1227 * encrypted/authenticated */
1228 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1229 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1231 printk("==>decrypt msdu error\n");
1235 //added by amy for AP roaming
1236 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1237 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1239 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1240 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1241 if (/*ieee->ieee802_1x &&*/
1242 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1244 #ifdef CONFIG_IEEE80211_DEBUG
1245 /* pass unencrypted EAPOL frames even if encryption is
1247 struct eapol *eap = (struct eapol *)(skb->data +
1249 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1250 eap_get_type(eap->type));
1253 IEEE80211_DEBUG_DROP(
1254 "encryption configured, but RX "
1255 "frame not encrypted (SA=%pM)\n",
1261 #ifdef CONFIG_IEEE80211_DEBUG
1262 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1263 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1264 struct eapol *eap = (struct eapol *)(skb->data +
1266 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1267 eap_get_type(eap->type));
1271 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1272 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1273 IEEE80211_DEBUG_DROP(
1274 "dropped unencrypted RX data "
1276 " (drop_unencrypted=1)\n",
1281 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1282 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1285 //added by amy for reorder
1286 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1287 && !is_multicast_ether_addr(hdr->addr1))
1289 TID = Frame_QoSTID(skb->data);
1290 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1291 GetTs(ieee,(PTS_COMMON_INFO *) &pTS,hdr->addr2,TID,RX_DIR,true);
1292 if(TID !=0 && TID !=3)
1294 ieee->bis_any_nonbepkts = true;
1297 //added by amy for reorder
1298 /* skb: hdr + (possible reassembled) full plaintext payload */
1299 payload = skb->data + hdrlen;
1300 //ethertype = (payload[6] << 8) | payload[7];
1301 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1304 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1307 /* to parse amsdu packets */
1308 /* qos data packets & reserved bit is 1 */
1309 if(parse_subframe(skb,rx_stats,rxb,src,dst) == 0) {
1310 /* only to free rxb, and not submit the packets to upper layer */
1311 for(i =0; i < rxb->nr_subframes; i++) {
1312 dev_kfree_skb(rxb->subframes[i]);
1319 //added by amy for reorder
1320 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1321 //added by amy for reorder
1322 for(i = 0; i<rxb->nr_subframes; i++) {
1323 struct sk_buff *sub_skb = rxb->subframes[i];
1326 /* convert hdr + possible LLC headers into Ethernet header */
1327 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1328 if (sub_skb->len >= 8 &&
1329 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1330 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1331 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1332 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1333 * replace EtherType */
1334 skb_pull(sub_skb, SNAP_SIZE);
1335 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1336 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1339 /* Leave Ethernet header part of hdr and full payload */
1340 len = htons(sub_skb->len);
1341 memcpy(skb_push(sub_skb, 2), &len, 2);
1342 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1343 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1346 stats->rx_packets++;
1347 stats->rx_bytes += sub_skb->len;
1348 if(is_multicast_ether_addr(dst)) {
1352 /* Indicat the packets to upper layer */
1353 //printk("0skb_len(%d)\n", skb->len);
1354 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1355 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1357 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1358 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1359 ieee->last_rx_ps_time = jiffies;
1360 //printk("1skb_len(%d)\n", skb->len);
1370 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1371 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1380 hostap_handle_sta_release(sta);
1387 stats->rx_dropped++;
1389 /* Returning 0 indicates to caller that we have not handled the SKB--
1390 * so it is still allocated and can be used again by underlying
1391 * hardware as a DMA target */
1395 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1397 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1400 * Make the structure we read from the beacon packet to have
1403 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1404 *info_element, int sub_type)
1407 if (info_element->qui_subtype != sub_type)
1409 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1411 if (info_element->qui_type != QOS_OUI_TYPE)
1413 if (info_element->version != QOS_VERSION_1)
1421 * Parse a QoS parameter element
1423 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1424 *element_param, struct ieee80211_info_element
1428 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1430 if ((info_element == NULL) || (element_param == NULL))
1433 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1434 memcpy(element_param->info_element.qui, info_element->data,
1436 element_param->info_element.elementID = info_element->id;
1437 element_param->info_element.length = info_element->len;
1441 ret = ieee80211_verify_qos_info(&element_param->info_element,
1442 QOS_OUI_PARAM_SUB_TYPE);
1447 * Parse a QoS information element
1449 static int ieee80211_read_qos_info_element(struct
1450 ieee80211_qos_information_element
1451 *element_info, struct ieee80211_info_element
1455 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1457 if (element_info == NULL)
1459 if (info_element == NULL)
1462 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1463 memcpy(element_info->qui, info_element->data,
1465 element_info->elementID = info_element->id;
1466 element_info->length = info_element->len;
1471 ret = ieee80211_verify_qos_info(element_info,
1472 QOS_OUI_INFO_SUB_TYPE);
1478 * Write QoS parameters from the ac parameters.
1480 static int ieee80211_qos_convert_ac_to_parameters(struct
1481 ieee80211_qos_parameter_info
1483 ieee80211_qos_parameters
1488 struct ieee80211_qos_ac_parameter *ac_params;
1493 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1494 ac_params = &(param_elm->ac_params_record[i]);
1496 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1498 if(aci >= QOS_QUEUE_NUM)
1500 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1502 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1503 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1505 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1507 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1509 qos_param->flag[aci] =
1510 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1511 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1517 * we have a generic data element which it may contain QoS information or
1518 * parameters element. check the information element length to decide
1519 * which type to read
1521 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1523 struct ieee80211_network *network)
1526 struct ieee80211_qos_parameters *qos_param = NULL;
1527 struct ieee80211_qos_information_element qos_info_element;
1529 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1532 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1533 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1535 struct ieee80211_qos_parameter_info param_element;
1537 rc = ieee80211_read_qos_param_element(¶m_element,
1540 qos_param = &(network->qos_data.parameters);
1541 ieee80211_qos_convert_ac_to_parameters(¶m_element,
1543 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1544 network->qos_data.param_count =
1545 param_element.info_element.ac_info & 0x0F;
1550 IEEE80211_DEBUG_QOS("QoS is supported\n");
1551 network->qos_data.supported = 1;
1556 #ifdef CONFIG_IEEE80211_DEBUG
1557 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1559 static const char *get_info_element_string(u16 id)
1564 MFIE_STRING(FH_SET);
1565 MFIE_STRING(DS_SET);
1566 MFIE_STRING(CF_SET);
1568 MFIE_STRING(IBSS_SET);
1569 MFIE_STRING(COUNTRY);
1570 MFIE_STRING(HOP_PARAMS);
1571 MFIE_STRING(HOP_TABLE);
1572 MFIE_STRING(REQUEST);
1573 MFIE_STRING(CHALLENGE);
1574 MFIE_STRING(POWER_CONSTRAINT);
1575 MFIE_STRING(POWER_CAPABILITY);
1576 MFIE_STRING(TPC_REQUEST);
1577 MFIE_STRING(TPC_REPORT);
1578 MFIE_STRING(SUPP_CHANNELS);
1580 MFIE_STRING(MEASURE_REQUEST);
1581 MFIE_STRING(MEASURE_REPORT);
1583 MFIE_STRING(IBSS_DFS);
1584 // MFIE_STRING(ERP_INFO);
1586 MFIE_STRING(RATES_EX);
1587 MFIE_STRING(GENERIC);
1588 MFIE_STRING(QOS_PARAMETER);
1595 static inline void ieee80211_extract_country_ie(
1596 struct ieee80211_device *ieee,
1597 struct ieee80211_info_element *info_element,
1598 struct ieee80211_network *network,
1602 if(IS_DOT11D_ENABLE(ieee))
1604 if(info_element->len!= 0)
1606 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1607 network->CountryIeLen = info_element->len;
1609 if(!IS_COUNTRY_IE_VALID(ieee))
1611 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1616 // 070305, rcnjko: I update country IE watch dog here because
1617 // some AP (e.g. Cisco 1242) don't include country IE in their
1618 // probe response frame.
1620 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1622 UPDATE_CIE_WATCHDOG(ieee);
1628 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1629 struct ieee80211_info_element *info_element,
1631 struct ieee80211_network *network,
1632 struct ieee80211_rx_stats *stats)
1636 u16 tmp_htcap_len=0;
1637 u16 tmp_htinfo_len=0;
1638 u16 ht_realtek_agg_len=0;
1639 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1640 // u16 broadcom_len = 0;
1641 #ifdef CONFIG_IEEE80211_DEBUG
1646 while (length >= sizeof(*info_element)) {
1647 if (sizeof(*info_element) + info_element->len > length) {
1648 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1649 "info_element->len + 2 > left : "
1650 "info_element->len+2=%zd left=%d, id=%d.\n",
1652 sizeof(*info_element),
1653 length, info_element->id);
1654 /* We stop processing but don't return an error here
1655 * because some misbehaviour APs break this rule. ie.
1656 * Orinoco AP1000. */
1660 switch (info_element->id) {
1661 case MFIE_TYPE_SSID:
1662 if (ieee80211_is_empty_essid(info_element->data,
1663 info_element->len)) {
1664 network->flags |= NETWORK_EMPTY_ESSID;
1668 network->ssid_len = min(info_element->len,
1669 (u8) IW_ESSID_MAX_SIZE);
1670 memcpy(network->ssid, info_element->data, network->ssid_len);
1671 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1672 memset(network->ssid + network->ssid_len, 0,
1673 IW_ESSID_MAX_SIZE - network->ssid_len);
1675 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1676 network->ssid, network->ssid_len);
1679 case MFIE_TYPE_RATES:
1680 #ifdef CONFIG_IEEE80211_DEBUG
1683 network->rates_len = min(info_element->len,
1685 for (i = 0; i < network->rates_len; i++) {
1686 network->rates[i] = info_element->data[i];
1687 #ifdef CONFIG_IEEE80211_DEBUG
1688 p += snprintf(p, sizeof(rates_str) -
1689 (p - rates_str), "%02X ",
1692 if (ieee80211_is_ofdm_rate
1693 (info_element->data[i])) {
1694 network->flags |= NETWORK_HAS_OFDM;
1695 if (info_element->data[i] &
1696 IEEE80211_BASIC_RATE_MASK)
1702 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1703 rates_str, network->rates_len);
1706 case MFIE_TYPE_RATES_EX:
1707 #ifdef CONFIG_IEEE80211_DEBUG
1710 network->rates_ex_len = min(info_element->len,
1711 MAX_RATES_EX_LENGTH);
1712 for (i = 0; i < network->rates_ex_len; i++) {
1713 network->rates_ex[i] = info_element->data[i];
1714 #ifdef CONFIG_IEEE80211_DEBUG
1715 p += snprintf(p, sizeof(rates_str) -
1716 (p - rates_str), "%02X ",
1719 if (ieee80211_is_ofdm_rate
1720 (info_element->data[i])) {
1721 network->flags |= NETWORK_HAS_OFDM;
1722 if (info_element->data[i] &
1723 IEEE80211_BASIC_RATE_MASK)
1729 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1730 rates_str, network->rates_ex_len);
1733 case MFIE_TYPE_DS_SET:
1734 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1735 info_element->data[0]);
1736 network->channel = info_element->data[0];
1739 case MFIE_TYPE_FH_SET:
1740 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1743 case MFIE_TYPE_CF_SET:
1744 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1748 if(info_element->len < 4)
1751 network->tim.tim_count = info_element->data[0];
1752 network->tim.tim_period = info_element->data[1];
1754 network->dtim_period = info_element->data[1];
1755 if(ieee->state != IEEE80211_LINKED)
1758 network->last_dtim_sta_time[0] = stats->mac_time[0];
1759 network->last_dtim_sta_time[1] = stats->mac_time[1];
1761 network->dtim_data = IEEE80211_DTIM_VALID;
1763 if(info_element->data[0] != 0)
1766 if(info_element->data[2] & 1)
1767 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1769 offset = (info_element->data[2] >> 1)*2;
1771 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1773 if(ieee->assoc_id < 8*offset ||
1774 ieee->assoc_id > 8*(offset + info_element->len -3))
1778 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1780 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1781 network->dtim_data |= IEEE80211_DTIM_UCAST;
1783 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1787 network->erp_value = info_element->data[0];
1788 network->flags |= NETWORK_HAS_ERP_VALUE;
1789 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1790 network->erp_value);
1792 case MFIE_TYPE_IBSS_SET:
1793 network->atim_window = info_element->data[0];
1794 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1795 network->atim_window);
1798 case MFIE_TYPE_CHALLENGE:
1799 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1802 case MFIE_TYPE_GENERIC:
1803 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1805 if (!ieee80211_parse_qos_info_param_IE(info_element,
1809 if (info_element->len >= 4 &&
1810 info_element->data[0] == 0x00 &&
1811 info_element->data[1] == 0x50 &&
1812 info_element->data[2] == 0xf2 &&
1813 info_element->data[3] == 0x01) {
1814 network->wpa_ie_len = min(info_element->len + 2,
1816 memcpy(network->wpa_ie, info_element,
1817 network->wpa_ie_len);
1822 if (info_element->len == 7 &&
1823 info_element->data[0] == 0x00 &&
1824 info_element->data[1] == 0xe0 &&
1825 info_element->data[2] == 0x4c &&
1826 info_element->data[3] == 0x01 &&
1827 info_element->data[4] == 0x02) {
1828 network->Turbo_Enable = 1;
1832 //for HTcap and HTinfo parameters
1833 if(tmp_htcap_len == 0){
1834 if(info_element->len >= 4 &&
1835 info_element->data[0] == 0x00 &&
1836 info_element->data[1] == 0x90 &&
1837 info_element->data[2] == 0x4c &&
1838 info_element->data[3] == 0x033){
1840 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1841 if(tmp_htcap_len != 0){
1842 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1843 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1844 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1845 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1848 if(tmp_htcap_len != 0)
1849 network->bssht.bdSupportHT = true;
1851 network->bssht.bdSupportHT = false;
1855 if(tmp_htinfo_len == 0){
1856 if(info_element->len >= 4 &&
1857 info_element->data[0] == 0x00 &&
1858 info_element->data[1] == 0x90 &&
1859 info_element->data[2] == 0x4c &&
1860 info_element->data[3] == 0x034){
1862 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1863 if(tmp_htinfo_len != 0){
1864 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1866 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1867 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1868 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1876 if(ieee->aggregation){
1877 if(network->bssht.bdSupportHT){
1878 if(info_element->len >= 4 &&
1879 info_element->data[0] == 0x00 &&
1880 info_element->data[1] == 0xe0 &&
1881 info_element->data[2] == 0x4c &&
1882 info_element->data[3] == 0x02){
1884 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
1885 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
1888 if(ht_realtek_agg_len >= 5){
1889 network->bssht.bdRT2RTAggregation = true;
1891 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1892 network->bssht.bdRT2RTLongSlotTime = true;
1898 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1900 if((info_element->len >= 3 &&
1901 info_element->data[0] == 0x00 &&
1902 info_element->data[1] == 0x05 &&
1903 info_element->data[2] == 0xb5) ||
1904 (info_element->len >= 3 &&
1905 info_element->data[0] == 0x00 &&
1906 info_element->data[1] == 0x0a &&
1907 info_element->data[2] == 0xf7) ||
1908 (info_element->len >= 3 &&
1909 info_element->data[0] == 0x00 &&
1910 info_element->data[1] == 0x10 &&
1911 info_element->data[2] == 0x18)){
1913 network->broadcom_cap_exist = true;
1917 if(info_element->len >= 3 &&
1918 info_element->data[0] == 0x00 &&
1919 info_element->data[1] == 0x0c &&
1920 info_element->data[2] == 0x43)
1922 network->ralink_cap_exist = true;
1925 network->ralink_cap_exist = false;
1926 //added by amy for atheros AP
1927 if((info_element->len >= 3 &&
1928 info_element->data[0] == 0x00 &&
1929 info_element->data[1] == 0x03 &&
1930 info_element->data[2] == 0x7f) ||
1931 (info_element->len >= 3 &&
1932 info_element->data[0] == 0x00 &&
1933 info_element->data[1] == 0x13 &&
1934 info_element->data[2] == 0x74))
1936 printk("========>%s(): athros AP is exist\n",__FUNCTION__);
1937 network->atheros_cap_exist = true;
1940 network->atheros_cap_exist = false;
1942 if(info_element->len >= 3 &&
1943 info_element->data[0] == 0x00 &&
1944 info_element->data[1] == 0x40 &&
1945 info_element->data[2] == 0x96)
1947 network->cisco_cap_exist = true;
1950 network->cisco_cap_exist = false;
1951 //added by amy for LEAP of cisco
1952 if(info_element->len > 4 &&
1953 info_element->data[0] == 0x00 &&
1954 info_element->data[1] == 0x40 &&
1955 info_element->data[2] == 0x96 &&
1956 info_element->data[3] == 0x01)
1958 if(info_element->len == 6)
1960 memcpy(network->CcxRmState, &info_element[4], 2);
1961 if(network->CcxRmState[0] != 0)
1963 network->bCcxRmEnable = true;
1966 network->bCcxRmEnable = false;
1968 // CCXv4 Table 59-1 MBSSID Masks.
1970 network->MBssidMask = network->CcxRmState[1] & 0x07;
1971 if(network->MBssidMask != 0)
1973 network->bMBssidValid = true;
1974 network->MBssidMask = 0xff << (network->MBssidMask);
1975 cpMacAddr(network->MBssid, network->bssid);
1976 network->MBssid[5] &= network->MBssidMask;
1980 network->bMBssidValid = false;
1985 network->bCcxRmEnable = false;
1988 if(info_element->len > 4 &&
1989 info_element->data[0] == 0x00 &&
1990 info_element->data[1] == 0x40 &&
1991 info_element->data[2] == 0x96 &&
1992 info_element->data[3] == 0x03)
1994 if(info_element->len == 5)
1996 network->bWithCcxVerNum = true;
1997 network->BssCcxVerNumber = info_element->data[4];
2001 network->bWithCcxVerNum = false;
2002 network->BssCcxVerNumber = 0;
2008 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2010 network->rsn_ie_len = min(info_element->len + 2,
2012 memcpy(network->rsn_ie, info_element,
2013 network->rsn_ie_len);
2016 //HT related element.
2017 case MFIE_TYPE_HT_CAP:
2018 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2020 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2021 if(tmp_htcap_len != 0){
2022 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2023 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2024 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2025 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2027 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2028 // windows driver will update WMM parameters each beacon received once connected
2029 // Linux driver is a bit different.
2030 network->bssht.bdSupportHT = true;
2033 network->bssht.bdSupportHT = false;
2037 case MFIE_TYPE_HT_INFO:
2038 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2040 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2042 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2043 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2044 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2045 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2049 case MFIE_TYPE_AIRONET:
2050 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2052 if(info_element->len >IE_CISCO_FLAG_POSITION)
2054 network->bWithAironetIE = true;
2056 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2057 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2058 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2059 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
2060 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
2062 network->bCkipSupported = true;
2066 network->bCkipSupported = false;
2071 network->bWithAironetIE = false;
2072 network->bCkipSupported = false;
2075 case MFIE_TYPE_QOS_PARAMETER:
2077 "QoS Error need to parse QOS_PARAMETER IE\n");
2080 case MFIE_TYPE_COUNTRY:
2081 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2083 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2084 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2088 IEEE80211_DEBUG_MGMT
2089 ("Unsupported info element: %s (%d)\n",
2090 get_info_element_string(info_element->id),
2095 length -= sizeof(*info_element) + info_element->len;
2097 (struct ieee80211_info_element *)&info_element->
2098 data[info_element->len];
2101 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2102 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation)
2104 network->unknown_cap_exist = true;
2108 network->unknown_cap_exist = false;
2113 static inline u8 ieee80211_SignalStrengthTranslate(
2119 // Step 1. Scale mapping.
2120 if(CurrSS >= 71 && CurrSS <= 100)
2122 RetSS = 90 + ((CurrSS - 70) / 3);
2124 else if(CurrSS >= 41 && CurrSS <= 70)
2126 RetSS = 78 + ((CurrSS - 40) / 3);
2128 else if(CurrSS >= 31 && CurrSS <= 40)
2130 RetSS = 66 + (CurrSS - 30);
2132 else if(CurrSS >= 21 && CurrSS <= 30)
2134 RetSS = 54 + (CurrSS - 20);
2136 else if(CurrSS >= 5 && CurrSS <= 20)
2138 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2140 else if(CurrSS == 4)
2144 else if(CurrSS == 3)
2148 else if(CurrSS == 2)
2152 else if(CurrSS == 1)
2160 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2162 // Step 2. Smoothing.
2164 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2169 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2171 long signal_power; // in dBm.
2173 // Translate to dBm (x=0.5y-95).
2174 signal_power = (long)((signal_strength_index + 1) >> 1);
2177 return signal_power;
2180 static inline int ieee80211_network_init(
2181 struct ieee80211_device *ieee,
2182 struct ieee80211_probe_response *beacon,
2183 struct ieee80211_network *network,
2184 struct ieee80211_rx_stats *stats)
2186 #ifdef CONFIG_IEEE80211_DEBUG
2187 //char rates_str[64];
2191 network->qos_data.active = 0;
2192 network->qos_data.supported = 0;
2193 network->qos_data.param_count = 0;
2194 network->qos_data.old_param_count = 0;
2196 /* Pull out fixed field data */
2197 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2198 network->capability = le16_to_cpu(beacon->capability);
2199 network->last_scanned = jiffies;
2200 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2201 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2202 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2203 /* Where to pull this? beacon->listen_interval;*/
2204 network->listen_interval = 0x0A;
2205 network->rates_len = network->rates_ex_len = 0;
2206 network->last_associate = 0;
2207 network->ssid_len = 0;
2209 network->atim_window = 0;
2210 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2212 network->berp_info_valid = false;
2213 network->broadcom_cap_exist = false;
2214 network->ralink_cap_exist = false;
2215 network->atheros_cap_exist = false;
2216 network->cisco_cap_exist = false;
2217 network->unknown_cap_exist = false;
2219 network->Turbo_Enable = 0;
2221 network->CountryIeLen = 0;
2222 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2223 //Initialize HT parameters
2224 //ieee80211_ht_initialize(&network->bssht);
2225 HTInitializeBssDesc(&network->bssht);
2226 if (stats->freq == IEEE80211_52GHZ_BAND) {
2227 /* for A band (No DS info) */
2228 network->channel = stats->received_channel;
2230 network->flags |= NETWORK_HAS_CCK;
2232 network->wpa_ie_len = 0;
2233 network->rsn_ie_len = 0;
2235 if (ieee80211_parse_info_param
2236 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2240 if (stats->freq == IEEE80211_52GHZ_BAND)
2241 network->mode = IEEE_A;
2243 if (network->flags & NETWORK_HAS_OFDM)
2244 network->mode |= IEEE_G;
2245 if (network->flags & NETWORK_HAS_CCK)
2246 network->mode |= IEEE_B;
2249 if (network->mode == 0) {
2250 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2252 escape_essid(network->ssid,
2258 if(network->bssht.bdSupportHT){
2259 if(network->mode == IEEE_A)
2260 network->mode = IEEE_N_5G;
2261 else if(network->mode & (IEEE_G | IEEE_B))
2262 network->mode = IEEE_N_24G;
2264 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2265 network->flags |= NETWORK_EMPTY_ESSID;
2267 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2268 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2269 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2271 memcpy(&network->stats, stats, sizeof(network->stats));
2276 static inline int is_same_network(struct ieee80211_network *src,
2277 struct ieee80211_network *dst, struct ieee80211_device *ieee)
2279 /* A network is only a duplicate if the channel, BSSID, ESSID
2280 * and the capability field (in particular IBSS and BSS) all match.
2281 * We treat all <hidden> with the same BSSID and channel
2283 return //((src->ssid_len == dst->ssid_len) &&
2284 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2285 (src->channel == dst->channel) &&
2286 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2287 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2288 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2289 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2290 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2291 ((src->capability & WLAN_CAPABILITY_BSS) ==
2292 (dst->capability & WLAN_CAPABILITY_BSS)));
2295 static inline void update_network(struct ieee80211_network *dst,
2296 struct ieee80211_network *src)
2301 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2302 dst->capability = src->capability;
2303 memcpy(dst->rates, src->rates, src->rates_len);
2304 dst->rates_len = src->rates_len;
2305 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2306 dst->rates_ex_len = src->rates_ex_len;
2307 if(src->ssid_len > 0)
2309 memset(dst->ssid, 0, dst->ssid_len);
2310 dst->ssid_len = src->ssid_len;
2311 memcpy(dst->ssid, src->ssid, src->ssid_len);
2313 dst->mode = src->mode;
2314 dst->flags = src->flags;
2315 dst->time_stamp[0] = src->time_stamp[0];
2316 dst->time_stamp[1] = src->time_stamp[1];
2317 if (src->flags & NETWORK_HAS_ERP_VALUE)
2319 dst->erp_value = src->erp_value;
2320 dst->berp_info_valid = src->berp_info_valid = true;
2322 dst->beacon_interval = src->beacon_interval;
2323 dst->listen_interval = src->listen_interval;
2324 dst->atim_window = src->atim_window;
2325 dst->dtim_period = src->dtim_period;
2326 dst->dtim_data = src->dtim_data;
2327 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2328 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2329 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2331 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2332 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2333 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2334 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2335 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2336 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2337 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2338 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2339 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2340 dst->ralink_cap_exist = src->ralink_cap_exist;
2341 dst->atheros_cap_exist = src->atheros_cap_exist;
2342 dst->cisco_cap_exist = src->cisco_cap_exist;
2343 dst->unknown_cap_exist = src->unknown_cap_exist;
2344 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2345 dst->wpa_ie_len = src->wpa_ie_len;
2346 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2347 dst->rsn_ie_len = src->rsn_ie_len;
2349 dst->last_scanned = jiffies;
2350 /* qos related parameters */
2351 //qos_active = src->qos_data.active;
2352 qos_active = dst->qos_data.active;
2353 //old_param = dst->qos_data.old_param_count;
2354 old_param = dst->qos_data.param_count;
2355 if(dst->flags & NETWORK_HAS_QOS_MASK)
2356 memcpy(&dst->qos_data, &src->qos_data,
2357 sizeof(struct ieee80211_qos_data));
2359 dst->qos_data.supported = src->qos_data.supported;
2360 dst->qos_data.param_count = src->qos_data.param_count;
2363 if(dst->qos_data.supported == 1) {
2364 dst->QoS_Enable = 1;
2367 ("QoS the network %s is QoS supported\n",
2371 ("QoS the network is QoS supported\n");
2373 dst->qos_data.active = qos_active;
2374 dst->qos_data.old_param_count = old_param;
2376 /* dst->last_associate is not overwritten */
2377 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2378 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2379 src->wmm_param[1].ac_aci_acm_aifsn|| \
2380 src->wmm_param[2].ac_aci_acm_aifsn|| \
2381 src->wmm_param[3].ac_aci_acm_aifsn) {
2382 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2384 //dst->QoS_Enable = src->QoS_Enable;
2386 dst->Turbo_Enable = src->Turbo_Enable;
2389 dst->CountryIeLen = src->CountryIeLen;
2390 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2392 //added by amy for LEAP
2393 dst->bWithAironetIE = src->bWithAironetIE;
2394 dst->bCkipSupported = src->bCkipSupported;
2395 memcpy(dst->CcxRmState,src->CcxRmState,2);
2396 dst->bCcxRmEnable = src->bCcxRmEnable;
2397 dst->MBssidMask = src->MBssidMask;
2398 dst->bMBssidValid = src->bMBssidValid;
2399 memcpy(dst->MBssid,src->MBssid,6);
2400 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2401 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2405 static inline int is_beacon(__le16 fc)
2407 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2410 static inline void ieee80211_process_probe_response(
2411 struct ieee80211_device *ieee,
2412 struct ieee80211_probe_response *beacon,
2413 struct ieee80211_rx_stats *stats)
2415 struct ieee80211_network network;
2416 struct ieee80211_network *target;
2417 struct ieee80211_network *oldest = NULL;
2418 #ifdef CONFIG_IEEE80211_DEBUG
2419 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2421 unsigned long flags;
2425 memset(&network, 0, sizeof(struct ieee80211_network));
2426 IEEE80211_DEBUG_SCAN(
2427 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2428 escape_essid(info_element->data, info_element->len),
2429 beacon->header.addr3,
2430 (beacon->capability & (1<<0xf)) ? '1' : '0',
2431 (beacon->capability & (1<<0xe)) ? '1' : '0',
2432 (beacon->capability & (1<<0xd)) ? '1' : '0',
2433 (beacon->capability & (1<<0xc)) ? '1' : '0',
2434 (beacon->capability & (1<<0xb)) ? '1' : '0',
2435 (beacon->capability & (1<<0xa)) ? '1' : '0',
2436 (beacon->capability & (1<<0x9)) ? '1' : '0',
2437 (beacon->capability & (1<<0x8)) ? '1' : '0',
2438 (beacon->capability & (1<<0x7)) ? '1' : '0',
2439 (beacon->capability & (1<<0x6)) ? '1' : '0',
2440 (beacon->capability & (1<<0x5)) ? '1' : '0',
2441 (beacon->capability & (1<<0x4)) ? '1' : '0',
2442 (beacon->capability & (1<<0x3)) ? '1' : '0',
2443 (beacon->capability & (1<<0x2)) ? '1' : '0',
2444 (beacon->capability & (1<<0x1)) ? '1' : '0',
2445 (beacon->capability & (1<<0x0)) ? '1' : '0');
2447 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2448 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2449 escape_essid(info_element->data,
2451 beacon->header.addr3,
2452 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2453 IEEE80211_STYPE_PROBE_RESP ?
2454 "PROBE RESPONSE" : "BEACON");
2458 // For Asus EeePc request,
2459 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2460 // wireless adapter should follow the country code.
2461 // (2) If there is no any country code in beacon,
2462 // then wireless adapter should do active scan from ch1~11 and
2463 // passive scan from ch12~14
2465 if( !IsLegalChannel(ieee, network.channel) )
2467 if(ieee->bGlobalDomain)
2469 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2471 // Case 1: Country code
2472 if(IS_COUNTRY_IE_VALID(ieee) )
2474 if( !IsLegalChannel(ieee, network.channel) )
2476 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2480 // Case 2: No any country code.
2483 // Filter over channel ch12~14
2484 if(network.channel > 11)
2486 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2493 // Case 1: Country code
2494 if(IS_COUNTRY_IE_VALID(ieee) )
2496 if( !IsLegalChannel(ieee, network.channel) )
2498 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2502 // Case 2: No any country code.
2505 // Filter over channel ch12~14
2506 if(network.channel > 14)
2508 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2515 /* The network parsed correctly -- so now we scan our known networks
2516 * to see if we can find it in our list.
2518 * NOTE: This search is definitely not optimized. Once its doing
2519 * the "right thing" we'll optimize it for efficiency if
2522 /* Search for this entry in the list and update it if it is
2525 spin_lock_irqsave(&ieee->lock, flags);
2527 if(is_same_network(&ieee->current_network, &network, ieee)) {
2528 update_network(&ieee->current_network, &network);
2529 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2530 && ieee->current_network.berp_info_valid){
2531 if(ieee->current_network.erp_value& ERP_UseProtection)
2532 ieee->current_network.buseprotection = true;
2534 ieee->current_network.buseprotection = false;
2536 if(is_beacon(beacon->header.frame_ctl))
2538 if(ieee->state == IEEE80211_LINKED)
2539 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2542 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2545 list_for_each_entry(target, &ieee->network_list, list) {
2546 if (is_same_network(target, &network, ieee))
2548 if ((oldest == NULL) ||
2549 (target->last_scanned < oldest->last_scanned))
2553 /* If we didn't find a match, then get a new network slot to initialize
2554 * with this beacon's information */
2555 if (&target->list == &ieee->network_list) {
2556 if (list_empty(&ieee->network_free_list)) {
2557 /* If there are no more slots, expire the oldest */
2558 list_del(&oldest->list);
2560 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2562 escape_essid(target->ssid,
2566 /* Otherwise just pull from the free list */
2567 target = list_entry(ieee->network_free_list.next,
2568 struct ieee80211_network, list);
2569 list_del(ieee->network_free_list.next);
2573 #ifdef CONFIG_IEEE80211_DEBUG
2574 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2575 escape_essid(network.ssid,
2578 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2579 IEEE80211_STYPE_PROBE_RESP ?
2580 "PROBE RESPONSE" : "BEACON");
2582 memcpy(target, &network, sizeof(*target));
2583 list_add_tail(&target->list, &ieee->network_list);
2584 if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2585 ieee80211_softmac_new_net(ieee,&network);
2587 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2588 escape_essid(target->ssid,
2591 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2592 IEEE80211_STYPE_PROBE_RESP ?
2593 "PROBE RESPONSE" : "BEACON");
2595 /* we have an entry and we are going to update it. But this entry may
2596 * be already expired. In this case we do the same as we found a new
2597 * net and call the new_net handler
2599 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2600 //YJ,add,080819,for hidden ap
2601 if(is_beacon(beacon->header.frame_ctl) == 0)
2602 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2603 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2604 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2605 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2606 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2607 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2609 //YJ,add,080819,for hidden ap,end
2611 update_network(target, &network);
2612 if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2613 ieee80211_softmac_new_net(ieee,&network);
2616 spin_unlock_irqrestore(&ieee->lock, flags);
2617 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2618 (ieee->state == IEEE80211_LINKED)) {
2619 if(ieee->handle_beacon != NULL) {
2620 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2625 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2626 struct ieee80211_hdr_4addr *header,
2627 struct ieee80211_rx_stats *stats)
2629 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2631 case IEEE80211_STYPE_BEACON:
2632 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2633 WLAN_FC_GET_STYPE(header->frame_ctl));
2634 IEEE80211_DEBUG_SCAN("Beacon\n");
2635 ieee80211_process_probe_response(
2636 ieee, (struct ieee80211_probe_response *)header, stats);
2639 case IEEE80211_STYPE_PROBE_RESP:
2640 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2641 WLAN_FC_GET_STYPE(header->frame_ctl));
2642 IEEE80211_DEBUG_SCAN("Probe response\n");
2643 ieee80211_process_probe_response(
2644 ieee, (struct ieee80211_probe_response *)header, stats);
2650 EXPORT_SYMBOL(ieee80211_rx_mgt);
2651 EXPORT_SYMBOL(ieee80211_rx);