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-2022 Intel Corporation
12 #include <linux/jiffies.h>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/rcupdate.h>
19 #include <linux/export.h>
20 #include <linux/kcov.h>
21 #include <linux/bitops.h>
22 #include <net/mac80211.h>
23 #include <net/ieee80211_radiotap.h>
24 #include <asm/unaligned.h>
26 #include "ieee80211_i.h"
27 #include "driver-ops.h"
37 * monitor mode reception
39 * This function cleans up the SKB, i.e. it removes all the stuff
40 * only useful for monitoring.
42 static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
43 unsigned int present_fcs_len,
44 unsigned int rtap_space)
46 struct ieee80211_hdr *hdr;
51 __pskb_trim(skb, skb->len - present_fcs_len);
52 __pskb_pull(skb, rtap_space);
54 hdr = (void *)skb->data;
55 fc = hdr->frame_control;
58 * Remove the HT-Control field (if present) on management
59 * frames after we've sent the frame to monitoring. We
60 * (currently) don't need it, and don't properly parse
61 * frames with it present, due to the assumption of a
62 * fixed management header length.
64 if (likely(!ieee80211_is_mgmt(fc) || !ieee80211_has_order(fc)))
67 hdrlen = ieee80211_hdrlen(fc);
68 hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_ORDER);
70 if (!pskb_may_pull(skb, hdrlen)) {
75 memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data,
76 hdrlen - IEEE80211_HT_CTL_LEN);
77 __pskb_pull(skb, IEEE80211_HT_CTL_LEN);
82 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
83 unsigned int rtap_space)
85 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
86 struct ieee80211_hdr *hdr;
88 hdr = (void *)(skb->data + rtap_space);
90 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
91 RX_FLAG_FAILED_PLCP_CRC |
92 RX_FLAG_ONLY_MONITOR |
96 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
99 if (ieee80211_is_ctl(hdr->frame_control) &&
100 !ieee80211_is_pspoll(hdr->frame_control) &&
101 !ieee80211_is_back_req(hdr->frame_control))
108 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
109 struct ieee80211_rx_status *status,
114 /* always present fields */
115 len = sizeof(struct ieee80211_radiotap_header) + 8;
117 /* allocate extra bitmaps */
119 len += 4 * hweight8(status->chains);
120 /* vendor presence bitmap */
121 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)
124 if (ieee80211_have_rx_timestamp(status)) {
128 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
131 /* antenna field, if we don't have per-chain info */
135 /* padding for RX_FLAGS if necessary */
138 if (status->encoding == RX_ENC_HT) /* HT info */
141 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
146 if (status->encoding == RX_ENC_VHT) {
151 if (local->hw.radiotap_timestamp.units_pos >= 0) {
156 if (status->encoding == RX_ENC_HE &&
157 status->flag & RX_FLAG_RADIOTAP_HE) {
160 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
163 if (status->encoding == RX_ENC_HE &&
164 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
167 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
170 if (status->flag & RX_FLAG_NO_PSDU)
173 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
176 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4);
179 if (status->chains) {
180 /* antenna and antenna signal fields */
181 len += 2 * hweight8(status->chains);
184 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
185 struct ieee80211_vendor_radiotap *rtap;
186 int vendor_data_offset = 0;
189 * The position to look at depends on the existence (or non-
190 * existence) of other elements, so take that into account...
192 if (status->flag & RX_FLAG_RADIOTAP_HE)
193 vendor_data_offset +=
194 sizeof(struct ieee80211_radiotap_he);
195 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
196 vendor_data_offset +=
197 sizeof(struct ieee80211_radiotap_he_mu);
198 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
199 vendor_data_offset +=
200 sizeof(struct ieee80211_radiotap_lsig);
202 rtap = (void *)&skb->data[vendor_data_offset];
204 /* alignment for fixed 6-byte vendor data header */
206 /* vendor data header */
208 if (WARN_ON(rtap->align == 0))
210 len = ALIGN(len, rtap->align);
211 len += rtap->len + rtap->pad;
217 static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
218 struct sta_info *sta,
221 skb_queue_tail(&sdata->skb_queue, skb);
222 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
224 sta->deflink.rx_stats.packets++;
227 static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
228 struct sta_info *sta,
232 __ieee80211_queue_skb_to_iface(sdata, sta, skb);
235 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
240 struct ieee80211_hdr_3addr hdr;
243 } __packed __aligned(2) action;
248 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
250 if (skb->len < rtap_space + sizeof(action) +
251 VHT_MUMIMO_GROUPS_DATA_LEN)
254 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
257 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
259 if (!ieee80211_is_action(action.hdr.frame_control))
262 if (action.category != WLAN_CATEGORY_VHT)
265 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
268 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
271 skb = skb_copy(skb, GFP_ATOMIC);
275 ieee80211_queue_skb_to_iface(sdata, NULL, skb);
279 * ieee80211_add_rx_radiotap_header - add radiotap header
281 * add a radiotap header containing all the fields which the hardware provided.
284 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
286 struct ieee80211_rate *rate,
287 int rtap_len, bool has_fcs)
289 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
290 struct ieee80211_radiotap_header *rthdr;
295 u16 channel_flags = 0;
297 unsigned long chains = status->chains;
298 struct ieee80211_vendor_radiotap rtap = {};
299 struct ieee80211_radiotap_he he = {};
300 struct ieee80211_radiotap_he_mu he_mu = {};
301 struct ieee80211_radiotap_lsig lsig = {};
303 if (status->flag & RX_FLAG_RADIOTAP_HE) {
304 he = *(struct ieee80211_radiotap_he *)skb->data;
305 skb_pull(skb, sizeof(he));
306 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
309 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
310 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
311 skb_pull(skb, sizeof(he_mu));
314 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
315 lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
316 skb_pull(skb, sizeof(lsig));
319 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
320 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
321 /* rtap.len and rtap.pad are undone immediately */
322 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
326 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
329 rthdr = skb_push(skb, rtap_len);
330 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
331 it_present = &rthdr->it_present;
333 /* radiotap header, set always present flags */
334 rthdr->it_len = cpu_to_le16(rtap_len);
335 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
336 BIT(IEEE80211_RADIOTAP_CHANNEL) |
337 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
340 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
342 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
344 BIT(IEEE80211_RADIOTAP_EXT) |
345 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
346 put_unaligned_le32(it_present_val, it_present);
348 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
349 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
352 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
353 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
354 BIT(IEEE80211_RADIOTAP_EXT);
355 put_unaligned_le32(it_present_val, it_present);
357 it_present_val = rtap.present;
360 put_unaligned_le32(it_present_val, it_present);
362 /* This references through an offset into it_optional[] rather
363 * than via it_present otherwise later uses of pos will cause
364 * the compiler to think we have walked past the end of the
367 pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
369 /* the order of the following fields is important */
371 /* IEEE80211_RADIOTAP_TSFT */
372 if (ieee80211_have_rx_timestamp(status)) {
374 while ((pos - (u8 *)rthdr) & 7)
377 ieee80211_calculate_rx_timestamp(local, status,
380 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));
384 /* IEEE80211_RADIOTAP_FLAGS */
385 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
386 *pos |= IEEE80211_RADIOTAP_F_FCS;
387 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
388 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
389 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
390 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
393 /* IEEE80211_RADIOTAP_RATE */
394 if (!rate || status->encoding != RX_ENC_LEGACY) {
396 * Without rate information don't add it. If we have,
397 * MCS information is a separate field in radiotap,
398 * added below. The byte here is needed as padding
399 * for the channel though, so initialise it to 0.
404 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
405 if (status->bw == RATE_INFO_BW_10)
407 else if (status->bw == RATE_INFO_BW_5)
409 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
413 /* IEEE80211_RADIOTAP_CHANNEL */
414 /* TODO: frequency offset in KHz */
415 put_unaligned_le16(status->freq, pos);
417 if (status->bw == RATE_INFO_BW_10)
418 channel_flags |= IEEE80211_CHAN_HALF;
419 else if (status->bw == RATE_INFO_BW_5)
420 channel_flags |= IEEE80211_CHAN_QUARTER;
422 if (status->band == NL80211_BAND_5GHZ ||
423 status->band == NL80211_BAND_6GHZ)
424 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
425 else if (status->encoding != RX_ENC_LEGACY)
426 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
427 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
428 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
430 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
432 channel_flags |= IEEE80211_CHAN_2GHZ;
433 put_unaligned_le16(channel_flags, pos);
436 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
437 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
438 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
439 *pos = status->signal;
441 cpu_to_le32(BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
445 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
447 if (!status->chains) {
448 /* IEEE80211_RADIOTAP_ANTENNA */
449 *pos = status->antenna;
453 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
455 /* IEEE80211_RADIOTAP_RX_FLAGS */
456 /* ensure 2 byte alignment for the 2 byte field as required */
457 if ((pos - (u8 *)rthdr) & 1)
459 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
460 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
461 put_unaligned_le16(rx_flags, pos);
464 if (status->encoding == RX_ENC_HT) {
467 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
468 *pos = local->hw.radiotap_mcs_details;
469 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
470 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
471 if (status->enc_flags & RX_ENC_FLAG_LDPC)
472 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FEC;
475 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
476 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
477 if (status->bw == RATE_INFO_BW_40)
478 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
479 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
480 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
481 if (status->enc_flags & RX_ENC_FLAG_LDPC)
482 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
483 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
484 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
486 *pos++ = status->rate_idx;
489 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
492 /* ensure 4 byte alignment */
493 while ((pos - (u8 *)rthdr) & 3)
496 cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
497 put_unaligned_le32(status->ampdu_reference, pos);
499 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
500 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
501 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
502 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
503 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
504 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
505 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
506 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
507 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
508 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
509 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
510 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
511 put_unaligned_le16(flags, pos);
513 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
514 *pos++ = status->ampdu_delimiter_crc;
520 if (status->encoding == RX_ENC_VHT) {
521 u16 known = local->hw.radiotap_vht_details;
523 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
524 put_unaligned_le16(known, pos);
527 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
528 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
529 /* in VHT, STBC is binary */
530 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
531 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
532 if (status->enc_flags & RX_ENC_FLAG_BF)
533 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
536 switch (status->bw) {
537 case RATE_INFO_BW_80:
540 case RATE_INFO_BW_160:
543 case RATE_INFO_BW_40:
550 *pos = (status->rate_idx << 4) | status->nss;
553 if (status->enc_flags & RX_ENC_FLAG_LDPC)
554 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
562 if (local->hw.radiotap_timestamp.units_pos >= 0) {
564 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
567 cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
569 /* ensure 8 byte alignment */
570 while ((pos - (u8 *)rthdr) & 7)
573 put_unaligned_le64(status->device_timestamp, pos);
576 if (local->hw.radiotap_timestamp.accuracy >= 0) {
577 accuracy = local->hw.radiotap_timestamp.accuracy;
578 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
580 put_unaligned_le16(accuracy, pos);
583 *pos++ = local->hw.radiotap_timestamp.units_pos;
587 if (status->encoding == RX_ENC_HE &&
588 status->flag & RX_FLAG_RADIOTAP_HE) {
589 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
591 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
592 he.data6 |= HE_PREP(DATA6_NSTS,
593 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
595 he.data3 |= HE_PREP(DATA3_STBC, 1);
597 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
600 #define CHECK_GI(s) \
601 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
602 (int)NL80211_RATE_INFO_HE_GI_##s)
608 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
609 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
610 he.data3 |= HE_PREP(DATA3_CODING,
611 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
613 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
615 switch (status->bw) {
616 case RATE_INFO_BW_20:
617 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
618 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
620 case RATE_INFO_BW_40:
621 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
622 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
624 case RATE_INFO_BW_80:
625 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
626 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
628 case RATE_INFO_BW_160:
629 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
630 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
632 case RATE_INFO_BW_HE_RU:
633 #define CHECK_RU_ALLOC(s) \
634 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
635 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
643 CHECK_RU_ALLOC(2x996);
645 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
649 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
652 /* ensure 2 byte alignment */
653 while ((pos - (u8 *)rthdr) & 1)
655 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
656 memcpy(pos, &he, sizeof(he));
660 if (status->encoding == RX_ENC_HE &&
661 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
662 /* ensure 2 byte alignment */
663 while ((pos - (u8 *)rthdr) & 1)
665 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
666 memcpy(pos, &he_mu, sizeof(he_mu));
667 pos += sizeof(he_mu);
670 if (status->flag & RX_FLAG_NO_PSDU) {
672 cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
673 *pos++ = status->zero_length_psdu_type;
676 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
677 /* ensure 2 byte alignment */
678 while ((pos - (u8 *)rthdr) & 1)
680 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
681 memcpy(pos, &lsig, sizeof(lsig));
685 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
686 *pos++ = status->chain_signal[chain];
690 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
691 /* ensure 2 byte alignment for the vendor field as required */
692 if ((pos - (u8 *)rthdr) & 1)
694 *pos++ = rtap.oui[0];
695 *pos++ = rtap.oui[1];
696 *pos++ = rtap.oui[2];
698 put_unaligned_le16(rtap.len, pos);
700 /* align the actual payload as requested */
701 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
703 /* data (and possible padding) already follows */
707 static struct sk_buff *
708 ieee80211_make_monitor_skb(struct ieee80211_local *local,
709 struct sk_buff **origskb,
710 struct ieee80211_rate *rate,
711 int rtap_space, bool use_origskb)
713 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
714 int rt_hdrlen, needed_headroom;
717 /* room for the radiotap header based on driver features */
718 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
719 needed_headroom = rt_hdrlen - rtap_space;
722 /* only need to expand headroom if necessary */
727 * This shouldn't trigger often because most devices have an
728 * RX header they pull before we get here, and that should
729 * be big enough for our radiotap information. We should
730 * probably export the length to drivers so that we can have
731 * them allocate enough headroom to start with.
733 if (skb_headroom(skb) < needed_headroom &&
734 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
740 * Need to make a copy and possibly remove radiotap header
741 * and FCS from the original.
743 skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
750 /* prepend radiotap information */
751 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
753 skb_reset_mac_header(skb);
754 skb->ip_summed = CHECKSUM_UNNECESSARY;
755 skb->pkt_type = PACKET_OTHERHOST;
756 skb->protocol = htons(ETH_P_802_2);
762 * This function copies a received frame to all monitor interfaces and
763 * returns a cleaned-up SKB that no longer includes the FCS nor the
764 * radiotap header the driver might have added.
766 static struct sk_buff *
767 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
768 struct ieee80211_rate *rate)
770 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
771 struct ieee80211_sub_if_data *sdata;
772 struct sk_buff *monskb = NULL;
773 int present_fcs_len = 0;
774 unsigned int rtap_space = 0;
775 struct ieee80211_sub_if_data *monitor_sdata =
776 rcu_dereference(local->monitor_sdata);
777 bool only_monitor = false;
778 unsigned int min_head_len;
780 if (status->flag & RX_FLAG_RADIOTAP_HE)
781 rtap_space += sizeof(struct ieee80211_radiotap_he);
783 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
784 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
786 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
787 rtap_space += sizeof(struct ieee80211_radiotap_lsig);
789 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
790 struct ieee80211_vendor_radiotap *rtap =
791 (void *)(origskb->data + rtap_space);
793 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
796 min_head_len = rtap_space;
799 * First, we may need to make a copy of the skb because
800 * (1) we need to modify it for radiotap (if not present), and
801 * (2) the other RX handlers will modify the skb we got.
803 * We don't need to, of course, if we aren't going to return
804 * the SKB because it has a bad FCS/PLCP checksum.
807 if (!(status->flag & RX_FLAG_NO_PSDU)) {
808 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
809 if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
812 dev_kfree_skb(origskb);
815 present_fcs_len = FCS_LEN;
818 /* also consider the hdr->frame_control */
822 /* ensure that the expected data elements are in skb head */
823 if (!pskb_may_pull(origskb, min_head_len)) {
824 dev_kfree_skb(origskb);
828 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
830 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
832 dev_kfree_skb(origskb);
836 return ieee80211_clean_skb(origskb, present_fcs_len,
840 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
842 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
843 bool last_monitor = list_is_last(&sdata->u.mntr.list,
847 monskb = ieee80211_make_monitor_skb(local, &origskb,
859 skb = skb_clone(monskb, GFP_ATOMIC);
863 skb->dev = sdata->dev;
864 dev_sw_netstats_rx_add(skb->dev, skb->len);
865 netif_receive_skb(skb);
873 /* this happens if last_monitor was erroneously false */
874 dev_kfree_skb(monskb);
880 return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
883 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
885 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
886 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
887 int tid, seqno_idx, security_idx;
889 /* does the frame have a qos control field? */
890 if (ieee80211_is_data_qos(hdr->frame_control)) {
891 u8 *qc = ieee80211_get_qos_ctl(hdr);
892 /* frame has qos control */
893 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
894 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
895 status->rx_flags |= IEEE80211_RX_AMSDU;
901 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
903 * Sequence numbers for management frames, QoS data
904 * frames with a broadcast/multicast address in the
905 * Address 1 field, and all non-QoS data frames sent
906 * by QoS STAs are assigned using an additional single
907 * modulo-4096 counter, [...]
909 * We also use that counter for non-QoS STAs.
911 seqno_idx = IEEE80211_NUM_TIDS;
913 if (ieee80211_is_mgmt(hdr->frame_control))
914 security_idx = IEEE80211_NUM_TIDS;
918 rx->seqno_idx = seqno_idx;
919 rx->security_idx = security_idx;
920 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
921 * For now, set skb->priority to 0 for other cases. */
922 rx->skb->priority = (tid > 7) ? 0 : tid;
926 * DOC: Packet alignment
928 * Drivers always need to pass packets that are aligned to two-byte boundaries
931 * Additionally, should, if possible, align the payload data in a way that
932 * guarantees that the contained IP header is aligned to a four-byte
933 * boundary. In the case of regular frames, this simply means aligning the
934 * payload to a four-byte boundary (because either the IP header is directly
935 * contained, or IV/RFC1042 headers that have a length divisible by four are
936 * in front of it). If the payload data is not properly aligned and the
937 * architecture doesn't support efficient unaligned operations, mac80211
938 * will align the data.
940 * With A-MSDU frames, however, the payload data address must yield two modulo
941 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
942 * push the IP header further back to a multiple of four again. Thankfully, the
943 * specs were sane enough this time around to require padding each A-MSDU
944 * subframe to a length that is a multiple of four.
946 * Padding like Atheros hardware adds which is between the 802.11 header and
947 * the payload is not supported, the driver is required to move the 802.11
948 * header to be directly in front of the payload in that case.
950 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
952 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
953 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
960 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
962 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
964 if (is_multicast_ether_addr(hdr->addr1))
967 return ieee80211_is_robust_mgmt_frame(skb);
971 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
973 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
975 if (!is_multicast_ether_addr(hdr->addr1))
978 return ieee80211_is_robust_mgmt_frame(skb);
982 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
983 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
985 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
986 struct ieee80211_mmie *mmie;
987 struct ieee80211_mmie_16 *mmie16;
989 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
992 if (!ieee80211_is_robust_mgmt_frame(skb) &&
993 !ieee80211_is_beacon(hdr->frame_control))
994 return -1; /* not a robust management frame */
996 mmie = (struct ieee80211_mmie *)
997 (skb->data + skb->len - sizeof(*mmie));
998 if (mmie->element_id == WLAN_EID_MMIE &&
999 mmie->length == sizeof(*mmie) - 2)
1000 return le16_to_cpu(mmie->key_id);
1002 mmie16 = (struct ieee80211_mmie_16 *)
1003 (skb->data + skb->len - sizeof(*mmie16));
1004 if (skb->len >= 24 + sizeof(*mmie16) &&
1005 mmie16->element_id == WLAN_EID_MMIE &&
1006 mmie16->length == sizeof(*mmie16) - 2)
1007 return le16_to_cpu(mmie16->key_id);
1012 static int ieee80211_get_keyid(struct sk_buff *skb)
1014 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1015 __le16 fc = hdr->frame_control;
1016 int hdrlen = ieee80211_hdrlen(fc);
1019 /* WEP, TKIP, CCMP and GCMP */
1020 if (unlikely(skb->len < hdrlen + IEEE80211_WEP_IV_LEN))
1023 skb_copy_bits(skb, hdrlen + 3, &keyid, 1);
1030 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1032 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1033 char *dev_addr = rx->sdata->vif.addr;
1035 if (ieee80211_is_data(hdr->frame_control)) {
1036 if (is_multicast_ether_addr(hdr->addr1)) {
1037 if (ieee80211_has_tods(hdr->frame_control) ||
1038 !ieee80211_has_fromds(hdr->frame_control))
1039 return RX_DROP_MONITOR;
1040 if (ether_addr_equal(hdr->addr3, dev_addr))
1041 return RX_DROP_MONITOR;
1043 if (!ieee80211_has_a4(hdr->frame_control))
1044 return RX_DROP_MONITOR;
1045 if (ether_addr_equal(hdr->addr4, dev_addr))
1046 return RX_DROP_MONITOR;
1050 /* If there is not an established peer link and this is not a peer link
1051 * establisment frame, beacon or probe, drop the frame.
1054 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1055 struct ieee80211_mgmt *mgmt;
1057 if (!ieee80211_is_mgmt(hdr->frame_control))
1058 return RX_DROP_MONITOR;
1060 if (ieee80211_is_action(hdr->frame_control)) {
1063 /* make sure category field is present */
1064 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1065 return RX_DROP_MONITOR;
1067 mgmt = (struct ieee80211_mgmt *)hdr;
1068 category = mgmt->u.action.category;
1069 if (category != WLAN_CATEGORY_MESH_ACTION &&
1070 category != WLAN_CATEGORY_SELF_PROTECTED)
1071 return RX_DROP_MONITOR;
1075 if (ieee80211_is_probe_req(hdr->frame_control) ||
1076 ieee80211_is_probe_resp(hdr->frame_control) ||
1077 ieee80211_is_beacon(hdr->frame_control) ||
1078 ieee80211_is_auth(hdr->frame_control))
1081 return RX_DROP_MONITOR;
1087 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1090 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1091 struct sk_buff *tail = skb_peek_tail(frames);
1092 struct ieee80211_rx_status *status;
1094 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1100 status = IEEE80211_SKB_RXCB(tail);
1101 if (status->flag & RX_FLAG_AMSDU_MORE)
1107 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1108 struct tid_ampdu_rx *tid_agg_rx,
1110 struct sk_buff_head *frames)
1112 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1113 struct sk_buff *skb;
1114 struct ieee80211_rx_status *status;
1116 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1118 if (skb_queue_empty(skb_list))
1121 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1122 __skb_queue_purge(skb_list);
1126 /* release frames from the reorder ring buffer */
1127 tid_agg_rx->stored_mpdu_num--;
1128 while ((skb = __skb_dequeue(skb_list))) {
1129 status = IEEE80211_SKB_RXCB(skb);
1130 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1131 __skb_queue_tail(frames, skb);
1135 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1136 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1139 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1140 struct tid_ampdu_rx *tid_agg_rx,
1142 struct sk_buff_head *frames)
1146 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1148 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1149 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1150 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1156 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1157 * the skb was added to the buffer longer than this time ago, the earlier
1158 * frames that have not yet been received are assumed to be lost and the skb
1159 * can be released for processing. This may also release other skb's from the
1160 * reorder buffer if there are no additional gaps between the frames.
1162 * Callers must hold tid_agg_rx->reorder_lock.
1164 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1166 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1167 struct tid_ampdu_rx *tid_agg_rx,
1168 struct sk_buff_head *frames)
1172 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1174 /* release the buffer until next missing frame */
1175 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1176 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1177 tid_agg_rx->stored_mpdu_num) {
1179 * No buffers ready to be released, but check whether any
1180 * frames in the reorder buffer have timed out.
1183 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1184 j = (j + 1) % tid_agg_rx->buf_size) {
1185 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1190 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1191 HT_RX_REORDER_BUF_TIMEOUT))
1192 goto set_release_timer;
1194 /* don't leave incomplete A-MSDUs around */
1195 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1196 i = (i + 1) % tid_agg_rx->buf_size)
1197 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1199 ht_dbg_ratelimited(sdata,
1200 "release an RX reorder frame due to timeout on earlier frames\n");
1201 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1205 * Increment the head seq# also for the skipped slots.
1207 tid_agg_rx->head_seq_num =
1208 (tid_agg_rx->head_seq_num +
1209 skipped) & IEEE80211_SN_MASK;
1212 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1213 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1215 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1218 if (tid_agg_rx->stored_mpdu_num) {
1219 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1221 for (; j != (index - 1) % tid_agg_rx->buf_size;
1222 j = (j + 1) % tid_agg_rx->buf_size) {
1223 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1229 if (!tid_agg_rx->removed)
1230 mod_timer(&tid_agg_rx->reorder_timer,
1231 tid_agg_rx->reorder_time[j] + 1 +
1232 HT_RX_REORDER_BUF_TIMEOUT);
1234 del_timer(&tid_agg_rx->reorder_timer);
1239 * As this function belongs to the RX path it must be under
1240 * rcu_read_lock protection. It returns false if the frame
1241 * can be processed immediately, true if it was consumed.
1243 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1244 struct tid_ampdu_rx *tid_agg_rx,
1245 struct sk_buff *skb,
1246 struct sk_buff_head *frames)
1248 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1249 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1250 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1251 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1252 u16 head_seq_num, buf_size;
1256 spin_lock(&tid_agg_rx->reorder_lock);
1259 * Offloaded BA sessions have no known starting sequence number so pick
1260 * one from first Rxed frame for this tid after BA was started.
1262 if (unlikely(tid_agg_rx->auto_seq)) {
1263 tid_agg_rx->auto_seq = false;
1264 tid_agg_rx->ssn = mpdu_seq_num;
1265 tid_agg_rx->head_seq_num = mpdu_seq_num;
1268 buf_size = tid_agg_rx->buf_size;
1269 head_seq_num = tid_agg_rx->head_seq_num;
1272 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1275 if (unlikely(!tid_agg_rx->started)) {
1276 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1280 tid_agg_rx->started = true;
1283 /* frame with out of date sequence number */
1284 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1290 * If frame the sequence number exceeds our buffering window
1291 * size release some previous frames to make room for this one.
1293 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1294 head_seq_num = ieee80211_sn_inc(
1295 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1296 /* release stored frames up to new head to stack */
1297 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1298 head_seq_num, frames);
1301 /* Now the new frame is always in the range of the reordering buffer */
1303 index = mpdu_seq_num % tid_agg_rx->buf_size;
1305 /* check if we already stored this frame */
1306 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1312 * If the current MPDU is in the right order and nothing else
1313 * is stored we can process it directly, no need to buffer it.
1314 * If it is first but there's something stored, we may be able
1315 * to release frames after this one.
1317 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1318 tid_agg_rx->stored_mpdu_num == 0) {
1319 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1320 tid_agg_rx->head_seq_num =
1321 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1326 /* put the frame in the reordering buffer */
1327 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1328 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1329 tid_agg_rx->reorder_time[index] = jiffies;
1330 tid_agg_rx->stored_mpdu_num++;
1331 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1335 spin_unlock(&tid_agg_rx->reorder_lock);
1340 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1341 * true if the MPDU was buffered, false if it should be processed.
1343 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1344 struct sk_buff_head *frames)
1346 struct sk_buff *skb = rx->skb;
1347 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1348 struct sta_info *sta = rx->sta;
1349 struct tid_ampdu_rx *tid_agg_rx;
1353 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1354 is_multicast_ether_addr(hdr->addr1))
1358 * filter the QoS data rx stream according to
1359 * STA/TID and check if this STA/TID is on aggregation
1365 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1366 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1367 tid = ieee80211_get_tid(hdr);
1369 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1371 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1372 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1373 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1374 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1375 WLAN_BACK_RECIPIENT,
1376 WLAN_REASON_QSTA_REQUIRE_SETUP);
1380 /* qos null data frames are excluded */
1381 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1384 /* not part of a BA session */
1385 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
1388 /* new, potentially un-ordered, ampdu frame - process it */
1390 /* reset session timer */
1391 if (tid_agg_rx->timeout)
1392 tid_agg_rx->last_rx = jiffies;
1394 /* if this mpdu is fragmented - terminate rx aggregation session */
1395 sc = le16_to_cpu(hdr->seq_ctrl);
1396 if (sc & IEEE80211_SCTL_FRAG) {
1397 ieee80211_queue_skb_to_iface(rx->sdata, NULL, skb);
1402 * No locking needed -- we will only ever process one
1403 * RX packet at a time, and thus own tid_agg_rx. All
1404 * other code manipulating it needs to (and does) make
1405 * sure that we cannot get to it any more before doing
1408 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1413 __skb_queue_tail(frames, skb);
1416 static ieee80211_rx_result debug_noinline
1417 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1419 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1420 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1422 if (status->flag & RX_FLAG_DUP_VALIDATED)
1426 * Drop duplicate 802.11 retransmissions
1427 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1430 if (rx->skb->len < 24)
1433 if (ieee80211_is_ctl(hdr->frame_control) ||
1434 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1435 is_multicast_ether_addr(hdr->addr1))
1441 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1442 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1443 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1444 rx->sta->deflink.rx_stats.num_duplicates++;
1445 return RX_DROP_UNUSABLE;
1446 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1447 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1453 static ieee80211_rx_result debug_noinline
1454 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1456 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1458 /* Drop disallowed frame classes based on STA auth/assoc state;
1459 * IEEE 802.11, Chap 5.5.
1461 * mac80211 filters only based on association state, i.e. it drops
1462 * Class 3 frames from not associated stations. hostapd sends
1463 * deauth/disassoc frames when needed. In addition, hostapd is
1464 * responsible for filtering on both auth and assoc states.
1467 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1468 return ieee80211_rx_mesh_check(rx);
1470 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1471 ieee80211_is_pspoll(hdr->frame_control)) &&
1472 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1473 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1474 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1476 * accept port control frames from the AP even when it's not
1477 * yet marked ASSOC to prevent a race where we don't set the
1478 * assoc bit quickly enough before it sends the first frame
1480 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1481 ieee80211_is_data_present(hdr->frame_control)) {
1482 unsigned int hdrlen;
1485 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1487 if (rx->skb->len < hdrlen + 8)
1488 return RX_DROP_MONITOR;
1490 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1491 if (ethertype == rx->sdata->control_port_protocol)
1495 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1496 cfg80211_rx_spurious_frame(rx->sdata->dev,
1499 return RX_DROP_UNUSABLE;
1501 return RX_DROP_MONITOR;
1508 static ieee80211_rx_result debug_noinline
1509 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1511 struct ieee80211_local *local;
1512 struct ieee80211_hdr *hdr;
1513 struct sk_buff *skb;
1517 hdr = (struct ieee80211_hdr *) skb->data;
1519 if (!local->pspolling)
1522 if (!ieee80211_has_fromds(hdr->frame_control))
1523 /* this is not from AP */
1526 if (!ieee80211_is_data(hdr->frame_control))
1529 if (!ieee80211_has_moredata(hdr->frame_control)) {
1530 /* AP has no more frames buffered for us */
1531 local->pspolling = false;
1535 /* more data bit is set, let's request a new frame from the AP */
1536 ieee80211_send_pspoll(local, rx->sdata);
1541 static void sta_ps_start(struct sta_info *sta)
1543 struct ieee80211_sub_if_data *sdata = sta->sdata;
1544 struct ieee80211_local *local = sdata->local;
1548 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1549 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1550 ps = &sdata->bss->ps;
1554 atomic_inc(&ps->num_sta_ps);
1555 set_sta_flag(sta, WLAN_STA_PS_STA);
1556 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1557 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1558 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1559 sta->sta.addr, sta->sta.aid);
1561 ieee80211_clear_fast_xmit(sta);
1563 if (!sta->sta.txq[0])
1566 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1567 struct ieee80211_txq *txq = sta->sta.txq[tid];
1568 struct txq_info *txqi = to_txq_info(txq);
1570 spin_lock(&local->active_txq_lock[txq->ac]);
1571 if (!list_empty(&txqi->schedule_order))
1572 list_del_init(&txqi->schedule_order);
1573 spin_unlock(&local->active_txq_lock[txq->ac]);
1575 if (txq_has_queue(txq))
1576 set_bit(tid, &sta->txq_buffered_tids);
1578 clear_bit(tid, &sta->txq_buffered_tids);
1582 static void sta_ps_end(struct sta_info *sta)
1584 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1585 sta->sta.addr, sta->sta.aid);
1587 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1589 * Clear the flag only if the other one is still set
1590 * so that the TX path won't start TX'ing new frames
1591 * directly ... In the case that the driver flag isn't
1592 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1594 clear_sta_flag(sta, WLAN_STA_PS_STA);
1595 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1596 sta->sta.addr, sta->sta.aid);
1600 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1601 clear_sta_flag(sta, WLAN_STA_PS_STA);
1602 ieee80211_sta_ps_deliver_wakeup(sta);
1605 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1607 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1610 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1612 /* Don't let the same PS state be set twice */
1613 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1614 if ((start && in_ps) || (!start && !in_ps))
1624 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1626 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1628 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1630 if (test_sta_flag(sta, WLAN_STA_SP))
1633 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1634 ieee80211_sta_ps_deliver_poll_response(sta);
1636 set_sta_flag(sta, WLAN_STA_PSPOLL);
1638 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1640 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1642 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1643 int ac = ieee80211_ac_from_tid(tid);
1646 * If this AC is not trigger-enabled do nothing unless the
1647 * driver is calling us after it already checked.
1649 * NB: This could/should check a separate bitmap of trigger-
1650 * enabled queues, but for now we only implement uAPSD w/o
1651 * TSPEC changes to the ACs, so they're always the same.
1653 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1654 tid != IEEE80211_NUM_TIDS)
1657 /* if we are in a service period, do nothing */
1658 if (test_sta_flag(sta, WLAN_STA_SP))
1661 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1662 ieee80211_sta_ps_deliver_uapsd(sta);
1664 set_sta_flag(sta, WLAN_STA_UAPSD);
1666 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1668 static ieee80211_rx_result debug_noinline
1669 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1671 struct ieee80211_sub_if_data *sdata = rx->sdata;
1672 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1673 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1678 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1679 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1683 * The device handles station powersave, so don't do anything about
1684 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1685 * it to mac80211 since they're handled.)
1687 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1691 * Don't do anything if the station isn't already asleep. In
1692 * the uAPSD case, the station will probably be marked asleep,
1693 * in the PS-Poll case the station must be confused ...
1695 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1698 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1699 ieee80211_sta_pspoll(&rx->sta->sta);
1701 /* Free PS Poll skb here instead of returning RX_DROP that would
1702 * count as an dropped frame. */
1703 dev_kfree_skb(rx->skb);
1706 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1707 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1708 ieee80211_has_pm(hdr->frame_control) &&
1709 (ieee80211_is_data_qos(hdr->frame_control) ||
1710 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1711 u8 tid = ieee80211_get_tid(hdr);
1713 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1719 static ieee80211_rx_result debug_noinline
1720 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1722 struct sta_info *sta = rx->sta;
1723 struct sk_buff *skb = rx->skb;
1724 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1725 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1732 * Update last_rx only for IBSS packets which are for the current
1733 * BSSID and for station already AUTHORIZED to avoid keeping the
1734 * current IBSS network alive in cases where other STAs start
1735 * using different BSSID. This will also give the station another
1736 * chance to restart the authentication/authorization in case
1737 * something went wrong the first time.
1739 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1740 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1741 NL80211_IFTYPE_ADHOC);
1742 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1743 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1744 sta->deflink.rx_stats.last_rx = jiffies;
1745 if (ieee80211_is_data(hdr->frame_control) &&
1746 !is_multicast_ether_addr(hdr->addr1))
1747 sta->deflink.rx_stats.last_rate =
1748 sta_stats_encode_rate(status);
1750 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1751 sta->deflink.rx_stats.last_rx = jiffies;
1752 } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
1753 !is_multicast_ether_addr(hdr->addr1)) {
1755 * Mesh beacons will update last_rx when if they are found to
1756 * match the current local configuration when processed.
1758 sta->deflink.rx_stats.last_rx = jiffies;
1759 if (ieee80211_is_data(hdr->frame_control))
1760 sta->deflink.rx_stats.last_rate = sta_stats_encode_rate(status);
1763 sta->deflink.rx_stats.fragments++;
1765 u64_stats_update_begin(&rx->sta->deflink.rx_stats.syncp);
1766 sta->deflink.rx_stats.bytes += rx->skb->len;
1767 u64_stats_update_end(&rx->sta->deflink.rx_stats.syncp);
1769 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1770 sta->deflink.rx_stats.last_signal = status->signal;
1771 ewma_signal_add(&sta->deflink.rx_stats_avg.signal,
1775 if (status->chains) {
1776 sta->deflink.rx_stats.chains = status->chains;
1777 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1778 int signal = status->chain_signal[i];
1780 if (!(status->chains & BIT(i)))
1783 sta->deflink.rx_stats.chain_signal_last[i] = signal;
1784 ewma_signal_add(&sta->deflink.rx_stats_avg.chain_signal[i],
1789 if (ieee80211_is_s1g_beacon(hdr->frame_control))
1793 * Change STA power saving mode only at the end of a frame
1794 * exchange sequence, and only for a data or management
1795 * frame as specified in IEEE 802.11-2016 11.2.3.2
1797 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1798 !ieee80211_has_morefrags(hdr->frame_control) &&
1799 !is_multicast_ether_addr(hdr->addr1) &&
1800 (ieee80211_is_mgmt(hdr->frame_control) ||
1801 ieee80211_is_data(hdr->frame_control)) &&
1802 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1803 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1804 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1805 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1806 if (!ieee80211_has_pm(hdr->frame_control))
1809 if (ieee80211_has_pm(hdr->frame_control))
1814 /* mesh power save support */
1815 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1816 ieee80211_mps_rx_h_sta_process(sta, hdr);
1819 * Drop (qos-)data::nullfunc frames silently, since they
1820 * are used only to control station power saving mode.
1822 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1823 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1826 * If we receive a 4-addr nullfunc frame from a STA
1827 * that was not moved to a 4-addr STA vlan yet send
1828 * the event to userspace and for older hostapd drop
1829 * the frame to the monitor interface.
1831 if (ieee80211_has_a4(hdr->frame_control) &&
1832 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1833 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1834 !rx->sdata->u.vlan.sta))) {
1835 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1836 cfg80211_rx_unexpected_4addr_frame(
1837 rx->sdata->dev, sta->sta.addr,
1839 return RX_DROP_MONITOR;
1842 * Update counter and free packet here to avoid
1843 * counting this as a dropped packed.
1845 sta->deflink.rx_stats.packets++;
1846 dev_kfree_skb(rx->skb);
1851 } /* ieee80211_rx_h_sta_process */
1853 static struct ieee80211_key *
1854 ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
1856 struct ieee80211_key *key = NULL;
1857 struct ieee80211_sub_if_data *sdata = rx->sdata;
1860 /* Make sure key gets set if either BIGTK key index is set so that
1861 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1862 * Beacon frames and Beacon frames that claim to use another BIGTK key
1863 * index (i.e., a key that we do not have).
1867 idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1870 if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1877 key = rcu_dereference(rx->sta->deflink.gtk[idx]);
1879 key = rcu_dereference(sdata->deflink.gtk[idx]);
1880 if (!key && rx->sta)
1881 key = rcu_dereference(rx->sta->deflink.gtk[idx2]);
1883 key = rcu_dereference(sdata->deflink.gtk[idx2]);
1888 static ieee80211_rx_result debug_noinline
1889 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1891 struct sk_buff *skb = rx->skb;
1892 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1893 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1895 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1896 struct ieee80211_key *sta_ptk = NULL;
1897 struct ieee80211_key *ptk_idx = NULL;
1898 int mmie_keyidx = -1;
1901 if (ieee80211_is_ext(hdr->frame_control))
1907 * There are five types of keys:
1908 * - GTK (group keys)
1909 * - IGTK (group keys for management frames)
1910 * - BIGTK (group keys for Beacon frames)
1911 * - PTK (pairwise keys)
1912 * - STK (station-to-station pairwise keys)
1914 * When selecting a key, we have to distinguish between multicast
1915 * (including broadcast) and unicast frames, the latter can only
1916 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1917 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1918 * then unicast frames can also use key indices like GTKs. Hence, if we
1919 * don't have a PTK/STK we check the key index for a WEP key.
1921 * Note that in a regular BSS, multicast frames are sent by the
1922 * AP only, associated stations unicast the frame to the AP first
1923 * which then multicasts it on their behalf.
1925 * There is also a slight problem in IBSS mode: GTKs are negotiated
1926 * with each station, that is something we don't currently handle.
1927 * The spec seems to expect that one negotiates the same key with
1928 * every station but there's no such requirement; VLANs could be
1932 /* start without a key */
1934 fc = hdr->frame_control;
1937 int keyid = rx->sta->ptk_idx;
1938 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1940 if (ieee80211_has_protected(fc) &&
1941 !(status->flag & RX_FLAG_IV_STRIPPED)) {
1942 keyid = ieee80211_get_keyid(rx->skb);
1944 if (unlikely(keyid < 0))
1945 return RX_DROP_UNUSABLE;
1947 ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1951 if (!ieee80211_has_protected(fc))
1952 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1954 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1955 rx->key = ptk_idx ? ptk_idx : sta_ptk;
1956 if ((status->flag & RX_FLAG_DECRYPTED) &&
1957 (status->flag & RX_FLAG_IV_STRIPPED))
1959 /* Skip decryption if the frame is not protected. */
1960 if (!ieee80211_has_protected(fc))
1962 } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
1963 /* Broadcast/multicast robust management frame / BIP */
1964 if ((status->flag & RX_FLAG_DECRYPTED) &&
1965 (status->flag & RX_FLAG_IV_STRIPPED))
1968 if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
1969 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
1970 NUM_DEFAULT_BEACON_KEYS) {
1971 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1974 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1977 rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
1979 return RX_CONTINUE; /* Beacon protection not in use */
1980 } else if (mmie_keyidx >= 0) {
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 ||
1987 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1988 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1990 if (ieee80211_is_group_privacy_action(skb) &&
1991 test_sta_flag(rx->sta, WLAN_STA_MFP))
1992 return RX_DROP_MONITOR;
1994 rx->key = rcu_dereference(rx->sta->deflink.gtk[mmie_keyidx]);
1997 rx->key = rcu_dereference(rx->sdata->deflink.gtk[mmie_keyidx]);
1998 } else if (!ieee80211_has_protected(fc)) {
2000 * The frame was not protected, so skip decryption. However, we
2001 * need to set rx->key if there is a key that could have been
2002 * used so that the frame may be dropped if encryption would
2003 * have been expected.
2005 struct ieee80211_key *key = NULL;
2006 struct ieee80211_sub_if_data *sdata = rx->sdata;
2009 if (ieee80211_is_beacon(fc)) {
2010 key = ieee80211_rx_get_bigtk(rx, -1);
2011 } else if (ieee80211_is_mgmt(fc) &&
2012 is_multicast_ether_addr(hdr->addr1)) {
2013 key = rcu_dereference(rx->sdata->deflink.default_mgmt_key);
2016 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2017 key = rcu_dereference(rx->sta->deflink.gtk[i]);
2023 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2024 key = rcu_dereference(sdata->deflink.gtk[i]);
2035 * The device doesn't give us the IV so we won't be
2036 * able to look up the key. That's ok though, we
2037 * don't need to decrypt the frame, we just won't
2038 * be able to keep statistics accurate.
2039 * Except for key threshold notifications, should
2040 * we somehow allow the driver to tell us which key
2041 * the hardware used if this flag is set?
2043 if ((status->flag & RX_FLAG_DECRYPTED) &&
2044 (status->flag & RX_FLAG_IV_STRIPPED))
2047 keyidx = ieee80211_get_keyid(rx->skb);
2049 if (unlikely(keyidx < 0))
2050 return RX_DROP_UNUSABLE;
2052 /* check per-station GTK first, if multicast packet */
2053 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
2054 rx->key = rcu_dereference(rx->sta->deflink.gtk[keyidx]);
2056 /* if not found, try default key */
2058 if (is_multicast_ether_addr(hdr->addr1))
2059 rx->key = rcu_dereference(rx->sdata->deflink.gtk[keyidx]);
2061 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
2064 * RSNA-protected unicast frames should always be
2065 * sent with pairwise or station-to-station keys,
2066 * but for WEP we allow using a key index as well.
2069 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2070 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2071 !is_multicast_ether_addr(hdr->addr1))
2077 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2078 return RX_DROP_MONITOR;
2080 /* TODO: add threshold stuff again */
2082 return RX_DROP_MONITOR;
2085 switch (rx->key->conf.cipher) {
2086 case WLAN_CIPHER_SUITE_WEP40:
2087 case WLAN_CIPHER_SUITE_WEP104:
2088 result = ieee80211_crypto_wep_decrypt(rx);
2090 case WLAN_CIPHER_SUITE_TKIP:
2091 result = ieee80211_crypto_tkip_decrypt(rx);
2093 case WLAN_CIPHER_SUITE_CCMP:
2094 result = ieee80211_crypto_ccmp_decrypt(
2095 rx, IEEE80211_CCMP_MIC_LEN);
2097 case WLAN_CIPHER_SUITE_CCMP_256:
2098 result = ieee80211_crypto_ccmp_decrypt(
2099 rx, IEEE80211_CCMP_256_MIC_LEN);
2101 case WLAN_CIPHER_SUITE_AES_CMAC:
2102 result = ieee80211_crypto_aes_cmac_decrypt(rx);
2104 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2105 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2107 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2108 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2109 result = ieee80211_crypto_aes_gmac_decrypt(rx);
2111 case WLAN_CIPHER_SUITE_GCMP:
2112 case WLAN_CIPHER_SUITE_GCMP_256:
2113 result = ieee80211_crypto_gcmp_decrypt(rx);
2116 result = RX_DROP_UNUSABLE;
2119 /* the hdr variable is invalid after the decrypt handlers */
2121 /* either the frame has been decrypted or will be dropped */
2122 status->flag |= RX_FLAG_DECRYPTED;
2124 if (unlikely(ieee80211_is_beacon(fc) && result == RX_DROP_UNUSABLE))
2125 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2126 skb->data, skb->len);
2131 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2135 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2136 skb_queue_head_init(&cache->entries[i].skb_list);
2139 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2143 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2144 __skb_queue_purge(&cache->entries[i].skb_list);
2147 static inline struct ieee80211_fragment_entry *
2148 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2149 unsigned int frag, unsigned int seq, int rx_queue,
2150 struct sk_buff **skb)
2152 struct ieee80211_fragment_entry *entry;
2154 entry = &cache->entries[cache->next++];
2155 if (cache->next >= IEEE80211_FRAGMENT_MAX)
2158 __skb_queue_purge(&entry->skb_list);
2160 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2162 entry->first_frag_time = jiffies;
2164 entry->rx_queue = rx_queue;
2165 entry->last_frag = frag;
2166 entry->check_sequential_pn = false;
2167 entry->extra_len = 0;
2172 static inline struct ieee80211_fragment_entry *
2173 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2174 unsigned int frag, unsigned int seq,
2175 int rx_queue, struct ieee80211_hdr *hdr)
2177 struct ieee80211_fragment_entry *entry;
2181 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2182 struct ieee80211_hdr *f_hdr;
2183 struct sk_buff *f_skb;
2187 idx = IEEE80211_FRAGMENT_MAX - 1;
2189 entry = &cache->entries[idx];
2190 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2191 entry->rx_queue != rx_queue ||
2192 entry->last_frag + 1 != frag)
2195 f_skb = __skb_peek(&entry->skb_list);
2196 f_hdr = (struct ieee80211_hdr *) f_skb->data;
2199 * Check ftype and addresses are equal, else check next fragment
2201 if (((hdr->frame_control ^ f_hdr->frame_control) &
2202 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2203 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2204 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2207 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2208 __skb_queue_purge(&entry->skb_list);
2217 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2220 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2221 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2222 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2223 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2224 ieee80211_has_protected(fc);
2227 static ieee80211_rx_result debug_noinline
2228 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2230 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2231 struct ieee80211_hdr *hdr;
2234 unsigned int frag, seq;
2235 struct ieee80211_fragment_entry *entry;
2236 struct sk_buff *skb;
2237 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2239 hdr = (struct ieee80211_hdr *)rx->skb->data;
2240 fc = hdr->frame_control;
2242 if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
2245 sc = le16_to_cpu(hdr->seq_ctrl);
2246 frag = sc & IEEE80211_SCTL_FRAG;
2249 cache = &rx->sta->frags;
2251 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2254 if (is_multicast_ether_addr(hdr->addr1))
2255 return RX_DROP_MONITOR;
2257 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2259 if (skb_linearize(rx->skb))
2260 return RX_DROP_UNUSABLE;
2263 * skb_linearize() might change the skb->data and
2264 * previously cached variables (in this case, hdr) need to
2265 * be refreshed with the new data.
2267 hdr = (struct ieee80211_hdr *)rx->skb->data;
2268 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2271 /* This is the first fragment of a new frame. */
2272 entry = ieee80211_reassemble_add(cache, frag, seq,
2273 rx->seqno_idx, &(rx->skb));
2274 if (requires_sequential_pn(rx, fc)) {
2275 int queue = rx->security_idx;
2277 /* Store CCMP/GCMP PN so that we can verify that the
2278 * next fragment has a sequential PN value.
2280 entry->check_sequential_pn = true;
2281 entry->is_protected = true;
2282 entry->key_color = rx->key->color;
2283 memcpy(entry->last_pn,
2284 rx->key->u.ccmp.rx_pn[queue],
2285 IEEE80211_CCMP_PN_LEN);
2286 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2288 offsetof(struct ieee80211_key,
2290 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2291 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2292 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2293 IEEE80211_GCMP_PN_LEN);
2294 } else if (rx->key &&
2295 (ieee80211_has_protected(fc) ||
2296 (status->flag & RX_FLAG_DECRYPTED))) {
2297 entry->is_protected = true;
2298 entry->key_color = rx->key->color;
2303 /* This is a fragment for a frame that should already be pending in
2304 * fragment cache. Add this fragment to the end of the pending entry.
2306 entry = ieee80211_reassemble_find(cache, frag, seq,
2307 rx->seqno_idx, hdr);
2309 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2310 return RX_DROP_MONITOR;
2313 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2314 * MPDU PN values are not incrementing in steps of 1."
2315 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2316 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2318 if (entry->check_sequential_pn) {
2320 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2322 if (!requires_sequential_pn(rx, fc))
2323 return RX_DROP_UNUSABLE;
2325 /* Prevent mixed key and fragment cache attacks */
2326 if (entry->key_color != rx->key->color)
2327 return RX_DROP_UNUSABLE;
2329 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2330 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2336 rpn = rx->ccm_gcm.pn;
2337 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2338 return RX_DROP_UNUSABLE;
2339 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2340 } else if (entry->is_protected &&
2342 (!ieee80211_has_protected(fc) &&
2343 !(status->flag & RX_FLAG_DECRYPTED)) ||
2344 rx->key->color != entry->key_color)) {
2345 /* Drop this as a mixed key or fragment cache attack, even
2346 * if for TKIP Michael MIC should protect us, and WEP is a
2347 * lost cause anyway.
2349 return RX_DROP_UNUSABLE;
2350 } else if (entry->is_protected && rx->key &&
2351 entry->key_color != rx->key->color &&
2352 (status->flag & RX_FLAG_DECRYPTED)) {
2353 return RX_DROP_UNUSABLE;
2356 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2357 __skb_queue_tail(&entry->skb_list, rx->skb);
2358 entry->last_frag = frag;
2359 entry->extra_len += rx->skb->len;
2360 if (ieee80211_has_morefrags(fc)) {
2365 rx->skb = __skb_dequeue(&entry->skb_list);
2366 if (skb_tailroom(rx->skb) < entry->extra_len) {
2367 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2368 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2370 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2371 __skb_queue_purge(&entry->skb_list);
2372 return RX_DROP_UNUSABLE;
2375 while ((skb = __skb_dequeue(&entry->skb_list))) {
2376 skb_put_data(rx->skb, skb->data, skb->len);
2381 ieee80211_led_rx(rx->local);
2383 rx->sta->deflink.rx_stats.packets++;
2387 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2389 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2395 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2397 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
2398 struct sk_buff *skb = rx->skb;
2399 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2402 * Pass through unencrypted frames if the hardware has
2403 * decrypted them already.
2405 if (status->flag & RX_FLAG_DECRYPTED)
2408 /* check mesh EAPOL frames first */
2409 if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
2410 ieee80211_is_data(fc))) {
2411 struct ieee80211s_hdr *mesh_hdr;
2412 u16 hdr_len = ieee80211_hdrlen(fc);
2413 u16 ethertype_offset;
2416 if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
2419 /* make sure fixed part of mesh header is there, also checks skb len */
2420 if (!pskb_may_pull(rx->skb, hdr_len + 6))
2423 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
2424 ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
2425 sizeof(rfc1042_header);
2427 if (skb_copy_bits(rx->skb, ethertype_offset, ðertype, 2) == 0 &&
2428 ethertype == rx->sdata->control_port_protocol)
2433 /* Drop unencrypted frames if key is set. */
2434 if (unlikely(!ieee80211_has_protected(fc) &&
2435 !ieee80211_is_any_nullfunc(fc) &&
2436 ieee80211_is_data(fc) && rx->key))
2442 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2444 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2445 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2446 __le16 fc = hdr->frame_control;
2449 * Pass through unencrypted frames if the hardware has
2450 * decrypted them already.
2452 if (status->flag & RX_FLAG_DECRYPTED)
2455 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2456 if (unlikely(!ieee80211_has_protected(fc) &&
2457 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2459 if (ieee80211_is_deauth(fc) ||
2460 ieee80211_is_disassoc(fc))
2461 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2466 /* BIP does not use Protected field, so need to check MMIE */
2467 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2468 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2469 if (ieee80211_is_deauth(fc) ||
2470 ieee80211_is_disassoc(fc))
2471 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2476 if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
2477 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2478 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2484 * When using MFP, Action frames are not allowed prior to
2485 * having configured keys.
2487 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2488 ieee80211_is_robust_mgmt_frame(rx->skb)))
2496 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2498 struct ieee80211_sub_if_data *sdata = rx->sdata;
2499 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2500 bool check_port_control = false;
2501 struct ethhdr *ehdr;
2504 *port_control = false;
2505 if (ieee80211_has_a4(hdr->frame_control) &&
2506 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2509 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2510 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2512 if (!sdata->u.mgd.use_4addr)
2514 else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2515 check_port_control = true;
2518 if (is_multicast_ether_addr(hdr->addr1) &&
2519 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2522 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2526 ehdr = (struct ethhdr *) rx->skb->data;
2527 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2528 *port_control = true;
2529 else if (check_port_control)
2535 bool ieee80211_is_our_addr(struct ieee80211_sub_if_data *sdata,
2536 const u8 *addr, int *out_link_id)
2538 unsigned int link_id;
2540 /* non-MLO, or MLD address replaced by hardware */
2541 if (ether_addr_equal(sdata->vif.addr, addr))
2544 if (!sdata->vif.valid_links)
2547 for (link_id = 0; link_id < ARRAY_SIZE(sdata->vif.link_conf); link_id++) {
2548 struct ieee80211_bss_conf *conf;
2550 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2554 if (ether_addr_equal(conf->addr, addr)) {
2556 *out_link_id = link_id;
2565 * requires that rx->skb is a frame with ethernet header
2567 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2569 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2570 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2571 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2574 * Allow EAPOL frames to us/the PAE group address regardless of
2575 * whether the frame was encrypted or not, and always disallow
2576 * all other destination addresses for them.
2578 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2579 return ieee80211_is_our_addr(rx->sdata, ehdr->h_dest, NULL) ||
2580 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2582 if (ieee80211_802_1x_port_control(rx) ||
2583 ieee80211_drop_unencrypted(rx, fc))
2589 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2590 struct ieee80211_rx_data *rx)
2592 struct ieee80211_sub_if_data *sdata = rx->sdata;
2593 struct net_device *dev = sdata->dev;
2595 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2596 (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
2597 !sdata->control_port_no_preauth)) &&
2598 sdata->control_port_over_nl80211)) {
2599 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2600 bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2602 cfg80211_rx_control_port(dev, skb, noencrypt);
2605 struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2607 memset(skb->cb, 0, sizeof(skb->cb));
2610 * 802.1X over 802.11 requires that the authenticator address
2611 * be used for EAPOL frames. However, 802.1X allows the use of
2612 * the PAE group address instead. If the interface is part of
2613 * a bridge and we pass the frame with the PAE group address,
2614 * then the bridge will forward it to the network (even if the
2615 * client was not associated yet), which isn't supposed to
2617 * To avoid that, rewrite the destination address to our own
2618 * address, so that the authenticator (e.g. hostapd) will see
2619 * the frame, but bridge won't forward it anywhere else. Note
2620 * that due to earlier filtering, the only other address can
2621 * be the PAE group address, unless the hardware allowed them
2622 * through in 802.3 offloaded mode.
2624 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2625 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2626 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2628 /* deliver to local stack */
2630 list_add_tail(&skb->list, rx->list);
2632 netif_receive_skb(skb);
2637 * requires that rx->skb is a frame with ethernet header
2640 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2642 struct ieee80211_sub_if_data *sdata = rx->sdata;
2643 struct net_device *dev = sdata->dev;
2644 struct sk_buff *skb, *xmit_skb;
2645 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2646 struct sta_info *dsta;
2651 dev_sw_netstats_rx_add(dev, skb->len);
2654 /* The seqno index has the same property as needed
2655 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2656 * for non-QoS-data frames. Here we know it's a data
2657 * frame, so count MSDUs.
2659 u64_stats_update_begin(&rx->sta->deflink.rx_stats.syncp);
2660 rx->sta->deflink.rx_stats.msdu[rx->seqno_idx]++;
2661 u64_stats_update_end(&rx->sta->deflink.rx_stats.syncp);
2664 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2665 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2666 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2667 ehdr->h_proto != rx->sdata->control_port_protocol &&
2668 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2669 if (is_multicast_ether_addr(ehdr->h_dest) &&
2670 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2672 * send multicast frames both to higher layers in
2673 * local net stack and back to the wireless medium
2675 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2677 net_info_ratelimited("%s: failed to clone multicast frame\n",
2679 } else if (!is_multicast_ether_addr(ehdr->h_dest) &&
2680 !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
2681 dsta = sta_info_get(sdata, ehdr->h_dest);
2684 * The destination station is associated to
2685 * this AP (in this VLAN), so send the frame
2686 * directly to it and do not pass it to local
2695 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2697 /* 'align' will only take the values 0 or 2 here since all
2698 * frames are required to be aligned to 2-byte boundaries
2699 * when being passed to mac80211; the code here works just
2700 * as well if that isn't true, but mac80211 assumes it can
2701 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2705 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2707 if (WARN_ON(skb_headroom(skb) < 3)) {
2711 u8 *data = skb->data;
2712 size_t len = skb_headlen(skb);
2714 memmove(skb->data, data, len);
2715 skb_set_tail_pointer(skb, len);
2722 skb->protocol = eth_type_trans(skb, dev);
2723 ieee80211_deliver_skb_to_local_stack(skb, rx);
2728 * Send to wireless media and increase priority by 256 to
2729 * keep the received priority instead of reclassifying
2730 * the frame (see cfg80211_classify8021d).
2732 xmit_skb->priority += 256;
2733 xmit_skb->protocol = htons(ETH_P_802_3);
2734 skb_reset_network_header(xmit_skb);
2735 skb_reset_mac_header(xmit_skb);
2736 dev_queue_xmit(xmit_skb);
2740 static ieee80211_rx_result debug_noinline
2741 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2743 struct net_device *dev = rx->sdata->dev;
2744 struct sk_buff *skb = rx->skb;
2745 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2746 __le16 fc = hdr->frame_control;
2747 struct sk_buff_head frame_list;
2748 struct ethhdr ethhdr;
2749 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2751 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2754 } else switch (rx->sdata->vif.type) {
2755 case NL80211_IFTYPE_AP:
2756 case NL80211_IFTYPE_AP_VLAN:
2759 case NL80211_IFTYPE_STATION:
2761 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2764 case NL80211_IFTYPE_MESH_POINT:
2772 __skb_queue_head_init(&frame_list);
2774 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2775 rx->sdata->vif.addr,
2776 rx->sdata->vif.type,
2778 return RX_DROP_UNUSABLE;
2780 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2781 rx->sdata->vif.type,
2782 rx->local->hw.extra_tx_headroom,
2783 check_da, check_sa);
2785 while (!skb_queue_empty(&frame_list)) {
2786 rx->skb = __skb_dequeue(&frame_list);
2788 if (!ieee80211_frame_allowed(rx, fc)) {
2789 dev_kfree_skb(rx->skb);
2793 ieee80211_deliver_skb(rx);
2799 static ieee80211_rx_result debug_noinline
2800 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2802 struct sk_buff *skb = rx->skb;
2803 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2804 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2805 __le16 fc = hdr->frame_control;
2807 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2810 if (unlikely(!ieee80211_is_data(fc)))
2813 if (unlikely(!ieee80211_is_data_present(fc)))
2814 return RX_DROP_MONITOR;
2816 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2817 switch (rx->sdata->vif.type) {
2818 case NL80211_IFTYPE_AP_VLAN:
2819 if (!rx->sdata->u.vlan.sta)
2820 return RX_DROP_UNUSABLE;
2822 case NL80211_IFTYPE_STATION:
2823 if (!rx->sdata->u.mgd.use_4addr)
2824 return RX_DROP_UNUSABLE;
2827 return RX_DROP_UNUSABLE;
2831 if (is_multicast_ether_addr(hdr->addr1))
2832 return RX_DROP_UNUSABLE;
2836 * We should not receive A-MSDUs on pre-HT connections,
2837 * and HT connections cannot use old ciphers. Thus drop
2838 * them, as in those cases we couldn't even have SPP
2841 switch (rx->key->conf.cipher) {
2842 case WLAN_CIPHER_SUITE_WEP40:
2843 case WLAN_CIPHER_SUITE_WEP104:
2844 case WLAN_CIPHER_SUITE_TKIP:
2845 return RX_DROP_UNUSABLE;
2851 return __ieee80211_rx_h_amsdu(rx, 0);
2854 #ifdef CONFIG_MAC80211_MESH
2855 static ieee80211_rx_result
2856 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2858 struct ieee80211_hdr *fwd_hdr, *hdr;
2859 struct ieee80211_tx_info *info;
2860 struct ieee80211s_hdr *mesh_hdr;
2861 struct sk_buff *skb = rx->skb, *fwd_skb;
2862 struct ieee80211_local *local = rx->local;
2863 struct ieee80211_sub_if_data *sdata = rx->sdata;
2864 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2868 hdr = (struct ieee80211_hdr *) skb->data;
2869 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2871 /* make sure fixed part of mesh header is there, also checks skb len */
2872 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2873 return RX_DROP_MONITOR;
2875 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2877 /* make sure full mesh header is there, also checks skb len */
2878 if (!pskb_may_pull(rx->skb,
2879 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2880 return RX_DROP_MONITOR;
2882 /* reload pointers */
2883 hdr = (struct ieee80211_hdr *) skb->data;
2884 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2886 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2887 return RX_DROP_MONITOR;
2889 /* frame is in RMC, don't forward */
2890 if (ieee80211_is_data(hdr->frame_control) &&
2891 is_multicast_ether_addr(hdr->addr1) &&
2892 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2893 return RX_DROP_MONITOR;
2895 if (!ieee80211_is_data(hdr->frame_control))
2899 return RX_DROP_MONITOR;
2901 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2902 struct mesh_path *mppath;
2906 if (is_multicast_ether_addr(hdr->addr1)) {
2907 mpp_addr = hdr->addr3;
2908 proxied_addr = mesh_hdr->eaddr1;
2909 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2910 MESH_FLAGS_AE_A5_A6) {
2911 /* has_a4 already checked in ieee80211_rx_mesh_check */
2912 mpp_addr = hdr->addr4;
2913 proxied_addr = mesh_hdr->eaddr2;
2915 return RX_DROP_MONITOR;
2919 mppath = mpp_path_lookup(sdata, proxied_addr);
2921 mpp_path_add(sdata, proxied_addr, mpp_addr);
2923 spin_lock_bh(&mppath->state_lock);
2924 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2925 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2926 mppath->exp_time = jiffies;
2927 spin_unlock_bh(&mppath->state_lock);
2932 /* Frame has reached destination. Don't forward */
2933 if (!is_multicast_ether_addr(hdr->addr1) &&
2934 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2937 ac = ieee802_1d_to_ac[skb->priority];
2938 q = sdata->vif.hw_queue[ac];
2939 if (ieee80211_queue_stopped(&local->hw, q)) {
2940 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2941 return RX_DROP_MONITOR;
2943 skb_set_queue_mapping(skb, ac);
2945 if (!--mesh_hdr->ttl) {
2946 if (!is_multicast_ether_addr(hdr->addr1))
2947 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2948 dropped_frames_ttl);
2952 if (!ifmsh->mshcfg.dot11MeshForwarding)
2955 if (sdata->crypto_tx_tailroom_needed_cnt)
2956 tailroom = IEEE80211_ENCRYPT_TAILROOM;
2958 fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2959 IEEE80211_ENCRYPT_HEADROOM,
2960 tailroom, GFP_ATOMIC);
2964 fwd_skb->dev = sdata->dev;
2965 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2966 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2967 info = IEEE80211_SKB_CB(fwd_skb);
2968 memset(info, 0, sizeof(*info));
2969 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
2970 info->control.vif = &rx->sdata->vif;
2971 info->control.jiffies = jiffies;
2972 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2973 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2974 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2975 /* update power mode indication when forwarding */
2976 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2977 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2978 /* mesh power mode flags updated in mesh_nexthop_lookup */
2979 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2981 /* unable to resolve next hop */
2982 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2984 WLAN_REASON_MESH_PATH_NOFORWARD,
2986 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2988 return RX_DROP_MONITOR;
2991 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2992 ieee80211_add_pending_skb(local, fwd_skb);
2994 if (is_multicast_ether_addr(hdr->addr1))
2996 return RX_DROP_MONITOR;
3000 static ieee80211_rx_result debug_noinline
3001 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
3003 struct ieee80211_sub_if_data *sdata = rx->sdata;
3004 struct ieee80211_local *local = rx->local;
3005 struct net_device *dev = sdata->dev;
3006 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
3007 __le16 fc = hdr->frame_control;
3011 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
3014 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
3015 return RX_DROP_MONITOR;
3018 * Send unexpected-4addr-frame event to hostapd. For older versions,
3019 * also drop the frame to cooked monitor interfaces.
3021 if (ieee80211_has_a4(hdr->frame_control) &&
3022 sdata->vif.type == NL80211_IFTYPE_AP) {
3024 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
3025 cfg80211_rx_unexpected_4addr_frame(
3026 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
3027 return RX_DROP_MONITOR;
3030 err = __ieee80211_data_to_8023(rx, &port_control);
3032 return RX_DROP_UNUSABLE;
3034 if (!ieee80211_frame_allowed(rx, fc))
3035 return RX_DROP_MONITOR;
3037 /* directly handle TDLS channel switch requests/responses */
3038 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
3039 cpu_to_be16(ETH_P_TDLS))) {
3040 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
3042 if (pskb_may_pull(rx->skb,
3043 offsetof(struct ieee80211_tdls_data, u)) &&
3044 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
3045 tf->category == WLAN_CATEGORY_TDLS &&
3046 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
3047 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
3048 rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
3049 __ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3054 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3055 unlikely(port_control) && sdata->bss) {
3056 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
3064 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3065 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
3066 !is_multicast_ether_addr(
3067 ((struct ethhdr *)rx->skb->data)->h_dest) &&
3068 (!local->scanning &&
3069 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
3070 mod_timer(&local->dynamic_ps_timer, jiffies +
3071 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
3073 ieee80211_deliver_skb(rx);
3078 static ieee80211_rx_result debug_noinline
3079 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
3081 struct sk_buff *skb = rx->skb;
3082 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
3083 struct tid_ampdu_rx *tid_agg_rx;
3087 if (likely(!ieee80211_is_ctl(bar->frame_control)))
3090 if (ieee80211_is_back_req(bar->frame_control)) {
3092 __le16 control, start_seq_num;
3093 } __packed bar_data;
3094 struct ieee80211_event event = {
3095 .type = BAR_RX_EVENT,
3099 return RX_DROP_MONITOR;
3101 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
3102 &bar_data, sizeof(bar_data)))
3103 return RX_DROP_MONITOR;
3105 tid = le16_to_cpu(bar_data.control) >> 12;
3107 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
3108 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
3109 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
3110 WLAN_BACK_RECIPIENT,
3111 WLAN_REASON_QSTA_REQUIRE_SETUP);
3113 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
3115 return RX_DROP_MONITOR;
3117 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
3118 event.u.ba.tid = tid;
3119 event.u.ba.ssn = start_seq_num;
3120 event.u.ba.sta = &rx->sta->sta;
3122 /* reset session timer */
3123 if (tid_agg_rx->timeout)
3124 mod_timer(&tid_agg_rx->session_timer,
3125 TU_TO_EXP_TIME(tid_agg_rx->timeout));
3127 spin_lock(&tid_agg_rx->reorder_lock);
3128 /* release stored frames up to start of BAR */
3129 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
3130 start_seq_num, frames);
3131 spin_unlock(&tid_agg_rx->reorder_lock);
3133 drv_event_callback(rx->local, rx->sdata, &event);
3140 * After this point, we only want management frames,
3141 * so we can drop all remaining control frames to
3142 * cooked monitor interfaces.
3144 return RX_DROP_MONITOR;
3147 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
3148 struct ieee80211_mgmt *mgmt,
3151 struct ieee80211_local *local = sdata->local;
3152 struct sk_buff *skb;
3153 struct ieee80211_mgmt *resp;
3155 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
3156 /* Not to own unicast address */
3160 if (!ether_addr_equal(mgmt->sa, sdata->deflink.u.mgd.bssid) ||
3161 !ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid)) {
3162 /* Not from the current AP or not associated yet. */
3166 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3167 /* Too short SA Query request frame */
3171 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3175 skb_reserve(skb, local->hw.extra_tx_headroom);
3176 resp = skb_put_zero(skb, 24);
3177 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3178 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3179 memcpy(resp->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3180 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3181 IEEE80211_STYPE_ACTION);
3182 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3183 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3184 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3185 memcpy(resp->u.action.u.sa_query.trans_id,
3186 mgmt->u.action.u.sa_query.trans_id,
3187 WLAN_SA_QUERY_TR_ID_LEN);
3189 ieee80211_tx_skb(sdata, skb);
3193 ieee80211_rx_check_bss_color_collision(struct ieee80211_rx_data *rx)
3195 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3196 const struct element *ie;
3199 if (!wiphy_ext_feature_isset(rx->local->hw.wiphy,
3200 NL80211_EXT_FEATURE_BSS_COLOR))
3203 if (ieee80211_hw_check(&rx->local->hw, DETECTS_COLOR_COLLISION))
3206 if (rx->sdata->vif.bss_conf.csa_active)
3209 baselen = mgmt->u.beacon.variable - rx->skb->data;
3210 if (baselen > rx->skb->len)
3213 ie = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION,
3214 mgmt->u.beacon.variable,
3215 rx->skb->len - baselen);
3216 if (ie && ie->datalen >= sizeof(struct ieee80211_he_operation) &&
3217 ie->datalen >= ieee80211_he_oper_size(ie->data + 1)) {
3218 struct ieee80211_bss_conf *bss_conf = &rx->sdata->vif.bss_conf;
3219 const struct ieee80211_he_operation *he_oper;
3222 he_oper = (void *)(ie->data + 1);
3223 if (le32_get_bits(he_oper->he_oper_params,
3224 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED))
3227 color = le32_get_bits(he_oper->he_oper_params,
3228 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3229 if (color == bss_conf->he_bss_color.color)
3230 ieeee80211_obss_color_collision_notify(&rx->sdata->vif,
3236 static ieee80211_rx_result debug_noinline
3237 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3239 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3240 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3242 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
3246 * From here on, look only at management frames.
3247 * Data and control frames are already handled,
3248 * and unknown (reserved) frames are useless.
3250 if (rx->skb->len < 24)
3251 return RX_DROP_MONITOR;
3253 if (!ieee80211_is_mgmt(mgmt->frame_control))
3254 return RX_DROP_MONITOR;
3256 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3257 ieee80211_is_beacon(mgmt->frame_control) &&
3258 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3261 /* sw bss color collision detection */
3262 ieee80211_rx_check_bss_color_collision(rx);
3264 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3265 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3266 sig = status->signal;
3268 cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3269 rx->skb->data, rx->skb->len,
3270 ieee80211_rx_status_to_khz(status),
3272 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3275 if (ieee80211_drop_unencrypted_mgmt(rx))
3276 return RX_DROP_UNUSABLE;
3282 ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
3284 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
3285 struct ieee80211_sub_if_data *sdata = rx->sdata;
3287 /* TWT actions are only supported in AP for the moment */
3288 if (sdata->vif.type != NL80211_IFTYPE_AP)
3291 if (!rx->local->ops->add_twt_setup)
3294 if (!sdata->vif.bss_conf.twt_responder)
3300 switch (mgmt->u.action.u.s1g.action_code) {
3301 case WLAN_S1G_TWT_SETUP: {
3302 struct ieee80211_twt_setup *twt;
3304 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3305 1 + /* action code */
3306 sizeof(struct ieee80211_twt_setup) +
3307 2 /* TWT req_type agrt */)
3310 twt = (void *)mgmt->u.action.u.s1g.variable;
3311 if (twt->element_id != WLAN_EID_S1G_TWT)
3314 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3315 4 + /* action code + token + tlv */
3319 return true; /* queue the frame */
3321 case WLAN_S1G_TWT_TEARDOWN:
3322 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
3325 return true; /* queue the frame */
3333 static ieee80211_rx_result debug_noinline
3334 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3336 struct ieee80211_local *local = rx->local;
3337 struct ieee80211_sub_if_data *sdata = rx->sdata;
3338 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3339 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3340 int len = rx->skb->len;
3342 if (!ieee80211_is_action(mgmt->frame_control))
3345 /* drop too small frames */
3346 if (len < IEEE80211_MIN_ACTION_SIZE)
3347 return RX_DROP_UNUSABLE;
3349 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3350 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3351 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3352 return RX_DROP_UNUSABLE;
3354 switch (mgmt->u.action.category) {
3355 case WLAN_CATEGORY_HT:
3356 /* reject HT action frames from stations not supporting HT */
3357 if (!rx->sta->sta.deflink.ht_cap.ht_supported)
3360 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3361 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3362 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3363 sdata->vif.type != NL80211_IFTYPE_AP &&
3364 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3367 /* verify action & smps_control/chanwidth are present */
3368 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3371 switch (mgmt->u.action.u.ht_smps.action) {
3372 case WLAN_HT_ACTION_SMPS: {
3373 struct ieee80211_supported_band *sband;
3374 enum ieee80211_smps_mode smps_mode;
3375 struct sta_opmode_info sta_opmode = {};
3377 if (sdata->vif.type != NL80211_IFTYPE_AP &&
3378 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3381 /* convert to HT capability */
3382 switch (mgmt->u.action.u.ht_smps.smps_control) {
3383 case WLAN_HT_SMPS_CONTROL_DISABLED:
3384 smps_mode = IEEE80211_SMPS_OFF;
3386 case WLAN_HT_SMPS_CONTROL_STATIC:
3387 smps_mode = IEEE80211_SMPS_STATIC;
3389 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3390 smps_mode = IEEE80211_SMPS_DYNAMIC;
3396 /* if no change do nothing */
3397 if (rx->sta->sta.smps_mode == smps_mode)
3399 rx->sta->sta.smps_mode = smps_mode;
3400 sta_opmode.smps_mode =
3401 ieee80211_smps_mode_to_smps_mode(smps_mode);
3402 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3404 sband = rx->local->hw.wiphy->bands[status->band];
3406 rate_control_rate_update(local, sband, rx->sta, 0,
3407 IEEE80211_RC_SMPS_CHANGED);
3408 cfg80211_sta_opmode_change_notify(sdata->dev,
3414 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3415 struct ieee80211_supported_band *sband;
3416 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3417 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3418 struct sta_opmode_info sta_opmode = {};
3420 /* If it doesn't support 40 MHz it can't change ... */
3421 if (!(rx->sta->sta.deflink.ht_cap.cap &
3422 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3425 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3426 max_bw = IEEE80211_STA_RX_BW_20;
3428 max_bw = ieee80211_sta_cap_rx_bw(&rx->sta->deflink);
3430 /* set cur_max_bandwidth and recalc sta bw */
3431 rx->sta->deflink.cur_max_bandwidth = max_bw;
3432 new_bw = ieee80211_sta_cur_vht_bw(&rx->sta->deflink);
3434 if (rx->sta->sta.deflink.bandwidth == new_bw)
3437 rx->sta->sta.deflink.bandwidth = new_bw;
3438 sband = rx->local->hw.wiphy->bands[status->band];
3440 ieee80211_sta_rx_bw_to_chan_width(&rx->sta->deflink);
3441 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3443 rate_control_rate_update(local, sband, rx->sta, 0,
3444 IEEE80211_RC_BW_CHANGED);
3445 cfg80211_sta_opmode_change_notify(sdata->dev,
3456 case WLAN_CATEGORY_PUBLIC:
3457 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3459 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3463 if (!ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid))
3465 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3466 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3468 if (len < offsetof(struct ieee80211_mgmt,
3469 u.action.u.ext_chan_switch.variable))
3472 case WLAN_CATEGORY_VHT:
3473 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3474 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3475 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3476 sdata->vif.type != NL80211_IFTYPE_AP &&
3477 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3480 /* verify action code is present */
3481 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3484 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3485 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3486 /* verify opmode is present */
3487 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3491 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3492 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3500 case WLAN_CATEGORY_BACK:
3501 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3502 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3503 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3504 sdata->vif.type != NL80211_IFTYPE_AP &&
3505 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3508 /* verify action_code is present */
3509 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3512 switch (mgmt->u.action.u.addba_req.action_code) {
3513 case WLAN_ACTION_ADDBA_REQ:
3514 if (len < (IEEE80211_MIN_ACTION_SIZE +
3515 sizeof(mgmt->u.action.u.addba_req)))
3518 case WLAN_ACTION_ADDBA_RESP:
3519 if (len < (IEEE80211_MIN_ACTION_SIZE +
3520 sizeof(mgmt->u.action.u.addba_resp)))
3523 case WLAN_ACTION_DELBA:
3524 if (len < (IEEE80211_MIN_ACTION_SIZE +
3525 sizeof(mgmt->u.action.u.delba)))
3533 case WLAN_CATEGORY_SPECTRUM_MGMT:
3534 /* verify action_code is present */
3535 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3538 switch (mgmt->u.action.u.measurement.action_code) {
3539 case WLAN_ACTION_SPCT_MSR_REQ:
3540 if (status->band != NL80211_BAND_5GHZ)
3543 if (len < (IEEE80211_MIN_ACTION_SIZE +
3544 sizeof(mgmt->u.action.u.measurement)))
3547 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3550 ieee80211_process_measurement_req(sdata, mgmt, len);
3552 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3554 if (len < (IEEE80211_MIN_ACTION_SIZE +
3555 sizeof(mgmt->u.action.u.chan_switch)))
3558 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3559 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3560 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3563 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3564 bssid = sdata->deflink.u.mgd.bssid;
3565 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3566 bssid = sdata->u.ibss.bssid;
3567 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3572 if (!ether_addr_equal(mgmt->bssid, bssid))
3579 case WLAN_CATEGORY_SELF_PROTECTED:
3580 if (len < (IEEE80211_MIN_ACTION_SIZE +
3581 sizeof(mgmt->u.action.u.self_prot.action_code)))
3584 switch (mgmt->u.action.u.self_prot.action_code) {
3585 case WLAN_SP_MESH_PEERING_OPEN:
3586 case WLAN_SP_MESH_PEERING_CLOSE:
3587 case WLAN_SP_MESH_PEERING_CONFIRM:
3588 if (!ieee80211_vif_is_mesh(&sdata->vif))
3590 if (sdata->u.mesh.user_mpm)
3591 /* userspace handles this frame */
3594 case WLAN_SP_MGK_INFORM:
3595 case WLAN_SP_MGK_ACK:
3596 if (!ieee80211_vif_is_mesh(&sdata->vif))
3601 case WLAN_CATEGORY_MESH_ACTION:
3602 if (len < (IEEE80211_MIN_ACTION_SIZE +
3603 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3606 if (!ieee80211_vif_is_mesh(&sdata->vif))
3608 if (mesh_action_is_path_sel(mgmt) &&
3609 !mesh_path_sel_is_hwmp(sdata))
3612 case WLAN_CATEGORY_S1G:
3613 switch (mgmt->u.action.u.s1g.action_code) {
3614 case WLAN_S1G_TWT_SETUP:
3615 case WLAN_S1G_TWT_TEARDOWN:
3616 if (ieee80211_process_rx_twt_action(rx))
3628 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3629 /* will return in the next handlers */
3634 rx->sta->deflink.rx_stats.packets++;
3635 dev_kfree_skb(rx->skb);
3639 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3643 static ieee80211_rx_result debug_noinline
3644 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3646 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3647 struct cfg80211_rx_info info = {
3648 .freq = ieee80211_rx_status_to_khz(status),
3649 .buf = rx->skb->data,
3650 .len = rx->skb->len,
3651 .link_id = rx->link_id,
3652 .have_link_id = rx->link_id >= 0,
3655 /* skip known-bad action frames and return them in the next handler */
3656 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3660 * Getting here means the kernel doesn't know how to handle
3661 * it, but maybe userspace does ... include returned frames
3662 * so userspace can register for those to know whether ones
3663 * it transmitted were processed or returned.
3666 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3667 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3668 info.sig_dbm = status->signal;
3670 if (ieee80211_is_timing_measurement(rx->skb) ||
3671 ieee80211_is_ftm(rx->skb)) {
3672 info.rx_tstamp = ktime_to_ns(skb_hwtstamps(rx->skb)->hwtstamp);
3673 info.ack_tstamp = ktime_to_ns(status->ack_tx_hwtstamp);
3676 if (cfg80211_rx_mgmt_ext(&rx->sdata->wdev, &info)) {
3678 rx->sta->deflink.rx_stats.packets++;
3679 dev_kfree_skb(rx->skb);
3686 static ieee80211_rx_result debug_noinline
3687 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
3689 struct ieee80211_sub_if_data *sdata = rx->sdata;
3690 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3691 int len = rx->skb->len;
3693 if (!ieee80211_is_action(mgmt->frame_control))
3696 switch (mgmt->u.action.category) {
3697 case WLAN_CATEGORY_SA_QUERY:
3698 if (len < (IEEE80211_MIN_ACTION_SIZE +
3699 sizeof(mgmt->u.action.u.sa_query)))
3702 switch (mgmt->u.action.u.sa_query.action) {
3703 case WLAN_ACTION_SA_QUERY_REQUEST:
3704 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3706 ieee80211_process_sa_query_req(sdata, mgmt, len);
3716 rx->sta->deflink.rx_stats.packets++;
3717 dev_kfree_skb(rx->skb);
3721 static ieee80211_rx_result debug_noinline
3722 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3724 struct ieee80211_local *local = rx->local;
3725 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3726 struct sk_buff *nskb;
3727 struct ieee80211_sub_if_data *sdata = rx->sdata;
3728 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3730 if (!ieee80211_is_action(mgmt->frame_control))
3734 * For AP mode, hostapd is responsible for handling any action
3735 * frames that we didn't handle, including returning unknown
3736 * ones. For all other modes we will return them to the sender,
3737 * setting the 0x80 bit in the action category, as required by
3738 * 802.11-2012 9.24.4.
3739 * Newer versions of hostapd shall also use the management frame
3740 * registration mechanisms, but older ones still use cooked
3741 * monitor interfaces so push all frames there.
3743 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3744 (sdata->vif.type == NL80211_IFTYPE_AP ||
3745 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3746 return RX_DROP_MONITOR;
3748 if (is_multicast_ether_addr(mgmt->da))
3749 return RX_DROP_MONITOR;
3751 /* do not return rejected action frames */
3752 if (mgmt->u.action.category & 0x80)
3753 return RX_DROP_UNUSABLE;
3755 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3758 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3760 nmgmt->u.action.category |= 0x80;
3761 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3762 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3764 memset(nskb->cb, 0, sizeof(nskb->cb));
3766 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3767 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3769 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3770 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3771 IEEE80211_TX_CTL_NO_CCK_RATE;
3772 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3774 local->hw.offchannel_tx_hw_queue;
3777 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, -1,
3780 dev_kfree_skb(rx->skb);
3784 static ieee80211_rx_result debug_noinline
3785 ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
3787 struct ieee80211_sub_if_data *sdata = rx->sdata;
3788 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
3790 if (!ieee80211_is_ext(hdr->frame_control))
3793 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3794 return RX_DROP_MONITOR;
3796 /* for now only beacons are ext, so queue them */
3797 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3802 static ieee80211_rx_result debug_noinline
3803 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3805 struct ieee80211_sub_if_data *sdata = rx->sdata;
3806 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3809 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3811 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3812 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3813 sdata->vif.type != NL80211_IFTYPE_OCB &&
3814 sdata->vif.type != NL80211_IFTYPE_STATION)
3815 return RX_DROP_MONITOR;
3818 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3819 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3820 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3821 /* process for all: mesh, mlme, ibss */
3823 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3824 if (is_multicast_ether_addr(mgmt->da) &&
3825 !is_broadcast_ether_addr(mgmt->da))
3826 return RX_DROP_MONITOR;
3828 /* process only for station/IBSS */
3829 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3830 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3831 return RX_DROP_MONITOR;
3833 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3834 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3835 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3836 if (is_multicast_ether_addr(mgmt->da) &&
3837 !is_broadcast_ether_addr(mgmt->da))
3838 return RX_DROP_MONITOR;
3840 /* process only for station */
3841 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3842 return RX_DROP_MONITOR;
3844 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3845 /* process only for ibss and mesh */
3846 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3847 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3848 return RX_DROP_MONITOR;
3851 return RX_DROP_MONITOR;
3854 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3859 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3860 struct ieee80211_rate *rate)
3862 struct ieee80211_sub_if_data *sdata;
3863 struct ieee80211_local *local = rx->local;
3864 struct sk_buff *skb = rx->skb, *skb2;
3865 struct net_device *prev_dev = NULL;
3866 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3867 int needed_headroom;
3870 * If cooked monitor has been processed already, then
3871 * don't do it again. If not, set the flag.
3873 if (rx->flags & IEEE80211_RX_CMNTR)
3875 rx->flags |= IEEE80211_RX_CMNTR;
3877 /* If there are no cooked monitor interfaces, just free the SKB */
3878 if (!local->cooked_mntrs)
3881 /* vendor data is long removed here */
3882 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3883 /* room for the radiotap header based on driver features */
3884 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3886 if (skb_headroom(skb) < needed_headroom &&
3887 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3890 /* prepend radiotap information */
3891 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3894 skb_reset_mac_header(skb);
3895 skb->ip_summed = CHECKSUM_UNNECESSARY;
3896 skb->pkt_type = PACKET_OTHERHOST;
3897 skb->protocol = htons(ETH_P_802_2);
3899 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3900 if (!ieee80211_sdata_running(sdata))
3903 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3904 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3908 skb2 = skb_clone(skb, GFP_ATOMIC);
3910 skb2->dev = prev_dev;
3911 netif_receive_skb(skb2);
3915 prev_dev = sdata->dev;
3916 dev_sw_netstats_rx_add(sdata->dev, skb->len);
3920 skb->dev = prev_dev;
3921 netif_receive_skb(skb);
3929 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3930 ieee80211_rx_result res)
3933 case RX_DROP_MONITOR:
3934 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3936 rx->sta->deflink.rx_stats.dropped++;
3939 struct ieee80211_rate *rate = NULL;
3940 struct ieee80211_supported_band *sband;
3941 struct ieee80211_rx_status *status;
3943 status = IEEE80211_SKB_RXCB((rx->skb));
3945 sband = rx->local->hw.wiphy->bands[status->band];
3946 if (status->encoding == RX_ENC_LEGACY)
3947 rate = &sband->bitrates[status->rate_idx];
3949 ieee80211_rx_cooked_monitor(rx, rate);
3952 case RX_DROP_UNUSABLE:
3953 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3955 rx->sta->deflink.rx_stats.dropped++;
3956 dev_kfree_skb(rx->skb);
3959 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3964 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3965 struct sk_buff_head *frames)
3967 ieee80211_rx_result res = RX_DROP_MONITOR;
3968 struct sk_buff *skb;
3970 #define CALL_RXH(rxh) \
3973 if (res != RX_CONTINUE) \
3977 /* Lock here to avoid hitting all of the data used in the RX
3978 * path (e.g. key data, station data, ...) concurrently when
3979 * a frame is released from the reorder buffer due to timeout
3980 * from the timer, potentially concurrently with RX from the
3983 spin_lock_bh(&rx->local->rx_path_lock);
3985 while ((skb = __skb_dequeue(frames))) {
3987 * all the other fields are valid across frames
3988 * that belong to an aMPDU since they are on the
3989 * same TID from the same station
3993 if (WARN_ON_ONCE(!rx->link))
3996 CALL_RXH(ieee80211_rx_h_check_more_data);
3997 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3998 CALL_RXH(ieee80211_rx_h_sta_process);
3999 CALL_RXH(ieee80211_rx_h_decrypt);
4000 CALL_RXH(ieee80211_rx_h_defragment);
4001 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
4002 /* must be after MMIC verify so header is counted in MPDU mic */
4003 #ifdef CONFIG_MAC80211_MESH
4004 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
4005 CALL_RXH(ieee80211_rx_h_mesh_fwding);
4007 CALL_RXH(ieee80211_rx_h_amsdu);
4008 CALL_RXH(ieee80211_rx_h_data);
4010 /* special treatment -- needs the queue */
4011 res = ieee80211_rx_h_ctrl(rx, frames);
4012 if (res != RX_CONTINUE)
4015 CALL_RXH(ieee80211_rx_h_mgmt_check);
4016 CALL_RXH(ieee80211_rx_h_action);
4017 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
4018 CALL_RXH(ieee80211_rx_h_action_post_userspace);
4019 CALL_RXH(ieee80211_rx_h_action_return);
4020 CALL_RXH(ieee80211_rx_h_ext);
4021 CALL_RXH(ieee80211_rx_h_mgmt);
4024 ieee80211_rx_handlers_result(rx, res);
4029 spin_unlock_bh(&rx->local->rx_path_lock);
4032 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
4034 struct sk_buff_head reorder_release;
4035 ieee80211_rx_result res = RX_DROP_MONITOR;
4037 __skb_queue_head_init(&reorder_release);
4039 #define CALL_RXH(rxh) \
4042 if (res != RX_CONTINUE) \
4046 CALL_RXH(ieee80211_rx_h_check_dup);
4047 CALL_RXH(ieee80211_rx_h_check);
4049 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
4051 ieee80211_rx_handlers(rx, &reorder_release);
4055 ieee80211_rx_handlers_result(rx, res);
4061 * This function makes calls into the RX path, therefore
4062 * it has to be invoked under RCU read lock.
4064 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
4066 struct sk_buff_head frames;
4067 struct ieee80211_rx_data rx = {
4069 .sdata = sta->sdata,
4070 .local = sta->local,
4071 /* This is OK -- must be QoS data frame */
4072 .security_idx = tid,
4076 struct tid_ampdu_rx *tid_agg_rx;
4079 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4083 __skb_queue_head_init(&frames);
4085 spin_lock(&tid_agg_rx->reorder_lock);
4086 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4087 spin_unlock(&tid_agg_rx->reorder_lock);
4089 if (!skb_queue_empty(&frames)) {
4090 struct ieee80211_event event = {
4091 .type = BA_FRAME_TIMEOUT,
4093 .u.ba.sta = &sta->sta,
4095 drv_event_callback(rx.local, rx.sdata, &event);
4097 /* FIXME: statistics won't be right with this */
4098 link_id = sta->sta.valid_links ? ffs(sta->sta.valid_links) - 1 : 0;
4099 rx.link = rcu_dereference(sta->sdata->link[link_id]);
4101 ieee80211_rx_handlers(&rx, &frames);
4104 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
4105 u16 ssn, u64 filtered,
4108 struct sta_info *sta;
4109 struct tid_ampdu_rx *tid_agg_rx;
4110 struct sk_buff_head frames;
4111 struct ieee80211_rx_data rx = {
4112 /* This is OK -- must be QoS data frame */
4113 .security_idx = tid,
4119 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
4122 __skb_queue_head_init(&frames);
4124 sta = container_of(pubsta, struct sta_info, sta);
4127 rx.sdata = sta->sdata;
4128 rx.link = &rx.sdata->deflink;
4129 rx.local = sta->local;
4132 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4136 spin_lock_bh(&tid_agg_rx->reorder_lock);
4138 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
4141 /* release all frames in the reorder buffer */
4142 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
4143 IEEE80211_SN_MODULO;
4144 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
4146 /* update ssn to match received ssn */
4147 tid_agg_rx->head_seq_num = ssn;
4149 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
4153 /* handle the case that received ssn is behind the mac ssn.
4154 * it can be tid_agg_rx->buf_size behind and still be valid */
4155 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
4156 if (diff >= tid_agg_rx->buf_size) {
4157 tid_agg_rx->reorder_buf_filtered = 0;
4160 filtered = filtered >> diff;
4164 for (i = 0; i < tid_agg_rx->buf_size; i++) {
4165 int index = (ssn + i) % tid_agg_rx->buf_size;
4167 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
4168 if (filtered & BIT_ULL(i))
4169 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
4172 /* now process also frames that the filter marking released */
4173 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4176 spin_unlock_bh(&tid_agg_rx->reorder_lock);
4178 ieee80211_rx_handlers(&rx, &frames);
4183 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
4185 /* main receive path */
4187 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
4189 return ether_addr_equal(raddr, addr) ||
4190 is_broadcast_ether_addr(raddr);
4193 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
4195 struct ieee80211_sub_if_data *sdata = rx->sdata;
4196 struct sk_buff *skb = rx->skb;
4197 struct ieee80211_hdr *hdr = (void *)skb->data;
4198 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4199 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
4200 bool multicast = is_multicast_ether_addr(hdr->addr1) ||
4201 ieee80211_is_s1g_beacon(hdr->frame_control);
4203 switch (sdata->vif.type) {
4204 case NL80211_IFTYPE_STATION:
4205 if (!bssid && !sdata->u.mgd.use_4addr)
4207 if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
4211 return ieee80211_is_our_addr(sdata, hdr->addr1, &rx->link_id);
4212 case NL80211_IFTYPE_ADHOC:
4215 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
4216 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
4217 !is_valid_ether_addr(hdr->addr2))
4219 if (ieee80211_is_beacon(hdr->frame_control))
4221 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
4224 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4228 if (status->encoding != RX_ENC_LEGACY)
4229 rate_idx = 0; /* TODO: HT/VHT rates */
4231 rate_idx = status->rate_idx;
4232 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
4236 case NL80211_IFTYPE_OCB:
4239 if (!ieee80211_is_data_present(hdr->frame_control))
4241 if (!is_broadcast_ether_addr(bssid))
4244 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
4248 if (status->encoding != RX_ENC_LEGACY)
4249 rate_idx = 0; /* TODO: HT rates */
4251 rate_idx = status->rate_idx;
4252 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
4256 case NL80211_IFTYPE_MESH_POINT:
4257 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
4261 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4262 case NL80211_IFTYPE_AP_VLAN:
4263 case NL80211_IFTYPE_AP:
4265 return ieee80211_is_our_addr(sdata, hdr->addr1,
4268 if (!is_broadcast_ether_addr(bssid) &&
4269 !ieee80211_is_our_addr(sdata, bssid, NULL)) {
4271 * Accept public action frames even when the
4272 * BSSID doesn't match, this is used for P2P
4273 * and location updates. Note that mac80211
4274 * itself never looks at these frames.
4277 !ieee80211_is_our_addr(sdata, hdr->addr1,
4280 if (ieee80211_is_public_action(hdr, skb->len))
4282 return ieee80211_is_beacon(hdr->frame_control);
4285 if (!ieee80211_has_tods(hdr->frame_control)) {
4286 /* ignore data frames to TDLS-peers */
4287 if (ieee80211_is_data(hdr->frame_control))
4289 /* ignore action frames to TDLS-peers */
4290 if (ieee80211_is_action(hdr->frame_control) &&
4291 !is_broadcast_ether_addr(bssid) &&
4292 !ether_addr_equal(bssid, hdr->addr1))
4297 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4298 * the BSSID - we've checked that already but may have accepted
4299 * the wildcard (ff:ff:ff:ff:ff:ff).
4302 * The BSSID of the Data frame is determined as follows:
4303 * a) If the STA is contained within an AP or is associated
4304 * with an AP, the BSSID is the address currently in use
4305 * by the STA contained in the AP.
4307 * So we should not accept data frames with an address that's
4310 * Accepting it also opens a security problem because stations
4311 * could encrypt it with the GTK and inject traffic that way.
4313 if (ieee80211_is_data(hdr->frame_control) && multicast)
4317 case NL80211_IFTYPE_P2P_DEVICE:
4318 return ieee80211_is_public_action(hdr, skb->len) ||
4319 ieee80211_is_probe_req(hdr->frame_control) ||
4320 ieee80211_is_probe_resp(hdr->frame_control) ||
4321 ieee80211_is_beacon(hdr->frame_control);
4322 case NL80211_IFTYPE_NAN:
4323 /* Currently no frames on NAN interface are allowed */
4333 void ieee80211_check_fast_rx(struct sta_info *sta)
4335 struct ieee80211_sub_if_data *sdata = sta->sdata;
4336 struct ieee80211_local *local = sdata->local;
4337 struct ieee80211_key *key;
4338 struct ieee80211_fast_rx fastrx = {
4340 .vif_type = sdata->vif.type,
4341 .control_port_protocol = sdata->control_port_protocol,
4342 }, *old, *new = NULL;
4343 bool set_offload = false;
4344 bool assign = false;
4347 /* use sparse to check that we don't return without updating */
4348 __acquire(check_fast_rx);
4350 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4351 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4352 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4353 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4355 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4357 /* fast-rx doesn't do reordering */
4358 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4359 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4362 switch (sdata->vif.type) {
4363 case NL80211_IFTYPE_STATION:
4364 if (sta->sta.tdls) {
4365 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4366 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4367 fastrx.expected_ds_bits = 0;
4369 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4370 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4371 fastrx.expected_ds_bits =
4372 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4375 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4376 fastrx.expected_ds_bits |=
4377 cpu_to_le16(IEEE80211_FCTL_TODS);
4378 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4379 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4382 if (!sdata->u.mgd.powersave)
4385 /* software powersave is a huge mess, avoid all of it */
4386 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4388 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4389 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4392 case NL80211_IFTYPE_AP_VLAN:
4393 case NL80211_IFTYPE_AP:
4394 /* parallel-rx requires this, at least with calls to
4395 * ieee80211_sta_ps_transition()
4397 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4399 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4400 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4401 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4403 fastrx.internal_forward =
4404 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4405 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4406 !sdata->u.vlan.sta);
4408 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4409 sdata->u.vlan.sta) {
4410 fastrx.expected_ds_bits |=
4411 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4412 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4413 fastrx.internal_forward = 0;
4421 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4425 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4427 key = rcu_dereference(sdata->default_unicast_key);
4429 switch (key->conf.cipher) {
4430 case WLAN_CIPHER_SUITE_TKIP:
4431 /* we don't want to deal with MMIC in fast-rx */
4433 case WLAN_CIPHER_SUITE_CCMP:
4434 case WLAN_CIPHER_SUITE_CCMP_256:
4435 case WLAN_CIPHER_SUITE_GCMP:
4436 case WLAN_CIPHER_SUITE_GCMP_256:
4439 /* We also don't want to deal with
4440 * WEP or cipher scheme.
4446 fastrx.icv_len = key->conf.icv_len;
4453 __release(check_fast_rx);
4456 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4459 (sdata->vif.offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED);
4462 set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4464 set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4467 drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
4469 spin_lock_bh(&sta->lock);
4470 old = rcu_dereference_protected(sta->fast_rx, true);
4471 rcu_assign_pointer(sta->fast_rx, new);
4472 spin_unlock_bh(&sta->lock);
4475 kfree_rcu(old, rcu_head);
4478 void ieee80211_clear_fast_rx(struct sta_info *sta)
4480 struct ieee80211_fast_rx *old;
4482 spin_lock_bh(&sta->lock);
4483 old = rcu_dereference_protected(sta->fast_rx, true);
4484 RCU_INIT_POINTER(sta->fast_rx, NULL);
4485 spin_unlock_bh(&sta->lock);
4488 kfree_rcu(old, rcu_head);
4491 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4493 struct ieee80211_local *local = sdata->local;
4494 struct sta_info *sta;
4496 lockdep_assert_held(&local->sta_mtx);
4498 list_for_each_entry(sta, &local->sta_list, list) {
4499 if (sdata != sta->sdata &&
4500 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4502 ieee80211_check_fast_rx(sta);
4506 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4508 struct ieee80211_local *local = sdata->local;
4510 mutex_lock(&local->sta_mtx);
4511 __ieee80211_check_fast_rx_iface(sdata);
4512 mutex_unlock(&local->sta_mtx);
4515 static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
4516 struct ieee80211_fast_rx *fast_rx,
4519 struct ieee80211_sta_rx_stats *stats;
4520 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4521 struct sta_info *sta = rx->sta;
4522 struct sk_buff *skb = rx->skb;
4523 void *sa = skb->data + ETH_ALEN;
4524 void *da = skb->data;
4526 stats = &sta->deflink.rx_stats;
4527 if (fast_rx->uses_rss)
4528 stats = this_cpu_ptr(sta->deflink.pcpu_rx_stats);
4530 /* statistics part of ieee80211_rx_h_sta_process() */
4531 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4532 stats->last_signal = status->signal;
4533 if (!fast_rx->uses_rss)
4534 ewma_signal_add(&sta->deflink.rx_stats_avg.signal,
4538 if (status->chains) {
4541 stats->chains = status->chains;
4542 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4543 int signal = status->chain_signal[i];
4545 if (!(status->chains & BIT(i)))
4548 stats->chain_signal_last[i] = signal;
4549 if (!fast_rx->uses_rss)
4550 ewma_signal_add(&sta->deflink.rx_stats_avg.chain_signal[i],
4554 /* end of statistics */
4556 stats->last_rx = jiffies;
4557 stats->last_rate = sta_stats_encode_rate(status);
4562 skb->dev = fast_rx->dev;
4564 dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
4566 /* The seqno index has the same property as needed
4567 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4568 * for non-QoS-data frames. Here we know it's a data
4569 * frame, so count MSDUs.
4571 u64_stats_update_begin(&stats->syncp);
4572 stats->msdu[rx->seqno_idx]++;
4573 stats->bytes += orig_len;
4574 u64_stats_update_end(&stats->syncp);
4576 if (fast_rx->internal_forward) {
4577 struct sk_buff *xmit_skb = NULL;
4578 if (is_multicast_ether_addr(da)) {
4579 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4580 } else if (!ether_addr_equal(da, sa) &&
4581 sta_info_get(rx->sdata, da)) {
4588 * Send to wireless media and increase priority by 256
4589 * to keep the received priority instead of
4590 * reclassifying the frame (see cfg80211_classify8021d).
4592 xmit_skb->priority += 256;
4593 xmit_skb->protocol = htons(ETH_P_802_3);
4594 skb_reset_network_header(xmit_skb);
4595 skb_reset_mac_header(xmit_skb);
4596 dev_queue_xmit(xmit_skb);
4603 /* deliver to local stack */
4604 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4605 ieee80211_deliver_skb_to_local_stack(skb, rx);
4608 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4609 struct ieee80211_fast_rx *fast_rx)
4611 struct sk_buff *skb = rx->skb;
4612 struct ieee80211_hdr *hdr = (void *)skb->data;
4613 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4614 struct sta_info *sta = rx->sta;
4615 int orig_len = skb->len;
4616 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4617 int snap_offs = hdrlen;
4619 u8 snap[sizeof(rfc1042_header)];
4621 } *payload __aligned(2);
4625 } addrs __aligned(2);
4626 struct ieee80211_sta_rx_stats *stats = &sta->deflink.rx_stats;
4628 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4629 * to a common data structure; drivers can implement that per queue
4630 * but we don't have that information in mac80211
4632 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4635 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4637 /* If using encryption, we also need to have:
4638 * - PN_VALIDATED: similar, but the implementation is tricky
4639 * - DECRYPTED: necessary for PN_VALIDATED
4642 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4645 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4648 if (unlikely(ieee80211_is_frag(hdr)))
4651 /* Since our interface address cannot be multicast, this
4652 * implicitly also rejects multicast frames without the
4655 * We shouldn't get any *data* frames not addressed to us
4656 * (AP mode will accept multicast *management* frames), but
4657 * punting here will make it go through the full checks in
4658 * ieee80211_accept_frame().
4660 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4663 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4664 IEEE80211_FCTL_TODS)) !=
4665 fast_rx->expected_ds_bits)
4668 /* assign the key to drop unencrypted frames (later)
4669 * and strip the IV/MIC if necessary
4671 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4672 /* GCMP header length is the same */
4673 snap_offs += IEEE80211_CCMP_HDR_LEN;
4676 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4677 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4680 payload = (void *)(skb->data + snap_offs);
4682 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4685 /* Don't handle these here since they require special code.
4686 * Accept AARP and IPX even though they should come with a
4687 * bridge-tunnel header - but if we get them this way then
4688 * there's little point in discarding them.
4690 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4691 payload->proto == fast_rx->control_port_protocol))
4695 /* after this point, don't punt to the slowpath! */
4697 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4698 pskb_trim(skb, skb->len - fast_rx->icv_len))
4701 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4704 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4705 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4712 /* do the header conversion - first grab the addresses */
4713 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4714 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4715 skb_postpull_rcsum(skb, skb->data + snap_offs,
4716 sizeof(rfc1042_header) + 2);
4717 /* remove the SNAP but leave the ethertype */
4718 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4719 /* push the addresses in front */
4720 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4722 ieee80211_rx_8023(rx, fast_rx, orig_len);
4727 if (fast_rx->uses_rss)
4728 stats = this_cpu_ptr(sta->deflink.pcpu_rx_stats);
4735 * This function returns whether or not the SKB
4736 * was destined for RX processing or not, which,
4737 * if consume is true, is equivalent to whether
4738 * or not the skb was consumed.
4740 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4741 struct sk_buff *skb, bool consume)
4743 struct ieee80211_local *local = rx->local;
4744 struct ieee80211_sub_if_data *sdata = rx->sdata;
4745 struct ieee80211_hdr *hdr = (void *)skb->data;
4746 struct link_sta_info *link_sta = NULL;
4747 struct ieee80211_link_data *link;
4751 /* See if we can do fast-rx; if we have to copy we already lost,
4752 * so punt in that case. We should never have to deliver a data
4753 * frame to multiple interfaces anyway.
4755 * We skip the ieee80211_accept_frame() call and do the necessary
4756 * checking inside ieee80211_invoke_fast_rx().
4758 if (consume && rx->sta) {
4759 struct ieee80211_fast_rx *fast_rx;
4761 fast_rx = rcu_dereference(rx->sta->fast_rx);
4762 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4766 if (!ieee80211_accept_frame(rx))
4769 if (rx->link_id >= 0) {
4770 link = rcu_dereference(rx->sdata->link[rx->link_id]);
4772 /* we might race link removal */
4777 rx->link = &sdata->deflink;
4780 if (unlikely(!is_multicast_ether_addr(hdr->addr1) &&
4781 rx->link_id >= 0 && rx->sta && rx->sta->sta.mlo)) {
4782 link_sta = rcu_dereference(rx->sta->link[rx->link_id]);
4784 if (WARN_ON_ONCE(!link_sta))
4789 struct skb_shared_hwtstamps *shwt;
4791 rx->skb = skb_copy(skb, GFP_ATOMIC);
4793 if (net_ratelimit())
4794 wiphy_debug(local->hw.wiphy,
4795 "failed to copy skb for %s\n",
4800 /* skb_copy() does not copy the hw timestamps, so copy it
4803 shwt = skb_hwtstamps(rx->skb);
4804 shwt->hwtstamp = skb_hwtstamps(skb)->hwtstamp;
4807 if (unlikely(link_sta)) {
4808 /* translate to MLD addresses */
4809 if (ether_addr_equal(link->conf->addr, hdr->addr1))
4810 ether_addr_copy(hdr->addr1, rx->sdata->vif.addr);
4811 if (ether_addr_equal(link_sta->addr, hdr->addr2))
4812 ether_addr_copy(hdr->addr2, rx->sta->addr);
4813 /* translate A3 only if it's the BSSID */
4814 if (!ieee80211_has_tods(hdr->frame_control) &&
4815 !ieee80211_has_fromds(hdr->frame_control)) {
4816 if (ether_addr_equal(link_sta->addr, hdr->addr3))
4817 ether_addr_copy(hdr->addr3, rx->sta->addr);
4818 else if (ether_addr_equal(link->conf->addr, hdr->addr3))
4819 ether_addr_copy(hdr->addr3, rx->sdata->vif.addr);
4821 /* not needed for A4 since it can only carry the SA */
4824 ieee80211_invoke_rx_handlers(rx);
4828 static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
4829 struct ieee80211_sta *pubsta,
4830 struct sk_buff *skb,
4831 struct list_head *list)
4833 struct ieee80211_local *local = hw_to_local(hw);
4834 struct ieee80211_fast_rx *fast_rx;
4835 struct ieee80211_rx_data rx;
4837 memset(&rx, 0, sizeof(rx));
4843 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4845 /* drop frame if too short for header */
4846 if (skb->len < sizeof(struct ethhdr))
4852 rx.sta = container_of(pubsta, struct sta_info, sta);
4853 rx.sdata = rx.sta->sdata;
4854 rx.link = &rx.sdata->deflink;
4856 fast_rx = rcu_dereference(rx.sta->fast_rx);
4860 ieee80211_rx_8023(&rx, fast_rx, skb->len);
4867 static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx,
4868 struct sk_buff *skb, bool consume)
4870 struct link_sta_info *link_sta;
4871 struct ieee80211_hdr *hdr = (void *)skb->data;
4874 * Look up link station first, in case there's a
4875 * chance that they might have a link address that
4876 * is identical to the MLD address, that way we'll
4877 * have the link information if needed.
4879 link_sta = link_sta_info_get_bss(rx->sdata, hdr->addr2);
4881 rx->sta = link_sta->sta;
4882 rx->link_id = link_sta->link_id;
4884 rx->sta = sta_info_get_bss(rx->sdata, hdr->addr2);
4887 return ieee80211_prepare_and_rx_handle(rx, skb, consume);
4891 * This is the actual Rx frames handler. as it belongs to Rx path it must
4892 * be called with rcu_read_lock protection.
4894 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4895 struct ieee80211_sta *pubsta,
4896 struct sk_buff *skb,
4897 struct list_head *list)
4899 struct ieee80211_local *local = hw_to_local(hw);
4900 struct ieee80211_sub_if_data *sdata;
4901 struct ieee80211_hdr *hdr;
4903 struct ieee80211_rx_data rx;
4904 struct ieee80211_sub_if_data *prev;
4905 struct rhlist_head *tmp;
4908 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4909 memset(&rx, 0, sizeof(rx));
4915 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4916 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4918 if (ieee80211_is_mgmt(fc)) {
4919 /* drop frame if too short for header */
4920 if (skb->len < ieee80211_hdrlen(fc))
4923 err = skb_linearize(skb);
4925 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4933 hdr = (struct ieee80211_hdr *)skb->data;
4934 ieee80211_parse_qos(&rx);
4935 ieee80211_verify_alignment(&rx);
4937 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4938 ieee80211_is_beacon(hdr->frame_control) ||
4939 ieee80211_is_s1g_beacon(hdr->frame_control)))
4940 ieee80211_scan_rx(local, skb);
4942 if (ieee80211_is_data(fc)) {
4943 struct sta_info *sta, *prev_sta;
4946 rx.sta = container_of(pubsta, struct sta_info, sta);
4947 rx.sdata = rx.sta->sdata;
4948 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4955 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4962 rx.sdata = prev_sta->sdata;
4963 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4970 rx.sdata = prev_sta->sdata;
4972 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4980 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4981 if (!ieee80211_sdata_running(sdata))
4984 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4985 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4989 * frame is destined for this interface, but if it's
4990 * not also for the previous one we handle that after
4991 * the loop to avoid copying the SKB once too much
5000 ieee80211_rx_for_interface(&rx, skb, false);
5008 if (ieee80211_rx_for_interface(&rx, skb, true))
5017 * This is the receive path handler. It is called by a low level driver when an
5018 * 802.11 MPDU is received from the hardware.
5020 void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5021 struct sk_buff *skb, struct list_head *list)
5023 struct ieee80211_local *local = hw_to_local(hw);
5024 struct ieee80211_rate *rate = NULL;
5025 struct ieee80211_supported_band *sband;
5026 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5027 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5029 WARN_ON_ONCE(softirq_count() == 0);
5031 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
5034 sband = local->hw.wiphy->bands[status->band];
5035 if (WARN_ON(!sband))
5039 * If we're suspending, it is possible although not too likely
5040 * that we'd be receiving frames after having already partially
5041 * quiesced the stack. We can't process such frames then since
5042 * that might, for example, cause stations to be added or other
5043 * driver callbacks be invoked.
5045 if (unlikely(local->quiescing || local->suspended))
5048 /* We might be during a HW reconfig, prevent Rx for the same reason */
5049 if (unlikely(local->in_reconfig))
5053 * The same happens when we're not even started,
5054 * but that's worth a warning.
5056 if (WARN_ON(!local->started))
5059 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
5061 * Validate the rate, unless a PLCP error means that
5062 * we probably can't have a valid rate here anyway.
5065 switch (status->encoding) {
5068 * rate_idx is MCS index, which can be [0-76]
5071 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
5073 * Anything else would be some sort of driver or
5074 * hardware error. The driver should catch hardware
5077 if (WARN(status->rate_idx > 76,
5078 "Rate marked as an HT rate but passed "
5079 "status->rate_idx is not "
5080 "an MCS index [0-76]: %d (0x%02x)\n",
5086 if (WARN_ONCE(status->rate_idx > 11 ||
5089 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
5090 status->rate_idx, status->nss))
5094 if (WARN_ONCE(status->rate_idx > 11 ||
5097 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
5098 status->rate_idx, status->nss))
5105 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
5107 rate = &sband->bitrates[status->rate_idx];
5111 status->rx_flags = 0;
5113 kcov_remote_start_common(skb_get_kcov_handle(skb));
5116 * Frames with failed FCS/PLCP checksum are not returned,
5117 * all other frames are returned without radiotap header
5118 * if it was previously present.
5119 * Also, frames with less than 16 bytes are dropped.
5121 if (!(status->flag & RX_FLAG_8023))
5122 skb = ieee80211_rx_monitor(local, skb, rate);
5124 if ((status->flag & RX_FLAG_8023) ||
5125 ieee80211_is_data_present(hdr->frame_control))
5126 ieee80211_tpt_led_trig_rx(local, skb->len);
5128 if (status->flag & RX_FLAG_8023)
5129 __ieee80211_rx_handle_8023(hw, pubsta, skb, list);
5131 __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
5139 EXPORT_SYMBOL(ieee80211_rx_list);
5141 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5142 struct sk_buff *skb, struct napi_struct *napi)
5144 struct sk_buff *tmp;
5149 * key references and virtual interfaces are protected using RCU
5150 * and this requires that we are in a read-side RCU section during
5151 * receive processing
5154 ieee80211_rx_list(hw, pubsta, skb, &list);
5158 netif_receive_skb_list(&list);
5162 list_for_each_entry_safe(skb, tmp, &list, list) {
5163 skb_list_del_init(skb);
5164 napi_gro_receive(napi, skb);
5167 EXPORT_SYMBOL(ieee80211_rx_napi);
5169 /* This is a version of the rx handler that can be called from hard irq
5170 * context. Post the skb on the queue and schedule the tasklet */
5171 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
5173 struct ieee80211_local *local = hw_to_local(hw);
5175 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
5177 skb->pkt_type = IEEE80211_RX_MSG;
5178 skb_queue_tail(&local->skb_queue, skb);
5179 tasklet_schedule(&local->tasklet);
5181 EXPORT_SYMBOL(ieee80211_rx_irqsafe);