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 =
53 (struct ieee80211_hdr_4addr *)skb->data;
54 u16 fc = le16_to_cpu(hdr->frame_ctl);
57 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_3addr_QOS *hdr_3addr_QoS;
108 struct ieee80211_hdr_QOS *hdr_4addr_QoS;
111 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
112 hdr_4addr_QoS = (struct ieee80211_hdr_QOS *)hdr;
113 tid = le16_to_cpu(hdr_4addr_QoS->QOS_ctl) & IEEE80211_QOS_TID;
116 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
117 hdr_3addr_QoS = (struct ieee80211_hdr_3addr_QOS *)hdr;
118 tid = le16_to_cpu(hdr_3addr_QoS->QOS_ctl) & IEEE80211_QOS_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_3addr_QOS *hdr_3addr_QoS;
175 struct ieee80211_hdr_QOS *hdr_4addr_QoS;
178 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
179 hdr_4addr_QoS = (struct ieee80211_hdr_QOS *)hdr;
180 tid = le16_to_cpu(hdr_4addr_QoS->QOS_ctl) & IEEE80211_QOS_TID;
183 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
184 hdr_3addr_QoS = (struct ieee80211_hdr_3addr_QOS *)hdr;
185 tid = le16_to_cpu(hdr_3addr_QoS->QOS_ctl) & IEEE80211_QOS_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 struct ieee80211_hdr_4addr *hdr;
220 // cheat the the hdr type
221 hdr = (struct ieee80211_hdr_4addr *)skb->data;
223 /* On the struct stats definition there is written that
224 * this is not mandatory.... but seems that the probe
225 * response parser uses it
227 rx_stats->len = skb->len;
228 ieee80211_rx_mgt(ieee, (struct ieee80211_hdr_4addr *)skb->data,
231 if((ieee->state == IEEE80211_LINKED)&&(memcmp(hdr->addr3,ieee->current_network.bssid,ETH_ALEN))) {
232 dev_kfree_skb_any(skb);
236 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
238 dev_kfree_skb_any(skb);
246 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
247 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
248 static unsigned char rfc1042_header[] =
249 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
250 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
251 static unsigned char bridge_tunnel_header[] =
252 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
253 /* No encapsulation header if EtherType < 0x600 (=length) */
255 /* Called by ieee80211_rx_frame_decrypt */
256 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
257 struct sk_buff *skb, size_t hdrlen)
259 struct net_device *dev = ieee->dev;
261 struct ieee80211_hdr_4addr *hdr;
267 hdr = (struct ieee80211_hdr_4addr *)skb->data;
268 fc = le16_to_cpu(hdr->frame_ctl);
270 /* check that the frame is unicast frame to us */
271 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
272 IEEE80211_FCTL_TODS &&
273 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
274 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
275 /* ToDS frame with own addr BSSID and DA */
276 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
277 IEEE80211_FCTL_FROMDS &&
278 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
279 /* FromDS frame with own addr as DA */
283 if (skb->len < 24 + 8)
286 /* check for port access entity Ethernet type */
287 // pos = skb->data + 24;
288 pos = skb->data + hdrlen;
289 ethertype = (pos[6] << 8) | pos[7];
290 if (ethertype == ETH_P_PAE)
296 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
298 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
299 struct ieee80211_crypt_data *crypt)
301 struct ieee80211_hdr_4addr *hdr;
304 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
307 hdr = (struct ieee80211_hdr_4addr *)skb->data;
308 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
310 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
311 if (ieee->tkip_countermeasures &&
312 strcmp(crypt->ops->name, "TKIP") == 0) {
313 if (net_ratelimit()) {
314 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
315 "received packet from " MAC_FMT "\n",
316 ieee->dev->name, MAC_ARG(hdr->addr2));
322 atomic_inc(&crypt->refcnt);
323 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
324 atomic_dec(&crypt->refcnt);
326 IEEE80211_DEBUG_DROP(
327 "decryption failed (SA=" MAC_FMT
328 ") res=%d\n", MAC_ARG(hdr->addr2), res);
330 IEEE80211_DEBUG_DROP("Decryption failed ICV "
331 "mismatch (key %d)\n",
332 skb->data[hdrlen + 3] >> 6);
333 ieee->ieee_stats.rx_discards_undecryptable++;
341 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
343 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
344 int keyidx, struct ieee80211_crypt_data *crypt)
346 struct ieee80211_hdr_4addr *hdr;
349 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
352 hdr = (struct ieee80211_hdr_4addr *)skb->data;
353 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
355 atomic_inc(&crypt->refcnt);
356 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
357 atomic_dec(&crypt->refcnt);
359 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
360 " (SA=" MAC_FMT " keyidx=%d)\n",
361 ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
369 /* this function is stolen from ipw2200 driver*/
370 #define IEEE_PACKET_RETRY_TIME (5*HZ)
371 static int is_duplicate_packet(struct ieee80211_device *ieee,
372 struct ieee80211_hdr_4addr *header)
374 u16 fc = le16_to_cpu(header->frame_ctl);
375 u16 sc = le16_to_cpu(header->seq_ctl);
376 u16 seq = WLAN_GET_SEQ_SEQ(sc);
377 u16 frag = WLAN_GET_SEQ_FRAG(sc);
378 u16 *last_seq, *last_frag;
379 unsigned long *last_time;
380 struct ieee80211_hdr_3addr_QOS *hdr_3addr_QoS;
381 struct ieee80211_hdr_QOS *hdr_4addr_QoS;
385 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
386 hdr_4addr_QoS = (struct ieee80211_hdr_QOS *)header;
387 tid = le16_to_cpu(hdr_4addr_QoS->QOS_ctl) & IEEE80211_QOS_TID;
390 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
391 hdr_3addr_QoS = (struct ieee80211_hdr_3addr_QOS*)header;
392 tid = le16_to_cpu(hdr_3addr_QoS->QOS_ctl) & IEEE80211_QOS_TID;
398 switch (ieee->iw_mode) {
402 struct ieee_ibss_seq *entry = NULL;
403 u8 *mac = header->addr2;
404 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
405 //for (pos = (head)->next; pos != (head); pos = pos->next)
406 __list_for_each(p, &ieee->ibss_mac_hash[index]) {
407 entry = list_entry(p, struct ieee_ibss_seq, list);
408 if (!memcmp(entry->mac, mac, ETH_ALEN))
411 // if (memcmp(entry->mac, mac, ETH_ALEN)){
412 if (p == &ieee->ibss_mac_hash[index]) {
413 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
415 printk(KERN_WARNING "Cannot malloc new mac entry\n");
418 memcpy(entry->mac, mac, ETH_ALEN);
419 entry->seq_num[tid] = seq;
420 entry->frag_num[tid] = frag;
421 entry->packet_time[tid] = jiffies;
422 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
425 last_seq = &entry->seq_num[tid];
426 last_frag = &entry->frag_num[tid];
427 last_time = &entry->packet_time[tid];
432 last_seq = &ieee->last_rxseq_num[tid];
433 last_frag = &ieee->last_rxfrag_num[tid];
434 last_time = &ieee->last_packet_time[tid];
442 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
444 if ((*last_seq == seq) &&
445 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
446 if (*last_frag == frag){
447 //printk(KERN_WARNING "[1] go drop!\n");
451 if (*last_frag + 1 != frag)
452 /* out-of-order fragment */
453 //printk(KERN_WARNING "[2] go drop!\n");
459 *last_time = jiffies;
463 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
470 /* All received frames are sent to this function. @skb contains the frame in
471 * IEEE 802.11 format, i.e., in the format it was sent over air.
472 * This function is called only as a tasklet (software IRQ). */
473 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
474 struct ieee80211_rx_stats *rx_stats)
476 struct net_device *dev = ieee->dev;
477 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
478 struct ieee80211_hdr_4addr *hdr;
479 //struct ieee80211_hdr_3addr_QOS *hdr;
482 u16 fc, type, stype, sc;
483 struct net_device_stats *stats;
491 struct ieee80211_crypt_data *crypt = NULL;
494 // cheat the the hdr type
495 hdr = (struct ieee80211_hdr_4addr *)skb->data;
496 stats = &ieee->stats;
499 printk(KERN_INFO "%s: SKB length < 10\n",
504 fc = le16_to_cpu(hdr->frame_ctl);
505 type = WLAN_FC_GET_TYPE(fc);
506 stype = WLAN_FC_GET_STYPE(fc);
507 sc = le16_to_cpu(hdr->seq_ctl);
509 frag = WLAN_GET_SEQ_FRAG(sc);
511 //YJ,add,080828,for keep alive
512 if((fc & IEEE80211_FCTL_TODS) != IEEE80211_FCTL_TODS)
514 if(!memcmp(hdr->addr1,dev->dev_addr, ETH_ALEN))
516 ieee->NumRxUnicast++;
521 if(!memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN))
523 ieee->NumRxUnicast++;
526 //YJ,add,080828,for keep alive,end
528 hdrlen = ieee80211_get_hdrlen(fc);
531 if (ieee->iw_mode == IW_MODE_MONITOR) {
532 ieee80211_monitor_rx(ieee, skb, rx_stats);
534 stats->rx_bytes += skb->len;
538 if (ieee->host_decrypt) {
540 if (skb->len >= hdrlen + 3)
541 idx = skb->data[hdrlen + 3] >> 6;
542 crypt = ieee->crypt[idx];
544 /* allow NULL decrypt to indicate an station specific override
545 * for default encryption */
546 if (crypt && (crypt->ops == NULL ||
547 crypt->ops->decrypt_mpdu == NULL))
550 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
551 /* This seems to be triggered by some (multicast?)
552 * frames from other than current BSS, so just drop the
553 * frames silently instead of filling system log with
555 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
556 " (SA=" MAC_FMT ")\n",
557 MAC_ARG(hdr->addr2));
558 ieee->ieee_stats.rx_discards_undecryptable++;
563 if (skb->len < IEEE80211_DATA_HDR3_LEN)
566 // if QoS enabled, should check the sequence for each of the AC
567 if (is_duplicate_packet(ieee, hdr))
571 if (type == IEEE80211_FTYPE_MGMT) {
572 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
578 /* Data frame - extract src/dst addresses */
579 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
580 case IEEE80211_FCTL_FROMDS:
581 memcpy(dst, hdr->addr1, ETH_ALEN);
582 memcpy(src, hdr->addr3, ETH_ALEN);
583 memcpy(bssid,hdr->addr2,ETH_ALEN);
585 case IEEE80211_FCTL_TODS:
586 memcpy(dst, hdr->addr3, ETH_ALEN);
587 memcpy(src, hdr->addr2, ETH_ALEN);
588 memcpy(bssid,hdr->addr1,ETH_ALEN);
590 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
591 if (skb->len < IEEE80211_DATA_HDR4_LEN)
593 memcpy(dst, hdr->addr3, ETH_ALEN);
594 memcpy(src, hdr->addr4, ETH_ALEN);
595 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
598 memcpy(dst, hdr->addr1, ETH_ALEN);
599 memcpy(src, hdr->addr2, ETH_ALEN);
600 memcpy(bssid,hdr->addr3,ETH_ALEN);
605 dev->last_rx = jiffies;
608 /* Nullfunc frames may have PS-bit set, so they must be passed to
609 * hostap_handle_sta_rx() before being dropped here. */
610 if (stype != IEEE80211_STYPE_DATA &&
611 stype != IEEE80211_STYPE_DATA_CFACK &&
612 stype != IEEE80211_STYPE_DATA_CFPOLL &&
613 stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
614 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
616 if (stype != IEEE80211_STYPE_NULLFUNC)
617 IEEE80211_DEBUG_DROP(
618 "RX: dropped data frame "
619 "with no data (type=0x%02x, "
620 "subtype=0x%02x, len=%d)\n",
621 type, stype, skb->len);
624 if(memcmp(bssid,ieee->current_network.bssid,ETH_ALEN)) {
628 ieee->NumRxDataInPeriod++;
629 ieee->NumRxOkTotal++;
630 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
632 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
633 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
636 hdr = (struct ieee80211_hdr_4addr *)skb->data;
638 /* skb: hdr + (possibly fragmented) plaintext payload */
639 // PR: FIXME: hostap has additional conditions in the "if" below:
640 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
641 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
643 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
644 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
647 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
648 "Rx cannot get skb from fragment "
649 "cache (morefrag=%d seq=%u frag=%u)\n",
650 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
651 WLAN_GET_SEQ_SEQ(sc), frag);
658 if (frag_skb->tail + flen > frag_skb->end) {
659 printk(KERN_WARNING "%s: host decrypted and "
660 "reassembled frame did not fit skb\n",
662 ieee80211_frag_cache_invalidate(ieee, hdr);
667 /* copy first fragment (including full headers) into
668 * beginning of the fragment cache skb */
669 memcpy(skb_put(frag_skb, flen), skb->data, flen);
671 /* append frame payload to the end of the fragment
673 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
676 dev_kfree_skb_any(skb);
679 if (fc & IEEE80211_FCTL_MOREFRAGS) {
680 /* more fragments expected - leave the skb in fragment
681 * cache for now; it will be delivered to upper layers
682 * after all fragments have been received */
686 /* this was the last fragment and the frame will be
687 * delivered, so remove skb from fragment cache */
689 hdr = (struct ieee80211_hdr_4addr *)skb->data;
690 ieee80211_frag_cache_invalidate(ieee, hdr);
693 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
694 * encrypted/authenticated */
695 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
696 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
699 hdr = (struct ieee80211_hdr_4addr *)skb->data;
700 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
701 if (/*ieee->ieee802_1x &&*/
702 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
704 #ifdef CONFIG_IEEE80211_DEBUG
705 /* pass unencrypted EAPOL frames even if encryption is
707 struct eapol *eap = (struct eapol *)(skb->data +
709 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
710 eap_get_type(eap->type));
713 IEEE80211_DEBUG_DROP(
714 "encryption configured, but RX "
715 "frame not encrypted (SA=" MAC_FMT ")\n",
716 MAC_ARG(hdr->addr2));
721 #ifdef CONFIG_IEEE80211_DEBUG
722 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
723 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
724 struct eapol *eap = (struct eapol *)(skb->data +
726 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
727 eap_get_type(eap->type));
731 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
732 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
733 IEEE80211_DEBUG_DROP(
734 "dropped unencrypted RX data "
735 "frame from " MAC_FMT
736 " (drop_unencrypted=1)\n",
737 MAC_ARG(hdr->addr2));
741 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
742 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
745 /* skb: hdr + (possible reassembled) full plaintext payload */
746 payload = skb->data + hdrlen;
747 ethertype = (payload[6] << 8) | payload[7];
750 /* convert hdr + possible LLC headers into Ethernet header */
751 if (skb->len - hdrlen >= 8 &&
752 ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
753 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
754 memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
755 /* remove RFC1042 or Bridge-Tunnel encapsulation and
756 * replace EtherType */
757 skb_pull(skb, hdrlen + SNAP_SIZE);
758 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
759 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
762 /* Leave Ethernet header part of hdr and full payload */
763 skb_pull(skb, hdrlen);
764 len = htons(skb->len);
765 memcpy(skb_push(skb, 2), &len, 2);
766 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
767 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
772 stats->rx_bytes += skb->len;
775 skb->protocol = eth_type_trans(skb, dev);
776 memset(skb->cb, 0, sizeof(skb->cb));
778 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
779 ieee->last_rx_ps_time = jiffies;
789 /* Returning 0 indicates to caller that we have not handled the SKB--
790 * so it is still allocated and can be used again by underlying
791 * hardware as a DMA target */
795 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
797 static inline int ieee80211_is_ofdm_rate(u8 rate)
799 switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
800 case IEEE80211_OFDM_RATE_6MB:
801 case IEEE80211_OFDM_RATE_9MB:
802 case IEEE80211_OFDM_RATE_12MB:
803 case IEEE80211_OFDM_RATE_18MB:
804 case IEEE80211_OFDM_RATE_24MB:
805 case IEEE80211_OFDM_RATE_36MB:
806 case IEEE80211_OFDM_RATE_48MB:
807 case IEEE80211_OFDM_RATE_54MB:
813 static inline int ieee80211_SignalStrengthTranslate(
819 // Step 1. Scale mapping.
820 if(CurrSS >= 71 && CurrSS <= 100)
822 RetSS = 90 + ((CurrSS - 70) / 3);
824 else if(CurrSS >= 41 && CurrSS <= 70)
826 RetSS = 78 + ((CurrSS - 40) / 3);
828 else if(CurrSS >= 31 && CurrSS <= 40)
830 RetSS = 66 + (CurrSS - 30);
832 else if(CurrSS >= 21 && CurrSS <= 30)
834 RetSS = 54 + (CurrSS - 20);
836 else if(CurrSS >= 5 && CurrSS <= 20)
838 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
860 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
862 // Step 2. Smoothing.
864 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
869 static inline void ieee80211_extract_country_ie(
870 struct ieee80211_device *ieee,
871 struct ieee80211_info_element *info_element,
872 struct ieee80211_network *network,
876 if(IS_DOT11D_ENABLE(ieee))
878 if(info_element->len!= 0)
880 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
881 network->CountryIeLen = info_element->len;
883 if(!IS_COUNTRY_IE_VALID(ieee))
885 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
890 // 070305, rcnjko: I update country IE watch dog here because
891 // some AP (e.g. Cisco 1242) don't include country IE in their
892 // probe response frame.
894 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
896 UPDATE_CIE_WATCHDOG(ieee);
903 ieee80211_TranslateToDbm(
904 unsigned char SignalStrengthIndex // 0-100 index.
907 unsigned char SignalPower; // in dBm.
909 // Translate to dBm (x=0.5y-95).
910 SignalPower = (int)SignalStrengthIndex * 7 / 10;
915 inline int ieee80211_network_init(
916 struct ieee80211_device *ieee,
917 struct ieee80211_probe_response *beacon,
918 struct ieee80211_network *network,
919 struct ieee80211_rx_stats *stats)
921 #ifdef CONFIG_IEEE80211_DEBUG
925 struct ieee80211_info_element *info_element;
929 u8 curRate = 0,hOpRate = 0,curRate_ex = 0;
931 /* Pull out fixed field data */
932 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
933 network->capability = beacon->capability;
934 network->last_scanned = jiffies;
935 network->time_stamp[0] = beacon->time_stamp[0];
936 network->time_stamp[1] = beacon->time_stamp[1];
937 network->beacon_interval = beacon->beacon_interval;
938 /* Where to pull this? beacon->listen_interval;*/
939 network->listen_interval = 0x0A;
940 network->rates_len = network->rates_ex_len = 0;
941 network->last_associate = 0;
942 network->ssid_len = 0;
944 network->atim_window = 0;
945 network->QoS_Enable = 0;
947 network->HighestOperaRate = 0;
949 network->Turbo_Enable = 0;
950 network->CountryIeLen = 0;
951 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
953 if (stats->freq == IEEE80211_52GHZ_BAND) {
954 /* for A band (No DS info) */
955 network->channel = stats->received_channel;
957 network->flags |= NETWORK_HAS_CCK;
959 network->wpa_ie_len = 0;
960 network->rsn_ie_len = 0;
962 info_element = &beacon->info_element;
963 left = stats->len - ((void *)info_element - (void *)beacon);
964 while (left >= sizeof(struct ieee80211_info_element_hdr)) {
965 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
966 IEEE80211_DEBUG_SCAN("SCAN: parse failed: info_element->len + 2 > left : info_element->len+2=%d left=%d.\n",
967 info_element->len + sizeof(struct ieee80211_info_element),
972 switch (info_element->id) {
974 if (ieee80211_is_empty_essid(info_element->data,
975 info_element->len)) {
976 network->flags |= NETWORK_EMPTY_ESSID;
980 network->ssid_len = min(info_element->len,
981 (u8)IW_ESSID_MAX_SIZE);
982 memcpy(network->ssid, info_element->data, network->ssid_len);
983 if (network->ssid_len < IW_ESSID_MAX_SIZE)
984 memset(network->ssid + network->ssid_len, 0,
985 IW_ESSID_MAX_SIZE - network->ssid_len);
987 IEEE80211_DEBUG_SCAN("MFIE_TYPE_SSID: '%s' len=%d.\n",
988 network->ssid, network->ssid_len);
991 case MFIE_TYPE_RATES:
992 #ifdef CONFIG_IEEE80211_DEBUG
995 network->rates_len = min(info_element->len, MAX_RATES_LENGTH);
996 for (i = 0; i < network->rates_len; i++) {
997 network->rates[i] = info_element->data[i];
998 curRate = network->rates[i] & 0x7f;
999 if( hOpRate < curRate )
1001 #ifdef CONFIG_IEEE80211_DEBUG
1002 p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
1004 if (ieee80211_is_ofdm_rate(info_element->data[i])) {
1005 network->flags |= NETWORK_HAS_OFDM;
1006 if (info_element->data[i] &
1007 IEEE80211_BASIC_RATE_MASK)
1013 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES: '%s' (%d)\n",
1014 rates_str, network->rates_len);
1017 case MFIE_TYPE_RATES_EX:
1018 #ifdef CONFIG_IEEE80211_DEBUG
1021 network->rates_ex_len = min(info_element->len, MAX_RATES_EX_LENGTH);
1022 for (i = 0; i < network->rates_ex_len; i++) {
1023 network->rates_ex[i] = info_element->data[i];
1024 curRate_ex = network->rates_ex[i] & 0x7f;
1025 if( hOpRate < curRate_ex )
1026 hOpRate = curRate_ex;
1027 #ifdef CONFIG_IEEE80211_DEBUG
1028 p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
1030 if (ieee80211_is_ofdm_rate(info_element->data[i])) {
1031 network->flags |= NETWORK_HAS_OFDM;
1032 if (info_element->data[i] &
1033 IEEE80211_BASIC_RATE_MASK)
1039 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1040 rates_str, network->rates_ex_len);
1043 case MFIE_TYPE_DS_SET:
1044 IEEE80211_DEBUG_SCAN("MFIE_TYPE_DS_SET: %d\n",
1045 info_element->data[0]);
1046 if (stats->freq == IEEE80211_24GHZ_BAND)
1047 network->channel = info_element->data[0];
1050 case MFIE_TYPE_FH_SET:
1051 IEEE80211_DEBUG_SCAN("MFIE_TYPE_FH_SET: ignored\n");
1054 case MFIE_TYPE_CF_SET:
1055 IEEE80211_DEBUG_SCAN("MFIE_TYPE_CF_SET: ignored\n");
1060 if(info_element->len < 4)
1063 network->dtim_period = info_element->data[1];
1065 if(ieee->state != IEEE80211_LINKED)
1068 network->last_dtim_sta_time[0] = jiffies;
1069 network->last_dtim_sta_time[1] = stats->mac_time[1];
1071 network->dtim_data = IEEE80211_DTIM_VALID;
1073 if(info_element->data[0] != 0)
1076 if(info_element->data[2] & 1)
1077 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1079 offset = (info_element->data[2] >> 1)*2;
1081 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1083 /* add and modified for ps 2008.1.22 */
1084 if(ieee->assoc_id < 8*offset ||
1085 ieee->assoc_id > 8*(offset + info_element->len -3)) {
1089 offset = (ieee->assoc_id/8) - offset;// + ((aid % 8)? 0 : 1) ;
1091 // printk("offset:%x data:%x, ucast:%d\n", offset,
1092 // info_element->data[3+offset] ,
1093 // info_element->data[3+offset] & (1<<(ieee->assoc_id%8)));
1095 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) {
1096 network->dtim_data |= IEEE80211_DTIM_UCAST;
1100 case MFIE_TYPE_IBSS_SET:
1101 IEEE80211_DEBUG_SCAN("MFIE_TYPE_IBSS_SET: ignored\n");
1104 case MFIE_TYPE_CHALLENGE:
1105 IEEE80211_DEBUG_SCAN("MFIE_TYPE_CHALLENGE: ignored\n");
1108 case MFIE_TYPE_GENERIC:
1110 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n",
1112 if (info_element->len >= 4 &&
1113 info_element->data[0] == 0x00 &&
1114 info_element->data[1] == 0x50 &&
1115 info_element->data[2] == 0xf2 &&
1116 info_element->data[3] == 0x01) {
1117 network->wpa_ie_len = min(info_element->len + 2,
1119 memcpy(network->wpa_ie, info_element,
1120 network->wpa_ie_len);
1123 if (info_element->len == 7 &&
1124 info_element->data[0] == 0x00 &&
1125 info_element->data[1] == 0xe0 &&
1126 info_element->data[2] == 0x4c &&
1127 info_element->data[3] == 0x01 &&
1128 info_element->data[4] == 0x02) {
1129 network->Turbo_Enable = 1;
1131 if (1 == stats->nic_type) {//nic 87
1135 if (info_element->len >= 5 &&
1136 info_element->data[0] == 0x00 &&
1137 info_element->data[1] == 0x50 &&
1138 info_element->data[2] == 0xf2 &&
1139 info_element->data[3] == 0x02 &&
1140 info_element->data[4] == 0x00) {
1141 //printk(KERN_WARNING "wmm info updated: %x\n", info_element->data[6]);
1142 //WMM Information Element
1143 network->wmm_info = info_element->data[6];
1144 network->QoS_Enable = 1;
1147 if (info_element->len >= 8 &&
1148 info_element->data[0] == 0x00 &&
1149 info_element->data[1] == 0x50 &&
1150 info_element->data[2] == 0xf2 &&
1151 info_element->data[3] == 0x02 &&
1152 info_element->data[4] == 0x01) {
1153 // Not care about version at present.
1154 //WMM Information Element
1155 //printk(KERN_WARNING "wmm info¶m updated: %x\n", info_element->data[6]);
1156 network->wmm_info = info_element->data[6];
1157 //WMM Parameter Element
1158 memcpy(network->wmm_param, (u8 *)(info_element->data + 8),(info_element->len - 8));
1159 network->QoS_Enable = 1;
1164 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RSN: %d bytes\n",
1166 network->rsn_ie_len = min(info_element->len + 2,
1168 memcpy(network->rsn_ie, info_element,
1169 network->rsn_ie_len);
1171 case MFIE_TYPE_COUNTRY:
1172 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
1174 // printk("=====>Receive <%s> Country IE\n",network->ssid);
1175 ieee80211_extract_country_ie(ieee, info_element, network, beacon->header.addr2);
1178 IEEE80211_DEBUG_SCAN("unsupported IE %d\n",
1183 left -= sizeof(struct ieee80211_info_element_hdr) +
1185 info_element = (struct ieee80211_info_element *)
1186 &info_element->data[info_element->len];
1189 network->HighestOperaRate = hOpRate;
1192 if (stats->freq == IEEE80211_52GHZ_BAND)
1193 network->mode = IEEE_A;
1195 if (network->flags & NETWORK_HAS_OFDM)
1196 network->mode |= IEEE_G;
1197 if (network->flags & NETWORK_HAS_CCK)
1198 network->mode |= IEEE_B;
1201 if (network->mode == 0) {
1202 IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
1204 escape_essid(network->ssid,
1206 MAC_ARG(network->bssid));
1210 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
1211 network->flags |= NETWORK_EMPTY_ESSID;
1213 stats->signal = ieee80211_TranslateToDbm(stats->signalstrength);
1214 //stats->noise = stats->signal - stats->noise;
1215 stats->noise = ieee80211_TranslateToDbm(100 - stats->signalstrength) - 25;
1216 memcpy(&network->stats, stats, sizeof(network->stats));
1221 static inline int is_same_network(struct ieee80211_network *src,
1222 struct ieee80211_network *dst,
1223 struct ieee80211_device * ieee)
1225 /* A network is only a duplicate if the channel, BSSID, ESSID
1226 * and the capability field (in particular IBSS and BSS) all match.
1227 * We treat all <hidden> with the same BSSID and channel
1229 return (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && //YJ,mod,080819,for hidden ap
1230 //((src->ssid_len == dst->ssid_len) &&
1231 (src->channel == dst->channel) &&
1232 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
1233 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && //YJ,mod,080819,for hidden ap
1234 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
1235 ((src->capability & WLAN_CAPABILITY_IBSS) ==
1236 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
1237 ((src->capability & WLAN_CAPABILITY_BSS) ==
1238 (dst->capability & WLAN_CAPABILITY_BSS)));
1241 inline void update_network(struct ieee80211_network *dst,
1242 struct ieee80211_network *src)
1244 unsigned char quality = src->stats.signalstrength;
1245 unsigned char signal = 0;
1246 unsigned char noise = 0;
1247 if(dst->stats.signalstrength > 0) {
1248 quality = (dst->stats.signalstrength * 5 + src->stats.signalstrength + 5)/6;
1250 signal = ieee80211_TranslateToDbm(quality);
1251 //noise = signal - src->stats.noise;
1252 if(dst->stats.noise > 0)
1253 noise = (dst->stats.noise * 5 + src->stats.noise)/6;
1254 //if(strcmp(dst->ssid, "linksys_lzm000") == 0)
1255 // printk("ssid:%s, quality:%d, signal:%d\n", dst->ssid, quality, signal);
1256 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
1257 dst->stats.signalstrength = quality;
1258 dst->stats.signal = signal;
1259 // printk("==================>stats.signal is %d\n",dst->stats.signal);
1260 dst->stats.noise = noise;
1263 dst->capability = src->capability;
1264 memcpy(dst->rates, src->rates, src->rates_len);
1265 dst->rates_len = src->rates_len;
1266 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1267 dst->rates_ex_len = src->rates_ex_len;
1268 dst->HighestOperaRate= src->HighestOperaRate;
1269 //printk("==========>in %s: src->ssid is %s,chan is %d\n",__func__,src->ssid,src->channel);
1271 //YJ,add,080819,for hidden ap
1272 if(src->ssid_len > 0)
1274 //if(src->ssid_len == 13)
1275 // printk("=====================>>>>>>>> Dst ssid: %s Src ssid: %s\n", dst->ssid, src->ssid);
1276 memset(dst->ssid, 0, dst->ssid_len);
1277 dst->ssid_len = src->ssid_len;
1278 memcpy(dst->ssid, src->ssid, src->ssid_len);
1280 //YJ,add,080819,for hidden ap,end
1282 dst->channel = src->channel;
1283 dst->mode = src->mode;
1284 dst->flags = src->flags;
1285 dst->time_stamp[0] = src->time_stamp[0];
1286 dst->time_stamp[1] = src->time_stamp[1];
1288 dst->beacon_interval = src->beacon_interval;
1289 dst->listen_interval = src->listen_interval;
1290 dst->atim_window = src->atim_window;
1291 dst->dtim_period = src->dtim_period;
1292 dst->dtim_data = src->dtim_data;
1293 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
1294 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
1295 // printk("update:%s, dtim_period:%x, dtim_data:%x\n", src->ssid, src->dtim_period, src->dtim_data);
1296 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1297 dst->wpa_ie_len = src->wpa_ie_len;
1298 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1299 dst->rsn_ie_len = src->rsn_ie_len;
1301 dst->last_scanned = jiffies;
1302 /* dst->last_associate is not overwritten */
1303 // disable QoS process now, added by David 2006/7/25
1305 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
1307 if((dst->wmm_info^src->wmm_info)&0x0f) {//Param Set Count change, update Parameter
1308 memcpy(dst->wmm_param, src->wmm_param, IEEE80211_AC_PRAM_LEN);
1311 if(src->wmm_param[0].ac_aci_acm_aifsn|| \
1312 src->wmm_param[1].ac_aci_acm_aifsn|| \
1313 src->wmm_param[2].ac_aci_acm_aifsn|| \
1314 src->wmm_param[3].ac_aci_acm_aifsn) {
1315 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
1317 dst->QoS_Enable = src->QoS_Enable;
1319 dst->QoS_Enable = 1;//for Rtl8187 simulation
1321 dst->SignalStrength = src->SignalStrength;
1322 dst->Turbo_Enable = src->Turbo_Enable;
1323 dst->CountryIeLen = src->CountryIeLen;
1324 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
1328 inline void ieee80211_process_probe_response(
1329 struct ieee80211_device *ieee,
1330 struct ieee80211_probe_response *beacon,
1331 struct ieee80211_rx_stats *stats)
1333 struct ieee80211_network network;
1334 struct ieee80211_network *target;
1335 struct ieee80211_network *oldest = NULL;
1336 #ifdef CONFIG_IEEE80211_DEBUG
1337 struct ieee80211_info_element *info_element = &beacon->info_element;
1339 unsigned long flags;
1342 u8 is_beacon = (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_BEACON)? 1:0; //YJ,add,080819,for hidden ap
1344 memset(&network, 0, sizeof(struct ieee80211_network));
1346 IEEE80211_DEBUG_SCAN(
1347 "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1348 escape_essid(info_element->data, info_element->len),
1349 MAC_ARG(beacon->header.addr3),
1350 (beacon->capability & (1<<0xf)) ? '1' : '0',
1351 (beacon->capability & (1<<0xe)) ? '1' : '0',
1352 (beacon->capability & (1<<0xd)) ? '1' : '0',
1353 (beacon->capability & (1<<0xc)) ? '1' : '0',
1354 (beacon->capability & (1<<0xb)) ? '1' : '0',
1355 (beacon->capability & (1<<0xa)) ? '1' : '0',
1356 (beacon->capability & (1<<0x9)) ? '1' : '0',
1357 (beacon->capability & (1<<0x8)) ? '1' : '0',
1358 (beacon->capability & (1<<0x7)) ? '1' : '0',
1359 (beacon->capability & (1<<0x6)) ? '1' : '0',
1360 (beacon->capability & (1<<0x5)) ? '1' : '0',
1361 (beacon->capability & (1<<0x4)) ? '1' : '0',
1362 (beacon->capability & (1<<0x3)) ? '1' : '0',
1363 (beacon->capability & (1<<0x2)) ? '1' : '0',
1364 (beacon->capability & (1<<0x1)) ? '1' : '0',
1365 (beacon->capability & (1<<0x0)) ? '1' : '0');
1367 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
1368 IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
1369 escape_essid(info_element->data,
1371 MAC_ARG(beacon->header.addr3),
1372 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1373 IEEE80211_STYPE_PROBE_RESP ?
1374 "PROBE RESPONSE" : "BEACON");
1378 // For Asus EeePc request,
1379 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
1380 // wireless adapter should follow the country code.
1381 // (2) If there is no any country code in beacon,
1382 // then wireless adapter should do active scan from ch1~11 and
1383 // passive scan from ch12~14
1384 if(ieee->bGlobalDomain)
1386 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
1388 // Case 1: Country code
1389 if(IS_COUNTRY_IE_VALID(ieee) )
1391 if( !IsLegalChannel(ieee, network.channel) )
1393 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
1397 // Case 2: No any country code.
1400 // Filter over channel ch12~14
1401 if(network.channel > 11)
1403 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
1410 // Case 1: Country code
1411 if(IS_COUNTRY_IE_VALID(ieee) )
1413 if( !IsLegalChannel(ieee, network.channel) )
1415 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
1419 // Case 2: No any country code.
1422 // Filter over channel ch12~14
1423 if(network.channel > 14)
1425 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
1431 /* The network parsed correctly -- so now we scan our known networks
1432 * to see if we can find it in our list.
1434 * NOTE: This search is definitely not optimized. Once its doing
1435 * the "right thing" we'll optimize it for efficiency if
1438 /* Search for this entry in the list and update it if it is
1441 spin_lock_irqsave(&ieee->lock, flags);
1443 if(is_same_network(&ieee->current_network, &network, ieee)) {
1444 wmm_info = ieee->current_network.wmm_info;
1445 //YJ,add,080819,for hidden ap
1447 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
1448 else if(ieee->state == IEEE80211_LINKED)
1449 ieee->NumRxBcnInPeriod++;
1450 //YJ,add,080819,for hidden ap,end
1451 //printk("====>network.ssid=%s cur_ssid=%s\n", network.ssid, ieee->current_network.ssid);
1452 update_network(&ieee->current_network, &network);
1455 list_for_each_entry(target, &ieee->network_list, list) {
1456 if (is_same_network(target, &network, ieee))
1458 if ((oldest == NULL) ||
1459 (target->last_scanned < oldest->last_scanned))
1463 /* If we didn't find a match, then get a new network slot to initialize
1464 * with this beacon's information */
1465 if (&target->list == &ieee->network_list) {
1466 if (list_empty(&ieee->network_free_list)) {
1467 /* If there are no more slots, expire the oldest */
1468 list_del(&oldest->list);
1470 IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
1472 escape_essid(target->ssid,
1474 MAC_ARG(target->bssid));
1476 /* Otherwise just pull from the free list */
1477 target = list_entry(ieee->network_free_list.next,
1478 struct ieee80211_network, list);
1479 list_del(ieee->network_free_list.next);
1483 #ifdef CONFIG_IEEE80211_DEBUG
1484 IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
1485 escape_essid(network.ssid,
1487 MAC_ARG(network.bssid),
1488 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1489 IEEE80211_STYPE_PROBE_RESP ?
1490 "PROBE RESPONSE" : "BEACON");
1493 memcpy(target, &network, sizeof(*target));
1494 list_add_tail(&target->list, &ieee->network_list);
1495 if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
1496 ieee80211_softmac_new_net(ieee,&network);
1498 IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
1499 escape_essid(target->ssid,
1501 MAC_ARG(target->bssid),
1502 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1503 IEEE80211_STYPE_PROBE_RESP ?
1504 "PROBE RESPONSE" : "BEACON");
1506 /* we have an entry and we are going to update it. But this entry may
1507 * be already expired. In this case we do the same as we found a new
1508 * net and call the new_net handler
1510 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
1511 //YJ,add,080819,for hidden ap
1513 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
1514 //if(strncmp(network.ssid, "linksys-c",9) == 0)
1515 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
1516 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
1517 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
1518 ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
1520 //YJ,add,080819,for hidden ap,end
1521 update_network(target, &network);
1522 if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
1523 ieee80211_softmac_new_net(ieee,&network);
1526 spin_unlock_irqrestore(&ieee->lock, flags);
1529 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1530 struct ieee80211_hdr_4addr *header,
1531 struct ieee80211_rx_stats *stats)
1533 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
1535 case IEEE80211_STYPE_BEACON:
1536 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
1537 WLAN_FC_GET_STYPE(header->frame_ctl));
1538 IEEE80211_DEBUG_SCAN("Beacon\n");
1539 ieee80211_process_probe_response(
1540 ieee, (struct ieee80211_probe_response *)header, stats);
1543 case IEEE80211_STYPE_PROBE_RESP:
1544 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1545 WLAN_FC_GET_STYPE(header->frame_ctl));
1546 IEEE80211_DEBUG_SCAN("Probe response\n");
1547 ieee80211_process_probe_response(
1548 ieee, (struct ieee80211_probe_response *)header, stats);