blob: b522b57a26916ad1d7e96c334f42bb087fcddded [file] [log] [blame]
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001/*
2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <jkmaline@cc.hut.fi>
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
13 * more details.
14 ******************************************************************************
15
16 Few modifications for Realtek's Wi-Fi drivers by
Andrea Merello559a4c32013-08-26 13:53:30 +020017 Andrea Merello <andrea.merello@gmail.com>
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080018
19 A special thanks goes to Realtek for their support !
20
21******************************************************************************/
22
23
24#include <linux/compiler.h>
25//#include <linux/config.h>
26#include <linux/errno.h>
27#include <linux/if_arp.h>
28#include <linux/in6.h>
29#include <linux/in.h>
30#include <linux/ip.h>
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/netdevice.h>
34#include <linux/pci.h>
35#include <linux/proc_fs.h>
36#include <linux/skbuff.h>
37#include <linux/slab.h>
38#include <linux/tcp.h>
39#include <linux/types.h>
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080040#include <linux/wireless.h>
41#include <linux/etherdevice.h>
YAMANE Toshiakid6610cf2012-11-28 22:15:50 +090042#include <linux/uaccess.h>
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080043#include <linux/ctype.h>
44
45#include "ieee80211.h"
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080046#include "dot11d.h"
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080047static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
48 struct sk_buff *skb,
49 struct ieee80211_rx_stats *rx_stats)
50{
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +020051 struct ieee80211_hdr_4addr *hdr =
52 (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080053 u16 fc = le16_to_cpu(hdr->frame_ctl);
54
55 skb->dev = ieee->dev;
Bartlomiej Zolnierkiewicz03704532009-06-13 18:30:28 +020056 skb_reset_mac_header(skb);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080057 skb_pull(skb, ieee80211_get_hdrlen(fc));
58 skb->pkt_type = PACKET_OTHERHOST;
59 skb->protocol = __constant_htons(ETH_P_80211_RAW);
60 memset(skb->cb, 0, sizeof(skb->cb));
61 netif_rx(skb);
62}
63
64
65/* Called only as a tasklet (software IRQ) */
66static struct ieee80211_frag_entry *
67ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +090068 unsigned int frag, u8 tid, u8 *src, u8 *dst)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080069{
70 struct ieee80211_frag_entry *entry;
71 int i;
72
73 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
74 entry = &ieee->frag_cache[tid][i];
75 if (entry->skb != NULL &&
76 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
77 IEEE80211_DEBUG_FRAG(
78 "expiring fragment cache entry "
79 "seq=%u last_frag=%u\n",
80 entry->seq, entry->last_frag);
81 dev_kfree_skb_any(entry->skb);
82 entry->skb = NULL;
83 }
84
85 if (entry->skb != NULL && entry->seq == seq &&
86 (entry->last_frag + 1 == frag || frag == -1) &&
87 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
88 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
89 return entry;
90 }
91
92 return NULL;
93}
94
95/* Called only as a tasklet (software IRQ) */
96static struct sk_buff *
97ieee80211_frag_cache_get(struct ieee80211_device *ieee,
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +020098 struct ieee80211_hdr_4addr *hdr)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -080099{
100 struct sk_buff *skb = NULL;
101 u16 fc = le16_to_cpu(hdr->frame_ctl);
102 u16 sc = le16_to_cpu(hdr->seq_ctl);
103 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
104 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
105 struct ieee80211_frag_entry *entry;
Bartlomiej Zolnierkiewicz726f11e2009-07-13 20:01:51 +0200106 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
Bartlomiej Zolnierkiewicz0ddd6f62009-07-13 20:01:57 +0200107 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800108 u8 tid;
109
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900110 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900111 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
112 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QOS_TID;
113 tid = UP2AC(tid);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900114 tid++;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800115 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900116 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
117 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QOS_TID;
118 tid = UP2AC(tid);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900119 tid++;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800120 } else {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900121 tid = 0;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800122 }
123
124 if (frag == 0) {
125 /* Reserve enough space to fit maximum frame length */
126 skb = dev_alloc_skb(ieee->dev->mtu +
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200127 sizeof(struct ieee80211_hdr_4addr) +
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800128 8 /* LLC */ +
129 2 /* alignment */ +
130 8 /* WEP */ +
131 ETH_ALEN /* WDS */ +
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900132 (IEEE80211_QOS_HAS_SEQ(fc) ? 2 : 0) /* QOS Control */);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800133 if (skb == NULL)
134 return NULL;
135
136 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
137 ieee->frag_next_idx[tid]++;
138 if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
139 ieee->frag_next_idx[tid] = 0;
140
141 if (entry->skb != NULL)
142 dev_kfree_skb_any(entry->skb);
143
144 entry->first_frag_time = jiffies;
145 entry->seq = seq;
146 entry->last_frag = frag;
147 entry->skb = skb;
148 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
149 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
150 } else {
151 /* received a fragment of a frame for which the head fragment
152 * should have already been received */
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900153 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid, hdr->addr2,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800154 hdr->addr1);
155 if (entry != NULL) {
156 entry->last_frag = frag;
157 skb = entry->skb;
158 }
159 }
160
161 return skb;
162}
163
164
165/* Called only as a tasklet (software IRQ) */
166static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200167 struct ieee80211_hdr_4addr *hdr)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800168{
169 u16 fc = le16_to_cpu(hdr->frame_ctl);
170 u16 sc = le16_to_cpu(hdr->seq_ctl);
171 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
172 struct ieee80211_frag_entry *entry;
Bartlomiej Zolnierkiewicz726f11e2009-07-13 20:01:51 +0200173 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
Bartlomiej Zolnierkiewicz0ddd6f62009-07-13 20:01:57 +0200174 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800175 u8 tid;
176
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900177 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900178 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr;
179 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QOS_TID;
180 tid = UP2AC(tid);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900181 tid++;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800182 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900183 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr;
184 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QOS_TID;
185 tid = UP2AC(tid);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900186 tid++;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800187 } else {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900188 tid = 0;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800189 }
190
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900191 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid, hdr->addr2,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800192 hdr->addr1);
193
194 if (entry == NULL) {
195 IEEE80211_DEBUG_FRAG(
196 "could not invalidate fragment cache "
197 "entry (seq=%u)\n", seq);
198 return -1;
199 }
200
201 entry->skb = NULL;
202 return 0;
203}
204
205
206
207/* ieee80211_rx_frame_mgtmt
208 *
209 * Responsible for handling management control frames
210 *
211 * Called by ieee80211_rx */
212static inline int
213ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
214 struct ieee80211_rx_stats *rx_stats, u16 type,
215 u16 stype)
216{
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200217 struct ieee80211_hdr_4addr *hdr;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800218
219 // cheat the the hdr type
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200220 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800221
222 /* On the struct stats definition there is written that
223 * this is not mandatory.... but seems that the probe
224 * response parser uses it
225 */
226 rx_stats->len = skb->len;
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200227 ieee80211_rx_mgt(ieee, (struct ieee80211_hdr_4addr *)skb->data,
228 rx_stats);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800229
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900230 if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800231 dev_kfree_skb_any(skb);
232 return 0;
233 }
234
235 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
236
237 dev_kfree_skb_any(skb);
238
239 return 0;
240
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800241}
242
243
244
245/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
246/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900247static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800248/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900249static unsigned char bridge_tunnel_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800250/* No encapsulation header if EtherType < 0x600 (=length) */
251
252/* Called by ieee80211_rx_frame_decrypt */
253static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
254 struct sk_buff *skb, size_t hdrlen)
255{
256 struct net_device *dev = ieee->dev;
257 u16 fc, ethertype;
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200258 struct ieee80211_hdr_4addr *hdr;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800259 u8 *pos;
260
261 if (skb->len < 24)
262 return 0;
263
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200264 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800265 fc = le16_to_cpu(hdr->frame_ctl);
266
267 /* check that the frame is unicast frame to us */
268 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
269 IEEE80211_FCTL_TODS &&
270 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
271 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
272 /* ToDS frame with own addr BSSID and DA */
273 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
274 IEEE80211_FCTL_FROMDS &&
275 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
276 /* FromDS frame with own addr as DA */
277 } else
278 return 0;
279
280 if (skb->len < 24 + 8)
281 return 0;
282
283 /* check for port access entity Ethernet type */
284// pos = skb->data + 24;
285 pos = skb->data + hdrlen;
286 ethertype = (pos[6] << 8) | pos[7];
287 if (ethertype == ETH_P_PAE)
288 return 1;
289
290 return 0;
291}
292
293/* Called only as a tasklet (software IRQ), by ieee80211_rx */
294static inline int
YAMANE Toshiaki9e2c0a62012-11-28 22:20:27 +0900295ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800296 struct ieee80211_crypt_data *crypt)
297{
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200298 struct ieee80211_hdr_4addr *hdr;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800299 int res, hdrlen;
300
301 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
302 return 0;
303
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200304 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800305 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
306
307#ifdef CONFIG_IEEE80211_CRYPT_TKIP
308 if (ieee->tkip_countermeasures &&
309 strcmp(crypt->ops->name, "TKIP") == 0) {
310 if (net_ratelimit()) {
YAMANE Toshiaki73b612b2012-11-28 22:20:40 +0900311 netdev_dbg(ieee->dev,
312 "TKIP countermeasures: dropped received packet from %pM\n",
313 ieee->dev->name, hdr->addr2);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800314 }
315 return -1;
316 }
317#endif
318
319 atomic_inc(&crypt->refcnt);
320 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
321 atomic_dec(&crypt->refcnt);
322 if (res < 0) {
323 IEEE80211_DEBUG_DROP(
Joe Perches0ee9f672009-12-06 11:34:52 -0800324 "decryption failed (SA=%pM"
325 ") res=%d\n", hdr->addr2, res);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800326 if (res == -2)
327 IEEE80211_DEBUG_DROP("Decryption failed ICV "
328 "mismatch (key %d)\n",
329 skb->data[hdrlen + 3] >> 6);
330 ieee->ieee_stats.rx_discards_undecryptable++;
331 return -1;
332 }
333
334 return res;
335}
336
337
338/* Called only as a tasklet (software IRQ), by ieee80211_rx */
339static inline int
Ana Rey5cfa1b22013-11-12 15:22:50 +0100340ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
341 struct sk_buff *skb, int keyidx,
342 struct ieee80211_crypt_data *crypt)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800343{
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200344 struct ieee80211_hdr_4addr *hdr;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800345 int res, hdrlen;
346
347 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
348 return 0;
349
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200350 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800351 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
352
353 atomic_inc(&crypt->refcnt);
354 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
355 atomic_dec(&crypt->refcnt);
356 if (res < 0) {
YAMANE Toshiaki73b612b2012-11-28 22:20:40 +0900357 netdev_dbg(ieee->dev,
358 "MSDU decryption/MIC verification failed (SA=%pM keyidx=%d)\n",
359 hdr->addr2, keyidx);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800360 return -1;
361 }
362
363 return 0;
364}
365
366
367/* this function is stolen from ipw2200 driver*/
368#define IEEE_PACKET_RETRY_TIME (5*HZ)
369static int is_duplicate_packet(struct ieee80211_device *ieee,
Ana Rey5cfa1b22013-11-12 15:22:50 +0100370 struct ieee80211_hdr_4addr *header)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800371{
372 u16 fc = le16_to_cpu(header->frame_ctl);
373 u16 sc = le16_to_cpu(header->seq_ctl);
374 u16 seq = WLAN_GET_SEQ_SEQ(sc);
375 u16 frag = WLAN_GET_SEQ_FRAG(sc);
376 u16 *last_seq, *last_frag;
377 unsigned long *last_time;
Bartlomiej Zolnierkiewicz726f11e2009-07-13 20:01:51 +0200378 struct ieee80211_hdr_3addrqos *hdr_3addrqos;
Bartlomiej Zolnierkiewicz0ddd6f62009-07-13 20:01:57 +0200379 struct ieee80211_hdr_4addrqos *hdr_4addrqos;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800380 u8 tid;
381
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800382 //TO2DS and QoS
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900383 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900384 hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header;
385 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QOS_TID;
386 tid = UP2AC(tid);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900387 tid++;
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900388 } else if (IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900389 hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)header;
390 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QOS_TID;
391 tid = UP2AC(tid);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900392 tid++;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800393 } else { // no QoS
YAMANE Toshiakida3d0792012-11-28 22:19:05 +0900394 tid = 0;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800395 }
396 switch (ieee->iw_mode) {
397 case IW_MODE_ADHOC:
398 {
399 struct list_head *p;
400 struct ieee_ibss_seq *entry = NULL;
401 u8 *mac = header->addr2;
402 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
Dave Jonescbe97c42013-06-17 22:26:46 -0400403
404 list_for_each(p, &ieee->ibss_mac_hash[index]) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800405 entry = list_entry(p, struct ieee_ibss_seq, list);
406 if (!memcmp(entry->mac, mac, ETH_ALEN))
407 break;
408 }
409 // if (memcmp(entry->mac, mac, ETH_ALEN)){
410 if (p == &ieee->ibss_mac_hash[index]) {
411 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
Joe Perches78110bb2013-02-11 09:41:29 -0800412 if (!entry)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800413 return 0;
Joe Perches78110bb2013-02-11 09:41:29 -0800414
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800415 memcpy(entry->mac, mac, ETH_ALEN);
416 entry->seq_num[tid] = seq;
417 entry->frag_num[tid] = frag;
418 entry->packet_time[tid] = jiffies;
419 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
420 return 0;
421 }
422 last_seq = &entry->seq_num[tid];
423 last_frag = &entry->frag_num[tid];
424 last_time = &entry->packet_time[tid];
425 break;
426 }
427
428 case IW_MODE_INFRA:
429 last_seq = &ieee->last_rxseq_num[tid];
430 last_frag = &ieee->last_rxfrag_num[tid];
431 last_time = &ieee->last_packet_time[tid];
432
433 break;
434 default:
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800435 return 0;
436 }
437
438// if(tid != 0) {
439// printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl);
440// }
441 if ((*last_seq == seq) &&
442 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900443 if (*last_frag == frag) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800444 //printk(KERN_WARNING "[1] go drop!\n");
445 goto drop;
446
447 }
448 if (*last_frag + 1 != frag)
449 /* out-of-order fragment */
450 //printk(KERN_WARNING "[2] go drop!\n");
451 goto drop;
452 } else
453 *last_seq = seq;
454
455 *last_frag = frag;
456 *last_time = jiffies;
457 return 0;
458
459drop:
460// BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
461// printk("DUP\n");
462
463 return 1;
464}
465
466
467/* All received frames are sent to this function. @skb contains the frame in
468 * IEEE 802.11 format, i.e., in the format it was sent over air.
469 * This function is called only as a tasklet (software IRQ). */
George Kadianakisdf574b82009-12-17 01:16:00 +0200470int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
Ana Rey5cfa1b22013-11-12 15:22:50 +0100471 struct ieee80211_rx_stats *rx_stats)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800472{
473 struct net_device *dev = ieee->dev;
474 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200475 struct ieee80211_hdr_4addr *hdr;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800476
477 size_t hdrlen;
478 u16 fc, type, stype, sc;
479 struct net_device_stats *stats;
480 unsigned int frag;
481 u8 *payload;
482 u16 ethertype;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800483 u8 dst[ETH_ALEN];
484 u8 src[ETH_ALEN];
485 u8 bssid[ETH_ALEN];
486 struct ieee80211_crypt_data *crypt = NULL;
487 int keyidx = 0;
488
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800489 // cheat the the hdr type
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200490 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800491 stats = &ieee->stats;
492
493 if (skb->len < 10) {
YAMANE Toshiaki73b612b2012-11-28 22:20:40 +0900494 netdev_info(ieee->dev, "SKB length < 10\n");
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800495 goto rx_dropped;
496 }
497
498 fc = le16_to_cpu(hdr->frame_ctl);
499 type = WLAN_FC_GET_TYPE(fc);
500 stype = WLAN_FC_GET_STYPE(fc);
501 sc = le16_to_cpu(hdr->seq_ctl);
502
503 frag = WLAN_GET_SEQ_FRAG(sc);
504
505//YJ,add,080828,for keep alive
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900506 if ((fc & IEEE80211_FCTL_TODS) != IEEE80211_FCTL_TODS) {
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900507 if (!memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN))
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800508 ieee->NumRxUnicast++;
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900509 } else {
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900510 if (!memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN))
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800511 ieee->NumRxUnicast++;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800512 }
513//YJ,add,080828,for keep alive,end
514
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800515 hdrlen = ieee80211_get_hdrlen(fc);
516
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800517
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800518 if (ieee->iw_mode == IW_MODE_MONITOR) {
519 ieee80211_monitor_rx(ieee, skb, rx_stats);
520 stats->rx_packets++;
521 stats->rx_bytes += skb->len;
522 return 1;
523 }
Bartlomiej Zolnierkiewicz8efff172009-06-13 18:31:18 +0200524
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800525 if (ieee->host_decrypt) {
526 int idx = 0;
527 if (skb->len >= hdrlen + 3)
528 idx = skb->data[hdrlen + 3] >> 6;
529 crypt = ieee->crypt[idx];
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800530
531 /* allow NULL decrypt to indicate an station specific override
532 * for default encryption */
533 if (crypt && (crypt->ops == NULL ||
534 crypt->ops->decrypt_mpdu == NULL))
535 crypt = NULL;
536
537 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
538 /* This seems to be triggered by some (multicast?)
539 * frames from other than current BSS, so just drop the
540 * frames silently instead of filling system log with
541 * these reports. */
542 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
Joe Perches0ee9f672009-12-06 11:34:52 -0800543 " (SA=%pM)\n",
544 hdr->addr2);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800545 ieee->ieee_stats.rx_discards_undecryptable++;
546 goto rx_dropped;
547 }
548 }
549
550 if (skb->len < IEEE80211_DATA_HDR3_LEN)
551 goto rx_dropped;
552
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800553 // if QoS enabled, should check the sequence for each of the AC
554 if (is_duplicate_packet(ieee, hdr))
555 goto rx_dropped;
556
557
558 if (type == IEEE80211_FTYPE_MGMT) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800559 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
560 goto rx_dropped;
561 else
562 goto rx_exit;
563 }
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800564
565 /* Data frame - extract src/dst addresses */
566 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
567 case IEEE80211_FCTL_FROMDS:
568 memcpy(dst, hdr->addr1, ETH_ALEN);
569 memcpy(src, hdr->addr3, ETH_ALEN);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900570 memcpy(bssid, hdr->addr2, ETH_ALEN);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800571 break;
572 case IEEE80211_FCTL_TODS:
573 memcpy(dst, hdr->addr3, ETH_ALEN);
574 memcpy(src, hdr->addr2, ETH_ALEN);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900575 memcpy(bssid, hdr->addr1, ETH_ALEN);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800576 break;
577 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
578 if (skb->len < IEEE80211_DATA_HDR4_LEN)
579 goto rx_dropped;
580 memcpy(dst, hdr->addr3, ETH_ALEN);
581 memcpy(src, hdr->addr4, ETH_ALEN);
582 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
583 break;
584 case 0:
585 memcpy(dst, hdr->addr1, ETH_ALEN);
586 memcpy(src, hdr->addr2, ETH_ALEN);
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900587 memcpy(bssid, hdr->addr3, ETH_ALEN);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800588 break;
589 }
590
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800591
592 dev->last_rx = jiffies;
593
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800594
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800595 /* Nullfunc frames may have PS-bit set, so they must be passed to
596 * hostap_handle_sta_rx() before being dropped here. */
597 if (stype != IEEE80211_STYPE_DATA &&
598 stype != IEEE80211_STYPE_DATA_CFACK &&
599 stype != IEEE80211_STYPE_DATA_CFPOLL &&
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900600 stype != IEEE80211_STYPE_DATA_CFACKPOLL &&
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800601 stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
602 ) {
603 if (stype != IEEE80211_STYPE_NULLFUNC)
604 IEEE80211_DEBUG_DROP(
605 "RX: dropped data frame "
606 "with no data (type=0x%02x, "
607 "subtype=0x%02x, len=%d)\n",
608 type, stype, skb->len);
609 goto rx_dropped;
610 }
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900611 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800612 goto rx_dropped;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800613
614 ieee->NumRxDataInPeriod++;
615 ieee->NumRxOkTotal++;
616 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
617
618 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
619 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
620 goto rx_dropped;
621
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200622 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800623
624 /* skb: hdr + (possibly fragmented) plaintext payload */
625 // PR: FIXME: hostap has additional conditions in the "if" below:
626 // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
627 if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
628 int flen;
629 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
630 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
631
632 if (!frag_skb) {
633 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
634 "Rx cannot get skb from fragment "
635 "cache (morefrag=%d seq=%u frag=%u)\n",
636 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
637 WLAN_GET_SEQ_SEQ(sc), frag);
638 goto rx_dropped;
639 }
640 flen = skb->len;
641 if (frag != 0)
642 flen -= hdrlen;
643
644 if (frag_skb->tail + flen > frag_skb->end) {
YAMANE Toshiaki73b612b2012-11-28 22:20:40 +0900645 netdev_warn(ieee->dev,
646 "host decrypted and reassembled frame did not fit skb\n");
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800647 ieee80211_frag_cache_invalidate(ieee, hdr);
648 goto rx_dropped;
649 }
650
651 if (frag == 0) {
652 /* copy first fragment (including full headers) into
653 * beginning of the fragment cache skb */
654 memcpy(skb_put(frag_skb, flen), skb->data, flen);
655 } else {
656 /* append frame payload to the end of the fragment
657 * cache skb */
658 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
659 flen);
660 }
661 dev_kfree_skb_any(skb);
662 skb = NULL;
663
664 if (fc & IEEE80211_FCTL_MOREFRAGS) {
665 /* more fragments expected - leave the skb in fragment
666 * cache for now; it will be delivered to upper layers
667 * after all fragments have been received */
668 goto rx_exit;
669 }
670
671 /* this was the last fragment and the frame will be
672 * delivered, so remove skb from fragment cache */
673 skb = frag_skb;
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200674 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800675 ieee80211_frag_cache_invalidate(ieee, hdr);
676 }
677
678 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
679 * encrypted/authenticated */
680 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
681 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
682 goto rx_dropped;
683
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +0200684 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800685 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
686 if (/*ieee->ieee802_1x &&*/
687 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
688
689#ifdef CONFIG_IEEE80211_DEBUG
690 /* pass unencrypted EAPOL frames even if encryption is
691 * configured */
692 struct eapol *eap = (struct eapol *)(skb->data +
693 24);
694 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
695 eap_get_type(eap->type));
696#endif
697 } else {
698 IEEE80211_DEBUG_DROP(
699 "encryption configured, but RX "
Joe Perches0ee9f672009-12-06 11:34:52 -0800700 "frame not encrypted (SA=%pM)\n",
701 hdr->addr2);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800702 goto rx_dropped;
703 }
704 }
705
706#ifdef CONFIG_IEEE80211_DEBUG
707 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
708 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
709 struct eapol *eap = (struct eapol *)(skb->data +
710 24);
711 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
712 eap_get_type(eap->type));
713 }
714#endif
715
716 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
717 !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
718 IEEE80211_DEBUG_DROP(
719 "dropped unencrypted RX data "
Joe Perches0ee9f672009-12-06 11:34:52 -0800720 "frame from %pM"
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800721 " (drop_unencrypted=1)\n",
Joe Perches0ee9f672009-12-06 11:34:52 -0800722 hdr->addr2);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800723 goto rx_dropped;
724 }
725/*
726 if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
727 printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n");
728 }
729*/
730 /* skb: hdr + (possible reassembled) full plaintext payload */
731 payload = skb->data + hdrlen;
732 ethertype = (payload[6] << 8) | payload[7];
733
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800734
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800735 /* convert hdr + possible LLC headers into Ethernet header */
736 if (skb->len - hdrlen >= 8 &&
737 ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
738 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
739 memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
740 /* remove RFC1042 or Bridge-Tunnel encapsulation and
741 * replace EtherType */
742 skb_pull(skb, hdrlen + SNAP_SIZE);
743 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
744 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
745 } else {
746 u16 len;
747 /* Leave Ethernet header part of hdr and full payload */
748 skb_pull(skb, hdrlen);
749 len = htons(skb->len);
750 memcpy(skb_push(skb, 2), &len, 2);
751 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
752 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
753 }
754
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800755
756 stats->rx_packets++;
757 stats->rx_bytes += skb->len;
758
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800759 if (skb) {
760 skb->protocol = eth_type_trans(skb, dev);
761 memset(skb->cb, 0, sizeof(skb->cb));
762 skb->dev = dev;
763 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
764 ieee->last_rx_ps_time = jiffies;
765 netif_rx(skb);
766 }
767
768 rx_exit:
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800769 return 1;
770
771 rx_dropped:
772 stats->rx_dropped++;
773
774 /* Returning 0 indicates to caller that we have not handled the SKB--
775 * so it is still allocated and can be used again by underlying
776 * hardware as a DMA target */
777 return 0;
778}
779
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800780#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
781
782static inline int ieee80211_is_ofdm_rate(u8 rate)
783{
784 switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
785 case IEEE80211_OFDM_RATE_6MB:
786 case IEEE80211_OFDM_RATE_9MB:
787 case IEEE80211_OFDM_RATE_12MB:
788 case IEEE80211_OFDM_RATE_18MB:
789 case IEEE80211_OFDM_RATE_24MB:
790 case IEEE80211_OFDM_RATE_36MB:
791 case IEEE80211_OFDM_RATE_48MB:
792 case IEEE80211_OFDM_RATE_54MB:
793 return 1;
794 }
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +0900795 return 0;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800796}
797
Ana Rey5cfa1b22013-11-12 15:22:50 +0100798static inline int ieee80211_SignalStrengthTranslate(int CurrSS)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800799{
800 int RetSS;
801
802 // Step 1. Scale mapping.
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900803 if (CurrSS >= 71 && CurrSS <= 100)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800804 RetSS = 90 + ((CurrSS - 70) / 3);
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900805 else if (CurrSS >= 41 && CurrSS <= 70)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800806 RetSS = 78 + ((CurrSS - 40) / 3);
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900807 else if (CurrSS >= 31 && CurrSS <= 40)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800808 RetSS = 66 + (CurrSS - 30);
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900809 else if (CurrSS >= 21 && CurrSS <= 30)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800810 RetSS = 54 + (CurrSS - 20);
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900811 else if (CurrSS >= 5 && CurrSS <= 20)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800812 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900813 else if (CurrSS == 4)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800814 RetSS = 36;
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900815 else if (CurrSS == 3)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800816 RetSS = 27;
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900817 else if (CurrSS == 2)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800818 RetSS = 18;
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900819 else if (CurrSS == 1)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800820 RetSS = 9;
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900821 else
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800822 RetSS = CurrSS;
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900823
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800824 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
825
826 // Step 2. Smoothing.
827
828 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
829
830 return RetSS;
831}
832
Ana Rey5cfa1b22013-11-12 15:22:50 +0100833static inline void
834ieee80211_extract_country_ie(struct ieee80211_device *ieee,
835 struct ieee80211_info_element *info_element,
836 struct ieee80211_network *network, u8 *addr2)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800837{
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900838 if (IS_DOT11D_ENABLE(ieee)) {
839 if (info_element->len != 0) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800840 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
841 network->CountryIeLen = info_element->len;
842
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900843 if (!IS_COUNTRY_IE_VALID(ieee))
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800844 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800845 }
846
847 //
848 // 070305, rcnjko: I update country IE watch dog here because
849 // some AP (e.g. Cisco 1242) don't include country IE in their
850 // probe response frame.
851 //
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +0900852 if (IS_EQUAL_CIE_SRC(ieee, addr2))
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800853 UPDATE_CIE_WATCHDOG(ieee);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800854 }
855
856}
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800857
Ana Rey5cfa1b22013-11-12 15:22:50 +0100858/* SignalStrengthIndex is 0-100 */
859static int ieee80211_TranslateToDbm(unsigned char SignalStrengthIndex)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800860{
861 unsigned char SignalPower; // in dBm.
862
863 // Translate to dBm (x=0.5y-95).
864 SignalPower = (int)SignalStrengthIndex * 7 / 10;
865 SignalPower -= 95;
866
867 return SignalPower;
868}
869inline int ieee80211_network_init(
870 struct ieee80211_device *ieee,
871 struct ieee80211_probe_response *beacon,
872 struct ieee80211_network *network,
873 struct ieee80211_rx_stats *stats)
874{
875#ifdef CONFIG_IEEE80211_DEBUG
876 char rates_str[64];
877 char *p;
878#endif
879 struct ieee80211_info_element *info_element;
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +0900880 u16 left;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800881 u8 i;
882 short offset;
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +0900883 u8 curRate = 0, hOpRate = 0, curRate_ex = 0;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800884
885 /* Pull out fixed field data */
886 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
887 network->capability = beacon->capability;
888 network->last_scanned = jiffies;
889 network->time_stamp[0] = beacon->time_stamp[0];
890 network->time_stamp[1] = beacon->time_stamp[1];
891 network->beacon_interval = beacon->beacon_interval;
892 /* Where to pull this? beacon->listen_interval;*/
893 network->listen_interval = 0x0A;
894 network->rates_len = network->rates_ex_len = 0;
895 network->last_associate = 0;
896 network->ssid_len = 0;
897 network->flags = 0;
898 network->atim_window = 0;
899 network->QoS_Enable = 0;
900//by amy 080312
901 network->HighestOperaRate = 0;
902//by amy 080312
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800903 network->Turbo_Enable = 0;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800904 network->CountryIeLen = 0;
905 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800906
907 if (stats->freq == IEEE80211_52GHZ_BAND) {
908 /* for A band (No DS info) */
909 network->channel = stats->received_channel;
910 } else
911 network->flags |= NETWORK_HAS_CCK;
912
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +0900913 network->wpa_ie_len = 0;
914 network->rsn_ie_len = 0;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800915
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +0900916 info_element = &beacon->info_element;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800917 left = stats->len - ((void *)info_element - (void *)beacon);
918 while (left >= sizeof(struct ieee80211_info_element_hdr)) {
919 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
920 IEEE80211_DEBUG_SCAN("SCAN: parse failed: info_element->len + 2 > left : info_element->len+2=%d left=%d.\n",
921 info_element->len + sizeof(struct ieee80211_info_element),
922 left);
923 return 1;
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +0900924 }
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800925
926 switch (info_element->id) {
927 case MFIE_TYPE_SSID:
928 if (ieee80211_is_empty_essid(info_element->data,
929 info_element->len)) {
930 network->flags |= NETWORK_EMPTY_ESSID;
931 break;
932 }
933
934 network->ssid_len = min(info_element->len,
935 (u8)IW_ESSID_MAX_SIZE);
936 memcpy(network->ssid, info_element->data, network->ssid_len);
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +0900937 if (network->ssid_len < IW_ESSID_MAX_SIZE)
938 memset(network->ssid + network->ssid_len, 0,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800939 IW_ESSID_MAX_SIZE - network->ssid_len);
940
941 IEEE80211_DEBUG_SCAN("MFIE_TYPE_SSID: '%s' len=%d.\n",
942 network->ssid, network->ssid_len);
943 break;
944
945 case MFIE_TYPE_RATES:
946#ifdef CONFIG_IEEE80211_DEBUG
947 p = rates_str;
948#endif
949 network->rates_len = min(info_element->len, MAX_RATES_LENGTH);
950 for (i = 0; i < network->rates_len; i++) {
951 network->rates[i] = info_element->data[i];
952 curRate = network->rates[i] & 0x7f;
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900953 if (hOpRate < curRate)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800954 hOpRate = curRate;
955#ifdef CONFIG_IEEE80211_DEBUG
956 p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
957#endif
958 if (ieee80211_is_ofdm_rate(info_element->data[i])) {
959 network->flags |= NETWORK_HAS_OFDM;
960 if (info_element->data[i] &
961 IEEE80211_BASIC_RATE_MASK)
962 network->flags &=
963 ~NETWORK_HAS_CCK;
964 }
965 }
966
967 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES: '%s' (%d)\n",
968 rates_str, network->rates_len);
969 break;
970
971 case MFIE_TYPE_RATES_EX:
972#ifdef CONFIG_IEEE80211_DEBUG
973 p = rates_str;
974#endif
975 network->rates_ex_len = min(info_element->len, MAX_RATES_EX_LENGTH);
976 for (i = 0; i < network->rates_ex_len; i++) {
977 network->rates_ex[i] = info_element->data[i];
978 curRate_ex = network->rates_ex[i] & 0x7f;
YAMANE Toshiakic6f255332012-11-28 22:20:13 +0900979 if (hOpRate < curRate_ex)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800980 hOpRate = curRate_ex;
981#ifdef CONFIG_IEEE80211_DEBUG
982 p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
983#endif
984 if (ieee80211_is_ofdm_rate(info_element->data[i])) {
985 network->flags |= NETWORK_HAS_OFDM;
986 if (info_element->data[i] &
987 IEEE80211_BASIC_RATE_MASK)
988 network->flags &=
989 ~NETWORK_HAS_CCK;
990 }
991 }
992
993 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
994 rates_str, network->rates_ex_len);
995 break;
996
997 case MFIE_TYPE_DS_SET:
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +0900998 IEEE80211_DEBUG_SCAN("MFIE_TYPE_DS_SET: %d\n",
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -0800999 info_element->data[0]);
1000 if (stats->freq == IEEE80211_24GHZ_BAND)
1001 network->channel = info_element->data[0];
1002 break;
1003
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +09001004 case MFIE_TYPE_FH_SET:
1005 IEEE80211_DEBUG_SCAN("MFIE_TYPE_FH_SET: ignored\n");
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001006 break;
1007
1008 case MFIE_TYPE_CF_SET:
1009 IEEE80211_DEBUG_SCAN("MFIE_TYPE_CF_SET: ignored\n");
1010 break;
1011
1012 case MFIE_TYPE_TIM:
1013
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001014 if (info_element->len < 4)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001015 break;
1016
1017 network->dtim_period = info_element->data[1];
1018
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001019 if (ieee->state != IEEE80211_LINKED)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001020 break;
Bartlomiej Zolnierkiewicz5521a512009-06-28 16:19:23 +02001021
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001022 network->last_dtim_sta_time[0] = jiffies;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001023 network->last_dtim_sta_time[1] = stats->mac_time[1];
1024
1025 network->dtim_data = IEEE80211_DTIM_VALID;
1026
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001027 if (info_element->data[0] != 0)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001028 break;
1029
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001030 if (info_element->data[2] & 1)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001031 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1032
1033 offset = (info_element->data[2] >> 1)*2;
1034
1035 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1036
1037 /* add and modified for ps 2008.1.22 */
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001038 if (ieee->assoc_id < 8*offset ||
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001039 ieee->assoc_id > 8*(offset + info_element->len - 3)) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001040 break;
1041 }
1042
1043 offset = (ieee->assoc_id/8) - offset;// + ((aid % 8)? 0 : 1) ;
1044
1045 // printk("offset:%x data:%x, ucast:%d\n", offset,
1046 // info_element->data[3+offset] ,
1047 // info_element->data[3+offset] & (1<<(ieee->assoc_id%8)));
1048
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +09001049 if (info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001050 network->dtim_data |= IEEE80211_DTIM_UCAST;
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +09001051
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001052 break;
1053
1054 case MFIE_TYPE_IBSS_SET:
1055 IEEE80211_DEBUG_SCAN("MFIE_TYPE_IBSS_SET: ignored\n");
1056 break;
1057
1058 case MFIE_TYPE_CHALLENGE:
1059 IEEE80211_DEBUG_SCAN("MFIE_TYPE_CHALLENGE: ignored\n");
1060 break;
1061
1062 case MFIE_TYPE_GENERIC:
1063 //nic is 87B
1064 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n",
1065 info_element->len);
1066 if (info_element->len >= 4 &&
1067 info_element->data[0] == 0x00 &&
1068 info_element->data[1] == 0x50 &&
1069 info_element->data[2] == 0xf2 &&
1070 info_element->data[3] == 0x01) {
1071 network->wpa_ie_len = min(info_element->len + 2,
1072 MAX_WPA_IE_LEN);
1073 memcpy(network->wpa_ie, info_element,
1074 network->wpa_ie_len);
1075 }
1076
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001077 if (info_element->len == 7 &&
1078 info_element->data[0] == 0x00 &&
1079 info_element->data[1] == 0xe0 &&
1080 info_element->data[2] == 0x4c &&
1081 info_element->data[3] == 0x01 &&
1082 info_element->data[4] == 0x02) {
1083 network->Turbo_Enable = 1;
1084 }
YAMANE Toshiaki0f18f5b2012-11-28 22:20:53 +09001085 if (1 == stats->nic_type) //nic 87
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001086 break;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001087
1088 if (info_element->len >= 5 &&
1089 info_element->data[0] == 0x00 &&
1090 info_element->data[1] == 0x50 &&
1091 info_element->data[2] == 0xf2 &&
1092 info_element->data[3] == 0x02 &&
1093 info_element->data[4] == 0x00) {
1094 //printk(KERN_WARNING "wmm info updated: %x\n", info_element->data[6]);
1095 //WMM Information Element
1096 network->wmm_info = info_element->data[6];
1097 network->QoS_Enable = 1;
1098 }
1099
1100 if (info_element->len >= 8 &&
1101 info_element->data[0] == 0x00 &&
1102 info_element->data[1] == 0x50 &&
1103 info_element->data[2] == 0xf2 &&
1104 info_element->data[3] == 0x02 &&
1105 info_element->data[4] == 0x01) {
1106 // Not care about version at present.
1107 //WMM Information Element
1108 //printk(KERN_WARNING "wmm info&param updated: %x\n", info_element->data[6]);
1109 network->wmm_info = info_element->data[6];
1110 //WMM Parameter Element
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001111 memcpy(network->wmm_param, (u8 *)(info_element->data + 8), (info_element->len - 8));
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001112 network->QoS_Enable = 1;
1113 }
1114 break;
1115
1116 case MFIE_TYPE_RSN:
1117 IEEE80211_DEBUG_SCAN("MFIE_TYPE_RSN: %d bytes\n",
1118 info_element->len);
1119 network->rsn_ie_len = min(info_element->len + 2,
1120 MAX_WPA_IE_LEN);
1121 memcpy(network->rsn_ie, info_element,
1122 network->rsn_ie_len);
1123 break;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001124 case MFIE_TYPE_COUNTRY:
1125 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
1126 info_element->len);
1127// printk("=====>Receive <%s> Country IE\n",network->ssid);
1128 ieee80211_extract_country_ie(ieee, info_element, network, beacon->header.addr2);
1129 break;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001130 default:
1131 IEEE80211_DEBUG_SCAN("unsupported IE %d\n",
1132 info_element->id);
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +09001133 break;
1134 }
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001135
1136 left -= sizeof(struct ieee80211_info_element_hdr) +
1137 info_element->len;
1138 info_element = (struct ieee80211_info_element *)
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +09001139 &info_element->data[info_element->len];
1140 }
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001141//by amy 080312
1142 network->HighestOperaRate = hOpRate;
1143//by amy 080312
1144 network->mode = 0;
1145 if (stats->freq == IEEE80211_52GHZ_BAND)
1146 network->mode = IEEE_A;
1147 else {
1148 if (network->flags & NETWORK_HAS_OFDM)
1149 network->mode |= IEEE_G;
1150 if (network->flags & NETWORK_HAS_CCK)
1151 network->mode |= IEEE_B;
1152 }
1153
1154 if (network->mode == 0) {
Joe Perches0ee9f672009-12-06 11:34:52 -08001155 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001156 "network.\n",
1157 escape_essid(network->ssid,
1158 network->ssid_len),
Joe Perches0ee9f672009-12-06 11:34:52 -08001159 network->bssid);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001160 return 1;
1161 }
1162
1163 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
1164 network->flags |= NETWORK_EMPTY_ESSID;
Bartlomiej Zolnierkiewicz5521a512009-06-28 16:19:23 +02001165
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001166 stats->signal = ieee80211_TranslateToDbm(stats->signalstrength);
1167 //stats->noise = stats->signal - stats->noise;
1168 stats->noise = ieee80211_TranslateToDbm(100 - stats->signalstrength) - 25;
1169 memcpy(&network->stats, stats, sizeof(network->stats));
1170
1171 return 0;
1172}
1173
1174static inline int is_same_network(struct ieee80211_network *src,
1175 struct ieee80211_network *dst,
YAMANE Toshiaki9e2c0a62012-11-28 22:20:27 +09001176 struct ieee80211_device *ieee)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001177{
1178 /* A network is only a duplicate if the channel, BSSID, ESSID
1179 * and the capability field (in particular IBSS and BSS) all match.
1180 * We treat all <hidden> with the same BSSID and channel
1181 * as one network */
1182 return (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && //YJ,mod,080819,for hidden ap
1183 //((src->ssid_len == dst->ssid_len) &&
1184 (src->channel == dst->channel) &&
1185 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
1186 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && //YJ,mod,080819,for hidden ap
1187 //!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
1188 ((src->capability & WLAN_CAPABILITY_IBSS) ==
1189 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
1190 ((src->capability & WLAN_CAPABILITY_BSS) ==
1191 (dst->capability & WLAN_CAPABILITY_BSS)));
1192}
1193
1194inline void update_network(struct ieee80211_network *dst,
Ana Rey5cfa1b22013-11-12 15:22:50 +01001195 struct ieee80211_network *src)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001196{
1197 unsigned char quality = src->stats.signalstrength;
1198 unsigned char signal = 0;
1199 unsigned char noise = 0;
YAMANE Toshiaki7f5d6d92012-11-28 22:21:07 +09001200 if (dst->stats.signalstrength > 0)
1201 quality = (dst->stats.signalstrength * 5 + src->stats.signalstrength + 5)/6;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001202 signal = ieee80211_TranslateToDbm(quality);
1203 //noise = signal - src->stats.noise;
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001204 if (dst->stats.noise > 0)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001205 noise = (dst->stats.noise * 5 + src->stats.noise)/6;
1206 //if(strcmp(dst->ssid, "linksys_lzm000") == 0)
1207// printk("ssid:%s, quality:%d, signal:%d\n", dst->ssid, quality, signal);
1208 memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
1209 dst->stats.signalstrength = quality;
1210 dst->stats.signal = signal;
1211// printk("==================>stats.signal is %d\n",dst->stats.signal);
1212 dst->stats.noise = noise;
1213
1214
1215 dst->capability = src->capability;
1216 memcpy(dst->rates, src->rates, src->rates_len);
1217 dst->rates_len = src->rates_len;
1218 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1219 dst->rates_ex_len = src->rates_ex_len;
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001220 dst->HighestOperaRate = src->HighestOperaRate;
Harvey Harrisond599edc2009-01-07 14:31:57 -08001221 //printk("==========>in %s: src->ssid is %s,chan is %d\n",__func__,src->ssid,src->channel);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001222
1223 //YJ,add,080819,for hidden ap
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001224 if (src->ssid_len > 0) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001225 //if(src->ssid_len == 13)
1226 // printk("=====================>>>>>>>> Dst ssid: %s Src ssid: %s\n", dst->ssid, src->ssid);
1227 memset(dst->ssid, 0, dst->ssid_len);
1228 dst->ssid_len = src->ssid_len;
1229 memcpy(dst->ssid, src->ssid, src->ssid_len);
1230 }
1231 //YJ,add,080819,for hidden ap,end
1232
1233 dst->channel = src->channel;
1234 dst->mode = src->mode;
1235 dst->flags = src->flags;
1236 dst->time_stamp[0] = src->time_stamp[0];
1237 dst->time_stamp[1] = src->time_stamp[1];
1238
1239 dst->beacon_interval = src->beacon_interval;
1240 dst->listen_interval = src->listen_interval;
1241 dst->atim_window = src->atim_window;
1242 dst->dtim_period = src->dtim_period;
1243 dst->dtim_data = src->dtim_data;
1244 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
1245 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
1246// printk("update:%s, dtim_period:%x, dtim_data:%x\n", src->ssid, src->dtim_period, src->dtim_data);
1247 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1248 dst->wpa_ie_len = src->wpa_ie_len;
1249 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1250 dst->rsn_ie_len = src->rsn_ie_len;
1251
1252 dst->last_scanned = jiffies;
1253 /* dst->last_associate is not overwritten */
1254// disable QoS process now, added by David 2006/7/25
1255#if 1
1256 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
1257/*
1258 if((dst->wmm_info^src->wmm_info)&0x0f) {//Param Set Count change, update Parameter
1259 memcpy(dst->wmm_param, src->wmm_param, IEEE80211_AC_PRAM_LEN);
1260 }
1261*/
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001262 if (src->wmm_param[0].ac_aci_acm_aifsn || \
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001263 src->wmm_param[1].ac_aci_acm_aifsn || \
1264 src->wmm_param[2].ac_aci_acm_aifsn || \
Roel Kluin50fdd342009-05-18 17:31:36 +02001265 src->wmm_param[3].ac_aci_acm_aifsn) {
YAMANE Toshiakida3d0792012-11-28 22:19:05 +09001266 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001267 }
1268 dst->QoS_Enable = src->QoS_Enable;
1269#else
1270 dst->QoS_Enable = 1;//for Rtl8187 simulation
1271#endif
1272 dst->SignalStrength = src->SignalStrength;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001273 dst->Turbo_Enable = src->Turbo_Enable;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001274 dst->CountryIeLen = src->CountryIeLen;
1275 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001276}
1277
1278
Ana Rey5cfa1b22013-11-12 15:22:50 +01001279inline void
1280ieee80211_process_probe_response(struct ieee80211_device *ieee,
1281 struct ieee80211_probe_response *beacon,
1282 struct ieee80211_rx_stats *stats)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001283{
1284 struct ieee80211_network network;
1285 struct ieee80211_network *target;
1286 struct ieee80211_network *oldest = NULL;
1287#ifdef CONFIG_IEEE80211_DEBUG
1288 struct ieee80211_info_element *info_element = &beacon->info_element;
1289#endif
1290 unsigned long flags;
1291 short renew;
1292 u8 wmm_info;
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001293 u8 is_beacon = (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_BEACON) ? 1 : 0; //YJ,add,080819,for hidden ap
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001294
1295 memset(&network, 0, sizeof(struct ieee80211_network));
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001296
1297 IEEE80211_DEBUG_SCAN(
Joe Perches0ee9f672009-12-06 11:34:52 -08001298 "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001299 escape_essid(info_element->data, info_element->len),
Joe Perches0ee9f672009-12-06 11:34:52 -08001300 beacon->header.addr3,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001301 (beacon->capability & (1<<0xf)) ? '1' : '0',
1302 (beacon->capability & (1<<0xe)) ? '1' : '0',
1303 (beacon->capability & (1<<0xd)) ? '1' : '0',
1304 (beacon->capability & (1<<0xc)) ? '1' : '0',
1305 (beacon->capability & (1<<0xb)) ? '1' : '0',
1306 (beacon->capability & (1<<0xa)) ? '1' : '0',
1307 (beacon->capability & (1<<0x9)) ? '1' : '0',
1308 (beacon->capability & (1<<0x8)) ? '1' : '0',
1309 (beacon->capability & (1<<0x7)) ? '1' : '0',
1310 (beacon->capability & (1<<0x6)) ? '1' : '0',
1311 (beacon->capability & (1<<0x5)) ? '1' : '0',
1312 (beacon->capability & (1<<0x4)) ? '1' : '0',
1313 (beacon->capability & (1<<0x3)) ? '1' : '0',
1314 (beacon->capability & (1<<0x2)) ? '1' : '0',
1315 (beacon->capability & (1<<0x1)) ? '1' : '0',
1316 (beacon->capability & (1<<0x0)) ? '1' : '0');
Bartlomiej Zolnierkiewicz5521a512009-06-28 16:19:23 +02001317
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001318 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
Joe Perches0ee9f672009-12-06 11:34:52 -08001319 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001320 escape_essid(info_element->data,
1321 info_element->len),
Joe Perches0ee9f672009-12-06 11:34:52 -08001322 beacon->header.addr3,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001323 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1324 IEEE80211_STYPE_PROBE_RESP ?
1325 "PROBE RESPONSE" : "BEACON");
1326 return;
1327 }
1328
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001329 // For Asus EeePc request,
1330 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
1331 // wireless adapter should follow the country code.
1332 // (2) If there is no any country code in beacon,
1333 // then wireless adapter should do active scan from ch1~11 and
1334 // passive scan from ch12~14
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001335 if (ieee->bGlobalDomain) {
1336 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001337 // Case 1: Country code
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001338 if (IS_COUNTRY_IE_VALID(ieee)) {
1339 if (!IsLegalChannel(ieee, network.channel)) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001340 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
1341 return;
1342 }
1343 }
1344 // Case 2: No any country code.
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001345 else {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001346 // Filter over channel ch12~14
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001347 if (network.channel > 11) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001348 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel);
1349 return;
1350 }
1351 }
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001352 } else {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001353 // Case 1: Country code
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001354 if (IS_COUNTRY_IE_VALID(ieee)) {
1355 if (!IsLegalChannel(ieee, network.channel)) {
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001356 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n", network.channel);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001357 return;
1358 }
1359 }
1360 // Case 2: No any country code.
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001361 else {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001362 // Filter over channel ch12~14
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001363 if (network.channel > 14) {
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001364 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n", network.channel);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001365 return;
1366 }
1367 }
1368 }
1369 }
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001370 /* The network parsed correctly -- so now we scan our known networks
1371 * to see if we can find it in our list.
1372 *
1373 * NOTE: This search is definitely not optimized. Once its doing
1374 * the "right thing" we'll optimize it for efficiency if
1375 * necessary */
1376
1377 /* Search for this entry in the list and update it if it is
1378 * already there. */
1379
1380 spin_lock_irqsave(&ieee->lock, flags);
1381
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001382 if (is_same_network(&ieee->current_network, &network, ieee)) {
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001383 wmm_info = ieee->current_network.wmm_info;
1384 //YJ,add,080819,for hidden ap
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001385 if (is_beacon == 0)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001386 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001387 else if (ieee->state == IEEE80211_LINKED)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001388 ieee->NumRxBcnInPeriod++;
1389 //YJ,add,080819,for hidden ap,end
1390 //printk("====>network.ssid=%s cur_ssid=%s\n", network.ssid, ieee->current_network.ssid);
1391 update_network(&ieee->current_network, &network);
1392 }
1393
1394 list_for_each_entry(target, &ieee->network_list, list) {
1395 if (is_same_network(target, &network, ieee))
1396 break;
1397 if ((oldest == NULL) ||
1398 (target->last_scanned < oldest->last_scanned))
1399 oldest = target;
1400 }
1401
1402 /* If we didn't find a match, then get a new network slot to initialize
1403 * with this beacon's information */
1404 if (&target->list == &ieee->network_list) {
1405 if (list_empty(&ieee->network_free_list)) {
1406 /* If there are no more slots, expire the oldest */
1407 list_del(&oldest->list);
1408 target = oldest;
Joe Perches0ee9f672009-12-06 11:34:52 -08001409 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001410 "network list.\n",
1411 escape_essid(target->ssid,
1412 target->ssid_len),
Joe Perches0ee9f672009-12-06 11:34:52 -08001413 target->bssid);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001414 } else {
1415 /* Otherwise just pull from the free list */
1416 target = list_entry(ieee->network_free_list.next,
1417 struct ieee80211_network, list);
1418 list_del(ieee->network_free_list.next);
1419 }
1420
1421
1422#ifdef CONFIG_IEEE80211_DEBUG
Joe Perches0ee9f672009-12-06 11:34:52 -08001423 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001424 escape_essid(network.ssid,
1425 network.ssid_len),
Joe Perches0ee9f672009-12-06 11:34:52 -08001426 network.bssid,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001427 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1428 IEEE80211_STYPE_PROBE_RESP ?
1429 "PROBE RESPONSE" : "BEACON");
1430#endif
1431
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001432 memcpy(target, &network, sizeof(*target));
1433 list_add_tail(&target->list, &ieee->network_list);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001434 } else {
Joe Perches0ee9f672009-12-06 11:34:52 -08001435 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001436 escape_essid(target->ssid,
1437 target->ssid_len),
Joe Perches0ee9f672009-12-06 11:34:52 -08001438 target->bssid,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001439 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1440 IEEE80211_STYPE_PROBE_RESP ?
1441 "PROBE RESPONSE" : "BEACON");
1442
1443 /* we have an entry and we are going to update it. But this entry may
1444 * be already expired. In this case we do the same as we found a new
1445 * net and call the new_net handler
1446 */
1447 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
1448 //YJ,add,080819,for hidden ap
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001449 if (is_beacon == 0)
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001450 network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags);
1451 //if(strncmp(network.ssid, "linksys-c",9) == 0)
1452 // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags);
YAMANE Toshiakic6f255332012-11-28 22:20:13 +09001453 if (((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001454 && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\
YAMANE Toshiaki173d6b92012-11-28 22:19:59 +09001455 || ((ieee->current_network.ssid_len == network.ssid_len) && (strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0) && (ieee->state == IEEE80211_NOLINK))))
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001456 renew = 1;
1457 //YJ,add,080819,for hidden ap,end
1458 update_network(target, &network);
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001459 }
1460
1461 spin_unlock_irqrestore(&ieee->lock, flags);
1462}
1463
1464void ieee80211_rx_mgt(struct ieee80211_device *ieee,
Bartlomiej Zolnierkiewicz06043842009-07-13 20:01:44 +02001465 struct ieee80211_hdr_4addr *header,
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001466 struct ieee80211_rx_stats *stats)
1467{
1468 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
1469
1470 case IEEE80211_STYPE_BEACON:
1471 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
1472 WLAN_FC_GET_STYPE(header->frame_ctl));
1473 IEEE80211_DEBUG_SCAN("Beacon\n");
1474 ieee80211_process_probe_response(
1475 ieee, (struct ieee80211_probe_response *)header, stats);
1476 break;
1477
1478 case IEEE80211_STYPE_PROBE_RESP:
1479 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1480 WLAN_FC_GET_STYPE(header->frame_ctl));
1481 IEEE80211_DEBUG_SCAN("Probe response\n");
1482 ieee80211_process_probe_response(
1483 ieee, (struct ieee80211_probe_response *)header, stats);
1484 break;
Greg Kroah-Hartmanc8d86be2008-12-04 20:01:41 -08001485 }
1486}