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 <andreamrl@tiscali.it>
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/version.h>
40 #include <linux/wireless.h>
41 #include <linux/etherdevice.h>
42 #include <linux/uaccess.h>
43 #include <linux/ctype.h>
48 static inline void rtllib_monitor_rx(struct rtllib_device *ieee,
49 struct sk_buff *skb, 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 = __constant_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 "
75 "seq=%u last_frag=%u\n",
76 entry->seq, entry->last_frag);
77 dev_kfree_skb_any(entry->skb);
81 if (entry->skb != NULL && entry->seq == seq &&
82 (entry->last_frag + 1 == frag || frag == -1) &&
83 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
84 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
91 /* Called only as a tasklet (software IRQ) */
92 static struct sk_buff *
93 rtllib_frag_cache_get(struct rtllib_device *ieee,
94 struct rtllib_hdr_4addr *hdr)
96 struct sk_buff *skb = NULL;
97 u16 fc = le16_to_cpu(hdr->frame_ctl);
98 u16 sc = le16_to_cpu(hdr->seq_ctl);
99 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
100 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
101 struct rtllib_frag_entry *entry;
102 struct rtllib_hdr_3addrqos *hdr_3addrqos;
103 struct rtllib_hdr_4addrqos *hdr_4addrqos;
106 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) && 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) +
128 (RTLLIB_QOS_HAS_SEQ(fc) ? 2 : 0) /* QOS Control */);
132 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
133 ieee->frag_next_idx[tid]++;
134 if (ieee->frag_next_idx[tid] >= RTLLIB_FRAG_CACHE_LEN)
135 ieee->frag_next_idx[tid] = 0;
137 if (entry->skb != NULL)
138 dev_kfree_skb_any(entry->skb);
140 entry->first_frag_time = jiffies;
142 entry->last_frag = frag;
144 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
145 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
147 /* received a fragment of a frame for which the head fragment
148 * should have already been received */
149 entry = rtllib_frag_cache_find(ieee, seq, frag, tid, hdr->addr2,
152 entry->last_frag = frag;
161 /* Called only as a tasklet (software IRQ) */
162 static int rtllib_frag_cache_invalidate(struct rtllib_device *ieee,
163 struct rtllib_hdr_4addr *hdr)
165 u16 fc = le16_to_cpu(hdr->frame_ctl);
166 u16 sc = le16_to_cpu(hdr->seq_ctl);
167 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
168 struct rtllib_frag_entry *entry;
169 struct rtllib_hdr_3addrqos *hdr_3addrqos;
170 struct rtllib_hdr_4addrqos *hdr_4addrqos;
173 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) && RTLLIB_QOS_HAS_SEQ(fc)) {
174 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
175 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
178 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
179 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)hdr;
180 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
187 entry = rtllib_frag_cache_find(ieee, seq, -1, tid, hdr->addr2,
192 "could not invalidate fragment cache "
193 "entry (seq=%u)\n", seq);
201 /* rtllib_rx_frame_mgtmt
203 * Responsible for handling management control frames
205 * Called by rtllib_rx */
207 rtllib_rx_frame_mgmt(struct rtllib_device *ieee, struct sk_buff *skb,
208 struct rtllib_rx_stats *rx_stats, u16 type,
211 /* On the struct stats definition there is written that
212 * this is not mandatory.... but seems that the probe
213 * response parser uses it
215 struct rtllib_hdr_3addr * hdr = (struct rtllib_hdr_3addr *)skb->data;
217 rx_stats->len = skb->len;
218 rtllib_rx_mgt(ieee, skb, rx_stats);
219 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN))) {
220 dev_kfree_skb_any(skb);
223 rtllib_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
225 dev_kfree_skb_any(skb);
230 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
231 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
232 static unsigned char rfc1042_header[] = {
233 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
235 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
236 static unsigned char bridge_tunnel_header[] = {
237 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
239 /* No encapsulation header if EtherType < 0x600 (=length) */
241 /* Called by rtllib_rx_frame_decrypt */
242 static int rtllib_is_eapol_frame(struct rtllib_device *ieee,
243 struct sk_buff *skb, size_t hdrlen)
245 struct net_device *dev = ieee->dev;
247 struct rtllib_hdr_4addr *hdr;
253 hdr = (struct rtllib_hdr_4addr *) skb->data;
254 fc = le16_to_cpu(hdr->frame_ctl);
256 /* check that the frame is unicast frame to us */
257 if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
259 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
260 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
261 /* ToDS frame with own addr BSSID and DA */
262 } else if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
263 RTLLIB_FCTL_FROMDS &&
264 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
265 /* FromDS frame with own addr as DA */
269 if (skb->len < 24 + 8)
272 /* check for port access entity Ethernet type */
273 pos = skb->data + hdrlen;
274 ethertype = (pos[6] << 8) | pos[7];
275 if (ethertype == ETH_P_PAE)
281 /* Called only as a tasklet (software IRQ), by rtllib_rx */
283 rtllib_rx_frame_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
284 struct rtllib_crypt_data *crypt)
286 struct rtllib_hdr_4addr *hdr;
289 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
292 if (ieee->hwsec_active) {
293 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=" MAC_FMT
309 ") res=%d\n", MAC_ARG(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 rtllib_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);
334 tcb_desc->bHwSec = 1;
336 if (ieee->need_sw_enc)
337 tcb_desc->bHwSec = 0;
340 hdr = (struct rtllib_hdr_4addr *) skb->data;
341 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
343 atomic_inc(&crypt->refcnt);
344 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv, ieee);
345 atomic_dec(&crypt->refcnt);
347 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
348 " (SA=" MAC_FMT " keyidx=%d)\n",
349 ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
357 /* this function is stolen from ipw2200 driver*/
358 #define IEEE_PACKET_RETRY_TIME (5*HZ)
359 static int is_duplicate_packet(struct rtllib_device *ieee,
360 struct rtllib_hdr_4addr *header)
362 u16 fc = le16_to_cpu(header->frame_ctl);
363 u16 sc = le16_to_cpu(header->seq_ctl);
364 u16 seq = WLAN_GET_SEQ_SEQ(sc);
365 u16 frag = WLAN_GET_SEQ_FRAG(sc);
366 u16 *last_seq, *last_frag;
367 unsigned long *last_time;
368 struct rtllib_hdr_3addrqos *hdr_3addrqos;
369 struct rtllib_hdr_4addrqos *hdr_4addrqos;
372 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) && RTLLIB_QOS_HAS_SEQ(fc)) {
373 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)header;
374 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
377 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
378 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)header;
379 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
386 switch (ieee->iw_mode) {
390 struct ieee_ibss_seq *entry = NULL;
391 u8 *mac = header->addr2;
392 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
393 list_for_each(p, &ieee->ibss_mac_hash[index]) {
394 entry = list_entry(p, struct ieee_ibss_seq, list);
395 if (!memcmp(entry->mac, mac, ETH_ALEN))
398 if (p == &ieee->ibss_mac_hash[index]) {
399 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
401 printk(KERN_WARNING "Cannot malloc new mac entry\n");
404 memcpy(entry->mac, mac, ETH_ALEN);
405 entry->seq_num[tid] = seq;
406 entry->frag_num[tid] = frag;
407 entry->packet_time[tid] = jiffies;
408 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
411 last_seq = &entry->seq_num[tid];
412 last_frag = &entry->frag_num[tid];
413 last_time = &entry->packet_time[tid];
418 last_seq = &ieee->last_rxseq_num[tid];
419 last_frag = &ieee->last_rxfrag_num[tid];
420 last_time = &ieee->last_packet_time[tid];
426 if ((*last_seq == seq) &&
427 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
428 if (*last_frag == frag)
430 if (*last_frag + 1 != frag)
431 /* out-of-order fragment */
437 *last_time = jiffies;
445 bool AddReorderEntry(struct rx_ts_record *pTS, struct rx_reorder_entry *pReorderEntry)
447 struct list_head *pList = &pTS->RxPendingPktList;
449 while (pList->next != &pTS->RxPendingPktList) {
450 if (SN_LESS(pReorderEntry->SeqNum, ((struct rx_reorder_entry *)list_entry(pList->next, struct rx_reorder_entry, List))->SeqNum))
452 else if (SN_EQUAL(pReorderEntry->SeqNum, ((struct rx_reorder_entry *)list_entry(pList->next, struct rx_reorder_entry, List))->SeqNum))
457 pReorderEntry->List.next = pList->next;
458 pReorderEntry->List.next->prev = &pReorderEntry->List;
459 pReorderEntry->List.prev = pList;
460 pList->next = &pReorderEntry->List;
465 void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prxbIndicateArray, u8 index)
467 struct net_device_stats *stats = &ieee->stats;
470 for (j = 0; j < index; j++) {
471 struct rtllib_rxb *prxb = prxbIndicateArray[j];
472 for (i = 0; i < prxb->nr_subframes; i++) {
473 struct sk_buff *sub_skb = prxb->subframes[i];
475 /* convert hdr + possible LLC headers into Ethernet header */
476 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
477 if (sub_skb->len >= 8 &&
478 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
479 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
480 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
481 /* remove RFC1042 or Bridge-Tunnel encapsulation
482 * and replace EtherType */
483 skb_pull(sub_skb, SNAP_SIZE);
484 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
485 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
488 /* Leave Ethernet header part of hdr and full payload */
489 len = htons(sub_skb->len);
490 memcpy(skb_push(sub_skb, 2), &len, 2);
491 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
492 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
495 /* Indicat the packets to upper layer */
498 stats->rx_bytes += sub_skb->len;
500 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
501 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
502 sub_skb->dev = ieee->dev;
503 sub_skb->dev->stats.rx_packets++;
504 sub_skb->dev->stats.rx_bytes += sub_skb->len;
505 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
506 ieee->last_rx_ps_time = jiffies;
515 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee, struct rx_ts_record *pTS)
517 struct rx_reorder_entry *pRxReorderEntry;
518 struct rtllib_rxb *RfdArray[REORDER_WIN_SIZE];
521 del_timer_sync(&pTS->RxPktPendingTimer);
522 while (!list_empty(&pTS->RxPendingPktList)) {
523 if (RfdCnt >= REORDER_WIN_SIZE) {
524 printk(KERN_INFO "-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n", __func__);
528 pRxReorderEntry = (struct rx_reorder_entry *)list_entry(pTS->RxPendingPktList.prev, struct rx_reorder_entry, List);
529 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate SeqNum %d!\n", __func__, pRxReorderEntry->SeqNum);
530 list_del_init(&pRxReorderEntry->List);
532 RfdArray[RfdCnt] = pRxReorderEntry->prxb;
535 list_add_tail(&pRxReorderEntry->List, &ieee->RxReorder_Unused_List);
537 rtllib_indicate_packets(ieee, RfdArray, RfdCnt);
539 pTS->RxIndicateSeq = 0xffff;
542 void RxReorderIndicatePacket(struct rtllib_device *ieee, struct rtllib_rxb *prxb,
543 struct rx_ts_record *pTS, u16 SeqNum)
545 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
546 struct rx_reorder_entry *pReorderEntry = NULL;
547 struct rtllib_rxb *prxbIndicateArray[REORDER_WIN_SIZE];
548 u8 WinSize = pHTInfo->RxReorderWinSize;
551 bool bMatchWinStart = false, bPktInBuf = false;
554 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Seq is %d, pTS->RxIndicateSeq"
555 " is %d, WinSize is %d\n", __func__, SeqNum,
556 pTS->RxIndicateSeq, WinSize);
558 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
560 WinEnd = (pTS->RxIndicateSeq + WinSize - 1) % 4096;
561 /* Rx Reorder initialize condition.*/
562 if (pTS->RxIndicateSeq == 0xffff)
563 pTS->RxIndicateSeq = SeqNum;
565 /* Drop out the packet which SeqNum is smaller than WinStart */
566 if (SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
567 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
568 pTS->RxIndicateSeq, SeqNum);
569 pHTInfo->RxReorderDropCounter++;
572 for (i = 0; i < prxb->nr_subframes; i++)
573 dev_kfree_skb(prxb->subframes[i]);
577 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
582 * Sliding window manipulation. Conditions includes:
583 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
584 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
586 if (SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
587 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
588 bMatchWinStart = true;
589 } else if (SN_LESS(WinEnd, SeqNum)) {
590 if (SeqNum >= (WinSize - 1))
591 pTS->RxIndicateSeq = SeqNum + 1 - WinSize;
593 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum + 1)) + 1;
594 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Window Shift! IndicateSeq: %d,"
595 " NewSeq: %d\n", pTS->RxIndicateSeq, SeqNum);
599 * Indication process.
600 * After Packet dropping and Sliding Window shifting as above, we can
601 * now just indicate the packets with the SeqNum smaller than latest
602 * WinStart and struct buffer other packets.
604 /* For Rx Reorder condition:
605 * 1. All packets with SeqNum smaller than WinStart => Indicate
606 * 2. All packets with SeqNum larger than or equal to
607 * WinStart => Buffer it.
609 if (bMatchWinStart) {
610 /* Current packet is going to be indicated.*/
611 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Packets indication!! "
612 "IndicateSeq: %d, NewSeq: %d\n",
613 pTS->RxIndicateSeq, SeqNum);
614 prxbIndicateArray[0] = prxb;
617 /* Current packet is going to be inserted into pending list.*/
618 if (!list_empty(&ieee->RxReorder_Unused_List)) {
619 pReorderEntry = (struct rx_reorder_entry *)
620 list_entry(ieee->RxReorder_Unused_List.next,
621 struct rx_reorder_entry, List);
622 list_del_init(&pReorderEntry->List);
624 /* Make a reorder entry and insert into a the packet list.*/
625 pReorderEntry->SeqNum = SeqNum;
626 pReorderEntry->prxb = prxb;
628 if (!AddReorderEntry(pTS, pReorderEntry)) {
629 RTLLIB_DEBUG(RTLLIB_DL_REORDER,
630 "%s(): Duplicate packet is "
631 "dropped!! IndicateSeq: %d, "
633 __func__, pTS->RxIndicateSeq,
635 list_add_tail(&pReorderEntry->List,
636 &ieee->RxReorder_Unused_List); {
638 for (i = 0; i < prxb->nr_subframes; i++)
639 dev_kfree_skb(prxb->subframes[i]);
644 RTLLIB_DEBUG(RTLLIB_DL_REORDER,
645 "Pkt insert into struct buffer!! "
646 "IndicateSeq: %d, NewSeq: %d\n",
647 pTS->RxIndicateSeq, SeqNum);
651 * Packets are dropped if there are not enough reorder
652 * entries. This part should be modified!! We can just
653 * indicate all the packets in struct buffer and get
656 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket():"
657 " There is no reorder entry!! Packet is "
661 for (i = 0; i < prxb->nr_subframes; i++)
662 dev_kfree_skb(prxb->subframes[i]);
669 /* Check if there is any packet need indicate.*/
670 while (!list_empty(&pTS->RxPendingPktList)) {
671 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): start RREORDER indicate\n", __func__);
673 pReorderEntry = (struct rx_reorder_entry *)list_entry(pTS->RxPendingPktList.prev,
674 struct rx_reorder_entry, List);
675 if (SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
676 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) {
677 /* This protect struct buffer from overflow. */
678 if (index >= REORDER_WIN_SIZE) {
679 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicate"
680 "Packet(): Buffer overflow!!\n");
685 list_del_init(&pReorderEntry->List);
687 if (SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
688 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
690 prxbIndicateArray[index] = pReorderEntry->prxb;
691 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate SeqNum"
692 " %d!\n", __func__, pReorderEntry->SeqNum);
695 list_add_tail(&pReorderEntry->List,
696 &ieee->RxReorder_Unused_List);
703 /* Handling pending timer. Set this timer to prevent from long time
706 if (timer_pending(&pTS->RxPktPendingTimer))
707 del_timer_sync(&pTS->RxPktPendingTimer);
708 pTS->RxTimeoutIndicateSeq = 0xffff;
710 if (index > REORDER_WIN_SIZE) {
711 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket():"
712 " Rx Reorer struct buffer full!!\n");
713 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
717 rtllib_indicate_packets(ieee, prxbIndicateArray, index);
721 if (bPktInBuf && pTS->RxTimeoutIndicateSeq == 0xffff) {
722 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): SET rx timeout timer\n",
724 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
725 mod_timer(&pTS->RxPktPendingTimer, jiffies +
726 MSECS(pHTInfo->RxReorderPendingTime));
728 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
731 u8 parse_subframe(struct rtllib_device *ieee, struct sk_buff *skb,
732 struct rtllib_rx_stats *rx_stats,
733 struct rtllib_rxb *rxb, u8 *src, u8 *dst)
735 struct rtllib_hdr_3addr *hdr = (struct rtllib_hdr_3addr *)skb->data;
736 u16 fc = le16_to_cpu(hdr->frame_ctl);
738 u16 LLCOffset = sizeof(struct rtllib_hdr_3addr);
740 bool bIsAggregateFrame = false;
741 u16 nSubframe_Length;
742 u8 nPadding_Length = 0;
744 struct sk_buff *sub_skb;
746 /* just for debug purpose */
747 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
748 if ((RTLLIB_QOS_HAS_SEQ(fc)) &&
749 (((union frameqos *)(skb->data + RTLLIB_3ADDR_LEN))->field.reserved))
750 bIsAggregateFrame = true;
752 if (RTLLIB_QOS_HAS_SEQ(fc))
754 if (rx_stats->bContainHTC)
755 LLCOffset += sHTCLng;
757 ChkLength = LLCOffset;
759 if (skb->len <= ChkLength)
762 skb_pull(skb, LLCOffset);
763 ieee->bIsAggregateFrame = bIsAggregateFrame;
764 if (!bIsAggregateFrame) {
765 rxb->nr_subframes = 1;
767 /* altered by clark 3/30/2010
768 * The struct buffer size of the skb indicated to upper layer
769 * must be less than 5000, or the defraged IP datagram
770 * in the IP layer will exceed "ipfrag_high_tresh" and be
771 * discarded. so there must not use the function
772 * "skb_copy" and "skb_clone" for "skb".
775 /* Allocate new skb for releasing to upper layer */
776 sub_skb = dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE);
777 skb_reserve(sub_skb, 12);
778 data_ptr = (u8 *)skb_put(sub_skb, skb->len);
779 memcpy(data_ptr, skb->data, skb->len);
780 sub_skb->dev = ieee->dev;
782 rxb->subframes[0] = sub_skb;
784 memcpy(rxb->src, src, ETH_ALEN);
785 memcpy(rxb->dst, dst, ETH_ALEN);
786 rxb->subframes[0]->dev = ieee->dev;
789 rxb->nr_subframes = 0;
790 memcpy(rxb->src, src, ETH_ALEN);
791 memcpy(rxb->dst, dst, ETH_ALEN);
792 while (skb->len > ETHERNET_HEADER_SIZE) {
793 /* Offset 12 denote 2 mac address */
794 nSubframe_Length = *((u16 *)(skb->data + 12));
795 nSubframe_Length = (nSubframe_Length >> 8) +
796 (nSubframe_Length << 8);
798 if (skb->len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
799 printk(KERN_INFO "%s: A-MSDU parse error!! "
800 "pRfd->nTotalSubframe : %d\n",\
801 __func__, rxb->nr_subframes);
802 printk(KERN_INFO "%s: A-MSDU parse error!! "
803 "Subframe Length: %d\n", __func__,
805 printk(KERN_INFO "nRemain_Length is %d and "
806 "nSubframe_Length is : %d\n", skb->len,
808 printk(KERN_INFO "The Packet SeqNum is %d\n", SeqNum);
812 /* move the data point to data content */
813 skb_pull(skb, ETHERNET_HEADER_SIZE);
815 /* altered by clark 3/30/2010
816 * The struct buffer size of the skb indicated to upper layer
817 * must be less than 5000, or the defraged IP datagram
818 * in the IP layer will exceed "ipfrag_high_tresh" and be
819 * discarded. so there must not use the function
820 * "skb_copy" and "skb_clone" for "skb".
823 /* Allocate new skb for releasing to upper layer */
824 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
825 skb_reserve(sub_skb, 12);
826 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
827 memcpy(data_ptr, skb->data, nSubframe_Length);
829 sub_skb->dev = ieee->dev;
830 rxb->subframes[rxb->nr_subframes++] = sub_skb;
831 if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
832 RTLLIB_DEBUG_RX("ParseSubframe(): Too many "
833 "Subframes! Packets dropped!\n");
836 skb_pull(skb, nSubframe_Length);
839 nPadding_Length = 4 - ((nSubframe_Length +
840 ETHERNET_HEADER_SIZE) % 4);
841 if (nPadding_Length == 4)
844 if (skb->len < nPadding_Length)
847 skb_pull(skb, nPadding_Length);
851 return rxb->nr_subframes;
856 size_t rtllib_rx_get_hdrlen(struct rtllib_device *ieee, struct sk_buff *skb,
857 struct rtllib_rx_stats *rx_stats)
859 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
860 u16 fc = le16_to_cpu(hdr->frame_ctl);
863 hdrlen = rtllib_get_hdrlen(fc);
864 if (HTCCheck(ieee, skb->data)) {
866 printk(KERN_INFO "%s: find HTCControl!\n", __func__);
868 rx_stats->bContainHTC = 1;
871 if (RTLLIB_QOS_HAS_SEQ(fc))
872 rx_stats->bIsQosData = 1;
877 int rtllib_rx_check_duplicate(struct rtllib_device *ieee, struct sk_buff *skb,
880 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
882 u8 frag, type, stype;
884 fc = le16_to_cpu(hdr->frame_ctl);
885 type = WLAN_FC_GET_TYPE(fc);
886 stype = WLAN_FC_GET_STYPE(fc);
887 sc = le16_to_cpu(hdr->seq_ctl);
888 frag = WLAN_GET_SEQ_FRAG(sc);
890 if ((ieee->pHTInfo->bCurRxReorderEnable == false) ||
891 !ieee->current_network.qos_data.active ||
892 !IsDataFrame(skb->data) ||
893 IsLegacyDataFrame(skb->data)) {
894 if (!((type == RTLLIB_FTYPE_MGMT) && (stype == RTLLIB_STYPE_BEACON))) {
895 if (is_duplicate_packet(ieee, hdr))
899 struct rx_ts_record *pRxTS = NULL;
900 if (GetTs(ieee, (struct ts_common_info **) &pRxTS, hdr->addr2,
901 (u8)Frame_QoSTID((u8 *)(skb->data)), RX_DIR, true)) {
902 if ((fc & (1<<11)) && (frag == pRxTS->RxLastFragNum) &&
903 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum)) {
906 pRxTS->RxLastFragNum = frag;
907 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
910 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!%s(): No TS!! Skip"
911 " the check!!\n", __func__);
919 void rtllib_rx_extract_addr(struct rtllib_device *ieee,
920 struct rtllib_hdr_4addr *hdr, u8 *dst, u8 *src,
923 u16 fc = le16_to_cpu(hdr->frame_ctl);
925 switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
926 case RTLLIB_FCTL_FROMDS:
927 memcpy(dst, hdr->addr1, ETH_ALEN);
928 memcpy(src, hdr->addr3, ETH_ALEN);
929 memcpy(bssid, hdr->addr2, ETH_ALEN);
931 case RTLLIB_FCTL_TODS:
932 memcpy(dst, hdr->addr3, ETH_ALEN);
933 memcpy(src, hdr->addr2, ETH_ALEN);
934 memcpy(bssid, hdr->addr1, ETH_ALEN);
936 case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
937 memcpy(dst, hdr->addr3, ETH_ALEN);
938 memcpy(src, hdr->addr4, ETH_ALEN);
939 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
942 memcpy(dst, hdr->addr1, ETH_ALEN);
943 memcpy(src, hdr->addr2, ETH_ALEN);
944 memcpy(bssid, hdr->addr3, ETH_ALEN);
949 int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc, u8 *dst, u8 *src,
950 u8 *bssid, u8 *addr2)
952 u8 zero_addr[ETH_ALEN] = {0};
955 type = WLAN_FC_GET_TYPE(fc);
956 stype = WLAN_FC_GET_STYPE(fc);
958 /* Filter frames from different BSS */
959 if (((fc & RTLLIB_FCTL_DSTODS) != RTLLIB_FCTL_DSTODS)
960 && (compare_ether_addr(ieee->current_network.bssid, bssid) != 0)
961 && memcmp(ieee->current_network.bssid, zero_addr, ETH_ALEN)) {
965 /* Filter packets sent by an STA that will be forwarded by AP */
966 if (ieee->IntelPromiscuousModeInfo.bPromiscuousOn &&
967 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame) {
968 if ((fc & RTLLIB_FCTL_TODS) && !(fc & RTLLIB_FCTL_FROMDS) &&
969 (compare_ether_addr(dst, ieee->current_network.bssid) != 0) &&
970 (compare_ether_addr(bssid, ieee->current_network.bssid) == 0)) {
975 /* Nullfunc frames may have PS-bit set, so they must be passed to
976 * hostap_handle_sta_rx() before being dropped here. */
977 if (!ieee->IntelPromiscuousModeInfo.bPromiscuousOn) {
978 if (stype != RTLLIB_STYPE_DATA &&
979 stype != RTLLIB_STYPE_DATA_CFACK &&
980 stype != RTLLIB_STYPE_DATA_CFPOLL &&
981 stype != RTLLIB_STYPE_DATA_CFACKPOLL &&
982 stype != RTLLIB_STYPE_QOS_DATA) {
983 if (stype != RTLLIB_STYPE_NULLFUNC)
985 "RX: dropped data frame "
986 "with no data (type=0x%02x, "
993 if (ieee->iw_mode != IW_MODE_MESH) {
994 /* packets from our adapter are dropped (echo) */
995 if (!memcmp(src, ieee->dev->dev_addr, ETH_ALEN))
998 /* {broad,multi}cast packets to our BSS go through */
999 if (is_multicast_ether_addr(dst) || is_broadcast_ether_addr(dst)) {
1000 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1007 int rtllib_rx_get_crypt(struct rtllib_device *ieee, struct sk_buff *skb,
1008 struct rtllib_crypt_data **crypt, size_t hdrlen)
1010 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1011 u16 fc = le16_to_cpu(hdr->frame_ctl);
1014 if (ieee->host_decrypt) {
1015 if (skb->len >= hdrlen + 3)
1016 idx = skb->data[hdrlen + 3] >> 6;
1018 *crypt = ieee->crypt[idx];
1019 /* allow NULL decrypt to indicate an station specific override
1020 * for default encryption */
1021 if (*crypt && ((*crypt)->ops == NULL ||
1022 (*crypt)->ops->decrypt_mpdu == NULL))
1025 if (!*crypt && (fc & RTLLIB_FCTL_WEP)) {
1026 /* This seems to be triggered by some (multicast?)
1027 * frames from other than current BSS, so just drop the
1028 * frames silently instead of filling system log with
1030 RTLLIB_DEBUG_DROP("Decryption failed (not set)"
1031 " (SA=" MAC_FMT ")\n",
1032 MAC_ARG(hdr->addr2));
1033 ieee->ieee_stats.rx_discards_undecryptable++;
1041 int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
1042 struct rtllib_rx_stats *rx_stats,
1043 struct rtllib_crypt_data *crypt, size_t hdrlen)
1045 struct rtllib_hdr_4addr *hdr;
1050 hdr = (struct rtllib_hdr_4addr *)skb->data;
1051 fc = le16_to_cpu(hdr->frame_ctl);
1052 sc = le16_to_cpu(hdr->seq_ctl);
1053 frag = WLAN_GET_SEQ_FRAG(sc);
1055 if ((!rx_stats->Decrypted))
1056 ieee->need_sw_enc = 1;
1058 ieee->need_sw_enc = 0;
1060 keyidx = rtllib_rx_frame_decrypt(ieee, skb, crypt);
1061 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) && (keyidx < 0)) {
1062 printk(KERN_INFO "%s: decrypt frame error\n", __func__);
1066 hdr = (struct rtllib_hdr_4addr *) skb->data;
1067 if ((frag != 0 || (fc & RTLLIB_FCTL_MOREFRAGS))) {
1069 struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
1070 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1073 RTLLIB_DEBUG(RTLLIB_DL_RX | RTLLIB_DL_FRAG,
1074 "Rx cannot get skb from fragment "
1075 "cache (morefrag=%d seq=%u frag=%u)\n",
1076 (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
1077 WLAN_GET_SEQ_SEQ(sc), frag);
1084 if (frag_skb->tail + flen > frag_skb->end) {
1085 printk(KERN_WARNING "%s: host decrypted and "
1086 "reassembled frame did not fit skb\n",
1088 rtllib_frag_cache_invalidate(ieee, hdr);
1093 /* copy first fragment (including full headers) into
1094 * beginning of the fragment cache skb */
1095 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1097 /* append frame payload to the end of the fragment
1099 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1102 dev_kfree_skb_any(skb);
1105 if (fc & RTLLIB_FCTL_MOREFRAGS) {
1106 /* more fragments expected - leave the skb in fragment
1107 * cache for now; it will be delivered to upper layers
1108 * after all fragments have been received */
1112 /* this was the last fragment and the frame will be
1113 * delivered, so remove skb from fragment cache */
1115 hdr = (struct rtllib_hdr_4addr *) skb->data;
1116 rtllib_frag_cache_invalidate(ieee, hdr);
1119 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1120 * encrypted/authenticated */
1121 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
1122 rtllib_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
1123 printk(KERN_INFO "%s: ==>decrypt msdu error\n", __func__);
1127 hdr = (struct rtllib_hdr_4addr *) skb->data;
1128 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep) {
1129 if (/*ieee->ieee802_1x &&*/
1130 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1132 /* pass unencrypted EAPOL frames even if encryption is
1134 struct eapol *eap = (struct eapol *)(skb->data +
1136 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1137 eap_get_type(eap->type));
1140 "encryption configured, but RX "
1141 "frame not encrypted (SA=" MAC_FMT ")\n",
1142 MAC_ARG(hdr->addr2));
1147 if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
1148 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
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 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
1156 !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1158 "dropped unencrypted RX data "
1159 "frame from " MAC_FMT
1160 " (drop_unencrypted=1)\n",
1161 MAC_ARG(hdr->addr2));
1165 if (rtllib_is_eapol_frame(ieee, skb, hdrlen))
1166 printk(KERN_WARNING "RX: IEEE802.1X EAPOL frame!\n");
1171 void rtllib_rx_check_leave_lps(struct rtllib_device *ieee, u8 unicast, u8 nr_subframes)
1175 if ((ieee->state == RTLLIB_LINKED)) {
1176 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +
1177 ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1178 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) {
1179 if (ieee->LeisurePSLeave)
1180 ieee->LeisurePSLeave(ieee->dev);
1184 ieee->last_rx_ps_time = jiffies;
1187 void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
1188 struct rtllib_rx_stats *rx_stats,
1189 struct rtllib_rxb *rxb,
1193 struct net_device *dev = ieee->dev;
1198 printk(KERN_INFO "%s: rxb is NULL!!\n", __func__);
1202 for (i = 0; i < rxb->nr_subframes; i++) {
1203 struct sk_buff *sub_skb = rxb->subframes[i];
1206 /* convert hdr + possible LLC headers into Ethernet header */
1207 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1208 if (sub_skb->len >= 8 &&
1209 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1210 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1211 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1212 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1213 * replace EtherType */
1214 skb_pull(sub_skb, SNAP_SIZE);
1215 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1216 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1219 /* Leave Ethernet header part of hdr and full payload */
1220 len = htons(sub_skb->len);
1221 memcpy(skb_push(sub_skb, 2), &len, 2);
1222 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1223 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1226 ieee->stats.rx_packets++;
1227 ieee->stats.rx_bytes += sub_skb->len;
1229 if (is_multicast_ether_addr(dst))
1230 ieee->stats.multicast++;
1232 /* Indicat the packets to upper layer */
1233 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1234 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1236 sub_skb->dev->stats.rx_packets++;
1237 sub_skb->dev->stats.rx_bytes += sub_skb->len;
1238 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1246 int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1247 struct rtllib_rx_stats *rx_stats)
1249 struct net_device *dev = ieee->dev;
1250 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1251 struct rtllib_crypt_data *crypt = NULL;
1252 struct rtllib_rxb *rxb = NULL;
1253 struct rx_ts_record *pTS = NULL;
1254 u16 fc, sc, SeqNum = 0;
1255 u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0;
1256 u8 dst[ETH_ALEN], src[ETH_ALEN], bssid[ETH_ALEN] = {0}, *payload;
1258 bool bToOtherSTA = false;
1261 hdr = (struct rtllib_hdr_4addr *)skb->data;
1262 fc = le16_to_cpu(hdr->frame_ctl);
1263 type = WLAN_FC_GET_TYPE(fc);
1264 stype = WLAN_FC_GET_STYPE(fc);
1265 sc = le16_to_cpu(hdr->seq_ctl);
1267 /*Filter pkt not to me*/
1268 multicast = is_multicast_ether_addr(hdr->addr1)|is_broadcast_ether_addr(hdr->addr1);
1269 unicast = !multicast;
1270 if (unicast && (compare_ether_addr(dev->dev_addr, hdr->addr1) != 0)) {
1271 if (ieee->bNetPromiscuousMode)
1277 /*Filter pkt has too small length */
1278 hdrlen = rtllib_rx_get_hdrlen(ieee, skb, rx_stats);
1279 if (skb->len < hdrlen) {
1280 printk(KERN_INFO "%s():ERR!!! skb->len is smaller than hdrlen\n", __func__);
1284 /* Filter Duplicate pkt */
1285 ret = rtllib_rx_check_duplicate(ieee, skb, multicast);
1289 /* Filter CTRL Frame */
1290 if (type == RTLLIB_FTYPE_CTL)
1293 /* Filter MGNT Frame */
1294 if (type == RTLLIB_FTYPE_MGMT) {
1297 if (rtllib_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1303 /* Filter WAPI DATA Frame */
1305 /* Update statstics for AP roaming */
1307 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1308 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1310 dev->last_rx = jiffies;
1312 /* Data frame - extract src/dst addresses */
1313 rtllib_rx_extract_addr(ieee, hdr, dst, src, bssid);
1315 /* Filter Data frames */
1316 ret = rtllib_rx_data_filter(ieee, fc, dst, src, bssid, hdr->addr2);
1320 if (skb->len == hdrlen)
1323 /* Send pspoll based on moredata */
1324 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == LPS_IS_SLEEP)
1325 && (ieee->polling) && (!bToOtherSTA)) {
1326 if (WLAN_FC_MORE_DATA(fc)) {
1327 /* more data bit is set, let's request a new frame from the AP */
1328 rtllib_sta_ps_send_pspoll_frame(ieee);
1330 ieee->polling = false;
1334 /* Get crypt if encrypted */
1335 ret = rtllib_rx_get_crypt(ieee, skb, &crypt, hdrlen);
1339 /* Decrypt data frame (including reassemble) */
1340 ret = rtllib_rx_decrypt(ieee, skb, rx_stats, crypt, hdrlen);
1346 /* Get TS for Rx Reorder */
1347 hdr = (struct rtllib_hdr_4addr *) skb->data;
1348 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1349 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1)
1350 && (!bToOtherSTA)) {
1351 TID = Frame_QoSTID(skb->data);
1352 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1353 GetTs(ieee, (struct ts_common_info **) &pTS, hdr->addr2, TID, RX_DIR, true);
1354 if (TID != 0 && TID != 3)
1355 ieee->bis_any_nonbepkts = true;
1358 /* Parse rx data frame (For AMSDU) */
1359 /* skb: hdr + (possible reassembled) full plaintext payload */
1360 payload = skb->data + hdrlen;
1361 rxb = kmalloc(sizeof(struct rtllib_rxb), GFP_ATOMIC);
1363 RTLLIB_DEBUG(RTLLIB_DL_ERR,
1364 "%s(): kmalloc rxb error\n", __func__);
1367 /* to parse amsdu packets */
1368 /* qos data packets & reserved bit is 1 */
1369 if (parse_subframe(ieee, skb, rx_stats, rxb, src, dst) == 0) {
1370 /* only to free rxb, and not submit the packets to upper layer */
1371 for (i = 0; i < rxb->nr_subframes; i++)
1372 dev_kfree_skb(rxb->subframes[i]);
1378 /* Update WAPI PN */
1380 /* Check if leave LPS */
1382 if (ieee->bIsAggregateFrame)
1383 nr_subframes = rxb->nr_subframes;
1387 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod += nr_subframes;
1388 rtllib_rx_check_leave_lps(ieee, unicast, nr_subframes);
1391 /* Indicate packets to upper layer or Rx Reorder */
1392 if (ieee->pHTInfo->bCurRxReorderEnable == false || pTS == NULL || bToOtherSTA)
1393 rtllib_rx_indicate_pkt_legacy(ieee, rx_stats, rxb, dst, src);
1395 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1407 ieee->stats.rx_dropped++;
1409 /* Returning 0 indicates to caller that we have not handled the SKB--
1410 * so it is still allocated and can be used again by underlying
1411 * hardware as a DMA target */
1415 int rtllib_rx_Master(struct rtllib_device *ieee, struct sk_buff *skb,
1416 struct rtllib_rx_stats *rx_stats)
1421 int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb,
1422 struct rtllib_rx_stats *rx_stats)
1424 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1425 u16 fc = le16_to_cpu(hdr->frame_ctl);
1426 size_t hdrlen = rtllib_get_hdrlen(fc);
1428 if (skb->len < hdrlen) {
1429 printk(KERN_INFO "%s():ERR!!! skb->len is smaller than hdrlen\n", __func__);
1433 if (HTCCheck(ieee, skb->data)) {
1434 if (net_ratelimit())
1435 printk(KERN_INFO "%s: Find HTCControl!\n", __func__);
1439 rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
1440 ieee->stats.rx_packets++;
1441 ieee->stats.rx_bytes += skb->len;
1446 int rtllib_rx_Mesh(struct rtllib_device *ieee, struct sk_buff *skb,
1447 struct rtllib_rx_stats *rx_stats)
1452 /* All received frames are sent to this function. @skb contains the frame in
1453 * IEEE 802.11 format, i.e., in the format it was sent over air.
1454 * This function is called only as a tasklet (software IRQ). */
1455 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1456 struct rtllib_rx_stats *rx_stats)
1460 if ((NULL == ieee) || (NULL == skb) || (NULL == rx_stats)) {
1461 printk(KERN_INFO "%s: Input parameters NULL!\n", __func__);
1464 if (skb->len < 10) {
1465 printk(KERN_INFO "%s: SKB length < 10\n", __func__);
1469 switch (ieee->iw_mode) {
1472 ret = rtllib_rx_InfraAdhoc(ieee, skb, rx_stats);
1474 case IW_MODE_MASTER:
1475 case IW_MODE_REPEAT:
1476 ret = rtllib_rx_Master(ieee, skb, rx_stats);
1478 case IW_MODE_MONITOR:
1479 ret = rtllib_rx_Monitor(ieee, skb, rx_stats);
1482 ret = rtllib_rx_Mesh(ieee, skb, rx_stats);
1485 printk(KERN_INFO"%s: ERR iw mode!!!\n", __func__);
1492 ieee->stats.rx_dropped++;
1496 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1499 * Make ther structure we read from the beacon packet has
1502 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1503 *info_element, int sub_type)
1506 if (info_element->qui_subtype != sub_type)
1508 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1510 if (info_element->qui_type != QOS_OUI_TYPE)
1512 if (info_element->version != QOS_VERSION_1)
1520 * Parse a QoS parameter element
1522 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
1523 *element_param, struct rtllib_info_element
1527 u16 size = sizeof(struct rtllib_qos_parameter_info) - 2;
1529 if ((info_element == NULL) || (element_param == NULL))
1532 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1533 memcpy(element_param->info_element.qui, info_element->data,
1535 element_param->info_element.elementID = info_element->id;
1536 element_param->info_element.length = info_element->len;
1540 ret = rtllib_verify_qos_info(&element_param->info_element,
1541 QOS_OUI_PARAM_SUB_TYPE);
1546 * Parse a QoS information element
1548 static int rtllib_read_qos_info_element(struct
1549 rtllib_qos_information_element
1550 *element_info, struct rtllib_info_element
1554 u16 size = sizeof(struct rtllib_qos_information_element) - 2;
1556 if (element_info == NULL)
1558 if (info_element == NULL)
1561 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1562 memcpy(element_info->qui, info_element->data,
1564 element_info->elementID = info_element->id;
1565 element_info->length = info_element->len;
1570 ret = rtllib_verify_qos_info(element_info,
1571 QOS_OUI_INFO_SUB_TYPE);
1577 * Write QoS parameters from the ac parameters.
1579 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info *param_elm,
1580 struct rtllib_qos_data *qos_data)
1582 struct rtllib_qos_ac_parameter *ac_params;
1583 struct rtllib_qos_parameters *qos_param = &(qos_data->parameters);
1589 qos_data->wmm_acm = 0;
1590 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1591 ac_params = &(param_elm->ac_params_record[i]);
1593 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1594 acm = (ac_params->aci_aifsn & 0x10) >> 4;
1596 if (aci >= QOS_QUEUE_NUM)
1600 /* BIT(0) | BIT(3) */
1602 qos_data->wmm_acm |= (0x01<<0)|(0x01<<3);
1605 /* BIT(4) | BIT(5) */
1607 qos_data->wmm_acm |= (0x01<<4)|(0x01<<5);
1610 /* BIT(6) | BIT(7) */
1612 qos_data->wmm_acm |= (0x01<<6)|(0x01<<7);
1616 /* BIT(1) | BIT(2) */
1618 qos_data->wmm_acm |= (0x01<<1)|(0x01<<2);
1622 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1624 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1625 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2 : qos_param->aifs[aci];
1627 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1629 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1631 qos_param->flag[aci] =
1632 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1633 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1639 * we have a generic data element which it may contain QoS information or
1640 * parameters element. check the information element length to decide
1641 * which type to read
1643 static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
1645 struct rtllib_network *network)
1648 struct rtllib_qos_information_element qos_info_element;
1650 rc = rtllib_read_qos_info_element(&qos_info_element, info_element);
1653 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1654 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1656 struct rtllib_qos_parameter_info param_element;
1658 rc = rtllib_read_qos_param_element(¶m_element,
1661 rtllib_qos_convert_ac_to_parameters(¶m_element,
1662 &(network->qos_data));
1663 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1664 network->qos_data.param_count =
1665 param_element.info_element.ac_info & 0x0F;
1670 RTLLIB_DEBUG_QOS("QoS is supported\n");
1671 network->qos_data.supported = 1;
1676 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1678 static const char *get_info_element_string(u16 id)
1683 MFIE_STRING(FH_SET);
1684 MFIE_STRING(DS_SET);
1685 MFIE_STRING(CF_SET);
1687 MFIE_STRING(IBSS_SET);
1688 MFIE_STRING(COUNTRY);
1689 MFIE_STRING(HOP_PARAMS);
1690 MFIE_STRING(HOP_TABLE);
1691 MFIE_STRING(REQUEST);
1692 MFIE_STRING(CHALLENGE);
1693 MFIE_STRING(POWER_CONSTRAINT);
1694 MFIE_STRING(POWER_CAPABILITY);
1695 MFIE_STRING(TPC_REQUEST);
1696 MFIE_STRING(TPC_REPORT);
1697 MFIE_STRING(SUPP_CHANNELS);
1699 MFIE_STRING(MEASURE_REQUEST);
1700 MFIE_STRING(MEASURE_REPORT);
1702 MFIE_STRING(IBSS_DFS);
1704 MFIE_STRING(RATES_EX);
1705 MFIE_STRING(GENERIC);
1706 MFIE_STRING(QOS_PARAMETER);
1712 static inline void rtllib_extract_country_ie(
1713 struct rtllib_device *ieee,
1714 struct rtllib_info_element *info_element,
1715 struct rtllib_network *network,
1718 if (IS_DOT11D_ENABLE(ieee)) {
1719 if (info_element->len != 0) {
1720 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1721 network->CountryIeLen = info_element->len;
1723 if (!IS_COUNTRY_IE_VALID(ieee)) {
1724 if ((rtllib_act_scanning(ieee, false) == true) && (ieee->FirstIe_InScan == 1))
1725 printk(KERN_INFO "Received beacon ContryIE, SSID: <%s>\n", network->ssid);
1726 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
1730 if (IS_EQUAL_CIE_SRC(ieee, addr2))
1731 UPDATE_CIE_WATCHDOG(ieee);
1736 int rtllib_parse_info_param(struct rtllib_device *ieee,
1737 struct rtllib_info_element *info_element,
1739 struct rtllib_network *network,
1740 struct rtllib_rx_stats *stats)
1744 u16 tmp_htcap_len = 0;
1745 u16 tmp_htinfo_len = 0;
1746 u16 ht_realtek_agg_len = 0;
1747 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1751 while (length >= sizeof(*info_element)) {
1752 if (sizeof(*info_element) + info_element->len > length) {
1753 RTLLIB_DEBUG_MGMT("Info elem: parse failed: "
1754 "info_element->len + 2 > left : "
1755 "info_element->len+2=%zd left=%d, id=%d.\n",
1757 sizeof(*info_element),
1758 length, info_element->id);
1759 /* We stop processing but don't return an error here
1760 * because some misbehaviour APs break this rule. ie.
1761 * Orinoco AP1000. */
1765 switch (info_element->id) {
1766 case MFIE_TYPE_SSID:
1767 if (rtllib_is_empty_essid(info_element->data,
1768 info_element->len)) {
1769 network->flags |= NETWORK_EMPTY_ESSID;
1773 network->ssid_len = min(info_element->len,
1774 (u8) IW_ESSID_MAX_SIZE);
1775 memcpy(network->ssid, info_element->data, network->ssid_len);
1776 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1777 memset(network->ssid + network->ssid_len, 0,
1778 IW_ESSID_MAX_SIZE - network->ssid_len);
1780 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1781 network->ssid, network->ssid_len);
1784 case MFIE_TYPE_RATES:
1786 network->rates_len = min(info_element->len,
1788 for (i = 0; i < network->rates_len; i++) {
1789 network->rates[i] = info_element->data[i];
1790 p += snprintf(p, sizeof(rates_str) -
1791 (p - rates_str), "%02X ",
1793 if (rtllib_is_ofdm_rate
1794 (info_element->data[i])) {
1795 network->flags |= NETWORK_HAS_OFDM;
1796 if (info_element->data[i] &
1797 RTLLIB_BASIC_RATE_MASK)
1802 if (rtllib_is_cck_rate
1803 (info_element->data[i])) {
1804 network->flags |= NETWORK_HAS_CCK;
1808 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1809 rates_str, network->rates_len);
1812 case MFIE_TYPE_RATES_EX:
1814 network->rates_ex_len = min(info_element->len,
1815 MAX_RATES_EX_LENGTH);
1816 for (i = 0; i < network->rates_ex_len; i++) {
1817 network->rates_ex[i] = info_element->data[i];
1818 p += snprintf(p, sizeof(rates_str) -
1819 (p - rates_str), "%02X ",
1821 if (rtllib_is_ofdm_rate
1822 (info_element->data[i])) {
1823 network->flags |= NETWORK_HAS_OFDM;
1824 if (info_element->data[i] &
1825 RTLLIB_BASIC_RATE_MASK)
1831 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1832 rates_str, network->rates_ex_len);
1835 case MFIE_TYPE_DS_SET:
1836 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1837 info_element->data[0]);
1838 network->channel = info_element->data[0];
1841 case MFIE_TYPE_FH_SET:
1842 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1845 case MFIE_TYPE_CF_SET:
1846 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1850 if (info_element->len < 4)
1853 network->tim.tim_count = info_element->data[0];
1854 network->tim.tim_period = info_element->data[1];
1856 network->dtim_period = info_element->data[1];
1857 if (ieee->state != RTLLIB_LINKED)
1859 network->last_dtim_sta_time = jiffies;
1861 network->dtim_data = RTLLIB_DTIM_VALID;
1864 if (info_element->data[2] & 1)
1865 network->dtim_data |= RTLLIB_DTIM_MBCAST;
1867 offset = (info_element->data[2] >> 1)*2;
1870 if (ieee->assoc_id < 8*offset ||
1871 ieee->assoc_id > 8*(offset + info_element->len - 3))
1874 offset = (ieee->assoc_id / 8) - offset;
1875 if (info_element->data[3 + offset] &
1876 (1 << (ieee->assoc_id % 8)))
1877 network->dtim_data |= RTLLIB_DTIM_UCAST;
1879 network->listen_interval = network->dtim_period;
1883 network->erp_value = info_element->data[0];
1884 network->flags |= NETWORK_HAS_ERP_VALUE;
1885 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1886 network->erp_value);
1888 case MFIE_TYPE_IBSS_SET:
1889 network->atim_window = info_element->data[0];
1890 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1891 network->atim_window);
1894 case MFIE_TYPE_CHALLENGE:
1895 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1898 case MFIE_TYPE_GENERIC:
1899 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1901 if (!rtllib_parse_qos_info_param_IE(info_element,
1904 if (info_element->len >= 4 &&
1905 info_element->data[0] == 0x00 &&
1906 info_element->data[1] == 0x50 &&
1907 info_element->data[2] == 0xf2 &&
1908 info_element->data[3] == 0x01) {
1909 network->wpa_ie_len = min(info_element->len + 2,
1911 memcpy(network->wpa_ie, info_element,
1912 network->wpa_ie_len);
1915 if (info_element->len == 7 &&
1916 info_element->data[0] == 0x00 &&
1917 info_element->data[1] == 0xe0 &&
1918 info_element->data[2] == 0x4c &&
1919 info_element->data[3] == 0x01 &&
1920 info_element->data[4] == 0x02)
1921 network->Turbo_Enable = 1;
1923 if (tmp_htcap_len == 0) {
1924 if (info_element->len >= 4 &&
1925 info_element->data[0] == 0x00 &&
1926 info_element->data[1] == 0x90 &&
1927 info_element->data[2] == 0x4c &&
1928 info_element->data[3] == 0x033) {
1930 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
1931 if (tmp_htcap_len != 0) {
1932 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1933 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ?
1934 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
1935 memcpy(network->bssht.bdHTCapBuf, info_element->data, network->bssht.bdHTCapLen);
1938 if (tmp_htcap_len != 0) {
1939 network->bssht.bdSupportHT = true;
1940 network->bssht.bdHT1R = ((((struct ht_capab_ele *)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
1942 network->bssht.bdSupportHT = false;
1943 network->bssht.bdHT1R = false;
1948 if (tmp_htinfo_len == 0) {
1949 if (info_element->len >= 4 &&
1950 info_element->data[0] == 0x00 &&
1951 info_element->data[1] == 0x90 &&
1952 info_element->data[2] == 0x4c &&
1953 info_element->data[3] == 0x034) {
1954 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
1955 if (tmp_htinfo_len != 0) {
1956 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1957 if (tmp_htinfo_len) {
1958 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf) ?
1959 sizeof(network->bssht.bdHTInfoBuf) : tmp_htinfo_len;
1960 memcpy(network->bssht.bdHTInfoBuf, info_element->data, network->bssht.bdHTInfoLen);
1968 if (ieee->aggregation) {
1969 if (network->bssht.bdSupportHT) {
1970 if (info_element->len >= 4 &&
1971 info_element->data[0] == 0x00 &&
1972 info_element->data[1] == 0xe0 &&
1973 info_element->data[2] == 0x4c &&
1974 info_element->data[3] == 0x02) {
1975 ht_realtek_agg_len = min(info_element->len, (u8)MAX_IE_LEN);
1976 memcpy(ht_realtek_agg_buf, info_element->data, info_element->len);
1978 if (ht_realtek_agg_len >= 5) {
1979 network->realtek_cap_exit = true;
1980 network->bssht.bdRT2RTAggregation = true;
1982 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1983 network->bssht.bdRT2RTLongSlotTime = true;
1985 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
1986 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
1989 if (ht_realtek_agg_len >= 5) {
1990 if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
1991 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_SOFTAP;
1995 if ((info_element->len >= 3 &&
1996 info_element->data[0] == 0x00 &&
1997 info_element->data[1] == 0x05 &&
1998 info_element->data[2] == 0xb5) ||
1999 (info_element->len >= 3 &&
2000 info_element->data[0] == 0x00 &&
2001 info_element->data[1] == 0x0a &&
2002 info_element->data[2] == 0xf7) ||
2003 (info_element->len >= 3 &&
2004 info_element->data[0] == 0x00 &&
2005 info_element->data[1] == 0x10 &&
2006 info_element->data[2] == 0x18)) {
2007 network->broadcom_cap_exist = true;
2009 if (info_element->len >= 3 &&
2010 info_element->data[0] == 0x00 &&
2011 info_element->data[1] == 0x0c &&
2012 info_element->data[2] == 0x43)
2013 network->ralink_cap_exist = true;
2014 if ((info_element->len >= 3 &&
2015 info_element->data[0] == 0x00 &&
2016 info_element->data[1] == 0x03 &&
2017 info_element->data[2] == 0x7f) ||
2018 (info_element->len >= 3 &&
2019 info_element->data[0] == 0x00 &&
2020 info_element->data[1] == 0x13 &&
2021 info_element->data[2] == 0x74))
2022 network->atheros_cap_exist = true;
2024 if ((info_element->len >= 3 &&
2025 info_element->data[0] == 0x00 &&
2026 info_element->data[1] == 0x50 &&
2027 info_element->data[2] == 0x43))
2028 network->marvell_cap_exist = true;
2029 if (info_element->len >= 3 &&
2030 info_element->data[0] == 0x00 &&
2031 info_element->data[1] == 0x40 &&
2032 info_element->data[2] == 0x96)
2033 network->cisco_cap_exist = true;
2036 if (info_element->len >= 3 &&
2037 info_element->data[0] == 0x00 &&
2038 info_element->data[1] == 0x0a &&
2039 info_element->data[2] == 0xf5)
2040 network->airgo_cap_exist = true;
2042 if (info_element->len > 4 &&
2043 info_element->data[0] == 0x00 &&
2044 info_element->data[1] == 0x40 &&
2045 info_element->data[2] == 0x96 &&
2046 info_element->data[3] == 0x01) {
2047 if (info_element->len == 6) {
2048 memcpy(network->CcxRmState, &info_element[4], 2);
2049 if (network->CcxRmState[0] != 0)
2050 network->bCcxRmEnable = true;
2052 network->bCcxRmEnable = false;
2053 network->MBssidMask = network->CcxRmState[1] & 0x07;
2054 if (network->MBssidMask != 0) {
2055 network->bMBssidValid = true;
2056 network->MBssidMask = 0xff << (network->MBssidMask);
2057 memcpy(network->MBssid, network->bssid, ETH_ALEN);
2058 network->MBssid[5] &= network->MBssidMask;
2060 network->bMBssidValid = false;
2063 network->bCcxRmEnable = false;
2066 if (info_element->len > 4 &&
2067 info_element->data[0] == 0x00 &&
2068 info_element->data[1] == 0x40 &&
2069 info_element->data[2] == 0x96 &&
2070 info_element->data[3] == 0x03) {
2071 if (info_element->len == 5) {
2072 network->bWithCcxVerNum = true;
2073 network->BssCcxVerNumber = info_element->data[4];
2075 network->bWithCcxVerNum = false;
2076 network->BssCcxVerNumber = 0;
2079 if (info_element->len > 4 &&
2080 info_element->data[0] == 0x00 &&
2081 info_element->data[1] == 0x50 &&
2082 info_element->data[2] == 0xf2 &&
2083 info_element->data[3] == 0x04) {
2084 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
2086 network->wzc_ie_len = min(info_element->len+2,
2088 memcpy(network->wzc_ie, info_element,
2089 network->wzc_ie_len);
2094 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
2096 network->rsn_ie_len = min(info_element->len + 2,
2098 memcpy(network->rsn_ie, info_element,
2099 network->rsn_ie_len);
2102 case MFIE_TYPE_HT_CAP:
2103 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2105 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
2106 if (tmp_htcap_len != 0) {
2107 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2108 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ?
2109 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
2110 memcpy(network->bssht.bdHTCapBuf,
2112 network->bssht.bdHTCapLen);
2114 network->bssht.bdSupportHT = true;
2115 network->bssht.bdHT1R = ((((struct ht_capab_ele *)
2116 network->bssht.bdHTCapBuf))->MCS[1]) == 0;
2118 network->bssht.bdBandWidth = (enum ht_channel_width)
2119 (((struct ht_capab_ele *)
2120 (network->bssht.bdHTCapBuf))->ChlWidth);
2122 network->bssht.bdSupportHT = false;
2123 network->bssht.bdHT1R = false;
2124 network->bssht.bdBandWidth = HT_CHANNEL_WIDTH_20;
2129 case MFIE_TYPE_HT_INFO:
2130 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
2132 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
2133 if (tmp_htinfo_len) {
2134 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2135 network->bssht.bdHTInfoLen = tmp_htinfo_len >
2136 sizeof(network->bssht.bdHTInfoBuf) ?
2137 sizeof(network->bssht.bdHTInfoBuf) :
2139 memcpy(network->bssht.bdHTInfoBuf,
2141 network->bssht.bdHTInfoLen);
2145 case MFIE_TYPE_AIRONET:
2146 RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2148 if (info_element->len > IE_CISCO_FLAG_POSITION) {
2149 network->bWithAironetIE = true;
2151 if ((info_element->data[IE_CISCO_FLAG_POSITION]
2152 & SUPPORT_CKIP_MIC) ||
2153 (info_element->data[IE_CISCO_FLAG_POSITION]
2155 network->bCkipSupported = true;
2157 network->bCkipSupported = false;
2159 network->bWithAironetIE = false;
2160 network->bCkipSupported = false;
2163 case MFIE_TYPE_QOS_PARAMETER:
2165 "QoS Error need to parse QOS_PARAMETER IE\n");
2168 case MFIE_TYPE_COUNTRY:
2169 RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2171 rtllib_extract_country_ie(ieee, info_element, network,
2177 ("Unsupported info element: %s (%d)\n",
2178 get_info_element_string(info_element->id),
2183 length -= sizeof(*info_element) + info_element->len;
2185 (struct rtllib_info_element *)&info_element->
2186 data[info_element->len];
2189 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2190 !network->cisco_cap_exist && !network->ralink_cap_exist &&
2191 !network->bssht.bdRT2RTAggregation)
2192 network->unknown_cap_exist = true;
2194 network->unknown_cap_exist = false;
2198 static inline u8 rtllib_SignalStrengthTranslate(u8 CurrSS)
2202 if (CurrSS >= 71 && CurrSS <= 100)
2203 RetSS = 90 + ((CurrSS - 70) / 3);
2204 else if (CurrSS >= 41 && CurrSS <= 70)
2205 RetSS = 78 + ((CurrSS - 40) / 3);
2206 else if (CurrSS >= 31 && CurrSS <= 40)
2207 RetSS = 66 + (CurrSS - 30);
2208 else if (CurrSS >= 21 && CurrSS <= 30)
2209 RetSS = 54 + (CurrSS - 20);
2210 else if (CurrSS >= 5 && CurrSS <= 20)
2211 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2212 else if (CurrSS == 4)
2214 else if (CurrSS == 3)
2216 else if (CurrSS == 2)
2218 else if (CurrSS == 1)
2226 long rtllib_translate_todbm(u8 signal_strength_index)
2230 signal_power = (long)((signal_strength_index + 1) >> 1);
2233 return signal_power;
2236 static inline int rtllib_network_init(
2237 struct rtllib_device *ieee,
2238 struct rtllib_probe_response *beacon,
2239 struct rtllib_network *network,
2240 struct rtllib_rx_stats *stats)
2244 network->qos_data.active = 0;
2245 network->qos_data.supported = 0;
2246 network->qos_data.param_count = 0;
2247 network->qos_data.old_param_count = 0;
2249 memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
2251 /* Pull out fixed field data */
2252 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2253 network->capability = le16_to_cpu(beacon->capability);
2254 network->last_scanned = jiffies;
2255 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2256 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2257 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
2258 /* Where to pull this? beacon->listen_interval;*/
2259 network->listen_interval = 0x0A;
2260 network->rates_len = network->rates_ex_len = 0;
2261 network->last_associate = 0;
2262 network->ssid_len = 0;
2263 network->hidden_ssid_len = 0;
2264 memset(network->hidden_ssid, 0, sizeof(network->hidden_ssid));
2266 network->atim_window = 0;
2267 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2269 network->berp_info_valid = false;
2270 network->broadcom_cap_exist = false;
2271 network->ralink_cap_exist = false;
2272 network->atheros_cap_exist = false;
2273 network->cisco_cap_exist = false;
2274 network->unknown_cap_exist = false;
2275 network->realtek_cap_exit = false;
2276 network->marvell_cap_exist = false;
2277 network->airgo_cap_exist = false;
2278 network->Turbo_Enable = 0;
2279 network->SignalStrength = stats->SignalStrength;
2280 network->RSSI = stats->SignalStrength;
2281 network->CountryIeLen = 0;
2282 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2283 HTInitializeBssDesc(&network->bssht);
2284 if (stats->freq == RTLLIB_52GHZ_BAND) {
2285 /* for A band (No DS info) */
2286 network->channel = stats->received_channel;
2288 network->flags |= NETWORK_HAS_CCK;
2290 network->wpa_ie_len = 0;
2291 network->rsn_ie_len = 0;
2292 network->wzc_ie_len = 0;
2294 if (rtllib_parse_info_param(ieee,
2295 beacon->info_element,
2296 (stats->len - sizeof(*beacon)),
2302 if (stats->freq == RTLLIB_52GHZ_BAND)
2303 network->mode = IEEE_A;
2305 if (network->flags & NETWORK_HAS_OFDM)
2306 network->mode |= IEEE_G;
2307 if (network->flags & NETWORK_HAS_CCK)
2308 network->mode |= IEEE_B;
2311 if (network->mode == 0) {
2312 RTLLIB_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
2314 escape_essid(network->ssid,
2316 MAC_ARG(network->bssid));
2320 if (network->bssht.bdSupportHT) {
2321 if (network->mode == IEEE_A)
2322 network->mode = IEEE_N_5G;
2323 else if (network->mode & (IEEE_G | IEEE_B))
2324 network->mode = IEEE_N_24G;
2326 if (rtllib_is_empty_essid(network->ssid, network->ssid_len))
2327 network->flags |= NETWORK_EMPTY_ESSID;
2328 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2329 stats->noise = rtllib_translate_todbm((u8)(100-stats->signal)) - 25;
2331 memcpy(&network->stats, stats, sizeof(network->stats));
2336 static inline int is_same_network(struct rtllib_network *src,
2337 struct rtllib_network *dst, u8 ssidbroad)
2339 /* A network is only a duplicate if the channel, BSSID, ESSID
2340 * and the capability field (in particular IBSS and BSS) all match.
2341 * We treat all <hidden> with the same BSSID and channel
2343 return (((src->ssid_len == dst->ssid_len) || (!ssidbroad)) &&
2344 (src->channel == dst->channel) &&
2345 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2346 (!memcmp(src->ssid, dst->ssid, src->ssid_len) ||
2348 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2349 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2350 ((src->capability & WLAN_CAPABILITY_ESS) ==
2351 (dst->capability & WLAN_CAPABILITY_ESS)));
2354 static inline void update_ibss_network(struct rtllib_network *dst,
2355 struct rtllib_network *src)
2357 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
2358 dst->last_scanned = jiffies;
2362 static inline void update_network(struct rtllib_network *dst,
2363 struct rtllib_network *src)
2368 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
2369 dst->capability = src->capability;
2370 memcpy(dst->rates, src->rates, src->rates_len);
2371 dst->rates_len = src->rates_len;
2372 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2373 dst->rates_ex_len = src->rates_ex_len;
2374 if (src->ssid_len > 0) {
2375 if (dst->ssid_len == 0) {
2376 memset(dst->hidden_ssid, 0, sizeof(dst->hidden_ssid));
2377 dst->hidden_ssid_len = src->ssid_len;
2378 memcpy(dst->hidden_ssid, src->ssid, src->ssid_len);
2380 memset(dst->ssid, 0, dst->ssid_len);
2381 dst->ssid_len = src->ssid_len;
2382 memcpy(dst->ssid, src->ssid, src->ssid_len);
2385 dst->mode = src->mode;
2386 dst->flags = src->flags;
2387 dst->time_stamp[0] = src->time_stamp[0];
2388 dst->time_stamp[1] = src->time_stamp[1];
2389 if (src->flags & NETWORK_HAS_ERP_VALUE) {
2390 dst->erp_value = src->erp_value;
2391 dst->berp_info_valid = src->berp_info_valid = true;
2393 dst->beacon_interval = src->beacon_interval;
2394 dst->listen_interval = src->listen_interval;
2395 dst->atim_window = src->atim_window;
2396 dst->dtim_period = src->dtim_period;
2397 dst->dtim_data = src->dtim_data;
2398 dst->last_dtim_sta_time = src->last_dtim_sta_time;
2399 memcpy(&dst->tim, &src->tim, sizeof(struct rtllib_tim_parameters));
2401 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2402 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2403 dst->bssht.bdHTCapLen = src->bssht.bdHTCapLen;
2404 memcpy(dst->bssht.bdHTCapBuf, src->bssht.bdHTCapBuf,
2405 src->bssht.bdHTCapLen);
2406 dst->bssht.bdHTInfoLen = src->bssht.bdHTInfoLen;
2407 memcpy(dst->bssht.bdHTInfoBuf, src->bssht.bdHTInfoBuf,
2408 src->bssht.bdHTInfoLen);
2409 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2410 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2411 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2412 dst->ralink_cap_exist = src->ralink_cap_exist;
2413 dst->atheros_cap_exist = src->atheros_cap_exist;
2414 dst->realtek_cap_exit = src->realtek_cap_exit;
2415 dst->marvell_cap_exist = src->marvell_cap_exist;
2416 dst->cisco_cap_exist = src->cisco_cap_exist;
2417 dst->airgo_cap_exist = src->airgo_cap_exist;
2418 dst->unknown_cap_exist = src->unknown_cap_exist;
2419 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2420 dst->wpa_ie_len = src->wpa_ie_len;
2421 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2422 dst->rsn_ie_len = src->rsn_ie_len;
2423 memcpy(dst->wzc_ie, src->wzc_ie, src->wzc_ie_len);
2424 dst->wzc_ie_len = src->wzc_ie_len;
2426 dst->last_scanned = jiffies;
2427 /* qos related parameters */
2428 qos_active = dst->qos_data.active;
2429 old_param = dst->qos_data.param_count;
2430 dst->qos_data.supported = src->qos_data.supported;
2431 if (dst->flags & NETWORK_HAS_QOS_PARAMETERS)
2432 memcpy(&dst->qos_data, &src->qos_data,
2433 sizeof(struct rtllib_qos_data));
2434 if (dst->qos_data.supported == 1) {
2437 ("QoS the network %s is QoS supported\n",
2441 ("QoS the network is QoS supported\n");
2443 dst->qos_data.active = qos_active;
2444 dst->qos_data.old_param_count = old_param;
2446 /* dst->last_associate is not overwritten */
2447 dst->wmm_info = src->wmm_info;
2448 if (src->wmm_param[0].ac_aci_acm_aifsn ||
2449 src->wmm_param[1].ac_aci_acm_aifsn ||
2450 src->wmm_param[2].ac_aci_acm_aifsn ||
2451 src->wmm_param[1].ac_aci_acm_aifsn)
2452 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2454 dst->SignalStrength = src->SignalStrength;
2455 dst->RSSI = src->RSSI;
2456 dst->Turbo_Enable = src->Turbo_Enable;
2458 dst->CountryIeLen = src->CountryIeLen;
2459 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2461 dst->bWithAironetIE = src->bWithAironetIE;
2462 dst->bCkipSupported = src->bCkipSupported;
2463 memcpy(dst->CcxRmState, src->CcxRmState, 2);
2464 dst->bCcxRmEnable = src->bCcxRmEnable;
2465 dst->MBssidMask = src->MBssidMask;
2466 dst->bMBssidValid = src->bMBssidValid;
2467 memcpy(dst->MBssid, src->MBssid, 6);
2468 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2469 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2472 static inline int is_beacon(__le16 fc)
2474 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == RTLLIB_STYPE_BEACON);
2477 static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
2479 if (MAX_CHANNEL_NUMBER < channel) {
2480 printk(KERN_INFO "%s(): Invalid Channel\n", __func__);
2484 if (rtllib->active_channel_map[channel] == 2)
2490 int IsLegalChannel(struct rtllib_device *rtllib, u8 channel)
2492 if (MAX_CHANNEL_NUMBER < channel) {
2493 printk(KERN_INFO "%s(): Invalid Channel\n", __func__);
2496 if (rtllib->active_channel_map[channel] > 0)
2502 static inline void rtllib_process_probe_response(
2503 struct rtllib_device *ieee,
2504 struct rtllib_probe_response *beacon,
2505 struct rtllib_rx_stats *stats)
2507 struct rtllib_network *target;
2508 struct rtllib_network *oldest = NULL;
2509 struct rtllib_info_element *info_element = &beacon->info_element[0];
2510 unsigned long flags;
2512 struct rtllib_network *network = kzalloc(sizeof(struct rtllib_network),
2519 "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2520 escape_essid(info_element->data, info_element->len),
2521 MAC_ARG(beacon->header.addr3),
2522 (beacon->capability & (1<<0xf)) ? '1' : '0',
2523 (beacon->capability & (1<<0xe)) ? '1' : '0',
2524 (beacon->capability & (1<<0xd)) ? '1' : '0',
2525 (beacon->capability & (1<<0xc)) ? '1' : '0',
2526 (beacon->capability & (1<<0xb)) ? '1' : '0',
2527 (beacon->capability & (1<<0xa)) ? '1' : '0',
2528 (beacon->capability & (1<<0x9)) ? '1' : '0',
2529 (beacon->capability & (1<<0x8)) ? '1' : '0',
2530 (beacon->capability & (1<<0x7)) ? '1' : '0',
2531 (beacon->capability & (1<<0x6)) ? '1' : '0',
2532 (beacon->capability & (1<<0x5)) ? '1' : '0',
2533 (beacon->capability & (1<<0x4)) ? '1' : '0',
2534 (beacon->capability & (1<<0x3)) ? '1' : '0',
2535 (beacon->capability & (1<<0x2)) ? '1' : '0',
2536 (beacon->capability & (1<<0x1)) ? '1' : '0',
2537 (beacon->capability & (1<<0x0)) ? '1' : '0');
2539 if (rtllib_network_init(ieee, beacon, network, stats)) {
2540 RTLLIB_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
2541 escape_essid(info_element->data,
2543 MAC_ARG(beacon->header.addr3),
2544 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2545 RTLLIB_STYPE_PROBE_RESP ?
2546 "PROBE RESPONSE" : "BEACON");
2551 if (!IsLegalChannel(ieee, network->channel))
2554 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2555 RTLLIB_STYPE_PROBE_RESP) {
2556 if (IsPassiveChannel(ieee, network->channel)) {
2557 printk(KERN_INFO "GetScanInfo(): For Global Domain, "
2558 "filter probe response at channel(%d).\n",
2564 /* The network parsed correctly -- so now we scan our known networks
2565 * to see if we can find it in our list.
2567 * NOTE: This search is definitely not optimized. Once its doing
2568 * the "right thing" we'll optimize it for efficiency if
2571 /* Search for this entry in the list and update it if it is
2574 spin_lock_irqsave(&ieee->lock, flags);
2575 if (is_same_network(&ieee->current_network, network,
2576 (network->ssid_len ? 1 : 0))) {
2577 update_network(&ieee->current_network, network);
2578 if ((ieee->current_network.mode == IEEE_N_24G ||
2579 ieee->current_network.mode == IEEE_G)
2580 && ieee->current_network.berp_info_valid) {
2581 if (ieee->current_network.erp_value & ERP_UseProtection)
2582 ieee->current_network.buseprotection = true;
2584 ieee->current_network.buseprotection = false;
2586 if (is_beacon(beacon->header.frame_ctl)) {
2587 if (ieee->state >= RTLLIB_LINKED)
2588 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2591 list_for_each_entry(target, &ieee->network_list, list) {
2592 if (is_same_network(target, network,
2593 (target->ssid_len ? 1 : 0)))
2595 if ((oldest == NULL) ||
2596 (target->last_scanned < oldest->last_scanned))
2600 /* If we didn't find a match, then get a new network slot to initialize
2601 * with this beacon's information */
2602 if (&target->list == &ieee->network_list) {
2603 if (list_empty(&ieee->network_free_list)) {
2604 /* If there are no more slots, expire the oldest */
2605 list_del(&oldest->list);
2607 RTLLIB_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
2609 escape_essid(target->ssid,
2611 MAC_ARG(target->bssid));
2613 /* Otherwise just pull from the free list */
2614 target = list_entry(ieee->network_free_list.next,
2615 struct rtllib_network, list);
2616 list_del(ieee->network_free_list.next);
2620 RTLLIB_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
2621 escape_essid(network->ssid,
2623 MAC_ARG(network->bssid),
2624 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2625 RTLLIB_STYPE_PROBE_RESP ?
2626 "PROBE RESPONSE" : "BEACON");
2627 memcpy(target, network, sizeof(*target));
2628 list_add_tail(&target->list, &ieee->network_list);
2629 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2630 rtllib_softmac_new_net(ieee, network);
2632 RTLLIB_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
2633 escape_essid(target->ssid,
2635 MAC_ARG(target->bssid),
2636 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
2637 RTLLIB_STYPE_PROBE_RESP ?
2638 "PROBE RESPONSE" : "BEACON");
2640 /* we have an entry and we are going to update it. But this
2641 * entry may be already expired. In this case we do the same
2642 * as we found a new net and call the new_net handler
2644 renew = !time_after(target->last_scanned + ieee->scan_age,
2646 if ((!target->ssid_len) &&
2647 (((network->ssid_len > 0) && (target->hidden_ssid_len == 0))
2648 || ((ieee->current_network.ssid_len == network->ssid_len) &&
2649 (strncmp(ieee->current_network.ssid, network->ssid,
2650 network->ssid_len) == 0) &&
2651 (ieee->state == RTLLIB_NOLINK))))
2653 update_network(target, network);
2654 if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2655 rtllib_softmac_new_net(ieee, network);
2658 spin_unlock_irqrestore(&ieee->lock, flags);
2659 if (is_beacon(beacon->header.frame_ctl) &&
2660 is_same_network(&ieee->current_network, network,
2661 (network->ssid_len ? 1 : 0)) &&
2662 (ieee->state == RTLLIB_LINKED)) {
2663 if (ieee->handle_beacon != NULL)
2664 ieee->handle_beacon(ieee->dev, beacon,
2665 &ieee->current_network);
2672 void rtllib_rx_mgt(struct rtllib_device *ieee,
2673 struct sk_buff *skb,
2674 struct rtllib_rx_stats *stats)
2676 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data ;
2678 if (WLAN_FC_GET_STYPE(header->frame_ctl) != RTLLIB_STYPE_PROBE_RESP &&
2679 WLAN_FC_GET_STYPE(header->frame_ctl) != RTLLIB_STYPE_BEACON)
2680 ieee->last_rx_ps_time = jiffies;
2682 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2684 case RTLLIB_STYPE_BEACON:
2685 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
2686 WLAN_FC_GET_STYPE(header->frame_ctl));
2687 RTLLIB_DEBUG_SCAN("Beacon\n");
2688 rtllib_process_probe_response(
2689 ieee, (struct rtllib_probe_response *)header,
2692 if (ieee->sta_sleep || (ieee->ps != RTLLIB_PS_DISABLED &&
2693 ieee->iw_mode == IW_MODE_INFRA &&
2694 ieee->state == RTLLIB_LINKED))
2695 tasklet_schedule(&ieee->ps_task);
2699 case RTLLIB_STYPE_PROBE_RESP:
2700 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2701 WLAN_FC_GET_STYPE(header->frame_ctl));
2702 RTLLIB_DEBUG_SCAN("Probe response\n");
2703 rtllib_process_probe_response(ieee,
2704 (struct rtllib_probe_response *)header, stats);
2706 case RTLLIB_STYPE_PROBE_REQ:
2707 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
2708 WLAN_FC_GET_STYPE(header->frame_ctl));
2709 RTLLIB_DEBUG_SCAN("Probe request\n");
2710 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2711 ((ieee->iw_mode == IW_MODE_ADHOC ||
2712 ieee->iw_mode == IW_MODE_MASTER) &&
2713 ieee->state == RTLLIB_LINKED))
2714 rtllib_rx_probe_rq(ieee, skb);