2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
14 ******************************************************************************
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
19 A special thanks goes to Realtek for their support !
21 ******************************************************************************/
24 #include <linux/compiler.h>
25 #include <linux/errno.h>
26 #include <linux/if_arp.h>
27 #include <linux/in6.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/netdevice.h>
33 #include <linux/pci.h>
34 #include <linux/proc_fs.h>
35 #include <linux/skbuff.h>
36 #include <linux/slab.h>
37 #include <linux/tcp.h>
38 #include <linux/types.h>
39 #include <linux/version.h>
40 #include <linux/wireless.h>
41 #include <linux/etherdevice.h>
42 #include <asm/uaccess.h>
43 #include <linux/ctype.h>
48 static inline void rtllib_monitor_rx(struct rtllib_device
*ieee
,
49 struct sk_buff
*skb
,struct rtllib_rx_stats
*rx_status
,
53 skb_reset_mac_header(skb
);
54 skb_pull(skb
, hdr_length
);
55 skb
->pkt_type
= PACKET_OTHERHOST
;
56 skb
->protocol
= __constant_htons(ETH_P_80211_RAW
);
57 memset(skb
->cb
, 0, sizeof(skb
->cb
));
61 /* Called only as a tasklet (software IRQ) */
62 static struct rtllib_frag_entry
*
63 rtllib_frag_cache_find(struct rtllib_device
*ieee
, unsigned int seq
,
64 unsigned int frag
, u8 tid
,u8
*src
, u8
*dst
)
66 struct rtllib_frag_entry
*entry
;
69 for (i
= 0; i
< RTLLIB_FRAG_CACHE_LEN
; i
++) {
70 entry
= &ieee
->frag_cache
[tid
][i
];
71 if (entry
->skb
!= NULL
&&
72 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
74 "expiring fragment cache entry "
75 "seq=%u last_frag=%u\n",
76 entry
->seq
, entry
->last_frag
);
77 dev_kfree_skb_any(entry
->skb
);
81 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
82 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
83 memcmp(entry
->src_addr
, src
, ETH_ALEN
) == 0 &&
84 memcmp(entry
->dst_addr
, dst
, ETH_ALEN
) == 0)
91 /* Called only as a tasklet (software IRQ) */
92 static struct sk_buff
*
93 rtllib_frag_cache_get(struct rtllib_device
*ieee
,
94 struct rtllib_hdr_4addr
*hdr
)
96 struct sk_buff
*skb
= NULL
;
97 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
98 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
99 unsigned int frag
= WLAN_GET_SEQ_FRAG(sc
);
100 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
101 struct rtllib_frag_entry
*entry
;
102 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
103 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
106 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
)&&RTLLIB_QOS_HAS_SEQ(fc
)) {
107 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)hdr
;
108 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
111 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
112 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)hdr
;
113 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
121 /* Reserve enough space to fit maximum frame length */
122 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
123 sizeof(struct rtllib_hdr_4addr
) +
128 (RTLLIB_QOS_HAS_SEQ(fc
)?2:0) /* QOS Control */);
132 entry
= &ieee
->frag_cache
[tid
][ieee
->frag_next_idx
[tid
]];
133 ieee
->frag_next_idx
[tid
]++;
134 if (ieee
->frag_next_idx
[tid
] >= RTLLIB_FRAG_CACHE_LEN
)
135 ieee
->frag_next_idx
[tid
] = 0;
137 if (entry
->skb
!= NULL
)
138 dev_kfree_skb_any(entry
->skb
);
140 entry
->first_frag_time
= jiffies
;
142 entry
->last_frag
= frag
;
144 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
145 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
147 /* received a fragment of a frame for which the head fragment
148 * should have already been received */
149 entry
= rtllib_frag_cache_find(ieee
, seq
, frag
, tid
,hdr
->addr2
,
152 entry
->last_frag
= frag
;
161 /* Called only as a tasklet (software IRQ) */
162 static int rtllib_frag_cache_invalidate(struct rtllib_device
*ieee
,
163 struct rtllib_hdr_4addr
*hdr
)
165 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
166 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
167 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
168 struct rtllib_frag_entry
*entry
;
169 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
170 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
173 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
)&&RTLLIB_QOS_HAS_SEQ(fc
)) {
174 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)hdr
;
175 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
178 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
179 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)hdr
;
180 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
187 entry
= rtllib_frag_cache_find(ieee
, seq
, -1, tid
,hdr
->addr2
,
192 "could not invalidate fragment cache "
193 "entry (seq=%u)\n", seq
);
203 /* rtllib_rx_frame_mgtmt
205 * Responsible for handling management control frames
207 * Called by rtllib_rx */
209 rtllib_rx_frame_mgmt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
210 struct rtllib_rx_stats
*rx_stats
, u16 type
,
213 /* On the struct stats definition there is written that
214 * this is not mandatory.... but seems that the probe
215 * response parser uses it
217 struct rtllib_hdr_3addr
* hdr
= (struct rtllib_hdr_3addr
*)skb
->data
;
219 rx_stats
->len
= skb
->len
;
220 rtllib_rx_mgt(ieee
,skb
,rx_stats
);
221 if ((memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
))) {
222 dev_kfree_skb_any(skb
);
225 rtllib_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
227 dev_kfree_skb_any(skb
);
232 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
233 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
234 static unsigned char rfc1042_header
[] =
235 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
236 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
237 static unsigned char bridge_tunnel_header
[] =
238 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
239 /* No encapsulation header if EtherType < 0x600 (=length) */
241 /* Called by rtllib_rx_frame_decrypt */
242 static int rtllib_is_eapol_frame(struct rtllib_device
*ieee
,
243 struct sk_buff
*skb
, size_t hdrlen
)
245 struct net_device
*dev
= ieee
->dev
;
247 struct rtllib_hdr_4addr
*hdr
;
253 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
254 fc
= le16_to_cpu(hdr
->frame_ctl
);
256 /* check that the frame is unicast frame to us */
257 if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
259 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
260 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
261 /* ToDS frame with own addr BSSID and DA */
262 } else if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
263 RTLLIB_FCTL_FROMDS
&&
264 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
265 /* FromDS frame with own addr as DA */
269 if (skb
->len
< 24 + 8)
272 /* check for port access entity Ethernet type */
273 pos
= skb
->data
+ hdrlen
;
274 ethertype
= (pos
[6] << 8) | pos
[7];
275 if (ethertype
== ETH_P_PAE
)
281 /* Called only as a tasklet (software IRQ), by rtllib_rx */
283 rtllib_rx_frame_decrypt(struct rtllib_device
* ieee
, struct sk_buff
*skb
,
284 struct rtllib_crypt_data
*crypt
)
286 struct rtllib_hdr_4addr
*hdr
;
289 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
292 if (ieee
->hwsec_active
)
294 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
295 tcb_desc
->bHwSec
= 1;
297 if (ieee
->need_sw_enc
)
298 tcb_desc
->bHwSec
= 0;
301 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
302 hdrlen
= rtllib_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
304 atomic_inc(&crypt
->refcnt
);
305 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
306 atomic_dec(&crypt
->refcnt
);
309 "decryption failed (SA=" MAC_FMT
310 ") res=%d\n", MAC_ARG(hdr
->addr2
), res
);
312 RTLLIB_DEBUG_DROP("Decryption failed ICV "
313 "mismatch (key %d)\n",
314 skb
->data
[hdrlen
+ 3] >> 6);
315 ieee
->ieee_stats
.rx_discards_undecryptable
++;
323 /* Called only as a tasklet (software IRQ), by rtllib_rx */
325 rtllib_rx_frame_decrypt_msdu(struct rtllib_device
* ieee
, struct sk_buff
*skb
,
326 int keyidx
, struct rtllib_crypt_data
*crypt
)
328 struct rtllib_hdr_4addr
*hdr
;
331 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
333 if (ieee
->hwsec_active
)
335 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
336 tcb_desc
->bHwSec
= 1;
338 if (ieee
->need_sw_enc
)
339 tcb_desc
->bHwSec
= 0;
342 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
343 hdrlen
= rtllib_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
345 atomic_inc(&crypt
->refcnt
);
346 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
,ieee
);
347 atomic_dec(&crypt
->refcnt
);
349 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
350 " (SA=" MAC_FMT
" keyidx=%d)\n",
351 ieee
->dev
->name
, MAC_ARG(hdr
->addr2
), keyidx
);
359 /* this function is stolen from ipw2200 driver*/
360 #define IEEE_PACKET_RETRY_TIME (5*HZ)
361 static int is_duplicate_packet(struct rtllib_device
*ieee
,
362 struct rtllib_hdr_4addr
*header
)
364 u16 fc
= le16_to_cpu(header
->frame_ctl
);
365 u16 sc
= le16_to_cpu(header
->seq_ctl
);
366 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
367 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
368 u16
*last_seq
, *last_frag
;
369 unsigned long *last_time
;
370 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
371 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
374 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
)&&RTLLIB_QOS_HAS_SEQ(fc
)) {
375 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)header
;
376 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
379 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
380 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)header
;
381 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
388 switch (ieee
->iw_mode
) {
392 struct ieee_ibss_seq
*entry
= NULL
;
393 u8
*mac
= header
->addr2
;
394 int index
= mac
[5] % IEEE_IBSS_MAC_HASH_SIZE
;
395 list_for_each(p
, &ieee
->ibss_mac_hash
[index
]) {
396 entry
= list_entry(p
, struct ieee_ibss_seq
, list
);
397 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
400 if (p
== &ieee
->ibss_mac_hash
[index
]) {
401 entry
= kmalloc(sizeof(struct ieee_ibss_seq
), GFP_ATOMIC
);
403 printk(KERN_WARNING
"Cannot malloc new mac entry\n");
406 memcpy(entry
->mac
, mac
, ETH_ALEN
);
407 entry
->seq_num
[tid
] = seq
;
408 entry
->frag_num
[tid
] = frag
;
409 entry
->packet_time
[tid
] = jiffies
;
410 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
413 last_seq
= &entry
->seq_num
[tid
];
414 last_frag
= &entry
->frag_num
[tid
];
415 last_time
= &entry
->packet_time
[tid
];
420 last_seq
= &ieee
->last_rxseq_num
[tid
];
421 last_frag
= &ieee
->last_rxfrag_num
[tid
];
422 last_time
= &ieee
->last_packet_time
[tid
];
428 if ((*last_seq
== seq
) &&
429 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
430 if (*last_frag
== frag
){
434 if (*last_frag
+ 1 != frag
)
435 /* out-of-order fragment */
441 *last_time
= jiffies
;
450 struct rx_ts_record
*pTS
,
451 struct rx_reorder_entry
*pReorderEntry
454 struct list_head
*pList
= &pTS
->RxPendingPktList
;
456 while(pList
->next
!= &pTS
->RxPendingPktList
)
458 if ( SN_LESS(pReorderEntry
->SeqNum
, ((struct rx_reorder_entry
*)list_entry(pList
->next
,struct rx_reorder_entry
,List
))->SeqNum
) )
462 else if ( SN_EQUAL(pReorderEntry
->SeqNum
, ((struct rx_reorder_entry
*)list_entry(pList
->next
,struct rx_reorder_entry
,List
))->SeqNum
) )
471 pReorderEntry
->List
.next
= pList
->next
;
472 pReorderEntry
->List
.next
->prev
= &pReorderEntry
->List
;
473 pReorderEntry
->List
.prev
= pList
;
474 pList
->next
= &pReorderEntry
->List
;
479 void rtllib_indicate_packets(struct rtllib_device
*ieee
, struct rtllib_rxb
** prxbIndicateArray
,u8 index
)
481 struct net_device_stats
*stats
= &ieee
->stats
;
484 for (j
= 0; j
< index
; j
++) {
485 struct rtllib_rxb
* prxb
= prxbIndicateArray
[j
];
486 for (i
= 0; i
<prxb
->nr_subframes
; i
++) {
487 struct sk_buff
*sub_skb
= prxb
->subframes
[i
];
489 /* convert hdr + possible LLC headers into Ethernet header */
490 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
491 if (sub_skb
->len
>= 8 &&
492 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
493 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
494 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
495 /* remove RFC1042 or Bridge-Tunnel encapsulation and
496 * replace EtherType */
497 skb_pull(sub_skb
, SNAP_SIZE
);
498 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
499 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
502 /* Leave Ethernet header part of hdr and full payload */
503 len
= htons(sub_skb
->len
);
504 memcpy(skb_push(sub_skb
, 2), &len
, 2);
505 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
506 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
509 /* Indicat the packets to upper layer */
512 stats
->rx_bytes
+= sub_skb
->len
;
514 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
515 sub_skb
->protocol
= eth_type_trans(sub_skb
, ieee
->dev
);
516 sub_skb
->dev
= ieee
->dev
;
517 sub_skb
->dev
->stats
.rx_packets
++;
518 sub_skb
->dev
->stats
.rx_bytes
+= sub_skb
->len
;
519 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
520 ieee
->last_rx_ps_time
= jiffies
;
530 rtllib_FlushRxTsPendingPkts(struct rtllib_device
*ieee
, struct rx_ts_record
*pTS
)
532 struct rx_reorder_entry
*pRxReorderEntry
;
533 struct rtllib_rxb
* RfdArray
[REORDER_WIN_SIZE
];
537 del_timer_sync(&pTS
->RxPktPendingTimer
);
538 while(!list_empty(&pTS
->RxPendingPktList
))
540 if (RfdCnt
>= REORDER_WIN_SIZE
){
541 printk("-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n", __func__
);
545 pRxReorderEntry
= (struct rx_reorder_entry
*)list_entry(pTS
->RxPendingPktList
.prev
,struct rx_reorder_entry
,List
);
546 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,"%s(): Indicate SeqNum %d!\n",__func__
, pRxReorderEntry
->SeqNum
);
547 list_del_init(&pRxReorderEntry
->List
);
549 RfdArray
[RfdCnt
] = pRxReorderEntry
->prxb
;
552 list_add_tail(&pRxReorderEntry
->List
, &ieee
->RxReorder_Unused_List
);
554 rtllib_indicate_packets(ieee
, RfdArray
, RfdCnt
);
556 pTS
->RxIndicateSeq
= 0xffff;
560 void RxReorderIndicatePacket( struct rtllib_device
*ieee
,
561 struct rtllib_rxb
* prxb
,
562 struct rx_ts_record
*pTS
,
565 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
566 struct rx_reorder_entry
*pReorderEntry
= NULL
;
567 struct rtllib_rxb
* prxbIndicateArray
[REORDER_WIN_SIZE
];
568 u8 WinSize
= pHTInfo
->RxReorderWinSize
;
571 bool bMatchWinStart
= false, bPktInBuf
= false;
574 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__func__
,SeqNum
,pTS
->RxIndicateSeq
,WinSize
);
576 spin_lock_irqsave(&(ieee
->reorder_spinlock
), flags
);
578 WinEnd
= (pTS
->RxIndicateSeq
+ WinSize
-1)%4096;
579 /* Rx Reorder initialize condition.*/
580 if (pTS
->RxIndicateSeq
== 0xffff) {
581 pTS
->RxIndicateSeq
= SeqNum
;
584 /* Drop out the packet which SeqNum is smaller than WinStart */
585 if (SN_LESS(SeqNum
, pTS
->RxIndicateSeq
)) {
586 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
587 pTS
->RxIndicateSeq
, SeqNum
);
588 pHTInfo
->RxReorderDropCounter
++;
591 for (i
=0; i
< prxb
->nr_subframes
; i
++) {
592 dev_kfree_skb(prxb
->subframes
[i
]);
597 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
602 * Sliding window manipulation. Conditions includes:
603 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
604 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
606 if (SN_EQUAL(SeqNum
, pTS
->RxIndicateSeq
)) {
607 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
608 bMatchWinStart
= true;
609 } else if (SN_LESS(WinEnd
, SeqNum
)) {
610 if (SeqNum
>= (WinSize
- 1)) {
611 pTS
->RxIndicateSeq
= SeqNum
+ 1 -WinSize
;
613 pTS
->RxIndicateSeq
= 4095 - (WinSize
- (SeqNum
+1)) + 1;
615 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
619 * Indication process.
620 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
621 * with the SeqNum smaller than latest WinStart and struct buffer other packets.
623 /* For Rx Reorder condition:
624 * 1. All packets with SeqNum smaller than WinStart => Indicate
625 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
627 if (bMatchWinStart
) {
628 /* Current packet is going to be indicated.*/
629 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
630 pTS
->RxIndicateSeq
, SeqNum
);
631 prxbIndicateArray
[0] = prxb
;
634 /* Current packet is going to be inserted into pending list.*/
635 if (!list_empty(&ieee
->RxReorder_Unused_List
)) {
636 pReorderEntry
= (struct rx_reorder_entry
*)list_entry(ieee
->RxReorder_Unused_List
.next
,struct rx_reorder_entry
,List
);
637 list_del_init(&pReorderEntry
->List
);
639 /* Make a reorder entry and insert into a the packet list.*/
640 pReorderEntry
->SeqNum
= SeqNum
;
641 pReorderEntry
->prxb
= prxb
;
643 if (!AddReorderEntry(pTS
, pReorderEntry
)) {
644 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
645 __func__
, pTS
->RxIndicateSeq
, SeqNum
);
646 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
649 for (i
=0; i
< prxb
->nr_subframes
; i
++) {
650 dev_kfree_skb(prxb
->subframes
[i
]);
656 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,
657 "Pkt insert into struct buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS
->RxIndicateSeq
, SeqNum
);
662 * Packets are dropped if there is not enough reorder entries.
663 * This part shall be modified!! We can just indicate all the
664 * packets in struct buffer and get reorder entries.
666 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
669 for (i
=0; i
< prxb
->nr_subframes
; i
++) {
670 dev_kfree_skb(prxb
->subframes
[i
]);
678 /* Check if there is any packet need indicate.*/
679 while(!list_empty(&pTS
->RxPendingPktList
)) {
680 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,"%s(): start RREORDER indicate\n",__func__
);
682 pReorderEntry
= (struct rx_reorder_entry
*)list_entry(pTS
->RxPendingPktList
.prev
,struct rx_reorder_entry
,List
);
683 if ( SN_LESS(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
) ||
684 SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
686 /* This protect struct buffer from overflow. */
687 if (index
>= REORDER_WIN_SIZE
) {
688 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket(): Buffer overflow!! \n");
693 list_del_init(&pReorderEntry
->List
);
695 if (SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
696 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
698 prxbIndicateArray
[index
] = pReorderEntry
->prxb
;
699 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,"%s(): Indicate SeqNum %d!\n",__func__
, pReorderEntry
->SeqNum
);
702 list_add_tail(&pReorderEntry
->List
,&ieee
->RxReorder_Unused_List
);
709 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
711 if (timer_pending(&pTS
->RxPktPendingTimer
)){
712 del_timer_sync(&pTS
->RxPktPendingTimer
);
714 pTS
->RxTimeoutIndicateSeq
= 0xffff;
716 if (index
>REORDER_WIN_SIZE
){
717 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket(): Rx Reorer struct buffer full!! \n");
718 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
721 rtllib_indicate_packets(ieee
, prxbIndicateArray
, index
);
725 if (bPktInBuf
&& pTS
->RxTimeoutIndicateSeq
==0xffff) {
726 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,"%s(): SET rx timeout timer\n", __func__
);
727 pTS
->RxTimeoutIndicateSeq
= pTS
->RxIndicateSeq
;
728 mod_timer(&pTS
->RxPktPendingTimer
, jiffies
+ MSECS(pHTInfo
->RxReorderPendingTime
));
730 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
733 u8
parse_subframe(struct rtllib_device
* ieee
,struct sk_buff
*skb
,
734 struct rtllib_rx_stats
*rx_stats
,
735 struct rtllib_rxb
*rxb
,u8
* src
,u8
* dst
)
737 struct rtllib_hdr_3addr
*hdr
= (struct rtllib_hdr_3addr
* )skb
->data
;
738 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
740 u16 LLCOffset
= sizeof(struct rtllib_hdr_3addr
);
742 bool bIsAggregateFrame
= false;
743 u16 nSubframe_Length
;
744 u8 nPadding_Length
= 0;
746 struct sk_buff
*sub_skb
;
748 /* just for debug purpose */
749 SeqNum
= WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr
->seq_ctl
));
750 if ((RTLLIB_QOS_HAS_SEQ(fc
))&&\
751 (((union frameqos
*)(skb
->data
+ RTLLIB_3ADDR_LEN
))->field
.reserved
)) {
752 bIsAggregateFrame
= true;
755 if (RTLLIB_QOS_HAS_SEQ(fc
)) {
758 if (rx_stats
->bContainHTC
) {
759 LLCOffset
+= sHTCLng
;
762 ChkLength
= LLCOffset
;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
764 if ( skb
->len
<= ChkLength
) {
768 skb_pull(skb
, LLCOffset
);
769 ieee
->bIsAggregateFrame
= bIsAggregateFrame
;
770 if (!bIsAggregateFrame
) {
771 rxb
->nr_subframes
= 1;
773 /* altered by clark 3/30/2010
774 * The struct buffer size of the skb indicated to upper layer
775 * must be less than 5000, or the defraged IP datagram
776 * in the IP layer will exceed "ipfrag_high_tresh" and be
777 * discarded. so there must not use the function
778 * "skb_copy" and "skb_clone" for "skb".
781 /* Allocate new skb for releasing to upper layer */
782 sub_skb
= dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE
);
783 skb_reserve(sub_skb
, 12);
784 data_ptr
= (u8
*)skb_put(sub_skb
, skb
->len
);
785 memcpy(data_ptr
, skb
->data
, skb
->len
);
786 sub_skb
->dev
= ieee
->dev
;
788 rxb
->subframes
[0] = sub_skb
;
790 memcpy(rxb
->src
,src
,ETH_ALEN
);
791 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
792 rxb
->subframes
[0]->dev
= ieee
->dev
;
795 rxb
->nr_subframes
= 0;
796 memcpy(rxb
->src
,src
,ETH_ALEN
);
797 memcpy(rxb
->dst
,dst
,ETH_ALEN
);
798 while(skb
->len
> ETHERNET_HEADER_SIZE
) {
799 /* Offset 12 denote 2 mac address */
800 nSubframe_Length
= *((u16
*)(skb
->data
+ 12));
801 nSubframe_Length
= (nSubframe_Length
>>8) + (nSubframe_Length
<<8);
803 if (skb
->len
<(ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
804 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
805 __func__
,rxb
->nr_subframes
);
806 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__func__
, nSubframe_Length
);
807 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb
->len
,nSubframe_Length
);
808 printk("The Packet SeqNum is %d\n",SeqNum
);
812 /* move the data point to data content */
813 skb_pull(skb
, ETHERNET_HEADER_SIZE
);
815 /* altered by clark 3/30/2010
816 * The struct buffer size of the skb indicated to upper layer
817 * must be less than 5000, or the defraged IP datagram
818 * in the IP layer will exceed "ipfrag_high_tresh" and be
819 * discarded. so there must not use the function
820 * "skb_copy" and "skb_clone" for "skb".
823 /* Allocate new skb for releasing to upper layer */
824 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
825 skb_reserve(sub_skb
, 12);
826 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
827 memcpy(data_ptr
,skb
->data
,nSubframe_Length
);
829 sub_skb
->dev
= ieee
->dev
;
830 rxb
->subframes
[rxb
->nr_subframes
++] = sub_skb
;
831 if (rxb
->nr_subframes
>= MAX_SUBFRAME_COUNT
) {
832 RTLLIB_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
835 skb_pull(skb
,nSubframe_Length
);
838 nPadding_Length
= 4 - ((nSubframe_Length
+ ETHERNET_HEADER_SIZE
) % 4);
839 if (nPadding_Length
== 4) {
843 if (skb
->len
< nPadding_Length
) {
847 skb_pull(skb
,nPadding_Length
);
851 return rxb
->nr_subframes
;
856 size_t rtllib_rx_get_hdrlen(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
857 struct rtllib_rx_stats
*rx_stats
)
859 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
860 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
863 hdrlen
= rtllib_get_hdrlen(fc
);
864 if (HTCCheck(ieee
, skb
->data
)) {
866 printk("%s: find HTCControl!\n", __func__
);
868 rx_stats
->bContainHTC
= 1;
871 if (RTLLIB_QOS_HAS_SEQ(fc
))
872 rx_stats
->bIsQosData
= 1;
877 int rtllib_rx_check_duplicate(struct rtllib_device
*ieee
, struct sk_buff
*skb
, u8 multicast
)
879 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
881 u8 frag
, type
, stype
;
883 fc
= le16_to_cpu(hdr
->frame_ctl
);
884 type
= WLAN_FC_GET_TYPE(fc
);
885 stype
= WLAN_FC_GET_STYPE(fc
);
886 sc
= le16_to_cpu(hdr
->seq_ctl
);
887 frag
= WLAN_GET_SEQ_FRAG(sc
);
889 if ( (ieee
->pHTInfo
->bCurRxReorderEnable
== false) ||
890 !ieee
->current_network
.qos_data
.active
||
891 !IsDataFrame(skb
->data
) ||
892 IsLegacyDataFrame(skb
->data
)) {
893 if (!((type
== RTLLIB_FTYPE_MGMT
) && (stype
== RTLLIB_STYPE_BEACON
))){
894 if (is_duplicate_packet(ieee
, hdr
)){
899 struct rx_ts_record
*pRxTS
= NULL
;
900 if (GetTs(ieee
, (struct ts_common_info
**) &pRxTS
, hdr
->addr2
,
901 (u8
)Frame_QoSTID((u8
*)(skb
->data
)), RX_DIR
, true)) {
902 if ((fc
& (1<<11)) && (frag
== pRxTS
->RxLastFragNum
) &&
903 (WLAN_GET_SEQ_SEQ(sc
) == pRxTS
->RxLastSeqNum
)) {
906 pRxTS
->RxLastFragNum
= frag
;
907 pRxTS
->RxLastSeqNum
= WLAN_GET_SEQ_SEQ(sc
);
910 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "ERR!!%s(): No TS!! Skip the check!!\n",__func__
);
917 void rtllib_rx_extract_addr(struct rtllib_device
*ieee
, struct rtllib_hdr_4addr
*hdr
, u8
*dst
, u8
*src
, u8
*bssid
)
919 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
921 switch (fc
& (RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
)) {
922 case RTLLIB_FCTL_FROMDS
:
923 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
924 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
925 memcpy(bssid
, hdr
->addr2
, ETH_ALEN
);
927 case RTLLIB_FCTL_TODS
:
928 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
929 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
930 memcpy(bssid
, hdr
->addr1
, ETH_ALEN
);
932 case RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
:
933 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
934 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
935 memcpy(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
938 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
939 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
940 memcpy(bssid
, hdr
->addr3
, ETH_ALEN
);
944 int rtllib_rx_data_filter(struct rtllib_device
*ieee
, u16 fc
, u8
*dst
, u8
*src
, u8
*bssid
, u8
*addr2
)
946 u8 zero_addr
[ETH_ALEN
] = {0};
949 type
= WLAN_FC_GET_TYPE(fc
);
950 stype
= WLAN_FC_GET_STYPE(fc
);
952 /* Filter frames from different BSS */
953 if (((fc
& RTLLIB_FCTL_DSTODS
) != RTLLIB_FCTL_DSTODS
)
954 && (compare_ether_addr(ieee
->current_network
.bssid
, bssid
) != 0)
955 && memcmp(ieee
->current_network
.bssid
, zero_addr
, ETH_ALEN
)) {
959 /* Filter packets sent by an STA that will be forwarded by AP */
960 if ( ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
&&
961 ieee
->IntelPromiscuousModeInfo
.bFilterSourceStationFrame
) {
962 if ((fc
& RTLLIB_FCTL_TODS
) && !(fc
& RTLLIB_FCTL_FROMDS
) &&
963 (compare_ether_addr(dst
, ieee
->current_network
.bssid
) != 0) &&
964 (compare_ether_addr(bssid
, ieee
->current_network
.bssid
) == 0)) {
969 /* Nullfunc frames may have PS-bit set, so they must be passed to
970 * hostap_handle_sta_rx() before being dropped here. */
971 if (!ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
){
972 if (stype
!= RTLLIB_STYPE_DATA
&&
973 stype
!= RTLLIB_STYPE_DATA_CFACK
&&
974 stype
!= RTLLIB_STYPE_DATA_CFPOLL
&&
975 stype
!= RTLLIB_STYPE_DATA_CFACKPOLL
&&
976 stype
!= RTLLIB_STYPE_QOS_DATA
978 if (stype
!= RTLLIB_STYPE_NULLFUNC
)
980 "RX: dropped data frame "
981 "with no data (type=0x%02x, "
988 if (ieee
->iw_mode
!= IW_MODE_MESH
) {
989 /* packets from our adapter are dropped (echo) */
990 if (!memcmp(src
, ieee
->dev
->dev_addr
, ETH_ALEN
))
993 /* {broad,multi}cast packets to our BSS go through */
994 if (is_multicast_ether_addr(dst
) || is_broadcast_ether_addr(dst
)) {
995 if (memcmp(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
)) {
1002 int rtllib_rx_get_crypt(
1003 struct rtllib_device
*ieee
,
1004 struct sk_buff
*skb
,
1005 struct rtllib_crypt_data
**crypt
,
1008 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1009 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1012 if (ieee
->host_decrypt
) {
1013 if (skb
->len
>= hdrlen
+ 3)
1014 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1016 *crypt
= ieee
->crypt
[idx
];
1017 /* allow NULL decrypt to indicate an station specific override
1018 * for default encryption */
1019 if (*crypt
&& ((*crypt
)->ops
== NULL
||
1020 (*crypt
)->ops
->decrypt_mpdu
== NULL
))
1023 if (!*crypt
&& (fc
& RTLLIB_FCTL_WEP
)) {
1024 /* This seems to be triggered by some (multicast?)
1025 * frames from other than current BSS, so just drop the
1026 * frames silently instead of filling system log with
1028 RTLLIB_DEBUG_DROP("Decryption failed (not set)"
1029 " (SA=" MAC_FMT
")\n",
1030 MAC_ARG(hdr
->addr2
));
1031 ieee
->ieee_stats
.rx_discards_undecryptable
++;
1038 int rtllib_rx_decrypt(
1039 struct rtllib_device
*ieee
,
1040 struct sk_buff
*skb
,
1041 struct rtllib_rx_stats
*rx_stats
,
1042 struct rtllib_crypt_data
*crypt
,
1045 struct rtllib_hdr_4addr
*hdr
;
1050 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1051 fc
= le16_to_cpu(hdr
->frame_ctl
);
1052 sc
= le16_to_cpu(hdr
->seq_ctl
);
1053 frag
= WLAN_GET_SEQ_FRAG(sc
);
1055 if ((!rx_stats
->Decrypted
)){
1056 ieee
->need_sw_enc
= 1;
1058 ieee
->need_sw_enc
= 0;
1061 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) &&
1062 ((keyidx
= rtllib_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0)) {
1063 printk("%s: decrypt frame error\n", __func__
);
1067 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1068 if ((frag
!= 0 || (fc
& RTLLIB_FCTL_MOREFRAGS
))) {
1070 struct sk_buff
*frag_skb
= rtllib_frag_cache_get(ieee
, hdr
);
1071 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
1074 RTLLIB_DEBUG(RTLLIB_DL_RX
| RTLLIB_DL_FRAG
,
1075 "Rx cannot get skb from fragment "
1076 "cache (morefrag=%d seq=%u frag=%u)\n",
1077 (fc
& RTLLIB_FCTL_MOREFRAGS
) != 0,
1078 WLAN_GET_SEQ_SEQ(sc
), frag
);
1085 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
1086 printk(KERN_WARNING
"%s: host decrypted and "
1087 "reassembled frame did not fit skb\n",
1089 rtllib_frag_cache_invalidate(ieee
, hdr
);
1094 /* copy first fragment (including full headers) into
1095 * beginning of the fragment cache skb */
1096 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
1098 /* append frame payload to the end of the fragment
1100 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
1103 dev_kfree_skb_any(skb
);
1106 if (fc
& RTLLIB_FCTL_MOREFRAGS
) {
1107 /* more fragments expected - leave the skb in fragment
1108 * cache for now; it will be delivered to upper layers
1109 * after all fragments have been received */
1113 /* this was the last fragment and the frame will be
1114 * delivered, so remove skb from fragment cache */
1116 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1117 rtllib_frag_cache_invalidate(ieee
, hdr
);
1120 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1121 * encrypted/authenticated */
1122 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) &&
1123 rtllib_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
))
1125 printk("%s: ==>decrypt msdu error\n", __func__
);
1129 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1130 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
) {
1131 if (/*ieee->ieee802_1x &&*/
1132 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1134 /* pass unencrypted EAPOL frames even if encryption is
1136 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1138 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1139 eap_get_type(eap
->type
));
1142 "encryption configured, but RX "
1143 "frame not encrypted (SA=" MAC_FMT
")\n",
1144 MAC_ARG(hdr
->addr2
));
1149 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) &&
1150 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1151 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1153 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1154 eap_get_type(eap
->type
));
1157 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
&&
1158 !rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1160 "dropped unencrypted RX data "
1161 "frame from " MAC_FMT
1162 " (drop_unencrypted=1)\n",
1163 MAC_ARG(hdr
->addr2
));
1167 if (rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1168 printk(KERN_WARNING
"RX: IEEE802.1X EAPOL frame!\n");
1173 void rtllib_rx_check_leave_lps(struct rtllib_device
*ieee
, u8 unicast
, u8 nr_subframes
)
1177 if ((ieee
->state
== RTLLIB_LINKED
) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/)
1179 if ( ((ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+ieee
->LinkDetectInfo
.NumTxOkInPeriod
) > 8 ) ||
1180 (ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
> 2) )
1182 if (ieee
->LeisurePSLeave
)
1183 ieee
->LeisurePSLeave(ieee
->dev
);
1187 ieee
->last_rx_ps_time
= jiffies
;
1189 void rtllib_rx_indicate_pkt_legacy(
1190 struct rtllib_device
*ieee
,
1191 struct rtllib_rx_stats
*rx_stats
,
1192 struct rtllib_rxb
* rxb
,
1196 struct net_device
*dev
= ieee
->dev
;
1201 printk("%s: rxb is NULL!!\n", __func__
);
1205 for (i
= 0; i
<rxb
->nr_subframes
; i
++) {
1206 struct sk_buff
*sub_skb
= rxb
->subframes
[i
];
1209 /* convert hdr + possible LLC headers into Ethernet header */
1210 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
1211 if (sub_skb
->len
>= 8 &&
1212 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
1213 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1214 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
1215 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1216 * replace EtherType */
1217 skb_pull(sub_skb
, SNAP_SIZE
);
1218 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1219 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1222 /* Leave Ethernet header part of hdr and full payload */
1223 len
= htons(sub_skb
->len
);
1224 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1225 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1226 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1229 ieee
->stats
.rx_packets
++;
1230 ieee
->stats
.rx_bytes
+= sub_skb
->len
;
1232 if (is_multicast_ether_addr(dst
)) {
1233 ieee
->stats
.multicast
++;
1236 /* Indicat the packets to upper layer */
1237 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
1238 sub_skb
->protocol
= eth_type_trans(sub_skb
, dev
);
1240 sub_skb
->dev
->stats
.rx_packets
++;
1241 sub_skb
->dev
->stats
.rx_bytes
+= sub_skb
->len
;
1242 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
1249 int rtllib_rx_InfraAdhoc(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1250 struct rtllib_rx_stats
*rx_stats
)
1252 struct net_device
*dev
= ieee
->dev
;
1253 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1254 struct rtllib_crypt_data
*crypt
= NULL
;
1255 struct rtllib_rxb
* rxb
= NULL
;
1256 struct rx_ts_record
*pTS
= NULL
;
1257 u16 fc
, sc
, SeqNum
= 0;
1258 u8 type
, stype
, multicast
= 0, unicast
= 0, nr_subframes
= 0, TID
= 0;
1259 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
], bssid
[ETH_ALEN
] = {0}, *payload
;
1261 bool bToOtherSTA
= false;
1264 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1265 fc
= le16_to_cpu(hdr
->frame_ctl
);
1266 type
= WLAN_FC_GET_TYPE(fc
);
1267 stype
= WLAN_FC_GET_STYPE(fc
);
1268 sc
= le16_to_cpu(hdr
->seq_ctl
);
1270 /*Filter pkt not to me*/
1271 multicast
= is_multicast_ether_addr(hdr
->addr1
)|is_broadcast_ether_addr(hdr
->addr1
);
1272 unicast
= !multicast
;
1273 if (unicast
&& (compare_ether_addr(dev
->dev_addr
, hdr
->addr1
) != 0)) {
1274 if (ieee
->bNetPromiscuousMode
)
1280 /*Filter pkt has too small length */
1281 hdrlen
= rtllib_rx_get_hdrlen(ieee
, skb
, rx_stats
);
1282 if (skb
->len
< hdrlen
){
1283 printk("%s():ERR!!! skb->len is smaller than hdrlen\n",__func__
);
1287 /* Filter Duplicate pkt */
1288 ret
= rtllib_rx_check_duplicate(ieee
, skb
, multicast
);
1292 /* Filter CTRL Frame */
1293 if (type
== RTLLIB_FTYPE_CTL
) {
1297 /* Filter MGNT Frame */
1298 if (type
== RTLLIB_FTYPE_MGMT
) {
1301 if (rtllib_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
1307 /* Filter WAPI DATA Frame */
1309 /* Update statstics for AP roaming */
1311 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
++;
1312 ieee
->LinkDetectInfo
.NumRxOkInPeriod
++;
1314 dev
->last_rx
= jiffies
;
1316 /* Data frame - extract src/dst addresses */
1317 rtllib_rx_extract_addr(ieee
, hdr
, dst
, src
, bssid
);
1319 /* Filter Data frames */
1320 ret
= rtllib_rx_data_filter(ieee
, fc
, dst
, src
, bssid
, hdr
->addr2
);
1324 if (skb
->len
== hdrlen
){
1328 /* Send pspoll based on moredata */
1329 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && (ieee
->sta_sleep
== LPS_IS_SLEEP
)
1330 && (ieee
->polling
) && (!bToOtherSTA
)) {
1331 if (WLAN_FC_MORE_DATA(fc
)) {
1332 /* more data bit is set, let's request a new frame from the AP */
1333 rtllib_sta_ps_send_pspoll_frame(ieee
);
1335 ieee
->polling
= false;
1339 /* Get crypt if encrypted */
1340 ret
= rtllib_rx_get_crypt(ieee
, skb
, &crypt
, hdrlen
);
1344 /* Decrypt data frame (including reassemble) */
1345 ret
= rtllib_rx_decrypt(ieee
, skb
, rx_stats
, crypt
, hdrlen
);
1351 /* Get TS for Rx Reorder */
1352 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1353 if (ieee
->current_network
.qos_data
.active
&& IsQoSDataFrame(skb
->data
)
1354 && !is_multicast_ether_addr(hdr
->addr1
) && !is_broadcast_ether_addr(hdr
->addr1
)
1357 TID
= Frame_QoSTID(skb
->data
);
1358 SeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1359 GetTs(ieee
,(struct ts_common_info
**) &pTS
,hdr
->addr2
,TID
,RX_DIR
,true);
1360 if (TID
!=0 && TID
!=3){
1361 ieee
->bis_any_nonbepkts
= true;
1365 /* Parse rx data frame (For AMSDU) */
1366 /* skb: hdr + (possible reassembled) full plaintext payload */
1367 payload
= skb
->data
+ hdrlen
;
1368 rxb
= (struct rtllib_rxb
*)kmalloc(sizeof(struct rtllib_rxb
),GFP_ATOMIC
);
1371 RTLLIB_DEBUG(RTLLIB_DL_ERR
,"%s(): kmalloc rxb error\n",__func__
);
1374 /* to parse amsdu packets */
1375 /* qos data packets & reserved bit is 1 */
1376 if (parse_subframe(ieee
,skb
,rx_stats
,rxb
,src
,dst
) == 0) {
1377 /* only to free rxb, and not submit the packets to upper layer */
1378 for (i
=0; i
< rxb
->nr_subframes
; i
++) {
1379 dev_kfree_skb(rxb
->subframes
[i
]);
1386 /* Update WAPI PN */
1388 /* Check if leave LPS */
1390 if (ieee
->bIsAggregateFrame
)
1391 nr_subframes
= rxb
->nr_subframes
;
1395 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+= nr_subframes
;
1396 rtllib_rx_check_leave_lps(ieee
, unicast
, nr_subframes
);
1399 /* Indicate packets to upper layer or Rx Reorder */
1400 if (ieee
->pHTInfo
->bCurRxReorderEnable
== false ||pTS
== NULL
|| bToOtherSTA
){
1401 rtllib_rx_indicate_pkt_legacy(ieee
, rx_stats
, rxb
, dst
, src
);
1403 RxReorderIndicatePacket(ieee
, rxb
, pTS
, SeqNum
);
1417 ieee
->stats
.rx_dropped
++;
1419 /* Returning 0 indicates to caller that we have not handled the SKB--
1420 * so it is still allocated and can be used again by underlying
1421 * hardware as a DMA target */
1425 int rtllib_rx_Master(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1426 struct rtllib_rx_stats
*rx_stats
)
1430 int rtllib_rx_Monitor(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1431 struct rtllib_rx_stats
*rx_stats
)
1433 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1434 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1435 size_t hdrlen
= rtllib_get_hdrlen(fc
);
1437 if (skb
->len
< hdrlen
){
1438 printk("%s():ERR!!! skb->len is smaller than hdrlen\n", __func__
);
1442 if (HTCCheck(ieee
, skb
->data
)) {
1443 if (net_ratelimit())
1444 printk("%s: Find HTCControl!\n", __func__
);
1448 rtllib_monitor_rx(ieee
, skb
, rx_stats
, hdrlen
);
1449 ieee
->stats
.rx_packets
++;
1450 ieee
->stats
.rx_bytes
+= skb
->len
;
1455 int rtllib_rx_Mesh(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1456 struct rtllib_rx_stats
*rx_stats
)
1461 /* All received frames are sent to this function. @skb contains the frame in
1462 * IEEE 802.11 format, i.e., in the format it was sent over air.
1463 * This function is called only as a tasklet (software IRQ). */
1464 int rtllib_rx(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1465 struct rtllib_rx_stats
*rx_stats
)
1469 if ((NULL
==ieee
) || (NULL
==skb
) || (NULL
==rx_stats
)){
1470 printk(KERN_INFO
"%s: Input parameters NULL!\n", __func__
);
1473 if (skb
->len
< 10) {
1474 printk(KERN_INFO
"%s: SKB length < 10 \n", __func__
);
1478 switch (ieee
->iw_mode
) {
1481 ret
= rtllib_rx_InfraAdhoc(ieee
, skb
, rx_stats
);
1483 case IW_MODE_MASTER
:
1484 case IW_MODE_REPEAT
:
1485 ret
= rtllib_rx_Master(ieee
, skb
, rx_stats
);
1487 case IW_MODE_MONITOR
:
1488 ret
= rtllib_rx_Monitor(ieee
, skb
, rx_stats
);
1491 ret
= rtllib_rx_Mesh(ieee
, skb
, rx_stats
);
1494 printk(KERN_INFO
"%s: ERR iw mode!!!\n", __func__
);
1501 ieee
->stats
.rx_dropped
++;
1505 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
1508 * Make ther structure we read from the beacon packet has
1511 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1512 *info_element
, int sub_type
)
1515 if (info_element
->qui_subtype
!= sub_type
)
1517 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
1519 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
1521 if (info_element
->version
!= QOS_VERSION_1
)
1529 * Parse a QoS parameter element
1531 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
1532 *element_param
, struct rtllib_info_element
1536 u16 size
= sizeof(struct rtllib_qos_parameter_info
) - 2;
1538 if ((info_element
== NULL
) || (element_param
== NULL
))
1541 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
1542 memcpy(element_param
->info_element
.qui
, info_element
->data
,
1544 element_param
->info_element
.elementID
= info_element
->id
;
1545 element_param
->info_element
.length
= info_element
->len
;
1549 ret
= rtllib_verify_qos_info(&element_param
->info_element
,
1550 QOS_OUI_PARAM_SUB_TYPE
);
1555 * Parse a QoS information element
1557 static int rtllib_read_qos_info_element(struct
1558 rtllib_qos_information_element
1559 *element_info
, struct rtllib_info_element
1563 u16 size
= sizeof(struct rtllib_qos_information_element
) - 2;
1565 if (element_info
== NULL
)
1567 if (info_element
== NULL
)
1570 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
1571 memcpy(element_info
->qui
, info_element
->data
,
1573 element_info
->elementID
= info_element
->id
;
1574 element_info
->length
= info_element
->len
;
1579 ret
= rtllib_verify_qos_info(element_info
,
1580 QOS_OUI_INFO_SUB_TYPE
);
1586 * Write QoS parameters from the ac parameters.
1588 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info
*param_elm
,
1589 struct rtllib_qos_data
*qos_data
)
1591 struct rtllib_qos_ac_parameter
*ac_params
;
1592 struct rtllib_qos_parameters
*qos_param
= &(qos_data
->parameters
);
1598 qos_data
->wmm_acm
= 0;
1599 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1600 ac_params
= &(param_elm
->ac_params_record
[i
]);
1602 aci
= (ac_params
->aci_aifsn
& 0x60) >> 5;
1603 acm
= (ac_params
->aci_aifsn
& 0x10) >> 4;
1605 if (aci
>= QOS_QUEUE_NUM
)
1609 /* BIT(0) | BIT(3) */
1611 qos_data
->wmm_acm
|= (0x01<<0)|(0x01<<3);
1614 /* BIT(4) | BIT(5) */
1616 qos_data
->wmm_acm
|= (0x01<<4)|(0x01<<5);
1619 /* BIT(6) | BIT(7) */
1621 qos_data
->wmm_acm
|= (0x01<<6)|(0x01<<7);
1625 /* BIT(1) | BIT(2) */
1627 qos_data
->wmm_acm
|= (0x01<<1)|(0x01<<2);
1631 qos_param
->aifs
[aci
] = (ac_params
->aci_aifsn
) & 0x0f;
1633 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1634 qos_param
->aifs
[aci
] = (qos_param
->aifs
[aci
] < 2) ? 2:qos_param
->aifs
[aci
];
1636 qos_param
->cw_min
[aci
] = ac_params
->ecw_min_max
& 0x0F;
1638 qos_param
->cw_max
[aci
] = (ac_params
->ecw_min_max
& 0xF0) >> 4;
1640 qos_param
->flag
[aci
] =
1641 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1642 qos_param
->tx_op_limit
[aci
] = le16_to_cpu(ac_params
->tx_op_limit
);
1648 * we have a generic data element which it may contain QoS information or
1649 * parameters element. check the information element length to decide
1650 * which type to read
1652 static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
1654 struct rtllib_network
*network
)
1657 struct rtllib_qos_information_element qos_info_element
;
1659 rc
= rtllib_read_qos_info_element(&qos_info_element
, info_element
);
1662 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1663 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1665 struct rtllib_qos_parameter_info param_element
;
1667 rc
= rtllib_read_qos_param_element(¶m_element
,
1670 rtllib_qos_convert_ac_to_parameters(¶m_element
,
1671 &(network
->qos_data
));
1672 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1673 network
->qos_data
.param_count
=
1674 param_element
.info_element
.ac_info
& 0x0F;
1679 RTLLIB_DEBUG_QOS("QoS is supported\n");
1680 network
->qos_data
.supported
= 1;
1685 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1687 static const char *get_info_element_string(u16 id
)
1692 MFIE_STRING(FH_SET
);
1693 MFIE_STRING(DS_SET
);
1694 MFIE_STRING(CF_SET
);
1696 MFIE_STRING(IBSS_SET
);
1697 MFIE_STRING(COUNTRY
);
1698 MFIE_STRING(HOP_PARAMS
);
1699 MFIE_STRING(HOP_TABLE
);
1700 MFIE_STRING(REQUEST
);
1701 MFIE_STRING(CHALLENGE
);
1702 MFIE_STRING(POWER_CONSTRAINT
);
1703 MFIE_STRING(POWER_CAPABILITY
);
1704 MFIE_STRING(TPC_REQUEST
);
1705 MFIE_STRING(TPC_REPORT
);
1706 MFIE_STRING(SUPP_CHANNELS
);
1708 MFIE_STRING(MEASURE_REQUEST
);
1709 MFIE_STRING(MEASURE_REPORT
);
1711 MFIE_STRING(IBSS_DFS
);
1713 MFIE_STRING(RATES_EX
);
1714 MFIE_STRING(GENERIC
);
1715 MFIE_STRING(QOS_PARAMETER
);
1721 static inline void rtllib_extract_country_ie(
1722 struct rtllib_device
*ieee
,
1723 struct rtllib_info_element
*info_element
,
1724 struct rtllib_network
*network
,
1727 if (IS_DOT11D_ENABLE(ieee
)) {
1728 if (info_element
->len
!= 0) {
1729 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
1730 network
->CountryIeLen
= info_element
->len
;
1732 if (!IS_COUNTRY_IE_VALID(ieee
))
1734 if ((rtllib_act_scanning(ieee
,false) == true) && (ieee
->FirstIe_InScan
== 1))
1735 printk("Received beacon ContryIE, SSID: <%s>\n",network
->ssid
);
1736 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
1740 if (IS_EQUAL_CIE_SRC(ieee
, addr2
)) {
1741 UPDATE_CIE_WATCHDOG(ieee
);
1747 int rtllib_parse_info_param(struct rtllib_device
*ieee
,
1748 struct rtllib_info_element
*info_element
,
1750 struct rtllib_network
*network
,
1751 struct rtllib_rx_stats
*stats
)
1755 u16 tmp_htcap_len
=0;
1756 u16 tmp_htinfo_len
=0;
1757 u16 ht_realtek_agg_len
=0;
1758 u8 ht_realtek_agg_buf
[MAX_IE_LEN
];
1762 while (length
>= sizeof(*info_element
)) {
1763 if (sizeof(*info_element
) + info_element
->len
> length
) {
1764 RTLLIB_DEBUG_MGMT("Info elem: parse failed: "
1765 "info_element->len + 2 > left : "
1766 "info_element->len+2=%zd left=%d, id=%d.\n",
1768 sizeof(*info_element
),
1769 length
, info_element
->id
);
1770 /* We stop processing but don't return an error here
1771 * because some misbehaviour APs break this rule. ie.
1772 * Orinoco AP1000. */
1776 switch (info_element
->id
) {
1777 case MFIE_TYPE_SSID
:
1778 if (rtllib_is_empty_essid(info_element
->data
,
1779 info_element
->len
)) {
1780 network
->flags
|= NETWORK_EMPTY_ESSID
;
1784 network
->ssid_len
= min(info_element
->len
,
1785 (u8
) IW_ESSID_MAX_SIZE
);
1786 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
1787 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1788 memset(network
->ssid
+ network
->ssid_len
, 0,
1789 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1791 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1792 network
->ssid
, network
->ssid_len
);
1795 case MFIE_TYPE_RATES
:
1797 network
->rates_len
= min(info_element
->len
,
1799 for (i
= 0; i
< network
->rates_len
; i
++) {
1800 network
->rates
[i
] = info_element
->data
[i
];
1801 p
+= snprintf(p
, sizeof(rates_str
) -
1802 (p
- rates_str
), "%02X ",
1804 if (rtllib_is_ofdm_rate
1805 (info_element
->data
[i
])) {
1806 network
->flags
|= NETWORK_HAS_OFDM
;
1807 if (info_element
->data
[i
] &
1808 RTLLIB_BASIC_RATE_MASK
)
1813 if (rtllib_is_cck_rate
1814 (info_element
->data
[i
])) {
1815 network
->flags
|= NETWORK_HAS_CCK
;
1819 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1820 rates_str
, network
->rates_len
);
1823 case MFIE_TYPE_RATES_EX
:
1825 network
->rates_ex_len
= min(info_element
->len
,
1826 MAX_RATES_EX_LENGTH
);
1827 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1828 network
->rates_ex
[i
] = info_element
->data
[i
];
1829 p
+= snprintf(p
, sizeof(rates_str
) -
1830 (p
- rates_str
), "%02X ",
1832 if (rtllib_is_ofdm_rate
1833 (info_element
->data
[i
])) {
1834 network
->flags
|= NETWORK_HAS_OFDM
;
1835 if (info_element
->data
[i
] &
1836 RTLLIB_BASIC_RATE_MASK
)
1842 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1843 rates_str
, network
->rates_ex_len
);
1846 case MFIE_TYPE_DS_SET
:
1847 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1848 info_element
->data
[0]);
1849 network
->channel
= info_element
->data
[0];
1852 case MFIE_TYPE_FH_SET
:
1853 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1856 case MFIE_TYPE_CF_SET
:
1857 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1861 if (info_element
->len
< 4)
1864 network
->tim
.tim_count
= info_element
->data
[0];
1865 network
->tim
.tim_period
= info_element
->data
[1];
1867 network
->dtim_period
= info_element
->data
[1];
1868 if (ieee
->state
!= RTLLIB_LINKED
)
1870 network
->last_dtim_sta_time
= jiffies
;
1872 network
->dtim_data
= RTLLIB_DTIM_VALID
;
1875 if (info_element
->data
[2] & 1)
1876 network
->dtim_data
|= RTLLIB_DTIM_MBCAST
;
1878 offset
= (info_element
->data
[2] >> 1)*2;
1881 if (ieee
->assoc_id
< 8*offset
||
1882 ieee
->assoc_id
> 8*(offset
+ info_element
->len
-3))
1886 offset
= (ieee
->assoc_id
/ 8) - offset
;
1887 if (info_element
->data
[3+offset
] & (1<<(ieee
->assoc_id
%8)))
1888 network
->dtim_data
|= RTLLIB_DTIM_UCAST
;
1890 network
->listen_interval
= network
->dtim_period
;
1894 network
->erp_value
= info_element
->data
[0];
1895 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1896 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1897 network
->erp_value
);
1899 case MFIE_TYPE_IBSS_SET
:
1900 network
->atim_window
= info_element
->data
[0];
1901 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1902 network
->atim_window
);
1905 case MFIE_TYPE_CHALLENGE
:
1906 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1909 case MFIE_TYPE_GENERIC
:
1910 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1912 if (!rtllib_parse_qos_info_param_IE(info_element
,
1915 if (info_element
->len
>= 4 &&
1916 info_element
->data
[0] == 0x00 &&
1917 info_element
->data
[1] == 0x50 &&
1918 info_element
->data
[2] == 0xf2 &&
1919 info_element
->data
[3] == 0x01) {
1920 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1922 memcpy(network
->wpa_ie
, info_element
,
1923 network
->wpa_ie_len
);
1926 if (info_element
->len
== 7 &&
1927 info_element
->data
[0] == 0x00 &&
1928 info_element
->data
[1] == 0xe0 &&
1929 info_element
->data
[2] == 0x4c &&
1930 info_element
->data
[3] == 0x01 &&
1931 info_element
->data
[4] == 0x02)
1932 network
->Turbo_Enable
= 1;
1934 if (tmp_htcap_len
== 0) {
1935 if (info_element
->len
>= 4 &&
1936 info_element
->data
[0] == 0x00 &&
1937 info_element
->data
[1] == 0x90 &&
1938 info_element
->data
[2] == 0x4c &&
1939 info_element
->data
[3] == 0x033) {
1941 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1942 if (tmp_htcap_len
!= 0){
1943 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1944 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
1945 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
1946 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
1949 if (tmp_htcap_len
!= 0){
1950 network
->bssht
.bdSupportHT
= true;
1951 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)(network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0);
1953 network
->bssht
.bdSupportHT
= false;
1954 network
->bssht
.bdHT1R
= false;
1959 if (tmp_htinfo_len
== 0){
1960 if (info_element
->len
>= 4 &&
1961 info_element
->data
[0] == 0x00 &&
1962 info_element
->data
[1] == 0x90 &&
1963 info_element
->data
[2] == 0x4c &&
1964 info_element
->data
[3] == 0x034){
1966 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1967 if (tmp_htinfo_len
!= 0){
1968 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1969 if (tmp_htinfo_len
){
1970 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
1971 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
1972 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
1980 if (ieee
->aggregation
){
1981 if (network
->bssht
.bdSupportHT
){
1982 if (info_element
->len
>= 4 &&
1983 info_element
->data
[0] == 0x00 &&
1984 info_element
->data
[1] == 0xe0 &&
1985 info_element
->data
[2] == 0x4c &&
1986 info_element
->data
[3] == 0x02){
1988 ht_realtek_agg_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
1989 memcpy(ht_realtek_agg_buf
,info_element
->data
,info_element
->len
);
1992 if (ht_realtek_agg_len
>= 5){
1993 network
->realtek_cap_exit
= true;
1994 network
->bssht
.bdRT2RTAggregation
= true;
1996 if ((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & 0x02))
1997 network
->bssht
.bdRT2RTLongSlotTime
= true;
1999 if ((ht_realtek_agg_buf
[4]==1) && (ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_92SE
))
2001 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_92SE
;
2005 if (ht_realtek_agg_len
>= 5){
2006 if ((ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_SOFTAP
))
2007 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_SOFTAP
;
2012 if ((info_element
->len
>= 3 &&
2013 info_element
->data
[0] == 0x00 &&
2014 info_element
->data
[1] == 0x05 &&
2015 info_element
->data
[2] == 0xb5) ||
2016 (info_element
->len
>= 3 &&
2017 info_element
->data
[0] == 0x00 &&
2018 info_element
->data
[1] == 0x0a &&
2019 info_element
->data
[2] == 0xf7) ||
2020 (info_element
->len
>= 3 &&
2021 info_element
->data
[0] == 0x00 &&
2022 info_element
->data
[1] == 0x10 &&
2023 info_element
->data
[2] == 0x18)){
2025 network
->broadcom_cap_exist
= true;
2029 if (info_element
->len
>= 3 &&
2030 info_element
->data
[0] == 0x00 &&
2031 info_element
->data
[1] == 0x0c &&
2032 info_element
->data
[2] == 0x43)
2034 network
->ralink_cap_exist
= true;
2036 if ((info_element
->len
>= 3 &&
2037 info_element
->data
[0] == 0x00 &&
2038 info_element
->data
[1] == 0x03 &&
2039 info_element
->data
[2] == 0x7f) ||
2040 (info_element
->len
>= 3 &&
2041 info_element
->data
[0] == 0x00 &&
2042 info_element
->data
[1] == 0x13 &&
2043 info_element
->data
[2] == 0x74))
2045 network
->atheros_cap_exist
= true;
2048 if ((info_element
->len
>= 3 &&
2049 info_element
->data
[0] == 0x00 &&
2050 info_element
->data
[1] == 0x50 &&
2051 info_element
->data
[2] == 0x43) )
2053 network
->marvell_cap_exist
= true;
2055 if (info_element
->len
>= 3 &&
2056 info_element
->data
[0] == 0x00 &&
2057 info_element
->data
[1] == 0x40 &&
2058 info_element
->data
[2] == 0x96)
2060 network
->cisco_cap_exist
= true;
2064 if (info_element
->len
>= 3 &&
2065 info_element
->data
[0] == 0x00 &&
2066 info_element
->data
[1] == 0x0a &&
2067 info_element
->data
[2] == 0xf5)
2069 network
->airgo_cap_exist
= true;
2072 if (info_element
->len
> 4 &&
2073 info_element
->data
[0] == 0x00 &&
2074 info_element
->data
[1] == 0x40 &&
2075 info_element
->data
[2] == 0x96 &&
2076 info_element
->data
[3] == 0x01)
2078 if (info_element
->len
== 6)
2080 memcpy(network
->CcxRmState
, &info_element
[4], 2);
2081 if (network
->CcxRmState
[0] != 0)
2083 network
->bCcxRmEnable
= true;
2086 network
->bCcxRmEnable
= false;
2087 network
->MBssidMask
= network
->CcxRmState
[1] & 0x07;
2088 if (network
->MBssidMask
!= 0)
2090 network
->bMBssidValid
= true;
2091 network
->MBssidMask
= 0xff << (network
->MBssidMask
);
2092 memcpy(network
->MBssid
, network
->bssid
, ETH_ALEN
);
2093 network
->MBssid
[5] &= network
->MBssidMask
;
2097 network
->bMBssidValid
= false;
2102 network
->bCcxRmEnable
= false;
2105 if (info_element
->len
> 4 &&
2106 info_element
->data
[0] == 0x00 &&
2107 info_element
->data
[1] == 0x40 &&
2108 info_element
->data
[2] == 0x96 &&
2109 info_element
->data
[3] == 0x03)
2111 if (info_element
->len
== 5)
2113 network
->bWithCcxVerNum
= true;
2114 network
->BssCcxVerNumber
= info_element
->data
[4];
2118 network
->bWithCcxVerNum
= false;
2119 network
->BssCcxVerNumber
= 0;
2122 if (info_element
->len
> 4 &&
2123 info_element
->data
[0] == 0x00 &&
2124 info_element
->data
[1] == 0x50 &&
2125 info_element
->data
[2] == 0xf2 &&
2126 info_element
->data
[3] == 0x04)
2128 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
2130 network
->wzc_ie_len
= min(info_element
->len
+2,
2132 memcpy(network
->wzc_ie
, info_element
,
2133 network
->wzc_ie_len
);
2138 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2140 network
->rsn_ie_len
= min(info_element
->len
+ 2,
2142 memcpy(network
->rsn_ie
, info_element
,
2143 network
->rsn_ie_len
);
2146 case MFIE_TYPE_HT_CAP
:
2147 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2149 tmp_htcap_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2150 if (tmp_htcap_len
!= 0){
2151 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
2152 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
)?\
2153 sizeof(network
->bssht
.bdHTCapBuf
):tmp_htcap_len
;
2154 memcpy(network
->bssht
.bdHTCapBuf
,info_element
->data
,network
->bssht
.bdHTCapLen
);
2156 network
->bssht
.bdSupportHT
= true;
2157 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)(network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0);
2159 network
->bssht
.bdBandWidth
= (enum ht_channel_width
)(((struct ht_capab_ele
*)(network
->bssht
.bdHTCapBuf
))->ChlWidth
);
2162 network
->bssht
.bdSupportHT
= false;
2163 network
->bssht
.bdHT1R
= false;
2164 network
->bssht
.bdBandWidth
= HT_CHANNEL_WIDTH_20
;
2169 case MFIE_TYPE_HT_INFO
:
2170 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2172 tmp_htinfo_len
= min(info_element
->len
,(u8
)MAX_IE_LEN
);
2173 if (tmp_htinfo_len
){
2174 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_IEEE
;
2175 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
)?\
2176 sizeof(network
->bssht
.bdHTInfoBuf
):tmp_htinfo_len
;
2177 memcpy(network
->bssht
.bdHTInfoBuf
,info_element
->data
,network
->bssht
.bdHTInfoLen
);
2181 case MFIE_TYPE_AIRONET
:
2182 RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2184 if (info_element
->len
>IE_CISCO_FLAG_POSITION
)
2186 network
->bWithAironetIE
= true;
2188 if ( (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_MIC
) ||
2189 (info_element
->data
[IE_CISCO_FLAG_POSITION
]&SUPPORT_CKIP_PK
) )
2191 network
->bCkipSupported
= true;
2195 network
->bCkipSupported
= false;
2200 network
->bWithAironetIE
= false;
2201 network
->bCkipSupported
= false;
2204 case MFIE_TYPE_QOS_PARAMETER
:
2206 "QoS Error need to parse QOS_PARAMETER IE\n");
2209 case MFIE_TYPE_COUNTRY
:
2210 RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2212 rtllib_extract_country_ie(ieee
, info_element
, network
, network
->bssid
);
2217 ("Unsupported info element: %s (%d)\n",
2218 get_info_element_string(info_element
->id
),
2223 length
-= sizeof(*info_element
) + info_element
->len
;
2225 (struct rtllib_info_element
*)&info_element
->
2226 data
[info_element
->len
];
2229 if (!network
->atheros_cap_exist
&& !network
->broadcom_cap_exist
&&
2230 !network
->cisco_cap_exist
&& !network
->ralink_cap_exist
&& !network
->bssht
.bdRT2RTAggregation
)
2232 network
->unknown_cap_exist
= true;
2236 network
->unknown_cap_exist
= false;
2241 static inline u8
rtllib_SignalStrengthTranslate(
2247 if (CurrSS
>= 71 && CurrSS
<= 100)
2249 RetSS
= 90 + ((CurrSS
- 70) / 3);
2251 else if (CurrSS
>= 41 && CurrSS
<= 70)
2253 RetSS
= 78 + ((CurrSS
- 40) / 3);
2255 else if (CurrSS
>= 31 && CurrSS
<= 40)
2257 RetSS
= 66 + (CurrSS
- 30);
2259 else if (CurrSS
>= 21 && CurrSS
<= 30)
2261 RetSS
= 54 + (CurrSS
- 20);
2263 else if (CurrSS
>= 5 && CurrSS
<= 20)
2265 RetSS
= 42 + (((CurrSS
- 5) * 2) / 3);
2267 else if (CurrSS
== 4)
2271 else if (CurrSS
== 3)
2275 else if (CurrSS
== 2)
2279 else if (CurrSS
== 1)
2293 long rtllib_translate_todbm(u8 signal_strength_index
)
2297 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
2300 return signal_power
;
2303 static inline int rtllib_network_init(
2304 struct rtllib_device
*ieee
,
2305 struct rtllib_probe_response
*beacon
,
2306 struct rtllib_network
*network
,
2307 struct rtllib_rx_stats
*stats
)
2311 network->qos_data.active = 0;
2312 network->qos_data.supported = 0;
2313 network->qos_data.param_count = 0;
2314 network->qos_data.old_param_count = 0;
2316 memset(&network
->qos_data
, 0, sizeof(struct rtllib_qos_data
));
2318 /* Pull out fixed field data */
2319 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
2320 network
->capability
= le16_to_cpu(beacon
->capability
);
2321 network
->last_scanned
= jiffies
;
2322 network
->time_stamp
[0] = le32_to_cpu(beacon
->time_stamp
[0]);
2323 network
->time_stamp
[1] = le32_to_cpu(beacon
->time_stamp
[1]);
2324 network
->beacon_interval
= le32_to_cpu(beacon
->beacon_interval
);
2325 /* Where to pull this? beacon->listen_interval;*/
2326 network
->listen_interval
= 0x0A;
2327 network
->rates_len
= network
->rates_ex_len
= 0;
2328 network
->last_associate
= 0;
2329 network
->ssid_len
= 0;
2330 network
->hidden_ssid_len
= 0;
2331 memset(network
->hidden_ssid
, 0, sizeof(network
->hidden_ssid
));
2333 network
->atim_window
= 0;
2334 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
2336 network
->berp_info_valid
= false;
2337 network
->broadcom_cap_exist
= false;
2338 network
->ralink_cap_exist
= false;
2339 network
->atheros_cap_exist
= false;
2340 network
->cisco_cap_exist
= false;
2341 network
->unknown_cap_exist
= false;
2342 network
->realtek_cap_exit
= false;
2343 network
->marvell_cap_exist
= false;
2344 network
->airgo_cap_exist
= false;
2345 network
->Turbo_Enable
= 0;
2346 network
->SignalStrength
= stats
->SignalStrength
;
2347 network
->RSSI
= stats
->SignalStrength
;
2348 network
->CountryIeLen
= 0;
2349 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
2350 HTInitializeBssDesc(&network
->bssht
);
2351 if (stats
->freq
== RTLLIB_52GHZ_BAND
) {
2352 /* for A band (No DS info) */
2353 network
->channel
= stats
->received_channel
;
2355 network
->flags
|= NETWORK_HAS_CCK
;
2357 network
->wpa_ie_len
= 0;
2358 network
->rsn_ie_len
= 0;
2359 network
->wzc_ie_len
= 0;
2361 if (rtllib_parse_info_param(ieee
,
2362 beacon
->info_element
,
2363 (stats
->len
- sizeof(*beacon
)),
2369 if (stats
->freq
== RTLLIB_52GHZ_BAND
)
2370 network
->mode
= IEEE_A
;
2372 if (network
->flags
& NETWORK_HAS_OFDM
)
2373 network
->mode
|= IEEE_G
;
2374 if (network
->flags
& NETWORK_HAS_CCK
)
2375 network
->mode
|= IEEE_B
;
2378 if (network
->mode
== 0) {
2379 RTLLIB_DEBUG_SCAN("Filtered out '%s (" MAC_FMT
")' "
2381 escape_essid(network
->ssid
,
2383 MAC_ARG(network
->bssid
));
2387 if (network
->bssht
.bdSupportHT
){
2388 if (network
->mode
== IEEE_A
)
2389 network
->mode
= IEEE_N_5G
;
2390 else if (network
->mode
& (IEEE_G
| IEEE_B
))
2391 network
->mode
= IEEE_N_24G
;
2393 if (rtllib_is_empty_essid(network
->ssid
, network
->ssid_len
))
2394 network
->flags
|= NETWORK_EMPTY_ESSID
;
2395 stats
->signal
= 30 + (stats
->SignalStrength
* 70) / 100;
2396 stats
->noise
= rtllib_translate_todbm((u8
)(100-stats
->signal
)) -25;
2398 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
2403 static inline int is_same_network(struct rtllib_network
*src
,
2404 struct rtllib_network
*dst
, u8 ssidbroad
)
2406 /* A network is only a duplicate if the channel, BSSID, ESSID
2407 * and the capability field (in particular IBSS and BSS) all match.
2408 * We treat all <hidden> with the same BSSID and channel
2411 (((src
->ssid_len
== dst
->ssid_len
) || (!ssidbroad
)) &&
2412 (src
->channel
== dst
->channel
) &&
2413 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
2414 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) || (!ssidbroad
)) &&
2415 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
2416 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
2417 ((src
->capability
& WLAN_CAPABILITY_ESS
) ==
2418 (dst
->capability
& WLAN_CAPABILITY_ESS
)));
2421 static inline void update_ibss_network(struct rtllib_network
*dst
,
2422 struct rtllib_network
*src
)
2424 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct rtllib_rx_stats
));
2425 dst
->last_scanned
= jiffies
;
2429 static inline void update_network(struct rtllib_network
*dst
,
2430 struct rtllib_network
*src
)
2435 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct rtllib_rx_stats
));
2436 dst
->capability
= src
->capability
;
2437 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
2438 dst
->rates_len
= src
->rates_len
;
2439 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
2440 dst
->rates_ex_len
= src
->rates_ex_len
;
2441 if (src
->ssid_len
> 0)
2443 if (dst
->ssid_len
== 0)
2445 memset(dst
->hidden_ssid
, 0, sizeof(dst
->hidden_ssid
));
2446 dst
->hidden_ssid_len
= src
->ssid_len
;
2447 memcpy(dst
->hidden_ssid
, src
->ssid
, src
->ssid_len
);
2449 memset(dst
->ssid
, 0, dst
->ssid_len
);
2450 dst
->ssid_len
= src
->ssid_len
;
2451 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
2454 dst
->mode
= src
->mode
;
2455 dst
->flags
= src
->flags
;
2456 dst
->time_stamp
[0] = src
->time_stamp
[0];
2457 dst
->time_stamp
[1] = src
->time_stamp
[1];
2458 if (src
->flags
& NETWORK_HAS_ERP_VALUE
)
2460 dst
->erp_value
= src
->erp_value
;
2461 dst
->berp_info_valid
= src
->berp_info_valid
= true;
2463 dst
->beacon_interval
= src
->beacon_interval
;
2464 dst
->listen_interval
= src
->listen_interval
;
2465 dst
->atim_window
= src
->atim_window
;
2466 dst
->dtim_period
= src
->dtim_period
;
2467 dst
->dtim_data
= src
->dtim_data
;
2468 dst
->last_dtim_sta_time
= src
->last_dtim_sta_time
;
2469 memcpy(&dst
->tim
, &src
->tim
, sizeof(struct rtllib_tim_parameters
));
2471 dst
->bssht
.bdSupportHT
= src
->bssht
.bdSupportHT
;
2472 dst
->bssht
.bdRT2RTAggregation
= src
->bssht
.bdRT2RTAggregation
;
2473 dst
->bssht
.bdHTCapLen
= src
->bssht
.bdHTCapLen
;
2474 memcpy(dst
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapBuf
,src
->bssht
.bdHTCapLen
);
2475 dst
->bssht
.bdHTInfoLen
= src
->bssht
.bdHTInfoLen
;
2476 memcpy(dst
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoBuf
,src
->bssht
.bdHTInfoLen
);
2477 dst
->bssht
.bdHTSpecVer
= src
->bssht
.bdHTSpecVer
;
2478 dst
->bssht
.bdRT2RTLongSlotTime
= src
->bssht
.bdRT2RTLongSlotTime
;
2479 dst
->broadcom_cap_exist
= src
->broadcom_cap_exist
;
2480 dst
->ralink_cap_exist
= src
->ralink_cap_exist
;
2481 dst
->atheros_cap_exist
= src
->atheros_cap_exist
;
2482 dst
->realtek_cap_exit
= src
->realtek_cap_exit
;
2483 dst
->marvell_cap_exist
= src
->marvell_cap_exist
;
2484 dst
->cisco_cap_exist
= src
->cisco_cap_exist
;
2485 dst
->airgo_cap_exist
= src
->airgo_cap_exist
;
2486 dst
->unknown_cap_exist
= src
->unknown_cap_exist
;
2487 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
2488 dst
->wpa_ie_len
= src
->wpa_ie_len
;
2489 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
2490 dst
->rsn_ie_len
= src
->rsn_ie_len
;
2491 memcpy(dst
->wzc_ie
, src
->wzc_ie
, src
->wzc_ie_len
);
2492 dst
->wzc_ie_len
= src
->wzc_ie_len
;
2494 dst
->last_scanned
= jiffies
;
2495 /* qos related parameters */
2496 qos_active
= dst
->qos_data
.active
;
2497 old_param
= dst
->qos_data
.param_count
;
2498 dst
->qos_data
.supported
= src
->qos_data
.supported
;
2499 if (dst
->flags
& NETWORK_HAS_QOS_PARAMETERS
)
2500 memcpy(&dst
->qos_data
, &src
->qos_data
, sizeof(struct rtllib_qos_data
));
2501 if (dst
->qos_data
.supported
== 1) {
2504 ("QoS the network %s is QoS supported\n",
2508 ("QoS the network is QoS supported\n");
2510 dst
->qos_data
.active
= qos_active
;
2511 dst
->qos_data
.old_param_count
= old_param
;
2513 /* dst->last_associate is not overwritten */
2514 dst
->wmm_info
= src
->wmm_info
;
2515 if (src
->wmm_param
[0].ac_aci_acm_aifsn
|| \
2516 src
->wmm_param
[1].ac_aci_acm_aifsn
|| \
2517 src
->wmm_param
[2].ac_aci_acm_aifsn
|| \
2518 src
->wmm_param
[1].ac_aci_acm_aifsn
) {
2519 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
2522 dst
->SignalStrength
= src
->SignalStrength
;
2523 dst
->RSSI
= src
->RSSI
;
2524 dst
->Turbo_Enable
= src
->Turbo_Enable
;
2526 dst
->CountryIeLen
= src
->CountryIeLen
;
2527 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
2529 dst
->bWithAironetIE
= src
->bWithAironetIE
;
2530 dst
->bCkipSupported
= src
->bCkipSupported
;
2531 memcpy(dst
->CcxRmState
,src
->CcxRmState
,2);
2532 dst
->bCcxRmEnable
= src
->bCcxRmEnable
;
2533 dst
->MBssidMask
= src
->MBssidMask
;
2534 dst
->bMBssidValid
= src
->bMBssidValid
;
2535 memcpy(dst
->MBssid
,src
->MBssid
,6);
2536 dst
->bWithCcxVerNum
= src
->bWithCcxVerNum
;
2537 dst
->BssCcxVerNumber
= src
->BssCcxVerNumber
;
2540 static inline int is_beacon(__le16 fc
)
2542 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == RTLLIB_STYPE_BEACON
);
2545 static int IsPassiveChannel( struct rtllib_device
*rtllib
, u8 channel
)
2547 if (MAX_CHANNEL_NUMBER
< channel
) {
2548 printk("%s(): Invalid Channel\n", __func__
);
2552 if (rtllib
->active_channel_map
[channel
] == 2)
2558 int IsLegalChannel( struct rtllib_device
*rtllib
, u8 channel
)
2560 if (MAX_CHANNEL_NUMBER
< channel
) {
2561 printk("%s(): Invalid Channel\n", __func__
);
2564 if (rtllib
->active_channel_map
[channel
] > 0)
2571 static inline void rtllib_process_probe_response(
2572 struct rtllib_device
*ieee
,
2573 struct rtllib_probe_response
*beacon
,
2574 struct rtllib_rx_stats
*stats
)
2576 struct rtllib_network
*target
;
2577 struct rtllib_network
*oldest
= NULL
;
2578 struct rtllib_info_element
*info_element
= &beacon
->info_element
[0];
2579 unsigned long flags
;
2581 struct rtllib_network
*network
= kzalloc(sizeof(struct rtllib_network
), GFP_ATOMIC
);
2587 "'%s' (" MAC_FMT
"): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2588 escape_essid(info_element
->data
, info_element
->len
),
2589 MAC_ARG(beacon
->header
.addr3
),
2590 (beacon
->capability
& (1<<0xf)) ? '1' : '0',
2591 (beacon
->capability
& (1<<0xe)) ? '1' : '0',
2592 (beacon
->capability
& (1<<0xd)) ? '1' : '0',
2593 (beacon
->capability
& (1<<0xc)) ? '1' : '0',
2594 (beacon
->capability
& (1<<0xb)) ? '1' : '0',
2595 (beacon
->capability
& (1<<0xa)) ? '1' : '0',
2596 (beacon
->capability
& (1<<0x9)) ? '1' : '0',
2597 (beacon
->capability
& (1<<0x8)) ? '1' : '0',
2598 (beacon
->capability
& (1<<0x7)) ? '1' : '0',
2599 (beacon
->capability
& (1<<0x6)) ? '1' : '0',
2600 (beacon
->capability
& (1<<0x5)) ? '1' : '0',
2601 (beacon
->capability
& (1<<0x4)) ? '1' : '0',
2602 (beacon
->capability
& (1<<0x3)) ? '1' : '0',
2603 (beacon
->capability
& (1<<0x2)) ? '1' : '0',
2604 (beacon
->capability
& (1<<0x1)) ? '1' : '0',
2605 (beacon
->capability
& (1<<0x0)) ? '1' : '0');
2607 if (rtllib_network_init(ieee
, beacon
, network
, stats
)) {
2608 RTLLIB_DEBUG_SCAN("Dropped '%s' (" MAC_FMT
") via %s.\n",
2609 escape_essid(info_element
->data
,
2611 MAC_ARG(beacon
->header
.addr3
),
2612 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2613 RTLLIB_STYPE_PROBE_RESP
?
2614 "PROBE RESPONSE" : "BEACON");
2619 if (!IsLegalChannel(ieee
, network
->channel
))
2622 if (WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) == RTLLIB_STYPE_PROBE_RESP
) {
2623 if (IsPassiveChannel(ieee
, network
->channel
)) {
2624 printk("GetScanInfo(): For Global Domain, "
2625 "filter probe response at channel(%d).\n", network
->channel
);
2630 /* The network parsed correctly -- so now we scan our known networks
2631 * to see if we can find it in our list.
2633 * NOTE: This search is definitely not optimized. Once its doing
2634 * the "right thing" we'll optimize it for efficiency if
2637 /* Search for this entry in the list and update it if it is
2640 spin_lock_irqsave(&ieee
->lock
, flags
);
2642 if (is_same_network(&ieee
->current_network
, network
, (network
->ssid_len
?1:0))) {
2643 update_network(&ieee
->current_network
, network
);
2644 if ((ieee
->current_network
.mode
== IEEE_N_24G
|| ieee
->current_network
.mode
== IEEE_G
)
2645 && ieee
->current_network
.berp_info_valid
){
2646 if (ieee
->current_network
.erp_value
& ERP_UseProtection
)
2647 ieee
->current_network
.buseprotection
= true;
2649 ieee
->current_network
.buseprotection
= false;
2651 if (is_beacon(beacon
->header
.frame_ctl
))
2653 if (ieee
->state
>= RTLLIB_LINKED
)
2654 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
++;
2658 list_for_each_entry(target
, &ieee
->network_list
, list
) {
2659 if (is_same_network(target
, network
,(target
->ssid_len
?1:0)))
2661 if ((oldest
== NULL
) ||
2662 (target
->last_scanned
< oldest
->last_scanned
))
2666 /* If we didn't find a match, then get a new network slot to initialize
2667 * with this beacon's information */
2668 if (&target
->list
== &ieee
->network_list
) {
2669 if (list_empty(&ieee
->network_free_list
)) {
2670 /* If there are no more slots, expire the oldest */
2671 list_del(&oldest
->list
);
2673 RTLLIB_DEBUG_SCAN("Expired '%s' (" MAC_FMT
") from "
2675 escape_essid(target
->ssid
,
2677 MAC_ARG(target
->bssid
));
2679 /* Otherwise just pull from the free list */
2680 target
= list_entry(ieee
->network_free_list
.next
,
2681 struct rtllib_network
, list
);
2682 list_del(ieee
->network_free_list
.next
);
2686 RTLLIB_DEBUG_SCAN("Adding '%s' (" MAC_FMT
") via %s.\n",
2687 escape_essid(network
->ssid
,
2689 MAC_ARG(network
->bssid
),
2690 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2691 RTLLIB_STYPE_PROBE_RESP
?
2692 "PROBE RESPONSE" : "BEACON");
2693 memcpy(target
, network
, sizeof(*target
));
2694 list_add_tail(&target
->list
, &ieee
->network_list
);
2695 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
)
2696 rtllib_softmac_new_net(ieee
, network
);
2698 RTLLIB_DEBUG_SCAN("Updating '%s' (" MAC_FMT
") via %s.\n",
2699 escape_essid(target
->ssid
,
2701 MAC_ARG(target
->bssid
),
2702 WLAN_FC_GET_STYPE(beacon
->header
.frame_ctl
) ==
2703 RTLLIB_STYPE_PROBE_RESP
?
2704 "PROBE RESPONSE" : "BEACON");
2706 /* we have an entry and we are going to update it. But this entry may
2707 * be already expired. In this case we do the same as we found a new
2708 * net and call the new_net handler
2710 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
);
2711 if ((!target
->ssid_len
) &&
2712 (((network
->ssid_len
> 0) && (target
->hidden_ssid_len
== 0))
2713 || ((ieee
->current_network
.ssid_len
== network
->ssid_len
) &&
2714 (strncmp(ieee
->current_network
.ssid
, network
->ssid
, network
->ssid_len
) == 0) &&
2715 (ieee
->state
== RTLLIB_NOLINK
)))
2719 update_network(target
, network
);
2720 if (renew
&& (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
))
2721 rtllib_softmac_new_net(ieee
, network
);
2724 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2725 if (is_beacon(beacon
->header
.frame_ctl
)&&is_same_network(&ieee
->current_network
, network
, (network
->ssid_len
?1:0))&&\
2726 (ieee
->state
== RTLLIB_LINKED
)) {
2727 if (ieee
->handle_beacon
!= NULL
) {
2728 ieee
->handle_beacon(ieee
->dev
,beacon
,&ieee
->current_network
);
2736 void rtllib_rx_mgt(struct rtllib_device
*ieee
,
2737 struct sk_buff
*skb
,
2738 struct rtllib_rx_stats
*stats
)
2740 struct rtllib_hdr_4addr
*header
= (struct rtllib_hdr_4addr
*)skb
->data
;
2741 if (WLAN_FC_GET_STYPE(header
->frame_ctl
) != RTLLIB_STYPE_PROBE_RESP
&&
2742 WLAN_FC_GET_STYPE(header
->frame_ctl
) != RTLLIB_STYPE_BEACON
)
2743 ieee
->last_rx_ps_time
= jiffies
;
2745 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
2747 case RTLLIB_STYPE_BEACON
:
2748 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
2749 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2750 RTLLIB_DEBUG_SCAN("Beacon\n");
2751 rtllib_process_probe_response(
2752 ieee
, (struct rtllib_probe_response
*)header
, stats
);
2754 if (ieee
->sta_sleep
|| (ieee
->ps
!= RTLLIB_PS_DISABLED
&&
2755 ieee
->iw_mode
== IW_MODE_INFRA
&&
2756 ieee
->state
== RTLLIB_LINKED
))
2757 tasklet_schedule(&ieee
->ps_task
);
2761 case RTLLIB_STYPE_PROBE_RESP
:
2762 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2763 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2764 RTLLIB_DEBUG_SCAN("Probe response\n");
2765 rtllib_process_probe_response(
2766 ieee
, (struct rtllib_probe_response
*)header
, stats
);
2768 case RTLLIB_STYPE_PROBE_REQ
:
2769 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
2770 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2771 RTLLIB_DEBUG_SCAN("Probe request\n");
2772 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
2773 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
2774 ieee
->iw_mode
== IW_MODE_MASTER
) &&
2775 ieee
->state
== RTLLIB_LINKED
)){
2776 rtllib_rx_probe_rq(ieee
, skb
);