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 <andrea.merello@gmail.com>
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/wireless.h>
40 #include <linux/etherdevice.h>
41 #include <linux/uaccess.h>
42 #include <linux/ctype.h>
47 static inline void rtllib_monitor_rx(struct rtllib_device
*ieee
,
48 struct sk_buff
*skb
, struct rtllib_rx_stats
*rx_status
,
52 skb_reset_mac_header(skb
);
53 skb_pull(skb
, hdr_length
);
54 skb
->pkt_type
= PACKET_OTHERHOST
;
55 skb
->protocol
= htons(ETH_P_80211_RAW
);
56 memset(skb
->cb
, 0, sizeof(skb
->cb
));
60 /* Called only as a tasklet (software IRQ) */
61 static struct rtllib_frag_entry
*
62 rtllib_frag_cache_find(struct rtllib_device
*ieee
, unsigned int seq
,
63 unsigned int frag
, u8 tid
, u8
*src
, u8
*dst
)
65 struct rtllib_frag_entry
*entry
;
68 for (i
= 0; i
< RTLLIB_FRAG_CACHE_LEN
; i
++) {
69 entry
= &ieee
->frag_cache
[tid
][i
];
70 if (entry
->skb
!= NULL
&&
71 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
73 "expiring fragment cache entry seq=%u last_frag=%u\n",
74 entry
->seq
, entry
->last_frag
);
75 dev_kfree_skb_any(entry
->skb
);
79 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
80 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
81 memcmp(entry
->src_addr
, src
, ETH_ALEN
) == 0 &&
82 memcmp(entry
->dst_addr
, dst
, ETH_ALEN
) == 0)
89 /* Called only as a tasklet (software IRQ) */
90 static struct sk_buff
*
91 rtllib_frag_cache_get(struct rtllib_device
*ieee
,
92 struct rtllib_hdr_4addr
*hdr
)
94 struct sk_buff
*skb
= NULL
;
95 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
96 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
97 unsigned int frag
= WLAN_GET_SEQ_FRAG(sc
);
98 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
99 struct rtllib_frag_entry
*entry
;
100 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
101 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
104 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
) && RTLLIB_QOS_HAS_SEQ(fc
)) {
105 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)hdr
;
106 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
109 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
110 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)hdr
;
111 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
119 /* Reserve enough space to fit maximum frame length */
120 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
121 sizeof(struct rtllib_hdr_4addr
) +
126 (RTLLIB_QOS_HAS_SEQ(fc
) ? 2 : 0) /* QOS Control */);
130 entry
= &ieee
->frag_cache
[tid
][ieee
->frag_next_idx
[tid
]];
131 ieee
->frag_next_idx
[tid
]++;
132 if (ieee
->frag_next_idx
[tid
] >= RTLLIB_FRAG_CACHE_LEN
)
133 ieee
->frag_next_idx
[tid
] = 0;
135 if (entry
->skb
!= NULL
)
136 dev_kfree_skb_any(entry
->skb
);
138 entry
->first_frag_time
= jiffies
;
140 entry
->last_frag
= frag
;
142 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
143 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
145 /* received a fragment of a frame for which the head fragment
146 * should have already been received */
147 entry
= rtllib_frag_cache_find(ieee
, seq
, frag
, tid
, hdr
->addr2
,
150 entry
->last_frag
= frag
;
159 /* Called only as a tasklet (software IRQ) */
160 static int rtllib_frag_cache_invalidate(struct rtllib_device
*ieee
,
161 struct rtllib_hdr_4addr
*hdr
)
163 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
164 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
165 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
166 struct rtllib_frag_entry
*entry
;
167 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
168 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
171 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
) && RTLLIB_QOS_HAS_SEQ(fc
)) {
172 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)hdr
;
173 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
176 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
177 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)hdr
;
178 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
185 entry
= rtllib_frag_cache_find(ieee
, seq
, -1, tid
, hdr
->addr2
,
190 "could not invalidate fragment cache entry (seq=%u)\n", seq
);
198 /* rtllib_rx_frame_mgtmt
200 * Responsible for handling management control frames
202 * Called by rtllib_rx */
204 rtllib_rx_frame_mgmt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
205 struct rtllib_rx_stats
*rx_stats
, u16 type
,
208 /* On the struct stats definition there is written that
209 * this is not mandatory.... but seems that the probe
210 * response parser uses it
212 struct rtllib_hdr_3addr
*hdr
= (struct rtllib_hdr_3addr
*)skb
->data
;
214 rx_stats
->len
= skb
->len
;
215 rtllib_rx_mgt(ieee
, skb
, rx_stats
);
216 if ((memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
))) {
217 dev_kfree_skb_any(skb
);
220 rtllib_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
222 dev_kfree_skb_any(skb
);
227 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
228 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
229 static unsigned char rfc1042_header
[] = {
230 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
232 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
233 static unsigned char bridge_tunnel_header
[] = {
234 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
236 /* No encapsulation header if EtherType < 0x600 (=length) */
238 /* Called by rtllib_rx_frame_decrypt */
239 static int rtllib_is_eapol_frame(struct rtllib_device
*ieee
,
240 struct sk_buff
*skb
, size_t hdrlen
)
242 struct net_device
*dev
= ieee
->dev
;
244 struct rtllib_hdr_4addr
*hdr
;
250 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
251 fc
= le16_to_cpu(hdr
->frame_ctl
);
253 /* check that the frame is unicast frame to us */
254 if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
256 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
257 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
258 /* ToDS frame with own addr BSSID and DA */
259 } else if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
260 RTLLIB_FCTL_FROMDS
&&
261 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
262 /* FromDS frame with own addr as DA */
266 if (skb
->len
< 24 + 8)
269 /* check for port access entity Ethernet type */
270 pos
= skb
->data
+ hdrlen
;
271 ethertype
= (pos
[6] << 8) | pos
[7];
272 if (ethertype
== ETH_P_PAE
)
278 /* Called only as a tasklet (software IRQ), by rtllib_rx */
280 rtllib_rx_frame_decrypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
281 struct lib80211_crypt_data
*crypt
)
283 struct rtllib_hdr_4addr
*hdr
;
286 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
289 if (ieee
->hwsec_active
) {
290 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
292 tcb_desc
->bHwSec
= 1;
294 if (ieee
->need_sw_enc
)
295 tcb_desc
->bHwSec
= 0;
298 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
299 hdrlen
= rtllib_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
301 atomic_inc(&crypt
->refcnt
);
302 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
303 atomic_dec(&crypt
->refcnt
);
306 "decryption failed (SA= %pM) res=%d\n", hdr
->addr2
, res
);
308 RTLLIB_DEBUG_DROP("Decryption failed ICV mismatch (key %d)\n",
309 skb
->data
[hdrlen
+ 3] >> 6);
310 ieee
->ieee_stats
.rx_discards_undecryptable
++;
318 /* Called only as a tasklet (software IRQ), by rtllib_rx */
320 rtllib_rx_frame_decrypt_msdu(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
321 int keyidx
, struct lib80211_crypt_data
*crypt
)
323 struct rtllib_hdr_4addr
*hdr
;
326 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
328 if (ieee
->hwsec_active
) {
329 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
331 tcb_desc
->bHwSec
= 1;
333 if (ieee
->need_sw_enc
)
334 tcb_desc
->bHwSec
= 0;
337 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
338 hdrlen
= rtllib_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
340 atomic_inc(&crypt
->refcnt
);
341 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
342 atomic_dec(&crypt
->refcnt
);
344 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed (SA= %pM keyidx=%d)\n",
345 ieee
->dev
->name
, hdr
->addr2
, keyidx
);
353 /* this function is stolen from ipw2200 driver*/
354 #define IEEE_PACKET_RETRY_TIME (5*HZ)
355 static int is_duplicate_packet(struct rtllib_device
*ieee
,
356 struct rtllib_hdr_4addr
*header
)
358 u16 fc
= le16_to_cpu(header
->frame_ctl
);
359 u16 sc
= le16_to_cpu(header
->seq_ctl
);
360 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
361 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
362 u16
*last_seq
, *last_frag
;
363 unsigned long *last_time
;
364 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
365 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
368 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
) && RTLLIB_QOS_HAS_SEQ(fc
)) {
369 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)header
;
370 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
373 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
374 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)header
;
375 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
382 switch (ieee
->iw_mode
) {
386 struct ieee_ibss_seq
*entry
= NULL
;
387 u8
*mac
= header
->addr2
;
388 int index
= mac
[5] % IEEE_IBSS_MAC_HASH_SIZE
;
390 list_for_each(p
, &ieee
->ibss_mac_hash
[index
]) {
391 entry
= list_entry(p
, struct ieee_ibss_seq
, list
);
392 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
395 if (p
== &ieee
->ibss_mac_hash
[index
]) {
396 entry
= kmalloc(sizeof(struct ieee_ibss_seq
), GFP_ATOMIC
);
398 printk(KERN_WARNING
"Cannot malloc new mac entry\n");
401 memcpy(entry
->mac
, mac
, ETH_ALEN
);
402 entry
->seq_num
[tid
] = seq
;
403 entry
->frag_num
[tid
] = frag
;
404 entry
->packet_time
[tid
] = jiffies
;
405 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
408 last_seq
= &entry
->seq_num
[tid
];
409 last_frag
= &entry
->frag_num
[tid
];
410 last_time
= &entry
->packet_time
[tid
];
415 last_seq
= &ieee
->last_rxseq_num
[tid
];
416 last_frag
= &ieee
->last_rxfrag_num
[tid
];
417 last_time
= &ieee
->last_packet_time
[tid
];
423 if ((*last_seq
== seq
) &&
424 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
425 if (*last_frag
== frag
)
427 if (*last_frag
+ 1 != frag
)
428 /* out-of-order fragment */
434 *last_time
= jiffies
;
442 static bool AddReorderEntry(struct rx_ts_record
*pTS
,
443 struct rx_reorder_entry
*pReorderEntry
)
445 struct list_head
*pList
= &pTS
->RxPendingPktList
;
447 while (pList
->next
!= &pTS
->RxPendingPktList
) {
448 if (SN_LESS(pReorderEntry
->SeqNum
, ((struct rx_reorder_entry
*)
449 list_entry(pList
->next
, struct rx_reorder_entry
,
452 else if (SN_EQUAL(pReorderEntry
->SeqNum
,
453 ((struct rx_reorder_entry
*)list_entry(pList
->next
,
454 struct rx_reorder_entry
, List
))->SeqNum
))
459 pReorderEntry
->List
.next
= pList
->next
;
460 pReorderEntry
->List
.next
->prev
= &pReorderEntry
->List
;
461 pReorderEntry
->List
.prev
= pList
;
462 pList
->next
= &pReorderEntry
->List
;
467 void rtllib_indicate_packets(struct rtllib_device
*ieee
, struct rtllib_rxb
**prxbIndicateArray
, u8 index
)
469 struct net_device_stats
*stats
= &ieee
->stats
;
473 for (j
= 0; j
< index
; j
++) {
474 struct rtllib_rxb
*prxb
= prxbIndicateArray
[j
];
476 for (i
= 0; i
< prxb
->nr_subframes
; i
++) {
477 struct sk_buff
*sub_skb
= prxb
->subframes
[i
];
479 /* convert hdr + possible LLC headers into Ethernet header */
480 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
481 if (sub_skb
->len
>= 8 &&
482 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
483 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
484 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
485 /* remove RFC1042 or Bridge-Tunnel encapsulation
486 * and replace EtherType */
487 skb_pull(sub_skb
, SNAP_SIZE
);
488 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
489 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
492 /* Leave Ethernet header part of hdr and full payload */
494 memcpy(skb_push(sub_skb
, 2), &len
, 2);
495 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
496 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
499 /* Indicate the packets to upper layer */
502 stats
->rx_bytes
+= sub_skb
->len
;
504 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
505 sub_skb
->protocol
= eth_type_trans(sub_skb
, ieee
->dev
);
506 sub_skb
->dev
= ieee
->dev
;
507 sub_skb
->dev
->stats
.rx_packets
++;
508 sub_skb
->dev
->stats
.rx_bytes
+= sub_skb
->len
;
509 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
510 ieee
->last_rx_ps_time
= jiffies
;
519 void rtllib_FlushRxTsPendingPkts(struct rtllib_device
*ieee
, struct rx_ts_record
*pTS
)
521 struct rx_reorder_entry
*pRxReorderEntry
;
524 del_timer_sync(&pTS
->RxPktPendingTimer
);
525 while (!list_empty(&pTS
->RxPendingPktList
)) {
526 if (RfdCnt
>= REORDER_WIN_SIZE
) {
527 printk(KERN_INFO
"-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n", __func__
);
531 pRxReorderEntry
= (struct rx_reorder_entry
*)list_entry(pTS
->RxPendingPktList
.prev
, struct rx_reorder_entry
, List
);
532 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Indicate SeqNum %d!\n", __func__
, pRxReorderEntry
->SeqNum
);
533 list_del_init(&pRxReorderEntry
->List
);
535 ieee
->RfdArray
[RfdCnt
] = pRxReorderEntry
->prxb
;
538 list_add_tail(&pRxReorderEntry
->List
, &ieee
->RxReorder_Unused_List
);
540 rtllib_indicate_packets(ieee
, ieee
->RfdArray
, RfdCnt
);
542 pTS
->RxIndicateSeq
= 0xffff;
545 static void RxReorderIndicatePacket(struct rtllib_device
*ieee
,
546 struct rtllib_rxb
*prxb
,
547 struct rx_ts_record
*pTS
, u16 SeqNum
)
549 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
550 struct rx_reorder_entry
*pReorderEntry
= NULL
;
551 u8 WinSize
= pHTInfo
->RxReorderWinSize
;
554 bool bMatchWinStart
= false, bPktInBuf
= false;
557 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Seq is %d, pTS->RxIndicateSeq is %d, WinSize is %d\n", __func__
, SeqNum
,
558 pTS
->RxIndicateSeq
, WinSize
);
560 spin_lock_irqsave(&(ieee
->reorder_spinlock
), flags
);
562 WinEnd
= (pTS
->RxIndicateSeq
+ WinSize
- 1) % 4096;
563 /* Rx Reorder initialize condition.*/
564 if (pTS
->RxIndicateSeq
== 0xffff)
565 pTS
->RxIndicateSeq
= SeqNum
;
567 /* Drop out the packet which SeqNum is smaller than WinStart */
568 if (SN_LESS(SeqNum
, pTS
->RxIndicateSeq
)) {
569 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
570 pTS
->RxIndicateSeq
, SeqNum
);
571 pHTInfo
->RxReorderDropCounter
++;
575 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
576 dev_kfree_skb(prxb
->subframes
[i
]);
580 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
585 * Sliding window manipulation. Conditions includes:
586 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
587 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
589 if (SN_EQUAL(SeqNum
, pTS
->RxIndicateSeq
)) {
590 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
591 bMatchWinStart
= true;
592 } else if (SN_LESS(WinEnd
, SeqNum
)) {
593 if (SeqNum
>= (WinSize
- 1))
594 pTS
->RxIndicateSeq
= SeqNum
+ 1 - WinSize
;
596 pTS
->RxIndicateSeq
= 4095 - (WinSize
- (SeqNum
+ 1)) + 1;
597 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Window Shift! IndicateSeq: %d, NewSeq: %d\n", pTS
->RxIndicateSeq
, SeqNum
);
601 * Indication process.
602 * After Packet dropping and Sliding Window shifting as above, we can
603 * now just indicate the packets with the SeqNum smaller than latest
604 * WinStart and struct buffer other packets.
606 /* For Rx Reorder condition:
607 * 1. All packets with SeqNum smaller than WinStart => Indicate
608 * 2. All packets with SeqNum larger than or equal to
609 * WinStart => Buffer it.
611 if (bMatchWinStart
) {
612 /* Current packet is going to be indicated.*/
613 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",
614 pTS
->RxIndicateSeq
, SeqNum
);
615 ieee
->prxbIndicateArray
[0] = prxb
;
618 /* Current packet is going to be inserted into pending list.*/
619 if (!list_empty(&ieee
->RxReorder_Unused_List
)) {
620 pReorderEntry
= (struct rx_reorder_entry
*)
621 list_entry(ieee
->RxReorder_Unused_List
.next
,
622 struct rx_reorder_entry
, List
);
623 list_del_init(&pReorderEntry
->List
);
625 /* Make a reorder entry and insert into a the packet list.*/
626 pReorderEntry
->SeqNum
= SeqNum
;
627 pReorderEntry
->prxb
= prxb
;
629 if (!AddReorderEntry(pTS
, pReorderEntry
)) {
630 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,
631 "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
632 __func__
, pTS
->RxIndicateSeq
,
634 list_add_tail(&pReorderEntry
->List
,
635 &ieee
->RxReorder_Unused_List
); {
638 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
639 dev_kfree_skb(prxb
->subframes
[i
]);
644 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,
645 "Pkt insert into struct buffer!! IndicateSeq: %d, NewSeq: %d\n",
646 pTS
->RxIndicateSeq
, SeqNum
);
650 * Packets are dropped if there are not enough reorder
651 * entries. This part should be modified!! We can just
652 * indicate all the packets in struct buffer and get
655 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
659 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
660 dev_kfree_skb(prxb
->subframes
[i
]);
667 /* Check if there is any packet need indicate.*/
668 while (!list_empty(&pTS
->RxPendingPktList
)) {
669 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): start RREORDER indicate\n", __func__
);
671 pReorderEntry
= (struct rx_reorder_entry
*)list_entry(pTS
->RxPendingPktList
.prev
,
672 struct rx_reorder_entry
, List
);
673 if (SN_LESS(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
) ||
674 SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
)) {
675 /* This protect struct buffer from overflow. */
676 if (index
>= REORDER_WIN_SIZE
) {
677 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket(): Buffer overflow!!\n");
682 list_del_init(&pReorderEntry
->List
);
684 if (SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
685 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
687 ieee
->prxbIndicateArray
[index
] = pReorderEntry
->prxb
;
688 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Indicate SeqNum %d!\n", __func__
, pReorderEntry
->SeqNum
);
691 list_add_tail(&pReorderEntry
->List
,
692 &ieee
->RxReorder_Unused_List
);
699 /* Handling pending timer. Set this timer to prevent from long time
702 if (timer_pending(&pTS
->RxPktPendingTimer
))
703 del_timer_sync(&pTS
->RxPktPendingTimer
);
704 pTS
->RxTimeoutIndicateSeq
= 0xffff;
706 if (index
> REORDER_WIN_SIZE
) {
707 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket(): Rx Reorder struct buffer full!!\n");
708 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
),
712 rtllib_indicate_packets(ieee
, ieee
->prxbIndicateArray
, index
);
716 if (bPktInBuf
&& pTS
->RxTimeoutIndicateSeq
== 0xffff) {
717 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): SET rx timeout timer\n",
719 pTS
->RxTimeoutIndicateSeq
= pTS
->RxIndicateSeq
;
720 mod_timer(&pTS
->RxPktPendingTimer
, jiffies
+
721 MSECS(pHTInfo
->RxReorderPendingTime
));
723 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
726 static u8
parse_subframe(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
727 struct rtllib_rx_stats
*rx_stats
,
728 struct rtllib_rxb
*rxb
, u8
*src
, u8
*dst
)
730 struct rtllib_hdr_3addr
*hdr
= (struct rtllib_hdr_3addr
*)skb
->data
;
731 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
733 u16 LLCOffset
= sizeof(struct rtllib_hdr_3addr
);
735 bool bIsAggregateFrame
= false;
736 u16 nSubframe_Length
;
737 u8 nPadding_Length
= 0;
739 struct sk_buff
*sub_skb
;
741 /* just for debug purpose */
742 SeqNum
= WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr
->seq_ctl
));
743 if ((RTLLIB_QOS_HAS_SEQ(fc
)) &&
744 (((union frameqos
*)(skb
->data
+ RTLLIB_3ADDR_LEN
))->field
.reserved
))
745 bIsAggregateFrame
= true;
747 if (RTLLIB_QOS_HAS_SEQ(fc
))
749 if (rx_stats
->bContainHTC
)
750 LLCOffset
+= sHTCLng
;
752 ChkLength
= LLCOffset
;
754 if (skb
->len
<= ChkLength
)
757 skb_pull(skb
, LLCOffset
);
758 ieee
->bIsAggregateFrame
= bIsAggregateFrame
;
759 if (!bIsAggregateFrame
) {
760 rxb
->nr_subframes
= 1;
762 /* altered by clark 3/30/2010
763 * The struct buffer size of the skb indicated to upper layer
764 * must be less than 5000, or the defraged IP datagram
765 * in the IP layer will exceed "ipfrag_high_tresh" and be
766 * discarded. so there must not use the function
767 * "skb_copy" and "skb_clone" for "skb".
770 /* Allocate new skb for releasing to upper layer */
771 sub_skb
= dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE
);
774 skb_reserve(sub_skb
, 12);
775 data_ptr
= (u8
*)skb_put(sub_skb
, skb
->len
);
776 memcpy(data_ptr
, skb
->data
, skb
->len
);
777 sub_skb
->dev
= ieee
->dev
;
779 rxb
->subframes
[0] = sub_skb
;
781 memcpy(rxb
->src
, src
, ETH_ALEN
);
782 memcpy(rxb
->dst
, dst
, ETH_ALEN
);
783 rxb
->subframes
[0]->dev
= ieee
->dev
;
786 rxb
->nr_subframes
= 0;
787 memcpy(rxb
->src
, src
, ETH_ALEN
);
788 memcpy(rxb
->dst
, dst
, ETH_ALEN
);
789 while (skb
->len
> ETHERNET_HEADER_SIZE
) {
790 /* Offset 12 denote 2 mac address */
791 nSubframe_Length
= *((u16
*)(skb
->data
+ 12));
792 nSubframe_Length
= (nSubframe_Length
>> 8) +
793 (nSubframe_Length
<< 8);
795 if (skb
->len
< (ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
796 printk(KERN_INFO
"%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
797 __func__
, rxb
->nr_subframes
);
798 printk(KERN_INFO
"%s: A-MSDU parse error!! Subframe Length: %d\n", __func__
,
800 printk(KERN_INFO
"nRemain_Length is %d and nSubframe_Length is : %d\n", skb
->len
,
802 printk(KERN_INFO
"The Packet SeqNum is %d\n", SeqNum
);
806 /* move the data point to data content */
807 skb_pull(skb
, ETHERNET_HEADER_SIZE
);
809 /* altered by clark 3/30/2010
810 * The struct buffer size of the skb indicated to upper layer
811 * must be less than 5000, or the defraged IP datagram
812 * in the IP layer will exceed "ipfrag_high_tresh" and be
813 * discarded. so there must not use the function
814 * "skb_copy" and "skb_clone" for "skb".
817 /* Allocate new skb for releasing to upper layer */
818 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
821 skb_reserve(sub_skb
, 12);
822 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
823 memcpy(data_ptr
, skb
->data
, nSubframe_Length
);
825 sub_skb
->dev
= ieee
->dev
;
826 rxb
->subframes
[rxb
->nr_subframes
++] = sub_skb
;
827 if (rxb
->nr_subframes
>= MAX_SUBFRAME_COUNT
) {
828 RTLLIB_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
831 skb_pull(skb
, nSubframe_Length
);
834 nPadding_Length
= 4 - ((nSubframe_Length
+
835 ETHERNET_HEADER_SIZE
) % 4);
836 if (nPadding_Length
== 4)
839 if (skb
->len
< nPadding_Length
)
842 skb_pull(skb
, nPadding_Length
);
846 return rxb
->nr_subframes
;
851 static size_t rtllib_rx_get_hdrlen(struct rtllib_device
*ieee
,
853 struct rtllib_rx_stats
*rx_stats
)
855 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
856 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
859 hdrlen
= rtllib_get_hdrlen(fc
);
860 if (HTCCheck(ieee
, skb
->data
)) {
862 printk(KERN_INFO
"%s: find HTCControl!\n", __func__
);
864 rx_stats
->bContainHTC
= true;
867 if (RTLLIB_QOS_HAS_SEQ(fc
))
868 rx_stats
->bIsQosData
= true;
873 static int rtllib_rx_check_duplicate(struct rtllib_device
*ieee
,
874 struct sk_buff
*skb
, u8 multicast
)
876 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
878 u8 frag
, type
, stype
;
880 fc
= le16_to_cpu(hdr
->frame_ctl
);
881 type
= WLAN_FC_GET_TYPE(fc
);
882 stype
= WLAN_FC_GET_STYPE(fc
);
883 sc
= le16_to_cpu(hdr
->seq_ctl
);
884 frag
= WLAN_GET_SEQ_FRAG(sc
);
886 if ((ieee
->pHTInfo
->bCurRxReorderEnable
== false) ||
887 !ieee
->current_network
.qos_data
.active
||
888 !IsDataFrame(skb
->data
) ||
889 IsLegacyDataFrame(skb
->data
)) {
890 if (!((type
== RTLLIB_FTYPE_MGMT
) && (stype
== RTLLIB_STYPE_BEACON
))) {
891 if (is_duplicate_packet(ieee
, hdr
))
895 struct rx_ts_record
*pRxTS
= NULL
;
897 if (GetTs(ieee
, (struct ts_common_info
**) &pRxTS
, hdr
->addr2
,
898 (u8
)Frame_QoSTID((u8
*)(skb
->data
)), RX_DIR
, true)) {
899 if ((fc
& (1<<11)) && (frag
== pRxTS
->RxLastFragNum
) &&
900 (WLAN_GET_SEQ_SEQ(sc
) == pRxTS
->RxLastSeqNum
))
902 pRxTS
->RxLastFragNum
= frag
;
903 pRxTS
->RxLastSeqNum
= WLAN_GET_SEQ_SEQ(sc
);
905 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "ERR!!%s(): No TS!! Skip the check!!\n", __func__
);
913 static void rtllib_rx_extract_addr(struct rtllib_device
*ieee
,
914 struct rtllib_hdr_4addr
*hdr
, u8
*dst
,
917 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
919 switch (fc
& (RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
)) {
920 case RTLLIB_FCTL_FROMDS
:
921 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
922 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
923 memcpy(bssid
, hdr
->addr2
, ETH_ALEN
);
925 case RTLLIB_FCTL_TODS
:
926 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
927 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
928 memcpy(bssid
, hdr
->addr1
, ETH_ALEN
);
930 case RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
:
931 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
932 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
933 memcpy(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
936 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
937 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
938 memcpy(bssid
, hdr
->addr3
, ETH_ALEN
);
943 static int rtllib_rx_data_filter(struct rtllib_device
*ieee
, u16 fc
,
944 u8
*dst
, u8
*src
, u8
*bssid
, u8
*addr2
)
948 type
= WLAN_FC_GET_TYPE(fc
);
949 stype
= WLAN_FC_GET_STYPE(fc
);
951 /* Filter frames from different BSS */
952 if (((fc
& RTLLIB_FCTL_DSTODS
) != RTLLIB_FCTL_DSTODS
) &&
953 !ether_addr_equal(ieee
->current_network
.bssid
, bssid
) &&
954 !is_zero_ether_addr(ieee
->current_network
.bssid
)) {
958 /* Filter packets sent by an STA that will be forwarded by AP */
959 if (ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
&&
960 ieee
->IntelPromiscuousModeInfo
.bFilterSourceStationFrame
) {
961 if ((fc
& RTLLIB_FCTL_TODS
) && !(fc
& RTLLIB_FCTL_FROMDS
) &&
962 !ether_addr_equal(dst
, ieee
->current_network
.bssid
) &&
963 ether_addr_equal(bssid
, ieee
->current_network
.bssid
)) {
968 /* Nullfunc frames may have PS-bit set, so they must be passed to
969 * hostap_handle_sta_rx() before being dropped here. */
970 if (!ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
) {
971 if (stype
!= RTLLIB_STYPE_DATA
&&
972 stype
!= RTLLIB_STYPE_DATA_CFACK
&&
973 stype
!= RTLLIB_STYPE_DATA_CFPOLL
&&
974 stype
!= RTLLIB_STYPE_DATA_CFACKPOLL
&&
975 stype
!= RTLLIB_STYPE_QOS_DATA
) {
976 if (stype
!= RTLLIB_STYPE_NULLFUNC
)
978 "RX: dropped data frame with no data (type=0x%02x, subtype=0x%02x)\n",
984 if (ieee
->iw_mode
!= IW_MODE_MESH
) {
985 /* packets from our adapter are dropped (echo) */
986 if (!memcmp(src
, ieee
->dev
->dev_addr
, ETH_ALEN
))
989 /* {broad,multi}cast packets to our BSS go through */
990 if (is_multicast_ether_addr(dst
)) {
991 if (memcmp(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
))
998 static int rtllib_rx_get_crypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
999 struct lib80211_crypt_data
**crypt
, size_t hdrlen
)
1001 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1002 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1005 if (ieee
->host_decrypt
) {
1006 if (skb
->len
>= hdrlen
+ 3)
1007 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1009 *crypt
= ieee
->crypt_info
.crypt
[idx
];
1010 /* allow NULL decrypt to indicate an station specific override
1011 * for default encryption */
1012 if (*crypt
&& ((*crypt
)->ops
== NULL
||
1013 (*crypt
)->ops
->decrypt_mpdu
== NULL
))
1016 if (!*crypt
&& (fc
& RTLLIB_FCTL_WEP
)) {
1017 /* This seems to be triggered by some (multicast?)
1018 * frames from other than current BSS, so just drop the
1019 * frames silently instead of filling system log with
1021 RTLLIB_DEBUG_DROP("Decryption failed (not set) (SA= %pM)\n",
1023 ieee
->ieee_stats
.rx_discards_undecryptable
++;
1031 static int rtllib_rx_decrypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1032 struct rtllib_rx_stats
*rx_stats
,
1033 struct lib80211_crypt_data
*crypt
, size_t hdrlen
)
1035 struct rtllib_hdr_4addr
*hdr
;
1040 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1041 fc
= le16_to_cpu(hdr
->frame_ctl
);
1042 sc
= le16_to_cpu(hdr
->seq_ctl
);
1043 frag
= WLAN_GET_SEQ_FRAG(sc
);
1045 if ((!rx_stats
->Decrypted
))
1046 ieee
->need_sw_enc
= 1;
1048 ieee
->need_sw_enc
= 0;
1050 keyidx
= rtllib_rx_frame_decrypt(ieee
, skb
, crypt
);
1051 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) && (keyidx
< 0)) {
1052 printk(KERN_INFO
"%s: decrypt frame error\n", __func__
);
1056 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1057 if ((frag
!= 0 || (fc
& RTLLIB_FCTL_MOREFRAGS
))) {
1059 struct sk_buff
*frag_skb
= rtllib_frag_cache_get(ieee
, hdr
);
1061 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
1064 RTLLIB_DEBUG(RTLLIB_DL_RX
| RTLLIB_DL_FRAG
,
1065 "Rx cannot get skb from fragment cache (morefrag=%d seq=%u frag=%u)\n",
1066 (fc
& RTLLIB_FCTL_MOREFRAGS
) != 0,
1067 WLAN_GET_SEQ_SEQ(sc
), frag
);
1074 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
1075 printk(KERN_WARNING
"%s: host decrypted and reassembled frame did not fit skb\n",
1077 rtllib_frag_cache_invalidate(ieee
, hdr
);
1082 /* copy first fragment (including full headers) into
1083 * beginning of the fragment cache skb */
1084 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
1086 /* append frame payload to the end of the fragment
1088 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
1091 dev_kfree_skb_any(skb
);
1094 if (fc
& RTLLIB_FCTL_MOREFRAGS
) {
1095 /* more fragments expected - leave the skb in fragment
1096 * cache for now; it will be delivered to upper layers
1097 * after all fragments have been received */
1101 /* this was the last fragment and the frame will be
1102 * delivered, so remove skb from fragment cache */
1104 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1105 rtllib_frag_cache_invalidate(ieee
, hdr
);
1108 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1109 * encrypted/authenticated */
1110 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) &&
1111 rtllib_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
)) {
1112 printk(KERN_INFO
"%s: ==>decrypt msdu error\n", __func__
);
1116 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1117 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
) {
1118 if (/*ieee->ieee802_1x &&*/
1119 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1121 /* pass unencrypted EAPOL frames even if encryption is
1123 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1125 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1126 eap_get_type(eap
->type
));
1129 "encryption configured, but RX frame not encrypted (SA= %pM)\n",
1135 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) &&
1136 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1137 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1139 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1140 eap_get_type(eap
->type
));
1143 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
&&
1144 !rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1146 "dropped unencrypted RX data frame from %pM (drop_unencrypted=1)\n",
1151 if (rtllib_is_eapol_frame(ieee
, skb
, hdrlen
))
1152 printk(KERN_WARNING
"RX: IEEE802.1X EAPOL frame!\n");
1157 static void rtllib_rx_check_leave_lps(struct rtllib_device
*ieee
, u8 unicast
, u8 nr_subframes
)
1161 if ((ieee
->state
== RTLLIB_LINKED
)) {
1162 if (((ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+
1163 ieee
->LinkDetectInfo
.NumTxOkInPeriod
) > 8) ||
1164 (ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
> 2)) {
1165 if (ieee
->LeisurePSLeave
)
1166 ieee
->LeisurePSLeave(ieee
->dev
);
1170 ieee
->last_rx_ps_time
= jiffies
;
1173 static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device
*ieee
,
1174 struct rtllib_rx_stats
*rx_stats
,
1175 struct rtllib_rxb
*rxb
,
1179 struct net_device
*dev
= ieee
->dev
;
1184 printk(KERN_INFO
"%s: rxb is NULL!!\n", __func__
);
1188 for (i
= 0; i
< rxb
->nr_subframes
; i
++) {
1189 struct sk_buff
*sub_skb
= rxb
->subframes
[i
];
1192 /* convert hdr + possible LLC headers into Ethernet header */
1193 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
1194 if (sub_skb
->len
>= 8 &&
1195 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
1196 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1197 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
1198 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1199 * replace EtherType */
1200 skb_pull(sub_skb
, SNAP_SIZE
);
1201 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1202 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1205 /* Leave Ethernet header part of hdr and full payload */
1207 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1208 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1209 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1212 ieee
->stats
.rx_packets
++;
1213 ieee
->stats
.rx_bytes
+= sub_skb
->len
;
1215 if (is_multicast_ether_addr(dst
))
1216 ieee
->stats
.multicast
++;
1218 /* Indicate the packets to upper layer */
1219 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
1220 sub_skb
->protocol
= eth_type_trans(sub_skb
, dev
);
1222 sub_skb
->dev
->stats
.rx_packets
++;
1223 sub_skb
->dev
->stats
.rx_bytes
+= sub_skb
->len
;
1224 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
1232 static int rtllib_rx_InfraAdhoc(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1233 struct rtllib_rx_stats
*rx_stats
)
1235 struct net_device
*dev
= ieee
->dev
;
1236 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1237 struct lib80211_crypt_data
*crypt
= NULL
;
1238 struct rtllib_rxb
*rxb
= NULL
;
1239 struct rx_ts_record
*pTS
= NULL
;
1240 u16 fc
, sc
, SeqNum
= 0;
1241 u8 type
, stype
, multicast
= 0, unicast
= 0, nr_subframes
= 0, TID
= 0;
1242 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
], bssid
[ETH_ALEN
] = {0}, *payload
;
1244 bool bToOtherSTA
= false;
1247 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1248 fc
= le16_to_cpu(hdr
->frame_ctl
);
1249 type
= WLAN_FC_GET_TYPE(fc
);
1250 stype
= WLAN_FC_GET_STYPE(fc
);
1251 sc
= le16_to_cpu(hdr
->seq_ctl
);
1253 /*Filter pkt not to me*/
1254 multicast
= is_multicast_ether_addr(hdr
->addr1
);
1255 unicast
= !multicast
;
1256 if (unicast
&& !ether_addr_equal(dev
->dev_addr
, hdr
->addr1
)) {
1257 if (ieee
->bNetPromiscuousMode
)
1263 /*Filter pkt has too small length */
1264 hdrlen
= rtllib_rx_get_hdrlen(ieee
, skb
, rx_stats
);
1265 if (skb
->len
< hdrlen
) {
1266 printk(KERN_INFO
"%s():ERR!!! skb->len is smaller than hdrlen\n", __func__
);
1270 /* Filter Duplicate pkt */
1271 ret
= rtllib_rx_check_duplicate(ieee
, skb
, multicast
);
1275 /* Filter CTRL Frame */
1276 if (type
== RTLLIB_FTYPE_CTL
)
1279 /* Filter MGNT Frame */
1280 if (type
== RTLLIB_FTYPE_MGMT
) {
1283 if (rtllib_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
1289 /* Filter WAPI DATA Frame */
1291 /* Update statstics for AP roaming */
1293 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
++;
1294 ieee
->LinkDetectInfo
.NumRxOkInPeriod
++;
1296 dev
->last_rx
= jiffies
;
1298 /* Data frame - extract src/dst addresses */
1299 rtllib_rx_extract_addr(ieee
, hdr
, dst
, src
, bssid
);
1301 /* Filter Data frames */
1302 ret
= rtllib_rx_data_filter(ieee
, fc
, dst
, src
, bssid
, hdr
->addr2
);
1306 if (skb
->len
== hdrlen
)
1309 /* Send pspoll based on moredata */
1310 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && (ieee
->sta_sleep
== LPS_IS_SLEEP
)
1311 && (ieee
->polling
) && (!bToOtherSTA
)) {
1312 if (WLAN_FC_MORE_DATA(fc
)) {
1313 /* more data bit is set, let's request a new frame from the AP */
1314 rtllib_sta_ps_send_pspoll_frame(ieee
);
1316 ieee
->polling
= false;
1320 /* Get crypt if encrypted */
1321 ret
= rtllib_rx_get_crypt(ieee
, skb
, &crypt
, hdrlen
);
1325 /* Decrypt data frame (including reassemble) */
1326 ret
= rtllib_rx_decrypt(ieee
, skb
, rx_stats
, crypt
, hdrlen
);
1332 /* Get TS for Rx Reorder */
1333 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1334 if (ieee
->current_network
.qos_data
.active
&& IsQoSDataFrame(skb
->data
)
1335 && !is_multicast_ether_addr(hdr
->addr1
)
1336 && (!bToOtherSTA
)) {
1337 TID
= Frame_QoSTID(skb
->data
);
1338 SeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1339 GetTs(ieee
, (struct ts_common_info
**) &pTS
, hdr
->addr2
, TID
, RX_DIR
, true);
1340 if (TID
!= 0 && TID
!= 3)
1341 ieee
->bis_any_nonbepkts
= true;
1344 /* Parse rx data frame (For AMSDU) */
1345 /* skb: hdr + (possible reassembled) full plaintext payload */
1346 payload
= skb
->data
+ hdrlen
;
1347 rxb
= kmalloc(sizeof(struct rtllib_rxb
), GFP_ATOMIC
);
1349 RTLLIB_DEBUG(RTLLIB_DL_ERR
,
1350 "%s(): kmalloc rxb error\n", __func__
);
1353 /* to parse amsdu packets */
1354 /* qos data packets & reserved bit is 1 */
1355 if (parse_subframe(ieee
, skb
, rx_stats
, rxb
, src
, dst
) == 0) {
1356 /* only to free rxb, and not submit the packets to upper layer */
1357 for (i
= 0; i
< rxb
->nr_subframes
; i
++)
1358 dev_kfree_skb(rxb
->subframes
[i
]);
1364 /* Update WAPI PN */
1366 /* Check if leave LPS */
1368 if (ieee
->bIsAggregateFrame
)
1369 nr_subframes
= rxb
->nr_subframes
;
1373 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+= nr_subframes
;
1374 rtllib_rx_check_leave_lps(ieee
, unicast
, nr_subframes
);
1377 /* Indicate packets to upper layer or Rx Reorder */
1378 if (ieee
->pHTInfo
->bCurRxReorderEnable
== false || pTS
== NULL
|| bToOtherSTA
)
1379 rtllib_rx_indicate_pkt_legacy(ieee
, rx_stats
, rxb
, dst
, src
);
1381 RxReorderIndicatePacket(ieee
, rxb
, pTS
, SeqNum
);
1389 ieee
->stats
.rx_dropped
++;
1391 /* Returning 0 indicates to caller that we have not handled the SKB--
1392 * so it is still allocated and can be used again by underlying
1393 * hardware as a DMA target */
1397 static int rtllib_rx_Master(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1398 struct rtllib_rx_stats
*rx_stats
)
1403 static int rtllib_rx_Monitor(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1404 struct rtllib_rx_stats
*rx_stats
)
1406 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1407 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1408 size_t hdrlen
= rtllib_get_hdrlen(fc
);
1410 if (skb
->len
< hdrlen
) {
1411 printk(KERN_INFO
"%s():ERR!!! skb->len is smaller than hdrlen\n", __func__
);
1415 if (HTCCheck(ieee
, skb
->data
)) {
1416 if (net_ratelimit())
1417 printk(KERN_INFO
"%s: Find HTCControl!\n", __func__
);
1421 rtllib_monitor_rx(ieee
, skb
, rx_stats
, hdrlen
);
1422 ieee
->stats
.rx_packets
++;
1423 ieee
->stats
.rx_bytes
+= skb
->len
;
1428 static int rtllib_rx_Mesh(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1429 struct rtllib_rx_stats
*rx_stats
)
1434 /* All received frames are sent to this function. @skb contains the frame in
1435 * IEEE 802.11 format, i.e., in the format it was sent over air.
1436 * This function is called only as a tasklet (software IRQ). */
1437 int rtllib_rx(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1438 struct rtllib_rx_stats
*rx_stats
)
1442 if ((NULL
== ieee
) || (NULL
== skb
) || (NULL
== rx_stats
)) {
1443 printk(KERN_INFO
"%s: Input parameters NULL!\n", __func__
);
1446 if (skb
->len
< 10) {
1447 printk(KERN_INFO
"%s: SKB length < 10\n", __func__
);
1451 switch (ieee
->iw_mode
) {
1454 ret
= rtllib_rx_InfraAdhoc(ieee
, skb
, rx_stats
);
1456 case IW_MODE_MASTER
:
1457 case IW_MODE_REPEAT
:
1458 ret
= rtllib_rx_Master(ieee
, skb
, rx_stats
);
1460 case IW_MODE_MONITOR
:
1461 ret
= rtllib_rx_Monitor(ieee
, skb
, rx_stats
);
1464 ret
= rtllib_rx_Mesh(ieee
, skb
, rx_stats
);
1467 printk(KERN_INFO
"%s: ERR iw mode!!!\n", __func__
);
1475 ieee
->stats
.rx_dropped
++;
1478 EXPORT_SYMBOL(rtllib_rx
);
1480 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
1483 * Make ther structure we read from the beacon packet has
1486 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1487 *info_element
, int sub_type
)
1490 if (info_element
->qui_subtype
!= sub_type
)
1492 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
1494 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
1496 if (info_element
->version
!= QOS_VERSION_1
)
1504 * Parse a QoS parameter element
1506 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
1507 *element_param
, struct rtllib_info_element
1511 u16 size
= sizeof(struct rtllib_qos_parameter_info
) - 2;
1513 if ((info_element
== NULL
) || (element_param
== NULL
))
1516 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
1517 memcpy(element_param
->info_element
.qui
, info_element
->data
,
1519 element_param
->info_element
.elementID
= info_element
->id
;
1520 element_param
->info_element
.length
= info_element
->len
;
1524 ret
= rtllib_verify_qos_info(&element_param
->info_element
,
1525 QOS_OUI_PARAM_SUB_TYPE
);
1530 * Parse a QoS information element
1532 static int rtllib_read_qos_info_element(struct
1533 rtllib_qos_information_element
1534 *element_info
, struct rtllib_info_element
1538 u16 size
= sizeof(struct rtllib_qos_information_element
) - 2;
1540 if (element_info
== NULL
)
1542 if (info_element
== NULL
)
1545 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
1546 memcpy(element_info
->qui
, info_element
->data
,
1548 element_info
->elementID
= info_element
->id
;
1549 element_info
->length
= info_element
->len
;
1554 ret
= rtllib_verify_qos_info(element_info
,
1555 QOS_OUI_INFO_SUB_TYPE
);
1561 * Write QoS parameters from the ac parameters.
1563 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info
*param_elm
,
1564 struct rtllib_qos_data
*qos_data
)
1566 struct rtllib_qos_ac_parameter
*ac_params
;
1567 struct rtllib_qos_parameters
*qos_param
= &(qos_data
->parameters
);
1572 qos_data
->wmm_acm
= 0;
1573 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1574 ac_params
= &(param_elm
->ac_params_record
[i
]);
1576 aci
= (ac_params
->aci_aifsn
& 0x60) >> 5;
1577 acm
= (ac_params
->aci_aifsn
& 0x10) >> 4;
1579 if (aci
>= QOS_QUEUE_NUM
)
1583 /* BIT(0) | BIT(3) */
1585 qos_data
->wmm_acm
|= (0x01<<0)|(0x01<<3);
1588 /* BIT(4) | BIT(5) */
1590 qos_data
->wmm_acm
|= (0x01<<4)|(0x01<<5);
1593 /* BIT(6) | BIT(7) */
1595 qos_data
->wmm_acm
|= (0x01<<6)|(0x01<<7);
1599 /* BIT(1) | BIT(2) */
1601 qos_data
->wmm_acm
|= (0x01<<1)|(0x01<<2);
1605 qos_param
->aifs
[aci
] = (ac_params
->aci_aifsn
) & 0x0f;
1607 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1608 qos_param
->aifs
[aci
] = (qos_param
->aifs
[aci
] < 2) ? 2 : qos_param
->aifs
[aci
];
1610 qos_param
->cw_min
[aci
] = cpu_to_le16(ac_params
->ecw_min_max
& 0x0F);
1612 qos_param
->cw_max
[aci
] = cpu_to_le16((ac_params
->ecw_min_max
& 0xF0) >> 4);
1614 qos_param
->flag
[aci
] =
1615 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1616 qos_param
->tx_op_limit
[aci
] = ac_params
->tx_op_limit
;
1622 * we have a generic data element which it may contain QoS information or
1623 * parameters element. check the information element length to decide
1624 * which type to read
1626 static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
1628 struct rtllib_network
*network
)
1631 struct rtllib_qos_information_element qos_info_element
;
1633 rc
= rtllib_read_qos_info_element(&qos_info_element
, info_element
);
1636 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1637 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1639 struct rtllib_qos_parameter_info param_element
;
1641 rc
= rtllib_read_qos_param_element(¶m_element
,
1644 rtllib_qos_convert_ac_to_parameters(¶m_element
,
1645 &(network
->qos_data
));
1646 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1647 network
->qos_data
.param_count
=
1648 param_element
.info_element
.ac_info
& 0x0F;
1653 RTLLIB_DEBUG_QOS("QoS is supported\n");
1654 network
->qos_data
.supported
= 1;
1659 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1661 static const char *get_info_element_string(u16 id
)
1666 MFIE_STRING(FH_SET
);
1667 MFIE_STRING(DS_SET
);
1668 MFIE_STRING(CF_SET
);
1670 MFIE_STRING(IBSS_SET
);
1671 MFIE_STRING(COUNTRY
);
1672 MFIE_STRING(HOP_PARAMS
);
1673 MFIE_STRING(HOP_TABLE
);
1674 MFIE_STRING(REQUEST
);
1675 MFIE_STRING(CHALLENGE
);
1676 MFIE_STRING(POWER_CONSTRAINT
);
1677 MFIE_STRING(POWER_CAPABILITY
);
1678 MFIE_STRING(TPC_REQUEST
);
1679 MFIE_STRING(TPC_REPORT
);
1680 MFIE_STRING(SUPP_CHANNELS
);
1682 MFIE_STRING(MEASURE_REQUEST
);
1683 MFIE_STRING(MEASURE_REPORT
);
1685 MFIE_STRING(IBSS_DFS
);
1687 MFIE_STRING(RATES_EX
);
1688 MFIE_STRING(GENERIC
);
1689 MFIE_STRING(QOS_PARAMETER
);
1695 static inline void rtllib_extract_country_ie(
1696 struct rtllib_device
*ieee
,
1697 struct rtllib_info_element
*info_element
,
1698 struct rtllib_network
*network
,
1701 if (IS_DOT11D_ENABLE(ieee
)) {
1702 if (info_element
->len
!= 0) {
1703 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
1704 network
->CountryIeLen
= info_element
->len
;
1706 if (!IS_COUNTRY_IE_VALID(ieee
)) {
1707 if (rtllib_act_scanning(ieee
, false) && ieee
->FirstIe_InScan
)
1708 printk(KERN_INFO
"Received beacon ContryIE, SSID: <%s>\n", network
->ssid
);
1709 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
1713 if (IS_EQUAL_CIE_SRC(ieee
, addr2
))
1714 UPDATE_CIE_WATCHDOG(ieee
);
1719 int rtllib_parse_info_param(struct rtllib_device
*ieee
,
1720 struct rtllib_info_element
*info_element
,
1722 struct rtllib_network
*network
,
1723 struct rtllib_rx_stats
*stats
)
1727 u16 tmp_htcap_len
= 0;
1728 u16 tmp_htinfo_len
= 0;
1729 u16 ht_realtek_agg_len
= 0;
1730 u8 ht_realtek_agg_buf
[MAX_IE_LEN
];
1734 while (length
>= sizeof(*info_element
)) {
1735 if (sizeof(*info_element
) + info_element
->len
> length
) {
1736 RTLLIB_DEBUG_MGMT("Info elem: parse failed: info_element->len + 2 > left : info_element->len+2=%zd left=%d, id=%d.\n",
1738 sizeof(*info_element
),
1739 length
, info_element
->id
);
1740 /* We stop processing but don't return an error here
1741 * because some misbehaviour APs break this rule. ie.
1742 * Orinoco AP1000. */
1746 switch (info_element
->id
) {
1747 case MFIE_TYPE_SSID
:
1748 if (rtllib_is_empty_essid(info_element
->data
,
1749 info_element
->len
)) {
1750 network
->flags
|= NETWORK_EMPTY_ESSID
;
1754 network
->ssid_len
= min(info_element
->len
,
1755 (u8
) IW_ESSID_MAX_SIZE
);
1756 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
1757 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1758 memset(network
->ssid
+ network
->ssid_len
, 0,
1759 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1761 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1762 network
->ssid
, network
->ssid_len
);
1765 case MFIE_TYPE_RATES
:
1767 network
->rates_len
= min(info_element
->len
,
1769 for (i
= 0; i
< network
->rates_len
; i
++) {
1770 network
->rates
[i
] = info_element
->data
[i
];
1771 p
+= snprintf(p
, sizeof(rates_str
) -
1772 (p
- rates_str
), "%02X ",
1774 if (rtllib_is_ofdm_rate
1775 (info_element
->data
[i
])) {
1776 network
->flags
|= NETWORK_HAS_OFDM
;
1777 if (info_element
->data
[i
] &
1778 RTLLIB_BASIC_RATE_MASK
)
1783 if (rtllib_is_cck_rate
1784 (info_element
->data
[i
])) {
1785 network
->flags
|= NETWORK_HAS_CCK
;
1789 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1790 rates_str
, network
->rates_len
);
1793 case MFIE_TYPE_RATES_EX
:
1795 network
->rates_ex_len
= min(info_element
->len
,
1796 MAX_RATES_EX_LENGTH
);
1797 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1798 network
->rates_ex
[i
] = info_element
->data
[i
];
1799 p
+= snprintf(p
, sizeof(rates_str
) -
1800 (p
- rates_str
), "%02X ",
1801 network
->rates_ex
[i
]);
1802 if (rtllib_is_ofdm_rate
1803 (info_element
->data
[i
])) {
1804 network
->flags
|= NETWORK_HAS_OFDM
;
1805 if (info_element
->data
[i
] &
1806 RTLLIB_BASIC_RATE_MASK
)
1812 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1813 rates_str
, network
->rates_ex_len
);
1816 case MFIE_TYPE_DS_SET
:
1817 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1818 info_element
->data
[0]);
1819 network
->channel
= info_element
->data
[0];
1822 case MFIE_TYPE_FH_SET
:
1823 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1826 case MFIE_TYPE_CF_SET
:
1827 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1831 if (info_element
->len
< 4)
1834 network
->tim
.tim_count
= info_element
->data
[0];
1835 network
->tim
.tim_period
= info_element
->data
[1];
1837 network
->dtim_period
= info_element
->data
[1];
1838 if (ieee
->state
!= RTLLIB_LINKED
)
1840 network
->last_dtim_sta_time
= jiffies
;
1842 network
->dtim_data
= RTLLIB_DTIM_VALID
;
1845 if (info_element
->data
[2] & 1)
1846 network
->dtim_data
|= RTLLIB_DTIM_MBCAST
;
1848 offset
= (info_element
->data
[2] >> 1)*2;
1851 if (ieee
->assoc_id
< 8*offset
||
1852 ieee
->assoc_id
> 8*(offset
+ info_element
->len
- 3))
1855 offset
= (ieee
->assoc_id
/ 8) - offset
;
1856 if (info_element
->data
[3 + offset
] &
1857 (1 << (ieee
->assoc_id
% 8)))
1858 network
->dtim_data
|= RTLLIB_DTIM_UCAST
;
1860 network
->listen_interval
= network
->dtim_period
;
1864 network
->erp_value
= info_element
->data
[0];
1865 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1866 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1867 network
->erp_value
);
1869 case MFIE_TYPE_IBSS_SET
:
1870 network
->atim_window
= info_element
->data
[0];
1871 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1872 network
->atim_window
);
1875 case MFIE_TYPE_CHALLENGE
:
1876 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1879 case MFIE_TYPE_GENERIC
:
1880 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1882 if (!rtllib_parse_qos_info_param_IE(info_element
,
1885 if (info_element
->len
>= 4 &&
1886 info_element
->data
[0] == 0x00 &&
1887 info_element
->data
[1] == 0x50 &&
1888 info_element
->data
[2] == 0xf2 &&
1889 info_element
->data
[3] == 0x01) {
1890 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1892 memcpy(network
->wpa_ie
, info_element
,
1893 network
->wpa_ie_len
);
1896 if (info_element
->len
== 7 &&
1897 info_element
->data
[0] == 0x00 &&
1898 info_element
->data
[1] == 0xe0 &&
1899 info_element
->data
[2] == 0x4c &&
1900 info_element
->data
[3] == 0x01 &&
1901 info_element
->data
[4] == 0x02)
1902 network
->Turbo_Enable
= 1;
1904 if (tmp_htcap_len
== 0) {
1905 if (info_element
->len
>= 4 &&
1906 info_element
->data
[0] == 0x00 &&
1907 info_element
->data
[1] == 0x90 &&
1908 info_element
->data
[2] == 0x4c &&
1909 info_element
->data
[3] == 0x033) {
1911 tmp_htcap_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
1912 if (tmp_htcap_len
!= 0) {
1913 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1914 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
) ?
1915 sizeof(network
->bssht
.bdHTCapBuf
) : tmp_htcap_len
;
1916 memcpy(network
->bssht
.bdHTCapBuf
, info_element
->data
, network
->bssht
.bdHTCapLen
);
1919 if (tmp_htcap_len
!= 0) {
1920 network
->bssht
.bdSupportHT
= true;
1921 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)(network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0);
1923 network
->bssht
.bdSupportHT
= false;
1924 network
->bssht
.bdHT1R
= false;
1929 if (tmp_htinfo_len
== 0) {
1930 if (info_element
->len
>= 4 &&
1931 info_element
->data
[0] == 0x00 &&
1932 info_element
->data
[1] == 0x90 &&
1933 info_element
->data
[2] == 0x4c &&
1934 info_element
->data
[3] == 0x034) {
1935 tmp_htinfo_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
1936 if (tmp_htinfo_len
!= 0) {
1937 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1938 if (tmp_htinfo_len
) {
1939 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
) ?
1940 sizeof(network
->bssht
.bdHTInfoBuf
) : tmp_htinfo_len
;
1941 memcpy(network
->bssht
.bdHTInfoBuf
, info_element
->data
, network
->bssht
.bdHTInfoLen
);
1949 if (ieee
->aggregation
) {
1950 if (network
->bssht
.bdSupportHT
) {
1951 if (info_element
->len
>= 4 &&
1952 info_element
->data
[0] == 0x00 &&
1953 info_element
->data
[1] == 0xe0 &&
1954 info_element
->data
[2] == 0x4c &&
1955 info_element
->data
[3] == 0x02) {
1956 ht_realtek_agg_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
1957 memcpy(ht_realtek_agg_buf
, info_element
->data
, info_element
->len
);
1959 if (ht_realtek_agg_len
>= 5) {
1960 network
->realtek_cap_exit
= true;
1961 network
->bssht
.bdRT2RTAggregation
= true;
1963 if ((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & 0x02))
1964 network
->bssht
.bdRT2RTLongSlotTime
= true;
1966 if ((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_92SE
))
1967 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_92SE
;
1970 if (ht_realtek_agg_len
>= 5) {
1971 if ((ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_SOFTAP
))
1972 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_SOFTAP
;
1976 if ((info_element
->len
>= 3 &&
1977 info_element
->data
[0] == 0x00 &&
1978 info_element
->data
[1] == 0x05 &&
1979 info_element
->data
[2] == 0xb5) ||
1980 (info_element
->len
>= 3 &&
1981 info_element
->data
[0] == 0x00 &&
1982 info_element
->data
[1] == 0x0a &&
1983 info_element
->data
[2] == 0xf7) ||
1984 (info_element
->len
>= 3 &&
1985 info_element
->data
[0] == 0x00 &&
1986 info_element
->data
[1] == 0x10 &&
1987 info_element
->data
[2] == 0x18)) {
1988 network
->broadcom_cap_exist
= true;
1990 if (info_element
->len
>= 3 &&
1991 info_element
->data
[0] == 0x00 &&
1992 info_element
->data
[1] == 0x0c &&
1993 info_element
->data
[2] == 0x43)
1994 network
->ralink_cap_exist
= true;
1995 if ((info_element
->len
>= 3 &&
1996 info_element
->data
[0] == 0x00 &&
1997 info_element
->data
[1] == 0x03 &&
1998 info_element
->data
[2] == 0x7f) ||
1999 (info_element
->len
>= 3 &&
2000 info_element
->data
[0] == 0x00 &&
2001 info_element
->data
[1] == 0x13 &&
2002 info_element
->data
[2] == 0x74))
2003 network
->atheros_cap_exist
= true;
2005 if ((info_element
->len
>= 3 &&
2006 info_element
->data
[0] == 0x00 &&
2007 info_element
->data
[1] == 0x50 &&
2008 info_element
->data
[2] == 0x43))
2009 network
->marvell_cap_exist
= true;
2010 if (info_element
->len
>= 3 &&
2011 info_element
->data
[0] == 0x00 &&
2012 info_element
->data
[1] == 0x40 &&
2013 info_element
->data
[2] == 0x96)
2014 network
->cisco_cap_exist
= true;
2017 if (info_element
->len
>= 3 &&
2018 info_element
->data
[0] == 0x00 &&
2019 info_element
->data
[1] == 0x0a &&
2020 info_element
->data
[2] == 0xf5)
2021 network
->airgo_cap_exist
= true;
2023 if (info_element
->len
> 4 &&
2024 info_element
->data
[0] == 0x00 &&
2025 info_element
->data
[1] == 0x40 &&
2026 info_element
->data
[2] == 0x96 &&
2027 info_element
->data
[3] == 0x01) {
2028 if (info_element
->len
== 6) {
2029 memcpy(network
->CcxRmState
, &info_element
[4], 2);
2030 if (network
->CcxRmState
[0] != 0)
2031 network
->bCcxRmEnable
= true;
2033 network
->bCcxRmEnable
= false;
2034 network
->MBssidMask
= network
->CcxRmState
[1] & 0x07;
2035 if (network
->MBssidMask
!= 0) {
2036 network
->bMBssidValid
= true;
2037 network
->MBssidMask
= 0xff << (network
->MBssidMask
);
2038 memcpy(network
->MBssid
, network
->bssid
, ETH_ALEN
);
2039 network
->MBssid
[5] &= network
->MBssidMask
;
2041 network
->bMBssidValid
= false;
2044 network
->bCcxRmEnable
= false;
2047 if (info_element
->len
> 4 &&
2048 info_element
->data
[0] == 0x00 &&
2049 info_element
->data
[1] == 0x40 &&
2050 info_element
->data
[2] == 0x96 &&
2051 info_element
->data
[3] == 0x03) {
2052 if (info_element
->len
== 5) {
2053 network
->bWithCcxVerNum
= true;
2054 network
->BssCcxVerNumber
= info_element
->data
[4];
2056 network
->bWithCcxVerNum
= false;
2057 network
->BssCcxVerNumber
= 0;
2060 if (info_element
->len
> 4 &&
2061 info_element
->data
[0] == 0x00 &&
2062 info_element
->data
[1] == 0x50 &&
2063 info_element
->data
[2] == 0xf2 &&
2064 info_element
->data
[3] == 0x04) {
2065 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
2067 network
->wzc_ie_len
= min(info_element
->len
+2,
2069 memcpy(network
->wzc_ie
, info_element
,
2070 network
->wzc_ie_len
);
2075 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2077 network
->rsn_ie_len
= min(info_element
->len
+ 2,
2079 memcpy(network
->rsn_ie
, info_element
,
2080 network
->rsn_ie_len
);
2083 case MFIE_TYPE_HT_CAP
:
2084 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2086 tmp_htcap_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
2087 if (tmp_htcap_len
!= 0) {
2088 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
2089 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
) ?
2090 sizeof(network
->bssht
.bdHTCapBuf
) : tmp_htcap_len
;
2091 memcpy(network
->bssht
.bdHTCapBuf
,
2093 network
->bssht
.bdHTCapLen
);
2095 network
->bssht
.bdSupportHT
= true;
2096 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)
2097 network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0;
2099 network
->bssht
.bdBandWidth
= (enum ht_channel_width
)
2100 (((struct ht_capab_ele
*)
2101 (network
->bssht
.bdHTCapBuf
))->ChlWidth
);
2103 network
->bssht
.bdSupportHT
= false;
2104 network
->bssht
.bdHT1R
= false;
2105 network
->bssht
.bdBandWidth
= HT_CHANNEL_WIDTH_20
;
2110 case MFIE_TYPE_HT_INFO
:
2111 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2113 tmp_htinfo_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
2114 if (tmp_htinfo_len
) {
2115 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_IEEE
;
2116 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
>
2117 sizeof(network
->bssht
.bdHTInfoBuf
) ?
2118 sizeof(network
->bssht
.bdHTInfoBuf
) :
2120 memcpy(network
->bssht
.bdHTInfoBuf
,
2122 network
->bssht
.bdHTInfoLen
);
2126 case MFIE_TYPE_AIRONET
:
2127 RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2129 if (info_element
->len
> IE_CISCO_FLAG_POSITION
) {
2130 network
->bWithAironetIE
= true;
2132 if ((info_element
->data
[IE_CISCO_FLAG_POSITION
]
2133 & SUPPORT_CKIP_MIC
) ||
2134 (info_element
->data
[IE_CISCO_FLAG_POSITION
]
2136 network
->bCkipSupported
= true;
2138 network
->bCkipSupported
= false;
2140 network
->bWithAironetIE
= false;
2141 network
->bCkipSupported
= false;
2144 case MFIE_TYPE_QOS_PARAMETER
:
2146 "QoS Error need to parse QOS_PARAMETER IE\n");
2149 case MFIE_TYPE_COUNTRY
:
2150 RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2152 rtllib_extract_country_ie(ieee
, info_element
, network
,
2158 ("Unsupported info element: %s (%d)\n",
2159 get_info_element_string(info_element
->id
),
2164 length
-= sizeof(*info_element
) + info_element
->len
;
2166 (struct rtllib_info_element
*)&info_element
->
2167 data
[info_element
->len
];
2170 if (!network
->atheros_cap_exist
&& !network
->broadcom_cap_exist
&&
2171 !network
->cisco_cap_exist
&& !network
->ralink_cap_exist
&&
2172 !network
->bssht
.bdRT2RTAggregation
)
2173 network
->unknown_cap_exist
= true;
2175 network
->unknown_cap_exist
= false;
2179 static long rtllib_translate_todbm(u8 signal_strength_index
)
2183 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
2186 return signal_power
;
2189 static inline int rtllib_network_init(
2190 struct rtllib_device
*ieee
,
2191 struct rtllib_probe_response
*beacon
,
2192 struct rtllib_network
*network
,
2193 struct rtllib_rx_stats
*stats
)
2197 network->qos_data.active = 0;
2198 network->qos_data.supported = 0;
2199 network->qos_data.param_count = 0;
2200 network->qos_data.old_param_count = 0;
2202 memset(&network
->qos_data
, 0, sizeof(struct rtllib_qos_data
));
2204 /* Pull out fixed field data */
2205 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
2206 network
->capability
= le16_to_cpu(beacon
->capability
);
2207 network
->last_scanned
= jiffies
;
2208 network
->time_stamp
[0] = beacon
->time_stamp
[0];
2209 network
->time_stamp
[1] = beacon
->time_stamp
[1];
2210 network
->beacon_interval
= le16_to_cpu(beacon
->beacon_interval
);
2211 /* Where to pull this? beacon->listen_interval;*/
2212 network
->listen_interval
= 0x0A;
2213 network
->rates_len
= network
->rates_ex_len
= 0;
2214 network
->last_associate
= 0;
2215 network
->ssid_len
= 0;
2216 network
->hidden_ssid_len
= 0;
2217 memset(network
->hidden_ssid
, 0, sizeof(network
->hidden_ssid
));
2219 network
->atim_window
= 0;
2220 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
2222 network
->berp_info_valid
= false;
2223 network
->broadcom_cap_exist
= false;
2224 network
->ralink_cap_exist
= false;
2225 network
->atheros_cap_exist
= false;
2226 network
->cisco_cap_exist
= false;
2227 network
->unknown_cap_exist
= false;
2228 network
->realtek_cap_exit
= false;
2229 network
->marvell_cap_exist
= false;
2230 network
->airgo_cap_exist
= false;
2231 network
->Turbo_Enable
= 0;
2232 network
->SignalStrength
= stats
->SignalStrength
;
2233 network
->RSSI
= stats
->SignalStrength
;
2234 network
->CountryIeLen
= 0;
2235 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
2236 HTInitializeBssDesc(&network
->bssht
);
2237 if (stats
->freq
== RTLLIB_52GHZ_BAND
) {
2238 /* for A band (No DS info) */
2239 network
->channel
= stats
->received_channel
;
2241 network
->flags
|= NETWORK_HAS_CCK
;
2243 network
->wpa_ie_len
= 0;
2244 network
->rsn_ie_len
= 0;
2245 network
->wzc_ie_len
= 0;
2247 if (rtllib_parse_info_param(ieee
,
2248 beacon
->info_element
,
2249 (stats
->len
- sizeof(*beacon
)),
2255 if (stats
->freq
== RTLLIB_52GHZ_BAND
)
2256 network
->mode
= IEEE_A
;
2258 if (network
->flags
& NETWORK_HAS_OFDM
)
2259 network
->mode
|= IEEE_G
;
2260 if (network
->flags
& NETWORK_HAS_CCK
)
2261 network
->mode
|= IEEE_B
;
2264 if (network
->mode
== 0) {
2265 RTLLIB_DEBUG_SCAN("Filtered out '%s (%pM)' network.\n",
2266 escape_essid(network
->ssid
,
2272 if (network
->bssht
.bdSupportHT
) {
2273 if (network
->mode
== IEEE_A
)
2274 network
->mode
= IEEE_N_5G
;
2275 else if (network
->mode
& (IEEE_G
| IEEE_B
))
2276 network
->mode
= IEEE_N_24G
;
2278 if (rtllib_is_empty_essid(network
->ssid
, network
->ssid_len
))
2279 network
->flags
|= NETWORK_EMPTY_ESSID
;
2280 stats
->signal
= 30 + (stats
->SignalStrength
* 70) / 100;
2281 stats
->noise
= rtllib_translate_todbm((u8
)(100-stats
->signal
)) - 25;
2283 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
2288 static inline int is_same_network(struct rtllib_network
*src
,
2289 struct rtllib_network
*dst
, u8 ssidbroad
)
2291 /* A network is only a duplicate if the channel, BSSID, ESSID
2292 * and the capability field (in particular IBSS and BSS) all match.
2293 * We treat all <hidden> with the same BSSID and channel
2295 return (((src
->ssid_len
== dst
->ssid_len
) || (!ssidbroad
)) &&
2296 (src
->channel
== dst
->channel
) &&
2297 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
2298 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) ||
2300 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
2301 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
2302 ((src
->capability
& WLAN_CAPABILITY_ESS
) ==
2303 (dst
->capability
& WLAN_CAPABILITY_ESS
)));
2307 static inline void update_network(struct rtllib_network
*dst
,
2308 struct rtllib_network
*src
)
2313 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct rtllib_rx_stats
));
2314 dst
->capability
= src
->capability
;
2315 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
2316 dst
->rates_len
= src
->rates_len
;
2317 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
2318 dst
->rates_ex_len
= src
->rates_ex_len
;
2319 if (src
->ssid_len
> 0) {
2320 if (dst
->ssid_len
== 0) {
2321 memset(dst
->hidden_ssid
, 0, sizeof(dst
->hidden_ssid
));
2322 dst
->hidden_ssid_len
= src
->ssid_len
;
2323 memcpy(dst
->hidden_ssid
, src
->ssid
, src
->ssid_len
);
2325 memset(dst
->ssid
, 0, dst
->ssid_len
);
2326 dst
->ssid_len
= src
->ssid_len
;
2327 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
2330 dst
->mode
= src
->mode
;
2331 dst
->flags
= src
->flags
;
2332 dst
->time_stamp
[0] = src
->time_stamp
[0];
2333 dst
->time_stamp
[1] = src
->time_stamp
[1];
2334 if (src
->flags
& NETWORK_HAS_ERP_VALUE
) {
2335 dst
->erp_value
= src
->erp_value
;
2336 dst
->berp_info_valid
= src
->berp_info_valid
= true;
2338 dst
->beacon_interval
= src
->beacon_interval
;
2339 dst
->listen_interval
= src
->listen_interval
;
2340 dst
->atim_window
= src
->atim_window
;
2341 dst
->dtim_period
= src
->dtim_period
;
2342 dst
->dtim_data
= src
->dtim_data
;
2343 dst
->last_dtim_sta_time
= src
->last_dtim_sta_time
;
2344 memcpy(&dst
->tim
, &src
->tim
, sizeof(struct rtllib_tim_parameters
));
2346 dst
->bssht
.bdSupportHT
= src
->bssht
.bdSupportHT
;
2347 dst
->bssht
.bdRT2RTAggregation
= src
->bssht
.bdRT2RTAggregation
;
2348 dst
->bssht
.bdHTCapLen
= src
->bssht
.bdHTCapLen
;
2349 memcpy(dst
->bssht
.bdHTCapBuf
, src
->bssht
.bdHTCapBuf
,
2350 src
->bssht
.bdHTCapLen
);
2351 dst
->bssht
.bdHTInfoLen
= src
->bssht
.bdHTInfoLen
;
2352 memcpy(dst
->bssht
.bdHTInfoBuf
, src
->bssht
.bdHTInfoBuf
,
2353 src
->bssht
.bdHTInfoLen
);
2354 dst
->bssht
.bdHTSpecVer
= src
->bssht
.bdHTSpecVer
;
2355 dst
->bssht
.bdRT2RTLongSlotTime
= src
->bssht
.bdRT2RTLongSlotTime
;
2356 dst
->broadcom_cap_exist
= src
->broadcom_cap_exist
;
2357 dst
->ralink_cap_exist
= src
->ralink_cap_exist
;
2358 dst
->atheros_cap_exist
= src
->atheros_cap_exist
;
2359 dst
->realtek_cap_exit
= src
->realtek_cap_exit
;
2360 dst
->marvell_cap_exist
= src
->marvell_cap_exist
;
2361 dst
->cisco_cap_exist
= src
->cisco_cap_exist
;
2362 dst
->airgo_cap_exist
= src
->airgo_cap_exist
;
2363 dst
->unknown_cap_exist
= src
->unknown_cap_exist
;
2364 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
2365 dst
->wpa_ie_len
= src
->wpa_ie_len
;
2366 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
2367 dst
->rsn_ie_len
= src
->rsn_ie_len
;
2368 memcpy(dst
->wzc_ie
, src
->wzc_ie
, src
->wzc_ie_len
);
2369 dst
->wzc_ie_len
= src
->wzc_ie_len
;
2371 dst
->last_scanned
= jiffies
;
2372 /* qos related parameters */
2373 qos_active
= dst
->qos_data
.active
;
2374 old_param
= dst
->qos_data
.param_count
;
2375 dst
->qos_data
.supported
= src
->qos_data
.supported
;
2376 if (dst
->flags
& NETWORK_HAS_QOS_PARAMETERS
)
2377 memcpy(&dst
->qos_data
, &src
->qos_data
,
2378 sizeof(struct rtllib_qos_data
));
2379 if (dst
->qos_data
.supported
== 1) {
2382 ("QoS the network %s is QoS supported\n",
2386 ("QoS the network is QoS supported\n");
2388 dst
->qos_data
.active
= qos_active
;
2389 dst
->qos_data
.old_param_count
= old_param
;
2391 /* dst->last_associate is not overwritten */
2392 dst
->wmm_info
= src
->wmm_info
;
2393 if (src
->wmm_param
[0].ac_aci_acm_aifsn
||
2394 src
->wmm_param
[1].ac_aci_acm_aifsn
||
2395 src
->wmm_param
[2].ac_aci_acm_aifsn
||
2396 src
->wmm_param
[3].ac_aci_acm_aifsn
)
2397 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
2399 dst
->SignalStrength
= src
->SignalStrength
;
2400 dst
->RSSI
= src
->RSSI
;
2401 dst
->Turbo_Enable
= src
->Turbo_Enable
;
2403 dst
->CountryIeLen
= src
->CountryIeLen
;
2404 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
2406 dst
->bWithAironetIE
= src
->bWithAironetIE
;
2407 dst
->bCkipSupported
= src
->bCkipSupported
;
2408 memcpy(dst
->CcxRmState
, src
->CcxRmState
, 2);
2409 dst
->bCcxRmEnable
= src
->bCcxRmEnable
;
2410 dst
->MBssidMask
= src
->MBssidMask
;
2411 dst
->bMBssidValid
= src
->bMBssidValid
;
2412 memcpy(dst
->MBssid
, src
->MBssid
, 6);
2413 dst
->bWithCcxVerNum
= src
->bWithCcxVerNum
;
2414 dst
->BssCcxVerNumber
= src
->BssCcxVerNumber
;
2417 static inline int is_beacon(__le16 fc
)
2419 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == RTLLIB_STYPE_BEACON
);
2422 static int IsPassiveChannel(struct rtllib_device
*rtllib
, u8 channel
)
2424 if (MAX_CHANNEL_NUMBER
< channel
) {
2425 printk(KERN_INFO
"%s(): Invalid Channel\n", __func__
);
2429 if (rtllib
->active_channel_map
[channel
] == 2)
2435 int rtllib_legal_channel(struct rtllib_device
*rtllib
, u8 channel
)
2437 if (MAX_CHANNEL_NUMBER
< channel
) {
2438 printk(KERN_INFO
"%s(): Invalid Channel\n", __func__
);
2441 if (rtllib
->active_channel_map
[channel
] > 0)
2446 EXPORT_SYMBOL(rtllib_legal_channel
);
2448 static inline void rtllib_process_probe_response(
2449 struct rtllib_device
*ieee
,
2450 struct rtllib_probe_response
*beacon
,
2451 struct rtllib_rx_stats
*stats
)
2453 struct rtllib_network
*target
;
2454 struct rtllib_network
*oldest
= NULL
;
2455 struct rtllib_info_element
*info_element
= &beacon
->info_element
[0];
2456 unsigned long flags
;
2458 struct rtllib_network
*network
= kzalloc(sizeof(struct rtllib_network
),
2465 "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2466 escape_essid(info_element
->data
, info_element
->len
),
2467 beacon
->header
.addr3
,
2468 (le16_to_cpu(beacon
->capability
) & (1<<0xf)) ? '1' : '0',
2469 (le16_to_cpu(beacon
->capability
) & (1<<0xe)) ? '1' : '0',
2470 (le16_to_cpu(beacon
->capability
) & (1<<0xd)) ? '1' : '0',
2471 (le16_to_cpu(beacon
->capability
) & (1<<0xc)) ? '1' : '0',
2472 (le16_to_cpu(beacon
->capability
) & (1<<0xb)) ? '1' : '0',
2473 (le16_to_cpu(beacon
->capability
) & (1<<0xa)) ? '1' : '0',
2474 (le16_to_cpu(beacon
->capability
) & (1<<0x9)) ? '1' : '0',
2475 (le16_to_cpu(beacon
->capability
) & (1<<0x8)) ? '1' : '0',
2476 (le16_to_cpu(beacon
->capability
) & (1<<0x7)) ? '1' : '0',
2477 (le16_to_cpu(beacon
->capability
) & (1<<0x6)) ? '1' : '0',
2478 (le16_to_cpu(beacon
->capability
) & (1<<0x5)) ? '1' : '0',
2479 (le16_to_cpu(beacon
->capability
) & (1<<0x4)) ? '1' : '0',
2480 (le16_to_cpu(beacon
->capability
) & (1<<0x3)) ? '1' : '0',
2481 (le16_to_cpu(beacon
->capability
) & (1<<0x2)) ? '1' : '0',
2482 (le16_to_cpu(beacon
->capability
) & (1<<0x1)) ? '1' : '0',
2483 (le16_to_cpu(beacon
->capability
) & (1<<0x0)) ? '1' : '0');
2485 if (rtllib_network_init(ieee
, beacon
, network
, stats
)) {
2486 RTLLIB_DEBUG_SCAN("Dropped '%s' ( %pM) via %s.\n",
2487 escape_essid(info_element
->data
,
2489 beacon
->header
.addr3
,
2491 le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2492 RTLLIB_STYPE_PROBE_RESP
?
2493 "PROBE RESPONSE" : "BEACON");
2498 if (!rtllib_legal_channel(ieee
, network
->channel
))
2501 if (WLAN_FC_GET_STYPE(le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2502 RTLLIB_STYPE_PROBE_RESP
) {
2503 if (IsPassiveChannel(ieee
, network
->channel
)) {
2504 printk(KERN_INFO
"GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n",
2510 /* The network parsed correctly -- so now we scan our known networks
2511 * to see if we can find it in our list.
2513 * NOTE: This search is definitely not optimized. Once its doing
2514 * the "right thing" we'll optimize it for efficiency if
2517 /* Search for this entry in the list and update it if it is
2520 spin_lock_irqsave(&ieee
->lock
, flags
);
2521 if (is_same_network(&ieee
->current_network
, network
,
2522 (network
->ssid_len
? 1 : 0))) {
2523 update_network(&ieee
->current_network
, network
);
2524 if ((ieee
->current_network
.mode
== IEEE_N_24G
||
2525 ieee
->current_network
.mode
== IEEE_G
)
2526 && ieee
->current_network
.berp_info_valid
) {
2527 if (ieee
->current_network
.erp_value
& ERP_UseProtection
)
2528 ieee
->current_network
.buseprotection
= true;
2530 ieee
->current_network
.buseprotection
= false;
2532 if (is_beacon(beacon
->header
.frame_ctl
)) {
2533 if (ieee
->state
>= RTLLIB_LINKED
)
2534 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
++;
2537 list_for_each_entry(target
, &ieee
->network_list
, list
) {
2538 if (is_same_network(target
, network
,
2539 (target
->ssid_len
? 1 : 0)))
2541 if ((oldest
== NULL
) ||
2542 (target
->last_scanned
< oldest
->last_scanned
))
2546 /* If we didn't find a match, then get a new network slot to initialize
2547 * with this beacon's information */
2548 if (&target
->list
== &ieee
->network_list
) {
2549 if (list_empty(&ieee
->network_free_list
)) {
2550 /* If there are no more slots, expire the oldest */
2551 list_del(&oldest
->list
);
2553 RTLLIB_DEBUG_SCAN("Expired '%s' ( %pM) from network list.\n",
2554 escape_essid(target
->ssid
,
2558 /* Otherwise just pull from the free list */
2559 target
= list_entry(ieee
->network_free_list
.next
,
2560 struct rtllib_network
, list
);
2561 list_del(ieee
->network_free_list
.next
);
2565 RTLLIB_DEBUG_SCAN("Adding '%s' ( %pM) via %s.\n",
2566 escape_essid(network
->ssid
,
2567 network
->ssid_len
), network
->bssid
,
2569 le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2570 RTLLIB_STYPE_PROBE_RESP
?
2571 "PROBE RESPONSE" : "BEACON");
2572 memcpy(target
, network
, sizeof(*target
));
2573 list_add_tail(&target
->list
, &ieee
->network_list
);
2574 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
)
2575 rtllib_softmac_new_net(ieee
, network
);
2577 RTLLIB_DEBUG_SCAN("Updating '%s' ( %pM) via %s.\n",
2578 escape_essid(target
->ssid
,
2579 target
->ssid_len
), target
->bssid
,
2581 le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2582 RTLLIB_STYPE_PROBE_RESP
?
2583 "PROBE RESPONSE" : "BEACON");
2585 /* we have an entry and we are going to update it. But this
2586 * entry may be already expired. In this case we do the same
2587 * as we found a new net and call the new_net handler
2589 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
,
2591 if ((!target
->ssid_len
) &&
2592 (((network
->ssid_len
> 0) && (target
->hidden_ssid_len
== 0))
2593 || ((ieee
->current_network
.ssid_len
== network
->ssid_len
) &&
2594 (strncmp(ieee
->current_network
.ssid
, network
->ssid
,
2595 network
->ssid_len
) == 0) &&
2596 (ieee
->state
== RTLLIB_NOLINK
))))
2598 update_network(target
, network
);
2599 if (renew
&& (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
))
2600 rtllib_softmac_new_net(ieee
, network
);
2603 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2604 if (is_beacon(beacon
->header
.frame_ctl
) &&
2605 is_same_network(&ieee
->current_network
, network
,
2606 (network
->ssid_len
? 1 : 0)) &&
2607 (ieee
->state
== RTLLIB_LINKED
)) {
2608 if (ieee
->handle_beacon
!= NULL
)
2609 ieee
->handle_beacon(ieee
->dev
, beacon
,
2610 &ieee
->current_network
);
2617 void rtllib_rx_mgt(struct rtllib_device
*ieee
,
2618 struct sk_buff
*skb
,
2619 struct rtllib_rx_stats
*stats
)
2621 struct rtllib_hdr_4addr
*header
= (struct rtllib_hdr_4addr
*)skb
->data
;
2623 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) !=
2624 RTLLIB_STYPE_PROBE_RESP
) &&
2625 (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) !=
2626 RTLLIB_STYPE_BEACON
))
2627 ieee
->last_rx_ps_time
= jiffies
;
2629 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
))) {
2631 case RTLLIB_STYPE_BEACON
:
2632 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
2633 WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)));
2634 RTLLIB_DEBUG_SCAN("Beacon\n");
2635 rtllib_process_probe_response(
2636 ieee
, (struct rtllib_probe_response
*)header
,
2639 if (ieee
->sta_sleep
|| (ieee
->ps
!= RTLLIB_PS_DISABLED
&&
2640 ieee
->iw_mode
== IW_MODE_INFRA
&&
2641 ieee
->state
== RTLLIB_LINKED
))
2642 tasklet_schedule(&ieee
->ps_task
);
2646 case RTLLIB_STYPE_PROBE_RESP
:
2647 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2648 WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)));
2649 RTLLIB_DEBUG_SCAN("Probe response\n");
2650 rtllib_process_probe_response(ieee
,
2651 (struct rtllib_probe_response
*)header
, stats
);
2653 case RTLLIB_STYPE_PROBE_REQ
:
2654 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
2656 le16_to_cpu(header
->frame_ctl
)));
2657 RTLLIB_DEBUG_SCAN("Probe request\n");
2658 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
2659 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
2660 ieee
->iw_mode
== IW_MODE_MASTER
) &&
2661 ieee
->state
== RTLLIB_LINKED
))
2662 rtllib_rx_probe_rq(ieee
, skb
);