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
8 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
9 * Copyright (c) 2004, Intel Corporation
10 ******************************************************************************
12 Few modifications for Realtek's Wi-Fi drivers by
13 Andrea Merello <andrea.merello@gmail.com>
15 A special thanks goes to Realtek for their support !
17 ******************************************************************************/
20 #include <linux/compiler.h>
21 #include <linux/errno.h>
22 #include <linux/if_arp.h>
23 #include <linux/in6.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/netdevice.h>
29 #include <linux/pci.h>
30 #include <linux/proc_fs.h>
31 #include <linux/skbuff.h>
32 #include <linux/slab.h>
33 #include <linux/tcp.h>
34 #include <linux/types.h>
35 #include <linux/wireless.h>
36 #include <linux/etherdevice.h>
37 #include <linux/uaccess.h>
38 #include <linux/ctype.h>
40 #include "ieee80211.h"
42 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
44 struct ieee80211_rx_stats *rx_stats)
46 struct rtl_80211_hdr_4addr *hdr = (struct rtl_80211_hdr_4addr *)skb->data;
47 u16 fc = le16_to_cpu(hdr->frame_ctl);
50 skb_reset_mac_header(skb);
52 skb_pull(skb, ieee80211_get_hdrlen(fc));
53 skb->pkt_type = PACKET_OTHERHOST;
54 skb->protocol = htons(ETH_P_80211_RAW);
55 memset(skb->cb, 0, sizeof(skb->cb));
60 /* Called only as a tasklet (software IRQ) */
61 static struct ieee80211_frag_entry *
62 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
63 unsigned int frag, u8 tid, u8 *src, u8 *dst)
65 struct ieee80211_frag_entry *entry;
68 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
69 entry = &ieee->frag_cache[tid][i];
71 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
73 "expiring fragment cache entry "
74 "seq=%u last_frag=%u\n",
75 entry->seq, entry->last_frag);
76 dev_kfree_skb_any(entry->skb);
80 if (entry->skb && entry->seq == seq &&
81 (entry->last_frag + 1 == frag || frag == -1) &&
82 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
83 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
90 /* Called only as a tasklet (software IRQ) */
91 static struct sk_buff *
92 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
93 struct rtl_80211_hdr_4addr *hdr)
95 struct sk_buff *skb = NULL;
96 u16 fc = le16_to_cpu(hdr->frame_ctl);
97 u16 sc = le16_to_cpu(hdr->seq_ctl);
98 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
99 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
100 struct ieee80211_frag_entry *entry;
101 struct rtl_80211_hdr_3addrqos *hdr_3addrqos;
102 struct rtl_80211_hdr_4addrqos *hdr_4addrqos;
105 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
106 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
107 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
110 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
111 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr;
112 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
120 /* Reserve enough space to fit maximum frame length */
121 skb = dev_alloc_skb(ieee->dev->mtu +
122 sizeof(struct rtl_80211_hdr_4addr) +
127 (IEEE80211_QOS_HAS_SEQ(fc) ? 2 : 0) /* QOS Control */);
131 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
132 ieee->frag_next_idx[tid]++;
133 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
134 ieee->frag_next_idx[tid] = 0;
137 dev_kfree_skb_any(entry->skb);
139 entry->first_frag_time = jiffies;
141 entry->last_frag = frag;
143 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
144 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
146 /* received a fragment of a frame for which the head fragment
147 * should have already been received */
148 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid, hdr->addr2,
151 entry->last_frag = frag;
160 /* Called only as a tasklet (software IRQ) */
161 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
162 struct rtl_80211_hdr_4addr *hdr)
164 u16 fc = le16_to_cpu(hdr->frame_ctl);
165 u16 sc = le16_to_cpu(hdr->seq_ctl);
166 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
167 struct ieee80211_frag_entry *entry;
168 struct rtl_80211_hdr_3addrqos *hdr_3addrqos;
169 struct rtl_80211_hdr_4addrqos *hdr_4addrqos;
172 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
173 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
174 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
177 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
178 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr;
179 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
186 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid, hdr->addr2,
190 IEEE80211_DEBUG_FRAG(
191 "could not invalidate fragment cache "
192 "entry (seq=%u)\n", seq);
202 /* ieee80211_rx_frame_mgtmt
204 * Responsible for handling management control frames
206 * Called by ieee80211_rx */
208 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
209 struct ieee80211_rx_stats *rx_stats, u16 type,
212 /* On the struct stats definition there is written that
213 * this is not mandatory.... but seems that the probe
214 * response parser uses it
216 struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data;
218 rx_stats->len = skb->len;
219 ieee80211_rx_mgt(ieee, (struct rtl_80211_hdr_4addr *)skb->data, rx_stats);
220 /* if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) */
221 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN))) {
222 /* use ADDR1 to perform address matching for Management frames */
223 dev_kfree_skb_any(skb);
227 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
229 dev_kfree_skb_any(skb);
234 if (ieee->iw_mode == IW_MODE_MASTER) {
235 netdev_dbg(ieee->dev, "Master mode not yet supported.\n");
238 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
242 if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) {
243 if (stype == WLAN_FC_STYPE_BEACON &&
244 ieee->iw_mode == IW_MODE_MASTER) {
245 struct sk_buff *skb2;
246 /* Process beacon frames also in kernel driver to
247 * update STA(AP) table statistics */
248 skb2 = skb_clone(skb, GFP_ATOMIC);
250 hostap_rx(skb2->dev, skb2, rx_stats);
253 /* send management frames to the user space daemon for
255 ieee->apdevstats.rx_packets++;
256 ieee->apdevstats.rx_bytes += skb->len;
257 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
261 if (ieee->iw_mode == IW_MODE_MASTER) {
262 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
263 netdev_dbg(skb->dev, "unknown management frame "
264 "(type=0x%02x, stype=0x%02x) dropped\n",
269 hostap_rx(skb->dev, skb, rx_stats);
273 netdev_dbg(skb->dev, "hostap_rx_frame_mgmt: management frame "
274 "received in non-Host AP mode\n");
281 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
282 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
283 static unsigned char rfc1042_header[] = {
284 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
285 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
286 static unsigned char bridge_tunnel_header[] = {
287 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
288 /* No encapsulation header if EtherType < 0x600 (=length) */
290 /* Called by ieee80211_rx_frame_decrypt */
291 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
292 struct sk_buff *skb, size_t hdrlen)
294 struct net_device *dev = ieee->dev;
296 struct rtl_80211_hdr_4addr *hdr;
302 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
303 fc = le16_to_cpu(hdr->frame_ctl);
305 /* check that the frame is unicast frame to us */
306 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
307 IEEE80211_FCTL_TODS &&
308 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
309 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
310 /* ToDS frame with own addr BSSID and DA */
311 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
312 IEEE80211_FCTL_FROMDS &&
313 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
314 /* FromDS frame with own addr as DA */
318 if (skb->len < 24 + 8)
321 /* check for port access entity Ethernet type */
322 // pos = skb->data + 24;
323 pos = skb->data + hdrlen;
324 ethertype = (pos[6] << 8) | pos[7];
325 if (ethertype == ETH_P_PAE)
331 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
333 ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
334 struct ieee80211_crypt_data *crypt)
336 struct rtl_80211_hdr_4addr *hdr;
339 if (!crypt || !crypt->ops->decrypt_mpdu)
341 if (ieee->hwsec_active) {
342 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
343 tcb_desc->bHwSec = 1;
345 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
346 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
348 if (ieee->tkip_countermeasures &&
349 strcmp(crypt->ops->name, "TKIP") == 0) {
350 if (net_ratelimit()) {
351 netdev_dbg(ieee->dev, "TKIP countermeasures: dropped "
352 "received packet from %pM\n",
358 atomic_inc(&crypt->refcnt);
359 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
360 atomic_dec(&crypt->refcnt);
362 IEEE80211_DEBUG_DROP(
363 "decryption failed (SA=%pM"
364 ") res=%d\n", hdr->addr2, res);
366 IEEE80211_DEBUG_DROP("Decryption failed ICV "
367 "mismatch (key %d)\n",
368 skb->data[hdrlen + 3] >> 6);
369 ieee->ieee_stats.rx_discards_undecryptable++;
377 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
379 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, struct sk_buff *skb,
380 int keyidx, struct ieee80211_crypt_data *crypt)
382 struct rtl_80211_hdr_4addr *hdr;
385 if (!crypt || !crypt->ops->decrypt_msdu)
387 if (ieee->hwsec_active) {
388 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
389 tcb_desc->bHwSec = 1;
392 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
393 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
395 atomic_inc(&crypt->refcnt);
396 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
397 atomic_dec(&crypt->refcnt);
399 netdev_dbg(ieee->dev, "MSDU decryption/MIC verification failed"
400 " (SA=%pM keyidx=%d)\n",
409 /* this function is stolen from ipw2200 driver*/
410 #define IEEE_PACKET_RETRY_TIME (5 * HZ)
411 static int is_duplicate_packet(struct ieee80211_device *ieee,
412 struct rtl_80211_hdr_4addr *header)
414 u16 fc = le16_to_cpu(header->frame_ctl);
415 u16 sc = le16_to_cpu(header->seq_ctl);
416 u16 seq = WLAN_GET_SEQ_SEQ(sc);
417 u16 frag = WLAN_GET_SEQ_FRAG(sc);
418 u16 *last_seq, *last_frag;
419 unsigned long *last_time;
420 struct rtl_80211_hdr_3addrqos *hdr_3addrqos;
421 struct rtl_80211_hdr_4addrqos *hdr_4addrqos;
426 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
427 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)header;
428 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
431 } else if (IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
432 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)header;
433 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
440 switch (ieee->iw_mode) {
444 struct ieee_ibss_seq *entry = NULL;
445 u8 *mac = header->addr2;
446 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
448 list_for_each(p, &ieee->ibss_mac_hash[index]) {
449 entry = list_entry(p, struct ieee_ibss_seq, list);
450 if (!memcmp(entry->mac, mac, ETH_ALEN))
453 // if (memcmp(entry->mac, mac, ETH_ALEN)){
454 if (p == &ieee->ibss_mac_hash[index]) {
455 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
458 memcpy(entry->mac, mac, ETH_ALEN);
459 entry->seq_num[tid] = seq;
460 entry->frag_num[tid] = frag;
461 entry->packet_time[tid] = jiffies;
462 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
465 last_seq = &entry->seq_num[tid];
466 last_frag = &entry->frag_num[tid];
467 last_time = &entry->packet_time[tid];
472 last_seq = &ieee->last_rxseq_num[tid];
473 last_frag = &ieee->last_rxfrag_num[tid];
474 last_time = &ieee->last_packet_time[tid];
482 // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
484 if ((*last_seq == seq) &&
485 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
486 if (*last_frag == frag)
488 if (*last_frag + 1 != frag)
489 /* out-of-order fragment */
495 *last_time = jiffies;
499 // BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
504 static bool AddReorderEntry(struct rx_ts_record *pTS, struct rx_reorder_entry *pReorderEntry)
506 struct list_head *pList = &pTS->rx_pending_pkt_list;
507 while (pList->next != &pTS->rx_pending_pkt_list) {
508 if (SN_LESS(pReorderEntry->SeqNum, list_entry(pList->next, struct rx_reorder_entry, List)->SeqNum))
510 else if (SN_EQUAL(pReorderEntry->SeqNum, list_entry(pList->next, struct rx_reorder_entry, List)->SeqNum))
515 pReorderEntry->List.next = pList->next;
516 pReorderEntry->List.next->prev = &pReorderEntry->List;
517 pReorderEntry->List.prev = pList;
518 pList->next = &pReorderEntry->List;
523 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb **prxbIndicateArray, u8 index)
528 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__func__,index);
529 for (j = 0; j < index; j++) {
530 //added by amy for reorder
531 struct ieee80211_rxb *prxb = prxbIndicateArray[j];
532 for (i = 0; i < prxb->nr_subframes; i++) {
533 struct sk_buff *sub_skb = prxb->subframes[i];
535 /* convert hdr + possible LLC headers into Ethernet header */
536 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
537 if (sub_skb->len >= 8 &&
538 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
539 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
540 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
541 /* remove RFC1042 or Bridge-Tunnel encapsulation and
542 * replace EtherType */
543 skb_pull(sub_skb, SNAP_SIZE);
544 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
545 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
547 /* Leave Ethernet header part of hdr and full payload */
548 put_unaligned_be16(sub_skb->len, skb_push(sub_skb, 2));
549 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
550 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
552 //stats->rx_packets++;
553 //stats->rx_bytes += sub_skb->len;
555 /* Indicate the packets to upper layer */
557 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
558 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
559 sub_skb->dev = ieee->dev;
560 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
561 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
562 ieee->last_rx_ps_time = jiffies;
572 static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
573 struct ieee80211_rxb *prxb,
574 struct rx_ts_record *pTS, u16 SeqNum)
576 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
577 struct rx_reorder_entry *pReorderEntry = NULL;
578 struct ieee80211_rxb **prxbIndicateArray;
579 u8 WinSize = pHTInfo->RxReorderWinSize;
580 u16 WinEnd = (pTS->rx_indicate_seq + WinSize - 1) % 4096;
582 bool bMatchWinStart = false, bPktInBuf = false;
583 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Seq is %d,pTS->rx_indicate_seq is %d, WinSize is %d\n", __func__, SeqNum, pTS->rx_indicate_seq, WinSize);
585 prxbIndicateArray = kmalloc_array(REORDER_WIN_SIZE,
586 sizeof(struct ieee80211_rxb *),
588 if (!prxbIndicateArray)
591 /* Rx Reorder initialize condition.*/
592 if (pTS->rx_indicate_seq == 0xffff)
593 pTS->rx_indicate_seq = SeqNum;
595 /* Drop out the packet which SeqNum is smaller than WinStart */
596 if (SN_LESS(SeqNum, pTS->rx_indicate_seq)) {
597 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
598 pTS->rx_indicate_seq, SeqNum);
599 pHTInfo->RxReorderDropCounter++;
602 for (i = 0; i < prxb->nr_subframes; i++) {
603 dev_kfree_skb(prxb->subframes[i]);
609 kfree(prxbIndicateArray);
614 * Sliding window manipulation. Conditions includes:
615 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
616 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
618 if (SN_EQUAL(SeqNum, pTS->rx_indicate_seq)) {
619 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) % 4096;
620 bMatchWinStart = true;
621 } else if (SN_LESS(WinEnd, SeqNum)) {
622 if (SeqNum >= (WinSize - 1)) {
623 pTS->rx_indicate_seq = SeqNum + 1 - WinSize;
625 pTS->rx_indicate_seq = 4095 - (WinSize - (SeqNum + 1)) + 1;
627 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n", pTS->rx_indicate_seq, SeqNum);
631 * Indication process.
632 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
633 * with the SeqNum smaller than latest WinStart and buffer other packets.
635 /* For Rx Reorder condition:
636 * 1. All packets with SeqNum smaller than WinStart => Indicate
637 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
639 if (bMatchWinStart) {
640 /* Current packet is going to be indicated.*/
641 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
642 pTS->rx_indicate_seq, SeqNum);
643 prxbIndicateArray[0] = prxb;
644 // printk("========================>%s(): SeqNum is %d\n",__func__,SeqNum);
647 /* Current packet is going to be inserted into pending list.*/
648 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to ordered list\n",__func__);
649 if (!list_empty(&ieee->RxReorder_Unused_List)) {
650 pReorderEntry = list_entry(ieee->RxReorder_Unused_List.next, struct rx_reorder_entry, List);
651 list_del_init(&pReorderEntry->List);
653 /* Make a reorder entry and insert into a the packet list.*/
654 pReorderEntry->SeqNum = SeqNum;
655 pReorderEntry->prxb = prxb;
656 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum);
658 if (!AddReorderEntry(pTS, pReorderEntry)) {
659 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
660 __func__, pTS->rx_indicate_seq, SeqNum);
661 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
664 for (i = 0; i < prxb->nr_subframes; i++) {
665 dev_kfree_skb(prxb->subframes[i]);
671 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
672 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n", pTS->rx_indicate_seq, SeqNum);
676 * Packets are dropped if there is not enough reorder entries.
677 * This part shall be modified!! We can just indicate all the
678 * packets in buffer and get reorder entries.
680 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
683 for (i = 0; i < prxb->nr_subframes; i++) {
684 dev_kfree_skb(prxb->subframes[i]);
692 /* Check if there is any packet need indicate.*/
693 while (!list_empty(&pTS->rx_pending_pkt_list)) {
694 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): start RREORDER indicate\n", __func__);
695 pReorderEntry = list_entry(pTS->rx_pending_pkt_list.prev, struct rx_reorder_entry, List);
696 if (SN_LESS(pReorderEntry->SeqNum, pTS->rx_indicate_seq) ||
697 SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq)) {
698 /* This protect buffer from overflow. */
699 if (index >= REORDER_WIN_SIZE) {
700 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
705 list_del_init(&pReorderEntry->List);
707 if (SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq))
708 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) % 4096;
710 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n", pTS->rx_indicate_seq, SeqNum);
711 prxbIndicateArray[index] = pReorderEntry->prxb;
712 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum);
715 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
722 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
724 // Cancel previous pending timer.
725 // del_timer_sync(&pTS->rx_pkt_pending_timer);
726 pTS->rx_timeout_indicate_seq = 0xffff;
729 if (index > REORDER_WIN_SIZE) {
730 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorder buffer full!! \n");
731 kfree(prxbIndicateArray);
734 ieee80211_indicate_packets(ieee, prxbIndicateArray, index);
737 if (bPktInBuf && pTS->rx_timeout_indicate_seq == 0xffff) {
738 // Set new pending timer.
739 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): SET rx timeout timer\n", __func__);
740 pTS->rx_timeout_indicate_seq = pTS->rx_indicate_seq;
741 if (timer_pending(&pTS->rx_pkt_pending_timer))
742 del_timer_sync(&pTS->rx_pkt_pending_timer);
743 pTS->rx_pkt_pending_timer.expires = jiffies +
744 msecs_to_jiffies(pHTInfo->RxReorderPendingTime);
745 add_timer(&pTS->rx_pkt_pending_timer);
748 kfree(prxbIndicateArray);
751 static u8 parse_subframe(struct ieee80211_device *ieee,
753 struct ieee80211_rx_stats *rx_stats,
754 struct ieee80211_rxb *rxb, u8 *src, u8 *dst)
756 struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data;
757 u16 fc = le16_to_cpu(hdr->frame_ctl);
759 u16 LLCOffset = sizeof(struct rtl_80211_hdr_3addr);
761 bool bIsAggregateFrame = false;
762 u16 nSubframe_Length;
763 u8 nPadding_Length = 0;
766 struct sk_buff *sub_skb;
767 /* just for debug purpose */
768 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
770 if ((IEEE80211_QOS_HAS_SEQ(fc)) && \
771 (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
772 bIsAggregateFrame = true;
775 if (IEEE80211_QOS_HAS_SEQ(fc)) {
779 if (rx_stats->bContainHTC) {
782 // Null packet, don't indicate it to upper layer
783 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
785 if (skb->len <= ChkLength)
788 skb_pull(skb, LLCOffset);
790 if (!bIsAggregateFrame) {
791 rxb->nr_subframes = 1;
793 rxb->subframes[0] = skb;
795 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
798 memcpy(rxb->src, src, ETH_ALEN);
799 memcpy(rxb->dst, dst, ETH_ALEN);
800 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
803 rxb->nr_subframes = 0;
804 memcpy(rxb->src, src, ETH_ALEN);
805 memcpy(rxb->dst, dst, ETH_ALEN);
806 while (skb->len > ETHERNET_HEADER_SIZE) {
807 /* Offset 12 denote 2 mac address */
808 nSubframe_Length = *((u16 *)(skb->data + 12));
809 //==m==>change the length order
810 nSubframe_Length = (nSubframe_Length >> 8) + (nSubframe_Length << 8);
812 if (skb->len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
813 netdev_dbg(ieee->dev, "A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",
815 netdev_dbg(ieee->dev, "A-MSDU parse error!! Subframe Length: %d\n", nSubframe_Length);
816 netdev_dbg(ieee->dev, "nRemain_Length is %d and nSubframe_Length is : %d\n", skb->len, nSubframe_Length);
817 netdev_dbg(ieee->dev, "The Packet SeqNum is %d\n", SeqNum);
821 /* move the data point to data content */
822 skb_pull(skb, ETHERNET_HEADER_SIZE);
825 sub_skb = skb_clone(skb, GFP_ATOMIC);
826 sub_skb->len = nSubframe_Length;
827 sub_skb->tail = sub_skb->data + nSubframe_Length;
829 /* Allocate new skb for releasing to upper layer */
830 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
833 skb_reserve(sub_skb, 12);
834 skb_put_data(sub_skb, skb->data, nSubframe_Length);
836 rxb->subframes[rxb->nr_subframes++] = sub_skb;
837 if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
838 IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
841 skb_pull(skb, nSubframe_Length);
844 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
845 if (nPadding_Length == 4) {
849 if (skb->len < nPadding_Length) {
853 skb_pull(skb, nPadding_Length);
859 //{just for debug added by david
860 //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes);
862 return rxb->nr_subframes;
866 /* All received frames are sent to this function. @skb contains the frame in
867 * IEEE 802.11 format, i.e., in the format it was sent over air.
868 * This function is called only as a tasklet (software IRQ). */
869 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
870 struct ieee80211_rx_stats *rx_stats)
872 struct net_device *dev = ieee->dev;
873 struct rtl_80211_hdr_4addr *hdr;
874 //struct rtl_80211_hdr_3addrqos *hdr;
877 u16 fc, type, stype, sc;
878 struct net_device_stats *stats;
881 //added by amy for reorder
884 struct rx_ts_record *pTS = NULL;
885 //bool bIsAggregateFrame = false;
886 //added by amy for reorder
888 struct net_device *wds = NULL;
889 struct net_device *wds = NULL;
890 int from_assoc_ap = 0;
897 struct ieee80211_crypt_data *crypt = NULL;
901 struct ieee80211_rxb *rxb = NULL;
902 // cheat the hdr type
903 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
904 stats = &ieee->stats;
907 netdev_info(dev, "SKB length < 10\n");
911 fc = le16_to_cpu(hdr->frame_ctl);
912 type = WLAN_FC_GET_TYPE(fc);
913 stype = WLAN_FC_GET_STYPE(fc);
914 sc = le16_to_cpu(hdr->seq_ctl);
916 frag = WLAN_GET_SEQ_FRAG(sc);
917 hdrlen = ieee80211_get_hdrlen(fc);
919 if (HTCCheck(ieee, skb->data)) {
921 netdev_warn(dev, "find HTCControl\n");
923 rx_stats->bContainHTC = true;
926 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
928 /* Put this code here so that we avoid duplicating it in all
929 * Rx paths. - Jean II */
930 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
931 /* If spy monitoring on */
932 if (iface->spy_data.spy_number > 0) {
933 struct iw_quality wstats;
934 wstats.level = rx_stats->rssi;
935 wstats.noise = rx_stats->noise;
936 wstats.updated = 6; /* No qual value */
937 /* Update spy records */
938 wireless_spy_update(dev, hdr->addr2, &wstats);
940 #endif /* IW_WIRELESS_SPY */
941 hostap_update_rx_stats(local->ap, hdr, rx_stats);
944 if (ieee->iw_mode == IW_MODE_MONITOR) {
945 ieee80211_monitor_rx(ieee, skb, rx_stats);
947 stats->rx_bytes += skb->len;
951 if (ieee->host_decrypt) {
953 if (skb->len >= hdrlen + 3)
954 idx = skb->data[hdrlen + 3] >> 6;
955 crypt = ieee->crypt[idx];
959 /* Use station specific key to override default keys if the
960 * receiver address is a unicast address ("individual RA"). If
961 * bcrx_sta_key parameter is set, station specific key is used
962 * even with broad/multicast targets (this is against IEEE
963 * 802.11, but makes it easier to use different keys with
964 * stations that do not support WEP key mapping). */
966 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
967 (void)hostap_handle_sta_crypto(local, hdr, &crypt,
971 /* allow NULL decrypt to indicate an station specific override
972 * for default encryption */
973 if (crypt && (!crypt->ops || !crypt->ops->decrypt_mpdu))
976 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
977 /* This seems to be triggered by some (multicast?)
978 * frames from other than current BSS, so just drop the
979 * frames silently instead of filling system log with
981 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
984 ieee->ieee_stats.rx_discards_undecryptable++;
989 if (skb->len < IEEE80211_DATA_HDR3_LEN)
992 // if QoS enabled, should check the sequence for each of the AC
993 if ((!ieee->pHTInfo->bCurRxReorderEnable) || !ieee->current_network.qos_data.active || !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)) {
994 if (is_duplicate_packet(ieee, hdr))
998 struct rx_ts_record *pRxTS = NULL;
999 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__func__, tid);
1002 (struct ts_common_info **)&pRxTS,
1004 Frame_QoSTID((u8 *)(skb->data)),
1008 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->rx_last_frag_num is %d,frag is %d,pRxTS->rx_last_seq_num is %d,seq is %d\n",__func__,pRxTS->rx_last_frag_num,frag,pRxTS->rx_last_seq_num,WLAN_GET_SEQ_SEQ(sc));
1009 if ((fc & (1 << 11)) &&
1010 (frag == pRxTS->rx_last_frag_num) &&
1011 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->rx_last_seq_num)) {
1014 pRxTS->rx_last_frag_num = frag;
1015 pRxTS->rx_last_seq_num = WLAN_GET_SEQ_SEQ(sc);
1018 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n", __func__);
1022 if (type == IEEE80211_FTYPE_MGMT) {
1025 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1026 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1032 /* Data frame - extract src/dst addresses */
1033 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
1034 case IEEE80211_FCTL_FROMDS:
1035 memcpy(dst, hdr->addr1, ETH_ALEN);
1036 memcpy(src, hdr->addr3, ETH_ALEN);
1037 memcpy(bssid, hdr->addr2, ETH_ALEN);
1039 case IEEE80211_FCTL_TODS:
1040 memcpy(dst, hdr->addr3, ETH_ALEN);
1041 memcpy(src, hdr->addr2, ETH_ALEN);
1042 memcpy(bssid, hdr->addr1, ETH_ALEN);
1044 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
1045 if (skb->len < IEEE80211_DATA_HDR4_LEN)
1047 memcpy(dst, hdr->addr3, ETH_ALEN);
1048 memcpy(src, hdr->addr4, ETH_ALEN);
1049 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1052 memcpy(dst, hdr->addr1, ETH_ALEN);
1053 memcpy(src, hdr->addr2, ETH_ALEN);
1054 memcpy(bssid, hdr->addr3, ETH_ALEN);
1059 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
1062 skb->dev = dev = wds;
1063 stats = hostap_get_stats(dev);
1066 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
1067 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
1069 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
1070 /* Frame from BSSID of the AP for which we are a client */
1071 skb->dev = dev = ieee->stadev;
1072 stats = hostap_get_stats(dev);
1076 if ((ieee->iw_mode == IW_MODE_MASTER ||
1077 ieee->iw_mode == IW_MODE_REPEAT) &&
1079 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
1081 case AP_RX_CONTINUE_NOT_AUTHORIZED:
1082 case AP_RX_CONTINUE:
1091 //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
1092 /* Nullfunc frames may have PS-bit set, so they must be passed to
1093 * hostap_handle_sta_rx() before being dropped here. */
1094 if (stype != IEEE80211_STYPE_DATA &&
1095 stype != IEEE80211_STYPE_DATA_CFACK &&
1096 stype != IEEE80211_STYPE_DATA_CFPOLL &&
1097 stype != IEEE80211_STYPE_DATA_CFACKPOLL &&
1098 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
1100 if (stype != IEEE80211_STYPE_NULLFUNC)
1101 IEEE80211_DEBUG_DROP(
1102 "RX: dropped data frame "
1103 "with no data (type=0x%02x, "
1104 "subtype=0x%02x, len=%d)\n",
1105 type, stype, skb->len);
1108 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1111 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1113 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1114 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
1115 netdev_dbg(ieee->dev, "decrypt frame error\n");
1120 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
1122 /* skb: hdr + (possibly fragmented) plaintext payload */
1123 // PR: FIXME: hostap has additional conditions in the "if" below:
1124 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1125 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
1127 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
1128 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1131 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
1132 "Rx cannot get skb from fragment "
1133 "cache (morefrag=%d seq=%u frag=%u)\n",
1134 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
1135 WLAN_GET_SEQ_SEQ(sc), frag);
1142 if (frag_skb->tail + flen > frag_skb->end) {
1143 netdev_warn(dev, "host decrypted and "
1144 "reassembled frame did not fit skb\n");
1145 ieee80211_frag_cache_invalidate(ieee, hdr);
1150 /* copy first fragment (including full headers) into
1151 * beginning of the fragment cache skb */
1152 skb_put_data(frag_skb, skb->data, flen);
1154 /* append frame payload to the end of the fragment
1156 skb_put_data(frag_skb, skb->data + hdrlen, flen);
1158 dev_kfree_skb_any(skb);
1161 if (fc & IEEE80211_FCTL_MOREFRAGS) {
1162 /* more fragments expected - leave the skb in fragment
1163 * cache for now; it will be delivered to upper layers
1164 * after all fragments have been received */
1168 /* this was the last fragment and the frame will be
1169 * delivered, so remove skb from fragment cache */
1171 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
1172 ieee80211_frag_cache_invalidate(ieee, hdr);
1175 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1176 * encrypted/authenticated */
1177 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1178 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
1179 netdev_dbg(ieee->dev, "==>decrypt msdu error\n");
1183 //added by amy for AP roaming
1184 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1185 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1187 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
1188 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1189 if (/*ieee->ieee802_1x &&*/
1190 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1192 #ifdef CONFIG_IEEE80211_DEBUG
1193 /* pass unencrypted EAPOL frames even if encryption is
1195 struct eapol *eap = (struct eapol *)(skb->data +
1197 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1198 eap_get_type(eap->type));
1201 IEEE80211_DEBUG_DROP(
1202 "encryption configured, but RX "
1203 "frame not encrypted (SA=%pM)\n",
1209 #ifdef CONFIG_IEEE80211_DEBUG
1210 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1211 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1212 struct eapol *eap = (struct eapol *)(skb->data +
1214 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1215 eap_get_type(eap->type));
1219 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
1220 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1221 IEEE80211_DEBUG_DROP(
1222 "dropped unencrypted RX data "
1224 " (drop_unencrypted=1)\n",
1229 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1230 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
1233 //added by amy for reorder
1234 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1235 && !is_multicast_ether_addr(hdr->addr1)) {
1236 TID = Frame_QoSTID(skb->data);
1237 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1238 GetTs(ieee, (struct ts_common_info **)&pTS, hdr->addr2, TID, RX_DIR, true);
1239 if (TID != 0 && TID != 3) {
1240 ieee->bis_any_nonbepkts = true;
1243 //added by amy for reorder
1244 /* skb: hdr + (possible reassembled) full plaintext payload */
1245 //ethertype = (payload[6] << 8) | payload[7];
1246 rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC);
1249 /* to parse amsdu packets */
1250 /* qos data packets & reserved bit is 1 */
1251 if (parse_subframe(ieee, skb, rx_stats, rxb, src, dst) == 0) {
1252 /* only to free rxb, and not submit the packets to upper layer */
1253 for (i = 0; i < rxb->nr_subframes; i++) {
1254 dev_kfree_skb(rxb->subframes[i]);
1261 //added by amy for reorder
1262 if (!ieee->pHTInfo->bCurRxReorderEnable || !pTS) {
1263 //added by amy for reorder
1264 for (i = 0; i < rxb->nr_subframes; i++) {
1265 struct sk_buff *sub_skb = rxb->subframes[i];
1268 /* convert hdr + possible LLC headers into Ethernet header */
1269 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1270 if (sub_skb->len >= 8 &&
1271 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1272 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1273 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1274 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1275 * replace EtherType */
1276 skb_pull(sub_skb, SNAP_SIZE);
1277 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1278 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1281 /* Leave Ethernet header part of hdr and full payload */
1282 len = be16_to_cpu(htons(sub_skb->len));
1283 memcpy(skb_push(sub_skb, 2), &len, 2);
1284 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1285 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1288 stats->rx_packets++;
1289 stats->rx_bytes += sub_skb->len;
1290 if (is_multicast_ether_addr(dst)) {
1294 /* Indicate the packets to upper layer */
1295 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1296 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1298 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1299 //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
1300 ieee->last_rx_ps_time = jiffies;
1308 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n", __func__);
1309 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1318 hostap_handle_sta_release(sta);
1325 stats->rx_dropped++;
1327 /* Returning 0 indicates to caller that we have not handled the SKB--
1328 * so it is still allocated and can be used again by underlying
1329 * hardware as a DMA target */
1332 EXPORT_SYMBOL(ieee80211_rx);
1334 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
1336 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1339 * Make the structure we read from the beacon packet to have
1342 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1343 *info_element, int sub_type)
1346 if (info_element->qui_subtype != sub_type)
1348 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1350 if (info_element->qui_type != QOS_OUI_TYPE)
1352 if (info_element->version != QOS_VERSION_1)
1360 * Parse a QoS parameter element
1362 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1363 *element_param, struct ieee80211_info_element
1367 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1369 if (!info_element || !element_param)
1372 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1373 memcpy(element_param->info_element.qui, info_element->data,
1375 element_param->info_element.elementID = info_element->id;
1376 element_param->info_element.length = info_element->len;
1380 ret = ieee80211_verify_qos_info(&element_param->info_element,
1381 QOS_OUI_PARAM_SUB_TYPE);
1386 * Parse a QoS information element
1388 static int ieee80211_read_qos_info_element(
1389 struct ieee80211_qos_information_element *element_info,
1390 struct ieee80211_info_element *info_element)
1393 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1400 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1401 memcpy(element_info->qui, info_element->data,
1403 element_info->elementID = info_element->id;
1404 element_info->length = info_element->len;
1409 ret = ieee80211_verify_qos_info(element_info,
1410 QOS_OUI_INFO_SUB_TYPE);
1416 * Write QoS parameters from the ac parameters.
1418 static int ieee80211_qos_convert_ac_to_parameters(
1419 struct ieee80211_qos_parameter_info *param_elm,
1420 struct ieee80211_qos_parameters *qos_param)
1423 struct ieee80211_qos_ac_parameter *ac_params;
1428 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1429 ac_params = &(param_elm->ac_params_record[i]);
1431 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1433 if (aci >= QOS_QUEUE_NUM)
1435 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1437 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1438 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2 : qos_param->aifs[aci];
1440 qos_param->cw_min[aci] =
1441 cpu_to_le16(ac_params->ecw_min_max & 0x0F);
1443 qos_param->cw_max[aci] =
1444 cpu_to_le16((ac_params->ecw_min_max & 0xF0) >> 4);
1446 qos_param->flag[aci] =
1447 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1448 qos_param->tx_op_limit[aci] = ac_params->tx_op_limit;
1454 * we have a generic data element which it may contain QoS information or
1455 * parameters element. check the information element length to decide
1456 * which type to read
1458 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1460 struct ieee80211_network *network)
1463 struct ieee80211_qos_parameters *qos_param = NULL;
1464 struct ieee80211_qos_information_element qos_info_element;
1466 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1469 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1470 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1472 struct ieee80211_qos_parameter_info param_element;
1474 rc = ieee80211_read_qos_param_element(¶m_element,
1477 qos_param = &(network->qos_data.parameters);
1478 ieee80211_qos_convert_ac_to_parameters(¶m_element,
1480 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1481 network->qos_data.param_count =
1482 param_element.info_element.ac_info & 0x0F;
1487 IEEE80211_DEBUG_QOS("QoS is supported\n");
1488 network->qos_data.supported = 1;
1493 #ifdef CONFIG_IEEE80211_DEBUG
1494 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1496 static const char *get_info_element_string(u16 id)
1501 MFIE_STRING(FH_SET);
1502 MFIE_STRING(DS_SET);
1503 MFIE_STRING(CF_SET);
1505 MFIE_STRING(IBSS_SET);
1506 MFIE_STRING(COUNTRY);
1507 MFIE_STRING(HOP_PARAMS);
1508 MFIE_STRING(HOP_TABLE);
1509 MFIE_STRING(REQUEST);
1510 MFIE_STRING(CHALLENGE);
1511 MFIE_STRING(POWER_CONSTRAINT);
1512 MFIE_STRING(POWER_CAPABILITY);
1513 MFIE_STRING(TPC_REQUEST);
1514 MFIE_STRING(TPC_REPORT);
1515 MFIE_STRING(SUPP_CHANNELS);
1517 MFIE_STRING(MEASURE_REQUEST);
1518 MFIE_STRING(MEASURE_REPORT);
1520 MFIE_STRING(IBSS_DFS);
1521 // MFIE_STRING(ERP_INFO);
1523 MFIE_STRING(RATES_EX);
1524 MFIE_STRING(GENERIC);
1525 MFIE_STRING(QOS_PARAMETER);
1532 static inline void ieee80211_extract_country_ie(
1533 struct ieee80211_device *ieee,
1534 struct ieee80211_info_element *info_element,
1535 struct ieee80211_network *network,
1539 if (IS_DOT11D_ENABLE(ieee)) {
1540 if (info_element->len != 0) {
1541 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1542 network->CountryIeLen = info_element->len;
1544 if (!IS_COUNTRY_IE_VALID(ieee)) {
1545 dot11d_update_country_ie(ieee, addr2, info_element->len, info_element->data);
1550 // 070305, rcnjko: I update country IE watch dog here because
1551 // some AP (e.g. Cisco 1242) don't include country IE in their
1552 // probe response frame.
1554 if (IS_EQUAL_CIE_SRC(ieee, addr2)) {
1555 UPDATE_CIE_WATCHDOG(ieee);
1561 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1562 struct ieee80211_info_element *info_element,
1564 struct ieee80211_network *network,
1565 struct ieee80211_rx_stats *stats)
1569 u16 tmp_htcap_len = 0;
1570 u16 tmp_htinfo_len = 0;
1571 u16 ht_realtek_agg_len = 0;
1572 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1573 // u16 broadcom_len = 0;
1574 #ifdef CONFIG_IEEE80211_DEBUG
1579 while (length >= sizeof(*info_element)) {
1580 if (sizeof(*info_element) + info_element->len > length) {
1581 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1582 "info_element->len + 2 > left : "
1583 "info_element->len+2=%zd left=%d, id=%d.\n",
1585 sizeof(*info_element),
1586 length, info_element->id);
1587 /* We stop processing but don't return an error here
1588 * because some misbehaviour APs break this rule. ie.
1589 * Orinoco AP1000. */
1593 switch (info_element->id) {
1594 case MFIE_TYPE_SSID:
1595 if (ieee80211_is_empty_essid(info_element->data,
1596 info_element->len)) {
1597 network->flags |= NETWORK_EMPTY_ESSID;
1601 network->ssid_len = min(info_element->len,
1602 (u8)IW_ESSID_MAX_SIZE);
1603 memcpy(network->ssid, info_element->data, network->ssid_len);
1604 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1605 memset(network->ssid + network->ssid_len, 0,
1606 IW_ESSID_MAX_SIZE - network->ssid_len);
1608 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1609 network->ssid, network->ssid_len);
1612 case MFIE_TYPE_RATES:
1613 #ifdef CONFIG_IEEE80211_DEBUG
1616 network->rates_len = min(info_element->len,
1618 for (i = 0; i < network->rates_len; i++) {
1619 network->rates[i] = info_element->data[i];
1620 #ifdef CONFIG_IEEE80211_DEBUG
1621 p += scnprintf(p, sizeof(rates_str) -
1622 (p - rates_str), "%02X ",
1625 if (ieee80211_is_ofdm_rate
1626 (info_element->data[i])) {
1627 network->flags |= NETWORK_HAS_OFDM;
1628 if (info_element->data[i] &
1629 IEEE80211_BASIC_RATE_MASK)
1635 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1636 rates_str, network->rates_len);
1639 case MFIE_TYPE_RATES_EX:
1640 #ifdef CONFIG_IEEE80211_DEBUG
1643 network->rates_ex_len = min(info_element->len,
1644 MAX_RATES_EX_LENGTH);
1645 for (i = 0; i < network->rates_ex_len; i++) {
1646 network->rates_ex[i] = info_element->data[i];
1647 #ifdef CONFIG_IEEE80211_DEBUG
1648 p += scnprintf(p, sizeof(rates_str) -
1649 (p - rates_str), "%02X ",
1650 network->rates_ex[i]);
1652 if (ieee80211_is_ofdm_rate
1653 (info_element->data[i])) {
1654 network->flags |= NETWORK_HAS_OFDM;
1655 if (info_element->data[i] &
1656 IEEE80211_BASIC_RATE_MASK)
1662 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1663 rates_str, network->rates_ex_len);
1666 case MFIE_TYPE_DS_SET:
1667 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1668 info_element->data[0]);
1669 network->channel = info_element->data[0];
1672 case MFIE_TYPE_FH_SET:
1673 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1676 case MFIE_TYPE_CF_SET:
1677 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1681 if (info_element->len < 4)
1684 network->tim.tim_count = info_element->data[0];
1685 network->tim.tim_period = info_element->data[1];
1687 network->dtim_period = info_element->data[1];
1688 if (ieee->state != IEEE80211_LINKED)
1691 network->last_dtim_sta_time[0] = stats->mac_time[0];
1692 network->last_dtim_sta_time[1] = stats->mac_time[1];
1694 network->dtim_data = IEEE80211_DTIM_VALID;
1696 if (info_element->data[0] != 0)
1699 if (info_element->data[2] & 1)
1700 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1702 offset = (info_element->data[2] >> 1) * 2;
1704 if (ieee->assoc_id < 8 * offset ||
1705 ieee->assoc_id > 8 * (offset + info_element->len - 3))
1709 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1711 if (info_element->data[3 + offset] & (1 << (ieee->assoc_id % 8)))
1712 network->dtim_data |= IEEE80211_DTIM_UCAST;
1714 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1718 network->erp_value = info_element->data[0];
1719 network->flags |= NETWORK_HAS_ERP_VALUE;
1720 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1721 network->erp_value);
1723 case MFIE_TYPE_IBSS_SET:
1724 network->atim_window = info_element->data[0];
1725 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1726 network->atim_window);
1729 case MFIE_TYPE_CHALLENGE:
1730 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1733 case MFIE_TYPE_GENERIC:
1734 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1736 if (!ieee80211_parse_qos_info_param_IE(info_element,
1740 if (info_element->len >= 4 &&
1741 info_element->data[0] == 0x00 &&
1742 info_element->data[1] == 0x50 &&
1743 info_element->data[2] == 0xf2 &&
1744 info_element->data[3] == 0x01) {
1745 network->wpa_ie_len = min(info_element->len + 2,
1747 memcpy(network->wpa_ie, info_element,
1748 network->wpa_ie_len);
1753 if (info_element->len == 7 &&
1754 info_element->data[0] == 0x00 &&
1755 info_element->data[1] == 0xe0 &&
1756 info_element->data[2] == 0x4c &&
1757 info_element->data[3] == 0x01 &&
1758 info_element->data[4] == 0x02) {
1759 network->Turbo_Enable = 1;
1763 //for HTcap and HTinfo parameters
1764 if (tmp_htcap_len == 0) {
1765 if (info_element->len >= 4 &&
1766 info_element->data[0] == 0x00 &&
1767 info_element->data[1] == 0x90 &&
1768 info_element->data[2] == 0x4c &&
1769 info_element->data[3] == 0x033){
1771 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
1772 if (tmp_htcap_len != 0) {
1773 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1774 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ? \
1775 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
1776 memcpy(network->bssht.bdHTCapBuf, info_element->data, network->bssht.bdHTCapLen);
1779 if (tmp_htcap_len != 0)
1780 network->bssht.bdSupportHT = true;
1782 network->bssht.bdSupportHT = false;
1786 if (tmp_htinfo_len == 0) {
1787 if (info_element->len >= 4 &&
1788 info_element->data[0] == 0x00 &&
1789 info_element->data[1] == 0x90 &&
1790 info_element->data[2] == 0x4c &&
1791 info_element->data[3] == 0x034){
1793 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
1794 if (tmp_htinfo_len != 0) {
1795 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1796 if (tmp_htinfo_len) {
1797 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf) ? \
1798 sizeof(network->bssht.bdHTInfoBuf) : tmp_htinfo_len;
1799 memcpy(network->bssht.bdHTInfoBuf, info_element->data, network->bssht.bdHTInfoLen);
1807 if (ieee->aggregation) {
1808 if (network->bssht.bdSupportHT) {
1809 if (info_element->len >= 4 &&
1810 info_element->data[0] == 0x00 &&
1811 info_element->data[1] == 0xe0 &&
1812 info_element->data[2] == 0x4c &&
1813 info_element->data[3] == 0x02){
1815 ht_realtek_agg_len = min(info_element->len, (u8)MAX_IE_LEN);
1816 memcpy(ht_realtek_agg_buf, info_element->data, info_element->len);
1819 if (ht_realtek_agg_len >= 5) {
1820 network->bssht.bdRT2RTAggregation = true;
1822 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1823 network->bssht.bdRT2RTLongSlotTime = true;
1829 //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0)
1831 if ((info_element->len >= 3 &&
1832 info_element->data[0] == 0x00 &&
1833 info_element->data[1] == 0x05 &&
1834 info_element->data[2] == 0xb5) ||
1835 (info_element->len >= 3 &&
1836 info_element->data[0] == 0x00 &&
1837 info_element->data[1] == 0x0a &&
1838 info_element->data[2] == 0xf7) ||
1839 (info_element->len >= 3 &&
1840 info_element->data[0] == 0x00 &&
1841 info_element->data[1] == 0x10 &&
1842 info_element->data[2] == 0x18)){
1844 network->broadcom_cap_exist = true;
1848 if (info_element->len >= 3 &&
1849 info_element->data[0] == 0x00 &&
1850 info_element->data[1] == 0x0c &&
1851 info_element->data[2] == 0x43) {
1852 network->ralink_cap_exist = true;
1854 network->ralink_cap_exist = false;
1855 //added by amy for atheros AP
1856 if ((info_element->len >= 3 &&
1857 info_element->data[0] == 0x00 &&
1858 info_element->data[1] == 0x03 &&
1859 info_element->data[2] == 0x7f) ||
1860 (info_element->len >= 3 &&
1861 info_element->data[0] == 0x00 &&
1862 info_element->data[1] == 0x13 &&
1863 info_element->data[2] == 0x74)) {
1864 netdev_dbg(ieee->dev, "========> athros AP is exist\n");
1865 network->atheros_cap_exist = true;
1867 network->atheros_cap_exist = false;
1869 if (info_element->len >= 3 &&
1870 info_element->data[0] == 0x00 &&
1871 info_element->data[1] == 0x40 &&
1872 info_element->data[2] == 0x96) {
1873 network->cisco_cap_exist = true;
1875 network->cisco_cap_exist = false;
1876 //added by amy for LEAP of cisco
1877 if (info_element->len > 4 &&
1878 info_element->data[0] == 0x00 &&
1879 info_element->data[1] == 0x40 &&
1880 info_element->data[2] == 0x96 &&
1881 info_element->data[3] == 0x01) {
1882 if (info_element->len == 6) {
1883 memcpy(network->CcxRmState, &info_element[4], 2);
1884 if (network->CcxRmState[0] != 0)
1885 network->bCcxRmEnable = true;
1887 network->bCcxRmEnable = false;
1889 // CCXv4 Table 59-1 MBSSID Masks.
1891 network->MBssidMask = network->CcxRmState[1] & 0x07;
1892 if (network->MBssidMask != 0) {
1893 network->bMBssidValid = true;
1894 network->MBssidMask = 0xff << (network->MBssidMask);
1895 ether_addr_copy(network->MBssid, network->bssid);
1896 network->MBssid[5] &= network->MBssidMask;
1898 network->bMBssidValid = false;
1901 network->bCcxRmEnable = false;
1904 if (info_element->len > 4 &&
1905 info_element->data[0] == 0x00 &&
1906 info_element->data[1] == 0x40 &&
1907 info_element->data[2] == 0x96 &&
1908 info_element->data[3] == 0x03) {
1909 if (info_element->len == 5) {
1910 network->bWithCcxVerNum = true;
1911 network->BssCcxVerNumber = info_element->data[4];
1913 network->bWithCcxVerNum = false;
1914 network->BssCcxVerNumber = 0;
1920 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1922 network->rsn_ie_len = min(info_element->len + 2,
1924 memcpy(network->rsn_ie, info_element,
1925 network->rsn_ie_len);
1928 //HT related element.
1929 case MFIE_TYPE_HT_CAP:
1930 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
1932 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
1933 if (tmp_htcap_len != 0) {
1934 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1935 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ? \
1936 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
1937 memcpy(network->bssht.bdHTCapBuf, info_element->data, network->bssht.bdHTCapLen);
1939 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1940 // windows driver will update WMM parameters each beacon received once connected
1941 // Linux driver is a bit different.
1942 network->bssht.bdSupportHT = true;
1944 network->bssht.bdSupportHT = false;
1948 case MFIE_TYPE_HT_INFO:
1949 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
1951 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
1952 if (tmp_htinfo_len) {
1953 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
1954 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf) ? \
1955 sizeof(network->bssht.bdHTInfoBuf) : tmp_htinfo_len;
1956 memcpy(network->bssht.bdHTInfoBuf, info_element->data, network->bssht.bdHTInfoLen);
1960 case MFIE_TYPE_AIRONET:
1961 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
1963 if (info_element->len > IE_CISCO_FLAG_POSITION) {
1964 network->bWithAironetIE = true;
1966 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
1967 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
1968 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
1969 if ((info_element->data[IE_CISCO_FLAG_POSITION] & SUPPORT_CKIP_MIC) ||
1970 (info_element->data[IE_CISCO_FLAG_POSITION] & SUPPORT_CKIP_PK)) {
1971 network->bCkipSupported = true;
1973 network->bCkipSupported = false;
1976 network->bWithAironetIE = false;
1977 network->bCkipSupported = false;
1980 case MFIE_TYPE_QOS_PARAMETER:
1981 netdev_err(ieee->dev,
1982 "QoS Error need to parse QOS_PARAMETER IE\n");
1985 case MFIE_TYPE_COUNTRY:
1986 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
1988 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
1992 IEEE80211_DEBUG_MGMT
1993 ("Unsupported info element: %s (%d)\n",
1994 get_info_element_string(info_element->id),
1999 length -= sizeof(*info_element) + info_element->len;
2001 (struct ieee80211_info_element *)&info_element->
2002 data[info_element->len];
2005 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2006 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation) {
2007 network->unknown_cap_exist = true;
2009 network->unknown_cap_exist = false;
2014 static inline u8 ieee80211_SignalStrengthTranslate(
2020 // Step 1. Scale mapping.
2021 if (CurrSS >= 71 && CurrSS <= 100) {
2022 RetSS = 90 + ((CurrSS - 70) / 3);
2023 } else if (CurrSS >= 41 && CurrSS <= 70) {
2024 RetSS = 78 + ((CurrSS - 40) / 3);
2025 } else if (CurrSS >= 31 && CurrSS <= 40) {
2026 RetSS = 66 + (CurrSS - 30);
2027 } else if (CurrSS >= 21 && CurrSS <= 30) {
2028 RetSS = 54 + (CurrSS - 20);
2029 } else if (CurrSS >= 5 && CurrSS <= 20) {
2030 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2031 } else if (CurrSS == 4) {
2033 } else if (CurrSS == 3) {
2035 } else if (CurrSS == 2) {
2037 } else if (CurrSS == 1) {
2042 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2044 // Step 2. Smoothing.
2046 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2052 static long ieee80211_translate_todbm(u8 signal_strength_index)
2054 long signal_power; // in dBm.
2056 // Translate to dBm (x=0.5y-95).
2057 signal_power = (long)((signal_strength_index + 1) >> 1);
2060 return signal_power;
2063 static inline int ieee80211_network_init(
2064 struct ieee80211_device *ieee,
2065 struct ieee80211_probe_response *beacon,
2066 struct ieee80211_network *network,
2067 struct ieee80211_rx_stats *stats)
2069 #ifdef CONFIG_IEEE80211_DEBUG
2070 //char rates_str[64];
2074 network->qos_data.active = 0;
2075 network->qos_data.supported = 0;
2076 network->qos_data.param_count = 0;
2077 network->qos_data.old_param_count = 0;
2079 /* Pull out fixed field data */
2080 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
2081 network->capability = le16_to_cpu(beacon->capability);
2082 network->last_scanned = jiffies;
2083 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
2084 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
2085 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
2086 /* Where to pull this? beacon->listen_interval;*/
2087 network->listen_interval = 0x0A;
2088 network->rates_len = network->rates_ex_len = 0;
2089 network->last_associate = 0;
2090 network->ssid_len = 0;
2092 network->atim_window = 0;
2093 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2095 network->berp_info_valid = false;
2096 network->broadcom_cap_exist = false;
2097 network->ralink_cap_exist = false;
2098 network->atheros_cap_exist = false;
2099 network->cisco_cap_exist = false;
2100 network->unknown_cap_exist = false;
2102 network->Turbo_Enable = 0;
2104 network->CountryIeLen = 0;
2105 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2106 //Initialize HT parameters
2107 //ieee80211_ht_initialize(&network->bssht);
2108 HTInitializeBssDesc(&network->bssht);
2109 if (stats->freq == IEEE80211_52GHZ_BAND) {
2110 /* for A band (No DS info) */
2111 network->channel = stats->received_channel;
2113 network->flags |= NETWORK_HAS_CCK;
2115 network->wpa_ie_len = 0;
2116 network->rsn_ie_len = 0;
2118 if (ieee80211_parse_info_param
2119 (ieee, beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2123 if (stats->freq == IEEE80211_52GHZ_BAND)
2124 network->mode = IEEE_A;
2126 if (network->flags & NETWORK_HAS_OFDM)
2127 network->mode |= IEEE_G;
2128 if (network->flags & NETWORK_HAS_CCK)
2129 network->mode |= IEEE_B;
2132 if (network->mode == 0) {
2133 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
2135 escape_essid(network->ssid,
2141 if (network->bssht.bdSupportHT) {
2142 if (network->mode == IEEE_A)
2143 network->mode = IEEE_N_5G;
2144 else if (network->mode & (IEEE_G | IEEE_B))
2145 network->mode = IEEE_N_24G;
2147 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
2148 network->flags |= NETWORK_EMPTY_ESSID;
2150 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2151 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2152 stats->noise = ieee80211_translate_todbm((u8)(100 - stats->signal)) - 25;
2154 memcpy(&network->stats, stats, sizeof(network->stats));
2159 static inline int is_same_network(struct ieee80211_network *src,
2160 struct ieee80211_network *dst, struct ieee80211_device *ieee)
2162 /* A network is only a duplicate if the channel, BSSID, ESSID
2163 * and the capability field (in particular IBSS and BSS) all match.
2164 * We treat all <hidden> with the same BSSID and channel
2166 return //((src->ssid_len == dst->ssid_len) &&
2167 (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2168 (src->channel == dst->channel) &&
2169 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
2170 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
2171 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) &&
2172 ((src->capability & WLAN_CAPABILITY_IBSS) ==
2173 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
2174 ((src->capability & WLAN_CAPABILITY_BSS) ==
2175 (dst->capability & WLAN_CAPABILITY_BSS)));
2178 static inline void update_network(struct ieee80211_network *dst,
2179 struct ieee80211_network *src)
2184 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
2185 dst->capability = src->capability;
2186 memcpy(dst->rates, src->rates, src->rates_len);
2187 dst->rates_len = src->rates_len;
2188 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2189 dst->rates_ex_len = src->rates_ex_len;
2190 if (src->ssid_len > 0) {
2191 memset(dst->ssid, 0, dst->ssid_len);
2192 dst->ssid_len = src->ssid_len;
2193 memcpy(dst->ssid, src->ssid, src->ssid_len);
2195 dst->mode = src->mode;
2196 dst->flags = src->flags;
2197 dst->time_stamp[0] = src->time_stamp[0];
2198 dst->time_stamp[1] = src->time_stamp[1];
2199 if (src->flags & NETWORK_HAS_ERP_VALUE) {
2200 dst->erp_value = src->erp_value;
2201 dst->berp_info_valid = src->berp_info_valid = true;
2203 dst->beacon_interval = src->beacon_interval;
2204 dst->listen_interval = src->listen_interval;
2205 dst->atim_window = src->atim_window;
2206 dst->dtim_period = src->dtim_period;
2207 dst->dtim_data = src->dtim_data;
2208 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
2209 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2210 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2212 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2213 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2214 dst->bssht.bdHTCapLen = src->bssht.bdHTCapLen;
2215 memcpy(dst->bssht.bdHTCapBuf, src->bssht.bdHTCapBuf, src->bssht.bdHTCapLen);
2216 dst->bssht.bdHTInfoLen = src->bssht.bdHTInfoLen;
2217 memcpy(dst->bssht.bdHTInfoBuf, src->bssht.bdHTInfoBuf, src->bssht.bdHTInfoLen);
2218 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2219 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2220 dst->broadcom_cap_exist = src->broadcom_cap_exist;
2221 dst->ralink_cap_exist = src->ralink_cap_exist;
2222 dst->atheros_cap_exist = src->atheros_cap_exist;
2223 dst->cisco_cap_exist = src->cisco_cap_exist;
2224 dst->unknown_cap_exist = src->unknown_cap_exist;
2225 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
2226 dst->wpa_ie_len = src->wpa_ie_len;
2227 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
2228 dst->rsn_ie_len = src->rsn_ie_len;
2230 dst->last_scanned = jiffies;
2231 /* qos related parameters */
2232 //qos_active = src->qos_data.active;
2233 qos_active = dst->qos_data.active;
2234 //old_param = dst->qos_data.old_param_count;
2235 old_param = dst->qos_data.param_count;
2236 if (dst->flags & NETWORK_HAS_QOS_MASK)
2237 memcpy(&dst->qos_data, &src->qos_data,
2238 sizeof(struct ieee80211_qos_data));
2240 dst->qos_data.supported = src->qos_data.supported;
2241 dst->qos_data.param_count = src->qos_data.param_count;
2244 if (dst->qos_data.supported == 1) {
2245 dst->QoS_Enable = 1;
2248 ("QoS the network %s is QoS supported\n",
2252 ("QoS the network is QoS supported\n");
2254 dst->qos_data.active = qos_active;
2255 dst->qos_data.old_param_count = old_param;
2257 /* dst->last_associate is not overwritten */
2258 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2259 if (src->wmm_param[0].aci_aifsn || \
2260 src->wmm_param[1].aci_aifsn || \
2261 src->wmm_param[2].aci_aifsn || \
2262 src->wmm_param[3].aci_aifsn) {
2263 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2265 //dst->QoS_Enable = src->QoS_Enable;
2267 dst->Turbo_Enable = src->Turbo_Enable;
2270 dst->CountryIeLen = src->CountryIeLen;
2271 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2273 //added by amy for LEAP
2274 dst->bWithAironetIE = src->bWithAironetIE;
2275 dst->bCkipSupported = src->bCkipSupported;
2276 memcpy(dst->CcxRmState, src->CcxRmState, 2);
2277 dst->bCcxRmEnable = src->bCcxRmEnable;
2278 dst->MBssidMask = src->MBssidMask;
2279 dst->bMBssidValid = src->bMBssidValid;
2280 memcpy(dst->MBssid, src->MBssid, 6);
2281 dst->bWithCcxVerNum = src->bWithCcxVerNum;
2282 dst->BssCcxVerNumber = src->BssCcxVerNumber;
2286 static inline int is_beacon(__le16 fc)
2288 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
2291 static inline void ieee80211_process_probe_response(
2292 struct ieee80211_device *ieee,
2293 struct ieee80211_probe_response *beacon,
2294 struct ieee80211_rx_stats *stats)
2296 struct ieee80211_network *network;
2297 struct ieee80211_network *target;
2298 struct ieee80211_network *oldest = NULL;
2299 #ifdef CONFIG_IEEE80211_DEBUG
2300 struct ieee80211_info_element *info_element = &beacon->info_element[0];
2302 int fc = WLAN_FC_GET_STYPE(le16_to_cpu(beacon->header.frame_ctl));
2303 unsigned long flags;
2308 network = kzalloc(sizeof(*network), GFP_ATOMIC);
2312 capability = le16_to_cpu(beacon->capability);
2313 IEEE80211_DEBUG_SCAN(
2314 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
2315 escape_essid(info_element->data, info_element->len),
2316 beacon->header.addr3,
2317 (capability & BIT(0xf)) ? '1' : '0',
2318 (capability & BIT(0xe)) ? '1' : '0',
2319 (capability & BIT(0xd)) ? '1' : '0',
2320 (capability & BIT(0xc)) ? '1' : '0',
2321 (capability & BIT(0xb)) ? '1' : '0',
2322 (capability & BIT(0xa)) ? '1' : '0',
2323 (capability & BIT(0x9)) ? '1' : '0',
2324 (capability & BIT(0x8)) ? '1' : '0',
2325 (capability & BIT(0x7)) ? '1' : '0',
2326 (capability & BIT(0x6)) ? '1' : '0',
2327 (capability & BIT(0x5)) ? '1' : '0',
2328 (capability & BIT(0x4)) ? '1' : '0',
2329 (capability & BIT(0x3)) ? '1' : '0',
2330 (capability & BIT(0x2)) ? '1' : '0',
2331 (capability & BIT(0x1)) ? '1' : '0',
2332 (capability & BIT(0x0)) ? '1' : '0');
2334 if (ieee80211_network_init(ieee, beacon, network, stats)) {
2335 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
2336 escape_essid(info_element->data,
2338 beacon->header.addr3,
2339 fc == IEEE80211_STYPE_PROBE_RESP ?
2340 "PROBE RESPONSE" : "BEACON");
2344 // For Asus EeePc request,
2345 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2346 // wireless adapter should follow the country code.
2347 // (2) If there is no any country code in beacon,
2348 // then wireless adapter should do active scan from ch1~11 and
2349 // passive scan from ch12~14
2351 if (!is_legal_channel(ieee, network->channel))
2353 if (ieee->bGlobalDomain) {
2354 if (fc == IEEE80211_STYPE_PROBE_RESP) {
2355 if (IS_COUNTRY_IE_VALID(ieee)) {
2356 // Case 1: Country code
2357 if (!is_legal_channel(ieee, network->channel)) {
2358 netdev_warn(ieee->dev, "GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network->channel);
2362 // Case 2: No any country code.
2363 // Filter over channel ch12~14
2364 if (network->channel > 11) {
2365 netdev_warn(ieee->dev, "GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network->channel);
2370 if (IS_COUNTRY_IE_VALID(ieee)) {
2371 // Case 1: Country code
2372 if (!is_legal_channel(ieee, network->channel)) {
2373 netdev_warn(ieee->dev, "GetScanInfo(): For Country code, filter beacon at channel(%d).\n", network->channel);
2377 // Case 2: No any country code.
2378 // Filter over channel ch12~14
2379 if (network->channel > 14) {
2380 netdev_warn(ieee->dev, "GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n", network->channel);
2387 /* The network parsed correctly -- so now we scan our known networks
2388 * to see if we can find it in our list.
2390 * NOTE: This search is definitely not optimized. Once its doing
2391 * the "right thing" we'll optimize it for efficiency if
2394 /* Search for this entry in the list and update it if it is
2397 spin_lock_irqsave(&ieee->lock, flags);
2399 if (is_same_network(&ieee->current_network, network, ieee)) {
2400 update_network(&ieee->current_network, network);
2401 if ((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2402 && ieee->current_network.berp_info_valid){
2403 if (ieee->current_network.erp_value & ERP_UseProtection)
2404 ieee->current_network.buseprotection = true;
2406 ieee->current_network.buseprotection = false;
2408 if (is_beacon(beacon->header.frame_ctl)) {
2409 if (ieee->state == IEEE80211_LINKED)
2410 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2412 network->flags = (~NETWORK_EMPTY_ESSID & network->flags) | (NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2415 list_for_each_entry(target, &ieee->network_list, list) {
2416 if (is_same_network(target, network, ieee))
2419 (target->last_scanned < oldest->last_scanned))
2423 /* If we didn't find a match, then get a new network slot to initialize
2424 * with this beacon's information */
2425 if (&target->list == &ieee->network_list) {
2426 if (list_empty(&ieee->network_free_list)) {
2427 /* If there are no more slots, expire the oldest */
2428 list_del(&oldest->list);
2430 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
2432 escape_essid(target->ssid,
2436 /* Otherwise just pull from the free list */
2437 target = list_entry(ieee->network_free_list.next,
2438 struct ieee80211_network, list);
2439 list_del(ieee->network_free_list.next);
2443 #ifdef CONFIG_IEEE80211_DEBUG
2444 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
2445 escape_essid(network->ssid,
2448 fc == IEEE80211_STYPE_PROBE_RESP ?
2449 "PROBE RESPONSE" : "BEACON");
2451 memcpy(target, network, sizeof(*target));
2452 list_add_tail(&target->list, &ieee->network_list);
2453 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2454 ieee80211_softmac_new_net(ieee, network);
2456 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2457 escape_essid(target->ssid,
2460 fc == IEEE80211_STYPE_PROBE_RESP ?
2461 "PROBE RESPONSE" : "BEACON");
2463 /* we have an entry and we are going to update it. But this entry may
2464 * be already expired. In this case we do the same as we found a new
2465 * net and call the new_net handler
2467 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2468 //YJ,add,080819,for hidden ap
2469 if (is_beacon(beacon->header.frame_ctl) == 0)
2470 network->flags = (~NETWORK_EMPTY_ESSID & network->flags) | (NETWORK_EMPTY_ESSID & target->flags);
2471 //if(strncmp(network->ssid, "linksys-c",9) == 0)
2472 // printk("====>2 network->ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network->ssid, network->flags, target->ssid, target->flags);
2473 if (((network->flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2474 && (((network->ssid_len > 0) && (strncmp(target->ssid, network->ssid, network->ssid_len)))\
2475 || ((ieee->current_network.ssid_len == network->ssid_len) && (strncmp(ieee->current_network.ssid, network->ssid, network->ssid_len) == 0) && (ieee->state == IEEE80211_NOLINK))))
2477 //YJ,add,080819,for hidden ap,end
2479 update_network(target, network);
2480 if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2481 ieee80211_softmac_new_net(ieee, network);
2484 spin_unlock_irqrestore(&ieee->lock, flags);
2485 if (is_beacon(beacon->header.frame_ctl) && is_same_network(&ieee->current_network, network, ieee) && \
2486 (ieee->state == IEEE80211_LINKED)) {
2487 if (ieee->handle_beacon)
2488 ieee->handle_beacon(ieee->dev, beacon, &ieee->current_network);
2495 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2496 struct rtl_80211_hdr_4addr *header,
2497 struct ieee80211_rx_stats *stats)
2499 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
2501 case IEEE80211_STYPE_BEACON:
2502 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
2503 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2504 IEEE80211_DEBUG_SCAN("Beacon\n");
2505 ieee80211_process_probe_response(
2506 ieee, (struct ieee80211_probe_response *)header, stats);
2509 case IEEE80211_STYPE_PROBE_RESP:
2510 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
2511 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
2512 IEEE80211_DEBUG_SCAN("Probe response\n");
2513 ieee80211_process_probe_response(
2514 ieee, (struct ieee80211_probe_response *)header, stats);
2519 EXPORT_SYMBOL(ieee80211_rx_mgt);