blob: 7f033815f2429d8e2c0d85452690e5a5bcd8534d [file] [log] [blame]
Larry Finger94a79942011-08-23 19:00:42 -05001/*
2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <jkmaline@cc.hut.fi>
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
13 * more details.
14 ******************************************************************************
15
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
18
19 A special thanks goes to Realtek for their support !
20
21******************************************************************************/
22
23
24#include <linux/compiler.h>
25#include <linux/errno.h>
26#include <linux/if_arp.h>
27#include <linux/in6.h>
28#include <linux/in.h>
29#include <linux/ip.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/netdevice.h>
33#include <linux/pci.h>
34#include <linux/proc_fs.h>
35#include <linux/skbuff.h>
36#include <linux/slab.h>
37#include <linux/tcp.h>
38#include <linux/types.h>
39#include <linux/version.h>
40#include <linux/wireless.h>
41#include <linux/etherdevice.h>
42#include <asm/uaccess.h>
43#include <linux/ctype.h>
44
45#include "rtllib.h"
46#ifdef ENABLE_DOT11D
47#include "dot11d.h"
48#endif
49
Larry Finger94a79942011-08-23 19:00:42 -050050#if defined CONFIG_CFG_80211
51#include <linux/crc32.h>
52
53struct ieee80211_channel *rtllib_get_channel(struct wiphy *wiphy,
54 int freq)
55{
56 enum ieee80211_band band;
57 struct ieee80211_supported_band *sband;
58 int i;
59
60 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
61 sband = wiphy->bands[band];
62
63 if (!sband)
64 continue;
65
66 for (i = 0; i < sband->n_channels; i++) {
67 if (sband->channels[i].center_freq == freq)
68 return &sband->channels[i];
69 }
70 }
71
72 return NULL;
73}
74
75int rtllib_channel_to_frequency(int chan)
76{
77 if (chan < 14)
78 return 2407 + chan * 5;
79
80 if (chan == 14)
81 return 2484;
82
83 /* FIXME: 802.11j 17.3.8.3.2 */
84 return (chan + 1000) * 5;
85}
86
87u32 rtllib_parse_elems_crc(u8 *start, size_t len,
88 struct ieee802_11_elems *elems,
89 u64 filter, u32 crc)
90{
91 size_t left = len;
92 u8 *pos = start;
93 bool calc_crc = filter != 0;
94
95 memset(elems, 0, sizeof(*elems));
96 elems->ie_start = start;
97 elems->total_len = len;
98
99 while (left >= 2) {
100 u8 id, elen;
101
102 id = *pos++;
103 elen = *pos++;
104 left -= 2;
105
106 if (elen > left)
107 break;
108
109 if (calc_crc && id < 64 && (filter & BIT(id)))
110 crc = crc32_be(crc, pos - 2, elen + 2);
111
112 switch (id) {
113 case WLAN_EID_SSID:
114 elems->ssid = pos;
115 elems->ssid_len = elen;
116 break;
117 case WLAN_EID_SUPP_RATES:
118 elems->supp_rates = pos;
119 elems->supp_rates_len = elen;
120 break;
121 case WLAN_EID_FH_PARAMS:
122 elems->fh_params = pos;
123 elems->fh_params_len = elen;
124 break;
125 case WLAN_EID_DS_PARAMS:
126 elems->ds_params = pos;
127 elems->ds_params_len = elen;
128 break;
129 case WLAN_EID_CF_PARAMS:
130 elems->cf_params = pos;
131 elems->cf_params_len = elen;
132 break;
133 case WLAN_EID_TIM:
134 if (elen >= sizeof(struct ieee80211_tim_ie)) {
135 elems->tim = (void *)pos;
136 elems->tim_len = elen;
137 }
138 break;
139 case WLAN_EID_IBSS_PARAMS:
140 elems->ibss_params = pos;
141 elems->ibss_params_len = elen;
142 break;
143 case WLAN_EID_CHALLENGE:
144 elems->challenge = pos;
145 elems->challenge_len = elen;
146 break;
147 case WLAN_EID_VENDOR_SPECIFIC:
148 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
149 pos[2] == 0xf2) {
150 /* Microsoft OUI (00:50:F2) */
151
152 if (calc_crc)
153 crc = crc32_be(crc, pos - 2, elen + 2);
154
155 if (pos[3] == 1) {
156 /* OUI Type 1 - WPA IE */
157 elems->wpa = pos;
158 elems->wpa_len = elen;
159 } else if (elen >= 5 && pos[3] == 2) {
160 /* OUI Type 2 - WMM IE */
161 if (pos[4] == 0) {
162 elems->wmm_info = pos;
163 elems->wmm_info_len = elen;
164 } else if (pos[4] == 1) {
165 elems->wmm_param = pos;
166 elems->wmm_param_len = elen;
167 }
168 }
169 }
170 break;
171 case WLAN_EID_RSN:
172 elems->rsn = pos;
173 elems->rsn_len = elen;
174 break;
175 case WLAN_EID_ERP_INFO:
176 elems->erp_info = pos;
177 elems->erp_info_len = elen;
178 break;
179 case WLAN_EID_EXT_SUPP_RATES:
180 elems->ext_supp_rates = pos;
181 elems->ext_supp_rates_len = elen;
182 break;
183 case WLAN_EID_HT_CAPABILITY:
184 if (elen >= sizeof(struct ieee80211_ht_cap))
185 elems->ht_cap_elem = (void *)pos;
186 break;
187 case WLAN_EID_HT_INFORMATION:
188 if (elen >= sizeof(struct ieee80211_ht_info))
189 elems->ht_info_elem = (void *)pos;
190 break;
191 case WLAN_EID_MESH_ID:
192 elems->mesh_id = pos;
193 elems->mesh_id_len = elen;
194 break;
195 case WLAN_EID_MESH_CONFIG:
196 elems->mesh_config = pos;
197 elems->mesh_config_len = elen;
198 break;
199 case WLAN_EID_PEER_LINK:
200 elems->peer_link = pos;
201 elems->peer_link_len = elen;
202 break;
203 case WLAN_EID_PREQ:
204 elems->preq = pos;
205 elems->preq_len = elen;
206 break;
207 case WLAN_EID_PREP:
208 elems->prep = pos;
209 elems->prep_len = elen;
210 break;
211 case WLAN_EID_PERR:
212 elems->perr = pos;
213 elems->perr_len = elen;
214 break;
215 case WLAN_EID_CHANNEL_SWITCH:
216 elems->ch_switch_elem = pos;
217 elems->ch_switch_elem_len = elen;
218 break;
219 case WLAN_EID_QUIET:
220 if (!elems->quiet_elem) {
221 elems->quiet_elem = pos;
222 elems->quiet_elem_len = elen;
223 }
224 elems->num_of_quiet_elem++;
225 break;
226 case WLAN_EID_COUNTRY:
227 elems->country_elem = pos;
228 elems->country_elem_len = elen;
229 break;
230 case WLAN_EID_PWR_CONSTRAINT:
231 elems->pwr_constr_elem = pos;
232 elems->pwr_constr_elem_len = elen;
233 break;
234 case WLAN_EID_TIMEOUT_INTERVAL:
235 elems->timeout_int = pos;
236 elems->timeout_int_len = elen;
237 break;
238 default:
239 break;
240 }
241
242 left -= elen;
243 pos += elen;
244 }
245
246 return crc;
247}
248
249void rtllib_parse_elems(u8 *start, size_t len,
250 struct ieee802_11_elems *elems)
251{
252 rtllib_parse_elems_crc(start, len, elems, 0, 0);
253}
254
255void ieee80211_scan_rx(struct rtllib_device *ieee, struct sk_buff *skb, struct rtllib_rx_stats *rx_status)
256{
257 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data ;
258 struct ieee80211_mgmt *mgmt;
259 struct ieee80211_bss *bss;
260 u8 *elements;
261 struct ieee80211_channel *channel;
262 size_t baselen;
263 int freq;
264 __le16 fc;
265 bool presp, beacon = false;
266 struct ieee802_11_elems elems;
267 s32 signal = 0;
268
269 if (skb->len < 2)
270 return;
271
272 mgmt = (struct ieee80211_mgmt *) skb->data;
273 fc = mgmt->frame_control;
274
275 if (skb->len < 24)
276 return;
277
278 presp = (WLAN_FC_GET_STYPE(header->frame_ctl) == RTLLIB_STYPE_PROBE_RESP);
279 if (presp) {
280 /* ignore ProbeResp to foreign address */
281 if (memcmp(mgmt->da, ieee->dev->dev_addr, ETH_ALEN))
282 return ;;
283
284 presp = true;
285 elements = mgmt->u.probe_resp.variable;
286 baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
287 } else {
288 beacon = (WLAN_FC_GET_STYPE(header->frame_ctl) == RTLLIB_STYPE_BEACON);
289 baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
290 elements = mgmt->u.beacon.variable;
291 }
292
293 if (!presp && !beacon)
294 return;
295
296 if (baselen > skb->len)
297 return;
298
299 rtllib_parse_elems(elements, skb->len - baselen, &elems);
300
301 if (elems.ds_params && elems.ds_params_len == 1)
302 freq = rtllib_channel_to_frequency(elems.ds_params[0]);
303 else
304 return;
305
306 channel = rtllib_get_channel(ieee->wdev.wiphy, freq);
307
308 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
309 return;
310
311 signal = rx_status->signal * 100;
312
313 bss = (void *)cfg80211_inform_bss_frame(ieee->wdev.wiphy, channel,
314 mgmt, skb->len, signal, GFP_ATOMIC);
315
316 return;
317}
318#endif
319
Larry Finger94a79942011-08-23 19:00:42 -0500320static inline void rtllib_monitor_rx(struct rtllib_device *ieee,
321 struct sk_buff *skb,struct rtllib_rx_stats *rx_status,
322 size_t hdr_length)
323{
Larry Finger94a79942011-08-23 19:00:42 -0500324 skb->dev = ieee->dev;
Larry Finger94a79942011-08-23 19:00:42 -0500325 skb_reset_mac_header(skb);
Larry Finger94a79942011-08-23 19:00:42 -0500326 skb_pull(skb, hdr_length);
327 skb->pkt_type = PACKET_OTHERHOST;
328 skb->protocol = __constant_htons(ETH_P_80211_RAW);
329 memset(skb->cb, 0, sizeof(skb->cb));
330 netif_rx(skb);
Larry Finger94a79942011-08-23 19:00:42 -0500331}
332
333/* Called only as a tasklet (software IRQ) */
334static struct rtllib_frag_entry *
335rtllib_frag_cache_find(struct rtllib_device *ieee, unsigned int seq,
336 unsigned int frag, u8 tid,u8 *src, u8 *dst)
337{
338 struct rtllib_frag_entry *entry;
339 int i;
340
341 for (i = 0; i < RTLLIB_FRAG_CACHE_LEN; i++) {
342 entry = &ieee->frag_cache[tid][i];
343 if (entry->skb != NULL &&
344 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
345 RTLLIB_DEBUG_FRAG(
346 "expiring fragment cache entry "
347 "seq=%u last_frag=%u\n",
348 entry->seq, entry->last_frag);
349 dev_kfree_skb_any(entry->skb);
350 entry->skb = NULL;
351 }
352
353 if (entry->skb != NULL && entry->seq == seq &&
354 (entry->last_frag + 1 == frag || frag == -1) &&
355 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
356 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
357 return entry;
358 }
359
360 return NULL;
361}
362
363/* Called only as a tasklet (software IRQ) */
364static struct sk_buff *
365rtllib_frag_cache_get(struct rtllib_device *ieee,
366 struct rtllib_hdr_4addr *hdr)
367{
368 struct sk_buff *skb = NULL;
369 u16 fc = le16_to_cpu(hdr->frame_ctl);
370 u16 sc = le16_to_cpu(hdr->seq_ctl);
371 unsigned int frag = WLAN_GET_SEQ_FRAG(sc);
372 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
373 struct rtllib_frag_entry *entry;
374 struct rtllib_hdr_3addrqos *hdr_3addrqos;
375 struct rtllib_hdr_4addrqos *hdr_4addrqos;
376 u8 tid;
377
378 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS)&&RTLLIB_QOS_HAS_SEQ(fc)) {
379 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
380 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
381 tid = UP2AC(tid);
382 tid ++;
383 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
384 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)hdr;
385 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
386 tid = UP2AC(tid);
387 tid ++;
388 } else {
389 tid = 0;
390 }
391
392 if (frag == 0) {
393 /* Reserve enough space to fit maximum frame length */
394 skb = dev_alloc_skb(ieee->dev->mtu +
395 sizeof(struct rtllib_hdr_4addr) +
396 8 /* LLC */ +
397 2 /* alignment */ +
398 8 /* WEP */ +
399 ETH_ALEN /* WDS */ +
400 (RTLLIB_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */);
401 if (skb == NULL)
402 return NULL;
403
404 entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]];
405 ieee->frag_next_idx[tid]++;
406 if (ieee->frag_next_idx[tid] >= RTLLIB_FRAG_CACHE_LEN)
407 ieee->frag_next_idx[tid] = 0;
408
409 if (entry->skb != NULL)
410 dev_kfree_skb_any(entry->skb);
411
412 entry->first_frag_time = jiffies;
413 entry->seq = seq;
414 entry->last_frag = frag;
415 entry->skb = skb;
416 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
417 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
418 } else {
419 /* received a fragment of a frame for which the head fragment
420 * should have already been received */
421 entry = rtllib_frag_cache_find(ieee, seq, frag, tid,hdr->addr2,
422 hdr->addr1);
423 if (entry != NULL) {
424 entry->last_frag = frag;
425 skb = entry->skb;
426 }
427 }
428
429 return skb;
430}
431
432
433/* Called only as a tasklet (software IRQ) */
434static int rtllib_frag_cache_invalidate(struct rtllib_device *ieee,
435 struct rtllib_hdr_4addr *hdr)
436{
437 u16 fc = le16_to_cpu(hdr->frame_ctl);
438 u16 sc = le16_to_cpu(hdr->seq_ctl);
439 unsigned int seq = WLAN_GET_SEQ_SEQ(sc);
440 struct rtllib_frag_entry *entry;
441 struct rtllib_hdr_3addrqos *hdr_3addrqos;
442 struct rtllib_hdr_4addrqos *hdr_4addrqos;
443 u8 tid;
444
445 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS)&&RTLLIB_QOS_HAS_SEQ(fc)) {
446 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
447 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
448 tid = UP2AC(tid);
449 tid ++;
450 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
451 hdr_3addrqos = (struct rtllib_hdr_3addrqos *)hdr;
452 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
453 tid = UP2AC(tid);
454 tid ++;
455 } else {
456 tid = 0;
457 }
458
459 entry = rtllib_frag_cache_find(ieee, seq, -1, tid,hdr->addr2,
460 hdr->addr1);
461
462 if (entry == NULL) {
463 RTLLIB_DEBUG_FRAG(
464 "could not invalidate fragment cache "
465 "entry (seq=%u)\n", seq);
466 return -1;
467 }
468
469 entry->skb = NULL;
470 return 0;
471}
472
473
474
475/* rtllib_rx_frame_mgtmt
476 *
477 * Responsible for handling management control frames
478 *
479 * Called by rtllib_rx */
480static inline int
481rtllib_rx_frame_mgmt(struct rtllib_device *ieee, struct sk_buff *skb,
482 struct rtllib_rx_stats *rx_stats, u16 type,
483 u16 stype)
484{
485 /* On the struct stats definition there is written that
486 * this is not mandatory.... but seems that the probe
487 * response parser uses it
488 */
489 struct rtllib_hdr_3addr * hdr = (struct rtllib_hdr_3addr *)skb->data;
490
491 rx_stats->len = skb->len;
492 rtllib_rx_mgt(ieee,skb,rx_stats);
493 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN))) {
494 dev_kfree_skb_any(skb);
495 return 0;
496 }
497 rtllib_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
498
499 dev_kfree_skb_any(skb);
500
501 return 0;
502
503#ifdef NOT_YET
504 if (ieee->iw_mode == IW_MODE_MASTER) {
505 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
506 ieee->dev->name);
507 return 0;
508/*
509 hostap_update_sta_ps(ieee, (struct hostap_rtllib_hdr_4addr *)
510 skb->data);*/
511 }
512
513 if (ieee->hostapd && type == RTLLIB_TYPE_MGMT) {
514 if (stype == WLAN_FC_STYPE_BEACON &&
515 ieee->iw_mode == IW_MODE_MASTER) {
516 struct sk_buff *skb2;
517 /* Process beacon frames also in kernel driver to
518 * update STA(AP) table statistics */
519 skb2 = skb_clone(skb, GFP_ATOMIC);
520 if (skb2)
521 hostap_rx(skb2->dev, skb2, rx_stats);
522 }
523
524 /* send management frames to the user space daemon for
525 * processing */
526 ieee->apdevstats.rx_packets++;
527 ieee->apdevstats.rx_bytes += skb->len;
528 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
529 return 0;
530 }
531
532 if (ieee->iw_mode == IW_MODE_MASTER) {
533 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
534 printk(KERN_DEBUG "%s: unknown management frame "
535 "(type=0x%02x, stype=0x%02x) dropped\n",
536 skb->dev->name, type, stype);
537 return -1;
538 }
539
540 hostap_rx(skb->dev, skb, rx_stats);
541 return 0;
542 }
543
544 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
545 "received in non-Host AP mode\n", skb->dev->name);
546 return -1;
547#endif
548}
549
550#ifndef CONFIG_CFG_80211
551/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
552/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
553static unsigned char rfc1042_header[] =
554{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
555/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
556static unsigned char bridge_tunnel_header[] =
557{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
558/* No encapsulation header if EtherType < 0x600 (=length) */
559#endif
560
561/* Called by rtllib_rx_frame_decrypt */
562static int rtllib_is_eapol_frame(struct rtllib_device *ieee,
563 struct sk_buff *skb, size_t hdrlen)
564{
565 struct net_device *dev = ieee->dev;
566 u16 fc, ethertype;
567 struct rtllib_hdr_4addr *hdr;
568 u8 *pos;
569
570 if (skb->len < 24)
571 return 0;
572
573 hdr = (struct rtllib_hdr_4addr *) skb->data;
574 fc = le16_to_cpu(hdr->frame_ctl);
575
576 /* check that the frame is unicast frame to us */
577 if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
578 RTLLIB_FCTL_TODS &&
579 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
580 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
581 /* ToDS frame with own addr BSSID and DA */
582 } else if ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
583 RTLLIB_FCTL_FROMDS &&
584 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
585 /* FromDS frame with own addr as DA */
586 } else
587 return 0;
588
589 if (skb->len < 24 + 8)
590 return 0;
591
592 /* check for port access entity Ethernet type */
593 pos = skb->data + hdrlen;
594 ethertype = (pos[6] << 8) | pos[7];
595 if (ethertype == ETH_P_PAE)
596 return 1;
597
598 return 0;
599}
600
601/* Called only as a tasklet (software IRQ), by rtllib_rx */
602static inline int
603rtllib_rx_frame_decrypt(struct rtllib_device* ieee, struct sk_buff *skb,
604 struct rtllib_crypt_data *crypt)
605{
606 struct rtllib_hdr_4addr *hdr;
607 int res, hdrlen;
608
609 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
610 return 0;
611#if 1
612 if (ieee->hwsec_active)
613 {
614 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
615 tcb_desc->bHwSec = 1;
616
617 if (ieee->need_sw_enc)
618 tcb_desc->bHwSec = 0;
619 }
620#endif
621 hdr = (struct rtllib_hdr_4addr *) skb->data;
622 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
623
624#ifdef CONFIG_RTLLIB_CRYPT_TKIP
625 if (ieee->tkip_countermeasures &&
626 strcmp(crypt->ops->name, "TKIP") == 0) {
627 if (net_ratelimit()) {
628 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
629 "received packet from " MAC_FMT "\n",
630 ieee->dev->name, MAC_ARG(hdr->addr2));
631 }
632 return -1;
633 }
634#endif
635
636 atomic_inc(&crypt->refcnt);
637 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
638 atomic_dec(&crypt->refcnt);
639 if (res < 0) {
640 RTLLIB_DEBUG_DROP(
641 "decryption failed (SA=" MAC_FMT
642 ") res=%d\n", MAC_ARG(hdr->addr2), res);
643 if (res == -2)
644 RTLLIB_DEBUG_DROP("Decryption failed ICV "
645 "mismatch (key %d)\n",
646 skb->data[hdrlen + 3] >> 6);
647 ieee->ieee_stats.rx_discards_undecryptable++;
648 return -1;
649 }
650
651 return res;
652}
653
654
655/* Called only as a tasklet (software IRQ), by rtllib_rx */
656static inline int
657rtllib_rx_frame_decrypt_msdu(struct rtllib_device* ieee, struct sk_buff *skb,
658 int keyidx, struct rtllib_crypt_data *crypt)
659{
660 struct rtllib_hdr_4addr *hdr;
661 int res, hdrlen;
662
663 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
664 return 0;
665 if (ieee->hwsec_active)
666 {
667 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
668 tcb_desc->bHwSec = 1;
669
670 if (ieee->need_sw_enc)
671 tcb_desc->bHwSec = 0;
672 }
673
674 hdr = (struct rtllib_hdr_4addr *) skb->data;
675 hdrlen = rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
676
677 atomic_inc(&crypt->refcnt);
678 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv,ieee);
679 atomic_dec(&crypt->refcnt);
680 if (res < 0) {
681 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
682 " (SA=" MAC_FMT " keyidx=%d)\n",
683 ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
684 return -1;
685 }
686
687 return 0;
688}
689
690
691/* this function is stolen from ipw2200 driver*/
692#define IEEE_PACKET_RETRY_TIME (5*HZ)
693static int is_duplicate_packet(struct rtllib_device *ieee,
694 struct rtllib_hdr_4addr *header)
695{
696 u16 fc = le16_to_cpu(header->frame_ctl);
697 u16 sc = le16_to_cpu(header->seq_ctl);
698 u16 seq = WLAN_GET_SEQ_SEQ(sc);
699 u16 frag = WLAN_GET_SEQ_FRAG(sc);
700 u16 *last_seq, *last_frag;
701 unsigned long *last_time;
702 struct rtllib_hdr_3addrqos *hdr_3addrqos;
703 struct rtllib_hdr_4addrqos *hdr_4addrqos;
704 u8 tid;
705
706 if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS)&&RTLLIB_QOS_HAS_SEQ(fc)) {
707 hdr_4addrqos = (struct rtllib_hdr_4addrqos *)header;
708 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
709 tid = UP2AC(tid);
710 tid ++;
711 } else if (RTLLIB_QOS_HAS_SEQ(fc)) {
712 hdr_3addrqos = (struct rtllib_hdr_3addrqos*)header;
713 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & RTLLIB_QCTL_TID;
714 tid = UP2AC(tid);
715 tid ++;
716 } else {
717 tid = 0;
718 }
719
720 switch (ieee->iw_mode) {
721 case IW_MODE_ADHOC:
722 {
723 struct list_head *p;
724 struct ieee_ibss_seq *entry = NULL;
725 u8 *mac = header->addr2;
726 int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
727 list_for_each(p, &ieee->ibss_mac_hash[index]) {
728 entry = list_entry(p, struct ieee_ibss_seq, list);
729 if (!memcmp(entry->mac, mac, ETH_ALEN))
730 break;
731 }
732 if (p == &ieee->ibss_mac_hash[index]) {
733 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
734 if (!entry) {
735 printk(KERN_WARNING "Cannot malloc new mac entry\n");
736 return 0;
737 }
738 memcpy(entry->mac, mac, ETH_ALEN);
739 entry->seq_num[tid] = seq;
740 entry->frag_num[tid] = frag;
741 entry->packet_time[tid] = jiffies;
742 list_add(&entry->list, &ieee->ibss_mac_hash[index]);
743 return 0;
744 }
745 last_seq = &entry->seq_num[tid];
746 last_frag = &entry->frag_num[tid];
747 last_time = &entry->packet_time[tid];
748 break;
749 }
750
751 case IW_MODE_INFRA:
752 last_seq = &ieee->last_rxseq_num[tid];
753 last_frag = &ieee->last_rxfrag_num[tid];
754 last_time = &ieee->last_packet_time[tid];
755 break;
756 default:
757 return 0;
758 }
759
760 if ((*last_seq == seq) &&
761 time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
762 if (*last_frag == frag){
763 goto drop;
764
765 }
766 if (*last_frag + 1 != frag)
767 /* out-of-order fragment */
768 goto drop;
769 } else
770 *last_seq = seq;
771
772 *last_frag = frag;
773 *last_time = jiffies;
774 return 0;
775
776drop:
777
778 return 1;
779}
780bool
781AddReorderEntry(
782 PRX_TS_RECORD pTS,
783 PRX_REORDER_ENTRY pReorderEntry
784 )
785{
786 struct list_head *pList = &pTS->RxPendingPktList;
787
788 while(pList->next != &pTS->RxPendingPktList)
789 {
790 if ( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
791 {
792 pList = pList->next;
793 }
794 else if ( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)list_entry(pList->next,RX_REORDER_ENTRY,List))->SeqNum) )
795 {
796 return false;
797 }
798 else
799 {
800 break;
801 }
802 }
803 pReorderEntry->List.next = pList->next;
804 pReorderEntry->List.next->prev = &pReorderEntry->List;
805 pReorderEntry->List.prev = pList;
806 pList->next = &pReorderEntry->List;
807
808 return true;
809}
810
811void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb** prxbIndicateArray,u8 index)
812{
813 struct net_device_stats *stats = &ieee->stats;
814 u8 i = 0 , j=0;
815 u16 ethertype;
816 for (j = 0; j < index; j++) {
817 struct rtllib_rxb* prxb = prxbIndicateArray[j];
818 for (i = 0; i<prxb->nr_subframes; i++) {
819 struct sk_buff *sub_skb = prxb->subframes[i];
820
821 /* convert hdr + possible LLC headers into Ethernet header */
822 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
823 if (sub_skb->len >= 8 &&
824 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
825 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
826 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
827 /* remove RFC1042 or Bridge-Tunnel encapsulation and
828 * replace EtherType */
829 skb_pull(sub_skb, SNAP_SIZE);
830 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
831 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
832 } else {
833 u16 len;
834 /* Leave Ethernet header part of hdr and full payload */
835 len = htons(sub_skb->len);
836 memcpy(skb_push(sub_skb, 2), &len, 2);
837 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->src, ETH_ALEN);
838 memcpy(skb_push(sub_skb, ETH_ALEN), prxb->dst, ETH_ALEN);
839 }
840
841 /* Indicat the packets to upper layer */
842 if (sub_skb) {
843 stats->rx_packets++;
844 stats->rx_bytes += sub_skb->len;
845
846 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
847 sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
848 sub_skb->dev = ieee->dev;
849 sub_skb->dev->stats.rx_packets++;
850 sub_skb->dev->stats.rx_bytes += sub_skb->len;
851#ifdef TCP_CSUM_OFFLOAD_RX
852 if ( prxb->tcp_csum_valid)
853 sub_skb->ip_summed = CHECKSUM_UNNECESSARY;
854 else
855 sub_skb->ip_summed = CHECKSUM_NONE;
856
857#else
858 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
859#endif
860 ieee->last_rx_ps_time = jiffies;
861 netif_rx(sub_skb);
862 }
863 }
864 kfree(prxb);
865 prxb = NULL;
866 }
867}
868
869void
870rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee, PRX_TS_RECORD pTS)
871{
872 PRX_REORDER_ENTRY pRxReorderEntry;
873 struct rtllib_rxb* RfdArray[REORDER_WIN_SIZE];
874 u8 RfdCnt = 0;
875
876
877 del_timer_sync(&pTS->RxPktPendingTimer);
878 while(!list_empty(&pTS->RxPendingPktList))
879 {
880 if (RfdCnt >= REORDER_WIN_SIZE){
881 printk("-------------->%s() error! RfdCnt >= REORDER_WIN_SIZE\n", __func__);
882 break;
883 }
884
885 pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
886 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): Indicate SeqNum %d!\n",__func__, pRxReorderEntry->SeqNum);
887 list_del_init(&pRxReorderEntry->List);
888
889 RfdArray[RfdCnt] = pRxReorderEntry->prxb;
890
891 RfdCnt = RfdCnt + 1;
892 list_add_tail(&pRxReorderEntry->List, &ieee->RxReorder_Unused_List);
893 }
894 rtllib_indicate_packets(ieee, RfdArray, RfdCnt);
895
896 pTS->RxIndicateSeq = 0xffff;
897
898#ifdef MERGE_TO_DO
899#endif
900}
901
902
903void RxReorderIndicatePacket( struct rtllib_device *ieee,
904 struct rtllib_rxb* prxb,
905 PRX_TS_RECORD pTS,
906 u16 SeqNum)
907{
908 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
909 PRX_REORDER_ENTRY pReorderEntry = NULL;
910 struct rtllib_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
911 u8 WinSize = pHTInfo->RxReorderWinSize;
912 u16 WinEnd = 0;
913 u8 index = 0;
914 bool bMatchWinStart = false, bPktInBuf = false;
915 unsigned long flags;
916
917 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize);
918
919 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
920
921 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
922 /* Rx Reorder initialize condition.*/
923 if (pTS->RxIndicateSeq == 0xffff) {
924 pTS->RxIndicateSeq = SeqNum;
925 }
926
927 /* Drop out the packet which SeqNum is smaller than WinStart */
928 if (SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
929 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
930 pTS->RxIndicateSeq, SeqNum);
931 pHTInfo->RxReorderDropCounter++;
932 {
933 int i;
934 for (i =0; i < prxb->nr_subframes; i++) {
935 dev_kfree_skb(prxb->subframes[i]);
936 }
937 kfree(prxb);
938 prxb = NULL;
939 }
940 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
941 return;
942 }
943
944 /*
945 * Sliding window manipulation. Conditions includes:
946 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
947 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
948 */
949 if (SN_EQUAL(SeqNum, pTS->RxIndicateSeq)) {
950 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
951 bMatchWinStart = true;
952 } else if (SN_LESS(WinEnd, SeqNum)) {
953 if (SeqNum >= (WinSize - 1)) {
954 pTS->RxIndicateSeq = SeqNum + 1 -WinSize;
955 } else {
956 pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum +1)) + 1;
957 }
958 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
959 }
960
961 /*
962 * Indication process.
963 * After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
964 * with the SeqNum smaller than latest WinStart and buffer other packets.
965 */
966 /* For Rx Reorder condition:
967 * 1. All packets with SeqNum smaller than WinStart => Indicate
968 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
969 */
970 if (bMatchWinStart) {
971 /* Current packet is going to be indicated.*/
972 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
973 pTS->RxIndicateSeq, SeqNum);
974 prxbIndicateArray[0] = prxb;
975 index = 1;
976 } else {
977 /* Current packet is going to be inserted into pending list.*/
978 if (!list_empty(&ieee->RxReorder_Unused_List)) {
979 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(ieee->RxReorder_Unused_List.next,RX_REORDER_ENTRY,List);
980 list_del_init(&pReorderEntry->List);
981
982 /* Make a reorder entry and insert into a the packet list.*/
983 pReorderEntry->SeqNum = SeqNum;
984 pReorderEntry->prxb = prxb;
985
986#if 1
987 if (!AddReorderEntry(pTS, pReorderEntry)) {
988 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
989 __func__, pTS->RxIndicateSeq, SeqNum);
990 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
991 {
992 int i;
993 for (i =0; i < prxb->nr_subframes; i++) {
994 dev_kfree_skb(prxb->subframes[i]);
995 }
996 kfree(prxb);
997 prxb = NULL;
998 }
999 } else {
1000 RTLLIB_DEBUG(RTLLIB_DL_REORDER,
1001 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->RxIndicateSeq, SeqNum);
1002 }
1003#endif
1004 }
1005 else {
1006 /*
1007 * Packets are dropped if there is not enough reorder entries.
1008 * This part shall be modified!! We can just indicate all the
1009 * packets in buffer and get reorder entries.
1010 */
1011 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
1012 {
1013 int i;
1014 for (i =0; i < prxb->nr_subframes; i++) {
1015 dev_kfree_skb(prxb->subframes[i]);
1016 }
1017 kfree(prxb);
1018 prxb = NULL;
1019 }
1020 }
1021 }
1022
1023 /* Check if there is any packet need indicate.*/
1024 while(!list_empty(&pTS->RxPendingPktList)) {
1025 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): start RREORDER indicate\n",__func__);
1026#if 1
1027 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
1028 if ( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
1029 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
1030 {
1031 /* This protect buffer from overflow. */
1032 if (index >= REORDER_WIN_SIZE) {
1033 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
1034 bPktInBuf = true;
1035 break;
1036 }
1037
1038 list_del_init(&pReorderEntry->List);
1039
1040 if (SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
1041 pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
1042
1043 prxbIndicateArray[index] = pReorderEntry->prxb;
1044 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): Indicate SeqNum %d!\n",__func__, pReorderEntry->SeqNum);
1045 index++;
1046
1047 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List);
1048 } else {
1049 bPktInBuf = true;
1050 break;
1051 }
1052#endif
1053 }
1054
1055 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
1056 if (index>0) {
1057 if (timer_pending(&pTS->RxPktPendingTimer)){
1058 del_timer_sync(&pTS->RxPktPendingTimer);
1059 }
1060 pTS->RxTimeoutIndicateSeq = 0xffff;
1061
1062 if (index>REORDER_WIN_SIZE){
1063 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
1064 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
1065 return;
1066 }
1067 rtllib_indicate_packets(ieee, prxbIndicateArray, index);
1068 bPktInBuf = false;
1069 }
1070
1071 if (bPktInBuf && pTS->RxTimeoutIndicateSeq==0xffff) {
1072 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): SET rx timeout timer\n", __func__);
1073 pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
1074 mod_timer(&pTS->RxPktPendingTimer, jiffies + MSECS(pHTInfo->RxReorderPendingTime));
1075 }
1076 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
1077}
1078
1079u8 parse_subframe(struct rtllib_device* ieee,struct sk_buff *skb,
1080 struct rtllib_rx_stats *rx_stats,
1081 struct rtllib_rxb *rxb,u8* src,u8* dst)
1082{
1083 struct rtllib_hdr_3addr *hdr = (struct rtllib_hdr_3addr* )skb->data;
1084 u16 fc = le16_to_cpu(hdr->frame_ctl);
1085
1086 u16 LLCOffset= sizeof(struct rtllib_hdr_3addr);
1087 u16 ChkLength;
1088 bool bIsAggregateFrame = false;
1089 u16 nSubframe_Length;
1090 u8 nPadding_Length = 0;
1091 u16 SeqNum=0;
1092 struct sk_buff *sub_skb;
1093 u8 *data_ptr;
1094 /* just for debug purpose */
1095 SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
1096 if ((RTLLIB_QOS_HAS_SEQ(fc))&&\
1097 (((frameqos *)(skb->data + RTLLIB_3ADDR_LEN))->field.reserved)) {
1098 bIsAggregateFrame = true;
1099 }
1100
1101 if (RTLLIB_QOS_HAS_SEQ(fc)) {
1102 LLCOffset += 2;
1103 }
1104 if (rx_stats->bContainHTC) {
1105 LLCOffset += sHTCLng;
1106 }
1107
1108 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
1109
1110 if ( skb->len <= ChkLength ) {
1111 return 0;
1112 }
1113
1114 skb_pull(skb, LLCOffset);
1115 ieee->bIsAggregateFrame = bIsAggregateFrame;
1116 if (!bIsAggregateFrame) {
1117 rxb->nr_subframes = 1;
1118
1119 /* altered by clark 3/30/2010
1120 * The buffer size of the skb indicated to upper layer
1121 * must be less than 5000, or the defraged IP datagram
1122 * in the IP layer will exceed "ipfrag_high_tresh" and be
1123 * discarded. so there must not use the function
1124 * "skb_copy" and "skb_clone" for "skb".
1125 */
1126
1127 /* Allocate new skb for releasing to upper layer */
1128 sub_skb = dev_alloc_skb(RTLLIB_SKBBUFFER_SIZE);
1129 skb_reserve(sub_skb, 12);
1130 data_ptr = (u8 *)skb_put(sub_skb, skb->len);
1131 memcpy(data_ptr, skb->data, skb->len);
1132 sub_skb->dev = ieee->dev;
1133
1134 rxb->subframes[0] = sub_skb;
1135
1136 memcpy(rxb->src,src,ETH_ALEN);
1137 memcpy(rxb->dst,dst,ETH_ALEN);
1138 rxb->subframes[0]->dev = ieee->dev;
1139 return 1;
1140 } else {
1141 rxb->nr_subframes = 0;
1142 memcpy(rxb->src,src,ETH_ALEN);
1143 memcpy(rxb->dst,dst,ETH_ALEN);
1144 while(skb->len > ETHERNET_HEADER_SIZE) {
1145 /* Offset 12 denote 2 mac address */
1146 nSubframe_Length = *((u16*)(skb->data + 12));
1147 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8);
1148
1149 if (skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1150 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
1151 __func__,rxb->nr_subframes);
1152 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__func__, nSubframe_Length);
1153 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length);
1154 printk("The Packet SeqNum is %d\n",SeqNum);
1155 return 0;
1156 }
1157
1158 /* move the data point to data content */
1159 skb_pull(skb, ETHERNET_HEADER_SIZE);
1160
1161 /* altered by clark 3/30/2010
1162 * The buffer size of the skb indicated to upper layer
1163 * must be less than 5000, or the defraged IP datagram
1164 * in the IP layer will exceed "ipfrag_high_tresh" and be
1165 * discarded. so there must not use the function
1166 * "skb_copy" and "skb_clone" for "skb".
1167 */
1168
1169 /* Allocate new skb for releasing to upper layer */
1170 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1171 skb_reserve(sub_skb, 12);
1172 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1173 memcpy(data_ptr,skb->data,nSubframe_Length);
1174
1175 sub_skb->dev = ieee->dev;
1176 rxb->subframes[rxb->nr_subframes++] = sub_skb;
1177 if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
1178 RTLLIB_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1179 break;
1180 }
1181 skb_pull(skb,nSubframe_Length);
1182
1183 if (skb->len != 0) {
1184 nPadding_Length = 4 - ((nSubframe_Length + ETHERNET_HEADER_SIZE) % 4);
1185 if (nPadding_Length == 4) {
1186 nPadding_Length = 0;
1187 }
1188
1189 if (skb->len < nPadding_Length) {
1190 return 0;
1191 }
1192
1193 skb_pull(skb,nPadding_Length);
1194 }
1195 }
1196
1197 return rxb->nr_subframes;
1198 }
1199}
1200
1201
1202size_t rtllib_rx_get_hdrlen(struct rtllib_device *ieee, struct sk_buff *skb,
1203 struct rtllib_rx_stats *rx_stats)
1204{
1205 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1206 u16 fc = le16_to_cpu(hdr->frame_ctl);
1207 size_t hdrlen = 0;
1208
1209 hdrlen = rtllib_get_hdrlen(fc);
1210 if (HTCCheck(ieee, skb->data)) {
1211 if (net_ratelimit())
1212 printk("%s: find HTCControl!\n", __func__);
1213 hdrlen += 4;
1214 rx_stats->bContainHTC = 1;
1215 }
1216
1217 if (RTLLIB_QOS_HAS_SEQ(fc))
1218 rx_stats->bIsQosData = 1;
1219
1220 return hdrlen;
1221}
1222
1223int rtllib_rx_check_duplicate(struct rtllib_device *ieee, struct sk_buff *skb, u8 multicast)
1224{
1225 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1226 u16 fc, sc;
1227 u8 frag, type, stype;
1228
1229 fc = le16_to_cpu(hdr->frame_ctl);
1230 type = WLAN_FC_GET_TYPE(fc);
1231 stype = WLAN_FC_GET_STYPE(fc);
1232 sc = le16_to_cpu(hdr->seq_ctl);
1233 frag = WLAN_GET_SEQ_FRAG(sc);
1234
1235 if ( (ieee->pHTInfo->bCurRxReorderEnable == false) ||
1236 !ieee->current_network.qos_data.active ||
1237 !IsDataFrame(skb->data) ||
1238 IsLegacyDataFrame(skb->data)) {
1239 if (!((type == RTLLIB_FTYPE_MGMT) && (stype == RTLLIB_STYPE_BEACON))){
1240 if (is_duplicate_packet(ieee, hdr)){
1241 return -1;
1242 }
1243 }
1244 } else {
1245 PRX_TS_RECORD pRxTS = NULL;
1246 if (GetTs(ieee, (PTS_COMMON_INFO*) &pRxTS, hdr->addr2,
1247 (u8)Frame_QoSTID((u8*)(skb->data)), RX_DIR, true)) {
1248 if ((fc & (1<<11)) && (frag == pRxTS->RxLastFragNum) &&
1249 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum)) {
1250 return -1;
1251 } else {
1252 pRxTS->RxLastFragNum = frag;
1253 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
1254 }
1255 } else {
1256 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!%s(): No TS!! Skip the check!!\n",__func__);
1257 return -1;
1258 }
1259 }
1260
1261 return 0;
1262}
1263void rtllib_rx_extract_addr(struct rtllib_device *ieee, struct rtllib_hdr_4addr *hdr, u8 *dst, u8 *src, u8 *bssid)
1264{
1265 u16 fc = le16_to_cpu(hdr->frame_ctl);
1266
1267 switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
1268 case RTLLIB_FCTL_FROMDS:
1269 memcpy(dst, hdr->addr1, ETH_ALEN);
1270 memcpy(src, hdr->addr3, ETH_ALEN);
1271 memcpy(bssid, hdr->addr2, ETH_ALEN);
1272 break;
1273 case RTLLIB_FCTL_TODS:
1274 memcpy(dst, hdr->addr3, ETH_ALEN);
1275 memcpy(src, hdr->addr2, ETH_ALEN);
1276 memcpy(bssid, hdr->addr1, ETH_ALEN);
1277 break;
1278 case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
1279 memcpy(dst, hdr->addr3, ETH_ALEN);
1280 memcpy(src, hdr->addr4, ETH_ALEN);
1281 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
1282 break;
1283 case 0:
1284 memcpy(dst, hdr->addr1, ETH_ALEN);
1285 memcpy(src, hdr->addr2, ETH_ALEN);
1286 memcpy(bssid, hdr->addr3, ETH_ALEN);
1287 break;
1288 }
1289}
1290int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc, u8 *dst, u8 *src, u8 *bssid, u8 *addr2)
1291{
1292 u8 zero_addr[ETH_ALEN] = {0};
1293 u8 type, stype;
1294
1295 type = WLAN_FC_GET_TYPE(fc);
1296 stype = WLAN_FC_GET_STYPE(fc);
1297
1298 /* Filter frames from different BSS */
1299 if (((fc & RTLLIB_FCTL_DSTODS) != RTLLIB_FCTL_DSTODS)
1300 && (compare_ether_addr(ieee->current_network.bssid, bssid) != 0)
1301 && memcmp(ieee->current_network.bssid, zero_addr, ETH_ALEN)) {
1302 return -1;
1303 }
1304
1305 /* Filter packets sent by an STA that will be forwarded by AP */
1306 if ( ieee->IntelPromiscuousModeInfo.bPromiscuousOn &&
1307 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame ) {
1308 if ((fc & RTLLIB_FCTL_TODS) && !(fc & RTLLIB_FCTL_FROMDS) &&
1309 (compare_ether_addr(dst, ieee->current_network.bssid) != 0) &&
1310 (compare_ether_addr(bssid, ieee->current_network.bssid) == 0)) {
1311 return -1;
1312 }
1313 }
1314
1315 /* Nullfunc frames may have PS-bit set, so they must be passed to
1316 * hostap_handle_sta_rx() before being dropped here. */
1317 if (!ieee->IntelPromiscuousModeInfo.bPromiscuousOn){
1318 if (stype != RTLLIB_STYPE_DATA &&
1319 stype != RTLLIB_STYPE_DATA_CFACK &&
1320 stype != RTLLIB_STYPE_DATA_CFPOLL &&
1321 stype != RTLLIB_STYPE_DATA_CFACKPOLL&&
1322 stype != RTLLIB_STYPE_QOS_DATA
1323 ) {
1324 if (stype != RTLLIB_STYPE_NULLFUNC)
1325 RTLLIB_DEBUG_DROP(
1326 "RX: dropped data frame "
1327 "with no data (type=0x%02x, "
1328 "subtype=0x%02x)\n",
1329 type, stype);
1330 return -1;
1331 }
1332 }
1333
1334 if (ieee->iw_mode != IW_MODE_MESH) {
1335 /* packets from our adapter are dropped (echo) */
1336 if (!memcmp(src, ieee->dev->dev_addr, ETH_ALEN))
1337 return -1;
1338
1339 /* {broad,multi}cast packets to our BSS go through */
1340 if (is_multicast_ether_addr(dst) || is_broadcast_ether_addr(dst)) {
1341 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) {
1342 return -1;
1343 }
1344 }
1345 }
1346 return 0;
1347}
1348int rtllib_rx_get_crypt(
1349 struct rtllib_device *ieee,
1350 struct sk_buff *skb,
1351 struct rtllib_crypt_data **crypt,
1352 size_t hdrlen)
1353{
1354 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1355 u16 fc = le16_to_cpu(hdr->frame_ctl);
1356 int idx = 0;
1357
1358 if (ieee->host_decrypt) {
1359 if (skb->len >= hdrlen + 3)
1360 idx = skb->data[hdrlen + 3] >> 6;
1361
1362 *crypt = ieee->crypt[idx];
1363 /* allow NULL decrypt to indicate an station specific override
1364 * for default encryption */
1365 if (*crypt && ((*crypt)->ops == NULL ||
1366 (*crypt)->ops->decrypt_mpdu == NULL))
1367 *crypt = NULL;
1368
1369 if (!*crypt && (fc & RTLLIB_FCTL_WEP)) {
1370 /* This seems to be triggered by some (multicast?)
1371 * frames from other than current BSS, so just drop the
1372 * frames silently instead of filling system log with
1373 * these reports. */
1374 RTLLIB_DEBUG_DROP("Decryption failed (not set)"
1375 " (SA=" MAC_FMT ")\n",
1376 MAC_ARG(hdr->addr2));
1377 ieee->ieee_stats.rx_discards_undecryptable++;
1378 return -1;
1379 }
1380 }
1381
1382 return 0;
1383}
1384int rtllib_rx_decrypt(
1385 struct rtllib_device *ieee,
1386 struct sk_buff *skb,
1387 struct rtllib_rx_stats *rx_stats,
1388 struct rtllib_crypt_data *crypt,
1389 size_t hdrlen)
1390{
1391 struct rtllib_hdr_4addr *hdr;
1392 int keyidx = 0;
1393 u16 fc, sc;
1394 u8 frag;
1395
1396 hdr = (struct rtllib_hdr_4addr *)skb->data;
1397 fc = le16_to_cpu(hdr->frame_ctl);
1398 sc = le16_to_cpu(hdr->seq_ctl);
1399 frag = WLAN_GET_SEQ_FRAG(sc);
1400
1401 if ((!rx_stats->Decrypted)){
1402 ieee->need_sw_enc = 1;
1403 }else{
1404 ieee->need_sw_enc = 0;
1405 }
1406
1407 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
1408 ((keyidx = rtllib_rx_frame_decrypt(ieee, skb, crypt)) < 0)) {
1409 printk("%s: decrypt frame error\n", __func__);
1410 return -1;
1411 }
1412
1413 hdr = (struct rtllib_hdr_4addr *) skb->data;
1414 if ((frag != 0 || (fc & RTLLIB_FCTL_MOREFRAGS))) {
1415 int flen;
1416 struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
1417 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
1418
1419 if (!frag_skb) {
1420 RTLLIB_DEBUG(RTLLIB_DL_RX | RTLLIB_DL_FRAG,
1421 "Rx cannot get skb from fragment "
1422 "cache (morefrag=%d seq=%u frag=%u)\n",
1423 (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
1424 WLAN_GET_SEQ_SEQ(sc), frag);
1425 return -1;
1426 }
1427 flen = skb->len;
1428 if (frag != 0)
1429 flen -= hdrlen;
1430
1431 if (frag_skb->tail + flen > frag_skb->end) {
1432 printk(KERN_WARNING "%s: host decrypted and "
1433 "reassembled frame did not fit skb\n",
1434 __func__);
1435 rtllib_frag_cache_invalidate(ieee, hdr);
1436 return -1;
1437 }
1438
1439 if (frag == 0) {
1440 /* copy first fragment (including full headers) into
1441 * beginning of the fragment cache skb */
1442 memcpy(skb_put(frag_skb, flen), skb->data, flen);
1443 } else {
1444 /* append frame payload to the end of the fragment
1445 * cache skb */
1446 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
1447 flen);
1448 }
1449 dev_kfree_skb_any(skb);
1450 skb = NULL;
1451
1452 if (fc & RTLLIB_FCTL_MOREFRAGS) {
1453 /* more fragments expected - leave the skb in fragment
1454 * cache for now; it will be delivered to upper layers
1455 * after all fragments have been received */
1456 return -2;
1457 }
1458
1459 /* this was the last fragment and the frame will be
1460 * delivered, so remove skb from fragment cache */
1461 skb = frag_skb;
1462 hdr = (struct rtllib_hdr_4addr *) skb->data;
1463 rtllib_frag_cache_invalidate(ieee, hdr);
1464 }
1465
1466 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1467 * encrypted/authenticated */
1468 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
1469 rtllib_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
1470 {
1471 printk("%s: ==>decrypt msdu error\n", __func__);
1472 return -1;
1473 }
1474
1475 hdr = (struct rtllib_hdr_4addr *) skb->data;
1476 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep) {
1477 if (/*ieee->ieee802_1x &&*/
1478 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1479
1480#ifdef CONFIG_RTLLIB_DEBUG
1481 /* pass unencrypted EAPOL frames even if encryption is
1482 * configured */
1483 struct eapol *eap = (struct eapol *)(skb->data +
1484 24);
1485 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1486 eap_get_type(eap->type));
1487#endif
1488 } else {
1489 RTLLIB_DEBUG_DROP(
1490 "encryption configured, but RX "
1491 "frame not encrypted (SA=" MAC_FMT ")\n",
1492 MAC_ARG(hdr->addr2));
1493 return -1;
1494 }
1495 }
1496
1497#ifdef CONFIG_RTLLIB_DEBUG
1498 if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
1499 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1500 struct eapol *eap = (struct eapol *)(skb->data +
1501 24);
1502 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1503 eap_get_type(eap->type));
1504 }
1505#endif
1506
1507 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
1508 !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1509 RTLLIB_DEBUG_DROP(
1510 "dropped unencrypted RX data "
1511 "frame from " MAC_FMT
1512 " (drop_unencrypted=1)\n",
1513 MAC_ARG(hdr->addr2));
1514 return -1;
1515 }
1516
1517 if (rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
1518 printk(KERN_WARNING "RX: IEEE802.1X EAPOL frame!\n");
1519 }
1520
1521 return 0;
1522}
1523void rtllib_rx_check_leave_lps(struct rtllib_device *ieee, u8 unicast, u8 nr_subframes)
1524{
1525#if !defined(RTL8192SU) && !defined(RTL8192U)
1526 if (unicast){
1527
1528 if ((ieee->state == RTLLIB_LINKED) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/)
1529 {
1530 if ( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
1531 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
1532 {
1533 if (ieee->LeisurePSLeave)
1534 ieee->LeisurePSLeave(ieee->dev);
1535 }
1536 }
1537 }
1538#endif
1539 ieee->last_rx_ps_time = jiffies;
1540}
1541void rtllib_rx_indicate_pkt_legacy(
1542 struct rtllib_device *ieee,
1543 struct rtllib_rx_stats *rx_stats,
1544 struct rtllib_rxb* rxb,
1545 u8 *dst,
1546 u8 *src)
1547{
1548 struct net_device *dev = ieee->dev;
1549 u16 ethertype;
1550 int i = 0;
1551
1552 if (rxb == NULL){
1553 printk("%s: rxb is NULL!!\n", __func__);
1554 return ;
1555 }
1556
1557 for (i = 0; i<rxb->nr_subframes; i++) {
1558 struct sk_buff *sub_skb = rxb->subframes[i];
1559
1560 if (sub_skb) {
1561 /* convert hdr + possible LLC headers into Ethernet header */
1562 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
1563 if (sub_skb->len >= 8 &&
1564 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
1565 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1566 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
1567 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1568 * replace EtherType */
1569 skb_pull(sub_skb, SNAP_SIZE);
1570 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1571 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1572 } else {
1573 u16 len;
1574 /* Leave Ethernet header part of hdr and full payload */
1575 len = htons(sub_skb->len);
1576 memcpy(skb_push(sub_skb, 2), &len, 2);
1577 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
1578 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
1579 }
1580
1581 ieee->stats.rx_packets++;
1582 ieee->stats.rx_bytes += sub_skb->len;
1583
1584 if (is_multicast_ether_addr(dst)) {
1585 ieee->stats.multicast++;
1586 }
1587
1588 /* Indicat the packets to upper layer */
1589 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
1590 sub_skb->protocol = eth_type_trans(sub_skb, dev);
1591 sub_skb->dev = dev;
1592 sub_skb->dev->stats.rx_packets++;
1593 sub_skb->dev->stats.rx_bytes += sub_skb->len;
1594#ifdef TCP_CSUM_OFFLOAD_RX
1595 if ( rx_stats->tcp_csum_valid)
1596 sub_skb->ip_summed = CHECKSUM_UNNECESSARY;
1597 else
1598 sub_skb->ip_summed = CHECKSUM_NONE;
1599#else
1600 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
1601#endif
1602 netif_rx(sub_skb);
1603 }
1604 }
1605 kfree(rxb);
1606 rxb = NULL;
1607}
1608int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1609 struct rtllib_rx_stats *rx_stats)
1610{
1611 struct net_device *dev = ieee->dev;
1612 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1613 struct rtllib_crypt_data *crypt = NULL;
1614#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
1615 struct sta_info * psta = NULL;
1616#endif
1617 struct rtllib_rxb* rxb = NULL;
1618 PRX_TS_RECORD pTS = NULL;
1619 u16 fc, sc, SeqNum = 0;
1620 u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0;
1621 u8 dst[ETH_ALEN], src[ETH_ALEN], bssid[ETH_ALEN] = {0}, *payload;
1622 size_t hdrlen = 0;
1623 bool bToOtherSTA = false;
1624 int ret = 0, i = 0;
1625
1626 hdr = (struct rtllib_hdr_4addr *)skb->data;
1627 fc = le16_to_cpu(hdr->frame_ctl);
1628 type = WLAN_FC_GET_TYPE(fc);
1629 stype = WLAN_FC_GET_STYPE(fc);
1630 sc = le16_to_cpu(hdr->seq_ctl);
1631
1632 /*Filter pkt not to me*/
1633 multicast = is_multicast_ether_addr(hdr->addr1)|is_broadcast_ether_addr(hdr->addr1);
1634 unicast = !multicast;
1635 if (unicast && (compare_ether_addr(dev->dev_addr, hdr->addr1) != 0)) {
1636 if (ieee->bNetPromiscuousMode)
1637 bToOtherSTA = true;
1638 else
1639 goto rx_dropped;
1640 }
1641
1642 /*Filter pkt has too small length */
1643 hdrlen = rtllib_rx_get_hdrlen(ieee, skb, rx_stats);
1644 if (skb->len < hdrlen){
1645 printk("%s():ERR!!! skb->len is smaller than hdrlen\n",__func__);
1646 goto rx_dropped;
1647 }
1648
1649 /* Filter Duplicate pkt */
1650 ret = rtllib_rx_check_duplicate(ieee, skb, multicast);
1651 if (ret < 0)
1652 goto rx_dropped;
1653
1654 /* Filter CTRL Frame */
1655 if (type == RTLLIB_FTYPE_CTL) {
1656 goto rx_dropped;
1657 }
1658
1659 /* Filter MGNT Frame */
1660 if (type == RTLLIB_FTYPE_MGMT) {
1661 if (bToOtherSTA)
1662 goto rx_dropped;
1663 if (rtllib_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
1664 goto rx_dropped;
1665 else
1666 goto rx_exit;
1667 }
1668
1669 /* Filter WAPI DATA Frame */
1670
1671 /* Update statstics for AP roaming */
1672 if (!bToOtherSTA){
1673 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1674 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1675 }
1676 dev->last_rx = jiffies;
1677
1678 /* Data frame - extract src/dst addresses */
1679 rtllib_rx_extract_addr(ieee, hdr, dst, src, bssid);
1680
1681 /* Filter Data frames */
1682 ret = rtllib_rx_data_filter(ieee, fc, dst, src, bssid, hdr->addr2);
1683 if (ret < 0)
1684 goto rx_dropped;
1685
1686 if (skb->len == hdrlen){
1687 goto rx_dropped;
1688 }
1689
1690 /* Send pspoll based on moredata */
1691 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == LPS_IS_SLEEP)
1692 && (ieee->polling) && (!bToOtherSTA)) {
1693 if (WLAN_FC_MORE_DATA(fc)) {
1694 /* more data bit is set, let's request a new frame from the AP */
1695 rtllib_sta_ps_send_pspoll_frame(ieee);
1696 } else {
1697 ieee->polling = false;
1698 }
1699 }
1700
1701#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
1702 if (ieee->iw_mode == IW_MODE_ADHOC){
1703 psta = GetStaInfo(ieee, src);
1704 if (NULL != psta)
1705 psta->LastActiveTime = jiffies;
1706 }
1707#endif
1708
1709 /* Get crypt if encrypted */
1710 ret = rtllib_rx_get_crypt(ieee, skb, &crypt, hdrlen);
1711 if (ret == -1)
1712 goto rx_dropped;
1713
1714 /* Decrypt data frame (including reassemble) */
1715 ret = rtllib_rx_decrypt(ieee, skb, rx_stats, crypt, hdrlen);
1716 if (ret == -1)
1717 goto rx_dropped;
1718 else if (ret == -2)
1719 goto rx_exit;
1720
1721 /* Get TS for Rx Reorder */
1722 hdr = (struct rtllib_hdr_4addr *) skb->data;
1723 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1724 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1)
1725 && (!bToOtherSTA))
1726 {
1727 TID = Frame_QoSTID(skb->data);
1728 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1729 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
1730 if (TID !=0 && TID !=3){
1731 ieee->bis_any_nonbepkts = true;
1732 }
1733 }
1734
1735 /* Parse rx data frame (For AMSDU) */
1736 /* skb: hdr + (possible reassembled) full plaintext payload */
1737 payload = skb->data + hdrlen;
1738 rxb = (struct rtllib_rxb*)kmalloc(sizeof(struct rtllib_rxb),GFP_ATOMIC);
1739 if (rxb == NULL)
1740 {
1741 RTLLIB_DEBUG(RTLLIB_DL_ERR,"%s(): kmalloc rxb error\n",__func__);
1742 goto rx_dropped;
1743 }
1744 /* to parse amsdu packets */
1745 /* qos data packets & reserved bit is 1 */
1746 if (parse_subframe(ieee,skb,rx_stats,rxb,src,dst) == 0) {
1747 /* only to free rxb, and not submit the packets to upper layer */
1748 for (i =0; i < rxb->nr_subframes; i++) {
1749 dev_kfree_skb(rxb->subframes[i]);
1750 }
1751 kfree(rxb);
1752 rxb = NULL;
1753 goto rx_dropped;
1754 }
1755
1756 /* Update WAPI PN */
1757
1758 /* Check if leave LPS */
1759 if (!bToOtherSTA){
1760 if (ieee->bIsAggregateFrame)
1761 nr_subframes = rxb->nr_subframes;
1762 else
1763 nr_subframes = 1;
1764 if (unicast)
1765 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod += nr_subframes;
1766 rtllib_rx_check_leave_lps(ieee, unicast, nr_subframes);
1767 }
1768
1769 /* Indicate packets to upper layer or Rx Reorder */
1770 if (ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL || bToOtherSTA){
1771 rtllib_rx_indicate_pkt_legacy(ieee, rx_stats, rxb, dst, src);
1772 }else{
1773#ifdef TCP_CSUM_OFFLOAD_RX
1774 rxb->tcp_csum_valid = rx_stats->tcp_csum_valid;
1775#endif
1776 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1777 }
1778
1779 dev_kfree_skb(skb);
1780
1781 rx_exit:
1782 return 1;
1783
1784 rx_dropped:
1785 if (rxb != NULL)
1786 {
1787 kfree(rxb);
1788 rxb = NULL;
1789 }
1790 ieee->stats.rx_dropped++;
1791
1792 /* Returning 0 indicates to caller that we have not handled the SKB--
1793 * so it is still allocated and can be used again by underlying
1794 * hardware as a DMA target */
1795 return 0;
1796}
1797
1798int rtllib_rx_Master(struct rtllib_device *ieee, struct sk_buff *skb,
1799 struct rtllib_rx_stats *rx_stats)
1800{
1801 return 0;
1802}
1803int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb,
1804 struct rtllib_rx_stats *rx_stats)
1805{
1806 struct rtllib_hdr_4addr *hdr = (struct rtllib_hdr_4addr *)skb->data;
1807 u16 fc = le16_to_cpu(hdr->frame_ctl);
1808 size_t hdrlen = rtllib_get_hdrlen(fc);
1809
1810 if (skb->len < hdrlen){
1811 printk("%s():ERR!!! skb->len is smaller than hdrlen\n", __func__);
1812 return 0;
1813 }
1814
1815 if (HTCCheck(ieee, skb->data)) {
1816 if (net_ratelimit())
1817 printk("%s: Find HTCControl!\n", __func__);
1818 hdrlen += 4;
1819 }
1820
1821#if WIRELESS_EXT > 15
1822 rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
1823 ieee->stats.rx_packets++;
1824 ieee->stats.rx_bytes += skb->len;
1825#endif
1826 return 1;
1827}
1828
1829int rtllib_rx_Mesh(struct rtllib_device *ieee, struct sk_buff *skb,
1830 struct rtllib_rx_stats *rx_stats)
1831{
1832 return 0;
1833}
1834
1835#if 1
1836/* All received frames are sent to this function. @skb contains the frame in
1837 * IEEE 802.11 format, i.e., in the format it was sent over air.
1838 * This function is called only as a tasklet (software IRQ). */
1839int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1840 struct rtllib_rx_stats *rx_stats)
1841{
1842 int ret = 0;
1843
1844 if ((NULL==ieee) || (NULL==skb) || (NULL==rx_stats)){
1845 printk(KERN_INFO "%s: Input parameters NULL!\n", __func__);
1846 goto rx_dropped;
1847 }
1848 if (skb->len < 10) {
1849 printk(KERN_INFO "%s: SKB length < 10 \n", __func__);
1850 goto rx_dropped;
1851 }
1852
1853 switch (ieee->iw_mode) {
1854 case IW_MODE_ADHOC:
1855 case IW_MODE_INFRA:
1856 ret = rtllib_rx_InfraAdhoc(ieee, skb, rx_stats);
1857 break;
1858 case IW_MODE_MASTER:
1859 case IW_MODE_REPEAT:
1860 ret = rtllib_rx_Master(ieee, skb, rx_stats);
1861 break;
1862 case IW_MODE_MONITOR:
1863 ret = rtllib_rx_Monitor(ieee, skb, rx_stats);
1864 break;
1865 case IW_MODE_MESH:
1866 ret = rtllib_rx_Mesh(ieee, skb, rx_stats);
1867 break;
1868 default:
1869 printk(KERN_INFO"%s: ERR iw mode!!!\n", __func__);
1870 break;
1871 }
1872
1873 return ret;
1874
1875 rx_dropped:
1876 ieee->stats.rx_dropped++;
1877 return 0;
1878}
1879#else
1880int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1881 struct rtllib_rx_stats *rx_stats)
1882{
1883 struct net_device *dev = ieee->dev;
1884 struct rtllib_hdr_4addr *hdr;
1885 size_t hdrlen;
1886 u16 fc, type, stype, sc;
1887 struct net_device_stats *stats = NULL;
1888 unsigned int frag;
1889 u8 *payload;
1890 u16 ethertype;
1891 u8 TID = 0;
1892 u16 SeqNum = 0;
1893 PRX_TS_RECORD pTS = NULL;
1894#ifdef NOT_YET
1895 struct net_device *wds = NULL;
1896 struct sk_buff *skb2 = NULL;
1897 struct net_device *wds = NULL;
1898 int frame_authorized = 0;
1899 int from_assoc_ap = 0;
1900 void *sta = NULL;
1901#endif
1902 u8 dst[ETH_ALEN];
1903 u8 src[ETH_ALEN];
1904 u8 bssid[ETH_ALEN] = {0};
1905 u8 zero_addr[ETH_ALEN] = {0};
1906 struct rtllib_crypt_data *crypt = NULL;
1907 int keyidx = 0;
1908#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
1909 struct sta_info * psta = NULL;
1910#endif
1911 bool unicast_packet = false;
1912 int i;
1913 struct rtllib_rxb* rxb = NULL;
1914 int multicast = 0;
1915 bool tmp_dump = false;
1916 bool bToOtherSTA = false;
1917 hdr = (struct rtllib_hdr_4addr *)skb->data;
1918 stats = &ieee->stats;
1919
1920 multicast = is_multicast_ether_addr(hdr->addr1)|is_broadcast_ether_addr(hdr->addr1);
1921 if (!multicast && (compare_ether_addr(dev->dev_addr, hdr->addr1) != 0)) {
1922 if ((ieee->iw_mode == IW_MODE_MONITOR) || ieee->bNetPromiscuousMode){
1923 bToOtherSTA = true;
1924 }else{
1925 goto rx_dropped;
1926 }
1927 }
1928
1929 fc = le16_to_cpu(hdr->frame_ctl);
1930 type = WLAN_FC_GET_TYPE(fc);
1931 stype = WLAN_FC_GET_STYPE(fc);
1932 sc = le16_to_cpu(hdr->seq_ctl);
1933 frag = WLAN_GET_SEQ_FRAG(sc);
1934
1935 ieee->need_sw_enc = 0;
1936
1937 hdrlen = rtllib_get_hdrlen(fc);
1938 if (skb->len < hdrlen){
1939 printk("%s():ERR!!! skb->len is smaller than hdrlen\n",__func__);
1940 goto rx_dropped;
1941 }
1942
1943 if (HTCCheck(ieee, skb->data)) {
1944 if (net_ratelimit())
1945 printk("find HTCControl\n");
1946 hdrlen += 4;
1947 rx_stats->bContainHTC = 1;
1948 }
1949 if (RTLLIB_QOS_HAS_SEQ(fc))
1950 rx_stats->bIsQosData = 1;
1951 if ((0) && (type == RTLLIB_FTYPE_DATA) && ((is_broadcast_ether_addr(hdr->addr1)) || (compare_ether_addr(dev->dev_addr, hdr->addr1) == 0))) {
1952 printk("===>RX data before decrypt\n");
1953 tmp_dump = true;
1954 dump_buf(skb->data,skb->len);
1955 }
1956#ifdef NOT_YET
1957 hostap_update_rx_stats(local->ap, hdr, rx_stats);
1958#endif
1959
1960 if (ieee->host_decrypt) {
1961 int idx = 0;
1962 if (skb->len >= hdrlen + 3)
1963 idx = skb->data[hdrlen + 3] >> 6;
1964 crypt = ieee->crypt[idx];
1965#ifdef NOT_YET
1966 sta = NULL;
1967
1968 /* Use station specific key to override default keys if the
1969 * receiver address is a unicast address ("individual RA"). If
1970 * bcrx_sta_key parameter is set, station specific key is used
1971 * even with broad/multicast targets (this is against IEEE
1972 * 802.11, but makes it easier to use different keys with
1973 * stations that do not support WEP key mapping). */
1974
1975 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1976 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1977 &sta);
1978#endif
1979
1980 /* allow NULL decrypt to indicate an station specific override
1981 * for default encryption */
1982 if (crypt && (crypt->ops == NULL ||
1983 crypt->ops->decrypt_mpdu == NULL))
1984 crypt = NULL;
1985
1986 if (!crypt && (fc & RTLLIB_FCTL_WEP)) {
1987 /* This seems to be triggered by some (multicast?)
1988 * frames from other than current BSS, so just drop the
1989 * frames silently instead of filling system log with
1990 * these reports. */
1991 RTLLIB_DEBUG_DROP("Decryption failed (not set)"
1992 " (SA=" MAC_FMT ")\n",
1993 MAC_ARG(hdr->addr2));
1994 ieee->ieee_stats.rx_discards_undecryptable++;
1995 goto rx_dropped;
1996 }
1997 }
1998
1999 if (skb->len < RTLLIB_DATA_HDR3_LEN)
2000 goto rx_dropped;
2001
2002 if ( (ieee->pHTInfo->bCurRxReorderEnable == false) ||
2003 !ieee->current_network.qos_data.active ||
2004 !IsDataFrame(skb->data) ||
2005 IsLegacyDataFrame(skb->data)) {
2006 if (!((type == RTLLIB_FTYPE_MGMT) && (stype == RTLLIB_STYPE_BEACON))){
2007 if (is_duplicate_packet(ieee, hdr)){
2008 goto rx_dropped;
2009 }
2010 }
2011 } else {
2012 PRX_TS_RECORD pRxTS = NULL;
2013 if (GetTs(ieee, (PTS_COMMON_INFO*) &pRxTS, hdr->addr2,
2014 (u8)Frame_QoSTID((u8*)(skb->data)), RX_DIR, true)) {
2015 if ((fc & (1<<11)) && (frag == pRxTS->RxLastFragNum) &&
2016 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum)) {
2017 goto rx_dropped;
2018 } else {
2019 pRxTS->RxLastFragNum = frag;
2020 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
2021 }
2022 } else {
2023 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!%s(): No TS!! Skip the check!!\n",__func__);
2024 goto rx_dropped;
2025 }
2026 }
2027 if (type == RTLLIB_FTYPE_MGMT) {
2028 if (bToOtherSTA)
2029 goto rx_dropped;
2030 if (rtllib_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
2031 goto rx_dropped;
2032 else
2033 goto rx_exit;
2034 }
2035 if (type == RTLLIB_FTYPE_CTL) {
2036 goto rx_dropped;
2037 }
2038 /* Data frame - extract src/dst addresses */
2039 switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
2040 case RTLLIB_FCTL_FROMDS:
2041 memcpy(dst, hdr->addr1, ETH_ALEN);
2042 memcpy(src, hdr->addr3, ETH_ALEN);
2043 memcpy(bssid, hdr->addr2, ETH_ALEN);
2044 break;
2045 case RTLLIB_FCTL_TODS:
2046 memcpy(dst, hdr->addr3, ETH_ALEN);
2047 memcpy(src, hdr->addr2, ETH_ALEN);
2048 memcpy(bssid, hdr->addr1, ETH_ALEN);
2049 break;
2050 case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
2051 if (skb->len < RTLLIB_DATA_HDR4_LEN)
2052 goto rx_dropped;
2053 memcpy(dst, hdr->addr3, ETH_ALEN);
2054 memcpy(src, hdr->addr4, ETH_ALEN);
2055 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
2056 break;
2057 case 0:
2058 memcpy(dst, hdr->addr1, ETH_ALEN);
2059 memcpy(src, hdr->addr2, ETH_ALEN);
2060 memcpy(bssid, hdr->addr3, ETH_ALEN);
2061 break;
2062 }
2063
2064 /* Filter frames from different BSS */
2065 if ((type != RTLLIB_FTYPE_CTL) && ((fc & RTLLIB_FCTL_DSTODS) != RTLLIB_FCTL_DSTODS)
2066 && (compare_ether_addr(ieee->current_network.bssid, bssid) != 0) && memcmp(ieee->current_network.bssid, zero_addr, ETH_ALEN)) {
2067 goto rx_dropped;
2068 }
2069
2070 /* Filter packets sent by an STA that will be forwarded by AP */
2071 if ( ieee->IntelPromiscuousModeInfo.bPromiscuousOn &&
2072 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame ) {
2073 if ((fc & RTLLIB_FCTL_TODS) && !(fc & RTLLIB_FCTL_FROMDS) &&
2074 (compare_ether_addr(dst, ieee->current_network.bssid) != 0) &&
2075 (compare_ether_addr(bssid, ieee->current_network.bssid) == 0)) {
2076 goto rx_dropped;
2077 }
2078 }
2079
2080#ifdef NOT_YET
2081 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
2082 goto rx_dropped;
2083 if (wds) {
2084 skb->dev = dev = wds;
2085 stats = hostap_get_stats(dev);
2086 }
2087
2088 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
2089 (fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) == RTLLIB_FCTL_FROMDS &&
2090 ieee->stadev &&
2091 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
2092 /* Frame from BSSID of the AP for which we are a client */
2093 skb->dev = dev = ieee->stadev;
2094 stats = hostap_get_stats(dev);
2095 from_assoc_ap = 1;
2096 }
2097#endif
2098
2099 dev->last_rx = jiffies;
2100
2101#ifdef NOT_YET
2102 if ((ieee->iw_mode == IW_MODE_MASTER ||
2103 ieee->iw_mode == IW_MODE_REPEAT) &&
2104 !from_assoc_ap) {
2105 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
2106 wds != NULL)) {
2107 case AP_RX_CONTINUE_NOT_AUTHORIZED:
2108 frame_authorized = 0;
2109 break;
2110 case AP_RX_CONTINUE:
2111 frame_authorized = 1;
2112 break;
2113 case AP_RX_DROP:
2114 goto rx_dropped;
2115 case AP_RX_EXIT:
2116 goto rx_exit;
2117 }
2118 }
2119#endif
2120 /* Nullfunc frames may have PS-bit set, so they must be passed to
2121 * hostap_handle_sta_rx() before being dropped here. */
2122 if (stype != RTLLIB_STYPE_DATA &&
2123 stype != RTLLIB_STYPE_DATA_CFACK &&
2124 stype != RTLLIB_STYPE_DATA_CFPOLL &&
2125 stype != RTLLIB_STYPE_DATA_CFACKPOLL&&
2126 stype != RTLLIB_STYPE_QOS_DATA
2127 ) {
2128 if (stype != RTLLIB_STYPE_NULLFUNC)
2129 RTLLIB_DEBUG_DROP(
2130 "RX: dropped data frame "
2131 "with no data (type=0x%02x, "
2132 "subtype=0x%02x, len=%d)\n",
2133 type, stype, skb->len);
2134 goto rx_dropped;
2135 }
2136
2137 if (skb->len == hdrlen){
2138 goto rx_dropped;
2139 }
2140
2141 {
2142 /* network filter more precisely */
2143 switch (ieee->iw_mode) {
2144 case IW_MODE_ADHOC:
2145 /* packets from our adapter are dropped (echo) */
2146 if (!memcmp(hdr->addr2, dev->dev_addr, ETH_ALEN))
2147 goto rx_dropped;
2148
2149 /* {broad,multi}cast packets to our BSSID go through */
2150 if (is_multicast_ether_addr(hdr->addr1)) {
2151 if (!memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))
2152 break;
2153 else
2154 goto rx_dropped;
2155 }
2156
2157 /* packets not to our adapter, just discard it */
2158 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2159 if (bToOtherSTA)
2160 break;
2161 else
2162 goto rx_dropped;
2163 }
2164
2165 break;
2166
2167 case IW_MODE_INFRA:
2168 /* packets from our adapter are dropped (echo) */
2169 if (!memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN))
2170 goto rx_dropped;
2171
2172 /* {broad,multi}cast packets to our BSS go through */
2173 if (is_multicast_ether_addr(hdr->addr1)) {
2174 if (!memcmp(hdr->addr2, ieee->current_network.bssid, ETH_ALEN))
2175 break;
2176 else
2177 goto rx_dropped;
2178 }
2179
2180 /* packets to our adapter go through */
2181 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2182 if (bToOtherSTA)
2183 break;
2184 else
2185 goto rx_dropped;
2186 }
2187
2188 break;
2189 }
2190
2191
2192 }
2193
2194 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == LPS_IS_SLEEP)
2195 && (ieee->polling)) {
2196 if (WLAN_FC_MORE_DATA(fc)) {
2197 /* more data bit is set, let's request a new frame from the AP */
2198 rtllib_sta_ps_send_pspoll_frame(ieee);
2199 } else {
2200 ieee->polling = false;
2201 }
2202 }
2203
2204#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
2205 if (ieee->iw_mode == IW_MODE_ADHOC){
2206 psta = GetStaInfo(ieee, src);
2207 if (NULL != psta)
2208 psta->LastActiveTime = jiffies;
2209 }
2210#endif
2211 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
2212 if ((!rx_stats->Decrypted)){
2213 ieee->need_sw_enc = 1;
2214 }
2215
2216 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
2217 ((keyidx = rtllib_rx_frame_decrypt(ieee, skb, crypt)) < 0)) {
2218 printk("decrypt frame error\n");
2219 goto rx_dropped;
2220 }
2221 if (tmp_dump) {
2222 printk("************after decrypt\n");
2223 dump_buf(skb->data,skb->len);
2224 }
2225 hdr = (struct rtllib_hdr_4addr *) skb->data;
2226
2227 /* skb: hdr + (possibly fragmented) plaintext payload */
2228 if ((frag != 0 || (fc & RTLLIB_FCTL_MOREFRAGS))) {
2229 int flen;
2230 struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
2231 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
2232
2233 if (!frag_skb) {
2234 RTLLIB_DEBUG(RTLLIB_DL_RX | RTLLIB_DL_FRAG,
2235 "Rx cannot get skb from fragment "
2236 "cache (morefrag=%d seq=%u frag=%u)\n",
2237 (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
2238 WLAN_GET_SEQ_SEQ(sc), frag);
2239 goto rx_dropped;
2240 }
2241 flen = skb->len;
2242 if (frag != 0)
2243 flen -= hdrlen;
2244
2245 if (frag_skb->tail + flen > frag_skb->end) {
2246 printk(KERN_WARNING "%s: host decrypted and "
2247 "reassembled frame did not fit skb\n",
2248 dev->name);
2249 rtllib_frag_cache_invalidate(ieee, hdr);
2250 goto rx_dropped;
2251 }
2252
2253 if (frag == 0) {
2254 /* copy first fragment (including full headers) into
2255 * beginning of the fragment cache skb */
2256 memcpy(skb_put(frag_skb, flen), skb->data, flen);
2257 } else {
2258 /* append frame payload to the end of the fragment
2259 * cache skb */
2260 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
2261 flen);
2262 }
2263 dev_kfree_skb_any(skb);
2264 skb = NULL;
2265
2266 if (fc & RTLLIB_FCTL_MOREFRAGS) {
2267 /* more fragments expected - leave the skb in fragment
2268 * cache for now; it will be delivered to upper layers
2269 * after all fragments have been received */
2270 goto rx_exit;
2271 }
2272
2273 /* this was the last fragment and the frame will be
2274 * delivered, so remove skb from fragment cache */
2275 skb = frag_skb;
2276 hdr = (struct rtllib_hdr_4addr *) skb->data;
2277 rtllib_frag_cache_invalidate(ieee, hdr);
2278 }
2279
2280 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
2281 * encrypted/authenticated */
2282 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
2283 rtllib_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
2284 printk("==>decrypt msdu error\n");
2285 goto rx_dropped;
2286 }
2287
2288 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
2289 ieee->LinkDetectInfo.NumRxOkInPeriod++;
2290
2291 hdr = (struct rtllib_hdr_4addr *) skb->data;
2292 if ((!is_multicast_ether_addr(hdr->addr1)) && (!is_broadcast_ether_addr(hdr->addr1)))
2293 unicast_packet = true;
2294 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep) {
2295 if (/*ieee->ieee802_1x &&*/
2296 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
2297
2298#ifdef CONFIG_RTLLIB_DEBUG
2299 /* pass unencrypted EAPOL frames even if encryption is
2300 * configured */
2301 struct eapol *eap = (struct eapol *)(skb->data +
2302 24);
2303 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
2304 eap_get_type(eap->type));
2305#endif
2306 } else {
2307 RTLLIB_DEBUG_DROP(
2308 "encryption configured, but RX "
2309 "frame not encrypted (SA=" MAC_FMT ")\n",
2310 MAC_ARG(hdr->addr2));
2311 goto rx_dropped;
2312 }
2313 }
2314
2315#ifdef CONFIG_RTLLIB_DEBUG
2316 if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
2317 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
2318 struct eapol *eap = (struct eapol *)(skb->data +
2319 24);
2320 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
2321 eap_get_type(eap->type));
2322 }
2323#endif
2324
2325 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
2326 !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
2327 RTLLIB_DEBUG_DROP(
2328 "dropped unencrypted RX data "
2329 "frame from " MAC_FMT
2330 " (drop_unencrypted=1)\n",
2331 MAC_ARG(hdr->addr2));
2332 goto rx_dropped;
2333 }
2334 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
2335 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1)) {
2336 TID = Frame_QoSTID(skb->data);
2337 SeqNum = WLAN_GET_SEQ_SEQ(sc);
2338 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
2339 if (TID !=0 && TID !=3)
2340 ieee->bis_any_nonbepkts = true;
2341 }
2342 /* skb: hdr + (possible reassembled) full plaintext payload */
2343 payload = skb->data + hdrlen;
2344 rxb = (struct rtllib_rxb*)kmalloc(sizeof(struct rtllib_rxb),GFP_ATOMIC);
2345 if (rxb == NULL) {
2346 RTLLIB_DEBUG(RTLLIB_DL_ERR,"%s(): kmalloc rxb error\n",__func__);
2347 goto rx_dropped;
2348 }
2349 /* to parse amsdu packets */
2350 /* qos data packets & reserved bit is 1 */
2351 if (parse_subframe(ieee,skb,rx_stats,rxb,src,dst) == 0) {
2352 /* only to free rxb, and not submit the packets to upper layer */
2353 for (i =0; i < rxb->nr_subframes; i++) {
2354 dev_kfree_skb(rxb->subframes[i]);
2355 }
2356 kfree(rxb);
2357 rxb = NULL;
2358 goto rx_dropped;
2359 }
2360#if !defined(RTL8192SU) && !defined(RTL8192U)
2361 if (unicast_packet) {
2362 if (type == RTLLIB_FTYPE_DATA) {
2363 if (ieee->bIsAggregateFrame)
2364 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod+=rxb->nr_subframes;
2365 else
2366 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod++;
2367
2368 if ((ieee->state == RTLLIB_LINKED) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/) {
2369 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
2370 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) {
2371 if (ieee->LeisurePSLeave)
2372 ieee->LeisurePSLeave(dev);
2373 }
2374 }
2375 }
2376 }
2377#endif
2378 ieee->last_rx_ps_time = jiffies;
2379 if (ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL || bToOtherSTA ){
2380 for (i = 0; i<rxb->nr_subframes; i++) {
2381 struct sk_buff *sub_skb = rxb->subframes[i];
2382
2383 if (sub_skb) {
2384 /* convert hdr + possible LLC headers into Ethernet header */
2385 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
2386 if (sub_skb->len >= 8 &&
2387 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
2388 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
2389 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
2390 /* remove RFC1042 or Bridge-Tunnel encapsulation and
2391 * replace EtherType */
2392 skb_pull(sub_skb, SNAP_SIZE);
2393 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
2394 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
2395 } else {
2396 u16 len;
2397 /* Leave Ethernet header part of hdr and full payload */
2398 len = htons(sub_skb->len);
2399 memcpy(skb_push(sub_skb, 2), &len, 2);
2400 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
2401 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
2402 }
2403
2404 stats->rx_packets++;
2405 stats->rx_bytes += sub_skb->len;
2406
2407 if (is_multicast_ether_addr(dst)) {
2408 stats->multicast++;
2409 }
2410
2411 /* Indicat the packets to upper layer */
2412 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
2413 sub_skb->protocol = eth_type_trans(sub_skb, dev);
2414 sub_skb->dev = dev;
2415 sub_skb->dev->stats.rx_packets++;
2416 sub_skb->dev->stats.rx_bytes += sub_skb->len;
2417#ifdef TCP_CSUM_OFFLOAD_RX
2418 if ( rx_stats->tcp_csum_valid)
2419 sub_skb->ip_summed = CHECKSUM_UNNECESSARY;
2420 else
2421 sub_skb->ip_summed = CHECKSUM_NONE;
2422#else
2423 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
2424#endif
2425
2426 netif_rx(sub_skb);
2427 }
2428 }
2429 kfree(rxb);
2430 rxb = NULL;
2431
2432 }
2433 else
2434 {
2435 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__func__);
2436#ifdef TCP_CSUM_OFFLOAD_RX
2437 rxb->tcp_csum_valid = rx_stats->tcp_csum_valid;
2438#endif
2439 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
2440 }
2441#ifndef JOHN_NOCPY
2442 dev_kfree_skb(skb);
2443#endif
2444
2445 rx_exit:
2446#ifdef NOT_YET
2447 if (sta)
2448 hostap_handle_sta_release(sta);
2449#endif
2450 return 1;
2451
2452 rx_dropped:
2453 if (rxb != NULL)
2454 {
2455 kfree(rxb);
2456 rxb = NULL;
2457 }
2458 stats->rx_dropped++;
2459
2460 /* Returning 0 indicates to caller that we have not handled the SKB--
2461 * so it is still allocated and can be used again by underlying
2462 * hardware as a DMA target */
2463 return 0;
2464}
2465#endif
2466
2467#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
2468
2469static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
2470
2471/*
2472* Make ther structure we read from the beacon packet has
2473* the right values
2474*/
2475static int rtllib_verify_qos_info(struct rtllib_qos_information_element
2476 *info_element, int sub_type)
2477{
2478
2479 if (info_element->qui_subtype != sub_type)
2480 return -1;
2481 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
2482 return -1;
2483 if (info_element->qui_type != QOS_OUI_TYPE)
2484 return -1;
2485 if (info_element->version != QOS_VERSION_1)
2486 return -1;
2487
2488 return 0;
2489}
2490
2491
2492/*
2493 * Parse a QoS parameter element
2494 */
2495static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
2496 *element_param, struct rtllib_info_element
2497 *info_element)
2498{
2499 int ret = 0;
2500 u16 size = sizeof(struct rtllib_qos_parameter_info) - 2;
2501
2502 if ((info_element == NULL) || (element_param == NULL))
2503 return -1;
2504
2505 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
2506 memcpy(element_param->info_element.qui, info_element->data,
2507 info_element->len);
2508 element_param->info_element.elementID = info_element->id;
2509 element_param->info_element.length = info_element->len;
2510 } else
2511 ret = -1;
2512 if (ret == 0)
2513 ret = rtllib_verify_qos_info(&element_param->info_element,
2514 QOS_OUI_PARAM_SUB_TYPE);
2515 return ret;
2516}
2517
2518/*
2519 * Parse a QoS information element
2520 */
2521static int rtllib_read_qos_info_element(struct
2522 rtllib_qos_information_element
2523 *element_info, struct rtllib_info_element
2524 *info_element)
2525{
2526 int ret = 0;
2527 u16 size = sizeof(struct rtllib_qos_information_element) - 2;
2528
2529 if (element_info == NULL)
2530 return -1;
2531 if (info_element == NULL)
2532 return -1;
2533
2534 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
2535 memcpy(element_info->qui, info_element->data,
2536 info_element->len);
2537 element_info->elementID = info_element->id;
2538 element_info->length = info_element->len;
2539 } else
2540 ret = -1;
2541
2542 if (ret == 0)
2543 ret = rtllib_verify_qos_info(element_info,
2544 QOS_OUI_INFO_SUB_TYPE);
2545 return ret;
2546}
2547
2548
2549/*
2550 * Write QoS parameters from the ac parameters.
2551 */
2552static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info *param_elm,
2553 struct rtllib_qos_data *qos_data)
2554{
2555 struct rtllib_qos_ac_parameter *ac_params;
2556 struct rtllib_qos_parameters *qos_param = &(qos_data->parameters);
2557 int rc = 0;
2558 int i;
2559 u8 aci;
2560 u8 acm;
2561
2562 qos_data->wmm_acm = 0;
2563 for (i = 0; i < QOS_QUEUE_NUM; i++) {
2564 ac_params = &(param_elm->ac_params_record[i]);
2565
2566 aci = (ac_params->aci_aifsn & 0x60) >> 5;
2567 acm = (ac_params->aci_aifsn & 0x10) >> 4;
2568
2569 if (aci >= QOS_QUEUE_NUM)
2570 continue;
2571 switch (aci) {
2572 case 1:
2573 /* BIT(0) | BIT(3) */
2574 if (acm)
2575 qos_data->wmm_acm |= (0x01<<0)|(0x01<<3);
2576 break;
2577 case 2:
2578 /* BIT(4) | BIT(5) */
2579 if (acm)
2580 qos_data->wmm_acm |= (0x01<<4)|(0x01<<5);
2581 break;
2582 case 3:
2583 /* BIT(6) | BIT(7) */
2584 if (acm)
2585 qos_data->wmm_acm |= (0x01<<6)|(0x01<<7);
2586 break;
2587 case 0:
2588 default:
2589 /* BIT(1) | BIT(2) */
2590 if (acm)
2591 qos_data->wmm_acm |= (0x01<<1)|(0x01<<2);
2592 break;
2593 }
2594
2595 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
2596
2597 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
2598 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
2599
2600 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
2601
2602 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
2603
2604 qos_param->flag[aci] =
2605 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
2606 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
2607 }
2608 return rc;
2609}
2610
2611/*
2612 * we have a generic data element which it may contain QoS information or
2613 * parameters element. check the information element length to decide
2614 * which type to read
2615 */
2616static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
2617 *info_element,
2618 struct rtllib_network *network)
2619{
2620 int rc = 0;
2621 struct rtllib_qos_information_element qos_info_element;
2622
2623 rc = rtllib_read_qos_info_element(&qos_info_element, info_element);
2624
2625 if (rc == 0) {
2626 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
2627 network->flags |= NETWORK_HAS_QOS_INFORMATION;
2628 } else {
2629 struct rtllib_qos_parameter_info param_element;
2630
2631 rc = rtllib_read_qos_param_element(&param_element,
2632 info_element);
2633 if (rc == 0) {
2634 rtllib_qos_convert_ac_to_parameters(&param_element,
2635 &(network->qos_data));
2636 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
2637 network->qos_data.param_count =
2638 param_element.info_element.ac_info & 0x0F;
2639 }
2640 }
2641
2642 if (rc == 0) {
2643 RTLLIB_DEBUG_QOS("QoS is supported\n");
2644 network->qos_data.supported = 1;
2645 }
2646 return rc;
2647}
2648
2649#ifdef CONFIG_RTLLIB_DEBUG
2650#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
2651
2652static const char *get_info_element_string(u16 id)
2653{
2654 switch (id) {
2655 MFIE_STRING(SSID);
2656 MFIE_STRING(RATES);
2657 MFIE_STRING(FH_SET);
2658 MFIE_STRING(DS_SET);
2659 MFIE_STRING(CF_SET);
2660 MFIE_STRING(TIM);
2661 MFIE_STRING(IBSS_SET);
2662 MFIE_STRING(COUNTRY);
2663 MFIE_STRING(HOP_PARAMS);
2664 MFIE_STRING(HOP_TABLE);
2665 MFIE_STRING(REQUEST);
2666 MFIE_STRING(CHALLENGE);
2667 MFIE_STRING(POWER_CONSTRAINT);
2668 MFIE_STRING(POWER_CAPABILITY);
2669 MFIE_STRING(TPC_REQUEST);
2670 MFIE_STRING(TPC_REPORT);
2671 MFIE_STRING(SUPP_CHANNELS);
2672 MFIE_STRING(CSA);
2673 MFIE_STRING(MEASURE_REQUEST);
2674 MFIE_STRING(MEASURE_REPORT);
2675 MFIE_STRING(QUIET);
2676 MFIE_STRING(IBSS_DFS);
2677 MFIE_STRING(RSN);
2678 MFIE_STRING(RATES_EX);
2679 MFIE_STRING(GENERIC);
2680 MFIE_STRING(QOS_PARAMETER);
2681 default:
2682 return "UNKNOWN";
2683 }
2684}
2685#endif
2686
2687#ifdef ENABLE_DOT11D
2688static inline void rtllib_extract_country_ie(
2689 struct rtllib_device *ieee,
2690 struct rtllib_info_element *info_element,
2691 struct rtllib_network *network,
2692 u8 * addr2)
2693{
2694 if (IS_DOT11D_ENABLE(ieee)) {
2695 if (info_element->len!= 0) {
2696 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
2697 network->CountryIeLen = info_element->len;
2698
2699 if (!IS_COUNTRY_IE_VALID(ieee))
2700 {
2701 if ((rtllib_act_scanning(ieee,false) == true) && (ieee->FirstIe_InScan == 1))
2702 printk("Received beacon ContryIE, SSID: <%s>\n",network->ssid);
2703 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
2704 }
2705 }
2706
2707 if (IS_EQUAL_CIE_SRC(ieee, addr2)) {
2708 UPDATE_CIE_WATCHDOG(ieee);
2709 }
2710 }
2711
2712}
2713#endif
2714
2715int rtllib_parse_info_param(struct rtllib_device *ieee,
2716 struct rtllib_info_element *info_element,
2717 u16 length,
2718 struct rtllib_network *network,
2719 struct rtllib_rx_stats *stats)
2720{
2721 u8 i;
2722 short offset;
2723 u16 tmp_htcap_len=0;
2724 u16 tmp_htinfo_len=0;
2725 u16 ht_realtek_agg_len=0;
2726 u8 ht_realtek_agg_buf[MAX_IE_LEN];
2727#ifdef CONFIG_RTLLIB_DEBUG
2728 char rates_str[64];
2729 char *p;
2730#endif
2731 while (length >= sizeof(*info_element)) {
2732 if (sizeof(*info_element) + info_element->len > length) {
2733 RTLLIB_DEBUG_MGMT("Info elem: parse failed: "
2734 "info_element->len + 2 > left : "
2735 "info_element->len+2=%zd left=%d, id=%d.\n",
2736 info_element->len +
2737 sizeof(*info_element),
2738 length, info_element->id);
2739 /* We stop processing but don't return an error here
2740 * because some misbehaviour APs break this rule. ie.
2741 * Orinoco AP1000. */
2742 break;
2743 }
2744
2745 switch (info_element->id) {
2746 case MFIE_TYPE_SSID:
2747 if (rtllib_is_empty_essid(info_element->data,
2748 info_element->len)) {
2749 network->flags |= NETWORK_EMPTY_ESSID;
2750 break;
2751 }
2752
2753 network->ssid_len = min(info_element->len,
2754 (u8) IW_ESSID_MAX_SIZE);
2755 memcpy(network->ssid, info_element->data, network->ssid_len);
2756 if (network->ssid_len < IW_ESSID_MAX_SIZE)
2757 memset(network->ssid + network->ssid_len, 0,
2758 IW_ESSID_MAX_SIZE - network->ssid_len);
2759
2760 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
2761 network->ssid, network->ssid_len);
2762 break;
2763
2764 case MFIE_TYPE_RATES:
2765#ifdef CONFIG_RTLLIB_DEBUG
2766 p = rates_str;
2767#endif
2768 network->rates_len = min(info_element->len,
2769 MAX_RATES_LENGTH);
2770 for (i = 0; i < network->rates_len; i++) {
2771 network->rates[i] = info_element->data[i];
2772#ifdef CONFIG_RTLLIB_DEBUG
2773 p += snprintf(p, sizeof(rates_str) -
2774 (p - rates_str), "%02X ",
2775 network->rates[i]);
2776#endif
2777 if (rtllib_is_ofdm_rate
2778 (info_element->data[i])) {
2779 network->flags |= NETWORK_HAS_OFDM;
2780 if (info_element->data[i] &
2781 RTLLIB_BASIC_RATE_MASK)
2782 network->flags &=
2783 ~NETWORK_HAS_CCK;
2784 }
2785
2786 if (rtllib_is_cck_rate
2787 (info_element->data[i])) {
2788 network->flags |= NETWORK_HAS_CCK;
2789 }
2790 }
2791
2792 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
2793 rates_str, network->rates_len);
2794 break;
2795
2796 case MFIE_TYPE_RATES_EX:
2797#ifdef CONFIG_RTLLIB_DEBUG
2798 p = rates_str;
2799#endif
2800 network->rates_ex_len = min(info_element->len,
2801 MAX_RATES_EX_LENGTH);
2802 for (i = 0; i < network->rates_ex_len; i++) {
2803 network->rates_ex[i] = info_element->data[i];
2804#ifdef CONFIG_RTLLIB_DEBUG
2805 p += snprintf(p, sizeof(rates_str) -
2806 (p - rates_str), "%02X ",
2807 network->rates[i]);
2808#endif
2809 if (rtllib_is_ofdm_rate
2810 (info_element->data[i])) {
2811 network->flags |= NETWORK_HAS_OFDM;
2812 if (info_element->data[i] &
2813 RTLLIB_BASIC_RATE_MASK)
2814 network->flags &=
2815 ~NETWORK_HAS_CCK;
2816 }
2817 }
2818
2819 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
2820 rates_str, network->rates_ex_len);
2821 break;
2822
2823 case MFIE_TYPE_DS_SET:
2824 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
2825 info_element->data[0]);
2826 network->channel = info_element->data[0];
2827 break;
2828
2829 case MFIE_TYPE_FH_SET:
2830 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
2831 break;
2832
2833 case MFIE_TYPE_CF_SET:
2834 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
2835 break;
2836
2837 case MFIE_TYPE_TIM:
2838 if (info_element->len < 4)
2839 break;
2840
2841 network->tim.tim_count = info_element->data[0];
2842 network->tim.tim_period = info_element->data[1];
2843
2844 network->dtim_period = info_element->data[1];
2845 if (ieee->state != RTLLIB_LINKED)
2846 break;
2847 network->last_dtim_sta_time[0] = jiffies;
2848 network->last_dtim_sta_time[1] = stats->mac_time[1];
2849
2850 network->dtim_data = RTLLIB_DTIM_VALID;
2851
2852
2853 if (info_element->data[2] & 1)
2854 network->dtim_data |= RTLLIB_DTIM_MBCAST;
2855
2856#if 1
2857 offset = (info_element->data[2] >> 1)*2;
2858
2859
2860 if (ieee->assoc_id < 8*offset ||
2861 ieee->assoc_id > 8*(offset + info_element->len -3))
2862
2863 break;
2864
2865 offset = (ieee->assoc_id / 8) - offset;
2866 if (info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
2867 network->dtim_data |= RTLLIB_DTIM_UCAST;
2868#else
2869 {
2870 u16 numSta = 0;
2871 u16 offset_byte = 0;
2872 u16 offset_bit = 0;
2873
2874 numSta = (info_element->data[2] &0xFE)*8;
2875
2876 if (ieee->assoc_id < numSta ||
2877 ieee->assoc_id > (numSta + (info_element->len -3)*8))
2878 break;
2879
2880 offset = ieee->assoc_id - numSta;
2881 offset_byte = offset / 8;
2882 offset_bit = offset % 8;
2883 if (info_element->data[3+offset_byte] & (0x01<<offset_bit))
2884 network->dtim_data |= RTLLIB_DTIM_UCAST;
2885 }
2886#endif
2887
2888 network->listen_interval = network->dtim_period;
2889 break;
2890
2891 case MFIE_TYPE_ERP:
2892 network->erp_value = info_element->data[0];
2893 network->flags |= NETWORK_HAS_ERP_VALUE;
2894 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
2895 network->erp_value);
2896 break;
2897 case MFIE_TYPE_IBSS_SET:
2898 network->atim_window = info_element->data[0];
2899 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
2900 network->atim_window);
2901 break;
2902
2903 case MFIE_TYPE_CHALLENGE:
2904 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
2905 break;
2906
2907 case MFIE_TYPE_GENERIC:
2908 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
2909 info_element->len);
2910 if (!rtllib_parse_qos_info_param_IE(info_element,
2911 network))
2912 break;
2913 if (info_element->len >= 4 &&
2914 info_element->data[0] == 0x00 &&
2915 info_element->data[1] == 0x50 &&
2916 info_element->data[2] == 0xf2 &&
2917 info_element->data[3] == 0x01) {
2918 network->wpa_ie_len = min(info_element->len + 2,
2919 MAX_WPA_IE_LEN);
2920 memcpy(network->wpa_ie, info_element,
2921 network->wpa_ie_len);
2922 break;
2923 }
2924 if (info_element->len == 7 &&
2925 info_element->data[0] == 0x00 &&
2926 info_element->data[1] == 0xe0 &&
2927 info_element->data[2] == 0x4c &&
2928 info_element->data[3] == 0x01 &&
2929 info_element->data[4] == 0x02)
2930 network->Turbo_Enable = 1;
2931
2932 if (tmp_htcap_len == 0) {
2933 if (info_element->len >= 4 &&
2934 info_element->data[0] == 0x00 &&
2935 info_element->data[1] == 0x90 &&
2936 info_element->data[2] == 0x4c &&
2937 info_element->data[3] == 0x033) {
2938
2939 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2940 if (tmp_htcap_len != 0){
2941 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2942 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2943 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2944 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2945 }
2946 }
2947 if (tmp_htcap_len != 0){
2948 network->bssht.bdSupportHT = true;
2949 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
2950 }else{
2951 network->bssht.bdSupportHT = false;
2952 network->bssht.bdHT1R = false;
2953 }
2954 }
2955
2956
2957 if (tmp_htinfo_len == 0){
2958 if (info_element->len >= 4 &&
2959 info_element->data[0] == 0x00 &&
2960 info_element->data[1] == 0x90 &&
2961 info_element->data[2] == 0x4c &&
2962 info_element->data[3] == 0x034){
2963
2964 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2965 if (tmp_htinfo_len != 0){
2966 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2967 if (tmp_htinfo_len){
2968 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2969 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2970 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2971 }
2972
2973 }
2974
2975 }
2976 }
2977
2978 if (ieee->aggregation){
2979 if (network->bssht.bdSupportHT){
2980 if (info_element->len >= 4 &&
2981 info_element->data[0] == 0x00 &&
2982 info_element->data[1] == 0xe0 &&
2983 info_element->data[2] == 0x4c &&
2984 info_element->data[3] == 0x02){
2985
2986 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
2987 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
2988
2989 }
2990 if (ht_realtek_agg_len >= 5){
2991 network->realtek_cap_exit = true;
2992 network->bssht.bdRT2RTAggregation = true;
2993
2994 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
2995 network->bssht.bdRT2RTLongSlotTime = true;
2996
2997 if ((ht_realtek_agg_buf[4]==1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
2998 {
2999 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
3000 }
3001 }
3002 }
3003 if (ht_realtek_agg_len >= 5){
3004 if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
3005 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_SOFTAP;
3006 }
3007 }
3008
3009 {
3010 if ((info_element->len >= 3 &&
3011 info_element->data[0] == 0x00 &&
3012 info_element->data[1] == 0x05 &&
3013 info_element->data[2] == 0xb5) ||
3014 (info_element->len >= 3 &&
3015 info_element->data[0] == 0x00 &&
3016 info_element->data[1] == 0x0a &&
3017 info_element->data[2] == 0xf7) ||
3018 (info_element->len >= 3 &&
3019 info_element->data[0] == 0x00 &&
3020 info_element->data[1] == 0x10 &&
3021 info_element->data[2] == 0x18)){
3022
3023 network->broadcom_cap_exist = true;
3024
3025 }
3026 }
3027 if (info_element->len >= 3 &&
3028 info_element->data[0] == 0x00 &&
3029 info_element->data[1] == 0x0c &&
3030 info_element->data[2] == 0x43)
3031 {
3032 network->ralink_cap_exist = true;
3033 }
3034 if ((info_element->len >= 3 &&
3035 info_element->data[0] == 0x00 &&
3036 info_element->data[1] == 0x03 &&
3037 info_element->data[2] == 0x7f) ||
3038 (info_element->len >= 3 &&
3039 info_element->data[0] == 0x00 &&
3040 info_element->data[1] == 0x13 &&
3041 info_element->data[2] == 0x74))
3042 {
3043 network->atheros_cap_exist = true;
3044 }
3045
3046 if ((info_element->len >= 3 &&
3047 info_element->data[0] == 0x00 &&
3048 info_element->data[1] == 0x50 &&
3049 info_element->data[2] == 0x43) )
3050 {
3051 network->marvell_cap_exist = true;
3052 }
3053 if (info_element->len >= 3 &&
3054 info_element->data[0] == 0x00 &&
3055 info_element->data[1] == 0x40 &&
3056 info_element->data[2] == 0x96)
3057 {
3058 network->cisco_cap_exist = true;
3059 }
3060
3061
3062 if (info_element->len >= 3 &&
3063 info_element->data[0] == 0x00 &&
3064 info_element->data[1] == 0x0a &&
3065 info_element->data[2] == 0xf5)
3066 {
3067 network->airgo_cap_exist = true;
3068 }
3069
3070 if (info_element->len > 4 &&
3071 info_element->data[0] == 0x00 &&
3072 info_element->data[1] == 0x40 &&
3073 info_element->data[2] == 0x96 &&
3074 info_element->data[3] == 0x01)
3075 {
3076 if (info_element->len == 6)
3077 {
3078 memcpy(network->CcxRmState, &info_element[4], 2);
3079 if (network->CcxRmState[0] != 0)
3080 {
3081 network->bCcxRmEnable = true;
3082 }
3083 else
3084 network->bCcxRmEnable = false;
3085 network->MBssidMask = network->CcxRmState[1] & 0x07;
3086 if (network->MBssidMask != 0)
3087 {
3088 network->bMBssidValid = true;
3089 network->MBssidMask = 0xff << (network->MBssidMask);
3090 memcpy(network->MBssid, network->bssid, ETH_ALEN);
3091 network->MBssid[5] &= network->MBssidMask;
3092 }
3093 else
3094 {
3095 network->bMBssidValid = false;
3096 }
3097 }
3098 else
3099 {
3100 network->bCcxRmEnable = false;
3101 }
3102 }
3103 if (info_element->len > 4 &&
3104 info_element->data[0] == 0x00 &&
3105 info_element->data[1] == 0x40 &&
3106 info_element->data[2] == 0x96 &&
3107 info_element->data[3] == 0x03)
3108 {
3109 if (info_element->len == 5)
3110 {
3111 network->bWithCcxVerNum = true;
3112 network->BssCcxVerNumber = info_element->data[4];
3113 }
3114 else
3115 {
3116 network->bWithCcxVerNum = false;
3117 network->BssCcxVerNumber = 0;
3118 }
3119 }
3120 if (info_element->len > 4 &&
3121 info_element->data[0] == 0x00 &&
3122 info_element->data[1] == 0x50 &&
3123 info_element->data[2] == 0xf2 &&
3124 info_element->data[3] == 0x04)
3125 {
3126 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
3127 info_element->len);
Larry Finger94a79942011-08-23 19:00:42 -05003128 network->wzc_ie_len = min(info_element->len+2,
3129 MAX_WZC_IE_LEN);
3130 memcpy(network->wzc_ie, info_element,
3131 network->wzc_ie_len);
Larry Finger94a79942011-08-23 19:00:42 -05003132 }
3133 break;
3134
3135 case MFIE_TYPE_RSN:
3136 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
3137 info_element->len);
3138 network->rsn_ie_len = min(info_element->len + 2,
3139 MAX_WPA_IE_LEN);
3140 memcpy(network->rsn_ie, info_element,
3141 network->rsn_ie_len);
3142 break;
3143
3144 case MFIE_TYPE_HT_CAP:
3145 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
3146 info_element->len);
3147 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
3148 if (tmp_htcap_len != 0){
3149 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
3150 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
3151 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
3152 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
3153
3154 network->bssht.bdSupportHT = true;
3155 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
3156
3157 network->bssht.bdBandWidth = (HT_CHANNEL_WIDTH)(((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->ChlWidth);
3158 }
3159 else{
3160 network->bssht.bdSupportHT = false;
3161 network->bssht.bdHT1R = false;
3162 network->bssht.bdBandWidth = HT_CHANNEL_WIDTH_20 ;
3163 }
3164 break;
3165
3166
3167 case MFIE_TYPE_HT_INFO:
3168 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
3169 info_element->len);
3170 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
3171 if (tmp_htinfo_len){
3172 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
3173 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
3174 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
3175 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
3176 }
3177 break;
3178
3179 case MFIE_TYPE_AIRONET:
3180 RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
3181 info_element->len);
3182 if (info_element->len >IE_CISCO_FLAG_POSITION)
3183 {
3184 network->bWithAironetIE = true;
3185
3186 if ( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
3187 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
3188 {
3189 network->bCkipSupported = true;
3190 }
3191 else
3192 {
3193 network->bCkipSupported = false;
3194 }
3195 }
3196 else
3197 {
3198 network->bWithAironetIE = false;
3199 network->bCkipSupported = false;
3200 }
3201 break;
3202 case MFIE_TYPE_QOS_PARAMETER:
3203 printk(KERN_ERR
3204 "QoS Error need to parse QOS_PARAMETER IE\n");
3205 break;
3206
3207#ifdef ENABLE_DOT11D
3208 case MFIE_TYPE_COUNTRY:
3209 RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
3210 info_element->len);
3211 rtllib_extract_country_ie(ieee, info_element, network, network->bssid);
3212 break;
3213#endif
3214/* TODO */
3215 default:
3216 RTLLIB_DEBUG_MGMT
3217 ("Unsupported info element: %s (%d)\n",
3218 get_info_element_string(info_element->id),
3219 info_element->id);
3220 break;
3221 }
3222
3223 length -= sizeof(*info_element) + info_element->len;
3224 info_element =
3225 (struct rtllib_info_element *)&info_element->
3226 data[info_element->len];
3227 }
3228
3229 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
3230 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation)
3231 {
3232 network->unknown_cap_exist = true;
3233 }
3234 else
3235 {
3236 network->unknown_cap_exist = false;
3237 }
3238 return 0;
3239}
3240
3241static inline u8 rtllib_SignalStrengthTranslate(
3242 u8 CurrSS
3243 )
3244{
3245 u8 RetSS;
3246
3247 if (CurrSS >= 71 && CurrSS <= 100)
3248 {
3249 RetSS = 90 + ((CurrSS - 70) / 3);
3250 }
3251 else if (CurrSS >= 41 && CurrSS <= 70)
3252 {
3253 RetSS = 78 + ((CurrSS - 40) / 3);
3254 }
3255 else if (CurrSS >= 31 && CurrSS <= 40)
3256 {
3257 RetSS = 66 + (CurrSS - 30);
3258 }
3259 else if (CurrSS >= 21 && CurrSS <= 30)
3260 {
3261 RetSS = 54 + (CurrSS - 20);
3262 }
3263 else if (CurrSS >= 5 && CurrSS <= 20)
3264 {
3265 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
3266 }
3267 else if (CurrSS == 4)
3268 {
3269 RetSS = 36;
3270 }
3271 else if (CurrSS == 3)
3272 {
3273 RetSS = 27;
3274 }
3275 else if (CurrSS == 2)
3276 {
3277 RetSS = 18;
3278 }
3279 else if (CurrSS == 1)
3280 {
3281 RetSS = 9;
3282 }
3283 else
3284 {
3285 RetSS = CurrSS;
3286 }
3287
3288
3289
3290 return RetSS;
3291}
3292
3293long rtllib_translate_todbm(u8 signal_strength_index )
3294{
3295 long signal_power;
3296
3297 signal_power = (long)((signal_strength_index + 1) >> 1);
3298 signal_power -= 95;
3299
3300 return signal_power;
3301}
3302
3303static inline int rtllib_network_init(
3304 struct rtllib_device *ieee,
3305 struct rtllib_probe_response *beacon,
3306 struct rtllib_network *network,
3307 struct rtllib_rx_stats *stats)
3308{
3309#ifdef CONFIG_RTLLIB_DEBUG
3310#endif
3311
3312 /*
3313 network->qos_data.active = 0;
3314 network->qos_data.supported = 0;
3315 network->qos_data.param_count = 0;
3316 network->qos_data.old_param_count = 0;
3317 */
3318 memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
3319
3320 /* Pull out fixed field data */
3321 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
3322 network->capability = le16_to_cpu(beacon->capability);
3323 network->last_scanned = jiffies;
3324 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
3325 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
3326 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
3327 /* Where to pull this? beacon->listen_interval;*/
3328 network->listen_interval = 0x0A;
3329 network->rates_len = network->rates_ex_len = 0;
3330 network->last_associate = 0;
3331 network->ssid_len = 0;
3332 network->hidden_ssid_len = 0;
3333 memset(network->hidden_ssid, 0, sizeof(network->hidden_ssid));
3334 network->flags = 0;
3335 network->atim_window = 0;
3336 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
3337 0x3 : 0x0;
3338 network->berp_info_valid = false;
3339 network->broadcom_cap_exist = false;
3340 network->ralink_cap_exist = false;
3341 network->atheros_cap_exist = false;
3342 network->cisco_cap_exist = false;
3343 network->unknown_cap_exist = false;
3344 network->realtek_cap_exit = false;
3345 network->marvell_cap_exist = false;
3346 network->airgo_cap_exist = false;
3347 network->Turbo_Enable = 0;
3348 network->SignalStrength = stats->SignalStrength;
3349 network->RSSI = stats->SignalStrength;
3350#ifdef ENABLE_DOT11D
3351 network->CountryIeLen = 0;
3352 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
3353#endif
3354 HTInitializeBssDesc(&network->bssht);
3355 if (stats->freq == RTLLIB_52GHZ_BAND) {
3356 /* for A band (No DS info) */
3357 network->channel = stats->received_channel;
3358 } else
3359 network->flags |= NETWORK_HAS_CCK;
3360
3361 network->wpa_ie_len = 0;
3362 network->rsn_ie_len = 0;
Larry Finger94a79942011-08-23 19:00:42 -05003363 network->wzc_ie_len = 0;
Larry Finger94a79942011-08-23 19:00:42 -05003364
3365 if (rtllib_parse_info_param(ieee,
3366 beacon->info_element,
3367 (stats->len - sizeof(*beacon)),
3368 network,
3369 stats))
3370 return 1;
3371
3372 network->mode = 0;
3373 if (stats->freq == RTLLIB_52GHZ_BAND)
3374 network->mode = IEEE_A;
3375 else {
3376 if (network->flags & NETWORK_HAS_OFDM)
3377 network->mode |= IEEE_G;
3378 if (network->flags & NETWORK_HAS_CCK)
3379 network->mode |= IEEE_B;
3380 }
3381
3382 if (network->mode == 0) {
3383 RTLLIB_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
3384 "network.\n",
3385 escape_essid(network->ssid,
3386 network->ssid_len),
3387 MAC_ARG(network->bssid));
3388 return 1;
3389 }
3390
3391 if (network->bssht.bdSupportHT){
3392 if (network->mode == IEEE_A)
3393 network->mode = IEEE_N_5G;
3394 else if (network->mode & (IEEE_G | IEEE_B))
3395 network->mode = IEEE_N_24G;
3396 }
3397 if (rtllib_is_empty_essid(network->ssid, network->ssid_len))
3398 network->flags |= NETWORK_EMPTY_ESSID;
3399 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
3400 stats->noise = rtllib_translate_todbm((u8)(100-stats->signal)) -25;
3401
3402 memcpy(&network->stats, stats, sizeof(network->stats));
3403
3404 return 0;
3405}
3406
3407static inline int is_same_network(struct rtllib_network *src,
3408 struct rtllib_network *dst, u8 ssidbroad)
3409{
3410 /* A network is only a duplicate if the channel, BSSID, ESSID
3411 * and the capability field (in particular IBSS and BSS) all match.
3412 * We treat all <hidden> with the same BSSID and channel
3413 * as one network */
3414 return
3415 (((src->ssid_len == dst->ssid_len) || (!ssidbroad)) &&
3416 (src->channel == dst->channel) &&
3417 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
3418 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (!ssidbroad)) &&
3419 ((src->capability & WLAN_CAPABILITY_IBSS) ==
3420 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
3421 ((src->capability & WLAN_CAPABILITY_ESS) ==
3422 (dst->capability & WLAN_CAPABILITY_ESS)));
3423}
3424
3425static inline void update_ibss_network(struct rtllib_network *dst,
3426 struct rtllib_network *src)
3427{
3428 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
3429 dst->last_scanned = jiffies;
3430}
3431
3432
3433static inline void update_network(struct rtllib_network *dst,
3434 struct rtllib_network *src)
3435{
3436 int qos_active;
3437 u8 old_param;
3438
3439 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
3440 dst->capability = src->capability;
3441 memcpy(dst->rates, src->rates, src->rates_len);
3442 dst->rates_len = src->rates_len;
3443 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
3444 dst->rates_ex_len = src->rates_ex_len;
3445 if (src->ssid_len > 0)
3446 {
3447 if (dst->ssid_len == 0)
3448 {
3449 memset(dst->hidden_ssid, 0, sizeof(dst->hidden_ssid));
3450 dst->hidden_ssid_len = src->ssid_len;
3451 memcpy(dst->hidden_ssid, src->ssid, src->ssid_len);
3452 }else{
3453 memset(dst->ssid, 0, dst->ssid_len);
3454 dst->ssid_len = src->ssid_len;
3455 memcpy(dst->ssid, src->ssid, src->ssid_len);
3456 }
3457 }
3458 dst->mode = src->mode;
3459 dst->flags = src->flags;
3460 dst->time_stamp[0] = src->time_stamp[0];
3461 dst->time_stamp[1] = src->time_stamp[1];
3462 if (src->flags & NETWORK_HAS_ERP_VALUE)
3463 {
3464 dst->erp_value = src->erp_value;
3465 dst->berp_info_valid = src->berp_info_valid = true;
3466 }
3467 dst->beacon_interval = src->beacon_interval;
3468 dst->listen_interval = src->listen_interval;
3469 dst->atim_window = src->atim_window;
3470 dst->dtim_period = src->dtim_period;
3471 dst->dtim_data = src->dtim_data;
3472 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
3473 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
3474 memcpy(&dst->tim, &src->tim, sizeof(struct rtllib_tim_parameters));
3475
3476 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
3477 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
3478 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
3479 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
3480 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
3481 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
3482 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
3483 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
3484 dst->broadcom_cap_exist = src->broadcom_cap_exist;
3485 dst->ralink_cap_exist = src->ralink_cap_exist;
3486 dst->atheros_cap_exist = src->atheros_cap_exist;
3487 dst->realtek_cap_exit = src->realtek_cap_exit;
3488 dst->marvell_cap_exist = src->marvell_cap_exist;
3489 dst->cisco_cap_exist = src->cisco_cap_exist;
3490 dst->airgo_cap_exist = src->airgo_cap_exist;
3491 dst->unknown_cap_exist = src->unknown_cap_exist;
3492 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
3493 dst->wpa_ie_len = src->wpa_ie_len;
3494 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
3495 dst->rsn_ie_len = src->rsn_ie_len;
Larry Finger94a79942011-08-23 19:00:42 -05003496 memcpy(dst->wzc_ie, src->wzc_ie, src->wzc_ie_len);
3497 dst->wzc_ie_len = src->wzc_ie_len;
Larry Finger94a79942011-08-23 19:00:42 -05003498
3499 dst->last_scanned = jiffies;
3500 /* qos related parameters */
3501 qos_active = dst->qos_data.active;
3502 old_param = dst->qos_data.param_count;
3503 dst->qos_data.supported = src->qos_data.supported;
3504 if (dst->flags & NETWORK_HAS_QOS_PARAMETERS)
3505 memcpy(&dst->qos_data, &src->qos_data, sizeof(struct rtllib_qos_data));
3506 if (dst->qos_data.supported == 1) {
3507 if (dst->ssid_len)
3508 RTLLIB_DEBUG_QOS
3509 ("QoS the network %s is QoS supported\n",
3510 dst->ssid);
3511 else
3512 RTLLIB_DEBUG_QOS
3513 ("QoS the network is QoS supported\n");
3514 }
3515 dst->qos_data.active = qos_active;
3516 dst->qos_data.old_param_count = old_param;
3517
3518 /* dst->last_associate is not overwritten */
3519 dst->wmm_info = src->wmm_info;
3520 if (src->wmm_param[0].ac_aci_acm_aifsn|| \
3521 src->wmm_param[1].ac_aci_acm_aifsn|| \
3522 src->wmm_param[2].ac_aci_acm_aifsn|| \
3523 src->wmm_param[1].ac_aci_acm_aifsn) {
3524 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
3525 }
3526
3527 dst->SignalStrength = src->SignalStrength;
3528 dst->RSSI = src->RSSI;
3529 dst->Turbo_Enable = src->Turbo_Enable;
3530
3531#ifdef ENABLE_DOT11D
3532 dst->CountryIeLen = src->CountryIeLen;
3533 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
3534#endif
3535
3536 dst->bWithAironetIE = src->bWithAironetIE;
3537 dst->bCkipSupported = src->bCkipSupported;
3538 memcpy(dst->CcxRmState,src->CcxRmState,2);
3539 dst->bCcxRmEnable = src->bCcxRmEnable;
3540 dst->MBssidMask = src->MBssidMask;
3541 dst->bMBssidValid = src->bMBssidValid;
3542 memcpy(dst->MBssid,src->MBssid,6);
3543 dst->bWithCcxVerNum = src->bWithCcxVerNum;
3544 dst->BssCcxVerNumber = src->BssCcxVerNumber;
3545
3546}
3547static inline int is_beacon(__le16 fc)
3548{
3549 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == RTLLIB_STYPE_BEACON);
3550}
3551
3552#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3553u8 AsocEntry_ComputeSum(u8 *paddr)
3554{
3555 u32 sum;
3556
3557 sum = paddr[0]+
3558 paddr[1]+
3559 paddr[2]+
3560 paddr[3]+
3561 paddr[4]+
3562 paddr[5];
3563
3564 return (u8)(sum % PEER_MAX_ASSOC);
3565}
3566u8 AsocEntry_AssignAvailableAID(struct rtllib_device *ieee, u8 *paddr)
3567{
3568 int i;
3569
3570 for (i = 0; i < PEER_MAX_ASSOC; i++)
3571 {
3572 if (ieee->AvailableAIDTable[i] == 99)
3573 {
3574 ieee->AvailableAIDTable[i] = AsocEntry_ComputeSum(paddr);
3575 return i+1;
3576 }
3577 }
3578
3579 return 1;
3580}
3581
3582void InitStaInfo(struct rtllib_device *ieee,int index)
3583{
3584 int idx = index;
3585 ieee->peer_assoc_list[idx]->StaDataRate = 0;
3586 ieee->peer_assoc_list[idx]->StaSS = 0;
3587 ieee->peer_assoc_list[idx]->RetryFrameCnt = 0;
3588 ieee->peer_assoc_list[idx]->NoRetryFrameCnt = 0;
3589 ieee->peer_assoc_list[idx]->LastRetryCnt = 0;
3590 ieee->peer_assoc_list[idx]->LastNoRetryCnt = 0;
3591 ieee->peer_assoc_list[idx]->AvgRetryRate = 0;
3592 ieee->peer_assoc_list[idx]->LastRetryRate = 0;
3593 ieee->peer_assoc_list[idx]->txRateIndex = 11;
3594 ieee->peer_assoc_list[idx]->APDataRate = 0x2;
3595 ieee->peer_assoc_list[idx]->ForcedDataRate = 0x2;
3596
3597}
3598static u8 IsStaInfoExist(struct rtllib_device *ieee, u8 *addr)
3599{
3600 int k=0;
3601 struct sta_info * psta = NULL;
3602 u8 sta_idx = PEER_MAX_ASSOC;
3603
3604 for (k=0; k<PEER_MAX_ASSOC; k++)
3605 {
3606 psta = ieee->peer_assoc_list[k];
3607 if (NULL != psta)
3608 {
3609 if (memcmp(addr, psta->macaddr, ETH_ALEN) == 0)
3610 {
3611 sta_idx = k;
3612 break;
3613 }
3614 }
3615 }
3616 return sta_idx;
3617}
3618static u8 GetFreeStaInfoIdx(struct rtllib_device *ieee, u8 *addr)
3619{
3620 int k = 0;
3621 while((ieee->peer_assoc_list[k] != NULL) && (k < PEER_MAX_ASSOC))
3622 k++;
3623 printk("%s: addr:"MAC_FMT" index: %d\n", __func__, MAC_ARG(addr), k);
3624 return k;
3625}
3626struct sta_info *GetStaInfo(struct rtllib_device *ieee, u8 *addr)
3627{
3628 int k=0;
3629 struct sta_info * psta = NULL;
3630 struct sta_info * psta_find = NULL;
3631
3632 for (k=0; k<PEER_MAX_ASSOC; k++)
3633 {
3634 psta = ieee->peer_assoc_list[k];
3635 if (NULL != psta)
3636 {
3637 if (memcmp(addr, psta->macaddr, ETH_ALEN) == 0)
3638 {
3639 psta_find = psta;
3640 break;
3641 }
3642 }
3643 }
3644 return psta_find;
3645}
3646void DelStaInfoList(struct rtllib_device *ieee)
3647{
3648 int idx = 0;
3649 struct sta_info * AsocEntry = NULL;
3650
3651 atomic_set(&ieee->AsocEntryNum, 0);
3652 for (idx=0; idx<PEER_MAX_ASSOC; idx++){
3653 AsocEntry = ieee->peer_assoc_list[idx];
3654 if (NULL != AsocEntry){
3655 kfree(AsocEntry);
3656 ieee->peer_assoc_list[idx] = NULL;
3657 }
3658 ieee->AvailableAIDTable[idx] = 99;
3659 }
3660}
3661void DelStaInfo(struct rtllib_device *ieee, u8 *addr)
3662{
3663 struct sta_info * psta = NULL;
3664 int k=0;
3665
3666 for (k=0; k<PEER_MAX_ASSOC; k++)
3667 {
3668 psta = ieee->peer_assoc_list[k];
3669 if (NULL != psta){
3670 if (memcmp(addr, psta->macaddr, ETH_ALEN) == 0){
3671 if (psta->aid > 0 && psta->aid-1 < PEER_MAX_ASSOC)
3672 ieee->AvailableAIDTable[psta->aid-1] = 99;
3673 else
3674 printk("%s(): clear non-existing entry AID\n", __func__);
3675
3676 kfree(psta);
3677 ieee->peer_assoc_list[k] = NULL;
3678 atomic_dec(&ieee->AsocEntryNum);
3679 }
3680 }
3681 }
3682}
3683void IbssAgeFunction(struct rtllib_device *ieee)
3684{
3685 struct sta_info* AsocEntry = NULL;
3686 int idx;
3687 unsigned long CurrentTime;
3688 signed long TimeDifference;
3689 struct rtllib_network *target;
3690
3691 CurrentTime = jiffies;
3692
3693 for (idx = 0; idx < PEER_MAX_ASSOC; idx++)
3694 {
3695 AsocEntry = ieee->peer_assoc_list[idx];
3696 if (AsocEntry)
3697 {
3698 TimeDifference = jiffies_to_msecs(CurrentTime - AsocEntry->LastActiveTime);
3699
3700 if (TimeDifference > 20000)
3701 {
3702 printk("IbssAgeFunction(): "MAC_FMT" timeout\n", MAC_ARG(AsocEntry->macaddr));
3703 kfree(AsocEntry);
3704 ieee->peer_assoc_list[idx] = NULL;
3705 atomic_dec(&ieee->AsocEntryNum);
3706
3707 if (atomic_read(&ieee->AsocEntryNum) == 0){
3708
3709 down(&ieee->wx_sem);
3710 rtllib_stop_protocol(ieee,true);
3711
3712 list_for_each_entry(target, &ieee->network_list, list) {
3713 if (is_same_network(target, &ieee->current_network,(target->ssid_len?1:0))){
3714 printk("delete sta of previous Ad-hoc\n");
3715 list_del(&target->list);
3716 break;
3717 }
3718 }
3719
3720 rtllib_start_protocol(ieee);
3721 up(&ieee->wx_sem);
3722 }
3723 }
3724 }
3725 }
3726
3727#ifdef TO_DO_LIST
3728 if (AsocEntry_AnyStationAssociated(pMgntInfo)==false)
3729 DrvIFIndicateDisassociation(Adapter, unspec_reason);
3730
3731 if (pMgntInfo->dot11CurrentWirelessMode == WIRELESS_MODE_G ||
3732 (IS_WIRELESS_MODE_N_24G(Adapter) && pMgntInfo->pHTInfo->bCurSuppCCK) )
3733 {
3734 if (nBModeStaCnt == 0)
3735 {
3736 pMgntInfo->bUseProtection = false;
3737 ActUpdate_mCapInfo(Adapter, pMgntInfo->mCap);
3738 }
3739 }
3740
3741 if (IS_WIRELESS_MODE_N_24G(Adapter) || IS_WIRELESS_MODE_N_5G(Adapter) )
3742 {
3743 if (nLegacyStaCnt > 0)
3744 {
3745 pMgntInfo->pHTInfo->CurrentOpMode = HT_OPMODE_MIXED;
3746 }
3747 else
3748 {
3749 if ((pMgntInfo->pHTInfo->bCurBW40MHz) && (n20MHzStaCnt > 0))
3750 pMgntInfo->pHTInfo->CurrentOpMode = HT_OPMODE_40MHZ_PROTECT;
3751 else
3752 pMgntInfo->pHTInfo->CurrentOpMode = HT_OPMODE_NO_PROTECT;
3753
3754 }
3755 }
3756
3757 if (IS_WIRELESS_MODE_G(Adapter) ||
3758 (IS_WIRELESS_MODE_N_24G(Adapter) && pMgntInfo->pHTInfo->bCurSuppCCK))
3759 {
3760 if (pMgntInfo->bUseProtection)
3761 {
3762 u8 CckRate[4] = { MGN_1M, MGN_2M, MGN_5_5M, MGN_11M };
3763 OCTET_STRING osCckRate;
3764 FillOctetString(osCckRate, CckRate, 4);
3765 FilterSupportRate(pMgntInfo->mBrates, &osCckRate, false);
3766 Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_BASIC_RATE, (pu1Byte)&osCckRate);
3767 }
3768 else
3769 {
3770 Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
3771 }
3772 }
3773#endif
3774}
3775#endif
3776
3777static int IsPassiveChannel( struct rtllib_device *rtllib, u8 channel)
3778{
3779 if (MAX_CHANNEL_NUMBER < channel) {
3780 printk("%s(): Invalid Channel\n", __func__);
3781 return 0;
3782 }
3783
3784 if (rtllib->active_channel_map[channel] == 2)
3785 return 1;
3786
3787 return 0;
3788}
3789
3790int IsLegalChannel( struct rtllib_device *rtllib, u8 channel)
3791{
3792 if (MAX_CHANNEL_NUMBER < channel) {
3793 printk("%s(): Invalid Channel\n", __func__);
3794 return 0;
3795 }
3796 if (rtllib->active_channel_map[channel] > 0)
3797 return 1;
3798
3799 return 0;
3800}
3801
3802
3803static inline void rtllib_process_probe_response(
3804 struct rtllib_device *ieee,
3805 struct rtllib_probe_response *beacon,
3806 struct rtllib_rx_stats *stats)
3807{
3808 struct rtllib_network *target;
3809 struct rtllib_network *oldest = NULL;
3810#ifdef CONFIG_RTLLIB_DEBUG
3811 struct rtllib_info_element *info_element = &beacon->info_element[0];
3812#endif
3813 unsigned long flags;
3814 short renew;
Larry Finger94a79942011-08-23 19:00:42 -05003815 struct rtllib_network *network = kzalloc(sizeof(struct rtllib_network), GFP_ATOMIC);
Larry Finger94a79942011-08-23 19:00:42 -05003816
Mike McCormackcb762152011-07-11 08:56:20 +09003817 if (!network)
Larry Finger94a79942011-08-23 19:00:42 -05003818 return;
Larry Finger94a79942011-08-23 19:00:42 -05003819
3820 RTLLIB_DEBUG_SCAN(
3821 "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
3822 escape_essid(info_element->data, info_element->len),
3823 MAC_ARG(beacon->header.addr3),
3824 (beacon->capability & (1<<0xf)) ? '1' : '0',
3825 (beacon->capability & (1<<0xe)) ? '1' : '0',
3826 (beacon->capability & (1<<0xd)) ? '1' : '0',
3827 (beacon->capability & (1<<0xc)) ? '1' : '0',
3828 (beacon->capability & (1<<0xb)) ? '1' : '0',
3829 (beacon->capability & (1<<0xa)) ? '1' : '0',
3830 (beacon->capability & (1<<0x9)) ? '1' : '0',
3831 (beacon->capability & (1<<0x8)) ? '1' : '0',
3832 (beacon->capability & (1<<0x7)) ? '1' : '0',
3833 (beacon->capability & (1<<0x6)) ? '1' : '0',
3834 (beacon->capability & (1<<0x5)) ? '1' : '0',
3835 (beacon->capability & (1<<0x4)) ? '1' : '0',
3836 (beacon->capability & (1<<0x3)) ? '1' : '0',
3837 (beacon->capability & (1<<0x2)) ? '1' : '0',
3838 (beacon->capability & (1<<0x1)) ? '1' : '0',
3839 (beacon->capability & (1<<0x0)) ? '1' : '0');
3840
3841 if (rtllib_network_init(ieee, beacon, network, stats)) {
3842 RTLLIB_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
3843 escape_essid(info_element->data,
3844 info_element->len),
3845 MAC_ARG(beacon->header.addr3),
3846 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
3847 RTLLIB_STYPE_PROBE_RESP ?
3848 "PROBE RESPONSE" : "BEACON");
3849 goto free_network;
3850 }
3851
3852
3853 if (!IsLegalChannel(ieee, network->channel))
3854 goto free_network;
3855
3856 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == RTLLIB_STYPE_PROBE_RESP) {
3857 if (IsPassiveChannel(ieee, network->channel)) {
3858 printk("GetScanInfo(): For Global Domain, "
3859 "filter probe response at channel(%d).\n", network->channel);
3860 goto free_network;
3861 }
3862 }
3863
3864 /* The network parsed correctly -- so now we scan our known networks
3865 * to see if we can find it in our list.
3866 *
3867 * NOTE: This search is definitely not optimized. Once its doing
3868 * the "right thing" we'll optimize it for efficiency if
3869 * necessary */
3870
3871 /* Search for this entry in the list and update it if it is
3872 * already there. */
3873
3874 spin_lock_irqsave(&ieee->lock, flags);
3875#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3876 if (is_beacon(beacon->header.frame_ctl)){
3877 if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->state == RTLLIB_LINKED))
3878 {
3879 if ((network->ssid_len == ieee->current_network.ssid_len)
3880 && (!memcmp(network->ssid,ieee->current_network.ssid,ieee->current_network.ssid_len))
3881 && (network->channel == ieee->current_network.channel)
3882 && (ieee->current_network.channel > 0)
3883 && (ieee->current_network.channel <= 14))
3884 {
3885 if (!memcmp(ieee->current_network.bssid,network->bssid,6))
3886 {
3887 int idx = 0;
3888 struct rtllib_hdr_3addr* header = NULL;
3889 int idx_exist = 0;
3890 if (timer_pending(&ieee->ibss_wait_timer))
3891 del_timer_sync(&ieee->ibss_wait_timer);
3892 header = (struct rtllib_hdr_3addr*)&(beacon->header);
3893 idx_exist = IsStaInfoExist(ieee,header->addr2);
3894 if (idx_exist >= PEER_MAX_ASSOC) {
3895 idx = GetFreeStaInfoIdx(ieee, header->addr2);
3896 } else {
3897 ieee->peer_assoc_list[idx_exist]->LastActiveTime = jiffies;
3898 goto no_alloc;
3899 }
3900 if (idx >= PEER_MAX_ASSOC - 1) {
3901 printk("\n%s():ERR!!!Buffer overflow - could not append!!!",__func__);
3902 goto free_network;
3903 } else {
3904 ieee->peer_assoc_list[idx] = (struct sta_info *)kmalloc(sizeof(struct sta_info), GFP_ATOMIC);
3905 memset(ieee->peer_assoc_list[idx], 0, sizeof(struct sta_info));
3906 ieee->peer_assoc_list[idx]->LastActiveTime = jiffies;
3907 memcpy(ieee->peer_assoc_list[idx]->macaddr,header->addr2,ETH_ALEN);
3908 ieee->peer_assoc_list[idx]->ratr_index = 8;
3909 InitStaInfo(ieee,idx);
3910 atomic_inc(&ieee->AsocEntryNum);
3911 ieee->peer_assoc_list[idx]->aid = AsocEntry_AssignAvailableAID(ieee, ieee->peer_assoc_list[idx]->macaddr);
3912 ieee->check_ht_cap(ieee->dev,ieee->peer_assoc_list[idx],network);
3913 queue_delayed_work_rsl(ieee->wq, &ieee->update_assoc_sta_info_wq, 0);
3914 ieee->Adhoc_InitRateAdaptive(ieee->dev,ieee->peer_assoc_list[idx]);
3915 }
3916 }
3917 }
3918 }
3919 }
3920 if (ieee->iw_mode == IW_MODE_ADHOC){
3921 if ((network->ssid_len == ieee->current_network.ssid_len)
3922 && (!memcmp(network->ssid,ieee->current_network.ssid,ieee->current_network.ssid_len))
3923 && (network->capability & WLAN_CAPABILITY_IBSS)
3924 && (ieee->state == RTLLIB_LINKED_SCANNING))
3925 {
3926 if (memcmp(ieee->current_network.bssid,network->bssid,6))
3927 {
3928 printk("%s(): SSID matched but BSSID mismatched.\n",__func__);
3929
3930 ieee->TargetTsf = beacon->time_stamp[1];
3931 ieee->TargetTsf <<= 32;
3932 ieee->TargetTsf |= beacon->time_stamp[0];
3933
3934 ieee->CurrTsf = stats->TimeStampLow;
3935
3936 queue_delayed_work_rsl(ieee->wq, &ieee->check_tsf_wq, 0);
3937 }
3938 }
3939 }
3940#endif
3941#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3942no_alloc:
3943 if (ieee->iw_mode == IW_MODE_INFRA)
3944#endif
3945 {
3946 if (is_same_network(&ieee->current_network, network, (network->ssid_len?1:0))) {
3947 update_network(&ieee->current_network, network);
3948 if ((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
3949 && ieee->current_network.berp_info_valid){
3950 if (ieee->current_network.erp_value& ERP_UseProtection)
3951 ieee->current_network.buseprotection = true;
3952 else
3953 ieee->current_network.buseprotection = false;
3954 }
3955 if (is_beacon(beacon->header.frame_ctl))
3956 {
3957 if (ieee->state >= RTLLIB_LINKED)
3958 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
3959 }
3960 }
3961 }
3962#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3963 else if (ieee->iw_mode == IW_MODE_ADHOC)
3964 {
3965 if (is_same_network(&ieee->current_network, network, (network->ssid_len?1:0))) {
3966 update_ibss_network(&ieee->current_network, network);
3967 }
3968 }
3969#endif
3970 list_for_each_entry(target, &ieee->network_list, list) {
3971 if (is_same_network(target, network,(target->ssid_len?1:0)))
3972 break;
3973 if ((oldest == NULL) ||
3974 (target->last_scanned < oldest->last_scanned))
3975 oldest = target;
3976 }
3977
3978 /* If we didn't find a match, then get a new network slot to initialize
3979 * with this beacon's information */
3980 if (&target->list == &ieee->network_list) {
3981 if (list_empty(&ieee->network_free_list)) {
3982 /* If there are no more slots, expire the oldest */
3983 list_del(&oldest->list);
3984 target = oldest;
3985 RTLLIB_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
3986 "network list.\n",
3987 escape_essid(target->ssid,
3988 target->ssid_len),
3989 MAC_ARG(target->bssid));
3990 } else {
3991 /* Otherwise just pull from the free list */
3992 target = list_entry(ieee->network_free_list.next,
3993 struct rtllib_network, list);
3994 list_del(ieee->network_free_list.next);
3995 }
3996
3997
3998#ifdef CONFIG_RTLLIB_DEBUG
3999 RTLLIB_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
4000 escape_essid(network->ssid,
4001 network->ssid_len),
4002 MAC_ARG(network->bssid),
4003 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
4004 RTLLIB_STYPE_PROBE_RESP ?
4005 "PROBE RESPONSE" : "BEACON");
4006#endif
4007 memcpy(target, network, sizeof(*target));
4008 list_add_tail(&target->list, &ieee->network_list);
4009 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
4010 rtllib_softmac_new_net(ieee, network);
4011 } else {
4012 RTLLIB_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
4013 escape_essid(target->ssid,
4014 target->ssid_len),
4015 MAC_ARG(target->bssid),
4016 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
4017 RTLLIB_STYPE_PROBE_RESP ?
4018 "PROBE RESPONSE" : "BEACON");
4019
4020 /* we have an entry and we are going to update it. But this entry may
4021 * be already expired. In this case we do the same as we found a new
4022 * net and call the new_net handler
4023 */
4024 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
4025 if ((!target->ssid_len) &&
4026 (((network->ssid_len > 0) && (target->hidden_ssid_len == 0))
4027 || ((ieee->current_network.ssid_len == network->ssid_len) &&
4028 (strncmp(ieee->current_network.ssid, network->ssid, network->ssid_len) == 0) &&
4029 (ieee->state == RTLLIB_NOLINK)))
4030 ) {
4031 renew = 1;
4032 }
4033 update_network(target, network);
4034 if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
4035 rtllib_softmac_new_net(ieee, network);
4036 }
4037
4038 spin_unlock_irqrestore(&ieee->lock, flags);
4039 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, network, (network->ssid_len?1:0))&&\
4040 (ieee->state == RTLLIB_LINKED)) {
4041 if (ieee->handle_beacon != NULL) {
4042 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
4043 }
4044 }
4045free_network:
4046 kfree(network);
4047 return;
4048}
4049
4050void rtllib_rx_mgt(struct rtllib_device *ieee,
4051 struct sk_buff *skb,
4052 struct rtllib_rx_stats *stats)
4053{
4054 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data ;
4055 if (WLAN_FC_GET_STYPE(header->frame_ctl) != RTLLIB_STYPE_PROBE_RESP &&
4056 WLAN_FC_GET_STYPE(header->frame_ctl) != RTLLIB_STYPE_BEACON)
4057 ieee->last_rx_ps_time = jiffies;
4058
4059 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
4060
4061 case RTLLIB_STYPE_BEACON:
4062 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
4063 WLAN_FC_GET_STYPE(header->frame_ctl));
4064 RTLLIB_DEBUG_SCAN("Beacon\n");
4065 rtllib_process_probe_response(
4066 ieee, (struct rtllib_probe_response *)header, stats);
4067
4068 if (ieee->sta_sleep || (ieee->ps != RTLLIB_PS_DISABLED &&
4069 ieee->iw_mode == IW_MODE_INFRA &&
4070 ieee->state == RTLLIB_LINKED))
4071 tasklet_schedule(&ieee->ps_task);
4072
4073 break;
4074
4075 case RTLLIB_STYPE_PROBE_RESP:
4076 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
4077 WLAN_FC_GET_STYPE(header->frame_ctl));
4078 RTLLIB_DEBUG_SCAN("Probe response\n");
4079 rtllib_process_probe_response(
4080 ieee, (struct rtllib_probe_response *)header, stats);
4081 break;
4082 case RTLLIB_STYPE_PROBE_REQ:
4083 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
4084 WLAN_FC_GET_STYPE(header->frame_ctl));
4085 RTLLIB_DEBUG_SCAN("Probe request\n");
4086 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
4087 ((ieee->iw_mode == IW_MODE_ADHOC ||
4088 ieee->iw_mode == IW_MODE_MASTER) &&
4089 ieee->state == RTLLIB_LINKED)){
4090 rtllib_rx_probe_rq(ieee, skb);
4091 }
4092 break;
4093 }
4094
4095}