1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
7 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
9 * Copyright (C) 2018-2024 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 <kunit/visibility.h>
23 #include <net/mac80211.h>
24 #include <net/ieee80211_radiotap.h>
25 #include <asm/unaligned.h>
27 #include "ieee80211_i.h"
28 #include "driver-ops.h"
38 * monitor mode reception
40 * This function cleans up the SKB, i.e. it removes all the stuff
41 * only useful for monitoring.
43 static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
44 unsigned int present_fcs_len,
45 unsigned int rtap_space)
47 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
48 struct ieee80211_hdr *hdr;
53 __pskb_trim(skb, skb->len - present_fcs_len);
54 pskb_pull(skb, rtap_space);
56 /* After pulling radiotap header, clear all flags that indicate
59 status->flag &= ~(RX_FLAG_RADIOTAP_TLV_AT_END |
60 RX_FLAG_RADIOTAP_LSIG |
61 RX_FLAG_RADIOTAP_HE_MU |
64 hdr = (void *)skb->data;
65 fc = hdr->frame_control;
68 * Remove the HT-Control field (if present) on management
69 * frames after we've sent the frame to monitoring. We
70 * (currently) don't need it, and don't properly parse
71 * frames with it present, due to the assumption of a
72 * fixed management header length.
74 if (likely(!ieee80211_is_mgmt(fc) || !ieee80211_has_order(fc)))
77 hdrlen = ieee80211_hdrlen(fc);
78 hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_ORDER);
80 if (!pskb_may_pull(skb, hdrlen)) {
85 memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data,
86 hdrlen - IEEE80211_HT_CTL_LEN);
87 pskb_pull(skb, IEEE80211_HT_CTL_LEN);
92 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
93 unsigned int rtap_space)
95 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
96 struct ieee80211_hdr *hdr;
98 hdr = (void *)(skb->data + rtap_space);
100 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
101 RX_FLAG_FAILED_PLCP_CRC |
102 RX_FLAG_ONLY_MONITOR |
106 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
109 if (ieee80211_is_ctl(hdr->frame_control) &&
110 !ieee80211_is_pspoll(hdr->frame_control) &&
111 !ieee80211_is_back_req(hdr->frame_control))
118 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
119 struct ieee80211_rx_status *status,
124 /* always present fields */
125 len = sizeof(struct ieee80211_radiotap_header) + 8;
127 /* allocate extra bitmaps */
129 len += 4 * hweight8(status->chains);
131 if (ieee80211_have_rx_timestamp(status)) {
135 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
138 /* antenna field, if we don't have per-chain info */
142 /* padding for RX_FLAGS if necessary */
145 if (status->encoding == RX_ENC_HT) /* HT info */
148 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
153 if (status->encoding == RX_ENC_VHT) {
158 if (local->hw.radiotap_timestamp.units_pos >= 0) {
163 if (status->encoding == RX_ENC_HE &&
164 status->flag & RX_FLAG_RADIOTAP_HE) {
167 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
170 if (status->encoding == RX_ENC_HE &&
171 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
174 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
177 if (status->flag & RX_FLAG_NO_PSDU)
180 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
183 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4);
186 if (status->chains) {
187 /* antenna and antenna signal fields */
188 len += 2 * hweight8(status->chains);
191 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END) {
195 * The position to look at depends on the existence (or non-
196 * existence) of other elements, so take that into account...
198 if (status->flag & RX_FLAG_RADIOTAP_HE)
200 sizeof(struct ieee80211_radiotap_he);
201 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
203 sizeof(struct ieee80211_radiotap_he_mu);
204 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
206 sizeof(struct ieee80211_radiotap_lsig);
208 /* ensure 4 byte alignment for TLV */
211 /* TLVs until the mac header */
212 len += skb_mac_header(skb) - &skb->data[tlv_offset];
218 static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
220 struct sta_info *sta,
223 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
226 status->link_valid = 1;
227 status->link_id = link_id;
229 status->link_valid = 0;
232 skb_queue_tail(&sdata->skb_queue, skb);
233 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
235 sta->deflink.rx_stats.packets++;
238 static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
240 struct sta_info *sta,
244 __ieee80211_queue_skb_to_iface(sdata, link_id, sta, skb);
247 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
252 struct ieee80211_hdr_3addr hdr;
255 } __packed __aligned(2) action;
260 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
262 if (skb->len < rtap_space + sizeof(action) +
263 VHT_MUMIMO_GROUPS_DATA_LEN)
266 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
269 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
271 if (!ieee80211_is_action(action.hdr.frame_control))
274 if (action.category != WLAN_CATEGORY_VHT)
277 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
280 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
283 skb = skb_copy(skb, GFP_ATOMIC);
287 ieee80211_queue_skb_to_iface(sdata, -1, NULL, skb);
291 * ieee80211_add_rx_radiotap_header - add radiotap header
293 * add a radiotap header containing all the fields which the hardware provided.
296 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
298 struct ieee80211_rate *rate,
299 int rtap_len, bool has_fcs)
301 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
302 struct ieee80211_radiotap_header *rthdr;
307 u16 channel_flags = 0;
310 unsigned long chains = status->chains;
311 struct ieee80211_radiotap_he he = {};
312 struct ieee80211_radiotap_he_mu he_mu = {};
313 struct ieee80211_radiotap_lsig lsig = {};
315 if (status->flag & RX_FLAG_RADIOTAP_HE) {
316 he = *(struct ieee80211_radiotap_he *)skb->data;
317 skb_pull(skb, sizeof(he));
318 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
321 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
322 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
323 skb_pull(skb, sizeof(he_mu));
326 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
327 lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
328 skb_pull(skb, sizeof(lsig));
331 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END) {
332 /* data is pointer at tlv all other info was pulled off */
333 tlvs_len = skb_mac_header(skb) - skb->data;
337 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
340 rthdr = skb_push(skb, rtap_len - tlvs_len);
341 memset(rthdr, 0, rtap_len - tlvs_len);
342 it_present = &rthdr->it_present;
344 /* radiotap header, set always present flags */
345 rthdr->it_len = cpu_to_le16(rtap_len);
346 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
347 BIT(IEEE80211_RADIOTAP_CHANNEL) |
348 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
351 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
353 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
355 BIT(IEEE80211_RADIOTAP_EXT) |
356 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
357 put_unaligned_le32(it_present_val, it_present);
359 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
360 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
363 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END)
364 it_present_val |= BIT(IEEE80211_RADIOTAP_TLV);
366 put_unaligned_le32(it_present_val, it_present);
368 /* This references through an offset into it_optional[] rather
369 * than via it_present otherwise later uses of pos will cause
370 * the compiler to think we have walked past the end of the
373 pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
375 /* the order of the following fields is important */
377 /* IEEE80211_RADIOTAP_TSFT */
378 if (ieee80211_have_rx_timestamp(status)) {
380 while ((pos - (u8 *)rthdr) & 7)
383 ieee80211_calculate_rx_timestamp(local, status,
386 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));
390 /* IEEE80211_RADIOTAP_FLAGS */
391 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
392 *pos |= IEEE80211_RADIOTAP_F_FCS;
393 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
394 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
395 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
396 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
399 /* IEEE80211_RADIOTAP_RATE */
400 if (!rate || status->encoding != RX_ENC_LEGACY) {
402 * Without rate information don't add it. If we have,
403 * MCS information is a separate field in radiotap,
404 * added below. The byte here is needed as padding
405 * for the channel though, so initialise it to 0.
410 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
411 if (status->bw == RATE_INFO_BW_10)
413 else if (status->bw == RATE_INFO_BW_5)
415 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
419 /* IEEE80211_RADIOTAP_CHANNEL */
420 /* TODO: frequency offset in KHz */
421 put_unaligned_le16(status->freq, pos);
423 if (status->bw == RATE_INFO_BW_10)
424 channel_flags |= IEEE80211_CHAN_HALF;
425 else if (status->bw == RATE_INFO_BW_5)
426 channel_flags |= IEEE80211_CHAN_QUARTER;
428 if (status->band == NL80211_BAND_5GHZ ||
429 status->band == NL80211_BAND_6GHZ)
430 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
431 else if (status->encoding != RX_ENC_LEGACY)
432 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
433 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
434 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
436 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
438 channel_flags |= IEEE80211_CHAN_2GHZ;
439 put_unaligned_le16(channel_flags, pos);
442 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
443 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
444 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
445 *pos = status->signal;
447 cpu_to_le32(BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
451 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
453 if (!status->chains) {
454 /* IEEE80211_RADIOTAP_ANTENNA */
455 *pos = status->antenna;
459 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
461 /* IEEE80211_RADIOTAP_RX_FLAGS */
462 /* ensure 2 byte alignment for the 2 byte field as required */
463 if ((pos - (u8 *)rthdr) & 1)
465 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
466 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
467 put_unaligned_le16(rx_flags, pos);
470 if (status->encoding == RX_ENC_HT) {
473 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
474 *pos = local->hw.radiotap_mcs_details;
475 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
476 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
477 if (status->enc_flags & RX_ENC_FLAG_LDPC)
478 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FEC;
481 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
482 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
483 if (status->bw == RATE_INFO_BW_40)
484 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
485 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
486 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
487 if (status->enc_flags & RX_ENC_FLAG_LDPC)
488 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
489 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
490 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
492 *pos++ = status->rate_idx;
495 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
498 /* ensure 4 byte alignment */
499 while ((pos - (u8 *)rthdr) & 3)
502 cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
503 put_unaligned_le32(status->ampdu_reference, pos);
505 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
506 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
507 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
508 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
509 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
510 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
511 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
512 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
513 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
514 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
515 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
516 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
517 put_unaligned_le16(flags, pos);
519 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
520 *pos++ = status->ampdu_delimiter_crc;
526 if (status->encoding == RX_ENC_VHT) {
527 u16 known = local->hw.radiotap_vht_details;
529 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
530 put_unaligned_le16(known, pos);
533 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
534 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
535 /* in VHT, STBC is binary */
536 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
537 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
538 if (status->enc_flags & RX_ENC_FLAG_BF)
539 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
542 switch (status->bw) {
543 case RATE_INFO_BW_80:
546 case RATE_INFO_BW_160:
549 case RATE_INFO_BW_40:
556 *pos = (status->rate_idx << 4) | status->nss;
559 if (status->enc_flags & RX_ENC_FLAG_LDPC)
560 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
568 if (local->hw.radiotap_timestamp.units_pos >= 0) {
574 cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
576 /* ensure 8 byte alignment */
577 while ((pos - (u8 *)rthdr) & 7)
580 if (status->flag & RX_FLAG_MACTIME_IS_RTAP_TS64) {
581 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_64BIT;
582 ts = status->mactime;
584 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
585 ts = status->device_timestamp;
588 put_unaligned_le64(ts, pos);
591 if (local->hw.radiotap_timestamp.accuracy >= 0) {
592 accuracy = local->hw.radiotap_timestamp.accuracy;
593 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
595 put_unaligned_le16(accuracy, pos);
598 *pos++ = local->hw.radiotap_timestamp.units_pos;
602 if (status->encoding == RX_ENC_HE &&
603 status->flag & RX_FLAG_RADIOTAP_HE) {
604 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
606 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
607 he.data6 |= HE_PREP(DATA6_NSTS,
608 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
610 he.data3 |= HE_PREP(DATA3_STBC, 1);
612 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
615 #define CHECK_GI(s) \
616 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
617 (int)NL80211_RATE_INFO_HE_GI_##s)
623 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
624 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
625 he.data3 |= HE_PREP(DATA3_CODING,
626 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
628 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
630 switch (status->bw) {
631 case RATE_INFO_BW_20:
632 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
633 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
635 case RATE_INFO_BW_40:
636 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
637 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
639 case RATE_INFO_BW_80:
640 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
641 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
643 case RATE_INFO_BW_160:
644 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
645 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
647 case RATE_INFO_BW_HE_RU:
648 #define CHECK_RU_ALLOC(s) \
649 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
650 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
658 CHECK_RU_ALLOC(2x996);
660 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
664 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
667 /* ensure 2 byte alignment */
668 while ((pos - (u8 *)rthdr) & 1)
670 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
671 memcpy(pos, &he, sizeof(he));
675 if (status->encoding == RX_ENC_HE &&
676 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
677 /* ensure 2 byte alignment */
678 while ((pos - (u8 *)rthdr) & 1)
680 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
681 memcpy(pos, &he_mu, sizeof(he_mu));
682 pos += sizeof(he_mu);
685 if (status->flag & RX_FLAG_NO_PSDU) {
687 cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
688 *pos++ = status->zero_length_psdu_type;
691 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
692 /* ensure 2 byte alignment */
693 while ((pos - (u8 *)rthdr) & 1)
695 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
696 memcpy(pos, &lsig, sizeof(lsig));
700 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
701 *pos++ = status->chain_signal[chain];
706 static struct sk_buff *
707 ieee80211_make_monitor_skb(struct ieee80211_local *local,
708 struct sk_buff **origskb,
709 struct ieee80211_rate *rate,
710 int rtap_space, bool use_origskb)
712 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
713 int rt_hdrlen, needed_headroom;
716 /* room for the radiotap header based on driver features */
717 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
718 needed_headroom = rt_hdrlen - rtap_space;
721 /* only need to expand headroom if necessary */
726 * This shouldn't trigger often because most devices have an
727 * RX header they pull before we get here, and that should
728 * be big enough for our radiotap information. We should
729 * probably export the length to drivers so that we can have
730 * them allocate enough headroom to start with.
732 if (skb_headroom(skb) < needed_headroom &&
733 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
739 * Need to make a copy and possibly remove radiotap header
740 * and FCS from the original.
742 skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
749 /* prepend radiotap information */
750 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
752 skb_reset_mac_header(skb);
753 skb->ip_summed = CHECKSUM_UNNECESSARY;
754 skb->pkt_type = PACKET_OTHERHOST;
755 skb->protocol = htons(ETH_P_802_2);
761 * This function copies a received frame to all monitor interfaces and
762 * returns a cleaned-up SKB that no longer includes the FCS nor the
763 * radiotap header the driver might have added.
765 static struct sk_buff *
766 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
767 struct ieee80211_rate *rate)
769 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
770 struct ieee80211_sub_if_data *sdata;
771 struct sk_buff *monskb = NULL;
772 int present_fcs_len = 0;
773 unsigned int rtap_space = 0;
774 struct ieee80211_sub_if_data *monitor_sdata =
775 rcu_dereference(local->monitor_sdata);
776 bool only_monitor = false;
777 unsigned int min_head_len;
779 if (WARN_ON_ONCE(status->flag & RX_FLAG_RADIOTAP_TLV_AT_END &&
780 !skb_mac_header_was_set(origskb))) {
781 /* with this skb no way to know where frame payload starts */
782 dev_kfree_skb(origskb);
786 if (status->flag & RX_FLAG_RADIOTAP_HE)
787 rtap_space += sizeof(struct ieee80211_radiotap_he);
789 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
790 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
792 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
793 rtap_space += sizeof(struct ieee80211_radiotap_lsig);
795 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END)
796 rtap_space += skb_mac_header(origskb) - &origskb->data[rtap_space];
798 min_head_len = rtap_space;
801 * First, we may need to make a copy of the skb because
802 * (1) we need to modify it for radiotap (if not present), and
803 * (2) the other RX handlers will modify the skb we got.
805 * We don't need to, of course, if we aren't going to return
806 * the SKB because it has a bad FCS/PLCP checksum.
809 if (!(status->flag & RX_FLAG_NO_PSDU)) {
810 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
811 if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
814 dev_kfree_skb(origskb);
817 present_fcs_len = FCS_LEN;
820 /* also consider the hdr->frame_control */
824 /* ensure that the expected data elements are in skb head */
825 if (!pskb_may_pull(origskb, min_head_len)) {
826 dev_kfree_skb(origskb);
830 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
832 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
834 dev_kfree_skb(origskb);
838 return ieee80211_clean_skb(origskb, present_fcs_len,
842 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
844 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
845 bool last_monitor = list_is_last(&sdata->u.mntr.list,
849 monskb = ieee80211_make_monitor_skb(local, &origskb,
861 skb = skb_clone(monskb, GFP_ATOMIC);
865 skb->dev = sdata->dev;
866 dev_sw_netstats_rx_add(skb->dev, skb->len);
867 netif_receive_skb(skb);
875 /* this happens if last_monitor was erroneously false */
876 dev_kfree_skb(monskb);
882 return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
885 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
887 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
888 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
889 int tid, seqno_idx, security_idx;
891 /* does the frame have a qos control field? */
892 if (ieee80211_is_data_qos(hdr->frame_control)) {
893 u8 *qc = ieee80211_get_qos_ctl(hdr);
894 /* frame has qos control */
895 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
896 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
897 status->rx_flags |= IEEE80211_RX_AMSDU;
903 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
905 * Sequence numbers for management frames, QoS data
906 * frames with a broadcast/multicast address in the
907 * Address 1 field, and all non-QoS data frames sent
908 * by QoS STAs are assigned using an additional single
909 * modulo-4096 counter, [...]
911 * We also use that counter for non-QoS STAs.
913 seqno_idx = IEEE80211_NUM_TIDS;
915 if (ieee80211_is_mgmt(hdr->frame_control))
916 security_idx = IEEE80211_NUM_TIDS;
920 rx->seqno_idx = seqno_idx;
921 rx->security_idx = security_idx;
922 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
923 * For now, set skb->priority to 0 for other cases. */
924 rx->skb->priority = (tid > 7) ? 0 : tid;
928 * DOC: Packet alignment
930 * Drivers always need to pass packets that are aligned to two-byte boundaries
933 * Additionally, they should, if possible, align the payload data in a way that
934 * guarantees that the contained IP header is aligned to a four-byte
935 * boundary. In the case of regular frames, this simply means aligning the
936 * payload to a four-byte boundary (because either the IP header is directly
937 * contained, or IV/RFC1042 headers that have a length divisible by four are
938 * in front of it). If the payload data is not properly aligned and the
939 * architecture doesn't support efficient unaligned operations, mac80211
940 * will align the data.
942 * With A-MSDU frames, however, the payload data address must yield two modulo
943 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
944 * push the IP header further back to a multiple of four again. Thankfully, the
945 * specs were sane enough this time around to require padding each A-MSDU
946 * subframe to a length that is a multiple of four.
948 * Padding like Atheros hardware adds which is between the 802.11 header and
949 * the payload is not supported; the driver is required to move the 802.11
950 * header to be directly in front of the payload in that case.
952 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
954 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
955 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
962 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
964 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
966 if (is_multicast_ether_addr(hdr->addr1))
969 return ieee80211_is_robust_mgmt_frame(skb);
973 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
975 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
977 if (!is_multicast_ether_addr(hdr->addr1))
980 return ieee80211_is_robust_mgmt_frame(skb);
984 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
985 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
987 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
988 struct ieee80211_mmie *mmie;
989 struct ieee80211_mmie_16 *mmie16;
991 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
994 if (!ieee80211_is_robust_mgmt_frame(skb) &&
995 !ieee80211_is_beacon(hdr->frame_control))
996 return -1; /* not a robust management frame */
998 mmie = (struct ieee80211_mmie *)
999 (skb->data + skb->len - sizeof(*mmie));
1000 if (mmie->element_id == WLAN_EID_MMIE &&
1001 mmie->length == sizeof(*mmie) - 2)
1002 return le16_to_cpu(mmie->key_id);
1004 mmie16 = (struct ieee80211_mmie_16 *)
1005 (skb->data + skb->len - sizeof(*mmie16));
1006 if (skb->len >= 24 + sizeof(*mmie16) &&
1007 mmie16->element_id == WLAN_EID_MMIE &&
1008 mmie16->length == sizeof(*mmie16) - 2)
1009 return le16_to_cpu(mmie16->key_id);
1014 static int ieee80211_get_keyid(struct sk_buff *skb)
1016 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1017 __le16 fc = hdr->frame_control;
1018 int hdrlen = ieee80211_hdrlen(fc);
1021 /* WEP, TKIP, CCMP and GCMP */
1022 if (unlikely(skb->len < hdrlen + IEEE80211_WEP_IV_LEN))
1025 skb_copy_bits(skb, hdrlen + 3, &keyid, 1);
1032 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1034 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1035 char *dev_addr = rx->sdata->vif.addr;
1037 if (ieee80211_is_data(hdr->frame_control)) {
1038 if (is_multicast_ether_addr(hdr->addr1)) {
1039 if (ieee80211_has_tods(hdr->frame_control) ||
1040 !ieee80211_has_fromds(hdr->frame_control))
1041 return RX_DROP_MONITOR;
1042 if (ether_addr_equal(hdr->addr3, dev_addr))
1043 return RX_DROP_MONITOR;
1045 if (!ieee80211_has_a4(hdr->frame_control))
1046 return RX_DROP_MONITOR;
1047 if (ether_addr_equal(hdr->addr4, dev_addr))
1048 return RX_DROP_MONITOR;
1052 /* If there is not an established peer link and this is not a peer link
1053 * establisment frame, beacon or probe, drop the frame.
1056 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1057 struct ieee80211_mgmt *mgmt;
1059 if (!ieee80211_is_mgmt(hdr->frame_control))
1060 return RX_DROP_MONITOR;
1062 if (ieee80211_is_action(hdr->frame_control)) {
1065 /* make sure category field is present */
1066 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1067 return RX_DROP_MONITOR;
1069 mgmt = (struct ieee80211_mgmt *)hdr;
1070 category = mgmt->u.action.category;
1071 if (category != WLAN_CATEGORY_MESH_ACTION &&
1072 category != WLAN_CATEGORY_SELF_PROTECTED)
1073 return RX_DROP_MONITOR;
1077 if (ieee80211_is_probe_req(hdr->frame_control) ||
1078 ieee80211_is_probe_resp(hdr->frame_control) ||
1079 ieee80211_is_beacon(hdr->frame_control) ||
1080 ieee80211_is_auth(hdr->frame_control))
1083 return RX_DROP_MONITOR;
1089 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1092 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1093 struct sk_buff *tail = skb_peek_tail(frames);
1094 struct ieee80211_rx_status *status;
1096 if (tid_agg_rx->reorder_buf_filtered &&
1097 tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1103 status = IEEE80211_SKB_RXCB(tail);
1104 if (status->flag & RX_FLAG_AMSDU_MORE)
1110 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1111 struct tid_ampdu_rx *tid_agg_rx,
1113 struct sk_buff_head *frames)
1115 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1116 struct sk_buff *skb;
1117 struct ieee80211_rx_status *status;
1119 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1121 if (skb_queue_empty(skb_list))
1124 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1125 __skb_queue_purge(skb_list);
1129 /* release frames from the reorder ring buffer */
1130 tid_agg_rx->stored_mpdu_num--;
1131 while ((skb = __skb_dequeue(skb_list))) {
1132 status = IEEE80211_SKB_RXCB(skb);
1133 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1134 __skb_queue_tail(frames, skb);
1138 if (tid_agg_rx->reorder_buf_filtered)
1139 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1140 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1143 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1144 struct tid_ampdu_rx *tid_agg_rx,
1146 struct sk_buff_head *frames)
1150 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1152 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1153 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1154 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1160 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1161 * the skb was added to the buffer longer than this time ago, the earlier
1162 * frames that have not yet been received are assumed to be lost and the skb
1163 * can be released for processing. This may also release other skb's from the
1164 * reorder buffer if there are no additional gaps between the frames.
1166 * Callers must hold tid_agg_rx->reorder_lock.
1168 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1170 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1171 struct tid_ampdu_rx *tid_agg_rx,
1172 struct sk_buff_head *frames)
1176 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1178 /* release the buffer until next missing frame */
1179 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1180 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1181 tid_agg_rx->stored_mpdu_num) {
1183 * No buffers ready to be released, but check whether any
1184 * frames in the reorder buffer have timed out.
1187 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1188 j = (j + 1) % tid_agg_rx->buf_size) {
1189 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1194 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1195 HT_RX_REORDER_BUF_TIMEOUT))
1196 goto set_release_timer;
1198 /* don't leave incomplete A-MSDUs around */
1199 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1200 i = (i + 1) % tid_agg_rx->buf_size)
1201 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1203 ht_dbg_ratelimited(sdata,
1204 "release an RX reorder frame due to timeout on earlier frames\n");
1205 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1209 * Increment the head seq# also for the skipped slots.
1211 tid_agg_rx->head_seq_num =
1212 (tid_agg_rx->head_seq_num +
1213 skipped) & IEEE80211_SN_MASK;
1216 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1217 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1219 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1222 if (tid_agg_rx->stored_mpdu_num) {
1223 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1225 for (; j != (index - 1) % tid_agg_rx->buf_size;
1226 j = (j + 1) % tid_agg_rx->buf_size) {
1227 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1233 if (!tid_agg_rx->removed)
1234 mod_timer(&tid_agg_rx->reorder_timer,
1235 tid_agg_rx->reorder_time[j] + 1 +
1236 HT_RX_REORDER_BUF_TIMEOUT);
1238 del_timer(&tid_agg_rx->reorder_timer);
1243 * As this function belongs to the RX path it must be under
1244 * rcu_read_lock protection. It returns false if the frame
1245 * can be processed immediately, true if it was consumed.
1247 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1248 struct tid_ampdu_rx *tid_agg_rx,
1249 struct sk_buff *skb,
1250 struct sk_buff_head *frames)
1252 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1253 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1254 u16 mpdu_seq_num = ieee80211_get_sn(hdr);
1255 u16 head_seq_num, buf_size;
1259 spin_lock(&tid_agg_rx->reorder_lock);
1262 * Offloaded BA sessions have no known starting sequence number so pick
1263 * one from first Rxed frame for this tid after BA was started.
1265 if (unlikely(tid_agg_rx->auto_seq)) {
1266 tid_agg_rx->auto_seq = false;
1267 tid_agg_rx->ssn = mpdu_seq_num;
1268 tid_agg_rx->head_seq_num = mpdu_seq_num;
1271 buf_size = tid_agg_rx->buf_size;
1272 head_seq_num = tid_agg_rx->head_seq_num;
1275 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1278 if (unlikely(!tid_agg_rx->started)) {
1279 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1283 tid_agg_rx->started = true;
1286 /* frame with out of date sequence number */
1287 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1293 * If frame the sequence number exceeds our buffering window
1294 * size release some previous frames to make room for this one.
1296 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1297 head_seq_num = ieee80211_sn_inc(
1298 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1299 /* release stored frames up to new head to stack */
1300 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1301 head_seq_num, frames);
1304 /* Now the new frame is always in the range of the reordering buffer */
1306 index = mpdu_seq_num % tid_agg_rx->buf_size;
1308 /* check if we already stored this frame */
1309 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1315 * If the current MPDU is in the right order and nothing else
1316 * is stored we can process it directly, no need to buffer it.
1317 * If it is first but there's something stored, we may be able
1318 * to release frames after this one.
1320 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1321 tid_agg_rx->stored_mpdu_num == 0) {
1322 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1323 tid_agg_rx->head_seq_num =
1324 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1329 /* put the frame in the reordering buffer */
1330 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1331 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1332 tid_agg_rx->reorder_time[index] = jiffies;
1333 tid_agg_rx->stored_mpdu_num++;
1334 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1338 spin_unlock(&tid_agg_rx->reorder_lock);
1343 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1344 * true if the MPDU was buffered, false if it should be processed.
1346 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1347 struct sk_buff_head *frames)
1349 struct sk_buff *skb = rx->skb;
1350 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1351 struct sta_info *sta = rx->sta;
1352 struct tid_ampdu_rx *tid_agg_rx;
1356 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1357 is_multicast_ether_addr(hdr->addr1))
1361 * filter the QoS data rx stream according to
1362 * STA/TID and check if this STA/TID is on aggregation
1368 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1369 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1370 tid = ieee80211_get_tid(hdr);
1372 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1374 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1375 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1376 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1377 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1378 WLAN_BACK_RECIPIENT,
1379 WLAN_REASON_QSTA_REQUIRE_SETUP);
1383 /* qos null data frames are excluded */
1384 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1387 /* not part of a BA session */
1388 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
1391 /* new, potentially un-ordered, ampdu frame - process it */
1393 /* reset session timer */
1394 if (tid_agg_rx->timeout)
1395 tid_agg_rx->last_rx = jiffies;
1397 /* if this mpdu is fragmented - terminate rx aggregation session */
1398 sc = le16_to_cpu(hdr->seq_ctrl);
1399 if (sc & IEEE80211_SCTL_FRAG) {
1400 ieee80211_queue_skb_to_iface(rx->sdata, rx->link_id, NULL, skb);
1405 * No locking needed -- we will only ever process one
1406 * RX packet at a time, and thus own tid_agg_rx. All
1407 * other code manipulating it needs to (and does) make
1408 * sure that we cannot get to it any more before doing
1411 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1416 __skb_queue_tail(frames, skb);
1419 static ieee80211_rx_result debug_noinline
1420 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1422 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1423 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1425 if (status->flag & RX_FLAG_DUP_VALIDATED)
1429 * Drop duplicate 802.11 retransmissions
1430 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1433 if (rx->skb->len < 24)
1436 if (ieee80211_is_ctl(hdr->frame_control) ||
1437 ieee80211_is_any_nullfunc(hdr->frame_control))
1443 if (unlikely(is_multicast_ether_addr(hdr->addr1))) {
1444 struct ieee80211_sub_if_data *sdata = rx->sdata;
1445 u16 sn = ieee80211_get_sn(hdr);
1447 if (!ieee80211_is_data_present(hdr->frame_control))
1450 if (!ieee80211_vif_is_mld(&sdata->vif) ||
1451 sdata->vif.type != NL80211_IFTYPE_STATION)
1454 if (sdata->u.mgd.mcast_seq_last != IEEE80211_SN_MODULO &&
1455 ieee80211_sn_less_eq(sn, sdata->u.mgd.mcast_seq_last))
1456 return RX_DROP_U_DUP;
1458 sdata->u.mgd.mcast_seq_last = sn;
1462 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1463 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1464 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1465 rx->link_sta->rx_stats.num_duplicates++;
1466 return RX_DROP_U_DUP;
1467 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1468 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1474 static ieee80211_rx_result debug_noinline
1475 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1477 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1479 /* Drop disallowed frame classes based on STA auth/assoc state;
1480 * IEEE 802.11, Chap 5.5.
1482 * mac80211 filters only based on association state, i.e. it drops
1483 * Class 3 frames from not associated stations. hostapd sends
1484 * deauth/disassoc frames when needed. In addition, hostapd is
1485 * responsible for filtering on both auth and assoc states.
1488 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1489 return ieee80211_rx_mesh_check(rx);
1491 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1492 ieee80211_is_pspoll(hdr->frame_control)) &&
1493 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1494 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1495 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1497 * accept port control frames from the AP even when it's not
1498 * yet marked ASSOC to prevent a race where we don't set the
1499 * assoc bit quickly enough before it sends the first frame
1501 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1502 ieee80211_is_data_present(hdr->frame_control)) {
1503 unsigned int hdrlen;
1506 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1508 if (rx->skb->len < hdrlen + 8)
1509 return RX_DROP_MONITOR;
1511 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1512 if (ethertype == rx->sdata->control_port_protocol)
1516 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1517 cfg80211_rx_spurious_frame(rx->sdata->dev,
1520 return RX_DROP_U_SPURIOUS;
1522 return RX_DROP_MONITOR;
1529 static ieee80211_rx_result debug_noinline
1530 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1532 struct ieee80211_local *local;
1533 struct ieee80211_hdr *hdr;
1534 struct sk_buff *skb;
1538 hdr = (struct ieee80211_hdr *) skb->data;
1540 if (!local->pspolling)
1543 if (!ieee80211_has_fromds(hdr->frame_control))
1544 /* this is not from AP */
1547 if (!ieee80211_is_data(hdr->frame_control))
1550 if (!ieee80211_has_moredata(hdr->frame_control)) {
1551 /* AP has no more frames buffered for us */
1552 local->pspolling = false;
1556 /* more data bit is set, let's request a new frame from the AP */
1557 ieee80211_send_pspoll(local, rx->sdata);
1562 static void sta_ps_start(struct sta_info *sta)
1564 struct ieee80211_sub_if_data *sdata = sta->sdata;
1565 struct ieee80211_local *local = sdata->local;
1569 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1570 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1571 ps = &sdata->bss->ps;
1575 atomic_inc(&ps->num_sta_ps);
1576 set_sta_flag(sta, WLAN_STA_PS_STA);
1577 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1578 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1579 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1580 sta->sta.addr, sta->sta.aid);
1582 ieee80211_clear_fast_xmit(sta);
1584 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1585 struct ieee80211_txq *txq = sta->sta.txq[tid];
1586 struct txq_info *txqi = to_txq_info(txq);
1588 spin_lock(&local->active_txq_lock[txq->ac]);
1589 if (!list_empty(&txqi->schedule_order))
1590 list_del_init(&txqi->schedule_order);
1591 spin_unlock(&local->active_txq_lock[txq->ac]);
1593 if (txq_has_queue(txq))
1594 set_bit(tid, &sta->txq_buffered_tids);
1596 clear_bit(tid, &sta->txq_buffered_tids);
1600 static void sta_ps_end(struct sta_info *sta)
1602 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1603 sta->sta.addr, sta->sta.aid);
1605 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1607 * Clear the flag only if the other one is still set
1608 * so that the TX path won't start TX'ing new frames
1609 * directly ... In the case that the driver flag isn't
1610 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1612 clear_sta_flag(sta, WLAN_STA_PS_STA);
1613 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1614 sta->sta.addr, sta->sta.aid);
1618 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1619 clear_sta_flag(sta, WLAN_STA_PS_STA);
1620 ieee80211_sta_ps_deliver_wakeup(sta);
1623 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1625 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1628 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1630 /* Don't let the same PS state be set twice */
1631 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1632 if ((start && in_ps) || (!start && !in_ps))
1642 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1644 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1646 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1648 if (test_sta_flag(sta, WLAN_STA_SP))
1651 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1652 ieee80211_sta_ps_deliver_poll_response(sta);
1654 set_sta_flag(sta, WLAN_STA_PSPOLL);
1656 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1658 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1660 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1661 int ac = ieee80211_ac_from_tid(tid);
1664 * If this AC is not trigger-enabled do nothing unless the
1665 * driver is calling us after it already checked.
1667 * NB: This could/should check a separate bitmap of trigger-
1668 * enabled queues, but for now we only implement uAPSD w/o
1669 * TSPEC changes to the ACs, so they're always the same.
1671 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1672 tid != IEEE80211_NUM_TIDS)
1675 /* if we are in a service period, do nothing */
1676 if (test_sta_flag(sta, WLAN_STA_SP))
1679 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1680 ieee80211_sta_ps_deliver_uapsd(sta);
1682 set_sta_flag(sta, WLAN_STA_UAPSD);
1684 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1686 static ieee80211_rx_result debug_noinline
1687 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1689 struct ieee80211_sub_if_data *sdata = rx->sdata;
1690 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1691 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1696 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1697 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1701 * The device handles station powersave, so don't do anything about
1702 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1703 * it to mac80211 since they're handled.)
1705 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1709 * Don't do anything if the station isn't already asleep. In
1710 * the uAPSD case, the station will probably be marked asleep,
1711 * in the PS-Poll case the station must be confused ...
1713 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1716 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1717 ieee80211_sta_pspoll(&rx->sta->sta);
1719 /* Free PS Poll skb here instead of returning RX_DROP that would
1720 * count as an dropped frame. */
1721 dev_kfree_skb(rx->skb);
1724 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1725 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1726 ieee80211_has_pm(hdr->frame_control) &&
1727 (ieee80211_is_data_qos(hdr->frame_control) ||
1728 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1729 u8 tid = ieee80211_get_tid(hdr);
1731 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1737 static ieee80211_rx_result debug_noinline
1738 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1740 struct sta_info *sta = rx->sta;
1741 struct link_sta_info *link_sta = rx->link_sta;
1742 struct sk_buff *skb = rx->skb;
1743 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1744 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1747 if (!sta || !link_sta)
1751 * Update last_rx only for IBSS packets which are for the current
1752 * BSSID and for station already AUTHORIZED to avoid keeping the
1753 * current IBSS network alive in cases where other STAs start
1754 * using different BSSID. This will also give the station another
1755 * chance to restart the authentication/authorization in case
1756 * something went wrong the first time.
1758 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1759 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1760 NL80211_IFTYPE_ADHOC);
1761 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1762 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1763 link_sta->rx_stats.last_rx = jiffies;
1764 if (ieee80211_is_data_present(hdr->frame_control) &&
1765 !is_multicast_ether_addr(hdr->addr1))
1766 link_sta->rx_stats.last_rate =
1767 sta_stats_encode_rate(status);
1769 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1770 link_sta->rx_stats.last_rx = jiffies;
1771 } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
1772 !is_multicast_ether_addr(hdr->addr1)) {
1774 * Mesh beacons will update last_rx when if they are found to
1775 * match the current local configuration when processed.
1777 link_sta->rx_stats.last_rx = jiffies;
1778 if (ieee80211_is_data_present(hdr->frame_control))
1779 link_sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1782 link_sta->rx_stats.fragments++;
1784 u64_stats_update_begin(&link_sta->rx_stats.syncp);
1785 link_sta->rx_stats.bytes += rx->skb->len;
1786 u64_stats_update_end(&link_sta->rx_stats.syncp);
1788 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1789 link_sta->rx_stats.last_signal = status->signal;
1790 ewma_signal_add(&link_sta->rx_stats_avg.signal,
1794 if (status->chains) {
1795 link_sta->rx_stats.chains = status->chains;
1796 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1797 int signal = status->chain_signal[i];
1799 if (!(status->chains & BIT(i)))
1802 link_sta->rx_stats.chain_signal_last[i] = signal;
1803 ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
1808 if (ieee80211_is_s1g_beacon(hdr->frame_control))
1812 * Change STA power saving mode only at the end of a frame
1813 * exchange sequence, and only for a data or management
1814 * frame as specified in IEEE 802.11-2016 11.2.3.2
1816 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1817 !ieee80211_has_morefrags(hdr->frame_control) &&
1818 !is_multicast_ether_addr(hdr->addr1) &&
1819 (ieee80211_is_mgmt(hdr->frame_control) ||
1820 ieee80211_is_data(hdr->frame_control)) &&
1821 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1822 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1823 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1824 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1825 if (!ieee80211_has_pm(hdr->frame_control))
1828 if (ieee80211_has_pm(hdr->frame_control))
1833 /* mesh power save support */
1834 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1835 ieee80211_mps_rx_h_sta_process(sta, hdr);
1838 * Drop (qos-)data::nullfunc frames silently, since they
1839 * are used only to control station power saving mode.
1841 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1842 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1845 * If we receive a 4-addr nullfunc frame from a STA
1846 * that was not moved to a 4-addr STA vlan yet send
1847 * the event to userspace and for older hostapd drop
1848 * the frame to the monitor interface.
1850 if (ieee80211_has_a4(hdr->frame_control) &&
1851 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1852 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1853 !rx->sdata->u.vlan.sta))) {
1854 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1855 cfg80211_rx_unexpected_4addr_frame(
1856 rx->sdata->dev, sta->sta.addr,
1858 return RX_DROP_M_UNEXPECTED_4ADDR_FRAME;
1861 * Update counter and free packet here to avoid
1862 * counting this as a dropped packed.
1864 link_sta->rx_stats.packets++;
1865 dev_kfree_skb(rx->skb);
1870 } /* ieee80211_rx_h_sta_process */
1872 static struct ieee80211_key *
1873 ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
1875 struct ieee80211_key *key = NULL;
1878 /* Make sure key gets set if either BIGTK key index is set so that
1879 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1880 * Beacon frames and Beacon frames that claim to use another BIGTK key
1881 * index (i.e., a key that we do not have).
1885 idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1888 if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1895 key = rcu_dereference(rx->link_sta->gtk[idx]);
1897 key = rcu_dereference(rx->link->gtk[idx]);
1898 if (!key && rx->link_sta)
1899 key = rcu_dereference(rx->link_sta->gtk[idx2]);
1901 key = rcu_dereference(rx->link->gtk[idx2]);
1906 static ieee80211_rx_result debug_noinline
1907 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1909 struct sk_buff *skb = rx->skb;
1910 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1911 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1913 ieee80211_rx_result result = RX_DROP_U_DECRYPT_FAIL;
1914 struct ieee80211_key *sta_ptk = NULL;
1915 struct ieee80211_key *ptk_idx = NULL;
1916 int mmie_keyidx = -1;
1919 if (ieee80211_is_ext(hdr->frame_control))
1925 * There are five types of keys:
1926 * - GTK (group keys)
1927 * - IGTK (group keys for management frames)
1928 * - BIGTK (group keys for Beacon frames)
1929 * - PTK (pairwise keys)
1930 * - STK (station-to-station pairwise keys)
1932 * When selecting a key, we have to distinguish between multicast
1933 * (including broadcast) and unicast frames, the latter can only
1934 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1935 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1936 * then unicast frames can also use key indices like GTKs. Hence, if we
1937 * don't have a PTK/STK we check the key index for a WEP key.
1939 * Note that in a regular BSS, multicast frames are sent by the
1940 * AP only, associated stations unicast the frame to the AP first
1941 * which then multicasts it on their behalf.
1943 * There is also a slight problem in IBSS mode: GTKs are negotiated
1944 * with each station, that is something we don't currently handle.
1945 * The spec seems to expect that one negotiates the same key with
1946 * every station but there's no such requirement; VLANs could be
1950 /* start without a key */
1952 fc = hdr->frame_control;
1955 int keyid = rx->sta->ptk_idx;
1956 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1958 if (ieee80211_has_protected(fc) &&
1959 !(status->flag & RX_FLAG_IV_STRIPPED)) {
1960 keyid = ieee80211_get_keyid(rx->skb);
1962 if (unlikely(keyid < 0))
1963 return RX_DROP_U_NO_KEY_ID;
1965 ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1969 if (!ieee80211_has_protected(fc))
1970 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1972 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1973 rx->key = ptk_idx ? ptk_idx : sta_ptk;
1974 if ((status->flag & RX_FLAG_DECRYPTED) &&
1975 (status->flag & RX_FLAG_IV_STRIPPED))
1977 /* Skip decryption if the frame is not protected. */
1978 if (!ieee80211_has_protected(fc))
1980 } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
1981 /* Broadcast/multicast robust management frame / BIP */
1982 if ((status->flag & RX_FLAG_DECRYPTED) &&
1983 (status->flag & RX_FLAG_IV_STRIPPED))
1986 if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
1987 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
1988 NUM_DEFAULT_BEACON_KEYS) {
1990 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1993 return RX_DROP_M_BAD_BCN_KEYIDX;
1996 rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
1998 return RX_CONTINUE; /* Beacon protection not in use */
1999 } else if (mmie_keyidx >= 0) {
2000 /* Broadcast/multicast robust management frame / BIP */
2001 if ((status->flag & RX_FLAG_DECRYPTED) &&
2002 (status->flag & RX_FLAG_IV_STRIPPED))
2005 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
2006 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
2007 return RX_DROP_M_BAD_MGMT_KEYIDX; /* unexpected BIP keyidx */
2009 if (ieee80211_is_group_privacy_action(skb) &&
2010 test_sta_flag(rx->sta, WLAN_STA_MFP))
2011 return RX_DROP_MONITOR;
2013 rx->key = rcu_dereference(rx->link_sta->gtk[mmie_keyidx]);
2016 rx->key = rcu_dereference(rx->link->gtk[mmie_keyidx]);
2017 } else if (!ieee80211_has_protected(fc)) {
2019 * The frame was not protected, so skip decryption. However, we
2020 * need to set rx->key if there is a key that could have been
2021 * used so that the frame may be dropped if encryption would
2022 * have been expected.
2024 struct ieee80211_key *key = NULL;
2027 if (ieee80211_is_beacon(fc)) {
2028 key = ieee80211_rx_get_bigtk(rx, -1);
2029 } else if (ieee80211_is_mgmt(fc) &&
2030 is_multicast_ether_addr(hdr->addr1)) {
2031 key = rcu_dereference(rx->link->default_mgmt_key);
2034 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2035 key = rcu_dereference(rx->link_sta->gtk[i]);
2041 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2042 key = rcu_dereference(rx->link->gtk[i]);
2053 * The device doesn't give us the IV so we won't be
2054 * able to look up the key. That's ok though, we
2055 * don't need to decrypt the frame, we just won't
2056 * be able to keep statistics accurate.
2057 * Except for key threshold notifications, should
2058 * we somehow allow the driver to tell us which key
2059 * the hardware used if this flag is set?
2061 if ((status->flag & RX_FLAG_DECRYPTED) &&
2062 (status->flag & RX_FLAG_IV_STRIPPED))
2065 keyidx = ieee80211_get_keyid(rx->skb);
2067 if (unlikely(keyidx < 0))
2068 return RX_DROP_U_NO_KEY_ID;
2070 /* check per-station GTK first, if multicast packet */
2071 if (is_multicast_ether_addr(hdr->addr1) && rx->link_sta)
2072 rx->key = rcu_dereference(rx->link_sta->gtk[keyidx]);
2074 /* if not found, try default key */
2076 if (is_multicast_ether_addr(hdr->addr1))
2077 rx->key = rcu_dereference(rx->link->gtk[keyidx]);
2079 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
2082 * RSNA-protected unicast frames should always be
2083 * sent with pairwise or station-to-station keys,
2084 * but for WEP we allow using a key index as well.
2087 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2088 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2089 !is_multicast_ether_addr(hdr->addr1))
2095 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2096 return RX_DROP_MONITOR;
2098 /* TODO: add threshold stuff again */
2100 return RX_DROP_MONITOR;
2103 switch (rx->key->conf.cipher) {
2104 case WLAN_CIPHER_SUITE_WEP40:
2105 case WLAN_CIPHER_SUITE_WEP104:
2106 result = ieee80211_crypto_wep_decrypt(rx);
2108 case WLAN_CIPHER_SUITE_TKIP:
2109 result = ieee80211_crypto_tkip_decrypt(rx);
2111 case WLAN_CIPHER_SUITE_CCMP:
2112 result = ieee80211_crypto_ccmp_decrypt(
2113 rx, IEEE80211_CCMP_MIC_LEN);
2115 case WLAN_CIPHER_SUITE_CCMP_256:
2116 result = ieee80211_crypto_ccmp_decrypt(
2117 rx, IEEE80211_CCMP_256_MIC_LEN);
2119 case WLAN_CIPHER_SUITE_AES_CMAC:
2120 result = ieee80211_crypto_aes_cmac_decrypt(rx);
2122 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2123 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2125 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2126 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2127 result = ieee80211_crypto_aes_gmac_decrypt(rx);
2129 case WLAN_CIPHER_SUITE_GCMP:
2130 case WLAN_CIPHER_SUITE_GCMP_256:
2131 result = ieee80211_crypto_gcmp_decrypt(rx);
2134 result = RX_DROP_U_BAD_CIPHER;
2137 /* the hdr variable is invalid after the decrypt handlers */
2139 /* either the frame has been decrypted or will be dropped */
2140 status->flag |= RX_FLAG_DECRYPTED;
2142 if (unlikely(ieee80211_is_beacon(fc) && RX_RES_IS_UNUSABLE(result) &&
2144 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2145 skb->data, skb->len);
2150 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2154 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2155 skb_queue_head_init(&cache->entries[i].skb_list);
2158 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2162 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2163 __skb_queue_purge(&cache->entries[i].skb_list);
2166 static inline struct ieee80211_fragment_entry *
2167 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2168 unsigned int frag, unsigned int seq, int rx_queue,
2169 struct sk_buff **skb)
2171 struct ieee80211_fragment_entry *entry;
2173 entry = &cache->entries[cache->next++];
2174 if (cache->next >= IEEE80211_FRAGMENT_MAX)
2177 __skb_queue_purge(&entry->skb_list);
2179 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2181 entry->first_frag_time = jiffies;
2183 entry->rx_queue = rx_queue;
2184 entry->last_frag = frag;
2185 entry->check_sequential_pn = false;
2186 entry->extra_len = 0;
2191 static inline struct ieee80211_fragment_entry *
2192 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2193 unsigned int frag, unsigned int seq,
2194 int rx_queue, struct ieee80211_hdr *hdr)
2196 struct ieee80211_fragment_entry *entry;
2200 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2201 struct ieee80211_hdr *f_hdr;
2202 struct sk_buff *f_skb;
2206 idx = IEEE80211_FRAGMENT_MAX - 1;
2208 entry = &cache->entries[idx];
2209 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2210 entry->rx_queue != rx_queue ||
2211 entry->last_frag + 1 != frag)
2214 f_skb = __skb_peek(&entry->skb_list);
2215 f_hdr = (struct ieee80211_hdr *) f_skb->data;
2218 * Check ftype and addresses are equal, else check next fragment
2220 if (((hdr->frame_control ^ f_hdr->frame_control) &
2221 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2222 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2223 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2226 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2227 __skb_queue_purge(&entry->skb_list);
2236 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2239 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2240 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2241 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2242 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2243 ieee80211_has_protected(fc);
2246 static ieee80211_rx_result debug_noinline
2247 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2249 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2250 struct ieee80211_hdr *hdr;
2253 unsigned int frag, seq;
2254 struct ieee80211_fragment_entry *entry;
2255 struct sk_buff *skb;
2256 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2258 hdr = (struct ieee80211_hdr *)rx->skb->data;
2259 fc = hdr->frame_control;
2261 if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
2264 sc = le16_to_cpu(hdr->seq_ctrl);
2265 frag = sc & IEEE80211_SCTL_FRAG;
2268 cache = &rx->sta->frags;
2270 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2273 if (is_multicast_ether_addr(hdr->addr1))
2274 return RX_DROP_MONITOR;
2276 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2278 if (skb_linearize(rx->skb))
2279 return RX_DROP_U_OOM;
2282 * skb_linearize() might change the skb->data and
2283 * previously cached variables (in this case, hdr) need to
2284 * be refreshed with the new data.
2286 hdr = (struct ieee80211_hdr *)rx->skb->data;
2287 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2290 /* This is the first fragment of a new frame. */
2291 entry = ieee80211_reassemble_add(cache, frag, seq,
2292 rx->seqno_idx, &(rx->skb));
2293 if (requires_sequential_pn(rx, fc)) {
2294 int queue = rx->security_idx;
2296 /* Store CCMP/GCMP PN so that we can verify that the
2297 * next fragment has a sequential PN value.
2299 entry->check_sequential_pn = true;
2300 entry->is_protected = true;
2301 entry->key_color = rx->key->color;
2302 memcpy(entry->last_pn,
2303 rx->key->u.ccmp.rx_pn[queue],
2304 IEEE80211_CCMP_PN_LEN);
2305 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2307 offsetof(struct ieee80211_key,
2309 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2310 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2311 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2312 IEEE80211_GCMP_PN_LEN);
2313 } else if (rx->key &&
2314 (ieee80211_has_protected(fc) ||
2315 (status->flag & RX_FLAG_DECRYPTED))) {
2316 entry->is_protected = true;
2317 entry->key_color = rx->key->color;
2322 /* This is a fragment for a frame that should already be pending in
2323 * fragment cache. Add this fragment to the end of the pending entry.
2325 entry = ieee80211_reassemble_find(cache, frag, seq,
2326 rx->seqno_idx, hdr);
2328 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2329 return RX_DROP_MONITOR;
2332 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2333 * MPDU PN values are not incrementing in steps of 1."
2334 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2335 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2337 if (entry->check_sequential_pn) {
2339 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2341 if (!requires_sequential_pn(rx, fc))
2342 return RX_DROP_U_NONSEQ_PN;
2344 /* Prevent mixed key and fragment cache attacks */
2345 if (entry->key_color != rx->key->color)
2346 return RX_DROP_U_BAD_KEY_COLOR;
2348 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2349 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2355 rpn = rx->ccm_gcm.pn;
2356 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2357 return RX_DROP_U_REPLAY;
2358 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2359 } else if (entry->is_protected &&
2361 (!ieee80211_has_protected(fc) &&
2362 !(status->flag & RX_FLAG_DECRYPTED)) ||
2363 rx->key->color != entry->key_color)) {
2364 /* Drop this as a mixed key or fragment cache attack, even
2365 * if for TKIP Michael MIC should protect us, and WEP is a
2366 * lost cause anyway.
2368 return RX_DROP_U_EXPECT_DEFRAG_PROT;
2369 } else if (entry->is_protected && rx->key &&
2370 entry->key_color != rx->key->color &&
2371 (status->flag & RX_FLAG_DECRYPTED)) {
2372 return RX_DROP_U_BAD_KEY_COLOR;
2375 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2376 __skb_queue_tail(&entry->skb_list, rx->skb);
2377 entry->last_frag = frag;
2378 entry->extra_len += rx->skb->len;
2379 if (ieee80211_has_morefrags(fc)) {
2384 rx->skb = __skb_dequeue(&entry->skb_list);
2385 if (skb_tailroom(rx->skb) < entry->extra_len) {
2386 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2387 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2389 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2390 __skb_queue_purge(&entry->skb_list);
2391 return RX_DROP_U_OOM;
2394 while ((skb = __skb_dequeue(&entry->skb_list))) {
2395 skb_put_data(rx->skb, skb->data, skb->len);
2400 ieee80211_led_rx(rx->local);
2402 rx->link_sta->rx_stats.packets++;
2406 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2408 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2414 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2416 struct sk_buff *skb = rx->skb;
2417 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2420 * Pass through unencrypted frames if the hardware has
2421 * decrypted them already.
2423 if (status->flag & RX_FLAG_DECRYPTED)
2426 /* Drop unencrypted frames if key is set. */
2427 if (unlikely(!ieee80211_has_protected(fc) &&
2428 !ieee80211_is_any_nullfunc(fc) &&
2429 ieee80211_is_data(fc) && rx->key))
2435 VISIBLE_IF_MAC80211_KUNIT ieee80211_rx_result
2436 ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2438 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2439 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2440 __le16 fc = mgmt->frame_control;
2443 * Pass through unencrypted frames if the hardware has
2444 * decrypted them already.
2446 if (status->flag & RX_FLAG_DECRYPTED)
2449 /* drop unicast protected dual (that wasn't protected) */
2450 if (ieee80211_is_action(fc) &&
2451 mgmt->u.action.category == WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION)
2452 return RX_DROP_U_UNPROT_DUAL;
2454 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2455 if (unlikely(!ieee80211_has_protected(fc) &&
2456 ieee80211_is_unicast_robust_mgmt_frame(rx->skb))) {
2457 if (ieee80211_is_deauth(fc) ||
2458 ieee80211_is_disassoc(fc)) {
2460 * Permit unprotected deauth/disassoc frames
2461 * during 4-way-HS (key is installed after HS).
2466 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2470 return RX_DROP_U_UNPROT_UCAST_MGMT;
2472 /* BIP does not use Protected field, so need to check MMIE */
2473 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2474 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2475 if (ieee80211_is_deauth(fc) ||
2476 ieee80211_is_disassoc(fc))
2477 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2480 return RX_DROP_U_UNPROT_MCAST_MGMT;
2482 if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
2483 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2484 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2487 return RX_DROP_U_UNPROT_BEACON;
2490 * When using MFP, Action frames are not allowed prior to
2491 * having configured keys.
2493 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2494 ieee80211_is_robust_mgmt_frame(rx->skb)))
2495 return RX_DROP_U_UNPROT_ACTION;
2497 /* drop unicast public action frames when using MPF */
2498 if (is_unicast_ether_addr(mgmt->da) &&
2499 ieee80211_is_protected_dual_of_public_action(rx->skb))
2500 return RX_DROP_U_UNPROT_UNICAST_PUB_ACTION;
2504 * Drop robust action frames before assoc regardless of MFP state,
2505 * after assoc we also have decided on MFP or not.
2507 if (ieee80211_is_action(fc) &&
2508 ieee80211_is_robust_mgmt_frame(rx->skb) &&
2509 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))
2510 return RX_DROP_U_UNPROT_ROBUST_ACTION;
2514 EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_drop_unencrypted_mgmt);
2516 static ieee80211_rx_result
2517 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2519 struct ieee80211_sub_if_data *sdata = rx->sdata;
2520 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2521 bool check_port_control = false;
2522 struct ethhdr *ehdr;
2525 *port_control = false;
2526 if (ieee80211_has_a4(hdr->frame_control) &&
2527 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2528 return RX_DROP_U_UNEXPECTED_VLAN_4ADDR;
2530 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2531 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2532 if (!sdata->u.mgd.use_4addr)
2533 return RX_DROP_U_UNEXPECTED_STA_4ADDR;
2534 else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2535 check_port_control = true;
2538 if (is_multicast_ether_addr(hdr->addr1) &&
2539 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2540 return RX_DROP_U_UNEXPECTED_VLAN_MCAST;
2542 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2544 return RX_DROP_U_INVALID_8023;
2546 ehdr = (struct ethhdr *) rx->skb->data;
2547 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2548 *port_control = true;
2549 else if (check_port_control)
2550 return RX_DROP_U_NOT_PORT_CONTROL;
2555 bool ieee80211_is_our_addr(struct ieee80211_sub_if_data *sdata,
2556 const u8 *addr, int *out_link_id)
2558 unsigned int link_id;
2560 /* non-MLO, or MLD address replaced by hardware */
2561 if (ether_addr_equal(sdata->vif.addr, addr))
2564 if (!ieee80211_vif_is_mld(&sdata->vif))
2567 for (link_id = 0; link_id < ARRAY_SIZE(sdata->vif.link_conf); link_id++) {
2568 struct ieee80211_bss_conf *conf;
2570 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2574 if (ether_addr_equal(conf->addr, addr)) {
2576 *out_link_id = link_id;
2585 * requires that rx->skb is a frame with ethernet header
2587 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2589 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2590 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2591 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2594 * Allow EAPOL frames to us/the PAE group address regardless of
2595 * whether the frame was encrypted or not, and always disallow
2596 * all other destination addresses for them.
2598 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2599 return ieee80211_is_our_addr(rx->sdata, ehdr->h_dest, NULL) ||
2600 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2602 if (ieee80211_802_1x_port_control(rx) ||
2603 ieee80211_drop_unencrypted(rx, fc))
2609 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2610 struct ieee80211_rx_data *rx)
2612 struct ieee80211_sub_if_data *sdata = rx->sdata;
2613 struct net_device *dev = sdata->dev;
2615 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2616 (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
2617 !sdata->control_port_no_preauth)) &&
2618 sdata->control_port_over_nl80211)) {
2619 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2620 bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2622 cfg80211_rx_control_port(dev, skb, noencrypt, rx->link_id);
2625 struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2627 memset(skb->cb, 0, sizeof(skb->cb));
2630 * 802.1X over 802.11 requires that the authenticator address
2631 * be used for EAPOL frames. However, 802.1X allows the use of
2632 * the PAE group address instead. If the interface is part of
2633 * a bridge and we pass the frame with the PAE group address,
2634 * then the bridge will forward it to the network (even if the
2635 * client was not associated yet), which isn't supposed to
2637 * To avoid that, rewrite the destination address to our own
2638 * address, so that the authenticator (e.g. hostapd) will see
2639 * the frame, but bridge won't forward it anywhere else. Note
2640 * that due to earlier filtering, the only other address can
2641 * be the PAE group address, unless the hardware allowed them
2642 * through in 802.3 offloaded mode.
2644 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2645 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2646 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2648 /* deliver to local stack */
2650 list_add_tail(&skb->list, rx->list);
2652 netif_receive_skb(skb);
2657 * requires that rx->skb is a frame with ethernet header
2660 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2662 struct ieee80211_sub_if_data *sdata = rx->sdata;
2663 struct net_device *dev = sdata->dev;
2664 struct sk_buff *skb, *xmit_skb;
2665 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2666 struct sta_info *dsta;
2671 dev_sw_netstats_rx_add(dev, skb->len);
2674 /* The seqno index has the same property as needed
2675 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2676 * for non-QoS-data frames. Here we know it's a data
2677 * frame, so count MSDUs.
2679 u64_stats_update_begin(&rx->link_sta->rx_stats.syncp);
2680 rx->link_sta->rx_stats.msdu[rx->seqno_idx]++;
2681 u64_stats_update_end(&rx->link_sta->rx_stats.syncp);
2684 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2685 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2686 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2687 ehdr->h_proto != rx->sdata->control_port_protocol &&
2688 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2689 if (is_multicast_ether_addr(ehdr->h_dest) &&
2690 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2692 * send multicast frames both to higher layers in
2693 * local net stack and back to the wireless medium
2695 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2697 net_info_ratelimited("%s: failed to clone multicast frame\n",
2699 } else if (!is_multicast_ether_addr(ehdr->h_dest) &&
2700 !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
2701 dsta = sta_info_get(sdata, ehdr->h_dest);
2704 * The destination station is associated to
2705 * this AP (in this VLAN), so send the frame
2706 * directly to it and do not pass it to local
2715 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2717 /* 'align' will only take the values 0 or 2 here since all
2718 * frames are required to be aligned to 2-byte boundaries
2719 * when being passed to mac80211; the code here works just
2720 * as well if that isn't true, but mac80211 assumes it can
2721 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2725 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2727 if (WARN_ON(skb_headroom(skb) < 3)) {
2731 u8 *data = skb->data;
2732 size_t len = skb_headlen(skb);
2734 memmove(skb->data, data, len);
2735 skb_set_tail_pointer(skb, len);
2742 skb->protocol = eth_type_trans(skb, dev);
2743 ieee80211_deliver_skb_to_local_stack(skb, rx);
2748 * Send to wireless media and increase priority by 256 to
2749 * keep the received priority instead of reclassifying
2750 * the frame (see cfg80211_classify8021d).
2752 xmit_skb->priority += 256;
2753 xmit_skb->protocol = htons(ETH_P_802_3);
2754 skb_reset_network_header(xmit_skb);
2755 skb_reset_mac_header(xmit_skb);
2756 dev_queue_xmit(xmit_skb);
2760 #ifdef CONFIG_MAC80211_MESH
2762 ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata,
2763 struct sk_buff *skb, int hdrlen)
2765 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2766 struct ieee80211_mesh_fast_tx *entry = NULL;
2767 struct ieee80211s_hdr *mesh_hdr;
2768 struct tid_ampdu_tx *tid_tx;
2769 struct sta_info *sta;
2773 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(eth));
2774 if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
2775 entry = mesh_fast_tx_get(sdata, mesh_hdr->eaddr1);
2776 else if (!(mesh_hdr->flags & MESH_FLAGS_AE))
2777 entry = mesh_fast_tx_get(sdata, skb->data);
2781 sta = rcu_dereference(entry->mpath->next_hop);
2785 if (skb_linearize(skb))
2788 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
2789 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
2791 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
2794 if (tid_tx->timeout)
2795 tid_tx->last_tx = jiffies;
2798 ieee80211_aggr_check(sdata, sta, skb);
2800 if (ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
2804 skb->protocol = htons(skb->len - hdrlen);
2805 skb_set_network_header(skb, hdrlen + 2);
2807 skb->dev = sdata->dev;
2808 memcpy(ð, skb->data, ETH_HLEN - 2);
2810 __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
2811 eth.h_dest, eth.h_source);
2812 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2813 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2819 static ieee80211_rx_result
2820 ieee80211_rx_mesh_data(struct ieee80211_sub_if_data *sdata, struct sta_info *sta,
2821 struct sk_buff *skb)
2823 #ifdef CONFIG_MAC80211_MESH
2824 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2825 struct ieee80211_local *local = sdata->local;
2826 uint16_t fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA;
2827 struct ieee80211_hdr hdr = {
2828 .frame_control = cpu_to_le16(fc)
2830 struct ieee80211_hdr *fwd_hdr;
2831 struct ieee80211s_hdr *mesh_hdr;
2832 struct ieee80211_tx_info *info;
2833 struct sk_buff *fwd_skb;
2837 int hdrlen, mesh_hdrlen;
2840 if (!ieee80211_vif_is_mesh(&sdata->vif))
2843 if (!pskb_may_pull(skb, sizeof(*eth) + 6))
2844 return RX_DROP_MONITOR;
2846 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(*eth));
2847 mesh_hdrlen = ieee80211_get_mesh_hdrlen(mesh_hdr);
2849 if (!pskb_may_pull(skb, sizeof(*eth) + mesh_hdrlen))
2850 return RX_DROP_MONITOR;
2852 eth = (struct ethhdr *)skb->data;
2853 multicast = is_multicast_ether_addr(eth->h_dest);
2855 mesh_hdr = (struct ieee80211s_hdr *)(eth + 1);
2857 return RX_DROP_MONITOR;
2859 /* frame is in RMC, don't forward */
2860 if (is_multicast_ether_addr(eth->h_dest) &&
2861 mesh_rmc_check(sdata, eth->h_source, mesh_hdr))
2862 return RX_DROP_MONITOR;
2864 /* forward packet */
2865 if (sdata->crypto_tx_tailroom_needed_cnt)
2866 tailroom = IEEE80211_ENCRYPT_TAILROOM;
2868 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2869 struct mesh_path *mppath;
2871 bool update = false;
2874 proxied_addr = mesh_hdr->eaddr1;
2875 else if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
2876 /* has_a4 already checked in ieee80211_rx_mesh_check */
2877 proxied_addr = mesh_hdr->eaddr2;
2879 return RX_DROP_MONITOR;
2882 mppath = mpp_path_lookup(sdata, proxied_addr);
2884 mpp_path_add(sdata, proxied_addr, eth->h_source);
2886 spin_lock_bh(&mppath->state_lock);
2887 if (!ether_addr_equal(mppath->mpp, eth->h_source)) {
2888 memcpy(mppath->mpp, eth->h_source, ETH_ALEN);
2891 mppath->exp_time = jiffies;
2892 spin_unlock_bh(&mppath->state_lock);
2895 /* flush fast xmit cache if the address path changed */
2897 mesh_fast_tx_flush_addr(sdata, proxied_addr);
2902 /* Frame has reached destination. Don't forward */
2903 if (ether_addr_equal(sdata->vif.addr, eth->h_dest))
2906 if (!--mesh_hdr->ttl) {
2910 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
2911 return RX_DROP_MONITOR;
2914 if (!ifmsh->mshcfg.dot11MeshForwarding) {
2915 if (is_multicast_ether_addr(eth->h_dest))
2918 return RX_DROP_MONITOR;
2921 skb_set_queue_mapping(skb, ieee802_1d_to_ac[skb->priority]);
2924 ieee80211_rx_mesh_fast_forward(sdata, skb, mesh_hdrlen))
2927 ieee80211_fill_mesh_addresses(&hdr, &hdr.frame_control,
2928 eth->h_dest, eth->h_source);
2929 hdrlen = ieee80211_hdrlen(hdr.frame_control);
2931 int extra_head = sizeof(struct ieee80211_hdr) - sizeof(*eth);
2933 fwd_skb = skb_copy_expand(skb, local->tx_headroom + extra_head +
2934 IEEE80211_ENCRYPT_HEADROOM,
2935 tailroom, GFP_ATOMIC);
2942 if (skb_cow_head(fwd_skb, hdrlen - sizeof(struct ethhdr)))
2943 return RX_DROP_U_OOM;
2945 if (skb_linearize(fwd_skb))
2946 return RX_DROP_U_OOM;
2949 fwd_hdr = skb_push(fwd_skb, hdrlen - sizeof(struct ethhdr));
2950 memcpy(fwd_hdr, &hdr, hdrlen - 2);
2951 qos = ieee80211_get_qos_ctl(fwd_hdr);
2952 qos[0] = qos[1] = 0;
2954 skb_reset_mac_header(fwd_skb);
2955 hdrlen += mesh_hdrlen;
2956 if (ieee80211_get_8023_tunnel_proto(fwd_skb->data + hdrlen,
2957 &fwd_skb->protocol))
2960 fwd_skb->protocol = htons(fwd_skb->len - hdrlen);
2961 skb_set_network_header(fwd_skb, hdrlen + 2);
2963 info = IEEE80211_SKB_CB(fwd_skb);
2964 memset(info, 0, sizeof(*info));
2965 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
2966 info->control.vif = &sdata->vif;
2967 info->control.jiffies = jiffies;
2968 fwd_skb->dev = sdata->dev;
2970 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2971 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2972 /* update power mode indication when forwarding */
2973 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2974 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2975 /* mesh power mode flags updated in mesh_nexthop_lookup */
2976 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2978 /* unable to resolve next hop */
2980 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2982 WLAN_REASON_MESH_PATH_NOFORWARD,
2984 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2989 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2990 ieee80211_add_pending_skb(local, fwd_skb);
2996 ieee80211_strip_8023_mesh_hdr(skb);
3002 static ieee80211_rx_result debug_noinline
3003 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
3005 struct net_device *dev = rx->sdata->dev;
3006 struct sk_buff *skb = rx->skb;
3007 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3008 __le16 fc = hdr->frame_control;
3009 struct sk_buff_head frame_list;
3010 ieee80211_rx_result res;
3011 struct ethhdr ethhdr;
3012 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
3014 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
3017 } else switch (rx->sdata->vif.type) {
3018 case NL80211_IFTYPE_AP:
3019 case NL80211_IFTYPE_AP_VLAN:
3022 case NL80211_IFTYPE_STATION:
3024 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
3027 case NL80211_IFTYPE_MESH_POINT:
3036 __skb_queue_head_init(&frame_list);
3038 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
3039 rx->sdata->vif.addr,
3040 rx->sdata->vif.type,
3042 return RX_DROP_U_BAD_AMSDU;
3044 if (rx->sta->amsdu_mesh_control < 0) {
3048 for (i = 0; i <= 2; i++) {
3049 if (!ieee80211_is_valid_amsdu(skb, i))
3061 rx->sta->amsdu_mesh_control = valid;
3064 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
3065 rx->sdata->vif.type,
3066 rx->local->hw.extra_tx_headroom,
3068 rx->sta->amsdu_mesh_control);
3070 while (!skb_queue_empty(&frame_list)) {
3071 rx->skb = __skb_dequeue(&frame_list);
3073 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
3083 if (!ieee80211_frame_allowed(rx, fc))
3086 ieee80211_deliver_skb(rx);
3090 dev_kfree_skb(rx->skb);
3096 static ieee80211_rx_result debug_noinline
3097 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
3099 struct sk_buff *skb = rx->skb;
3100 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3101 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3102 __le16 fc = hdr->frame_control;
3104 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
3107 if (unlikely(!ieee80211_is_data(fc)))
3110 if (unlikely(!ieee80211_is_data_present(fc)))
3111 return RX_DROP_MONITOR;
3113 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
3114 switch (rx->sdata->vif.type) {
3115 case NL80211_IFTYPE_AP_VLAN:
3116 if (!rx->sdata->u.vlan.sta)
3117 return RX_DROP_U_BAD_4ADDR;
3119 case NL80211_IFTYPE_STATION:
3120 if (!rx->sdata->u.mgd.use_4addr)
3121 return RX_DROP_U_BAD_4ADDR;
3123 case NL80211_IFTYPE_MESH_POINT:
3126 return RX_DROP_U_BAD_4ADDR;
3130 if (is_multicast_ether_addr(hdr->addr1) || !rx->sta)
3131 return RX_DROP_U_BAD_AMSDU;
3135 * We should not receive A-MSDUs on pre-HT connections,
3136 * and HT connections cannot use old ciphers. Thus drop
3137 * them, as in those cases we couldn't even have SPP
3140 switch (rx->key->conf.cipher) {
3141 case WLAN_CIPHER_SUITE_WEP40:
3142 case WLAN_CIPHER_SUITE_WEP104:
3143 case WLAN_CIPHER_SUITE_TKIP:
3144 return RX_DROP_U_BAD_AMSDU_CIPHER;
3150 return __ieee80211_rx_h_amsdu(rx, 0);
3153 static ieee80211_rx_result debug_noinline
3154 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
3156 struct ieee80211_sub_if_data *sdata = rx->sdata;
3157 struct ieee80211_local *local = rx->local;
3158 struct net_device *dev = sdata->dev;
3159 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
3160 __le16 fc = hdr->frame_control;
3161 ieee80211_rx_result res;
3164 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
3167 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
3168 return RX_DROP_MONITOR;
3171 * Send unexpected-4addr-frame event to hostapd. For older versions,
3172 * also drop the frame to cooked monitor interfaces.
3174 if (ieee80211_has_a4(hdr->frame_control) &&
3175 sdata->vif.type == NL80211_IFTYPE_AP) {
3177 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
3178 cfg80211_rx_unexpected_4addr_frame(
3179 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
3180 return RX_DROP_MONITOR;
3183 res = __ieee80211_data_to_8023(rx, &port_control);
3184 if (unlikely(res != RX_CONTINUE))
3187 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
3188 if (res != RX_CONTINUE)
3191 if (!ieee80211_frame_allowed(rx, fc))
3192 return RX_DROP_MONITOR;
3194 /* directly handle TDLS channel switch requests/responses */
3195 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
3196 cpu_to_be16(ETH_P_TDLS))) {
3197 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
3199 if (pskb_may_pull(rx->skb,
3200 offsetof(struct ieee80211_tdls_data, u)) &&
3201 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
3202 tf->category == WLAN_CATEGORY_TDLS &&
3203 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
3204 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
3205 rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
3206 __ieee80211_queue_skb_to_iface(sdata, rx->link_id,
3212 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3213 unlikely(port_control) && sdata->bss) {
3214 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
3222 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3223 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
3224 !is_multicast_ether_addr(
3225 ((struct ethhdr *)rx->skb->data)->h_dest) &&
3226 (!local->scanning &&
3227 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
3228 mod_timer(&local->dynamic_ps_timer, jiffies +
3229 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
3231 ieee80211_deliver_skb(rx);
3236 static ieee80211_rx_result debug_noinline
3237 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
3239 struct sk_buff *skb = rx->skb;
3240 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
3241 struct tid_ampdu_rx *tid_agg_rx;
3245 if (likely(!ieee80211_is_ctl(bar->frame_control)))
3248 if (ieee80211_is_back_req(bar->frame_control)) {
3250 __le16 control, start_seq_num;
3251 } __packed bar_data;
3252 struct ieee80211_event event = {
3253 .type = BAR_RX_EVENT,
3257 return RX_DROP_MONITOR;
3259 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
3260 &bar_data, sizeof(bar_data)))
3261 return RX_DROP_MONITOR;
3263 tid = le16_to_cpu(bar_data.control) >> 12;
3265 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
3266 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
3267 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
3268 WLAN_BACK_RECIPIENT,
3269 WLAN_REASON_QSTA_REQUIRE_SETUP);
3271 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
3273 return RX_DROP_MONITOR;
3275 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
3276 event.u.ba.tid = tid;
3277 event.u.ba.ssn = start_seq_num;
3278 event.u.ba.sta = &rx->sta->sta;
3280 /* reset session timer */
3281 if (tid_agg_rx->timeout)
3282 mod_timer(&tid_agg_rx->session_timer,
3283 TU_TO_EXP_TIME(tid_agg_rx->timeout));
3285 spin_lock(&tid_agg_rx->reorder_lock);
3286 /* release stored frames up to start of BAR */
3287 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
3288 start_seq_num, frames);
3289 spin_unlock(&tid_agg_rx->reorder_lock);
3291 drv_event_callback(rx->local, rx->sdata, &event);
3298 * After this point, we only want management frames,
3299 * so we can drop all remaining control frames to
3300 * cooked monitor interfaces.
3302 return RX_DROP_MONITOR;
3305 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
3306 struct ieee80211_mgmt *mgmt,
3309 struct ieee80211_local *local = sdata->local;
3310 struct sk_buff *skb;
3311 struct ieee80211_mgmt *resp;
3313 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
3314 /* Not to own unicast address */
3318 if (!ether_addr_equal(mgmt->sa, sdata->deflink.u.mgd.bssid) ||
3319 !ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid)) {
3320 /* Not from the current AP or not associated yet. */
3324 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3325 /* Too short SA Query request frame */
3329 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3333 skb_reserve(skb, local->hw.extra_tx_headroom);
3334 resp = skb_put_zero(skb, 24);
3335 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3336 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3337 memcpy(resp->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3338 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3339 IEEE80211_STYPE_ACTION);
3340 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3341 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3342 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3343 memcpy(resp->u.action.u.sa_query.trans_id,
3344 mgmt->u.action.u.sa_query.trans_id,
3345 WLAN_SA_QUERY_TR_ID_LEN);
3347 ieee80211_tx_skb(sdata, skb);
3351 ieee80211_rx_check_bss_color_collision(struct ieee80211_rx_data *rx)
3353 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3354 const struct element *ie;
3357 if (!wiphy_ext_feature_isset(rx->local->hw.wiphy,
3358 NL80211_EXT_FEATURE_BSS_COLOR))
3361 if (ieee80211_hw_check(&rx->local->hw, DETECTS_COLOR_COLLISION))
3364 if (rx->sdata->vif.bss_conf.csa_active)
3367 baselen = mgmt->u.beacon.variable - rx->skb->data;
3368 if (baselen > rx->skb->len)
3371 ie = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION,
3372 mgmt->u.beacon.variable,
3373 rx->skb->len - baselen);
3374 if (ie && ie->datalen >= sizeof(struct ieee80211_he_operation) &&
3375 ie->datalen >= ieee80211_he_oper_size(ie->data + 1)) {
3376 struct ieee80211_bss_conf *bss_conf = &rx->sdata->vif.bss_conf;
3377 const struct ieee80211_he_operation *he_oper;
3380 he_oper = (void *)(ie->data + 1);
3381 if (le32_get_bits(he_oper->he_oper_params,
3382 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED))
3385 color = le32_get_bits(he_oper->he_oper_params,
3386 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3387 if (color == bss_conf->he_bss_color.color)
3388 ieee80211_obss_color_collision_notify(&rx->sdata->vif,
3393 static ieee80211_rx_result debug_noinline
3394 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3396 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3397 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3399 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
3403 * From here on, look only at management frames.
3404 * Data and control frames are already handled,
3405 * and unknown (reserved) frames are useless.
3407 if (rx->skb->len < 24)
3408 return RX_DROP_MONITOR;
3410 if (!ieee80211_is_mgmt(mgmt->frame_control))
3411 return RX_DROP_MONITOR;
3413 /* drop too small action frames */
3414 if (ieee80211_is_action(mgmt->frame_control) &&
3415 rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
3416 return RX_DROP_U_RUNT_ACTION;
3418 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3419 ieee80211_is_beacon(mgmt->frame_control) &&
3420 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3423 /* sw bss color collision detection */
3424 ieee80211_rx_check_bss_color_collision(rx);
3426 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3427 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3428 sig = status->signal;
3430 cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3431 rx->skb->data, rx->skb->len,
3432 ieee80211_rx_status_to_khz(status),
3434 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3437 return ieee80211_drop_unencrypted_mgmt(rx);
3441 ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
3443 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
3444 struct ieee80211_sub_if_data *sdata = rx->sdata;
3446 /* TWT actions are only supported in AP for the moment */
3447 if (sdata->vif.type != NL80211_IFTYPE_AP)
3450 if (!rx->local->ops->add_twt_setup)
3453 if (!sdata->vif.bss_conf.twt_responder)
3459 switch (mgmt->u.action.u.s1g.action_code) {
3460 case WLAN_S1G_TWT_SETUP: {
3461 struct ieee80211_twt_setup *twt;
3463 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3464 1 + /* action code */
3465 sizeof(struct ieee80211_twt_setup) +
3466 2 /* TWT req_type agrt */)
3469 twt = (void *)mgmt->u.action.u.s1g.variable;
3470 if (twt->element_id != WLAN_EID_S1G_TWT)
3473 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3474 4 + /* action code + token + tlv */
3478 return true; /* queue the frame */
3480 case WLAN_S1G_TWT_TEARDOWN:
3481 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
3484 return true; /* queue the frame */
3492 static ieee80211_rx_result debug_noinline
3493 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3495 struct ieee80211_local *local = rx->local;
3496 struct ieee80211_sub_if_data *sdata = rx->sdata;
3497 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3498 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3499 int len = rx->skb->len;
3501 if (!ieee80211_is_action(mgmt->frame_control))
3504 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3505 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3506 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3507 return RX_DROP_U_ACTION_UNKNOWN_SRC;
3509 switch (mgmt->u.action.category) {
3510 case WLAN_CATEGORY_HT:
3511 /* reject HT action frames from stations not supporting HT */
3512 if (!rx->link_sta->pub->ht_cap.ht_supported)
3515 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3516 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3517 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3518 sdata->vif.type != NL80211_IFTYPE_AP &&
3519 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3522 /* verify action & smps_control/chanwidth are present */
3523 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3526 switch (mgmt->u.action.u.ht_smps.action) {
3527 case WLAN_HT_ACTION_SMPS: {
3528 struct ieee80211_supported_band *sband;
3529 enum ieee80211_smps_mode smps_mode;
3530 struct sta_opmode_info sta_opmode = {};
3532 if (sdata->vif.type != NL80211_IFTYPE_AP &&
3533 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3536 /* convert to HT capability */
3537 switch (mgmt->u.action.u.ht_smps.smps_control) {
3538 case WLAN_HT_SMPS_CONTROL_DISABLED:
3539 smps_mode = IEEE80211_SMPS_OFF;
3541 case WLAN_HT_SMPS_CONTROL_STATIC:
3542 smps_mode = IEEE80211_SMPS_STATIC;
3544 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3545 smps_mode = IEEE80211_SMPS_DYNAMIC;
3551 /* if no change do nothing */
3552 if (rx->link_sta->pub->smps_mode == smps_mode)
3554 rx->link_sta->pub->smps_mode = smps_mode;
3555 sta_opmode.smps_mode =
3556 ieee80211_smps_mode_to_smps_mode(smps_mode);
3557 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3559 sband = rx->local->hw.wiphy->bands[status->band];
3561 rate_control_rate_update(local, sband, rx->sta, 0,
3562 IEEE80211_RC_SMPS_CHANGED);
3563 cfg80211_sta_opmode_change_notify(sdata->dev,
3569 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3570 struct ieee80211_supported_band *sband;
3571 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3572 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3573 struct sta_opmode_info sta_opmode = {};
3575 /* If it doesn't support 40 MHz it can't change ... */
3576 if (!(rx->link_sta->pub->ht_cap.cap &
3577 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3580 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3581 max_bw = IEEE80211_STA_RX_BW_20;
3583 max_bw = ieee80211_sta_cap_rx_bw(rx->link_sta);
3585 /* set cur_max_bandwidth and recalc sta bw */
3586 rx->link_sta->cur_max_bandwidth = max_bw;
3587 new_bw = ieee80211_sta_cur_vht_bw(rx->link_sta);
3589 if (rx->link_sta->pub->bandwidth == new_bw)
3592 rx->link_sta->pub->bandwidth = new_bw;
3593 sband = rx->local->hw.wiphy->bands[status->band];
3595 ieee80211_sta_rx_bw_to_chan_width(rx->link_sta);
3596 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3598 rate_control_rate_update(local, sband, rx->sta, 0,
3599 IEEE80211_RC_BW_CHANGED);
3600 cfg80211_sta_opmode_change_notify(sdata->dev,
3611 case WLAN_CATEGORY_PUBLIC:
3612 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3614 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3618 if (!ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid))
3620 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3621 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3623 if (len < offsetof(struct ieee80211_mgmt,
3624 u.action.u.ext_chan_switch.variable))
3627 case WLAN_CATEGORY_VHT:
3628 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3629 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3630 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3631 sdata->vif.type != NL80211_IFTYPE_AP &&
3632 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3635 /* verify action code is present */
3636 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3639 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3640 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3641 /* verify opmode is present */
3642 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3646 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3647 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3655 case WLAN_CATEGORY_BACK:
3656 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3657 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3658 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3659 sdata->vif.type != NL80211_IFTYPE_AP &&
3660 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3663 /* verify action_code is present */
3664 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3667 switch (mgmt->u.action.u.addba_req.action_code) {
3668 case WLAN_ACTION_ADDBA_REQ:
3669 if (len < (IEEE80211_MIN_ACTION_SIZE +
3670 sizeof(mgmt->u.action.u.addba_req)))
3673 case WLAN_ACTION_ADDBA_RESP:
3674 if (len < (IEEE80211_MIN_ACTION_SIZE +
3675 sizeof(mgmt->u.action.u.addba_resp)))
3678 case WLAN_ACTION_DELBA:
3679 if (len < (IEEE80211_MIN_ACTION_SIZE +
3680 sizeof(mgmt->u.action.u.delba)))
3688 case WLAN_CATEGORY_SPECTRUM_MGMT:
3689 /* verify action_code is present */
3690 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3693 switch (mgmt->u.action.u.measurement.action_code) {
3694 case WLAN_ACTION_SPCT_MSR_REQ:
3695 if (status->band != NL80211_BAND_5GHZ)
3698 if (len < (IEEE80211_MIN_ACTION_SIZE +
3699 sizeof(mgmt->u.action.u.measurement)))
3702 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3705 ieee80211_process_measurement_req(sdata, mgmt, len);
3707 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3709 if (len < (IEEE80211_MIN_ACTION_SIZE +
3710 sizeof(mgmt->u.action.u.chan_switch)))
3713 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3714 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3715 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3718 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3719 bssid = sdata->deflink.u.mgd.bssid;
3720 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3721 bssid = sdata->u.ibss.bssid;
3722 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3727 if (!ether_addr_equal(mgmt->bssid, bssid))
3734 case WLAN_CATEGORY_SELF_PROTECTED:
3735 if (len < (IEEE80211_MIN_ACTION_SIZE +
3736 sizeof(mgmt->u.action.u.self_prot.action_code)))
3739 switch (mgmt->u.action.u.self_prot.action_code) {
3740 case WLAN_SP_MESH_PEERING_OPEN:
3741 case WLAN_SP_MESH_PEERING_CLOSE:
3742 case WLAN_SP_MESH_PEERING_CONFIRM:
3743 if (!ieee80211_vif_is_mesh(&sdata->vif))
3745 if (sdata->u.mesh.user_mpm)
3746 /* userspace handles this frame */
3749 case WLAN_SP_MGK_INFORM:
3750 case WLAN_SP_MGK_ACK:
3751 if (!ieee80211_vif_is_mesh(&sdata->vif))
3756 case WLAN_CATEGORY_MESH_ACTION:
3757 if (len < (IEEE80211_MIN_ACTION_SIZE +
3758 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3761 if (!ieee80211_vif_is_mesh(&sdata->vif))
3763 if (mesh_action_is_path_sel(mgmt) &&
3764 !mesh_path_sel_is_hwmp(sdata))
3767 case WLAN_CATEGORY_S1G:
3768 if (len < offsetofend(typeof(*mgmt),
3769 u.action.u.s1g.action_code))
3772 switch (mgmt->u.action.u.s1g.action_code) {
3773 case WLAN_S1G_TWT_SETUP:
3774 case WLAN_S1G_TWT_TEARDOWN:
3775 if (ieee80211_process_rx_twt_action(rx))
3782 case WLAN_CATEGORY_PROTECTED_EHT:
3783 switch (mgmt->u.action.u.ttlm_req.action_code) {
3784 case WLAN_PROTECTED_EHT_ACTION_TTLM_REQ:
3785 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3788 if (len < offsetofend(typeof(*mgmt),
3789 u.action.u.ttlm_req))
3792 case WLAN_PROTECTED_EHT_ACTION_TTLM_RES:
3793 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3796 if (len < offsetofend(typeof(*mgmt),
3797 u.action.u.ttlm_res))
3809 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3810 /* will return in the next handlers */
3815 rx->link_sta->rx_stats.packets++;
3816 dev_kfree_skb(rx->skb);
3820 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3824 static ieee80211_rx_result debug_noinline
3825 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3827 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3828 struct cfg80211_rx_info info = {
3829 .freq = ieee80211_rx_status_to_khz(status),
3830 .buf = rx->skb->data,
3831 .len = rx->skb->len,
3832 .link_id = rx->link_id,
3833 .have_link_id = rx->link_id >= 0,
3836 /* skip known-bad action frames and return them in the next handler */
3837 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3841 * Getting here means the kernel doesn't know how to handle
3842 * it, but maybe userspace does ... include returned frames
3843 * so userspace can register for those to know whether ones
3844 * it transmitted were processed or returned.
3847 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3848 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3849 info.sig_dbm = status->signal;
3851 if (ieee80211_is_timing_measurement(rx->skb) ||
3852 ieee80211_is_ftm(rx->skb)) {
3853 info.rx_tstamp = ktime_to_ns(skb_hwtstamps(rx->skb)->hwtstamp);
3854 info.ack_tstamp = ktime_to_ns(status->ack_tx_hwtstamp);
3857 if (cfg80211_rx_mgmt_ext(&rx->sdata->wdev, &info)) {
3859 rx->link_sta->rx_stats.packets++;
3860 dev_kfree_skb(rx->skb);
3867 static ieee80211_rx_result debug_noinline
3868 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
3870 struct ieee80211_sub_if_data *sdata = rx->sdata;
3871 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3872 int len = rx->skb->len;
3874 if (!ieee80211_is_action(mgmt->frame_control))
3877 switch (mgmt->u.action.category) {
3878 case WLAN_CATEGORY_SA_QUERY:
3879 if (len < (IEEE80211_MIN_ACTION_SIZE +
3880 sizeof(mgmt->u.action.u.sa_query)))
3883 switch (mgmt->u.action.u.sa_query.action) {
3884 case WLAN_ACTION_SA_QUERY_REQUEST:
3885 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3887 ieee80211_process_sa_query_req(sdata, mgmt, len);
3897 rx->link_sta->rx_stats.packets++;
3898 dev_kfree_skb(rx->skb);
3902 static ieee80211_rx_result debug_noinline
3903 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3905 struct ieee80211_local *local = rx->local;
3906 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3907 struct sk_buff *nskb;
3908 struct ieee80211_sub_if_data *sdata = rx->sdata;
3909 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3911 if (!ieee80211_is_action(mgmt->frame_control))
3915 * For AP mode, hostapd is responsible for handling any action
3916 * frames that we didn't handle, including returning unknown
3917 * ones. For all other modes we will return them to the sender,
3918 * setting the 0x80 bit in the action category, as required by
3919 * 802.11-2012 9.24.4.
3920 * Newer versions of hostapd shall also use the management frame
3921 * registration mechanisms, but older ones still use cooked
3922 * monitor interfaces so push all frames there.
3924 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3925 (sdata->vif.type == NL80211_IFTYPE_AP ||
3926 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3927 return RX_DROP_MONITOR;
3929 if (is_multicast_ether_addr(mgmt->da))
3930 return RX_DROP_MONITOR;
3932 /* do not return rejected action frames */
3933 if (mgmt->u.action.category & 0x80)
3934 return RX_DROP_U_REJECTED_ACTION_RESPONSE;
3936 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3939 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3941 nmgmt->u.action.category |= 0x80;
3942 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3943 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3945 memset(nskb->cb, 0, sizeof(nskb->cb));
3947 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3948 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3950 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3951 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3952 IEEE80211_TX_CTL_NO_CCK_RATE;
3953 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3955 local->hw.offchannel_tx_hw_queue;
3958 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, -1,
3961 dev_kfree_skb(rx->skb);
3965 static ieee80211_rx_result debug_noinline
3966 ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
3968 struct ieee80211_sub_if_data *sdata = rx->sdata;
3969 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
3971 if (!ieee80211_is_ext(hdr->frame_control))
3974 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3975 return RX_DROP_MONITOR;
3977 /* for now only beacons are ext, so queue them */
3978 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3983 static ieee80211_rx_result debug_noinline
3984 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3986 struct ieee80211_sub_if_data *sdata = rx->sdata;
3987 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3990 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3992 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3993 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3994 sdata->vif.type != NL80211_IFTYPE_OCB &&
3995 sdata->vif.type != NL80211_IFTYPE_STATION)
3996 return RX_DROP_MONITOR;
3999 case cpu_to_le16(IEEE80211_STYPE_AUTH):
4000 case cpu_to_le16(IEEE80211_STYPE_BEACON):
4001 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
4002 /* process for all: mesh, mlme, ibss */
4004 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
4005 if (is_multicast_ether_addr(mgmt->da) &&
4006 !is_broadcast_ether_addr(mgmt->da))
4007 return RX_DROP_MONITOR;
4009 /* process only for station/IBSS */
4010 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
4011 sdata->vif.type != NL80211_IFTYPE_ADHOC)
4012 return RX_DROP_MONITOR;
4014 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
4015 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
4016 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
4017 if (is_multicast_ether_addr(mgmt->da) &&
4018 !is_broadcast_ether_addr(mgmt->da))
4019 return RX_DROP_MONITOR;
4021 /* process only for station */
4022 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4023 return RX_DROP_MONITOR;
4025 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
4026 /* process only for ibss and mesh */
4027 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
4028 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
4029 return RX_DROP_MONITOR;
4032 return RX_DROP_MONITOR;
4035 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
4040 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
4041 struct ieee80211_rate *rate,
4042 ieee80211_rx_result reason)
4044 struct ieee80211_sub_if_data *sdata;
4045 struct ieee80211_local *local = rx->local;
4046 struct sk_buff *skb = rx->skb, *skb2;
4047 struct net_device *prev_dev = NULL;
4048 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4049 int needed_headroom;
4052 * If cooked monitor has been processed already, then
4053 * don't do it again. If not, set the flag.
4055 if (rx->flags & IEEE80211_RX_CMNTR)
4057 rx->flags |= IEEE80211_RX_CMNTR;
4059 /* If there are no cooked monitor interfaces, just free the SKB */
4060 if (!local->cooked_mntrs)
4063 /* room for the radiotap header based on driver features */
4064 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
4066 if (skb_headroom(skb) < needed_headroom &&
4067 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
4070 /* prepend radiotap information */
4071 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
4074 skb_reset_mac_header(skb);
4075 skb->ip_summed = CHECKSUM_UNNECESSARY;
4076 skb->pkt_type = PACKET_OTHERHOST;
4077 skb->protocol = htons(ETH_P_802_2);
4079 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4080 if (!ieee80211_sdata_running(sdata))
4083 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
4084 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
4088 skb2 = skb_clone(skb, GFP_ATOMIC);
4090 skb2->dev = prev_dev;
4091 netif_receive_skb(skb2);
4095 prev_dev = sdata->dev;
4096 dev_sw_netstats_rx_add(sdata->dev, skb->len);
4100 skb->dev = prev_dev;
4101 netif_receive_skb(skb);
4106 kfree_skb_reason(skb, (__force u32)reason);
4109 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
4110 ieee80211_rx_result res)
4112 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4113 struct ieee80211_supported_band *sband;
4114 struct ieee80211_rate *rate = NULL;
4116 if (res == RX_QUEUED) {
4117 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
4121 if (res != RX_CONTINUE) {
4122 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
4124 rx->link_sta->rx_stats.dropped++;
4127 if (u32_get_bits((__force u32)res, SKB_DROP_REASON_SUBSYS_MASK) ==
4128 SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE) {
4129 kfree_skb_reason(rx->skb, (__force u32)res);
4133 sband = rx->local->hw.wiphy->bands[status->band];
4134 if (status->encoding == RX_ENC_LEGACY)
4135 rate = &sband->bitrates[status->rate_idx];
4137 ieee80211_rx_cooked_monitor(rx, rate, res);
4140 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
4141 struct sk_buff_head *frames)
4143 ieee80211_rx_result res = RX_DROP_MONITOR;
4144 struct sk_buff *skb;
4146 #define CALL_RXH(rxh) \
4149 if (res != RX_CONTINUE) \
4153 /* Lock here to avoid hitting all of the data used in the RX
4154 * path (e.g. key data, station data, ...) concurrently when
4155 * a frame is released from the reorder buffer due to timeout
4156 * from the timer, potentially concurrently with RX from the
4159 spin_lock_bh(&rx->local->rx_path_lock);
4161 while ((skb = __skb_dequeue(frames))) {
4163 * all the other fields are valid across frames
4164 * that belong to an aMPDU since they are on the
4165 * same TID from the same station
4169 if (WARN_ON_ONCE(!rx->link))
4172 CALL_RXH(ieee80211_rx_h_check_more_data);
4173 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
4174 CALL_RXH(ieee80211_rx_h_sta_process);
4175 CALL_RXH(ieee80211_rx_h_decrypt);
4176 CALL_RXH(ieee80211_rx_h_defragment);
4177 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
4178 /* must be after MMIC verify so header is counted in MPDU mic */
4179 CALL_RXH(ieee80211_rx_h_amsdu);
4180 CALL_RXH(ieee80211_rx_h_data);
4182 /* special treatment -- needs the queue */
4183 res = ieee80211_rx_h_ctrl(rx, frames);
4184 if (res != RX_CONTINUE)
4187 CALL_RXH(ieee80211_rx_h_mgmt_check);
4188 CALL_RXH(ieee80211_rx_h_action);
4189 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
4190 CALL_RXH(ieee80211_rx_h_action_post_userspace);
4191 CALL_RXH(ieee80211_rx_h_action_return);
4192 CALL_RXH(ieee80211_rx_h_ext);
4193 CALL_RXH(ieee80211_rx_h_mgmt);
4196 ieee80211_rx_handlers_result(rx, res);
4201 spin_unlock_bh(&rx->local->rx_path_lock);
4204 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
4206 struct sk_buff_head reorder_release;
4207 ieee80211_rx_result res = RX_DROP_MONITOR;
4209 __skb_queue_head_init(&reorder_release);
4211 #define CALL_RXH(rxh) \
4214 if (res != RX_CONTINUE) \
4218 CALL_RXH(ieee80211_rx_h_check_dup);
4219 CALL_RXH(ieee80211_rx_h_check);
4221 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
4223 ieee80211_rx_handlers(rx, &reorder_release);
4227 ieee80211_rx_handlers_result(rx, res);
4233 ieee80211_rx_is_valid_sta_link_id(struct ieee80211_sta *sta, u8 link_id)
4235 return !!(sta->valid_links & BIT(link_id));
4238 static bool ieee80211_rx_data_set_link(struct ieee80211_rx_data *rx,
4241 rx->link_id = link_id;
4242 rx->link = rcu_dereference(rx->sdata->link[link_id]);
4247 if (!ieee80211_rx_is_valid_sta_link_id(&rx->sta->sta, link_id))
4250 rx->link_sta = rcu_dereference(rx->sta->link[link_id]);
4252 return rx->link && rx->link_sta;
4255 static bool ieee80211_rx_data_set_sta(struct ieee80211_rx_data *rx,
4256 struct sta_info *sta, int link_id)
4258 rx->link_id = link_id;
4262 rx->local = sta->sdata->local;
4264 rx->sdata = sta->sdata;
4265 rx->link_sta = &sta->deflink;
4267 rx->link_sta = NULL;
4271 rx->link = &rx->sdata->deflink;
4272 else if (!ieee80211_rx_data_set_link(rx, link_id))
4279 * This function makes calls into the RX path, therefore
4280 * it has to be invoked under RCU read lock.
4282 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
4284 struct sk_buff_head frames;
4285 struct ieee80211_rx_data rx = {
4286 /* This is OK -- must be QoS data frame */
4287 .security_idx = tid,
4290 struct tid_ampdu_rx *tid_agg_rx;
4293 /* FIXME: statistics won't be right with this */
4294 if (sta->sta.valid_links)
4295 link_id = ffs(sta->sta.valid_links) - 1;
4297 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
4300 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4304 __skb_queue_head_init(&frames);
4306 spin_lock(&tid_agg_rx->reorder_lock);
4307 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4308 spin_unlock(&tid_agg_rx->reorder_lock);
4310 if (!skb_queue_empty(&frames)) {
4311 struct ieee80211_event event = {
4312 .type = BA_FRAME_TIMEOUT,
4314 .u.ba.sta = &sta->sta,
4316 drv_event_callback(rx.local, rx.sdata, &event);
4319 ieee80211_rx_handlers(&rx, &frames);
4322 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
4323 u16 ssn, u64 filtered,
4326 struct ieee80211_local *local;
4327 struct sta_info *sta;
4328 struct tid_ampdu_rx *tid_agg_rx;
4329 struct sk_buff_head frames;
4330 struct ieee80211_rx_data rx = {
4331 /* This is OK -- must be QoS data frame */
4332 .security_idx = tid,
4337 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
4340 __skb_queue_head_init(&frames);
4342 sta = container_of(pubsta, struct sta_info, sta);
4344 local = sta->sdata->local;
4345 WARN_ONCE(local->hw.max_rx_aggregation_subframes > 64,
4346 "RX BA marker can't support max_rx_aggregation_subframes %u > 64\n",
4347 local->hw.max_rx_aggregation_subframes);
4349 if (!ieee80211_rx_data_set_sta(&rx, sta, -1))
4353 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4357 spin_lock_bh(&tid_agg_rx->reorder_lock);
4359 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
4362 /* release all frames in the reorder buffer */
4363 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
4364 IEEE80211_SN_MODULO;
4365 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
4367 /* update ssn to match received ssn */
4368 tid_agg_rx->head_seq_num = ssn;
4370 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
4374 /* handle the case that received ssn is behind the mac ssn.
4375 * it can be tid_agg_rx->buf_size behind and still be valid */
4376 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
4377 if (diff >= tid_agg_rx->buf_size) {
4378 tid_agg_rx->reorder_buf_filtered = 0;
4381 filtered = filtered >> diff;
4385 for (i = 0; i < tid_agg_rx->buf_size; i++) {
4386 int index = (ssn + i) % tid_agg_rx->buf_size;
4388 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
4389 if (filtered & BIT_ULL(i))
4390 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
4393 /* now process also frames that the filter marking released */
4394 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4397 spin_unlock_bh(&tid_agg_rx->reorder_lock);
4399 ieee80211_rx_handlers(&rx, &frames);
4404 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
4406 /* main receive path */
4408 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
4410 return ether_addr_equal(raddr, addr) ||
4411 is_broadcast_ether_addr(raddr);
4414 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
4416 struct ieee80211_sub_if_data *sdata = rx->sdata;
4417 struct sk_buff *skb = rx->skb;
4418 struct ieee80211_hdr *hdr = (void *)skb->data;
4419 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4420 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
4421 bool multicast = is_multicast_ether_addr(hdr->addr1) ||
4422 ieee80211_is_s1g_beacon(hdr->frame_control);
4424 switch (sdata->vif.type) {
4425 case NL80211_IFTYPE_STATION:
4426 if (!bssid && !sdata->u.mgd.use_4addr)
4428 if (ieee80211_is_first_frag(hdr->seq_ctrl) &&
4429 ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
4433 return ieee80211_is_our_addr(sdata, hdr->addr1, &rx->link_id);
4434 case NL80211_IFTYPE_ADHOC:
4437 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
4438 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
4439 !is_valid_ether_addr(hdr->addr2))
4441 if (ieee80211_is_beacon(hdr->frame_control))
4443 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
4446 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4450 if (status->encoding != RX_ENC_LEGACY)
4451 rate_idx = 0; /* TODO: HT/VHT rates */
4453 rate_idx = status->rate_idx;
4454 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
4458 case NL80211_IFTYPE_OCB:
4461 if (!ieee80211_is_data_present(hdr->frame_control))
4463 if (!is_broadcast_ether_addr(bssid))
4466 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
4470 if (status->encoding != RX_ENC_LEGACY)
4471 rate_idx = 0; /* TODO: HT rates */
4473 rate_idx = status->rate_idx;
4474 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
4478 case NL80211_IFTYPE_MESH_POINT:
4479 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
4483 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4484 case NL80211_IFTYPE_AP_VLAN:
4485 case NL80211_IFTYPE_AP:
4487 return ieee80211_is_our_addr(sdata, hdr->addr1,
4490 if (!is_broadcast_ether_addr(bssid) &&
4491 !ieee80211_is_our_addr(sdata, bssid, NULL)) {
4493 * Accept public action frames even when the
4494 * BSSID doesn't match, this is used for P2P
4495 * and location updates. Note that mac80211
4496 * itself never looks at these frames.
4499 !ieee80211_is_our_addr(sdata, hdr->addr1,
4502 if (ieee80211_is_public_action(hdr, skb->len))
4504 return ieee80211_is_beacon(hdr->frame_control);
4507 if (!ieee80211_has_tods(hdr->frame_control)) {
4508 /* ignore data frames to TDLS-peers */
4509 if (ieee80211_is_data(hdr->frame_control))
4511 /* ignore action frames to TDLS-peers */
4512 if (ieee80211_is_action(hdr->frame_control) &&
4513 !is_broadcast_ether_addr(bssid) &&
4514 !ether_addr_equal(bssid, hdr->addr1))
4519 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4520 * the BSSID - we've checked that already but may have accepted
4521 * the wildcard (ff:ff:ff:ff:ff:ff).
4524 * The BSSID of the Data frame is determined as follows:
4525 * a) If the STA is contained within an AP or is associated
4526 * with an AP, the BSSID is the address currently in use
4527 * by the STA contained in the AP.
4529 * So we should not accept data frames with an address that's
4532 * Accepting it also opens a security problem because stations
4533 * could encrypt it with the GTK and inject traffic that way.
4535 if (ieee80211_is_data(hdr->frame_control) && multicast)
4539 case NL80211_IFTYPE_P2P_DEVICE:
4540 return ieee80211_is_public_action(hdr, skb->len) ||
4541 ieee80211_is_probe_req(hdr->frame_control) ||
4542 ieee80211_is_probe_resp(hdr->frame_control) ||
4543 ieee80211_is_beacon(hdr->frame_control);
4544 case NL80211_IFTYPE_NAN:
4545 /* Currently no frames on NAN interface are allowed */
4555 void ieee80211_check_fast_rx(struct sta_info *sta)
4557 struct ieee80211_sub_if_data *sdata = sta->sdata;
4558 struct ieee80211_local *local = sdata->local;
4559 struct ieee80211_key *key;
4560 struct ieee80211_fast_rx fastrx = {
4562 .vif_type = sdata->vif.type,
4563 .control_port_protocol = sdata->control_port_protocol,
4564 }, *old, *new = NULL;
4566 bool set_offload = false;
4567 bool assign = false;
4570 /* use sparse to check that we don't return without updating */
4571 __acquire(check_fast_rx);
4573 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4574 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4575 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4576 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4578 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4580 /* fast-rx doesn't do reordering */
4581 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4582 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4585 switch (sdata->vif.type) {
4586 case NL80211_IFTYPE_STATION:
4587 if (sta->sta.tdls) {
4588 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4589 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4590 fastrx.expected_ds_bits = 0;
4592 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4593 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4594 fastrx.expected_ds_bits =
4595 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4598 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4599 fastrx.expected_ds_bits |=
4600 cpu_to_le16(IEEE80211_FCTL_TODS);
4601 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4602 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4605 if (!sdata->u.mgd.powersave)
4608 /* software powersave is a huge mess, avoid all of it */
4609 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4611 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4612 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4615 case NL80211_IFTYPE_AP_VLAN:
4616 case NL80211_IFTYPE_AP:
4617 /* parallel-rx requires this, at least with calls to
4618 * ieee80211_sta_ps_transition()
4620 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4622 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4623 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4624 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4626 fastrx.internal_forward =
4627 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4628 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4629 !sdata->u.vlan.sta);
4631 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4632 sdata->u.vlan.sta) {
4633 fastrx.expected_ds_bits |=
4634 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4635 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4636 fastrx.internal_forward = 0;
4640 case NL80211_IFTYPE_MESH_POINT:
4641 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_FROMDS |
4642 IEEE80211_FCTL_TODS);
4643 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4644 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4650 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4654 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4656 key = rcu_dereference(sdata->default_unicast_key);
4658 switch (key->conf.cipher) {
4659 case WLAN_CIPHER_SUITE_TKIP:
4660 /* we don't want to deal with MMIC in fast-rx */
4662 case WLAN_CIPHER_SUITE_CCMP:
4663 case WLAN_CIPHER_SUITE_CCMP_256:
4664 case WLAN_CIPHER_SUITE_GCMP:
4665 case WLAN_CIPHER_SUITE_GCMP_256:
4668 /* We also don't want to deal with
4669 * WEP or cipher scheme.
4675 fastrx.icv_len = key->conf.icv_len;
4682 __release(check_fast_rx);
4685 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4687 offload_flags = get_bss_sdata(sdata)->vif.offload_flags;
4688 offload = offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED;
4690 if (assign && offload)
4691 set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4693 set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4696 drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
4698 spin_lock_bh(&sta->lock);
4699 old = rcu_dereference_protected(sta->fast_rx, true);
4700 rcu_assign_pointer(sta->fast_rx, new);
4701 spin_unlock_bh(&sta->lock);
4704 kfree_rcu(old, rcu_head);
4707 void ieee80211_clear_fast_rx(struct sta_info *sta)
4709 struct ieee80211_fast_rx *old;
4711 spin_lock_bh(&sta->lock);
4712 old = rcu_dereference_protected(sta->fast_rx, true);
4713 RCU_INIT_POINTER(sta->fast_rx, NULL);
4714 spin_unlock_bh(&sta->lock);
4717 kfree_rcu(old, rcu_head);
4720 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4722 struct ieee80211_local *local = sdata->local;
4723 struct sta_info *sta;
4725 lockdep_assert_wiphy(local->hw.wiphy);
4727 list_for_each_entry(sta, &local->sta_list, list) {
4728 if (sdata != sta->sdata &&
4729 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4731 ieee80211_check_fast_rx(sta);
4735 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4737 struct ieee80211_local *local = sdata->local;
4739 lockdep_assert_wiphy(local->hw.wiphy);
4741 __ieee80211_check_fast_rx_iface(sdata);
4744 static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
4745 struct ieee80211_fast_rx *fast_rx,
4748 struct ieee80211_sta_rx_stats *stats;
4749 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4750 struct sta_info *sta = rx->sta;
4751 struct link_sta_info *link_sta;
4752 struct sk_buff *skb = rx->skb;
4753 void *sa = skb->data + ETH_ALEN;
4754 void *da = skb->data;
4756 if (rx->link_id >= 0) {
4757 link_sta = rcu_dereference(sta->link[rx->link_id]);
4758 if (WARN_ON_ONCE(!link_sta)) {
4759 dev_kfree_skb(rx->skb);
4763 link_sta = &sta->deflink;
4766 stats = &link_sta->rx_stats;
4767 if (fast_rx->uses_rss)
4768 stats = this_cpu_ptr(link_sta->pcpu_rx_stats);
4770 /* statistics part of ieee80211_rx_h_sta_process() */
4771 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4772 stats->last_signal = status->signal;
4773 if (!fast_rx->uses_rss)
4774 ewma_signal_add(&link_sta->rx_stats_avg.signal,
4778 if (status->chains) {
4781 stats->chains = status->chains;
4782 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4783 int signal = status->chain_signal[i];
4785 if (!(status->chains & BIT(i)))
4788 stats->chain_signal_last[i] = signal;
4789 if (!fast_rx->uses_rss)
4790 ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
4794 /* end of statistics */
4796 stats->last_rx = jiffies;
4797 stats->last_rate = sta_stats_encode_rate(status);
4802 skb->dev = fast_rx->dev;
4804 dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
4806 /* The seqno index has the same property as needed
4807 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4808 * for non-QoS-data frames. Here we know it's a data
4809 * frame, so count MSDUs.
4811 u64_stats_update_begin(&stats->syncp);
4812 stats->msdu[rx->seqno_idx]++;
4813 stats->bytes += orig_len;
4814 u64_stats_update_end(&stats->syncp);
4816 if (fast_rx->internal_forward) {
4817 struct sk_buff *xmit_skb = NULL;
4818 if (is_multicast_ether_addr(da)) {
4819 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4820 } else if (!ether_addr_equal(da, sa) &&
4821 sta_info_get(rx->sdata, da)) {
4828 * Send to wireless media and increase priority by 256
4829 * to keep the received priority instead of
4830 * reclassifying the frame (see cfg80211_classify8021d).
4832 xmit_skb->priority += 256;
4833 xmit_skb->protocol = htons(ETH_P_802_3);
4834 skb_reset_network_header(xmit_skb);
4835 skb_reset_mac_header(xmit_skb);
4836 dev_queue_xmit(xmit_skb);
4843 /* deliver to local stack */
4844 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4845 ieee80211_deliver_skb_to_local_stack(skb, rx);
4848 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4849 struct ieee80211_fast_rx *fast_rx)
4851 struct sk_buff *skb = rx->skb;
4852 struct ieee80211_hdr *hdr = (void *)skb->data;
4853 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4854 static ieee80211_rx_result res;
4855 int orig_len = skb->len;
4856 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4857 int snap_offs = hdrlen;
4859 u8 snap[sizeof(rfc1042_header)];
4861 } *payload __aligned(2);
4865 } addrs __aligned(2);
4866 struct ieee80211_sta_rx_stats *stats;
4868 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4869 * to a common data structure; drivers can implement that per queue
4870 * but we don't have that information in mac80211
4872 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4875 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4877 /* If using encryption, we also need to have:
4878 * - PN_VALIDATED: similar, but the implementation is tricky
4879 * - DECRYPTED: necessary for PN_VALIDATED
4882 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4885 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4888 if (unlikely(ieee80211_is_frag(hdr)))
4891 /* Since our interface address cannot be multicast, this
4892 * implicitly also rejects multicast frames without the
4895 * We shouldn't get any *data* frames not addressed to us
4896 * (AP mode will accept multicast *management* frames), but
4897 * punting here will make it go through the full checks in
4898 * ieee80211_accept_frame().
4900 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4903 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4904 IEEE80211_FCTL_TODS)) !=
4905 fast_rx->expected_ds_bits)
4908 /* assign the key to drop unencrypted frames (later)
4909 * and strip the IV/MIC if necessary
4911 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4912 /* GCMP header length is the same */
4913 snap_offs += IEEE80211_CCMP_HDR_LEN;
4916 if (!ieee80211_vif_is_mesh(&rx->sdata->vif) &&
4917 !(status->rx_flags & IEEE80211_RX_AMSDU)) {
4918 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4921 payload = (void *)(skb->data + snap_offs);
4923 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4926 /* Don't handle these here since they require special code.
4927 * Accept AARP and IPX even though they should come with a
4928 * bridge-tunnel header - but if we get them this way then
4929 * there's little point in discarding them.
4931 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4932 payload->proto == fast_rx->control_port_protocol))
4936 /* after this point, don't punt to the slowpath! */
4938 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4939 pskb_trim(skb, skb->len - fast_rx->icv_len))
4942 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4945 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4946 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4953 /* do the header conversion - first grab the addresses */
4954 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4955 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4956 if (ieee80211_vif_is_mesh(&rx->sdata->vif)) {
4957 skb_pull(skb, snap_offs - 2);
4958 put_unaligned_be16(skb->len - 2, skb->data);
4960 skb_postpull_rcsum(skb, skb->data + snap_offs,
4961 sizeof(rfc1042_header) + 2);
4963 /* remove the SNAP but leave the ethertype */
4964 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4966 /* push the addresses in front */
4967 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4969 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
4979 ieee80211_rx_8023(rx, fast_rx, orig_len);
4985 if (fast_rx->uses_rss)
4986 stats = this_cpu_ptr(rx->link_sta->pcpu_rx_stats);
4988 stats = &rx->link_sta->rx_stats;
4995 * This function returns whether or not the SKB
4996 * was destined for RX processing or not, which,
4997 * if consume is true, is equivalent to whether
4998 * or not the skb was consumed.
5000 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
5001 struct sk_buff *skb, bool consume)
5003 struct ieee80211_local *local = rx->local;
5004 struct ieee80211_sub_if_data *sdata = rx->sdata;
5005 struct ieee80211_hdr *hdr = (void *)skb->data;
5006 struct link_sta_info *link_sta = rx->link_sta;
5007 struct ieee80211_link_data *link = rx->link;
5011 /* See if we can do fast-rx; if we have to copy we already lost,
5012 * so punt in that case. We should never have to deliver a data
5013 * frame to multiple interfaces anyway.
5015 * We skip the ieee80211_accept_frame() call and do the necessary
5016 * checking inside ieee80211_invoke_fast_rx().
5018 if (consume && rx->sta) {
5019 struct ieee80211_fast_rx *fast_rx;
5021 fast_rx = rcu_dereference(rx->sta->fast_rx);
5022 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
5026 if (!ieee80211_accept_frame(rx))
5030 struct skb_shared_hwtstamps *shwt;
5032 rx->skb = skb_copy(skb, GFP_ATOMIC);
5034 if (net_ratelimit())
5035 wiphy_debug(local->hw.wiphy,
5036 "failed to copy skb for %s\n",
5041 /* skb_copy() does not copy the hw timestamps, so copy it
5044 shwt = skb_hwtstamps(rx->skb);
5045 shwt->hwtstamp = skb_hwtstamps(skb)->hwtstamp;
5047 /* Update the hdr pointer to the new skb for translation below */
5048 hdr = (struct ieee80211_hdr *)rx->skb->data;
5051 if (unlikely(rx->sta && rx->sta->sta.mlo) &&
5052 is_unicast_ether_addr(hdr->addr1) &&
5053 !ieee80211_is_probe_resp(hdr->frame_control) &&
5054 !ieee80211_is_beacon(hdr->frame_control)) {
5055 /* translate to MLD addresses */
5056 if (ether_addr_equal(link->conf->addr, hdr->addr1))
5057 ether_addr_copy(hdr->addr1, rx->sdata->vif.addr);
5058 if (ether_addr_equal(link_sta->addr, hdr->addr2))
5059 ether_addr_copy(hdr->addr2, rx->sta->addr);
5060 /* translate A3 only if it's the BSSID */
5061 if (!ieee80211_has_tods(hdr->frame_control) &&
5062 !ieee80211_has_fromds(hdr->frame_control)) {
5063 if (ether_addr_equal(link_sta->addr, hdr->addr3))
5064 ether_addr_copy(hdr->addr3, rx->sta->addr);
5065 else if (ether_addr_equal(link->conf->addr, hdr->addr3))
5066 ether_addr_copy(hdr->addr3, rx->sdata->vif.addr);
5068 /* not needed for A4 since it can only carry the SA */
5071 ieee80211_invoke_rx_handlers(rx);
5075 static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
5076 struct ieee80211_sta *pubsta,
5077 struct sk_buff *skb,
5078 struct list_head *list)
5080 struct ieee80211_local *local = hw_to_local(hw);
5081 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5082 struct ieee80211_fast_rx *fast_rx;
5083 struct ieee80211_rx_data rx;
5084 struct sta_info *sta;
5087 memset(&rx, 0, sizeof(rx));
5093 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
5095 /* drop frame if too short for header */
5096 if (skb->len < sizeof(struct ethhdr))
5102 if (status->link_valid)
5103 link_id = status->link_id;
5106 * TODO: Should the frame be dropped if the right link_id is not
5107 * available? Or may be it is fine in the current form to proceed with
5108 * the frame processing because with frame being in 802.3 format,
5109 * link_id is used only for stats purpose and updating the stats on
5110 * the deflink is fine?
5112 sta = container_of(pubsta, struct sta_info, sta);
5113 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
5116 fast_rx = rcu_dereference(rx.sta->fast_rx);
5120 ieee80211_rx_8023(&rx, fast_rx, skb->len);
5127 static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx,
5128 struct sk_buff *skb, bool consume)
5130 struct link_sta_info *link_sta;
5131 struct ieee80211_hdr *hdr = (void *)skb->data;
5132 struct sta_info *sta;
5136 * Look up link station first, in case there's a
5137 * chance that they might have a link address that
5138 * is identical to the MLD address, that way we'll
5139 * have the link information if needed.
5141 link_sta = link_sta_info_get_bss(rx->sdata, hdr->addr2);
5143 sta = link_sta->sta;
5144 link_id = link_sta->link_id;
5146 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5148 sta = sta_info_get_bss(rx->sdata, hdr->addr2);
5149 if (status->link_valid)
5150 link_id = status->link_id;
5153 if (!ieee80211_rx_data_set_sta(rx, sta, link_id))
5156 return ieee80211_prepare_and_rx_handle(rx, skb, consume);
5160 * This is the actual Rx frames handler. as it belongs to Rx path it must
5161 * be called with rcu_read_lock protection.
5163 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
5164 struct ieee80211_sta *pubsta,
5165 struct sk_buff *skb,
5166 struct list_head *list)
5168 struct ieee80211_local *local = hw_to_local(hw);
5169 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5170 struct ieee80211_sub_if_data *sdata;
5171 struct ieee80211_hdr *hdr;
5173 struct ieee80211_rx_data rx;
5174 struct ieee80211_sub_if_data *prev;
5175 struct rhlist_head *tmp;
5178 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
5179 memset(&rx, 0, sizeof(rx));
5185 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
5186 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
5188 if (ieee80211_is_mgmt(fc)) {
5189 /* drop frame if too short for header */
5190 if (skb->len < ieee80211_hdrlen(fc))
5193 err = skb_linearize(skb);
5195 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
5203 hdr = (struct ieee80211_hdr *)skb->data;
5204 ieee80211_parse_qos(&rx);
5205 ieee80211_verify_alignment(&rx);
5207 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
5208 ieee80211_is_beacon(hdr->frame_control) ||
5209 ieee80211_is_s1g_beacon(hdr->frame_control)))
5210 ieee80211_scan_rx(local, skb);
5212 if (ieee80211_is_data(fc)) {
5213 struct sta_info *sta, *prev_sta;
5216 if (status->link_valid)
5217 link_id = status->link_id;
5220 sta = container_of(pubsta, struct sta_info, sta);
5221 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
5225 * In MLO connection, fetch the link_id using addr2
5226 * when the driver does not pass link_id in status.
5227 * When the address translation is already performed by
5228 * driver/hw, the valid link_id must be passed in
5232 if (!status->link_valid && pubsta->mlo) {
5233 struct link_sta_info *link_sta;
5235 link_sta = link_sta_info_get_bss(rx.sdata,
5240 ieee80211_rx_data_set_link(&rx, link_sta->link_id);
5243 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
5250 for_each_sta_info(local, hdr->addr2, sta, tmp) {
5256 rx.sdata = prev_sta->sdata;
5257 if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
5260 if (!status->link_valid && prev_sta->sta.mlo)
5263 ieee80211_prepare_and_rx_handle(&rx, skb, false);
5269 rx.sdata = prev_sta->sdata;
5270 if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
5273 if (!status->link_valid && prev_sta->sta.mlo)
5276 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
5284 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
5285 if (!ieee80211_sdata_running(sdata))
5288 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
5289 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
5293 * frame is destined for this interface, but if it's
5294 * not also for the previous one we handle that after
5295 * the loop to avoid copying the SKB once too much
5304 ieee80211_rx_for_interface(&rx, skb, false);
5312 if (ieee80211_rx_for_interface(&rx, skb, true))
5321 * This is the receive path handler. It is called by a low level driver when an
5322 * 802.11 MPDU is received from the hardware.
5324 void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5325 struct sk_buff *skb, struct list_head *list)
5327 struct ieee80211_local *local = hw_to_local(hw);
5328 struct ieee80211_rate *rate = NULL;
5329 struct ieee80211_supported_band *sband;
5330 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5331 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5333 WARN_ON_ONCE(softirq_count() == 0);
5335 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
5338 sband = local->hw.wiphy->bands[status->band];
5339 if (WARN_ON(!sband))
5343 * If we're suspending, it is possible although not too likely
5344 * that we'd be receiving frames after having already partially
5345 * quiesced the stack. We can't process such frames then since
5346 * that might, for example, cause stations to be added or other
5347 * driver callbacks be invoked.
5349 if (unlikely(local->quiescing || local->suspended))
5352 /* We might be during a HW reconfig, prevent Rx for the same reason */
5353 if (unlikely(local->in_reconfig))
5357 * The same happens when we're not even started,
5358 * but that's worth a warning.
5360 if (WARN_ON(!local->started))
5363 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
5365 * Validate the rate, unless a PLCP error means that
5366 * we probably can't have a valid rate here anyway.
5369 switch (status->encoding) {
5372 * rate_idx is MCS index, which can be [0-76]
5375 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
5377 * Anything else would be some sort of driver or
5378 * hardware error. The driver should catch hardware
5381 if (WARN(status->rate_idx > 76,
5382 "Rate marked as an HT rate but passed "
5383 "status->rate_idx is not "
5384 "an MCS index [0-76]: %d (0x%02x)\n",
5390 if (WARN_ONCE(status->rate_idx > 11 ||
5393 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
5394 status->rate_idx, status->nss))
5398 if (WARN_ONCE(status->rate_idx > 11 ||
5401 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
5402 status->rate_idx, status->nss))
5406 if (WARN_ONCE(status->rate_idx > 15 ||
5409 status->eht.gi > NL80211_RATE_INFO_EHT_GI_3_2,
5410 "Rate marked as an EHT rate but data is invalid: MCS:%d, NSS:%d, GI:%d\n",
5411 status->rate_idx, status->nss, status->eht.gi))
5418 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
5420 rate = &sband->bitrates[status->rate_idx];
5424 if (WARN_ON_ONCE(status->link_id >= IEEE80211_LINK_UNSPECIFIED))
5427 status->rx_flags = 0;
5429 kcov_remote_start_common(skb_get_kcov_handle(skb));
5432 * Frames with failed FCS/PLCP checksum are not returned,
5433 * all other frames are returned without radiotap header
5434 * if it was previously present.
5435 * Also, frames with less than 16 bytes are dropped.
5437 if (!(status->flag & RX_FLAG_8023))
5438 skb = ieee80211_rx_monitor(local, skb, rate);
5440 if ((status->flag & RX_FLAG_8023) ||
5441 ieee80211_is_data_present(hdr->frame_control))
5442 ieee80211_tpt_led_trig_rx(local, skb->len);
5444 if (status->flag & RX_FLAG_8023)
5445 __ieee80211_rx_handle_8023(hw, pubsta, skb, list);
5447 __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
5455 EXPORT_SYMBOL(ieee80211_rx_list);
5457 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5458 struct sk_buff *skb, struct napi_struct *napi)
5460 struct sk_buff *tmp;
5465 * key references and virtual interfaces are protected using RCU
5466 * and this requires that we are in a read-side RCU section during
5467 * receive processing
5470 ieee80211_rx_list(hw, pubsta, skb, &list);
5474 netif_receive_skb_list(&list);
5478 list_for_each_entry_safe(skb, tmp, &list, list) {
5479 skb_list_del_init(skb);
5480 napi_gro_receive(napi, skb);
5483 EXPORT_SYMBOL(ieee80211_rx_napi);
5485 /* This is a version of the rx handler that can be called from hard irq
5486 * context. Post the skb on the queue and schedule the tasklet */
5487 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
5489 struct ieee80211_local *local = hw_to_local(hw);
5491 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
5493 skb->pkt_type = IEEE80211_RX_MSG;
5494 skb_queue_tail(&local->skb_queue, skb);
5495 tasklet_schedule(&local->tasklet);
5497 EXPORT_SYMBOL(ieee80211_rx_irqsafe);