2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
14 ******************************************************************************
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andrea.merello@gmail.com>
19 A special thanks goes to Realtek for their support !
21 ******************************************************************************/
24 #include <linux/compiler.h>
25 #include <linux/errno.h>
26 #include <linux/if_arp.h>
27 #include <linux/in6.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/netdevice.h>
33 #include <linux/pci.h>
34 #include <linux/proc_fs.h>
35 #include <linux/skbuff.h>
36 #include <linux/slab.h>
37 #include <linux/tcp.h>
38 #include <linux/types.h>
39 #include <linux/wireless.h>
40 #include <linux/etherdevice.h>
41 #include <linux/uaccess.h>
42 #include <linux/ctype.h>
47 static inline void rtllib_monitor_rx(struct rtllib_device *ieee,
48 struct sk_buff *skb, struct rtllib_rx_stats *rx_status,
52 skb_reset_mac_header(skb);
53 skb_pull(skb, hdr_length);
54 skb->pkt_type = PACKET_OTHERHOST;
55 skb->protocol = htons(ETH_P_80211_RAW);
56 memset(skb->cb, 0, sizeof(skb->cb));
60 /* Called only as a tasklet (software IRQ) */
61 static struct rtllib_frag_entry *
62 rtllib_frag_cache_find(struct rtllib_device *ieee, unsigned int seq,
63 unsigned int frag, u8 tid, u8 *src, u8 *dst)
65 struct rtllib_frag_entry *entry;
68 for (i = 0; i < RTLLIB_FRAG_CACHE_LEN; i++) {
69 entry = &ieee->frag_cache[tid][i];
70 if (entry->skb != NULL &&
71 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
73 "expiring fragment cache entry "
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);
294 tcb_desc->bHwSec = 1;
296 if (ieee->need_sw_enc)
297 tcb_desc->bHwSec = 0;
300 hdr = (struct rtllib_hdr_4addr *) skb->data;
301 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
303 atomic_inc(&crypt->refcnt);
304 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
305 atomic_dec(&crypt->refcnt);
308 "decryption failed (SA= %pM"
309 ") res=%d\n", hdr->addr2, res);
311 RTLLIB_DEBUG_DROP("Decryption failed ICV "
312 "mismatch (key %d)\n",
313 skb->data[hdrlen + 3] >> 6);
314 ieee->ieee_stats.rx_discards_undecryptable++;
322 /* Called only as a tasklet (software IRQ), by rtllib_rx */
324 rtllib_rx_frame_decrypt_msdu(struct rtllib_device *ieee, struct sk_buff *skb,
325 int keyidx, struct lib80211_crypt_data *crypt)
327 struct rtllib_hdr_4addr *hdr;
330 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
332 if (ieee->hwsec_active) {
333 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
335 tcb_desc->bHwSec = 1;
337 if (ieee->need_sw_enc)
338 tcb_desc->bHwSec = 0;
341 hdr = (struct rtllib_hdr_4addr *) skb->data;
342 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
344 atomic_inc(&crypt->refcnt);
345 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
346 atomic_dec(&crypt->refcnt);
348 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
349 " (SA= %pM keyidx=%d)\n",
350 ieee->dev->name, hdr->addr2, keyidx);
358 /* this function is stolen from ipw2200 driver*/
359 #define IEEE_PACKET_RETRY_TIME (5*HZ)
360 static int is_duplicate_packet(struct rtllib_device *ieee,
361 struct rtllib_hdr_4addr *header)
363 u16 fc = le16_to_cpu(header->frame_ctl);
364 u16 sc = le16_to_cpu(header->seq_ctl);
365 u16 seq = WLAN_GET_SEQ_SEQ(sc);
366 u16 frag = WLAN_GET_SEQ_FRAG(sc);
367 u16 *last_seq, *last_frag;
368 unsigned long *last_time;
369 struct rtllib_hdr_3addrqos *hdr_3addrqos;
370 struct rtllib_hdr_4addrqos *hdr_4addrqos;
373 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) && RTLLIB_QOS_HAS_SEQ(fc)) {
374 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)header;
375 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
378 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
379 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)header;
380 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
387 switch (ieee->iw_mode) {
391 struct ieee_ibss_seq *entry = NULL;
392 u8 *mac = header->addr2;
393 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
395 list_for_each(p, &ieee->ibss_mac_hash[index]) {
396 entry = list_entry(p, struct ieee_ibss_seq, list);
397 if (!memcmp(entry->mac, mac, ETH_ALEN))
400 if (p == &ieee->ibss_mac_hash[index]) {
401 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
403 printk(KERN_WARNING "Cannot malloc new mac entry\n");
406 memcpy(entry->mac, mac, ETH_ALEN);
407 entry->seq_num[tid] = seq;
408 entry->frag_num[tid] = frag;
409 entry->packet_time[tid] = jiffies;
410 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
413 last_seq = &entry->seq_num[tid];
414 last_frag = &entry->frag_num[tid];
415 last_time = &entry->packet_time[tid];
420 last_seq = &ieee->last_rxseq_num[tid];
421 last_frag = &ieee->last_rxfrag_num[tid];
422 last_time = &ieee->last_packet_time[tid];
428 if ((*last_seq == seq) &&
429 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
430 if (*last_frag == frag)
432 if (*last_frag + 1 != frag)
433 /* out-of-order fragment */
439 *last_time = jiffies;
447 static bool AddReorderEntry(struct rx_ts_record *pTS,
448 struct rx_reorder_entry *pReorderEntry)
450 struct list_head *pList = &pTS->RxPendingPktList;
452 while (pList->next != &pTS->RxPendingPktList) {
453 if (SN_LESS(pReorderEntry->SeqNum, ((struct rx_reorder_entry *)
454 list_entry(pList->next, struct rx_reorder_entry,
457 else if (SN_EQUAL(pReorderEntry->SeqNum,
458 ((struct rx_reorder_entry *)list_entry(pList->next,
459 struct rx_reorder_entry, List))->SeqNum))
464 pReorderEntry->List.next = pList->next;
465 pReorderEntry->List.next->prev = &pReorderEntry->List;
466 pReorderEntry->List.prev = pList;
467 pList->next = &pReorderEntry->List;
472 void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prxbIndicateArray, u8 index)
474 struct net_device_stats *stats = &ieee->stats;
478 for (j = 0; j < index; j++) {
479 struct rtllib_rxb *prxb = prxbIndicateArray[j];
481 for (i = 0; i < prxb->nr_subframes; i++) {
482 struct sk_buff *sub_skb = prxb->subframes[i];
484 /* convert hdr + possible LLC headers into Ethernet header */
485 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
486 if (sub_skb->len >= 8 &&
487 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
488 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
489 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
490 /* remove RFC1042 or Bridge-Tunnel encapsulation
491 * and replace EtherType */
492 skb_pull(sub_skb, SNAP_SIZE);
493 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
494 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
497 /* Leave Ethernet header part of hdr and full payload */
499 memcpy(skb_push(sub_skb, 2), &len, 2);
500 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
501 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
504 /* Indicate the packets to upper layer */
507 stats->rx_bytes += sub_skb->len;
509 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
510 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
511 sub_skb->dev = ieee->dev;
512 sub_skb->dev->stats.rx_packets++;
513 sub_skb->dev->stats.rx_bytes += sub_skb->len;
514 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
515 ieee->last_rx_ps_time = jiffies;
524 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee, struct rx_ts_record *pTS)
526 struct rx_reorder_entry *pRxReorderEntry;
529 del_timer_sync(&pTS->RxPktPendingTimer);
530 while (!list_empty(&pTS->RxPendingPktList)) {
531 if (RfdCnt >= REORDER_WIN_SIZE) {
532 printk(KERN_INFO "-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n", __func__);
536 pRxReorderEntry = (struct rx_reorder_entry *)list_entry(pTS->RxPendingPktList.prev, struct rx_reorder_entry, List);
537 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate SeqNum %d!\n", __func__, pRxReorderEntry->SeqNum);
538 list_del_init(&pRxReorderEntry->List);
540 ieee->RfdArray[RfdCnt] = pRxReorderEntry->prxb;
543 list_add_tail(&pRxReorderEntry->List, &ieee->RxReorder_Unused_List);
545 rtllib_indicate_packets(ieee, ieee->RfdArray, RfdCnt);
547 pTS->RxIndicateSeq = 0xffff;
550 static void RxReorderIndicatePacket(struct rtllib_device *ieee,
551 struct rtllib_rxb *prxb,
552 struct rx_ts_record *pTS, u16 SeqNum)
554 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
555 struct rx_reorder_entry *pReorderEntry = NULL;
556 u8 WinSize = pHTInfo->RxReorderWinSize;
559 bool bMatchWinStart = false, bPktInBuf = false;
562 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Seq is %d, pTS->RxIndicateSeq"
563 " is %d, WinSize is %d\n", __func__, SeqNum,
564 pTS->RxIndicateSeq, WinSize);
566 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
568 WinEnd = (pTS->RxIndicateSeq + WinSize - 1) % 4096;
569 /* Rx Reorder initialize condition.*/
570 if (pTS->RxIndicateSeq == 0xffff)
571 pTS->RxIndicateSeq = SeqNum;
573 /* Drop out the packet which SeqNum is smaller than WinStart */
574 if (SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
575 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
576 pTS->RxIndicateSeq, SeqNum);
577 pHTInfo->RxReorderDropCounter++;
581 for (i = 0; i < prxb->nr_subframes; i++)
582 dev_kfree_skb(prxb->subframes[i]);
586 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
591 * Sliding window manipulation. Conditions includes:
592 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
593 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
595 if (SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
596 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
597 bMatchWinStart = true;
598 } else if (SN_LESS(WinEnd, SeqNum)) {
599 if (SeqNum >= (WinSize - 1))
600 pTS->RxIndicateSeq = SeqNum + 1 - WinSize;
602 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum + 1)) + 1;
603 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Window Shift! IndicateSeq: %d,"
604 " NewSeq: %d\n", pTS->RxIndicateSeq, SeqNum);
608 * Indication process.
609 * After Packet dropping and Sliding Window shifting as above, we can
610 * now just indicate the packets with the SeqNum smaller than latest
611 * WinStart and struct buffer other packets.
613 /* For Rx Reorder condition:
614 * 1. All packets with SeqNum smaller than WinStart => Indicate
615 * 2. All packets with SeqNum larger than or equal to
616 * WinStart => Buffer it.
618 if (bMatchWinStart) {
619 /* Current packet is going to be indicated.*/
620 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Packets indication!! "
621 "IndicateSeq: %d, NewSeq: %d\n",
622 pTS->RxIndicateSeq, SeqNum);
623 ieee->prxbIndicateArray[0] = prxb;
626 /* Current packet is going to be inserted into pending list.*/
627 if (!list_empty(&ieee->RxReorder_Unused_List)) {
628 pReorderEntry = (struct rx_reorder_entry *)
629 list_entry(ieee->RxReorder_Unused_List.next,
630 struct rx_reorder_entry, List);
631 list_del_init(&pReorderEntry->List);
633 /* Make a reorder entry and insert into a the packet list.*/
634 pReorderEntry->SeqNum = SeqNum;
635 pReorderEntry->prxb = prxb;
637 if (!AddReorderEntry(pTS, pReorderEntry)) {
638 RTLLIB_DEBUG(RTLLIB_DL_REORDER,
639 "%s(): Duplicate packet is "
640 "dropped!! IndicateSeq: %d, "
642 __func__, pTS->RxIndicateSeq,
644 list_add_tail(&pReorderEntry->List,
645 &ieee->RxReorder_Unused_List); {
648 for (i = 0; i < prxb->nr_subframes; i++)
649 dev_kfree_skb(prxb->subframes[i]);
654 RTLLIB_DEBUG(RTLLIB_DL_REORDER,
655 "Pkt insert into struct buffer!! "
656 "IndicateSeq: %d, NewSeq: %d\n",
657 pTS->RxIndicateSeq, SeqNum);
661 * Packets are dropped if there are not enough reorder
662 * entries. This part should be modified!! We can just
663 * indicate all the packets in struct buffer and get
666 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket():"
667 " There is no reorder entry!! Packet is "
672 for (i = 0; i < prxb->nr_subframes; i++)
673 dev_kfree_skb(prxb->subframes[i]);
680 /* Check if there is any packet need indicate.*/
681 while (!list_empty(&pTS->RxPendingPktList)) {
682 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): start RREORDER indicate\n", __func__);
684 pReorderEntry = (struct rx_reorder_entry *)list_entry(pTS->RxPendingPktList.prev,
685 struct rx_reorder_entry, List);
686 if (SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
687 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) {
688 /* This protect struct buffer from overflow. */
689 if (index >= REORDER_WIN_SIZE) {
690 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicate"
691 "Packet(): Buffer overflow!!\n");
696 list_del_init(&pReorderEntry->List);
698 if (SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
699 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
701 ieee->prxbIndicateArray[index] = pReorderEntry->prxb;
702 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate SeqNum"
703 " %d!\n", __func__, pReorderEntry->SeqNum);
706 list_add_tail(&pReorderEntry->List,
707 &ieee->RxReorder_Unused_List);
714 /* Handling pending timer. Set this timer to prevent from long time
717 if (timer_pending(&pTS->RxPktPendingTimer))
718 del_timer_sync(&pTS->RxPktPendingTimer);
719 pTS->RxTimeoutIndicateSeq = 0xffff;
721 if (index > REORDER_WIN_SIZE) {
722 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket():"
723 " Rx Reorder struct buffer full!!\n");
724 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
728 rtllib_indicate_packets(ieee, ieee->prxbIndicateArray, index);
732 if (bPktInBuf && pTS->RxTimeoutIndicateSeq == 0xffff) {
733 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): SET rx timeout timer\n",
735 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
736 mod_timer(&pTS->RxPktPendingTimer, jiffies +
737 MSECS(pHTInfo->RxReorderPendingTime));
739 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
742 static u8 parse_subframe(struct rtllib_device *ieee, struct sk_buff *skb,
743 struct rtllib_rx_stats *rx_stats,
744 struct rtllib_rxb *rxb, u8 *src, u8 *dst)
746 struct rtllib_hdr_3addr *hdr = (struct rtllib_hdr_3addr *)skb->data;
747 u16 fc = le16_to_cpu(hdr->frame_ctl);
749 u16 LLCOffset = sizeof(struct rtllib_hdr_3addr);
751 bool bIsAggregateFrame = false;
752 u16 nSubframe_Length;
753 u8 nPadding_Length = 0;
755 struct sk_buff *sub_skb;
757 /* just for debug purpose */
758 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
759 if ((RTLLIB_QOS_HAS_SEQ(fc)) &&
760 (((union frameqos *)(skb->data + RTLLIB_3ADDR_LEN))->field.reserved))
761 bIsAggregateFrame = true;
763 if (RTLLIB_QOS_HAS_SEQ(fc))
765 if (rx_stats->bContainHTC)
766 LLCOffset += sHTCLng;
768 ChkLength = LLCOffset;
770 if (skb->len <= ChkLength)
773 skb_pull(skb, LLCOffset);
774 ieee->bIsAggregateFrame = bIsAggregateFrame;
775 if (!bIsAggregateFrame) {
776 rxb->nr_subframes = 1;
778 /* altered by clark 3/30/2010
779 * The struct buffer size of the skb indicated to upper layer
780 * must be less than 5000, or the defraged IP datagram
781 * in the IP layer will exceed "ipfrag_high_tresh" and be
782 * discarded. so there must not use the function
783 * "skb_copy" and "skb_clone" for "skb".
786 /* Allocate new skb for releasing to upper layer */
787 sub_skb = dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE);
790 skb_reserve(sub_skb, 12);
791 data_ptr = (u8 *)skb_put(sub_skb, skb->len);
792 memcpy(data_ptr, skb->data, skb->len);
793 sub_skb->dev = ieee->dev;
795 rxb->subframes[0] = sub_skb;
797 memcpy(rxb->src, src, ETH_ALEN);
798 memcpy(rxb->dst, dst, ETH_ALEN);
799 rxb->subframes[0]->dev = ieee->dev;
802 rxb->nr_subframes = 0;
803 memcpy(rxb->src, src, ETH_ALEN);
804 memcpy(rxb->dst, dst, ETH_ALEN);
805 while (skb->len > ETHERNET_HEADER_SIZE) {
806 /* Offset 12 denote 2 mac address */
807 nSubframe_Length = *((u16 *)(skb->data + 12));
808 nSubframe_Length = (nSubframe_Length >> 8) +
809 (nSubframe_Length << 8);
811 if (skb->len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
812 printk(KERN_INFO "%s: A-MSDU parse error!! "
813 "pRfd->nTotalSubframe : %d\n",\
814 __func__, rxb->nr_subframes);
815 printk(KERN_INFO "%s: A-MSDU parse error!! "
816 "Subframe Length: %d\n", __func__,
818 printk(KERN_INFO "nRemain_Length is %d and "
819 "nSubframe_Length is : %d\n", skb->len,
821 printk(KERN_INFO "The Packet SeqNum is %d\n", SeqNum);
825 /* move the data point to data content */
826 skb_pull(skb, ETHERNET_HEADER_SIZE);
828 /* altered by clark 3/30/2010
829 * The struct buffer size of the skb indicated to upper layer
830 * must be less than 5000, or the defraged IP datagram
831 * in the IP layer will exceed "ipfrag_high_tresh" and be
832 * discarded. so there must not use the function
833 * "skb_copy" and "skb_clone" for "skb".
836 /* Allocate new skb for releasing to upper layer */
837 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
840 skb_reserve(sub_skb, 12);
841 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
842 memcpy(data_ptr, skb->data, nSubframe_Length);
844 sub_skb->dev = ieee->dev;
845 rxb->subframes[rxb->nr_subframes++] = sub_skb;
846 if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
847 RTLLIB_DEBUG_RX("ParseSubframe(): Too many "
848 "Subframes! Packets dropped!\n");
851 skb_pull(skb, nSubframe_Length);
854 nPadding_Length = 4 - ((nSubframe_Length +
855 ETHERNET_HEADER_SIZE) % 4);
856 if (nPadding_Length == 4)
859 if (skb->len < nPadding_Length)
862 skb_pull(skb, nPadding_Length);
866 return rxb->nr_subframes;
871 static size_t rtllib_rx_get_hdrlen(struct rtllib_device *ieee,
873 struct rtllib_rx_stats *rx_stats)
875 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
876 u16 fc = le16_to_cpu(hdr->frame_ctl);
879 hdrlen = rtllib_get_hdrlen(fc);
880 if (HTCCheck(ieee, skb->data)) {
882 printk(KERN_INFO "%s: find HTCControl!\n", __func__);
884 rx_stats->bContainHTC = true;
887 if (RTLLIB_QOS_HAS_SEQ(fc))
888 rx_stats->bIsQosData = true;
893 static int rtllib_rx_check_duplicate(struct rtllib_device *ieee,
894 struct sk_buff *skb, u8 multicast)
896 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
898 u8 frag, type, stype;
900 fc = le16_to_cpu(hdr->frame_ctl);
901 type = WLAN_FC_GET_TYPE(fc);
902 stype = WLAN_FC_GET_STYPE(fc);
903 sc = le16_to_cpu(hdr->seq_ctl);
904 frag = WLAN_GET_SEQ_FRAG(sc);
906 if ((ieee->pHTInfo->bCurRxReorderEnable == false) ||
907 !ieee->current_network.qos_data.active ||
908 !IsDataFrame(skb->data) ||
909 IsLegacyDataFrame(skb->data)) {
910 if (!((type == RTLLIB_FTYPE_MGMT) && (stype == RTLLIB_STYPE_BEACON))) {
911 if (is_duplicate_packet(ieee, hdr))
915 struct rx_ts_record *pRxTS = NULL;
917 if (GetTs(ieee, (struct ts_common_info **) &pRxTS, hdr->addr2,
918 (u8)Frame_QoSTID((u8 *)(skb->data)), RX_DIR, true)) {
919 if ((fc & (1<<11)) && (frag == pRxTS->RxLastFragNum) &&
920 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum))
922 pRxTS->RxLastFragNum = frag;
923 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
925 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!%s(): No TS!! Skip"
926 " the check!!\n", __func__);
934 static void rtllib_rx_extract_addr(struct rtllib_device *ieee,
935 struct rtllib_hdr_4addr *hdr, u8 *dst,
938 u16 fc = le16_to_cpu(hdr->frame_ctl);
940 switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
941 case RTLLIB_FCTL_FROMDS:
942 memcpy(dst, hdr->addr1, ETH_ALEN);
943 memcpy(src, hdr->addr3, ETH_ALEN);
944 memcpy(bssid, hdr->addr2, ETH_ALEN);
946 case RTLLIB_FCTL_TODS:
947 memcpy(dst, hdr->addr3, ETH_ALEN);
948 memcpy(src, hdr->addr2, ETH_ALEN);
949 memcpy(bssid, hdr->addr1, ETH_ALEN);
951 case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
952 memcpy(dst, hdr->addr3, ETH_ALEN);
953 memcpy(src, hdr->addr4, ETH_ALEN);
954 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
957 memcpy(dst, hdr->addr1, ETH_ALEN);
958 memcpy(src, hdr->addr2, ETH_ALEN);
959 memcpy(bssid, hdr->addr3, ETH_ALEN);
964 static int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc,
965 u8 *dst, u8 *src, u8 *bssid, u8 *addr2)
969 type = WLAN_FC_GET_TYPE(fc);
970 stype = WLAN_FC_GET_STYPE(fc);
972 /* Filter frames from different BSS */
973 if (((fc & RTLLIB_FCTL_DSTODS) != RTLLIB_FCTL_DSTODS) &&
974 !ether_addr_equal(ieee->current_network.bssid, bssid) &&
975 !is_zero_ether_addr(ieee->current_network.bssid)) {
979 /* Filter packets sent by an STA that will be forwarded by AP */
980 if (ieee->IntelPromiscuousModeInfo.bPromiscuousOn &&
981 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame) {
982 if ((fc & RTLLIB_FCTL_TODS) && !(fc & RTLLIB_FCTL_FROMDS) &&
983 !ether_addr_equal(dst, ieee->current_network.bssid) &&
984 ether_addr_equal(bssid, ieee->current_network.bssid)) {
989 /* Nullfunc frames may have PS-bit set, so they must be passed to
990 * hostap_handle_sta_rx() before being dropped here. */
991 if (!ieee->IntelPromiscuousModeInfo.bPromiscuousOn) {
992 if (stype != RTLLIB_STYPE_DATA &&
993 stype != RTLLIB_STYPE_DATA_CFACK &&
994 stype != RTLLIB_STYPE_DATA_CFPOLL &&
995 stype != RTLLIB_STYPE_DATA_CFACKPOLL &&
996 stype != RTLLIB_STYPE_QOS_DATA) {
997 if (stype != RTLLIB_STYPE_NULLFUNC)
999 "RX: dropped data frame "
1000 "with no data (type=0x%02x, "
1001 "subtype=0x%02x)\n",
1007 if (ieee->iw_mode != IW_MODE_MESH) {
1008 /* packets from our adapter are dropped (echo) */
1009 if (!memcmp(src, ieee->dev->dev_addr, ETH_ALEN))
1012 /* {broad,multi}cast packets to our BSS go through */
1013 if (is_multicast_ether_addr(dst)) {
1014 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1021 static int rtllib_rx_get_crypt(struct rtllib_device *ieee, struct sk_buff *skb,
1022 struct lib80211_crypt_data **crypt, size_t hdrlen)
1024 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1025 u16 fc = le16_to_cpu(hdr->frame_ctl);
1028 if (ieee->host_decrypt) {
1029 if (skb->len >= hdrlen + 3)
1030 idx = skb->data[hdrlen + 3] >> 6;
1032 *crypt = ieee->crypt_info.crypt[idx];
1033 /* allow NULL decrypt to indicate an station specific override
1034 * for default encryption */
1035 if (*crypt && ((*crypt)->ops == NULL ||
1036 (*crypt)->ops->decrypt_mpdu == NULL))
1039 if (!*crypt && (fc & RTLLIB_FCTL_WEP)) {
1040 /* This seems to be triggered by some (multicast?)
1041 * frames from other than current BSS, so just drop the
1042 * frames silently instead of filling system log with
1044 RTLLIB_DEBUG_DROP("Decryption failed (not set)"
1047 ieee->ieee_stats.rx_discards_undecryptable++;
1055 static int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
1056 struct rtllib_rx_stats *rx_stats,
1057 struct lib80211_crypt_data *crypt, size_t hdrlen)
1059 struct rtllib_hdr_4addr *hdr;
1064 hdr = (struct rtllib_hdr_4addr *)skb->data;
1065 fc = le16_to_cpu(hdr->frame_ctl);
1066 sc = le16_to_cpu(hdr->seq_ctl);
1067 frag = WLAN_GET_SEQ_FRAG(sc);
1069 if ((!rx_stats->Decrypted))
1070 ieee->need_sw_enc = 1;
1072 ieee->need_sw_enc = 0;
1074 keyidx = rtllib_rx_frame_decrypt(ieee, skb, crypt);
1075 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) && (keyidx < 0)) {
1076 printk(KERN_INFO "%s: decrypt frame error\n", __func__);
1080 hdr = (struct rtllib_hdr_4addr *) skb->data;
1081 if ((frag != 0 || (fc & RTLLIB_FCTL_MOREFRAGS))) {
1083 struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
1085 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1088 RTLLIB_DEBUG(RTLLIB_DL_RX | RTLLIB_DL_FRAG,
1089 "Rx cannot get skb from fragment "
1090 "cache (morefrag=%d seq=%u frag=%u)\n",
1091 (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
1092 WLAN_GET_SEQ_SEQ(sc), frag);
1099 if (frag_skb->tail + flen > frag_skb->end) {
1100 printk(KERN_WARNING "%s: host decrypted and "
1101 "reassembled frame did not fit skb\n",
1103 rtllib_frag_cache_invalidate(ieee, hdr);
1108 /* copy first fragment (including full headers) into
1109 * beginning of the fragment cache skb */
1110 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1112 /* append frame payload to the end of the fragment
1114 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1117 dev_kfree_skb_any(skb);
1120 if (fc & RTLLIB_FCTL_MOREFRAGS) {
1121 /* more fragments expected - leave the skb in fragment
1122 * cache for now; it will be delivered to upper layers
1123 * after all fragments have been received */
1127 /* this was the last fragment and the frame will be
1128 * delivered, so remove skb from fragment cache */
1130 hdr = (struct rtllib_hdr_4addr *) skb->data;
1131 rtllib_frag_cache_invalidate(ieee, hdr);
1134 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1135 * encrypted/authenticated */
1136 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
1137 rtllib_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
1138 printk(KERN_INFO "%s: ==>decrypt msdu error\n", __func__);
1142 hdr = (struct rtllib_hdr_4addr *) skb->data;
1143 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep) {
1144 if (/*ieee->ieee802_1x &&*/
1145 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1147 /* pass unencrypted EAPOL frames even if encryption is
1149 struct eapol *eap = (struct eapol *)(skb->data +
1151 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1152 eap_get_type(eap->type));
1155 "encryption configured, but RX "
1156 "frame not encrypted (SA= %pM)\n",
1162 if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
1163 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1164 struct eapol *eap = (struct eapol *)(skb->data +
1166 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1167 eap_get_type(eap->type));
1170 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
1171 !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1173 "dropped unencrypted RX data "
1175 " (drop_unencrypted=1)\n",
1180 if (rtllib_is_eapol_frame(ieee, skb, hdrlen))
1181 printk(KERN_WARNING "RX: IEEE802.1X EAPOL frame!\n");
1186 static void rtllib_rx_check_leave_lps(struct rtllib_device *ieee, u8 unicast, u8 nr_subframes)
1190 if ((ieee->state == RTLLIB_LINKED)) {
1191 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +
1192 ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1193 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) {
1194 if (ieee->LeisurePSLeave)
1195 ieee->LeisurePSLeave(ieee->dev);
1199 ieee->last_rx_ps_time = jiffies;
1202 static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
1203 struct rtllib_rx_stats *rx_stats,
1204 struct rtllib_rxb *rxb,
1208 struct net_device *dev = ieee->dev;
1213 printk(KERN_INFO "%s: rxb is NULL!!\n", __func__);
1217 for (i = 0; i < rxb->nr_subframes; i++) {
1218 struct sk_buff *sub_skb = rxb->subframes[i];
1221 /* convert hdr + possible LLC headers into Ethernet header */
1222 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1223 if (sub_skb->len >= 8 &&
1224 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1225 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1226 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1227 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1228 * replace EtherType */
1229 skb_pull(sub_skb, SNAP_SIZE);
1230 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1231 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1234 /* Leave Ethernet header part of hdr and full payload */
1236 memcpy(skb_push(sub_skb, 2), &len, 2);
1237 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1238 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1241 ieee->stats.rx_packets++;
1242 ieee->stats.rx_bytes += sub_skb->len;
1244 if (is_multicast_ether_addr(dst))
1245 ieee->stats.multicast++;
1247 /* Indicate the packets to upper layer */
1248 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1249 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1251 sub_skb->dev->stats.rx_packets++;
1252 sub_skb->dev->stats.rx_bytes += sub_skb->len;
1253 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1261 static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1262 struct rtllib_rx_stats *rx_stats)
1264 struct net_device *dev = ieee->dev;
1265 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1266 struct lib80211_crypt_data *crypt = NULL;
1267 struct rtllib_rxb *rxb = NULL;
1268 struct rx_ts_record *pTS = NULL;
1269 u16 fc, sc, SeqNum = 0;
1270 u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0;
1271 u8 dst[ETH_ALEN], src[ETH_ALEN], bssid[ETH_ALEN] = {0}, *payload;
1273 bool bToOtherSTA = false;
1276 hdr = (struct rtllib_hdr_4addr *)skb->data;
1277 fc = le16_to_cpu(hdr->frame_ctl);
1278 type = WLAN_FC_GET_TYPE(fc);
1279 stype = WLAN_FC_GET_STYPE(fc);
1280 sc = le16_to_cpu(hdr->seq_ctl);
1282 /*Filter pkt not to me*/
1283 multicast = is_multicast_ether_addr(hdr->addr1);
1284 unicast = !multicast;
1285 if (unicast && !ether_addr_equal(dev->dev_addr, hdr->addr1)) {
1286 if (ieee->bNetPromiscuousMode)
1292 /*Filter pkt has too small length */
1293 hdrlen = rtllib_rx_get_hdrlen(ieee, skb, rx_stats);
1294 if (skb->len < hdrlen) {
1295 printk(KERN_INFO "%s():ERR!!! skb->len is smaller than hdrlen\n", __func__);
1299 /* Filter Duplicate pkt */
1300 ret = rtllib_rx_check_duplicate(ieee, skb, multicast);
1304 /* Filter CTRL Frame */
1305 if (type == RTLLIB_FTYPE_CTL)
1308 /* Filter MGNT Frame */
1309 if (type == RTLLIB_FTYPE_MGMT) {
1312 if (rtllib_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1318 /* Filter WAPI DATA Frame */
1320 /* Update statstics for AP roaming */
1322 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1323 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1325 dev->last_rx = jiffies;
1327 /* Data frame - extract src/dst addresses */
1328 rtllib_rx_extract_addr(ieee, hdr, dst, src, bssid);
1330 /* Filter Data frames */
1331 ret = rtllib_rx_data_filter(ieee, fc, dst, src, bssid, hdr->addr2);
1335 if (skb->len == hdrlen)
1338 /* Send pspoll based on moredata */
1339 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == LPS_IS_SLEEP)
1340 && (ieee->polling) && (!bToOtherSTA)) {
1341 if (WLAN_FC_MORE_DATA(fc)) {
1342 /* more data bit is set, let's request a new frame from the AP */
1343 rtllib_sta_ps_send_pspoll_frame(ieee);
1345 ieee->polling = false;
1349 /* Get crypt if encrypted */
1350 ret = rtllib_rx_get_crypt(ieee, skb, &crypt, hdrlen);
1354 /* Decrypt data frame (including reassemble) */
1355 ret = rtllib_rx_decrypt(ieee, skb, rx_stats, crypt, hdrlen);
1361 /* Get TS for Rx Reorder */
1362 hdr = (struct rtllib_hdr_4addr *) skb->data;
1363 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1364 && !is_multicast_ether_addr(hdr->addr1)
1365 && (!bToOtherSTA)) {
1366 TID = Frame_QoSTID(skb->data);
1367 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1368 GetTs(ieee, (struct ts_common_info **) &pTS, hdr->addr2, TID, RX_DIR, true);
1369 if (TID != 0 && TID != 3)
1370 ieee->bis_any_nonbepkts = true;
1373 /* Parse rx data frame (For AMSDU) */
1374 /* skb: hdr + (possible reassembled) full plaintext payload */
1375 payload = skb->data + hdrlen;
1376 rxb = kmalloc(sizeof(struct rtllib_rxb), GFP_ATOMIC);
1378 RTLLIB_DEBUG(RTLLIB_DL_ERR,
1379 "%s(): kmalloc rxb error\n", __func__);
1382 /* to parse amsdu packets */
1383 /* qos data packets & reserved bit is 1 */
1384 if (parse_subframe(ieee, skb, rx_stats, rxb, src, dst) == 0) {
1385 /* only to free rxb, and not submit the packets to upper layer */
1386 for (i = 0; i < rxb->nr_subframes; i++)
1387 dev_kfree_skb(rxb->subframes[i]);
1393 /* Update WAPI PN */
1395 /* Check if leave LPS */
1397 if (ieee->bIsAggregateFrame)
1398 nr_subframes = rxb->nr_subframes;
1402 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod += nr_subframes;
1403 rtllib_rx_check_leave_lps(ieee, unicast, nr_subframes);
1406 /* Indicate packets to upper layer or Rx Reorder */
1407 if (ieee->pHTInfo->bCurRxReorderEnable == false || pTS == NULL || bToOtherSTA)
1408 rtllib_rx_indicate_pkt_legacy(ieee, rx_stats, rxb, dst, src);
1410 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1418 ieee->stats.rx_dropped++;
1420 /* Returning 0 indicates to caller that we have not handled the SKB--
1421 * so it is still allocated and can be used again by underlying
1422 * hardware as a DMA target */
1426 static int rtllib_rx_Master(struct rtllib_device *ieee, struct sk_buff *skb,
1427 struct rtllib_rx_stats *rx_stats)
1432 static int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb,
1433 struct rtllib_rx_stats *rx_stats)
1435 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1436 u16 fc = le16_to_cpu(hdr->frame_ctl);
1437 size_t hdrlen = rtllib_get_hdrlen(fc);
1439 if (skb->len < hdrlen) {
1440 printk(KERN_INFO "%s():ERR!!! skb->len is smaller than hdrlen\n", __func__);
1444 if (HTCCheck(ieee, skb->data)) {
1445 if (net_ratelimit())
1446 printk(KERN_INFO "%s: Find HTCControl!\n", __func__);
1450 rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
1451 ieee->stats.rx_packets++;
1452 ieee->stats.rx_bytes += skb->len;
1457 static int rtllib_rx_Mesh(struct rtllib_device *ieee, struct sk_buff *skb,
1458 struct rtllib_rx_stats *rx_stats)
1463 /* All received frames are sent to this function. @skb contains the frame in
1464 * IEEE 802.11 format, i.e., in the format it was sent over air.
1465 * This function is called only as a tasklet (software IRQ). */
1466 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1467 struct rtllib_rx_stats *rx_stats)
1471 if ((NULL == ieee) || (NULL == skb) || (NULL == rx_stats)) {
1472 printk(KERN_INFO "%s: Input parameters NULL!\n", __func__);
1475 if (skb->len < 10) {
1476 printk(KERN_INFO "%s: SKB length < 10\n", __func__);
1480 switch (ieee->iw_mode) {
1483 ret = rtllib_rx_InfraAdhoc(ieee, skb, rx_stats);
1485 case IW_MODE_MASTER:
1486 case IW_MODE_REPEAT:
1487 ret = rtllib_rx_Master(ieee, skb, rx_stats);
1489 case IW_MODE_MONITOR:
1490 ret = rtllib_rx_Monitor(ieee, skb, rx_stats);
1493 ret = rtllib_rx_Mesh(ieee, skb, rx_stats);
1496 printk(KERN_INFO"%s: ERR iw mode!!!\n", __func__);
1504 ieee->stats.rx_dropped++;
1507 EXPORT_SYMBOL(rtllib_rx);
1509 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1512 * Make ther structure we read from the beacon packet has
1515 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1516 *info_element, int sub_type)
1519 if (info_element->qui_subtype != sub_type)
1521 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1523 if (info_element->qui_type != QOS_OUI_TYPE)
1525 if (info_element->version != QOS_VERSION_1)
1533 * Parse a QoS parameter element
1535 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
1536 *element_param, struct rtllib_info_element
1540 u16 size = sizeof(struct rtllib_qos_parameter_info) - 2;
1542 if ((info_element == NULL) || (element_param == NULL))
1545 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1546 memcpy(element_param->info_element.qui, info_element->data,
1548 element_param->info_element.elementID = info_element->id;
1549 element_param->info_element.length = info_element->len;
1553 ret = rtllib_verify_qos_info(&element_param->info_element,
1554 QOS_OUI_PARAM_SUB_TYPE);
1559 * Parse a QoS information element
1561 static int rtllib_read_qos_info_element(struct
1562 rtllib_qos_information_element
1563 *element_info, struct rtllib_info_element
1567 u16 size = sizeof(struct rtllib_qos_information_element) - 2;
1569 if (element_info == NULL)
1571 if (info_element == NULL)
1574 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1575 memcpy(element_info->qui, info_element->data,
1577 element_info->elementID = info_element->id;
1578 element_info->length = info_element->len;
1583 ret = rtllib_verify_qos_info(element_info,
1584 QOS_OUI_INFO_SUB_TYPE);
1590 * Write QoS parameters from the ac parameters.
1592 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info *param_elm,
1593 struct rtllib_qos_data *qos_data)
1595 struct rtllib_qos_ac_parameter *ac_params;
1596 struct rtllib_qos_parameters *qos_param = &(qos_data->parameters);
1601 qos_data->wmm_acm = 0;
1602 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1603 ac_params = &(param_elm->ac_params_record[i]);
1605 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1606 acm = (ac_params->aci_aifsn & 0x10) >> 4;
1608 if (aci >= QOS_QUEUE_NUM)
1612 /* BIT(0) | BIT(3) */
1614 qos_data->wmm_acm |= (0x01<<0)|(0x01<<3);
1617 /* BIT(4) | BIT(5) */
1619 qos_data->wmm_acm |= (0x01<<4)|(0x01<<5);
1622 /* BIT(6) | BIT(7) */
1624 qos_data->wmm_acm |= (0x01<<6)|(0x01<<7);
1628 /* BIT(1) | BIT(2) */
1630 qos_data->wmm_acm |= (0x01<<1)|(0x01<<2);
1634 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1636 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1637 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2 : qos_param->aifs[aci];
1639 qos_param->cw_min[aci] = cpu_to_le16(ac_params->ecw_min_max & 0x0F);
1641 qos_param->cw_max[aci] = cpu_to_le16((ac_params->ecw_min_max & 0xF0) >> 4);
1643 qos_param->flag[aci] =
1644 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1645 qos_param->tx_op_limit[aci] = ac_params->tx_op_limit;
1651 * we have a generic data element which it may contain QoS information or
1652 * parameters element. check the information element length to decide
1653 * which type to read
1655 static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
1657 struct rtllib_network *network)
1660 struct rtllib_qos_information_element qos_info_element;
1662 rc = rtllib_read_qos_info_element(&qos_info_element, info_element);
1665 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1666 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1668 struct rtllib_qos_parameter_info param_element;
1670 rc = rtllib_read_qos_param_element(¶m_element,
1673 rtllib_qos_convert_ac_to_parameters(¶m_element,
1674 &(network->qos_data));
1675 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1676 network->qos_data.param_count =
1677 param_element.info_element.ac_info & 0x0F;
1682 RTLLIB_DEBUG_QOS("QoS is supported\n");
1683 network->qos_data.supported = 1;
1688 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1690 static const char *get_info_element_string(u16 id)
1695 MFIE_STRING(FH_SET);
1696 MFIE_STRING(DS_SET);
1697 MFIE_STRING(CF_SET);
1699 MFIE_STRING(IBSS_SET);
1700 MFIE_STRING(COUNTRY);
1701 MFIE_STRING(HOP_PARAMS);
1702 MFIE_STRING(HOP_TABLE);
1703 MFIE_STRING(REQUEST);
1704 MFIE_STRING(CHALLENGE);
1705 MFIE_STRING(POWER_CONSTRAINT);
1706 MFIE_STRING(POWER_CAPABILITY);
1707 MFIE_STRING(TPC_REQUEST);
1708 MFIE_STRING(TPC_REPORT);
1709 MFIE_STRING(SUPP_CHANNELS);
1711 MFIE_STRING(MEASURE_REQUEST);
1712 MFIE_STRING(MEASURE_REPORT);
1714 MFIE_STRING(IBSS_DFS);
1716 MFIE_STRING(RATES_EX);
1717 MFIE_STRING(GENERIC);
1718 MFIE_STRING(QOS_PARAMETER);
1724 static inline void rtllib_extract_country_ie(
1725 struct rtllib_device *ieee,
1726 struct rtllib_info_element *info_element,
1727 struct rtllib_network *network,
1730 if (IS_DOT11D_ENABLE(ieee)) {
1731 if (info_element->len != 0) {
1732 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1733 network->CountryIeLen = info_element->len;
1735 if (!IS_COUNTRY_IE_VALID(ieee)) {
1736 if (rtllib_act_scanning(ieee, false) && ieee->FirstIe_InScan)
1737 printk(KERN_INFO "Received beacon ContryIE, SSID: <%s>\n", network->ssid);
1738 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1742 if (IS_EQUAL_CIE_SRC(ieee, addr2))
1743 UPDATE_CIE_WATCHDOG(ieee);
1748 int rtllib_parse_info_param(struct rtllib_device *ieee,
1749 struct rtllib_info_element *info_element,
1751 struct rtllib_network *network,
1752 struct rtllib_rx_stats *stats)
1756 u16 tmp_htcap_len = 0;
1757 u16 tmp_htinfo_len = 0;
1758 u16 ht_realtek_agg_len = 0;
1759 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1763 while (length >= sizeof(*info_element)) {
1764 if (sizeof(*info_element) + info_element->len > length) {
1765 RTLLIB_DEBUG_MGMT("Info elem: parse failed: "
1766 "info_element->len + 2 > left : "
1767 "info_element->len+2=%zd left=%d, id=%d.\n",
1769 sizeof(*info_element),
1770 length, info_element->id);
1771 /* We stop processing but don't return an error here
1772 * because some misbehaviour APs break this rule. ie.
1773 * Orinoco AP1000. */
1777 switch (info_element->id) {
1778 case MFIE_TYPE_SSID:
1779 if (rtllib_is_empty_essid(info_element->data,
1780 info_element->len)) {
1781 network->flags |= NETWORK_EMPTY_ESSID;
1785 network->ssid_len = min(info_element->len,
1786 (u8) IW_ESSID_MAX_SIZE);
1787 memcpy(network->ssid, info_element->data, network->ssid_len);
1788 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1789 memset(network->ssid + network->ssid_len, 0,
1790 IW_ESSID_MAX_SIZE - network->ssid_len);
1792 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1793 network->ssid, network->ssid_len);
1796 case MFIE_TYPE_RATES:
1798 network->rates_len = min(info_element->len,
1800 for (i = 0; i < network->rates_len; i++) {
1801 network->rates[i] = info_element->data[i];
1802 p += snprintf(p, sizeof(rates_str) -
1803 (p - rates_str), "%02X ",
1805 if (rtllib_is_ofdm_rate
1806 (info_element->data[i])) {
1807 network->flags |= NETWORK_HAS_OFDM;
1808 if (info_element->data[i] &
1809 RTLLIB_BASIC_RATE_MASK)
1814 if (rtllib_is_cck_rate
1815 (info_element->data[i])) {
1816 network->flags |= NETWORK_HAS_CCK;
1820 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1821 rates_str, network->rates_len);
1824 case MFIE_TYPE_RATES_EX:
1826 network->rates_ex_len = min(info_element->len,
1827 MAX_RATES_EX_LENGTH);
1828 for (i = 0; i < network->rates_ex_len; i++) {
1829 network->rates_ex[i] = info_element->data[i];
1830 p += snprintf(p, sizeof(rates_str) -
1831 (p - rates_str), "%02X ",
1832 network->rates_ex[i]);
1833 if (rtllib_is_ofdm_rate
1834 (info_element->data[i])) {
1835 network->flags |= NETWORK_HAS_OFDM;
1836 if (info_element->data[i] &
1837 RTLLIB_BASIC_RATE_MASK)
1843 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1844 rates_str, network->rates_ex_len);
1847 case MFIE_TYPE_DS_SET:
1848 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1849 info_element->data[0]);
1850 network->channel = info_element->data[0];
1853 case MFIE_TYPE_FH_SET:
1854 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1857 case MFIE_TYPE_CF_SET:
1858 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1862 if (info_element->len < 4)
1865 network->tim.tim_count = info_element->data[0];
1866 network->tim.tim_period = info_element->data[1];
1868 network->dtim_period = info_element->data[1];
1869 if (ieee->state != RTLLIB_LINKED)
1871 network->last_dtim_sta_time = jiffies;
1873 network->dtim_data = RTLLIB_DTIM_VALID;
1876 if (info_element->data[2] & 1)
1877 network->dtim_data |= RTLLIB_DTIM_MBCAST;
1879 offset = (info_element->data[2] >> 1)*2;
1882 if (ieee->assoc_id < 8*offset ||
1883 ieee->assoc_id > 8*(offset + info_element->len - 3))
1886 offset = (ieee->assoc_id / 8) - offset;
1887 if (info_element->data[3 + offset] &
1888 (1 << (ieee->assoc_id % 8)))
1889 network->dtim_data |= RTLLIB_DTIM_UCAST;
1891 network->listen_interval = network->dtim_period;
1895 network->erp_value = info_element->data[0];
1896 network->flags |= NETWORK_HAS_ERP_VALUE;
1897 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1898 network->erp_value);
1900 case MFIE_TYPE_IBSS_SET:
1901 network->atim_window = info_element->data[0];
1902 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1903 network->atim_window);
1906 case MFIE_TYPE_CHALLENGE:
1907 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1910 case MFIE_TYPE_GENERIC:
1911 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1913 if (!rtllib_parse_qos_info_param_IE(info_element,
1916 if (info_element->len >= 4 &&
1917 info_element->data[0] == 0x00 &&
1918 info_element->data[1] == 0x50 &&
1919 info_element->data[2] == 0xf2 &&
1920 info_element->data[3] == 0x01) {
1921 network->wpa_ie_len = min(info_element->len + 2,
1923 memcpy(network->wpa_ie, info_element,
1924 network->wpa_ie_len);
1927 if (info_element->len == 7 &&
1928 info_element->data[0] == 0x00 &&
1929 info_element->data[1] == 0xe0 &&
1930 info_element->data[2] == 0x4c &&
1931 info_element->data[3] == 0x01 &&
1932 info_element->data[4] == 0x02)
1933 network->Turbo_Enable = 1;
1935 if (tmp_htcap_len == 0) {
1936 if (info_element->len >= 4 &&
1937 info_element->data[0] == 0x00 &&
1938 info_element->data[1] == 0x90 &&
1939 info_element->data[2] == 0x4c &&
1940 info_element->data[3] == 0x033) {
1942 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
1943 if (tmp_htcap_len != 0) {
1944 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1945 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ?
1946 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
1947 memcpy(network->bssht.bdHTCapBuf, info_element->data, network->bssht.bdHTCapLen);
1950 if (tmp_htcap_len != 0) {
1951 network->bssht.bdSupportHT = true;
1952 network->bssht.bdHT1R = ((((struct ht_capab_ele *)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1954 network->bssht.bdSupportHT = false;
1955 network->bssht.bdHT1R = false;
1960 if (tmp_htinfo_len == 0) {
1961 if (info_element->len >= 4 &&
1962 info_element->data[0] == 0x00 &&
1963 info_element->data[1] == 0x90 &&
1964 info_element->data[2] == 0x4c &&
1965 info_element->data[3] == 0x034) {
1966 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
1967 if (tmp_htinfo_len != 0) {
1968 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1969 if (tmp_htinfo_len) {
1970 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf) ?
1971 sizeof(network->bssht.bdHTInfoBuf) : tmp_htinfo_len;
1972 memcpy(network->bssht.bdHTInfoBuf, info_element->data, network->bssht.bdHTInfoLen);
1980 if (ieee->aggregation) {
1981 if (network->bssht.bdSupportHT) {
1982 if (info_element->len >= 4 &&
1983 info_element->data[0] == 0x00 &&
1984 info_element->data[1] == 0xe0 &&
1985 info_element->data[2] == 0x4c &&
1986 info_element->data[3] == 0x02) {
1987 ht_realtek_agg_len = min(info_element->len, (u8)MAX_IE_LEN);
1988 memcpy(ht_realtek_agg_buf, info_element->data, info_element->len);
1990 if (ht_realtek_agg_len >= 5) {
1991 network->realtek_cap_exit = true;
1992 network->bssht.bdRT2RTAggregation = true;
1994 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1995 network->bssht.bdRT2RTLongSlotTime = true;
1997 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
1998 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
2001 if (ht_realtek_agg_len >= 5) {
2002 if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
2003 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_SOFTAP;
2007 if ((info_element->len >= 3 &&
2008 info_element->data[0] == 0x00 &&
2009 info_element->data[1] == 0x05 &&
2010 info_element->data[2] == 0xb5) ||
2011 (info_element->len >= 3 &&
2012 info_element->data[0] == 0x00 &&
2013 info_element->data[1] == 0x0a &&
2014 info_element->data[2] == 0xf7) ||
2015 (info_element->len >= 3 &&
2016 info_element->data[0] == 0x00 &&
2017 info_element->data[1] == 0x10 &&
2018 info_element->data[2] == 0x18)) {
2019 network->broadcom_cap_exist = true;
2021 if (info_element->len >= 3 &&
2022 info_element->data[0] == 0x00 &&
2023 info_element->data[1] == 0x0c &&
2024 info_element->data[2] == 0x43)
2025 network->ralink_cap_exist = true;
2026 if ((info_element->len >= 3 &&
2027 info_element->data[0] == 0x00 &&
2028 info_element->data[1] == 0x03 &&
2029 info_element->data[2] == 0x7f) ||
2030 (info_element->len >= 3 &&
2031 info_element->data[0] == 0x00 &&
2032 info_element->data[1] == 0x13 &&
2033 info_element->data[2] == 0x74))
2034 network->atheros_cap_exist = true;
2036 if ((info_element->len >= 3 &&
2037 info_element->data[0] == 0x00 &&
2038 info_element->data[1] == 0x50 &&
2039 info_element->data[2] == 0x43))
2040 network->marvell_cap_exist = true;
2041 if (info_element->len >= 3 &&
2042 info_element->data[0] == 0x00 &&
2043 info_element->data[1] == 0x40 &&
2044 info_element->data[2] == 0x96)
2045 network->cisco_cap_exist = true;
2048 if (info_element->len >= 3 &&
2049 info_element->data[0] == 0x00 &&
2050 info_element->data[1] == 0x0a &&
2051 info_element->data[2] == 0xf5)
2052 network->airgo_cap_exist = true;
2054 if (info_element->len > 4 &&
2055 info_element->data[0] == 0x00 &&
2056 info_element->data[1] == 0x40 &&
2057 info_element->data[2] == 0x96 &&
2058 info_element->data[3] == 0x01) {
2059 if (info_element->len == 6) {
2060 memcpy(network->CcxRmState, &info_element[4], 2);
2061 if (network->CcxRmState[0] != 0)
2062 network->bCcxRmEnable = true;
2064 network->bCcxRmEnable = false;
2065 network->MBssidMask = network->CcxRmState[1] & 0x07;
2066 if (network->MBssidMask != 0) {
2067 network->bMBssidValid = true;
2068 network->MBssidMask = 0xff << (network->MBssidMask);
2069 memcpy(network->MBssid, network->bssid, ETH_ALEN);
2070 network->MBssid[5] &= network->MBssidMask;
2072 network->bMBssidValid = false;
2075 network->bCcxRmEnable = false;
2078 if (info_element->len > 4 &&
2079 info_element->data[0] == 0x00 &&
2080 info_element->data[1] == 0x40 &&
2081 info_element->data[2] == 0x96 &&
2082 info_element->data[3] == 0x03) {
2083 if (info_element->len == 5) {
2084 network->bWithCcxVerNum = true;
2085 network->BssCcxVerNumber = info_element->data[4];
2087 network->bWithCcxVerNum = false;
2088 network->BssCcxVerNumber = 0;
2091 if (info_element->len > 4 &&
2092 info_element->data[0] == 0x00 &&
2093 info_element->data[1] == 0x50 &&
2094 info_element->data[2] == 0xf2 &&
2095 info_element->data[3] == 0x04) {
2096 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
2098 network->wzc_ie_len = min(info_element->len+2,
2100 memcpy(network->wzc_ie, info_element,
2101 network->wzc_ie_len);
2106 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2108 network->rsn_ie_len = min(info_element->len + 2,
2110 memcpy(network->rsn_ie, info_element,
2111 network->rsn_ie_len);
2114 case MFIE_TYPE_HT_CAP:
2115 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2117 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
2118 if (tmp_htcap_len != 0) {
2119 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2120 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ?
2121 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
2122 memcpy(network->bssht.bdHTCapBuf,
2124 network->bssht.bdHTCapLen);
2126 network->bssht.bdSupportHT = true;
2127 network->bssht.bdHT1R = ((((struct ht_capab_ele *)
2128 network->bssht.bdHTCapBuf))->MCS[1]) == 0;
2130 network->bssht.bdBandWidth = (enum ht_channel_width)
2131 (((struct ht_capab_ele *)
2132 (network->bssht.bdHTCapBuf))->ChlWidth);
2134 network->bssht.bdSupportHT = false;
2135 network->bssht.bdHT1R = false;
2136 network->bssht.bdBandWidth = HT_CHANNEL_WIDTH_20;
2141 case MFIE_TYPE_HT_INFO:
2142 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2144 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
2145 if (tmp_htinfo_len) {
2146 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2147 network->bssht.bdHTInfoLen = tmp_htinfo_len >
2148 sizeof(network->bssht.bdHTInfoBuf) ?
2149 sizeof(network->bssht.bdHTInfoBuf) :
2151 memcpy(network->bssht.bdHTInfoBuf,
2153 network->bssht.bdHTInfoLen);
2157 case MFIE_TYPE_AIRONET:
2158 RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2160 if (info_element->len > IE_CISCO_FLAG_POSITION) {
2161 network->bWithAironetIE = true;
2163 if ((info_element->data[IE_CISCO_FLAG_POSITION]
2164 & SUPPORT_CKIP_MIC) ||
2165 (info_element->data[IE_CISCO_FLAG_POSITION]
2167 network->bCkipSupported = true;
2169 network->bCkipSupported = false;
2171 network->bWithAironetIE = false;
2172 network->bCkipSupported = false;
2175 case MFIE_TYPE_QOS_PARAMETER:
2177 "QoS Error need to parse QOS_PARAMETER IE\n");
2180 case MFIE_TYPE_COUNTRY:
2181 RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2183 rtllib_extract_country_ie(ieee, info_element, network,
2189 ("Unsupported info element: %s (%d)\n",
2190 get_info_element_string(info_element->id),
2195 length -= sizeof(*info_element) + info_element->len;
2197 (struct rtllib_info_element *)&info_element->
2198 data[info_element->len];
2201 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2202 !network->cisco_cap_exist && !network->ralink_cap_exist &&
2203 !network->bssht.bdRT2RTAggregation)
2204 network->unknown_cap_exist = true;
2206 network->unknown_cap_exist = false;
2210 static inline u8 rtllib_SignalStrengthTranslate(u8 CurrSS)
2214 if (CurrSS >= 71 && CurrSS <= 100)
2215 RetSS = 90 + ((CurrSS - 70) / 3);
2216 else if (CurrSS >= 41 && CurrSS <= 70)
2217 RetSS = 78 + ((CurrSS - 40) / 3);
2218 else if (CurrSS >= 31 && CurrSS <= 40)
2219 RetSS = 66 + (CurrSS - 30);
2220 else if (CurrSS >= 21 && CurrSS <= 30)
2221 RetSS = 54 + (CurrSS - 20);
2222 else if (CurrSS >= 5 && CurrSS <= 20)
2223 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2224 else if (CurrSS == 4)
2226 else if (CurrSS == 3)
2228 else if (CurrSS == 2)
2230 else if (CurrSS == 1)
2238 static long rtllib_translate_todbm(u8 signal_strength_index)
2242 signal_power = (long)((signal_strength_index + 1) >> 1);
2245 return signal_power;
2248 static inline int rtllib_network_init(
2249 struct rtllib_device *ieee,
2250 struct rtllib_probe_response *beacon,
2251 struct rtllib_network *network,
2252 struct rtllib_rx_stats *stats)
2256 network->qos_data.active = 0;
2257 network->qos_data.supported = 0;
2258 network->qos_data.param_count = 0;
2259 network->qos_data.old_param_count = 0;
2261 memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
2263 /* Pull out fixed field data */
2264 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2265 network->capability = le16_to_cpu(beacon->capability);
2266 network->last_scanned = jiffies;
2267 network->time_stamp[0] = beacon->time_stamp[0];
2268 network->time_stamp[1] = beacon->time_stamp[1];
2269 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
2270 /* Where to pull this? beacon->listen_interval;*/
2271 network->listen_interval = 0x0A;
2272 network->rates_len = network->rates_ex_len = 0;
2273 network->last_associate = 0;
2274 network->ssid_len = 0;
2275 network->hidden_ssid_len = 0;
2276 memset(network->hidden_ssid, 0, sizeof(network->hidden_ssid));
2278 network->atim_window = 0;
2279 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2281 network->berp_info_valid = false;
2282 network->broadcom_cap_exist = false;
2283 network->ralink_cap_exist = false;
2284 network->atheros_cap_exist = false;
2285 network->cisco_cap_exist = false;
2286 network->unknown_cap_exist = false;
2287 network->realtek_cap_exit = false;
2288 network->marvell_cap_exist = false;
2289 network->airgo_cap_exist = false;
2290 network->Turbo_Enable = 0;
2291 network->SignalStrength = stats->SignalStrength;
2292 network->RSSI = stats->SignalStrength;
2293 network->CountryIeLen = 0;
2294 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2295 HTInitializeBssDesc(&network->bssht);
2296 if (stats->freq == RTLLIB_52GHZ_BAND) {
2297 /* for A band (No DS info) */
2298 network->channel = stats->received_channel;
2300 network->flags |= NETWORK_HAS_CCK;
2302 network->wpa_ie_len = 0;
2303 network->rsn_ie_len = 0;
2304 network->wzc_ie_len = 0;
2306 if (rtllib_parse_info_param(ieee,
2307 beacon->info_element,
2308 (stats->len - sizeof(*beacon)),
2314 if (stats->freq == RTLLIB_52GHZ_BAND)
2315 network->mode = IEEE_A;
2317 if (network->flags & NETWORK_HAS_OFDM)
2318 network->mode |= IEEE_G;
2319 if (network->flags & NETWORK_HAS_CCK)
2320 network->mode |= IEEE_B;
2323 if (network->mode == 0) {
2324 RTLLIB_DEBUG_SCAN("Filtered out '%s (%pM)' "
2326 escape_essid(network->ssid,
2332 if (network->bssht.bdSupportHT) {
2333 if (network->mode == IEEE_A)
2334 network->mode = IEEE_N_5G;
2335 else if (network->mode & (IEEE_G | IEEE_B))
2336 network->mode = IEEE_N_24G;
2338 if (rtllib_is_empty_essid(network->ssid, network->ssid_len))
2339 network->flags |= NETWORK_EMPTY_ESSID;
2340 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2341 stats->noise = rtllib_translate_todbm((u8)(100-stats->signal)) - 25;
2343 memcpy(&network->stats, stats, sizeof(network->stats));
2348 static inline int is_same_network(struct rtllib_network *src,
2349 struct rtllib_network *dst, u8 ssidbroad)
2351 /* A network is only a duplicate if the channel, BSSID, ESSID
2352 * and the capability field (in particular IBSS and BSS) all match.
2353 * We treat all <hidden> with the same BSSID and channel
2355 return (((src->ssid_len == dst->ssid_len) || (!ssidbroad)) &&
2356 (src->channel == dst->channel) &&
2357 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2358 (!memcmp(src->ssid, dst->ssid, src->ssid_len) ||
2360 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2361 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2362 ((src->capability & WLAN_CAPABILITY_ESS) ==
2363 (dst->capability & WLAN_CAPABILITY_ESS)));
2366 static inline void update_ibss_network(struct rtllib_network *dst,
2367 struct rtllib_network *src)
2369 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
2370 dst->last_scanned = jiffies;
2374 static inline void update_network(struct rtllib_network *dst,
2375 struct rtllib_network *src)
2380 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
2381 dst->capability = src->capability;
2382 memcpy(dst->rates, src->rates, src->rates_len);
2383 dst->rates_len = src->rates_len;
2384 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2385 dst->rates_ex_len = src->rates_ex_len;
2386 if (src->ssid_len > 0) {
2387 if (dst->ssid_len == 0) {
2388 memset(dst->hidden_ssid, 0, sizeof(dst->hidden_ssid));
2389 dst->hidden_ssid_len = src->ssid_len;
2390 memcpy(dst->hidden_ssid, src->ssid, src->ssid_len);
2392 memset(dst->ssid, 0, dst->ssid_len);
2393 dst->ssid_len = src->ssid_len;
2394 memcpy(dst->ssid, src->ssid, src->ssid_len);
2397 dst->mode = src->mode;
2398 dst->flags = src->flags;
2399 dst->time_stamp[0] = src->time_stamp[0];
2400 dst->time_stamp[1] = src->time_stamp[1];
2401 if (src->flags & NETWORK_HAS_ERP_VALUE) {
2402 dst->erp_value = src->erp_value;
2403 dst->berp_info_valid = src->berp_info_valid = true;
2405 dst->beacon_interval = src->beacon_interval;
2406 dst->listen_interval = src->listen_interval;
2407 dst->atim_window = src->atim_window;
2408 dst->dtim_period = src->dtim_period;
2409 dst->dtim_data = src->dtim_data;
2410 dst->last_dtim_sta_time = src->last_dtim_sta_time;
2411 memcpy(&dst->tim, &src->tim, sizeof(struct rtllib_tim_parameters));
2413 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2414 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2415 dst->bssht.bdHTCapLen = src->bssht.bdHTCapLen;
2416 memcpy(dst->bssht.bdHTCapBuf, src->bssht.bdHTCapBuf,
2417 src->bssht.bdHTCapLen);
2418 dst->bssht.bdHTInfoLen = src->bssht.bdHTInfoLen;
2419 memcpy(dst->bssht.bdHTInfoBuf, src->bssht.bdHTInfoBuf,
2420 src->bssht.bdHTInfoLen);
2421 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2422 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2423 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2424 dst->ralink_cap_exist = src->ralink_cap_exist;
2425 dst->atheros_cap_exist = src->atheros_cap_exist;
2426 dst->realtek_cap_exit = src->realtek_cap_exit;
2427 dst->marvell_cap_exist = src->marvell_cap_exist;
2428 dst->cisco_cap_exist = src->cisco_cap_exist;
2429 dst->airgo_cap_exist = src->airgo_cap_exist;
2430 dst->unknown_cap_exist = src->unknown_cap_exist;
2431 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2432 dst->wpa_ie_len = src->wpa_ie_len;
2433 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2434 dst->rsn_ie_len = src->rsn_ie_len;
2435 memcpy(dst->wzc_ie, src->wzc_ie, src->wzc_ie_len);
2436 dst->wzc_ie_len = src->wzc_ie_len;
2438 dst->last_scanned = jiffies;
2439 /* qos related parameters */
2440 qos_active = dst->qos_data.active;
2441 old_param = dst->qos_data.param_count;
2442 dst->qos_data.supported = src->qos_data.supported;
2443 if (dst->flags & NETWORK_HAS_QOS_PARAMETERS)
2444 memcpy(&dst->qos_data, &src->qos_data,
2445 sizeof(struct rtllib_qos_data));
2446 if (dst->qos_data.supported == 1) {
2449 ("QoS the network %s is QoS supported\n",
2453 ("QoS the network is QoS supported\n");
2455 dst->qos_data.active = qos_active;
2456 dst->qos_data.old_param_count = old_param;
2458 /* dst->last_associate is not overwritten */
2459 dst->wmm_info = src->wmm_info;
2460 if (src->wmm_param[0].ac_aci_acm_aifsn ||
2461 src->wmm_param[1].ac_aci_acm_aifsn ||
2462 src->wmm_param[2].ac_aci_acm_aifsn ||
2463 src->wmm_param[3].ac_aci_acm_aifsn)
2464 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2466 dst->SignalStrength = src->SignalStrength;
2467 dst->RSSI = src->RSSI;
2468 dst->Turbo_Enable = src->Turbo_Enable;
2470 dst->CountryIeLen = src->CountryIeLen;
2471 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2473 dst->bWithAironetIE = src->bWithAironetIE;
2474 dst->bCkipSupported = src->bCkipSupported;
2475 memcpy(dst->CcxRmState, src->CcxRmState, 2);
2476 dst->bCcxRmEnable = src->bCcxRmEnable;
2477 dst->MBssidMask = src->MBssidMask;
2478 dst->bMBssidValid = src->bMBssidValid;
2479 memcpy(dst->MBssid, src->MBssid, 6);
2480 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2481 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2484 static inline int is_beacon(__le16 fc)
2486 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == RTLLIB_STYPE_BEACON);
2489 static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
2491 if (MAX_CHANNEL_NUMBER < channel) {
2492 printk(KERN_INFO "%s(): Invalid Channel\n", __func__);
2496 if (rtllib->active_channel_map[channel] == 2)
2502 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel)
2504 if (MAX_CHANNEL_NUMBER < channel) {
2505 printk(KERN_INFO "%s(): Invalid Channel\n", __func__);
2508 if (rtllib->active_channel_map[channel] > 0)
2513 EXPORT_SYMBOL(rtllib_legal_channel);
2515 static inline void rtllib_process_probe_response(
2516 struct rtllib_device *ieee,
2517 struct rtllib_probe_response *beacon,
2518 struct rtllib_rx_stats *stats)
2520 struct rtllib_network *target;
2521 struct rtllib_network *oldest = NULL;
2522 struct rtllib_info_element *info_element = &beacon->info_element[0];
2523 unsigned long flags;
2525 struct rtllib_network *network = kzalloc(sizeof(struct rtllib_network),
2532 "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2533 escape_essid(info_element->data, info_element->len),
2534 beacon->header.addr3,
2535 (le16_to_cpu(beacon->capability) & (1<<0xf)) ? '1' : '0',
2536 (le16_to_cpu(beacon->capability) & (1<<0xe)) ? '1' : '0',
2537 (le16_to_cpu(beacon->capability) & (1<<0xd)) ? '1' : '0',
2538 (le16_to_cpu(beacon->capability) & (1<<0xc)) ? '1' : '0',
2539 (le16_to_cpu(beacon->capability) & (1<<0xb)) ? '1' : '0',
2540 (le16_to_cpu(beacon->capability) & (1<<0xa)) ? '1' : '0',
2541 (le16_to_cpu(beacon->capability) & (1<<0x9)) ? '1' : '0',
2542 (le16_to_cpu(beacon->capability) & (1<<0x8)) ? '1' : '0',
2543 (le16_to_cpu(beacon->capability) & (1<<0x7)) ? '1' : '0',
2544 (le16_to_cpu(beacon->capability) & (1<<0x6)) ? '1' : '0',
2545 (le16_to_cpu(beacon->capability) & (1<<0x5)) ? '1' : '0',
2546 (le16_to_cpu(beacon->capability) & (1<<0x4)) ? '1' : '0',
2547 (le16_to_cpu(beacon->capability) & (1<<0x3)) ? '1' : '0',
2548 (le16_to_cpu(beacon->capability) & (1<<0x2)) ? '1' : '0',
2549 (le16_to_cpu(beacon->capability) & (1<<0x1)) ? '1' : '0',
2550 (le16_to_cpu(beacon->capability) & (1<<0x0)) ? '1' : '0');
2552 if (rtllib_network_init(ieee, beacon, network, stats)) {
2553 RTLLIB_DEBUG_SCAN("Dropped '%s' ( %pM) via %s.\n",
2554 escape_essid(info_element->data,
2556 beacon->header.addr3,
2558 le16_to_cpu(beacon->header.frame_ctl)) ==
2559 RTLLIB_STYPE_PROBE_RESP ?
2560 "PROBE RESPONSE" : "BEACON");
2565 if (!rtllib_legal_channel(ieee, network->channel))
2568 if (WLAN_FC_GET_STYPE(le16_to_cpu(beacon->header.frame_ctl)) ==
2569 RTLLIB_STYPE_PROBE_RESP) {
2570 if (IsPassiveChannel(ieee, network->channel)) {
2571 printk(KERN_INFO "GetScanInfo(): For Global Domain, "
2572 "filter probe response at channel(%d).\n",
2578 /* The network parsed correctly -- so now we scan our known networks
2579 * to see if we can find it in our list.
2581 * NOTE: This search is definitely not optimized. Once its doing
2582 * the "right thing" we'll optimize it for efficiency if
2585 /* Search for this entry in the list and update it if it is
2588 spin_lock_irqsave(&ieee->lock, flags);
2589 if (is_same_network(&ieee->current_network, network,
2590 (network->ssid_len ? 1 : 0))) {
2591 update_network(&ieee->current_network, network);
2592 if ((ieee->current_network.mode == IEEE_N_24G ||
2593 ieee->current_network.mode == IEEE_G)
2594 && ieee->current_network.berp_info_valid) {
2595 if (ieee->current_network.erp_value & ERP_UseProtection)
2596 ieee->current_network.buseprotection = true;
2598 ieee->current_network.buseprotection = false;
2600 if (is_beacon(beacon->header.frame_ctl)) {
2601 if (ieee->state >= RTLLIB_LINKED)
2602 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2605 list_for_each_entry(target, &ieee->network_list, list) {
2606 if (is_same_network(target, network,
2607 (target->ssid_len ? 1 : 0)))
2609 if ((oldest == NULL) ||
2610 (target->last_scanned < oldest->last_scanned))
2614 /* If we didn't find a match, then get a new network slot to initialize
2615 * with this beacon's information */
2616 if (&target->list == &ieee->network_list) {
2617 if (list_empty(&ieee->network_free_list)) {
2618 /* If there are no more slots, expire the oldest */
2619 list_del(&oldest->list);
2621 RTLLIB_DEBUG_SCAN("Expired '%s' ( %pM) from "
2623 escape_essid(target->ssid,
2627 /* Otherwise just pull from the free list */
2628 target = list_entry(ieee->network_free_list.next,
2629 struct rtllib_network, list);
2630 list_del(ieee->network_free_list.next);
2634 RTLLIB_DEBUG_SCAN("Adding '%s' ( %pM) via %s.\n",
2635 escape_essid(network->ssid,
2636 network->ssid_len), network->bssid,
2638 le16_to_cpu(beacon->header.frame_ctl)) ==
2639 RTLLIB_STYPE_PROBE_RESP ?
2640 "PROBE RESPONSE" : "BEACON");
2641 memcpy(target, network, sizeof(*target));
2642 list_add_tail(&target->list, &ieee->network_list);
2643 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2644 rtllib_softmac_new_net(ieee, network);
2646 RTLLIB_DEBUG_SCAN("Updating '%s' ( %pM) via %s.\n",
2647 escape_essid(target->ssid,
2648 target->ssid_len), target->bssid,
2650 le16_to_cpu(beacon->header.frame_ctl)) ==
2651 RTLLIB_STYPE_PROBE_RESP ?
2652 "PROBE RESPONSE" : "BEACON");
2654 /* we have an entry and we are going to update it. But this
2655 * entry may be already expired. In this case we do the same
2656 * as we found a new net and call the new_net handler
2658 renew = !time_after(target->last_scanned + ieee->scan_age,
2660 if ((!target->ssid_len) &&
2661 (((network->ssid_len > 0) && (target->hidden_ssid_len == 0))
2662 || ((ieee->current_network.ssid_len == network->ssid_len) &&
2663 (strncmp(ieee->current_network.ssid, network->ssid,
2664 network->ssid_len) == 0) &&
2665 (ieee->state == RTLLIB_NOLINK))))
2667 update_network(target, network);
2668 if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2669 rtllib_softmac_new_net(ieee, network);
2672 spin_unlock_irqrestore(&ieee->lock, flags);
2673 if (is_beacon(beacon->header.frame_ctl) &&
2674 is_same_network(&ieee->current_network, network,
2675 (network->ssid_len ? 1 : 0)) &&
2676 (ieee->state == RTLLIB_LINKED)) {
2677 if (ieee->handle_beacon != NULL)
2678 ieee->handle_beacon(ieee->dev, beacon,
2679 &ieee->current_network);
2686 void rtllib_rx_mgt(struct rtllib_device *ieee,
2687 struct sk_buff *skb,
2688 struct rtllib_rx_stats *stats)
2690 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data;
2692 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) !=
2693 RTLLIB_STYPE_PROBE_RESP) &&
2694 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) !=
2695 RTLLIB_STYPE_BEACON))
2696 ieee->last_rx_ps_time = jiffies;
2698 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
2700 case RTLLIB_STYPE_BEACON:
2701 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
2702 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2703 RTLLIB_DEBUG_SCAN("Beacon\n");
2704 rtllib_process_probe_response(
2705 ieee, (struct rtllib_probe_response *)header,
2708 if (ieee->sta_sleep || (ieee->ps != RTLLIB_PS_DISABLED &&
2709 ieee->iw_mode == IW_MODE_INFRA &&
2710 ieee->state == RTLLIB_LINKED))
2711 tasklet_schedule(&ieee->ps_task);
2715 case RTLLIB_STYPE_PROBE_RESP:
2716 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2717 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2718 RTLLIB_DEBUG_SCAN("Probe response\n");
2719 rtllib_process_probe_response(ieee,
2720 (struct rtllib_probe_response *)header, stats);
2722 case RTLLIB_STYPE_PROBE_REQ:
2723 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
2725 le16_to_cpu(header->frame_ctl)));
2726 RTLLIB_DEBUG_SCAN("Probe request\n");
2727 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2728 ((ieee->iw_mode == IW_MODE_ADHOC ||
2729 ieee->iw_mode == IW_MODE_MASTER) &&
2730 ieee->state == RTLLIB_LINKED))
2731 rtllib_rx_probe_rq(ieee, skb);