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_decrypt(struct ieee80211_txrx_data
*rx
)
424 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
427 ieee80211_txrx_result result
= TXRX_DROP
;
428 struct ieee80211_key
*stakey
= NULL
;
433 * There are three types of keys:
435 * - PTK (pairwise keys)
436 * - STK (station-to-station pairwise keys)
438 * When selecting a key, we have to distinguish between multicast
439 * (including broadcast) and unicast frames, the latter can only
440 * use PTKs and STKs while the former always use GTKs. Unless, of
441 * course, actual WEP keys ("pre-RSNA") are used, then unicast
442 * frames can also use key indizes like GTKs. Hence, if we don't
443 * have a PTK/STK we check the key index for a WEP key.
445 * Note that in a regular BSS, multicast frames are sent by the
446 * AP only, associated stations unicast the frame to the AP first
447 * which then multicasts it on their behalf.
449 * There is also a slight problem in IBSS mode: GTKs are negotiated
450 * with each station, that is something we don't currently handle.
451 * The spec seems to expect that one negotiates the same key with
452 * every station but there's no such requirement; VLANs could be
456 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
))
457 return TXRX_CONTINUE
;
460 * No point in finding a key and decrypting if the frame is neither
461 * addressed to us nor a multicast frame.
463 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
464 return TXRX_CONTINUE
;
467 stakey
= rcu_dereference(rx
->sta
->key
);
469 if (!is_multicast_ether_addr(hdr
->addr1
) && stakey
) {
473 * The device doesn't give us the IV so we won't be
474 * able to look up the key. That's ok though, we
475 * don't need to decrypt the frame, we just won't
476 * be able to keep statistics accurate.
477 * Except for key threshold notifications, should
478 * we somehow allow the driver to tell us which key
479 * the hardware used if this flag is set?
481 if ((rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
) &&
482 (rx
->u
.rx
.status
->flag
& RX_FLAG_IV_STRIPPED
))
483 return TXRX_CONTINUE
;
485 hdrlen
= ieee80211_get_hdrlen(rx
->fc
);
487 if (rx
->skb
->len
< 8 + hdrlen
)
488 return TXRX_DROP
; /* TODO: count this? */
491 * no need to call ieee80211_wep_get_keyidx,
492 * it verifies a bunch of things we've done already
494 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
496 rx
->key
= rcu_dereference(rx
->sdata
->keys
[keyidx
]);
499 * RSNA-protected unicast frames should always be sent with
500 * pairwise or station-to-station keys, but for WEP we allow
501 * using a key index as well.
503 if (rx
->key
&& rx
->key
->conf
.alg
!= ALG_WEP
&&
504 !is_multicast_ether_addr(hdr
->addr1
))
509 rx
->key
->tx_rx_count
++;
510 /* TODO: add threshold stuff again */
513 printk(KERN_DEBUG
"%s: RX protected frame,"
514 " but have no key\n", rx
->dev
->name
);
518 /* Check for weak IVs if possible */
519 if (rx
->sta
&& rx
->key
->conf
.alg
== ALG_WEP
&&
520 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
521 (!(rx
->u
.rx
.status
->flag
& RX_FLAG_IV_STRIPPED
) ||
522 !(rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
)) &&
523 ieee80211_wep_is_weak_iv(rx
->skb
, rx
->key
))
524 rx
->sta
->wep_weak_iv_count
++;
526 switch (rx
->key
->conf
.alg
) {
528 result
= ieee80211_crypto_wep_decrypt(rx
);
531 result
= ieee80211_crypto_tkip_decrypt(rx
);
534 result
= ieee80211_crypto_ccmp_decrypt(rx
);
538 /* either the frame has been decrypted or will be dropped */
539 rx
->u
.rx
.status
->flag
|= RX_FLAG_DECRYPTED
;
544 static void ap_sta_ps_start(struct net_device
*dev
, struct sta_info
*sta
)
546 struct ieee80211_sub_if_data
*sdata
;
547 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
550 atomic_inc(&sdata
->bss
->num_sta_ps
);
551 sta
->flags
|= WLAN_STA_PS
;
553 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
554 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d enters power "
555 "save mode\n", dev
->name
, MAC_ARG(sta
->addr
), sta
->aid
);
556 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
559 static int ap_sta_ps_end(struct net_device
*dev
, struct sta_info
*sta
)
561 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
564 struct ieee80211_sub_if_data
*sdata
;
565 struct ieee80211_tx_packet_data
*pkt_data
;
567 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
569 atomic_dec(&sdata
->bss
->num_sta_ps
);
570 sta
->flags
&= ~(WLAN_STA_PS
| WLAN_STA_TIM
);
572 if (!skb_queue_empty(&sta
->ps_tx_buf
)) {
573 if (local
->ops
->set_tim
)
574 local
->ops
->set_tim(local_to_hw(local
), sta
->aid
, 0);
576 bss_tim_clear(local
, sdata
->bss
, sta
->aid
);
578 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
579 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d exits power "
580 "save mode\n", dev
->name
, MAC_ARG(sta
->addr
), sta
->aid
);
581 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
582 /* Send all buffered frames to the station */
583 while ((skb
= skb_dequeue(&sta
->tx_filtered
)) != NULL
) {
584 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
586 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
589 while ((skb
= skb_dequeue(&sta
->ps_tx_buf
)) != NULL
) {
590 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
591 local
->total_ps_buffered
--;
593 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
594 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d send PS frame "
595 "since STA not sleeping anymore\n", dev
->name
,
596 MAC_ARG(sta
->addr
), sta
->aid
);
597 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
598 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
605 static ieee80211_txrx_result
606 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data
*rx
)
608 struct sta_info
*sta
= rx
->sta
;
609 struct net_device
*dev
= rx
->dev
;
610 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
613 return TXRX_CONTINUE
;
615 /* Update last_rx only for IBSS packets which are for the current
616 * BSSID to avoid keeping the current IBSS network alive in cases where
617 * other STAs are using different BSSID. */
618 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
619 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
);
620 if (compare_ether_addr(bssid
, rx
->sdata
->u
.sta
.bssid
) == 0)
621 sta
->last_rx
= jiffies
;
623 if (!is_multicast_ether_addr(hdr
->addr1
) ||
624 rx
->sdata
->type
== IEEE80211_IF_TYPE_STA
) {
625 /* Update last_rx only for unicast frames in order to prevent
626 * the Probe Request frames (the only broadcast frames from a
627 * STA in infrastructure mode) from keeping a connection alive.
629 sta
->last_rx
= jiffies
;
632 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
633 return TXRX_CONTINUE
;
636 sta
->rx_bytes
+= rx
->skb
->len
;
637 sta
->last_rssi
= rx
->u
.rx
.status
->ssi
;
638 sta
->last_signal
= rx
->u
.rx
.status
->signal
;
639 sta
->last_noise
= rx
->u
.rx
.status
->noise
;
641 if (!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
)) {
642 /* Change STA power saving mode only in the end of a frame
643 * exchange sequence */
644 if ((sta
->flags
& WLAN_STA_PS
) && !(rx
->fc
& IEEE80211_FCTL_PM
))
645 rx
->u
.rx
.sent_ps_buffered
+= ap_sta_ps_end(dev
, sta
);
646 else if (!(sta
->flags
& WLAN_STA_PS
) &&
647 (rx
->fc
& IEEE80211_FCTL_PM
))
648 ap_sta_ps_start(dev
, sta
);
651 /* Drop data::nullfunc frames silently, since they are used only to
652 * control station power saving mode. */
653 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
654 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_NULLFUNC
) {
655 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
656 /* Update counter and free packet here to avoid counting this
657 * as a dropped packed. */
659 dev_kfree_skb(rx
->skb
);
663 return TXRX_CONTINUE
;
664 } /* ieee80211_rx_h_sta_process */
666 static inline struct ieee80211_fragment_entry
*
667 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
668 unsigned int frag
, unsigned int seq
, int rx_queue
,
669 struct sk_buff
**skb
)
671 struct ieee80211_fragment_entry
*entry
;
674 idx
= sdata
->fragment_next
;
675 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
676 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
677 sdata
->fragment_next
= 0;
679 if (!skb_queue_empty(&entry
->skb_list
)) {
680 #ifdef CONFIG_MAC80211_DEBUG
681 struct ieee80211_hdr
*hdr
=
682 (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
683 printk(KERN_DEBUG
"%s: RX reassembly removed oldest "
684 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
685 "addr1=" MAC_FMT
" addr2=" MAC_FMT
"\n",
686 sdata
->dev
->name
, idx
,
687 jiffies
- entry
->first_frag_time
, entry
->seq
,
688 entry
->last_frag
, MAC_ARG(hdr
->addr1
),
689 MAC_ARG(hdr
->addr2
));
690 #endif /* CONFIG_MAC80211_DEBUG */
691 __skb_queue_purge(&entry
->skb_list
);
694 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
696 entry
->first_frag_time
= jiffies
;
698 entry
->rx_queue
= rx_queue
;
699 entry
->last_frag
= frag
;
701 entry
->extra_len
= 0;
706 static inline struct ieee80211_fragment_entry
*
707 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
708 u16 fc
, unsigned int frag
, unsigned int seq
,
709 int rx_queue
, struct ieee80211_hdr
*hdr
)
711 struct ieee80211_fragment_entry
*entry
;
714 idx
= sdata
->fragment_next
;
715 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
716 struct ieee80211_hdr
*f_hdr
;
721 idx
= IEEE80211_FRAGMENT_MAX
- 1;
723 entry
= &sdata
->fragments
[idx
];
724 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
725 entry
->rx_queue
!= rx_queue
||
726 entry
->last_frag
+ 1 != frag
)
729 f_hdr
= (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
730 f_fc
= le16_to_cpu(f_hdr
->frame_control
);
732 if ((fc
& IEEE80211_FCTL_FTYPE
) != (f_fc
& IEEE80211_FCTL_FTYPE
) ||
733 compare_ether_addr(hdr
->addr1
, f_hdr
->addr1
) != 0 ||
734 compare_ether_addr(hdr
->addr2
, f_hdr
->addr2
) != 0)
737 if (entry
->first_frag_time
+ 2 * HZ
< jiffies
) {
738 __skb_queue_purge(&entry
->skb_list
);
747 static ieee80211_txrx_result
748 ieee80211_rx_h_defragment(struct ieee80211_txrx_data
*rx
)
750 struct ieee80211_hdr
*hdr
;
752 unsigned int frag
, seq
;
753 struct ieee80211_fragment_entry
*entry
;
756 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
757 sc
= le16_to_cpu(hdr
->seq_ctrl
);
758 frag
= sc
& IEEE80211_SCTL_FRAG
;
760 if (likely((!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) && frag
== 0) ||
761 (rx
->skb
)->len
< 24 ||
762 is_multicast_ether_addr(hdr
->addr1
))) {
766 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
768 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
771 /* This is the first fragment of a new frame. */
772 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
773 rx
->u
.rx
.queue
, &(rx
->skb
));
774 if (rx
->key
&& rx
->key
->conf
.alg
== ALG_CCMP
&&
775 (rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
776 /* Store CCMP PN so that we can verify that the next
777 * fragment has a sequential PN value. */
779 memcpy(entry
->last_pn
,
780 rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
],
786 /* This is a fragment for a frame that should already be pending in
787 * fragment cache. Add this fragment to the end of the pending entry.
789 entry
= ieee80211_reassemble_find(rx
->sdata
, rx
->fc
, frag
, seq
,
790 rx
->u
.rx
.queue
, hdr
);
792 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
796 /* Verify that MPDUs within one MSDU have sequential PN values.
797 * (IEEE 802.11i, 8.3.3.4.5) */
800 u8 pn
[CCMP_PN_LEN
], *rpn
;
801 if (!rx
->key
|| rx
->key
->conf
.alg
!= ALG_CCMP
)
803 memcpy(pn
, entry
->last_pn
, CCMP_PN_LEN
);
804 for (i
= CCMP_PN_LEN
- 1; i
>= 0; i
--) {
809 rpn
= rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
];
810 if (memcmp(pn
, rpn
, CCMP_PN_LEN
) != 0) {
812 printk(KERN_DEBUG
"%s: defrag: CCMP PN not "
813 "sequential A2=" MAC_FMT
814 " PN=%02x%02x%02x%02x%02x%02x "
815 "(expected %02x%02x%02x%02x%02x%02x)\n",
816 rx
->dev
->name
, MAC_ARG(hdr
->addr2
),
817 rpn
[0], rpn
[1], rpn
[2], rpn
[3], rpn
[4],
818 rpn
[5], pn
[0], pn
[1], pn
[2], pn
[3],
822 memcpy(entry
->last_pn
, pn
, CCMP_PN_LEN
);
825 skb_pull(rx
->skb
, ieee80211_get_hdrlen(rx
->fc
));
826 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
827 entry
->last_frag
= frag
;
828 entry
->extra_len
+= rx
->skb
->len
;
829 if (rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) {
834 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
835 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
836 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head2
);
837 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
839 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
840 __skb_queue_purge(&entry
->skb_list
);
844 while ((skb
= __skb_dequeue(&entry
->skb_list
))) {
845 memcpy(skb_put(rx
->skb
, skb
->len
), skb
->data
, skb
->len
);
849 /* Complete frame has been reassembled - process it now */
850 rx
->flags
|= IEEE80211_TXRXD_FRAGMENTED
;
854 rx
->sta
->rx_packets
++;
855 if (is_multicast_ether_addr(hdr
->addr1
))
856 rx
->local
->dot11MulticastReceivedFrameCount
++;
858 ieee80211_led_rx(rx
->local
);
859 return TXRX_CONTINUE
;
862 static ieee80211_txrx_result
863 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data
*rx
)
868 if (likely(!rx
->sta
||
869 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_CTL
||
870 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_PSPOLL
||
871 !(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)))
872 return TXRX_CONTINUE
;
874 skb
= skb_dequeue(&rx
->sta
->tx_filtered
);
876 skb
= skb_dequeue(&rx
->sta
->ps_tx_buf
);
878 rx
->local
->total_ps_buffered
--;
880 no_pending_pkts
= skb_queue_empty(&rx
->sta
->tx_filtered
) &&
881 skb_queue_empty(&rx
->sta
->ps_tx_buf
);
884 struct ieee80211_hdr
*hdr
=
885 (struct ieee80211_hdr
*) skb
->data
;
887 /* tell TX path to send one frame even though the STA may
888 * still remain is PS mode after this frame exchange */
891 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
892 printk(KERN_DEBUG
"STA " MAC_FMT
" aid %d: PS Poll (entries "
894 MAC_ARG(rx
->sta
->addr
), rx
->sta
->aid
,
895 skb_queue_len(&rx
->sta
->ps_tx_buf
));
896 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
898 /* Use MoreData flag to indicate whether there are more
899 * buffered frames for this STA */
900 if (no_pending_pkts
) {
901 hdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_MOREDATA
);
902 rx
->sta
->flags
&= ~WLAN_STA_TIM
;
904 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
908 if (no_pending_pkts
) {
909 if (rx
->local
->ops
->set_tim
)
910 rx
->local
->ops
->set_tim(local_to_hw(rx
->local
),
913 bss_tim_clear(rx
->local
, rx
->sdata
->bss
, rx
->sta
->aid
);
915 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
916 } else if (!rx
->u
.rx
.sent_ps_buffered
) {
917 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" sent PS Poll even "
918 "though there is no buffered frames for it\n",
919 rx
->dev
->name
, MAC_ARG(rx
->sta
->addr
));
920 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
924 /* Free PS Poll skb here instead of returning TXRX_DROP that would
925 * count as an dropped frame. */
926 dev_kfree_skb(rx
->skb
);
931 static ieee80211_txrx_result
932 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data
*rx
)
935 u8
*data
= rx
->skb
->data
;
936 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) data
;
938 if (!WLAN_FC_IS_QOS_DATA(fc
))
939 return TXRX_CONTINUE
;
941 /* remove the qos control field, update frame type and meta-data */
942 memmove(data
+ 2, data
, ieee80211_get_hdrlen(fc
) - 2);
943 hdr
= (struct ieee80211_hdr
*) skb_pull(rx
->skb
, 2);
944 /* change frame type to non QOS */
945 rx
->fc
= fc
&= ~IEEE80211_STYPE_QOS_DATA
;
946 hdr
->frame_control
= cpu_to_le16(fc
);
948 return TXRX_CONTINUE
;
951 static ieee80211_txrx_result
952 ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data
*rx
)
954 if (rx
->sdata
->eapol
&& ieee80211_is_eapol(rx
->skb
) &&
955 rx
->sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
956 (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
957 return TXRX_CONTINUE
;
959 if (unlikely(rx
->sdata
->ieee802_1x
&&
960 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
961 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
962 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_AUTHORIZED
)) &&
963 !ieee80211_is_eapol(rx
->skb
))) {
964 #ifdef CONFIG_MAC80211_DEBUG
965 struct ieee80211_hdr
*hdr
=
966 (struct ieee80211_hdr
*) rx
->skb
->data
;
967 printk(KERN_DEBUG
"%s: dropped frame from " MAC_FMT
968 " (unauthorized port)\n", rx
->dev
->name
,
969 MAC_ARG(hdr
->addr2
));
970 #endif /* CONFIG_MAC80211_DEBUG */
974 return TXRX_CONTINUE
;
977 static ieee80211_txrx_result
978 ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data
*rx
)
981 * Pass through unencrypted frames if the hardware has
982 * decrypted them already.
984 if (rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
)
985 return TXRX_CONTINUE
;
987 /* Drop unencrypted frames if key is set. */
988 if (unlikely(!(rx
->fc
& IEEE80211_FCTL_PROTECTED
) &&
989 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
990 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
991 rx
->sdata
->drop_unencrypted
&&
992 (rx
->sdata
->eapol
== 0 || !ieee80211_is_eapol(rx
->skb
)))) {
994 printk(KERN_DEBUG
"%s: RX non-WEP frame, but expected "
995 "encryption\n", rx
->dev
->name
);
998 return TXRX_CONTINUE
;
1001 static ieee80211_txrx_result
1002 ieee80211_rx_h_data(struct ieee80211_txrx_data
*rx
)
1004 struct net_device
*dev
= rx
->dev
;
1005 struct ieee80211_local
*local
= rx
->local
;
1006 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
1007 u16 fc
, hdrlen
, ethertype
;
1011 struct sk_buff
*skb
= rx
->skb
, *skb2
;
1012 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1015 if (unlikely((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
))
1016 return TXRX_CONTINUE
;
1018 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
1021 hdrlen
= ieee80211_get_hdrlen(fc
);
1023 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1025 * IEEE 802.11 address fields:
1026 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1027 * 0 0 DA SA BSSID n/a
1028 * 0 1 DA BSSID SA n/a
1029 * 1 0 BSSID SA DA n/a
1033 switch (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
1034 case IEEE80211_FCTL_TODS
:
1036 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1037 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1039 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_AP
&&
1040 sdata
->type
!= IEEE80211_IF_TYPE_VLAN
)) {
1041 if (net_ratelimit())
1042 printk(KERN_DEBUG
"%s: dropped ToDS frame "
1045 " DA=" MAC_FMT
")\n",
1047 MAC_ARG(hdr
->addr1
),
1048 MAC_ARG(hdr
->addr2
),
1049 MAC_ARG(hdr
->addr3
));
1053 case (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
1055 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1056 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
1058 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_WDS
)) {
1059 if (net_ratelimit())
1060 printk(KERN_DEBUG
"%s: dropped FromDS&ToDS "
1061 "frame (RA=" MAC_FMT
1062 " TA=" MAC_FMT
" DA=" MAC_FMT
1063 " SA=" MAC_FMT
")\n",
1065 MAC_ARG(hdr
->addr1
),
1066 MAC_ARG(hdr
->addr2
),
1067 MAC_ARG(hdr
->addr3
),
1068 MAC_ARG(hdr
->addr4
));
1072 case IEEE80211_FCTL_FROMDS
:
1074 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1075 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
1077 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
||
1078 (is_multicast_ether_addr(dst
) &&
1079 !compare_ether_addr(src
, dev
->dev_addr
)))
1084 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1085 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1087 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
1088 if (net_ratelimit()) {
1089 printk(KERN_DEBUG
"%s: dropped IBSS frame (DA="
1090 MAC_FMT
" SA=" MAC_FMT
" BSSID=" MAC_FMT
1092 dev
->name
, MAC_ARG(hdr
->addr1
),
1093 MAC_ARG(hdr
->addr2
),
1094 MAC_ARG(hdr
->addr3
));
1101 payload
= skb
->data
+ hdrlen
;
1103 if (unlikely(skb
->len
- hdrlen
< 8)) {
1104 if (net_ratelimit()) {
1105 printk(KERN_DEBUG
"%s: RX too short data frame "
1106 "payload\n", dev
->name
);
1111 ethertype
= (payload
[6] << 8) | payload
[7];
1113 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
1114 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1115 compare_ether_addr(payload
, bridge_tunnel_header
) == 0)) {
1116 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1117 * replace EtherType */
1118 skb_pull(skb
, hdrlen
+ 6);
1119 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
1120 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1122 struct ethhdr
*ehdr
;
1124 skb_pull(skb
, hdrlen
);
1125 len
= htons(skb
->len
);
1126 ehdr
= (struct ethhdr
*) skb_push(skb
, sizeof(struct ethhdr
));
1127 memcpy(ehdr
->h_dest
, dst
, ETH_ALEN
);
1128 memcpy(ehdr
->h_source
, src
, ETH_ALEN
);
1129 ehdr
->h_proto
= len
;
1135 dev
->stats
.rx_packets
++;
1136 dev
->stats
.rx_bytes
+= skb
->len
;
1138 if (local
->bridge_packets
&& (sdata
->type
== IEEE80211_IF_TYPE_AP
1139 || sdata
->type
== IEEE80211_IF_TYPE_VLAN
) &&
1140 (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)) {
1141 if (is_multicast_ether_addr(skb
->data
)) {
1142 /* send multicast frames both to higher layers in
1143 * local net stack and back to the wireless media */
1144 skb2
= skb_copy(skb
, GFP_ATOMIC
);
1145 if (!skb2
&& net_ratelimit())
1146 printk(KERN_DEBUG
"%s: failed to clone "
1147 "multicast frame\n", dev
->name
);
1149 struct sta_info
*dsta
;
1150 dsta
= sta_info_get(local
, skb
->data
);
1151 if (dsta
&& !dsta
->dev
) {
1152 if (net_ratelimit())
1153 printk(KERN_DEBUG
"Station with null "
1154 "dev structure!\n");
1155 } else if (dsta
&& dsta
->dev
== dev
) {
1156 /* Destination station is associated to this
1157 * AP, so send the frame directly to it and
1158 * do not pass the frame to local net stack.
1169 /* deliver to local stack */
1170 skb
->protocol
= eth_type_trans(skb
, dev
);
1171 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1176 /* send to wireless media */
1177 skb2
->protocol
= __constant_htons(ETH_P_802_3
);
1178 skb_set_network_header(skb2
, 0);
1179 skb_set_mac_header(skb2
, 0);
1180 dev_queue_xmit(skb2
);
1186 static ieee80211_txrx_result
1187 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data
*rx
)
1189 struct ieee80211_sub_if_data
*sdata
;
1191 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
1194 sdata
= IEEE80211_DEV_TO_SUB_IF(rx
->dev
);
1195 if ((sdata
->type
== IEEE80211_IF_TYPE_STA
||
1196 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) &&
1197 !(sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
))
1198 ieee80211_sta_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
1205 static inline ieee80211_txrx_result
__ieee80211_invoke_rx_handlers(
1206 struct ieee80211_local
*local
,
1207 ieee80211_rx_handler
*handlers
,
1208 struct ieee80211_txrx_data
*rx
,
1209 struct sta_info
*sta
)
1211 ieee80211_rx_handler
*handler
;
1212 ieee80211_txrx_result res
= TXRX_DROP
;
1214 for (handler
= handlers
; *handler
!= NULL
; handler
++) {
1215 res
= (*handler
)(rx
);
1221 I802_DEBUG_INC(local
->rx_handlers_drop
);
1226 I802_DEBUG_INC(local
->rx_handlers_queued
);
1232 if (res
== TXRX_DROP
)
1233 dev_kfree_skb(rx
->skb
);
1237 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local
*local
,
1238 ieee80211_rx_handler
*handlers
,
1239 struct ieee80211_txrx_data
*rx
,
1240 struct sta_info
*sta
)
1242 if (__ieee80211_invoke_rx_handlers(local
, handlers
, rx
, sta
) ==
1244 dev_kfree_skb(rx
->skb
);
1247 static void ieee80211_rx_michael_mic_report(struct net_device
*dev
,
1248 struct ieee80211_hdr
*hdr
,
1249 struct sta_info
*sta
,
1250 struct ieee80211_txrx_data
*rx
)
1254 hdrlen
= ieee80211_get_hdrlen_from_skb(rx
->skb
);
1255 if (rx
->skb
->len
>= hdrlen
+ 4)
1256 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
1260 if (net_ratelimit())
1261 printk(KERN_DEBUG
"%s: TKIP hwaccel reported Michael MIC "
1262 "failure from " MAC_FMT
" to " MAC_FMT
" keyidx=%d\n",
1263 dev
->name
, MAC_ARG(hdr
->addr2
), MAC_ARG(hdr
->addr1
),
1268 * Some hardware seem to generate incorrect Michael MIC
1269 * reports; ignore them to avoid triggering countermeasures.
1271 if (net_ratelimit())
1272 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1273 "error for unknown address " MAC_FMT
"\n",
1274 dev
->name
, MAC_ARG(hdr
->addr2
));
1278 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
1279 if (net_ratelimit())
1280 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1281 "error for a frame with no PROTECTED flag (src "
1282 MAC_FMT
")\n", dev
->name
, MAC_ARG(hdr
->addr2
));
1286 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_AP
&& keyidx
) {
1288 * APs with pairwise keys should never receive Michael MIC
1289 * errors for non-zero keyidx because these are reserved for
1290 * group keys and only the AP is sending real multicast
1291 * frames in the BSS.
1293 if (net_ratelimit())
1294 printk(KERN_DEBUG
"%s: ignored Michael MIC error for "
1295 "a frame with non-zero keyidx (%d)"
1296 " (src " MAC_FMT
")\n", dev
->name
, keyidx
,
1297 MAC_ARG(hdr
->addr2
));
1301 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
1302 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
1303 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)) {
1304 if (net_ratelimit())
1305 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1306 "error for a frame that cannot be encrypted "
1307 "(fc=0x%04x) (src " MAC_FMT
")\n",
1308 dev
->name
, rx
->fc
, MAC_ARG(hdr
->addr2
));
1312 mac80211_ev_michael_mic_failure(rx
->dev
, keyidx
, hdr
);
1314 dev_kfree_skb(rx
->skb
);
1318 ieee80211_rx_handler ieee80211_rx_handlers
[] =
1320 ieee80211_rx_h_if_stats
,
1321 ieee80211_rx_h_passive_scan
,
1322 ieee80211_rx_h_check
,
1323 ieee80211_rx_h_decrypt
,
1324 ieee80211_rx_h_sta_process
,
1325 ieee80211_rx_h_defragment
,
1326 ieee80211_rx_h_ps_poll
,
1327 ieee80211_rx_h_michael_mic_verify
,
1328 /* this must be after decryption - so header is counted in MPDU mic
1329 * must be before pae and data, so QOS_DATA format frames
1330 * are not passed to user space by these functions
1332 ieee80211_rx_h_remove_qos_control
,
1333 ieee80211_rx_h_802_1x_pae
,
1334 ieee80211_rx_h_drop_unencrypted
,
1335 ieee80211_rx_h_data
,
1336 ieee80211_rx_h_mgmt
,
1340 /* main receive path */
1342 static int prepare_for_handlers(struct ieee80211_sub_if_data
*sdata
,
1343 u8
*bssid
, struct ieee80211_txrx_data
*rx
,
1344 struct ieee80211_hdr
*hdr
)
1346 int multicast
= is_multicast_ether_addr(hdr
->addr1
);
1348 switch (sdata
->type
) {
1349 case IEEE80211_IF_TYPE_STA
:
1352 if (!ieee80211_bssid_match(bssid
, sdata
->u
.sta
.bssid
)) {
1353 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1355 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1356 } else if (!multicast
&&
1357 compare_ether_addr(sdata
->dev
->dev_addr
,
1359 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
1361 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1364 case IEEE80211_IF_TYPE_IBSS
:
1367 if (!ieee80211_bssid_match(bssid
, sdata
->u
.sta
.bssid
)) {
1368 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1370 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1371 } else if (!multicast
&&
1372 compare_ether_addr(sdata
->dev
->dev_addr
,
1374 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
1376 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1377 } else if (!rx
->sta
)
1378 rx
->sta
= ieee80211_ibss_add_sta(sdata
->dev
, rx
->skb
,
1381 case IEEE80211_IF_TYPE_VLAN
:
1382 case IEEE80211_IF_TYPE_AP
:
1384 if (compare_ether_addr(sdata
->dev
->dev_addr
,
1387 } else if (!ieee80211_bssid_match(bssid
,
1388 sdata
->dev
->dev_addr
)) {
1389 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1391 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1393 if (sdata
->dev
== sdata
->local
->mdev
&&
1394 !(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1395 /* do not receive anything via
1396 * master device when not scanning */
1399 case IEEE80211_IF_TYPE_WDS
:
1401 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
)
1403 if (compare_ether_addr(sdata
->u
.wds
.remote_addr
, hdr
->addr2
))
1406 case IEEE80211_IF_TYPE_MNTR
:
1407 /* take everything */
1409 case IEEE80211_IF_TYPE_INVALID
:
1410 /* should never get here */
1419 * This is the receive path handler. It is called by a low level driver when an
1420 * 802.11 MPDU is received from the hardware.
1422 void __ieee80211_rx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1423 struct ieee80211_rx_status
*status
)
1425 struct ieee80211_local
*local
= hw_to_local(hw
);
1426 struct ieee80211_sub_if_data
*sdata
;
1427 struct sta_info
*sta
;
1428 struct ieee80211_hdr
*hdr
;
1429 struct ieee80211_txrx_data rx
;
1432 struct ieee80211_sub_if_data
*prev
= NULL
;
1433 struct sk_buff
*skb_new
;
1437 * key references and virtual interfaces are protected using RCU
1438 * and this requires that we are in a read-side RCU section during
1439 * receive processing
1444 * Frames with failed FCS/PLCP checksum are not returned,
1445 * all other frames are returned without radiotap header
1446 * if it was previously present.
1447 * Also, frames with less than 16 bytes are dropped.
1449 skb
= ieee80211_rx_monitor(local
, skb
, status
);
1455 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1456 memset(&rx
, 0, sizeof(rx
));
1460 rx
.u
.rx
.status
= status
;
1461 rx
.fc
= le16_to_cpu(hdr
->frame_control
);
1462 type
= rx
.fc
& IEEE80211_FCTL_FTYPE
;
1464 if (type
== IEEE80211_FTYPE_DATA
|| type
== IEEE80211_FTYPE_MGMT
)
1465 local
->dot11ReceivedFragmentCount
++;
1467 sta
= rx
.sta
= sta_info_get(local
, hdr
->addr2
);
1469 rx
.dev
= rx
.sta
->dev
;
1470 rx
.sdata
= IEEE80211_DEV_TO_SUB_IF(rx
.dev
);
1473 if ((status
->flag
& RX_FLAG_MMIC_ERROR
)) {
1474 ieee80211_rx_michael_mic_report(local
->mdev
, hdr
, sta
, &rx
);
1478 if (unlikely(local
->sta_scanning
))
1479 rx
.flags
|= IEEE80211_TXRXD_RXIN_SCAN
;
1481 if (__ieee80211_invoke_rx_handlers(local
, local
->rx_pre_handlers
, &rx
,
1482 sta
) != TXRX_CONTINUE
)
1486 if (sta
&& !(sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_ASSOC_AP
)) &&
1487 !atomic_read(&local
->iff_promiscs
) &&
1488 !is_multicast_ether_addr(hdr
->addr1
)) {
1489 rx
.flags
|= IEEE80211_TXRXD_RXRA_MATCH
;
1490 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
, &rx
,
1497 bssid
= ieee80211_get_bssid(hdr
, skb
->len
);
1499 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1500 if (!netif_running(sdata
->dev
))
1503 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
1506 rx
.flags
|= IEEE80211_TXRXD_RXRA_MATCH
;
1507 prepres
= prepare_for_handlers(sdata
, bssid
, &rx
, hdr
);
1508 /* prepare_for_handlers can change sta */
1515 * frame is destined for this interface, but if it's not
1516 * also for the previous one we handle that after the
1517 * loop to avoid copying the SKB once too much
1526 * frame was destined for the previous interface
1527 * so invoke RX handlers for it
1530 skb_new
= skb_copy(skb
, GFP_ATOMIC
);
1532 if (net_ratelimit())
1533 printk(KERN_DEBUG
"%s: failed to copy "
1534 "multicast frame for %s",
1535 wiphy_name(local
->hw
.wiphy
),
1542 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
1550 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
1561 EXPORT_SYMBOL(__ieee80211_rx
);
1563 /* This is a version of the rx handler that can be called from hard irq
1564 * context. Post the skb on the queue and schedule the tasklet */
1565 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1566 struct ieee80211_rx_status
*status
)
1568 struct ieee80211_local
*local
= hw_to_local(hw
);
1570 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
));
1572 skb
->dev
= local
->mdev
;
1573 /* copy status into skb->cb for use by tasklet */
1574 memcpy(skb
->cb
, status
, sizeof(*status
));
1575 skb
->pkt_type
= IEEE80211_RX_MSG
;
1576 skb_queue_tail(&local
->skb_queue
, skb
);
1577 tasklet_schedule(&local
->tasklet
);
1579 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);