1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
5 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
6 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
9 * Copyright (C) 2018-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,
219 struct sta_info *sta,
222 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
225 status->link_valid = 1;
226 status->link_id = link_id;
228 status->link_valid = 0;
231 skb_queue_tail(&sdata->skb_queue, skb);
232 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
234 sta->deflink.rx_stats.packets++;
237 static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
239 struct sta_info *sta,
243 __ieee80211_queue_skb_to_iface(sdata, link_id, sta, skb);
246 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
251 struct ieee80211_hdr_3addr hdr;
254 } __packed __aligned(2) action;
259 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
261 if (skb->len < rtap_space + sizeof(action) +
262 VHT_MUMIMO_GROUPS_DATA_LEN)
265 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
268 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
270 if (!ieee80211_is_action(action.hdr.frame_control))
273 if (action.category != WLAN_CATEGORY_VHT)
276 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
279 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
282 skb = skb_copy(skb, GFP_ATOMIC);
286 ieee80211_queue_skb_to_iface(sdata, -1, NULL, skb);
290 * ieee80211_add_rx_radiotap_header - add radiotap header
292 * add a radiotap header containing all the fields which the hardware provided.
295 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
297 struct ieee80211_rate *rate,
298 int rtap_len, bool has_fcs)
300 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
301 struct ieee80211_radiotap_header *rthdr;
306 u16 channel_flags = 0;
308 unsigned long chains = status->chains;
309 struct ieee80211_vendor_radiotap rtap = {};
310 struct ieee80211_radiotap_he he = {};
311 struct ieee80211_radiotap_he_mu he_mu = {};
312 struct ieee80211_radiotap_lsig lsig = {};
314 if (status->flag & RX_FLAG_RADIOTAP_HE) {
315 he = *(struct ieee80211_radiotap_he *)skb->data;
316 skb_pull(skb, sizeof(he));
317 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
320 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
321 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
322 skb_pull(skb, sizeof(he_mu));
325 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
326 lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
327 skb_pull(skb, sizeof(lsig));
330 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
331 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
332 /* rtap.len and rtap.pad are undone immediately */
333 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
337 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
340 rthdr = skb_push(skb, rtap_len);
341 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
342 it_present = &rthdr->it_present;
344 /* radiotap header, set always present flags */
345 rthdr->it_len = cpu_to_le16(rtap_len);
346 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
347 BIT(IEEE80211_RADIOTAP_CHANNEL) |
348 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
351 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
353 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
355 BIT(IEEE80211_RADIOTAP_EXT) |
356 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
357 put_unaligned_le32(it_present_val, it_present);
359 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
360 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
363 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
364 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
365 BIT(IEEE80211_RADIOTAP_EXT);
366 put_unaligned_le32(it_present_val, it_present);
368 it_present_val = rtap.present;
371 put_unaligned_le32(it_present_val, it_present);
373 /* This references through an offset into it_optional[] rather
374 * than via it_present otherwise later uses of pos will cause
375 * the compiler to think we have walked past the end of the
378 pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
380 /* the order of the following fields is important */
382 /* IEEE80211_RADIOTAP_TSFT */
383 if (ieee80211_have_rx_timestamp(status)) {
385 while ((pos - (u8 *)rthdr) & 7)
388 ieee80211_calculate_rx_timestamp(local, status,
391 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));
395 /* IEEE80211_RADIOTAP_FLAGS */
396 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
397 *pos |= IEEE80211_RADIOTAP_F_FCS;
398 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
399 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
400 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
401 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
404 /* IEEE80211_RADIOTAP_RATE */
405 if (!rate || status->encoding != RX_ENC_LEGACY) {
407 * Without rate information don't add it. If we have,
408 * MCS information is a separate field in radiotap,
409 * added below. The byte here is needed as padding
410 * for the channel though, so initialise it to 0.
415 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
416 if (status->bw == RATE_INFO_BW_10)
418 else if (status->bw == RATE_INFO_BW_5)
420 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
424 /* IEEE80211_RADIOTAP_CHANNEL */
425 /* TODO: frequency offset in KHz */
426 put_unaligned_le16(status->freq, pos);
428 if (status->bw == RATE_INFO_BW_10)
429 channel_flags |= IEEE80211_CHAN_HALF;
430 else if (status->bw == RATE_INFO_BW_5)
431 channel_flags |= IEEE80211_CHAN_QUARTER;
433 if (status->band == NL80211_BAND_5GHZ ||
434 status->band == NL80211_BAND_6GHZ)
435 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
436 else if (status->encoding != RX_ENC_LEGACY)
437 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
438 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
439 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
441 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
443 channel_flags |= IEEE80211_CHAN_2GHZ;
444 put_unaligned_le16(channel_flags, pos);
447 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
448 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
449 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
450 *pos = status->signal;
452 cpu_to_le32(BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
456 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
458 if (!status->chains) {
459 /* IEEE80211_RADIOTAP_ANTENNA */
460 *pos = status->antenna;
464 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
466 /* IEEE80211_RADIOTAP_RX_FLAGS */
467 /* ensure 2 byte alignment for the 2 byte field as required */
468 if ((pos - (u8 *)rthdr) & 1)
470 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
471 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
472 put_unaligned_le16(rx_flags, pos);
475 if (status->encoding == RX_ENC_HT) {
478 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
479 *pos = local->hw.radiotap_mcs_details;
480 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
481 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
482 if (status->enc_flags & RX_ENC_FLAG_LDPC)
483 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FEC;
486 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
487 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
488 if (status->bw == RATE_INFO_BW_40)
489 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
490 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
491 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
492 if (status->enc_flags & RX_ENC_FLAG_LDPC)
493 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
494 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
495 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
497 *pos++ = status->rate_idx;
500 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
503 /* ensure 4 byte alignment */
504 while ((pos - (u8 *)rthdr) & 3)
507 cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
508 put_unaligned_le32(status->ampdu_reference, pos);
510 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
511 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
512 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
513 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
514 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
515 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
516 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
517 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
518 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
519 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
520 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
521 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
522 put_unaligned_le16(flags, pos);
524 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
525 *pos++ = status->ampdu_delimiter_crc;
531 if (status->encoding == RX_ENC_VHT) {
532 u16 known = local->hw.radiotap_vht_details;
534 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
535 put_unaligned_le16(known, pos);
538 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
539 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
540 /* in VHT, STBC is binary */
541 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
542 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
543 if (status->enc_flags & RX_ENC_FLAG_BF)
544 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
547 switch (status->bw) {
548 case RATE_INFO_BW_80:
551 case RATE_INFO_BW_160:
554 case RATE_INFO_BW_40:
561 *pos = (status->rate_idx << 4) | status->nss;
564 if (status->enc_flags & RX_ENC_FLAG_LDPC)
565 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
573 if (local->hw.radiotap_timestamp.units_pos >= 0) {
575 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
578 cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
580 /* ensure 8 byte alignment */
581 while ((pos - (u8 *)rthdr) & 7)
584 put_unaligned_le64(status->device_timestamp, pos);
587 if (local->hw.radiotap_timestamp.accuracy >= 0) {
588 accuracy = local->hw.radiotap_timestamp.accuracy;
589 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
591 put_unaligned_le16(accuracy, pos);
594 *pos++ = local->hw.radiotap_timestamp.units_pos;
598 if (status->encoding == RX_ENC_HE &&
599 status->flag & RX_FLAG_RADIOTAP_HE) {
600 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
602 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
603 he.data6 |= HE_PREP(DATA6_NSTS,
604 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
606 he.data3 |= HE_PREP(DATA3_STBC, 1);
608 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
611 #define CHECK_GI(s) \
612 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
613 (int)NL80211_RATE_INFO_HE_GI_##s)
619 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
620 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
621 he.data3 |= HE_PREP(DATA3_CODING,
622 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
624 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
626 switch (status->bw) {
627 case RATE_INFO_BW_20:
628 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
629 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
631 case RATE_INFO_BW_40:
632 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
633 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
635 case RATE_INFO_BW_80:
636 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
637 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
639 case RATE_INFO_BW_160:
640 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
641 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
643 case RATE_INFO_BW_HE_RU:
644 #define CHECK_RU_ALLOC(s) \
645 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
646 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
654 CHECK_RU_ALLOC(2x996);
656 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
660 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
663 /* ensure 2 byte alignment */
664 while ((pos - (u8 *)rthdr) & 1)
666 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
667 memcpy(pos, &he, sizeof(he));
671 if (status->encoding == RX_ENC_HE &&
672 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
673 /* ensure 2 byte alignment */
674 while ((pos - (u8 *)rthdr) & 1)
676 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
677 memcpy(pos, &he_mu, sizeof(he_mu));
678 pos += sizeof(he_mu);
681 if (status->flag & RX_FLAG_NO_PSDU) {
683 cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
684 *pos++ = status->zero_length_psdu_type;
687 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
688 /* ensure 2 byte alignment */
689 while ((pos - (u8 *)rthdr) & 1)
691 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
692 memcpy(pos, &lsig, sizeof(lsig));
696 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
697 *pos++ = status->chain_signal[chain];
701 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
702 /* ensure 2 byte alignment for the vendor field as required */
703 if ((pos - (u8 *)rthdr) & 1)
705 *pos++ = rtap.oui[0];
706 *pos++ = rtap.oui[1];
707 *pos++ = rtap.oui[2];
709 put_unaligned_le16(rtap.len, pos);
711 /* align the actual payload as requested */
712 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
714 /* data (and possible padding) already follows */
718 static struct sk_buff *
719 ieee80211_make_monitor_skb(struct ieee80211_local *local,
720 struct sk_buff **origskb,
721 struct ieee80211_rate *rate,
722 int rtap_space, bool use_origskb)
724 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
725 int rt_hdrlen, needed_headroom;
728 /* room for the radiotap header based on driver features */
729 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
730 needed_headroom = rt_hdrlen - rtap_space;
733 /* only need to expand headroom if necessary */
738 * This shouldn't trigger often because most devices have an
739 * RX header they pull before we get here, and that should
740 * be big enough for our radiotap information. We should
741 * probably export the length to drivers so that we can have
742 * them allocate enough headroom to start with.
744 if (skb_headroom(skb) < needed_headroom &&
745 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
751 * Need to make a copy and possibly remove radiotap header
752 * and FCS from the original.
754 skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
761 /* prepend radiotap information */
762 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
764 skb_reset_mac_header(skb);
765 skb->ip_summed = CHECKSUM_UNNECESSARY;
766 skb->pkt_type = PACKET_OTHERHOST;
767 skb->protocol = htons(ETH_P_802_2);
773 * This function copies a received frame to all monitor interfaces and
774 * returns a cleaned-up SKB that no longer includes the FCS nor the
775 * radiotap header the driver might have added.
777 static struct sk_buff *
778 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
779 struct ieee80211_rate *rate)
781 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
782 struct ieee80211_sub_if_data *sdata;
783 struct sk_buff *monskb = NULL;
784 int present_fcs_len = 0;
785 unsigned int rtap_space = 0;
786 struct ieee80211_sub_if_data *monitor_sdata =
787 rcu_dereference(local->monitor_sdata);
788 bool only_monitor = false;
789 unsigned int min_head_len;
791 if (status->flag & RX_FLAG_RADIOTAP_HE)
792 rtap_space += sizeof(struct ieee80211_radiotap_he);
794 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
795 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
797 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
798 rtap_space += sizeof(struct ieee80211_radiotap_lsig);
800 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
801 struct ieee80211_vendor_radiotap *rtap =
802 (void *)(origskb->data + rtap_space);
804 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
807 min_head_len = rtap_space;
810 * First, we may need to make a copy of the skb because
811 * (1) we need to modify it for radiotap (if not present), and
812 * (2) the other RX handlers will modify the skb we got.
814 * We don't need to, of course, if we aren't going to return
815 * the SKB because it has a bad FCS/PLCP checksum.
818 if (!(status->flag & RX_FLAG_NO_PSDU)) {
819 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
820 if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
823 dev_kfree_skb(origskb);
826 present_fcs_len = FCS_LEN;
829 /* also consider the hdr->frame_control */
833 /* ensure that the expected data elements are in skb head */
834 if (!pskb_may_pull(origskb, min_head_len)) {
835 dev_kfree_skb(origskb);
839 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
841 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
843 dev_kfree_skb(origskb);
847 return ieee80211_clean_skb(origskb, present_fcs_len,
851 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
853 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
854 bool last_monitor = list_is_last(&sdata->u.mntr.list,
858 monskb = ieee80211_make_monitor_skb(local, &origskb,
870 skb = skb_clone(monskb, GFP_ATOMIC);
874 skb->dev = sdata->dev;
875 dev_sw_netstats_rx_add(skb->dev, skb->len);
876 netif_receive_skb(skb);
884 /* this happens if last_monitor was erroneously false */
885 dev_kfree_skb(monskb);
891 return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
894 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
896 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
897 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
898 int tid, seqno_idx, security_idx;
900 /* does the frame have a qos control field? */
901 if (ieee80211_is_data_qos(hdr->frame_control)) {
902 u8 *qc = ieee80211_get_qos_ctl(hdr);
903 /* frame has qos control */
904 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
905 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
906 status->rx_flags |= IEEE80211_RX_AMSDU;
912 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
914 * Sequence numbers for management frames, QoS data
915 * frames with a broadcast/multicast address in the
916 * Address 1 field, and all non-QoS data frames sent
917 * by QoS STAs are assigned using an additional single
918 * modulo-4096 counter, [...]
920 * We also use that counter for non-QoS STAs.
922 seqno_idx = IEEE80211_NUM_TIDS;
924 if (ieee80211_is_mgmt(hdr->frame_control))
925 security_idx = IEEE80211_NUM_TIDS;
929 rx->seqno_idx = seqno_idx;
930 rx->security_idx = security_idx;
931 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
932 * For now, set skb->priority to 0 for other cases. */
933 rx->skb->priority = (tid > 7) ? 0 : tid;
937 * DOC: Packet alignment
939 * Drivers always need to pass packets that are aligned to two-byte boundaries
942 * Additionally, should, if possible, align the payload data in a way that
943 * guarantees that the contained IP header is aligned to a four-byte
944 * boundary. In the case of regular frames, this simply means aligning the
945 * payload to a four-byte boundary (because either the IP header is directly
946 * contained, or IV/RFC1042 headers that have a length divisible by four are
947 * in front of it). If the payload data is not properly aligned and the
948 * architecture doesn't support efficient unaligned operations, mac80211
949 * will align the data.
951 * With A-MSDU frames, however, the payload data address must yield two modulo
952 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
953 * push the IP header further back to a multiple of four again. Thankfully, the
954 * specs were sane enough this time around to require padding each A-MSDU
955 * subframe to a length that is a multiple of four.
957 * Padding like Atheros hardware adds which is between the 802.11 header and
958 * the payload is not supported, the driver is required to move the 802.11
959 * header to be directly in front of the payload in that case.
961 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
963 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
964 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
971 static int ieee80211_is_unicast_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 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
984 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
986 if (!is_multicast_ether_addr(hdr->addr1))
989 return ieee80211_is_robust_mgmt_frame(skb);
993 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
994 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
996 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
997 struct ieee80211_mmie *mmie;
998 struct ieee80211_mmie_16 *mmie16;
1000 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
1003 if (!ieee80211_is_robust_mgmt_frame(skb) &&
1004 !ieee80211_is_beacon(hdr->frame_control))
1005 return -1; /* not a robust management frame */
1007 mmie = (struct ieee80211_mmie *)
1008 (skb->data + skb->len - sizeof(*mmie));
1009 if (mmie->element_id == WLAN_EID_MMIE &&
1010 mmie->length == sizeof(*mmie) - 2)
1011 return le16_to_cpu(mmie->key_id);
1013 mmie16 = (struct ieee80211_mmie_16 *)
1014 (skb->data + skb->len - sizeof(*mmie16));
1015 if (skb->len >= 24 + sizeof(*mmie16) &&
1016 mmie16->element_id == WLAN_EID_MMIE &&
1017 mmie16->length == sizeof(*mmie16) - 2)
1018 return le16_to_cpu(mmie16->key_id);
1023 static int ieee80211_get_keyid(struct sk_buff *skb)
1025 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1026 __le16 fc = hdr->frame_control;
1027 int hdrlen = ieee80211_hdrlen(fc);
1030 /* WEP, TKIP, CCMP and GCMP */
1031 if (unlikely(skb->len < hdrlen + IEEE80211_WEP_IV_LEN))
1034 skb_copy_bits(skb, hdrlen + 3, &keyid, 1);
1041 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1043 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1044 char *dev_addr = rx->sdata->vif.addr;
1046 if (ieee80211_is_data(hdr->frame_control)) {
1047 if (is_multicast_ether_addr(hdr->addr1)) {
1048 if (ieee80211_has_tods(hdr->frame_control) ||
1049 !ieee80211_has_fromds(hdr->frame_control))
1050 return RX_DROP_MONITOR;
1051 if (ether_addr_equal(hdr->addr3, dev_addr))
1052 return RX_DROP_MONITOR;
1054 if (!ieee80211_has_a4(hdr->frame_control))
1055 return RX_DROP_MONITOR;
1056 if (ether_addr_equal(hdr->addr4, dev_addr))
1057 return RX_DROP_MONITOR;
1061 /* If there is not an established peer link and this is not a peer link
1062 * establisment frame, beacon or probe, drop the frame.
1065 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1066 struct ieee80211_mgmt *mgmt;
1068 if (!ieee80211_is_mgmt(hdr->frame_control))
1069 return RX_DROP_MONITOR;
1071 if (ieee80211_is_action(hdr->frame_control)) {
1074 /* make sure category field is present */
1075 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1076 return RX_DROP_MONITOR;
1078 mgmt = (struct ieee80211_mgmt *)hdr;
1079 category = mgmt->u.action.category;
1080 if (category != WLAN_CATEGORY_MESH_ACTION &&
1081 category != WLAN_CATEGORY_SELF_PROTECTED)
1082 return RX_DROP_MONITOR;
1086 if (ieee80211_is_probe_req(hdr->frame_control) ||
1087 ieee80211_is_probe_resp(hdr->frame_control) ||
1088 ieee80211_is_beacon(hdr->frame_control) ||
1089 ieee80211_is_auth(hdr->frame_control))
1092 return RX_DROP_MONITOR;
1098 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1101 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1102 struct sk_buff *tail = skb_peek_tail(frames);
1103 struct ieee80211_rx_status *status;
1105 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1111 status = IEEE80211_SKB_RXCB(tail);
1112 if (status->flag & RX_FLAG_AMSDU_MORE)
1118 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1119 struct tid_ampdu_rx *tid_agg_rx,
1121 struct sk_buff_head *frames)
1123 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1124 struct sk_buff *skb;
1125 struct ieee80211_rx_status *status;
1127 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1129 if (skb_queue_empty(skb_list))
1132 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1133 __skb_queue_purge(skb_list);
1137 /* release frames from the reorder ring buffer */
1138 tid_agg_rx->stored_mpdu_num--;
1139 while ((skb = __skb_dequeue(skb_list))) {
1140 status = IEEE80211_SKB_RXCB(skb);
1141 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1142 __skb_queue_tail(frames, skb);
1146 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1147 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1150 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1151 struct tid_ampdu_rx *tid_agg_rx,
1153 struct sk_buff_head *frames)
1157 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1159 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1160 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1161 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1167 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1168 * the skb was added to the buffer longer than this time ago, the earlier
1169 * frames that have not yet been received are assumed to be lost and the skb
1170 * can be released for processing. This may also release other skb's from the
1171 * reorder buffer if there are no additional gaps between the frames.
1173 * Callers must hold tid_agg_rx->reorder_lock.
1175 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1177 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1178 struct tid_ampdu_rx *tid_agg_rx,
1179 struct sk_buff_head *frames)
1183 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1185 /* release the buffer until next missing frame */
1186 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1187 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1188 tid_agg_rx->stored_mpdu_num) {
1190 * No buffers ready to be released, but check whether any
1191 * frames in the reorder buffer have timed out.
1194 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1195 j = (j + 1) % tid_agg_rx->buf_size) {
1196 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1201 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1202 HT_RX_REORDER_BUF_TIMEOUT))
1203 goto set_release_timer;
1205 /* don't leave incomplete A-MSDUs around */
1206 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1207 i = (i + 1) % tid_agg_rx->buf_size)
1208 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1210 ht_dbg_ratelimited(sdata,
1211 "release an RX reorder frame due to timeout on earlier frames\n");
1212 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1216 * Increment the head seq# also for the skipped slots.
1218 tid_agg_rx->head_seq_num =
1219 (tid_agg_rx->head_seq_num +
1220 skipped) & IEEE80211_SN_MASK;
1223 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1224 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1226 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1229 if (tid_agg_rx->stored_mpdu_num) {
1230 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1232 for (; j != (index - 1) % tid_agg_rx->buf_size;
1233 j = (j + 1) % tid_agg_rx->buf_size) {
1234 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1240 if (!tid_agg_rx->removed)
1241 mod_timer(&tid_agg_rx->reorder_timer,
1242 tid_agg_rx->reorder_time[j] + 1 +
1243 HT_RX_REORDER_BUF_TIMEOUT);
1245 del_timer(&tid_agg_rx->reorder_timer);
1250 * As this function belongs to the RX path it must be under
1251 * rcu_read_lock protection. It returns false if the frame
1252 * can be processed immediately, true if it was consumed.
1254 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1255 struct tid_ampdu_rx *tid_agg_rx,
1256 struct sk_buff *skb,
1257 struct sk_buff_head *frames)
1259 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1260 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1261 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1262 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1263 u16 head_seq_num, buf_size;
1267 spin_lock(&tid_agg_rx->reorder_lock);
1270 * Offloaded BA sessions have no known starting sequence number so pick
1271 * one from first Rxed frame for this tid after BA was started.
1273 if (unlikely(tid_agg_rx->auto_seq)) {
1274 tid_agg_rx->auto_seq = false;
1275 tid_agg_rx->ssn = mpdu_seq_num;
1276 tid_agg_rx->head_seq_num = mpdu_seq_num;
1279 buf_size = tid_agg_rx->buf_size;
1280 head_seq_num = tid_agg_rx->head_seq_num;
1283 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1286 if (unlikely(!tid_agg_rx->started)) {
1287 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1291 tid_agg_rx->started = true;
1294 /* frame with out of date sequence number */
1295 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1301 * If frame the sequence number exceeds our buffering window
1302 * size release some previous frames to make room for this one.
1304 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1305 head_seq_num = ieee80211_sn_inc(
1306 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1307 /* release stored frames up to new head to stack */
1308 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1309 head_seq_num, frames);
1312 /* Now the new frame is always in the range of the reordering buffer */
1314 index = mpdu_seq_num % tid_agg_rx->buf_size;
1316 /* check if we already stored this frame */
1317 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1323 * If the current MPDU is in the right order and nothing else
1324 * is stored we can process it directly, no need to buffer it.
1325 * If it is first but there's something stored, we may be able
1326 * to release frames after this one.
1328 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1329 tid_agg_rx->stored_mpdu_num == 0) {
1330 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1331 tid_agg_rx->head_seq_num =
1332 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1337 /* put the frame in the reordering buffer */
1338 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1339 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1340 tid_agg_rx->reorder_time[index] = jiffies;
1341 tid_agg_rx->stored_mpdu_num++;
1342 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1346 spin_unlock(&tid_agg_rx->reorder_lock);
1351 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1352 * true if the MPDU was buffered, false if it should be processed.
1354 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1355 struct sk_buff_head *frames)
1357 struct sk_buff *skb = rx->skb;
1358 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1359 struct sta_info *sta = rx->sta;
1360 struct tid_ampdu_rx *tid_agg_rx;
1364 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1365 is_multicast_ether_addr(hdr->addr1))
1369 * filter the QoS data rx stream according to
1370 * STA/TID and check if this STA/TID is on aggregation
1376 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1377 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1378 tid = ieee80211_get_tid(hdr);
1380 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1382 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1383 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1384 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1385 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1386 WLAN_BACK_RECIPIENT,
1387 WLAN_REASON_QSTA_REQUIRE_SETUP);
1391 /* qos null data frames are excluded */
1392 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1395 /* not part of a BA session */
1396 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
1399 /* new, potentially un-ordered, ampdu frame - process it */
1401 /* reset session timer */
1402 if (tid_agg_rx->timeout)
1403 tid_agg_rx->last_rx = jiffies;
1405 /* if this mpdu is fragmented - terminate rx aggregation session */
1406 sc = le16_to_cpu(hdr->seq_ctrl);
1407 if (sc & IEEE80211_SCTL_FRAG) {
1408 ieee80211_queue_skb_to_iface(rx->sdata, rx->link_id, NULL, skb);
1413 * No locking needed -- we will only ever process one
1414 * RX packet at a time, and thus own tid_agg_rx. All
1415 * other code manipulating it needs to (and does) make
1416 * sure that we cannot get to it any more before doing
1419 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1424 __skb_queue_tail(frames, skb);
1427 static ieee80211_rx_result debug_noinline
1428 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1430 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1431 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1433 if (status->flag & RX_FLAG_DUP_VALIDATED)
1437 * Drop duplicate 802.11 retransmissions
1438 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1441 if (rx->skb->len < 24)
1444 if (ieee80211_is_ctl(hdr->frame_control) ||
1445 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1446 is_multicast_ether_addr(hdr->addr1))
1452 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1453 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1454 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1455 rx->link_sta->rx_stats.num_duplicates++;
1456 return RX_DROP_UNUSABLE;
1457 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1458 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1464 static ieee80211_rx_result debug_noinline
1465 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1467 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1469 /* Drop disallowed frame classes based on STA auth/assoc state;
1470 * IEEE 802.11, Chap 5.5.
1472 * mac80211 filters only based on association state, i.e. it drops
1473 * Class 3 frames from not associated stations. hostapd sends
1474 * deauth/disassoc frames when needed. In addition, hostapd is
1475 * responsible for filtering on both auth and assoc states.
1478 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1479 return ieee80211_rx_mesh_check(rx);
1481 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1482 ieee80211_is_pspoll(hdr->frame_control)) &&
1483 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1484 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1485 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1487 * accept port control frames from the AP even when it's not
1488 * yet marked ASSOC to prevent a race where we don't set the
1489 * assoc bit quickly enough before it sends the first frame
1491 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1492 ieee80211_is_data_present(hdr->frame_control)) {
1493 unsigned int hdrlen;
1496 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1498 if (rx->skb->len < hdrlen + 8)
1499 return RX_DROP_MONITOR;
1501 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1502 if (ethertype == rx->sdata->control_port_protocol)
1506 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1507 cfg80211_rx_spurious_frame(rx->sdata->dev,
1510 return RX_DROP_UNUSABLE;
1512 return RX_DROP_MONITOR;
1519 static ieee80211_rx_result debug_noinline
1520 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1522 struct ieee80211_local *local;
1523 struct ieee80211_hdr *hdr;
1524 struct sk_buff *skb;
1528 hdr = (struct ieee80211_hdr *) skb->data;
1530 if (!local->pspolling)
1533 if (!ieee80211_has_fromds(hdr->frame_control))
1534 /* this is not from AP */
1537 if (!ieee80211_is_data(hdr->frame_control))
1540 if (!ieee80211_has_moredata(hdr->frame_control)) {
1541 /* AP has no more frames buffered for us */
1542 local->pspolling = false;
1546 /* more data bit is set, let's request a new frame from the AP */
1547 ieee80211_send_pspoll(local, rx->sdata);
1552 static void sta_ps_start(struct sta_info *sta)
1554 struct ieee80211_sub_if_data *sdata = sta->sdata;
1555 struct ieee80211_local *local = sdata->local;
1559 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1560 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1561 ps = &sdata->bss->ps;
1565 atomic_inc(&ps->num_sta_ps);
1566 set_sta_flag(sta, WLAN_STA_PS_STA);
1567 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1568 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1569 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1570 sta->sta.addr, sta->sta.aid);
1572 ieee80211_clear_fast_xmit(sta);
1574 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1575 struct ieee80211_txq *txq = sta->sta.txq[tid];
1576 struct txq_info *txqi = to_txq_info(txq);
1578 spin_lock(&local->active_txq_lock[txq->ac]);
1579 if (!list_empty(&txqi->schedule_order))
1580 list_del_init(&txqi->schedule_order);
1581 spin_unlock(&local->active_txq_lock[txq->ac]);
1583 if (txq_has_queue(txq))
1584 set_bit(tid, &sta->txq_buffered_tids);
1586 clear_bit(tid, &sta->txq_buffered_tids);
1590 static void sta_ps_end(struct sta_info *sta)
1592 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1593 sta->sta.addr, sta->sta.aid);
1595 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1597 * Clear the flag only if the other one is still set
1598 * so that the TX path won't start TX'ing new frames
1599 * directly ... In the case that the driver flag isn't
1600 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1602 clear_sta_flag(sta, WLAN_STA_PS_STA);
1603 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1604 sta->sta.addr, sta->sta.aid);
1608 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1609 clear_sta_flag(sta, WLAN_STA_PS_STA);
1610 ieee80211_sta_ps_deliver_wakeup(sta);
1613 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1615 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1618 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1620 /* Don't let the same PS state be set twice */
1621 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1622 if ((start && in_ps) || (!start && !in_ps))
1632 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1634 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1636 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1638 if (test_sta_flag(sta, WLAN_STA_SP))
1641 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1642 ieee80211_sta_ps_deliver_poll_response(sta);
1644 set_sta_flag(sta, WLAN_STA_PSPOLL);
1646 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1648 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1650 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1651 int ac = ieee80211_ac_from_tid(tid);
1654 * If this AC is not trigger-enabled do nothing unless the
1655 * driver is calling us after it already checked.
1657 * NB: This could/should check a separate bitmap of trigger-
1658 * enabled queues, but for now we only implement uAPSD w/o
1659 * TSPEC changes to the ACs, so they're always the same.
1661 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1662 tid != IEEE80211_NUM_TIDS)
1665 /* if we are in a service period, do nothing */
1666 if (test_sta_flag(sta, WLAN_STA_SP))
1669 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1670 ieee80211_sta_ps_deliver_uapsd(sta);
1672 set_sta_flag(sta, WLAN_STA_UAPSD);
1674 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1676 static ieee80211_rx_result debug_noinline
1677 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1679 struct ieee80211_sub_if_data *sdata = rx->sdata;
1680 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1681 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1686 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1687 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1691 * The device handles station powersave, so don't do anything about
1692 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1693 * it to mac80211 since they're handled.)
1695 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1699 * Don't do anything if the station isn't already asleep. In
1700 * the uAPSD case, the station will probably be marked asleep,
1701 * in the PS-Poll case the station must be confused ...
1703 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1706 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1707 ieee80211_sta_pspoll(&rx->sta->sta);
1709 /* Free PS Poll skb here instead of returning RX_DROP that would
1710 * count as an dropped frame. */
1711 dev_kfree_skb(rx->skb);
1714 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1715 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1716 ieee80211_has_pm(hdr->frame_control) &&
1717 (ieee80211_is_data_qos(hdr->frame_control) ||
1718 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1719 u8 tid = ieee80211_get_tid(hdr);
1721 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1727 static ieee80211_rx_result debug_noinline
1728 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1730 struct sta_info *sta = rx->sta;
1731 struct link_sta_info *link_sta = rx->link_sta;
1732 struct sk_buff *skb = rx->skb;
1733 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1734 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1737 if (!sta || !link_sta)
1741 * Update last_rx only for IBSS packets which are for the current
1742 * BSSID and for station already AUTHORIZED to avoid keeping the
1743 * current IBSS network alive in cases where other STAs start
1744 * using different BSSID. This will also give the station another
1745 * chance to restart the authentication/authorization in case
1746 * something went wrong the first time.
1748 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1749 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1750 NL80211_IFTYPE_ADHOC);
1751 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1752 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1753 link_sta->rx_stats.last_rx = jiffies;
1754 if (ieee80211_is_data(hdr->frame_control) &&
1755 !is_multicast_ether_addr(hdr->addr1))
1756 link_sta->rx_stats.last_rate =
1757 sta_stats_encode_rate(status);
1759 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1760 link_sta->rx_stats.last_rx = jiffies;
1761 } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
1762 !is_multicast_ether_addr(hdr->addr1)) {
1764 * Mesh beacons will update last_rx when if they are found to
1765 * match the current local configuration when processed.
1767 link_sta->rx_stats.last_rx = jiffies;
1768 if (ieee80211_is_data(hdr->frame_control))
1769 link_sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1772 link_sta->rx_stats.fragments++;
1774 u64_stats_update_begin(&link_sta->rx_stats.syncp);
1775 link_sta->rx_stats.bytes += rx->skb->len;
1776 u64_stats_update_end(&link_sta->rx_stats.syncp);
1778 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1779 link_sta->rx_stats.last_signal = status->signal;
1780 ewma_signal_add(&link_sta->rx_stats_avg.signal,
1784 if (status->chains) {
1785 link_sta->rx_stats.chains = status->chains;
1786 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1787 int signal = status->chain_signal[i];
1789 if (!(status->chains & BIT(i)))
1792 link_sta->rx_stats.chain_signal_last[i] = signal;
1793 ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
1798 if (ieee80211_is_s1g_beacon(hdr->frame_control))
1802 * Change STA power saving mode only at the end of a frame
1803 * exchange sequence, and only for a data or management
1804 * frame as specified in IEEE 802.11-2016 11.2.3.2
1806 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1807 !ieee80211_has_morefrags(hdr->frame_control) &&
1808 !is_multicast_ether_addr(hdr->addr1) &&
1809 (ieee80211_is_mgmt(hdr->frame_control) ||
1810 ieee80211_is_data(hdr->frame_control)) &&
1811 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1812 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1813 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1814 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1815 if (!ieee80211_has_pm(hdr->frame_control))
1818 if (ieee80211_has_pm(hdr->frame_control))
1823 /* mesh power save support */
1824 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1825 ieee80211_mps_rx_h_sta_process(sta, hdr);
1828 * Drop (qos-)data::nullfunc frames silently, since they
1829 * are used only to control station power saving mode.
1831 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1832 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1835 * If we receive a 4-addr nullfunc frame from a STA
1836 * that was not moved to a 4-addr STA vlan yet send
1837 * the event to userspace and for older hostapd drop
1838 * the frame to the monitor interface.
1840 if (ieee80211_has_a4(hdr->frame_control) &&
1841 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1842 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1843 !rx->sdata->u.vlan.sta))) {
1844 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1845 cfg80211_rx_unexpected_4addr_frame(
1846 rx->sdata->dev, sta->sta.addr,
1848 return RX_DROP_MONITOR;
1851 * Update counter and free packet here to avoid
1852 * counting this as a dropped packed.
1854 link_sta->rx_stats.packets++;
1855 dev_kfree_skb(rx->skb);
1860 } /* ieee80211_rx_h_sta_process */
1862 static struct ieee80211_key *
1863 ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
1865 struct ieee80211_key *key = NULL;
1868 /* Make sure key gets set if either BIGTK key index is set so that
1869 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1870 * Beacon frames and Beacon frames that claim to use another BIGTK key
1871 * index (i.e., a key that we do not have).
1875 idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1878 if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1885 key = rcu_dereference(rx->link_sta->gtk[idx]);
1887 key = rcu_dereference(rx->link->gtk[idx]);
1888 if (!key && rx->link_sta)
1889 key = rcu_dereference(rx->link_sta->gtk[idx2]);
1891 key = rcu_dereference(rx->link->gtk[idx2]);
1896 static ieee80211_rx_result debug_noinline
1897 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1899 struct sk_buff *skb = rx->skb;
1900 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1901 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1903 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1904 struct ieee80211_key *sta_ptk = NULL;
1905 struct ieee80211_key *ptk_idx = NULL;
1906 int mmie_keyidx = -1;
1909 if (ieee80211_is_ext(hdr->frame_control))
1915 * There are five types of keys:
1916 * - GTK (group keys)
1917 * - IGTK (group keys for management frames)
1918 * - BIGTK (group keys for Beacon frames)
1919 * - PTK (pairwise keys)
1920 * - STK (station-to-station pairwise keys)
1922 * When selecting a key, we have to distinguish between multicast
1923 * (including broadcast) and unicast frames, the latter can only
1924 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1925 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1926 * then unicast frames can also use key indices like GTKs. Hence, if we
1927 * don't have a PTK/STK we check the key index for a WEP key.
1929 * Note that in a regular BSS, multicast frames are sent by the
1930 * AP only, associated stations unicast the frame to the AP first
1931 * which then multicasts it on their behalf.
1933 * There is also a slight problem in IBSS mode: GTKs are negotiated
1934 * with each station, that is something we don't currently handle.
1935 * The spec seems to expect that one negotiates the same key with
1936 * every station but there's no such requirement; VLANs could be
1940 /* start without a key */
1942 fc = hdr->frame_control;
1945 int keyid = rx->sta->ptk_idx;
1946 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1948 if (ieee80211_has_protected(fc) &&
1949 !(status->flag & RX_FLAG_IV_STRIPPED)) {
1950 keyid = ieee80211_get_keyid(rx->skb);
1952 if (unlikely(keyid < 0))
1953 return RX_DROP_UNUSABLE;
1955 ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1959 if (!ieee80211_has_protected(fc))
1960 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1962 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1963 rx->key = ptk_idx ? ptk_idx : sta_ptk;
1964 if ((status->flag & RX_FLAG_DECRYPTED) &&
1965 (status->flag & RX_FLAG_IV_STRIPPED))
1967 /* Skip decryption if the frame is not protected. */
1968 if (!ieee80211_has_protected(fc))
1970 } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
1971 /* Broadcast/multicast robust management frame / BIP */
1972 if ((status->flag & RX_FLAG_DECRYPTED) &&
1973 (status->flag & RX_FLAG_IV_STRIPPED))
1976 if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
1977 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
1978 NUM_DEFAULT_BEACON_KEYS) {
1980 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1983 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1986 rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
1988 return RX_CONTINUE; /* Beacon protection not in use */
1989 } else if (mmie_keyidx >= 0) {
1990 /* Broadcast/multicast robust management frame / BIP */
1991 if ((status->flag & RX_FLAG_DECRYPTED) &&
1992 (status->flag & RX_FLAG_IV_STRIPPED))
1995 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1996 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1997 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1999 if (ieee80211_is_group_privacy_action(skb) &&
2000 test_sta_flag(rx->sta, WLAN_STA_MFP))
2001 return RX_DROP_MONITOR;
2003 rx->key = rcu_dereference(rx->link_sta->gtk[mmie_keyidx]);
2006 rx->key = rcu_dereference(rx->link->gtk[mmie_keyidx]);
2007 } else if (!ieee80211_has_protected(fc)) {
2009 * The frame was not protected, so skip decryption. However, we
2010 * need to set rx->key if there is a key that could have been
2011 * used so that the frame may be dropped if encryption would
2012 * have been expected.
2014 struct ieee80211_key *key = NULL;
2017 if (ieee80211_is_beacon(fc)) {
2018 key = ieee80211_rx_get_bigtk(rx, -1);
2019 } else if (ieee80211_is_mgmt(fc) &&
2020 is_multicast_ether_addr(hdr->addr1)) {
2021 key = rcu_dereference(rx->link->default_mgmt_key);
2024 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2025 key = rcu_dereference(rx->link_sta->gtk[i]);
2031 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2032 key = rcu_dereference(rx->link->gtk[i]);
2043 * The device doesn't give us the IV so we won't be
2044 * able to look up the key. That's ok though, we
2045 * don't need to decrypt the frame, we just won't
2046 * be able to keep statistics accurate.
2047 * Except for key threshold notifications, should
2048 * we somehow allow the driver to tell us which key
2049 * the hardware used if this flag is set?
2051 if ((status->flag & RX_FLAG_DECRYPTED) &&
2052 (status->flag & RX_FLAG_IV_STRIPPED))
2055 keyidx = ieee80211_get_keyid(rx->skb);
2057 if (unlikely(keyidx < 0))
2058 return RX_DROP_UNUSABLE;
2060 /* check per-station GTK first, if multicast packet */
2061 if (is_multicast_ether_addr(hdr->addr1) && rx->link_sta)
2062 rx->key = rcu_dereference(rx->link_sta->gtk[keyidx]);
2064 /* if not found, try default key */
2066 if (is_multicast_ether_addr(hdr->addr1))
2067 rx->key = rcu_dereference(rx->link->gtk[keyidx]);
2069 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
2072 * RSNA-protected unicast frames should always be
2073 * sent with pairwise or station-to-station keys,
2074 * but for WEP we allow using a key index as well.
2077 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2078 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2079 !is_multicast_ether_addr(hdr->addr1))
2085 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2086 return RX_DROP_MONITOR;
2088 /* TODO: add threshold stuff again */
2090 return RX_DROP_MONITOR;
2093 switch (rx->key->conf.cipher) {
2094 case WLAN_CIPHER_SUITE_WEP40:
2095 case WLAN_CIPHER_SUITE_WEP104:
2096 result = ieee80211_crypto_wep_decrypt(rx);
2098 case WLAN_CIPHER_SUITE_TKIP:
2099 result = ieee80211_crypto_tkip_decrypt(rx);
2101 case WLAN_CIPHER_SUITE_CCMP:
2102 result = ieee80211_crypto_ccmp_decrypt(
2103 rx, IEEE80211_CCMP_MIC_LEN);
2105 case WLAN_CIPHER_SUITE_CCMP_256:
2106 result = ieee80211_crypto_ccmp_decrypt(
2107 rx, IEEE80211_CCMP_256_MIC_LEN);
2109 case WLAN_CIPHER_SUITE_AES_CMAC:
2110 result = ieee80211_crypto_aes_cmac_decrypt(rx);
2112 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2113 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2115 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2116 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2117 result = ieee80211_crypto_aes_gmac_decrypt(rx);
2119 case WLAN_CIPHER_SUITE_GCMP:
2120 case WLAN_CIPHER_SUITE_GCMP_256:
2121 result = ieee80211_crypto_gcmp_decrypt(rx);
2124 result = RX_DROP_UNUSABLE;
2127 /* the hdr variable is invalid after the decrypt handlers */
2129 /* either the frame has been decrypted or will be dropped */
2130 status->flag |= RX_FLAG_DECRYPTED;
2132 if (unlikely(ieee80211_is_beacon(fc) && result == RX_DROP_UNUSABLE &&
2134 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2135 skb->data, skb->len);
2140 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2144 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2145 skb_queue_head_init(&cache->entries[i].skb_list);
2148 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2152 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2153 __skb_queue_purge(&cache->entries[i].skb_list);
2156 static inline struct ieee80211_fragment_entry *
2157 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2158 unsigned int frag, unsigned int seq, int rx_queue,
2159 struct sk_buff **skb)
2161 struct ieee80211_fragment_entry *entry;
2163 entry = &cache->entries[cache->next++];
2164 if (cache->next >= IEEE80211_FRAGMENT_MAX)
2167 __skb_queue_purge(&entry->skb_list);
2169 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2171 entry->first_frag_time = jiffies;
2173 entry->rx_queue = rx_queue;
2174 entry->last_frag = frag;
2175 entry->check_sequential_pn = false;
2176 entry->extra_len = 0;
2181 static inline struct ieee80211_fragment_entry *
2182 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2183 unsigned int frag, unsigned int seq,
2184 int rx_queue, struct ieee80211_hdr *hdr)
2186 struct ieee80211_fragment_entry *entry;
2190 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2191 struct ieee80211_hdr *f_hdr;
2192 struct sk_buff *f_skb;
2196 idx = IEEE80211_FRAGMENT_MAX - 1;
2198 entry = &cache->entries[idx];
2199 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2200 entry->rx_queue != rx_queue ||
2201 entry->last_frag + 1 != frag)
2204 f_skb = __skb_peek(&entry->skb_list);
2205 f_hdr = (struct ieee80211_hdr *) f_skb->data;
2208 * Check ftype and addresses are equal, else check next fragment
2210 if (((hdr->frame_control ^ f_hdr->frame_control) &
2211 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2212 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2213 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2216 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2217 __skb_queue_purge(&entry->skb_list);
2226 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2229 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2230 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2231 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2232 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2233 ieee80211_has_protected(fc);
2236 static ieee80211_rx_result debug_noinline
2237 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2239 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2240 struct ieee80211_hdr *hdr;
2243 unsigned int frag, seq;
2244 struct ieee80211_fragment_entry *entry;
2245 struct sk_buff *skb;
2246 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2248 hdr = (struct ieee80211_hdr *)rx->skb->data;
2249 fc = hdr->frame_control;
2251 if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
2254 sc = le16_to_cpu(hdr->seq_ctrl);
2255 frag = sc & IEEE80211_SCTL_FRAG;
2258 cache = &rx->sta->frags;
2260 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2263 if (is_multicast_ether_addr(hdr->addr1))
2264 return RX_DROP_MONITOR;
2266 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2268 if (skb_linearize(rx->skb))
2269 return RX_DROP_UNUSABLE;
2272 * skb_linearize() might change the skb->data and
2273 * previously cached variables (in this case, hdr) need to
2274 * be refreshed with the new data.
2276 hdr = (struct ieee80211_hdr *)rx->skb->data;
2277 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2280 /* This is the first fragment of a new frame. */
2281 entry = ieee80211_reassemble_add(cache, frag, seq,
2282 rx->seqno_idx, &(rx->skb));
2283 if (requires_sequential_pn(rx, fc)) {
2284 int queue = rx->security_idx;
2286 /* Store CCMP/GCMP PN so that we can verify that the
2287 * next fragment has a sequential PN value.
2289 entry->check_sequential_pn = true;
2290 entry->is_protected = true;
2291 entry->key_color = rx->key->color;
2292 memcpy(entry->last_pn,
2293 rx->key->u.ccmp.rx_pn[queue],
2294 IEEE80211_CCMP_PN_LEN);
2295 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2297 offsetof(struct ieee80211_key,
2299 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2300 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2301 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2302 IEEE80211_GCMP_PN_LEN);
2303 } else if (rx->key &&
2304 (ieee80211_has_protected(fc) ||
2305 (status->flag & RX_FLAG_DECRYPTED))) {
2306 entry->is_protected = true;
2307 entry->key_color = rx->key->color;
2312 /* This is a fragment for a frame that should already be pending in
2313 * fragment cache. Add this fragment to the end of the pending entry.
2315 entry = ieee80211_reassemble_find(cache, frag, seq,
2316 rx->seqno_idx, hdr);
2318 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2319 return RX_DROP_MONITOR;
2322 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2323 * MPDU PN values are not incrementing in steps of 1."
2324 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2325 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2327 if (entry->check_sequential_pn) {
2329 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2331 if (!requires_sequential_pn(rx, fc))
2332 return RX_DROP_UNUSABLE;
2334 /* Prevent mixed key and fragment cache attacks */
2335 if (entry->key_color != rx->key->color)
2336 return RX_DROP_UNUSABLE;
2338 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2339 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2345 rpn = rx->ccm_gcm.pn;
2346 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2347 return RX_DROP_UNUSABLE;
2348 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2349 } else if (entry->is_protected &&
2351 (!ieee80211_has_protected(fc) &&
2352 !(status->flag & RX_FLAG_DECRYPTED)) ||
2353 rx->key->color != entry->key_color)) {
2354 /* Drop this as a mixed key or fragment cache attack, even
2355 * if for TKIP Michael MIC should protect us, and WEP is a
2356 * lost cause anyway.
2358 return RX_DROP_UNUSABLE;
2359 } else if (entry->is_protected && rx->key &&
2360 entry->key_color != rx->key->color &&
2361 (status->flag & RX_FLAG_DECRYPTED)) {
2362 return RX_DROP_UNUSABLE;
2365 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2366 __skb_queue_tail(&entry->skb_list, rx->skb);
2367 entry->last_frag = frag;
2368 entry->extra_len += rx->skb->len;
2369 if (ieee80211_has_morefrags(fc)) {
2374 rx->skb = __skb_dequeue(&entry->skb_list);
2375 if (skb_tailroom(rx->skb) < entry->extra_len) {
2376 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2377 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2379 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2380 __skb_queue_purge(&entry->skb_list);
2381 return RX_DROP_UNUSABLE;
2384 while ((skb = __skb_dequeue(&entry->skb_list))) {
2385 skb_put_data(rx->skb, skb->data, skb->len);
2390 ieee80211_led_rx(rx->local);
2392 rx->link_sta->rx_stats.packets++;
2396 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2398 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2404 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2406 struct sk_buff *skb = rx->skb;
2407 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2410 * Pass through unencrypted frames if the hardware has
2411 * decrypted them already.
2413 if (status->flag & RX_FLAG_DECRYPTED)
2416 /* Drop unencrypted frames if key is set. */
2417 if (unlikely(!ieee80211_has_protected(fc) &&
2418 !ieee80211_is_any_nullfunc(fc) &&
2419 ieee80211_is_data(fc) && rx->key))
2425 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2427 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2428 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2429 __le16 fc = hdr->frame_control;
2432 * Pass through unencrypted frames if the hardware has
2433 * decrypted them already.
2435 if (status->flag & RX_FLAG_DECRYPTED)
2438 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2439 if (unlikely(!ieee80211_has_protected(fc) &&
2440 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2442 if (ieee80211_is_deauth(fc) ||
2443 ieee80211_is_disassoc(fc))
2444 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2449 /* BIP does not use Protected field, so need to check MMIE */
2450 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2451 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2452 if (ieee80211_is_deauth(fc) ||
2453 ieee80211_is_disassoc(fc))
2454 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2459 if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
2460 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2461 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2467 * When using MFP, Action frames are not allowed prior to
2468 * having configured keys.
2470 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2471 ieee80211_is_robust_mgmt_frame(rx->skb)))
2479 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2481 struct ieee80211_sub_if_data *sdata = rx->sdata;
2482 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2483 bool check_port_control = false;
2484 struct ethhdr *ehdr;
2487 *port_control = false;
2488 if (ieee80211_has_a4(hdr->frame_control) &&
2489 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2492 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2493 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2495 if (!sdata->u.mgd.use_4addr)
2497 else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2498 check_port_control = true;
2501 if (is_multicast_ether_addr(hdr->addr1) &&
2502 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2505 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2509 ehdr = (struct ethhdr *) rx->skb->data;
2510 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2511 *port_control = true;
2512 else if (check_port_control)
2518 bool ieee80211_is_our_addr(struct ieee80211_sub_if_data *sdata,
2519 const u8 *addr, int *out_link_id)
2521 unsigned int link_id;
2523 /* non-MLO, or MLD address replaced by hardware */
2524 if (ether_addr_equal(sdata->vif.addr, addr))
2527 if (!sdata->vif.valid_links)
2530 for (link_id = 0; link_id < ARRAY_SIZE(sdata->vif.link_conf); link_id++) {
2531 struct ieee80211_bss_conf *conf;
2533 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2537 if (ether_addr_equal(conf->addr, addr)) {
2539 *out_link_id = link_id;
2548 * requires that rx->skb is a frame with ethernet header
2550 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2552 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2553 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2554 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2557 * Allow EAPOL frames to us/the PAE group address regardless of
2558 * whether the frame was encrypted or not, and always disallow
2559 * all other destination addresses for them.
2561 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2562 return ieee80211_is_our_addr(rx->sdata, ehdr->h_dest, NULL) ||
2563 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2565 if (ieee80211_802_1x_port_control(rx) ||
2566 ieee80211_drop_unencrypted(rx, fc))
2572 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2573 struct ieee80211_rx_data *rx)
2575 struct ieee80211_sub_if_data *sdata = rx->sdata;
2576 struct net_device *dev = sdata->dev;
2578 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2579 (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
2580 !sdata->control_port_no_preauth)) &&
2581 sdata->control_port_over_nl80211)) {
2582 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2583 bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2585 cfg80211_rx_control_port(dev, skb, noencrypt);
2588 struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2590 memset(skb->cb, 0, sizeof(skb->cb));
2593 * 802.1X over 802.11 requires that the authenticator address
2594 * be used for EAPOL frames. However, 802.1X allows the use of
2595 * the PAE group address instead. If the interface is part of
2596 * a bridge and we pass the frame with the PAE group address,
2597 * then the bridge will forward it to the network (even if the
2598 * client was not associated yet), which isn't supposed to
2600 * To avoid that, rewrite the destination address to our own
2601 * address, so that the authenticator (e.g. hostapd) will see
2602 * the frame, but bridge won't forward it anywhere else. Note
2603 * that due to earlier filtering, the only other address can
2604 * be the PAE group address, unless the hardware allowed them
2605 * through in 802.3 offloaded mode.
2607 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2608 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2609 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2611 /* deliver to local stack */
2613 list_add_tail(&skb->list, rx->list);
2615 netif_receive_skb(skb);
2620 * requires that rx->skb is a frame with ethernet header
2623 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2625 struct ieee80211_sub_if_data *sdata = rx->sdata;
2626 struct net_device *dev = sdata->dev;
2627 struct sk_buff *skb, *xmit_skb;
2628 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2629 struct sta_info *dsta;
2634 dev_sw_netstats_rx_add(dev, skb->len);
2637 /* The seqno index has the same property as needed
2638 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2639 * for non-QoS-data frames. Here we know it's a data
2640 * frame, so count MSDUs.
2642 u64_stats_update_begin(&rx->link_sta->rx_stats.syncp);
2643 rx->link_sta->rx_stats.msdu[rx->seqno_idx]++;
2644 u64_stats_update_end(&rx->link_sta->rx_stats.syncp);
2647 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2648 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2649 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2650 ehdr->h_proto != rx->sdata->control_port_protocol &&
2651 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2652 if (is_multicast_ether_addr(ehdr->h_dest) &&
2653 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2655 * send multicast frames both to higher layers in
2656 * local net stack and back to the wireless medium
2658 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2660 net_info_ratelimited("%s: failed to clone multicast frame\n",
2662 } else if (!is_multicast_ether_addr(ehdr->h_dest) &&
2663 !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
2664 dsta = sta_info_get(sdata, ehdr->h_dest);
2667 * The destination station is associated to
2668 * this AP (in this VLAN), so send the frame
2669 * directly to it and do not pass it to local
2678 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2680 /* 'align' will only take the values 0 or 2 here since all
2681 * frames are required to be aligned to 2-byte boundaries
2682 * when being passed to mac80211; the code here works just
2683 * as well if that isn't true, but mac80211 assumes it can
2684 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2688 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2690 if (WARN_ON(skb_headroom(skb) < 3)) {
2694 u8 *data = skb->data;
2695 size_t len = skb_headlen(skb);
2697 memmove(skb->data, data, len);
2698 skb_set_tail_pointer(skb, len);
2705 skb->protocol = eth_type_trans(skb, dev);
2706 ieee80211_deliver_skb_to_local_stack(skb, rx);
2711 * Send to wireless media and increase priority by 256 to
2712 * keep the received priority instead of reclassifying
2713 * the frame (see cfg80211_classify8021d).
2715 xmit_skb->priority += 256;
2716 xmit_skb->protocol = htons(ETH_P_802_3);
2717 skb_reset_network_header(xmit_skb);
2718 skb_reset_mac_header(xmit_skb);
2719 dev_queue_xmit(xmit_skb);
2723 static ieee80211_rx_result
2724 ieee80211_rx_mesh_data(struct ieee80211_sub_if_data *sdata, struct sta_info *sta,
2725 struct sk_buff *skb)
2727 #ifdef CONFIG_MAC80211_MESH
2728 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2729 struct ieee80211_local *local = sdata->local;
2730 uint16_t fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA;
2731 struct ieee80211_hdr hdr = {
2732 .frame_control = cpu_to_le16(fc)
2734 struct ieee80211_hdr *fwd_hdr;
2735 struct ieee80211s_hdr *mesh_hdr;
2736 struct ieee80211_tx_info *info;
2737 struct sk_buff *fwd_skb;
2741 int hdrlen, mesh_hdrlen;
2744 if (!ieee80211_vif_is_mesh(&sdata->vif))
2747 if (!pskb_may_pull(skb, sizeof(*eth) + 6))
2748 return RX_DROP_MONITOR;
2750 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(*eth));
2751 mesh_hdrlen = ieee80211_get_mesh_hdrlen(mesh_hdr);
2753 if (!pskb_may_pull(skb, sizeof(*eth) + mesh_hdrlen))
2754 return RX_DROP_MONITOR;
2756 eth = (struct ethhdr *)skb->data;
2757 multicast = is_multicast_ether_addr(eth->h_dest);
2759 mesh_hdr = (struct ieee80211s_hdr *)(eth + 1);
2761 return RX_DROP_MONITOR;
2763 /* frame is in RMC, don't forward */
2764 if (is_multicast_ether_addr(eth->h_dest) &&
2765 mesh_rmc_check(sdata, eth->h_source, mesh_hdr))
2766 return RX_DROP_MONITOR;
2768 /* forward packet */
2769 if (sdata->crypto_tx_tailroom_needed_cnt)
2770 tailroom = IEEE80211_ENCRYPT_TAILROOM;
2772 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2773 struct mesh_path *mppath;
2777 proxied_addr = mesh_hdr->eaddr1;
2778 else if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
2779 /* has_a4 already checked in ieee80211_rx_mesh_check */
2780 proxied_addr = mesh_hdr->eaddr2;
2782 return RX_DROP_MONITOR;
2785 mppath = mpp_path_lookup(sdata, proxied_addr);
2787 mpp_path_add(sdata, proxied_addr, eth->h_source);
2789 spin_lock_bh(&mppath->state_lock);
2790 if (!ether_addr_equal(mppath->mpp, eth->h_source))
2791 memcpy(mppath->mpp, eth->h_source, ETH_ALEN);
2792 mppath->exp_time = jiffies;
2793 spin_unlock_bh(&mppath->state_lock);
2798 /* Frame has reached destination. Don't forward */
2799 if (ether_addr_equal(sdata->vif.addr, eth->h_dest))
2802 if (!--mesh_hdr->ttl) {
2806 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
2807 return RX_DROP_MONITOR;
2810 if (!ifmsh->mshcfg.dot11MeshForwarding) {
2811 if (is_multicast_ether_addr(eth->h_dest))
2814 return RX_DROP_MONITOR;
2817 skb_set_queue_mapping(skb, ieee802_1d_to_ac[skb->priority]);
2819 ieee80211_fill_mesh_addresses(&hdr, &hdr.frame_control,
2820 eth->h_dest, eth->h_source);
2821 hdrlen = ieee80211_hdrlen(hdr.frame_control);
2823 int extra_head = sizeof(struct ieee80211_hdr) - sizeof(*eth);
2825 fwd_skb = skb_copy_expand(skb, local->tx_headroom + extra_head +
2826 IEEE80211_ENCRYPT_HEADROOM,
2827 tailroom, GFP_ATOMIC);
2834 if (skb_cow_head(fwd_skb, hdrlen - sizeof(struct ethhdr)))
2835 return RX_DROP_UNUSABLE;
2837 if (skb_linearize(fwd_skb))
2838 return RX_DROP_UNUSABLE;
2841 fwd_hdr = skb_push(fwd_skb, hdrlen - sizeof(struct ethhdr));
2842 memcpy(fwd_hdr, &hdr, hdrlen - 2);
2843 qos = ieee80211_get_qos_ctl(fwd_hdr);
2844 qos[0] = qos[1] = 0;
2846 skb_reset_mac_header(fwd_skb);
2847 hdrlen += mesh_hdrlen;
2848 if (ieee80211_get_8023_tunnel_proto(fwd_skb->data + hdrlen,
2849 &fwd_skb->protocol))
2852 fwd_skb->protocol = htons(fwd_skb->len - hdrlen);
2853 skb_set_network_header(fwd_skb, hdrlen + 2);
2855 info = IEEE80211_SKB_CB(fwd_skb);
2856 memset(info, 0, sizeof(*info));
2857 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
2858 info->control.vif = &sdata->vif;
2859 info->control.jiffies = jiffies;
2861 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2862 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2863 /* update power mode indication when forwarding */
2864 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2865 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2866 /* mesh power mode flags updated in mesh_nexthop_lookup */
2867 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2869 /* unable to resolve next hop */
2871 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2873 WLAN_REASON_MESH_PATH_NOFORWARD,
2875 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2880 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2881 fwd_skb->dev = sdata->dev;
2882 ieee80211_add_pending_skb(local, fwd_skb);
2888 ieee80211_strip_8023_mesh_hdr(skb);
2894 static ieee80211_rx_result debug_noinline
2895 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2897 struct net_device *dev = rx->sdata->dev;
2898 struct sk_buff *skb = rx->skb;
2899 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2900 __le16 fc = hdr->frame_control;
2901 struct sk_buff_head frame_list;
2902 ieee80211_rx_result res;
2903 struct ethhdr ethhdr;
2904 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2906 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2909 } else switch (rx->sdata->vif.type) {
2910 case NL80211_IFTYPE_AP:
2911 case NL80211_IFTYPE_AP_VLAN:
2914 case NL80211_IFTYPE_STATION:
2916 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2919 case NL80211_IFTYPE_MESH_POINT:
2928 __skb_queue_head_init(&frame_list);
2930 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2931 rx->sdata->vif.addr,
2932 rx->sdata->vif.type,
2934 return RX_DROP_UNUSABLE;
2936 if (rx->sta->amsdu_mesh_control < 0) {
2937 bool valid_std = ieee80211_is_valid_amsdu(skb, true);
2938 bool valid_nonstd = ieee80211_is_valid_amsdu(skb, false);
2940 if (valid_std && !valid_nonstd)
2941 rx->sta->amsdu_mesh_control = 1;
2942 else if (valid_nonstd && !valid_std)
2943 rx->sta->amsdu_mesh_control = 0;
2946 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2947 rx->sdata->vif.type,
2948 rx->local->hw.extra_tx_headroom,
2950 rx->sta->amsdu_mesh_control);
2952 while (!skb_queue_empty(&frame_list)) {
2953 rx->skb = __skb_dequeue(&frame_list);
2955 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
2965 if (!ieee80211_frame_allowed(rx, fc))
2968 ieee80211_deliver_skb(rx);
2972 dev_kfree_skb(rx->skb);
2978 static ieee80211_rx_result debug_noinline
2979 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2981 struct sk_buff *skb = rx->skb;
2982 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2983 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2984 __le16 fc = hdr->frame_control;
2986 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2989 if (unlikely(!ieee80211_is_data(fc)))
2992 if (unlikely(!ieee80211_is_data_present(fc)))
2993 return RX_DROP_MONITOR;
2995 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2996 switch (rx->sdata->vif.type) {
2997 case NL80211_IFTYPE_AP_VLAN:
2998 if (!rx->sdata->u.vlan.sta)
2999 return RX_DROP_UNUSABLE;
3001 case NL80211_IFTYPE_STATION:
3002 if (!rx->sdata->u.mgd.use_4addr)
3003 return RX_DROP_UNUSABLE;
3005 case NL80211_IFTYPE_MESH_POINT:
3008 return RX_DROP_UNUSABLE;
3012 if (is_multicast_ether_addr(hdr->addr1) || !rx->sta)
3013 return RX_DROP_UNUSABLE;
3017 * We should not receive A-MSDUs on pre-HT connections,
3018 * and HT connections cannot use old ciphers. Thus drop
3019 * them, as in those cases we couldn't even have SPP
3022 switch (rx->key->conf.cipher) {
3023 case WLAN_CIPHER_SUITE_WEP40:
3024 case WLAN_CIPHER_SUITE_WEP104:
3025 case WLAN_CIPHER_SUITE_TKIP:
3026 return RX_DROP_UNUSABLE;
3032 return __ieee80211_rx_h_amsdu(rx, 0);
3035 static ieee80211_rx_result debug_noinline
3036 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
3038 struct ieee80211_sub_if_data *sdata = rx->sdata;
3039 struct ieee80211_local *local = rx->local;
3040 struct net_device *dev = sdata->dev;
3041 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
3042 __le16 fc = hdr->frame_control;
3043 ieee80211_rx_result res;
3047 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
3050 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
3051 return RX_DROP_MONITOR;
3054 * Send unexpected-4addr-frame event to hostapd. For older versions,
3055 * also drop the frame to cooked monitor interfaces.
3057 if (ieee80211_has_a4(hdr->frame_control) &&
3058 sdata->vif.type == NL80211_IFTYPE_AP) {
3060 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
3061 cfg80211_rx_unexpected_4addr_frame(
3062 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
3063 return RX_DROP_MONITOR;
3066 err = __ieee80211_data_to_8023(rx, &port_control);
3068 return RX_DROP_UNUSABLE;
3070 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
3071 if (res != RX_CONTINUE)
3074 if (!ieee80211_frame_allowed(rx, fc))
3075 return RX_DROP_MONITOR;
3077 /* directly handle TDLS channel switch requests/responses */
3078 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
3079 cpu_to_be16(ETH_P_TDLS))) {
3080 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
3082 if (pskb_may_pull(rx->skb,
3083 offsetof(struct ieee80211_tdls_data, u)) &&
3084 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
3085 tf->category == WLAN_CATEGORY_TDLS &&
3086 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
3087 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
3088 rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
3089 __ieee80211_queue_skb_to_iface(sdata, rx->link_id,
3095 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3096 unlikely(port_control) && sdata->bss) {
3097 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
3105 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3106 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
3107 !is_multicast_ether_addr(
3108 ((struct ethhdr *)rx->skb->data)->h_dest) &&
3109 (!local->scanning &&
3110 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
3111 mod_timer(&local->dynamic_ps_timer, jiffies +
3112 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
3114 ieee80211_deliver_skb(rx);
3119 static ieee80211_rx_result debug_noinline
3120 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
3122 struct sk_buff *skb = rx->skb;
3123 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
3124 struct tid_ampdu_rx *tid_agg_rx;
3128 if (likely(!ieee80211_is_ctl(bar->frame_control)))
3131 if (ieee80211_is_back_req(bar->frame_control)) {
3133 __le16 control, start_seq_num;
3134 } __packed bar_data;
3135 struct ieee80211_event event = {
3136 .type = BAR_RX_EVENT,
3140 return RX_DROP_MONITOR;
3142 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
3143 &bar_data, sizeof(bar_data)))
3144 return RX_DROP_MONITOR;
3146 tid = le16_to_cpu(bar_data.control) >> 12;
3148 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
3149 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
3150 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
3151 WLAN_BACK_RECIPIENT,
3152 WLAN_REASON_QSTA_REQUIRE_SETUP);
3154 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
3156 return RX_DROP_MONITOR;
3158 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
3159 event.u.ba.tid = tid;
3160 event.u.ba.ssn = start_seq_num;
3161 event.u.ba.sta = &rx->sta->sta;
3163 /* reset session timer */
3164 if (tid_agg_rx->timeout)
3165 mod_timer(&tid_agg_rx->session_timer,
3166 TU_TO_EXP_TIME(tid_agg_rx->timeout));
3168 spin_lock(&tid_agg_rx->reorder_lock);
3169 /* release stored frames up to start of BAR */
3170 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
3171 start_seq_num, frames);
3172 spin_unlock(&tid_agg_rx->reorder_lock);
3174 drv_event_callback(rx->local, rx->sdata, &event);
3181 * After this point, we only want management frames,
3182 * so we can drop all remaining control frames to
3183 * cooked monitor interfaces.
3185 return RX_DROP_MONITOR;
3188 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
3189 struct ieee80211_mgmt *mgmt,
3192 struct ieee80211_local *local = sdata->local;
3193 struct sk_buff *skb;
3194 struct ieee80211_mgmt *resp;
3196 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
3197 /* Not to own unicast address */
3201 if (!ether_addr_equal(mgmt->sa, sdata->deflink.u.mgd.bssid) ||
3202 !ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid)) {
3203 /* Not from the current AP or not associated yet. */
3207 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3208 /* Too short SA Query request frame */
3212 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3216 skb_reserve(skb, local->hw.extra_tx_headroom);
3217 resp = skb_put_zero(skb, 24);
3218 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3219 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3220 memcpy(resp->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3221 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3222 IEEE80211_STYPE_ACTION);
3223 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3224 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3225 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3226 memcpy(resp->u.action.u.sa_query.trans_id,
3227 mgmt->u.action.u.sa_query.trans_id,
3228 WLAN_SA_QUERY_TR_ID_LEN);
3230 ieee80211_tx_skb(sdata, skb);
3234 ieee80211_rx_check_bss_color_collision(struct ieee80211_rx_data *rx)
3236 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3237 const struct element *ie;
3240 if (!wiphy_ext_feature_isset(rx->local->hw.wiphy,
3241 NL80211_EXT_FEATURE_BSS_COLOR))
3244 if (ieee80211_hw_check(&rx->local->hw, DETECTS_COLOR_COLLISION))
3247 if (rx->sdata->vif.bss_conf.csa_active)
3250 baselen = mgmt->u.beacon.variable - rx->skb->data;
3251 if (baselen > rx->skb->len)
3254 ie = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION,
3255 mgmt->u.beacon.variable,
3256 rx->skb->len - baselen);
3257 if (ie && ie->datalen >= sizeof(struct ieee80211_he_operation) &&
3258 ie->datalen >= ieee80211_he_oper_size(ie->data + 1)) {
3259 struct ieee80211_bss_conf *bss_conf = &rx->sdata->vif.bss_conf;
3260 const struct ieee80211_he_operation *he_oper;
3263 he_oper = (void *)(ie->data + 1);
3264 if (le32_get_bits(he_oper->he_oper_params,
3265 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED))
3268 color = le32_get_bits(he_oper->he_oper_params,
3269 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3270 if (color == bss_conf->he_bss_color.color)
3271 ieee80211_obss_color_collision_notify(&rx->sdata->vif,
3277 static ieee80211_rx_result debug_noinline
3278 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3280 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3281 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3283 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
3287 * From here on, look only at management frames.
3288 * Data and control frames are already handled,
3289 * and unknown (reserved) frames are useless.
3291 if (rx->skb->len < 24)
3292 return RX_DROP_MONITOR;
3294 if (!ieee80211_is_mgmt(mgmt->frame_control))
3295 return RX_DROP_MONITOR;
3297 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3298 ieee80211_is_beacon(mgmt->frame_control) &&
3299 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3302 /* sw bss color collision detection */
3303 ieee80211_rx_check_bss_color_collision(rx);
3305 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3306 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3307 sig = status->signal;
3309 cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3310 rx->skb->data, rx->skb->len,
3311 ieee80211_rx_status_to_khz(status),
3313 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3316 if (ieee80211_drop_unencrypted_mgmt(rx))
3317 return RX_DROP_UNUSABLE;
3323 ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
3325 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
3326 struct ieee80211_sub_if_data *sdata = rx->sdata;
3328 /* TWT actions are only supported in AP for the moment */
3329 if (sdata->vif.type != NL80211_IFTYPE_AP)
3332 if (!rx->local->ops->add_twt_setup)
3335 if (!sdata->vif.bss_conf.twt_responder)
3341 switch (mgmt->u.action.u.s1g.action_code) {
3342 case WLAN_S1G_TWT_SETUP: {
3343 struct ieee80211_twt_setup *twt;
3345 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3346 1 + /* action code */
3347 sizeof(struct ieee80211_twt_setup) +
3348 2 /* TWT req_type agrt */)
3351 twt = (void *)mgmt->u.action.u.s1g.variable;
3352 if (twt->element_id != WLAN_EID_S1G_TWT)
3355 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3356 4 + /* action code + token + tlv */
3360 return true; /* queue the frame */
3362 case WLAN_S1G_TWT_TEARDOWN:
3363 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
3366 return true; /* queue the frame */
3374 static ieee80211_rx_result debug_noinline
3375 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3377 struct ieee80211_local *local = rx->local;
3378 struct ieee80211_sub_if_data *sdata = rx->sdata;
3379 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3380 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3381 int len = rx->skb->len;
3383 if (!ieee80211_is_action(mgmt->frame_control))
3386 /* drop too small frames */
3387 if (len < IEEE80211_MIN_ACTION_SIZE)
3388 return RX_DROP_UNUSABLE;
3390 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3391 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3392 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3393 return RX_DROP_UNUSABLE;
3395 switch (mgmt->u.action.category) {
3396 case WLAN_CATEGORY_HT:
3397 /* reject HT action frames from stations not supporting HT */
3398 if (!rx->link_sta->pub->ht_cap.ht_supported)
3401 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3402 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3403 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3404 sdata->vif.type != NL80211_IFTYPE_AP &&
3405 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3408 /* verify action & smps_control/chanwidth are present */
3409 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3412 switch (mgmt->u.action.u.ht_smps.action) {
3413 case WLAN_HT_ACTION_SMPS: {
3414 struct ieee80211_supported_band *sband;
3415 enum ieee80211_smps_mode smps_mode;
3416 struct sta_opmode_info sta_opmode = {};
3418 if (sdata->vif.type != NL80211_IFTYPE_AP &&
3419 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3422 /* convert to HT capability */
3423 switch (mgmt->u.action.u.ht_smps.smps_control) {
3424 case WLAN_HT_SMPS_CONTROL_DISABLED:
3425 smps_mode = IEEE80211_SMPS_OFF;
3427 case WLAN_HT_SMPS_CONTROL_STATIC:
3428 smps_mode = IEEE80211_SMPS_STATIC;
3430 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3431 smps_mode = IEEE80211_SMPS_DYNAMIC;
3437 /* if no change do nothing */
3438 if (rx->link_sta->pub->smps_mode == smps_mode)
3440 rx->link_sta->pub->smps_mode = smps_mode;
3441 sta_opmode.smps_mode =
3442 ieee80211_smps_mode_to_smps_mode(smps_mode);
3443 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3445 sband = rx->local->hw.wiphy->bands[status->band];
3447 rate_control_rate_update(local, sband, rx->sta, 0,
3448 IEEE80211_RC_SMPS_CHANGED);
3449 cfg80211_sta_opmode_change_notify(sdata->dev,
3455 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3456 struct ieee80211_supported_band *sband;
3457 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3458 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3459 struct sta_opmode_info sta_opmode = {};
3461 /* If it doesn't support 40 MHz it can't change ... */
3462 if (!(rx->link_sta->pub->ht_cap.cap &
3463 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3466 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3467 max_bw = IEEE80211_STA_RX_BW_20;
3469 max_bw = ieee80211_sta_cap_rx_bw(rx->link_sta);
3471 /* set cur_max_bandwidth and recalc sta bw */
3472 rx->link_sta->cur_max_bandwidth = max_bw;
3473 new_bw = ieee80211_sta_cur_vht_bw(rx->link_sta);
3475 if (rx->link_sta->pub->bandwidth == new_bw)
3478 rx->link_sta->pub->bandwidth = new_bw;
3479 sband = rx->local->hw.wiphy->bands[status->band];
3481 ieee80211_sta_rx_bw_to_chan_width(rx->link_sta);
3482 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3484 rate_control_rate_update(local, sband, rx->sta, 0,
3485 IEEE80211_RC_BW_CHANGED);
3486 cfg80211_sta_opmode_change_notify(sdata->dev,
3497 case WLAN_CATEGORY_PUBLIC:
3498 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3500 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3504 if (!ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid))
3506 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3507 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3509 if (len < offsetof(struct ieee80211_mgmt,
3510 u.action.u.ext_chan_switch.variable))
3513 case WLAN_CATEGORY_VHT:
3514 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3515 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3516 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3517 sdata->vif.type != NL80211_IFTYPE_AP &&
3518 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3521 /* verify action code is present */
3522 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3525 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3526 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3527 /* verify opmode is present */
3528 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3532 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3533 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3541 case WLAN_CATEGORY_BACK:
3542 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3543 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3544 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3545 sdata->vif.type != NL80211_IFTYPE_AP &&
3546 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3549 /* verify action_code is present */
3550 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3553 switch (mgmt->u.action.u.addba_req.action_code) {
3554 case WLAN_ACTION_ADDBA_REQ:
3555 if (len < (IEEE80211_MIN_ACTION_SIZE +
3556 sizeof(mgmt->u.action.u.addba_req)))
3559 case WLAN_ACTION_ADDBA_RESP:
3560 if (len < (IEEE80211_MIN_ACTION_SIZE +
3561 sizeof(mgmt->u.action.u.addba_resp)))
3564 case WLAN_ACTION_DELBA:
3565 if (len < (IEEE80211_MIN_ACTION_SIZE +
3566 sizeof(mgmt->u.action.u.delba)))
3574 case WLAN_CATEGORY_SPECTRUM_MGMT:
3575 /* verify action_code is present */
3576 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3579 switch (mgmt->u.action.u.measurement.action_code) {
3580 case WLAN_ACTION_SPCT_MSR_REQ:
3581 if (status->band != NL80211_BAND_5GHZ)
3584 if (len < (IEEE80211_MIN_ACTION_SIZE +
3585 sizeof(mgmt->u.action.u.measurement)))
3588 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3591 ieee80211_process_measurement_req(sdata, mgmt, len);
3593 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3595 if (len < (IEEE80211_MIN_ACTION_SIZE +
3596 sizeof(mgmt->u.action.u.chan_switch)))
3599 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3600 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3601 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3604 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3605 bssid = sdata->deflink.u.mgd.bssid;
3606 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3607 bssid = sdata->u.ibss.bssid;
3608 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3613 if (!ether_addr_equal(mgmt->bssid, bssid))
3620 case WLAN_CATEGORY_SELF_PROTECTED:
3621 if (len < (IEEE80211_MIN_ACTION_SIZE +
3622 sizeof(mgmt->u.action.u.self_prot.action_code)))
3625 switch (mgmt->u.action.u.self_prot.action_code) {
3626 case WLAN_SP_MESH_PEERING_OPEN:
3627 case WLAN_SP_MESH_PEERING_CLOSE:
3628 case WLAN_SP_MESH_PEERING_CONFIRM:
3629 if (!ieee80211_vif_is_mesh(&sdata->vif))
3631 if (sdata->u.mesh.user_mpm)
3632 /* userspace handles this frame */
3635 case WLAN_SP_MGK_INFORM:
3636 case WLAN_SP_MGK_ACK:
3637 if (!ieee80211_vif_is_mesh(&sdata->vif))
3642 case WLAN_CATEGORY_MESH_ACTION:
3643 if (len < (IEEE80211_MIN_ACTION_SIZE +
3644 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3647 if (!ieee80211_vif_is_mesh(&sdata->vif))
3649 if (mesh_action_is_path_sel(mgmt) &&
3650 !mesh_path_sel_is_hwmp(sdata))
3653 case WLAN_CATEGORY_S1G:
3654 switch (mgmt->u.action.u.s1g.action_code) {
3655 case WLAN_S1G_TWT_SETUP:
3656 case WLAN_S1G_TWT_TEARDOWN:
3657 if (ieee80211_process_rx_twt_action(rx))
3669 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3670 /* will return in the next handlers */
3675 rx->link_sta->rx_stats.packets++;
3676 dev_kfree_skb(rx->skb);
3680 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3684 static ieee80211_rx_result debug_noinline
3685 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3687 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3688 struct cfg80211_rx_info info = {
3689 .freq = ieee80211_rx_status_to_khz(status),
3690 .buf = rx->skb->data,
3691 .len = rx->skb->len,
3692 .link_id = rx->link_id,
3693 .have_link_id = rx->link_id >= 0,
3696 /* skip known-bad action frames and return them in the next handler */
3697 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3701 * Getting here means the kernel doesn't know how to handle
3702 * it, but maybe userspace does ... include returned frames
3703 * so userspace can register for those to know whether ones
3704 * it transmitted were processed or returned.
3707 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3708 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3709 info.sig_dbm = status->signal;
3711 if (ieee80211_is_timing_measurement(rx->skb) ||
3712 ieee80211_is_ftm(rx->skb)) {
3713 info.rx_tstamp = ktime_to_ns(skb_hwtstamps(rx->skb)->hwtstamp);
3714 info.ack_tstamp = ktime_to_ns(status->ack_tx_hwtstamp);
3717 if (cfg80211_rx_mgmt_ext(&rx->sdata->wdev, &info)) {
3719 rx->link_sta->rx_stats.packets++;
3720 dev_kfree_skb(rx->skb);
3727 static ieee80211_rx_result debug_noinline
3728 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
3730 struct ieee80211_sub_if_data *sdata = rx->sdata;
3731 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3732 int len = rx->skb->len;
3734 if (!ieee80211_is_action(mgmt->frame_control))
3737 switch (mgmt->u.action.category) {
3738 case WLAN_CATEGORY_SA_QUERY:
3739 if (len < (IEEE80211_MIN_ACTION_SIZE +
3740 sizeof(mgmt->u.action.u.sa_query)))
3743 switch (mgmt->u.action.u.sa_query.action) {
3744 case WLAN_ACTION_SA_QUERY_REQUEST:
3745 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3747 ieee80211_process_sa_query_req(sdata, mgmt, len);
3757 rx->link_sta->rx_stats.packets++;
3758 dev_kfree_skb(rx->skb);
3762 static ieee80211_rx_result debug_noinline
3763 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3765 struct ieee80211_local *local = rx->local;
3766 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3767 struct sk_buff *nskb;
3768 struct ieee80211_sub_if_data *sdata = rx->sdata;
3769 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3771 if (!ieee80211_is_action(mgmt->frame_control))
3775 * For AP mode, hostapd is responsible for handling any action
3776 * frames that we didn't handle, including returning unknown
3777 * ones. For all other modes we will return them to the sender,
3778 * setting the 0x80 bit in the action category, as required by
3779 * 802.11-2012 9.24.4.
3780 * Newer versions of hostapd shall also use the management frame
3781 * registration mechanisms, but older ones still use cooked
3782 * monitor interfaces so push all frames there.
3784 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3785 (sdata->vif.type == NL80211_IFTYPE_AP ||
3786 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3787 return RX_DROP_MONITOR;
3789 if (is_multicast_ether_addr(mgmt->da))
3790 return RX_DROP_MONITOR;
3792 /* do not return rejected action frames */
3793 if (mgmt->u.action.category & 0x80)
3794 return RX_DROP_UNUSABLE;
3796 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3799 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3801 nmgmt->u.action.category |= 0x80;
3802 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3803 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3805 memset(nskb->cb, 0, sizeof(nskb->cb));
3807 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3808 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3810 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3811 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3812 IEEE80211_TX_CTL_NO_CCK_RATE;
3813 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3815 local->hw.offchannel_tx_hw_queue;
3818 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, -1,
3821 dev_kfree_skb(rx->skb);
3825 static ieee80211_rx_result debug_noinline
3826 ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
3828 struct ieee80211_sub_if_data *sdata = rx->sdata;
3829 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
3831 if (!ieee80211_is_ext(hdr->frame_control))
3834 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3835 return RX_DROP_MONITOR;
3837 /* for now only beacons are ext, so queue them */
3838 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3843 static ieee80211_rx_result debug_noinline
3844 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3846 struct ieee80211_sub_if_data *sdata = rx->sdata;
3847 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3850 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3852 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3853 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3854 sdata->vif.type != NL80211_IFTYPE_OCB &&
3855 sdata->vif.type != NL80211_IFTYPE_STATION)
3856 return RX_DROP_MONITOR;
3859 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3860 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3861 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3862 /* process for all: mesh, mlme, ibss */
3864 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3865 if (is_multicast_ether_addr(mgmt->da) &&
3866 !is_broadcast_ether_addr(mgmt->da))
3867 return RX_DROP_MONITOR;
3869 /* process only for station/IBSS */
3870 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3871 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3872 return RX_DROP_MONITOR;
3874 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3875 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3876 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3877 if (is_multicast_ether_addr(mgmt->da) &&
3878 !is_broadcast_ether_addr(mgmt->da))
3879 return RX_DROP_MONITOR;
3881 /* process only for station */
3882 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3883 return RX_DROP_MONITOR;
3885 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3886 /* process only for ibss and mesh */
3887 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3888 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3889 return RX_DROP_MONITOR;
3892 return RX_DROP_MONITOR;
3895 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3900 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3901 struct ieee80211_rate *rate)
3903 struct ieee80211_sub_if_data *sdata;
3904 struct ieee80211_local *local = rx->local;
3905 struct sk_buff *skb = rx->skb, *skb2;
3906 struct net_device *prev_dev = NULL;
3907 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3908 int needed_headroom;
3911 * If cooked monitor has been processed already, then
3912 * don't do it again. If not, set the flag.
3914 if (rx->flags & IEEE80211_RX_CMNTR)
3916 rx->flags |= IEEE80211_RX_CMNTR;
3918 /* If there are no cooked monitor interfaces, just free the SKB */
3919 if (!local->cooked_mntrs)
3922 /* vendor data is long removed here */
3923 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3924 /* room for the radiotap header based on driver features */
3925 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3927 if (skb_headroom(skb) < needed_headroom &&
3928 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3931 /* prepend radiotap information */
3932 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3935 skb_reset_mac_header(skb);
3936 skb->ip_summed = CHECKSUM_UNNECESSARY;
3937 skb->pkt_type = PACKET_OTHERHOST;
3938 skb->protocol = htons(ETH_P_802_2);
3940 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3941 if (!ieee80211_sdata_running(sdata))
3944 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3945 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3949 skb2 = skb_clone(skb, GFP_ATOMIC);
3951 skb2->dev = prev_dev;
3952 netif_receive_skb(skb2);
3956 prev_dev = sdata->dev;
3957 dev_sw_netstats_rx_add(sdata->dev, skb->len);
3961 skb->dev = prev_dev;
3962 netif_receive_skb(skb);
3970 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3971 ieee80211_rx_result res)
3974 case RX_DROP_MONITOR:
3975 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3977 rx->link_sta->rx_stats.dropped++;
3980 struct ieee80211_rate *rate = NULL;
3981 struct ieee80211_supported_band *sband;
3982 struct ieee80211_rx_status *status;
3984 status = IEEE80211_SKB_RXCB((rx->skb));
3986 sband = rx->local->hw.wiphy->bands[status->band];
3987 if (status->encoding == RX_ENC_LEGACY)
3988 rate = &sband->bitrates[status->rate_idx];
3990 ieee80211_rx_cooked_monitor(rx, rate);
3993 case RX_DROP_UNUSABLE:
3994 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3996 rx->link_sta->rx_stats.dropped++;
3997 dev_kfree_skb(rx->skb);
4000 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
4005 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
4006 struct sk_buff_head *frames)
4008 ieee80211_rx_result res = RX_DROP_MONITOR;
4009 struct sk_buff *skb;
4011 #define CALL_RXH(rxh) \
4014 if (res != RX_CONTINUE) \
4018 /* Lock here to avoid hitting all of the data used in the RX
4019 * path (e.g. key data, station data, ...) concurrently when
4020 * a frame is released from the reorder buffer due to timeout
4021 * from the timer, potentially concurrently with RX from the
4024 spin_lock_bh(&rx->local->rx_path_lock);
4026 while ((skb = __skb_dequeue(frames))) {
4028 * all the other fields are valid across frames
4029 * that belong to an aMPDU since they are on the
4030 * same TID from the same station
4034 if (WARN_ON_ONCE(!rx->link))
4037 CALL_RXH(ieee80211_rx_h_check_more_data);
4038 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
4039 CALL_RXH(ieee80211_rx_h_sta_process);
4040 CALL_RXH(ieee80211_rx_h_decrypt);
4041 CALL_RXH(ieee80211_rx_h_defragment);
4042 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
4043 /* must be after MMIC verify so header is counted in MPDU mic */
4044 CALL_RXH(ieee80211_rx_h_amsdu);
4045 CALL_RXH(ieee80211_rx_h_data);
4047 /* special treatment -- needs the queue */
4048 res = ieee80211_rx_h_ctrl(rx, frames);
4049 if (res != RX_CONTINUE)
4052 CALL_RXH(ieee80211_rx_h_mgmt_check);
4053 CALL_RXH(ieee80211_rx_h_action);
4054 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
4055 CALL_RXH(ieee80211_rx_h_action_post_userspace);
4056 CALL_RXH(ieee80211_rx_h_action_return);
4057 CALL_RXH(ieee80211_rx_h_ext);
4058 CALL_RXH(ieee80211_rx_h_mgmt);
4061 ieee80211_rx_handlers_result(rx, res);
4066 spin_unlock_bh(&rx->local->rx_path_lock);
4069 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
4071 struct sk_buff_head reorder_release;
4072 ieee80211_rx_result res = RX_DROP_MONITOR;
4074 __skb_queue_head_init(&reorder_release);
4076 #define CALL_RXH(rxh) \
4079 if (res != RX_CONTINUE) \
4083 CALL_RXH(ieee80211_rx_h_check_dup);
4084 CALL_RXH(ieee80211_rx_h_check);
4086 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
4088 ieee80211_rx_handlers(rx, &reorder_release);
4092 ieee80211_rx_handlers_result(rx, res);
4098 ieee80211_rx_is_valid_sta_link_id(struct ieee80211_sta *sta, u8 link_id)
4100 return !!(sta->valid_links & BIT(link_id));
4103 static bool ieee80211_rx_data_set_link(struct ieee80211_rx_data *rx,
4106 rx->link_id = link_id;
4107 rx->link = rcu_dereference(rx->sdata->link[link_id]);
4112 if (!ieee80211_rx_is_valid_sta_link_id(&rx->sta->sta, link_id))
4115 rx->link_sta = rcu_dereference(rx->sta->link[link_id]);
4117 return rx->link && rx->link_sta;
4120 static bool ieee80211_rx_data_set_sta(struct ieee80211_rx_data *rx,
4121 struct sta_info *sta, int link_id)
4123 rx->link_id = link_id;
4127 rx->local = sta->sdata->local;
4129 rx->sdata = sta->sdata;
4130 rx->link_sta = &sta->deflink;
4132 rx->link_sta = NULL;
4136 rx->link = &rx->sdata->deflink;
4137 else if (!ieee80211_rx_data_set_link(rx, link_id))
4144 * This function makes calls into the RX path, therefore
4145 * it has to be invoked under RCU read lock.
4147 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
4149 struct sk_buff_head frames;
4150 struct ieee80211_rx_data rx = {
4151 /* This is OK -- must be QoS data frame */
4152 .security_idx = tid,
4155 struct tid_ampdu_rx *tid_agg_rx;
4158 /* FIXME: statistics won't be right with this */
4159 if (sta->sta.valid_links)
4160 link_id = ffs(sta->sta.valid_links) - 1;
4162 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
4165 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4169 __skb_queue_head_init(&frames);
4171 spin_lock(&tid_agg_rx->reorder_lock);
4172 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4173 spin_unlock(&tid_agg_rx->reorder_lock);
4175 if (!skb_queue_empty(&frames)) {
4176 struct ieee80211_event event = {
4177 .type = BA_FRAME_TIMEOUT,
4179 .u.ba.sta = &sta->sta,
4181 drv_event_callback(rx.local, rx.sdata, &event);
4184 ieee80211_rx_handlers(&rx, &frames);
4187 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
4188 u16 ssn, u64 filtered,
4191 struct sta_info *sta;
4192 struct tid_ampdu_rx *tid_agg_rx;
4193 struct sk_buff_head frames;
4194 struct ieee80211_rx_data rx = {
4195 /* This is OK -- must be QoS data frame */
4196 .security_idx = tid,
4201 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
4204 __skb_queue_head_init(&frames);
4206 sta = container_of(pubsta, struct sta_info, sta);
4208 if (!ieee80211_rx_data_set_sta(&rx, sta, -1))
4212 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4216 spin_lock_bh(&tid_agg_rx->reorder_lock);
4218 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
4221 /* release all frames in the reorder buffer */
4222 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
4223 IEEE80211_SN_MODULO;
4224 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
4226 /* update ssn to match received ssn */
4227 tid_agg_rx->head_seq_num = ssn;
4229 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
4233 /* handle the case that received ssn is behind the mac ssn.
4234 * it can be tid_agg_rx->buf_size behind and still be valid */
4235 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
4236 if (diff >= tid_agg_rx->buf_size) {
4237 tid_agg_rx->reorder_buf_filtered = 0;
4240 filtered = filtered >> diff;
4244 for (i = 0; i < tid_agg_rx->buf_size; i++) {
4245 int index = (ssn + i) % tid_agg_rx->buf_size;
4247 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
4248 if (filtered & BIT_ULL(i))
4249 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
4252 /* now process also frames that the filter marking released */
4253 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4256 spin_unlock_bh(&tid_agg_rx->reorder_lock);
4258 ieee80211_rx_handlers(&rx, &frames);
4263 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
4265 /* main receive path */
4267 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
4269 return ether_addr_equal(raddr, addr) ||
4270 is_broadcast_ether_addr(raddr);
4273 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
4275 struct ieee80211_sub_if_data *sdata = rx->sdata;
4276 struct sk_buff *skb = rx->skb;
4277 struct ieee80211_hdr *hdr = (void *)skb->data;
4278 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4279 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
4280 bool multicast = is_multicast_ether_addr(hdr->addr1) ||
4281 ieee80211_is_s1g_beacon(hdr->frame_control);
4283 switch (sdata->vif.type) {
4284 case NL80211_IFTYPE_STATION:
4285 if (!bssid && !sdata->u.mgd.use_4addr)
4287 if (ieee80211_is_first_frag(hdr->seq_ctrl) &&
4288 ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
4292 return ieee80211_is_our_addr(sdata, hdr->addr1, &rx->link_id);
4293 case NL80211_IFTYPE_ADHOC:
4296 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
4297 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
4298 !is_valid_ether_addr(hdr->addr2))
4300 if (ieee80211_is_beacon(hdr->frame_control))
4302 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
4305 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4309 if (status->encoding != RX_ENC_LEGACY)
4310 rate_idx = 0; /* TODO: HT/VHT rates */
4312 rate_idx = status->rate_idx;
4313 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
4317 case NL80211_IFTYPE_OCB:
4320 if (!ieee80211_is_data_present(hdr->frame_control))
4322 if (!is_broadcast_ether_addr(bssid))
4325 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
4329 if (status->encoding != RX_ENC_LEGACY)
4330 rate_idx = 0; /* TODO: HT rates */
4332 rate_idx = status->rate_idx;
4333 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
4337 case NL80211_IFTYPE_MESH_POINT:
4338 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
4342 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4343 case NL80211_IFTYPE_AP_VLAN:
4344 case NL80211_IFTYPE_AP:
4346 return ieee80211_is_our_addr(sdata, hdr->addr1,
4349 if (!is_broadcast_ether_addr(bssid) &&
4350 !ieee80211_is_our_addr(sdata, bssid, NULL)) {
4352 * Accept public action frames even when the
4353 * BSSID doesn't match, this is used for P2P
4354 * and location updates. Note that mac80211
4355 * itself never looks at these frames.
4358 !ieee80211_is_our_addr(sdata, hdr->addr1,
4361 if (ieee80211_is_public_action(hdr, skb->len))
4363 return ieee80211_is_beacon(hdr->frame_control);
4366 if (!ieee80211_has_tods(hdr->frame_control)) {
4367 /* ignore data frames to TDLS-peers */
4368 if (ieee80211_is_data(hdr->frame_control))
4370 /* ignore action frames to TDLS-peers */
4371 if (ieee80211_is_action(hdr->frame_control) &&
4372 !is_broadcast_ether_addr(bssid) &&
4373 !ether_addr_equal(bssid, hdr->addr1))
4378 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4379 * the BSSID - we've checked that already but may have accepted
4380 * the wildcard (ff:ff:ff:ff:ff:ff).
4383 * The BSSID of the Data frame is determined as follows:
4384 * a) If the STA is contained within an AP or is associated
4385 * with an AP, the BSSID is the address currently in use
4386 * by the STA contained in the AP.
4388 * So we should not accept data frames with an address that's
4391 * Accepting it also opens a security problem because stations
4392 * could encrypt it with the GTK and inject traffic that way.
4394 if (ieee80211_is_data(hdr->frame_control) && multicast)
4398 case NL80211_IFTYPE_P2P_DEVICE:
4399 return ieee80211_is_public_action(hdr, skb->len) ||
4400 ieee80211_is_probe_req(hdr->frame_control) ||
4401 ieee80211_is_probe_resp(hdr->frame_control) ||
4402 ieee80211_is_beacon(hdr->frame_control);
4403 case NL80211_IFTYPE_NAN:
4404 /* Currently no frames on NAN interface are allowed */
4414 void ieee80211_check_fast_rx(struct sta_info *sta)
4416 struct ieee80211_sub_if_data *sdata = sta->sdata;
4417 struct ieee80211_local *local = sdata->local;
4418 struct ieee80211_key *key;
4419 struct ieee80211_fast_rx fastrx = {
4421 .vif_type = sdata->vif.type,
4422 .control_port_protocol = sdata->control_port_protocol,
4423 }, *old, *new = NULL;
4425 bool set_offload = false;
4426 bool assign = false;
4429 /* use sparse to check that we don't return without updating */
4430 __acquire(check_fast_rx);
4432 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4433 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4434 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4435 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4437 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4439 /* fast-rx doesn't do reordering */
4440 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4441 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4444 switch (sdata->vif.type) {
4445 case NL80211_IFTYPE_STATION:
4446 if (sta->sta.tdls) {
4447 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4448 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4449 fastrx.expected_ds_bits = 0;
4451 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4452 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4453 fastrx.expected_ds_bits =
4454 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4457 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4458 fastrx.expected_ds_bits |=
4459 cpu_to_le16(IEEE80211_FCTL_TODS);
4460 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4461 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4464 if (!sdata->u.mgd.powersave)
4467 /* software powersave is a huge mess, avoid all of it */
4468 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4470 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4471 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4474 case NL80211_IFTYPE_AP_VLAN:
4475 case NL80211_IFTYPE_AP:
4476 /* parallel-rx requires this, at least with calls to
4477 * ieee80211_sta_ps_transition()
4479 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4481 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4482 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4483 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4485 fastrx.internal_forward =
4486 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4487 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4488 !sdata->u.vlan.sta);
4490 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4491 sdata->u.vlan.sta) {
4492 fastrx.expected_ds_bits |=
4493 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4494 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4495 fastrx.internal_forward = 0;
4503 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4507 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4509 key = rcu_dereference(sdata->default_unicast_key);
4511 switch (key->conf.cipher) {
4512 case WLAN_CIPHER_SUITE_TKIP:
4513 /* we don't want to deal with MMIC in fast-rx */
4515 case WLAN_CIPHER_SUITE_CCMP:
4516 case WLAN_CIPHER_SUITE_CCMP_256:
4517 case WLAN_CIPHER_SUITE_GCMP:
4518 case WLAN_CIPHER_SUITE_GCMP_256:
4521 /* We also don't want to deal with
4522 * WEP or cipher scheme.
4528 fastrx.icv_len = key->conf.icv_len;
4535 __release(check_fast_rx);
4538 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4540 offload_flags = get_bss_sdata(sdata)->vif.offload_flags;
4541 offload = offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED;
4543 if (assign && offload)
4544 set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4546 set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4549 drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
4551 spin_lock_bh(&sta->lock);
4552 old = rcu_dereference_protected(sta->fast_rx, true);
4553 rcu_assign_pointer(sta->fast_rx, new);
4554 spin_unlock_bh(&sta->lock);
4557 kfree_rcu(old, rcu_head);
4560 void ieee80211_clear_fast_rx(struct sta_info *sta)
4562 struct ieee80211_fast_rx *old;
4564 spin_lock_bh(&sta->lock);
4565 old = rcu_dereference_protected(sta->fast_rx, true);
4566 RCU_INIT_POINTER(sta->fast_rx, NULL);
4567 spin_unlock_bh(&sta->lock);
4570 kfree_rcu(old, rcu_head);
4573 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4575 struct ieee80211_local *local = sdata->local;
4576 struct sta_info *sta;
4578 lockdep_assert_held(&local->sta_mtx);
4580 list_for_each_entry(sta, &local->sta_list, list) {
4581 if (sdata != sta->sdata &&
4582 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4584 ieee80211_check_fast_rx(sta);
4588 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4590 struct ieee80211_local *local = sdata->local;
4592 mutex_lock(&local->sta_mtx);
4593 __ieee80211_check_fast_rx_iface(sdata);
4594 mutex_unlock(&local->sta_mtx);
4597 static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
4598 struct ieee80211_fast_rx *fast_rx,
4601 struct ieee80211_sta_rx_stats *stats;
4602 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4603 struct sta_info *sta = rx->sta;
4604 struct link_sta_info *link_sta;
4605 struct sk_buff *skb = rx->skb;
4606 void *sa = skb->data + ETH_ALEN;
4607 void *da = skb->data;
4609 if (rx->link_id >= 0) {
4610 link_sta = rcu_dereference(sta->link[rx->link_id]);
4611 if (WARN_ON_ONCE(!link_sta)) {
4612 dev_kfree_skb(rx->skb);
4616 link_sta = &sta->deflink;
4619 stats = &link_sta->rx_stats;
4620 if (fast_rx->uses_rss)
4621 stats = this_cpu_ptr(link_sta->pcpu_rx_stats);
4623 /* statistics part of ieee80211_rx_h_sta_process() */
4624 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4625 stats->last_signal = status->signal;
4626 if (!fast_rx->uses_rss)
4627 ewma_signal_add(&link_sta->rx_stats_avg.signal,
4631 if (status->chains) {
4634 stats->chains = status->chains;
4635 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4636 int signal = status->chain_signal[i];
4638 if (!(status->chains & BIT(i)))
4641 stats->chain_signal_last[i] = signal;
4642 if (!fast_rx->uses_rss)
4643 ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
4647 /* end of statistics */
4649 stats->last_rx = jiffies;
4650 stats->last_rate = sta_stats_encode_rate(status);
4655 skb->dev = fast_rx->dev;
4657 dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
4659 /* The seqno index has the same property as needed
4660 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4661 * for non-QoS-data frames. Here we know it's a data
4662 * frame, so count MSDUs.
4664 u64_stats_update_begin(&stats->syncp);
4665 stats->msdu[rx->seqno_idx]++;
4666 stats->bytes += orig_len;
4667 u64_stats_update_end(&stats->syncp);
4669 if (fast_rx->internal_forward) {
4670 struct sk_buff *xmit_skb = NULL;
4671 if (is_multicast_ether_addr(da)) {
4672 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4673 } else if (!ether_addr_equal(da, sa) &&
4674 sta_info_get(rx->sdata, da)) {
4681 * Send to wireless media and increase priority by 256
4682 * to keep the received priority instead of
4683 * reclassifying the frame (see cfg80211_classify8021d).
4685 xmit_skb->priority += 256;
4686 xmit_skb->protocol = htons(ETH_P_802_3);
4687 skb_reset_network_header(xmit_skb);
4688 skb_reset_mac_header(xmit_skb);
4689 dev_queue_xmit(xmit_skb);
4696 /* deliver to local stack */
4697 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4698 ieee80211_deliver_skb_to_local_stack(skb, rx);
4701 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4702 struct ieee80211_fast_rx *fast_rx)
4704 struct sk_buff *skb = rx->skb;
4705 struct ieee80211_hdr *hdr = (void *)skb->data;
4706 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4707 int orig_len = skb->len;
4708 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4709 int snap_offs = hdrlen;
4711 u8 snap[sizeof(rfc1042_header)];
4713 } *payload __aligned(2);
4717 } addrs __aligned(2);
4718 struct ieee80211_sta_rx_stats *stats;
4720 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4721 * to a common data structure; drivers can implement that per queue
4722 * but we don't have that information in mac80211
4724 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4727 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4729 /* If using encryption, we also need to have:
4730 * - PN_VALIDATED: similar, but the implementation is tricky
4731 * - DECRYPTED: necessary for PN_VALIDATED
4734 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4737 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4740 if (unlikely(ieee80211_is_frag(hdr)))
4743 /* Since our interface address cannot be multicast, this
4744 * implicitly also rejects multicast frames without the
4747 * We shouldn't get any *data* frames not addressed to us
4748 * (AP mode will accept multicast *management* frames), but
4749 * punting here will make it go through the full checks in
4750 * ieee80211_accept_frame().
4752 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4755 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4756 IEEE80211_FCTL_TODS)) !=
4757 fast_rx->expected_ds_bits)
4760 /* assign the key to drop unencrypted frames (later)
4761 * and strip the IV/MIC if necessary
4763 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4764 /* GCMP header length is the same */
4765 snap_offs += IEEE80211_CCMP_HDR_LEN;
4768 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4769 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4772 payload = (void *)(skb->data + snap_offs);
4774 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4777 /* Don't handle these here since they require special code.
4778 * Accept AARP and IPX even though they should come with a
4779 * bridge-tunnel header - but if we get them this way then
4780 * there's little point in discarding them.
4782 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4783 payload->proto == fast_rx->control_port_protocol))
4787 /* after this point, don't punt to the slowpath! */
4789 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4790 pskb_trim(skb, skb->len - fast_rx->icv_len))
4793 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4796 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4797 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4804 /* do the header conversion - first grab the addresses */
4805 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4806 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4807 skb_postpull_rcsum(skb, skb->data + snap_offs,
4808 sizeof(rfc1042_header) + 2);
4809 /* remove the SNAP but leave the ethertype */
4810 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4811 /* push the addresses in front */
4812 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4814 ieee80211_rx_8023(rx, fast_rx, orig_len);
4820 if (fast_rx->uses_rss)
4821 stats = this_cpu_ptr(rx->link_sta->pcpu_rx_stats);
4823 stats = &rx->link_sta->rx_stats;
4830 * This function returns whether or not the SKB
4831 * was destined for RX processing or not, which,
4832 * if consume is true, is equivalent to whether
4833 * or not the skb was consumed.
4835 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4836 struct sk_buff *skb, bool consume)
4838 struct ieee80211_local *local = rx->local;
4839 struct ieee80211_sub_if_data *sdata = rx->sdata;
4840 struct ieee80211_hdr *hdr = (void *)skb->data;
4841 struct link_sta_info *link_sta = rx->link_sta;
4842 struct ieee80211_link_data *link = rx->link;
4846 /* See if we can do fast-rx; if we have to copy we already lost,
4847 * so punt in that case. We should never have to deliver a data
4848 * frame to multiple interfaces anyway.
4850 * We skip the ieee80211_accept_frame() call and do the necessary
4851 * checking inside ieee80211_invoke_fast_rx().
4853 if (consume && rx->sta) {
4854 struct ieee80211_fast_rx *fast_rx;
4856 fast_rx = rcu_dereference(rx->sta->fast_rx);
4857 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4861 if (!ieee80211_accept_frame(rx))
4865 struct skb_shared_hwtstamps *shwt;
4867 rx->skb = skb_copy(skb, GFP_ATOMIC);
4869 if (net_ratelimit())
4870 wiphy_debug(local->hw.wiphy,
4871 "failed to copy skb for %s\n",
4876 /* skb_copy() does not copy the hw timestamps, so copy it
4879 shwt = skb_hwtstamps(rx->skb);
4880 shwt->hwtstamp = skb_hwtstamps(skb)->hwtstamp;
4882 /* Update the hdr pointer to the new skb for translation below */
4883 hdr = (struct ieee80211_hdr *)rx->skb->data;
4886 if (unlikely(rx->sta && rx->sta->sta.mlo) &&
4887 is_unicast_ether_addr(hdr->addr1)) {
4888 /* translate to MLD addresses */
4889 if (ether_addr_equal(link->conf->addr, hdr->addr1))
4890 ether_addr_copy(hdr->addr1, rx->sdata->vif.addr);
4891 if (ether_addr_equal(link_sta->addr, hdr->addr2))
4892 ether_addr_copy(hdr->addr2, rx->sta->addr);
4893 /* translate A3 only if it's the BSSID */
4894 if (!ieee80211_has_tods(hdr->frame_control) &&
4895 !ieee80211_has_fromds(hdr->frame_control)) {
4896 if (ether_addr_equal(link_sta->addr, hdr->addr3))
4897 ether_addr_copy(hdr->addr3, rx->sta->addr);
4898 else if (ether_addr_equal(link->conf->addr, hdr->addr3))
4899 ether_addr_copy(hdr->addr3, rx->sdata->vif.addr);
4901 /* not needed for A4 since it can only carry the SA */
4904 ieee80211_invoke_rx_handlers(rx);
4908 static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
4909 struct ieee80211_sta *pubsta,
4910 struct sk_buff *skb,
4911 struct list_head *list)
4913 struct ieee80211_local *local = hw_to_local(hw);
4914 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4915 struct ieee80211_fast_rx *fast_rx;
4916 struct ieee80211_rx_data rx;
4917 struct sta_info *sta;
4920 memset(&rx, 0, sizeof(rx));
4926 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4928 /* drop frame if too short for header */
4929 if (skb->len < sizeof(struct ethhdr))
4935 if (status->link_valid)
4936 link_id = status->link_id;
4939 * TODO: Should the frame be dropped if the right link_id is not
4940 * available? Or may be it is fine in the current form to proceed with
4941 * the frame processing because with frame being in 802.3 format,
4942 * link_id is used only for stats purpose and updating the stats on
4943 * the deflink is fine?
4945 sta = container_of(pubsta, struct sta_info, sta);
4946 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
4949 fast_rx = rcu_dereference(rx.sta->fast_rx);
4953 ieee80211_rx_8023(&rx, fast_rx, skb->len);
4960 static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx,
4961 struct sk_buff *skb, bool consume)
4963 struct link_sta_info *link_sta;
4964 struct ieee80211_hdr *hdr = (void *)skb->data;
4965 struct sta_info *sta;
4969 * Look up link station first, in case there's a
4970 * chance that they might have a link address that
4971 * is identical to the MLD address, that way we'll
4972 * have the link information if needed.
4974 link_sta = link_sta_info_get_bss(rx->sdata, hdr->addr2);
4976 sta = link_sta->sta;
4977 link_id = link_sta->link_id;
4979 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4981 sta = sta_info_get_bss(rx->sdata, hdr->addr2);
4982 if (status->link_valid)
4983 link_id = status->link_id;
4986 if (!ieee80211_rx_data_set_sta(rx, sta, link_id))
4989 return ieee80211_prepare_and_rx_handle(rx, skb, consume);
4993 * This is the actual Rx frames handler. as it belongs to Rx path it must
4994 * be called with rcu_read_lock protection.
4996 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4997 struct ieee80211_sta *pubsta,
4998 struct sk_buff *skb,
4999 struct list_head *list)
5001 struct ieee80211_local *local = hw_to_local(hw);
5002 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5003 struct ieee80211_sub_if_data *sdata;
5004 struct ieee80211_hdr *hdr;
5006 struct ieee80211_rx_data rx;
5007 struct ieee80211_sub_if_data *prev;
5008 struct rhlist_head *tmp;
5011 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
5012 memset(&rx, 0, sizeof(rx));
5018 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
5019 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
5021 if (ieee80211_is_mgmt(fc)) {
5022 /* drop frame if too short for header */
5023 if (skb->len < ieee80211_hdrlen(fc))
5026 err = skb_linearize(skb);
5028 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
5036 hdr = (struct ieee80211_hdr *)skb->data;
5037 ieee80211_parse_qos(&rx);
5038 ieee80211_verify_alignment(&rx);
5040 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
5041 ieee80211_is_beacon(hdr->frame_control) ||
5042 ieee80211_is_s1g_beacon(hdr->frame_control)))
5043 ieee80211_scan_rx(local, skb);
5045 if (ieee80211_is_data(fc)) {
5046 struct sta_info *sta, *prev_sta;
5049 if (status->link_valid)
5050 link_id = status->link_id;
5053 sta = container_of(pubsta, struct sta_info, sta);
5054 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
5058 * In MLO connection, fetch the link_id using addr2
5059 * when the driver does not pass link_id in status.
5060 * When the address translation is already performed by
5061 * driver/hw, the valid link_id must be passed in
5065 if (!status->link_valid && pubsta->mlo) {
5066 struct ieee80211_hdr *hdr = (void *)skb->data;
5067 struct link_sta_info *link_sta;
5069 link_sta = link_sta_info_get_bss(rx.sdata,
5074 ieee80211_rx_data_set_link(&rx, link_sta->link_id);
5077 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
5084 for_each_sta_info(local, hdr->addr2, sta, tmp) {
5090 rx.sdata = prev_sta->sdata;
5091 if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
5094 if (!status->link_valid && prev_sta->sta.mlo)
5097 ieee80211_prepare_and_rx_handle(&rx, skb, false);
5103 rx.sdata = prev_sta->sdata;
5104 if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
5107 if (!status->link_valid && prev_sta->sta.mlo)
5110 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
5118 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
5119 if (!ieee80211_sdata_running(sdata))
5122 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
5123 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
5127 * frame is destined for this interface, but if it's
5128 * not also for the previous one we handle that after
5129 * the loop to avoid copying the SKB once too much
5138 ieee80211_rx_for_interface(&rx, skb, false);
5146 if (ieee80211_rx_for_interface(&rx, skb, true))
5155 * This is the receive path handler. It is called by a low level driver when an
5156 * 802.11 MPDU is received from the hardware.
5158 void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5159 struct sk_buff *skb, struct list_head *list)
5161 struct ieee80211_local *local = hw_to_local(hw);
5162 struct ieee80211_rate *rate = NULL;
5163 struct ieee80211_supported_band *sband;
5164 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5165 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5167 WARN_ON_ONCE(softirq_count() == 0);
5169 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
5172 sband = local->hw.wiphy->bands[status->band];
5173 if (WARN_ON(!sband))
5177 * If we're suspending, it is possible although not too likely
5178 * that we'd be receiving frames after having already partially
5179 * quiesced the stack. We can't process such frames then since
5180 * that might, for example, cause stations to be added or other
5181 * driver callbacks be invoked.
5183 if (unlikely(local->quiescing || local->suspended))
5186 /* We might be during a HW reconfig, prevent Rx for the same reason */
5187 if (unlikely(local->in_reconfig))
5191 * The same happens when we're not even started,
5192 * but that's worth a warning.
5194 if (WARN_ON(!local->started))
5197 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
5199 * Validate the rate, unless a PLCP error means that
5200 * we probably can't have a valid rate here anyway.
5203 switch (status->encoding) {
5206 * rate_idx is MCS index, which can be [0-76]
5209 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
5211 * Anything else would be some sort of driver or
5212 * hardware error. The driver should catch hardware
5215 if (WARN(status->rate_idx > 76,
5216 "Rate marked as an HT rate but passed "
5217 "status->rate_idx is not "
5218 "an MCS index [0-76]: %d (0x%02x)\n",
5224 if (WARN_ONCE(status->rate_idx > 11 ||
5227 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
5228 status->rate_idx, status->nss))
5232 if (WARN_ONCE(status->rate_idx > 11 ||
5235 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
5236 status->rate_idx, status->nss))
5240 if (WARN_ONCE(status->rate_idx > 15 ||
5243 status->eht.gi > NL80211_RATE_INFO_EHT_GI_3_2,
5244 "Rate marked as an EHT rate but data is invalid: MCS:%d, NSS:%d, GI:%d\n",
5245 status->rate_idx, status->nss, status->eht.gi))
5252 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
5254 rate = &sband->bitrates[status->rate_idx];
5258 if (WARN_ON_ONCE(status->link_id >= IEEE80211_LINK_UNSPECIFIED))
5261 status->rx_flags = 0;
5263 kcov_remote_start_common(skb_get_kcov_handle(skb));
5266 * Frames with failed FCS/PLCP checksum are not returned,
5267 * all other frames are returned without radiotap header
5268 * if it was previously present.
5269 * Also, frames with less than 16 bytes are dropped.
5271 if (!(status->flag & RX_FLAG_8023))
5272 skb = ieee80211_rx_monitor(local, skb, rate);
5274 if ((status->flag & RX_FLAG_8023) ||
5275 ieee80211_is_data_present(hdr->frame_control))
5276 ieee80211_tpt_led_trig_rx(local, skb->len);
5278 if (status->flag & RX_FLAG_8023)
5279 __ieee80211_rx_handle_8023(hw, pubsta, skb, list);
5281 __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
5289 EXPORT_SYMBOL(ieee80211_rx_list);
5291 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5292 struct sk_buff *skb, struct napi_struct *napi)
5294 struct sk_buff *tmp;
5299 * key references and virtual interfaces are protected using RCU
5300 * and this requires that we are in a read-side RCU section during
5301 * receive processing
5304 ieee80211_rx_list(hw, pubsta, skb, &list);
5308 netif_receive_skb_list(&list);
5312 list_for_each_entry_safe(skb, tmp, &list, list) {
5313 skb_list_del_init(skb);
5314 napi_gro_receive(napi, skb);
5317 EXPORT_SYMBOL(ieee80211_rx_napi);
5319 /* This is a version of the rx handler that can be called from hard irq
5320 * context. Post the skb on the queue and schedule the tasklet */
5321 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
5323 struct ieee80211_local *local = hw_to_local(hw);
5325 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
5327 skb->pkt_type = IEEE80211_RX_MSG;
5328 skb_queue_tail(&local->skb_queue, skb);
5329 tasklet_schedule(&local->tasklet);
5331 EXPORT_SYMBOL(ieee80211_rx_irqsafe);