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