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>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/netdevice.h>
25 #include <linux/proc_fs.h>
26 #include <linux/skbuff.h>
27 #include <linux/slab.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>
36 #include <net/ieee80211.h>
38 static void ieee80211_monitor_rx(struct ieee80211_device
*ieee
,
40 struct ieee80211_rx_stats
*rx_stats
)
42 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
43 u16 fc
= le16_to_cpu(hdr
->frame_control
);
46 skb_reset_mac_header(skb
);
47 skb_pull(skb
, ieee80211_get_hdrlen(fc
));
48 skb
->pkt_type
= PACKET_OTHERHOST
;
49 skb
->protocol
= htons(ETH_P_80211_RAW
);
50 memset(skb
->cb
, 0, sizeof(skb
->cb
));
54 /* Called only as a tasklet (software IRQ) */
55 static struct ieee80211_frag_entry
*ieee80211_frag_cache_find(struct
63 struct ieee80211_frag_entry
*entry
;
66 for (i
= 0; i
< IEEE80211_FRAG_CACHE_LEN
; i
++) {
67 entry
= &ieee
->frag_cache
[i
];
68 if (entry
->skb
!= NULL
&&
69 time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
70 IEEE80211_DEBUG_FRAG("expiring fragment cache entry "
71 "seq=%u last_frag=%u\n",
72 entry
->seq
, entry
->last_frag
);
73 dev_kfree_skb_any(entry
->skb
);
77 if (entry
->skb
!= NULL
&& entry
->seq
== seq
&&
78 (entry
->last_frag
+ 1 == frag
|| frag
== -1) &&
79 !compare_ether_addr(entry
->src_addr
, src
) &&
80 !compare_ether_addr(entry
->dst_addr
, dst
))
87 /* Called only as a tasklet (software IRQ) */
88 static struct sk_buff
*ieee80211_frag_cache_get(struct ieee80211_device
*ieee
,
89 struct ieee80211_hdr_4addr
*hdr
)
91 struct sk_buff
*skb
= NULL
;
93 unsigned int frag
, seq
;
94 struct ieee80211_frag_entry
*entry
;
96 sc
= le16_to_cpu(hdr
->seq_ctl
);
97 frag
= WLAN_GET_SEQ_FRAG(sc
);
98 seq
= WLAN_GET_SEQ_SEQ(sc
);
101 /* Reserve enough space to fit maximum frame length */
102 skb
= dev_alloc_skb(ieee
->dev
->mtu
+
103 sizeof(struct ieee80211_hdr_4addr
) +
106 8 /* WEP */ + ETH_ALEN
/* WDS */ );
110 entry
= &ieee
->frag_cache
[ieee
->frag_next_idx
];
111 ieee
->frag_next_idx
++;
112 if (ieee
->frag_next_idx
>= IEEE80211_FRAG_CACHE_LEN
)
113 ieee
->frag_next_idx
= 0;
115 if (entry
->skb
!= NULL
)
116 dev_kfree_skb_any(entry
->skb
);
118 entry
->first_frag_time
= jiffies
;
120 entry
->last_frag
= frag
;
122 memcpy(entry
->src_addr
, hdr
->addr2
, ETH_ALEN
);
123 memcpy(entry
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
125 /* received a fragment of a frame for which the head fragment
126 * should have already been received */
127 entry
= ieee80211_frag_cache_find(ieee
, seq
, frag
, hdr
->addr2
,
130 entry
->last_frag
= frag
;
138 /* Called only as a tasklet (software IRQ) */
139 static int ieee80211_frag_cache_invalidate(struct ieee80211_device
*ieee
,
140 struct ieee80211_hdr_4addr
*hdr
)
144 struct ieee80211_frag_entry
*entry
;
146 sc
= le16_to_cpu(hdr
->seq_ctl
);
147 seq
= WLAN_GET_SEQ_SEQ(sc
);
149 entry
= ieee80211_frag_cache_find(ieee
, seq
, -1, hdr
->addr2
,
153 IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
154 "entry (seq=%u)\n", seq
);
163 /* ieee80211_rx_frame_mgtmt
165 * Responsible for handling management control frames
167 * Called by ieee80211_rx */
169 ieee80211_rx_frame_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
170 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
173 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
174 printk(KERN_DEBUG
"%s: Master mode not yet suppported.\n",
178 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
182 if (ieee
->hostapd
&& type
== WLAN_FC_TYPE_MGMT
) {
183 if (stype
== WLAN_FC_STYPE_BEACON
&&
184 ieee
->iw_mode
== IW_MODE_MASTER
) {
185 struct sk_buff
*skb2
;
186 /* Process beacon frames also in kernel driver to
187 * update STA(AP) table statistics */
188 skb2
= skb_clone(skb
, GFP_ATOMIC
);
190 hostap_rx(skb2
->dev
, skb2
, rx_stats
);
193 /* send management frames to the user space daemon for
195 ieee
->apdevstats
.rx_packets
++;
196 ieee
->apdevstats
.rx_bytes
+= skb
->len
;
197 prism2_rx_80211(ieee
->apdev
, skb
, rx_stats
, PRISM2_RX_MGMT
);
201 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
202 if (type
!= WLAN_FC_TYPE_MGMT
&& type
!= WLAN_FC_TYPE_CTRL
) {
203 printk(KERN_DEBUG
"%s: unknown management frame "
204 "(type=0x%02x, stype=0x%02x) dropped\n",
205 skb
->dev
->name
, type
, stype
);
209 hostap_rx(skb
->dev
, skb
, rx_stats
);
213 printk(KERN_DEBUG
"%s: hostap_rx_frame_mgmt: management frame "
214 "received in non-Host AP mode\n", skb
->dev
->name
);
219 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
220 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
221 static unsigned char rfc1042_header
[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
223 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
224 static unsigned char bridge_tunnel_header
[] =
225 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
226 /* No encapsulation header if EtherType < 0x600 (=length) */
228 /* Called by ieee80211_rx_frame_decrypt */
229 static int ieee80211_is_eapol_frame(struct ieee80211_device
*ieee
,
232 struct net_device
*dev
= ieee
->dev
;
234 struct ieee80211_hdr_3addr
*hdr
;
240 hdr
= (struct ieee80211_hdr_3addr
*)skb
->data
;
241 fc
= le16_to_cpu(hdr
->frame_ctl
);
243 /* check that the frame is unicast frame to us */
244 if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
245 IEEE80211_FCTL_TODS
&&
246 !compare_ether_addr(hdr
->addr1
, dev
->dev_addr
) &&
247 !compare_ether_addr(hdr
->addr3
, dev
->dev_addr
)) {
248 /* ToDS frame with own addr BSSID and DA */
249 } else if ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
250 IEEE80211_FCTL_FROMDS
&&
251 !compare_ether_addr(hdr
->addr1
, dev
->dev_addr
)) {
252 /* FromDS frame with own addr as DA */
256 if (skb
->len
< 24 + 8)
259 /* check for port access entity Ethernet type */
260 pos
= skb
->data
+ 24;
261 ethertype
= (pos
[6] << 8) | pos
[7];
262 if (ethertype
== ETH_P_PAE
)
268 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
270 ieee80211_rx_frame_decrypt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
271 struct ieee80211_crypt_data
*crypt
)
273 struct ieee80211_hdr_3addr
*hdr
;
276 if (crypt
== NULL
|| crypt
->ops
->decrypt_mpdu
== NULL
)
279 hdr
= (struct ieee80211_hdr_3addr
*)skb
->data
;
280 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
282 atomic_inc(&crypt
->refcnt
);
283 res
= crypt
->ops
->decrypt_mpdu(skb
, hdrlen
, crypt
->priv
);
284 atomic_dec(&crypt
->refcnt
);
286 IEEE80211_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
289 IEEE80211_DEBUG_DROP("Decryption failed ICV "
290 "mismatch (key %d)\n",
291 skb
->data
[hdrlen
+ 3] >> 6);
292 ieee
->ieee_stats
.rx_discards_undecryptable
++;
299 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
301 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device
*ieee
,
302 struct sk_buff
*skb
, int keyidx
,
303 struct ieee80211_crypt_data
*crypt
)
305 struct ieee80211_hdr_3addr
*hdr
;
308 if (crypt
== NULL
|| crypt
->ops
->decrypt_msdu
== NULL
)
311 hdr
= (struct ieee80211_hdr_3addr
*)skb
->data
;
312 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
314 atomic_inc(&crypt
->refcnt
);
315 res
= crypt
->ops
->decrypt_msdu(skb
, keyidx
, hdrlen
, crypt
->priv
);
316 atomic_dec(&crypt
->refcnt
);
318 printk(KERN_DEBUG
"%s: MSDU decryption/MIC verification failed"
319 " (SA=%pM keyidx=%d)\n", ieee
->dev
->name
, hdr
->addr2
,
327 /* All received frames are sent to this function. @skb contains the frame in
328 * IEEE 802.11 format, i.e., in the format it was sent over air.
329 * This function is called only as a tasklet (software IRQ). */
330 int ieee80211_rx(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
331 struct ieee80211_rx_stats
*rx_stats
)
333 struct net_device
*dev
= ieee
->dev
;
334 struct ieee80211_hdr_4addr
*hdr
;
336 u16 fc
, type
, stype
, sc
;
337 struct net_device_stats
*stats
;
342 struct net_device
*wds
= NULL
;
343 struct sk_buff
*skb2
= NULL
;
344 struct net_device
*wds
= NULL
;
345 int frame_authorized
= 0;
346 int from_assoc_ap
= 0;
351 struct ieee80211_crypt_data
*crypt
= NULL
;
353 int can_be_decrypted
= 0;
355 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
356 stats
= &ieee
->stats
;
359 printk(KERN_INFO
"%s: SKB length < 10\n", dev
->name
);
363 fc
= le16_to_cpu(hdr
->frame_ctl
);
364 type
= WLAN_FC_GET_TYPE(fc
);
365 stype
= WLAN_FC_GET_STYPE(fc
);
366 sc
= le16_to_cpu(hdr
->seq_ctl
);
367 frag
= WLAN_GET_SEQ_FRAG(sc
);
368 hdrlen
= ieee80211_get_hdrlen(fc
);
370 if (skb
->len
< hdrlen
) {
371 printk(KERN_INFO
"%s: invalid SKB length %d\n",
372 dev
->name
, skb
->len
);
376 /* Put this code here so that we avoid duplicating it in all
377 * Rx paths. - Jean II */
378 #ifdef CONFIG_WIRELESS_EXT
379 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
380 /* If spy monitoring on */
381 if (ieee
->spy_data
.spy_number
> 0) {
382 struct iw_quality wstats
;
385 if (rx_stats
->mask
& IEEE80211_STATMASK_RSSI
) {
386 wstats
.level
= rx_stats
->signal
;
387 wstats
.updated
|= IW_QUAL_LEVEL_UPDATED
;
389 wstats
.updated
|= IW_QUAL_LEVEL_INVALID
;
391 if (rx_stats
->mask
& IEEE80211_STATMASK_NOISE
) {
392 wstats
.noise
= rx_stats
->noise
;
393 wstats
.updated
|= IW_QUAL_NOISE_UPDATED
;
395 wstats
.updated
|= IW_QUAL_NOISE_INVALID
;
397 if (rx_stats
->mask
& IEEE80211_STATMASK_SIGNAL
) {
398 wstats
.qual
= rx_stats
->signal
;
399 wstats
.updated
|= IW_QUAL_QUAL_UPDATED
;
401 wstats
.updated
|= IW_QUAL_QUAL_INVALID
;
403 /* Update spy records */
404 wireless_spy_update(ieee
->dev
, hdr
->addr2
, &wstats
);
406 #endif /* IW_WIRELESS_SPY */
407 #endif /* CONFIG_WIRELESS_EXT */
410 hostap_update_rx_stats(local
->ap
, hdr
, rx_stats
);
413 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
415 stats
->rx_bytes
+= skb
->len
;
416 ieee80211_monitor_rx(ieee
, skb
, rx_stats
);
420 can_be_decrypted
= (is_multicast_ether_addr(hdr
->addr1
) ||
421 is_broadcast_ether_addr(hdr
->addr2
)) ?
422 ieee
->host_mc_decrypt
: ieee
->host_decrypt
;
424 if (can_be_decrypted
) {
425 if (skb
->len
>= hdrlen
+ 3) {
426 /* Top two-bits of byte 3 are the key index */
427 keyidx
= skb
->data
[hdrlen
+ 3] >> 6;
430 /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
431 * is only allowed 2-bits of storage, no value of keyidx can
432 * be provided via above code that would result in keyidx
433 * being out of range */
434 crypt
= ieee
->crypt
[keyidx
];
439 /* Use station specific key to override default keys if the
440 * receiver address is a unicast address ("individual RA"). If
441 * bcrx_sta_key parameter is set, station specific key is used
442 * even with broad/multicast targets (this is against IEEE
443 * 802.11, but makes it easier to use different keys with
444 * stations that do not support WEP key mapping). */
446 if (!(hdr
->addr1
[0] & 0x01) || local
->bcrx_sta_key
)
447 (void)hostap_handle_sta_crypto(local
, hdr
, &crypt
,
451 /* allow NULL decrypt to indicate an station specific override
452 * for default encryption */
453 if (crypt
&& (crypt
->ops
== NULL
||
454 crypt
->ops
->decrypt_mpdu
== NULL
))
457 if (!crypt
&& (fc
& IEEE80211_FCTL_PROTECTED
)) {
458 /* This seems to be triggered by some (multicast?)
459 * frames from other than current BSS, so just drop the
460 * frames silently instead of filling system log with
462 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
463 " (SA=%pM)\n", hdr
->addr2
);
464 ieee
->ieee_stats
.rx_discards_undecryptable
++;
469 if (type
!= WLAN_FC_TYPE_DATA
) {
470 if (type
== WLAN_FC_TYPE_MGMT
&& stype
== WLAN_FC_STYPE_AUTH
&&
471 fc
& IEEE80211_FCTL_PROTECTED
&& ieee
->host_decrypt
&&
472 (keyidx
= hostap_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0) {
473 printk(KERN_DEBUG
"%s: failed to decrypt mgmt::auth "
474 "from %pM\n", dev
->name
, hdr
->addr2
);
475 /* TODO: could inform hostapd about this so that it
476 * could send auth failure report */
480 if (ieee80211_rx_frame_mgmt(ieee
, skb
, rx_stats
, type
, stype
))
486 /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
487 if (sc
== ieee
->prev_seq_ctl
)
490 ieee
->prev_seq_ctl
= sc
;
492 /* Data frame - extract src/dst addresses */
493 if (skb
->len
< IEEE80211_3ADDR_LEN
)
496 switch (fc
& (IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
)) {
497 case IEEE80211_FCTL_FROMDS
:
498 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
499 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
501 case IEEE80211_FCTL_TODS
:
502 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
503 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
505 case IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
:
506 if (skb
->len
< IEEE80211_4ADDR_LEN
)
508 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
509 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
512 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
513 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
518 if (hostap_rx_frame_wds(ieee
, hdr
, fc
, &wds
))
521 skb
->dev
= dev
= wds
;
522 stats
= hostap_get_stats(dev
);
525 if (ieee
->iw_mode
== IW_MODE_MASTER
&& !wds
&&
526 (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
527 IEEE80211_FCTL_FROMDS
&& ieee
->stadev
528 && !compare_ether_addr(hdr
->addr2
, ieee
->assoc_ap_addr
)) {
529 /* Frame from BSSID of the AP for which we are a client */
530 skb
->dev
= dev
= ieee
->stadev
;
531 stats
= hostap_get_stats(dev
);
537 if ((ieee
->iw_mode
== IW_MODE_MASTER
||
538 ieee
->iw_mode
== IW_MODE_REPEAT
) && !from_assoc_ap
) {
539 switch (hostap_handle_sta_rx(ieee
, dev
, skb
, rx_stats
,
541 case AP_RX_CONTINUE_NOT_AUTHORIZED
:
542 frame_authorized
= 0;
545 frame_authorized
= 1;
555 /* Nullfunc frames may have PS-bit set, so they must be passed to
556 * hostap_handle_sta_rx() before being dropped here. */
558 stype
&= ~IEEE80211_STYPE_QOS_DATA
;
560 if (stype
!= IEEE80211_STYPE_DATA
&&
561 stype
!= IEEE80211_STYPE_DATA_CFACK
&&
562 stype
!= IEEE80211_STYPE_DATA_CFPOLL
&&
563 stype
!= IEEE80211_STYPE_DATA_CFACKPOLL
) {
564 if (stype
!= IEEE80211_STYPE_NULLFUNC
)
565 IEEE80211_DEBUG_DROP("RX: dropped data frame "
566 "with no data (type=0x%02x, "
567 "subtype=0x%02x, len=%d)\n",
568 type
, stype
, skb
->len
);
572 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
574 if ((fc
& IEEE80211_FCTL_PROTECTED
) && can_be_decrypted
&&
575 (keyidx
= ieee80211_rx_frame_decrypt(ieee
, skb
, crypt
)) < 0)
578 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
580 /* skb: hdr + (possibly fragmented) plaintext payload */
581 // PR: FIXME: hostap has additional conditions in the "if" below:
582 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
583 if ((frag
!= 0) || (fc
& IEEE80211_FCTL_MOREFRAGS
)) {
585 struct sk_buff
*frag_skb
= ieee80211_frag_cache_get(ieee
, hdr
);
586 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag
);
589 IEEE80211_DEBUG(IEEE80211_DL_RX
| IEEE80211_DL_FRAG
,
590 "Rx cannot get skb from fragment "
591 "cache (morefrag=%d seq=%u frag=%u)\n",
592 (fc
& IEEE80211_FCTL_MOREFRAGS
) != 0,
593 WLAN_GET_SEQ_SEQ(sc
), frag
);
601 if (frag_skb
->tail
+ flen
> frag_skb
->end
) {
602 printk(KERN_WARNING
"%s: host decrypted and "
603 "reassembled frame did not fit skb\n",
605 ieee80211_frag_cache_invalidate(ieee
, hdr
);
610 /* copy first fragment (including full headers) into
611 * beginning of the fragment cache skb */
612 skb_copy_from_linear_data(skb
, skb_put(frag_skb
, flen
), flen
);
614 /* append frame payload to the end of the fragment
616 skb_copy_from_linear_data_offset(skb
, hdrlen
,
617 skb_put(frag_skb
, flen
), flen
);
619 dev_kfree_skb_any(skb
);
622 if (fc
& IEEE80211_FCTL_MOREFRAGS
) {
623 /* more fragments expected - leave the skb in fragment
624 * cache for now; it will be delivered to upper layers
625 * after all fragments have been received */
629 /* this was the last fragment and the frame will be
630 * delivered, so remove skb from fragment cache */
632 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
633 ieee80211_frag_cache_invalidate(ieee
, hdr
);
636 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
637 * encrypted/authenticated */
638 if ((fc
& IEEE80211_FCTL_PROTECTED
) && can_be_decrypted
&&
639 ieee80211_rx_frame_decrypt_msdu(ieee
, skb
, keyidx
, crypt
))
642 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
643 if (crypt
&& !(fc
& IEEE80211_FCTL_PROTECTED
) && !ieee
->open_wep
) {
644 if ( /*ieee->ieee802_1x && */
645 ieee80211_is_eapol_frame(ieee
, skb
)) {
646 /* pass unencrypted EAPOL frames even if encryption is
649 IEEE80211_DEBUG_DROP("encryption configured, but RX "
650 "frame not encrypted (SA=%pM)\n",
656 if (crypt
&& !(fc
& IEEE80211_FCTL_PROTECTED
) && !ieee
->open_wep
&&
657 !ieee80211_is_eapol_frame(ieee
, skb
)) {
658 IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
659 "frame from %pM (drop_unencrypted=1)\n",
664 /* If the frame was decrypted in hardware, we may need to strip off
665 * any security data (IV, ICV, etc) that was left behind */
666 if (!can_be_decrypted
&& (fc
& IEEE80211_FCTL_PROTECTED
) &&
667 ieee
->host_strip_iv_icv
) {
670 /* Top two-bits of byte 3 are the key index */
671 if (skb
->len
>= hdrlen
+ 3)
672 keyidx
= skb
->data
[hdrlen
+ 3] >> 6;
674 /* To strip off any security data which appears before the
675 * payload, we simply increase hdrlen (as the header gets
676 * chopped off immediately below). For the security data which
677 * appears after the payload, we use skb_trim. */
679 switch (ieee
->sec
.encode_alg
[keyidx
]) {
687 /* 4 byte IV, 4 byte ExtIV */
689 /* 8 byte MIC, 4 byte ICV */
693 /* 8 byte CCMP header */
700 if (skb
->len
< trimlen
)
703 __skb_trim(skb
, skb
->len
- trimlen
);
705 if (skb
->len
< hdrlen
)
709 /* skb: hdr + (possible reassembled) full plaintext payload */
711 payload
= skb
->data
+ hdrlen
;
712 ethertype
= (payload
[6] << 8) | payload
[7];
715 /* If IEEE 802.1X is used, check whether the port is authorized to send
716 * the received frame. */
717 if (ieee
->ieee802_1x
&& ieee
->iw_mode
== IW_MODE_MASTER
) {
718 if (ethertype
== ETH_P_PAE
) {
719 printk(KERN_DEBUG
"%s: RX: IEEE 802.1X frame\n",
721 if (ieee
->hostapd
&& ieee
->apdev
) {
722 /* Send IEEE 802.1X frames to the user
723 * space daemon for processing */
724 prism2_rx_80211(ieee
->apdev
, skb
, rx_stats
,
726 ieee
->apdevstats
.rx_packets
++;
727 ieee
->apdevstats
.rx_bytes
+= skb
->len
;
730 } else if (!frame_authorized
) {
731 printk(KERN_DEBUG
"%s: dropped frame from "
732 "unauthorized port (IEEE 802.1X): "
733 "ethertype=0x%04x\n", dev
->name
, ethertype
);
739 /* convert hdr + possible LLC headers into Ethernet header */
740 if (skb
->len
- hdrlen
>= 8 &&
741 ((memcmp(payload
, rfc1042_header
, SNAP_SIZE
) == 0 &&
742 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
743 memcmp(payload
, bridge_tunnel_header
, SNAP_SIZE
) == 0)) {
744 /* remove RFC1042 or Bridge-Tunnel encapsulation and
745 * replace EtherType */
746 skb_pull(skb
, hdrlen
+ SNAP_SIZE
);
747 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
748 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
751 /* Leave Ethernet header part of hdr and full payload */
752 skb_pull(skb
, hdrlen
);
753 len
= htons(skb
->len
);
754 memcpy(skb_push(skb
, 2), &len
, 2);
755 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
756 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
760 if (wds
&& ((fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) ==
761 IEEE80211_FCTL_TODS
) && skb
->len
>= ETH_HLEN
+ ETH_ALEN
) {
762 /* Non-standard frame: get addr4 from its bogus location after
764 skb_copy_to_linear_data_offset(skb
, ETH_ALEN
,
765 skb
->data
+ skb
->len
- ETH_ALEN
,
767 skb_trim(skb
, skb
->len
- ETH_ALEN
);
772 stats
->rx_bytes
+= skb
->len
;
775 if (ieee
->iw_mode
== IW_MODE_MASTER
&& !wds
&& ieee
->ap
->bridge_packets
) {
777 /* copy multicast frame both to the higher layers and
778 * to the wireless media */
779 ieee
->ap
->bridged_multicast
++;
780 skb2
= skb_clone(skb
, GFP_ATOMIC
);
782 printk(KERN_DEBUG
"%s: skb_clone failed for "
783 "multicast frame\n", dev
->name
);
784 } else if (hostap_is_sta_assoc(ieee
->ap
, dst
)) {
785 /* send frame directly to the associated STA using
786 * wireless media and not passing to higher layers */
787 ieee
->ap
->bridged_unicast
++;
794 /* send to wireless media */
796 skb2
->protocol
= htons(ETH_P_802_3
);
797 skb_reset_mac_header(skb2
);
798 skb_reset_network_header(skb2
);
799 /* skb2->network_header += ETH_HLEN; */
800 dev_queue_xmit(skb2
);
805 skb
->protocol
= eth_type_trans(skb
, dev
);
806 memset(skb
->cb
, 0, sizeof(skb
->cb
));
807 skb
->ip_summed
= CHECKSUM_NONE
; /* 802.11 crc not sufficient */
808 if (netif_rx(skb
) == NET_RX_DROP
) {
809 /* netif_rx always succeeds, but it might drop
810 * the packet. If it drops the packet, we log that
813 ("RX: netif_rx dropped the packet\n");
821 hostap_handle_sta_release(sta
);
828 /* Returning 0 indicates to caller that we have not handled the SKB--
829 * so it is still allocated and can be used again by underlying
830 * hardware as a DMA target */
834 /* Filter out unrelated packets, call ieee80211_rx[_mgt]
835 * This function takes over the skb, it should not be used again after calling
837 void ieee80211_rx_any(struct ieee80211_device
*ieee
,
838 struct sk_buff
*skb
, struct ieee80211_rx_stats
*stats
)
840 struct ieee80211_hdr_4addr
*hdr
;
841 int is_packet_for_us
;
844 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
845 if (!ieee80211_rx(ieee
, skb
, stats
))
846 dev_kfree_skb_irq(skb
);
850 if (skb
->len
< sizeof(struct ieee80211_hdr
))
853 hdr
= (struct ieee80211_hdr_4addr
*)skb
->data
;
854 fc
= le16_to_cpu(hdr
->frame_ctl
);
856 if ((fc
& IEEE80211_FCTL_VERS
) != 0)
859 switch (fc
& IEEE80211_FCTL_FTYPE
) {
860 case IEEE80211_FTYPE_MGMT
:
861 if (skb
->len
< sizeof(struct ieee80211_hdr_3addr
))
863 ieee80211_rx_mgt(ieee
, hdr
, stats
);
864 dev_kfree_skb_irq(skb
);
866 case IEEE80211_FTYPE_DATA
:
868 case IEEE80211_FTYPE_CTL
:
874 is_packet_for_us
= 0;
875 switch (ieee
->iw_mode
) {
877 /* our BSS and not from/to DS */
878 if (memcmp(hdr
->addr3
, ieee
->bssid
, ETH_ALEN
) == 0)
879 if ((fc
& (IEEE80211_FCTL_TODS
+IEEE80211_FCTL_FROMDS
)) == 0) {
880 /* promisc: get all */
881 if (ieee
->dev
->flags
& IFF_PROMISC
)
882 is_packet_for_us
= 1;
884 else if (memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
) == 0)
885 is_packet_for_us
= 1;
887 else if (is_multicast_ether_addr(hdr
->addr1
))
888 is_packet_for_us
= 1;
892 /* our BSS (== from our AP) and from DS */
893 if (memcmp(hdr
->addr2
, ieee
->bssid
, ETH_ALEN
) == 0)
894 if ((fc
& (IEEE80211_FCTL_TODS
+IEEE80211_FCTL_FROMDS
)) == IEEE80211_FCTL_FROMDS
) {
895 /* promisc: get all */
896 if (ieee
->dev
->flags
& IFF_PROMISC
)
897 is_packet_for_us
= 1;
899 else if (memcmp(hdr
->addr1
, ieee
->dev
->dev_addr
, ETH_ALEN
) == 0)
900 is_packet_for_us
= 1;
902 else if (is_multicast_ether_addr(hdr
->addr1
)) {
903 /* not our own packet bcasted from AP */
904 if (memcmp(hdr
->addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
))
905 is_packet_for_us
= 1;
914 if (is_packet_for_us
)
915 if (!ieee80211_rx(ieee
, skb
, stats
))
916 dev_kfree_skb_irq(skb
);
920 dev_kfree_skb_irq(skb
);
921 ieee
->stats
.rx_dropped
++;
925 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
927 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
930 * Make ther structure we read from the beacon packet has
933 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
934 *info_element
, int sub_type
)
937 if (info_element
->qui_subtype
!= sub_type
)
939 if (memcmp(info_element
->qui
, qos_oui
, QOS_OUI_LEN
))
941 if (info_element
->qui_type
!= QOS_OUI_TYPE
)
943 if (info_element
->version
!= QOS_VERSION_1
)
950 * Parse a QoS parameter element
952 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
953 *element_param
, struct ieee80211_info_element
957 u16 size
= sizeof(struct ieee80211_qos_parameter_info
) - 2;
959 if ((info_element
== NULL
) || (element_param
== NULL
))
962 if (info_element
->id
== QOS_ELEMENT_ID
&& info_element
->len
== size
) {
963 memcpy(element_param
->info_element
.qui
, info_element
->data
,
965 element_param
->info_element
.elementID
= info_element
->id
;
966 element_param
->info_element
.length
= info_element
->len
;
970 ret
= ieee80211_verify_qos_info(&element_param
->info_element
,
971 QOS_OUI_PARAM_SUB_TYPE
);
976 * Parse a QoS information element
978 static int ieee80211_read_qos_info_element(struct
979 ieee80211_qos_information_element
980 *element_info
, struct ieee80211_info_element
984 u16 size
= sizeof(struct ieee80211_qos_information_element
) - 2;
986 if (element_info
== NULL
)
988 if (info_element
== NULL
)
991 if ((info_element
->id
== QOS_ELEMENT_ID
) && (info_element
->len
== size
)) {
992 memcpy(element_info
->qui
, info_element
->data
,
994 element_info
->elementID
= info_element
->id
;
995 element_info
->length
= info_element
->len
;
1000 ret
= ieee80211_verify_qos_info(element_info
,
1001 QOS_OUI_INFO_SUB_TYPE
);
1006 * Write QoS parameters from the ac parameters.
1008 static int ieee80211_qos_convert_ac_to_parameters(struct
1009 ieee80211_qos_parameter_info
1011 ieee80211_qos_parameters
1016 struct ieee80211_qos_ac_parameter
*ac_params
;
1021 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++) {
1022 ac_params
= &(param_elm
->ac_params_record
[i
]);
1024 qos_param
->aifs
[i
] = (ac_params
->aci_aifsn
) & 0x0F;
1025 qos_param
->aifs
[i
] -= (qos_param
->aifs
[i
] < 2) ? 0 : 2;
1027 cw_min
= ac_params
->ecw_min_max
& 0x0F;
1028 qos_param
->cw_min
[i
] = cpu_to_le16((1 << cw_min
) - 1);
1030 cw_max
= (ac_params
->ecw_min_max
& 0xF0) >> 4;
1031 qos_param
->cw_max
[i
] = cpu_to_le16((1 << cw_max
) - 1);
1033 qos_param
->flag
[i
] =
1034 (ac_params
->aci_aifsn
& 0x10) ? 0x01 : 0x00;
1036 txop
= le16_to_cpu(ac_params
->tx_op_limit
) * 32;
1037 qos_param
->tx_op_limit
[i
] = cpu_to_le16(txop
);
1043 * we have a generic data element which it may contain QoS information or
1044 * parameters element. check the information element length to decide
1045 * which type to read
1047 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1049 struct ieee80211_network
*network
)
1052 struct ieee80211_qos_parameters
*qos_param
= NULL
;
1053 struct ieee80211_qos_information_element qos_info_element
;
1055 rc
= ieee80211_read_qos_info_element(&qos_info_element
, info_element
);
1058 network
->qos_data
.param_count
= qos_info_element
.ac_info
& 0x0F;
1059 network
->flags
|= NETWORK_HAS_QOS_INFORMATION
;
1061 struct ieee80211_qos_parameter_info param_element
;
1063 rc
= ieee80211_read_qos_param_element(¶m_element
,
1066 qos_param
= &(network
->qos_data
.parameters
);
1067 ieee80211_qos_convert_ac_to_parameters(¶m_element
,
1069 network
->flags
|= NETWORK_HAS_QOS_PARAMETERS
;
1070 network
->qos_data
.param_count
=
1071 param_element
.info_element
.ac_info
& 0x0F;
1076 IEEE80211_DEBUG_QOS("QoS is supported\n");
1077 network
->qos_data
.supported
= 1;
1082 #ifdef CONFIG_IEEE80211_DEBUG
1083 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1085 static const char *get_info_element_string(u16 id
)
1090 MFIE_STRING(FH_SET
);
1091 MFIE_STRING(DS_SET
);
1092 MFIE_STRING(CF_SET
);
1094 MFIE_STRING(IBSS_SET
);
1095 MFIE_STRING(COUNTRY
);
1096 MFIE_STRING(HOP_PARAMS
);
1097 MFIE_STRING(HOP_TABLE
);
1098 MFIE_STRING(REQUEST
);
1099 MFIE_STRING(CHALLENGE
);
1100 MFIE_STRING(POWER_CONSTRAINT
);
1101 MFIE_STRING(POWER_CAPABILITY
);
1102 MFIE_STRING(TPC_REQUEST
);
1103 MFIE_STRING(TPC_REPORT
);
1104 MFIE_STRING(SUPP_CHANNELS
);
1106 MFIE_STRING(MEASURE_REQUEST
);
1107 MFIE_STRING(MEASURE_REPORT
);
1109 MFIE_STRING(IBSS_DFS
);
1110 MFIE_STRING(ERP_INFO
);
1112 MFIE_STRING(RATES_EX
);
1113 MFIE_STRING(GENERIC
);
1114 MFIE_STRING(QOS_PARAMETER
);
1121 static int ieee80211_parse_info_param(struct ieee80211_info_element
1122 *info_element
, u16 length
,
1123 struct ieee80211_network
*network
)
1125 DECLARE_SSID_BUF(ssid
);
1127 #ifdef CONFIG_IEEE80211_DEBUG
1132 while (length
>= sizeof(*info_element
)) {
1133 if (sizeof(*info_element
) + info_element
->len
> length
) {
1134 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1135 "info_element->len + 2 > left : "
1136 "info_element->len+2=%zd left=%d, id=%d.\n",
1138 sizeof(*info_element
),
1139 length
, info_element
->id
);
1140 /* We stop processing but don't return an error here
1141 * because some misbehaviour APs break this rule. ie.
1142 * Orinoco AP1000. */
1146 switch (info_element
->id
) {
1147 case MFIE_TYPE_SSID
:
1148 network
->ssid_len
= min(info_element
->len
,
1149 (u8
) IW_ESSID_MAX_SIZE
);
1150 memcpy(network
->ssid
, info_element
->data
,
1152 if (network
->ssid_len
< IW_ESSID_MAX_SIZE
)
1153 memset(network
->ssid
+ network
->ssid_len
, 0,
1154 IW_ESSID_MAX_SIZE
- network
->ssid_len
);
1156 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1157 print_ssid(ssid
, network
->ssid
,
1162 case MFIE_TYPE_RATES
:
1163 #ifdef CONFIG_IEEE80211_DEBUG
1166 network
->rates_len
= min(info_element
->len
,
1168 for (i
= 0; i
< network
->rates_len
; i
++) {
1169 network
->rates
[i
] = info_element
->data
[i
];
1170 #ifdef CONFIG_IEEE80211_DEBUG
1171 p
+= snprintf(p
, sizeof(rates_str
) -
1172 (p
- rates_str
), "%02X ",
1175 if (ieee80211_is_ofdm_rate
1176 (info_element
->data
[i
])) {
1177 network
->flags
|= NETWORK_HAS_OFDM
;
1178 if (info_element
->data
[i
] &
1179 IEEE80211_BASIC_RATE_MASK
)
1185 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1186 rates_str
, network
->rates_len
);
1189 case MFIE_TYPE_RATES_EX
:
1190 #ifdef CONFIG_IEEE80211_DEBUG
1193 network
->rates_ex_len
= min(info_element
->len
,
1194 MAX_RATES_EX_LENGTH
);
1195 for (i
= 0; i
< network
->rates_ex_len
; i
++) {
1196 network
->rates_ex
[i
] = info_element
->data
[i
];
1197 #ifdef CONFIG_IEEE80211_DEBUG
1198 p
+= snprintf(p
, sizeof(rates_str
) -
1199 (p
- rates_str
), "%02X ",
1202 if (ieee80211_is_ofdm_rate
1203 (info_element
->data
[i
])) {
1204 network
->flags
|= NETWORK_HAS_OFDM
;
1205 if (info_element
->data
[i
] &
1206 IEEE80211_BASIC_RATE_MASK
)
1212 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1213 rates_str
, network
->rates_ex_len
);
1216 case MFIE_TYPE_DS_SET
:
1217 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1218 info_element
->data
[0]);
1219 network
->channel
= info_element
->data
[0];
1222 case MFIE_TYPE_FH_SET
:
1223 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1226 case MFIE_TYPE_CF_SET
:
1227 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1231 network
->tim
.tim_count
= info_element
->data
[0];
1232 network
->tim
.tim_period
= info_element
->data
[1];
1233 IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1236 case MFIE_TYPE_ERP_INFO
:
1237 network
->erp_value
= info_element
->data
[0];
1238 network
->flags
|= NETWORK_HAS_ERP_VALUE
;
1239 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1240 network
->erp_value
);
1243 case MFIE_TYPE_IBSS_SET
:
1244 network
->atim_window
= info_element
->data
[0];
1245 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1246 network
->atim_window
);
1249 case MFIE_TYPE_CHALLENGE
:
1250 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1253 case MFIE_TYPE_GENERIC
:
1254 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1256 if (!ieee80211_parse_qos_info_param_IE(info_element
,
1260 if (info_element
->len
>= 4 &&
1261 info_element
->data
[0] == 0x00 &&
1262 info_element
->data
[1] == 0x50 &&
1263 info_element
->data
[2] == 0xf2 &&
1264 info_element
->data
[3] == 0x01) {
1265 network
->wpa_ie_len
= min(info_element
->len
+ 2,
1267 memcpy(network
->wpa_ie
, info_element
,
1268 network
->wpa_ie_len
);
1273 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1275 network
->rsn_ie_len
= min(info_element
->len
+ 2,
1277 memcpy(network
->rsn_ie
, info_element
,
1278 network
->rsn_ie_len
);
1281 case MFIE_TYPE_QOS_PARAMETER
:
1283 "QoS Error need to parse QOS_PARAMETER IE\n");
1286 case MFIE_TYPE_POWER_CONSTRAINT
:
1287 network
->power_constraint
= info_element
->data
[0];
1288 network
->flags
|= NETWORK_HAS_POWER_CONSTRAINT
;
1292 network
->power_constraint
= info_element
->data
[0];
1293 network
->flags
|= NETWORK_HAS_CSA
;
1296 case MFIE_TYPE_QUIET
:
1297 network
->quiet
.count
= info_element
->data
[0];
1298 network
->quiet
.period
= info_element
->data
[1];
1299 network
->quiet
.duration
= info_element
->data
[2];
1300 network
->quiet
.offset
= info_element
->data
[3];
1301 network
->flags
|= NETWORK_HAS_QUIET
;
1304 case MFIE_TYPE_IBSS_DFS
:
1305 if (network
->ibss_dfs
)
1307 network
->ibss_dfs
= kmemdup(info_element
->data
,
1310 if (!network
->ibss_dfs
)
1312 network
->flags
|= NETWORK_HAS_IBSS_DFS
;
1315 case MFIE_TYPE_TPC_REPORT
:
1316 network
->tpc_report
.transmit_power
=
1317 info_element
->data
[0];
1318 network
->tpc_report
.link_margin
= info_element
->data
[1];
1319 network
->flags
|= NETWORK_HAS_TPC_REPORT
;
1323 IEEE80211_DEBUG_MGMT
1324 ("Unsupported info element: %s (%d)\n",
1325 get_info_element_string(info_element
->id
),
1330 length
-= sizeof(*info_element
) + info_element
->len
;
1332 (struct ieee80211_info_element
*)&info_element
->
1333 data
[info_element
->len
];
1339 static int ieee80211_handle_assoc_resp(struct ieee80211_device
*ieee
, struct ieee80211_assoc_response
1340 *frame
, struct ieee80211_rx_stats
*stats
)
1342 struct ieee80211_network network_resp
= {
1345 struct ieee80211_network
*network
= &network_resp
;
1346 struct net_device
*dev
= ieee
->dev
;
1349 network
->qos_data
.active
= 0;
1350 network
->qos_data
.supported
= 0;
1351 network
->qos_data
.param_count
= 0;
1352 network
->qos_data
.old_param_count
= 0;
1354 //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1355 network
->atim_window
= le16_to_cpu(frame
->aid
);
1356 network
->listen_interval
= le16_to_cpu(frame
->status
);
1357 memcpy(network
->bssid
, frame
->header
.addr3
, ETH_ALEN
);
1358 network
->capability
= le16_to_cpu(frame
->capability
);
1359 network
->last_scanned
= jiffies
;
1360 network
->rates_len
= network
->rates_ex_len
= 0;
1361 network
->last_associate
= 0;
1362 network
->ssid_len
= 0;
1363 network
->erp_value
=
1364 (network
->capability
& WLAN_CAPABILITY_IBSS
) ? 0x3 : 0x0;
1366 if (stats
->freq
== IEEE80211_52GHZ_BAND
) {
1367 /* for A band (No DS info) */
1368 network
->channel
= stats
->received_channel
;
1370 network
->flags
|= NETWORK_HAS_CCK
;
1372 network
->wpa_ie_len
= 0;
1373 network
->rsn_ie_len
= 0;
1375 if (ieee80211_parse_info_param
1376 (frame
->info_element
, stats
->len
- sizeof(*frame
), network
))
1380 if (stats
->freq
== IEEE80211_52GHZ_BAND
)
1381 network
->mode
= IEEE_A
;
1383 if (network
->flags
& NETWORK_HAS_OFDM
)
1384 network
->mode
|= IEEE_G
;
1385 if (network
->flags
& NETWORK_HAS_CCK
)
1386 network
->mode
|= IEEE_B
;
1389 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
1391 if (ieee
->handle_assoc_response
!= NULL
)
1392 ieee
->handle_assoc_response(dev
, frame
, network
);
1397 /***************************************************/
1399 static int ieee80211_network_init(struct ieee80211_device
*ieee
, struct ieee80211_probe_response
1401 struct ieee80211_network
*network
,
1402 struct ieee80211_rx_stats
*stats
)
1404 DECLARE_SSID_BUF(ssid
);
1406 network
->qos_data
.active
= 0;
1407 network
->qos_data
.supported
= 0;
1408 network
->qos_data
.param_count
= 0;
1409 network
->qos_data
.old_param_count
= 0;
1411 /* Pull out fixed field data */
1412 memcpy(network
->bssid
, beacon
->header
.addr3
, ETH_ALEN
);
1413 network
->capability
= le16_to_cpu(beacon
->capability
);
1414 network
->last_scanned
= jiffies
;
1415 network
->time_stamp
[0] = le32_to_cpu(beacon
->time_stamp
[0]);
1416 network
->time_stamp
[1] = le32_to_cpu(beacon
->time_stamp
[1]);
1417 network
->beacon_interval
= le16_to_cpu(beacon
->beacon_interval
);
1418 /* Where to pull this? beacon->listen_interval; */
1419 network
->listen_interval
= 0x0A;
1420 network
->rates_len
= network
->rates_ex_len
= 0;
1421 network
->last_associate
= 0;
1422 network
->ssid_len
= 0;
1424 network
->atim_window
= 0;
1425 network
->erp_value
= (network
->capability
& WLAN_CAPABILITY_IBSS
) ?
1428 if (stats
->freq
== IEEE80211_52GHZ_BAND
) {
1429 /* for A band (No DS info) */
1430 network
->channel
= stats
->received_channel
;
1432 network
->flags
|= NETWORK_HAS_CCK
;
1434 network
->wpa_ie_len
= 0;
1435 network
->rsn_ie_len
= 0;
1437 if (ieee80211_parse_info_param
1438 (beacon
->info_element
, stats
->len
- sizeof(*beacon
), network
))
1442 if (stats
->freq
== IEEE80211_52GHZ_BAND
)
1443 network
->mode
= IEEE_A
;
1445 if (network
->flags
& NETWORK_HAS_OFDM
)
1446 network
->mode
|= IEEE_G
;
1447 if (network
->flags
& NETWORK_HAS_CCK
)
1448 network
->mode
|= IEEE_B
;
1451 if (network
->mode
== 0) {
1452 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
1454 print_ssid(ssid
, network
->ssid
,
1460 memcpy(&network
->stats
, stats
, sizeof(network
->stats
));
1465 static inline int is_same_network(struct ieee80211_network
*src
,
1466 struct ieee80211_network
*dst
)
1468 /* A network is only a duplicate if the channel, BSSID, and ESSID
1469 * all match. We treat all <hidden> with the same BSSID and channel
1471 return ((src
->ssid_len
== dst
->ssid_len
) &&
1472 (src
->channel
== dst
->channel
) &&
1473 !compare_ether_addr(src
->bssid
, dst
->bssid
) &&
1474 !memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
));
1477 static void update_network(struct ieee80211_network
*dst
,
1478 struct ieee80211_network
*src
)
1483 ieee80211_network_reset(dst
);
1484 dst
->ibss_dfs
= src
->ibss_dfs
;
1486 /* We only update the statistics if they were created by receiving
1487 * the network information on the actual channel the network is on.
1489 * This keeps beacons received on neighbor channels from bringing
1490 * down the signal level of an AP. */
1491 if (dst
->channel
== src
->stats
.received_channel
)
1492 memcpy(&dst
->stats
, &src
->stats
,
1493 sizeof(struct ieee80211_rx_stats
));
1495 IEEE80211_DEBUG_SCAN("Network %pM info received "
1496 "off channel (%d vs. %d)\n", src
->bssid
,
1497 dst
->channel
, src
->stats
.received_channel
);
1499 dst
->capability
= src
->capability
;
1500 memcpy(dst
->rates
, src
->rates
, src
->rates_len
);
1501 dst
->rates_len
= src
->rates_len
;
1502 memcpy(dst
->rates_ex
, src
->rates_ex
, src
->rates_ex_len
);
1503 dst
->rates_ex_len
= src
->rates_ex_len
;
1505 dst
->mode
= src
->mode
;
1506 dst
->flags
= src
->flags
;
1507 dst
->time_stamp
[0] = src
->time_stamp
[0];
1508 dst
->time_stamp
[1] = src
->time_stamp
[1];
1510 dst
->beacon_interval
= src
->beacon_interval
;
1511 dst
->listen_interval
= src
->listen_interval
;
1512 dst
->atim_window
= src
->atim_window
;
1513 dst
->erp_value
= src
->erp_value
;
1514 dst
->tim
= src
->tim
;
1516 memcpy(dst
->wpa_ie
, src
->wpa_ie
, src
->wpa_ie_len
);
1517 dst
->wpa_ie_len
= src
->wpa_ie_len
;
1518 memcpy(dst
->rsn_ie
, src
->rsn_ie
, src
->rsn_ie_len
);
1519 dst
->rsn_ie_len
= src
->rsn_ie_len
;
1521 dst
->last_scanned
= jiffies
;
1522 qos_active
= src
->qos_data
.active
;
1523 old_param
= dst
->qos_data
.old_param_count
;
1524 if (dst
->flags
& NETWORK_HAS_QOS_MASK
)
1525 memcpy(&dst
->qos_data
, &src
->qos_data
,
1526 sizeof(struct ieee80211_qos_data
));
1528 dst
->qos_data
.supported
= src
->qos_data
.supported
;
1529 dst
->qos_data
.param_count
= src
->qos_data
.param_count
;
1532 if (dst
->qos_data
.supported
== 1) {
1535 ("QoS the network %s is QoS supported\n",
1539 ("QoS the network is QoS supported\n");
1541 dst
->qos_data
.active
= qos_active
;
1542 dst
->qos_data
.old_param_count
= old_param
;
1544 /* dst->last_associate is not overwritten */
1547 static inline int is_beacon(__le16 fc
)
1549 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc
)) == IEEE80211_STYPE_BEACON
);
1552 static void ieee80211_process_probe_response(struct ieee80211_device
1554 ieee80211_probe_response
1555 *beacon
, struct ieee80211_rx_stats
1558 struct net_device
*dev
= ieee
->dev
;
1559 struct ieee80211_network network
= {
1562 struct ieee80211_network
*target
;
1563 struct ieee80211_network
*oldest
= NULL
;
1564 #ifdef CONFIG_IEEE80211_DEBUG
1565 struct ieee80211_info_element
*info_element
= beacon
->info_element
;
1567 unsigned long flags
;
1568 DECLARE_SSID_BUF(ssid
);
1570 IEEE80211_DEBUG_SCAN("'%s' (%pM"
1571 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1572 print_ssid(ssid
, info_element
->data
, info_element
->len
),
1573 beacon
->header
.addr3
,
1574 (beacon
->capability
& cpu_to_le16(1 << 0xf)) ? '1' : '0',
1575 (beacon
->capability
& cpu_to_le16(1 << 0xe)) ? '1' : '0',
1576 (beacon
->capability
& cpu_to_le16(1 << 0xd)) ? '1' : '0',
1577 (beacon
->capability
& cpu_to_le16(1 << 0xc)) ? '1' : '0',
1578 (beacon
->capability
& cpu_to_le16(1 << 0xb)) ? '1' : '0',
1579 (beacon
->capability
& cpu_to_le16(1 << 0xa)) ? '1' : '0',
1580 (beacon
->capability
& cpu_to_le16(1 << 0x9)) ? '1' : '0',
1581 (beacon
->capability
& cpu_to_le16(1 << 0x8)) ? '1' : '0',
1582 (beacon
->capability
& cpu_to_le16(1 << 0x7)) ? '1' : '0',
1583 (beacon
->capability
& cpu_to_le16(1 << 0x6)) ? '1' : '0',
1584 (beacon
->capability
& cpu_to_le16(1 << 0x5)) ? '1' : '0',
1585 (beacon
->capability
& cpu_to_le16(1 << 0x4)) ? '1' : '0',
1586 (beacon
->capability
& cpu_to_le16(1 << 0x3)) ? '1' : '0',
1587 (beacon
->capability
& cpu_to_le16(1 << 0x2)) ? '1' : '0',
1588 (beacon
->capability
& cpu_to_le16(1 << 0x1)) ? '1' : '0',
1589 (beacon
->capability
& cpu_to_le16(1 << 0x0)) ? '1' : '0');
1591 if (ieee80211_network_init(ieee
, beacon
, &network
, stats
)) {
1592 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
1593 print_ssid(ssid
, info_element
->data
,
1595 beacon
->header
.addr3
,
1596 is_beacon(beacon
->header
.frame_ctl
) ?
1597 "BEACON" : "PROBE RESPONSE");
1601 /* The network parsed correctly -- so now we scan our known networks
1602 * to see if we can find it in our list.
1604 * NOTE: This search is definitely not optimized. Once its doing
1605 * the "right thing" we'll optimize it for efficiency if
1608 /* Search for this entry in the list and update it if it is
1611 spin_lock_irqsave(&ieee
->lock
, flags
);
1613 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1614 if (is_same_network(target
, &network
))
1617 if ((oldest
== NULL
) ||
1618 (target
->last_scanned
< oldest
->last_scanned
))
1622 /* If we didn't find a match, then get a new network slot to initialize
1623 * with this beacon's information */
1624 if (&target
->list
== &ieee
->network_list
) {
1625 if (list_empty(&ieee
->network_free_list
)) {
1626 /* If there are no more slots, expire the oldest */
1627 list_del(&oldest
->list
);
1629 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
1631 print_ssid(ssid
, target
->ssid
,
1634 ieee80211_network_reset(target
);
1636 /* Otherwise just pull from the free list */
1637 target
= list_entry(ieee
->network_free_list
.next
,
1638 struct ieee80211_network
, list
);
1639 list_del(ieee
->network_free_list
.next
);
1642 #ifdef CONFIG_IEEE80211_DEBUG
1643 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
1644 print_ssid(ssid
, network
.ssid
,
1647 is_beacon(beacon
->header
.frame_ctl
) ?
1648 "BEACON" : "PROBE RESPONSE");
1650 memcpy(target
, &network
, sizeof(*target
));
1651 network
.ibss_dfs
= NULL
;
1652 list_add_tail(&target
->list
, &ieee
->network_list
);
1654 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
1655 print_ssid(ssid
, target
->ssid
,
1658 is_beacon(beacon
->header
.frame_ctl
) ?
1659 "BEACON" : "PROBE RESPONSE");
1660 update_network(target
, &network
);
1661 network
.ibss_dfs
= NULL
;
1664 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1666 if (is_beacon(beacon
->header
.frame_ctl
)) {
1667 if (ieee
->handle_beacon
!= NULL
)
1668 ieee
->handle_beacon(dev
, beacon
, target
);
1670 if (ieee
->handle_probe_response
!= NULL
)
1671 ieee
->handle_probe_response(dev
, beacon
, target
);
1675 void ieee80211_rx_mgt(struct ieee80211_device
*ieee
,
1676 struct ieee80211_hdr_4addr
*header
,
1677 struct ieee80211_rx_stats
*stats
)
1679 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
))) {
1680 case IEEE80211_STYPE_ASSOC_RESP
:
1681 IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
1682 WLAN_FC_GET_STYPE(le16_to_cpu
1683 (header
->frame_ctl
)));
1684 ieee80211_handle_assoc_resp(ieee
,
1685 (struct ieee80211_assoc_response
*)
1689 case IEEE80211_STYPE_REASSOC_RESP
:
1690 IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
1691 WLAN_FC_GET_STYPE(le16_to_cpu
1692 (header
->frame_ctl
)));
1695 case IEEE80211_STYPE_PROBE_REQ
:
1696 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
1697 WLAN_FC_GET_STYPE(le16_to_cpu
1698 (header
->frame_ctl
)));
1700 if (ieee
->handle_probe_request
!= NULL
)
1701 ieee
->handle_probe_request(ieee
->dev
,
1703 ieee80211_probe_request
*)
1707 case IEEE80211_STYPE_PROBE_RESP
:
1708 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1709 WLAN_FC_GET_STYPE(le16_to_cpu
1710 (header
->frame_ctl
)));
1711 IEEE80211_DEBUG_SCAN("Probe response\n");
1712 ieee80211_process_probe_response(ieee
,
1714 ieee80211_probe_response
*)
1718 case IEEE80211_STYPE_BEACON
:
1719 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
1720 WLAN_FC_GET_STYPE(le16_to_cpu
1721 (header
->frame_ctl
)));
1722 IEEE80211_DEBUG_SCAN("Beacon\n");
1723 ieee80211_process_probe_response(ieee
,
1725 ieee80211_probe_response
*)
1728 case IEEE80211_STYPE_AUTH
:
1730 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
1731 WLAN_FC_GET_STYPE(le16_to_cpu
1732 (header
->frame_ctl
)));
1734 if (ieee
->handle_auth
!= NULL
)
1735 ieee
->handle_auth(ieee
->dev
,
1736 (struct ieee80211_auth
*)header
);
1739 case IEEE80211_STYPE_DISASSOC
:
1740 if (ieee
->handle_disassoc
!= NULL
)
1741 ieee
->handle_disassoc(ieee
->dev
,
1742 (struct ieee80211_disassoc
*)
1746 case IEEE80211_STYPE_ACTION
:
1747 IEEE80211_DEBUG_MGMT("ACTION\n");
1748 if (ieee
->handle_action
)
1749 ieee
->handle_action(ieee
->dev
,
1750 (struct ieee80211_action
*)
1754 case IEEE80211_STYPE_REASSOC_REQ
:
1755 IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
1756 WLAN_FC_GET_STYPE(le16_to_cpu
1757 (header
->frame_ctl
)));
1759 IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
1761 if (ieee
->handle_reassoc_request
!= NULL
)
1762 ieee
->handle_reassoc_request(ieee
->dev
,
1763 (struct ieee80211_reassoc_request
*)
1767 case IEEE80211_STYPE_ASSOC_REQ
:
1768 IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
1769 WLAN_FC_GET_STYPE(le16_to_cpu
1770 (header
->frame_ctl
)));
1772 IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
1774 if (ieee
->handle_assoc_request
!= NULL
)
1775 ieee
->handle_assoc_request(ieee
->dev
);
1778 case IEEE80211_STYPE_DEAUTH
:
1779 IEEE80211_DEBUG_MGMT("DEAUTH\n");
1780 if (ieee
->handle_deauth
!= NULL
)
1781 ieee
->handle_deauth(ieee
->dev
,
1782 (struct ieee80211_deauth
*)
1786 IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
1787 WLAN_FC_GET_STYPE(le16_to_cpu
1788 (header
->frame_ctl
)));
1789 IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1791 WLAN_FC_GET_STYPE(le16_to_cpu
1792 (header
->frame_ctl
)));
1797 EXPORT_SYMBOL_GPL(ieee80211_rx_any
);
1798 EXPORT_SYMBOL(ieee80211_rx_mgt
);
1799 EXPORT_SYMBOL(ieee80211_rx
);