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/jiffies.h>
13 #include <linux/kernel.h>
14 #include <linux/skbuff.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/rcupdate.h>
18 #include <net/mac80211.h>
19 #include <net/ieee80211_radiotap.h>
21 #include "ieee80211_i.h"
22 #include "driver-ops.h"
30 static void ieee80211_release_reorder_frames(struct ieee80211_hw
*hw
,
31 struct tid_ampdu_rx
*tid_agg_rx
,
35 * monitor mode reception
37 * This function cleans up the SKB, i.e. it removes all the stuff
38 * only useful for monitoring.
40 static struct sk_buff
*remove_monitor_info(struct ieee80211_local
*local
,
43 if (local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
) {
44 if (likely(skb
->len
> FCS_LEN
))
45 skb_trim(skb
, skb
->len
- FCS_LEN
);
57 static inline int should_drop_frame(struct sk_buff
*skb
,
60 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
61 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
63 if (status
->flag
& (RX_FLAG_FAILED_FCS_CRC
| RX_FLAG_FAILED_PLCP_CRC
))
65 if (unlikely(skb
->len
< 16 + present_fcs_len
))
67 if (ieee80211_is_ctl(hdr
->frame_control
) &&
68 !ieee80211_is_pspoll(hdr
->frame_control
) &&
69 !ieee80211_is_back_req(hdr
->frame_control
))
75 ieee80211_rx_radiotap_len(struct ieee80211_local
*local
,
76 struct ieee80211_rx_status
*status
)
80 /* always present fields */
81 len
= sizeof(struct ieee80211_radiotap_header
) + 9;
83 if (status
->flag
& RX_FLAG_TSFT
)
85 if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
)
87 if (local
->hw
.flags
& IEEE80211_HW_NOISE_DBM
)
90 if (len
& 1) /* padding for RX_FLAGS if necessary */
97 * ieee80211_add_rx_radiotap_header - add radiotap header
99 * add a radiotap header containing all the fields which the hardware provided.
102 ieee80211_add_rx_radiotap_header(struct ieee80211_local
*local
,
104 struct ieee80211_rate
*rate
,
107 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
108 struct ieee80211_radiotap_header
*rthdr
;
112 rthdr
= (struct ieee80211_radiotap_header
*)skb_push(skb
, rtap_len
);
113 memset(rthdr
, 0, rtap_len
);
115 /* radiotap header, set always present flags */
117 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS
) |
118 (1 << IEEE80211_RADIOTAP_CHANNEL
) |
119 (1 << IEEE80211_RADIOTAP_ANTENNA
) |
120 (1 << IEEE80211_RADIOTAP_RX_FLAGS
));
121 rthdr
->it_len
= cpu_to_le16(rtap_len
);
123 pos
= (unsigned char *)(rthdr
+1);
125 /* the order of the following fields is important */
127 /* IEEE80211_RADIOTAP_TSFT */
128 if (status
->flag
& RX_FLAG_TSFT
) {
129 put_unaligned_le64(status
->mactime
, pos
);
131 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT
);
135 /* IEEE80211_RADIOTAP_FLAGS */
136 if (local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
)
137 *pos
|= IEEE80211_RADIOTAP_F_FCS
;
138 if (status
->flag
& (RX_FLAG_FAILED_FCS_CRC
| RX_FLAG_FAILED_PLCP_CRC
))
139 *pos
|= IEEE80211_RADIOTAP_F_BADFCS
;
140 if (status
->flag
& RX_FLAG_SHORTPRE
)
141 *pos
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
144 /* IEEE80211_RADIOTAP_RATE */
145 if (status
->flag
& RX_FLAG_HT
) {
147 * TODO: add following information into radiotap header once
148 * suitable fields are defined for it:
149 * - MCS index (status->rate_idx)
150 * - HT40 (status->flag & RX_FLAG_40MHZ)
151 * - short-GI (status->flag & RX_FLAG_SHORT_GI)
155 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE
);
156 *pos
= rate
->bitrate
/ 5;
160 /* IEEE80211_RADIOTAP_CHANNEL */
161 put_unaligned_le16(status
->freq
, pos
);
163 if (status
->band
== IEEE80211_BAND_5GHZ
)
164 put_unaligned_le16(IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_5GHZ
,
166 else if (status
->flag
& RX_FLAG_HT
)
167 put_unaligned_le16(IEEE80211_CHAN_DYN
| IEEE80211_CHAN_2GHZ
,
169 else if (rate
->flags
& IEEE80211_RATE_ERP_G
)
170 put_unaligned_le16(IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_2GHZ
,
173 put_unaligned_le16(IEEE80211_CHAN_CCK
| IEEE80211_CHAN_2GHZ
,
177 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
178 if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
) {
179 *pos
= status
->signal
;
181 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
);
185 /* IEEE80211_RADIOTAP_DBM_ANTNOISE */
186 if (local
->hw
.flags
& IEEE80211_HW_NOISE_DBM
) {
187 *pos
= status
->noise
;
189 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE
);
193 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
195 /* IEEE80211_RADIOTAP_ANTENNA */
196 *pos
= status
->antenna
;
199 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
201 /* IEEE80211_RADIOTAP_RX_FLAGS */
202 /* ensure 2 byte alignment for the 2 byte field as required */
203 if ((pos
- (u8
*)rthdr
) & 1)
205 if (status
->flag
& RX_FLAG_FAILED_PLCP_CRC
)
206 rx_flags
|= IEEE80211_RADIOTAP_F_RX_BADPLCP
;
207 put_unaligned_le16(rx_flags
, pos
);
212 * This function copies a received frame to all monitor interfaces and
213 * returns a cleaned-up SKB that no longer includes the FCS nor the
214 * radiotap header the driver might have added.
216 static struct sk_buff
*
217 ieee80211_rx_monitor(struct ieee80211_local
*local
, struct sk_buff
*origskb
,
218 struct ieee80211_rate
*rate
)
220 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(origskb
);
221 struct ieee80211_sub_if_data
*sdata
;
222 int needed_headroom
= 0;
223 struct sk_buff
*skb
, *skb2
;
224 struct net_device
*prev_dev
= NULL
;
225 int present_fcs_len
= 0;
228 * First, we may need to make a copy of the skb because
229 * (1) we need to modify it for radiotap (if not present), and
230 * (2) the other RX handlers will modify the skb we got.
232 * We don't need to, of course, if we aren't going to return
233 * the SKB because it has a bad FCS/PLCP checksum.
236 /* room for the radiotap header based on driver features */
237 needed_headroom
= ieee80211_rx_radiotap_len(local
, status
);
239 if (local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
)
240 present_fcs_len
= FCS_LEN
;
242 if (!local
->monitors
) {
243 if (should_drop_frame(origskb
, present_fcs_len
)) {
244 dev_kfree_skb(origskb
);
248 return remove_monitor_info(local
, origskb
);
251 if (should_drop_frame(origskb
, present_fcs_len
)) {
252 /* only need to expand headroom if necessary */
257 * This shouldn't trigger often because most devices have an
258 * RX header they pull before we get here, and that should
259 * be big enough for our radiotap information. We should
260 * probably export the length to drivers so that we can have
261 * them allocate enough headroom to start with.
263 if (skb_headroom(skb
) < needed_headroom
&&
264 pskb_expand_head(skb
, needed_headroom
, 0, GFP_ATOMIC
)) {
270 * Need to make a copy and possibly remove radiotap header
271 * and FCS from the original.
273 skb
= skb_copy_expand(origskb
, needed_headroom
, 0, GFP_ATOMIC
);
275 origskb
= remove_monitor_info(local
, origskb
);
281 /* prepend radiotap information */
282 ieee80211_add_rx_radiotap_header(local
, skb
, rate
, needed_headroom
);
284 skb_reset_mac_header(skb
);
285 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
286 skb
->pkt_type
= PACKET_OTHERHOST
;
287 skb
->protocol
= htons(ETH_P_802_2
);
289 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
290 if (!netif_running(sdata
->dev
))
293 if (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
)
296 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
)
300 skb2
= skb_clone(skb
, GFP_ATOMIC
);
302 skb2
->dev
= prev_dev
;
307 prev_dev
= sdata
->dev
;
308 sdata
->dev
->stats
.rx_packets
++;
309 sdata
->dev
->stats
.rx_bytes
+= skb
->len
;
322 static void ieee80211_parse_qos(struct ieee80211_rx_data
*rx
)
324 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
327 /* does the frame have a qos control field? */
328 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
329 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
330 /* frame has qos control */
331 tid
= *qc
& IEEE80211_QOS_CTL_TID_MASK
;
332 if (*qc
& IEEE80211_QOS_CONTROL_A_MSDU_PRESENT
)
333 rx
->flags
|= IEEE80211_RX_AMSDU
;
335 rx
->flags
&= ~IEEE80211_RX_AMSDU
;
338 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
340 * Sequence numbers for management frames, QoS data
341 * frames with a broadcast/multicast address in the
342 * Address 1 field, and all non-QoS data frames sent
343 * by QoS STAs are assigned using an additional single
344 * modulo-4096 counter, [...]
346 * We also use that counter for non-QoS STAs.
348 tid
= NUM_RX_DATA_QUEUES
- 1;
352 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
353 * For now, set skb->priority to 0 for other cases. */
354 rx
->skb
->priority
= (tid
> 7) ? 0 : tid
;
358 * DOC: Packet alignment
360 * Drivers always need to pass packets that are aligned to two-byte boundaries
363 * Additionally, should, if possible, align the payload data in a way that
364 * guarantees that the contained IP header is aligned to a four-byte
365 * boundary. In the case of regular frames, this simply means aligning the
366 * payload to a four-byte boundary (because either the IP header is directly
367 * contained, or IV/RFC1042 headers that have a length divisible by four are
370 * With A-MSDU frames, however, the payload data address must yield two modulo
371 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
372 * push the IP header further back to a multiple of four again. Thankfully, the
373 * specs were sane enough this time around to require padding each A-MSDU
374 * subframe to a length that is a multiple of four.
376 * Padding like Atheros hardware adds which is inbetween the 802.11 header and
377 * the payload is not supported, the driver is required to move the 802.11
378 * header to be directly in front of the payload in that case.
380 static void ieee80211_verify_alignment(struct ieee80211_rx_data
*rx
)
382 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
385 #ifndef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
389 if (WARN_ONCE((unsigned long)rx
->skb
->data
& 1,
390 "unaligned packet at 0x%p\n", rx
->skb
->data
))
393 if (!ieee80211_is_data_present(hdr
->frame_control
))
396 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
397 if (rx
->flags
& IEEE80211_RX_AMSDU
)
399 WARN_ONCE(((unsigned long)(rx
->skb
->data
+ hdrlen
)) & 3,
400 "unaligned IP payload at 0x%p\n", rx
->skb
->data
+ hdrlen
);
406 static ieee80211_rx_result debug_noinline
407 ieee80211_rx_h_passive_scan(struct ieee80211_rx_data
*rx
)
409 struct ieee80211_local
*local
= rx
->local
;
410 struct sk_buff
*skb
= rx
->skb
;
412 if (unlikely(test_bit(SCAN_HW_SCANNING
, &local
->scanning
)))
413 return ieee80211_scan_rx(rx
->sdata
, skb
);
415 if (unlikely(test_bit(SCAN_SW_SCANNING
, &local
->scanning
) &&
416 (rx
->flags
& IEEE80211_RX_IN_SCAN
))) {
417 /* drop all the other packets during a software scan anyway */
418 if (ieee80211_scan_rx(rx
->sdata
, skb
) != RX_QUEUED
)
423 if (unlikely(rx
->flags
& IEEE80211_RX_IN_SCAN
)) {
424 /* scanning finished during invoking of handlers */
425 I802_DEBUG_INC(local
->rx_handlers_drop_passive_scan
);
426 return RX_DROP_UNUSABLE
;
433 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff
*skb
)
435 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
437 if (skb
->len
< 24 || is_multicast_ether_addr(hdr
->addr1
))
440 return ieee80211_is_robust_mgmt_frame(hdr
);
444 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff
*skb
)
446 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
448 if (skb
->len
< 24 || !is_multicast_ether_addr(hdr
->addr1
))
451 return ieee80211_is_robust_mgmt_frame(hdr
);
455 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
456 static int ieee80211_get_mmie_keyidx(struct sk_buff
*skb
)
458 struct ieee80211_mgmt
*hdr
= (struct ieee80211_mgmt
*) skb
->data
;
459 struct ieee80211_mmie
*mmie
;
461 if (skb
->len
< 24 + sizeof(*mmie
) ||
462 !is_multicast_ether_addr(hdr
->da
))
465 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr
*) hdr
))
466 return -1; /* not a robust management frame */
468 mmie
= (struct ieee80211_mmie
*)
469 (skb
->data
+ skb
->len
- sizeof(*mmie
));
470 if (mmie
->element_id
!= WLAN_EID_MMIE
||
471 mmie
->length
!= sizeof(*mmie
) - 2)
474 return le16_to_cpu(mmie
->key_id
);
478 static ieee80211_rx_result
479 ieee80211_rx_mesh_check(struct ieee80211_rx_data
*rx
)
481 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
482 unsigned int hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
483 char *dev_addr
= rx
->sdata
->dev
->dev_addr
;
485 if (ieee80211_is_data(hdr
->frame_control
)) {
486 if (is_multicast_ether_addr(hdr
->addr1
)) {
487 if (ieee80211_has_tods(hdr
->frame_control
) ||
488 !ieee80211_has_fromds(hdr
->frame_control
))
489 return RX_DROP_MONITOR
;
490 if (memcmp(hdr
->addr3
, dev_addr
, ETH_ALEN
) == 0)
491 return RX_DROP_MONITOR
;
493 if (!ieee80211_has_a4(hdr
->frame_control
))
494 return RX_DROP_MONITOR
;
495 if (memcmp(hdr
->addr4
, dev_addr
, ETH_ALEN
) == 0)
496 return RX_DROP_MONITOR
;
500 /* If there is not an established peer link and this is not a peer link
501 * establisment frame, beacon or probe, drop the frame.
504 if (!rx
->sta
|| sta_plink_state(rx
->sta
) != PLINK_ESTAB
) {
505 struct ieee80211_mgmt
*mgmt
;
507 if (!ieee80211_is_mgmt(hdr
->frame_control
))
508 return RX_DROP_MONITOR
;
510 if (ieee80211_is_action(hdr
->frame_control
)) {
511 mgmt
= (struct ieee80211_mgmt
*)hdr
;
512 if (mgmt
->u
.action
.category
!= MESH_PLINK_CATEGORY
)
513 return RX_DROP_MONITOR
;
517 if (ieee80211_is_probe_req(hdr
->frame_control
) ||
518 ieee80211_is_probe_resp(hdr
->frame_control
) ||
519 ieee80211_is_beacon(hdr
->frame_control
))
522 return RX_DROP_MONITOR
;
526 #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
528 if (ieee80211_is_data(hdr
->frame_control
) &&
529 is_multicast_ether_addr(hdr
->addr1
) &&
530 mesh_rmc_check(hdr
->addr3
, msh_h_get(hdr
, hdrlen
), rx
->sdata
))
531 return RX_DROP_MONITOR
;
538 static ieee80211_rx_result debug_noinline
539 ieee80211_rx_h_check(struct ieee80211_rx_data
*rx
)
541 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
543 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
544 if (rx
->sta
&& !is_multicast_ether_addr(hdr
->addr1
)) {
545 if (unlikely(ieee80211_has_retry(hdr
->frame_control
) &&
546 rx
->sta
->last_seq_ctrl
[rx
->queue
] ==
548 if (rx
->flags
& IEEE80211_RX_RA_MATCH
) {
549 rx
->local
->dot11FrameDuplicateCount
++;
550 rx
->sta
->num_duplicates
++;
552 return RX_DROP_MONITOR
;
554 rx
->sta
->last_seq_ctrl
[rx
->queue
] = hdr
->seq_ctrl
;
557 if (unlikely(rx
->skb
->len
< 16)) {
558 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_short
);
559 return RX_DROP_MONITOR
;
562 /* Drop disallowed frame classes based on STA auth/assoc state;
563 * IEEE 802.11, Chap 5.5.
565 * mac80211 filters only based on association state, i.e. it drops
566 * Class 3 frames from not associated stations. hostapd sends
567 * deauth/disassoc frames when needed. In addition, hostapd is
568 * responsible for filtering on both auth and assoc states.
571 if (ieee80211_vif_is_mesh(&rx
->sdata
->vif
))
572 return ieee80211_rx_mesh_check(rx
);
574 if (unlikely((ieee80211_is_data(hdr
->frame_control
) ||
575 ieee80211_is_pspoll(hdr
->frame_control
)) &&
576 rx
->sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
577 (!rx
->sta
|| !test_sta_flags(rx
->sta
, WLAN_STA_ASSOC
)))) {
578 if ((!ieee80211_has_fromds(hdr
->frame_control
) &&
579 !ieee80211_has_tods(hdr
->frame_control
) &&
580 ieee80211_is_data(hdr
->frame_control
)) ||
581 !(rx
->flags
& IEEE80211_RX_RA_MATCH
)) {
582 /* Drop IBSS frames and frames for other hosts
584 return RX_DROP_MONITOR
;
587 return RX_DROP_MONITOR
;
594 static ieee80211_rx_result debug_noinline
595 ieee80211_rx_h_decrypt(struct ieee80211_rx_data
*rx
)
597 struct sk_buff
*skb
= rx
->skb
;
598 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
599 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
602 ieee80211_rx_result result
= RX_DROP_UNUSABLE
;
603 struct ieee80211_key
*stakey
= NULL
;
604 int mmie_keyidx
= -1;
609 * There are four types of keys:
611 * - IGTK (group keys for management frames)
612 * - PTK (pairwise keys)
613 * - STK (station-to-station pairwise keys)
615 * When selecting a key, we have to distinguish between multicast
616 * (including broadcast) and unicast frames, the latter can only
617 * use PTKs and STKs while the former always use GTKs and IGTKs.
618 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
619 * unicast frames can also use key indices like GTKs. Hence, if we
620 * don't have a PTK/STK we check the key index for a WEP key.
622 * Note that in a regular BSS, multicast frames are sent by the
623 * AP only, associated stations unicast the frame to the AP first
624 * which then multicasts it on their behalf.
626 * There is also a slight problem in IBSS mode: GTKs are negotiated
627 * with each station, that is something we don't currently handle.
628 * The spec seems to expect that one negotiates the same key with
629 * every station but there's no such requirement; VLANs could be
634 * No point in finding a key and decrypting if the frame is neither
635 * addressed to us nor a multicast frame.
637 if (!(rx
->flags
& IEEE80211_RX_RA_MATCH
))
641 stakey
= rcu_dereference(rx
->sta
->key
);
643 if (!ieee80211_has_protected(hdr
->frame_control
))
644 mmie_keyidx
= ieee80211_get_mmie_keyidx(rx
->skb
);
646 if (!is_multicast_ether_addr(hdr
->addr1
) && stakey
) {
648 /* Skip decryption if the frame is not protected. */
649 if (!ieee80211_has_protected(hdr
->frame_control
))
651 } else if (mmie_keyidx
>= 0) {
652 /* Broadcast/multicast robust management frame / BIP */
653 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
654 (status
->flag
& RX_FLAG_IV_STRIPPED
))
657 if (mmie_keyidx
< NUM_DEFAULT_KEYS
||
658 mmie_keyidx
>= NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
)
659 return RX_DROP_MONITOR
; /* unexpected BIP keyidx */
660 rx
->key
= rcu_dereference(rx
->sdata
->keys
[mmie_keyidx
]);
661 } else if (!ieee80211_has_protected(hdr
->frame_control
)) {
663 * The frame was not protected, so skip decryption. However, we
664 * need to set rx->key if there is a key that could have been
665 * used so that the frame may be dropped if encryption would
666 * have been expected.
668 struct ieee80211_key
*key
= NULL
;
669 if (ieee80211_is_mgmt(hdr
->frame_control
) &&
670 is_multicast_ether_addr(hdr
->addr1
) &&
671 (key
= rcu_dereference(rx
->sdata
->default_mgmt_key
)))
673 else if ((key
= rcu_dereference(rx
->sdata
->default_key
)))
678 * The device doesn't give us the IV so we won't be
679 * able to look up the key. That's ok though, we
680 * don't need to decrypt the frame, we just won't
681 * be able to keep statistics accurate.
682 * Except for key threshold notifications, should
683 * we somehow allow the driver to tell us which key
684 * the hardware used if this flag is set?
686 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
687 (status
->flag
& RX_FLAG_IV_STRIPPED
))
690 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
692 if (rx
->skb
->len
< 8 + hdrlen
)
693 return RX_DROP_UNUSABLE
; /* TODO: count this? */
696 * no need to call ieee80211_wep_get_keyidx,
697 * it verifies a bunch of things we've done already
699 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
701 rx
->key
= rcu_dereference(rx
->sdata
->keys
[keyidx
]);
704 * RSNA-protected unicast frames should always be sent with
705 * pairwise or station-to-station keys, but for WEP we allow
706 * using a key index as well.
708 if (rx
->key
&& rx
->key
->conf
.alg
!= ALG_WEP
&&
709 !is_multicast_ether_addr(hdr
->addr1
))
714 rx
->key
->tx_rx_count
++;
715 /* TODO: add threshold stuff again */
717 return RX_DROP_MONITOR
;
720 /* Check for weak IVs if possible */
721 if (rx
->sta
&& rx
->key
->conf
.alg
== ALG_WEP
&&
722 ieee80211_is_data(hdr
->frame_control
) &&
723 (!(status
->flag
& RX_FLAG_IV_STRIPPED
) ||
724 !(status
->flag
& RX_FLAG_DECRYPTED
)) &&
725 ieee80211_wep_is_weak_iv(rx
->skb
, rx
->key
))
726 rx
->sta
->wep_weak_iv_count
++;
728 switch (rx
->key
->conf
.alg
) {
730 result
= ieee80211_crypto_wep_decrypt(rx
);
733 result
= ieee80211_crypto_tkip_decrypt(rx
);
736 result
= ieee80211_crypto_ccmp_decrypt(rx
);
739 result
= ieee80211_crypto_aes_cmac_decrypt(rx
);
743 /* either the frame has been decrypted or will be dropped */
744 status
->flag
|= RX_FLAG_DECRYPTED
;
749 static ieee80211_rx_result debug_noinline
750 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data
*rx
)
752 struct ieee80211_local
*local
;
753 struct ieee80211_hdr
*hdr
;
758 hdr
= (struct ieee80211_hdr
*) skb
->data
;
760 if (!local
->pspolling
)
763 if (!ieee80211_has_fromds(hdr
->frame_control
))
764 /* this is not from AP */
767 if (!ieee80211_is_data(hdr
->frame_control
))
770 if (!ieee80211_has_moredata(hdr
->frame_control
)) {
771 /* AP has no more frames buffered for us */
772 local
->pspolling
= false;
776 /* more data bit is set, let's request a new frame from the AP */
777 ieee80211_send_pspoll(local
, rx
->sdata
);
782 static void ap_sta_ps_start(struct sta_info
*sta
)
784 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
785 struct ieee80211_local
*local
= sdata
->local
;
787 atomic_inc(&sdata
->bss
->num_sta_ps
);
788 set_sta_flags(sta
, WLAN_STA_PS_STA
);
789 drv_sta_notify(local
, &sdata
->vif
, STA_NOTIFY_SLEEP
, &sta
->sta
);
790 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
791 printk(KERN_DEBUG
"%s: STA %pM aid %d enters power save mode\n",
792 sdata
->dev
->name
, sta
->sta
.addr
, sta
->sta
.aid
);
793 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
796 static void ap_sta_ps_end(struct sta_info
*sta
)
798 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
800 atomic_dec(&sdata
->bss
->num_sta_ps
);
802 clear_sta_flags(sta
, WLAN_STA_PS_STA
);
804 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
805 printk(KERN_DEBUG
"%s: STA %pM aid %d exits power save mode\n",
806 sdata
->dev
->name
, sta
->sta
.addr
, sta
->sta
.aid
);
807 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
809 if (test_sta_flags(sta
, WLAN_STA_PS_DRIVER
)) {
810 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
811 printk(KERN_DEBUG
"%s: STA %pM aid %d driver-ps-blocked\n",
812 sdata
->dev
->name
, sta
->sta
.addr
, sta
->sta
.aid
);
813 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
817 ieee80211_sta_ps_deliver_wakeup(sta
);
820 static ieee80211_rx_result debug_noinline
821 ieee80211_rx_h_sta_process(struct ieee80211_rx_data
*rx
)
823 struct sta_info
*sta
= rx
->sta
;
824 struct sk_buff
*skb
= rx
->skb
;
825 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
826 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
832 * Update last_rx only for IBSS packets which are for the current
833 * BSSID to avoid keeping the current IBSS network alive in cases
834 * where other STAs start using different BSSID.
836 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
837 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
,
838 NL80211_IFTYPE_ADHOC
);
839 if (compare_ether_addr(bssid
, rx
->sdata
->u
.ibss
.bssid
) == 0)
840 sta
->last_rx
= jiffies
;
841 } else if (!is_multicast_ether_addr(hdr
->addr1
)) {
843 * Mesh beacons will update last_rx when if they are found to
844 * match the current local configuration when processed.
846 sta
->last_rx
= jiffies
;
849 if (!(rx
->flags
& IEEE80211_RX_RA_MATCH
))
852 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
853 ieee80211_sta_rx_notify(rx
->sdata
, hdr
);
856 sta
->rx_bytes
+= rx
->skb
->len
;
857 sta
->last_signal
= status
->signal
;
858 sta
->last_noise
= status
->noise
;
861 * Change STA power saving mode only at the end of a frame
864 if (!ieee80211_has_morefrags(hdr
->frame_control
) &&
865 (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
866 rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)) {
867 if (test_sta_flags(sta
, WLAN_STA_PS_STA
)) {
869 * Ignore doze->wake transitions that are
870 * indicated by non-data frames, the standard
871 * is unclear here, but for example going to
872 * PS mode and then scanning would cause a
873 * doze->wake transition for the probe request,
874 * and that is clearly undesirable.
876 if (ieee80211_is_data(hdr
->frame_control
) &&
877 !ieee80211_has_pm(hdr
->frame_control
))
880 if (ieee80211_has_pm(hdr
->frame_control
))
881 ap_sta_ps_start(sta
);
886 * Drop (qos-)data::nullfunc frames silently, since they
887 * are used only to control station power saving mode.
889 if (ieee80211_is_nullfunc(hdr
->frame_control
) ||
890 ieee80211_is_qos_nullfunc(hdr
->frame_control
)) {
891 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
893 * Update counter and free packet here to avoid
894 * counting this as a dropped packed.
897 dev_kfree_skb(rx
->skb
);
902 } /* ieee80211_rx_h_sta_process */
904 static inline struct ieee80211_fragment_entry
*
905 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
906 unsigned int frag
, unsigned int seq
, int rx_queue
,
907 struct sk_buff
**skb
)
909 struct ieee80211_fragment_entry
*entry
;
912 idx
= sdata
->fragment_next
;
913 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
914 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
915 sdata
->fragment_next
= 0;
917 if (!skb_queue_empty(&entry
->skb_list
)) {
918 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
919 struct ieee80211_hdr
*hdr
=
920 (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
921 printk(KERN_DEBUG
"%s: RX reassembly removed oldest "
922 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
923 "addr1=%pM addr2=%pM\n",
924 sdata
->dev
->name
, idx
,
925 jiffies
- entry
->first_frag_time
, entry
->seq
,
926 entry
->last_frag
, hdr
->addr1
, hdr
->addr2
);
928 __skb_queue_purge(&entry
->skb_list
);
931 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
933 entry
->first_frag_time
= jiffies
;
935 entry
->rx_queue
= rx_queue
;
936 entry
->last_frag
= frag
;
938 entry
->extra_len
= 0;
943 static inline struct ieee80211_fragment_entry
*
944 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
945 unsigned int frag
, unsigned int seq
,
946 int rx_queue
, struct ieee80211_hdr
*hdr
)
948 struct ieee80211_fragment_entry
*entry
;
951 idx
= sdata
->fragment_next
;
952 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
953 struct ieee80211_hdr
*f_hdr
;
957 idx
= IEEE80211_FRAGMENT_MAX
- 1;
959 entry
= &sdata
->fragments
[idx
];
960 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
961 entry
->rx_queue
!= rx_queue
||
962 entry
->last_frag
+ 1 != frag
)
965 f_hdr
= (struct ieee80211_hdr
*)entry
->skb_list
.next
->data
;
968 * Check ftype and addresses are equal, else check next fragment
970 if (((hdr
->frame_control
^ f_hdr
->frame_control
) &
971 cpu_to_le16(IEEE80211_FCTL_FTYPE
)) ||
972 compare_ether_addr(hdr
->addr1
, f_hdr
->addr1
) != 0 ||
973 compare_ether_addr(hdr
->addr2
, f_hdr
->addr2
) != 0)
976 if (time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
977 __skb_queue_purge(&entry
->skb_list
);
986 static ieee80211_rx_result debug_noinline
987 ieee80211_rx_h_defragment(struct ieee80211_rx_data
*rx
)
989 struct ieee80211_hdr
*hdr
;
992 unsigned int frag
, seq
;
993 struct ieee80211_fragment_entry
*entry
;
996 hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
997 fc
= hdr
->frame_control
;
998 sc
= le16_to_cpu(hdr
->seq_ctrl
);
999 frag
= sc
& IEEE80211_SCTL_FRAG
;
1001 if (likely((!ieee80211_has_morefrags(fc
) && frag
== 0) ||
1002 (rx
->skb
)->len
< 24 ||
1003 is_multicast_ether_addr(hdr
->addr1
))) {
1004 /* not fragmented */
1007 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
1009 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
1012 /* This is the first fragment of a new frame. */
1013 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
1014 rx
->queue
, &(rx
->skb
));
1015 if (rx
->key
&& rx
->key
->conf
.alg
== ALG_CCMP
&&
1016 ieee80211_has_protected(fc
)) {
1017 /* Store CCMP PN so that we can verify that the next
1018 * fragment has a sequential PN value. */
1020 memcpy(entry
->last_pn
,
1021 rx
->key
->u
.ccmp
.rx_pn
[rx
->queue
],
1027 /* This is a fragment for a frame that should already be pending in
1028 * fragment cache. Add this fragment to the end of the pending entry.
1030 entry
= ieee80211_reassemble_find(rx
->sdata
, frag
, seq
, rx
->queue
, hdr
);
1032 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
1033 return RX_DROP_MONITOR
;
1036 /* Verify that MPDUs within one MSDU have sequential PN values.
1037 * (IEEE 802.11i, 8.3.3.4.5) */
1040 u8 pn
[CCMP_PN_LEN
], *rpn
;
1041 if (!rx
->key
|| rx
->key
->conf
.alg
!= ALG_CCMP
)
1042 return RX_DROP_UNUSABLE
;
1043 memcpy(pn
, entry
->last_pn
, CCMP_PN_LEN
);
1044 for (i
= CCMP_PN_LEN
- 1; i
>= 0; i
--) {
1049 rpn
= rx
->key
->u
.ccmp
.rx_pn
[rx
->queue
];
1050 if (memcmp(pn
, rpn
, CCMP_PN_LEN
))
1051 return RX_DROP_UNUSABLE
;
1052 memcpy(entry
->last_pn
, pn
, CCMP_PN_LEN
);
1055 skb_pull(rx
->skb
, ieee80211_hdrlen(fc
));
1056 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
1057 entry
->last_frag
= frag
;
1058 entry
->extra_len
+= rx
->skb
->len
;
1059 if (ieee80211_has_morefrags(fc
)) {
1064 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
1065 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
1066 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head2
);
1067 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
1069 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
1070 __skb_queue_purge(&entry
->skb_list
);
1071 return RX_DROP_UNUSABLE
;
1074 while ((skb
= __skb_dequeue(&entry
->skb_list
))) {
1075 memcpy(skb_put(rx
->skb
, skb
->len
), skb
->data
, skb
->len
);
1079 /* Complete frame has been reassembled - process it now */
1080 rx
->flags
|= IEEE80211_RX_FRAGMENTED
;
1084 rx
->sta
->rx_packets
++;
1085 if (is_multicast_ether_addr(hdr
->addr1
))
1086 rx
->local
->dot11MulticastReceivedFrameCount
++;
1088 ieee80211_led_rx(rx
->local
);
1092 static ieee80211_rx_result debug_noinline
1093 ieee80211_rx_h_ps_poll(struct ieee80211_rx_data
*rx
)
1095 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1096 __le16 fc
= ((struct ieee80211_hdr
*)rx
->skb
->data
)->frame_control
;
1098 if (likely(!rx
->sta
|| !ieee80211_is_pspoll(fc
) ||
1099 !(rx
->flags
& IEEE80211_RX_RA_MATCH
)))
1102 if ((sdata
->vif
.type
!= NL80211_IFTYPE_AP
) &&
1103 (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
))
1104 return RX_DROP_UNUSABLE
;
1106 if (!test_sta_flags(rx
->sta
, WLAN_STA_PS_DRIVER
))
1107 ieee80211_sta_ps_deliver_poll_response(rx
->sta
);
1109 set_sta_flags(rx
->sta
, WLAN_STA_PSPOLL
);
1111 /* Free PS Poll skb here instead of returning RX_DROP that would
1112 * count as an dropped frame. */
1113 dev_kfree_skb(rx
->skb
);
1118 static ieee80211_rx_result debug_noinline
1119 ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data
*rx
)
1121 u8
*data
= rx
->skb
->data
;
1122 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)data
;
1124 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1127 /* remove the qos control field, update frame type and meta-data */
1128 memmove(data
+ IEEE80211_QOS_CTL_LEN
, data
,
1129 ieee80211_hdrlen(hdr
->frame_control
) - IEEE80211_QOS_CTL_LEN
);
1130 hdr
= (struct ieee80211_hdr
*)skb_pull(rx
->skb
, IEEE80211_QOS_CTL_LEN
);
1131 /* change frame type to non QOS */
1132 hdr
->frame_control
&= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
1138 ieee80211_802_1x_port_control(struct ieee80211_rx_data
*rx
)
1140 if (unlikely(!rx
->sta
||
1141 !test_sta_flags(rx
->sta
, WLAN_STA_AUTHORIZED
)))
1148 ieee80211_drop_unencrypted(struct ieee80211_rx_data
*rx
, __le16 fc
)
1150 struct sk_buff
*skb
= rx
->skb
;
1151 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1154 * Pass through unencrypted frames if the hardware has
1155 * decrypted them already.
1157 if (status
->flag
& RX_FLAG_DECRYPTED
)
1160 /* Drop unencrypted frames if key is set. */
1161 if (unlikely(!ieee80211_has_protected(fc
) &&
1162 !ieee80211_is_nullfunc(fc
) &&
1163 ieee80211_is_data(fc
) &&
1164 (rx
->key
|| rx
->sdata
->drop_unencrypted
)))
1166 if (rx
->sta
&& test_sta_flags(rx
->sta
, WLAN_STA_MFP
)) {
1167 if (unlikely(ieee80211_is_unicast_robust_mgmt_frame(rx
->skb
) &&
1170 /* BIP does not use Protected field, so need to check MMIE */
1171 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx
->skb
)
1172 && ieee80211_get_mmie_keyidx(rx
->skb
) < 0 &&
1176 * When using MFP, Action frames are not allowed prior to
1177 * having configured keys.
1179 if (unlikely(ieee80211_is_action(fc
) && !rx
->key
&&
1180 ieee80211_is_robust_mgmt_frame(
1181 (struct ieee80211_hdr
*) rx
->skb
->data
)))
1189 __ieee80211_data_to_8023(struct ieee80211_rx_data
*rx
)
1191 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1192 struct net_device
*dev
= sdata
->dev
;
1193 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
1195 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&& !sdata
->use_4addr
&&
1196 ieee80211_has_a4(hdr
->frame_control
))
1198 if (sdata
->use_4addr
&& is_multicast_ether_addr(hdr
->addr1
))
1201 return ieee80211_data_to_8023(rx
->skb
, dev
->dev_addr
, sdata
->vif
.type
);
1205 * requires that rx->skb is a frame with ethernet header
1207 static bool ieee80211_frame_allowed(struct ieee80211_rx_data
*rx
, __le16 fc
)
1209 static const u8 pae_group_addr
[ETH_ALEN
] __aligned(2)
1210 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1211 struct ethhdr
*ehdr
= (struct ethhdr
*) rx
->skb
->data
;
1214 * Allow EAPOL frames to us/the PAE group address regardless
1215 * of whether the frame was encrypted or not.
1217 if (ehdr
->h_proto
== htons(ETH_P_PAE
) &&
1218 (compare_ether_addr(ehdr
->h_dest
, rx
->sdata
->dev
->dev_addr
) == 0 ||
1219 compare_ether_addr(ehdr
->h_dest
, pae_group_addr
) == 0))
1222 if (ieee80211_802_1x_port_control(rx
) ||
1223 ieee80211_drop_unencrypted(rx
, fc
))
1230 * requires that rx->skb is a frame with ethernet header
1233 ieee80211_deliver_skb(struct ieee80211_rx_data
*rx
)
1235 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1236 struct net_device
*dev
= sdata
->dev
;
1237 struct ieee80211_local
*local
= rx
->local
;
1238 struct sk_buff
*skb
, *xmit_skb
;
1239 struct ethhdr
*ehdr
= (struct ethhdr
*) rx
->skb
->data
;
1240 struct sta_info
*dsta
;
1245 if ((sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1246 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) &&
1247 !(sdata
->flags
& IEEE80211_SDATA_DONT_BRIDGE_PACKETS
) &&
1248 (rx
->flags
& IEEE80211_RX_RA_MATCH
) && !rx
->sdata
->use_4addr
) {
1249 if (is_multicast_ether_addr(ehdr
->h_dest
)) {
1251 * send multicast frames both to higher layers in
1252 * local net stack and back to the wireless medium
1254 xmit_skb
= skb_copy(skb
, GFP_ATOMIC
);
1255 if (!xmit_skb
&& net_ratelimit())
1256 printk(KERN_DEBUG
"%s: failed to clone "
1257 "multicast frame\n", dev
->name
);
1259 dsta
= sta_info_get(local
, skb
->data
);
1260 if (dsta
&& dsta
->sdata
->dev
== dev
) {
1262 * The destination station is associated to
1263 * this AP (in this VLAN), so send the frame
1264 * directly to it and do not pass it to local
1274 int align __maybe_unused
;
1276 #if defined(CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT) || !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
1278 * 'align' will only take the values 0 or 2 here
1279 * since all frames are required to be aligned
1280 * to 2-byte boundaries when being passed to
1281 * mac80211. That also explains the __skb_push()
1284 align
= ((unsigned long)(skb
->data
+ sizeof(struct ethhdr
))) & 3;
1286 if (WARN_ON(skb_headroom(skb
) < 3)) {
1290 u8
*data
= skb
->data
;
1291 size_t len
= skb_headlen(skb
);
1293 memmove(skb
->data
, data
, len
);
1294 skb_set_tail_pointer(skb
, len
);
1300 /* deliver to local stack */
1301 skb
->protocol
= eth_type_trans(skb
, dev
);
1302 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1308 /* send to wireless media */
1309 xmit_skb
->protocol
= htons(ETH_P_802_3
);
1310 skb_reset_network_header(xmit_skb
);
1311 skb_reset_mac_header(xmit_skb
);
1312 dev_queue_xmit(xmit_skb
);
1316 static ieee80211_rx_result debug_noinline
1317 ieee80211_rx_h_amsdu(struct ieee80211_rx_data
*rx
)
1319 struct net_device
*dev
= rx
->sdata
->dev
;
1320 struct ieee80211_local
*local
= rx
->local
;
1323 struct sk_buff
*skb
= rx
->skb
, *frame
= NULL
;
1324 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1325 __le16 fc
= hdr
->frame_control
;
1326 const struct ethhdr
*eth
;
1331 if (unlikely(!ieee80211_is_data(fc
)))
1334 if (unlikely(!ieee80211_is_data_present(fc
)))
1335 return RX_DROP_MONITOR
;
1337 if (!(rx
->flags
& IEEE80211_RX_AMSDU
))
1340 err
= __ieee80211_data_to_8023(rx
);
1342 return RX_DROP_UNUSABLE
;
1346 dev
->stats
.rx_packets
++;
1347 dev
->stats
.rx_bytes
+= skb
->len
;
1349 /* skip the wrapping header */
1350 eth
= (struct ethhdr
*) skb_pull(skb
, sizeof(struct ethhdr
));
1352 return RX_DROP_UNUSABLE
;
1354 while (skb
!= frame
) {
1356 __be16 len
= eth
->h_proto
;
1357 unsigned int subframe_len
= sizeof(struct ethhdr
) + ntohs(len
);
1359 remaining
= skb
->len
;
1360 memcpy(dst
, eth
->h_dest
, ETH_ALEN
);
1361 memcpy(src
, eth
->h_source
, ETH_ALEN
);
1363 padding
= ((4 - subframe_len
) & 0x3);
1364 /* the last MSDU has no padding */
1365 if (subframe_len
> remaining
)
1366 return RX_DROP_UNUSABLE
;
1368 skb_pull(skb
, sizeof(struct ethhdr
));
1369 /* if last subframe reuse skb */
1370 if (remaining
<= subframe_len
+ padding
)
1374 * Allocate and reserve two bytes more for payload
1375 * alignment since sizeof(struct ethhdr) is 14.
1377 frame
= dev_alloc_skb(
1378 ALIGN(local
->hw
.extra_tx_headroom
, 4) +
1382 return RX_DROP_UNUSABLE
;
1385 ALIGN(local
->hw
.extra_tx_headroom
, 4) +
1386 sizeof(struct ethhdr
) + 2);
1387 memcpy(skb_put(frame
, ntohs(len
)), skb
->data
,
1390 eth
= (struct ethhdr
*) skb_pull(skb
, ntohs(len
) +
1393 dev_kfree_skb(frame
);
1394 return RX_DROP_UNUSABLE
;
1398 skb_reset_network_header(frame
);
1400 frame
->priority
= skb
->priority
;
1403 payload
= frame
->data
;
1404 ethertype
= (payload
[6] << 8) | payload
[7];
1406 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
1407 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
1408 compare_ether_addr(payload
,
1409 bridge_tunnel_header
) == 0)) {
1410 /* remove RFC1042 or Bridge-Tunnel
1411 * encapsulation and replace EtherType */
1413 memcpy(skb_push(frame
, ETH_ALEN
), src
, ETH_ALEN
);
1414 memcpy(skb_push(frame
, ETH_ALEN
), dst
, ETH_ALEN
);
1416 memcpy(skb_push(frame
, sizeof(__be16
)),
1417 &len
, sizeof(__be16
));
1418 memcpy(skb_push(frame
, ETH_ALEN
), src
, ETH_ALEN
);
1419 memcpy(skb_push(frame
, ETH_ALEN
), dst
, ETH_ALEN
);
1422 if (!ieee80211_frame_allowed(rx
, fc
)) {
1423 if (skb
== frame
) /* last frame */
1424 return RX_DROP_UNUSABLE
;
1425 dev_kfree_skb(frame
);
1429 ieee80211_deliver_skb(rx
);
1435 #ifdef CONFIG_MAC80211_MESH
1436 static ieee80211_rx_result
1437 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data
*rx
)
1439 struct ieee80211_hdr
*hdr
;
1440 struct ieee80211s_hdr
*mesh_hdr
;
1441 unsigned int hdrlen
;
1442 struct sk_buff
*skb
= rx
->skb
, *fwd_skb
;
1443 struct ieee80211_local
*local
= rx
->local
;
1444 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1446 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1447 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
1448 mesh_hdr
= (struct ieee80211s_hdr
*) (skb
->data
+ hdrlen
);
1450 if (!ieee80211_is_data(hdr
->frame_control
))
1455 return RX_DROP_MONITOR
;
1457 if (mesh_hdr
->flags
& MESH_FLAGS_AE
) {
1458 struct mesh_path
*mppath
;
1462 if (is_multicast_ether_addr(hdr
->addr1
)) {
1463 mpp_addr
= hdr
->addr3
;
1464 proxied_addr
= mesh_hdr
->eaddr1
;
1466 mpp_addr
= hdr
->addr4
;
1467 proxied_addr
= mesh_hdr
->eaddr2
;
1471 mppath
= mpp_path_lookup(proxied_addr
, sdata
);
1473 mpp_path_add(proxied_addr
, mpp_addr
, sdata
);
1475 spin_lock_bh(&mppath
->state_lock
);
1476 mppath
->exp_time
= jiffies
;
1477 if (compare_ether_addr(mppath
->mpp
, mpp_addr
) != 0)
1478 memcpy(mppath
->mpp
, mpp_addr
, ETH_ALEN
);
1479 spin_unlock_bh(&mppath
->state_lock
);
1484 /* Frame has reached destination. Don't forward */
1485 if (!is_multicast_ether_addr(hdr
->addr1
) &&
1486 compare_ether_addr(sdata
->dev
->dev_addr
, hdr
->addr3
) == 0)
1491 if (rx
->flags
& IEEE80211_RX_RA_MATCH
) {
1493 IEEE80211_IFSTA_MESH_CTR_INC(&rx
->sdata
->u
.mesh
,
1494 dropped_frames_ttl
);
1496 struct ieee80211_hdr
*fwd_hdr
;
1497 struct ieee80211_tx_info
*info
;
1499 fwd_skb
= skb_copy(skb
, GFP_ATOMIC
);
1501 if (!fwd_skb
&& net_ratelimit())
1502 printk(KERN_DEBUG
"%s: failed to clone mesh frame\n",
1505 fwd_hdr
= (struct ieee80211_hdr
*) fwd_skb
->data
;
1506 memcpy(fwd_hdr
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1507 info
= IEEE80211_SKB_CB(fwd_skb
);
1508 memset(info
, 0, sizeof(*info
));
1509 info
->flags
|= IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
1510 info
->control
.vif
= &rx
->sdata
->vif
;
1511 ieee80211_select_queue(local
, fwd_skb
);
1512 if (is_multicast_ether_addr(fwd_hdr
->addr1
))
1513 IEEE80211_IFSTA_MESH_CTR_INC(&sdata
->u
.mesh
,
1518 * Save TA to addr1 to send TA a path error if a
1519 * suitable next hop is not found
1521 memcpy(fwd_hdr
->addr1
, fwd_hdr
->addr2
,
1523 err
= mesh_nexthop_lookup(fwd_skb
, sdata
);
1524 /* Failed to immediately resolve next hop:
1525 * fwded frame was dropped or will be added
1526 * later to the pending skb queue. */
1528 return RX_DROP_MONITOR
;
1530 IEEE80211_IFSTA_MESH_CTR_INC(&sdata
->u
.mesh
,
1533 IEEE80211_IFSTA_MESH_CTR_INC(&sdata
->u
.mesh
,
1535 ieee80211_add_pending_skb(local
, fwd_skb
);
1539 if (is_multicast_ether_addr(hdr
->addr1
) ||
1540 sdata
->dev
->flags
& IFF_PROMISC
)
1543 return RX_DROP_MONITOR
;
1547 static ieee80211_rx_result debug_noinline
1548 ieee80211_rx_h_data(struct ieee80211_rx_data
*rx
)
1550 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1551 struct net_device
*dev
= sdata
->dev
;
1552 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
1553 __le16 fc
= hdr
->frame_control
;
1556 if (unlikely(!ieee80211_is_data(hdr
->frame_control
)))
1559 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
1560 return RX_DROP_MONITOR
;
1563 * Allow the cooked monitor interface of an AP to see 4-addr frames so
1564 * that a 4-addr station can be detected and moved into a separate VLAN
1566 if (ieee80211_has_a4(hdr
->frame_control
) &&
1567 sdata
->vif
.type
== NL80211_IFTYPE_AP
)
1568 return RX_DROP_MONITOR
;
1570 err
= __ieee80211_data_to_8023(rx
);
1572 return RX_DROP_UNUSABLE
;
1574 if (!ieee80211_frame_allowed(rx
, fc
))
1575 return RX_DROP_MONITOR
;
1579 dev
->stats
.rx_packets
++;
1580 dev
->stats
.rx_bytes
+= rx
->skb
->len
;
1582 ieee80211_deliver_skb(rx
);
1587 static ieee80211_rx_result debug_noinline
1588 ieee80211_rx_h_ctrl(struct ieee80211_rx_data
*rx
)
1590 struct ieee80211_local
*local
= rx
->local
;
1591 struct ieee80211_hw
*hw
= &local
->hw
;
1592 struct sk_buff
*skb
= rx
->skb
;
1593 struct ieee80211_bar
*bar
= (struct ieee80211_bar
*)skb
->data
;
1594 struct tid_ampdu_rx
*tid_agg_rx
;
1598 if (likely(!ieee80211_is_ctl(bar
->frame_control
)))
1601 if (ieee80211_is_back_req(bar
->frame_control
)) {
1603 return RX_DROP_MONITOR
;
1604 tid
= le16_to_cpu(bar
->control
) >> 12;
1605 if (rx
->sta
->ampdu_mlme
.tid_state_rx
[tid
]
1606 != HT_AGG_STATE_OPERATIONAL
)
1607 return RX_DROP_MONITOR
;
1608 tid_agg_rx
= rx
->sta
->ampdu_mlme
.tid_rx
[tid
];
1610 start_seq_num
= le16_to_cpu(bar
->start_seq_num
) >> 4;
1612 /* reset session timer */
1613 if (tid_agg_rx
->timeout
)
1614 mod_timer(&tid_agg_rx
->session_timer
,
1615 TU_TO_EXP_TIME(tid_agg_rx
->timeout
));
1617 /* release stored frames up to start of BAR */
1618 ieee80211_release_reorder_frames(hw
, tid_agg_rx
, start_seq_num
);
1626 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data
*sdata
,
1627 struct ieee80211_mgmt
*mgmt
,
1630 struct ieee80211_local
*local
= sdata
->local
;
1631 struct sk_buff
*skb
;
1632 struct ieee80211_mgmt
*resp
;
1634 if (compare_ether_addr(mgmt
->da
, sdata
->dev
->dev_addr
) != 0) {
1635 /* Not to own unicast address */
1639 if (compare_ether_addr(mgmt
->sa
, sdata
->u
.mgd
.bssid
) != 0 ||
1640 compare_ether_addr(mgmt
->bssid
, sdata
->u
.mgd
.bssid
) != 0) {
1641 /* Not from the current AP or not associated yet. */
1645 if (len
< 24 + 1 + sizeof(resp
->u
.action
.u
.sa_query
)) {
1646 /* Too short SA Query request frame */
1650 skb
= dev_alloc_skb(sizeof(*resp
) + local
->hw
.extra_tx_headroom
);
1654 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1655 resp
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1656 memset(resp
, 0, 24);
1657 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
1658 memcpy(resp
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1659 memcpy(resp
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
1660 resp
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1661 IEEE80211_STYPE_ACTION
);
1662 skb_put(skb
, 1 + sizeof(resp
->u
.action
.u
.sa_query
));
1663 resp
->u
.action
.category
= WLAN_CATEGORY_SA_QUERY
;
1664 resp
->u
.action
.u
.sa_query
.action
= WLAN_ACTION_SA_QUERY_RESPONSE
;
1665 memcpy(resp
->u
.action
.u
.sa_query
.trans_id
,
1666 mgmt
->u
.action
.u
.sa_query
.trans_id
,
1667 WLAN_SA_QUERY_TR_ID_LEN
);
1669 ieee80211_tx_skb(sdata
, skb
);
1672 static ieee80211_rx_result debug_noinline
1673 ieee80211_rx_h_action(struct ieee80211_rx_data
*rx
)
1675 struct ieee80211_local
*local
= rx
->local
;
1676 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1677 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
1678 int len
= rx
->skb
->len
;
1680 if (!ieee80211_is_action(mgmt
->frame_control
))
1684 return RX_DROP_MONITOR
;
1686 if (!(rx
->flags
& IEEE80211_RX_RA_MATCH
))
1687 return RX_DROP_MONITOR
;
1689 if (ieee80211_drop_unencrypted(rx
, mgmt
->frame_control
))
1690 return RX_DROP_MONITOR
;
1692 /* all categories we currently handle have action_code */
1693 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
1694 return RX_DROP_MONITOR
;
1696 switch (mgmt
->u
.action
.category
) {
1697 case WLAN_CATEGORY_BACK
:
1699 * The aggregation code is not prepared to handle
1700 * anything but STA/AP due to the BSSID handling;
1701 * IBSS could work in the code but isn't supported
1702 * by drivers or the standard.
1704 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
1705 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
1706 sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
1707 return RX_DROP_MONITOR
;
1709 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
1710 case WLAN_ACTION_ADDBA_REQ
:
1711 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
1712 sizeof(mgmt
->u
.action
.u
.addba_req
)))
1713 return RX_DROP_MONITOR
;
1714 ieee80211_process_addba_request(local
, rx
->sta
, mgmt
, len
);
1716 case WLAN_ACTION_ADDBA_RESP
:
1717 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
1718 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
1719 return RX_DROP_MONITOR
;
1720 ieee80211_process_addba_resp(local
, rx
->sta
, mgmt
, len
);
1722 case WLAN_ACTION_DELBA
:
1723 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
1724 sizeof(mgmt
->u
.action
.u
.delba
)))
1725 return RX_DROP_MONITOR
;
1726 ieee80211_process_delba(sdata
, rx
->sta
, mgmt
, len
);
1730 case WLAN_CATEGORY_SPECTRUM_MGMT
:
1731 if (local
->hw
.conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
1732 return RX_DROP_MONITOR
;
1734 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1735 return RX_DROP_MONITOR
;
1737 switch (mgmt
->u
.action
.u
.measurement
.action_code
) {
1738 case WLAN_ACTION_SPCT_MSR_REQ
:
1739 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
1740 sizeof(mgmt
->u
.action
.u
.measurement
)))
1741 return RX_DROP_MONITOR
;
1742 ieee80211_process_measurement_req(sdata
, mgmt
, len
);
1744 case WLAN_ACTION_SPCT_CHL_SWITCH
:
1745 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
1746 sizeof(mgmt
->u
.action
.u
.chan_switch
)))
1747 return RX_DROP_MONITOR
;
1749 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1750 return RX_DROP_MONITOR
;
1752 if (memcmp(mgmt
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
))
1753 return RX_DROP_MONITOR
;
1755 return ieee80211_sta_rx_mgmt(sdata
, rx
->skb
);
1758 case WLAN_CATEGORY_SA_QUERY
:
1759 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
1760 sizeof(mgmt
->u
.action
.u
.sa_query
)))
1761 return RX_DROP_MONITOR
;
1762 switch (mgmt
->u
.action
.u
.sa_query
.action
) {
1763 case WLAN_ACTION_SA_QUERY_REQUEST
:
1764 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1765 return RX_DROP_MONITOR
;
1766 ieee80211_process_sa_query_req(sdata
, mgmt
, len
);
1768 case WLAN_ACTION_SA_QUERY_RESPONSE
:
1770 * SA Query response is currently only used in AP mode
1771 * and it is processed in user space.
1780 rx
->sta
->rx_packets
++;
1781 dev_kfree_skb(rx
->skb
);
1785 static ieee80211_rx_result debug_noinline
1786 ieee80211_rx_h_mgmt(struct ieee80211_rx_data
*rx
)
1788 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1789 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
1791 if (!(rx
->flags
& IEEE80211_RX_RA_MATCH
))
1792 return RX_DROP_MONITOR
;
1794 if (ieee80211_drop_unencrypted(rx
, mgmt
->frame_control
))
1795 return RX_DROP_MONITOR
;
1797 if (ieee80211_vif_is_mesh(&sdata
->vif
))
1798 return ieee80211_mesh_rx_mgmt(sdata
, rx
->skb
);
1800 if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
)
1801 return ieee80211_ibss_rx_mgmt(sdata
, rx
->skb
);
1803 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
1804 return ieee80211_sta_rx_mgmt(sdata
, rx
->skb
);
1806 return RX_DROP_MONITOR
;
1809 static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr
*hdr
,
1810 struct ieee80211_rx_data
*rx
)
1813 unsigned int hdrlen
;
1815 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
1816 if (rx
->skb
->len
>= hdrlen
+ 4)
1817 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
1823 * Some hardware seem to generate incorrect Michael MIC
1824 * reports; ignore them to avoid triggering countermeasures.
1829 if (!ieee80211_has_protected(hdr
->frame_control
))
1832 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
&& keyidx
) {
1834 * APs with pairwise keys should never receive Michael MIC
1835 * errors for non-zero keyidx because these are reserved for
1836 * group keys and only the AP is sending real multicast
1837 * frames in the BSS.
1842 if (!ieee80211_is_data(hdr
->frame_control
) &&
1843 !ieee80211_is_auth(hdr
->frame_control
))
1846 mac80211_ev_michael_mic_failure(rx
->sdata
, keyidx
, hdr
, NULL
,
1850 /* TODO: use IEEE80211_RX_FRAGMENTED */
1851 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data
*rx
,
1852 struct ieee80211_rate
*rate
)
1854 struct ieee80211_sub_if_data
*sdata
;
1855 struct ieee80211_local
*local
= rx
->local
;
1856 struct ieee80211_rtap_hdr
{
1857 struct ieee80211_radiotap_header hdr
;
1862 } __attribute__ ((packed
)) *rthdr
;
1863 struct sk_buff
*skb
= rx
->skb
, *skb2
;
1864 struct net_device
*prev_dev
= NULL
;
1865 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1867 if (rx
->flags
& IEEE80211_RX_CMNTR_REPORTED
)
1870 if (skb_headroom(skb
) < sizeof(*rthdr
) &&
1871 pskb_expand_head(skb
, sizeof(*rthdr
), 0, GFP_ATOMIC
))
1874 rthdr
= (void *)skb_push(skb
, sizeof(*rthdr
));
1875 memset(rthdr
, 0, sizeof(*rthdr
));
1876 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1877 rthdr
->hdr
.it_present
=
1878 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS
) |
1879 (1 << IEEE80211_RADIOTAP_CHANNEL
));
1882 rthdr
->rate_or_pad
= rate
->bitrate
/ 5;
1883 rthdr
->hdr
.it_present
|=
1884 cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE
);
1886 rthdr
->chan_freq
= cpu_to_le16(status
->freq
);
1888 if (status
->band
== IEEE80211_BAND_5GHZ
)
1889 rthdr
->chan_flags
= cpu_to_le16(IEEE80211_CHAN_OFDM
|
1890 IEEE80211_CHAN_5GHZ
);
1892 rthdr
->chan_flags
= cpu_to_le16(IEEE80211_CHAN_DYN
|
1893 IEEE80211_CHAN_2GHZ
);
1895 skb_set_mac_header(skb
, 0);
1896 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1897 skb
->pkt_type
= PACKET_OTHERHOST
;
1898 skb
->protocol
= htons(ETH_P_802_2
);
1900 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1901 if (!netif_running(sdata
->dev
))
1904 if (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
||
1905 !(sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
))
1909 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1911 skb2
->dev
= prev_dev
;
1916 prev_dev
= sdata
->dev
;
1917 sdata
->dev
->stats
.rx_packets
++;
1918 sdata
->dev
->stats
.rx_bytes
+= skb
->len
;
1922 skb
->dev
= prev_dev
;
1928 rx
->flags
|= IEEE80211_RX_CMNTR_REPORTED
;
1936 static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data
*sdata
,
1937 struct ieee80211_rx_data
*rx
,
1938 struct sk_buff
*skb
,
1939 struct ieee80211_rate
*rate
)
1941 ieee80211_rx_result res
= RX_DROP_MONITOR
;
1946 #define CALL_RXH(rxh) \
1949 if (res != RX_CONTINUE) \
1953 CALL_RXH(ieee80211_rx_h_passive_scan
)
1954 CALL_RXH(ieee80211_rx_h_check
)
1955 CALL_RXH(ieee80211_rx_h_decrypt
)
1956 CALL_RXH(ieee80211_rx_h_check_more_data
)
1957 CALL_RXH(ieee80211_rx_h_sta_process
)
1958 CALL_RXH(ieee80211_rx_h_defragment
)
1959 CALL_RXH(ieee80211_rx_h_ps_poll
)
1960 CALL_RXH(ieee80211_rx_h_michael_mic_verify
)
1961 /* must be after MMIC verify so header is counted in MPDU mic */
1962 CALL_RXH(ieee80211_rx_h_remove_qos_control
)
1963 CALL_RXH(ieee80211_rx_h_amsdu
)
1964 #ifdef CONFIG_MAC80211_MESH
1965 if (ieee80211_vif_is_mesh(&sdata
->vif
))
1966 CALL_RXH(ieee80211_rx_h_mesh_fwding
);
1968 CALL_RXH(ieee80211_rx_h_data
)
1969 CALL_RXH(ieee80211_rx_h_ctrl
)
1970 CALL_RXH(ieee80211_rx_h_action
)
1971 CALL_RXH(ieee80211_rx_h_mgmt
)
1977 case RX_DROP_MONITOR
:
1978 I802_DEBUG_INC(sdata
->local
->rx_handlers_drop
);
1980 rx
->sta
->rx_dropped
++;
1983 ieee80211_rx_cooked_monitor(rx
, rate
);
1985 case RX_DROP_UNUSABLE
:
1986 I802_DEBUG_INC(sdata
->local
->rx_handlers_drop
);
1988 rx
->sta
->rx_dropped
++;
1989 dev_kfree_skb(rx
->skb
);
1992 I802_DEBUG_INC(sdata
->local
->rx_handlers_queued
);
1997 /* main receive path */
1999 static int prepare_for_handlers(struct ieee80211_sub_if_data
*sdata
,
2000 struct ieee80211_rx_data
*rx
,
2001 struct ieee80211_hdr
*hdr
)
2003 struct sk_buff
*skb
= rx
->skb
;
2004 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2005 u8
*bssid
= ieee80211_get_bssid(hdr
, skb
->len
, sdata
->vif
.type
);
2006 int multicast
= is_multicast_ether_addr(hdr
->addr1
);
2008 switch (sdata
->vif
.type
) {
2009 case NL80211_IFTYPE_STATION
:
2010 if (!bssid
&& !sdata
->use_4addr
)
2013 compare_ether_addr(sdata
->dev
->dev_addr
, hdr
->addr1
) != 0) {
2014 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
2016 rx
->flags
&= ~IEEE80211_RX_RA_MATCH
;
2019 case NL80211_IFTYPE_ADHOC
:
2022 if (ieee80211_is_beacon(hdr
->frame_control
)) {
2025 else if (!ieee80211_bssid_match(bssid
, sdata
->u
.ibss
.bssid
)) {
2026 if (!(rx
->flags
& IEEE80211_RX_IN_SCAN
))
2028 rx
->flags
&= ~IEEE80211_RX_RA_MATCH
;
2029 } else if (!multicast
&&
2030 compare_ether_addr(sdata
->dev
->dev_addr
,
2032 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
2034 rx
->flags
&= ~IEEE80211_RX_RA_MATCH
;
2035 } else if (!rx
->sta
) {
2037 if (status
->flag
& RX_FLAG_HT
)
2038 rate_idx
= 0; /* TODO: HT rates */
2040 rate_idx
= status
->rate_idx
;
2041 rx
->sta
= ieee80211_ibss_add_sta(sdata
, bssid
, hdr
->addr2
,
2045 case NL80211_IFTYPE_MESH_POINT
:
2047 compare_ether_addr(sdata
->dev
->dev_addr
,
2049 if (!(sdata
->dev
->flags
& IFF_PROMISC
))
2052 rx
->flags
&= ~IEEE80211_RX_RA_MATCH
;
2055 case NL80211_IFTYPE_AP_VLAN
:
2056 case NL80211_IFTYPE_AP
:
2058 if (compare_ether_addr(sdata
->dev
->dev_addr
,
2061 } else if (!ieee80211_bssid_match(bssid
,
2062 sdata
->dev
->dev_addr
)) {
2063 if (!(rx
->flags
& IEEE80211_RX_IN_SCAN
))
2065 rx
->flags
&= ~IEEE80211_RX_RA_MATCH
;
2068 case NL80211_IFTYPE_WDS
:
2069 if (bssid
|| !ieee80211_is_data(hdr
->frame_control
))
2071 if (compare_ether_addr(sdata
->u
.wds
.remote_addr
, hdr
->addr2
))
2074 case NL80211_IFTYPE_MONITOR
:
2075 case NL80211_IFTYPE_UNSPECIFIED
:
2076 case __NL80211_IFTYPE_AFTER_LAST
:
2077 /* should never get here */
2086 * This is the actual Rx frames handler. as it blongs to Rx path it must
2087 * be called with rcu_read_lock protection.
2089 static void __ieee80211_rx_handle_packet(struct ieee80211_hw
*hw
,
2090 struct sk_buff
*skb
,
2091 struct ieee80211_rate
*rate
)
2093 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2094 struct ieee80211_local
*local
= hw_to_local(hw
);
2095 struct ieee80211_sub_if_data
*sdata
;
2096 struct ieee80211_hdr
*hdr
;
2097 struct ieee80211_rx_data rx
;
2099 struct ieee80211_sub_if_data
*prev
= NULL
;
2100 struct sk_buff
*skb_new
;
2102 hdr
= (struct ieee80211_hdr
*)skb
->data
;
2103 memset(&rx
, 0, sizeof(rx
));
2107 if (ieee80211_is_data(hdr
->frame_control
) || ieee80211_is_mgmt(hdr
->frame_control
))
2108 local
->dot11ReceivedFragmentCount
++;
2110 if (unlikely(test_bit(SCAN_HW_SCANNING
, &local
->scanning
) ||
2111 test_bit(SCAN_OFF_CHANNEL
, &local
->scanning
)))
2112 rx
.flags
|= IEEE80211_RX_IN_SCAN
;
2114 ieee80211_parse_qos(&rx
);
2115 ieee80211_verify_alignment(&rx
);
2117 rx
.sta
= sta_info_get(local
, hdr
->addr2
);
2119 rx
.sdata
= rx
.sta
->sdata
;
2121 if (rx
.sdata
&& ieee80211_is_data(hdr
->frame_control
)) {
2122 rx
.flags
|= IEEE80211_RX_RA_MATCH
;
2123 prepares
= prepare_for_handlers(rx
.sdata
, &rx
, hdr
);
2125 if (status
->flag
& RX_FLAG_MMIC_ERROR
) {
2126 if (rx
.flags
& IEEE80211_RX_RA_MATCH
)
2127 ieee80211_rx_michael_mic_report(hdr
, &rx
);
2131 } else list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
2132 if (!netif_running(sdata
->dev
))
2135 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
||
2136 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
2139 rx
.flags
|= IEEE80211_RX_RA_MATCH
;
2140 prepares
= prepare_for_handlers(sdata
, &rx
, hdr
);
2145 if (status
->flag
& RX_FLAG_MMIC_ERROR
) {
2147 if (rx
.flags
& IEEE80211_RX_RA_MATCH
)
2148 ieee80211_rx_michael_mic_report(hdr
, &rx
);
2153 * frame is destined for this interface, but if it's not
2154 * also for the previous one we handle that after the
2155 * loop to avoid copying the SKB once too much
2164 * frame was destined for the previous interface
2165 * so invoke RX handlers for it
2168 skb_new
= skb_copy(skb
, GFP_ATOMIC
);
2170 if (net_ratelimit())
2171 printk(KERN_DEBUG
"%s: failed to copy "
2172 "multicast frame for %s\n",
2173 wiphy_name(local
->hw
.wiphy
),
2177 ieee80211_invoke_rx_handlers(prev
, &rx
, skb_new
, rate
);
2181 ieee80211_invoke_rx_handlers(prev
, &rx
, skb
, rate
);
2186 #define SEQ_MODULO 0x1000
2187 #define SEQ_MASK 0xfff
2189 static inline int seq_less(u16 sq1
, u16 sq2
)
2191 return ((sq1
- sq2
) & SEQ_MASK
) > (SEQ_MODULO
>> 1);
2194 static inline u16
seq_inc(u16 sq
)
2196 return (sq
+ 1) & SEQ_MASK
;
2199 static inline u16
seq_sub(u16 sq1
, u16 sq2
)
2201 return (sq1
- sq2
) & SEQ_MASK
;
2205 static void ieee80211_release_reorder_frame(struct ieee80211_hw
*hw
,
2206 struct tid_ampdu_rx
*tid_agg_rx
,
2209 struct ieee80211_supported_band
*sband
;
2210 struct ieee80211_rate
*rate
= NULL
;
2211 struct sk_buff
*skb
= tid_agg_rx
->reorder_buf
[index
];
2212 struct ieee80211_rx_status
*status
;
2217 status
= IEEE80211_SKB_RXCB(skb
);
2219 /* release the reordered frames to stack */
2220 sband
= hw
->wiphy
->bands
[status
->band
];
2221 if (!(status
->flag
& RX_FLAG_HT
))
2222 rate
= &sband
->bitrates
[status
->rate_idx
];
2223 __ieee80211_rx_handle_packet(hw
, skb
, rate
);
2224 tid_agg_rx
->stored_mpdu_num
--;
2225 tid_agg_rx
->reorder_buf
[index
] = NULL
;
2228 tid_agg_rx
->head_seq_num
= seq_inc(tid_agg_rx
->head_seq_num
);
2231 static void ieee80211_release_reorder_frames(struct ieee80211_hw
*hw
,
2232 struct tid_ampdu_rx
*tid_agg_rx
,
2237 while (seq_less(tid_agg_rx
->head_seq_num
, head_seq_num
)) {
2238 index
= seq_sub(tid_agg_rx
->head_seq_num
, tid_agg_rx
->ssn
) %
2239 tid_agg_rx
->buf_size
;
2240 ieee80211_release_reorder_frame(hw
, tid_agg_rx
, index
);
2245 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
2246 * the skb was added to the buffer longer than this time ago, the earlier
2247 * frames that have not yet been received are assumed to be lost and the skb
2248 * can be released for processing. This may also release other skb's from the
2249 * reorder buffer if there are no additional gaps between the frames.
2251 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
2254 * As this function belongs to the RX path it must be under
2255 * rcu_read_lock protection. It returns false if the frame
2256 * can be processed immediately, true if it was consumed.
2258 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw
*hw
,
2259 struct tid_ampdu_rx
*tid_agg_rx
,
2260 struct sk_buff
*skb
)
2262 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
2263 u16 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2264 u16 mpdu_seq_num
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2265 u16 head_seq_num
, buf_size
;
2268 buf_size
= tid_agg_rx
->buf_size
;
2269 head_seq_num
= tid_agg_rx
->head_seq_num
;
2271 /* frame with out of date sequence number */
2272 if (seq_less(mpdu_seq_num
, head_seq_num
)) {
2278 * If frame the sequence number exceeds our buffering window
2279 * size release some previous frames to make room for this one.
2281 if (!seq_less(mpdu_seq_num
, head_seq_num
+ buf_size
)) {
2282 head_seq_num
= seq_inc(seq_sub(mpdu_seq_num
, buf_size
));
2283 /* release stored frames up to new head to stack */
2284 ieee80211_release_reorder_frames(hw
, tid_agg_rx
, head_seq_num
);
2287 /* Now the new frame is always in the range of the reordering buffer */
2289 index
= seq_sub(mpdu_seq_num
, tid_agg_rx
->ssn
) % tid_agg_rx
->buf_size
;
2291 /* check if we already stored this frame */
2292 if (tid_agg_rx
->reorder_buf
[index
]) {
2298 * If the current MPDU is in the right order and nothing else
2299 * is stored we can process it directly, no need to buffer it.
2301 if (mpdu_seq_num
== tid_agg_rx
->head_seq_num
&&
2302 tid_agg_rx
->stored_mpdu_num
== 0) {
2303 tid_agg_rx
->head_seq_num
= seq_inc(tid_agg_rx
->head_seq_num
);
2307 /* put the frame in the reordering buffer */
2308 tid_agg_rx
->reorder_buf
[index
] = skb
;
2309 tid_agg_rx
->reorder_time
[index
] = jiffies
;
2310 tid_agg_rx
->stored_mpdu_num
++;
2311 /* release the buffer until next missing frame */
2312 index
= seq_sub(tid_agg_rx
->head_seq_num
, tid_agg_rx
->ssn
) %
2313 tid_agg_rx
->buf_size
;
2314 if (!tid_agg_rx
->reorder_buf
[index
] &&
2315 tid_agg_rx
->stored_mpdu_num
> 1) {
2317 * No buffers ready to be released, but check whether any
2318 * frames in the reorder buffer have timed out.
2322 for (j
= (index
+ 1) % tid_agg_rx
->buf_size
; j
!= index
;
2323 j
= (j
+ 1) % tid_agg_rx
->buf_size
) {
2324 if (!tid_agg_rx
->reorder_buf
[j
]) {
2328 if (!time_after(jiffies
, tid_agg_rx
->reorder_time
[j
] +
2329 HT_RX_REORDER_BUF_TIMEOUT
))
2332 #ifdef CONFIG_MAC80211_HT_DEBUG
2333 if (net_ratelimit())
2334 printk(KERN_DEBUG
"%s: release an RX reorder "
2335 "frame due to timeout on earlier "
2337 wiphy_name(hw
->wiphy
));
2339 ieee80211_release_reorder_frame(hw
, tid_agg_rx
, j
);
2342 * Increment the head seq# also for the skipped slots.
2344 tid_agg_rx
->head_seq_num
=
2345 (tid_agg_rx
->head_seq_num
+ skipped
) & SEQ_MASK
;
2348 } else while (tid_agg_rx
->reorder_buf
[index
]) {
2349 ieee80211_release_reorder_frame(hw
, tid_agg_rx
, index
);
2350 index
= seq_sub(tid_agg_rx
->head_seq_num
, tid_agg_rx
->ssn
) %
2351 tid_agg_rx
->buf_size
;
2358 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
2359 * true if the MPDU was buffered, false if it should be processed.
2361 static bool ieee80211_rx_reorder_ampdu(struct ieee80211_local
*local
,
2362 struct sk_buff
*skb
)
2364 struct ieee80211_hw
*hw
= &local
->hw
;
2365 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
2366 struct sta_info
*sta
;
2367 struct tid_ampdu_rx
*tid_agg_rx
;
2371 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2375 * filter the QoS data rx stream according to
2376 * STA/TID and check if this STA/TID is on aggregation
2379 sta
= sta_info_get(local
, hdr
->addr2
);
2383 tid
= *ieee80211_get_qos_ctl(hdr
) & IEEE80211_QOS_CTL_TID_MASK
;
2385 if (sta
->ampdu_mlme
.tid_state_rx
[tid
] != HT_AGG_STATE_OPERATIONAL
)
2388 tid_agg_rx
= sta
->ampdu_mlme
.tid_rx
[tid
];
2390 /* qos null data frames are excluded */
2391 if (unlikely(hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_NULLFUNC
)))
2394 /* new, potentially un-ordered, ampdu frame - process it */
2396 /* reset session timer */
2397 if (tid_agg_rx
->timeout
)
2398 mod_timer(&tid_agg_rx
->session_timer
,
2399 TU_TO_EXP_TIME(tid_agg_rx
->timeout
));
2401 /* if this mpdu is fragmented - terminate rx aggregation session */
2402 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2403 if (sc
& IEEE80211_SCTL_FRAG
) {
2404 ieee80211_sta_stop_rx_ba_session(sta
->sdata
, sta
->sta
.addr
,
2405 tid
, 0, WLAN_REASON_QSTA_REQUIRE_SETUP
);
2410 return ieee80211_sta_manage_reorder_buf(hw
, tid_agg_rx
, skb
);
2414 * This is the receive path handler. It is called by a low level driver when an
2415 * 802.11 MPDU is received from the hardware.
2417 void ieee80211_rx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2419 struct ieee80211_local
*local
= hw_to_local(hw
);
2420 struct ieee80211_rate
*rate
= NULL
;
2421 struct ieee80211_supported_band
*sband
;
2422 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2424 WARN_ON_ONCE(softirq_count() == 0);
2426 if (WARN_ON(status
->band
< 0 ||
2427 status
->band
>= IEEE80211_NUM_BANDS
))
2430 sband
= local
->hw
.wiphy
->bands
[status
->band
];
2431 if (WARN_ON(!sband
))
2435 * If we're suspending, it is possible although not too likely
2436 * that we'd be receiving frames after having already partially
2437 * quiesced the stack. We can't process such frames then since
2438 * that might, for example, cause stations to be added or other
2439 * driver callbacks be invoked.
2441 if (unlikely(local
->quiescing
|| local
->suspended
))
2445 * The same happens when we're not even started,
2446 * but that's worth a warning.
2448 if (WARN_ON(!local
->started
))
2451 if (status
->flag
& RX_FLAG_HT
) {
2453 * rate_idx is MCS index, which can be [0-76] as documented on:
2455 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
2457 * Anything else would be some sort of driver or hardware error.
2458 * The driver should catch hardware errors.
2460 if (WARN((status
->rate_idx
< 0 ||
2461 status
->rate_idx
> 76),
2462 "Rate marked as an HT rate but passed "
2463 "status->rate_idx is not "
2464 "an MCS index [0-76]: %d (0x%02x)\n",
2469 if (WARN_ON(status
->rate_idx
< 0 ||
2470 status
->rate_idx
>= sband
->n_bitrates
))
2472 rate
= &sband
->bitrates
[status
->rate_idx
];
2476 * key references and virtual interfaces are protected using RCU
2477 * and this requires that we are in a read-side RCU section during
2478 * receive processing
2483 * Frames with failed FCS/PLCP checksum are not returned,
2484 * all other frames are returned without radiotap header
2485 * if it was previously present.
2486 * Also, frames with less than 16 bytes are dropped.
2488 skb
= ieee80211_rx_monitor(local
, skb
, rate
);
2495 * In theory, the block ack reordering should happen after duplicate
2496 * removal (ieee80211_rx_h_check(), which is an RX handler). As such,
2497 * the call to ieee80211_rx_reorder_ampdu() should really be moved to
2498 * happen as a new RX handler between ieee80211_rx_h_check and
2499 * ieee80211_rx_h_decrypt. This cleanup may eventually happen, but for
2500 * the time being, the call can be here since RX reorder buf processing
2501 * will implicitly skip duplicates. We could, in theory at least,
2502 * process frames that ieee80211_rx_h_passive_scan would drop (e.g.,
2503 * frames from other than operational channel), but that should not
2504 * happen in normal networks.
2506 if (!ieee80211_rx_reorder_ampdu(local
, skb
))
2507 __ieee80211_rx_handle_packet(hw
, skb
, rate
);
2515 EXPORT_SYMBOL(ieee80211_rx
);
2517 /* This is a version of the rx handler that can be called from hard irq
2518 * context. Post the skb on the queue and schedule the tasklet */
2519 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2521 struct ieee80211_local
*local
= hw_to_local(hw
);
2523 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
));
2525 skb
->pkt_type
= IEEE80211_RX_MSG
;
2526 skb_queue_tail(&local
->skb_queue
, skb
);
2527 tasklet_schedule(&local
->tasklet
);
2529 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);