1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
5 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
6 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
9 * Copyright (C) 2018-2020 Intel Corporation
12 #include <linux/jiffies.h>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/rcupdate.h>
19 #include <linux/export.h>
20 #include <linux/kcov.h>
21 #include <linux/bitops.h>
22 #include <net/mac80211.h>
23 #include <net/ieee80211_radiotap.h>
24 #include <asm/unaligned.h>
26 #include "ieee80211_i.h"
27 #include "driver-ops.h"
37 * monitor mode reception
39 * This function cleans up the SKB, i.e. it removes all the stuff
40 * only useful for monitoring.
42 static struct sk_buff
*ieee80211_clean_skb(struct sk_buff
*skb
,
43 unsigned int present_fcs_len
,
44 unsigned int rtap_space
)
46 struct ieee80211_hdr
*hdr
;
51 __pskb_trim(skb
, skb
->len
- present_fcs_len
);
52 __pskb_pull(skb
, rtap_space
);
54 hdr
= (void *)skb
->data
;
55 fc
= hdr
->frame_control
;
58 * Remove the HT-Control field (if present) on management
59 * frames after we've sent the frame to monitoring. We
60 * (currently) don't need it, and don't properly parse
61 * frames with it present, due to the assumption of a
62 * fixed management header length.
64 if (likely(!ieee80211_is_mgmt(fc
) || !ieee80211_has_order(fc
)))
67 hdrlen
= ieee80211_hdrlen(fc
);
68 hdr
->frame_control
&= ~cpu_to_le16(IEEE80211_FCTL_ORDER
);
70 if (!pskb_may_pull(skb
, hdrlen
)) {
75 memmove(skb
->data
+ IEEE80211_HT_CTL_LEN
, skb
->data
,
76 hdrlen
- IEEE80211_HT_CTL_LEN
);
77 __pskb_pull(skb
, IEEE80211_HT_CTL_LEN
);
82 static inline bool should_drop_frame(struct sk_buff
*skb
, int present_fcs_len
,
83 unsigned int rtap_space
)
85 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
86 struct ieee80211_hdr
*hdr
;
88 hdr
= (void *)(skb
->data
+ rtap_space
);
90 if (status
->flag
& (RX_FLAG_FAILED_FCS_CRC
|
91 RX_FLAG_FAILED_PLCP_CRC
|
92 RX_FLAG_ONLY_MONITOR
|
96 if (unlikely(skb
->len
< 16 + present_fcs_len
+ rtap_space
))
99 if (ieee80211_is_ctl(hdr
->frame_control
) &&
100 !ieee80211_is_pspoll(hdr
->frame_control
) &&
101 !ieee80211_is_back_req(hdr
->frame_control
))
108 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local
*local
,
109 struct ieee80211_rx_status
*status
,
114 /* always present fields */
115 len
= sizeof(struct ieee80211_radiotap_header
) + 8;
117 /* allocate extra bitmaps */
119 len
+= 4 * hweight8(status
->chains
);
120 /* vendor presence bitmap */
121 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
)
124 if (ieee80211_have_rx_timestamp(status
)) {
128 if (ieee80211_hw_check(&local
->hw
, SIGNAL_DBM
))
131 /* antenna field, if we don't have per-chain info */
135 /* padding for RX_FLAGS if necessary */
138 if (status
->encoding
== RX_ENC_HT
) /* HT info */
141 if (status
->flag
& RX_FLAG_AMPDU_DETAILS
) {
146 if (status
->encoding
== RX_ENC_VHT
) {
151 if (local
->hw
.radiotap_timestamp
.units_pos
>= 0) {
156 if (status
->encoding
== RX_ENC_HE
&&
157 status
->flag
& RX_FLAG_RADIOTAP_HE
) {
160 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he
) != 12);
163 if (status
->encoding
== RX_ENC_HE
&&
164 status
->flag
& RX_FLAG_RADIOTAP_HE_MU
) {
167 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu
) != 12);
170 if (status
->flag
& RX_FLAG_NO_PSDU
)
173 if (status
->flag
& RX_FLAG_RADIOTAP_LSIG
) {
176 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig
) != 4);
179 if (status
->chains
) {
180 /* antenna and antenna signal fields */
181 len
+= 2 * hweight8(status
->chains
);
184 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
185 struct ieee80211_vendor_radiotap
*rtap
;
186 int vendor_data_offset
= 0;
189 * The position to look at depends on the existence (or non-
190 * existence) of other elements, so take that into account...
192 if (status
->flag
& RX_FLAG_RADIOTAP_HE
)
193 vendor_data_offset
+=
194 sizeof(struct ieee80211_radiotap_he
);
195 if (status
->flag
& RX_FLAG_RADIOTAP_HE_MU
)
196 vendor_data_offset
+=
197 sizeof(struct ieee80211_radiotap_he_mu
);
198 if (status
->flag
& RX_FLAG_RADIOTAP_LSIG
)
199 vendor_data_offset
+=
200 sizeof(struct ieee80211_radiotap_lsig
);
202 rtap
= (void *)&skb
->data
[vendor_data_offset
];
204 /* alignment for fixed 6-byte vendor data header */
206 /* vendor data header */
208 if (WARN_ON(rtap
->align
== 0))
210 len
= ALIGN(len
, rtap
->align
);
211 len
+= rtap
->len
+ rtap
->pad
;
217 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data
*sdata
,
222 struct ieee80211_hdr_3addr hdr
;
225 } __packed
__aligned(2) action
;
230 BUILD_BUG_ON(sizeof(action
) != IEEE80211_MIN_ACTION_SIZE
+ 1);
232 if (skb
->len
< rtap_space
+ sizeof(action
) +
233 VHT_MUMIMO_GROUPS_DATA_LEN
)
236 if (!is_valid_ether_addr(sdata
->u
.mntr
.mu_follow_addr
))
239 skb_copy_bits(skb
, rtap_space
, &action
, sizeof(action
));
241 if (!ieee80211_is_action(action
.hdr
.frame_control
))
244 if (action
.category
!= WLAN_CATEGORY_VHT
)
247 if (action
.action_code
!= WLAN_VHT_ACTION_GROUPID_MGMT
)
250 if (!ether_addr_equal(action
.hdr
.addr1
, sdata
->u
.mntr
.mu_follow_addr
))
253 skb
= skb_copy(skb
, GFP_ATOMIC
);
257 skb_queue_tail(&sdata
->skb_queue
, skb
);
258 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
262 * ieee80211_add_rx_radiotap_header - add radiotap header
264 * add a radiotap header containing all the fields which the hardware provided.
267 ieee80211_add_rx_radiotap_header(struct ieee80211_local
*local
,
269 struct ieee80211_rate
*rate
,
270 int rtap_len
, bool has_fcs
)
272 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
273 struct ieee80211_radiotap_header
*rthdr
;
278 u16 channel_flags
= 0;
280 unsigned long chains
= status
->chains
;
281 struct ieee80211_vendor_radiotap rtap
= {};
282 struct ieee80211_radiotap_he he
= {};
283 struct ieee80211_radiotap_he_mu he_mu
= {};
284 struct ieee80211_radiotap_lsig lsig
= {};
286 if (status
->flag
& RX_FLAG_RADIOTAP_HE
) {
287 he
= *(struct ieee80211_radiotap_he
*)skb
->data
;
288 skb_pull(skb
, sizeof(he
));
289 WARN_ON_ONCE(status
->encoding
!= RX_ENC_HE
);
292 if (status
->flag
& RX_FLAG_RADIOTAP_HE_MU
) {
293 he_mu
= *(struct ieee80211_radiotap_he_mu
*)skb
->data
;
294 skb_pull(skb
, sizeof(he_mu
));
297 if (status
->flag
& RX_FLAG_RADIOTAP_LSIG
) {
298 lsig
= *(struct ieee80211_radiotap_lsig
*)skb
->data
;
299 skb_pull(skb
, sizeof(lsig
));
302 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
303 rtap
= *(struct ieee80211_vendor_radiotap
*)skb
->data
;
304 /* rtap.len and rtap.pad are undone immediately */
305 skb_pull(skb
, sizeof(rtap
) + rtap
.len
+ rtap
.pad
);
309 if (!(has_fcs
&& ieee80211_hw_check(&local
->hw
, RX_INCLUDES_FCS
)))
312 rthdr
= skb_push(skb
, rtap_len
);
313 memset(rthdr
, 0, rtap_len
- rtap
.len
- rtap
.pad
);
314 it_present
= &rthdr
->it_present
;
316 /* radiotap header, set always present flags */
317 rthdr
->it_len
= cpu_to_le16(rtap_len
);
318 it_present_val
= BIT(IEEE80211_RADIOTAP_FLAGS
) |
319 BIT(IEEE80211_RADIOTAP_CHANNEL
) |
320 BIT(IEEE80211_RADIOTAP_RX_FLAGS
);
323 it_present_val
|= BIT(IEEE80211_RADIOTAP_ANTENNA
);
325 for_each_set_bit(chain
, &chains
, IEEE80211_MAX_CHAINS
) {
327 BIT(IEEE80211_RADIOTAP_EXT
) |
328 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE
);
329 put_unaligned_le32(it_present_val
, it_present
);
331 it_present_val
= BIT(IEEE80211_RADIOTAP_ANTENNA
) |
332 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL
);
335 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
336 it_present_val
|= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE
) |
337 BIT(IEEE80211_RADIOTAP_EXT
);
338 put_unaligned_le32(it_present_val
, it_present
);
340 it_present_val
= rtap
.present
;
343 put_unaligned_le32(it_present_val
, it_present
);
345 pos
= (void *)(it_present
+ 1);
347 /* the order of the following fields is important */
349 /* IEEE80211_RADIOTAP_TSFT */
350 if (ieee80211_have_rx_timestamp(status
)) {
352 while ((pos
- (u8
*)rthdr
) & 7)
355 ieee80211_calculate_rx_timestamp(local
, status
,
358 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT
);
362 /* IEEE80211_RADIOTAP_FLAGS */
363 if (has_fcs
&& ieee80211_hw_check(&local
->hw
, RX_INCLUDES_FCS
))
364 *pos
|= IEEE80211_RADIOTAP_F_FCS
;
365 if (status
->flag
& (RX_FLAG_FAILED_FCS_CRC
| RX_FLAG_FAILED_PLCP_CRC
))
366 *pos
|= IEEE80211_RADIOTAP_F_BADFCS
;
367 if (status
->enc_flags
& RX_ENC_FLAG_SHORTPRE
)
368 *pos
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
371 /* IEEE80211_RADIOTAP_RATE */
372 if (!rate
|| status
->encoding
!= RX_ENC_LEGACY
) {
374 * Without rate information don't add it. If we have,
375 * MCS information is a separate field in radiotap,
376 * added below. The byte here is needed as padding
377 * for the channel though, so initialise it to 0.
382 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE
);
383 if (status
->bw
== RATE_INFO_BW_10
)
385 else if (status
->bw
== RATE_INFO_BW_5
)
387 *pos
= DIV_ROUND_UP(rate
->bitrate
, 5 * (1 << shift
));
391 /* IEEE80211_RADIOTAP_CHANNEL */
392 /* TODO: frequency offset in KHz */
393 put_unaligned_le16(status
->freq
, pos
);
395 if (status
->bw
== RATE_INFO_BW_10
)
396 channel_flags
|= IEEE80211_CHAN_HALF
;
397 else if (status
->bw
== RATE_INFO_BW_5
)
398 channel_flags
|= IEEE80211_CHAN_QUARTER
;
400 if (status
->band
== NL80211_BAND_5GHZ
||
401 status
->band
== NL80211_BAND_6GHZ
)
402 channel_flags
|= IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_5GHZ
;
403 else if (status
->encoding
!= RX_ENC_LEGACY
)
404 channel_flags
|= IEEE80211_CHAN_DYN
| IEEE80211_CHAN_2GHZ
;
405 else if (rate
&& rate
->flags
& IEEE80211_RATE_ERP_G
)
406 channel_flags
|= IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_2GHZ
;
408 channel_flags
|= IEEE80211_CHAN_CCK
| IEEE80211_CHAN_2GHZ
;
410 channel_flags
|= IEEE80211_CHAN_2GHZ
;
411 put_unaligned_le16(channel_flags
, pos
);
414 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
415 if (ieee80211_hw_check(&local
->hw
, SIGNAL_DBM
) &&
416 !(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
)) {
417 *pos
= status
->signal
;
419 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
);
423 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
425 if (!status
->chains
) {
426 /* IEEE80211_RADIOTAP_ANTENNA */
427 *pos
= status
->antenna
;
431 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
433 /* IEEE80211_RADIOTAP_RX_FLAGS */
434 /* ensure 2 byte alignment for the 2 byte field as required */
435 if ((pos
- (u8
*)rthdr
) & 1)
437 if (status
->flag
& RX_FLAG_FAILED_PLCP_CRC
)
438 rx_flags
|= IEEE80211_RADIOTAP_F_RX_BADPLCP
;
439 put_unaligned_le16(rx_flags
, pos
);
442 if (status
->encoding
== RX_ENC_HT
) {
445 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS
);
446 *pos
++ = local
->hw
.radiotap_mcs_details
;
448 if (status
->enc_flags
& RX_ENC_FLAG_SHORT_GI
)
449 *pos
|= IEEE80211_RADIOTAP_MCS_SGI
;
450 if (status
->bw
== RATE_INFO_BW_40
)
451 *pos
|= IEEE80211_RADIOTAP_MCS_BW_40
;
452 if (status
->enc_flags
& RX_ENC_FLAG_HT_GF
)
453 *pos
|= IEEE80211_RADIOTAP_MCS_FMT_GF
;
454 if (status
->enc_flags
& RX_ENC_FLAG_LDPC
)
455 *pos
|= IEEE80211_RADIOTAP_MCS_FEC_LDPC
;
456 stbc
= (status
->enc_flags
& RX_ENC_FLAG_STBC_MASK
) >> RX_ENC_FLAG_STBC_SHIFT
;
457 *pos
|= stbc
<< IEEE80211_RADIOTAP_MCS_STBC_SHIFT
;
459 *pos
++ = status
->rate_idx
;
462 if (status
->flag
& RX_FLAG_AMPDU_DETAILS
) {
465 /* ensure 4 byte alignment */
466 while ((pos
- (u8
*)rthdr
) & 3)
469 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS
);
470 put_unaligned_le32(status
->ampdu_reference
, pos
);
472 if (status
->flag
& RX_FLAG_AMPDU_LAST_KNOWN
)
473 flags
|= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN
;
474 if (status
->flag
& RX_FLAG_AMPDU_IS_LAST
)
475 flags
|= IEEE80211_RADIOTAP_AMPDU_IS_LAST
;
476 if (status
->flag
& RX_FLAG_AMPDU_DELIM_CRC_ERROR
)
477 flags
|= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR
;
478 if (status
->flag
& RX_FLAG_AMPDU_DELIM_CRC_KNOWN
)
479 flags
|= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN
;
480 if (status
->flag
& RX_FLAG_AMPDU_EOF_BIT_KNOWN
)
481 flags
|= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN
;
482 if (status
->flag
& RX_FLAG_AMPDU_EOF_BIT
)
483 flags
|= IEEE80211_RADIOTAP_AMPDU_EOF
;
484 put_unaligned_le16(flags
, pos
);
486 if (status
->flag
& RX_FLAG_AMPDU_DELIM_CRC_KNOWN
)
487 *pos
++ = status
->ampdu_delimiter_crc
;
493 if (status
->encoding
== RX_ENC_VHT
) {
494 u16 known
= local
->hw
.radiotap_vht_details
;
496 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT
);
497 put_unaligned_le16(known
, pos
);
500 if (status
->enc_flags
& RX_ENC_FLAG_SHORT_GI
)
501 *pos
|= IEEE80211_RADIOTAP_VHT_FLAG_SGI
;
502 /* in VHT, STBC is binary */
503 if (status
->enc_flags
& RX_ENC_FLAG_STBC_MASK
)
504 *pos
|= IEEE80211_RADIOTAP_VHT_FLAG_STBC
;
505 if (status
->enc_flags
& RX_ENC_FLAG_BF
)
506 *pos
|= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED
;
509 switch (status
->bw
) {
510 case RATE_INFO_BW_80
:
513 case RATE_INFO_BW_160
:
516 case RATE_INFO_BW_40
:
523 *pos
= (status
->rate_idx
<< 4) | status
->nss
;
526 if (status
->enc_flags
& RX_ENC_FLAG_LDPC
)
527 *pos
|= IEEE80211_RADIOTAP_CODING_LDPC_USER0
;
535 if (local
->hw
.radiotap_timestamp
.units_pos
>= 0) {
537 u8 flags
= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT
;
540 cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP
);
542 /* ensure 8 byte alignment */
543 while ((pos
- (u8
*)rthdr
) & 7)
546 put_unaligned_le64(status
->device_timestamp
, pos
);
549 if (local
->hw
.radiotap_timestamp
.accuracy
>= 0) {
550 accuracy
= local
->hw
.radiotap_timestamp
.accuracy
;
551 flags
|= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY
;
553 put_unaligned_le16(accuracy
, pos
);
556 *pos
++ = local
->hw
.radiotap_timestamp
.units_pos
;
560 if (status
->encoding
== RX_ENC_HE
&&
561 status
->flag
& RX_FLAG_RADIOTAP_HE
) {
562 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
564 if (status
->enc_flags
& RX_ENC_FLAG_STBC_MASK
) {
565 he
.data6
|= HE_PREP(DATA6_NSTS
,
566 FIELD_GET(RX_ENC_FLAG_STBC_MASK
,
568 he
.data3
|= HE_PREP(DATA3_STBC
, 1);
570 he
.data6
|= HE_PREP(DATA6_NSTS
, status
->nss
);
573 #define CHECK_GI(s) \
574 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
575 (int)NL80211_RATE_INFO_HE_GI_##s)
581 he
.data3
|= HE_PREP(DATA3_DATA_MCS
, status
->rate_idx
);
582 he
.data3
|= HE_PREP(DATA3_DATA_DCM
, status
->he_dcm
);
583 he
.data3
|= HE_PREP(DATA3_CODING
,
584 !!(status
->enc_flags
& RX_ENC_FLAG_LDPC
));
586 he
.data5
|= HE_PREP(DATA5_GI
, status
->he_gi
);
588 switch (status
->bw
) {
589 case RATE_INFO_BW_20
:
590 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
591 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ
);
593 case RATE_INFO_BW_40
:
594 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
595 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ
);
597 case RATE_INFO_BW_80
:
598 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
599 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ
);
601 case RATE_INFO_BW_160
:
602 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
603 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ
);
605 case RATE_INFO_BW_HE_RU
:
606 #define CHECK_RU_ALLOC(s) \
607 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
608 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
616 CHECK_RU_ALLOC(2x996
);
618 he
.data5
|= HE_PREP(DATA5_DATA_BW_RU_ALLOC
,
622 WARN_ONCE(1, "Invalid SU BW %d\n", status
->bw
);
625 /* ensure 2 byte alignment */
626 while ((pos
- (u8
*)rthdr
) & 1)
628 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE
);
629 memcpy(pos
, &he
, sizeof(he
));
633 if (status
->encoding
== RX_ENC_HE
&&
634 status
->flag
& RX_FLAG_RADIOTAP_HE_MU
) {
635 /* ensure 2 byte alignment */
636 while ((pos
- (u8
*)rthdr
) & 1)
638 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU
);
639 memcpy(pos
, &he_mu
, sizeof(he_mu
));
640 pos
+= sizeof(he_mu
);
643 if (status
->flag
& RX_FLAG_NO_PSDU
) {
645 cpu_to_le32(1 << IEEE80211_RADIOTAP_ZERO_LEN_PSDU
);
646 *pos
++ = status
->zero_length_psdu_type
;
649 if (status
->flag
& RX_FLAG_RADIOTAP_LSIG
) {
650 /* ensure 2 byte alignment */
651 while ((pos
- (u8
*)rthdr
) & 1)
653 rthdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_LSIG
);
654 memcpy(pos
, &lsig
, sizeof(lsig
));
658 for_each_set_bit(chain
, &chains
, IEEE80211_MAX_CHAINS
) {
659 *pos
++ = status
->chain_signal
[chain
];
663 if (status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
) {
664 /* ensure 2 byte alignment for the vendor field as required */
665 if ((pos
- (u8
*)rthdr
) & 1)
667 *pos
++ = rtap
.oui
[0];
668 *pos
++ = rtap
.oui
[1];
669 *pos
++ = rtap
.oui
[2];
671 put_unaligned_le16(rtap
.len
, pos
);
673 /* align the actual payload as requested */
674 while ((pos
- (u8
*)rthdr
) & (rtap
.align
- 1))
676 /* data (and possible padding) already follows */
680 static struct sk_buff
*
681 ieee80211_make_monitor_skb(struct ieee80211_local
*local
,
682 struct sk_buff
**origskb
,
683 struct ieee80211_rate
*rate
,
684 int rtap_space
, bool use_origskb
)
686 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(*origskb
);
687 int rt_hdrlen
, needed_headroom
;
690 /* room for the radiotap header based on driver features */
691 rt_hdrlen
= ieee80211_rx_radiotap_hdrlen(local
, status
, *origskb
);
692 needed_headroom
= rt_hdrlen
- rtap_space
;
695 /* only need to expand headroom if necessary */
700 * This shouldn't trigger often because most devices have an
701 * RX header they pull before we get here, and that should
702 * be big enough for our radiotap information. We should
703 * probably export the length to drivers so that we can have
704 * them allocate enough headroom to start with.
706 if (skb_headroom(skb
) < needed_headroom
&&
707 pskb_expand_head(skb
, needed_headroom
, 0, GFP_ATOMIC
)) {
713 * Need to make a copy and possibly remove radiotap header
714 * and FCS from the original.
716 skb
= skb_copy_expand(*origskb
, needed_headroom
, 0, GFP_ATOMIC
);
722 /* prepend radiotap information */
723 ieee80211_add_rx_radiotap_header(local
, skb
, rate
, rt_hdrlen
, true);
725 skb_reset_mac_header(skb
);
726 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
727 skb
->pkt_type
= PACKET_OTHERHOST
;
728 skb
->protocol
= htons(ETH_P_802_2
);
734 * This function copies a received frame to all monitor interfaces and
735 * returns a cleaned-up SKB that no longer includes the FCS nor the
736 * radiotap header the driver might have added.
738 static struct sk_buff
*
739 ieee80211_rx_monitor(struct ieee80211_local
*local
, struct sk_buff
*origskb
,
740 struct ieee80211_rate
*rate
)
742 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(origskb
);
743 struct ieee80211_sub_if_data
*sdata
;
744 struct sk_buff
*monskb
= NULL
;
745 int present_fcs_len
= 0;
746 unsigned int rtap_space
= 0;
747 struct ieee80211_sub_if_data
*monitor_sdata
=
748 rcu_dereference(local
->monitor_sdata
);
749 bool only_monitor
= false;
750 unsigned int min_head_len
;
752 if (status
->flag
& RX_FLAG_RADIOTAP_HE
)
753 rtap_space
+= sizeof(struct ieee80211_radiotap_he
);
755 if (status
->flag
& RX_FLAG_RADIOTAP_HE_MU
)
756 rtap_space
+= sizeof(struct ieee80211_radiotap_he_mu
);
758 if (status
->flag
& RX_FLAG_RADIOTAP_LSIG
)
759 rtap_space
+= sizeof(struct ieee80211_radiotap_lsig
);
761 if (unlikely(status
->flag
& RX_FLAG_RADIOTAP_VENDOR_DATA
)) {
762 struct ieee80211_vendor_radiotap
*rtap
=
763 (void *)(origskb
->data
+ rtap_space
);
765 rtap_space
+= sizeof(*rtap
) + rtap
->len
+ rtap
->pad
;
768 min_head_len
= rtap_space
;
771 * First, we may need to make a copy of the skb because
772 * (1) we need to modify it for radiotap (if not present), and
773 * (2) the other RX handlers will modify the skb we got.
775 * We don't need to, of course, if we aren't going to return
776 * the SKB because it has a bad FCS/PLCP checksum.
779 if (!(status
->flag
& RX_FLAG_NO_PSDU
)) {
780 if (ieee80211_hw_check(&local
->hw
, RX_INCLUDES_FCS
)) {
781 if (unlikely(origskb
->len
<= FCS_LEN
+ rtap_space
)) {
784 dev_kfree_skb(origskb
);
787 present_fcs_len
= FCS_LEN
;
790 /* also consider the hdr->frame_control */
794 /* ensure that the expected data elements are in skb head */
795 if (!pskb_may_pull(origskb
, min_head_len
)) {
796 dev_kfree_skb(origskb
);
800 only_monitor
= should_drop_frame(origskb
, present_fcs_len
, rtap_space
);
802 if (!local
->monitors
|| (status
->flag
& RX_FLAG_SKIP_MONITOR
)) {
804 dev_kfree_skb(origskb
);
808 return ieee80211_clean_skb(origskb
, present_fcs_len
,
812 ieee80211_handle_mu_mimo_mon(monitor_sdata
, origskb
, rtap_space
);
814 list_for_each_entry_rcu(sdata
, &local
->mon_list
, u
.mntr
.list
) {
815 bool last_monitor
= list_is_last(&sdata
->u
.mntr
.list
,
819 monskb
= ieee80211_make_monitor_skb(local
, &origskb
,
831 skb
= skb_clone(monskb
, GFP_ATOMIC
);
835 skb
->dev
= sdata
->dev
;
836 dev_sw_netstats_rx_add(skb
->dev
, skb
->len
);
837 netif_receive_skb(skb
);
845 /* this happens if last_monitor was erroneously false */
846 dev_kfree_skb(monskb
);
852 return ieee80211_clean_skb(origskb
, present_fcs_len
, rtap_space
);
855 static void ieee80211_parse_qos(struct ieee80211_rx_data
*rx
)
857 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
858 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
859 int tid
, seqno_idx
, security_idx
;
861 /* does the frame have a qos control field? */
862 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
863 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
864 /* frame has qos control */
865 tid
= *qc
& IEEE80211_QOS_CTL_TID_MASK
;
866 if (*qc
& IEEE80211_QOS_CTL_A_MSDU_PRESENT
)
867 status
->rx_flags
|= IEEE80211_RX_AMSDU
;
873 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
875 * Sequence numbers for management frames, QoS data
876 * frames with a broadcast/multicast address in the
877 * Address 1 field, and all non-QoS data frames sent
878 * by QoS STAs are assigned using an additional single
879 * modulo-4096 counter, [...]
881 * We also use that counter for non-QoS STAs.
883 seqno_idx
= IEEE80211_NUM_TIDS
;
885 if (ieee80211_is_mgmt(hdr
->frame_control
))
886 security_idx
= IEEE80211_NUM_TIDS
;
890 rx
->seqno_idx
= seqno_idx
;
891 rx
->security_idx
= security_idx
;
892 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
893 * For now, set skb->priority to 0 for other cases. */
894 rx
->skb
->priority
= (tid
> 7) ? 0 : tid
;
898 * DOC: Packet alignment
900 * Drivers always need to pass packets that are aligned to two-byte boundaries
903 * Additionally, should, if possible, align the payload data in a way that
904 * guarantees that the contained IP header is aligned to a four-byte
905 * boundary. In the case of regular frames, this simply means aligning the
906 * payload to a four-byte boundary (because either the IP header is directly
907 * contained, or IV/RFC1042 headers that have a length divisible by four are
908 * in front of it). If the payload data is not properly aligned and the
909 * architecture doesn't support efficient unaligned operations, mac80211
910 * will align the data.
912 * With A-MSDU frames, however, the payload data address must yield two modulo
913 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
914 * push the IP header further back to a multiple of four again. Thankfully, the
915 * specs were sane enough this time around to require padding each A-MSDU
916 * subframe to a length that is a multiple of four.
918 * Padding like Atheros hardware adds which is between the 802.11 header and
919 * the payload is not supported, the driver is required to move the 802.11
920 * header to be directly in front of the payload in that case.
922 static void ieee80211_verify_alignment(struct ieee80211_rx_data
*rx
)
924 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
925 WARN_ON_ONCE((unsigned long)rx
->skb
->data
& 1);
932 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff
*skb
)
934 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
936 if (is_multicast_ether_addr(hdr
->addr1
))
939 return ieee80211_is_robust_mgmt_frame(skb
);
943 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff
*skb
)
945 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
947 if (!is_multicast_ether_addr(hdr
->addr1
))
950 return ieee80211_is_robust_mgmt_frame(skb
);
954 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
955 static int ieee80211_get_mmie_keyidx(struct sk_buff
*skb
)
957 struct ieee80211_mgmt
*hdr
= (struct ieee80211_mgmt
*) skb
->data
;
958 struct ieee80211_mmie
*mmie
;
959 struct ieee80211_mmie_16
*mmie16
;
961 if (skb
->len
< 24 + sizeof(*mmie
) || !is_multicast_ether_addr(hdr
->da
))
964 if (!ieee80211_is_robust_mgmt_frame(skb
) &&
965 !ieee80211_is_beacon(hdr
->frame_control
))
966 return -1; /* not a robust management frame */
968 mmie
= (struct ieee80211_mmie
*)
969 (skb
->data
+ skb
->len
- sizeof(*mmie
));
970 if (mmie
->element_id
== WLAN_EID_MMIE
&&
971 mmie
->length
== sizeof(*mmie
) - 2)
972 return le16_to_cpu(mmie
->key_id
);
974 mmie16
= (struct ieee80211_mmie_16
*)
975 (skb
->data
+ skb
->len
- sizeof(*mmie16
));
976 if (skb
->len
>= 24 + sizeof(*mmie16
) &&
977 mmie16
->element_id
== WLAN_EID_MMIE
&&
978 mmie16
->length
== sizeof(*mmie16
) - 2)
979 return le16_to_cpu(mmie16
->key_id
);
984 static int ieee80211_get_keyid(struct sk_buff
*skb
,
985 const struct ieee80211_cipher_scheme
*cs
)
987 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
995 fc
= hdr
->frame_control
;
996 hdrlen
= ieee80211_hdrlen(fc
);
999 minlen
= hdrlen
+ cs
->hdr_len
;
1000 key_idx_off
= hdrlen
+ cs
->key_idx_off
;
1001 key_idx_shift
= cs
->key_idx_shift
;
1003 /* WEP, TKIP, CCMP and GCMP */
1004 minlen
= hdrlen
+ IEEE80211_WEP_IV_LEN
;
1005 key_idx_off
= hdrlen
+ 3;
1009 if (unlikely(skb
->len
< minlen
))
1012 skb_copy_bits(skb
, key_idx_off
, &keyid
, 1);
1015 keyid
&= cs
->key_idx_mask
;
1016 keyid
>>= key_idx_shift
;
1018 /* cs could use more than the usual two bits for the keyid */
1019 if (unlikely(keyid
>= NUM_DEFAULT_KEYS
))
1025 static ieee80211_rx_result
ieee80211_rx_mesh_check(struct ieee80211_rx_data
*rx
)
1027 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
1028 char *dev_addr
= rx
->sdata
->vif
.addr
;
1030 if (ieee80211_is_data(hdr
->frame_control
)) {
1031 if (is_multicast_ether_addr(hdr
->addr1
)) {
1032 if (ieee80211_has_tods(hdr
->frame_control
) ||
1033 !ieee80211_has_fromds(hdr
->frame_control
))
1034 return RX_DROP_MONITOR
;
1035 if (ether_addr_equal(hdr
->addr3
, dev_addr
))
1036 return RX_DROP_MONITOR
;
1038 if (!ieee80211_has_a4(hdr
->frame_control
))
1039 return RX_DROP_MONITOR
;
1040 if (ether_addr_equal(hdr
->addr4
, dev_addr
))
1041 return RX_DROP_MONITOR
;
1045 /* If there is not an established peer link and this is not a peer link
1046 * establisment frame, beacon or probe, drop the frame.
1049 if (!rx
->sta
|| sta_plink_state(rx
->sta
) != NL80211_PLINK_ESTAB
) {
1050 struct ieee80211_mgmt
*mgmt
;
1052 if (!ieee80211_is_mgmt(hdr
->frame_control
))
1053 return RX_DROP_MONITOR
;
1055 if (ieee80211_is_action(hdr
->frame_control
)) {
1058 /* make sure category field is present */
1059 if (rx
->skb
->len
< IEEE80211_MIN_ACTION_SIZE
)
1060 return RX_DROP_MONITOR
;
1062 mgmt
= (struct ieee80211_mgmt
*)hdr
;
1063 category
= mgmt
->u
.action
.category
;
1064 if (category
!= WLAN_CATEGORY_MESH_ACTION
&&
1065 category
!= WLAN_CATEGORY_SELF_PROTECTED
)
1066 return RX_DROP_MONITOR
;
1070 if (ieee80211_is_probe_req(hdr
->frame_control
) ||
1071 ieee80211_is_probe_resp(hdr
->frame_control
) ||
1072 ieee80211_is_beacon(hdr
->frame_control
) ||
1073 ieee80211_is_auth(hdr
->frame_control
))
1076 return RX_DROP_MONITOR
;
1082 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx
*tid_agg_rx
,
1085 struct sk_buff_head
*frames
= &tid_agg_rx
->reorder_buf
[index
];
1086 struct sk_buff
*tail
= skb_peek_tail(frames
);
1087 struct ieee80211_rx_status
*status
;
1089 if (tid_agg_rx
->reorder_buf_filtered
& BIT_ULL(index
))
1095 status
= IEEE80211_SKB_RXCB(tail
);
1096 if (status
->flag
& RX_FLAG_AMSDU_MORE
)
1102 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data
*sdata
,
1103 struct tid_ampdu_rx
*tid_agg_rx
,
1105 struct sk_buff_head
*frames
)
1107 struct sk_buff_head
*skb_list
= &tid_agg_rx
->reorder_buf
[index
];
1108 struct sk_buff
*skb
;
1109 struct ieee80211_rx_status
*status
;
1111 lockdep_assert_held(&tid_agg_rx
->reorder_lock
);
1113 if (skb_queue_empty(skb_list
))
1116 if (!ieee80211_rx_reorder_ready(tid_agg_rx
, index
)) {
1117 __skb_queue_purge(skb_list
);
1121 /* release frames from the reorder ring buffer */
1122 tid_agg_rx
->stored_mpdu_num
--;
1123 while ((skb
= __skb_dequeue(skb_list
))) {
1124 status
= IEEE80211_SKB_RXCB(skb
);
1125 status
->rx_flags
|= IEEE80211_RX_DEFERRED_RELEASE
;
1126 __skb_queue_tail(frames
, skb
);
1130 tid_agg_rx
->reorder_buf_filtered
&= ~BIT_ULL(index
);
1131 tid_agg_rx
->head_seq_num
= ieee80211_sn_inc(tid_agg_rx
->head_seq_num
);
1134 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data
*sdata
,
1135 struct tid_ampdu_rx
*tid_agg_rx
,
1137 struct sk_buff_head
*frames
)
1141 lockdep_assert_held(&tid_agg_rx
->reorder_lock
);
1143 while (ieee80211_sn_less(tid_agg_rx
->head_seq_num
, head_seq_num
)) {
1144 index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1145 ieee80211_release_reorder_frame(sdata
, tid_agg_rx
, index
,
1151 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1152 * the skb was added to the buffer longer than this time ago, the earlier
1153 * frames that have not yet been received are assumed to be lost and the skb
1154 * can be released for processing. This may also release other skb's from the
1155 * reorder buffer if there are no additional gaps between the frames.
1157 * Callers must hold tid_agg_rx->reorder_lock.
1159 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1161 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data
*sdata
,
1162 struct tid_ampdu_rx
*tid_agg_rx
,
1163 struct sk_buff_head
*frames
)
1167 lockdep_assert_held(&tid_agg_rx
->reorder_lock
);
1169 /* release the buffer until next missing frame */
1170 index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1171 if (!ieee80211_rx_reorder_ready(tid_agg_rx
, index
) &&
1172 tid_agg_rx
->stored_mpdu_num
) {
1174 * No buffers ready to be released, but check whether any
1175 * frames in the reorder buffer have timed out.
1178 for (j
= (index
+ 1) % tid_agg_rx
->buf_size
; j
!= index
;
1179 j
= (j
+ 1) % tid_agg_rx
->buf_size
) {
1180 if (!ieee80211_rx_reorder_ready(tid_agg_rx
, j
)) {
1185 !time_after(jiffies
, tid_agg_rx
->reorder_time
[j
] +
1186 HT_RX_REORDER_BUF_TIMEOUT
))
1187 goto set_release_timer
;
1189 /* don't leave incomplete A-MSDUs around */
1190 for (i
= (index
+ 1) % tid_agg_rx
->buf_size
; i
!= j
;
1191 i
= (i
+ 1) % tid_agg_rx
->buf_size
)
1192 __skb_queue_purge(&tid_agg_rx
->reorder_buf
[i
]);
1194 ht_dbg_ratelimited(sdata
,
1195 "release an RX reorder frame due to timeout on earlier frames\n");
1196 ieee80211_release_reorder_frame(sdata
, tid_agg_rx
, j
,
1200 * Increment the head seq# also for the skipped slots.
1202 tid_agg_rx
->head_seq_num
=
1203 (tid_agg_rx
->head_seq_num
+
1204 skipped
) & IEEE80211_SN_MASK
;
1207 } else while (ieee80211_rx_reorder_ready(tid_agg_rx
, index
)) {
1208 ieee80211_release_reorder_frame(sdata
, tid_agg_rx
, index
,
1210 index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1213 if (tid_agg_rx
->stored_mpdu_num
) {
1214 j
= index
= tid_agg_rx
->head_seq_num
% tid_agg_rx
->buf_size
;
1216 for (; j
!= (index
- 1) % tid_agg_rx
->buf_size
;
1217 j
= (j
+ 1) % tid_agg_rx
->buf_size
) {
1218 if (ieee80211_rx_reorder_ready(tid_agg_rx
, j
))
1224 if (!tid_agg_rx
->removed
)
1225 mod_timer(&tid_agg_rx
->reorder_timer
,
1226 tid_agg_rx
->reorder_time
[j
] + 1 +
1227 HT_RX_REORDER_BUF_TIMEOUT
);
1229 del_timer(&tid_agg_rx
->reorder_timer
);
1234 * As this function belongs to the RX path it must be under
1235 * rcu_read_lock protection. It returns false if the frame
1236 * can be processed immediately, true if it was consumed.
1238 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data
*sdata
,
1239 struct tid_ampdu_rx
*tid_agg_rx
,
1240 struct sk_buff
*skb
,
1241 struct sk_buff_head
*frames
)
1243 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1244 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1245 u16 sc
= le16_to_cpu(hdr
->seq_ctrl
);
1246 u16 mpdu_seq_num
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
1247 u16 head_seq_num
, buf_size
;
1251 spin_lock(&tid_agg_rx
->reorder_lock
);
1254 * Offloaded BA sessions have no known starting sequence number so pick
1255 * one from first Rxed frame for this tid after BA was started.
1257 if (unlikely(tid_agg_rx
->auto_seq
)) {
1258 tid_agg_rx
->auto_seq
= false;
1259 tid_agg_rx
->ssn
= mpdu_seq_num
;
1260 tid_agg_rx
->head_seq_num
= mpdu_seq_num
;
1263 buf_size
= tid_agg_rx
->buf_size
;
1264 head_seq_num
= tid_agg_rx
->head_seq_num
;
1267 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1270 if (unlikely(!tid_agg_rx
->started
)) {
1271 if (ieee80211_sn_less(mpdu_seq_num
, head_seq_num
)) {
1275 tid_agg_rx
->started
= true;
1278 /* frame with out of date sequence number */
1279 if (ieee80211_sn_less(mpdu_seq_num
, head_seq_num
)) {
1285 * If frame the sequence number exceeds our buffering window
1286 * size release some previous frames to make room for this one.
1288 if (!ieee80211_sn_less(mpdu_seq_num
, head_seq_num
+ buf_size
)) {
1289 head_seq_num
= ieee80211_sn_inc(
1290 ieee80211_sn_sub(mpdu_seq_num
, buf_size
));
1291 /* release stored frames up to new head to stack */
1292 ieee80211_release_reorder_frames(sdata
, tid_agg_rx
,
1293 head_seq_num
, frames
);
1296 /* Now the new frame is always in the range of the reordering buffer */
1298 index
= mpdu_seq_num
% tid_agg_rx
->buf_size
;
1300 /* check if we already stored this frame */
1301 if (ieee80211_rx_reorder_ready(tid_agg_rx
, index
)) {
1307 * If the current MPDU is in the right order and nothing else
1308 * is stored we can process it directly, no need to buffer it.
1309 * If it is first but there's something stored, we may be able
1310 * to release frames after this one.
1312 if (mpdu_seq_num
== tid_agg_rx
->head_seq_num
&&
1313 tid_agg_rx
->stored_mpdu_num
== 0) {
1314 if (!(status
->flag
& RX_FLAG_AMSDU_MORE
))
1315 tid_agg_rx
->head_seq_num
=
1316 ieee80211_sn_inc(tid_agg_rx
->head_seq_num
);
1321 /* put the frame in the reordering buffer */
1322 __skb_queue_tail(&tid_agg_rx
->reorder_buf
[index
], skb
);
1323 if (!(status
->flag
& RX_FLAG_AMSDU_MORE
)) {
1324 tid_agg_rx
->reorder_time
[index
] = jiffies
;
1325 tid_agg_rx
->stored_mpdu_num
++;
1326 ieee80211_sta_reorder_release(sdata
, tid_agg_rx
, frames
);
1330 spin_unlock(&tid_agg_rx
->reorder_lock
);
1335 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1336 * true if the MPDU was buffered, false if it should be processed.
1338 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data
*rx
,
1339 struct sk_buff_head
*frames
)
1341 struct sk_buff
*skb
= rx
->skb
;
1342 struct ieee80211_local
*local
= rx
->local
;
1343 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1344 struct sta_info
*sta
= rx
->sta
;
1345 struct tid_ampdu_rx
*tid_agg_rx
;
1349 if (!ieee80211_is_data_qos(hdr
->frame_control
) ||
1350 is_multicast_ether_addr(hdr
->addr1
))
1354 * filter the QoS data rx stream according to
1355 * STA/TID and check if this STA/TID is on aggregation
1361 ack_policy
= *ieee80211_get_qos_ctl(hdr
) &
1362 IEEE80211_QOS_CTL_ACK_POLICY_MASK
;
1363 tid
= ieee80211_get_tid(hdr
);
1365 tid_agg_rx
= rcu_dereference(sta
->ampdu_mlme
.tid_rx
[tid
]);
1367 if (ack_policy
== IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK
&&
1368 !test_bit(tid
, rx
->sta
->ampdu_mlme
.agg_session_valid
) &&
1369 !test_and_set_bit(tid
, rx
->sta
->ampdu_mlme
.unexpected_agg
))
1370 ieee80211_send_delba(rx
->sdata
, rx
->sta
->sta
.addr
, tid
,
1371 WLAN_BACK_RECIPIENT
,
1372 WLAN_REASON_QSTA_REQUIRE_SETUP
);
1376 /* qos null data frames are excluded */
1377 if (unlikely(hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_NULLFUNC
)))
1380 /* not part of a BA session */
1381 if (ack_policy
!= IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK
&&
1382 ack_policy
!= IEEE80211_QOS_CTL_ACK_POLICY_NORMAL
)
1385 /* new, potentially un-ordered, ampdu frame - process it */
1387 /* reset session timer */
1388 if (tid_agg_rx
->timeout
)
1389 tid_agg_rx
->last_rx
= jiffies
;
1391 /* if this mpdu is fragmented - terminate rx aggregation session */
1392 sc
= le16_to_cpu(hdr
->seq_ctrl
);
1393 if (sc
& IEEE80211_SCTL_FRAG
) {
1394 skb_queue_tail(&rx
->sdata
->skb_queue
, skb
);
1395 ieee80211_queue_work(&local
->hw
, &rx
->sdata
->work
);
1400 * No locking needed -- we will only ever process one
1401 * RX packet at a time, and thus own tid_agg_rx. All
1402 * other code manipulating it needs to (and does) make
1403 * sure that we cannot get to it any more before doing
1406 if (ieee80211_sta_manage_reorder_buf(rx
->sdata
, tid_agg_rx
, skb
,
1411 __skb_queue_tail(frames
, skb
);
1414 static ieee80211_rx_result debug_noinline
1415 ieee80211_rx_h_check_dup(struct ieee80211_rx_data
*rx
)
1417 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
1418 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
1420 if (status
->flag
& RX_FLAG_DUP_VALIDATED
)
1424 * Drop duplicate 802.11 retransmissions
1425 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1428 if (rx
->skb
->len
< 24)
1431 if (ieee80211_is_ctl(hdr
->frame_control
) ||
1432 ieee80211_is_any_nullfunc(hdr
->frame_control
) ||
1433 is_multicast_ether_addr(hdr
->addr1
))
1439 if (unlikely(ieee80211_has_retry(hdr
->frame_control
) &&
1440 rx
->sta
->last_seq_ctrl
[rx
->seqno_idx
] == hdr
->seq_ctrl
)) {
1441 I802_DEBUG_INC(rx
->local
->dot11FrameDuplicateCount
);
1442 rx
->sta
->rx_stats
.num_duplicates
++;
1443 return RX_DROP_UNUSABLE
;
1444 } else if (!(status
->flag
& RX_FLAG_AMSDU_MORE
)) {
1445 rx
->sta
->last_seq_ctrl
[rx
->seqno_idx
] = hdr
->seq_ctrl
;
1451 static ieee80211_rx_result debug_noinline
1452 ieee80211_rx_h_check(struct ieee80211_rx_data
*rx
)
1454 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
1456 /* Drop disallowed frame classes based on STA auth/assoc state;
1457 * IEEE 802.11, Chap 5.5.
1459 * mac80211 filters only based on association state, i.e. it drops
1460 * Class 3 frames from not associated stations. hostapd sends
1461 * deauth/disassoc frames when needed. In addition, hostapd is
1462 * responsible for filtering on both auth and assoc states.
1465 if (ieee80211_vif_is_mesh(&rx
->sdata
->vif
))
1466 return ieee80211_rx_mesh_check(rx
);
1468 if (unlikely((ieee80211_is_data(hdr
->frame_control
) ||
1469 ieee80211_is_pspoll(hdr
->frame_control
)) &&
1470 rx
->sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
1471 rx
->sdata
->vif
.type
!= NL80211_IFTYPE_OCB
&&
1472 (!rx
->sta
|| !test_sta_flag(rx
->sta
, WLAN_STA_ASSOC
)))) {
1474 * accept port control frames from the AP even when it's not
1475 * yet marked ASSOC to prevent a race where we don't set the
1476 * assoc bit quickly enough before it sends the first frame
1478 if (rx
->sta
&& rx
->sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
1479 ieee80211_is_data_present(hdr
->frame_control
)) {
1480 unsigned int hdrlen
;
1483 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
1485 if (rx
->skb
->len
< hdrlen
+ 8)
1486 return RX_DROP_MONITOR
;
1488 skb_copy_bits(rx
->skb
, hdrlen
+ 6, ðertype
, 2);
1489 if (ethertype
== rx
->sdata
->control_port_protocol
)
1493 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
&&
1494 cfg80211_rx_spurious_frame(rx
->sdata
->dev
,
1497 return RX_DROP_UNUSABLE
;
1499 return RX_DROP_MONITOR
;
1506 static ieee80211_rx_result debug_noinline
1507 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data
*rx
)
1509 struct ieee80211_local
*local
;
1510 struct ieee80211_hdr
*hdr
;
1511 struct sk_buff
*skb
;
1515 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1517 if (!local
->pspolling
)
1520 if (!ieee80211_has_fromds(hdr
->frame_control
))
1521 /* this is not from AP */
1524 if (!ieee80211_is_data(hdr
->frame_control
))
1527 if (!ieee80211_has_moredata(hdr
->frame_control
)) {
1528 /* AP has no more frames buffered for us */
1529 local
->pspolling
= false;
1533 /* more data bit is set, let's request a new frame from the AP */
1534 ieee80211_send_pspoll(local
, rx
->sdata
);
1539 static void sta_ps_start(struct sta_info
*sta
)
1541 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
1542 struct ieee80211_local
*local
= sdata
->local
;
1546 if (sta
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1547 sta
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
1548 ps
= &sdata
->bss
->ps
;
1552 atomic_inc(&ps
->num_sta_ps
);
1553 set_sta_flag(sta
, WLAN_STA_PS_STA
);
1554 if (!ieee80211_hw_check(&local
->hw
, AP_LINK_PS
))
1555 drv_sta_notify(local
, sdata
, STA_NOTIFY_SLEEP
, &sta
->sta
);
1556 ps_dbg(sdata
, "STA %pM aid %d enters power save mode\n",
1557 sta
->sta
.addr
, sta
->sta
.aid
);
1559 ieee80211_clear_fast_xmit(sta
);
1561 if (!sta
->sta
.txq
[0])
1564 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
; tid
++) {
1565 struct ieee80211_txq
*txq
= sta
->sta
.txq
[tid
];
1566 struct txq_info
*txqi
= to_txq_info(txq
);
1568 spin_lock(&local
->active_txq_lock
[txq
->ac
]);
1569 if (!list_empty(&txqi
->schedule_order
))
1570 list_del_init(&txqi
->schedule_order
);
1571 spin_unlock(&local
->active_txq_lock
[txq
->ac
]);
1573 if (txq_has_queue(txq
))
1574 set_bit(tid
, &sta
->txq_buffered_tids
);
1576 clear_bit(tid
, &sta
->txq_buffered_tids
);
1580 static void sta_ps_end(struct sta_info
*sta
)
1582 ps_dbg(sta
->sdata
, "STA %pM aid %d exits power save mode\n",
1583 sta
->sta
.addr
, sta
->sta
.aid
);
1585 if (test_sta_flag(sta
, WLAN_STA_PS_DRIVER
)) {
1587 * Clear the flag only if the other one is still set
1588 * so that the TX path won't start TX'ing new frames
1589 * directly ... In the case that the driver flag isn't
1590 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1592 clear_sta_flag(sta
, WLAN_STA_PS_STA
);
1593 ps_dbg(sta
->sdata
, "STA %pM aid %d driver-ps-blocked\n",
1594 sta
->sta
.addr
, sta
->sta
.aid
);
1598 set_sta_flag(sta
, WLAN_STA_PS_DELIVER
);
1599 clear_sta_flag(sta
, WLAN_STA_PS_STA
);
1600 ieee80211_sta_ps_deliver_wakeup(sta
);
1603 int ieee80211_sta_ps_transition(struct ieee80211_sta
*pubsta
, bool start
)
1605 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
1608 WARN_ON(!ieee80211_hw_check(&sta
->local
->hw
, AP_LINK_PS
));
1610 /* Don't let the same PS state be set twice */
1611 in_ps
= test_sta_flag(sta
, WLAN_STA_PS_STA
);
1612 if ((start
&& in_ps
) || (!start
&& !in_ps
))
1622 EXPORT_SYMBOL(ieee80211_sta_ps_transition
);
1624 void ieee80211_sta_pspoll(struct ieee80211_sta
*pubsta
)
1626 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
1628 if (test_sta_flag(sta
, WLAN_STA_SP
))
1631 if (!test_sta_flag(sta
, WLAN_STA_PS_DRIVER
))
1632 ieee80211_sta_ps_deliver_poll_response(sta
);
1634 set_sta_flag(sta
, WLAN_STA_PSPOLL
);
1636 EXPORT_SYMBOL(ieee80211_sta_pspoll
);
1638 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta
*pubsta
, u8 tid
)
1640 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
1641 int ac
= ieee80211_ac_from_tid(tid
);
1644 * If this AC is not trigger-enabled do nothing unless the
1645 * driver is calling us after it already checked.
1647 * NB: This could/should check a separate bitmap of trigger-
1648 * enabled queues, but for now we only implement uAPSD w/o
1649 * TSPEC changes to the ACs, so they're always the same.
1651 if (!(sta
->sta
.uapsd_queues
& ieee80211_ac_to_qos_mask
[ac
]) &&
1652 tid
!= IEEE80211_NUM_TIDS
)
1655 /* if we are in a service period, do nothing */
1656 if (test_sta_flag(sta
, WLAN_STA_SP
))
1659 if (!test_sta_flag(sta
, WLAN_STA_PS_DRIVER
))
1660 ieee80211_sta_ps_deliver_uapsd(sta
);
1662 set_sta_flag(sta
, WLAN_STA_UAPSD
);
1664 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger
);
1666 static ieee80211_rx_result debug_noinline
1667 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data
*rx
)
1669 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1670 struct ieee80211_hdr
*hdr
= (void *)rx
->skb
->data
;
1671 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
1676 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
1677 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
)
1681 * The device handles station powersave, so don't do anything about
1682 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1683 * it to mac80211 since they're handled.)
1685 if (ieee80211_hw_check(&sdata
->local
->hw
, AP_LINK_PS
))
1689 * Don't do anything if the station isn't already asleep. In
1690 * the uAPSD case, the station will probably be marked asleep,
1691 * in the PS-Poll case the station must be confused ...
1693 if (!test_sta_flag(rx
->sta
, WLAN_STA_PS_STA
))
1696 if (unlikely(ieee80211_is_pspoll(hdr
->frame_control
))) {
1697 ieee80211_sta_pspoll(&rx
->sta
->sta
);
1699 /* Free PS Poll skb here instead of returning RX_DROP that would
1700 * count as an dropped frame. */
1701 dev_kfree_skb(rx
->skb
);
1704 } else if (!ieee80211_has_morefrags(hdr
->frame_control
) &&
1705 !(status
->rx_flags
& IEEE80211_RX_DEFERRED_RELEASE
) &&
1706 ieee80211_has_pm(hdr
->frame_control
) &&
1707 (ieee80211_is_data_qos(hdr
->frame_control
) ||
1708 ieee80211_is_qos_nullfunc(hdr
->frame_control
))) {
1709 u8 tid
= ieee80211_get_tid(hdr
);
1711 ieee80211_sta_uapsd_trigger(&rx
->sta
->sta
, tid
);
1717 static ieee80211_rx_result debug_noinline
1718 ieee80211_rx_h_sta_process(struct ieee80211_rx_data
*rx
)
1720 struct sta_info
*sta
= rx
->sta
;
1721 struct sk_buff
*skb
= rx
->skb
;
1722 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1723 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1730 * Update last_rx only for IBSS packets which are for the current
1731 * BSSID and for station already AUTHORIZED to avoid keeping the
1732 * current IBSS network alive in cases where other STAs start
1733 * using different BSSID. This will also give the station another
1734 * chance to restart the authentication/authorization in case
1735 * something went wrong the first time.
1737 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
1738 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
,
1739 NL80211_IFTYPE_ADHOC
);
1740 if (ether_addr_equal(bssid
, rx
->sdata
->u
.ibss
.bssid
) &&
1741 test_sta_flag(sta
, WLAN_STA_AUTHORIZED
)) {
1742 sta
->rx_stats
.last_rx
= jiffies
;
1743 if (ieee80211_is_data(hdr
->frame_control
) &&
1744 !is_multicast_ether_addr(hdr
->addr1
))
1745 sta
->rx_stats
.last_rate
=
1746 sta_stats_encode_rate(status
);
1748 } else if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_OCB
) {
1749 sta
->rx_stats
.last_rx
= jiffies
;
1750 } else if (!ieee80211_is_s1g_beacon(hdr
->frame_control
) &&
1751 !is_multicast_ether_addr(hdr
->addr1
)) {
1753 * Mesh beacons will update last_rx when if they are found to
1754 * match the current local configuration when processed.
1756 sta
->rx_stats
.last_rx
= jiffies
;
1757 if (ieee80211_is_data(hdr
->frame_control
))
1758 sta
->rx_stats
.last_rate
= sta_stats_encode_rate(status
);
1761 sta
->rx_stats
.fragments
++;
1763 u64_stats_update_begin(&rx
->sta
->rx_stats
.syncp
);
1764 sta
->rx_stats
.bytes
+= rx
->skb
->len
;
1765 u64_stats_update_end(&rx
->sta
->rx_stats
.syncp
);
1767 if (!(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
)) {
1768 sta
->rx_stats
.last_signal
= status
->signal
;
1769 ewma_signal_add(&sta
->rx_stats_avg
.signal
, -status
->signal
);
1772 if (status
->chains
) {
1773 sta
->rx_stats
.chains
= status
->chains
;
1774 for (i
= 0; i
< ARRAY_SIZE(status
->chain_signal
); i
++) {
1775 int signal
= status
->chain_signal
[i
];
1777 if (!(status
->chains
& BIT(i
)))
1780 sta
->rx_stats
.chain_signal_last
[i
] = signal
;
1781 ewma_signal_add(&sta
->rx_stats_avg
.chain_signal
[i
],
1786 if (ieee80211_is_s1g_beacon(hdr
->frame_control
))
1790 * Change STA power saving mode only at the end of a frame
1791 * exchange sequence, and only for a data or management
1792 * frame as specified in IEEE 802.11-2016 11.2.3.2
1794 if (!ieee80211_hw_check(&sta
->local
->hw
, AP_LINK_PS
) &&
1795 !ieee80211_has_morefrags(hdr
->frame_control
) &&
1796 !is_multicast_ether_addr(hdr
->addr1
) &&
1797 (ieee80211_is_mgmt(hdr
->frame_control
) ||
1798 ieee80211_is_data(hdr
->frame_control
)) &&
1799 !(status
->rx_flags
& IEEE80211_RX_DEFERRED_RELEASE
) &&
1800 (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1801 rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)) {
1802 if (test_sta_flag(sta
, WLAN_STA_PS_STA
)) {
1803 if (!ieee80211_has_pm(hdr
->frame_control
))
1806 if (ieee80211_has_pm(hdr
->frame_control
))
1811 /* mesh power save support */
1812 if (ieee80211_vif_is_mesh(&rx
->sdata
->vif
))
1813 ieee80211_mps_rx_h_sta_process(sta
, hdr
);
1816 * Drop (qos-)data::nullfunc frames silently, since they
1817 * are used only to control station power saving mode.
1819 if (ieee80211_is_any_nullfunc(hdr
->frame_control
)) {
1820 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
1823 * If we receive a 4-addr nullfunc frame from a STA
1824 * that was not moved to a 4-addr STA vlan yet send
1825 * the event to userspace and for older hostapd drop
1826 * the frame to the monitor interface.
1828 if (ieee80211_has_a4(hdr
->frame_control
) &&
1829 (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1830 (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
1831 !rx
->sdata
->u
.vlan
.sta
))) {
1832 if (!test_and_set_sta_flag(sta
, WLAN_STA_4ADDR_EVENT
))
1833 cfg80211_rx_unexpected_4addr_frame(
1834 rx
->sdata
->dev
, sta
->sta
.addr
,
1836 return RX_DROP_MONITOR
;
1839 * Update counter and free packet here to avoid
1840 * counting this as a dropped packed.
1842 sta
->rx_stats
.packets
++;
1843 dev_kfree_skb(rx
->skb
);
1848 } /* ieee80211_rx_h_sta_process */
1850 static struct ieee80211_key
*
1851 ieee80211_rx_get_bigtk(struct ieee80211_rx_data
*rx
, int idx
)
1853 struct ieee80211_key
*key
= NULL
;
1854 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
1857 /* Make sure key gets set if either BIGTK key index is set so that
1858 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1859 * Beacon frames and Beacon frames that claim to use another BIGTK key
1860 * index (i.e., a key that we do not have).
1864 idx
= NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
;
1867 if (idx
== NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
)
1874 key
= rcu_dereference(rx
->sta
->gtk
[idx
]);
1876 key
= rcu_dereference(sdata
->keys
[idx
]);
1877 if (!key
&& rx
->sta
)
1878 key
= rcu_dereference(rx
->sta
->gtk
[idx2
]);
1880 key
= rcu_dereference(sdata
->keys
[idx2
]);
1885 static ieee80211_rx_result debug_noinline
1886 ieee80211_rx_h_decrypt(struct ieee80211_rx_data
*rx
)
1888 struct sk_buff
*skb
= rx
->skb
;
1889 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
1890 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1892 ieee80211_rx_result result
= RX_DROP_UNUSABLE
;
1893 struct ieee80211_key
*sta_ptk
= NULL
;
1894 struct ieee80211_key
*ptk_idx
= NULL
;
1895 int mmie_keyidx
= -1;
1897 const struct ieee80211_cipher_scheme
*cs
= NULL
;
1899 if (ieee80211_is_ext(hdr
->frame_control
))
1905 * There are five types of keys:
1906 * - GTK (group keys)
1907 * - IGTK (group keys for management frames)
1908 * - BIGTK (group keys for Beacon frames)
1909 * - PTK (pairwise keys)
1910 * - STK (station-to-station pairwise keys)
1912 * When selecting a key, we have to distinguish between multicast
1913 * (including broadcast) and unicast frames, the latter can only
1914 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1915 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1916 * then unicast frames can also use key indices like GTKs. Hence, if we
1917 * don't have a PTK/STK we check the key index for a WEP key.
1919 * Note that in a regular BSS, multicast frames are sent by the
1920 * AP only, associated stations unicast the frame to the AP first
1921 * which then multicasts it on their behalf.
1923 * There is also a slight problem in IBSS mode: GTKs are negotiated
1924 * with each station, that is something we don't currently handle.
1925 * The spec seems to expect that one negotiates the same key with
1926 * every station but there's no such requirement; VLANs could be
1930 /* start without a key */
1932 fc
= hdr
->frame_control
;
1935 int keyid
= rx
->sta
->ptk_idx
;
1936 sta_ptk
= rcu_dereference(rx
->sta
->ptk
[keyid
]);
1938 if (ieee80211_has_protected(fc
)) {
1939 cs
= rx
->sta
->cipher_scheme
;
1940 keyid
= ieee80211_get_keyid(rx
->skb
, cs
);
1942 if (unlikely(keyid
< 0))
1943 return RX_DROP_UNUSABLE
;
1945 ptk_idx
= rcu_dereference(rx
->sta
->ptk
[keyid
]);
1949 if (!ieee80211_has_protected(fc
))
1950 mmie_keyidx
= ieee80211_get_mmie_keyidx(rx
->skb
);
1952 if (!is_multicast_ether_addr(hdr
->addr1
) && sta_ptk
) {
1953 rx
->key
= ptk_idx
? ptk_idx
: sta_ptk
;
1954 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
1955 (status
->flag
& RX_FLAG_IV_STRIPPED
))
1957 /* Skip decryption if the frame is not protected. */
1958 if (!ieee80211_has_protected(fc
))
1960 } else if (mmie_keyidx
>= 0 && ieee80211_is_beacon(fc
)) {
1961 /* Broadcast/multicast robust management frame / BIP */
1962 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
1963 (status
->flag
& RX_FLAG_IV_STRIPPED
))
1966 if (mmie_keyidx
< NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
||
1967 mmie_keyidx
>= NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
+
1968 NUM_DEFAULT_BEACON_KEYS
) {
1969 cfg80211_rx_unprot_mlme_mgmt(rx
->sdata
->dev
,
1972 return RX_DROP_MONITOR
; /* unexpected BIP keyidx */
1975 rx
->key
= ieee80211_rx_get_bigtk(rx
, mmie_keyidx
);
1977 return RX_CONTINUE
; /* Beacon protection not in use */
1978 } else if (mmie_keyidx
>= 0) {
1979 /* Broadcast/multicast robust management frame / BIP */
1980 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
1981 (status
->flag
& RX_FLAG_IV_STRIPPED
))
1984 if (mmie_keyidx
< NUM_DEFAULT_KEYS
||
1985 mmie_keyidx
>= NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
)
1986 return RX_DROP_MONITOR
; /* unexpected BIP keyidx */
1988 if (ieee80211_is_group_privacy_action(skb
) &&
1989 test_sta_flag(rx
->sta
, WLAN_STA_MFP
))
1990 return RX_DROP_MONITOR
;
1992 rx
->key
= rcu_dereference(rx
->sta
->gtk
[mmie_keyidx
]);
1995 rx
->key
= rcu_dereference(rx
->sdata
->keys
[mmie_keyidx
]);
1996 } else if (!ieee80211_has_protected(fc
)) {
1998 * The frame was not protected, so skip decryption. However, we
1999 * need to set rx->key if there is a key that could have been
2000 * used so that the frame may be dropped if encryption would
2001 * have been expected.
2003 struct ieee80211_key
*key
= NULL
;
2004 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2007 if (ieee80211_is_beacon(fc
)) {
2008 key
= ieee80211_rx_get_bigtk(rx
, -1);
2009 } else if (ieee80211_is_mgmt(fc
) &&
2010 is_multicast_ether_addr(hdr
->addr1
)) {
2011 key
= rcu_dereference(rx
->sdata
->default_mgmt_key
);
2014 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2015 key
= rcu_dereference(rx
->sta
->gtk
[i
]);
2021 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2022 key
= rcu_dereference(sdata
->keys
[i
]);
2033 * The device doesn't give us the IV so we won't be
2034 * able to look up the key. That's ok though, we
2035 * don't need to decrypt the frame, we just won't
2036 * be able to keep statistics accurate.
2037 * Except for key threshold notifications, should
2038 * we somehow allow the driver to tell us which key
2039 * the hardware used if this flag is set?
2041 if ((status
->flag
& RX_FLAG_DECRYPTED
) &&
2042 (status
->flag
& RX_FLAG_IV_STRIPPED
))
2045 keyidx
= ieee80211_get_keyid(rx
->skb
, cs
);
2047 if (unlikely(keyidx
< 0))
2048 return RX_DROP_UNUSABLE
;
2050 /* check per-station GTK first, if multicast packet */
2051 if (is_multicast_ether_addr(hdr
->addr1
) && rx
->sta
)
2052 rx
->key
= rcu_dereference(rx
->sta
->gtk
[keyidx
]);
2054 /* if not found, try default key */
2056 rx
->key
= rcu_dereference(rx
->sdata
->keys
[keyidx
]);
2059 * RSNA-protected unicast frames should always be
2060 * sent with pairwise or station-to-station keys,
2061 * but for WEP we allow using a key index as well.
2064 rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
2065 rx
->key
->conf
.cipher
!= WLAN_CIPHER_SUITE_WEP104
&&
2066 !is_multicast_ether_addr(hdr
->addr1
))
2072 if (unlikely(rx
->key
->flags
& KEY_FLAG_TAINTED
))
2073 return RX_DROP_MONITOR
;
2075 /* TODO: add threshold stuff again */
2077 return RX_DROP_MONITOR
;
2080 switch (rx
->key
->conf
.cipher
) {
2081 case WLAN_CIPHER_SUITE_WEP40
:
2082 case WLAN_CIPHER_SUITE_WEP104
:
2083 result
= ieee80211_crypto_wep_decrypt(rx
);
2085 case WLAN_CIPHER_SUITE_TKIP
:
2086 result
= ieee80211_crypto_tkip_decrypt(rx
);
2088 case WLAN_CIPHER_SUITE_CCMP
:
2089 result
= ieee80211_crypto_ccmp_decrypt(
2090 rx
, IEEE80211_CCMP_MIC_LEN
);
2092 case WLAN_CIPHER_SUITE_CCMP_256
:
2093 result
= ieee80211_crypto_ccmp_decrypt(
2094 rx
, IEEE80211_CCMP_256_MIC_LEN
);
2096 case WLAN_CIPHER_SUITE_AES_CMAC
:
2097 result
= ieee80211_crypto_aes_cmac_decrypt(rx
);
2099 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
2100 result
= ieee80211_crypto_aes_cmac_256_decrypt(rx
);
2102 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
2103 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
2104 result
= ieee80211_crypto_aes_gmac_decrypt(rx
);
2106 case WLAN_CIPHER_SUITE_GCMP
:
2107 case WLAN_CIPHER_SUITE_GCMP_256
:
2108 result
= ieee80211_crypto_gcmp_decrypt(rx
);
2111 result
= ieee80211_crypto_hw_decrypt(rx
);
2114 /* the hdr variable is invalid after the decrypt handlers */
2116 /* either the frame has been decrypted or will be dropped */
2117 status
->flag
|= RX_FLAG_DECRYPTED
;
2119 if (unlikely(ieee80211_is_beacon(fc
) && result
== RX_DROP_UNUSABLE
))
2120 cfg80211_rx_unprot_mlme_mgmt(rx
->sdata
->dev
,
2121 skb
->data
, skb
->len
);
2126 static inline struct ieee80211_fragment_entry
*
2127 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
2128 unsigned int frag
, unsigned int seq
, int rx_queue
,
2129 struct sk_buff
**skb
)
2131 struct ieee80211_fragment_entry
*entry
;
2133 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
2134 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
2135 sdata
->fragment_next
= 0;
2137 if (!skb_queue_empty(&entry
->skb_list
))
2138 __skb_queue_purge(&entry
->skb_list
);
2140 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
2142 entry
->first_frag_time
= jiffies
;
2144 entry
->rx_queue
= rx_queue
;
2145 entry
->last_frag
= frag
;
2146 entry
->check_sequential_pn
= false;
2147 entry
->extra_len
= 0;
2152 static inline struct ieee80211_fragment_entry
*
2153 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
2154 unsigned int frag
, unsigned int seq
,
2155 int rx_queue
, struct ieee80211_hdr
*hdr
)
2157 struct ieee80211_fragment_entry
*entry
;
2160 idx
= sdata
->fragment_next
;
2161 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
2162 struct ieee80211_hdr
*f_hdr
;
2163 struct sk_buff
*f_skb
;
2167 idx
= IEEE80211_FRAGMENT_MAX
- 1;
2169 entry
= &sdata
->fragments
[idx
];
2170 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
2171 entry
->rx_queue
!= rx_queue
||
2172 entry
->last_frag
+ 1 != frag
)
2175 f_skb
= __skb_peek(&entry
->skb_list
);
2176 f_hdr
= (struct ieee80211_hdr
*) f_skb
->data
;
2179 * Check ftype and addresses are equal, else check next fragment
2181 if (((hdr
->frame_control
^ f_hdr
->frame_control
) &
2182 cpu_to_le16(IEEE80211_FCTL_FTYPE
)) ||
2183 !ether_addr_equal(hdr
->addr1
, f_hdr
->addr1
) ||
2184 !ether_addr_equal(hdr
->addr2
, f_hdr
->addr2
))
2187 if (time_after(jiffies
, entry
->first_frag_time
+ 2 * HZ
)) {
2188 __skb_queue_purge(&entry
->skb_list
);
2197 static bool requires_sequential_pn(struct ieee80211_rx_data
*rx
, __le16 fc
)
2200 (rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_CCMP
||
2201 rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_CCMP_256
||
2202 rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_GCMP
||
2203 rx
->key
->conf
.cipher
== WLAN_CIPHER_SUITE_GCMP_256
) &&
2204 ieee80211_has_protected(fc
);
2207 static ieee80211_rx_result debug_noinline
2208 ieee80211_rx_h_defragment(struct ieee80211_rx_data
*rx
)
2210 struct ieee80211_hdr
*hdr
;
2213 unsigned int frag
, seq
;
2214 struct ieee80211_fragment_entry
*entry
;
2215 struct sk_buff
*skb
;
2217 hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2218 fc
= hdr
->frame_control
;
2220 if (ieee80211_is_ctl(fc
) || ieee80211_is_ext(fc
))
2223 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2224 frag
= sc
& IEEE80211_SCTL_FRAG
;
2226 if (is_multicast_ether_addr(hdr
->addr1
)) {
2227 I802_DEBUG_INC(rx
->local
->dot11MulticastReceivedFrameCount
);
2231 if (likely(!ieee80211_has_morefrags(fc
) && frag
== 0))
2234 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
2236 if (skb_linearize(rx
->skb
))
2237 return RX_DROP_UNUSABLE
;
2240 * skb_linearize() might change the skb->data and
2241 * previously cached variables (in this case, hdr) need to
2242 * be refreshed with the new data.
2244 hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2245 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2248 /* This is the first fragment of a new frame. */
2249 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
2250 rx
->seqno_idx
, &(rx
->skb
));
2251 if (requires_sequential_pn(rx
, fc
)) {
2252 int queue
= rx
->security_idx
;
2254 /* Store CCMP/GCMP PN so that we can verify that the
2255 * next fragment has a sequential PN value.
2257 entry
->check_sequential_pn
= true;
2258 entry
->key_color
= rx
->key
->color
;
2259 memcpy(entry
->last_pn
,
2260 rx
->key
->u
.ccmp
.rx_pn
[queue
],
2261 IEEE80211_CCMP_PN_LEN
);
2262 BUILD_BUG_ON(offsetof(struct ieee80211_key
,
2264 offsetof(struct ieee80211_key
,
2266 BUILD_BUG_ON(sizeof(rx
->key
->u
.ccmp
.rx_pn
[queue
]) !=
2267 sizeof(rx
->key
->u
.gcmp
.rx_pn
[queue
]));
2268 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN
!=
2269 IEEE80211_GCMP_PN_LEN
);
2274 /* This is a fragment for a frame that should already be pending in
2275 * fragment cache. Add this fragment to the end of the pending entry.
2277 entry
= ieee80211_reassemble_find(rx
->sdata
, frag
, seq
,
2278 rx
->seqno_idx
, hdr
);
2280 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
2281 return RX_DROP_MONITOR
;
2284 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2285 * MPDU PN values are not incrementing in steps of 1."
2286 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2287 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2289 if (entry
->check_sequential_pn
) {
2291 u8 pn
[IEEE80211_CCMP_PN_LEN
], *rpn
;
2294 if (!requires_sequential_pn(rx
, fc
))
2295 return RX_DROP_UNUSABLE
;
2297 /* Prevent mixed key and fragment cache attacks */
2298 if (entry
->key_color
!= rx
->key
->color
)
2299 return RX_DROP_UNUSABLE
;
2301 memcpy(pn
, entry
->last_pn
, IEEE80211_CCMP_PN_LEN
);
2302 for (i
= IEEE80211_CCMP_PN_LEN
- 1; i
>= 0; i
--) {
2307 queue
= rx
->security_idx
;
2308 rpn
= rx
->key
->u
.ccmp
.rx_pn
[queue
];
2309 if (memcmp(pn
, rpn
, IEEE80211_CCMP_PN_LEN
))
2310 return RX_DROP_UNUSABLE
;
2311 memcpy(entry
->last_pn
, pn
, IEEE80211_CCMP_PN_LEN
);
2314 skb_pull(rx
->skb
, ieee80211_hdrlen(fc
));
2315 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
2316 entry
->last_frag
= frag
;
2317 entry
->extra_len
+= rx
->skb
->len
;
2318 if (ieee80211_has_morefrags(fc
)) {
2323 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
2324 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
2325 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head_defrag
);
2326 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
2328 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
2329 __skb_queue_purge(&entry
->skb_list
);
2330 return RX_DROP_UNUSABLE
;
2333 while ((skb
= __skb_dequeue(&entry
->skb_list
))) {
2334 skb_put_data(rx
->skb
, skb
->data
, skb
->len
);
2339 ieee80211_led_rx(rx
->local
);
2342 rx
->sta
->rx_stats
.packets
++;
2346 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data
*rx
)
2348 if (unlikely(!rx
->sta
|| !test_sta_flag(rx
->sta
, WLAN_STA_AUTHORIZED
)))
2354 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data
*rx
, __le16 fc
)
2356 struct ieee80211_hdr
*hdr
= (void *)rx
->skb
->data
;
2357 struct sk_buff
*skb
= rx
->skb
;
2358 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2361 * Pass through unencrypted frames if the hardware has
2362 * decrypted them already.
2364 if (status
->flag
& RX_FLAG_DECRYPTED
)
2367 /* check mesh EAPOL frames first */
2368 if (unlikely(rx
->sta
&& ieee80211_vif_is_mesh(&rx
->sdata
->vif
) &&
2369 ieee80211_is_data(fc
))) {
2370 struct ieee80211s_hdr
*mesh_hdr
;
2371 u16 hdr_len
= ieee80211_hdrlen(fc
);
2372 u16 ethertype_offset
;
2375 if (!ether_addr_equal(hdr
->addr1
, rx
->sdata
->vif
.addr
))
2378 /* make sure fixed part of mesh header is there, also checks skb len */
2379 if (!pskb_may_pull(rx
->skb
, hdr_len
+ 6))
2382 mesh_hdr
= (struct ieee80211s_hdr
*)(skb
->data
+ hdr_len
);
2383 ethertype_offset
= hdr_len
+ ieee80211_get_mesh_hdrlen(mesh_hdr
) +
2384 sizeof(rfc1042_header
);
2386 if (skb_copy_bits(rx
->skb
, ethertype_offset
, ðertype
, 2) == 0 &&
2387 ethertype
== rx
->sdata
->control_port_protocol
)
2392 /* Drop unencrypted frames if key is set. */
2393 if (unlikely(!ieee80211_has_protected(fc
) &&
2394 !ieee80211_is_any_nullfunc(fc
) &&
2395 ieee80211_is_data(fc
) && rx
->key
))
2401 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data
*rx
)
2403 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2404 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
2405 __le16 fc
= hdr
->frame_control
;
2408 * Pass through unencrypted frames if the hardware has
2409 * decrypted them already.
2411 if (status
->flag
& RX_FLAG_DECRYPTED
)
2414 if (rx
->sta
&& test_sta_flag(rx
->sta
, WLAN_STA_MFP
)) {
2415 if (unlikely(!ieee80211_has_protected(fc
) &&
2416 ieee80211_is_unicast_robust_mgmt_frame(rx
->skb
) &&
2418 if (ieee80211_is_deauth(fc
) ||
2419 ieee80211_is_disassoc(fc
))
2420 cfg80211_rx_unprot_mlme_mgmt(rx
->sdata
->dev
,
2425 /* BIP does not use Protected field, so need to check MMIE */
2426 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx
->skb
) &&
2427 ieee80211_get_mmie_keyidx(rx
->skb
) < 0)) {
2428 if (ieee80211_is_deauth(fc
) ||
2429 ieee80211_is_disassoc(fc
))
2430 cfg80211_rx_unprot_mlme_mgmt(rx
->sdata
->dev
,
2435 if (unlikely(ieee80211_is_beacon(fc
) && rx
->key
&&
2436 ieee80211_get_mmie_keyidx(rx
->skb
) < 0)) {
2437 cfg80211_rx_unprot_mlme_mgmt(rx
->sdata
->dev
,
2443 * When using MFP, Action frames are not allowed prior to
2444 * having configured keys.
2446 if (unlikely(ieee80211_is_action(fc
) && !rx
->key
&&
2447 ieee80211_is_robust_mgmt_frame(rx
->skb
)))
2455 __ieee80211_data_to_8023(struct ieee80211_rx_data
*rx
, bool *port_control
)
2457 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2458 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2459 bool check_port_control
= false;
2460 struct ethhdr
*ehdr
;
2463 *port_control
= false;
2464 if (ieee80211_has_a4(hdr
->frame_control
) &&
2465 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&& !sdata
->u
.vlan
.sta
)
2468 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
2469 !!sdata
->u
.mgd
.use_4addr
!= !!ieee80211_has_a4(hdr
->frame_control
)) {
2471 if (!sdata
->u
.mgd
.use_4addr
)
2473 else if (!ether_addr_equal(hdr
->addr1
, sdata
->vif
.addr
))
2474 check_port_control
= true;
2477 if (is_multicast_ether_addr(hdr
->addr1
) &&
2478 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&& sdata
->u
.vlan
.sta
)
2481 ret
= ieee80211_data_to_8023(rx
->skb
, sdata
->vif
.addr
, sdata
->vif
.type
);
2485 ehdr
= (struct ethhdr
*) rx
->skb
->data
;
2486 if (ehdr
->h_proto
== rx
->sdata
->control_port_protocol
)
2487 *port_control
= true;
2488 else if (check_port_control
)
2495 * requires that rx->skb is a frame with ethernet header
2497 static bool ieee80211_frame_allowed(struct ieee80211_rx_data
*rx
, __le16 fc
)
2499 static const u8 pae_group_addr
[ETH_ALEN
] __aligned(2)
2500 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2501 struct ethhdr
*ehdr
= (struct ethhdr
*) rx
->skb
->data
;
2504 * Allow EAPOL frames to us/the PAE group address regardless
2505 * of whether the frame was encrypted or not.
2507 if (ehdr
->h_proto
== rx
->sdata
->control_port_protocol
&&
2508 (ether_addr_equal(ehdr
->h_dest
, rx
->sdata
->vif
.addr
) ||
2509 ether_addr_equal(ehdr
->h_dest
, pae_group_addr
)))
2512 if (ieee80211_802_1x_port_control(rx
) ||
2513 ieee80211_drop_unencrypted(rx
, fc
))
2519 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff
*skb
,
2520 struct ieee80211_rx_data
*rx
)
2522 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2523 struct net_device
*dev
= sdata
->dev
;
2525 if (unlikely((skb
->protocol
== sdata
->control_port_protocol
||
2526 (skb
->protocol
== cpu_to_be16(ETH_P_PREAUTH
) &&
2527 !sdata
->control_port_no_preauth
)) &&
2528 sdata
->control_port_over_nl80211
)) {
2529 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2530 bool noencrypt
= !(status
->flag
& RX_FLAG_DECRYPTED
);
2532 cfg80211_rx_control_port(dev
, skb
, noencrypt
);
2535 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2537 /* deliver to local stack */
2539 list_add_tail(&skb
->list
, rx
->list
);
2541 netif_receive_skb(skb
);
2546 * requires that rx->skb is a frame with ethernet header
2549 ieee80211_deliver_skb(struct ieee80211_rx_data
*rx
)
2551 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2552 struct net_device
*dev
= sdata
->dev
;
2553 struct sk_buff
*skb
, *xmit_skb
;
2554 struct ethhdr
*ehdr
= (struct ethhdr
*) rx
->skb
->data
;
2555 struct sta_info
*dsta
;
2560 dev_sw_netstats_rx_add(dev
, skb
->len
);
2563 /* The seqno index has the same property as needed
2564 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2565 * for non-QoS-data frames. Here we know it's a data
2566 * frame, so count MSDUs.
2568 u64_stats_update_begin(&rx
->sta
->rx_stats
.syncp
);
2569 rx
->sta
->rx_stats
.msdu
[rx
->seqno_idx
]++;
2570 u64_stats_update_end(&rx
->sta
->rx_stats
.syncp
);
2573 if ((sdata
->vif
.type
== NL80211_IFTYPE_AP
||
2574 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) &&
2575 !(sdata
->flags
& IEEE80211_SDATA_DONT_BRIDGE_PACKETS
) &&
2576 (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
|| !sdata
->u
.vlan
.sta
)) {
2577 if (is_multicast_ether_addr(ehdr
->h_dest
) &&
2578 ieee80211_vif_get_num_mcast_if(sdata
) != 0) {
2580 * send multicast frames both to higher layers in
2581 * local net stack and back to the wireless medium
2583 xmit_skb
= skb_copy(skb
, GFP_ATOMIC
);
2585 net_info_ratelimited("%s: failed to clone multicast frame\n",
2587 } else if (!is_multicast_ether_addr(ehdr
->h_dest
) &&
2588 !ether_addr_equal(ehdr
->h_dest
, ehdr
->h_source
)) {
2589 dsta
= sta_info_get(sdata
, ehdr
->h_dest
);
2592 * The destination station is associated to
2593 * this AP (in this VLAN), so send the frame
2594 * directly to it and do not pass it to local
2603 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2605 /* 'align' will only take the values 0 or 2 here since all
2606 * frames are required to be aligned to 2-byte boundaries
2607 * when being passed to mac80211; the code here works just
2608 * as well if that isn't true, but mac80211 assumes it can
2609 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2613 align
= (unsigned long)(skb
->data
+ sizeof(struct ethhdr
)) & 3;
2615 if (WARN_ON(skb_headroom(skb
) < 3)) {
2619 u8
*data
= skb
->data
;
2620 size_t len
= skb_headlen(skb
);
2622 memmove(skb
->data
, data
, len
);
2623 skb_set_tail_pointer(skb
, len
);
2630 skb
->protocol
= eth_type_trans(skb
, dev
);
2631 ieee80211_deliver_skb_to_local_stack(skb
, rx
);
2636 * Send to wireless media and increase priority by 256 to
2637 * keep the received priority instead of reclassifying
2638 * the frame (see cfg80211_classify8021d).
2640 xmit_skb
->priority
+= 256;
2641 xmit_skb
->protocol
= htons(ETH_P_802_3
);
2642 skb_reset_network_header(xmit_skb
);
2643 skb_reset_mac_header(xmit_skb
);
2644 dev_queue_xmit(xmit_skb
);
2648 static ieee80211_rx_result debug_noinline
2649 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data
*rx
, u8 data_offset
)
2651 struct net_device
*dev
= rx
->sdata
->dev
;
2652 struct sk_buff
*skb
= rx
->skb
;
2653 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2654 __le16 fc
= hdr
->frame_control
;
2655 struct sk_buff_head frame_list
;
2656 struct ethhdr ethhdr
;
2657 const u8
*check_da
= ethhdr
.h_dest
, *check_sa
= ethhdr
.h_source
;
2659 if (unlikely(ieee80211_has_a4(hdr
->frame_control
))) {
2662 } else switch (rx
->sdata
->vif
.type
) {
2663 case NL80211_IFTYPE_AP
:
2664 case NL80211_IFTYPE_AP_VLAN
:
2667 case NL80211_IFTYPE_STATION
:
2669 !test_sta_flag(rx
->sta
, WLAN_STA_TDLS_PEER
))
2672 case NL80211_IFTYPE_MESH_POINT
:
2680 __skb_queue_head_init(&frame_list
);
2682 if (ieee80211_data_to_8023_exthdr(skb
, ðhdr
,
2683 rx
->sdata
->vif
.addr
,
2684 rx
->sdata
->vif
.type
,
2686 return RX_DROP_UNUSABLE
;
2688 ieee80211_amsdu_to_8023s(skb
, &frame_list
, dev
->dev_addr
,
2689 rx
->sdata
->vif
.type
,
2690 rx
->local
->hw
.extra_tx_headroom
,
2691 check_da
, check_sa
);
2693 while (!skb_queue_empty(&frame_list
)) {
2694 rx
->skb
= __skb_dequeue(&frame_list
);
2696 if (!ieee80211_frame_allowed(rx
, fc
)) {
2697 dev_kfree_skb(rx
->skb
);
2701 ieee80211_deliver_skb(rx
);
2707 static ieee80211_rx_result debug_noinline
2708 ieee80211_rx_h_amsdu(struct ieee80211_rx_data
*rx
)
2710 struct sk_buff
*skb
= rx
->skb
;
2711 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
2712 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2713 __le16 fc
= hdr
->frame_control
;
2715 if (!(status
->rx_flags
& IEEE80211_RX_AMSDU
))
2718 if (unlikely(!ieee80211_is_data(fc
)))
2721 if (unlikely(!ieee80211_is_data_present(fc
)))
2722 return RX_DROP_MONITOR
;
2724 if (unlikely(ieee80211_has_a4(hdr
->frame_control
))) {
2725 switch (rx
->sdata
->vif
.type
) {
2726 case NL80211_IFTYPE_AP_VLAN
:
2727 if (!rx
->sdata
->u
.vlan
.sta
)
2728 return RX_DROP_UNUSABLE
;
2730 case NL80211_IFTYPE_STATION
:
2731 if (!rx
->sdata
->u
.mgd
.use_4addr
)
2732 return RX_DROP_UNUSABLE
;
2735 return RX_DROP_UNUSABLE
;
2739 if (is_multicast_ether_addr(hdr
->addr1
))
2740 return RX_DROP_UNUSABLE
;
2742 return __ieee80211_rx_h_amsdu(rx
, 0);
2745 #ifdef CONFIG_MAC80211_MESH
2746 static ieee80211_rx_result
2747 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data
*rx
)
2749 struct ieee80211_hdr
*fwd_hdr
, *hdr
;
2750 struct ieee80211_tx_info
*info
;
2751 struct ieee80211s_hdr
*mesh_hdr
;
2752 struct sk_buff
*skb
= rx
->skb
, *fwd_skb
;
2753 struct ieee80211_local
*local
= rx
->local
;
2754 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2755 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
2759 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2760 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
2762 /* make sure fixed part of mesh header is there, also checks skb len */
2763 if (!pskb_may_pull(rx
->skb
, hdrlen
+ 6))
2764 return RX_DROP_MONITOR
;
2766 mesh_hdr
= (struct ieee80211s_hdr
*) (skb
->data
+ hdrlen
);
2768 /* make sure full mesh header is there, also checks skb len */
2769 if (!pskb_may_pull(rx
->skb
,
2770 hdrlen
+ ieee80211_get_mesh_hdrlen(mesh_hdr
)))
2771 return RX_DROP_MONITOR
;
2773 /* reload pointers */
2774 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2775 mesh_hdr
= (struct ieee80211s_hdr
*) (skb
->data
+ hdrlen
);
2777 if (ieee80211_drop_unencrypted(rx
, hdr
->frame_control
))
2778 return RX_DROP_MONITOR
;
2780 /* frame is in RMC, don't forward */
2781 if (ieee80211_is_data(hdr
->frame_control
) &&
2782 is_multicast_ether_addr(hdr
->addr1
) &&
2783 mesh_rmc_check(rx
->sdata
, hdr
->addr3
, mesh_hdr
))
2784 return RX_DROP_MONITOR
;
2786 if (!ieee80211_is_data(hdr
->frame_control
))
2790 return RX_DROP_MONITOR
;
2792 if (mesh_hdr
->flags
& MESH_FLAGS_AE
) {
2793 struct mesh_path
*mppath
;
2797 if (is_multicast_ether_addr(hdr
->addr1
)) {
2798 mpp_addr
= hdr
->addr3
;
2799 proxied_addr
= mesh_hdr
->eaddr1
;
2800 } else if ((mesh_hdr
->flags
& MESH_FLAGS_AE
) ==
2801 MESH_FLAGS_AE_A5_A6
) {
2802 /* has_a4 already checked in ieee80211_rx_mesh_check */
2803 mpp_addr
= hdr
->addr4
;
2804 proxied_addr
= mesh_hdr
->eaddr2
;
2806 return RX_DROP_MONITOR
;
2810 mppath
= mpp_path_lookup(sdata
, proxied_addr
);
2812 mpp_path_add(sdata
, proxied_addr
, mpp_addr
);
2814 spin_lock_bh(&mppath
->state_lock
);
2815 if (!ether_addr_equal(mppath
->mpp
, mpp_addr
))
2816 memcpy(mppath
->mpp
, mpp_addr
, ETH_ALEN
);
2817 mppath
->exp_time
= jiffies
;
2818 spin_unlock_bh(&mppath
->state_lock
);
2823 /* Frame has reached destination. Don't forward */
2824 if (!is_multicast_ether_addr(hdr
->addr1
) &&
2825 ether_addr_equal(sdata
->vif
.addr
, hdr
->addr3
))
2828 ac
= ieee80211_select_queue_80211(sdata
, skb
, hdr
);
2829 q
= sdata
->vif
.hw_queue
[ac
];
2830 if (ieee80211_queue_stopped(&local
->hw
, q
)) {
2831 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, dropped_frames_congestion
);
2832 return RX_DROP_MONITOR
;
2834 skb_set_queue_mapping(skb
, q
);
2836 if (!--mesh_hdr
->ttl
) {
2837 if (!is_multicast_ether_addr(hdr
->addr1
))
2838 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
,
2839 dropped_frames_ttl
);
2843 if (!ifmsh
->mshcfg
.dot11MeshForwarding
)
2846 if (sdata
->crypto_tx_tailroom_needed_cnt
)
2847 tailroom
= IEEE80211_ENCRYPT_TAILROOM
;
2849 fwd_skb
= skb_copy_expand(skb
, local
->tx_headroom
+
2850 sdata
->encrypt_headroom
,
2851 tailroom
, GFP_ATOMIC
);
2855 fwd_hdr
= (struct ieee80211_hdr
*) fwd_skb
->data
;
2856 fwd_hdr
->frame_control
&= ~cpu_to_le16(IEEE80211_FCTL_RETRY
);
2857 info
= IEEE80211_SKB_CB(fwd_skb
);
2858 memset(info
, 0, sizeof(*info
));
2859 info
->control
.flags
|= IEEE80211_TX_INTCFL_NEED_TXPROCESSING
;
2860 info
->control
.vif
= &rx
->sdata
->vif
;
2861 info
->control
.jiffies
= jiffies
;
2862 if (is_multicast_ether_addr(fwd_hdr
->addr1
)) {
2863 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, fwded_mcast
);
2864 memcpy(fwd_hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2865 /* update power mode indication when forwarding */
2866 ieee80211_mps_set_frame_flags(sdata
, NULL
, fwd_hdr
);
2867 } else if (!mesh_nexthop_lookup(sdata
, fwd_skb
)) {
2868 /* mesh power mode flags updated in mesh_nexthop_lookup */
2869 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, fwded_unicast
);
2871 /* unable to resolve next hop */
2872 mesh_path_error_tx(sdata
, ifmsh
->mshcfg
.element_ttl
,
2874 WLAN_REASON_MESH_PATH_NOFORWARD
,
2876 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, dropped_frames_no_route
);
2878 return RX_DROP_MONITOR
;
2881 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh
, fwded_frames
);
2882 ieee80211_add_pending_skb(local
, fwd_skb
);
2884 if (is_multicast_ether_addr(hdr
->addr1
))
2886 return RX_DROP_MONITOR
;
2890 static ieee80211_rx_result debug_noinline
2891 ieee80211_rx_h_data(struct ieee80211_rx_data
*rx
)
2893 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
2894 struct ieee80211_local
*local
= rx
->local
;
2895 struct net_device
*dev
= sdata
->dev
;
2896 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)rx
->skb
->data
;
2897 __le16 fc
= hdr
->frame_control
;
2901 if (unlikely(!ieee80211_is_data(hdr
->frame_control
)))
2904 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
2905 return RX_DROP_MONITOR
;
2908 * Send unexpected-4addr-frame event to hostapd. For older versions,
2909 * also drop the frame to cooked monitor interfaces.
2911 if (ieee80211_has_a4(hdr
->frame_control
) &&
2912 sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
2914 !test_and_set_sta_flag(rx
->sta
, WLAN_STA_4ADDR_EVENT
))
2915 cfg80211_rx_unexpected_4addr_frame(
2916 rx
->sdata
->dev
, rx
->sta
->sta
.addr
, GFP_ATOMIC
);
2917 return RX_DROP_MONITOR
;
2920 err
= __ieee80211_data_to_8023(rx
, &port_control
);
2922 return RX_DROP_UNUSABLE
;
2924 if (!ieee80211_frame_allowed(rx
, fc
))
2925 return RX_DROP_MONITOR
;
2927 /* directly handle TDLS channel switch requests/responses */
2928 if (unlikely(((struct ethhdr
*)rx
->skb
->data
)->h_proto
==
2929 cpu_to_be16(ETH_P_TDLS
))) {
2930 struct ieee80211_tdls_data
*tf
= (void *)rx
->skb
->data
;
2932 if (pskb_may_pull(rx
->skb
,
2933 offsetof(struct ieee80211_tdls_data
, u
)) &&
2934 tf
->payload_type
== WLAN_TDLS_SNAP_RFTYPE
&&
2935 tf
->category
== WLAN_CATEGORY_TDLS
&&
2936 (tf
->action_code
== WLAN_TDLS_CHANNEL_SWITCH_REQUEST
||
2937 tf
->action_code
== WLAN_TDLS_CHANNEL_SWITCH_RESPONSE
)) {
2938 skb_queue_tail(&local
->skb_queue_tdls_chsw
, rx
->skb
);
2939 schedule_work(&local
->tdls_chsw_work
);
2941 rx
->sta
->rx_stats
.packets
++;
2947 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
2948 unlikely(port_control
) && sdata
->bss
) {
2949 sdata
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
,
2957 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
) &&
2958 local
->ps_sdata
&& local
->hw
.conf
.dynamic_ps_timeout
> 0 &&
2959 !is_multicast_ether_addr(
2960 ((struct ethhdr
*)rx
->skb
->data
)->h_dest
) &&
2961 (!local
->scanning
&&
2962 !test_bit(SDATA_STATE_OFFCHANNEL
, &sdata
->state
)))
2963 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
2964 msecs_to_jiffies(local
->hw
.conf
.dynamic_ps_timeout
));
2966 ieee80211_deliver_skb(rx
);
2971 static ieee80211_rx_result debug_noinline
2972 ieee80211_rx_h_ctrl(struct ieee80211_rx_data
*rx
, struct sk_buff_head
*frames
)
2974 struct sk_buff
*skb
= rx
->skb
;
2975 struct ieee80211_bar
*bar
= (struct ieee80211_bar
*)skb
->data
;
2976 struct tid_ampdu_rx
*tid_agg_rx
;
2980 if (likely(!ieee80211_is_ctl(bar
->frame_control
)))
2983 if (ieee80211_is_back_req(bar
->frame_control
)) {
2985 __le16 control
, start_seq_num
;
2986 } __packed bar_data
;
2987 struct ieee80211_event event
= {
2988 .type
= BAR_RX_EVENT
,
2992 return RX_DROP_MONITOR
;
2994 if (skb_copy_bits(skb
, offsetof(struct ieee80211_bar
, control
),
2995 &bar_data
, sizeof(bar_data
)))
2996 return RX_DROP_MONITOR
;
2998 tid
= le16_to_cpu(bar_data
.control
) >> 12;
3000 if (!test_bit(tid
, rx
->sta
->ampdu_mlme
.agg_session_valid
) &&
3001 !test_and_set_bit(tid
, rx
->sta
->ampdu_mlme
.unexpected_agg
))
3002 ieee80211_send_delba(rx
->sdata
, rx
->sta
->sta
.addr
, tid
,
3003 WLAN_BACK_RECIPIENT
,
3004 WLAN_REASON_QSTA_REQUIRE_SETUP
);
3006 tid_agg_rx
= rcu_dereference(rx
->sta
->ampdu_mlme
.tid_rx
[tid
]);
3008 return RX_DROP_MONITOR
;
3010 start_seq_num
= le16_to_cpu(bar_data
.start_seq_num
) >> 4;
3011 event
.u
.ba
.tid
= tid
;
3012 event
.u
.ba
.ssn
= start_seq_num
;
3013 event
.u
.ba
.sta
= &rx
->sta
->sta
;
3015 /* reset session timer */
3016 if (tid_agg_rx
->timeout
)
3017 mod_timer(&tid_agg_rx
->session_timer
,
3018 TU_TO_EXP_TIME(tid_agg_rx
->timeout
));
3020 spin_lock(&tid_agg_rx
->reorder_lock
);
3021 /* release stored frames up to start of BAR */
3022 ieee80211_release_reorder_frames(rx
->sdata
, tid_agg_rx
,
3023 start_seq_num
, frames
);
3024 spin_unlock(&tid_agg_rx
->reorder_lock
);
3026 drv_event_callback(rx
->local
, rx
->sdata
, &event
);
3033 * After this point, we only want management frames,
3034 * so we can drop all remaining control frames to
3035 * cooked monitor interfaces.
3037 return RX_DROP_MONITOR
;
3040 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data
*sdata
,
3041 struct ieee80211_mgmt
*mgmt
,
3044 struct ieee80211_local
*local
= sdata
->local
;
3045 struct sk_buff
*skb
;
3046 struct ieee80211_mgmt
*resp
;
3048 if (!ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
)) {
3049 /* Not to own unicast address */
3053 if (!ether_addr_equal(mgmt
->sa
, sdata
->u
.mgd
.bssid
) ||
3054 !ether_addr_equal(mgmt
->bssid
, sdata
->u
.mgd
.bssid
)) {
3055 /* Not from the current AP or not associated yet. */
3059 if (len
< 24 + 1 + sizeof(resp
->u
.action
.u
.sa_query
)) {
3060 /* Too short SA Query request frame */
3064 skb
= dev_alloc_skb(sizeof(*resp
) + local
->hw
.extra_tx_headroom
);
3068 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3069 resp
= skb_put_zero(skb
, 24);
3070 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
3071 memcpy(resp
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
3072 memcpy(resp
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
3073 resp
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
3074 IEEE80211_STYPE_ACTION
);
3075 skb_put(skb
, 1 + sizeof(resp
->u
.action
.u
.sa_query
));
3076 resp
->u
.action
.category
= WLAN_CATEGORY_SA_QUERY
;
3077 resp
->u
.action
.u
.sa_query
.action
= WLAN_ACTION_SA_QUERY_RESPONSE
;
3078 memcpy(resp
->u
.action
.u
.sa_query
.trans_id
,
3079 mgmt
->u
.action
.u
.sa_query
.trans_id
,
3080 WLAN_SA_QUERY_TR_ID_LEN
);
3082 ieee80211_tx_skb(sdata
, skb
);
3085 static ieee80211_rx_result debug_noinline
3086 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data
*rx
)
3088 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
3089 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
3091 if (ieee80211_is_s1g_beacon(mgmt
->frame_control
))
3095 * From here on, look only at management frames.
3096 * Data and control frames are already handled,
3097 * and unknown (reserved) frames are useless.
3099 if (rx
->skb
->len
< 24)
3100 return RX_DROP_MONITOR
;
3102 if (!ieee80211_is_mgmt(mgmt
->frame_control
))
3103 return RX_DROP_MONITOR
;
3105 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
&&
3106 ieee80211_is_beacon(mgmt
->frame_control
) &&
3107 !(rx
->flags
& IEEE80211_RX_BEACON_REPORTED
)) {
3110 if (ieee80211_hw_check(&rx
->local
->hw
, SIGNAL_DBM
) &&
3111 !(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
))
3112 sig
= status
->signal
;
3114 cfg80211_report_obss_beacon_khz(rx
->local
->hw
.wiphy
,
3115 rx
->skb
->data
, rx
->skb
->len
,
3116 ieee80211_rx_status_to_khz(status
),
3118 rx
->flags
|= IEEE80211_RX_BEACON_REPORTED
;
3121 if (ieee80211_drop_unencrypted_mgmt(rx
))
3122 return RX_DROP_UNUSABLE
;
3127 static ieee80211_rx_result debug_noinline
3128 ieee80211_rx_h_action(struct ieee80211_rx_data
*rx
)
3130 struct ieee80211_local
*local
= rx
->local
;
3131 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3132 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
3133 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
3134 int len
= rx
->skb
->len
;
3136 if (!ieee80211_is_action(mgmt
->frame_control
))
3139 /* drop too small frames */
3140 if (len
< IEEE80211_MIN_ACTION_SIZE
)
3141 return RX_DROP_UNUSABLE
;
3143 if (!rx
->sta
&& mgmt
->u
.action
.category
!= WLAN_CATEGORY_PUBLIC
&&
3144 mgmt
->u
.action
.category
!= WLAN_CATEGORY_SELF_PROTECTED
&&
3145 mgmt
->u
.action
.category
!= WLAN_CATEGORY_SPECTRUM_MGMT
)
3146 return RX_DROP_UNUSABLE
;
3148 switch (mgmt
->u
.action
.category
) {
3149 case WLAN_CATEGORY_HT
:
3150 /* reject HT action frames from stations not supporting HT */
3151 if (!rx
->sta
->sta
.ht_cap
.ht_supported
)
3154 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3155 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
&&
3156 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
3157 sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
3158 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
3161 /* verify action & smps_control/chanwidth are present */
3162 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 2)
3165 switch (mgmt
->u
.action
.u
.ht_smps
.action
) {
3166 case WLAN_HT_ACTION_SMPS
: {
3167 struct ieee80211_supported_band
*sband
;
3168 enum ieee80211_smps_mode smps_mode
;
3169 struct sta_opmode_info sta_opmode
= {};
3171 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
3172 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
)
3175 /* convert to HT capability */
3176 switch (mgmt
->u
.action
.u
.ht_smps
.smps_control
) {
3177 case WLAN_HT_SMPS_CONTROL_DISABLED
:
3178 smps_mode
= IEEE80211_SMPS_OFF
;
3180 case WLAN_HT_SMPS_CONTROL_STATIC
:
3181 smps_mode
= IEEE80211_SMPS_STATIC
;
3183 case WLAN_HT_SMPS_CONTROL_DYNAMIC
:
3184 smps_mode
= IEEE80211_SMPS_DYNAMIC
;
3190 /* if no change do nothing */
3191 if (rx
->sta
->sta
.smps_mode
== smps_mode
)
3193 rx
->sta
->sta
.smps_mode
= smps_mode
;
3194 sta_opmode
.smps_mode
=
3195 ieee80211_smps_mode_to_smps_mode(smps_mode
);
3196 sta_opmode
.changed
= STA_OPMODE_SMPS_MODE_CHANGED
;
3198 sband
= rx
->local
->hw
.wiphy
->bands
[status
->band
];
3200 rate_control_rate_update(local
, sband
, rx
->sta
,
3201 IEEE80211_RC_SMPS_CHANGED
);
3202 cfg80211_sta_opmode_change_notify(sdata
->dev
,
3208 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH
: {
3209 struct ieee80211_supported_band
*sband
;
3210 u8 chanwidth
= mgmt
->u
.action
.u
.ht_notify_cw
.chanwidth
;
3211 enum ieee80211_sta_rx_bandwidth max_bw
, new_bw
;
3212 struct sta_opmode_info sta_opmode
= {};
3214 /* If it doesn't support 40 MHz it can't change ... */
3215 if (!(rx
->sta
->sta
.ht_cap
.cap
&
3216 IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
3219 if (chanwidth
== IEEE80211_HT_CHANWIDTH_20MHZ
)
3220 max_bw
= IEEE80211_STA_RX_BW_20
;
3222 max_bw
= ieee80211_sta_cap_rx_bw(rx
->sta
);
3224 /* set cur_max_bandwidth and recalc sta bw */
3225 rx
->sta
->cur_max_bandwidth
= max_bw
;
3226 new_bw
= ieee80211_sta_cur_vht_bw(rx
->sta
);
3228 if (rx
->sta
->sta
.bandwidth
== new_bw
)
3231 rx
->sta
->sta
.bandwidth
= new_bw
;
3232 sband
= rx
->local
->hw
.wiphy
->bands
[status
->band
];
3234 ieee80211_sta_rx_bw_to_chan_width(rx
->sta
);
3235 sta_opmode
.changed
= STA_OPMODE_MAX_BW_CHANGED
;
3237 rate_control_rate_update(local
, sband
, rx
->sta
,
3238 IEEE80211_RC_BW_CHANGED
);
3239 cfg80211_sta_opmode_change_notify(sdata
->dev
,
3250 case WLAN_CATEGORY_PUBLIC
:
3251 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3253 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3257 if (!ether_addr_equal(mgmt
->bssid
, sdata
->u
.mgd
.bssid
))
3259 if (mgmt
->u
.action
.u
.ext_chan_switch
.action_code
!=
3260 WLAN_PUB_ACTION_EXT_CHANSW_ANN
)
3262 if (len
< offsetof(struct ieee80211_mgmt
,
3263 u
.action
.u
.ext_chan_switch
.variable
))
3266 case WLAN_CATEGORY_VHT
:
3267 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3268 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
&&
3269 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
3270 sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
3271 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
3274 /* verify action code is present */
3275 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3278 switch (mgmt
->u
.action
.u
.vht_opmode_notif
.action_code
) {
3279 case WLAN_VHT_ACTION_OPMODE_NOTIF
: {
3280 /* verify opmode is present */
3281 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 2)
3285 case WLAN_VHT_ACTION_GROUPID_MGMT
: {
3286 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 25)
3294 case WLAN_CATEGORY_BACK
:
3295 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3296 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
&&
3297 sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
3298 sdata
->vif
.type
!= NL80211_IFTYPE_AP
&&
3299 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
3302 /* verify action_code is present */
3303 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3306 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
3307 case WLAN_ACTION_ADDBA_REQ
:
3308 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3309 sizeof(mgmt
->u
.action
.u
.addba_req
)))
3312 case WLAN_ACTION_ADDBA_RESP
:
3313 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3314 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
3317 case WLAN_ACTION_DELBA
:
3318 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3319 sizeof(mgmt
->u
.action
.u
.delba
)))
3327 case WLAN_CATEGORY_SPECTRUM_MGMT
:
3328 /* verify action_code is present */
3329 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
3332 switch (mgmt
->u
.action
.u
.measurement
.action_code
) {
3333 case WLAN_ACTION_SPCT_MSR_REQ
:
3334 if (status
->band
!= NL80211_BAND_5GHZ
)
3337 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3338 sizeof(mgmt
->u
.action
.u
.measurement
)))
3341 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3344 ieee80211_process_measurement_req(sdata
, mgmt
, len
);
3346 case WLAN_ACTION_SPCT_CHL_SWITCH
: {
3348 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3349 sizeof(mgmt
->u
.action
.u
.chan_switch
)))
3352 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3353 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
3354 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
3357 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
3358 bssid
= sdata
->u
.mgd
.bssid
;
3359 else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
)
3360 bssid
= sdata
->u
.ibss
.bssid
;
3361 else if (sdata
->vif
.type
== NL80211_IFTYPE_MESH_POINT
)
3366 if (!ether_addr_equal(mgmt
->bssid
, bssid
))
3373 case WLAN_CATEGORY_SELF_PROTECTED
:
3374 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3375 sizeof(mgmt
->u
.action
.u
.self_prot
.action_code
)))
3378 switch (mgmt
->u
.action
.u
.self_prot
.action_code
) {
3379 case WLAN_SP_MESH_PEERING_OPEN
:
3380 case WLAN_SP_MESH_PEERING_CLOSE
:
3381 case WLAN_SP_MESH_PEERING_CONFIRM
:
3382 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
3384 if (sdata
->u
.mesh
.user_mpm
)
3385 /* userspace handles this frame */
3388 case WLAN_SP_MGK_INFORM
:
3389 case WLAN_SP_MGK_ACK
:
3390 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
3395 case WLAN_CATEGORY_MESH_ACTION
:
3396 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3397 sizeof(mgmt
->u
.action
.u
.mesh_action
.action_code
)))
3400 if (!ieee80211_vif_is_mesh(&sdata
->vif
))
3402 if (mesh_action_is_path_sel(mgmt
) &&
3403 !mesh_path_sel_is_hwmp(sdata
))
3411 status
->rx_flags
|= IEEE80211_RX_MALFORMED_ACTION_FRM
;
3412 /* will return in the next handlers */
3417 rx
->sta
->rx_stats
.packets
++;
3418 dev_kfree_skb(rx
->skb
);
3422 skb_queue_tail(&sdata
->skb_queue
, rx
->skb
);
3423 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
3425 rx
->sta
->rx_stats
.packets
++;
3429 static ieee80211_rx_result debug_noinline
3430 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data
*rx
)
3432 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
3435 /* skip known-bad action frames and return them in the next handler */
3436 if (status
->rx_flags
& IEEE80211_RX_MALFORMED_ACTION_FRM
)
3440 * Getting here means the kernel doesn't know how to handle
3441 * it, but maybe userspace does ... include returned frames
3442 * so userspace can register for those to know whether ones
3443 * it transmitted were processed or returned.
3446 if (ieee80211_hw_check(&rx
->local
->hw
, SIGNAL_DBM
) &&
3447 !(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
))
3448 sig
= status
->signal
;
3450 if (cfg80211_rx_mgmt_khz(&rx
->sdata
->wdev
,
3451 ieee80211_rx_status_to_khz(status
), sig
,
3452 rx
->skb
->data
, rx
->skb
->len
, 0)) {
3454 rx
->sta
->rx_stats
.packets
++;
3455 dev_kfree_skb(rx
->skb
);
3462 static ieee80211_rx_result debug_noinline
3463 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data
*rx
)
3465 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3466 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
3467 int len
= rx
->skb
->len
;
3469 if (!ieee80211_is_action(mgmt
->frame_control
))
3472 switch (mgmt
->u
.action
.category
) {
3473 case WLAN_CATEGORY_SA_QUERY
:
3474 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3475 sizeof(mgmt
->u
.action
.u
.sa_query
)))
3478 switch (mgmt
->u
.action
.u
.sa_query
.action
) {
3479 case WLAN_ACTION_SA_QUERY_REQUEST
:
3480 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3482 ieee80211_process_sa_query_req(sdata
, mgmt
, len
);
3492 rx
->sta
->rx_stats
.packets
++;
3493 dev_kfree_skb(rx
->skb
);
3497 static ieee80211_rx_result debug_noinline
3498 ieee80211_rx_h_action_return(struct ieee80211_rx_data
*rx
)
3500 struct ieee80211_local
*local
= rx
->local
;
3501 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*) rx
->skb
->data
;
3502 struct sk_buff
*nskb
;
3503 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3504 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
3506 if (!ieee80211_is_action(mgmt
->frame_control
))
3510 * For AP mode, hostapd is responsible for handling any action
3511 * frames that we didn't handle, including returning unknown
3512 * ones. For all other modes we will return them to the sender,
3513 * setting the 0x80 bit in the action category, as required by
3514 * 802.11-2012 9.24.4.
3515 * Newer versions of hostapd shall also use the management frame
3516 * registration mechanisms, but older ones still use cooked
3517 * monitor interfaces so push all frames there.
3519 if (!(status
->rx_flags
& IEEE80211_RX_MALFORMED_ACTION_FRM
) &&
3520 (sdata
->vif
.type
== NL80211_IFTYPE_AP
||
3521 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
))
3522 return RX_DROP_MONITOR
;
3524 if (is_multicast_ether_addr(mgmt
->da
))
3525 return RX_DROP_MONITOR
;
3527 /* do not return rejected action frames */
3528 if (mgmt
->u
.action
.category
& 0x80)
3529 return RX_DROP_UNUSABLE
;
3531 nskb
= skb_copy_expand(rx
->skb
, local
->hw
.extra_tx_headroom
, 0,
3534 struct ieee80211_mgmt
*nmgmt
= (void *)nskb
->data
;
3536 nmgmt
->u
.action
.category
|= 0x80;
3537 memcpy(nmgmt
->da
, nmgmt
->sa
, ETH_ALEN
);
3538 memcpy(nmgmt
->sa
, rx
->sdata
->vif
.addr
, ETH_ALEN
);
3540 memset(nskb
->cb
, 0, sizeof(nskb
->cb
));
3542 if (rx
->sdata
->vif
.type
== NL80211_IFTYPE_P2P_DEVICE
) {
3543 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(nskb
);
3545 info
->flags
= IEEE80211_TX_CTL_TX_OFFCHAN
|
3546 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
|
3547 IEEE80211_TX_CTL_NO_CCK_RATE
;
3548 if (ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
))
3550 local
->hw
.offchannel_tx_hw_queue
;
3553 __ieee80211_tx_skb_tid_band(rx
->sdata
, nskb
, 7,
3556 dev_kfree_skb(rx
->skb
);
3560 static ieee80211_rx_result debug_noinline
3561 ieee80211_rx_h_ext(struct ieee80211_rx_data
*rx
)
3563 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3564 struct ieee80211_hdr
*hdr
= (void *)rx
->skb
->data
;
3566 if (!ieee80211_is_ext(hdr
->frame_control
))
3569 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3570 return RX_DROP_MONITOR
;
3572 /* for now only beacons are ext, so queue them */
3573 skb_queue_tail(&sdata
->skb_queue
, rx
->skb
);
3574 ieee80211_queue_work(&rx
->local
->hw
, &sdata
->work
);
3576 rx
->sta
->rx_stats
.packets
++;
3581 static ieee80211_rx_result debug_noinline
3582 ieee80211_rx_h_mgmt(struct ieee80211_rx_data
*rx
)
3584 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3585 struct ieee80211_mgmt
*mgmt
= (void *)rx
->skb
->data
;
3588 stype
= mgmt
->frame_control
& cpu_to_le16(IEEE80211_FCTL_STYPE
);
3590 if (!ieee80211_vif_is_mesh(&sdata
->vif
) &&
3591 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
3592 sdata
->vif
.type
!= NL80211_IFTYPE_OCB
&&
3593 sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3594 return RX_DROP_MONITOR
;
3597 case cpu_to_le16(IEEE80211_STYPE_AUTH
):
3598 case cpu_to_le16(IEEE80211_STYPE_BEACON
):
3599 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
):
3600 /* process for all: mesh, mlme, ibss */
3602 case cpu_to_le16(IEEE80211_STYPE_DEAUTH
):
3603 if (is_multicast_ether_addr(mgmt
->da
) &&
3604 !is_broadcast_ether_addr(mgmt
->da
))
3605 return RX_DROP_MONITOR
;
3607 /* process only for station/IBSS */
3608 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
3609 sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
3610 return RX_DROP_MONITOR
;
3612 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
):
3613 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP
):
3614 case cpu_to_le16(IEEE80211_STYPE_DISASSOC
):
3615 if (is_multicast_ether_addr(mgmt
->da
) &&
3616 !is_broadcast_ether_addr(mgmt
->da
))
3617 return RX_DROP_MONITOR
;
3619 /* process only for station */
3620 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3621 return RX_DROP_MONITOR
;
3623 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
):
3624 /* process only for ibss and mesh */
3625 if (sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
3626 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
3627 return RX_DROP_MONITOR
;
3630 return RX_DROP_MONITOR
;
3633 /* queue up frame and kick off work to process it */
3634 skb_queue_tail(&sdata
->skb_queue
, rx
->skb
);
3635 ieee80211_queue_work(&rx
->local
->hw
, &sdata
->work
);
3637 rx
->sta
->rx_stats
.packets
++;
3642 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data
*rx
,
3643 struct ieee80211_rate
*rate
)
3645 struct ieee80211_sub_if_data
*sdata
;
3646 struct ieee80211_local
*local
= rx
->local
;
3647 struct sk_buff
*skb
= rx
->skb
, *skb2
;
3648 struct net_device
*prev_dev
= NULL
;
3649 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
3650 int needed_headroom
;
3653 * If cooked monitor has been processed already, then
3654 * don't do it again. If not, set the flag.
3656 if (rx
->flags
& IEEE80211_RX_CMNTR
)
3658 rx
->flags
|= IEEE80211_RX_CMNTR
;
3660 /* If there are no cooked monitor interfaces, just free the SKB */
3661 if (!local
->cooked_mntrs
)
3664 /* vendor data is long removed here */
3665 status
->flag
&= ~RX_FLAG_RADIOTAP_VENDOR_DATA
;
3666 /* room for the radiotap header based on driver features */
3667 needed_headroom
= ieee80211_rx_radiotap_hdrlen(local
, status
, skb
);
3669 if (skb_headroom(skb
) < needed_headroom
&&
3670 pskb_expand_head(skb
, needed_headroom
, 0, GFP_ATOMIC
))
3673 /* prepend radiotap information */
3674 ieee80211_add_rx_radiotap_header(local
, skb
, rate
, needed_headroom
,
3677 skb_reset_mac_header(skb
);
3678 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3679 skb
->pkt_type
= PACKET_OTHERHOST
;
3680 skb
->protocol
= htons(ETH_P_802_2
);
3682 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3683 if (!ieee80211_sdata_running(sdata
))
3686 if (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
||
3687 !(sdata
->u
.mntr
.flags
& MONITOR_FLAG_COOK_FRAMES
))
3691 skb2
= skb_clone(skb
, GFP_ATOMIC
);
3693 skb2
->dev
= prev_dev
;
3694 netif_receive_skb(skb2
);
3698 prev_dev
= sdata
->dev
;
3699 dev_sw_netstats_rx_add(sdata
->dev
, skb
->len
);
3703 skb
->dev
= prev_dev
;
3704 netif_receive_skb(skb
);
3712 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data
*rx
,
3713 ieee80211_rx_result res
)
3716 case RX_DROP_MONITOR
:
3717 I802_DEBUG_INC(rx
->sdata
->local
->rx_handlers_drop
);
3719 rx
->sta
->rx_stats
.dropped
++;
3722 struct ieee80211_rate
*rate
= NULL
;
3723 struct ieee80211_supported_band
*sband
;
3724 struct ieee80211_rx_status
*status
;
3726 status
= IEEE80211_SKB_RXCB((rx
->skb
));
3728 sband
= rx
->local
->hw
.wiphy
->bands
[status
->band
];
3729 if (status
->encoding
== RX_ENC_LEGACY
)
3730 rate
= &sband
->bitrates
[status
->rate_idx
];
3732 ieee80211_rx_cooked_monitor(rx
, rate
);
3735 case RX_DROP_UNUSABLE
:
3736 I802_DEBUG_INC(rx
->sdata
->local
->rx_handlers_drop
);
3738 rx
->sta
->rx_stats
.dropped
++;
3739 dev_kfree_skb(rx
->skb
);
3742 I802_DEBUG_INC(rx
->sdata
->local
->rx_handlers_queued
);
3747 static void ieee80211_rx_handlers(struct ieee80211_rx_data
*rx
,
3748 struct sk_buff_head
*frames
)
3750 ieee80211_rx_result res
= RX_DROP_MONITOR
;
3751 struct sk_buff
*skb
;
3753 #define CALL_RXH(rxh) \
3756 if (res != RX_CONTINUE) \
3760 /* Lock here to avoid hitting all of the data used in the RX
3761 * path (e.g. key data, station data, ...) concurrently when
3762 * a frame is released from the reorder buffer due to timeout
3763 * from the timer, potentially concurrently with RX from the
3766 spin_lock_bh(&rx
->local
->rx_path_lock
);
3768 while ((skb
= __skb_dequeue(frames
))) {
3770 * all the other fields are valid across frames
3771 * that belong to an aMPDU since they are on the
3772 * same TID from the same station
3776 CALL_RXH(ieee80211_rx_h_check_more_data
);
3777 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll
);
3778 CALL_RXH(ieee80211_rx_h_sta_process
);
3779 CALL_RXH(ieee80211_rx_h_decrypt
);
3780 CALL_RXH(ieee80211_rx_h_defragment
);
3781 CALL_RXH(ieee80211_rx_h_michael_mic_verify
);
3782 /* must be after MMIC verify so header is counted in MPDU mic */
3783 #ifdef CONFIG_MAC80211_MESH
3784 if (ieee80211_vif_is_mesh(&rx
->sdata
->vif
))
3785 CALL_RXH(ieee80211_rx_h_mesh_fwding
);
3787 CALL_RXH(ieee80211_rx_h_amsdu
);
3788 CALL_RXH(ieee80211_rx_h_data
);
3790 /* special treatment -- needs the queue */
3791 res
= ieee80211_rx_h_ctrl(rx
, frames
);
3792 if (res
!= RX_CONTINUE
)
3795 CALL_RXH(ieee80211_rx_h_mgmt_check
);
3796 CALL_RXH(ieee80211_rx_h_action
);
3797 CALL_RXH(ieee80211_rx_h_userspace_mgmt
);
3798 CALL_RXH(ieee80211_rx_h_action_post_userspace
);
3799 CALL_RXH(ieee80211_rx_h_action_return
);
3800 CALL_RXH(ieee80211_rx_h_ext
);
3801 CALL_RXH(ieee80211_rx_h_mgmt
);
3804 ieee80211_rx_handlers_result(rx
, res
);
3809 spin_unlock_bh(&rx
->local
->rx_path_lock
);
3812 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data
*rx
)
3814 struct sk_buff_head reorder_release
;
3815 ieee80211_rx_result res
= RX_DROP_MONITOR
;
3817 __skb_queue_head_init(&reorder_release
);
3819 #define CALL_RXH(rxh) \
3822 if (res != RX_CONTINUE) \
3826 CALL_RXH(ieee80211_rx_h_check_dup
);
3827 CALL_RXH(ieee80211_rx_h_check
);
3829 ieee80211_rx_reorder_ampdu(rx
, &reorder_release
);
3831 ieee80211_rx_handlers(rx
, &reorder_release
);
3835 ieee80211_rx_handlers_result(rx
, res
);
3841 * This function makes calls into the RX path, therefore
3842 * it has to be invoked under RCU read lock.
3844 void ieee80211_release_reorder_timeout(struct sta_info
*sta
, int tid
)
3846 struct sk_buff_head frames
;
3847 struct ieee80211_rx_data rx
= {
3849 .sdata
= sta
->sdata
,
3850 .local
= sta
->local
,
3851 /* This is OK -- must be QoS data frame */
3852 .security_idx
= tid
,
3855 struct tid_ampdu_rx
*tid_agg_rx
;
3857 tid_agg_rx
= rcu_dereference(sta
->ampdu_mlme
.tid_rx
[tid
]);
3861 __skb_queue_head_init(&frames
);
3863 spin_lock(&tid_agg_rx
->reorder_lock
);
3864 ieee80211_sta_reorder_release(sta
->sdata
, tid_agg_rx
, &frames
);
3865 spin_unlock(&tid_agg_rx
->reorder_lock
);
3867 if (!skb_queue_empty(&frames
)) {
3868 struct ieee80211_event event
= {
3869 .type
= BA_FRAME_TIMEOUT
,
3871 .u
.ba
.sta
= &sta
->sta
,
3873 drv_event_callback(rx
.local
, rx
.sdata
, &event
);
3876 ieee80211_rx_handlers(&rx
, &frames
);
3879 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta
*pubsta
, u8 tid
,
3880 u16 ssn
, u64 filtered
,
3883 struct sta_info
*sta
;
3884 struct tid_ampdu_rx
*tid_agg_rx
;
3885 struct sk_buff_head frames
;
3886 struct ieee80211_rx_data rx
= {
3887 /* This is OK -- must be QoS data frame */
3888 .security_idx
= tid
,
3893 if (WARN_ON(!pubsta
|| tid
>= IEEE80211_NUM_TIDS
))
3896 __skb_queue_head_init(&frames
);
3898 sta
= container_of(pubsta
, struct sta_info
, sta
);
3901 rx
.sdata
= sta
->sdata
;
3902 rx
.local
= sta
->local
;
3905 tid_agg_rx
= rcu_dereference(sta
->ampdu_mlme
.tid_rx
[tid
]);
3909 spin_lock_bh(&tid_agg_rx
->reorder_lock
);
3911 if (received_mpdus
>= IEEE80211_SN_MODULO
>> 1) {
3914 /* release all frames in the reorder buffer */
3915 release
= (tid_agg_rx
->head_seq_num
+ tid_agg_rx
->buf_size
) %
3916 IEEE80211_SN_MODULO
;
3917 ieee80211_release_reorder_frames(sta
->sdata
, tid_agg_rx
,
3919 /* update ssn to match received ssn */
3920 tid_agg_rx
->head_seq_num
= ssn
;
3922 ieee80211_release_reorder_frames(sta
->sdata
, tid_agg_rx
, ssn
,
3926 /* handle the case that received ssn is behind the mac ssn.
3927 * it can be tid_agg_rx->buf_size behind and still be valid */
3928 diff
= (tid_agg_rx
->head_seq_num
- ssn
) & IEEE80211_SN_MASK
;
3929 if (diff
>= tid_agg_rx
->buf_size
) {
3930 tid_agg_rx
->reorder_buf_filtered
= 0;
3933 filtered
= filtered
>> diff
;
3937 for (i
= 0; i
< tid_agg_rx
->buf_size
; i
++) {
3938 int index
= (ssn
+ i
) % tid_agg_rx
->buf_size
;
3940 tid_agg_rx
->reorder_buf_filtered
&= ~BIT_ULL(index
);
3941 if (filtered
& BIT_ULL(i
))
3942 tid_agg_rx
->reorder_buf_filtered
|= BIT_ULL(index
);
3945 /* now process also frames that the filter marking released */
3946 ieee80211_sta_reorder_release(sta
->sdata
, tid_agg_rx
, &frames
);
3949 spin_unlock_bh(&tid_agg_rx
->reorder_lock
);
3951 ieee80211_rx_handlers(&rx
, &frames
);
3956 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames
);
3958 /* main receive path */
3960 static bool ieee80211_accept_frame(struct ieee80211_rx_data
*rx
)
3962 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
3963 struct sk_buff
*skb
= rx
->skb
;
3964 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3965 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
3966 u8
*bssid
= ieee80211_get_bssid(hdr
, skb
->len
, sdata
->vif
.type
);
3967 bool multicast
= is_multicast_ether_addr(hdr
->addr1
) ||
3968 ieee80211_is_s1g_beacon(hdr
->frame_control
);
3970 switch (sdata
->vif
.type
) {
3971 case NL80211_IFTYPE_STATION
:
3972 if (!bssid
&& !sdata
->u
.mgd
.use_4addr
)
3974 if (ieee80211_is_robust_mgmt_frame(skb
) && !rx
->sta
)
3978 return ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
);
3979 case NL80211_IFTYPE_ADHOC
:
3982 if (ether_addr_equal(sdata
->vif
.addr
, hdr
->addr2
) ||
3983 ether_addr_equal(sdata
->u
.ibss
.bssid
, hdr
->addr2
))
3985 if (ieee80211_is_beacon(hdr
->frame_control
))
3987 if (!ieee80211_bssid_match(bssid
, sdata
->u
.ibss
.bssid
))
3990 !ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
))
3994 if (status
->encoding
!= RX_ENC_LEGACY
)
3995 rate_idx
= 0; /* TODO: HT/VHT rates */
3997 rate_idx
= status
->rate_idx
;
3998 ieee80211_ibss_rx_no_sta(sdata
, bssid
, hdr
->addr2
,
4002 case NL80211_IFTYPE_OCB
:
4005 if (!ieee80211_is_data_present(hdr
->frame_control
))
4007 if (!is_broadcast_ether_addr(bssid
))
4010 !ether_addr_equal(sdata
->dev
->dev_addr
, hdr
->addr1
))
4014 if (status
->encoding
!= RX_ENC_LEGACY
)
4015 rate_idx
= 0; /* TODO: HT rates */
4017 rate_idx
= status
->rate_idx
;
4018 ieee80211_ocb_rx_no_sta(sdata
, bssid
, hdr
->addr2
,
4022 case NL80211_IFTYPE_MESH_POINT
:
4023 if (ether_addr_equal(sdata
->vif
.addr
, hdr
->addr2
))
4027 return ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
);
4028 case NL80211_IFTYPE_AP_VLAN
:
4029 case NL80211_IFTYPE_AP
:
4031 return ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
);
4033 if (!ieee80211_bssid_match(bssid
, sdata
->vif
.addr
)) {
4035 * Accept public action frames even when the
4036 * BSSID doesn't match, this is used for P2P
4037 * and location updates. Note that mac80211
4038 * itself never looks at these frames.
4041 !ether_addr_equal(sdata
->vif
.addr
, hdr
->addr1
))
4043 if (ieee80211_is_public_action(hdr
, skb
->len
))
4045 return ieee80211_is_beacon(hdr
->frame_control
);
4048 if (!ieee80211_has_tods(hdr
->frame_control
)) {
4049 /* ignore data frames to TDLS-peers */
4050 if (ieee80211_is_data(hdr
->frame_control
))
4052 /* ignore action frames to TDLS-peers */
4053 if (ieee80211_is_action(hdr
->frame_control
) &&
4054 !is_broadcast_ether_addr(bssid
) &&
4055 !ether_addr_equal(bssid
, hdr
->addr1
))
4060 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4061 * the BSSID - we've checked that already but may have accepted
4062 * the wildcard (ff:ff:ff:ff:ff:ff).
4065 * The BSSID of the Data frame is determined as follows:
4066 * a) If the STA is contained within an AP or is associated
4067 * with an AP, the BSSID is the address currently in use
4068 * by the STA contained in the AP.
4070 * So we should not accept data frames with an address that's
4073 * Accepting it also opens a security problem because stations
4074 * could encrypt it with the GTK and inject traffic that way.
4076 if (ieee80211_is_data(hdr
->frame_control
) && multicast
)
4080 case NL80211_IFTYPE_P2P_DEVICE
:
4081 return ieee80211_is_public_action(hdr
, skb
->len
) ||
4082 ieee80211_is_probe_req(hdr
->frame_control
) ||
4083 ieee80211_is_probe_resp(hdr
->frame_control
) ||
4084 ieee80211_is_beacon(hdr
->frame_control
);
4085 case NL80211_IFTYPE_NAN
:
4086 /* Currently no frames on NAN interface are allowed */
4096 void ieee80211_check_fast_rx(struct sta_info
*sta
)
4098 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
4099 struct ieee80211_local
*local
= sdata
->local
;
4100 struct ieee80211_key
*key
;
4101 struct ieee80211_fast_rx fastrx
= {
4103 .vif_type
= sdata
->vif
.type
,
4104 .control_port_protocol
= sdata
->control_port_protocol
,
4105 }, *old
, *new = NULL
;
4106 bool set_offload
= false;
4107 bool assign
= false;
4110 /* use sparse to check that we don't return without updating */
4111 __acquire(check_fast_rx
);
4113 BUILD_BUG_ON(sizeof(fastrx
.rfc1042_hdr
) != sizeof(rfc1042_header
));
4114 BUILD_BUG_ON(sizeof(fastrx
.rfc1042_hdr
) != ETH_ALEN
);
4115 ether_addr_copy(fastrx
.rfc1042_hdr
, rfc1042_header
);
4116 ether_addr_copy(fastrx
.vif_addr
, sdata
->vif
.addr
);
4118 fastrx
.uses_rss
= ieee80211_hw_check(&local
->hw
, USES_RSS
);
4120 /* fast-rx doesn't do reordering */
4121 if (ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
) &&
4122 !ieee80211_hw_check(&local
->hw
, SUPPORTS_REORDERING_BUFFER
))
4125 switch (sdata
->vif
.type
) {
4126 case NL80211_IFTYPE_STATION
:
4127 if (sta
->sta
.tdls
) {
4128 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
4129 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
4130 fastrx
.expected_ds_bits
= 0;
4132 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
4133 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr3
);
4134 fastrx
.expected_ds_bits
=
4135 cpu_to_le16(IEEE80211_FCTL_FROMDS
);
4138 if (sdata
->u
.mgd
.use_4addr
&& !sta
->sta
.tdls
) {
4139 fastrx
.expected_ds_bits
|=
4140 cpu_to_le16(IEEE80211_FCTL_TODS
);
4141 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
4142 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
4145 if (!sdata
->u
.mgd
.powersave
)
4148 /* software powersave is a huge mess, avoid all of it */
4149 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
))
4151 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
) &&
4152 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
))
4155 case NL80211_IFTYPE_AP_VLAN
:
4156 case NL80211_IFTYPE_AP
:
4157 /* parallel-rx requires this, at least with calls to
4158 * ieee80211_sta_ps_transition()
4160 if (!ieee80211_hw_check(&local
->hw
, AP_LINK_PS
))
4162 fastrx
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
4163 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
4164 fastrx
.expected_ds_bits
= cpu_to_le16(IEEE80211_FCTL_TODS
);
4166 fastrx
.internal_forward
=
4167 !(sdata
->flags
& IEEE80211_SDATA_DONT_BRIDGE_PACKETS
) &&
4168 (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
||
4169 !sdata
->u
.vlan
.sta
);
4171 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
4172 sdata
->u
.vlan
.sta
) {
4173 fastrx
.expected_ds_bits
|=
4174 cpu_to_le16(IEEE80211_FCTL_FROMDS
);
4175 fastrx
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
4176 fastrx
.internal_forward
= 0;
4184 if (!test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
4188 key
= rcu_dereference(sta
->ptk
[sta
->ptk_idx
]);
4190 key
= rcu_dereference(sdata
->default_unicast_key
);
4192 switch (key
->conf
.cipher
) {
4193 case WLAN_CIPHER_SUITE_TKIP
:
4194 /* we don't want to deal with MMIC in fast-rx */
4196 case WLAN_CIPHER_SUITE_CCMP
:
4197 case WLAN_CIPHER_SUITE_CCMP_256
:
4198 case WLAN_CIPHER_SUITE_GCMP
:
4199 case WLAN_CIPHER_SUITE_GCMP_256
:
4202 /* We also don't want to deal with
4203 * WEP or cipher scheme.
4209 fastrx
.icv_len
= key
->conf
.icv_len
;
4216 __release(check_fast_rx
);
4219 new = kmemdup(&fastrx
, sizeof(fastrx
), GFP_KERNEL
);
4222 (sdata
->vif
.offload_flags
& IEEE80211_OFFLOAD_DECAP_ENABLED
);
4225 set_offload
= !test_and_set_sta_flag(sta
, WLAN_STA_DECAP_OFFLOAD
);
4227 set_offload
= test_and_clear_sta_flag(sta
, WLAN_STA_DECAP_OFFLOAD
);
4230 drv_sta_set_decap_offload(local
, sdata
, &sta
->sta
, assign
);
4232 spin_lock_bh(&sta
->lock
);
4233 old
= rcu_dereference_protected(sta
->fast_rx
, true);
4234 rcu_assign_pointer(sta
->fast_rx
, new);
4235 spin_unlock_bh(&sta
->lock
);
4238 kfree_rcu(old
, rcu_head
);
4241 void ieee80211_clear_fast_rx(struct sta_info
*sta
)
4243 struct ieee80211_fast_rx
*old
;
4245 spin_lock_bh(&sta
->lock
);
4246 old
= rcu_dereference_protected(sta
->fast_rx
, true);
4247 RCU_INIT_POINTER(sta
->fast_rx
, NULL
);
4248 spin_unlock_bh(&sta
->lock
);
4251 kfree_rcu(old
, rcu_head
);
4254 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data
*sdata
)
4256 struct ieee80211_local
*local
= sdata
->local
;
4257 struct sta_info
*sta
;
4259 lockdep_assert_held(&local
->sta_mtx
);
4261 list_for_each_entry(sta
, &local
->sta_list
, list
) {
4262 if (sdata
!= sta
->sdata
&&
4263 (!sta
->sdata
->bss
|| sta
->sdata
->bss
!= sdata
->bss
))
4265 ieee80211_check_fast_rx(sta
);
4269 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data
*sdata
)
4271 struct ieee80211_local
*local
= sdata
->local
;
4273 mutex_lock(&local
->sta_mtx
);
4274 __ieee80211_check_fast_rx_iface(sdata
);
4275 mutex_unlock(&local
->sta_mtx
);
4278 static void ieee80211_rx_8023(struct ieee80211_rx_data
*rx
,
4279 struct ieee80211_fast_rx
*fast_rx
,
4282 struct ieee80211_sta_rx_stats
*stats
;
4283 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(rx
->skb
);
4284 struct sta_info
*sta
= rx
->sta
;
4285 struct sk_buff
*skb
= rx
->skb
;
4286 void *sa
= skb
->data
+ ETH_ALEN
;
4287 void *da
= skb
->data
;
4289 stats
= &sta
->rx_stats
;
4290 if (fast_rx
->uses_rss
)
4291 stats
= this_cpu_ptr(sta
->pcpu_rx_stats
);
4293 /* statistics part of ieee80211_rx_h_sta_process() */
4294 if (!(status
->flag
& RX_FLAG_NO_SIGNAL_VAL
)) {
4295 stats
->last_signal
= status
->signal
;
4296 if (!fast_rx
->uses_rss
)
4297 ewma_signal_add(&sta
->rx_stats_avg
.signal
,
4301 if (status
->chains
) {
4304 stats
->chains
= status
->chains
;
4305 for (i
= 0; i
< ARRAY_SIZE(status
->chain_signal
); i
++) {
4306 int signal
= status
->chain_signal
[i
];
4308 if (!(status
->chains
& BIT(i
)))
4311 stats
->chain_signal_last
[i
] = signal
;
4312 if (!fast_rx
->uses_rss
)
4313 ewma_signal_add(&sta
->rx_stats_avg
.chain_signal
[i
],
4317 /* end of statistics */
4319 stats
->last_rx
= jiffies
;
4320 stats
->last_rate
= sta_stats_encode_rate(status
);
4325 skb
->dev
= fast_rx
->dev
;
4327 dev_sw_netstats_rx_add(fast_rx
->dev
, skb
->len
);
4329 /* The seqno index has the same property as needed
4330 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4331 * for non-QoS-data frames. Here we know it's a data
4332 * frame, so count MSDUs.
4334 u64_stats_update_begin(&stats
->syncp
);
4335 stats
->msdu
[rx
->seqno_idx
]++;
4336 stats
->bytes
+= orig_len
;
4337 u64_stats_update_end(&stats
->syncp
);
4339 if (fast_rx
->internal_forward
) {
4340 struct sk_buff
*xmit_skb
= NULL
;
4341 if (is_multicast_ether_addr(da
)) {
4342 xmit_skb
= skb_copy(skb
, GFP_ATOMIC
);
4343 } else if (!ether_addr_equal(da
, sa
) &&
4344 sta_info_get(rx
->sdata
, da
)) {
4351 * Send to wireless media and increase priority by 256
4352 * to keep the received priority instead of
4353 * reclassifying the frame (see cfg80211_classify8021d).
4355 xmit_skb
->priority
+= 256;
4356 xmit_skb
->protocol
= htons(ETH_P_802_3
);
4357 skb_reset_network_header(xmit_skb
);
4358 skb_reset_mac_header(xmit_skb
);
4359 dev_queue_xmit(xmit_skb
);
4366 /* deliver to local stack */
4367 skb
->protocol
= eth_type_trans(skb
, fast_rx
->dev
);
4368 memset(skb
->cb
, 0, sizeof(skb
->cb
));
4370 list_add_tail(&skb
->list
, rx
->list
);
4372 netif_receive_skb(skb
);
4376 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data
*rx
,
4377 struct ieee80211_fast_rx
*fast_rx
)
4379 struct sk_buff
*skb
= rx
->skb
;
4380 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
4381 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
4382 struct sta_info
*sta
= rx
->sta
;
4383 int orig_len
= skb
->len
;
4384 int hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
4385 int snap_offs
= hdrlen
;
4387 u8 snap
[sizeof(rfc1042_header
)];
4389 } *payload
__aligned(2);
4393 } addrs
__aligned(2);
4394 struct ieee80211_sta_rx_stats
*stats
= &sta
->rx_stats
;
4396 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4397 * to a common data structure; drivers can implement that per queue
4398 * but we don't have that information in mac80211
4400 if (!(status
->flag
& RX_FLAG_DUP_VALIDATED
))
4403 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4405 /* If using encryption, we also need to have:
4406 * - PN_VALIDATED: similar, but the implementation is tricky
4407 * - DECRYPTED: necessary for PN_VALIDATED
4410 (status
->flag
& FAST_RX_CRYPT_FLAGS
) != FAST_RX_CRYPT_FLAGS
)
4413 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
4416 if (unlikely(ieee80211_is_frag(hdr
)))
4419 /* Since our interface address cannot be multicast, this
4420 * implicitly also rejects multicast frames without the
4423 * We shouldn't get any *data* frames not addressed to us
4424 * (AP mode will accept multicast *management* frames), but
4425 * punting here will make it go through the full checks in
4426 * ieee80211_accept_frame().
4428 if (!ether_addr_equal(fast_rx
->vif_addr
, hdr
->addr1
))
4431 if ((hdr
->frame_control
& cpu_to_le16(IEEE80211_FCTL_FROMDS
|
4432 IEEE80211_FCTL_TODS
)) !=
4433 fast_rx
->expected_ds_bits
)
4436 /* assign the key to drop unencrypted frames (later)
4437 * and strip the IV/MIC if necessary
4439 if (fast_rx
->key
&& !(status
->flag
& RX_FLAG_IV_STRIPPED
)) {
4440 /* GCMP header length is the same */
4441 snap_offs
+= IEEE80211_CCMP_HDR_LEN
;
4444 if (!(status
->rx_flags
& IEEE80211_RX_AMSDU
)) {
4445 if (!pskb_may_pull(skb
, snap_offs
+ sizeof(*payload
)))
4448 payload
= (void *)(skb
->data
+ snap_offs
);
4450 if (!ether_addr_equal(payload
->snap
, fast_rx
->rfc1042_hdr
))
4453 /* Don't handle these here since they require special code.
4454 * Accept AARP and IPX even though they should come with a
4455 * bridge-tunnel header - but if we get them this way then
4456 * there's little point in discarding them.
4458 if (unlikely(payload
->proto
== cpu_to_be16(ETH_P_TDLS
) ||
4459 payload
->proto
== fast_rx
->control_port_protocol
))
4463 /* after this point, don't punt to the slowpath! */
4465 if (rx
->key
&& !(status
->flag
& RX_FLAG_MIC_STRIPPED
) &&
4466 pskb_trim(skb
, skb
->len
- fast_rx
->icv_len
))
4469 if (rx
->key
&& !ieee80211_has_protected(hdr
->frame_control
))
4472 if (status
->rx_flags
& IEEE80211_RX_AMSDU
) {
4473 if (__ieee80211_rx_h_amsdu(rx
, snap_offs
- hdrlen
) !=
4480 /* do the header conversion - first grab the addresses */
4481 ether_addr_copy(addrs
.da
, skb
->data
+ fast_rx
->da_offs
);
4482 ether_addr_copy(addrs
.sa
, skb
->data
+ fast_rx
->sa_offs
);
4483 /* remove the SNAP but leave the ethertype */
4484 skb_pull(skb
, snap_offs
+ sizeof(rfc1042_header
));
4485 /* push the addresses in front */
4486 memcpy(skb_push(skb
, sizeof(addrs
)), &addrs
, sizeof(addrs
));
4488 ieee80211_rx_8023(rx
, fast_rx
, orig_len
);
4493 if (fast_rx
->uses_rss
)
4494 stats
= this_cpu_ptr(sta
->pcpu_rx_stats
);
4501 * This function returns whether or not the SKB
4502 * was destined for RX processing or not, which,
4503 * if consume is true, is equivalent to whether
4504 * or not the skb was consumed.
4506 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data
*rx
,
4507 struct sk_buff
*skb
, bool consume
)
4509 struct ieee80211_local
*local
= rx
->local
;
4510 struct ieee80211_sub_if_data
*sdata
= rx
->sdata
;
4514 /* See if we can do fast-rx; if we have to copy we already lost,
4515 * so punt in that case. We should never have to deliver a data
4516 * frame to multiple interfaces anyway.
4518 * We skip the ieee80211_accept_frame() call and do the necessary
4519 * checking inside ieee80211_invoke_fast_rx().
4521 if (consume
&& rx
->sta
) {
4522 struct ieee80211_fast_rx
*fast_rx
;
4524 fast_rx
= rcu_dereference(rx
->sta
->fast_rx
);
4525 if (fast_rx
&& ieee80211_invoke_fast_rx(rx
, fast_rx
))
4529 if (!ieee80211_accept_frame(rx
))
4533 skb
= skb_copy(skb
, GFP_ATOMIC
);
4535 if (net_ratelimit())
4536 wiphy_debug(local
->hw
.wiphy
,
4537 "failed to copy skb for %s\n",
4545 ieee80211_invoke_rx_handlers(rx
);
4549 static void __ieee80211_rx_handle_8023(struct ieee80211_hw
*hw
,
4550 struct ieee80211_sta
*pubsta
,
4551 struct sk_buff
*skb
,
4552 struct list_head
*list
)
4554 struct ieee80211_local
*local
= hw_to_local(hw
);
4555 struct ieee80211_fast_rx
*fast_rx
;
4556 struct ieee80211_rx_data rx
;
4558 memset(&rx
, 0, sizeof(rx
));
4563 I802_DEBUG_INC(local
->dot11ReceivedFragmentCount
);
4565 /* drop frame if too short for header */
4566 if (skb
->len
< sizeof(struct ethhdr
))
4572 rx
.sta
= container_of(pubsta
, struct sta_info
, sta
);
4573 rx
.sdata
= rx
.sta
->sdata
;
4575 fast_rx
= rcu_dereference(rx
.sta
->fast_rx
);
4579 ieee80211_rx_8023(&rx
, fast_rx
, skb
->len
);
4587 * This is the actual Rx frames handler. as it belongs to Rx path it must
4588 * be called with rcu_read_lock protection.
4590 static void __ieee80211_rx_handle_packet(struct ieee80211_hw
*hw
,
4591 struct ieee80211_sta
*pubsta
,
4592 struct sk_buff
*skb
,
4593 struct list_head
*list
)
4595 struct ieee80211_local
*local
= hw_to_local(hw
);
4596 struct ieee80211_sub_if_data
*sdata
;
4597 struct ieee80211_hdr
*hdr
;
4599 struct ieee80211_rx_data rx
;
4600 struct ieee80211_sub_if_data
*prev
;
4601 struct rhlist_head
*tmp
;
4604 fc
= ((struct ieee80211_hdr
*)skb
->data
)->frame_control
;
4605 memset(&rx
, 0, sizeof(rx
));
4610 if (ieee80211_is_data(fc
) || ieee80211_is_mgmt(fc
))
4611 I802_DEBUG_INC(local
->dot11ReceivedFragmentCount
);
4613 if (ieee80211_is_mgmt(fc
)) {
4614 /* drop frame if too short for header */
4615 if (skb
->len
< ieee80211_hdrlen(fc
))
4618 err
= skb_linearize(skb
);
4620 err
= !pskb_may_pull(skb
, ieee80211_hdrlen(fc
));
4628 hdr
= (struct ieee80211_hdr
*)skb
->data
;
4629 ieee80211_parse_qos(&rx
);
4630 ieee80211_verify_alignment(&rx
);
4632 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
) ||
4633 ieee80211_is_beacon(hdr
->frame_control
) ||
4634 ieee80211_is_s1g_beacon(hdr
->frame_control
)))
4635 ieee80211_scan_rx(local
, skb
);
4637 if (ieee80211_is_data(fc
)) {
4638 struct sta_info
*sta
, *prev_sta
;
4641 rx
.sta
= container_of(pubsta
, struct sta_info
, sta
);
4642 rx
.sdata
= rx
.sta
->sdata
;
4643 if (ieee80211_prepare_and_rx_handle(&rx
, skb
, true))
4650 for_each_sta_info(local
, hdr
->addr2
, sta
, tmp
) {
4657 rx
.sdata
= prev_sta
->sdata
;
4658 ieee80211_prepare_and_rx_handle(&rx
, skb
, false);
4665 rx
.sdata
= prev_sta
->sdata
;
4667 if (ieee80211_prepare_and_rx_handle(&rx
, skb
, true))
4675 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4676 if (!ieee80211_sdata_running(sdata
))
4679 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
||
4680 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
4684 * frame is destined for this interface, but if it's
4685 * not also for the previous one we handle that after
4686 * the loop to avoid copying the SKB once too much
4694 rx
.sta
= sta_info_get_bss(prev
, hdr
->addr2
);
4696 ieee80211_prepare_and_rx_handle(&rx
, skb
, false);
4702 rx
.sta
= sta_info_get_bss(prev
, hdr
->addr2
);
4705 if (ieee80211_prepare_and_rx_handle(&rx
, skb
, true))
4714 * This is the receive path handler. It is called by a low level driver when an
4715 * 802.11 MPDU is received from the hardware.
4717 void ieee80211_rx_list(struct ieee80211_hw
*hw
, struct ieee80211_sta
*pubsta
,
4718 struct sk_buff
*skb
, struct list_head
*list
)
4720 struct ieee80211_local
*local
= hw_to_local(hw
);
4721 struct ieee80211_rate
*rate
= NULL
;
4722 struct ieee80211_supported_band
*sband
;
4723 struct ieee80211_rx_status
*status
= IEEE80211_SKB_RXCB(skb
);
4725 WARN_ON_ONCE(softirq_count() == 0);
4727 if (WARN_ON(status
->band
>= NUM_NL80211_BANDS
))
4730 sband
= local
->hw
.wiphy
->bands
[status
->band
];
4731 if (WARN_ON(!sband
))
4735 * If we're suspending, it is possible although not too likely
4736 * that we'd be receiving frames after having already partially
4737 * quiesced the stack. We can't process such frames then since
4738 * that might, for example, cause stations to be added or other
4739 * driver callbacks be invoked.
4741 if (unlikely(local
->quiescing
|| local
->suspended
))
4744 /* We might be during a HW reconfig, prevent Rx for the same reason */
4745 if (unlikely(local
->in_reconfig
))
4749 * The same happens when we're not even started,
4750 * but that's worth a warning.
4752 if (WARN_ON(!local
->started
))
4755 if (likely(!(status
->flag
& RX_FLAG_FAILED_PLCP_CRC
))) {
4757 * Validate the rate, unless a PLCP error means that
4758 * we probably can't have a valid rate here anyway.
4761 switch (status
->encoding
) {
4764 * rate_idx is MCS index, which can be [0-76]
4767 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
4769 * Anything else would be some sort of driver or
4770 * hardware error. The driver should catch hardware
4773 if (WARN(status
->rate_idx
> 76,
4774 "Rate marked as an HT rate but passed "
4775 "status->rate_idx is not "
4776 "an MCS index [0-76]: %d (0x%02x)\n",
4782 if (WARN_ONCE(status
->rate_idx
> 9 ||
4785 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4786 status
->rate_idx
, status
->nss
))
4790 if (WARN_ONCE(status
->rate_idx
> 11 ||
4793 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4794 status
->rate_idx
, status
->nss
))
4801 if (WARN_ON(status
->rate_idx
>= sband
->n_bitrates
))
4803 rate
= &sband
->bitrates
[status
->rate_idx
];
4807 status
->rx_flags
= 0;
4809 kcov_remote_start_common(skb_get_kcov_handle(skb
));
4812 * Frames with failed FCS/PLCP checksum are not returned,
4813 * all other frames are returned without radiotap header
4814 * if it was previously present.
4815 * Also, frames with less than 16 bytes are dropped.
4817 if (!(status
->flag
& RX_FLAG_8023
))
4818 skb
= ieee80211_rx_monitor(local
, skb
, rate
);
4820 ieee80211_tpt_led_trig_rx(local
,
4821 ((struct ieee80211_hdr
*)skb
->data
)->frame_control
,
4824 if (status
->flag
& RX_FLAG_8023
)
4825 __ieee80211_rx_handle_8023(hw
, pubsta
, skb
, list
);
4827 __ieee80211_rx_handle_packet(hw
, pubsta
, skb
, list
);
4835 EXPORT_SYMBOL(ieee80211_rx_list
);
4837 void ieee80211_rx_napi(struct ieee80211_hw
*hw
, struct ieee80211_sta
*pubsta
,
4838 struct sk_buff
*skb
, struct napi_struct
*napi
)
4840 struct sk_buff
*tmp
;
4845 * key references and virtual interfaces are protected using RCU
4846 * and this requires that we are in a read-side RCU section during
4847 * receive processing
4850 ieee80211_rx_list(hw
, pubsta
, skb
, &list
);
4854 netif_receive_skb_list(&list
);
4858 list_for_each_entry_safe(skb
, tmp
, &list
, list
) {
4859 skb_list_del_init(skb
);
4860 napi_gro_receive(napi
, skb
);
4863 EXPORT_SYMBOL(ieee80211_rx_napi
);
4865 /* This is a version of the rx handler that can be called from hard irq
4866 * context. Post the skb on the queue and schedule the tasklet */
4867 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
4869 struct ieee80211_local
*local
= hw_to_local(hw
);
4871 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
));
4873 skb
->pkt_type
= IEEE80211_RX_MSG
;
4874 skb_queue_tail(&local
->skb_queue
, skb
);
4875 tasklet_schedule(&local
->tasklet
);
4877 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);