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