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
;
246 if (qc
[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
)
247 rx
->flags
|= IEEE80211_TXRXD_RX_AMSDU
;
249 rx
->flags
&= ~IEEE80211_TXRXD_RX_AMSDU
;
251 if (unlikely((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)) {
252 /* Separate TID for management frames */
253 tid
= NUM_RX_DATA_QUEUES
- 1;
255 /* no qos control present */
256 tid
= 0; /* 802.1d - Best Effort */
260 I802_DEBUG_INC(rx
->local
->wme_rx_queue
[tid
]);
261 /* only a debug counter, sta might not be assigned properly yet */
263 I802_DEBUG_INC(rx
->sta
->wme_rx_queue
[tid
]);
265 rx
->u
.rx
.queue
= tid
;
266 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
267 * For now, set skb->priority to 0 for other cases. */
268 rx
->skb
->priority
= (tid
> 7) ? 0 : tid
;
270 return TXRX_CONTINUE
;
273 static ieee80211_txrx_result
274 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data
*rx
)
276 struct ieee80211_local
*local
= rx
->local
;
277 struct sk_buff
*skb
= rx
->skb
;
278 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
279 u32 load
= 0, hdrtime
;
280 struct ieee80211_rate
*rate
;
281 struct ieee80211_hw_mode
*mode
= local
->hw
.conf
.mode
;
284 /* Estimate total channel use caused by this frame */
286 if (unlikely(mode
->num_rates
< 0))
287 return TXRX_CONTINUE
;
289 rate
= &mode
->rates
[0];
290 for (i
= 0; i
< mode
->num_rates
; i
++) {
291 if (mode
->rates
[i
].val
== rx
->u
.rx
.status
->rate
) {
292 rate
= &mode
->rates
[i
];
297 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
298 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
300 if (mode
->mode
== MODE_IEEE80211A
||
301 (mode
->mode
== MODE_IEEE80211G
&&
302 rate
->flags
& IEEE80211_RATE_ERP
))
303 hdrtime
= CHAN_UTIL_HDR_SHORT
;
305 hdrtime
= CHAN_UTIL_HDR_LONG
;
308 if (!is_multicast_ether_addr(hdr
->addr1
))
311 load
+= skb
->len
* rate
->rate_inv
;
313 /* Divide channel_use by 8 to avoid wrapping around the counter */
314 load
>>= CHAN_UTIL_SHIFT
;
315 local
->channel_use_raw
+= load
;
316 rx
->u
.rx
.load
= load
;
318 return TXRX_CONTINUE
;
321 ieee80211_rx_handler ieee80211_rx_pre_handlers
[] =
323 ieee80211_rx_h_parse_qos
,
324 ieee80211_rx_h_load_stats
,
330 static ieee80211_txrx_result
331 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data
*rx
)
334 rx
->sta
->channel_use_raw
+= rx
->u
.rx
.load
;
335 rx
->sdata
->channel_use_raw
+= rx
->u
.rx
.load
;
336 return TXRX_CONTINUE
;
339 static ieee80211_txrx_result
340 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data
*rx
)
342 struct ieee80211_local
*local
= rx
->local
;
343 struct sk_buff
*skb
= rx
->skb
;
345 if (unlikely(local
->sta_hw_scanning
))
346 return ieee80211_sta_rx_scan(rx
->dev
, skb
, rx
->u
.rx
.status
);
348 if (unlikely(local
->sta_sw_scanning
)) {
349 /* drop all the other packets during a software scan anyway */
350 if (ieee80211_sta_rx_scan(rx
->dev
, skb
, rx
->u
.rx
.status
)
356 if (unlikely(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
)) {
357 /* scanning finished during invoking of handlers */
358 I802_DEBUG_INC(local
->rx_handlers_drop_passive_scan
);
362 return TXRX_CONTINUE
;
365 static ieee80211_txrx_result
366 ieee80211_rx_h_check(struct ieee80211_txrx_data
*rx
)
368 struct ieee80211_hdr
*hdr
;
369 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
371 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
372 if (rx
->sta
&& !is_multicast_ether_addr(hdr
->addr1
)) {
373 if (unlikely(rx
->fc
& IEEE80211_FCTL_RETRY
&&
374 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] ==
376 if (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
) {
377 rx
->local
->dot11FrameDuplicateCount
++;
378 rx
->sta
->num_duplicates
++;
382 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] = hdr
->seq_ctrl
;
385 if (unlikely(rx
->skb
->len
< 16)) {
386 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_short
);
390 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
391 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
392 else if (compare_ether_addr(rx
->dev
->dev_addr
, hdr
->addr1
) == 0)
393 rx
->skb
->pkt_type
= PACKET_HOST
;
394 else if (is_multicast_ether_addr(hdr
->addr1
)) {
395 if (is_broadcast_ether_addr(hdr
->addr1
))
396 rx
->skb
->pkt_type
= PACKET_BROADCAST
;
398 rx
->skb
->pkt_type
= PACKET_MULTICAST
;
400 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
402 /* Drop disallowed frame classes based on STA auth/assoc state;
403 * IEEE 802.11, Chap 5.5.
405 * 80211.o does filtering only based on association state, i.e., it
406 * drops Class 3 frames from not associated stations. hostapd sends
407 * deauth/disassoc frames when needed. In addition, hostapd is
408 * responsible for filtering on both auth and assoc states.
410 if (unlikely(((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
||
411 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
&&
412 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PSPOLL
)) &&
413 rx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
414 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_ASSOC
)))) {
415 if ((!(rx
->fc
& IEEE80211_FCTL_FROMDS
) &&
416 !(rx
->fc
& IEEE80211_FCTL_TODS
) &&
417 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)
418 || !(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)) {
419 /* Drop IBSS frames and frames for other hosts
427 return TXRX_CONTINUE
;
431 static ieee80211_txrx_result
432 ieee80211_rx_h_decrypt(struct ieee80211_txrx_data
*rx
)
434 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
437 ieee80211_txrx_result result
= TXRX_DROP
;
438 struct ieee80211_key
*stakey
= NULL
;
443 * There are three types of keys:
445 * - PTK (pairwise keys)
446 * - STK (station-to-station pairwise keys)
448 * When selecting a key, we have to distinguish between multicast
449 * (including broadcast) and unicast frames, the latter can only
450 * use PTKs and STKs while the former always use GTKs. Unless, of
451 * course, actual WEP keys ("pre-RSNA") are used, then unicast
452 * frames can also use key indizes like GTKs. Hence, if we don't
453 * have a PTK/STK we check the key index for a WEP key.
455 * Note that in a regular BSS, multicast frames are sent by the
456 * AP only, associated stations unicast the frame to the AP first
457 * which then multicasts it on their behalf.
459 * There is also a slight problem in IBSS mode: GTKs are negotiated
460 * with each station, that is something we don't currently handle.
461 * The spec seems to expect that one negotiates the same key with
462 * every station but there's no such requirement; VLANs could be
466 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
))
467 return TXRX_CONTINUE
;
470 * No point in finding a key and decrypting if the frame is neither
471 * addressed to us nor a multicast frame.
473 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
474 return TXRX_CONTINUE
;
477 stakey
= rcu_dereference(rx
->sta
->key
);
479 if (!is_multicast_ether_addr(hdr
->addr1
) && stakey
) {
483 * The device doesn't give us the IV so we won't be
484 * able to look up the key. That's ok though, we
485 * don't need to decrypt the frame, we just won't
486 * be able to keep statistics accurate.
487 * Except for key threshold notifications, should
488 * we somehow allow the driver to tell us which key
489 * the hardware used if this flag is set?
491 if ((rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
) &&
492 (rx
->u
.rx
.status
->flag
& RX_FLAG_IV_STRIPPED
))
493 return TXRX_CONTINUE
;
495 hdrlen
= ieee80211_get_hdrlen(rx
->fc
);
497 if (rx
->skb
->len
< 8 + hdrlen
)
498 return TXRX_DROP
; /* TODO: count this? */
501 * no need to call ieee80211_wep_get_keyidx,
502 * it verifies a bunch of things we've done already
504 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
506 rx
->key
= rcu_dereference(rx
->sdata
->keys
[keyidx
]);
509 * RSNA-protected unicast frames should always be sent with
510 * pairwise or station-to-station keys, but for WEP we allow
511 * using a key index as well.
513 if (rx
->key
&& rx
->key
->conf
.alg
!= ALG_WEP
&&
514 !is_multicast_ether_addr(hdr
->addr1
))
519 rx
->key
->tx_rx_count
++;
520 /* TODO: add threshold stuff again */
522 #ifdef CONFIG_MAC80211_DEBUG
524 printk(KERN_DEBUG
"%s: RX protected frame,"
525 " but have no key\n", rx
->dev
->name
);
526 #endif /* CONFIG_MAC80211_DEBUG */
530 /* Check for weak IVs if possible */
531 if (rx
->sta
&& rx
->key
->conf
.alg
== ALG_WEP
&&
532 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
533 (!(rx
->u
.rx
.status
->flag
& RX_FLAG_IV_STRIPPED
) ||
534 !(rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
)) &&
535 ieee80211_wep_is_weak_iv(rx
->skb
, rx
->key
))
536 rx
->sta
->wep_weak_iv_count
++;
538 switch (rx
->key
->conf
.alg
) {
540 result
= ieee80211_crypto_wep_decrypt(rx
);
543 result
= ieee80211_crypto_tkip_decrypt(rx
);
546 result
= ieee80211_crypto_ccmp_decrypt(rx
);
550 /* either the frame has been decrypted or will be dropped */
551 rx
->u
.rx
.status
->flag
|= RX_FLAG_DECRYPTED
;
556 static void ap_sta_ps_start(struct net_device
*dev
, struct sta_info
*sta
)
558 struct ieee80211_sub_if_data
*sdata
;
559 DECLARE_MAC_BUF(mac
);
561 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
564 atomic_inc(&sdata
->bss
->num_sta_ps
);
565 sta
->flags
|= WLAN_STA_PS
;
567 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
568 printk(KERN_DEBUG
"%s: STA %s aid %d enters power save mode\n",
569 dev
->name
, print_mac(mac
, sta
->addr
), sta
->aid
);
570 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
573 static int ap_sta_ps_end(struct net_device
*dev
, struct sta_info
*sta
)
575 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
578 struct ieee80211_sub_if_data
*sdata
;
579 struct ieee80211_tx_packet_data
*pkt_data
;
580 DECLARE_MAC_BUF(mac
);
582 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
584 atomic_dec(&sdata
->bss
->num_sta_ps
);
585 sta
->flags
&= ~(WLAN_STA_PS
| WLAN_STA_TIM
);
587 if (!skb_queue_empty(&sta
->ps_tx_buf
)) {
588 if (local
->ops
->set_tim
)
589 local
->ops
->set_tim(local_to_hw(local
), sta
->aid
, 0);
591 bss_tim_clear(local
, sdata
->bss
, sta
->aid
);
593 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
594 printk(KERN_DEBUG
"%s: STA %s aid %d exits power save mode\n",
595 dev
->name
, print_mac(mac
, sta
->addr
), sta
->aid
);
596 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
597 /* Send all buffered frames to the station */
598 while ((skb
= skb_dequeue(&sta
->tx_filtered
)) != NULL
) {
599 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
601 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
604 while ((skb
= skb_dequeue(&sta
->ps_tx_buf
)) != NULL
) {
605 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
606 local
->total_ps_buffered
--;
608 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
609 printk(KERN_DEBUG
"%s: STA %s aid %d send PS frame "
610 "since STA not sleeping anymore\n", dev
->name
,
611 print_mac(mac
, sta
->addr
), sta
->aid
);
612 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
613 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
620 static ieee80211_txrx_result
621 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data
*rx
)
623 struct sta_info
*sta
= rx
->sta
;
624 struct net_device
*dev
= rx
->dev
;
625 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
628 return TXRX_CONTINUE
;
630 /* Update last_rx only for IBSS packets which are for the current
631 * BSSID to avoid keeping the current IBSS network alive in cases where
632 * other STAs are using different BSSID. */
633 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
634 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
);
635 if (compare_ether_addr(bssid
, rx
->sdata
->u
.sta
.bssid
) == 0)
636 sta
->last_rx
= jiffies
;
638 if (!is_multicast_ether_addr(hdr
->addr1
) ||
639 rx
->sdata
->type
== IEEE80211_IF_TYPE_STA
) {
640 /* Update last_rx only for unicast frames in order to prevent
641 * the Probe Request frames (the only broadcast frames from a
642 * STA in infrastructure mode) from keeping a connection alive.
644 sta
->last_rx
= jiffies
;
647 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
648 return TXRX_CONTINUE
;
651 sta
->rx_bytes
+= rx
->skb
->len
;
652 sta
->last_rssi
= rx
->u
.rx
.status
->ssi
;
653 sta
->last_signal
= rx
->u
.rx
.status
->signal
;
654 sta
->last_noise
= rx
->u
.rx
.status
->noise
;
656 if (!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
)) {
657 /* Change STA power saving mode only in the end of a frame
658 * exchange sequence */
659 if ((sta
->flags
& WLAN_STA_PS
) && !(rx
->fc
& IEEE80211_FCTL_PM
))
660 rx
->u
.rx
.sent_ps_buffered
+= ap_sta_ps_end(dev
, sta
);
661 else if (!(sta
->flags
& WLAN_STA_PS
) &&
662 (rx
->fc
& IEEE80211_FCTL_PM
))
663 ap_sta_ps_start(dev
, sta
);
666 /* Drop data::nullfunc frames silently, since they are used only to
667 * control station power saving mode. */
668 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
669 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_NULLFUNC
) {
670 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
671 /* Update counter and free packet here to avoid counting this
672 * as a dropped packed. */
674 dev_kfree_skb(rx
->skb
);
678 return TXRX_CONTINUE
;
679 } /* ieee80211_rx_h_sta_process */
681 static inline struct ieee80211_fragment_entry
*
682 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
683 unsigned int frag
, unsigned int seq
, int rx_queue
,
684 struct sk_buff
**skb
)
686 struct ieee80211_fragment_entry
*entry
;
689 idx
= sdata
->fragment_next
;
690 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
691 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
692 sdata
->fragment_next
= 0;
694 if (!skb_queue_empty(&entry
->skb_list
)) {
695 #ifdef CONFIG_MAC80211_DEBUG
696 struct ieee80211_hdr
*hdr
=
697 (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
698 DECLARE_MAC_BUF(mac
);
699 DECLARE_MAC_BUF(mac2
);
700 printk(KERN_DEBUG
"%s: RX reassembly removed oldest "
701 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
702 "addr1=%s addr2=%s\n",
703 sdata
->dev
->name
, idx
,
704 jiffies
- entry
->first_frag_time
, entry
->seq
,
705 entry
->last_frag
, print_mac(mac
, hdr
->addr1
),
706 print_mac(mac2
, hdr
->addr2
));
707 #endif /* CONFIG_MAC80211_DEBUG */
708 __skb_queue_purge(&entry
->skb_list
);
711 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
713 entry
->first_frag_time
= jiffies
;
715 entry
->rx_queue
= rx_queue
;
716 entry
->last_frag
= frag
;
718 entry
->extra_len
= 0;
723 static inline struct ieee80211_fragment_entry
*
724 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
725 u16 fc
, unsigned int frag
, unsigned int seq
,
726 int rx_queue
, struct ieee80211_hdr
*hdr
)
728 struct ieee80211_fragment_entry
*entry
;
731 idx
= sdata
->fragment_next
;
732 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
733 struct ieee80211_hdr
*f_hdr
;
738 idx
= IEEE80211_FRAGMENT_MAX
- 1;
740 entry
= &sdata
->fragments
[idx
];
741 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
742 entry
->rx_queue
!= rx_queue
||
743 entry
->last_frag
+ 1 != frag
)
746 f_hdr
= (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
747 f_fc
= le16_to_cpu(f_hdr
->frame_control
);
749 if ((fc
& IEEE80211_FCTL_FTYPE
) != (f_fc
& IEEE80211_FCTL_FTYPE
) ||
750 compare_ether_addr(hdr
->addr1
, f_hdr
->addr1
) != 0 ||
751 compare_ether_addr(hdr
->addr2
, f_hdr
->addr2
) != 0)
754 if (entry
->first_frag_time
+ 2 * HZ
< jiffies
) {
755 __skb_queue_purge(&entry
->skb_list
);
764 static ieee80211_txrx_result
765 ieee80211_rx_h_defragment(struct ieee80211_txrx_data
*rx
)
767 struct ieee80211_hdr
*hdr
;
769 unsigned int frag
, seq
;
770 struct ieee80211_fragment_entry
*entry
;
772 DECLARE_MAC_BUF(mac
);
774 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
775 sc
= le16_to_cpu(hdr
->seq_ctrl
);
776 frag
= sc
& IEEE80211_SCTL_FRAG
;
778 if (likely((!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) && frag
== 0) ||
779 (rx
->skb
)->len
< 24 ||
780 is_multicast_ether_addr(hdr
->addr1
))) {
784 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
786 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
789 /* This is the first fragment of a new frame. */
790 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
791 rx
->u
.rx
.queue
, &(rx
->skb
));
792 if (rx
->key
&& rx
->key
->conf
.alg
== ALG_CCMP
&&
793 (rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
794 /* Store CCMP PN so that we can verify that the next
795 * fragment has a sequential PN value. */
797 memcpy(entry
->last_pn
,
798 rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
],
804 /* This is a fragment for a frame that should already be pending in
805 * fragment cache. Add this fragment to the end of the pending entry.
807 entry
= ieee80211_reassemble_find(rx
->sdata
, rx
->fc
, frag
, seq
,
808 rx
->u
.rx
.queue
, hdr
);
810 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
814 /* Verify that MPDUs within one MSDU have sequential PN values.
815 * (IEEE 802.11i, 8.3.3.4.5) */
818 u8 pn
[CCMP_PN_LEN
], *rpn
;
819 if (!rx
->key
|| rx
->key
->conf
.alg
!= ALG_CCMP
)
821 memcpy(pn
, entry
->last_pn
, CCMP_PN_LEN
);
822 for (i
= CCMP_PN_LEN
- 1; i
>= 0; i
--) {
827 rpn
= rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
];
828 if (memcmp(pn
, rpn
, CCMP_PN_LEN
) != 0) {
830 printk(KERN_DEBUG
"%s: defrag: CCMP PN not "
832 " PN=%02x%02x%02x%02x%02x%02x "
833 "(expected %02x%02x%02x%02x%02x%02x)\n",
834 rx
->dev
->name
, print_mac(mac
, hdr
->addr2
),
835 rpn
[0], rpn
[1], rpn
[2], rpn
[3], rpn
[4],
836 rpn
[5], pn
[0], pn
[1], pn
[2], pn
[3],
840 memcpy(entry
->last_pn
, pn
, CCMP_PN_LEN
);
843 skb_pull(rx
->skb
, ieee80211_get_hdrlen(rx
->fc
));
844 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
845 entry
->last_frag
= frag
;
846 entry
->extra_len
+= rx
->skb
->len
;
847 if (rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) {
852 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
853 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
854 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head2
);
855 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
857 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
858 __skb_queue_purge(&entry
->skb_list
);
862 while ((skb
= __skb_dequeue(&entry
->skb_list
))) {
863 memcpy(skb_put(rx
->skb
, skb
->len
), skb
->data
, skb
->len
);
867 /* Complete frame has been reassembled - process it now */
868 rx
->flags
|= IEEE80211_TXRXD_FRAGMENTED
;
872 rx
->sta
->rx_packets
++;
873 if (is_multicast_ether_addr(hdr
->addr1
))
874 rx
->local
->dot11MulticastReceivedFrameCount
++;
876 ieee80211_led_rx(rx
->local
);
877 return TXRX_CONTINUE
;
880 static ieee80211_txrx_result
881 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data
*rx
)
885 DECLARE_MAC_BUF(mac
);
887 if (likely(!rx
->sta
||
888 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_CTL
||
889 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_PSPOLL
||
890 !(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)))
891 return TXRX_CONTINUE
;
893 skb
= skb_dequeue(&rx
->sta
->tx_filtered
);
895 skb
= skb_dequeue(&rx
->sta
->ps_tx_buf
);
897 rx
->local
->total_ps_buffered
--;
899 no_pending_pkts
= skb_queue_empty(&rx
->sta
->tx_filtered
) &&
900 skb_queue_empty(&rx
->sta
->ps_tx_buf
);
903 struct ieee80211_hdr
*hdr
=
904 (struct ieee80211_hdr
*) skb
->data
;
906 /* tell TX path to send one frame even though the STA may
907 * still remain is PS mode after this frame exchange */
910 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
911 printk(KERN_DEBUG
"STA %s aid %d: PS Poll (entries after %d)\n",
912 print_mac(mac
, rx
->sta
->addr
), rx
->sta
->aid
,
913 skb_queue_len(&rx
->sta
->ps_tx_buf
));
914 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
916 /* Use MoreData flag to indicate whether there are more
917 * buffered frames for this STA */
918 if (no_pending_pkts
) {
919 hdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_MOREDATA
);
920 rx
->sta
->flags
&= ~WLAN_STA_TIM
;
922 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
926 if (no_pending_pkts
) {
927 if (rx
->local
->ops
->set_tim
)
928 rx
->local
->ops
->set_tim(local_to_hw(rx
->local
),
931 bss_tim_clear(rx
->local
, rx
->sdata
->bss
, rx
->sta
->aid
);
933 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
934 } else if (!rx
->u
.rx
.sent_ps_buffered
) {
935 printk(KERN_DEBUG
"%s: STA %s sent PS Poll even "
936 "though there is no buffered frames for it\n",
937 rx
->dev
->name
, print_mac(mac
, rx
->sta
->addr
));
938 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
942 /* Free PS Poll skb here instead of returning TXRX_DROP that would
943 * count as an dropped frame. */
944 dev_kfree_skb(rx
->skb
);
949 static ieee80211_txrx_result
950 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data
*rx
)
953 u8
*data
= rx
->skb
->data
;
954 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) data
;
956 if (!WLAN_FC_IS_QOS_DATA(fc
))
957 return TXRX_CONTINUE
;
959 /* remove the qos control field, update frame type and meta-data */
960 memmove(data
+ 2, data
, ieee80211_get_hdrlen(fc
) - 2);
961 hdr
= (struct ieee80211_hdr
*) skb_pull(rx
->skb
, 2);
962 /* change frame type to non QOS */
963 rx
->fc
= fc
&= ~IEEE80211_STYPE_QOS_DATA
;
964 hdr
->frame_control
= cpu_to_le16(fc
);
966 return TXRX_CONTINUE
;
970 ieee80211_drop_802_1x_pae(struct ieee80211_txrx_data
*rx
, int hdrlen
)
972 if (rx
->sdata
->eapol
&& ieee80211_is_eapol(rx
->skb
, hdrlen
) &&
973 rx
->sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
974 (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
977 if (unlikely(rx
->sdata
->ieee802_1x
&&
978 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
979 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
980 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_AUTHORIZED
)) &&
981 !ieee80211_is_eapol(rx
->skb
, hdrlen
))) {
982 #ifdef CONFIG_MAC80211_DEBUG
983 printk(KERN_DEBUG
"%s: dropped frame "
984 "(unauthorized port)\n", rx
->dev
->name
);
985 #endif /* CONFIG_MAC80211_DEBUG */
993 ieee80211_drop_unencrypted(struct ieee80211_txrx_data
*rx
, int hdrlen
)
996 * Pass through unencrypted frames if the hardware has
997 * decrypted them already.
999 if (rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
)
1002 /* Drop unencrypted frames if key is set. */
1003 if (unlikely(!(rx
->fc
& IEEE80211_FCTL_PROTECTED
) &&
1004 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
1005 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
1006 (rx
->key
|| rx
->sdata
->drop_unencrypted
) &&
1007 (rx
->sdata
->eapol
== 0 ||
1008 !ieee80211_is_eapol(rx
->skb
, hdrlen
)))) {
1009 if (net_ratelimit())
1010 printk(KERN_DEBUG
"%s: RX non-WEP frame, but expected "
1011 "encryption\n", rx
->dev
->name
);
1018 ieee80211_data_to_8023(struct ieee80211_txrx_data
*rx
)
1020 struct net_device
*dev
= rx
->dev
;
1021 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
1022 u16 fc
, hdrlen
, ethertype
;
1026 struct sk_buff
*skb
= rx
->skb
;
1027 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1028 DECLARE_MAC_BUF(mac
);
1029 DECLARE_MAC_BUF(mac2
);
1030 DECLARE_MAC_BUF(mac3
);
1031 DECLARE_MAC_BUF(mac4
);
1035 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
1038 hdrlen
= ieee80211_get_hdrlen(fc
);
1040 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1042 * IEEE 802.11 address fields:
1043 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1044 * 0 0 DA SA BSSID n/a
1045 * 0 1 DA BSSID SA n/a
1046 * 1 0 BSSID SA DA n/a
1050 switch (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
1051 case IEEE80211_FCTL_TODS
:
1053 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1054 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1056 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_AP
&&
1057 sdata
->type
!= IEEE80211_IF_TYPE_VLAN
)) {
1058 if (net_ratelimit())
1059 printk(KERN_DEBUG
"%s: dropped ToDS frame "
1060 "(BSSID=%s SA=%s DA=%s)\n",
1062 print_mac(mac
, hdr
->addr1
),
1063 print_mac(mac2
, hdr
->addr2
),
1064 print_mac(mac3
, hdr
->addr3
));
1068 case (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
1070 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
1071 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
1073 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_WDS
)) {
1074 if (net_ratelimit())
1075 printk(KERN_DEBUG
"%s: dropped FromDS&ToDS "
1076 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1078 print_mac(mac
, hdr
->addr1
),
1079 print_mac(mac2
, hdr
->addr2
),
1080 print_mac(mac3
, hdr
->addr3
),
1081 print_mac(mac4
, hdr
->addr4
));
1085 case IEEE80211_FCTL_FROMDS
:
1087 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1088 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
1090 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
||
1091 (is_multicast_ether_addr(dst
) &&
1092 !compare_ether_addr(src
, dev
->dev_addr
)))
1097 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
1098 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
1100 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
1101 if (net_ratelimit()) {
1102 printk(KERN_DEBUG
"%s: dropped IBSS frame "
1103 "(DA=%s SA=%s BSSID=%s)\n",
1105 print_mac(mac
, hdr
->addr1
),
1106 print_mac(mac2
, hdr
->addr2
),
1107 print_mac(mac3
, hdr
->addr3
));
1114 if (unlikely(skb
->len
- hdrlen
< 8)) {
1115 if (net_ratelimit()) {
1116 printk(KERN_DEBUG
"%s: RX too short data frame "
1117 "payload\n", dev
->name
);
1122 payload
= skb
->data
+ hdrlen
;
1123 ethertype
= (payload
[6] << 8) | payload
[7];
1125 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
1126 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1127 compare_ether_addr(payload
, bridge_tunnel_header
) == 0)) {
1128 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1129 * replace EtherType */
1130 skb_pull(skb
, hdrlen
+ 6);
1131 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
1132 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
1134 struct ethhdr
*ehdr
;
1136 skb_pull(skb
, hdrlen
);
1137 len
= htons(skb
->len
);
1138 ehdr
= (struct ethhdr
*) skb_push(skb
, sizeof(struct ethhdr
));
1139 memcpy(ehdr
->h_dest
, dst
, ETH_ALEN
);
1140 memcpy(ehdr
->h_source
, src
, ETH_ALEN
);
1141 ehdr
->h_proto
= len
;
1147 ieee80211_deliver_skb(struct ieee80211_txrx_data
*rx
)
1149 struct net_device
*dev
= rx
->dev
;
1150 struct ieee80211_local
*local
= rx
->local
;
1151 struct sk_buff
*skb
, *xmit_skb
;
1152 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1157 if (local
->bridge_packets
&& (sdata
->type
== IEEE80211_IF_TYPE_AP
1158 || sdata
->type
== IEEE80211_IF_TYPE_VLAN
) &&
1159 (rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
)) {
1160 if (is_multicast_ether_addr(skb
->data
)) {
1161 /* send multicast frames both to higher layers in
1162 * local net stack and back to the wireless media */
1163 xmit_skb
= skb_copy(skb
, GFP_ATOMIC
);
1164 if (!xmit_skb
&& net_ratelimit())
1165 printk(KERN_DEBUG
"%s: failed to clone "
1166 "multicast frame\n", dev
->name
);
1168 struct sta_info
*dsta
;
1169 dsta
= sta_info_get(local
, skb
->data
);
1170 if (dsta
&& !dsta
->dev
) {
1171 if (net_ratelimit())
1172 printk(KERN_DEBUG
"Station with null "
1173 "dev structure!\n");
1174 } else if (dsta
&& dsta
->dev
== dev
) {
1175 /* Destination station is associated to this
1176 * AP, so send the frame directly to it and
1177 * do not pass the frame to local net stack.
1188 /* deliver to local stack */
1189 skb
->protocol
= eth_type_trans(skb
, dev
);
1190 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1195 /* send to wireless media */
1196 xmit_skb
->protocol
= htons(ETH_P_802_3
);
1197 skb_set_network_header(xmit_skb
, 0);
1198 skb_set_mac_header(xmit_skb
, 0);
1199 dev_queue_xmit(xmit_skb
);
1203 static ieee80211_txrx_result
1204 ieee80211_rx_h_amsdu(struct ieee80211_txrx_data
*rx
)
1206 struct net_device
*dev
= rx
->dev
;
1207 struct ieee80211_local
*local
= rx
->local
;
1210 struct sk_buff
*skb
= rx
->skb
, *frame
= NULL
;
1211 const struct ethhdr
*eth
;
1215 DECLARE_MAC_BUF(mac
);
1218 if (unlikely((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
))
1219 return TXRX_CONTINUE
;
1221 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
1224 if (!(rx
->flags
& IEEE80211_TXRXD_RX_AMSDU
))
1225 return TXRX_CONTINUE
;
1227 err
= ieee80211_data_to_8023(rx
);
1233 dev
->stats
.rx_packets
++;
1234 dev
->stats
.rx_bytes
+= skb
->len
;
1236 /* skip the wrapping header */
1237 eth
= (struct ethhdr
*) skb_pull(skb
, sizeof(struct ethhdr
));
1241 while (skb
!= frame
) {
1243 __be16 len
= eth
->h_proto
;
1244 unsigned int subframe_len
= sizeof(struct ethhdr
) + ntohs(len
);
1246 remaining
= skb
->len
;
1247 memcpy(dst
, eth
->h_dest
, ETH_ALEN
);
1248 memcpy(src
, eth
->h_source
, ETH_ALEN
);
1250 padding
= ((4 - subframe_len
) & 0x3);
1251 /* the last MSDU has no padding */
1252 if (subframe_len
> remaining
) {
1253 printk(KERN_DEBUG
"%s: wrong buffer size", dev
->name
);
1257 skb_pull(skb
, sizeof(struct ethhdr
));
1258 /* if last subframe reuse skb */
1259 if (remaining
<= subframe_len
+ padding
)
1262 frame
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
1268 skb_reserve(frame
, local
->hw
.extra_tx_headroom
+
1269 sizeof(struct ethhdr
));
1270 memcpy(skb_put(frame
, ntohs(len
)), skb
->data
,
1273 eth
= (struct ethhdr
*) skb_pull(skb
, ntohs(len
) +
1276 printk(KERN_DEBUG
"%s: wrong buffer size ",
1278 dev_kfree_skb(frame
);
1283 skb_set_network_header(frame
, 0);
1285 frame
->priority
= skb
->priority
;
1288 if ((ieee80211_drop_802_1x_pae(rx
, 0)) ||
1289 (ieee80211_drop_unencrypted(rx
, 0))) {
1290 if (skb
== frame
) /* last frame */
1292 dev_kfree_skb(frame
);
1296 payload
= frame
->data
;
1297 ethertype
= (payload
[6] << 8) | payload
[7];
1299 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
1300 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1301 compare_ether_addr(payload
,
1302 bridge_tunnel_header
) == 0)) {
1303 /* remove RFC1042 or Bridge-Tunnel
1304 * encapsulation and replace EtherType */
1306 memcpy(skb_push(frame
, ETH_ALEN
), src
, ETH_ALEN
);
1307 memcpy(skb_push(frame
, ETH_ALEN
), dst
, ETH_ALEN
);
1309 memcpy(skb_push(frame
, sizeof(__be16
)), &len
,
1311 memcpy(skb_push(frame
, ETH_ALEN
), src
, ETH_ALEN
);
1312 memcpy(skb_push(frame
, ETH_ALEN
), dst
, ETH_ALEN
);
1316 ieee80211_deliver_skb(rx
);
1322 static ieee80211_txrx_result
1323 ieee80211_rx_h_data(struct ieee80211_txrx_data
*rx
)
1325 struct net_device
*dev
= rx
->dev
;
1330 if (unlikely((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
))
1331 return TXRX_CONTINUE
;
1333 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
1336 hdrlen
= ieee80211_get_hdrlen(fc
);
1338 if ((ieee80211_drop_802_1x_pae(rx
, hdrlen
)) ||
1339 (ieee80211_drop_unencrypted(rx
, hdrlen
)))
1342 err
= ieee80211_data_to_8023(rx
);
1348 dev
->stats
.rx_packets
++;
1349 dev
->stats
.rx_bytes
+= rx
->skb
->len
;
1351 ieee80211_deliver_skb(rx
);
1356 static ieee80211_txrx_result
1357 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data
*rx
)
1359 struct ieee80211_sub_if_data
*sdata
;
1361 if (!(rx
->flags
& IEEE80211_TXRXD_RXRA_MATCH
))
1364 sdata
= IEEE80211_DEV_TO_SUB_IF(rx
->dev
);
1365 if ((sdata
->type
== IEEE80211_IF_TYPE_STA
||
1366 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) &&
1367 !(sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
))
1368 ieee80211_sta_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
1375 static inline ieee80211_txrx_result
__ieee80211_invoke_rx_handlers(
1376 struct ieee80211_local
*local
,
1377 ieee80211_rx_handler
*handlers
,
1378 struct ieee80211_txrx_data
*rx
,
1379 struct sta_info
*sta
)
1381 ieee80211_rx_handler
*handler
;
1382 ieee80211_txrx_result res
= TXRX_DROP
;
1384 for (handler
= handlers
; *handler
!= NULL
; handler
++) {
1385 res
= (*handler
)(rx
);
1391 I802_DEBUG_INC(local
->rx_handlers_drop
);
1396 I802_DEBUG_INC(local
->rx_handlers_queued
);
1402 if (res
== TXRX_DROP
)
1403 dev_kfree_skb(rx
->skb
);
1407 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local
*local
,
1408 ieee80211_rx_handler
*handlers
,
1409 struct ieee80211_txrx_data
*rx
,
1410 struct sta_info
*sta
)
1412 if (__ieee80211_invoke_rx_handlers(local
, handlers
, rx
, sta
) ==
1414 dev_kfree_skb(rx
->skb
);
1417 static void ieee80211_rx_michael_mic_report(struct net_device
*dev
,
1418 struct ieee80211_hdr
*hdr
,
1419 struct sta_info
*sta
,
1420 struct ieee80211_txrx_data
*rx
)
1423 DECLARE_MAC_BUF(mac
);
1424 DECLARE_MAC_BUF(mac2
);
1426 hdrlen
= ieee80211_get_hdrlen_from_skb(rx
->skb
);
1427 if (rx
->skb
->len
>= hdrlen
+ 4)
1428 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
1432 if (net_ratelimit())
1433 printk(KERN_DEBUG
"%s: TKIP hwaccel reported Michael MIC "
1434 "failure from %s to %s keyidx=%d\n",
1435 dev
->name
, print_mac(mac
, hdr
->addr2
),
1436 print_mac(mac2
, hdr
->addr1
), keyidx
);
1440 * Some hardware seem to generate incorrect Michael MIC
1441 * reports; ignore them to avoid triggering countermeasures.
1443 if (net_ratelimit())
1444 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1445 "error for unknown address %s\n",
1446 dev
->name
, print_mac(mac
, hdr
->addr2
));
1450 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
1451 if (net_ratelimit())
1452 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1453 "error for a frame with no PROTECTED flag (src "
1454 "%s)\n", dev
->name
, print_mac(mac
, hdr
->addr2
));
1458 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_AP
&& keyidx
) {
1460 * APs with pairwise keys should never receive Michael MIC
1461 * errors for non-zero keyidx because these are reserved for
1462 * group keys and only the AP is sending real multicast
1463 * frames in the BSS.
1465 if (net_ratelimit())
1466 printk(KERN_DEBUG
"%s: ignored Michael MIC error for "
1467 "a frame with non-zero keyidx (%d)"
1468 " (src %s)\n", dev
->name
, keyidx
,
1469 print_mac(mac
, hdr
->addr2
));
1473 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
1474 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
1475 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)) {
1476 if (net_ratelimit())
1477 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
1478 "error for a frame that cannot be encrypted "
1479 "(fc=0x%04x) (src %s)\n",
1480 dev
->name
, rx
->fc
, print_mac(mac
, hdr
->addr2
));
1484 mac80211_ev_michael_mic_failure(rx
->dev
, keyidx
, hdr
);
1486 dev_kfree_skb(rx
->skb
);
1490 ieee80211_rx_handler ieee80211_rx_handlers
[] =
1492 ieee80211_rx_h_if_stats
,
1493 ieee80211_rx_h_passive_scan
,
1494 ieee80211_rx_h_check
,
1495 ieee80211_rx_h_decrypt
,
1496 ieee80211_rx_h_sta_process
,
1497 ieee80211_rx_h_defragment
,
1498 ieee80211_rx_h_ps_poll
,
1499 ieee80211_rx_h_michael_mic_verify
,
1500 /* this must be after decryption - so header is counted in MPDU mic
1501 * must be before pae and data, so QOS_DATA format frames
1502 * are not passed to user space by these functions
1504 ieee80211_rx_h_remove_qos_control
,
1505 ieee80211_rx_h_amsdu
,
1506 ieee80211_rx_h_data
,
1507 ieee80211_rx_h_mgmt
,
1511 /* main receive path */
1513 static int prepare_for_handlers(struct ieee80211_sub_if_data
*sdata
,
1514 u8
*bssid
, struct ieee80211_txrx_data
*rx
,
1515 struct ieee80211_hdr
*hdr
)
1517 int multicast
= is_multicast_ether_addr(hdr
->addr1
);
1519 switch (sdata
->type
) {
1520 case IEEE80211_IF_TYPE_STA
:
1523 if (!ieee80211_bssid_match(bssid
, sdata
->u
.sta
.bssid
)) {
1524 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1526 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1527 } else if (!multicast
&&
1528 compare_ether_addr(sdata
->dev
->dev_addr
,
1530 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
1532 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1535 case IEEE80211_IF_TYPE_IBSS
:
1538 if (!ieee80211_bssid_match(bssid
, sdata
->u
.sta
.bssid
)) {
1539 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1541 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1542 } else if (!multicast
&&
1543 compare_ether_addr(sdata
->dev
->dev_addr
,
1545 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
1547 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1548 } else if (!rx
->sta
)
1549 rx
->sta
= ieee80211_ibss_add_sta(sdata
->dev
, rx
->skb
,
1552 case IEEE80211_IF_TYPE_VLAN
:
1553 case IEEE80211_IF_TYPE_AP
:
1555 if (compare_ether_addr(sdata
->dev
->dev_addr
,
1558 } else if (!ieee80211_bssid_match(bssid
,
1559 sdata
->dev
->dev_addr
)) {
1560 if (!(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1562 rx
->flags
&= ~IEEE80211_TXRXD_RXRA_MATCH
;
1564 if (sdata
->dev
== sdata
->local
->mdev
&&
1565 !(rx
->flags
& IEEE80211_TXRXD_RXIN_SCAN
))
1566 /* do not receive anything via
1567 * master device when not scanning */
1570 case IEEE80211_IF_TYPE_WDS
:
1572 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
)
1574 if (compare_ether_addr(sdata
->u
.wds
.remote_addr
, hdr
->addr2
))
1577 case IEEE80211_IF_TYPE_MNTR
:
1578 /* take everything */
1580 case IEEE80211_IF_TYPE_INVALID
:
1581 /* should never get here */
1590 * This is the receive path handler. It is called by a low level driver when an
1591 * 802.11 MPDU is received from the hardware.
1593 void __ieee80211_rx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1594 struct ieee80211_rx_status
*status
)
1596 struct ieee80211_local
*local
= hw_to_local(hw
);
1597 struct ieee80211_sub_if_data
*sdata
;
1598 struct sta_info
*sta
;
1599 struct ieee80211_hdr
*hdr
;
1600 struct ieee80211_txrx_data rx
;
1603 struct ieee80211_sub_if_data
*prev
= NULL
;
1604 struct sk_buff
*skb_new
;
1609 * key references and virtual interfaces are protected using RCU
1610 * and this requires that we are in a read-side RCU section during
1611 * receive processing
1616 * Frames with failed FCS/PLCP checksum are not returned,
1617 * all other frames are returned without radiotap header
1618 * if it was previously present.
1619 * Also, frames with less than 16 bytes are dropped.
1621 skb
= ieee80211_rx_monitor(local
, skb
, status
);
1627 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1628 memset(&rx
, 0, sizeof(rx
));
1632 rx
.u
.rx
.status
= status
;
1633 rx
.fc
= le16_to_cpu(hdr
->frame_control
);
1634 type
= rx
.fc
& IEEE80211_FCTL_FTYPE
;
1637 * Drivers are required to align the payload data to a four-byte
1638 * boundary, so the last two bits of the address where it starts
1639 * may not be set. The header is required to be directly before
1640 * the payload data, padding like atheros hardware adds which is
1641 * inbetween the 802.11 header and the payload is not supported,
1642 * the driver is required to move the 802.11 header further back
1645 hdrlen
= ieee80211_get_hdrlen(rx
.fc
);
1646 WARN_ON_ONCE(((unsigned long)(skb
->data
+ hdrlen
)) & 3);
1648 if (type
== IEEE80211_FTYPE_DATA
|| type
== IEEE80211_FTYPE_MGMT
)
1649 local
->dot11ReceivedFragmentCount
++;
1651 sta
= rx
.sta
= sta_info_get(local
, hdr
->addr2
);
1653 rx
.dev
= rx
.sta
->dev
;
1654 rx
.sdata
= IEEE80211_DEV_TO_SUB_IF(rx
.dev
);
1657 if ((status
->flag
& RX_FLAG_MMIC_ERROR
)) {
1658 ieee80211_rx_michael_mic_report(local
->mdev
, hdr
, sta
, &rx
);
1662 if (unlikely(local
->sta_sw_scanning
|| local
->sta_hw_scanning
))
1663 rx
.flags
|= IEEE80211_TXRXD_RXIN_SCAN
;
1665 if (__ieee80211_invoke_rx_handlers(local
, local
->rx_pre_handlers
, &rx
,
1666 sta
) != TXRX_CONTINUE
)
1670 if (sta
&& !(sta
->flags
& (WLAN_STA_WDS
| WLAN_STA_ASSOC_AP
)) &&
1671 !atomic_read(&local
->iff_promiscs
) &&
1672 !is_multicast_ether_addr(hdr
->addr1
)) {
1673 rx
.flags
|= IEEE80211_TXRXD_RXRA_MATCH
;
1674 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
, &rx
,
1681 bssid
= ieee80211_get_bssid(hdr
, skb
->len
);
1683 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1684 if (!netif_running(sdata
->dev
))
1687 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
1690 rx
.flags
|= IEEE80211_TXRXD_RXRA_MATCH
;
1691 prepres
= prepare_for_handlers(sdata
, bssid
, &rx
, hdr
);
1692 /* prepare_for_handlers can change sta */
1699 * frame is destined for this interface, but if it's not
1700 * also for the previous one we handle that after the
1701 * loop to avoid copying the SKB once too much
1710 * frame was destined for the previous interface
1711 * so invoke RX handlers for it
1714 skb_new
= skb_copy(skb
, GFP_ATOMIC
);
1716 if (net_ratelimit())
1717 printk(KERN_DEBUG
"%s: failed to copy "
1718 "multicast frame for %s",
1719 wiphy_name(local
->hw
.wiphy
),
1726 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
1734 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
1745 EXPORT_SYMBOL(__ieee80211_rx
);
1747 /* This is a version of the rx handler that can be called from hard irq
1748 * context. Post the skb on the queue and schedule the tasklet */
1749 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1750 struct ieee80211_rx_status
*status
)
1752 struct ieee80211_local
*local
= hw_to_local(hw
);
1754 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
));
1756 skb
->dev
= local
->mdev
;
1757 /* copy status into skb->cb for use by tasklet */
1758 memcpy(skb
->cb
, status
, sizeof(*status
));
1759 skb
->pkt_type
= IEEE80211_RX_MSG
;
1760 skb_queue_tail(&local
->skb_queue
, skb
);
1761 tasklet_schedule(&local
->tasklet
);
1763 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);