1 // SPDX-License-Identifier: GPL-2.0
3 * Original code based Host AP (software wireless LAN access point) driver
4 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
6 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
9 * Copyright (c) 2004, Intel Corporation
11 * Few modifications for Realtek's Wi-Fi drivers by
14 * A special thanks goes to Realtek for their support !
16 #include <linux/compiler.h>
17 #include <linux/errno.h>
18 #include <linux/if_arp.h>
19 #include <linux/in6.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/netdevice.h>
25 #include <linux/pci.h>
26 #include <linux/proc_fs.h>
27 #include <linux/skbuff.h>
28 #include <linux/slab.h>
29 #include <linux/tcp.h>
30 #include <linux/types.h>
31 #include <linux/wireless.h>
32 #include <linux/etherdevice.h>
33 #include <linux/uaccess.h>
34 #include <linux/ctype.h>
39 static void rtllib_rx_mgt(struct rtllib_device *ieee, struct sk_buff *skb,
40 struct rtllib_rx_stats *stats);
42 static inline void rtllib_monitor_rx(struct rtllib_device *ieee,
44 struct rtllib_rx_stats *rx_status,
48 skb_reset_mac_header(skb);
49 skb_pull(skb, hdr_length);
50 skb->pkt_type = PACKET_OTHERHOST;
51 skb->protocol = htons(ETH_P_80211_RAW);
52 memset(skb->cb, 0, sizeof(skb->cb));
56 /* Called only as a tasklet (software IRQ) */
57 static struct rtllib_frag_entry *
58 rtllib_frag_cache_find(struct rtllib_device *ieee, unsigned int seq,
59 unsigned int frag, u8 tid, u8 *src, u8 *dst)
61 struct rtllib_frag_entry *entry;
64 for (i = 0; i < RTLLIB_FRAG_CACHE_LEN; i++) {
65 entry = &ieee->frag_cache[tid][i];
66 if (entry->skb != NULL &&
67 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
69 "expiring fragment cache entry seq=%u last_frag=%u\n",
70 entry->seq, entry->last_frag);
71 dev_kfree_skb_any(entry->skb);
75 if (entry->skb != NULL && entry->seq == seq &&
76 (entry->last_frag + 1 == frag || frag == -1) &&
77 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
78 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
85 /* Called only as a tasklet (software IRQ) */
86 static struct sk_buff *
87 rtllib_frag_cache_get(struct rtllib_device *ieee,
88 struct rtllib_hdr_4addr *hdr)
90 struct sk_buff *skb = NULL;
91 u16 fc = le16_to_cpu(hdr->frame_ctl);
92 u16 sc = le16_to_cpu(hdr->seq_ctl);
93 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
94 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
95 struct rtllib_frag_entry *entry;
96 struct rtllib_hdr_3addrqos *hdr_3addrqos;
97 struct rtllib_hdr_4addrqos *hdr_4addrqos;
100 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) &&
101 RTLLIB_QOS_HAS_SEQ(fc)) {
102 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
103 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
106 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
107 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)hdr;
108 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
116 /* Reserve enough space to fit maximum frame length */
117 skb = dev_alloc_skb(ieee->dev->mtu +
118 sizeof(struct rtllib_hdr_4addr) +
124 (RTLLIB_QOS_HAS_SEQ(fc) ? 2 : 0));
128 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
129 ieee->frag_next_idx[tid]++;
130 if (ieee->frag_next_idx[tid] >= RTLLIB_FRAG_CACHE_LEN)
131 ieee->frag_next_idx[tid] = 0;
133 if (entry->skb != NULL)
134 dev_kfree_skb_any(entry->skb);
136 entry->first_frag_time = jiffies;
138 entry->last_frag = frag;
140 ether_addr_copy(entry->src_addr, hdr->addr2);
141 ether_addr_copy(entry->dst_addr, hdr->addr1);
143 /* received a fragment of a frame for which the head fragment
144 * should have already been received
146 entry = rtllib_frag_cache_find(ieee, seq, frag, tid, hdr->addr2,
149 entry->last_frag = frag;
157 /* Called only as a tasklet (software IRQ) */
158 static int rtllib_frag_cache_invalidate(struct rtllib_device *ieee,
159 struct rtllib_hdr_4addr *hdr)
161 u16 fc = le16_to_cpu(hdr->frame_ctl);
162 u16 sc = le16_to_cpu(hdr->seq_ctl);
163 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
164 struct rtllib_frag_entry *entry;
165 struct rtllib_hdr_3addrqos *hdr_3addrqos;
166 struct rtllib_hdr_4addrqos *hdr_4addrqos;
169 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) &&
170 RTLLIB_QOS_HAS_SEQ(fc)) {
171 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
172 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
175 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
176 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)hdr;
177 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
184 entry = rtllib_frag_cache_find(ieee, seq, -1, tid, hdr->addr2,
188 netdev_dbg(ieee->dev,
189 "Couldn't invalidate fragment cache entry (seq=%u)\n",
198 /* rtllib_rx_frame_mgtmt
200 * Responsible for handling management control frames
202 * Called by rtllib_rx
205 rtllib_rx_frame_mgmt(struct rtllib_device *ieee, struct sk_buff *skb,
206 struct rtllib_rx_stats *rx_stats, u16 type,
209 /* On the struct stats definition there is written that
210 * this is not mandatory.... but seems that the probe
211 * response parser uses it
213 struct rtllib_hdr_3addr *hdr = (struct rtllib_hdr_3addr *)skb->data;
215 rx_stats->len = skb->len;
216 rtllib_rx_mgt(ieee, skb, rx_stats);
217 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN))) {
218 dev_kfree_skb_any(skb);
221 rtllib_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
223 dev_kfree_skb_any(skb);
228 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation
229 * Ethernet-II snap header (RFC1042 for most EtherTypes)
231 static unsigned char rfc1042_header[] = {
232 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
240 /* No encapsulation header if EtherType < 0x600 (=length) */
242 /* Called by rtllib_rx_frame_decrypt */
243 static int rtllib_is_eapol_frame(struct rtllib_device *ieee,
244 struct sk_buff *skb, size_t hdrlen)
246 struct net_device *dev = ieee->dev;
248 struct rtllib_hdr_4addr *hdr;
254 hdr = (struct rtllib_hdr_4addr *)skb->data;
255 fc = le16_to_cpu(hdr->frame_ctl);
257 /* check that the frame is unicast frame to us */
258 if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
260 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
261 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
262 /* ToDS frame with own addr BSSID and DA */
263 } else if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
264 RTLLIB_FCTL_FROMDS &&
265 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
266 /* FromDS frame with own addr as DA */
270 if (skb->len < 24 + 8)
273 /* check for port access entity Ethernet type */
274 pos = skb->data + hdrlen;
275 ethertype = (pos[6] << 8) | pos[7];
276 if (ethertype == ETH_P_PAE)
282 /* Called only as a tasklet (software IRQ), by rtllib_rx */
284 rtllib_rx_frame_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
285 struct lib80211_crypt_data *crypt)
287 struct rtllib_hdr_4addr *hdr;
290 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
293 if (ieee->hwsec_active) {
294 struct cb_desc *tcb_desc = (struct cb_desc *)
295 (skb->cb + MAX_DEV_ADDR_SIZE);
297 tcb_desc->bHwSec = 1;
299 if (ieee->need_sw_enc)
300 tcb_desc->bHwSec = 0;
303 hdr = (struct rtllib_hdr_4addr *)skb->data;
304 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
306 atomic_inc(&crypt->refcnt);
307 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
308 atomic_dec(&crypt->refcnt);
310 netdev_dbg(ieee->dev, "decryption failed (SA= %pM) res=%d\n",
313 netdev_dbg(ieee->dev,
314 "Decryption failed ICV mismatch (key %d)\n",
315 skb->data[hdrlen + 3] >> 6);
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 *)
334 (skb->cb + MAX_DEV_ADDR_SIZE);
336 tcb_desc->bHwSec = 1;
338 if (ieee->need_sw_enc)
339 tcb_desc->bHwSec = 0;
342 hdr = (struct rtllib_hdr_4addr *)skb->data;
343 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
345 atomic_inc(&crypt->refcnt);
346 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
347 atomic_dec(&crypt->refcnt);
349 netdev_dbg(ieee->dev,
350 "MSDU decryption/MIC verification failed (SA= %pM keyidx=%d)\n",
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) &&
374 RTLLIB_QOS_HAS_SEQ(fc)) {
375 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)header;
376 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
379 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
380 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)header;
381 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
388 switch (ieee->iw_mode) {
392 struct ieee_ibss_seq *entry = NULL;
393 u8 *mac = header->addr2;
394 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
396 list_for_each(p, &ieee->ibss_mac_hash[index]) {
397 entry = list_entry(p, struct ieee_ibss_seq, list);
398 if (!memcmp(entry->mac, mac, ETH_ALEN))
401 if (p == &ieee->ibss_mac_hash[index]) {
402 entry = kmalloc(sizeof(struct ieee_ibss_seq),
407 ether_addr_copy(entry->mac, mac);
408 entry->seq_num[tid] = seq;
409 entry->frag_num[tid] = frag;
410 entry->packet_time[tid] = jiffies;
411 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
414 last_seq = &entry->seq_num[tid];
415 last_frag = &entry->frag_num[tid];
416 last_time = &entry->packet_time[tid];
421 last_seq = &ieee->last_rxseq_num[tid];
422 last_frag = &ieee->last_rxfrag_num[tid];
423 last_time = &ieee->last_packet_time[tid];
429 if ((*last_seq == seq) &&
430 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
431 if (*last_frag == frag)
433 if (*last_frag + 1 != frag)
434 /* out-of-order fragment */
440 *last_time = jiffies;
448 static bool AddReorderEntry(struct rx_ts_record *pTS,
449 struct rx_reorder_entry *pReorderEntry)
451 struct list_head *pList = &pTS->rx_pending_pkt_list;
453 while (pList->next != &pTS->rx_pending_pkt_list) {
454 if (SN_LESS(pReorderEntry->SeqNum, ((struct rx_reorder_entry *)
455 list_entry(pList->next, struct rx_reorder_entry,
458 else if (SN_EQUAL(pReorderEntry->SeqNum,
459 ((struct rx_reorder_entry *)list_entry(pList->next,
460 struct rx_reorder_entry, List))->SeqNum))
465 pReorderEntry->List.next = pList->next;
466 pReorderEntry->List.next->prev = &pReorderEntry->List;
467 pReorderEntry->List.prev = pList;
468 pList->next = &pReorderEntry->List;
473 void rtllib_indicate_packets(struct rtllib_device *ieee,
474 struct rtllib_rxb **prxbIndicateArray, u8 index)
476 struct net_device_stats *stats = &ieee->stats;
480 for (j = 0; j < index; j++) {
481 struct rtllib_rxb *prxb = prxbIndicateArray[j];
483 for (i = 0; i < prxb->nr_subframes; i++) {
484 struct sk_buff *sub_skb = prxb->subframes[i];
486 /* convert hdr + possible LLC headers into Ethernet header */
487 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
488 if (sub_skb->len >= 8 &&
489 ((memcmp(sub_skb->data, rfc1042_header,
491 ethertype != ETH_P_AARP &&
492 ethertype != ETH_P_IPX) ||
493 memcmp(sub_skb->data, bridge_tunnel_header,
495 /* remove RFC1042 or Bridge-Tunnel encapsulation
496 * and replace EtherType
498 skb_pull(sub_skb, SNAP_SIZE);
499 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
500 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
503 /* Leave Ethernet header part of hdr and full payload */
505 memcpy(skb_push(sub_skb, 2), &len, 2);
506 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
507 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
510 /* Indicate the packets to upper layer */
513 stats->rx_bytes += sub_skb->len;
515 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
516 sub_skb->protocol = eth_type_trans(sub_skb,
518 sub_skb->dev = ieee->dev;
519 sub_skb->dev->stats.rx_packets++;
520 sub_skb->dev->stats.rx_bytes += sub_skb->len;
521 /* 802.11 crc not sufficient */
522 sub_skb->ip_summed = CHECKSUM_NONE;
523 ieee->last_rx_ps_time = jiffies;
532 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
533 struct rx_ts_record *pTS)
535 struct rx_reorder_entry *pRxReorderEntry;
538 del_timer_sync(&pTS->rx_pkt_pending_timer);
539 while (!list_empty(&pTS->rx_pending_pkt_list)) {
540 if (RfdCnt >= REORDER_WIN_SIZE) {
541 netdev_info(ieee->dev,
542 "-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n",
547 pRxReorderEntry = (struct rx_reorder_entry *)
548 list_entry(pTS->rx_pending_pkt_list.prev,
549 struct rx_reorder_entry, List);
550 netdev_dbg(ieee->dev, "%s(): Indicate SeqNum %d!\n", __func__,
551 pRxReorderEntry->SeqNum);
552 list_del_init(&pRxReorderEntry->List);
554 ieee->RfdArray[RfdCnt] = pRxReorderEntry->prxb;
557 list_add_tail(&pRxReorderEntry->List,
558 &ieee->RxReorder_Unused_List);
560 rtllib_indicate_packets(ieee, ieee->RfdArray, RfdCnt);
562 pTS->rx_indicate_seq = 0xffff;
565 static void RxReorderIndicatePacket(struct rtllib_device *ieee,
566 struct rtllib_rxb *prxb,
567 struct rx_ts_record *pTS, u16 SeqNum)
569 struct rt_hi_throughput *ht_info = ieee->ht_info;
570 struct rx_reorder_entry *pReorderEntry = NULL;
571 u8 WinSize = ht_info->rx_reorder_win_size;
574 bool bMatchWinStart = false, bPktInBuf = false;
577 netdev_dbg(ieee->dev,
578 "%s(): Seq is %d, pTS->rx_indicate_seq is %d, WinSize is %d\n",
579 __func__, SeqNum, pTS->rx_indicate_seq, WinSize);
581 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
583 WinEnd = (pTS->rx_indicate_seq + WinSize - 1) % 4096;
584 /* Rx Reorder initialize condition.*/
585 if (pTS->rx_indicate_seq == 0xffff)
586 pTS->rx_indicate_seq = SeqNum;
588 /* Drop out the packet which SeqNum is smaller than WinStart */
589 if (SN_LESS(SeqNum, pTS->rx_indicate_seq)) {
590 netdev_dbg(ieee->dev,
591 "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
592 pTS->rx_indicate_seq, SeqNum);
593 ht_info->rx_reorder_drop_counter++;
597 for (i = 0; i < prxb->nr_subframes; i++)
598 dev_kfree_skb(prxb->subframes[i]);
602 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
606 /* Sliding window manipulation. Conditions includes:
607 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
608 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
610 if (SN_EQUAL(SeqNum, pTS->rx_indicate_seq)) {
611 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) % 4096;
612 bMatchWinStart = true;
613 } else if (SN_LESS(WinEnd, SeqNum)) {
614 if (SeqNum >= (WinSize - 1))
615 pTS->rx_indicate_seq = SeqNum + 1 - WinSize;
617 pTS->rx_indicate_seq = 4095 -
618 (WinSize - (SeqNum + 1)) + 1;
619 netdev_dbg(ieee->dev,
620 "Window Shift! IndicateSeq: %d, NewSeq: %d\n",
621 pTS->rx_indicate_seq, SeqNum);
624 /* Indication process.
625 * After Packet dropping and Sliding Window shifting as above, we can
626 * now just indicate the packets with the SeqNum smaller than latest
627 * WinStart and struct buffer other packets.
629 * For Rx Reorder condition:
630 * 1. All packets with SeqNum smaller than WinStart => Indicate
631 * 2. All packets with SeqNum larger than or equal to
632 * WinStart => Buffer it.
634 if (bMatchWinStart) {
635 /* Current packet is going to be indicated.*/
636 netdev_dbg(ieee->dev,
637 "Packets indication! IndicateSeq: %d, NewSeq: %d\n",
638 pTS->rx_indicate_seq, SeqNum);
639 ieee->prxbIndicateArray[0] = prxb;
642 /* Current packet is going to be inserted into pending list.*/
643 if (!list_empty(&ieee->RxReorder_Unused_List)) {
644 pReorderEntry = (struct rx_reorder_entry *)
645 list_entry(ieee->RxReorder_Unused_List.next,
646 struct rx_reorder_entry, List);
647 list_del_init(&pReorderEntry->List);
649 /* Make a reorder entry and insert
650 * into a the packet list.
652 pReorderEntry->SeqNum = SeqNum;
653 pReorderEntry->prxb = prxb;
655 if (!AddReorderEntry(pTS, pReorderEntry)) {
658 netdev_dbg(ieee->dev,
659 "%s(): Duplicate packet is dropped. IndicateSeq: %d, NewSeq: %d\n",
660 __func__, pTS->rx_indicate_seq,
662 list_add_tail(&pReorderEntry->List,
663 &ieee->RxReorder_Unused_List);
665 for (i = 0; i < prxb->nr_subframes; i++)
666 dev_kfree_skb(prxb->subframes[i]);
670 netdev_dbg(ieee->dev,
671 "Pkt insert into struct buffer. IndicateSeq: %d, NewSeq: %d\n",
672 pTS->rx_indicate_seq, SeqNum);
675 /* Packets are dropped if there are not enough reorder
676 * entries. This part should be modified!! We can just
677 * indicate all the packets in struct buffer and get
680 netdev_err(ieee->dev,
681 "%s(): There is no reorder entry! Packet is dropped!\n",
686 for (i = 0; i < prxb->nr_subframes; i++)
687 dev_kfree_skb(prxb->subframes[i]);
694 /* Check if there is any packet need indicate.*/
695 while (!list_empty(&pTS->rx_pending_pkt_list)) {
696 netdev_dbg(ieee->dev, "%s(): start RREORDER indicate\n",
699 pReorderEntry = (struct rx_reorder_entry *)
700 list_entry(pTS->rx_pending_pkt_list.prev,
701 struct rx_reorder_entry,
703 if (SN_LESS(pReorderEntry->SeqNum, pTS->rx_indicate_seq) ||
704 SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq)) {
705 /* This protect struct buffer from overflow. */
706 if (index >= REORDER_WIN_SIZE) {
707 netdev_err(ieee->dev,
708 "%s(): Buffer overflow!\n",
714 list_del_init(&pReorderEntry->List);
716 if (SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq))
717 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) %
720 ieee->prxbIndicateArray[index] = pReorderEntry->prxb;
721 netdev_dbg(ieee->dev, "%s(): Indicate SeqNum %d!\n",
722 __func__, pReorderEntry->SeqNum);
725 list_add_tail(&pReorderEntry->List,
726 &ieee->RxReorder_Unused_List);
733 /* Handling pending timer. Set this timer to prevent from long time
737 if (timer_pending(&pTS->rx_pkt_pending_timer))
738 del_timer_sync(&pTS->rx_pkt_pending_timer);
739 pTS->rx_timeout_indicate_seq = 0xffff;
741 if (index > REORDER_WIN_SIZE) {
742 netdev_err(ieee->dev,
743 "%s(): Rx Reorder struct buffer full!\n",
745 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
749 rtllib_indicate_packets(ieee, ieee->prxbIndicateArray, index);
753 if (bPktInBuf && pTS->rx_timeout_indicate_seq == 0xffff) {
754 netdev_dbg(ieee->dev, "%s(): SET rx timeout timer\n", __func__);
755 pTS->rx_timeout_indicate_seq = pTS->rx_indicate_seq;
756 mod_timer(&pTS->rx_pkt_pending_timer, jiffies +
757 msecs_to_jiffies(ht_info->rx_reorder_pending_time));
759 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
762 static u8 parse_subframe(struct rtllib_device *ieee, struct sk_buff *skb,
763 struct rtllib_rx_stats *rx_stats,
764 struct rtllib_rxb *rxb, u8 *src, u8 *dst)
766 struct rtllib_hdr_3addr *hdr = (struct rtllib_hdr_3addr *)skb->data;
767 u16 fc = le16_to_cpu(hdr->frame_ctl);
769 u16 LLCOffset = sizeof(struct rtllib_hdr_3addr);
771 bool bIsAggregateFrame = false;
772 u16 nSubframe_Length;
773 u8 nPadding_Length = 0;
775 struct sk_buff *sub_skb;
776 /* just for debug purpose */
777 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
778 if ((RTLLIB_QOS_HAS_SEQ(fc)) &&
779 (((union frameqos *)(skb->data + RTLLIB_3ADDR_LEN))->field.reserved))
780 bIsAggregateFrame = true;
782 if (RTLLIB_QOS_HAS_SEQ(fc))
784 if (rx_stats->bContainHTC)
785 LLCOffset += sHTCLng;
787 ChkLength = LLCOffset;
789 if (skb->len <= ChkLength)
792 skb_pull(skb, LLCOffset);
793 ieee->bIsAggregateFrame = bIsAggregateFrame;
794 if (!bIsAggregateFrame) {
795 rxb->nr_subframes = 1;
797 /* altered by clark 3/30/2010
798 * The struct buffer size of the skb indicated to upper layer
799 * must be less than 5000, or the defraged IP datagram
800 * in the IP layer will exceed "ipfrag_high_tresh" and be
801 * discarded. so there must not use the function
802 * "skb_copy" and "skb_clone" for "skb".
805 /* Allocate new skb for releasing to upper layer */
806 sub_skb = dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE);
809 skb_reserve(sub_skb, 12);
810 skb_put_data(sub_skb, skb->data, skb->len);
811 sub_skb->dev = ieee->dev;
813 rxb->subframes[0] = sub_skb;
815 memcpy(rxb->src, src, ETH_ALEN);
816 memcpy(rxb->dst, dst, ETH_ALEN);
817 rxb->subframes[0]->dev = ieee->dev;
821 rxb->nr_subframes = 0;
822 memcpy(rxb->src, src, ETH_ALEN);
823 memcpy(rxb->dst, dst, ETH_ALEN);
824 while (skb->len > ETHERNET_HEADER_SIZE) {
825 /* Offset 12 denote 2 mac address */
826 nSubframe_Length = *((u16 *)(skb->data + 12));
827 nSubframe_Length = (nSubframe_Length >> 8) +
828 (nSubframe_Length << 8);
830 if (skb->len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
831 netdev_info(ieee->dev,
832 "%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",
833 __func__, rxb->nr_subframes);
834 netdev_info(ieee->dev,
835 "%s: A-MSDU parse error!! Subframe Length: %d\n",
836 __func__, nSubframe_Length);
837 netdev_info(ieee->dev,
838 "nRemain_Length is %d and nSubframe_Length is : %d\n",
839 skb->len, nSubframe_Length);
840 netdev_info(ieee->dev,
841 "The Packet SeqNum is %d\n",
846 /* move the data point to data content */
847 skb_pull(skb, ETHERNET_HEADER_SIZE);
849 /* altered by clark 3/30/2010
850 * The struct buffer size of the skb indicated to upper layer
851 * must be less than 5000, or the defraged IP datagram
852 * in the IP layer will exceed "ipfrag_high_tresh" and be
853 * discarded. so there must not use the function
854 * "skb_copy" and "skb_clone" for "skb".
857 /* Allocate new skb for releasing to upper layer */
858 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
861 skb_reserve(sub_skb, 12);
862 skb_put_data(sub_skb, skb->data, nSubframe_Length);
864 sub_skb->dev = ieee->dev;
865 rxb->subframes[rxb->nr_subframes++] = sub_skb;
866 if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
867 netdev_dbg(ieee->dev,
868 "ParseSubframe(): Too many Subframes! Packets dropped!\n");
871 skb_pull(skb, nSubframe_Length);
874 nPadding_Length = 4 - ((nSubframe_Length +
875 ETHERNET_HEADER_SIZE) % 4);
876 if (nPadding_Length == 4)
879 if (skb->len < nPadding_Length)
882 skb_pull(skb, nPadding_Length);
886 return rxb->nr_subframes;
889 static size_t rtllib_rx_get_hdrlen(struct rtllib_device *ieee,
891 struct rtllib_rx_stats *rx_stats)
893 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
894 u16 fc = le16_to_cpu(hdr->frame_ctl);
897 hdrlen = rtllib_get_hdrlen(fc);
898 if (HTCCheck(ieee, skb->data)) {
900 netdev_info(ieee->dev, "%s: find HTCControl!\n",
903 rx_stats->bContainHTC = true;
906 if (RTLLIB_QOS_HAS_SEQ(fc))
907 rx_stats->bIsQosData = true;
912 static int rtllib_rx_check_duplicate(struct rtllib_device *ieee,
913 struct sk_buff *skb, u8 multicast)
915 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
917 u8 frag, type, stype;
919 fc = le16_to_cpu(hdr->frame_ctl);
920 type = WLAN_FC_GET_TYPE(fc);
921 stype = WLAN_FC_GET_STYPE(fc);
922 sc = le16_to_cpu(hdr->seq_ctl);
923 frag = WLAN_GET_SEQ_FRAG(sc);
925 if (!ieee->ht_info->cur_rx_reorder_enable ||
926 !ieee->current_network.qos_data.active ||
927 !IsDataFrame(skb->data) ||
928 IsLegacyDataFrame(skb->data)) {
929 if (!((type == RTLLIB_FTYPE_MGMT) &&
930 (stype == RTLLIB_STYPE_BEACON))) {
931 if (is_duplicate_packet(ieee, hdr))
935 struct rx_ts_record *pRxTS = NULL;
937 if (GetTs(ieee, (struct ts_common_info **)&pRxTS, hdr->addr2,
938 (u8)Frame_QoSTID((u8 *)(skb->data)), RX_DIR, true)) {
939 if ((fc & (1 << 11)) && (frag == pRxTS->rx_last_frag_num) &&
940 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->rx_last_seq_num))
942 pRxTS->rx_last_frag_num = frag;
943 pRxTS->rx_last_seq_num = WLAN_GET_SEQ_SEQ(sc);
945 netdev_warn(ieee->dev, "%s(): No TS! Skip the check!\n",
954 static void rtllib_rx_extract_addr(struct rtllib_device *ieee,
955 struct rtllib_hdr_4addr *hdr, u8 *dst,
958 u16 fc = le16_to_cpu(hdr->frame_ctl);
960 switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
961 case RTLLIB_FCTL_FROMDS:
962 ether_addr_copy(dst, hdr->addr1);
963 ether_addr_copy(src, hdr->addr3);
964 ether_addr_copy(bssid, hdr->addr2);
966 case RTLLIB_FCTL_TODS:
967 ether_addr_copy(dst, hdr->addr3);
968 ether_addr_copy(src, hdr->addr2);
969 ether_addr_copy(bssid, hdr->addr1);
971 case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
972 ether_addr_copy(dst, hdr->addr3);
973 ether_addr_copy(src, hdr->addr4);
974 ether_addr_copy(bssid, ieee->current_network.bssid);
977 ether_addr_copy(dst, hdr->addr1);
978 ether_addr_copy(src, hdr->addr2);
979 ether_addr_copy(bssid, hdr->addr3);
984 static int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc,
985 u8 *dst, u8 *src, u8 *bssid, u8 *addr2)
989 type = WLAN_FC_GET_TYPE(fc);
990 stype = WLAN_FC_GET_STYPE(fc);
992 /* Filter frames from different BSS */
993 if (((fc & RTLLIB_FCTL_DSTODS) != RTLLIB_FCTL_DSTODS) &&
994 !ether_addr_equal(ieee->current_network.bssid, bssid) &&
995 !is_zero_ether_addr(ieee->current_network.bssid)) {
999 /* Filter packets sent by an STA that will be forwarded by AP */
1000 if (ieee->intel_promiscuous_md_info.promiscuous_on &&
1001 ieee->intel_promiscuous_md_info.fltr_src_sta_frame) {
1002 if ((fc & RTLLIB_FCTL_TODS) && !(fc & RTLLIB_FCTL_FROMDS) &&
1003 !ether_addr_equal(dst, ieee->current_network.bssid) &&
1004 ether_addr_equal(bssid, ieee->current_network.bssid)) {
1009 /* Nullfunc frames may have PS-bit set, so they must be passed to
1010 * hostap_handle_sta_rx() before being dropped here.
1012 if (!ieee->intel_promiscuous_md_info.promiscuous_on) {
1013 if (stype != RTLLIB_STYPE_DATA &&
1014 stype != RTLLIB_STYPE_DATA_CFACK &&
1015 stype != RTLLIB_STYPE_DATA_CFPOLL &&
1016 stype != RTLLIB_STYPE_DATA_CFACKPOLL &&
1017 stype != RTLLIB_STYPE_QOS_DATA) {
1018 if (stype != RTLLIB_STYPE_NULLFUNC)
1019 netdev_dbg(ieee->dev,
1020 "RX: dropped data frame with no data (type=0x%02x, subtype=0x%02x)\n",
1026 if (ieee->iw_mode != IW_MODE_MESH) {
1027 /* packets from our adapter are dropped (echo) */
1028 if (!memcmp(src, ieee->dev->dev_addr, ETH_ALEN))
1031 /* {broad,multi}cast packets to our BSS go through */
1032 if (is_multicast_ether_addr(dst)) {
1033 if (memcmp(bssid, ieee->current_network.bssid,
1041 static int rtllib_rx_get_crypt(struct rtllib_device *ieee, struct sk_buff *skb,
1042 struct lib80211_crypt_data **crypt, size_t hdrlen)
1044 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1045 u16 fc = le16_to_cpu(hdr->frame_ctl);
1048 if (ieee->host_decrypt) {
1049 if (skb->len >= hdrlen + 3)
1050 idx = skb->data[hdrlen + 3] >> 6;
1052 *crypt = ieee->crypt_info.crypt[idx];
1053 /* allow NULL decrypt to indicate an station specific override
1054 * for default encryption
1056 if (*crypt && ((*crypt)->ops == NULL ||
1057 (*crypt)->ops->decrypt_mpdu == NULL))
1060 if (!*crypt && (fc & RTLLIB_FCTL_WEP)) {
1061 /* This seems to be triggered by some (multicast?)
1062 * frames from other than current BSS, so just drop the
1063 * frames silently instead of filling system log with
1066 netdev_dbg(ieee->dev,
1067 "Decryption failed (not set) (SA= %pM)\n",
1076 static int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
1077 struct rtllib_rx_stats *rx_stats,
1078 struct lib80211_crypt_data *crypt, size_t hdrlen)
1080 struct rtllib_hdr_4addr *hdr;
1085 hdr = (struct rtllib_hdr_4addr *)skb->data;
1086 fc = le16_to_cpu(hdr->frame_ctl);
1087 sc = le16_to_cpu(hdr->seq_ctl);
1088 frag = WLAN_GET_SEQ_FRAG(sc);
1090 if ((!rx_stats->Decrypted))
1091 ieee->need_sw_enc = 1;
1093 ieee->need_sw_enc = 0;
1095 keyidx = rtllib_rx_frame_decrypt(ieee, skb, crypt);
1096 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) && (keyidx < 0)) {
1097 netdev_info(ieee->dev, "%s: decrypt frame error\n", __func__);
1101 hdr = (struct rtllib_hdr_4addr *)skb->data;
1102 if ((frag != 0 || (fc & RTLLIB_FCTL_MOREFRAGS))) {
1104 struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
1106 netdev_dbg(ieee->dev, "Rx Fragment received (%u)\n", frag);
1109 netdev_dbg(ieee->dev,
1110 "Rx cannot get skb from fragment cache (morefrag=%d seq=%u frag=%u)\n",
1111 (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
1112 WLAN_GET_SEQ_SEQ(sc), frag);
1119 if (frag_skb->tail + flen > frag_skb->end) {
1120 netdev_warn(ieee->dev,
1121 "%s: host decrypted and reassembled frame did not fit skb\n",
1123 rtllib_frag_cache_invalidate(ieee, hdr);
1128 /* copy first fragment (including full headers) into
1129 * beginning of the fragment cache skb
1131 skb_put_data(frag_skb, skb->data, flen);
1133 /* append frame payload to the end of the fragment
1136 skb_put_data(frag_skb, skb->data + hdrlen, flen);
1138 dev_kfree_skb_any(skb);
1141 if (fc & RTLLIB_FCTL_MOREFRAGS) {
1142 /* more fragments expected - leave the skb in fragment
1143 * cache for now; it will be delivered to upper layers
1144 * after all fragments have been received
1149 /* this was the last fragment and the frame will be
1150 * delivered, so remove skb from fragment cache
1153 hdr = (struct rtllib_hdr_4addr *)skb->data;
1154 rtllib_frag_cache_invalidate(ieee, hdr);
1157 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1158 * encrypted/authenticated
1160 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
1161 rtllib_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
1162 netdev_info(ieee->dev, "%s: ==>decrypt msdu error\n", __func__);
1166 hdr = (struct rtllib_hdr_4addr *)skb->data;
1167 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep) {
1168 if (/*ieee->ieee802_1x &&*/
1169 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1170 /* pass unencrypted EAPOL frames even if encryption is
1173 struct eapol *eap = (struct eapol *)(skb->data +
1175 netdev_dbg(ieee->dev,
1176 "RX: IEEE 802.1X EAPOL frame: %s\n",
1177 eap_get_type(eap->type));
1179 netdev_dbg(ieee->dev,
1180 "encryption configured, but RX frame not encrypted (SA= %pM)\n",
1186 if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
1187 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1188 struct eapol *eap = (struct eapol *)(skb->data + 24);
1190 netdev_dbg(ieee->dev, "RX: IEEE 802.1X EAPOL frame: %s\n",
1191 eap_get_type(eap->type));
1194 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
1195 !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1196 netdev_dbg(ieee->dev,
1197 "dropped unencrypted RX data frame from %pM (drop_unencrypted=1)\n",
1205 static void rtllib_rx_check_leave_lps(struct rtllib_device *ieee, u8 unicast,
1209 if (ieee->state == RTLLIB_LINKED) {
1210 if (((ieee->link_detect_info.NumRxUnicastOkInPeriod +
1211 ieee->link_detect_info.NumTxOkInPeriod) > 8) ||
1212 (ieee->link_detect_info.NumRxUnicastOkInPeriod > 2)) {
1213 ieee->LeisurePSLeave(ieee->dev);
1217 ieee->last_rx_ps_time = jiffies;
1220 static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
1221 struct rtllib_rx_stats *rx_stats,
1222 struct rtllib_rxb *rxb,
1226 struct net_device *dev = ieee->dev;
1231 netdev_info(dev, "%s: rxb is NULL!!\n", __func__);
1235 for (i = 0; i < rxb->nr_subframes; i++) {
1236 struct sk_buff *sub_skb = rxb->subframes[i];
1239 /* convert hdr + possible LLC headers
1240 * into Ethernet header
1242 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1243 if (sub_skb->len >= 8 &&
1244 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1245 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1246 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1247 /* remove RFC1042 or Bridge-Tunnel encapsulation
1248 * and replace EtherType
1250 skb_pull(sub_skb, SNAP_SIZE);
1251 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1253 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1257 /* Leave Ethernet header part of hdr
1261 memcpy(skb_push(sub_skb, 2), &len, 2);
1262 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1264 ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
1268 ieee->stats.rx_packets++;
1269 ieee->stats.rx_bytes += sub_skb->len;
1271 if (is_multicast_ether_addr(dst))
1272 ieee->stats.multicast++;
1274 /* Indicate the packets to upper layer */
1275 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1276 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1278 sub_skb->dev->stats.rx_packets++;
1279 sub_skb->dev->stats.rx_bytes += sub_skb->len;
1280 /* 802.11 crc not sufficient */
1281 sub_skb->ip_summed = CHECKSUM_NONE;
1288 static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1289 struct rtllib_rx_stats *rx_stats)
1291 struct net_device *dev = ieee->dev;
1292 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1293 struct lib80211_crypt_data *crypt = NULL;
1294 struct rtllib_rxb *rxb = NULL;
1295 struct rx_ts_record *pTS = NULL;
1296 u16 fc, sc, SeqNum = 0;
1297 u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0;
1300 u8 bssid[ETH_ALEN] = {0};
1303 bool bToOtherSTA = false;
1306 fc = le16_to_cpu(hdr->frame_ctl);
1307 type = WLAN_FC_GET_TYPE(fc);
1308 stype = WLAN_FC_GET_STYPE(fc);
1309 sc = le16_to_cpu(hdr->seq_ctl);
1311 /*Filter pkt not to me*/
1312 multicast = is_multicast_ether_addr(hdr->addr1);
1313 unicast = !multicast;
1314 if (unicast && !ether_addr_equal(dev->dev_addr, hdr->addr1)) {
1315 if (ieee->net_promiscuous_md)
1321 /*Filter pkt has too small length */
1322 hdrlen = rtllib_rx_get_hdrlen(ieee, skb, rx_stats);
1323 if (skb->len < hdrlen) {
1325 "%s():ERR!!! skb->len is smaller than hdrlen\n",
1330 /* Filter Duplicate pkt */
1331 ret = rtllib_rx_check_duplicate(ieee, skb, multicast);
1335 /* Filter CTRL Frame */
1336 if (type == RTLLIB_FTYPE_CTL)
1339 /* Filter MGNT Frame */
1340 if (type == RTLLIB_FTYPE_MGMT) {
1343 if (rtllib_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1349 /* Filter WAPI DATA Frame */
1351 /* Update statstics for AP roaming */
1353 ieee->link_detect_info.NumRecvDataInPeriod++;
1354 ieee->link_detect_info.NumRxOkInPeriod++;
1357 /* Data frame - extract src/dst addresses */
1358 rtllib_rx_extract_addr(ieee, hdr, dst, src, bssid);
1360 /* Filter Data frames */
1361 ret = rtllib_rx_data_filter(ieee, fc, dst, src, bssid, hdr->addr2);
1365 if (skb->len == hdrlen)
1368 /* Send pspoll based on moredata */
1369 if ((ieee->iw_mode == IW_MODE_INFRA) &&
1370 (ieee->sta_sleep == LPS_IS_SLEEP) &&
1371 (ieee->polling) && (!bToOtherSTA)) {
1372 if (WLAN_FC_MORE_DATA(fc)) {
1373 /* more data bit is set, let's request a new frame
1376 rtllib_sta_ps_send_pspoll_frame(ieee);
1378 ieee->polling = false;
1382 /* Get crypt if encrypted */
1383 ret = rtllib_rx_get_crypt(ieee, skb, &crypt, hdrlen);
1387 /* Decrypt data frame (including reassemble) */
1388 ret = rtllib_rx_decrypt(ieee, skb, rx_stats, crypt, hdrlen);
1394 /* Get TS for Rx Reorder */
1395 hdr = (struct rtllib_hdr_4addr *)skb->data;
1396 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1397 && !is_multicast_ether_addr(hdr->addr1)
1398 && (!bToOtherSTA)) {
1399 TID = Frame_QoSTID(skb->data);
1400 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1401 GetTs(ieee, (struct ts_common_info **)&pTS, hdr->addr2, TID,
1403 if (TID != 0 && TID != 3)
1404 ieee->bis_any_nonbepkts = true;
1407 /* Parse rx data frame (For AMSDU) */
1408 /* skb: hdr + (possible reassembled) full plaintext payload */
1409 rxb = kmalloc(sizeof(struct rtllib_rxb), GFP_ATOMIC);
1413 /* to parse amsdu packets */
1414 /* qos data packets & reserved bit is 1 */
1415 if (parse_subframe(ieee, skb, rx_stats, rxb, src, dst) == 0) {
1416 /* only to free rxb, and not submit the packets
1419 for (i = 0; i < rxb->nr_subframes; i++)
1420 dev_kfree_skb(rxb->subframes[i]);
1426 /* Update WAPI PN */
1428 /* Check if leave LPS */
1430 if (ieee->bIsAggregateFrame)
1431 nr_subframes = rxb->nr_subframes;
1435 ieee->link_detect_info.NumRxUnicastOkInPeriod += nr_subframes;
1436 rtllib_rx_check_leave_lps(ieee, unicast, nr_subframes);
1439 /* Indicate packets to upper layer or Rx Reorder */
1440 if (!ieee->ht_info->cur_rx_reorder_enable || pTS == NULL || bToOtherSTA)
1441 rtllib_rx_indicate_pkt_legacy(ieee, rx_stats, rxb, dst, src);
1443 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1451 ieee->stats.rx_dropped++;
1453 /* Returning 0 indicates to caller that we have not handled the SKB--
1454 * so it is still allocated and can be used again by underlying
1455 * hardware as a DMA target
1460 static int rtllib_rx_Master(struct rtllib_device *ieee, struct sk_buff *skb,
1461 struct rtllib_rx_stats *rx_stats)
1466 static int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb,
1467 struct rtllib_rx_stats *rx_stats)
1469 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1470 u16 fc = le16_to_cpu(hdr->frame_ctl);
1471 size_t hdrlen = rtllib_get_hdrlen(fc);
1473 if (skb->len < hdrlen) {
1474 netdev_info(ieee->dev,
1475 "%s():ERR!!! skb->len is smaller than hdrlen\n",
1480 if (HTCCheck(ieee, skb->data)) {
1481 if (net_ratelimit())
1482 netdev_info(ieee->dev, "%s: Find HTCControl!\n",
1487 ieee->stats.rx_packets++;
1488 ieee->stats.rx_bytes += skb->len;
1489 rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
1494 static int rtllib_rx_Mesh(struct rtllib_device *ieee, struct sk_buff *skb,
1495 struct rtllib_rx_stats *rx_stats)
1500 /* All received frames are sent to this function. @skb contains the frame in
1501 * IEEE 802.11 format, i.e., in the format it was sent over air.
1502 * This function is called only as a tasklet (software IRQ).
1504 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1505 struct rtllib_rx_stats *rx_stats)
1509 if (!ieee || !skb || !rx_stats) {
1510 pr_info("%s: Input parameters NULL!\n", __func__);
1513 if (skb->len < 10) {
1514 netdev_info(ieee->dev, "%s: SKB length < 10\n", __func__);
1518 switch (ieee->iw_mode) {
1521 ret = rtllib_rx_InfraAdhoc(ieee, skb, rx_stats);
1523 case IW_MODE_MASTER:
1524 case IW_MODE_REPEAT:
1525 ret = rtllib_rx_Master(ieee, skb, rx_stats);
1527 case IW_MODE_MONITOR:
1528 ret = rtllib_rx_Monitor(ieee, skb, rx_stats);
1531 ret = rtllib_rx_Mesh(ieee, skb, rx_stats);
1534 netdev_info(ieee->dev, "%s: ERR iw mode!!!\n", __func__);
1542 ieee->stats.rx_dropped++;
1545 EXPORT_SYMBOL(rtllib_rx);
1547 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1549 /* Make ther structure we read from the beacon packet has the right values */
1550 static int rtllib_verify_qos_info(struct rtllib_qos_information_element
1551 *info_element, int sub_type)
1553 if (info_element->elementID != QOS_ELEMENT_ID)
1555 if (info_element->qui_subtype != sub_type)
1557 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1559 if (info_element->qui_type != QOS_OUI_TYPE)
1561 if (info_element->version != QOS_VERSION_1)
1567 /* Parse a QoS parameter element */
1568 static int rtllib_read_qos_param_element(
1569 struct rtllib_qos_parameter_info *element_param,
1570 struct rtllib_info_element *info_element)
1572 size_t size = sizeof(*element_param);
1574 if (!element_param || !info_element || info_element->len != size - 2)
1577 memcpy(element_param, info_element, size);
1578 return rtllib_verify_qos_info(&element_param->info_element,
1579 QOS_OUI_PARAM_SUB_TYPE);
1582 /* Parse a QoS information element */
1583 static int rtllib_read_qos_info_element(
1584 struct rtllib_qos_information_element *element_info,
1585 struct rtllib_info_element *info_element)
1587 size_t size = sizeof(*element_info);
1589 if (!element_info || !info_element || info_element->len != size - 2)
1592 memcpy(element_info, info_element, size);
1593 return rtllib_verify_qos_info(element_info, QOS_OUI_INFO_SUB_TYPE);
1596 /* Write QoS parameters from the ac parameters. */
1597 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info *param_elm,
1598 struct rtllib_qos_data *qos_data)
1600 struct rtllib_qos_ac_parameter *ac_params;
1601 struct rtllib_qos_parameters *qos_param = &(qos_data->parameters);
1606 qos_data->wmm_acm = 0;
1607 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1608 ac_params = &(param_elm->ac_params_record[i]);
1610 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1611 acm = (ac_params->aci_aifsn & 0x10) >> 4;
1613 if (aci >= QOS_QUEUE_NUM)
1617 /* BIT(0) | BIT(3) */
1619 qos_data->wmm_acm |= (0x01 << 0) | (0x01 << 3);
1622 /* BIT(4) | BIT(5) */
1624 qos_data->wmm_acm |= (0x01 << 4) | (0x01 << 5);
1627 /* BIT(6) | BIT(7) */
1629 qos_data->wmm_acm |= (0x01 << 6) | (0x01 << 7);
1633 /* BIT(1) | BIT(2) */
1635 qos_data->wmm_acm |= (0x01 << 1) | (0x01 << 2);
1639 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1641 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1642 qos_param->aifs[aci] = max_t(u8, qos_param->aifs[aci], 2);
1644 qos_param->cw_min[aci] = cpu_to_le16(ac_params->ecw_min_max &
1647 qos_param->cw_max[aci] = cpu_to_le16((ac_params->ecw_min_max &
1650 qos_param->flag[aci] =
1651 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1652 qos_param->tx_op_limit[aci] = ac_params->tx_op_limit;
1657 /* we have a generic data element which it may contain QoS information or
1658 * parameters element. check the information element length to decide
1659 * which type to read
1661 static int rtllib_parse_qos_info_param_IE(struct rtllib_device *ieee,
1662 struct rtllib_info_element
1664 struct rtllib_network *network)
1667 struct rtllib_qos_information_element qos_info_element;
1669 rc = rtllib_read_qos_info_element(&qos_info_element, info_element);
1672 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1673 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1675 struct rtllib_qos_parameter_info param_element;
1677 rc = rtllib_read_qos_param_element(¶m_element,
1680 rtllib_qos_convert_ac_to_parameters(¶m_element,
1681 &(network->qos_data));
1682 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1683 network->qos_data.param_count =
1684 param_element.info_element.ac_info & 0x0F;
1689 netdev_dbg(ieee->dev, "QoS is supported\n");
1690 network->qos_data.supported = 1;
1695 static const char *get_info_element_string(u16 id)
1698 case MFIE_TYPE_SSID:
1700 case MFIE_TYPE_RATES:
1702 case MFIE_TYPE_FH_SET:
1704 case MFIE_TYPE_DS_SET:
1706 case MFIE_TYPE_CF_SET:
1710 case MFIE_TYPE_IBSS_SET:
1712 case MFIE_TYPE_COUNTRY:
1714 case MFIE_TYPE_HOP_PARAMS:
1715 return "HOP_PARAMS";
1716 case MFIE_TYPE_HOP_TABLE:
1718 case MFIE_TYPE_REQUEST:
1720 case MFIE_TYPE_CHALLENGE:
1722 case MFIE_TYPE_POWER_CONSTRAINT:
1723 return "POWER_CONSTRAINT";
1724 case MFIE_TYPE_POWER_CAPABILITY:
1725 return "POWER_CAPABILITY";
1726 case MFIE_TYPE_TPC_REQUEST:
1727 return "TPC_REQUEST";
1728 case MFIE_TYPE_TPC_REPORT:
1729 return "TPC_REPORT";
1730 case MFIE_TYPE_SUPP_CHANNELS:
1731 return "SUPP_CHANNELS";
1734 case MFIE_TYPE_MEASURE_REQUEST:
1735 return "MEASURE_REQUEST";
1736 case MFIE_TYPE_MEASURE_REPORT:
1737 return "MEASURE_REPORT";
1738 case MFIE_TYPE_QUIET:
1740 case MFIE_TYPE_IBSS_DFS:
1744 case MFIE_TYPE_RATES_EX:
1746 case MFIE_TYPE_GENERIC:
1748 case MFIE_TYPE_QOS_PARAMETER:
1749 return "QOS_PARAMETER";
1755 static inline void rtllib_extract_country_ie(
1756 struct rtllib_device *ieee,
1757 struct rtllib_info_element *info_element,
1758 struct rtllib_network *network,
1761 if (IS_DOT11D_ENABLE(ieee)) {
1762 if (info_element->len != 0) {
1763 memcpy(network->CountryIeBuf, info_element->data,
1765 network->CountryIeLen = info_element->len;
1767 if (!IS_COUNTRY_IE_VALID(ieee)) {
1768 if (rtllib_act_scanning(ieee, false) &&
1769 ieee->FirstIe_InScan)
1770 netdev_info(ieee->dev,
1771 "Received beacon CountryIE, SSID: <%s>\n",
1773 dot11d_update_country(ieee, addr2,
1775 info_element->data);
1779 if (IS_EQUAL_CIE_SRC(ieee, addr2))
1780 UPDATE_CIE_WATCHDOG(ieee);
1784 static void rtllib_parse_mife_generic(struct rtllib_device *ieee,
1785 struct rtllib_info_element *info_element,
1786 struct rtllib_network *network,
1788 u16 *tmp_htinfo_len)
1790 u16 ht_realtek_agg_len = 0;
1791 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1793 if (!rtllib_parse_qos_info_param_IE(ieee, info_element, network))
1795 if (info_element->len >= 4 &&
1796 info_element->data[0] == 0x00 &&
1797 info_element->data[1] == 0x50 &&
1798 info_element->data[2] == 0xf2 &&
1799 info_element->data[3] == 0x01) {
1800 network->wpa_ie_len = min(info_element->len + 2,
1802 memcpy(network->wpa_ie, info_element, network->wpa_ie_len);
1805 if (info_element->len == 7 &&
1806 info_element->data[0] == 0x00 &&
1807 info_element->data[1] == 0xe0 &&
1808 info_element->data[2] == 0x4c &&
1809 info_element->data[3] == 0x01 &&
1810 info_element->data[4] == 0x02)
1811 network->Turbo_Enable = 1;
1813 if (*tmp_htcap_len == 0) {
1814 if (info_element->len >= 4 &&
1815 info_element->data[0] == 0x00 &&
1816 info_element->data[1] == 0x90 &&
1817 info_element->data[2] == 0x4c &&
1818 info_element->data[3] == 0x033) {
1819 *tmp_htcap_len = min_t(u8, info_element->len,
1821 if (*tmp_htcap_len != 0) {
1822 network->bssht.bd_ht_spec_ver = HT_SPEC_VER_EWC;
1823 network->bssht.bd_ht_cap_len = min_t(u16, *tmp_htcap_len,
1824 sizeof(network->bssht.bd_ht_cap_buf));
1825 memcpy(network->bssht.bd_ht_cap_buf,
1827 network->bssht.bd_ht_cap_len);
1830 if (*tmp_htcap_len != 0) {
1831 network->bssht.bd_support_ht = true;
1832 network->bssht.bd_ht_1r = ((((struct ht_capab_ele *)(network->bssht.bd_ht_cap_buf))->MCS[1]) == 0);
1834 network->bssht.bd_support_ht = false;
1835 network->bssht.bd_ht_1r = false;
1839 if (*tmp_htinfo_len == 0) {
1840 if (info_element->len >= 4 &&
1841 info_element->data[0] == 0x00 &&
1842 info_element->data[1] == 0x90 &&
1843 info_element->data[2] == 0x4c &&
1844 info_element->data[3] == 0x034) {
1845 *tmp_htinfo_len = min_t(u8, info_element->len,
1847 if (*tmp_htinfo_len != 0) {
1848 network->bssht.bd_ht_spec_ver = HT_SPEC_VER_EWC;
1849 network->bssht.bd_ht_info_len = min_t(u16, *tmp_htinfo_len,
1850 sizeof(network->bssht.bd_ht_info_buf));
1851 memcpy(network->bssht.bd_ht_info_buf,
1853 network->bssht.bd_ht_info_len);
1858 if (network->bssht.bd_support_ht) {
1859 if (info_element->len >= 4 &&
1860 info_element->data[0] == 0x00 &&
1861 info_element->data[1] == 0xe0 &&
1862 info_element->data[2] == 0x4c &&
1863 info_element->data[3] == 0x02) {
1864 ht_realtek_agg_len = min_t(u8, info_element->len,
1866 memcpy(ht_realtek_agg_buf, info_element->data,
1869 if (ht_realtek_agg_len >= 5) {
1870 network->realtek_cap_exit = true;
1871 network->bssht.bd_rt2rt_aggregation = true;
1873 if ((ht_realtek_agg_buf[4] == 1) &&
1874 (ht_realtek_agg_buf[5] & 0x02))
1875 network->bssht.bd_rt2rt_long_slot_time = true;
1877 if ((ht_realtek_agg_buf[4] == 1) &&
1878 (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
1879 network->bssht.rt2rt_ht_mode |= RT_HT_CAP_USE_92SE;
1882 if (ht_realtek_agg_len >= 5) {
1883 if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
1884 network->bssht.rt2rt_ht_mode |= RT_HT_CAP_USE_SOFTAP;
1887 if ((info_element->len >= 3 &&
1888 info_element->data[0] == 0x00 &&
1889 info_element->data[1] == 0x05 &&
1890 info_element->data[2] == 0xb5) ||
1891 (info_element->len >= 3 &&
1892 info_element->data[0] == 0x00 &&
1893 info_element->data[1] == 0x0a &&
1894 info_element->data[2] == 0xf7) ||
1895 (info_element->len >= 3 &&
1896 info_element->data[0] == 0x00 &&
1897 info_element->data[1] == 0x10 &&
1898 info_element->data[2] == 0x18)) {
1899 network->broadcom_cap_exist = true;
1901 if (info_element->len >= 3 &&
1902 info_element->data[0] == 0x00 &&
1903 info_element->data[1] == 0x0c &&
1904 info_element->data[2] == 0x43)
1905 network->ralink_cap_exist = true;
1906 if ((info_element->len >= 3 &&
1907 info_element->data[0] == 0x00 &&
1908 info_element->data[1] == 0x03 &&
1909 info_element->data[2] == 0x7f) ||
1910 (info_element->len >= 3 &&
1911 info_element->data[0] == 0x00 &&
1912 info_element->data[1] == 0x13 &&
1913 info_element->data[2] == 0x74))
1914 network->atheros_cap_exist = true;
1916 if ((info_element->len >= 3 &&
1917 info_element->data[0] == 0x00 &&
1918 info_element->data[1] == 0x50 &&
1919 info_element->data[2] == 0x43))
1920 network->marvell_cap_exist = true;
1921 if (info_element->len >= 3 &&
1922 info_element->data[0] == 0x00 &&
1923 info_element->data[1] == 0x40 &&
1924 info_element->data[2] == 0x96)
1925 network->cisco_cap_exist = true;
1927 if (info_element->len >= 3 &&
1928 info_element->data[0] == 0x00 &&
1929 info_element->data[1] == 0x0a &&
1930 info_element->data[2] == 0xf5)
1931 network->airgo_cap_exist = true;
1933 if (info_element->len > 4 &&
1934 info_element->data[0] == 0x00 &&
1935 info_element->data[1] == 0x40 &&
1936 info_element->data[2] == 0x96 &&
1937 info_element->data[3] == 0x01) {
1938 if (info_element->len == 6) {
1939 memcpy(network->CcxRmState, &info_element->data[4], 2);
1940 if (network->CcxRmState[0] != 0)
1941 network->bCcxRmEnable = true;
1943 network->bCcxRmEnable = false;
1944 network->MBssidMask = network->CcxRmState[1] & 0x07;
1945 if (network->MBssidMask != 0) {
1946 network->bMBssidValid = true;
1947 network->MBssidMask = 0xff <<
1948 (network->MBssidMask);
1949 ether_addr_copy(network->MBssid,
1951 network->MBssid[5] &= network->MBssidMask;
1953 network->bMBssidValid = false;
1956 network->bCcxRmEnable = false;
1959 if (info_element->len > 4 &&
1960 info_element->data[0] == 0x00 &&
1961 info_element->data[1] == 0x40 &&
1962 info_element->data[2] == 0x96 &&
1963 info_element->data[3] == 0x03) {
1964 if (info_element->len == 5) {
1965 network->bWithCcxVerNum = true;
1966 network->BssCcxVerNumber = info_element->data[4];
1968 network->bWithCcxVerNum = false;
1969 network->BssCcxVerNumber = 0;
1972 if (info_element->len > 4 &&
1973 info_element->data[0] == 0x00 &&
1974 info_element->data[1] == 0x50 &&
1975 info_element->data[2] == 0xf2 &&
1976 info_element->data[3] == 0x04) {
1977 netdev_dbg(ieee->dev, "MFIE_TYPE_WZC: %d bytes\n",
1979 network->wzc_ie_len = min(info_element->len + 2, MAX_WZC_IE_LEN);
1980 memcpy(network->wzc_ie, info_element, network->wzc_ie_len);
1984 static void rtllib_parse_mfie_ht_cap(struct rtllib_info_element *info_element,
1985 struct rtllib_network *network,
1988 struct bss_ht *ht = &network->bssht;
1990 *tmp_htcap_len = min_t(u8, info_element->len, MAX_IE_LEN);
1991 if (*tmp_htcap_len != 0) {
1992 ht->bd_ht_spec_ver = HT_SPEC_VER_EWC;
1993 ht->bd_ht_cap_len = min_t(u16, *tmp_htcap_len,
1994 sizeof(ht->bd_ht_cap_buf));
1995 memcpy(ht->bd_ht_cap_buf, info_element->data, ht->bd_ht_cap_len);
1997 ht->bd_support_ht = true;
1998 ht->bd_ht_1r = ((((struct ht_capab_ele *)
1999 ht->bd_ht_cap_buf))->MCS[1]) == 0;
2001 ht->bd_bandwidth = (enum ht_channel_width)
2002 (((struct ht_capab_ele *)
2003 (ht->bd_ht_cap_buf))->ChlWidth);
2005 ht->bd_support_ht = false;
2006 ht->bd_ht_1r = false;
2007 ht->bd_bandwidth = HT_CHANNEL_WIDTH_20;
2011 int rtllib_parse_info_param(struct rtllib_device *ieee,
2012 struct rtllib_info_element *info_element,
2014 struct rtllib_network *network,
2015 struct rtllib_rx_stats *stats)
2019 u16 tmp_htcap_len = 0;
2020 u16 tmp_htinfo_len = 0;
2024 while (length >= sizeof(*info_element)) {
2025 if (sizeof(*info_element) + info_element->len > length) {
2026 netdev_dbg(ieee->dev,
2027 "Info elem: parse failed: info_element->len + 2 > left : info_element->len+2=%zd left=%d, id=%d.\n",
2028 info_element->len + sizeof(*info_element),
2029 length, info_element->id);
2030 /* We stop processing but don't return an error here
2031 * because some misbehaviour APs break this rule. ie.
2037 switch (info_element->id) {
2038 case MFIE_TYPE_SSID:
2039 if (rtllib_is_empty_essid(info_element->data,
2040 info_element->len)) {
2041 network->flags |= NETWORK_EMPTY_ESSID;
2045 network->ssid_len = min(info_element->len,
2046 (u8)IW_ESSID_MAX_SIZE);
2047 memcpy(network->ssid, info_element->data,
2049 if (network->ssid_len < IW_ESSID_MAX_SIZE)
2050 memset(network->ssid + network->ssid_len, 0,
2051 IW_ESSID_MAX_SIZE - network->ssid_len);
2053 netdev_dbg(ieee->dev, "MFIE_TYPE_SSID: '%s' len=%d.\n",
2054 network->ssid, network->ssid_len);
2057 case MFIE_TYPE_RATES:
2059 network->rates_len = min(info_element->len,
2061 for (i = 0; i < network->rates_len; i++) {
2062 network->rates[i] = info_element->data[i];
2063 p += scnprintf(p, sizeof(rates_str) -
2064 (p - rates_str), "%02X ",
2066 if (rtllib_is_ofdm_rate
2067 (info_element->data[i])) {
2068 network->flags |= NETWORK_HAS_OFDM;
2069 if (info_element->data[i] &
2070 RTLLIB_BASIC_RATE_MASK)
2075 if (rtllib_is_cck_rate
2076 (info_element->data[i])) {
2077 network->flags |= NETWORK_HAS_CCK;
2081 netdev_dbg(ieee->dev, "MFIE_TYPE_RATES: '%s' (%d)\n",
2082 rates_str, network->rates_len);
2085 case MFIE_TYPE_RATES_EX:
2087 network->rates_ex_len = min(info_element->len,
2088 MAX_RATES_EX_LENGTH);
2089 for (i = 0; i < network->rates_ex_len; i++) {
2090 network->rates_ex[i] = info_element->data[i];
2091 p += scnprintf(p, sizeof(rates_str) -
2092 (p - rates_str), "%02X ",
2093 network->rates_ex[i]);
2094 if (rtllib_is_ofdm_rate
2095 (info_element->data[i])) {
2096 network->flags |= NETWORK_HAS_OFDM;
2097 if (info_element->data[i] &
2098 RTLLIB_BASIC_RATE_MASK)
2104 netdev_dbg(ieee->dev, "MFIE_TYPE_RATES_EX: '%s' (%d)\n",
2105 rates_str, network->rates_ex_len);
2108 case MFIE_TYPE_DS_SET:
2109 netdev_dbg(ieee->dev, "MFIE_TYPE_DS_SET: %d\n",
2110 info_element->data[0]);
2111 network->channel = info_element->data[0];
2114 case MFIE_TYPE_FH_SET:
2115 netdev_dbg(ieee->dev, "MFIE_TYPE_FH_SET: ignored\n");
2118 case MFIE_TYPE_CF_SET:
2119 netdev_dbg(ieee->dev, "MFIE_TYPE_CF_SET: ignored\n");
2123 if (info_element->len < 4)
2126 network->tim.tim_count = info_element->data[0];
2127 network->tim.tim_period = info_element->data[1];
2129 network->dtim_period = info_element->data[1];
2130 if (ieee->state != RTLLIB_LINKED)
2132 network->last_dtim_sta_time = jiffies;
2134 network->dtim_data = RTLLIB_DTIM_VALID;
2136 if (info_element->data[2] & 1)
2137 network->dtim_data |= RTLLIB_DTIM_MBCAST;
2139 offset = (info_element->data[2] >> 1) * 2;
2141 if (ieee->assoc_id < 8 * offset ||
2142 ieee->assoc_id > 8 * (offset + info_element->len - 3))
2145 offset = (ieee->assoc_id / 8) - offset;
2146 if (info_element->data[3 + offset] &
2147 (1 << (ieee->assoc_id % 8)))
2148 network->dtim_data |= RTLLIB_DTIM_UCAST;
2150 network->listen_interval = network->dtim_period;
2154 network->erp_value = info_element->data[0];
2155 network->flags |= NETWORK_HAS_ERP_VALUE;
2156 netdev_dbg(ieee->dev, "MFIE_TYPE_ERP_SET: %d\n",
2157 network->erp_value);
2159 case MFIE_TYPE_IBSS_SET:
2160 network->atim_window = info_element->data[0];
2161 netdev_dbg(ieee->dev, "MFIE_TYPE_IBSS_SET: %d\n",
2162 network->atim_window);
2165 case MFIE_TYPE_CHALLENGE:
2166 netdev_dbg(ieee->dev, "MFIE_TYPE_CHALLENGE: ignored\n");
2169 case MFIE_TYPE_GENERIC:
2170 netdev_dbg(ieee->dev, "MFIE_TYPE_GENERIC: %d bytes\n",
2173 rtllib_parse_mife_generic(ieee, info_element, network,
2179 netdev_dbg(ieee->dev, "MFIE_TYPE_RSN: %d bytes\n",
2181 network->rsn_ie_len = min(info_element->len + 2,
2183 memcpy(network->rsn_ie, info_element,
2184 network->rsn_ie_len);
2187 case MFIE_TYPE_HT_CAP:
2188 netdev_dbg(ieee->dev, "MFIE_TYPE_HT_CAP: %d bytes\n",
2191 rtllib_parse_mfie_ht_cap(info_element, network,
2195 case MFIE_TYPE_HT_INFO:
2196 netdev_dbg(ieee->dev, "MFIE_TYPE_HT_INFO: %d bytes\n",
2198 tmp_htinfo_len = min_t(u8, info_element->len,
2200 if (tmp_htinfo_len) {
2201 network->bssht.bd_ht_spec_ver = HT_SPEC_VER_IEEE;
2202 network->bssht.bd_ht_info_len = tmp_htinfo_len >
2203 sizeof(network->bssht.bd_ht_info_buf) ?
2204 sizeof(network->bssht.bd_ht_info_buf) :
2206 memcpy(network->bssht.bd_ht_info_buf,
2208 network->bssht.bd_ht_info_len);
2212 case MFIE_TYPE_AIRONET:
2213 netdev_dbg(ieee->dev, "MFIE_TYPE_AIRONET: %d bytes\n",
2215 if (info_element->len > IE_CISCO_FLAG_POSITION) {
2216 network->bWithAironetIE = true;
2218 if ((info_element->data[IE_CISCO_FLAG_POSITION]
2219 & SUPPORT_CKIP_MIC) ||
2220 (info_element->data[IE_CISCO_FLAG_POSITION]
2222 network->bCkipSupported = true;
2224 network->bCkipSupported = false;
2226 network->bWithAironetIE = false;
2227 network->bCkipSupported = false;
2230 case MFIE_TYPE_QOS_PARAMETER:
2231 netdev_err(ieee->dev,
2232 "QoS Error need to parse QOS_PARAMETER IE\n");
2235 case MFIE_TYPE_COUNTRY:
2236 netdev_dbg(ieee->dev, "MFIE_TYPE_COUNTRY: %d bytes\n",
2238 rtllib_extract_country_ie(ieee, info_element, network,
2243 netdev_dbg(ieee->dev,
2244 "Unsupported info element: %s (%d)\n",
2245 get_info_element_string(info_element->id),
2250 length -= sizeof(*info_element) + info_element->len;
2252 (struct rtllib_info_element *)&info_element->data[info_element->len];
2255 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2256 !network->cisco_cap_exist && !network->ralink_cap_exist &&
2257 !network->bssht.bd_rt2rt_aggregation)
2258 network->unknown_cap_exist = true;
2260 network->unknown_cap_exist = false;
2264 static long rtllib_translate_todbm(u8 signal_strength_index)
2268 signal_power = (long)((signal_strength_index + 1) >> 1);
2271 return signal_power;
2274 static inline int rtllib_network_init(
2275 struct rtllib_device *ieee,
2276 struct rtllib_probe_response *beacon,
2277 struct rtllib_network *network,
2278 struct rtllib_rx_stats *stats)
2280 memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
2282 /* Pull out fixed field data */
2283 ether_addr_copy(network->bssid, beacon->header.addr3);
2284 network->capability = le16_to_cpu(beacon->capability);
2285 network->last_scanned = jiffies;
2286 network->time_stamp[0] = beacon->time_stamp[0];
2287 network->time_stamp[1] = beacon->time_stamp[1];
2288 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
2289 /* Where to pull this? beacon->listen_interval;*/
2290 network->listen_interval = 0x0A;
2291 network->rates_len = network->rates_ex_len = 0;
2292 network->ssid_len = 0;
2293 network->hidden_ssid_len = 0;
2294 memset(network->hidden_ssid, 0, sizeof(network->hidden_ssid));
2296 network->atim_window = 0;
2297 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2299 network->berp_info_valid = false;
2300 network->broadcom_cap_exist = false;
2301 network->ralink_cap_exist = false;
2302 network->atheros_cap_exist = false;
2303 network->cisco_cap_exist = false;
2304 network->unknown_cap_exist = false;
2305 network->realtek_cap_exit = false;
2306 network->marvell_cap_exist = false;
2307 network->airgo_cap_exist = false;
2308 network->Turbo_Enable = 0;
2309 network->SignalStrength = stats->SignalStrength;
2310 network->RSSI = stats->SignalStrength;
2311 network->CountryIeLen = 0;
2312 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2313 HTInitializeBssDesc(&network->bssht);
2314 if (stats->freq == RTLLIB_52GHZ_BAND) {
2315 /* for A band (No DS info) */
2316 network->channel = stats->received_channel;
2318 network->flags |= NETWORK_HAS_CCK;
2320 network->wpa_ie_len = 0;
2321 network->rsn_ie_len = 0;
2322 network->wzc_ie_len = 0;
2324 if (rtllib_parse_info_param(ieee,
2325 beacon->info_element,
2326 (stats->len - sizeof(*beacon)),
2332 if (stats->freq == RTLLIB_52GHZ_BAND)
2333 network->mode = IEEE_A;
2335 if (network->flags & NETWORK_HAS_OFDM)
2336 network->mode |= IEEE_G;
2337 if (network->flags & NETWORK_HAS_CCK)
2338 network->mode |= IEEE_B;
2341 if (network->mode == 0) {
2342 netdev_dbg(ieee->dev, "Filtered out '%s (%pM)' network.\n",
2343 escape_essid(network->ssid, network->ssid_len),
2348 if (network->bssht.bd_support_ht) {
2349 if (network->mode == IEEE_A)
2350 network->mode = IEEE_N_5G;
2351 else if (network->mode & (IEEE_G | IEEE_B))
2352 network->mode = IEEE_N_24G;
2354 if (rtllib_is_empty_essid(network->ssid, network->ssid_len))
2355 network->flags |= NETWORK_EMPTY_ESSID;
2356 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2357 stats->noise = rtllib_translate_todbm((u8)(100 - stats->signal)) - 25;
2359 memcpy(&network->stats, stats, sizeof(network->stats));
2364 static inline int is_same_network(struct rtllib_network *src,
2365 struct rtllib_network *dst, u8 ssidbroad)
2367 /* A network is only a duplicate if the channel, BSSID, ESSID
2368 * and the capability field (in particular IBSS and BSS) all match.
2369 * We treat all <hidden> with the same BSSID and channel
2372 return (((src->ssid_len == dst->ssid_len) || (!ssidbroad)) &&
2373 (src->channel == dst->channel) &&
2374 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2375 (!memcmp(src->ssid, dst->ssid, src->ssid_len) ||
2377 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2378 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2379 ((src->capability & WLAN_CAPABILITY_ESS) ==
2380 (dst->capability & WLAN_CAPABILITY_ESS)));
2383 static inline void update_network(struct rtllib_device *ieee,
2384 struct rtllib_network *dst,
2385 struct rtllib_network *src)
2390 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
2391 dst->capability = src->capability;
2392 memcpy(dst->rates, src->rates, src->rates_len);
2393 dst->rates_len = src->rates_len;
2394 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2395 dst->rates_ex_len = src->rates_ex_len;
2396 if (src->ssid_len > 0) {
2397 if (dst->ssid_len == 0) {
2398 memset(dst->hidden_ssid, 0, sizeof(dst->hidden_ssid));
2399 dst->hidden_ssid_len = src->ssid_len;
2400 memcpy(dst->hidden_ssid, src->ssid, src->ssid_len);
2402 memset(dst->ssid, 0, dst->ssid_len);
2403 dst->ssid_len = src->ssid_len;
2404 memcpy(dst->ssid, src->ssid, src->ssid_len);
2407 dst->mode = src->mode;
2408 dst->flags = src->flags;
2409 dst->time_stamp[0] = src->time_stamp[0];
2410 dst->time_stamp[1] = src->time_stamp[1];
2411 if (src->flags & NETWORK_HAS_ERP_VALUE) {
2412 dst->erp_value = src->erp_value;
2413 dst->berp_info_valid = src->berp_info_valid = true;
2415 dst->beacon_interval = src->beacon_interval;
2416 dst->listen_interval = src->listen_interval;
2417 dst->atim_window = src->atim_window;
2418 dst->dtim_period = src->dtim_period;
2419 dst->dtim_data = src->dtim_data;
2420 dst->last_dtim_sta_time = src->last_dtim_sta_time;
2421 memcpy(&dst->tim, &src->tim, sizeof(struct rtllib_tim_parameters));
2423 dst->bssht.bd_support_ht = src->bssht.bd_support_ht;
2424 dst->bssht.bd_rt2rt_aggregation = src->bssht.bd_rt2rt_aggregation;
2425 dst->bssht.bd_ht_cap_len = src->bssht.bd_ht_cap_len;
2426 memcpy(dst->bssht.bd_ht_cap_buf, src->bssht.bd_ht_cap_buf,
2427 src->bssht.bd_ht_cap_len);
2428 dst->bssht.bd_ht_info_len = src->bssht.bd_ht_info_len;
2429 memcpy(dst->bssht.bd_ht_info_buf, src->bssht.bd_ht_info_buf,
2430 src->bssht.bd_ht_info_len);
2431 dst->bssht.bd_ht_spec_ver = src->bssht.bd_ht_spec_ver;
2432 dst->bssht.bd_rt2rt_long_slot_time = src->bssht.bd_rt2rt_long_slot_time;
2433 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2434 dst->ralink_cap_exist = src->ralink_cap_exist;
2435 dst->atheros_cap_exist = src->atheros_cap_exist;
2436 dst->realtek_cap_exit = src->realtek_cap_exit;
2437 dst->marvell_cap_exist = src->marvell_cap_exist;
2438 dst->cisco_cap_exist = src->cisco_cap_exist;
2439 dst->airgo_cap_exist = src->airgo_cap_exist;
2440 dst->unknown_cap_exist = src->unknown_cap_exist;
2441 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2442 dst->wpa_ie_len = src->wpa_ie_len;
2443 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2444 dst->rsn_ie_len = src->rsn_ie_len;
2445 memcpy(dst->wzc_ie, src->wzc_ie, src->wzc_ie_len);
2446 dst->wzc_ie_len = src->wzc_ie_len;
2448 dst->last_scanned = jiffies;
2449 /* qos related parameters */
2450 qos_active = dst->qos_data.active;
2451 old_param = dst->qos_data.param_count;
2452 dst->qos_data.supported = src->qos_data.supported;
2453 if (dst->flags & NETWORK_HAS_QOS_PARAMETERS)
2454 memcpy(&dst->qos_data, &src->qos_data,
2455 sizeof(struct rtllib_qos_data));
2456 if (dst->qos_data.supported == 1) {
2458 netdev_dbg(ieee->dev,
2459 "QoS the network %s is QoS supported\n",
2462 netdev_dbg(ieee->dev,
2463 "QoS the network is QoS supported\n");
2465 dst->qos_data.active = qos_active;
2466 dst->qos_data.old_param_count = old_param;
2468 dst->wmm_info = src->wmm_info;
2469 if (src->wmm_param[0].ac_aci_acm_aifsn ||
2470 src->wmm_param[1].ac_aci_acm_aifsn ||
2471 src->wmm_param[2].ac_aci_acm_aifsn ||
2472 src->wmm_param[3].ac_aci_acm_aifsn)
2473 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2475 dst->SignalStrength = src->SignalStrength;
2476 dst->RSSI = src->RSSI;
2477 dst->Turbo_Enable = src->Turbo_Enable;
2479 dst->CountryIeLen = src->CountryIeLen;
2480 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2482 dst->bWithAironetIE = src->bWithAironetIE;
2483 dst->bCkipSupported = src->bCkipSupported;
2484 memcpy(dst->CcxRmState, src->CcxRmState, 2);
2485 dst->bCcxRmEnable = src->bCcxRmEnable;
2486 dst->MBssidMask = src->MBssidMask;
2487 dst->bMBssidValid = src->bMBssidValid;
2488 memcpy(dst->MBssid, src->MBssid, 6);
2489 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2490 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2493 static inline int is_beacon(u16 fc)
2495 return (WLAN_FC_GET_STYPE(fc) == RTLLIB_STYPE_BEACON);
2498 static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
2500 if (channel > MAX_CHANNEL_NUMBER) {
2501 netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
2505 if (rtllib->active_channel_map[channel] == 2)
2511 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel)
2513 if (channel > MAX_CHANNEL_NUMBER) {
2514 netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
2517 if (rtllib->active_channel_map[channel] > 0)
2522 EXPORT_SYMBOL(rtllib_legal_channel);
2524 static inline void rtllib_process_probe_response(
2525 struct rtllib_device *ieee,
2526 struct rtllib_probe_response *beacon,
2527 struct rtllib_rx_stats *stats)
2529 struct rtllib_network *target;
2530 struct rtllib_network *oldest = NULL;
2531 struct rtllib_info_element *info_element = &beacon->info_element[0];
2532 unsigned long flags;
2534 struct rtllib_network *network = kzalloc(sizeof(struct rtllib_network),
2536 u16 frame_ctl = le16_to_cpu(beacon->header.frame_ctl);
2541 netdev_dbg(ieee->dev,
2542 "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2543 escape_essid(info_element->data, info_element->len),
2544 beacon->header.addr3,
2545 (le16_to_cpu(beacon->capability) & (1 << 0xf)) ? '1' : '0',
2546 (le16_to_cpu(beacon->capability) & (1 << 0xe)) ? '1' : '0',
2547 (le16_to_cpu(beacon->capability) & (1 << 0xd)) ? '1' : '0',
2548 (le16_to_cpu(beacon->capability) & (1 << 0xc)) ? '1' : '0',
2549 (le16_to_cpu(beacon->capability) & (1 << 0xb)) ? '1' : '0',
2550 (le16_to_cpu(beacon->capability) & (1 << 0xa)) ? '1' : '0',
2551 (le16_to_cpu(beacon->capability) & (1 << 0x9)) ? '1' : '0',
2552 (le16_to_cpu(beacon->capability) & (1 << 0x8)) ? '1' : '0',
2553 (le16_to_cpu(beacon->capability) & (1 << 0x7)) ? '1' : '0',
2554 (le16_to_cpu(beacon->capability) & (1 << 0x6)) ? '1' : '0',
2555 (le16_to_cpu(beacon->capability) & (1 << 0x5)) ? '1' : '0',
2556 (le16_to_cpu(beacon->capability) & (1 << 0x4)) ? '1' : '0',
2557 (le16_to_cpu(beacon->capability) & (1 << 0x3)) ? '1' : '0',
2558 (le16_to_cpu(beacon->capability) & (1 << 0x2)) ? '1' : '0',
2559 (le16_to_cpu(beacon->capability) & (1 << 0x1)) ? '1' : '0',
2560 (le16_to_cpu(beacon->capability) & (1 << 0x0)) ? '1' : '0');
2562 if (rtllib_network_init(ieee, beacon, network, stats)) {
2563 netdev_dbg(ieee->dev, "Dropped '%s' ( %pM) via %s.\n",
2564 escape_essid(info_element->data, info_element->len),
2565 beacon->header.addr3,
2566 is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
2570 if (!rtllib_legal_channel(ieee, network->channel))
2573 if (WLAN_FC_GET_STYPE(frame_ctl) == RTLLIB_STYPE_PROBE_RESP) {
2574 if (IsPassiveChannel(ieee, network->channel)) {
2575 netdev_info(ieee->dev,
2576 "GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n",
2582 /* The network parsed correctly -- so now we scan our known networks
2583 * to see if we can find it in our list.
2585 * NOTE: This search is definitely not optimized. Once its doing
2586 * the "right thing" we'll optimize it for efficiency if
2590 /* Search for this entry in the list and update it if it is
2594 spin_lock_irqsave(&ieee->lock, flags);
2595 if (is_same_network(&ieee->current_network, network,
2596 (network->ssid_len ? 1 : 0))) {
2597 update_network(ieee, &ieee->current_network, network);
2598 if ((ieee->current_network.mode == IEEE_N_24G ||
2599 ieee->current_network.mode == IEEE_G) &&
2600 ieee->current_network.berp_info_valid) {
2601 if (ieee->current_network.erp_value & ERP_UseProtection)
2602 ieee->current_network.buseprotection = true;
2604 ieee->current_network.buseprotection = false;
2606 if (is_beacon(frame_ctl)) {
2607 if (ieee->state >= RTLLIB_LINKED)
2608 ieee->link_detect_info.NumRecvBcnInPeriod++;
2611 list_for_each_entry(target, &ieee->network_list, list) {
2612 if (is_same_network(target, network,
2613 (target->ssid_len ? 1 : 0)))
2615 if ((oldest == NULL) ||
2616 (target->last_scanned < oldest->last_scanned))
2620 /* If we didn't find a match, then get a new network slot to initialize
2621 * with this beacon's information
2623 if (&target->list == &ieee->network_list) {
2624 if (list_empty(&ieee->network_free_list)) {
2625 /* If there are no more slots, expire the oldest */
2626 list_del(&oldest->list);
2628 netdev_dbg(ieee->dev,
2629 "Expired '%s' ( %pM) from network list.\n",
2630 escape_essid(target->ssid, target->ssid_len),
2633 /* Otherwise just pull from the free list */
2634 target = list_entry(ieee->network_free_list.next,
2635 struct rtllib_network, list);
2636 list_del(ieee->network_free_list.next);
2639 netdev_dbg(ieee->dev, "Adding '%s' ( %pM) via %s.\n",
2640 escape_essid(network->ssid, network->ssid_len),
2642 is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
2644 memcpy(target, network, sizeof(*target));
2645 list_add_tail(&target->list, &ieee->network_list);
2646 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2647 rtllib_softmac_new_net(ieee, network);
2649 netdev_dbg(ieee->dev, "Updating '%s' ( %pM) via %s.\n",
2650 escape_essid(target->ssid, target->ssid_len),
2652 is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
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(ieee, 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(frame_ctl) &&
2674 is_same_network(&ieee->current_network, network,
2675 (network->ssid_len ? 1 : 0)) &&
2676 (ieee->state == RTLLIB_LINKED)) {
2677 ieee->handle_beacon(ieee->dev, beacon, &ieee->current_network);
2683 static void rtllib_rx_mgt(struct rtllib_device *ieee,
2684 struct sk_buff *skb,
2685 struct rtllib_rx_stats *stats)
2687 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data;
2689 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) !=
2690 RTLLIB_STYPE_PROBE_RESP) &&
2691 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) !=
2692 RTLLIB_STYPE_BEACON))
2693 ieee->last_rx_ps_time = jiffies;
2695 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
2696 case RTLLIB_STYPE_BEACON:
2697 netdev_dbg(ieee->dev, "received BEACON (%d)\n",
2698 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2699 rtllib_process_probe_response(
2700 ieee, (struct rtllib_probe_response *)header,
2703 if (ieee->sta_sleep || (ieee->ps != RTLLIB_PS_DISABLED &&
2704 ieee->iw_mode == IW_MODE_INFRA &&
2705 ieee->state == RTLLIB_LINKED))
2706 schedule_work(&ieee->ps_task);
2710 case RTLLIB_STYPE_PROBE_RESP:
2711 netdev_dbg(ieee->dev, "received PROBE RESPONSE (%d)\n",
2712 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2713 rtllib_process_probe_response(ieee,
2714 (struct rtllib_probe_response *)header, stats);
2716 case RTLLIB_STYPE_PROBE_REQ:
2717 netdev_dbg(ieee->dev, "received PROBE REQUEST (%d)\n",
2718 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2719 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2720 ((ieee->iw_mode == IW_MODE_ADHOC ||
2721 ieee->iw_mode == IW_MODE_MASTER) &&
2722 ieee->state == RTLLIB_LINKED))
2723 rtllib_rx_probe_rq(ieee, skb);