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-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
8 * Copyright (C) 2018 Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/jiffies.h>
16 #include <linux/slab.h>
17 #include <linux/kernel.h>
18 #include <linux/skbuff.h>
19 #include <linux/netdevice.h>
20 #include <linux/etherdevice.h>
21 #include <linux/rcupdate.h>
22 #include <linux/export.h>
23 #include <linux/bitops.h>
24 #include <net/mac80211.h>
25 #include <net/ieee80211_radiotap.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
38 static inline void ieee80211_rx_stats(struct net_device
*dev
, u32 len
)
40 struct pcpu_sw_netstats
*tstats
= this_cpu_ptr(dev
->tstats
);
42 u64_stats_update_begin(&tstats
->syncp
);
44 tstats
->rx_bytes
+= len
;
45 u64_stats_update_end(&tstats
->syncp
);
48 static u8
*ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
,
49 enum nl80211_iftype type
)
51 __le16 fc
= hdr
->frame_control
;
53 if (ieee80211_is_data(fc
)) {
54 if (len
< 24) /* drop incorrect hdr len (data) */
57 if (ieee80211_has_a4(fc
))
59 if (ieee80211_has_tods(fc
))
61 if (ieee80211_has_fromds(fc
))
67 if (ieee80211_is_mgmt(fc
)) {
68 if (len
< 24) /* drop incorrect hdr len (mgmt) */
73 if (ieee80211_is_ctl(fc
)) {
74 if (ieee80211_is_pspoll(fc
))
77 if (ieee80211_is_back_req(fc
)) {
79 case NL80211_IFTYPE_STATION
:
81 case NL80211_IFTYPE_AP
:
82 case NL80211_IFTYPE_AP_VLAN
:
85 break; /* fall through to the return */
94 * monitor mode reception
96 * This function cleans up the SKB, i.e. it removes all the stuff
97 * only useful for monitoring.
99 static void remove_monitor_info(struct sk_buff
*skb
,
100 unsigned int present_fcs_len
,
101 unsigned int rtap_space
)
104 __pskb_trim(skb
, skb
->len
- present_fcs_len
);
105 __pskb_pull(skb
, rtap_space
);
108 static inline bool should_drop_frame(struct sk_buff
*skb
, int present_fcs_len
,
109 unsigned int rtap_space
)
111 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
112 struct ieee80211_hdr
*hdr
;
114 hdr
= (void *)(skb
->data
+ rtap_space
);
116 if (status
->flag
& (RX_FLAG_FAILED_FCS_CRC
|
117 RX_FLAG_FAILED_PLCP_CRC
|
118 RX_FLAG_ONLY_MONITOR
))
121 if (unlikely(skb
->len
< 16 + present_fcs_len
+ rtap_space
))
124 if (ieee80211_is_ctl(hdr
->frame_control
) &&
125 !ieee80211_is_pspoll(hdr
->frame_control
) &&
126 !ieee80211_is_back_req(hdr
->frame_control
))
133 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local
*local
,
134 struct ieee80211_rx_status
*status
,
139 /* always present fields */
140 len
= sizeof(struct ieee80211_radiotap_header
) + 8;
142 /* allocate extra bitmaps */
144 len
+= 4 * hweight8(status
->chains
);
145 /* vendor presence bitmap */
146 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
)
149 if (ieee80211_have_rx_timestamp(status
)) {
153 if (ieee80211_hw_check(&local
->hw
, SIGNAL_DBM
))
156 /* antenna field, if we don't have per-chain info */
160 /* padding for RX_FLAGS if necessary */
163 if (status
->encoding
== RX_ENC_HT
) /* HT info */
166 if (status
->flag
& RX_FLAG_AMPDU_DETAILS
) {
171 if (status
->encoding
== RX_ENC_VHT
) {
176 if (local
->hw
.radiotap_timestamp
.units_pos
>= 0) {
181 if (status
->encoding
== RX_ENC_HE
&&
182 status
->flag
& RX_FLAG_RADIOTAP_HE
) {
185 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he
) != 12);
188 if (status
->encoding
== RX_ENC_HE
&&
189 status
->flag
& RX_FLAG_RADIOTAP_HE_MU
) {
192 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu
) != 12);
195 if (status
->chains
) {
196 /* antenna and antenna signal fields */
197 len
+= 2 * hweight8(status
->chains
);
200 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
201 struct ieee80211_vendor_radiotap
*rtap
= (void *)skb
->data
;
203 /* alignment for fixed 6-byte vendor data header */
205 /* vendor data header */
207 if (WARN_ON(rtap
->align
== 0))
209 len
= ALIGN(len
, rtap
->align
);
210 len
+= rtap
->len
+ rtap
->pad
;
216 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data
*sdata
,
221 struct ieee80211_hdr_3addr hdr
;
224 } __packed
__aligned(2) action
;
229 BUILD_BUG_ON(sizeof(action
) != IEEE80211_MIN_ACTION_SIZE
+ 1);
231 if (skb
->len
< rtap_space
+ sizeof(action
) +
232 VHT_MUMIMO_GROUPS_DATA_LEN
)
235 if (!is_valid_ether_addr(sdata
->u
.mntr
.mu_follow_addr
))
238 skb_copy_bits(skb
, rtap_space
, &action
, sizeof(action
));
240 if (!ieee80211_is_action(action
.hdr
.frame_control
))
243 if (action
.category
!= WLAN_CATEGORY_VHT
)
246 if (action
.action_code
!= WLAN_VHT_ACTION_GROUPID_MGMT
)
249 if (!ether_addr_equal(action
.hdr
.addr1
, sdata
->u
.mntr
.mu_follow_addr
))
252 skb
= skb_copy(skb
, GFP_ATOMIC
);
256 skb_queue_tail(&sdata
->skb_queue
, skb
);
257 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
261 * ieee80211_add_rx_radiotap_header - add radiotap header
263 * add a radiotap header containing all the fields which the hardware provided.
266 ieee80211_add_rx_radiotap_header(struct ieee80211_local
*local
,
268 struct ieee80211_rate
*rate
,
269 int rtap_len
, bool has_fcs
)
271 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
272 struct ieee80211_radiotap_header
*rthdr
;
277 u16 channel_flags
= 0;
279 unsigned long chains
= status
->chains
;
280 struct ieee80211_vendor_radiotap rtap
= {};
281 struct ieee80211_radiotap_he he
= {};
282 struct ieee80211_radiotap_he_mu he_mu
= {};
284 if (status
->flag
& RX_FLAG_RADIOTAP_HE
) {
285 he
= *(struct ieee80211_radiotap_he
*)skb
->data
;
286 skb_pull(skb
, sizeof(he
));
287 WARN_ON_ONCE(status
->encoding
!= RX_ENC_HE
);
290 if (status
->flag
& RX_FLAG_RADIOTAP_HE_MU
) {
291 he_mu
= *(struct ieee80211_radiotap_he_mu
*)skb
->data
;
292 skb_pull(skb
, sizeof(he_mu
));
295 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
296 rtap
= *(struct ieee80211_vendor_radiotap
*)skb
->data
;
297 /* rtap.len and rtap.pad are undone immediately */
298 skb_pull(skb
, sizeof(rtap
) + rtap
.len
+ rtap
.pad
);
302 if (!(has_fcs
&& ieee80211_hw_check(&local
->hw
, RX_INCLUDES_FCS
)))
305 rthdr
= skb_push(skb
, rtap_len
);
306 memset(rthdr
, 0, rtap_len
- rtap
.len
- rtap
.pad
);
307 it_present
= &rthdr
->it_present
;
309 /* radiotap header, set always present flags */
310 rthdr
->it_len
= cpu_to_le16(rtap_len
);
311 it_present_val
= BIT(IEEE80211_RADIOTAP_FLAGS
) |
312 BIT(IEEE80211_RADIOTAP_CHANNEL
) |
313 BIT(IEEE80211_RADIOTAP_RX_FLAGS
);
316 it_present_val
|= BIT(IEEE80211_RADIOTAP_ANTENNA
);
318 for_each_set_bit(chain
, &chains
, IEEE80211_MAX_CHAINS
) {
320 BIT(IEEE80211_RADIOTAP_EXT
) |
321 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE
);
322 put_unaligned_le32(it_present_val
, it_present
);
324 it_present_val
= BIT(IEEE80211_RADIOTAP_ANTENNA
) |
325 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL
);
328 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
329 it_present_val
|= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE
) |
330 BIT(IEEE80211_RADIOTAP_EXT
);
331 put_unaligned_le32(it_present_val
, it_present
);
333 it_present_val
= rtap
.present
;
336 put_unaligned_le32(it_present_val
, it_present
);
338 pos
= (void *)(it_present
+ 1);
340 /* the order of the following fields is important */
342 /* IEEE80211_RADIOTAP_TSFT */
343 if (ieee80211_have_rx_timestamp(status
)) {
345 while ((pos
- (u8
*)rthdr
) & 7)
348 ieee80211_calculate_rx_timestamp(local
, status
,
351 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT
);
355 /* IEEE80211_RADIOTAP_FLAGS */
356 if (has_fcs
&& ieee80211_hw_check(&local
->hw
, RX_INCLUDES_FCS
))
357 *pos
|= IEEE80211_RADIOTAP_F_FCS
;
358 if (status
->flag
& (RX_FLAG_FAILED_FCS_CRC
| RX_FLAG_FAILED_PLCP_CRC
))
359 *pos
|= IEEE80211_RADIOTAP_F_BADFCS
;
360 if (status
->enc_flags
& RX_ENC_FLAG_SHORTPRE
)
361 *pos
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
364 /* IEEE80211_RADIOTAP_RATE */
365 if (!rate
|| status
->encoding
!= RX_ENC_LEGACY
) {
367 * Without rate information don't add it. If we have,
368 * MCS information is a separate field in radiotap,
369 * added below. The byte here is needed as padding
370 * for the channel though, so initialise it to 0.
375 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE
);
376 if (status
->bw
== RATE_INFO_BW_10
)
378 else if (status
->bw
== RATE_INFO_BW_5
)
380 *pos
= DIV_ROUND_UP(rate
->bitrate
, 5 * (1 << shift
));
384 /* IEEE80211_RADIOTAP_CHANNEL */
385 put_unaligned_le16(status
->freq
, pos
);
387 if (status
->bw
== RATE_INFO_BW_10
)
388 channel_flags
|= IEEE80211_CHAN_HALF
;
389 else if (status
->bw
== RATE_INFO_BW_5
)
390 channel_flags
|= IEEE80211_CHAN_QUARTER
;
392 if (status
->band
== NL80211_BAND_5GHZ
)
393 channel_flags
|= IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_5GHZ
;
394 else if (status
->encoding
!= RX_ENC_LEGACY
)
395 channel_flags
|= IEEE80211_CHAN_DYN
| IEEE80211_CHAN_2GHZ
;
396 else if (rate
&& rate
->flags
& IEEE80211_RATE_ERP_G
)
397 channel_flags
|= IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_2GHZ
;
399 channel_flags
|= IEEE80211_CHAN_CCK
| IEEE80211_CHAN_2GHZ
;
401 channel_flags
|= IEEE80211_CHAN_2GHZ
;
402 put_unaligned_le16(channel_flags
, pos
);
405 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
406 if (ieee80211_hw_check(&local
->hw
, SIGNAL_DBM
) &&
407 !(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
)) {
408 *pos
= status
->signal
;
410 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
);
414 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
416 if (!status
->chains
) {
417 /* IEEE80211_RADIOTAP_ANTENNA */
418 *pos
= status
->antenna
;
422 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
424 /* IEEE80211_RADIOTAP_RX_FLAGS */
425 /* ensure 2 byte alignment for the 2 byte field as required */
426 if ((pos
- (u8
*)rthdr
) & 1)
428 if (status
->flag
& RX_FLAG_FAILED_PLCP_CRC
)
429 rx_flags
|= IEEE80211_RADIOTAP_F_RX_BADPLCP
;
430 put_unaligned_le16(rx_flags
, pos
);
433 if (status
->encoding
== RX_ENC_HT
) {
436 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS
);
437 *pos
++ = local
->hw
.radiotap_mcs_details
;
439 if (status
->enc_flags
& RX_ENC_FLAG_SHORT_GI
)
440 *pos
|= IEEE80211_RADIOTAP_MCS_SGI
;
441 if (status
->bw
== RATE_INFO_BW_40
)
442 *pos
|= IEEE80211_RADIOTAP_MCS_BW_40
;
443 if (status
->enc_flags
& RX_ENC_FLAG_HT_GF
)
444 *pos
|= IEEE80211_RADIOTAP_MCS_FMT_GF
;
445 if (status
->enc_flags
& RX_ENC_FLAG_LDPC
)
446 *pos
|= IEEE80211_RADIOTAP_MCS_FEC_LDPC
;
447 stbc
= (status
->enc_flags
& RX_ENC_FLAG_STBC_MASK
) >> RX_ENC_FLAG_STBC_SHIFT
;
448 *pos
|= stbc
<< IEEE80211_RADIOTAP_MCS_STBC_SHIFT
;
450 *pos
++ = status
->rate_idx
;
453 if (status
->flag
& RX_FLAG_AMPDU_DETAILS
) {
456 /* ensure 4 byte alignment */
457 while ((pos
- (u8
*)rthdr
) & 3)
460 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS
);
461 put_unaligned_le32(status
->ampdu_reference
, pos
);
463 if (status
->flag
& RX_FLAG_AMPDU_LAST_KNOWN
)
464 flags
|= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN
;
465 if (status
->flag
& RX_FLAG_AMPDU_IS_LAST
)
466 flags
|= IEEE80211_RADIOTAP_AMPDU_IS_LAST
;
467 if (status
->flag
& RX_FLAG_AMPDU_DELIM_CRC_ERROR
)
468 flags
|= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR
;
469 if (status
->flag
& RX_FLAG_AMPDU_DELIM_CRC_KNOWN
)
470 flags
|= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN
;
471 if (status
->flag
& RX_FLAG_AMPDU_EOF_BIT_KNOWN
)
472 flags
|= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN
;
473 if (status
->flag
& RX_FLAG_AMPDU_EOF_BIT
)
474 flags
|= IEEE80211_RADIOTAP_AMPDU_EOF
;
475 put_unaligned_le16(flags
, pos
);
477 if (status
->flag
& RX_FLAG_AMPDU_DELIM_CRC_KNOWN
)
478 *pos
++ = status
->ampdu_delimiter_crc
;
484 if (status
->encoding
== RX_ENC_VHT
) {
485 u16 known
= local
->hw
.radiotap_vht_details
;
487 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT
);
488 put_unaligned_le16(known
, pos
);
491 if (status
->enc_flags
& RX_ENC_FLAG_SHORT_GI
)
492 *pos
|= IEEE80211_RADIOTAP_VHT_FLAG_SGI
;
493 /* in VHT, STBC is binary */
494 if (status
->enc_flags
& RX_ENC_FLAG_STBC_MASK
)
495 *pos
|= IEEE80211_RADIOTAP_VHT_FLAG_STBC
;
496 if (status
->enc_flags
& RX_ENC_FLAG_BF
)
497 *pos
|= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED
;
500 switch (status
->bw
) {
501 case RATE_INFO_BW_80
:
504 case RATE_INFO_BW_160
:
507 case RATE_INFO_BW_40
:
514 *pos
= (status
->rate_idx
<< 4) | status
->nss
;
517 if (status
->enc_flags
& RX_ENC_FLAG_LDPC
)
518 *pos
|= IEEE80211_RADIOTAP_CODING_LDPC_USER0
;
526 if (local
->hw
.radiotap_timestamp
.units_pos
>= 0) {
528 u8 flags
= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT
;
531 cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP
);
533 /* ensure 8 byte alignment */
534 while ((pos
- (u8
*)rthdr
) & 7)
537 put_unaligned_le64(status
->device_timestamp
, pos
);
540 if (local
->hw
.radiotap_timestamp
.accuracy
>= 0) {
541 accuracy
= local
->hw
.radiotap_timestamp
.accuracy
;
542 flags
|= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY
;
544 put_unaligned_le16(accuracy
, pos
);
547 *pos
++ = local
->hw
.radiotap_timestamp
.units_pos
;
551 if (status
->encoding
== RX_ENC_HE
&&
552 status
->flag
& RX_FLAG_RADIOTAP_HE
) {
553 #define HE_PREP(f, val) cpu_to_le16(FIELD_PREP(IEEE80211_RADIOTAP_HE_##f, val))
555 if (status
->enc_flags
& RX_ENC_FLAG_STBC_MASK
) {
556 he
.data6
|= HE_PREP(DATA6_NSTS
,
557 FIELD_GET(RX_ENC_FLAG_STBC_MASK
,
559 he
.data3
|= HE_PREP(DATA3_STBC
, 1);
561 he
.data6
|= HE_PREP(DATA6_NSTS
, status
->nss
);
564 #define CHECK_GI(s) \
565 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
566 (int)NL80211_RATE_INFO_HE_GI_##s)
572 he
.data3
|= HE_PREP(DATA3_DATA_MCS
, status
->rate_idx
);
573 he
.data3
|= HE_PREP(DATA3_DATA_DCM
, status
->he_dcm
);
574 he
.data3
|= HE_PREP(DATA3_CODING
,
575 !!(status
->enc_flags
& RX_ENC_FLAG_LDPC
));
577 he
.data5
|= HE_PREP(DATA5_GI
, status
->he_gi
);
579 switch (status
->bw
) {
580 case RATE_INFO_BW_20
:
581 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
582 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ
);
584 case RATE_INFO_BW_40
:
585 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
586 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ
);
588 case RATE_INFO_BW_80
:
589 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
590 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ
);
592 case RATE_INFO_BW_160
:
593 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
594 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ
);
596 case RATE_INFO_BW_HE_RU
:
597 #define CHECK_RU_ALLOC(s) \
598 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
599 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
607 CHECK_RU_ALLOC(2x996
);
609 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
613 WARN_ONCE(1, "Invalid SU BW %d\n", status
->bw
);
616 /* ensure 2 byte alignment */
617 while ((pos
- (u8
*)rthdr
) & 1)
619 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE
);
620 memcpy(pos
, &he
, sizeof(he
));
624 if (status
->encoding
== RX_ENC_HE
&&
625 status
->flag
& RX_FLAG_RADIOTAP_HE_MU
) {
626 /* ensure 2 byte alignment */
627 while ((pos
- (u8
*)rthdr
) & 1)
629 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU
);
630 memcpy(pos
, &he_mu
, sizeof(he_mu
));
631 pos
+= sizeof(he_mu
);
634 for_each_set_bit(chain
, &chains
, IEEE80211_MAX_CHAINS
) {
635 *pos
++ = status
->chain_signal
[chain
];
639 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
640 /* ensure 2 byte alignment for the vendor field as required */
641 if ((pos
- (u8
*)rthdr
) & 1)
643 *pos
++ = rtap
.oui
[0];
644 *pos
++ = rtap
.oui
[1];
645 *pos
++ = rtap
.oui
[2];
647 put_unaligned_le16(rtap
.len
, pos
);
649 /* align the actual payload as requested */
650 while ((pos
- (u8
*)rthdr
) & (rtap
.align
- 1))
652 /* data (and possible padding) already follows */
656 static struct sk_buff
*
657 ieee80211_make_monitor_skb(struct ieee80211_local
*local
,
658 struct sk_buff
**origskb
,
659 struct ieee80211_rate
*rate
,
660 int rtap_space
, bool use_origskb
)
662 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(*origskb
);
663 int rt_hdrlen
, needed_headroom
;
666 /* room for the radiotap header based on driver features */
667 rt_hdrlen
= ieee80211_rx_radiotap_hdrlen(local
, status
, *origskb
);
668 needed_headroom
= rt_hdrlen
- rtap_space
;
671 /* only need to expand headroom if necessary */
676 * This shouldn't trigger often because most devices have an
677 * RX header they pull before we get here, and that should
678 * be big enough for our radiotap information. We should
679 * probably export the length to drivers so that we can have
680 * them allocate enough headroom to start with.
682 if (skb_headroom(skb
) < needed_headroom
&&
683 pskb_expand_head(skb
, needed_headroom
, 0, GFP_ATOMIC
)) {
689 * Need to make a copy and possibly remove radiotap header
690 * and FCS from the original.
692 skb
= skb_copy_expand(*origskb
, needed_headroom
, 0, GFP_ATOMIC
);
698 /* prepend radiotap information */
699 ieee80211_add_rx_radiotap_header(local
, skb
, rate
, rt_hdrlen
, true);
701 skb_reset_mac_header(skb
);
702 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
703 skb
->pkt_type
= PACKET_OTHERHOST
;
704 skb
->protocol
= htons(ETH_P_802_2
);
710 * This function copies a received frame to all monitor interfaces and
711 * returns a cleaned-up SKB that no longer includes the FCS nor the
712 * radiotap header the driver might have added.
714 static struct sk_buff
*
715 ieee80211_rx_monitor(struct ieee80211_local
*local
, struct sk_buff
*origskb
,
716 struct ieee80211_rate
*rate
)
718 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(origskb
);
719 struct ieee80211_sub_if_data
*sdata
;
720 struct sk_buff
*monskb
= NULL
;
721 int present_fcs_len
= 0;
722 unsigned int rtap_space
= 0;
723 struct ieee80211_sub_if_data
*monitor_sdata
=
724 rcu_dereference(local
->monitor_sdata
);
725 bool only_monitor
= false;
727 if (status
->flag
& RX_FLAG_RADIOTAP_HE
)
728 rtap_space
+= sizeof(struct ieee80211_radiotap_he
);
730 if (status
->flag
& RX_FLAG_RADIOTAP_HE_MU
)
731 rtap_space
+= sizeof(struct ieee80211_radiotap_he_mu
);
733 if (unlikely(status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
)) {
734 struct ieee80211_vendor_radiotap
*rtap
= (void *)origskb
->data
;
736 rtap_space
+= sizeof(*rtap
) + rtap
->len
+ rtap
->pad
;
740 * First, we may need to make a copy of the skb because
741 * (1) we need to modify it for radiotap (if not present), and
742 * (2) the other RX handlers will modify the skb we got.
744 * We don't need to, of course, if we aren't going to return
745 * the SKB because it has a bad FCS/PLCP checksum.
748 if (ieee80211_hw_check(&local
->hw
, RX_INCLUDES_FCS
)) {
749 if (unlikely(origskb
->len
<= FCS_LEN
)) {
752 dev_kfree_skb(origskb
);
755 present_fcs_len
= FCS_LEN
;
758 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
759 if (!pskb_may_pull(origskb
, 2 + rtap_space
)) {
760 dev_kfree_skb(origskb
);
764 only_monitor
= should_drop_frame(origskb
, present_fcs_len
, rtap_space
);
766 if (!local
->monitors
|| (status
->flag
& RX_FLAG_SKIP_MONITOR
)) {
768 dev_kfree_skb(origskb
);
772 remove_monitor_info(origskb
, present_fcs_len
, rtap_space
);
776 ieee80211_handle_mu_mimo_mon(monitor_sdata
, origskb
, rtap_space
);
778 list_for_each_entry_rcu(sdata
, &local
->mon_list
, u
.mntr
.list
) {
779 bool last_monitor
= list_is_last(&sdata
->u
.mntr
.list
,
783 monskb
= ieee80211_make_monitor_skb(local
, &origskb
,
795 skb
= skb_clone(monskb
, GFP_ATOMIC
);
799 skb
->dev
= sdata
->dev
;
800 ieee80211_rx_stats(skb
->dev
, skb
->len
);
801 netif_receive_skb(skb
);
809 /* this happens if last_monitor was erroneously false */
810 dev_kfree_skb(monskb
);
816 remove_monitor_info(origskb
, present_fcs_len
, rtap_space
);
820 static void ieee80211_parse_qos(struct ieee80211_rx_data
*rx
)
822 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
823 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
824 int tid
, seqno_idx
, security_idx
;
826 /* does the frame have a qos control field? */
827 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
828 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
829 /* frame has qos control */
830 tid
= *qc
& IEEE80211_QOS_CTL_TID_MASK
;
831 if (*qc
& IEEE80211_QOS_CTL_A_MSDU_PRESENT
)
832 status
->rx_flags
|= IEEE80211_RX_AMSDU
;
838 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
840 * Sequence numbers for management frames, QoS data
841 * frames with a broadcast/multicast address in the
842 * Address 1 field, and all non-QoS data frames sent
843 * by QoS STAs are assigned using an additional single
844 * modulo-4096 counter, [...]
846 * We also use that counter for non-QoS STAs.
848 seqno_idx
= IEEE80211_NUM_TIDS
;
850 if (ieee80211_is_mgmt(hdr
->frame_control
))
851 security_idx
= IEEE80211_NUM_TIDS
;
855 rx
->seqno_idx
= seqno_idx
;
856 rx
->security_idx
= security_idx
;
857 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
858 * For now, set skb->priority to 0 for other cases. */
859 rx
->skb
->priority
= (tid
> 7) ? 0 : tid
;
863 * DOC: Packet alignment
865 * Drivers always need to pass packets that are aligned to two-byte boundaries
868 * Additionally, should, if possible, align the payload data in a way that
869 * guarantees that the contained IP header is aligned to a four-byte
870 * boundary. In the case of regular frames, this simply means aligning the
871 * payload to a four-byte boundary (because either the IP header is directly
872 * contained, or IV/RFC1042 headers that have a length divisible by four are
873 * in front of it). If the payload data is not properly aligned and the
874 * architecture doesn't support efficient unaligned operations, mac80211
875 * will align the data.
877 * With A-MSDU frames, however, the payload data address must yield two modulo
878 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
879 * push the IP header further back to a multiple of four again. Thankfully, the
880 * specs were sane enough this time around to require padding each A-MSDU
881 * subframe to a length that is a multiple of four.
883 * Padding like Atheros hardware adds which is between the 802.11 header and
884 * the payload is not supported, the driver is required to move the 802.11
885 * header to be directly in front of the payload in that case.
887 static void ieee80211_verify_alignment(struct ieee80211_rx_data
*rx
)
889 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
890 WARN_ON_ONCE((unsigned long)rx
->skb
->data
& 1);
897 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff
*skb
)
899 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
901 if (is_multicast_ether_addr(hdr
->addr1
))
904 return ieee80211_is_robust_mgmt_frame(skb
);
908 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff
*skb
)
910 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
912 if (!is_multicast_ether_addr(hdr
->addr1
))
915 return ieee80211_is_robust_mgmt_frame(skb
);
919 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
920 static int ieee80211_get_mmie_keyidx(struct sk_buff
*skb
)
922 struct ieee80211_mgmt
*hdr
= (struct ieee80211_mgmt
*) skb
->data
;
923 struct ieee80211_mmie
*mmie
;
924 struct ieee80211_mmie_16
*mmie16
;
926 if (skb
->len
< 24 + sizeof(*mmie
) || !is_multicast_ether_addr(hdr
->da
))
929 if (!ieee80211_is_robust_mgmt_frame(skb
))
930 return -1; /* not a robust management frame */
932 mmie
= (struct ieee80211_mmie
*)
933 (skb
->data
+ skb
->len
- sizeof(*mmie
));
934 if (mmie
->element_id
== WLAN_EID_MMIE
&&
935 mmie
->length
== sizeof(*mmie
) - 2)
936 return le16_to_cpu(mmie
->key_id
);
938 mmie16
= (struct ieee80211_mmie_16
*)
939 (skb
->data
+ skb
->len
- sizeof(*mmie16
));
940 if (skb
->len
>= 24 + sizeof(*mmie16
) &&
941 mmie16
->element_id
== WLAN_EID_MMIE
&&
942 mmie16
->length
== sizeof(*mmie16
) - 2)
943 return le16_to_cpu(mmie16
->key_id
);
948 static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme
*cs
,
951 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
956 fc
= hdr
->frame_control
;
957 hdrlen
= ieee80211_hdrlen(fc
);
959 if (skb
->len
< hdrlen
+ cs
->hdr_len
)
962 skb_copy_bits(skb
, hdrlen
+ cs
->key_idx_off
, &keyid
, 1);
963 keyid
&= cs
->key_idx_mask
;
964 keyid
>>= cs
->key_idx_shift
;
969 static ieee80211_rx_result
ieee80211_rx_mesh_check(struct ieee80211_rx_data
*rx
)
971 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
972 char *dev_addr
= rx
->sdata
->vif
.addr
;
974 if (ieee80211_is_data(hdr
->frame_control
)) {
975 if (is_multicast_ether_addr(hdr
->addr1
)) {
976 if (ieee80211_has_tods(hdr
->frame_control
) ||
977 !ieee80211_has_fromds(hdr
->frame_control
))
978 return RX_DROP_MONITOR
;
979 if (ether_addr_equal(hdr
->addr3
, dev_addr
))
980 return RX_DROP_MONITOR
;
982 if (!ieee80211_has_a4(hdr
->frame_control
))
983 return RX_DROP_MONITOR
;
984 if (ether_addr_equal(hdr
->addr4
, dev_addr
))
985 return RX_DROP_MONITOR
;
989 /* If there is not an established peer link and this is not a peer link
990 * establisment frame, beacon or probe, drop the frame.
993 if (!rx
->sta
|| sta_plink_state(rx
->sta
) != NL80211_PLINK_ESTAB
) {
994 struct ieee80211_mgmt
*mgmt
;
996 if (!ieee80211_is_mgmt(hdr
->frame_control
))
997 return RX_DROP_MONITOR
;
999 if (ieee80211_is_action(hdr
->frame_control
)) {
1002 /* make sure category field is present */
1003 if (rx
->skb
->len
< IEEE80211_MIN_ACTION_SIZE
)
1004 return RX_DROP_MONITOR
;
1006 mgmt
= (struct ieee80211_mgmt
*)hdr
;
1007 category
= mgmt
->u
.action
.category
;
1008 if (category
!= WLAN_CATEGORY_MESH_ACTION
&&
1009 category
!= WLAN_CATEGORY_SELF_PROTECTED
)
1010 return RX_DROP_MONITOR
;
1014 if (ieee80211_is_probe_req(hdr
->frame_control
) ||
1015 ieee80211_is_probe_resp(hdr
->frame_control
) ||
1016 ieee80211_is_beacon(hdr
->frame_control
) ||
1017 ieee80211_is_auth(hdr
->frame_control
))
1020 return RX_DROP_MONITOR
;
1026 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx
*tid_agg_rx
,
1029 struct sk_buff_head
*frames
= &tid_agg_rx
->reorder_buf
[index
];
1030 struct sk_buff
*tail
= skb_peek_tail(frames
);
1031 struct ieee80211_rx_status
*status
;
1033 if (tid_agg_rx
->reorder_buf_filtered
& BIT_ULL(index
))
1039 status
= IEEE80211_SKB_RXCB(tail
);
1040 if (status
->flag
& RX_FLAG_AMSDU_MORE
)
1046 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data
*sdata
,
1047 struct tid_ampdu_rx
*tid_agg_rx
,
1049 struct sk_buff_head
*frames
)
1051 struct sk_buff_head
*skb_list
= &tid_agg_rx
->reorder_buf
[index
];
1052 struct sk_buff
*skb
;
1053 struct ieee80211_rx_status
*status
;
1055 lockdep_assert_held(&tid_agg_rx
->reorder_lock
);
1057 if (skb_queue_empty(skb_list
))
1060 if (!ieee80211_rx_reorder_ready(tid_agg_rx
, index
)) {
1061 __skb_queue_purge(skb_list
);
1065 /* release frames from the reorder ring buffer */
1066 tid_agg_rx
->stored_mpdu_num
--;
1067 while ((skb
= __skb_dequeue(skb_list
))) {
1068 status
= IEEE80211_SKB_RXCB(skb
);
1069 status
->rx_flags
|= IEEE80211_RX_DEFERRED_RELEASE
;
1070 __skb_queue_tail(frames
, skb
);
1074 tid_agg_rx
->reorder_buf_filtered
&= ~BIT_ULL(index
);
1075 tid_agg_rx
->head_seq_num
= ieee80211_sn_inc(tid_agg_rx
->head_seq_num
);
1078 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data
*sdata
,
1079 struct tid_ampdu_rx
*tid_agg_rx
,
1081 struct sk_buff_head
*frames
)
1085 lockdep_assert_held(&tid_agg_rx
->reorder_lock
);
1087 while (ieee80211_sn_less(tid_agg_rx
->head_seq_num
, head_seq_num
)) {
1088 index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1089 ieee80211_release_reorder_frame(sdata
, tid_agg_rx
, index
,
1095 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1096 * the skb was added to the buffer longer than this time ago, the earlier
1097 * frames that have not yet been received are assumed to be lost and the skb
1098 * can be released for processing. This may also release other skb's from the
1099 * reorder buffer if there are no additional gaps between the frames.
1101 * Callers must hold tid_agg_rx->reorder_lock.
1103 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1105 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data
*sdata
,
1106 struct tid_ampdu_rx
*tid_agg_rx
,
1107 struct sk_buff_head
*frames
)
1111 lockdep_assert_held(&tid_agg_rx
->reorder_lock
);
1113 /* release the buffer until next missing frame */
1114 index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1115 if (!ieee80211_rx_reorder_ready(tid_agg_rx
, index
) &&
1116 tid_agg_rx
->stored_mpdu_num
) {
1118 * No buffers ready to be released, but check whether any
1119 * frames in the reorder buffer have timed out.
1122 for (j
= (index
+ 1) % tid_agg_rx
->buf_size
; j
!= index
;
1123 j
= (j
+ 1) % tid_agg_rx
->buf_size
) {
1124 if (!ieee80211_rx_reorder_ready(tid_agg_rx
, j
)) {
1129 !time_after(jiffies
, tid_agg_rx
->reorder_time
[j
] +
1130 HT_RX_REORDER_BUF_TIMEOUT
))
1131 goto set_release_timer
;
1133 /* don't leave incomplete A-MSDUs around */
1134 for (i
= (index
+ 1) % tid_agg_rx
->buf_size
; i
!= j
;
1135 i
= (i
+ 1) % tid_agg_rx
->buf_size
)
1136 __skb_queue_purge(&tid_agg_rx
->reorder_buf
[i
]);
1138 ht_dbg_ratelimited(sdata
,
1139 "release an RX reorder frame due to timeout on earlier frames\n");
1140 ieee80211_release_reorder_frame(sdata
, tid_agg_rx
, j
,
1144 * Increment the head seq# also for the skipped slots.
1146 tid_agg_rx
->head_seq_num
=
1147 (tid_agg_rx
->head_seq_num
+
1148 skipped
) & IEEE80211_SN_MASK
;
1151 } else while (ieee80211_rx_reorder_ready(tid_agg_rx
, index
)) {
1152 ieee80211_release_reorder_frame(sdata
, tid_agg_rx
, index
,
1154 index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1157 if (tid_agg_rx
->stored_mpdu_num
) {
1158 j
= index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1160 for (; j
!= (index
- 1) % tid_agg_rx
->buf_size
;
1161 j
= (j
+ 1) % tid_agg_rx
->buf_size
) {
1162 if (ieee80211_rx_reorder_ready(tid_agg_rx
, j
))
1168 if (!tid_agg_rx
->removed
)
1169 mod_timer(&tid_agg_rx
->reorder_timer
,
1170 tid_agg_rx
->reorder_time
[j
] + 1 +
1171 HT_RX_REORDER_BUF_TIMEOUT
);
1173 del_timer(&tid_agg_rx
->reorder_timer
);
1178 * As this function belongs to the RX path it must be under
1179 * rcu_read_lock protection. It returns false if the frame
1180 * can be processed immediately, true if it was consumed.
1182 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data
*sdata
,
1183 struct tid_ampdu_rx
*tid_agg_rx
,
1184 struct sk_buff
*skb
,
1185 struct sk_buff_head
*frames
)
1187 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1188 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1189 u16 sc
= le16_to_cpu(hdr
->seq_ctrl
);
1190 u16 mpdu_seq_num
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
1191 u16 head_seq_num
, buf_size
;
1195 spin_lock(&tid_agg_rx
->reorder_lock
);
1198 * Offloaded BA sessions have no known starting sequence number so pick
1199 * one from first Rxed frame for this tid after BA was started.
1201 if (unlikely(tid_agg_rx
->auto_seq
)) {
1202 tid_agg_rx
->auto_seq
= false;
1203 tid_agg_rx
->ssn
= mpdu_seq_num
;
1204 tid_agg_rx
->head_seq_num
= mpdu_seq_num
;
1207 buf_size
= tid_agg_rx
->buf_size
;
1208 head_seq_num
= tid_agg_rx
->head_seq_num
;
1211 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1214 if (unlikely(!tid_agg_rx
->started
)) {
1215 if (ieee80211_sn_less(mpdu_seq_num
, head_seq_num
)) {
1219 tid_agg_rx
->started
= true;
1222 /* frame with out of date sequence number */
1223 if (ieee80211_sn_less(mpdu_seq_num
, head_seq_num
)) {
1229 * If frame the sequence number exceeds our buffering window
1230 * size release some previous frames to make room for this one.
1232 if (!ieee80211_sn_less(mpdu_seq_num
, head_seq_num
+ buf_size
)) {
1233 head_seq_num
= ieee80211_sn_inc(
1234 ieee80211_sn_sub(mpdu_seq_num
, buf_size
));
1235 /* release stored frames up to new head to stack */
1236 ieee80211_release_reorder_frames(sdata
, tid_agg_rx
,
1237 head_seq_num
, frames
);
1240 /* Now the new frame is always in the range of the reordering buffer */
1242 index
= mpdu_seq_num
% tid_agg_rx
->buf_size
;
1244 /* check if we already stored this frame */
1245 if (ieee80211_rx_reorder_ready(tid_agg_rx
, index
)) {
1251 * If the current MPDU is in the right order and nothing else
1252 * is stored we can process it directly, no need to buffer it.
1253 * If it is first but there's something stored, we may be able
1254 * to release frames after this one.
1256 if (mpdu_seq_num
== tid_agg_rx
->head_seq_num
&&
1257 tid_agg_rx
->stored_mpdu_num
== 0) {
1258 if (!(status
->flag
& RX_FLAG_AMSDU_MORE
))
1259 tid_agg_rx
->head_seq_num
=
1260 ieee80211_sn_inc(tid_agg_rx
->head_seq_num
);
1265 /* put the frame in the reordering buffer */
1266 __skb_queue_tail(&tid_agg_rx
->reorder_buf
[index
], skb
);
1267 if (!(status
->flag
& RX_FLAG_AMSDU_MORE
)) {
1268 tid_agg_rx
->reorder_time
[index
] = jiffies
;
1269 tid_agg_rx
->stored_mpdu_num
++;
1270 ieee80211_sta_reorder_release(sdata
, tid_agg_rx
, frames
);
1274 spin_unlock(&tid_agg_rx
->reorder_lock
);
1279 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1280 * true if the MPDU was buffered, false if it should be processed.
1282 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data
*rx
,
1283 struct sk_buff_head
*frames
)
1285 struct sk_buff
*skb
= rx
->skb
;
1286 struct ieee80211_local
*local
= rx
->local
;
1287 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1288 struct sta_info
*sta
= rx
->sta
;
1289 struct tid_ampdu_rx
*tid_agg_rx
;
1293 if (!ieee80211_is_data_qos(hdr
->frame_control
) ||
1294 is_multicast_ether_addr(hdr
->addr1
))
1298 * filter the QoS data rx stream according to
1299 * STA/TID and check if this STA/TID is on aggregation
1305 ack_policy
= *ieee80211_get_qos_ctl(hdr
) &
1306 IEEE80211_QOS_CTL_ACK_POLICY_MASK
;
1307 tid
= ieee80211_get_tid(hdr
);
1309 tid_agg_rx
= rcu_dereference(sta
->ampdu_mlme
.tid_rx
[tid
]);
1311 if (ack_policy
== IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK
&&
1312 !test_bit(tid
, rx
->sta
->ampdu_mlme
.agg_session_valid
) &&
1313 !test_and_set_bit(tid
, rx
->sta
->ampdu_mlme
.unexpected_agg
))
1314 ieee80211_send_delba(rx
->sdata
, rx
->sta
->sta
.addr
, tid
,
1315 WLAN_BACK_RECIPIENT
,
1316 WLAN_REASON_QSTA_REQUIRE_SETUP
);
1320 /* qos null data frames are excluded */
1321 if (unlikely(hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_NULLFUNC
)))
1324 /* not part of a BA session */
1325 if (ack_policy
!= IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK
&&
1326 ack_policy
!= IEEE80211_QOS_CTL_ACK_POLICY_NORMAL
)
1329 /* new, potentially un-ordered, ampdu frame - process it */
1331 /* reset session timer */
1332 if (tid_agg_rx
->timeout
)
1333 tid_agg_rx
->last_rx
= jiffies
;
1335 /* if this mpdu is fragmented - terminate rx aggregation session */
1336 sc
= le16_to_cpu(hdr
->seq_ctrl
);
1337 if (sc
& IEEE80211_SCTL_FRAG
) {
1338 skb_queue_tail(&rx
->sdata
->skb_queue
, skb
);
1339 ieee80211_queue_work(&local
->hw
, &rx
->sdata
->work
);
1344 * No locking needed -- we will only ever process one
1345 * RX packet at a time, and thus own tid_agg_rx. All
1346 * other code manipulating it needs to (and does) make
1347 * sure that we cannot get to it any more before doing
1350 if (ieee80211_sta_manage_reorder_buf(rx
->sdata
, tid_agg_rx
, skb
,
1355 __skb_queue_tail(frames
, skb
);
1358 static ieee80211_rx_result debug_noinline
1359 ieee80211_rx_h_check_dup(struct ieee80211_rx_data
*rx
)
1361 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
1362 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
1364 if (status
->flag
& RX_FLAG_DUP_VALIDATED
)
1368 * Drop duplicate 802.11 retransmissions
1369 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1372 if (rx
->skb
->len
< 24)
1375 if (ieee80211_is_ctl(hdr
->frame_control
) ||
1376 ieee80211_is_any_nullfunc(hdr
->frame_control
) ||
1377 is_multicast_ether_addr(hdr
->addr1
))
1383 if (unlikely(ieee80211_has_retry(hdr
->frame_control
) &&
1384 rx
->sta
->last_seq_ctrl
[rx
->seqno_idx
] == hdr
->seq_ctrl
)) {
1385 I802_DEBUG_INC(rx
->local
->dot11FrameDuplicateCount
);
1386 rx
->sta
->rx_stats
.num_duplicates
++;
1387 return RX_DROP_UNUSABLE
;
1388 } else if (!(status
->flag
& RX_FLAG_AMSDU_MORE
)) {
1389 rx
->sta
->last_seq_ctrl
[rx
->seqno_idx
] = hdr
->seq_ctrl
;
1395 static ieee80211_rx_result debug_noinline
1396 ieee80211_rx_h_check(struct ieee80211_rx_data
*rx
)
1398 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
1400 /* Drop disallowed frame classes based on STA auth/assoc state;
1401 * IEEE 802.11, Chap 5.5.
1403 * mac80211 filters only based on association state, i.e. it drops
1404 * Class 3 frames from not associated stations. hostapd sends
1405 * deauth/disassoc frames when needed. In addition, hostapd is
1406 * responsible for filtering on both auth and assoc states.
1409 if (ieee80211_vif_is_mesh(&rx
->sdata
->vif
))
1410 return ieee80211_rx_mesh_check(rx
);
1412 if (unlikely((ieee80211_is_data(hdr
->frame_control
) ||
1413 ieee80211_is_pspoll(hdr
->frame_control
)) &&
1414 rx
->sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
1415 rx
->sdata
->vif
.type
!= NL80211_IFTYPE_WDS
&&
1416 rx
->sdata
->vif
.type
!= NL80211_IFTYPE_OCB
&&
1417 (!rx
->sta
|| !test_sta_flag(rx
->sta
, WLAN_STA_ASSOC
)))) {
1419 * accept port control frames from the AP even when it's not
1420 * yet marked ASSOC to prevent a race where we don't set the
1421 * assoc bit quickly enough before it sends the first frame
1423 if (rx
->sta
&& rx
->sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
1424 ieee80211_is_data_present(hdr
->frame_control
)) {
1425 unsigned int hdrlen
;
1428 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
1430 if (rx
->skb
->len
< hdrlen
+ 8)
1431 return RX_DROP_MONITOR
;
1433 skb_copy_bits(rx
->skb
, hdrlen
+ 6, ðertype
, 2);
1434 if (ethertype
== rx
->sdata
->control_port_protocol
)
1438 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
&&
1439 cfg80211_rx_spurious_frame(rx
->sdata
->dev
,
1442 return RX_DROP_UNUSABLE
;
1444 return RX_DROP_MONITOR
;
1451 static ieee80211_rx_result debug_noinline
1452 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data
*rx
)
1454 struct ieee80211_local
*local
;
1455 struct ieee80211_hdr
*hdr
;
1456 struct sk_buff
*skb
;
1460 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1462 if (!local
->pspolling
)
1465 if (!ieee80211_has_fromds(hdr
->frame_control
))
1466 /* this is not from AP */
1469 if (!ieee80211_is_data(hdr
->frame_control
))
1472 if (!ieee80211_has_moredata(hdr
->frame_control
)) {
1473 /* AP has no more frames buffered for us */
1474 local
->pspolling
= false;
1478 /* more data bit is set, let's request a new frame from the AP */
1479 ieee80211_send_pspoll(local
, rx
->sdata
);
1484 static void sta_ps_start(struct sta_info
*sta
)
1486 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
1487 struct ieee80211_local
*local
= sdata
->local
;
1491 if (sta
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1492 sta
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
1493 ps
= &sdata
->bss
->ps
;
1497 atomic_inc(&ps
->num_sta_ps
);
1498 set_sta_flag(sta
, WLAN_STA_PS_STA
);
1499 if (!ieee80211_hw_check(&local
->hw
, AP_LINK_PS
))
1500 drv_sta_notify(local
, sdata
, STA_NOTIFY_SLEEP
, &sta
->sta
);
1501 ps_dbg(sdata
, "STA %pM aid %d enters power save mode\n",
1502 sta
->sta
.addr
, sta
->sta
.aid
);
1504 ieee80211_clear_fast_xmit(sta
);
1506 if (!sta
->sta
.txq
[0])
1509 for (tid
= 0; tid
< ARRAY_SIZE(sta
->sta
.txq
); tid
++) {
1510 if (txq_has_queue(sta
->sta
.txq
[tid
]))
1511 set_bit(tid
, &sta
->txq_buffered_tids
);
1513 clear_bit(tid
, &sta
->txq_buffered_tids
);
1517 static void sta_ps_end(struct sta_info
*sta
)
1519 ps_dbg(sta
->sdata
, "STA %pM aid %d exits power save mode\n",
1520 sta
->sta
.addr
, sta
->sta
.aid
);
1522 if (test_sta_flag(sta
, WLAN_STA_PS_DRIVER
)) {
1524 * Clear the flag only if the other one is still set
1525 * so that the TX path won't start TX'ing new frames
1526 * directly ... In the case that the driver flag isn't
1527 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1529 clear_sta_flag(sta
, WLAN_STA_PS_STA
);
1530 ps_dbg(sta
->sdata
, "STA %pM aid %d driver-ps-blocked\n",
1531 sta
->sta
.addr
, sta
->sta
.aid
);
1535 set_sta_flag(sta
, WLAN_STA_PS_DELIVER
);
1536 clear_sta_flag(sta
, WLAN_STA_PS_STA
);
1537 ieee80211_sta_ps_deliver_wakeup(sta
);
1540 int ieee80211_sta_ps_transition(struct ieee80211_sta
*pubsta
, bool start
)
1542 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
1545 WARN_ON(!ieee80211_hw_check(&sta
->local
->hw
, AP_LINK_PS
));
1547 /* Don't let the same PS state be set twice */
1548 in_ps
= test_sta_flag(sta
, WLAN_STA_PS_STA
);
1549 if ((start
&& in_ps
) || (!start
&& !in_ps
))
1559 EXPORT_SYMBOL(ieee80211_sta_ps_transition
);
1561 void ieee80211_sta_pspoll(struct ieee80211_sta
*pubsta
)
1563 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
1565 if (test_sta_flag(sta
, WLAN_STA_SP
))
1568 if (!test_sta_flag(sta
, WLAN_STA_PS_DRIVER
))
1569 ieee80211_sta_ps_deliver_poll_response(sta
);
1571 set_sta_flag(sta
, WLAN_STA_PSPOLL
);
1573 EXPORT_SYMBOL(ieee80211_sta_pspoll
);
1575 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta
*pubsta
, u8 tid
)
1577 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
1578 int ac
= ieee80211_ac_from_tid(tid
);
1581 * If this AC is not trigger-enabled do nothing unless the
1582 * driver is calling us after it already checked.
1584 * NB: This could/should check a separate bitmap of trigger-
1585 * enabled queues, but for now we only implement uAPSD w/o
1586 * TSPEC changes to the ACs, so they're always the same.
1588 if (!(sta
->sta
.uapsd_queues
& ieee80211_ac_to_qos_mask
[ac
]) &&
1589 tid
!= IEEE80211_NUM_TIDS
)
1592 /* if we are in a service period, do nothing */
1593 if (test_sta_flag(sta
, WLAN_STA_SP
))
1596 if (!test_sta_flag(sta
, WLAN_STA_PS_DRIVER
))
1597 ieee80211_sta_ps_deliver_uapsd(sta
);
1599 set_sta_flag(sta
, WLAN_STA_UAPSD
);
1601 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger
);
1603 static ieee80211_rx_result debug_noinline
1604 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data
*rx
)
1606 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1607 struct ieee80211_hdr
*hdr
= (void *)rx
->skb
->data
;
1608 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
1613 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
1614 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
)
1618 * The device handles station powersave, so don't do anything about
1619 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1620 * it to mac80211 since they're handled.)
1622 if (ieee80211_hw_check(&sdata
->local
->hw
, AP_LINK_PS
))
1626 * Don't do anything if the station isn't already asleep. In
1627 * the uAPSD case, the station will probably be marked asleep,
1628 * in the PS-Poll case the station must be confused ...
1630 if (!test_sta_flag(rx
->sta
, WLAN_STA_PS_STA
))
1633 if (unlikely(ieee80211_is_pspoll(hdr
->frame_control
))) {
1634 ieee80211_sta_pspoll(&rx
->sta
->sta
);
1636 /* Free PS Poll skb here instead of returning RX_DROP that would
1637 * count as an dropped frame. */
1638 dev_kfree_skb(rx
->skb
);
1641 } else if (!ieee80211_has_morefrags(hdr
->frame_control
) &&
1642 !(status
->rx_flags
& IEEE80211_RX_DEFERRED_RELEASE
) &&
1643 ieee80211_has_pm(hdr
->frame_control
) &&
1644 (ieee80211_is_data_qos(hdr
->frame_control
) ||
1645 ieee80211_is_qos_nullfunc(hdr
->frame_control
))) {
1646 u8 tid
= ieee80211_get_tid(hdr
);
1648 ieee80211_sta_uapsd_trigger(&rx
->sta
->sta
, tid
);
1654 static ieee80211_rx_result debug_noinline
1655 ieee80211_rx_h_sta_process(struct ieee80211_rx_data
*rx
)
1657 struct sta_info
*sta
= rx
->sta
;
1658 struct sk_buff
*skb
= rx
->skb
;
1659 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1660 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1667 * Update last_rx only for IBSS packets which are for the current
1668 * BSSID and for station already AUTHORIZED to avoid keeping the
1669 * current IBSS network alive in cases where other STAs start
1670 * using different BSSID. This will also give the station another
1671 * chance to restart the authentication/authorization in case
1672 * something went wrong the first time.
1674 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
1675 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
,
1676 NL80211_IFTYPE_ADHOC
);
1677 if (ether_addr_equal(bssid
, rx
->sdata
->u
.ibss
.bssid
) &&
1678 test_sta_flag(sta
, WLAN_STA_AUTHORIZED
)) {
1679 sta
->rx_stats
.last_rx
= jiffies
;
1680 if (ieee80211_is_data(hdr
->frame_control
) &&
1681 !is_multicast_ether_addr(hdr
->addr1
))
1682 sta
->rx_stats
.last_rate
=
1683 sta_stats_encode_rate(status
);
1685 } else if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_OCB
) {
1686 sta
->rx_stats
.last_rx
= jiffies
;
1687 } else if (!is_multicast_ether_addr(hdr
->addr1
)) {
1689 * Mesh beacons will update last_rx when if they are found to
1690 * match the current local configuration when processed.
1692 sta
->rx_stats
.last_rx
= jiffies
;
1693 if (ieee80211_is_data(hdr
->frame_control
))
1694 sta
->rx_stats
.last_rate
= sta_stats_encode_rate(status
);
1697 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
1698 ieee80211_sta_rx_notify(rx
->sdata
, hdr
);
1700 sta
->rx_stats
.fragments
++;
1702 u64_stats_update_begin(&rx
->sta
->rx_stats
.syncp
);
1703 sta
->rx_stats
.bytes
+= rx
->skb
->len
;
1704 u64_stats_update_end(&rx
->sta
->rx_stats
.syncp
);
1706 if (!(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
)) {
1707 sta
->rx_stats
.last_signal
= status
->signal
;
1708 ewma_signal_add(&sta
->rx_stats_avg
.signal
, -status
->signal
);
1711 if (status
->chains
) {
1712 sta
->rx_stats
.chains
= status
->chains
;
1713 for (i
= 0; i
< ARRAY_SIZE(status
->chain_signal
); i
++) {
1714 int signal
= status
->chain_signal
[i
];
1716 if (!(status
->chains
& BIT(i
)))
1719 sta
->rx_stats
.chain_signal_last
[i
] = signal
;
1720 ewma_signal_add(&sta
->rx_stats_avg
.chain_signal
[i
],
1726 * Change STA power saving mode only at the end of a frame
1727 * exchange sequence, and only for a data or management
1728 * frame as specified in IEEE 802.11-2016 11.2.3.2
1730 if (!ieee80211_hw_check(&sta
->local
->hw
, AP_LINK_PS
) &&
1731 !ieee80211_has_morefrags(hdr
->frame_control
) &&
1732 !is_multicast_ether_addr(hdr
->addr1
) &&
1733 (ieee80211_is_mgmt(hdr
->frame_control
) ||
1734 ieee80211_is_data(hdr
->frame_control
)) &&
1735 !(status
->rx_flags
& IEEE80211_RX_DEFERRED_RELEASE
) &&
1736 (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1737 rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)) {
1738 if (test_sta_flag(sta
, WLAN_STA_PS_STA
)) {
1739 if (!ieee80211_has_pm(hdr
->frame_control
))
1742 if (ieee80211_has_pm(hdr
->frame_control
))
1747 /* mesh power save support */
1748 if (ieee80211_vif_is_mesh(&rx
->sdata
->vif
))
1749 ieee80211_mps_rx_h_sta_process(sta
, hdr
);
1752 * Drop (qos-)data::nullfunc frames silently, since they
1753 * are used only to control station power saving mode.
1755 if (ieee80211_is_any_nullfunc(hdr
->frame_control
)) {
1756 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
1759 * If we receive a 4-addr nullfunc frame from a STA
1760 * that was not moved to a 4-addr STA vlan yet send
1761 * the event to userspace and for older hostapd drop
1762 * the frame to the monitor interface.
1764 if (ieee80211_has_a4(hdr
->frame_control
) &&
1765 (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1766 (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
1767 !rx
->sdata
->u
.vlan
.sta
))) {
1768 if (!test_and_set_sta_flag(sta
, WLAN_STA_4ADDR_EVENT
))
1769 cfg80211_rx_unexpected_4addr_frame(
1770 rx
->sdata
->dev
, sta
->sta
.addr
,
1772 return RX_DROP_MONITOR
;
1775 * Update counter and free packet here to avoid
1776 * counting this as a dropped packed.
1778 sta
->rx_stats
.packets
++;
1779 dev_kfree_skb(rx
->skb
);
1784 } /* ieee80211_rx_h_sta_process */
1786 static ieee80211_rx_result debug_noinline
1787 ieee80211_rx_h_decrypt(struct ieee80211_rx_data
*rx
)
1789 struct sk_buff
*skb
= rx
->skb
;
1790 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1791 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1794 ieee80211_rx_result result
= RX_DROP_UNUSABLE
;
1795 struct ieee80211_key
*sta_ptk
= NULL
;
1796 int mmie_keyidx
= -1;
1798 const struct ieee80211_cipher_scheme
*cs
= NULL
;
1803 * There are four types of keys:
1804 * - GTK (group keys)
1805 * - IGTK (group keys for management frames)
1806 * - PTK (pairwise keys)
1807 * - STK (station-to-station pairwise keys)
1809 * When selecting a key, we have to distinguish between multicast
1810 * (including broadcast) and unicast frames, the latter can only
1811 * use PTKs and STKs while the former always use GTKs and IGTKs.
1812 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1813 * unicast frames can also use key indices like GTKs. Hence, if we
1814 * don't have a PTK/STK we check the key index for a WEP key.
1816 * Note that in a regular BSS, multicast frames are sent by the
1817 * AP only, associated stations unicast the frame to the AP first
1818 * which then multicasts it on their behalf.
1820 * There is also a slight problem in IBSS mode: GTKs are negotiated
1821 * with each station, that is something we don't currently handle.
1822 * The spec seems to expect that one negotiates the same key with
1823 * every station but there's no such requirement; VLANs could be
1827 /* start without a key */
1829 fc
= hdr
->frame_control
;
1832 int keyid
= rx
->sta
->ptk_idx
;
1834 if (ieee80211_has_protected(fc
) && rx
->sta
->cipher_scheme
) {
1835 cs
= rx
->sta
->cipher_scheme
;
1836 keyid
= ieee80211_get_cs_keyid(cs
, rx
->skb
);
1837 if (unlikely(keyid
< 0))
1838 return RX_DROP_UNUSABLE
;
1840 sta_ptk
= rcu_dereference(rx
->sta
->ptk
[keyid
]);
1843 if (!ieee80211_has_protected(fc
))
1844 mmie_keyidx
= ieee80211_get_mmie_keyidx(rx
->skb
);
1846 if (!is_multicast_ether_addr(hdr
->addr1
) && sta_ptk
) {
1848 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
1849 (status
->flag
& RX_FLAG_IV_STRIPPED
))
1851 /* Skip decryption if the frame is not protected. */
1852 if (!ieee80211_has_protected(fc
))
1854 } else if (mmie_keyidx
>= 0) {
1855 /* Broadcast/multicast robust management frame / BIP */
1856 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
1857 (status
->flag
& RX_FLAG_IV_STRIPPED
))
1860 if (mmie_keyidx
< NUM_DEFAULT_KEYS
||
1861 mmie_keyidx
>= NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
)
1862 return RX_DROP_MONITOR
; /* unexpected BIP keyidx */
1864 if (ieee80211_is_group_privacy_action(skb
) &&
1865 test_sta_flag(rx
->sta
, WLAN_STA_MFP
))
1866 return RX_DROP_MONITOR
;
1868 rx
->key
= rcu_dereference(rx
->sta
->gtk
[mmie_keyidx
]);
1871 rx
->key
= rcu_dereference(rx
->sdata
->keys
[mmie_keyidx
]);
1872 } else if (!ieee80211_has_protected(fc
)) {
1874 * The frame was not protected, so skip decryption. However, we
1875 * need to set rx->key if there is a key that could have been
1876 * used so that the frame may be dropped if encryption would
1877 * have been expected.
1879 struct ieee80211_key
*key
= NULL
;
1880 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1883 if (ieee80211_is_mgmt(fc
) &&
1884 is_multicast_ether_addr(hdr
->addr1
) &&
1885 (key
= rcu_dereference(rx
->sdata
->default_mgmt_key
)))
1889 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1890 key
= rcu_dereference(rx
->sta
->gtk
[i
]);
1896 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1897 key
= rcu_dereference(sdata
->keys
[i
]);
1910 * The device doesn't give us the IV so we won't be
1911 * able to look up the key. That's ok though, we
1912 * don't need to decrypt the frame, we just won't
1913 * be able to keep statistics accurate.
1914 * Except for key threshold notifications, should
1915 * we somehow allow the driver to tell us which key
1916 * the hardware used if this flag is set?
1918 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
1919 (status
->flag
& RX_FLAG_IV_STRIPPED
))
1922 hdrlen
= ieee80211_hdrlen(fc
);
1925 keyidx
= ieee80211_get_cs_keyid(cs
, rx
->skb
);
1927 if (unlikely(keyidx
< 0))
1928 return RX_DROP_UNUSABLE
;
1930 if (rx
->skb
->len
< 8 + hdrlen
)
1931 return RX_DROP_UNUSABLE
; /* TODO: count this? */
1933 * no need to call ieee80211_wep_get_keyidx,
1934 * it verifies a bunch of things we've done already
1936 skb_copy_bits(rx
->skb
, hdrlen
+ 3, &keyid
, 1);
1937 keyidx
= keyid
>> 6;
1940 /* check per-station GTK first, if multicast packet */
1941 if (is_multicast_ether_addr(hdr
->addr1
) && rx
->sta
)
1942 rx
->key
= rcu_dereference(rx
->sta
->gtk
[keyidx
]);
1944 /* if not found, try default key */
1946 rx
->key
= rcu_dereference(rx
->sdata
->keys
[keyidx
]);
1949 * RSNA-protected unicast frames should always be
1950 * sent with pairwise or station-to-station keys,
1951 * but for WEP we allow using a key index as well.
1954 rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1955 rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_WEP104
&&
1956 !is_multicast_ether_addr(hdr
->addr1
))
1962 if (unlikely(rx
->key
->flags
& KEY_FLAG_TAINTED
))
1963 return RX_DROP_MONITOR
;
1965 /* TODO: add threshold stuff again */
1967 return RX_DROP_MONITOR
;
1970 switch (rx
->key
->conf
.cipher
) {
1971 case WLAN_CIPHER_SUITE_WEP40
:
1972 case WLAN_CIPHER_SUITE_WEP104
:
1973 result
= ieee80211_crypto_wep_decrypt(rx
);
1975 case WLAN_CIPHER_SUITE_TKIP
:
1976 result
= ieee80211_crypto_tkip_decrypt(rx
);
1978 case WLAN_CIPHER_SUITE_CCMP
:
1979 result
= ieee80211_crypto_ccmp_decrypt(
1980 rx
, IEEE80211_CCMP_MIC_LEN
);
1982 case WLAN_CIPHER_SUITE_CCMP_256
:
1983 result
= ieee80211_crypto_ccmp_decrypt(
1984 rx
, IEEE80211_CCMP_256_MIC_LEN
);
1986 case WLAN_CIPHER_SUITE_AES_CMAC
:
1987 result
= ieee80211_crypto_aes_cmac_decrypt(rx
);
1989 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
1990 result
= ieee80211_crypto_aes_cmac_256_decrypt(rx
);
1992 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
1993 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
1994 result
= ieee80211_crypto_aes_gmac_decrypt(rx
);
1996 case WLAN_CIPHER_SUITE_GCMP
:
1997 case WLAN_CIPHER_SUITE_GCMP_256
:
1998 result
= ieee80211_crypto_gcmp_decrypt(rx
);
2001 result
= ieee80211_crypto_hw_decrypt(rx
);
2004 /* the hdr variable is invalid after the decrypt handlers */
2006 /* either the frame has been decrypted or will be dropped */
2007 status
->flag
|= RX_FLAG_DECRYPTED
;
2012 static inline struct ieee80211_fragment_entry
*
2013 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
2014 unsigned int frag
, unsigned int seq
, int rx_queue
,
2015 struct sk_buff
**skb
)
2017 struct ieee80211_fragment_entry
*entry
;
2019 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
2020 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
2021 sdata
->fragment_next
= 0;
2023 if (!skb_queue_empty(&entry
->skb_list
))
2024 __skb_queue_purge(&entry
->skb_list
);
2026 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
2028 entry
->first_frag_time
= jiffies
;
2030 entry
->rx_queue
= rx_queue
;
2031 entry
->last_frag
= frag
;
2032 entry
->check_sequential_pn
= false;
2033 entry
->extra_len
= 0;
2038 static inline struct ieee80211_fragment_entry
*
2039 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
2040 unsigned int frag
, unsigned int seq
,
2041 int rx_queue
, struct ieee80211_hdr
*hdr
)
2043 struct ieee80211_fragment_entry
*entry
;
2046 idx
= sdata
->fragment_next
;
2047 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
2048 struct ieee80211_hdr
*f_hdr
;
2052 idx
= IEEE80211_FRAGMENT_MAX
- 1;
2054 entry
= &sdata
->fragments
[idx
];
2055 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
2056 entry
->rx_queue
!= rx_queue
||
2057 entry
->last_frag
+ 1 != frag
)
2060 f_hdr
= (struct ieee80211_hdr
*)entry
->skb_list
.next
->data
;
2063 * Check ftype and addresses are equal, else check next fragment
2065 if (((hdr
->frame_control
^ f_hdr
->frame_control
) &
2066 cpu_to_le16(IEEE80211_FCTL_FTYPE
)) ||
2067 !ether_addr_equal(hdr
->addr1
, f_hdr
->addr1
) ||
2068 !ether_addr_equal(hdr
->addr2
, f_hdr
->addr2
))
2071 if (time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
2072 __skb_queue_purge(&entry
->skb_list
);
2081 static ieee80211_rx_result debug_noinline
2082 ieee80211_rx_h_defragment(struct ieee80211_rx_data
*rx
)
2084 struct ieee80211_hdr
*hdr
;
2087 unsigned int frag
, seq
;
2088 struct ieee80211_fragment_entry
*entry
;
2089 struct sk_buff
*skb
;
2091 hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2092 fc
= hdr
->frame_control
;
2094 if (ieee80211_is_ctl(fc
))
2097 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2098 frag
= sc
& IEEE80211_SCTL_FRAG
;
2100 if (is_multicast_ether_addr(hdr
->addr1
)) {
2101 I802_DEBUG_INC(rx
->local
->dot11MulticastReceivedFrameCount
);
2105 if (likely(!ieee80211_has_morefrags(fc
) && frag
== 0))
2108 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
2110 if (skb_linearize(rx
->skb
))
2111 return RX_DROP_UNUSABLE
;
2114 * skb_linearize() might change the skb->data and
2115 * previously cached variables (in this case, hdr) need to
2116 * be refreshed with the new data.
2118 hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2119 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2122 /* This is the first fragment of a new frame. */
2123 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
2124 rx
->seqno_idx
, &(rx
->skb
));
2126 (rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_CCMP
||
2127 rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_CCMP_256
||
2128 rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_GCMP
||
2129 rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_GCMP_256
) &&
2130 ieee80211_has_protected(fc
)) {
2131 int queue
= rx
->security_idx
;
2133 /* Store CCMP/GCMP PN so that we can verify that the
2134 * next fragment has a sequential PN value.
2136 entry
->check_sequential_pn
= true;
2137 memcpy(entry
->last_pn
,
2138 rx
->key
->u
.ccmp
.rx_pn
[queue
],
2139 IEEE80211_CCMP_PN_LEN
);
2140 BUILD_BUG_ON(offsetof(struct ieee80211_key
,
2142 offsetof(struct ieee80211_key
,
2144 BUILD_BUG_ON(sizeof(rx
->key
->u
.ccmp
.rx_pn
[queue
]) !=
2145 sizeof(rx
->key
->u
.gcmp
.rx_pn
[queue
]));
2146 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN
!=
2147 IEEE80211_GCMP_PN_LEN
);
2152 /* This is a fragment for a frame that should already be pending in
2153 * fragment cache. Add this fragment to the end of the pending entry.
2155 entry
= ieee80211_reassemble_find(rx
->sdata
, frag
, seq
,
2156 rx
->seqno_idx
, hdr
);
2158 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
2159 return RX_DROP_MONITOR
;
2162 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2163 * MPDU PN values are not incrementing in steps of 1."
2164 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2165 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2167 if (entry
->check_sequential_pn
) {
2169 u8 pn
[IEEE80211_CCMP_PN_LEN
], *rpn
;
2173 (rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_CCMP
&&
2174 rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_CCMP_256
&&
2175 rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_GCMP
&&
2176 rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_GCMP_256
))
2177 return RX_DROP_UNUSABLE
;
2178 memcpy(pn
, entry
->last_pn
, IEEE80211_CCMP_PN_LEN
);
2179 for (i
= IEEE80211_CCMP_PN_LEN
- 1; i
>= 0; i
--) {
2184 queue
= rx
->security_idx
;
2185 rpn
= rx
->key
->u
.ccmp
.rx_pn
[queue
];
2186 if (memcmp(pn
, rpn
, IEEE80211_CCMP_PN_LEN
))
2187 return RX_DROP_UNUSABLE
;
2188 memcpy(entry
->last_pn
, pn
, IEEE80211_CCMP_PN_LEN
);
2191 skb_pull(rx
->skb
, ieee80211_hdrlen(fc
));
2192 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
2193 entry
->last_frag
= frag
;
2194 entry
->extra_len
+= rx
->skb
->len
;
2195 if (ieee80211_has_morefrags(fc
)) {
2200 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
2201 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
2202 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head_defrag
);
2203 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
2205 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
2206 __skb_queue_purge(&entry
->skb_list
);
2207 return RX_DROP_UNUSABLE
;
2210 while ((skb
= __skb_dequeue(&entry
->skb_list
))) {
2211 skb_put_data(rx
->skb
, skb
->data
, skb
->len
);
2216 ieee80211_led_rx(rx
->local
);
2219 rx
->sta
->rx_stats
.packets
++;
2223 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data
*rx
)
2225 if (unlikely(!rx
->sta
|| !test_sta_flag(rx
->sta
, WLAN_STA_AUTHORIZED
)))
2231 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data
*rx
, __le16 fc
)
2233 struct sk_buff
*skb
= rx
->skb
;
2234 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2237 * Pass through unencrypted frames if the hardware has
2238 * decrypted them already.
2240 if (status
->flag
& RX_FLAG_DECRYPTED
)
2243 /* Drop unencrypted frames if key is set. */
2244 if (unlikely(!ieee80211_has_protected(fc
) &&
2245 !ieee80211_is_any_nullfunc(fc
) &&
2246 ieee80211_is_data(fc
) && rx
->key
))
2252 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data
*rx
)
2254 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2255 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
2256 __le16 fc
= hdr
->frame_control
;
2259 * Pass through unencrypted frames if the hardware has
2260 * decrypted them already.
2262 if (status
->flag
& RX_FLAG_DECRYPTED
)
2265 if (rx
->sta
&& test_sta_flag(rx
->sta
, WLAN_STA_MFP
)) {
2266 if (unlikely(!ieee80211_has_protected(fc
) &&
2267 ieee80211_is_unicast_robust_mgmt_frame(rx
->skb
) &&
2269 if (ieee80211_is_deauth(fc
) ||
2270 ieee80211_is_disassoc(fc
))
2271 cfg80211_rx_unprot_mlme_mgmt(rx
->sdata
->dev
,
2276 /* BIP does not use Protected field, so need to check MMIE */
2277 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx
->skb
) &&
2278 ieee80211_get_mmie_keyidx(rx
->skb
) < 0)) {
2279 if (ieee80211_is_deauth(fc
) ||
2280 ieee80211_is_disassoc(fc
))
2281 cfg80211_rx_unprot_mlme_mgmt(rx
->sdata
->dev
,
2287 * When using MFP, Action frames are not allowed prior to
2288 * having configured keys.
2290 if (unlikely(ieee80211_is_action(fc
) && !rx
->key
&&
2291 ieee80211_is_robust_mgmt_frame(rx
->skb
)))
2299 __ieee80211_data_to_8023(struct ieee80211_rx_data
*rx
, bool *port_control
)
2301 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2302 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2303 bool check_port_control
= false;
2304 struct ethhdr
*ehdr
;
2307 *port_control
= false;
2308 if (ieee80211_has_a4(hdr
->frame_control
) &&
2309 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&& !sdata
->u
.vlan
.sta
)
2312 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
2313 !!sdata
->u
.mgd
.use_4addr
!= !!ieee80211_has_a4(hdr
->frame_control
)) {
2315 if (!sdata
->u
.mgd
.use_4addr
)
2318 check_port_control
= true;
2321 if (is_multicast_ether_addr(hdr
->addr1
) &&
2322 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&& sdata
->u
.vlan
.sta
)
2325 ret
= ieee80211_data_to_8023(rx
->skb
, sdata
->vif
.addr
, sdata
->vif
.type
);
2329 ehdr
= (struct ethhdr
*) rx
->skb
->data
;
2330 if (ehdr
->h_proto
== rx
->sdata
->control_port_protocol
)
2331 *port_control
= true;
2332 else if (check_port_control
)
2339 * requires that rx->skb is a frame with ethernet header
2341 static bool ieee80211_frame_allowed(struct ieee80211_rx_data
*rx
, __le16 fc
)
2343 static const u8 pae_group_addr
[ETH_ALEN
] __aligned(2)
2344 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2345 struct ethhdr
*ehdr
= (struct ethhdr
*) rx
->skb
->data
;
2348 * Allow EAPOL frames to us/the PAE group address regardless
2349 * of whether the frame was encrypted or not.
2351 if (ehdr
->h_proto
== rx
->sdata
->control_port_protocol
&&
2352 (ether_addr_equal(ehdr
->h_dest
, rx
->sdata
->vif
.addr
) ||
2353 ether_addr_equal(ehdr
->h_dest
, pae_group_addr
)))
2356 if (ieee80211_802_1x_port_control(rx
) ||
2357 ieee80211_drop_unencrypted(rx
, fc
))
2363 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff
*skb
,
2364 struct ieee80211_rx_data
*rx
)
2366 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2367 struct net_device
*dev
= sdata
->dev
;
2369 if (unlikely((skb
->protocol
== sdata
->control_port_protocol
||
2370 skb
->protocol
== cpu_to_be16(ETH_P_PREAUTH
)) &&
2371 sdata
->control_port_over_nl80211
)) {
2372 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2373 bool noencrypt
= !(status
->flag
& RX_FLAG_DECRYPTED
);
2375 cfg80211_rx_control_port(dev
, skb
, noencrypt
);
2378 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2380 /* deliver to local stack */
2382 napi_gro_receive(rx
->napi
, skb
);
2384 netif_receive_skb(skb
);
2389 * requires that rx->skb is a frame with ethernet header
2392 ieee80211_deliver_skb(struct ieee80211_rx_data
*rx
)
2394 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2395 struct net_device
*dev
= sdata
->dev
;
2396 struct sk_buff
*skb
, *xmit_skb
;
2397 struct ethhdr
*ehdr
= (struct ethhdr
*) rx
->skb
->data
;
2398 struct sta_info
*dsta
;
2403 ieee80211_rx_stats(dev
, skb
->len
);
2406 /* The seqno index has the same property as needed
2407 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2408 * for non-QoS-data frames. Here we know it's a data
2409 * frame, so count MSDUs.
2411 u64_stats_update_begin(&rx
->sta
->rx_stats
.syncp
);
2412 rx
->sta
->rx_stats
.msdu
[rx
->seqno_idx
]++;
2413 u64_stats_update_end(&rx
->sta
->rx_stats
.syncp
);
2416 if ((sdata
->vif
.type
== NL80211_IFTYPE_AP
||
2417 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) &&
2418 !(sdata
->flags
& IEEE80211_SDATA_DONT_BRIDGE_PACKETS
) &&
2419 (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
|| !sdata
->u
.vlan
.sta
)) {
2420 if (is_multicast_ether_addr(ehdr
->h_dest
) &&
2421 ieee80211_vif_get_num_mcast_if(sdata
) != 0) {
2423 * send multicast frames both to higher layers in
2424 * local net stack and back to the wireless medium
2426 xmit_skb
= skb_copy(skb
, GFP_ATOMIC
);
2428 net_info_ratelimited("%s: failed to clone multicast frame\n",
2430 } else if (!is_multicast_ether_addr(ehdr
->h_dest
)) {
2431 dsta
= sta_info_get(sdata
, skb
->data
);
2434 * The destination station is associated to
2435 * this AP (in this VLAN), so send the frame
2436 * directly to it and do not pass it to local
2445 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2447 /* 'align' will only take the values 0 or 2 here since all
2448 * frames are required to be aligned to 2-byte boundaries
2449 * when being passed to mac80211; the code here works just
2450 * as well if that isn't true, but mac80211 assumes it can
2451 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2455 align
= (unsigned long)(skb
->data
+ sizeof(struct ethhdr
)) & 3;
2457 if (WARN_ON(skb_headroom(skb
) < 3)) {
2461 u8
*data
= skb
->data
;
2462 size_t len
= skb_headlen(skb
);
2464 memmove(skb
->data
, data
, len
);
2465 skb_set_tail_pointer(skb
, len
);
2472 skb
->protocol
= eth_type_trans(skb
, dev
);
2473 ieee80211_deliver_skb_to_local_stack(skb
, rx
);
2478 * Send to wireless media and increase priority by 256 to
2479 * keep the received priority instead of reclassifying
2480 * the frame (see cfg80211_classify8021d).
2482 xmit_skb
->priority
+= 256;
2483 xmit_skb
->protocol
= htons(ETH_P_802_3
);
2484 skb_reset_network_header(xmit_skb
);
2485 skb_reset_mac_header(xmit_skb
);
2486 dev_queue_xmit(xmit_skb
);
2490 static ieee80211_rx_result debug_noinline
2491 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data
*rx
, u8 data_offset
)
2493 struct net_device
*dev
= rx
->sdata
->dev
;
2494 struct sk_buff
*skb
= rx
->skb
;
2495 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2496 __le16 fc
= hdr
->frame_control
;
2497 struct sk_buff_head frame_list
;
2498 struct ethhdr ethhdr
;
2499 const u8
*check_da
= ethhdr
.h_dest
, *check_sa
= ethhdr
.h_source
;
2501 if (unlikely(ieee80211_has_a4(hdr
->frame_control
))) {
2504 } else switch (rx
->sdata
->vif
.type
) {
2505 case NL80211_IFTYPE_AP
:
2506 case NL80211_IFTYPE_AP_VLAN
:
2509 case NL80211_IFTYPE_STATION
:
2511 !test_sta_flag(rx
->sta
, WLAN_STA_TDLS_PEER
))
2514 case NL80211_IFTYPE_MESH_POINT
:
2522 __skb_queue_head_init(&frame_list
);
2524 if (ieee80211_data_to_8023_exthdr(skb
, ðhdr
,
2525 rx
->sdata
->vif
.addr
,
2526 rx
->sdata
->vif
.type
,
2528 return RX_DROP_UNUSABLE
;
2530 ieee80211_amsdu_to_8023s(skb
, &frame_list
, dev
->dev_addr
,
2531 rx
->sdata
->vif
.type
,
2532 rx
->local
->hw
.extra_tx_headroom
,
2533 check_da
, check_sa
);
2535 while (!skb_queue_empty(&frame_list
)) {
2536 rx
->skb
= __skb_dequeue(&frame_list
);
2538 if (!ieee80211_frame_allowed(rx
, fc
)) {
2539 dev_kfree_skb(rx
->skb
);
2543 ieee80211_deliver_skb(rx
);
2549 static ieee80211_rx_result debug_noinline
2550 ieee80211_rx_h_amsdu(struct ieee80211_rx_data
*rx
)
2552 struct sk_buff
*skb
= rx
->skb
;
2553 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2554 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2555 __le16 fc
= hdr
->frame_control
;
2557 if (!(status
->rx_flags
& IEEE80211_RX_AMSDU
))
2560 if (unlikely(!ieee80211_is_data(fc
)))
2563 if (unlikely(!ieee80211_is_data_present(fc
)))
2564 return RX_DROP_MONITOR
;
2566 if (unlikely(ieee80211_has_a4(hdr
->frame_control
))) {
2567 switch (rx
->sdata
->vif
.type
) {
2568 case NL80211_IFTYPE_AP_VLAN
:
2569 if (!rx
->sdata
->u
.vlan
.sta
)
2570 return RX_DROP_UNUSABLE
;
2572 case NL80211_IFTYPE_STATION
:
2573 if (!rx
->sdata
->u
.mgd
.use_4addr
)
2574 return RX_DROP_UNUSABLE
;
2577 return RX_DROP_UNUSABLE
;
2581 if (is_multicast_ether_addr(hdr
->addr1
))
2582 return RX_DROP_UNUSABLE
;
2584 return __ieee80211_rx_h_amsdu(rx
, 0);
2587 #ifdef CONFIG_MAC80211_MESH
2588 static ieee80211_rx_result
2589 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data
*rx
)
2591 struct ieee80211_hdr
*fwd_hdr
, *hdr
;
2592 struct ieee80211_tx_info
*info
;
2593 struct ieee80211s_hdr
*mesh_hdr
;
2594 struct sk_buff
*skb
= rx
->skb
, *fwd_skb
;
2595 struct ieee80211_local
*local
= rx
->local
;
2596 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2597 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
2601 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2602 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
2604 /* make sure fixed part of mesh header is there, also checks skb len */
2605 if (!pskb_may_pull(rx
->skb
, hdrlen
+ 6))
2606 return RX_DROP_MONITOR
;
2608 mesh_hdr
= (struct ieee80211s_hdr
*) (skb
->data
+ hdrlen
);
2610 /* make sure full mesh header is there, also checks skb len */
2611 if (!pskb_may_pull(rx
->skb
,
2612 hdrlen
+ ieee80211_get_mesh_hdrlen(mesh_hdr
)))
2613 return RX_DROP_MONITOR
;
2615 /* reload pointers */
2616 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2617 mesh_hdr
= (struct ieee80211s_hdr
*) (skb
->data
+ hdrlen
);
2619 if (ieee80211_drop_unencrypted(rx
, hdr
->frame_control
))
2620 return RX_DROP_MONITOR
;
2622 /* frame is in RMC, don't forward */
2623 if (ieee80211_is_data(hdr
->frame_control
) &&
2624 is_multicast_ether_addr(hdr
->addr1
) &&
2625 mesh_rmc_check(rx
->sdata
, hdr
->addr3
, mesh_hdr
))
2626 return RX_DROP_MONITOR
;
2628 if (!ieee80211_is_data(hdr
->frame_control
))
2632 return RX_DROP_MONITOR
;
2634 if (mesh_hdr
->flags
& MESH_FLAGS_AE
) {
2635 struct mesh_path
*mppath
;
2639 if (is_multicast_ether_addr(hdr
->addr1
)) {
2640 mpp_addr
= hdr
->addr3
;
2641 proxied_addr
= mesh_hdr
->eaddr1
;
2642 } else if ((mesh_hdr
->flags
& MESH_FLAGS_AE
) ==
2643 MESH_FLAGS_AE_A5_A6
) {
2644 /* has_a4 already checked in ieee80211_rx_mesh_check */
2645 mpp_addr
= hdr
->addr4
;
2646 proxied_addr
= mesh_hdr
->eaddr2
;
2648 return RX_DROP_MONITOR
;
2652 mppath
= mpp_path_lookup(sdata
, proxied_addr
);
2654 mpp_path_add(sdata
, proxied_addr
, mpp_addr
);
2656 spin_lock_bh(&mppath
->state_lock
);
2657 if (!ether_addr_equal(mppath
->mpp
, mpp_addr
))
2658 memcpy(mppath
->mpp
, mpp_addr
, ETH_ALEN
);
2659 mppath
->exp_time
= jiffies
;
2660 spin_unlock_bh(&mppath
->state_lock
);
2665 /* Frame has reached destination. Don't forward */
2666 if (!is_multicast_ether_addr(hdr
->addr1
) &&
2667 ether_addr_equal(sdata
->vif
.addr
, hdr
->addr3
))
2670 ac
= ieee80211_select_queue_80211(sdata
, skb
, hdr
);
2671 q
= sdata
->vif
.hw_queue
[ac
];
2672 if (ieee80211_queue_stopped(&local
->hw
, q
)) {
2673 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, dropped_frames_congestion
);
2674 return RX_DROP_MONITOR
;
2676 skb_set_queue_mapping(skb
, q
);
2678 if (!--mesh_hdr
->ttl
) {
2679 if (!is_multicast_ether_addr(hdr
->addr1
))
2680 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
,
2681 dropped_frames_ttl
);
2685 if (!ifmsh
->mshcfg
.dot11MeshForwarding
)
2688 if (sdata
->crypto_tx_tailroom_needed_cnt
)
2689 tailroom
= IEEE80211_ENCRYPT_TAILROOM
;
2691 fwd_skb
= skb_copy_expand(skb
, local
->tx_headroom
+
2692 sdata
->encrypt_headroom
,
2693 tailroom
, GFP_ATOMIC
);
2697 fwd_hdr
= (struct ieee80211_hdr
*) fwd_skb
->data
;
2698 fwd_hdr
->frame_control
&= ~cpu_to_le16(IEEE80211_FCTL_RETRY
);
2699 info
= IEEE80211_SKB_CB(fwd_skb
);
2700 memset(info
, 0, sizeof(*info
));
2701 info
->flags
|= IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
2702 info
->control
.vif
= &rx
->sdata
->vif
;
2703 info
->control
.jiffies
= jiffies
;
2704 if (is_multicast_ether_addr(fwd_hdr
->addr1
)) {
2705 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, fwded_mcast
);
2706 memcpy(fwd_hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2707 /* update power mode indication when forwarding */
2708 ieee80211_mps_set_frame_flags(sdata
, NULL
, fwd_hdr
);
2709 } else if (!mesh_nexthop_lookup(sdata
, fwd_skb
)) {
2710 /* mesh power mode flags updated in mesh_nexthop_lookup */
2711 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, fwded_unicast
);
2713 /* unable to resolve next hop */
2714 mesh_path_error_tx(sdata
, ifmsh
->mshcfg
.element_ttl
,
2716 WLAN_REASON_MESH_PATH_NOFORWARD
,
2718 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, dropped_frames_no_route
);
2720 return RX_DROP_MONITOR
;
2723 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, fwded_frames
);
2724 ieee80211_add_pending_skb(local
, fwd_skb
);
2726 if (is_multicast_ether_addr(hdr
->addr1
))
2728 return RX_DROP_MONITOR
;
2732 static ieee80211_rx_result debug_noinline
2733 ieee80211_rx_h_data(struct ieee80211_rx_data
*rx
)
2735 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2736 struct ieee80211_local
*local
= rx
->local
;
2737 struct net_device
*dev
= sdata
->dev
;
2738 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2739 __le16 fc
= hdr
->frame_control
;
2743 if (unlikely(!ieee80211_is_data(hdr
->frame_control
)))
2746 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
2747 return RX_DROP_MONITOR
;
2750 * Send unexpected-4addr-frame event to hostapd. For older versions,
2751 * also drop the frame to cooked monitor interfaces.
2753 if (ieee80211_has_a4(hdr
->frame_control
) &&
2754 sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
2756 !test_and_set_sta_flag(rx
->sta
, WLAN_STA_4ADDR_EVENT
))
2757 cfg80211_rx_unexpected_4addr_frame(
2758 rx
->sdata
->dev
, rx
->sta
->sta
.addr
, GFP_ATOMIC
);
2759 return RX_DROP_MONITOR
;
2762 err
= __ieee80211_data_to_8023(rx
, &port_control
);
2764 return RX_DROP_UNUSABLE
;
2766 if (!ieee80211_frame_allowed(rx
, fc
))
2767 return RX_DROP_MONITOR
;
2769 /* directly handle TDLS channel switch requests/responses */
2770 if (unlikely(((struct ethhdr
*)rx
->skb
->data
)->h_proto
==
2771 cpu_to_be16(ETH_P_TDLS
))) {
2772 struct ieee80211_tdls_data
*tf
= (void *)rx
->skb
->data
;
2774 if (pskb_may_pull(rx
->skb
,
2775 offsetof(struct ieee80211_tdls_data
, u
)) &&
2776 tf
->payload_type
== WLAN_TDLS_SNAP_RFTYPE
&&
2777 tf
->category
== WLAN_CATEGORY_TDLS
&&
2778 (tf
->action_code
== WLAN_TDLS_CHANNEL_SWITCH_REQUEST
||
2779 tf
->action_code
== WLAN_TDLS_CHANNEL_SWITCH_RESPONSE
)) {
2780 skb_queue_tail(&local
->skb_queue_tdls_chsw
, rx
->skb
);
2781 schedule_work(&local
->tdls_chsw_work
);
2783 rx
->sta
->rx_stats
.packets
++;
2789 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
2790 unlikely(port_control
) && sdata
->bss
) {
2791 sdata
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
,
2799 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
) &&
2800 local
->ps_sdata
&& local
->hw
.conf
.dynamic_ps_timeout
> 0 &&
2801 !is_multicast_ether_addr(
2802 ((struct ethhdr
*)rx
->skb
->data
)->h_dest
) &&
2803 (!local
->scanning
&&
2804 !test_bit(SDATA_STATE_OFFCHANNEL
, &sdata
->state
)))
2805 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
2806 msecs_to_jiffies(local
->hw
.conf
.dynamic_ps_timeout
));
2808 ieee80211_deliver_skb(rx
);
2813 static ieee80211_rx_result debug_noinline
2814 ieee80211_rx_h_ctrl(struct ieee80211_rx_data
*rx
, struct sk_buff_head
*frames
)
2816 struct sk_buff
*skb
= rx
->skb
;
2817 struct ieee80211_bar
*bar
= (struct ieee80211_bar
*)skb
->data
;
2818 struct tid_ampdu_rx
*tid_agg_rx
;
2822 if (likely(!ieee80211_is_ctl(bar
->frame_control
)))
2825 if (ieee80211_is_back_req(bar
->frame_control
)) {
2827 __le16 control
, start_seq_num
;
2828 } __packed bar_data
;
2829 struct ieee80211_event event
= {
2830 .type
= BAR_RX_EVENT
,
2834 return RX_DROP_MONITOR
;
2836 if (skb_copy_bits(skb
, offsetof(struct ieee80211_bar
, control
),
2837 &bar_data
, sizeof(bar_data
)))
2838 return RX_DROP_MONITOR
;
2840 tid
= le16_to_cpu(bar_data
.control
) >> 12;
2842 if (!test_bit(tid
, rx
->sta
->ampdu_mlme
.agg_session_valid
) &&
2843 !test_and_set_bit(tid
, rx
->sta
->ampdu_mlme
.unexpected_agg
))
2844 ieee80211_send_delba(rx
->sdata
, rx
->sta
->sta
.addr
, tid
,
2845 WLAN_BACK_RECIPIENT
,
2846 WLAN_REASON_QSTA_REQUIRE_SETUP
);
2848 tid_agg_rx
= rcu_dereference(rx
->sta
->ampdu_mlme
.tid_rx
[tid
]);
2850 return RX_DROP_MONITOR
;
2852 start_seq_num
= le16_to_cpu(bar_data
.start_seq_num
) >> 4;
2853 event
.u
.ba
.tid
= tid
;
2854 event
.u
.ba
.ssn
= start_seq_num
;
2855 event
.u
.ba
.sta
= &rx
->sta
->sta
;
2857 /* reset session timer */
2858 if (tid_agg_rx
->timeout
)
2859 mod_timer(&tid_agg_rx
->session_timer
,
2860 TU_TO_EXP_TIME(tid_agg_rx
->timeout
));
2862 spin_lock(&tid_agg_rx
->reorder_lock
);
2863 /* release stored frames up to start of BAR */
2864 ieee80211_release_reorder_frames(rx
->sdata
, tid_agg_rx
,
2865 start_seq_num
, frames
);
2866 spin_unlock(&tid_agg_rx
->reorder_lock
);
2868 drv_event_callback(rx
->local
, rx
->sdata
, &event
);
2875 * After this point, we only want management frames,
2876 * so we can drop all remaining control frames to
2877 * cooked monitor interfaces.
2879 return RX_DROP_MONITOR
;
2882 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data
*sdata
,
2883 struct ieee80211_mgmt
*mgmt
,
2886 struct ieee80211_local
*local
= sdata
->local
;
2887 struct sk_buff
*skb
;
2888 struct ieee80211_mgmt
*resp
;
2890 if (!ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
)) {
2891 /* Not to own unicast address */
2895 if (!ether_addr_equal(mgmt
->sa
, sdata
->u
.mgd
.bssid
) ||
2896 !ether_addr_equal(mgmt
->bssid
, sdata
->u
.mgd
.bssid
)) {
2897 /* Not from the current AP or not associated yet. */
2901 if (len
< 24 + 1 + sizeof(resp
->u
.action
.u
.sa_query
)) {
2902 /* Too short SA Query request frame */
2906 skb
= dev_alloc_skb(sizeof(*resp
) + local
->hw
.extra_tx_headroom
);
2910 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2911 resp
= skb_put_zero(skb
, 24);
2912 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2913 memcpy(resp
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
2914 memcpy(resp
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2915 resp
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2916 IEEE80211_STYPE_ACTION
);
2917 skb_put(skb
, 1 + sizeof(resp
->u
.action
.u
.sa_query
));
2918 resp
->u
.action
.category
= WLAN_CATEGORY_SA_QUERY
;
2919 resp
->u
.action
.u
.sa_query
.action
= WLAN_ACTION_SA_QUERY_RESPONSE
;
2920 memcpy(resp
->u
.action
.u
.sa_query
.trans_id
,
2921 mgmt
->u
.action
.u
.sa_query
.trans_id
,
2922 WLAN_SA_QUERY_TR_ID_LEN
);
2924 ieee80211_tx_skb(sdata
, skb
);
2927 static ieee80211_rx_result debug_noinline
2928 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data
*rx
)
2930 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
2931 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
2934 * From here on, look only at management frames.
2935 * Data and control frames are already handled,
2936 * and unknown (reserved) frames are useless.
2938 if (rx
->skb
->len
< 24)
2939 return RX_DROP_MONITOR
;
2941 if (!ieee80211_is_mgmt(mgmt
->frame_control
))
2942 return RX_DROP_MONITOR
;
2944 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
&&
2945 ieee80211_is_beacon(mgmt
->frame_control
) &&
2946 !(rx
->flags
& IEEE80211_RX_BEACON_REPORTED
)) {
2949 if (ieee80211_hw_check(&rx
->local
->hw
, SIGNAL_DBM
) &&
2950 !(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
))
2951 sig
= status
->signal
;
2953 cfg80211_report_obss_beacon(rx
->local
->hw
.wiphy
,
2954 rx
->skb
->data
, rx
->skb
->len
,
2956 rx
->flags
|= IEEE80211_RX_BEACON_REPORTED
;
2959 if (ieee80211_drop_unencrypted_mgmt(rx
))
2960 return RX_DROP_UNUSABLE
;
2965 static ieee80211_rx_result debug_noinline
2966 ieee80211_rx_h_action(struct ieee80211_rx_data
*rx
)
2968 struct ieee80211_local
*local
= rx
->local
;
2969 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2970 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
2971 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
2972 int len
= rx
->skb
->len
;
2974 if (!ieee80211_is_action(mgmt
->frame_control
))
2977 /* drop too small frames */
2978 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2979 return RX_DROP_UNUSABLE
;
2981 if (!rx
->sta
&& mgmt
->u
.action
.category
!= WLAN_CATEGORY_PUBLIC
&&
2982 mgmt
->u
.action
.category
!= WLAN_CATEGORY_SELF_PROTECTED
&&
2983 mgmt
->u
.action
.category
!= WLAN_CATEGORY_SPECTRUM_MGMT
)
2984 return RX_DROP_UNUSABLE
;
2986 switch (mgmt
->u
.action
.category
) {
2987 case WLAN_CATEGORY_HT
:
2988 /* reject HT action frames from stations not supporting HT */
2989 if (!rx
->sta
->sta
.ht_cap
.ht_supported
)
2992 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
2993 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
&&
2994 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
2995 sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
2996 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
2999 /* verify action & smps_control/chanwidth are present */
3000 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 2)
3003 switch (mgmt
->u
.action
.u
.ht_smps
.action
) {
3004 case WLAN_HT_ACTION_SMPS
: {
3005 struct ieee80211_supported_band
*sband
;
3006 enum ieee80211_smps_mode smps_mode
;
3007 struct sta_opmode_info sta_opmode
= {};
3009 /* convert to HT capability */
3010 switch (mgmt
->u
.action
.u
.ht_smps
.smps_control
) {
3011 case WLAN_HT_SMPS_CONTROL_DISABLED
:
3012 smps_mode
= IEEE80211_SMPS_OFF
;
3014 case WLAN_HT_SMPS_CONTROL_STATIC
:
3015 smps_mode
= IEEE80211_SMPS_STATIC
;
3017 case WLAN_HT_SMPS_CONTROL_DYNAMIC
:
3018 smps_mode
= IEEE80211_SMPS_DYNAMIC
;
3024 /* if no change do nothing */
3025 if (rx
->sta
->sta
.smps_mode
== smps_mode
)
3027 rx
->sta
->sta
.smps_mode
= smps_mode
;
3028 sta_opmode
.smps_mode
=
3029 ieee80211_smps_mode_to_smps_mode(smps_mode
);
3030 sta_opmode
.changed
= STA_OPMODE_SMPS_MODE_CHANGED
;
3032 sband
= rx
->local
->hw
.wiphy
->bands
[status
->band
];
3034 rate_control_rate_update(local
, sband
, rx
->sta
,
3035 IEEE80211_RC_SMPS_CHANGED
);
3036 cfg80211_sta_opmode_change_notify(sdata
->dev
,
3042 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH
: {
3043 struct ieee80211_supported_band
*sband
;
3044 u8 chanwidth
= mgmt
->u
.action
.u
.ht_notify_cw
.chanwidth
;
3045 enum ieee80211_sta_rx_bandwidth max_bw
, new_bw
;
3046 struct sta_opmode_info sta_opmode
= {};
3048 /* If it doesn't support 40 MHz it can't change ... */
3049 if (!(rx
->sta
->sta
.ht_cap
.cap
&
3050 IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
3053 if (chanwidth
== IEEE80211_HT_CHANWIDTH_20MHZ
)
3054 max_bw
= IEEE80211_STA_RX_BW_20
;
3056 max_bw
= ieee80211_sta_cap_rx_bw(rx
->sta
);
3058 /* set cur_max_bandwidth and recalc sta bw */
3059 rx
->sta
->cur_max_bandwidth
= max_bw
;
3060 new_bw
= ieee80211_sta_cur_vht_bw(rx
->sta
);
3062 if (rx
->sta
->sta
.bandwidth
== new_bw
)
3065 rx
->sta
->sta
.bandwidth
= new_bw
;
3066 sband
= rx
->local
->hw
.wiphy
->bands
[status
->band
];
3068 ieee80211_sta_rx_bw_to_chan_width(rx
->sta
);
3069 sta_opmode
.changed
= STA_OPMODE_MAX_BW_CHANGED
;
3071 rate_control_rate_update(local
, sband
, rx
->sta
,
3072 IEEE80211_RC_BW_CHANGED
);
3073 cfg80211_sta_opmode_change_notify(sdata
->dev
,
3084 case WLAN_CATEGORY_PUBLIC
:
3085 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3087 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3091 if (!ether_addr_equal(mgmt
->bssid
, sdata
->u
.mgd
.bssid
))
3093 if (mgmt
->u
.action
.u
.ext_chan_switch
.action_code
!=
3094 WLAN_PUB_ACTION_EXT_CHANSW_ANN
)
3096 if (len
< offsetof(struct ieee80211_mgmt
,
3097 u
.action
.u
.ext_chan_switch
.variable
))
3100 case WLAN_CATEGORY_VHT
:
3101 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3102 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
&&
3103 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
3104 sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
3105 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
3108 /* verify action code is present */
3109 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3112 switch (mgmt
->u
.action
.u
.vht_opmode_notif
.action_code
) {
3113 case WLAN_VHT_ACTION_OPMODE_NOTIF
: {
3114 /* verify opmode is present */
3115 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 2)
3119 case WLAN_VHT_ACTION_GROUPID_MGMT
: {
3120 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 25)
3128 case WLAN_CATEGORY_BACK
:
3129 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3130 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
&&
3131 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
3132 sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
3133 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
3136 /* verify action_code is present */
3137 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3140 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
3141 case WLAN_ACTION_ADDBA_REQ
:
3142 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3143 sizeof(mgmt
->u
.action
.u
.addba_req
)))
3146 case WLAN_ACTION_ADDBA_RESP
:
3147 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3148 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
3151 case WLAN_ACTION_DELBA
:
3152 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3153 sizeof(mgmt
->u
.action
.u
.delba
)))
3161 case WLAN_CATEGORY_SPECTRUM_MGMT
:
3162 /* verify action_code is present */
3163 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3166 switch (mgmt
->u
.action
.u
.measurement
.action_code
) {
3167 case WLAN_ACTION_SPCT_MSR_REQ
:
3168 if (status
->band
!= NL80211_BAND_5GHZ
)
3171 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3172 sizeof(mgmt
->u
.action
.u
.measurement
)))
3175 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3178 ieee80211_process_measurement_req(sdata
, mgmt
, len
);
3180 case WLAN_ACTION_SPCT_CHL_SWITCH
: {
3182 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3183 sizeof(mgmt
->u
.action
.u
.chan_switch
)))
3186 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3187 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
3188 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
3191 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
3192 bssid
= sdata
->u
.mgd
.bssid
;
3193 else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
)
3194 bssid
= sdata
->u
.ibss
.bssid
;
3195 else if (sdata
->vif
.type
== NL80211_IFTYPE_MESH_POINT
)
3200 if (!ether_addr_equal(mgmt
->bssid
, bssid
))
3207 case WLAN_CATEGORY_SA_QUERY
:
3208 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3209 sizeof(mgmt
->u
.action
.u
.sa_query
)))
3212 switch (mgmt
->u
.action
.u
.sa_query
.action
) {
3213 case WLAN_ACTION_SA_QUERY_REQUEST
:
3214 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3216 ieee80211_process_sa_query_req(sdata
, mgmt
, len
);
3220 case WLAN_CATEGORY_SELF_PROTECTED
:
3221 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3222 sizeof(mgmt
->u
.action
.u
.self_prot
.action_code
)))
3225 switch (mgmt
->u
.action
.u
.self_prot
.action_code
) {
3226 case WLAN_SP_MESH_PEERING_OPEN
:
3227 case WLAN_SP_MESH_PEERING_CLOSE
:
3228 case WLAN_SP_MESH_PEERING_CONFIRM
:
3229 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
3231 if (sdata
->u
.mesh
.user_mpm
)
3232 /* userspace handles this frame */
3235 case WLAN_SP_MGK_INFORM
:
3236 case WLAN_SP_MGK_ACK
:
3237 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
3242 case WLAN_CATEGORY_MESH_ACTION
:
3243 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3244 sizeof(mgmt
->u
.action
.u
.mesh_action
.action_code
)))
3247 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
3249 if (mesh_action_is_path_sel(mgmt
) &&
3250 !mesh_path_sel_is_hwmp(sdata
))
3258 status
->rx_flags
|= IEEE80211_RX_MALFORMED_ACTION_FRM
;
3259 /* will return in the next handlers */
3264 rx
->sta
->rx_stats
.packets
++;
3265 dev_kfree_skb(rx
->skb
);
3269 skb_queue_tail(&sdata
->skb_queue
, rx
->skb
);
3270 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
3272 rx
->sta
->rx_stats
.packets
++;
3276 static ieee80211_rx_result debug_noinline
3277 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data
*rx
)
3279 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
3282 /* skip known-bad action frames and return them in the next handler */
3283 if (status
->rx_flags
& IEEE80211_RX_MALFORMED_ACTION_FRM
)
3287 * Getting here means the kernel doesn't know how to handle
3288 * it, but maybe userspace does ... include returned frames
3289 * so userspace can register for those to know whether ones
3290 * it transmitted were processed or returned.
3293 if (ieee80211_hw_check(&rx
->local
->hw
, SIGNAL_DBM
) &&
3294 !(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
))
3295 sig
= status
->signal
;
3297 if (cfg80211_rx_mgmt(&rx
->sdata
->wdev
, status
->freq
, sig
,
3298 rx
->skb
->data
, rx
->skb
->len
, 0)) {
3300 rx
->sta
->rx_stats
.packets
++;
3301 dev_kfree_skb(rx
->skb
);
3308 static ieee80211_rx_result debug_noinline
3309 ieee80211_rx_h_action_return(struct ieee80211_rx_data
*rx
)
3311 struct ieee80211_local
*local
= rx
->local
;
3312 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
3313 struct sk_buff
*nskb
;
3314 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3315 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
3317 if (!ieee80211_is_action(mgmt
->frame_control
))
3321 * For AP mode, hostapd is responsible for handling any action
3322 * frames that we didn't handle, including returning unknown
3323 * ones. For all other modes we will return them to the sender,
3324 * setting the 0x80 bit in the action category, as required by
3325 * 802.11-2012 9.24.4.
3326 * Newer versions of hostapd shall also use the management frame
3327 * registration mechanisms, but older ones still use cooked
3328 * monitor interfaces so push all frames there.
3330 if (!(status
->rx_flags
& IEEE80211_RX_MALFORMED_ACTION_FRM
) &&
3331 (sdata
->vif
.type
== NL80211_IFTYPE_AP
||
3332 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
))
3333 return RX_DROP_MONITOR
;
3335 if (is_multicast_ether_addr(mgmt
->da
))
3336 return RX_DROP_MONITOR
;
3338 /* do not return rejected action frames */
3339 if (mgmt
->u
.action
.category
& 0x80)
3340 return RX_DROP_UNUSABLE
;
3342 nskb
= skb_copy_expand(rx
->skb
, local
->hw
.extra_tx_headroom
, 0,
3345 struct ieee80211_mgmt
*nmgmt
= (void *)nskb
->data
;
3347 nmgmt
->u
.action
.category
|= 0x80;
3348 memcpy(nmgmt
->da
, nmgmt
->sa
, ETH_ALEN
);
3349 memcpy(nmgmt
->sa
, rx
->sdata
->vif
.addr
, ETH_ALEN
);
3351 memset(nskb
->cb
, 0, sizeof(nskb
->cb
));
3353 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_P2P_DEVICE
) {
3354 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(nskb
);
3356 info
->flags
= IEEE80211_TX_CTL_TX_OFFCHAN
|
3357 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
|
3358 IEEE80211_TX_CTL_NO_CCK_RATE
;
3359 if (ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
))
3361 local
->hw
.offchannel_tx_hw_queue
;
3364 __ieee80211_tx_skb_tid_band(rx
->sdata
, nskb
, 7,
3367 dev_kfree_skb(rx
->skb
);
3371 static ieee80211_rx_result debug_noinline
3372 ieee80211_rx_h_mgmt(struct ieee80211_rx_data
*rx
)
3374 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3375 struct ieee80211_mgmt
*mgmt
= (void *)rx
->skb
->data
;
3378 stype
= mgmt
->frame_control
& cpu_to_le16(IEEE80211_FCTL_STYPE
);
3380 if (!ieee80211_vif_is_mesh(&sdata
->vif
) &&
3381 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
3382 sdata
->vif
.type
!= NL80211_IFTYPE_OCB
&&
3383 sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3384 return RX_DROP_MONITOR
;
3387 case cpu_to_le16(IEEE80211_STYPE_AUTH
):
3388 case cpu_to_le16(IEEE80211_STYPE_BEACON
):
3389 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
):
3390 /* process for all: mesh, mlme, ibss */
3392 case cpu_to_le16(IEEE80211_STYPE_DEAUTH
):
3393 if (is_multicast_ether_addr(mgmt
->da
) &&
3394 !is_broadcast_ether_addr(mgmt
->da
))
3395 return RX_DROP_MONITOR
;
3397 /* process only for station/IBSS */
3398 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3399 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
3400 return RX_DROP_MONITOR
;
3402 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
):
3403 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP
):
3404 case cpu_to_le16(IEEE80211_STYPE_DISASSOC
):
3405 if (is_multicast_ether_addr(mgmt
->da
) &&
3406 !is_broadcast_ether_addr(mgmt
->da
))
3407 return RX_DROP_MONITOR
;
3409 /* process only for station */
3410 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3411 return RX_DROP_MONITOR
;
3413 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
):
3414 /* process only for ibss and mesh */
3415 if (sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
3416 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
3417 return RX_DROP_MONITOR
;
3420 return RX_DROP_MONITOR
;
3423 /* queue up frame and kick off work to process it */
3424 skb_queue_tail(&sdata
->skb_queue
, rx
->skb
);
3425 ieee80211_queue_work(&rx
->local
->hw
, &sdata
->work
);
3427 rx
->sta
->rx_stats
.packets
++;
3432 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data
*rx
,
3433 struct ieee80211_rate
*rate
)
3435 struct ieee80211_sub_if_data
*sdata
;
3436 struct ieee80211_local
*local
= rx
->local
;
3437 struct sk_buff
*skb
= rx
->skb
, *skb2
;
3438 struct net_device
*prev_dev
= NULL
;
3439 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
3440 int needed_headroom
;
3443 * If cooked monitor has been processed already, then
3444 * don't do it again. If not, set the flag.
3446 if (rx
->flags
& IEEE80211_RX_CMNTR
)
3448 rx
->flags
|= IEEE80211_RX_CMNTR
;
3450 /* If there are no cooked monitor interfaces, just free the SKB */
3451 if (!local
->cooked_mntrs
)
3454 /* vendor data is long removed here */
3455 status
->flag
&= ~RX_FLAG_RADIOTAP_VENDOR_DATA
;
3456 /* room for the radiotap header based on driver features */
3457 needed_headroom
= ieee80211_rx_radiotap_hdrlen(local
, status
, skb
);
3459 if (skb_headroom(skb
) < needed_headroom
&&
3460 pskb_expand_head(skb
, needed_headroom
, 0, GFP_ATOMIC
))
3463 /* prepend radiotap information */
3464 ieee80211_add_rx_radiotap_header(local
, skb
, rate
, needed_headroom
,
3467 skb_reset_mac_header(skb
);
3468 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3469 skb
->pkt_type
= PACKET_OTHERHOST
;
3470 skb
->protocol
= htons(ETH_P_802_2
);
3472 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3473 if (!ieee80211_sdata_running(sdata
))
3476 if (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
||
3477 !(sdata
->u
.mntr
.flags
& MONITOR_FLAG_COOK_FRAMES
))
3481 skb2
= skb_clone(skb
, GFP_ATOMIC
);
3483 skb2
->dev
= prev_dev
;
3484 netif_receive_skb(skb2
);
3488 prev_dev
= sdata
->dev
;
3489 ieee80211_rx_stats(sdata
->dev
, skb
->len
);
3493 skb
->dev
= prev_dev
;
3494 netif_receive_skb(skb
);
3502 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data
*rx
,
3503 ieee80211_rx_result res
)
3506 case RX_DROP_MONITOR
:
3507 I802_DEBUG_INC(rx
->sdata
->local
->rx_handlers_drop
);
3509 rx
->sta
->rx_stats
.dropped
++;
3512 struct ieee80211_rate
*rate
= NULL
;
3513 struct ieee80211_supported_band
*sband
;
3514 struct ieee80211_rx_status
*status
;
3516 status
= IEEE80211_SKB_RXCB((rx
->skb
));
3518 sband
= rx
->local
->hw
.wiphy
->bands
[status
->band
];
3519 if (status
->encoding
== RX_ENC_LEGACY
)
3520 rate
= &sband
->bitrates
[status
->rate_idx
];
3522 ieee80211_rx_cooked_monitor(rx
, rate
);
3525 case RX_DROP_UNUSABLE
:
3526 I802_DEBUG_INC(rx
->sdata
->local
->rx_handlers_drop
);
3528 rx
->sta
->rx_stats
.dropped
++;
3529 dev_kfree_skb(rx
->skb
);
3532 I802_DEBUG_INC(rx
->sdata
->local
->rx_handlers_queued
);
3537 static void ieee80211_rx_handlers(struct ieee80211_rx_data
*rx
,
3538 struct sk_buff_head
*frames
)
3540 ieee80211_rx_result res
= RX_DROP_MONITOR
;
3541 struct sk_buff
*skb
;
3543 #define CALL_RXH(rxh) \
3546 if (res != RX_CONTINUE) \
3550 /* Lock here to avoid hitting all of the data used in the RX
3551 * path (e.g. key data, station data, ...) concurrently when
3552 * a frame is released from the reorder buffer due to timeout
3553 * from the timer, potentially concurrently with RX from the
3556 spin_lock_bh(&rx
->local
->rx_path_lock
);
3558 while ((skb
= __skb_dequeue(frames
))) {
3560 * all the other fields are valid across frames
3561 * that belong to an aMPDU since they are on the
3562 * same TID from the same station
3566 CALL_RXH(ieee80211_rx_h_check_more_data
);
3567 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll
);
3568 CALL_RXH(ieee80211_rx_h_sta_process
);
3569 CALL_RXH(ieee80211_rx_h_decrypt
);
3570 CALL_RXH(ieee80211_rx_h_defragment
);
3571 CALL_RXH(ieee80211_rx_h_michael_mic_verify
);
3572 /* must be after MMIC verify so header is counted in MPDU mic */
3573 #ifdef CONFIG_MAC80211_MESH
3574 if (ieee80211_vif_is_mesh(&rx
->sdata
->vif
))
3575 CALL_RXH(ieee80211_rx_h_mesh_fwding
);
3577 CALL_RXH(ieee80211_rx_h_amsdu
);
3578 CALL_RXH(ieee80211_rx_h_data
);
3580 /* special treatment -- needs the queue */
3581 res
= ieee80211_rx_h_ctrl(rx
, frames
);
3582 if (res
!= RX_CONTINUE
)
3585 CALL_RXH(ieee80211_rx_h_mgmt_check
);
3586 CALL_RXH(ieee80211_rx_h_action
);
3587 CALL_RXH(ieee80211_rx_h_userspace_mgmt
);
3588 CALL_RXH(ieee80211_rx_h_action_return
);
3589 CALL_RXH(ieee80211_rx_h_mgmt
);
3592 ieee80211_rx_handlers_result(rx
, res
);
3597 spin_unlock_bh(&rx
->local
->rx_path_lock
);
3600 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data
*rx
)
3602 struct sk_buff_head reorder_release
;
3603 ieee80211_rx_result res
= RX_DROP_MONITOR
;
3605 __skb_queue_head_init(&reorder_release
);
3607 #define CALL_RXH(rxh) \
3610 if (res != RX_CONTINUE) \
3614 CALL_RXH(ieee80211_rx_h_check_dup
);
3615 CALL_RXH(ieee80211_rx_h_check
);
3617 ieee80211_rx_reorder_ampdu(rx
, &reorder_release
);
3619 ieee80211_rx_handlers(rx
, &reorder_release
);
3623 ieee80211_rx_handlers_result(rx
, res
);
3629 * This function makes calls into the RX path, therefore
3630 * it has to be invoked under RCU read lock.
3632 void ieee80211_release_reorder_timeout(struct sta_info
*sta
, int tid
)
3634 struct sk_buff_head frames
;
3635 struct ieee80211_rx_data rx
= {
3637 .sdata
= sta
->sdata
,
3638 .local
= sta
->local
,
3639 /* This is OK -- must be QoS data frame */
3640 .security_idx
= tid
,
3642 .napi
= NULL
, /* must be NULL to not have races */
3644 struct tid_ampdu_rx
*tid_agg_rx
;
3646 tid_agg_rx
= rcu_dereference(sta
->ampdu_mlme
.tid_rx
[tid
]);
3650 __skb_queue_head_init(&frames
);
3652 spin_lock(&tid_agg_rx
->reorder_lock
);
3653 ieee80211_sta_reorder_release(sta
->sdata
, tid_agg_rx
, &frames
);
3654 spin_unlock(&tid_agg_rx
->reorder_lock
);
3656 if (!skb_queue_empty(&frames
)) {
3657 struct ieee80211_event event
= {
3658 .type
= BA_FRAME_TIMEOUT
,
3660 .u
.ba
.sta
= &sta
->sta
,
3662 drv_event_callback(rx
.local
, rx
.sdata
, &event
);
3665 ieee80211_rx_handlers(&rx
, &frames
);
3668 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta
*pubsta
, u8 tid
,
3669 u16 ssn
, u64 filtered
,
3672 struct sta_info
*sta
;
3673 struct tid_ampdu_rx
*tid_agg_rx
;
3674 struct sk_buff_head frames
;
3675 struct ieee80211_rx_data rx
= {
3676 /* This is OK -- must be QoS data frame */
3677 .security_idx
= tid
,
3682 if (WARN_ON(!pubsta
|| tid
>= IEEE80211_NUM_TIDS
))
3685 __skb_queue_head_init(&frames
);
3687 sta
= container_of(pubsta
, struct sta_info
, sta
);
3690 rx
.sdata
= sta
->sdata
;
3691 rx
.local
= sta
->local
;
3694 tid_agg_rx
= rcu_dereference(sta
->ampdu_mlme
.tid_rx
[tid
]);
3698 spin_lock_bh(&tid_agg_rx
->reorder_lock
);
3700 if (received_mpdus
>= IEEE80211_SN_MODULO
>> 1) {
3703 /* release all frames in the reorder buffer */
3704 release
= (tid_agg_rx
->head_seq_num
+ tid_agg_rx
->buf_size
) %
3705 IEEE80211_SN_MODULO
;
3706 ieee80211_release_reorder_frames(sta
->sdata
, tid_agg_rx
,
3708 /* update ssn to match received ssn */
3709 tid_agg_rx
->head_seq_num
= ssn
;
3711 ieee80211_release_reorder_frames(sta
->sdata
, tid_agg_rx
, ssn
,
3715 /* handle the case that received ssn is behind the mac ssn.
3716 * it can be tid_agg_rx->buf_size behind and still be valid */
3717 diff
= (tid_agg_rx
->head_seq_num
- ssn
) & IEEE80211_SN_MASK
;
3718 if (diff
>= tid_agg_rx
->buf_size
) {
3719 tid_agg_rx
->reorder_buf_filtered
= 0;
3722 filtered
= filtered
>> diff
;
3726 for (i
= 0; i
< tid_agg_rx
->buf_size
; i
++) {
3727 int index
= (ssn
+ i
) % tid_agg_rx
->buf_size
;
3729 tid_agg_rx
->reorder_buf_filtered
&= ~BIT_ULL(index
);
3730 if (filtered
& BIT_ULL(i
))
3731 tid_agg_rx
->reorder_buf_filtered
|= BIT_ULL(index
);
3734 /* now process also frames that the filter marking released */
3735 ieee80211_sta_reorder_release(sta
->sdata
, tid_agg_rx
, &frames
);
3738 spin_unlock_bh(&tid_agg_rx
->reorder_lock
);
3740 ieee80211_rx_handlers(&rx
, &frames
);
3745 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames
);
3747 /* main receive path */
3749 static bool ieee80211_accept_frame(struct ieee80211_rx_data
*rx
)
3751 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3752 struct sk_buff
*skb
= rx
->skb
;
3753 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3754 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
3755 u8
*bssid
= ieee80211_get_bssid(hdr
, skb
->len
, sdata
->vif
.type
);
3756 bool multicast
= is_multicast_ether_addr(hdr
->addr1
);
3758 switch (sdata
->vif
.type
) {
3759 case NL80211_IFTYPE_STATION
:
3760 if (!bssid
&& !sdata
->u
.mgd
.use_4addr
)
3762 if (ieee80211_is_robust_mgmt_frame(skb
) && !rx
->sta
)
3766 return ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
);
3767 case NL80211_IFTYPE_ADHOC
:
3770 if (ether_addr_equal(sdata
->vif
.addr
, hdr
->addr2
) ||
3771 ether_addr_equal(sdata
->u
.ibss
.bssid
, hdr
->addr2
))
3773 if (ieee80211_is_beacon(hdr
->frame_control
))
3775 if (!ieee80211_bssid_match(bssid
, sdata
->u
.ibss
.bssid
))
3778 !ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
))
3782 if (status
->encoding
!= RX_ENC_LEGACY
)
3783 rate_idx
= 0; /* TODO: HT/VHT rates */
3785 rate_idx
= status
->rate_idx
;
3786 ieee80211_ibss_rx_no_sta(sdata
, bssid
, hdr
->addr2
,
3790 case NL80211_IFTYPE_OCB
:
3793 if (!ieee80211_is_data_present(hdr
->frame_control
))
3795 if (!is_broadcast_ether_addr(bssid
))
3798 !ether_addr_equal(sdata
->dev
->dev_addr
, hdr
->addr1
))
3802 if (status
->encoding
!= RX_ENC_LEGACY
)
3803 rate_idx
= 0; /* TODO: HT rates */
3805 rate_idx
= status
->rate_idx
;
3806 ieee80211_ocb_rx_no_sta(sdata
, bssid
, hdr
->addr2
,
3810 case NL80211_IFTYPE_MESH_POINT
:
3811 if (ether_addr_equal(sdata
->vif
.addr
, hdr
->addr2
))
3815 return ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
);
3816 case NL80211_IFTYPE_AP_VLAN
:
3817 case NL80211_IFTYPE_AP
:
3819 return ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
);
3821 if (!ieee80211_bssid_match(bssid
, sdata
->vif
.addr
)) {
3823 * Accept public action frames even when the
3824 * BSSID doesn't match, this is used for P2P
3825 * and location updates. Note that mac80211
3826 * itself never looks at these frames.
3829 !ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
))
3831 if (ieee80211_is_public_action(hdr
, skb
->len
))
3833 return ieee80211_is_beacon(hdr
->frame_control
);
3836 if (!ieee80211_has_tods(hdr
->frame_control
)) {
3837 /* ignore data frames to TDLS-peers */
3838 if (ieee80211_is_data(hdr
->frame_control
))
3840 /* ignore action frames to TDLS-peers */
3841 if (ieee80211_is_action(hdr
->frame_control
) &&
3842 !is_broadcast_ether_addr(bssid
) &&
3843 !ether_addr_equal(bssid
, hdr
->addr1
))
3848 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3849 * the BSSID - we've checked that already but may have accepted
3850 * the wildcard (ff:ff:ff:ff:ff:ff).
3853 * The BSSID of the Data frame is determined as follows:
3854 * a) If the STA is contained within an AP or is associated
3855 * with an AP, the BSSID is the address currently in use
3856 * by the STA contained in the AP.
3858 * So we should not accept data frames with an address that's
3861 * Accepting it also opens a security problem because stations
3862 * could encrypt it with the GTK and inject traffic that way.
3864 if (ieee80211_is_data(hdr
->frame_control
) && multicast
)
3868 case NL80211_IFTYPE_WDS
:
3869 if (bssid
|| !ieee80211_is_data(hdr
->frame_control
))
3871 return ether_addr_equal(sdata
->u
.wds
.remote_addr
, hdr
->addr2
);
3872 case NL80211_IFTYPE_P2P_DEVICE
:
3873 return ieee80211_is_public_action(hdr
, skb
->len
) ||
3874 ieee80211_is_probe_req(hdr
->frame_control
) ||
3875 ieee80211_is_probe_resp(hdr
->frame_control
) ||
3876 ieee80211_is_beacon(hdr
->frame_control
);
3877 case NL80211_IFTYPE_NAN
:
3878 /* Currently no frames on NAN interface are allowed */
3888 void ieee80211_check_fast_rx(struct sta_info
*sta
)
3890 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
3891 struct ieee80211_local
*local
= sdata
->local
;
3892 struct ieee80211_key
*key
;
3893 struct ieee80211_fast_rx fastrx
= {
3895 .vif_type
= sdata
->vif
.type
,
3896 .control_port_protocol
= sdata
->control_port_protocol
,
3897 }, *old
, *new = NULL
;
3898 bool assign
= false;
3900 /* use sparse to check that we don't return without updating */
3901 __acquire(check_fast_rx
);
3903 BUILD_BUG_ON(sizeof(fastrx
.rfc1042_hdr
) != sizeof(rfc1042_header
));
3904 BUILD_BUG_ON(sizeof(fastrx
.rfc1042_hdr
) != ETH_ALEN
);
3905 ether_addr_copy(fastrx
.rfc1042_hdr
, rfc1042_header
);
3906 ether_addr_copy(fastrx
.vif_addr
, sdata
->vif
.addr
);
3908 fastrx
.uses_rss
= ieee80211_hw_check(&local
->hw
, USES_RSS
);
3910 /* fast-rx doesn't do reordering */
3911 if (ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
) &&
3912 !ieee80211_hw_check(&local
->hw
, SUPPORTS_REORDERING_BUFFER
))
3915 switch (sdata
->vif
.type
) {
3916 case NL80211_IFTYPE_STATION
:
3917 if (sta
->sta
.tdls
) {
3918 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
3919 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
3920 fastrx
.expected_ds_bits
= 0;
3922 fastrx
.sta_notify
= sdata
->u
.mgd
.probe_send_count
> 0;
3923 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
3924 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr3
);
3925 fastrx
.expected_ds_bits
=
3926 cpu_to_le16(IEEE80211_FCTL_FROMDS
);
3929 if (sdata
->u
.mgd
.use_4addr
&& !sta
->sta
.tdls
) {
3930 fastrx
.expected_ds_bits
|=
3931 cpu_to_le16(IEEE80211_FCTL_TODS
);
3932 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
3933 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
3936 if (!sdata
->u
.mgd
.powersave
)
3939 /* software powersave is a huge mess, avoid all of it */
3940 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
))
3942 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
) &&
3943 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
))
3946 case NL80211_IFTYPE_AP_VLAN
:
3947 case NL80211_IFTYPE_AP
:
3948 /* parallel-rx requires this, at least with calls to
3949 * ieee80211_sta_ps_transition()
3951 if (!ieee80211_hw_check(&local
->hw
, AP_LINK_PS
))
3953 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
3954 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
3955 fastrx
.expected_ds_bits
= cpu_to_le16(IEEE80211_FCTL_TODS
);
3957 fastrx
.internal_forward
=
3958 !(sdata
->flags
& IEEE80211_SDATA_DONT_BRIDGE_PACKETS
) &&
3959 (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
||
3960 !sdata
->u
.vlan
.sta
);
3962 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
3963 sdata
->u
.vlan
.sta
) {
3964 fastrx
.expected_ds_bits
|=
3965 cpu_to_le16(IEEE80211_FCTL_FROMDS
);
3966 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
3967 fastrx
.internal_forward
= 0;
3975 if (!test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
3979 key
= rcu_dereference(sta
->ptk
[sta
->ptk_idx
]);
3981 switch (key
->conf
.cipher
) {
3982 case WLAN_CIPHER_SUITE_TKIP
:
3983 /* we don't want to deal with MMIC in fast-rx */
3985 case WLAN_CIPHER_SUITE_CCMP
:
3986 case WLAN_CIPHER_SUITE_CCMP_256
:
3987 case WLAN_CIPHER_SUITE_GCMP
:
3988 case WLAN_CIPHER_SUITE_GCMP_256
:
3991 /* we also don't want to deal with WEP or cipher scheme
3992 * since those require looking up the key idx in the
3993 * frame, rather than assuming the PTK is used
3994 * (we need to revisit this once we implement the real
3995 * PTK index, which is now valid in the spec, but we
3996 * haven't implemented that part yet)
4002 fastrx
.icv_len
= key
->conf
.icv_len
;
4009 __release(check_fast_rx
);
4012 new = kmemdup(&fastrx
, sizeof(fastrx
), GFP_KERNEL
);
4014 spin_lock_bh(&sta
->lock
);
4015 old
= rcu_dereference_protected(sta
->fast_rx
, true);
4016 rcu_assign_pointer(sta
->fast_rx
, new);
4017 spin_unlock_bh(&sta
->lock
);
4020 kfree_rcu(old
, rcu_head
);
4023 void ieee80211_clear_fast_rx(struct sta_info
*sta
)
4025 struct ieee80211_fast_rx
*old
;
4027 spin_lock_bh(&sta
->lock
);
4028 old
= rcu_dereference_protected(sta
->fast_rx
, true);
4029 RCU_INIT_POINTER(sta
->fast_rx
, NULL
);
4030 spin_unlock_bh(&sta
->lock
);
4033 kfree_rcu(old
, rcu_head
);
4036 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data
*sdata
)
4038 struct ieee80211_local
*local
= sdata
->local
;
4039 struct sta_info
*sta
;
4041 lockdep_assert_held(&local
->sta_mtx
);
4043 list_for_each_entry(sta
, &local
->sta_list
, list
) {
4044 if (sdata
!= sta
->sdata
&&
4045 (!sta
->sdata
->bss
|| sta
->sdata
->bss
!= sdata
->bss
))
4047 ieee80211_check_fast_rx(sta
);
4051 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data
*sdata
)
4053 struct ieee80211_local
*local
= sdata
->local
;
4055 mutex_lock(&local
->sta_mtx
);
4056 __ieee80211_check_fast_rx_iface(sdata
);
4057 mutex_unlock(&local
->sta_mtx
);
4060 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data
*rx
,
4061 struct ieee80211_fast_rx
*fast_rx
)
4063 struct sk_buff
*skb
= rx
->skb
;
4064 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
4065 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
4066 struct sta_info
*sta
= rx
->sta
;
4067 int orig_len
= skb
->len
;
4068 int hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
4069 int snap_offs
= hdrlen
;
4071 u8 snap
[sizeof(rfc1042_header
)];
4073 } *payload
__aligned(2);
4077 } addrs
__aligned(2);
4078 struct ieee80211_sta_rx_stats
*stats
= &sta
->rx_stats
;
4080 if (fast_rx
->uses_rss
)
4081 stats
= this_cpu_ptr(sta
->pcpu_rx_stats
);
4083 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4084 * to a common data structure; drivers can implement that per queue
4085 * but we don't have that information in mac80211
4087 if (!(status
->flag
& RX_FLAG_DUP_VALIDATED
))
4090 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4092 /* If using encryption, we also need to have:
4093 * - PN_VALIDATED: similar, but the implementation is tricky
4094 * - DECRYPTED: necessary for PN_VALIDATED
4097 (status
->flag
& FAST_RX_CRYPT_FLAGS
) != FAST_RX_CRYPT_FLAGS
)
4100 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
4103 if (unlikely(ieee80211_is_frag(hdr
)))
4106 /* Since our interface address cannot be multicast, this
4107 * implicitly also rejects multicast frames without the
4110 * We shouldn't get any *data* frames not addressed to us
4111 * (AP mode will accept multicast *management* frames), but
4112 * punting here will make it go through the full checks in
4113 * ieee80211_accept_frame().
4115 if (!ether_addr_equal(fast_rx
->vif_addr
, hdr
->addr1
))
4118 if ((hdr
->frame_control
& cpu_to_le16(IEEE80211_FCTL_FROMDS
|
4119 IEEE80211_FCTL_TODS
)) !=
4120 fast_rx
->expected_ds_bits
)
4123 /* assign the key to drop unencrypted frames (later)
4124 * and strip the IV/MIC if necessary
4126 if (fast_rx
->key
&& !(status
->flag
& RX_FLAG_IV_STRIPPED
)) {
4127 /* GCMP header length is the same */
4128 snap_offs
+= IEEE80211_CCMP_HDR_LEN
;
4131 if (!(status
->rx_flags
& IEEE80211_RX_AMSDU
)) {
4132 if (!pskb_may_pull(skb
, snap_offs
+ sizeof(*payload
)))
4135 payload
= (void *)(skb
->data
+ snap_offs
);
4137 if (!ether_addr_equal(payload
->snap
, fast_rx
->rfc1042_hdr
))
4140 /* Don't handle these here since they require special code.
4141 * Accept AARP and IPX even though they should come with a
4142 * bridge-tunnel header - but if we get them this way then
4143 * there's little point in discarding them.
4145 if (unlikely(payload
->proto
== cpu_to_be16(ETH_P_TDLS
) ||
4146 payload
->proto
== fast_rx
->control_port_protocol
))
4150 /* after this point, don't punt to the slowpath! */
4152 if (rx
->key
&& !(status
->flag
& RX_FLAG_MIC_STRIPPED
) &&
4153 pskb_trim(skb
, skb
->len
- fast_rx
->icv_len
))
4156 if (unlikely(fast_rx
->sta_notify
)) {
4157 ieee80211_sta_rx_notify(rx
->sdata
, hdr
);
4158 fast_rx
->sta_notify
= false;
4161 /* statistics part of ieee80211_rx_h_sta_process() */
4162 if (!(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
)) {
4163 stats
->last_signal
= status
->signal
;
4164 if (!fast_rx
->uses_rss
)
4165 ewma_signal_add(&sta
->rx_stats_avg
.signal
,
4169 if (status
->chains
) {
4172 stats
->chains
= status
->chains
;
4173 for (i
= 0; i
< ARRAY_SIZE(status
->chain_signal
); i
++) {
4174 int signal
= status
->chain_signal
[i
];
4176 if (!(status
->chains
& BIT(i
)))
4179 stats
->chain_signal_last
[i
] = signal
;
4180 if (!fast_rx
->uses_rss
)
4181 ewma_signal_add(&sta
->rx_stats_avg
.chain_signal
[i
],
4185 /* end of statistics */
4187 if (rx
->key
&& !ieee80211_has_protected(hdr
->frame_control
))
4190 if (status
->rx_flags
& IEEE80211_RX_AMSDU
) {
4191 if (__ieee80211_rx_h_amsdu(rx
, snap_offs
- hdrlen
) !=
4198 stats
->last_rx
= jiffies
;
4199 stats
->last_rate
= sta_stats_encode_rate(status
);
4204 /* do the header conversion - first grab the addresses */
4205 ether_addr_copy(addrs
.da
, skb
->data
+ fast_rx
->da_offs
);
4206 ether_addr_copy(addrs
.sa
, skb
->data
+ fast_rx
->sa_offs
);
4207 /* remove the SNAP but leave the ethertype */
4208 skb_pull(skb
, snap_offs
+ sizeof(rfc1042_header
));
4209 /* push the addresses in front */
4210 memcpy(skb_push(skb
, sizeof(addrs
)), &addrs
, sizeof(addrs
));
4212 skb
->dev
= fast_rx
->dev
;
4214 ieee80211_rx_stats(fast_rx
->dev
, skb
->len
);
4216 /* The seqno index has the same property as needed
4217 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4218 * for non-QoS-data frames. Here we know it's a data
4219 * frame, so count MSDUs.
4221 u64_stats_update_begin(&stats
->syncp
);
4222 stats
->msdu
[rx
->seqno_idx
]++;
4223 stats
->bytes
+= orig_len
;
4224 u64_stats_update_end(&stats
->syncp
);
4226 if (fast_rx
->internal_forward
) {
4227 struct sk_buff
*xmit_skb
= NULL
;
4228 bool multicast
= is_multicast_ether_addr(skb
->data
);
4231 xmit_skb
= skb_copy(skb
, GFP_ATOMIC
);
4232 } else if (sta_info_get(rx
->sdata
, skb
->data
)) {
4239 * Send to wireless media and increase priority by 256
4240 * to keep the received priority instead of
4241 * reclassifying the frame (see cfg80211_classify8021d).
4243 xmit_skb
->priority
+= 256;
4244 xmit_skb
->protocol
= htons(ETH_P_802_3
);
4245 skb_reset_network_header(xmit_skb
);
4246 skb_reset_mac_header(xmit_skb
);
4247 dev_queue_xmit(xmit_skb
);
4254 /* deliver to local stack */
4255 skb
->protocol
= eth_type_trans(skb
, fast_rx
->dev
);
4256 memset(skb
->cb
, 0, sizeof(skb
->cb
));
4258 napi_gro_receive(rx
->napi
, skb
);
4260 netif_receive_skb(skb
);
4270 * This function returns whether or not the SKB
4271 * was destined for RX processing or not, which,
4272 * if consume is true, is equivalent to whether
4273 * or not the skb was consumed.
4275 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data
*rx
,
4276 struct sk_buff
*skb
, bool consume
)
4278 struct ieee80211_local
*local
= rx
->local
;
4279 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
4283 /* See if we can do fast-rx; if we have to copy we already lost,
4284 * so punt in that case. We should never have to deliver a data
4285 * frame to multiple interfaces anyway.
4287 * We skip the ieee80211_accept_frame() call and do the necessary
4288 * checking inside ieee80211_invoke_fast_rx().
4290 if (consume
&& rx
->sta
) {
4291 struct ieee80211_fast_rx
*fast_rx
;
4293 fast_rx
= rcu_dereference(rx
->sta
->fast_rx
);
4294 if (fast_rx
&& ieee80211_invoke_fast_rx(rx
, fast_rx
))
4298 if (!ieee80211_accept_frame(rx
))
4302 skb
= skb_copy(skb
, GFP_ATOMIC
);
4304 if (net_ratelimit())
4305 wiphy_debug(local
->hw
.wiphy
,
4306 "failed to copy skb for %s\n",
4314 ieee80211_invoke_rx_handlers(rx
);
4319 * This is the actual Rx frames handler. as it belongs to Rx path it must
4320 * be called with rcu_read_lock protection.
4322 static void __ieee80211_rx_handle_packet(struct ieee80211_hw
*hw
,
4323 struct ieee80211_sta
*pubsta
,
4324 struct sk_buff
*skb
,
4325 struct napi_struct
*napi
)
4327 struct ieee80211_local
*local
= hw_to_local(hw
);
4328 struct ieee80211_sub_if_data
*sdata
;
4329 struct ieee80211_hdr
*hdr
;
4331 struct ieee80211_rx_data rx
;
4332 struct ieee80211_sub_if_data
*prev
;
4333 struct rhlist_head
*tmp
;
4336 fc
= ((struct ieee80211_hdr
*)skb
->data
)->frame_control
;
4337 memset(&rx
, 0, sizeof(rx
));
4342 if (ieee80211_is_data(fc
) || ieee80211_is_mgmt(fc
))
4343 I802_DEBUG_INC(local
->dot11ReceivedFragmentCount
);
4345 if (ieee80211_is_mgmt(fc
)) {
4346 /* drop frame if too short for header */
4347 if (skb
->len
< ieee80211_hdrlen(fc
))
4350 err
= skb_linearize(skb
);
4352 err
= !pskb_may_pull(skb
, ieee80211_hdrlen(fc
));
4360 hdr
= (struct ieee80211_hdr
*)skb
->data
;
4361 ieee80211_parse_qos(&rx
);
4362 ieee80211_verify_alignment(&rx
);
4364 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
) ||
4365 ieee80211_is_beacon(hdr
->frame_control
)))
4366 ieee80211_scan_rx(local
, skb
);
4368 if (ieee80211_is_data(fc
)) {
4369 struct sta_info
*sta
, *prev_sta
;
4372 rx
.sta
= container_of(pubsta
, struct sta_info
, sta
);
4373 rx
.sdata
= rx
.sta
->sdata
;
4374 if (ieee80211_prepare_and_rx_handle(&rx
, skb
, true))
4381 for_each_sta_info(local
, hdr
->addr2
, sta
, tmp
) {
4388 rx
.sdata
= prev_sta
->sdata
;
4389 ieee80211_prepare_and_rx_handle(&rx
, skb
, false);
4396 rx
.sdata
= prev_sta
->sdata
;
4398 if (ieee80211_prepare_and_rx_handle(&rx
, skb
, true))
4406 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4407 if (!ieee80211_sdata_running(sdata
))
4410 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
||
4411 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
4415 * frame is destined for this interface, but if it's
4416 * not also for the previous one we handle that after
4417 * the loop to avoid copying the SKB once too much
4425 rx
.sta
= sta_info_get_bss(prev
, hdr
->addr2
);
4427 ieee80211_prepare_and_rx_handle(&rx
, skb
, false);
4433 rx
.sta
= sta_info_get_bss(prev
, hdr
->addr2
);
4436 if (ieee80211_prepare_and_rx_handle(&rx
, skb
, true))
4445 * This is the receive path handler. It is called by a low level driver when an
4446 * 802.11 MPDU is received from the hardware.
4448 void ieee80211_rx_napi(struct ieee80211_hw
*hw
, struct ieee80211_sta
*pubsta
,
4449 struct sk_buff
*skb
, struct napi_struct
*napi
)
4451 struct ieee80211_local
*local
= hw_to_local(hw
);
4452 struct ieee80211_rate
*rate
= NULL
;
4453 struct ieee80211_supported_band
*sband
;
4454 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
4456 WARN_ON_ONCE(softirq_count() == 0);
4458 if (WARN_ON(status
->band
>= NUM_NL80211_BANDS
))
4461 sband
= local
->hw
.wiphy
->bands
[status
->band
];
4462 if (WARN_ON(!sband
))
4466 * If we're suspending, it is possible although not too likely
4467 * that we'd be receiving frames after having already partially
4468 * quiesced the stack. We can't process such frames then since
4469 * that might, for example, cause stations to be added or other
4470 * driver callbacks be invoked.
4472 if (unlikely(local
->quiescing
|| local
->suspended
))
4475 /* We might be during a HW reconfig, prevent Rx for the same reason */
4476 if (unlikely(local
->in_reconfig
))
4480 * The same happens when we're not even started,
4481 * but that's worth a warning.
4483 if (WARN_ON(!local
->started
))
4486 if (likely(!(status
->flag
& RX_FLAG_FAILED_PLCP_CRC
))) {
4488 * Validate the rate, unless a PLCP error means that
4489 * we probably can't have a valid rate here anyway.
4492 switch (status
->encoding
) {
4495 * rate_idx is MCS index, which can be [0-76]
4498 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4500 * Anything else would be some sort of driver or
4501 * hardware error. The driver should catch hardware
4504 if (WARN(status
->rate_idx
> 76,
4505 "Rate marked as an HT rate but passed "
4506 "status->rate_idx is not "
4507 "an MCS index [0-76]: %d (0x%02x)\n",
4513 if (WARN_ONCE(status
->rate_idx
> 9 ||
4516 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4517 status
->rate_idx
, status
->nss
))
4521 if (WARN_ONCE(status
->rate_idx
> 11 ||
4524 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4525 status
->rate_idx
, status
->nss
))
4532 if (WARN_ON(status
->rate_idx
>= sband
->n_bitrates
))
4534 rate
= &sband
->bitrates
[status
->rate_idx
];
4538 status
->rx_flags
= 0;
4541 * key references and virtual interfaces are protected using RCU
4542 * and this requires that we are in a read-side RCU section during
4543 * receive processing
4548 * Frames with failed FCS/PLCP checksum are not returned,
4549 * all other frames are returned without radiotap header
4550 * if it was previously present.
4551 * Also, frames with less than 16 bytes are dropped.
4553 skb
= ieee80211_rx_monitor(local
, skb
, rate
);
4559 ieee80211_tpt_led_trig_rx(local
,
4560 ((struct ieee80211_hdr
*)skb
->data
)->frame_control
,
4563 __ieee80211_rx_handle_packet(hw
, pubsta
, skb
, napi
);
4571 EXPORT_SYMBOL(ieee80211_rx_napi
);
4573 /* This is a version of the rx handler that can be called from hard irq
4574 * context. Post the skb on the queue and schedule the tasklet */
4575 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
4577 struct ieee80211_local
*local
= hw_to_local(hw
);
4579 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
));
4581 skb
->pkt_type
= IEEE80211_RX_MSG
;
4582 skb_queue_tail(&local
->skb_queue
, skb
);
4583 tasklet_schedule(&local
->tasklet
);
4585 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);