2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
14 ******************************************************************************
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
19 A special thanks goes to Realtek for their support !
21 ******************************************************************************/
24 #include <linux/compiler.h>
25 //#include <linux/config.h>
26 #include <linux/errno.h>
27 #include <linux/if_arp.h>
28 #include <linux/in6.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <linux/pci.h>
35 #include <linux/proc_fs.h>
36 #include <linux/skbuff.h>
37 #include <linux/slab.h>
38 #include <linux/tcp.h>
39 #include <linux/types.h>
40 #include <linux/version.h>
41 #include <linux/wireless.h>
42 #include <linux/etherdevice.h>
43 #include <asm/uaccess.h>
44 #include <linux/ctype.h>
46 #include "ieee80211.h"
48 static inline void ieee80211_monitor_rx(struct ieee80211_device
*ieee
,
50 struct ieee80211_rx_stats
*rx_stats
)
52 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
53 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
56 skb_reset_mac_header(skb
);
58 skb_pull(skb
, ieee80211_get_hdrlen(fc
));
59 skb
->pkt_type
= PACKET_OTHERHOST
;
60 skb
->protocol
= __constant_htons(ETH_P_80211_RAW
);
61 memset(skb
->cb
, 0, sizeof(skb
->cb
));
66 /* Called only as a tasklet (software IRQ) */
67 static struct ieee80211_frag_entry
*
68 ieee80211_frag_cache_find(struct ieee80211_device
*ieee
, unsigned int seq
,
69 unsigned int frag
, u8 tid
,u8
*src
, u8
*dst
)
71 struct ieee80211_frag_entry
*entry
;
74 for (i
= 0; i
< IEEE80211_FRAG_CACHE_LEN
; i
++) {
75 entry
= &ieee
->frag_cache
[tid
][i
];
76 if (entry
->skb
!= NULL
&&
77 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
79 "expiring fragment cache entry "
80 "seq=%u last_frag=%u\n",
81 entry
->seq
, entry
->last_frag
);
82 dev_kfree_skb_any(entry
->skb
);
86 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
87 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
88 memcmp(entry
->src_addr
, src
, ETH_ALEN
) == 0 &&
89 memcmp(entry
->dst_addr
, dst
, ETH_ALEN
) == 0)
96 /* Called only as a tasklet (software IRQ) */
97 static struct sk_buff
*
98 ieee80211_frag_cache_get(struct ieee80211_device
*ieee
,
99 struct ieee80211_hdr_4addr
*hdr
)
101 struct sk_buff
*skb
= NULL
;
102 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
103 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
104 unsigned int frag
= WLAN_GET_SEQ_FRAG(sc
);
105 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
106 struct ieee80211_frag_entry
*entry
;
107 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
108 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
111 if (((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
112 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
113 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
116 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
117 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
118 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
126 /* Reserve enough space to fit maximum frame length */
127 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
128 sizeof(struct ieee80211_hdr_4addr
) +
133 (IEEE80211_QOS_HAS_SEQ(fc
)?2:0) /* QOS Control */);
137 entry
= &ieee
->frag_cache
[tid
][ieee
->frag_next_idx
[tid
]];
138 ieee
->frag_next_idx
[tid
]++;
139 if (ieee
->frag_next_idx
[tid
] >= IEEE80211_FRAG_CACHE_LEN
)
140 ieee
->frag_next_idx
[tid
] = 0;
142 if (entry
->skb
!= NULL
)
143 dev_kfree_skb_any(entry
->skb
);
145 entry
->first_frag_time
= jiffies
;
147 entry
->last_frag
= frag
;
149 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
150 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
152 /* received a fragment of a frame for which the head fragment
153 * should have already been received */
154 entry
= ieee80211_frag_cache_find(ieee
, seq
, frag
, tid
,hdr
->addr2
,
157 entry
->last_frag
= frag
;
166 /* Called only as a tasklet (software IRQ) */
167 static int ieee80211_frag_cache_invalidate(struct ieee80211_device
*ieee
,
168 struct ieee80211_hdr_4addr
*hdr
)
170 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
171 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
172 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
173 struct ieee80211_frag_entry
*entry
;
174 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
175 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
178 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
179 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
180 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
183 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
184 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
185 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
192 entry
= ieee80211_frag_cache_find(ieee
, seq
, -1, tid
,hdr
->addr2
,
196 IEEE80211_DEBUG_FRAG(
197 "could not invalidate fragment cache "
198 "entry (seq=%u)\n", seq
);
208 /* ieee80211_rx_frame_mgtmt
210 * Responsible for handling management control frames
212 * Called by ieee80211_rx */
214 ieee80211_rx_frame_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
215 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
218 /* On the struct stats definition there is written that
219 * this is not mandatory.... but seems that the probe
220 * response parser uses it
222 struct ieee80211_hdr_3addr
* hdr
= (struct ieee80211_hdr_3addr
*)skb
->data
;
224 rx_stats
->len
= skb
->len
;
225 ieee80211_rx_mgt(ieee
,(struct ieee80211_hdr_4addr
*)skb
->data
,rx_stats
);
226 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
227 if ((memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
)))//use ADDR1 to perform address matching for Management frames
229 dev_kfree_skb_any(skb
);
233 ieee80211_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
235 dev_kfree_skb_any(skb
);
240 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
241 printk(KERN_DEBUG
"%s: Master mode not yet suppported.\n",
245 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
249 if (ieee
->hostapd
&& type
== IEEE80211_TYPE_MGMT
) {
250 if (stype
== WLAN_FC_STYPE_BEACON
&&
251 ieee
->iw_mode
== IW_MODE_MASTER
) {
252 struct sk_buff
*skb2
;
253 /* Process beacon frames also in kernel driver to
254 * update STA(AP) table statistics */
255 skb2
= skb_clone(skb
, GFP_ATOMIC
);
257 hostap_rx(skb2
->dev
, skb2
, rx_stats
);
260 /* send management frames to the user space daemon for
262 ieee
->apdevstats
.rx_packets
++;
263 ieee
->apdevstats
.rx_bytes
+= skb
->len
;
264 prism2_rx_80211(ieee
->apdev
, skb
, rx_stats
, PRISM2_RX_MGMT
);
268 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
269 if (type
!= WLAN_FC_TYPE_MGMT
&& type
!= WLAN_FC_TYPE_CTRL
) {
270 printk(KERN_DEBUG
"%s: unknown management frame "
271 "(type=0x%02x, stype=0x%02x) dropped\n",
272 skb
->dev
->name
, type
, stype
);
276 hostap_rx(skb
->dev
, skb
, rx_stats
);
280 printk(KERN_DEBUG
"%s: hostap_rx_frame_mgmt: management frame "
281 "received in non-Host AP mode\n", skb
->dev
->name
);
288 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
289 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
290 static unsigned char rfc1042_header
[] =
291 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
292 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
293 static unsigned char bridge_tunnel_header
[] =
294 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
295 /* No encapsulation header if EtherType < 0x600 (=length) */
297 /* Called by ieee80211_rx_frame_decrypt */
298 static int ieee80211_is_eapol_frame(struct ieee80211_device
*ieee
,
299 struct sk_buff
*skb
, size_t hdrlen
)
301 struct net_device
*dev
= ieee
->dev
;
303 struct ieee80211_hdr_4addr
*hdr
;
309 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
310 fc
= le16_to_cpu(hdr
->frame_ctl
);
312 /* check that the frame is unicast frame to us */
313 if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
314 IEEE80211_FCTL_TODS
&&
315 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
316 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
317 /* ToDS frame with own addr BSSID and DA */
318 } else if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
319 IEEE80211_FCTL_FROMDS
&&
320 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
321 /* FromDS frame with own addr as DA */
325 if (skb
->len
< 24 + 8)
328 /* check for port access entity Ethernet type */
329 // pos = skb->data + 24;
330 pos
= skb
->data
+ hdrlen
;
331 ethertype
= (pos
[6] << 8) | pos
[7];
332 if (ethertype
== ETH_P_PAE
)
338 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
340 ieee80211_rx_frame_decrypt(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
341 struct ieee80211_crypt_data
*crypt
)
343 struct ieee80211_hdr_4addr
*hdr
;
346 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
348 if (ieee
->hwsec_active
)
350 cb_desc
*tcb_desc
= (cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
351 tcb_desc
->bHwSec
= 1;
353 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
354 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
356 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
357 if (ieee
->tkip_countermeasures
&&
358 strcmp(crypt
->ops
->name
, "TKIP") == 0) {
359 if (net_ratelimit()) {
360 printk(KERN_DEBUG
"%s: TKIP countermeasures: dropped "
361 "received packet from %pM\n",
362 ieee
->dev
->name
, hdr
->addr2
);
368 atomic_inc(&crypt
->refcnt
);
369 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
370 atomic_dec(&crypt
->refcnt
);
372 IEEE80211_DEBUG_DROP(
373 "decryption failed (SA=%pM"
374 ") res=%d\n", hdr
->addr2
, res
);
376 IEEE80211_DEBUG_DROP("Decryption failed ICV "
377 "mismatch (key %d)\n",
378 skb
->data
[hdrlen
+ 3] >> 6);
379 ieee
->ieee_stats
.rx_discards_undecryptable
++;
387 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
389 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
390 int keyidx
, struct ieee80211_crypt_data
*crypt
)
392 struct ieee80211_hdr_4addr
*hdr
;
395 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
397 if (ieee
->hwsec_active
)
399 cb_desc
*tcb_desc
= (cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
400 tcb_desc
->bHwSec
= 1;
403 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
404 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
406 atomic_inc(&crypt
->refcnt
);
407 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
408 atomic_dec(&crypt
->refcnt
);
410 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
411 " (SA=%pM keyidx=%d)\n",
412 ieee
->dev
->name
, hdr
->addr2
, keyidx
);
420 /* this function is stolen from ipw2200 driver*/
421 #define IEEE_PACKET_RETRY_TIME (5*HZ)
422 static int is_duplicate_packet(struct ieee80211_device
*ieee
,
423 struct ieee80211_hdr_4addr
*header
)
425 u16 fc
= le16_to_cpu(header
->frame_ctl
);
426 u16 sc
= le16_to_cpu(header
->seq_ctl
);
427 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
428 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
429 u16
*last_seq
, *last_frag
;
430 unsigned long *last_time
;
431 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
432 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
437 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
438 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)header
;
439 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
442 } else if(IEEE80211_QOS_HAS_SEQ(fc
)) { //QoS
443 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)header
;
444 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QCTL_TID
;
451 switch (ieee
->iw_mode
) {
455 struct ieee_ibss_seq
*entry
= NULL
;
456 u8
*mac
= header
->addr2
;
457 int index
= mac
[5] % IEEE_IBSS_MAC_HASH_SIZE
;
458 //for (pos = (head)->next; pos != (head); pos = pos->next)
459 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
460 list_for_each(p
, &ieee
->ibss_mac_hash
[index
]) {
461 entry
= list_entry(p
, struct ieee_ibss_seq
, list
);
462 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
465 // if (memcmp(entry->mac, mac, ETH_ALEN)){
466 if (p
== &ieee
->ibss_mac_hash
[index
]) {
467 entry
= kmalloc(sizeof(struct ieee_ibss_seq
), GFP_ATOMIC
);
469 printk(KERN_WARNING
"Cannot malloc new mac entry\n");
472 memcpy(entry
->mac
, mac
, ETH_ALEN
);
473 entry
->seq_num
[tid
] = seq
;
474 entry
->frag_num
[tid
] = frag
;
475 entry
->packet_time
[tid
] = jiffies
;
476 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
479 last_seq
= &entry
->seq_num
[tid
];
480 last_frag
= &entry
->frag_num
[tid
];
481 last_time
= &entry
->packet_time
[tid
];
486 last_seq
= &ieee
->last_rxseq_num
[tid
];
487 last_frag
= &ieee
->last_rxfrag_num
[tid
];
488 last_time
= &ieee
->last_packet_time
[tid
];
496 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
498 if ((*last_seq
== seq
) &&
499 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
500 if (*last_frag
== frag
){
501 //printk(KERN_WARNING "[1] go drop!\n");
505 if (*last_frag
+ 1 != frag
)
506 /* out-of-order fragment */
507 //printk(KERN_WARNING "[2] go drop!\n");
513 *last_time
= jiffies
;
517 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
525 PRX_REORDER_ENTRY pReorderEntry
528 struct list_head
*pList
= &pTS
->RxPendingPktList
;
529 while(pList
->next
!= &pTS
->RxPendingPktList
)
531 if( SN_LESS(pReorderEntry
->SeqNum
, ((PRX_REORDER_ENTRY
)list_entry(pList
->next
,RX_REORDER_ENTRY
,List
))->SeqNum
) )
535 else if( SN_EQUAL(pReorderEntry
->SeqNum
, ((PRX_REORDER_ENTRY
)list_entry(pList
->next
,RX_REORDER_ENTRY
,List
))->SeqNum
) )
544 pReorderEntry
->List
.next
= pList
->next
;
545 pReorderEntry
->List
.next
->prev
= &pReorderEntry
->List
;
546 pReorderEntry
->List
.prev
= pList
;
547 pList
->next
= &pReorderEntry
->List
;
552 void ieee80211_indicate_packets(struct ieee80211_device
*ieee
, struct ieee80211_rxb
** prxbIndicateArray
,u8 index
)
557 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
558 for(j
= 0; j
<index
; j
++)
560 //added by amy for reorder
561 struct ieee80211_rxb
* prxb
= prxbIndicateArray
[j
];
562 for(i
= 0; i
<prxb
->nr_subframes
; i
++) {
563 struct sk_buff
*sub_skb
= prxb
->subframes
[i
];
565 /* convert hdr + possible LLC headers into Ethernet header */
566 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
567 if (sub_skb
->len
>= 8 &&
568 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
569 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
570 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
571 /* remove RFC1042 or Bridge-Tunnel encapsulation and
572 * replace EtherType */
573 skb_pull(sub_skb
, SNAP_SIZE
);
574 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
575 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
578 /* Leave Ethernet header part of hdr and full payload */
579 len
= htons(sub_skb
->len
);
580 memcpy(skb_push(sub_skb
, 2), &len
, 2);
581 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
582 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
584 //stats->rx_packets++;
585 //stats->rx_bytes += sub_skb->len;
587 /* Indicat the packets to upper layer */
589 //printk("0skb_len(%d)\n", skb->len);
590 sub_skb
->protocol
= eth_type_trans(sub_skb
, ieee
->dev
);
591 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
592 sub_skb
->dev
= ieee
->dev
;
593 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
594 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
595 ieee
->last_rx_ps_time
= jiffies
;
596 //printk("1skb_len(%d)\n", skb->len);
606 void RxReorderIndicatePacket( struct ieee80211_device
*ieee
,
607 struct ieee80211_rxb
* prxb
,
611 PRT_HIGH_THROUGHPUT pHTInfo
= ieee
->pHTInfo
;
612 PRX_REORDER_ENTRY pReorderEntry
= NULL
;
613 struct ieee80211_rxb
* prxbIndicateArray
[REORDER_WIN_SIZE
];
614 u8 WinSize
= pHTInfo
->RxReorderWinSize
;
615 u16 WinEnd
= (pTS
->RxIndicateSeq
+ WinSize
-1)%4096;
617 bool bMatchWinStart
= false, bPktInBuf
= false;
618 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__
,SeqNum
,pTS
->RxIndicateSeq
,WinSize
);
619 /* Rx Reorder initialize condition.*/
620 if(pTS
->RxIndicateSeq
== 0xffff) {
621 pTS
->RxIndicateSeq
= SeqNum
;
624 /* Drop out the packet which SeqNum is smaller than WinStart */
625 if(SN_LESS(SeqNum
, pTS
->RxIndicateSeq
)) {
626 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
627 pTS
->RxIndicateSeq
, SeqNum
);
628 pHTInfo
->RxReorderDropCounter
++;
631 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
632 dev_kfree_skb(prxb
->subframes
[i
]);
641 * Sliding window manipulation. Conditions includes:
642 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
643 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
645 if(SN_EQUAL(SeqNum
, pTS
->RxIndicateSeq
)) {
646 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
647 bMatchWinStart
= true;
648 } else if(SN_LESS(WinEnd
, SeqNum
)) {
649 if(SeqNum
>= (WinSize
- 1)) {
650 pTS
->RxIndicateSeq
= SeqNum
+ 1 -WinSize
;
652 pTS
->RxIndicateSeq
= 4095 - (WinSize
- (SeqNum
+1)) + 1;
654 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
658 * Indication process.
659 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
660 * with the SeqNum smaller than latest WinStart and buffer other packets.
662 /* For Rx Reorder condition:
663 * 1. All packets with SeqNum smaller than WinStart => Indicate
664 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
667 /* Current packet is going to be indicated.*/
668 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
669 pTS
->RxIndicateSeq
, SeqNum
);
670 prxbIndicateArray
[0] = prxb
;
671 // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
674 /* Current packet is going to be inserted into pending list.*/
675 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
676 if(!list_empty(&ieee
->RxReorder_Unused_List
)) {
677 pReorderEntry
= (PRX_REORDER_ENTRY
)list_entry(ieee
->RxReorder_Unused_List
.next
,RX_REORDER_ENTRY
,List
);
678 list_del_init(&pReorderEntry
->List
);
680 /* Make a reorder entry and insert into a the packet list.*/
681 pReorderEntry
->SeqNum
= SeqNum
;
682 pReorderEntry
->prxb
= prxb
;
683 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
685 if(!AddReorderEntry(pTS
, pReorderEntry
)) {
686 IEEE80211_DEBUG(IEEE80211_DL_REORDER
, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
687 __FUNCTION__
, pTS
->RxIndicateSeq
, SeqNum
);
688 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
691 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
692 dev_kfree_skb(prxb
->subframes
[i
]);
698 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,
699 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
704 * Packets are dropped if there is not enough reorder entries.
705 * This part shall be modified!! We can just indicate all the
706 * packets in buffer and get reorder entries.
708 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
711 for(i
=0; i
< prxb
->nr_subframes
; i
++) {
712 dev_kfree_skb(prxb
->subframes
[i
]);
720 /* Check if there is any packet need indicate.*/
721 while(!list_empty(&pTS
->RxPendingPktList
)) {
722 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): start RREORDER indicate\n",__FUNCTION__
);
723 pReorderEntry
= (PRX_REORDER_ENTRY
)list_entry(pTS
->RxPendingPktList
.prev
,RX_REORDER_ENTRY
,List
);
724 if( SN_LESS(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
) ||
725 SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
727 /* This protect buffer from overflow. */
728 if(index
>= REORDER_WIN_SIZE
) {
729 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): Buffer overflow!! \n");
734 list_del_init(&pReorderEntry
->List
);
736 if(SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
737 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
739 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
740 prxbIndicateArray
[index
] = pReorderEntry
->prxb
;
741 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
744 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
751 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
753 // Cancel previous pending timer.
754 // del_timer_sync(&pTS->RxPktPendingTimer);
755 pTS
->RxTimeoutIndicateSeq
= 0xffff;
758 if(index
>REORDER_WIN_SIZE
){
759 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
762 ieee80211_indicate_packets(ieee
, prxbIndicateArray
, index
);
765 if(bPktInBuf
&& pTS
->RxTimeoutIndicateSeq
==0xffff) {
766 // Set new pending timer.
767 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): SET rx timeout timer\n", __FUNCTION__
);
768 pTS
->RxTimeoutIndicateSeq
= pTS
->RxIndicateSeq
;
769 if(timer_pending(&pTS
->RxPktPendingTimer
))
770 del_timer_sync(&pTS
->RxPktPendingTimer
);
771 pTS
->RxPktPendingTimer
.expires
= jiffies
+ MSECS(pHTInfo
->RxReorderPendingTime
);
772 add_timer(&pTS
->RxPktPendingTimer
);
776 u8
parse_subframe(struct sk_buff
*skb
,
777 struct ieee80211_rx_stats
*rx_stats
,
778 struct ieee80211_rxb
*rxb
,u8
* src
,u8
* dst
)
780 struct ieee80211_hdr_3addr
*hdr
= (struct ieee80211_hdr_3addr
* )skb
->data
;
781 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
783 u16 LLCOffset
= sizeof(struct ieee80211_hdr_3addr
);
785 bool bIsAggregateFrame
= false;
786 u16 nSubframe_Length
;
787 u8 nPadding_Length
= 0;
790 struct sk_buff
*sub_skb
;
792 /* just for debug purpose */
793 SeqNum
= WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr
->seq_ctl
));
795 if((IEEE80211_QOS_HAS_SEQ(fc
))&&\
796 (((frameqos
*)(skb
->data
+ IEEE80211_3ADDR_LEN
))->field
.reserved
)) {
797 bIsAggregateFrame
= true;
800 if(IEEE80211_QOS_HAS_SEQ(fc
)) {
804 if(rx_stats
->bContainHTC
) {
805 LLCOffset
+= sHTCLng
;
807 //printk("ChkLength = %d\n", LLCOffset);
808 // Null packet, don't indicate it to upper layer
809 ChkLength
= LLCOffset
;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
811 if( skb
->len
<= ChkLength
) {
815 skb_pull(skb
, LLCOffset
);
817 if(!bIsAggregateFrame
) {
818 rxb
->nr_subframes
= 1;
820 rxb
->subframes
[0] = skb
;
822 rxb
->subframes
[0] = skb_copy(skb
, GFP_ATOMIC
);
825 memcpy(rxb
->src
,src
,ETH_ALEN
);
826 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
827 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
830 rxb
->nr_subframes
= 0;
831 memcpy(rxb
->src
,src
,ETH_ALEN
);
832 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
833 while(skb
->len
> ETHERNET_HEADER_SIZE
) {
834 /* Offset 12 denote 2 mac address */
835 nSubframe_Length
= *((u16
*)(skb
->data
+ 12));
836 //==m==>change the length order
837 nSubframe_Length
= (nSubframe_Length
>>8) + (nSubframe_Length
<<8);
839 if(skb
->len
<(ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
840 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
841 __FUNCTION__
,rxb
->nr_subframes
);
842 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__
, nSubframe_Length
);
843 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb
->len
,nSubframe_Length
);
844 printk("The Packet SeqNum is %d\n",SeqNum
);
848 /* move the data point to data content */
849 skb_pull(skb
, ETHERNET_HEADER_SIZE
);
852 sub_skb
= skb_clone(skb
, GFP_ATOMIC
);
853 sub_skb
->len
= nSubframe_Length
;
854 sub_skb
->tail
= sub_skb
->data
+ nSubframe_Length
;
856 /* Allocate new skb for releasing to upper layer */
857 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
858 skb_reserve(sub_skb
, 12);
859 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
860 memcpy(data_ptr
,skb
->data
,nSubframe_Length
);
862 rxb
->subframes
[rxb
->nr_subframes
++] = sub_skb
;
863 if(rxb
->nr_subframes
>= MAX_SUBFRAME_COUNT
) {
864 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
867 skb_pull(skb
,nSubframe_Length
);
870 nPadding_Length
= 4 - ((nSubframe_Length
+ ETHERNET_HEADER_SIZE
) % 4);
871 if(nPadding_Length
== 4) {
875 if(skb
->len
< nPadding_Length
) {
879 skb_pull(skb
,nPadding_Length
);
885 //{just for debug added by david
886 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
888 return rxb
->nr_subframes
;
892 /* All received frames are sent to this function. @skb contains the frame in
893 * IEEE 802.11 format, i.e., in the format it was sent over air.
894 * This function is called only as a tasklet (software IRQ). */
895 int ieee80211_rx(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
896 struct ieee80211_rx_stats
*rx_stats
)
898 struct net_device
*dev
= ieee
->dev
;
899 struct ieee80211_hdr_4addr
*hdr
;
900 //struct ieee80211_hdr_3addrqos *hdr;
903 u16 fc
, type
, stype
, sc
;
904 struct net_device_stats
*stats
;
908 //added by amy for reorder
911 PRX_TS_RECORD pTS
= NULL
;
912 //bool bIsAggregateFrame = false;
913 //added by amy for reorder
915 struct net_device
*wds
= NULL
;
916 struct sk_buff
*skb2
= NULL
;
917 struct net_device
*wds
= NULL
;
918 int frame_authorized
= 0;
919 int from_assoc_ap
= 0;
926 struct ieee80211_crypt_data
*crypt
= NULL
;
930 struct ieee80211_rxb
* rxb
= NULL
;
931 // cheat the the hdr type
932 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
933 stats
= &ieee
->stats
;
936 printk(KERN_INFO
"%s: SKB length < 10\n",
941 fc
= le16_to_cpu(hdr
->frame_ctl
);
942 type
= WLAN_FC_GET_TYPE(fc
);
943 stype
= WLAN_FC_GET_STYPE(fc
);
944 sc
= le16_to_cpu(hdr
->seq_ctl
);
946 frag
= WLAN_GET_SEQ_FRAG(sc
);
947 hdrlen
= ieee80211_get_hdrlen(fc
);
949 if(HTCCheck(ieee
, skb
->data
))
952 printk("find HTCControl\n");
954 rx_stats
->bContainHTC
= 1;
957 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
959 #if WIRELESS_EXT > 15
960 /* Put this code here so that we avoid duplicating it in all
961 * Rx paths. - Jean II */
962 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
963 /* If spy monitoring on */
964 if (iface
->spy_data
.spy_number
> 0) {
965 struct iw_quality wstats
;
966 wstats
.level
= rx_stats
->rssi
;
967 wstats
.noise
= rx_stats
->noise
;
968 wstats
.updated
= 6; /* No qual value */
969 /* Update spy records */
970 wireless_spy_update(dev
, hdr
->addr2
, &wstats
);
972 #endif /* IW_WIRELESS_SPY */
973 #endif /* WIRELESS_EXT > 15 */
974 hostap_update_rx_stats(local
->ap
, hdr
, rx_stats
);
977 #if WIRELESS_EXT > 15
978 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
979 ieee80211_monitor_rx(ieee
, skb
, rx_stats
);
981 stats
->rx_bytes
+= skb
->len
;
985 if (ieee
->host_decrypt
) {
987 if (skb
->len
>= hdrlen
+ 3)
988 idx
= skb
->data
[hdrlen
+ 3] >> 6;
989 crypt
= ieee
->crypt
[idx
];
993 /* Use station specific key to override default keys if the
994 * receiver address is a unicast address ("individual RA"). If
995 * bcrx_sta_key parameter is set, station specific key is used
996 * even with broad/multicast targets (this is against IEEE
997 * 802.11, but makes it easier to use different keys with
998 * stations that do not support WEP key mapping). */
1000 if (!(hdr
->addr1
[0] & 0x01) || local
->bcrx_sta_key
)
1001 (void) hostap_handle_sta_crypto(local
, hdr
, &crypt
,
1005 /* allow NULL decrypt to indicate an station specific override
1006 * for default encryption */
1007 if (crypt
&& (crypt
->ops
== NULL
||
1008 crypt
->ops
->decrypt_mpdu
== NULL
))
1011 if (!crypt
&& (fc
& IEEE80211_FCTL_WEP
)) {
1012 /* This seems to be triggered by some (multicast?)
1013 * frames from other than current BSS, so just drop the
1014 * frames silently instead of filling system log with
1016 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1019 ieee
->ieee_stats
.rx_discards_undecryptable
++;
1024 if (skb
->len
< IEEE80211_DATA_HDR3_LEN
)
1027 // if QoS enabled, should check the sequence for each of the AC
1028 if( (ieee
->pHTInfo
->bCurRxReorderEnable
== false) || !ieee
->current_network
.qos_data
.active
|| !IsDataFrame(skb
->data
) || IsLegacyDataFrame(skb
->data
)){
1029 if (is_duplicate_packet(ieee
, hdr
))
1035 PRX_TS_RECORD pRxTS
= NULL
;
1036 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1039 (PTS_COMMON_INFO
*) &pRxTS
,
1041 (u8
)Frame_QoSTID((u8
*)(skb
->data
)),
1046 // 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));
1047 if( (fc
& (1<<11)) &&
1048 (frag
== pRxTS
->RxLastFragNum
) &&
1049 (WLAN_GET_SEQ_SEQ(sc
) == pRxTS
->RxLastSeqNum
) )
1055 pRxTS
->RxLastFragNum
= frag
;
1056 pRxTS
->RxLastSeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1061 IEEE80211_DEBUG(IEEE80211_DL_ERR
, "%s(): No TS!! Skip the check!!\n",__FUNCTION__
);
1065 if (type
== IEEE80211_FTYPE_MGMT
) {
1068 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1069 if (ieee80211_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
1075 /* Data frame - extract src/dst addresses */
1076 switch (fc
& (IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
)) {
1077 case IEEE80211_FCTL_FROMDS
:
1078 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1079 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
1080 memcpy(bssid
, hdr
->addr2
, ETH_ALEN
);
1082 case IEEE80211_FCTL_TODS
:
1083 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1084 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1085 memcpy(bssid
, hdr
->addr1
, ETH_ALEN
);
1087 case IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
:
1088 if (skb
->len
< IEEE80211_DATA_HDR4_LEN
)
1090 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1091 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
1092 memcpy(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
1095 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1096 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1097 memcpy(bssid
, hdr
->addr3
, ETH_ALEN
);
1102 if (hostap_rx_frame_wds(ieee
, hdr
, fc
, &wds
))
1105 skb
->dev
= dev
= wds
;
1106 stats
= hostap_get_stats(dev
);
1109 if (ieee
->iw_mode
== IW_MODE_MASTER
&& !wds
&&
1110 (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) == IEEE80211_FCTL_FROMDS
&&
1112 memcmp(hdr
->addr2
, ieee
->assoc_ap_addr
, ETH_ALEN
) == 0) {
1113 /* Frame from BSSID of the AP for which we are a client */
1114 skb
->dev
= dev
= ieee
->stadev
;
1115 stats
= hostap_get_stats(dev
);
1120 dev
->last_rx
= jiffies
;
1123 if ((ieee
->iw_mode
== IW_MODE_MASTER
||
1124 ieee
->iw_mode
== IW_MODE_REPEAT
) &&
1126 switch (hostap_handle_sta_rx(ieee
, dev
, skb
, rx_stats
,
1128 case AP_RX_CONTINUE_NOT_AUTHORIZED
:
1129 frame_authorized
= 0;
1131 case AP_RX_CONTINUE
:
1132 frame_authorized
= 1;
1141 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1142 /* Nullfunc frames may have PS-bit set, so they must be passed to
1143 * hostap_handle_sta_rx() before being dropped here. */
1144 if (stype
!= IEEE80211_STYPE_DATA
&&
1145 stype
!= IEEE80211_STYPE_DATA_CFACK
&&
1146 stype
!= IEEE80211_STYPE_DATA_CFPOLL
&&
1147 stype
!= IEEE80211_STYPE_DATA_CFACKPOLL
&&
1148 stype
!= IEEE80211_STYPE_QOS_DATA
//add by David,2006.8.4
1150 if (stype
!= IEEE80211_STYPE_NULLFUNC
)
1151 IEEE80211_DEBUG_DROP(
1152 "RX: dropped data frame "
1153 "with no data (type=0x%02x, "
1154 "subtype=0x%02x, len=%d)\n",
1155 type
, stype
, skb
->len
);
1158 if (memcmp(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
))
1161 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1163 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
1164 (keyidx
= ieee80211_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0)
1166 printk("decrypt frame error\n");
1171 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1173 /* skb: hdr + (possibly fragmented) plaintext payload */
1174 // PR: FIXME: hostap has additional conditions in the "if" below:
1175 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1176 if ((frag
!= 0 || (fc
& IEEE80211_FCTL_MOREFRAGS
))) {
1178 struct sk_buff
*frag_skb
= ieee80211_frag_cache_get(ieee
, hdr
);
1179 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
1182 IEEE80211_DEBUG(IEEE80211_DL_RX
| IEEE80211_DL_FRAG
,
1183 "Rx cannot get skb from fragment "
1184 "cache (morefrag=%d seq=%u frag=%u)\n",
1185 (fc
& IEEE80211_FCTL_MOREFRAGS
) != 0,
1186 WLAN_GET_SEQ_SEQ(sc
), frag
);
1193 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
1194 printk(KERN_WARNING
"%s: host decrypted and "
1195 "reassembled frame did not fit skb\n",
1197 ieee80211_frag_cache_invalidate(ieee
, hdr
);
1202 /* copy first fragment (including full headers) into
1203 * beginning of the fragment cache skb */
1204 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
1206 /* append frame payload to the end of the fragment
1208 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
1211 dev_kfree_skb_any(skb
);
1214 if (fc
& IEEE80211_FCTL_MOREFRAGS
) {
1215 /* more fragments expected - leave the skb in fragment
1216 * cache for now; it will be delivered to upper layers
1217 * after all fragments have been received */
1221 /* this was the last fragment and the frame will be
1222 * delivered, so remove skb from fragment cache */
1224 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1225 ieee80211_frag_cache_invalidate(ieee
, hdr
);
1228 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1229 * encrypted/authenticated */
1230 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
1231 ieee80211_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
))
1233 printk("==>decrypt msdu error\n");
1237 //added by amy for AP roaming
1238 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
++;
1239 ieee
->LinkDetectInfo
.NumRxOkInPeriod
++;
1241 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1242 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
) {
1243 if (/*ieee->ieee802_1x &&*/
1244 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1246 #ifdef CONFIG_IEEE80211_DEBUG
1247 /* pass unencrypted EAPOL frames even if encryption is
1249 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1251 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1252 eap_get_type(eap
->type
));
1255 IEEE80211_DEBUG_DROP(
1256 "encryption configured, but RX "
1257 "frame not encrypted (SA=%pM)\n",
1263 #ifdef CONFIG_IEEE80211_DEBUG
1264 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) &&
1265 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1266 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1268 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1269 eap_get_type(eap
->type
));
1273 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
&&
1274 !ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1275 IEEE80211_DEBUG_DROP(
1276 "dropped unencrypted RX data "
1278 " (drop_unencrypted=1)\n",
1283 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1284 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1287 //added by amy for reorder
1288 if(ieee
->current_network
.qos_data
.active
&& IsQoSDataFrame(skb
->data
)
1289 && !is_multicast_ether_addr(hdr
->addr1
) && !is_broadcast_ether_addr(hdr
->addr1
))
1291 TID
= Frame_QoSTID(skb
->data
);
1292 SeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1293 GetTs(ieee
,(PTS_COMMON_INFO
*) &pTS
,hdr
->addr2
,TID
,RX_DIR
,true);
1294 if(TID
!=0 && TID
!=3)
1296 ieee
->bis_any_nonbepkts
= true;
1299 //added by amy for reorder
1300 /* skb: hdr + (possible reassembled) full plaintext payload */
1301 payload
= skb
->data
+ hdrlen
;
1302 //ethertype = (payload[6] << 8) | payload[7];
1303 rxb
= kmalloc(sizeof(struct ieee80211_rxb
), GFP_ATOMIC
);
1306 IEEE80211_DEBUG(IEEE80211_DL_ERR
,"%s(): kmalloc rxb error\n",__FUNCTION__
);
1309 /* to parse amsdu packets */
1310 /* qos data packets & reserved bit is 1 */
1311 if(parse_subframe(skb
,rx_stats
,rxb
,src
,dst
) == 0) {
1312 /* only to free rxb, and not submit the packets to upper layer */
1313 for(i
=0; i
< rxb
->nr_subframes
; i
++) {
1314 dev_kfree_skb(rxb
->subframes
[i
]);
1321 //added by amy for reorder
1322 if(ieee
->pHTInfo
->bCurRxReorderEnable
== false ||pTS
== NULL
){
1323 //added by amy for reorder
1324 for(i
= 0; i
<rxb
->nr_subframes
; i
++) {
1325 struct sk_buff
*sub_skb
= rxb
->subframes
[i
];
1328 /* convert hdr + possible LLC headers into Ethernet header */
1329 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
1330 if (sub_skb
->len
>= 8 &&
1331 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
1332 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1333 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
1334 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1335 * replace EtherType */
1336 skb_pull(sub_skb
, SNAP_SIZE
);
1337 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1338 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1341 /* Leave Ethernet header part of hdr and full payload */
1342 len
= htons(sub_skb
->len
);
1343 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1344 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1345 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1348 stats
->rx_packets
++;
1349 stats
->rx_bytes
+= sub_skb
->len
;
1350 if(is_multicast_ether_addr(dst
)) {
1354 /* Indicat the packets to upper layer */
1355 //printk("0skb_len(%d)\n", skb->len);
1356 sub_skb
->protocol
= eth_type_trans(sub_skb
, dev
);
1357 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
1359 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
1360 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1361 ieee
->last_rx_ps_time
= jiffies
;
1362 //printk("1skb_len(%d)\n", skb->len);
1372 IEEE80211_DEBUG(IEEE80211_DL_REORDER
,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__
);
1373 RxReorderIndicatePacket(ieee
, rxb
, pTS
, SeqNum
);
1382 hostap_handle_sta_release(sta
);
1389 stats
->rx_dropped
++;
1391 /* Returning 0 indicates to caller that we have not handled the SKB--
1392 * so it is still allocated and can be used again by underlying
1393 * hardware as a DMA target */
1397 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1399 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
1402 * Make the structure we read from the beacon packet to have
1405 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1406 *info_element
, int sub_type
)
1409 if (info_element
->qui_subtype
!= sub_type
)
1411 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
1413 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
1415 if (info_element
->version
!= QOS_VERSION_1
)
1423 * Parse a QoS parameter element
1425 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1426 *element_param
, struct ieee80211_info_element
1430 u16 size
= sizeof(struct ieee80211_qos_parameter_info
) - 2;
1432 if ((info_element
== NULL
) || (element_param
== NULL
))
1435 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
1436 memcpy(element_param
->info_element
.qui
, info_element
->data
,
1438 element_param
->info_element
.elementID
= info_element
->id
;
1439 element_param
->info_element
.length
= info_element
->len
;
1443 ret
= ieee80211_verify_qos_info(&element_param
->info_element
,
1444 QOS_OUI_PARAM_SUB_TYPE
);
1449 * Parse a QoS information element
1451 static int ieee80211_read_qos_info_element(struct
1452 ieee80211_qos_information_element
1453 *element_info
, struct ieee80211_info_element
1457 u16 size
= sizeof(struct ieee80211_qos_information_element
) - 2;
1459 if (element_info
== NULL
)
1461 if (info_element
== NULL
)
1464 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
1465 memcpy(element_info
->qui
, info_element
->data
,
1467 element_info
->elementID
= info_element
->id
;
1468 element_info
->length
= info_element
->len
;
1473 ret
= ieee80211_verify_qos_info(element_info
,
1474 QOS_OUI_INFO_SUB_TYPE
);
1480 * Write QoS parameters from the ac parameters.
1482 static int ieee80211_qos_convert_ac_to_parameters(struct
1483 ieee80211_qos_parameter_info
1485 ieee80211_qos_parameters
1490 struct ieee80211_qos_ac_parameter
*ac_params
;
1495 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1496 ac_params
= &(param_elm
->ac_params_record
[i
]);
1498 aci
= (ac_params
->aci_aifsn
& 0x60) >> 5;
1500 if(aci
>= QOS_QUEUE_NUM
)
1502 qos_param
->aifs
[aci
] = (ac_params
->aci_aifsn
) & 0x0f;
1504 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1505 qos_param
->aifs
[aci
] = (qos_param
->aifs
[aci
] < 2) ? 2:qos_param
->aifs
[aci
];
1507 qos_param
->cw_min
[aci
] = ac_params
->ecw_min_max
& 0x0F;
1509 qos_param
->cw_max
[aci
] = (ac_params
->ecw_min_max
& 0xF0) >> 4;
1511 qos_param
->flag
[aci
] =
1512 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1513 qos_param
->tx_op_limit
[aci
] = le16_to_cpu(ac_params
->tx_op_limit
);
1519 * we have a generic data element which it may contain QoS information or
1520 * parameters element. check the information element length to decide
1521 * which type to read
1523 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1525 struct ieee80211_network
*network
)
1528 struct ieee80211_qos_parameters
*qos_param
= NULL
;
1529 struct ieee80211_qos_information_element qos_info_element
;
1531 rc
= ieee80211_read_qos_info_element(&qos_info_element
, info_element
);
1534 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1535 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1537 struct ieee80211_qos_parameter_info param_element
;
1539 rc
= ieee80211_read_qos_param_element(¶m_element
,
1542 qos_param
= &(network
->qos_data
.parameters
);
1543 ieee80211_qos_convert_ac_to_parameters(¶m_element
,
1545 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1546 network
->qos_data
.param_count
=
1547 param_element
.info_element
.ac_info
& 0x0F;
1552 IEEE80211_DEBUG_QOS("QoS is supported\n");
1553 network
->qos_data
.supported
= 1;
1558 #ifdef CONFIG_IEEE80211_DEBUG
1559 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1561 static const char *get_info_element_string(u16 id
)
1566 MFIE_STRING(FH_SET
);
1567 MFIE_STRING(DS_SET
);
1568 MFIE_STRING(CF_SET
);
1570 MFIE_STRING(IBSS_SET
);
1571 MFIE_STRING(COUNTRY
);
1572 MFIE_STRING(HOP_PARAMS
);
1573 MFIE_STRING(HOP_TABLE
);
1574 MFIE_STRING(REQUEST
);
1575 MFIE_STRING(CHALLENGE
);
1576 MFIE_STRING(POWER_CONSTRAINT
);
1577 MFIE_STRING(POWER_CAPABILITY
);
1578 MFIE_STRING(TPC_REQUEST
);
1579 MFIE_STRING(TPC_REPORT
);
1580 MFIE_STRING(SUPP_CHANNELS
);
1582 MFIE_STRING(MEASURE_REQUEST
);
1583 MFIE_STRING(MEASURE_REPORT
);
1585 MFIE_STRING(IBSS_DFS
);
1586 // MFIE_STRING(ERP_INFO);
1588 MFIE_STRING(RATES_EX
);
1589 MFIE_STRING(GENERIC
);
1590 MFIE_STRING(QOS_PARAMETER
);
1597 static inline void ieee80211_extract_country_ie(
1598 struct ieee80211_device
*ieee
,
1599 struct ieee80211_info_element
*info_element
,
1600 struct ieee80211_network
*network
,
1604 if(IS_DOT11D_ENABLE(ieee
))
1606 if(info_element
->len
!= 0)
1608 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
1609 network
->CountryIeLen
= info_element
->len
;
1611 if(!IS_COUNTRY_IE_VALID(ieee
))
1613 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
1618 // 070305, rcnjko: I update country IE watch dog here because
1619 // some AP (e.g. Cisco 1242) don't include country IE in their
1620 // probe response frame.
1622 if(IS_EQUAL_CIE_SRC(ieee
, addr2
) )
1624 UPDATE_CIE_WATCHDOG(ieee
);
1630 int ieee80211_parse_info_param(struct ieee80211_device
*ieee
,
1631 struct ieee80211_info_element
*info_element
,
1633 struct ieee80211_network
*network
,
1634 struct ieee80211_rx_stats
*stats
)
1638 u16 tmp_htcap_len
=0;
1639 u16 tmp_htinfo_len
=0;
1640 u16 ht_realtek_agg_len
=0;
1641 u8 ht_realtek_agg_buf
[MAX_IE_LEN
];
1642 // u16 broadcom_len = 0;
1643 #ifdef CONFIG_IEEE80211_DEBUG
1648 while (length
>= sizeof(*info_element
)) {
1649 if (sizeof(*info_element
) + info_element
->len
> length
) {
1650 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1651 "info_element->len + 2 > left : "
1652 "info_element->len+2=%zd left=%d, id=%d.\n",
1654 sizeof(*info_element
),
1655 length
, info_element
->id
);
1656 /* We stop processing but don't return an error here
1657 * because some misbehaviour APs break this rule. ie.
1658 * Orinoco AP1000. */
1662 switch (info_element
->id
) {
1663 case MFIE_TYPE_SSID
:
1664 if (ieee80211_is_empty_essid(info_element
->data
,
1665 info_element
->len
)) {
1666 network
->flags
|= NETWORK_EMPTY_ESSID
;
1670 network
->ssid_len
= min(info_element
->len
,
1671 (u8
) IW_ESSID_MAX_SIZE
);
1672 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
1673 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1674 memset(network
->ssid
+ network
->ssid_len
, 0,
1675 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1677 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1678 network
->ssid
, network
->ssid_len
);
1681 case MFIE_TYPE_RATES
:
1682 #ifdef CONFIG_IEEE80211_DEBUG
1685 network
->rates_len
= min(info_element
->len
,
1687 for (i
= 0; i
< network
->rates_len
; i
++) {
1688 network
->rates
[i
] = info_element
->data
[i
];
1689 #ifdef CONFIG_IEEE80211_DEBUG
1690 p
+= snprintf(p
, sizeof(rates_str
) -
1691 (p
- rates_str
), "%02X ",
1694 if (ieee80211_is_ofdm_rate
1695 (info_element
->data
[i
])) {
1696 network
->flags
|= NETWORK_HAS_OFDM
;
1697 if (info_element
->data
[i
] &
1698 IEEE80211_BASIC_RATE_MASK
)
1704 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1705 rates_str
, network
->rates_len
);
1708 case MFIE_TYPE_RATES_EX
:
1709 #ifdef CONFIG_IEEE80211_DEBUG
1712 network
->rates_ex_len
= min(info_element
->len
,
1713 MAX_RATES_EX_LENGTH
);
1714 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1715 network
->rates_ex
[i
] = info_element
->data
[i
];
1716 #ifdef CONFIG_IEEE80211_DEBUG
1717 p
+= snprintf(p
, sizeof(rates_str
) -
1718 (p
- rates_str
), "%02X ",
1721 if (ieee80211_is_ofdm_rate
1722 (info_element
->data
[i
])) {
1723 network
->flags
|= NETWORK_HAS_OFDM
;
1724 if (info_element
->data
[i
] &
1725 IEEE80211_BASIC_RATE_MASK
)
1731 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1732 rates_str
, network
->rates_ex_len
);
1735 case MFIE_TYPE_DS_SET
:
1736 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1737 info_element
->data
[0]);
1738 network
->channel
= info_element
->data
[0];
1741 case MFIE_TYPE_FH_SET
:
1742 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1745 case MFIE_TYPE_CF_SET
:
1746 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1750 if(info_element
->len
< 4)
1753 network
->tim
.tim_count
= info_element
->data
[0];
1754 network
->tim
.tim_period
= info_element
->data
[1];
1756 network
->dtim_period
= info_element
->data
[1];
1757 if(ieee
->state
!= IEEE80211_LINKED
)
1760 network
->last_dtim_sta_time
[0] = stats
->mac_time
[0];
1761 network
->last_dtim_sta_time
[1] = stats
->mac_time
[1];
1763 network
->dtim_data
= IEEE80211_DTIM_VALID
;
1765 if(info_element
->data
[0] != 0)
1768 if(info_element
->data
[2] & 1)
1769 network
->dtim_data
|= IEEE80211_DTIM_MBCAST
;
1771 offset
= (info_element
->data
[2] >> 1)*2;
1773 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1775 if(ieee
->assoc_id
< 8*offset
||
1776 ieee
->assoc_id
> 8*(offset
+ info_element
->len
-3))
1780 offset
= (ieee
->assoc_id
/ 8) - offset
;// + ((aid % 8)? 0 : 1) ;
1782 if(info_element
->data
[3+offset
] & (1<<(ieee
->assoc_id
%8)))
1783 network
->dtim_data
|= IEEE80211_DTIM_UCAST
;
1785 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1789 network
->erp_value
= info_element
->data
[0];
1790 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1791 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1792 network
->erp_value
);
1794 case MFIE_TYPE_IBSS_SET
:
1795 network
->atim_window
= info_element
->data
[0];
1796 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1797 network
->atim_window
);
1800 case MFIE_TYPE_CHALLENGE
:
1801 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1804 case MFIE_TYPE_GENERIC
:
1805 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1807 if (!ieee80211_parse_qos_info_param_IE(info_element
,
1811 if (info_element
->len
>= 4 &&
1812 info_element
->data
[0] == 0x00 &&
1813 info_element
->data
[1] == 0x50 &&
1814 info_element
->data
[2] == 0xf2 &&
1815 info_element
->data
[3] == 0x01) {
1816 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1818 memcpy(network
->wpa_ie
, info_element
,
1819 network
->wpa_ie_len
);
1824 if (info_element
->len
== 7 &&
1825 info_element
->data
[0] == 0x00 &&
1826 info_element
->data
[1] == 0xe0 &&
1827 info_element
->data
[2] == 0x4c &&
1828 info_element
->data
[3] == 0x01 &&
1829 info_element
->data
[4] == 0x02) {
1830 network
->Turbo_Enable
= 1;
1834 //for HTcap and HTinfo parameters
1835 if(tmp_htcap_len
== 0){
1836 if(info_element
->len
>= 4 &&
1837 info_element
->data
[0] == 0x00 &&
1838 info_element
->data
[1] == 0x90 &&
1839 info_element
->data
[2] == 0x4c &&
1840 info_element
->data
[3] == 0x033){
1842 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1843 if(tmp_htcap_len
!= 0){
1844 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1845 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
1846 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
1847 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
1850 if(tmp_htcap_len
!= 0)
1851 network
->bssht
.bdSupportHT
= true;
1853 network
->bssht
.bdSupportHT
= false;
1857 if(tmp_htinfo_len
== 0){
1858 if(info_element
->len
>= 4 &&
1859 info_element
->data
[0] == 0x00 &&
1860 info_element
->data
[1] == 0x90 &&
1861 info_element
->data
[2] == 0x4c &&
1862 info_element
->data
[3] == 0x034){
1864 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1865 if(tmp_htinfo_len
!= 0){
1866 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1868 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
1869 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
1870 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
1878 if(ieee
->aggregation
){
1879 if(network
->bssht
.bdSupportHT
){
1880 if(info_element
->len
>= 4 &&
1881 info_element
->data
[0] == 0x00 &&
1882 info_element
->data
[1] == 0xe0 &&
1883 info_element
->data
[2] == 0x4c &&
1884 info_element
->data
[3] == 0x02){
1886 ht_realtek_agg_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1887 memcpy(ht_realtek_agg_buf
,info_element
->data
,info_element
->len
);
1890 if(ht_realtek_agg_len
>= 5){
1891 network
->bssht
.bdRT2RTAggregation
= true;
1893 if((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & 0x02))
1894 network
->bssht
.bdRT2RTLongSlotTime
= true;
1900 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1902 if((info_element
->len
>= 3 &&
1903 info_element
->data
[0] == 0x00 &&
1904 info_element
->data
[1] == 0x05 &&
1905 info_element
->data
[2] == 0xb5) ||
1906 (info_element
->len
>= 3 &&
1907 info_element
->data
[0] == 0x00 &&
1908 info_element
->data
[1] == 0x0a &&
1909 info_element
->data
[2] == 0xf7) ||
1910 (info_element
->len
>= 3 &&
1911 info_element
->data
[0] == 0x00 &&
1912 info_element
->data
[1] == 0x10 &&
1913 info_element
->data
[2] == 0x18)){
1915 network
->broadcom_cap_exist
= true;
1919 if(info_element
->len
>= 3 &&
1920 info_element
->data
[0] == 0x00 &&
1921 info_element
->data
[1] == 0x0c &&
1922 info_element
->data
[2] == 0x43)
1924 network
->ralink_cap_exist
= true;
1927 network
->ralink_cap_exist
= false;
1928 //added by amy for atheros AP
1929 if((info_element
->len
>= 3 &&
1930 info_element
->data
[0] == 0x00 &&
1931 info_element
->data
[1] == 0x03 &&
1932 info_element
->data
[2] == 0x7f) ||
1933 (info_element
->len
>= 3 &&
1934 info_element
->data
[0] == 0x00 &&
1935 info_element
->data
[1] == 0x13 &&
1936 info_element
->data
[2] == 0x74))
1938 printk("========>%s(): athros AP is exist\n",__FUNCTION__
);
1939 network
->atheros_cap_exist
= true;
1942 network
->atheros_cap_exist
= false;
1944 if(info_element
->len
>= 3 &&
1945 info_element
->data
[0] == 0x00 &&
1946 info_element
->data
[1] == 0x40 &&
1947 info_element
->data
[2] == 0x96)
1949 network
->cisco_cap_exist
= true;
1952 network
->cisco_cap_exist
= false;
1953 //added by amy for LEAP of cisco
1954 if(info_element
->len
> 4 &&
1955 info_element
->data
[0] == 0x00 &&
1956 info_element
->data
[1] == 0x40 &&
1957 info_element
->data
[2] == 0x96 &&
1958 info_element
->data
[3] == 0x01)
1960 if(info_element
->len
== 6)
1962 memcpy(network
->CcxRmState
, &info_element
[4], 2);
1963 if(network
->CcxRmState
[0] != 0)
1965 network
->bCcxRmEnable
= true;
1968 network
->bCcxRmEnable
= false;
1970 // CCXv4 Table 59-1 MBSSID Masks.
1972 network
->MBssidMask
= network
->CcxRmState
[1] & 0x07;
1973 if(network
->MBssidMask
!= 0)
1975 network
->bMBssidValid
= true;
1976 network
->MBssidMask
= 0xff << (network
->MBssidMask
);
1977 cpMacAddr(network
->MBssid
, network
->bssid
);
1978 network
->MBssid
[5] &= network
->MBssidMask
;
1982 network
->bMBssidValid
= false;
1987 network
->bCcxRmEnable
= false;
1990 if(info_element
->len
> 4 &&
1991 info_element
->data
[0] == 0x00 &&
1992 info_element
->data
[1] == 0x40 &&
1993 info_element
->data
[2] == 0x96 &&
1994 info_element
->data
[3] == 0x03)
1996 if(info_element
->len
== 5)
1998 network
->bWithCcxVerNum
= true;
1999 network
->BssCcxVerNumber
= info_element
->data
[4];
2003 network
->bWithCcxVerNum
= false;
2004 network
->BssCcxVerNumber
= 0;
2010 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2012 network
->rsn_ie_len
= min(info_element
->len
+ 2,
2014 memcpy(network
->rsn_ie
, info_element
,
2015 network
->rsn_ie_len
);
2018 //HT related element.
2019 case MFIE_TYPE_HT_CAP
:
2020 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2022 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2023 if(tmp_htcap_len
!= 0){
2024 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
2025 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
2026 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
2027 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
2029 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2030 // windows driver will update WMM parameters each beacon received once connected
2031 // Linux driver is a bit different.
2032 network
->bssht
.bdSupportHT
= true;
2035 network
->bssht
.bdSupportHT
= false;
2039 case MFIE_TYPE_HT_INFO
:
2040 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2042 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2044 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_IEEE
;
2045 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
2046 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
2047 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
2051 case MFIE_TYPE_AIRONET
:
2052 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2054 if(info_element
->len
>IE_CISCO_FLAG_POSITION
)
2056 network
->bWithAironetIE
= true;
2058 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2059 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2060 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2061 if( (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_MIC
) ||
2062 (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_PK
) )
2064 network
->bCkipSupported
= true;
2068 network
->bCkipSupported
= false;
2073 network
->bWithAironetIE
= false;
2074 network
->bCkipSupported
= false;
2077 case MFIE_TYPE_QOS_PARAMETER
:
2079 "QoS Error need to parse QOS_PARAMETER IE\n");
2082 case MFIE_TYPE_COUNTRY
:
2083 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2085 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2086 ieee80211_extract_country_ie(ieee
, info_element
, network
, network
->bssid
);//addr2 is same as addr3 when from an AP
2090 IEEE80211_DEBUG_MGMT
2091 ("Unsupported info element: %s (%d)\n",
2092 get_info_element_string(info_element
->id
),
2097 length
-= sizeof(*info_element
) + info_element
->len
;
2099 (struct ieee80211_info_element
*)&info_element
->
2100 data
[info_element
->len
];
2103 if(!network
->atheros_cap_exist
&& !network
->broadcom_cap_exist
&&
2104 !network
->cisco_cap_exist
&& !network
->ralink_cap_exist
&& !network
->bssht
.bdRT2RTAggregation
)
2106 network
->unknown_cap_exist
= true;
2110 network
->unknown_cap_exist
= false;
2115 static inline u8
ieee80211_SignalStrengthTranslate(
2121 // Step 1. Scale mapping.
2122 if(CurrSS
>= 71 && CurrSS
<= 100)
2124 RetSS
= 90 + ((CurrSS
- 70) / 3);
2126 else if(CurrSS
>= 41 && CurrSS
<= 70)
2128 RetSS
= 78 + ((CurrSS
- 40) / 3);
2130 else if(CurrSS
>= 31 && CurrSS
<= 40)
2132 RetSS
= 66 + (CurrSS
- 30);
2134 else if(CurrSS
>= 21 && CurrSS
<= 30)
2136 RetSS
= 54 + (CurrSS
- 20);
2138 else if(CurrSS
>= 5 && CurrSS
<= 20)
2140 RetSS
= 42 + (((CurrSS
- 5) * 2) / 3);
2142 else if(CurrSS
== 4)
2146 else if(CurrSS
== 3)
2150 else if(CurrSS
== 2)
2154 else if(CurrSS
== 1)
2162 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2164 // Step 2. Smoothing.
2166 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2171 long ieee80211_translate_todbm(u8 signal_strength_index
)// 0-100 index.
2173 long signal_power
; // in dBm.
2175 // Translate to dBm (x=0.5y-95).
2176 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
2179 return signal_power
;
2182 static inline int ieee80211_network_init(
2183 struct ieee80211_device
*ieee
,
2184 struct ieee80211_probe_response
*beacon
,
2185 struct ieee80211_network
*network
,
2186 struct ieee80211_rx_stats
*stats
)
2188 #ifdef CONFIG_IEEE80211_DEBUG
2189 //char rates_str[64];
2193 network
->qos_data
.active
= 0;
2194 network
->qos_data
.supported
= 0;
2195 network
->qos_data
.param_count
= 0;
2196 network
->qos_data
.old_param_count
= 0;
2198 /* Pull out fixed field data */
2199 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
2200 network
->capability
= le16_to_cpu(beacon
->capability
);
2201 network
->last_scanned
= jiffies
;
2202 network
->time_stamp
[0] = le32_to_cpu(beacon
->time_stamp
[0]);
2203 network
->time_stamp
[1] = le32_to_cpu(beacon
->time_stamp
[1]);
2204 network
->beacon_interval
= le32_to_cpu(beacon
->beacon_interval
);
2205 /* Where to pull this? beacon->listen_interval;*/
2206 network
->listen_interval
= 0x0A;
2207 network
->rates_len
= network
->rates_ex_len
= 0;
2208 network
->last_associate
= 0;
2209 network
->ssid_len
= 0;
2211 network
->atim_window
= 0;
2212 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
2214 network
->berp_info_valid
= false;
2215 network
->broadcom_cap_exist
= false;
2216 network
->ralink_cap_exist
= false;
2217 network
->atheros_cap_exist
= false;
2218 network
->cisco_cap_exist
= false;
2219 network
->unknown_cap_exist
= false;
2221 network
->Turbo_Enable
= 0;
2223 network
->CountryIeLen
= 0;
2224 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
2225 //Initialize HT parameters
2226 //ieee80211_ht_initialize(&network->bssht);
2227 HTInitializeBssDesc(&network
->bssht
);
2228 if (stats
->freq
== IEEE80211_52GHZ_BAND
) {
2229 /* for A band (No DS info) */
2230 network
->channel
= stats
->received_channel
;
2232 network
->flags
|= NETWORK_HAS_CCK
;
2234 network
->wpa_ie_len
= 0;
2235 network
->rsn_ie_len
= 0;
2237 if (ieee80211_parse_info_param
2238 (ieee
,beacon
->info_element
, stats
->len
- sizeof(*beacon
), network
, stats
))
2242 if (stats
->freq
== IEEE80211_52GHZ_BAND
)
2243 network
->mode
= IEEE_A
;
2245 if (network
->flags
& NETWORK_HAS_OFDM
)
2246 network
->mode
|= IEEE_G
;
2247 if (network
->flags
& NETWORK_HAS_CCK
)
2248 network
->mode
|= IEEE_B
;
2251 if (network
->mode
== 0) {
2252 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2254 escape_essid(network
->ssid
,
2260 if(network
->bssht
.bdSupportHT
){
2261 if(network
->mode
== IEEE_A
)
2262 network
->mode
= IEEE_N_5G
;
2263 else if(network
->mode
& (IEEE_G
| IEEE_B
))
2264 network
->mode
= IEEE_N_24G
;
2266 if (ieee80211_is_empty_essid(network
->ssid
, network
->ssid_len
))
2267 network
->flags
|= NETWORK_EMPTY_ESSID
;
2269 stats
->signal
= 30 + (stats
->SignalStrength
* 70) / 100;
2270 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2271 stats
->noise
= ieee80211_translate_todbm((u8
)(100-stats
->signal
)) -25;
2273 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
2278 static inline int is_same_network(struct ieee80211_network
*src
,
2279 struct ieee80211_network
*dst
, struct ieee80211_device
* ieee
)
2281 /* A network is only a duplicate if the channel, BSSID, ESSID
2282 * and the capability field (in particular IBSS and BSS) all match.
2283 * We treat all <hidden> with the same BSSID and channel
2285 return //((src->ssid_len == dst->ssid_len) &&
2286 (((src
->ssid_len
== dst
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) &&
2287 (src
->channel
== dst
->channel
) &&
2288 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
2289 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2290 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) &&
2291 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
2292 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
2293 ((src
->capability
& WLAN_CAPABILITY_BSS
) ==
2294 (dst
->capability
& WLAN_CAPABILITY_BSS
)));
2297 static inline void update_network(struct ieee80211_network
*dst
,
2298 struct ieee80211_network
*src
)
2303 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct ieee80211_rx_stats
));
2304 dst
->capability
= src
->capability
;
2305 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
2306 dst
->rates_len
= src
->rates_len
;
2307 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
2308 dst
->rates_ex_len
= src
->rates_ex_len
;
2309 if(src
->ssid_len
> 0)
2311 memset(dst
->ssid
, 0, dst
->ssid_len
);
2312 dst
->ssid_len
= src
->ssid_len
;
2313 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
2315 dst
->mode
= src
->mode
;
2316 dst
->flags
= src
->flags
;
2317 dst
->time_stamp
[0] = src
->time_stamp
[0];
2318 dst
->time_stamp
[1] = src
->time_stamp
[1];
2319 if (src
->flags
& NETWORK_HAS_ERP_VALUE
)
2321 dst
->erp_value
= src
->erp_value
;
2322 dst
->berp_info_valid
= src
->berp_info_valid
= true;
2324 dst
->beacon_interval
= src
->beacon_interval
;
2325 dst
->listen_interval
= src
->listen_interval
;
2326 dst
->atim_window
= src
->atim_window
;
2327 dst
->dtim_period
= src
->dtim_period
;
2328 dst
->dtim_data
= src
->dtim_data
;
2329 dst
->last_dtim_sta_time
[0] = src
->last_dtim_sta_time
[0];
2330 dst
->last_dtim_sta_time
[1] = src
->last_dtim_sta_time
[1];
2331 memcpy(&dst
->tim
, &src
->tim
, sizeof(struct ieee80211_tim_parameters
));
2333 dst
->bssht
.bdSupportHT
= src
->bssht
.bdSupportHT
;
2334 dst
->bssht
.bdRT2RTAggregation
= src
->bssht
.bdRT2RTAggregation
;
2335 dst
->bssht
.bdHTCapLen
= src
->bssht
.bdHTCapLen
;
2336 memcpy(dst
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapLen
);
2337 dst
->bssht
.bdHTInfoLen
= src
->bssht
.bdHTInfoLen
;
2338 memcpy(dst
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoLen
);
2339 dst
->bssht
.bdHTSpecVer
= src
->bssht
.bdHTSpecVer
;
2340 dst
->bssht
.bdRT2RTLongSlotTime
= src
->bssht
.bdRT2RTLongSlotTime
;
2341 dst
->broadcom_cap_exist
= src
->broadcom_cap_exist
;
2342 dst
->ralink_cap_exist
= src
->ralink_cap_exist
;
2343 dst
->atheros_cap_exist
= src
->atheros_cap_exist
;
2344 dst
->cisco_cap_exist
= src
->cisco_cap_exist
;
2345 dst
->unknown_cap_exist
= src
->unknown_cap_exist
;
2346 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
2347 dst
->wpa_ie_len
= src
->wpa_ie_len
;
2348 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
2349 dst
->rsn_ie_len
= src
->rsn_ie_len
;
2351 dst
->last_scanned
= jiffies
;
2352 /* qos related parameters */
2353 //qos_active = src->qos_data.active;
2354 qos_active
= dst
->qos_data
.active
;
2355 //old_param = dst->qos_data.old_param_count;
2356 old_param
= dst
->qos_data
.param_count
;
2357 if(dst
->flags
& NETWORK_HAS_QOS_MASK
)
2358 memcpy(&dst
->qos_data
, &src
->qos_data
,
2359 sizeof(struct ieee80211_qos_data
));
2361 dst
->qos_data
.supported
= src
->qos_data
.supported
;
2362 dst
->qos_data
.param_count
= src
->qos_data
.param_count
;
2365 if(dst
->qos_data
.supported
== 1) {
2366 dst
->QoS_Enable
= 1;
2369 ("QoS the network %s is QoS supported\n",
2373 ("QoS the network is QoS supported\n");
2375 dst
->qos_data
.active
= qos_active
;
2376 dst
->qos_data
.old_param_count
= old_param
;
2378 /* dst->last_associate is not overwritten */
2379 dst
->wmm_info
= src
->wmm_info
; //sure to exist in beacon or probe response frame.
2380 if(src
->wmm_param
[0].ac_aci_acm_aifsn
|| \
2381 src
->wmm_param
[1].ac_aci_acm_aifsn
|| \
2382 src
->wmm_param
[2].ac_aci_acm_aifsn
|| \
2383 src
->wmm_param
[3].ac_aci_acm_aifsn
) {
2384 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
2386 //dst->QoS_Enable = src->QoS_Enable;
2388 dst
->Turbo_Enable
= src
->Turbo_Enable
;
2391 dst
->CountryIeLen
= src
->CountryIeLen
;
2392 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
2394 //added by amy for LEAP
2395 dst
->bWithAironetIE
= src
->bWithAironetIE
;
2396 dst
->bCkipSupported
= src
->bCkipSupported
;
2397 memcpy(dst
->CcxRmState
,src
->CcxRmState
,2);
2398 dst
->bCcxRmEnable
= src
->bCcxRmEnable
;
2399 dst
->MBssidMask
= src
->MBssidMask
;
2400 dst
->bMBssidValid
= src
->bMBssidValid
;
2401 memcpy(dst
->MBssid
,src
->MBssid
,6);
2402 dst
->bWithCcxVerNum
= src
->bWithCcxVerNum
;
2403 dst
->BssCcxVerNumber
= src
->BssCcxVerNumber
;
2407 static inline int is_beacon(__le16 fc
)
2409 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == IEEE80211_STYPE_BEACON
);
2412 static inline void ieee80211_process_probe_response(
2413 struct ieee80211_device
*ieee
,
2414 struct ieee80211_probe_response
*beacon
,
2415 struct ieee80211_rx_stats
*stats
)
2417 struct ieee80211_network network
;
2418 struct ieee80211_network
*target
;
2419 struct ieee80211_network
*oldest
= NULL
;
2420 #ifdef CONFIG_IEEE80211_DEBUG
2421 struct ieee80211_info_element
*info_element
= &beacon
->info_element
[0];
2423 unsigned long flags
;
2427 memset(&network
, 0, sizeof(struct ieee80211_network
));
2428 IEEE80211_DEBUG_SCAN(
2429 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2430 escape_essid(info_element
->data
, info_element
->len
),
2431 beacon
->header
.addr3
,
2432 (beacon
->capability
& (1<<0xf)) ? '1' : '0',
2433 (beacon
->capability
& (1<<0xe)) ? '1' : '0',
2434 (beacon
->capability
& (1<<0xd)) ? '1' : '0',
2435 (beacon
->capability
& (1<<0xc)) ? '1' : '0',
2436 (beacon
->capability
& (1<<0xb)) ? '1' : '0',
2437 (beacon
->capability
& (1<<0xa)) ? '1' : '0',
2438 (beacon
->capability
& (1<<0x9)) ? '1' : '0',
2439 (beacon
->capability
& (1<<0x8)) ? '1' : '0',
2440 (beacon
->capability
& (1<<0x7)) ? '1' : '0',
2441 (beacon
->capability
& (1<<0x6)) ? '1' : '0',
2442 (beacon
->capability
& (1<<0x5)) ? '1' : '0',
2443 (beacon
->capability
& (1<<0x4)) ? '1' : '0',
2444 (beacon
->capability
& (1<<0x3)) ? '1' : '0',
2445 (beacon
->capability
& (1<<0x2)) ? '1' : '0',
2446 (beacon
->capability
& (1<<0x1)) ? '1' : '0',
2447 (beacon
->capability
& (1<<0x0)) ? '1' : '0');
2449 if (ieee80211_network_init(ieee
, beacon
, &network
, stats
)) {
2450 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2451 escape_essid(info_element
->data
,
2453 beacon
->header
.addr3
,
2454 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2455 IEEE80211_STYPE_PROBE_RESP
?
2456 "PROBE RESPONSE" : "BEACON");
2460 // For Asus EeePc request,
2461 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2462 // wireless adapter should follow the country code.
2463 // (2) If there is no any country code in beacon,
2464 // then wireless adapter should do active scan from ch1~11 and
2465 // passive scan from ch12~14
2467 if( !IsLegalChannel(ieee
, network
.channel
) )
2469 if(ieee
->bGlobalDomain
)
2471 if (WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) == IEEE80211_STYPE_PROBE_RESP
)
2473 // Case 1: Country code
2474 if(IS_COUNTRY_IE_VALID(ieee
) )
2476 if( !IsLegalChannel(ieee
, network
.channel
) )
2478 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network
.channel
);
2482 // Case 2: No any country code.
2485 // Filter over channel ch12~14
2486 if(network
.channel
> 11)
2488 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network
.channel
);
2495 // Case 1: Country code
2496 if(IS_COUNTRY_IE_VALID(ieee
) )
2498 if( !IsLegalChannel(ieee
, network
.channel
) )
2500 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network
.channel
);
2504 // Case 2: No any country code.
2507 // Filter over channel ch12~14
2508 if(network
.channel
> 14)
2510 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network
.channel
);
2517 /* The network parsed correctly -- so now we scan our known networks
2518 * to see if we can find it in our list.
2520 * NOTE: This search is definitely not optimized. Once its doing
2521 * the "right thing" we'll optimize it for efficiency if
2524 /* Search for this entry in the list and update it if it is
2527 spin_lock_irqsave(&ieee
->lock
, flags
);
2529 if(is_same_network(&ieee
->current_network
, &network
, ieee
)) {
2530 update_network(&ieee
->current_network
, &network
);
2531 if((ieee
->current_network
.mode
== IEEE_N_24G
|| ieee
->current_network
.mode
== IEEE_G
)
2532 && ieee
->current_network
.berp_info_valid
){
2533 if(ieee
->current_network
.erp_value
& ERP_UseProtection
)
2534 ieee
->current_network
.buseprotection
= true;
2536 ieee
->current_network
.buseprotection
= false;
2538 if(is_beacon(beacon
->header
.frame_ctl
))
2540 if(ieee
->state
== IEEE80211_LINKED
)
2541 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
++;
2544 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& ieee
->current_network
.flags
);
2547 list_for_each_entry(target
, &ieee
->network_list
, list
) {
2548 if (is_same_network(target
, &network
, ieee
))
2550 if ((oldest
== NULL
) ||
2551 (target
->last_scanned
< oldest
->last_scanned
))
2555 /* If we didn't find a match, then get a new network slot to initialize
2556 * with this beacon's information */
2557 if (&target
->list
== &ieee
->network_list
) {
2558 if (list_empty(&ieee
->network_free_list
)) {
2559 /* If there are no more slots, expire the oldest */
2560 list_del(&oldest
->list
);
2562 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2564 escape_essid(target
->ssid
,
2568 /* Otherwise just pull from the free list */
2569 target
= list_entry(ieee
->network_free_list
.next
,
2570 struct ieee80211_network
, list
);
2571 list_del(ieee
->network_free_list
.next
);
2575 #ifdef CONFIG_IEEE80211_DEBUG
2576 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2577 escape_essid(network
.ssid
,
2580 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2581 IEEE80211_STYPE_PROBE_RESP
?
2582 "PROBE RESPONSE" : "BEACON");
2584 memcpy(target
, &network
, sizeof(*target
));
2585 list_add_tail(&target
->list
, &ieee
->network_list
);
2586 if(ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
)
2587 ieee80211_softmac_new_net(ieee
,&network
);
2589 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2590 escape_essid(target
->ssid
,
2593 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2594 IEEE80211_STYPE_PROBE_RESP
?
2595 "PROBE RESPONSE" : "BEACON");
2597 /* we have an entry and we are going to update it. But this entry may
2598 * be already expired. In this case we do the same as we found a new
2599 * net and call the new_net handler
2601 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
);
2602 //YJ,add,080819,for hidden ap
2603 if(is_beacon(beacon
->header
.frame_ctl
) == 0)
2604 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& target
->flags
);
2605 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2606 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2607 if(((network
.flags
& NETWORK_EMPTY_ESSID
) == NETWORK_EMPTY_ESSID
) \
2608 && (((network
.ssid_len
> 0) && (strncmp(target
->ssid
, network
.ssid
, network
.ssid_len
)))\
2609 ||((ieee
->current_network
.ssid_len
== network
.ssid_len
)&&(strncmp(ieee
->current_network
.ssid
, network
.ssid
, network
.ssid_len
) == 0)&&(ieee
->state
== IEEE80211_NOLINK
))))
2611 //YJ,add,080819,for hidden ap,end
2613 update_network(target
, &network
);
2614 if(renew
&& (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
))
2615 ieee80211_softmac_new_net(ieee
,&network
);
2618 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2619 if (is_beacon(beacon
->header
.frame_ctl
)&&is_same_network(&ieee
->current_network
, &network
, ieee
)&&\
2620 (ieee
->state
== IEEE80211_LINKED
)) {
2621 if(ieee
->handle_beacon
!= NULL
) {
2622 ieee
->handle_beacon(ieee
->dev
,beacon
,&ieee
->current_network
);
2627 void ieee80211_rx_mgt(struct ieee80211_device
*ieee
,
2628 struct ieee80211_hdr_4addr
*header
,
2629 struct ieee80211_rx_stats
*stats
)
2631 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
2633 case IEEE80211_STYPE_BEACON
:
2634 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2635 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2636 IEEE80211_DEBUG_SCAN("Beacon\n");
2637 ieee80211_process_probe_response(
2638 ieee
, (struct ieee80211_probe_response
*)header
, stats
);
2641 case IEEE80211_STYPE_PROBE_RESP
:
2642 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2643 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2644 IEEE80211_DEBUG_SCAN("Probe response\n");
2645 ieee80211_process_probe_response(
2646 ieee
, (struct ieee80211_probe_response
*)header
, stats
);
2652 EXPORT_SYMBOL(ieee80211_rx_mgt
);
2653 EXPORT_SYMBOL(ieee80211_rx
);