rtl8192e: Remove WIRELESS_EXT macro checks
[deliverable/linux.git] / drivers / staging / rtl8192e / rtllib_rx.c
CommitLineData
94a79942
LF
1/*
2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <jkmaline@cc.hut.fi>
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2004, Intel Corporation
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. See README and COPYING for
13 * more details.
14 ******************************************************************************
15
16 Few modifications for Realtek's Wi-Fi drivers by
17 Andrea Merello <andreamrl@tiscali.it>
18
19 A special thanks goes to Realtek for their support !
20
21******************************************************************************/
22
23
24#include <linux/compiler.h>
25#include <linux/errno.h>
26#include <linux/if_arp.h>
27#include <linux/in6.h>
28#include <linux/in.h>
29#include <linux/ip.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/netdevice.h>
33#include <linux/pci.h>
34#include <linux/proc_fs.h>
35#include <linux/skbuff.h>
36#include <linux/slab.h>
37#include <linux/tcp.h>
38#include <linux/types.h>
39#include <linux/version.h>
40#include <linux/wireless.h>
41#include <linux/etherdevice.h>
42#include <asm/uaccess.h>
43#include <linux/ctype.h>
44
45#include "rtllib.h"
46#ifdef ENABLE_DOT11D
47#include "dot11d.h"
48#endif
49
94a79942
LF
50#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
94a79942
LF
320static 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{
94a79942 324 skb->dev = ieee->dev;
94a79942 325 skb_reset_mac_header(skb);
94a79942
LF
326 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);
94a79942
LF
331}
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
94a79942
LF
1821 rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
1822 ieee->stats.rx_packets++;
1823 ieee->stats.rx_bytes += skb->len;
3591733d 1824
94a79942
LF
1825 return 1;
1826}
1827
1828int rtllib_rx_Mesh(struct rtllib_device *ieee, struct sk_buff *skb,
1829 struct rtllib_rx_stats *rx_stats)
1830{
1831 return 0;
1832}
1833
1834#if 1
1835/* All received frames are sent to this function. @skb contains the frame in
1836 * IEEE 802.11 format, i.e., in the format it was sent over air.
1837 * This function is called only as a tasklet (software IRQ). */
1838int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1839 struct rtllib_rx_stats *rx_stats)
1840{
1841 int ret = 0;
1842
1843 if ((NULL==ieee) || (NULL==skb) || (NULL==rx_stats)){
1844 printk(KERN_INFO "%s: Input parameters NULL!\n", __func__);
1845 goto rx_dropped;
1846 }
1847 if (skb->len < 10) {
1848 printk(KERN_INFO "%s: SKB length < 10 \n", __func__);
1849 goto rx_dropped;
1850 }
1851
1852 switch (ieee->iw_mode) {
1853 case IW_MODE_ADHOC:
1854 case IW_MODE_INFRA:
1855 ret = rtllib_rx_InfraAdhoc(ieee, skb, rx_stats);
1856 break;
1857 case IW_MODE_MASTER:
1858 case IW_MODE_REPEAT:
1859 ret = rtllib_rx_Master(ieee, skb, rx_stats);
1860 break;
1861 case IW_MODE_MONITOR:
1862 ret = rtllib_rx_Monitor(ieee, skb, rx_stats);
1863 break;
1864 case IW_MODE_MESH:
1865 ret = rtllib_rx_Mesh(ieee, skb, rx_stats);
1866 break;
1867 default:
1868 printk(KERN_INFO"%s: ERR iw mode!!!\n", __func__);
1869 break;
1870 }
1871
1872 return ret;
1873
1874 rx_dropped:
1875 ieee->stats.rx_dropped++;
1876 return 0;
1877}
1878#else
1879int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1880 struct rtllib_rx_stats *rx_stats)
1881{
1882 struct net_device *dev = ieee->dev;
1883 struct rtllib_hdr_4addr *hdr;
1884 size_t hdrlen;
1885 u16 fc, type, stype, sc;
1886 struct net_device_stats *stats = NULL;
1887 unsigned int frag;
1888 u8 *payload;
1889 u16 ethertype;
1890 u8 TID = 0;
1891 u16 SeqNum = 0;
1892 PRX_TS_RECORD pTS = NULL;
1893#ifdef NOT_YET
1894 struct net_device *wds = NULL;
1895 struct sk_buff *skb2 = NULL;
1896 struct net_device *wds = NULL;
1897 int frame_authorized = 0;
1898 int from_assoc_ap = 0;
1899 void *sta = NULL;
1900#endif
1901 u8 dst[ETH_ALEN];
1902 u8 src[ETH_ALEN];
1903 u8 bssid[ETH_ALEN] = {0};
1904 u8 zero_addr[ETH_ALEN] = {0};
1905 struct rtllib_crypt_data *crypt = NULL;
1906 int keyidx = 0;
1907#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
1908 struct sta_info * psta = NULL;
1909#endif
1910 bool unicast_packet = false;
1911 int i;
1912 struct rtllib_rxb* rxb = NULL;
1913 int multicast = 0;
1914 bool tmp_dump = false;
1915 bool bToOtherSTA = false;
1916 hdr = (struct rtllib_hdr_4addr *)skb->data;
1917 stats = &ieee->stats;
1918
1919 multicast = is_multicast_ether_addr(hdr->addr1)|is_broadcast_ether_addr(hdr->addr1);
1920 if (!multicast && (compare_ether_addr(dev->dev_addr, hdr->addr1) != 0)) {
1921 if ((ieee->iw_mode == IW_MODE_MONITOR) || ieee->bNetPromiscuousMode){
1922 bToOtherSTA = true;
1923 }else{
1924 goto rx_dropped;
1925 }
1926 }
1927
1928 fc = le16_to_cpu(hdr->frame_ctl);
1929 type = WLAN_FC_GET_TYPE(fc);
1930 stype = WLAN_FC_GET_STYPE(fc);
1931 sc = le16_to_cpu(hdr->seq_ctl);
1932 frag = WLAN_GET_SEQ_FRAG(sc);
1933
1934 ieee->need_sw_enc = 0;
1935
1936 hdrlen = rtllib_get_hdrlen(fc);
1937 if (skb->len < hdrlen){
1938 printk("%s():ERR!!! skb->len is smaller than hdrlen\n",__func__);
1939 goto rx_dropped;
1940 }
1941
1942 if (HTCCheck(ieee, skb->data)) {
1943 if (net_ratelimit())
1944 printk("find HTCControl\n");
1945 hdrlen += 4;
1946 rx_stats->bContainHTC = 1;
1947 }
1948 if (RTLLIB_QOS_HAS_SEQ(fc))
1949 rx_stats->bIsQosData = 1;
1950 if ((0) && (type == RTLLIB_FTYPE_DATA) && ((is_broadcast_ether_addr(hdr->addr1)) || (compare_ether_addr(dev->dev_addr, hdr->addr1) == 0))) {
1951 printk("===>RX data before decrypt\n");
1952 tmp_dump = true;
1953 dump_buf(skb->data,skb->len);
1954 }
1955#ifdef NOT_YET
1956 hostap_update_rx_stats(local->ap, hdr, rx_stats);
1957#endif
1958
1959 if (ieee->host_decrypt) {
1960 int idx = 0;
1961 if (skb->len >= hdrlen + 3)
1962 idx = skb->data[hdrlen + 3] >> 6;
1963 crypt = ieee->crypt[idx];
1964#ifdef NOT_YET
1965 sta = NULL;
1966
1967 /* Use station specific key to override default keys if the
1968 * receiver address is a unicast address ("individual RA"). If
1969 * bcrx_sta_key parameter is set, station specific key is used
1970 * even with broad/multicast targets (this is against IEEE
1971 * 802.11, but makes it easier to use different keys with
1972 * stations that do not support WEP key mapping). */
1973
1974 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
1975 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
1976 &sta);
1977#endif
1978
1979 /* allow NULL decrypt to indicate an station specific override
1980 * for default encryption */
1981 if (crypt && (crypt->ops == NULL ||
1982 crypt->ops->decrypt_mpdu == NULL))
1983 crypt = NULL;
1984
1985 if (!crypt && (fc & RTLLIB_FCTL_WEP)) {
1986 /* This seems to be triggered by some (multicast?)
1987 * frames from other than current BSS, so just drop the
1988 * frames silently instead of filling system log with
1989 * these reports. */
1990 RTLLIB_DEBUG_DROP("Decryption failed (not set)"
1991 " (SA=" MAC_FMT ")\n",
1992 MAC_ARG(hdr->addr2));
1993 ieee->ieee_stats.rx_discards_undecryptable++;
1994 goto rx_dropped;
1995 }
1996 }
1997
1998 if (skb->len < RTLLIB_DATA_HDR3_LEN)
1999 goto rx_dropped;
2000
2001 if ( (ieee->pHTInfo->bCurRxReorderEnable == false) ||
2002 !ieee->current_network.qos_data.active ||
2003 !IsDataFrame(skb->data) ||
2004 IsLegacyDataFrame(skb->data)) {
2005 if (!((type == RTLLIB_FTYPE_MGMT) && (stype == RTLLIB_STYPE_BEACON))){
2006 if (is_duplicate_packet(ieee, hdr)){
2007 goto rx_dropped;
2008 }
2009 }
2010 } else {
2011 PRX_TS_RECORD pRxTS = NULL;
2012 if (GetTs(ieee, (PTS_COMMON_INFO*) &pRxTS, hdr->addr2,
2013 (u8)Frame_QoSTID((u8*)(skb->data)), RX_DIR, true)) {
2014 if ((fc & (1<<11)) && (frag == pRxTS->RxLastFragNum) &&
2015 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum)) {
2016 goto rx_dropped;
2017 } else {
2018 pRxTS->RxLastFragNum = frag;
2019 pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
2020 }
2021 } else {
2022 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!%s(): No TS!! Skip the check!!\n",__func__);
2023 goto rx_dropped;
2024 }
2025 }
2026 if (type == RTLLIB_FTYPE_MGMT) {
2027 if (bToOtherSTA)
2028 goto rx_dropped;
2029 if (rtllib_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
2030 goto rx_dropped;
2031 else
2032 goto rx_exit;
2033 }
2034 if (type == RTLLIB_FTYPE_CTL) {
2035 goto rx_dropped;
2036 }
2037 /* Data frame - extract src/dst addresses */
2038 switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
2039 case RTLLIB_FCTL_FROMDS:
2040 memcpy(dst, hdr->addr1, ETH_ALEN);
2041 memcpy(src, hdr->addr3, ETH_ALEN);
2042 memcpy(bssid, hdr->addr2, ETH_ALEN);
2043 break;
2044 case RTLLIB_FCTL_TODS:
2045 memcpy(dst, hdr->addr3, ETH_ALEN);
2046 memcpy(src, hdr->addr2, ETH_ALEN);
2047 memcpy(bssid, hdr->addr1, ETH_ALEN);
2048 break;
2049 case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
2050 if (skb->len < RTLLIB_DATA_HDR4_LEN)
2051 goto rx_dropped;
2052 memcpy(dst, hdr->addr3, ETH_ALEN);
2053 memcpy(src, hdr->addr4, ETH_ALEN);
2054 memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
2055 break;
2056 case 0:
2057 memcpy(dst, hdr->addr1, ETH_ALEN);
2058 memcpy(src, hdr->addr2, ETH_ALEN);
2059 memcpy(bssid, hdr->addr3, ETH_ALEN);
2060 break;
2061 }
2062
2063 /* Filter frames from different BSS */
2064 if ((type != RTLLIB_FTYPE_CTL) && ((fc & RTLLIB_FCTL_DSTODS) != RTLLIB_FCTL_DSTODS)
2065 && (compare_ether_addr(ieee->current_network.bssid, bssid) != 0) && memcmp(ieee->current_network.bssid, zero_addr, ETH_ALEN)) {
2066 goto rx_dropped;
2067 }
2068
2069 /* Filter packets sent by an STA that will be forwarded by AP */
2070 if ( ieee->IntelPromiscuousModeInfo.bPromiscuousOn &&
2071 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame ) {
2072 if ((fc & RTLLIB_FCTL_TODS) && !(fc & RTLLIB_FCTL_FROMDS) &&
2073 (compare_ether_addr(dst, ieee->current_network.bssid) != 0) &&
2074 (compare_ether_addr(bssid, ieee->current_network.bssid) == 0)) {
2075 goto rx_dropped;
2076 }
2077 }
2078
2079#ifdef NOT_YET
2080 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
2081 goto rx_dropped;
2082 if (wds) {
2083 skb->dev = dev = wds;
2084 stats = hostap_get_stats(dev);
2085 }
2086
2087 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
2088 (fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) == RTLLIB_FCTL_FROMDS &&
2089 ieee->stadev &&
2090 memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
2091 /* Frame from BSSID of the AP for which we are a client */
2092 skb->dev = dev = ieee->stadev;
2093 stats = hostap_get_stats(dev);
2094 from_assoc_ap = 1;
2095 }
2096#endif
2097
2098 dev->last_rx = jiffies;
2099
2100#ifdef NOT_YET
2101 if ((ieee->iw_mode == IW_MODE_MASTER ||
2102 ieee->iw_mode == IW_MODE_REPEAT) &&
2103 !from_assoc_ap) {
2104 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
2105 wds != NULL)) {
2106 case AP_RX_CONTINUE_NOT_AUTHORIZED:
2107 frame_authorized = 0;
2108 break;
2109 case AP_RX_CONTINUE:
2110 frame_authorized = 1;
2111 break;
2112 case AP_RX_DROP:
2113 goto rx_dropped;
2114 case AP_RX_EXIT:
2115 goto rx_exit;
2116 }
2117 }
2118#endif
2119 /* Nullfunc frames may have PS-bit set, so they must be passed to
2120 * hostap_handle_sta_rx() before being dropped here. */
2121 if (stype != RTLLIB_STYPE_DATA &&
2122 stype != RTLLIB_STYPE_DATA_CFACK &&
2123 stype != RTLLIB_STYPE_DATA_CFPOLL &&
2124 stype != RTLLIB_STYPE_DATA_CFACKPOLL&&
2125 stype != RTLLIB_STYPE_QOS_DATA
2126 ) {
2127 if (stype != RTLLIB_STYPE_NULLFUNC)
2128 RTLLIB_DEBUG_DROP(
2129 "RX: dropped data frame "
2130 "with no data (type=0x%02x, "
2131 "subtype=0x%02x, len=%d)\n",
2132 type, stype, skb->len);
2133 goto rx_dropped;
2134 }
2135
2136 if (skb->len == hdrlen){
2137 goto rx_dropped;
2138 }
2139
2140 {
2141 /* network filter more precisely */
2142 switch (ieee->iw_mode) {
2143 case IW_MODE_ADHOC:
2144 /* packets from our adapter are dropped (echo) */
2145 if (!memcmp(hdr->addr2, dev->dev_addr, ETH_ALEN))
2146 goto rx_dropped;
2147
2148 /* {broad,multi}cast packets to our BSSID go through */
2149 if (is_multicast_ether_addr(hdr->addr1)) {
2150 if (!memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))
2151 break;
2152 else
2153 goto rx_dropped;
2154 }
2155
2156 /* packets not to our adapter, just discard it */
2157 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2158 if (bToOtherSTA)
2159 break;
2160 else
2161 goto rx_dropped;
2162 }
2163
2164 break;
2165
2166 case IW_MODE_INFRA:
2167 /* packets from our adapter are dropped (echo) */
2168 if (!memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN))
2169 goto rx_dropped;
2170
2171 /* {broad,multi}cast packets to our BSS go through */
2172 if (is_multicast_ether_addr(hdr->addr1)) {
2173 if (!memcmp(hdr->addr2, ieee->current_network.bssid, ETH_ALEN))
2174 break;
2175 else
2176 goto rx_dropped;
2177 }
2178
2179 /* packets to our adapter go through */
2180 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2181 if (bToOtherSTA)
2182 break;
2183 else
2184 goto rx_dropped;
2185 }
2186
2187 break;
2188 }
2189
2190
2191 }
2192
2193 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->sta_sleep == LPS_IS_SLEEP)
2194 && (ieee->polling)) {
2195 if (WLAN_FC_MORE_DATA(fc)) {
2196 /* more data bit is set, let's request a new frame from the AP */
2197 rtllib_sta_ps_send_pspoll_frame(ieee);
2198 } else {
2199 ieee->polling = false;
2200 }
2201 }
2202
2203#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
2204 if (ieee->iw_mode == IW_MODE_ADHOC){
2205 psta = GetStaInfo(ieee, src);
2206 if (NULL != psta)
2207 psta->LastActiveTime = jiffies;
2208 }
2209#endif
2210 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
2211 if ((!rx_stats->Decrypted)){
2212 ieee->need_sw_enc = 1;
2213 }
2214
2215 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
2216 ((keyidx = rtllib_rx_frame_decrypt(ieee, skb, crypt)) < 0)) {
2217 printk("decrypt frame error\n");
2218 goto rx_dropped;
2219 }
2220 if (tmp_dump) {
2221 printk("************after decrypt\n");
2222 dump_buf(skb->data,skb->len);
2223 }
2224 hdr = (struct rtllib_hdr_4addr *) skb->data;
2225
2226 /* skb: hdr + (possibly fragmented) plaintext payload */
2227 if ((frag != 0 || (fc & RTLLIB_FCTL_MOREFRAGS))) {
2228 int flen;
2229 struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
2230 RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
2231
2232 if (!frag_skb) {
2233 RTLLIB_DEBUG(RTLLIB_DL_RX | RTLLIB_DL_FRAG,
2234 "Rx cannot get skb from fragment "
2235 "cache (morefrag=%d seq=%u frag=%u)\n",
2236 (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
2237 WLAN_GET_SEQ_SEQ(sc), frag);
2238 goto rx_dropped;
2239 }
2240 flen = skb->len;
2241 if (frag != 0)
2242 flen -= hdrlen;
2243
2244 if (frag_skb->tail + flen > frag_skb->end) {
2245 printk(KERN_WARNING "%s: host decrypted and "
2246 "reassembled frame did not fit skb\n",
2247 dev->name);
2248 rtllib_frag_cache_invalidate(ieee, hdr);
2249 goto rx_dropped;
2250 }
2251
2252 if (frag == 0) {
2253 /* copy first fragment (including full headers) into
2254 * beginning of the fragment cache skb */
2255 memcpy(skb_put(frag_skb, flen), skb->data, flen);
2256 } else {
2257 /* append frame payload to the end of the fragment
2258 * cache skb */
2259 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
2260 flen);
2261 }
2262 dev_kfree_skb_any(skb);
2263 skb = NULL;
2264
2265 if (fc & RTLLIB_FCTL_MOREFRAGS) {
2266 /* more fragments expected - leave the skb in fragment
2267 * cache for now; it will be delivered to upper layers
2268 * after all fragments have been received */
2269 goto rx_exit;
2270 }
2271
2272 /* this was the last fragment and the frame will be
2273 * delivered, so remove skb from fragment cache */
2274 skb = frag_skb;
2275 hdr = (struct rtllib_hdr_4addr *) skb->data;
2276 rtllib_frag_cache_invalidate(ieee, hdr);
2277 }
2278
2279 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
2280 * encrypted/authenticated */
2281 if (ieee->host_decrypt && (fc & RTLLIB_FCTL_WEP) &&
2282 rtllib_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
2283 printk("==>decrypt msdu error\n");
2284 goto rx_dropped;
2285 }
2286
2287 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
2288 ieee->LinkDetectInfo.NumRxOkInPeriod++;
2289
2290 hdr = (struct rtllib_hdr_4addr *) skb->data;
2291 if ((!is_multicast_ether_addr(hdr->addr1)) && (!is_broadcast_ether_addr(hdr->addr1)))
2292 unicast_packet = true;
2293 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep) {
2294 if (/*ieee->ieee802_1x &&*/
2295 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
2296
2297#ifdef CONFIG_RTLLIB_DEBUG
2298 /* pass unencrypted EAPOL frames even if encryption is
2299 * configured */
2300 struct eapol *eap = (struct eapol *)(skb->data +
2301 24);
2302 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
2303 eap_get_type(eap->type));
2304#endif
2305 } else {
2306 RTLLIB_DEBUG_DROP(
2307 "encryption configured, but RX "
2308 "frame not encrypted (SA=" MAC_FMT ")\n",
2309 MAC_ARG(hdr->addr2));
2310 goto rx_dropped;
2311 }
2312 }
2313
2314#ifdef CONFIG_RTLLIB_DEBUG
2315 if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
2316 rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
2317 struct eapol *eap = (struct eapol *)(skb->data +
2318 24);
2319 RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
2320 eap_get_type(eap->type));
2321 }
2322#endif
2323
2324 if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
2325 !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
2326 RTLLIB_DEBUG_DROP(
2327 "dropped unencrypted RX data "
2328 "frame from " MAC_FMT
2329 " (drop_unencrypted=1)\n",
2330 MAC_ARG(hdr->addr2));
2331 goto rx_dropped;
2332 }
2333 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
2334 && !is_multicast_ether_addr(hdr->addr1) && !is_broadcast_ether_addr(hdr->addr1)) {
2335 TID = Frame_QoSTID(skb->data);
2336 SeqNum = WLAN_GET_SEQ_SEQ(sc);
2337 GetTs(ieee,(PTS_COMMON_INFO*) &pTS,hdr->addr2,TID,RX_DIR,true);
2338 if (TID !=0 && TID !=3)
2339 ieee->bis_any_nonbepkts = true;
2340 }
2341 /* skb: hdr + (possible reassembled) full plaintext payload */
2342 payload = skb->data + hdrlen;
2343 rxb = (struct rtllib_rxb*)kmalloc(sizeof(struct rtllib_rxb),GFP_ATOMIC);
2344 if (rxb == NULL) {
2345 RTLLIB_DEBUG(RTLLIB_DL_ERR,"%s(): kmalloc rxb error\n",__func__);
2346 goto rx_dropped;
2347 }
2348 /* to parse amsdu packets */
2349 /* qos data packets & reserved bit is 1 */
2350 if (parse_subframe(ieee,skb,rx_stats,rxb,src,dst) == 0) {
2351 /* only to free rxb, and not submit the packets to upper layer */
2352 for (i =0; i < rxb->nr_subframes; i++) {
2353 dev_kfree_skb(rxb->subframes[i]);
2354 }
2355 kfree(rxb);
2356 rxb = NULL;
2357 goto rx_dropped;
2358 }
2359#if !defined(RTL8192SU) && !defined(RTL8192U)
2360 if (unicast_packet) {
2361 if (type == RTLLIB_FTYPE_DATA) {
2362 if (ieee->bIsAggregateFrame)
2363 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod+=rxb->nr_subframes;
2364 else
2365 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod++;
2366
2367 if ((ieee->state == RTLLIB_LINKED) /*&& !MgntInitAdapterInProgress(pMgntInfo)*/) {
2368 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
2369 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) {
2370 if (ieee->LeisurePSLeave)
2371 ieee->LeisurePSLeave(dev);
2372 }
2373 }
2374 }
2375 }
2376#endif
2377 ieee->last_rx_ps_time = jiffies;
2378 if (ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL || bToOtherSTA ){
2379 for (i = 0; i<rxb->nr_subframes; i++) {
2380 struct sk_buff *sub_skb = rxb->subframes[i];
2381
2382 if (sub_skb) {
2383 /* convert hdr + possible LLC headers into Ethernet header */
2384 ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
2385 if (sub_skb->len >= 8 &&
2386 ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
2387 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
2388 memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
2389 /* remove RFC1042 or Bridge-Tunnel encapsulation and
2390 * replace EtherType */
2391 skb_pull(sub_skb, SNAP_SIZE);
2392 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
2393 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
2394 } else {
2395 u16 len;
2396 /* Leave Ethernet header part of hdr and full payload */
2397 len = htons(sub_skb->len);
2398 memcpy(skb_push(sub_skb, 2), &len, 2);
2399 memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
2400 memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
2401 }
2402
2403 stats->rx_packets++;
2404 stats->rx_bytes += sub_skb->len;
2405
2406 if (is_multicast_ether_addr(dst)) {
2407 stats->multicast++;
2408 }
2409
2410 /* Indicat the packets to upper layer */
2411 memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
2412 sub_skb->protocol = eth_type_trans(sub_skb, dev);
2413 sub_skb->dev = dev;
2414 sub_skb->dev->stats.rx_packets++;
2415 sub_skb->dev->stats.rx_bytes += sub_skb->len;
2416#ifdef TCP_CSUM_OFFLOAD_RX
2417 if ( rx_stats->tcp_csum_valid)
2418 sub_skb->ip_summed = CHECKSUM_UNNECESSARY;
2419 else
2420 sub_skb->ip_summed = CHECKSUM_NONE;
2421#else
2422 sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
2423#endif
2424
2425 netif_rx(sub_skb);
2426 }
2427 }
2428 kfree(rxb);
2429 rxb = NULL;
2430
2431 }
2432 else
2433 {
2434 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__func__);
2435#ifdef TCP_CSUM_OFFLOAD_RX
2436 rxb->tcp_csum_valid = rx_stats->tcp_csum_valid;
2437#endif
2438 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
2439 }
2440#ifndef JOHN_NOCPY
2441 dev_kfree_skb(skb);
2442#endif
2443
2444 rx_exit:
2445#ifdef NOT_YET
2446 if (sta)
2447 hostap_handle_sta_release(sta);
2448#endif
2449 return 1;
2450
2451 rx_dropped:
2452 if (rxb != NULL)
2453 {
2454 kfree(rxb);
2455 rxb = NULL;
2456 }
2457 stats->rx_dropped++;
2458
2459 /* Returning 0 indicates to caller that we have not handled the SKB--
2460 * so it is still allocated and can be used again by underlying
2461 * hardware as a DMA target */
2462 return 0;
2463}
2464#endif
2465
2466#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
2467
2468static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
2469
2470/*
2471* Make ther structure we read from the beacon packet has
2472* the right values
2473*/
2474static int rtllib_verify_qos_info(struct rtllib_qos_information_element
2475 *info_element, int sub_type)
2476{
2477
2478 if (info_element->qui_subtype != sub_type)
2479 return -1;
2480 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
2481 return -1;
2482 if (info_element->qui_type != QOS_OUI_TYPE)
2483 return -1;
2484 if (info_element->version != QOS_VERSION_1)
2485 return -1;
2486
2487 return 0;
2488}
2489
2490
2491/*
2492 * Parse a QoS parameter element
2493 */
2494static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
2495 *element_param, struct rtllib_info_element
2496 *info_element)
2497{
2498 int ret = 0;
2499 u16 size = sizeof(struct rtllib_qos_parameter_info) - 2;
2500
2501 if ((info_element == NULL) || (element_param == NULL))
2502 return -1;
2503
2504 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
2505 memcpy(element_param->info_element.qui, info_element->data,
2506 info_element->len);
2507 element_param->info_element.elementID = info_element->id;
2508 element_param->info_element.length = info_element->len;
2509 } else
2510 ret = -1;
2511 if (ret == 0)
2512 ret = rtllib_verify_qos_info(&element_param->info_element,
2513 QOS_OUI_PARAM_SUB_TYPE);
2514 return ret;
2515}
2516
2517/*
2518 * Parse a QoS information element
2519 */
2520static int rtllib_read_qos_info_element(struct
2521 rtllib_qos_information_element
2522 *element_info, struct rtllib_info_element
2523 *info_element)
2524{
2525 int ret = 0;
2526 u16 size = sizeof(struct rtllib_qos_information_element) - 2;
2527
2528 if (element_info == NULL)
2529 return -1;
2530 if (info_element == NULL)
2531 return -1;
2532
2533 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
2534 memcpy(element_info->qui, info_element->data,
2535 info_element->len);
2536 element_info->elementID = info_element->id;
2537 element_info->length = info_element->len;
2538 } else
2539 ret = -1;
2540
2541 if (ret == 0)
2542 ret = rtllib_verify_qos_info(element_info,
2543 QOS_OUI_INFO_SUB_TYPE);
2544 return ret;
2545}
2546
2547
2548/*
2549 * Write QoS parameters from the ac parameters.
2550 */
2551static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info *param_elm,
2552 struct rtllib_qos_data *qos_data)
2553{
2554 struct rtllib_qos_ac_parameter *ac_params;
2555 struct rtllib_qos_parameters *qos_param = &(qos_data->parameters);
2556 int rc = 0;
2557 int i;
2558 u8 aci;
2559 u8 acm;
2560
2561 qos_data->wmm_acm = 0;
2562 for (i = 0; i < QOS_QUEUE_NUM; i++) {
2563 ac_params = &(param_elm->ac_params_record[i]);
2564
2565 aci = (ac_params->aci_aifsn & 0x60) >> 5;
2566 acm = (ac_params->aci_aifsn & 0x10) >> 4;
2567
2568 if (aci >= QOS_QUEUE_NUM)
2569 continue;
2570 switch (aci) {
2571 case 1:
2572 /* BIT(0) | BIT(3) */
2573 if (acm)
2574 qos_data->wmm_acm |= (0x01<<0)|(0x01<<3);
2575 break;
2576 case 2:
2577 /* BIT(4) | BIT(5) */
2578 if (acm)
2579 qos_data->wmm_acm |= (0x01<<4)|(0x01<<5);
2580 break;
2581 case 3:
2582 /* BIT(6) | BIT(7) */
2583 if (acm)
2584 qos_data->wmm_acm |= (0x01<<6)|(0x01<<7);
2585 break;
2586 case 0:
2587 default:
2588 /* BIT(1) | BIT(2) */
2589 if (acm)
2590 qos_data->wmm_acm |= (0x01<<1)|(0x01<<2);
2591 break;
2592 }
2593
2594 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
2595
2596 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
2597 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
2598
2599 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
2600
2601 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
2602
2603 qos_param->flag[aci] =
2604 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
2605 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
2606 }
2607 return rc;
2608}
2609
2610/*
2611 * we have a generic data element which it may contain QoS information or
2612 * parameters element. check the information element length to decide
2613 * which type to read
2614 */
2615static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
2616 *info_element,
2617 struct rtllib_network *network)
2618{
2619 int rc = 0;
2620 struct rtllib_qos_information_element qos_info_element;
2621
2622 rc = rtllib_read_qos_info_element(&qos_info_element, info_element);
2623
2624 if (rc == 0) {
2625 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
2626 network->flags |= NETWORK_HAS_QOS_INFORMATION;
2627 } else {
2628 struct rtllib_qos_parameter_info param_element;
2629
2630 rc = rtllib_read_qos_param_element(&param_element,
2631 info_element);
2632 if (rc == 0) {
2633 rtllib_qos_convert_ac_to_parameters(&param_element,
2634 &(network->qos_data));
2635 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
2636 network->qos_data.param_count =
2637 param_element.info_element.ac_info & 0x0F;
2638 }
2639 }
2640
2641 if (rc == 0) {
2642 RTLLIB_DEBUG_QOS("QoS is supported\n");
2643 network->qos_data.supported = 1;
2644 }
2645 return rc;
2646}
2647
2648#ifdef CONFIG_RTLLIB_DEBUG
2649#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
2650
2651static const char *get_info_element_string(u16 id)
2652{
2653 switch (id) {
2654 MFIE_STRING(SSID);
2655 MFIE_STRING(RATES);
2656 MFIE_STRING(FH_SET);
2657 MFIE_STRING(DS_SET);
2658 MFIE_STRING(CF_SET);
2659 MFIE_STRING(TIM);
2660 MFIE_STRING(IBSS_SET);
2661 MFIE_STRING(COUNTRY);
2662 MFIE_STRING(HOP_PARAMS);
2663 MFIE_STRING(HOP_TABLE);
2664 MFIE_STRING(REQUEST);
2665 MFIE_STRING(CHALLENGE);
2666 MFIE_STRING(POWER_CONSTRAINT);
2667 MFIE_STRING(POWER_CAPABILITY);
2668 MFIE_STRING(TPC_REQUEST);
2669 MFIE_STRING(TPC_REPORT);
2670 MFIE_STRING(SUPP_CHANNELS);
2671 MFIE_STRING(CSA);
2672 MFIE_STRING(MEASURE_REQUEST);
2673 MFIE_STRING(MEASURE_REPORT);
2674 MFIE_STRING(QUIET);
2675 MFIE_STRING(IBSS_DFS);
2676 MFIE_STRING(RSN);
2677 MFIE_STRING(RATES_EX);
2678 MFIE_STRING(GENERIC);
2679 MFIE_STRING(QOS_PARAMETER);
2680 default:
2681 return "UNKNOWN";
2682 }
2683}
2684#endif
2685
2686#ifdef ENABLE_DOT11D
2687static inline void rtllib_extract_country_ie(
2688 struct rtllib_device *ieee,
2689 struct rtllib_info_element *info_element,
2690 struct rtllib_network *network,
2691 u8 * addr2)
2692{
2693 if (IS_DOT11D_ENABLE(ieee)) {
2694 if (info_element->len!= 0) {
2695 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
2696 network->CountryIeLen = info_element->len;
2697
2698 if (!IS_COUNTRY_IE_VALID(ieee))
2699 {
2700 if ((rtllib_act_scanning(ieee,false) == true) && (ieee->FirstIe_InScan == 1))
2701 printk("Received beacon ContryIE, SSID: <%s>\n",network->ssid);
2702 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
2703 }
2704 }
2705
2706 if (IS_EQUAL_CIE_SRC(ieee, addr2)) {
2707 UPDATE_CIE_WATCHDOG(ieee);
2708 }
2709 }
2710
2711}
2712#endif
2713
2714int rtllib_parse_info_param(struct rtllib_device *ieee,
2715 struct rtllib_info_element *info_element,
2716 u16 length,
2717 struct rtllib_network *network,
2718 struct rtllib_rx_stats *stats)
2719{
2720 u8 i;
2721 short offset;
2722 u16 tmp_htcap_len=0;
2723 u16 tmp_htinfo_len=0;
2724 u16 ht_realtek_agg_len=0;
2725 u8 ht_realtek_agg_buf[MAX_IE_LEN];
2726#ifdef CONFIG_RTLLIB_DEBUG
2727 char rates_str[64];
2728 char *p;
2729#endif
2730 while (length >= sizeof(*info_element)) {
2731 if (sizeof(*info_element) + info_element->len > length) {
2732 RTLLIB_DEBUG_MGMT("Info elem: parse failed: "
2733 "info_element->len + 2 > left : "
2734 "info_element->len+2=%zd left=%d, id=%d.\n",
2735 info_element->len +
2736 sizeof(*info_element),
2737 length, info_element->id);
2738 /* We stop processing but don't return an error here
2739 * because some misbehaviour APs break this rule. ie.
2740 * Orinoco AP1000. */
2741 break;
2742 }
2743
2744 switch (info_element->id) {
2745 case MFIE_TYPE_SSID:
2746 if (rtllib_is_empty_essid(info_element->data,
2747 info_element->len)) {
2748 network->flags |= NETWORK_EMPTY_ESSID;
2749 break;
2750 }
2751
2752 network->ssid_len = min(info_element->len,
2753 (u8) IW_ESSID_MAX_SIZE);
2754 memcpy(network->ssid, info_element->data, network->ssid_len);
2755 if (network->ssid_len < IW_ESSID_MAX_SIZE)
2756 memset(network->ssid + network->ssid_len, 0,
2757 IW_ESSID_MAX_SIZE - network->ssid_len);
2758
2759 RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
2760 network->ssid, network->ssid_len);
2761 break;
2762
2763 case MFIE_TYPE_RATES:
2764#ifdef CONFIG_RTLLIB_DEBUG
2765 p = rates_str;
2766#endif
2767 network->rates_len = min(info_element->len,
2768 MAX_RATES_LENGTH);
2769 for (i = 0; i < network->rates_len; i++) {
2770 network->rates[i] = info_element->data[i];
2771#ifdef CONFIG_RTLLIB_DEBUG
2772 p += snprintf(p, sizeof(rates_str) -
2773 (p - rates_str), "%02X ",
2774 network->rates[i]);
2775#endif
2776 if (rtllib_is_ofdm_rate
2777 (info_element->data[i])) {
2778 network->flags |= NETWORK_HAS_OFDM;
2779 if (info_element->data[i] &
2780 RTLLIB_BASIC_RATE_MASK)
2781 network->flags &=
2782 ~NETWORK_HAS_CCK;
2783 }
2784
2785 if (rtllib_is_cck_rate
2786 (info_element->data[i])) {
2787 network->flags |= NETWORK_HAS_CCK;
2788 }
2789 }
2790
2791 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
2792 rates_str, network->rates_len);
2793 break;
2794
2795 case MFIE_TYPE_RATES_EX:
2796#ifdef CONFIG_RTLLIB_DEBUG
2797 p = rates_str;
2798#endif
2799 network->rates_ex_len = min(info_element->len,
2800 MAX_RATES_EX_LENGTH);
2801 for (i = 0; i < network->rates_ex_len; i++) {
2802 network->rates_ex[i] = info_element->data[i];
2803#ifdef CONFIG_RTLLIB_DEBUG
2804 p += snprintf(p, sizeof(rates_str) -
2805 (p - rates_str), "%02X ",
2806 network->rates[i]);
2807#endif
2808 if (rtllib_is_ofdm_rate
2809 (info_element->data[i])) {
2810 network->flags |= NETWORK_HAS_OFDM;
2811 if (info_element->data[i] &
2812 RTLLIB_BASIC_RATE_MASK)
2813 network->flags &=
2814 ~NETWORK_HAS_CCK;
2815 }
2816 }
2817
2818 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
2819 rates_str, network->rates_ex_len);
2820 break;
2821
2822 case MFIE_TYPE_DS_SET:
2823 RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
2824 info_element->data[0]);
2825 network->channel = info_element->data[0];
2826 break;
2827
2828 case MFIE_TYPE_FH_SET:
2829 RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
2830 break;
2831
2832 case MFIE_TYPE_CF_SET:
2833 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
2834 break;
2835
2836 case MFIE_TYPE_TIM:
2837 if (info_element->len < 4)
2838 break;
2839
2840 network->tim.tim_count = info_element->data[0];
2841 network->tim.tim_period = info_element->data[1];
2842
2843 network->dtim_period = info_element->data[1];
2844 if (ieee->state != RTLLIB_LINKED)
2845 break;
2846 network->last_dtim_sta_time[0] = jiffies;
2847 network->last_dtim_sta_time[1] = stats->mac_time[1];
2848
2849 network->dtim_data = RTLLIB_DTIM_VALID;
2850
2851
2852 if (info_element->data[2] & 1)
2853 network->dtim_data |= RTLLIB_DTIM_MBCAST;
2854
2855#if 1
2856 offset = (info_element->data[2] >> 1)*2;
2857
2858
2859 if (ieee->assoc_id < 8*offset ||
2860 ieee->assoc_id > 8*(offset + info_element->len -3))
2861
2862 break;
2863
2864 offset = (ieee->assoc_id / 8) - offset;
2865 if (info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
2866 network->dtim_data |= RTLLIB_DTIM_UCAST;
2867#else
2868 {
2869 u16 numSta = 0;
2870 u16 offset_byte = 0;
2871 u16 offset_bit = 0;
2872
2873 numSta = (info_element->data[2] &0xFE)*8;
2874
2875 if (ieee->assoc_id < numSta ||
2876 ieee->assoc_id > (numSta + (info_element->len -3)*8))
2877 break;
2878
2879 offset = ieee->assoc_id - numSta;
2880 offset_byte = offset / 8;
2881 offset_bit = offset % 8;
2882 if (info_element->data[3+offset_byte] & (0x01<<offset_bit))
2883 network->dtim_data |= RTLLIB_DTIM_UCAST;
2884 }
2885#endif
2886
2887 network->listen_interval = network->dtim_period;
2888 break;
2889
2890 case MFIE_TYPE_ERP:
2891 network->erp_value = info_element->data[0];
2892 network->flags |= NETWORK_HAS_ERP_VALUE;
2893 RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
2894 network->erp_value);
2895 break;
2896 case MFIE_TYPE_IBSS_SET:
2897 network->atim_window = info_element->data[0];
2898 RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
2899 network->atim_window);
2900 break;
2901
2902 case MFIE_TYPE_CHALLENGE:
2903 RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
2904 break;
2905
2906 case MFIE_TYPE_GENERIC:
2907 RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
2908 info_element->len);
2909 if (!rtllib_parse_qos_info_param_IE(info_element,
2910 network))
2911 break;
2912 if (info_element->len >= 4 &&
2913 info_element->data[0] == 0x00 &&
2914 info_element->data[1] == 0x50 &&
2915 info_element->data[2] == 0xf2 &&
2916 info_element->data[3] == 0x01) {
2917 network->wpa_ie_len = min(info_element->len + 2,
2918 MAX_WPA_IE_LEN);
2919 memcpy(network->wpa_ie, info_element,
2920 network->wpa_ie_len);
2921 break;
2922 }
2923 if (info_element->len == 7 &&
2924 info_element->data[0] == 0x00 &&
2925 info_element->data[1] == 0xe0 &&
2926 info_element->data[2] == 0x4c &&
2927 info_element->data[3] == 0x01 &&
2928 info_element->data[4] == 0x02)
2929 network->Turbo_Enable = 1;
2930
2931 if (tmp_htcap_len == 0) {
2932 if (info_element->len >= 4 &&
2933 info_element->data[0] == 0x00 &&
2934 info_element->data[1] == 0x90 &&
2935 info_element->data[2] == 0x4c &&
2936 info_element->data[3] == 0x033) {
2937
2938 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
2939 if (tmp_htcap_len != 0){
2940 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2941 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
2942 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
2943 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
2944 }
2945 }
2946 if (tmp_htcap_len != 0){
2947 network->bssht.bdSupportHT = true;
2948 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
2949 }else{
2950 network->bssht.bdSupportHT = false;
2951 network->bssht.bdHT1R = false;
2952 }
2953 }
2954
2955
2956 if (tmp_htinfo_len == 0){
2957 if (info_element->len >= 4 &&
2958 info_element->data[0] == 0x00 &&
2959 info_element->data[1] == 0x90 &&
2960 info_element->data[2] == 0x4c &&
2961 info_element->data[3] == 0x034){
2962
2963 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
2964 if (tmp_htinfo_len != 0){
2965 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
2966 if (tmp_htinfo_len){
2967 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
2968 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
2969 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
2970 }
2971
2972 }
2973
2974 }
2975 }
2976
2977 if (ieee->aggregation){
2978 if (network->bssht.bdSupportHT){
2979 if (info_element->len >= 4 &&
2980 info_element->data[0] == 0x00 &&
2981 info_element->data[1] == 0xe0 &&
2982 info_element->data[2] == 0x4c &&
2983 info_element->data[3] == 0x02){
2984
2985 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN);
2986 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len);
2987
2988 }
2989 if (ht_realtek_agg_len >= 5){
2990 network->realtek_cap_exit = true;
2991 network->bssht.bdRT2RTAggregation = true;
2992
2993 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
2994 network->bssht.bdRT2RTLongSlotTime = true;
2995
2996 if ((ht_realtek_agg_buf[4]==1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
2997 {
2998 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
2999 }
3000 }
3001 }
3002 if (ht_realtek_agg_len >= 5){
3003 if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
3004 network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_SOFTAP;
3005 }
3006 }
3007
3008 {
3009 if ((info_element->len >= 3 &&
3010 info_element->data[0] == 0x00 &&
3011 info_element->data[1] == 0x05 &&
3012 info_element->data[2] == 0xb5) ||
3013 (info_element->len >= 3 &&
3014 info_element->data[0] == 0x00 &&
3015 info_element->data[1] == 0x0a &&
3016 info_element->data[2] == 0xf7) ||
3017 (info_element->len >= 3 &&
3018 info_element->data[0] == 0x00 &&
3019 info_element->data[1] == 0x10 &&
3020 info_element->data[2] == 0x18)){
3021
3022 network->broadcom_cap_exist = true;
3023
3024 }
3025 }
3026 if (info_element->len >= 3 &&
3027 info_element->data[0] == 0x00 &&
3028 info_element->data[1] == 0x0c &&
3029 info_element->data[2] == 0x43)
3030 {
3031 network->ralink_cap_exist = true;
3032 }
3033 if ((info_element->len >= 3 &&
3034 info_element->data[0] == 0x00 &&
3035 info_element->data[1] == 0x03 &&
3036 info_element->data[2] == 0x7f) ||
3037 (info_element->len >= 3 &&
3038 info_element->data[0] == 0x00 &&
3039 info_element->data[1] == 0x13 &&
3040 info_element->data[2] == 0x74))
3041 {
3042 network->atheros_cap_exist = true;
3043 }
3044
3045 if ((info_element->len >= 3 &&
3046 info_element->data[0] == 0x00 &&
3047 info_element->data[1] == 0x50 &&
3048 info_element->data[2] == 0x43) )
3049 {
3050 network->marvell_cap_exist = true;
3051 }
3052 if (info_element->len >= 3 &&
3053 info_element->data[0] == 0x00 &&
3054 info_element->data[1] == 0x40 &&
3055 info_element->data[2] == 0x96)
3056 {
3057 network->cisco_cap_exist = true;
3058 }
3059
3060
3061 if (info_element->len >= 3 &&
3062 info_element->data[0] == 0x00 &&
3063 info_element->data[1] == 0x0a &&
3064 info_element->data[2] == 0xf5)
3065 {
3066 network->airgo_cap_exist = true;
3067 }
3068
3069 if (info_element->len > 4 &&
3070 info_element->data[0] == 0x00 &&
3071 info_element->data[1] == 0x40 &&
3072 info_element->data[2] == 0x96 &&
3073 info_element->data[3] == 0x01)
3074 {
3075 if (info_element->len == 6)
3076 {
3077 memcpy(network->CcxRmState, &info_element[4], 2);
3078 if (network->CcxRmState[0] != 0)
3079 {
3080 network->bCcxRmEnable = true;
3081 }
3082 else
3083 network->bCcxRmEnable = false;
3084 network->MBssidMask = network->CcxRmState[1] & 0x07;
3085 if (network->MBssidMask != 0)
3086 {
3087 network->bMBssidValid = true;
3088 network->MBssidMask = 0xff << (network->MBssidMask);
3089 memcpy(network->MBssid, network->bssid, ETH_ALEN);
3090 network->MBssid[5] &= network->MBssidMask;
3091 }
3092 else
3093 {
3094 network->bMBssidValid = false;
3095 }
3096 }
3097 else
3098 {
3099 network->bCcxRmEnable = false;
3100 }
3101 }
3102 if (info_element->len > 4 &&
3103 info_element->data[0] == 0x00 &&
3104 info_element->data[1] == 0x40 &&
3105 info_element->data[2] == 0x96 &&
3106 info_element->data[3] == 0x03)
3107 {
3108 if (info_element->len == 5)
3109 {
3110 network->bWithCcxVerNum = true;
3111 network->BssCcxVerNumber = info_element->data[4];
3112 }
3113 else
3114 {
3115 network->bWithCcxVerNum = false;
3116 network->BssCcxVerNumber = 0;
3117 }
3118 }
3119 if (info_element->len > 4 &&
3120 info_element->data[0] == 0x00 &&
3121 info_element->data[1] == 0x50 &&
3122 info_element->data[2] == 0xf2 &&
3123 info_element->data[3] == 0x04)
3124 {
3125 RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
3126 info_element->len);
94a79942
LF
3127 network->wzc_ie_len = min(info_element->len+2,
3128 MAX_WZC_IE_LEN);
3129 memcpy(network->wzc_ie, info_element,
3130 network->wzc_ie_len);
94a79942
LF
3131 }
3132 break;
3133
3134 case MFIE_TYPE_RSN:
3135 RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
3136 info_element->len);
3137 network->rsn_ie_len = min(info_element->len + 2,
3138 MAX_WPA_IE_LEN);
3139 memcpy(network->rsn_ie, info_element,
3140 network->rsn_ie_len);
3141 break;
3142
3143 case MFIE_TYPE_HT_CAP:
3144 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
3145 info_element->len);
3146 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
3147 if (tmp_htcap_len != 0){
3148 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
3149 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
3150 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
3151 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
3152
3153 network->bssht.bdSupportHT = true;
3154 network->bssht.bdHT1R = ((((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
3155
3156 network->bssht.bdBandWidth = (HT_CHANNEL_WIDTH)(((PHT_CAPABILITY_ELE)(network->bssht.bdHTCapBuf))->ChlWidth);
3157 }
3158 else{
3159 network->bssht.bdSupportHT = false;
3160 network->bssht.bdHT1R = false;
3161 network->bssht.bdBandWidth = HT_CHANNEL_WIDTH_20 ;
3162 }
3163 break;
3164
3165
3166 case MFIE_TYPE_HT_INFO:
3167 RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
3168 info_element->len);
3169 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
3170 if (tmp_htinfo_len){
3171 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
3172 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\
3173 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len;
3174 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen);
3175 }
3176 break;
3177
3178 case MFIE_TYPE_AIRONET:
3179 RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
3180 info_element->len);
3181 if (info_element->len >IE_CISCO_FLAG_POSITION)
3182 {
3183 network->bWithAironetIE = true;
3184
3185 if ( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
3186 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
3187 {
3188 network->bCkipSupported = true;
3189 }
3190 else
3191 {
3192 network->bCkipSupported = false;
3193 }
3194 }
3195 else
3196 {
3197 network->bWithAironetIE = false;
3198 network->bCkipSupported = false;
3199 }
3200 break;
3201 case MFIE_TYPE_QOS_PARAMETER:
3202 printk(KERN_ERR
3203 "QoS Error need to parse QOS_PARAMETER IE\n");
3204 break;
3205
3206#ifdef ENABLE_DOT11D
3207 case MFIE_TYPE_COUNTRY:
3208 RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
3209 info_element->len);
3210 rtllib_extract_country_ie(ieee, info_element, network, network->bssid);
3211 break;
3212#endif
3213/* TODO */
3214 default:
3215 RTLLIB_DEBUG_MGMT
3216 ("Unsupported info element: %s (%d)\n",
3217 get_info_element_string(info_element->id),
3218 info_element->id);
3219 break;
3220 }
3221
3222 length -= sizeof(*info_element) + info_element->len;
3223 info_element =
3224 (struct rtllib_info_element *)&info_element->
3225 data[info_element->len];
3226 }
3227
3228 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
3229 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation)
3230 {
3231 network->unknown_cap_exist = true;
3232 }
3233 else
3234 {
3235 network->unknown_cap_exist = false;
3236 }
3237 return 0;
3238}
3239
3240static inline u8 rtllib_SignalStrengthTranslate(
3241 u8 CurrSS
3242 )
3243{
3244 u8 RetSS;
3245
3246 if (CurrSS >= 71 && CurrSS <= 100)
3247 {
3248 RetSS = 90 + ((CurrSS - 70) / 3);
3249 }
3250 else if (CurrSS >= 41 && CurrSS <= 70)
3251 {
3252 RetSS = 78 + ((CurrSS - 40) / 3);
3253 }
3254 else if (CurrSS >= 31 && CurrSS <= 40)
3255 {
3256 RetSS = 66 + (CurrSS - 30);
3257 }
3258 else if (CurrSS >= 21 && CurrSS <= 30)
3259 {
3260 RetSS = 54 + (CurrSS - 20);
3261 }
3262 else if (CurrSS >= 5 && CurrSS <= 20)
3263 {
3264 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
3265 }
3266 else if (CurrSS == 4)
3267 {
3268 RetSS = 36;
3269 }
3270 else if (CurrSS == 3)
3271 {
3272 RetSS = 27;
3273 }
3274 else if (CurrSS == 2)
3275 {
3276 RetSS = 18;
3277 }
3278 else if (CurrSS == 1)
3279 {
3280 RetSS = 9;
3281 }
3282 else
3283 {
3284 RetSS = CurrSS;
3285 }
3286
3287
3288
3289 return RetSS;
3290}
3291
3292long rtllib_translate_todbm(u8 signal_strength_index )
3293{
3294 long signal_power;
3295
3296 signal_power = (long)((signal_strength_index + 1) >> 1);
3297 signal_power -= 95;
3298
3299 return signal_power;
3300}
3301
3302static inline int rtllib_network_init(
3303 struct rtllib_device *ieee,
3304 struct rtllib_probe_response *beacon,
3305 struct rtllib_network *network,
3306 struct rtllib_rx_stats *stats)
3307{
3308#ifdef CONFIG_RTLLIB_DEBUG
3309#endif
3310
3311 /*
3312 network->qos_data.active = 0;
3313 network->qos_data.supported = 0;
3314 network->qos_data.param_count = 0;
3315 network->qos_data.old_param_count = 0;
3316 */
3317 memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
3318
3319 /* Pull out fixed field data */
3320 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
3321 network->capability = le16_to_cpu(beacon->capability);
3322 network->last_scanned = jiffies;
3323 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
3324 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
3325 network->beacon_interval = le32_to_cpu(beacon->beacon_interval);
3326 /* Where to pull this? beacon->listen_interval;*/
3327 network->listen_interval = 0x0A;
3328 network->rates_len = network->rates_ex_len = 0;
3329 network->last_associate = 0;
3330 network->ssid_len = 0;
3331 network->hidden_ssid_len = 0;
3332 memset(network->hidden_ssid, 0, sizeof(network->hidden_ssid));
3333 network->flags = 0;
3334 network->atim_window = 0;
3335 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
3336 0x3 : 0x0;
3337 network->berp_info_valid = false;
3338 network->broadcom_cap_exist = false;
3339 network->ralink_cap_exist = false;
3340 network->atheros_cap_exist = false;
3341 network->cisco_cap_exist = false;
3342 network->unknown_cap_exist = false;
3343 network->realtek_cap_exit = false;
3344 network->marvell_cap_exist = false;
3345 network->airgo_cap_exist = false;
3346 network->Turbo_Enable = 0;
3347 network->SignalStrength = stats->SignalStrength;
3348 network->RSSI = stats->SignalStrength;
3349#ifdef ENABLE_DOT11D
3350 network->CountryIeLen = 0;
3351 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
3352#endif
3353 HTInitializeBssDesc(&network->bssht);
3354 if (stats->freq == RTLLIB_52GHZ_BAND) {
3355 /* for A band (No DS info) */
3356 network->channel = stats->received_channel;
3357 } else
3358 network->flags |= NETWORK_HAS_CCK;
3359
3360 network->wpa_ie_len = 0;
3361 network->rsn_ie_len = 0;
94a79942 3362 network->wzc_ie_len = 0;
94a79942
LF
3363
3364 if (rtllib_parse_info_param(ieee,
3365 beacon->info_element,
3366 (stats->len - sizeof(*beacon)),
3367 network,
3368 stats))
3369 return 1;
3370
3371 network->mode = 0;
3372 if (stats->freq == RTLLIB_52GHZ_BAND)
3373 network->mode = IEEE_A;
3374 else {
3375 if (network->flags & NETWORK_HAS_OFDM)
3376 network->mode |= IEEE_G;
3377 if (network->flags & NETWORK_HAS_CCK)
3378 network->mode |= IEEE_B;
3379 }
3380
3381 if (network->mode == 0) {
3382 RTLLIB_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
3383 "network.\n",
3384 escape_essid(network->ssid,
3385 network->ssid_len),
3386 MAC_ARG(network->bssid));
3387 return 1;
3388 }
3389
3390 if (network->bssht.bdSupportHT){
3391 if (network->mode == IEEE_A)
3392 network->mode = IEEE_N_5G;
3393 else if (network->mode & (IEEE_G | IEEE_B))
3394 network->mode = IEEE_N_24G;
3395 }
3396 if (rtllib_is_empty_essid(network->ssid, network->ssid_len))
3397 network->flags |= NETWORK_EMPTY_ESSID;
3398 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
3399 stats->noise = rtllib_translate_todbm((u8)(100-stats->signal)) -25;
3400
3401 memcpy(&network->stats, stats, sizeof(network->stats));
3402
3403 return 0;
3404}
3405
3406static inline int is_same_network(struct rtllib_network *src,
3407 struct rtllib_network *dst, u8 ssidbroad)
3408{
3409 /* A network is only a duplicate if the channel, BSSID, ESSID
3410 * and the capability field (in particular IBSS and BSS) all match.
3411 * We treat all <hidden> with the same BSSID and channel
3412 * as one network */
3413 return
3414 (((src->ssid_len == dst->ssid_len) || (!ssidbroad)) &&
3415 (src->channel == dst->channel) &&
3416 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
3417 (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (!ssidbroad)) &&
3418 ((src->capability & WLAN_CAPABILITY_IBSS) ==
3419 (dst->capability & WLAN_CAPABILITY_IBSS)) &&
3420 ((src->capability & WLAN_CAPABILITY_ESS) ==
3421 (dst->capability & WLAN_CAPABILITY_ESS)));
3422}
3423
3424static inline void update_ibss_network(struct rtllib_network *dst,
3425 struct rtllib_network *src)
3426{
3427 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
3428 dst->last_scanned = jiffies;
3429}
3430
3431
3432static inline void update_network(struct rtllib_network *dst,
3433 struct rtllib_network *src)
3434{
3435 int qos_active;
3436 u8 old_param;
3437
3438 memcpy(&dst->stats, &src->stats, sizeof(struct rtllib_rx_stats));
3439 dst->capability = src->capability;
3440 memcpy(dst->rates, src->rates, src->rates_len);
3441 dst->rates_len = src->rates_len;
3442 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
3443 dst->rates_ex_len = src->rates_ex_len;
3444 if (src->ssid_len > 0)
3445 {
3446 if (dst->ssid_len == 0)
3447 {
3448 memset(dst->hidden_ssid, 0, sizeof(dst->hidden_ssid));
3449 dst->hidden_ssid_len = src->ssid_len;
3450 memcpy(dst->hidden_ssid, src->ssid, src->ssid_len);
3451 }else{
3452 memset(dst->ssid, 0, dst->ssid_len);
3453 dst->ssid_len = src->ssid_len;
3454 memcpy(dst->ssid, src->ssid, src->ssid_len);
3455 }
3456 }
3457 dst->mode = src->mode;
3458 dst->flags = src->flags;
3459 dst->time_stamp[0] = src->time_stamp[0];
3460 dst->time_stamp[1] = src->time_stamp[1];
3461 if (src->flags & NETWORK_HAS_ERP_VALUE)
3462 {
3463 dst->erp_value = src->erp_value;
3464 dst->berp_info_valid = src->berp_info_valid = true;
3465 }
3466 dst->beacon_interval = src->beacon_interval;
3467 dst->listen_interval = src->listen_interval;
3468 dst->atim_window = src->atim_window;
3469 dst->dtim_period = src->dtim_period;
3470 dst->dtim_data = src->dtim_data;
3471 dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
3472 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
3473 memcpy(&dst->tim, &src->tim, sizeof(struct rtllib_tim_parameters));
3474
3475 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
3476 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
3477 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
3478 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
3479 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen;
3480 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen);
3481 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
3482 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
3483 dst->broadcom_cap_exist = src->broadcom_cap_exist;
3484 dst->ralink_cap_exist = src->ralink_cap_exist;
3485 dst->atheros_cap_exist = src->atheros_cap_exist;
3486 dst->realtek_cap_exit = src->realtek_cap_exit;
3487 dst->marvell_cap_exist = src->marvell_cap_exist;
3488 dst->cisco_cap_exist = src->cisco_cap_exist;
3489 dst->airgo_cap_exist = src->airgo_cap_exist;
3490 dst->unknown_cap_exist = src->unknown_cap_exist;
3491 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
3492 dst->wpa_ie_len = src->wpa_ie_len;
3493 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
3494 dst->rsn_ie_len = src->rsn_ie_len;
94a79942
LF
3495 memcpy(dst->wzc_ie, src->wzc_ie, src->wzc_ie_len);
3496 dst->wzc_ie_len = src->wzc_ie_len;
94a79942
LF
3497
3498 dst->last_scanned = jiffies;
3499 /* qos related parameters */
3500 qos_active = dst->qos_data.active;
3501 old_param = dst->qos_data.param_count;
3502 dst->qos_data.supported = src->qos_data.supported;
3503 if (dst->flags & NETWORK_HAS_QOS_PARAMETERS)
3504 memcpy(&dst->qos_data, &src->qos_data, sizeof(struct rtllib_qos_data));
3505 if (dst->qos_data.supported == 1) {
3506 if (dst->ssid_len)
3507 RTLLIB_DEBUG_QOS
3508 ("QoS the network %s is QoS supported\n",
3509 dst->ssid);
3510 else
3511 RTLLIB_DEBUG_QOS
3512 ("QoS the network is QoS supported\n");
3513 }
3514 dst->qos_data.active = qos_active;
3515 dst->qos_data.old_param_count = old_param;
3516
3517 /* dst->last_associate is not overwritten */
3518 dst->wmm_info = src->wmm_info;
3519 if (src->wmm_param[0].ac_aci_acm_aifsn|| \
3520 src->wmm_param[1].ac_aci_acm_aifsn|| \
3521 src->wmm_param[2].ac_aci_acm_aifsn|| \
3522 src->wmm_param[1].ac_aci_acm_aifsn) {
3523 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
3524 }
3525
3526 dst->SignalStrength = src->SignalStrength;
3527 dst->RSSI = src->RSSI;
3528 dst->Turbo_Enable = src->Turbo_Enable;
3529
3530#ifdef ENABLE_DOT11D
3531 dst->CountryIeLen = src->CountryIeLen;
3532 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
3533#endif
3534
3535 dst->bWithAironetIE = src->bWithAironetIE;
3536 dst->bCkipSupported = src->bCkipSupported;
3537 memcpy(dst->CcxRmState,src->CcxRmState,2);
3538 dst->bCcxRmEnable = src->bCcxRmEnable;
3539 dst->MBssidMask = src->MBssidMask;
3540 dst->bMBssidValid = src->bMBssidValid;
3541 memcpy(dst->MBssid,src->MBssid,6);
3542 dst->bWithCcxVerNum = src->bWithCcxVerNum;
3543 dst->BssCcxVerNumber = src->BssCcxVerNumber;
3544
3545}
3546static inline int is_beacon(__le16 fc)
3547{
3548 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == RTLLIB_STYPE_BEACON);
3549}
3550
3551#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3552u8 AsocEntry_ComputeSum(u8 *paddr)
3553{
3554 u32 sum;
3555
3556 sum = paddr[0]+
3557 paddr[1]+
3558 paddr[2]+
3559 paddr[3]+
3560 paddr[4]+
3561 paddr[5];
3562
3563 return (u8)(sum % PEER_MAX_ASSOC);
3564}
3565u8 AsocEntry_AssignAvailableAID(struct rtllib_device *ieee, u8 *paddr)
3566{
3567 int i;
3568
3569 for (i = 0; i < PEER_MAX_ASSOC; i++)
3570 {
3571 if (ieee->AvailableAIDTable[i] == 99)
3572 {
3573 ieee->AvailableAIDTable[i] = AsocEntry_ComputeSum(paddr);
3574 return i+1;
3575 }
3576 }
3577
3578 return 1;
3579}
3580
3581void InitStaInfo(struct rtllib_device *ieee,int index)
3582{
3583 int idx = index;
3584 ieee->peer_assoc_list[idx]->StaDataRate = 0;
3585 ieee->peer_assoc_list[idx]->StaSS = 0;
3586 ieee->peer_assoc_list[idx]->RetryFrameCnt = 0;
3587 ieee->peer_assoc_list[idx]->NoRetryFrameCnt = 0;
3588 ieee->peer_assoc_list[idx]->LastRetryCnt = 0;
3589 ieee->peer_assoc_list[idx]->LastNoRetryCnt = 0;
3590 ieee->peer_assoc_list[idx]->AvgRetryRate = 0;
3591 ieee->peer_assoc_list[idx]->LastRetryRate = 0;
3592 ieee->peer_assoc_list[idx]->txRateIndex = 11;
3593 ieee->peer_assoc_list[idx]->APDataRate = 0x2;
3594 ieee->peer_assoc_list[idx]->ForcedDataRate = 0x2;
3595
3596}
3597static u8 IsStaInfoExist(struct rtllib_device *ieee, u8 *addr)
3598{
3599 int k=0;
3600 struct sta_info * psta = NULL;
3601 u8 sta_idx = PEER_MAX_ASSOC;
3602
3603 for (k=0; k<PEER_MAX_ASSOC; k++)
3604 {
3605 psta = ieee->peer_assoc_list[k];
3606 if (NULL != psta)
3607 {
3608 if (memcmp(addr, psta->macaddr, ETH_ALEN) == 0)
3609 {
3610 sta_idx = k;
3611 break;
3612 }
3613 }
3614 }
3615 return sta_idx;
3616}
3617static u8 GetFreeStaInfoIdx(struct rtllib_device *ieee, u8 *addr)
3618{
3619 int k = 0;
3620 while((ieee->peer_assoc_list[k] != NULL) && (k < PEER_MAX_ASSOC))
3621 k++;
3622 printk("%s: addr:"MAC_FMT" index: %d\n", __func__, MAC_ARG(addr), k);
3623 return k;
3624}
3625struct sta_info *GetStaInfo(struct rtllib_device *ieee, u8 *addr)
3626{
3627 int k=0;
3628 struct sta_info * psta = NULL;
3629 struct sta_info * psta_find = NULL;
3630
3631 for (k=0; k<PEER_MAX_ASSOC; k++)
3632 {
3633 psta = ieee->peer_assoc_list[k];
3634 if (NULL != psta)
3635 {
3636 if (memcmp(addr, psta->macaddr, ETH_ALEN) == 0)
3637 {
3638 psta_find = psta;
3639 break;
3640 }
3641 }
3642 }
3643 return psta_find;
3644}
3645void DelStaInfoList(struct rtllib_device *ieee)
3646{
3647 int idx = 0;
3648 struct sta_info * AsocEntry = NULL;
3649
3650 atomic_set(&ieee->AsocEntryNum, 0);
3651 for (idx=0; idx<PEER_MAX_ASSOC; idx++){
3652 AsocEntry = ieee->peer_assoc_list[idx];
3653 if (NULL != AsocEntry){
3654 kfree(AsocEntry);
3655 ieee->peer_assoc_list[idx] = NULL;
3656 }
3657 ieee->AvailableAIDTable[idx] = 99;
3658 }
3659}
3660void DelStaInfo(struct rtllib_device *ieee, u8 *addr)
3661{
3662 struct sta_info * psta = NULL;
3663 int k=0;
3664
3665 for (k=0; k<PEER_MAX_ASSOC; k++)
3666 {
3667 psta = ieee->peer_assoc_list[k];
3668 if (NULL != psta){
3669 if (memcmp(addr, psta->macaddr, ETH_ALEN) == 0){
3670 if (psta->aid > 0 && psta->aid-1 < PEER_MAX_ASSOC)
3671 ieee->AvailableAIDTable[psta->aid-1] = 99;
3672 else
3673 printk("%s(): clear non-existing entry AID\n", __func__);
3674
3675 kfree(psta);
3676 ieee->peer_assoc_list[k] = NULL;
3677 atomic_dec(&ieee->AsocEntryNum);
3678 }
3679 }
3680 }
3681}
3682void IbssAgeFunction(struct rtllib_device *ieee)
3683{
3684 struct sta_info* AsocEntry = NULL;
3685 int idx;
3686 unsigned long CurrentTime;
3687 signed long TimeDifference;
3688 struct rtllib_network *target;
3689
3690 CurrentTime = jiffies;
3691
3692 for (idx = 0; idx < PEER_MAX_ASSOC; idx++)
3693 {
3694 AsocEntry = ieee->peer_assoc_list[idx];
3695 if (AsocEntry)
3696 {
3697 TimeDifference = jiffies_to_msecs(CurrentTime - AsocEntry->LastActiveTime);
3698
3699 if (TimeDifference > 20000)
3700 {
3701 printk("IbssAgeFunction(): "MAC_FMT" timeout\n", MAC_ARG(AsocEntry->macaddr));
3702 kfree(AsocEntry);
3703 ieee->peer_assoc_list[idx] = NULL;
3704 atomic_dec(&ieee->AsocEntryNum);
3705
3706 if (atomic_read(&ieee->AsocEntryNum) == 0){
3707
3708 down(&ieee->wx_sem);
3709 rtllib_stop_protocol(ieee,true);
3710
3711 list_for_each_entry(target, &ieee->network_list, list) {
3712 if (is_same_network(target, &ieee->current_network,(target->ssid_len?1:0))){
3713 printk("delete sta of previous Ad-hoc\n");
3714 list_del(&target->list);
3715 break;
3716 }
3717 }
3718
3719 rtllib_start_protocol(ieee);
3720 up(&ieee->wx_sem);
3721 }
3722 }
3723 }
3724 }
3725
3726#ifdef TO_DO_LIST
3727 if (AsocEntry_AnyStationAssociated(pMgntInfo)==false)
3728 DrvIFIndicateDisassociation(Adapter, unspec_reason);
3729
3730 if (pMgntInfo->dot11CurrentWirelessMode == WIRELESS_MODE_G ||
3731 (IS_WIRELESS_MODE_N_24G(Adapter) && pMgntInfo->pHTInfo->bCurSuppCCK) )
3732 {
3733 if (nBModeStaCnt == 0)
3734 {
3735 pMgntInfo->bUseProtection = false;
3736 ActUpdate_mCapInfo(Adapter, pMgntInfo->mCap);
3737 }
3738 }
3739
3740 if (IS_WIRELESS_MODE_N_24G(Adapter) || IS_WIRELESS_MODE_N_5G(Adapter) )
3741 {
3742 if (nLegacyStaCnt > 0)
3743 {
3744 pMgntInfo->pHTInfo->CurrentOpMode = HT_OPMODE_MIXED;
3745 }
3746 else
3747 {
3748 if ((pMgntInfo->pHTInfo->bCurBW40MHz) && (n20MHzStaCnt > 0))
3749 pMgntInfo->pHTInfo->CurrentOpMode = HT_OPMODE_40MHZ_PROTECT;
3750 else
3751 pMgntInfo->pHTInfo->CurrentOpMode = HT_OPMODE_NO_PROTECT;
3752
3753 }
3754 }
3755
3756 if (IS_WIRELESS_MODE_G(Adapter) ||
3757 (IS_WIRELESS_MODE_N_24G(Adapter) && pMgntInfo->pHTInfo->bCurSuppCCK))
3758 {
3759 if (pMgntInfo->bUseProtection)
3760 {
3761 u8 CckRate[4] = { MGN_1M, MGN_2M, MGN_5_5M, MGN_11M };
3762 OCTET_STRING osCckRate;
3763 FillOctetString(osCckRate, CckRate, 4);
3764 FilterSupportRate(pMgntInfo->mBrates, &osCckRate, false);
3765 Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_BASIC_RATE, (pu1Byte)&osCckRate);
3766 }
3767 else
3768 {
3769 Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
3770 }
3771 }
3772#endif
3773}
3774#endif
3775
3776static int IsPassiveChannel( struct rtllib_device *rtllib, u8 channel)
3777{
3778 if (MAX_CHANNEL_NUMBER < channel) {
3779 printk("%s(): Invalid Channel\n", __func__);
3780 return 0;
3781 }
3782
3783 if (rtllib->active_channel_map[channel] == 2)
3784 return 1;
3785
3786 return 0;
3787}
3788
3789int IsLegalChannel( struct rtllib_device *rtllib, u8 channel)
3790{
3791 if (MAX_CHANNEL_NUMBER < channel) {
3792 printk("%s(): Invalid Channel\n", __func__);
3793 return 0;
3794 }
3795 if (rtllib->active_channel_map[channel] > 0)
3796 return 1;
3797
3798 return 0;
3799}
3800
3801
3802static inline void rtllib_process_probe_response(
3803 struct rtllib_device *ieee,
3804 struct rtllib_probe_response *beacon,
3805 struct rtllib_rx_stats *stats)
3806{
3807 struct rtllib_network *target;
3808 struct rtllib_network *oldest = NULL;
3809#ifdef CONFIG_RTLLIB_DEBUG
3810 struct rtllib_info_element *info_element = &beacon->info_element[0];
3811#endif
3812 unsigned long flags;
3813 short renew;
94a79942 3814 struct rtllib_network *network = kzalloc(sizeof(struct rtllib_network), GFP_ATOMIC);
94a79942 3815
cb762154 3816 if (!network)
94a79942 3817 return;
94a79942
LF
3818
3819 RTLLIB_DEBUG_SCAN(
3820 "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
3821 escape_essid(info_element->data, info_element->len),
3822 MAC_ARG(beacon->header.addr3),
3823 (beacon->capability & (1<<0xf)) ? '1' : '0',
3824 (beacon->capability & (1<<0xe)) ? '1' : '0',
3825 (beacon->capability & (1<<0xd)) ? '1' : '0',
3826 (beacon->capability & (1<<0xc)) ? '1' : '0',
3827 (beacon->capability & (1<<0xb)) ? '1' : '0',
3828 (beacon->capability & (1<<0xa)) ? '1' : '0',
3829 (beacon->capability & (1<<0x9)) ? '1' : '0',
3830 (beacon->capability & (1<<0x8)) ? '1' : '0',
3831 (beacon->capability & (1<<0x7)) ? '1' : '0',
3832 (beacon->capability & (1<<0x6)) ? '1' : '0',
3833 (beacon->capability & (1<<0x5)) ? '1' : '0',
3834 (beacon->capability & (1<<0x4)) ? '1' : '0',
3835 (beacon->capability & (1<<0x3)) ? '1' : '0',
3836 (beacon->capability & (1<<0x2)) ? '1' : '0',
3837 (beacon->capability & (1<<0x1)) ? '1' : '0',
3838 (beacon->capability & (1<<0x0)) ? '1' : '0');
3839
3840 if (rtllib_network_init(ieee, beacon, network, stats)) {
3841 RTLLIB_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
3842 escape_essid(info_element->data,
3843 info_element->len),
3844 MAC_ARG(beacon->header.addr3),
3845 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
3846 RTLLIB_STYPE_PROBE_RESP ?
3847 "PROBE RESPONSE" : "BEACON");
3848 goto free_network;
3849 }
3850
3851
3852 if (!IsLegalChannel(ieee, network->channel))
3853 goto free_network;
3854
3855 if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == RTLLIB_STYPE_PROBE_RESP) {
3856 if (IsPassiveChannel(ieee, network->channel)) {
3857 printk("GetScanInfo(): For Global Domain, "
3858 "filter probe response at channel(%d).\n", network->channel);
3859 goto free_network;
3860 }
3861 }
3862
3863 /* The network parsed correctly -- so now we scan our known networks
3864 * to see if we can find it in our list.
3865 *
3866 * NOTE: This search is definitely not optimized. Once its doing
3867 * the "right thing" we'll optimize it for efficiency if
3868 * necessary */
3869
3870 /* Search for this entry in the list and update it if it is
3871 * already there. */
3872
3873 spin_lock_irqsave(&ieee->lock, flags);
3874#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3875 if (is_beacon(beacon->header.frame_ctl)){
3876 if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->state == RTLLIB_LINKED))
3877 {
3878 if ((network->ssid_len == ieee->current_network.ssid_len)
3879 && (!memcmp(network->ssid,ieee->current_network.ssid,ieee->current_network.ssid_len))
3880 && (network->channel == ieee->current_network.channel)
3881 && (ieee->current_network.channel > 0)
3882 && (ieee->current_network.channel <= 14))
3883 {
3884 if (!memcmp(ieee->current_network.bssid,network->bssid,6))
3885 {
3886 int idx = 0;
3887 struct rtllib_hdr_3addr* header = NULL;
3888 int idx_exist = 0;
3889 if (timer_pending(&ieee->ibss_wait_timer))
3890 del_timer_sync(&ieee->ibss_wait_timer);
3891 header = (struct rtllib_hdr_3addr*)&(beacon->header);
3892 idx_exist = IsStaInfoExist(ieee,header->addr2);
3893 if (idx_exist >= PEER_MAX_ASSOC) {
3894 idx = GetFreeStaInfoIdx(ieee, header->addr2);
3895 } else {
3896 ieee->peer_assoc_list[idx_exist]->LastActiveTime = jiffies;
3897 goto no_alloc;
3898 }
3899 if (idx >= PEER_MAX_ASSOC - 1) {
3900 printk("\n%s():ERR!!!Buffer overflow - could not append!!!",__func__);
3901 goto free_network;
3902 } else {
3903 ieee->peer_assoc_list[idx] = (struct sta_info *)kmalloc(sizeof(struct sta_info), GFP_ATOMIC);
3904 memset(ieee->peer_assoc_list[idx], 0, sizeof(struct sta_info));
3905 ieee->peer_assoc_list[idx]->LastActiveTime = jiffies;
3906 memcpy(ieee->peer_assoc_list[idx]->macaddr,header->addr2,ETH_ALEN);
3907 ieee->peer_assoc_list[idx]->ratr_index = 8;
3908 InitStaInfo(ieee,idx);
3909 atomic_inc(&ieee->AsocEntryNum);
3910 ieee->peer_assoc_list[idx]->aid = AsocEntry_AssignAvailableAID(ieee, ieee->peer_assoc_list[idx]->macaddr);
3911 ieee->check_ht_cap(ieee->dev,ieee->peer_assoc_list[idx],network);
3912 queue_delayed_work_rsl(ieee->wq, &ieee->update_assoc_sta_info_wq, 0);
3913 ieee->Adhoc_InitRateAdaptive(ieee->dev,ieee->peer_assoc_list[idx]);
3914 }
3915 }
3916 }
3917 }
3918 }
3919 if (ieee->iw_mode == IW_MODE_ADHOC){
3920 if ((network->ssid_len == ieee->current_network.ssid_len)
3921 && (!memcmp(network->ssid,ieee->current_network.ssid,ieee->current_network.ssid_len))
3922 && (network->capability & WLAN_CAPABILITY_IBSS)
3923 && (ieee->state == RTLLIB_LINKED_SCANNING))
3924 {
3925 if (memcmp(ieee->current_network.bssid,network->bssid,6))
3926 {
3927 printk("%s(): SSID matched but BSSID mismatched.\n",__func__);
3928
3929 ieee->TargetTsf = beacon->time_stamp[1];
3930 ieee->TargetTsf <<= 32;
3931 ieee->TargetTsf |= beacon->time_stamp[0];
3932
3933 ieee->CurrTsf = stats->TimeStampLow;
3934
3935 queue_delayed_work_rsl(ieee->wq, &ieee->check_tsf_wq, 0);
3936 }
3937 }
3938 }
3939#endif
3940#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3941no_alloc:
3942 if (ieee->iw_mode == IW_MODE_INFRA)
3943#endif
3944 {
3945 if (is_same_network(&ieee->current_network, network, (network->ssid_len?1:0))) {
3946 update_network(&ieee->current_network, network);
3947 if ((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
3948 && ieee->current_network.berp_info_valid){
3949 if (ieee->current_network.erp_value& ERP_UseProtection)
3950 ieee->current_network.buseprotection = true;
3951 else
3952 ieee->current_network.buseprotection = false;
3953 }
3954 if (is_beacon(beacon->header.frame_ctl))
3955 {
3956 if (ieee->state >= RTLLIB_LINKED)
3957 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
3958 }
3959 }
3960 }
3961#if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3962 else if (ieee->iw_mode == IW_MODE_ADHOC)
3963 {
3964 if (is_same_network(&ieee->current_network, network, (network->ssid_len?1:0))) {
3965 update_ibss_network(&ieee->current_network, network);
3966 }
3967 }
3968#endif
3969 list_for_each_entry(target, &ieee->network_list, list) {
3970 if (is_same_network(target, network,(target->ssid_len?1:0)))
3971 break;
3972 if ((oldest == NULL) ||
3973 (target->last_scanned < oldest->last_scanned))
3974 oldest = target;
3975 }
3976
3977 /* If we didn't find a match, then get a new network slot to initialize
3978 * with this beacon's information */
3979 if (&target->list == &ieee->network_list) {
3980 if (list_empty(&ieee->network_free_list)) {
3981 /* If there are no more slots, expire the oldest */
3982 list_del(&oldest->list);
3983 target = oldest;
3984 RTLLIB_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
3985 "network list.\n",
3986 escape_essid(target->ssid,
3987 target->ssid_len),
3988 MAC_ARG(target->bssid));
3989 } else {
3990 /* Otherwise just pull from the free list */
3991 target = list_entry(ieee->network_free_list.next,
3992 struct rtllib_network, list);
3993 list_del(ieee->network_free_list.next);
3994 }
3995
3996
3997#ifdef CONFIG_RTLLIB_DEBUG
3998 RTLLIB_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
3999 escape_essid(network->ssid,
4000 network->ssid_len),
4001 MAC_ARG(network->bssid),
4002 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
4003 RTLLIB_STYPE_PROBE_RESP ?
4004 "PROBE RESPONSE" : "BEACON");
4005#endif
4006 memcpy(target, network, sizeof(*target));
4007 list_add_tail(&target->list, &ieee->network_list);
4008 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
4009 rtllib_softmac_new_net(ieee, network);
4010 } else {
4011 RTLLIB_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
4012 escape_essid(target->ssid,
4013 target->ssid_len),
4014 MAC_ARG(target->bssid),
4015 WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
4016 RTLLIB_STYPE_PROBE_RESP ?
4017 "PROBE RESPONSE" : "BEACON");
4018
4019 /* we have an entry and we are going to update it. But this entry may
4020 * be already expired. In this case we do the same as we found a new
4021 * net and call the new_net handler
4022 */
4023 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
4024 if ((!target->ssid_len) &&
4025 (((network->ssid_len > 0) && (target->hidden_ssid_len == 0))
4026 || ((ieee->current_network.ssid_len == network->ssid_len) &&
4027 (strncmp(ieee->current_network.ssid, network->ssid, network->ssid_len) == 0) &&
4028 (ieee->state == RTLLIB_NOLINK)))
4029 ) {
4030 renew = 1;
4031 }
4032 update_network(target, network);
4033 if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
4034 rtllib_softmac_new_net(ieee, network);
4035 }
4036
4037 spin_unlock_irqrestore(&ieee->lock, flags);
4038 if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, network, (network->ssid_len?1:0))&&\
4039 (ieee->state == RTLLIB_LINKED)) {
4040 if (ieee->handle_beacon != NULL) {
4041 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
4042 }
4043 }
4044free_network:
4045 kfree(network);
4046 return;
4047}
4048
4049void rtllib_rx_mgt(struct rtllib_device *ieee,
4050 struct sk_buff *skb,
4051 struct rtllib_rx_stats *stats)
4052{
4053 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data ;
4054 if (WLAN_FC_GET_STYPE(header->frame_ctl) != RTLLIB_STYPE_PROBE_RESP &&
4055 WLAN_FC_GET_STYPE(header->frame_ctl) != RTLLIB_STYPE_BEACON)
4056 ieee->last_rx_ps_time = jiffies;
4057
4058 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
4059
4060 case RTLLIB_STYPE_BEACON:
4061 RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
4062 WLAN_FC_GET_STYPE(header->frame_ctl));
4063 RTLLIB_DEBUG_SCAN("Beacon\n");
4064 rtllib_process_probe_response(
4065 ieee, (struct rtllib_probe_response *)header, stats);
4066
4067 if (ieee->sta_sleep || (ieee->ps != RTLLIB_PS_DISABLED &&
4068 ieee->iw_mode == IW_MODE_INFRA &&
4069 ieee->state == RTLLIB_LINKED))
4070 tasklet_schedule(&ieee->ps_task);
4071
4072 break;
4073
4074 case RTLLIB_STYPE_PROBE_RESP:
4075 RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
4076 WLAN_FC_GET_STYPE(header->frame_ctl));
4077 RTLLIB_DEBUG_SCAN("Probe response\n");
4078 rtllib_process_probe_response(
4079 ieee, (struct rtllib_probe_response *)header, stats);
4080 break;
4081 case RTLLIB_STYPE_PROBE_REQ:
4082 RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
4083 WLAN_FC_GET_STYPE(header->frame_ctl));
4084 RTLLIB_DEBUG_SCAN("Probe request\n");
4085 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
4086 ((ieee->iw_mode == IW_MODE_ADHOC ||
4087 ieee->iw_mode == IW_MODE_MASTER) &&
4088 ieee->state == RTLLIB_LINKED)){
4089 rtllib_rx_probe_rq(ieee, skb);
4090 }
4091 break;
4092 }
4093
4094}
This page took 0.184703 seconds and 5 git commands to generate.