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;
469 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
470 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
471 if (status->enc_flags & RX_ENC_FLAG_LDPC)
472 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FEC;
475 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
476 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
477 if (status->bw == RATE_INFO_BW_40)
478 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
479 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
480 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
481 if (status->enc_flags & RX_ENC_FLAG_LDPC)
482 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
483 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
484 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
486 *pos++ = status->rate_idx;
489 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
492 /* ensure 4 byte alignment */
493 while ((pos - (u8 *)rthdr) & 3)
496 cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
497 put_unaligned_le32(status->ampdu_reference, pos);
499 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
500 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
501 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
502 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
503 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
504 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
505 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
506 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
507 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
508 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
509 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
510 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
511 put_unaligned_le16(flags, pos);
513 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
514 *pos++ = status->ampdu_delimiter_crc;
520 if (status->encoding == RX_ENC_VHT) {
521 u16 known = local->hw.radiotap_vht_details;
523 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
524 put_unaligned_le16(known, pos);
527 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
528 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
529 /* in VHT, STBC is binary */
530 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
531 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
532 if (status->enc_flags & RX_ENC_FLAG_BF)
533 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
536 switch (status->bw) {
537 case RATE_INFO_BW_80:
540 case RATE_INFO_BW_160:
543 case RATE_INFO_BW_40:
550 *pos = (status->rate_idx << 4) | status->nss;
553 if (status->enc_flags & RX_ENC_FLAG_LDPC)
554 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
562 if (local->hw.radiotap_timestamp.units_pos >= 0) {
564 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
567 cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
569 /* ensure 8 byte alignment */
570 while ((pos - (u8 *)rthdr) & 7)
573 put_unaligned_le64(status->device_timestamp, pos);
576 if (local->hw.radiotap_timestamp.accuracy >= 0) {
577 accuracy = local->hw.radiotap_timestamp.accuracy;
578 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
580 put_unaligned_le16(accuracy, pos);
583 *pos++ = local->hw.radiotap_timestamp.units_pos;
587 if (status->encoding == RX_ENC_HE &&
588 status->flag & RX_FLAG_RADIOTAP_HE) {
589 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
591 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
592 he.data6 |= HE_PREP(DATA6_NSTS,
593 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
595 he.data3 |= HE_PREP(DATA3_STBC, 1);
597 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
600 #define CHECK_GI(s) \
601 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
602 (int)NL80211_RATE_INFO_HE_GI_##s)
608 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
609 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
610 he.data3 |= HE_PREP(DATA3_CODING,
611 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
613 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
615 switch (status->bw) {
616 case RATE_INFO_BW_20:
617 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
618 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
620 case RATE_INFO_BW_40:
621 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
622 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
624 case RATE_INFO_BW_80:
625 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
626 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
628 case RATE_INFO_BW_160:
629 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
630 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
632 case RATE_INFO_BW_HE_RU:
633 #define CHECK_RU_ALLOC(s) \
634 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
635 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
643 CHECK_RU_ALLOC(2x996);
645 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
649 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
652 /* ensure 2 byte alignment */
653 while ((pos - (u8 *)rthdr) & 1)
655 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
656 memcpy(pos, &he, sizeof(he));
660 if (status->encoding == RX_ENC_HE &&
661 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
662 /* ensure 2 byte alignment */
663 while ((pos - (u8 *)rthdr) & 1)
665 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
666 memcpy(pos, &he_mu, sizeof(he_mu));
667 pos += sizeof(he_mu);
670 if (status->flag & RX_FLAG_NO_PSDU) {
672 cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
673 *pos++ = status->zero_length_psdu_type;
676 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
677 /* ensure 2 byte alignment */
678 while ((pos - (u8 *)rthdr) & 1)
680 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
681 memcpy(pos, &lsig, sizeof(lsig));
685 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
686 *pos++ = status->chain_signal[chain];
690 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
691 /* ensure 2 byte alignment for the vendor field as required */
692 if ((pos - (u8 *)rthdr) & 1)
694 *pos++ = rtap.oui[0];
695 *pos++ = rtap.oui[1];
696 *pos++ = rtap.oui[2];
698 put_unaligned_le16(rtap.len, pos);
700 /* align the actual payload as requested */
701 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
703 /* data (and possible padding) already follows */
707 static struct sk_buff *
708 ieee80211_make_monitor_skb(struct ieee80211_local *local,
709 struct sk_buff **origskb,
710 struct ieee80211_rate *rate,
711 int rtap_space, bool use_origskb)
713 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
714 int rt_hdrlen, needed_headroom;
717 /* room for the radiotap header based on driver features */
718 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
719 needed_headroom = rt_hdrlen - rtap_space;
722 /* only need to expand headroom if necessary */
727 * This shouldn't trigger often because most devices have an
728 * RX header they pull before we get here, and that should
729 * be big enough for our radiotap information. We should
730 * probably export the length to drivers so that we can have
731 * them allocate enough headroom to start with.
733 if (skb_headroom(skb) < needed_headroom &&
734 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
740 * Need to make a copy and possibly remove radiotap header
741 * and FCS from the original.
743 skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
750 /* prepend radiotap information */
751 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
753 skb_reset_mac_header(skb);
754 skb->ip_summed = CHECKSUM_UNNECESSARY;
755 skb->pkt_type = PACKET_OTHERHOST;
756 skb->protocol = htons(ETH_P_802_2);
762 * This function copies a received frame to all monitor interfaces and
763 * returns a cleaned-up SKB that no longer includes the FCS nor the
764 * radiotap header the driver might have added.
766 static struct sk_buff *
767 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
768 struct ieee80211_rate *rate)
770 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
771 struct ieee80211_sub_if_data *sdata;
772 struct sk_buff *monskb = NULL;
773 int present_fcs_len = 0;
774 unsigned int rtap_space = 0;
775 struct ieee80211_sub_if_data *monitor_sdata =
776 rcu_dereference(local->monitor_sdata);
777 bool only_monitor = false;
778 unsigned int min_head_len;
780 if (status->flag & RX_FLAG_RADIOTAP_HE)
781 rtap_space += sizeof(struct ieee80211_radiotap_he);
783 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
784 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
786 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
787 rtap_space += sizeof(struct ieee80211_radiotap_lsig);
789 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
790 struct ieee80211_vendor_radiotap *rtap =
791 (void *)(origskb->data + rtap_space);
793 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
796 min_head_len = rtap_space;
799 * First, we may need to make a copy of the skb because
800 * (1) we need to modify it for radiotap (if not present), and
801 * (2) the other RX handlers will modify the skb we got.
803 * We don't need to, of course, if we aren't going to return
804 * the SKB because it has a bad FCS/PLCP checksum.
807 if (!(status->flag & RX_FLAG_NO_PSDU)) {
808 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
809 if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
812 dev_kfree_skb(origskb);
815 present_fcs_len = FCS_LEN;
818 /* also consider the hdr->frame_control */
822 /* ensure that the expected data elements are in skb head */
823 if (!pskb_may_pull(origskb, min_head_len)) {
824 dev_kfree_skb(origskb);
828 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
830 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
832 dev_kfree_skb(origskb);
836 return ieee80211_clean_skb(origskb, present_fcs_len,
840 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
842 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
843 bool last_monitor = list_is_last(&sdata->u.mntr.list,
847 monskb = ieee80211_make_monitor_skb(local, &origskb,
859 skb = skb_clone(monskb, GFP_ATOMIC);
863 skb->dev = sdata->dev;
864 dev_sw_netstats_rx_add(skb->dev, skb->len);
865 netif_receive_skb(skb);
873 /* this happens if last_monitor was erroneously false */
874 dev_kfree_skb(monskb);
880 return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
883 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
885 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
886 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
887 int tid, seqno_idx, security_idx;
889 /* does the frame have a qos control field? */
890 if (ieee80211_is_data_qos(hdr->frame_control)) {
891 u8 *qc = ieee80211_get_qos_ctl(hdr);
892 /* frame has qos control */
893 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
894 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
895 status->rx_flags |= IEEE80211_RX_AMSDU;
901 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
903 * Sequence numbers for management frames, QoS data
904 * frames with a broadcast/multicast address in the
905 * Address 1 field, and all non-QoS data frames sent
906 * by QoS STAs are assigned using an additional single
907 * modulo-4096 counter, [...]
909 * We also use that counter for non-QoS STAs.
911 seqno_idx = IEEE80211_NUM_TIDS;
913 if (ieee80211_is_mgmt(hdr->frame_control))
914 security_idx = IEEE80211_NUM_TIDS;
918 rx->seqno_idx = seqno_idx;
919 rx->security_idx = security_idx;
920 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
921 * For now, set skb->priority to 0 for other cases. */
922 rx->skb->priority = (tid > 7) ? 0 : tid;
926 * DOC: Packet alignment
928 * Drivers always need to pass packets that are aligned to two-byte boundaries
931 * Additionally, should, if possible, align the payload data in a way that
932 * guarantees that the contained IP header is aligned to a four-byte
933 * boundary. In the case of regular frames, this simply means aligning the
934 * payload to a four-byte boundary (because either the IP header is directly
935 * contained, or IV/RFC1042 headers that have a length divisible by four are
936 * in front of it). If the payload data is not properly aligned and the
937 * architecture doesn't support efficient unaligned operations, mac80211
938 * will align the data.
940 * With A-MSDU frames, however, the payload data address must yield two modulo
941 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
942 * push the IP header further back to a multiple of four again. Thankfully, the
943 * specs were sane enough this time around to require padding each A-MSDU
944 * subframe to a length that is a multiple of four.
946 * Padding like Atheros hardware adds which is between the 802.11 header and
947 * the payload is not supported, the driver is required to move the 802.11
948 * header to be directly in front of the payload in that case.
950 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
952 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
953 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
960 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
962 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
964 if (is_multicast_ether_addr(hdr->addr1))
967 return ieee80211_is_robust_mgmt_frame(skb);
971 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
973 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
975 if (!is_multicast_ether_addr(hdr->addr1))
978 return ieee80211_is_robust_mgmt_frame(skb);
982 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
983 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
985 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
986 struct ieee80211_mmie *mmie;
987 struct ieee80211_mmie_16 *mmie16;
989 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
992 if (!ieee80211_is_robust_mgmt_frame(skb) &&
993 !ieee80211_is_beacon(hdr->frame_control))
994 return -1; /* not a robust management frame */
996 mmie = (struct ieee80211_mmie *)
997 (skb->data + skb->len - sizeof(*mmie));
998 if (mmie->element_id == WLAN_EID_MMIE &&
999 mmie->length == sizeof(*mmie) - 2)
1000 return le16_to_cpu(mmie->key_id);
1002 mmie16 = (struct ieee80211_mmie_16 *)
1003 (skb->data + skb->len - sizeof(*mmie16));
1004 if (skb->len >= 24 + sizeof(*mmie16) &&
1005 mmie16->element_id == WLAN_EID_MMIE &&
1006 mmie16->length == sizeof(*mmie16) - 2)
1007 return le16_to_cpu(mmie16->key_id);
1012 static int ieee80211_get_keyid(struct sk_buff *skb,
1013 const struct ieee80211_cipher_scheme *cs)
1015 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1023 fc = hdr->frame_control;
1024 hdrlen = ieee80211_hdrlen(fc);
1027 minlen = hdrlen + cs->hdr_len;
1028 key_idx_off = hdrlen + cs->key_idx_off;
1029 key_idx_shift = cs->key_idx_shift;
1031 /* WEP, TKIP, CCMP and GCMP */
1032 minlen = hdrlen + IEEE80211_WEP_IV_LEN;
1033 key_idx_off = hdrlen + 3;
1037 if (unlikely(skb->len < minlen))
1040 skb_copy_bits(skb, key_idx_off, &keyid, 1);
1043 keyid &= cs->key_idx_mask;
1044 keyid >>= key_idx_shift;
1046 /* cs could use more than the usual two bits for the keyid */
1047 if (unlikely(keyid >= NUM_DEFAULT_KEYS))
1053 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1055 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1056 char *dev_addr = rx->sdata->vif.addr;
1058 if (ieee80211_is_data(hdr->frame_control)) {
1059 if (is_multicast_ether_addr(hdr->addr1)) {
1060 if (ieee80211_has_tods(hdr->frame_control) ||
1061 !ieee80211_has_fromds(hdr->frame_control))
1062 return RX_DROP_MONITOR;
1063 if (ether_addr_equal(hdr->addr3, dev_addr))
1064 return RX_DROP_MONITOR;
1066 if (!ieee80211_has_a4(hdr->frame_control))
1067 return RX_DROP_MONITOR;
1068 if (ether_addr_equal(hdr->addr4, dev_addr))
1069 return RX_DROP_MONITOR;
1073 /* If there is not an established peer link and this is not a peer link
1074 * establisment frame, beacon or probe, drop the frame.
1077 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1078 struct ieee80211_mgmt *mgmt;
1080 if (!ieee80211_is_mgmt(hdr->frame_control))
1081 return RX_DROP_MONITOR;
1083 if (ieee80211_is_action(hdr->frame_control)) {
1086 /* make sure category field is present */
1087 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1088 return RX_DROP_MONITOR;
1090 mgmt = (struct ieee80211_mgmt *)hdr;
1091 category = mgmt->u.action.category;
1092 if (category != WLAN_CATEGORY_MESH_ACTION &&
1093 category != WLAN_CATEGORY_SELF_PROTECTED)
1094 return RX_DROP_MONITOR;
1098 if (ieee80211_is_probe_req(hdr->frame_control) ||
1099 ieee80211_is_probe_resp(hdr->frame_control) ||
1100 ieee80211_is_beacon(hdr->frame_control) ||
1101 ieee80211_is_auth(hdr->frame_control))
1104 return RX_DROP_MONITOR;
1110 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1113 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1114 struct sk_buff *tail = skb_peek_tail(frames);
1115 struct ieee80211_rx_status *status;
1117 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1123 status = IEEE80211_SKB_RXCB(tail);
1124 if (status->flag & RX_FLAG_AMSDU_MORE)
1130 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1131 struct tid_ampdu_rx *tid_agg_rx,
1133 struct sk_buff_head *frames)
1135 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1136 struct sk_buff *skb;
1137 struct ieee80211_rx_status *status;
1139 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1141 if (skb_queue_empty(skb_list))
1144 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1145 __skb_queue_purge(skb_list);
1149 /* release frames from the reorder ring buffer */
1150 tid_agg_rx->stored_mpdu_num--;
1151 while ((skb = __skb_dequeue(skb_list))) {
1152 status = IEEE80211_SKB_RXCB(skb);
1153 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1154 __skb_queue_tail(frames, skb);
1158 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1159 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1162 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1163 struct tid_ampdu_rx *tid_agg_rx,
1165 struct sk_buff_head *frames)
1169 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1171 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1172 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1173 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1179 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1180 * the skb was added to the buffer longer than this time ago, the earlier
1181 * frames that have not yet been received are assumed to be lost and the skb
1182 * can be released for processing. This may also release other skb's from the
1183 * reorder buffer if there are no additional gaps between the frames.
1185 * Callers must hold tid_agg_rx->reorder_lock.
1187 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1189 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1190 struct tid_ampdu_rx *tid_agg_rx,
1191 struct sk_buff_head *frames)
1195 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1197 /* release the buffer until next missing frame */
1198 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1199 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1200 tid_agg_rx->stored_mpdu_num) {
1202 * No buffers ready to be released, but check whether any
1203 * frames in the reorder buffer have timed out.
1206 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1207 j = (j + 1) % tid_agg_rx->buf_size) {
1208 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1213 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1214 HT_RX_REORDER_BUF_TIMEOUT))
1215 goto set_release_timer;
1217 /* don't leave incomplete A-MSDUs around */
1218 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1219 i = (i + 1) % tid_agg_rx->buf_size)
1220 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1222 ht_dbg_ratelimited(sdata,
1223 "release an RX reorder frame due to timeout on earlier frames\n");
1224 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1228 * Increment the head seq# also for the skipped slots.
1230 tid_agg_rx->head_seq_num =
1231 (tid_agg_rx->head_seq_num +
1232 skipped) & IEEE80211_SN_MASK;
1235 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1236 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1238 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1241 if (tid_agg_rx->stored_mpdu_num) {
1242 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1244 for (; j != (index - 1) % tid_agg_rx->buf_size;
1245 j = (j + 1) % tid_agg_rx->buf_size) {
1246 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1252 if (!tid_agg_rx->removed)
1253 mod_timer(&tid_agg_rx->reorder_timer,
1254 tid_agg_rx->reorder_time[j] + 1 +
1255 HT_RX_REORDER_BUF_TIMEOUT);
1257 del_timer(&tid_agg_rx->reorder_timer);
1262 * As this function belongs to the RX path it must be under
1263 * rcu_read_lock protection. It returns false if the frame
1264 * can be processed immediately, true if it was consumed.
1266 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1267 struct tid_ampdu_rx *tid_agg_rx,
1268 struct sk_buff *skb,
1269 struct sk_buff_head *frames)
1271 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1272 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1273 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1274 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1275 u16 head_seq_num, buf_size;
1279 spin_lock(&tid_agg_rx->reorder_lock);
1282 * Offloaded BA sessions have no known starting sequence number so pick
1283 * one from first Rxed frame for this tid after BA was started.
1285 if (unlikely(tid_agg_rx->auto_seq)) {
1286 tid_agg_rx->auto_seq = false;
1287 tid_agg_rx->ssn = mpdu_seq_num;
1288 tid_agg_rx->head_seq_num = mpdu_seq_num;
1291 buf_size = tid_agg_rx->buf_size;
1292 head_seq_num = tid_agg_rx->head_seq_num;
1295 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1298 if (unlikely(!tid_agg_rx->started)) {
1299 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1303 tid_agg_rx->started = true;
1306 /* frame with out of date sequence number */
1307 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1313 * If frame the sequence number exceeds our buffering window
1314 * size release some previous frames to make room for this one.
1316 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1317 head_seq_num = ieee80211_sn_inc(
1318 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1319 /* release stored frames up to new head to stack */
1320 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1321 head_seq_num, frames);
1324 /* Now the new frame is always in the range of the reordering buffer */
1326 index = mpdu_seq_num % tid_agg_rx->buf_size;
1328 /* check if we already stored this frame */
1329 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1335 * If the current MPDU is in the right order and nothing else
1336 * is stored we can process it directly, no need to buffer it.
1337 * If it is first but there's something stored, we may be able
1338 * to release frames after this one.
1340 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1341 tid_agg_rx->stored_mpdu_num == 0) {
1342 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1343 tid_agg_rx->head_seq_num =
1344 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1349 /* put the frame in the reordering buffer */
1350 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1351 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1352 tid_agg_rx->reorder_time[index] = jiffies;
1353 tid_agg_rx->stored_mpdu_num++;
1354 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1358 spin_unlock(&tid_agg_rx->reorder_lock);
1363 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1364 * true if the MPDU was buffered, false if it should be processed.
1366 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1367 struct sk_buff_head *frames)
1369 struct sk_buff *skb = rx->skb;
1370 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1371 struct sta_info *sta = rx->sta;
1372 struct tid_ampdu_rx *tid_agg_rx;
1376 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1377 is_multicast_ether_addr(hdr->addr1))
1381 * filter the QoS data rx stream according to
1382 * STA/TID and check if this STA/TID is on aggregation
1388 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1389 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1390 tid = ieee80211_get_tid(hdr);
1392 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1394 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1395 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1396 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1397 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1398 WLAN_BACK_RECIPIENT,
1399 WLAN_REASON_QSTA_REQUIRE_SETUP);
1403 /* qos null data frames are excluded */
1404 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1407 /* not part of a BA session */
1408 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
1411 /* new, potentially un-ordered, ampdu frame - process it */
1413 /* reset session timer */
1414 if (tid_agg_rx->timeout)
1415 tid_agg_rx->last_rx = jiffies;
1417 /* if this mpdu is fragmented - terminate rx aggregation session */
1418 sc = le16_to_cpu(hdr->seq_ctrl);
1419 if (sc & IEEE80211_SCTL_FRAG) {
1420 ieee80211_queue_skb_to_iface(rx->sdata, NULL, skb);
1425 * No locking needed -- we will only ever process one
1426 * RX packet at a time, and thus own tid_agg_rx. All
1427 * other code manipulating it needs to (and does) make
1428 * sure that we cannot get to it any more before doing
1431 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1436 __skb_queue_tail(frames, skb);
1439 static ieee80211_rx_result debug_noinline
1440 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1442 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1443 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1445 if (status->flag & RX_FLAG_DUP_VALIDATED)
1449 * Drop duplicate 802.11 retransmissions
1450 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1453 if (rx->skb->len < 24)
1456 if (ieee80211_is_ctl(hdr->frame_control) ||
1457 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1458 is_multicast_ether_addr(hdr->addr1))
1464 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1465 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1466 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1467 rx->sta->rx_stats.num_duplicates++;
1468 return RX_DROP_UNUSABLE;
1469 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1470 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1476 static ieee80211_rx_result debug_noinline
1477 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1479 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1481 /* Drop disallowed frame classes based on STA auth/assoc state;
1482 * IEEE 802.11, Chap 5.5.
1484 * mac80211 filters only based on association state, i.e. it drops
1485 * Class 3 frames from not associated stations. hostapd sends
1486 * deauth/disassoc frames when needed. In addition, hostapd is
1487 * responsible for filtering on both auth and assoc states.
1490 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1491 return ieee80211_rx_mesh_check(rx);
1493 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1494 ieee80211_is_pspoll(hdr->frame_control)) &&
1495 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1496 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1497 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1499 * accept port control frames from the AP even when it's not
1500 * yet marked ASSOC to prevent a race where we don't set the
1501 * assoc bit quickly enough before it sends the first frame
1503 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1504 ieee80211_is_data_present(hdr->frame_control)) {
1505 unsigned int hdrlen;
1508 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1510 if (rx->skb->len < hdrlen + 8)
1511 return RX_DROP_MONITOR;
1513 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1514 if (ethertype == rx->sdata->control_port_protocol)
1518 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1519 cfg80211_rx_spurious_frame(rx->sdata->dev,
1522 return RX_DROP_UNUSABLE;
1524 return RX_DROP_MONITOR;
1531 static ieee80211_rx_result debug_noinline
1532 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1534 struct ieee80211_local *local;
1535 struct ieee80211_hdr *hdr;
1536 struct sk_buff *skb;
1540 hdr = (struct ieee80211_hdr *) skb->data;
1542 if (!local->pspolling)
1545 if (!ieee80211_has_fromds(hdr->frame_control))
1546 /* this is not from AP */
1549 if (!ieee80211_is_data(hdr->frame_control))
1552 if (!ieee80211_has_moredata(hdr->frame_control)) {
1553 /* AP has no more frames buffered for us */
1554 local->pspolling = false;
1558 /* more data bit is set, let's request a new frame from the AP */
1559 ieee80211_send_pspoll(local, rx->sdata);
1564 static void sta_ps_start(struct sta_info *sta)
1566 struct ieee80211_sub_if_data *sdata = sta->sdata;
1567 struct ieee80211_local *local = sdata->local;
1571 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1572 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1573 ps = &sdata->bss->ps;
1577 atomic_inc(&ps->num_sta_ps);
1578 set_sta_flag(sta, WLAN_STA_PS_STA);
1579 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1580 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1581 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1582 sta->sta.addr, sta->sta.aid);
1584 ieee80211_clear_fast_xmit(sta);
1586 if (!sta->sta.txq[0])
1589 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1590 struct ieee80211_txq *txq = sta->sta.txq[tid];
1592 ieee80211_unschedule_txq(&local->hw, txq, false);
1594 if (txq_has_queue(txq))
1595 set_bit(tid, &sta->txq_buffered_tids);
1597 clear_bit(tid, &sta->txq_buffered_tids);
1601 static void sta_ps_end(struct sta_info *sta)
1603 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1604 sta->sta.addr, sta->sta.aid);
1606 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1608 * Clear the flag only if the other one is still set
1609 * so that the TX path won't start TX'ing new frames
1610 * directly ... In the case that the driver flag isn't
1611 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1613 clear_sta_flag(sta, WLAN_STA_PS_STA);
1614 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1615 sta->sta.addr, sta->sta.aid);
1619 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1620 clear_sta_flag(sta, WLAN_STA_PS_STA);
1621 ieee80211_sta_ps_deliver_wakeup(sta);
1624 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1626 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1629 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1631 /* Don't let the same PS state be set twice */
1632 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1633 if ((start && in_ps) || (!start && !in_ps))
1643 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1645 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1647 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1649 if (test_sta_flag(sta, WLAN_STA_SP))
1652 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1653 ieee80211_sta_ps_deliver_poll_response(sta);
1655 set_sta_flag(sta, WLAN_STA_PSPOLL);
1657 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1659 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1661 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1662 int ac = ieee80211_ac_from_tid(tid);
1665 * If this AC is not trigger-enabled do nothing unless the
1666 * driver is calling us after it already checked.
1668 * NB: This could/should check a separate bitmap of trigger-
1669 * enabled queues, but for now we only implement uAPSD w/o
1670 * TSPEC changes to the ACs, so they're always the same.
1672 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1673 tid != IEEE80211_NUM_TIDS)
1676 /* if we are in a service period, do nothing */
1677 if (test_sta_flag(sta, WLAN_STA_SP))
1680 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1681 ieee80211_sta_ps_deliver_uapsd(sta);
1683 set_sta_flag(sta, WLAN_STA_UAPSD);
1685 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1687 static ieee80211_rx_result debug_noinline
1688 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1690 struct ieee80211_sub_if_data *sdata = rx->sdata;
1691 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1692 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1697 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1698 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1702 * The device handles station powersave, so don't do anything about
1703 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1704 * it to mac80211 since they're handled.)
1706 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1710 * Don't do anything if the station isn't already asleep. In
1711 * the uAPSD case, the station will probably be marked asleep,
1712 * in the PS-Poll case the station must be confused ...
1714 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1717 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1718 ieee80211_sta_pspoll(&rx->sta->sta);
1720 /* Free PS Poll skb here instead of returning RX_DROP that would
1721 * count as an dropped frame. */
1722 dev_kfree_skb(rx->skb);
1725 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1726 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1727 ieee80211_has_pm(hdr->frame_control) &&
1728 (ieee80211_is_data_qos(hdr->frame_control) ||
1729 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1730 u8 tid = ieee80211_get_tid(hdr);
1732 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1738 static ieee80211_rx_result debug_noinline
1739 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1741 struct sta_info *sta = rx->sta;
1742 struct sk_buff *skb = rx->skb;
1743 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1744 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1751 * Update last_rx only for IBSS packets which are for the current
1752 * BSSID and for station already AUTHORIZED to avoid keeping the
1753 * current IBSS network alive in cases where other STAs start
1754 * using different BSSID. This will also give the station another
1755 * chance to restart the authentication/authorization in case
1756 * something went wrong the first time.
1758 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1759 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1760 NL80211_IFTYPE_ADHOC);
1761 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1762 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1763 sta->rx_stats.last_rx = jiffies;
1764 if (ieee80211_is_data(hdr->frame_control) &&
1765 !is_multicast_ether_addr(hdr->addr1))
1766 sta->rx_stats.last_rate =
1767 sta_stats_encode_rate(status);
1769 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1770 sta->rx_stats.last_rx = jiffies;
1771 } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
1772 !is_multicast_ether_addr(hdr->addr1)) {
1774 * Mesh beacons will update last_rx when if they are found to
1775 * match the current local configuration when processed.
1777 sta->rx_stats.last_rx = jiffies;
1778 if (ieee80211_is_data(hdr->frame_control))
1779 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1782 sta->rx_stats.fragments++;
1784 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1785 sta->rx_stats.bytes += rx->skb->len;
1786 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1788 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1789 sta->rx_stats.last_signal = status->signal;
1790 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1793 if (status->chains) {
1794 sta->rx_stats.chains = status->chains;
1795 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1796 int signal = status->chain_signal[i];
1798 if (!(status->chains & BIT(i)))
1801 sta->rx_stats.chain_signal_last[i] = signal;
1802 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1807 if (ieee80211_is_s1g_beacon(hdr->frame_control))
1811 * Change STA power saving mode only at the end of a frame
1812 * exchange sequence, and only for a data or management
1813 * frame as specified in IEEE 802.11-2016 11.2.3.2
1815 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1816 !ieee80211_has_morefrags(hdr->frame_control) &&
1817 !is_multicast_ether_addr(hdr->addr1) &&
1818 (ieee80211_is_mgmt(hdr->frame_control) ||
1819 ieee80211_is_data(hdr->frame_control)) &&
1820 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1821 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1822 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1823 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1824 if (!ieee80211_has_pm(hdr->frame_control))
1827 if (ieee80211_has_pm(hdr->frame_control))
1832 /* mesh power save support */
1833 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1834 ieee80211_mps_rx_h_sta_process(sta, hdr);
1837 * Drop (qos-)data::nullfunc frames silently, since they
1838 * are used only to control station power saving mode.
1840 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1841 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1844 * If we receive a 4-addr nullfunc frame from a STA
1845 * that was not moved to a 4-addr STA vlan yet send
1846 * the event to userspace and for older hostapd drop
1847 * the frame to the monitor interface.
1849 if (ieee80211_has_a4(hdr->frame_control) &&
1850 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1851 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1852 !rx->sdata->u.vlan.sta))) {
1853 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1854 cfg80211_rx_unexpected_4addr_frame(
1855 rx->sdata->dev, sta->sta.addr,
1857 return RX_DROP_MONITOR;
1860 * Update counter and free packet here to avoid
1861 * counting this as a dropped packed.
1863 sta->rx_stats.packets++;
1864 dev_kfree_skb(rx->skb);
1869 } /* ieee80211_rx_h_sta_process */
1871 static struct ieee80211_key *
1872 ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
1874 struct ieee80211_key *key = NULL;
1875 struct ieee80211_sub_if_data *sdata = rx->sdata;
1878 /* Make sure key gets set if either BIGTK key index is set so that
1879 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1880 * Beacon frames and Beacon frames that claim to use another BIGTK key
1881 * index (i.e., a key that we do not have).
1885 idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1888 if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1895 key = rcu_dereference(rx->sta->gtk[idx]);
1897 key = rcu_dereference(sdata->keys[idx]);
1898 if (!key && rx->sta)
1899 key = rcu_dereference(rx->sta->gtk[idx2]);
1901 key = rcu_dereference(sdata->keys[idx2]);
1906 static ieee80211_rx_result debug_noinline
1907 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1909 struct sk_buff *skb = rx->skb;
1910 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1911 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1913 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1914 struct ieee80211_key *sta_ptk = NULL;
1915 struct ieee80211_key *ptk_idx = NULL;
1916 int mmie_keyidx = -1;
1918 const struct ieee80211_cipher_scheme *cs = NULL;
1920 if (ieee80211_is_ext(hdr->frame_control))
1926 * There are five types of keys:
1927 * - GTK (group keys)
1928 * - IGTK (group keys for management frames)
1929 * - BIGTK (group keys for Beacon frames)
1930 * - PTK (pairwise keys)
1931 * - STK (station-to-station pairwise keys)
1933 * When selecting a key, we have to distinguish between multicast
1934 * (including broadcast) and unicast frames, the latter can only
1935 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1936 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1937 * then unicast frames can also use key indices like GTKs. Hence, if we
1938 * don't have a PTK/STK we check the key index for a WEP key.
1940 * Note that in a regular BSS, multicast frames are sent by the
1941 * AP only, associated stations unicast the frame to the AP first
1942 * which then multicasts it on their behalf.
1944 * There is also a slight problem in IBSS mode: GTKs are negotiated
1945 * with each station, that is something we don't currently handle.
1946 * The spec seems to expect that one negotiates the same key with
1947 * every station but there's no such requirement; VLANs could be
1951 /* start without a key */
1953 fc = hdr->frame_control;
1956 int keyid = rx->sta->ptk_idx;
1957 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1959 if (ieee80211_has_protected(fc) &&
1960 !(status->flag & RX_FLAG_IV_STRIPPED)) {
1961 cs = rx->sta->cipher_scheme;
1962 keyid = ieee80211_get_keyid(rx->skb, cs);
1964 if (unlikely(keyid < 0))
1965 return RX_DROP_UNUSABLE;
1967 ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1971 if (!ieee80211_has_protected(fc))
1972 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1974 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1975 rx->key = ptk_idx ? ptk_idx : sta_ptk;
1976 if ((status->flag & RX_FLAG_DECRYPTED) &&
1977 (status->flag & RX_FLAG_IV_STRIPPED))
1979 /* Skip decryption if the frame is not protected. */
1980 if (!ieee80211_has_protected(fc))
1982 } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
1983 /* Broadcast/multicast robust management frame / BIP */
1984 if ((status->flag & RX_FLAG_DECRYPTED) &&
1985 (status->flag & RX_FLAG_IV_STRIPPED))
1988 if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
1989 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
1990 NUM_DEFAULT_BEACON_KEYS) {
1991 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1994 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1997 rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
1999 return RX_CONTINUE; /* Beacon protection not in use */
2000 } else if (mmie_keyidx >= 0) {
2001 /* Broadcast/multicast robust management frame / BIP */
2002 if ((status->flag & RX_FLAG_DECRYPTED) &&
2003 (status->flag & RX_FLAG_IV_STRIPPED))
2006 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
2007 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
2008 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
2010 if (ieee80211_is_group_privacy_action(skb) &&
2011 test_sta_flag(rx->sta, WLAN_STA_MFP))
2012 return RX_DROP_MONITOR;
2014 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
2017 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
2018 } else if (!ieee80211_has_protected(fc)) {
2020 * The frame was not protected, so skip decryption. However, we
2021 * need to set rx->key if there is a key that could have been
2022 * used so that the frame may be dropped if encryption would
2023 * have been expected.
2025 struct ieee80211_key *key = NULL;
2026 struct ieee80211_sub_if_data *sdata = rx->sdata;
2029 if (ieee80211_is_beacon(fc)) {
2030 key = ieee80211_rx_get_bigtk(rx, -1);
2031 } else if (ieee80211_is_mgmt(fc) &&
2032 is_multicast_ether_addr(hdr->addr1)) {
2033 key = rcu_dereference(rx->sdata->default_mgmt_key);
2036 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2037 key = rcu_dereference(rx->sta->gtk[i]);
2043 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2044 key = rcu_dereference(sdata->keys[i]);
2055 * The device doesn't give us the IV so we won't be
2056 * able to look up the key. That's ok though, we
2057 * don't need to decrypt the frame, we just won't
2058 * be able to keep statistics accurate.
2059 * Except for key threshold notifications, should
2060 * we somehow allow the driver to tell us which key
2061 * the hardware used if this flag is set?
2063 if ((status->flag & RX_FLAG_DECRYPTED) &&
2064 (status->flag & RX_FLAG_IV_STRIPPED))
2067 keyidx = ieee80211_get_keyid(rx->skb, cs);
2069 if (unlikely(keyidx < 0))
2070 return RX_DROP_UNUSABLE;
2072 /* check per-station GTK first, if multicast packet */
2073 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
2074 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
2076 /* if not found, try default key */
2078 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
2081 * RSNA-protected unicast frames should always be
2082 * sent with pairwise or station-to-station keys,
2083 * but for WEP we allow using a key index as well.
2086 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2087 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2088 !is_multicast_ether_addr(hdr->addr1))
2094 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2095 return RX_DROP_MONITOR;
2097 /* TODO: add threshold stuff again */
2099 return RX_DROP_MONITOR;
2102 switch (rx->key->conf.cipher) {
2103 case WLAN_CIPHER_SUITE_WEP40:
2104 case WLAN_CIPHER_SUITE_WEP104:
2105 result = ieee80211_crypto_wep_decrypt(rx);
2107 case WLAN_CIPHER_SUITE_TKIP:
2108 result = ieee80211_crypto_tkip_decrypt(rx);
2110 case WLAN_CIPHER_SUITE_CCMP:
2111 result = ieee80211_crypto_ccmp_decrypt(
2112 rx, IEEE80211_CCMP_MIC_LEN);
2114 case WLAN_CIPHER_SUITE_CCMP_256:
2115 result = ieee80211_crypto_ccmp_decrypt(
2116 rx, IEEE80211_CCMP_256_MIC_LEN);
2118 case WLAN_CIPHER_SUITE_AES_CMAC:
2119 result = ieee80211_crypto_aes_cmac_decrypt(rx);
2121 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2122 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2124 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2125 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2126 result = ieee80211_crypto_aes_gmac_decrypt(rx);
2128 case WLAN_CIPHER_SUITE_GCMP:
2129 case WLAN_CIPHER_SUITE_GCMP_256:
2130 result = ieee80211_crypto_gcmp_decrypt(rx);
2133 result = ieee80211_crypto_hw_decrypt(rx);
2136 /* the hdr variable is invalid after the decrypt handlers */
2138 /* either the frame has been decrypted or will be dropped */
2139 status->flag |= RX_FLAG_DECRYPTED;
2141 if (unlikely(ieee80211_is_beacon(fc) && result == RX_DROP_UNUSABLE))
2142 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2143 skb->data, skb->len);
2148 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2152 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2153 skb_queue_head_init(&cache->entries[i].skb_list);
2156 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2160 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2161 __skb_queue_purge(&cache->entries[i].skb_list);
2164 static inline struct ieee80211_fragment_entry *
2165 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2166 unsigned int frag, unsigned int seq, int rx_queue,
2167 struct sk_buff **skb)
2169 struct ieee80211_fragment_entry *entry;
2171 entry = &cache->entries[cache->next++];
2172 if (cache->next >= IEEE80211_FRAGMENT_MAX)
2175 __skb_queue_purge(&entry->skb_list);
2177 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2179 entry->first_frag_time = jiffies;
2181 entry->rx_queue = rx_queue;
2182 entry->last_frag = frag;
2183 entry->check_sequential_pn = false;
2184 entry->extra_len = 0;
2189 static inline struct ieee80211_fragment_entry *
2190 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2191 unsigned int frag, unsigned int seq,
2192 int rx_queue, struct ieee80211_hdr *hdr)
2194 struct ieee80211_fragment_entry *entry;
2198 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2199 struct ieee80211_hdr *f_hdr;
2200 struct sk_buff *f_skb;
2204 idx = IEEE80211_FRAGMENT_MAX - 1;
2206 entry = &cache->entries[idx];
2207 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2208 entry->rx_queue != rx_queue ||
2209 entry->last_frag + 1 != frag)
2212 f_skb = __skb_peek(&entry->skb_list);
2213 f_hdr = (struct ieee80211_hdr *) f_skb->data;
2216 * Check ftype and addresses are equal, else check next fragment
2218 if (((hdr->frame_control ^ f_hdr->frame_control) &
2219 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2220 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2221 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2224 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2225 __skb_queue_purge(&entry->skb_list);
2234 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2237 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2238 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2239 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2240 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2241 ieee80211_has_protected(fc);
2244 static ieee80211_rx_result debug_noinline
2245 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2247 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2248 struct ieee80211_hdr *hdr;
2251 unsigned int frag, seq;
2252 struct ieee80211_fragment_entry *entry;
2253 struct sk_buff *skb;
2254 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2256 hdr = (struct ieee80211_hdr *)rx->skb->data;
2257 fc = hdr->frame_control;
2259 if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
2262 sc = le16_to_cpu(hdr->seq_ctrl);
2263 frag = sc & IEEE80211_SCTL_FRAG;
2266 cache = &rx->sta->frags;
2268 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2271 if (is_multicast_ether_addr(hdr->addr1))
2272 return RX_DROP_MONITOR;
2274 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2276 if (skb_linearize(rx->skb))
2277 return RX_DROP_UNUSABLE;
2280 * skb_linearize() might change the skb->data and
2281 * previously cached variables (in this case, hdr) need to
2282 * be refreshed with the new data.
2284 hdr = (struct ieee80211_hdr *)rx->skb->data;
2285 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2288 /* This is the first fragment of a new frame. */
2289 entry = ieee80211_reassemble_add(cache, frag, seq,
2290 rx->seqno_idx, &(rx->skb));
2291 if (requires_sequential_pn(rx, fc)) {
2292 int queue = rx->security_idx;
2294 /* Store CCMP/GCMP PN so that we can verify that the
2295 * next fragment has a sequential PN value.
2297 entry->check_sequential_pn = true;
2298 entry->is_protected = true;
2299 entry->key_color = rx->key->color;
2300 memcpy(entry->last_pn,
2301 rx->key->u.ccmp.rx_pn[queue],
2302 IEEE80211_CCMP_PN_LEN);
2303 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2305 offsetof(struct ieee80211_key,
2307 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2308 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2309 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2310 IEEE80211_GCMP_PN_LEN);
2311 } else if (rx->key &&
2312 (ieee80211_has_protected(fc) ||
2313 (status->flag & RX_FLAG_DECRYPTED))) {
2314 entry->is_protected = true;
2315 entry->key_color = rx->key->color;
2320 /* This is a fragment for a frame that should already be pending in
2321 * fragment cache. Add this fragment to the end of the pending entry.
2323 entry = ieee80211_reassemble_find(cache, frag, seq,
2324 rx->seqno_idx, hdr);
2326 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2327 return RX_DROP_MONITOR;
2330 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2331 * MPDU PN values are not incrementing in steps of 1."
2332 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2333 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2335 if (entry->check_sequential_pn) {
2337 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2339 if (!requires_sequential_pn(rx, fc))
2340 return RX_DROP_UNUSABLE;
2342 /* Prevent mixed key and fragment cache attacks */
2343 if (entry->key_color != rx->key->color)
2344 return RX_DROP_UNUSABLE;
2346 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2347 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2353 rpn = rx->ccm_gcm.pn;
2354 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2355 return RX_DROP_UNUSABLE;
2356 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2357 } else if (entry->is_protected &&
2359 (!ieee80211_has_protected(fc) &&
2360 !(status->flag & RX_FLAG_DECRYPTED)) ||
2361 rx->key->color != entry->key_color)) {
2362 /* Drop this as a mixed key or fragment cache attack, even
2363 * if for TKIP Michael MIC should protect us, and WEP is a
2364 * lost cause anyway.
2366 return RX_DROP_UNUSABLE;
2367 } else if (entry->is_protected && rx->key &&
2368 entry->key_color != rx->key->color &&
2369 (status->flag & RX_FLAG_DECRYPTED)) {
2370 return RX_DROP_UNUSABLE;
2373 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2374 __skb_queue_tail(&entry->skb_list, rx->skb);
2375 entry->last_frag = frag;
2376 entry->extra_len += rx->skb->len;
2377 if (ieee80211_has_morefrags(fc)) {
2382 rx->skb = __skb_dequeue(&entry->skb_list);
2383 if (skb_tailroom(rx->skb) < entry->extra_len) {
2384 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2385 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2387 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2388 __skb_queue_purge(&entry->skb_list);
2389 return RX_DROP_UNUSABLE;
2392 while ((skb = __skb_dequeue(&entry->skb_list))) {
2393 skb_put_data(rx->skb, skb->data, skb->len);
2398 ieee80211_led_rx(rx->local);
2400 rx->sta->rx_stats.packets++;
2404 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2406 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2412 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2414 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
2415 struct sk_buff *skb = rx->skb;
2416 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2419 * Pass through unencrypted frames if the hardware has
2420 * decrypted them already.
2422 if (status->flag & RX_FLAG_DECRYPTED)
2425 /* check mesh EAPOL frames first */
2426 if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
2427 ieee80211_is_data(fc))) {
2428 struct ieee80211s_hdr *mesh_hdr;
2429 u16 hdr_len = ieee80211_hdrlen(fc);
2430 u16 ethertype_offset;
2433 if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
2436 /* make sure fixed part of mesh header is there, also checks skb len */
2437 if (!pskb_may_pull(rx->skb, hdr_len + 6))
2440 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
2441 ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
2442 sizeof(rfc1042_header);
2444 if (skb_copy_bits(rx->skb, ethertype_offset, ðertype, 2) == 0 &&
2445 ethertype == rx->sdata->control_port_protocol)
2450 /* Drop unencrypted frames if key is set. */
2451 if (unlikely(!ieee80211_has_protected(fc) &&
2452 !ieee80211_is_any_nullfunc(fc) &&
2453 ieee80211_is_data(fc) && rx->key))
2459 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2461 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2462 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2463 __le16 fc = hdr->frame_control;
2466 * Pass through unencrypted frames if the hardware has
2467 * decrypted them already.
2469 if (status->flag & RX_FLAG_DECRYPTED)
2472 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2473 if (unlikely(!ieee80211_has_protected(fc) &&
2474 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2476 if (ieee80211_is_deauth(fc) ||
2477 ieee80211_is_disassoc(fc))
2478 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2483 /* BIP does not use Protected field, so need to check MMIE */
2484 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2485 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2486 if (ieee80211_is_deauth(fc) ||
2487 ieee80211_is_disassoc(fc))
2488 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2493 if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
2494 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2495 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2501 * When using MFP, Action frames are not allowed prior to
2502 * having configured keys.
2504 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2505 ieee80211_is_robust_mgmt_frame(rx->skb)))
2513 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2515 struct ieee80211_sub_if_data *sdata = rx->sdata;
2516 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2517 bool check_port_control = false;
2518 struct ethhdr *ehdr;
2521 *port_control = false;
2522 if (ieee80211_has_a4(hdr->frame_control) &&
2523 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2526 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2527 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2529 if (!sdata->u.mgd.use_4addr)
2531 else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2532 check_port_control = true;
2535 if (is_multicast_ether_addr(hdr->addr1) &&
2536 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2539 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2543 ehdr = (struct ethhdr *) rx->skb->data;
2544 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2545 *port_control = true;
2546 else if (check_port_control)
2553 * requires that rx->skb is a frame with ethernet header
2555 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2557 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2558 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2559 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2562 * Allow EAPOL frames to us/the PAE group address regardless of
2563 * whether the frame was encrypted or not, and always disallow
2564 * all other destination addresses for them.
2566 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2567 return ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2568 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2570 if (ieee80211_802_1x_port_control(rx) ||
2571 ieee80211_drop_unencrypted(rx, fc))
2577 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2578 struct ieee80211_rx_data *rx)
2580 struct ieee80211_sub_if_data *sdata = rx->sdata;
2581 struct net_device *dev = sdata->dev;
2583 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2584 (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
2585 !sdata->control_port_no_preauth)) &&
2586 sdata->control_port_over_nl80211)) {
2587 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2588 bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2590 cfg80211_rx_control_port(dev, skb, noencrypt);
2593 struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2595 memset(skb->cb, 0, sizeof(skb->cb));
2598 * 802.1X over 802.11 requires that the authenticator address
2599 * be used for EAPOL frames. However, 802.1X allows the use of
2600 * the PAE group address instead. If the interface is part of
2601 * a bridge and we pass the frame with the PAE group address,
2602 * then the bridge will forward it to the network (even if the
2603 * client was not associated yet), which isn't supposed to
2605 * To avoid that, rewrite the destination address to our own
2606 * address, so that the authenticator (e.g. hostapd) will see
2607 * the frame, but bridge won't forward it anywhere else. Note
2608 * that due to earlier filtering, the only other address can
2609 * be the PAE group address, unless the hardware allowed them
2610 * through in 802.3 offloaded mode.
2612 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2613 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2614 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2616 /* deliver to local stack */
2618 list_add_tail(&skb->list, rx->list);
2620 netif_receive_skb(skb);
2625 * requires that rx->skb is a frame with ethernet header
2628 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2630 struct ieee80211_sub_if_data *sdata = rx->sdata;
2631 struct net_device *dev = sdata->dev;
2632 struct sk_buff *skb, *xmit_skb;
2633 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2634 struct sta_info *dsta;
2639 dev_sw_netstats_rx_add(dev, skb->len);
2642 /* The seqno index has the same property as needed
2643 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2644 * for non-QoS-data frames. Here we know it's a data
2645 * frame, so count MSDUs.
2647 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
2648 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2649 u64_stats_update_end(&rx->sta->rx_stats.syncp);
2652 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2653 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2654 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2655 ehdr->h_proto != rx->sdata->control_port_protocol &&
2656 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2657 if (is_multicast_ether_addr(ehdr->h_dest) &&
2658 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2660 * send multicast frames both to higher layers in
2661 * local net stack and back to the wireless medium
2663 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2665 net_info_ratelimited("%s: failed to clone multicast frame\n",
2667 } else if (!is_multicast_ether_addr(ehdr->h_dest) &&
2668 !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
2669 dsta = sta_info_get(sdata, ehdr->h_dest);
2672 * The destination station is associated to
2673 * this AP (in this VLAN), so send the frame
2674 * directly to it and do not pass it to local
2683 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2685 /* 'align' will only take the values 0 or 2 here since all
2686 * frames are required to be aligned to 2-byte boundaries
2687 * when being passed to mac80211; the code here works just
2688 * as well if that isn't true, but mac80211 assumes it can
2689 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2693 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2695 if (WARN_ON(skb_headroom(skb) < 3)) {
2699 u8 *data = skb->data;
2700 size_t len = skb_headlen(skb);
2702 memmove(skb->data, data, len);
2703 skb_set_tail_pointer(skb, len);
2710 skb->protocol = eth_type_trans(skb, dev);
2711 ieee80211_deliver_skb_to_local_stack(skb, rx);
2716 * Send to wireless media and increase priority by 256 to
2717 * keep the received priority instead of reclassifying
2718 * the frame (see cfg80211_classify8021d).
2720 xmit_skb->priority += 256;
2721 xmit_skb->protocol = htons(ETH_P_802_3);
2722 skb_reset_network_header(xmit_skb);
2723 skb_reset_mac_header(xmit_skb);
2724 dev_queue_xmit(xmit_skb);
2728 static ieee80211_rx_result debug_noinline
2729 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2731 struct net_device *dev = rx->sdata->dev;
2732 struct sk_buff *skb = rx->skb;
2733 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2734 __le16 fc = hdr->frame_control;
2735 struct sk_buff_head frame_list;
2736 struct ethhdr ethhdr;
2737 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2739 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2742 } else switch (rx->sdata->vif.type) {
2743 case NL80211_IFTYPE_AP:
2744 case NL80211_IFTYPE_AP_VLAN:
2747 case NL80211_IFTYPE_STATION:
2749 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2752 case NL80211_IFTYPE_MESH_POINT:
2760 __skb_queue_head_init(&frame_list);
2762 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2763 rx->sdata->vif.addr,
2764 rx->sdata->vif.type,
2766 return RX_DROP_UNUSABLE;
2768 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2769 rx->sdata->vif.type,
2770 rx->local->hw.extra_tx_headroom,
2771 check_da, check_sa);
2773 while (!skb_queue_empty(&frame_list)) {
2774 rx->skb = __skb_dequeue(&frame_list);
2776 if (!ieee80211_frame_allowed(rx, fc)) {
2777 dev_kfree_skb(rx->skb);
2781 ieee80211_deliver_skb(rx);
2787 static ieee80211_rx_result debug_noinline
2788 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2790 struct sk_buff *skb = rx->skb;
2791 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2792 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2793 __le16 fc = hdr->frame_control;
2795 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2798 if (unlikely(!ieee80211_is_data(fc)))
2801 if (unlikely(!ieee80211_is_data_present(fc)))
2802 return RX_DROP_MONITOR;
2804 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2805 switch (rx->sdata->vif.type) {
2806 case NL80211_IFTYPE_AP_VLAN:
2807 if (!rx->sdata->u.vlan.sta)
2808 return RX_DROP_UNUSABLE;
2810 case NL80211_IFTYPE_STATION:
2811 if (!rx->sdata->u.mgd.use_4addr)
2812 return RX_DROP_UNUSABLE;
2815 return RX_DROP_UNUSABLE;
2819 if (is_multicast_ether_addr(hdr->addr1))
2820 return RX_DROP_UNUSABLE;
2824 * We should not receive A-MSDUs on pre-HT connections,
2825 * and HT connections cannot use old ciphers. Thus drop
2826 * them, as in those cases we couldn't even have SPP
2829 switch (rx->key->conf.cipher) {
2830 case WLAN_CIPHER_SUITE_WEP40:
2831 case WLAN_CIPHER_SUITE_WEP104:
2832 case WLAN_CIPHER_SUITE_TKIP:
2833 return RX_DROP_UNUSABLE;
2839 return __ieee80211_rx_h_amsdu(rx, 0);
2842 #ifdef CONFIG_MAC80211_MESH
2843 static ieee80211_rx_result
2844 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2846 struct ieee80211_hdr *fwd_hdr, *hdr;
2847 struct ieee80211_tx_info *info;
2848 struct ieee80211s_hdr *mesh_hdr;
2849 struct sk_buff *skb = rx->skb, *fwd_skb;
2850 struct ieee80211_local *local = rx->local;
2851 struct ieee80211_sub_if_data *sdata = rx->sdata;
2852 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2856 hdr = (struct ieee80211_hdr *) skb->data;
2857 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2859 /* make sure fixed part of mesh header is there, also checks skb len */
2860 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2861 return RX_DROP_MONITOR;
2863 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2865 /* make sure full mesh header is there, also checks skb len */
2866 if (!pskb_may_pull(rx->skb,
2867 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2868 return RX_DROP_MONITOR;
2870 /* reload pointers */
2871 hdr = (struct ieee80211_hdr *) skb->data;
2872 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2874 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2875 return RX_DROP_MONITOR;
2877 /* frame is in RMC, don't forward */
2878 if (ieee80211_is_data(hdr->frame_control) &&
2879 is_multicast_ether_addr(hdr->addr1) &&
2880 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2881 return RX_DROP_MONITOR;
2883 if (!ieee80211_is_data(hdr->frame_control))
2887 return RX_DROP_MONITOR;
2889 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2890 struct mesh_path *mppath;
2894 if (is_multicast_ether_addr(hdr->addr1)) {
2895 mpp_addr = hdr->addr3;
2896 proxied_addr = mesh_hdr->eaddr1;
2897 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2898 MESH_FLAGS_AE_A5_A6) {
2899 /* has_a4 already checked in ieee80211_rx_mesh_check */
2900 mpp_addr = hdr->addr4;
2901 proxied_addr = mesh_hdr->eaddr2;
2903 return RX_DROP_MONITOR;
2907 mppath = mpp_path_lookup(sdata, proxied_addr);
2909 mpp_path_add(sdata, proxied_addr, mpp_addr);
2911 spin_lock_bh(&mppath->state_lock);
2912 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2913 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2914 mppath->exp_time = jiffies;
2915 spin_unlock_bh(&mppath->state_lock);
2920 /* Frame has reached destination. Don't forward */
2921 if (!is_multicast_ether_addr(hdr->addr1) &&
2922 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2925 ac = ieee802_1d_to_ac[skb->priority];
2926 q = sdata->vif.hw_queue[ac];
2927 if (ieee80211_queue_stopped(&local->hw, q)) {
2928 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2929 return RX_DROP_MONITOR;
2931 skb_set_queue_mapping(skb, ac);
2933 if (!--mesh_hdr->ttl) {
2934 if (!is_multicast_ether_addr(hdr->addr1))
2935 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2936 dropped_frames_ttl);
2940 if (!ifmsh->mshcfg.dot11MeshForwarding)
2943 if (sdata->crypto_tx_tailroom_needed_cnt)
2944 tailroom = IEEE80211_ENCRYPT_TAILROOM;
2946 fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2947 sdata->encrypt_headroom,
2948 tailroom, GFP_ATOMIC);
2952 fwd_skb->dev = sdata->dev;
2953 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2954 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2955 info = IEEE80211_SKB_CB(fwd_skb);
2956 memset(info, 0, sizeof(*info));
2957 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
2958 info->control.vif = &rx->sdata->vif;
2959 info->control.jiffies = jiffies;
2960 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2961 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2962 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2963 /* update power mode indication when forwarding */
2964 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2965 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2966 /* mesh power mode flags updated in mesh_nexthop_lookup */
2967 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2969 /* unable to resolve next hop */
2970 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2972 WLAN_REASON_MESH_PATH_NOFORWARD,
2974 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2976 return RX_DROP_MONITOR;
2979 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2980 ieee80211_add_pending_skb(local, fwd_skb);
2982 if (is_multicast_ether_addr(hdr->addr1))
2984 return RX_DROP_MONITOR;
2988 static ieee80211_rx_result debug_noinline
2989 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2991 struct ieee80211_sub_if_data *sdata = rx->sdata;
2992 struct ieee80211_local *local = rx->local;
2993 struct net_device *dev = sdata->dev;
2994 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2995 __le16 fc = hdr->frame_control;
2999 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
3002 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
3003 return RX_DROP_MONITOR;
3006 * Send unexpected-4addr-frame event to hostapd. For older versions,
3007 * also drop the frame to cooked monitor interfaces.
3009 if (ieee80211_has_a4(hdr->frame_control) &&
3010 sdata->vif.type == NL80211_IFTYPE_AP) {
3012 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
3013 cfg80211_rx_unexpected_4addr_frame(
3014 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
3015 return RX_DROP_MONITOR;
3018 err = __ieee80211_data_to_8023(rx, &port_control);
3020 return RX_DROP_UNUSABLE;
3022 if (!ieee80211_frame_allowed(rx, fc))
3023 return RX_DROP_MONITOR;
3025 /* directly handle TDLS channel switch requests/responses */
3026 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
3027 cpu_to_be16(ETH_P_TDLS))) {
3028 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
3030 if (pskb_may_pull(rx->skb,
3031 offsetof(struct ieee80211_tdls_data, u)) &&
3032 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
3033 tf->category == WLAN_CATEGORY_TDLS &&
3034 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
3035 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
3036 rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
3037 __ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3042 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3043 unlikely(port_control) && sdata->bss) {
3044 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
3052 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3053 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
3054 !is_multicast_ether_addr(
3055 ((struct ethhdr *)rx->skb->data)->h_dest) &&
3056 (!local->scanning &&
3057 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
3058 mod_timer(&local->dynamic_ps_timer, jiffies +
3059 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
3061 ieee80211_deliver_skb(rx);
3066 static ieee80211_rx_result debug_noinline
3067 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
3069 struct sk_buff *skb = rx->skb;
3070 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
3071 struct tid_ampdu_rx *tid_agg_rx;
3075 if (likely(!ieee80211_is_ctl(bar->frame_control)))
3078 if (ieee80211_is_back_req(bar->frame_control)) {
3080 __le16 control, start_seq_num;
3081 } __packed bar_data;
3082 struct ieee80211_event event = {
3083 .type = BAR_RX_EVENT,
3087 return RX_DROP_MONITOR;
3089 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
3090 &bar_data, sizeof(bar_data)))
3091 return RX_DROP_MONITOR;
3093 tid = le16_to_cpu(bar_data.control) >> 12;
3095 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
3096 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
3097 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
3098 WLAN_BACK_RECIPIENT,
3099 WLAN_REASON_QSTA_REQUIRE_SETUP);
3101 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
3103 return RX_DROP_MONITOR;
3105 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
3106 event.u.ba.tid = tid;
3107 event.u.ba.ssn = start_seq_num;
3108 event.u.ba.sta = &rx->sta->sta;
3110 /* reset session timer */
3111 if (tid_agg_rx->timeout)
3112 mod_timer(&tid_agg_rx->session_timer,
3113 TU_TO_EXP_TIME(tid_agg_rx->timeout));
3115 spin_lock(&tid_agg_rx->reorder_lock);
3116 /* release stored frames up to start of BAR */
3117 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
3118 start_seq_num, frames);
3119 spin_unlock(&tid_agg_rx->reorder_lock);
3121 drv_event_callback(rx->local, rx->sdata, &event);
3128 * After this point, we only want management frames,
3129 * so we can drop all remaining control frames to
3130 * cooked monitor interfaces.
3132 return RX_DROP_MONITOR;
3135 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
3136 struct ieee80211_mgmt *mgmt,
3139 struct ieee80211_local *local = sdata->local;
3140 struct sk_buff *skb;
3141 struct ieee80211_mgmt *resp;
3143 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
3144 /* Not to own unicast address */
3148 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
3149 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
3150 /* Not from the current AP or not associated yet. */
3154 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3155 /* Too short SA Query request frame */
3159 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3163 skb_reserve(skb, local->hw.extra_tx_headroom);
3164 resp = skb_put_zero(skb, 24);
3165 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3166 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3167 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3168 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3169 IEEE80211_STYPE_ACTION);
3170 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3171 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3172 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3173 memcpy(resp->u.action.u.sa_query.trans_id,
3174 mgmt->u.action.u.sa_query.trans_id,
3175 WLAN_SA_QUERY_TR_ID_LEN);
3177 ieee80211_tx_skb(sdata, skb);
3180 static ieee80211_rx_result debug_noinline
3181 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3183 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3184 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3186 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
3190 * From here on, look only at management frames.
3191 * Data and control frames are already handled,
3192 * and unknown (reserved) frames are useless.
3194 if (rx->skb->len < 24)
3195 return RX_DROP_MONITOR;
3197 if (!ieee80211_is_mgmt(mgmt->frame_control))
3198 return RX_DROP_MONITOR;
3200 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3201 ieee80211_is_beacon(mgmt->frame_control) &&
3202 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3205 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3206 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3207 sig = status->signal;
3209 cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3210 rx->skb->data, rx->skb->len,
3211 ieee80211_rx_status_to_khz(status),
3213 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3216 if (ieee80211_drop_unencrypted_mgmt(rx))
3217 return RX_DROP_UNUSABLE;
3223 ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
3225 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
3226 struct ieee80211_sub_if_data *sdata = rx->sdata;
3228 /* TWT actions are only supported in AP for the moment */
3229 if (sdata->vif.type != NL80211_IFTYPE_AP)
3232 if (!rx->local->ops->add_twt_setup)
3235 if (!sdata->vif.bss_conf.twt_responder)
3241 switch (mgmt->u.action.u.s1g.action_code) {
3242 case WLAN_S1G_TWT_SETUP: {
3243 struct ieee80211_twt_setup *twt;
3245 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3246 1 + /* action code */
3247 sizeof(struct ieee80211_twt_setup) +
3248 2 /* TWT req_type agrt */)
3251 twt = (void *)mgmt->u.action.u.s1g.variable;
3252 if (twt->element_id != WLAN_EID_S1G_TWT)
3255 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3256 4 + /* action code + token + tlv */
3260 return true; /* queue the frame */
3262 case WLAN_S1G_TWT_TEARDOWN:
3263 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
3266 return true; /* queue the frame */
3274 static ieee80211_rx_result debug_noinline
3275 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3277 struct ieee80211_local *local = rx->local;
3278 struct ieee80211_sub_if_data *sdata = rx->sdata;
3279 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3280 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3281 int len = rx->skb->len;
3283 if (!ieee80211_is_action(mgmt->frame_control))
3286 /* drop too small frames */
3287 if (len < IEEE80211_MIN_ACTION_SIZE)
3288 return RX_DROP_UNUSABLE;
3290 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3291 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3292 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3293 return RX_DROP_UNUSABLE;
3295 switch (mgmt->u.action.category) {
3296 case WLAN_CATEGORY_HT:
3297 /* reject HT action frames from stations not supporting HT */
3298 if (!rx->sta->sta.ht_cap.ht_supported)
3301 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3302 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3303 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3304 sdata->vif.type != NL80211_IFTYPE_AP &&
3305 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3308 /* verify action & smps_control/chanwidth are present */
3309 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3312 switch (mgmt->u.action.u.ht_smps.action) {
3313 case WLAN_HT_ACTION_SMPS: {
3314 struct ieee80211_supported_band *sband;
3315 enum ieee80211_smps_mode smps_mode;
3316 struct sta_opmode_info sta_opmode = {};
3318 if (sdata->vif.type != NL80211_IFTYPE_AP &&
3319 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3322 /* convert to HT capability */
3323 switch (mgmt->u.action.u.ht_smps.smps_control) {
3324 case WLAN_HT_SMPS_CONTROL_DISABLED:
3325 smps_mode = IEEE80211_SMPS_OFF;
3327 case WLAN_HT_SMPS_CONTROL_STATIC:
3328 smps_mode = IEEE80211_SMPS_STATIC;
3330 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3331 smps_mode = IEEE80211_SMPS_DYNAMIC;
3337 /* if no change do nothing */
3338 if (rx->sta->sta.smps_mode == smps_mode)
3340 rx->sta->sta.smps_mode = smps_mode;
3341 sta_opmode.smps_mode =
3342 ieee80211_smps_mode_to_smps_mode(smps_mode);
3343 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3345 sband = rx->local->hw.wiphy->bands[status->band];
3347 rate_control_rate_update(local, sband, rx->sta,
3348 IEEE80211_RC_SMPS_CHANGED);
3349 cfg80211_sta_opmode_change_notify(sdata->dev,
3355 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3356 struct ieee80211_supported_band *sband;
3357 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3358 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3359 struct sta_opmode_info sta_opmode = {};
3361 /* If it doesn't support 40 MHz it can't change ... */
3362 if (!(rx->sta->sta.ht_cap.cap &
3363 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3366 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3367 max_bw = IEEE80211_STA_RX_BW_20;
3369 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
3371 /* set cur_max_bandwidth and recalc sta bw */
3372 rx->sta->cur_max_bandwidth = max_bw;
3373 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
3375 if (rx->sta->sta.bandwidth == new_bw)
3378 rx->sta->sta.bandwidth = new_bw;
3379 sband = rx->local->hw.wiphy->bands[status->band];
3381 ieee80211_sta_rx_bw_to_chan_width(rx->sta);
3382 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3384 rate_control_rate_update(local, sband, rx->sta,
3385 IEEE80211_RC_BW_CHANGED);
3386 cfg80211_sta_opmode_change_notify(sdata->dev,
3397 case WLAN_CATEGORY_PUBLIC:
3398 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3400 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3404 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3406 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3407 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3409 if (len < offsetof(struct ieee80211_mgmt,
3410 u.action.u.ext_chan_switch.variable))
3413 case WLAN_CATEGORY_VHT:
3414 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3415 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3416 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3417 sdata->vif.type != NL80211_IFTYPE_AP &&
3418 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3421 /* verify action code is present */
3422 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3425 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3426 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3427 /* verify opmode is present */
3428 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3432 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3433 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3441 case WLAN_CATEGORY_BACK:
3442 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3443 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3444 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3445 sdata->vif.type != NL80211_IFTYPE_AP &&
3446 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3449 /* verify action_code is present */
3450 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3453 switch (mgmt->u.action.u.addba_req.action_code) {
3454 case WLAN_ACTION_ADDBA_REQ:
3455 if (len < (IEEE80211_MIN_ACTION_SIZE +
3456 sizeof(mgmt->u.action.u.addba_req)))
3459 case WLAN_ACTION_ADDBA_RESP:
3460 if (len < (IEEE80211_MIN_ACTION_SIZE +
3461 sizeof(mgmt->u.action.u.addba_resp)))
3464 case WLAN_ACTION_DELBA:
3465 if (len < (IEEE80211_MIN_ACTION_SIZE +
3466 sizeof(mgmt->u.action.u.delba)))
3474 case WLAN_CATEGORY_SPECTRUM_MGMT:
3475 /* verify action_code is present */
3476 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3479 switch (mgmt->u.action.u.measurement.action_code) {
3480 case WLAN_ACTION_SPCT_MSR_REQ:
3481 if (status->band != NL80211_BAND_5GHZ)
3484 if (len < (IEEE80211_MIN_ACTION_SIZE +
3485 sizeof(mgmt->u.action.u.measurement)))
3488 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3491 ieee80211_process_measurement_req(sdata, mgmt, len);
3493 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3495 if (len < (IEEE80211_MIN_ACTION_SIZE +
3496 sizeof(mgmt->u.action.u.chan_switch)))
3499 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3500 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3501 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3504 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3505 bssid = sdata->u.mgd.bssid;
3506 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3507 bssid = sdata->u.ibss.bssid;
3508 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3513 if (!ether_addr_equal(mgmt->bssid, bssid))
3520 case WLAN_CATEGORY_SELF_PROTECTED:
3521 if (len < (IEEE80211_MIN_ACTION_SIZE +
3522 sizeof(mgmt->u.action.u.self_prot.action_code)))
3525 switch (mgmt->u.action.u.self_prot.action_code) {
3526 case WLAN_SP_MESH_PEERING_OPEN:
3527 case WLAN_SP_MESH_PEERING_CLOSE:
3528 case WLAN_SP_MESH_PEERING_CONFIRM:
3529 if (!ieee80211_vif_is_mesh(&sdata->vif))
3531 if (sdata->u.mesh.user_mpm)
3532 /* userspace handles this frame */
3535 case WLAN_SP_MGK_INFORM:
3536 case WLAN_SP_MGK_ACK:
3537 if (!ieee80211_vif_is_mesh(&sdata->vif))
3542 case WLAN_CATEGORY_MESH_ACTION:
3543 if (len < (IEEE80211_MIN_ACTION_SIZE +
3544 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3547 if (!ieee80211_vif_is_mesh(&sdata->vif))
3549 if (mesh_action_is_path_sel(mgmt) &&
3550 !mesh_path_sel_is_hwmp(sdata))
3553 case WLAN_CATEGORY_S1G:
3554 switch (mgmt->u.action.u.s1g.action_code) {
3555 case WLAN_S1G_TWT_SETUP:
3556 case WLAN_S1G_TWT_TEARDOWN:
3557 if (ieee80211_process_rx_twt_action(rx))
3569 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3570 /* will return in the next handlers */
3575 rx->sta->rx_stats.packets++;
3576 dev_kfree_skb(rx->skb);
3580 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3584 static ieee80211_rx_result debug_noinline
3585 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3587 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3590 /* skip known-bad action frames and return them in the next handler */
3591 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3595 * Getting here means the kernel doesn't know how to handle
3596 * it, but maybe userspace does ... include returned frames
3597 * so userspace can register for those to know whether ones
3598 * it transmitted were processed or returned.
3601 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3602 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3603 sig = status->signal;
3605 if (cfg80211_rx_mgmt_khz(&rx->sdata->wdev,
3606 ieee80211_rx_status_to_khz(status), sig,
3607 rx->skb->data, rx->skb->len, 0)) {
3609 rx->sta->rx_stats.packets++;
3610 dev_kfree_skb(rx->skb);
3617 static ieee80211_rx_result debug_noinline
3618 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
3620 struct ieee80211_sub_if_data *sdata = rx->sdata;
3621 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3622 int len = rx->skb->len;
3624 if (!ieee80211_is_action(mgmt->frame_control))
3627 switch (mgmt->u.action.category) {
3628 case WLAN_CATEGORY_SA_QUERY:
3629 if (len < (IEEE80211_MIN_ACTION_SIZE +
3630 sizeof(mgmt->u.action.u.sa_query)))
3633 switch (mgmt->u.action.u.sa_query.action) {
3634 case WLAN_ACTION_SA_QUERY_REQUEST:
3635 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3637 ieee80211_process_sa_query_req(sdata, mgmt, len);
3647 rx->sta->rx_stats.packets++;
3648 dev_kfree_skb(rx->skb);
3652 static ieee80211_rx_result debug_noinline
3653 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3655 struct ieee80211_local *local = rx->local;
3656 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3657 struct sk_buff *nskb;
3658 struct ieee80211_sub_if_data *sdata = rx->sdata;
3659 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3661 if (!ieee80211_is_action(mgmt->frame_control))
3665 * For AP mode, hostapd is responsible for handling any action
3666 * frames that we didn't handle, including returning unknown
3667 * ones. For all other modes we will return them to the sender,
3668 * setting the 0x80 bit in the action category, as required by
3669 * 802.11-2012 9.24.4.
3670 * Newer versions of hostapd shall also use the management frame
3671 * registration mechanisms, but older ones still use cooked
3672 * monitor interfaces so push all frames there.
3674 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3675 (sdata->vif.type == NL80211_IFTYPE_AP ||
3676 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3677 return RX_DROP_MONITOR;
3679 if (is_multicast_ether_addr(mgmt->da))
3680 return RX_DROP_MONITOR;
3682 /* do not return rejected action frames */
3683 if (mgmt->u.action.category & 0x80)
3684 return RX_DROP_UNUSABLE;
3686 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3689 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3691 nmgmt->u.action.category |= 0x80;
3692 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3693 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3695 memset(nskb->cb, 0, sizeof(nskb->cb));
3697 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3698 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3700 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3701 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3702 IEEE80211_TX_CTL_NO_CCK_RATE;
3703 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3705 local->hw.offchannel_tx_hw_queue;
3708 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3711 dev_kfree_skb(rx->skb);
3715 static ieee80211_rx_result debug_noinline
3716 ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
3718 struct ieee80211_sub_if_data *sdata = rx->sdata;
3719 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
3721 if (!ieee80211_is_ext(hdr->frame_control))
3724 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3725 return RX_DROP_MONITOR;
3727 /* for now only beacons are ext, so queue them */
3728 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3733 static ieee80211_rx_result debug_noinline
3734 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3736 struct ieee80211_sub_if_data *sdata = rx->sdata;
3737 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3740 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3742 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3743 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3744 sdata->vif.type != NL80211_IFTYPE_OCB &&
3745 sdata->vif.type != NL80211_IFTYPE_STATION)
3746 return RX_DROP_MONITOR;
3749 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3750 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3751 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3752 /* process for all: mesh, mlme, ibss */
3754 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3755 if (is_multicast_ether_addr(mgmt->da) &&
3756 !is_broadcast_ether_addr(mgmt->da))
3757 return RX_DROP_MONITOR;
3759 /* process only for station/IBSS */
3760 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3761 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3762 return RX_DROP_MONITOR;
3764 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3765 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3766 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3767 if (is_multicast_ether_addr(mgmt->da) &&
3768 !is_broadcast_ether_addr(mgmt->da))
3769 return RX_DROP_MONITOR;
3771 /* process only for station */
3772 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3773 return RX_DROP_MONITOR;
3775 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3776 /* process only for ibss and mesh */
3777 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3778 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3779 return RX_DROP_MONITOR;
3782 return RX_DROP_MONITOR;
3785 ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3790 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3791 struct ieee80211_rate *rate)
3793 struct ieee80211_sub_if_data *sdata;
3794 struct ieee80211_local *local = rx->local;
3795 struct sk_buff *skb = rx->skb, *skb2;
3796 struct net_device *prev_dev = NULL;
3797 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3798 int needed_headroom;
3801 * If cooked monitor has been processed already, then
3802 * don't do it again. If not, set the flag.
3804 if (rx->flags & IEEE80211_RX_CMNTR)
3806 rx->flags |= IEEE80211_RX_CMNTR;
3808 /* If there are no cooked monitor interfaces, just free the SKB */
3809 if (!local->cooked_mntrs)
3812 /* vendor data is long removed here */
3813 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3814 /* room for the radiotap header based on driver features */
3815 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3817 if (skb_headroom(skb) < needed_headroom &&
3818 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3821 /* prepend radiotap information */
3822 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3825 skb_reset_mac_header(skb);
3826 skb->ip_summed = CHECKSUM_UNNECESSARY;
3827 skb->pkt_type = PACKET_OTHERHOST;
3828 skb->protocol = htons(ETH_P_802_2);
3830 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3831 if (!ieee80211_sdata_running(sdata))
3834 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3835 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3839 skb2 = skb_clone(skb, GFP_ATOMIC);
3841 skb2->dev = prev_dev;
3842 netif_receive_skb(skb2);
3846 prev_dev = sdata->dev;
3847 dev_sw_netstats_rx_add(sdata->dev, skb->len);
3851 skb->dev = prev_dev;
3852 netif_receive_skb(skb);
3860 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3861 ieee80211_rx_result res)
3864 case RX_DROP_MONITOR:
3865 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3867 rx->sta->rx_stats.dropped++;
3870 struct ieee80211_rate *rate = NULL;
3871 struct ieee80211_supported_band *sband;
3872 struct ieee80211_rx_status *status;
3874 status = IEEE80211_SKB_RXCB((rx->skb));
3876 sband = rx->local->hw.wiphy->bands[status->band];
3877 if (status->encoding == RX_ENC_LEGACY)
3878 rate = &sband->bitrates[status->rate_idx];
3880 ieee80211_rx_cooked_monitor(rx, rate);
3883 case RX_DROP_UNUSABLE:
3884 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3886 rx->sta->rx_stats.dropped++;
3887 dev_kfree_skb(rx->skb);
3890 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3895 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3896 struct sk_buff_head *frames)
3898 ieee80211_rx_result res = RX_DROP_MONITOR;
3899 struct sk_buff *skb;
3901 #define CALL_RXH(rxh) \
3904 if (res != RX_CONTINUE) \
3908 /* Lock here to avoid hitting all of the data used in the RX
3909 * path (e.g. key data, station data, ...) concurrently when
3910 * a frame is released from the reorder buffer due to timeout
3911 * from the timer, potentially concurrently with RX from the
3914 spin_lock_bh(&rx->local->rx_path_lock);
3916 while ((skb = __skb_dequeue(frames))) {
3918 * all the other fields are valid across frames
3919 * that belong to an aMPDU since they are on the
3920 * same TID from the same station
3924 CALL_RXH(ieee80211_rx_h_check_more_data);
3925 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3926 CALL_RXH(ieee80211_rx_h_sta_process);
3927 CALL_RXH(ieee80211_rx_h_decrypt);
3928 CALL_RXH(ieee80211_rx_h_defragment);
3929 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3930 /* must be after MMIC verify so header is counted in MPDU mic */
3931 #ifdef CONFIG_MAC80211_MESH
3932 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3933 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3935 CALL_RXH(ieee80211_rx_h_amsdu);
3936 CALL_RXH(ieee80211_rx_h_data);
3938 /* special treatment -- needs the queue */
3939 res = ieee80211_rx_h_ctrl(rx, frames);
3940 if (res != RX_CONTINUE)
3943 CALL_RXH(ieee80211_rx_h_mgmt_check);
3944 CALL_RXH(ieee80211_rx_h_action);
3945 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3946 CALL_RXH(ieee80211_rx_h_action_post_userspace);
3947 CALL_RXH(ieee80211_rx_h_action_return);
3948 CALL_RXH(ieee80211_rx_h_ext);
3949 CALL_RXH(ieee80211_rx_h_mgmt);
3952 ieee80211_rx_handlers_result(rx, res);
3957 spin_unlock_bh(&rx->local->rx_path_lock);
3960 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3962 struct sk_buff_head reorder_release;
3963 ieee80211_rx_result res = RX_DROP_MONITOR;
3965 __skb_queue_head_init(&reorder_release);
3967 #define CALL_RXH(rxh) \
3970 if (res != RX_CONTINUE) \
3974 CALL_RXH(ieee80211_rx_h_check_dup);
3975 CALL_RXH(ieee80211_rx_h_check);
3977 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3979 ieee80211_rx_handlers(rx, &reorder_release);
3983 ieee80211_rx_handlers_result(rx, res);
3989 * This function makes calls into the RX path, therefore
3990 * it has to be invoked under RCU read lock.
3992 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3994 struct sk_buff_head frames;
3995 struct ieee80211_rx_data rx = {
3997 .sdata = sta->sdata,
3998 .local = sta->local,
3999 /* This is OK -- must be QoS data frame */
4000 .security_idx = tid,
4003 struct tid_ampdu_rx *tid_agg_rx;
4005 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4009 __skb_queue_head_init(&frames);
4011 spin_lock(&tid_agg_rx->reorder_lock);
4012 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4013 spin_unlock(&tid_agg_rx->reorder_lock);
4015 if (!skb_queue_empty(&frames)) {
4016 struct ieee80211_event event = {
4017 .type = BA_FRAME_TIMEOUT,
4019 .u.ba.sta = &sta->sta,
4021 drv_event_callback(rx.local, rx.sdata, &event);
4024 ieee80211_rx_handlers(&rx, &frames);
4027 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
4028 u16 ssn, u64 filtered,
4031 struct sta_info *sta;
4032 struct tid_ampdu_rx *tid_agg_rx;
4033 struct sk_buff_head frames;
4034 struct ieee80211_rx_data rx = {
4035 /* This is OK -- must be QoS data frame */
4036 .security_idx = tid,
4041 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
4044 __skb_queue_head_init(&frames);
4046 sta = container_of(pubsta, struct sta_info, sta);
4049 rx.sdata = sta->sdata;
4050 rx.local = sta->local;
4053 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4057 spin_lock_bh(&tid_agg_rx->reorder_lock);
4059 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
4062 /* release all frames in the reorder buffer */
4063 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
4064 IEEE80211_SN_MODULO;
4065 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
4067 /* update ssn to match received ssn */
4068 tid_agg_rx->head_seq_num = ssn;
4070 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
4074 /* handle the case that received ssn is behind the mac ssn.
4075 * it can be tid_agg_rx->buf_size behind and still be valid */
4076 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
4077 if (diff >= tid_agg_rx->buf_size) {
4078 tid_agg_rx->reorder_buf_filtered = 0;
4081 filtered = filtered >> diff;
4085 for (i = 0; i < tid_agg_rx->buf_size; i++) {
4086 int index = (ssn + i) % tid_agg_rx->buf_size;
4088 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
4089 if (filtered & BIT_ULL(i))
4090 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
4093 /* now process also frames that the filter marking released */
4094 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4097 spin_unlock_bh(&tid_agg_rx->reorder_lock);
4099 ieee80211_rx_handlers(&rx, &frames);
4104 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
4106 /* main receive path */
4108 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
4110 struct ieee80211_sub_if_data *sdata = rx->sdata;
4111 struct sk_buff *skb = rx->skb;
4112 struct ieee80211_hdr *hdr = (void *)skb->data;
4113 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4114 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
4115 bool multicast = is_multicast_ether_addr(hdr->addr1) ||
4116 ieee80211_is_s1g_beacon(hdr->frame_control);
4118 switch (sdata->vif.type) {
4119 case NL80211_IFTYPE_STATION:
4120 if (!bssid && !sdata->u.mgd.use_4addr)
4122 if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
4126 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4127 case NL80211_IFTYPE_ADHOC:
4130 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
4131 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
4132 !is_valid_ether_addr(hdr->addr2))
4134 if (ieee80211_is_beacon(hdr->frame_control))
4136 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
4139 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4143 if (status->encoding != RX_ENC_LEGACY)
4144 rate_idx = 0; /* TODO: HT/VHT rates */
4146 rate_idx = status->rate_idx;
4147 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
4151 case NL80211_IFTYPE_OCB:
4154 if (!ieee80211_is_data_present(hdr->frame_control))
4156 if (!is_broadcast_ether_addr(bssid))
4159 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
4163 if (status->encoding != RX_ENC_LEGACY)
4164 rate_idx = 0; /* TODO: HT rates */
4166 rate_idx = status->rate_idx;
4167 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
4171 case NL80211_IFTYPE_MESH_POINT:
4172 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
4176 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4177 case NL80211_IFTYPE_AP_VLAN:
4178 case NL80211_IFTYPE_AP:
4180 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4182 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
4184 * Accept public action frames even when the
4185 * BSSID doesn't match, this is used for P2P
4186 * and location updates. Note that mac80211
4187 * itself never looks at these frames.
4190 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4192 if (ieee80211_is_public_action(hdr, skb->len))
4194 return ieee80211_is_beacon(hdr->frame_control);
4197 if (!ieee80211_has_tods(hdr->frame_control)) {
4198 /* ignore data frames to TDLS-peers */
4199 if (ieee80211_is_data(hdr->frame_control))
4201 /* ignore action frames to TDLS-peers */
4202 if (ieee80211_is_action(hdr->frame_control) &&
4203 !is_broadcast_ether_addr(bssid) &&
4204 !ether_addr_equal(bssid, hdr->addr1))
4209 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4210 * the BSSID - we've checked that already but may have accepted
4211 * the wildcard (ff:ff:ff:ff:ff:ff).
4214 * The BSSID of the Data frame is determined as follows:
4215 * a) If the STA is contained within an AP or is associated
4216 * with an AP, the BSSID is the address currently in use
4217 * by the STA contained in the AP.
4219 * So we should not accept data frames with an address that's
4222 * Accepting it also opens a security problem because stations
4223 * could encrypt it with the GTK and inject traffic that way.
4225 if (ieee80211_is_data(hdr->frame_control) && multicast)
4229 case NL80211_IFTYPE_P2P_DEVICE:
4230 return ieee80211_is_public_action(hdr, skb->len) ||
4231 ieee80211_is_probe_req(hdr->frame_control) ||
4232 ieee80211_is_probe_resp(hdr->frame_control) ||
4233 ieee80211_is_beacon(hdr->frame_control);
4234 case NL80211_IFTYPE_NAN:
4235 /* Currently no frames on NAN interface are allowed */
4245 void ieee80211_check_fast_rx(struct sta_info *sta)
4247 struct ieee80211_sub_if_data *sdata = sta->sdata;
4248 struct ieee80211_local *local = sdata->local;
4249 struct ieee80211_key *key;
4250 struct ieee80211_fast_rx fastrx = {
4252 .vif_type = sdata->vif.type,
4253 .control_port_protocol = sdata->control_port_protocol,
4254 }, *old, *new = NULL;
4255 bool set_offload = false;
4256 bool assign = false;
4259 /* use sparse to check that we don't return without updating */
4260 __acquire(check_fast_rx);
4262 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4263 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4264 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4265 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4267 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4269 /* fast-rx doesn't do reordering */
4270 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4271 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4274 switch (sdata->vif.type) {
4275 case NL80211_IFTYPE_STATION:
4276 if (sta->sta.tdls) {
4277 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4278 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4279 fastrx.expected_ds_bits = 0;
4281 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4282 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4283 fastrx.expected_ds_bits =
4284 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4287 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4288 fastrx.expected_ds_bits |=
4289 cpu_to_le16(IEEE80211_FCTL_TODS);
4290 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4291 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4294 if (!sdata->u.mgd.powersave)
4297 /* software powersave is a huge mess, avoid all of it */
4298 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4300 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4301 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4304 case NL80211_IFTYPE_AP_VLAN:
4305 case NL80211_IFTYPE_AP:
4306 /* parallel-rx requires this, at least with calls to
4307 * ieee80211_sta_ps_transition()
4309 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4311 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4312 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4313 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4315 fastrx.internal_forward =
4316 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4317 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4318 !sdata->u.vlan.sta);
4320 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4321 sdata->u.vlan.sta) {
4322 fastrx.expected_ds_bits |=
4323 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4324 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4325 fastrx.internal_forward = 0;
4333 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4337 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4339 key = rcu_dereference(sdata->default_unicast_key);
4341 switch (key->conf.cipher) {
4342 case WLAN_CIPHER_SUITE_TKIP:
4343 /* we don't want to deal with MMIC in fast-rx */
4345 case WLAN_CIPHER_SUITE_CCMP:
4346 case WLAN_CIPHER_SUITE_CCMP_256:
4347 case WLAN_CIPHER_SUITE_GCMP:
4348 case WLAN_CIPHER_SUITE_GCMP_256:
4351 /* We also don't want to deal with
4352 * WEP or cipher scheme.
4358 fastrx.icv_len = key->conf.icv_len;
4365 __release(check_fast_rx);
4368 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4371 (sdata->vif.offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED);
4374 set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4376 set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4379 drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
4381 spin_lock_bh(&sta->lock);
4382 old = rcu_dereference_protected(sta->fast_rx, true);
4383 rcu_assign_pointer(sta->fast_rx, new);
4384 spin_unlock_bh(&sta->lock);
4387 kfree_rcu(old, rcu_head);
4390 void ieee80211_clear_fast_rx(struct sta_info *sta)
4392 struct ieee80211_fast_rx *old;
4394 spin_lock_bh(&sta->lock);
4395 old = rcu_dereference_protected(sta->fast_rx, true);
4396 RCU_INIT_POINTER(sta->fast_rx, NULL);
4397 spin_unlock_bh(&sta->lock);
4400 kfree_rcu(old, rcu_head);
4403 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4405 struct ieee80211_local *local = sdata->local;
4406 struct sta_info *sta;
4408 lockdep_assert_held(&local->sta_mtx);
4410 list_for_each_entry(sta, &local->sta_list, list) {
4411 if (sdata != sta->sdata &&
4412 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4414 ieee80211_check_fast_rx(sta);
4418 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4420 struct ieee80211_local *local = sdata->local;
4422 mutex_lock(&local->sta_mtx);
4423 __ieee80211_check_fast_rx_iface(sdata);
4424 mutex_unlock(&local->sta_mtx);
4427 static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
4428 struct ieee80211_fast_rx *fast_rx,
4431 struct ieee80211_sta_rx_stats *stats;
4432 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4433 struct sta_info *sta = rx->sta;
4434 struct sk_buff *skb = rx->skb;
4435 void *sa = skb->data + ETH_ALEN;
4436 void *da = skb->data;
4438 stats = &sta->rx_stats;
4439 if (fast_rx->uses_rss)
4440 stats = this_cpu_ptr(sta->pcpu_rx_stats);
4442 /* statistics part of ieee80211_rx_h_sta_process() */
4443 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4444 stats->last_signal = status->signal;
4445 if (!fast_rx->uses_rss)
4446 ewma_signal_add(&sta->rx_stats_avg.signal,
4450 if (status->chains) {
4453 stats->chains = status->chains;
4454 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4455 int signal = status->chain_signal[i];
4457 if (!(status->chains & BIT(i)))
4460 stats->chain_signal_last[i] = signal;
4461 if (!fast_rx->uses_rss)
4462 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4466 /* end of statistics */
4468 stats->last_rx = jiffies;
4469 stats->last_rate = sta_stats_encode_rate(status);
4474 skb->dev = fast_rx->dev;
4476 dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
4478 /* The seqno index has the same property as needed
4479 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4480 * for non-QoS-data frames. Here we know it's a data
4481 * frame, so count MSDUs.
4483 u64_stats_update_begin(&stats->syncp);
4484 stats->msdu[rx->seqno_idx]++;
4485 stats->bytes += orig_len;
4486 u64_stats_update_end(&stats->syncp);
4488 if (fast_rx->internal_forward) {
4489 struct sk_buff *xmit_skb = NULL;
4490 if (is_multicast_ether_addr(da)) {
4491 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4492 } else if (!ether_addr_equal(da, sa) &&
4493 sta_info_get(rx->sdata, da)) {
4500 * Send to wireless media and increase priority by 256
4501 * to keep the received priority instead of
4502 * reclassifying the frame (see cfg80211_classify8021d).
4504 xmit_skb->priority += 256;
4505 xmit_skb->protocol = htons(ETH_P_802_3);
4506 skb_reset_network_header(xmit_skb);
4507 skb_reset_mac_header(xmit_skb);
4508 dev_queue_xmit(xmit_skb);
4515 /* deliver to local stack */
4516 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4517 ieee80211_deliver_skb_to_local_stack(skb, rx);
4520 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4521 struct ieee80211_fast_rx *fast_rx)
4523 struct sk_buff *skb = rx->skb;
4524 struct ieee80211_hdr *hdr = (void *)skb->data;
4525 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4526 struct sta_info *sta = rx->sta;
4527 int orig_len = skb->len;
4528 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4529 int snap_offs = hdrlen;
4531 u8 snap[sizeof(rfc1042_header)];
4533 } *payload __aligned(2);
4537 } addrs __aligned(2);
4538 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
4540 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4541 * to a common data structure; drivers can implement that per queue
4542 * but we don't have that information in mac80211
4544 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4547 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4549 /* If using encryption, we also need to have:
4550 * - PN_VALIDATED: similar, but the implementation is tricky
4551 * - DECRYPTED: necessary for PN_VALIDATED
4554 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4557 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4560 if (unlikely(ieee80211_is_frag(hdr)))
4563 /* Since our interface address cannot be multicast, this
4564 * implicitly also rejects multicast frames without the
4567 * We shouldn't get any *data* frames not addressed to us
4568 * (AP mode will accept multicast *management* frames), but
4569 * punting here will make it go through the full checks in
4570 * ieee80211_accept_frame().
4572 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4575 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4576 IEEE80211_FCTL_TODS)) !=
4577 fast_rx->expected_ds_bits)
4580 /* assign the key to drop unencrypted frames (later)
4581 * and strip the IV/MIC if necessary
4583 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4584 /* GCMP header length is the same */
4585 snap_offs += IEEE80211_CCMP_HDR_LEN;
4588 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4589 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4592 payload = (void *)(skb->data + snap_offs);
4594 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4597 /* Don't handle these here since they require special code.
4598 * Accept AARP and IPX even though they should come with a
4599 * bridge-tunnel header - but if we get them this way then
4600 * there's little point in discarding them.
4602 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4603 payload->proto == fast_rx->control_port_protocol))
4607 /* after this point, don't punt to the slowpath! */
4609 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4610 pskb_trim(skb, skb->len - fast_rx->icv_len))
4613 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4616 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4617 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4624 /* do the header conversion - first grab the addresses */
4625 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4626 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4627 skb_postpull_rcsum(skb, skb->data + snap_offs,
4628 sizeof(rfc1042_header) + 2);
4629 /* remove the SNAP but leave the ethertype */
4630 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4631 /* push the addresses in front */
4632 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4634 ieee80211_rx_8023(rx, fast_rx, orig_len);
4639 if (fast_rx->uses_rss)
4640 stats = this_cpu_ptr(sta->pcpu_rx_stats);
4647 * This function returns whether or not the SKB
4648 * was destined for RX processing or not, which,
4649 * if consume is true, is equivalent to whether
4650 * or not the skb was consumed.
4652 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4653 struct sk_buff *skb, bool consume)
4655 struct ieee80211_local *local = rx->local;
4656 struct ieee80211_sub_if_data *sdata = rx->sdata;
4660 /* See if we can do fast-rx; if we have to copy we already lost,
4661 * so punt in that case. We should never have to deliver a data
4662 * frame to multiple interfaces anyway.
4664 * We skip the ieee80211_accept_frame() call and do the necessary
4665 * checking inside ieee80211_invoke_fast_rx().
4667 if (consume && rx->sta) {
4668 struct ieee80211_fast_rx *fast_rx;
4670 fast_rx = rcu_dereference(rx->sta->fast_rx);
4671 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4675 if (!ieee80211_accept_frame(rx))
4679 skb = skb_copy(skb, GFP_ATOMIC);
4681 if (net_ratelimit())
4682 wiphy_debug(local->hw.wiphy,
4683 "failed to copy skb for %s\n",
4691 ieee80211_invoke_rx_handlers(rx);
4695 static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
4696 struct ieee80211_sta *pubsta,
4697 struct sk_buff *skb,
4698 struct list_head *list)
4700 struct ieee80211_local *local = hw_to_local(hw);
4701 struct ieee80211_fast_rx *fast_rx;
4702 struct ieee80211_rx_data rx;
4704 memset(&rx, 0, sizeof(rx));
4709 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4711 /* drop frame if too short for header */
4712 if (skb->len < sizeof(struct ethhdr))
4718 rx.sta = container_of(pubsta, struct sta_info, sta);
4719 rx.sdata = rx.sta->sdata;
4721 fast_rx = rcu_dereference(rx.sta->fast_rx);
4725 ieee80211_rx_8023(&rx, fast_rx, skb->len);
4733 * This is the actual Rx frames handler. as it belongs to Rx path it must
4734 * be called with rcu_read_lock protection.
4736 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4737 struct ieee80211_sta *pubsta,
4738 struct sk_buff *skb,
4739 struct list_head *list)
4741 struct ieee80211_local *local = hw_to_local(hw);
4742 struct ieee80211_sub_if_data *sdata;
4743 struct ieee80211_hdr *hdr;
4745 struct ieee80211_rx_data rx;
4746 struct ieee80211_sub_if_data *prev;
4747 struct rhlist_head *tmp;
4750 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4751 memset(&rx, 0, sizeof(rx));
4756 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4757 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4759 if (ieee80211_is_mgmt(fc)) {
4760 /* drop frame if too short for header */
4761 if (skb->len < ieee80211_hdrlen(fc))
4764 err = skb_linearize(skb);
4766 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4774 hdr = (struct ieee80211_hdr *)skb->data;
4775 ieee80211_parse_qos(&rx);
4776 ieee80211_verify_alignment(&rx);
4778 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4779 ieee80211_is_beacon(hdr->frame_control) ||
4780 ieee80211_is_s1g_beacon(hdr->frame_control)))
4781 ieee80211_scan_rx(local, skb);
4783 if (ieee80211_is_data(fc)) {
4784 struct sta_info *sta, *prev_sta;
4787 rx.sta = container_of(pubsta, struct sta_info, sta);
4788 rx.sdata = rx.sta->sdata;
4789 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4796 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4803 rx.sdata = prev_sta->sdata;
4804 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4811 rx.sdata = prev_sta->sdata;
4813 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4821 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4822 if (!ieee80211_sdata_running(sdata))
4825 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4826 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4830 * frame is destined for this interface, but if it's
4831 * not also for the previous one we handle that after
4832 * the loop to avoid copying the SKB once too much
4840 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4842 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4848 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4851 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4860 * This is the receive path handler. It is called by a low level driver when an
4861 * 802.11 MPDU is received from the hardware.
4863 void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4864 struct sk_buff *skb, struct list_head *list)
4866 struct ieee80211_local *local = hw_to_local(hw);
4867 struct ieee80211_rate *rate = NULL;
4868 struct ieee80211_supported_band *sband;
4869 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4870 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4872 WARN_ON_ONCE(softirq_count() == 0);
4874 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4877 sband = local->hw.wiphy->bands[status->band];
4878 if (WARN_ON(!sband))
4882 * If we're suspending, it is possible although not too likely
4883 * that we'd be receiving frames after having already partially
4884 * quiesced the stack. We can't process such frames then since
4885 * that might, for example, cause stations to be added or other
4886 * driver callbacks be invoked.
4888 if (unlikely(local->quiescing || local->suspended))
4891 /* We might be during a HW reconfig, prevent Rx for the same reason */
4892 if (unlikely(local->in_reconfig))
4896 * The same happens when we're not even started,
4897 * but that's worth a warning.
4899 if (WARN_ON(!local->started))
4902 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4904 * Validate the rate, unless a PLCP error means that
4905 * we probably can't have a valid rate here anyway.
4908 switch (status->encoding) {
4911 * rate_idx is MCS index, which can be [0-76]
4914 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
4916 * Anything else would be some sort of driver or
4917 * hardware error. The driver should catch hardware
4920 if (WARN(status->rate_idx > 76,
4921 "Rate marked as an HT rate but passed "
4922 "status->rate_idx is not "
4923 "an MCS index [0-76]: %d (0x%02x)\n",
4929 if (WARN_ONCE(status->rate_idx > 11 ||
4932 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4933 status->rate_idx, status->nss))
4937 if (WARN_ONCE(status->rate_idx > 11 ||
4940 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4941 status->rate_idx, status->nss))
4948 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4950 rate = &sband->bitrates[status->rate_idx];
4954 status->rx_flags = 0;
4956 kcov_remote_start_common(skb_get_kcov_handle(skb));
4959 * Frames with failed FCS/PLCP checksum are not returned,
4960 * all other frames are returned without radiotap header
4961 * if it was previously present.
4962 * Also, frames with less than 16 bytes are dropped.
4964 if (!(status->flag & RX_FLAG_8023))
4965 skb = ieee80211_rx_monitor(local, skb, rate);
4967 if ((status->flag & RX_FLAG_8023) ||
4968 ieee80211_is_data_present(hdr->frame_control))
4969 ieee80211_tpt_led_trig_rx(local, skb->len);
4971 if (status->flag & RX_FLAG_8023)
4972 __ieee80211_rx_handle_8023(hw, pubsta, skb, list);
4974 __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
4982 EXPORT_SYMBOL(ieee80211_rx_list);
4984 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4985 struct sk_buff *skb, struct napi_struct *napi)
4987 struct sk_buff *tmp;
4992 * key references and virtual interfaces are protected using RCU
4993 * and this requires that we are in a read-side RCU section during
4994 * receive processing
4997 ieee80211_rx_list(hw, pubsta, skb, &list);
5001 netif_receive_skb_list(&list);
5005 list_for_each_entry_safe(skb, tmp, &list, list) {
5006 skb_list_del_init(skb);
5007 napi_gro_receive(napi, skb);
5010 EXPORT_SYMBOL(ieee80211_rx_napi);
5012 /* This is a version of the rx handler that can be called from hard irq
5013 * context. Post the skb on the queue and schedule the tasklet */
5014 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
5016 struct ieee80211_local *local = hw_to_local(hw);
5018 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
5020 skb->pkt_type = IEEE80211_RX_MSG;
5021 skb_queue_tail(&local->skb_queue, skb);
5022 tasklet_schedule(&local->tasklet);
5024 EXPORT_SYMBOL(ieee80211_rx_irqsafe);