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
= __constant_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 "
74 "seq=%u last_frag=%u\n",
75 entry
->seq
, entry
->last_frag
);
76 dev_kfree_skb_any(entry
->skb
);
80 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
81 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
82 memcmp(entry
->src_addr
, src
, ETH_ALEN
) == 0 &&
83 memcmp(entry
->dst_addr
, dst
, ETH_ALEN
) == 0)
90 /* Called only as a tasklet (software IRQ) */
91 static struct sk_buff
*
92 rtllib_frag_cache_get(struct rtllib_device
*ieee
,
93 struct rtllib_hdr_4addr
*hdr
)
95 struct sk_buff
*skb
= NULL
;
96 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
97 u16 sc
= le16_to_cpu(hdr
->seq_ctl
);
98 unsigned int frag
= WLAN_GET_SEQ_FRAG(sc
);
99 unsigned int seq
= WLAN_GET_SEQ_SEQ(sc
);
100 struct rtllib_frag_entry
*entry
;
101 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
102 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
105 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
) && RTLLIB_QOS_HAS_SEQ(fc
)) {
106 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)hdr
;
107 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
110 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
111 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)hdr
;
112 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
120 /* Reserve enough space to fit maximum frame length */
121 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
122 sizeof(struct rtllib_hdr_4addr
) +
127 (RTLLIB_QOS_HAS_SEQ(fc
) ? 2 : 0) /* QOS Control */);
131 entry
= &ieee
->frag_cache
[tid
][ieee
->frag_next_idx
[tid
]];
132 ieee
->frag_next_idx
[tid
]++;
133 if (ieee
->frag_next_idx
[tid
] >= RTLLIB_FRAG_CACHE_LEN
)
134 ieee
->frag_next_idx
[tid
] = 0;
136 if (entry
->skb
!= NULL
)
137 dev_kfree_skb_any(entry
->skb
);
139 entry
->first_frag_time
= jiffies
;
141 entry
->last_frag
= frag
;
143 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
144 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
146 /* received a fragment of a frame for which the head fragment
147 * 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
,
191 "could not invalidate fragment cache "
192 "entry (seq=%u)\n", seq
);
200 /* rtllib_rx_frame_mgtmt
202 * Responsible for handling management control frames
204 * Called by rtllib_rx */
206 rtllib_rx_frame_mgmt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
207 struct rtllib_rx_stats
*rx_stats
, u16 type
,
210 /* On the struct stats definition there is written that
211 * this is not mandatory.... but seems that the probe
212 * response parser uses it
214 struct rtllib_hdr_3addr
*hdr
= (struct rtllib_hdr_3addr
*)skb
->data
;
216 rx_stats
->len
= skb
->len
;
217 rtllib_rx_mgt(ieee
, skb
, rx_stats
);
218 if ((memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
))) {
219 dev_kfree_skb_any(skb
);
222 rtllib_rx_frame_softmac(ieee
, skb
, rx_stats
, type
, stype
);
224 dev_kfree_skb_any(skb
);
229 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
230 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
231 static unsigned char rfc1042_header
[] = {
232 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
234 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
235 static unsigned char bridge_tunnel_header
[] = {
236 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
238 /* No encapsulation header if EtherType < 0x600 (=length) */
240 /* Called by rtllib_rx_frame_decrypt */
241 static int rtllib_is_eapol_frame(struct rtllib_device
*ieee
,
242 struct sk_buff
*skb
, size_t hdrlen
)
244 struct net_device
*dev
= ieee
->dev
;
246 struct rtllib_hdr_4addr
*hdr
;
252 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
253 fc
= le16_to_cpu(hdr
->frame_ctl
);
255 /* check that the frame is unicast frame to us */
256 if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
258 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0 &&
259 memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
260 /* ToDS frame with own addr BSSID and DA */
261 } else if ((fc
& (RTLLIB_FCTL_TODS
| RTLLIB_FCTL_FROMDS
)) ==
262 RTLLIB_FCTL_FROMDS
&&
263 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
264 /* FromDS frame with own addr as DA */
268 if (skb
->len
< 24 + 8)
271 /* check for port access entity Ethernet type */
272 pos
= skb
->data
+ hdrlen
;
273 ethertype
= (pos
[6] << 8) | pos
[7];
274 if (ethertype
== ETH_P_PAE
)
280 /* Called only as a tasklet (software IRQ), by rtllib_rx */
282 rtllib_rx_frame_decrypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
283 struct lib80211_crypt_data
*crypt
)
285 struct rtllib_hdr_4addr
*hdr
;
288 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
291 if (ieee
->hwsec_active
) {
292 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
293 tcb_desc
->bHwSec
= 1;
295 if (ieee
->need_sw_enc
)
296 tcb_desc
->bHwSec
= 0;
299 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
300 hdrlen
= rtllib_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
302 atomic_inc(&crypt
->refcnt
);
303 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
304 atomic_dec(&crypt
->refcnt
);
307 "decryption failed (SA= %pM"
308 ") res=%d\n", hdr
->addr2
, res
);
310 RTLLIB_DEBUG_DROP("Decryption failed ICV "
311 "mismatch (key %d)\n",
312 skb
->data
[hdrlen
+ 3] >> 6);
313 ieee
->ieee_stats
.rx_discards_undecryptable
++;
321 /* Called only as a tasklet (software IRQ), by rtllib_rx */
323 rtllib_rx_frame_decrypt_msdu(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
324 int keyidx
, struct lib80211_crypt_data
*crypt
)
326 struct rtllib_hdr_4addr
*hdr
;
329 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
331 if (ieee
->hwsec_active
) {
332 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ MAX_DEV_ADDR_SIZE
);
333 tcb_desc
->bHwSec
= 1;
335 if (ieee
->need_sw_enc
)
336 tcb_desc
->bHwSec
= 0;
339 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
340 hdrlen
= rtllib_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
342 atomic_inc(&crypt
->refcnt
);
343 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
344 atomic_dec(&crypt
->refcnt
);
346 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
347 " (SA= %pM keyidx=%d)\n",
348 ieee
->dev
->name
, hdr
->addr2
, keyidx
);
356 /* this function is stolen from ipw2200 driver*/
357 #define IEEE_PACKET_RETRY_TIME (5*HZ)
358 static int is_duplicate_packet(struct rtllib_device
*ieee
,
359 struct rtllib_hdr_4addr
*header
)
361 u16 fc
= le16_to_cpu(header
->frame_ctl
);
362 u16 sc
= le16_to_cpu(header
->seq_ctl
);
363 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
364 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
365 u16
*last_seq
, *last_frag
;
366 unsigned long *last_time
;
367 struct rtllib_hdr_3addrqos
*hdr_3addrqos
;
368 struct rtllib_hdr_4addrqos
*hdr_4addrqos
;
371 if (((fc
& RTLLIB_FCTL_DSTODS
) == RTLLIB_FCTL_DSTODS
) && RTLLIB_QOS_HAS_SEQ(fc
)) {
372 hdr_4addrqos
= (struct rtllib_hdr_4addrqos
*)header
;
373 tid
= le16_to_cpu(hdr_4addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
376 } else if (RTLLIB_QOS_HAS_SEQ(fc
)) {
377 hdr_3addrqos
= (struct rtllib_hdr_3addrqos
*)header
;
378 tid
= le16_to_cpu(hdr_3addrqos
->qos_ctl
) & RTLLIB_QCTL_TID
;
385 switch (ieee
->iw_mode
) {
389 struct ieee_ibss_seq
*entry
= NULL
;
390 u8
*mac
= header
->addr2
;
391 int index
= mac
[5] % IEEE_IBSS_MAC_HASH_SIZE
;
392 list_for_each(p
, &ieee
->ibss_mac_hash
[index
]) {
393 entry
= list_entry(p
, struct ieee_ibss_seq
, list
);
394 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
397 if (p
== &ieee
->ibss_mac_hash
[index
]) {
398 entry
= kmalloc(sizeof(struct ieee_ibss_seq
), GFP_ATOMIC
);
400 printk(KERN_WARNING
"Cannot malloc new mac entry\n");
403 memcpy(entry
->mac
, mac
, ETH_ALEN
);
404 entry
->seq_num
[tid
] = seq
;
405 entry
->frag_num
[tid
] = frag
;
406 entry
->packet_time
[tid
] = jiffies
;
407 list_add(&entry
->list
, &ieee
->ibss_mac_hash
[index
]);
410 last_seq
= &entry
->seq_num
[tid
];
411 last_frag
= &entry
->frag_num
[tid
];
412 last_time
= &entry
->packet_time
[tid
];
417 last_seq
= &ieee
->last_rxseq_num
[tid
];
418 last_frag
= &ieee
->last_rxfrag_num
[tid
];
419 last_time
= &ieee
->last_packet_time
[tid
];
425 if ((*last_seq
== seq
) &&
426 time_after(*last_time
+ IEEE_PACKET_RETRY_TIME
, jiffies
)) {
427 if (*last_frag
== frag
)
429 if (*last_frag
+ 1 != frag
)
430 /* out-of-order fragment */
436 *last_time
= jiffies
;
444 static bool AddReorderEntry(struct rx_ts_record
*pTS
,
445 struct rx_reorder_entry
*pReorderEntry
)
447 struct list_head
*pList
= &pTS
->RxPendingPktList
;
449 while (pList
->next
!= &pTS
->RxPendingPktList
) {
450 if (SN_LESS(pReorderEntry
->SeqNum
, ((struct rx_reorder_entry
*)
451 list_entry(pList
->next
, struct rx_reorder_entry
,
454 else if (SN_EQUAL(pReorderEntry
->SeqNum
,
455 ((struct rx_reorder_entry
*)list_entry(pList
->next
,
456 struct rx_reorder_entry
, List
))->SeqNum
))
461 pReorderEntry
->List
.next
= pList
->next
;
462 pReorderEntry
->List
.next
->prev
= &pReorderEntry
->List
;
463 pReorderEntry
->List
.prev
= pList
;
464 pList
->next
= &pReorderEntry
->List
;
469 void rtllib_indicate_packets(struct rtllib_device
*ieee
, struct rtllib_rxb
**prxbIndicateArray
, u8 index
)
471 struct net_device_stats
*stats
= &ieee
->stats
;
474 for (j
= 0; j
< index
; j
++) {
475 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"
558 " is %d, WinSize is %d\n", __func__
, SeqNum
,
559 pTS
->RxIndicateSeq
, WinSize
);
561 spin_lock_irqsave(&(ieee
->reorder_spinlock
), flags
);
563 WinEnd
= (pTS
->RxIndicateSeq
+ WinSize
- 1) % 4096;
564 /* Rx Reorder initialize condition.*/
565 if (pTS
->RxIndicateSeq
== 0xffff)
566 pTS
->RxIndicateSeq
= SeqNum
;
568 /* Drop out the packet which SeqNum is smaller than WinStart */
569 if (SN_LESS(SeqNum
, pTS
->RxIndicateSeq
)) {
570 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
571 pTS
->RxIndicateSeq
, SeqNum
);
572 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,"
598 " NewSeq: %d\n", pTS
->RxIndicateSeq
, SeqNum
);
602 * Indication process.
603 * After Packet dropping and Sliding Window shifting as above, we can
604 * now just indicate the packets with the SeqNum smaller than latest
605 * WinStart and struct buffer other packets.
607 /* For Rx Reorder condition:
608 * 1. All packets with SeqNum smaller than WinStart => Indicate
609 * 2. All packets with SeqNum larger than or equal to
610 * WinStart => Buffer it.
612 if (bMatchWinStart
) {
613 /* Current packet is going to be indicated.*/
614 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "Packets indication!! "
615 "IndicateSeq: %d, NewSeq: %d\n",
616 pTS
->RxIndicateSeq
, SeqNum
);
617 ieee
->prxbIndicateArray
[0] = prxb
;
620 /* Current packet is going to be inserted into pending list.*/
621 if (!list_empty(&ieee
->RxReorder_Unused_List
)) {
622 pReorderEntry
= (struct rx_reorder_entry
*)
623 list_entry(ieee
->RxReorder_Unused_List
.next
,
624 struct rx_reorder_entry
, List
);
625 list_del_init(&pReorderEntry
->List
);
627 /* Make a reorder entry and insert into a the packet list.*/
628 pReorderEntry
->SeqNum
= SeqNum
;
629 pReorderEntry
->prxb
= prxb
;
631 if (!AddReorderEntry(pTS
, pReorderEntry
)) {
632 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,
633 "%s(): Duplicate packet is "
634 "dropped!! IndicateSeq: %d, "
636 __func__
, pTS
->RxIndicateSeq
,
638 list_add_tail(&pReorderEntry
->List
,
639 &ieee
->RxReorder_Unused_List
); {
641 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
642 dev_kfree_skb(prxb
->subframes
[i
]);
647 RTLLIB_DEBUG(RTLLIB_DL_REORDER
,
648 "Pkt insert into struct buffer!! "
649 "IndicateSeq: %d, NewSeq: %d\n",
650 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 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket():"
660 " There is no reorder entry!! Packet is "
664 for (i
= 0; i
< prxb
->nr_subframes
; i
++)
665 dev_kfree_skb(prxb
->subframes
[i
]);
672 /* Check if there is any packet need indicate.*/
673 while (!list_empty(&pTS
->RxPendingPktList
)) {
674 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): start RREORDER indicate\n", __func__
);
676 pReorderEntry
= (struct rx_reorder_entry
*)list_entry(pTS
->RxPendingPktList
.prev
,
677 struct rx_reorder_entry
, List
);
678 if (SN_LESS(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
) ||
679 SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
)) {
680 /* This protect struct buffer from overflow. */
681 if (index
>= REORDER_WIN_SIZE
) {
682 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicate"
683 "Packet(): Buffer overflow!!\n");
688 list_del_init(&pReorderEntry
->List
);
690 if (SN_EQUAL(pReorderEntry
->SeqNum
, pTS
->RxIndicateSeq
))
691 pTS
->RxIndicateSeq
= (pTS
->RxIndicateSeq
+ 1) % 4096;
693 ieee
->prxbIndicateArray
[index
] = pReorderEntry
->prxb
;
694 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): Indicate SeqNum"
695 " %d!\n", __func__
, pReorderEntry
->SeqNum
);
698 list_add_tail(&pReorderEntry
->List
,
699 &ieee
->RxReorder_Unused_List
);
706 /* Handling pending timer. Set this timer to prevent from long time
709 if (timer_pending(&pTS
->RxPktPendingTimer
))
710 del_timer_sync(&pTS
->RxPktPendingTimer
);
711 pTS
->RxTimeoutIndicateSeq
= 0xffff;
713 if (index
> REORDER_WIN_SIZE
) {
714 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "RxReorderIndicatePacket():"
715 " Rx Reorer struct buffer full!!\n");
716 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
),
720 rtllib_indicate_packets(ieee
, ieee
->prxbIndicateArray
, index
);
724 if (bPktInBuf
&& pTS
->RxTimeoutIndicateSeq
== 0xffff) {
725 RTLLIB_DEBUG(RTLLIB_DL_REORDER
, "%s(): SET rx timeout timer\n",
727 pTS
->RxTimeoutIndicateSeq
= pTS
->RxIndicateSeq
;
728 mod_timer(&pTS
->RxPktPendingTimer
, jiffies
+
729 MSECS(pHTInfo
->RxReorderPendingTime
));
731 spin_unlock_irqrestore(&(ieee
->reorder_spinlock
), flags
);
734 static u8
parse_subframe(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
735 struct rtllib_rx_stats
*rx_stats
,
736 struct rtllib_rxb
*rxb
, u8
*src
, u8
*dst
)
738 struct rtllib_hdr_3addr
*hdr
= (struct rtllib_hdr_3addr
*)skb
->data
;
739 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
741 u16 LLCOffset
= sizeof(struct rtllib_hdr_3addr
);
743 bool bIsAggregateFrame
= false;
744 u16 nSubframe_Length
;
745 u8 nPadding_Length
= 0;
747 struct sk_buff
*sub_skb
;
749 /* just for debug purpose */
750 SeqNum
= WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr
->seq_ctl
));
751 if ((RTLLIB_QOS_HAS_SEQ(fc
)) &&
752 (((union frameqos
*)(skb
->data
+ RTLLIB_3ADDR_LEN
))->field
.reserved
))
753 bIsAggregateFrame
= true;
755 if (RTLLIB_QOS_HAS_SEQ(fc
))
757 if (rx_stats
->bContainHTC
)
758 LLCOffset
+= sHTCLng
;
760 ChkLength
= LLCOffset
;
762 if (skb
->len
<= ChkLength
)
765 skb_pull(skb
, LLCOffset
);
766 ieee
->bIsAggregateFrame
= bIsAggregateFrame
;
767 if (!bIsAggregateFrame
) {
768 rxb
->nr_subframes
= 1;
770 /* altered by clark 3/30/2010
771 * The struct buffer size of the skb indicated to upper layer
772 * must be less than 5000, or the defraged IP datagram
773 * in the IP layer will exceed "ipfrag_high_tresh" and be
774 * discarded. so there must not use the function
775 * "skb_copy" and "skb_clone" for "skb".
778 /* Allocate new skb for releasing to upper layer */
779 sub_skb
= dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE
);
782 skb_reserve(sub_skb
, 12);
783 data_ptr
= (u8
*)skb_put(sub_skb
, skb
->len
);
784 memcpy(data_ptr
, skb
->data
, skb
->len
);
785 sub_skb
->dev
= ieee
->dev
;
787 rxb
->subframes
[0] = sub_skb
;
789 memcpy(rxb
->src
, src
, ETH_ALEN
);
790 memcpy(rxb
->dst
, dst
, ETH_ALEN
);
791 rxb
->subframes
[0]->dev
= ieee
->dev
;
794 rxb
->nr_subframes
= 0;
795 memcpy(rxb
->src
, src
, ETH_ALEN
);
796 memcpy(rxb
->dst
, dst
, ETH_ALEN
);
797 while (skb
->len
> ETHERNET_HEADER_SIZE
) {
798 /* Offset 12 denote 2 mac address */
799 nSubframe_Length
= *((u16
*)(skb
->data
+ 12));
800 nSubframe_Length
= (nSubframe_Length
>> 8) +
801 (nSubframe_Length
<< 8);
803 if (skb
->len
< (ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
804 printk(KERN_INFO
"%s: A-MSDU parse error!! "
805 "pRfd->nTotalSubframe : %d\n",\
806 __func__
, rxb
->nr_subframes
);
807 printk(KERN_INFO
"%s: A-MSDU parse error!! "
808 "Subframe Length: %d\n", __func__
,
810 printk(KERN_INFO
"nRemain_Length is %d and "
811 "nSubframe_Length is : %d\n", skb
->len
,
813 printk(KERN_INFO
"The Packet SeqNum is %d\n", SeqNum
);
817 /* move the data point to data content */
818 skb_pull(skb
, ETHERNET_HEADER_SIZE
);
820 /* altered by clark 3/30/2010
821 * The struct buffer size of the skb indicated to upper layer
822 * must be less than 5000, or the defraged IP datagram
823 * in the IP layer will exceed "ipfrag_high_tresh" and be
824 * discarded. so there must not use the function
825 * "skb_copy" and "skb_clone" for "skb".
828 /* Allocate new skb for releasing to upper layer */
829 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
832 skb_reserve(sub_skb
, 12);
833 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
834 memcpy(data_ptr
, skb
->data
, nSubframe_Length
);
836 sub_skb
->dev
= ieee
->dev
;
837 rxb
->subframes
[rxb
->nr_subframes
++] = sub_skb
;
838 if (rxb
->nr_subframes
>= MAX_SUBFRAME_COUNT
) {
839 RTLLIB_DEBUG_RX("ParseSubframe(): Too many "
840 "Subframes! Packets dropped!\n");
843 skb_pull(skb
, nSubframe_Length
);
846 nPadding_Length
= 4 - ((nSubframe_Length
+
847 ETHERNET_HEADER_SIZE
) % 4);
848 if (nPadding_Length
== 4)
851 if (skb
->len
< nPadding_Length
)
854 skb_pull(skb
, nPadding_Length
);
858 return rxb
->nr_subframes
;
863 static size_t rtllib_rx_get_hdrlen(struct rtllib_device
*ieee
,
865 struct rtllib_rx_stats
*rx_stats
)
867 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
868 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
871 hdrlen
= rtllib_get_hdrlen(fc
);
872 if (HTCCheck(ieee
, skb
->data
)) {
874 printk(KERN_INFO
"%s: find HTCControl!\n", __func__
);
876 rx_stats
->bContainHTC
= true;
879 if (RTLLIB_QOS_HAS_SEQ(fc
))
880 rx_stats
->bIsQosData
= true;
885 static int rtllib_rx_check_duplicate(struct rtllib_device
*ieee
,
886 struct sk_buff
*skb
, u8 multicast
)
888 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
890 u8 frag
, type
, stype
;
892 fc
= le16_to_cpu(hdr
->frame_ctl
);
893 type
= WLAN_FC_GET_TYPE(fc
);
894 stype
= WLAN_FC_GET_STYPE(fc
);
895 sc
= le16_to_cpu(hdr
->seq_ctl
);
896 frag
= WLAN_GET_SEQ_FRAG(sc
);
898 if ((ieee
->pHTInfo
->bCurRxReorderEnable
== false) ||
899 !ieee
->current_network
.qos_data
.active
||
900 !IsDataFrame(skb
->data
) ||
901 IsLegacyDataFrame(skb
->data
)) {
902 if (!((type
== RTLLIB_FTYPE_MGMT
) && (stype
== RTLLIB_STYPE_BEACON
))) {
903 if (is_duplicate_packet(ieee
, hdr
))
907 struct rx_ts_record
*pRxTS
= NULL
;
908 if (GetTs(ieee
, (struct ts_common_info
**) &pRxTS
, hdr
->addr2
,
909 (u8
)Frame_QoSTID((u8
*)(skb
->data
)), RX_DIR
, true)) {
910 if ((fc
& (1<<11)) && (frag
== pRxTS
->RxLastFragNum
) &&
911 (WLAN_GET_SEQ_SEQ(sc
) == pRxTS
->RxLastSeqNum
)) {
914 pRxTS
->RxLastFragNum
= frag
;
915 pRxTS
->RxLastSeqNum
= WLAN_GET_SEQ_SEQ(sc
);
918 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "ERR!!%s(): No TS!! Skip"
919 " the check!!\n", __func__
);
927 static void rtllib_rx_extract_addr(struct rtllib_device
*ieee
,
928 struct rtllib_hdr_4addr
*hdr
, u8
*dst
,
931 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
933 switch (fc
& (RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
)) {
934 case RTLLIB_FCTL_FROMDS
:
935 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
936 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
937 memcpy(bssid
, hdr
->addr2
, ETH_ALEN
);
939 case RTLLIB_FCTL_TODS
:
940 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
941 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
942 memcpy(bssid
, hdr
->addr1
, ETH_ALEN
);
944 case RTLLIB_FCTL_FROMDS
| RTLLIB_FCTL_TODS
:
945 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
946 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
947 memcpy(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
950 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
951 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
952 memcpy(bssid
, hdr
->addr3
, ETH_ALEN
);
957 static int rtllib_rx_data_filter(struct rtllib_device
*ieee
, u16 fc
,
958 u8
*dst
, u8
*src
, u8
*bssid
, u8
*addr2
)
962 type
= WLAN_FC_GET_TYPE(fc
);
963 stype
= WLAN_FC_GET_STYPE(fc
);
965 /* Filter frames from different BSS */
966 if (((fc
& RTLLIB_FCTL_DSTODS
) != RTLLIB_FCTL_DSTODS
) &&
967 !ether_addr_equal(ieee
->current_network
.bssid
, bssid
) &&
968 !is_zero_ether_addr(ieee
->current_network
.bssid
)) {
972 /* Filter packets sent by an STA that will be forwarded by AP */
973 if (ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
&&
974 ieee
->IntelPromiscuousModeInfo
.bFilterSourceStationFrame
) {
975 if ((fc
& RTLLIB_FCTL_TODS
) && !(fc
& RTLLIB_FCTL_FROMDS
) &&
976 !ether_addr_equal(dst
, ieee
->current_network
.bssid
) &&
977 ether_addr_equal(bssid
, ieee
->current_network
.bssid
)) {
982 /* Nullfunc frames may have PS-bit set, so they must be passed to
983 * hostap_handle_sta_rx() before being dropped here. */
984 if (!ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
) {
985 if (stype
!= RTLLIB_STYPE_DATA
&&
986 stype
!= RTLLIB_STYPE_DATA_CFACK
&&
987 stype
!= RTLLIB_STYPE_DATA_CFPOLL
&&
988 stype
!= RTLLIB_STYPE_DATA_CFACKPOLL
&&
989 stype
!= RTLLIB_STYPE_QOS_DATA
) {
990 if (stype
!= RTLLIB_STYPE_NULLFUNC
)
992 "RX: dropped data frame "
993 "with no data (type=0x%02x, "
1000 if (ieee
->iw_mode
!= IW_MODE_MESH
) {
1001 /* packets from our adapter are dropped (echo) */
1002 if (!memcmp(src
, ieee
->dev
->dev_addr
, ETH_ALEN
))
1005 /* {broad,multi}cast packets to our BSS go through */
1006 if (is_multicast_ether_addr(dst
)) {
1007 if (memcmp(bssid
, ieee
->current_network
.bssid
, ETH_ALEN
))
1014 static int rtllib_rx_get_crypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1015 struct lib80211_crypt_data
**crypt
, size_t hdrlen
)
1017 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1018 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1021 if (ieee
->host_decrypt
) {
1022 if (skb
->len
>= hdrlen
+ 3)
1023 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1025 *crypt
= ieee
->crypt_info
.crypt
[idx
];
1026 /* allow NULL decrypt to indicate an station specific override
1027 * for default encryption */
1028 if (*crypt
&& ((*crypt
)->ops
== NULL
||
1029 (*crypt
)->ops
->decrypt_mpdu
== NULL
))
1032 if (!*crypt
&& (fc
& RTLLIB_FCTL_WEP
)) {
1033 /* This seems to be triggered by some (multicast?)
1034 * frames from other than current BSS, so just drop the
1035 * frames silently instead of filling system log with
1037 RTLLIB_DEBUG_DROP("Decryption failed (not set)"
1040 ieee
->ieee_stats
.rx_discards_undecryptable
++;
1048 static int rtllib_rx_decrypt(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1049 struct rtllib_rx_stats
*rx_stats
,
1050 struct lib80211_crypt_data
*crypt
, size_t hdrlen
)
1052 struct rtllib_hdr_4addr
*hdr
;
1057 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1058 fc
= le16_to_cpu(hdr
->frame_ctl
);
1059 sc
= le16_to_cpu(hdr
->seq_ctl
);
1060 frag
= WLAN_GET_SEQ_FRAG(sc
);
1062 if ((!rx_stats
->Decrypted
))
1063 ieee
->need_sw_enc
= 1;
1065 ieee
->need_sw_enc
= 0;
1067 keyidx
= rtllib_rx_frame_decrypt(ieee
, skb
, crypt
);
1068 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) && (keyidx
< 0)) {
1069 printk(KERN_INFO
"%s: decrypt frame error\n", __func__
);
1073 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1074 if ((frag
!= 0 || (fc
& RTLLIB_FCTL_MOREFRAGS
))) {
1076 struct sk_buff
*frag_skb
= rtllib_frag_cache_get(ieee
, hdr
);
1077 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
1080 RTLLIB_DEBUG(RTLLIB_DL_RX
| RTLLIB_DL_FRAG
,
1081 "Rx cannot get skb from fragment "
1082 "cache (morefrag=%d seq=%u frag=%u)\n",
1083 (fc
& RTLLIB_FCTL_MOREFRAGS
) != 0,
1084 WLAN_GET_SEQ_SEQ(sc
), frag
);
1091 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
1092 printk(KERN_WARNING
"%s: host decrypted and "
1093 "reassembled frame did not fit skb\n",
1095 rtllib_frag_cache_invalidate(ieee
, hdr
);
1100 /* copy first fragment (including full headers) into
1101 * beginning of the fragment cache skb */
1102 memcpy(skb_put(frag_skb
, flen
), skb
->data
, flen
);
1104 /* append frame payload to the end of the fragment
1106 memcpy(skb_put(frag_skb
, flen
), skb
->data
+ hdrlen
,
1109 dev_kfree_skb_any(skb
);
1112 if (fc
& RTLLIB_FCTL_MOREFRAGS
) {
1113 /* more fragments expected - leave the skb in fragment
1114 * cache for now; it will be delivered to upper layers
1115 * after all fragments have been received */
1119 /* this was the last fragment and the frame will be
1120 * delivered, so remove skb from fragment cache */
1122 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1123 rtllib_frag_cache_invalidate(ieee
, hdr
);
1126 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1127 * encrypted/authenticated */
1128 if (ieee
->host_decrypt
&& (fc
& RTLLIB_FCTL_WEP
) &&
1129 rtllib_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
)) {
1130 printk(KERN_INFO
"%s: ==>decrypt msdu error\n", __func__
);
1134 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1135 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
) {
1136 if (/*ieee->ieee802_1x &&*/
1137 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1139 /* pass unencrypted EAPOL frames even if encryption is
1141 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1143 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1144 eap_get_type(eap
->type
));
1147 "encryption configured, but RX "
1148 "frame not encrypted (SA= %pM)\n",
1154 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) &&
1155 rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1156 struct eapol
*eap
= (struct eapol
*)(skb
->data
+
1158 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1159 eap_get_type(eap
->type
));
1162 if (crypt
&& !(fc
& RTLLIB_FCTL_WEP
) && !ieee
->open_wep
&&
1163 !rtllib_is_eapol_frame(ieee
, skb
, hdrlen
)) {
1165 "dropped unencrypted RX data "
1167 " (drop_unencrypted=1)\n",
1172 if (rtllib_is_eapol_frame(ieee
, skb
, hdrlen
))
1173 printk(KERN_WARNING
"RX: IEEE802.1X EAPOL frame!\n");
1178 static void rtllib_rx_check_leave_lps(struct rtllib_device
*ieee
, u8 unicast
, u8 nr_subframes
)
1182 if ((ieee
->state
== RTLLIB_LINKED
)) {
1183 if (((ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+
1184 ieee
->LinkDetectInfo
.NumTxOkInPeriod
) > 8) ||
1185 (ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
> 2)) {
1186 if (ieee
->LeisurePSLeave
)
1187 ieee
->LeisurePSLeave(ieee
->dev
);
1191 ieee
->last_rx_ps_time
= jiffies
;
1194 static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device
*ieee
,
1195 struct rtllib_rx_stats
*rx_stats
,
1196 struct rtllib_rxb
*rxb
,
1200 struct net_device
*dev
= ieee
->dev
;
1205 printk(KERN_INFO
"%s: rxb is NULL!!\n", __func__
);
1209 for (i
= 0; i
< rxb
->nr_subframes
; i
++) {
1210 struct sk_buff
*sub_skb
= rxb
->subframes
[i
];
1213 /* convert hdr + possible LLC headers into Ethernet header */
1214 ethertype
= (sub_skb
->data
[6] << 8) | sub_skb
->data
[7];
1215 if (sub_skb
->len
>= 8 &&
1216 ((memcmp(sub_skb
->data
, rfc1042_header
, SNAP_SIZE
) == 0 &&
1217 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1218 memcmp(sub_skb
->data
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
1219 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1220 * replace EtherType */
1221 skb_pull(sub_skb
, SNAP_SIZE
);
1222 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1223 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1226 /* Leave Ethernet header part of hdr and full payload */
1228 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1229 memcpy(skb_push(sub_skb
, ETH_ALEN
), src
, ETH_ALEN
);
1230 memcpy(skb_push(sub_skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1233 ieee
->stats
.rx_packets
++;
1234 ieee
->stats
.rx_bytes
+= sub_skb
->len
;
1236 if (is_multicast_ether_addr(dst
))
1237 ieee
->stats
.multicast
++;
1239 /* Indicate the packets to upper layer */
1240 memset(sub_skb
->cb
, 0, sizeof(sub_skb
->cb
));
1241 sub_skb
->protocol
= eth_type_trans(sub_skb
, dev
);
1243 sub_skb
->dev
->stats
.rx_packets
++;
1244 sub_skb
->dev
->stats
.rx_bytes
+= sub_skb
->len
;
1245 sub_skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
1253 static int rtllib_rx_InfraAdhoc(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1254 struct rtllib_rx_stats
*rx_stats
)
1256 struct net_device
*dev
= ieee
->dev
;
1257 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1258 struct lib80211_crypt_data
*crypt
= NULL
;
1259 struct rtllib_rxb
*rxb
= NULL
;
1260 struct rx_ts_record
*pTS
= NULL
;
1261 u16 fc
, sc
, SeqNum
= 0;
1262 u8 type
, stype
, multicast
= 0, unicast
= 0, nr_subframes
= 0, TID
= 0;
1263 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
], bssid
[ETH_ALEN
] = {0}, *payload
;
1265 bool bToOtherSTA
= false;
1268 hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1269 fc
= le16_to_cpu(hdr
->frame_ctl
);
1270 type
= WLAN_FC_GET_TYPE(fc
);
1271 stype
= WLAN_FC_GET_STYPE(fc
);
1272 sc
= le16_to_cpu(hdr
->seq_ctl
);
1274 /*Filter pkt not to me*/
1275 multicast
= is_multicast_ether_addr(hdr
->addr1
);
1276 unicast
= !multicast
;
1277 if (unicast
&& !ether_addr_equal(dev
->dev_addr
, hdr
->addr1
)) {
1278 if (ieee
->bNetPromiscuousMode
)
1284 /*Filter pkt has too small length */
1285 hdrlen
= rtllib_rx_get_hdrlen(ieee
, skb
, rx_stats
);
1286 if (skb
->len
< hdrlen
) {
1287 printk(KERN_INFO
"%s():ERR!!! skb->len is smaller than hdrlen\n", __func__
);
1291 /* Filter Duplicate pkt */
1292 ret
= rtllib_rx_check_duplicate(ieee
, skb
, multicast
);
1296 /* Filter CTRL Frame */
1297 if (type
== RTLLIB_FTYPE_CTL
)
1300 /* Filter MGNT Frame */
1301 if (type
== RTLLIB_FTYPE_MGMT
) {
1304 if (rtllib_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
1310 /* Filter WAPI DATA Frame */
1312 /* Update statstics for AP roaming */
1314 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
++;
1315 ieee
->LinkDetectInfo
.NumRxOkInPeriod
++;
1317 dev
->last_rx
= jiffies
;
1319 /* Data frame - extract src/dst addresses */
1320 rtllib_rx_extract_addr(ieee
, hdr
, dst
, src
, bssid
);
1322 /* Filter Data frames */
1323 ret
= rtllib_rx_data_filter(ieee
, fc
, dst
, src
, bssid
, hdr
->addr2
);
1327 if (skb
->len
== hdrlen
)
1330 /* Send pspoll based on moredata */
1331 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && (ieee
->sta_sleep
== LPS_IS_SLEEP
)
1332 && (ieee
->polling
) && (!bToOtherSTA
)) {
1333 if (WLAN_FC_MORE_DATA(fc
)) {
1334 /* more data bit is set, let's request a new frame from the AP */
1335 rtllib_sta_ps_send_pspoll_frame(ieee
);
1337 ieee
->polling
= false;
1341 /* Get crypt if encrypted */
1342 ret
= rtllib_rx_get_crypt(ieee
, skb
, &crypt
, hdrlen
);
1346 /* Decrypt data frame (including reassemble) */
1347 ret
= rtllib_rx_decrypt(ieee
, skb
, rx_stats
, crypt
, hdrlen
);
1353 /* Get TS for Rx Reorder */
1354 hdr
= (struct rtllib_hdr_4addr
*) skb
->data
;
1355 if (ieee
->current_network
.qos_data
.active
&& IsQoSDataFrame(skb
->data
)
1356 && !is_multicast_ether_addr(hdr
->addr1
)
1357 && (!bToOtherSTA
)) {
1358 TID
= Frame_QoSTID(skb
->data
);
1359 SeqNum
= WLAN_GET_SEQ_SEQ(sc
);
1360 GetTs(ieee
, (struct ts_common_info
**) &pTS
, hdr
->addr2
, TID
, RX_DIR
, true);
1361 if (TID
!= 0 && TID
!= 3)
1362 ieee
->bis_any_nonbepkts
= true;
1365 /* Parse rx data frame (For AMSDU) */
1366 /* skb: hdr + (possible reassembled) full plaintext payload */
1367 payload
= skb
->data
+ hdrlen
;
1368 rxb
= kmalloc(sizeof(struct rtllib_rxb
), GFP_ATOMIC
);
1370 RTLLIB_DEBUG(RTLLIB_DL_ERR
,
1371 "%s(): kmalloc rxb error\n", __func__
);
1374 /* to parse amsdu packets */
1375 /* qos data packets & reserved bit is 1 */
1376 if (parse_subframe(ieee
, skb
, rx_stats
, rxb
, src
, dst
) == 0) {
1377 /* only to free rxb, and not submit the packets to upper layer */
1378 for (i
= 0; i
< rxb
->nr_subframes
; i
++)
1379 dev_kfree_skb(rxb
->subframes
[i
]);
1385 /* Update WAPI PN */
1387 /* Check if leave LPS */
1389 if (ieee
->bIsAggregateFrame
)
1390 nr_subframes
= rxb
->nr_subframes
;
1394 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
+= nr_subframes
;
1395 rtllib_rx_check_leave_lps(ieee
, unicast
, nr_subframes
);
1398 /* Indicate packets to upper layer or Rx Reorder */
1399 if (ieee
->pHTInfo
->bCurRxReorderEnable
== false || pTS
== NULL
|| bToOtherSTA
)
1400 rtllib_rx_indicate_pkt_legacy(ieee
, rx_stats
, rxb
, dst
, src
);
1402 RxReorderIndicatePacket(ieee
, rxb
, pTS
, SeqNum
);
1414 ieee
->stats
.rx_dropped
++;
1416 /* Returning 0 indicates to caller that we have not handled the SKB--
1417 * so it is still allocated and can be used again by underlying
1418 * hardware as a DMA target */
1422 static int rtllib_rx_Master(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1423 struct rtllib_rx_stats
*rx_stats
)
1428 static int rtllib_rx_Monitor(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1429 struct rtllib_rx_stats
*rx_stats
)
1431 struct rtllib_hdr_4addr
*hdr
= (struct rtllib_hdr_4addr
*)skb
->data
;
1432 u16 fc
= le16_to_cpu(hdr
->frame_ctl
);
1433 size_t hdrlen
= rtllib_get_hdrlen(fc
);
1435 if (skb
->len
< hdrlen
) {
1436 printk(KERN_INFO
"%s():ERR!!! skb->len is smaller than hdrlen\n", __func__
);
1440 if (HTCCheck(ieee
, skb
->data
)) {
1441 if (net_ratelimit())
1442 printk(KERN_INFO
"%s: Find HTCControl!\n", __func__
);
1446 rtllib_monitor_rx(ieee
, skb
, rx_stats
, hdrlen
);
1447 ieee
->stats
.rx_packets
++;
1448 ieee
->stats
.rx_bytes
+= skb
->len
;
1453 static int rtllib_rx_Mesh(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1454 struct rtllib_rx_stats
*rx_stats
)
1459 /* All received frames are sent to this function. @skb contains the frame in
1460 * IEEE 802.11 format, i.e., in the format it was sent over air.
1461 * This function is called only as a tasklet (software IRQ). */
1462 int rtllib_rx(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1463 struct rtllib_rx_stats
*rx_stats
)
1467 if ((NULL
== ieee
) || (NULL
== skb
) || (NULL
== rx_stats
)) {
1468 printk(KERN_INFO
"%s: Input parameters NULL!\n", __func__
);
1471 if (skb
->len
< 10) {
1472 printk(KERN_INFO
"%s: SKB length < 10\n", __func__
);
1476 switch (ieee
->iw_mode
) {
1479 ret
= rtllib_rx_InfraAdhoc(ieee
, skb
, rx_stats
);
1481 case IW_MODE_MASTER
:
1482 case IW_MODE_REPEAT
:
1483 ret
= rtllib_rx_Master(ieee
, skb
, rx_stats
);
1485 case IW_MODE_MONITOR
:
1486 ret
= rtllib_rx_Monitor(ieee
, skb
, rx_stats
);
1489 ret
= rtllib_rx_Mesh(ieee
, skb
, rx_stats
);
1492 printk(KERN_INFO
"%s: ERR iw mode!!!\n", __func__
);
1499 ieee
->stats
.rx_dropped
++;
1502 EXPORT_SYMBOL(rtllib_rx
);
1504 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
1507 * Make ther structure we read from the beacon packet has
1510 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1511 *info_element
, int sub_type
)
1514 if (info_element
->qui_subtype
!= sub_type
)
1516 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
1518 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
1520 if (info_element
->version
!= QOS_VERSION_1
)
1528 * Parse a QoS parameter element
1530 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
1531 *element_param
, struct rtllib_info_element
1535 u16 size
= sizeof(struct rtllib_qos_parameter_info
) - 2;
1537 if ((info_element
== NULL
) || (element_param
== NULL
))
1540 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
1541 memcpy(element_param
->info_element
.qui
, info_element
->data
,
1543 element_param
->info_element
.elementID
= info_element
->id
;
1544 element_param
->info_element
.length
= info_element
->len
;
1548 ret
= rtllib_verify_qos_info(&element_param
->info_element
,
1549 QOS_OUI_PARAM_SUB_TYPE
);
1554 * Parse a QoS information element
1556 static int rtllib_read_qos_info_element(struct
1557 rtllib_qos_information_element
1558 *element_info
, struct rtllib_info_element
1562 u16 size
= sizeof(struct rtllib_qos_information_element
) - 2;
1564 if (element_info
== NULL
)
1566 if (info_element
== NULL
)
1569 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
1570 memcpy(element_info
->qui
, info_element
->data
,
1572 element_info
->elementID
= info_element
->id
;
1573 element_info
->length
= info_element
->len
;
1578 ret
= rtllib_verify_qos_info(element_info
,
1579 QOS_OUI_INFO_SUB_TYPE
);
1585 * Write QoS parameters from the ac parameters.
1587 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info
*param_elm
,
1588 struct rtllib_qos_data
*qos_data
)
1590 struct rtllib_qos_ac_parameter
*ac_params
;
1591 struct rtllib_qos_parameters
*qos_param
= &(qos_data
->parameters
);
1597 qos_data
->wmm_acm
= 0;
1598 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1599 ac_params
= &(param_elm
->ac_params_record
[i
]);
1601 aci
= (ac_params
->aci_aifsn
& 0x60) >> 5;
1602 acm
= (ac_params
->aci_aifsn
& 0x10) >> 4;
1604 if (aci
>= QOS_QUEUE_NUM
)
1608 /* BIT(0) | BIT(3) */
1610 qos_data
->wmm_acm
|= (0x01<<0)|(0x01<<3);
1613 /* BIT(4) | BIT(5) */
1615 qos_data
->wmm_acm
|= (0x01<<4)|(0x01<<5);
1618 /* BIT(6) | BIT(7) */
1620 qos_data
->wmm_acm
|= (0x01<<6)|(0x01<<7);
1624 /* BIT(1) | BIT(2) */
1626 qos_data
->wmm_acm
|= (0x01<<1)|(0x01<<2);
1630 qos_param
->aifs
[aci
] = (ac_params
->aci_aifsn
) & 0x0f;
1632 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1633 qos_param
->aifs
[aci
] = (qos_param
->aifs
[aci
] < 2) ? 2 : qos_param
->aifs
[aci
];
1635 qos_param
->cw_min
[aci
] = cpu_to_le16(ac_params
->ecw_min_max
& 0x0F);
1637 qos_param
->cw_max
[aci
] = cpu_to_le16((ac_params
->ecw_min_max
& 0xF0) >> 4);
1639 qos_param
->flag
[aci
] =
1640 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1641 qos_param
->tx_op_limit
[aci
] = ac_params
->tx_op_limit
;
1647 * we have a generic data element which it may contain QoS information or
1648 * parameters element. check the information element length to decide
1649 * which type to read
1651 static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
1653 struct rtllib_network
*network
)
1656 struct rtllib_qos_information_element qos_info_element
;
1658 rc
= rtllib_read_qos_info_element(&qos_info_element
, info_element
);
1661 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1662 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1664 struct rtllib_qos_parameter_info param_element
;
1666 rc
= rtllib_read_qos_param_element(¶m_element
,
1669 rtllib_qos_convert_ac_to_parameters(¶m_element
,
1670 &(network
->qos_data
));
1671 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1672 network
->qos_data
.param_count
=
1673 param_element
.info_element
.ac_info
& 0x0F;
1678 RTLLIB_DEBUG_QOS("QoS is supported\n");
1679 network
->qos_data
.supported
= 1;
1684 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1686 static const char *get_info_element_string(u16 id
)
1691 MFIE_STRING(FH_SET
);
1692 MFIE_STRING(DS_SET
);
1693 MFIE_STRING(CF_SET
);
1695 MFIE_STRING(IBSS_SET
);
1696 MFIE_STRING(COUNTRY
);
1697 MFIE_STRING(HOP_PARAMS
);
1698 MFIE_STRING(HOP_TABLE
);
1699 MFIE_STRING(REQUEST
);
1700 MFIE_STRING(CHALLENGE
);
1701 MFIE_STRING(POWER_CONSTRAINT
);
1702 MFIE_STRING(POWER_CAPABILITY
);
1703 MFIE_STRING(TPC_REQUEST
);
1704 MFIE_STRING(TPC_REPORT
);
1705 MFIE_STRING(SUPP_CHANNELS
);
1707 MFIE_STRING(MEASURE_REQUEST
);
1708 MFIE_STRING(MEASURE_REPORT
);
1710 MFIE_STRING(IBSS_DFS
);
1712 MFIE_STRING(RATES_EX
);
1713 MFIE_STRING(GENERIC
);
1714 MFIE_STRING(QOS_PARAMETER
);
1720 static inline void rtllib_extract_country_ie(
1721 struct rtllib_device
*ieee
,
1722 struct rtllib_info_element
*info_element
,
1723 struct rtllib_network
*network
,
1726 if (IS_DOT11D_ENABLE(ieee
)) {
1727 if (info_element
->len
!= 0) {
1728 memcpy(network
->CountryIeBuf
, info_element
->data
, info_element
->len
);
1729 network
->CountryIeLen
= info_element
->len
;
1731 if (!IS_COUNTRY_IE_VALID(ieee
)) {
1732 if (rtllib_act_scanning(ieee
, false) && ieee
->FirstIe_InScan
)
1733 printk(KERN_INFO
"Received beacon ContryIE, SSID: <%s>\n", network
->ssid
);
1734 Dot11d_UpdateCountryIe(ieee
, addr2
, info_element
->len
, info_element
->data
);
1738 if (IS_EQUAL_CIE_SRC(ieee
, addr2
))
1739 UPDATE_CIE_WATCHDOG(ieee
);
1744 int rtllib_parse_info_param(struct rtllib_device
*ieee
,
1745 struct rtllib_info_element
*info_element
,
1747 struct rtllib_network
*network
,
1748 struct rtllib_rx_stats
*stats
)
1752 u16 tmp_htcap_len
= 0;
1753 u16 tmp_htinfo_len
= 0;
1754 u16 ht_realtek_agg_len
= 0;
1755 u8 ht_realtek_agg_buf
[MAX_IE_LEN
];
1759 while (length
>= sizeof(*info_element
)) {
1760 if (sizeof(*info_element
) + info_element
->len
> length
) {
1761 RTLLIB_DEBUG_MGMT("Info elem: parse failed: "
1762 "info_element->len + 2 > left : "
1763 "info_element->len+2=%zd left=%d, id=%d.\n",
1765 sizeof(*info_element
),
1766 length
, info_element
->id
);
1767 /* We stop processing but don't return an error here
1768 * because some misbehaviour APs break this rule. ie.
1769 * Orinoco AP1000. */
1773 switch (info_element
->id
) {
1774 case MFIE_TYPE_SSID
:
1775 if (rtllib_is_empty_essid(info_element
->data
,
1776 info_element
->len
)) {
1777 network
->flags
|= NETWORK_EMPTY_ESSID
;
1781 network
->ssid_len
= min(info_element
->len
,
1782 (u8
) IW_ESSID_MAX_SIZE
);
1783 memcpy(network
->ssid
, info_element
->data
, network
->ssid_len
);
1784 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1785 memset(network
->ssid
+ network
->ssid_len
, 0,
1786 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1788 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1789 network
->ssid
, network
->ssid_len
);
1792 case MFIE_TYPE_RATES
:
1794 network
->rates_len
= min(info_element
->len
,
1796 for (i
= 0; i
< network
->rates_len
; i
++) {
1797 network
->rates
[i
] = info_element
->data
[i
];
1798 p
+= snprintf(p
, sizeof(rates_str
) -
1799 (p
- rates_str
), "%02X ",
1801 if (rtllib_is_ofdm_rate
1802 (info_element
->data
[i
])) {
1803 network
->flags
|= NETWORK_HAS_OFDM
;
1804 if (info_element
->data
[i
] &
1805 RTLLIB_BASIC_RATE_MASK
)
1810 if (rtllib_is_cck_rate
1811 (info_element
->data
[i
])) {
1812 network
->flags
|= NETWORK_HAS_CCK
;
1816 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1817 rates_str
, network
->rates_len
);
1820 case MFIE_TYPE_RATES_EX
:
1822 network
->rates_ex_len
= min(info_element
->len
,
1823 MAX_RATES_EX_LENGTH
);
1824 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1825 network
->rates_ex
[i
] = info_element
->data
[i
];
1826 p
+= snprintf(p
, sizeof(rates_str
) -
1827 (p
- rates_str
), "%02X ",
1828 network
->rates_ex
[i
]);
1829 if (rtllib_is_ofdm_rate
1830 (info_element
->data
[i
])) {
1831 network
->flags
|= NETWORK_HAS_OFDM
;
1832 if (info_element
->data
[i
] &
1833 RTLLIB_BASIC_RATE_MASK
)
1839 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1840 rates_str
, network
->rates_ex_len
);
1843 case MFIE_TYPE_DS_SET
:
1844 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1845 info_element
->data
[0]);
1846 network
->channel
= info_element
->data
[0];
1849 case MFIE_TYPE_FH_SET
:
1850 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1853 case MFIE_TYPE_CF_SET
:
1854 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1858 if (info_element
->len
< 4)
1861 network
->tim
.tim_count
= info_element
->data
[0];
1862 network
->tim
.tim_period
= info_element
->data
[1];
1864 network
->dtim_period
= info_element
->data
[1];
1865 if (ieee
->state
!= RTLLIB_LINKED
)
1867 network
->last_dtim_sta_time
= jiffies
;
1869 network
->dtim_data
= RTLLIB_DTIM_VALID
;
1872 if (info_element
->data
[2] & 1)
1873 network
->dtim_data
|= RTLLIB_DTIM_MBCAST
;
1875 offset
= (info_element
->data
[2] >> 1)*2;
1878 if (ieee
->assoc_id
< 8*offset
||
1879 ieee
->assoc_id
> 8*(offset
+ info_element
->len
- 3))
1882 offset
= (ieee
->assoc_id
/ 8) - offset
;
1883 if (info_element
->data
[3 + offset
] &
1884 (1 << (ieee
->assoc_id
% 8)))
1885 network
->dtim_data
|= RTLLIB_DTIM_UCAST
;
1887 network
->listen_interval
= network
->dtim_period
;
1891 network
->erp_value
= info_element
->data
[0];
1892 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1893 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1894 network
->erp_value
);
1896 case MFIE_TYPE_IBSS_SET
:
1897 network
->atim_window
= info_element
->data
[0];
1898 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1899 network
->atim_window
);
1902 case MFIE_TYPE_CHALLENGE
:
1903 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1906 case MFIE_TYPE_GENERIC
:
1907 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1909 if (!rtllib_parse_qos_info_param_IE(info_element
,
1912 if (info_element
->len
>= 4 &&
1913 info_element
->data
[0] == 0x00 &&
1914 info_element
->data
[1] == 0x50 &&
1915 info_element
->data
[2] == 0xf2 &&
1916 info_element
->data
[3] == 0x01) {
1917 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1919 memcpy(network
->wpa_ie
, info_element
,
1920 network
->wpa_ie_len
);
1923 if (info_element
->len
== 7 &&
1924 info_element
->data
[0] == 0x00 &&
1925 info_element
->data
[1] == 0xe0 &&
1926 info_element
->data
[2] == 0x4c &&
1927 info_element
->data
[3] == 0x01 &&
1928 info_element
->data
[4] == 0x02)
1929 network
->Turbo_Enable
= 1;
1931 if (tmp_htcap_len
== 0) {
1932 if (info_element
->len
>= 4 &&
1933 info_element
->data
[0] == 0x00 &&
1934 info_element
->data
[1] == 0x90 &&
1935 info_element
->data
[2] == 0x4c &&
1936 info_element
->data
[3] == 0x033) {
1938 tmp_htcap_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
1939 if (tmp_htcap_len
!= 0) {
1940 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1941 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
) ?
1942 sizeof(network
->bssht
.bdHTCapBuf
) : tmp_htcap_len
;
1943 memcpy(network
->bssht
.bdHTCapBuf
, info_element
->data
, network
->bssht
.bdHTCapLen
);
1946 if (tmp_htcap_len
!= 0) {
1947 network
->bssht
.bdSupportHT
= true;
1948 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)(network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0);
1950 network
->bssht
.bdSupportHT
= false;
1951 network
->bssht
.bdHT1R
= false;
1956 if (tmp_htinfo_len
== 0) {
1957 if (info_element
->len
>= 4 &&
1958 info_element
->data
[0] == 0x00 &&
1959 info_element
->data
[1] == 0x90 &&
1960 info_element
->data
[2] == 0x4c &&
1961 info_element
->data
[3] == 0x034) {
1962 tmp_htinfo_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
1963 if (tmp_htinfo_len
!= 0) {
1964 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
1965 if (tmp_htinfo_len
) {
1966 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
> sizeof(network
->bssht
.bdHTInfoBuf
) ?
1967 sizeof(network
->bssht
.bdHTInfoBuf
) : tmp_htinfo_len
;
1968 memcpy(network
->bssht
.bdHTInfoBuf
, info_element
->data
, network
->bssht
.bdHTInfoLen
);
1976 if (ieee
->aggregation
) {
1977 if (network
->bssht
.bdSupportHT
) {
1978 if (info_element
->len
>= 4 &&
1979 info_element
->data
[0] == 0x00 &&
1980 info_element
->data
[1] == 0xe0 &&
1981 info_element
->data
[2] == 0x4c &&
1982 info_element
->data
[3] == 0x02) {
1983 ht_realtek_agg_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
1984 memcpy(ht_realtek_agg_buf
, info_element
->data
, info_element
->len
);
1986 if (ht_realtek_agg_len
>= 5) {
1987 network
->realtek_cap_exit
= true;
1988 network
->bssht
.bdRT2RTAggregation
= true;
1990 if ((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & 0x02))
1991 network
->bssht
.bdRT2RTLongSlotTime
= true;
1993 if ((ht_realtek_agg_buf
[4] == 1) && (ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_92SE
))
1994 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_92SE
;
1997 if (ht_realtek_agg_len
>= 5) {
1998 if ((ht_realtek_agg_buf
[5] & RT_HT_CAP_USE_SOFTAP
))
1999 network
->bssht
.RT2RT_HT_Mode
|= RT_HT_CAP_USE_SOFTAP
;
2003 if ((info_element
->len
>= 3 &&
2004 info_element
->data
[0] == 0x00 &&
2005 info_element
->data
[1] == 0x05 &&
2006 info_element
->data
[2] == 0xb5) ||
2007 (info_element
->len
>= 3 &&
2008 info_element
->data
[0] == 0x00 &&
2009 info_element
->data
[1] == 0x0a &&
2010 info_element
->data
[2] == 0xf7) ||
2011 (info_element
->len
>= 3 &&
2012 info_element
->data
[0] == 0x00 &&
2013 info_element
->data
[1] == 0x10 &&
2014 info_element
->data
[2] == 0x18)) {
2015 network
->broadcom_cap_exist
= true;
2017 if (info_element
->len
>= 3 &&
2018 info_element
->data
[0] == 0x00 &&
2019 info_element
->data
[1] == 0x0c &&
2020 info_element
->data
[2] == 0x43)
2021 network
->ralink_cap_exist
= true;
2022 if ((info_element
->len
>= 3 &&
2023 info_element
->data
[0] == 0x00 &&
2024 info_element
->data
[1] == 0x03 &&
2025 info_element
->data
[2] == 0x7f) ||
2026 (info_element
->len
>= 3 &&
2027 info_element
->data
[0] == 0x00 &&
2028 info_element
->data
[1] == 0x13 &&
2029 info_element
->data
[2] == 0x74))
2030 network
->atheros_cap_exist
= true;
2032 if ((info_element
->len
>= 3 &&
2033 info_element
->data
[0] == 0x00 &&
2034 info_element
->data
[1] == 0x50 &&
2035 info_element
->data
[2] == 0x43))
2036 network
->marvell_cap_exist
= true;
2037 if (info_element
->len
>= 3 &&
2038 info_element
->data
[0] == 0x00 &&
2039 info_element
->data
[1] == 0x40 &&
2040 info_element
->data
[2] == 0x96)
2041 network
->cisco_cap_exist
= true;
2044 if (info_element
->len
>= 3 &&
2045 info_element
->data
[0] == 0x00 &&
2046 info_element
->data
[1] == 0x0a &&
2047 info_element
->data
[2] == 0xf5)
2048 network
->airgo_cap_exist
= true;
2050 if (info_element
->len
> 4 &&
2051 info_element
->data
[0] == 0x00 &&
2052 info_element
->data
[1] == 0x40 &&
2053 info_element
->data
[2] == 0x96 &&
2054 info_element
->data
[3] == 0x01) {
2055 if (info_element
->len
== 6) {
2056 memcpy(network
->CcxRmState
, &info_element
[4], 2);
2057 if (network
->CcxRmState
[0] != 0)
2058 network
->bCcxRmEnable
= true;
2060 network
->bCcxRmEnable
= false;
2061 network
->MBssidMask
= network
->CcxRmState
[1] & 0x07;
2062 if (network
->MBssidMask
!= 0) {
2063 network
->bMBssidValid
= true;
2064 network
->MBssidMask
= 0xff << (network
->MBssidMask
);
2065 memcpy(network
->MBssid
, network
->bssid
, ETH_ALEN
);
2066 network
->MBssid
[5] &= network
->MBssidMask
;
2068 network
->bMBssidValid
= false;
2071 network
->bCcxRmEnable
= false;
2074 if (info_element
->len
> 4 &&
2075 info_element
->data
[0] == 0x00 &&
2076 info_element
->data
[1] == 0x40 &&
2077 info_element
->data
[2] == 0x96 &&
2078 info_element
->data
[3] == 0x03) {
2079 if (info_element
->len
== 5) {
2080 network
->bWithCcxVerNum
= true;
2081 network
->BssCcxVerNumber
= info_element
->data
[4];
2083 network
->bWithCcxVerNum
= false;
2084 network
->BssCcxVerNumber
= 0;
2087 if (info_element
->len
> 4 &&
2088 info_element
->data
[0] == 0x00 &&
2089 info_element
->data
[1] == 0x50 &&
2090 info_element
->data
[2] == 0xf2 &&
2091 info_element
->data
[3] == 0x04) {
2092 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
2094 network
->wzc_ie_len
= min(info_element
->len
+2,
2096 memcpy(network
->wzc_ie
, info_element
,
2097 network
->wzc_ie_len
);
2102 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2104 network
->rsn_ie_len
= min(info_element
->len
+ 2,
2106 memcpy(network
->rsn_ie
, info_element
,
2107 network
->rsn_ie_len
);
2110 case MFIE_TYPE_HT_CAP
:
2111 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2113 tmp_htcap_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
2114 if (tmp_htcap_len
!= 0) {
2115 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_EWC
;
2116 network
->bssht
.bdHTCapLen
= tmp_htcap_len
> sizeof(network
->bssht
.bdHTCapBuf
) ?
2117 sizeof(network
->bssht
.bdHTCapBuf
) : tmp_htcap_len
;
2118 memcpy(network
->bssht
.bdHTCapBuf
,
2120 network
->bssht
.bdHTCapLen
);
2122 network
->bssht
.bdSupportHT
= true;
2123 network
->bssht
.bdHT1R
= ((((struct ht_capab_ele
*)
2124 network
->bssht
.bdHTCapBuf
))->MCS
[1]) == 0;
2126 network
->bssht
.bdBandWidth
= (enum ht_channel_width
)
2127 (((struct ht_capab_ele
*)
2128 (network
->bssht
.bdHTCapBuf
))->ChlWidth
);
2130 network
->bssht
.bdSupportHT
= false;
2131 network
->bssht
.bdHT1R
= false;
2132 network
->bssht
.bdBandWidth
= HT_CHANNEL_WIDTH_20
;
2137 case MFIE_TYPE_HT_INFO
:
2138 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2140 tmp_htinfo_len
= min(info_element
->len
, (u8
)MAX_IE_LEN
);
2141 if (tmp_htinfo_len
) {
2142 network
->bssht
.bdHTSpecVer
= HT_SPEC_VER_IEEE
;
2143 network
->bssht
.bdHTInfoLen
= tmp_htinfo_len
>
2144 sizeof(network
->bssht
.bdHTInfoBuf
) ?
2145 sizeof(network
->bssht
.bdHTInfoBuf
) :
2147 memcpy(network
->bssht
.bdHTInfoBuf
,
2149 network
->bssht
.bdHTInfoLen
);
2153 case MFIE_TYPE_AIRONET
:
2154 RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2156 if (info_element
->len
> IE_CISCO_FLAG_POSITION
) {
2157 network
->bWithAironetIE
= true;
2159 if ((info_element
->data
[IE_CISCO_FLAG_POSITION
]
2160 & SUPPORT_CKIP_MIC
) ||
2161 (info_element
->data
[IE_CISCO_FLAG_POSITION
]
2163 network
->bCkipSupported
= true;
2165 network
->bCkipSupported
= false;
2167 network
->bWithAironetIE
= false;
2168 network
->bCkipSupported
= false;
2171 case MFIE_TYPE_QOS_PARAMETER
:
2173 "QoS Error need to parse QOS_PARAMETER IE\n");
2176 case MFIE_TYPE_COUNTRY
:
2177 RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2179 rtllib_extract_country_ie(ieee
, info_element
, network
,
2185 ("Unsupported info element: %s (%d)\n",
2186 get_info_element_string(info_element
->id
),
2191 length
-= sizeof(*info_element
) + info_element
->len
;
2193 (struct rtllib_info_element
*)&info_element
->
2194 data
[info_element
->len
];
2197 if (!network
->atheros_cap_exist
&& !network
->broadcom_cap_exist
&&
2198 !network
->cisco_cap_exist
&& !network
->ralink_cap_exist
&&
2199 !network
->bssht
.bdRT2RTAggregation
)
2200 network
->unknown_cap_exist
= true;
2202 network
->unknown_cap_exist
= false;
2206 static inline u8
rtllib_SignalStrengthTranslate(u8 CurrSS
)
2210 if (CurrSS
>= 71 && CurrSS
<= 100)
2211 RetSS
= 90 + ((CurrSS
- 70) / 3);
2212 else if (CurrSS
>= 41 && CurrSS
<= 70)
2213 RetSS
= 78 + ((CurrSS
- 40) / 3);
2214 else if (CurrSS
>= 31 && CurrSS
<= 40)
2215 RetSS
= 66 + (CurrSS
- 30);
2216 else if (CurrSS
>= 21 && CurrSS
<= 30)
2217 RetSS
= 54 + (CurrSS
- 20);
2218 else if (CurrSS
>= 5 && CurrSS
<= 20)
2219 RetSS
= 42 + (((CurrSS
- 5) * 2) / 3);
2220 else if (CurrSS
== 4)
2222 else if (CurrSS
== 3)
2224 else if (CurrSS
== 2)
2226 else if (CurrSS
== 1)
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
)
2252 network->qos_data.active = 0;
2253 network->qos_data.supported = 0;
2254 network->qos_data.param_count = 0;
2255 network->qos_data.old_param_count = 0;
2257 memset(&network
->qos_data
, 0, sizeof(struct rtllib_qos_data
));
2259 /* Pull out fixed field data */
2260 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
2261 network
->capability
= le16_to_cpu(beacon
->capability
);
2262 network
->last_scanned
= jiffies
;
2263 network
->time_stamp
[0] = beacon
->time_stamp
[0];
2264 network
->time_stamp
[1] = beacon
->time_stamp
[1];
2265 network
->beacon_interval
= le16_to_cpu(beacon
->beacon_interval
);
2266 /* Where to pull this? beacon->listen_interval;*/
2267 network
->listen_interval
= 0x0A;
2268 network
->rates_len
= network
->rates_ex_len
= 0;
2269 network
->last_associate
= 0;
2270 network
->ssid_len
= 0;
2271 network
->hidden_ssid_len
= 0;
2272 memset(network
->hidden_ssid
, 0, sizeof(network
->hidden_ssid
));
2274 network
->atim_window
= 0;
2275 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
2277 network
->berp_info_valid
= false;
2278 network
->broadcom_cap_exist
= false;
2279 network
->ralink_cap_exist
= false;
2280 network
->atheros_cap_exist
= false;
2281 network
->cisco_cap_exist
= false;
2282 network
->unknown_cap_exist
= false;
2283 network
->realtek_cap_exit
= false;
2284 network
->marvell_cap_exist
= false;
2285 network
->airgo_cap_exist
= false;
2286 network
->Turbo_Enable
= 0;
2287 network
->SignalStrength
= stats
->SignalStrength
;
2288 network
->RSSI
= stats
->SignalStrength
;
2289 network
->CountryIeLen
= 0;
2290 memset(network
->CountryIeBuf
, 0, MAX_IE_LEN
);
2291 HTInitializeBssDesc(&network
->bssht
);
2292 if (stats
->freq
== RTLLIB_52GHZ_BAND
) {
2293 /* for A band (No DS info) */
2294 network
->channel
= stats
->received_channel
;
2296 network
->flags
|= NETWORK_HAS_CCK
;
2298 network
->wpa_ie_len
= 0;
2299 network
->rsn_ie_len
= 0;
2300 network
->wzc_ie_len
= 0;
2302 if (rtllib_parse_info_param(ieee
,
2303 beacon
->info_element
,
2304 (stats
->len
- sizeof(*beacon
)),
2310 if (stats
->freq
== RTLLIB_52GHZ_BAND
)
2311 network
->mode
= IEEE_A
;
2313 if (network
->flags
& NETWORK_HAS_OFDM
)
2314 network
->mode
|= IEEE_G
;
2315 if (network
->flags
& NETWORK_HAS_CCK
)
2316 network
->mode
|= IEEE_B
;
2319 if (network
->mode
== 0) {
2320 RTLLIB_DEBUG_SCAN("Filtered out '%s (%pM)' "
2322 escape_essid(network
->ssid
,
2328 if (network
->bssht
.bdSupportHT
) {
2329 if (network
->mode
== IEEE_A
)
2330 network
->mode
= IEEE_N_5G
;
2331 else if (network
->mode
& (IEEE_G
| IEEE_B
))
2332 network
->mode
= IEEE_N_24G
;
2334 if (rtllib_is_empty_essid(network
->ssid
, network
->ssid_len
))
2335 network
->flags
|= NETWORK_EMPTY_ESSID
;
2336 stats
->signal
= 30 + (stats
->SignalStrength
* 70) / 100;
2337 stats
->noise
= rtllib_translate_todbm((u8
)(100-stats
->signal
)) - 25;
2339 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
2344 static inline int is_same_network(struct rtllib_network
*src
,
2345 struct rtllib_network
*dst
, u8 ssidbroad
)
2347 /* A network is only a duplicate if the channel, BSSID, ESSID
2348 * and the capability field (in particular IBSS and BSS) all match.
2349 * We treat all <hidden> with the same BSSID and channel
2351 return (((src
->ssid_len
== dst
->ssid_len
) || (!ssidbroad
)) &&
2352 (src
->channel
== dst
->channel
) &&
2353 !memcmp(src
->bssid
, dst
->bssid
, ETH_ALEN
) &&
2354 (!memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
) ||
2356 ((src
->capability
& WLAN_CAPABILITY_IBSS
) ==
2357 (dst
->capability
& WLAN_CAPABILITY_IBSS
)) &&
2358 ((src
->capability
& WLAN_CAPABILITY_ESS
) ==
2359 (dst
->capability
& WLAN_CAPABILITY_ESS
)));
2362 static inline void update_ibss_network(struct rtllib_network
*dst
,
2363 struct rtllib_network
*src
)
2365 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct rtllib_rx_stats
));
2366 dst
->last_scanned
= jiffies
;
2370 static inline void update_network(struct rtllib_network
*dst
,
2371 struct rtllib_network
*src
)
2376 memcpy(&dst
->stats
, &src
->stats
, sizeof(struct rtllib_rx_stats
));
2377 dst
->capability
= src
->capability
;
2378 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
2379 dst
->rates_len
= src
->rates_len
;
2380 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
2381 dst
->rates_ex_len
= src
->rates_ex_len
;
2382 if (src
->ssid_len
> 0) {
2383 if (dst
->ssid_len
== 0) {
2384 memset(dst
->hidden_ssid
, 0, sizeof(dst
->hidden_ssid
));
2385 dst
->hidden_ssid_len
= src
->ssid_len
;
2386 memcpy(dst
->hidden_ssid
, src
->ssid
, src
->ssid_len
);
2388 memset(dst
->ssid
, 0, dst
->ssid_len
);
2389 dst
->ssid_len
= src
->ssid_len
;
2390 memcpy(dst
->ssid
, src
->ssid
, src
->ssid_len
);
2393 dst
->mode
= src
->mode
;
2394 dst
->flags
= src
->flags
;
2395 dst
->time_stamp
[0] = src
->time_stamp
[0];
2396 dst
->time_stamp
[1] = src
->time_stamp
[1];
2397 if (src
->flags
& NETWORK_HAS_ERP_VALUE
) {
2398 dst
->erp_value
= src
->erp_value
;
2399 dst
->berp_info_valid
= src
->berp_info_valid
= true;
2401 dst
->beacon_interval
= src
->beacon_interval
;
2402 dst
->listen_interval
= src
->listen_interval
;
2403 dst
->atim_window
= src
->atim_window
;
2404 dst
->dtim_period
= src
->dtim_period
;
2405 dst
->dtim_data
= src
->dtim_data
;
2406 dst
->last_dtim_sta_time
= src
->last_dtim_sta_time
;
2407 memcpy(&dst
->tim
, &src
->tim
, sizeof(struct rtllib_tim_parameters
));
2409 dst
->bssht
.bdSupportHT
= src
->bssht
.bdSupportHT
;
2410 dst
->bssht
.bdRT2RTAggregation
= src
->bssht
.bdRT2RTAggregation
;
2411 dst
->bssht
.bdHTCapLen
= src
->bssht
.bdHTCapLen
;
2412 memcpy(dst
->bssht
.bdHTCapBuf
, src
->bssht
.bdHTCapBuf
,
2413 src
->bssht
.bdHTCapLen
);
2414 dst
->bssht
.bdHTInfoLen
= src
->bssht
.bdHTInfoLen
;
2415 memcpy(dst
->bssht
.bdHTInfoBuf
, src
->bssht
.bdHTInfoBuf
,
2416 src
->bssht
.bdHTInfoLen
);
2417 dst
->bssht
.bdHTSpecVer
= src
->bssht
.bdHTSpecVer
;
2418 dst
->bssht
.bdRT2RTLongSlotTime
= src
->bssht
.bdRT2RTLongSlotTime
;
2419 dst
->broadcom_cap_exist
= src
->broadcom_cap_exist
;
2420 dst
->ralink_cap_exist
= src
->ralink_cap_exist
;
2421 dst
->atheros_cap_exist
= src
->atheros_cap_exist
;
2422 dst
->realtek_cap_exit
= src
->realtek_cap_exit
;
2423 dst
->marvell_cap_exist
= src
->marvell_cap_exist
;
2424 dst
->cisco_cap_exist
= src
->cisco_cap_exist
;
2425 dst
->airgo_cap_exist
= src
->airgo_cap_exist
;
2426 dst
->unknown_cap_exist
= src
->unknown_cap_exist
;
2427 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
2428 dst
->wpa_ie_len
= src
->wpa_ie_len
;
2429 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
2430 dst
->rsn_ie_len
= src
->rsn_ie_len
;
2431 memcpy(dst
->wzc_ie
, src
->wzc_ie
, src
->wzc_ie_len
);
2432 dst
->wzc_ie_len
= src
->wzc_ie_len
;
2434 dst
->last_scanned
= jiffies
;
2435 /* qos related parameters */
2436 qos_active
= dst
->qos_data
.active
;
2437 old_param
= dst
->qos_data
.param_count
;
2438 dst
->qos_data
.supported
= src
->qos_data
.supported
;
2439 if (dst
->flags
& NETWORK_HAS_QOS_PARAMETERS
)
2440 memcpy(&dst
->qos_data
, &src
->qos_data
,
2441 sizeof(struct rtllib_qos_data
));
2442 if (dst
->qos_data
.supported
== 1) {
2445 ("QoS the network %s is QoS supported\n",
2449 ("QoS the network is QoS supported\n");
2451 dst
->qos_data
.active
= qos_active
;
2452 dst
->qos_data
.old_param_count
= old_param
;
2454 /* dst->last_associate is not overwritten */
2455 dst
->wmm_info
= src
->wmm_info
;
2456 if (src
->wmm_param
[0].ac_aci_acm_aifsn
||
2457 src
->wmm_param
[1].ac_aci_acm_aifsn
||
2458 src
->wmm_param
[2].ac_aci_acm_aifsn
||
2459 src
->wmm_param
[3].ac_aci_acm_aifsn
)
2460 memcpy(dst
->wmm_param
, src
->wmm_param
, WME_AC_PRAM_LEN
);
2462 dst
->SignalStrength
= src
->SignalStrength
;
2463 dst
->RSSI
= src
->RSSI
;
2464 dst
->Turbo_Enable
= src
->Turbo_Enable
;
2466 dst
->CountryIeLen
= src
->CountryIeLen
;
2467 memcpy(dst
->CountryIeBuf
, src
->CountryIeBuf
, src
->CountryIeLen
);
2469 dst
->bWithAironetIE
= src
->bWithAironetIE
;
2470 dst
->bCkipSupported
= src
->bCkipSupported
;
2471 memcpy(dst
->CcxRmState
, src
->CcxRmState
, 2);
2472 dst
->bCcxRmEnable
= src
->bCcxRmEnable
;
2473 dst
->MBssidMask
= src
->MBssidMask
;
2474 dst
->bMBssidValid
= src
->bMBssidValid
;
2475 memcpy(dst
->MBssid
, src
->MBssid
, 6);
2476 dst
->bWithCcxVerNum
= src
->bWithCcxVerNum
;
2477 dst
->BssCcxVerNumber
= src
->BssCcxVerNumber
;
2480 static inline int is_beacon(__le16 fc
)
2482 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == RTLLIB_STYPE_BEACON
);
2485 static int IsPassiveChannel(struct rtllib_device
*rtllib
, u8 channel
)
2487 if (MAX_CHANNEL_NUMBER
< channel
) {
2488 printk(KERN_INFO
"%s(): Invalid Channel\n", __func__
);
2492 if (rtllib
->active_channel_map
[channel
] == 2)
2498 int rtllib_legal_channel(struct rtllib_device
*rtllib
, u8 channel
)
2500 if (MAX_CHANNEL_NUMBER
< channel
) {
2501 printk(KERN_INFO
"%s(): Invalid Channel\n", __func__
);
2504 if (rtllib
->active_channel_map
[channel
] > 0)
2509 EXPORT_SYMBOL(rtllib_legal_channel
);
2511 static inline void rtllib_process_probe_response(
2512 struct rtllib_device
*ieee
,
2513 struct rtllib_probe_response
*beacon
,
2514 struct rtllib_rx_stats
*stats
)
2516 struct rtllib_network
*target
;
2517 struct rtllib_network
*oldest
= NULL
;
2518 struct rtllib_info_element
*info_element
= &beacon
->info_element
[0];
2519 unsigned long flags
;
2521 struct rtllib_network
*network
= kzalloc(sizeof(struct rtllib_network
),
2528 "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2529 escape_essid(info_element
->data
, info_element
->len
),
2530 beacon
->header
.addr3
,
2531 (le16_to_cpu(beacon
->capability
) & (1<<0xf)) ? '1' : '0',
2532 (le16_to_cpu(beacon
->capability
) & (1<<0xe)) ? '1' : '0',
2533 (le16_to_cpu(beacon
->capability
) & (1<<0xd)) ? '1' : '0',
2534 (le16_to_cpu(beacon
->capability
) & (1<<0xc)) ? '1' : '0',
2535 (le16_to_cpu(beacon
->capability
) & (1<<0xb)) ? '1' : '0',
2536 (le16_to_cpu(beacon
->capability
) & (1<<0xa)) ? '1' : '0',
2537 (le16_to_cpu(beacon
->capability
) & (1<<0x9)) ? '1' : '0',
2538 (le16_to_cpu(beacon
->capability
) & (1<<0x8)) ? '1' : '0',
2539 (le16_to_cpu(beacon
->capability
) & (1<<0x7)) ? '1' : '0',
2540 (le16_to_cpu(beacon
->capability
) & (1<<0x6)) ? '1' : '0',
2541 (le16_to_cpu(beacon
->capability
) & (1<<0x5)) ? '1' : '0',
2542 (le16_to_cpu(beacon
->capability
) & (1<<0x4)) ? '1' : '0',
2543 (le16_to_cpu(beacon
->capability
) & (1<<0x3)) ? '1' : '0',
2544 (le16_to_cpu(beacon
->capability
) & (1<<0x2)) ? '1' : '0',
2545 (le16_to_cpu(beacon
->capability
) & (1<<0x1)) ? '1' : '0',
2546 (le16_to_cpu(beacon
->capability
) & (1<<0x0)) ? '1' : '0');
2548 if (rtllib_network_init(ieee
, beacon
, network
, stats
)) {
2549 RTLLIB_DEBUG_SCAN("Dropped '%s' ( %pM) via %s.\n",
2550 escape_essid(info_element
->data
,
2552 beacon
->header
.addr3
,
2554 le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2555 RTLLIB_STYPE_PROBE_RESP
?
2556 "PROBE RESPONSE" : "BEACON");
2561 if (!rtllib_legal_channel(ieee
, network
->channel
))
2564 if (WLAN_FC_GET_STYPE(le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2565 RTLLIB_STYPE_PROBE_RESP
) {
2566 if (IsPassiveChannel(ieee
, network
->channel
)) {
2567 printk(KERN_INFO
"GetScanInfo(): For Global Domain, "
2568 "filter probe response at channel(%d).\n",
2574 /* The network parsed correctly -- so now we scan our known networks
2575 * to see if we can find it in our list.
2577 * NOTE: This search is definitely not optimized. Once its doing
2578 * the "right thing" we'll optimize it for efficiency if
2581 /* Search for this entry in the list and update it if it is
2584 spin_lock_irqsave(&ieee
->lock
, flags
);
2585 if (is_same_network(&ieee
->current_network
, network
,
2586 (network
->ssid_len
? 1 : 0))) {
2587 update_network(&ieee
->current_network
, network
);
2588 if ((ieee
->current_network
.mode
== IEEE_N_24G
||
2589 ieee
->current_network
.mode
== IEEE_G
)
2590 && ieee
->current_network
.berp_info_valid
) {
2591 if (ieee
->current_network
.erp_value
& ERP_UseProtection
)
2592 ieee
->current_network
.buseprotection
= true;
2594 ieee
->current_network
.buseprotection
= false;
2596 if (is_beacon(beacon
->header
.frame_ctl
)) {
2597 if (ieee
->state
>= RTLLIB_LINKED
)
2598 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
++;
2601 list_for_each_entry(target
, &ieee
->network_list
, list
) {
2602 if (is_same_network(target
, network
,
2603 (target
->ssid_len
? 1 : 0)))
2605 if ((oldest
== NULL
) ||
2606 (target
->last_scanned
< oldest
->last_scanned
))
2610 /* If we didn't find a match, then get a new network slot to initialize
2611 * with this beacon's information */
2612 if (&target
->list
== &ieee
->network_list
) {
2613 if (list_empty(&ieee
->network_free_list
)) {
2614 /* If there are no more slots, expire the oldest */
2615 list_del(&oldest
->list
);
2617 RTLLIB_DEBUG_SCAN("Expired '%s' ( %pM) from "
2619 escape_essid(target
->ssid
,
2623 /* Otherwise just pull from the free list */
2624 target
= list_entry(ieee
->network_free_list
.next
,
2625 struct rtllib_network
, list
);
2626 list_del(ieee
->network_free_list
.next
);
2630 RTLLIB_DEBUG_SCAN("Adding '%s' ( %pM) via %s.\n",
2631 escape_essid(network
->ssid
,
2632 network
->ssid_len
), network
->bssid
,
2634 le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2635 RTLLIB_STYPE_PROBE_RESP
?
2636 "PROBE RESPONSE" : "BEACON");
2637 memcpy(target
, network
, sizeof(*target
));
2638 list_add_tail(&target
->list
, &ieee
->network_list
);
2639 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
)
2640 rtllib_softmac_new_net(ieee
, network
);
2642 RTLLIB_DEBUG_SCAN("Updating '%s' ( %pM) via %s.\n",
2643 escape_essid(target
->ssid
,
2644 target
->ssid_len
), target
->bssid
,
2646 le16_to_cpu(beacon
->header
.frame_ctl
)) ==
2647 RTLLIB_STYPE_PROBE_RESP
?
2648 "PROBE RESPONSE" : "BEACON");
2650 /* we have an entry and we are going to update it. But this
2651 * entry may be already expired. In this case we do the same
2652 * as we found a new net and call the new_net handler
2654 renew
= !time_after(target
->last_scanned
+ ieee
->scan_age
,
2656 if ((!target
->ssid_len
) &&
2657 (((network
->ssid_len
> 0) && (target
->hidden_ssid_len
== 0))
2658 || ((ieee
->current_network
.ssid_len
== network
->ssid_len
) &&
2659 (strncmp(ieee
->current_network
.ssid
, network
->ssid
,
2660 network
->ssid_len
) == 0) &&
2661 (ieee
->state
== RTLLIB_NOLINK
))))
2663 update_network(target
, network
);
2664 if (renew
&& (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
))
2665 rtllib_softmac_new_net(ieee
, network
);
2668 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2669 if (is_beacon(beacon
->header
.frame_ctl
) &&
2670 is_same_network(&ieee
->current_network
, network
,
2671 (network
->ssid_len
? 1 : 0)) &&
2672 (ieee
->state
== RTLLIB_LINKED
)) {
2673 if (ieee
->handle_beacon
!= NULL
)
2674 ieee
->handle_beacon(ieee
->dev
, beacon
,
2675 &ieee
->current_network
);
2682 void rtllib_rx_mgt(struct rtllib_device
*ieee
,
2683 struct sk_buff
*skb
,
2684 struct rtllib_rx_stats
*stats
)
2686 struct rtllib_hdr_4addr
*header
= (struct rtllib_hdr_4addr
*)skb
->data
;
2688 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) !=
2689 RTLLIB_STYPE_PROBE_RESP
) &&
2690 (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) !=
2691 RTLLIB_STYPE_BEACON
))
2692 ieee
->last_rx_ps_time
= jiffies
;
2694 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
))) {
2696 case RTLLIB_STYPE_BEACON
:
2697 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
2698 WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)));
2699 RTLLIB_DEBUG_SCAN("Beacon\n");
2700 rtllib_process_probe_response(
2701 ieee
, (struct rtllib_probe_response
*)header
,
2704 if (ieee
->sta_sleep
|| (ieee
->ps
!= RTLLIB_PS_DISABLED
&&
2705 ieee
->iw_mode
== IW_MODE_INFRA
&&
2706 ieee
->state
== RTLLIB_LINKED
))
2707 tasklet_schedule(&ieee
->ps_task
);
2711 case RTLLIB_STYPE_PROBE_RESP
:
2712 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2713 WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)));
2714 RTLLIB_DEBUG_SCAN("Probe response\n");
2715 rtllib_process_probe_response(ieee
,
2716 (struct rtllib_probe_response
*)header
, stats
);
2718 case RTLLIB_STYPE_PROBE_REQ
:
2719 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
2721 le16_to_cpu(header
->frame_ctl
)));
2722 RTLLIB_DEBUG_SCAN("Probe request\n");
2723 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
2724 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
2725 ieee
->iw_mode
== IW_MODE_MASTER
) &&
2726 ieee
->state
== RTLLIB_LINKED
))
2727 rtllib_rx_probe_rq(ieee
, skb
);