Commit | Line | Data |
---|---|---|
8fc8598e JC |
1 | /* |
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 | |
17 | Andrea Merello <andreamrl@tiscali.it> | |
18 | ||
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> | |
40 | #include <linux/version.h> | |
41 | #include <linux/wireless.h> | |
42 | #include <linux/etherdevice.h> | |
43 | #include <asm/uaccess.h> | |
44 | #include <linux/ctype.h> | |
45 | ||
46 | #include "ieee80211.h" | |
8fc8598e | 47 | #include "dot11d.h" |
8fc8598e JC |
48 | static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee, |
49 | struct sk_buff *skb, | |
50 | struct ieee80211_rx_stats *rx_stats) | |
51 | { | |
52 | struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *)skb->data; | |
53 | u16 fc = le16_to_cpu(hdr->frame_ctl); | |
54 | ||
55 | skb->dev = ieee->dev; | |
8fc8598e | 56 | skb_reset_mac_header(skb); |
8fc8598e JC |
57 | |
58 | skb_pull(skb, ieee80211_get_hdrlen(fc)); | |
59 | skb->pkt_type = PACKET_OTHERHOST; | |
60 | skb->protocol = __constant_htons(ETH_P_80211_RAW); | |
61 | memset(skb->cb, 0, sizeof(skb->cb)); | |
62 | netif_rx(skb); | |
63 | } | |
64 | ||
65 | ||
66 | /* Called only as a tasklet (software IRQ) */ | |
67 | static struct ieee80211_frag_entry * | |
68 | ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq, | |
69 | unsigned int frag, u8 tid,u8 *src, u8 *dst) | |
70 | { | |
71 | struct ieee80211_frag_entry *entry; | |
72 | int i; | |
73 | ||
74 | for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) { | |
75 | entry = &ieee->frag_cache[tid][i]; | |
76 | if (entry->skb != NULL && | |
77 | time_after(jiffies, entry->first_frag_time + 2 * HZ)) { | |
78 | IEEE80211_DEBUG_FRAG( | |
79 | "expiring fragment cache entry " | |
80 | "seq=%u last_frag=%u\n", | |
81 | entry->seq, entry->last_frag); | |
82 | dev_kfree_skb_any(entry->skb); | |
83 | entry->skb = NULL; | |
84 | } | |
85 | ||
86 | if (entry->skb != NULL && entry->seq == seq && | |
87 | (entry->last_frag + 1 == frag || frag == -1) && | |
88 | memcmp(entry->src_addr, src, ETH_ALEN) == 0 && | |
89 | memcmp(entry->dst_addr, dst, ETH_ALEN) == 0) | |
90 | return entry; | |
91 | } | |
92 | ||
93 | return NULL; | |
94 | } | |
95 | ||
96 | /* Called only as a tasklet (software IRQ) */ | |
97 | static struct sk_buff * | |
98 | ieee80211_frag_cache_get(struct ieee80211_device *ieee, | |
99 | struct ieee80211_hdr_4addr *hdr) | |
100 | { | |
101 | struct sk_buff *skb = NULL; | |
102 | u16 fc = le16_to_cpu(hdr->frame_ctl); | |
103 | u16 sc = le16_to_cpu(hdr->seq_ctl); | |
104 | unsigned int frag = WLAN_GET_SEQ_FRAG(sc); | |
105 | unsigned int seq = WLAN_GET_SEQ_SEQ(sc); | |
106 | struct ieee80211_frag_entry *entry; | |
107 | struct ieee80211_hdr_3addrqos *hdr_3addrqos; | |
108 | struct ieee80211_hdr_4addrqos *hdr_4addrqos; | |
109 | u8 tid; | |
110 | ||
111 | if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) { | |
112 | hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr; | |
113 | tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; | |
114 | tid = UP2AC(tid); | |
115 | tid ++; | |
116 | } else if (IEEE80211_QOS_HAS_SEQ(fc)) { | |
117 | hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr; | |
118 | tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; | |
119 | tid = UP2AC(tid); | |
120 | tid ++; | |
121 | } else { | |
122 | tid = 0; | |
123 | } | |
124 | ||
125 | if (frag == 0) { | |
126 | /* Reserve enough space to fit maximum frame length */ | |
127 | skb = dev_alloc_skb(ieee->dev->mtu + | |
128 | sizeof(struct ieee80211_hdr_4addr) + | |
129 | 8 /* LLC */ + | |
130 | 2 /* alignment */ + | |
131 | 8 /* WEP */ + | |
132 | ETH_ALEN /* WDS */ + | |
133 | (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */); | |
134 | if (skb == NULL) | |
135 | return NULL; | |
136 | ||
137 | entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]]; | |
138 | ieee->frag_next_idx[tid]++; | |
139 | if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN) | |
140 | ieee->frag_next_idx[tid] = 0; | |
141 | ||
142 | if (entry->skb != NULL) | |
143 | dev_kfree_skb_any(entry->skb); | |
144 | ||
145 | entry->first_frag_time = jiffies; | |
146 | entry->seq = seq; | |
147 | entry->last_frag = frag; | |
148 | entry->skb = skb; | |
149 | memcpy(entry->src_addr, hdr->addr2, ETH_ALEN); | |
150 | memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN); | |
151 | } else { | |
152 | /* received a fragment of a frame for which the head fragment | |
153 | * should have already been received */ | |
154 | entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2, | |
155 | hdr->addr1); | |
156 | if (entry != NULL) { | |
157 | entry->last_frag = frag; | |
158 | skb = entry->skb; | |
159 | } | |
160 | } | |
161 | ||
162 | return skb; | |
163 | } | |
164 | ||
165 | ||
166 | /* Called only as a tasklet (software IRQ) */ | |
167 | static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee, | |
168 | struct ieee80211_hdr_4addr *hdr) | |
169 | { | |
170 | u16 fc = le16_to_cpu(hdr->frame_ctl); | |
171 | u16 sc = le16_to_cpu(hdr->seq_ctl); | |
172 | unsigned int seq = WLAN_GET_SEQ_SEQ(sc); | |
173 | struct ieee80211_frag_entry *entry; | |
174 | struct ieee80211_hdr_3addrqos *hdr_3addrqos; | |
175 | struct ieee80211_hdr_4addrqos *hdr_4addrqos; | |
176 | u8 tid; | |
177 | ||
178 | if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) { | |
179 | hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr; | |
180 | tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; | |
181 | tid = UP2AC(tid); | |
182 | tid ++; | |
183 | } else if (IEEE80211_QOS_HAS_SEQ(fc)) { | |
184 | hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr; | |
185 | tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; | |
186 | tid = UP2AC(tid); | |
187 | tid ++; | |
188 | } else { | |
189 | tid = 0; | |
190 | } | |
191 | ||
192 | entry = ieee80211_frag_cache_find(ieee, seq, -1, tid,hdr->addr2, | |
193 | hdr->addr1); | |
194 | ||
195 | if (entry == NULL) { | |
196 | IEEE80211_DEBUG_FRAG( | |
197 | "could not invalidate fragment cache " | |
198 | "entry (seq=%u)\n", seq); | |
199 | return -1; | |
200 | } | |
201 | ||
202 | entry->skb = NULL; | |
203 | return 0; | |
204 | } | |
205 | ||
206 | ||
207 | ||
208 | /* ieee80211_rx_frame_mgtmt | |
209 | * | |
210 | * Responsible for handling management control frames | |
211 | * | |
212 | * Called by ieee80211_rx */ | |
213 | static inline int | |
214 | ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb, | |
215 | struct ieee80211_rx_stats *rx_stats, u16 type, | |
216 | u16 stype) | |
217 | { | |
218 | /* On the struct stats definition there is written that | |
219 | * this is not mandatory.... but seems that the probe | |
220 | * response parser uses it | |
221 | */ | |
222 | struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data; | |
223 | ||
224 | rx_stats->len = skb->len; | |
225 | ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats); | |
226 | //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) | |
227 | if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames | |
228 | { | |
229 | dev_kfree_skb_any(skb); | |
230 | return 0; | |
231 | } | |
232 | ||
233 | ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype); | |
234 | ||
235 | dev_kfree_skb_any(skb); | |
236 | ||
237 | return 0; | |
238 | ||
239 | #ifdef NOT_YET | |
240 | if (ieee->iw_mode == IW_MODE_MASTER) { | |
241 | printk(KERN_DEBUG "%s: Master mode not yet suppported.\n", | |
242 | ieee->dev->name); | |
243 | return 0; | |
244 | /* | |
245 | hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *) | |
246 | skb->data);*/ | |
247 | } | |
248 | ||
249 | if (ieee->hostapd && type == IEEE80211_TYPE_MGMT) { | |
250 | if (stype == WLAN_FC_STYPE_BEACON && | |
251 | ieee->iw_mode == IW_MODE_MASTER) { | |
252 | struct sk_buff *skb2; | |
253 | /* Process beacon frames also in kernel driver to | |
254 | * update STA(AP) table statistics */ | |
255 | skb2 = skb_clone(skb, GFP_ATOMIC); | |
256 | if (skb2) | |
257 | hostap_rx(skb2->dev, skb2, rx_stats); | |
258 | } | |
259 | ||
260 | /* send management frames to the user space daemon for | |
261 | * processing */ | |
262 | ieee->apdevstats.rx_packets++; | |
263 | ieee->apdevstats.rx_bytes += skb->len; | |
264 | prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT); | |
265 | return 0; | |
266 | } | |
267 | ||
268 | if (ieee->iw_mode == IW_MODE_MASTER) { | |
269 | if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) { | |
270 | printk(KERN_DEBUG "%s: unknown management frame " | |
271 | "(type=0x%02x, stype=0x%02x) dropped\n", | |
272 | skb->dev->name, type, stype); | |
273 | return -1; | |
274 | } | |
275 | ||
276 | hostap_rx(skb->dev, skb, rx_stats); | |
277 | return 0; | |
278 | } | |
279 | ||
280 | printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame " | |
281 | "received in non-Host AP mode\n", skb->dev->name); | |
282 | return -1; | |
283 | #endif | |
284 | } | |
285 | ||
286 | ||
287 | ||
288 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ | |
289 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ | |
290 | static unsigned char rfc1042_header[] = | |
291 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
292 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ | |
293 | static unsigned char bridge_tunnel_header[] = | |
294 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; | |
295 | /* No encapsulation header if EtherType < 0x600 (=length) */ | |
296 | ||
297 | /* Called by ieee80211_rx_frame_decrypt */ | |
298 | static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee, | |
299 | struct sk_buff *skb, size_t hdrlen) | |
300 | { | |
301 | struct net_device *dev = ieee->dev; | |
302 | u16 fc, ethertype; | |
303 | struct ieee80211_hdr_4addr *hdr; | |
304 | u8 *pos; | |
305 | ||
306 | if (skb->len < 24) | |
307 | return 0; | |
308 | ||
309 | hdr = (struct ieee80211_hdr_4addr *) skb->data; | |
310 | fc = le16_to_cpu(hdr->frame_ctl); | |
311 | ||
312 | /* check that the frame is unicast frame to us */ | |
313 | if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == | |
314 | IEEE80211_FCTL_TODS && | |
315 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 && | |
316 | memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) { | |
317 | /* ToDS frame with own addr BSSID and DA */ | |
318 | } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == | |
319 | IEEE80211_FCTL_FROMDS && | |
320 | memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) { | |
321 | /* FromDS frame with own addr as DA */ | |
322 | } else | |
323 | return 0; | |
324 | ||
325 | if (skb->len < 24 + 8) | |
326 | return 0; | |
327 | ||
328 | /* check for port access entity Ethernet type */ | |
329 | // pos = skb->data + 24; | |
330 | pos = skb->data + hdrlen; | |
331 | ethertype = (pos[6] << 8) | pos[7]; | |
332 | if (ethertype == ETH_P_PAE) | |
333 | return 1; | |
334 | ||
335 | return 0; | |
336 | } | |
337 | ||
338 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ | |
339 | static inline int | |
340 | ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb, | |
341 | struct ieee80211_crypt_data *crypt) | |
342 | { | |
343 | struct ieee80211_hdr_4addr *hdr; | |
344 | int res, hdrlen; | |
345 | ||
346 | if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL) | |
347 | return 0; | |
8fc8598e JC |
348 | if (ieee->hwsec_active) |
349 | { | |
350 | cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE); | |
351 | tcb_desc->bHwSec = 1; | |
352 | } | |
8fc8598e JC |
353 | hdr = (struct ieee80211_hdr_4addr *) skb->data; |
354 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); | |
355 | ||
356 | #ifdef CONFIG_IEEE80211_CRYPT_TKIP | |
357 | if (ieee->tkip_countermeasures && | |
358 | strcmp(crypt->ops->name, "TKIP") == 0) { | |
359 | if (net_ratelimit()) { | |
360 | printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " | |
0ee9f67c JP |
361 | "received packet from %pM\n", |
362 | ieee->dev->name, hdr->addr2); | |
8fc8598e JC |
363 | } |
364 | return -1; | |
365 | } | |
366 | #endif | |
367 | ||
368 | atomic_inc(&crypt->refcnt); | |
369 | res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv); | |
370 | atomic_dec(&crypt->refcnt); | |
371 | if (res < 0) { | |
372 | IEEE80211_DEBUG_DROP( | |
0ee9f67c JP |
373 | "decryption failed (SA=%pM" |
374 | ") res=%d\n", hdr->addr2, res); | |
8fc8598e JC |
375 | if (res == -2) |
376 | IEEE80211_DEBUG_DROP("Decryption failed ICV " | |
377 | "mismatch (key %d)\n", | |
378 | skb->data[hdrlen + 3] >> 6); | |
379 | ieee->ieee_stats.rx_discards_undecryptable++; | |
380 | return -1; | |
381 | } | |
382 | ||
383 | return res; | |
384 | } | |
385 | ||
386 | ||
387 | /* Called only as a tasklet (software IRQ), by ieee80211_rx */ | |
388 | static inline int | |
389 | ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb, | |
390 | int keyidx, struct ieee80211_crypt_data *crypt) | |
391 | { | |
392 | struct ieee80211_hdr_4addr *hdr; | |
393 | int res, hdrlen; | |
394 | ||
395 | if (crypt == NULL || crypt->ops->decrypt_msdu == NULL) | |
396 | return 0; | |
397 | if (ieee->hwsec_active) | |
398 | { | |
399 | cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE); | |
400 | tcb_desc->bHwSec = 1; | |
401 | } | |
402 | ||
403 | hdr = (struct ieee80211_hdr_4addr *) skb->data; | |
404 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); | |
405 | ||
406 | atomic_inc(&crypt->refcnt); | |
407 | res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv); | |
408 | atomic_dec(&crypt->refcnt); | |
409 | if (res < 0) { | |
410 | printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed" | |
0ee9f67c JP |
411 | " (SA=%pM keyidx=%d)\n", |
412 | ieee->dev->name, hdr->addr2, keyidx); | |
8fc8598e JC |
413 | return -1; |
414 | } | |
415 | ||
416 | return 0; | |
417 | } | |
418 | ||
419 | ||
420 | /* this function is stolen from ipw2200 driver*/ | |
421 | #define IEEE_PACKET_RETRY_TIME (5*HZ) | |
422 | static int is_duplicate_packet(struct ieee80211_device *ieee, | |
423 | struct ieee80211_hdr_4addr *header) | |
424 | { | |
425 | u16 fc = le16_to_cpu(header->frame_ctl); | |
426 | u16 sc = le16_to_cpu(header->seq_ctl); | |
427 | u16 seq = WLAN_GET_SEQ_SEQ(sc); | |
428 | u16 frag = WLAN_GET_SEQ_FRAG(sc); | |
429 | u16 *last_seq, *last_frag; | |
430 | unsigned long *last_time; | |
431 | struct ieee80211_hdr_3addrqos *hdr_3addrqos; | |
432 | struct ieee80211_hdr_4addrqos *hdr_4addrqos; | |
433 | u8 tid; | |
434 | ||
435 | ||
436 | //TO2DS and QoS | |
437 | if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) { | |
438 | hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header; | |
439 | tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; | |
440 | tid = UP2AC(tid); | |
441 | tid ++; | |
442 | } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS | |
443 | hdr_3addrqos = (struct ieee80211_hdr_3addrqos*)header; | |
444 | tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; | |
445 | tid = UP2AC(tid); | |
446 | tid ++; | |
447 | } else { // no QoS | |
448 | tid = 0; | |
449 | } | |
450 | ||
451 | switch (ieee->iw_mode) { | |
452 | case IW_MODE_ADHOC: | |
453 | { | |
454 | struct list_head *p; | |
455 | struct ieee_ibss_seq *entry = NULL; | |
456 | u8 *mac = header->addr2; | |
457 | int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE; | |
458 | //for (pos = (head)->next; pos != (head); pos = pos->next) | |
459 | //__list_for_each(p, &ieee->ibss_mac_hash[index]) { | |
460 | list_for_each(p, &ieee->ibss_mac_hash[index]) { | |
461 | entry = list_entry(p, struct ieee_ibss_seq, list); | |
462 | if (!memcmp(entry->mac, mac, ETH_ALEN)) | |
463 | break; | |
464 | } | |
465 | // if (memcmp(entry->mac, mac, ETH_ALEN)){ | |
466 | if (p == &ieee->ibss_mac_hash[index]) { | |
467 | entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC); | |
468 | if (!entry) { | |
469 | printk(KERN_WARNING "Cannot malloc new mac entry\n"); | |
470 | return 0; | |
471 | } | |
472 | memcpy(entry->mac, mac, ETH_ALEN); | |
473 | entry->seq_num[tid] = seq; | |
474 | entry->frag_num[tid] = frag; | |
475 | entry->packet_time[tid] = jiffies; | |
476 | list_add(&entry->list, &ieee->ibss_mac_hash[index]); | |
477 | return 0; | |
478 | } | |
479 | last_seq = &entry->seq_num[tid]; | |
480 | last_frag = &entry->frag_num[tid]; | |
481 | last_time = &entry->packet_time[tid]; | |
482 | break; | |
483 | } | |
484 | ||
485 | case IW_MODE_INFRA: | |
486 | last_seq = &ieee->last_rxseq_num[tid]; | |
487 | last_frag = &ieee->last_rxfrag_num[tid]; | |
488 | last_time = &ieee->last_packet_time[tid]; | |
489 | ||
490 | break; | |
491 | default: | |
492 | return 0; | |
493 | } | |
494 | ||
495 | // if(tid != 0) { | |
496 | // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl); | |
497 | // } | |
498 | if ((*last_seq == seq) && | |
499 | time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) { | |
500 | if (*last_frag == frag){ | |
501 | //printk(KERN_WARNING "[1] go drop!\n"); | |
502 | goto drop; | |
503 | ||
504 | } | |
505 | if (*last_frag + 1 != frag) | |
506 | /* out-of-order fragment */ | |
507 | //printk(KERN_WARNING "[2] go drop!\n"); | |
508 | goto drop; | |
509 | } else | |
510 | *last_seq = seq; | |
511 | ||
512 | *last_frag = frag; | |
513 | *last_time = jiffies; | |
514 | return 0; | |
515 | ||
516 | drop: | |
517 | // BUG_ON(!(fc & IEEE80211_FCTL_RETRY)); | |
518 | // printk("DUP\n"); | |
519 | ||
520 | return 1; | |
521 | } | |
522 | bool | |
523 | AddReorderEntry( | |
524 | PRX_TS_RECORD pTS, | |
525 | PRX_REORDER_ENTRY pReorderEntry | |
526 | ) | |
527 | { | |
528 | struct list_head *pList = &pTS->RxPendingPktList; | |
8fc8598e JC |
529 | while(pList->next != &pTS->RxPendingPktList) |
530 | { | |
531 | if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) ) | |
532 | { | |
533 | pList = pList->next; | |
534 | } | |
535 | else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) ) | |
536 | { | |
537 | return false; | |
538 | } | |
539 | else | |
540 | { | |
541 | break; | |
542 | } | |
543 | } | |
8fc8598e JC |
544 | pReorderEntry->List.next = pList->next; |
545 | pReorderEntry->List.next->prev = &pReorderEntry->List; | |
546 | pReorderEntry->List.prev = pList; | |
547 | pList->next = &pReorderEntry->List; | |
548 | ||
549 | return true; | |
550 | } | |
551 | ||
552 | void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8 index) | |
553 | { | |
554 | u8 i = 0 , j=0; | |
555 | u16 ethertype; | |
556 | // if(index > 1) | |
557 | // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__FUNCTION__,index); | |
558 | for(j = 0; j<index; j++) | |
559 | { | |
560 | //added by amy for reorder | |
561 | struct ieee80211_rxb* prxb = prxbIndicateArray[j]; | |
562 | for(i = 0; i<prxb->nr_subframes; i++) { | |
563 | struct sk_buff *sub_skb = prxb->subframes[i]; | |
564 | ||
565 | /* convert hdr + possible LLC headers into Ethernet header */ | |
566 | ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7]; | |
567 | if (sub_skb->len >= 8 && | |
568 | ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 && | |
569 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | |
570 | memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) { | |
571 | /* remove RFC1042 or Bridge-Tunnel encapsulation and | |
572 | * replace EtherType */ | |
573 | skb_pull(sub_skb, SNAP_SIZE); | |
574 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN); | |
575 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN); | |
576 | } else { | |
577 | u16 len; | |
578 | /* Leave Ethernet header part of hdr and full payload */ | |
579 | len = htons(sub_skb->len); | |
580 | memcpy(skb_push(sub_skb, 2), &len, 2); | |
581 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN); | |
582 | memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN); | |
583 | } | |
584 | //stats->rx_packets++; | |
585 | //stats->rx_bytes += sub_skb->len; | |
586 | ||
587 | /* Indicat the packets to upper layer */ | |
588 | if (sub_skb) { | |
589 | //printk("0skb_len(%d)\n", skb->len); | |
590 | sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev); | |
591 | memset(sub_skb->cb, 0, sizeof(sub_skb->cb)); | |
592 | sub_skb->dev = ieee->dev; | |
593 | sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */ | |
594 | //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */ | |
595 | ieee->last_rx_ps_time = jiffies; | |
596 | //printk("1skb_len(%d)\n", skb->len); | |
597 | netif_rx(sub_skb); | |
598 | } | |
599 | } | |
600 | kfree(prxb); | |
601 | prxb = NULL; | |
602 | } | |
603 | } | |
604 | ||
605 | ||
606 | void RxReorderIndicatePacket( struct ieee80211_device *ieee, | |
607 | struct ieee80211_rxb* prxb, | |
608 | PRX_TS_RECORD pTS, | |
609 | u16 SeqNum) | |
610 | { | |
611 | PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; | |
612 | PRX_REORDER_ENTRY pReorderEntry = NULL; | |
613 | struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE]; | |
614 | u8 WinSize = pHTInfo->RxReorderWinSize; | |
615 | u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096; | |
616 | u8 index = 0; | |
617 | bool bMatchWinStart = false, bPktInBuf = false; | |
618 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__FUNCTION__,SeqNum,pTS->RxIndicateSeq,WinSize); | |
8fc8598e JC |
619 | /* Rx Reorder initialize condition.*/ |
620 | if(pTS->RxIndicateSeq == 0xffff) { | |
621 | pTS->RxIndicateSeq = SeqNum; | |
622 | } | |
623 | ||
624 | /* Drop out the packet which SeqNum is smaller than WinStart */ | |
625 | if(SN_LESS(SeqNum, pTS->RxIndicateSeq)) { | |
626 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n", | |
627 | pTS->RxIndicateSeq, SeqNum); | |
628 | pHTInfo->RxReorderDropCounter++; | |
629 | { | |
630 | int i; | |
631 | for(i =0; i < prxb->nr_subframes; i++) { | |
632 | dev_kfree_skb(prxb->subframes[i]); | |
633 | } | |
634 | kfree(prxb); | |
635 | prxb = NULL; | |
636 | } | |
637 | return; | |
638 | } | |
639 | ||
640 | /* | |
641 | * Sliding window manipulation. Conditions includes: | |
642 | * 1. Incoming SeqNum is equal to WinStart =>Window shift 1 | |
643 | * 2. Incoming SeqNum is larger than the WinEnd => Window shift N | |
644 | */ | |
645 | if(SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) { | |
646 | pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096; | |
647 | bMatchWinStart = true; | |
648 | } else if(SN_LESS(WinEnd, SeqNum)) { | |
649 | if(SeqNum >= (WinSize - 1)) { | |
650 | pTS->RxIndicateSeq = SeqNum + 1 -WinSize; | |
651 | } else { | |
652 | pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1; | |
653 | } | |
654 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum); | |
655 | } | |
656 | ||
657 | /* | |
658 | * Indication process. | |
659 | * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets | |
660 | * with the SeqNum smaller than latest WinStart and buffer other packets. | |
661 | */ | |
662 | /* For Rx Reorder condition: | |
663 | * 1. All packets with SeqNum smaller than WinStart => Indicate | |
664 | * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. | |
665 | */ | |
666 | if(bMatchWinStart) { | |
667 | /* Current packet is going to be indicated.*/ | |
668 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\ | |
669 | pTS->RxIndicateSeq, SeqNum); | |
670 | prxbIndicateArray[0] = prxb; | |
671 | // printk("========================>%s(): SeqNum is %d\n",__FUNCTION__,SeqNum); | |
672 | index = 1; | |
673 | } else { | |
674 | /* Current packet is going to be inserted into pending list.*/ | |
675 | //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to orderd list\n",__FUNCTION__); | |
676 | if(!list_empty(&ieee->RxReorder_Unused_List)) { | |
677 | pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List); | |
678 | list_del_init(&pReorderEntry->List); | |
679 | ||
680 | /* Make a reorder entry and insert into a the packet list.*/ | |
681 | pReorderEntry->SeqNum = SeqNum; | |
682 | pReorderEntry->prxb = prxb; | |
683 | // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum); | |
684 | ||
8fc8598e JC |
685 | if(!AddReorderEntry(pTS, pReorderEntry)) { |
686 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n", | |
687 | __FUNCTION__, pTS->RxIndicateSeq, SeqNum); | |
688 | list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List); | |
689 | { | |
690 | int i; | |
691 | for(i =0; i < prxb->nr_subframes; i++) { | |
692 | dev_kfree_skb(prxb->subframes[i]); | |
693 | } | |
694 | kfree(prxb); | |
695 | prxb = NULL; | |
696 | } | |
697 | } else { | |
698 | IEEE80211_DEBUG(IEEE80211_DL_REORDER, | |
699 | "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum); | |
700 | } | |
8fc8598e JC |
701 | } |
702 | else { | |
703 | /* | |
704 | * Packets are dropped if there is not enough reorder entries. | |
705 | * This part shall be modified!! We can just indicate all the | |
706 | * packets in buffer and get reorder entries. | |
707 | */ | |
708 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n"); | |
709 | { | |
710 | int i; | |
711 | for(i =0; i < prxb->nr_subframes; i++) { | |
712 | dev_kfree_skb(prxb->subframes[i]); | |
713 | } | |
714 | kfree(prxb); | |
715 | prxb = NULL; | |
716 | } | |
717 | } | |
718 | } | |
719 | ||
720 | /* Check if there is any packet need indicate.*/ | |
721 | while(!list_empty(&pTS->RxPendingPktList)) { | |
722 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__FUNCTION__); | |
8fc8598e JC |
723 | pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List); |
724 | if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) || | |
725 | SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) | |
726 | { | |
727 | /* This protect buffer from overflow. */ | |
728 | if(index >= REORDER_WIN_SIZE) { | |
729 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n"); | |
730 | bPktInBuf = true; | |
731 | break; | |
732 | } | |
733 | ||
734 | list_del_init(&pReorderEntry->List); | |
735 | ||
736 | if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) | |
737 | pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096; | |
738 | ||
739 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum); | |
740 | prxbIndicateArray[index] = pReorderEntry->prxb; | |
741 | // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__FUNCTION__,pReorderEntry->SeqNum); | |
742 | index++; | |
743 | ||
744 | list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List); | |
745 | } else { | |
746 | bPktInBuf = true; | |
747 | break; | |
748 | } | |
8fc8598e JC |
749 | } |
750 | ||
751 | /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/ | |
752 | if(index>0) { | |
753 | // Cancel previous pending timer. | |
754 | // del_timer_sync(&pTS->RxPktPendingTimer); | |
755 | pTS->RxTimeoutIndicateSeq = 0xffff; | |
756 | ||
757 | // Indicate packets | |
758 | if(index>REORDER_WIN_SIZE){ | |
759 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n"); | |
760 | return; | |
761 | } | |
762 | ieee80211_indicate_packets(ieee, prxbIndicateArray, index); | |
763 | } | |
764 | ||
8fc8598e JC |
765 | if(bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) { |
766 | // Set new pending timer. | |
767 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __FUNCTION__); | |
768 | pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq; | |
769 | if(timer_pending(&pTS->RxPktPendingTimer)) | |
770 | del_timer_sync(&pTS->RxPktPendingTimer); | |
771 | pTS->RxPktPendingTimer.expires = jiffies + MSECS(pHTInfo->RxReorderPendingTime); | |
772 | add_timer(&pTS->RxPktPendingTimer); | |
773 | } | |
8fc8598e JC |
774 | } |
775 | ||
776 | u8 parse_subframe(struct sk_buff *skb, | |
777 | struct ieee80211_rx_stats *rx_stats, | |
778 | struct ieee80211_rxb *rxb,u8* src,u8* dst) | |
779 | { | |
780 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data; | |
781 | u16 fc = le16_to_cpu(hdr->frame_ctl); | |
782 | ||
783 | u16 LLCOffset= sizeof(struct ieee80211_hdr_3addr); | |
784 | u16 ChkLength; | |
785 | bool bIsAggregateFrame = false; | |
786 | u16 nSubframe_Length; | |
787 | u8 nPadding_Length = 0; | |
788 | u16 SeqNum=0; | |
789 | ||
790 | struct sk_buff *sub_skb; | |
791 | u8 *data_ptr; | |
792 | /* just for debug purpose */ | |
793 | SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl)); | |
794 | ||
795 | if((IEEE80211_QOS_HAS_SEQ(fc))&&\ | |
796 | (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) { | |
797 | bIsAggregateFrame = true; | |
798 | } | |
799 | ||
800 | if(IEEE80211_QOS_HAS_SEQ(fc)) { | |
801 | LLCOffset += 2; | |
802 | } | |
803 | ||
804 | if(rx_stats->bContainHTC) { | |
805 | LLCOffset += sHTCLng; | |
806 | } | |
807 | //printk("ChkLength = %d\n", LLCOffset); | |
808 | // Null packet, don't indicate it to upper layer | |
809 | ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/ | |
810 | ||
811 | if( skb->len <= ChkLength ) { | |
812 | return 0; | |
813 | } | |
814 | ||
815 | skb_pull(skb, LLCOffset); | |
816 | ||
817 | if(!bIsAggregateFrame) { | |
818 | rxb->nr_subframes = 1; | |
819 | #ifdef JOHN_NOCPY | |
820 | rxb->subframes[0] = skb; | |
821 | #else | |
822 | rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC); | |
823 | #endif | |
824 | ||
825 | memcpy(rxb->src,src,ETH_ALEN); | |
826 | memcpy(rxb->dst,dst,ETH_ALEN); | |
827 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len); | |
828 | return 1; | |
829 | } else { | |
830 | rxb->nr_subframes = 0; | |
831 | memcpy(rxb->src,src,ETH_ALEN); | |
832 | memcpy(rxb->dst,dst,ETH_ALEN); | |
833 | while(skb->len > ETHERNET_HEADER_SIZE) { | |
834 | /* Offset 12 denote 2 mac address */ | |
835 | nSubframe_Length = *((u16*)(skb->data + 12)); | |
836 | //==m==>change the length order | |
837 | nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8); | |
838 | ||
839 | if(skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) { | |
8fc8598e JC |
840 | printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\ |
841 | __FUNCTION__,rxb->nr_subframes); | |
842 | printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__FUNCTION__, nSubframe_Length); | |
843 | printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length); | |
844 | printk("The Packet SeqNum is %d\n",SeqNum); | |
845 | return 0; | |
846 | } | |
847 | ||
848 | /* move the data point to data content */ | |
849 | skb_pull(skb, ETHERNET_HEADER_SIZE); | |
850 | ||
851 | #ifdef JOHN_NOCPY | |
852 | sub_skb = skb_clone(skb, GFP_ATOMIC); | |
853 | sub_skb->len = nSubframe_Length; | |
854 | sub_skb->tail = sub_skb->data + nSubframe_Length; | |
855 | #else | |
856 | /* Allocate new skb for releasing to upper layer */ | |
857 | sub_skb = dev_alloc_skb(nSubframe_Length + 12); | |
858 | skb_reserve(sub_skb, 12); | |
859 | data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length); | |
860 | memcpy(data_ptr,skb->data,nSubframe_Length); | |
861 | #endif | |
862 | rxb->subframes[rxb->nr_subframes++] = sub_skb; | |
863 | if(rxb->nr_subframes >= MAX_SUBFRAME_COUNT) { | |
864 | IEEE80211_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n"); | |
865 | break; | |
866 | } | |
867 | skb_pull(skb,nSubframe_Length); | |
868 | ||
869 | if(skb->len != 0) { | |
870 | nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4); | |
871 | if(nPadding_Length == 4) { | |
872 | nPadding_Length = 0; | |
873 | } | |
874 | ||
875 | if(skb->len < nPadding_Length) { | |
876 | return 0; | |
877 | } | |
878 | ||
879 | skb_pull(skb,nPadding_Length); | |
880 | } | |
881 | } | |
882 | #ifdef JOHN_NOCPY | |
883 | dev_kfree_skb(skb); | |
884 | #endif | |
885 | //{just for debug added by david | |
886 | //printk("AMSDU::rxb->nr_subframes = %d\n",rxb->nr_subframes); | |
887 | //} | |
888 | return rxb->nr_subframes; | |
889 | } | |
890 | } | |
891 | ||
892 | /* All received frames are sent to this function. @skb contains the frame in | |
893 | * IEEE 802.11 format, i.e., in the format it was sent over air. | |
894 | * This function is called only as a tasklet (software IRQ). */ | |
895 | int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, | |
896 | struct ieee80211_rx_stats *rx_stats) | |
897 | { | |
898 | struct net_device *dev = ieee->dev; | |
899 | struct ieee80211_hdr_4addr *hdr; | |
900 | //struct ieee80211_hdr_3addrqos *hdr; | |
901 | ||
902 | size_t hdrlen; | |
903 | u16 fc, type, stype, sc; | |
904 | struct net_device_stats *stats; | |
905 | unsigned int frag; | |
906 | u8 *payload; | |
907 | u16 ethertype; | |
908 | //added by amy for reorder | |
909 | u8 TID = 0; | |
910 | u16 SeqNum = 0; | |
911 | PRX_TS_RECORD pTS = NULL; | |
912 | //bool bIsAggregateFrame = false; | |
913 | //added by amy for reorder | |
914 | #ifdef NOT_YET | |
915 | struct net_device *wds = NULL; | |
916 | struct sk_buff *skb2 = NULL; | |
917 | struct net_device *wds = NULL; | |
918 | int frame_authorized = 0; | |
919 | int from_assoc_ap = 0; | |
920 | void *sta = NULL; | |
921 | #endif | |
922 | // u16 qos_ctl = 0; | |
923 | u8 dst[ETH_ALEN]; | |
924 | u8 src[ETH_ALEN]; | |
925 | u8 bssid[ETH_ALEN]; | |
926 | struct ieee80211_crypt_data *crypt = NULL; | |
927 | int keyidx = 0; | |
928 | ||
929 | int i; | |
930 | struct ieee80211_rxb* rxb = NULL; | |
931 | // cheat the the hdr type | |
932 | hdr = (struct ieee80211_hdr_4addr *)skb->data; | |
933 | stats = &ieee->stats; | |
934 | ||
935 | if (skb->len < 10) { | |
936 | printk(KERN_INFO "%s: SKB length < 10\n", | |
937 | dev->name); | |
938 | goto rx_dropped; | |
939 | } | |
940 | ||
941 | fc = le16_to_cpu(hdr->frame_ctl); | |
942 | type = WLAN_FC_GET_TYPE(fc); | |
943 | stype = WLAN_FC_GET_STYPE(fc); | |
944 | sc = le16_to_cpu(hdr->seq_ctl); | |
945 | ||
946 | frag = WLAN_GET_SEQ_FRAG(sc); | |
947 | hdrlen = ieee80211_get_hdrlen(fc); | |
948 | ||
949 | if(HTCCheck(ieee, skb->data)) | |
950 | { | |
951 | if(net_ratelimit()) | |
952 | printk("find HTCControl\n"); | |
953 | hdrlen += 4; | |
954 | rx_stats->bContainHTC = 1; | |
955 | } | |
956 | ||
957 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); | |
958 | #ifdef NOT_YET | |
959 | #if WIRELESS_EXT > 15 | |
960 | /* Put this code here so that we avoid duplicating it in all | |
961 | * Rx paths. - Jean II */ | |
962 | #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */ | |
963 | /* If spy monitoring on */ | |
964 | if (iface->spy_data.spy_number > 0) { | |
965 | struct iw_quality wstats; | |
966 | wstats.level = rx_stats->rssi; | |
967 | wstats.noise = rx_stats->noise; | |
968 | wstats.updated = 6; /* No qual value */ | |
969 | /* Update spy records */ | |
970 | wireless_spy_update(dev, hdr->addr2, &wstats); | |
971 | } | |
972 | #endif /* IW_WIRELESS_SPY */ | |
973 | #endif /* WIRELESS_EXT > 15 */ | |
974 | hostap_update_rx_stats(local->ap, hdr, rx_stats); | |
975 | #endif | |
976 | ||
977 | #if WIRELESS_EXT > 15 | |
978 | if (ieee->iw_mode == IW_MODE_MONITOR) { | |
979 | ieee80211_monitor_rx(ieee, skb, rx_stats); | |
980 | stats->rx_packets++; | |
981 | stats->rx_bytes += skb->len; | |
982 | return 1; | |
983 | } | |
984 | #endif | |
985 | if (ieee->host_decrypt) { | |
986 | int idx = 0; | |
987 | if (skb->len >= hdrlen + 3) | |
988 | idx = skb->data[hdrlen + 3] >> 6; | |
989 | crypt = ieee->crypt[idx]; | |
990 | #ifdef NOT_YET | |
991 | sta = NULL; | |
992 | ||
993 | /* Use station specific key to override default keys if the | |
994 | * receiver address is a unicast address ("individual RA"). If | |
995 | * bcrx_sta_key parameter is set, station specific key is used | |
996 | * even with broad/multicast targets (this is against IEEE | |
997 | * 802.11, but makes it easier to use different keys with | |
998 | * stations that do not support WEP key mapping). */ | |
999 | ||
1000 | if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key) | |
1001 | (void) hostap_handle_sta_crypto(local, hdr, &crypt, | |
1002 | &sta); | |
1003 | #endif | |
1004 | ||
1005 | /* allow NULL decrypt to indicate an station specific override | |
1006 | * for default encryption */ | |
1007 | if (crypt && (crypt->ops == NULL || | |
1008 | crypt->ops->decrypt_mpdu == NULL)) | |
1009 | crypt = NULL; | |
1010 | ||
1011 | if (!crypt && (fc & IEEE80211_FCTL_WEP)) { | |
1012 | /* This seems to be triggered by some (multicast?) | |
1013 | * frames from other than current BSS, so just drop the | |
1014 | * frames silently instead of filling system log with | |
1015 | * these reports. */ | |
1016 | IEEE80211_DEBUG_DROP("Decryption failed (not set)" | |
0ee9f67c JP |
1017 | " (SA=%pM)\n", |
1018 | hdr->addr2); | |
8fc8598e JC |
1019 | ieee->ieee_stats.rx_discards_undecryptable++; |
1020 | goto rx_dropped; | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | if (skb->len < IEEE80211_DATA_HDR3_LEN) | |
1025 | goto rx_dropped; | |
1026 | ||
1027 | // if QoS enabled, should check the sequence for each of the AC | |
1028 | if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){ | |
1029 | if (is_duplicate_packet(ieee, hdr)) | |
1030 | goto rx_dropped; | |
1031 | ||
1032 | } | |
1033 | else | |
1034 | { | |
1035 | PRX_TS_RECORD pRxTS = NULL; | |
8fc8598e | 1036 | //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__FUNCTION__, tid); |
8fc8598e JC |
1037 | if(GetTs( |
1038 | ieee, | |
1039 | (PTS_COMMON_INFO*) &pRxTS, | |
1040 | hdr->addr2, | |
1041 | (u8)Frame_QoSTID((u8*)(skb->data)), | |
1042 | RX_DIR, | |
1043 | true)) | |
1044 | { | |
1045 | ||
1046 | // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__FUNCTION__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc)); | |
1047 | if( (fc & (1<<11)) && | |
1048 | (frag == pRxTS->RxLastFragNum) && | |
1049 | (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) ) | |
1050 | { | |
1051 | goto rx_dropped; | |
1052 | } | |
1053 | else | |
1054 | { | |
1055 | pRxTS->RxLastFragNum = frag; | |
1056 | pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc); | |
1057 | } | |
1058 | } | |
1059 | else | |
1060 | { | |
1061 | IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__FUNCTION__); | |
1062 | goto rx_dropped; | |
1063 | } | |
1064 | } | |
8fc8598e JC |
1065 | if (type == IEEE80211_FTYPE_MGMT) { |
1066 | ||
8fc8598e JC |
1067 | |
1068 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); | |
1069 | if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype)) | |
1070 | goto rx_dropped; | |
1071 | else | |
1072 | goto rx_exit; | |
1073 | } | |
1074 | ||
1075 | /* Data frame - extract src/dst addresses */ | |
1076 | switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { | |
1077 | case IEEE80211_FCTL_FROMDS: | |
1078 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
1079 | memcpy(src, hdr->addr3, ETH_ALEN); | |
1080 | memcpy(bssid, hdr->addr2, ETH_ALEN); | |
1081 | break; | |
1082 | case IEEE80211_FCTL_TODS: | |
1083 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
1084 | memcpy(src, hdr->addr2, ETH_ALEN); | |
1085 | memcpy(bssid, hdr->addr1, ETH_ALEN); | |
1086 | break; | |
1087 | case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: | |
1088 | if (skb->len < IEEE80211_DATA_HDR4_LEN) | |
1089 | goto rx_dropped; | |
1090 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
1091 | memcpy(src, hdr->addr4, ETH_ALEN); | |
1092 | memcpy(bssid, ieee->current_network.bssid, ETH_ALEN); | |
1093 | break; | |
1094 | case 0: | |
1095 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
1096 | memcpy(src, hdr->addr2, ETH_ALEN); | |
1097 | memcpy(bssid, hdr->addr3, ETH_ALEN); | |
1098 | break; | |
1099 | } | |
1100 | ||
1101 | #ifdef NOT_YET | |
1102 | if (hostap_rx_frame_wds(ieee, hdr, fc, &wds)) | |
1103 | goto rx_dropped; | |
1104 | if (wds) { | |
1105 | skb->dev = dev = wds; | |
1106 | stats = hostap_get_stats(dev); | |
1107 | } | |
1108 | ||
1109 | if (ieee->iw_mode == IW_MODE_MASTER && !wds && | |
1110 | (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS && | |
1111 | ieee->stadev && | |
1112 | memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) { | |
1113 | /* Frame from BSSID of the AP for which we are a client */ | |
1114 | skb->dev = dev = ieee->stadev; | |
1115 | stats = hostap_get_stats(dev); | |
1116 | from_assoc_ap = 1; | |
1117 | } | |
1118 | #endif | |
1119 | ||
1120 | dev->last_rx = jiffies; | |
1121 | ||
1122 | #ifdef NOT_YET | |
1123 | if ((ieee->iw_mode == IW_MODE_MASTER || | |
1124 | ieee->iw_mode == IW_MODE_REPEAT) && | |
1125 | !from_assoc_ap) { | |
1126 | switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats, | |
1127 | wds != NULL)) { | |
1128 | case AP_RX_CONTINUE_NOT_AUTHORIZED: | |
1129 | frame_authorized = 0; | |
1130 | break; | |
1131 | case AP_RX_CONTINUE: | |
1132 | frame_authorized = 1; | |
1133 | break; | |
1134 | case AP_RX_DROP: | |
1135 | goto rx_dropped; | |
1136 | case AP_RX_EXIT: | |
1137 | goto rx_exit; | |
1138 | } | |
1139 | } | |
1140 | #endif | |
1141 | //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); | |
1142 | /* Nullfunc frames may have PS-bit set, so they must be passed to | |
1143 | * hostap_handle_sta_rx() before being dropped here. */ | |
1144 | if (stype != IEEE80211_STYPE_DATA && | |
1145 | stype != IEEE80211_STYPE_DATA_CFACK && | |
1146 | stype != IEEE80211_STYPE_DATA_CFPOLL && | |
1147 | stype != IEEE80211_STYPE_DATA_CFACKPOLL&& | |
1148 | stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4 | |
1149 | ) { | |
1150 | if (stype != IEEE80211_STYPE_NULLFUNC) | |
1151 | IEEE80211_DEBUG_DROP( | |
1152 | "RX: dropped data frame " | |
1153 | "with no data (type=0x%02x, " | |
1154 | "subtype=0x%02x, len=%d)\n", | |
1155 | type, stype, skb->len); | |
1156 | goto rx_dropped; | |
1157 | } | |
1158 | if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) | |
1159 | goto rx_dropped; | |
1160 | ||
1161 | /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ | |
1162 | ||
1163 | if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && | |
1164 | (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) | |
1165 | { | |
1166 | printk("decrypt frame error\n"); | |
1167 | goto rx_dropped; | |
1168 | } | |
1169 | ||
1170 | ||
1171 | hdr = (struct ieee80211_hdr_4addr *) skb->data; | |
1172 | ||
1173 | /* skb: hdr + (possibly fragmented) plaintext payload */ | |
1174 | // PR: FIXME: hostap has additional conditions in the "if" below: | |
1175 | // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && | |
1176 | if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) { | |
1177 | int flen; | |
1178 | struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr); | |
1179 | IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag); | |
1180 | ||
1181 | if (!frag_skb) { | |
1182 | IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG, | |
1183 | "Rx cannot get skb from fragment " | |
1184 | "cache (morefrag=%d seq=%u frag=%u)\n", | |
1185 | (fc & IEEE80211_FCTL_MOREFRAGS) != 0, | |
1186 | WLAN_GET_SEQ_SEQ(sc), frag); | |
1187 | goto rx_dropped; | |
1188 | } | |
1189 | flen = skb->len; | |
1190 | if (frag != 0) | |
1191 | flen -= hdrlen; | |
1192 | ||
1193 | if (frag_skb->tail + flen > frag_skb->end) { | |
1194 | printk(KERN_WARNING "%s: host decrypted and " | |
1195 | "reassembled frame did not fit skb\n", | |
1196 | dev->name); | |
1197 | ieee80211_frag_cache_invalidate(ieee, hdr); | |
1198 | goto rx_dropped; | |
1199 | } | |
1200 | ||
1201 | if (frag == 0) { | |
1202 | /* copy first fragment (including full headers) into | |
1203 | * beginning of the fragment cache skb */ | |
1204 | memcpy(skb_put(frag_skb, flen), skb->data, flen); | |
1205 | } else { | |
1206 | /* append frame payload to the end of the fragment | |
1207 | * cache skb */ | |
1208 | memcpy(skb_put(frag_skb, flen), skb->data + hdrlen, | |
1209 | flen); | |
1210 | } | |
1211 | dev_kfree_skb_any(skb); | |
1212 | skb = NULL; | |
1213 | ||
1214 | if (fc & IEEE80211_FCTL_MOREFRAGS) { | |
1215 | /* more fragments expected - leave the skb in fragment | |
1216 | * cache for now; it will be delivered to upper layers | |
1217 | * after all fragments have been received */ | |
1218 | goto rx_exit; | |
1219 | } | |
1220 | ||
1221 | /* this was the last fragment and the frame will be | |
1222 | * delivered, so remove skb from fragment cache */ | |
1223 | skb = frag_skb; | |
1224 | hdr = (struct ieee80211_hdr_4addr *) skb->data; | |
1225 | ieee80211_frag_cache_invalidate(ieee, hdr); | |
1226 | } | |
1227 | ||
1228 | /* skb: hdr + (possible reassembled) full MSDU payload; possibly still | |
1229 | * encrypted/authenticated */ | |
1230 | if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && | |
1231 | ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) | |
1232 | { | |
1233 | printk("==>decrypt msdu error\n"); | |
1234 | goto rx_dropped; | |
1235 | } | |
1236 | ||
1237 | //added by amy for AP roaming | |
1238 | ieee->LinkDetectInfo.NumRecvDataInPeriod++; | |
1239 | ieee->LinkDetectInfo.NumRxOkInPeriod++; | |
1240 | ||
1241 | hdr = (struct ieee80211_hdr_4addr *) skb->data; | |
1242 | if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) { | |
1243 | if (/*ieee->ieee802_1x &&*/ | |
1244 | ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { | |
1245 | ||
1246 | #ifdef CONFIG_IEEE80211_DEBUG | |
1247 | /* pass unencrypted EAPOL frames even if encryption is | |
1248 | * configured */ | |
1249 | struct eapol *eap = (struct eapol *)(skb->data + | |
1250 | 24); | |
1251 | IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n", | |
1252 | eap_get_type(eap->type)); | |
1253 | #endif | |
1254 | } else { | |
1255 | IEEE80211_DEBUG_DROP( | |
1256 | "encryption configured, but RX " | |
0ee9f67c JP |
1257 | "frame not encrypted (SA=%pM)\n", |
1258 | hdr->addr2); | |
8fc8598e JC |
1259 | goto rx_dropped; |
1260 | } | |
1261 | } | |
1262 | ||
1263 | #ifdef CONFIG_IEEE80211_DEBUG | |
1264 | if (crypt && !(fc & IEEE80211_FCTL_WEP) && | |
1265 | ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { | |
1266 | struct eapol *eap = (struct eapol *)(skb->data + | |
1267 | 24); | |
1268 | IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n", | |
1269 | eap_get_type(eap->type)); | |
1270 | } | |
1271 | #endif | |
1272 | ||
1273 | if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep && | |
1274 | !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { | |
1275 | IEEE80211_DEBUG_DROP( | |
1276 | "dropped unencrypted RX data " | |
0ee9f67c | 1277 | "frame from %pM" |
8fc8598e | 1278 | " (drop_unencrypted=1)\n", |
0ee9f67c | 1279 | hdr->addr2); |
8fc8598e JC |
1280 | goto rx_dropped; |
1281 | } | |
1282 | /* | |
1283 | if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { | |
1284 | printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n"); | |
1285 | } | |
1286 | */ | |
1287 | //added by amy for reorder | |
8fc8598e JC |
1288 | if(ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data) |
1289 | && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1)) | |
1290 | { | |
1291 | TID = Frame_QoSTID(skb->data); | |
1292 | SeqNum = WLAN_GET_SEQ_SEQ(sc); | |
1293 | GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true); | |
1294 | if(TID !=0 && TID !=3) | |
1295 | { | |
1296 | ieee->bis_any_nonbepkts = true; | |
1297 | } | |
1298 | } | |
8fc8598e JC |
1299 | //added by amy for reorder |
1300 | /* skb: hdr + (possible reassembled) full plaintext payload */ | |
1301 | payload = skb->data + hdrlen; | |
1302 | //ethertype = (payload[6] << 8) | payload[7]; | |
32414878 | 1303 | rxb = kmalloc(sizeof(struct ieee80211_rxb), GFP_ATOMIC); |
8fc8598e JC |
1304 | if(rxb == NULL) |
1305 | { | |
1306 | IEEE80211_DEBUG(IEEE80211_DL_ERR,"%s(): kmalloc rxb error\n",__FUNCTION__); | |
1307 | goto rx_dropped; | |
1308 | } | |
1309 | /* to parse amsdu packets */ | |
1310 | /* qos data packets & reserved bit is 1 */ | |
1311 | if(parse_subframe(skb,rx_stats,rxb,src,dst) == 0) { | |
1312 | /* only to free rxb, and not submit the packets to upper layer */ | |
1313 | for(i =0; i < rxb->nr_subframes; i++) { | |
1314 | dev_kfree_skb(rxb->subframes[i]); | |
1315 | } | |
1316 | kfree(rxb); | |
1317 | rxb = NULL; | |
1318 | goto rx_dropped; | |
1319 | } | |
1320 | ||
1321 | //added by amy for reorder | |
1322 | if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){ | |
1323 | //added by amy for reorder | |
1324 | for(i = 0; i<rxb->nr_subframes; i++) { | |
1325 | struct sk_buff *sub_skb = rxb->subframes[i]; | |
1326 | ||
1327 | if (sub_skb) { | |
1328 | /* convert hdr + possible LLC headers into Ethernet header */ | |
1329 | ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7]; | |
1330 | if (sub_skb->len >= 8 && | |
1331 | ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 && | |
1332 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | |
1333 | memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) { | |
1334 | /* remove RFC1042 or Bridge-Tunnel encapsulation and | |
1335 | * replace EtherType */ | |
1336 | skb_pull(sub_skb, SNAP_SIZE); | |
1337 | memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN); | |
1338 | memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN); | |
1339 | } else { | |
1340 | u16 len; | |
1341 | /* Leave Ethernet header part of hdr and full payload */ | |
1342 | len = htons(sub_skb->len); | |
1343 | memcpy(skb_push(sub_skb, 2), &len, 2); | |
1344 | memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN); | |
1345 | memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN); | |
1346 | } | |
1347 | ||
1348 | stats->rx_packets++; | |
1349 | stats->rx_bytes += sub_skb->len; | |
1350 | if(is_multicast_ether_addr(dst)) { | |
1351 | stats->multicast++; | |
1352 | } | |
1353 | ||
1354 | /* Indicat the packets to upper layer */ | |
1355 | //printk("0skb_len(%d)\n", skb->len); | |
1356 | sub_skb->protocol = eth_type_trans(sub_skb, dev); | |
1357 | memset(sub_skb->cb, 0, sizeof(sub_skb->cb)); | |
1358 | sub_skb->dev = dev; | |
1359 | sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */ | |
1360 | //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */ | |
1361 | ieee->last_rx_ps_time = jiffies; | |
1362 | //printk("1skb_len(%d)\n", skb->len); | |
1363 | netif_rx(sub_skb); | |
1364 | } | |
1365 | } | |
1366 | kfree(rxb); | |
1367 | rxb = NULL; | |
1368 | ||
1369 | } | |
1370 | else | |
1371 | { | |
1372 | IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__FUNCTION__); | |
1373 | RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum); | |
1374 | } | |
1375 | #ifndef JOHN_NOCPY | |
1376 | dev_kfree_skb(skb); | |
1377 | #endif | |
1378 | ||
1379 | rx_exit: | |
1380 | #ifdef NOT_YET | |
1381 | if (sta) | |
1382 | hostap_handle_sta_release(sta); | |
1383 | #endif | |
1384 | return 1; | |
1385 | ||
1386 | rx_dropped: | |
e72714fb IM |
1387 | kfree(rxb); |
1388 | rxb = NULL; | |
8fc8598e JC |
1389 | stats->rx_dropped++; |
1390 | ||
1391 | /* Returning 0 indicates to caller that we have not handled the SKB-- | |
1392 | * so it is still allocated and can be used again by underlying | |
1393 | * hardware as a DMA target */ | |
1394 | return 0; | |
1395 | } | |
1396 | ||
1397 | #define MGMT_FRAME_FIXED_PART_LENGTH 0x24 | |
1398 | ||
1399 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; | |
1400 | ||
1401 | /* | |
25985edc | 1402 | * Make the structure we read from the beacon packet to have |
8fc8598e JC |
1403 | * the right values |
1404 | */ | |
1405 | static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element | |
1406 | *info_element, int sub_type) | |
1407 | { | |
1408 | ||
1409 | if (info_element->qui_subtype != sub_type) | |
1410 | return -1; | |
1411 | if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN)) | |
1412 | return -1; | |
1413 | if (info_element->qui_type != QOS_OUI_TYPE) | |
1414 | return -1; | |
1415 | if (info_element->version != QOS_VERSION_1) | |
1416 | return -1; | |
1417 | ||
1418 | return 0; | |
1419 | } | |
1420 | ||
1421 | ||
1422 | /* | |
1423 | * Parse a QoS parameter element | |
1424 | */ | |
1425 | static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info | |
1426 | *element_param, struct ieee80211_info_element | |
1427 | *info_element) | |
1428 | { | |
1429 | int ret = 0; | |
1430 | u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2; | |
1431 | ||
1432 | if ((info_element == NULL) || (element_param == NULL)) | |
1433 | return -1; | |
1434 | ||
1435 | if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) { | |
1436 | memcpy(element_param->info_element.qui, info_element->data, | |
1437 | info_element->len); | |
1438 | element_param->info_element.elementID = info_element->id; | |
1439 | element_param->info_element.length = info_element->len; | |
1440 | } else | |
1441 | ret = -1; | |
1442 | if (ret == 0) | |
1443 | ret = ieee80211_verify_qos_info(&element_param->info_element, | |
1444 | QOS_OUI_PARAM_SUB_TYPE); | |
1445 | return ret; | |
1446 | } | |
1447 | ||
1448 | /* | |
1449 | * Parse a QoS information element | |
1450 | */ | |
1451 | static int ieee80211_read_qos_info_element(struct | |
1452 | ieee80211_qos_information_element | |
1453 | *element_info, struct ieee80211_info_element | |
1454 | *info_element) | |
1455 | { | |
1456 | int ret = 0; | |
1457 | u16 size = sizeof(struct ieee80211_qos_information_element) - 2; | |
1458 | ||
1459 | if (element_info == NULL) | |
1460 | return -1; | |
1461 | if (info_element == NULL) | |
1462 | return -1; | |
1463 | ||
1464 | if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) { | |
1465 | memcpy(element_info->qui, info_element->data, | |
1466 | info_element->len); | |
1467 | element_info->elementID = info_element->id; | |
1468 | element_info->length = info_element->len; | |
1469 | } else | |
1470 | ret = -1; | |
1471 | ||
1472 | if (ret == 0) | |
1473 | ret = ieee80211_verify_qos_info(element_info, | |
1474 | QOS_OUI_INFO_SUB_TYPE); | |
1475 | return ret; | |
1476 | } | |
1477 | ||
1478 | ||
1479 | /* | |
1480 | * Write QoS parameters from the ac parameters. | |
1481 | */ | |
1482 | static int ieee80211_qos_convert_ac_to_parameters(struct | |
1483 | ieee80211_qos_parameter_info | |
1484 | *param_elm, struct | |
1485 | ieee80211_qos_parameters | |
1486 | *qos_param) | |
1487 | { | |
1488 | int rc = 0; | |
1489 | int i; | |
1490 | struct ieee80211_qos_ac_parameter *ac_params; | |
1491 | u8 aci; | |
1492 | //u8 cw_min; | |
1493 | //u8 cw_max; | |
1494 | ||
1495 | for (i = 0; i < QOS_QUEUE_NUM; i++) { | |
1496 | ac_params = &(param_elm->ac_params_record[i]); | |
1497 | ||
1498 | aci = (ac_params->aci_aifsn & 0x60) >> 5; | |
1499 | ||
1500 | if(aci >= QOS_QUEUE_NUM) | |
1501 | continue; | |
1502 | qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f; | |
1503 | ||
1504 | /* WMM spec P.11: The minimum value for AIFSN shall be 2 */ | |
1505 | qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci]; | |
1506 | ||
1507 | qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F; | |
1508 | ||
1509 | qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4; | |
1510 | ||
1511 | qos_param->flag[aci] = | |
1512 | (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00; | |
1513 | qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit); | |
1514 | } | |
1515 | return rc; | |
1516 | } | |
1517 | ||
1518 | /* | |
1519 | * we have a generic data element which it may contain QoS information or | |
1520 | * parameters element. check the information element length to decide | |
1521 | * which type to read | |
1522 | */ | |
1523 | static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element | |
1524 | *info_element, | |
1525 | struct ieee80211_network *network) | |
1526 | { | |
1527 | int rc = 0; | |
1528 | struct ieee80211_qos_parameters *qos_param = NULL; | |
1529 | struct ieee80211_qos_information_element qos_info_element; | |
1530 | ||
1531 | rc = ieee80211_read_qos_info_element(&qos_info_element, info_element); | |
1532 | ||
1533 | if (rc == 0) { | |
1534 | network->qos_data.param_count = qos_info_element.ac_info & 0x0F; | |
1535 | network->flags |= NETWORK_HAS_QOS_INFORMATION; | |
1536 | } else { | |
1537 | struct ieee80211_qos_parameter_info param_element; | |
1538 | ||
1539 | rc = ieee80211_read_qos_param_element(¶m_element, | |
1540 | info_element); | |
1541 | if (rc == 0) { | |
1542 | qos_param = &(network->qos_data.parameters); | |
1543 | ieee80211_qos_convert_ac_to_parameters(¶m_element, | |
1544 | qos_param); | |
1545 | network->flags |= NETWORK_HAS_QOS_PARAMETERS; | |
1546 | network->qos_data.param_count = | |
1547 | param_element.info_element.ac_info & 0x0F; | |
1548 | } | |
1549 | } | |
1550 | ||
1551 | if (rc == 0) { | |
1552 | IEEE80211_DEBUG_QOS("QoS is supported\n"); | |
1553 | network->qos_data.supported = 1; | |
1554 | } | |
1555 | return rc; | |
1556 | } | |
1557 | ||
1558 | #ifdef CONFIG_IEEE80211_DEBUG | |
1559 | #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x | |
1560 | ||
1561 | static const char *get_info_element_string(u16 id) | |
1562 | { | |
1563 | switch (id) { | |
1564 | MFIE_STRING(SSID); | |
1565 | MFIE_STRING(RATES); | |
1566 | MFIE_STRING(FH_SET); | |
1567 | MFIE_STRING(DS_SET); | |
1568 | MFIE_STRING(CF_SET); | |
1569 | MFIE_STRING(TIM); | |
1570 | MFIE_STRING(IBSS_SET); | |
1571 | MFIE_STRING(COUNTRY); | |
1572 | MFIE_STRING(HOP_PARAMS); | |
1573 | MFIE_STRING(HOP_TABLE); | |
1574 | MFIE_STRING(REQUEST); | |
1575 | MFIE_STRING(CHALLENGE); | |
1576 | MFIE_STRING(POWER_CONSTRAINT); | |
1577 | MFIE_STRING(POWER_CAPABILITY); | |
1578 | MFIE_STRING(TPC_REQUEST); | |
1579 | MFIE_STRING(TPC_REPORT); | |
1580 | MFIE_STRING(SUPP_CHANNELS); | |
1581 | MFIE_STRING(CSA); | |
1582 | MFIE_STRING(MEASURE_REQUEST); | |
1583 | MFIE_STRING(MEASURE_REPORT); | |
1584 | MFIE_STRING(QUIET); | |
1585 | MFIE_STRING(IBSS_DFS); | |
1586 | // MFIE_STRING(ERP_INFO); | |
1587 | MFIE_STRING(RSN); | |
1588 | MFIE_STRING(RATES_EX); | |
1589 | MFIE_STRING(GENERIC); | |
1590 | MFIE_STRING(QOS_PARAMETER); | |
1591 | default: | |
1592 | return "UNKNOWN"; | |
1593 | } | |
1594 | } | |
1595 | #endif | |
1596 | ||
8fc8598e JC |
1597 | static inline void ieee80211_extract_country_ie( |
1598 | struct ieee80211_device *ieee, | |
1599 | struct ieee80211_info_element *info_element, | |
1600 | struct ieee80211_network *network, | |
1601 | u8 * addr2 | |
1602 | ) | |
1603 | { | |
1604 | if(IS_DOT11D_ENABLE(ieee)) | |
1605 | { | |
1606 | if(info_element->len!= 0) | |
1607 | { | |
1608 | memcpy(network->CountryIeBuf, info_element->data, info_element->len); | |
1609 | network->CountryIeLen = info_element->len; | |
1610 | ||
1611 | if(!IS_COUNTRY_IE_VALID(ieee)) | |
1612 | { | |
1613 | Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data); | |
1614 | } | |
1615 | } | |
1616 | ||
1617 | // | |
1618 | // 070305, rcnjko: I update country IE watch dog here because | |
1619 | // some AP (e.g. Cisco 1242) don't include country IE in their | |
1620 | // probe response frame. | |
1621 | // | |
1622 | if(IS_EQUAL_CIE_SRC(ieee, addr2) ) | |
1623 | { | |
1624 | UPDATE_CIE_WATCHDOG(ieee); | |
1625 | } | |
1626 | } | |
1627 | ||
1628 | } | |
8fc8598e JC |
1629 | |
1630 | int ieee80211_parse_info_param(struct ieee80211_device *ieee, | |
1631 | struct ieee80211_info_element *info_element, | |
1632 | u16 length, | |
1633 | struct ieee80211_network *network, | |
1634 | struct ieee80211_rx_stats *stats) | |
1635 | { | |
1636 | u8 i; | |
1637 | short offset; | |
1638 | u16 tmp_htcap_len=0; | |
1639 | u16 tmp_htinfo_len=0; | |
1640 | u16 ht_realtek_agg_len=0; | |
1641 | u8 ht_realtek_agg_buf[MAX_IE_LEN]; | |
1642 | // u16 broadcom_len = 0; | |
1643 | #ifdef CONFIG_IEEE80211_DEBUG | |
1644 | char rates_str[64]; | |
1645 | char *p; | |
1646 | #endif | |
1647 | ||
1648 | while (length >= sizeof(*info_element)) { | |
1649 | if (sizeof(*info_element) + info_element->len > length) { | |
1650 | IEEE80211_DEBUG_MGMT("Info elem: parse failed: " | |
1651 | "info_element->len + 2 > left : " | |
1652 | "info_element->len+2=%zd left=%d, id=%d.\n", | |
1653 | info_element->len + | |
1654 | sizeof(*info_element), | |
1655 | length, info_element->id); | |
1656 | /* We stop processing but don't return an error here | |
1657 | * because some misbehaviour APs break this rule. ie. | |
1658 | * Orinoco AP1000. */ | |
1659 | break; | |
1660 | } | |
1661 | ||
1662 | switch (info_element->id) { | |
1663 | case MFIE_TYPE_SSID: | |
1664 | if (ieee80211_is_empty_essid(info_element->data, | |
1665 | info_element->len)) { | |
1666 | network->flags |= NETWORK_EMPTY_ESSID; | |
1667 | break; | |
1668 | } | |
1669 | ||
1670 | network->ssid_len = min(info_element->len, | |
1671 | (u8) IW_ESSID_MAX_SIZE); | |
1672 | memcpy(network->ssid, info_element->data, network->ssid_len); | |
1673 | if (network->ssid_len < IW_ESSID_MAX_SIZE) | |
1674 | memset(network->ssid + network->ssid_len, 0, | |
1675 | IW_ESSID_MAX_SIZE - network->ssid_len); | |
1676 | ||
1677 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n", | |
1678 | network->ssid, network->ssid_len); | |
1679 | break; | |
1680 | ||
1681 | case MFIE_TYPE_RATES: | |
1682 | #ifdef CONFIG_IEEE80211_DEBUG | |
1683 | p = rates_str; | |
1684 | #endif | |
1685 | network->rates_len = min(info_element->len, | |
1686 | MAX_RATES_LENGTH); | |
1687 | for (i = 0; i < network->rates_len; i++) { | |
1688 | network->rates[i] = info_element->data[i]; | |
1689 | #ifdef CONFIG_IEEE80211_DEBUG | |
1690 | p += snprintf(p, sizeof(rates_str) - | |
1691 | (p - rates_str), "%02X ", | |
1692 | network->rates[i]); | |
1693 | #endif | |
1694 | if (ieee80211_is_ofdm_rate | |
1695 | (info_element->data[i])) { | |
1696 | network->flags |= NETWORK_HAS_OFDM; | |
1697 | if (info_element->data[i] & | |
1698 | IEEE80211_BASIC_RATE_MASK) | |
1699 | network->flags &= | |
1700 | ~NETWORK_HAS_CCK; | |
1701 | } | |
1702 | } | |
1703 | ||
1704 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n", | |
1705 | rates_str, network->rates_len); | |
1706 | break; | |
1707 | ||
1708 | case MFIE_TYPE_RATES_EX: | |
1709 | #ifdef CONFIG_IEEE80211_DEBUG | |
1710 | p = rates_str; | |
1711 | #endif | |
1712 | network->rates_ex_len = min(info_element->len, | |
1713 | MAX_RATES_EX_LENGTH); | |
1714 | for (i = 0; i < network->rates_ex_len; i++) { | |
1715 | network->rates_ex[i] = info_element->data[i]; | |
1716 | #ifdef CONFIG_IEEE80211_DEBUG | |
1717 | p += snprintf(p, sizeof(rates_str) - | |
1718 | (p - rates_str), "%02X ", | |
1719 | network->rates[i]); | |
1720 | #endif | |
1721 | if (ieee80211_is_ofdm_rate | |
1722 | (info_element->data[i])) { | |
1723 | network->flags |= NETWORK_HAS_OFDM; | |
1724 | if (info_element->data[i] & | |
1725 | IEEE80211_BASIC_RATE_MASK) | |
1726 | network->flags &= | |
1727 | ~NETWORK_HAS_CCK; | |
1728 | } | |
1729 | } | |
1730 | ||
1731 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n", | |
1732 | rates_str, network->rates_ex_len); | |
1733 | break; | |
1734 | ||
1735 | case MFIE_TYPE_DS_SET: | |
1736 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n", | |
1737 | info_element->data[0]); | |
1738 | network->channel = info_element->data[0]; | |
1739 | break; | |
1740 | ||
1741 | case MFIE_TYPE_FH_SET: | |
1742 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n"); | |
1743 | break; | |
1744 | ||
1745 | case MFIE_TYPE_CF_SET: | |
1746 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n"); | |
1747 | break; | |
1748 | ||
1749 | case MFIE_TYPE_TIM: | |
1750 | if(info_element->len < 4) | |
1751 | break; | |
1752 | ||
1753 | network->tim.tim_count = info_element->data[0]; | |
1754 | network->tim.tim_period = info_element->data[1]; | |
1755 | ||
1756 | network->dtim_period = info_element->data[1]; | |
1757 | if(ieee->state != IEEE80211_LINKED) | |
1758 | break; | |
1759 | ||
1760 | network->last_dtim_sta_time[0] = stats->mac_time[0]; | |
1761 | network->last_dtim_sta_time[1] = stats->mac_time[1]; | |
1762 | ||
1763 | network->dtim_data = IEEE80211_DTIM_VALID; | |
1764 | ||
1765 | if(info_element->data[0] != 0) | |
1766 | break; | |
1767 | ||
1768 | if(info_element->data[2] & 1) | |
1769 | network->dtim_data |= IEEE80211_DTIM_MBCAST; | |
1770 | ||
1771 | offset = (info_element->data[2] >> 1)*2; | |
1772 | ||
1773 | //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id); | |
1774 | ||
1775 | if(ieee->assoc_id < 8*offset || | |
1776 | ieee->assoc_id > 8*(offset + info_element->len -3)) | |
1777 | ||
1778 | break; | |
1779 | ||
1780 | offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ; | |
1781 | ||
1782 | if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) | |
1783 | network->dtim_data |= IEEE80211_DTIM_UCAST; | |
1784 | ||
1785 | //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n"); | |
1786 | break; | |
1787 | ||
1788 | case MFIE_TYPE_ERP: | |
1789 | network->erp_value = info_element->data[0]; | |
1790 | network->flags |= NETWORK_HAS_ERP_VALUE; | |
1791 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n", | |
1792 | network->erp_value); | |
1793 | break; | |
1794 | case MFIE_TYPE_IBSS_SET: | |
1795 | network->atim_window = info_element->data[0]; | |
1796 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n", | |
1797 | network->atim_window); | |
1798 | break; | |
1799 | ||
1800 | case MFIE_TYPE_CHALLENGE: | |
1801 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n"); | |
1802 | break; | |
1803 | ||
1804 | case MFIE_TYPE_GENERIC: | |
1805 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n", | |
1806 | info_element->len); | |
1807 | if (!ieee80211_parse_qos_info_param_IE(info_element, | |
1808 | network)) | |
1809 | break; | |
1810 | ||
1811 | if (info_element->len >= 4 && | |
1812 | info_element->data[0] == 0x00 && | |
1813 | info_element->data[1] == 0x50 && | |
1814 | info_element->data[2] == 0xf2 && | |
1815 | info_element->data[3] == 0x01) { | |
1816 | network->wpa_ie_len = min(info_element->len + 2, | |
1817 | MAX_WPA_IE_LEN); | |
1818 | memcpy(network->wpa_ie, info_element, | |
1819 | network->wpa_ie_len); | |
1820 | break; | |
1821 | } | |
1822 | ||
1823 | #ifdef THOMAS_TURBO | |
1824 | if (info_element->len == 7 && | |
1825 | info_element->data[0] == 0x00 && | |
1826 | info_element->data[1] == 0xe0 && | |
1827 | info_element->data[2] == 0x4c && | |
1828 | info_element->data[3] == 0x01 && | |
1829 | info_element->data[4] == 0x02) { | |
1830 | network->Turbo_Enable = 1; | |
1831 | } | |
1832 | #endif | |
1833 | ||
1834 | //for HTcap and HTinfo parameters | |
1835 | if(tmp_htcap_len == 0){ | |
1836 | if(info_element->len >= 4 && | |
1837 | info_element->data[0] == 0x00 && | |
1838 | info_element->data[1] == 0x90 && | |
1839 | info_element->data[2] == 0x4c && | |
1840 | info_element->data[3] == 0x033){ | |
1841 | ||
1842 | tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); | |
1843 | if(tmp_htcap_len != 0){ | |
1844 | network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; | |
1845 | network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ | |
1846 | sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; | |
1847 | memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); | |
1848 | } | |
1849 | } | |
1850 | if(tmp_htcap_len != 0) | |
1851 | network->bssht.bdSupportHT = true; | |
1852 | else | |
1853 | network->bssht.bdSupportHT = false; | |
1854 | } | |
1855 | ||
1856 | ||
1857 | if(tmp_htinfo_len == 0){ | |
1858 | if(info_element->len >= 4 && | |
1859 | info_element->data[0] == 0x00 && | |
1860 | info_element->data[1] == 0x90 && | |
1861 | info_element->data[2] == 0x4c && | |
1862 | info_element->data[3] == 0x034){ | |
1863 | ||
1864 | tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); | |
1865 | if(tmp_htinfo_len != 0){ | |
1866 | network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; | |
1867 | if(tmp_htinfo_len){ | |
1868 | network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\ | |
1869 | sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len; | |
1870 | memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen); | |
1871 | } | |
1872 | ||
1873 | } | |
1874 | ||
1875 | } | |
1876 | } | |
1877 | ||
1878 | if(ieee->aggregation){ | |
1879 | if(network->bssht.bdSupportHT){ | |
1880 | if(info_element->len >= 4 && | |
1881 | info_element->data[0] == 0x00 && | |
1882 | info_element->data[1] == 0xe0 && | |
1883 | info_element->data[2] == 0x4c && | |
1884 | info_element->data[3] == 0x02){ | |
1885 | ||
1886 | ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN); | |
1887 | memcpy(ht_realtek_agg_buf,info_element->data,info_element->len); | |
1888 | ||
1889 | } | |
1890 | if(ht_realtek_agg_len >= 5){ | |
1891 | network->bssht.bdRT2RTAggregation = true; | |
1892 | ||
1893 | if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02)) | |
1894 | network->bssht.bdRT2RTLongSlotTime = true; | |
1895 | } | |
1896 | } | |
1897 | ||
1898 | } | |
1899 | ||
1900 | //if(tmp_htcap_len !=0 || tmp_htinfo_len != 0) | |
1901 | { | |
1902 | if((info_element->len >= 3 && | |
1903 | info_element->data[0] == 0x00 && | |
1904 | info_element->data[1] == 0x05 && | |
1905 | info_element->data[2] == 0xb5) || | |
1906 | (info_element->len >= 3 && | |
1907 | info_element->data[0] == 0x00 && | |
1908 | info_element->data[1] == 0x0a && | |
1909 | info_element->data[2] == 0xf7) || | |
1910 | (info_element->len >= 3 && | |
1911 | info_element->data[0] == 0x00 && | |
1912 | info_element->data[1] == 0x10 && | |
1913 | info_element->data[2] == 0x18)){ | |
1914 | ||
1915 | network->broadcom_cap_exist = true; | |
1916 | ||
1917 | } | |
1918 | } | |
8fc8598e JC |
1919 | if(info_element->len >= 3 && |
1920 | info_element->data[0] == 0x00 && | |
1921 | info_element->data[1] == 0x0c && | |
1922 | info_element->data[2] == 0x43) | |
1923 | { | |
1924 | network->ralink_cap_exist = true; | |
1925 | } | |
1926 | else | |
1927 | network->ralink_cap_exist = false; | |
1928 | //added by amy for atheros AP | |
1929 | if((info_element->len >= 3 && | |
1930 | info_element->data[0] == 0x00 && | |
1931 | info_element->data[1] == 0x03 && | |
1932 | info_element->data[2] == 0x7f) || | |
1933 | (info_element->len >= 3 && | |
1934 | info_element->data[0] == 0x00 && | |
1935 | info_element->data[1] == 0x13 && | |
1936 | info_element->data[2] == 0x74)) | |
1937 | { | |
1938 | printk("========>%s(): athros AP is exist\n",__FUNCTION__); | |
1939 | network->atheros_cap_exist = true; | |
1940 | } | |
1941 | else | |
1942 | network->atheros_cap_exist = false; | |
1943 | ||
1944 | if(info_element->len >= 3 && | |
1945 | info_element->data[0] == 0x00 && | |
1946 | info_element->data[1] == 0x40 && | |
1947 | info_element->data[2] == 0x96) | |
1948 | { | |
1949 | network->cisco_cap_exist = true; | |
1950 | } | |
1951 | else | |
1952 | network->cisco_cap_exist = false; | |
1953 | //added by amy for LEAP of cisco | |
1954 | if(info_element->len > 4 && | |
1955 | info_element->data[0] == 0x00 && | |
1956 | info_element->data[1] == 0x40 && | |
1957 | info_element->data[2] == 0x96 && | |
1958 | info_element->data[3] == 0x01) | |
1959 | { | |
1960 | if(info_element->len == 6) | |
1961 | { | |
1962 | memcpy(network->CcxRmState, &info_element[4], 2); | |
1963 | if(network->CcxRmState[0] != 0) | |
1964 | { | |
1965 | network->bCcxRmEnable = true; | |
1966 | } | |
1967 | else | |
1968 | network->bCcxRmEnable = false; | |
1969 | // | |
1970 | // CCXv4 Table 59-1 MBSSID Masks. | |
1971 | // | |
1972 | network->MBssidMask = network->CcxRmState[1] & 0x07; | |
1973 | if(network->MBssidMask != 0) | |
1974 | { | |
1975 | network->bMBssidValid = true; | |
1976 | network->MBssidMask = 0xff << (network->MBssidMask); | |
1977 | cpMacAddr(network->MBssid, network->bssid); | |
1978 | network->MBssid[5] &= network->MBssidMask; | |
1979 | } | |
1980 | else | |
1981 | { | |
1982 | network->bMBssidValid = false; | |
1983 | } | |
1984 | } | |
1985 | else | |
1986 | { | |
1987 | network->bCcxRmEnable = false; | |
1988 | } | |
1989 | } | |
1990 | if(info_element->len > 4 && | |
1991 | info_element->data[0] == 0x00 && | |
1992 | info_element->data[1] == 0x40 && | |
1993 | info_element->data[2] == 0x96 && | |
1994 | info_element->data[3] == 0x03) | |
1995 | { | |
1996 | if(info_element->len == 5) | |
1997 | { | |
1998 | network->bWithCcxVerNum = true; | |
1999 | network->BssCcxVerNumber = info_element->data[4]; | |
2000 | } | |
2001 | else | |
2002 | { | |
2003 | network->bWithCcxVerNum = false; | |
2004 | network->BssCcxVerNumber = 0; | |
2005 | } | |
2006 | } | |
2007 | break; | |
2008 | ||
2009 | case MFIE_TYPE_RSN: | |
2010 | IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n", | |
2011 | info_element->len); | |
2012 | network->rsn_ie_len = min(info_element->len + 2, | |
2013 | MAX_WPA_IE_LEN); | |
2014 | memcpy(network->rsn_ie, info_element, | |
2015 | network->rsn_ie_len); | |
2016 | break; | |
2017 | ||
2018 | //HT related element. | |
2019 | case MFIE_TYPE_HT_CAP: | |
2020 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n", | |
2021 | info_element->len); | |
2022 | tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); | |
2023 | if(tmp_htcap_len != 0){ | |
2024 | network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; | |
2025 | network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ | |
2026 | sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; | |
2027 | memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); | |
2028 | ||
2029 | //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT() | |
2030 | // windows driver will update WMM parameters each beacon received once connected | |
2031 | // Linux driver is a bit different. | |
2032 | network->bssht.bdSupportHT = true; | |
2033 | } | |
2034 | else | |
2035 | network->bssht.bdSupportHT = false; | |
2036 | break; | |
2037 | ||
2038 | ||
2039 | case MFIE_TYPE_HT_INFO: | |
2040 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n", | |
2041 | info_element->len); | |
2042 | tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); | |
2043 | if(tmp_htinfo_len){ | |
2044 | network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE; | |
2045 | network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\ | |
2046 | sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len; | |
2047 | memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen); | |
2048 | } | |
2049 | break; | |
2050 | ||
2051 | case MFIE_TYPE_AIRONET: | |
2052 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n", | |
2053 | info_element->len); | |
2054 | if(info_element->len >IE_CISCO_FLAG_POSITION) | |
2055 | { | |
2056 | network->bWithAironetIE = true; | |
2057 | ||
2058 | // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23): | |
2059 | // "A Cisco access point advertises support for CKIP in beacon and probe response packets, | |
2060 | // by adding an Aironet element and setting one or both of the CKIP negotiation bits." | |
2061 | if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) || | |
2062 | (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) ) | |
2063 | { | |
2064 | network->bCkipSupported = true; | |
2065 | } | |
2066 | else | |
2067 | { | |
2068 | network->bCkipSupported = false; | |
2069 | } | |
2070 | } | |
2071 | else | |
2072 | { | |
2073 | network->bWithAironetIE = false; | |
2074 | network->bCkipSupported = false; | |
2075 | } | |
2076 | break; | |
2077 | case MFIE_TYPE_QOS_PARAMETER: | |
2078 | printk(KERN_ERR | |
2079 | "QoS Error need to parse QOS_PARAMETER IE\n"); | |
2080 | break; | |
2081 | ||
8fc8598e JC |
2082 | case MFIE_TYPE_COUNTRY: |
2083 | IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n", | |
2084 | info_element->len); | |
2085 | //printk("=====>Receive <%s> Country IE\n",network->ssid); | |
2086 | ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP | |
2087 | break; | |
8fc8598e | 2088 | /* TODO */ |
8fc8598e JC |
2089 | default: |
2090 | IEEE80211_DEBUG_MGMT | |
2091 | ("Unsupported info element: %s (%d)\n", | |
2092 | get_info_element_string(info_element->id), | |
2093 | info_element->id); | |
2094 | break; | |
2095 | } | |
2096 | ||
2097 | length -= sizeof(*info_element) + info_element->len; | |
2098 | info_element = | |
2099 | (struct ieee80211_info_element *)&info_element-> | |
2100 | data[info_element->len]; | |
2101 | } | |
2102 | ||
2103 | if(!network->atheros_cap_exist && !network->broadcom_cap_exist && | |
2104 | !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation) | |
2105 | { | |
2106 | network->unknown_cap_exist = true; | |
2107 | } | |
2108 | else | |
2109 | { | |
2110 | network->unknown_cap_exist = false; | |
2111 | } | |
2112 | return 0; | |
2113 | } | |
2114 | ||
2115 | static inline u8 ieee80211_SignalStrengthTranslate( | |
2116 | u8 CurrSS | |
2117 | ) | |
2118 | { | |
2119 | u8 RetSS; | |
2120 | ||
2121 | // Step 1. Scale mapping. | |
2122 | if(CurrSS >= 71 && CurrSS <= 100) | |
2123 | { | |
2124 | RetSS = 90 + ((CurrSS - 70) / 3); | |
2125 | } | |
2126 | else if(CurrSS >= 41 && CurrSS <= 70) | |
2127 | { | |
2128 | RetSS = 78 + ((CurrSS - 40) / 3); | |
2129 | } | |
2130 | else if(CurrSS >= 31 && CurrSS <= 40) | |
2131 | { | |
2132 | RetSS = 66 + (CurrSS - 30); | |
2133 | } | |
2134 | else if(CurrSS >= 21 && CurrSS <= 30) | |
2135 | { | |
2136 | RetSS = 54 + (CurrSS - 20); | |
2137 | } | |
2138 | else if(CurrSS >= 5 && CurrSS <= 20) | |
2139 | { | |
2140 | RetSS = 42 + (((CurrSS - 5) * 2) / 3); | |
2141 | } | |
2142 | else if(CurrSS == 4) | |
2143 | { | |
2144 | RetSS = 36; | |
2145 | } | |
2146 | else if(CurrSS == 3) | |
2147 | { | |
2148 | RetSS = 27; | |
2149 | } | |
2150 | else if(CurrSS == 2) | |
2151 | { | |
2152 | RetSS = 18; | |
2153 | } | |
2154 | else if(CurrSS == 1) | |
2155 | { | |
2156 | RetSS = 9; | |
2157 | } | |
2158 | else | |
2159 | { | |
2160 | RetSS = CurrSS; | |
2161 | } | |
2162 | //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS)); | |
2163 | ||
2164 | // Step 2. Smoothing. | |
2165 | ||
2166 | //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS)); | |
2167 | ||
2168 | return RetSS; | |
2169 | } | |
2170 | ||
2171 | long ieee80211_translate_todbm(u8 signal_strength_index )// 0-100 index. | |
2172 | { | |
2173 | long signal_power; // in dBm. | |
2174 | ||
2175 | // Translate to dBm (x=0.5y-95). | |
2176 | signal_power = (long)((signal_strength_index + 1) >> 1); | |
2177 | signal_power -= 95; | |
2178 | ||
2179 | return signal_power; | |
2180 | } | |
2181 | ||
2182 | static inline int ieee80211_network_init( | |
2183 | struct ieee80211_device *ieee, | |
2184 | struct ieee80211_probe_response *beacon, | |
2185 | struct ieee80211_network *network, | |
2186 | struct ieee80211_rx_stats *stats) | |
2187 | { | |
2188 | #ifdef CONFIG_IEEE80211_DEBUG | |
2189 | //char rates_str[64]; | |
2190 | //char *p; | |
2191 | #endif | |
2192 | ||
2193 | network->qos_data.active = 0; | |
2194 | network->qos_data.supported = 0; | |
2195 | network->qos_data.param_count = 0; | |
2196 | network->qos_data.old_param_count = 0; | |
2197 | ||
2198 | /* Pull out fixed field data */ | |
2199 | memcpy(network->bssid, beacon->header.addr3, ETH_ALEN); | |
2200 | network->capability = le16_to_cpu(beacon->capability); | |
2201 | network->last_scanned = jiffies; | |
2202 | network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]); | |
2203 | network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]); | |
2204 | network->beacon_interval = le32_to_cpu(beacon->beacon_interval); | |
2205 | /* Where to pull this? beacon->listen_interval;*/ | |
2206 | network->listen_interval = 0x0A; | |
2207 | network->rates_len = network->rates_ex_len = 0; | |
2208 | network->last_associate = 0; | |
2209 | network->ssid_len = 0; | |
2210 | network->flags = 0; | |
2211 | network->atim_window = 0; | |
2212 | network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ? | |
2213 | 0x3 : 0x0; | |
2214 | network->berp_info_valid = false; | |
2215 | network->broadcom_cap_exist = false; | |
2216 | network->ralink_cap_exist = false; | |
2217 | network->atheros_cap_exist = false; | |
2218 | network->cisco_cap_exist = false; | |
2219 | network->unknown_cap_exist = false; | |
2220 | #ifdef THOMAS_TURBO | |
2221 | network->Turbo_Enable = 0; | |
2222 | #endif | |
8fc8598e JC |
2223 | network->CountryIeLen = 0; |
2224 | memset(network->CountryIeBuf, 0, MAX_IE_LEN); | |
8fc8598e JC |
2225 | //Initialize HT parameters |
2226 | //ieee80211_ht_initialize(&network->bssht); | |
2227 | HTInitializeBssDesc(&network->bssht); | |
2228 | if (stats->freq == IEEE80211_52GHZ_BAND) { | |
2229 | /* for A band (No DS info) */ | |
2230 | network->channel = stats->received_channel; | |
2231 | } else | |
2232 | network->flags |= NETWORK_HAS_CCK; | |
2233 | ||
2234 | network->wpa_ie_len = 0; | |
2235 | network->rsn_ie_len = 0; | |
2236 | ||
2237 | if (ieee80211_parse_info_param | |
2238 | (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats)) | |
2239 | return 1; | |
2240 | ||
2241 | network->mode = 0; | |
2242 | if (stats->freq == IEEE80211_52GHZ_BAND) | |
2243 | network->mode = IEEE_A; | |
2244 | else { | |
2245 | if (network->flags & NETWORK_HAS_OFDM) | |
2246 | network->mode |= IEEE_G; | |
2247 | if (network->flags & NETWORK_HAS_CCK) | |
2248 | network->mode |= IEEE_B; | |
2249 | } | |
2250 | ||
2251 | if (network->mode == 0) { | |
0ee9f67c | 2252 | IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' " |
8fc8598e JC |
2253 | "network.\n", |
2254 | escape_essid(network->ssid, | |
2255 | network->ssid_len), | |
0ee9f67c | 2256 | network->bssid); |
8fc8598e JC |
2257 | return 1; |
2258 | } | |
2259 | ||
2260 | if(network->bssht.bdSupportHT){ | |
2261 | if(network->mode == IEEE_A) | |
2262 | network->mode = IEEE_N_5G; | |
2263 | else if(network->mode & (IEEE_G | IEEE_B)) | |
2264 | network->mode = IEEE_N_24G; | |
2265 | } | |
2266 | if (ieee80211_is_empty_essid(network->ssid, network->ssid_len)) | |
2267 | network->flags |= NETWORK_EMPTY_ESSID; | |
2268 | ||
8fc8598e JC |
2269 | stats->signal = 30 + (stats->SignalStrength * 70) / 100; |
2270 | //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal); | |
2271 | stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25; | |
8fc8598e JC |
2272 | |
2273 | memcpy(&network->stats, stats, sizeof(network->stats)); | |
2274 | ||
2275 | return 0; | |
2276 | } | |
2277 | ||
2278 | static inline int is_same_network(struct ieee80211_network *src, | |
2279 | struct ieee80211_network *dst, struct ieee80211_device* ieee) | |
2280 | { | |
2281 | /* A network is only a duplicate if the channel, BSSID, ESSID | |
2282 | * and the capability field (in particular IBSS and BSS) all match. | |
2283 | * We treat all <hidden> with the same BSSID and channel | |
2284 | * as one network */ | |
2285 | return //((src->ssid_len == dst->ssid_len) && | |
2286 | (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && | |
2287 | (src->channel == dst->channel) && | |
2288 | !memcmp(src->bssid, dst->bssid, ETH_ALEN) && | |
2289 | //!memcmp(src->ssid, dst->ssid, src->ssid_len) && | |
2290 | (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && | |
2291 | ((src->capability & WLAN_CAPABILITY_IBSS) == | |
2292 | (dst->capability & WLAN_CAPABILITY_IBSS)) && | |
2293 | ((src->capability & WLAN_CAPABILITY_BSS) == | |
2294 | (dst->capability & WLAN_CAPABILITY_BSS))); | |
2295 | } | |
2296 | ||
2297 | static inline void update_network(struct ieee80211_network *dst, | |
2298 | struct ieee80211_network *src) | |
2299 | { | |
2300 | int qos_active; | |
2301 | u8 old_param; | |
2302 | ||
2303 | memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats)); | |
2304 | dst->capability = src->capability; | |
2305 | memcpy(dst->rates, src->rates, src->rates_len); | |
2306 | dst->rates_len = src->rates_len; | |
2307 | memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len); | |
2308 | dst->rates_ex_len = src->rates_ex_len; | |
2309 | if(src->ssid_len > 0) | |
2310 | { | |
2311 | memset(dst->ssid, 0, dst->ssid_len); | |
2312 | dst->ssid_len = src->ssid_len; | |
2313 | memcpy(dst->ssid, src->ssid, src->ssid_len); | |
2314 | } | |
2315 | dst->mode = src->mode; | |
2316 | dst->flags = src->flags; | |
2317 | dst->time_stamp[0] = src->time_stamp[0]; | |
2318 | dst->time_stamp[1] = src->time_stamp[1]; | |
2319 | if (src->flags & NETWORK_HAS_ERP_VALUE) | |
2320 | { | |
2321 | dst->erp_value = src->erp_value; | |
2322 | dst->berp_info_valid = src->berp_info_valid = true; | |
2323 | } | |
2324 | dst->beacon_interval = src->beacon_interval; | |
2325 | dst->listen_interval = src->listen_interval; | |
2326 | dst->atim_window = src->atim_window; | |
2327 | dst->dtim_period = src->dtim_period; | |
2328 | dst->dtim_data = src->dtim_data; | |
2329 | dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0]; | |
2330 | dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1]; | |
2331 | memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters)); | |
2332 | ||
2333 | dst->bssht.bdSupportHT = src->bssht.bdSupportHT; | |
2334 | dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation; | |
2335 | dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen; | |
2336 | memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen); | |
2337 | dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen; | |
2338 | memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen); | |
2339 | dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer; | |
2340 | dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime; | |
2341 | dst->broadcom_cap_exist = src->broadcom_cap_exist; | |
2342 | dst->ralink_cap_exist = src->ralink_cap_exist; | |
2343 | dst->atheros_cap_exist = src->atheros_cap_exist; | |
2344 | dst->cisco_cap_exist = src->cisco_cap_exist; | |
2345 | dst->unknown_cap_exist = src->unknown_cap_exist; | |
2346 | memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len); | |
2347 | dst->wpa_ie_len = src->wpa_ie_len; | |
2348 | memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len); | |
2349 | dst->rsn_ie_len = src->rsn_ie_len; | |
2350 | ||
2351 | dst->last_scanned = jiffies; | |
2352 | /* qos related parameters */ | |
2353 | //qos_active = src->qos_data.active; | |
2354 | qos_active = dst->qos_data.active; | |
2355 | //old_param = dst->qos_data.old_param_count; | |
2356 | old_param = dst->qos_data.param_count; | |
2357 | if(dst->flags & NETWORK_HAS_QOS_MASK) | |
2358 | memcpy(&dst->qos_data, &src->qos_data, | |
2359 | sizeof(struct ieee80211_qos_data)); | |
2360 | else { | |
2361 | dst->qos_data.supported = src->qos_data.supported; | |
2362 | dst->qos_data.param_count = src->qos_data.param_count; | |
2363 | } | |
2364 | ||
2365 | if(dst->qos_data.supported == 1) { | |
2366 | dst->QoS_Enable = 1; | |
2367 | if(dst->ssid_len) | |
2368 | IEEE80211_DEBUG_QOS | |
2369 | ("QoS the network %s is QoS supported\n", | |
2370 | dst->ssid); | |
2371 | else | |
2372 | IEEE80211_DEBUG_QOS | |
2373 | ("QoS the network is QoS supported\n"); | |
2374 | } | |
2375 | dst->qos_data.active = qos_active; | |
2376 | dst->qos_data.old_param_count = old_param; | |
2377 | ||
2378 | /* dst->last_associate is not overwritten */ | |
8fc8598e JC |
2379 | dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame. |
2380 | if(src->wmm_param[0].ac_aci_acm_aifsn|| \ | |
2381 | src->wmm_param[1].ac_aci_acm_aifsn|| \ | |
2382 | src->wmm_param[2].ac_aci_acm_aifsn|| \ | |
4498dbcd | 2383 | src->wmm_param[3].ac_aci_acm_aifsn) { |
8fc8598e JC |
2384 | memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN); |
2385 | } | |
2386 | //dst->QoS_Enable = src->QoS_Enable; | |
8fc8598e JC |
2387 | #ifdef THOMAS_TURBO |
2388 | dst->Turbo_Enable = src->Turbo_Enable; | |
2389 | #endif | |
2390 | ||
8fc8598e JC |
2391 | dst->CountryIeLen = src->CountryIeLen; |
2392 | memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen); | |
8fc8598e JC |
2393 | |
2394 | //added by amy for LEAP | |
2395 | dst->bWithAironetIE = src->bWithAironetIE; | |
2396 | dst->bCkipSupported = src->bCkipSupported; | |
2397 | memcpy(dst->CcxRmState,src->CcxRmState,2); | |
2398 | dst->bCcxRmEnable = src->bCcxRmEnable; | |
2399 | dst->MBssidMask = src->MBssidMask; | |
2400 | dst->bMBssidValid = src->bMBssidValid; | |
2401 | memcpy(dst->MBssid,src->MBssid,6); | |
2402 | dst->bWithCcxVerNum = src->bWithCcxVerNum; | |
2403 | dst->BssCcxVerNumber = src->BssCcxVerNumber; | |
2404 | ||
2405 | } | |
2406 | ||
2407 | static inline int is_beacon(__le16 fc) | |
2408 | { | |
2409 | return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON); | |
2410 | } | |
2411 | ||
2412 | static inline void ieee80211_process_probe_response( | |
2413 | struct ieee80211_device *ieee, | |
2414 | struct ieee80211_probe_response *beacon, | |
2415 | struct ieee80211_rx_stats *stats) | |
2416 | { | |
2417 | struct ieee80211_network network; | |
2418 | struct ieee80211_network *target; | |
2419 | struct ieee80211_network *oldest = NULL; | |
2420 | #ifdef CONFIG_IEEE80211_DEBUG | |
2421 | struct ieee80211_info_element *info_element = &beacon->info_element[0]; | |
2422 | #endif | |
2423 | unsigned long flags; | |
2424 | short renew; | |
2425 | //u8 wmm_info; | |
2426 | ||
2427 | memset(&network, 0, sizeof(struct ieee80211_network)); | |
2428 | IEEE80211_DEBUG_SCAN( | |
0ee9f67c | 2429 | "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n", |
8fc8598e | 2430 | escape_essid(info_element->data, info_element->len), |
0ee9f67c | 2431 | beacon->header.addr3, |
8fc8598e JC |
2432 | (beacon->capability & (1<<0xf)) ? '1' : '0', |
2433 | (beacon->capability & (1<<0xe)) ? '1' : '0', | |
2434 | (beacon->capability & (1<<0xd)) ? '1' : '0', | |
2435 | (beacon->capability & (1<<0xc)) ? '1' : '0', | |
2436 | (beacon->capability & (1<<0xb)) ? '1' : '0', | |
2437 | (beacon->capability & (1<<0xa)) ? '1' : '0', | |
2438 | (beacon->capability & (1<<0x9)) ? '1' : '0', | |
2439 | (beacon->capability & (1<<0x8)) ? '1' : '0', | |
2440 | (beacon->capability & (1<<0x7)) ? '1' : '0', | |
2441 | (beacon->capability & (1<<0x6)) ? '1' : '0', | |
2442 | (beacon->capability & (1<<0x5)) ? '1' : '0', | |
2443 | (beacon->capability & (1<<0x4)) ? '1' : '0', | |
2444 | (beacon->capability & (1<<0x3)) ? '1' : '0', | |
2445 | (beacon->capability & (1<<0x2)) ? '1' : '0', | |
2446 | (beacon->capability & (1<<0x1)) ? '1' : '0', | |
2447 | (beacon->capability & (1<<0x0)) ? '1' : '0'); | |
2448 | ||
2449 | if (ieee80211_network_init(ieee, beacon, &network, stats)) { | |
0ee9f67c | 2450 | IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n", |
8fc8598e JC |
2451 | escape_essid(info_element->data, |
2452 | info_element->len), | |
0ee9f67c | 2453 | beacon->header.addr3, |
8fc8598e JC |
2454 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == |
2455 | IEEE80211_STYPE_PROBE_RESP ? | |
2456 | "PROBE RESPONSE" : "BEACON"); | |
2457 | return; | |
2458 | } | |
2459 | ||
8fc8598e JC |
2460 | // For Asus EeePc request, |
2461 | // (1) if wireless adapter receive get any 802.11d country code in AP beacon, | |
2462 | // wireless adapter should follow the country code. | |
2463 | // (2) If there is no any country code in beacon, | |
2464 | // then wireless adapter should do active scan from ch1~11 and | |
2465 | // passive scan from ch12~14 | |
2466 | ||
2467 | if( !IsLegalChannel(ieee, network.channel) ) | |
2468 | return; | |
2469 | if(ieee->bGlobalDomain) | |
2470 | { | |
2471 | if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP) | |
2472 | { | |
2473 | // Case 1: Country code | |
2474 | if(IS_COUNTRY_IE_VALID(ieee) ) | |
2475 | { | |
2476 | if( !IsLegalChannel(ieee, network.channel) ) | |
2477 | { | |
2478 | printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel); | |
2479 | return; | |
2480 | } | |
2481 | } | |
2482 | // Case 2: No any country code. | |
2483 | else | |
2484 | { | |
2485 | // Filter over channel ch12~14 | |
2486 | if(network.channel > 11) | |
2487 | { | |
2488 | printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel); | |
2489 | return; | |
2490 | } | |
2491 | } | |
2492 | } | |
2493 | else | |
2494 | { | |
2495 | // Case 1: Country code | |
2496 | if(IS_COUNTRY_IE_VALID(ieee) ) | |
2497 | { | |
2498 | if( !IsLegalChannel(ieee, network.channel) ) | |
2499 | { | |
2500 | printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel); | |
2501 | return; | |
2502 | } | |
2503 | } | |
2504 | // Case 2: No any country code. | |
2505 | else | |
2506 | { | |
2507 | // Filter over channel ch12~14 | |
2508 | if(network.channel > 14) | |
2509 | { | |
2510 | printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network.channel); | |
2511 | return; | |
2512 | } | |
2513 | } | |
2514 | } | |
2515 | } | |
8fc8598e JC |
2516 | |
2517 | /* The network parsed correctly -- so now we scan our known networks | |
2518 | * to see if we can find it in our list. | |
2519 | * | |
2520 | * NOTE: This search is definitely not optimized. Once its doing | |
2521 | * the "right thing" we'll optimize it for efficiency if | |
2522 | * necessary */ | |
2523 | ||
2524 | /* Search for this entry in the list and update it if it is | |
2525 | * already there. */ | |
2526 | ||
2527 | spin_lock_irqsave(&ieee->lock, flags); | |
2528 | ||
2529 | if(is_same_network(&ieee->current_network, &network, ieee)) { | |
2530 | update_network(&ieee->current_network, &network); | |
2531 | if((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G) | |
2532 | && ieee->current_network.berp_info_valid){ | |
2533 | if(ieee->current_network.erp_value& ERP_UseProtection) | |
2534 | ieee->current_network.buseprotection = true; | |
2535 | else | |
2536 | ieee->current_network.buseprotection = false; | |
2537 | } | |
2538 | if(is_beacon(beacon->header.frame_ctl)) | |
2539 | { | |
2540 | if(ieee->state == IEEE80211_LINKED) | |
2541 | ieee->LinkDetectInfo.NumRecvBcnInPeriod++; | |
2542 | } | |
2543 | else //hidden AP | |
2544 | network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags); | |
2545 | } | |
2546 | ||
2547 | list_for_each_entry(target, &ieee->network_list, list) { | |
2548 | if (is_same_network(target, &network, ieee)) | |
2549 | break; | |
2550 | if ((oldest == NULL) || | |
2551 | (target->last_scanned < oldest->last_scanned)) | |
2552 | oldest = target; | |
2553 | } | |
2554 | ||
2555 | /* If we didn't find a match, then get a new network slot to initialize | |
2556 | * with this beacon's information */ | |
2557 | if (&target->list == &ieee->network_list) { | |
2558 | if (list_empty(&ieee->network_free_list)) { | |
2559 | /* If there are no more slots, expire the oldest */ | |
2560 | list_del(&oldest->list); | |
2561 | target = oldest; | |
0ee9f67c | 2562 | IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from " |
8fc8598e JC |
2563 | "network list.\n", |
2564 | escape_essid(target->ssid, | |
2565 | target->ssid_len), | |
0ee9f67c | 2566 | target->bssid); |
8fc8598e JC |
2567 | } else { |
2568 | /* Otherwise just pull from the free list */ | |
2569 | target = list_entry(ieee->network_free_list.next, | |
2570 | struct ieee80211_network, list); | |
2571 | list_del(ieee->network_free_list.next); | |
2572 | } | |
2573 | ||
2574 | ||
2575 | #ifdef CONFIG_IEEE80211_DEBUG | |
0ee9f67c | 2576 | IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n", |
8fc8598e JC |
2577 | escape_essid(network.ssid, |
2578 | network.ssid_len), | |
0ee9f67c | 2579 | network.bssid, |
8fc8598e JC |
2580 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == |
2581 | IEEE80211_STYPE_PROBE_RESP ? | |
2582 | "PROBE RESPONSE" : "BEACON"); | |
2583 | #endif | |
2584 | memcpy(target, &network, sizeof(*target)); | |
2585 | list_add_tail(&target->list, &ieee->network_list); | |
2586 | if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) | |
2587 | ieee80211_softmac_new_net(ieee,&network); | |
2588 | } else { | |
0ee9f67c | 2589 | IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n", |
8fc8598e JC |
2590 | escape_essid(target->ssid, |
2591 | target->ssid_len), | |
0ee9f67c | 2592 | target->bssid, |
8fc8598e JC |
2593 | WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == |
2594 | IEEE80211_STYPE_PROBE_RESP ? | |
2595 | "PROBE RESPONSE" : "BEACON"); | |
2596 | ||
2597 | /* we have an entry and we are going to update it. But this entry may | |
2598 | * be already expired. In this case we do the same as we found a new | |
2599 | * net and call the new_net handler | |
2600 | */ | |
2601 | renew = !time_after(target->last_scanned + ieee->scan_age, jiffies); | |
2602 | //YJ,add,080819,for hidden ap | |
2603 | if(is_beacon(beacon->header.frame_ctl) == 0) | |
2604 | network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags); | |
2605 | //if(strncmp(network.ssid, "linksys-c",9) == 0) | |
2606 | // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags); | |
2607 | if(((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \ | |
2608 | && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\ | |
2609 | ||((ieee->current_network.ssid_len == network.ssid_len)&&(strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK)))) | |
2610 | renew = 1; | |
2611 | //YJ,add,080819,for hidden ap,end | |
2612 | ||
2613 | update_network(target, &network); | |
2614 | if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)) | |
2615 | ieee80211_softmac_new_net(ieee,&network); | |
2616 | } | |
2617 | ||
2618 | spin_unlock_irqrestore(&ieee->lock, flags); | |
2619 | if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, &network, ieee)&&\ | |
2620 | (ieee->state == IEEE80211_LINKED)) { | |
2621 | if(ieee->handle_beacon != NULL) { | |
2622 | ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network); | |
2623 | } | |
2624 | } | |
2625 | } | |
2626 | ||
2627 | void ieee80211_rx_mgt(struct ieee80211_device *ieee, | |
2628 | struct ieee80211_hdr_4addr *header, | |
2629 | struct ieee80211_rx_stats *stats) | |
2630 | { | |
2631 | switch (WLAN_FC_GET_STYPE(header->frame_ctl)) { | |
2632 | ||
2633 | case IEEE80211_STYPE_BEACON: | |
2634 | IEEE80211_DEBUG_MGMT("received BEACON (%d)\n", | |
2635 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
2636 | IEEE80211_DEBUG_SCAN("Beacon\n"); | |
2637 | ieee80211_process_probe_response( | |
2638 | ieee, (struct ieee80211_probe_response *)header, stats); | |
2639 | break; | |
2640 | ||
2641 | case IEEE80211_STYPE_PROBE_RESP: | |
2642 | IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n", | |
2643 | WLAN_FC_GET_STYPE(header->frame_ctl)); | |
2644 | IEEE80211_DEBUG_SCAN("Probe response\n"); | |
2645 | ieee80211_process_probe_response( | |
2646 | ieee, (struct ieee80211_probe_response *)header, stats); | |
2647 | break; | |
2648 | ||
2649 | } | |
2650 | } | |
2651 | ||
8fc8598e JC |
2652 | EXPORT_SYMBOL(ieee80211_rx_mgt); |
2653 | EXPORT_SYMBOL(ieee80211_rx); |