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