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,
49 struct rtllib_rx_stats *rx_status,
53 skb_reset_mac_header(skb);
54 skb_pull(skb, hdr_length);
55 skb->pkt_type = PACKET_OTHERHOST;
56 skb->protocol = htons(ETH_P_80211_RAW);
57 memset(skb->cb, 0, sizeof(skb->cb));
61 /* Called only as a tasklet (software IRQ) */
62 static struct rtllib_frag_entry *
63 rtllib_frag_cache_find(struct rtllib_device *ieee, unsigned int seq,
64 unsigned int frag, u8 tid, u8 *src, u8 *dst)
66 struct rtllib_frag_entry *entry;
69 for (i = 0; i < RTLLIB_FRAG_CACHE_LEN; i++) {
70 entry = &ieee->frag_cache[tid][i];
71 if (entry->skb != NULL &&
72 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
74 "expiring fragment cache entry 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) &&
106 RTLLIB_QOS_HAS_SEQ(fc)) {
107 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
108 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
111 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
112 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)hdr;
113 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
121 /* Reserve enough space to fit maximum frame length */
122 skb = dev_alloc_skb(ieee->dev->mtu +
123 sizeof(struct rtllib_hdr_4addr) +
129 (RTLLIB_QOS_HAS_SEQ(fc) ? 2 : 0));
133 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
134 ieee->frag_next_idx[tid]++;
135 if (ieee->frag_next_idx[tid] >= RTLLIB_FRAG_CACHE_LEN)
136 ieee->frag_next_idx[tid] = 0;
138 if (entry->skb != NULL)
139 dev_kfree_skb_any(entry->skb);
141 entry->first_frag_time = jiffies;
143 entry->last_frag = frag;
145 ether_addr_copy(entry->src_addr, hdr->addr2);
146 ether_addr_copy(entry->dst_addr, hdr->addr1);
148 /* received a fragment of a frame for which the head fragment
149 * should have already been received
151 entry = rtllib_frag_cache_find(ieee, seq, frag, tid, hdr->addr2,
154 entry->last_frag = frag;
163 /* Called only as a tasklet (software IRQ) */
164 static int rtllib_frag_cache_invalidate(struct rtllib_device *ieee,
165 struct rtllib_hdr_4addr *hdr)
167 u16 fc = le16_to_cpu(hdr->frame_ctl);
168 u16 sc = le16_to_cpu(hdr->seq_ctl);
169 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
170 struct rtllib_frag_entry *entry;
171 struct rtllib_hdr_3addrqos *hdr_3addrqos;
172 struct rtllib_hdr_4addrqos *hdr_4addrqos;
175 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) &&
176 RTLLIB_QOS_HAS_SEQ(fc)) {
177 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
178 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
181 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
182 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)hdr;
183 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
190 entry = rtllib_frag_cache_find(ieee, seq, -1, tid, hdr->addr2,
194 netdev_dbg(ieee->dev,
195 "Couldn't invalidate fragment cache entry (seq=%u)\n",
204 /* rtllib_rx_frame_mgtmt
206 * Responsible for handling management control frames
208 * Called by rtllib_rx
211 rtllib_rx_frame_mgmt(struct rtllib_device *ieee, struct sk_buff *skb,
212 struct rtllib_rx_stats *rx_stats, u16 type,
215 /* On the struct stats definition there is written that
216 * this is not mandatory.... but seems that the probe
217 * response parser uses it
219 struct rtllib_hdr_3addr *hdr = (struct rtllib_hdr_3addr *)skb->data;
221 rx_stats->len = skb->len;
222 rtllib_rx_mgt(ieee, skb, rx_stats);
223 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN))) {
224 dev_kfree_skb_any(skb);
227 rtllib_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
229 dev_kfree_skb_any(skb);
234 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation
235 * Ethernet-II snap header (RFC1042 for most EtherTypes)
237 static unsigned char rfc1042_header[] = {
238 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
240 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
241 static unsigned char bridge_tunnel_header[] = {
242 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
244 /* No encapsulation header if EtherType < 0x600 (=length) */
246 /* Called by rtllib_rx_frame_decrypt */
247 static int rtllib_is_eapol_frame(struct rtllib_device *ieee,
248 struct sk_buff *skb, size_t hdrlen)
250 struct net_device *dev = ieee->dev;
252 struct rtllib_hdr_4addr *hdr;
258 hdr = (struct rtllib_hdr_4addr *) skb->data;
259 fc = le16_to_cpu(hdr->frame_ctl);
261 /* check that the frame is unicast frame to us */
262 if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
264 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
265 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
266 /* ToDS frame with own addr BSSID and DA */
267 } else if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
268 RTLLIB_FCTL_FROMDS &&
269 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
270 /* FromDS frame with own addr as DA */
274 if (skb->len < 24 + 8)
277 /* check for port access entity Ethernet type */
278 pos = skb->data + hdrlen;
279 ethertype = (pos[6] << 8) | pos[7];
280 if (ethertype == ETH_P_PAE)
286 /* Called only as a tasklet (software IRQ), by rtllib_rx */
288 rtllib_rx_frame_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
289 struct lib80211_crypt_data *crypt)
291 struct rtllib_hdr_4addr *hdr;
294 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
297 if (ieee->hwsec_active) {
298 struct cb_desc *tcb_desc = (struct cb_desc *)
299 (skb->cb + MAX_DEV_ADDR_SIZE);
301 tcb_desc->bHwSec = 1;
303 if (ieee->need_sw_enc)
304 tcb_desc->bHwSec = 0;
307 hdr = (struct rtllib_hdr_4addr *) skb->data;
308 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
310 atomic_inc(&crypt->refcnt);
311 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
312 atomic_dec(&crypt->refcnt);
314 netdev_dbg(ieee->dev, "decryption failed (SA= %pM) res=%d\n",
317 netdev_dbg(ieee->dev,
318 "Decryption failed ICV mismatch (key %d)\n",
319 skb->data[hdrlen + 3] >> 6);
320 ieee->ieee_stats.rx_discards_undecryptable++;
328 /* Called only as a tasklet (software IRQ), by rtllib_rx */
330 rtllib_rx_frame_decrypt_msdu(struct rtllib_device *ieee, struct sk_buff *skb,
331 int keyidx, struct lib80211_crypt_data *crypt)
333 struct rtllib_hdr_4addr *hdr;
336 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
338 if (ieee->hwsec_active) {
339 struct cb_desc *tcb_desc = (struct cb_desc *)
340 (skb->cb + MAX_DEV_ADDR_SIZE);
342 tcb_desc->bHwSec = 1;
344 if (ieee->need_sw_enc)
345 tcb_desc->bHwSec = 0;
348 hdr = (struct rtllib_hdr_4addr *) skb->data;
349 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
351 atomic_inc(&crypt->refcnt);
352 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
353 atomic_dec(&crypt->refcnt);
355 netdev_dbg(ieee->dev,
356 "MSDU decryption/MIC verification failed (SA= %pM keyidx=%d)\n",
365 /* this function is stolen from ipw2200 driver*/
366 #define IEEE_PACKET_RETRY_TIME (5*HZ)
367 static int is_duplicate_packet(struct rtllib_device *ieee,
368 struct rtllib_hdr_4addr *header)
370 u16 fc = le16_to_cpu(header->frame_ctl);
371 u16 sc = le16_to_cpu(header->seq_ctl);
372 u16 seq = WLAN_GET_SEQ_SEQ(sc);
373 u16 frag = WLAN_GET_SEQ_FRAG(sc);
374 u16 *last_seq, *last_frag;
375 unsigned long *last_time;
376 struct rtllib_hdr_3addrqos *hdr_3addrqos;
377 struct rtllib_hdr_4addrqos *hdr_4addrqos;
380 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) &&
381 RTLLIB_QOS_HAS_SEQ(fc)) {
382 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)header;
383 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
386 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
387 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)header;
388 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
395 switch (ieee->iw_mode) {
399 struct ieee_ibss_seq *entry = NULL;
400 u8 *mac = header->addr2;
401 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
403 list_for_each(p, &ieee->ibss_mac_hash[index]) {
404 entry = list_entry(p, struct ieee_ibss_seq, list);
405 if (!memcmp(entry->mac, mac, ETH_ALEN))
408 if (p == &ieee->ibss_mac_hash[index]) {
409 entry = kmalloc(sizeof(struct ieee_ibss_seq),
414 ether_addr_copy(entry->mac, mac);
415 entry->seq_num[tid] = seq;
416 entry->frag_num[tid] = frag;
417 entry->packet_time[tid] = jiffies;
418 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
421 last_seq = &entry->seq_num[tid];
422 last_frag = &entry->frag_num[tid];
423 last_time = &entry->packet_time[tid];
428 last_seq = &ieee->last_rxseq_num[tid];
429 last_frag = &ieee->last_rxfrag_num[tid];
430 last_time = &ieee->last_packet_time[tid];
436 if ((*last_seq == seq) &&
437 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
438 if (*last_frag == frag)
440 if (*last_frag + 1 != frag)
441 /* out-of-order fragment */
447 *last_time = jiffies;
455 static bool AddReorderEntry(struct rx_ts_record *pTS,
456 struct rx_reorder_entry *pReorderEntry)
458 struct list_head *pList = &pTS->RxPendingPktList;
460 while (pList->next != &pTS->RxPendingPktList) {
461 if (SN_LESS(pReorderEntry->SeqNum, ((struct rx_reorder_entry *)
462 list_entry(pList->next, struct rx_reorder_entry,
465 else if (SN_EQUAL(pReorderEntry->SeqNum,
466 ((struct rx_reorder_entry *)list_entry(pList->next,
467 struct rx_reorder_entry, List))->SeqNum))
472 pReorderEntry->List.next = pList->next;
473 pReorderEntry->List.next->prev = &pReorderEntry->List;
474 pReorderEntry->List.prev = pList;
475 pList->next = &pReorderEntry->List;
480 void rtllib_indicate_packets(struct rtllib_device *ieee,
481 struct rtllib_rxb **prxbIndicateArray, u8 index)
483 struct net_device_stats *stats = &ieee->stats;
487 for (j = 0; j < index; j++) {
488 struct rtllib_rxb *prxb = prxbIndicateArray[j];
490 for (i = 0; i < prxb->nr_subframes; i++) {
491 struct sk_buff *sub_skb = prxb->subframes[i];
493 /* convert hdr + possible LLC headers into Ethernet header */
494 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
495 if (sub_skb->len >= 8 &&
496 ((memcmp(sub_skb->data, rfc1042_header,
498 ethertype != ETH_P_AARP &&
499 ethertype != ETH_P_IPX) ||
500 memcmp(sub_skb->data, bridge_tunnel_header,
502 /* remove RFC1042 or Bridge-Tunnel encapsulation
503 * and replace EtherType
505 skb_pull(sub_skb, SNAP_SIZE);
506 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
507 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
510 /* Leave Ethernet header part of hdr and full payload */
512 memcpy(skb_push(sub_skb, 2), &len, 2);
513 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
514 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
517 /* Indicate the packets to upper layer */
520 stats->rx_bytes += sub_skb->len;
522 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
523 sub_skb->protocol = eth_type_trans(sub_skb,
525 sub_skb->dev = ieee->dev;
526 sub_skb->dev->stats.rx_packets++;
527 sub_skb->dev->stats.rx_bytes += sub_skb->len;
528 /* 802.11 crc not sufficient */
529 sub_skb->ip_summed = CHECKSUM_NONE;
530 ieee->last_rx_ps_time = jiffies;
539 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
540 struct rx_ts_record *pTS)
542 struct rx_reorder_entry *pRxReorderEntry;
545 del_timer_sync(&pTS->RxPktPendingTimer);
546 while (!list_empty(&pTS->RxPendingPktList)) {
547 if (RfdCnt >= REORDER_WIN_SIZE) {
548 netdev_info(ieee->dev,
549 "-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n",
554 pRxReorderEntry = (struct rx_reorder_entry *)
555 list_entry(pTS->RxPendingPktList.prev,
556 struct rx_reorder_entry, List);
557 netdev_dbg(ieee->dev, "%s(): Indicate SeqNum %d!\n", __func__,
558 pRxReorderEntry->SeqNum);
559 list_del_init(&pRxReorderEntry->List);
561 ieee->RfdArray[RfdCnt] = pRxReorderEntry->prxb;
564 list_add_tail(&pRxReorderEntry->List,
565 &ieee->RxReorder_Unused_List);
567 rtllib_indicate_packets(ieee, ieee->RfdArray, RfdCnt);
569 pTS->RxIndicateSeq = 0xffff;
572 static void RxReorderIndicatePacket(struct rtllib_device *ieee,
573 struct rtllib_rxb *prxb,
574 struct rx_ts_record *pTS, u16 SeqNum)
576 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
577 struct rx_reorder_entry *pReorderEntry = NULL;
578 u8 WinSize = pHTInfo->RxReorderWinSize;
581 bool bMatchWinStart = false, bPktInBuf = false;
584 netdev_dbg(ieee->dev,
585 "%s(): Seq is %d, pTS->RxIndicateSeq is %d, WinSize is %d\n",
586 __func__, SeqNum, pTS->RxIndicateSeq, WinSize);
588 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
590 WinEnd = (pTS->RxIndicateSeq + WinSize - 1) % 4096;
591 /* Rx Reorder initialize condition.*/
592 if (pTS->RxIndicateSeq == 0xffff)
593 pTS->RxIndicateSeq = SeqNum;
595 /* Drop out the packet which SeqNum is smaller than WinStart */
596 if (SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
597 netdev_dbg(ieee->dev,
598 "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
599 pTS->RxIndicateSeq, SeqNum);
600 pHTInfo->RxReorderDropCounter++;
604 for (i = 0; i < prxb->nr_subframes; i++)
605 dev_kfree_skb(prxb->subframes[i]);
609 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
613 /* Sliding window manipulation. Conditions includes:
614 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
615 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
617 if (SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
618 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
619 bMatchWinStart = true;
620 } else if (SN_LESS(WinEnd, SeqNum)) {
621 if (SeqNum >= (WinSize - 1))
622 pTS->RxIndicateSeq = SeqNum + 1 - WinSize;
624 pTS->RxIndicateSeq = 4095 -
625 (WinSize - (SeqNum + 1)) + 1;
626 netdev_dbg(ieee->dev,
627 "Window Shift! IndicateSeq: %d, NewSeq: %d\n",
628 pTS->RxIndicateSeq, SeqNum);
631 /* Indication process.
632 * After Packet dropping and Sliding Window shifting as above, we can
633 * now just indicate the packets with the SeqNum smaller than latest
634 * WinStart and struct buffer other packets.
636 * For Rx Reorder condition:
637 * 1. All packets with SeqNum smaller than WinStart => Indicate
638 * 2. All packets with SeqNum larger than or equal to
639 * WinStart => Buffer it.
641 if (bMatchWinStart) {
642 /* Current packet is going to be indicated.*/
643 netdev_dbg(ieee->dev,
644 "Packets indication! IndicateSeq: %d, NewSeq: %d\n",
645 pTS->RxIndicateSeq, SeqNum);
646 ieee->prxbIndicateArray[0] = prxb;
649 /* Current packet is going to be inserted into pending list.*/
650 if (!list_empty(&ieee->RxReorder_Unused_List)) {
651 pReorderEntry = (struct rx_reorder_entry *)
652 list_entry(ieee->RxReorder_Unused_List.next,
653 struct rx_reorder_entry, List);
654 list_del_init(&pReorderEntry->List);
656 /* Make a reorder entry and insert
657 * into a the packet list.
659 pReorderEntry->SeqNum = SeqNum;
660 pReorderEntry->prxb = prxb;
662 if (!AddReorderEntry(pTS, pReorderEntry)) {
665 netdev_dbg(ieee->dev,
666 "%s(): Duplicate packet is dropped. IndicateSeq: %d, NewSeq: %d\n",
667 __func__, pTS->RxIndicateSeq,
669 list_add_tail(&pReorderEntry->List,
670 &ieee->RxReorder_Unused_List);
672 for (i = 0; i < prxb->nr_subframes; i++)
673 dev_kfree_skb(prxb->subframes[i]);
677 netdev_dbg(ieee->dev,
678 "Pkt insert into struct buffer. IndicateSeq: %d, NewSeq: %d\n",
679 pTS->RxIndicateSeq, SeqNum);
682 /* Packets are dropped if there are not enough reorder
683 * entries. This part should be modified!! We can just
684 * indicate all the packets in struct buffer and get
687 netdev_err(ieee->dev,
688 "%s(): There is no reorder entry! Packet is dropped!\n",
693 for (i = 0; i < prxb->nr_subframes; i++)
694 dev_kfree_skb(prxb->subframes[i]);
701 /* Check if there is any packet need indicate.*/
702 while (!list_empty(&pTS->RxPendingPktList)) {
703 netdev_dbg(ieee->dev, "%s(): start RREORDER indicate\n",
706 pReorderEntry = (struct rx_reorder_entry *)
707 list_entry(pTS->RxPendingPktList.prev,
708 struct rx_reorder_entry,
710 if (SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
711 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) {
712 /* This protect struct buffer from overflow. */
713 if (index >= REORDER_WIN_SIZE) {
714 netdev_err(ieee->dev,
715 "%s(): Buffer overflow!\n",
721 list_del_init(&pReorderEntry->List);
723 if (SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
724 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) %
727 ieee->prxbIndicateArray[index] = pReorderEntry->prxb;
728 netdev_dbg(ieee->dev, "%s(): Indicate SeqNum %d!\n",
729 __func__, pReorderEntry->SeqNum);
732 list_add_tail(&pReorderEntry->List,
733 &ieee->RxReorder_Unused_List);
740 /* Handling pending timer. Set this timer to prevent from long time
744 if (timer_pending(&pTS->RxPktPendingTimer))
745 del_timer_sync(&pTS->RxPktPendingTimer);
746 pTS->RxTimeoutIndicateSeq = 0xffff;
748 if (index > REORDER_WIN_SIZE) {
749 netdev_err(ieee->dev,
750 "%s(): Rx Reorder struct buffer full!\n",
752 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
756 rtllib_indicate_packets(ieee, ieee->prxbIndicateArray, index);
760 if (bPktInBuf && pTS->RxTimeoutIndicateSeq == 0xffff) {
761 netdev_dbg(ieee->dev, "%s(): SET rx timeout timer\n", __func__);
762 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
763 mod_timer(&pTS->RxPktPendingTimer, jiffies +
764 msecs_to_jiffies(pHTInfo->RxReorderPendingTime));
766 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
769 static u8 parse_subframe(struct rtllib_device *ieee, struct sk_buff *skb,
770 struct rtllib_rx_stats *rx_stats,
771 struct rtllib_rxb *rxb, u8 *src, u8 *dst)
773 struct rtllib_hdr_3addr *hdr = (struct rtllib_hdr_3addr *)skb->data;
774 u16 fc = le16_to_cpu(hdr->frame_ctl);
776 u16 LLCOffset = sizeof(struct rtllib_hdr_3addr);
778 bool bIsAggregateFrame = false;
779 u16 nSubframe_Length;
780 u8 nPadding_Length = 0;
782 struct sk_buff *sub_skb;
784 /* just for debug purpose */
785 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
786 if ((RTLLIB_QOS_HAS_SEQ(fc)) &&
787 (((union frameqos *)(skb->data + RTLLIB_3ADDR_LEN))->field.reserved))
788 bIsAggregateFrame = true;
790 if (RTLLIB_QOS_HAS_SEQ(fc))
792 if (rx_stats->bContainHTC)
793 LLCOffset += sHTCLng;
795 ChkLength = LLCOffset;
797 if (skb->len <= ChkLength)
800 skb_pull(skb, LLCOffset);
801 ieee->bIsAggregateFrame = bIsAggregateFrame;
802 if (!bIsAggregateFrame) {
803 rxb->nr_subframes = 1;
805 /* altered by clark 3/30/2010
806 * The struct buffer size of the skb indicated to upper layer
807 * must be less than 5000, or the defraged IP datagram
808 * in the IP layer will exceed "ipfrag_high_tresh" and be
809 * discarded. so there must not use the function
810 * "skb_copy" and "skb_clone" for "skb".
813 /* Allocate new skb for releasing to upper layer */
814 sub_skb = dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE);
817 skb_reserve(sub_skb, 12);
818 data_ptr = (u8 *)skb_put(sub_skb, skb->len);
819 memcpy(data_ptr, skb->data, skb->len);
820 sub_skb->dev = ieee->dev;
822 rxb->subframes[0] = sub_skb;
824 memcpy(rxb->src, src, ETH_ALEN);
825 memcpy(rxb->dst, dst, ETH_ALEN);
826 rxb->subframes[0]->dev = ieee->dev;
830 rxb->nr_subframes = 0;
831 memcpy(rxb->src, src, ETH_ALEN);
832 memcpy(rxb->dst, dst, ETH_ALEN);
833 while (skb->len > ETHERNET_HEADER_SIZE) {
834 /* Offset 12 denote 2 mac address */
835 nSubframe_Length = *((u16 *)(skb->data + 12));
836 nSubframe_Length = (nSubframe_Length >> 8) +
837 (nSubframe_Length << 8);
839 if (skb->len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
840 netdev_info(ieee->dev,
841 "%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",
842 __func__, rxb->nr_subframes);
843 netdev_info(ieee->dev,
844 "%s: A-MSDU parse error!! Subframe Length: %d\n",
845 __func__, nSubframe_Length);
846 netdev_info(ieee->dev,
847 "nRemain_Length is %d and nSubframe_Length is : %d\n",
848 skb->len, nSubframe_Length);
849 netdev_info(ieee->dev,
850 "The Packet SeqNum is %d\n",
855 /* move the data point to data content */
856 skb_pull(skb, ETHERNET_HEADER_SIZE);
858 /* altered by clark 3/30/2010
859 * The struct buffer size of the skb indicated to upper layer
860 * must be less than 5000, or the defraged IP datagram
861 * in the IP layer will exceed "ipfrag_high_tresh" and be
862 * discarded. so there must not use the function
863 * "skb_copy" and "skb_clone" for "skb".
866 /* Allocate new skb for releasing to upper layer */
867 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
870 skb_reserve(sub_skb, 12);
871 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
872 memcpy(data_ptr, skb->data, nSubframe_Length);
874 sub_skb->dev = ieee->dev;
875 rxb->subframes[rxb->nr_subframes++] = sub_skb;
876 if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
877 netdev_dbg(ieee->dev,
878 "ParseSubframe(): Too many Subframes! Packets dropped!\n");
881 skb_pull(skb, nSubframe_Length);
884 nPadding_Length = 4 - ((nSubframe_Length +
885 ETHERNET_HEADER_SIZE) % 4);
886 if (nPadding_Length == 4)
889 if (skb->len < nPadding_Length)
892 skb_pull(skb, nPadding_Length);
896 return rxb->nr_subframes;
900 static size_t rtllib_rx_get_hdrlen(struct rtllib_device *ieee,
902 struct rtllib_rx_stats *rx_stats)
904 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
905 u16 fc = le16_to_cpu(hdr->frame_ctl);
908 hdrlen = rtllib_get_hdrlen(fc);
909 if (HTCCheck(ieee, skb->data)) {
911 netdev_info(ieee->dev, "%s: find HTCControl!\n",
914 rx_stats->bContainHTC = true;
917 if (RTLLIB_QOS_HAS_SEQ(fc))
918 rx_stats->bIsQosData = true;
923 static int rtllib_rx_check_duplicate(struct rtllib_device *ieee,
924 struct sk_buff *skb, u8 multicast)
926 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
928 u8 frag, type, stype;
930 fc = le16_to_cpu(hdr->frame_ctl);
931 type = WLAN_FC_GET_TYPE(fc);
932 stype = WLAN_FC_GET_STYPE(fc);
933 sc = le16_to_cpu(hdr->seq_ctl);
934 frag = WLAN_GET_SEQ_FRAG(sc);
936 if ((ieee->pHTInfo->bCurRxReorderEnable == false) ||
937 !ieee->current_network.qos_data.active ||
938 !IsDataFrame(skb->data) ||
939 IsLegacyDataFrame(skb->data)) {
940 if (!((type == RTLLIB_FTYPE_MGMT) &&
941 (stype == RTLLIB_STYPE_BEACON))) {
942 if (is_duplicate_packet(ieee, hdr))
946 struct rx_ts_record *pRxTS = NULL;
948 if (GetTs(ieee, (struct ts_common_info **) &pRxTS, hdr->addr2,
949 (u8)Frame_QoSTID((u8 *)(skb->data)), RX_DIR, true)) {
950 if ((fc & (1<<11)) && (frag == pRxTS->RxLastFragNum) &&
951 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum))
953 pRxTS->RxLastFragNum = frag;
954 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
956 netdev_warn(ieee->dev, "%s(): No TS! Skip the check!\n",
965 static void rtllib_rx_extract_addr(struct rtllib_device *ieee,
966 struct rtllib_hdr_4addr *hdr, u8 *dst,
969 u16 fc = le16_to_cpu(hdr->frame_ctl);
971 switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
972 case RTLLIB_FCTL_FROMDS:
973 ether_addr_copy(dst, hdr->addr1);
974 ether_addr_copy(src, hdr->addr3);
975 ether_addr_copy(bssid, hdr->addr2);
977 case RTLLIB_FCTL_TODS:
978 ether_addr_copy(dst, hdr->addr3);
979 ether_addr_copy(src, hdr->addr2);
980 ether_addr_copy(bssid, hdr->addr1);
982 case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
983 ether_addr_copy(dst, hdr->addr3);
984 ether_addr_copy(src, hdr->addr4);
985 ether_addr_copy(bssid, ieee->current_network.bssid);
988 ether_addr_copy(dst, hdr->addr1);
989 ether_addr_copy(src, hdr->addr2);
990 ether_addr_copy(bssid, hdr->addr3);
995 static int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc,
996 u8 *dst, u8 *src, u8 *bssid, u8 *addr2)
1000 type = WLAN_FC_GET_TYPE(fc);
1001 stype = WLAN_FC_GET_STYPE(fc);
1003 /* Filter frames from different BSS */
1004 if (((fc & RTLLIB_FCTL_DSTODS) != RTLLIB_FCTL_DSTODS) &&
1005 !ether_addr_equal(ieee->current_network.bssid, bssid) &&
1006 !is_zero_ether_addr(ieee->current_network.bssid)) {
1010 /* Filter packets sent by an STA that will be forwarded by AP */
1011 if (ieee->IntelPromiscuousModeInfo.bPromiscuousOn &&
1012 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame) {
1013 if ((fc & RTLLIB_FCTL_TODS) && !(fc & RTLLIB_FCTL_FROMDS) &&
1014 !ether_addr_equal(dst, ieee->current_network.bssid) &&
1015 ether_addr_equal(bssid, ieee->current_network.bssid)) {
1020 /* Nullfunc frames may have PS-bit set, so they must be passed to
1021 * hostap_handle_sta_rx() before being dropped here.
1023 if (!ieee->IntelPromiscuousModeInfo.bPromiscuousOn) {
1024 if (stype != RTLLIB_STYPE_DATA &&
1025 stype != RTLLIB_STYPE_DATA_CFACK &&
1026 stype != RTLLIB_STYPE_DATA_CFPOLL &&
1027 stype != RTLLIB_STYPE_DATA_CFACKPOLL &&
1028 stype != RTLLIB_STYPE_QOS_DATA) {
1029 if (stype != RTLLIB_STYPE_NULLFUNC)
1030 netdev_dbg(ieee->dev,
1031 "RX: dropped data frame with no data (type=0x%02x, subtype=0x%02x)\n",
1037 if (ieee->iw_mode != IW_MODE_MESH) {
1038 /* packets from our adapter are dropped (echo) */
1039 if (!memcmp(src, ieee->dev->dev_addr, ETH_ALEN))
1042 /* {broad,multi}cast packets to our BSS go through */
1043 if (is_multicast_ether_addr(dst)) {
1044 if (memcmp(bssid, ieee->current_network.bssid,
1052 static int rtllib_rx_get_crypt(struct rtllib_device *ieee, struct sk_buff *skb,
1053 struct lib80211_crypt_data **crypt, size_t hdrlen)
1055 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1056 u16 fc = le16_to_cpu(hdr->frame_ctl);
1059 if (ieee->host_decrypt) {
1060 if (skb->len >= hdrlen + 3)
1061 idx = skb->data[hdrlen + 3] >> 6;
1063 *crypt = ieee->crypt_info.crypt[idx];
1064 /* allow NULL decrypt to indicate an station specific override
1065 * for default encryption
1067 if (*crypt && ((*crypt)->ops == NULL ||
1068 (*crypt)->ops->decrypt_mpdu == NULL))
1071 if (!*crypt && (fc & RTLLIB_FCTL_WEP)) {
1072 /* This seems to be triggered by some (multicast?)
1073 * frames from other than current BSS, so just drop the
1074 * frames silently instead of filling system log with
1077 netdev_dbg(ieee->dev,
1078 "Decryption failed (not set) (SA= %pM)\n",
1080 ieee->ieee_stats.rx_discards_undecryptable++;
1088 static int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
1089 struct rtllib_rx_stats *rx_stats,
1090 struct lib80211_crypt_data *crypt, size_t hdrlen)
1092 struct rtllib_hdr_4addr *hdr;
1097 hdr = (struct rtllib_hdr_4addr *)skb->data;
1098 fc = le16_to_cpu(hdr->frame_ctl);
1099 sc = le16_to_cpu(hdr->seq_ctl);
1100 frag = WLAN_GET_SEQ_FRAG(sc);
1102 if ((!rx_stats->Decrypted))
1103 ieee->need_sw_enc = 1;
1105 ieee->need_sw_enc = 0;
1107 keyidx = rtllib_rx_frame_decrypt(ieee, skb, crypt);
1108 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) && (keyidx < 0)) {
1109 netdev_info(ieee->dev, "%s: decrypt frame error\n", __func__);
1113 hdr = (struct rtllib_hdr_4addr *) skb->data;
1114 if ((frag != 0 || (fc & RTLLIB_FCTL_MOREFRAGS))) {
1116 struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
1118 netdev_dbg(ieee->dev, "Rx Fragment received (%u)\n", frag);
1121 netdev_dbg(ieee->dev,
1122 "Rx cannot get skb from fragment cache (morefrag=%d seq=%u frag=%u)\n",
1123 (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
1124 WLAN_GET_SEQ_SEQ(sc), frag);
1131 if (frag_skb->tail + flen > frag_skb->end) {
1132 netdev_warn(ieee->dev,
1133 "%s: host decrypted and reassembled frame did not fit skb\n",
1135 rtllib_frag_cache_invalidate(ieee, hdr);
1140 /* copy first fragment (including full headers) into
1141 * beginning of the fragment cache skb
1143 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1145 /* append frame payload to the end of the fragment
1148 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1151 dev_kfree_skb_any(skb);
1154 if (fc & RTLLIB_FCTL_MOREFRAGS) {
1155 /* more fragments expected - leave the skb in fragment
1156 * cache for now; it will be delivered to upper layers
1157 * after all fragments have been received
1162 /* this was the last fragment and the frame will be
1163 * delivered, so remove skb from fragment cache
1166 hdr = (struct rtllib_hdr_4addr *) skb->data;
1167 rtllib_frag_cache_invalidate(ieee, hdr);
1170 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1171 * encrypted/authenticated
1173 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
1174 rtllib_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
1175 netdev_info(ieee->dev, "%s: ==>decrypt msdu error\n", __func__);
1179 hdr = (struct rtllib_hdr_4addr *) skb->data;
1180 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep) {
1181 if (/*ieee->ieee802_1x &&*/
1182 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1184 /* pass unencrypted EAPOL frames even if encryption is
1187 struct eapol *eap = (struct eapol *)(skb->data +
1189 netdev_dbg(ieee->dev,
1190 "RX: IEEE 802.1X EAPOL frame: %s\n",
1191 eap_get_type(eap->type));
1193 netdev_dbg(ieee->dev,
1194 "encryption configured, but RX frame not encrypted (SA= %pM)\n",
1200 if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
1201 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1202 struct eapol *eap = (struct eapol *)(skb->data +
1204 netdev_dbg(ieee->dev,
1205 "RX: IEEE 802.1X EAPOL frame: %s\n",
1206 eap_get_type(eap->type));
1209 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
1210 !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1211 netdev_dbg(ieee->dev,
1212 "dropped unencrypted RX data frame from %pM (drop_unencrypted=1)\n",
1217 if (rtllib_is_eapol_frame(ieee, skb, hdrlen))
1218 netdev_warn(ieee->dev, "RX: IEEE802.1X EAPOL frame!\n");
1223 static void rtllib_rx_check_leave_lps(struct rtllib_device *ieee, u8 unicast,
1228 if (ieee->state == RTLLIB_LINKED) {
1229 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +
1230 ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1231 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) {
1232 if (ieee->LeisurePSLeave)
1233 ieee->LeisurePSLeave(ieee->dev);
1237 ieee->last_rx_ps_time = jiffies;
1240 static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
1241 struct rtllib_rx_stats *rx_stats,
1242 struct rtllib_rxb *rxb,
1246 struct net_device *dev = ieee->dev;
1251 netdev_info(dev, "%s: rxb is NULL!!\n", __func__);
1255 for (i = 0; i < rxb->nr_subframes; i++) {
1256 struct sk_buff *sub_skb = rxb->subframes[i];
1259 /* convert hdr + possible LLC headers
1260 * into Ethernet header
1262 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1263 if (sub_skb->len >= 8 &&
1264 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1265 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1266 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1267 /* remove RFC1042 or Bridge-Tunnel encapsulation
1268 * and replace EtherType
1270 skb_pull(sub_skb, SNAP_SIZE);
1271 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1273 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1277 /* Leave Ethernet header part of hdr
1281 memcpy(skb_push(sub_skb, 2), &len, 2);
1282 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1284 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1288 ieee->stats.rx_packets++;
1289 ieee->stats.rx_bytes += sub_skb->len;
1291 if (is_multicast_ether_addr(dst))
1292 ieee->stats.multicast++;
1294 /* Indicate the packets to upper layer */
1295 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1296 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1298 sub_skb->dev->stats.rx_packets++;
1299 sub_skb->dev->stats.rx_bytes += sub_skb->len;
1300 /* 802.11 crc not sufficient */
1301 sub_skb->ip_summed = CHECKSUM_NONE;
1308 static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1309 struct rtllib_rx_stats *rx_stats)
1311 struct net_device *dev = ieee->dev;
1312 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1313 struct lib80211_crypt_data *crypt = NULL;
1314 struct rtllib_rxb *rxb = NULL;
1315 struct rx_ts_record *pTS = NULL;
1316 u16 fc, sc, SeqNum = 0;
1317 u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0;
1321 u8 bssid[ETH_ALEN] = {0};
1324 bool bToOtherSTA = false;
1327 hdr = (struct rtllib_hdr_4addr *)skb->data;
1328 fc = le16_to_cpu(hdr->frame_ctl);
1329 type = WLAN_FC_GET_TYPE(fc);
1330 stype = WLAN_FC_GET_STYPE(fc);
1331 sc = le16_to_cpu(hdr->seq_ctl);
1333 /*Filter pkt not to me*/
1334 multicast = is_multicast_ether_addr(hdr->addr1);
1335 unicast = !multicast;
1336 if (unicast && !ether_addr_equal(dev->dev_addr, hdr->addr1)) {
1337 if (ieee->bNetPromiscuousMode)
1343 /*Filter pkt has too small length */
1344 hdrlen = rtllib_rx_get_hdrlen(ieee, skb, rx_stats);
1345 if (skb->len < hdrlen) {
1347 "%s():ERR!!! skb->len is smaller than hdrlen\n",
1352 /* Filter Duplicate pkt */
1353 ret = rtllib_rx_check_duplicate(ieee, skb, multicast);
1357 /* Filter CTRL Frame */
1358 if (type == RTLLIB_FTYPE_CTL)
1361 /* Filter MGNT Frame */
1362 if (type == RTLLIB_FTYPE_MGMT) {
1365 if (rtllib_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1371 /* Filter WAPI DATA Frame */
1373 /* Update statstics for AP roaming */
1375 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1376 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1378 dev->last_rx = jiffies;
1380 /* Data frame - extract src/dst addresses */
1381 rtllib_rx_extract_addr(ieee, hdr, dst, src, bssid);
1383 /* Filter Data frames */
1384 ret = rtllib_rx_data_filter(ieee, fc, dst, src, bssid, hdr->addr2);
1388 if (skb->len == hdrlen)
1391 /* Send pspoll based on moredata */
1392 if ((ieee->iw_mode == IW_MODE_INFRA) &&
1393 (ieee->sta_sleep == LPS_IS_SLEEP) &&
1394 (ieee->polling) && (!bToOtherSTA)) {
1395 if (WLAN_FC_MORE_DATA(fc)) {
1396 /* more data bit is set, let's request a new frame
1399 rtllib_sta_ps_send_pspoll_frame(ieee);
1401 ieee->polling = false;
1405 /* Get crypt if encrypted */
1406 ret = rtllib_rx_get_crypt(ieee, skb, &crypt, hdrlen);
1410 /* Decrypt data frame (including reassemble) */
1411 ret = rtllib_rx_decrypt(ieee, skb, rx_stats, crypt, hdrlen);
1417 /* Get TS for Rx Reorder */
1418 hdr = (struct rtllib_hdr_4addr *) skb->data;
1419 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1420 && !is_multicast_ether_addr(hdr->addr1)
1421 && (!bToOtherSTA)) {
1422 TID = Frame_QoSTID(skb->data);
1423 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1424 GetTs(ieee, (struct ts_common_info **) &pTS, hdr->addr2, TID,
1426 if (TID != 0 && TID != 3)
1427 ieee->bis_any_nonbepkts = true;
1430 /* Parse rx data frame (For AMSDU) */
1431 /* skb: hdr + (possible reassembled) full plaintext payload */
1432 payload = skb->data + hdrlen;
1433 rxb = kmalloc(sizeof(struct rtllib_rxb), GFP_ATOMIC);
1437 /* to parse amsdu packets */
1438 /* qos data packets & reserved bit is 1 */
1439 if (parse_subframe(ieee, skb, rx_stats, rxb, src, dst) == 0) {
1440 /* only to free rxb, and not submit the packets
1443 for (i = 0; i < rxb->nr_subframes; i++)
1444 dev_kfree_skb(rxb->subframes[i]);
1450 /* Update WAPI PN */
1452 /* Check if leave LPS */
1454 if (ieee->bIsAggregateFrame)
1455 nr_subframes = rxb->nr_subframes;
1459 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod += nr_subframes;
1460 rtllib_rx_check_leave_lps(ieee, unicast, nr_subframes);
1463 /* Indicate packets to upper layer or Rx Reorder */
1464 if (ieee->pHTInfo->bCurRxReorderEnable == false || pTS == NULL ||
1466 rtllib_rx_indicate_pkt_legacy(ieee, rx_stats, rxb, dst, src);
1468 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1476 ieee->stats.rx_dropped++;
1478 /* Returning 0 indicates to caller that we have not handled the SKB--
1479 * so it is still allocated and can be used again by underlying
1480 * hardware as a DMA target
1485 static int rtllib_rx_Master(struct rtllib_device *ieee, struct sk_buff *skb,
1486 struct rtllib_rx_stats *rx_stats)
1491 static int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb,
1492 struct rtllib_rx_stats *rx_stats)
1494 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1495 u16 fc = le16_to_cpu(hdr->frame_ctl);
1496 size_t hdrlen = rtllib_get_hdrlen(fc);
1498 if (skb->len < hdrlen) {
1499 netdev_info(ieee->dev,
1500 "%s():ERR!!! skb->len is smaller than hdrlen\n",
1505 if (HTCCheck(ieee, skb->data)) {
1506 if (net_ratelimit())
1507 netdev_info(ieee->dev, "%s: Find HTCControl!\n",
1512 rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
1513 ieee->stats.rx_packets++;
1514 ieee->stats.rx_bytes += skb->len;
1519 static int rtllib_rx_Mesh(struct rtllib_device *ieee, struct sk_buff *skb,
1520 struct rtllib_rx_stats *rx_stats)
1525 /* All received frames are sent to this function. @skb contains the frame in
1526 * IEEE 802.11 format, i.e., in the format it was sent over air.
1527 * This function is called only as a tasklet (software IRQ).
1529 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1530 struct rtllib_rx_stats *rx_stats)
1534 if ((NULL == ieee) || (NULL == skb) || (NULL == rx_stats)) {
1535 pr_info("%s: Input parameters NULL!\n", __func__);
1538 if (skb->len < 10) {
1539 netdev_info(ieee->dev, "%s: SKB length < 10\n", __func__);
1543 switch (ieee->iw_mode) {
1546 ret = rtllib_rx_InfraAdhoc(ieee, skb, rx_stats);
1548 case IW_MODE_MASTER:
1549 case IW_MODE_REPEAT:
1550 ret = rtllib_rx_Master(ieee, skb, rx_stats);
1552 case IW_MODE_MONITOR:
1553 ret = rtllib_rx_Monitor(ieee, skb, rx_stats);
1556 ret = rtllib_rx_Mesh(ieee, skb, rx_stats);
1559 netdev_info(ieee->dev, "%s: ERR iw mode!!!\n", __func__);
1567 ieee->stats.rx_dropped++;
1570 EXPORT_SYMBOL(rtllib_rx);
1572 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1574 /* Make ther structure we read from the beacon packet has the right values */
1575 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1576 *info_element, int sub_type)
1579 if (info_element->qui_subtype != sub_type)
1581 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1583 if (info_element->qui_type != QOS_OUI_TYPE)
1585 if (info_element->version != QOS_VERSION_1)
1592 /* Parse a QoS parameter element */
1593 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
1595 struct rtllib_info_element
1599 u16 size = sizeof(struct rtllib_qos_parameter_info) - 2;
1601 if ((info_element == NULL) || (element_param == NULL))
1604 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1605 memcpy(element_param->info_element.qui, info_element->data,
1607 element_param->info_element.elementID = info_element->id;
1608 element_param->info_element.length = info_element->len;
1612 ret = rtllib_verify_qos_info(&element_param->info_element,
1613 QOS_OUI_PARAM_SUB_TYPE);
1617 /* Parse a QoS information element */
1618 static int rtllib_read_qos_info_element(struct rtllib_qos_information_element
1620 struct rtllib_info_element
1624 u16 size = sizeof(struct rtllib_qos_information_element) - 2;
1626 if (element_info == NULL)
1628 if (info_element == NULL)
1631 if ((info_element->id == QOS_ELEMENT_ID) &&
1632 (info_element->len == size)) {
1633 memcpy(element_info->qui, info_element->data,
1635 element_info->elementID = info_element->id;
1636 element_info->length = info_element->len;
1641 ret = rtllib_verify_qos_info(element_info,
1642 QOS_OUI_INFO_SUB_TYPE);
1647 /* Write QoS parameters from the ac parameters. */
1648 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info *param_elm,
1649 struct rtllib_qos_data *qos_data)
1651 struct rtllib_qos_ac_parameter *ac_params;
1652 struct rtllib_qos_parameters *qos_param = &(qos_data->parameters);
1657 qos_data->wmm_acm = 0;
1658 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1659 ac_params = &(param_elm->ac_params_record[i]);
1661 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1662 acm = (ac_params->aci_aifsn & 0x10) >> 4;
1664 if (aci >= QOS_QUEUE_NUM)
1668 /* BIT(0) | BIT(3) */
1670 qos_data->wmm_acm |= (0x01<<0)|(0x01<<3);
1673 /* BIT(4) | BIT(5) */
1675 qos_data->wmm_acm |= (0x01<<4)|(0x01<<5);
1678 /* BIT(6) | BIT(7) */
1680 qos_data->wmm_acm |= (0x01<<6)|(0x01<<7);
1684 /* BIT(1) | BIT(2) */
1686 qos_data->wmm_acm |= (0x01<<1)|(0x01<<2);
1690 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1692 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1693 qos_param->aifs[aci] = max_t(u8, qos_param->aifs[aci], 2);
1695 qos_param->cw_min[aci] = cpu_to_le16(ac_params->ecw_min_max &
1698 qos_param->cw_max[aci] = cpu_to_le16((ac_params->ecw_min_max &
1701 qos_param->flag[aci] =
1702 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1703 qos_param->tx_op_limit[aci] = ac_params->tx_op_limit;
1708 /* we have a generic data element which it may contain QoS information or
1709 * parameters element. check the information element length to decide
1710 * which type to read
1712 static int rtllib_parse_qos_info_param_IE(struct rtllib_device *ieee,
1713 struct rtllib_info_element
1715 struct rtllib_network *network)
1718 struct rtllib_qos_information_element qos_info_element;
1720 rc = rtllib_read_qos_info_element(&qos_info_element, info_element);
1723 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1724 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1726 struct rtllib_qos_parameter_info param_element;
1728 rc = rtllib_read_qos_param_element(¶m_element,
1731 rtllib_qos_convert_ac_to_parameters(¶m_element,
1732 &(network->qos_data));
1733 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1734 network->qos_data.param_count =
1735 param_element.info_element.ac_info & 0x0F;
1740 netdev_dbg(ieee->dev, "QoS is supported\n");
1741 network->qos_data.supported = 1;
1746 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1748 static const char *get_info_element_string(u16 id)
1753 MFIE_STRING(FH_SET);
1754 MFIE_STRING(DS_SET);
1755 MFIE_STRING(CF_SET);
1757 MFIE_STRING(IBSS_SET);
1758 MFIE_STRING(COUNTRY);
1759 MFIE_STRING(HOP_PARAMS);
1760 MFIE_STRING(HOP_TABLE);
1761 MFIE_STRING(REQUEST);
1762 MFIE_STRING(CHALLENGE);
1763 MFIE_STRING(POWER_CONSTRAINT);
1764 MFIE_STRING(POWER_CAPABILITY);
1765 MFIE_STRING(TPC_REQUEST);
1766 MFIE_STRING(TPC_REPORT);
1767 MFIE_STRING(SUPP_CHANNELS);
1769 MFIE_STRING(MEASURE_REQUEST);
1770 MFIE_STRING(MEASURE_REPORT);
1772 MFIE_STRING(IBSS_DFS);
1774 MFIE_STRING(RATES_EX);
1775 MFIE_STRING(GENERIC);
1776 MFIE_STRING(QOS_PARAMETER);
1782 static inline void rtllib_extract_country_ie(
1783 struct rtllib_device *ieee,
1784 struct rtllib_info_element *info_element,
1785 struct rtllib_network *network,
1788 if (IS_DOT11D_ENABLE(ieee)) {
1789 if (info_element->len != 0) {
1790 memcpy(network->CountryIeBuf, info_element->data,
1792 network->CountryIeLen = info_element->len;
1794 if (!IS_COUNTRY_IE_VALID(ieee)) {
1795 if (rtllib_act_scanning(ieee, false) &&
1796 ieee->FirstIe_InScan)
1797 netdev_info(ieee->dev,
1798 "Received beacon ContryIE, SSID: <%s>\n",
1800 Dot11d_UpdateCountryIe(ieee, addr2,
1802 info_element->data);
1806 if (IS_EQUAL_CIE_SRC(ieee, addr2))
1807 UPDATE_CIE_WATCHDOG(ieee);
1812 static void rtllib_parse_mife_generic(struct rtllib_device *ieee,
1813 struct rtllib_info_element *info_element,
1814 struct rtllib_network *network,
1816 u16 *tmp_htinfo_len)
1818 u16 ht_realtek_agg_len = 0;
1819 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1821 if (!rtllib_parse_qos_info_param_IE(ieee, info_element, network))
1823 if (info_element->len >= 4 &&
1824 info_element->data[0] == 0x00 &&
1825 info_element->data[1] == 0x50 &&
1826 info_element->data[2] == 0xf2 &&
1827 info_element->data[3] == 0x01) {
1828 network->wpa_ie_len = min(info_element->len + 2,
1830 memcpy(network->wpa_ie, info_element, network->wpa_ie_len);
1833 if (info_element->len == 7 &&
1834 info_element->data[0] == 0x00 &&
1835 info_element->data[1] == 0xe0 &&
1836 info_element->data[2] == 0x4c &&
1837 info_element->data[3] == 0x01 &&
1838 info_element->data[4] == 0x02)
1839 network->Turbo_Enable = 1;
1841 if (*tmp_htcap_len == 0) {
1842 if (info_element->len >= 4 &&
1843 info_element->data[0] == 0x00 &&
1844 info_element->data[1] == 0x90 &&
1845 info_element->data[2] == 0x4c &&
1846 info_element->data[3] == 0x033) {
1847 *tmp_htcap_len = min_t(u8, info_element->len,
1849 if (*tmp_htcap_len != 0) {
1850 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1851 network->bssht.bdHTCapLen = min_t(u16, *tmp_htcap_len, sizeof(network->bssht.bdHTCapBuf));
1852 memcpy(network->bssht.bdHTCapBuf,
1854 network->bssht.bdHTCapLen);
1857 if (*tmp_htcap_len != 0) {
1858 network->bssht.bdSupportHT = true;
1859 network->bssht.bdHT1R = ((((struct ht_capab_ele *)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1861 network->bssht.bdSupportHT = false;
1862 network->bssht.bdHT1R = false;
1867 if (*tmp_htinfo_len == 0) {
1868 if (info_element->len >= 4 &&
1869 info_element->data[0] == 0x00 &&
1870 info_element->data[1] == 0x90 &&
1871 info_element->data[2] == 0x4c &&
1872 info_element->data[3] == 0x034) {
1873 *tmp_htinfo_len = min_t(u8, info_element->len,
1875 if (*tmp_htinfo_len != 0) {
1876 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1877 network->bssht.bdHTInfoLen = min_t(u16, *tmp_htinfo_len, sizeof(network->bssht.bdHTInfoBuf));
1878 memcpy(network->bssht.bdHTInfoBuf,
1880 network->bssht.bdHTInfoLen);
1886 if (ieee->aggregation) {
1887 if (network->bssht.bdSupportHT) {
1888 if (info_element->len >= 4 &&
1889 info_element->data[0] == 0x00 &&
1890 info_element->data[1] == 0xe0 &&
1891 info_element->data[2] == 0x4c &&
1892 info_element->data[3] == 0x02) {
1893 ht_realtek_agg_len = min_t(u8,
1896 memcpy(ht_realtek_agg_buf,
1900 if (ht_realtek_agg_len >= 5) {
1901 network->realtek_cap_exit = true;
1902 network->bssht.bdRT2RTAggregation = true;
1904 if ((ht_realtek_agg_buf[4] == 1) &&
1905 (ht_realtek_agg_buf[5] & 0x02))
1906 network->bssht.bdRT2RTLongSlotTime = true;
1908 if ((ht_realtek_agg_buf[4] == 1) &&
1909 (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
1910 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
1913 if (ht_realtek_agg_len >= 5) {
1914 if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
1915 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_SOFTAP;
1919 if ((info_element->len >= 3 &&
1920 info_element->data[0] == 0x00 &&
1921 info_element->data[1] == 0x05 &&
1922 info_element->data[2] == 0xb5) ||
1923 (info_element->len >= 3 &&
1924 info_element->data[0] == 0x00 &&
1925 info_element->data[1] == 0x0a &&
1926 info_element->data[2] == 0xf7) ||
1927 (info_element->len >= 3 &&
1928 info_element->data[0] == 0x00 &&
1929 info_element->data[1] == 0x10 &&
1930 info_element->data[2] == 0x18)) {
1931 network->broadcom_cap_exist = true;
1933 if (info_element->len >= 3 &&
1934 info_element->data[0] == 0x00 &&
1935 info_element->data[1] == 0x0c &&
1936 info_element->data[2] == 0x43)
1937 network->ralink_cap_exist = true;
1938 if ((info_element->len >= 3 &&
1939 info_element->data[0] == 0x00 &&
1940 info_element->data[1] == 0x03 &&
1941 info_element->data[2] == 0x7f) ||
1942 (info_element->len >= 3 &&
1943 info_element->data[0] == 0x00 &&
1944 info_element->data[1] == 0x13 &&
1945 info_element->data[2] == 0x74))
1946 network->atheros_cap_exist = true;
1948 if ((info_element->len >= 3 &&
1949 info_element->data[0] == 0x00 &&
1950 info_element->data[1] == 0x50 &&
1951 info_element->data[2] == 0x43))
1952 network->marvell_cap_exist = true;
1953 if (info_element->len >= 3 &&
1954 info_element->data[0] == 0x00 &&
1955 info_element->data[1] == 0x40 &&
1956 info_element->data[2] == 0x96)
1957 network->cisco_cap_exist = true;
1960 if (info_element->len >= 3 &&
1961 info_element->data[0] == 0x00 &&
1962 info_element->data[1] == 0x0a &&
1963 info_element->data[2] == 0xf5)
1964 network->airgo_cap_exist = true;
1966 if (info_element->len > 4 &&
1967 info_element->data[0] == 0x00 &&
1968 info_element->data[1] == 0x40 &&
1969 info_element->data[2] == 0x96 &&
1970 info_element->data[3] == 0x01) {
1971 if (info_element->len == 6) {
1972 memcpy(network->CcxRmState, &info_element[4], 2);
1973 if (network->CcxRmState[0] != 0)
1974 network->bCcxRmEnable = true;
1976 network->bCcxRmEnable = false;
1977 network->MBssidMask = network->CcxRmState[1] & 0x07;
1978 if (network->MBssidMask != 0) {
1979 network->bMBssidValid = true;
1980 network->MBssidMask = 0xff <<
1981 (network->MBssidMask);
1982 ether_addr_copy(network->MBssid,
1984 network->MBssid[5] &= network->MBssidMask;
1986 network->bMBssidValid = false;
1989 network->bCcxRmEnable = false;
1992 if (info_element->len > 4 &&
1993 info_element->data[0] == 0x00 &&
1994 info_element->data[1] == 0x40 &&
1995 info_element->data[2] == 0x96 &&
1996 info_element->data[3] == 0x03) {
1997 if (info_element->len == 5) {
1998 network->bWithCcxVerNum = true;
1999 network->BssCcxVerNumber = info_element->data[4];
2001 network->bWithCcxVerNum = false;
2002 network->BssCcxVerNumber = 0;
2005 if (info_element->len > 4 &&
2006 info_element->data[0] == 0x00 &&
2007 info_element->data[1] == 0x50 &&
2008 info_element->data[2] == 0xf2 &&
2009 info_element->data[3] == 0x04) {
2010 netdev_dbg(ieee->dev, "MFIE_TYPE_WZC: %d bytes\n",
2012 network->wzc_ie_len = min(info_element->len+2, MAX_WZC_IE_LEN);
2013 memcpy(network->wzc_ie, info_element, network->wzc_ie_len);
2017 static void rtllib_parse_mfie_ht_cap(struct rtllib_info_element *info_element,
2018 struct rtllib_network *network,
2021 struct bss_ht *ht = &network->bssht;
2023 *tmp_htcap_len = min_t(u8, info_element->len, MAX_IE_LEN);
2024 if (*tmp_htcap_len != 0) {
2025 ht->bdHTSpecVer = HT_SPEC_VER_EWC;
2026 ht->bdHTCapLen = min_t(u16, *tmp_htcap_len,
2027 sizeof(ht->bdHTCapBuf));
2028 memcpy(ht->bdHTCapBuf, info_element->data, ht->bdHTCapLen);
2030 ht->bdSupportHT = true;
2031 ht->bdHT1R = ((((struct ht_capab_ele *)
2032 ht->bdHTCapBuf))->MCS[1]) == 0;
2034 ht->bdBandWidth = (enum ht_channel_width)
2035 (((struct ht_capab_ele *)
2036 (ht->bdHTCapBuf))->ChlWidth);
2038 ht->bdSupportHT = false;
2040 ht->bdBandWidth = HT_CHANNEL_WIDTH_20;
2044 int rtllib_parse_info_param(struct rtllib_device *ieee,
2045 struct rtllib_info_element *info_element,
2047 struct rtllib_network *network,
2048 struct rtllib_rx_stats *stats)
2052 u16 tmp_htcap_len = 0;
2053 u16 tmp_htinfo_len = 0;
2057 while (length >= sizeof(*info_element)) {
2058 if (sizeof(*info_element) + info_element->len > length) {
2059 netdev_dbg(ieee->dev,
2060 "Info elem: parse failed: info_element->len + 2 > left : info_element->len+2=%zd left=%d, id=%d.\n",
2061 info_element->len + sizeof(*info_element),
2062 length, info_element->id);
2063 /* We stop processing but don't return an error here
2064 * because some misbehaviour APs break this rule. ie.
2070 switch (info_element->id) {
2071 case MFIE_TYPE_SSID:
2072 if (rtllib_is_empty_essid(info_element->data,
2073 info_element->len)) {
2074 network->flags |= NETWORK_EMPTY_ESSID;
2078 network->ssid_len = min(info_element->len,
2079 (u8) IW_ESSID_MAX_SIZE);
2080 memcpy(network->ssid, info_element->data,
2082 if (network->ssid_len < IW_ESSID_MAX_SIZE)
2083 memset(network->ssid + network->ssid_len, 0,
2084 IW_ESSID_MAX_SIZE - network->ssid_len);
2086 netdev_dbg(ieee->dev, "MFIE_TYPE_SSID: '%s' len=%d.\n",
2087 network->ssid, network->ssid_len);
2090 case MFIE_TYPE_RATES:
2092 network->rates_len = min(info_element->len,
2094 for (i = 0; i < network->rates_len; i++) {
2095 network->rates[i] = info_element->data[i];
2096 p += snprintf(p, sizeof(rates_str) -
2097 (p - rates_str), "%02X ",
2099 if (rtllib_is_ofdm_rate
2100 (info_element->data[i])) {
2101 network->flags |= NETWORK_HAS_OFDM;
2102 if (info_element->data[i] &
2103 RTLLIB_BASIC_RATE_MASK)
2108 if (rtllib_is_cck_rate
2109 (info_element->data[i])) {
2110 network->flags |= NETWORK_HAS_CCK;
2114 netdev_dbg(ieee->dev, "MFIE_TYPE_RATES: '%s' (%d)\n",
2115 rates_str, network->rates_len);
2118 case MFIE_TYPE_RATES_EX:
2120 network->rates_ex_len = min(info_element->len,
2121 MAX_RATES_EX_LENGTH);
2122 for (i = 0; i < network->rates_ex_len; i++) {
2123 network->rates_ex[i] = info_element->data[i];
2124 p += snprintf(p, sizeof(rates_str) -
2125 (p - rates_str), "%02X ",
2126 network->rates_ex[i]);
2127 if (rtllib_is_ofdm_rate
2128 (info_element->data[i])) {
2129 network->flags |= NETWORK_HAS_OFDM;
2130 if (info_element->data[i] &
2131 RTLLIB_BASIC_RATE_MASK)
2137 netdev_dbg(ieee->dev, "MFIE_TYPE_RATES_EX: '%s' (%d)\n",
2138 rates_str, network->rates_ex_len);
2141 case MFIE_TYPE_DS_SET:
2142 netdev_dbg(ieee->dev, "MFIE_TYPE_DS_SET: %d\n",
2143 info_element->data[0]);
2144 network->channel = info_element->data[0];
2147 case MFIE_TYPE_FH_SET:
2148 netdev_dbg(ieee->dev, "MFIE_TYPE_FH_SET: ignored\n");
2151 case MFIE_TYPE_CF_SET:
2152 netdev_dbg(ieee->dev, "MFIE_TYPE_CF_SET: ignored\n");
2156 if (info_element->len < 4)
2159 network->tim.tim_count = info_element->data[0];
2160 network->tim.tim_period = info_element->data[1];
2162 network->dtim_period = info_element->data[1];
2163 if (ieee->state != RTLLIB_LINKED)
2165 network->last_dtim_sta_time = jiffies;
2167 network->dtim_data = RTLLIB_DTIM_VALID;
2170 if (info_element->data[2] & 1)
2171 network->dtim_data |= RTLLIB_DTIM_MBCAST;
2173 offset = (info_element->data[2] >> 1)*2;
2176 if (ieee->assoc_id < 8*offset ||
2177 ieee->assoc_id > 8*(offset + info_element->len - 3))
2180 offset = (ieee->assoc_id / 8) - offset;
2181 if (info_element->data[3 + offset] &
2182 (1 << (ieee->assoc_id % 8)))
2183 network->dtim_data |= RTLLIB_DTIM_UCAST;
2185 network->listen_interval = network->dtim_period;
2189 network->erp_value = info_element->data[0];
2190 network->flags |= NETWORK_HAS_ERP_VALUE;
2191 netdev_dbg(ieee->dev, "MFIE_TYPE_ERP_SET: %d\n",
2192 network->erp_value);
2194 case MFIE_TYPE_IBSS_SET:
2195 network->atim_window = info_element->data[0];
2196 netdev_dbg(ieee->dev, "MFIE_TYPE_IBSS_SET: %d\n",
2197 network->atim_window);
2200 case MFIE_TYPE_CHALLENGE:
2201 netdev_dbg(ieee->dev, "MFIE_TYPE_CHALLENGE: ignored\n");
2204 case MFIE_TYPE_GENERIC:
2205 netdev_dbg(ieee->dev, "MFIE_TYPE_GENERIC: %d bytes\n",
2208 rtllib_parse_mife_generic(ieee, info_element, network,
2214 netdev_dbg(ieee->dev, "MFIE_TYPE_RSN: %d bytes\n",
2216 network->rsn_ie_len = min(info_element->len + 2,
2218 memcpy(network->rsn_ie, info_element,
2219 network->rsn_ie_len);
2222 case MFIE_TYPE_HT_CAP:
2223 netdev_dbg(ieee->dev, "MFIE_TYPE_HT_CAP: %d bytes\n",
2226 rtllib_parse_mfie_ht_cap(info_element, network,
2231 case MFIE_TYPE_HT_INFO:
2232 netdev_dbg(ieee->dev, "MFIE_TYPE_HT_INFO: %d bytes\n",
2234 tmp_htinfo_len = min_t(u8, info_element->len,
2236 if (tmp_htinfo_len) {
2237 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2238 network->bssht.bdHTInfoLen = tmp_htinfo_len >
2239 sizeof(network->bssht.bdHTInfoBuf) ?
2240 sizeof(network->bssht.bdHTInfoBuf) :
2242 memcpy(network->bssht.bdHTInfoBuf,
2244 network->bssht.bdHTInfoLen);
2248 case MFIE_TYPE_AIRONET:
2249 netdev_dbg(ieee->dev, "MFIE_TYPE_AIRONET: %d bytes\n",
2251 if (info_element->len > IE_CISCO_FLAG_POSITION) {
2252 network->bWithAironetIE = true;
2254 if ((info_element->data[IE_CISCO_FLAG_POSITION]
2255 & SUPPORT_CKIP_MIC) ||
2256 (info_element->data[IE_CISCO_FLAG_POSITION]
2258 network->bCkipSupported = true;
2260 network->bCkipSupported = false;
2262 network->bWithAironetIE = false;
2263 network->bCkipSupported = false;
2266 case MFIE_TYPE_QOS_PARAMETER:
2267 netdev_err(ieee->dev,
2268 "QoS Error need to parse QOS_PARAMETER IE\n");
2271 case MFIE_TYPE_COUNTRY:
2272 netdev_dbg(ieee->dev, "MFIE_TYPE_COUNTRY: %d bytes\n",
2274 rtllib_extract_country_ie(ieee, info_element, network,
2279 netdev_dbg(ieee->dev,
2280 "Unsupported info element: %s (%d)\n",
2281 get_info_element_string(info_element->id),
2286 length -= sizeof(*info_element) + info_element->len;
2288 (struct rtllib_info_element *)&info_element->
2289 data[info_element->len];
2292 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2293 !network->cisco_cap_exist && !network->ralink_cap_exist &&
2294 !network->bssht.bdRT2RTAggregation)
2295 network->unknown_cap_exist = true;
2297 network->unknown_cap_exist = false;
2301 static long rtllib_translate_todbm(u8 signal_strength_index)
2305 signal_power = (long)((signal_strength_index + 1) >> 1);
2308 return signal_power;
2311 static inline int rtllib_network_init(
2312 struct rtllib_device *ieee,
2313 struct rtllib_probe_response *beacon,
2314 struct rtllib_network *network,
2315 struct rtllib_rx_stats *stats)
2317 memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
2319 /* Pull out fixed field data */
2320 ether_addr_copy(network->bssid, beacon->header.addr3);
2321 network->capability = le16_to_cpu(beacon->capability);
2322 network->last_scanned = jiffies;
2323 network->time_stamp[0] = beacon->time_stamp[0];
2324 network->time_stamp[1] = beacon->time_stamp[1];
2325 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
2326 /* Where to pull this? beacon->listen_interval;*/
2327 network->listen_interval = 0x0A;
2328 network->rates_len = network->rates_ex_len = 0;
2329 network->last_associate = 0;
2330 network->ssid_len = 0;
2331 network->hidden_ssid_len = 0;
2332 memset(network->hidden_ssid, 0, sizeof(network->hidden_ssid));
2334 network->atim_window = 0;
2335 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2337 network->berp_info_valid = false;
2338 network->broadcom_cap_exist = false;
2339 network->ralink_cap_exist = false;
2340 network->atheros_cap_exist = false;
2341 network->cisco_cap_exist = false;
2342 network->unknown_cap_exist = false;
2343 network->realtek_cap_exit = false;
2344 network->marvell_cap_exist = false;
2345 network->airgo_cap_exist = false;
2346 network->Turbo_Enable = 0;
2347 network->SignalStrength = stats->SignalStrength;
2348 network->RSSI = stats->SignalStrength;
2349 network->CountryIeLen = 0;
2350 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2351 HTInitializeBssDesc(&network->bssht);
2352 if (stats->freq == RTLLIB_52GHZ_BAND) {
2353 /* for A band (No DS info) */
2354 network->channel = stats->received_channel;
2356 network->flags |= NETWORK_HAS_CCK;
2358 network->wpa_ie_len = 0;
2359 network->rsn_ie_len = 0;
2360 network->wzc_ie_len = 0;
2362 if (rtllib_parse_info_param(ieee,
2363 beacon->info_element,
2364 (stats->len - sizeof(*beacon)),
2370 if (stats->freq == RTLLIB_52GHZ_BAND)
2371 network->mode = IEEE_A;
2373 if (network->flags & NETWORK_HAS_OFDM)
2374 network->mode |= IEEE_G;
2375 if (network->flags & NETWORK_HAS_CCK)
2376 network->mode |= IEEE_B;
2379 if (network->mode == 0) {
2380 netdev_dbg(ieee->dev, "Filtered out '%s (%pM)' network.\n",
2381 escape_essid(network->ssid, network->ssid_len),
2386 if (network->bssht.bdSupportHT) {
2387 if (network->mode == IEEE_A)
2388 network->mode = IEEE_N_5G;
2389 else if (network->mode & (IEEE_G | IEEE_B))
2390 network->mode = IEEE_N_24G;
2392 if (rtllib_is_empty_essid(network->ssid, network->ssid_len))
2393 network->flags |= NETWORK_EMPTY_ESSID;
2394 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2395 stats->noise = rtllib_translate_todbm((u8)(100-stats->signal)) - 25;
2397 memcpy(&network->stats, stats, sizeof(network->stats));
2402 static inline int is_same_network(struct rtllib_network *src,
2403 struct rtllib_network *dst, u8 ssidbroad)
2405 /* A network is only a duplicate if the channel, BSSID, ESSID
2406 * and the capability field (in particular IBSS and BSS) all match.
2407 * We treat all <hidden> with the same BSSID and channel
2410 return (((src->ssid_len == dst->ssid_len) || (!ssidbroad)) &&
2411 (src->channel == dst->channel) &&
2412 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2413 (!memcmp(src->ssid, dst->ssid, src->ssid_len) ||
2415 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2416 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2417 ((src->capability & WLAN_CAPABILITY_ESS) ==
2418 (dst->capability & WLAN_CAPABILITY_ESS)));
2422 static inline void update_network(struct rtllib_device *ieee,
2423 struct rtllib_network *dst,
2424 struct rtllib_network *src)
2429 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
2430 dst->capability = src->capability;
2431 memcpy(dst->rates, src->rates, src->rates_len);
2432 dst->rates_len = src->rates_len;
2433 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2434 dst->rates_ex_len = src->rates_ex_len;
2435 if (src->ssid_len > 0) {
2436 if (dst->ssid_len == 0) {
2437 memset(dst->hidden_ssid, 0, sizeof(dst->hidden_ssid));
2438 dst->hidden_ssid_len = src->ssid_len;
2439 memcpy(dst->hidden_ssid, src->ssid, src->ssid_len);
2441 memset(dst->ssid, 0, dst->ssid_len);
2442 dst->ssid_len = src->ssid_len;
2443 memcpy(dst->ssid, src->ssid, src->ssid_len);
2446 dst->mode = src->mode;
2447 dst->flags = src->flags;
2448 dst->time_stamp[0] = src->time_stamp[0];
2449 dst->time_stamp[1] = src->time_stamp[1];
2450 if (src->flags & NETWORK_HAS_ERP_VALUE) {
2451 dst->erp_value = src->erp_value;
2452 dst->berp_info_valid = src->berp_info_valid = true;
2454 dst->beacon_interval = src->beacon_interval;
2455 dst->listen_interval = src->listen_interval;
2456 dst->atim_window = src->atim_window;
2457 dst->dtim_period = src->dtim_period;
2458 dst->dtim_data = src->dtim_data;
2459 dst->last_dtim_sta_time = src->last_dtim_sta_time;
2460 memcpy(&dst->tim, &src->tim, sizeof(struct rtllib_tim_parameters));
2462 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2463 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2464 dst->bssht.bdHTCapLen = src->bssht.bdHTCapLen;
2465 memcpy(dst->bssht.bdHTCapBuf, src->bssht.bdHTCapBuf,
2466 src->bssht.bdHTCapLen);
2467 dst->bssht.bdHTInfoLen = src->bssht.bdHTInfoLen;
2468 memcpy(dst->bssht.bdHTInfoBuf, src->bssht.bdHTInfoBuf,
2469 src->bssht.bdHTInfoLen);
2470 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2471 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2472 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2473 dst->ralink_cap_exist = src->ralink_cap_exist;
2474 dst->atheros_cap_exist = src->atheros_cap_exist;
2475 dst->realtek_cap_exit = src->realtek_cap_exit;
2476 dst->marvell_cap_exist = src->marvell_cap_exist;
2477 dst->cisco_cap_exist = src->cisco_cap_exist;
2478 dst->airgo_cap_exist = src->airgo_cap_exist;
2479 dst->unknown_cap_exist = src->unknown_cap_exist;
2480 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2481 dst->wpa_ie_len = src->wpa_ie_len;
2482 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2483 dst->rsn_ie_len = src->rsn_ie_len;
2484 memcpy(dst->wzc_ie, src->wzc_ie, src->wzc_ie_len);
2485 dst->wzc_ie_len = src->wzc_ie_len;
2487 dst->last_scanned = jiffies;
2488 /* qos related parameters */
2489 qos_active = dst->qos_data.active;
2490 old_param = dst->qos_data.param_count;
2491 dst->qos_data.supported = src->qos_data.supported;
2492 if (dst->flags & NETWORK_HAS_QOS_PARAMETERS)
2493 memcpy(&dst->qos_data, &src->qos_data,
2494 sizeof(struct rtllib_qos_data));
2495 if (dst->qos_data.supported == 1) {
2497 netdev_dbg(ieee->dev,
2498 "QoS the network %s is QoS supported\n",
2501 netdev_dbg(ieee->dev,
2502 "QoS the network is QoS supported\n");
2504 dst->qos_data.active = qos_active;
2505 dst->qos_data.old_param_count = old_param;
2507 /* dst->last_associate is not overwritten */
2508 dst->wmm_info = src->wmm_info;
2509 if (src->wmm_param[0].ac_aci_acm_aifsn ||
2510 src->wmm_param[1].ac_aci_acm_aifsn ||
2511 src->wmm_param[2].ac_aci_acm_aifsn ||
2512 src->wmm_param[3].ac_aci_acm_aifsn)
2513 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2515 dst->SignalStrength = src->SignalStrength;
2516 dst->RSSI = src->RSSI;
2517 dst->Turbo_Enable = src->Turbo_Enable;
2519 dst->CountryIeLen = src->CountryIeLen;
2520 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2522 dst->bWithAironetIE = src->bWithAironetIE;
2523 dst->bCkipSupported = src->bCkipSupported;
2524 memcpy(dst->CcxRmState, src->CcxRmState, 2);
2525 dst->bCcxRmEnable = src->bCcxRmEnable;
2526 dst->MBssidMask = src->MBssidMask;
2527 dst->bMBssidValid = src->bMBssidValid;
2528 memcpy(dst->MBssid, src->MBssid, 6);
2529 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2530 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2533 static inline int is_beacon(u16 fc)
2535 return (WLAN_FC_GET_STYPE(fc) == RTLLIB_STYPE_BEACON);
2538 static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
2540 if (MAX_CHANNEL_NUMBER < channel) {
2541 netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
2545 if (rtllib->active_channel_map[channel] == 2)
2551 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel)
2553 if (MAX_CHANNEL_NUMBER < channel) {
2554 netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
2557 if (rtllib->active_channel_map[channel] > 0)
2562 EXPORT_SYMBOL(rtllib_legal_channel);
2564 static inline void rtllib_process_probe_response(
2565 struct rtllib_device *ieee,
2566 struct rtllib_probe_response *beacon,
2567 struct rtllib_rx_stats *stats)
2569 struct rtllib_network *target;
2570 struct rtllib_network *oldest = NULL;
2571 struct rtllib_info_element *info_element = &beacon->info_element[0];
2572 unsigned long flags;
2574 struct rtllib_network *network = kzalloc(sizeof(struct rtllib_network),
2576 u16 frame_ctl = le16_to_cpu(beacon->header.frame_ctl);
2581 netdev_dbg(ieee->dev,
2582 "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2583 escape_essid(info_element->data, info_element->len),
2584 beacon->header.addr3,
2585 (le16_to_cpu(beacon->capability) & (1<<0xf)) ? '1' : '0',
2586 (le16_to_cpu(beacon->capability) & (1<<0xe)) ? '1' : '0',
2587 (le16_to_cpu(beacon->capability) & (1<<0xd)) ? '1' : '0',
2588 (le16_to_cpu(beacon->capability) & (1<<0xc)) ? '1' : '0',
2589 (le16_to_cpu(beacon->capability) & (1<<0xb)) ? '1' : '0',
2590 (le16_to_cpu(beacon->capability) & (1<<0xa)) ? '1' : '0',
2591 (le16_to_cpu(beacon->capability) & (1<<0x9)) ? '1' : '0',
2592 (le16_to_cpu(beacon->capability) & (1<<0x8)) ? '1' : '0',
2593 (le16_to_cpu(beacon->capability) & (1<<0x7)) ? '1' : '0',
2594 (le16_to_cpu(beacon->capability) & (1<<0x6)) ? '1' : '0',
2595 (le16_to_cpu(beacon->capability) & (1<<0x5)) ? '1' : '0',
2596 (le16_to_cpu(beacon->capability) & (1<<0x4)) ? '1' : '0',
2597 (le16_to_cpu(beacon->capability) & (1<<0x3)) ? '1' : '0',
2598 (le16_to_cpu(beacon->capability) & (1<<0x2)) ? '1' : '0',
2599 (le16_to_cpu(beacon->capability) & (1<<0x1)) ? '1' : '0',
2600 (le16_to_cpu(beacon->capability) & (1<<0x0)) ? '1' : '0');
2602 if (rtllib_network_init(ieee, beacon, network, stats)) {
2603 netdev_dbg(ieee->dev, "Dropped '%s' ( %pM) via %s.\n",
2604 escape_essid(info_element->data, info_element->len),
2605 beacon->header.addr3,
2606 is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
2611 if (!rtllib_legal_channel(ieee, network->channel))
2614 if (WLAN_FC_GET_STYPE(frame_ctl) == RTLLIB_STYPE_PROBE_RESP) {
2615 if (IsPassiveChannel(ieee, network->channel)) {
2616 netdev_info(ieee->dev,
2617 "GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n",
2623 /* The network parsed correctly -- so now we scan our known networks
2624 * to see if we can find it in our list.
2626 * NOTE: This search is definitely not optimized. Once its doing
2627 * the "right thing" we'll optimize it for efficiency if
2631 /* Search for this entry in the list and update it if it is
2635 spin_lock_irqsave(&ieee->lock, flags);
2636 if (is_same_network(&ieee->current_network, network,
2637 (network->ssid_len ? 1 : 0))) {
2638 update_network(ieee, &ieee->current_network, network);
2639 if ((ieee->current_network.mode == IEEE_N_24G ||
2640 ieee->current_network.mode == IEEE_G)
2641 && ieee->current_network.berp_info_valid) {
2642 if (ieee->current_network.erp_value & ERP_UseProtection)
2643 ieee->current_network.buseprotection = true;
2645 ieee->current_network.buseprotection = false;
2647 if (is_beacon(frame_ctl)) {
2648 if (ieee->state >= RTLLIB_LINKED)
2649 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2652 list_for_each_entry(target, &ieee->network_list, list) {
2653 if (is_same_network(target, network,
2654 (target->ssid_len ? 1 : 0)))
2656 if ((oldest == NULL) ||
2657 (target->last_scanned < oldest->last_scanned))
2661 /* If we didn't find a match, then get a new network slot to initialize
2662 * with this beacon's information
2664 if (&target->list == &ieee->network_list) {
2665 if (list_empty(&ieee->network_free_list)) {
2666 /* If there are no more slots, expire the oldest */
2667 list_del(&oldest->list);
2669 netdev_dbg(ieee->dev,
2670 "Expired '%s' ( %pM) from network list.\n",
2671 escape_essid(target->ssid, target->ssid_len),
2674 /* Otherwise just pull from the free list */
2675 target = list_entry(ieee->network_free_list.next,
2676 struct rtllib_network, list);
2677 list_del(ieee->network_free_list.next);
2680 netdev_dbg(ieee->dev, "Adding '%s' ( %pM) via %s.\n",
2681 escape_essid(network->ssid, network->ssid_len),
2683 is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
2685 memcpy(target, network, sizeof(*target));
2686 list_add_tail(&target->list, &ieee->network_list);
2687 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2688 rtllib_softmac_new_net(ieee, network);
2690 netdev_dbg(ieee->dev, "Updating '%s' ( %pM) via %s.\n",
2691 escape_essid(target->ssid, target->ssid_len),
2693 is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
2695 /* we have an entry and we are going to update it. But this
2696 * entry may be already expired. In this case we do the same
2697 * as we found a new net and call the new_net handler
2699 renew = !time_after(target->last_scanned + ieee->scan_age,
2701 if ((!target->ssid_len) &&
2702 (((network->ssid_len > 0) && (target->hidden_ssid_len == 0))
2703 || ((ieee->current_network.ssid_len == network->ssid_len) &&
2704 (strncmp(ieee->current_network.ssid, network->ssid,
2705 network->ssid_len) == 0) &&
2706 (ieee->state == RTLLIB_NOLINK))))
2708 update_network(ieee, target, network);
2709 if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2710 rtllib_softmac_new_net(ieee, network);
2713 spin_unlock_irqrestore(&ieee->lock, flags);
2714 if (is_beacon(frame_ctl) &&
2715 is_same_network(&ieee->current_network, network,
2716 (network->ssid_len ? 1 : 0)) &&
2717 (ieee->state == RTLLIB_LINKED)) {
2718 if (ieee->handle_beacon != NULL)
2719 ieee->handle_beacon(ieee->dev, beacon,
2720 &ieee->current_network);
2726 void rtllib_rx_mgt(struct rtllib_device *ieee,
2727 struct sk_buff *skb,
2728 struct rtllib_rx_stats *stats)
2730 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data;
2732 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) !=
2733 RTLLIB_STYPE_PROBE_RESP) &&
2734 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) !=
2735 RTLLIB_STYPE_BEACON))
2736 ieee->last_rx_ps_time = jiffies;
2738 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
2740 case RTLLIB_STYPE_BEACON:
2741 netdev_dbg(ieee->dev, "received BEACON (%d)\n",
2742 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2743 rtllib_process_probe_response(
2744 ieee, (struct rtllib_probe_response *)header,
2747 if (ieee->sta_sleep || (ieee->ps != RTLLIB_PS_DISABLED &&
2748 ieee->iw_mode == IW_MODE_INFRA &&
2749 ieee->state == RTLLIB_LINKED))
2750 tasklet_schedule(&ieee->ps_task);
2754 case RTLLIB_STYPE_PROBE_RESP:
2755 netdev_dbg(ieee->dev, "received PROBE RESPONSE (%d)\n",
2756 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2757 rtllib_process_probe_response(ieee,
2758 (struct rtllib_probe_response *)header, stats);
2760 case RTLLIB_STYPE_PROBE_REQ:
2761 netdev_dbg(ieee->dev, "received PROBE RESQUEST (%d)\n",
2762 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2763 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2764 ((ieee->iw_mode == IW_MODE_ADHOC ||
2765 ieee->iw_mode == IW_MODE_MASTER) &&
2766 ieee->state == RTLLIB_LINKED))
2767 rtllib_rx_probe_rq(ieee, skb);