Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * Original code based Host AP (software wireless LAN access point) driver
  3  * for Intersil Prism2/2.5/3 - hostap.o module, common routines
  4  *
  5  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6  * <jkmaline@cc.hut.fi>
  7  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
  8  * Copyright (c) 2004, Intel Corporation
  9  *
 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
 13  * more details.
 14  ******************************************************************************
 15 
 16   Few modifications for Realtek's Wi-Fi drivers by
 17   Andrea Merello <andreamrl@tiscali.it>
 18 
 19   A special thanks goes to Realtek for their support !
 20 
 21 ******************************************************************************/
 22 
 23 
 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>
 29 #include <linux/in.h>
 30 #include <linux/ip.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>
 45 
 46 #include "ieee80211.h"
 47 #ifdef ENABLE_DOT11D
 48 #include "dot11d.h"
 49 #endif
 50 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
 51                                         struct sk_buff *skb,
 52                                         struct ieee80211_rx_stats *rx_stats)
 53 {
 54         struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *)skb->data;
 55         u16 fc = le16_to_cpu(hdr->frame_ctl);
 56 
 57         skb->dev = ieee->dev;
 58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 59         skb_reset_mac_header(skb);
 60 #else
 61         skb->mac.raw = skb->data;
 62 #endif
 63 
 64         skb_pull(skb, ieee80211_get_hdrlen(fc));
 65         skb->pkt_type = PACKET_OTHERHOST;
 66         skb->protocol = __constant_htons(ETH_P_80211_RAW);
 67         memset(skb->cb, 0, sizeof(skb->cb));
 68         netif_rx(skb);
 69 }
 70 
 71 
 72 /* Called only as a tasklet (software IRQ) */
 73 static struct ieee80211_frag_entry *
 74 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
 75                           unsigned int frag, u8 tid,u8 *src, u8 *dst)
 76 {
 77         struct ieee80211_frag_entry *entry;
 78         int i;
 79 
 80         for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
 81                 entry = &ieee->frag_cache[tid][i];
 82                 if (entry->skb != NULL &&
 83                     time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
 84                         IEEE80211_DEBUG_FRAG(
 85                                 "expiring fragment cache entry "
 86                                 "seq=%u last_frag=%u\n",
 87                                 entry->seq, entry->last_frag);
 88                         dev_kfree_skb_any(entry->skb);
 89                         entry->skb = NULL;
 90                 }
 91 
 92                 if (entry->skb != NULL && entry->seq == seq &&
 93                     (entry->last_frag + 1 == frag || frag == -1) &&
 94                     memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
 95                     memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
 96                         return entry;
 97         }
 98 
 99         return NULL;
100 }
101 
102 /* Called only as a tasklet (software IRQ) */
103 static struct sk_buff *
104 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
105                          struct ieee80211_hdr_4addr *hdr)
106 {
107         struct sk_buff *skb = NULL;
108         u16 fc = le16_to_cpu(hdr->frame_ctl);
109         u16 sc = le16_to_cpu(hdr->seq_ctl);
110         unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
111         unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
112         struct ieee80211_frag_entry *entry;
113         struct ieee80211_hdr_3addrqos *hdr_3addrqos;
114         struct ieee80211_hdr_4addrqos *hdr_4addrqos;
115         u8 tid;
116 
117         if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
118           hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
119           tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
120           tid = UP2AC(tid);
121           tid ++;
122         } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
123           hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
124           tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
125           tid = UP2AC(tid);
126           tid ++;
127         } else {
128           tid = 0;
129         }
130 
131         if (frag == 0) {
132                 /* Reserve enough space to fit maximum frame length */
133                 skb = dev_alloc_skb(ieee->dev->mtu +
134                                     sizeof(struct ieee80211_hdr_4addr) +
135                                     8 /* LLC */ +
136                                     2 /* alignment */ +
137                                     8 /* WEP */ +
138                                     ETH_ALEN /* WDS */ +
139                                     (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
140                 if (skb == NULL)
141                         return NULL;
142 
143                 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
144                 ieee->frag_next_idx[tid]++;
145                 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
146                         ieee->frag_next_idx[tid] = 0;
147 
148                 if (entry->skb != NULL)
149                         dev_kfree_skb_any(entry->skb);
150 
151                 entry->first_frag_time = jiffies;
152                 entry->seq = seq;
153                 entry->last_frag = frag;
154                 entry->skb = skb;
155                 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
156                 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
157         } else {
158                 /* received a fragment of a frame for which the head fragment
159                  * should have already been received */
160                 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
161                                                   hdr->addr1);
162                 if (entry != NULL) {
163                         entry->last_frag = frag;
164                         skb = entry->skb;
165                 }
166         }
167 
168         return skb;
169 }
170 
171 
172 /* Called only as a tasklet (software IRQ) */
173 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
174                                            struct ieee80211_hdr_4addr *hdr)
175 {
176         u16 fc = le16_to_cpu(hdr->frame_ctl);
177         u16 sc = le16_to_cpu(hdr->seq_ctl);
178         unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
179         struct ieee80211_frag_entry *entry;
180         struct ieee80211_hdr_3addrqos *hdr_3addrqos;
181         struct ieee80211_hdr_4addrqos *hdr_4addrqos;
182         u8 tid;
183 
184         if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
185           hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
186           tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
187           tid = UP2AC(tid);
188           tid ++;
189         } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
190           hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
191           tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
192           tid = UP2AC(tid);
193           tid ++;
194         } else {
195           tid = 0;
196         }
197 
198         entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
199                                           hdr->addr1);
200 
201         if (entry == NULL) {
202                 IEEE80211_DEBUG_FRAG(
203                         "could not invalidate fragment cache "
204                         "entry (seq=%u)\n", seq);
205                 return -1;
206         }
207 
208         entry->skb = NULL;
209         return 0;
210 }
211 
212 
213 
214 /* ieee80211_rx_frame_mgtmt
215  *
216  * Responsible for handling management control frames
217  *
218  * Called by ieee80211_rx */
219 static inline int
220 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
221                         struct ieee80211_rx_stats *rx_stats, u16 type,
222                         u16 stype)
223 {
224         /* On the struct stats definition there is written that
225          * this is not mandatory.... but seems that the probe
226          * response parser uses it
227          */
228         struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data;
229 
230         rx_stats->len = skb->len;
231         ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
232         //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
233         if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames
234         {
235                 dev_kfree_skb_any(skb);
236                 return 0;
237         }
238 
239         ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
240 
241         dev_kfree_skb_any(skb);
242 
243         return 0;
244 
245         #ifdef NOT_YET
246         if (ieee->iw_mode == IW_MODE_MASTER) {
247                 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
248                        ieee->dev->name);
249                 return 0;
250 /*
251   hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
252   skb->data);*/
253         }
254 
255         if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) {
256                 if (stype == WLAN_FC_STYPE_BEACON &&
257                     ieee->iw_mode == IW_MODE_MASTER) {
258                         struct sk_buff *skb2;
259                         /* Process beacon frames also in kernel driver to
260                          * update STA(AP) table statistics */
261                         skb2 = skb_clone(skb, GFP_ATOMIC);
262                         if (skb2)
263                                 hostap_rx(skb2->dev, skb2, rx_stats);
264                 }
265 
266                 /* send management frames to the user space daemon for
267                  * processing */
268                 ieee->apdevstats.rx_packets++;
269                 ieee->apdevstats.rx_bytes += skb->len;
270                 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
271                 return 0;
272         }
273 
274             if (ieee->iw_mode == IW_MODE_MASTER) {
275                 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
276                         printk(KERN_DEBUG "%s: unknown management frame "
277                                "(type=0x%02x, stype=0x%02x) dropped\n",
278                                skb->dev->name, type, stype);
279                         return -1;
280                 }
281 
282                 hostap_rx(skb->dev, skb, rx_stats);
283                 return 0;
284         }
285 
286         printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
287                "received in non-Host AP mode\n", skb->dev->name);
288         return -1;
289         #endif
290 }
291 
292 
293 
294 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
295 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
296 static unsigned char rfc1042_header[] =
297 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
298 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
299 static unsigned char bridge_tunnel_header[] =
300 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
301 /* No encapsulation header if EtherType < 0x600 (=length) */
302 
303 /* Called by ieee80211_rx_frame_decrypt */
304 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
305                                     struct sk_buff *skb, size_t hdrlen)
306 {
307         struct net_device *dev = ieee->dev;
308         u16 fc, ethertype;
309         struct ieee80211_hdr_4addr *hdr;
310         u8 *pos;
311 
312         if (skb->len < 24)
313                 return 0;
314 
315         hdr = (struct ieee80211_hdr_4addr *) skb->data;
316         fc = le16_to_cpu(hdr->frame_ctl);
317 
318         /* check that the frame is unicast frame to us */
319         if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
320             IEEE80211_FCTL_TODS &&
321             memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
322             memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
323                 /* ToDS frame with own addr BSSID and DA */
324         } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
325                    IEEE80211_FCTL_FROMDS &&
326                    memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
327                 /* FromDS frame with own addr as DA */
328         } else
329                 return 0;
330 
331         if (skb->len < 24 + 8)
332                 return 0;
333 
334         /* check for port access entity Ethernet type */
335 //      pos = skb->data + 24;
336         pos = skb->data + hdrlen;
337         ethertype = (pos[6] << 8) | pos[7];
338         if (ethertype == ETH_P_PAE)
339                 return 1;
340 
341         return 0;
342 }
343 
344 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
345 static inline int
346 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
347                            struct ieee80211_crypt_data *crypt)
348 {
349         struct ieee80211_hdr_4addr *hdr;
350         int res, hdrlen;
351 
352         if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
353                 return 0;
354 #if 1
355         if (ieee->hwsec_active)
356         {
357                 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
358                 tcb_desc->bHwSec = 1;
359         }
360 #endif
361         hdr = (struct ieee80211_hdr_4addr *) skb->data;
362         hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
363 
364 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
365         if (ieee->tkip_countermeasures &&
366             strcmp(crypt->ops->name, "TKIP") == 0) {
367                 if (net_ratelimit()) {
368                         printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
369                                "received packet from " MAC_FMT "\n",
370                                ieee->dev->name, MAC_ARG(hdr->addr2));
371                 }
372                 return -1;
373         }
374 #endif
375 
376         atomic_inc(&crypt->refcnt);
377         res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
378         atomic_dec(&crypt->refcnt);
379         if (res < 0) {
380                 IEEE80211_DEBUG_DROP(
381                         "decryption failed (SA=" MAC_FMT
382                         ") res=%d\n", MAC_ARG(hdr->addr2), res);
383                 if (res == -2)
384                         IEEE80211_DEBUG_DROP("Decryption failed ICV "
385                                              "mismatch (key %d)\n",
386                                              skb->data[hdrlen + 3] >> 6);
387                 ieee->ieee_stats.rx_discards_undecryptable++;
388                 return -1;
389         }
390 
391         return res;
392 }
393 
394 
395 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
396 static inline int
397 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
398                              int keyidx, struct ieee80211_crypt_data *crypt)
399 {
400         struct ieee80211_hdr_4addr *hdr;
401         int res, hdrlen;
402 
403         if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
404                 return 0;
405         if (ieee->hwsec_active)
406         {
407                 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
408                 tcb_desc->bHwSec = 1;
409         }
410 
411         hdr = (struct ieee80211_hdr_4addr *) skb->data;
412         hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
413 
414         atomic_inc(&crypt->refcnt);
415         res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
416         atomic_dec(&crypt->refcnt);
417         if (res < 0) {
418                 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
419                        " (SA=" MAC_FMT " keyidx=%d)\n",
420                        ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
421                 return -1;
422         }
423 
424         return 0;
425 }
426 
427 
428 /* this function is stolen from ipw2200 driver*/
429 #define IEEE_PACKET_RETRY_TIME (5*HZ)
430 static int is_duplicate_packet(struct ieee80211_device *ieee,
431                                       struct ieee80211_hdr_4addr *header)
432 {
433         u16 fc = le16_to_cpu(header->frame_ctl);
434         u16 sc = le16_to_cpu(header->seq_ctl);
435         u16 seq = WLAN_GET_SEQ_SEQ(sc);
436         u16 frag = WLAN_GET_SEQ_FRAG(sc);
437         u16 *last_seq, *last_frag;
438         unsigned long *last_time;
439         struct ieee80211_hdr_3addrqos *hdr_3addrqos;
440         struct ieee80211_hdr_4addrqos *hdr_4addrqos;
441         u8 tid;
442 
443 
444         //TO2DS and QoS
445         if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
446           hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
447           tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
448           tid = UP2AC(tid);
449           tid ++;
450         } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
451           hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header;
452           tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
453           tid = UP2AC(tid);
454           tid ++;
455         } else { // no QoS
456           tid = 0;
457         }
458 
459         switch (ieee->iw_mode) {
460         case IW_MODE_ADHOC:
461         {
462                 struct list_head *p;
463                 struct ieee_ibss_seq *entry = NULL;
464                 u8 *mac = header->addr2;
465                 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
466                 //for (pos = (head)->next; pos != (head); pos = pos->next)
467                 //__list_for_each(p, &ieee->ibss_mac_hash[index]) {
468                 list_for_each(p, &ieee->ibss_mac_hash[index]) {
469                         entry = list_entry(p, struct ieee_ibss_seq, list);
470                         if (!memcmp(entry->mac, mac, ETH_ALEN))
471                                 break;
472                 }
473         //      if (memcmp(entry->mac, mac, ETH_ALEN)){
474                 if (p == &ieee->ibss_mac_hash[index]) {
475                         entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
476                         if (!entry) {
477                                 printk(KERN_WARNING "Cannot malloc new mac entry\n");
478                                 return 0;
479                         }
480                         memcpy(entry->mac, mac, ETH_ALEN);
481                         entry->seq_num[tid] = seq;
482                         entry->frag_num[tid] = frag;
483                         entry->packet_time[tid] = jiffies;
484                         list_add(&entry->list, &ieee->ibss_mac_hash[index]);
485                         return 0;
486                 }
487                 last_seq = &entry->seq_num[tid];
488                 last_frag = &entry->frag_num[tid];
489                 last_time = &entry->packet_time[tid];
490                 break;
491         }
492 
493         case IW_MODE_INFRA:
494                 last_seq = &ieee->last_rxseq_num[tid];
495                 last_frag = &ieee->last_rxfrag_num[tid];
496                 last_time = &ieee->last_packet_time[tid];
497 
498                 break;
499         default:
500                 return 0;
501         }
502 
503 //      if(tid != 0) {
504 //              printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
505 //      }
506         if ((*last_seq == seq) &&
507             time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
508                 if (*last_frag == frag){
509                         //printk(KERN_WARNING "[1] go drop!\n");
510                         goto drop;
511 
512                 }
513                 if (*last_frag + 1 != frag)
514                         /* out-of-order fragment */
515                         //printk(KERN_WARNING "[2] go drop!\n");
516                         goto drop;
517         } else
518                 *last_seq = seq;
519 
520         *last_frag = frag;
521         *last_time = jiffies;
522         return 0;
523 
524 drop:
525 //      BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
526 //      printk("DUP\n");
527 
528         return 1;
529 }
530 bool
531 AddReorderEntry(
532         PRX_TS_RECORD                   pTS,
533         PRX_REORDER_ENTRY               pReorderEntry
534         )
535 {
536         struct list_head *pList = &pTS->RxPendingPktList;
537 #if  1
538         while(pList->next != &pTS->RxPendingPktList)
539         {
540                 if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
541                 {
542                         pList = pList->next;
543                 }
544                 else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
545                 {
546                         return false;
547                 }
548                 else
549                 {
550                         break;
551                 }
552         }
553 #endif
554         pReorderEntry->List.next = pList->next;
555         pReorderEntry->List.next->prev = &pReorderEntry->List;
556         pReorderEntry->List.prev = pList;
557         pList->next = &pReorderEntry->List;
558 
559         return true;
560 }
561 
562 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8  index)
563 {
564         u8 i = 0 , j=0;
565         u16 ethertype;
566 //      if(index > 1)
567 //              IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index);
568         for(j = 0; j<index; j++)
569         {
570 //added by amy for reorder
571                 struct ieee80211_rxb* prxb = prxbIndicateArray[j];
572                 for(i = 0; i<prxb->nr_subframes; i++) {
573                         struct sk_buff *sub_skb = prxb->subframes[i];
574 
575                 /* convert hdr + possible LLC headers into Ethernet header */
576                         ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
577                         if (sub_skb->len >= 8 &&
578                                 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
579                                   ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
580                                  memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
581                         /* remove RFC1042 or Bridge-Tunnel encapsulation and
582                          * replace EtherType */
583                                 skb_pull(sub_skb, SNAP_SIZE);
584                                 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
585                                 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
586                         } else {
587                                 u16 len;
588                         /* Leave Ethernet header part of hdr and full payload */
589                                 len = htons(sub_skb->len);
590                                 memcpy(skb_push(sub_skb, 2), &len, 2);
591                                 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
592                                 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
593                         }
594                         //stats->rx_packets++;
595                         //stats->rx_bytes += sub_skb->len;
596 
597                 /* Indicat the packets to upper layer */
598                         if (sub_skb) {
599                                 //printk("0skb_len(%d)\n", skb->len);
600                                 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
601                                 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
602                                 sub_skb->dev = ieee->dev;
603                                 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
604                                 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
605                                 ieee->last_rx_ps_time = jiffies;
606                                 //printk("1skb_len(%d)\n", skb->len);
607                                 netif_rx(sub_skb);
608                         }
609                 }
610                 kfree(prxb);
611                 prxb = NULL;
612         }
613 }
614 
615 
616 void RxReorderIndicatePacket( struct ieee80211_device *ieee,
617                 struct ieee80211_rxb* prxb,
618                 PRX_TS_RECORD           pTS,
619                 u16                     SeqNum)
620 {
621         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
622         PRX_REORDER_ENTRY       pReorderEntry = NULL;
623         struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
624         u8                      WinSize = pHTInfo->RxReorderWinSize;
625         u16                     WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
626         u8                      index = 0;
627         bool                    bMatchWinStart = false, bPktInBuf = false;
628         IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize);
629 #if 0
630         if(!list_empty(&ieee->RxReorder_Unused_List))
631                 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): ieee->RxReorder_Unused_List is nut NULL\n");
632 #endif
633         /* Rx Reorder initialize condition.*/
634         if(pTS->RxIndicateSeq == 0xffff) {
635                 pTS->RxIndicateSeq = SeqNum;
636         }
637 
638         /* Drop out the packet which SeqNum is smaller than WinStart */
639         if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
640                 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
641                                  pTS->RxIndicateSeq, SeqNum);
642                 pHTInfo->RxReorderDropCounter++;
643                 {
644                         int i;
645                         for(i =0; i < prxb->nr_subframes; i++) {
646                                 dev_kfree_skb(prxb->subframes[i]);
647                         }
648                         kfree(prxb);
649                         prxb = NULL;
650                 }
651                 return;
652         }
653 
654         /*
655          * Sliding window manipulation. Conditions includes:
656          * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
657          * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
658          */
659         if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
660                 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
661                 bMatchWinStart = true;
662         } else if(SN_LESS(WinEnd, SeqNum)) {
663                 if(SeqNum >= (WinSize - 1)) {
664                         pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
665                 } else {
666                         pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
667                 }
668                 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
669         }
670 
671         /*
672          * Indication process.
673          * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
674          * with the SeqNum smaller than latest WinStart and buffer other packets.
675          */
676         /* For Rx Reorder condition:
677          * 1. All packets with SeqNum smaller than WinStart => Indicate
678          * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
679          */
680         if(bMatchWinStart) {
681                 /* Current packet is going to be indicated.*/
682                 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
683                                 pTS->RxIndicateSeq, SeqNum);
684                 prxbIndicateArray[0] = prxb;
685 //              printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum);
686                 index = 1;
687         } else {
688                 /* Current packet is going to be inserted into pending list.*/
689                 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__);
690                 if(!list_empty(&ieee->RxReorder_Unused_List)) {
691                         pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
692                         list_del_init(&pReorderEntry->List);
693 
694                         /* Make a reorder entry and insert into a the packet list.*/
695                         pReorderEntry->SeqNum = SeqNum;
696                         pReorderEntry->prxb = prxb;
697         //              IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
698 
699 #if 1
700                         if(!AddReorderEntry(pTS, pReorderEntry)) {
701                                 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
702                                         __FUNCTION__, pTS->RxIndicateSeq, SeqNum);
703                                 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
704                                 {
705                                         int i;
706                                         for(i =0; i < prxb->nr_subframes; i++) {
707                                                 dev_kfree_skb(prxb->subframes[i]);
708                                         }
709                                         kfree(prxb);
710                                         prxb = NULL;
711                                 }
712                         } else {
713                                 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
714                                          "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
715                         }
716 #endif
717                 }
718                 else {
719                         /*
720                          * Packets are dropped if there is not enough reorder entries.
721                          * This part shall be modified!! We can just indicate all the
722                          * packets in buffer and get reorder entries.
723                          */
724                         IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
725                         {
726                                 int i;
727                                 for(i =0; i < prxb->nr_subframes; i++) {
728                                         dev_kfree_skb(prxb->subframes[i]);
729                                 }
730                                 kfree(prxb);
731                                 prxb = NULL;
732                         }
733                 }
734         }
735 
736         /* Check if there is any packet need indicate.*/
737         while(!list_empty(&pTS->RxPendingPktList)) {
738                 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__);
739 #if 1
740                 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
741                 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
742                                 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
743                 {
744                         /* This protect buffer from overflow. */
745                         if(index >= REORDER_WIN_SIZE) {
746                                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
747                                 bPktInBuf = true;
748                                 break;
749                         }
750 
751                         list_del_init(&pReorderEntry->List);
752 
753                         if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
754                                 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
755 
756                         IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
757                         prxbIndicateArray[index] = pReorderEntry->prxb;
758                 //      printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum);
759                         index++;
760 
761                         list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
762                 } else {
763                         bPktInBuf = true;
764                         break;
765                 }
766 #endif
767         }
768 
769         /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
770         if(index>0) {
771                 // Cancel previous pending timer.
772                 if(timer_pending(&pTS->RxPktPendingTimer))
773                 {
774                         del_timer_sync(&pTS->RxPktPendingTimer);
775                 }
776         //      del_timer_sync(&pTS->RxPktPendingTimer);
777                 pTS->RxTimeoutIndicateSeq = 0xffff;
778 
779                 // Indicate packets
780                 if(index>REORDER_WIN_SIZE){
781                         IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
782                         return;
783                 }
784                 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
785                 bPktInBuf = false;
786         }
787 
788 #if 1
789         if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
790                 // Set new pending timer.
791                 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__);
792                 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
793 #if 0
794                 if(timer_pending(&pTS->RxPktPendingTimer))
795                         del_timer_sync(&pTS->RxPktPendingTimer);
796                 pTS->RxPktPendingTimer.expires = jiffies + MSECS(pHTInfo->RxReorderPendingTime);
797                 add_timer(&pTS->RxPktPendingTimer);
798 #else
799                 mod_timer(&pTS->RxPktPendingTimer,  jiffies + MSECS(pHTInfo->RxReorderPendingTime));
800 #endif
801         }
802 #endif
803 }
804 
805 u8 parse_subframe(struct sk_buff *skb,
806                   struct ieee80211_rx_stats *rx_stats,
807                   struct ieee80211_rxb *rxb,u8* src,u8* dst)
808 {
809         struct ieee80211_hdr_3addr  *hdr = (struct ieee80211_hdr_3addr* )skb->data;
810         u16             fc = le16_to_cpu(hdr->frame_ctl);
811 
812         u16             LLCOffset= sizeof(struct ieee80211_hdr_3addr);
813         u16             ChkLength;
814         bool            bIsAggregateFrame = false;
815         u16             nSubframe_Length;
816         u8              nPadding_Length = 0;
817         u16             SeqNum=0;
818 
819         struct sk_buff *sub_skb;
820         u8             *data_ptr;
821         /* just for debug purpose */
822         SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
823 
824         if((IEEE80211_QOS_HAS_SEQ(fc))&&\
825                         (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
826                 bIsAggregateFrame = true;
827         }
828 
829         if(IEEE80211_QOS_HAS_SEQ(fc)) {
830                 LLCOffset += 2;
831         }
832 
833         if(rx_stats->bContainHTC) {
834                 LLCOffset += sHTCLng;
835         }
836         //printk("ChkLength = %d\n", LLCOffset);
837         // Null packet, don't indicate it to upper layer
838         ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
839 
840         if( skb->len <= ChkLength ) {
841                 return 0;
842         }
843 
844         skb_pull(skb, LLCOffset);
845 
846         if(!bIsAggregateFrame) {
847                 rxb->nr_subframes = 1;
848 #ifdef JOHN_NOCPY
849                 rxb->subframes[0] = skb;
850 #else
851                 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
852 #endif
853 
854                 memcpy(rxb->src,src,ETH_ALEN);
855                 memcpy(rxb->dst,dst,ETH_ALEN);
856                 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
857                 return 1;
858         } else {
859                 rxb->nr_subframes = 0;
860                 memcpy(rxb->src,src,ETH_ALEN);
861                 memcpy(rxb->dst,dst,ETH_ALEN);
862                 while(skb->len > ETHERNET_HEADER_SIZE) {
863                         /* Offset 12 denote 2 mac address */
864                         nSubframe_Length = *((u16*)(skb->data + 12));
865                         //==m==>change the length order
866                         nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
867 
868                         if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
869 #if 0//cosa
870                                 RT_ASSERT(
871                                                 (nRemain_Length>=(ETHERNET_HEADER_SIZE + nSubframe_Length)),
872                                                 ("ParseSubframe(): A-MSDU subframe parse error!! Subframe Length: %d\n", nSubframe_Length) );
873 #endif
874                                 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
875                                                 __FUNCTION__,rxb->nr_subframes);
876                                 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length);
877                                 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
878                                 printk("The Packet SeqNum is %d\n",SeqNum);
879                                 return 0;
880                         }
881 
882                         /* move the data point to data content */
883                         skb_pull(skb, ETHERNET_HEADER_SIZE);
884 
885 #ifdef JOHN_NOCPY
886                         sub_skb = skb_clone(skb, GFP_ATOMIC);
887                         sub_skb->len = nSubframe_Length;
888                         sub_skb->tail = sub_skb->data + nSubframe_Length;
889 #else
890                         /* Allocate new skb for releasing to upper layer */
891                         sub_skb = dev_alloc_skb(nSubframe_Length + 12);
892                         skb_reserve(sub_skb, 12);
893                         data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
894                         memcpy(data_ptr,skb->data,nSubframe_Length);
895 #endif
896                         rxb->subframes[rxb->nr_subframes++] = sub_skb;
897                         if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
898                                 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
899                                 break;
900                         }
901                         skb_pull(skb,nSubframe_Length);
902 
903                         if(skb->len != 0) {
904                                 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
905                                 if(nPadding_Length == 4) {
906                                         nPadding_Length = 0;
907                                 }
908 
909                                 if(skb->len < nPadding_Length) {
910                                         return 0;
911                                 }
912 
913                                 skb_pull(skb,nPadding_Length);
914                         }
915                 }
916 #ifdef JOHN_NOCPY
917                 dev_kfree_skb(skb);
918 #endif
919                 //{just for debug added by david
920                 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
921                 //}
922                 return rxb->nr_subframes;
923         }
924 }
925 
926 /* All received frames are sent to this function. @skb contains the frame in
927  * IEEE 802.11 format, i.e., in the format it was sent over air.
928  * This function is called only as a tasklet (software IRQ). */
929 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
930                  struct ieee80211_rx_stats *rx_stats)
931 {
932         struct net_device *dev = ieee->dev;
933         struct ieee80211_hdr_4addr *hdr;
934         //struct ieee80211_hdr_3addrqos *hdr;
935 
936         size_t hdrlen;
937         u16 fc, type, stype, sc;
938         struct net_device_stats *stats;
939         unsigned int frag;
940         u8 *payload;
941         u16 ethertype;
942         //added by amy for reorder
943         u8      TID = 0;
944         u16     SeqNum = 0;
945         PRX_TS_RECORD pTS = NULL;
946         //bool bIsAggregateFrame = false;
947         //added by amy for reorder
948 #ifdef NOT_YET
949         struct net_device *wds = NULL;
950         struct sk_buff *skb2 = NULL;
951         struct net_device *wds = NULL;
952         int frame_authorized = 0;
953         int from_assoc_ap = 0;
954         void *sta = NULL;
955 #endif
956 //      u16 qos_ctl = 0;
957         u8 dst[ETH_ALEN];
958         u8 src[ETH_ALEN];
959         u8 bssid[ETH_ALEN];
960         struct ieee80211_crypt_data *crypt = NULL;
961         int keyidx = 0;
962 
963         int i;
964         struct ieee80211_rxb* rxb = NULL;
965         // cheat the the hdr type
966         hdr = (struct ieee80211_hdr_4addr *)skb->data;
967         stats = &ieee->stats;
968 
969         if (skb->len < 10) {
970                 printk(KERN_INFO "%s: SKB length < 10\n",
971                        dev->name);
972                 goto rx_dropped;
973         }
974 
975         fc = le16_to_cpu(hdr->frame_ctl);
976         type = WLAN_FC_GET_TYPE(fc);
977         stype = WLAN_FC_GET_STYPE(fc);
978         sc = le16_to_cpu(hdr->seq_ctl);
979 
980         frag = WLAN_GET_SEQ_FRAG(sc);
981         hdrlen = ieee80211_get_hdrlen(fc);
982 
983         if(HTCCheck(ieee, skb->data))
984         {
985                 if(net_ratelimit())
986                 printk("find HTCControl\n");
987                 hdrlen += 4;
988                 rx_stats->bContainHTC = 1;
989         }
990 
991         //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
992 #ifdef NOT_YET
993 #if WIRELESS_EXT > 15
994         /* Put this code here so that we avoid duplicating it in all
995          * Rx paths. - Jean II */
996 #ifdef IW_WIRELESS_SPY          /* defined in iw_handler.h */
997         /* If spy monitoring on */
998         if (iface->spy_data.spy_number > 0) {
999                 struct iw_quality wstats;
1000                 wstats.level = rx_stats->rssi;
1001                 wstats.noise = rx_stats->noise;
1002                 wstats.updated = 6;     /* No qual value */
1003                 /* Update spy records */
1004                 wireless_spy_update(dev, hdr->addr2, &wstats);
1005         }
1006 #endif /* IW_WIRELESS_SPY */
1007 #endif /* WIRELESS_EXT > 15 */
1008         hostap_update_rx_stats(local->ap, hdr, rx_stats);
1009 #endif
1010 
1011 #if WIRELESS_EXT > 15
1012         if (ieee->iw_mode == IW_MODE_MONITOR) {
1013                 ieee80211_monitor_rx(ieee, skb, rx_stats);
1014                 stats->rx_packets++;
1015                 stats->rx_bytes += skb->len;
1016                 return 1;
1017         }
1018 #endif
1019         if (ieee->host_decrypt) {
1020                 int idx = 0;
1021                 if (skb->len >= hdrlen + 3)
1022                         idx = skb->data[hdrlen + 3] >> 6;
1023                 crypt = ieee->crypt[idx];
1024 #ifdef NOT_YET
1025                 sta = NULL;
1026 
1027                 /* Use station specific key to override default keys if the
1028                  * receiver address is a unicast address ("individual RA"). If
1029                  * bcrx_sta_key parameter is set, station specific key is used
1030                  * even with broad/multicast targets (this is against IEEE
1031                  * 802.11, but makes it easier to use different keys with
1032                  * stations that do not support WEP key mapping). */
1033 
1034                 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1035                         (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1036                                                         &sta);
1037 #endif
1038 
1039                 /* allow NULL decrypt to indicate an station specific override
1040                  * for default encryption */
1041                 if (crypt && (crypt->ops == NULL ||
1042                               crypt->ops->decrypt_mpdu == NULL))
1043                         crypt = NULL;
1044 
1045                 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
1046                         /* This seems to be triggered by some (multicast?)
1047                          * frames from other than current BSS, so just drop the
1048                          * frames silently instead of filling system log with
1049                          * these reports. */
1050                         IEEE80211_DEBUG_DROP("Decryption failed (not set)"
1051                                              " (SA=" MAC_FMT ")\n",
1052                                              MAC_ARG(hdr->addr2));
1053                         ieee->ieee_stats.rx_discards_undecryptable++;
1054                         goto rx_dropped;
1055                 }
1056         }
1057 
1058         if (skb->len < IEEE80211_DATA_HDR3_LEN)
1059                 goto rx_dropped;
1060 
1061         // if QoS enabled, should check the sequence for each of the AC
1062         if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){
1063                 if (is_duplicate_packet(ieee, hdr))
1064                 goto rx_dropped;
1065 
1066         }
1067         else
1068         {
1069                 PRX_TS_RECORD pRxTS = NULL;
1070         #if 0
1071                 struct ieee80211_hdr_3addr *hdr;
1072                 u16 fc;
1073                 hdr = (struct ieee80211_hdr_3addr *)skb->data;
1074                 fc = le16_to_cpu(hdr->frame_ctl);
1075                 u8 tmp = (fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS);
1076 
1077                 u8 tid = (*((u8*)skb->data + (((fc& IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))?30:24)))&0xf;
1078                 printk("====================>fc:%x, tid:%d, tmp:%d\n", fc, tid, tmp);
1079                 //u8 tid =  (u8)((frameqos*)(buf + ((fc & IEEE80211_FCTL_TODS)&&(fc & IEEE80211_FCTL_FROMDS))? 30 : 24))->field.tid;
1080         #endif
1081                         //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid);
1082 #if 1
1083                 if(GetTs(
1084                                 ieee,
1085                                 (PTS_COMMON_INFO*) &pRxTS,
1086                                 hdr->addr2,
1087                                 (u8)Frame_QoSTID((u8*)(skb->data)),
1088                                 RX_DIR,
1089                                 true))
1090                 {
1091 
1092                 //      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));
1093                         if(     (fc & (1<<11))  &&
1094                                         (frag == pRxTS->RxLastFragNum) &&
1095                                         (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum)   )
1096                         {
1097                                 goto rx_dropped;
1098                         }
1099                         else
1100                         {
1101                                 pRxTS->RxLastFragNum = frag;
1102                                 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1103                         }
1104                 }
1105                 else
1106                 {
1107                         IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__);
1108                         goto rx_dropped;
1109                 }
1110         }
1111 #endif
1112         if (type == IEEE80211_FTYPE_MGMT) {
1113 
1114         #if 0
1115                 if ( stype == IEEE80211_STYPE_AUTH &&
1116                     fc & IEEE80211_FCTL_WEP && ieee->host_decrypt &&
1117                     (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1118                 {
1119                         printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
1120                                "from " MAC_FMT "\n", dev->name,
1121                                MAC_ARG(hdr->addr2));
1122                         /* TODO: could inform hostapd about this so that it
1123                          * could send auth failure report */
1124                         goto rx_dropped;
1125                 }
1126         #endif
1127 
1128         //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1129                 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1130                         goto rx_dropped;
1131                 else
1132                         goto rx_exit;
1133         }
1134 
1135         /* Data frame - extract src/dst addresses */
1136         switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1137         case IEEE80211_FCTL_FROMDS:
1138                 memcpy(dst, hdr->addr1, ETH_ALEN);
1139                 memcpy(src, hdr->addr3, ETH_ALEN);
1140                 memcpy(bssid, hdr->addr2, ETH_ALEN);
1141                 break;
1142         case IEEE80211_FCTL_TODS:
1143                 memcpy(dst, hdr->addr3, ETH_ALEN);
1144                 memcpy(src, hdr->addr2, ETH_ALEN);
1145                 memcpy(bssid, hdr->addr1, ETH_ALEN);
1146                 break;
1147         case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1148                 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1149                         goto rx_dropped;
1150                 memcpy(dst, hdr->addr3, ETH_ALEN);
1151                 memcpy(src, hdr->addr4, ETH_ALEN);
1152                 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1153                 break;
1154         case 0:
1155                 memcpy(dst, hdr->addr1, ETH_ALEN);
1156                 memcpy(src, hdr->addr2, ETH_ALEN);
1157                 memcpy(bssid, hdr->addr3, ETH_ALEN);
1158                 break;
1159         }
1160 
1161 #ifdef NOT_YET
1162         if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1163                 goto rx_dropped;
1164         if (wds) {
1165                 skb->dev = dev = wds;
1166                 stats = hostap_get_stats(dev);
1167         }
1168 
1169         if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1170             (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1171             ieee->stadev &&
1172             memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1173                 /* Frame from BSSID of the AP for which we are a client */
1174                 skb->dev = dev = ieee->stadev;
1175                 stats = hostap_get_stats(dev);
1176                 from_assoc_ap = 1;
1177         }
1178 #endif
1179 
1180         dev->last_rx = jiffies;
1181 
1182 #ifdef NOT_YET
1183         if ((ieee->iw_mode == IW_MODE_MASTER ||
1184              ieee->iw_mode == IW_MODE_REPEAT) &&
1185             !from_assoc_ap) {
1186                 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1187                                              wds != NULL)) {
1188                 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1189                         frame_authorized = 0;
1190                         break;
1191                 case AP_RX_CONTINUE:
1192                         frame_authorized = 1;
1193                         break;
1194                 case AP_RX_DROP:
1195                         goto rx_dropped;
1196                 case AP_RX_EXIT:
1197                         goto rx_exit;
1198                 }
1199         }
1200 #endif
1201         //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1202         /* Nullfunc frames may have PS-bit set, so they must be passed to
1203          * hostap_handle_sta_rx() before being dropped here. */
1204         if (stype != IEEE80211_STYPE_DATA &&
1205             stype != IEEE80211_STYPE_DATA_CFACK &&
1206             stype != IEEE80211_STYPE_DATA_CFPOLL &&
1207             stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
1208             stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1209             ) {
1210                 if (stype != IEEE80211_STYPE_NULLFUNC)
1211                         IEEE80211_DEBUG_DROP(
1212                                 "RX: dropped data frame "
1213                                 "with no data (type=0x%02x, "
1214                                 "subtype=0x%02x, len=%d)\n",
1215                                 type, stype, skb->len);
1216                 goto rx_dropped;
1217         }
1218         if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1219                 goto rx_dropped;
1220 
1221         /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1222 
1223         if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1224             (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
1225         {
1226                 printk("decrypt frame error\n");
1227                 goto rx_dropped;
1228         }
1229 
1230 
1231         hdr = (struct ieee80211_hdr_4addr *) skb->data;
1232 
1233         /* skb: hdr + (possibly fragmented) plaintext payload */
1234         // PR: FIXME: hostap has additional conditions in the "if" below:
1235         // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1236         if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1237                 int flen;
1238                 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1239                 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1240 
1241                 if (!frag_skb) {
1242                         IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1243                                         "Rx cannot get skb from fragment "
1244                                         "cache (morefrag=%d seq=%u frag=%u)\n",
1245                                         (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1246                                         WLAN_GET_SEQ_SEQ(sc), frag);
1247                         goto rx_dropped;
1248                 }
1249                 flen = skb->len;
1250                 if (frag != 0)
1251                         flen -= hdrlen;
1252 
1253                 if (frag_skb->tail + flen > frag_skb->end) {
1254                         printk(KERN_WARNING "%s: host decrypted and "
1255                                "reassembled frame did not fit skb\n",
1256                                dev->name);
1257                         ieee80211_frag_cache_invalidate(ieee, hdr);
1258                         goto rx_dropped;
1259                 }
1260 
1261                 if (frag == 0) {
1262                         /* copy first fragment (including full headers) into
1263                          * beginning of the fragment cache skb */
1264                         memcpy(skb_put(frag_skb, flen), skb->data, flen);
1265                 } else {
1266                         /* append frame payload to the end of the fragment
1267                          * cache skb */
1268                         memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1269                                flen);
1270                 }
1271                 dev_kfree_skb_any(skb);
1272                 skb = NULL;
1273 
1274                 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1275                         /* more fragments expected - leave the skb in fragment
1276                          * cache for now; it will be delivered to upper layers
1277                          * after all fragments have been received */
1278                         goto rx_exit;
1279                 }
1280 
1281                 /* this was the last fragment and the frame will be
1282                  * delivered, so remove skb from fragment cache */
1283                 skb = frag_skb;
1284                 hdr = (struct ieee80211_hdr_4addr *) skb->data;
1285                 ieee80211_frag_cache_invalidate(ieee, hdr);
1286         }
1287 
1288         /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1289          * encrypted/authenticated */
1290         if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1291             ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1292         {
1293                 printk("==>decrypt msdu error\n");
1294                 goto rx_dropped;
1295         }
1296 
1297         //added by amy for AP roaming
1298         ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1299         ieee->LinkDetectInfo.NumRxOkInPeriod++;
1300 
1301         hdr = (struct ieee80211_hdr_4addr *) skb->data;
1302         if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1303                 if (/*ieee->ieee802_1x &&*/
1304                     ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1305 
1306 #ifdef CONFIG_IEEE80211_DEBUG
1307                         /* pass unencrypted EAPOL frames even if encryption is
1308                          * configured */
1309                         struct eapol *eap = (struct eapol *)(skb->data +
1310                                 24);
1311                         IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1312                                                 eap_get_type(eap->type));
1313 #endif
1314                 } else {
1315                         IEEE80211_DEBUG_DROP(
1316                                 "encryption configured, but RX "
1317                                 "frame not encrypted (SA=" MAC_FMT ")\n",
1318                                 MAC_ARG(hdr->addr2));
1319                         goto rx_dropped;
1320                 }
1321         }
1322 
1323 #ifdef CONFIG_IEEE80211_DEBUG
1324         if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1325             ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1326                         struct eapol *eap = (struct eapol *)(skb->data +
1327                                 24);
1328                         IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1329                                                 eap_get_type(eap->type));
1330         }
1331 #endif
1332 
1333         if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1334             !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1335                 IEEE80211_DEBUG_DROP(
1336                         "dropped unencrypted RX data "
1337                         "frame from " MAC_FMT
1338                         " (drop_unencrypted=1)\n",
1339                         MAC_ARG(hdr->addr2));
1340                 goto rx_dropped;
1341         }
1342 /*
1343         if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1344                 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1345         }
1346 */
1347 //added by amy for reorder
1348 #if 1
1349         if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1350                 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1))
1351         {
1352                 TID = Frame_QoSTID(skb->data);
1353                 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1354                 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1355                 if(TID !=0 && TID !=3)
1356                 {
1357                         ieee->bis_any_nonbepkts = true;
1358                 }
1359         }
1360 #endif
1361 //added by amy for reorder
1362         /* skb: hdr + (possible reassembled) full plaintext payload */
1363         payload = skb->data + hdrlen;
1364         //ethertype = (payload[6] << 8) | payload[7];
1365         rxb = (struct ieee80211_rxb*)kmalloc(sizeof(struct ieee80211_rxb),GFP_ATOMIC);
1366         if(rxb == NULL)
1367         {
1368                 IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__);
1369                 goto rx_dropped;
1370         }
1371         /* to parse amsdu packets */
1372         /* qos data packets & reserved bit is 1 */
1373         if(parse_subframe(skb,rx_stats,rxb,src,dst) == 0) {
1374                 /* only to free rxb, and not submit the packets to upper layer */
1375                 for(i =0; i < rxb->nr_subframes; i++) {
1376                         dev_kfree_skb(rxb->subframes[i]);
1377                 }
1378                 kfree(rxb);
1379                 rxb = NULL;
1380                 goto rx_dropped;
1381         }
1382 
1383         ieee->last_rx_ps_time = jiffies;
1384 //added by amy for reorder
1385         if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){
1386 //added by amy for reorder
1387                 for(i = 0; i<rxb->nr_subframes; i++) {
1388                         struct sk_buff *sub_skb = rxb->subframes[i];
1389 
1390                         if (sub_skb) {
1391                                 /* convert hdr + possible LLC headers into Ethernet header */
1392                                 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1393                                 if (sub_skb->len >= 8 &&
1394                                                 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1395                                                   ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1396                                                  memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1397                                         /* remove RFC1042 or Bridge-Tunnel encapsulation and
1398                                          * replace EtherType */
1399                                         skb_pull(sub_skb, SNAP_SIZE);
1400                                         memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1401                                         memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1402                                 } else {
1403                                         u16 len;
1404                                         /* Leave Ethernet header part of hdr and full payload */
1405                                         len = htons(sub_skb->len);
1406                                         memcpy(skb_push(sub_skb, 2), &len, 2);
1407                                         memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1408                                         memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1409                                 }
1410 
1411                                 stats->rx_packets++;
1412                                 stats->rx_bytes += sub_skb->len;
1413                                 if(is_multicast_ether_addr(dst)) {
1414                                         stats->multicast++;
1415                                 }
1416 
1417                                 /* Indicat the packets to upper layer */
1418                                 //printk("0skb_len(%d)\n", skb->len);
1419                                 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1420                                 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1421                                 sub_skb->dev = dev;
1422                                 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1423                                 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1424                                 //printk("1skb_len(%d)\n", skb->len);
1425                                 netif_rx(sub_skb);
1426                         }
1427                 }
1428                 kfree(rxb);
1429                 rxb = NULL;
1430 
1431         }
1432         else
1433         {
1434                 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__);
1435                 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1436         }
1437 #ifndef JOHN_NOCPY
1438         dev_kfree_skb(skb);
1439 #endif
1440 
1441  rx_exit:
1442 #ifdef NOT_YET
1443         if (sta)
1444                 hostap_handle_sta_release(sta);
1445 #endif
1446         return 1;
1447 
1448  rx_dropped:
1449         if (rxb != NULL)
1450         {
1451                 kfree(rxb);
1452                 rxb = NULL;
1453         }
1454         stats->rx_dropped++;
1455 
1456         /* Returning 0 indicates to caller that we have not handled the SKB--
1457          * so it is still allocated and can be used again by underlying
1458          * hardware as a DMA target */
1459         return 0;
1460 }
1461 
1462 #define MGMT_FRAME_FIXED_PART_LENGTH            0x24
1463 
1464 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1465 
1466 /*
1467 * Make ther structure we read from the beacon packet has
1468 * the right values
1469 */
1470 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1471                                      *info_element, int sub_type)
1472 {
1473 
1474         if (info_element->qui_subtype != sub_type)
1475                 return -1;
1476         if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1477                 return -1;
1478         if (info_element->qui_type != QOS_OUI_TYPE)
1479                 return -1;
1480         if (info_element->version != QOS_VERSION_1)
1481                 return -1;
1482 
1483         return 0;
1484 }
1485 
1486 
1487 /*
1488  * Parse a QoS parameter element
1489  */
1490 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1491                                             *element_param, struct ieee80211_info_element
1492                                             *info_element)
1493 {
1494         int ret = 0;
1495         u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1496 
1497         if ((info_element == NULL) || (element_param == NULL))
1498                 return -1;
1499 
1500         if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1501                 memcpy(element_param->info_element.qui, info_element->data,
1502                        info_element->len);
1503                 element_param->info_element.elementID = info_element->id;
1504                 element_param->info_element.length = info_element->len;
1505         } else
1506                 ret = -1;
1507         if (ret == 0)
1508                 ret = ieee80211_verify_qos_info(&element_param->info_element,
1509                                                 QOS_OUI_PARAM_SUB_TYPE);
1510         return ret;
1511 }
1512 
1513 /*
1514  * Parse a QoS information element
1515  */
1516 static int ieee80211_read_qos_info_element(struct
1517                                            ieee80211_qos_information_element
1518                                            *element_info, struct ieee80211_info_element
1519                                            *info_element)
1520 {
1521         int ret = 0;
1522         u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1523 
1524         if (element_info == NULL)
1525                 return -1;
1526         if (info_element == NULL)
1527                 return -1;
1528 
1529         if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1530                 memcpy(element_info->qui, info_element->data,
1531                        info_element->len);
1532                 element_info->elementID = info_element->id;
1533                 element_info->length = info_element->len;
1534         } else
1535                 ret = -1;
1536 
1537         if (ret == 0)
1538                 ret = ieee80211_verify_qos_info(element_info,
1539                                                 QOS_OUI_INFO_SUB_TYPE);
1540         return ret;
1541 }
1542 
1543 
1544 /*
1545  * Write QoS parameters from the ac parameters.
1546  */
1547 static int ieee80211_qos_convert_ac_to_parameters(struct
1548                                                   ieee80211_qos_parameter_info
1549                                                   *param_elm, struct
1550                                                   ieee80211_qos_parameters
1551                                                   *qos_param)
1552 {
1553         int rc = 0;
1554         int i;
1555         struct ieee80211_qos_ac_parameter *ac_params;
1556         u8 aci;
1557         //u8 cw_min;
1558         //u8 cw_max;
1559 
1560         for (i = 0; i < QOS_QUEUE_NUM; i++) {
1561                 ac_params = &(param_elm->ac_params_record[i]);
1562 
1563                 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1564 
1565                 if(aci >= QOS_QUEUE_NUM)
1566                         continue;
1567                 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1568 
1569                 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1570                 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1571 
1572                 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1573 
1574                 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1575 
1576                 qos_param->flag[aci] =
1577                     (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1578                 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1579         }
1580         return rc;
1581 }
1582 
1583 /*
1584  * we have a generic data element which it may contain QoS information or
1585  * parameters element. check the information element length to decide
1586  * which type to read
1587  */
1588 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1589                                              *info_element,
1590                                              struct ieee80211_network *network)
1591 {
1592         int rc = 0;
1593         struct ieee80211_qos_parameters *qos_param = NULL;
1594         struct ieee80211_qos_information_element qos_info_element;
1595 
1596         rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1597 
1598         if (rc == 0) {
1599                 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1600                 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1601         } else {
1602                 struct ieee80211_qos_parameter_info param_element;
1603 
1604                 rc = ieee80211_read_qos_param_element(&param_element,
1605                                                       info_element);
1606                 if (rc == 0) {
1607                         qos_param = &(network->qos_data.parameters);
1608                         ieee80211_qos_convert_ac_to_parameters(&param_element,
1609                                                                qos_param);
1610                         network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1611                         network->qos_data.param_count =
1612                             param_element.info_element.ac_info & 0x0F;
1613                 }
1614         }
1615 
1616         if (rc == 0) {
1617                 IEEE80211_DEBUG_QOS("QoS is supported\n");
1618                 network->qos_data.supported = 1;
1619         }
1620         return rc;
1621 }
1622 
1623 #ifdef CONFIG_IEEE80211_DEBUG
1624 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1625 
1626 static const char *get_info_element_string(u16 id)
1627 {
1628         switch (id) {
1629                 MFIE_STRING(SSID);
1630                 MFIE_STRING(RATES);
1631                 MFIE_STRING(FH_SET);
1632                 MFIE_STRING(DS_SET);
1633                 MFIE_STRING(CF_SET);
1634                 MFIE_STRING(TIM);
1635                 MFIE_STRING(IBSS_SET);
1636                 MFIE_STRING(COUNTRY);
1637                 MFIE_STRING(HOP_PARAMS);
1638                 MFIE_STRING(HOP_TABLE);
1639                 MFIE_STRING(REQUEST);
1640                 MFIE_STRING(CHALLENGE);
1641                 MFIE_STRING(POWER_CONSTRAINT);
1642                 MFIE_STRING(POWER_CAPABILITY);
1643                 MFIE_STRING(TPC_REQUEST);
1644                 MFIE_STRING(TPC_REPORT);
1645                 MFIE_STRING(SUPP_CHANNELS);
1646                 MFIE_STRING(CSA);
1647                 MFIE_STRING(MEASURE_REQUEST);
1648                 MFIE_STRING(MEASURE_REPORT);
1649                 MFIE_STRING(QUIET);
1650                 MFIE_STRING(IBSS_DFS);
1651                // MFIE_STRING(ERP_INFO);
1652                 MFIE_STRING(RSN);
1653                 MFIE_STRING(RATES_EX);
1654                 MFIE_STRING(GENERIC);
1655                 MFIE_STRING(QOS_PARAMETER);
1656         default:
1657                 return "UNKNOWN";
1658         }
1659 }
1660 #endif
1661 
1662 #ifdef ENABLE_DOT11D
1663 static inline void ieee80211_extract_country_ie(
1664         struct ieee80211_device *ieee,
1665         struct ieee80211_info_element *info_element,
1666         struct ieee80211_network *network,
1667         u8 * addr2
1668 )
1669 {
1670         if(IS_DOT11D_ENABLE(ieee))
1671         {
1672                 if(info_element->len!= 0)
1673                 {
1674                         memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1675                         network->CountryIeLen = info_element->len;
1676 
1677                         if(!IS_COUNTRY_IE_VALID(ieee))
1678                         {
1679                                 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1680                         }
1681                 }
1682 
1683                 //
1684                 // 070305, rcnjko: I update country IE watch dog here because
1685                 // some AP (e.g. Cisco 1242) don't include country IE in their
1686                 // probe response frame.
1687                 //
1688                 if(IS_EQUAL_CIE_SRC(ieee, addr2) )
1689                 {
1690                         UPDATE_CIE_WATCHDOG(ieee);
1691                 }
1692         }
1693 
1694 }
1695 #endif
1696 
1697 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1698                 struct ieee80211_info_element *info_element,
1699                 u16 length,
1700                 struct ieee80211_network *network,
1701                 struct ieee80211_rx_stats *stats)
1702 {
1703         u8 i;
1704         short offset;
1705         u16     tmp_htcap_len=0;
1706         u16     tmp_htinfo_len=0;
1707         u16 ht_realtek_agg_len=0;
1708         u8  ht_realtek_agg_buf[MAX_IE_LEN];
1709 //      u16 broadcom_len = 0;
1710 #ifdef CONFIG_IEEE80211_DEBUG
1711         char rates_str[64];
1712         char *p;
1713 #endif
1714 
1715         while (length >= sizeof(*info_element)) {
1716                 if (sizeof(*info_element) + info_element->len > length) {
1717                         IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1718                                              "info_element->len + 2 > left : "
1719                                              "info_element->len+2=%zd left=%d, id=%d.\n",
1720                                              info_element->len +
1721                                              sizeof(*info_element),
1722                                              length, info_element->id);
1723                         /* We stop processing but don't return an error here
1724                          * because some misbehaviour APs break this rule. ie.
1725                          * Orinoco AP1000. */
1726                         break;
1727                 }
1728 
1729                 switch (info_element->id) {
1730                 case MFIE_TYPE_SSID:
1731                         if (ieee80211_is_empty_essid(info_element->data,
1732                                                      info_element->len)) {
1733                                 network->flags |= NETWORK_EMPTY_ESSID;
1734                                 break;
1735                         }
1736 
1737                         network->ssid_len = min(info_element->len,
1738                                                 (u8) IW_ESSID_MAX_SIZE);
1739                         memcpy(network->ssid, info_element->data, network->ssid_len);
1740                         if (network->ssid_len < IW_ESSID_MAX_SIZE)
1741                                 memset(network->ssid + network->ssid_len, 0,
1742                                        IW_ESSID_MAX_SIZE - network->ssid_len);
1743 
1744                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1745                                              network->ssid, network->ssid_len);
1746                         break;
1747 
1748                 case MFIE_TYPE_RATES:
1749 #ifdef CONFIG_IEEE80211_DEBUG
1750                         p = rates_str;
1751 #endif
1752                         network->rates_len = min(info_element->len,
1753                                                  MAX_RATES_LENGTH);
1754                         for (i = 0; i < network->rates_len; i++) {
1755                                 network->rates[i] = info_element->data[i];
1756 #ifdef CONFIG_IEEE80211_DEBUG
1757                                 p += snprintf(p, sizeof(rates_str) -
1758                                               (p - rates_str), "%02X ",
1759                                               network->rates[i]);
1760 #endif
1761                                 if (ieee80211_is_ofdm_rate
1762                                     (info_element->data[i])) {
1763                                         network->flags |= NETWORK_HAS_OFDM;
1764                                         if (info_element->data[i] &
1765                                             IEEE80211_BASIC_RATE_MASK)
1766                                                 network->flags &=
1767                                                     ~NETWORK_HAS_CCK;
1768                                 }
1769                         }
1770 
1771                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1772                                              rates_str, network->rates_len);
1773                         break;
1774 
1775                 case MFIE_TYPE_RATES_EX:
1776 #ifdef CONFIG_IEEE80211_DEBUG
1777                         p = rates_str;
1778 #endif
1779                         network->rates_ex_len = min(info_element->len,
1780                                                     MAX_RATES_EX_LENGTH);
1781                         for (i = 0; i < network->rates_ex_len; i++) {
1782                                 network->rates_ex[i] = info_element->data[i];
1783 #ifdef CONFIG_IEEE80211_DEBUG
1784                                 p += snprintf(p, sizeof(rates_str) -
1785                                               (p - rates_str), "%02X ",
1786                                               network->rates[i]);
1787 #endif
1788                                 if (ieee80211_is_ofdm_rate
1789                                     (info_element->data[i])) {
1790                                         network->flags |= NETWORK_HAS_OFDM;
1791                                         if (info_element->data[i] &
1792                                             IEEE80211_BASIC_RATE_MASK)
1793                                                 network->flags &=
1794                                                     ~NETWORK_HAS_CCK;
1795                                 }
1796                         }
1797 
1798                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1799                                              rates_str, network->rates_ex_len);
1800                         break;
1801 
1802                 case MFIE_TYPE_DS_SET:
1803                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1804                                              info_element->data[0]);
1805                         network->channel = info_element->data[0];
1806                         break;
1807 
1808                 case MFIE_TYPE_FH_SET:
1809                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1810                         break;
1811 
1812                 case MFIE_TYPE_CF_SET:
1813                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1814                         break;
1815 
1816                 case MFIE_TYPE_TIM:
1817                         if(info_element->len < 4)
1818                                 break;
1819 
1820                         network->tim.tim_count = info_element->data[0];
1821                         network->tim.tim_period = info_element->data[1];
1822 
1823                         network->dtim_period = info_element->data[1];
1824                         if(ieee->state != IEEE80211_LINKED)
1825                                 break;
1826 #if 0
1827                         network->last_dtim_sta_time[0] = stats->mac_time[0];
1828 #else
1829                         //we use jiffies for legacy Power save
1830                         network->last_dtim_sta_time[0] = jiffies;
1831 #endif
1832                         network->last_dtim_sta_time[1] = stats->mac_time[1];
1833 
1834                         network->dtim_data = IEEE80211_DTIM_VALID;
1835 
1836                         if(info_element->data[0] != 0)
1837                                 break;
1838 
1839                         if(info_element->data[2] & 1)
1840                                 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1841 
1842                         offset = (info_element->data[2] >> 1)*2;
1843 
1844                         //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1845 
1846                         if(ieee->assoc_id < 8*offset ||
1847                                 ieee->assoc_id > 8*(offset + info_element->len -3))
1848 
1849                                 break;
1850 
1851                         offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1852 
1853                         if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1854                                 network->dtim_data |= IEEE80211_DTIM_UCAST;
1855 
1856                         //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1857                         break;
1858 
1859                 case MFIE_TYPE_ERP:
1860                         network->erp_value = info_element->data[0];
1861                         network->flags |= NETWORK_HAS_ERP_VALUE;
1862                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1863                                              network->erp_value);
1864                         break;
1865                 case MFIE_TYPE_IBSS_SET:
1866                         network->atim_window = info_element->data[0];
1867                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1868                                              network->atim_window);
1869                         break;
1870 
1871                 case MFIE_TYPE_CHALLENGE:
1872                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1873                         break;
1874 
1875                 case MFIE_TYPE_GENERIC:
1876                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1877                                              info_element->len);
1878                         if (!ieee80211_parse_qos_info_param_IE(info_element,
1879                                                                network))
1880                                 break;
1881 
1882                         if (info_element->len >= 4 &&
1883                             info_element->data[0] == 0x00 &&
1884                             info_element->data[1] == 0x50 &&
1885                             info_element->data[2] == 0xf2 &&
1886                             info_element->data[3] == 0x01) {
1887                                 network->wpa_ie_len = min(info_element->len + 2,
1888                                                           MAX_WPA_IE_LEN);
1889                                 memcpy(network->wpa_ie, info_element,
1890                                        network->wpa_ie_len);
1891                                 break;
1892                         }
1893 
1894 #ifdef THOMAS_TURBO
1895                         if (info_element->len == 7 &&
1896                             info_element->data[0] == 0x00 &&
1897                             info_element->data[1] == 0xe0 &&
1898                             info_element->data[2] == 0x4c &&
1899                             info_element->data[3] == 0x01 &&
1900                             info_element->data[4] == 0x02) {
1901                                 network->Turbo_Enable = 1;
1902                         }
1903 #endif
1904 
1905                         //for HTcap and HTinfo parameters
1906                         if(tmp_htcap_len == 0){
1907                                 if(info_element->len >= 4 &&
1908                                    info_element->data[0] == 0x00 &&
1909                                    info_element->data[1] == 0x90 &&
1910                                    info_element->data[2] == 0x4c &&
1911                                    info_element->data[3] == 0x033){
1912 
1913                                                 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1914                                                 if(tmp_htcap_len != 0){
1915                                                         network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1916                                                         network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1917                                                                 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1918                                                         memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1919                                                 }
1920                                 }
1921                                 if(tmp_htcap_len != 0){
1922                                         network->bssht.bdSupportHT = true;
1923                                         network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1924                                 }else{
1925                                         network->bssht.bdSupportHT = false;
1926                                         network->bssht.bdHT1R = false;
1927                                 }
1928                         }
1929 
1930 
1931                         if(tmp_htinfo_len == 0){
1932                                 if(info_element->len >= 4 &&
1933                                         info_element->data[0] == 0x00 &&
1934                                         info_element->data[1] == 0x90 &&
1935                                         info_element->data[2] == 0x4c &&
1936                                         info_element->data[3] == 0x034){
1937 
1938                                                 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1939                                                 if(tmp_htinfo_len != 0){
1940                                                         network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1941                                                         if(tmp_htinfo_len){
1942                                                                 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
1943                                                                         sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
1944                                                                 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
1945                                                         }
1946 
1947                                                 }
1948 
1949                                 }
1950                         }
1951 
1952                         if(ieee->aggregation){
1953                                 if(network->bssht.bdSupportHT){
1954                                         if(info_element->len >= 4 &&
1955                                                 info_element->data[0] == 0x00 &&
1956                                                 info_element->data[1] == 0xe0 &&
1957                                                 info_element->data[2] == 0x4c &&
1958                                                 info_element->data[3] == 0x02){
1959 
1960                                                 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
1961                                                 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
1962 
1963                                         }
1964                                         if(ht_realtek_agg_len >= 5){
1965                                                 network->realtek_cap_exit = true;
1966                                                 network->bssht.bdRT2RTAggregation = true;
1967 
1968                                                 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1969                                                 network->bssht.bdRT2RTLongSlotTime = true;
1970 
1971                                                 if((ht_realtek_agg_buf[4]==1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
1972                                                 {
1973                                                         network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
1974                                                         //bssDesc->Vender = HT_IOT_PEER_REALTEK_92SE;
1975                                                 }
1976                                         }
1977                                 }
1978 
1979                         }
1980 
1981                         //if(tmp_htcap_len !=0  ||  tmp_htinfo_len != 0)
1982                         {
1983                                 if((info_element->len >= 3 &&
1984                                          info_element->data[0] == 0x00 &&
1985                                          info_element->data[1] == 0x05 &&
1986                                          info_element->data[2] == 0xb5) ||
1987                                          (info_element->len >= 3 &&
1988                                          info_element->data[0] == 0x00 &&
1989                                          info_element->data[1] == 0x0a &&
1990                                          info_element->data[2] == 0xf7) ||
1991                                          (info_element->len >= 3 &&
1992                                          info_element->data[0] == 0x00 &&
1993                                          info_element->data[1] == 0x10 &&
1994                                          info_element->data[2] == 0x18)){
1995 
1996                                                 network->broadcom_cap_exist = true;
1997 
1998                                 }
1999                         }
2000 #if 0
2001                         if (tmp_htcap_len !=0)
2002                                 {
2003                                         u16 cap_ext = ((PHT_CAPABILITY_ELE)&info_element->data[0])->ExtHTCapInfo;
2004                                         if ((cap_ext & 0x0c00) == 0x0c00)
2005                                                 {
2006                                                         network->ralink_cap_exist = true;
2007                                                 }
2008                                 }
2009 #endif
2010                         if(info_element->len >= 3 &&
2011                                 info_element->data[0] == 0x00 &&
2012                                 info_element->data[1] == 0x0c &&
2013                                 info_element->data[2] == 0x43)
2014                         {
2015                                 network->ralink_cap_exist = true;
2016                         }
2017                         else
2018                                 network->ralink_cap_exist = false;
2019                         //added by amy for atheros AP
2020                         if((info_element->len >= 3 &&
2021                                 info_element->data[0] == 0x00 &&
2022                                 info_element->data[1] == 0x03 &&
2023                                 info_element->data[2] == 0x7f) ||
2024                                 (info_element->len >= 3 &&
2025                                 info_element->data[0] == 0x00 &&
2026                                 info_element->data[1] == 0x13 &&
2027                                 info_element->data[2] == 0x74))
2028                         {
2029                         //      printk("========>%s(): athros AP is exist\n",__FUNCTION__);
2030                                 network->atheros_cap_exist = true;
2031                         }
2032                         else
2033                                 network->atheros_cap_exist = false;
2034 
2035                         if ((info_element->len >= 3 &&
2036                                 info_element->data[0] == 0x00 &&
2037                                 info_element->data[1] == 0x50 &&
2038                                 info_element->data[2] == 0x43) )
2039                                 {
2040                                         network->marvell_cap_exist = true;
2041                                 }
2042                         else
2043                                 network->marvell_cap_exist = false;
2044 
2045                         if(info_element->len >= 3 &&
2046                                 info_element->data[0] == 0x00 &&
2047                                 info_element->data[1] == 0x40 &&
2048                                 info_element->data[2] == 0x96)
2049                         {
2050                                 network->cisco_cap_exist = true;
2051                         }
2052                         else
2053                                 network->cisco_cap_exist = false;
2054                         //added by amy for LEAP of cisco
2055                         if(info_element->len > 4 &&
2056                                 info_element->data[0] == 0x00 &&
2057                                 info_element->data[1] == 0x40 &&
2058                                 info_element->data[2] == 0x96 &&
2059                                 info_element->data[3] == 0x01)
2060                         {
2061                                 if(info_element->len == 6)
2062                                 {
2063                                         memcpy(network->CcxRmState, &info_element[4], 2);
2064                                         if(network->CcxRmState[0] != 0)
2065                                         {
2066                                                 network->bCcxRmEnable = true;
2067                                         }
2068                                         else
2069                                                 network->bCcxRmEnable = false;
2070                                         //
2071                                         // CCXv4 Table 59-1 MBSSID Masks.
2072                                         //
2073                                         network->MBssidMask = network->CcxRmState[1] & 0x07;
2074                                         if(network->MBssidMask != 0)
2075                                         {
2076                                                 network->bMBssidValid = true;
2077                                                 network->MBssidMask = 0xff << (network->MBssidMask);
2078                                                 cpMacAddr(network->MBssid, network->bssid);
2079                                                 network->MBssid[5] &= network->MBssidMask;
2080                                         }
2081                                         else
2082                                         {
2083                                                 network->bMBssidValid = false;
2084                                         }
2085                                 }
2086                                 else
2087                                 {
2088                                         network->bCcxRmEnable = false;
2089                                 }
2090                         }
2091                         if(info_element->len > 4  &&
2092                                 info_element->data[0] == 0x00 &&
2093                                 info_element->data[1] == 0x40 &&
2094                                 info_element->data[2] == 0x96 &&
2095                                 info_element->data[3] == 0x03)
2096                         {
2097                                 if(info_element->len == 5)
2098                                 {
2099                                         network->bWithCcxVerNum = true;
2100                                         network->BssCcxVerNumber = info_element->data[4];
2101                                 }
2102                                 else
2103                                 {
2104                                         network->bWithCcxVerNum = false;
2105                                         network->BssCcxVerNumber = 0;
2106                                 }
2107                         }
2108                         break;
2109 
2110                 case MFIE_TYPE_RSN:
2111                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2112                                              info_element->len);
2113                         network->rsn_ie_len = min(info_element->len + 2,
2114                                                   MAX_WPA_IE_LEN);
2115                         memcpy(network->rsn_ie, info_element,
2116                                network->rsn_ie_len);
2117                         break;
2118 
2119                         //HT related element.
2120                 case MFIE_TYPE_HT_CAP:
2121                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2122                                              info_element->len);
2123                         tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2124                         if(tmp_htcap_len != 0){
2125                                 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2126                                 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2127                                         sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2128                                 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2129 
2130                                 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2131                                 // windows driver will update WMM parameters each beacon received once connected
2132                                 // Linux driver is a bit different.
2133                                 network->bssht.bdSupportHT = true;
2134                                 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
2135                         }
2136                         else{
2137                                 network->bssht.bdSupportHT = false;
2138                                 network->bssht.bdHT1R = false;
2139                         }
2140                         break;
2141 
2142 
2143                 case MFIE_TYPE_HT_INFO:
2144                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2145                                              info_element->len);
2146                         tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2147                         if(tmp_htinfo_len){
2148                                 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2149                                 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2150                                         sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2151                                 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2152                         }
2153                         break;
2154 
2155                 case MFIE_TYPE_AIRONET:
2156                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2157                                              info_element->len);
2158                         if(info_element->len >IE_CISCO_FLAG_POSITION)
2159                         {
2160                                 network->bWithAironetIE = true;
2161 
2162                                 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2163                                 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2164                                 //  by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2165                                 if(     (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC)   ||
2166                                         (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK)    )
2167                                 {
2168                                         network->bCkipSupported = true;
2169                                 }
2170                                 else
2171                                 {
2172                                         network->bCkipSupported = false;
2173                                 }
2174                         }
2175                         else
2176                         {
2177                                 network->bWithAironetIE = false;
2178                                 network->bCkipSupported = false;
2179                         }
2180                         break;
2181                 case MFIE_TYPE_QOS_PARAMETER:
2182                         printk(KERN_ERR
2183                                "QoS Error need to parse QOS_PARAMETER IE\n");
2184                         break;
2185 
2186 #ifdef ENABLE_DOT11D
2187                 case MFIE_TYPE_COUNTRY:
2188                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2189                                              info_element->len);
2190                         //printk("=====>Receive <%s> Country IE\n",network->ssid);
2191                         ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2192                         break;
2193 #endif
2194 /* TODO */
2195 #if 0
2196                         /* 802.11h */
2197                 case MFIE_TYPE_POWER_CONSTRAINT:
2198                         network->power_constraint = info_element->data[0];
2199                         network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
2200                         break;
2201 
2202                 case MFIE_TYPE_CSA:
2203                         network->power_constraint = info_element->data[0];
2204                         network->flags |= NETWORK_HAS_CSA;
2205                         break;
2206 
2207                 case MFIE_TYPE_QUIET:
2208                         network->quiet.count = info_element->data[0];
2209                         network->quiet.period = info_element->data[1];
2210                         network->quiet.duration = info_element->data[2];
2211                         network->quiet.offset = info_element->data[3];
2212                         network->flags |= NETWORK_HAS_QUIET;
2213                         break;
2214 
2215                 case MFIE_TYPE_IBSS_DFS:
2216                         if (network->ibss_dfs)
2217                                 break;
2218                         network->ibss_dfs = kmemdup(info_element->data,
2219                                                     info_element->len,
2220                                                     GFP_ATOMIC);
2221                         if (!network->ibss_dfs)
2222                                 return 1;
2223                         network->flags |= NETWORK_HAS_IBSS_DFS;
2224                         break;
2225 
2226                 case MFIE_TYPE_TPC_REPORT:
2227                         network->tpc_report.transmit_power =
2228                             info_element->data[0];
2229                         network->tpc_report.link_margin = info_element->data[1];
2230                         network->flags |= NETWORK_HAS_TPC_REPORT;
2231                         break;
2232 #endif
2233                 default:
2234                         IEEE80211_DEBUG_MGMT
2235                             ("Unsupported info element: %s (%d)\n",
2236                              get_info_element_string(info_element->id),
2237                              info_element->id);
2238                         break;
2239                 }
2240 
2241                 length -= sizeof(*info_element) + info_element->len;
2242                 info_element =
2243                     (struct ieee80211_info_element *)&info_element->
2244                     data[info_element->len];
2245         }
2246 
2247         if(!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2248                 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation)
2249         {
2250                 network->unknown_cap_exist = true;
2251         }
2252         else
2253         {
2254                 network->unknown_cap_exist = false;
2255         }
2256         return 0;
2257 }
2258 
2259 static inline u8 ieee80211_SignalStrengthTranslate(
2260         u8  CurrSS
2261         )
2262 {
2263         u8 RetSS;
2264 
2265         // Step 1. Scale mapping.
2266         if(CurrSS >= 71 && CurrSS <= 100)
2267         {
2268                 RetSS = 90 + ((CurrSS - 70) / 3);
2269         }
2270         else if(CurrSS >= 41 && CurrSS <= 70)
2271         {
2272                 RetSS = 78 + ((CurrSS - 40) / 3);
2273         }
2274         else if(CurrSS >= 31 && CurrSS <= 40)
2275         {
2276                 RetSS = 66 + (CurrSS - 30);
2277         }
2278         else if(CurrSS >= 21 && CurrSS <= 30)
2279         {
2280                 RetSS = 54 + (CurrSS - 20);
2281         }
2282         else if(CurrSS >= 5 && CurrSS <= 20)
2283         {
2284                 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2285         }
2286         else if(CurrSS == 4)
2287         {
2288                 RetSS = 36;
2289         }
2290         else if(CurrSS == 3)
2291         {
2292                 RetSS = 27;
2293         }
2294         else if(CurrSS == 2)
2295         {
2296                 RetSS = 18;
2297         }
2298         else if(CurrSS == 1)
2299         {
2300                 RetSS = 9;
2301         }
2302         else
2303         {
2304                 RetSS = CurrSS;
2305         }
2306         //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping:  LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2307 
2308         // Step 2. Smoothing.
2309 
2310         //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing:  LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2311 
2312         return RetSS;
2313 }
2314 
2315 long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index.
2316 {
2317         long    signal_power; // in dBm.
2318 
2319         // Translate to dBm (x=0.5y-95).
2320         signal_power = (long)((signal_strength_index + 1) >> 1);
2321         signal_power -= 95;
2322 
2323         return signal_power;
2324 }
2325 
2326 static inline int ieee80211_network_init(
2327         struct ieee80211_device *ieee,
2328         struct ieee80211_probe_response *beacon,
2329         struct ieee80211_network *network,
2330         struct ieee80211_rx_stats *stats)
2331 {
2332 #ifdef CONFIG_IEEE80211_DEBUG
2333         //char rates_str[64];
2334         //char *p;
2335 #endif
2336 
2337         network->qos_data.active = 0;
2338         network->qos_data.supported = 0;
2339         network->qos_data.param_count = 0;
2340         network->qos_data.old_param_count = 0;
2341 
2342         /* Pull out fixed field data */
2343         memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2344         network->capability = le16_to_cpu(beacon->capability);
2345         network->last_scanned = jiffies;
2346         network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2347         network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2348         network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2349         /* Where to pull this? beacon->listen_interval;*/
2350         network->listen_interval = 0x0A;
2351         network->rates_len = network->rates_ex_len = 0;
2352         network->last_associate = 0;
2353         network->ssid_len = 0;
2354         network->flags = 0;
2355         network->atim_window = 0;
2356         network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2357             0x3 : 0x0;
2358         network->berp_info_valid = false;
2359         network->broadcom_cap_exist = false;
2360         network->ralink_cap_exist = false;
2361         network->atheros_cap_exist = false;
2362         network->cisco_cap_exist = false;
2363         network->unknown_cap_exist = false;
2364         network->realtek_cap_exit = false;
2365         network->marvell_cap_exist = false;
2366 #ifdef THOMAS_TURBO
2367         network->Turbo_Enable = 0;
2368 #endif
2369 #ifdef ENABLE_DOT11D
2370         network->CountryIeLen = 0;
2371         memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2372 #endif
2373 //Initialize HT parameters
2374         //ieee80211_ht_initialize(&network->bssht);
2375         HTInitializeBssDesc(&network->bssht);
2376         if (stats->freq == IEEE80211_52GHZ_BAND) {
2377                 /* for A band (No DS info) */
2378                 network->channel = stats->received_channel;
2379         } else
2380                 network->flags |= NETWORK_HAS_CCK;
2381 
2382         network->wpa_ie_len = 0;
2383         network->rsn_ie_len = 0;
2384 
2385         if (ieee80211_parse_info_param
2386             (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2387                 return 1;
2388 
2389         network->mode = 0;
2390         if (stats->freq == IEEE80211_52GHZ_BAND)
2391                 network->mode = IEEE_A;
2392         else {
2393                 if (network->flags & NETWORK_HAS_OFDM)
2394                         network->mode |= IEEE_G;
2395                 if (network->flags & NETWORK_HAS_CCK)
2396                         network->mode |= IEEE_B;
2397         }
2398 
2399         if (network->mode == 0) {
2400                 IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
2401                                      "network.\n",
2402                                      escape_essid(network->ssid,
2403                                                   network->ssid_len),
2404                                      MAC_ARG(network->bssid));
2405                 return 1;
2406         }
2407 
2408         if(network->bssht.bdSupportHT){
2409                 if(network->mode == IEEE_A)
2410                         network->mode = IEEE_N_5G;
2411                 else if(network->mode & (IEEE_G | IEEE_B))
2412                         network->mode = IEEE_N_24G;
2413         }
2414         if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2415                 network->flags |= NETWORK_EMPTY_ESSID;
2416 
2417 #if 1
2418         stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2419         //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2420         stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25;
2421 #endif
2422 
2423         memcpy(&network->stats, stats, sizeof(network->stats));
2424 
2425         return 0;
2426 }
2427 
2428 static inline int is_same_network(struct ieee80211_network *src,
2429                                   struct ieee80211_network *dst, struct ieee80211_device* ieee)
2430 {
2431         /* A network is only a duplicate if the channel, BSSID, ESSID
2432          * and the capability field (in particular IBSS and BSS) all match.
2433          * We treat all <hidden> with the same BSSID and channel
2434          * as one network */
2435         return //((src->ssid_len == dst->ssid_len) &&
2436                 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2437                 (src->channel == dst->channel) &&
2438                 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2439                 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2440                 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2441                 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2442                 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2443                 ((src->capability & WLAN_CAPABILITY_BSS) ==
2444                 (dst->capability & WLAN_CAPABILITY_BSS)));
2445 }
2446 
2447 static inline void update_network(struct ieee80211_network *dst,
2448                                   struct ieee80211_network *src)
2449 {
2450         int qos_active;
2451         u8 old_param;
2452 
2453         memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2454         dst->capability = src->capability;
2455         memcpy(dst->rates, src->rates, src->rates_len);
2456         dst->rates_len = src->rates_len;
2457         memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2458         dst->rates_ex_len = src->rates_ex_len;
2459         if(src->ssid_len > 0)
2460         {
2461                 memset(dst->ssid, 0, dst->ssid_len);
2462                 dst->ssid_len = src->ssid_len;
2463                 memcpy(dst->ssid, src->ssid, src->ssid_len);
2464         }
2465         dst->mode = src->mode;
2466         dst->flags = src->flags;
2467         dst->time_stamp[0] = src->time_stamp[0];
2468         dst->time_stamp[1] = src->time_stamp[1];
2469         if (src->flags & NETWORK_HAS_ERP_VALUE)
2470         {
2471                 dst->erp_value = src->erp_value;
2472                 dst->berp_info_valid = src->berp_info_valid = true;
2473         }
2474         dst->beacon_interval = src->beacon_interval;
2475         dst->listen_interval = src->listen_interval;
2476         dst->atim_window = src->atim_window;
2477         dst->dtim_period = src->dtim_period;
2478         dst->dtim_data = src->dtim_data;
2479         dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2480         dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2481         memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2482 
2483         dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2484         dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2485         dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2486         memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
2487         dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
2488         memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
2489         dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2490         dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2491         dst->broadcom_cap_exist = src->broadcom_cap_exist;
2492         dst->ralink_cap_exist = src->ralink_cap_exist;
2493         dst->atheros_cap_exist = src->atheros_cap_exist;
2494         dst->realtek_cap_exit = src->realtek_cap_exit;
2495         dst->marvell_cap_exist = src->marvell_cap_exist;
2496         dst->cisco_cap_exist = src->cisco_cap_exist;
2497         dst->unknown_cap_exist = src->unknown_cap_exist;
2498         memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2499         dst->wpa_ie_len = src->wpa_ie_len;
2500         memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2501         dst->rsn_ie_len = src->rsn_ie_len;
2502 
2503         dst->last_scanned = jiffies;
2504         /* qos related parameters */
2505         //qos_active = src->qos_data.active;
2506         qos_active = dst->qos_data.active;
2507         //old_param = dst->qos_data.old_param_count;
2508         old_param = dst->qos_data.param_count;
2509         if(dst->flags & NETWORK_HAS_QOS_MASK){
2510         //not update QOS paramter in beacon, as most AP will set all these parameter to 0.//WB
2511         //      printk("====>%s(), aifs:%x, %x\n", __FUNCTION__, dst->qos_data.parameters.aifs[0], src->qos_data.parameters.aifs[0]);
2512         //      memcpy(&dst->qos_data, &src->qos_data,
2513         //              sizeof(struct ieee80211_qos_data));
2514         }
2515         else {
2516                 dst->qos_data.supported = src->qos_data.supported;
2517                 dst->qos_data.param_count = src->qos_data.param_count;
2518         }
2519 
2520         if(dst->qos_data.supported == 1) {
2521                 dst->QoS_Enable = 1;
2522                 if(dst->ssid_len)
2523                         IEEE80211_DEBUG_QOS
2524                                 ("QoS the network %s is QoS supported\n",
2525                                 dst->ssid);
2526                 else
2527                         IEEE80211_DEBUG_QOS
2528                                 ("QoS the network is QoS supported\n");
2529         }
2530         dst->qos_data.active = qos_active;
2531         dst->qos_data.old_param_count = old_param;
2532 
2533         /* dst->last_associate is not overwritten */
2534 #if 1
2535         dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2536         if(src->wmm_param[0].ac_aci_acm_aifsn|| \
2537            src->wmm_param[1].ac_aci_acm_aifsn|| \
2538            src->wmm_param[2].ac_aci_acm_aifsn|| \
2539            src->wmm_param[1].ac_aci_acm_aifsn) {
2540           memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2541         }
2542         //dst->QoS_Enable = src->QoS_Enable;
2543 #else
2544         dst->QoS_Enable = 1;//for Rtl8187 simulation
2545 #endif
2546 #ifdef THOMAS_TURBO
2547         dst->Turbo_Enable = src->Turbo_Enable;
2548 #endif
2549 
2550 #ifdef ENABLE_DOT11D
2551         dst->CountryIeLen = src->CountryIeLen;
2552         memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2553 #endif
2554 
2555         //added by amy for LEAP
2556         dst->bWithAironetIE = src->bWithAironetIE;
2557         dst->bCkipSupported = src->bCkipSupported;
2558         memcpy(dst->CcxRmState,src->CcxRmState,2);
2559         dst->bCcxRmEnable = src->bCcxRmEnable;
2560         dst->MBssidMask = src->MBssidMask;
2561         dst->bMBssidValid = src->bMBssidValid;
2562         memcpy(dst->MBssid,src->MBssid,6);
2563         dst->bWithCcxVerNum = src->bWithCcxVerNum;
2564         dst->BssCcxVerNumber = src->BssCcxVerNumber;
2565 
2566 }
2567 
2568 static inline int is_beacon(__le16 fc)
2569 {
2570         return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2571 }
2572 
2573 static inline void ieee80211_process_probe_response(
2574         struct ieee80211_device *ieee,
2575         struct ieee80211_probe_response *beacon,
2576         struct ieee80211_rx_stats *stats)
2577 {
2578         struct ieee80211_network network;
2579         struct ieee80211_network *target;
2580         struct ieee80211_network *oldest = NULL;
2581 #ifdef CONFIG_IEEE80211_DEBUG
2582         struct ieee80211_info_element *info_element = &beacon->info_element[0];
2583 #endif
2584         unsigned long flags;
2585         short renew;
2586         //u8 wmm_info;
2587 
2588         memset(&network, 0, sizeof(struct ieee80211_network));
2589         IEEE80211_DEBUG_SCAN(
2590                 "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2591                 escape_essid(info_element->data, info_element->len),
2592                 MAC_ARG(beacon->header.addr3),
2593                 (beacon->capability & (1<<0xf)) ? '1' : '',
2594                 (beacon->capability & (1<<0xe)) ? '1' : '',
2595                 (beacon->capability & (1<<0xd)) ? '1' : '',
2596                 (beacon->capability & (1<<0xc)) ? '1' : '',
2597                 (beacon->capability & (1<<0xb)) ? '1' : '',
2598                 (beacon->capability & (1<<0xa)) ? '1' : '',
2599                 (beacon->capability & (1<<0x9)) ? '1' : '',
2600                 (beacon->capability & (1<<0x8)) ? '1' : '',
2601                 (beacon->capability & (1<<0x7)) ? '1' : '',
2602                 (beacon->capability & (1<<0x6)) ? '1' : '',
2603                 (beacon->capability & (1<<0x5)) ? '1' : '',
2604                 (beacon->capability & (1<<0x4)) ? '1' : '',
2605                 (beacon->capability & (1<<0x3)) ? '1' : '',
2606                 (beacon->capability & (1<<0x2)) ? '1' : '',
2607                 (beacon->capability & (1<<0x1)) ? '1' : '',
2608                 (beacon->capability & (1<<0x0)) ? '1' : '');
2609 
2610         if (ieee80211_network_init(ieee, beacon, &network, stats)) {
2611                 IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
2612                                      escape_essid(info_element->data,
2613                                                   info_element->len),
2614                                      MAC_ARG(beacon->header.addr3),
2615                                      WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2616                                      IEEE80211_STYPE_PROBE_RESP ?
2617                                      "PROBE RESPONSE" : "BEACON");
2618                 return;
2619         }
2620 
2621 #ifdef ENABLE_DOT11D
2622         // For Asus EeePc request,
2623         // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2624         //         wireless adapter should follow the country code.
2625         // (2)  If there is no any country code in beacon,
2626         //       then wireless adapter should do active scan from ch1~11 and
2627         //       passive scan from ch12~14
2628 
2629         if( !IsLegalChannel(ieee, network.channel) )
2630                 return;
2631         if(ieee->bGlobalDomain)
2632         {
2633                 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP)
2634                 {
2635                         // Case 1: Country code
2636                         if(IS_COUNTRY_IE_VALID(ieee) )
2637                         {
2638                                 if( !IsLegalChannel(ieee, network.channel) )
2639                                 {
2640                                         printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2641                                         return;
2642                                 }
2643                         }
2644                         // Case 2: No any country code.
2645                         else
2646                         {
2647                                 // Filter over channel ch12~14
2648                                 if(network.channel > 11)
2649                                 {
2650                                         printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
2651                                         return;
2652                                 }
2653                         }
2654                 }
2655                 else
2656                 {
2657                         // Case 1: Country code
2658                         if(IS_COUNTRY_IE_VALID(ieee) )
2659                         {
2660                                 if( !IsLegalChannel(ieee, network.channel) )
2661                                 {
2662                                         printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2663                                         return;
2664                                 }
2665                         }
2666                         // Case 2: No any country code.
2667                         else
2668                         {
2669                                 // Filter over channel ch12~14
2670                                 if(network.channel > 14)
2671                                 {
2672                                         printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel);
2673                                         return;
2674                                 }
2675                         }
2676                 }
2677         }
2678 #endif
2679 
2680         /* The network parsed correctly -- so now we scan our known networks
2681          * to see if we can find it in our list.
2682          *
2683          * NOTE:  This search is definitely not optimized.  Once its doing
2684          *        the "right thing" we'll optimize it for efficiency if
2685          *        necessary */
2686 
2687         /* Search for this entry in the list and update it if it is
2688          * already there. */
2689 
2690         spin_lock_irqsave(&ieee->lock, flags);
2691 
2692         if(is_same_network(&ieee->current_network, &network, ieee)) {
2693                 update_network(&ieee->current_network, &network);
2694                 if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2695                 && ieee->current_network.berp_info_valid){
2696                 if(ieee->current_network.erp_value& ERP_UseProtection)
2697                         ieee->current_network.buseprotection = true;
2698                 else
2699                         ieee->current_network.buseprotection = false;
2700                 }
2701                 if(is_beacon(beacon->header.frame_ctl))
2702                 {
2703                         if(ieee->state == IEEE80211_LINKED)
2704                                 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2705                 }
2706                 else //hidden AP
2707                         network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2708         }
2709 
2710         list_for_each_entry(target, &ieee->network_list, list) {
2711                 if (is_same_network(target, &network, ieee))
2712                         break;
2713                 if ((oldest == NULL) ||
2714                     (target->last_scanned < oldest->last_scanned))
2715                         oldest = target;
2716         }
2717 
2718         /* If we didn't find a match, then get a new network slot to initialize
2719          * with this beacon's information */
2720         if (&target->list == &ieee->network_list) {
2721                 if (list_empty(&ieee->network_free_list)) {
2722                         /* If there are no more slots, expire the oldest */
2723                         list_del(&oldest->list);
2724                         target = oldest;
2725                         IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
2726                                              "network list.\n",
2727                                              escape_essid(target->ssid,
2728                                                           target->ssid_len),
2729                                              MAC_ARG(target->bssid));
2730                 } else {
2731                         /* Otherwise just pull from the free list */
2732                         target = list_entry(ieee->network_free_list.next,
2733                                             struct ieee80211_network, list);
2734                         list_del(ieee->network_free_list.next);
2735                 }
2736 
2737 
2738 #ifdef CONFIG_IEEE80211_DEBUG
2739                 IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
2740                                      escape_essid(network.ssid,
2741                                                   network.ssid_len),
2742                                      MAC_ARG(network.bssid),
2743                                      WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2744                                      IEEE80211_STYPE_PROBE_RESP ?
2745                                      "PROBE RESPONSE" : "BEACON");
2746 #endif
2747                 memcpy(target, &network, sizeof(*target));
2748                 list_add_tail(&target->list, &ieee->network_list);
2749                 if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2750                         ieee80211_softmac_new_net(ieee,&network);
2751         } else {
2752                 IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
2753                                      escape_essid(target->ssid,
2754                                                   target->ssid_len),
2755                                      MAC_ARG(target->bssid),
2756                                      WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2757                                      IEEE80211_STYPE_PROBE_RESP ?
2758                                      "PROBE RESPONSE" : "BEACON");
2759 
2760                 /* we have an entry and we are going to update it. But this entry may
2761                  * be already expired. In this case we do the same as we found a new
2762                  * net and call the new_net handler
2763                  */
2764                 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2765                 //YJ,add,080819,for hidden ap
2766                 if(is_beacon(beacon->header.frame_ctl) == 0)
2767                         network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
2768                 //if(strncmp(network.ssid, "linksys-c",9) == 0)
2769                 //      printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
2770                 if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2771                     && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
2772                     ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
2773                         renew = 1;
2774                 //YJ,add,080819,for hidden ap,end
2775 
2776                 update_network(target, &network);
2777                 if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2778                         ieee80211_softmac_new_net(ieee,&network);
2779         }
2780 
2781         spin_unlock_irqrestore(&ieee->lock, flags);
2782         if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\
2783                 (ieee->state == IEEE80211_LINKED)) {
2784                 if(ieee->handle_beacon != NULL) {
2785                         ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
2786                 }
2787         }
2788 }
2789 
2790 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2791                       struct ieee80211_hdr_4addr *header,
2792                       struct ieee80211_rx_stats *stats)
2793 {
2794         if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2795                                 ieee->iw_mode == IW_MODE_INFRA &&
2796                                 ieee->state == IEEE80211_LINKED))
2797         {
2798                 tasklet_schedule(&ieee->ps_task);
2799         }
2800 
2801         if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2802                 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2803                 ieee->last_rx_ps_time = jiffies;
2804 
2805         switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2806 
2807         case IEEE80211_STYPE_BEACON:
2808                 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2809                                      WLAN_FC_GET_STYPE(header->frame_ctl));
2810                 IEEE80211_DEBUG_SCAN("Beacon\n");
2811                 ieee80211_process_probe_response(
2812                         ieee, (struct ieee80211_probe_response *)header, stats);
2813                 break;
2814 
2815         case IEEE80211_STYPE_PROBE_RESP:
2816                 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2817                                      WLAN_FC_GET_STYPE(header->frame_ctl));
2818                 IEEE80211_DEBUG_SCAN("Probe response\n");
2819                 ieee80211_process_probe_response(
2820                         ieee, (struct ieee80211_probe_response *)header, stats);
2821                 break;
2822 
2823         }
2824 }
2825 
2826 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2827 EXPORT_SYMBOL(ieee80211_rx_mgt);
2828 EXPORT_SYMBOL(ieee80211_rx);
2829 #else
2830 EXPORT_SYMBOL_NOVERS(ieee80211_rx_mgt);
2831 EXPORT_SYMBOL_NOVERS(ieee80211_rx);
2832 #endif
2833 
  This page was automatically generated by the LXR engine.