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