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"
48 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
50 struct ieee80211_rx_stats *rx_stats)
52 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *)skb->data;
53 u16 fc = le16_to_cpu(hdr->frame_ctl);
56 skb_reset_mac_header(skb);
58 skb_pull(skb, ieee80211_get_hdrlen(fc));
59 skb->pkt_type = PACKET_OTHERHOST;
60 skb->protocol = __constant_htons(ETH_P_80211_RAW);
61 memset(skb->cb, 0, sizeof(skb->cb));
66 /* Called only as a tasklet (software IRQ) */
67 static struct ieee80211_frag_entry *
68 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
69 unsigned int frag, u8 tid,u8 *src, u8 *dst)
71 struct ieee80211_frag_entry *entry;
74 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
75 entry = &ieee->frag_cache[tid][i];
76 if (entry->skb != NULL &&
77 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
79 "expiring fragment cache entry "
80 "seq=%u last_frag=%u\n",
81 entry->seq, entry->last_frag);
82 dev_kfree_skb_any(entry->skb);
86 if (entry->skb != NULL && entry->seq == seq &&
87 (entry->last_frag + 1 == frag || frag == -1) &&
88 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
89 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
96 /* Called only as a tasklet (software IRQ) */
97 static struct sk_buff *
98 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
99 struct ieee80211_hdr_4addr *hdr)
101 struct sk_buff *skb = NULL;
102 u16 fc = le16_to_cpu(hdr->frame_ctl);
103 u16 sc = le16_to_cpu(hdr->seq_ctl);
104 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
105 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
106 struct ieee80211_frag_entry *entry;
107 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
108 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
111 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
112 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
113 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
116 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
117 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
118 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
126 /* Reserve enough space to fit maximum frame length */
127 skb = dev_alloc_skb(ieee->dev->mtu +
128 sizeof(struct ieee80211_hdr_4addr) +
133 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
137 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
138 ieee->frag_next_idx[tid]++;
139 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
140 ieee->frag_next_idx[tid] = 0;
142 if (entry->skb != NULL)
143 dev_kfree_skb_any(entry->skb);
145 entry->first_frag_time = jiffies;
147 entry->last_frag = frag;
149 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
150 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
152 /* received a fragment of a frame for which the head fragment
153 * should have already been received */
154 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
157 entry->last_frag = frag;
166 /* Called only as a tasklet (software IRQ) */
167 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
168 struct ieee80211_hdr_4addr *hdr)
170 u16 fc = le16_to_cpu(hdr->frame_ctl);
171 u16 sc = le16_to_cpu(hdr->seq_ctl);
172 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
173 struct ieee80211_frag_entry *entry;
174 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
175 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
178 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
179 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
180 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
183 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
184 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
185 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
192 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
196 IEEE80211_DEBUG_FRAG(
197 "could not invalidate fragment cache "
198 "entry (seq=%u)\n", seq);
208 /* ieee80211_rx_frame_mgtmt
210 * Responsible for handling management control frames
212 * Called by ieee80211_rx */
214 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
215 struct ieee80211_rx_stats *rx_stats, u16 type,
218 /* On the struct stats definition there is written that
219 * this is not mandatory.... but seems that the probe
220 * response parser uses it
222 struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data;
224 rx_stats->len = skb->len;
225 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
226 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
227 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames
229 dev_kfree_skb_any(skb);
233 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
235 dev_kfree_skb_any(skb);
243 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
244 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
245 static unsigned char rfc1042_header[] =
246 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
247 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
248 static unsigned char bridge_tunnel_header[] =
249 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
250 /* No encapsulation header if EtherType < 0x600 (=length) */
252 /* Called by ieee80211_rx_frame_decrypt */
253 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
254 struct sk_buff *skb, size_t hdrlen)
256 struct net_device *dev = ieee->dev;
258 struct ieee80211_hdr_4addr *hdr;
264 hdr = (struct ieee80211_hdr_4addr *) skb->data;
265 fc = le16_to_cpu(hdr->frame_ctl);
267 /* check that the frame is unicast frame to us */
268 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
269 IEEE80211_FCTL_TODS &&
270 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
271 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
272 /* ToDS frame with own addr BSSID and DA */
273 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
274 IEEE80211_FCTL_FROMDS &&
275 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
276 /* FromDS frame with own addr as DA */
280 if (skb->len < 24 + 8)
283 /* check for port access entity Ethernet type */
284 // pos = skb->data + 24;
285 pos = skb->data + hdrlen;
286 ethertype = (pos[6] << 8) | pos[7];
287 if (ethertype == ETH_P_PAE)
293 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
295 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
296 struct ieee80211_crypt_data *crypt)
298 struct ieee80211_hdr_4addr *hdr;
301 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
304 if (ieee->hwsec_active)
306 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
307 tcb_desc->bHwSec = 1;
310 hdr = (struct ieee80211_hdr_4addr *) skb->data;
311 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
313 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
314 if (ieee->tkip_countermeasures &&
315 strcmp(crypt->ops->name, "TKIP") == 0) {
316 if (net_ratelimit()) {
317 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
318 "received packet from " MAC_FMT "\n",
319 ieee->dev->name, MAC_ARG(hdr->addr2));
325 atomic_inc(&crypt->refcnt);
326 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
327 atomic_dec(&crypt->refcnt);
329 IEEE80211_DEBUG_DROP(
330 "decryption failed (SA=" MAC_FMT
331 ") res=%d\n", MAC_ARG(hdr->addr2), res);
333 IEEE80211_DEBUG_DROP("Decryption failed ICV "
334 "mismatch (key %d)\n",
335 skb->data[hdrlen + 3] >> 6);
336 ieee->ieee_stats.rx_discards_undecryptable++;
344 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
346 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
347 int keyidx, struct ieee80211_crypt_data *crypt)
349 struct ieee80211_hdr_4addr *hdr;
352 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
354 if (ieee->hwsec_active)
356 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
357 tcb_desc->bHwSec = 1;
360 hdr = (struct ieee80211_hdr_4addr *) skb->data;
361 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
363 atomic_inc(&crypt->refcnt);
364 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
365 atomic_dec(&crypt->refcnt);
367 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
368 " (SA=" MAC_FMT " keyidx=%d)\n",
369 ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
377 /* this function is stolen from ipw2200 driver*/
378 #define IEEE_PACKET_RETRY_TIME (5*HZ)
379 static int is_duplicate_packet(struct ieee80211_device *ieee,
380 struct ieee80211_hdr_4addr *header)
382 u16 fc = le16_to_cpu(header->frame_ctl);
383 u16 sc = le16_to_cpu(header->seq_ctl);
384 u16 seq = WLAN_GET_SEQ_SEQ(sc);
385 u16 frag = WLAN_GET_SEQ_FRAG(sc);
386 u16 *last_seq, *last_frag;
387 unsigned long *last_time;
388 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
389 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
394 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
395 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
396 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
399 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
400 hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
401 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
408 switch (ieee->iw_mode) {
412 struct ieee_ibss_seq *entry = NULL;
413 u8 *mac = header->addr2;
414 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
415 //for (pos = (head)->next; pos != (head); pos = pos->next)
416 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
417 list_for_each(p, &ieee->ibss_mac_hash[index]) {
418 entry = list_entry(p, struct ieee_ibss_seq, list);
419 if (!memcmp(entry->mac, mac, ETH_ALEN))
422 // if (memcmp(entry->mac, mac, ETH_ALEN)){
423 if (p == &ieee->ibss_mac_hash[index]) {
424 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
426 printk(KERN_WARNING "Cannot malloc new mac entry\n");
429 memcpy(entry->mac, mac, ETH_ALEN);
430 entry->seq_num[tid] = seq;
431 entry->frag_num[tid] = frag;
432 entry->packet_time[tid] = jiffies;
433 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
436 last_seq = &entry->seq_num[tid];
437 last_frag = &entry->frag_num[tid];
438 last_time = &entry->packet_time[tid];
443 last_seq = &ieee->last_rxseq_num[tid];
444 last_frag = &ieee->last_rxfrag_num[tid];
445 last_time = &ieee->last_packet_time[tid];
453 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
455 if ((*last_seq == seq) &&
456 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
457 if (*last_frag == frag){
458 //printk(KERN_WARNING "[1] go drop!\n");
462 if (*last_frag + 1 != frag)
463 /* out-of-order fragment */
464 //printk(KERN_WARNING "[2] go drop!\n");
470 *last_time = jiffies;
474 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
482 PRX_REORDER_ENTRY pReorderEntry
485 struct list_head *pList = &pTS->RxPendingPktList;
487 while(pList->next != &pTS->RxPendingPktList)
489 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
493 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
503 pReorderEntry->List.next = pList->next;
504 pReorderEntry->List.next->prev = &pReorderEntry->List;
505 pReorderEntry->List.prev = pList;
506 pList->next = &pReorderEntry->List;
511 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index)
516 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
517 for(j = 0; j<index; j++)
519 //added by amy for reorder
520 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
521 for(i = 0; i<prxb->nr_subframes; i++) {
522 struct sk_buff *sub_skb = prxb->subframes[i];
524 /* convert hdr + possible LLC headers into Ethernet header */
525 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
526 if (sub_skb->len >= 8 &&
527 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
528 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
529 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
530 /* remove RFC1042 or Bridge-Tunnel encapsulation and
531 * replace EtherType */
532 skb_pull(sub_skb, SNAP_SIZE);
533 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
534 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
537 /* Leave Ethernet header part of hdr and full payload */
538 len = htons(sub_skb->len);
539 memcpy(skb_push(sub_skb, 2), &len, 2);
540 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
541 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
543 //stats->rx_packets++;
544 //stats->rx_bytes += sub_skb->len;
546 /* Indicat the packets to upper layer */
548 //printk("0skb_len(%d)\n", skb->len);
549 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
550 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
551 sub_skb->dev = ieee->dev;
552 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
553 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
554 ieee->last_rx_ps_time = jiffies;
555 //printk("1skb_len(%d)\n", skb->len);
565 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
566 struct ieee80211_rxb* prxb,
570 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
571 PRX_REORDER_ENTRY pReorderEntry = NULL;
572 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
573 u8 WinSize = pHTInfo->RxReorderWinSize;
574 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
576 bool bMatchWinStart = false, bPktInBuf = false;
577 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
578 /* Rx Reorder initialize condition.*/
579 if(pTS->RxIndicateSeq == 0xffff) {
580 pTS->RxIndicateSeq = SeqNum;
583 /* Drop out the packet which SeqNum is smaller than WinStart */
584 if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
585 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
586 pTS->RxIndicateSeq, SeqNum);
587 pHTInfo->RxReorderDropCounter++;
590 for(i =0; i < prxb->nr_subframes; i++) {
591 dev_kfree_skb(prxb->subframes[i]);
600 * Sliding window manipulation. Conditions includes:
601 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
602 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
604 if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
605 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
606 bMatchWinStart = true;
607 } else if(SN_LESS(WinEnd, SeqNum)) {
608 if(SeqNum >= (WinSize - 1)) {
609 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
611 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
613 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
617 * Indication process.
618 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
619 * with the SeqNum smaller than latest WinStart and buffer other packets.
621 /* For Rx Reorder condition:
622 * 1. All packets with SeqNum smaller than WinStart => Indicate
623 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
626 /* Current packet is going to be indicated.*/
627 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
628 pTS->RxIndicateSeq, SeqNum);
629 prxbIndicateArray[0] = prxb;
630 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
633 /* Current packet is going to be inserted into pending list.*/
634 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
635 if(!list_empty(&ieee->RxReorder_Unused_List)) {
636 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
637 list_del_init(&pReorderEntry->List);
639 /* Make a reorder entry and insert into a the packet list.*/
640 pReorderEntry->SeqNum = SeqNum;
641 pReorderEntry->prxb = prxb;
642 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
645 if(!AddReorderEntry(pTS, pReorderEntry)) {
646 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
647 __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
648 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
651 for(i =0; i < prxb->nr_subframes; i++) {
652 dev_kfree_skb(prxb->subframes[i]);
658 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
659 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
665 * Packets are dropped if there is not enough reorder entries.
666 * This part shall be modified!! We can just indicate all the
667 * packets in buffer and get reorder entries.
669 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
672 for(i =0; i < prxb->nr_subframes; i++) {
673 dev_kfree_skb(prxb->subframes[i]);
681 /* Check if there is any packet need indicate.*/
682 while(!list_empty(&pTS->RxPendingPktList)) {
683 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
685 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
686 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
687 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
689 /* This protect buffer from overflow. */
690 if(index >= REORDER_WIN_SIZE) {
691 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
696 list_del_init(&pReorderEntry->List);
698 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
699 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
701 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
702 prxbIndicateArray[index] = pReorderEntry->prxb;
703 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
706 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
714 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
716 // Cancel previous pending timer.
717 if(timer_pending(&pTS->RxPktPendingTimer))
719 del_timer_sync(&pTS->RxPktPendingTimer);
721 // del_timer_sync(&pTS->RxPktPendingTimer);
722 pTS->RxTimeoutIndicateSeq = 0xffff;
725 if(index>REORDER_WIN_SIZE){
726 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
729 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
734 if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
735 // Set new pending timer.
736 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
737 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
738 mod_timer(&pTS->RxPktPendingTimer, jiffies + MSECS(pHTInfo->RxReorderPendingTime));
743 u8 parse_subframe(struct sk_buff *skb,
744 struct ieee80211_rx_stats *rx_stats,
745 struct ieee80211_rxb *rxb,u8* src,u8* dst)
747 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
748 u16 fc = le16_to_cpu(hdr->frame_ctl);
750 u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr);
752 bool bIsAggregateFrame = false;
753 u16 nSubframe_Length;
754 u8 nPadding_Length = 0;
757 struct sk_buff *sub_skb;
759 /* just for debug purpose */
760 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
762 if((IEEE80211_QOS_HAS_SEQ(fc))&&\
763 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
764 bIsAggregateFrame = true;
767 if(IEEE80211_QOS_HAS_SEQ(fc)) {
771 if(rx_stats->bContainHTC) {
772 LLCOffset += sHTCLng;
774 //printk("ChkLength = %d\n", LLCOffset);
775 // Null packet, don't indicate it to upper layer
776 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
778 if( skb->len <= ChkLength ) {
782 skb_pull(skb, LLCOffset);
784 if(!bIsAggregateFrame) {
785 rxb->nr_subframes = 1;
787 rxb->subframes[0] = skb;
789 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
792 memcpy(rxb->src,src,ETH_ALEN);
793 memcpy(rxb->dst,dst,ETH_ALEN);
794 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
797 rxb->nr_subframes = 0;
798 memcpy(rxb->src,src,ETH_ALEN);
799 memcpy(rxb->dst,dst,ETH_ALEN);
800 while(skb->len > ETHERNET_HEADER_SIZE) {
801 /* Offset 12 denote 2 mac address */
802 nSubframe_Length = *((u16*)(skb->data + 12));
803 //==m==>change the length order
804 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
806 if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
807 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
808 __FUNCTION__,rxb->nr_subframes);
809 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
810 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
811 printk("The Packet SeqNum is %d\n",SeqNum);
815 /* move the data point to data content */
816 skb_pull(skb, ETHERNET_HEADER_SIZE);
819 sub_skb = skb_clone(skb, GFP_ATOMIC);
820 sub_skb->len = nSubframe_Length;
821 sub_skb->tail = sub_skb->data + nSubframe_Length;
823 /* Allocate new skb for releasing to upper layer */
824 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
825 skb_reserve(sub_skb, 12);
826 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
827 memcpy(data_ptr,skb->data,nSubframe_Length);
829 rxb->subframes[rxb->nr_subframes++] = sub_skb;
830 if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
831 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
834 skb_pull(skb,nSubframe_Length);
837 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
838 if(nPadding_Length == 4) {
842 if(skb->len < nPadding_Length) {
846 skb_pull(skb,nPadding_Length);
852 //{just for debug added by david
853 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
855 return rxb->nr_subframes;
859 /* All received frames are sent to this function. @skb contains the frame in
860 * IEEE 802.11 format, i.e., in the format it was sent over air.
861 * This function is called only as a tasklet (software IRQ). */
862 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
863 struct ieee80211_rx_stats *rx_stats)
865 struct net_device *dev = ieee->dev;
866 struct ieee80211_hdr_4addr *hdr;
867 //struct ieee80211_hdr_3addrqos *hdr;
870 u16 fc, type, stype, sc;
871 struct net_device_stats *stats;
875 //added by amy for reorder
878 PRX_TS_RECORD pTS = NULL;
879 //bool bIsAggregateFrame = false;
880 //added by amy for reorder
885 struct ieee80211_crypt_data *crypt = NULL;
889 struct ieee80211_rxb* rxb = NULL;
890 // cheat the the hdr type
891 hdr = (struct ieee80211_hdr_4addr *)skb->data;
892 stats = &ieee->stats;
895 printk(KERN_INFO "%s: SKB length < 10\n",
900 fc = le16_to_cpu(hdr->frame_ctl);
901 type = WLAN_FC_GET_TYPE(fc);
902 stype = WLAN_FC_GET_STYPE(fc);
903 sc = le16_to_cpu(hdr->seq_ctl);
905 frag = WLAN_GET_SEQ_FRAG(sc);
906 hdrlen = ieee80211_get_hdrlen(fc);
908 if(HTCCheck(ieee, skb->data))
911 printk("find HTCControl\n");
913 rx_stats->bContainHTC = 1;
916 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
918 if (ieee->iw_mode == IW_MODE_MONITOR) {
919 ieee80211_monitor_rx(ieee, skb, rx_stats);
921 stats->rx_bytes += skb->len;
925 if (ieee->host_decrypt) {
927 if (skb->len >= hdrlen + 3)
928 idx = skb->data[hdrlen + 3] >> 6;
929 crypt = ieee->crypt[idx];
931 /* allow NULL decrypt to indicate an station specific override
932 * for default encryption */
933 if (crypt && (crypt->ops == NULL ||
934 crypt->ops->decrypt_mpdu == NULL))
937 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
938 /* This seems to be triggered by some (multicast?)
939 * frames from other than current BSS, so just drop the
940 * frames silently instead of filling system log with
942 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
943 " (SA=" MAC_FMT ")\n",
944 MAC_ARG(hdr->addr2));
945 ieee->ieee_stats.rx_discards_undecryptable++;
950 if (skb->len < IEEE80211_DATA_HDR3_LEN)
953 // if QoS enabled, should check the sequence for each of the AC
954 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
955 if (is_duplicate_packet(ieee, hdr))
961 PRX_TS_RECORD pRxTS = NULL;
962 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
966 (PTS_COMMON_INFO*) &pRxTS,
968 (u8)Frame_QoSTID((u8*)(skb->data)),
973 // 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));
974 if( (fc & (1<<11)) &&
975 (frag == pRxTS->RxLastFragNum) &&
976 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
982 pRxTS->RxLastFragNum = frag;
983 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
988 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
993 if (type == IEEE80211_FTYPE_MGMT) {
995 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
996 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1002 /* Data frame - extract src/dst addresses */
1003 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1004 case IEEE80211_FCTL_FROMDS:
1005 memcpy(dst, hdr->addr1, ETH_ALEN);
1006 memcpy(src, hdr->addr3, ETH_ALEN);
1007 memcpy(bssid, hdr->addr2, ETH_ALEN);
1009 case IEEE80211_FCTL_TODS:
1010 memcpy(dst, hdr->addr3, ETH_ALEN);
1011 memcpy(src, hdr->addr2, ETH_ALEN);
1012 memcpy(bssid, hdr->addr1, ETH_ALEN);
1014 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1015 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1017 memcpy(dst, hdr->addr3, ETH_ALEN);
1018 memcpy(src, hdr->addr4, ETH_ALEN);
1019 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1022 memcpy(dst, hdr->addr1, ETH_ALEN);
1023 memcpy(src, hdr->addr2, ETH_ALEN);
1024 memcpy(bssid, hdr->addr3, ETH_ALEN);
1029 dev->last_rx = jiffies;
1031 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1032 /* Nullfunc frames may have PS-bit set, so they must be passed to
1033 * hostap_handle_sta_rx() before being dropped here. */
1034 if (stype != IEEE80211_STYPE_DATA &&
1035 stype != IEEE80211_STYPE_DATA_CFACK &&
1036 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1037 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1038 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1040 if (stype != IEEE80211_STYPE_NULLFUNC)
1041 IEEE80211_DEBUG_DROP(
1042 "RX: dropped data frame "
1043 "with no data (type=0x%02x, "
1044 "subtype=0x%02x, len=%d)\n",
1045 type, stype, skb->len);
1048 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1051 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1053 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1054 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1056 printk("decrypt frame error\n");
1061 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1063 /* skb: hdr + (possibly fragmented) plaintext payload */
1064 // PR: FIXME: hostap has additional conditions in the "if" below:
1065 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1066 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1068 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1069 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1072 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1073 "Rx cannot get skb from fragment "
1074 "cache (morefrag=%d seq=%u frag=%u)\n",
1075 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1076 WLAN_GET_SEQ_SEQ(sc), frag);
1083 if (frag_skb->tail + flen > frag_skb->end) {
1084 printk(KERN_WARNING "%s: host decrypted and "
1085 "reassembled frame did not fit skb\n",
1087 ieee80211_frag_cache_invalidate(ieee, hdr);
1092 /* copy first fragment (including full headers) into
1093 * beginning of the fragment cache skb */
1094 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1096 /* append frame payload to the end of the fragment
1098 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1101 dev_kfree_skb_any(skb);
1104 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1105 /* more fragments expected - leave the skb in fragment
1106 * cache for now; it will be delivered to upper layers
1107 * after all fragments have been received */
1111 /* this was the last fragment and the frame will be
1112 * delivered, so remove skb from fragment cache */
1114 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1115 ieee80211_frag_cache_invalidate(ieee, hdr);
1118 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1119 * encrypted/authenticated */
1120 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1121 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1123 printk("==>decrypt msdu error\n");
1127 //added by amy for AP roaming
1128 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1129 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1131 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1132 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1133 if (/*ieee->ieee802_1x &&*/
1134 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1136 #ifdef CONFIG_IEEE80211_DEBUG
1137 /* pass unencrypted EAPOL frames even if encryption is
1139 struct eapol *eap = (struct eapol *)(skb->data +
1141 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1142 eap_get_type(eap->type));
1145 IEEE80211_DEBUG_DROP(
1146 "encryption configured, but RX "
1147 "frame not encrypted (SA=" MAC_FMT ")\n",
1148 MAC_ARG(hdr->addr2));
1153 #ifdef CONFIG_IEEE80211_DEBUG
1154 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1155 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1156 struct eapol *eap = (struct eapol *)(skb->data +
1158 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1159 eap_get_type(eap->type));
1163 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1164 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1165 IEEE80211_DEBUG_DROP(
1166 "dropped unencrypted RX data "
1167 "frame from " MAC_FMT
1168 " (drop_unencrypted=1)\n",
1169 MAC_ARG(hdr->addr2));
1173 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1174 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1177 //added by amy for reorder
1179 if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1180 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1182 TID = Frame_QoSTID(skb->data);
1183 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1184 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1185 if(TID !=0 && TID !=3)
1187 ieee->bis_any_nonbepkts = true;
1191 //added by amy for reorder
1192 /* skb: hdr + (possible reassembled) full plaintext payload */
1193 payload = skb->data + hdrlen;
1194 //ethertype = (payload[6] << 8) | payload[7];
1195 rxb = (struct ieee80211_rxb*)kmalloc(sizeof(struct ieee80211_rxb),GFP_ATOMIC);
1198 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1201 /* to parse amsdu packets */
1202 /* qos data packets & reserved bit is 1 */
1203 if(parse_subframe(skb,rx_stats,rxb,src,dst) == 0) {
1204 /* only to free rxb, and not submit the packets to upper layer */
1205 for(i =0; i < rxb->nr_subframes; i++) {
1206 dev_kfree_skb(rxb->subframes[i]);
1213 ieee->last_rx_ps_time = jiffies;
1214 //added by amy for reorder
1215 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1216 //added by amy for reorder
1217 for(i = 0; i<rxb->nr_subframes; i++) {
1218 struct sk_buff *sub_skb = rxb->subframes[i];
1221 /* convert hdr + possible LLC headers into Ethernet header */
1222 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1223 if (sub_skb->len >= 8 &&
1224 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1225 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1226 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1227 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1228 * replace EtherType */
1229 skb_pull(sub_skb, SNAP_SIZE);
1230 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1231 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1234 /* Leave Ethernet header part of hdr and full payload */
1235 len = htons(sub_skb->len);
1236 memcpy(skb_push(sub_skb, 2), &len, 2);
1237 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1238 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1241 stats->rx_packets++;
1242 stats->rx_bytes += sub_skb->len;
1243 if(is_multicast_ether_addr(dst)) {
1247 /* Indicat the packets to upper layer */
1248 //printk("0skb_len(%d)\n", skb->len);
1249 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1250 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1252 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1253 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1254 //printk("1skb_len(%d)\n", skb->len);
1264 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1265 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1280 stats->rx_dropped++;
1282 /* Returning 0 indicates to caller that we have not handled the SKB--
1283 * so it is still allocated and can be used again by underlying
1284 * hardware as a DMA target */
1288 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1290 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1293 * Make ther structure we read from the beacon packet has
1296 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1297 *info_element, int sub_type)
1300 if (info_element->qui_subtype != sub_type)
1302 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1304 if (info_element->qui_type != QOS_OUI_TYPE)
1306 if (info_element->version != QOS_VERSION_1)
1314 * Parse a QoS parameter element
1316 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1317 *element_param, struct ieee80211_info_element
1321 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1323 if ((info_element == NULL) || (element_param == NULL))
1326 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1327 memcpy(element_param->info_element.qui, info_element->data,
1329 element_param->info_element.elementID = info_element->id;
1330 element_param->info_element.length = info_element->len;
1334 ret = ieee80211_verify_qos_info(&element_param->info_element,
1335 QOS_OUI_PARAM_SUB_TYPE);
1340 * Parse a QoS information element
1342 static int ieee80211_read_qos_info_element(struct
1343 ieee80211_qos_information_element
1344 *element_info, struct ieee80211_info_element
1348 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1350 if (element_info == NULL)
1352 if (info_element == NULL)
1355 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1356 memcpy(element_info->qui, info_element->data,
1358 element_info->elementID = info_element->id;
1359 element_info->length = info_element->len;
1364 ret = ieee80211_verify_qos_info(element_info,
1365 QOS_OUI_INFO_SUB_TYPE);
1371 * Write QoS parameters from the ac parameters.
1373 static int ieee80211_qos_convert_ac_to_parameters(struct
1374 ieee80211_qos_parameter_info
1376 ieee80211_qos_parameters
1381 struct ieee80211_qos_ac_parameter *ac_params;
1386 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1387 ac_params = &(param_elm->ac_params_record[i]);
1389 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1391 if(aci >= QOS_QUEUE_NUM)
1393 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1395 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1396 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1398 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1400 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1402 qos_param->flag[aci] =
1403 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1404 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1410 * we have a generic data element which it may contain QoS information or
1411 * parameters element. check the information element length to decide
1412 * which type to read
1414 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1416 struct ieee80211_network *network)
1419 struct ieee80211_qos_parameters *qos_param = NULL;
1420 struct ieee80211_qos_information_element qos_info_element;
1422 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1425 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1426 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1428 struct ieee80211_qos_parameter_info param_element;
1430 rc = ieee80211_read_qos_param_element(¶m_element,
1433 qos_param = &(network->qos_data.parameters);
1434 ieee80211_qos_convert_ac_to_parameters(¶m_element,
1436 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1437 network->qos_data.param_count =
1438 param_element.info_element.ac_info & 0x0F;
1443 IEEE80211_DEBUG_QOS("QoS is supported\n");
1444 network->qos_data.supported = 1;
1449 #ifdef CONFIG_IEEE80211_DEBUG
1450 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1452 static const char *get_info_element_string(u16 id)
1457 MFIE_STRING(FH_SET);
1458 MFIE_STRING(DS_SET);
1459 MFIE_STRING(CF_SET);
1461 MFIE_STRING(IBSS_SET);
1462 MFIE_STRING(COUNTRY);
1463 MFIE_STRING(HOP_PARAMS);
1464 MFIE_STRING(HOP_TABLE);
1465 MFIE_STRING(REQUEST);
1466 MFIE_STRING(CHALLENGE);
1467 MFIE_STRING(POWER_CONSTRAINT);
1468 MFIE_STRING(POWER_CAPABILITY);
1469 MFIE_STRING(TPC_REQUEST);
1470 MFIE_STRING(TPC_REPORT);
1471 MFIE_STRING(SUPP_CHANNELS);
1473 MFIE_STRING(MEASURE_REQUEST);
1474 MFIE_STRING(MEASURE_REPORT);
1476 MFIE_STRING(IBSS_DFS);
1477 // MFIE_STRING(ERP_INFO);
1479 MFIE_STRING(RATES_EX);
1480 MFIE_STRING(GENERIC);
1481 MFIE_STRING(QOS_PARAMETER);
1488 static inline void ieee80211_extract_country_ie(
1489 struct ieee80211_device *ieee,
1490 struct ieee80211_info_element *info_element,
1491 struct ieee80211_network *network,
1495 if(IS_DOT11D_ENABLE(ieee))
1497 if(info_element->len!= 0)
1499 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1500 network->CountryIeLen = info_element->len;
1502 if(!IS_COUNTRY_IE_VALID(ieee))
1504 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1509 // 070305, rcnjko: I update country IE watch dog here because
1510 // some AP (e.g. Cisco 1242) don't include country IE in their
1511 // probe response frame.
1513 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1515 UPDATE_CIE_WATCHDOG(ieee);
1521 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1522 struct ieee80211_info_element *info_element,
1524 struct ieee80211_network *network,
1525 struct ieee80211_rx_stats *stats)
1529 u16 tmp_htcap_len=0;
1530 u16 tmp_htinfo_len=0;
1531 u16 ht_realtek_agg_len=0;
1532 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1533 // u16 broadcom_len = 0;
1534 #ifdef CONFIG_IEEE80211_DEBUG
1539 while (length >= sizeof(*info_element)) {
1540 if (sizeof(*info_element) + info_element->len > length) {
1541 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1542 "info_element->len + 2 > left : "
1543 "info_element->len+2=%zd left=%d, id=%d.\n",
1545 sizeof(*info_element),
1546 length, info_element->id);
1547 /* We stop processing but don't return an error here
1548 * because some misbehaviour APs break this rule. ie.
1549 * Orinoco AP1000. */
1553 switch (info_element->id) {
1554 case MFIE_TYPE_SSID:
1555 if (ieee80211_is_empty_essid(info_element->data,
1556 info_element->len)) {
1557 network->flags |= NETWORK_EMPTY_ESSID;
1561 network->ssid_len = min(info_element->len,
1562 (u8) IW_ESSID_MAX_SIZE);
1563 memcpy(network->ssid, info_element->data, network->ssid_len);
1564 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1565 memset(network->ssid + network->ssid_len, 0,
1566 IW_ESSID_MAX_SIZE - network->ssid_len);
1568 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1569 network->ssid, network->ssid_len);
1572 case MFIE_TYPE_RATES:
1573 #ifdef CONFIG_IEEE80211_DEBUG
1576 network->rates_len = min(info_element->len,
1578 for (i = 0; i < network->rates_len; i++) {
1579 network->rates[i] = info_element->data[i];
1580 #ifdef CONFIG_IEEE80211_DEBUG
1581 p += snprintf(p, sizeof(rates_str) -
1582 (p - rates_str), "%02X ",
1585 if (ieee80211_is_ofdm_rate
1586 (info_element->data[i])) {
1587 network->flags |= NETWORK_HAS_OFDM;
1588 if (info_element->data[i] &
1589 IEEE80211_BASIC_RATE_MASK)
1595 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1596 rates_str, network->rates_len);
1599 case MFIE_TYPE_RATES_EX:
1600 #ifdef CONFIG_IEEE80211_DEBUG
1603 network->rates_ex_len = min(info_element->len,
1604 MAX_RATES_EX_LENGTH);
1605 for (i = 0; i < network->rates_ex_len; i++) {
1606 network->rates_ex[i] = info_element->data[i];
1607 #ifdef CONFIG_IEEE80211_DEBUG
1608 p += snprintf(p, sizeof(rates_str) -
1609 (p - rates_str), "%02X ",
1612 if (ieee80211_is_ofdm_rate
1613 (info_element->data[i])) {
1614 network->flags |= NETWORK_HAS_OFDM;
1615 if (info_element->data[i] &
1616 IEEE80211_BASIC_RATE_MASK)
1622 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1623 rates_str, network->rates_ex_len);
1626 case MFIE_TYPE_DS_SET:
1627 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1628 info_element->data[0]);
1629 network->channel = info_element->data[0];
1632 case MFIE_TYPE_FH_SET:
1633 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1636 case MFIE_TYPE_CF_SET:
1637 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1641 if(info_element->len < 4)
1644 network->tim.tim_count = info_element->data[0];
1645 network->tim.tim_period = info_element->data[1];
1647 network->dtim_period = info_element->data[1];
1648 if(ieee->state != IEEE80211_LINKED)
1650 //we use jiffies for legacy Power save
1651 network->last_dtim_sta_time[0] = jiffies;
1652 network->last_dtim_sta_time[1] = stats->mac_time[1];
1654 network->dtim_data = IEEE80211_DTIM_VALID;
1656 if(info_element->data[0] != 0)
1659 if(info_element->data[2] & 1)
1660 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1662 offset = (info_element->data[2] >> 1)*2;
1664 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1666 if(ieee->assoc_id < 8*offset ||
1667 ieee->assoc_id > 8*(offset + info_element->len -3))
1671 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1673 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1674 network->dtim_data |= IEEE80211_DTIM_UCAST;
1676 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1680 network->erp_value = info_element->data[0];
1681 network->flags |= NETWORK_HAS_ERP_VALUE;
1682 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1683 network->erp_value);
1685 case MFIE_TYPE_IBSS_SET:
1686 network->atim_window = info_element->data[0];
1687 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1688 network->atim_window);
1691 case MFIE_TYPE_CHALLENGE:
1692 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1695 case MFIE_TYPE_GENERIC:
1696 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1698 if (!ieee80211_parse_qos_info_param_IE(info_element,
1702 if (info_element->len >= 4 &&
1703 info_element->data[0] == 0x00 &&
1704 info_element->data[1] == 0x50 &&
1705 info_element->data[2] == 0xf2 &&
1706 info_element->data[3] == 0x01) {
1707 network->wpa_ie_len = min(info_element->len + 2,
1709 memcpy(network->wpa_ie, info_element,
1710 network->wpa_ie_len);
1714 if (info_element->len == 7 &&
1715 info_element->data[0] == 0x00 &&
1716 info_element->data[1] == 0xe0 &&
1717 info_element->data[2] == 0x4c &&
1718 info_element->data[3] == 0x01 &&
1719 info_element->data[4] == 0x02) {
1720 network->Turbo_Enable = 1;
1723 //for HTcap and HTinfo parameters
1724 if(tmp_htcap_len == 0){
1725 if(info_element->len >= 4 &&
1726 info_element->data[0] == 0x00 &&
1727 info_element->data[1] == 0x90 &&
1728 info_element->data[2] == 0x4c &&
1729 info_element->data[3] == 0x033){
1731 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1732 if(tmp_htcap_len != 0){
1733 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1734 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1735 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1736 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1739 if(tmp_htcap_len != 0){
1740 network->bssht.bdSupportHT = true;
1741 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1743 network->bssht.bdSupportHT = false;
1744 network->bssht.bdHT1R = false;
1749 if(tmp_htinfo_len == 0){
1750 if(info_element->len >= 4 &&
1751 info_element->data[0] == 0x00 &&
1752 info_element->data[1] == 0x90 &&
1753 info_element->data[2] == 0x4c &&
1754 info_element->data[3] == 0x034){
1756 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1757 if(tmp_htinfo_len != 0){
1758 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1760 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1761 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1762 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1770 if(ieee->aggregation){
1771 if(network->bssht.bdSupportHT){
1772 if(info_element->len >= 4 &&
1773 info_element->data[0] == 0x00 &&
1774 info_element->data[1] == 0xe0 &&
1775 info_element->data[2] == 0x4c &&
1776 info_element->data[3] == 0x02){
1778 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
1779 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
1782 if(ht_realtek_agg_len >= 5){
1783 network->realtek_cap_exit = true;
1784 network->bssht.bdRT2RTAggregation = true;
1786 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1787 network->bssht.bdRT2RTLongSlotTime = true;
1789 if((ht_realtek_agg_buf[4]==1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
1791 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
1792 //bssDesc->Vender = HT_IOT_PEER_REALTEK_92SE;
1799 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1801 if((info_element->len >= 3 &&
1802 info_element->data[0] == 0x00 &&
1803 info_element->data[1] == 0x05 &&
1804 info_element->data[2] == 0xb5) ||
1805 (info_element->len >= 3 &&
1806 info_element->data[0] == 0x00 &&
1807 info_element->data[1] == 0x0a &&
1808 info_element->data[2] == 0xf7) ||
1809 (info_element->len >= 3 &&
1810 info_element->data[0] == 0x00 &&
1811 info_element->data[1] == 0x10 &&
1812 info_element->data[2] == 0x18)){
1814 network->broadcom_cap_exist = true;
1818 if(info_element->len >= 3 &&
1819 info_element->data[0] == 0x00 &&
1820 info_element->data[1] == 0x0c &&
1821 info_element->data[2] == 0x43)
1823 network->ralink_cap_exist = true;
1826 network->ralink_cap_exist = false;
1827 //added by amy for atheros AP
1828 if((info_element->len >= 3 &&
1829 info_element->data[0] == 0x00 &&
1830 info_element->data[1] == 0x03 &&
1831 info_element->data[2] == 0x7f) ||
1832 (info_element->len >= 3 &&
1833 info_element->data[0] == 0x00 &&
1834 info_element->data[1] == 0x13 &&
1835 info_element->data[2] == 0x74))
1837 // printk("========>%s(): athros AP is exist\n",__FUNCTION__);
1838 network->atheros_cap_exist = true;
1841 network->atheros_cap_exist = false;
1843 if ((info_element->len >= 3 &&
1844 info_element->data[0] == 0x00 &&
1845 info_element->data[1] == 0x50 &&
1846 info_element->data[2] == 0x43) )
1848 network->marvell_cap_exist = true;
1851 network->marvell_cap_exist = false;
1853 if(info_element->len >= 3 &&
1854 info_element->data[0] == 0x00 &&
1855 info_element->data[1] == 0x40 &&
1856 info_element->data[2] == 0x96)
1858 network->cisco_cap_exist = true;
1861 network->cisco_cap_exist = false;
1862 //added by amy for LEAP of cisco
1863 if(info_element->len > 4 &&
1864 info_element->data[0] == 0x00 &&
1865 info_element->data[1] == 0x40 &&
1866 info_element->data[2] == 0x96 &&
1867 info_element->data[3] == 0x01)
1869 if(info_element->len == 6)
1871 memcpy(network->CcxRmState, &info_element[4], 2);
1872 if(network->CcxRmState[0] != 0)
1874 network->bCcxRmEnable = true;
1877 network->bCcxRmEnable = false;
1879 // CCXv4 Table 59-1 MBSSID Masks.
1881 network->MBssidMask = network->CcxRmState[1] & 0x07;
1882 if(network->MBssidMask != 0)
1884 network->bMBssidValid = true;
1885 network->MBssidMask = 0xff << (network->MBssidMask);
1886 cpMacAddr(network->MBssid, network->bssid);
1887 network->MBssid[5] &= network->MBssidMask;
1891 network->bMBssidValid = false;
1896 network->bCcxRmEnable = false;
1899 if(info_element->len > 4 &&
1900 info_element->data[0] == 0x00 &&
1901 info_element->data[1] == 0x40 &&
1902 info_element->data[2] == 0x96 &&
1903 info_element->data[3] == 0x03)
1905 if(info_element->len == 5)
1907 network->bWithCcxVerNum = true;
1908 network->BssCcxVerNumber = info_element->data[4];
1912 network->bWithCcxVerNum = false;
1913 network->BssCcxVerNumber = 0;
1919 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1921 network->rsn_ie_len = min(info_element->len + 2,
1923 memcpy(network->rsn_ie, info_element,
1924 network->rsn_ie_len);
1927 //HT related element.
1928 case MFIE_TYPE_HT_CAP:
1929 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
1931 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1932 if(tmp_htcap_len != 0){
1933 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1934 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1935 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1936 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1938 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1939 // windows driver will update WMM parameters each beacon received once connected
1940 // Linux driver is a bit different.
1941 network->bssht.bdSupportHT = true;
1942 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1945 network->bssht.bdSupportHT = false;
1946 network->bssht.bdHT1R = false;
1951 case MFIE_TYPE_HT_INFO:
1952 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
1954 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1956 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
1957 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1958 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1959 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1963 case MFIE_TYPE_AIRONET:
1964 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
1966 if(info_element->len >IE_CISCO_FLAG_POSITION)
1968 network->bWithAironetIE = true;
1970 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
1971 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
1972 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
1973 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
1974 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
1976 network->bCkipSupported = true;
1980 network->bCkipSupported = false;
1985 network->bWithAironetIE = false;
1986 network->bCkipSupported = false;
1989 case MFIE_TYPE_QOS_PARAMETER:
1991 "QoS Error need to parse QOS_PARAMETER IE\n");
1994 case MFIE_TYPE_COUNTRY:
1995 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
1997 //printk("=====>Receive <%s> Country IE\n",network->ssid);
1998 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2001 IEEE80211_DEBUG_MGMT
2002 ("Unsupported info element: %s (%d)\n",
2003 get_info_element_string(info_element->id),
2008 length -= sizeof(*info_element) + info_element->len;
2010 (struct ieee80211_info_element *)&info_element->
2011 data[info_element->len];
2014 if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2015 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation)
2017 network->unknown_cap_exist = true;
2021 network->unknown_cap_exist = false;
2026 static inline u8 ieee80211_SignalStrengthTranslate(
2032 // Step 1. Scale mapping.
2033 if(CurrSS >= 71 && CurrSS <= 100)
2035 RetSS = 90 + ((CurrSS - 70) / 3);
2037 else if(CurrSS >= 41 && CurrSS <= 70)
2039 RetSS = 78 + ((CurrSS - 40) / 3);
2041 else if(CurrSS >= 31 && CurrSS <= 40)
2043 RetSS = 66 + (CurrSS - 30);
2045 else if(CurrSS >= 21 && CurrSS <= 30)
2047 RetSS = 54 + (CurrSS - 20);
2049 else if(CurrSS >= 5 && CurrSS <= 20)
2051 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2053 else if(CurrSS == 4)
2057 else if(CurrSS == 3)
2061 else if(CurrSS == 2)
2065 else if(CurrSS == 1)
2073 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2075 // Step 2. Smoothing.
2077 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2082 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2084 long signal_power; // in dBm.
2086 // Translate to dBm (x=0.5y-95).
2087 signal_power = (long)((signal_strength_index + 1) >> 1);
2090 return signal_power;
2093 static inline int ieee80211_network_init(
2094 struct ieee80211_device *ieee,
2095 struct ieee80211_probe_response *beacon,
2096 struct ieee80211_network *network,
2097 struct ieee80211_rx_stats *stats)
2099 #ifdef CONFIG_IEEE80211_DEBUG
2100 //char rates_str[64];
2104 network->qos_data.active = 0;
2105 network->qos_data.supported = 0;
2106 network->qos_data.param_count = 0;
2107 network->qos_data.old_param_count = 0;
2109 /* Pull out fixed field data */
2110 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2111 network->capability = le16_to_cpu(beacon->capability);
2112 network->last_scanned = jiffies;
2113 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2114 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2115 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2116 /* Where to pull this? beacon->listen_interval;*/
2117 network->listen_interval = 0x0A;
2118 network->rates_len = network->rates_ex_len = 0;
2119 network->last_associate = 0;
2120 network->ssid_len = 0;
2122 network->atim_window = 0;
2123 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2125 network->berp_info_valid = false;
2126 network->broadcom_cap_exist = false;
2127 network->ralink_cap_exist = false;
2128 network->atheros_cap_exist = false;
2129 network->cisco_cap_exist = false;
2130 network->unknown_cap_exist = false;
2131 network->realtek_cap_exit = false;
2132 network->marvell_cap_exist = false;
2133 network->Turbo_Enable = 0;
2134 network->CountryIeLen = 0;
2135 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2136 //Initialize HT parameters
2137 //ieee80211_ht_initialize(&network->bssht);
2138 HTInitializeBssDesc(&network->bssht);
2139 if (stats->freq == IEEE80211_52GHZ_BAND) {
2140 /* for A band (No DS info) */
2141 network->channel = stats->received_channel;
2143 network->flags |= NETWORK_HAS_CCK;
2145 network->wpa_ie_len = 0;
2146 network->rsn_ie_len = 0;
2148 if (ieee80211_parse_info_param
2149 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2153 if (stats->freq == IEEE80211_52GHZ_BAND)
2154 network->mode = IEEE_A;
2156 if (network->flags & NETWORK_HAS_OFDM)
2157 network->mode |= IEEE_G;
2158 if (network->flags & NETWORK_HAS_CCK)
2159 network->mode |= IEEE_B;
2162 if (network->mode == 0) {
2163 IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
2165 escape_essid(network->ssid,
2167 MAC_ARG(network->bssid));
2171 if(network->bssht.bdSupportHT){
2172 if(network->mode == IEEE_A)
2173 network->mode = IEEE_N_5G;
2174 else if(network->mode & (IEEE_G | IEEE_B))
2175 network->mode = IEEE_N_24G;
2177 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2178 network->flags |= NETWORK_EMPTY_ESSID;
2181 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2182 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2183 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2186 memcpy(&network->stats, stats, sizeof(network->stats));
2191 static inline int is_same_network(struct ieee80211_network *src,
2192 struct ieee80211_network *dst, struct ieee80211_device* ieee)
2194 /* A network is only a duplicate if the channel, BSSID, ESSID
2195 * and the capability field (in particular IBSS and BSS) all match.
2196 * We treat all <hidden> with the same BSSID and channel
2198 return //((src->ssid_len == dst->ssid_len) &&
2199 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2200 (src->channel == dst->channel) &&
2201 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2202 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2203 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2204 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2205 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2206 ((src->capability & WLAN_CAPABILITY_BSS) ==
2207 (dst->capability & WLAN_CAPABILITY_BSS)));
2210 static inline void update_network(struct ieee80211_network *dst,
2211 struct ieee80211_network *src)
2216 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2217 dst->capability = src->capability;
2218 memcpy(dst->rates, src->rates, src->rates_len);
2219 dst->rates_len = src->rates_len;
2220 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2221 dst->rates_ex_len = src->rates_ex_len;
2222 if(src->ssid_len > 0)
2224 memset(dst->ssid, 0, dst->ssid_len);
2225 dst->ssid_len = src->ssid_len;
2226 memcpy(dst->ssid, src->ssid, src->ssid_len);
2228 dst->mode = src->mode;
2229 dst->flags = src->flags;
2230 dst->time_stamp[0] = src->time_stamp[0];
2231 dst->time_stamp[1] = src->time_stamp[1];
2232 if (src->flags & NETWORK_HAS_ERP_VALUE)
2234 dst->erp_value = src->erp_value;
2235 dst->berp_info_valid = src->berp_info_valid = true;
2237 dst->beacon_interval = src->beacon_interval;
2238 dst->listen_interval = src->listen_interval;
2239 dst->atim_window = src->atim_window;
2240 dst->dtim_period = src->dtim_period;
2241 dst->dtim_data = src->dtim_data;
2242 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2243 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2244 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2246 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2247 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2248 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2249 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2250 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2251 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2252 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2253 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2254 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2255 dst->ralink_cap_exist = src->ralink_cap_exist;
2256 dst->atheros_cap_exist = src->atheros_cap_exist;
2257 dst->realtek_cap_exit = src->realtek_cap_exit;
2258 dst->marvell_cap_exist = src->marvell_cap_exist;
2259 dst->cisco_cap_exist = src->cisco_cap_exist;
2260 dst->unknown_cap_exist = src->unknown_cap_exist;
2261 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2262 dst->wpa_ie_len = src->wpa_ie_len;
2263 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2264 dst->rsn_ie_len = src->rsn_ie_len;
2266 dst->last_scanned = jiffies;
2267 /* qos related parameters */
2268 //qos_active = src->qos_data.active;
2269 qos_active = dst->qos_data.active;
2270 //old_param = dst->qos_data.old_param_count;
2271 old_param = dst->qos_data.param_count;
2272 if(dst->flags & NETWORK_HAS_QOS_MASK){
2273 //not update QOS paramter in beacon, as most AP will set all these parameter to 0.//WB
2274 // printk("====>%s(), aifs:%x, %x\n", __FUNCTION__, dst->qos_data.parameters.aifs[0], src->qos_data.parameters.aifs[0]);
2275 // memcpy(&dst->qos_data, &src->qos_data,
2276 // sizeof(struct ieee80211_qos_data));
2279 dst->qos_data.supported = src->qos_data.supported;
2280 dst->qos_data.param_count = src->qos_data.param_count;
2283 if(dst->qos_data.supported == 1) {
2284 dst->QoS_Enable = 1;
2287 ("QoS the network %s is QoS supported\n",
2291 ("QoS the network is QoS supported\n");
2293 dst->qos_data.active = qos_active;
2294 dst->qos_data.old_param_count = old_param;
2296 /* dst->last_associate is not overwritten */
2298 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2299 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2300 src->wmm_param[1].ac_aci_acm_aifsn|| \
2301 src->wmm_param[2].ac_aci_acm_aifsn|| \
2302 src->wmm_param[1].ac_aci_acm_aifsn) {
2303 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2305 //dst->QoS_Enable = src->QoS_Enable;
2307 dst->QoS_Enable = 1;//for Rtl8187 simulation
2309 dst->Turbo_Enable = src->Turbo_Enable;
2311 dst->CountryIeLen = src->CountryIeLen;
2312 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2314 //added by amy for LEAP
2315 dst->bWithAironetIE = src->bWithAironetIE;
2316 dst->bCkipSupported = src->bCkipSupported;
2317 memcpy(dst->CcxRmState,src->CcxRmState,2);
2318 dst->bCcxRmEnable = src->bCcxRmEnable;
2319 dst->MBssidMask = src->MBssidMask;
2320 dst->bMBssidValid = src->bMBssidValid;
2321 memcpy(dst->MBssid,src->MBssid,6);
2322 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2323 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2327 static inline int is_beacon(__le16 fc)
2329 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2332 static inline void ieee80211_process_probe_response(
2333 struct ieee80211_device *ieee,
2334 struct ieee80211_probe_response *beacon,
2335 struct ieee80211_rx_stats *stats)
2337 struct ieee80211_network network;
2338 struct ieee80211_network *target;
2339 struct ieee80211_network *oldest = NULL;
2340 #ifdef CONFIG_IEEE80211_DEBUG
2341 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2343 unsigned long flags;
2347 memset(&network, 0, sizeof(struct ieee80211_network));
2348 IEEE80211_DEBUG_SCAN(
2349 "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2350 escape_essid(info_element->data, info_element->len),
2351 MAC_ARG(beacon->header.addr3),
2352 (beacon->capability & (1<<0xf)) ? '1' : '0',
2353 (beacon->capability & (1<<0xe)) ? '1' : '0',
2354 (beacon->capability & (1<<0xd)) ? '1' : '0',
2355 (beacon->capability & (1<<0xc)) ? '1' : '0',
2356 (beacon->capability & (1<<0xb)) ? '1' : '0',
2357 (beacon->capability & (1<<0xa)) ? '1' : '0',
2358 (beacon->capability & (1<<0x9)) ? '1' : '0',
2359 (beacon->capability & (1<<0x8)) ? '1' : '0',
2360 (beacon->capability & (1<<0x7)) ? '1' : '0',
2361 (beacon->capability & (1<<0x6)) ? '1' : '0',
2362 (beacon->capability & (1<<0x5)) ? '1' : '0',
2363 (beacon->capability & (1<<0x4)) ? '1' : '0',
2364 (beacon->capability & (1<<0x3)) ? '1' : '0',
2365 (beacon->capability & (1<<0x2)) ? '1' : '0',
2366 (beacon->capability & (1<<0x1)) ? '1' : '0',
2367 (beacon->capability & (1<<0x0)) ? '1' : '0');
2369 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2370 IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
2371 escape_essid(info_element->data,
2373 MAC_ARG(beacon->header.addr3),
2374 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2375 IEEE80211_STYPE_PROBE_RESP ?
2376 "PROBE RESPONSE" : "BEACON");
2380 // For Asus EeePc request,
2381 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2382 // wireless adapter should follow the country code.
2383 // (2) If there is no any country code in beacon,
2384 // then wireless adapter should do active scan from ch1~11 and
2385 // passive scan from ch12~14
2387 if( !IsLegalChannel(ieee, network.channel) )
2389 if(ieee->bGlobalDomain)
2391 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2393 // Case 1: Country code
2394 if(IS_COUNTRY_IE_VALID(ieee) )
2396 if( !IsLegalChannel(ieee, network.channel) )
2398 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2402 // Case 2: No any country code.
2405 // Filter over channel ch12~14
2406 if(network.channel > 11)
2408 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2415 // Case 1: Country code
2416 if(IS_COUNTRY_IE_VALID(ieee) )
2418 if( !IsLegalChannel(ieee, network.channel) )
2420 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2424 // Case 2: No any country code.
2427 // Filter over channel ch12~14
2428 if(network.channel > 14)
2430 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2437 /* The network parsed correctly -- so now we scan our known networks
2438 * to see if we can find it in our list.
2440 * NOTE: This search is definitely not optimized. Once its doing
2441 * the "right thing" we'll optimize it for efficiency if
2444 /* Search for this entry in the list and update it if it is
2447 spin_lock_irqsave(&ieee->lock, flags);
2449 if(is_same_network(&ieee->current_network, &network, ieee)) {
2450 update_network(&ieee->current_network, &network);
2451 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2452 && ieee->current_network.berp_info_valid){
2453 if(ieee->current_network.erp_value& ERP_UseProtection)
2454 ieee->current_network.buseprotection = true;
2456 ieee->current_network.buseprotection = false;
2458 if(is_beacon(beacon->header.frame_ctl))
2460 if(ieee->state == IEEE80211_LINKED)
2461 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2464 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2467 list_for_each_entry(target, &ieee->network_list, list) {
2468 if (is_same_network(target, &network, ieee))
2470 if ((oldest == NULL) ||
2471 (target->last_scanned < oldest->last_scanned))
2475 /* If we didn't find a match, then get a new network slot to initialize
2476 * with this beacon's information */
2477 if (&target->list == &ieee->network_list) {
2478 if (list_empty(&ieee->network_free_list)) {
2479 /* If there are no more slots, expire the oldest */
2480 list_del(&oldest->list);
2482 IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
2484 escape_essid(target->ssid,
2486 MAC_ARG(target->bssid));
2488 /* Otherwise just pull from the free list */
2489 target = list_entry(ieee->network_free_list.next,
2490 struct ieee80211_network, list);
2491 list_del(ieee->network_free_list.next);
2495 #ifdef CONFIG_IEEE80211_DEBUG
2496 IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
2497 escape_essid(network.ssid,
2499 MAC_ARG(network.bssid),
2500 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2501 IEEE80211_STYPE_PROBE_RESP ?
2502 "PROBE RESPONSE" : "BEACON");
2504 memcpy(target, &network, sizeof(*target));
2505 list_add_tail(&target->list, &ieee->network_list);
2506 if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2507 ieee80211_softmac_new_net(ieee,&network);
2509 IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
2510 escape_essid(target->ssid,
2512 MAC_ARG(target->bssid),
2513 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2514 IEEE80211_STYPE_PROBE_RESP ?
2515 "PROBE RESPONSE" : "BEACON");
2517 /* we have an entry and we are going to update it. But this entry may
2518 * be already expired. In this case we do the same as we found a new
2519 * net and call the new_net handler
2521 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2522 //YJ,add,080819,for hidden ap
2523 if(is_beacon(beacon->header.frame_ctl) == 0)
2524 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2525 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2526 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2527 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2528 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2529 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2531 //YJ,add,080819,for hidden ap,end
2533 update_network(target, &network);
2534 if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2535 ieee80211_softmac_new_net(ieee,&network);
2538 spin_unlock_irqrestore(&ieee->lock, flags);
2539 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2540 (ieee->state == IEEE80211_LINKED)) {
2541 if(ieee->handle_beacon != NULL) {
2542 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2547 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2548 struct ieee80211_hdr_4addr *header,
2549 struct ieee80211_rx_stats *stats)
2551 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2552 ieee->iw_mode == IW_MODE_INFRA &&
2553 ieee->state == IEEE80211_LINKED))
2555 tasklet_schedule(&ieee->ps_task);
2558 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2559 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2560 ieee->last_rx_ps_time = jiffies;
2562 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2564 case IEEE80211_STYPE_BEACON:
2565 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2566 WLAN_FC_GET_STYPE(header->frame_ctl));
2567 IEEE80211_DEBUG_SCAN("Beacon\n");
2568 ieee80211_process_probe_response(
2569 ieee, (struct ieee80211_probe_response *)header, stats);
2572 case IEEE80211_STYPE_PROBE_RESP:
2573 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2574 WLAN_FC_GET_STYPE(header->frame_ctl));
2575 IEEE80211_DEBUG_SCAN("Probe response\n");
2576 ieee80211_process_probe_response(
2577 ieee, (struct ieee80211_probe_response *)header, stats);