2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/rcupdate.h>
17 #include <net/mac80211.h>
18 #include <net/ieee80211_radiotap.h>
20 #include "ieee80211_i.h"
21 #include "ieee80211_led.h"
28 * monitor mode reception
30 * This function cleans up the SKB, i.e. it removes all the stuff
31 * only useful for monitoring.
33 static struct sk_buff
*remove_monitor_info(struct ieee80211_local
*local
,
37 skb_pull(skb
, rtap_len
);
39 if (local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
) {
40 if (likely(skb
->len
> FCS_LEN
))
41 skb_trim(skb
, skb
->len
- FCS_LEN
);
53 static inline int should_drop_frame(struct ieee80211_rx_status
*status
,
58 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
60 if (status
->flag
& (RX_FLAG_FAILED_FCS_CRC
| RX_FLAG_FAILED_PLCP_CRC
))
62 if (unlikely(skb
->len
< 16 + present_fcs_len
+ radiotap_len
))
64 if ((hdr
->frame_control
& cpu_to_le16(IEEE80211_FCTL_FTYPE
)) ==
65 cpu_to_le16(IEEE80211_FTYPE_CTL
))
71 * This function copies a received frame to all monitor interfaces and
72 * returns a cleaned-up SKB that no longer includes the FCS nor the
73 * radiotap header the driver might have added.
75 static struct sk_buff
*
76 ieee80211_rx_monitor(struct ieee80211_local
*local
, struct sk_buff
*origskb
,
77 struct ieee80211_rx_status
*status
)
79 struct ieee80211_sub_if_data
*sdata
;
80 struct ieee80211_rate
*rate
;
81 int needed_headroom
= 0;
82 struct ieee80211_rtap_hdr
{
83 struct ieee80211_radiotap_header hdr
;
89 u8 padding_for_rxflags
;
91 } __attribute__ ((packed
)) *rthdr
;
92 struct sk_buff
*skb
, *skb2
;
93 struct net_device
*prev_dev
= NULL
;
94 int present_fcs_len
= 0;
98 * First, we may need to make a copy of the skb because
99 * (1) we need to modify it for radiotap (if not present), and
100 * (2) the other RX handlers will modify the skb we got.
102 * We don't need to, of course, if we aren't going to return
103 * the SKB because it has a bad FCS/PLCP checksum.
105 if (status
->flag
& RX_FLAG_RADIOTAP
)
106 rtap_len
= ieee80211_get_radiotap_len(origskb
->data
);
108 needed_headroom
= sizeof(*rthdr
);
110 if (local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
)
111 present_fcs_len
= FCS_LEN
;
113 if (!local
->monitors
) {
114 if (should_drop_frame(status
, origskb
, present_fcs_len
,
116 dev_kfree_skb(origskb
);
120 return remove_monitor_info(local
, origskb
, rtap_len
);
123 if (should_drop_frame(status
, origskb
, present_fcs_len
, rtap_len
)) {
124 /* only need to expand headroom if necessary */
129 * This shouldn't trigger often because most devices have an
130 * RX header they pull before we get here, and that should
131 * be big enough for our radiotap information. We should
132 * probably export the length to drivers so that we can have
133 * them allocate enough headroom to start with.
135 if (skb_headroom(skb
) < needed_headroom
&&
136 pskb_expand_head(skb
, sizeof(*rthdr
), 0, GFP_ATOMIC
)) {
142 * Need to make a copy and possibly remove radiotap header
143 * and FCS from the original.
145 skb
= skb_copy_expand(origskb
, needed_headroom
, 0, GFP_ATOMIC
);
147 origskb
= remove_monitor_info(local
, origskb
, rtap_len
);
153 /* if necessary, prepend radiotap information */
154 if (!(status
->flag
& RX_FLAG_RADIOTAP
)) {
155 rthdr
= (void *) skb_push(skb
, sizeof(*rthdr
));
156 memset(rthdr
, 0, sizeof(*rthdr
));
157 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
158 rthdr
->hdr
.it_present
=
159 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS
) |
160 (1 << IEEE80211_RADIOTAP_RATE
) |
161 (1 << IEEE80211_RADIOTAP_CHANNEL
) |
162 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL
) |
163 (1 << IEEE80211_RADIOTAP_RX_FLAGS
));
164 rthdr
->flags
= local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
?
165 IEEE80211_RADIOTAP_F_FCS
: 0;
167 /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
170 (RX_FLAG_FAILED_FCS_CRC
| RX_FLAG_FAILED_PLCP_CRC
))
172 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS
);
174 rate
= ieee80211_get_rate(local
, status
->phymode
,
177 rthdr
->rate
= rate
->rate
/ 5;
179 rthdr
->chan_freq
= cpu_to_le16(status
->freq
);
181 if (status
->phymode
== MODE_IEEE80211A
)
183 cpu_to_le16(IEEE80211_CHAN_OFDM
|
184 IEEE80211_CHAN_5GHZ
);
187 cpu_to_le16(IEEE80211_CHAN_DYN
|
188 IEEE80211_CHAN_2GHZ
);
190 rthdr
->antsignal
= status
->ssi
;
193 skb_set_mac_header(skb
, 0);
194 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
195 skb
->pkt_type
= PACKET_OTHERHOST
;
196 skb
->protocol
= htons(ETH_P_802_2
);
198 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
199 if (!netif_running(sdata
->dev
))
202 if (sdata
->type
!= IEEE80211_IF_TYPE_MNTR
)
206 skb2
= skb_clone(skb
, GFP_ATOMIC
);
208 skb2
->dev
= prev_dev
;
213 prev_dev
= sdata
->dev
;
214 sdata
->dev
->stats
.rx_packets
++;
215 sdata
->dev
->stats
.rx_bytes
+= skb
->len
;
230 * these don't have dev/sdata fields in the rx data
231 * The sta value should also not be used because it may
232 * be NULL even though a STA (in IBSS mode) will be added.
235 static ieee80211_txrx_result
236 ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data
*rx
)
238 u8
*data
= rx
->skb
->data
;
241 /* does the frame have a qos control field? */
242 if (WLAN_FC_IS_QOS_DATA(rx
->fc
)) {
243 u8
*qc
= data
+ ieee80211_get_hdrlen(rx
->fc
) - QOS_CONTROL_LEN
;
244 /* frame has qos control */
245 tid
= qc
[0] & QOS_CONTROL_TID_MASK
;
247 if (unlikely((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)) {
248 /* Separate TID for management frames */
249 tid
= NUM_RX_DATA_QUEUES
- 1;
251 /* no qos control present */
252 tid
= 0; /* 802.1d - Best Effort */
256 I802_DEBUG_INC(rx
->local
->wme_rx_queue
[tid
]);
257 /* only a debug counter, sta might not be assigned properly yet */
259 I802_DEBUG_INC(rx
->sta
->wme_rx_queue
[tid
]);
261 rx
->u
.rx
.queue
= tid
;
262 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
263 * For now, set skb->priority to 0 for other cases. */
264 rx
->skb
->priority
= (tid
> 7) ? 0 : tid
;
266 return TXRX_CONTINUE
;
269 static ieee80211_txrx_result
270 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data
*rx
)
272 struct ieee80211_local
*local
= rx
->local
;
273 struct sk_buff
*skb
= rx
->skb
;
274 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
275 u32 load
= 0, hdrtime
;
276 struct ieee80211_rate
*rate
;
277 struct ieee80211_hw_mode
*mode
= local
->hw
.conf
.mode
;
280 /* Estimate total channel use caused by this frame */
282 if (unlikely(mode
->num_rates
< 0))
283 return TXRX_CONTINUE
;
285 rate
= &mode
->rates
[0];
286 for (i
= 0; i
< mode
->num_rates
; i
++) {
287 if (mode
->rates
[i
].val
== rx
->u
.rx
.status
->rate
) {
288 rate
= &mode
->rates
[i
];
293 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
294 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
296 if (mode
->mode
== MODE_IEEE80211A
||
297 (mode
->mode
== MODE_IEEE80211G
&&
298 rate
->flags
& IEEE80211_RATE_ERP
))
299 hdrtime
= CHAN_UTIL_HDR_SHORT
;
301 hdrtime
= CHAN_UTIL_HDR_LONG
;
304 if (!is_multicast_ether_addr(hdr
->addr1
))
307 load
+= skb
->len
* rate
->rate_inv
;
309 /* Divide channel_use by 8 to avoid wrapping around the counter */
310 load
>>= CHAN_UTIL_SHIFT
;
311 local
->channel_use_raw
+= load
;
312 rx
->u
.rx
.load
= load
;
314 return TXRX_CONTINUE
;
317 ieee80211_rx_handler ieee80211_rx_pre_handlers
[] =
319 ieee80211_rx_h_parse_qos
,
320 ieee80211_rx_h_load_stats
,
326 static ieee80211_txrx_result
327 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data
*rx
)
330 rx
->sta
->channel_use_raw
+= rx
->u
.rx
.load
;
331 rx
->sdata
->channel_use_raw
+= rx
->u
.rx
.load
;
332 return TXRX_CONTINUE
;
335 static ieee80211_txrx_result
336 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data
*rx
)
338 struct ieee80211_local
*local
= rx
->local
;
339 struct sk_buff
*skb
= rx
->skb
;
341 if (unlikely(local
->sta_scanning
!= 0)) {
342 ieee80211_sta_rx_scan(rx
->dev
, skb
, rx
->u
.rx
.status
);
346 if (unlikely(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
)) {
347 /* scanning finished during invoking of handlers */
348 I802_DEBUG_INC(local
->rx_handlers_drop_passive_scan
);
352 return TXRX_CONTINUE
;
355 static ieee80211_txrx_result
356 ieee80211_rx_h_check(struct ieee80211_txrx_data
*rx
)
358 struct ieee80211_hdr
*hdr
;
359 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
361 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
362 if (rx
->sta
&& !is_multicast_ether_addr(hdr
->addr1
)) {
363 if (unlikely(rx
->fc
& IEEE80211_FCTL_RETRY
&&
364 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] ==
366 if (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
) {
367 rx
->local
->dot11FrameDuplicateCount
++;
368 rx
->sta
->num_duplicates
++;
372 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] = hdr
->seq_ctrl
;
375 if (unlikely(rx
->skb
->len
< 16)) {
376 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_short
);
380 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
381 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
382 else if (compare_ether_addr(rx
->dev
->dev_addr
, hdr
->addr1
) == 0)
383 rx
->skb
->pkt_type
= PACKET_HOST
;
384 else if (is_multicast_ether_addr(hdr
->addr1
)) {
385 if (is_broadcast_ether_addr(hdr
->addr1
))
386 rx
->skb
->pkt_type
= PACKET_BROADCAST
;
388 rx
->skb
->pkt_type
= PACKET_MULTICAST
;
390 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
392 /* Drop disallowed frame classes based on STA auth/assoc state;
393 * IEEE 802.11, Chap 5.5.
395 * 80211.o does filtering only based on association state, i.e., it
396 * drops Class 3 frames from not associated stations. hostapd sends
397 * deauth/disassoc frames when needed. In addition, hostapd is
398 * responsible for filtering on both auth and assoc states.
400 if (unlikely(((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
||
401 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
&&
402 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PSPOLL
)) &&
403 rx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
404 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_ASSOC
)))) {
405 if ((!(rx
->fc
& IEEE80211_FCTL_FROMDS
) &&
406 !(rx
->fc
& IEEE80211_FCTL_TODS
) &&
407 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)
408 || !(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)) {
409 /* Drop IBSS frames and frames for other hosts
417 return TXRX_CONTINUE
;
421 static ieee80211_txrx_result
422 ieee80211_rx_h_load_key(struct ieee80211_txrx_data
*rx
)
424 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
427 struct ieee80211_key
*stakey
= NULL
;
432 * There are three types of keys:
434 * - PTK (pairwise keys)
435 * - STK (station-to-station pairwise keys)
437 * When selecting a key, we have to distinguish between multicast
438 * (including broadcast) and unicast frames, the latter can only
439 * use PTKs and STKs while the former always use GTKs. Unless, of
440 * course, actual WEP keys ("pre-RSNA") are used, then unicast
441 * frames can also use key indizes like GTKs. Hence, if we don't
442 * have a PTK/STK we check the key index for a WEP key.
444 * Note that in a regular BSS, multicast frames are sent by the
445 * AP only, associated stations unicast the frame to the AP first
446 * which then multicasts it on their behalf.
448 * There is also a slight problem in IBSS mode: GTKs are negotiated
449 * with each station, that is something we don't currently handle.
450 * The spec seems to expect that one negotiates the same key with
451 * every station but there's no such requirement; VLANs could be
455 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
))
456 return TXRX_CONTINUE
;
459 * No point in finding a key if the frame is neither
460 * addressed to us nor a multicast frame.
462 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
463 return TXRX_CONTINUE
;
466 stakey
= rcu_dereference(rx
->sta
->key
);
468 if (!is_multicast_ether_addr(hdr
->addr1
) && stakey
) {
472 * The device doesn't give us the IV so we won't be
473 * able to look up the key. That's ok though, we
474 * don't need to decrypt the frame, we just won't
475 * be able to keep statistics accurate.
476 * Except for key threshold notifications, should
477 * we somehow allow the driver to tell us which key
478 * the hardware used if this flag is set?
480 if ((rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
) &&
481 (rx
->u
.rx
.status
->flag
& RX_FLAG_IV_STRIPPED
))
482 return TXRX_CONTINUE
;
484 hdrlen
= ieee80211_get_hdrlen(rx
->fc
);
486 if (rx
->skb
->len
< 8 + hdrlen
)
487 return TXRX_DROP
; /* TODO: count this? */
490 * no need to call ieee80211_wep_get_keyidx,
491 * it verifies a bunch of things we've done already
493 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
495 rx
->key
= rcu_dereference(rx
->sdata
->keys
[keyidx
]);
498 * RSNA-protected unicast frames should always be sent with
499 * pairwise or station-to-station keys, but for WEP we allow
500 * using a key index as well.
502 if (rx
->key
&& rx
->key
->conf
.alg
!= ALG_WEP
&&
503 !is_multicast_ether_addr(hdr
->addr1
))
508 rx
->key
->tx_rx_count
++;
509 /* TODO: add threshold stuff again */
512 return TXRX_CONTINUE
;
515 static ieee80211_txrx_result
516 ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data
*rx
)
518 if (!rx
->sta
|| !(rx
->fc
& IEEE80211_FCTL_PROTECTED
) ||
519 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
||
520 !rx
->key
|| rx
->key
->conf
.alg
!= ALG_WEP
||
521 !(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
522 return TXRX_CONTINUE
;
524 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
525 if (!(rx
->u
.rx
.status
->flag
& RX_FLAG_IV_STRIPPED
) ||
526 !(rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
))
527 if (ieee80211_wep_is_weak_iv(rx
->skb
, rx
->key
))
528 rx
->sta
->wep_weak_iv_count
++;
530 return TXRX_CONTINUE
;
533 static ieee80211_txrx_result
534 ieee80211_rx_h_decrypt(struct ieee80211_txrx_data
*rx
)
536 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
))
537 return TXRX_CONTINUE
;
541 printk(KERN_DEBUG
"%s: RX protected frame,"
542 " but have no key\n", rx
->dev
->name
);
546 switch (rx
->key
->conf
.alg
) {
548 return ieee80211_crypto_wep_decrypt(rx
);
550 return ieee80211_crypto_tkip_decrypt(rx
);
552 return ieee80211_crypto_ccmp_decrypt(rx
);
554 return TXRX_CONTINUE
;
562 static void ap_sta_ps_start(struct net_device
*dev
, struct sta_info
*sta
)
564 struct ieee80211_sub_if_data
*sdata
;
565 DECLARE_MAC_BUF(mac
);
567 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
570 atomic_inc(&sdata
->bss
->num_sta_ps
);
571 sta
->flags
|= WLAN_STA_PS
;
573 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
574 printk(KERN_DEBUG
"%s: STA %s aid %d enters power save mode\n",
575 dev
->name
, print_mac(mac
, sta
->addr
), sta
->aid
);
576 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
579 static int ap_sta_ps_end(struct net_device
*dev
, struct sta_info
*sta
)
581 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
584 struct ieee80211_sub_if_data
*sdata
;
585 struct ieee80211_tx_packet_data
*pkt_data
;
586 DECLARE_MAC_BUF(mac
);
588 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
590 atomic_dec(&sdata
->bss
->num_sta_ps
);
591 sta
->flags
&= ~(WLAN_STA_PS
| WLAN_STA_TIM
);
593 if (!skb_queue_empty(&sta
->ps_tx_buf
)) {
594 if (local
->ops
->set_tim
)
595 local
->ops
->set_tim(local_to_hw(local
), sta
->aid
, 0);
597 bss_tim_clear(local
, sdata
->bss
, sta
->aid
);
599 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
600 printk(KERN_DEBUG
"%s: STA %s aid %d exits power save mode\n",
601 dev
->name
, print_mac(mac
, sta
->addr
), sta
->aid
);
602 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
603 /* Send all buffered frames to the station */
604 while ((skb
= skb_dequeue(&sta
->tx_filtered
)) != NULL
) {
605 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
607 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
610 while ((skb
= skb_dequeue(&sta
->ps_tx_buf
)) != NULL
) {
611 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
612 local
->total_ps_buffered
--;
614 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
615 printk(KERN_DEBUG
"%s: STA %s aid %d send PS frame "
616 "since STA not sleeping anymore\n", dev
->name
,
617 print_mac(mac
, sta
->addr
), sta
->aid
);
618 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
619 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
626 static ieee80211_txrx_result
627 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data
*rx
)
629 struct sta_info
*sta
= rx
->sta
;
630 struct net_device
*dev
= rx
->dev
;
631 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
634 return TXRX_CONTINUE
;
636 /* Update last_rx only for IBSS packets which are for the current
637 * BSSID to avoid keeping the current IBSS network alive in cases where
638 * other STAs are using different BSSID. */
639 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
640 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
);
641 if (compare_ether_addr(bssid
, rx
->sdata
->u
.sta
.bssid
) == 0)
642 sta
->last_rx
= jiffies
;
644 if (!is_multicast_ether_addr(hdr
->addr1
) ||
645 rx
->sdata
->type
== IEEE80211_IF_TYPE_STA
) {
646 /* Update last_rx only for unicast frames in order to prevent
647 * the Probe Request frames (the only broadcast frames from a
648 * STA in infrastructure mode) from keeping a connection alive.
650 sta
->last_rx
= jiffies
;
653 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
654 return TXRX_CONTINUE
;
657 sta
->rx_bytes
+= rx
->skb
->len
;
658 sta
->last_rssi
= rx
->u
.rx
.status
->ssi
;
659 sta
->last_signal
= rx
->u
.rx
.status
->signal
;
660 sta
->last_noise
= rx
->u
.rx
.status
->noise
;
662 if (!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
)) {
663 /* Change STA power saving mode only in the end of a frame
664 * exchange sequence */
665 if ((sta
->flags
& WLAN_STA_PS
) && !(rx
->fc
& IEEE80211_FCTL_PM
))
666 rx
->u
.rx
.sent_ps_buffered
+= ap_sta_ps_end(dev
, sta
);
667 else if (!(sta
->flags
& WLAN_STA_PS
) &&
668 (rx
->fc
& IEEE80211_FCTL_PM
))
669 ap_sta_ps_start(dev
, sta
);
672 /* Drop data::nullfunc frames silently, since they are used only to
673 * control station power saving mode. */
674 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
675 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_NULLFUNC
) {
676 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
677 /* Update counter and free packet here to avoid counting this
678 * as a dropped packed. */
680 dev_kfree_skb(rx
->skb
);
684 return TXRX_CONTINUE
;
685 } /* ieee80211_rx_h_sta_process */
687 static inline struct ieee80211_fragment_entry
*
688 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
689 unsigned int frag
, unsigned int seq
, int rx_queue
,
690 struct sk_buff
**skb
)
692 struct ieee80211_fragment_entry
*entry
;
695 idx
= sdata
->fragment_next
;
696 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
697 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
698 sdata
->fragment_next
= 0;
700 if (!skb_queue_empty(&entry
->skb_list
)) {
701 #ifdef CONFIG_MAC80211_DEBUG
702 struct ieee80211_hdr
*hdr
=
703 (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
704 DECLARE_MAC_BUF(mac
);
705 DECLARE_MAC_BUF(mac2
);
706 printk(KERN_DEBUG
"%s: RX reassembly removed oldest "
707 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
708 "addr1=%s addr2=%s\n",
709 sdata
->dev
->name
, idx
,
710 jiffies
- entry
->first_frag_time
, entry
->seq
,
711 entry
->last_frag
, print_mac(mac
, hdr
->addr1
),
712 print_mac(mac2
, hdr
->addr2
));
713 #endif /* CONFIG_MAC80211_DEBUG */
714 __skb_queue_purge(&entry
->skb_list
);
717 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
719 entry
->first_frag_time
= jiffies
;
721 entry
->rx_queue
= rx_queue
;
722 entry
->last_frag
= frag
;
724 entry
->extra_len
= 0;
729 static inline struct ieee80211_fragment_entry
*
730 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
731 u16 fc
, unsigned int frag
, unsigned int seq
,
732 int rx_queue
, struct ieee80211_hdr
*hdr
)
734 struct ieee80211_fragment_entry
*entry
;
737 idx
= sdata
->fragment_next
;
738 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
739 struct ieee80211_hdr
*f_hdr
;
744 idx
= IEEE80211_FRAGMENT_MAX
- 1;
746 entry
= &sdata
->fragments
[idx
];
747 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
748 entry
->rx_queue
!= rx_queue
||
749 entry
->last_frag
+ 1 != frag
)
752 f_hdr
= (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
753 f_fc
= le16_to_cpu(f_hdr
->frame_control
);
755 if ((fc
& IEEE80211_FCTL_FTYPE
) != (f_fc
& IEEE80211_FCTL_FTYPE
) ||
756 compare_ether_addr(hdr
->addr1
, f_hdr
->addr1
) != 0 ||
757 compare_ether_addr(hdr
->addr2
, f_hdr
->addr2
) != 0)
760 if (entry
->first_frag_time
+ 2 * HZ
< jiffies
) {
761 __skb_queue_purge(&entry
->skb_list
);
770 static ieee80211_txrx_result
771 ieee80211_rx_h_defragment(struct ieee80211_txrx_data
*rx
)
773 struct ieee80211_hdr
*hdr
;
775 unsigned int frag
, seq
;
776 struct ieee80211_fragment_entry
*entry
;
778 DECLARE_MAC_BUF(mac
);
780 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
781 sc
= le16_to_cpu(hdr
->seq_ctrl
);
782 frag
= sc
& IEEE80211_SCTL_FRAG
;
784 if (likely((!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) && frag
== 0) ||
785 (rx
->skb
)->len
< 24 ||
786 is_multicast_ether_addr(hdr
->addr1
))) {
790 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
792 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
795 /* This is the first fragment of a new frame. */
796 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
797 rx
->u
.rx
.queue
, &(rx
->skb
));
798 if (rx
->key
&& rx
->key
->conf
.alg
== ALG_CCMP
&&
799 (rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
800 /* Store CCMP PN so that we can verify that the next
801 * fragment has a sequential PN value. */
803 memcpy(entry
->last_pn
,
804 rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
],
810 /* This is a fragment for a frame that should already be pending in
811 * fragment cache. Add this fragment to the end of the pending entry.
813 entry
= ieee80211_reassemble_find(rx
->sdata
, rx
->fc
, frag
, seq
,
814 rx
->u
.rx
.queue
, hdr
);
816 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
820 /* Verify that MPDUs within one MSDU have sequential PN values.
821 * (IEEE 802.11i, 8.3.3.4.5) */
824 u8 pn
[CCMP_PN_LEN
], *rpn
;
825 if (!rx
->key
|| rx
->key
->conf
.alg
!= ALG_CCMP
)
827 memcpy(pn
, entry
->last_pn
, CCMP_PN_LEN
);
828 for (i
= CCMP_PN_LEN
- 1; i
>= 0; i
--) {
833 rpn
= rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
];
834 if (memcmp(pn
, rpn
, CCMP_PN_LEN
) != 0) {
836 printk(KERN_DEBUG
"%s: defrag: CCMP PN not "
838 " PN=%02x%02x%02x%02x%02x%02x "
839 "(expected %02x%02x%02x%02x%02x%02x)\n",
840 rx
->dev
->name
, print_mac(mac
, hdr
->addr2
),
841 rpn
[0], rpn
[1], rpn
[2], rpn
[3], rpn
[4],
842 rpn
[5], pn
[0], pn
[1], pn
[2], pn
[3],
846 memcpy(entry
->last_pn
, pn
, CCMP_PN_LEN
);
849 skb_pull(rx
->skb
, ieee80211_get_hdrlen(rx
->fc
));
850 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
851 entry
->last_frag
= frag
;
852 entry
->extra_len
+= rx
->skb
->len
;
853 if (rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) {
858 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
859 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
860 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head2
);
861 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
863 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
864 __skb_queue_purge(&entry
->skb_list
);
868 while ((skb
= __skb_dequeue(&entry
->skb_list
))) {
869 memcpy(skb_put(rx
->skb
, skb
->len
), skb
->data
, skb
->len
);
873 /* Complete frame has been reassembled - process it now */
874 rx
->flags
|= IEEE80211_TXRXD_FRAGMENTED
;
878 rx
->sta
->rx_packets
++;
879 if (is_multicast_ether_addr(hdr
->addr1
))
880 rx
->local
->dot11MulticastReceivedFrameCount
++;
882 ieee80211_led_rx(rx
->local
);
883 return TXRX_CONTINUE
;
886 static ieee80211_txrx_result
887 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data
*rx
)
891 DECLARE_MAC_BUF(mac
);
893 if (likely(!rx
->sta
||
894 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_CTL
||
895 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_PSPOLL
||
896 !(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)))
897 return TXRX_CONTINUE
;
899 skb
= skb_dequeue(&rx
->sta
->tx_filtered
);
901 skb
= skb_dequeue(&rx
->sta
->ps_tx_buf
);
903 rx
->local
->total_ps_buffered
--;
905 no_pending_pkts
= skb_queue_empty(&rx
->sta
->tx_filtered
) &&
906 skb_queue_empty(&rx
->sta
->ps_tx_buf
);
909 struct ieee80211_hdr
*hdr
=
910 (struct ieee80211_hdr
*) skb
->data
;
912 /* tell TX path to send one frame even though the STA may
913 * still remain is PS mode after this frame exchange */
916 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
917 printk(KERN_DEBUG
"STA %s aid %d: PS Poll (entries after %d)\n",
918 print_mac(mac
, rx
->sta
->addr
), rx
->sta
->aid
,
919 skb_queue_len(&rx
->sta
->ps_tx_buf
));
920 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
922 /* Use MoreData flag to indicate whether there are more
923 * buffered frames for this STA */
924 if (no_pending_pkts
) {
925 hdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_MOREDATA
);
926 rx
->sta
->flags
&= ~WLAN_STA_TIM
;
928 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
932 if (no_pending_pkts
) {
933 if (rx
->local
->ops
->set_tim
)
934 rx
->local
->ops
->set_tim(local_to_hw(rx
->local
),
937 bss_tim_clear(rx
->local
, rx
->sdata
->bss
, rx
->sta
->aid
);
939 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
940 } else if (!rx
->u
.rx
.sent_ps_buffered
) {
941 printk(KERN_DEBUG
"%s: STA %s sent PS Poll even "
942 "though there is no buffered frames for it\n",
943 rx
->dev
->name
, print_mac(mac
, rx
->sta
->addr
));
944 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
948 /* Free PS Poll skb here instead of returning TXRX_DROP that would
949 * count as an dropped frame. */
950 dev_kfree_skb(rx
->skb
);
955 static ieee80211_txrx_result
956 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data
*rx
)
959 u8
*data
= rx
->skb
->data
;
960 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) data
;
962 if (!WLAN_FC_IS_QOS_DATA(fc
))
963 return TXRX_CONTINUE
;
965 /* remove the qos control field, update frame type and meta-data */
966 memmove(data
+ 2, data
, ieee80211_get_hdrlen(fc
) - 2);
967 hdr
= (struct ieee80211_hdr
*) skb_pull(rx
->skb
, 2);
968 /* change frame type to non QOS */
969 rx
->fc
= fc
&= ~IEEE80211_STYPE_QOS_DATA
;
970 hdr
->frame_control
= cpu_to_le16(fc
);
972 return TXRX_CONTINUE
;
975 static ieee80211_txrx_result
976 ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data
*rx
)
978 if (rx
->sdata
->eapol
&& ieee80211_is_eapol(rx
->skb
) &&
979 rx
->sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
980 (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
981 return TXRX_CONTINUE
;
983 if (unlikely(rx
->sdata
->ieee802_1x
&&
984 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
985 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
986 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_AUTHORIZED
)) &&
987 !ieee80211_is_eapol(rx
->skb
))) {
988 #ifdef CONFIG_MAC80211_DEBUG
989 struct ieee80211_hdr
*hdr
=
990 (struct ieee80211_hdr
*) rx
->skb
->data
;
991 DECLARE_MAC_BUF(mac
);
992 printk(KERN_DEBUG
"%s: dropped frame from %s"
993 " (unauthorized port)\n", rx
->dev
->name
,
994 print_mac(mac
, hdr
->addr2
));
995 #endif /* CONFIG_MAC80211_DEBUG */
999 return TXRX_CONTINUE
;
1002 static ieee80211_txrx_result
1003 ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data
*rx
)
1006 * Pass through unencrypted frames if the hardware has
1007 * decrypted them already.
1009 if (rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
)
1010 return TXRX_CONTINUE
;
1012 /* Drop unencrypted frames if key is set. */
1013 if (unlikely(!(rx
->fc
& IEEE80211_FCTL_PROTECTED
) &&
1014 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
1015 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
1016 (rx
->key
|| rx
->sdata
->drop_unencrypted
) &&
1017 (rx
->sdata
->eapol
== 0 ||
1018 !ieee80211_is_eapol(rx
->skb
)))) {
1019 if (net_ratelimit())
1020 printk(KERN_DEBUG
"%s: RX non-WEP frame, but expected "
1021 "encryption\n", rx
->dev
->name
);
1024 return TXRX_CONTINUE
;
1027 static ieee80211_txrx_result
1028 ieee80211_rx_h_data(struct ieee80211_txrx_data
*rx
)
1030 struct net_device
*dev
= rx
->dev
;
1031 struct ieee80211_local
*local
= rx
->local
;
1032 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
1033 u16 fc
, hdrlen
, ethertype
;
1037 struct sk_buff
*skb
= rx
->skb
, *skb2
;
1038 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1039 DECLARE_MAC_BUF(mac
);
1040 DECLARE_MAC_BUF(mac2
);
1041 DECLARE_MAC_BUF(mac3
);
1042 DECLARE_MAC_BUF(mac4
);
1045 if (unlikely((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
))
1046 return TXRX_CONTINUE
;
1048 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
1051 hdrlen
= ieee80211_get_hdrlen(fc
);
1053 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1055 * IEEE 802.11 address fields:
1056 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1057 * 0 0 DA SA BSSID n/a
1058 * 0 1 DA BSSID SA n/a
1059 * 1 0 BSSID SA DA n/a
1063 switch (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
1064 case IEEE80211_FCTL_TODS
:
1066 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1067 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1069 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_AP
&&
1070 sdata
->type
!= IEEE80211_IF_TYPE_VLAN
)) {
1071 if (net_ratelimit())
1072 printk(KERN_DEBUG
"%s: dropped ToDS frame "
1073 "(BSSID=%s SA=%s DA=%s)\n",
1075 print_mac(mac
, hdr
->addr1
),
1076 print_mac(mac2
, hdr
->addr2
),
1077 print_mac(mac3
, hdr
->addr3
));
1081 case (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
1083 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1084 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
1086 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_WDS
)) {
1087 if (net_ratelimit())
1088 printk(KERN_DEBUG
"%s: dropped FromDS&ToDS "
1089 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1091 print_mac(mac
, hdr
->addr1
),
1092 print_mac(mac2
, hdr
->addr2
),
1093 print_mac(mac3
, hdr
->addr3
),
1094 print_mac(mac4
, hdr
->addr4
));
1098 case IEEE80211_FCTL_FROMDS
:
1100 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1101 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
1103 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
||
1104 (is_multicast_ether_addr(dst
) &&
1105 !compare_ether_addr(src
, dev
->dev_addr
)))
1110 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1111 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1113 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
1114 if (net_ratelimit()) {
1115 printk(KERN_DEBUG
"%s: dropped IBSS frame "
1116 "(DA=%s SA=%s BSSID=%s)\n",
1118 print_mac(mac
, hdr
->addr1
),
1119 print_mac(mac2
, hdr
->addr2
),
1120 print_mac(mac3
, hdr
->addr3
));
1127 payload
= skb
->data
+ hdrlen
;
1129 if (unlikely(skb
->len
- hdrlen
< 8)) {
1130 if (net_ratelimit()) {
1131 printk(KERN_DEBUG
"%s: RX too short data frame "
1132 "payload\n", dev
->name
);
1137 ethertype
= (payload
[6] << 8) | payload
[7];
1139 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
1140 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1141 compare_ether_addr(payload
, bridge_tunnel_header
) == 0)) {
1142 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1143 * replace EtherType */
1144 skb_pull(skb
, hdrlen
+ 6);
1145 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
1146 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1148 struct ethhdr
*ehdr
;
1150 skb_pull(skb
, hdrlen
);
1151 len
= htons(skb
->len
);
1152 ehdr
= (struct ethhdr
*) skb_push(skb
, sizeof(struct ethhdr
));
1153 memcpy(ehdr
->h_dest
, dst
, ETH_ALEN
);
1154 memcpy(ehdr
->h_source
, src
, ETH_ALEN
);
1155 ehdr
->h_proto
= len
;
1161 dev
->stats
.rx_packets
++;
1162 dev
->stats
.rx_bytes
+= skb
->len
;
1164 if (local
->bridge_packets
&& (sdata
->type
== IEEE80211_IF_TYPE_AP
1165 || sdata
->type
== IEEE80211_IF_TYPE_VLAN
) &&
1166 (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)) {
1167 if (is_multicast_ether_addr(skb
->data
)) {
1168 /* send multicast frames both to higher layers in
1169 * local net stack and back to the wireless media */
1170 skb2
= skb_copy(skb
, GFP_ATOMIC
);
1171 if (!skb2
&& net_ratelimit())
1172 printk(KERN_DEBUG
"%s: failed to clone "
1173 "multicast frame\n", dev
->name
);
1175 struct sta_info
*dsta
;
1176 dsta
= sta_info_get(local
, skb
->data
);
1177 if (dsta
&& !dsta
->dev
) {
1178 if (net_ratelimit())
1179 printk(KERN_DEBUG
"Station with null "
1180 "dev structure!\n");
1181 } else if (dsta
&& dsta
->dev
== dev
) {
1182 /* Destination station is associated to this
1183 * AP, so send the frame directly to it and
1184 * do not pass the frame to local net stack.
1195 /* deliver to local stack */
1196 skb
->protocol
= eth_type_trans(skb
, dev
);
1197 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1202 /* send to wireless media */
1203 skb2
->protocol
= __constant_htons(ETH_P_802_3
);
1204 skb_set_network_header(skb2
, 0);
1205 skb_set_mac_header(skb2
, 0);
1206 dev_queue_xmit(skb2
);
1212 static ieee80211_txrx_result
1213 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data
*rx
)
1215 struct ieee80211_sub_if_data
*sdata
;
1217 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
1220 sdata
= IEEE80211_DEV_TO_SUB_IF(rx
->dev
);
1221 if ((sdata
->type
== IEEE80211_IF_TYPE_STA
||
1222 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) &&
1223 !rx
->local
->user_space_mlme
)
1224 ieee80211_sta_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
1231 static inline ieee80211_txrx_result
__ieee80211_invoke_rx_handlers(
1232 struct ieee80211_local
*local
,
1233 ieee80211_rx_handler
*handlers
,
1234 struct ieee80211_txrx_data
*rx
,
1235 struct sta_info
*sta
)
1237 ieee80211_rx_handler
*handler
;
1238 ieee80211_txrx_result res
= TXRX_DROP
;
1240 for (handler
= handlers
; *handler
!= NULL
; handler
++) {
1241 res
= (*handler
)(rx
);
1247 I802_DEBUG_INC(local
->rx_handlers_drop
);
1252 I802_DEBUG_INC(local
->rx_handlers_queued
);
1258 if (res
== TXRX_DROP
)
1259 dev_kfree_skb(rx
->skb
);
1263 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local
*local
,
1264 ieee80211_rx_handler
*handlers
,
1265 struct ieee80211_txrx_data
*rx
,
1266 struct sta_info
*sta
)
1268 if (__ieee80211_invoke_rx_handlers(local
, handlers
, rx
, sta
) ==
1270 dev_kfree_skb(rx
->skb
);
1273 static void ieee80211_rx_michael_mic_report(struct net_device
*dev
,
1274 struct ieee80211_hdr
*hdr
,
1275 struct sta_info
*sta
,
1276 struct ieee80211_txrx_data
*rx
)
1279 DECLARE_MAC_BUF(mac
);
1280 DECLARE_MAC_BUF(mac2
);
1282 hdrlen
= ieee80211_get_hdrlen_from_skb(rx
->skb
);
1283 if (rx
->skb
->len
>= hdrlen
+ 4)
1284 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
1288 if (net_ratelimit())
1289 printk(KERN_DEBUG
"%s: TKIP hwaccel reported Michael MIC "
1290 "failure from %s to %s keyidx=%d\n",
1291 dev
->name
, print_mac(mac
, hdr
->addr2
),
1292 print_mac(mac2
, hdr
->addr1
), keyidx
);
1296 * Some hardware seem to generate incorrect Michael MIC
1297 * reports; ignore them to avoid triggering countermeasures.
1299 if (net_ratelimit())
1300 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1301 "error for unknown address %s\n",
1302 dev
->name
, print_mac(mac
, hdr
->addr2
));
1306 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
1307 if (net_ratelimit())
1308 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1309 "error for a frame with no PROTECTED flag (src "
1310 "%s)\n", dev
->name
, print_mac(mac
, hdr
->addr2
));
1314 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_AP
&& keyidx
) {
1316 * APs with pairwise keys should never receive Michael MIC
1317 * errors for non-zero keyidx because these are reserved for
1318 * group keys and only the AP is sending real multicast
1319 * frames in the BSS.
1321 if (net_ratelimit())
1322 printk(KERN_DEBUG
"%s: ignored Michael MIC error for "
1323 "a frame with non-zero keyidx (%d)"
1324 " (src %s)\n", dev
->name
, keyidx
,
1325 print_mac(mac
, hdr
->addr2
));
1329 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
1330 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
1331 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)) {
1332 if (net_ratelimit())
1333 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1334 "error for a frame that cannot be encrypted "
1335 "(fc=0x%04x) (src %s)\n",
1336 dev
->name
, rx
->fc
, print_mac(mac
, hdr
->addr2
));
1340 mac80211_ev_michael_mic_failure(rx
->dev
, keyidx
, hdr
);
1342 dev_kfree_skb(rx
->skb
);
1346 ieee80211_rx_handler ieee80211_rx_handlers
[] =
1348 ieee80211_rx_h_if_stats
,
1349 ieee80211_rx_h_passive_scan
,
1350 ieee80211_rx_h_check
,
1351 ieee80211_rx_h_load_key
,
1352 ieee80211_rx_h_wep_weak_iv_detection
,
1353 ieee80211_rx_h_decrypt
,
1354 ieee80211_rx_h_sta_process
,
1355 ieee80211_rx_h_defragment
,
1356 ieee80211_rx_h_ps_poll
,
1357 ieee80211_rx_h_michael_mic_verify
,
1358 /* this must be after decryption - so header is counted in MPDU mic
1359 * must be before pae and data, so QOS_DATA format frames
1360 * are not passed to user space by these functions
1362 ieee80211_rx_h_remove_qos_control
,
1363 ieee80211_rx_h_802_1x_pae
,
1364 ieee80211_rx_h_drop_unencrypted
,
1365 ieee80211_rx_h_data
,
1366 ieee80211_rx_h_mgmt
,
1370 /* main receive path */
1372 static int prepare_for_handlers(struct ieee80211_sub_if_data
*sdata
,
1373 u8
*bssid
, struct ieee80211_txrx_data
*rx
,
1374 struct ieee80211_hdr
*hdr
)
1376 int multicast
= is_multicast_ether_addr(hdr
->addr1
);
1378 switch (sdata
->type
) {
1379 case IEEE80211_IF_TYPE_STA
:
1382 if (!ieee80211_bssid_match(bssid
, sdata
->u
.sta
.bssid
)) {
1383 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1385 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1386 } else if (!multicast
&&
1387 compare_ether_addr(sdata
->dev
->dev_addr
,
1389 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
1391 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1394 case IEEE80211_IF_TYPE_IBSS
:
1397 if (!ieee80211_bssid_match(bssid
, sdata
->u
.sta
.bssid
)) {
1398 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1400 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1401 } else if (!multicast
&&
1402 compare_ether_addr(sdata
->dev
->dev_addr
,
1404 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
1406 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1407 } else if (!rx
->sta
)
1408 rx
->sta
= ieee80211_ibss_add_sta(sdata
->dev
, rx
->skb
,
1411 case IEEE80211_IF_TYPE_VLAN
:
1412 case IEEE80211_IF_TYPE_AP
:
1414 if (compare_ether_addr(sdata
->dev
->dev_addr
,
1417 } else if (!ieee80211_bssid_match(bssid
,
1418 sdata
->dev
->dev_addr
)) {
1419 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1421 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1423 if (sdata
->dev
== sdata
->local
->mdev
&&
1424 !(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1425 /* do not receive anything via
1426 * master device when not scanning */
1429 case IEEE80211_IF_TYPE_WDS
:
1431 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
)
1433 if (compare_ether_addr(sdata
->u
.wds
.remote_addr
, hdr
->addr2
))
1436 case IEEE80211_IF_TYPE_MNTR
:
1437 /* take everything */
1439 case IEEE80211_IF_TYPE_INVALID
:
1440 /* should never get here */
1449 * This is the receive path handler. It is called by a low level driver when an
1450 * 802.11 MPDU is received from the hardware.
1452 void __ieee80211_rx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1453 struct ieee80211_rx_status
*status
)
1455 struct ieee80211_local
*local
= hw_to_local(hw
);
1456 struct ieee80211_sub_if_data
*sdata
;
1457 struct sta_info
*sta
;
1458 struct ieee80211_hdr
*hdr
;
1459 struct ieee80211_txrx_data rx
;
1462 struct ieee80211_sub_if_data
*prev
= NULL
;
1463 struct sk_buff
*skb_new
;
1467 * key references and virtual interfaces are protected using RCU
1468 * and this requires that we are in a read-side RCU section during
1469 * receive processing
1474 * Frames with failed FCS/PLCP checksum are not returned,
1475 * all other frames are returned without radiotap header
1476 * if it was previously present.
1477 * Also, frames with less than 16 bytes are dropped.
1479 skb
= ieee80211_rx_monitor(local
, skb
, status
);
1485 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1486 memset(&rx
, 0, sizeof(rx
));
1490 rx
.u
.rx
.status
= status
;
1491 rx
.fc
= le16_to_cpu(hdr
->frame_control
);
1492 type
= rx
.fc
& IEEE80211_FCTL_FTYPE
;
1494 if (type
== IEEE80211_FTYPE_DATA
|| type
== IEEE80211_FTYPE_MGMT
)
1495 local
->dot11ReceivedFragmentCount
++;
1497 sta
= rx
.sta
= sta_info_get(local
, hdr
->addr2
);
1499 rx
.dev
= rx
.sta
->dev
;
1500 rx
.sdata
= IEEE80211_DEV_TO_SUB_IF(rx
.dev
);
1503 if ((status
->flag
& RX_FLAG_MMIC_ERROR
)) {
1504 ieee80211_rx_michael_mic_report(local
->mdev
, hdr
, sta
, &rx
);
1508 if (unlikely(local
->sta_scanning
))
1509 rx
.flags
|= IEEE80211_TXRXD_RXIN_SCAN
;
1511 if (__ieee80211_invoke_rx_handlers(local
, local
->rx_pre_handlers
, &rx
,
1512 sta
) != TXRX_CONTINUE
)
1516 if (sta
&& !(sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_ASSOC_AP
)) &&
1517 !atomic_read(&local
->iff_promiscs
) &&
1518 !is_multicast_ether_addr(hdr
->addr1
)) {
1519 rx
.flags
|= IEEE80211_TXRXD_RXRA_MATCH
;
1520 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
, &rx
,
1527 bssid
= ieee80211_get_bssid(hdr
, skb
->len
);
1529 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1530 if (!netif_running(sdata
->dev
))
1533 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
1536 rx
.flags
|= IEEE80211_TXRXD_RXRA_MATCH
;
1537 prepres
= prepare_for_handlers(sdata
, bssid
, &rx
, hdr
);
1538 /* prepare_for_handlers can change sta */
1545 * frame is destined for this interface, but if it's not
1546 * also for the previous one we handle that after the
1547 * loop to avoid copying the SKB once too much
1556 * frame was destined for the previous interface
1557 * so invoke RX handlers for it
1560 skb_new
= skb_copy(skb
, GFP_ATOMIC
);
1562 if (net_ratelimit())
1563 printk(KERN_DEBUG
"%s: failed to copy "
1564 "multicast frame for %s",
1565 wiphy_name(local
->hw
.wiphy
),
1572 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
1580 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
1591 EXPORT_SYMBOL(__ieee80211_rx
);
1593 /* This is a version of the rx handler that can be called from hard irq
1594 * context. Post the skb on the queue and schedule the tasklet */
1595 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1596 struct ieee80211_rx_status
*status
)
1598 struct ieee80211_local
*local
= hw_to_local(hw
);
1600 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
));
1602 skb
->dev
= local
->mdev
;
1603 /* copy status into skb->cb for use by tasklet */
1604 memcpy(skb
->cb
, status
, sizeof(*status
));
1605 skb
->pkt_type
= IEEE80211_RX_MSG
;
1606 skb_queue_tail(&local
->skb_queue
, skb
);
1607 tasklet_schedule(&local
->tasklet
);
1609 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);