1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
5 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
6 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
9 * Copyright (C) 2018-2022 Intel Corporation
12 #include <linux/jiffies.h>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/rcupdate.h>
19 #include <linux/export.h>
20 #include <linux/kcov.h>
21 #include <linux/bitops.h>
22 #include <net/mac80211.h>
23 #include <net/ieee80211_radiotap.h>
24 #include <asm/unaligned.h>
26 #include "ieee80211_i.h"
27 #include "driver-ops.h"
37 * monitor mode reception
39 * This function cleans up the SKB, i.e. it removes all the stuff
40 * only useful for monitoring.
42 static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
43 unsigned int present_fcs_len,
44 unsigned int rtap_space)
46 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
47 struct ieee80211_hdr *hdr;
52 __pskb_trim(skb, skb->len - present_fcs_len);
53 pskb_pull(skb, rtap_space);
55 /* After pulling radiotap header, clear all flags that indicate
58 status->flag &= ~(RX_FLAG_RADIOTAP_TLV_AT_END |
59 RX_FLAG_RADIOTAP_LSIG |
60 RX_FLAG_RADIOTAP_HE_MU |
63 hdr = (void *)skb->data;
64 fc = hdr->frame_control;
67 * Remove the HT-Control field (if present) on management
68 * frames after we've sent the frame to monitoring. We
69 * (currently) don't need it, and don't properly parse
70 * frames with it present, due to the assumption of a
71 * fixed management header length.
73 if (likely(!ieee80211_is_mgmt(fc) || !ieee80211_has_order(fc)))
76 hdrlen = ieee80211_hdrlen(fc);
77 hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_ORDER);
79 if (!pskb_may_pull(skb, hdrlen)) {
84 memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data,
85 hdrlen - IEEE80211_HT_CTL_LEN);
86 pskb_pull(skb, IEEE80211_HT_CTL_LEN);
91 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
92 unsigned int rtap_space)
94 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
95 struct ieee80211_hdr *hdr;
97 hdr = (void *)(skb->data + rtap_space);
99 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
100 RX_FLAG_FAILED_PLCP_CRC |
101 RX_FLAG_ONLY_MONITOR |
105 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
108 if (ieee80211_is_ctl(hdr->frame_control) &&
109 !ieee80211_is_pspoll(hdr->frame_control) &&
110 !ieee80211_is_back_req(hdr->frame_control))
117 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
118 struct ieee80211_rx_status *status,
123 /* always present fields */
124 len = sizeof(struct ieee80211_radiotap_header) + 8;
126 /* allocate extra bitmaps */
128 len += 4 * hweight8(status->chains);
130 if (ieee80211_have_rx_timestamp(status)) {
134 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
137 /* antenna field, if we don't have per-chain info */
141 /* padding for RX_FLAGS if necessary */
144 if (status->encoding == RX_ENC_HT) /* HT info */
147 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
152 if (status->encoding == RX_ENC_VHT) {
157 if (local->hw.radiotap_timestamp.units_pos >= 0) {
162 if (status->encoding == RX_ENC_HE &&
163 status->flag & RX_FLAG_RADIOTAP_HE) {
166 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
169 if (status->encoding == RX_ENC_HE &&
170 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
173 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
176 if (status->flag & RX_FLAG_NO_PSDU)
179 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
182 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4);
185 if (status->chains) {
186 /* antenna and antenna signal fields */
187 len += 2 * hweight8(status->chains);
190 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END) {
194 * The position to look at depends on the existence (or non-
195 * existence) of other elements, so take that into account...
197 if (status->flag & RX_FLAG_RADIOTAP_HE)
199 sizeof(struct ieee80211_radiotap_he);
200 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
202 sizeof(struct ieee80211_radiotap_he_mu);
203 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
205 sizeof(struct ieee80211_radiotap_lsig);
207 /* ensure 4 byte alignment for TLV */
210 /* TLVs until the mac header */
211 len += skb_mac_header(skb) - &skb->data[tlv_offset];
217 static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
219 struct sta_info *sta,
222 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
225 status->link_valid = 1;
226 status->link_id = link_id;
228 status->link_valid = 0;
231 skb_queue_tail(&sdata->skb_queue, skb);
232 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
234 sta->deflink.rx_stats.packets++;
237 static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
239 struct sta_info *sta,
243 __ieee80211_queue_skb_to_iface(sdata, link_id, sta, skb);
246 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
251 struct ieee80211_hdr_3addr hdr;
254 } __packed __aligned(2) action;
259 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
261 if (skb->len < rtap_space + sizeof(action) +
262 VHT_MUMIMO_GROUPS_DATA_LEN)
265 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
268 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
270 if (!ieee80211_is_action(action.hdr.frame_control))
273 if (action.category != WLAN_CATEGORY_VHT)
276 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
279 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
282 skb = skb_copy(skb, GFP_ATOMIC);
286 ieee80211_queue_skb_to_iface(sdata, -1, NULL, skb);
290 * ieee80211_add_rx_radiotap_header - add radiotap header
292 * add a radiotap header containing all the fields which the hardware provided.
295 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
297 struct ieee80211_rate *rate,
298 int rtap_len, bool has_fcs)
300 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
301 struct ieee80211_radiotap_header *rthdr;
306 u16 channel_flags = 0;
309 unsigned long chains = status->chains;
310 struct ieee80211_radiotap_he he = {};
311 struct ieee80211_radiotap_he_mu he_mu = {};
312 struct ieee80211_radiotap_lsig lsig = {};
314 if (status->flag & RX_FLAG_RADIOTAP_HE) {
315 he = *(struct ieee80211_radiotap_he *)skb->data;
316 skb_pull(skb, sizeof(he));
317 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
320 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
321 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
322 skb_pull(skb, sizeof(he_mu));
325 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
326 lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
327 skb_pull(skb, sizeof(lsig));
330 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END) {
331 /* data is pointer at tlv all other info was pulled off */
332 tlvs_len = skb_mac_header(skb) - skb->data;
336 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
339 rthdr = skb_push(skb, rtap_len - tlvs_len);
340 memset(rthdr, 0, rtap_len - tlvs_len);
341 it_present = &rthdr->it_present;
343 /* radiotap header, set always present flags */
344 rthdr->it_len = cpu_to_le16(rtap_len);
345 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
346 BIT(IEEE80211_RADIOTAP_CHANNEL) |
347 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
350 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
352 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
354 BIT(IEEE80211_RADIOTAP_EXT) |
355 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
356 put_unaligned_le32(it_present_val, it_present);
358 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
359 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
362 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END)
363 it_present_val |= BIT(IEEE80211_RADIOTAP_TLV);
365 put_unaligned_le32(it_present_val, it_present);
367 /* This references through an offset into it_optional[] rather
368 * than via it_present otherwise later uses of pos will cause
369 * the compiler to think we have walked past the end of the
372 pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
374 /* the order of the following fields is important */
376 /* IEEE80211_RADIOTAP_TSFT */
377 if (ieee80211_have_rx_timestamp(status)) {
379 while ((pos - (u8 *)rthdr) & 7)
382 ieee80211_calculate_rx_timestamp(local, status,
385 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));
389 /* IEEE80211_RADIOTAP_FLAGS */
390 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
391 *pos |= IEEE80211_RADIOTAP_F_FCS;
392 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
393 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
394 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
395 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
398 /* IEEE80211_RADIOTAP_RATE */
399 if (!rate || status->encoding != RX_ENC_LEGACY) {
401 * Without rate information don't add it. If we have,
402 * MCS information is a separate field in radiotap,
403 * added below. The byte here is needed as padding
404 * for the channel though, so initialise it to 0.
409 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
410 if (status->bw == RATE_INFO_BW_10)
412 else if (status->bw == RATE_INFO_BW_5)
414 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
418 /* IEEE80211_RADIOTAP_CHANNEL */
419 /* TODO: frequency offset in KHz */
420 put_unaligned_le16(status->freq, pos);
422 if (status->bw == RATE_INFO_BW_10)
423 channel_flags |= IEEE80211_CHAN_HALF;
424 else if (status->bw == RATE_INFO_BW_5)
425 channel_flags |= IEEE80211_CHAN_QUARTER;
427 if (status->band == NL80211_BAND_5GHZ ||
428 status->band == NL80211_BAND_6GHZ)
429 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
430 else if (status->encoding != RX_ENC_LEGACY)
431 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
432 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
433 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
435 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
437 channel_flags |= IEEE80211_CHAN_2GHZ;
438 put_unaligned_le16(channel_flags, pos);
441 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
442 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
443 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
444 *pos = status->signal;
446 cpu_to_le32(BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
450 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
452 if (!status->chains) {
453 /* IEEE80211_RADIOTAP_ANTENNA */
454 *pos = status->antenna;
458 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
460 /* IEEE80211_RADIOTAP_RX_FLAGS */
461 /* ensure 2 byte alignment for the 2 byte field as required */
462 if ((pos - (u8 *)rthdr) & 1)
464 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
465 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
466 put_unaligned_le16(rx_flags, pos);
469 if (status->encoding == RX_ENC_HT) {
472 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
473 *pos = local->hw.radiotap_mcs_details;
474 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
475 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
476 if (status->enc_flags & RX_ENC_FLAG_LDPC)
477 *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FEC;
480 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
481 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
482 if (status->bw == RATE_INFO_BW_40)
483 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
484 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
485 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
486 if (status->enc_flags & RX_ENC_FLAG_LDPC)
487 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
488 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
489 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
491 *pos++ = status->rate_idx;
494 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
497 /* ensure 4 byte alignment */
498 while ((pos - (u8 *)rthdr) & 3)
501 cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
502 put_unaligned_le32(status->ampdu_reference, pos);
504 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
505 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
506 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
507 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
508 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
509 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
510 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
511 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
512 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
513 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
514 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
515 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
516 put_unaligned_le16(flags, pos);
518 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
519 *pos++ = status->ampdu_delimiter_crc;
525 if (status->encoding == RX_ENC_VHT) {
526 u16 known = local->hw.radiotap_vht_details;
528 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
529 put_unaligned_le16(known, pos);
532 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
533 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
534 /* in VHT, STBC is binary */
535 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
536 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
537 if (status->enc_flags & RX_ENC_FLAG_BF)
538 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
541 switch (status->bw) {
542 case RATE_INFO_BW_80:
545 case RATE_INFO_BW_160:
548 case RATE_INFO_BW_40:
555 *pos = (status->rate_idx << 4) | status->nss;
558 if (status->enc_flags & RX_ENC_FLAG_LDPC)
559 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
567 if (local->hw.radiotap_timestamp.units_pos >= 0) {
569 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
572 cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
574 /* ensure 8 byte alignment */
575 while ((pos - (u8 *)rthdr) & 7)
578 put_unaligned_le64(status->device_timestamp, pos);
581 if (local->hw.radiotap_timestamp.accuracy >= 0) {
582 accuracy = local->hw.radiotap_timestamp.accuracy;
583 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
585 put_unaligned_le16(accuracy, pos);
588 *pos++ = local->hw.radiotap_timestamp.units_pos;
592 if (status->encoding == RX_ENC_HE &&
593 status->flag & RX_FLAG_RADIOTAP_HE) {
594 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
596 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
597 he.data6 |= HE_PREP(DATA6_NSTS,
598 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
600 he.data3 |= HE_PREP(DATA3_STBC, 1);
602 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
605 #define CHECK_GI(s) \
606 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
607 (int)NL80211_RATE_INFO_HE_GI_##s)
613 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
614 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
615 he.data3 |= HE_PREP(DATA3_CODING,
616 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
618 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
620 switch (status->bw) {
621 case RATE_INFO_BW_20:
622 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
623 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
625 case RATE_INFO_BW_40:
626 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
627 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
629 case RATE_INFO_BW_80:
630 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
631 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
633 case RATE_INFO_BW_160:
634 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
635 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
637 case RATE_INFO_BW_HE_RU:
638 #define CHECK_RU_ALLOC(s) \
639 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
640 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
648 CHECK_RU_ALLOC(2x996);
650 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
654 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
657 /* ensure 2 byte alignment */
658 while ((pos - (u8 *)rthdr) & 1)
660 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
661 memcpy(pos, &he, sizeof(he));
665 if (status->encoding == RX_ENC_HE &&
666 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
667 /* ensure 2 byte alignment */
668 while ((pos - (u8 *)rthdr) & 1)
670 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
671 memcpy(pos, &he_mu, sizeof(he_mu));
672 pos += sizeof(he_mu);
675 if (status->flag & RX_FLAG_NO_PSDU) {
677 cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
678 *pos++ = status->zero_length_psdu_type;
681 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
682 /* ensure 2 byte alignment */
683 while ((pos - (u8 *)rthdr) & 1)
685 rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
686 memcpy(pos, &lsig, sizeof(lsig));
690 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
691 *pos++ = status->chain_signal[chain];
696 static struct sk_buff *
697 ieee80211_make_monitor_skb(struct ieee80211_local *local,
698 struct sk_buff **origskb,
699 struct ieee80211_rate *rate,
700 int rtap_space, bool use_origskb)
702 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
703 int rt_hdrlen, needed_headroom;
706 /* room for the radiotap header based on driver features */
707 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
708 needed_headroom = rt_hdrlen - rtap_space;
711 /* only need to expand headroom if necessary */
716 * This shouldn't trigger often because most devices have an
717 * RX header they pull before we get here, and that should
718 * be big enough for our radiotap information. We should
719 * probably export the length to drivers so that we can have
720 * them allocate enough headroom to start with.
722 if (skb_headroom(skb) < needed_headroom &&
723 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
729 * Need to make a copy and possibly remove radiotap header
730 * and FCS from the original.
732 skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
739 /* prepend radiotap information */
740 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
742 skb_reset_mac_header(skb);
743 skb->ip_summed = CHECKSUM_UNNECESSARY;
744 skb->pkt_type = PACKET_OTHERHOST;
745 skb->protocol = htons(ETH_P_802_2);
751 * This function copies a received frame to all monitor interfaces and
752 * returns a cleaned-up SKB that no longer includes the FCS nor the
753 * radiotap header the driver might have added.
755 static struct sk_buff *
756 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
757 struct ieee80211_rate *rate)
759 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
760 struct ieee80211_sub_if_data *sdata;
761 struct sk_buff *monskb = NULL;
762 int present_fcs_len = 0;
763 unsigned int rtap_space = 0;
764 struct ieee80211_sub_if_data *monitor_sdata =
765 rcu_dereference(local->monitor_sdata);
766 bool only_monitor = false;
767 unsigned int min_head_len;
769 if (WARN_ON_ONCE(status->flag & RX_FLAG_RADIOTAP_TLV_AT_END &&
770 !skb_mac_header_was_set(origskb))) {
771 /* with this skb no way to know where frame payload starts */
772 dev_kfree_skb(origskb);
776 if (status->flag & RX_FLAG_RADIOTAP_HE)
777 rtap_space += sizeof(struct ieee80211_radiotap_he);
779 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
780 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
782 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
783 rtap_space += sizeof(struct ieee80211_radiotap_lsig);
785 if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END)
786 rtap_space += skb_mac_header(origskb) - &origskb->data[rtap_space];
788 min_head_len = rtap_space;
791 * First, we may need to make a copy of the skb because
792 * (1) we need to modify it for radiotap (if not present), and
793 * (2) the other RX handlers will modify the skb we got.
795 * We don't need to, of course, if we aren't going to return
796 * the SKB because it has a bad FCS/PLCP checksum.
799 if (!(status->flag & RX_FLAG_NO_PSDU)) {
800 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
801 if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
804 dev_kfree_skb(origskb);
807 present_fcs_len = FCS_LEN;
810 /* also consider the hdr->frame_control */
814 /* ensure that the expected data elements are in skb head */
815 if (!pskb_may_pull(origskb, min_head_len)) {
816 dev_kfree_skb(origskb);
820 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
822 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
824 dev_kfree_skb(origskb);
828 return ieee80211_clean_skb(origskb, present_fcs_len,
832 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
834 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
835 bool last_monitor = list_is_last(&sdata->u.mntr.list,
839 monskb = ieee80211_make_monitor_skb(local, &origskb,
851 skb = skb_clone(monskb, GFP_ATOMIC);
855 skb->dev = sdata->dev;
856 dev_sw_netstats_rx_add(skb->dev, skb->len);
857 netif_receive_skb(skb);
865 /* this happens if last_monitor was erroneously false */
866 dev_kfree_skb(monskb);
872 return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
875 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
877 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
878 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
879 int tid, seqno_idx, security_idx;
881 /* does the frame have a qos control field? */
882 if (ieee80211_is_data_qos(hdr->frame_control)) {
883 u8 *qc = ieee80211_get_qos_ctl(hdr);
884 /* frame has qos control */
885 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
886 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
887 status->rx_flags |= IEEE80211_RX_AMSDU;
893 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
895 * Sequence numbers for management frames, QoS data
896 * frames with a broadcast/multicast address in the
897 * Address 1 field, and all non-QoS data frames sent
898 * by QoS STAs are assigned using an additional single
899 * modulo-4096 counter, [...]
901 * We also use that counter for non-QoS STAs.
903 seqno_idx = IEEE80211_NUM_TIDS;
905 if (ieee80211_is_mgmt(hdr->frame_control))
906 security_idx = IEEE80211_NUM_TIDS;
910 rx->seqno_idx = seqno_idx;
911 rx->security_idx = security_idx;
912 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
913 * For now, set skb->priority to 0 for other cases. */
914 rx->skb->priority = (tid > 7) ? 0 : tid;
918 * DOC: Packet alignment
920 * Drivers always need to pass packets that are aligned to two-byte boundaries
923 * Additionally, should, if possible, align the payload data in a way that
924 * guarantees that the contained IP header is aligned to a four-byte
925 * boundary. In the case of regular frames, this simply means aligning the
926 * payload to a four-byte boundary (because either the IP header is directly
927 * contained, or IV/RFC1042 headers that have a length divisible by four are
928 * in front of it). If the payload data is not properly aligned and the
929 * architecture doesn't support efficient unaligned operations, mac80211
930 * will align the data.
932 * With A-MSDU frames, however, the payload data address must yield two modulo
933 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
934 * push the IP header further back to a multiple of four again. Thankfully, the
935 * specs were sane enough this time around to require padding each A-MSDU
936 * subframe to a length that is a multiple of four.
938 * Padding like Atheros hardware adds which is between the 802.11 header and
939 * the payload is not supported, the driver is required to move the 802.11
940 * header to be directly in front of the payload in that case.
942 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
944 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
945 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
952 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
954 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
956 if (is_multicast_ether_addr(hdr->addr1))
959 return ieee80211_is_robust_mgmt_frame(skb);
963 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
965 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
967 if (!is_multicast_ether_addr(hdr->addr1))
970 return ieee80211_is_robust_mgmt_frame(skb);
974 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
975 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
977 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
978 struct ieee80211_mmie *mmie;
979 struct ieee80211_mmie_16 *mmie16;
981 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
984 if (!ieee80211_is_robust_mgmt_frame(skb) &&
985 !ieee80211_is_beacon(hdr->frame_control))
986 return -1; /* not a robust management frame */
988 mmie = (struct ieee80211_mmie *)
989 (skb->data + skb->len - sizeof(*mmie));
990 if (mmie->element_id == WLAN_EID_MMIE &&
991 mmie->length == sizeof(*mmie) - 2)
992 return le16_to_cpu(mmie->key_id);
994 mmie16 = (struct ieee80211_mmie_16 *)
995 (skb->data + skb->len - sizeof(*mmie16));
996 if (skb->len >= 24 + sizeof(*mmie16) &&
997 mmie16->element_id == WLAN_EID_MMIE &&
998 mmie16->length == sizeof(*mmie16) - 2)
999 return le16_to_cpu(mmie16->key_id);
1004 static int ieee80211_get_keyid(struct sk_buff *skb)
1006 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1007 __le16 fc = hdr->frame_control;
1008 int hdrlen = ieee80211_hdrlen(fc);
1011 /* WEP, TKIP, CCMP and GCMP */
1012 if (unlikely(skb->len < hdrlen + IEEE80211_WEP_IV_LEN))
1015 skb_copy_bits(skb, hdrlen + 3, &keyid, 1);
1022 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1024 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1025 char *dev_addr = rx->sdata->vif.addr;
1027 if (ieee80211_is_data(hdr->frame_control)) {
1028 if (is_multicast_ether_addr(hdr->addr1)) {
1029 if (ieee80211_has_tods(hdr->frame_control) ||
1030 !ieee80211_has_fromds(hdr->frame_control))
1031 return RX_DROP_MONITOR;
1032 if (ether_addr_equal(hdr->addr3, dev_addr))
1033 return RX_DROP_MONITOR;
1035 if (!ieee80211_has_a4(hdr->frame_control))
1036 return RX_DROP_MONITOR;
1037 if (ether_addr_equal(hdr->addr4, dev_addr))
1038 return RX_DROP_MONITOR;
1042 /* If there is not an established peer link and this is not a peer link
1043 * establisment frame, beacon or probe, drop the frame.
1046 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1047 struct ieee80211_mgmt *mgmt;
1049 if (!ieee80211_is_mgmt(hdr->frame_control))
1050 return RX_DROP_MONITOR;
1052 if (ieee80211_is_action(hdr->frame_control)) {
1055 /* make sure category field is present */
1056 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1057 return RX_DROP_MONITOR;
1059 mgmt = (struct ieee80211_mgmt *)hdr;
1060 category = mgmt->u.action.category;
1061 if (category != WLAN_CATEGORY_MESH_ACTION &&
1062 category != WLAN_CATEGORY_SELF_PROTECTED)
1063 return RX_DROP_MONITOR;
1067 if (ieee80211_is_probe_req(hdr->frame_control) ||
1068 ieee80211_is_probe_resp(hdr->frame_control) ||
1069 ieee80211_is_beacon(hdr->frame_control) ||
1070 ieee80211_is_auth(hdr->frame_control))
1073 return RX_DROP_MONITOR;
1079 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1082 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1083 struct sk_buff *tail = skb_peek_tail(frames);
1084 struct ieee80211_rx_status *status;
1086 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1092 status = IEEE80211_SKB_RXCB(tail);
1093 if (status->flag & RX_FLAG_AMSDU_MORE)
1099 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1100 struct tid_ampdu_rx *tid_agg_rx,
1102 struct sk_buff_head *frames)
1104 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1105 struct sk_buff *skb;
1106 struct ieee80211_rx_status *status;
1108 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1110 if (skb_queue_empty(skb_list))
1113 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1114 __skb_queue_purge(skb_list);
1118 /* release frames from the reorder ring buffer */
1119 tid_agg_rx->stored_mpdu_num--;
1120 while ((skb = __skb_dequeue(skb_list))) {
1121 status = IEEE80211_SKB_RXCB(skb);
1122 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1123 __skb_queue_tail(frames, skb);
1127 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1128 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1131 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1132 struct tid_ampdu_rx *tid_agg_rx,
1134 struct sk_buff_head *frames)
1138 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1140 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1141 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1142 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1148 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1149 * the skb was added to the buffer longer than this time ago, the earlier
1150 * frames that have not yet been received are assumed to be lost and the skb
1151 * can be released for processing. This may also release other skb's from the
1152 * reorder buffer if there are no additional gaps between the frames.
1154 * Callers must hold tid_agg_rx->reorder_lock.
1156 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1158 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1159 struct tid_ampdu_rx *tid_agg_rx,
1160 struct sk_buff_head *frames)
1164 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1166 /* release the buffer until next missing frame */
1167 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1168 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1169 tid_agg_rx->stored_mpdu_num) {
1171 * No buffers ready to be released, but check whether any
1172 * frames in the reorder buffer have timed out.
1175 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1176 j = (j + 1) % tid_agg_rx->buf_size) {
1177 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1182 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1183 HT_RX_REORDER_BUF_TIMEOUT))
1184 goto set_release_timer;
1186 /* don't leave incomplete A-MSDUs around */
1187 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1188 i = (i + 1) % tid_agg_rx->buf_size)
1189 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1191 ht_dbg_ratelimited(sdata,
1192 "release an RX reorder frame due to timeout on earlier frames\n");
1193 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1197 * Increment the head seq# also for the skipped slots.
1199 tid_agg_rx->head_seq_num =
1200 (tid_agg_rx->head_seq_num +
1201 skipped) & IEEE80211_SN_MASK;
1204 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1205 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1207 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1210 if (tid_agg_rx->stored_mpdu_num) {
1211 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1213 for (; j != (index - 1) % tid_agg_rx->buf_size;
1214 j = (j + 1) % tid_agg_rx->buf_size) {
1215 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1221 if (!tid_agg_rx->removed)
1222 mod_timer(&tid_agg_rx->reorder_timer,
1223 tid_agg_rx->reorder_time[j] + 1 +
1224 HT_RX_REORDER_BUF_TIMEOUT);
1226 del_timer(&tid_agg_rx->reorder_timer);
1231 * As this function belongs to the RX path it must be under
1232 * rcu_read_lock protection. It returns false if the frame
1233 * can be processed immediately, true if it was consumed.
1235 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1236 struct tid_ampdu_rx *tid_agg_rx,
1237 struct sk_buff *skb,
1238 struct sk_buff_head *frames)
1240 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1241 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1242 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1243 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1244 u16 head_seq_num, buf_size;
1248 spin_lock(&tid_agg_rx->reorder_lock);
1251 * Offloaded BA sessions have no known starting sequence number so pick
1252 * one from first Rxed frame for this tid after BA was started.
1254 if (unlikely(tid_agg_rx->auto_seq)) {
1255 tid_agg_rx->auto_seq = false;
1256 tid_agg_rx->ssn = mpdu_seq_num;
1257 tid_agg_rx->head_seq_num = mpdu_seq_num;
1260 buf_size = tid_agg_rx->buf_size;
1261 head_seq_num = tid_agg_rx->head_seq_num;
1264 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1267 if (unlikely(!tid_agg_rx->started)) {
1268 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1272 tid_agg_rx->started = true;
1275 /* frame with out of date sequence number */
1276 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1282 * If frame the sequence number exceeds our buffering window
1283 * size release some previous frames to make room for this one.
1285 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1286 head_seq_num = ieee80211_sn_inc(
1287 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1288 /* release stored frames up to new head to stack */
1289 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1290 head_seq_num, frames);
1293 /* Now the new frame is always in the range of the reordering buffer */
1295 index = mpdu_seq_num % tid_agg_rx->buf_size;
1297 /* check if we already stored this frame */
1298 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1304 * If the current MPDU is in the right order and nothing else
1305 * is stored we can process it directly, no need to buffer it.
1306 * If it is first but there's something stored, we may be able
1307 * to release frames after this one.
1309 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1310 tid_agg_rx->stored_mpdu_num == 0) {
1311 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1312 tid_agg_rx->head_seq_num =
1313 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1318 /* put the frame in the reordering buffer */
1319 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1320 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1321 tid_agg_rx->reorder_time[index] = jiffies;
1322 tid_agg_rx->stored_mpdu_num++;
1323 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1327 spin_unlock(&tid_agg_rx->reorder_lock);
1332 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1333 * true if the MPDU was buffered, false if it should be processed.
1335 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1336 struct sk_buff_head *frames)
1338 struct sk_buff *skb = rx->skb;
1339 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1340 struct sta_info *sta = rx->sta;
1341 struct tid_ampdu_rx *tid_agg_rx;
1345 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1346 is_multicast_ether_addr(hdr->addr1))
1350 * filter the QoS data rx stream according to
1351 * STA/TID and check if this STA/TID is on aggregation
1357 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1358 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1359 tid = ieee80211_get_tid(hdr);
1361 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1363 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1364 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1365 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1366 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1367 WLAN_BACK_RECIPIENT,
1368 WLAN_REASON_QSTA_REQUIRE_SETUP);
1372 /* qos null data frames are excluded */
1373 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1376 /* not part of a BA session */
1377 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
1380 /* new, potentially un-ordered, ampdu frame - process it */
1382 /* reset session timer */
1383 if (tid_agg_rx->timeout)
1384 tid_agg_rx->last_rx = jiffies;
1386 /* if this mpdu is fragmented - terminate rx aggregation session */
1387 sc = le16_to_cpu(hdr->seq_ctrl);
1388 if (sc & IEEE80211_SCTL_FRAG) {
1389 ieee80211_queue_skb_to_iface(rx->sdata, rx->link_id, NULL, skb);
1394 * No locking needed -- we will only ever process one
1395 * RX packet at a time, and thus own tid_agg_rx. All
1396 * other code manipulating it needs to (and does) make
1397 * sure that we cannot get to it any more before doing
1400 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1405 __skb_queue_tail(frames, skb);
1408 static ieee80211_rx_result debug_noinline
1409 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1411 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1412 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1414 if (status->flag & RX_FLAG_DUP_VALIDATED)
1418 * Drop duplicate 802.11 retransmissions
1419 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1422 if (rx->skb->len < 24)
1425 if (ieee80211_is_ctl(hdr->frame_control) ||
1426 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1427 is_multicast_ether_addr(hdr->addr1))
1433 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1434 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1435 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1436 rx->link_sta->rx_stats.num_duplicates++;
1437 return RX_DROP_UNUSABLE;
1438 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1439 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1445 static ieee80211_rx_result debug_noinline
1446 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1448 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1450 /* Drop disallowed frame classes based on STA auth/assoc state;
1451 * IEEE 802.11, Chap 5.5.
1453 * mac80211 filters only based on association state, i.e. it drops
1454 * Class 3 frames from not associated stations. hostapd sends
1455 * deauth/disassoc frames when needed. In addition, hostapd is
1456 * responsible for filtering on both auth and assoc states.
1459 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1460 return ieee80211_rx_mesh_check(rx);
1462 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1463 ieee80211_is_pspoll(hdr->frame_control)) &&
1464 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1465 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1466 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1468 * accept port control frames from the AP even when it's not
1469 * yet marked ASSOC to prevent a race where we don't set the
1470 * assoc bit quickly enough before it sends the first frame
1472 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1473 ieee80211_is_data_present(hdr->frame_control)) {
1474 unsigned int hdrlen;
1477 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1479 if (rx->skb->len < hdrlen + 8)
1480 return RX_DROP_MONITOR;
1482 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1483 if (ethertype == rx->sdata->control_port_protocol)
1487 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1488 cfg80211_rx_spurious_frame(rx->sdata->dev,
1491 return RX_DROP_UNUSABLE;
1493 return RX_DROP_MONITOR;
1500 static ieee80211_rx_result debug_noinline
1501 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1503 struct ieee80211_local *local;
1504 struct ieee80211_hdr *hdr;
1505 struct sk_buff *skb;
1509 hdr = (struct ieee80211_hdr *) skb->data;
1511 if (!local->pspolling)
1514 if (!ieee80211_has_fromds(hdr->frame_control))
1515 /* this is not from AP */
1518 if (!ieee80211_is_data(hdr->frame_control))
1521 if (!ieee80211_has_moredata(hdr->frame_control)) {
1522 /* AP has no more frames buffered for us */
1523 local->pspolling = false;
1527 /* more data bit is set, let's request a new frame from the AP */
1528 ieee80211_send_pspoll(local, rx->sdata);
1533 static void sta_ps_start(struct sta_info *sta)
1535 struct ieee80211_sub_if_data *sdata = sta->sdata;
1536 struct ieee80211_local *local = sdata->local;
1540 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1541 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1542 ps = &sdata->bss->ps;
1546 atomic_inc(&ps->num_sta_ps);
1547 set_sta_flag(sta, WLAN_STA_PS_STA);
1548 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1549 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1550 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1551 sta->sta.addr, sta->sta.aid);
1553 ieee80211_clear_fast_xmit(sta);
1555 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1556 struct ieee80211_txq *txq = sta->sta.txq[tid];
1557 struct txq_info *txqi = to_txq_info(txq);
1559 spin_lock(&local->active_txq_lock[txq->ac]);
1560 if (!list_empty(&txqi->schedule_order))
1561 list_del_init(&txqi->schedule_order);
1562 spin_unlock(&local->active_txq_lock[txq->ac]);
1564 if (txq_has_queue(txq))
1565 set_bit(tid, &sta->txq_buffered_tids);
1567 clear_bit(tid, &sta->txq_buffered_tids);
1571 static void sta_ps_end(struct sta_info *sta)
1573 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1574 sta->sta.addr, sta->sta.aid);
1576 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1578 * Clear the flag only if the other one is still set
1579 * so that the TX path won't start TX'ing new frames
1580 * directly ... In the case that the driver flag isn't
1581 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1583 clear_sta_flag(sta, WLAN_STA_PS_STA);
1584 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1585 sta->sta.addr, sta->sta.aid);
1589 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1590 clear_sta_flag(sta, WLAN_STA_PS_STA);
1591 ieee80211_sta_ps_deliver_wakeup(sta);
1594 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1596 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1599 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1601 /* Don't let the same PS state be set twice */
1602 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1603 if ((start && in_ps) || (!start && !in_ps))
1613 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1615 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1617 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1619 if (test_sta_flag(sta, WLAN_STA_SP))
1622 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1623 ieee80211_sta_ps_deliver_poll_response(sta);
1625 set_sta_flag(sta, WLAN_STA_PSPOLL);
1627 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1629 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1631 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1632 int ac = ieee80211_ac_from_tid(tid);
1635 * If this AC is not trigger-enabled do nothing unless the
1636 * driver is calling us after it already checked.
1638 * NB: This could/should check a separate bitmap of trigger-
1639 * enabled queues, but for now we only implement uAPSD w/o
1640 * TSPEC changes to the ACs, so they're always the same.
1642 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1643 tid != IEEE80211_NUM_TIDS)
1646 /* if we are in a service period, do nothing */
1647 if (test_sta_flag(sta, WLAN_STA_SP))
1650 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1651 ieee80211_sta_ps_deliver_uapsd(sta);
1653 set_sta_flag(sta, WLAN_STA_UAPSD);
1655 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1657 static ieee80211_rx_result debug_noinline
1658 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1660 struct ieee80211_sub_if_data *sdata = rx->sdata;
1661 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1662 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1667 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1668 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1672 * The device handles station powersave, so don't do anything about
1673 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1674 * it to mac80211 since they're handled.)
1676 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1680 * Don't do anything if the station isn't already asleep. In
1681 * the uAPSD case, the station will probably be marked asleep,
1682 * in the PS-Poll case the station must be confused ...
1684 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1687 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1688 ieee80211_sta_pspoll(&rx->sta->sta);
1690 /* Free PS Poll skb here instead of returning RX_DROP that would
1691 * count as an dropped frame. */
1692 dev_kfree_skb(rx->skb);
1695 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1696 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1697 ieee80211_has_pm(hdr->frame_control) &&
1698 (ieee80211_is_data_qos(hdr->frame_control) ||
1699 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1700 u8 tid = ieee80211_get_tid(hdr);
1702 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1708 static ieee80211_rx_result debug_noinline
1709 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1711 struct sta_info *sta = rx->sta;
1712 struct link_sta_info *link_sta = rx->link_sta;
1713 struct sk_buff *skb = rx->skb;
1714 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1715 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1718 if (!sta || !link_sta)
1722 * Update last_rx only for IBSS packets which are for the current
1723 * BSSID and for station already AUTHORIZED to avoid keeping the
1724 * current IBSS network alive in cases where other STAs start
1725 * using different BSSID. This will also give the station another
1726 * chance to restart the authentication/authorization in case
1727 * something went wrong the first time.
1729 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1730 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1731 NL80211_IFTYPE_ADHOC);
1732 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1733 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1734 link_sta->rx_stats.last_rx = jiffies;
1735 if (ieee80211_is_data(hdr->frame_control) &&
1736 !is_multicast_ether_addr(hdr->addr1))
1737 link_sta->rx_stats.last_rate =
1738 sta_stats_encode_rate(status);
1740 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1741 link_sta->rx_stats.last_rx = jiffies;
1742 } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
1743 !is_multicast_ether_addr(hdr->addr1)) {
1745 * Mesh beacons will update last_rx when if they are found to
1746 * match the current local configuration when processed.
1748 link_sta->rx_stats.last_rx = jiffies;
1749 if (ieee80211_is_data(hdr->frame_control))
1750 link_sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1753 link_sta->rx_stats.fragments++;
1755 u64_stats_update_begin(&link_sta->rx_stats.syncp);
1756 link_sta->rx_stats.bytes += rx->skb->len;
1757 u64_stats_update_end(&link_sta->rx_stats.syncp);
1759 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1760 link_sta->rx_stats.last_signal = status->signal;
1761 ewma_signal_add(&link_sta->rx_stats_avg.signal,
1765 if (status->chains) {
1766 link_sta->rx_stats.chains = status->chains;
1767 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1768 int signal = status->chain_signal[i];
1770 if (!(status->chains & BIT(i)))
1773 link_sta->rx_stats.chain_signal_last[i] = signal;
1774 ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
1779 if (ieee80211_is_s1g_beacon(hdr->frame_control))
1783 * Change STA power saving mode only at the end of a frame
1784 * exchange sequence, and only for a data or management
1785 * frame as specified in IEEE 802.11-2016 11.2.3.2
1787 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1788 !ieee80211_has_morefrags(hdr->frame_control) &&
1789 !is_multicast_ether_addr(hdr->addr1) &&
1790 (ieee80211_is_mgmt(hdr->frame_control) ||
1791 ieee80211_is_data(hdr->frame_control)) &&
1792 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1793 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1794 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1795 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1796 if (!ieee80211_has_pm(hdr->frame_control))
1799 if (ieee80211_has_pm(hdr->frame_control))
1804 /* mesh power save support */
1805 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1806 ieee80211_mps_rx_h_sta_process(sta, hdr);
1809 * Drop (qos-)data::nullfunc frames silently, since they
1810 * are used only to control station power saving mode.
1812 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1813 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1816 * If we receive a 4-addr nullfunc frame from a STA
1817 * that was not moved to a 4-addr STA vlan yet send
1818 * the event to userspace and for older hostapd drop
1819 * the frame to the monitor interface.
1821 if (ieee80211_has_a4(hdr->frame_control) &&
1822 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1823 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1824 !rx->sdata->u.vlan.sta))) {
1825 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1826 cfg80211_rx_unexpected_4addr_frame(
1827 rx->sdata->dev, sta->sta.addr,
1829 return RX_DROP_M_UNEXPECTED_4ADDR_FRAME;
1832 * Update counter and free packet here to avoid
1833 * counting this as a dropped packed.
1835 link_sta->rx_stats.packets++;
1836 dev_kfree_skb(rx->skb);
1841 } /* ieee80211_rx_h_sta_process */
1843 static struct ieee80211_key *
1844 ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
1846 struct ieee80211_key *key = NULL;
1849 /* Make sure key gets set if either BIGTK key index is set so that
1850 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1851 * Beacon frames and Beacon frames that claim to use another BIGTK key
1852 * index (i.e., a key that we do not have).
1856 idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1859 if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1866 key = rcu_dereference(rx->link_sta->gtk[idx]);
1868 key = rcu_dereference(rx->link->gtk[idx]);
1869 if (!key && rx->link_sta)
1870 key = rcu_dereference(rx->link_sta->gtk[idx2]);
1872 key = rcu_dereference(rx->link->gtk[idx2]);
1877 static ieee80211_rx_result debug_noinline
1878 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1880 struct sk_buff *skb = rx->skb;
1881 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1882 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1884 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1885 struct ieee80211_key *sta_ptk = NULL;
1886 struct ieee80211_key *ptk_idx = NULL;
1887 int mmie_keyidx = -1;
1890 if (ieee80211_is_ext(hdr->frame_control))
1896 * There are five types of keys:
1897 * - GTK (group keys)
1898 * - IGTK (group keys for management frames)
1899 * - BIGTK (group keys for Beacon frames)
1900 * - PTK (pairwise keys)
1901 * - STK (station-to-station pairwise keys)
1903 * When selecting a key, we have to distinguish between multicast
1904 * (including broadcast) and unicast frames, the latter can only
1905 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1906 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1907 * then unicast frames can also use key indices like GTKs. Hence, if we
1908 * don't have a PTK/STK we check the key index for a WEP key.
1910 * Note that in a regular BSS, multicast frames are sent by the
1911 * AP only, associated stations unicast the frame to the AP first
1912 * which then multicasts it on their behalf.
1914 * There is also a slight problem in IBSS mode: GTKs are negotiated
1915 * with each station, that is something we don't currently handle.
1916 * The spec seems to expect that one negotiates the same key with
1917 * every station but there's no such requirement; VLANs could be
1921 /* start without a key */
1923 fc = hdr->frame_control;
1926 int keyid = rx->sta->ptk_idx;
1927 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1929 if (ieee80211_has_protected(fc) &&
1930 !(status->flag & RX_FLAG_IV_STRIPPED)) {
1931 keyid = ieee80211_get_keyid(rx->skb);
1933 if (unlikely(keyid < 0))
1934 return RX_DROP_UNUSABLE;
1936 ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1940 if (!ieee80211_has_protected(fc))
1941 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1943 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1944 rx->key = ptk_idx ? ptk_idx : sta_ptk;
1945 if ((status->flag & RX_FLAG_DECRYPTED) &&
1946 (status->flag & RX_FLAG_IV_STRIPPED))
1948 /* Skip decryption if the frame is not protected. */
1949 if (!ieee80211_has_protected(fc))
1951 } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
1952 /* Broadcast/multicast robust management frame / BIP */
1953 if ((status->flag & RX_FLAG_DECRYPTED) &&
1954 (status->flag & RX_FLAG_IV_STRIPPED))
1957 if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
1958 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
1959 NUM_DEFAULT_BEACON_KEYS) {
1961 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1964 return RX_DROP_M_BAD_BCN_KEYIDX;
1967 rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
1969 return RX_CONTINUE; /* Beacon protection not in use */
1970 } else if (mmie_keyidx >= 0) {
1971 /* Broadcast/multicast robust management frame / BIP */
1972 if ((status->flag & RX_FLAG_DECRYPTED) &&
1973 (status->flag & RX_FLAG_IV_STRIPPED))
1976 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1977 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1978 return RX_DROP_M_BAD_MGMT_KEYIDX; /* unexpected BIP keyidx */
1980 if (ieee80211_is_group_privacy_action(skb) &&
1981 test_sta_flag(rx->sta, WLAN_STA_MFP))
1982 return RX_DROP_MONITOR;
1984 rx->key = rcu_dereference(rx->link_sta->gtk[mmie_keyidx]);
1987 rx->key = rcu_dereference(rx->link->gtk[mmie_keyidx]);
1988 } else if (!ieee80211_has_protected(fc)) {
1990 * The frame was not protected, so skip decryption. However, we
1991 * need to set rx->key if there is a key that could have been
1992 * used so that the frame may be dropped if encryption would
1993 * have been expected.
1995 struct ieee80211_key *key = NULL;
1998 if (ieee80211_is_beacon(fc)) {
1999 key = ieee80211_rx_get_bigtk(rx, -1);
2000 } else if (ieee80211_is_mgmt(fc) &&
2001 is_multicast_ether_addr(hdr->addr1)) {
2002 key = rcu_dereference(rx->link->default_mgmt_key);
2005 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2006 key = rcu_dereference(rx->link_sta->gtk[i]);
2012 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2013 key = rcu_dereference(rx->link->gtk[i]);
2024 * The device doesn't give us the IV so we won't be
2025 * able to look up the key. That's ok though, we
2026 * don't need to decrypt the frame, we just won't
2027 * be able to keep statistics accurate.
2028 * Except for key threshold notifications, should
2029 * we somehow allow the driver to tell us which key
2030 * the hardware used if this flag is set?
2032 if ((status->flag & RX_FLAG_DECRYPTED) &&
2033 (status->flag & RX_FLAG_IV_STRIPPED))
2036 keyidx = ieee80211_get_keyid(rx->skb);
2038 if (unlikely(keyidx < 0))
2039 return RX_DROP_UNUSABLE;
2041 /* check per-station GTK first, if multicast packet */
2042 if (is_multicast_ether_addr(hdr->addr1) && rx->link_sta)
2043 rx->key = rcu_dereference(rx->link_sta->gtk[keyidx]);
2045 /* if not found, try default key */
2047 if (is_multicast_ether_addr(hdr->addr1))
2048 rx->key = rcu_dereference(rx->link->gtk[keyidx]);
2050 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
2053 * RSNA-protected unicast frames should always be
2054 * sent with pairwise or station-to-station keys,
2055 * but for WEP we allow using a key index as well.
2058 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2059 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2060 !is_multicast_ether_addr(hdr->addr1))
2066 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2067 return RX_DROP_MONITOR;
2069 /* TODO: add threshold stuff again */
2071 return RX_DROP_MONITOR;
2074 switch (rx->key->conf.cipher) {
2075 case WLAN_CIPHER_SUITE_WEP40:
2076 case WLAN_CIPHER_SUITE_WEP104:
2077 result = ieee80211_crypto_wep_decrypt(rx);
2079 case WLAN_CIPHER_SUITE_TKIP:
2080 result = ieee80211_crypto_tkip_decrypt(rx);
2082 case WLAN_CIPHER_SUITE_CCMP:
2083 result = ieee80211_crypto_ccmp_decrypt(
2084 rx, IEEE80211_CCMP_MIC_LEN);
2086 case WLAN_CIPHER_SUITE_CCMP_256:
2087 result = ieee80211_crypto_ccmp_decrypt(
2088 rx, IEEE80211_CCMP_256_MIC_LEN);
2090 case WLAN_CIPHER_SUITE_AES_CMAC:
2091 result = ieee80211_crypto_aes_cmac_decrypt(rx);
2093 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2094 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2096 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2097 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2098 result = ieee80211_crypto_aes_gmac_decrypt(rx);
2100 case WLAN_CIPHER_SUITE_GCMP:
2101 case WLAN_CIPHER_SUITE_GCMP_256:
2102 result = ieee80211_crypto_gcmp_decrypt(rx);
2105 result = RX_DROP_UNUSABLE;
2108 /* the hdr variable is invalid after the decrypt handlers */
2110 /* either the frame has been decrypted or will be dropped */
2111 status->flag |= RX_FLAG_DECRYPTED;
2113 if (unlikely(ieee80211_is_beacon(fc) && result == RX_DROP_UNUSABLE &&
2115 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2116 skb->data, skb->len);
2121 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2125 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2126 skb_queue_head_init(&cache->entries[i].skb_list);
2129 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2133 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2134 __skb_queue_purge(&cache->entries[i].skb_list);
2137 static inline struct ieee80211_fragment_entry *
2138 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2139 unsigned int frag, unsigned int seq, int rx_queue,
2140 struct sk_buff **skb)
2142 struct ieee80211_fragment_entry *entry;
2144 entry = &cache->entries[cache->next++];
2145 if (cache->next >= IEEE80211_FRAGMENT_MAX)
2148 __skb_queue_purge(&entry->skb_list);
2150 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2152 entry->first_frag_time = jiffies;
2154 entry->rx_queue = rx_queue;
2155 entry->last_frag = frag;
2156 entry->check_sequential_pn = false;
2157 entry->extra_len = 0;
2162 static inline struct ieee80211_fragment_entry *
2163 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2164 unsigned int frag, unsigned int seq,
2165 int rx_queue, struct ieee80211_hdr *hdr)
2167 struct ieee80211_fragment_entry *entry;
2171 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2172 struct ieee80211_hdr *f_hdr;
2173 struct sk_buff *f_skb;
2177 idx = IEEE80211_FRAGMENT_MAX - 1;
2179 entry = &cache->entries[idx];
2180 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2181 entry->rx_queue != rx_queue ||
2182 entry->last_frag + 1 != frag)
2185 f_skb = __skb_peek(&entry->skb_list);
2186 f_hdr = (struct ieee80211_hdr *) f_skb->data;
2189 * Check ftype and addresses are equal, else check next fragment
2191 if (((hdr->frame_control ^ f_hdr->frame_control) &
2192 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2193 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2194 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2197 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2198 __skb_queue_purge(&entry->skb_list);
2207 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2210 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2211 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2212 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2213 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2214 ieee80211_has_protected(fc);
2217 static ieee80211_rx_result debug_noinline
2218 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2220 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2221 struct ieee80211_hdr *hdr;
2224 unsigned int frag, seq;
2225 struct ieee80211_fragment_entry *entry;
2226 struct sk_buff *skb;
2227 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2229 hdr = (struct ieee80211_hdr *)rx->skb->data;
2230 fc = hdr->frame_control;
2232 if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
2235 sc = le16_to_cpu(hdr->seq_ctrl);
2236 frag = sc & IEEE80211_SCTL_FRAG;
2239 cache = &rx->sta->frags;
2241 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2244 if (is_multicast_ether_addr(hdr->addr1))
2245 return RX_DROP_MONITOR;
2247 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2249 if (skb_linearize(rx->skb))
2250 return RX_DROP_UNUSABLE;
2253 * skb_linearize() might change the skb->data and
2254 * previously cached variables (in this case, hdr) need to
2255 * be refreshed with the new data.
2257 hdr = (struct ieee80211_hdr *)rx->skb->data;
2258 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2261 /* This is the first fragment of a new frame. */
2262 entry = ieee80211_reassemble_add(cache, frag, seq,
2263 rx->seqno_idx, &(rx->skb));
2264 if (requires_sequential_pn(rx, fc)) {
2265 int queue = rx->security_idx;
2267 /* Store CCMP/GCMP PN so that we can verify that the
2268 * next fragment has a sequential PN value.
2270 entry->check_sequential_pn = true;
2271 entry->is_protected = true;
2272 entry->key_color = rx->key->color;
2273 memcpy(entry->last_pn,
2274 rx->key->u.ccmp.rx_pn[queue],
2275 IEEE80211_CCMP_PN_LEN);
2276 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2278 offsetof(struct ieee80211_key,
2280 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2281 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2282 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2283 IEEE80211_GCMP_PN_LEN);
2284 } else if (rx->key &&
2285 (ieee80211_has_protected(fc) ||
2286 (status->flag & RX_FLAG_DECRYPTED))) {
2287 entry->is_protected = true;
2288 entry->key_color = rx->key->color;
2293 /* This is a fragment for a frame that should already be pending in
2294 * fragment cache. Add this fragment to the end of the pending entry.
2296 entry = ieee80211_reassemble_find(cache, frag, seq,
2297 rx->seqno_idx, hdr);
2299 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2300 return RX_DROP_MONITOR;
2303 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2304 * MPDU PN values are not incrementing in steps of 1."
2305 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2306 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2308 if (entry->check_sequential_pn) {
2310 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2312 if (!requires_sequential_pn(rx, fc))
2313 return RX_DROP_UNUSABLE;
2315 /* Prevent mixed key and fragment cache attacks */
2316 if (entry->key_color != rx->key->color)
2317 return RX_DROP_UNUSABLE;
2319 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2320 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2326 rpn = rx->ccm_gcm.pn;
2327 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2328 return RX_DROP_UNUSABLE;
2329 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2330 } else if (entry->is_protected &&
2332 (!ieee80211_has_protected(fc) &&
2333 !(status->flag & RX_FLAG_DECRYPTED)) ||
2334 rx->key->color != entry->key_color)) {
2335 /* Drop this as a mixed key or fragment cache attack, even
2336 * if for TKIP Michael MIC should protect us, and WEP is a
2337 * lost cause anyway.
2339 return RX_DROP_UNUSABLE;
2340 } else if (entry->is_protected && rx->key &&
2341 entry->key_color != rx->key->color &&
2342 (status->flag & RX_FLAG_DECRYPTED)) {
2343 return RX_DROP_UNUSABLE;
2346 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2347 __skb_queue_tail(&entry->skb_list, rx->skb);
2348 entry->last_frag = frag;
2349 entry->extra_len += rx->skb->len;
2350 if (ieee80211_has_morefrags(fc)) {
2355 rx->skb = __skb_dequeue(&entry->skb_list);
2356 if (skb_tailroom(rx->skb) < entry->extra_len) {
2357 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2358 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2360 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2361 __skb_queue_purge(&entry->skb_list);
2362 return RX_DROP_UNUSABLE;
2365 while ((skb = __skb_dequeue(&entry->skb_list))) {
2366 skb_put_data(rx->skb, skb->data, skb->len);
2371 ieee80211_led_rx(rx->local);
2373 rx->link_sta->rx_stats.packets++;
2377 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2379 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2385 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2387 struct sk_buff *skb = rx->skb;
2388 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2391 * Pass through unencrypted frames if the hardware has
2392 * decrypted them already.
2394 if (status->flag & RX_FLAG_DECRYPTED)
2397 /* Drop unencrypted frames if key is set. */
2398 if (unlikely(!ieee80211_has_protected(fc) &&
2399 !ieee80211_is_any_nullfunc(fc) &&
2400 ieee80211_is_data(fc) && rx->key))
2406 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2408 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2409 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2410 __le16 fc = hdr->frame_control;
2413 * Pass through unencrypted frames if the hardware has
2414 * decrypted them already.
2416 if (status->flag & RX_FLAG_DECRYPTED)
2419 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2420 if (unlikely(!ieee80211_has_protected(fc) &&
2421 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2423 if (ieee80211_is_deauth(fc) ||
2424 ieee80211_is_disassoc(fc))
2425 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2430 /* BIP does not use Protected field, so need to check MMIE */
2431 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2432 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2433 if (ieee80211_is_deauth(fc) ||
2434 ieee80211_is_disassoc(fc))
2435 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2440 if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
2441 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2442 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2448 * When using MFP, Action frames are not allowed prior to
2449 * having configured keys.
2451 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2452 ieee80211_is_robust_mgmt_frame(rx->skb)))
2460 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2462 struct ieee80211_sub_if_data *sdata = rx->sdata;
2463 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2464 bool check_port_control = false;
2465 struct ethhdr *ehdr;
2468 *port_control = false;
2469 if (ieee80211_has_a4(hdr->frame_control) &&
2470 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2473 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2474 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2476 if (!sdata->u.mgd.use_4addr)
2478 else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2479 check_port_control = true;
2482 if (is_multicast_ether_addr(hdr->addr1) &&
2483 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2486 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2490 ehdr = (struct ethhdr *) rx->skb->data;
2491 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2492 *port_control = true;
2493 else if (check_port_control)
2499 bool ieee80211_is_our_addr(struct ieee80211_sub_if_data *sdata,
2500 const u8 *addr, int *out_link_id)
2502 unsigned int link_id;
2504 /* non-MLO, or MLD address replaced by hardware */
2505 if (ether_addr_equal(sdata->vif.addr, addr))
2508 if (!sdata->vif.valid_links)
2511 for (link_id = 0; link_id < ARRAY_SIZE(sdata->vif.link_conf); link_id++) {
2512 struct ieee80211_bss_conf *conf;
2514 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2518 if (ether_addr_equal(conf->addr, addr)) {
2520 *out_link_id = link_id;
2529 * requires that rx->skb is a frame with ethernet header
2531 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2533 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2534 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2535 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2538 * Allow EAPOL frames to us/the PAE group address regardless of
2539 * whether the frame was encrypted or not, and always disallow
2540 * all other destination addresses for them.
2542 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2543 return ieee80211_is_our_addr(rx->sdata, ehdr->h_dest, NULL) ||
2544 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2546 if (ieee80211_802_1x_port_control(rx) ||
2547 ieee80211_drop_unencrypted(rx, fc))
2553 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2554 struct ieee80211_rx_data *rx)
2556 struct ieee80211_sub_if_data *sdata = rx->sdata;
2557 struct net_device *dev = sdata->dev;
2559 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2560 (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
2561 !sdata->control_port_no_preauth)) &&
2562 sdata->control_port_over_nl80211)) {
2563 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2564 bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2566 cfg80211_rx_control_port(dev, skb, noencrypt, rx->link_id);
2569 struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2571 memset(skb->cb, 0, sizeof(skb->cb));
2574 * 802.1X over 802.11 requires that the authenticator address
2575 * be used for EAPOL frames. However, 802.1X allows the use of
2576 * the PAE group address instead. If the interface is part of
2577 * a bridge and we pass the frame with the PAE group address,
2578 * then the bridge will forward it to the network (even if the
2579 * client was not associated yet), which isn't supposed to
2581 * To avoid that, rewrite the destination address to our own
2582 * address, so that the authenticator (e.g. hostapd) will see
2583 * the frame, but bridge won't forward it anywhere else. Note
2584 * that due to earlier filtering, the only other address can
2585 * be the PAE group address, unless the hardware allowed them
2586 * through in 802.3 offloaded mode.
2588 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2589 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2590 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2592 /* deliver to local stack */
2594 list_add_tail(&skb->list, rx->list);
2596 netif_receive_skb(skb);
2601 * requires that rx->skb is a frame with ethernet header
2604 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2606 struct ieee80211_sub_if_data *sdata = rx->sdata;
2607 struct net_device *dev = sdata->dev;
2608 struct sk_buff *skb, *xmit_skb;
2609 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2610 struct sta_info *dsta;
2615 dev_sw_netstats_rx_add(dev, skb->len);
2618 /* The seqno index has the same property as needed
2619 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2620 * for non-QoS-data frames. Here we know it's a data
2621 * frame, so count MSDUs.
2623 u64_stats_update_begin(&rx->link_sta->rx_stats.syncp);
2624 rx->link_sta->rx_stats.msdu[rx->seqno_idx]++;
2625 u64_stats_update_end(&rx->link_sta->rx_stats.syncp);
2628 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2629 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2630 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2631 ehdr->h_proto != rx->sdata->control_port_protocol &&
2632 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2633 if (is_multicast_ether_addr(ehdr->h_dest) &&
2634 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2636 * send multicast frames both to higher layers in
2637 * local net stack and back to the wireless medium
2639 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2641 net_info_ratelimited("%s: failed to clone multicast frame\n",
2643 } else if (!is_multicast_ether_addr(ehdr->h_dest) &&
2644 !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
2645 dsta = sta_info_get(sdata, ehdr->h_dest);
2648 * The destination station is associated to
2649 * this AP (in this VLAN), so send the frame
2650 * directly to it and do not pass it to local
2659 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2661 /* 'align' will only take the values 0 or 2 here since all
2662 * frames are required to be aligned to 2-byte boundaries
2663 * when being passed to mac80211; the code here works just
2664 * as well if that isn't true, but mac80211 assumes it can
2665 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2669 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2671 if (WARN_ON(skb_headroom(skb) < 3)) {
2675 u8 *data = skb->data;
2676 size_t len = skb_headlen(skb);
2678 memmove(skb->data, data, len);
2679 skb_set_tail_pointer(skb, len);
2686 skb->protocol = eth_type_trans(skb, dev);
2687 ieee80211_deliver_skb_to_local_stack(skb, rx);
2692 * Send to wireless media and increase priority by 256 to
2693 * keep the received priority instead of reclassifying
2694 * the frame (see cfg80211_classify8021d).
2696 xmit_skb->priority += 256;
2697 xmit_skb->protocol = htons(ETH_P_802_3);
2698 skb_reset_network_header(xmit_skb);
2699 skb_reset_mac_header(xmit_skb);
2700 dev_queue_xmit(xmit_skb);
2704 #ifdef CONFIG_MAC80211_MESH
2706 ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata,
2707 struct sk_buff *skb, int hdrlen)
2709 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2710 struct ieee80211_mesh_fast_tx *entry = NULL;
2711 struct ieee80211s_hdr *mesh_hdr;
2712 struct tid_ampdu_tx *tid_tx;
2713 struct sta_info *sta;
2717 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(eth));
2718 if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
2719 entry = mesh_fast_tx_get(sdata, mesh_hdr->eaddr1);
2720 else if (!(mesh_hdr->flags & MESH_FLAGS_AE))
2721 entry = mesh_fast_tx_get(sdata, skb->data);
2725 sta = rcu_dereference(entry->mpath->next_hop);
2729 if (skb_linearize(skb))
2732 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
2733 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
2735 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
2738 if (tid_tx->timeout)
2739 tid_tx->last_tx = jiffies;
2742 ieee80211_aggr_check(sdata, sta, skb);
2744 if (ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
2748 skb->protocol = htons(skb->len - hdrlen);
2749 skb_set_network_header(skb, hdrlen + 2);
2751 skb->dev = sdata->dev;
2752 memcpy(ð, skb->data, ETH_HLEN - 2);
2754 __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
2755 eth.h_dest, eth.h_source);
2756 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2757 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2763 static ieee80211_rx_result
2764 ieee80211_rx_mesh_data(struct ieee80211_sub_if_data *sdata, struct sta_info *sta,
2765 struct sk_buff *skb)
2767 #ifdef CONFIG_MAC80211_MESH
2768 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2769 struct ieee80211_local *local = sdata->local;
2770 uint16_t fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA;
2771 struct ieee80211_hdr hdr = {
2772 .frame_control = cpu_to_le16(fc)
2774 struct ieee80211_hdr *fwd_hdr;
2775 struct ieee80211s_hdr *mesh_hdr;
2776 struct ieee80211_tx_info *info;
2777 struct sk_buff *fwd_skb;
2781 int hdrlen, mesh_hdrlen;
2784 if (!ieee80211_vif_is_mesh(&sdata->vif))
2787 if (!pskb_may_pull(skb, sizeof(*eth) + 6))
2788 return RX_DROP_MONITOR;
2790 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(*eth));
2791 mesh_hdrlen = ieee80211_get_mesh_hdrlen(mesh_hdr);
2793 if (!pskb_may_pull(skb, sizeof(*eth) + mesh_hdrlen))
2794 return RX_DROP_MONITOR;
2796 eth = (struct ethhdr *)skb->data;
2797 multicast = is_multicast_ether_addr(eth->h_dest);
2799 mesh_hdr = (struct ieee80211s_hdr *)(eth + 1);
2801 return RX_DROP_MONITOR;
2803 /* frame is in RMC, don't forward */
2804 if (is_multicast_ether_addr(eth->h_dest) &&
2805 mesh_rmc_check(sdata, eth->h_source, mesh_hdr))
2806 return RX_DROP_MONITOR;
2808 /* forward packet */
2809 if (sdata->crypto_tx_tailroom_needed_cnt)
2810 tailroom = IEEE80211_ENCRYPT_TAILROOM;
2812 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2813 struct mesh_path *mppath;
2815 bool update = false;
2818 proxied_addr = mesh_hdr->eaddr1;
2819 else if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
2820 /* has_a4 already checked in ieee80211_rx_mesh_check */
2821 proxied_addr = mesh_hdr->eaddr2;
2823 return RX_DROP_MONITOR;
2826 mppath = mpp_path_lookup(sdata, proxied_addr);
2828 mpp_path_add(sdata, proxied_addr, eth->h_source);
2830 spin_lock_bh(&mppath->state_lock);
2831 if (!ether_addr_equal(mppath->mpp, eth->h_source)) {
2832 memcpy(mppath->mpp, eth->h_source, ETH_ALEN);
2835 mppath->exp_time = jiffies;
2836 spin_unlock_bh(&mppath->state_lock);
2839 /* flush fast xmit cache if the address path changed */
2841 mesh_fast_tx_flush_addr(sdata, proxied_addr);
2846 /* Frame has reached destination. Don't forward */
2847 if (ether_addr_equal(sdata->vif.addr, eth->h_dest))
2850 if (!--mesh_hdr->ttl) {
2854 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
2855 return RX_DROP_MONITOR;
2858 if (!ifmsh->mshcfg.dot11MeshForwarding) {
2859 if (is_multicast_ether_addr(eth->h_dest))
2862 return RX_DROP_MONITOR;
2865 skb_set_queue_mapping(skb, ieee802_1d_to_ac[skb->priority]);
2868 ieee80211_rx_mesh_fast_forward(sdata, skb, mesh_hdrlen))
2871 ieee80211_fill_mesh_addresses(&hdr, &hdr.frame_control,
2872 eth->h_dest, eth->h_source);
2873 hdrlen = ieee80211_hdrlen(hdr.frame_control);
2875 int extra_head = sizeof(struct ieee80211_hdr) - sizeof(*eth);
2877 fwd_skb = skb_copy_expand(skb, local->tx_headroom + extra_head +
2878 IEEE80211_ENCRYPT_HEADROOM,
2879 tailroom, GFP_ATOMIC);
2886 if (skb_cow_head(fwd_skb, hdrlen - sizeof(struct ethhdr)))
2887 return RX_DROP_UNUSABLE;
2889 if (skb_linearize(fwd_skb))
2890 return RX_DROP_UNUSABLE;
2893 fwd_hdr = skb_push(fwd_skb, hdrlen - sizeof(struct ethhdr));
2894 memcpy(fwd_hdr, &hdr, hdrlen - 2);
2895 qos = ieee80211_get_qos_ctl(fwd_hdr);
2896 qos[0] = qos[1] = 0;
2898 skb_reset_mac_header(fwd_skb);
2899 hdrlen += mesh_hdrlen;
2900 if (ieee80211_get_8023_tunnel_proto(fwd_skb->data + hdrlen,
2901 &fwd_skb->protocol))
2904 fwd_skb->protocol = htons(fwd_skb->len - hdrlen);
2905 skb_set_network_header(fwd_skb, hdrlen + 2);
2907 info = IEEE80211_SKB_CB(fwd_skb);
2908 memset(info, 0, sizeof(*info));
2909 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
2910 info->control.vif = &sdata->vif;
2911 info->control.jiffies = jiffies;
2912 fwd_skb->dev = sdata->dev;
2914 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2915 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2916 /* update power mode indication when forwarding */
2917 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2918 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2919 /* mesh power mode flags updated in mesh_nexthop_lookup */
2920 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2922 /* unable to resolve next hop */
2924 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2926 WLAN_REASON_MESH_PATH_NOFORWARD,
2928 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2933 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2934 ieee80211_add_pending_skb(local, fwd_skb);
2940 ieee80211_strip_8023_mesh_hdr(skb);
2946 static ieee80211_rx_result debug_noinline
2947 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2949 struct net_device *dev = rx->sdata->dev;
2950 struct sk_buff *skb = rx->skb;
2951 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2952 __le16 fc = hdr->frame_control;
2953 struct sk_buff_head frame_list;
2954 ieee80211_rx_result res;
2955 struct ethhdr ethhdr;
2956 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2958 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2961 } else switch (rx->sdata->vif.type) {
2962 case NL80211_IFTYPE_AP:
2963 case NL80211_IFTYPE_AP_VLAN:
2966 case NL80211_IFTYPE_STATION:
2968 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2971 case NL80211_IFTYPE_MESH_POINT:
2980 __skb_queue_head_init(&frame_list);
2982 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2983 rx->sdata->vif.addr,
2984 rx->sdata->vif.type,
2986 return RX_DROP_UNUSABLE;
2988 if (rx->sta->amsdu_mesh_control < 0) {
2992 for (i = 0; i <= 2; i++) {
2993 if (!ieee80211_is_valid_amsdu(skb, i))
3005 rx->sta->amsdu_mesh_control = valid;
3008 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
3009 rx->sdata->vif.type,
3010 rx->local->hw.extra_tx_headroom,
3012 rx->sta->amsdu_mesh_control);
3014 while (!skb_queue_empty(&frame_list)) {
3015 rx->skb = __skb_dequeue(&frame_list);
3017 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
3027 if (!ieee80211_frame_allowed(rx, fc))
3030 ieee80211_deliver_skb(rx);
3034 dev_kfree_skb(rx->skb);
3040 static ieee80211_rx_result debug_noinline
3041 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
3043 struct sk_buff *skb = rx->skb;
3044 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3045 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3046 __le16 fc = hdr->frame_control;
3048 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
3051 if (unlikely(!ieee80211_is_data(fc)))
3054 if (unlikely(!ieee80211_is_data_present(fc)))
3055 return RX_DROP_MONITOR;
3057 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
3058 switch (rx->sdata->vif.type) {
3059 case NL80211_IFTYPE_AP_VLAN:
3060 if (!rx->sdata->u.vlan.sta)
3061 return RX_DROP_UNUSABLE;
3063 case NL80211_IFTYPE_STATION:
3064 if (!rx->sdata->u.mgd.use_4addr)
3065 return RX_DROP_UNUSABLE;
3067 case NL80211_IFTYPE_MESH_POINT:
3070 return RX_DROP_UNUSABLE;
3074 if (is_multicast_ether_addr(hdr->addr1) || !rx->sta)
3075 return RX_DROP_UNUSABLE;
3079 * We should not receive A-MSDUs on pre-HT connections,
3080 * and HT connections cannot use old ciphers. Thus drop
3081 * them, as in those cases we couldn't even have SPP
3084 switch (rx->key->conf.cipher) {
3085 case WLAN_CIPHER_SUITE_WEP40:
3086 case WLAN_CIPHER_SUITE_WEP104:
3087 case WLAN_CIPHER_SUITE_TKIP:
3088 return RX_DROP_UNUSABLE;
3094 return __ieee80211_rx_h_amsdu(rx, 0);
3097 static ieee80211_rx_result debug_noinline
3098 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
3100 struct ieee80211_sub_if_data *sdata = rx->sdata;
3101 struct ieee80211_local *local = rx->local;
3102 struct net_device *dev = sdata->dev;
3103 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
3104 __le16 fc = hdr->frame_control;
3105 ieee80211_rx_result res;
3109 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
3112 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
3113 return RX_DROP_MONITOR;
3116 * Send unexpected-4addr-frame event to hostapd. For older versions,
3117 * also drop the frame to cooked monitor interfaces.
3119 if (ieee80211_has_a4(hdr->frame_control) &&
3120 sdata->vif.type == NL80211_IFTYPE_AP) {
3122 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
3123 cfg80211_rx_unexpected_4addr_frame(
3124 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
3125 return RX_DROP_MONITOR;
3128 err = __ieee80211_data_to_8023(rx, &port_control);
3130 return RX_DROP_UNUSABLE;
3132 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
3133 if (res != RX_CONTINUE)
3136 if (!ieee80211_frame_allowed(rx, fc))
3137 return RX_DROP_MONITOR;
3139 /* directly handle TDLS channel switch requests/responses */
3140 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
3141 cpu_to_be16(ETH_P_TDLS))) {
3142 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
3144 if (pskb_may_pull(rx->skb,
3145 offsetof(struct ieee80211_tdls_data, u)) &&
3146 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
3147 tf->category == WLAN_CATEGORY_TDLS &&
3148 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
3149 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
3150 rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
3151 __ieee80211_queue_skb_to_iface(sdata, rx->link_id,
3157 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3158 unlikely(port_control) && sdata->bss) {
3159 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
3167 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3168 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
3169 !is_multicast_ether_addr(
3170 ((struct ethhdr *)rx->skb->data)->h_dest) &&
3171 (!local->scanning &&
3172 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
3173 mod_timer(&local->dynamic_ps_timer, jiffies +
3174 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
3176 ieee80211_deliver_skb(rx);
3181 static ieee80211_rx_result debug_noinline
3182 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
3184 struct sk_buff *skb = rx->skb;
3185 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
3186 struct tid_ampdu_rx *tid_agg_rx;
3190 if (likely(!ieee80211_is_ctl(bar->frame_control)))
3193 if (ieee80211_is_back_req(bar->frame_control)) {
3195 __le16 control, start_seq_num;
3196 } __packed bar_data;
3197 struct ieee80211_event event = {
3198 .type = BAR_RX_EVENT,
3202 return RX_DROP_MONITOR;
3204 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
3205 &bar_data, sizeof(bar_data)))
3206 return RX_DROP_MONITOR;
3208 tid = le16_to_cpu(bar_data.control) >> 12;
3210 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
3211 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
3212 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
3213 WLAN_BACK_RECIPIENT,
3214 WLAN_REASON_QSTA_REQUIRE_SETUP);
3216 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
3218 return RX_DROP_MONITOR;
3220 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
3221 event.u.ba.tid = tid;
3222 event.u.ba.ssn = start_seq_num;
3223 event.u.ba.sta = &rx->sta->sta;
3225 /* reset session timer */
3226 if (tid_agg_rx->timeout)
3227 mod_timer(&tid_agg_rx->session_timer,
3228 TU_TO_EXP_TIME(tid_agg_rx->timeout));
3230 spin_lock(&tid_agg_rx->reorder_lock);
3231 /* release stored frames up to start of BAR */
3232 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
3233 start_seq_num, frames);
3234 spin_unlock(&tid_agg_rx->reorder_lock);
3236 drv_event_callback(rx->local, rx->sdata, &event);
3243 * After this point, we only want management frames,
3244 * so we can drop all remaining control frames to
3245 * cooked monitor interfaces.
3247 return RX_DROP_MONITOR;
3250 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
3251 struct ieee80211_mgmt *mgmt,
3254 struct ieee80211_local *local = sdata->local;
3255 struct sk_buff *skb;
3256 struct ieee80211_mgmt *resp;
3258 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
3259 /* Not to own unicast address */
3263 if (!ether_addr_equal(mgmt->sa, sdata->deflink.u.mgd.bssid) ||
3264 !ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid)) {
3265 /* Not from the current AP or not associated yet. */
3269 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3270 /* Too short SA Query request frame */
3274 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3278 skb_reserve(skb, local->hw.extra_tx_headroom);
3279 resp = skb_put_zero(skb, 24);
3280 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3281 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3282 memcpy(resp->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3283 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3284 IEEE80211_STYPE_ACTION);
3285 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3286 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3287 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3288 memcpy(resp->u.action.u.sa_query.trans_id,
3289 mgmt->u.action.u.sa_query.trans_id,
3290 WLAN_SA_QUERY_TR_ID_LEN);
3292 ieee80211_tx_skb(sdata, skb);
3296 ieee80211_rx_check_bss_color_collision(struct ieee80211_rx_data *rx)
3298 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3299 const struct element *ie;
3302 if (!wiphy_ext_feature_isset(rx->local->hw.wiphy,
3303 NL80211_EXT_FEATURE_BSS_COLOR))
3306 if (ieee80211_hw_check(&rx->local->hw, DETECTS_COLOR_COLLISION))
3309 if (rx->sdata->vif.bss_conf.csa_active)
3312 baselen = mgmt->u.beacon.variable - rx->skb->data;
3313 if (baselen > rx->skb->len)
3316 ie = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION,
3317 mgmt->u.beacon.variable,
3318 rx->skb->len - baselen);
3319 if (ie && ie->datalen >= sizeof(struct ieee80211_he_operation) &&
3320 ie->datalen >= ieee80211_he_oper_size(ie->data + 1)) {
3321 struct ieee80211_bss_conf *bss_conf = &rx->sdata->vif.bss_conf;
3322 const struct ieee80211_he_operation *he_oper;
3325 he_oper = (void *)(ie->data + 1);
3326 if (le32_get_bits(he_oper->he_oper_params,
3327 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED))
3330 color = le32_get_bits(he_oper->he_oper_params,
3331 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3332 if (color == bss_conf->he_bss_color.color)
3333 ieee80211_obss_color_collision_notify(&rx->sdata->vif,
3339 static ieee80211_rx_result debug_noinline
3340 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3342 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3343 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3345 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
3349 * From here on, look only at management frames.
3350 * Data and control frames are already handled,
3351 * and unknown (reserved) frames are useless.
3353 if (rx->skb->len < 24)
3354 return RX_DROP_MONITOR;
3356 if (!ieee80211_is_mgmt(mgmt->frame_control))
3357 return RX_DROP_MONITOR;
3359 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3360 ieee80211_is_beacon(mgmt->frame_control) &&
3361 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3364 /* sw bss color collision detection */
3365 ieee80211_rx_check_bss_color_collision(rx);
3367 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3368 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3369 sig = status->signal;
3371 cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3372 rx->skb->data, rx->skb->len,
3373 ieee80211_rx_status_to_khz(status),
3375 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3378 if (ieee80211_drop_unencrypted_mgmt(rx))
3379 return RX_DROP_UNUSABLE;
3385 ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
3387 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
3388 struct ieee80211_sub_if_data *sdata = rx->sdata;
3390 /* TWT actions are only supported in AP for the moment */
3391 if (sdata->vif.type != NL80211_IFTYPE_AP)
3394 if (!rx->local->ops->add_twt_setup)
3397 if (!sdata->vif.bss_conf.twt_responder)
3403 switch (mgmt->u.action.u.s1g.action_code) {
3404 case WLAN_S1G_TWT_SETUP: {
3405 struct ieee80211_twt_setup *twt;
3407 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3408 1 + /* action code */
3409 sizeof(struct ieee80211_twt_setup) +
3410 2 /* TWT req_type agrt */)
3413 twt = (void *)mgmt->u.action.u.s1g.variable;
3414 if (twt->element_id != WLAN_EID_S1G_TWT)
3417 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3418 4 + /* action code + token + tlv */
3422 return true; /* queue the frame */
3424 case WLAN_S1G_TWT_TEARDOWN:
3425 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
3428 return true; /* queue the frame */
3436 static ieee80211_rx_result debug_noinline
3437 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3439 struct ieee80211_local *local = rx->local;
3440 struct ieee80211_sub_if_data *sdata = rx->sdata;
3441 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3442 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3443 int len = rx->skb->len;
3445 if (!ieee80211_is_action(mgmt->frame_control))
3448 /* drop too small frames */
3449 if (len < IEEE80211_MIN_ACTION_SIZE)
3450 return RX_DROP_UNUSABLE;
3452 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3453 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3454 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3455 return RX_DROP_UNUSABLE;
3457 switch (mgmt->u.action.category) {
3458 case WLAN_CATEGORY_HT:
3459 /* reject HT action frames from stations not supporting HT */
3460 if (!rx->link_sta->pub->ht_cap.ht_supported)
3463 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3464 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3465 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3466 sdata->vif.type != NL80211_IFTYPE_AP &&
3467 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3470 /* verify action & smps_control/chanwidth are present */
3471 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3474 switch (mgmt->u.action.u.ht_smps.action) {
3475 case WLAN_HT_ACTION_SMPS: {
3476 struct ieee80211_supported_band *sband;
3477 enum ieee80211_smps_mode smps_mode;
3478 struct sta_opmode_info sta_opmode = {};
3480 if (sdata->vif.type != NL80211_IFTYPE_AP &&
3481 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3484 /* convert to HT capability */
3485 switch (mgmt->u.action.u.ht_smps.smps_control) {
3486 case WLAN_HT_SMPS_CONTROL_DISABLED:
3487 smps_mode = IEEE80211_SMPS_OFF;
3489 case WLAN_HT_SMPS_CONTROL_STATIC:
3490 smps_mode = IEEE80211_SMPS_STATIC;
3492 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3493 smps_mode = IEEE80211_SMPS_DYNAMIC;
3499 /* if no change do nothing */
3500 if (rx->link_sta->pub->smps_mode == smps_mode)
3502 rx->link_sta->pub->smps_mode = smps_mode;
3503 sta_opmode.smps_mode =
3504 ieee80211_smps_mode_to_smps_mode(smps_mode);
3505 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3507 sband = rx->local->hw.wiphy->bands[status->band];
3509 rate_control_rate_update(local, sband, rx->sta, 0,
3510 IEEE80211_RC_SMPS_CHANGED);
3511 cfg80211_sta_opmode_change_notify(sdata->dev,
3517 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3518 struct ieee80211_supported_band *sband;
3519 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3520 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3521 struct sta_opmode_info sta_opmode = {};
3523 /* If it doesn't support 40 MHz it can't change ... */
3524 if (!(rx->link_sta->pub->ht_cap.cap &
3525 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3528 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3529 max_bw = IEEE80211_STA_RX_BW_20;
3531 max_bw = ieee80211_sta_cap_rx_bw(rx->link_sta);
3533 /* set cur_max_bandwidth and recalc sta bw */
3534 rx->link_sta->cur_max_bandwidth = max_bw;
3535 new_bw = ieee80211_sta_cur_vht_bw(rx->link_sta);
3537 if (rx->link_sta->pub->bandwidth == new_bw)
3540 rx->link_sta->pub->bandwidth = new_bw;
3541 sband = rx->local->hw.wiphy->bands[status->band];
3543 ieee80211_sta_rx_bw_to_chan_width(rx->link_sta);
3544 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3546 rate_control_rate_update(local, sband, rx->sta, 0,
3547 IEEE80211_RC_BW_CHANGED);
3548 cfg80211_sta_opmode_change_notify(sdata->dev,
3559 case WLAN_CATEGORY_PUBLIC:
3560 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3562 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3566 if (!ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid))
3568 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3569 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3571 if (len < offsetof(struct ieee80211_mgmt,
3572 u.action.u.ext_chan_switch.variable))
3575 case WLAN_CATEGORY_VHT:
3576 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3577 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3578 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3579 sdata->vif.type != NL80211_IFTYPE_AP &&
3580 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3583 /* verify action code is present */
3584 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3587 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3588 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3589 /* verify opmode is present */
3590 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3594 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3595 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3603 case WLAN_CATEGORY_BACK:
3604 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3605 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3606 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3607 sdata->vif.type != NL80211_IFTYPE_AP &&
3608 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3611 /* verify action_code is present */
3612 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3615 switch (mgmt->u.action.u.addba_req.action_code) {
3616 case WLAN_ACTION_ADDBA_REQ:
3617 if (len < (IEEE80211_MIN_ACTION_SIZE +
3618 sizeof(mgmt->u.action.u.addba_req)))
3621 case WLAN_ACTION_ADDBA_RESP:
3622 if (len < (IEEE80211_MIN_ACTION_SIZE +
3623 sizeof(mgmt->u.action.u.addba_resp)))
3626 case WLAN_ACTION_DELBA:
3627 if (len < (IEEE80211_MIN_ACTION_SIZE +
3628 sizeof(mgmt->u.action.u.delba)))
3636 case WLAN_CATEGORY_SPECTRUM_MGMT:
3637 /* verify action_code is present */
3638 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3641 switch (mgmt->u.action.u.measurement.action_code) {
3642 case WLAN_ACTION_SPCT_MSR_REQ:
3643 if (status->band != NL80211_BAND_5GHZ)
3646 if (len < (IEEE80211_MIN_ACTION_SIZE +
3647 sizeof(mgmt->u.action.u.measurement)))
3650 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3653 ieee80211_process_measurement_req(sdata, mgmt, len);
3655 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3657 if (len < (IEEE80211_MIN_ACTION_SIZE +
3658 sizeof(mgmt->u.action.u.chan_switch)))
3661 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3662 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3663 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3666 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3667 bssid = sdata->deflink.u.mgd.bssid;
3668 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3669 bssid = sdata->u.ibss.bssid;
3670 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3675 if (!ether_addr_equal(mgmt->bssid, bssid))
3682 case WLAN_CATEGORY_SELF_PROTECTED:
3683 if (len < (IEEE80211_MIN_ACTION_SIZE +
3684 sizeof(mgmt->u.action.u.self_prot.action_code)))
3687 switch (mgmt->u.action.u.self_prot.action_code) {
3688 case WLAN_SP_MESH_PEERING_OPEN:
3689 case WLAN_SP_MESH_PEERING_CLOSE:
3690 case WLAN_SP_MESH_PEERING_CONFIRM:
3691 if (!ieee80211_vif_is_mesh(&sdata->vif))
3693 if (sdata->u.mesh.user_mpm)
3694 /* userspace handles this frame */
3697 case WLAN_SP_MGK_INFORM:
3698 case WLAN_SP_MGK_ACK:
3699 if (!ieee80211_vif_is_mesh(&sdata->vif))
3704 case WLAN_CATEGORY_MESH_ACTION:
3705 if (len < (IEEE80211_MIN_ACTION_SIZE +
3706 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3709 if (!ieee80211_vif_is_mesh(&sdata->vif))
3711 if (mesh_action_is_path_sel(mgmt) &&
3712 !mesh_path_sel_is_hwmp(sdata))
3715 case WLAN_CATEGORY_S1G:
3716 switch (mgmt->u.action.u.s1g.action_code) {
3717 case WLAN_S1G_TWT_SETUP:
3718 case WLAN_S1G_TWT_TEARDOWN:
3719 if (ieee80211_process_rx_twt_action(rx))
3731 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3732 /* will return in the next handlers */
3737 rx->link_sta->rx_stats.packets++;
3738 dev_kfree_skb(rx->skb);
3742 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3746 static ieee80211_rx_result debug_noinline
3747 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3749 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3750 struct cfg80211_rx_info info = {
3751 .freq = ieee80211_rx_status_to_khz(status),
3752 .buf = rx->skb->data,
3753 .len = rx->skb->len,
3754 .link_id = rx->link_id,
3755 .have_link_id = rx->link_id >= 0,
3758 /* skip known-bad action frames and return them in the next handler */
3759 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3763 * Getting here means the kernel doesn't know how to handle
3764 * it, but maybe userspace does ... include returned frames
3765 * so userspace can register for those to know whether ones
3766 * it transmitted were processed or returned.
3769 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3770 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3771 info.sig_dbm = status->signal;
3773 if (ieee80211_is_timing_measurement(rx->skb) ||
3774 ieee80211_is_ftm(rx->skb)) {
3775 info.rx_tstamp = ktime_to_ns(skb_hwtstamps(rx->skb)->hwtstamp);
3776 info.ack_tstamp = ktime_to_ns(status->ack_tx_hwtstamp);
3779 if (cfg80211_rx_mgmt_ext(&rx->sdata->wdev, &info)) {
3781 rx->link_sta->rx_stats.packets++;
3782 dev_kfree_skb(rx->skb);
3789 static ieee80211_rx_result debug_noinline
3790 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
3792 struct ieee80211_sub_if_data *sdata = rx->sdata;
3793 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3794 int len = rx->skb->len;
3796 if (!ieee80211_is_action(mgmt->frame_control))
3799 switch (mgmt->u.action.category) {
3800 case WLAN_CATEGORY_SA_QUERY:
3801 if (len < (IEEE80211_MIN_ACTION_SIZE +
3802 sizeof(mgmt->u.action.u.sa_query)))
3805 switch (mgmt->u.action.u.sa_query.action) {
3806 case WLAN_ACTION_SA_QUERY_REQUEST:
3807 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3809 ieee80211_process_sa_query_req(sdata, mgmt, len);
3819 rx->link_sta->rx_stats.packets++;
3820 dev_kfree_skb(rx->skb);
3824 static ieee80211_rx_result debug_noinline
3825 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3827 struct ieee80211_local *local = rx->local;
3828 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3829 struct sk_buff *nskb;
3830 struct ieee80211_sub_if_data *sdata = rx->sdata;
3831 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3833 if (!ieee80211_is_action(mgmt->frame_control))
3837 * For AP mode, hostapd is responsible for handling any action
3838 * frames that we didn't handle, including returning unknown
3839 * ones. For all other modes we will return them to the sender,
3840 * setting the 0x80 bit in the action category, as required by
3841 * 802.11-2012 9.24.4.
3842 * Newer versions of hostapd shall also use the management frame
3843 * registration mechanisms, but older ones still use cooked
3844 * monitor interfaces so push all frames there.
3846 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3847 (sdata->vif.type == NL80211_IFTYPE_AP ||
3848 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3849 return RX_DROP_MONITOR;
3851 if (is_multicast_ether_addr(mgmt->da))
3852 return RX_DROP_MONITOR;
3854 /* do not return rejected action frames */
3855 if (mgmt->u.action.category & 0x80)
3856 return RX_DROP_UNUSABLE;
3858 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3861 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3863 nmgmt->u.action.category |= 0x80;
3864 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3865 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3867 memset(nskb->cb, 0, sizeof(nskb->cb));
3869 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3870 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3872 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3873 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3874 IEEE80211_TX_CTL_NO_CCK_RATE;
3875 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3877 local->hw.offchannel_tx_hw_queue;
3880 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, -1,
3883 dev_kfree_skb(rx->skb);
3887 static ieee80211_rx_result debug_noinline
3888 ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
3890 struct ieee80211_sub_if_data *sdata = rx->sdata;
3891 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
3893 if (!ieee80211_is_ext(hdr->frame_control))
3896 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3897 return RX_DROP_MONITOR;
3899 /* for now only beacons are ext, so queue them */
3900 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3905 static ieee80211_rx_result debug_noinline
3906 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3908 struct ieee80211_sub_if_data *sdata = rx->sdata;
3909 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3912 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3914 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3915 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3916 sdata->vif.type != NL80211_IFTYPE_OCB &&
3917 sdata->vif.type != NL80211_IFTYPE_STATION)
3918 return RX_DROP_MONITOR;
3921 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3922 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3923 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3924 /* process for all: mesh, mlme, ibss */
3926 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3927 if (is_multicast_ether_addr(mgmt->da) &&
3928 !is_broadcast_ether_addr(mgmt->da))
3929 return RX_DROP_MONITOR;
3931 /* process only for station/IBSS */
3932 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3933 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3934 return RX_DROP_MONITOR;
3936 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3937 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3938 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3939 if (is_multicast_ether_addr(mgmt->da) &&
3940 !is_broadcast_ether_addr(mgmt->da))
3941 return RX_DROP_MONITOR;
3943 /* process only for station */
3944 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3945 return RX_DROP_MONITOR;
3947 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3948 /* process only for ibss and mesh */
3949 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3950 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3951 return RX_DROP_MONITOR;
3954 return RX_DROP_MONITOR;
3957 ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
3962 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3963 struct ieee80211_rate *rate,
3964 ieee80211_rx_result reason)
3966 struct ieee80211_sub_if_data *sdata;
3967 struct ieee80211_local *local = rx->local;
3968 struct sk_buff *skb = rx->skb, *skb2;
3969 struct net_device *prev_dev = NULL;
3970 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3971 int needed_headroom;
3974 * If cooked monitor has been processed already, then
3975 * don't do it again. If not, set the flag.
3977 if (rx->flags & IEEE80211_RX_CMNTR)
3979 rx->flags |= IEEE80211_RX_CMNTR;
3981 /* If there are no cooked monitor interfaces, just free the SKB */
3982 if (!local->cooked_mntrs)
3985 /* room for the radiotap header based on driver features */
3986 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3988 if (skb_headroom(skb) < needed_headroom &&
3989 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3992 /* prepend radiotap information */
3993 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3996 skb_reset_mac_header(skb);
3997 skb->ip_summed = CHECKSUM_UNNECESSARY;
3998 skb->pkt_type = PACKET_OTHERHOST;
3999 skb->protocol = htons(ETH_P_802_2);
4001 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4002 if (!ieee80211_sdata_running(sdata))
4005 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
4006 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
4010 skb2 = skb_clone(skb, GFP_ATOMIC);
4012 skb2->dev = prev_dev;
4013 netif_receive_skb(skb2);
4017 prev_dev = sdata->dev;
4018 dev_sw_netstats_rx_add(sdata->dev, skb->len);
4022 skb->dev = prev_dev;
4023 netif_receive_skb(skb);
4028 kfree_skb_reason(skb, (__force u32)reason);
4031 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
4032 ieee80211_rx_result res)
4034 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4035 struct ieee80211_supported_band *sband;
4036 struct ieee80211_rate *rate = NULL;
4038 if (res == RX_QUEUED) {
4039 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
4043 if (res != RX_CONTINUE) {
4044 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
4046 rx->link_sta->rx_stats.dropped++;
4049 if (u32_get_bits((__force u32)res, SKB_DROP_REASON_SUBSYS_MASK) ==
4050 SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE) {
4051 kfree_skb_reason(rx->skb, (__force u32)res);
4055 sband = rx->local->hw.wiphy->bands[status->band];
4056 if (status->encoding == RX_ENC_LEGACY)
4057 rate = &sband->bitrates[status->rate_idx];
4059 ieee80211_rx_cooked_monitor(rx, rate, res);
4062 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
4063 struct sk_buff_head *frames)
4065 ieee80211_rx_result res = RX_DROP_MONITOR;
4066 struct sk_buff *skb;
4068 #define CALL_RXH(rxh) \
4071 if (res != RX_CONTINUE) \
4075 /* Lock here to avoid hitting all of the data used in the RX
4076 * path (e.g. key data, station data, ...) concurrently when
4077 * a frame is released from the reorder buffer due to timeout
4078 * from the timer, potentially concurrently with RX from the
4081 spin_lock_bh(&rx->local->rx_path_lock);
4083 while ((skb = __skb_dequeue(frames))) {
4085 * all the other fields are valid across frames
4086 * that belong to an aMPDU since they are on the
4087 * same TID from the same station
4091 if (WARN_ON_ONCE(!rx->link))
4094 CALL_RXH(ieee80211_rx_h_check_more_data);
4095 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
4096 CALL_RXH(ieee80211_rx_h_sta_process);
4097 CALL_RXH(ieee80211_rx_h_decrypt);
4098 CALL_RXH(ieee80211_rx_h_defragment);
4099 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
4100 /* must be after MMIC verify so header is counted in MPDU mic */
4101 CALL_RXH(ieee80211_rx_h_amsdu);
4102 CALL_RXH(ieee80211_rx_h_data);
4104 /* special treatment -- needs the queue */
4105 res = ieee80211_rx_h_ctrl(rx, frames);
4106 if (res != RX_CONTINUE)
4109 CALL_RXH(ieee80211_rx_h_mgmt_check);
4110 CALL_RXH(ieee80211_rx_h_action);
4111 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
4112 CALL_RXH(ieee80211_rx_h_action_post_userspace);
4113 CALL_RXH(ieee80211_rx_h_action_return);
4114 CALL_RXH(ieee80211_rx_h_ext);
4115 CALL_RXH(ieee80211_rx_h_mgmt);
4118 ieee80211_rx_handlers_result(rx, res);
4123 spin_unlock_bh(&rx->local->rx_path_lock);
4126 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
4128 struct sk_buff_head reorder_release;
4129 ieee80211_rx_result res = RX_DROP_MONITOR;
4131 __skb_queue_head_init(&reorder_release);
4133 #define CALL_RXH(rxh) \
4136 if (res != RX_CONTINUE) \
4140 CALL_RXH(ieee80211_rx_h_check_dup);
4141 CALL_RXH(ieee80211_rx_h_check);
4143 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
4145 ieee80211_rx_handlers(rx, &reorder_release);
4149 ieee80211_rx_handlers_result(rx, res);
4155 ieee80211_rx_is_valid_sta_link_id(struct ieee80211_sta *sta, u8 link_id)
4157 return !!(sta->valid_links & BIT(link_id));
4160 static bool ieee80211_rx_data_set_link(struct ieee80211_rx_data *rx,
4163 rx->link_id = link_id;
4164 rx->link = rcu_dereference(rx->sdata->link[link_id]);
4169 if (!ieee80211_rx_is_valid_sta_link_id(&rx->sta->sta, link_id))
4172 rx->link_sta = rcu_dereference(rx->sta->link[link_id]);
4174 return rx->link && rx->link_sta;
4177 static bool ieee80211_rx_data_set_sta(struct ieee80211_rx_data *rx,
4178 struct sta_info *sta, int link_id)
4180 rx->link_id = link_id;
4184 rx->local = sta->sdata->local;
4186 rx->sdata = sta->sdata;
4187 rx->link_sta = &sta->deflink;
4189 rx->link_sta = NULL;
4193 rx->link = &rx->sdata->deflink;
4194 else if (!ieee80211_rx_data_set_link(rx, link_id))
4201 * This function makes calls into the RX path, therefore
4202 * it has to be invoked under RCU read lock.
4204 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
4206 struct sk_buff_head frames;
4207 struct ieee80211_rx_data rx = {
4208 /* This is OK -- must be QoS data frame */
4209 .security_idx = tid,
4212 struct tid_ampdu_rx *tid_agg_rx;
4215 /* FIXME: statistics won't be right with this */
4216 if (sta->sta.valid_links)
4217 link_id = ffs(sta->sta.valid_links) - 1;
4219 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
4222 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4226 __skb_queue_head_init(&frames);
4228 spin_lock(&tid_agg_rx->reorder_lock);
4229 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4230 spin_unlock(&tid_agg_rx->reorder_lock);
4232 if (!skb_queue_empty(&frames)) {
4233 struct ieee80211_event event = {
4234 .type = BA_FRAME_TIMEOUT,
4236 .u.ba.sta = &sta->sta,
4238 drv_event_callback(rx.local, rx.sdata, &event);
4241 ieee80211_rx_handlers(&rx, &frames);
4244 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
4245 u16 ssn, u64 filtered,
4248 struct sta_info *sta;
4249 struct tid_ampdu_rx *tid_agg_rx;
4250 struct sk_buff_head frames;
4251 struct ieee80211_rx_data rx = {
4252 /* This is OK -- must be QoS data frame */
4253 .security_idx = tid,
4258 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
4261 __skb_queue_head_init(&frames);
4263 sta = container_of(pubsta, struct sta_info, sta);
4265 if (!ieee80211_rx_data_set_sta(&rx, sta, -1))
4269 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4273 spin_lock_bh(&tid_agg_rx->reorder_lock);
4275 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
4278 /* release all frames in the reorder buffer */
4279 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
4280 IEEE80211_SN_MODULO;
4281 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
4283 /* update ssn to match received ssn */
4284 tid_agg_rx->head_seq_num = ssn;
4286 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
4290 /* handle the case that received ssn is behind the mac ssn.
4291 * it can be tid_agg_rx->buf_size behind and still be valid */
4292 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
4293 if (diff >= tid_agg_rx->buf_size) {
4294 tid_agg_rx->reorder_buf_filtered = 0;
4297 filtered = filtered >> diff;
4301 for (i = 0; i < tid_agg_rx->buf_size; i++) {
4302 int index = (ssn + i) % tid_agg_rx->buf_size;
4304 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
4305 if (filtered & BIT_ULL(i))
4306 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
4309 /* now process also frames that the filter marking released */
4310 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4313 spin_unlock_bh(&tid_agg_rx->reorder_lock);
4315 ieee80211_rx_handlers(&rx, &frames);
4320 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
4322 /* main receive path */
4324 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
4326 return ether_addr_equal(raddr, addr) ||
4327 is_broadcast_ether_addr(raddr);
4330 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
4332 struct ieee80211_sub_if_data *sdata = rx->sdata;
4333 struct sk_buff *skb = rx->skb;
4334 struct ieee80211_hdr *hdr = (void *)skb->data;
4335 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4336 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
4337 bool multicast = is_multicast_ether_addr(hdr->addr1) ||
4338 ieee80211_is_s1g_beacon(hdr->frame_control);
4340 switch (sdata->vif.type) {
4341 case NL80211_IFTYPE_STATION:
4342 if (!bssid && !sdata->u.mgd.use_4addr)
4344 if (ieee80211_is_first_frag(hdr->seq_ctrl) &&
4345 ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
4349 return ieee80211_is_our_addr(sdata, hdr->addr1, &rx->link_id);
4350 case NL80211_IFTYPE_ADHOC:
4353 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
4354 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
4355 !is_valid_ether_addr(hdr->addr2))
4357 if (ieee80211_is_beacon(hdr->frame_control))
4359 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
4362 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4366 if (status->encoding != RX_ENC_LEGACY)
4367 rate_idx = 0; /* TODO: HT/VHT rates */
4369 rate_idx = status->rate_idx;
4370 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
4374 case NL80211_IFTYPE_OCB:
4377 if (!ieee80211_is_data_present(hdr->frame_control))
4379 if (!is_broadcast_ether_addr(bssid))
4382 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
4386 if (status->encoding != RX_ENC_LEGACY)
4387 rate_idx = 0; /* TODO: HT rates */
4389 rate_idx = status->rate_idx;
4390 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
4394 case NL80211_IFTYPE_MESH_POINT:
4395 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
4399 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4400 case NL80211_IFTYPE_AP_VLAN:
4401 case NL80211_IFTYPE_AP:
4403 return ieee80211_is_our_addr(sdata, hdr->addr1,
4406 if (!is_broadcast_ether_addr(bssid) &&
4407 !ieee80211_is_our_addr(sdata, bssid, NULL)) {
4409 * Accept public action frames even when the
4410 * BSSID doesn't match, this is used for P2P
4411 * and location updates. Note that mac80211
4412 * itself never looks at these frames.
4415 !ieee80211_is_our_addr(sdata, hdr->addr1,
4418 if (ieee80211_is_public_action(hdr, skb->len))
4420 return ieee80211_is_beacon(hdr->frame_control);
4423 if (!ieee80211_has_tods(hdr->frame_control)) {
4424 /* ignore data frames to TDLS-peers */
4425 if (ieee80211_is_data(hdr->frame_control))
4427 /* ignore action frames to TDLS-peers */
4428 if (ieee80211_is_action(hdr->frame_control) &&
4429 !is_broadcast_ether_addr(bssid) &&
4430 !ether_addr_equal(bssid, hdr->addr1))
4435 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4436 * the BSSID - we've checked that already but may have accepted
4437 * the wildcard (ff:ff:ff:ff:ff:ff).
4440 * The BSSID of the Data frame is determined as follows:
4441 * a) If the STA is contained within an AP or is associated
4442 * with an AP, the BSSID is the address currently in use
4443 * by the STA contained in the AP.
4445 * So we should not accept data frames with an address that's
4448 * Accepting it also opens a security problem because stations
4449 * could encrypt it with the GTK and inject traffic that way.
4451 if (ieee80211_is_data(hdr->frame_control) && multicast)
4455 case NL80211_IFTYPE_P2P_DEVICE:
4456 return ieee80211_is_public_action(hdr, skb->len) ||
4457 ieee80211_is_probe_req(hdr->frame_control) ||
4458 ieee80211_is_probe_resp(hdr->frame_control) ||
4459 ieee80211_is_beacon(hdr->frame_control);
4460 case NL80211_IFTYPE_NAN:
4461 /* Currently no frames on NAN interface are allowed */
4471 void ieee80211_check_fast_rx(struct sta_info *sta)
4473 struct ieee80211_sub_if_data *sdata = sta->sdata;
4474 struct ieee80211_local *local = sdata->local;
4475 struct ieee80211_key *key;
4476 struct ieee80211_fast_rx fastrx = {
4478 .vif_type = sdata->vif.type,
4479 .control_port_protocol = sdata->control_port_protocol,
4480 }, *old, *new = NULL;
4482 bool set_offload = false;
4483 bool assign = false;
4486 /* use sparse to check that we don't return without updating */
4487 __acquire(check_fast_rx);
4489 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4490 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4491 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4492 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4494 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4496 /* fast-rx doesn't do reordering */
4497 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4498 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4501 switch (sdata->vif.type) {
4502 case NL80211_IFTYPE_STATION:
4503 if (sta->sta.tdls) {
4504 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4505 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4506 fastrx.expected_ds_bits = 0;
4508 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4509 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4510 fastrx.expected_ds_bits =
4511 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4514 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4515 fastrx.expected_ds_bits |=
4516 cpu_to_le16(IEEE80211_FCTL_TODS);
4517 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4518 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4521 if (!sdata->u.mgd.powersave)
4524 /* software powersave is a huge mess, avoid all of it */
4525 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4527 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4528 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4531 case NL80211_IFTYPE_AP_VLAN:
4532 case NL80211_IFTYPE_AP:
4533 /* parallel-rx requires this, at least with calls to
4534 * ieee80211_sta_ps_transition()
4536 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4538 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4539 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4540 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4542 fastrx.internal_forward =
4543 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4544 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4545 !sdata->u.vlan.sta);
4547 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4548 sdata->u.vlan.sta) {
4549 fastrx.expected_ds_bits |=
4550 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4551 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4552 fastrx.internal_forward = 0;
4556 case NL80211_IFTYPE_MESH_POINT:
4557 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_FROMDS |
4558 IEEE80211_FCTL_TODS);
4559 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4560 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4566 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4570 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4572 key = rcu_dereference(sdata->default_unicast_key);
4574 switch (key->conf.cipher) {
4575 case WLAN_CIPHER_SUITE_TKIP:
4576 /* we don't want to deal with MMIC in fast-rx */
4578 case WLAN_CIPHER_SUITE_CCMP:
4579 case WLAN_CIPHER_SUITE_CCMP_256:
4580 case WLAN_CIPHER_SUITE_GCMP:
4581 case WLAN_CIPHER_SUITE_GCMP_256:
4584 /* We also don't want to deal with
4585 * WEP or cipher scheme.
4591 fastrx.icv_len = key->conf.icv_len;
4598 __release(check_fast_rx);
4601 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4603 offload_flags = get_bss_sdata(sdata)->vif.offload_flags;
4604 offload = offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED;
4606 if (assign && offload)
4607 set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4609 set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4612 drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
4614 spin_lock_bh(&sta->lock);
4615 old = rcu_dereference_protected(sta->fast_rx, true);
4616 rcu_assign_pointer(sta->fast_rx, new);
4617 spin_unlock_bh(&sta->lock);
4620 kfree_rcu(old, rcu_head);
4623 void ieee80211_clear_fast_rx(struct sta_info *sta)
4625 struct ieee80211_fast_rx *old;
4627 spin_lock_bh(&sta->lock);
4628 old = rcu_dereference_protected(sta->fast_rx, true);
4629 RCU_INIT_POINTER(sta->fast_rx, NULL);
4630 spin_unlock_bh(&sta->lock);
4633 kfree_rcu(old, rcu_head);
4636 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4638 struct ieee80211_local *local = sdata->local;
4639 struct sta_info *sta;
4641 lockdep_assert_held(&local->sta_mtx);
4643 list_for_each_entry(sta, &local->sta_list, list) {
4644 if (sdata != sta->sdata &&
4645 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4647 ieee80211_check_fast_rx(sta);
4651 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4653 struct ieee80211_local *local = sdata->local;
4655 mutex_lock(&local->sta_mtx);
4656 __ieee80211_check_fast_rx_iface(sdata);
4657 mutex_unlock(&local->sta_mtx);
4660 static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
4661 struct ieee80211_fast_rx *fast_rx,
4664 struct ieee80211_sta_rx_stats *stats;
4665 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4666 struct sta_info *sta = rx->sta;
4667 struct link_sta_info *link_sta;
4668 struct sk_buff *skb = rx->skb;
4669 void *sa = skb->data + ETH_ALEN;
4670 void *da = skb->data;
4672 if (rx->link_id >= 0) {
4673 link_sta = rcu_dereference(sta->link[rx->link_id]);
4674 if (WARN_ON_ONCE(!link_sta)) {
4675 dev_kfree_skb(rx->skb);
4679 link_sta = &sta->deflink;
4682 stats = &link_sta->rx_stats;
4683 if (fast_rx->uses_rss)
4684 stats = this_cpu_ptr(link_sta->pcpu_rx_stats);
4686 /* statistics part of ieee80211_rx_h_sta_process() */
4687 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4688 stats->last_signal = status->signal;
4689 if (!fast_rx->uses_rss)
4690 ewma_signal_add(&link_sta->rx_stats_avg.signal,
4694 if (status->chains) {
4697 stats->chains = status->chains;
4698 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4699 int signal = status->chain_signal[i];
4701 if (!(status->chains & BIT(i)))
4704 stats->chain_signal_last[i] = signal;
4705 if (!fast_rx->uses_rss)
4706 ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
4710 /* end of statistics */
4712 stats->last_rx = jiffies;
4713 stats->last_rate = sta_stats_encode_rate(status);
4718 skb->dev = fast_rx->dev;
4720 dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
4722 /* The seqno index has the same property as needed
4723 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4724 * for non-QoS-data frames. Here we know it's a data
4725 * frame, so count MSDUs.
4727 u64_stats_update_begin(&stats->syncp);
4728 stats->msdu[rx->seqno_idx]++;
4729 stats->bytes += orig_len;
4730 u64_stats_update_end(&stats->syncp);
4732 if (fast_rx->internal_forward) {
4733 struct sk_buff *xmit_skb = NULL;
4734 if (is_multicast_ether_addr(da)) {
4735 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4736 } else if (!ether_addr_equal(da, sa) &&
4737 sta_info_get(rx->sdata, da)) {
4744 * Send to wireless media and increase priority by 256
4745 * to keep the received priority instead of
4746 * reclassifying the frame (see cfg80211_classify8021d).
4748 xmit_skb->priority += 256;
4749 xmit_skb->protocol = htons(ETH_P_802_3);
4750 skb_reset_network_header(xmit_skb);
4751 skb_reset_mac_header(xmit_skb);
4752 dev_queue_xmit(xmit_skb);
4759 /* deliver to local stack */
4760 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4761 ieee80211_deliver_skb_to_local_stack(skb, rx);
4764 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4765 struct ieee80211_fast_rx *fast_rx)
4767 struct sk_buff *skb = rx->skb;
4768 struct ieee80211_hdr *hdr = (void *)skb->data;
4769 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4770 static ieee80211_rx_result res;
4771 int orig_len = skb->len;
4772 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4773 int snap_offs = hdrlen;
4775 u8 snap[sizeof(rfc1042_header)];
4777 } *payload __aligned(2);
4781 } addrs __aligned(2);
4782 struct ieee80211_sta_rx_stats *stats;
4784 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4785 * to a common data structure; drivers can implement that per queue
4786 * but we don't have that information in mac80211
4788 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4791 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4793 /* If using encryption, we also need to have:
4794 * - PN_VALIDATED: similar, but the implementation is tricky
4795 * - DECRYPTED: necessary for PN_VALIDATED
4798 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4801 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4804 if (unlikely(ieee80211_is_frag(hdr)))
4807 /* Since our interface address cannot be multicast, this
4808 * implicitly also rejects multicast frames without the
4811 * We shouldn't get any *data* frames not addressed to us
4812 * (AP mode will accept multicast *management* frames), but
4813 * punting here will make it go through the full checks in
4814 * ieee80211_accept_frame().
4816 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4819 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4820 IEEE80211_FCTL_TODS)) !=
4821 fast_rx->expected_ds_bits)
4824 /* assign the key to drop unencrypted frames (later)
4825 * and strip the IV/MIC if necessary
4827 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4828 /* GCMP header length is the same */
4829 snap_offs += IEEE80211_CCMP_HDR_LEN;
4832 if (!ieee80211_vif_is_mesh(&rx->sdata->vif) &&
4833 !(status->rx_flags & IEEE80211_RX_AMSDU)) {
4834 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4837 payload = (void *)(skb->data + snap_offs);
4839 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4842 /* Don't handle these here since they require special code.
4843 * Accept AARP and IPX even though they should come with a
4844 * bridge-tunnel header - but if we get them this way then
4845 * there's little point in discarding them.
4847 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4848 payload->proto == fast_rx->control_port_protocol))
4852 /* after this point, don't punt to the slowpath! */
4854 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4855 pskb_trim(skb, skb->len - fast_rx->icv_len))
4858 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4861 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4862 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4869 /* do the header conversion - first grab the addresses */
4870 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4871 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4872 if (ieee80211_vif_is_mesh(&rx->sdata->vif)) {
4873 skb_pull(skb, snap_offs - 2);
4874 put_unaligned_be16(skb->len - 2, skb->data);
4876 skb_postpull_rcsum(skb, skb->data + snap_offs,
4877 sizeof(rfc1042_header) + 2);
4879 /* remove the SNAP but leave the ethertype */
4880 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4882 /* push the addresses in front */
4883 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4885 res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
4895 ieee80211_rx_8023(rx, fast_rx, orig_len);
4901 if (fast_rx->uses_rss)
4902 stats = this_cpu_ptr(rx->link_sta->pcpu_rx_stats);
4904 stats = &rx->link_sta->rx_stats;
4911 * This function returns whether or not the SKB
4912 * was destined for RX processing or not, which,
4913 * if consume is true, is equivalent to whether
4914 * or not the skb was consumed.
4916 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4917 struct sk_buff *skb, bool consume)
4919 struct ieee80211_local *local = rx->local;
4920 struct ieee80211_sub_if_data *sdata = rx->sdata;
4921 struct ieee80211_hdr *hdr = (void *)skb->data;
4922 struct link_sta_info *link_sta = rx->link_sta;
4923 struct ieee80211_link_data *link = rx->link;
4927 /* See if we can do fast-rx; if we have to copy we already lost,
4928 * so punt in that case. We should never have to deliver a data
4929 * frame to multiple interfaces anyway.
4931 * We skip the ieee80211_accept_frame() call and do the necessary
4932 * checking inside ieee80211_invoke_fast_rx().
4934 if (consume && rx->sta) {
4935 struct ieee80211_fast_rx *fast_rx;
4937 fast_rx = rcu_dereference(rx->sta->fast_rx);
4938 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4942 if (!ieee80211_accept_frame(rx))
4946 struct skb_shared_hwtstamps *shwt;
4948 rx->skb = skb_copy(skb, GFP_ATOMIC);
4950 if (net_ratelimit())
4951 wiphy_debug(local->hw.wiphy,
4952 "failed to copy skb for %s\n",
4957 /* skb_copy() does not copy the hw timestamps, so copy it
4960 shwt = skb_hwtstamps(rx->skb);
4961 shwt->hwtstamp = skb_hwtstamps(skb)->hwtstamp;
4963 /* Update the hdr pointer to the new skb for translation below */
4964 hdr = (struct ieee80211_hdr *)rx->skb->data;
4967 if (unlikely(rx->sta && rx->sta->sta.mlo) &&
4968 is_unicast_ether_addr(hdr->addr1)) {
4969 /* translate to MLD addresses */
4970 if (ether_addr_equal(link->conf->addr, hdr->addr1))
4971 ether_addr_copy(hdr->addr1, rx->sdata->vif.addr);
4972 if (ether_addr_equal(link_sta->addr, hdr->addr2))
4973 ether_addr_copy(hdr->addr2, rx->sta->addr);
4974 /* translate A3 only if it's the BSSID */
4975 if (!ieee80211_has_tods(hdr->frame_control) &&
4976 !ieee80211_has_fromds(hdr->frame_control)) {
4977 if (ether_addr_equal(link_sta->addr, hdr->addr3))
4978 ether_addr_copy(hdr->addr3, rx->sta->addr);
4979 else if (ether_addr_equal(link->conf->addr, hdr->addr3))
4980 ether_addr_copy(hdr->addr3, rx->sdata->vif.addr);
4982 /* not needed for A4 since it can only carry the SA */
4985 ieee80211_invoke_rx_handlers(rx);
4989 static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
4990 struct ieee80211_sta *pubsta,
4991 struct sk_buff *skb,
4992 struct list_head *list)
4994 struct ieee80211_local *local = hw_to_local(hw);
4995 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4996 struct ieee80211_fast_rx *fast_rx;
4997 struct ieee80211_rx_data rx;
4998 struct sta_info *sta;
5001 memset(&rx, 0, sizeof(rx));
5007 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
5009 /* drop frame if too short for header */
5010 if (skb->len < sizeof(struct ethhdr))
5016 if (status->link_valid)
5017 link_id = status->link_id;
5020 * TODO: Should the frame be dropped if the right link_id is not
5021 * available? Or may be it is fine in the current form to proceed with
5022 * the frame processing because with frame being in 802.3 format,
5023 * link_id is used only for stats purpose and updating the stats on
5024 * the deflink is fine?
5026 sta = container_of(pubsta, struct sta_info, sta);
5027 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
5030 fast_rx = rcu_dereference(rx.sta->fast_rx);
5034 ieee80211_rx_8023(&rx, fast_rx, skb->len);
5041 static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx,
5042 struct sk_buff *skb, bool consume)
5044 struct link_sta_info *link_sta;
5045 struct ieee80211_hdr *hdr = (void *)skb->data;
5046 struct sta_info *sta;
5050 * Look up link station first, in case there's a
5051 * chance that they might have a link address that
5052 * is identical to the MLD address, that way we'll
5053 * have the link information if needed.
5055 link_sta = link_sta_info_get_bss(rx->sdata, hdr->addr2);
5057 sta = link_sta->sta;
5058 link_id = link_sta->link_id;
5060 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5062 sta = sta_info_get_bss(rx->sdata, hdr->addr2);
5063 if (status->link_valid)
5064 link_id = status->link_id;
5067 if (!ieee80211_rx_data_set_sta(rx, sta, link_id))
5070 return ieee80211_prepare_and_rx_handle(rx, skb, consume);
5074 * This is the actual Rx frames handler. as it belongs to Rx path it must
5075 * be called with rcu_read_lock protection.
5077 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
5078 struct ieee80211_sta *pubsta,
5079 struct sk_buff *skb,
5080 struct list_head *list)
5082 struct ieee80211_local *local = hw_to_local(hw);
5083 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5084 struct ieee80211_sub_if_data *sdata;
5085 struct ieee80211_hdr *hdr;
5087 struct ieee80211_rx_data rx;
5088 struct ieee80211_sub_if_data *prev;
5089 struct rhlist_head *tmp;
5092 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
5093 memset(&rx, 0, sizeof(rx));
5099 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
5100 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
5102 if (ieee80211_is_mgmt(fc)) {
5103 /* drop frame if too short for header */
5104 if (skb->len < ieee80211_hdrlen(fc))
5107 err = skb_linearize(skb);
5109 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
5117 hdr = (struct ieee80211_hdr *)skb->data;
5118 ieee80211_parse_qos(&rx);
5119 ieee80211_verify_alignment(&rx);
5121 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
5122 ieee80211_is_beacon(hdr->frame_control) ||
5123 ieee80211_is_s1g_beacon(hdr->frame_control)))
5124 ieee80211_scan_rx(local, skb);
5126 if (ieee80211_is_data(fc)) {
5127 struct sta_info *sta, *prev_sta;
5130 if (status->link_valid)
5131 link_id = status->link_id;
5134 sta = container_of(pubsta, struct sta_info, sta);
5135 if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
5139 * In MLO connection, fetch the link_id using addr2
5140 * when the driver does not pass link_id in status.
5141 * When the address translation is already performed by
5142 * driver/hw, the valid link_id must be passed in
5146 if (!status->link_valid && pubsta->mlo) {
5147 struct ieee80211_hdr *hdr = (void *)skb->data;
5148 struct link_sta_info *link_sta;
5150 link_sta = link_sta_info_get_bss(rx.sdata,
5155 ieee80211_rx_data_set_link(&rx, link_sta->link_id);
5158 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
5165 for_each_sta_info(local, hdr->addr2, sta, tmp) {
5171 rx.sdata = prev_sta->sdata;
5172 if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
5175 if (!status->link_valid && prev_sta->sta.mlo)
5178 ieee80211_prepare_and_rx_handle(&rx, skb, false);
5184 rx.sdata = prev_sta->sdata;
5185 if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
5188 if (!status->link_valid && prev_sta->sta.mlo)
5191 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
5199 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
5200 if (!ieee80211_sdata_running(sdata))
5203 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
5204 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
5208 * frame is destined for this interface, but if it's
5209 * not also for the previous one we handle that after
5210 * the loop to avoid copying the SKB once too much
5219 ieee80211_rx_for_interface(&rx, skb, false);
5227 if (ieee80211_rx_for_interface(&rx, skb, true))
5236 * This is the receive path handler. It is called by a low level driver when an
5237 * 802.11 MPDU is received from the hardware.
5239 void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5240 struct sk_buff *skb, struct list_head *list)
5242 struct ieee80211_local *local = hw_to_local(hw);
5243 struct ieee80211_rate *rate = NULL;
5244 struct ieee80211_supported_band *sband;
5245 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5246 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5248 WARN_ON_ONCE(softirq_count() == 0);
5250 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
5253 sband = local->hw.wiphy->bands[status->band];
5254 if (WARN_ON(!sband))
5258 * If we're suspending, it is possible although not too likely
5259 * that we'd be receiving frames after having already partially
5260 * quiesced the stack. We can't process such frames then since
5261 * that might, for example, cause stations to be added or other
5262 * driver callbacks be invoked.
5264 if (unlikely(local->quiescing || local->suspended))
5267 /* We might be during a HW reconfig, prevent Rx for the same reason */
5268 if (unlikely(local->in_reconfig))
5272 * The same happens when we're not even started,
5273 * but that's worth a warning.
5275 if (WARN_ON(!local->started))
5278 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
5280 * Validate the rate, unless a PLCP error means that
5281 * we probably can't have a valid rate here anyway.
5284 switch (status->encoding) {
5287 * rate_idx is MCS index, which can be [0-76]
5290 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
5292 * Anything else would be some sort of driver or
5293 * hardware error. The driver should catch hardware
5296 if (WARN(status->rate_idx > 76,
5297 "Rate marked as an HT rate but passed "
5298 "status->rate_idx is not "
5299 "an MCS index [0-76]: %d (0x%02x)\n",
5305 if (WARN_ONCE(status->rate_idx > 11 ||
5308 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
5309 status->rate_idx, status->nss))
5313 if (WARN_ONCE(status->rate_idx > 11 ||
5316 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
5317 status->rate_idx, status->nss))
5321 if (WARN_ONCE(status->rate_idx > 15 ||
5324 status->eht.gi > NL80211_RATE_INFO_EHT_GI_3_2,
5325 "Rate marked as an EHT rate but data is invalid: MCS:%d, NSS:%d, GI:%d\n",
5326 status->rate_idx, status->nss, status->eht.gi))
5333 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
5335 rate = &sband->bitrates[status->rate_idx];
5339 if (WARN_ON_ONCE(status->link_id >= IEEE80211_LINK_UNSPECIFIED))
5342 status->rx_flags = 0;
5344 kcov_remote_start_common(skb_get_kcov_handle(skb));
5347 * Frames with failed FCS/PLCP checksum are not returned,
5348 * all other frames are returned without radiotap header
5349 * if it was previously present.
5350 * Also, frames with less than 16 bytes are dropped.
5352 if (!(status->flag & RX_FLAG_8023))
5353 skb = ieee80211_rx_monitor(local, skb, rate);
5355 if ((status->flag & RX_FLAG_8023) ||
5356 ieee80211_is_data_present(hdr->frame_control))
5357 ieee80211_tpt_led_trig_rx(local, skb->len);
5359 if (status->flag & RX_FLAG_8023)
5360 __ieee80211_rx_handle_8023(hw, pubsta, skb, list);
5362 __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
5370 EXPORT_SYMBOL(ieee80211_rx_list);
5372 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
5373 struct sk_buff *skb, struct napi_struct *napi)
5375 struct sk_buff *tmp;
5380 * key references and virtual interfaces are protected using RCU
5381 * and this requires that we are in a read-side RCU section during
5382 * receive processing
5385 ieee80211_rx_list(hw, pubsta, skb, &list);
5389 netif_receive_skb_list(&list);
5393 list_for_each_entry_safe(skb, tmp, &list, list) {
5394 skb_list_del_init(skb);
5395 napi_gro_receive(napi, skb);
5398 EXPORT_SYMBOL(ieee80211_rx_napi);
5400 /* This is a version of the rx handler that can be called from hard irq
5401 * context. Post the skb on the queue and schedule the tasklet */
5402 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
5404 struct ieee80211_local *local = hw_to_local(hw);
5406 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
5408 skb->pkt_type = IEEE80211_RX_MSG;
5409 skb_queue_tail(&local->skb_queue, skb);
5410 tasklet_schedule(&local->tasklet);
5412 EXPORT_SYMBOL(ieee80211_rx_irqsafe);