2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
14 ******************************************************************************
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
19 A special thanks goes to Realtek for their support !
21 ******************************************************************************/
24 #include <linux/compiler.h>
25 //#include <linux/config.h>
26 #include <linux/errno.h>
27 #include <linux/if_arp.h>
28 #include <linux/in6.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <linux/pci.h>
35 #include <linux/proc_fs.h>
36 #include <linux/skbuff.h>
37 #include <linux/slab.h>
38 #include <linux/tcp.h>
39 #include <linux/types.h>
40 #include <linux/version.h>
41 #include <linux/wireless.h>
42 #include <linux/etherdevice.h>
43 #include <asm/uaccess.h>
44 #include <linux/ctype.h>
46 #include "ieee80211.h"
50 static inline void ieee80211_monitor_rx(struct ieee80211_device
*ieee
,
52 struct ieee80211_rx_stats
*rx_stats
)
54 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
55 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
58 skb_reset_mac_header(skb
);
60 skb_pull(skb
, ieee80211_get_hdrlen(fc
));
61 skb
->pkt_type
= PACKET_OTHERHOST
;
62 skb
->protocol
= __constant_htons(ETH_P_80211_RAW
);
63 memset(skb
->cb
, 0, sizeof(skb
->cb
));
68 /* Called only as a tasklet (software IRQ) */
69 static struct ieee80211_frag_entry
*
70 ieee80211_frag_cache_find(struct ieee80211_device
*ieee
, unsigned int seq
,
71 unsigned int frag
, u8 tid
,u8
*src
, u8
*dst
)
73 struct ieee80211_frag_entry
*entry
;
76 for (i
= 0; i
< IEEE80211_FRAG_CACHE_LEN
; i
++) {
77 entry
= &ieee
->frag_cache
[tid
][i
];
78 if (entry
->skb
!= NULL
&&
79 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
81 "expiring fragment cache entry "
82 "seq=%u last_frag=%u\n",
83 entry
->seq
, entry
->last_frag
);
84 dev_kfree_skb_any(entry
->skb
);
88 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
89 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
90 memcmp(entry
->src_addr
, src
, ETH_ALEN
) == 0 &&
91 memcmp(entry
->dst_addr
, dst
, ETH_ALEN
) == 0)
98 /* Called only as a tasklet (software IRQ) */
99 static struct sk_buff
*
100 ieee80211_frag_cache_get(struct ieee80211_device
*ieee
,
101 struct ieee80211_hdr_4addr
*hdr
)
103 struct sk_buff
*skb
= NULL
;
104 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
105 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
106 unsigned int frag
= WLAN_GET_SEQ_FRAG(sc
);
107 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
108 struct ieee80211_frag_entry
*entry
;
109 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
110 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
113 if (((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
114 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
115 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
118 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
119 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
120 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
128 /* Reserve enough space to fit maximum frame length */
129 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
130 sizeof(struct ieee80211_hdr_4addr
) +
135 (IEEE80211_QOS_HAS_SEQ(fc
)?2:0) /* QOS Control */);
139 entry
= &ieee
->frag_cache
[tid
][ieee
->frag_next_idx
[tid
]];
140 ieee
->frag_next_idx
[tid
]++;
141 if (ieee
->frag_next_idx
[tid
] >= IEEE80211_FRAG_CACHE_LEN
)
142 ieee
->frag_next_idx
[tid
] = 0;
144 if (entry
->skb
!= NULL
)
145 dev_kfree_skb_any(entry
->skb
);
147 entry
->first_frag_time
= jiffies
;
149 entry
->last_frag
= frag
;
151 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
152 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
154 /* received a fragment of a frame for which the head fragment
155 * should have already been received */
156 entry
= ieee80211_frag_cache_find(ieee
, seq
, frag
, tid
,hdr
->addr2
,
159 entry
->last_frag
= frag
;
168 /* Called only as a tasklet (software IRQ) */
169 static int ieee80211_frag_cache_invalidate(struct ieee80211_device
*ieee
,
170 struct ieee80211_hdr_4addr
*hdr
)
172 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
173 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
174 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
175 struct ieee80211_frag_entry
*entry
;
176 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
177 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
180 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
181 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
182 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
185 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
186 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
187 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
194 entry
= ieee80211_frag_cache_find(ieee
, seq
, -1, tid
,hdr
->addr2
,
198 IEEE80211_DEBUG_FRAG(
199 "could not invalidate fragment cache "
200 "entry (seq=%u)\n", seq
);
210 /* ieee80211_rx_frame_mgtmt
212 * Responsible for handling management control frames
214 * Called by ieee80211_rx */
216 ieee80211_rx_frame_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
217 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
220 /* On the struct stats definition there is written that
221 * this is not mandatory.... but seems that the probe
222 * response parser uses it
224 struct ieee80211_hdr_3addr
* hdr
= (struct ieee80211_hdr_3addr
*)skb
->data
;
226 rx_stats
->len
= skb
->len
;
227 ieee80211_rx_mgt(ieee
,(struct ieee80211_hdr_4addr
*)skb
->data
,rx_stats
);
228 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
229 if ((memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
)))//use ADDR1 to perform address matching for Management frames
231 dev_kfree_skb_any(skb
);
235 ieee80211_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
237 dev_kfree_skb_any(skb
);
242 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
243 printk(KERN_DEBUG
"%s: Master mode not yet suppported.\n",
247 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
251 if (ieee
->hostapd
&& type
== IEEE80211_TYPE_MGMT
) {
252 if (stype
== WLAN_FC_STYPE_BEACON
&&
253 ieee
->iw_mode
== IW_MODE_MASTER
) {
254 struct sk_buff
*skb2
;
255 /* Process beacon frames also in kernel driver to
256 * update STA(AP) table statistics */
257 skb2
= skb_clone(skb
, GFP_ATOMIC
);
259 hostap_rx(skb2
->dev
, skb2
, rx_stats
);
262 /* send management frames to the user space daemon for
264 ieee
->apdevstats
.rx_packets
++;
265 ieee
->apdevstats
.rx_bytes
+= skb
->len
;
266 prism2_rx_80211(ieee
->apdev
, skb
, rx_stats
, PRISM2_RX_MGMT
);
270 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
271 if (type
!= WLAN_FC_TYPE_MGMT
&& type
!= WLAN_FC_TYPE_CTRL
) {
272 printk(KERN_DEBUG
"%s: unknown management frame "
273 "(type=0x%02x, stype=0x%02x) dropped\n",
274 skb
->dev
->name
, type
, stype
);
278 hostap_rx(skb
->dev
, skb
, rx_stats
);
282 printk(KERN_DEBUG
"%s: hostap_rx_frame_mgmt: management frame "
283 "received in non-Host AP mode\n", skb
->dev
->name
);
290 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
291 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
292 static unsigned char rfc1042_header
[] =
293 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
294 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
295 static unsigned char bridge_tunnel_header
[] =
296 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
297 /* No encapsulation header if EtherType < 0x600 (=length) */
299 /* Called by ieee80211_rx_frame_decrypt */
300 static int ieee80211_is_eapol_frame(struct ieee80211_device
*ieee
,
301 struct sk_buff
*skb
, size_t hdrlen
)
303 struct net_device
*dev
= ieee
->dev
;
305 struct ieee80211_hdr_4addr
*hdr
;
311 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
312 fc
= le16_to_cpu(hdr
->frame_ctl
);
314 /* check that the frame is unicast frame to us */
315 if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
316 IEEE80211_FCTL_TODS
&&
317 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
318 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
319 /* ToDS frame with own addr BSSID and DA */
320 } else if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
321 IEEE80211_FCTL_FROMDS
&&
322 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
323 /* FromDS frame with own addr as DA */
327 if (skb
->len
< 24 + 8)
330 /* check for port access entity Ethernet type */
331 // pos = skb->data + 24;
332 pos
= skb
->data
+ hdrlen
;
333 ethertype
= (pos
[6] << 8) | pos
[7];
334 if (ethertype
== ETH_P_PAE
)
340 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
342 ieee80211_rx_frame_decrypt(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
343 struct ieee80211_crypt_data
*crypt
)
345 struct ieee80211_hdr_4addr
*hdr
;
348 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
350 if (ieee
->hwsec_active
)
352 cb_desc
*tcb_desc
= (cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
353 tcb_desc
->bHwSec
= 1;
355 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
356 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
358 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
359 if (ieee
->tkip_countermeasures
&&
360 strcmp(crypt
->ops
->name
, "TKIP") == 0) {
361 if (net_ratelimit()) {
362 printk(KERN_DEBUG
"%s: TKIP countermeasures: dropped "
363 "received packet from %pM\n",
364 ieee
->dev
->name
, hdr
->addr2
);
370 atomic_inc(&crypt
->refcnt
);
371 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
372 atomic_dec(&crypt
->refcnt
);
374 IEEE80211_DEBUG_DROP(
375 "decryption failed (SA=%pM"
376 ") res=%d\n", hdr
->addr2
, res
);
378 IEEE80211_DEBUG_DROP("Decryption failed ICV "
379 "mismatch (key %d)\n",
380 skb
->data
[hdrlen
+ 3] >> 6);
381 ieee
->ieee_stats
.rx_discards_undecryptable
++;
389 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
391 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
392 int keyidx
, struct ieee80211_crypt_data
*crypt
)
394 struct ieee80211_hdr_4addr
*hdr
;
397 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
399 if (ieee
->hwsec_active
)
401 cb_desc
*tcb_desc
= (cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
402 tcb_desc
->bHwSec
= 1;
405 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
406 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
408 atomic_inc(&crypt
->refcnt
);
409 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
410 atomic_dec(&crypt
->refcnt
);
412 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
413 " (SA=%pM keyidx=%d)\n",
414 ieee
->dev
->name
, hdr
->addr2
, keyidx
);
422 /* this function is stolen from ipw2200 driver*/
423 #define IEEE_PACKET_RETRY_TIME (5*HZ)
424 static int is_duplicate_packet(struct ieee80211_device
*ieee
,
425 struct ieee80211_hdr_4addr
*header
)
427 u16 fc
= le16_to_cpu(header
->frame_ctl
);
428 u16 sc
= le16_to_cpu(header
->seq_ctl
);
429 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
430 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
431 u16
*last_seq
, *last_frag
;
432 unsigned long *last_time
;
433 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
434 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
439 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
440 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)header
;
441 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
444 } else if(IEEE80211_QOS_HAS_SEQ(fc
)) { //QoS
445 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)header
;
446 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
453 switch (ieee
->iw_mode
) {
457 struct ieee_ibss_seq
*entry
= NULL
;
458 u8
*mac
= header
->addr2
;
459 int index
= mac
[5] % IEEE_IBSS_MAC_HASH_SIZE
;
460 //for (pos = (head)->next; pos != (head); pos = pos->next)
461 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
462 list_for_each(p
, &ieee
->ibss_mac_hash
[index
]) {
463 entry
= list_entry(p
, struct ieee_ibss_seq
, list
);
464 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
467 // if (memcmp(entry->mac, mac, ETH_ALEN)){
468 if (p
== &ieee
->ibss_mac_hash
[index
]) {
469 entry
= kmalloc(sizeof(struct ieee_ibss_seq
), GFP_ATOMIC
);
471 printk(KERN_WARNING
"Cannot malloc new mac entry\n");
474 memcpy(entry
->mac
, mac
, ETH_ALEN
);
475 entry
->seq_num
[tid
] = seq
;
476 entry
->frag_num
[tid
] = frag
;
477 entry
->packet_time
[tid
] = jiffies
;
478 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
481 last_seq
= &entry
->seq_num
[tid
];
482 last_frag
= &entry
->frag_num
[tid
];
483 last_time
= &entry
->packet_time
[tid
];
488 last_seq
= &ieee
->last_rxseq_num
[tid
];
489 last_frag
= &ieee
->last_rxfrag_num
[tid
];
490 last_time
= &ieee
->last_packet_time
[tid
];
498 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
500 if ((*last_seq
== seq
) &&
501 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
502 if (*last_frag
== frag
){
503 //printk(KERN_WARNING "[1] go drop!\n");
507 if (*last_frag
+ 1 != frag
)
508 /* out-of-order fragment */
509 //printk(KERN_WARNING "[2] go drop!\n");
515 *last_time
= jiffies
;
519 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
527 PRX_REORDER_ENTRY pReorderEntry
530 struct list_head
*pList
= &pTS
->RxPendingPktList
;
531 while(pList
->next
!= &pTS
->RxPendingPktList
)
533 if( SN_LESS(pReorderEntry
->SeqNum
, ((PRX_REORDER_ENTRY
)list_entry(pList
->next
,RX_REORDER_ENTRY
,List
))->SeqNum
) )
537 else if( SN_EQUAL(pReorderEntry
->SeqNum
, ((PRX_REORDER_ENTRY
)list_entry(pList
->next
,RX_REORDER_ENTRY
,List
))->SeqNum
) )
546 pReorderEntry
->List
.next
= pList
->next
;
547 pReorderEntry
->List
.next
->prev
= &pReorderEntry
->List
;
548 pReorderEntry
->List
.prev
= pList
;
549 pList
->next
= &pReorderEntry
->List
;
554 void ieee80211_indicate_packets(struct ieee80211_device
*ieee
, struct ieee80211_rxb
** prxbIndicateArray
,u8 index
)
559 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
560 for(j
= 0; j
<index
; j
++)
562 //added by amy for reorder
563 struct ieee80211_rxb
* prxb
= prxbIndicateArray
[j
];
564 for(i
= 0; i
<prxb
->nr_subframes
; i
++) {
565 struct sk_buff
*sub_skb
= prxb
->subframes
[i
];
567 /* convert hdr + possible LLC headers into Ethernet header */
568 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
569 if (sub_skb
->len
>= 8 &&
570 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
571 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
572 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
573 /* remove RFC1042 or Bridge-Tunnel encapsulation and
574 * replace EtherType */
575 skb_pull(sub_skb
, SNAP_SIZE
);
576 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
577 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
580 /* Leave Ethernet header part of hdr and full payload */
581 len
= htons(sub_skb
->len
);
582 memcpy(skb_push(sub_skb
, 2), &len
, 2);
583 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
584 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
586 //stats->rx_packets++;
587 //stats->rx_bytes += sub_skb->len;
589 /* Indicat the packets to upper layer */
591 //printk("0skb_len(%d)\n", skb->len);
592 sub_skb
->protocol
= eth_type_trans(sub_skb
, ieee
->dev
);
593 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
594 sub_skb
->dev
= ieee
->dev
;
595 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
596 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
597 ieee
->last_rx_ps_time
= jiffies
;
598 //printk("1skb_len(%d)\n", skb->len);
608 void RxReorderIndicatePacket( struct ieee80211_device
*ieee
,
609 struct ieee80211_rxb
* prxb
,
613 PRT_HIGH_THROUGHPUT pHTInfo
= ieee
->pHTInfo
;
614 PRX_REORDER_ENTRY pReorderEntry
= NULL
;
615 struct ieee80211_rxb
* prxbIndicateArray
[REORDER_WIN_SIZE
];
616 u8 WinSize
= pHTInfo
->RxReorderWinSize
;
617 u16 WinEnd
= (pTS
->RxIndicateSeq
+ WinSize
-1)%4096;
619 bool bMatchWinStart
= false, bPktInBuf
= false;
620 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__
,SeqNum
,pTS
->RxIndicateSeq
,WinSize
);
621 /* Rx Reorder initialize condition.*/
622 if(pTS
->RxIndicateSeq
== 0xffff) {
623 pTS
->RxIndicateSeq
= SeqNum
;
626 /* Drop out the packet which SeqNum is smaller than WinStart */
627 if(SN_LESS(SeqNum
, pTS
->RxIndicateSeq
)) {
628 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
629 pTS
->RxIndicateSeq
, SeqNum
);
630 pHTInfo
->RxReorderDropCounter
++;
633 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
634 dev_kfree_skb(prxb
->subframes
[i
]);
643 * Sliding window manipulation. Conditions includes:
644 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
645 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
647 if(SN_EQUAL(SeqNum
, pTS
->RxIndicateSeq
)) {
648 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
649 bMatchWinStart
= true;
650 } else if(SN_LESS(WinEnd
, SeqNum
)) {
651 if(SeqNum
>= (WinSize
- 1)) {
652 pTS
->RxIndicateSeq
= SeqNum
+ 1 -WinSize
;
654 pTS
->RxIndicateSeq
= 4095 - (WinSize
- (SeqNum
+1)) + 1;
656 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
660 * Indication process.
661 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
662 * with the SeqNum smaller than latest WinStart and buffer other packets.
664 /* For Rx Reorder condition:
665 * 1. All packets with SeqNum smaller than WinStart => Indicate
666 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
669 /* Current packet is going to be indicated.*/
670 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
671 pTS
->RxIndicateSeq
, SeqNum
);
672 prxbIndicateArray
[0] = prxb
;
673 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
676 /* Current packet is going to be inserted into pending list.*/
677 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
678 if(!list_empty(&ieee
->RxReorder_Unused_List
)) {
679 pReorderEntry
= (PRX_REORDER_ENTRY
)list_entry(ieee
->RxReorder_Unused_List
.next
,RX_REORDER_ENTRY
,List
);
680 list_del_init(&pReorderEntry
->List
);
682 /* Make a reorder entry and insert into a the packet list.*/
683 pReorderEntry
->SeqNum
= SeqNum
;
684 pReorderEntry
->prxb
= prxb
;
685 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
687 if(!AddReorderEntry(pTS
, pReorderEntry
)) {
688 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
689 __FUNCTION__
, pTS
->RxIndicateSeq
, SeqNum
);
690 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
693 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
694 dev_kfree_skb(prxb
->subframes
[i
]);
700 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,
701 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
706 * Packets are dropped if there is not enough reorder entries.
707 * This part shall be modified!! We can just indicate all the
708 * packets in buffer and get reorder entries.
710 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
713 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
714 dev_kfree_skb(prxb
->subframes
[i
]);
722 /* Check if there is any packet need indicate.*/
723 while(!list_empty(&pTS
->RxPendingPktList
)) {
724 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): start RREORDER indicate\n",__FUNCTION__
);
725 pReorderEntry
= (PRX_REORDER_ENTRY
)list_entry(pTS
->RxPendingPktList
.prev
,RX_REORDER_ENTRY
,List
);
726 if( SN_LESS(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
) ||
727 SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
729 /* This protect buffer from overflow. */
730 if(index
>= REORDER_WIN_SIZE
) {
731 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): Buffer overflow!! \n");
736 list_del_init(&pReorderEntry
->List
);
738 if(SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
739 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
741 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
742 prxbIndicateArray
[index
] = pReorderEntry
->prxb
;
743 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
746 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
753 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
755 // Cancel previous pending timer.
756 // del_timer_sync(&pTS->RxPktPendingTimer);
757 pTS
->RxTimeoutIndicateSeq
= 0xffff;
760 if(index
>REORDER_WIN_SIZE
){
761 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
764 ieee80211_indicate_packets(ieee
, prxbIndicateArray
, index
);
767 if(bPktInBuf
&& pTS
->RxTimeoutIndicateSeq
==0xffff) {
768 // Set new pending timer.
769 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): SET rx timeout timer\n", __FUNCTION__
);
770 pTS
->RxTimeoutIndicateSeq
= pTS
->RxIndicateSeq
;
771 if(timer_pending(&pTS
->RxPktPendingTimer
))
772 del_timer_sync(&pTS
->RxPktPendingTimer
);
773 pTS
->RxPktPendingTimer
.expires
= jiffies
+ MSECS(pHTInfo
->RxReorderPendingTime
);
774 add_timer(&pTS
->RxPktPendingTimer
);
778 u8
parse_subframe(struct sk_buff
*skb
,
779 struct ieee80211_rx_stats
*rx_stats
,
780 struct ieee80211_rxb
*rxb
,u8
* src
,u8
* dst
)
782 struct ieee80211_hdr_3addr
*hdr
= (struct ieee80211_hdr_3addr
* )skb
->data
;
783 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
785 u16 LLCOffset
= sizeof(struct ieee80211_hdr_3addr
);
787 bool bIsAggregateFrame
= false;
788 u16 nSubframe_Length
;
789 u8 nPadding_Length
= 0;
792 struct sk_buff
*sub_skb
;
794 /* just for debug purpose */
795 SeqNum
= WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr
->seq_ctl
));
797 if((IEEE80211_QOS_HAS_SEQ(fc
))&&\
798 (((frameqos
*)(skb
->data
+ IEEE80211_3ADDR_LEN
))->field
.reserved
)) {
799 bIsAggregateFrame
= true;
802 if(IEEE80211_QOS_HAS_SEQ(fc
)) {
806 if(rx_stats
->bContainHTC
) {
807 LLCOffset
+= sHTCLng
;
809 //printk("ChkLength = %d\n", LLCOffset);
810 // Null packet, don't indicate it to upper layer
811 ChkLength
= LLCOffset
;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
813 if( skb
->len
<= ChkLength
) {
817 skb_pull(skb
, LLCOffset
);
819 if(!bIsAggregateFrame
) {
820 rxb
->nr_subframes
= 1;
822 rxb
->subframes
[0] = skb
;
824 rxb
->subframes
[0] = skb_copy(skb
, GFP_ATOMIC
);
827 memcpy(rxb
->src
,src
,ETH_ALEN
);
828 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
829 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
832 rxb
->nr_subframes
= 0;
833 memcpy(rxb
->src
,src
,ETH_ALEN
);
834 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
835 while(skb
->len
> ETHERNET_HEADER_SIZE
) {
836 /* Offset 12 denote 2 mac address */
837 nSubframe_Length
= *((u16
*)(skb
->data
+ 12));
838 //==m==>change the length order
839 nSubframe_Length
= (nSubframe_Length
>>8) + (nSubframe_Length
<<8);
841 if(skb
->len
<(ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
842 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
843 __FUNCTION__
,rxb
->nr_subframes
);
844 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__
, nSubframe_Length
);
845 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb
->len
,nSubframe_Length
);
846 printk("The Packet SeqNum is %d\n",SeqNum
);
850 /* move the data point to data content */
851 skb_pull(skb
, ETHERNET_HEADER_SIZE
);
854 sub_skb
= skb_clone(skb
, GFP_ATOMIC
);
855 sub_skb
->len
= nSubframe_Length
;
856 sub_skb
->tail
= sub_skb
->data
+ nSubframe_Length
;
858 /* Allocate new skb for releasing to upper layer */
859 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
860 skb_reserve(sub_skb
, 12);
861 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
862 memcpy(data_ptr
,skb
->data
,nSubframe_Length
);
864 rxb
->subframes
[rxb
->nr_subframes
++] = sub_skb
;
865 if(rxb
->nr_subframes
>= MAX_SUBFRAME_COUNT
) {
866 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
869 skb_pull(skb
,nSubframe_Length
);
872 nPadding_Length
= 4 - ((nSubframe_Length
+ ETHERNET_HEADER_SIZE
) % 4);
873 if(nPadding_Length
== 4) {
877 if(skb
->len
< nPadding_Length
) {
881 skb_pull(skb
,nPadding_Length
);
887 //{just for debug added by david
888 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
890 return rxb
->nr_subframes
;
894 /* All received frames are sent to this function. @skb contains the frame in
895 * IEEE 802.11 format, i.e., in the format it was sent over air.
896 * This function is called only as a tasklet (software IRQ). */
897 int ieee80211_rx(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
898 struct ieee80211_rx_stats
*rx_stats
)
900 struct net_device
*dev
= ieee
->dev
;
901 struct ieee80211_hdr_4addr
*hdr
;
902 //struct ieee80211_hdr_3addrqos *hdr;
905 u16 fc
, type
, stype
, sc
;
906 struct net_device_stats
*stats
;
910 //added by amy for reorder
913 PRX_TS_RECORD pTS
= NULL
;
914 //bool bIsAggregateFrame = false;
915 //added by amy for reorder
917 struct net_device
*wds
= NULL
;
918 struct sk_buff
*skb2
= NULL
;
919 struct net_device
*wds
= NULL
;
920 int frame_authorized
= 0;
921 int from_assoc_ap
= 0;
928 struct ieee80211_crypt_data
*crypt
= NULL
;
932 struct ieee80211_rxb
* rxb
= NULL
;
933 // cheat the the hdr type
934 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
935 stats
= &ieee
->stats
;
938 printk(KERN_INFO
"%s: SKB length < 10\n",
943 fc
= le16_to_cpu(hdr
->frame_ctl
);
944 type
= WLAN_FC_GET_TYPE(fc
);
945 stype
= WLAN_FC_GET_STYPE(fc
);
946 sc
= le16_to_cpu(hdr
->seq_ctl
);
948 frag
= WLAN_GET_SEQ_FRAG(sc
);
949 hdrlen
= ieee80211_get_hdrlen(fc
);
951 if(HTCCheck(ieee
, skb
->data
))
954 printk("find HTCControl\n");
956 rx_stats
->bContainHTC
= 1;
959 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
961 #if WIRELESS_EXT > 15
962 /* Put this code here so that we avoid duplicating it in all
963 * Rx paths. - Jean II */
964 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
965 /* If spy monitoring on */
966 if (iface
->spy_data
.spy_number
> 0) {
967 struct iw_quality wstats
;
968 wstats
.level
= rx_stats
->rssi
;
969 wstats
.noise
= rx_stats
->noise
;
970 wstats
.updated
= 6; /* No qual value */
971 /* Update spy records */
972 wireless_spy_update(dev
, hdr
->addr2
, &wstats
);
974 #endif /* IW_WIRELESS_SPY */
975 #endif /* WIRELESS_EXT > 15 */
976 hostap_update_rx_stats(local
->ap
, hdr
, rx_stats
);
979 #if WIRELESS_EXT > 15
980 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
981 ieee80211_monitor_rx(ieee
, skb
, rx_stats
);
983 stats
->rx_bytes
+= skb
->len
;
987 if (ieee
->host_decrypt
) {
989 if (skb
->len
>= hdrlen
+ 3)
990 idx
= skb
->data
[hdrlen
+ 3] >> 6;
991 crypt
= ieee
->crypt
[idx
];
995 /* Use station specific key to override default keys if the
996 * receiver address is a unicast address ("individual RA"). If
997 * bcrx_sta_key parameter is set, station specific key is used
998 * even with broad/multicast targets (this is against IEEE
999 * 802.11, but makes it easier to use different keys with
1000 * stations that do not support WEP key mapping). */
1002 if (!(hdr
->addr1
[0] & 0x01) || local
->bcrx_sta_key
)
1003 (void) hostap_handle_sta_crypto(local
, hdr
, &crypt
,
1007 /* allow NULL decrypt to indicate an station specific override
1008 * for default encryption */
1009 if (crypt
&& (crypt
->ops
== NULL
||
1010 crypt
->ops
->decrypt_mpdu
== NULL
))
1013 if (!crypt
&& (fc
& IEEE80211_FCTL_WEP
)) {
1014 /* This seems to be triggered by some (multicast?)
1015 * frames from other than current BSS, so just drop the
1016 * frames silently instead of filling system log with
1018 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1021 ieee
->ieee_stats
.rx_discards_undecryptable
++;
1026 if (skb
->len
< IEEE80211_DATA_HDR3_LEN
)
1029 // if QoS enabled, should check the sequence for each of the AC
1030 if( (ieee
->pHTInfo
->bCurRxReorderEnable
== false) || !ieee
->current_network
.qos_data
.active
|| !IsDataFrame(skb
->data
) || IsLegacyDataFrame(skb
->data
)){
1031 if (is_duplicate_packet(ieee
, hdr
))
1037 PRX_TS_RECORD pRxTS
= NULL
;
1038 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1041 (PTS_COMMON_INFO
*) &pRxTS
,
1043 (u8
)Frame_QoSTID((u8
*)(skb
->data
)),
1048 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__FUNCTION__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc));
1049 if( (fc
& (1<<11)) &&
1050 (frag
== pRxTS
->RxLastFragNum
) &&
1051 (WLAN_GET_SEQ_SEQ(sc
) == pRxTS
->RxLastSeqNum
) )
1057 pRxTS
->RxLastFragNum
= frag
;
1058 pRxTS
->RxLastSeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1063 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "%s(): No TS!! Skip the check!!\n",__FUNCTION__
);
1067 if (type
== IEEE80211_FTYPE_MGMT
) {
1070 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1071 if (ieee80211_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
1077 /* Data frame - extract src/dst addresses */
1078 switch (fc
& (IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
)) {
1079 case IEEE80211_FCTL_FROMDS
:
1080 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1081 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
1082 memcpy(bssid
, hdr
->addr2
, ETH_ALEN
);
1084 case IEEE80211_FCTL_TODS
:
1085 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1086 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1087 memcpy(bssid
, hdr
->addr1
, ETH_ALEN
);
1089 case IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
:
1090 if (skb
->len
< IEEE80211_DATA_HDR4_LEN
)
1092 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1093 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
1094 memcpy(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
1097 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1098 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1099 memcpy(bssid
, hdr
->addr3
, ETH_ALEN
);
1104 if (hostap_rx_frame_wds(ieee
, hdr
, fc
, &wds
))
1107 skb
->dev
= dev
= wds
;
1108 stats
= hostap_get_stats(dev
);
1111 if (ieee
->iw_mode
== IW_MODE_MASTER
&& !wds
&&
1112 (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) == IEEE80211_FCTL_FROMDS
&&
1114 memcmp(hdr
->addr2
, ieee
->assoc_ap_addr
, ETH_ALEN
) == 0) {
1115 /* Frame from BSSID of the AP for which we are a client */
1116 skb
->dev
= dev
= ieee
->stadev
;
1117 stats
= hostap_get_stats(dev
);
1122 dev
->last_rx
= jiffies
;
1125 if ((ieee
->iw_mode
== IW_MODE_MASTER
||
1126 ieee
->iw_mode
== IW_MODE_REPEAT
) &&
1128 switch (hostap_handle_sta_rx(ieee
, dev
, skb
, rx_stats
,
1130 case AP_RX_CONTINUE_NOT_AUTHORIZED
:
1131 frame_authorized
= 0;
1133 case AP_RX_CONTINUE
:
1134 frame_authorized
= 1;
1143 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1144 /* Nullfunc frames may have PS-bit set, so they must be passed to
1145 * hostap_handle_sta_rx() before being dropped here. */
1146 if (stype
!= IEEE80211_STYPE_DATA
&&
1147 stype
!= IEEE80211_STYPE_DATA_CFACK
&&
1148 stype
!= IEEE80211_STYPE_DATA_CFPOLL
&&
1149 stype
!= IEEE80211_STYPE_DATA_CFACKPOLL
&&
1150 stype
!= IEEE80211_STYPE_QOS_DATA
//add by David,2006.8.4
1152 if (stype
!= IEEE80211_STYPE_NULLFUNC
)
1153 IEEE80211_DEBUG_DROP(
1154 "RX: dropped data frame "
1155 "with no data (type=0x%02x, "
1156 "subtype=0x%02x, len=%d)\n",
1157 type
, stype
, skb
->len
);
1160 if (memcmp(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
))
1163 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1165 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
1166 (keyidx
= ieee80211_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0)
1168 printk("decrypt frame error\n");
1173 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1175 /* skb: hdr + (possibly fragmented) plaintext payload */
1176 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1177 if ((frag
!= 0 || (fc
& IEEE80211_FCTL_MOREFRAGS
))) {
1179 struct sk_buff
*frag_skb
= ieee80211_frag_cache_get(ieee
, hdr
);
1180 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
1183 IEEE80211_DEBUG(IEEE80211_DL_RX
| IEEE80211_DL_FRAG
,
1184 "Rx cannot get skb from fragment "
1185 "cache (morefrag=%d seq=%u frag=%u)\n",
1186 (fc
& IEEE80211_FCTL_MOREFRAGS
) != 0,
1187 WLAN_GET_SEQ_SEQ(sc
), frag
);
1194 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
1195 printk(KERN_WARNING
"%s: host decrypted and "
1196 "reassembled frame did not fit skb\n",
1198 ieee80211_frag_cache_invalidate(ieee
, hdr
);
1203 /* copy first fragment (including full headers) into
1204 * beginning of the fragment cache skb */
1205 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
1207 /* append frame payload to the end of the fragment
1209 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
1212 dev_kfree_skb_any(skb
);
1215 if (fc
& IEEE80211_FCTL_MOREFRAGS
) {
1216 /* more fragments expected - leave the skb in fragment
1217 * cache for now; it will be delivered to upper layers
1218 * after all fragments have been received */
1222 /* this was the last fragment and the frame will be
1223 * delivered, so remove skb from fragment cache */
1225 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1226 ieee80211_frag_cache_invalidate(ieee
, hdr
);
1229 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1230 * encrypted/authenticated */
1231 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
1232 ieee80211_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
))
1234 printk("==>decrypt msdu error\n");
1238 //added by amy for AP roaming
1239 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
++;
1240 ieee
->LinkDetectInfo
.NumRxOkInPeriod
++;
1242 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1243 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
) {
1244 if (/*ieee->ieee802_1x &&*/
1245 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1247 #ifdef CONFIG_IEEE80211_DEBUG
1248 /* pass unencrypted EAPOL frames even if encryption is
1250 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1252 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1253 eap_get_type(eap
->type
));
1256 IEEE80211_DEBUG_DROP(
1257 "encryption configured, but RX "
1258 "frame not encrypted (SA=%pM)\n",
1264 #ifdef CONFIG_IEEE80211_DEBUG
1265 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) &&
1266 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1267 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1269 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1270 eap_get_type(eap
->type
));
1274 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
&&
1275 !ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1276 IEEE80211_DEBUG_DROP(
1277 "dropped unencrypted RX data "
1279 " (drop_unencrypted=1)\n",
1284 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1285 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1288 //added by amy for reorder
1289 if(ieee
->current_network
.qos_data
.active
&& IsQoSDataFrame(skb
->data
)
1290 && !is_multicast_ether_addr(hdr
->addr1
) && !is_broadcast_ether_addr(hdr
->addr1
))
1292 TID
= Frame_QoSTID(skb
->data
);
1293 SeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1294 GetTs(ieee
,(PTS_COMMON_INFO
*) &pTS
,hdr
->addr2
,TID
,RX_DIR
,true);
1295 if(TID
!=0 && TID
!=3)
1297 ieee
->bis_any_nonbepkts
= true;
1300 //added by amy for reorder
1301 /* skb: hdr + (possible reassembled) full plaintext payload */
1302 payload
= skb
->data
+ hdrlen
;
1303 //ethertype = (payload[6] << 8) | payload[7];
1304 rxb
= kmalloc(sizeof(struct ieee80211_rxb
), GFP_ATOMIC
);
1307 IEEE80211_DEBUG(IEEE80211_DL_ERR
,"%s(): kmalloc rxb error\n",__FUNCTION__
);
1310 /* to parse amsdu packets */
1311 /* qos data packets & reserved bit is 1 */
1312 if(parse_subframe(skb
,rx_stats
,rxb
,src
,dst
) == 0) {
1313 /* only to free rxb, and not submit the packets to upper layer */
1314 for(i
=0; i
< rxb
->nr_subframes
; i
++) {
1315 dev_kfree_skb(rxb
->subframes
[i
]);
1322 //added by amy for reorder
1323 if(ieee
->pHTInfo
->bCurRxReorderEnable
== false ||pTS
== NULL
){
1324 //added by amy for reorder
1325 for(i
= 0; i
<rxb
->nr_subframes
; i
++) {
1326 struct sk_buff
*sub_skb
= rxb
->subframes
[i
];
1329 /* convert hdr + possible LLC headers into Ethernet header */
1330 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
1331 if (sub_skb
->len
>= 8 &&
1332 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
1333 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1334 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
1335 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1336 * replace EtherType */
1337 skb_pull(sub_skb
, SNAP_SIZE
);
1338 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1339 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1342 /* Leave Ethernet header part of hdr and full payload */
1343 len
= htons(sub_skb
->len
);
1344 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1345 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1346 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1349 stats
->rx_packets
++;
1350 stats
->rx_bytes
+= sub_skb
->len
;
1351 if(is_multicast_ether_addr(dst
)) {
1355 /* Indicat the packets to upper layer */
1356 //printk("0skb_len(%d)\n", skb->len);
1357 sub_skb
->protocol
= eth_type_trans(sub_skb
, dev
);
1358 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
1360 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
1361 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1362 ieee
->last_rx_ps_time
= jiffies
;
1363 //printk("1skb_len(%d)\n", skb->len);
1373 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__
);
1374 RxReorderIndicatePacket(ieee
, rxb
, pTS
, SeqNum
);
1383 hostap_handle_sta_release(sta
);
1393 stats
->rx_dropped
++;
1395 /* Returning 0 indicates to caller that we have not handled the SKB--
1396 * so it is still allocated and can be used again by underlying
1397 * hardware as a DMA target */
1401 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1403 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
1406 * Make ther structure we read from the beacon packet has
1409 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1410 *info_element
, int sub_type
)
1413 if (info_element
->qui_subtype
!= sub_type
)
1415 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
1417 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
1419 if (info_element
->version
!= QOS_VERSION_1
)
1427 * Parse a QoS parameter element
1429 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1430 *element_param
, struct ieee80211_info_element
1434 u16 size
= sizeof(struct ieee80211_qos_parameter_info
) - 2;
1436 if ((info_element
== NULL
) || (element_param
== NULL
))
1439 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
1440 memcpy(element_param
->info_element
.qui
, info_element
->data
,
1442 element_param
->info_element
.elementID
= info_element
->id
;
1443 element_param
->info_element
.length
= info_element
->len
;
1447 ret
= ieee80211_verify_qos_info(&element_param
->info_element
,
1448 QOS_OUI_PARAM_SUB_TYPE
);
1453 * Parse a QoS information element
1455 static int ieee80211_read_qos_info_element(struct
1456 ieee80211_qos_information_element
1457 *element_info
, struct ieee80211_info_element
1461 u16 size
= sizeof(struct ieee80211_qos_information_element
) - 2;
1463 if (element_info
== NULL
)
1465 if (info_element
== NULL
)
1468 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
1469 memcpy(element_info
->qui
, info_element
->data
,
1471 element_info
->elementID
= info_element
->id
;
1472 element_info
->length
= info_element
->len
;
1477 ret
= ieee80211_verify_qos_info(element_info
,
1478 QOS_OUI_INFO_SUB_TYPE
);
1484 * Write QoS parameters from the ac parameters.
1486 static int ieee80211_qos_convert_ac_to_parameters(struct
1487 ieee80211_qos_parameter_info
1489 ieee80211_qos_parameters
1494 struct ieee80211_qos_ac_parameter
*ac_params
;
1499 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1500 ac_params
= &(param_elm
->ac_params_record
[i
]);
1502 aci
= (ac_params
->aci_aifsn
& 0x60) >> 5;
1504 if(aci
>= QOS_QUEUE_NUM
)
1506 qos_param
->aifs
[aci
] = (ac_params
->aci_aifsn
) & 0x0f;
1508 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1509 qos_param
->aifs
[aci
] = (qos_param
->aifs
[aci
] < 2) ? 2:qos_param
->aifs
[aci
];
1511 qos_param
->cw_min
[aci
] = ac_params
->ecw_min_max
& 0x0F;
1513 qos_param
->cw_max
[aci
] = (ac_params
->ecw_min_max
& 0xF0) >> 4;
1515 qos_param
->flag
[aci
] =
1516 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1517 qos_param
->tx_op_limit
[aci
] = le16_to_cpu(ac_params
->tx_op_limit
);
1523 * we have a generic data element which it may contain QoS information or
1524 * parameters element. check the information element length to decide
1525 * which type to read
1527 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1529 struct ieee80211_network
*network
)
1532 struct ieee80211_qos_parameters
*qos_param
= NULL
;
1533 struct ieee80211_qos_information_element qos_info_element
;
1535 rc
= ieee80211_read_qos_info_element(&qos_info_element
, info_element
);
1538 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1539 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1541 struct ieee80211_qos_parameter_info param_element
;
1543 rc
= ieee80211_read_qos_param_element(¶m_element
,
1546 qos_param
= &(network
->qos_data
.parameters
);
1547 ieee80211_qos_convert_ac_to_parameters(¶m_element
,
1549 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1550 network
->qos_data
.param_count
=
1551 param_element
.info_element
.ac_info
& 0x0F;
1556 IEEE80211_DEBUG_QOS("QoS is supported\n");
1557 network
->qos_data
.supported
= 1;
1562 #ifdef CONFIG_IEEE80211_DEBUG
1563 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1565 static const char *get_info_element_string(u16 id
)
1570 MFIE_STRING(FH_SET
);
1571 MFIE_STRING(DS_SET
);
1572 MFIE_STRING(CF_SET
);
1574 MFIE_STRING(IBSS_SET
);
1575 MFIE_STRING(COUNTRY
);
1576 MFIE_STRING(HOP_PARAMS
);
1577 MFIE_STRING(HOP_TABLE
);
1578 MFIE_STRING(REQUEST
);
1579 MFIE_STRING(CHALLENGE
);
1580 MFIE_STRING(POWER_CONSTRAINT
);
1581 MFIE_STRING(POWER_CAPABILITY
);
1582 MFIE_STRING(TPC_REQUEST
);
1583 MFIE_STRING(TPC_REPORT
);
1584 MFIE_STRING(SUPP_CHANNELS
);
1586 MFIE_STRING(MEASURE_REQUEST
);
1587 MFIE_STRING(MEASURE_REPORT
);
1589 MFIE_STRING(IBSS_DFS
);
1590 // MFIE_STRING(ERP_INFO);
1592 MFIE_STRING(RATES_EX
);
1593 MFIE_STRING(GENERIC
);
1594 MFIE_STRING(QOS_PARAMETER
);
1601 #ifdef ENABLE_DOT11D
1602 static inline void ieee80211_extract_country_ie(
1603 struct ieee80211_device
*ieee
,
1604 struct ieee80211_info_element
*info_element
,
1605 struct ieee80211_network
*network
,
1609 if(IS_DOT11D_ENABLE(ieee
))
1611 if(info_element
->len
!= 0)
1613 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
1614 network
->CountryIeLen
= info_element
->len
;
1616 if(!IS_COUNTRY_IE_VALID(ieee
))
1618 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
1623 // 070305, rcnjko: I update country IE watch dog here because
1624 // some AP (e.g. Cisco 1242) don't include country IE in their
1625 // probe response frame.
1627 if(IS_EQUAL_CIE_SRC(ieee
, addr2
) )
1629 UPDATE_CIE_WATCHDOG(ieee
);
1636 int ieee80211_parse_info_param(struct ieee80211_device
*ieee
,
1637 struct ieee80211_info_element
*info_element
,
1639 struct ieee80211_network
*network
,
1640 struct ieee80211_rx_stats
*stats
)
1644 u16 tmp_htcap_len
=0;
1645 u16 tmp_htinfo_len
=0;
1646 u16 ht_realtek_agg_len
=0;
1647 u8 ht_realtek_agg_buf
[MAX_IE_LEN
];
1648 // u16 broadcom_len = 0;
1649 #ifdef CONFIG_IEEE80211_DEBUG
1654 while (length
>= sizeof(*info_element
)) {
1655 if (sizeof(*info_element
) + info_element
->len
> length
) {
1656 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1657 "info_element->len + 2 > left : "
1658 "info_element->len+2=%zd left=%d, id=%d.\n",
1660 sizeof(*info_element
),
1661 length
, info_element
->id
);
1662 /* We stop processing but don't return an error here
1663 * because some misbehaviour APs break this rule. ie.
1664 * Orinoco AP1000. */
1668 switch (info_element
->id
) {
1669 case MFIE_TYPE_SSID
:
1670 if (ieee80211_is_empty_essid(info_element
->data
,
1671 info_element
->len
)) {
1672 network
->flags
|= NETWORK_EMPTY_ESSID
;
1676 network
->ssid_len
= min(info_element
->len
,
1677 (u8
) IW_ESSID_MAX_SIZE
);
1678 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
1679 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1680 memset(network
->ssid
+ network
->ssid_len
, 0,
1681 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1683 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1684 network
->ssid
, network
->ssid_len
);
1687 case MFIE_TYPE_RATES
:
1688 #ifdef CONFIG_IEEE80211_DEBUG
1691 network
->rates_len
= min(info_element
->len
,
1693 for (i
= 0; i
< network
->rates_len
; i
++) {
1694 network
->rates
[i
] = info_element
->data
[i
];
1695 #ifdef CONFIG_IEEE80211_DEBUG
1696 p
+= snprintf(p
, sizeof(rates_str
) -
1697 (p
- rates_str
), "%02X ",
1700 if (ieee80211_is_ofdm_rate
1701 (info_element
->data
[i
])) {
1702 network
->flags
|= NETWORK_HAS_OFDM
;
1703 if (info_element
->data
[i
] &
1704 IEEE80211_BASIC_RATE_MASK
)
1710 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1711 rates_str
, network
->rates_len
);
1714 case MFIE_TYPE_RATES_EX
:
1715 #ifdef CONFIG_IEEE80211_DEBUG
1718 network
->rates_ex_len
= min(info_element
->len
,
1719 MAX_RATES_EX_LENGTH
);
1720 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1721 network
->rates_ex
[i
] = info_element
->data
[i
];
1722 #ifdef CONFIG_IEEE80211_DEBUG
1723 p
+= snprintf(p
, sizeof(rates_str
) -
1724 (p
- rates_str
), "%02X ",
1727 if (ieee80211_is_ofdm_rate
1728 (info_element
->data
[i
])) {
1729 network
->flags
|= NETWORK_HAS_OFDM
;
1730 if (info_element
->data
[i
] &
1731 IEEE80211_BASIC_RATE_MASK
)
1737 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1738 rates_str
, network
->rates_ex_len
);
1741 case MFIE_TYPE_DS_SET
:
1742 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1743 info_element
->data
[0]);
1744 network
->channel
= info_element
->data
[0];
1747 case MFIE_TYPE_FH_SET
:
1748 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1751 case MFIE_TYPE_CF_SET
:
1752 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1756 if(info_element
->len
< 4)
1759 network
->tim
.tim_count
= info_element
->data
[0];
1760 network
->tim
.tim_period
= info_element
->data
[1];
1762 network
->dtim_period
= info_element
->data
[1];
1763 if(ieee
->state
!= IEEE80211_LINKED
)
1766 network
->last_dtim_sta_time
[0] = stats
->mac_time
[0];
1767 network
->last_dtim_sta_time
[1] = stats
->mac_time
[1];
1769 network
->dtim_data
= IEEE80211_DTIM_VALID
;
1771 if(info_element
->data
[0] != 0)
1774 if(info_element
->data
[2] & 1)
1775 network
->dtim_data
|= IEEE80211_DTIM_MBCAST
;
1777 offset
= (info_element
->data
[2] >> 1)*2;
1779 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1781 if(ieee
->assoc_id
< 8*offset
||
1782 ieee
->assoc_id
> 8*(offset
+ info_element
->len
-3))
1786 offset
= (ieee
->assoc_id
/ 8) - offset
;// + ((aid % 8)? 0 : 1) ;
1788 if(info_element
->data
[3+offset
] & (1<<(ieee
->assoc_id
%8)))
1789 network
->dtim_data
|= IEEE80211_DTIM_UCAST
;
1791 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1795 network
->erp_value
= info_element
->data
[0];
1796 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1797 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1798 network
->erp_value
);
1800 case MFIE_TYPE_IBSS_SET
:
1801 network
->atim_window
= info_element
->data
[0];
1802 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1803 network
->atim_window
);
1806 case MFIE_TYPE_CHALLENGE
:
1807 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1810 case MFIE_TYPE_GENERIC
:
1811 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1813 if (!ieee80211_parse_qos_info_param_IE(info_element
,
1817 if (info_element
->len
>= 4 &&
1818 info_element
->data
[0] == 0x00 &&
1819 info_element
->data
[1] == 0x50 &&
1820 info_element
->data
[2] == 0xf2 &&
1821 info_element
->data
[3] == 0x01) {
1822 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1824 memcpy(network
->wpa_ie
, info_element
,
1825 network
->wpa_ie_len
);
1830 if (info_element
->len
== 7 &&
1831 info_element
->data
[0] == 0x00 &&
1832 info_element
->data
[1] == 0xe0 &&
1833 info_element
->data
[2] == 0x4c &&
1834 info_element
->data
[3] == 0x01 &&
1835 info_element
->data
[4] == 0x02) {
1836 network
->Turbo_Enable
= 1;
1840 //for HTcap and HTinfo parameters
1841 if(tmp_htcap_len
== 0){
1842 if(info_element
->len
>= 4 &&
1843 info_element
->data
[0] == 0x00 &&
1844 info_element
->data
[1] == 0x90 &&
1845 info_element
->data
[2] == 0x4c &&
1846 info_element
->data
[3] == 0x033){
1848 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1849 if(tmp_htcap_len
!= 0){
1850 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1851 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
1852 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
1853 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
1856 if(tmp_htcap_len
!= 0)
1857 network
->bssht
.bdSupportHT
= true;
1859 network
->bssht
.bdSupportHT
= false;
1863 if(tmp_htinfo_len
== 0){
1864 if(info_element
->len
>= 4 &&
1865 info_element
->data
[0] == 0x00 &&
1866 info_element
->data
[1] == 0x90 &&
1867 info_element
->data
[2] == 0x4c &&
1868 info_element
->data
[3] == 0x034){
1870 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1871 if(tmp_htinfo_len
!= 0){
1872 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1874 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
1875 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
1876 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
1884 if(ieee
->aggregation
){
1885 if(network
->bssht
.bdSupportHT
){
1886 if(info_element
->len
>= 4 &&
1887 info_element
->data
[0] == 0x00 &&
1888 info_element
->data
[1] == 0xe0 &&
1889 info_element
->data
[2] == 0x4c &&
1890 info_element
->data
[3] == 0x02){
1892 ht_realtek_agg_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1893 memcpy(ht_realtek_agg_buf
,info_element
->data
,info_element
->len
);
1896 if(ht_realtek_agg_len
>= 5){
1897 network
->bssht
.bdRT2RTAggregation
= true;
1899 if((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & 0x02))
1900 network
->bssht
.bdRT2RTLongSlotTime
= true;
1906 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1908 if((info_element
->len
>= 3 &&
1909 info_element
->data
[0] == 0x00 &&
1910 info_element
->data
[1] == 0x05 &&
1911 info_element
->data
[2] == 0xb5) ||
1912 (info_element
->len
>= 3 &&
1913 info_element
->data
[0] == 0x00 &&
1914 info_element
->data
[1] == 0x0a &&
1915 info_element
->data
[2] == 0xf7) ||
1916 (info_element
->len
>= 3 &&
1917 info_element
->data
[0] == 0x00 &&
1918 info_element
->data
[1] == 0x10 &&
1919 info_element
->data
[2] == 0x18)){
1921 network
->broadcom_cap_exist
= true;
1925 if(info_element
->len
>= 3 &&
1926 info_element
->data
[0] == 0x00 &&
1927 info_element
->data
[1] == 0x0c &&
1928 info_element
->data
[2] == 0x43)
1930 network
->ralink_cap_exist
= true;
1933 network
->ralink_cap_exist
= false;
1934 //added by amy for atheros AP
1935 if((info_element
->len
>= 3 &&
1936 info_element
->data
[0] == 0x00 &&
1937 info_element
->data
[1] == 0x03 &&
1938 info_element
->data
[2] == 0x7f) ||
1939 (info_element
->len
>= 3 &&
1940 info_element
->data
[0] == 0x00 &&
1941 info_element
->data
[1] == 0x13 &&
1942 info_element
->data
[2] == 0x74))
1944 printk("========>%s(): athros AP is exist\n",__FUNCTION__
);
1945 network
->atheros_cap_exist
= true;
1948 network
->atheros_cap_exist
= false;
1950 if(info_element
->len
>= 3 &&
1951 info_element
->data
[0] == 0x00 &&
1952 info_element
->data
[1] == 0x40 &&
1953 info_element
->data
[2] == 0x96)
1955 network
->cisco_cap_exist
= true;
1958 network
->cisco_cap_exist
= false;
1959 //added by amy for LEAP of cisco
1960 if(info_element
->len
> 4 &&
1961 info_element
->data
[0] == 0x00 &&
1962 info_element
->data
[1] == 0x40 &&
1963 info_element
->data
[2] == 0x96 &&
1964 info_element
->data
[3] == 0x01)
1966 if(info_element
->len
== 6)
1968 memcpy(network
->CcxRmState
, &info_element
[4], 2);
1969 if(network
->CcxRmState
[0] != 0)
1971 network
->bCcxRmEnable
= true;
1974 network
->bCcxRmEnable
= false;
1976 // CCXv4 Table 59-1 MBSSID Masks.
1978 network
->MBssidMask
= network
->CcxRmState
[1] & 0x07;
1979 if(network
->MBssidMask
!= 0)
1981 network
->bMBssidValid
= true;
1982 network
->MBssidMask
= 0xff << (network
->MBssidMask
);
1983 cpMacAddr(network
->MBssid
, network
->bssid
);
1984 network
->MBssid
[5] &= network
->MBssidMask
;
1988 network
->bMBssidValid
= false;
1993 network
->bCcxRmEnable
= false;
1996 if(info_element
->len
> 4 &&
1997 info_element
->data
[0] == 0x00 &&
1998 info_element
->data
[1] == 0x40 &&
1999 info_element
->data
[2] == 0x96 &&
2000 info_element
->data
[3] == 0x03)
2002 if(info_element
->len
== 5)
2004 network
->bWithCcxVerNum
= true;
2005 network
->BssCcxVerNumber
= info_element
->data
[4];
2009 network
->bWithCcxVerNum
= false;
2010 network
->BssCcxVerNumber
= 0;
2016 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2018 network
->rsn_ie_len
= min(info_element
->len
+ 2,
2020 memcpy(network
->rsn_ie
, info_element
,
2021 network
->rsn_ie_len
);
2024 //HT related element.
2025 case MFIE_TYPE_HT_CAP
:
2026 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2028 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2029 if(tmp_htcap_len
!= 0){
2030 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
2031 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
2032 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
2033 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
2035 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2036 // windows driver will update WMM parameters each beacon received once connected
2037 // Linux driver is a bit different.
2038 network
->bssht
.bdSupportHT
= true;
2041 network
->bssht
.bdSupportHT
= false;
2045 case MFIE_TYPE_HT_INFO
:
2046 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2048 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2050 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_IEEE
;
2051 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
2052 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
2053 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
2057 case MFIE_TYPE_AIRONET
:
2058 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2060 if(info_element
->len
>IE_CISCO_FLAG_POSITION
)
2062 network
->bWithAironetIE
= true;
2064 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2065 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2066 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2067 if( (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_MIC
) ||
2068 (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_PK
) )
2070 network
->bCkipSupported
= true;
2074 network
->bCkipSupported
= false;
2079 network
->bWithAironetIE
= false;
2080 network
->bCkipSupported
= false;
2083 case MFIE_TYPE_QOS_PARAMETER
:
2085 "QoS Error need to parse QOS_PARAMETER IE\n");
2088 #ifdef ENABLE_DOT11D
2089 case MFIE_TYPE_COUNTRY
:
2090 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2092 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2093 ieee80211_extract_country_ie(ieee
, info_element
, network
, network
->bssid
);//addr2 is same as addr3 when from an AP
2098 IEEE80211_DEBUG_MGMT
2099 ("Unsupported info element: %s (%d)\n",
2100 get_info_element_string(info_element
->id
),
2105 length
-= sizeof(*info_element
) + info_element
->len
;
2107 (struct ieee80211_info_element
*)&info_element
->
2108 data
[info_element
->len
];
2111 if(!network
->atheros_cap_exist
&& !network
->broadcom_cap_exist
&&
2112 !network
->cisco_cap_exist
&& !network
->ralink_cap_exist
&& !network
->bssht
.bdRT2RTAggregation
)
2114 network
->unknown_cap_exist
= true;
2118 network
->unknown_cap_exist
= false;
2123 static inline u8
ieee80211_SignalStrengthTranslate(
2129 // Step 1. Scale mapping.
2130 if(CurrSS
>= 71 && CurrSS
<= 100)
2132 RetSS
= 90 + ((CurrSS
- 70) / 3);
2134 else if(CurrSS
>= 41 && CurrSS
<= 70)
2136 RetSS
= 78 + ((CurrSS
- 40) / 3);
2138 else if(CurrSS
>= 31 && CurrSS
<= 40)
2140 RetSS
= 66 + (CurrSS
- 30);
2142 else if(CurrSS
>= 21 && CurrSS
<= 30)
2144 RetSS
= 54 + (CurrSS
- 20);
2146 else if(CurrSS
>= 5 && CurrSS
<= 20)
2148 RetSS
= 42 + (((CurrSS
- 5) * 2) / 3);
2150 else if(CurrSS
== 4)
2154 else if(CurrSS
== 3)
2158 else if(CurrSS
== 2)
2162 else if(CurrSS
== 1)
2170 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2172 // Step 2. Smoothing.
2174 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2179 long ieee80211_translate_todbm(u8 signal_strength_index
)// 0-100 index.
2181 long signal_power
; // in dBm.
2183 // Translate to dBm (x=0.5y-95).
2184 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
2187 return signal_power
;
2190 static inline int ieee80211_network_init(
2191 struct ieee80211_device
*ieee
,
2192 struct ieee80211_probe_response
*beacon
,
2193 struct ieee80211_network
*network
,
2194 struct ieee80211_rx_stats
*stats
)
2196 #ifdef CONFIG_IEEE80211_DEBUG
2197 //char rates_str[64];
2201 network
->qos_data
.active
= 0;
2202 network
->qos_data
.supported
= 0;
2203 network
->qos_data
.param_count
= 0;
2204 network
->qos_data
.old_param_count
= 0;
2206 /* Pull out fixed field data */
2207 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
2208 network
->capability
= le16_to_cpu(beacon
->capability
);
2209 network
->last_scanned
= jiffies
;
2210 network
->time_stamp
[0] = le32_to_cpu(beacon
->time_stamp
[0]);
2211 network
->time_stamp
[1] = le32_to_cpu(beacon
->time_stamp
[1]);
2212 network
->beacon_interval
= le32_to_cpu(beacon
->beacon_interval
);
2213 /* Where to pull this? beacon->listen_interval;*/
2214 network
->listen_interval
= 0x0A;
2215 network
->rates_len
= network
->rates_ex_len
= 0;
2216 network
->last_associate
= 0;
2217 network
->ssid_len
= 0;
2219 network
->atim_window
= 0;
2220 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
2222 network
->berp_info_valid
= false;
2223 network
->broadcom_cap_exist
= false;
2224 network
->ralink_cap_exist
= false;
2225 network
->atheros_cap_exist
= false;
2226 network
->cisco_cap_exist
= false;
2227 network
->unknown_cap_exist
= false;
2229 network
->Turbo_Enable
= 0;
2231 #ifdef ENABLE_DOT11D
2232 network
->CountryIeLen
= 0;
2233 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
2235 //Initialize HT parameters
2236 //ieee80211_ht_initialize(&network->bssht);
2237 HTInitializeBssDesc(&network
->bssht
);
2238 if (stats
->freq
== IEEE80211_52GHZ_BAND
) {
2239 /* for A band (No DS info) */
2240 network
->channel
= stats
->received_channel
;
2242 network
->flags
|= NETWORK_HAS_CCK
;
2244 network
->wpa_ie_len
= 0;
2245 network
->rsn_ie_len
= 0;
2247 if (ieee80211_parse_info_param
2248 (ieee
,beacon
->info_element
, stats
->len
- sizeof(*beacon
), network
, stats
))
2252 if (stats
->freq
== IEEE80211_52GHZ_BAND
)
2253 network
->mode
= IEEE_A
;
2255 if (network
->flags
& NETWORK_HAS_OFDM
)
2256 network
->mode
|= IEEE_G
;
2257 if (network
->flags
& NETWORK_HAS_CCK
)
2258 network
->mode
|= IEEE_B
;
2261 if (network
->mode
== 0) {
2262 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2264 escape_essid(network
->ssid
,
2270 if(network
->bssht
.bdSupportHT
){
2271 if(network
->mode
== IEEE_A
)
2272 network
->mode
= IEEE_N_5G
;
2273 else if(network
->mode
& (IEEE_G
| IEEE_B
))
2274 network
->mode
= IEEE_N_24G
;
2276 if (ieee80211_is_empty_essid(network
->ssid
, network
->ssid_len
))
2277 network
->flags
|= NETWORK_EMPTY_ESSID
;
2279 stats
->signal
= 30 + (stats
->SignalStrength
* 70) / 100;
2280 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2281 stats
->noise
= ieee80211_translate_todbm((u8
)(100-stats
->signal
)) -25;
2283 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
2288 static inline int is_same_network(struct ieee80211_network
*src
,
2289 struct ieee80211_network
*dst
, struct ieee80211_device
* ieee
)
2291 /* A network is only a duplicate if the channel, BSSID, ESSID
2292 * and the capability field (in particular IBSS and BSS) all match.
2293 * We treat all <hidden> with the same BSSID and channel
2295 return //((src->ssid_len == dst->ssid_len) &&
2296 (((src
->ssid_len
== dst
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) &&
2297 (src
->channel
== dst
->channel
) &&
2298 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
2299 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2300 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) &&
2301 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
2302 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
2303 ((src
->capability
& WLAN_CAPABILITY_BSS
) ==
2304 (dst
->capability
& WLAN_CAPABILITY_BSS
)));
2307 static inline void update_network(struct ieee80211_network
*dst
,
2308 struct ieee80211_network
*src
)
2313 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct ieee80211_rx_stats
));
2314 dst
->capability
= src
->capability
;
2315 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
2316 dst
->rates_len
= src
->rates_len
;
2317 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
2318 dst
->rates_ex_len
= src
->rates_ex_len
;
2319 if(src
->ssid_len
> 0)
2321 memset(dst
->ssid
, 0, dst
->ssid_len
);
2322 dst
->ssid_len
= src
->ssid_len
;
2323 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
2325 dst
->mode
= src
->mode
;
2326 dst
->flags
= src
->flags
;
2327 dst
->time_stamp
[0] = src
->time_stamp
[0];
2328 dst
->time_stamp
[1] = src
->time_stamp
[1];
2329 if (src
->flags
& NETWORK_HAS_ERP_VALUE
)
2331 dst
->erp_value
= src
->erp_value
;
2332 dst
->berp_info_valid
= src
->berp_info_valid
= true;
2334 dst
->beacon_interval
= src
->beacon_interval
;
2335 dst
->listen_interval
= src
->listen_interval
;
2336 dst
->atim_window
= src
->atim_window
;
2337 dst
->dtim_period
= src
->dtim_period
;
2338 dst
->dtim_data
= src
->dtim_data
;
2339 dst
->last_dtim_sta_time
[0] = src
->last_dtim_sta_time
[0];
2340 dst
->last_dtim_sta_time
[1] = src
->last_dtim_sta_time
[1];
2341 memcpy(&dst
->tim
, &src
->tim
, sizeof(struct ieee80211_tim_parameters
));
2343 dst
->bssht
.bdSupportHT
= src
->bssht
.bdSupportHT
;
2344 dst
->bssht
.bdRT2RTAggregation
= src
->bssht
.bdRT2RTAggregation
;
2345 dst
->bssht
.bdHTCapLen
= src
->bssht
.bdHTCapLen
;
2346 memcpy(dst
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapLen
);
2347 dst
->bssht
.bdHTInfoLen
= src
->bssht
.bdHTInfoLen
;
2348 memcpy(dst
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoLen
);
2349 dst
->bssht
.bdHTSpecVer
= src
->bssht
.bdHTSpecVer
;
2350 dst
->bssht
.bdRT2RTLongSlotTime
= src
->bssht
.bdRT2RTLongSlotTime
;
2351 dst
->broadcom_cap_exist
= src
->broadcom_cap_exist
;
2352 dst
->ralink_cap_exist
= src
->ralink_cap_exist
;
2353 dst
->atheros_cap_exist
= src
->atheros_cap_exist
;
2354 dst
->cisco_cap_exist
= src
->cisco_cap_exist
;
2355 dst
->unknown_cap_exist
= src
->unknown_cap_exist
;
2356 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
2357 dst
->wpa_ie_len
= src
->wpa_ie_len
;
2358 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
2359 dst
->rsn_ie_len
= src
->rsn_ie_len
;
2361 dst
->last_scanned
= jiffies
;
2362 /* qos related parameters */
2363 //qos_active = src->qos_data.active;
2364 qos_active
= dst
->qos_data
.active
;
2365 //old_param = dst->qos_data.old_param_count;
2366 old_param
= dst
->qos_data
.param_count
;
2367 if(dst
->flags
& NETWORK_HAS_QOS_MASK
)
2368 memcpy(&dst
->qos_data
, &src
->qos_data
,
2369 sizeof(struct ieee80211_qos_data
));
2371 dst
->qos_data
.supported
= src
->qos_data
.supported
;
2372 dst
->qos_data
.param_count
= src
->qos_data
.param_count
;
2375 if(dst
->qos_data
.supported
== 1) {
2376 dst
->QoS_Enable
= 1;
2379 ("QoS the network %s is QoS supported\n",
2383 ("QoS the network is QoS supported\n");
2385 dst
->qos_data
.active
= qos_active
;
2386 dst
->qos_data
.old_param_count
= old_param
;
2388 /* dst->last_associate is not overwritten */
2389 dst
->wmm_info
= src
->wmm_info
; //sure to exist in beacon or probe response frame.
2390 if(src
->wmm_param
[0].ac_aci_acm_aifsn
|| \
2391 src
->wmm_param
[1].ac_aci_acm_aifsn
|| \
2392 src
->wmm_param
[2].ac_aci_acm_aifsn
|| \
2393 src
->wmm_param
[1].ac_aci_acm_aifsn
) {
2394 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
2396 //dst->QoS_Enable = src->QoS_Enable;
2398 dst
->Turbo_Enable
= src
->Turbo_Enable
;
2401 #ifdef ENABLE_DOT11D
2402 dst
->CountryIeLen
= src
->CountryIeLen
;
2403 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
2406 //added by amy for LEAP
2407 dst
->bWithAironetIE
= src
->bWithAironetIE
;
2408 dst
->bCkipSupported
= src
->bCkipSupported
;
2409 memcpy(dst
->CcxRmState
,src
->CcxRmState
,2);
2410 dst
->bCcxRmEnable
= src
->bCcxRmEnable
;
2411 dst
->MBssidMask
= src
->MBssidMask
;
2412 dst
->bMBssidValid
= src
->bMBssidValid
;
2413 memcpy(dst
->MBssid
,src
->MBssid
,6);
2414 dst
->bWithCcxVerNum
= src
->bWithCcxVerNum
;
2415 dst
->BssCcxVerNumber
= src
->BssCcxVerNumber
;
2419 static inline int is_beacon(__le16 fc
)
2421 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == IEEE80211_STYPE_BEACON
);
2424 static inline void ieee80211_process_probe_response(
2425 struct ieee80211_device
*ieee
,
2426 struct ieee80211_probe_response
*beacon
,
2427 struct ieee80211_rx_stats
*stats
)
2429 struct ieee80211_network network
;
2430 struct ieee80211_network
*target
;
2431 struct ieee80211_network
*oldest
= NULL
;
2432 #ifdef CONFIG_IEEE80211_DEBUG
2433 struct ieee80211_info_element
*info_element
= &beacon
->info_element
[0];
2435 unsigned long flags
;
2439 memset(&network
, 0, sizeof(struct ieee80211_network
));
2440 IEEE80211_DEBUG_SCAN(
2441 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2442 escape_essid(info_element
->data
, info_element
->len
),
2443 beacon
->header
.addr3
,
2444 (beacon
->capability
& (1<<0xf)) ? '1' : '0',
2445 (beacon
->capability
& (1<<0xe)) ? '1' : '0',
2446 (beacon
->capability
& (1<<0xd)) ? '1' : '0',
2447 (beacon
->capability
& (1<<0xc)) ? '1' : '0',
2448 (beacon
->capability
& (1<<0xb)) ? '1' : '0',
2449 (beacon
->capability
& (1<<0xa)) ? '1' : '0',
2450 (beacon
->capability
& (1<<0x9)) ? '1' : '0',
2451 (beacon
->capability
& (1<<0x8)) ? '1' : '0',
2452 (beacon
->capability
& (1<<0x7)) ? '1' : '0',
2453 (beacon
->capability
& (1<<0x6)) ? '1' : '0',
2454 (beacon
->capability
& (1<<0x5)) ? '1' : '0',
2455 (beacon
->capability
& (1<<0x4)) ? '1' : '0',
2456 (beacon
->capability
& (1<<0x3)) ? '1' : '0',
2457 (beacon
->capability
& (1<<0x2)) ? '1' : '0',
2458 (beacon
->capability
& (1<<0x1)) ? '1' : '0',
2459 (beacon
->capability
& (1<<0x0)) ? '1' : '0');
2461 if (ieee80211_network_init(ieee
, beacon
, &network
, stats
)) {
2462 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2463 escape_essid(info_element
->data
,
2465 beacon
->header
.addr3
,
2466 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2467 IEEE80211_STYPE_PROBE_RESP
?
2468 "PROBE RESPONSE" : "BEACON");
2472 #ifdef ENABLE_DOT11D
2473 // For Asus EeePc request,
2474 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2475 // wireless adapter should follow the country code.
2476 // (2) If there is no any country code in beacon,
2477 // then wireless adapter should do active scan from ch1~11 and
2478 // passive scan from ch12~14
2480 if( !IsLegalChannel(ieee
, network
.channel
) )
2482 if(ieee
->bGlobalDomain
)
2484 if (WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) == IEEE80211_STYPE_PROBE_RESP
)
2486 // Case 1: Country code
2487 if(IS_COUNTRY_IE_VALID(ieee
) )
2489 if( !IsLegalChannel(ieee
, network
.channel
) )
2491 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network
.channel
);
2495 // Case 2: No any country code.
2498 // Filter over channel ch12~14
2499 if(network
.channel
> 11)
2501 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network
.channel
);
2508 // Case 1: Country code
2509 if(IS_COUNTRY_IE_VALID(ieee
) )
2511 if( !IsLegalChannel(ieee
, network
.channel
) )
2513 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network
.channel
);
2517 // Case 2: No any country code.
2520 // Filter over channel ch12~14
2521 if(network
.channel
> 14)
2523 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network
.channel
);
2531 /* The network parsed correctly -- so now we scan our known networks
2532 * to see if we can find it in our list.
2534 * NOTE: This search is definitely not optimized. Once its doing
2535 * the "right thing" we'll optimize it for efficiency if
2538 /* Search for this entry in the list and update it if it is
2541 spin_lock_irqsave(&ieee
->lock
, flags
);
2543 if(is_same_network(&ieee
->current_network
, &network
, ieee
)) {
2544 update_network(&ieee
->current_network
, &network
);
2545 if((ieee
->current_network
.mode
== IEEE_N_24G
|| ieee
->current_network
.mode
== IEEE_G
)
2546 && ieee
->current_network
.berp_info_valid
){
2547 if(ieee
->current_network
.erp_value
& ERP_UseProtection
)
2548 ieee
->current_network
.buseprotection
= true;
2550 ieee
->current_network
.buseprotection
= false;
2552 if(is_beacon(beacon
->header
.frame_ctl
))
2554 if(ieee
->state
== IEEE80211_LINKED
)
2555 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
++;
2558 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& ieee
->current_network
.flags
);
2561 list_for_each_entry(target
, &ieee
->network_list
, list
) {
2562 if (is_same_network(target
, &network
, ieee
))
2564 if ((oldest
== NULL
) ||
2565 (target
->last_scanned
< oldest
->last_scanned
))
2569 /* If we didn't find a match, then get a new network slot to initialize
2570 * with this beacon's information */
2571 if (&target
->list
== &ieee
->network_list
) {
2572 if (list_empty(&ieee
->network_free_list
)) {
2573 /* If there are no more slots, expire the oldest */
2574 list_del(&oldest
->list
);
2576 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2578 escape_essid(target
->ssid
,
2582 /* Otherwise just pull from the free list */
2583 target
= list_entry(ieee
->network_free_list
.next
,
2584 struct ieee80211_network
, list
);
2585 list_del(ieee
->network_free_list
.next
);
2589 #ifdef CONFIG_IEEE80211_DEBUG
2590 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2591 escape_essid(network
.ssid
,
2594 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2595 IEEE80211_STYPE_PROBE_RESP
?
2596 "PROBE RESPONSE" : "BEACON");
2598 memcpy(target
, &network
, sizeof(*target
));
2599 list_add_tail(&target
->list
, &ieee
->network_list
);
2600 if(ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
)
2601 ieee80211_softmac_new_net(ieee
,&network
);
2603 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2604 escape_essid(target
->ssid
,
2607 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2608 IEEE80211_STYPE_PROBE_RESP
?
2609 "PROBE RESPONSE" : "BEACON");
2611 /* we have an entry and we are going to update it. But this entry may
2612 * be already expired. In this case we do the same as we found a new
2613 * net and call the new_net handler
2615 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
);
2616 //YJ,add,080819,for hidden ap
2617 if(is_beacon(beacon
->header
.frame_ctl
) == 0)
2618 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& target
->flags
);
2619 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2620 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2621 if(((network
.flags
& NETWORK_EMPTY_ESSID
) == NETWORK_EMPTY_ESSID
) \
2622 && (((network
.ssid_len
> 0) && (strncmp(target
->ssid
, network
.ssid
, network
.ssid_len
)))\
2623 ||((ieee
->current_network
.ssid_len
== network
.ssid_len
)&&(strncmp(ieee
->current_network
.ssid
, network
.ssid
, network
.ssid_len
) == 0)&&(ieee
->state
== IEEE80211_NOLINK
))))
2625 //YJ,add,080819,for hidden ap,end
2627 update_network(target
, &network
);
2628 if(renew
&& (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
))
2629 ieee80211_softmac_new_net(ieee
,&network
);
2632 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2633 if (is_beacon(beacon
->header
.frame_ctl
)&&is_same_network(&ieee
->current_network
, &network
, ieee
)&&\
2634 (ieee
->state
== IEEE80211_LINKED
)) {
2635 if(ieee
->handle_beacon
!= NULL
) {
2636 ieee
->handle_beacon(ieee
->dev
,beacon
,&ieee
->current_network
);
2641 void ieee80211_rx_mgt(struct ieee80211_device
*ieee
,
2642 struct ieee80211_hdr_4addr
*header
,
2643 struct ieee80211_rx_stats
*stats
)
2645 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
2647 case IEEE80211_STYPE_BEACON
:
2648 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2649 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2650 IEEE80211_DEBUG_SCAN("Beacon\n");
2651 ieee80211_process_probe_response(
2652 ieee
, (struct ieee80211_probe_response
*)header
, stats
);
2655 case IEEE80211_STYPE_PROBE_RESP
:
2656 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2657 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2658 IEEE80211_DEBUG_SCAN("Probe response\n");
2659 ieee80211_process_probe_response(
2660 ieee
, (struct ieee80211_probe_response
*)header
, stats
);
2666 EXPORT_SYMBOL(ieee80211_rx_mgt
);
2667 EXPORT_SYMBOL(ieee80211_rx
);