2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
14 ******************************************************************************
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
19 A special thanks goes to Realtek for their support !
21 ******************************************************************************/
24 #include <linux/compiler.h>
25 //#include <linux/config.h>
26 #include <linux/errno.h>
27 #include <linux/if_arp.h>
28 #include <linux/in6.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <linux/pci.h>
35 #include <linux/proc_fs.h>
36 #include <linux/skbuff.h>
37 #include <linux/slab.h>
38 #include <linux/tcp.h>
39 #include <linux/types.h>
40 #include <linux/wireless.h>
41 #include <linux/etherdevice.h>
42 #include <asm/uaccess.h>
43 #include <linux/ctype.h>
45 #include "ieee80211.h"
47 static inline void ieee80211_monitor_rx(struct ieee80211_device
*ieee
,
49 struct ieee80211_rx_stats
*rx_stats
)
51 struct ieee80211_hdr_4addr
*hdr
=
52 (struct ieee80211_hdr_4addr
*)skb
->data
;
53 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
56 skb_reset_mac_header(skb
);
57 skb_pull(skb
, ieee80211_get_hdrlen(fc
));
58 skb
->pkt_type
= PACKET_OTHERHOST
;
59 skb
->protocol
= __constant_htons(ETH_P_80211_RAW
);
60 memset(skb
->cb
, 0, sizeof(skb
->cb
));
65 /* Called only as a tasklet (software IRQ) */
66 static struct ieee80211_frag_entry
*
67 ieee80211_frag_cache_find(struct ieee80211_device
*ieee
, unsigned int seq
,
68 unsigned int frag
, u8 tid
,u8
*src
, u8
*dst
)
70 struct ieee80211_frag_entry
*entry
;
73 for (i
= 0; i
< IEEE80211_FRAG_CACHE_LEN
; i
++) {
74 entry
= &ieee
->frag_cache
[tid
][i
];
75 if (entry
->skb
!= NULL
&&
76 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
78 "expiring fragment cache entry "
79 "seq=%u last_frag=%u\n",
80 entry
->seq
, entry
->last_frag
);
81 dev_kfree_skb_any(entry
->skb
);
85 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
86 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
87 memcmp(entry
->src_addr
, src
, ETH_ALEN
) == 0 &&
88 memcmp(entry
->dst_addr
, dst
, ETH_ALEN
) == 0)
95 /* Called only as a tasklet (software IRQ) */
96 static struct sk_buff
*
97 ieee80211_frag_cache_get(struct ieee80211_device
*ieee
,
98 struct ieee80211_hdr_4addr
*hdr
)
100 struct sk_buff
*skb
= NULL
;
101 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
102 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
103 unsigned int frag
= WLAN_GET_SEQ_FRAG(sc
);
104 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
105 struct ieee80211_frag_entry
*entry
;
106 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
107 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
110 if (((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
111 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
112 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QOS_TID
;
115 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
116 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
117 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QOS_TID
;
125 /* Reserve enough space to fit maximum frame length */
126 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
127 sizeof(struct ieee80211_hdr_4addr
) +
132 (IEEE80211_QOS_HAS_SEQ(fc
)?2:0) /* QOS Control */);
136 entry
= &ieee
->frag_cache
[tid
][ieee
->frag_next_idx
[tid
]];
137 ieee
->frag_next_idx
[tid
]++;
138 if (ieee
->frag_next_idx
[tid
] >= IEEE80211_FRAG_CACHE_LEN
)
139 ieee
->frag_next_idx
[tid
] = 0;
141 if (entry
->skb
!= NULL
)
142 dev_kfree_skb_any(entry
->skb
);
144 entry
->first_frag_time
= jiffies
;
146 entry
->last_frag
= frag
;
148 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
149 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
151 /* received a fragment of a frame for which the head fragment
152 * should have already been received */
153 entry
= ieee80211_frag_cache_find(ieee
, seq
, frag
, tid
,hdr
->addr2
,
156 entry
->last_frag
= frag
;
165 /* Called only as a tasklet (software IRQ) */
166 static int ieee80211_frag_cache_invalidate(struct ieee80211_device
*ieee
,
167 struct ieee80211_hdr_4addr
*hdr
)
169 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
170 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
171 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
172 struct ieee80211_frag_entry
*entry
;
173 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
174 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
177 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
178 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)hdr
;
179 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QOS_TID
;
182 } else if (IEEE80211_QOS_HAS_SEQ(fc
)) {
183 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)hdr
;
184 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QOS_TID
;
191 entry
= ieee80211_frag_cache_find(ieee
, seq
, -1, tid
,hdr
->addr2
,
195 IEEE80211_DEBUG_FRAG(
196 "could not invalidate fragment cache "
197 "entry (seq=%u)\n", seq
);
207 /* ieee80211_rx_frame_mgtmt
209 * Responsible for handling management control frames
211 * Called by ieee80211_rx */
213 ieee80211_rx_frame_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
214 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
217 struct ieee80211_hdr_4addr
*hdr
;
219 // cheat the the hdr type
220 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
222 /* On the struct stats definition there is written that
223 * this is not mandatory.... but seems that the probe
224 * response parser uses it
226 rx_stats
->len
= skb
->len
;
227 ieee80211_rx_mgt(ieee
, (struct ieee80211_hdr_4addr
*)skb
->data
,
230 if((ieee
->state
== IEEE80211_LINKED
)&&(memcmp(hdr
->addr3
,ieee
->current_network
.bssid
,ETH_ALEN
))) {
231 dev_kfree_skb_any(skb
);
235 ieee80211_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
237 dev_kfree_skb_any(skb
);
245 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
246 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
247 static unsigned char rfc1042_header
[] =
248 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
249 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
250 static unsigned char bridge_tunnel_header
[] =
251 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
252 /* No encapsulation header if EtherType < 0x600 (=length) */
254 /* Called by ieee80211_rx_frame_decrypt */
255 static int ieee80211_is_eapol_frame(struct ieee80211_device
*ieee
,
256 struct sk_buff
*skb
, size_t hdrlen
)
258 struct net_device
*dev
= ieee
->dev
;
260 struct ieee80211_hdr_4addr
*hdr
;
266 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
267 fc
= le16_to_cpu(hdr
->frame_ctl
);
269 /* check that the frame is unicast frame to us */
270 if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
271 IEEE80211_FCTL_TODS
&&
272 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
273 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
274 /* ToDS frame with own addr BSSID and DA */
275 } else if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
276 IEEE80211_FCTL_FROMDS
&&
277 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
278 /* FromDS frame with own addr as DA */
282 if (skb
->len
< 24 + 8)
285 /* check for port access entity Ethernet type */
286 // pos = skb->data + 24;
287 pos
= skb
->data
+ hdrlen
;
288 ethertype
= (pos
[6] << 8) | pos
[7];
289 if (ethertype
== ETH_P_PAE
)
295 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
297 ieee80211_rx_frame_decrypt(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
298 struct ieee80211_crypt_data
*crypt
)
300 struct ieee80211_hdr_4addr
*hdr
;
303 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
306 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
307 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
309 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
310 if (ieee
->tkip_countermeasures
&&
311 strcmp(crypt
->ops
->name
, "TKIP") == 0) {
312 if (net_ratelimit()) {
313 printk(KERN_DEBUG
"%s: TKIP countermeasures: dropped "
314 "received packet from " MAC_FMT
"\n",
315 ieee
->dev
->name
, MAC_ARG(hdr
->addr2
));
321 atomic_inc(&crypt
->refcnt
);
322 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
323 atomic_dec(&crypt
->refcnt
);
325 IEEE80211_DEBUG_DROP(
326 "decryption failed (SA=" MAC_FMT
327 ") res=%d\n", MAC_ARG(hdr
->addr2
), res
);
329 IEEE80211_DEBUG_DROP("Decryption failed ICV "
330 "mismatch (key %d)\n",
331 skb
->data
[hdrlen
+ 3] >> 6);
332 ieee
->ieee_stats
.rx_discards_undecryptable
++;
340 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
342 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device
* ieee
, struct sk_buff
*skb
,
343 int keyidx
, struct ieee80211_crypt_data
*crypt
)
345 struct ieee80211_hdr_4addr
*hdr
;
348 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
351 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
352 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
354 atomic_inc(&crypt
->refcnt
);
355 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
356 atomic_dec(&crypt
->refcnt
);
358 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
359 " (SA=" MAC_FMT
" keyidx=%d)\n",
360 ieee
->dev
->name
, MAC_ARG(hdr
->addr2
), keyidx
);
368 /* this function is stolen from ipw2200 driver*/
369 #define IEEE_PACKET_RETRY_TIME (5*HZ)
370 static int is_duplicate_packet(struct ieee80211_device
*ieee
,
371 struct ieee80211_hdr_4addr
*header
)
373 u16 fc
= le16_to_cpu(header
->frame_ctl
);
374 u16 sc
= le16_to_cpu(header
->seq_ctl
);
375 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
376 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
377 u16
*last_seq
, *last_frag
;
378 unsigned long *last_time
;
379 struct ieee80211_hdr_3addrqos
*hdr_3addrqos
;
380 struct ieee80211_hdr_4addrqos
*hdr_4addrqos
;
384 if(((fc
& IEEE80211_FCTL_DSTODS
) == IEEE80211_FCTL_DSTODS
)&&IEEE80211_QOS_HAS_SEQ(fc
)) {
385 hdr_4addrqos
= (struct ieee80211_hdr_4addrqos
*)header
;
386 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & IEEE80211_QOS_TID
;
389 } else if(IEEE80211_QOS_HAS_SEQ(fc
)) { //QoS
390 hdr_3addrqos
= (struct ieee80211_hdr_3addrqos
*)header
;
391 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & IEEE80211_QOS_TID
;
397 switch (ieee
->iw_mode
) {
401 struct ieee_ibss_seq
*entry
= NULL
;
402 u8
*mac
= header
->addr2
;
403 int index
= mac
[5] % IEEE_IBSS_MAC_HASH_SIZE
;
404 //for (pos = (head)->next; pos != (head); pos = pos->next)
405 __list_for_each(p
, &ieee
->ibss_mac_hash
[index
]) {
406 entry
= list_entry(p
, struct ieee_ibss_seq
, list
);
407 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
410 // if (memcmp(entry->mac, mac, ETH_ALEN)){
411 if (p
== &ieee
->ibss_mac_hash
[index
]) {
412 entry
= kmalloc(sizeof(struct ieee_ibss_seq
), GFP_ATOMIC
);
414 printk(KERN_WARNING
"Cannot malloc new mac entry\n");
417 memcpy(entry
->mac
, mac
, ETH_ALEN
);
418 entry
->seq_num
[tid
] = seq
;
419 entry
->frag_num
[tid
] = frag
;
420 entry
->packet_time
[tid
] = jiffies
;
421 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
424 last_seq
= &entry
->seq_num
[tid
];
425 last_frag
= &entry
->frag_num
[tid
];
426 last_time
= &entry
->packet_time
[tid
];
431 last_seq
= &ieee
->last_rxseq_num
[tid
];
432 last_frag
= &ieee
->last_rxfrag_num
[tid
];
433 last_time
= &ieee
->last_packet_time
[tid
];
441 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
443 if ((*last_seq
== seq
) &&
444 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
445 if (*last_frag
== frag
){
446 //printk(KERN_WARNING "[1] go drop!\n");
450 if (*last_frag
+ 1 != frag
)
451 /* out-of-order fragment */
452 //printk(KERN_WARNING "[2] go drop!\n");
458 *last_time
= jiffies
;
462 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
469 /* All received frames are sent to this function. @skb contains the frame in
470 * IEEE 802.11 format, i.e., in the format it was sent over air.
471 * This function is called only as a tasklet (software IRQ). */
472 int ieee80211_rtl_rx(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
473 struct ieee80211_rx_stats
*rx_stats
)
475 struct net_device
*dev
= ieee
->dev
;
476 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
477 struct ieee80211_hdr_4addr
*hdr
;
480 u16 fc
, type
, stype
, sc
;
481 struct net_device_stats
*stats
;
488 struct ieee80211_crypt_data
*crypt
= NULL
;
491 // cheat the the hdr type
492 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
493 stats
= &ieee
->stats
;
496 printk(KERN_INFO
"%s: SKB length < 10\n",
501 fc
= le16_to_cpu(hdr
->frame_ctl
);
502 type
= WLAN_FC_GET_TYPE(fc
);
503 stype
= WLAN_FC_GET_STYPE(fc
);
504 sc
= le16_to_cpu(hdr
->seq_ctl
);
506 frag
= WLAN_GET_SEQ_FRAG(sc
);
508 //YJ,add,080828,for keep alive
509 if((fc
& IEEE80211_FCTL_TODS
) != IEEE80211_FCTL_TODS
)
511 if(!memcmp(hdr
->addr1
,dev
->dev_addr
, ETH_ALEN
))
513 ieee
->NumRxUnicast
++;
518 if(!memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
))
520 ieee
->NumRxUnicast
++;
523 //YJ,add,080828,for keep alive,end
525 hdrlen
= ieee80211_get_hdrlen(fc
);
528 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
529 ieee80211_monitor_rx(ieee
, skb
, rx_stats
);
531 stats
->rx_bytes
+= skb
->len
;
535 if (ieee
->host_decrypt
) {
537 if (skb
->len
>= hdrlen
+ 3)
538 idx
= skb
->data
[hdrlen
+ 3] >> 6;
539 crypt
= ieee
->crypt
[idx
];
541 /* allow NULL decrypt to indicate an station specific override
542 * for default encryption */
543 if (crypt
&& (crypt
->ops
== NULL
||
544 crypt
->ops
->decrypt_mpdu
== NULL
))
547 if (!crypt
&& (fc
& IEEE80211_FCTL_WEP
)) {
548 /* This seems to be triggered by some (multicast?)
549 * frames from other than current BSS, so just drop the
550 * frames silently instead of filling system log with
552 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
553 " (SA=" MAC_FMT
")\n",
554 MAC_ARG(hdr
->addr2
));
555 ieee
->ieee_stats
.rx_discards_undecryptable
++;
560 if (skb
->len
< IEEE80211_DATA_HDR3_LEN
)
563 // if QoS enabled, should check the sequence for each of the AC
564 if (is_duplicate_packet(ieee
, hdr
))
568 if (type
== IEEE80211_FTYPE_MGMT
) {
569 if (ieee80211_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
575 /* Data frame - extract src/dst addresses */
576 switch (fc
& (IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
)) {
577 case IEEE80211_FCTL_FROMDS
:
578 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
579 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
580 memcpy(bssid
,hdr
->addr2
,ETH_ALEN
);
582 case IEEE80211_FCTL_TODS
:
583 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
584 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
585 memcpy(bssid
,hdr
->addr1
,ETH_ALEN
);
587 case IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
:
588 if (skb
->len
< IEEE80211_DATA_HDR4_LEN
)
590 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
591 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
592 memcpy(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
595 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
596 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
597 memcpy(bssid
,hdr
->addr3
,ETH_ALEN
);
602 dev
->last_rx
= jiffies
;
605 /* Nullfunc frames may have PS-bit set, so they must be passed to
606 * hostap_handle_sta_rx() before being dropped here. */
607 if (stype
!= IEEE80211_STYPE_DATA
&&
608 stype
!= IEEE80211_STYPE_DATA_CFACK
&&
609 stype
!= IEEE80211_STYPE_DATA_CFPOLL
&&
610 stype
!= IEEE80211_STYPE_DATA_CFACKPOLL
&&
611 stype
!= IEEE80211_STYPE_QOS_DATA
//add by David,2006.8.4
613 if (stype
!= IEEE80211_STYPE_NULLFUNC
)
614 IEEE80211_DEBUG_DROP(
615 "RX: dropped data frame "
616 "with no data (type=0x%02x, "
617 "subtype=0x%02x, len=%d)\n",
618 type
, stype
, skb
->len
);
621 if(memcmp(bssid
,ieee
->current_network
.bssid
,ETH_ALEN
)) {
625 ieee
->NumRxDataInPeriod
++;
626 ieee
->NumRxOkTotal
++;
627 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
629 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
630 (keyidx
= ieee80211_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0)
633 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
635 /* skb: hdr + (possibly fragmented) plaintext payload */
636 // PR: FIXME: hostap has additional conditions in the "if" below:
637 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
638 if ((frag
!= 0 || (fc
& IEEE80211_FCTL_MOREFRAGS
))) {
640 struct sk_buff
*frag_skb
= ieee80211_frag_cache_get(ieee
, hdr
);
641 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
644 IEEE80211_DEBUG(IEEE80211_DL_RX
| IEEE80211_DL_FRAG
,
645 "Rx cannot get skb from fragment "
646 "cache (morefrag=%d seq=%u frag=%u)\n",
647 (fc
& IEEE80211_FCTL_MOREFRAGS
) != 0,
648 WLAN_GET_SEQ_SEQ(sc
), frag
);
655 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
656 printk(KERN_WARNING
"%s: host decrypted and "
657 "reassembled frame did not fit skb\n",
659 ieee80211_frag_cache_invalidate(ieee
, hdr
);
664 /* copy first fragment (including full headers) into
665 * beginning of the fragment cache skb */
666 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
668 /* append frame payload to the end of the fragment
670 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
673 dev_kfree_skb_any(skb
);
676 if (fc
& IEEE80211_FCTL_MOREFRAGS
) {
677 /* more fragments expected - leave the skb in fragment
678 * cache for now; it will be delivered to upper layers
679 * after all fragments have been received */
683 /* this was the last fragment and the frame will be
684 * delivered, so remove skb from fragment cache */
686 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
687 ieee80211_frag_cache_invalidate(ieee
, hdr
);
690 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
691 * encrypted/authenticated */
692 if (ieee
->host_decrypt
&& (fc
& IEEE80211_FCTL_WEP
) &&
693 ieee80211_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
))
696 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
697 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
) {
698 if (/*ieee->ieee802_1x &&*/
699 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
701 #ifdef CONFIG_IEEE80211_DEBUG
702 /* pass unencrypted EAPOL frames even if encryption is
704 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
706 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
707 eap_get_type(eap
->type
));
710 IEEE80211_DEBUG_DROP(
711 "encryption configured, but RX "
712 "frame not encrypted (SA=" MAC_FMT
")\n",
713 MAC_ARG(hdr
->addr2
));
718 #ifdef CONFIG_IEEE80211_DEBUG
719 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) &&
720 ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
721 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
723 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
724 eap_get_type(eap
->type
));
728 if (crypt
&& !(fc
& IEEE80211_FCTL_WEP
) && !ieee
->open_wep
&&
729 !ieee80211_is_eapol_frame(ieee
, skb
, hdrlen
)) {
730 IEEE80211_DEBUG_DROP(
731 "dropped unencrypted RX data "
732 "frame from " MAC_FMT
733 " (drop_unencrypted=1)\n",
734 MAC_ARG(hdr
->addr2
));
738 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
739 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
742 /* skb: hdr + (possible reassembled) full plaintext payload */
743 payload
= skb
->data
+ hdrlen
;
744 ethertype
= (payload
[6] << 8) | payload
[7];
747 /* convert hdr + possible LLC headers into Ethernet header */
748 if (skb
->len
- hdrlen
>= 8 &&
749 ((memcmp(payload
, rfc1042_header
, SNAP_SIZE
) == 0 &&
750 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
751 memcmp(payload
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
752 /* remove RFC1042 or Bridge-Tunnel encapsulation and
753 * replace EtherType */
754 skb_pull(skb
, hdrlen
+ SNAP_SIZE
);
755 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
756 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
759 /* Leave Ethernet header part of hdr and full payload */
760 skb_pull(skb
, hdrlen
);
761 len
= htons(skb
->len
);
762 memcpy(skb_push(skb
, 2), &len
, 2);
763 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
764 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
769 stats
->rx_bytes
+= skb
->len
;
772 skb
->protocol
= eth_type_trans(skb
, dev
);
773 memset(skb
->cb
, 0, sizeof(skb
->cb
));
775 skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
776 ieee
->last_rx_ps_time
= jiffies
;
786 /* Returning 0 indicates to caller that we have not handled the SKB--
787 * so it is still allocated and can be used again by underlying
788 * hardware as a DMA target */
792 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
794 static inline int ieee80211_is_ofdm_rate(u8 rate
)
796 switch (rate
& ~IEEE80211_BASIC_RATE_MASK
) {
797 case IEEE80211_OFDM_RATE_6MB
:
798 case IEEE80211_OFDM_RATE_9MB
:
799 case IEEE80211_OFDM_RATE_12MB
:
800 case IEEE80211_OFDM_RATE_18MB
:
801 case IEEE80211_OFDM_RATE_24MB
:
802 case IEEE80211_OFDM_RATE_36MB
:
803 case IEEE80211_OFDM_RATE_48MB
:
804 case IEEE80211_OFDM_RATE_54MB
:
810 static inline int ieee80211_SignalStrengthTranslate(
816 // Step 1. Scale mapping.
817 if(CurrSS
>= 71 && CurrSS
<= 100)
819 RetSS
= 90 + ((CurrSS
- 70) / 3);
821 else if(CurrSS
>= 41 && CurrSS
<= 70)
823 RetSS
= 78 + ((CurrSS
- 40) / 3);
825 else if(CurrSS
>= 31 && CurrSS
<= 40)
827 RetSS
= 66 + (CurrSS
- 30);
829 else if(CurrSS
>= 21 && CurrSS
<= 30)
831 RetSS
= 54 + (CurrSS
- 20);
833 else if(CurrSS
>= 5 && CurrSS
<= 20)
835 RetSS
= 42 + (((CurrSS
- 5) * 2) / 3);
857 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
859 // Step 2. Smoothing.
861 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
866 static inline void ieee80211_extract_country_ie(
867 struct ieee80211_device
*ieee
,
868 struct ieee80211_info_element
*info_element
,
869 struct ieee80211_network
*network
,
873 if(IS_DOT11D_ENABLE(ieee
))
875 if(info_element
->len
!= 0)
877 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
878 network
->CountryIeLen
= info_element
->len
;
880 if(!IS_COUNTRY_IE_VALID(ieee
))
882 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
887 // 070305, rcnjko: I update country IE watch dog here because
888 // some AP (e.g. Cisco 1242) don't include country IE in their
889 // probe response frame.
891 if(IS_EQUAL_CIE_SRC(ieee
, addr2
) )
893 UPDATE_CIE_WATCHDOG(ieee
);
900 ieee80211_TranslateToDbm(
901 unsigned char SignalStrengthIndex
// 0-100 index.
904 unsigned char SignalPower
; // in dBm.
906 // Translate to dBm (x=0.5y-95).
907 SignalPower
= (int)SignalStrengthIndex
* 7 / 10;
912 inline int ieee80211_network_init(
913 struct ieee80211_device
*ieee
,
914 struct ieee80211_probe_response
*beacon
,
915 struct ieee80211_network
*network
,
916 struct ieee80211_rx_stats
*stats
)
918 #ifdef CONFIG_IEEE80211_DEBUG
922 struct ieee80211_info_element
*info_element
;
926 u8 curRate
= 0,hOpRate
= 0,curRate_ex
= 0;
928 /* Pull out fixed field data */
929 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
930 network
->capability
= beacon
->capability
;
931 network
->last_scanned
= jiffies
;
932 network
->time_stamp
[0] = beacon
->time_stamp
[0];
933 network
->time_stamp
[1] = beacon
->time_stamp
[1];
934 network
->beacon_interval
= beacon
->beacon_interval
;
935 /* Where to pull this? beacon->listen_interval;*/
936 network
->listen_interval
= 0x0A;
937 network
->rates_len
= network
->rates_ex_len
= 0;
938 network
->last_associate
= 0;
939 network
->ssid_len
= 0;
941 network
->atim_window
= 0;
942 network
->QoS_Enable
= 0;
944 network
->HighestOperaRate
= 0;
946 network
->Turbo_Enable
= 0;
947 network
->CountryIeLen
= 0;
948 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
950 if (stats
->freq
== IEEE80211_52GHZ_BAND
) {
951 /* for A band (No DS info) */
952 network
->channel
= stats
->received_channel
;
954 network
->flags
|= NETWORK_HAS_CCK
;
956 network
->wpa_ie_len
= 0;
957 network
->rsn_ie_len
= 0;
959 info_element
= &beacon
->info_element
;
960 left
= stats
->len
- ((void *)info_element
- (void *)beacon
);
961 while (left
>= sizeof(struct ieee80211_info_element_hdr
)) {
962 if (sizeof(struct ieee80211_info_element_hdr
) + info_element
->len
> left
) {
963 IEEE80211_DEBUG_SCAN("SCAN: parse failed: info_element->len + 2 > left : info_element->len+2=%d left=%d.\n",
964 info_element
->len
+ sizeof(struct ieee80211_info_element
),
969 switch (info_element
->id
) {
971 if (ieee80211_is_empty_essid(info_element
->data
,
972 info_element
->len
)) {
973 network
->flags
|= NETWORK_EMPTY_ESSID
;
977 network
->ssid_len
= min(info_element
->len
,
978 (u8
)IW_ESSID_MAX_SIZE
);
979 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
980 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
981 memset(network
->ssid
+ network
->ssid_len
, 0,
982 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
984 IEEE80211_DEBUG_SCAN("MFIE_TYPE_SSID: '%s' len=%d.\n",
985 network
->ssid
, network
->ssid_len
);
988 case MFIE_TYPE_RATES
:
989 #ifdef CONFIG_IEEE80211_DEBUG
992 network
->rates_len
= min(info_element
->len
, MAX_RATES_LENGTH
);
993 for (i
= 0; i
< network
->rates_len
; i
++) {
994 network
->rates
[i
] = info_element
->data
[i
];
995 curRate
= network
->rates
[i
] & 0x7f;
996 if( hOpRate
< curRate
)
998 #ifdef CONFIG_IEEE80211_DEBUG
999 p
+= snprintf(p
, sizeof(rates_str
) - (p
- rates_str
), "%02X ", network
->rates
[i
]);
1001 if (ieee80211_is_ofdm_rate(info_element
->data
[i
])) {
1002 network
->flags
|= NETWORK_HAS_OFDM
;
1003 if (info_element
->data
[i
] &
1004 IEEE80211_BASIC_RATE_MASK
)
1010 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES: '%s' (%d)\n",
1011 rates_str
, network
->rates_len
);
1014 case MFIE_TYPE_RATES_EX
:
1015 #ifdef CONFIG_IEEE80211_DEBUG
1018 network
->rates_ex_len
= min(info_element
->len
, MAX_RATES_EX_LENGTH
);
1019 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1020 network
->rates_ex
[i
] = info_element
->data
[i
];
1021 curRate_ex
= network
->rates_ex
[i
] & 0x7f;
1022 if( hOpRate
< curRate_ex
)
1023 hOpRate
= curRate_ex
;
1024 #ifdef CONFIG_IEEE80211_DEBUG
1025 p
+= snprintf(p
, sizeof(rates_str
) - (p
- rates_str
), "%02X ", network
->rates
[i
]);
1027 if (ieee80211_is_ofdm_rate(info_element
->data
[i
])) {
1028 network
->flags
|= NETWORK_HAS_OFDM
;
1029 if (info_element
->data
[i
] &
1030 IEEE80211_BASIC_RATE_MASK
)
1036 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1037 rates_str
, network
->rates_ex_len
);
1040 case MFIE_TYPE_DS_SET
:
1041 IEEE80211_DEBUG_SCAN("MFIE_TYPE_DS_SET: %d\n",
1042 info_element
->data
[0]);
1043 if (stats
->freq
== IEEE80211_24GHZ_BAND
)
1044 network
->channel
= info_element
->data
[0];
1047 case MFIE_TYPE_FH_SET
:
1048 IEEE80211_DEBUG_SCAN("MFIE_TYPE_FH_SET: ignored\n");
1051 case MFIE_TYPE_CF_SET
:
1052 IEEE80211_DEBUG_SCAN("MFIE_TYPE_CF_SET: ignored\n");
1057 if(info_element
->len
< 4)
1060 network
->dtim_period
= info_element
->data
[1];
1062 if(ieee
->state
!= IEEE80211_LINKED
)
1065 network
->last_dtim_sta_time
[0] = jiffies
;
1066 network
->last_dtim_sta_time
[1] = stats
->mac_time
[1];
1068 network
->dtim_data
= IEEE80211_DTIM_VALID
;
1070 if(info_element
->data
[0] != 0)
1073 if(info_element
->data
[2] & 1)
1074 network
->dtim_data
|= IEEE80211_DTIM_MBCAST
;
1076 offset
= (info_element
->data
[2] >> 1)*2;
1078 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1080 /* add and modified for ps 2008.1.22 */
1081 if(ieee
->assoc_id
< 8*offset
||
1082 ieee
->assoc_id
> 8*(offset
+ info_element
->len
-3)) {
1086 offset
= (ieee
->assoc_id
/8) - offset
;// + ((aid % 8)? 0 : 1) ;
1088 // printk("offset:%x data:%x, ucast:%d\n", offset,
1089 // info_element->data[3+offset] ,
1090 // info_element->data[3+offset] & (1<<(ieee->assoc_id%8)));
1092 if(info_element
->data
[3+offset
] & (1<<(ieee
->assoc_id
%8))) {
1093 network
->dtim_data
|= IEEE80211_DTIM_UCAST
;
1097 case MFIE_TYPE_IBSS_SET
:
1098 IEEE80211_DEBUG_SCAN("MFIE_TYPE_IBSS_SET: ignored\n");
1101 case MFIE_TYPE_CHALLENGE
:
1102 IEEE80211_DEBUG_SCAN("MFIE_TYPE_CHALLENGE: ignored\n");
1105 case MFIE_TYPE_GENERIC
:
1107 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n",
1109 if (info_element
->len
>= 4 &&
1110 info_element
->data
[0] == 0x00 &&
1111 info_element
->data
[1] == 0x50 &&
1112 info_element
->data
[2] == 0xf2 &&
1113 info_element
->data
[3] == 0x01) {
1114 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1116 memcpy(network
->wpa_ie
, info_element
,
1117 network
->wpa_ie_len
);
1120 if (info_element
->len
== 7 &&
1121 info_element
->data
[0] == 0x00 &&
1122 info_element
->data
[1] == 0xe0 &&
1123 info_element
->data
[2] == 0x4c &&
1124 info_element
->data
[3] == 0x01 &&
1125 info_element
->data
[4] == 0x02) {
1126 network
->Turbo_Enable
= 1;
1128 if (1 == stats
->nic_type
) {//nic 87
1132 if (info_element
->len
>= 5 &&
1133 info_element
->data
[0] == 0x00 &&
1134 info_element
->data
[1] == 0x50 &&
1135 info_element
->data
[2] == 0xf2 &&
1136 info_element
->data
[3] == 0x02 &&
1137 info_element
->data
[4] == 0x00) {
1138 //printk(KERN_WARNING "wmm info updated: %x\n", info_element->data[6]);
1139 //WMM Information Element
1140 network
->wmm_info
= info_element
->data
[6];
1141 network
->QoS_Enable
= 1;
1144 if (info_element
->len
>= 8 &&
1145 info_element
->data
[0] == 0x00 &&
1146 info_element
->data
[1] == 0x50 &&
1147 info_element
->data
[2] == 0xf2 &&
1148 info_element
->data
[3] == 0x02 &&
1149 info_element
->data
[4] == 0x01) {
1150 // Not care about version at present.
1151 //WMM Information Element
1152 //printk(KERN_WARNING "wmm info¶m updated: %x\n", info_element->data[6]);
1153 network
->wmm_info
= info_element
->data
[6];
1154 //WMM Parameter Element
1155 memcpy(network
->wmm_param
, (u8
*)(info_element
->data
+ 8),(info_element
->len
- 8));
1156 network
->QoS_Enable
= 1;
1161 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RSN: %d bytes\n",
1163 network
->rsn_ie_len
= min(info_element
->len
+ 2,
1165 memcpy(network
->rsn_ie
, info_element
,
1166 network
->rsn_ie_len
);
1168 case MFIE_TYPE_COUNTRY
:
1169 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
1171 // printk("=====>Receive <%s> Country IE\n",network->ssid);
1172 ieee80211_extract_country_ie(ieee
, info_element
, network
, beacon
->header
.addr2
);
1175 IEEE80211_DEBUG_SCAN("unsupported IE %d\n",
1180 left
-= sizeof(struct ieee80211_info_element_hdr
) +
1182 info_element
= (struct ieee80211_info_element
*)
1183 &info_element
->data
[info_element
->len
];
1186 network
->HighestOperaRate
= hOpRate
;
1189 if (stats
->freq
== IEEE80211_52GHZ_BAND
)
1190 network
->mode
= IEEE_A
;
1192 if (network
->flags
& NETWORK_HAS_OFDM
)
1193 network
->mode
|= IEEE_G
;
1194 if (network
->flags
& NETWORK_HAS_CCK
)
1195 network
->mode
|= IEEE_B
;
1198 if (network
->mode
== 0) {
1199 IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT
")' "
1201 escape_essid(network
->ssid
,
1203 MAC_ARG(network
->bssid
));
1207 if (ieee80211_is_empty_essid(network
->ssid
, network
->ssid_len
))
1208 network
->flags
|= NETWORK_EMPTY_ESSID
;
1210 stats
->signal
= ieee80211_TranslateToDbm(stats
->signalstrength
);
1211 //stats->noise = stats->signal - stats->noise;
1212 stats
->noise
= ieee80211_TranslateToDbm(100 - stats
->signalstrength
) - 25;
1213 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
1218 static inline int is_same_network(struct ieee80211_network
*src
,
1219 struct ieee80211_network
*dst
,
1220 struct ieee80211_device
* ieee
)
1222 /* A network is only a duplicate if the channel, BSSID, ESSID
1223 * and the capability field (in particular IBSS and BSS) all match.
1224 * We treat all <hidden> with the same BSSID and channel
1226 return (((src
->ssid_len
== dst
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) && //YJ,mod,080819,for hidden ap
1227 //((src->ssid_len == dst->ssid_len) &&
1228 (src
->channel
== dst
->channel
) &&
1229 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
1230 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) || (ieee
->iw_mode
== IW_MODE_INFRA
)) && //YJ,mod,080819,for hidden ap
1231 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
1232 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
1233 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
1234 ((src
->capability
& WLAN_CAPABILITY_BSS
) ==
1235 (dst
->capability
& WLAN_CAPABILITY_BSS
)));
1238 inline void update_network(struct ieee80211_network
*dst
,
1239 struct ieee80211_network
*src
)
1241 unsigned char quality
= src
->stats
.signalstrength
;
1242 unsigned char signal
= 0;
1243 unsigned char noise
= 0;
1244 if(dst
->stats
.signalstrength
> 0) {
1245 quality
= (dst
->stats
.signalstrength
* 5 + src
->stats
.signalstrength
+ 5)/6;
1247 signal
= ieee80211_TranslateToDbm(quality
);
1248 //noise = signal - src->stats.noise;
1249 if(dst
->stats
.noise
> 0)
1250 noise
= (dst
->stats
.noise
* 5 + src
->stats
.noise
)/6;
1251 //if(strcmp(dst->ssid, "linksys_lzm000") == 0)
1252 // printk("ssid:%s, quality:%d, signal:%d\n", dst->ssid, quality, signal);
1253 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct ieee80211_rx_stats
));
1254 dst
->stats
.signalstrength
= quality
;
1255 dst
->stats
.signal
= signal
;
1256 // printk("==================>stats.signal is %d\n",dst->stats.signal);
1257 dst
->stats
.noise
= noise
;
1260 dst
->capability
= src
->capability
;
1261 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
1262 dst
->rates_len
= src
->rates_len
;
1263 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
1264 dst
->rates_ex_len
= src
->rates_ex_len
;
1265 dst
->HighestOperaRate
= src
->HighestOperaRate
;
1266 //printk("==========>in %s: src->ssid is %s,chan is %d\n",__func__,src->ssid,src->channel);
1268 //YJ,add,080819,for hidden ap
1269 if(src
->ssid_len
> 0)
1271 //if(src->ssid_len == 13)
1272 // printk("=====================>>>>>>>> Dst ssid: %s Src ssid: %s\n", dst->ssid, src->ssid);
1273 memset(dst
->ssid
, 0, dst
->ssid_len
);
1274 dst
->ssid_len
= src
->ssid_len
;
1275 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
1277 //YJ,add,080819,for hidden ap,end
1279 dst
->channel
= src
->channel
;
1280 dst
->mode
= src
->mode
;
1281 dst
->flags
= src
->flags
;
1282 dst
->time_stamp
[0] = src
->time_stamp
[0];
1283 dst
->time_stamp
[1] = src
->time_stamp
[1];
1285 dst
->beacon_interval
= src
->beacon_interval
;
1286 dst
->listen_interval
= src
->listen_interval
;
1287 dst
->atim_window
= src
->atim_window
;
1288 dst
->dtim_period
= src
->dtim_period
;
1289 dst
->dtim_data
= src
->dtim_data
;
1290 dst
->last_dtim_sta_time
[0] = src
->last_dtim_sta_time
[0];
1291 dst
->last_dtim_sta_time
[1] = src
->last_dtim_sta_time
[1];
1292 // printk("update:%s, dtim_period:%x, dtim_data:%x\n", src->ssid, src->dtim_period, src->dtim_data);
1293 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
1294 dst
->wpa_ie_len
= src
->wpa_ie_len
;
1295 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
1296 dst
->rsn_ie_len
= src
->rsn_ie_len
;
1298 dst
->last_scanned
= jiffies
;
1299 /* dst->last_associate is not overwritten */
1300 // disable QoS process now, added by David 2006/7/25
1302 dst
->wmm_info
= src
->wmm_info
; //sure to exist in beacon or probe response frame.
1304 if((dst->wmm_info^src->wmm_info)&0x0f) {//Param Set Count change, update Parameter
1305 memcpy(dst->wmm_param, src->wmm_param, IEEE80211_AC_PRAM_LEN);
1308 if(src
->wmm_param
[0].ac_aci_acm_aifsn
|| \
1309 src
->wmm_param
[1].ac_aci_acm_aifsn
|| \
1310 src
->wmm_param
[2].ac_aci_acm_aifsn
|| \
1311 src
->wmm_param
[3].ac_aci_acm_aifsn
) {
1312 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
1314 dst
->QoS_Enable
= src
->QoS_Enable
;
1316 dst
->QoS_Enable
= 1;//for Rtl8187 simulation
1318 dst
->SignalStrength
= src
->SignalStrength
;
1319 dst
->Turbo_Enable
= src
->Turbo_Enable
;
1320 dst
->CountryIeLen
= src
->CountryIeLen
;
1321 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
1325 inline void ieee80211_process_probe_response(
1326 struct ieee80211_device
*ieee
,
1327 struct ieee80211_probe_response
*beacon
,
1328 struct ieee80211_rx_stats
*stats
)
1330 struct ieee80211_network network
;
1331 struct ieee80211_network
*target
;
1332 struct ieee80211_network
*oldest
= NULL
;
1333 #ifdef CONFIG_IEEE80211_DEBUG
1334 struct ieee80211_info_element
*info_element
= &beacon
->info_element
;
1336 unsigned long flags
;
1339 u8 is_beacon
= (WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) == IEEE80211_STYPE_BEACON
)? 1:0; //YJ,add,080819,for hidden ap
1341 memset(&network
, 0, sizeof(struct ieee80211_network
));
1343 IEEE80211_DEBUG_SCAN(
1344 "'%s' (" MAC_FMT
"): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1345 escape_essid(info_element
->data
, info_element
->len
),
1346 MAC_ARG(beacon
->header
.addr3
),
1347 (beacon
->capability
& (1<<0xf)) ? '1' : '0',
1348 (beacon
->capability
& (1<<0xe)) ? '1' : '0',
1349 (beacon
->capability
& (1<<0xd)) ? '1' : '0',
1350 (beacon
->capability
& (1<<0xc)) ? '1' : '0',
1351 (beacon
->capability
& (1<<0xb)) ? '1' : '0',
1352 (beacon
->capability
& (1<<0xa)) ? '1' : '0',
1353 (beacon
->capability
& (1<<0x9)) ? '1' : '0',
1354 (beacon
->capability
& (1<<0x8)) ? '1' : '0',
1355 (beacon
->capability
& (1<<0x7)) ? '1' : '0',
1356 (beacon
->capability
& (1<<0x6)) ? '1' : '0',
1357 (beacon
->capability
& (1<<0x5)) ? '1' : '0',
1358 (beacon
->capability
& (1<<0x4)) ? '1' : '0',
1359 (beacon
->capability
& (1<<0x3)) ? '1' : '0',
1360 (beacon
->capability
& (1<<0x2)) ? '1' : '0',
1361 (beacon
->capability
& (1<<0x1)) ? '1' : '0',
1362 (beacon
->capability
& (1<<0x0)) ? '1' : '0');
1364 if (ieee80211_network_init(ieee
, beacon
, &network
, stats
)) {
1365 IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT
") via %s.\n",
1366 escape_essid(info_element
->data
,
1368 MAC_ARG(beacon
->header
.addr3
),
1369 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
1370 IEEE80211_STYPE_PROBE_RESP
?
1371 "PROBE RESPONSE" : "BEACON");
1375 // For Asus EeePc request,
1376 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
1377 // wireless adapter should follow the country code.
1378 // (2) If there is no any country code in beacon,
1379 // then wireless adapter should do active scan from ch1~11 and
1380 // passive scan from ch12~14
1381 if(ieee
->bGlobalDomain
)
1383 if (WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) == IEEE80211_STYPE_PROBE_RESP
)
1385 // Case 1: Country code
1386 if(IS_COUNTRY_IE_VALID(ieee
) )
1388 if( !IsLegalChannel(ieee
, network
.channel
) )
1390 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network
.channel
);
1394 // Case 2: No any country code.
1397 // Filter over channel ch12~14
1398 if(network
.channel
> 11)
1400 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network
.channel
);
1407 // Case 1: Country code
1408 if(IS_COUNTRY_IE_VALID(ieee
) )
1410 if( !IsLegalChannel(ieee
, network
.channel
) )
1412 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network
.channel
);
1416 // Case 2: No any country code.
1419 // Filter over channel ch12~14
1420 if(network
.channel
> 14)
1422 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network
.channel
);
1428 /* The network parsed correctly -- so now we scan our known networks
1429 * to see if we can find it in our list.
1431 * NOTE: This search is definitely not optimized. Once its doing
1432 * the "right thing" we'll optimize it for efficiency if
1435 /* Search for this entry in the list and update it if it is
1438 spin_lock_irqsave(&ieee
->lock
, flags
);
1440 if(is_same_network(&ieee
->current_network
, &network
, ieee
)) {
1441 wmm_info
= ieee
->current_network
.wmm_info
;
1442 //YJ,add,080819,for hidden ap
1444 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& ieee
->current_network
.flags
);
1445 else if(ieee
->state
== IEEE80211_LINKED
)
1446 ieee
->NumRxBcnInPeriod
++;
1447 //YJ,add,080819,for hidden ap,end
1448 //printk("====>network.ssid=%s cur_ssid=%s\n", network.ssid, ieee->current_network.ssid);
1449 update_network(&ieee
->current_network
, &network
);
1452 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1453 if (is_same_network(target
, &network
, ieee
))
1455 if ((oldest
== NULL
) ||
1456 (target
->last_scanned
< oldest
->last_scanned
))
1460 /* If we didn't find a match, then get a new network slot to initialize
1461 * with this beacon's information */
1462 if (&target
->list
== &ieee
->network_list
) {
1463 if (list_empty(&ieee
->network_free_list
)) {
1464 /* If there are no more slots, expire the oldest */
1465 list_del(&oldest
->list
);
1467 IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT
") from "
1469 escape_essid(target
->ssid
,
1471 MAC_ARG(target
->bssid
));
1473 /* Otherwise just pull from the free list */
1474 target
= list_entry(ieee
->network_free_list
.next
,
1475 struct ieee80211_network
, list
);
1476 list_del(ieee
->network_free_list
.next
);
1480 #ifdef CONFIG_IEEE80211_DEBUG
1481 IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT
") via %s.\n",
1482 escape_essid(network
.ssid
,
1484 MAC_ARG(network
.bssid
),
1485 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
1486 IEEE80211_STYPE_PROBE_RESP
?
1487 "PROBE RESPONSE" : "BEACON");
1490 memcpy(target
, &network
, sizeof(*target
));
1491 list_add_tail(&target
->list
, &ieee
->network_list
);
1492 if(ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
)
1493 ieee80211_softmac_new_net(ieee
,&network
);
1495 IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT
") via %s.\n",
1496 escape_essid(target
->ssid
,
1498 MAC_ARG(target
->bssid
),
1499 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
1500 IEEE80211_STYPE_PROBE_RESP
?
1501 "PROBE RESPONSE" : "BEACON");
1503 /* we have an entry and we are going to update it. But this entry may
1504 * be already expired. In this case we do the same as we found a new
1505 * net and call the new_net handler
1507 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
);
1508 //YJ,add,080819,for hidden ap
1510 network
.flags
= (~NETWORK_EMPTY_ESSID
& network
.flags
)|(NETWORK_EMPTY_ESSID
& target
->flags
);
1511 //if(strncmp(network.ssid, "linksys-c",9) == 0)
1512 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
1513 if(((network
.flags
& NETWORK_EMPTY_ESSID
) == NETWORK_EMPTY_ESSID
) \
1514 && (((network
.ssid_len
> 0) && (strncmp(target
->ssid
, network
.ssid
, network
.ssid_len
)))\
1515 ||((ieee
->current_network
.ssid_len
== network
.ssid_len
)&&(strncmp(ieee
->current_network
.ssid
, network
.ssid
, network
.ssid_len
) == 0)&&(ieee
->state
== IEEE80211_NOLINK
))))
1517 //YJ,add,080819,for hidden ap,end
1518 update_network(target
, &network
);
1519 if(renew
&& (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
))
1520 ieee80211_softmac_new_net(ieee
,&network
);
1523 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1526 void ieee80211_rx_mgt(struct ieee80211_device
*ieee
,
1527 struct ieee80211_hdr_4addr
*header
,
1528 struct ieee80211_rx_stats
*stats
)
1530 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
1532 case IEEE80211_STYPE_BEACON
:
1533 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
1534 WLAN_FC_GET_STYPE(header
->frame_ctl
));
1535 IEEE80211_DEBUG_SCAN("Beacon\n");
1536 ieee80211_process_probe_response(
1537 ieee
, (struct ieee80211_probe_response
*)header
, stats
);
1540 case IEEE80211_STYPE_PROBE_RESP
:
1541 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1542 WLAN_FC_GET_STYPE(header
->frame_ctl
));
1543 IEEE80211_DEBUG_SCAN("Probe response\n");
1544 ieee80211_process_probe_response(
1545 ieee
, (struct ieee80211_probe_response
*)header
, stats
);