2 * Original code based Host AP (software wireless LAN access point) driver
3 * for Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
8 * Copyright (c) 2004-2005, Intel Corporation
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
16 #include <linux/compiler.h>
17 #include <linux/errno.h>
18 #include <linux/if_arp.h>
19 #include <linux/in6.h>
20 #include <linux/gfp.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/netdevice.h>
26 #include <linux/proc_fs.h>
27 #include <linux/skbuff.h>
28 #include <linux/tcp.h>
29 #include <linux/types.h>
30 #include <linux/wireless.h>
31 #include <linux/etherdevice.h>
32 #include <asm/uaccess.h>
33 #include <linux/ctype.h>
35 #include <net/lib80211.h>
39 static void libipw_monitor_rx(struct libipw_device
*ieee
,
41 struct libipw_rx_stats
*rx_stats
)
43 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
44 u16 fc
= le16_to_cpu(hdr
->frame_control
);
47 skb_reset_mac_header(skb
);
48 skb_pull(skb
, libipw_get_hdrlen(fc
));
49 skb
->pkt_type
= PACKET_OTHERHOST
;
50 skb
->protocol
= htons(ETH_P_80211_RAW
);
51 memset(skb
->cb
, 0, sizeof(skb
->cb
));
55 /* Called only as a tasklet (software IRQ) */
56 static struct libipw_frag_entry
*libipw_frag_cache_find(struct
64 struct libipw_frag_entry
*entry
;
67 for (i
= 0; i
< LIBIPW_FRAG_CACHE_LEN
; i
++) {
68 entry
= &ieee
->frag_cache
[i
];
69 if (entry
->skb
!= NULL
&&
70 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
71 LIBIPW_DEBUG_FRAG("expiring fragment cache entry "
72 "seq=%u last_frag=%u\n",
73 entry
->seq
, entry
->last_frag
);
74 dev_kfree_skb_any(entry
->skb
);
78 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
79 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
80 ether_addr_equal(entry
->src_addr
, src
) &&
81 ether_addr_equal(entry
->dst_addr
, dst
))
88 /* Called only as a tasklet (software IRQ) */
89 static struct sk_buff
*libipw_frag_cache_get(struct libipw_device
*ieee
,
90 struct libipw_hdr_4addr
*hdr
)
92 struct sk_buff
*skb
= NULL
;
94 unsigned int frag
, seq
;
95 struct libipw_frag_entry
*entry
;
97 sc
= le16_to_cpu(hdr
->seq_ctl
);
98 frag
= WLAN_GET_SEQ_FRAG(sc
);
99 seq
= WLAN_GET_SEQ_SEQ(sc
);
102 /* Reserve enough space to fit maximum frame length */
103 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
104 sizeof(struct libipw_hdr_4addr
) +
107 8 /* WEP */ + ETH_ALEN
/* WDS */ );
111 entry
= &ieee
->frag_cache
[ieee
->frag_next_idx
];
112 ieee
->frag_next_idx
++;
113 if (ieee
->frag_next_idx
>= LIBIPW_FRAG_CACHE_LEN
)
114 ieee
->frag_next_idx
= 0;
116 if (entry
->skb
!= NULL
)
117 dev_kfree_skb_any(entry
->skb
);
119 entry
->first_frag_time
= jiffies
;
121 entry
->last_frag
= frag
;
123 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
124 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
126 /* received a fragment of a frame for which the head fragment
127 * should have already been received */
128 entry
= libipw_frag_cache_find(ieee
, seq
, frag
, hdr
->addr2
,
131 entry
->last_frag
= frag
;
139 /* Called only as a tasklet (software IRQ) */
140 static int libipw_frag_cache_invalidate(struct libipw_device
*ieee
,
141 struct libipw_hdr_4addr
*hdr
)
145 struct libipw_frag_entry
*entry
;
147 sc
= le16_to_cpu(hdr
->seq_ctl
);
148 seq
= WLAN_GET_SEQ_SEQ(sc
);
150 entry
= libipw_frag_cache_find(ieee
, seq
, -1, hdr
->addr2
,
154 LIBIPW_DEBUG_FRAG("could not invalidate fragment cache "
155 "entry (seq=%u)\n", seq
);
164 /* libipw_rx_frame_mgtmt
166 * Responsible for handling management control frames
168 * Called by libipw_rx */
170 libipw_rx_frame_mgmt(struct libipw_device
*ieee
, struct sk_buff
*skb
,
171 struct libipw_rx_stats
*rx_stats
, u16 type
,
174 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
175 printk(KERN_DEBUG
"%s: Master mode not yet supported.\n",
179 hostap_update_sta_ps(ieee, (struct hostap_libipw_hdr_4addr *)
183 if (ieee
->hostapd
&& type
== WLAN_FC_TYPE_MGMT
) {
184 if (stype
== WLAN_FC_STYPE_BEACON
&&
185 ieee
->iw_mode
== IW_MODE_MASTER
) {
186 struct sk_buff
*skb2
;
187 /* Process beacon frames also in kernel driver to
188 * update STA(AP) table statistics */
189 skb2
= skb_clone(skb
, GFP_ATOMIC
);
191 hostap_rx(skb2
->dev
, skb2
, rx_stats
);
194 /* send management frames to the user space daemon for
196 ieee
->apdevstats
.rx_packets
++;
197 ieee
->apdevstats
.rx_bytes
+= skb
->len
;
198 prism2_rx_80211(ieee
->apdev
, skb
, rx_stats
, PRISM2_RX_MGMT
);
202 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
203 if (type
!= WLAN_FC_TYPE_MGMT
&& type
!= WLAN_FC_TYPE_CTRL
) {
204 printk(KERN_DEBUG
"%s: unknown management frame "
205 "(type=0x%02x, stype=0x%02x) dropped\n",
206 skb
->dev
->name
, type
, stype
);
210 hostap_rx(skb
->dev
, skb
, rx_stats
);
214 printk(KERN_DEBUG
"%s: hostap_rx_frame_mgmt: management frame "
215 "received in non-Host AP mode\n", skb
->dev
->name
);
220 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
221 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
222 static unsigned char libipw_rfc1042_header
[] =
223 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
225 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
226 static unsigned char libipw_bridge_tunnel_header
[] =
227 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
228 /* No encapsulation header if EtherType < 0x600 (=length) */
230 /* Called by libipw_rx_frame_decrypt */
231 static int libipw_is_eapol_frame(struct libipw_device
*ieee
,
234 struct net_device
*dev
= ieee
->dev
;
236 struct libipw_hdr_3addr
*hdr
;
242 hdr
= (struct libipw_hdr_3addr
*)skb
->data
;
243 fc
= le16_to_cpu(hdr
->frame_ctl
);
245 /* check that the frame is unicast frame to us */
246 if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
247 IEEE80211_FCTL_TODS
&&
248 ether_addr_equal(hdr
->addr1
, dev
->dev_addr
) &&
249 ether_addr_equal(hdr
->addr3
, dev
->dev_addr
)) {
250 /* ToDS frame with own addr BSSID and DA */
251 } else if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
252 IEEE80211_FCTL_FROMDS
&&
253 ether_addr_equal(hdr
->addr1
, dev
->dev_addr
)) {
254 /* FromDS frame with own addr as DA */
258 if (skb
->len
< 24 + 8)
261 /* check for port access entity Ethernet type */
262 pos
= skb
->data
+ 24;
263 ethertype
= (pos
[6] << 8) | pos
[7];
264 if (ethertype
== ETH_P_PAE
)
270 /* Called only as a tasklet (software IRQ), by libipw_rx */
272 libipw_rx_frame_decrypt(struct libipw_device
*ieee
, struct sk_buff
*skb
,
273 struct lib80211_crypt_data
*crypt
)
275 struct libipw_hdr_3addr
*hdr
;
278 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
281 hdr
= (struct libipw_hdr_3addr
*)skb
->data
;
282 hdrlen
= libipw_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
284 atomic_inc(&crypt
->refcnt
);
285 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
286 atomic_dec(&crypt
->refcnt
);
288 LIBIPW_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
291 LIBIPW_DEBUG_DROP("Decryption failed ICV "
292 "mismatch (key %d)\n",
293 skb
->data
[hdrlen
+ 3] >> 6);
294 ieee
->ieee_stats
.rx_discards_undecryptable
++;
301 /* Called only as a tasklet (software IRQ), by libipw_rx */
303 libipw_rx_frame_decrypt_msdu(struct libipw_device
*ieee
,
304 struct sk_buff
*skb
, int keyidx
,
305 struct lib80211_crypt_data
*crypt
)
307 struct libipw_hdr_3addr
*hdr
;
310 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
313 hdr
= (struct libipw_hdr_3addr
*)skb
->data
;
314 hdrlen
= libipw_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
316 atomic_inc(&crypt
->refcnt
);
317 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
318 atomic_dec(&crypt
->refcnt
);
320 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
321 " (SA=%pM keyidx=%d)\n", ieee
->dev
->name
, hdr
->addr2
,
329 /* All received frames are sent to this function. @skb contains the frame in
330 * IEEE 802.11 format, i.e., in the format it was sent over air.
331 * This function is called only as a tasklet (software IRQ). */
332 int libipw_rx(struct libipw_device
*ieee
, struct sk_buff
*skb
,
333 struct libipw_rx_stats
*rx_stats
)
335 struct net_device
*dev
= ieee
->dev
;
336 struct libipw_hdr_4addr
*hdr
;
338 u16 fc
, type
, stype
, sc
;
343 struct net_device
*wds
= NULL
;
344 struct sk_buff
*skb2
= NULL
;
345 struct net_device
*wds
= NULL
;
346 int frame_authorized
= 0;
347 int from_assoc_ap
= 0;
352 struct lib80211_crypt_data
*crypt
= NULL
;
354 int can_be_decrypted
= 0;
356 hdr
= (struct libipw_hdr_4addr
*)skb
->data
;
358 printk(KERN_INFO
"%s: SKB length < 10\n", dev
->name
);
362 fc
= le16_to_cpu(hdr
->frame_ctl
);
363 type
= WLAN_FC_GET_TYPE(fc
);
364 stype
= WLAN_FC_GET_STYPE(fc
);
365 sc
= le16_to_cpu(hdr
->seq_ctl
);
366 frag
= WLAN_GET_SEQ_FRAG(sc
);
367 hdrlen
= libipw_get_hdrlen(fc
);
369 if (skb
->len
< hdrlen
) {
370 printk(KERN_INFO
"%s: invalid SKB length %d\n",
371 dev
->name
, skb
->len
);
375 /* Put this code here so that we avoid duplicating it in all
376 * Rx paths. - Jean II */
377 #ifdef CONFIG_WIRELESS_EXT
378 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
379 /* If spy monitoring on */
380 if (ieee
->spy_data
.spy_number
> 0) {
381 struct iw_quality wstats
;
384 if (rx_stats
->mask
& LIBIPW_STATMASK_RSSI
) {
385 wstats
.level
= rx_stats
->signal
;
386 wstats
.updated
|= IW_QUAL_LEVEL_UPDATED
;
388 wstats
.updated
|= IW_QUAL_LEVEL_INVALID
;
390 if (rx_stats
->mask
& LIBIPW_STATMASK_NOISE
) {
391 wstats
.noise
= rx_stats
->noise
;
392 wstats
.updated
|= IW_QUAL_NOISE_UPDATED
;
394 wstats
.updated
|= IW_QUAL_NOISE_INVALID
;
396 if (rx_stats
->mask
& LIBIPW_STATMASK_SIGNAL
) {
397 wstats
.qual
= rx_stats
->signal
;
398 wstats
.updated
|= IW_QUAL_QUAL_UPDATED
;
400 wstats
.updated
|= IW_QUAL_QUAL_INVALID
;
402 /* Update spy records */
403 wireless_spy_update(ieee
->dev
, hdr
->addr2
, &wstats
);
405 #endif /* IW_WIRELESS_SPY */
406 #endif /* CONFIG_WIRELESS_EXT */
409 hostap_update_rx_stats(local
->ap
, hdr
, rx_stats
);
412 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
413 dev
->stats
.rx_packets
++;
414 dev
->stats
.rx_bytes
+= skb
->len
;
415 libipw_monitor_rx(ieee
, skb
, rx_stats
);
419 can_be_decrypted
= (is_multicast_ether_addr(hdr
->addr1
) ||
420 is_broadcast_ether_addr(hdr
->addr2
)) ?
421 ieee
->host_mc_decrypt
: ieee
->host_decrypt
;
423 if (can_be_decrypted
) {
424 if (skb
->len
>= hdrlen
+ 3) {
425 /* Top two-bits of byte 3 are the key index */
426 keyidx
= skb
->data
[hdrlen
+ 3] >> 6;
429 /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
430 * is only allowed 2-bits of storage, no value of keyidx can
431 * be provided via above code that would result in keyidx
432 * being out of range */
433 crypt
= ieee
->crypt_info
.crypt
[keyidx
];
438 /* Use station specific key to override default keys if the
439 * receiver address is a unicast address ("individual RA"). If
440 * bcrx_sta_key parameter is set, station specific key is used
441 * even with broad/multicast targets (this is against IEEE
442 * 802.11, but makes it easier to use different keys with
443 * stations that do not support WEP key mapping). */
445 if (is_unicast_ether_addr(hdr
->addr1
) || local
->bcrx_sta_key
)
446 (void)hostap_handle_sta_crypto(local
, hdr
, &crypt
,
450 /* allow NULL decrypt to indicate an station specific override
451 * for default encryption */
452 if (crypt
&& (crypt
->ops
== NULL
||
453 crypt
->ops
->decrypt_mpdu
== NULL
))
456 if (!crypt
&& (fc
& IEEE80211_FCTL_PROTECTED
)) {
457 /* This seems to be triggered by some (multicast?)
458 * frames from other than current BSS, so just drop the
459 * frames silently instead of filling system log with
461 LIBIPW_DEBUG_DROP("Decryption failed (not set)"
462 " (SA=%pM)\n", hdr
->addr2
);
463 ieee
->ieee_stats
.rx_discards_undecryptable
++;
468 if (type
!= WLAN_FC_TYPE_DATA
) {
469 if (type
== WLAN_FC_TYPE_MGMT
&& stype
== WLAN_FC_STYPE_AUTH
&&
470 fc
& IEEE80211_FCTL_PROTECTED
&& ieee
->host_decrypt
&&
471 (keyidx
= hostap_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0) {
472 printk(KERN_DEBUG
"%s: failed to decrypt mgmt::auth "
473 "from %pM\n", dev
->name
, hdr
->addr2
);
474 /* TODO: could inform hostapd about this so that it
475 * could send auth failure report */
479 if (libipw_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
485 /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
486 if (sc
== ieee
->prev_seq_ctl
)
489 ieee
->prev_seq_ctl
= sc
;
491 /* Data frame - extract src/dst addresses */
492 if (skb
->len
< LIBIPW_3ADDR_LEN
)
495 switch (fc
& (IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
)) {
496 case IEEE80211_FCTL_FROMDS
:
497 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
498 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
500 case IEEE80211_FCTL_TODS
:
501 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
502 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
504 case IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
:
505 if (skb
->len
< LIBIPW_4ADDR_LEN
)
507 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
508 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
511 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
512 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
517 if (hostap_rx_frame_wds(ieee
, hdr
, fc
, &wds
))
520 skb
->dev
= dev
= wds
;
521 stats
= hostap_get_stats(dev
);
524 if (ieee
->iw_mode
== IW_MODE_MASTER
&& !wds
&&
525 (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
526 IEEE80211_FCTL_FROMDS
&& ieee
->stadev
&&
527 ether_addr_equal(hdr
->addr2
, ieee
->assoc_ap_addr
)) {
528 /* Frame from BSSID of the AP for which we are a client */
529 skb
->dev
= dev
= ieee
->stadev
;
530 stats
= hostap_get_stats(dev
);
536 if ((ieee
->iw_mode
== IW_MODE_MASTER
||
537 ieee
->iw_mode
== IW_MODE_REPEAT
) && !from_assoc_ap
) {
538 switch (hostap_handle_sta_rx(ieee
, dev
, skb
, rx_stats
,
540 case AP_RX_CONTINUE_NOT_AUTHORIZED
:
541 frame_authorized
= 0;
544 frame_authorized
= 1;
554 /* Nullfunc frames may have PS-bit set, so they must be passed to
555 * hostap_handle_sta_rx() before being dropped here. */
557 stype
&= ~IEEE80211_STYPE_QOS_DATA
;
559 if (stype
!= IEEE80211_STYPE_DATA
&&
560 stype
!= IEEE80211_STYPE_DATA_CFACK
&&
561 stype
!= IEEE80211_STYPE_DATA_CFPOLL
&&
562 stype
!= IEEE80211_STYPE_DATA_CFACKPOLL
) {
563 if (stype
!= IEEE80211_STYPE_NULLFUNC
)
564 LIBIPW_DEBUG_DROP("RX: dropped data frame "
565 "with no data (type=0x%02x, "
566 "subtype=0x%02x, len=%d)\n",
567 type
, stype
, skb
->len
);
571 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
573 if ((fc
& IEEE80211_FCTL_PROTECTED
) && can_be_decrypted
&&
574 (keyidx
= libipw_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0)
577 hdr
= (struct libipw_hdr_4addr
*)skb
->data
;
579 /* skb: hdr + (possibly fragmented) plaintext payload */
580 // PR: FIXME: hostap has additional conditions in the "if" below:
581 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
582 if ((frag
!= 0) || (fc
& IEEE80211_FCTL_MOREFRAGS
)) {
584 struct sk_buff
*frag_skb
= libipw_frag_cache_get(ieee
, hdr
);
585 LIBIPW_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
588 LIBIPW_DEBUG(LIBIPW_DL_RX
| LIBIPW_DL_FRAG
,
589 "Rx cannot get skb from fragment "
590 "cache (morefrag=%d seq=%u frag=%u)\n",
591 (fc
& IEEE80211_FCTL_MOREFRAGS
) != 0,
592 WLAN_GET_SEQ_SEQ(sc
), frag
);
600 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
601 printk(KERN_WARNING
"%s: host decrypted and "
602 "reassembled frame did not fit skb\n",
604 libipw_frag_cache_invalidate(ieee
, hdr
);
609 /* copy first fragment (including full headers) into
610 * beginning of the fragment cache skb */
611 skb_copy_from_linear_data(skb
, skb_put(frag_skb
, flen
), flen
);
613 /* append frame payload to the end of the fragment
615 skb_copy_from_linear_data_offset(skb
, hdrlen
,
616 skb_put(frag_skb
, flen
), flen
);
618 dev_kfree_skb_any(skb
);
621 if (fc
& IEEE80211_FCTL_MOREFRAGS
) {
622 /* more fragments expected - leave the skb in fragment
623 * cache for now; it will be delivered to upper layers
624 * after all fragments have been received */
628 /* this was the last fragment and the frame will be
629 * delivered, so remove skb from fragment cache */
631 hdr
= (struct libipw_hdr_4addr
*)skb
->data
;
632 libipw_frag_cache_invalidate(ieee
, hdr
);
635 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
636 * encrypted/authenticated */
637 if ((fc
& IEEE80211_FCTL_PROTECTED
) && can_be_decrypted
&&
638 libipw_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
))
641 hdr
= (struct libipw_hdr_4addr
*)skb
->data
;
642 if (crypt
&& !(fc
& IEEE80211_FCTL_PROTECTED
) && !ieee
->open_wep
) {
643 if ( /*ieee->ieee802_1x && */
644 libipw_is_eapol_frame(ieee
, skb
)) {
645 /* pass unencrypted EAPOL frames even if encryption is
648 LIBIPW_DEBUG_DROP("encryption configured, but RX "
649 "frame not encrypted (SA=%pM)\n",
655 if (crypt
&& !(fc
& IEEE80211_FCTL_PROTECTED
) && !ieee
->open_wep
&&
656 !libipw_is_eapol_frame(ieee
, skb
)) {
657 LIBIPW_DEBUG_DROP("dropped unencrypted RX data "
658 "frame from %pM (drop_unencrypted=1)\n",
663 /* If the frame was decrypted in hardware, we may need to strip off
664 * any security data (IV, ICV, etc) that was left behind */
665 if (!can_be_decrypted
&& (fc
& IEEE80211_FCTL_PROTECTED
) &&
666 ieee
->host_strip_iv_icv
) {
669 /* Top two-bits of byte 3 are the key index */
670 if (skb
->len
>= hdrlen
+ 3)
671 keyidx
= skb
->data
[hdrlen
+ 3] >> 6;
673 /* To strip off any security data which appears before the
674 * payload, we simply increase hdrlen (as the header gets
675 * chopped off immediately below). For the security data which
676 * appears after the payload, we use skb_trim. */
678 switch (ieee
->sec
.encode_alg
[keyidx
]) {
686 /* 4 byte IV, 4 byte ExtIV */
688 /* 8 byte MIC, 4 byte ICV */
692 /* 8 byte CCMP header */
699 if (skb
->len
< trimlen
)
702 __skb_trim(skb
, skb
->len
- trimlen
);
704 if (skb
->len
< hdrlen
)
708 /* skb: hdr + (possible reassembled) full plaintext payload */
710 payload
= skb
->data
+ hdrlen
;
711 ethertype
= (payload
[6] << 8) | payload
[7];
714 /* If IEEE 802.1X is used, check whether the port is authorized to send
715 * the received frame. */
716 if (ieee
->ieee802_1x
&& ieee
->iw_mode
== IW_MODE_MASTER
) {
717 if (ethertype
== ETH_P_PAE
) {
718 printk(KERN_DEBUG
"%s: RX: IEEE 802.1X frame\n",
720 if (ieee
->hostapd
&& ieee
->apdev
) {
721 /* Send IEEE 802.1X frames to the user
722 * space daemon for processing */
723 prism2_rx_80211(ieee
->apdev
, skb
, rx_stats
,
725 ieee
->apdevstats
.rx_packets
++;
726 ieee
->apdevstats
.rx_bytes
+= skb
->len
;
729 } else if (!frame_authorized
) {
730 printk(KERN_DEBUG
"%s: dropped frame from "
731 "unauthorized port (IEEE 802.1X): "
732 "ethertype=0x%04x\n", dev
->name
, ethertype
);
738 /* convert hdr + possible LLC headers into Ethernet header */
739 if (skb
->len
- hdrlen
>= 8 &&
740 ((memcmp(payload
, libipw_rfc1042_header
, SNAP_SIZE
) == 0 &&
741 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
742 memcmp(payload
, libipw_bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
743 /* remove RFC1042 or Bridge-Tunnel encapsulation and
744 * replace EtherType */
745 skb_pull(skb
, hdrlen
+ SNAP_SIZE
);
746 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
747 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
750 /* Leave Ethernet header part of hdr and full payload */
751 skb_pull(skb
, hdrlen
);
752 len
= htons(skb
->len
);
753 memcpy(skb_push(skb
, 2), &len
, 2);
754 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
755 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
759 if (wds
&& ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
760 IEEE80211_FCTL_TODS
) && skb
->len
>= ETH_HLEN
+ ETH_ALEN
) {
761 /* Non-standard frame: get addr4 from its bogus location after
763 skb_copy_to_linear_data_offset(skb
, ETH_ALEN
,
764 skb
->data
+ skb
->len
- ETH_ALEN
,
766 skb_trim(skb
, skb
->len
- ETH_ALEN
);
770 dev
->stats
.rx_packets
++;
771 dev
->stats
.rx_bytes
+= skb
->len
;
774 if (ieee
->iw_mode
== IW_MODE_MASTER
&& !wds
&& ieee
->ap
->bridge_packets
) {
775 if (is_multicast_ether_addr(dst
)) {
776 /* copy multicast frame both to the higher layers and
777 * to the wireless media */
778 ieee
->ap
->bridged_multicast
++;
779 skb2
= skb_clone(skb
, GFP_ATOMIC
);
781 printk(KERN_DEBUG
"%s: skb_clone failed for "
782 "multicast frame\n", dev
->name
);
783 } else if (hostap_is_sta_assoc(ieee
->ap
, dst
)) {
784 /* send frame directly to the associated STA using
785 * wireless media and not passing to higher layers */
786 ieee
->ap
->bridged_unicast
++;
793 /* send to wireless media */
795 skb2
->protocol
= htons(ETH_P_802_3
);
796 skb_reset_mac_header(skb2
);
797 skb_reset_network_header(skb2
);
798 /* skb2->network_header += ETH_HLEN; */
799 dev_queue_xmit(skb2
);
804 skb
->protocol
= eth_type_trans(skb
, dev
);
805 memset(skb
->cb
, 0, sizeof(skb
->cb
));
806 skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
807 if (netif_rx(skb
) == NET_RX_DROP
) {
808 /* netif_rx always succeeds, but it might drop
809 * the packet. If it drops the packet, we log that
812 ("RX: netif_rx dropped the packet\n");
813 dev
->stats
.rx_dropped
++;
820 hostap_handle_sta_release(sta
);
825 dev
->stats
.rx_dropped
++;
827 /* Returning 0 indicates to caller that we have not handled the SKB--
828 * so it is still allocated and can be used again by underlying
829 * hardware as a DMA target */
833 /* Filter out unrelated packets, call libipw_rx[_mgt]
834 * This function takes over the skb, it should not be used again after calling
836 void libipw_rx_any(struct libipw_device
*ieee
,
837 struct sk_buff
*skb
, struct libipw_rx_stats
*stats
)
839 struct libipw_hdr_4addr
*hdr
;
840 int is_packet_for_us
;
843 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
844 if (!libipw_rx(ieee
, skb
, stats
))
845 dev_kfree_skb_irq(skb
);
849 if (skb
->len
< sizeof(struct ieee80211_hdr
))
852 hdr
= (struct libipw_hdr_4addr
*)skb
->data
;
853 fc
= le16_to_cpu(hdr
->frame_ctl
);
855 if ((fc
& IEEE80211_FCTL_VERS
) != 0)
858 switch (fc
& IEEE80211_FCTL_FTYPE
) {
859 case IEEE80211_FTYPE_MGMT
:
860 if (skb
->len
< sizeof(struct libipw_hdr_3addr
))
862 libipw_rx_mgt(ieee
, hdr
, stats
);
863 dev_kfree_skb_irq(skb
);
865 case IEEE80211_FTYPE_DATA
:
867 case IEEE80211_FTYPE_CTL
:
873 is_packet_for_us
= 0;
874 switch (ieee
->iw_mode
) {
876 /* our BSS and not from/to DS */
877 if (ether_addr_equal(hdr
->addr3
, ieee
->bssid
))
878 if ((fc
& (IEEE80211_FCTL_TODS
+IEEE80211_FCTL_FROMDS
)) == 0) {
879 /* promisc: get all */
880 if (ieee
->dev
->flags
& IFF_PROMISC
)
881 is_packet_for_us
= 1;
883 else if (ether_addr_equal(hdr
->addr1
, ieee
->dev
->dev_addr
))
884 is_packet_for_us
= 1;
886 else if (is_multicast_ether_addr(hdr
->addr1
))
887 is_packet_for_us
= 1;
891 /* our BSS (== from our AP) and from DS */
892 if (ether_addr_equal(hdr
->addr2
, ieee
->bssid
))
893 if ((fc
& (IEEE80211_FCTL_TODS
+IEEE80211_FCTL_FROMDS
)) == IEEE80211_FCTL_FROMDS
) {
894 /* promisc: get all */
895 if (ieee
->dev
->flags
& IFF_PROMISC
)
896 is_packet_for_us
= 1;
898 else if (ether_addr_equal(hdr
->addr1
, ieee
->dev
->dev_addr
))
899 is_packet_for_us
= 1;
901 else if (is_multicast_ether_addr(hdr
->addr1
)) {
902 /* not our own packet bcasted from AP */
903 if (!ether_addr_equal(hdr
->addr3
, ieee
->dev
->dev_addr
))
904 is_packet_for_us
= 1;
913 if (is_packet_for_us
)
914 if (!libipw_rx(ieee
, skb
, stats
))
915 dev_kfree_skb_irq(skb
);
919 dev_kfree_skb_irq(skb
);
920 ieee
->dev
->stats
.rx_dropped
++;
923 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
925 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
928 * Make the structure we read from the beacon packet to have
931 static int libipw_verify_qos_info(struct libipw_qos_information_element
932 *info_element
, int sub_type
)
935 if (info_element
->qui_subtype
!= sub_type
)
937 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
939 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
941 if (info_element
->version
!= QOS_VERSION_1
)
948 * Parse a QoS parameter element
950 static int libipw_read_qos_param_element(struct libipw_qos_parameter_info
951 *element_param
, struct libipw_info_element
955 u16 size
= sizeof(struct libipw_qos_parameter_info
) - 2;
957 if ((info_element
== NULL
) || (element_param
== NULL
))
960 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
961 memcpy(element_param
->info_element
.qui
, info_element
->data
,
963 element_param
->info_element
.elementID
= info_element
->id
;
964 element_param
->info_element
.length
= info_element
->len
;
968 ret
= libipw_verify_qos_info(&element_param
->info_element
,
969 QOS_OUI_PARAM_SUB_TYPE
);
974 * Parse a QoS information element
976 static int libipw_read_qos_info_element(struct
977 libipw_qos_information_element
978 *element_info
, struct libipw_info_element
982 u16 size
= sizeof(struct libipw_qos_information_element
) - 2;
984 if (element_info
== NULL
)
986 if (info_element
== NULL
)
989 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
990 memcpy(element_info
->qui
, info_element
->data
,
992 element_info
->elementID
= info_element
->id
;
993 element_info
->length
= info_element
->len
;
998 ret
= libipw_verify_qos_info(element_info
,
999 QOS_OUI_INFO_SUB_TYPE
);
1004 * Write QoS parameters from the ac parameters.
1006 static int libipw_qos_convert_ac_to_parameters(struct
1007 libipw_qos_parameter_info
1009 libipw_qos_parameters
1014 struct libipw_qos_ac_parameter
*ac_params
;
1019 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1020 ac_params
= &(param_elm
->ac_params_record
[i
]);
1022 qos_param
->aifs
[i
] = (ac_params
->aci_aifsn
) & 0x0F;
1023 qos_param
->aifs
[i
] -= (qos_param
->aifs
[i
] < 2) ? 0 : 2;
1025 cw_min
= ac_params
->ecw_min_max
& 0x0F;
1026 qos_param
->cw_min
[i
] = cpu_to_le16((1 << cw_min
) - 1);
1028 cw_max
= (ac_params
->ecw_min_max
& 0xF0) >> 4;
1029 qos_param
->cw_max
[i
] = cpu_to_le16((1 << cw_max
) - 1);
1031 qos_param
->flag
[i
] =
1032 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1034 txop
= le16_to_cpu(ac_params
->tx_op_limit
) * 32;
1035 qos_param
->tx_op_limit
[i
] = cpu_to_le16(txop
);
1041 * we have a generic data element which it may contain QoS information or
1042 * parameters element. check the information element length to decide
1043 * which type to read
1045 static int libipw_parse_qos_info_param_IE(struct libipw_info_element
1047 struct libipw_network
*network
)
1050 struct libipw_qos_parameters
*qos_param
= NULL
;
1051 struct libipw_qos_information_element qos_info_element
;
1053 rc
= libipw_read_qos_info_element(&qos_info_element
, info_element
);
1056 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1057 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1059 struct libipw_qos_parameter_info param_element
;
1061 rc
= libipw_read_qos_param_element(¶m_element
,
1064 qos_param
= &(network
->qos_data
.parameters
);
1065 libipw_qos_convert_ac_to_parameters(¶m_element
,
1067 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1068 network
->qos_data
.param_count
=
1069 param_element
.info_element
.ac_info
& 0x0F;
1074 LIBIPW_DEBUG_QOS("QoS is supported\n");
1075 network
->qos_data
.supported
= 1;
1080 #ifdef CONFIG_LIBIPW_DEBUG
1081 #define MFIE_STRING(x) case WLAN_EID_ ##x: return #x
1083 static const char *get_info_element_string(u16 id
)
1087 MFIE_STRING(SUPP_RATES
);
1088 MFIE_STRING(FH_PARAMS
);
1089 MFIE_STRING(DS_PARAMS
);
1090 MFIE_STRING(CF_PARAMS
);
1092 MFIE_STRING(IBSS_PARAMS
);
1093 MFIE_STRING(COUNTRY
);
1094 MFIE_STRING(HP_PARAMS
);
1095 MFIE_STRING(HP_TABLE
);
1096 MFIE_STRING(REQUEST
);
1097 MFIE_STRING(CHALLENGE
);
1098 MFIE_STRING(PWR_CONSTRAINT
);
1099 MFIE_STRING(PWR_CAPABILITY
);
1100 MFIE_STRING(TPC_REQUEST
);
1101 MFIE_STRING(TPC_REPORT
);
1102 MFIE_STRING(SUPPORTED_CHANNELS
);
1103 MFIE_STRING(CHANNEL_SWITCH
);
1104 MFIE_STRING(MEASURE_REQUEST
);
1105 MFIE_STRING(MEASURE_REPORT
);
1107 MFIE_STRING(IBSS_DFS
);
1108 MFIE_STRING(ERP_INFO
);
1110 MFIE_STRING(EXT_SUPP_RATES
);
1111 MFIE_STRING(VENDOR_SPECIFIC
);
1112 MFIE_STRING(QOS_PARAMETER
);
1119 static int libipw_parse_info_param(struct libipw_info_element
1120 *info_element
, u16 length
,
1121 struct libipw_network
*network
)
1124 #ifdef CONFIG_LIBIPW_DEBUG
1129 while (length
>= sizeof(*info_element
)) {
1130 if (sizeof(*info_element
) + info_element
->len
> length
) {
1131 LIBIPW_DEBUG_MGMT("Info elem: parse failed: "
1132 "info_element->len + 2 > left : "
1133 "info_element->len+2=%zd left=%d, id=%d.\n",
1135 sizeof(*info_element
),
1136 length
, info_element
->id
);
1137 /* We stop processing but don't return an error here
1138 * because some misbehaviour APs break this rule. ie.
1139 * Orinoco AP1000. */
1143 switch (info_element
->id
) {
1145 network
->ssid_len
= min(info_element
->len
,
1146 (u8
) IW_ESSID_MAX_SIZE
);
1147 memcpy(network
->ssid
, info_element
->data
,
1149 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1150 memset(network
->ssid
+ network
->ssid_len
, 0,
1151 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1153 LIBIPW_DEBUG_MGMT("WLAN_EID_SSID: '%*pE' len=%d.\n",
1154 network
->ssid_len
, network
->ssid
,
1158 case WLAN_EID_SUPP_RATES
:
1159 #ifdef CONFIG_LIBIPW_DEBUG
1162 network
->rates_len
= min(info_element
->len
,
1164 for (i
= 0; i
< network
->rates_len
; i
++) {
1165 network
->rates
[i
] = info_element
->data
[i
];
1166 #ifdef CONFIG_LIBIPW_DEBUG
1167 p
+= snprintf(p
, sizeof(rates_str
) -
1168 (p
- rates_str
), "%02X ",
1171 if (libipw_is_ofdm_rate
1172 (info_element
->data
[i
])) {
1173 network
->flags
|= NETWORK_HAS_OFDM
;
1174 if (info_element
->data
[i
] &
1175 LIBIPW_BASIC_RATE_MASK
)
1181 LIBIPW_DEBUG_MGMT("WLAN_EID_SUPP_RATES: '%s' (%d)\n",
1182 rates_str
, network
->rates_len
);
1185 case WLAN_EID_EXT_SUPP_RATES
:
1186 #ifdef CONFIG_LIBIPW_DEBUG
1189 network
->rates_ex_len
= min(info_element
->len
,
1190 MAX_RATES_EX_LENGTH
);
1191 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1192 network
->rates_ex
[i
] = info_element
->data
[i
];
1193 #ifdef CONFIG_LIBIPW_DEBUG
1194 p
+= snprintf(p
, sizeof(rates_str
) -
1195 (p
- rates_str
), "%02X ",
1196 network
->rates_ex
[i
]);
1198 if (libipw_is_ofdm_rate
1199 (info_element
->data
[i
])) {
1200 network
->flags
|= NETWORK_HAS_OFDM
;
1201 if (info_element
->data
[i
] &
1202 LIBIPW_BASIC_RATE_MASK
)
1208 LIBIPW_DEBUG_MGMT("WLAN_EID_EXT_SUPP_RATES: '%s' (%d)\n",
1209 rates_str
, network
->rates_ex_len
);
1212 case WLAN_EID_DS_PARAMS
:
1213 LIBIPW_DEBUG_MGMT("WLAN_EID_DS_PARAMS: %d\n",
1214 info_element
->data
[0]);
1215 network
->channel
= info_element
->data
[0];
1218 case WLAN_EID_FH_PARAMS
:
1219 LIBIPW_DEBUG_MGMT("WLAN_EID_FH_PARAMS: ignored\n");
1222 case WLAN_EID_CF_PARAMS
:
1223 LIBIPW_DEBUG_MGMT("WLAN_EID_CF_PARAMS: ignored\n");
1227 network
->tim
.tim_count
= info_element
->data
[0];
1228 network
->tim
.tim_period
= info_element
->data
[1];
1229 LIBIPW_DEBUG_MGMT("WLAN_EID_TIM: partially ignored\n");
1232 case WLAN_EID_ERP_INFO
:
1233 network
->erp_value
= info_element
->data
[0];
1234 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1235 LIBIPW_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1236 network
->erp_value
);
1239 case WLAN_EID_IBSS_PARAMS
:
1240 network
->atim_window
= info_element
->data
[0];
1241 LIBIPW_DEBUG_MGMT("WLAN_EID_IBSS_PARAMS: %d\n",
1242 network
->atim_window
);
1245 case WLAN_EID_CHALLENGE
:
1246 LIBIPW_DEBUG_MGMT("WLAN_EID_CHALLENGE: ignored\n");
1249 case WLAN_EID_VENDOR_SPECIFIC
:
1250 LIBIPW_DEBUG_MGMT("WLAN_EID_VENDOR_SPECIFIC: %d bytes\n",
1252 if (!libipw_parse_qos_info_param_IE(info_element
,
1256 if (info_element
->len
>= 4 &&
1257 info_element
->data
[0] == 0x00 &&
1258 info_element
->data
[1] == 0x50 &&
1259 info_element
->data
[2] == 0xf2 &&
1260 info_element
->data
[3] == 0x01) {
1261 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1263 memcpy(network
->wpa_ie
, info_element
,
1264 network
->wpa_ie_len
);
1269 LIBIPW_DEBUG_MGMT("WLAN_EID_RSN: %d bytes\n",
1271 network
->rsn_ie_len
= min(info_element
->len
+ 2,
1273 memcpy(network
->rsn_ie
, info_element
,
1274 network
->rsn_ie_len
);
1277 case WLAN_EID_QOS_PARAMETER
:
1279 "QoS Error need to parse QOS_PARAMETER IE\n");
1282 case WLAN_EID_PWR_CONSTRAINT
:
1283 network
->power_constraint
= info_element
->data
[0];
1284 network
->flags
|= NETWORK_HAS_POWER_CONSTRAINT
;
1287 case WLAN_EID_CHANNEL_SWITCH
:
1288 network
->power_constraint
= info_element
->data
[0];
1289 network
->flags
|= NETWORK_HAS_CSA
;
1292 case WLAN_EID_QUIET
:
1293 network
->quiet
.count
= info_element
->data
[0];
1294 network
->quiet
.period
= info_element
->data
[1];
1295 network
->quiet
.duration
= info_element
->data
[2];
1296 network
->quiet
.offset
= info_element
->data
[3];
1297 network
->flags
|= NETWORK_HAS_QUIET
;
1300 case WLAN_EID_IBSS_DFS
:
1301 network
->flags
|= NETWORK_HAS_IBSS_DFS
;
1304 case WLAN_EID_TPC_REPORT
:
1305 network
->tpc_report
.transmit_power
=
1306 info_element
->data
[0];
1307 network
->tpc_report
.link_margin
= info_element
->data
[1];
1308 network
->flags
|= NETWORK_HAS_TPC_REPORT
;
1313 ("Unsupported info element: %s (%d)\n",
1314 get_info_element_string(info_element
->id
),
1319 length
-= sizeof(*info_element
) + info_element
->len
;
1321 (struct libipw_info_element
*)&info_element
->
1322 data
[info_element
->len
];
1328 static int libipw_handle_assoc_resp(struct libipw_device
*ieee
, struct libipw_assoc_response
1329 *frame
, struct libipw_rx_stats
*stats
)
1331 struct libipw_network network_resp
= { };
1332 struct libipw_network
*network
= &network_resp
;
1333 struct net_device
*dev
= ieee
->dev
;
1336 network
->qos_data
.active
= 0;
1337 network
->qos_data
.supported
= 0;
1338 network
->qos_data
.param_count
= 0;
1339 network
->qos_data
.old_param_count
= 0;
1341 //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1342 network
->atim_window
= le16_to_cpu(frame
->aid
);
1343 network
->listen_interval
= le16_to_cpu(frame
->status
);
1344 memcpy(network
->bssid
, frame
->header
.addr3
, ETH_ALEN
);
1345 network
->capability
= le16_to_cpu(frame
->capability
);
1346 network
->last_scanned
= jiffies
;
1347 network
->rates_len
= network
->rates_ex_len
= 0;
1348 network
->last_associate
= 0;
1349 network
->ssid_len
= 0;
1350 network
->erp_value
=
1351 (network
->capability
& WLAN_CAPABILITY_IBSS
) ? 0x3 : 0x0;
1353 if (stats
->freq
== LIBIPW_52GHZ_BAND
) {
1354 /* for A band (No DS info) */
1355 network
->channel
= stats
->received_channel
;
1357 network
->flags
|= NETWORK_HAS_CCK
;
1359 network
->wpa_ie_len
= 0;
1360 network
->rsn_ie_len
= 0;
1362 if (libipw_parse_info_param
1363 (frame
->info_element
, stats
->len
- sizeof(*frame
), network
))
1367 if (stats
->freq
== LIBIPW_52GHZ_BAND
)
1368 network
->mode
= IEEE_A
;
1370 if (network
->flags
& NETWORK_HAS_OFDM
)
1371 network
->mode
|= IEEE_G
;
1372 if (network
->flags
& NETWORK_HAS_CCK
)
1373 network
->mode
|= IEEE_B
;
1376 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
1378 if (ieee
->handle_assoc_response
!= NULL
)
1379 ieee
->handle_assoc_response(dev
, frame
, network
);
1384 /***************************************************/
1386 static int libipw_network_init(struct libipw_device
*ieee
, struct libipw_probe_response
1388 struct libipw_network
*network
,
1389 struct libipw_rx_stats
*stats
)
1391 network
->qos_data
.active
= 0;
1392 network
->qos_data
.supported
= 0;
1393 network
->qos_data
.param_count
= 0;
1394 network
->qos_data
.old_param_count
= 0;
1396 /* Pull out fixed field data */
1397 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
1398 network
->capability
= le16_to_cpu(beacon
->capability
);
1399 network
->last_scanned
= jiffies
;
1400 network
->time_stamp
[0] = le32_to_cpu(beacon
->time_stamp
[0]);
1401 network
->time_stamp
[1] = le32_to_cpu(beacon
->time_stamp
[1]);
1402 network
->beacon_interval
= le16_to_cpu(beacon
->beacon_interval
);
1403 /* Where to pull this? beacon->listen_interval; */
1404 network
->listen_interval
= 0x0A;
1405 network
->rates_len
= network
->rates_ex_len
= 0;
1406 network
->last_associate
= 0;
1407 network
->ssid_len
= 0;
1409 network
->atim_window
= 0;
1410 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
1413 if (stats
->freq
== LIBIPW_52GHZ_BAND
) {
1414 /* for A band (No DS info) */
1415 network
->channel
= stats
->received_channel
;
1417 network
->flags
|= NETWORK_HAS_CCK
;
1419 network
->wpa_ie_len
= 0;
1420 network
->rsn_ie_len
= 0;
1422 if (libipw_parse_info_param
1423 (beacon
->info_element
, stats
->len
- sizeof(*beacon
), network
))
1427 if (stats
->freq
== LIBIPW_52GHZ_BAND
)
1428 network
->mode
= IEEE_A
;
1430 if (network
->flags
& NETWORK_HAS_OFDM
)
1431 network
->mode
|= IEEE_G
;
1432 if (network
->flags
& NETWORK_HAS_CCK
)
1433 network
->mode
|= IEEE_B
;
1436 if (network
->mode
== 0) {
1437 LIBIPW_DEBUG_SCAN("Filtered out '%*pE (%pM)' network.\n",
1438 network
->ssid_len
, network
->ssid
,
1443 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
1448 static inline int is_same_network(struct libipw_network
*src
,
1449 struct libipw_network
*dst
)
1451 /* A network is only a duplicate if the channel, BSSID, and ESSID
1452 * all match. We treat all <hidden> with the same BSSID and channel
1454 return ((src
->ssid_len
== dst
->ssid_len
) &&
1455 (src
->channel
== dst
->channel
) &&
1456 ether_addr_equal_64bits(src
->bssid
, dst
->bssid
) &&
1457 !memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
));
1460 static void update_network(struct libipw_network
*dst
,
1461 struct libipw_network
*src
)
1466 /* We only update the statistics if they were created by receiving
1467 * the network information on the actual channel the network is on.
1469 * This keeps beacons received on neighbor channels from bringing
1470 * down the signal level of an AP. */
1471 if (dst
->channel
== src
->stats
.received_channel
)
1472 memcpy(&dst
->stats
, &src
->stats
,
1473 sizeof(struct libipw_rx_stats
));
1475 LIBIPW_DEBUG_SCAN("Network %pM info received "
1476 "off channel (%d vs. %d)\n", src
->bssid
,
1477 dst
->channel
, src
->stats
.received_channel
);
1479 dst
->capability
= src
->capability
;
1480 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
1481 dst
->rates_len
= src
->rates_len
;
1482 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
1483 dst
->rates_ex_len
= src
->rates_ex_len
;
1485 dst
->mode
= src
->mode
;
1486 dst
->flags
= src
->flags
;
1487 dst
->time_stamp
[0] = src
->time_stamp
[0];
1488 dst
->time_stamp
[1] = src
->time_stamp
[1];
1490 dst
->beacon_interval
= src
->beacon_interval
;
1491 dst
->listen_interval
= src
->listen_interval
;
1492 dst
->atim_window
= src
->atim_window
;
1493 dst
->erp_value
= src
->erp_value
;
1494 dst
->tim
= src
->tim
;
1496 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
1497 dst
->wpa_ie_len
= src
->wpa_ie_len
;
1498 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
1499 dst
->rsn_ie_len
= src
->rsn_ie_len
;
1501 dst
->last_scanned
= jiffies
;
1502 qos_active
= src
->qos_data
.active
;
1503 old_param
= dst
->qos_data
.old_param_count
;
1504 if (dst
->flags
& NETWORK_HAS_QOS_MASK
)
1505 memcpy(&dst
->qos_data
, &src
->qos_data
,
1506 sizeof(struct libipw_qos_data
));
1508 dst
->qos_data
.supported
= src
->qos_data
.supported
;
1509 dst
->qos_data
.param_count
= src
->qos_data
.param_count
;
1512 if (dst
->qos_data
.supported
== 1) {
1515 ("QoS the network %s is QoS supported\n",
1519 ("QoS the network is QoS supported\n");
1521 dst
->qos_data
.active
= qos_active
;
1522 dst
->qos_data
.old_param_count
= old_param
;
1524 /* dst->last_associate is not overwritten */
1527 static inline int is_beacon(__le16 fc
)
1529 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == IEEE80211_STYPE_BEACON
);
1532 static void libipw_process_probe_response(struct libipw_device
1534 libipw_probe_response
1535 *beacon
, struct libipw_rx_stats
1538 struct net_device
*dev
= ieee
->dev
;
1539 struct libipw_network network
= { };
1540 struct libipw_network
*target
;
1541 struct libipw_network
*oldest
= NULL
;
1542 #ifdef CONFIG_LIBIPW_DEBUG
1543 struct libipw_info_element
*info_element
= beacon
->info_element
;
1545 unsigned long flags
;
1547 LIBIPW_DEBUG_SCAN("'%*pE' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1548 info_element
->len
, info_element
->data
,
1549 beacon
->header
.addr3
,
1550 (beacon
->capability
& cpu_to_le16(1 << 0xf)) ? '1' : '0',
1551 (beacon
->capability
& cpu_to_le16(1 << 0xe)) ? '1' : '0',
1552 (beacon
->capability
& cpu_to_le16(1 << 0xd)) ? '1' : '0',
1553 (beacon
->capability
& cpu_to_le16(1 << 0xc)) ? '1' : '0',
1554 (beacon
->capability
& cpu_to_le16(1 << 0xb)) ? '1' : '0',
1555 (beacon
->capability
& cpu_to_le16(1 << 0xa)) ? '1' : '0',
1556 (beacon
->capability
& cpu_to_le16(1 << 0x9)) ? '1' : '0',
1557 (beacon
->capability
& cpu_to_le16(1 << 0x8)) ? '1' : '0',
1558 (beacon
->capability
& cpu_to_le16(1 << 0x7)) ? '1' : '0',
1559 (beacon
->capability
& cpu_to_le16(1 << 0x6)) ? '1' : '0',
1560 (beacon
->capability
& cpu_to_le16(1 << 0x5)) ? '1' : '0',
1561 (beacon
->capability
& cpu_to_le16(1 << 0x4)) ? '1' : '0',
1562 (beacon
->capability
& cpu_to_le16(1 << 0x3)) ? '1' : '0',
1563 (beacon
->capability
& cpu_to_le16(1 << 0x2)) ? '1' : '0',
1564 (beacon
->capability
& cpu_to_le16(1 << 0x1)) ? '1' : '0',
1565 (beacon
->capability
& cpu_to_le16(1 << 0x0)) ? '1' : '0');
1567 if (libipw_network_init(ieee
, beacon
, &network
, stats
)) {
1568 LIBIPW_DEBUG_SCAN("Dropped '%*pE' (%pM) via %s.\n",
1569 info_element
->len
, info_element
->data
,
1570 beacon
->header
.addr3
,
1571 is_beacon(beacon
->header
.frame_ctl
) ?
1572 "BEACON" : "PROBE RESPONSE");
1576 /* The network parsed correctly -- so now we scan our known networks
1577 * to see if we can find it in our list.
1579 * NOTE: This search is definitely not optimized. Once its doing
1580 * the "right thing" we'll optimize it for efficiency if
1583 /* Search for this entry in the list and update it if it is
1586 spin_lock_irqsave(&ieee
->lock
, flags
);
1588 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1589 if (is_same_network(target
, &network
))
1592 if ((oldest
== NULL
) ||
1593 time_before(target
->last_scanned
, oldest
->last_scanned
))
1597 /* If we didn't find a match, then get a new network slot to initialize
1598 * with this beacon's information */
1599 if (&target
->list
== &ieee
->network_list
) {
1600 if (list_empty(&ieee
->network_free_list
)) {
1601 /* If there are no more slots, expire the oldest */
1602 list_del(&oldest
->list
);
1604 LIBIPW_DEBUG_SCAN("Expired '%*pE' (%pM) from network list.\n",
1605 target
->ssid_len
, target
->ssid
,
1608 /* Otherwise just pull from the free list */
1609 target
= list_entry(ieee
->network_free_list
.next
,
1610 struct libipw_network
, list
);
1611 list_del(ieee
->network_free_list
.next
);
1614 #ifdef CONFIG_LIBIPW_DEBUG
1615 LIBIPW_DEBUG_SCAN("Adding '%*pE' (%pM) via %s.\n",
1616 network
.ssid_len
, network
.ssid
,
1618 is_beacon(beacon
->header
.frame_ctl
) ?
1619 "BEACON" : "PROBE RESPONSE");
1621 memcpy(target
, &network
, sizeof(*target
));
1622 list_add_tail(&target
->list
, &ieee
->network_list
);
1624 LIBIPW_DEBUG_SCAN("Updating '%*pE' (%pM) via %s.\n",
1625 target
->ssid_len
, target
->ssid
,
1627 is_beacon(beacon
->header
.frame_ctl
) ?
1628 "BEACON" : "PROBE RESPONSE");
1629 update_network(target
, &network
);
1632 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1634 if (is_beacon(beacon
->header
.frame_ctl
)) {
1635 if (ieee
->handle_beacon
!= NULL
)
1636 ieee
->handle_beacon(dev
, beacon
, target
);
1638 if (ieee
->handle_probe_response
!= NULL
)
1639 ieee
->handle_probe_response(dev
, beacon
, target
);
1643 void libipw_rx_mgt(struct libipw_device
*ieee
,
1644 struct libipw_hdr_4addr
*header
,
1645 struct libipw_rx_stats
*stats
)
1647 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
))) {
1648 case IEEE80211_STYPE_ASSOC_RESP
:
1649 LIBIPW_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
1650 WLAN_FC_GET_STYPE(le16_to_cpu
1651 (header
->frame_ctl
)));
1652 libipw_handle_assoc_resp(ieee
,
1653 (struct libipw_assoc_response
*)
1657 case IEEE80211_STYPE_REASSOC_RESP
:
1658 LIBIPW_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
1659 WLAN_FC_GET_STYPE(le16_to_cpu
1660 (header
->frame_ctl
)));
1663 case IEEE80211_STYPE_PROBE_REQ
:
1664 LIBIPW_DEBUG_MGMT("received auth (%d)\n",
1665 WLAN_FC_GET_STYPE(le16_to_cpu
1666 (header
->frame_ctl
)));
1668 if (ieee
->handle_probe_request
!= NULL
)
1669 ieee
->handle_probe_request(ieee
->dev
,
1671 libipw_probe_request
*)
1675 case IEEE80211_STYPE_PROBE_RESP
:
1676 LIBIPW_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1677 WLAN_FC_GET_STYPE(le16_to_cpu
1678 (header
->frame_ctl
)));
1679 LIBIPW_DEBUG_SCAN("Probe response\n");
1680 libipw_process_probe_response(ieee
,
1682 libipw_probe_response
*)
1686 case IEEE80211_STYPE_BEACON
:
1687 LIBIPW_DEBUG_MGMT("received BEACON (%d)\n",
1688 WLAN_FC_GET_STYPE(le16_to_cpu
1689 (header
->frame_ctl
)));
1690 LIBIPW_DEBUG_SCAN("Beacon\n");
1691 libipw_process_probe_response(ieee
,
1693 libipw_probe_response
*)
1696 case IEEE80211_STYPE_AUTH
:
1698 LIBIPW_DEBUG_MGMT("received auth (%d)\n",
1699 WLAN_FC_GET_STYPE(le16_to_cpu
1700 (header
->frame_ctl
)));
1702 if (ieee
->handle_auth
!= NULL
)
1703 ieee
->handle_auth(ieee
->dev
,
1704 (struct libipw_auth
*)header
);
1707 case IEEE80211_STYPE_DISASSOC
:
1708 if (ieee
->handle_disassoc
!= NULL
)
1709 ieee
->handle_disassoc(ieee
->dev
,
1710 (struct libipw_disassoc
*)
1714 case IEEE80211_STYPE_ACTION
:
1715 LIBIPW_DEBUG_MGMT("ACTION\n");
1716 if (ieee
->handle_action
)
1717 ieee
->handle_action(ieee
->dev
,
1718 (struct libipw_action
*)
1722 case IEEE80211_STYPE_REASSOC_REQ
:
1723 LIBIPW_DEBUG_MGMT("received reassoc (%d)\n",
1724 WLAN_FC_GET_STYPE(le16_to_cpu
1725 (header
->frame_ctl
)));
1727 LIBIPW_DEBUG_MGMT("%s: LIBIPW_REASSOC_REQ received\n",
1729 if (ieee
->handle_reassoc_request
!= NULL
)
1730 ieee
->handle_reassoc_request(ieee
->dev
,
1731 (struct libipw_reassoc_request
*)
1735 case IEEE80211_STYPE_ASSOC_REQ
:
1736 LIBIPW_DEBUG_MGMT("received assoc (%d)\n",
1737 WLAN_FC_GET_STYPE(le16_to_cpu
1738 (header
->frame_ctl
)));
1740 LIBIPW_DEBUG_MGMT("%s: LIBIPW_ASSOC_REQ received\n",
1742 if (ieee
->handle_assoc_request
!= NULL
)
1743 ieee
->handle_assoc_request(ieee
->dev
);
1746 case IEEE80211_STYPE_DEAUTH
:
1747 LIBIPW_DEBUG_MGMT("DEAUTH\n");
1748 if (ieee
->handle_deauth
!= NULL
)
1749 ieee
->handle_deauth(ieee
->dev
,
1750 (struct libipw_deauth
*)
1754 LIBIPW_DEBUG_MGMT("received UNKNOWN (%d)\n",
1755 WLAN_FC_GET_STYPE(le16_to_cpu
1756 (header
->frame_ctl
)));
1757 LIBIPW_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1759 WLAN_FC_GET_STYPE(le16_to_cpu
1760 (header
->frame_ctl
)));
1765 EXPORT_SYMBOL_GPL(libipw_rx_any
);
1766 EXPORT_SYMBOL(libipw_rx_mgt
);
1767 EXPORT_SYMBOL(libipw_rx
);