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 ether_addr_copy(entry
->src_addr
, hdr
->addr2
);
143 ether_addr_copy(entry
->dst_addr
, hdr
->addr1
);
145 /* received a fragment of a frame for which the head fragment
146 * should have already been received
148 entry
= rtllib_frag_cache_find(ieee
, seq
, frag
, tid
, hdr
->addr2
,
151 entry
->last_frag
= frag
;
160 /* Called only as a tasklet (software IRQ) */
161 static int rtllib_frag_cache_invalidate(struct rtllib_device
*ieee
,
162 struct rtllib_hdr_4addr
*hdr
)
164 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
165 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
166 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
167 struct rtllib_frag_entry
*entry
;
168 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
169 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
172 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
) && RTLLIB_QOS_HAS_SEQ(fc
)) {
173 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)hdr
;
174 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
177 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
178 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)hdr
;
179 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
186 entry
= rtllib_frag_cache_find(ieee
, seq
, -1, tid
, hdr
->addr2
,
190 netdev_dbg(ieee
->dev
,
191 "Couldn't invalidate fragment cache entry (seq=%u)\n",
200 /* rtllib_rx_frame_mgtmt
202 * Responsible for handling management control frames
204 * Called by rtllib_rx
207 rtllib_rx_frame_mgmt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
208 struct rtllib_rx_stats
*rx_stats
, u16 type
,
211 /* On the struct stats definition there is written that
212 * this is not mandatory.... but seems that the probe
213 * response parser uses it
215 struct rtllib_hdr_3addr
*hdr
= (struct rtllib_hdr_3addr
*)skb
->data
;
217 rx_stats
->len
= skb
->len
;
218 rtllib_rx_mgt(ieee
, skb
, rx_stats
);
219 if ((memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
))) {
220 dev_kfree_skb_any(skb
);
223 rtllib_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
225 dev_kfree_skb_any(skb
);
230 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation
231 * Ethernet-II snap header (RFC1042 for most EtherTypes)
233 static unsigned char rfc1042_header
[] = {
234 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
240 /* No encapsulation header if EtherType < 0x600 (=length) */
242 /* Called by rtllib_rx_frame_decrypt */
243 static int rtllib_is_eapol_frame(struct rtllib_device
*ieee
,
244 struct sk_buff
*skb
, size_t hdrlen
)
246 struct net_device
*dev
= ieee
->dev
;
248 struct rtllib_hdr_4addr
*hdr
;
254 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
255 fc
= le16_to_cpu(hdr
->frame_ctl
);
257 /* check that the frame is unicast frame to us */
258 if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
260 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
261 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
262 /* ToDS frame with own addr BSSID and DA */
263 } else if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
264 RTLLIB_FCTL_FROMDS
&&
265 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
266 /* FromDS frame with own addr as DA */
270 if (skb
->len
< 24 + 8)
273 /* check for port access entity Ethernet type */
274 pos
= skb
->data
+ hdrlen
;
275 ethertype
= (pos
[6] << 8) | pos
[7];
276 if (ethertype
== ETH_P_PAE
)
282 /* Called only as a tasklet (software IRQ), by rtllib_rx */
284 rtllib_rx_frame_decrypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
285 struct lib80211_crypt_data
*crypt
)
287 struct rtllib_hdr_4addr
*hdr
;
290 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
293 if (ieee
->hwsec_active
) {
294 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
296 tcb_desc
->bHwSec
= 1;
298 if (ieee
->need_sw_enc
)
299 tcb_desc
->bHwSec
= 0;
302 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
303 hdrlen
= rtllib_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
305 atomic_inc(&crypt
->refcnt
);
306 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
307 atomic_dec(&crypt
->refcnt
);
309 netdev_dbg(ieee
->dev
, "decryption failed (SA= %pM) res=%d\n",
312 netdev_dbg(ieee
->dev
,
313 "Decryption failed ICV 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 lib80211_crypt_data
*crypt
)
328 struct rtllib_hdr_4addr
*hdr
;
331 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
333 if (ieee
->hwsec_active
) {
334 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
);
347 atomic_dec(&crypt
->refcnt
);
349 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed (SA= %pM keyidx=%d)\n",
350 ieee
->dev
->name
, hdr
->addr2
, keyidx
);
358 /* this function is stolen from ipw2200 driver*/
359 #define IEEE_PACKET_RETRY_TIME (5*HZ)
360 static int is_duplicate_packet(struct rtllib_device
*ieee
,
361 struct rtllib_hdr_4addr
*header
)
363 u16 fc
= le16_to_cpu(header
->frame_ctl
);
364 u16 sc
= le16_to_cpu(header
->seq_ctl
);
365 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
366 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
367 u16
*last_seq
, *last_frag
;
368 unsigned long *last_time
;
369 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
370 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
373 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
) && RTLLIB_QOS_HAS_SEQ(fc
)) {
374 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)header
;
375 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
378 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
379 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)header
;
380 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
387 switch (ieee
->iw_mode
) {
391 struct ieee_ibss_seq
*entry
= NULL
;
392 u8
*mac
= header
->addr2
;
393 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
);
405 ether_addr_copy(entry
->mac
, mac
);
406 entry
->seq_num
[tid
] = seq
;
407 entry
->frag_num
[tid
] = frag
;
408 entry
->packet_time
[tid
] = jiffies
;
409 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
412 last_seq
= &entry
->seq_num
[tid
];
413 last_frag
= &entry
->frag_num
[tid
];
414 last_time
= &entry
->packet_time
[tid
];
419 last_seq
= &ieee
->last_rxseq_num
[tid
];
420 last_frag
= &ieee
->last_rxfrag_num
[tid
];
421 last_time
= &ieee
->last_packet_time
[tid
];
427 if ((*last_seq
== seq
) &&
428 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
429 if (*last_frag
== frag
)
431 if (*last_frag
+ 1 != frag
)
432 /* out-of-order fragment */
438 *last_time
= jiffies
;
446 static bool AddReorderEntry(struct rx_ts_record
*pTS
,
447 struct rx_reorder_entry
*pReorderEntry
)
449 struct list_head
*pList
= &pTS
->RxPendingPktList
;
451 while (pList
->next
!= &pTS
->RxPendingPktList
) {
452 if (SN_LESS(pReorderEntry
->SeqNum
, ((struct rx_reorder_entry
*)
453 list_entry(pList
->next
, struct rx_reorder_entry
,
456 else if (SN_EQUAL(pReorderEntry
->SeqNum
,
457 ((struct rx_reorder_entry
*)list_entry(pList
->next
,
458 struct rx_reorder_entry
, List
))->SeqNum
))
463 pReorderEntry
->List
.next
= pList
->next
;
464 pReorderEntry
->List
.next
->prev
= &pReorderEntry
->List
;
465 pReorderEntry
->List
.prev
= pList
;
466 pList
->next
= &pReorderEntry
->List
;
471 void rtllib_indicate_packets(struct rtllib_device
*ieee
, struct rtllib_rxb
**prxbIndicateArray
, u8 index
)
473 struct net_device_stats
*stats
= &ieee
->stats
;
477 for (j
= 0; j
< index
; j
++) {
478 struct rtllib_rxb
*prxb
= prxbIndicateArray
[j
];
480 for (i
= 0; i
< prxb
->nr_subframes
; i
++) {
481 struct sk_buff
*sub_skb
= prxb
->subframes
[i
];
483 /* convert hdr + possible LLC headers into Ethernet header */
484 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
485 if (sub_skb
->len
>= 8 &&
486 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
487 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
488 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
489 /* remove RFC1042 or Bridge-Tunnel encapsulation
490 * and replace EtherType
492 skb_pull(sub_skb
, SNAP_SIZE
);
493 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
494 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
497 /* Leave Ethernet header part of hdr and full payload */
499 memcpy(skb_push(sub_skb
, 2), &len
, 2);
500 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->src
, ETH_ALEN
);
501 memcpy(skb_push(sub_skb
, ETH_ALEN
), prxb
->dst
, ETH_ALEN
);
504 /* Indicate the packets to upper layer */
507 stats
->rx_bytes
+= sub_skb
->len
;
509 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
510 sub_skb
->protocol
= eth_type_trans(sub_skb
, ieee
->dev
);
511 sub_skb
->dev
= ieee
->dev
;
512 sub_skb
->dev
->stats
.rx_packets
++;
513 sub_skb
->dev
->stats
.rx_bytes
+= sub_skb
->len
;
514 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
515 ieee
->last_rx_ps_time
= jiffies
;
524 void rtllib_FlushRxTsPendingPkts(struct rtllib_device
*ieee
, struct rx_ts_record
*pTS
)
526 struct rx_reorder_entry
*pRxReorderEntry
;
529 del_timer_sync(&pTS
->RxPktPendingTimer
);
530 while (!list_empty(&pTS
->RxPendingPktList
)) {
531 if (RfdCnt
>= REORDER_WIN_SIZE
) {
532 netdev_info(ieee
->dev
,
533 "-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n",
538 pRxReorderEntry
= (struct rx_reorder_entry
*)list_entry(pTS
->RxPendingPktList
.prev
, struct rx_reorder_entry
, List
);
539 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Indicate SeqNum %d!\n", __func__
, pRxReorderEntry
->SeqNum
);
540 list_del_init(&pRxReorderEntry
->List
);
542 ieee
->RfdArray
[RfdCnt
] = pRxReorderEntry
->prxb
;
545 list_add_tail(&pRxReorderEntry
->List
, &ieee
->RxReorder_Unused_List
);
547 rtllib_indicate_packets(ieee
, ieee
->RfdArray
, RfdCnt
);
549 pTS
->RxIndicateSeq
= 0xffff;
552 static void RxReorderIndicatePacket(struct rtllib_device
*ieee
,
553 struct rtllib_rxb
*prxb
,
554 struct rx_ts_record
*pTS
, u16 SeqNum
)
556 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
557 struct rx_reorder_entry
*pReorderEntry
= NULL
;
558 u8 WinSize
= pHTInfo
->RxReorderWinSize
;
561 bool bMatchWinStart
= false, bPktInBuf
= false;
564 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Seq is %d, pTS->RxIndicateSeq is %d, WinSize is %d\n", __func__
, SeqNum
,
565 pTS
->RxIndicateSeq
, WinSize
);
567 spin_lock_irqsave(&(ieee
->reorder_spinlock
), flags
);
569 WinEnd
= (pTS
->RxIndicateSeq
+ WinSize
- 1) % 4096;
570 /* Rx Reorder initialize condition.*/
571 if (pTS
->RxIndicateSeq
== 0xffff)
572 pTS
->RxIndicateSeq
= SeqNum
;
574 /* Drop out the packet which SeqNum is smaller than WinStart */
575 if (SN_LESS(SeqNum
, pTS
->RxIndicateSeq
)) {
576 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
577 pTS
->RxIndicateSeq
, SeqNum
);
578 pHTInfo
->RxReorderDropCounter
++;
582 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
583 dev_kfree_skb(prxb
->subframes
[i
]);
587 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
591 /* Sliding window manipulation. Conditions includes:
592 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
593 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
595 if (SN_EQUAL(SeqNum
, pTS
->RxIndicateSeq
)) {
596 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
597 bMatchWinStart
= true;
598 } else if (SN_LESS(WinEnd
, SeqNum
)) {
599 if (SeqNum
>= (WinSize
- 1))
600 pTS
->RxIndicateSeq
= SeqNum
+ 1 - WinSize
;
602 pTS
->RxIndicateSeq
= 4095 - (WinSize
- (SeqNum
+ 1)) + 1;
603 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Window Shift! IndicateSeq: %d, NewSeq: %d\n", pTS
->RxIndicateSeq
, SeqNum
);
606 /* Indication process.
607 * After Packet dropping and Sliding Window shifting as above, we can
608 * now just indicate the packets with the SeqNum smaller than latest
609 * WinStart and struct buffer other packets.
611 * For Rx Reorder condition:
612 * 1. All packets with SeqNum smaller than WinStart => Indicate
613 * 2. All packets with SeqNum larger than or equal to
614 * WinStart => Buffer it.
616 if (bMatchWinStart
) {
617 /* Current packet is going to be indicated.*/
618 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",
619 pTS
->RxIndicateSeq
, SeqNum
);
620 ieee
->prxbIndicateArray
[0] = prxb
;
623 /* Current packet is going to be inserted into pending list.*/
624 if (!list_empty(&ieee
->RxReorder_Unused_List
)) {
625 pReorderEntry
= (struct rx_reorder_entry
*)
626 list_entry(ieee
->RxReorder_Unused_List
.next
,
627 struct rx_reorder_entry
, List
);
628 list_del_init(&pReorderEntry
->List
);
630 /* Make a reorder entry and insert into a the packet list.*/
631 pReorderEntry
->SeqNum
= SeqNum
;
632 pReorderEntry
->prxb
= prxb
;
634 if (!AddReorderEntry(pTS
, pReorderEntry
)) {
635 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,
636 "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
637 __func__
, pTS
->RxIndicateSeq
,
639 list_add_tail(&pReorderEntry
->List
,
640 &ieee
->RxReorder_Unused_List
); {
643 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
644 dev_kfree_skb(prxb
->subframes
[i
]);
649 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,
650 "Pkt insert into struct buffer!! IndicateSeq: %d, NewSeq: %d\n",
651 pTS
->RxIndicateSeq
, SeqNum
);
654 /* Packets are dropped if there are not enough reorder
655 * entries. This part should be modified!! We can just
656 * indicate all the packets in struct buffer and get
659 netdev_err(ieee
->dev
,
660 "%s(): There is no reorder entry! Packet is dropped!\n",
665 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
666 dev_kfree_skb(prxb
->subframes
[i
]);
673 /* Check if there is any packet need indicate.*/
674 while (!list_empty(&pTS
->RxPendingPktList
)) {
675 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): start RREORDER indicate\n", __func__
);
677 pReorderEntry
= (struct rx_reorder_entry
*)list_entry(pTS
->RxPendingPktList
.prev
,
678 struct rx_reorder_entry
, List
);
679 if (SN_LESS(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
) ||
680 SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
)) {
681 /* This protect struct buffer from overflow. */
682 if (index
>= REORDER_WIN_SIZE
) {
683 netdev_err(ieee
->dev
,
684 "%s(): Buffer overflow!\n",
690 list_del_init(&pReorderEntry
->List
);
692 if (SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
693 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
695 ieee
->prxbIndicateArray
[index
] = pReorderEntry
->prxb
;
696 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Indicate SeqNum %d!\n", __func__
, pReorderEntry
->SeqNum
);
699 list_add_tail(&pReorderEntry
->List
,
700 &ieee
->RxReorder_Unused_List
);
707 /* Handling pending timer. Set this timer to prevent from long time
711 if (timer_pending(&pTS
->RxPktPendingTimer
))
712 del_timer_sync(&pTS
->RxPktPendingTimer
);
713 pTS
->RxTimeoutIndicateSeq
= 0xffff;
715 if (index
> REORDER_WIN_SIZE
) {
716 netdev_err(ieee
->dev
,
717 "%s(): Rx Reorder struct buffer full!\n",
719 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
),
723 rtllib_indicate_packets(ieee
, ieee
->prxbIndicateArray
, index
);
727 if (bPktInBuf
&& pTS
->RxTimeoutIndicateSeq
== 0xffff) {
728 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): SET rx timeout timer\n",
730 pTS
->RxTimeoutIndicateSeq
= pTS
->RxIndicateSeq
;
731 mod_timer(&pTS
->RxPktPendingTimer
, jiffies
+
732 msecs_to_jiffies(pHTInfo
->RxReorderPendingTime
));
734 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
737 static u8
parse_subframe(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
738 struct rtllib_rx_stats
*rx_stats
,
739 struct rtllib_rxb
*rxb
, u8
*src
, u8
*dst
)
741 struct rtllib_hdr_3addr
*hdr
= (struct rtllib_hdr_3addr
*)skb
->data
;
742 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
744 u16 LLCOffset
= sizeof(struct rtllib_hdr_3addr
);
746 bool bIsAggregateFrame
= false;
747 u16 nSubframe_Length
;
748 u8 nPadding_Length
= 0;
750 struct sk_buff
*sub_skb
;
752 /* just for debug purpose */
753 SeqNum
= WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr
->seq_ctl
));
754 if ((RTLLIB_QOS_HAS_SEQ(fc
)) &&
755 (((union frameqos
*)(skb
->data
+ RTLLIB_3ADDR_LEN
))->field
.reserved
))
756 bIsAggregateFrame
= true;
758 if (RTLLIB_QOS_HAS_SEQ(fc
))
760 if (rx_stats
->bContainHTC
)
761 LLCOffset
+= sHTCLng
;
763 ChkLength
= LLCOffset
;
765 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
);
785 skb_reserve(sub_skb
, 12);
786 data_ptr
= (u8
*)skb_put(sub_skb
, skb
->len
);
787 memcpy(data_ptr
, skb
->data
, skb
->len
);
788 sub_skb
->dev
= ieee
->dev
;
790 rxb
->subframes
[0] = sub_skb
;
792 memcpy(rxb
->src
, src
, ETH_ALEN
);
793 memcpy(rxb
->dst
, dst
, ETH_ALEN
);
794 rxb
->subframes
[0]->dev
= ieee
->dev
;
798 rxb
->nr_subframes
= 0;
799 memcpy(rxb
->src
, src
, ETH_ALEN
);
800 memcpy(rxb
->dst
, dst
, ETH_ALEN
);
801 while (skb
->len
> ETHERNET_HEADER_SIZE
) {
802 /* Offset 12 denote 2 mac address */
803 nSubframe_Length
= *((u16
*)(skb
->data
+ 12));
804 nSubframe_Length
= (nSubframe_Length
>> 8) +
805 (nSubframe_Length
<< 8);
807 if (skb
->len
< (ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
808 netdev_info(ieee
->dev
,
809 "%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",
810 __func__
, rxb
->nr_subframes
);
811 netdev_info(ieee
->dev
,
812 "%s: A-MSDU parse error!! Subframe Length: %d\n",
813 __func__
, nSubframe_Length
);
814 netdev_info(ieee
->dev
,
815 "nRemain_Length is %d and nSubframe_Length is : %d\n",
816 skb
->len
, nSubframe_Length
);
817 netdev_info(ieee
->dev
,
818 "The Packet SeqNum is %d\n",
823 /* move the data point to data content */
824 skb_pull(skb
, ETHERNET_HEADER_SIZE
);
826 /* altered by clark 3/30/2010
827 * The struct buffer size of the skb indicated to upper layer
828 * must be less than 5000, or the defraged IP datagram
829 * in the IP layer will exceed "ipfrag_high_tresh" and be
830 * discarded. so there must not use the function
831 * "skb_copy" and "skb_clone" for "skb".
834 /* Allocate new skb for releasing to upper layer */
835 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
838 skb_reserve(sub_skb
, 12);
839 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
840 memcpy(data_ptr
, skb
->data
, nSubframe_Length
);
842 sub_skb
->dev
= ieee
->dev
;
843 rxb
->subframes
[rxb
->nr_subframes
++] = sub_skb
;
844 if (rxb
->nr_subframes
>= MAX_SUBFRAME_COUNT
) {
845 netdev_dbg(ieee
->dev
,
846 "ParseSubframe(): Too many Subframes! Packets dropped!\n");
849 skb_pull(skb
, nSubframe_Length
);
852 nPadding_Length
= 4 - ((nSubframe_Length
+
853 ETHERNET_HEADER_SIZE
) % 4);
854 if (nPadding_Length
== 4)
857 if (skb
->len
< nPadding_Length
)
860 skb_pull(skb
, nPadding_Length
);
864 return rxb
->nr_subframes
;
868 static size_t rtllib_rx_get_hdrlen(struct rtllib_device
*ieee
,
870 struct rtllib_rx_stats
*rx_stats
)
872 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
873 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
876 hdrlen
= rtllib_get_hdrlen(fc
);
877 if (HTCCheck(ieee
, skb
->data
)) {
879 netdev_info(ieee
->dev
, "%s: find HTCControl!\n",
882 rx_stats
->bContainHTC
= true;
885 if (RTLLIB_QOS_HAS_SEQ(fc
))
886 rx_stats
->bIsQosData
= true;
891 static int rtllib_rx_check_duplicate(struct rtllib_device
*ieee
,
892 struct sk_buff
*skb
, u8 multicast
)
894 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
896 u8 frag
, type
, stype
;
898 fc
= le16_to_cpu(hdr
->frame_ctl
);
899 type
= WLAN_FC_GET_TYPE(fc
);
900 stype
= WLAN_FC_GET_STYPE(fc
);
901 sc
= le16_to_cpu(hdr
->seq_ctl
);
902 frag
= WLAN_GET_SEQ_FRAG(sc
);
904 if ((ieee
->pHTInfo
->bCurRxReorderEnable
== false) ||
905 !ieee
->current_network
.qos_data
.active
||
906 !IsDataFrame(skb
->data
) ||
907 IsLegacyDataFrame(skb
->data
)) {
908 if (!((type
== RTLLIB_FTYPE_MGMT
) && (stype
== RTLLIB_STYPE_BEACON
))) {
909 if (is_duplicate_packet(ieee
, hdr
))
913 struct rx_ts_record
*pRxTS
= NULL
;
915 if (GetTs(ieee
, (struct ts_common_info
**) &pRxTS
, hdr
->addr2
,
916 (u8
)Frame_QoSTID((u8
*)(skb
->data
)), RX_DIR
, true)) {
917 if ((fc
& (1<<11)) && (frag
== pRxTS
->RxLastFragNum
) &&
918 (WLAN_GET_SEQ_SEQ(sc
) == pRxTS
->RxLastSeqNum
))
920 pRxTS
->RxLastFragNum
= frag
;
921 pRxTS
->RxLastSeqNum
= WLAN_GET_SEQ_SEQ(sc
);
923 netdev_warn(ieee
->dev
, "%s(): No TS! Skip the check!\n",
932 static void rtllib_rx_extract_addr(struct rtllib_device
*ieee
,
933 struct rtllib_hdr_4addr
*hdr
, u8
*dst
,
936 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
938 switch (fc
& (RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
)) {
939 case RTLLIB_FCTL_FROMDS
:
940 ether_addr_copy(dst
, hdr
->addr1
);
941 ether_addr_copy(src
, hdr
->addr3
);
942 ether_addr_copy(bssid
, hdr
->addr2
);
944 case RTLLIB_FCTL_TODS
:
945 ether_addr_copy(dst
, hdr
->addr3
);
946 ether_addr_copy(src
, hdr
->addr2
);
947 ether_addr_copy(bssid
, hdr
->addr1
);
949 case RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
:
950 ether_addr_copy(dst
, hdr
->addr3
);
951 ether_addr_copy(src
, hdr
->addr4
);
952 ether_addr_copy(bssid
, ieee
->current_network
.bssid
);
955 ether_addr_copy(dst
, hdr
->addr1
);
956 ether_addr_copy(src
, hdr
->addr2
);
957 ether_addr_copy(bssid
, hdr
->addr3
);
962 static int rtllib_rx_data_filter(struct rtllib_device
*ieee
, u16 fc
,
963 u8
*dst
, u8
*src
, u8
*bssid
, u8
*addr2
)
967 type
= WLAN_FC_GET_TYPE(fc
);
968 stype
= WLAN_FC_GET_STYPE(fc
);
970 /* Filter frames from different BSS */
971 if (((fc
& RTLLIB_FCTL_DSTODS
) != RTLLIB_FCTL_DSTODS
) &&
972 !ether_addr_equal(ieee
->current_network
.bssid
, bssid
) &&
973 !is_zero_ether_addr(ieee
->current_network
.bssid
)) {
977 /* Filter packets sent by an STA that will be forwarded by AP */
978 if (ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
&&
979 ieee
->IntelPromiscuousModeInfo
.bFilterSourceStationFrame
) {
980 if ((fc
& RTLLIB_FCTL_TODS
) && !(fc
& RTLLIB_FCTL_FROMDS
) &&
981 !ether_addr_equal(dst
, ieee
->current_network
.bssid
) &&
982 ether_addr_equal(bssid
, ieee
->current_network
.bssid
)) {
987 /* Nullfunc frames may have PS-bit set, so they must be passed to
988 * hostap_handle_sta_rx() before being dropped here.
990 if (!ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
) {
991 if (stype
!= RTLLIB_STYPE_DATA
&&
992 stype
!= RTLLIB_STYPE_DATA_CFACK
&&
993 stype
!= RTLLIB_STYPE_DATA_CFPOLL
&&
994 stype
!= RTLLIB_STYPE_DATA_CFACKPOLL
&&
995 stype
!= RTLLIB_STYPE_QOS_DATA
) {
996 if (stype
!= RTLLIB_STYPE_NULLFUNC
)
997 netdev_dbg(ieee
->dev
,
998 "RX: dropped data frame with no data (type=0x%02x, subtype=0x%02x)\n",
1004 if (ieee
->iw_mode
!= IW_MODE_MESH
) {
1005 /* packets from our adapter are dropped (echo) */
1006 if (!memcmp(src
, ieee
->dev
->dev_addr
, ETH_ALEN
))
1009 /* {broad,multi}cast packets to our BSS go through */
1010 if (is_multicast_ether_addr(dst
)) {
1011 if (memcmp(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
))
1018 static int rtllib_rx_get_crypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1019 struct lib80211_crypt_data
**crypt
, size_t hdrlen
)
1021 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1022 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1025 if (ieee
->host_decrypt
) {
1026 if (skb
->len
>= hdrlen
+ 3)
1027 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1029 *crypt
= ieee
->crypt_info
.crypt
[idx
];
1030 /* allow NULL decrypt to indicate an station specific override
1031 * for default encryption
1033 if (*crypt
&& ((*crypt
)->ops
== NULL
||
1034 (*crypt
)->ops
->decrypt_mpdu
== NULL
))
1037 if (!*crypt
&& (fc
& RTLLIB_FCTL_WEP
)) {
1038 /* This seems to be triggered by some (multicast?)
1039 * frames from other than current BSS, so just drop the
1040 * frames silently instead of filling system log with
1043 netdev_dbg(ieee
->dev
,
1044 "Decryption failed (not set) (SA= %pM)\n",
1046 ieee
->ieee_stats
.rx_discards_undecryptable
++;
1054 static int rtllib_rx_decrypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1055 struct rtllib_rx_stats
*rx_stats
,
1056 struct lib80211_crypt_data
*crypt
, size_t hdrlen
)
1058 struct rtllib_hdr_4addr
*hdr
;
1063 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1064 fc
= le16_to_cpu(hdr
->frame_ctl
);
1065 sc
= le16_to_cpu(hdr
->seq_ctl
);
1066 frag
= WLAN_GET_SEQ_FRAG(sc
);
1068 if ((!rx_stats
->Decrypted
))
1069 ieee
->need_sw_enc
= 1;
1071 ieee
->need_sw_enc
= 0;
1073 keyidx
= rtllib_rx_frame_decrypt(ieee
, skb
, crypt
);
1074 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) && (keyidx
< 0)) {
1075 netdev_info(ieee
->dev
, "%s: decrypt frame error\n", __func__
);
1079 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1080 if ((frag
!= 0 || (fc
& RTLLIB_FCTL_MOREFRAGS
))) {
1082 struct sk_buff
*frag_skb
= rtllib_frag_cache_get(ieee
, hdr
);
1084 netdev_dbg(ieee
->dev
, "Rx Fragment received (%u)\n", frag
);
1087 RTLLIB_DEBUG(RTLLIB_DL_RX
| RTLLIB_DL_FRAG
,
1088 "Rx cannot get skb from fragment cache (morefrag=%d seq=%u frag=%u)\n",
1089 (fc
& RTLLIB_FCTL_MOREFRAGS
) != 0,
1090 WLAN_GET_SEQ_SEQ(sc
), frag
);
1097 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
1098 netdev_warn(ieee
->dev
,
1099 "%s: host decrypted and reassembled frame did not fit skb\n",
1101 rtllib_frag_cache_invalidate(ieee
, hdr
);
1106 /* copy first fragment (including full headers) into
1107 * beginning of the fragment cache skb
1109 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
1111 /* append frame payload to the end of the fragment
1114 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
1117 dev_kfree_skb_any(skb
);
1120 if (fc
& RTLLIB_FCTL_MOREFRAGS
) {
1121 /* more fragments expected - leave the skb in fragment
1122 * cache for now; it will be delivered to upper layers
1123 * after all fragments have been received
1128 /* this was the last fragment and the frame will be
1129 * delivered, so remove skb from fragment cache
1132 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1133 rtllib_frag_cache_invalidate(ieee
, hdr
);
1136 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1137 * encrypted/authenticated
1139 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) &&
1140 rtllib_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
)) {
1141 netdev_info(ieee
->dev
, "%s: ==>decrypt msdu error\n", __func__
);
1145 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1146 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
) {
1147 if (/*ieee->ieee802_1x &&*/
1148 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1150 /* pass unencrypted EAPOL frames even if encryption is
1153 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1155 netdev_dbg(ieee
->dev
,
1156 "RX: IEEE 802.1X EAPOL frame: %s\n",
1157 eap_get_type(eap
->type
));
1159 netdev_dbg(ieee
->dev
,
1160 "encryption configured, but RX frame not encrypted (SA= %pM)\n",
1166 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) &&
1167 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1168 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1170 netdev_dbg(ieee
->dev
,
1171 "RX: IEEE 802.1X EAPOL frame: %s\n",
1172 eap_get_type(eap
->type
));
1175 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
&&
1176 !rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1177 netdev_dbg(ieee
->dev
,
1178 "dropped unencrypted RX data frame from %pM (drop_unencrypted=1)\n",
1183 if (rtllib_is_eapol_frame(ieee
, skb
, hdrlen
))
1184 netdev_warn(ieee
->dev
, "RX: IEEE802.1X EAPOL frame!\n");
1189 static void rtllib_rx_check_leave_lps(struct rtllib_device
*ieee
, u8 unicast
, u8 nr_subframes
)
1193 if (ieee
->state
== RTLLIB_LINKED
) {
1194 if (((ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+
1195 ieee
->LinkDetectInfo
.NumTxOkInPeriod
) > 8) ||
1196 (ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
> 2)) {
1197 if (ieee
->LeisurePSLeave
)
1198 ieee
->LeisurePSLeave(ieee
->dev
);
1202 ieee
->last_rx_ps_time
= jiffies
;
1205 static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device
*ieee
,
1206 struct rtllib_rx_stats
*rx_stats
,
1207 struct rtllib_rxb
*rxb
,
1211 struct net_device
*dev
= ieee
->dev
;
1216 netdev_info(dev
, "%s: rxb is NULL!!\n", __func__
);
1220 for (i
= 0; i
< rxb
->nr_subframes
; i
++) {
1221 struct sk_buff
*sub_skb
= rxb
->subframes
[i
];
1224 /* convert hdr + possible LLC headers into Ethernet header */
1225 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
1226 if (sub_skb
->len
>= 8 &&
1227 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
1228 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1229 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
1230 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1233 skb_pull(sub_skb
, SNAP_SIZE
);
1234 ether_addr_copy(skb_push(sub_skb
, ETH_ALEN
),
1236 ether_addr_copy(skb_push(sub_skb
, ETH_ALEN
),
1240 /* Leave Ethernet header part of hdr and full payload */
1242 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1243 ether_addr_copy(skb_push(sub_skb
, ETH_ALEN
),
1245 ether_addr_copy(skb_push(sub_skb
, ETH_ALEN
),
1249 ieee
->stats
.rx_packets
++;
1250 ieee
->stats
.rx_bytes
+= sub_skb
->len
;
1252 if (is_multicast_ether_addr(dst
))
1253 ieee
->stats
.multicast
++;
1255 /* Indicate the packets to upper layer */
1256 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
1257 sub_skb
->protocol
= eth_type_trans(sub_skb
, dev
);
1259 sub_skb
->dev
->stats
.rx_packets
++;
1260 sub_skb
->dev
->stats
.rx_bytes
+= sub_skb
->len
;
1261 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
1268 static int rtllib_rx_InfraAdhoc(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1269 struct rtllib_rx_stats
*rx_stats
)
1271 struct net_device
*dev
= ieee
->dev
;
1272 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1273 struct lib80211_crypt_data
*crypt
= NULL
;
1274 struct rtllib_rxb
*rxb
= NULL
;
1275 struct rx_ts_record
*pTS
= NULL
;
1276 u16 fc
, sc
, SeqNum
= 0;
1277 u8 type
, stype
, multicast
= 0, unicast
= 0, nr_subframes
= 0, TID
= 0;
1281 u8 bssid
[ETH_ALEN
] = {0};
1284 bool bToOtherSTA
= false;
1287 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1288 fc
= le16_to_cpu(hdr
->frame_ctl
);
1289 type
= WLAN_FC_GET_TYPE(fc
);
1290 stype
= WLAN_FC_GET_STYPE(fc
);
1291 sc
= le16_to_cpu(hdr
->seq_ctl
);
1293 /*Filter pkt not to me*/
1294 multicast
= is_multicast_ether_addr(hdr
->addr1
);
1295 unicast
= !multicast
;
1296 if (unicast
&& !ether_addr_equal(dev
->dev_addr
, hdr
->addr1
)) {
1297 if (ieee
->bNetPromiscuousMode
)
1303 /*Filter pkt has too small length */
1304 hdrlen
= rtllib_rx_get_hdrlen(ieee
, skb
, rx_stats
);
1305 if (skb
->len
< hdrlen
) {
1306 netdev_info(dev
, "%s():ERR!!! skb->len is smaller than hdrlen\n",
1311 /* Filter Duplicate pkt */
1312 ret
= rtllib_rx_check_duplicate(ieee
, skb
, multicast
);
1316 /* Filter CTRL Frame */
1317 if (type
== RTLLIB_FTYPE_CTL
)
1320 /* Filter MGNT Frame */
1321 if (type
== RTLLIB_FTYPE_MGMT
) {
1324 if (rtllib_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
1330 /* Filter WAPI DATA Frame */
1332 /* Update statstics for AP roaming */
1334 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
++;
1335 ieee
->LinkDetectInfo
.NumRxOkInPeriod
++;
1337 dev
->last_rx
= jiffies
;
1339 /* Data frame - extract src/dst addresses */
1340 rtllib_rx_extract_addr(ieee
, hdr
, dst
, src
, bssid
);
1342 /* Filter Data frames */
1343 ret
= rtllib_rx_data_filter(ieee
, fc
, dst
, src
, bssid
, hdr
->addr2
);
1347 if (skb
->len
== hdrlen
)
1350 /* Send pspoll based on moredata */
1351 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && (ieee
->sta_sleep
== LPS_IS_SLEEP
)
1352 && (ieee
->polling
) && (!bToOtherSTA
)) {
1353 if (WLAN_FC_MORE_DATA(fc
)) {
1354 /* more data bit is set, let's request a new frame from the AP */
1355 rtllib_sta_ps_send_pspoll_frame(ieee
);
1357 ieee
->polling
= false;
1361 /* Get crypt if encrypted */
1362 ret
= rtllib_rx_get_crypt(ieee
, skb
, &crypt
, hdrlen
);
1366 /* Decrypt data frame (including reassemble) */
1367 ret
= rtllib_rx_decrypt(ieee
, skb
, rx_stats
, crypt
, hdrlen
);
1373 /* Get TS for Rx Reorder */
1374 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1375 if (ieee
->current_network
.qos_data
.active
&& IsQoSDataFrame(skb
->data
)
1376 && !is_multicast_ether_addr(hdr
->addr1
)
1377 && (!bToOtherSTA
)) {
1378 TID
= Frame_QoSTID(skb
->data
);
1379 SeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1380 GetTs(ieee
, (struct ts_common_info
**) &pTS
, hdr
->addr2
, TID
, RX_DIR
, true);
1381 if (TID
!= 0 && TID
!= 3)
1382 ieee
->bis_any_nonbepkts
= true;
1385 /* Parse rx data frame (For AMSDU) */
1386 /* skb: hdr + (possible reassembled) full plaintext payload */
1387 payload
= skb
->data
+ hdrlen
;
1388 rxb
= kmalloc(sizeof(struct rtllib_rxb
), GFP_ATOMIC
);
1392 /* to parse amsdu packets */
1393 /* qos data packets & reserved bit is 1 */
1394 if (parse_subframe(ieee
, skb
, rx_stats
, rxb
, src
, dst
) == 0) {
1395 /* only to free rxb, and not submit the packets to upper layer */
1396 for (i
= 0; i
< rxb
->nr_subframes
; i
++)
1397 dev_kfree_skb(rxb
->subframes
[i
]);
1403 /* Update WAPI PN */
1405 /* Check if leave LPS */
1407 if (ieee
->bIsAggregateFrame
)
1408 nr_subframes
= rxb
->nr_subframes
;
1412 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+= nr_subframes
;
1413 rtllib_rx_check_leave_lps(ieee
, unicast
, nr_subframes
);
1416 /* Indicate packets to upper layer or Rx Reorder */
1417 if (ieee
->pHTInfo
->bCurRxReorderEnable
== false || pTS
== NULL
|| bToOtherSTA
)
1418 rtllib_rx_indicate_pkt_legacy(ieee
, rx_stats
, rxb
, dst
, src
);
1420 RxReorderIndicatePacket(ieee
, rxb
, pTS
, SeqNum
);
1428 ieee
->stats
.rx_dropped
++;
1430 /* Returning 0 indicates to caller that we have not handled the SKB--
1431 * so it is still allocated and can be used again by underlying
1432 * hardware as a DMA target
1437 static int rtllib_rx_Master(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1438 struct rtllib_rx_stats
*rx_stats
)
1443 static int rtllib_rx_Monitor(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1444 struct rtllib_rx_stats
*rx_stats
)
1446 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1447 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1448 size_t hdrlen
= rtllib_get_hdrlen(fc
);
1450 if (skb
->len
< hdrlen
) {
1451 netdev_info(ieee
->dev
,
1452 "%s():ERR!!! skb->len is smaller than hdrlen\n",
1457 if (HTCCheck(ieee
, skb
->data
)) {
1458 if (net_ratelimit())
1459 netdev_info(ieee
->dev
, "%s: Find HTCControl!\n",
1464 rtllib_monitor_rx(ieee
, skb
, rx_stats
, hdrlen
);
1465 ieee
->stats
.rx_packets
++;
1466 ieee
->stats
.rx_bytes
+= skb
->len
;
1471 static int rtllib_rx_Mesh(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1472 struct rtllib_rx_stats
*rx_stats
)
1477 /* All received frames are sent to this function. @skb contains the frame in
1478 * IEEE 802.11 format, i.e., in the format it was sent over air.
1479 * This function is called only as a tasklet (software IRQ).
1481 int rtllib_rx(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1482 struct rtllib_rx_stats
*rx_stats
)
1486 if ((NULL
== ieee
) || (NULL
== skb
) || (NULL
== rx_stats
)) {
1487 pr_info("%s: Input parameters NULL!\n", __func__
);
1490 if (skb
->len
< 10) {
1491 netdev_info(ieee
->dev
, "%s: SKB length < 10\n", __func__
);
1495 switch (ieee
->iw_mode
) {
1498 ret
= rtllib_rx_InfraAdhoc(ieee
, skb
, rx_stats
);
1500 case IW_MODE_MASTER
:
1501 case IW_MODE_REPEAT
:
1502 ret
= rtllib_rx_Master(ieee
, skb
, rx_stats
);
1504 case IW_MODE_MONITOR
:
1505 ret
= rtllib_rx_Monitor(ieee
, skb
, rx_stats
);
1508 ret
= rtllib_rx_Mesh(ieee
, skb
, rx_stats
);
1511 netdev_info(ieee
->dev
, "%s: ERR iw mode!!!\n", __func__
);
1519 ieee
->stats
.rx_dropped
++;
1522 EXPORT_SYMBOL(rtllib_rx
);
1524 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
1526 /* Make ther structure we read from the beacon packet has the right values */
1527 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1528 *info_element
, int sub_type
)
1531 if (info_element
->qui_subtype
!= sub_type
)
1533 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
1535 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
1537 if (info_element
->version
!= QOS_VERSION_1
)
1544 /* Parse a QoS parameter element */
1545 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
1546 *element_param
, struct rtllib_info_element
1550 u16 size
= sizeof(struct rtllib_qos_parameter_info
) - 2;
1552 if ((info_element
== NULL
) || (element_param
== NULL
))
1555 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
1556 memcpy(element_param
->info_element
.qui
, info_element
->data
,
1558 element_param
->info_element
.elementID
= info_element
->id
;
1559 element_param
->info_element
.length
= info_element
->len
;
1563 ret
= rtllib_verify_qos_info(&element_param
->info_element
,
1564 QOS_OUI_PARAM_SUB_TYPE
);
1568 /* Parse a QoS information element */
1569 static int rtllib_read_qos_info_element(struct
1570 rtllib_qos_information_element
1571 *element_info
, struct rtllib_info_element
1575 u16 size
= sizeof(struct rtllib_qos_information_element
) - 2;
1577 if (element_info
== NULL
)
1579 if (info_element
== NULL
)
1582 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
1583 memcpy(element_info
->qui
, info_element
->data
,
1585 element_info
->elementID
= info_element
->id
;
1586 element_info
->length
= info_element
->len
;
1591 ret
= rtllib_verify_qos_info(element_info
,
1592 QOS_OUI_INFO_SUB_TYPE
);
1597 /* Write QoS parameters from the ac parameters. */
1598 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info
*param_elm
,
1599 struct rtllib_qos_data
*qos_data
)
1601 struct rtllib_qos_ac_parameter
*ac_params
;
1602 struct rtllib_qos_parameters
*qos_param
= &(qos_data
->parameters
);
1607 qos_data
->wmm_acm
= 0;
1608 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1609 ac_params
= &(param_elm
->ac_params_record
[i
]);
1611 aci
= (ac_params
->aci_aifsn
& 0x60) >> 5;
1612 acm
= (ac_params
->aci_aifsn
& 0x10) >> 4;
1614 if (aci
>= QOS_QUEUE_NUM
)
1618 /* BIT(0) | BIT(3) */
1620 qos_data
->wmm_acm
|= (0x01<<0)|(0x01<<3);
1623 /* BIT(4) | BIT(5) */
1625 qos_data
->wmm_acm
|= (0x01<<4)|(0x01<<5);
1628 /* BIT(6) | BIT(7) */
1630 qos_data
->wmm_acm
|= (0x01<<6)|(0x01<<7);
1634 /* BIT(1) | BIT(2) */
1636 qos_data
->wmm_acm
|= (0x01<<1)|(0x01<<2);
1640 qos_param
->aifs
[aci
] = (ac_params
->aci_aifsn
) & 0x0f;
1642 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1643 qos_param
->aifs
[aci
] = (qos_param
->aifs
[aci
] < 2) ? 2 : qos_param
->aifs
[aci
];
1645 qos_param
->cw_min
[aci
] = cpu_to_le16(ac_params
->ecw_min_max
& 0x0F);
1647 qos_param
->cw_max
[aci
] = cpu_to_le16((ac_params
->ecw_min_max
& 0xF0) >> 4);
1649 qos_param
->flag
[aci
] =
1650 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1651 qos_param
->tx_op_limit
[aci
] = ac_params
->tx_op_limit
;
1656 /* we have a generic data element which it may contain QoS information or
1657 * parameters element. check the information element length to decide
1658 * which type to read
1660 static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
1662 struct rtllib_network
*network
)
1665 struct rtllib_qos_information_element qos_info_element
;
1667 rc
= rtllib_read_qos_info_element(&qos_info_element
, info_element
);
1670 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1671 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1673 struct rtllib_qos_parameter_info param_element
;
1675 rc
= rtllib_read_qos_param_element(¶m_element
,
1678 rtllib_qos_convert_ac_to_parameters(¶m_element
,
1679 &(network
->qos_data
));
1680 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1681 network
->qos_data
.param_count
=
1682 param_element
.info_element
.ac_info
& 0x0F;
1687 RTLLIB_DEBUG_QOS("QoS is supported\n");
1688 network
->qos_data
.supported
= 1;
1693 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1695 static const char *get_info_element_string(u16 id
)
1700 MFIE_STRING(FH_SET
);
1701 MFIE_STRING(DS_SET
);
1702 MFIE_STRING(CF_SET
);
1704 MFIE_STRING(IBSS_SET
);
1705 MFIE_STRING(COUNTRY
);
1706 MFIE_STRING(HOP_PARAMS
);
1707 MFIE_STRING(HOP_TABLE
);
1708 MFIE_STRING(REQUEST
);
1709 MFIE_STRING(CHALLENGE
);
1710 MFIE_STRING(POWER_CONSTRAINT
);
1711 MFIE_STRING(POWER_CAPABILITY
);
1712 MFIE_STRING(TPC_REQUEST
);
1713 MFIE_STRING(TPC_REPORT
);
1714 MFIE_STRING(SUPP_CHANNELS
);
1716 MFIE_STRING(MEASURE_REQUEST
);
1717 MFIE_STRING(MEASURE_REPORT
);
1719 MFIE_STRING(IBSS_DFS
);
1721 MFIE_STRING(RATES_EX
);
1722 MFIE_STRING(GENERIC
);
1723 MFIE_STRING(QOS_PARAMETER
);
1729 static inline void rtllib_extract_country_ie(
1730 struct rtllib_device
*ieee
,
1731 struct rtllib_info_element
*info_element
,
1732 struct rtllib_network
*network
,
1735 if (IS_DOT11D_ENABLE(ieee
)) {
1736 if (info_element
->len
!= 0) {
1737 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
1738 network
->CountryIeLen
= info_element
->len
;
1740 if (!IS_COUNTRY_IE_VALID(ieee
)) {
1741 if (rtllib_act_scanning(ieee
, false) && ieee
->FirstIe_InScan
)
1742 netdev_info(ieee
->dev
,
1743 "Received beacon ContryIE, SSID: <%s>\n",
1745 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
1749 if (IS_EQUAL_CIE_SRC(ieee
, addr2
))
1750 UPDATE_CIE_WATCHDOG(ieee
);
1755 static void rtllib_parse_mife_generic(struct rtllib_device
*ieee
,
1756 struct rtllib_info_element
*info_element
,
1757 struct rtllib_network
*network
,
1759 u16
*tmp_htinfo_len
)
1761 u16 ht_realtek_agg_len
= 0;
1762 u8 ht_realtek_agg_buf
[MAX_IE_LEN
];
1764 if (!rtllib_parse_qos_info_param_IE(info_element
, network
))
1766 if (info_element
->len
>= 4 &&
1767 info_element
->data
[0] == 0x00 &&
1768 info_element
->data
[1] == 0x50 &&
1769 info_element
->data
[2] == 0xf2 &&
1770 info_element
->data
[3] == 0x01) {
1771 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1773 memcpy(network
->wpa_ie
, info_element
, network
->wpa_ie_len
);
1776 if (info_element
->len
== 7 &&
1777 info_element
->data
[0] == 0x00 &&
1778 info_element
->data
[1] == 0xe0 &&
1779 info_element
->data
[2] == 0x4c &&
1780 info_element
->data
[3] == 0x01 &&
1781 info_element
->data
[4] == 0x02)
1782 network
->Turbo_Enable
= 1;
1784 if (*tmp_htcap_len
== 0) {
1785 if (info_element
->len
>= 4 &&
1786 info_element
->data
[0] == 0x00 &&
1787 info_element
->data
[1] == 0x90 &&
1788 info_element
->data
[2] == 0x4c &&
1789 info_element
->data
[3] == 0x033) {
1791 *tmp_htcap_len
= min_t(u8
, info_element
->len
,
1793 if (*tmp_htcap_len
!= 0) {
1794 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1795 network
->bssht
.bdHTCapLen
= min_t(u16
, *tmp_htcap_len
, sizeof(network
->bssht
.bdHTCapBuf
));
1796 memcpy(network
->bssht
.bdHTCapBuf
,
1798 network
->bssht
.bdHTCapLen
);
1801 if (*tmp_htcap_len
!= 0) {
1802 network
->bssht
.bdSupportHT
= true;
1803 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)(network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0);
1805 network
->bssht
.bdSupportHT
= false;
1806 network
->bssht
.bdHT1R
= false;
1811 if (*tmp_htinfo_len
== 0) {
1812 if (info_element
->len
>= 4 &&
1813 info_element
->data
[0] == 0x00 &&
1814 info_element
->data
[1] == 0x90 &&
1815 info_element
->data
[2] == 0x4c &&
1816 info_element
->data
[3] == 0x034) {
1817 *tmp_htinfo_len
= min_t(u8
, info_element
->len
,
1819 if (*tmp_htinfo_len
!= 0) {
1820 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1821 network
->bssht
.bdHTInfoLen
= min_t(u16
, *tmp_htinfo_len
, sizeof(network
->bssht
.bdHTInfoBuf
));
1822 memcpy(network
->bssht
.bdHTInfoBuf
,
1824 network
->bssht
.bdHTInfoLen
);
1830 if (ieee
->aggregation
) {
1831 if (network
->bssht
.bdSupportHT
) {
1832 if (info_element
->len
>= 4 &&
1833 info_element
->data
[0] == 0x00 &&
1834 info_element
->data
[1] == 0xe0 &&
1835 info_element
->data
[2] == 0x4c &&
1836 info_element
->data
[3] == 0x02) {
1837 ht_realtek_agg_len
= min_t(u8
,
1840 memcpy(ht_realtek_agg_buf
,
1844 if (ht_realtek_agg_len
>= 5) {
1845 network
->realtek_cap_exit
= true;
1846 network
->bssht
.bdRT2RTAggregation
= true;
1848 if ((ht_realtek_agg_buf
[4] == 1) &&
1849 (ht_realtek_agg_buf
[5] & 0x02))
1850 network
->bssht
.bdRT2RTLongSlotTime
= true;
1852 if ((ht_realtek_agg_buf
[4] == 1) &&
1853 (ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_92SE
))
1854 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_92SE
;
1857 if (ht_realtek_agg_len
>= 5) {
1858 if ((ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_SOFTAP
))
1859 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_SOFTAP
;
1863 if ((info_element
->len
>= 3 &&
1864 info_element
->data
[0] == 0x00 &&
1865 info_element
->data
[1] == 0x05 &&
1866 info_element
->data
[2] == 0xb5) ||
1867 (info_element
->len
>= 3 &&
1868 info_element
->data
[0] == 0x00 &&
1869 info_element
->data
[1] == 0x0a &&
1870 info_element
->data
[2] == 0xf7) ||
1871 (info_element
->len
>= 3 &&
1872 info_element
->data
[0] == 0x00 &&
1873 info_element
->data
[1] == 0x10 &&
1874 info_element
->data
[2] == 0x18)) {
1875 network
->broadcom_cap_exist
= true;
1877 if (info_element
->len
>= 3 &&
1878 info_element
->data
[0] == 0x00 &&
1879 info_element
->data
[1] == 0x0c &&
1880 info_element
->data
[2] == 0x43)
1881 network
->ralink_cap_exist
= true;
1882 if ((info_element
->len
>= 3 &&
1883 info_element
->data
[0] == 0x00 &&
1884 info_element
->data
[1] == 0x03 &&
1885 info_element
->data
[2] == 0x7f) ||
1886 (info_element
->len
>= 3 &&
1887 info_element
->data
[0] == 0x00 &&
1888 info_element
->data
[1] == 0x13 &&
1889 info_element
->data
[2] == 0x74))
1890 network
->atheros_cap_exist
= true;
1892 if ((info_element
->len
>= 3 &&
1893 info_element
->data
[0] == 0x00 &&
1894 info_element
->data
[1] == 0x50 &&
1895 info_element
->data
[2] == 0x43))
1896 network
->marvell_cap_exist
= true;
1897 if (info_element
->len
>= 3 &&
1898 info_element
->data
[0] == 0x00 &&
1899 info_element
->data
[1] == 0x40 &&
1900 info_element
->data
[2] == 0x96)
1901 network
->cisco_cap_exist
= true;
1904 if (info_element
->len
>= 3 &&
1905 info_element
->data
[0] == 0x00 &&
1906 info_element
->data
[1] == 0x0a &&
1907 info_element
->data
[2] == 0xf5)
1908 network
->airgo_cap_exist
= true;
1910 if (info_element
->len
> 4 &&
1911 info_element
->data
[0] == 0x00 &&
1912 info_element
->data
[1] == 0x40 &&
1913 info_element
->data
[2] == 0x96 &&
1914 info_element
->data
[3] == 0x01) {
1915 if (info_element
->len
== 6) {
1916 memcpy(network
->CcxRmState
, &info_element
[4], 2);
1917 if (network
->CcxRmState
[0] != 0)
1918 network
->bCcxRmEnable
= true;
1920 network
->bCcxRmEnable
= false;
1921 network
->MBssidMask
= network
->CcxRmState
[1] & 0x07;
1922 if (network
->MBssidMask
!= 0) {
1923 network
->bMBssidValid
= true;
1924 network
->MBssidMask
= 0xff << (network
->MBssidMask
);
1925 ether_addr_copy(network
->MBssid
,
1927 network
->MBssid
[5] &= network
->MBssidMask
;
1929 network
->bMBssidValid
= false;
1932 network
->bCcxRmEnable
= false;
1935 if (info_element
->len
> 4 &&
1936 info_element
->data
[0] == 0x00 &&
1937 info_element
->data
[1] == 0x40 &&
1938 info_element
->data
[2] == 0x96 &&
1939 info_element
->data
[3] == 0x03) {
1940 if (info_element
->len
== 5) {
1941 network
->bWithCcxVerNum
= true;
1942 network
->BssCcxVerNumber
= info_element
->data
[4];
1944 network
->bWithCcxVerNum
= false;
1945 network
->BssCcxVerNumber
= 0;
1948 if (info_element
->len
> 4 &&
1949 info_element
->data
[0] == 0x00 &&
1950 info_element
->data
[1] == 0x50 &&
1951 info_element
->data
[2] == 0xf2 &&
1952 info_element
->data
[3] == 0x04) {
1953 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
1955 network
->wzc_ie_len
= min(info_element
->len
+2,
1957 memcpy(network
->wzc_ie
, info_element
,
1958 network
->wzc_ie_len
);
1962 int rtllib_parse_info_param(struct rtllib_device
*ieee
,
1963 struct rtllib_info_element
*info_element
,
1965 struct rtllib_network
*network
,
1966 struct rtllib_rx_stats
*stats
)
1970 u16 tmp_htcap_len
= 0;
1971 u16 tmp_htinfo_len
= 0;
1975 while (length
>= sizeof(*info_element
)) {
1976 if (sizeof(*info_element
) + info_element
->len
> length
) {
1977 RTLLIB_DEBUG_MGMT("Info elem: parse failed: info_element->len + 2 > left : info_element->len+2=%zd left=%d, id=%d.\n",
1979 sizeof(*info_element
),
1980 length
, info_element
->id
);
1981 /* We stop processing but don't return an error here
1982 * because some misbehaviour APs break this rule. ie.
1988 switch (info_element
->id
) {
1989 case MFIE_TYPE_SSID
:
1990 if (rtllib_is_empty_essid(info_element
->data
,
1991 info_element
->len
)) {
1992 network
->flags
|= NETWORK_EMPTY_ESSID
;
1996 network
->ssid_len
= min(info_element
->len
,
1997 (u8
) IW_ESSID_MAX_SIZE
);
1998 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
1999 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
2000 memset(network
->ssid
+ network
->ssid_len
, 0,
2001 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
2003 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
2004 network
->ssid
, network
->ssid_len
);
2007 case MFIE_TYPE_RATES
:
2009 network
->rates_len
= min(info_element
->len
,
2011 for (i
= 0; i
< network
->rates_len
; i
++) {
2012 network
->rates
[i
] = info_element
->data
[i
];
2013 p
+= snprintf(p
, sizeof(rates_str
) -
2014 (p
- rates_str
), "%02X ",
2016 if (rtllib_is_ofdm_rate
2017 (info_element
->data
[i
])) {
2018 network
->flags
|= NETWORK_HAS_OFDM
;
2019 if (info_element
->data
[i
] &
2020 RTLLIB_BASIC_RATE_MASK
)
2025 if (rtllib_is_cck_rate
2026 (info_element
->data
[i
])) {
2027 network
->flags
|= NETWORK_HAS_CCK
;
2031 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
2032 rates_str
, network
->rates_len
);
2035 case MFIE_TYPE_RATES_EX
:
2037 network
->rates_ex_len
= min(info_element
->len
,
2038 MAX_RATES_EX_LENGTH
);
2039 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
2040 network
->rates_ex
[i
] = info_element
->data
[i
];
2041 p
+= snprintf(p
, sizeof(rates_str
) -
2042 (p
- rates_str
), "%02X ",
2043 network
->rates_ex
[i
]);
2044 if (rtllib_is_ofdm_rate
2045 (info_element
->data
[i
])) {
2046 network
->flags
|= NETWORK_HAS_OFDM
;
2047 if (info_element
->data
[i
] &
2048 RTLLIB_BASIC_RATE_MASK
)
2054 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
2055 rates_str
, network
->rates_ex_len
);
2058 case MFIE_TYPE_DS_SET
:
2059 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
2060 info_element
->data
[0]);
2061 network
->channel
= info_element
->data
[0];
2064 case MFIE_TYPE_FH_SET
:
2065 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
2068 case MFIE_TYPE_CF_SET
:
2069 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
2073 if (info_element
->len
< 4)
2076 network
->tim
.tim_count
= info_element
->data
[0];
2077 network
->tim
.tim_period
= info_element
->data
[1];
2079 network
->dtim_period
= info_element
->data
[1];
2080 if (ieee
->state
!= RTLLIB_LINKED
)
2082 network
->last_dtim_sta_time
= jiffies
;
2084 network
->dtim_data
= RTLLIB_DTIM_VALID
;
2087 if (info_element
->data
[2] & 1)
2088 network
->dtim_data
|= RTLLIB_DTIM_MBCAST
;
2090 offset
= (info_element
->data
[2] >> 1)*2;
2093 if (ieee
->assoc_id
< 8*offset
||
2094 ieee
->assoc_id
> 8*(offset
+ info_element
->len
- 3))
2097 offset
= (ieee
->assoc_id
/ 8) - offset
;
2098 if (info_element
->data
[3 + offset
] &
2099 (1 << (ieee
->assoc_id
% 8)))
2100 network
->dtim_data
|= RTLLIB_DTIM_UCAST
;
2102 network
->listen_interval
= network
->dtim_period
;
2106 network
->erp_value
= info_element
->data
[0];
2107 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
2108 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
2109 network
->erp_value
);
2111 case MFIE_TYPE_IBSS_SET
:
2112 network
->atim_window
= info_element
->data
[0];
2113 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
2114 network
->atim_window
);
2117 case MFIE_TYPE_CHALLENGE
:
2118 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
2121 case MFIE_TYPE_GENERIC
:
2122 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
2124 rtllib_parse_mife_generic(ieee
, info_element
, network
,
2130 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2132 network
->rsn_ie_len
= min(info_element
->len
+ 2,
2134 memcpy(network
->rsn_ie
, info_element
,
2135 network
->rsn_ie_len
);
2138 case MFIE_TYPE_HT_CAP
:
2139 netdev_dbg(ieee
->dev
, "MFIE_TYPE_HT_CAP: %d bytes\n",
2141 tmp_htcap_len
= min_t(u8
, info_element
->len
, MAX_IE_LEN
);
2142 if (tmp_htcap_len
!= 0) {
2143 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
2144 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
) ?
2145 sizeof(network
->bssht
.bdHTCapBuf
) : tmp_htcap_len
;
2146 memcpy(network
->bssht
.bdHTCapBuf
,
2148 network
->bssht
.bdHTCapLen
);
2150 network
->bssht
.bdSupportHT
= true;
2151 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)
2152 network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0;
2154 network
->bssht
.bdBandWidth
= (enum ht_channel_width
)
2155 (((struct ht_capab_ele
*)
2156 (network
->bssht
.bdHTCapBuf
))->ChlWidth
);
2158 network
->bssht
.bdSupportHT
= false;
2159 network
->bssht
.bdHT1R
= false;
2160 network
->bssht
.bdBandWidth
= HT_CHANNEL_WIDTH_20
;
2165 case MFIE_TYPE_HT_INFO
:
2166 netdev_dbg(ieee
->dev
, "MFIE_TYPE_HT_INFO: %d bytes\n",
2168 tmp_htinfo_len
= min_t(u8
, info_element
->len
, MAX_IE_LEN
);
2169 if (tmp_htinfo_len
) {
2170 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_IEEE
;
2171 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
>
2172 sizeof(network
->bssht
.bdHTInfoBuf
) ?
2173 sizeof(network
->bssht
.bdHTInfoBuf
) :
2175 memcpy(network
->bssht
.bdHTInfoBuf
,
2177 network
->bssht
.bdHTInfoLen
);
2181 case MFIE_TYPE_AIRONET
:
2182 netdev_dbg(ieee
->dev
, "MFIE_TYPE_AIRONET: %d bytes\n",
2184 if (info_element
->len
> IE_CISCO_FLAG_POSITION
) {
2185 network
->bWithAironetIE
= true;
2187 if ((info_element
->data
[IE_CISCO_FLAG_POSITION
]
2188 & SUPPORT_CKIP_MIC
) ||
2189 (info_element
->data
[IE_CISCO_FLAG_POSITION
]
2191 network
->bCkipSupported
= true;
2193 network
->bCkipSupported
= false;
2195 network
->bWithAironetIE
= false;
2196 network
->bCkipSupported
= false;
2199 case MFIE_TYPE_QOS_PARAMETER
:
2200 netdev_err(ieee
->dev
,
2201 "QoS Error need to parse QOS_PARAMETER IE\n");
2204 case MFIE_TYPE_COUNTRY
:
2205 netdev_dbg(ieee
->dev
, "MFIE_TYPE_COUNTRY: %d bytes\n",
2207 rtllib_extract_country_ie(ieee
, info_element
, network
,
2213 ("Unsupported info element: %s (%d)\n",
2214 get_info_element_string(info_element
->id
),
2219 length
-= sizeof(*info_element
) + info_element
->len
;
2221 (struct rtllib_info_element
*)&info_element
->
2222 data
[info_element
->len
];
2225 if (!network
->atheros_cap_exist
&& !network
->broadcom_cap_exist
&&
2226 !network
->cisco_cap_exist
&& !network
->ralink_cap_exist
&&
2227 !network
->bssht
.bdRT2RTAggregation
)
2228 network
->unknown_cap_exist
= true;
2230 network
->unknown_cap_exist
= false;
2234 static long rtllib_translate_todbm(u8 signal_strength_index
)
2238 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
2241 return signal_power
;
2244 static inline int rtllib_network_init(
2245 struct rtllib_device
*ieee
,
2246 struct rtllib_probe_response
*beacon
,
2247 struct rtllib_network
*network
,
2248 struct rtllib_rx_stats
*stats
)
2250 memset(&network
->qos_data
, 0, sizeof(struct rtllib_qos_data
));
2252 /* Pull out fixed field data */
2253 ether_addr_copy(network
->bssid
, beacon
->header
.addr3
);
2254 network
->capability
= le16_to_cpu(beacon
->capability
);
2255 network
->last_scanned
= jiffies
;
2256 network
->time_stamp
[0] = beacon
->time_stamp
[0];
2257 network
->time_stamp
[1] = beacon
->time_stamp
[1];
2258 network
->beacon_interval
= le16_to_cpu(beacon
->beacon_interval
);
2259 /* Where to pull this? beacon->listen_interval;*/
2260 network
->listen_interval
= 0x0A;
2261 network
->rates_len
= network
->rates_ex_len
= 0;
2262 network
->last_associate
= 0;
2263 network
->ssid_len
= 0;
2264 network
->hidden_ssid_len
= 0;
2265 memset(network
->hidden_ssid
, 0, sizeof(network
->hidden_ssid
));
2267 network
->atim_window
= 0;
2268 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
2270 network
->berp_info_valid
= false;
2271 network
->broadcom_cap_exist
= false;
2272 network
->ralink_cap_exist
= false;
2273 network
->atheros_cap_exist
= false;
2274 network
->cisco_cap_exist
= false;
2275 network
->unknown_cap_exist
= false;
2276 network
->realtek_cap_exit
= false;
2277 network
->marvell_cap_exist
= false;
2278 network
->airgo_cap_exist
= false;
2279 network
->Turbo_Enable
= 0;
2280 network
->SignalStrength
= stats
->SignalStrength
;
2281 network
->RSSI
= stats
->SignalStrength
;
2282 network
->CountryIeLen
= 0;
2283 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
2284 HTInitializeBssDesc(&network
->bssht
);
2285 if (stats
->freq
== RTLLIB_52GHZ_BAND
) {
2286 /* for A band (No DS info) */
2287 network
->channel
= stats
->received_channel
;
2289 network
->flags
|= NETWORK_HAS_CCK
;
2291 network
->wpa_ie_len
= 0;
2292 network
->rsn_ie_len
= 0;
2293 network
->wzc_ie_len
= 0;
2295 if (rtllib_parse_info_param(ieee
,
2296 beacon
->info_element
,
2297 (stats
->len
- sizeof(*beacon
)),
2303 if (stats
->freq
== RTLLIB_52GHZ_BAND
)
2304 network
->mode
= IEEE_A
;
2306 if (network
->flags
& NETWORK_HAS_OFDM
)
2307 network
->mode
|= IEEE_G
;
2308 if (network
->flags
& NETWORK_HAS_CCK
)
2309 network
->mode
|= IEEE_B
;
2312 if (network
->mode
== 0) {
2313 netdev_dbg(ieee
->dev
, "Filtered out '%s (%pM)' network.\n",
2314 escape_essid(network
->ssid
, network
->ssid_len
),
2319 if (network
->bssht
.bdSupportHT
) {
2320 if (network
->mode
== IEEE_A
)
2321 network
->mode
= IEEE_N_5G
;
2322 else if (network
->mode
& (IEEE_G
| IEEE_B
))
2323 network
->mode
= IEEE_N_24G
;
2325 if (rtllib_is_empty_essid(network
->ssid
, network
->ssid_len
))
2326 network
->flags
|= NETWORK_EMPTY_ESSID
;
2327 stats
->signal
= 30 + (stats
->SignalStrength
* 70) / 100;
2328 stats
->noise
= rtllib_translate_todbm((u8
)(100-stats
->signal
)) - 25;
2330 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
2335 static inline int is_same_network(struct rtllib_network
*src
,
2336 struct rtllib_network
*dst
, u8 ssidbroad
)
2338 /* A network is only a duplicate if the channel, BSSID, ESSID
2339 * and the capability field (in particular IBSS and BSS) all match.
2340 * We treat all <hidden> with the same BSSID and channel
2343 return (((src
->ssid_len
== dst
->ssid_len
) || (!ssidbroad
)) &&
2344 (src
->channel
== dst
->channel
) &&
2345 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
2346 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) ||
2348 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
2349 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
2350 ((src
->capability
& WLAN_CAPABILITY_ESS
) ==
2351 (dst
->capability
& WLAN_CAPABILITY_ESS
)));
2355 static inline void update_network(struct rtllib_network
*dst
,
2356 struct rtllib_network
*src
)
2361 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct rtllib_rx_stats
));
2362 dst
->capability
= src
->capability
;
2363 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
2364 dst
->rates_len
= src
->rates_len
;
2365 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
2366 dst
->rates_ex_len
= src
->rates_ex_len
;
2367 if (src
->ssid_len
> 0) {
2368 if (dst
->ssid_len
== 0) {
2369 memset(dst
->hidden_ssid
, 0, sizeof(dst
->hidden_ssid
));
2370 dst
->hidden_ssid_len
= src
->ssid_len
;
2371 memcpy(dst
->hidden_ssid
, src
->ssid
, src
->ssid_len
);
2373 memset(dst
->ssid
, 0, dst
->ssid_len
);
2374 dst
->ssid_len
= src
->ssid_len
;
2375 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
2378 dst
->mode
= src
->mode
;
2379 dst
->flags
= src
->flags
;
2380 dst
->time_stamp
[0] = src
->time_stamp
[0];
2381 dst
->time_stamp
[1] = src
->time_stamp
[1];
2382 if (src
->flags
& NETWORK_HAS_ERP_VALUE
) {
2383 dst
->erp_value
= src
->erp_value
;
2384 dst
->berp_info_valid
= src
->berp_info_valid
= true;
2386 dst
->beacon_interval
= src
->beacon_interval
;
2387 dst
->listen_interval
= src
->listen_interval
;
2388 dst
->atim_window
= src
->atim_window
;
2389 dst
->dtim_period
= src
->dtim_period
;
2390 dst
->dtim_data
= src
->dtim_data
;
2391 dst
->last_dtim_sta_time
= src
->last_dtim_sta_time
;
2392 memcpy(&dst
->tim
, &src
->tim
, sizeof(struct rtllib_tim_parameters
));
2394 dst
->bssht
.bdSupportHT
= src
->bssht
.bdSupportHT
;
2395 dst
->bssht
.bdRT2RTAggregation
= src
->bssht
.bdRT2RTAggregation
;
2396 dst
->bssht
.bdHTCapLen
= src
->bssht
.bdHTCapLen
;
2397 memcpy(dst
->bssht
.bdHTCapBuf
, src
->bssht
.bdHTCapBuf
,
2398 src
->bssht
.bdHTCapLen
);
2399 dst
->bssht
.bdHTInfoLen
= src
->bssht
.bdHTInfoLen
;
2400 memcpy(dst
->bssht
.bdHTInfoBuf
, src
->bssht
.bdHTInfoBuf
,
2401 src
->bssht
.bdHTInfoLen
);
2402 dst
->bssht
.bdHTSpecVer
= src
->bssht
.bdHTSpecVer
;
2403 dst
->bssht
.bdRT2RTLongSlotTime
= src
->bssht
.bdRT2RTLongSlotTime
;
2404 dst
->broadcom_cap_exist
= src
->broadcom_cap_exist
;
2405 dst
->ralink_cap_exist
= src
->ralink_cap_exist
;
2406 dst
->atheros_cap_exist
= src
->atheros_cap_exist
;
2407 dst
->realtek_cap_exit
= src
->realtek_cap_exit
;
2408 dst
->marvell_cap_exist
= src
->marvell_cap_exist
;
2409 dst
->cisco_cap_exist
= src
->cisco_cap_exist
;
2410 dst
->airgo_cap_exist
= src
->airgo_cap_exist
;
2411 dst
->unknown_cap_exist
= src
->unknown_cap_exist
;
2412 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
2413 dst
->wpa_ie_len
= src
->wpa_ie_len
;
2414 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
2415 dst
->rsn_ie_len
= src
->rsn_ie_len
;
2416 memcpy(dst
->wzc_ie
, src
->wzc_ie
, src
->wzc_ie_len
);
2417 dst
->wzc_ie_len
= src
->wzc_ie_len
;
2419 dst
->last_scanned
= jiffies
;
2420 /* qos related parameters */
2421 qos_active
= dst
->qos_data
.active
;
2422 old_param
= dst
->qos_data
.param_count
;
2423 dst
->qos_data
.supported
= src
->qos_data
.supported
;
2424 if (dst
->flags
& NETWORK_HAS_QOS_PARAMETERS
)
2425 memcpy(&dst
->qos_data
, &src
->qos_data
,
2426 sizeof(struct rtllib_qos_data
));
2427 if (dst
->qos_data
.supported
== 1) {
2430 ("QoS the network %s is QoS supported\n",
2434 ("QoS the network is QoS supported\n");
2436 dst
->qos_data
.active
= qos_active
;
2437 dst
->qos_data
.old_param_count
= old_param
;
2439 /* dst->last_associate is not overwritten */
2440 dst
->wmm_info
= src
->wmm_info
;
2441 if (src
->wmm_param
[0].ac_aci_acm_aifsn
||
2442 src
->wmm_param
[1].ac_aci_acm_aifsn
||
2443 src
->wmm_param
[2].ac_aci_acm_aifsn
||
2444 src
->wmm_param
[3].ac_aci_acm_aifsn
)
2445 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
2447 dst
->SignalStrength
= src
->SignalStrength
;
2448 dst
->RSSI
= src
->RSSI
;
2449 dst
->Turbo_Enable
= src
->Turbo_Enable
;
2451 dst
->CountryIeLen
= src
->CountryIeLen
;
2452 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
2454 dst
->bWithAironetIE
= src
->bWithAironetIE
;
2455 dst
->bCkipSupported
= src
->bCkipSupported
;
2456 memcpy(dst
->CcxRmState
, src
->CcxRmState
, 2);
2457 dst
->bCcxRmEnable
= src
->bCcxRmEnable
;
2458 dst
->MBssidMask
= src
->MBssidMask
;
2459 dst
->bMBssidValid
= src
->bMBssidValid
;
2460 memcpy(dst
->MBssid
, src
->MBssid
, 6);
2461 dst
->bWithCcxVerNum
= src
->bWithCcxVerNum
;
2462 dst
->BssCcxVerNumber
= src
->BssCcxVerNumber
;
2465 static inline int is_beacon(u16 fc
)
2467 return (WLAN_FC_GET_STYPE(fc
) == RTLLIB_STYPE_BEACON
);
2470 static int IsPassiveChannel(struct rtllib_device
*rtllib
, u8 channel
)
2472 if (MAX_CHANNEL_NUMBER
< channel
) {
2473 netdev_info(rtllib
->dev
, "%s(): Invalid Channel\n", __func__
);
2477 if (rtllib
->active_channel_map
[channel
] == 2)
2483 int rtllib_legal_channel(struct rtllib_device
*rtllib
, u8 channel
)
2485 if (MAX_CHANNEL_NUMBER
< channel
) {
2486 netdev_info(rtllib
->dev
, "%s(): Invalid Channel\n", __func__
);
2489 if (rtllib
->active_channel_map
[channel
] > 0)
2494 EXPORT_SYMBOL(rtllib_legal_channel
);
2496 static inline void rtllib_process_probe_response(
2497 struct rtllib_device
*ieee
,
2498 struct rtllib_probe_response
*beacon
,
2499 struct rtllib_rx_stats
*stats
)
2501 struct rtllib_network
*target
;
2502 struct rtllib_network
*oldest
= NULL
;
2503 struct rtllib_info_element
*info_element
= &beacon
->info_element
[0];
2504 unsigned long flags
;
2506 struct rtllib_network
*network
= kzalloc(sizeof(struct rtllib_network
),
2508 u16 frame_ctl
= le16_to_cpu(beacon
->header
.frame_ctl
);
2513 netdev_dbg(ieee
->dev
,
2514 "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2515 escape_essid(info_element
->data
, info_element
->len
),
2516 beacon
->header
.addr3
,
2517 (le16_to_cpu(beacon
->capability
) & (1<<0xf)) ? '1' : '0',
2518 (le16_to_cpu(beacon
->capability
) & (1<<0xe)) ? '1' : '0',
2519 (le16_to_cpu(beacon
->capability
) & (1<<0xd)) ? '1' : '0',
2520 (le16_to_cpu(beacon
->capability
) & (1<<0xc)) ? '1' : '0',
2521 (le16_to_cpu(beacon
->capability
) & (1<<0xb)) ? '1' : '0',
2522 (le16_to_cpu(beacon
->capability
) & (1<<0xa)) ? '1' : '0',
2523 (le16_to_cpu(beacon
->capability
) & (1<<0x9)) ? '1' : '0',
2524 (le16_to_cpu(beacon
->capability
) & (1<<0x8)) ? '1' : '0',
2525 (le16_to_cpu(beacon
->capability
) & (1<<0x7)) ? '1' : '0',
2526 (le16_to_cpu(beacon
->capability
) & (1<<0x6)) ? '1' : '0',
2527 (le16_to_cpu(beacon
->capability
) & (1<<0x5)) ? '1' : '0',
2528 (le16_to_cpu(beacon
->capability
) & (1<<0x4)) ? '1' : '0',
2529 (le16_to_cpu(beacon
->capability
) & (1<<0x3)) ? '1' : '0',
2530 (le16_to_cpu(beacon
->capability
) & (1<<0x2)) ? '1' : '0',
2531 (le16_to_cpu(beacon
->capability
) & (1<<0x1)) ? '1' : '0',
2532 (le16_to_cpu(beacon
->capability
) & (1<<0x0)) ? '1' : '0');
2534 if (rtllib_network_init(ieee
, beacon
, network
, stats
)) {
2535 netdev_dbg(ieee
->dev
, "Dropped '%s' ( %pM) via %s.\n",
2536 escape_essid(info_element
->data
, info_element
->len
),
2537 beacon
->header
.addr3
,
2538 is_beacon(frame_ctl
) ? "BEACON" : "PROBE RESPONSE");
2543 if (!rtllib_legal_channel(ieee
, network
->channel
))
2546 if (WLAN_FC_GET_STYPE(frame_ctl
) == RTLLIB_STYPE_PROBE_RESP
) {
2547 if (IsPassiveChannel(ieee
, network
->channel
)) {
2548 netdev_info(ieee
->dev
,
2549 "GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n",
2555 /* The network parsed correctly -- so now we scan our known networks
2556 * to see if we can find it in our list.
2558 * NOTE: This search is definitely not optimized. Once its doing
2559 * the "right thing" we'll optimize it for efficiency if
2563 /* Search for this entry in the list and update it if it is
2567 spin_lock_irqsave(&ieee
->lock
, flags
);
2568 if (is_same_network(&ieee
->current_network
, network
,
2569 (network
->ssid_len
? 1 : 0))) {
2570 update_network(&ieee
->current_network
, network
);
2571 if ((ieee
->current_network
.mode
== IEEE_N_24G
||
2572 ieee
->current_network
.mode
== IEEE_G
)
2573 && ieee
->current_network
.berp_info_valid
) {
2574 if (ieee
->current_network
.erp_value
& ERP_UseProtection
)
2575 ieee
->current_network
.buseprotection
= true;
2577 ieee
->current_network
.buseprotection
= false;
2579 if (is_beacon(frame_ctl
)) {
2580 if (ieee
->state
>= RTLLIB_LINKED
)
2581 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
++;
2584 list_for_each_entry(target
, &ieee
->network_list
, list
) {
2585 if (is_same_network(target
, network
,
2586 (target
->ssid_len
? 1 : 0)))
2588 if ((oldest
== NULL
) ||
2589 (target
->last_scanned
< oldest
->last_scanned
))
2593 /* If we didn't find a match, then get a new network slot to initialize
2594 * with this beacon's information
2596 if (&target
->list
== &ieee
->network_list
) {
2597 if (list_empty(&ieee
->network_free_list
)) {
2598 /* If there are no more slots, expire the oldest */
2599 list_del(&oldest
->list
);
2601 netdev_dbg(ieee
->dev
,
2602 "Expired '%s' ( %pM) from network list.\n",
2603 escape_essid(target
->ssid
, target
->ssid_len
),
2606 /* Otherwise just pull from the free list */
2607 target
= list_entry(ieee
->network_free_list
.next
,
2608 struct rtllib_network
, list
);
2609 list_del(ieee
->network_free_list
.next
);
2612 netdev_dbg(ieee
->dev
, "Adding '%s' ( %pM) via %s.\n",
2613 escape_essid(network
->ssid
, network
->ssid_len
),
2615 is_beacon(frame_ctl
) ? "BEACON" : "PROBE RESPONSE");
2617 memcpy(target
, network
, sizeof(*target
));
2618 list_add_tail(&target
->list
, &ieee
->network_list
);
2619 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
)
2620 rtllib_softmac_new_net(ieee
, network
);
2622 netdev_dbg(ieee
->dev
, "Updating '%s' ( %pM) via %s.\n",
2623 escape_essid(target
->ssid
, target
->ssid_len
),
2625 is_beacon(frame_ctl
) ? "BEACON" : "PROBE RESPONSE");
2627 /* we have an entry and we are going to update it. But this
2628 * entry may be already expired. In this case we do the same
2629 * as we found a new net and call the new_net handler
2631 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
,
2633 if ((!target
->ssid_len
) &&
2634 (((network
->ssid_len
> 0) && (target
->hidden_ssid_len
== 0))
2635 || ((ieee
->current_network
.ssid_len
== network
->ssid_len
) &&
2636 (strncmp(ieee
->current_network
.ssid
, network
->ssid
,
2637 network
->ssid_len
) == 0) &&
2638 (ieee
->state
== RTLLIB_NOLINK
))))
2640 update_network(target
, network
);
2641 if (renew
&& (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
))
2642 rtllib_softmac_new_net(ieee
, network
);
2645 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2646 if (is_beacon(frame_ctl
) &&
2647 is_same_network(&ieee
->current_network
, network
,
2648 (network
->ssid_len
? 1 : 0)) &&
2649 (ieee
->state
== RTLLIB_LINKED
)) {
2650 if (ieee
->handle_beacon
!= NULL
)
2651 ieee
->handle_beacon(ieee
->dev
, beacon
,
2652 &ieee
->current_network
);
2658 void rtllib_rx_mgt(struct rtllib_device
*ieee
,
2659 struct sk_buff
*skb
,
2660 struct rtllib_rx_stats
*stats
)
2662 struct rtllib_hdr_4addr
*header
= (struct rtllib_hdr_4addr
*)skb
->data
;
2664 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) !=
2665 RTLLIB_STYPE_PROBE_RESP
) &&
2666 (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) !=
2667 RTLLIB_STYPE_BEACON
))
2668 ieee
->last_rx_ps_time
= jiffies
;
2670 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
))) {
2672 case RTLLIB_STYPE_BEACON
:
2673 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
2674 WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)));
2675 rtllib_process_probe_response(
2676 ieee
, (struct rtllib_probe_response
*)header
,
2679 if (ieee
->sta_sleep
|| (ieee
->ps
!= RTLLIB_PS_DISABLED
&&
2680 ieee
->iw_mode
== IW_MODE_INFRA
&&
2681 ieee
->state
== RTLLIB_LINKED
))
2682 tasklet_schedule(&ieee
->ps_task
);
2686 case RTLLIB_STYPE_PROBE_RESP
:
2687 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2688 WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)));
2689 rtllib_process_probe_response(ieee
,
2690 (struct rtllib_probe_response
*)header
, stats
);
2692 case RTLLIB_STYPE_PROBE_REQ
:
2693 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
2695 le16_to_cpu(header
->frame_ctl
)));
2696 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
2697 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
2698 ieee
->iw_mode
== IW_MODE_MASTER
) &&
2699 ieee
->state
== RTLLIB_LINKED
))
2700 rtllib_rx_probe_rq(ieee
, skb
);