2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
14 ******************************************************************************
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
19 A special thanks goes to Realtek for their support !
21 ******************************************************************************/
24 #include <linux/compiler.h>
25 //#include <linux/config.h>
26 #include <linux/errno.h>
27 #include <linux/if_arp.h>
28 #include <linux/in6.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <linux/pci.h>
35 #include <linux/proc_fs.h>
36 #include <linux/skbuff.h>
37 #include <linux/slab.h>
38 #include <linux/tcp.h>
39 #include <linux/types.h>
40 #include <linux/version.h>
41 #include <linux/wireless.h>
42 #include <linux/etherdevice.h>
43 #include <asm/uaccess.h>
44 #include <linux/ctype.h>
46 #include "ieee80211.h"
50 static inline void ieee80211_monitor_rx(struct ieee80211_device
*ieee
,
52 struct ieee80211_rx_stats
*rx_stats
)
54 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
55 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
58 skb_reset_mac_header(skb
);
60 skb_pull(skb
, ieee80211_get_hdrlen(fc
));
61 skb
->pkt_type
= PACKET_OTHERHOST
;
62 skb
->protocol
= __constant_htons(ETH_P_80211_RAW
);
63 memset(skb
->cb
, 0, sizeof(skb
->cb
));
68 /* Called only as a tasklet (software IRQ) */
69 static struct ieee80211_frag_entry
*
70 ieee80211_frag_cache_find(struct ieee80211_device
*ieee
, unsigned int seq
,
71 unsigned int frag
, u8 tid
,u8
*src
, u8
*dst
)
73 struct ieee80211_frag_entry
*entry
;
76 for (i
= 0; i
< IEEE80211_FRAG_CACHE_LEN
; i
++) {
77 entry
= &ieee
->frag_cache
[tid
][i
];
78 if (entry
->skb
!= NULL
&&
79 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
81 "expiring fragment cache entry "
82 "seq=%u last_frag=%u\n",
83 entry
->seq
, entry
->last_frag
);
84 dev_kfree_skb_any(entry
->skb
);
88 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
89 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
90 memcmp(entry
->src_addr
, src
, ETH_ALEN
) == 0 &&
91 memcmp(entry
->dst_addr
, dst
, ETH_ALEN
) == 0)
98 /* Called only as a tasklet (software IRQ) */
99 static struct sk_buff
*
100 ieee80211_frag_cache_get(struct ieee80211_device
*ieee
,
101 struct ieee80211_hdr_4addr
*hdr
)
103 struct sk_buff
*skb
= NULL
;
104 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
105 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
106 unsigned int frag
= WLAN_GET_SEQ_FRAG(sc
);
107 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
108 struct ieee80211_frag_entry
*entry
;
109 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
110 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
113 if (((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
114 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
115 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
118 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
119 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
120 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
128 /* Reserve enough space to fit maximum frame length */
129 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
130 sizeof(struct ieee80211_hdr_4addr
) +
135 (IEEE80211_QOS_HAS_SEQ(fc
)?2:0) /* QOS Control */);
139 entry
= &ieee
->frag_cache
[tid
][ieee
->frag_next_idx
[tid
]];
140 ieee
->frag_next_idx
[tid
]++;
141 if (ieee
->frag_next_idx
[tid
] >= IEEE80211_FRAG_CACHE_LEN
)
142 ieee
->frag_next_idx
[tid
] = 0;
144 if (entry
->skb
!= NULL
)
145 dev_kfree_skb_any(entry
->skb
);
147 entry
->first_frag_time
= jiffies
;
149 entry
->last_frag
= frag
;
151 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
152 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
154 /* received a fragment of a frame for which the head fragment
155 * should have already been received */
156 entry
= ieee80211_frag_cache_find(ieee
, seq
, frag
, tid
,hdr
->addr2
,
159 entry
->last_frag
= frag
;
168 /* Called only as a tasklet (software IRQ) */
169 static int ieee80211_frag_cache_invalidate(struct ieee80211_device
*ieee
,
170 struct ieee80211_hdr_4addr
*hdr
)
172 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
173 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
174 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
175 struct ieee80211_frag_entry
*entry
;
176 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
177 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
180 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
181 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
182 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
185 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
186 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
187 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
194 entry
= ieee80211_frag_cache_find(ieee
, seq
, -1, tid
,hdr
->addr2
,
198 IEEE80211_DEBUG_FRAG(
199 "could not invalidate fragment cache "
200 "entry (seq=%u)\n", seq
);
210 /* ieee80211_rx_frame_mgtmt
212 * Responsible for handling management control frames
214 * Called by ieee80211_rx */
216 ieee80211_rx_frame_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
217 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
220 /* On the struct stats definition there is written that
221 * this is not mandatory.... but seems that the probe
222 * response parser uses it
224 struct ieee80211_hdr_3addr
* hdr
= (struct ieee80211_hdr_3addr
*)skb
->data
;
226 rx_stats
->len
= skb
->len
;
227 ieee80211_rx_mgt(ieee
,(struct ieee80211_hdr_4addr
*)skb
->data
,rx_stats
);
228 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
229 if ((memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
)))//use ADDR1 to perform address matching for Management frames
231 dev_kfree_skb_any(skb
);
235 ieee80211_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
237 dev_kfree_skb_any(skb
);
242 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
243 printk(KERN_DEBUG
"%s: Master mode not yet suppported.\n",
247 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
251 if (ieee
->hostapd
&& type
== IEEE80211_TYPE_MGMT
) {
252 if (stype
== WLAN_FC_STYPE_BEACON
&&
253 ieee
->iw_mode
== IW_MODE_MASTER
) {
254 struct sk_buff
*skb2
;
255 /* Process beacon frames also in kernel driver to
256 * update STA(AP) table statistics */
257 skb2
= skb_clone(skb
, GFP_ATOMIC
);
259 hostap_rx(skb2
->dev
, skb2
, rx_stats
);
262 /* send management frames to the user space daemon for
264 ieee
->apdevstats
.rx_packets
++;
265 ieee
->apdevstats
.rx_bytes
+= skb
->len
;
266 prism2_rx_80211(ieee
->apdev
, skb
, rx_stats
, PRISM2_RX_MGMT
);
270 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
271 if (type
!= WLAN_FC_TYPE_MGMT
&& type
!= WLAN_FC_TYPE_CTRL
) {
272 printk(KERN_DEBUG
"%s: unknown management frame "
273 "(type=0x%02x, stype=0x%02x) dropped\n",
274 skb
->dev
->name
, type
, stype
);
278 hostap_rx(skb
->dev
, skb
, rx_stats
);
282 printk(KERN_DEBUG
"%s: hostap_rx_frame_mgmt: management frame "
283 "received in non-Host AP mode\n", skb
->dev
->name
);
290 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
291 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
292 static unsigned char rfc1042_header
[] =
293 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
294 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
295 static unsigned char bridge_tunnel_header
[] =
296 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
297 /* No encapsulation header if EtherType < 0x600 (=length) */
299 /* Called by ieee80211_rx_frame_decrypt */
300 static int ieee80211_is_eapol_frame(struct ieee80211_device
*ieee
,
301 struct sk_buff
*skb
, size_t hdrlen
)
303 struct net_device
*dev
= ieee
->dev
;
305 struct ieee80211_hdr_4addr
*hdr
;
311 if (ieee
->hwsec_active
)
313 cb_desc
*tcb_desc
= (cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
314 tcb_desc
->bHwSec
= 1;
316 if(ieee
->need_sw_enc
)
317 tcb_desc
->bHwSec
= 0;
320 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
321 fc
= le16_to_cpu(hdr
->frame_ctl
);
323 /* check that the frame is unicast frame to us */
324 if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
325 IEEE80211_FCTL_TODS
&&
326 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
327 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
328 /* ToDS frame with own addr BSSID and DA */
329 } else if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
330 IEEE80211_FCTL_FROMDS
&&
331 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
332 /* FromDS frame with own addr as DA */
336 if (skb
->len
< 24 + 8)
339 /* check for port access entity Ethernet type */
340 // pos = skb->data + 24;
341 pos
= skb
->data
+ hdrlen
;
342 ethertype
= (pos
[6] << 8) | pos
[7];
343 if (ethertype
== ETH_P_PAE
)
349 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
351 ieee80211_rx_frame_decrypt(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
352 struct ieee80211_crypt_data
*crypt
)
354 struct ieee80211_hdr_4addr
*hdr
;
357 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
359 if (ieee
->hwsec_active
)
361 cb_desc
*tcb_desc
= (cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
362 tcb_desc
->bHwSec
= 1;
364 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
365 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
367 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
368 if (ieee
->tkip_countermeasures
&&
369 strcmp(crypt
->ops
->name
, "TKIP") == 0) {
370 if (net_ratelimit()) {
371 printk(KERN_DEBUG
"%s: TKIP countermeasures: dropped "
372 "received packet from %pM\n",
373 ieee
->dev
->name
, hdr
->addr2
);
379 atomic_inc(&crypt
->refcnt
);
380 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
381 atomic_dec(&crypt
->refcnt
);
383 IEEE80211_DEBUG_DROP(
384 "decryption failed (SA=%pM"
385 ") res=%d\n", hdr
->addr2
, res
);
387 IEEE80211_DEBUG_DROP("Decryption failed ICV "
388 "mismatch (key %d)\n",
389 skb
->data
[hdrlen
+ 3] >> 6);
390 ieee
->ieee_stats
.rx_discards_undecryptable
++;
398 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
400 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
401 int keyidx
, struct ieee80211_crypt_data
*crypt
)
403 struct ieee80211_hdr_4addr
*hdr
;
406 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
408 if (ieee
->hwsec_active
)
410 cb_desc
*tcb_desc
= (cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
411 tcb_desc
->bHwSec
= 1;
413 if(ieee
->need_sw_enc
)
414 tcb_desc
->bHwSec
= 0;
418 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
419 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
421 atomic_inc(&crypt
->refcnt
);
422 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
423 atomic_dec(&crypt
->refcnt
);
425 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
426 " (SA=%pM keyidx=%d)\n",
427 ieee
->dev
->name
, hdr
->addr2
, keyidx
);
435 /* this function is stolen from ipw2200 driver*/
436 #define IEEE_PACKET_RETRY_TIME (5*HZ)
437 static int is_duplicate_packet(struct ieee80211_device
*ieee
,
438 struct ieee80211_hdr_4addr
*header
)
440 u16 fc
= le16_to_cpu(header
->frame_ctl
);
441 u16 sc
= le16_to_cpu(header
->seq_ctl
);
442 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
443 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
444 u16
*last_seq
, *last_frag
;
445 unsigned long *last_time
;
446 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
447 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
452 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
453 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)header
;
454 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
457 } else if(IEEE80211_QOS_HAS_SEQ(fc
)) { //QoS
458 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)header
;
459 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
466 switch (ieee
->iw_mode
) {
470 struct ieee_ibss_seq
*entry
= NULL
;
471 u8
*mac
= header
->addr2
;
472 int index
= mac
[5] % IEEE_IBSS_MAC_HASH_SIZE
;
473 //for (pos = (head)->next; pos != (head); pos = pos->next)
474 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
475 list_for_each(p
, &ieee
->ibss_mac_hash
[index
]) {
476 entry
= list_entry(p
, struct ieee_ibss_seq
, list
);
477 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
480 // if (memcmp(entry->mac, mac, ETH_ALEN)){
481 if (p
== &ieee
->ibss_mac_hash
[index
]) {
482 entry
= kmalloc(sizeof(struct ieee_ibss_seq
), GFP_ATOMIC
);
484 printk(KERN_WARNING
"Cannot malloc new mac entry\n");
487 memcpy(entry
->mac
, mac
, ETH_ALEN
);
488 entry
->seq_num
[tid
] = seq
;
489 entry
->frag_num
[tid
] = frag
;
490 entry
->packet_time
[tid
] = jiffies
;
491 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
494 last_seq
= &entry
->seq_num
[tid
];
495 last_frag
= &entry
->frag_num
[tid
];
496 last_time
= &entry
->packet_time
[tid
];
501 last_seq
= &ieee
->last_rxseq_num
[tid
];
502 last_frag
= &ieee
->last_rxfrag_num
[tid
];
503 last_time
= &ieee
->last_packet_time
[tid
];
511 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
513 if ((*last_seq
== seq
) &&
514 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
515 if (*last_frag
== frag
){
516 //printk(KERN_WARNING "[1] go drop!\n");
520 if (*last_frag
+ 1 != frag
)
521 /* out-of-order fragment */
522 //printk(KERN_WARNING "[2] go drop!\n");
528 *last_time
= jiffies
;
532 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
540 PRX_REORDER_ENTRY pReorderEntry
543 struct list_head
*pList
= &pTS
->RxPendingPktList
;
544 while(pList
->next
!= &pTS
->RxPendingPktList
)
546 if( SN_LESS(pReorderEntry
->SeqNum
, ((PRX_REORDER_ENTRY
)list_entry(pList
->next
,RX_REORDER_ENTRY
,List
))->SeqNum
) )
550 else if( SN_EQUAL(pReorderEntry
->SeqNum
, ((PRX_REORDER_ENTRY
)list_entry(pList
->next
,RX_REORDER_ENTRY
,List
))->SeqNum
) )
559 pReorderEntry
->List
.next
= pList
->next
;
560 pReorderEntry
->List
.next
->prev
= &pReorderEntry
->List
;
561 pReorderEntry
->List
.prev
= pList
;
562 pList
->next
= &pReorderEntry
->List
;
567 void ieee80211_indicate_packets(struct ieee80211_device
*ieee
, struct ieee80211_rxb
** prxbIndicateArray
,u8 index
)
572 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
573 for(j
= 0; j
<index
; j
++)
575 //added by amy for reorder
576 struct ieee80211_rxb
* prxb
= prxbIndicateArray
[j
];
577 for(i
= 0; i
<prxb
->nr_subframes
; i
++) {
578 struct sk_buff
*sub_skb
= prxb
->subframes
[i
];
580 /* convert hdr + possible LLC headers into Ethernet header */
581 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
582 if (sub_skb
->len
>= 8 &&
583 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
584 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
585 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
586 /* remove RFC1042 or Bridge-Tunnel encapsulation and
587 * replace EtherType */
588 skb_pull(sub_skb
, SNAP_SIZE
);
589 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
590 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
593 /* Leave Ethernet header part of hdr and full payload */
594 len
= htons(sub_skb
->len
);
595 memcpy(skb_push(sub_skb
, 2), &len
, 2);
596 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
597 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
599 //stats->rx_packets++;
600 //stats->rx_bytes += sub_skb->len;
602 /* Indicat the packets to upper layer */
604 //printk("0skb_len(%d)\n", skb->len);
605 sub_skb
->protocol
= eth_type_trans(sub_skb
, ieee
->dev
);
606 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
607 sub_skb
->dev
= ieee
->dev
;
608 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
609 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
610 ieee
->last_rx_ps_time
= jiffies
;
611 //printk("1skb_len(%d)\n", skb->len);
621 void RxReorderIndicatePacket( struct ieee80211_device
*ieee
,
622 struct ieee80211_rxb
* prxb
,
626 PRT_HIGH_THROUGHPUT pHTInfo
= ieee
->pHTInfo
;
627 PRX_REORDER_ENTRY pReorderEntry
= NULL
;
628 struct ieee80211_rxb
* prxbIndicateArray
[REORDER_WIN_SIZE
];
629 u8 WinSize
= pHTInfo
->RxReorderWinSize
;
630 u16 WinEnd
= (pTS
->RxIndicateSeq
+ WinSize
-1)%4096;
632 bool bMatchWinStart
= false, bPktInBuf
= false;
633 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__
,SeqNum
,pTS
->RxIndicateSeq
,WinSize
);
634 /* Rx Reorder initialize condition.*/
635 if(pTS
->RxIndicateSeq
== 0xffff) {
636 pTS
->RxIndicateSeq
= SeqNum
;
639 /* Drop out the packet which SeqNum is smaller than WinStart */
640 if(SN_LESS(SeqNum
, pTS
->RxIndicateSeq
)) {
641 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
642 pTS
->RxIndicateSeq
, SeqNum
);
643 pHTInfo
->RxReorderDropCounter
++;
646 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
647 dev_kfree_skb(prxb
->subframes
[i
]);
656 * Sliding window manipulation. Conditions includes:
657 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
658 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
660 if(SN_EQUAL(SeqNum
, pTS
->RxIndicateSeq
)) {
661 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
662 bMatchWinStart
= true;
663 } else if(SN_LESS(WinEnd
, SeqNum
)) {
664 if(SeqNum
>= (WinSize
- 1)) {
665 pTS
->RxIndicateSeq
= SeqNum
+ 1 -WinSize
;
667 pTS
->RxIndicateSeq
= 4095 - (WinSize
- (SeqNum
+1)) + 1;
669 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
673 * Indication process.
674 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
675 * with the SeqNum smaller than latest WinStart and buffer other packets.
677 /* For Rx Reorder condition:
678 * 1. All packets with SeqNum smaller than WinStart => Indicate
679 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
682 /* Current packet is going to be indicated.*/
683 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
684 pTS
->RxIndicateSeq
, SeqNum
);
685 prxbIndicateArray
[0] = prxb
;
686 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
689 /* Current packet is going to be inserted into pending list.*/
690 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
691 if(!list_empty(&ieee
->RxReorder_Unused_List
)) {
692 pReorderEntry
= (PRX_REORDER_ENTRY
)list_entry(ieee
->RxReorder_Unused_List
.next
,RX_REORDER_ENTRY
,List
);
693 list_del_init(&pReorderEntry
->List
);
695 /* Make a reorder entry and insert into a the packet list.*/
696 pReorderEntry
->SeqNum
= SeqNum
;
697 pReorderEntry
->prxb
= prxb
;
698 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
700 if(!AddReorderEntry(pTS
, pReorderEntry
)) {
701 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
702 __FUNCTION__
, pTS
->RxIndicateSeq
, SeqNum
);
703 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
706 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
707 dev_kfree_skb(prxb
->subframes
[i
]);
713 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,
714 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
719 * Packets are dropped if there is not enough reorder entries.
720 * This part shall be modified!! We can just indicate all the
721 * packets in buffer and get reorder entries.
723 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
726 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
727 dev_kfree_skb(prxb
->subframes
[i
]);
735 /* Check if there is any packet need indicate.*/
736 while(!list_empty(&pTS
->RxPendingPktList
)) {
737 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): start RREORDER indicate\n",__FUNCTION__
);
738 pReorderEntry
= (PRX_REORDER_ENTRY
)list_entry(pTS
->RxPendingPktList
.prev
,RX_REORDER_ENTRY
,List
);
739 if( SN_LESS(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
) ||
740 SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
742 /* This protect buffer from overflow. */
743 if(index
>= REORDER_WIN_SIZE
) {
744 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): Buffer overflow!! \n");
749 list_del_init(&pReorderEntry
->List
);
751 if(SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
752 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
754 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
755 prxbIndicateArray
[index
] = pReorderEntry
->prxb
;
756 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
759 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
766 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
768 // Cancel previous pending timer.
769 if (timer_pending(&pTS
->RxPktPendingTimer
))
770 del_timer_sync(&pTS
->RxPktPendingTimer
);
771 pTS
->RxTimeoutIndicateSeq
= 0xffff;
774 if(index
>REORDER_WIN_SIZE
){
775 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
778 ieee80211_indicate_packets(ieee
, prxbIndicateArray
, index
);
782 if(bPktInBuf
&& pTS
->RxTimeoutIndicateSeq
==0xffff) {
783 // Set new pending timer.
784 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): SET rx timeout timer\n", __FUNCTION__
);
785 pTS
->RxTimeoutIndicateSeq
= pTS
->RxIndicateSeq
;
786 mod_timer(&pTS
->RxPktPendingTimer
, jiffies
+ MSECS(pHTInfo
->RxReorderPendingTime
));
790 u8
parse_subframe(struct ieee80211_device
* ieee
,struct sk_buff
*skb
,
791 struct ieee80211_rx_stats
*rx_stats
,
792 struct ieee80211_rxb
*rxb
,u8
* src
,u8
* dst
)
794 struct ieee80211_hdr_3addr
*hdr
= (struct ieee80211_hdr_3addr
* )skb
->data
;
795 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
797 u16 LLCOffset
= sizeof(struct ieee80211_hdr_3addr
);
799 bool bIsAggregateFrame
= false;
800 u16 nSubframe_Length
;
801 u8 nPadding_Length
= 0;
804 struct sk_buff
*sub_skb
;
806 /* just for debug purpose */
807 SeqNum
= WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr
->seq_ctl
));
809 if((IEEE80211_QOS_HAS_SEQ(fc
))&&\
810 (((frameqos
*)(skb
->data
+ IEEE80211_3ADDR_LEN
))->field
.reserved
)) {
811 bIsAggregateFrame
= true;
814 if(IEEE80211_QOS_HAS_SEQ(fc
)) {
818 if(rx_stats
->bContainHTC
) {
819 LLCOffset
+= sHTCLng
;
821 //printk("ChkLength = %d\n", LLCOffset);
822 // Null packet, don't indicate it to upper layer
823 ChkLength
= LLCOffset
;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
825 if( skb
->len
<= ChkLength
) {
829 skb_pull(skb
, LLCOffset
);
830 ieee
->bIsAggregateFrame
= bIsAggregateFrame
;//added by amy for Leisure PS
832 if(!bIsAggregateFrame
) {
833 rxb
->nr_subframes
= 1;
835 rxb
->subframes
[0] = skb
;
837 rxb
->subframes
[0] = skb_copy(skb
, GFP_ATOMIC
);
840 memcpy(rxb
->src
,src
,ETH_ALEN
);
841 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
842 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
845 rxb
->nr_subframes
= 0;
846 memcpy(rxb
->src
,src
,ETH_ALEN
);
847 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
848 while(skb
->len
> ETHERNET_HEADER_SIZE
) {
849 /* Offset 12 denote 2 mac address */
850 nSubframe_Length
= *((u16
*)(skb
->data
+ 12));
851 //==m==>change the length order
852 nSubframe_Length
= (nSubframe_Length
>>8) + (nSubframe_Length
<<8);
854 if(skb
->len
<(ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
855 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
856 __FUNCTION__
,rxb
->nr_subframes
);
857 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__
, nSubframe_Length
);
858 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb
->len
,nSubframe_Length
);
859 printk("The Packet SeqNum is %d\n",SeqNum
);
863 /* move the data point to data content */
864 skb_pull(skb
, ETHERNET_HEADER_SIZE
);
867 sub_skb
= skb_clone(skb
, GFP_ATOMIC
);
868 sub_skb
->len
= nSubframe_Length
;
869 sub_skb
->tail
= sub_skb
->data
+ nSubframe_Length
;
871 /* Allocate new skb for releasing to upper layer */
872 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
873 skb_reserve(sub_skb
, 12);
874 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
875 memcpy(data_ptr
,skb
->data
,nSubframe_Length
);
877 rxb
->subframes
[rxb
->nr_subframes
++] = sub_skb
;
878 if(rxb
->nr_subframes
>= MAX_SUBFRAME_COUNT
) {
879 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
882 skb_pull(skb
,nSubframe_Length
);
885 nPadding_Length
= 4 - ((nSubframe_Length
+ ETHERNET_HEADER_SIZE
) % 4);
886 if(nPadding_Length
== 4) {
890 if(skb
->len
< nPadding_Length
) {
894 skb_pull(skb
,nPadding_Length
);
900 //{just for debug added by david
901 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
903 return rxb
->nr_subframes
;
907 /* All received frames are sent to this function. @skb contains the frame in
908 * IEEE 802.11 format, i.e., in the format it was sent over air.
909 * This function is called only as a tasklet (software IRQ). */
910 int ieee80211_rtl_rx(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
911 struct ieee80211_rx_stats
*rx_stats
)
913 struct net_device
*dev
= ieee
->dev
;
914 struct ieee80211_hdr_4addr
*hdr
;
915 //struct ieee80211_hdr_3addrqos *hdr;
918 u16 fc
, type
, stype
, sc
;
919 struct net_device_stats
*stats
;
923 //added by amy for reorder
926 PRX_TS_RECORD pTS
= NULL
;
927 bool unicast_packet
= false;
928 //bool bIsAggregateFrame = false;
929 //added by amy for reorder
931 struct net_device
*wds
= NULL
;
932 struct sk_buff
*skb2
= NULL
;
933 struct net_device
*wds
= NULL
;
934 int frame_authorized
= 0;
935 int from_assoc_ap
= 0;
942 struct ieee80211_crypt_data
*crypt
= NULL
;
946 struct ieee80211_rxb
* rxb
= NULL
;
947 // cheat the the hdr type
948 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
949 stats
= &ieee
->stats
;
952 printk(KERN_INFO
"%s: SKB length < 10\n",
957 fc
= le16_to_cpu(hdr
->frame_ctl
);
958 type
= WLAN_FC_GET_TYPE(fc
);
959 stype
= WLAN_FC_GET_STYPE(fc
);
960 sc
= le16_to_cpu(hdr
->seq_ctl
);
962 frag
= WLAN_GET_SEQ_FRAG(sc
);
963 hdrlen
= ieee80211_get_hdrlen(fc
);
965 if(HTCCheck(ieee
, skb
->data
))
968 printk("find HTCControl\n");
970 rx_stats
->bContainHTC
= 1;
973 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
975 #if WIRELESS_EXT > 15
976 /* Put this code here so that we avoid duplicating it in all
977 * Rx paths. - Jean II */
978 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
979 /* If spy monitoring on */
980 if (iface
->spy_data
.spy_number
> 0) {
981 struct iw_quality wstats
;
982 wstats
.level
= rx_stats
->rssi
;
983 wstats
.noise
= rx_stats
->noise
;
984 wstats
.updated
= 6; /* No qual value */
985 /* Update spy records */
986 wireless_spy_update(dev
, hdr
->addr2
, &wstats
);
988 #endif /* IW_WIRELESS_SPY */
989 #endif /* WIRELESS_EXT > 15 */
990 hostap_update_rx_stats(local
->ap
, hdr
, rx_stats
);
993 #if WIRELESS_EXT > 15
994 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
995 ieee80211_monitor_rx(ieee
, skb
, rx_stats
);
997 stats
->rx_bytes
+= skb
->len
;
1001 if (ieee
->host_decrypt
) {
1003 if (skb
->len
>= hdrlen
+ 3)
1004 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1005 crypt
= ieee
->crypt
[idx
];
1009 /* Use station specific key to override default keys if the
1010 * receiver address is a unicast address ("individual RA"). If
1011 * bcrx_sta_key parameter is set, station specific key is used
1012 * even with broad/multicast targets (this is against IEEE
1013 * 802.11, but makes it easier to use different keys with
1014 * stations that do not support WEP key mapping). */
1016 if (!(hdr
->addr1
[0] & 0x01) || local
->bcrx_sta_key
)
1017 (void) hostap_handle_sta_crypto(local
, hdr
, &crypt
,
1021 /* allow NULL decrypt to indicate an station specific override
1022 * for default encryption */
1023 if (crypt
&& (crypt
->ops
== NULL
||
1024 crypt
->ops
->decrypt_mpdu
== NULL
))
1027 if (!crypt
&& (fc
& IEEE80211_FCTL_WEP
)) {
1028 /* This seems to be triggered by some (multicast?)
1029 * frames from other than current BSS, so just drop the
1030 * frames silently instead of filling system log with
1032 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1035 ieee
->ieee_stats
.rx_discards_undecryptable
++;
1040 if (skb
->len
< IEEE80211_DATA_HDR3_LEN
)
1043 // if QoS enabled, should check the sequence for each of the AC
1044 if( (ieee
->pHTInfo
->bCurRxReorderEnable
== false) || !ieee
->current_network
.qos_data
.active
|| !IsDataFrame(skb
->data
) || IsLegacyDataFrame(skb
->data
)){
1045 if (is_duplicate_packet(ieee
, hdr
))
1051 PRX_TS_RECORD pRxTS
= NULL
;
1052 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1055 (PTS_COMMON_INFO
*) &pRxTS
,
1057 (u8
)Frame_QoSTID((u8
*)(skb
->data
)),
1062 // 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));
1063 if( (fc
& (1<<11)) &&
1064 (frag
== pRxTS
->RxLastFragNum
) &&
1065 (WLAN_GET_SEQ_SEQ(sc
) == pRxTS
->RxLastSeqNum
) )
1071 pRxTS
->RxLastFragNum
= frag
;
1072 pRxTS
->RxLastSeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1077 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "%s(): No TS!! Skip the check!!\n",__FUNCTION__
);
1081 if (type
== IEEE80211_FTYPE_MGMT
) {
1084 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1085 if (ieee80211_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
1091 /* Data frame - extract src/dst addresses */
1092 switch (fc
& (IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
)) {
1093 case IEEE80211_FCTL_FROMDS
:
1094 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1095 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
1096 memcpy(bssid
, hdr
->addr2
, ETH_ALEN
);
1098 case IEEE80211_FCTL_TODS
:
1099 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1100 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1101 memcpy(bssid
, hdr
->addr1
, ETH_ALEN
);
1103 case IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
:
1104 if (skb
->len
< IEEE80211_DATA_HDR4_LEN
)
1106 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1107 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
1108 memcpy(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
1111 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1112 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1113 memcpy(bssid
, hdr
->addr3
, ETH_ALEN
);
1118 if (hostap_rx_frame_wds(ieee
, hdr
, fc
, &wds
))
1121 skb
->dev
= dev
= wds
;
1122 stats
= hostap_get_stats(dev
);
1125 if (ieee
->iw_mode
== IW_MODE_MASTER
&& !wds
&&
1126 (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) == IEEE80211_FCTL_FROMDS
&&
1128 memcmp(hdr
->addr2
, ieee
->assoc_ap_addr
, ETH_ALEN
) == 0) {
1129 /* Frame from BSSID of the AP for which we are a client */
1130 skb
->dev
= dev
= ieee
->stadev
;
1131 stats
= hostap_get_stats(dev
);
1136 dev
->last_rx
= jiffies
;
1139 if ((ieee
->iw_mode
== IW_MODE_MASTER
||
1140 ieee
->iw_mode
== IW_MODE_REPEAT
) &&
1142 switch (hostap_handle_sta_rx(ieee
, dev
, skb
, rx_stats
,
1144 case AP_RX_CONTINUE_NOT_AUTHORIZED
:
1145 frame_authorized
= 0;
1147 case AP_RX_CONTINUE
:
1148 frame_authorized
= 1;
1157 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1158 /* Nullfunc frames may have PS-bit set, so they must be passed to
1159 * hostap_handle_sta_rx() before being dropped here. */
1160 if (stype
!= IEEE80211_STYPE_DATA
&&
1161 stype
!= IEEE80211_STYPE_DATA_CFACK
&&
1162 stype
!= IEEE80211_STYPE_DATA_CFPOLL
&&
1163 stype
!= IEEE80211_STYPE_DATA_CFACKPOLL
&&
1164 stype
!= IEEE80211_STYPE_QOS_DATA
//add by David,2006.8.4
1166 if (stype
!= IEEE80211_STYPE_NULLFUNC
)
1167 IEEE80211_DEBUG_DROP(
1168 "RX: dropped data frame "
1169 "with no data (type=0x%02x, "
1170 "subtype=0x%02x, len=%d)\n",
1171 type
, stype
, skb
->len
);
1174 if (memcmp(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
))
1178 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && (ieee
->sta_sleep
== 1)
1179 && (ieee
->polling
)) {
1180 if (WLAN_FC_MORE_DATA(fc
)) {
1181 /* more data bit is set, let's request a new frame from the AP */
1182 ieee80211_sta_ps_send_pspoll_frame(ieee
);
1184 ieee
->polling
= false;
1189 ieee
->need_sw_enc
= 0;
1191 if((!rx_stats
->Decrypted
)){
1192 ieee
->need_sw_enc
= 1;
1195 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1197 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
1198 (keyidx
= ieee80211_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0)
1200 printk("decrypt frame error\n");
1205 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1207 /* skb: hdr + (possibly fragmented) plaintext payload */
1208 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1209 if ((frag
!= 0 || (fc
& IEEE80211_FCTL_MOREFRAGS
))) {
1211 struct sk_buff
*frag_skb
= ieee80211_frag_cache_get(ieee
, hdr
);
1212 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
1215 IEEE80211_DEBUG(IEEE80211_DL_RX
| IEEE80211_DL_FRAG
,
1216 "Rx cannot get skb from fragment "
1217 "cache (morefrag=%d seq=%u frag=%u)\n",
1218 (fc
& IEEE80211_FCTL_MOREFRAGS
) != 0,
1219 WLAN_GET_SEQ_SEQ(sc
), frag
);
1226 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
1227 printk(KERN_WARNING
"%s: host decrypted and "
1228 "reassembled frame did not fit skb\n",
1230 ieee80211_frag_cache_invalidate(ieee
, hdr
);
1235 /* copy first fragment (including full headers) into
1236 * beginning of the fragment cache skb */
1237 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
1239 /* append frame payload to the end of the fragment
1241 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
1244 dev_kfree_skb_any(skb
);
1247 if (fc
& IEEE80211_FCTL_MOREFRAGS
) {
1248 /* more fragments expected - leave the skb in fragment
1249 * cache for now; it will be delivered to upper layers
1250 * after all fragments have been received */
1254 /* this was the last fragment and the frame will be
1255 * delivered, so remove skb from fragment cache */
1257 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1258 ieee80211_frag_cache_invalidate(ieee
, hdr
);
1261 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1262 * encrypted/authenticated */
1263 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
1264 ieee80211_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
))
1266 printk("==>decrypt msdu error\n");
1270 //added by amy for AP roaming
1271 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
++;
1272 ieee
->LinkDetectInfo
.NumRxOkInPeriod
++;
1274 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1275 if((!is_multicast_ether_addr(hdr
->addr1
)) && (!is_broadcast_ether_addr(hdr
->addr1
)))
1276 unicast_packet
= true;
1278 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
) {
1279 if (/*ieee->ieee802_1x &&*/
1280 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1282 #ifdef CONFIG_IEEE80211_DEBUG
1283 /* pass unencrypted EAPOL frames even if encryption is
1285 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1287 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1288 eap_get_type(eap
->type
));
1291 IEEE80211_DEBUG_DROP(
1292 "encryption configured, but RX "
1293 "frame not encrypted (SA=%pM)\n",
1299 #ifdef CONFIG_IEEE80211_DEBUG
1300 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) &&
1301 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1302 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1304 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1305 eap_get_type(eap
->type
));
1309 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
&&
1310 !ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1311 IEEE80211_DEBUG_DROP(
1312 "dropped unencrypted RX data "
1314 " (drop_unencrypted=1)\n",
1319 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1320 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1323 //added by amy for reorder
1324 if(ieee
->current_network
.qos_data
.active
&& IsQoSDataFrame(skb
->data
)
1325 && !is_multicast_ether_addr(hdr
->addr1
) && !is_broadcast_ether_addr(hdr
->addr1
))
1327 TID
= Frame_QoSTID(skb
->data
);
1328 SeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1329 GetTs(ieee
,(PTS_COMMON_INFO
*) &pTS
,hdr
->addr2
,TID
,RX_DIR
,true);
1330 if(TID
!=0 && TID
!=3)
1332 ieee
->bis_any_nonbepkts
= true;
1335 //added by amy for reorder
1336 /* skb: hdr + (possible reassembled) full plaintext payload */
1337 payload
= skb
->data
+ hdrlen
;
1338 //ethertype = (payload[6] << 8) | payload[7];
1339 rxb
= kmalloc(sizeof(struct ieee80211_rxb
), GFP_ATOMIC
);
1342 IEEE80211_DEBUG(IEEE80211_DL_ERR
,"%s(): kmalloc rxb error\n",__FUNCTION__
);
1345 /* to parse amsdu packets */
1346 /* qos data packets & reserved bit is 1 */
1347 if(parse_subframe(ieee
, skb
,rx_stats
,rxb
,src
,dst
) == 0) {
1348 /* only to free rxb, and not submit the packets to upper layer */
1349 for(i
=0; i
< rxb
->nr_subframes
; i
++) {
1350 dev_kfree_skb(rxb
->subframes
[i
]);
1360 if (type
== IEEE80211_FTYPE_DATA
)
1363 if(ieee
->bIsAggregateFrame
)
1364 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+=rxb
->nr_subframes
;
1366 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
++;
1368 // 2009.03.03 Leave DC mode immediately when detect high traffic
1369 // DbgPrint("ending Seq %d\n", Frame_SeqNum(pduOS));
1370 if((ieee
->state
== IEEE80211_LINKED
) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/)
1372 if( ((ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+ieee
->LinkDetectInfo
.NumTxOkInPeriod
) > 8 ) ||
1373 (ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
> 2) )
1375 if(ieee
->LeisurePSLeave
)
1376 ieee
->LeisurePSLeave(dev
);
1383 ieee
->last_rx_ps_time
= jiffies
;
1384 //added by amy for reorder
1385 if(ieee
->pHTInfo
->bCurRxReorderEnable
== false ||pTS
== NULL
){
1386 //added by amy for reorder
1387 for(i
= 0; i
<rxb
->nr_subframes
; i
++) {
1388 struct sk_buff
*sub_skb
= rxb
->subframes
[i
];
1391 /* convert hdr + possible LLC headers into Ethernet header */
1392 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
1393 if (sub_skb
->len
>= 8 &&
1394 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
1395 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1396 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
1397 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1398 * replace EtherType */
1399 skb_pull(sub_skb
, SNAP_SIZE
);
1400 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1401 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1404 /* Leave Ethernet header part of hdr and full payload */
1405 len
= htons(sub_skb
->len
);
1406 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1407 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1408 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1411 stats
->rx_packets
++;
1412 stats
->rx_bytes
+= sub_skb
->len
;
1413 if(is_multicast_ether_addr(dst
)) {
1417 /* Indicat the packets to upper layer */
1418 //printk("0skb_len(%d)\n", skb->len);
1419 sub_skb
->protocol
= eth_type_trans(sub_skb
, dev
);
1420 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
1422 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
1423 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1424 //printk("1skb_len(%d)\n", skb->len);
1434 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__
);
1435 RxReorderIndicatePacket(ieee
, rxb
, pTS
, SeqNum
);
1444 hostap_handle_sta_release(sta
);
1454 stats
->rx_dropped
++;
1456 /* Returning 0 indicates to caller that we have not handled the SKB--
1457 * so it is still allocated and can be used again by underlying
1458 * hardware as a DMA target */
1462 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1464 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
1467 * Make ther structure we read from the beacon packet has
1470 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1471 *info_element
, int sub_type
)
1474 if (info_element
->qui_subtype
!= sub_type
)
1476 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
1478 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
1480 if (info_element
->version
!= QOS_VERSION_1
)
1488 * Parse a QoS parameter element
1490 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1491 *element_param
, struct ieee80211_info_element
1495 u16 size
= sizeof(struct ieee80211_qos_parameter_info
) - 2;
1497 if ((info_element
== NULL
) || (element_param
== NULL
))
1500 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
1501 memcpy(element_param
->info_element
.qui
, info_element
->data
,
1503 element_param
->info_element
.elementID
= info_element
->id
;
1504 element_param
->info_element
.length
= info_element
->len
;
1508 ret
= ieee80211_verify_qos_info(&element_param
->info_element
,
1509 QOS_OUI_PARAM_SUB_TYPE
);
1514 * Parse a QoS information element
1516 static int ieee80211_read_qos_info_element(struct
1517 ieee80211_qos_information_element
1518 *element_info
, struct ieee80211_info_element
1522 u16 size
= sizeof(struct ieee80211_qos_information_element
) - 2;
1524 if (element_info
== NULL
)
1526 if (info_element
== NULL
)
1529 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
1530 memcpy(element_info
->qui
, info_element
->data
,
1532 element_info
->elementID
= info_element
->id
;
1533 element_info
->length
= info_element
->len
;
1538 ret
= ieee80211_verify_qos_info(element_info
,
1539 QOS_OUI_INFO_SUB_TYPE
);
1545 * Write QoS parameters from the ac parameters.
1547 static int ieee80211_qos_convert_ac_to_parameters(struct
1548 ieee80211_qos_parameter_info
1550 ieee80211_qos_parameters
1555 struct ieee80211_qos_ac_parameter
*ac_params
;
1560 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1561 ac_params
= &(param_elm
->ac_params_record
[i
]);
1563 aci
= (ac_params
->aci_aifsn
& 0x60) >> 5;
1565 if(aci
>= QOS_QUEUE_NUM
)
1567 qos_param
->aifs
[aci
] = (ac_params
->aci_aifsn
) & 0x0f;
1569 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1570 qos_param
->aifs
[aci
] = (qos_param
->aifs
[aci
] < 2) ? 2:qos_param
->aifs
[aci
];
1572 qos_param
->cw_min
[aci
] = ac_params
->ecw_min_max
& 0x0F;
1574 qos_param
->cw_max
[aci
] = (ac_params
->ecw_min_max
& 0xF0) >> 4;
1576 qos_param
->flag
[aci
] =
1577 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1578 qos_param
->tx_op_limit
[aci
] = le16_to_cpu(ac_params
->tx_op_limit
);
1584 * we have a generic data element which it may contain QoS information or
1585 * parameters element. check the information element length to decide
1586 * which type to read
1588 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1590 struct ieee80211_network
*network
)
1593 struct ieee80211_qos_parameters
*qos_param
= NULL
;
1594 struct ieee80211_qos_information_element qos_info_element
;
1596 rc
= ieee80211_read_qos_info_element(&qos_info_element
, info_element
);
1599 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1600 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1602 struct ieee80211_qos_parameter_info param_element
;
1604 rc
= ieee80211_read_qos_param_element(¶m_element
,
1607 qos_param
= &(network
->qos_data
.parameters
);
1608 ieee80211_qos_convert_ac_to_parameters(¶m_element
,
1610 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1611 network
->qos_data
.param_count
=
1612 param_element
.info_element
.ac_info
& 0x0F;
1617 IEEE80211_DEBUG_QOS("QoS is supported\n");
1618 network
->qos_data
.supported
= 1;
1623 #ifdef CONFIG_IEEE80211_DEBUG
1624 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1626 static const char *get_info_element_string(u16 id
)
1631 MFIE_STRING(FH_SET
);
1632 MFIE_STRING(DS_SET
);
1633 MFIE_STRING(CF_SET
);
1635 MFIE_STRING(IBSS_SET
);
1636 MFIE_STRING(COUNTRY
);
1637 MFIE_STRING(HOP_PARAMS
);
1638 MFIE_STRING(HOP_TABLE
);
1639 MFIE_STRING(REQUEST
);
1640 MFIE_STRING(CHALLENGE
);
1641 MFIE_STRING(POWER_CONSTRAINT
);
1642 MFIE_STRING(POWER_CAPABILITY
);
1643 MFIE_STRING(TPC_REQUEST
);
1644 MFIE_STRING(TPC_REPORT
);
1645 MFIE_STRING(SUPP_CHANNELS
);
1647 MFIE_STRING(MEASURE_REQUEST
);
1648 MFIE_STRING(MEASURE_REPORT
);
1650 MFIE_STRING(IBSS_DFS
);
1651 // MFIE_STRING(ERP_INFO);
1653 MFIE_STRING(RATES_EX
);
1654 MFIE_STRING(GENERIC
);
1655 MFIE_STRING(QOS_PARAMETER
);
1662 #ifdef ENABLE_DOT11D
1663 static inline void ieee80211_extract_country_ie(
1664 struct ieee80211_device
*ieee
,
1665 struct ieee80211_info_element
*info_element
,
1666 struct ieee80211_network
*network
,
1670 if(IS_DOT11D_ENABLE(ieee
))
1672 if(info_element
->len
!= 0)
1674 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
1675 network
->CountryIeLen
= info_element
->len
;
1677 if(!IS_COUNTRY_IE_VALID(ieee
))
1679 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
1684 // 070305, rcnjko: I update country IE watch dog here because
1685 // some AP (e.g. Cisco 1242) don't include country IE in their
1686 // probe response frame.
1688 if(IS_EQUAL_CIE_SRC(ieee
, addr2
) )
1690 UPDATE_CIE_WATCHDOG(ieee
);
1697 int ieee80211_parse_info_param(struct ieee80211_device
*ieee
,
1698 struct ieee80211_info_element
*info_element
,
1700 struct ieee80211_network
*network
,
1701 struct ieee80211_rx_stats
*stats
)
1705 u16 tmp_htcap_len
=0;
1706 u16 tmp_htinfo_len
=0;
1707 u16 ht_realtek_agg_len
=0;
1708 u8 ht_realtek_agg_buf
[MAX_IE_LEN
];
1709 // u16 broadcom_len = 0;
1710 #ifdef CONFIG_IEEE80211_DEBUG
1715 while (length
>= sizeof(*info_element
)) {
1716 if (sizeof(*info_element
) + info_element
->len
> length
) {
1717 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1718 "info_element->len + 2 > left : "
1719 "info_element->len+2=%zd left=%d, id=%d.\n",
1721 sizeof(*info_element
),
1722 length
, info_element
->id
);
1723 /* We stop processing but don't return an error here
1724 * because some misbehaviour APs break this rule. ie.
1725 * Orinoco AP1000. */
1729 switch (info_element
->id
) {
1730 case MFIE_TYPE_SSID
:
1731 if (ieee80211_is_empty_essid(info_element
->data
,
1732 info_element
->len
)) {
1733 network
->flags
|= NETWORK_EMPTY_ESSID
;
1737 network
->ssid_len
= min(info_element
->len
,
1738 (u8
) IW_ESSID_MAX_SIZE
);
1739 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
1740 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1741 memset(network
->ssid
+ network
->ssid_len
, 0,
1742 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1744 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1745 network
->ssid
, network
->ssid_len
);
1748 case MFIE_TYPE_RATES
:
1749 #ifdef CONFIG_IEEE80211_DEBUG
1752 network
->rates_len
= min(info_element
->len
,
1754 for (i
= 0; i
< network
->rates_len
; i
++) {
1755 network
->rates
[i
] = info_element
->data
[i
];
1756 #ifdef CONFIG_IEEE80211_DEBUG
1757 p
+= snprintf(p
, sizeof(rates_str
) -
1758 (p
- rates_str
), "%02X ",
1761 if (ieee80211_is_ofdm_rate
1762 (info_element
->data
[i
])) {
1763 network
->flags
|= NETWORK_HAS_OFDM
;
1764 if (info_element
->data
[i
] &
1765 IEEE80211_BASIC_RATE_MASK
)
1771 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1772 rates_str
, network
->rates_len
);
1775 case MFIE_TYPE_RATES_EX
:
1776 #ifdef CONFIG_IEEE80211_DEBUG
1779 network
->rates_ex_len
= min(info_element
->len
,
1780 MAX_RATES_EX_LENGTH
);
1781 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1782 network
->rates_ex
[i
] = info_element
->data
[i
];
1783 #ifdef CONFIG_IEEE80211_DEBUG
1784 p
+= snprintf(p
, sizeof(rates_str
) -
1785 (p
- rates_str
), "%02X ",
1788 if (ieee80211_is_ofdm_rate
1789 (info_element
->data
[i
])) {
1790 network
->flags
|= NETWORK_HAS_OFDM
;
1791 if (info_element
->data
[i
] &
1792 IEEE80211_BASIC_RATE_MASK
)
1798 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1799 rates_str
, network
->rates_ex_len
);
1802 case MFIE_TYPE_DS_SET
:
1803 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1804 info_element
->data
[0]);
1805 network
->channel
= info_element
->data
[0];
1808 case MFIE_TYPE_FH_SET
:
1809 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1812 case MFIE_TYPE_CF_SET
:
1813 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1817 if(info_element
->len
< 4)
1820 network
->tim
.tim_count
= info_element
->data
[0];
1821 network
->tim
.tim_period
= info_element
->data
[1];
1823 network
->dtim_period
= info_element
->data
[1];
1824 if(ieee
->state
!= IEEE80211_LINKED
)
1826 //we use jiffies for legacy Power save
1827 network
->last_dtim_sta_time
[0] = jiffies
;
1828 network
->last_dtim_sta_time
[1] = stats
->mac_time
[1];
1830 network
->dtim_data
= IEEE80211_DTIM_VALID
;
1832 if(info_element
->data
[0] != 0)
1835 if(info_element
->data
[2] & 1)
1836 network
->dtim_data
|= IEEE80211_DTIM_MBCAST
;
1838 offset
= (info_element
->data
[2] >> 1)*2;
1840 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1842 if(ieee
->assoc_id
< 8*offset
||
1843 ieee
->assoc_id
> 8*(offset
+ info_element
->len
-3))
1847 offset
= (ieee
->assoc_id
/ 8) - offset
;// + ((aid % 8)? 0 : 1) ;
1849 if(info_element
->data
[3+offset
] & (1<<(ieee
->assoc_id
%8)))
1850 network
->dtim_data
|= IEEE80211_DTIM_UCAST
;
1852 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1856 network
->erp_value
= info_element
->data
[0];
1857 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1858 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1859 network
->erp_value
);
1861 case MFIE_TYPE_IBSS_SET
:
1862 network
->atim_window
= info_element
->data
[0];
1863 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1864 network
->atim_window
);
1867 case MFIE_TYPE_CHALLENGE
:
1868 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1871 case MFIE_TYPE_GENERIC
:
1872 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1874 if (!ieee80211_parse_qos_info_param_IE(info_element
,
1878 if (info_element
->len
>= 4 &&
1879 info_element
->data
[0] == 0x00 &&
1880 info_element
->data
[1] == 0x50 &&
1881 info_element
->data
[2] == 0xf2 &&
1882 info_element
->data
[3] == 0x01) {
1883 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1885 memcpy(network
->wpa_ie
, info_element
,
1886 network
->wpa_ie_len
);
1891 if (info_element
->len
== 7 &&
1892 info_element
->data
[0] == 0x00 &&
1893 info_element
->data
[1] == 0xe0 &&
1894 info_element
->data
[2] == 0x4c &&
1895 info_element
->data
[3] == 0x01 &&
1896 info_element
->data
[4] == 0x02) {
1897 network
->Turbo_Enable
= 1;
1901 //for HTcap and HTinfo parameters
1902 if(tmp_htcap_len
== 0){
1903 if(info_element
->len
>= 4 &&
1904 info_element
->data
[0] == 0x00 &&
1905 info_element
->data
[1] == 0x90 &&
1906 info_element
->data
[2] == 0x4c &&
1907 info_element
->data
[3] == 0x033){
1909 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1910 if(tmp_htcap_len
!= 0){
1911 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1912 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
1913 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
1914 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
1917 if(tmp_htcap_len
!= 0)
1918 network
->bssht
.bdSupportHT
= true;
1920 network
->bssht
.bdSupportHT
= false;
1924 if(tmp_htinfo_len
== 0){
1925 if(info_element
->len
>= 4 &&
1926 info_element
->data
[0] == 0x00 &&
1927 info_element
->data
[1] == 0x90 &&
1928 info_element
->data
[2] == 0x4c &&
1929 info_element
->data
[3] == 0x034){
1931 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1932 if(tmp_htinfo_len
!= 0){
1933 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1935 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
1936 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
1937 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
1945 if(ieee
->aggregation
){
1946 if(network
->bssht
.bdSupportHT
){
1947 if(info_element
->len
>= 4 &&
1948 info_element
->data
[0] == 0x00 &&
1949 info_element
->data
[1] == 0xe0 &&
1950 info_element
->data
[2] == 0x4c &&
1951 info_element
->data
[3] == 0x02){
1953 ht_realtek_agg_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1954 memcpy(ht_realtek_agg_buf
,info_element
->data
,info_element
->len
);
1957 if(ht_realtek_agg_len
>= 5){
1958 network
->bssht
.bdRT2RTAggregation
= true;
1960 if((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & 0x02))
1961 network
->bssht
.bdRT2RTLongSlotTime
= true;
1967 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1969 if((info_element
->len
>= 3 &&
1970 info_element
->data
[0] == 0x00 &&
1971 info_element
->data
[1] == 0x05 &&
1972 info_element
->data
[2] == 0xb5) ||
1973 (info_element
->len
>= 3 &&
1974 info_element
->data
[0] == 0x00 &&
1975 info_element
->data
[1] == 0x0a &&
1976 info_element
->data
[2] == 0xf7) ||
1977 (info_element
->len
>= 3 &&
1978 info_element
->data
[0] == 0x00 &&
1979 info_element
->data
[1] == 0x10 &&
1980 info_element
->data
[2] == 0x18)){
1982 network
->broadcom_cap_exist
= true;
1986 if(info_element
->len
>= 3 &&
1987 info_element
->data
[0] == 0x00 &&
1988 info_element
->data
[1] == 0x0c &&
1989 info_element
->data
[2] == 0x43)
1991 network
->ralink_cap_exist
= true;
1994 network
->ralink_cap_exist
= false;
1995 //added by amy for atheros AP
1996 if((info_element
->len
>= 3 &&
1997 info_element
->data
[0] == 0x00 &&
1998 info_element
->data
[1] == 0x03 &&
1999 info_element
->data
[2] == 0x7f) ||
2000 (info_element
->len
>= 3 &&
2001 info_element
->data
[0] == 0x00 &&
2002 info_element
->data
[1] == 0x13 &&
2003 info_element
->data
[2] == 0x74))
2005 //printk("========>%s(): athros AP is exist\n",__FUNCTION__);
2006 network
->atheros_cap_exist
= true;
2009 network
->atheros_cap_exist
= false;
2011 if ((info_element
->len
>= 3 &&
2012 info_element
->data
[0] == 0x00 &&
2013 info_element
->data
[1] == 0x50 &&
2014 info_element
->data
[2] == 0x43) )
2016 network
->marvell_cap_exist
= true;
2017 //printk("========>%s(): marvel AP is exist\n",__FUNCTION__);
2021 if(info_element
->len
>= 3 &&
2022 info_element
->data
[0] == 0x00 &&
2023 info_element
->data
[1] == 0x40 &&
2024 info_element
->data
[2] == 0x96)
2026 network
->cisco_cap_exist
= true;
2029 network
->cisco_cap_exist
= false;
2030 //added by amy for LEAP of cisco
2031 if(info_element
->len
> 4 &&
2032 info_element
->data
[0] == 0x00 &&
2033 info_element
->data
[1] == 0x40 &&
2034 info_element
->data
[2] == 0x96 &&
2035 info_element
->data
[3] == 0x01)
2037 if(info_element
->len
== 6)
2039 memcpy(network
->CcxRmState
, &info_element
[4], 2);
2040 if(network
->CcxRmState
[0] != 0)
2042 network
->bCcxRmEnable
= true;
2045 network
->bCcxRmEnable
= false;
2047 // CCXv4 Table 59-1 MBSSID Masks.
2049 network
->MBssidMask
= network
->CcxRmState
[1] & 0x07;
2050 if(network
->MBssidMask
!= 0)
2052 network
->bMBssidValid
= true;
2053 network
->MBssidMask
= 0xff << (network
->MBssidMask
);
2054 cpMacAddr(network
->MBssid
, network
->bssid
);
2055 network
->MBssid
[5] &= network
->MBssidMask
;
2059 network
->bMBssidValid
= false;
2064 network
->bCcxRmEnable
= false;
2067 if(info_element
->len
> 4 &&
2068 info_element
->data
[0] == 0x00 &&
2069 info_element
->data
[1] == 0x40 &&
2070 info_element
->data
[2] == 0x96 &&
2071 info_element
->data
[3] == 0x03)
2073 if(info_element
->len
== 5)
2075 network
->bWithCcxVerNum
= true;
2076 network
->BssCcxVerNumber
= info_element
->data
[4];
2080 network
->bWithCcxVerNum
= false;
2081 network
->BssCcxVerNumber
= 0;
2087 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2089 network
->rsn_ie_len
= min(info_element
->len
+ 2,
2091 memcpy(network
->rsn_ie
, info_element
,
2092 network
->rsn_ie_len
);
2095 //HT related element.
2096 case MFIE_TYPE_HT_CAP
:
2097 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2099 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2100 if(tmp_htcap_len
!= 0){
2101 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
2102 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
2103 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
2104 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
2106 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2107 // windows driver will update WMM parameters each beacon received once connected
2108 // Linux driver is a bit different.
2109 network
->bssht
.bdSupportHT
= true;
2112 network
->bssht
.bdSupportHT
= false;
2116 case MFIE_TYPE_HT_INFO
:
2117 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2119 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2121 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_IEEE
;
2122 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
2123 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
2124 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
2128 case MFIE_TYPE_AIRONET
:
2129 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2131 if(info_element
->len
>IE_CISCO_FLAG_POSITION
)
2133 network
->bWithAironetIE
= true;
2135 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2136 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2137 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2138 if( (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_MIC
) ||
2139 (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_PK
) )
2141 network
->bCkipSupported
= true;
2145 network
->bCkipSupported
= false;
2150 network
->bWithAironetIE
= false;
2151 network
->bCkipSupported
= false;
2154 case MFIE_TYPE_QOS_PARAMETER
:
2156 "QoS Error need to parse QOS_PARAMETER IE\n");
2159 #ifdef ENABLE_DOT11D
2160 case MFIE_TYPE_COUNTRY
:
2161 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2163 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2164 ieee80211_extract_country_ie(ieee
, info_element
, network
, network
->bssid
);//addr2 is same as addr3 when from an AP
2169 IEEE80211_DEBUG_MGMT
2170 ("Unsupported info element: %s (%d)\n",
2171 get_info_element_string(info_element
->id
),
2176 length
-= sizeof(*info_element
) + info_element
->len
;
2178 (struct ieee80211_info_element
*)&info_element
->
2179 data
[info_element
->len
];
2182 if(!network
->atheros_cap_exist
&& !network
->broadcom_cap_exist
&&
2183 !network
->cisco_cap_exist
&& !network
->ralink_cap_exist
&& !network
->bssht
.bdRT2RTAggregation
&&
2184 !network
->marvell_cap_exist
)
2186 network
->unknown_cap_exist
= true;
2190 network
->unknown_cap_exist
= false;
2195 static inline u8
ieee80211_SignalStrengthTranslate(
2201 // Step 1. Scale mapping.
2202 if(CurrSS
>= 71 && CurrSS
<= 100)
2204 RetSS
= 90 + ((CurrSS
- 70) / 3);
2206 else if(CurrSS
>= 41 && CurrSS
<= 70)
2208 RetSS
= 78 + ((CurrSS
- 40) / 3);
2210 else if(CurrSS
>= 31 && CurrSS
<= 40)
2212 RetSS
= 66 + (CurrSS
- 30);
2214 else if(CurrSS
>= 21 && CurrSS
<= 30)
2216 RetSS
= 54 + (CurrSS
- 20);
2218 else if(CurrSS
>= 5 && CurrSS
<= 20)
2220 RetSS
= 42 + (((CurrSS
- 5) * 2) / 3);
2222 else if(CurrSS
== 4)
2226 else if(CurrSS
== 3)
2230 else if(CurrSS
== 2)
2234 else if(CurrSS
== 1)
2242 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2244 // Step 2. Smoothing.
2246 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2251 long ieee80211_translate_todbm(u8 signal_strength_index
)// 0-100 index.
2253 long signal_power
; // in dBm.
2255 // Translate to dBm (x=0.5y-95).
2256 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
2259 return signal_power
;
2262 static inline int ieee80211_network_init(
2263 struct ieee80211_device
*ieee
,
2264 struct ieee80211_probe_response
*beacon
,
2265 struct ieee80211_network
*network
,
2266 struct ieee80211_rx_stats
*stats
)
2268 #ifdef CONFIG_IEEE80211_DEBUG
2269 //char rates_str[64];
2273 network
->qos_data
.active
= 0;
2274 network
->qos_data
.supported
= 0;
2275 network
->qos_data
.param_count
= 0;
2276 network
->qos_data
.old_param_count
= 0;
2278 /* Pull out fixed field data */
2279 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
2280 network
->capability
= le16_to_cpu(beacon
->capability
);
2281 network
->last_scanned
= jiffies
;
2282 network
->time_stamp
[0] = le32_to_cpu(beacon
->time_stamp
[0]);
2283 network
->time_stamp
[1] = le32_to_cpu(beacon
->time_stamp
[1]);
2284 network
->beacon_interval
= le32_to_cpu(beacon
->beacon_interval
);
2285 /* Where to pull this? beacon->listen_interval;*/
2286 network
->listen_interval
= 0x0A;
2287 network
->rates_len
= network
->rates_ex_len
= 0;
2288 network
->last_associate
= 0;
2289 network
->ssid_len
= 0;
2291 network
->atim_window
= 0;
2292 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
2294 network
->berp_info_valid
= false;
2295 network
->broadcom_cap_exist
= false;
2296 network
->ralink_cap_exist
= false;
2297 network
->atheros_cap_exist
= false;
2298 network
->marvell_cap_exist
= false;
2299 network
->cisco_cap_exist
= false;
2300 network
->unknown_cap_exist
= false;
2302 network
->Turbo_Enable
= 0;
2304 #ifdef ENABLE_DOT11D
2305 network
->CountryIeLen
= 0;
2306 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
2308 //Initialize HT parameters
2309 //ieee80211_ht_initialize(&network->bssht);
2310 HTInitializeBssDesc(&network
->bssht
);
2311 if (stats
->freq
== IEEE80211_52GHZ_BAND
) {
2312 /* for A band (No DS info) */
2313 network
->channel
= stats
->received_channel
;
2315 network
->flags
|= NETWORK_HAS_CCK
;
2317 network
->wpa_ie_len
= 0;
2318 network
->rsn_ie_len
= 0;
2320 if (ieee80211_parse_info_param
2321 (ieee
,beacon
->info_element
, stats
->len
- sizeof(*beacon
), network
, stats
))
2325 if (stats
->freq
== IEEE80211_52GHZ_BAND
)
2326 network
->mode
= IEEE_A
;
2328 if (network
->flags
& NETWORK_HAS_OFDM
)
2329 network
->mode
|= IEEE_G
;
2330 if (network
->flags
& NETWORK_HAS_CCK
)
2331 network
->mode
|= IEEE_B
;
2334 if (network
->mode
== 0) {
2335 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2337 escape_essid(network
->ssid
,
2343 if(network
->bssht
.bdSupportHT
){
2344 if(network
->mode
== IEEE_A
)
2345 network
->mode
= IEEE_N_5G
;
2346 else if(network
->mode
& (IEEE_G
| IEEE_B
))
2347 network
->mode
= IEEE_N_24G
;
2349 if (ieee80211_is_empty_essid(network
->ssid
, network
->ssid_len
))
2350 network
->flags
|= NETWORK_EMPTY_ESSID
;
2352 stats
->signal
= 30 + (stats
->SignalStrength
* 70) / 100;
2353 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2354 stats
->noise
= ieee80211_translate_todbm((u8
)(100-stats
->signal
)) -25;
2356 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
2361 static inline int is_same_network(struct ieee80211_network
*src
,
2362 struct ieee80211_network
*dst
, struct ieee80211_device
* ieee
)
2364 /* A network is only a duplicate if the channel, BSSID, ESSID
2365 * and the capability field (in particular IBSS and BSS) all match.
2366 * We treat all <hidden> with the same BSSID and channel
2368 return //((src->ssid_len == dst->ssid_len) &&
2369 (((src
->ssid_len
== dst
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) &&
2370 (src
->channel
== dst
->channel
) &&
2371 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
2372 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2373 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) &&
2374 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
2375 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
2376 ((src
->capability
& WLAN_CAPABILITY_BSS
) ==
2377 (dst
->capability
& WLAN_CAPABILITY_BSS
)));
2380 static inline void update_network(struct ieee80211_network
*dst
,
2381 struct ieee80211_network
*src
)
2386 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct ieee80211_rx_stats
));
2387 dst
->capability
= src
->capability
;
2388 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
2389 dst
->rates_len
= src
->rates_len
;
2390 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
2391 dst
->rates_ex_len
= src
->rates_ex_len
;
2392 if(src
->ssid_len
> 0)
2394 memset(dst
->ssid
, 0, dst
->ssid_len
);
2395 dst
->ssid_len
= src
->ssid_len
;
2396 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
2398 dst
->mode
= src
->mode
;
2399 dst
->flags
= src
->flags
;
2400 dst
->time_stamp
[0] = src
->time_stamp
[0];
2401 dst
->time_stamp
[1] = src
->time_stamp
[1];
2402 if (src
->flags
& NETWORK_HAS_ERP_VALUE
)
2404 dst
->erp_value
= src
->erp_value
;
2405 dst
->berp_info_valid
= src
->berp_info_valid
= true;
2407 dst
->beacon_interval
= src
->beacon_interval
;
2408 dst
->listen_interval
= src
->listen_interval
;
2409 dst
->atim_window
= src
->atim_window
;
2410 dst
->dtim_period
= src
->dtim_period
;
2411 dst
->dtim_data
= src
->dtim_data
;
2412 dst
->last_dtim_sta_time
[0] = src
->last_dtim_sta_time
[0];
2413 dst
->last_dtim_sta_time
[1] = src
->last_dtim_sta_time
[1];
2414 memcpy(&dst
->tim
, &src
->tim
, sizeof(struct ieee80211_tim_parameters
));
2416 dst
->bssht
.bdSupportHT
= src
->bssht
.bdSupportHT
;
2417 dst
->bssht
.bdRT2RTAggregation
= src
->bssht
.bdRT2RTAggregation
;
2418 dst
->bssht
.bdHTCapLen
= src
->bssht
.bdHTCapLen
;
2419 memcpy(dst
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapLen
);
2420 dst
->bssht
.bdHTInfoLen
= src
->bssht
.bdHTInfoLen
;
2421 memcpy(dst
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoLen
);
2422 dst
->bssht
.bdHTSpecVer
= src
->bssht
.bdHTSpecVer
;
2423 dst
->bssht
.bdRT2RTLongSlotTime
= src
->bssht
.bdRT2RTLongSlotTime
;
2424 dst
->broadcom_cap_exist
= src
->broadcom_cap_exist
;
2425 dst
->ralink_cap_exist
= src
->ralink_cap_exist
;
2426 dst
->atheros_cap_exist
= src
->atheros_cap_exist
;
2427 dst
->marvell_cap_exist
= src
->marvell_cap_exist
;
2428 dst
->cisco_cap_exist
= src
->cisco_cap_exist
;
2429 dst
->unknown_cap_exist
= src
->unknown_cap_exist
;
2430 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
2431 dst
->wpa_ie_len
= src
->wpa_ie_len
;
2432 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
2433 dst
->rsn_ie_len
= src
->rsn_ie_len
;
2435 dst
->last_scanned
= jiffies
;
2436 /* qos related parameters */
2437 //qos_active = src->qos_data.active;
2438 qos_active
= dst
->qos_data
.active
;
2439 //old_param = dst->qos_data.old_param_count;
2440 old_param
= dst
->qos_data
.param_count
;
2441 if(dst
->flags
& NETWORK_HAS_QOS_MASK
){
2442 //not update QOS paramter in beacon, as most AP will set all these parameter to 0.//WB
2443 // printk("====>%s(), aifs:%x, %x\n", __FUNCTION__, dst->qos_data.parameters.aifs[0], src->qos_data.parameters.aifs[0]);
2444 // memcpy(&dst->qos_data, &src->qos_data,
2445 // sizeof(struct ieee80211_qos_data));
2448 dst
->qos_data
.supported
= src
->qos_data
.supported
;
2449 dst
->qos_data
.param_count
= src
->qos_data
.param_count
;
2452 if(dst
->qos_data
.supported
== 1) {
2453 dst
->QoS_Enable
= 1;
2456 ("QoS the network %s is QoS supported\n",
2460 ("QoS the network is QoS supported\n");
2462 dst
->qos_data
.active
= qos_active
;
2463 dst
->qos_data
.old_param_count
= old_param
;
2465 /* dst->last_associate is not overwritten */
2466 dst
->wmm_info
= src
->wmm_info
; //sure to exist in beacon or probe response frame.
2467 if(src
->wmm_param
[0].ac_aci_acm_aifsn
|| \
2468 src
->wmm_param
[1].ac_aci_acm_aifsn
|| \
2469 src
->wmm_param
[2].ac_aci_acm_aifsn
|| \
2470 src
->wmm_param
[1].ac_aci_acm_aifsn
) {
2471 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
2473 //dst->QoS_Enable = src->QoS_Enable;
2475 dst
->Turbo_Enable
= src
->Turbo_Enable
;
2478 #ifdef ENABLE_DOT11D
2479 dst
->CountryIeLen
= src
->CountryIeLen
;
2480 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
2483 //added by amy for LEAP
2484 dst
->bWithAironetIE
= src
->bWithAironetIE
;
2485 dst
->bCkipSupported
= src
->bCkipSupported
;
2486 memcpy(dst
->CcxRmState
,src
->CcxRmState
,2);
2487 dst
->bCcxRmEnable
= src
->bCcxRmEnable
;
2488 dst
->MBssidMask
= src
->MBssidMask
;
2489 dst
->bMBssidValid
= src
->bMBssidValid
;
2490 memcpy(dst
->MBssid
,src
->MBssid
,6);
2491 dst
->bWithCcxVerNum
= src
->bWithCcxVerNum
;
2492 dst
->BssCcxVerNumber
= src
->BssCcxVerNumber
;
2496 static inline int is_beacon(__le16 fc
)
2498 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == IEEE80211_STYPE_BEACON
);
2501 static inline void ieee80211_process_probe_response(
2502 struct ieee80211_device
*ieee
,
2503 struct ieee80211_probe_response
*beacon
,
2504 struct ieee80211_rx_stats
*stats
)
2506 struct ieee80211_network network
;
2507 struct ieee80211_network
*target
;
2508 struct ieee80211_network
*oldest
= NULL
;
2509 #ifdef CONFIG_IEEE80211_DEBUG
2510 struct ieee80211_info_element
*info_element
= &beacon
->info_element
[0];
2512 unsigned long flags
;
2516 memset(&network
, 0, sizeof(struct ieee80211_network
));
2517 IEEE80211_DEBUG_SCAN(
2518 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2519 escape_essid(info_element
->data
, info_element
->len
),
2520 beacon
->header
.addr3
,
2521 (beacon
->capability
& (1<<0xf)) ? '1' : '0',
2522 (beacon
->capability
& (1<<0xe)) ? '1' : '0',
2523 (beacon
->capability
& (1<<0xd)) ? '1' : '0',
2524 (beacon
->capability
& (1<<0xc)) ? '1' : '0',
2525 (beacon
->capability
& (1<<0xb)) ? '1' : '0',
2526 (beacon
->capability
& (1<<0xa)) ? '1' : '0',
2527 (beacon
->capability
& (1<<0x9)) ? '1' : '0',
2528 (beacon
->capability
& (1<<0x8)) ? '1' : '0',
2529 (beacon
->capability
& (1<<0x7)) ? '1' : '0',
2530 (beacon
->capability
& (1<<0x6)) ? '1' : '0',
2531 (beacon
->capability
& (1<<0x5)) ? '1' : '0',
2532 (beacon
->capability
& (1<<0x4)) ? '1' : '0',
2533 (beacon
->capability
& (1<<0x3)) ? '1' : '0',
2534 (beacon
->capability
& (1<<0x2)) ? '1' : '0',
2535 (beacon
->capability
& (1<<0x1)) ? '1' : '0',
2536 (beacon
->capability
& (1<<0x0)) ? '1' : '0');
2538 if (ieee80211_network_init(ieee
, beacon
, &network
, stats
)) {
2539 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2540 escape_essid(info_element
->data
,
2542 beacon
->header
.addr3
,
2543 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2544 IEEE80211_STYPE_PROBE_RESP
?
2545 "PROBE RESPONSE" : "BEACON");
2549 #ifdef ENABLE_DOT11D
2550 // For Asus EeePc request,
2551 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2552 // wireless adapter should follow the country code.
2553 // (2) If there is no any country code in beacon,
2554 // then wireless adapter should do active scan from ch1~11 and
2555 // passive scan from ch12~14
2557 if( !IsLegalChannel(ieee
, network
.channel
) )
2559 if(ieee
->bGlobalDomain
)
2561 if (WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) == IEEE80211_STYPE_PROBE_RESP
)
2563 // Case 1: Country code
2564 if(IS_COUNTRY_IE_VALID(ieee
) )
2566 if( !IsLegalChannel(ieee
, network
.channel
) )
2568 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network
.channel
);
2572 // Case 2: No any country code.
2575 // Filter over channel ch12~14
2576 if(network
.channel
> 11)
2578 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network
.channel
);
2585 // Case 1: Country code
2586 if(IS_COUNTRY_IE_VALID(ieee
) )
2588 if( !IsLegalChannel(ieee
, network
.channel
) )
2590 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network
.channel
);
2594 // Case 2: No any country code.
2597 // Filter over channel ch12~14
2598 if(network
.channel
> 14)
2600 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network
.channel
);
2608 /* The network parsed correctly -- so now we scan our known networks
2609 * to see if we can find it in our list.
2611 * NOTE: This search is definitely not optimized. Once its doing
2612 * the "right thing" we'll optimize it for efficiency if
2615 /* Search for this entry in the list and update it if it is
2618 spin_lock_irqsave(&ieee
->lock
, flags
);
2620 if(is_same_network(&ieee
->current_network
, &network
, ieee
)) {
2621 update_network(&ieee
->current_network
, &network
);
2622 if((ieee
->current_network
.mode
== IEEE_N_24G
|| ieee
->current_network
.mode
== IEEE_G
)
2623 && ieee
->current_network
.berp_info_valid
){
2624 if(ieee
->current_network
.erp_value
& ERP_UseProtection
)
2625 ieee
->current_network
.buseprotection
= true;
2627 ieee
->current_network
.buseprotection
= false;
2629 if(is_beacon(beacon
->header
.frame_ctl
))
2631 if(ieee
->state
== IEEE80211_LINKED
)
2632 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
++;
2635 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& ieee
->current_network
.flags
);
2638 list_for_each_entry(target
, &ieee
->network_list
, list
) {
2639 if (is_same_network(target
, &network
, ieee
))
2641 if ((oldest
== NULL
) ||
2642 (target
->last_scanned
< oldest
->last_scanned
))
2646 /* If we didn't find a match, then get a new network slot to initialize
2647 * with this beacon's information */
2648 if (&target
->list
== &ieee
->network_list
) {
2649 if (list_empty(&ieee
->network_free_list
)) {
2650 /* If there are no more slots, expire the oldest */
2651 list_del(&oldest
->list
);
2653 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2655 escape_essid(target
->ssid
,
2659 /* Otherwise just pull from the free list */
2660 target
= list_entry(ieee
->network_free_list
.next
,
2661 struct ieee80211_network
, list
);
2662 list_del(ieee
->network_free_list
.next
);
2666 #ifdef CONFIG_IEEE80211_DEBUG
2667 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2668 escape_essid(network
.ssid
,
2671 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2672 IEEE80211_STYPE_PROBE_RESP
?
2673 "PROBE RESPONSE" : "BEACON");
2675 memcpy(target
, &network
, sizeof(*target
));
2676 list_add_tail(&target
->list
, &ieee
->network_list
);
2678 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2679 escape_essid(target
->ssid
,
2682 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2683 IEEE80211_STYPE_PROBE_RESP
?
2684 "PROBE RESPONSE" : "BEACON");
2686 /* we have an entry and we are going to update it. But this entry may
2687 * be already expired. In this case we do the same as we found a new
2688 * net and call the new_net handler
2690 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
);
2691 //YJ,add,080819,for hidden ap
2692 if(is_beacon(beacon
->header
.frame_ctl
) == 0)
2693 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& target
->flags
);
2694 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2695 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2696 if(((network
.flags
& NETWORK_EMPTY_ESSID
) == NETWORK_EMPTY_ESSID
) \
2697 && (((network
.ssid_len
> 0) && (strncmp(target
->ssid
, network
.ssid
, network
.ssid_len
)))\
2698 ||((ieee
->current_network
.ssid_len
== network
.ssid_len
)&&(strncmp(ieee
->current_network
.ssid
, network
.ssid
, network
.ssid_len
) == 0)&&(ieee
->state
== IEEE80211_NOLINK
))))
2700 //YJ,add,080819,for hidden ap,end
2702 update_network(target
, &network
);
2705 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2706 if (is_beacon(beacon
->header
.frame_ctl
)&&is_same_network(&ieee
->current_network
, &network
, ieee
)&&\
2707 (ieee
->state
== IEEE80211_LINKED
)) {
2708 if(ieee
->handle_beacon
!= NULL
) {
2709 ieee
->handle_beacon(ieee
->dev
,beacon
,&ieee
->current_network
);
2714 void ieee80211_rx_mgt(struct ieee80211_device
*ieee
,
2715 struct ieee80211_hdr_4addr
*header
,
2716 struct ieee80211_rx_stats
*stats
)
2719 if(WLAN_FC_GET_STYPE(header
->frame_ctl
) != IEEE80211_STYPE_PROBE_RESP
&&
2720 WLAN_FC_GET_STYPE(header
->frame_ctl
) != IEEE80211_STYPE_BEACON
)
2721 ieee
->last_rx_ps_time
= jiffies
;
2723 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
2725 case IEEE80211_STYPE_BEACON
:
2726 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2727 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2728 IEEE80211_DEBUG_SCAN("Beacon\n");
2729 ieee80211_process_probe_response(
2730 ieee
, (struct ieee80211_probe_response
*)header
, stats
);
2732 //printk("----------->%s()\n", __func__);
2733 if(ieee
->sta_sleep
|| (ieee
->ps
!= IEEE80211_PS_DISABLED
&&
2734 ieee
->iw_mode
== IW_MODE_INFRA
&&
2735 ieee
->state
== IEEE80211_LINKED
))
2737 tasklet_schedule(&ieee
->ps_task
);
2742 case IEEE80211_STYPE_PROBE_RESP
:
2743 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2744 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2745 IEEE80211_DEBUG_SCAN("Probe response\n");
2746 ieee80211_process_probe_response(
2747 ieee
, (struct ieee80211_probe_response
*)header
, stats
);