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-2021 Intel Corporation
12 #include <linux/jiffies.h>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/rcupdate.h>
19 #include <linux/export.h>
20 #include <linux/kcov.h>
21 #include <linux/bitops.h>
22 #include <net/mac80211.h>
23 #include <net/ieee80211_radiotap.h>
24 #include <asm/unaligned.h>
26 #include "ieee80211_i.h"
27 #include "driver-ops.h"
37 * monitor mode reception
39 * This function cleans up the SKB, i.e. it removes all the stuff
40 * only useful for monitoring.
42 static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
43 unsigned int present_fcs_len,
44 unsigned int rtap_space)
46 struct ieee80211_hdr *hdr;
51 __pskb_trim(skb, skb->len - present_fcs_len);
52 __pskb_pull(skb, rtap_space);
54 hdr = (void *)skb->data;
55 fc = hdr->frame_control;
58 * Remove the HT-Control field (if present) on management
59 * frames after we've sent the frame to monitoring. We
60 * (currently) don't need it, and don't properly parse
61 * frames with it present, due to the assumption of a
62 * fixed management header length.
64 if (likely(!ieee80211_is_mgmt(fc) || !ieee80211_has_order(fc)))
67 hdrlen = ieee80211_hdrlen(fc);
68 hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_ORDER);
70 if (!pskb_may_pull(skb, hdrlen)) {
75 memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data,
76 hdrlen - IEEE80211_HT_CTL_LEN);
77 __pskb_pull(skb, IEEE80211_HT_CTL_LEN);
82 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
83 unsigned int rtap_space)
85 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
86 struct ieee80211_hdr *hdr;
88 hdr = (void *)(skb->data + rtap_space);
90 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
91 RX_FLAG_FAILED_PLCP_CRC |
92 RX_FLAG_ONLY_MONITOR |
96 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
99 if (ieee80211_is_ctl(hdr->frame_control) &&
100 !ieee80211_is_pspoll(hdr->frame_control) &&
101 !ieee80211_is_back_req(hdr->frame_control))
108 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
109 struct ieee80211_rx_status *status,
114 /* always present fields */
115 len = sizeof(struct ieee80211_radiotap_header) + 8;
117 /* allocate extra bitmaps */
119 len += 4 * hweight8(status->chains);
120 /* vendor presence bitmap */
121 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)
124 if (ieee80211_have_rx_timestamp(status)) {
128 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
131 /* antenna field, if we don't have per-chain info */
135 /* padding for RX_FLAGS if necessary */
138 if (status->encoding == RX_ENC_HT) /* HT info */
141 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
146 if (status->encoding == RX_ENC_VHT) {
151 if (local->hw.radiotap_timestamp.units_pos >= 0) {
156 if (status->encoding == RX_ENC_HE &&
157 status->flag & RX_FLAG_RADIOTAP_HE) {
160 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
163 if (status->encoding == RX_ENC_HE &&
164 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
167 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
170 if (status->flag & RX_FLAG_NO_PSDU)
173 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
176 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4);
179 if (status->chains) {
180 /* antenna and antenna signal fields */
181 len += 2 * hweight8(status->chains);
184 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
185 struct ieee80211_vendor_radiotap *rtap;
186 int vendor_data_offset = 0;
189 * The position to look at depends on the existence (or non-
190 * existence) of other elements, so take that into account...
192 if (status->flag & RX_FLAG_RADIOTAP_HE)
193 vendor_data_offset +=
194 sizeof(struct ieee80211_radiotap_he);
195 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
196 vendor_data_offset +=
197 sizeof(struct ieee80211_radiotap_he_mu);
198 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
199 vendor_data_offset +=
200 sizeof(struct ieee80211_radiotap_lsig);
202 rtap = (void *)&skb->data[vendor_data_offset];
204 /* alignment for fixed 6-byte vendor data header */
206 /* vendor data header */
208 if (WARN_ON(rtap->align == 0))
210 len = ALIGN(len, rtap->align);
211 len += rtap->len + rtap->pad;
217 static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
218 struct sta_info *sta,
221 skb_queue_tail(&sdata->skb_queue, skb);
222 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
224 sta->rx_stats.packets++;
227 static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
228 struct sta_info *sta,
232 __ieee80211_queue_skb_to_iface(sdata, sta, skb);
235 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
240 struct ieee80211_hdr_3addr hdr;
243 } __packed __aligned(2) action;
248 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
250 if (skb->len < rtap_space + sizeof(action) +
251 VHT_MUMIMO_GROUPS_DATA_LEN)
254 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
257 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
259 if (!ieee80211_is_action(action.hdr.frame_control))
262 if (action.category != WLAN_CATEGORY_VHT)
265 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
268 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
271 skb = skb_copy(skb, GFP_ATOMIC);
275 ieee80211_queue_skb_to_iface(sdata, NULL, skb);
279 * ieee80211_add_rx_radiotap_header - add radiotap header
281 * add a radiotap header containing all the fields which the hardware provided.
284 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
286 struct ieee80211_rate *rate,
287 int rtap_len, bool has_fcs)
289 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
290 struct ieee80211_radiotap_header *rthdr;
295 u16 channel_flags = 0;
297 unsigned long chains = status->chains;
298 struct ieee80211_vendor_radiotap rtap = {};
299 struct ieee80211_radiotap_he he = {};
300 struct ieee80211_radiotap_he_mu he_mu = {};
301 struct ieee80211_radiotap_lsig lsig = {};
303 if (status->flag & RX_FLAG_RADIOTAP_HE) {
304 he = *(struct ieee80211_radiotap_he *)skb->data;
305 skb_pull(skb, sizeof(he));
306 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
309 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
310 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
311 skb_pull(skb, sizeof(he_mu));
314 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
315 lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
316 skb_pull(skb, sizeof(lsig));
319 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
320 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
321 /* rtap.len and rtap.pad are undone immediately */
322 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
326 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
329 rthdr = skb_push(skb, rtap_len);
330 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
331 it_present = &rthdr->it_present;
333 /* radiotap header, set always present flags */
334 rthdr->it_len = cpu_to_le16(rtap_len);
335 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
336 BIT(IEEE80211_RADIOTAP_CHANNEL) |
337 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
340 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
342 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
344 BIT(IEEE80211_RADIOTAP_EXT) |
345 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
346 put_unaligned_le32(it_present_val, it_present);
348 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
349 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
352 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
353 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
354 BIT(IEEE80211_RADIOTAP_EXT);
355 put_unaligned_le32(it_present_val, it_present);
357 it_present_val = rtap.present;
360 put_unaligned_le32(it_present_val, it_present);
362 /* This references through an offset into it_optional[] rather
363 * than via it_present otherwise later uses of pos will cause
364 * the compiler to think we have walked past the end of the
367 pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
369 /* the order of the following fields is important */
371 /* IEEE80211_RADIOTAP_TSFT */
372 if (ieee80211_have_rx_timestamp(status)) {
374 while ((pos - (u8 *)rthdr) & 7)
377 ieee80211_calculate_rx_timestamp(local, status,
380 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));
384 /* IEEE80211_RADIOTAP_FLAGS */
385 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
386 *pos |= IEEE80211_RADIOTAP_F_FCS;
387 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
388 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
389 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
390 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
393 /* IEEE80211_RADIOTAP_RATE */
394 if (!rate || status->encoding != RX_ENC_LEGACY) {
396 * Without rate information don't add it. If we have,
397 * MCS information is a separate field in radiotap,
398 * added below. The byte here is needed as padding
399 * for the channel though, so initialise it to 0.
404 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
405 if (status->bw == RATE_INFO_BW_10)
407 else if (status->bw == RATE_INFO_BW_5)
409 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
413 /* IEEE80211_RADIOTAP_CHANNEL */
414 /* TODO: frequency offset in KHz */
415 put_unaligned_le16(status->freq, pos);
417 if (status->bw == RATE_INFO_BW_10)
418 channel_flags |= IEEE80211_CHAN_HALF;
419 else if (status->bw == RATE_INFO_BW_5)
420 channel_flags |= IEEE80211_CHAN_QUARTER;
422 if (status->band == NL80211_BAND_5GHZ ||
423 status->band == NL80211_BAND_6GHZ)
424 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
425 else if (status->encoding != RX_ENC_LEGACY)
426 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
427 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
428 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
430 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
432 channel_flags |= IEEE80211_CHAN_2GHZ;
433 put_unaligned_le16(channel_flags, pos);
436 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
437 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
438 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
439 *pos = status->signal;
441 cpu_to_le32(BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
445 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
447 if (!status->chains) {
448 /* IEEE80211_RADIOTAP_ANTENNA */
449 *pos = status->antenna;
453 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
455 /* IEEE80211_RADIOTAP_RX_FLAGS */
456 /* ensure 2 byte alignment for the 2 byte field as required */
457 if ((pos - (u8 *)rthdr) & 1)
459 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
460 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
461 put_unaligned_le16(rx_flags, pos);
464 if (status->encoding == RX_ENC_HT) {
467 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
468 *pos++ = local->hw.radiotap_mcs_details;
470 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
471 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
472 if (status->bw == RATE_INFO_BW_40)
473 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
474 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
475 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
476 if (status->enc_flags & RX_ENC_FLAG_LDPC)
477 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
478 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
479 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
481 *pos++ = status->rate_idx;
484 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
487 /* ensure 4 byte alignment */
488 while ((pos - (u8 *)rthdr) & 3)
491 cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
492 put_unaligned_le32(status->ampdu_reference, pos);
494 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
495 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
496 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
497 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
498 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
499 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
500 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
501 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
502 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
503 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
504 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
505 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
506 put_unaligned_le16(flags, pos);
508 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
509 *pos++ = status->ampdu_delimiter_crc;
515 if (status->encoding == RX_ENC_VHT) {
516 u16 known = local->hw.radiotap_vht_details;
518 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
519 put_unaligned_le16(known, pos);
522 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
523 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
524 /* in VHT, STBC is binary */
525 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
526 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
527 if (status->enc_flags & RX_ENC_FLAG_BF)
528 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
531 switch (status->bw) {
532 case RATE_INFO_BW_80:
535 case RATE_INFO_BW_160:
538 case RATE_INFO_BW_40:
545 *pos = (status->rate_idx << 4) | status->nss;
548 if (status->enc_flags & RX_ENC_FLAG_LDPC)
549 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
557 if (local->hw.radiotap_timestamp.units_pos >= 0) {
559 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
562 cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
564 /* ensure 8 byte alignment */
565 while ((pos - (u8 *)rthdr) & 7)
568 put_unaligned_le64(status->device_timestamp, pos);
571 if (local->hw.radiotap_timestamp.accuracy >= 0) {
572 accuracy = local->hw.radiotap_timestamp.accuracy;
573 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
575 put_unaligned_le16(accuracy, pos);
578 *pos++ = local->hw.radiotap_timestamp.units_pos;
582 if (status->encoding == RX_ENC_HE &&
583 status->flag & RX_FLAG_RADIOTAP_HE) {
584 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
586 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
587 he.data6 |= HE_PREP(DATA6_NSTS,
588 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
590 he.data3 |= HE_PREP(DATA3_STBC, 1);
592 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
595 #define CHECK_GI(s) \
596 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
597 (int)NL80211_RATE_INFO_HE_GI_##s)
603 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
604 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
605 he.data3 |= HE_PREP(DATA3_CODING,
606 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
608 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
610 switch (status->bw) {
611 case RATE_INFO_BW_20:
612 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
613 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
615 case RATE_INFO_BW_40:
616 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
617 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
619 case RATE_INFO_BW_80:
620 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
621 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
623 case RATE_INFO_BW_160:
624 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
625 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
627 case RATE_INFO_BW_HE_RU:
628 #define CHECK_RU_ALLOC(s) \
629 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
630 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
638 CHECK_RU_ALLOC(2x996);
640 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
644 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
647 /* ensure 2 byte alignment */
648 while ((pos - (u8 *)rthdr) & 1)
650 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
651 memcpy(pos, &he, sizeof(he));
655 if (status->encoding == RX_ENC_HE &&
656 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
657 /* ensure 2 byte alignment */
658 while ((pos - (u8 *)rthdr) & 1)
660 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
661 memcpy(pos, &he_mu, sizeof(he_mu));
662 pos += sizeof(he_mu);
665 if (status->flag & RX_FLAG_NO_PSDU) {
667 cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
668 *pos++ = status->zero_length_psdu_type;
671 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
672 /* ensure 2 byte alignment */
673 while ((pos - (u8 *)rthdr) & 1)
675 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
676 memcpy(pos, &lsig, sizeof(lsig));
680 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
681 *pos++ = status->chain_signal[chain];
685 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
686 /* ensure 2 byte alignment for the vendor field as required */
687 if ((pos - (u8 *)rthdr) & 1)
689 *pos++ = rtap.oui[0];
690 *pos++ = rtap.oui[1];
691 *pos++ = rtap.oui[2];
693 put_unaligned_le16(rtap.len, pos);
695 /* align the actual payload as requested */
696 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
698 /* data (and possible padding) already follows */
702 static struct sk_buff *
703 ieee80211_make_monitor_skb(struct ieee80211_local *local,
704 struct sk_buff **origskb,
705 struct ieee80211_rate *rate,
706 int rtap_space, bool use_origskb)
708 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
709 int rt_hdrlen, needed_headroom;
712 /* room for the radiotap header based on driver features */
713 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
714 needed_headroom = rt_hdrlen - rtap_space;
717 /* only need to expand headroom if necessary */
722 * This shouldn't trigger often because most devices have an
723 * RX header they pull before we get here, and that should
724 * be big enough for our radiotap information. We should
725 * probably export the length to drivers so that we can have
726 * them allocate enough headroom to start with.
728 if (skb_headroom(skb) < needed_headroom &&
729 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
735 * Need to make a copy and possibly remove radiotap header
736 * and FCS from the original.
738 skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
745 /* prepend radiotap information */
746 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
748 skb_reset_mac_header(skb);
749 skb->ip_summed = CHECKSUM_UNNECESSARY;
750 skb->pkt_type = PACKET_OTHERHOST;
751 skb->protocol = htons(ETH_P_802_2);
757 * This function copies a received frame to all monitor interfaces and
758 * returns a cleaned-up SKB that no longer includes the FCS nor the
759 * radiotap header the driver might have added.
761 static struct sk_buff *
762 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
763 struct ieee80211_rate *rate)
765 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
766 struct ieee80211_sub_if_data *sdata;
767 struct sk_buff *monskb = NULL;
768 int present_fcs_len = 0;
769 unsigned int rtap_space = 0;
770 struct ieee80211_sub_if_data *monitor_sdata =
771 rcu_dereference(local->monitor_sdata);
772 bool only_monitor = false;
773 unsigned int min_head_len;
775 if (status->flag & RX_FLAG_RADIOTAP_HE)
776 rtap_space += sizeof(struct ieee80211_radiotap_he);
778 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
779 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
781 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
782 rtap_space += sizeof(struct ieee80211_radiotap_lsig);
784 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
785 struct ieee80211_vendor_radiotap *rtap =
786 (void *)(origskb->data + rtap_space);
788 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
791 min_head_len = rtap_space;
794 * First, we may need to make a copy of the skb because
795 * (1) we need to modify it for radiotap (if not present), and
796 * (2) the other RX handlers will modify the skb we got.
798 * We don't need to, of course, if we aren't going to return
799 * the SKB because it has a bad FCS/PLCP checksum.
802 if (!(status->flag & RX_FLAG_NO_PSDU)) {
803 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
804 if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
807 dev_kfree_skb(origskb);
810 present_fcs_len = FCS_LEN;
813 /* also consider the hdr->frame_control */
817 /* ensure that the expected data elements are in skb head */
818 if (!pskb_may_pull(origskb, min_head_len)) {
819 dev_kfree_skb(origskb);
823 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
825 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
827 dev_kfree_skb(origskb);
831 return ieee80211_clean_skb(origskb, present_fcs_len,
835 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
837 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
838 bool last_monitor = list_is_last(&sdata->u.mntr.list,
842 monskb = ieee80211_make_monitor_skb(local, &origskb,
854 skb = skb_clone(monskb, GFP_ATOMIC);
858 skb->dev = sdata->dev;
859 dev_sw_netstats_rx_add(skb->dev, skb->len);
860 netif_receive_skb(skb);
868 /* this happens if last_monitor was erroneously false */
869 dev_kfree_skb(monskb);
875 return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
878 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
880 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
881 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
882 int tid, seqno_idx, security_idx;
884 /* does the frame have a qos control field? */
885 if (ieee80211_is_data_qos(hdr->frame_control)) {
886 u8 *qc = ieee80211_get_qos_ctl(hdr);
887 /* frame has qos control */
888 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
889 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
890 status->rx_flags |= IEEE80211_RX_AMSDU;
896 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
898 * Sequence numbers for management frames, QoS data
899 * frames with a broadcast/multicast address in the
900 * Address 1 field, and all non-QoS data frames sent
901 * by QoS STAs are assigned using an additional single
902 * modulo-4096 counter, [...]
904 * We also use that counter for non-QoS STAs.
906 seqno_idx = IEEE80211_NUM_TIDS;
908 if (ieee80211_is_mgmt(hdr->frame_control))
909 security_idx = IEEE80211_NUM_TIDS;
913 rx->seqno_idx = seqno_idx;
914 rx->security_idx = security_idx;
915 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
916 * For now, set skb->priority to 0 for other cases. */
917 rx->skb->priority = (tid > 7) ? 0 : tid;
921 * DOC: Packet alignment
923 * Drivers always need to pass packets that are aligned to two-byte boundaries
926 * Additionally, should, if possible, align the payload data in a way that
927 * guarantees that the contained IP header is aligned to a four-byte
928 * boundary. In the case of regular frames, this simply means aligning the
929 * payload to a four-byte boundary (because either the IP header is directly
930 * contained, or IV/RFC1042 headers that have a length divisible by four are
931 * in front of it). If the payload data is not properly aligned and the
932 * architecture doesn't support efficient unaligned operations, mac80211
933 * will align the data.
935 * With A-MSDU frames, however, the payload data address must yield two modulo
936 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
937 * push the IP header further back to a multiple of four again. Thankfully, the
938 * specs were sane enough this time around to require padding each A-MSDU
939 * subframe to a length that is a multiple of four.
941 * Padding like Atheros hardware adds which is between the 802.11 header and
942 * the payload is not supported, the driver is required to move the 802.11
943 * header to be directly in front of the payload in that case.
945 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
947 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
948 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
955 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
957 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
959 if (is_multicast_ether_addr(hdr->addr1))
962 return ieee80211_is_robust_mgmt_frame(skb);
966 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
968 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
970 if (!is_multicast_ether_addr(hdr->addr1))
973 return ieee80211_is_robust_mgmt_frame(skb);
977 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
978 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
980 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
981 struct ieee80211_mmie *mmie;
982 struct ieee80211_mmie_16 *mmie16;
984 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
987 if (!ieee80211_is_robust_mgmt_frame(skb) &&
988 !ieee80211_is_beacon(hdr->frame_control))
989 return -1; /* not a robust management frame */
991 mmie = (struct ieee80211_mmie *)
992 (skb->data + skb->len - sizeof(*mmie));
993 if (mmie->element_id == WLAN_EID_MMIE &&
994 mmie->length == sizeof(*mmie) - 2)
995 return le16_to_cpu(mmie->key_id);
997 mmie16 = (struct ieee80211_mmie_16 *)
998 (skb->data + skb->len - sizeof(*mmie16));
999 if (skb->len >= 24 + sizeof(*mmie16) &&
1000 mmie16->element_id == WLAN_EID_MMIE &&
1001 mmie16->length == sizeof(*mmie16) - 2)
1002 return le16_to_cpu(mmie16->key_id);
1007 static int ieee80211_get_keyid(struct sk_buff *skb,
1008 const struct ieee80211_cipher_scheme *cs)
1010 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1018 fc = hdr->frame_control;
1019 hdrlen = ieee80211_hdrlen(fc);
1022 minlen = hdrlen + cs->hdr_len;
1023 key_idx_off = hdrlen + cs->key_idx_off;
1024 key_idx_shift = cs->key_idx_shift;
1026 /* WEP, TKIP, CCMP and GCMP */
1027 minlen = hdrlen + IEEE80211_WEP_IV_LEN;
1028 key_idx_off = hdrlen + 3;
1032 if (unlikely(skb->len < minlen))
1035 skb_copy_bits(skb, key_idx_off, &keyid, 1);
1038 keyid &= cs->key_idx_mask;
1039 keyid >>= key_idx_shift;
1041 /* cs could use more than the usual two bits for the keyid */
1042 if (unlikely(keyid >= NUM_DEFAULT_KEYS))
1048 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1050 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1051 char *dev_addr = rx->sdata->vif.addr;
1053 if (ieee80211_is_data(hdr->frame_control)) {
1054 if (is_multicast_ether_addr(hdr->addr1)) {
1055 if (ieee80211_has_tods(hdr->frame_control) ||
1056 !ieee80211_has_fromds(hdr->frame_control))
1057 return RX_DROP_MONITOR;
1058 if (ether_addr_equal(hdr->addr3, dev_addr))
1059 return RX_DROP_MONITOR;
1061 if (!ieee80211_has_a4(hdr->frame_control))
1062 return RX_DROP_MONITOR;
1063 if (ether_addr_equal(hdr->addr4, dev_addr))
1064 return RX_DROP_MONITOR;
1068 /* If there is not an established peer link and this is not a peer link
1069 * establisment frame, beacon or probe, drop the frame.
1072 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1073 struct ieee80211_mgmt *mgmt;
1075 if (!ieee80211_is_mgmt(hdr->frame_control))
1076 return RX_DROP_MONITOR;
1078 if (ieee80211_is_action(hdr->frame_control)) {
1081 /* make sure category field is present */
1082 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1083 return RX_DROP_MONITOR;
1085 mgmt = (struct ieee80211_mgmt *)hdr;
1086 category = mgmt->u.action.category;
1087 if (category != WLAN_CATEGORY_MESH_ACTION &&
1088 category != WLAN_CATEGORY_SELF_PROTECTED)
1089 return RX_DROP_MONITOR;
1093 if (ieee80211_is_probe_req(hdr->frame_control) ||
1094 ieee80211_is_probe_resp(hdr->frame_control) ||
1095 ieee80211_is_beacon(hdr->frame_control) ||
1096 ieee80211_is_auth(hdr->frame_control))
1099 return RX_DROP_MONITOR;
1105 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1108 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1109 struct sk_buff *tail = skb_peek_tail(frames);
1110 struct ieee80211_rx_status *status;
1112 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1118 status = IEEE80211_SKB_RXCB(tail);
1119 if (status->flag & RX_FLAG_AMSDU_MORE)
1125 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1126 struct tid_ampdu_rx *tid_agg_rx,
1128 struct sk_buff_head *frames)
1130 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1131 struct sk_buff *skb;
1132 struct ieee80211_rx_status *status;
1134 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1136 if (skb_queue_empty(skb_list))
1139 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1140 __skb_queue_purge(skb_list);
1144 /* release frames from the reorder ring buffer */
1145 tid_agg_rx->stored_mpdu_num--;
1146 while ((skb = __skb_dequeue(skb_list))) {
1147 status = IEEE80211_SKB_RXCB(skb);
1148 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1149 __skb_queue_tail(frames, skb);
1153 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1154 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1157 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1158 struct tid_ampdu_rx *tid_agg_rx,
1160 struct sk_buff_head *frames)
1164 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1166 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1167 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1168 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1174 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1175 * the skb was added to the buffer longer than this time ago, the earlier
1176 * frames that have not yet been received are assumed to be lost and the skb
1177 * can be released for processing. This may also release other skb's from the
1178 * reorder buffer if there are no additional gaps between the frames.
1180 * Callers must hold tid_agg_rx->reorder_lock.
1182 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1184 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1185 struct tid_ampdu_rx *tid_agg_rx,
1186 struct sk_buff_head *frames)
1190 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1192 /* release the buffer until next missing frame */
1193 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1194 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1195 tid_agg_rx->stored_mpdu_num) {
1197 * No buffers ready to be released, but check whether any
1198 * frames in the reorder buffer have timed out.
1201 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1202 j = (j + 1) % tid_agg_rx->buf_size) {
1203 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1208 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1209 HT_RX_REORDER_BUF_TIMEOUT))
1210 goto set_release_timer;
1212 /* don't leave incomplete A-MSDUs around */
1213 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1214 i = (i + 1) % tid_agg_rx->buf_size)
1215 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1217 ht_dbg_ratelimited(sdata,
1218 "release an RX reorder frame due to timeout on earlier frames\n");
1219 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1223 * Increment the head seq# also for the skipped slots.
1225 tid_agg_rx->head_seq_num =
1226 (tid_agg_rx->head_seq_num +
1227 skipped) & IEEE80211_SN_MASK;
1230 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1231 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1233 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1236 if (tid_agg_rx->stored_mpdu_num) {
1237 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1239 for (; j != (index - 1) % tid_agg_rx->buf_size;
1240 j = (j + 1) % tid_agg_rx->buf_size) {
1241 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1247 if (!tid_agg_rx->removed)
1248 mod_timer(&tid_agg_rx->reorder_timer,
1249 tid_agg_rx->reorder_time[j] + 1 +
1250 HT_RX_REORDER_BUF_TIMEOUT);
1252 del_timer(&tid_agg_rx->reorder_timer);
1257 * As this function belongs to the RX path it must be under
1258 * rcu_read_lock protection. It returns false if the frame
1259 * can be processed immediately, true if it was consumed.
1261 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1262 struct tid_ampdu_rx *tid_agg_rx,
1263 struct sk_buff *skb,
1264 struct sk_buff_head *frames)
1266 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1267 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1268 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1269 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1270 u16 head_seq_num, buf_size;
1274 spin_lock(&tid_agg_rx->reorder_lock);
1277 * Offloaded BA sessions have no known starting sequence number so pick
1278 * one from first Rxed frame for this tid after BA was started.
1280 if (unlikely(tid_agg_rx->auto_seq)) {
1281 tid_agg_rx->auto_seq = false;
1282 tid_agg_rx->ssn = mpdu_seq_num;
1283 tid_agg_rx->head_seq_num = mpdu_seq_num;
1286 buf_size = tid_agg_rx->buf_size;
1287 head_seq_num = tid_agg_rx->head_seq_num;
1290 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1293 if (unlikely(!tid_agg_rx->started)) {
1294 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1298 tid_agg_rx->started = true;
1301 /* frame with out of date sequence number */
1302 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1308 * If frame the sequence number exceeds our buffering window
1309 * size release some previous frames to make room for this one.
1311 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1312 head_seq_num = ieee80211_sn_inc(
1313 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1314 /* release stored frames up to new head to stack */
1315 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1316 head_seq_num, frames);
1319 /* Now the new frame is always in the range of the reordering buffer */
1321 index = mpdu_seq_num % tid_agg_rx->buf_size;
1323 /* check if we already stored this frame */
1324 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1330 * If the current MPDU is in the right order and nothing else
1331 * is stored we can process it directly, no need to buffer it.
1332 * If it is first but there's something stored, we may be able
1333 * to release frames after this one.
1335 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1336 tid_agg_rx->stored_mpdu_num == 0) {
1337 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1338 tid_agg_rx->head_seq_num =
1339 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1344 /* put the frame in the reordering buffer */
1345 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1346 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1347 tid_agg_rx->reorder_time[index] = jiffies;
1348 tid_agg_rx->stored_mpdu_num++;
1349 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1353 spin_unlock(&tid_agg_rx->reorder_lock);
1358 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1359 * true if the MPDU was buffered, false if it should be processed.
1361 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1362 struct sk_buff_head *frames)
1364 struct sk_buff *skb = rx->skb;
1365 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1366 struct sta_info *sta = rx->sta;
1367 struct tid_ampdu_rx *tid_agg_rx;
1371 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1372 is_multicast_ether_addr(hdr->addr1))
1376 * filter the QoS data rx stream according to
1377 * STA/TID and check if this STA/TID is on aggregation
1383 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1384 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1385 tid = ieee80211_get_tid(hdr);
1387 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1389 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1390 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1391 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1392 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1393 WLAN_BACK_RECIPIENT,
1394 WLAN_REASON_QSTA_REQUIRE_SETUP);
1398 /* qos null data frames are excluded */
1399 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1402 /* not part of a BA session */
1403 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1404 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1407 /* new, potentially un-ordered, ampdu frame - process it */
1409 /* reset session timer */
1410 if (tid_agg_rx->timeout)
1411 tid_agg_rx->last_rx = jiffies;
1413 /* if this mpdu is fragmented - terminate rx aggregation session */
1414 sc = le16_to_cpu(hdr->seq_ctrl);
1415 if (sc & IEEE80211_SCTL_FRAG) {
1416 ieee80211_queue_skb_to_iface(rx->sdata, NULL, skb);
1421 * No locking needed -- we will only ever process one
1422 * RX packet at a time, and thus own tid_agg_rx. All
1423 * other code manipulating it needs to (and does) make
1424 * sure that we cannot get to it any more before doing
1427 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1432 __skb_queue_tail(frames, skb);
1435 static ieee80211_rx_result debug_noinline
1436 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1438 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1439 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1441 if (status->flag & RX_FLAG_DUP_VALIDATED)
1445 * Drop duplicate 802.11 retransmissions
1446 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1449 if (rx->skb->len < 24)
1452 if (ieee80211_is_ctl(hdr->frame_control) ||
1453 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1454 is_multicast_ether_addr(hdr->addr1))
1460 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1461 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1462 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1463 rx->sta->rx_stats.num_duplicates++;
1464 return RX_DROP_UNUSABLE;
1465 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1466 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1472 static ieee80211_rx_result debug_noinline
1473 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1475 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1477 /* Drop disallowed frame classes based on STA auth/assoc state;
1478 * IEEE 802.11, Chap 5.5.
1480 * mac80211 filters only based on association state, i.e. it drops
1481 * Class 3 frames from not associated stations. hostapd sends
1482 * deauth/disassoc frames when needed. In addition, hostapd is
1483 * responsible for filtering on both auth and assoc states.
1486 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1487 return ieee80211_rx_mesh_check(rx);
1489 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1490 ieee80211_is_pspoll(hdr->frame_control)) &&
1491 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1492 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1493 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1495 * accept port control frames from the AP even when it's not
1496 * yet marked ASSOC to prevent a race where we don't set the
1497 * assoc bit quickly enough before it sends the first frame
1499 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1500 ieee80211_is_data_present(hdr->frame_control)) {
1501 unsigned int hdrlen;
1504 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1506 if (rx->skb->len < hdrlen + 8)
1507 return RX_DROP_MONITOR;
1509 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1510 if (ethertype == rx->sdata->control_port_protocol)
1514 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1515 cfg80211_rx_spurious_frame(rx->sdata->dev,
1518 return RX_DROP_UNUSABLE;
1520 return RX_DROP_MONITOR;
1527 static ieee80211_rx_result debug_noinline
1528 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1530 struct ieee80211_local *local;
1531 struct ieee80211_hdr *hdr;
1532 struct sk_buff *skb;
1536 hdr = (struct ieee80211_hdr *) skb->data;
1538 if (!local->pspolling)
1541 if (!ieee80211_has_fromds(hdr->frame_control))
1542 /* this is not from AP */
1545 if (!ieee80211_is_data(hdr->frame_control))
1548 if (!ieee80211_has_moredata(hdr->frame_control)) {
1549 /* AP has no more frames buffered for us */
1550 local->pspolling = false;
1554 /* more data bit is set, let's request a new frame from the AP */
1555 ieee80211_send_pspoll(local, rx->sdata);
1560 static void sta_ps_start(struct sta_info *sta)
1562 struct ieee80211_sub_if_data *sdata = sta->sdata;
1563 struct ieee80211_local *local = sdata->local;
1567 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1568 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1569 ps = &sdata->bss->ps;
1573 atomic_inc(&ps->num_sta_ps);
1574 set_sta_flag(sta, WLAN_STA_PS_STA);
1575 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1576 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1577 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1578 sta->sta.addr, sta->sta.aid);
1580 ieee80211_clear_fast_xmit(sta);
1582 if (!sta->sta.txq[0])
1585 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1586 struct ieee80211_txq *txq = sta->sta.txq[tid];
1588 ieee80211_unschedule_txq(&local->hw, txq, false);
1590 if (txq_has_queue(txq))
1591 set_bit(tid, &sta->txq_buffered_tids);
1593 clear_bit(tid, &sta->txq_buffered_tids);
1597 static void sta_ps_end(struct sta_info *sta)
1599 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1600 sta->sta.addr, sta->sta.aid);
1602 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1604 * Clear the flag only if the other one is still set
1605 * so that the TX path won't start TX'ing new frames
1606 * directly ... In the case that the driver flag isn't
1607 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1609 clear_sta_flag(sta, WLAN_STA_PS_STA);
1610 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1611 sta->sta.addr, sta->sta.aid);
1615 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1616 clear_sta_flag(sta, WLAN_STA_PS_STA);
1617 ieee80211_sta_ps_deliver_wakeup(sta);
1620 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1622 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1625 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1627 /* Don't let the same PS state be set twice */
1628 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1629 if ((start && in_ps) || (!start && !in_ps))
1639 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1641 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1643 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1645 if (test_sta_flag(sta, WLAN_STA_SP))
1648 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1649 ieee80211_sta_ps_deliver_poll_response(sta);
1651 set_sta_flag(sta, WLAN_STA_PSPOLL);
1653 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1655 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1657 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1658 int ac = ieee80211_ac_from_tid(tid);
1661 * If this AC is not trigger-enabled do nothing unless the
1662 * driver is calling us after it already checked.
1664 * NB: This could/should check a separate bitmap of trigger-
1665 * enabled queues, but for now we only implement uAPSD w/o
1666 * TSPEC changes to the ACs, so they're always the same.
1668 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1669 tid != IEEE80211_NUM_TIDS)
1672 /* if we are in a service period, do nothing */
1673 if (test_sta_flag(sta, WLAN_STA_SP))
1676 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1677 ieee80211_sta_ps_deliver_uapsd(sta);
1679 set_sta_flag(sta, WLAN_STA_UAPSD);
1681 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1683 static ieee80211_rx_result debug_noinline
1684 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1686 struct ieee80211_sub_if_data *sdata = rx->sdata;
1687 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1688 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1693 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1694 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1698 * The device handles station powersave, so don't do anything about
1699 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1700 * it to mac80211 since they're handled.)
1702 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1706 * Don't do anything if the station isn't already asleep. In
1707 * the uAPSD case, the station will probably be marked asleep,
1708 * in the PS-Poll case the station must be confused ...
1710 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1713 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1714 ieee80211_sta_pspoll(&rx->sta->sta);
1716 /* Free PS Poll skb here instead of returning RX_DROP that would
1717 * count as an dropped frame. */
1718 dev_kfree_skb(rx->skb);
1721 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1722 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1723 ieee80211_has_pm(hdr->frame_control) &&
1724 (ieee80211_is_data_qos(hdr->frame_control) ||
1725 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1726 u8 tid = ieee80211_get_tid(hdr);
1728 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1734 static ieee80211_rx_result debug_noinline
1735 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1737 struct sta_info *sta = rx->sta;
1738 struct sk_buff *skb = rx->skb;
1739 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1740 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1747 * Update last_rx only for IBSS packets which are for the current
1748 * BSSID and for station already AUTHORIZED to avoid keeping the
1749 * current IBSS network alive in cases where other STAs start
1750 * using different BSSID. This will also give the station another
1751 * chance to restart the authentication/authorization in case
1752 * something went wrong the first time.
1754 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1755 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1756 NL80211_IFTYPE_ADHOC);
1757 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1758 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1759 sta->rx_stats.last_rx = jiffies;
1760 if (ieee80211_is_data(hdr->frame_control) &&
1761 !is_multicast_ether_addr(hdr->addr1))
1762 sta->rx_stats.last_rate =
1763 sta_stats_encode_rate(status);
1765 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1766 sta->rx_stats.last_rx = jiffies;
1767 } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
1768 !is_multicast_ether_addr(hdr->addr1)) {
1770 * Mesh beacons will update last_rx when if they are found to
1771 * match the current local configuration when processed.
1773 sta->rx_stats.last_rx = jiffies;
1774 if (ieee80211_is_data(hdr->frame_control))
1775 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1778 sta->rx_stats.fragments++;
1780 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1781 sta->rx_stats.bytes += rx->skb->len;
1782 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1784 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1785 sta->rx_stats.last_signal = status->signal;
1786 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1789 if (status->chains) {
1790 sta->rx_stats.chains = status->chains;
1791 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1792 int signal = status->chain_signal[i];
1794 if (!(status->chains & BIT(i)))
1797 sta->rx_stats.chain_signal_last[i] = signal;
1798 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1803 if (ieee80211_is_s1g_beacon(hdr->frame_control))
1807 * Change STA power saving mode only at the end of a frame
1808 * exchange sequence, and only for a data or management
1809 * frame as specified in IEEE 802.11-2016 11.2.3.2
1811 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1812 !ieee80211_has_morefrags(hdr->frame_control) &&
1813 !is_multicast_ether_addr(hdr->addr1) &&
1814 (ieee80211_is_mgmt(hdr->frame_control) ||
1815 ieee80211_is_data(hdr->frame_control)) &&
1816 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1817 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1818 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1819 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1820 if (!ieee80211_has_pm(hdr->frame_control))
1823 if (ieee80211_has_pm(hdr->frame_control))
1828 /* mesh power save support */
1829 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1830 ieee80211_mps_rx_h_sta_process(sta, hdr);
1833 * Drop (qos-)data::nullfunc frames silently, since they
1834 * are used only to control station power saving mode.
1836 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1837 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1840 * If we receive a 4-addr nullfunc frame from a STA
1841 * that was not moved to a 4-addr STA vlan yet send
1842 * the event to userspace and for older hostapd drop
1843 * the frame to the monitor interface.
1845 if (ieee80211_has_a4(hdr->frame_control) &&
1846 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1847 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1848 !rx->sdata->u.vlan.sta))) {
1849 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1850 cfg80211_rx_unexpected_4addr_frame(
1851 rx->sdata->dev, sta->sta.addr,
1853 return RX_DROP_MONITOR;
1856 * Update counter and free packet here to avoid
1857 * counting this as a dropped packed.
1859 sta->rx_stats.packets++;
1860 dev_kfree_skb(rx->skb);
1865 } /* ieee80211_rx_h_sta_process */
1867 static struct ieee80211_key *
1868 ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
1870 struct ieee80211_key *key = NULL;
1871 struct ieee80211_sub_if_data *sdata = rx->sdata;
1874 /* Make sure key gets set if either BIGTK key index is set so that
1875 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1876 * Beacon frames and Beacon frames that claim to use another BIGTK key
1877 * index (i.e., a key that we do not have).
1881 idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1884 if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1891 key = rcu_dereference(rx->sta->gtk[idx]);
1893 key = rcu_dereference(sdata->keys[idx]);
1894 if (!key && rx->sta)
1895 key = rcu_dereference(rx->sta->gtk[idx2]);
1897 key = rcu_dereference(sdata->keys[idx2]);
1902 static ieee80211_rx_result debug_noinline
1903 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1905 struct sk_buff *skb = rx->skb;
1906 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1907 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1909 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1910 struct ieee80211_key *sta_ptk = NULL;
1911 struct ieee80211_key *ptk_idx = NULL;
1912 int mmie_keyidx = -1;
1914 const struct ieee80211_cipher_scheme *cs = NULL;
1916 if (ieee80211_is_ext(hdr->frame_control))
1922 * There are five types of keys:
1923 * - GTK (group keys)
1924 * - IGTK (group keys for management frames)
1925 * - BIGTK (group keys for Beacon frames)
1926 * - PTK (pairwise keys)
1927 * - STK (station-to-station pairwise keys)
1929 * When selecting a key, we have to distinguish between multicast
1930 * (including broadcast) and unicast frames, the latter can only
1931 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1932 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1933 * then unicast frames can also use key indices like GTKs. Hence, if we
1934 * don't have a PTK/STK we check the key index for a WEP key.
1936 * Note that in a regular BSS, multicast frames are sent by the
1937 * AP only, associated stations unicast the frame to the AP first
1938 * which then multicasts it on their behalf.
1940 * There is also a slight problem in IBSS mode: GTKs are negotiated
1941 * with each station, that is something we don't currently handle.
1942 * The spec seems to expect that one negotiates the same key with
1943 * every station but there's no such requirement; VLANs could be
1947 /* start without a key */
1949 fc = hdr->frame_control;
1952 int keyid = rx->sta->ptk_idx;
1953 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1955 if (ieee80211_has_protected(fc) &&
1956 !(status->flag & RX_FLAG_IV_STRIPPED)) {
1957 cs = rx->sta->cipher_scheme;
1958 keyid = ieee80211_get_keyid(rx->skb, cs);
1960 if (unlikely(keyid < 0))
1961 return RX_DROP_UNUSABLE;
1963 ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1967 if (!ieee80211_has_protected(fc))
1968 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1970 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1971 rx->key = ptk_idx ? ptk_idx : sta_ptk;
1972 if ((status->flag & RX_FLAG_DECRYPTED) &&
1973 (status->flag & RX_FLAG_IV_STRIPPED))
1975 /* Skip decryption if the frame is not protected. */
1976 if (!ieee80211_has_protected(fc))
1978 } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
1979 /* Broadcast/multicast robust management frame / BIP */
1980 if ((status->flag & RX_FLAG_DECRYPTED) &&
1981 (status->flag & RX_FLAG_IV_STRIPPED))
1984 if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
1985 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
1986 NUM_DEFAULT_BEACON_KEYS) {
1987 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1990 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1993 rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
1995 return RX_CONTINUE; /* Beacon protection not in use */
1996 } else if (mmie_keyidx >= 0) {
1997 /* Broadcast/multicast robust management frame / BIP */
1998 if ((status->flag & RX_FLAG_DECRYPTED) &&
1999 (status->flag & RX_FLAG_IV_STRIPPED))
2002 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
2003 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
2004 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
2006 if (ieee80211_is_group_privacy_action(skb) &&
2007 test_sta_flag(rx->sta, WLAN_STA_MFP))
2008 return RX_DROP_MONITOR;
2010 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
2013 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
2014 } else if (!ieee80211_has_protected(fc)) {
2016 * The frame was not protected, so skip decryption. However, we
2017 * need to set rx->key if there is a key that could have been
2018 * used so that the frame may be dropped if encryption would
2019 * have been expected.
2021 struct ieee80211_key *key = NULL;
2022 struct ieee80211_sub_if_data *sdata = rx->sdata;
2025 if (ieee80211_is_beacon(fc)) {
2026 key = ieee80211_rx_get_bigtk(rx, -1);
2027 } else if (ieee80211_is_mgmt(fc) &&
2028 is_multicast_ether_addr(hdr->addr1)) {
2029 key = rcu_dereference(rx->sdata->default_mgmt_key);
2032 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2033 key = rcu_dereference(rx->sta->gtk[i]);
2039 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2040 key = rcu_dereference(sdata->keys[i]);
2051 * The device doesn't give us the IV so we won't be
2052 * able to look up the key. That's ok though, we
2053 * don't need to decrypt the frame, we just won't
2054 * be able to keep statistics accurate.
2055 * Except for key threshold notifications, should
2056 * we somehow allow the driver to tell us which key
2057 * the hardware used if this flag is set?
2059 if ((status->flag & RX_FLAG_DECRYPTED) &&
2060 (status->flag & RX_FLAG_IV_STRIPPED))
2063 keyidx = ieee80211_get_keyid(rx->skb, cs);
2065 if (unlikely(keyidx < 0))
2066 return RX_DROP_UNUSABLE;
2068 /* check per-station GTK first, if multicast packet */
2069 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
2070 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
2072 /* if not found, try default key */
2074 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
2077 * RSNA-protected unicast frames should always be
2078 * sent with pairwise or station-to-station keys,
2079 * but for WEP we allow using a key index as well.
2082 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2083 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2084 !is_multicast_ether_addr(hdr->addr1))
2090 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2091 return RX_DROP_MONITOR;
2093 /* TODO: add threshold stuff again */
2095 return RX_DROP_MONITOR;
2098 switch (rx->key->conf.cipher) {
2099 case WLAN_CIPHER_SUITE_WEP40:
2100 case WLAN_CIPHER_SUITE_WEP104:
2101 result = ieee80211_crypto_wep_decrypt(rx);
2103 case WLAN_CIPHER_SUITE_TKIP:
2104 result = ieee80211_crypto_tkip_decrypt(rx);
2106 case WLAN_CIPHER_SUITE_CCMP:
2107 result = ieee80211_crypto_ccmp_decrypt(
2108 rx, IEEE80211_CCMP_MIC_LEN);
2110 case WLAN_CIPHER_SUITE_CCMP_256:
2111 result = ieee80211_crypto_ccmp_decrypt(
2112 rx, IEEE80211_CCMP_256_MIC_LEN);
2114 case WLAN_CIPHER_SUITE_AES_CMAC:
2115 result = ieee80211_crypto_aes_cmac_decrypt(rx);
2117 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2118 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2120 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2121 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2122 result = ieee80211_crypto_aes_gmac_decrypt(rx);
2124 case WLAN_CIPHER_SUITE_GCMP:
2125 case WLAN_CIPHER_SUITE_GCMP_256:
2126 result = ieee80211_crypto_gcmp_decrypt(rx);
2129 result = ieee80211_crypto_hw_decrypt(rx);
2132 /* the hdr variable is invalid after the decrypt handlers */
2134 /* either the frame has been decrypted or will be dropped */
2135 status->flag |= RX_FLAG_DECRYPTED;
2137 if (unlikely(ieee80211_is_beacon(fc) && result == RX_DROP_UNUSABLE))
2138 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2139 skb->data, skb->len);
2144 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2148 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2149 skb_queue_head_init(&cache->entries[i].skb_list);
2152 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2156 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2157 __skb_queue_purge(&cache->entries[i].skb_list);
2160 static inline struct ieee80211_fragment_entry *
2161 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2162 unsigned int frag, unsigned int seq, int rx_queue,
2163 struct sk_buff **skb)
2165 struct ieee80211_fragment_entry *entry;
2167 entry = &cache->entries[cache->next++];
2168 if (cache->next >= IEEE80211_FRAGMENT_MAX)
2171 __skb_queue_purge(&entry->skb_list);
2173 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2175 entry->first_frag_time = jiffies;
2177 entry->rx_queue = rx_queue;
2178 entry->last_frag = frag;
2179 entry->check_sequential_pn = false;
2180 entry->extra_len = 0;
2185 static inline struct ieee80211_fragment_entry *
2186 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2187 unsigned int frag, unsigned int seq,
2188 int rx_queue, struct ieee80211_hdr *hdr)
2190 struct ieee80211_fragment_entry *entry;
2194 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2195 struct ieee80211_hdr *f_hdr;
2196 struct sk_buff *f_skb;
2200 idx = IEEE80211_FRAGMENT_MAX - 1;
2202 entry = &cache->entries[idx];
2203 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2204 entry->rx_queue != rx_queue ||
2205 entry->last_frag + 1 != frag)
2208 f_skb = __skb_peek(&entry->skb_list);
2209 f_hdr = (struct ieee80211_hdr *) f_skb->data;
2212 * Check ftype and addresses are equal, else check next fragment
2214 if (((hdr->frame_control ^ f_hdr->frame_control) &
2215 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2216 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2217 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2220 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2221 __skb_queue_purge(&entry->skb_list);
2230 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2233 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2234 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2235 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2236 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2237 ieee80211_has_protected(fc);
2240 static ieee80211_rx_result debug_noinline
2241 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2243 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2244 struct ieee80211_hdr *hdr;
2247 unsigned int frag, seq;
2248 struct ieee80211_fragment_entry *entry;
2249 struct sk_buff *skb;
2250 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2252 hdr = (struct ieee80211_hdr *)rx->skb->data;
2253 fc = hdr->frame_control;
2255 if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
2258 sc = le16_to_cpu(hdr->seq_ctrl);
2259 frag = sc & IEEE80211_SCTL_FRAG;
2262 cache = &rx->sta->frags;
2264 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2267 if (is_multicast_ether_addr(hdr->addr1))
2268 return RX_DROP_MONITOR;
2270 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2272 if (skb_linearize(rx->skb))
2273 return RX_DROP_UNUSABLE;
2276 * skb_linearize() might change the skb->data and
2277 * previously cached variables (in this case, hdr) need to
2278 * be refreshed with the new data.
2280 hdr = (struct ieee80211_hdr *)rx->skb->data;
2281 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2284 /* This is the first fragment of a new frame. */
2285 entry = ieee80211_reassemble_add(cache, frag, seq,
2286 rx->seqno_idx, &(rx->skb));
2287 if (requires_sequential_pn(rx, fc)) {
2288 int queue = rx->security_idx;
2290 /* Store CCMP/GCMP PN so that we can verify that the
2291 * next fragment has a sequential PN value.
2293 entry->check_sequential_pn = true;
2294 entry->is_protected = true;
2295 entry->key_color = rx->key->color;
2296 memcpy(entry->last_pn,
2297 rx->key->u.ccmp.rx_pn[queue],
2298 IEEE80211_CCMP_PN_LEN);
2299 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2301 offsetof(struct ieee80211_key,
2303 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2304 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2305 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2306 IEEE80211_GCMP_PN_LEN);
2307 } else if (rx->key &&
2308 (ieee80211_has_protected(fc) ||
2309 (status->flag & RX_FLAG_DECRYPTED))) {
2310 entry->is_protected = true;
2311 entry->key_color = rx->key->color;
2316 /* This is a fragment for a frame that should already be pending in
2317 * fragment cache. Add this fragment to the end of the pending entry.
2319 entry = ieee80211_reassemble_find(cache, frag, seq,
2320 rx->seqno_idx, hdr);
2322 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2323 return RX_DROP_MONITOR;
2326 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2327 * MPDU PN values are not incrementing in steps of 1."
2328 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2329 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2331 if (entry->check_sequential_pn) {
2333 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2335 if (!requires_sequential_pn(rx, fc))
2336 return RX_DROP_UNUSABLE;
2338 /* Prevent mixed key and fragment cache attacks */
2339 if (entry->key_color != rx->key->color)
2340 return RX_DROP_UNUSABLE;
2342 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2343 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2349 rpn = rx->ccm_gcm.pn;
2350 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2351 return RX_DROP_UNUSABLE;
2352 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2353 } else if (entry->is_protected &&
2355 (!ieee80211_has_protected(fc) &&
2356 !(status->flag & RX_FLAG_DECRYPTED)) ||
2357 rx->key->color != entry->key_color)) {
2358 /* Drop this as a mixed key or fragment cache attack, even
2359 * if for TKIP Michael MIC should protect us, and WEP is a
2360 * lost cause anyway.
2362 return RX_DROP_UNUSABLE;
2363 } else if (entry->is_protected && rx->key &&
2364 entry->key_color != rx->key->color &&
2365 (status->flag & RX_FLAG_DECRYPTED)) {
2366 return RX_DROP_UNUSABLE;
2369 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2370 __skb_queue_tail(&entry->skb_list, rx->skb);
2371 entry->last_frag = frag;
2372 entry->extra_len += rx->skb->len;
2373 if (ieee80211_has_morefrags(fc)) {
2378 rx->skb = __skb_dequeue(&entry->skb_list);
2379 if (skb_tailroom(rx->skb) < entry->extra_len) {
2380 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2381 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2383 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2384 __skb_queue_purge(&entry->skb_list);
2385 return RX_DROP_UNUSABLE;
2388 while ((skb = __skb_dequeue(&entry->skb_list))) {
2389 skb_put_data(rx->skb, skb->data, skb->len);
2394 ieee80211_led_rx(rx->local);
2396 rx->sta->rx_stats.packets++;
2400 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2402 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2408 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2410 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
2411 struct sk_buff *skb = rx->skb;
2412 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2415 * Pass through unencrypted frames if the hardware has
2416 * decrypted them already.
2418 if (status->flag & RX_FLAG_DECRYPTED)
2421 /* check mesh EAPOL frames first */
2422 if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
2423 ieee80211_is_data(fc))) {
2424 struct ieee80211s_hdr *mesh_hdr;
2425 u16 hdr_len = ieee80211_hdrlen(fc);
2426 u16 ethertype_offset;
2429 if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
2432 /* make sure fixed part of mesh header is there, also checks skb len */
2433 if (!pskb_may_pull(rx->skb, hdr_len + 6))
2436 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
2437 ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
2438 sizeof(rfc1042_header);
2440 if (skb_copy_bits(rx->skb, ethertype_offset, ðertype, 2) == 0 &&
2441 ethertype == rx->sdata->control_port_protocol)
2446 /* Drop unencrypted frames if key is set. */
2447 if (unlikely(!ieee80211_has_protected(fc) &&
2448 !ieee80211_is_any_nullfunc(fc) &&
2449 ieee80211_is_data(fc) && rx->key))
2455 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2457 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2458 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2459 __le16 fc = hdr->frame_control;
2462 * Pass through unencrypted frames if the hardware has
2463 * decrypted them already.
2465 if (status->flag & RX_FLAG_DECRYPTED)
2468 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2469 if (unlikely(!ieee80211_has_protected(fc) &&
2470 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2472 if (ieee80211_is_deauth(fc) ||
2473 ieee80211_is_disassoc(fc))
2474 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2479 /* BIP does not use Protected field, so need to check MMIE */
2480 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2481 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2482 if (ieee80211_is_deauth(fc) ||
2483 ieee80211_is_disassoc(fc))
2484 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2489 if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
2490 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2491 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2497 * When using MFP, Action frames are not allowed prior to
2498 * having configured keys.
2500 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2501 ieee80211_is_robust_mgmt_frame(rx->skb)))
2509 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2511 struct ieee80211_sub_if_data *sdata = rx->sdata;
2512 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2513 bool check_port_control = false;
2514 struct ethhdr *ehdr;
2517 *port_control = false;
2518 if (ieee80211_has_a4(hdr->frame_control) &&
2519 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2522 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2523 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2525 if (!sdata->u.mgd.use_4addr)
2527 else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2528 check_port_control = true;
2531 if (is_multicast_ether_addr(hdr->addr1) &&
2532 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2535 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2539 ehdr = (struct ethhdr *) rx->skb->data;
2540 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2541 *port_control = true;
2542 else if (check_port_control)
2549 * requires that rx->skb is a frame with ethernet header
2551 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2553 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2554 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2555 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2558 * Allow EAPOL frames to us/the PAE group address regardless of
2559 * whether the frame was encrypted or not, and always disallow
2560 * all other destination addresses for them.
2562 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2563 return ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2564 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2566 if (ieee80211_802_1x_port_control(rx) ||
2567 ieee80211_drop_unencrypted(rx, fc))
2573 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2574 struct ieee80211_rx_data *rx)
2576 struct ieee80211_sub_if_data *sdata = rx->sdata;
2577 struct net_device *dev = sdata->dev;
2579 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2580 (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
2581 !sdata->control_port_no_preauth)) &&
2582 sdata->control_port_over_nl80211)) {
2583 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2584 bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2586 cfg80211_rx_control_port(dev, skb, noencrypt);
2589 struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2591 memset(skb->cb, 0, sizeof(skb->cb));
2594 * 802.1X over 802.11 requires that the authenticator address
2595 * be used for EAPOL frames. However, 802.1X allows the use of
2596 * the PAE group address instead. If the interface is part of
2597 * a bridge and we pass the frame with the PAE group address,
2598 * then the bridge will forward it to the network (even if the
2599 * client was not associated yet), which isn't supposed to
2601 * To avoid that, rewrite the destination address to our own
2602 * address, so that the authenticator (e.g. hostapd) will see
2603 * the frame, but bridge won't forward it anywhere else. Note
2604 * that due to earlier filtering, the only other address can
2605 * be the PAE group address.
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->sta->rx_stats.syncp);
2643 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2644 u64_stats_update_end(&rx->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 debug_noinline
2724 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2726 struct net_device *dev = rx->sdata->dev;
2727 struct sk_buff *skb = rx->skb;
2728 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2729 __le16 fc = hdr->frame_control;
2730 struct sk_buff_head frame_list;
2731 struct ethhdr ethhdr;
2732 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2734 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2737 } else switch (rx->sdata->vif.type) {
2738 case NL80211_IFTYPE_AP:
2739 case NL80211_IFTYPE_AP_VLAN:
2742 case NL80211_IFTYPE_STATION:
2744 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2747 case NL80211_IFTYPE_MESH_POINT:
2755 __skb_queue_head_init(&frame_list);
2757 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2758 rx->sdata->vif.addr,
2759 rx->sdata->vif.type,
2761 return RX_DROP_UNUSABLE;
2763 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2764 rx->sdata->vif.type,
2765 rx->local->hw.extra_tx_headroom,
2766 check_da, check_sa);
2768 while (!skb_queue_empty(&frame_list)) {
2769 rx->skb = __skb_dequeue(&frame_list);
2771 if (!ieee80211_frame_allowed(rx, fc)) {
2772 dev_kfree_skb(rx->skb);
2776 ieee80211_deliver_skb(rx);
2782 static ieee80211_rx_result debug_noinline
2783 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2785 struct sk_buff *skb = rx->skb;
2786 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2787 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2788 __le16 fc = hdr->frame_control;
2790 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2793 if (unlikely(!ieee80211_is_data(fc)))
2796 if (unlikely(!ieee80211_is_data_present(fc)))
2797 return RX_DROP_MONITOR;
2799 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2800 switch (rx->sdata->vif.type) {
2801 case NL80211_IFTYPE_AP_VLAN:
2802 if (!rx->sdata->u.vlan.sta)
2803 return RX_DROP_UNUSABLE;
2805 case NL80211_IFTYPE_STATION:
2806 if (!rx->sdata->u.mgd.use_4addr)
2807 return RX_DROP_UNUSABLE;
2810 return RX_DROP_UNUSABLE;
2814 if (is_multicast_ether_addr(hdr->addr1))
2815 return RX_DROP_UNUSABLE;
2819 * We should not receive A-MSDUs on pre-HT connections,
2820 * and HT connections cannot use old ciphers. Thus drop
2821 * them, as in those cases we couldn't even have SPP
2824 switch (rx->key->conf.cipher) {
2825 case WLAN_CIPHER_SUITE_WEP40:
2826 case WLAN_CIPHER_SUITE_WEP104:
2827 case WLAN_CIPHER_SUITE_TKIP:
2828 return RX_DROP_UNUSABLE;
2834 return __ieee80211_rx_h_amsdu(rx, 0);
2837 #ifdef CONFIG_MAC80211_MESH
2838 static ieee80211_rx_result
2839 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2841 struct ieee80211_hdr *fwd_hdr, *hdr;
2842 struct ieee80211_tx_info *info;
2843 struct ieee80211s_hdr *mesh_hdr;
2844 struct sk_buff *skb = rx->skb, *fwd_skb;
2845 struct ieee80211_local *local = rx->local;
2846 struct ieee80211_sub_if_data *sdata = rx->sdata;
2847 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2851 hdr = (struct ieee80211_hdr *) skb->data;
2852 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2854 /* make sure fixed part of mesh header is there, also checks skb len */
2855 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2856 return RX_DROP_MONITOR;
2858 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2860 /* make sure full mesh header is there, also checks skb len */
2861 if (!pskb_may_pull(rx->skb,
2862 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2863 return RX_DROP_MONITOR;
2865 /* reload pointers */
2866 hdr = (struct ieee80211_hdr *) skb->data;
2867 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2869 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2870 return RX_DROP_MONITOR;
2872 /* frame is in RMC, don't forward */
2873 if (ieee80211_is_data(hdr->frame_control) &&
2874 is_multicast_ether_addr(hdr->addr1) &&
2875 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2876 return RX_DROP_MONITOR;
2878 if (!ieee80211_is_data(hdr->frame_control))
2882 return RX_DROP_MONITOR;
2884 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2885 struct mesh_path *mppath;
2889 if (is_multicast_ether_addr(hdr->addr1)) {
2890 mpp_addr = hdr->addr3;
2891 proxied_addr = mesh_hdr->eaddr1;
2892 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2893 MESH_FLAGS_AE_A5_A6) {
2894 /* has_a4 already checked in ieee80211_rx_mesh_check */
2895 mpp_addr = hdr->addr4;
2896 proxied_addr = mesh_hdr->eaddr2;
2898 return RX_DROP_MONITOR;
2902 mppath = mpp_path_lookup(sdata, proxied_addr);
2904 mpp_path_add(sdata, proxied_addr, mpp_addr);
2906 spin_lock_bh(&mppath->state_lock);
2907 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2908 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2909 mppath->exp_time = jiffies;
2910 spin_unlock_bh(&mppath->state_lock);
2915 /* Frame has reached destination. Don't forward */
2916 if (!is_multicast_ether_addr(hdr->addr1) &&
2917 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2920 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2921 q = sdata->vif.hw_queue[ac];
2922 if (ieee80211_queue_stopped(&local->hw, q)) {
2923 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2924 return RX_DROP_MONITOR;
2926 skb_set_queue_mapping(skb, q);
2928 if (!--mesh_hdr->ttl) {
2929 if (!is_multicast_ether_addr(hdr->addr1))
2930 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2931 dropped_frames_ttl);
2935 if (!ifmsh->mshcfg.dot11MeshForwarding)
2938 if (sdata->crypto_tx_tailroom_needed_cnt)
2939 tailroom = IEEE80211_ENCRYPT_TAILROOM;
2941 fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2942 sdata->encrypt_headroom,
2943 tailroom, GFP_ATOMIC);
2947 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2948 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2949 info = IEEE80211_SKB_CB(fwd_skb);
2950 memset(info, 0, sizeof(*info));
2951 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
2952 info->control.vif = &rx->sdata->vif;
2953 info->control.jiffies = jiffies;
2954 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2955 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2956 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2957 /* update power mode indication when forwarding */
2958 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2959 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2960 /* mesh power mode flags updated in mesh_nexthop_lookup */
2961 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2963 /* unable to resolve next hop */
2964 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2966 WLAN_REASON_MESH_PATH_NOFORWARD,
2968 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2970 return RX_DROP_MONITOR;
2973 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2974 ieee80211_add_pending_skb(local, fwd_skb);
2976 if (is_multicast_ether_addr(hdr->addr1))
2978 return RX_DROP_MONITOR;
2982 static ieee80211_rx_result debug_noinline
2983 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2985 struct ieee80211_sub_if_data *sdata = rx->sdata;
2986 struct ieee80211_local *local = rx->local;
2987 struct net_device *dev = sdata->dev;
2988 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2989 __le16 fc = hdr->frame_control;
2993 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2996 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2997 return RX_DROP_MONITOR;
3000 * Send unexpected-4addr-frame event to hostapd. For older versions,
3001 * also drop the frame to cooked monitor interfaces.
3003 if (ieee80211_has_a4(hdr->frame_control) &&
3004 sdata->vif.type == NL80211_IFTYPE_AP) {
3006 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
3007 cfg80211_rx_unexpected_4addr_frame(
3008 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
3009 return RX_DROP_MONITOR;
3012 err = __ieee80211_data_to_8023(rx, &port_control);
3014 return RX_DROP_UNUSABLE;
3016 if (!ieee80211_frame_allowed(rx, fc))
3017 return RX_DROP_MONITOR;
3019 /* directly handle TDLS channel switch requests/responses */
3020 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
3021 cpu_to_be16(ETH_P_TDLS))) {
3022 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
3024 if (pskb_may_pull(rx->skb,
3025 offsetof(struct ieee80211_tdls_data, u)) &&
3026 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
3027 tf->category == WLAN_CATEGORY_TDLS &&
3028 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
3029 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
3030 rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
3031 __ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3036 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3037 unlikely(port_control) && sdata->bss) {
3038 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
3046 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3047 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
3048 !is_multicast_ether_addr(
3049 ((struct ethhdr *)rx->skb->data)->h_dest) &&
3050 (!local->scanning &&
3051 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
3052 mod_timer(&local->dynamic_ps_timer, jiffies +
3053 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
3055 ieee80211_deliver_skb(rx);
3060 static ieee80211_rx_result debug_noinline
3061 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
3063 struct sk_buff *skb = rx->skb;
3064 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
3065 struct tid_ampdu_rx *tid_agg_rx;
3069 if (likely(!ieee80211_is_ctl(bar->frame_control)))
3072 if (ieee80211_is_back_req(bar->frame_control)) {
3074 __le16 control, start_seq_num;
3075 } __packed bar_data;
3076 struct ieee80211_event event = {
3077 .type = BAR_RX_EVENT,
3081 return RX_DROP_MONITOR;
3083 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
3084 &bar_data, sizeof(bar_data)))
3085 return RX_DROP_MONITOR;
3087 tid = le16_to_cpu(bar_data.control) >> 12;
3089 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
3090 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
3091 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
3092 WLAN_BACK_RECIPIENT,
3093 WLAN_REASON_QSTA_REQUIRE_SETUP);
3095 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
3097 return RX_DROP_MONITOR;
3099 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
3100 event.u.ba.tid = tid;
3101 event.u.ba.ssn = start_seq_num;
3102 event.u.ba.sta = &rx->sta->sta;
3104 /* reset session timer */
3105 if (tid_agg_rx->timeout)
3106 mod_timer(&tid_agg_rx->session_timer,
3107 TU_TO_EXP_TIME(tid_agg_rx->timeout));
3109 spin_lock(&tid_agg_rx->reorder_lock);
3110 /* release stored frames up to start of BAR */
3111 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
3112 start_seq_num, frames);
3113 spin_unlock(&tid_agg_rx->reorder_lock);
3115 drv_event_callback(rx->local, rx->sdata, &event);
3122 * After this point, we only want management frames,
3123 * so we can drop all remaining control frames to
3124 * cooked monitor interfaces.
3126 return RX_DROP_MONITOR;
3129 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
3130 struct ieee80211_mgmt *mgmt,
3133 struct ieee80211_local *local = sdata->local;
3134 struct sk_buff *skb;
3135 struct ieee80211_mgmt *resp;
3137 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
3138 /* Not to own unicast address */
3142 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
3143 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
3144 /* Not from the current AP or not associated yet. */
3148 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3149 /* Too short SA Query request frame */
3153 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3157 skb_reserve(skb, local->hw.extra_tx_headroom);
3158 resp = skb_put_zero(skb, 24);
3159 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3160 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3161 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3162 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3163 IEEE80211_STYPE_ACTION);
3164 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3165 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3166 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3167 memcpy(resp->u.action.u.sa_query.trans_id,
3168 mgmt->u.action.u.sa_query.trans_id,
3169 WLAN_SA_QUERY_TR_ID_LEN);
3171 ieee80211_tx_skb(sdata, skb);
3174 static ieee80211_rx_result debug_noinline
3175 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3177 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3178 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3180 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
3184 * From here on, look only at management frames.
3185 * Data and control frames are already handled,
3186 * and unknown (reserved) frames are useless.
3188 if (rx->skb->len < 24)
3189 return RX_DROP_MONITOR;
3191 if (!ieee80211_is_mgmt(mgmt->frame_control))
3192 return RX_DROP_MONITOR;
3194 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3195 ieee80211_is_beacon(mgmt->frame_control) &&
3196 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3199 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3200 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3201 sig = status->signal;
3203 cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3204 rx->skb->data, rx->skb->len,
3205 ieee80211_rx_status_to_khz(status),
3207 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3210 if (ieee80211_drop_unencrypted_mgmt(rx))
3211 return RX_DROP_UNUSABLE;
3217 ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
3219 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
3220 struct ieee80211_sub_if_data *sdata = rx->sdata;
3222 /* TWT actions are only supported in AP for the moment */
3223 if (sdata->vif.type != NL80211_IFTYPE_AP)
3226 if (!rx->local->ops->add_twt_setup)
3229 if (!sdata->vif.bss_conf.twt_responder)
3235 switch (mgmt->u.action.u.s1g.action_code) {
3236 case WLAN_S1G_TWT_SETUP: {
3237 struct ieee80211_twt_setup *twt;
3239 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3240 1 + /* action code */
3241 sizeof(struct ieee80211_twt_setup) +
3242 2 /* TWT req_type agrt */)
3245 twt = (void *)mgmt->u.action.u.s1g.variable;
3246 if (twt->element_id != WLAN_EID_S1G_TWT)
3249 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3250 4 + /* action code + token + tlv */
3254 return true; /* queue the frame */
3256 case WLAN_S1G_TWT_TEARDOWN:
3257 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
3260 return true; /* queue the frame */
3268 static ieee80211_rx_result debug_noinline
3269 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3271 struct ieee80211_local *local = rx->local;
3272 struct ieee80211_sub_if_data *sdata = rx->sdata;
3273 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3274 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3275 int len = rx->skb->len;
3277 if (!ieee80211_is_action(mgmt->frame_control))
3280 /* drop too small frames */
3281 if (len < IEEE80211_MIN_ACTION_SIZE)
3282 return RX_DROP_UNUSABLE;
3284 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3285 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3286 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3287 return RX_DROP_UNUSABLE;
3289 switch (mgmt->u.action.category) {
3290 case WLAN_CATEGORY_HT:
3291 /* reject HT action frames from stations not supporting HT */
3292 if (!rx->sta->sta.ht_cap.ht_supported)
3295 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3296 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3297 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3298 sdata->vif.type != NL80211_IFTYPE_AP &&
3299 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3302 /* verify action & smps_control/chanwidth are present */
3303 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3306 switch (mgmt->u.action.u.ht_smps.action) {
3307 case WLAN_HT_ACTION_SMPS: {
3308 struct ieee80211_supported_band *sband;
3309 enum ieee80211_smps_mode smps_mode;
3310 struct sta_opmode_info sta_opmode = {};
3312 if (sdata->vif.type != NL80211_IFTYPE_AP &&
3313 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3316 /* convert to HT capability */
3317 switch (mgmt->u.action.u.ht_smps.smps_control) {
3318 case WLAN_HT_SMPS_CONTROL_DISABLED:
3319 smps_mode = IEEE80211_SMPS_OFF;
3321 case WLAN_HT_SMPS_CONTROL_STATIC:
3322 smps_mode = IEEE80211_SMPS_STATIC;
3324 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3325 smps_mode = IEEE80211_SMPS_DYNAMIC;
3331 /* if no change do nothing */
3332 if (rx->sta->sta.smps_mode == smps_mode)
3334 rx->sta->sta.smps_mode = smps_mode;
3335 sta_opmode.smps_mode =
3336 ieee80211_smps_mode_to_smps_mode(smps_mode);
3337 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3339 sband = rx->local->hw.wiphy->bands[status->band];
3341 rate_control_rate_update(local, sband, rx->sta,
3342 IEEE80211_RC_SMPS_CHANGED);
3343 cfg80211_sta_opmode_change_notify(sdata->dev,
3349 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3350 struct ieee80211_supported_band *sband;
3351 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3352 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3353 struct sta_opmode_info sta_opmode = {};
3355 /* If it doesn't support 40 MHz it can't change ... */
3356 if (!(rx->sta->sta.ht_cap.cap &
3357 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3360 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3361 max_bw = IEEE80211_STA_RX_BW_20;
3363 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
3365 /* set cur_max_bandwidth and recalc sta bw */
3366 rx->sta->cur_max_bandwidth = max_bw;
3367 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
3369 if (rx->sta->sta.bandwidth == new_bw)
3372 rx->sta->sta.bandwidth = new_bw;
3373 sband = rx->local->hw.wiphy->bands[status->band];
3375 ieee80211_sta_rx_bw_to_chan_width(rx->sta);
3376 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3378 rate_control_rate_update(local, sband, rx->sta,
3379 IEEE80211_RC_BW_CHANGED);
3380 cfg80211_sta_opmode_change_notify(sdata->dev,
3391 case WLAN_CATEGORY_PUBLIC:
3392 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3394 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3398 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3400 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3401 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3403 if (len < offsetof(struct ieee80211_mgmt,
3404 u.action.u.ext_chan_switch.variable))
3407 case WLAN_CATEGORY_VHT:
3408 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3409 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3410 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3411 sdata->vif.type != NL80211_IFTYPE_AP &&
3412 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3415 /* verify action code is present */
3416 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3419 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3420 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3421 /* verify opmode is present */
3422 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3426 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3427 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3435 case WLAN_CATEGORY_BACK:
3436 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3437 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3438 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3439 sdata->vif.type != NL80211_IFTYPE_AP &&
3440 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3443 /* verify action_code is present */
3444 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3447 switch (mgmt->u.action.u.addba_req.action_code) {
3448 case WLAN_ACTION_ADDBA_REQ:
3449 if (len < (IEEE80211_MIN_ACTION_SIZE +
3450 sizeof(mgmt->u.action.u.addba_req)))
3453 case WLAN_ACTION_ADDBA_RESP:
3454 if (len < (IEEE80211_MIN_ACTION_SIZE +
3455 sizeof(mgmt->u.action.u.addba_resp)))
3458 case WLAN_ACTION_DELBA:
3459 if (len < (IEEE80211_MIN_ACTION_SIZE +
3460 sizeof(mgmt->u.action.u.delba)))
3468 case WLAN_CATEGORY_SPECTRUM_MGMT:
3469 /* verify action_code is present */
3470 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3473 switch (mgmt->u.action.u.measurement.action_code) {
3474 case WLAN_ACTION_SPCT_MSR_REQ:
3475 if (status->band != NL80211_BAND_5GHZ)
3478 if (len < (IEEE80211_MIN_ACTION_SIZE +
3479 sizeof(mgmt->u.action.u.measurement)))
3482 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3485 ieee80211_process_measurement_req(sdata, mgmt, len);
3487 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3489 if (len < (IEEE80211_MIN_ACTION_SIZE +
3490 sizeof(mgmt->u.action.u.chan_switch)))
3493 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3494 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3495 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3498 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3499 bssid = sdata->u.mgd.bssid;
3500 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3501 bssid = sdata->u.ibss.bssid;
3502 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3507 if (!ether_addr_equal(mgmt->bssid, bssid))
3514 case WLAN_CATEGORY_SELF_PROTECTED:
3515 if (len < (IEEE80211_MIN_ACTION_SIZE +
3516 sizeof(mgmt->u.action.u.self_prot.action_code)))
3519 switch (mgmt->u.action.u.self_prot.action_code) {
3520 case WLAN_SP_MESH_PEERING_OPEN:
3521 case WLAN_SP_MESH_PEERING_CLOSE:
3522 case WLAN_SP_MESH_PEERING_CONFIRM:
3523 if (!ieee80211_vif_is_mesh(&sdata->vif))
3525 if (sdata->u.mesh.user_mpm)
3526 /* userspace handles this frame */
3529 case WLAN_SP_MGK_INFORM:
3530 case WLAN_SP_MGK_ACK:
3531 if (!ieee80211_vif_is_mesh(&sdata->vif))
3536 case WLAN_CATEGORY_MESH_ACTION:
3537 if (len < (IEEE80211_MIN_ACTION_SIZE +
3538 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3541 if (!ieee80211_vif_is_mesh(&sdata->vif))
3543 if (mesh_action_is_path_sel(mgmt) &&
3544 !mesh_path_sel_is_hwmp(sdata))
3547 case WLAN_CATEGORY_S1G:
3548 switch (mgmt->u.action.u.s1g.action_code) {
3549 case WLAN_S1G_TWT_SETUP:
3550 case WLAN_S1G_TWT_TEARDOWN:
3551 if (ieee80211_process_rx_twt_action(rx))
3563 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3564 /* will return in the next handlers */
3569 rx->sta->rx_stats.packets++;
3570 dev_kfree_skb(rx->skb);
3574 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3578 static ieee80211_rx_result debug_noinline
3579 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3581 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3584 /* skip known-bad action frames and return them in the next handler */
3585 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3589 * Getting here means the kernel doesn't know how to handle
3590 * it, but maybe userspace does ... include returned frames
3591 * so userspace can register for those to know whether ones
3592 * it transmitted were processed or returned.
3595 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3596 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3597 sig = status->signal;
3599 if (cfg80211_rx_mgmt_khz(&rx->sdata->wdev,
3600 ieee80211_rx_status_to_khz(status), sig,
3601 rx->skb->data, rx->skb->len, 0)) {
3603 rx->sta->rx_stats.packets++;
3604 dev_kfree_skb(rx->skb);
3611 static ieee80211_rx_result debug_noinline
3612 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
3614 struct ieee80211_sub_if_data *sdata = rx->sdata;
3615 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3616 int len = rx->skb->len;
3618 if (!ieee80211_is_action(mgmt->frame_control))
3621 switch (mgmt->u.action.category) {
3622 case WLAN_CATEGORY_SA_QUERY:
3623 if (len < (IEEE80211_MIN_ACTION_SIZE +
3624 sizeof(mgmt->u.action.u.sa_query)))
3627 switch (mgmt->u.action.u.sa_query.action) {
3628 case WLAN_ACTION_SA_QUERY_REQUEST:
3629 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3631 ieee80211_process_sa_query_req(sdata, mgmt, len);
3641 rx->sta->rx_stats.packets++;
3642 dev_kfree_skb(rx->skb);
3646 static ieee80211_rx_result debug_noinline
3647 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3649 struct ieee80211_local *local = rx->local;
3650 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3651 struct sk_buff *nskb;
3652 struct ieee80211_sub_if_data *sdata = rx->sdata;
3653 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3655 if (!ieee80211_is_action(mgmt->frame_control))
3659 * For AP mode, hostapd is responsible for handling any action
3660 * frames that we didn't handle, including returning unknown
3661 * ones. For all other modes we will return them to the sender,
3662 * setting the 0x80 bit in the action category, as required by
3663 * 802.11-2012 9.24.4.
3664 * Newer versions of hostapd shall also use the management frame
3665 * registration mechanisms, but older ones still use cooked
3666 * monitor interfaces so push all frames there.
3668 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3669 (sdata->vif.type == NL80211_IFTYPE_AP ||
3670 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3671 return RX_DROP_MONITOR;
3673 if (is_multicast_ether_addr(mgmt->da))
3674 return RX_DROP_MONITOR;
3676 /* do not return rejected action frames */
3677 if (mgmt->u.action.category & 0x80)
3678 return RX_DROP_UNUSABLE;
3680 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3683 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3685 nmgmt->u.action.category |= 0x80;
3686 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3687 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3689 memset(nskb->cb, 0, sizeof(nskb->cb));
3691 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3692 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3694 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3695 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3696 IEEE80211_TX_CTL_NO_CCK_RATE;
3697 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3699 local->hw.offchannel_tx_hw_queue;
3702 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3705 dev_kfree_skb(rx->skb);
3709 static ieee80211_rx_result debug_noinline
3710 ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
3712 struct ieee80211_sub_if_data *sdata = rx->sdata;
3713 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
3715 if (!ieee80211_is_ext(hdr->frame_control))
3718 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3719 return RX_DROP_MONITOR;
3721 /* for now only beacons are ext, so queue them */
3722 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3727 static ieee80211_rx_result debug_noinline
3728 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3730 struct ieee80211_sub_if_data *sdata = rx->sdata;
3731 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3734 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3736 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3737 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3738 sdata->vif.type != NL80211_IFTYPE_OCB &&
3739 sdata->vif.type != NL80211_IFTYPE_STATION)
3740 return RX_DROP_MONITOR;
3743 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3744 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3745 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3746 /* process for all: mesh, mlme, ibss */
3748 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3749 if (is_multicast_ether_addr(mgmt->da) &&
3750 !is_broadcast_ether_addr(mgmt->da))
3751 return RX_DROP_MONITOR;
3753 /* process only for station/IBSS */
3754 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3755 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3756 return RX_DROP_MONITOR;
3758 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3759 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3760 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3761 if (is_multicast_ether_addr(mgmt->da) &&
3762 !is_broadcast_ether_addr(mgmt->da))
3763 return RX_DROP_MONITOR;
3765 /* process only for station */
3766 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3767 return RX_DROP_MONITOR;
3769 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3770 /* process only for ibss and mesh */
3771 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3772 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3773 return RX_DROP_MONITOR;
3776 return RX_DROP_MONITOR;
3779 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3784 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3785 struct ieee80211_rate *rate)
3787 struct ieee80211_sub_if_data *sdata;
3788 struct ieee80211_local *local = rx->local;
3789 struct sk_buff *skb = rx->skb, *skb2;
3790 struct net_device *prev_dev = NULL;
3791 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3792 int needed_headroom;
3795 * If cooked monitor has been processed already, then
3796 * don't do it again. If not, set the flag.
3798 if (rx->flags & IEEE80211_RX_CMNTR)
3800 rx->flags |= IEEE80211_RX_CMNTR;
3802 /* If there are no cooked monitor interfaces, just free the SKB */
3803 if (!local->cooked_mntrs)
3806 /* vendor data is long removed here */
3807 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3808 /* room for the radiotap header based on driver features */
3809 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3811 if (skb_headroom(skb) < needed_headroom &&
3812 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3815 /* prepend radiotap information */
3816 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3819 skb_reset_mac_header(skb);
3820 skb->ip_summed = CHECKSUM_UNNECESSARY;
3821 skb->pkt_type = PACKET_OTHERHOST;
3822 skb->protocol = htons(ETH_P_802_2);
3824 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3825 if (!ieee80211_sdata_running(sdata))
3828 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3829 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3833 skb2 = skb_clone(skb, GFP_ATOMIC);
3835 skb2->dev = prev_dev;
3836 netif_receive_skb(skb2);
3840 prev_dev = sdata->dev;
3841 dev_sw_netstats_rx_add(sdata->dev, skb->len);
3845 skb->dev = prev_dev;
3846 netif_receive_skb(skb);
3854 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3855 ieee80211_rx_result res)
3858 case RX_DROP_MONITOR:
3859 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3861 rx->sta->rx_stats.dropped++;
3864 struct ieee80211_rate *rate = NULL;
3865 struct ieee80211_supported_band *sband;
3866 struct ieee80211_rx_status *status;
3868 status = IEEE80211_SKB_RXCB((rx->skb));
3870 sband = rx->local->hw.wiphy->bands[status->band];
3871 if (status->encoding == RX_ENC_LEGACY)
3872 rate = &sband->bitrates[status->rate_idx];
3874 ieee80211_rx_cooked_monitor(rx, rate);
3877 case RX_DROP_UNUSABLE:
3878 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3880 rx->sta->rx_stats.dropped++;
3881 dev_kfree_skb(rx->skb);
3884 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3889 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3890 struct sk_buff_head *frames)
3892 ieee80211_rx_result res = RX_DROP_MONITOR;
3893 struct sk_buff *skb;
3895 #define CALL_RXH(rxh) \
3898 if (res != RX_CONTINUE) \
3902 /* Lock here to avoid hitting all of the data used in the RX
3903 * path (e.g. key data, station data, ...) concurrently when
3904 * a frame is released from the reorder buffer due to timeout
3905 * from the timer, potentially concurrently with RX from the
3908 spin_lock_bh(&rx->local->rx_path_lock);
3910 while ((skb = __skb_dequeue(frames))) {
3912 * all the other fields are valid across frames
3913 * that belong to an aMPDU since they are on the
3914 * same TID from the same station
3918 CALL_RXH(ieee80211_rx_h_check_more_data);
3919 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3920 CALL_RXH(ieee80211_rx_h_sta_process);
3921 CALL_RXH(ieee80211_rx_h_decrypt);
3922 CALL_RXH(ieee80211_rx_h_defragment);
3923 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3924 /* must be after MMIC verify so header is counted in MPDU mic */
3925 #ifdef CONFIG_MAC80211_MESH
3926 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3927 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3929 CALL_RXH(ieee80211_rx_h_amsdu);
3930 CALL_RXH(ieee80211_rx_h_data);
3932 /* special treatment -- needs the queue */
3933 res = ieee80211_rx_h_ctrl(rx, frames);
3934 if (res != RX_CONTINUE)
3937 CALL_RXH(ieee80211_rx_h_mgmt_check);
3938 CALL_RXH(ieee80211_rx_h_action);
3939 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3940 CALL_RXH(ieee80211_rx_h_action_post_userspace);
3941 CALL_RXH(ieee80211_rx_h_action_return);
3942 CALL_RXH(ieee80211_rx_h_ext);
3943 CALL_RXH(ieee80211_rx_h_mgmt);
3946 ieee80211_rx_handlers_result(rx, res);
3951 spin_unlock_bh(&rx->local->rx_path_lock);
3954 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3956 struct sk_buff_head reorder_release;
3957 ieee80211_rx_result res = RX_DROP_MONITOR;
3959 __skb_queue_head_init(&reorder_release);
3961 #define CALL_RXH(rxh) \
3964 if (res != RX_CONTINUE) \
3968 CALL_RXH(ieee80211_rx_h_check_dup);
3969 CALL_RXH(ieee80211_rx_h_check);
3971 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3973 ieee80211_rx_handlers(rx, &reorder_release);
3977 ieee80211_rx_handlers_result(rx, res);
3983 * This function makes calls into the RX path, therefore
3984 * it has to be invoked under RCU read lock.
3986 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3988 struct sk_buff_head frames;
3989 struct ieee80211_rx_data rx = {
3991 .sdata = sta->sdata,
3992 .local = sta->local,
3993 /* This is OK -- must be QoS data frame */
3994 .security_idx = tid,
3997 struct tid_ampdu_rx *tid_agg_rx;
3999 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4003 __skb_queue_head_init(&frames);
4005 spin_lock(&tid_agg_rx->reorder_lock);
4006 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4007 spin_unlock(&tid_agg_rx->reorder_lock);
4009 if (!skb_queue_empty(&frames)) {
4010 struct ieee80211_event event = {
4011 .type = BA_FRAME_TIMEOUT,
4013 .u.ba.sta = &sta->sta,
4015 drv_event_callback(rx.local, rx.sdata, &event);
4018 ieee80211_rx_handlers(&rx, &frames);
4021 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
4022 u16 ssn, u64 filtered,
4025 struct sta_info *sta;
4026 struct tid_ampdu_rx *tid_agg_rx;
4027 struct sk_buff_head frames;
4028 struct ieee80211_rx_data rx = {
4029 /* This is OK -- must be QoS data frame */
4030 .security_idx = tid,
4035 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
4038 __skb_queue_head_init(&frames);
4040 sta = container_of(pubsta, struct sta_info, sta);
4043 rx.sdata = sta->sdata;
4044 rx.local = sta->local;
4047 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4051 spin_lock_bh(&tid_agg_rx->reorder_lock);
4053 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
4056 /* release all frames in the reorder buffer */
4057 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
4058 IEEE80211_SN_MODULO;
4059 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
4061 /* update ssn to match received ssn */
4062 tid_agg_rx->head_seq_num = ssn;
4064 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
4068 /* handle the case that received ssn is behind the mac ssn.
4069 * it can be tid_agg_rx->buf_size behind and still be valid */
4070 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
4071 if (diff >= tid_agg_rx->buf_size) {
4072 tid_agg_rx->reorder_buf_filtered = 0;
4075 filtered = filtered >> diff;
4079 for (i = 0; i < tid_agg_rx->buf_size; i++) {
4080 int index = (ssn + i) % tid_agg_rx->buf_size;
4082 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
4083 if (filtered & BIT_ULL(i))
4084 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
4087 /* now process also frames that the filter marking released */
4088 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4091 spin_unlock_bh(&tid_agg_rx->reorder_lock);
4093 ieee80211_rx_handlers(&rx, &frames);
4098 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
4100 /* main receive path */
4102 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
4104 struct ieee80211_sub_if_data *sdata = rx->sdata;
4105 struct sk_buff *skb = rx->skb;
4106 struct ieee80211_hdr *hdr = (void *)skb->data;
4107 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4108 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
4109 bool multicast = is_multicast_ether_addr(hdr->addr1) ||
4110 ieee80211_is_s1g_beacon(hdr->frame_control);
4112 switch (sdata->vif.type) {
4113 case NL80211_IFTYPE_STATION:
4114 if (!bssid && !sdata->u.mgd.use_4addr)
4116 if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
4120 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4121 case NL80211_IFTYPE_ADHOC:
4124 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
4125 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
4126 !is_valid_ether_addr(hdr->addr2))
4128 if (ieee80211_is_beacon(hdr->frame_control))
4130 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
4133 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4137 if (status->encoding != RX_ENC_LEGACY)
4138 rate_idx = 0; /* TODO: HT/VHT rates */
4140 rate_idx = status->rate_idx;
4141 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
4145 case NL80211_IFTYPE_OCB:
4148 if (!ieee80211_is_data_present(hdr->frame_control))
4150 if (!is_broadcast_ether_addr(bssid))
4153 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
4157 if (status->encoding != RX_ENC_LEGACY)
4158 rate_idx = 0; /* TODO: HT rates */
4160 rate_idx = status->rate_idx;
4161 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
4165 case NL80211_IFTYPE_MESH_POINT:
4166 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
4170 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4171 case NL80211_IFTYPE_AP_VLAN:
4172 case NL80211_IFTYPE_AP:
4174 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4176 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
4178 * Accept public action frames even when the
4179 * BSSID doesn't match, this is used for P2P
4180 * and location updates. Note that mac80211
4181 * itself never looks at these frames.
4184 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4186 if (ieee80211_is_public_action(hdr, skb->len))
4188 return ieee80211_is_beacon(hdr->frame_control);
4191 if (!ieee80211_has_tods(hdr->frame_control)) {
4192 /* ignore data frames to TDLS-peers */
4193 if (ieee80211_is_data(hdr->frame_control))
4195 /* ignore action frames to TDLS-peers */
4196 if (ieee80211_is_action(hdr->frame_control) &&
4197 !is_broadcast_ether_addr(bssid) &&
4198 !ether_addr_equal(bssid, hdr->addr1))
4203 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4204 * the BSSID - we've checked that already but may have accepted
4205 * the wildcard (ff:ff:ff:ff:ff:ff).
4208 * The BSSID of the Data frame is determined as follows:
4209 * a) If the STA is contained within an AP or is associated
4210 * with an AP, the BSSID is the address currently in use
4211 * by the STA contained in the AP.
4213 * So we should not accept data frames with an address that's
4216 * Accepting it also opens a security problem because stations
4217 * could encrypt it with the GTK and inject traffic that way.
4219 if (ieee80211_is_data(hdr->frame_control) && multicast)
4223 case NL80211_IFTYPE_P2P_DEVICE:
4224 return ieee80211_is_public_action(hdr, skb->len) ||
4225 ieee80211_is_probe_req(hdr->frame_control) ||
4226 ieee80211_is_probe_resp(hdr->frame_control) ||
4227 ieee80211_is_beacon(hdr->frame_control);
4228 case NL80211_IFTYPE_NAN:
4229 /* Currently no frames on NAN interface are allowed */
4239 void ieee80211_check_fast_rx(struct sta_info *sta)
4241 struct ieee80211_sub_if_data *sdata = sta->sdata;
4242 struct ieee80211_local *local = sdata->local;
4243 struct ieee80211_key *key;
4244 struct ieee80211_fast_rx fastrx = {
4246 .vif_type = sdata->vif.type,
4247 .control_port_protocol = sdata->control_port_protocol,
4248 }, *old, *new = NULL;
4249 bool set_offload = false;
4250 bool assign = false;
4253 /* use sparse to check that we don't return without updating */
4254 __acquire(check_fast_rx);
4256 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4257 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4258 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4259 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4261 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4263 /* fast-rx doesn't do reordering */
4264 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4265 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4268 switch (sdata->vif.type) {
4269 case NL80211_IFTYPE_STATION:
4270 if (sta->sta.tdls) {
4271 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4272 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4273 fastrx.expected_ds_bits = 0;
4275 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4276 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4277 fastrx.expected_ds_bits =
4278 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4281 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4282 fastrx.expected_ds_bits |=
4283 cpu_to_le16(IEEE80211_FCTL_TODS);
4284 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4285 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4288 if (!sdata->u.mgd.powersave)
4291 /* software powersave is a huge mess, avoid all of it */
4292 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4294 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4295 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4298 case NL80211_IFTYPE_AP_VLAN:
4299 case NL80211_IFTYPE_AP:
4300 /* parallel-rx requires this, at least with calls to
4301 * ieee80211_sta_ps_transition()
4303 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4305 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4306 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4307 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4309 fastrx.internal_forward =
4310 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4311 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4312 !sdata->u.vlan.sta);
4314 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4315 sdata->u.vlan.sta) {
4316 fastrx.expected_ds_bits |=
4317 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4318 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4319 fastrx.internal_forward = 0;
4327 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4331 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4333 key = rcu_dereference(sdata->default_unicast_key);
4335 switch (key->conf.cipher) {
4336 case WLAN_CIPHER_SUITE_TKIP:
4337 /* we don't want to deal with MMIC in fast-rx */
4339 case WLAN_CIPHER_SUITE_CCMP:
4340 case WLAN_CIPHER_SUITE_CCMP_256:
4341 case WLAN_CIPHER_SUITE_GCMP:
4342 case WLAN_CIPHER_SUITE_GCMP_256:
4345 /* We also don't want to deal with
4346 * WEP or cipher scheme.
4352 fastrx.icv_len = key->conf.icv_len;
4359 __release(check_fast_rx);
4362 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4365 (sdata->vif.offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED);
4368 set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4370 set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4373 drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
4375 spin_lock_bh(&sta->lock);
4376 old = rcu_dereference_protected(sta->fast_rx, true);
4377 rcu_assign_pointer(sta->fast_rx, new);
4378 spin_unlock_bh(&sta->lock);
4381 kfree_rcu(old, rcu_head);
4384 void ieee80211_clear_fast_rx(struct sta_info *sta)
4386 struct ieee80211_fast_rx *old;
4388 spin_lock_bh(&sta->lock);
4389 old = rcu_dereference_protected(sta->fast_rx, true);
4390 RCU_INIT_POINTER(sta->fast_rx, NULL);
4391 spin_unlock_bh(&sta->lock);
4394 kfree_rcu(old, rcu_head);
4397 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4399 struct ieee80211_local *local = sdata->local;
4400 struct sta_info *sta;
4402 lockdep_assert_held(&local->sta_mtx);
4404 list_for_each_entry(sta, &local->sta_list, list) {
4405 if (sdata != sta->sdata &&
4406 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4408 ieee80211_check_fast_rx(sta);
4412 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4414 struct ieee80211_local *local = sdata->local;
4416 mutex_lock(&local->sta_mtx);
4417 __ieee80211_check_fast_rx_iface(sdata);
4418 mutex_unlock(&local->sta_mtx);
4421 static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
4422 struct ieee80211_fast_rx *fast_rx,
4425 struct ieee80211_sta_rx_stats *stats;
4426 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4427 struct sta_info *sta = rx->sta;
4428 struct sk_buff *skb = rx->skb;
4429 void *sa = skb->data + ETH_ALEN;
4430 void *da = skb->data;
4432 stats = &sta->rx_stats;
4433 if (fast_rx->uses_rss)
4434 stats = this_cpu_ptr(sta->pcpu_rx_stats);
4436 /* statistics part of ieee80211_rx_h_sta_process() */
4437 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4438 stats->last_signal = status->signal;
4439 if (!fast_rx->uses_rss)
4440 ewma_signal_add(&sta->rx_stats_avg.signal,
4444 if (status->chains) {
4447 stats->chains = status->chains;
4448 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4449 int signal = status->chain_signal[i];
4451 if (!(status->chains & BIT(i)))
4454 stats->chain_signal_last[i] = signal;
4455 if (!fast_rx->uses_rss)
4456 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4460 /* end of statistics */
4462 stats->last_rx = jiffies;
4463 stats->last_rate = sta_stats_encode_rate(status);
4468 skb->dev = fast_rx->dev;
4470 dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
4472 /* The seqno index has the same property as needed
4473 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4474 * for non-QoS-data frames. Here we know it's a data
4475 * frame, so count MSDUs.
4477 u64_stats_update_begin(&stats->syncp);
4478 stats->msdu[rx->seqno_idx]++;
4479 stats->bytes += orig_len;
4480 u64_stats_update_end(&stats->syncp);
4482 if (fast_rx->internal_forward) {
4483 struct sk_buff *xmit_skb = NULL;
4484 if (is_multicast_ether_addr(da)) {
4485 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4486 } else if (!ether_addr_equal(da, sa) &&
4487 sta_info_get(rx->sdata, da)) {
4494 * Send to wireless media and increase priority by 256
4495 * to keep the received priority instead of
4496 * reclassifying the frame (see cfg80211_classify8021d).
4498 xmit_skb->priority += 256;
4499 xmit_skb->protocol = htons(ETH_P_802_3);
4500 skb_reset_network_header(xmit_skb);
4501 skb_reset_mac_header(xmit_skb);
4502 dev_queue_xmit(xmit_skb);
4509 /* deliver to local stack */
4510 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4511 memset(skb->cb, 0, sizeof(skb->cb));
4513 list_add_tail(&skb->list, rx->list);
4515 netif_receive_skb(skb);
4519 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4520 struct ieee80211_fast_rx *fast_rx)
4522 struct sk_buff *skb = rx->skb;
4523 struct ieee80211_hdr *hdr = (void *)skb->data;
4524 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4525 struct sta_info *sta = rx->sta;
4526 int orig_len = skb->len;
4527 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4528 int snap_offs = hdrlen;
4530 u8 snap[sizeof(rfc1042_header)];
4532 } *payload __aligned(2);
4536 } addrs __aligned(2);
4537 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
4539 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4540 * to a common data structure; drivers can implement that per queue
4541 * but we don't have that information in mac80211
4543 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4546 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4548 /* If using encryption, we also need to have:
4549 * - PN_VALIDATED: similar, but the implementation is tricky
4550 * - DECRYPTED: necessary for PN_VALIDATED
4553 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4556 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4559 if (unlikely(ieee80211_is_frag(hdr)))
4562 /* Since our interface address cannot be multicast, this
4563 * implicitly also rejects multicast frames without the
4566 * We shouldn't get any *data* frames not addressed to us
4567 * (AP mode will accept multicast *management* frames), but
4568 * punting here will make it go through the full checks in
4569 * ieee80211_accept_frame().
4571 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4574 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4575 IEEE80211_FCTL_TODS)) !=
4576 fast_rx->expected_ds_bits)
4579 /* assign the key to drop unencrypted frames (later)
4580 * and strip the IV/MIC if necessary
4582 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4583 /* GCMP header length is the same */
4584 snap_offs += IEEE80211_CCMP_HDR_LEN;
4587 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4588 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4591 payload = (void *)(skb->data + snap_offs);
4593 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4596 /* Don't handle these here since they require special code.
4597 * Accept AARP and IPX even though they should come with a
4598 * bridge-tunnel header - but if we get them this way then
4599 * there's little point in discarding them.
4601 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4602 payload->proto == fast_rx->control_port_protocol))
4606 /* after this point, don't punt to the slowpath! */
4608 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4609 pskb_trim(skb, skb->len - fast_rx->icv_len))
4612 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4615 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4616 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4623 /* do the header conversion - first grab the addresses */
4624 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4625 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4626 /* remove the SNAP but leave the ethertype */
4627 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4628 /* push the addresses in front */
4629 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4631 ieee80211_rx_8023(rx, fast_rx, orig_len);
4636 if (fast_rx->uses_rss)
4637 stats = this_cpu_ptr(sta->pcpu_rx_stats);
4644 * This function returns whether or not the SKB
4645 * was destined for RX processing or not, which,
4646 * if consume is true, is equivalent to whether
4647 * or not the skb was consumed.
4649 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4650 struct sk_buff *skb, bool consume)
4652 struct ieee80211_local *local = rx->local;
4653 struct ieee80211_sub_if_data *sdata = rx->sdata;
4657 /* See if we can do fast-rx; if we have to copy we already lost,
4658 * so punt in that case. We should never have to deliver a data
4659 * frame to multiple interfaces anyway.
4661 * We skip the ieee80211_accept_frame() call and do the necessary
4662 * checking inside ieee80211_invoke_fast_rx().
4664 if (consume && rx->sta) {
4665 struct ieee80211_fast_rx *fast_rx;
4667 fast_rx = rcu_dereference(rx->sta->fast_rx);
4668 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4672 if (!ieee80211_accept_frame(rx))
4676 skb = skb_copy(skb, GFP_ATOMIC);
4678 if (net_ratelimit())
4679 wiphy_debug(local->hw.wiphy,
4680 "failed to copy skb for %s\n",
4688 ieee80211_invoke_rx_handlers(rx);
4692 static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
4693 struct ieee80211_sta *pubsta,
4694 struct sk_buff *skb,
4695 struct list_head *list)
4697 struct ieee80211_local *local = hw_to_local(hw);
4698 struct ieee80211_fast_rx *fast_rx;
4699 struct ieee80211_rx_data rx;
4701 memset(&rx, 0, sizeof(rx));
4706 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4708 /* drop frame if too short for header */
4709 if (skb->len < sizeof(struct ethhdr))
4715 rx.sta = container_of(pubsta, struct sta_info, sta);
4716 rx.sdata = rx.sta->sdata;
4718 fast_rx = rcu_dereference(rx.sta->fast_rx);
4722 ieee80211_rx_8023(&rx, fast_rx, skb->len);
4730 * This is the actual Rx frames handler. as it belongs to Rx path it must
4731 * be called with rcu_read_lock protection.
4733 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4734 struct ieee80211_sta *pubsta,
4735 struct sk_buff *skb,
4736 struct list_head *list)
4738 struct ieee80211_local *local = hw_to_local(hw);
4739 struct ieee80211_sub_if_data *sdata;
4740 struct ieee80211_hdr *hdr;
4742 struct ieee80211_rx_data rx;
4743 struct ieee80211_sub_if_data *prev;
4744 struct rhlist_head *tmp;
4747 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4748 memset(&rx, 0, sizeof(rx));
4753 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4754 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4756 if (ieee80211_is_mgmt(fc)) {
4757 /* drop frame if too short for header */
4758 if (skb->len < ieee80211_hdrlen(fc))
4761 err = skb_linearize(skb);
4763 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4771 hdr = (struct ieee80211_hdr *)skb->data;
4772 ieee80211_parse_qos(&rx);
4773 ieee80211_verify_alignment(&rx);
4775 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4776 ieee80211_is_beacon(hdr->frame_control) ||
4777 ieee80211_is_s1g_beacon(hdr->frame_control)))
4778 ieee80211_scan_rx(local, skb);
4780 if (ieee80211_is_data(fc)) {
4781 struct sta_info *sta, *prev_sta;
4784 rx.sta = container_of(pubsta, struct sta_info, sta);
4785 rx.sdata = rx.sta->sdata;
4786 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4793 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4800 rx.sdata = prev_sta->sdata;
4801 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4808 rx.sdata = prev_sta->sdata;
4810 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4818 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4819 if (!ieee80211_sdata_running(sdata))
4822 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4823 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4827 * frame is destined for this interface, but if it's
4828 * not also for the previous one we handle that after
4829 * the loop to avoid copying the SKB once too much
4837 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4839 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4845 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4848 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4857 * This is the receive path handler. It is called by a low level driver when an
4858 * 802.11 MPDU is received from the hardware.
4860 void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4861 struct sk_buff *skb, struct list_head *list)
4863 struct ieee80211_local *local = hw_to_local(hw);
4864 struct ieee80211_rate *rate = NULL;
4865 struct ieee80211_supported_band *sband;
4866 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4867 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4869 WARN_ON_ONCE(softirq_count() == 0);
4871 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4874 sband = local->hw.wiphy->bands[status->band];
4875 if (WARN_ON(!sband))
4879 * If we're suspending, it is possible although not too likely
4880 * that we'd be receiving frames after having already partially
4881 * quiesced the stack. We can't process such frames then since
4882 * that might, for example, cause stations to be added or other
4883 * driver callbacks be invoked.
4885 if (unlikely(local->quiescing || local->suspended))
4888 /* We might be during a HW reconfig, prevent Rx for the same reason */
4889 if (unlikely(local->in_reconfig))
4893 * The same happens when we're not even started,
4894 * but that's worth a warning.
4896 if (WARN_ON(!local->started))
4899 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4901 * Validate the rate, unless a PLCP error means that
4902 * we probably can't have a valid rate here anyway.
4905 switch (status->encoding) {
4908 * rate_idx is MCS index, which can be [0-76]
4911 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
4913 * Anything else would be some sort of driver or
4914 * hardware error. The driver should catch hardware
4917 if (WARN(status->rate_idx > 76,
4918 "Rate marked as an HT rate but passed "
4919 "status->rate_idx is not "
4920 "an MCS index [0-76]: %d (0x%02x)\n",
4926 if (WARN_ONCE(status->rate_idx > 9 ||
4929 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4930 status->rate_idx, status->nss))
4934 if (WARN_ONCE(status->rate_idx > 11 ||
4937 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4938 status->rate_idx, status->nss))
4945 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4947 rate = &sband->bitrates[status->rate_idx];
4951 status->rx_flags = 0;
4953 kcov_remote_start_common(skb_get_kcov_handle(skb));
4956 * Frames with failed FCS/PLCP checksum are not returned,
4957 * all other frames are returned without radiotap header
4958 * if it was previously present.
4959 * Also, frames with less than 16 bytes are dropped.
4961 if (!(status->flag & RX_FLAG_8023))
4962 skb = ieee80211_rx_monitor(local, skb, rate);
4964 if ((status->flag & RX_FLAG_8023) ||
4965 ieee80211_is_data_present(hdr->frame_control))
4966 ieee80211_tpt_led_trig_rx(local, skb->len);
4968 if (status->flag & RX_FLAG_8023)
4969 __ieee80211_rx_handle_8023(hw, pubsta, skb, list);
4971 __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
4979 EXPORT_SYMBOL(ieee80211_rx_list);
4981 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4982 struct sk_buff *skb, struct napi_struct *napi)
4984 struct sk_buff *tmp;
4989 * key references and virtual interfaces are protected using RCU
4990 * and this requires that we are in a read-side RCU section during
4991 * receive processing
4994 ieee80211_rx_list(hw, pubsta, skb, &list);
4998 netif_receive_skb_list(&list);
5002 list_for_each_entry_safe(skb, tmp, &list, list) {
5003 skb_list_del_init(skb);
5004 napi_gro_receive(napi, skb);
5007 EXPORT_SYMBOL(ieee80211_rx_napi);
5009 /* This is a version of the rx handler that can be called from hard irq
5010 * context. Post the skb on the queue and schedule the tasklet */
5011 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
5013 struct ieee80211_local *local = hw_to_local(hw);
5015 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
5017 skb->pkt_type = IEEE80211_RX_MSG;
5018 skb_queue_tail(&local->skb_queue, skb);
5019 tasklet_schedule(&local->tasklet);
5021 EXPORT_SYMBOL(ieee80211_rx_irqsafe);