2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2021 Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/jiffies.h>
16 #include <linux/slab.h>
17 #include <linux/kernel.h>
18 #include <linux/skbuff.h>
19 #include <linux/netdevice.h>
20 #include <linux/etherdevice.h>
21 #include <linux/rcupdate.h>
22 #include <linux/export.h>
23 #include <linux/bitops.h>
24 #include <net/mac80211.h>
25 #include <net/ieee80211_radiotap.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
38 static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
40 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
42 u64_stats_update_begin(&tstats->syncp);
44 tstats->rx_bytes += len;
45 u64_stats_update_end(&tstats->syncp);
48 static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
49 enum nl80211_iftype type)
51 __le16 fc = hdr->frame_control;
53 if (ieee80211_is_data(fc)) {
54 if (len < 24) /* drop incorrect hdr len (data) */
57 if (ieee80211_has_a4(fc))
59 if (ieee80211_has_tods(fc))
61 if (ieee80211_has_fromds(fc))
67 if (ieee80211_is_mgmt(fc)) {
68 if (len < 24) /* drop incorrect hdr len (mgmt) */
73 if (ieee80211_is_ctl(fc)) {
74 if (ieee80211_is_pspoll(fc))
77 if (ieee80211_is_back_req(fc)) {
79 case NL80211_IFTYPE_STATION:
81 case NL80211_IFTYPE_AP:
82 case NL80211_IFTYPE_AP_VLAN:
85 break; /* fall through to the return */
94 * monitor mode reception
96 * This function cleans up the SKB, i.e. it removes all the stuff
97 * only useful for monitoring.
99 static void remove_monitor_info(struct sk_buff *skb,
100 unsigned int present_fcs_len,
101 unsigned int rtap_space)
104 __pskb_trim(skb, skb->len - present_fcs_len);
105 __pskb_pull(skb, rtap_space);
108 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
109 unsigned int rtap_space)
111 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
112 struct ieee80211_hdr *hdr;
114 hdr = (void *)(skb->data + rtap_space);
116 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
117 RX_FLAG_FAILED_PLCP_CRC |
118 RX_FLAG_ONLY_MONITOR))
121 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
124 if (ieee80211_is_ctl(hdr->frame_control) &&
125 !ieee80211_is_pspoll(hdr->frame_control) &&
126 !ieee80211_is_back_req(hdr->frame_control))
133 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
134 struct ieee80211_rx_status *status,
139 /* always present fields */
140 len = sizeof(struct ieee80211_radiotap_header) + 8;
142 /* allocate extra bitmaps */
144 len += 4 * hweight8(status->chains);
145 /* vendor presence bitmap */
146 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)
149 if (ieee80211_have_rx_timestamp(status)) {
153 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
156 /* antenna field, if we don't have per-chain info */
160 /* padding for RX_FLAGS if necessary */
163 if (status->encoding == RX_ENC_HT) /* HT info */
166 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
171 if (status->encoding == RX_ENC_VHT) {
176 if (local->hw.radiotap_timestamp.units_pos >= 0) {
181 if (status->encoding == RX_ENC_HE &&
182 status->flag & RX_FLAG_RADIOTAP_HE) {
185 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
188 if (status->encoding == RX_ENC_HE &&
189 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
192 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
195 if (status->chains) {
196 /* antenna and antenna signal fields */
197 len += 2 * hweight8(status->chains);
200 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
201 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
203 /* alignment for fixed 6-byte vendor data header */
205 /* vendor data header */
207 if (WARN_ON(rtap->align == 0))
209 len = ALIGN(len, rtap->align);
210 len += rtap->len + rtap->pad;
216 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
221 struct ieee80211_hdr_3addr hdr;
224 } __packed __aligned(2) action;
229 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
231 if (skb->len < rtap_space + sizeof(action) +
232 VHT_MUMIMO_GROUPS_DATA_LEN)
235 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
238 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
240 if (!ieee80211_is_action(action.hdr.frame_control))
243 if (action.category != WLAN_CATEGORY_VHT)
246 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
249 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
252 skb = skb_copy(skb, GFP_ATOMIC);
256 skb_queue_tail(&sdata->skb_queue, skb);
257 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
261 * ieee80211_add_rx_radiotap_header - add radiotap header
263 * add a radiotap header containing all the fields which the hardware provided.
266 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
268 struct ieee80211_rate *rate,
269 int rtap_len, bool has_fcs)
271 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
272 struct ieee80211_radiotap_header *rthdr;
277 u16 channel_flags = 0;
279 unsigned long chains = status->chains;
280 struct ieee80211_vendor_radiotap rtap = {};
281 struct ieee80211_radiotap_he he = {};
282 struct ieee80211_radiotap_he_mu he_mu = {};
284 if (status->flag & RX_FLAG_RADIOTAP_HE) {
285 he = *(struct ieee80211_radiotap_he *)skb->data;
286 skb_pull(skb, sizeof(he));
287 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
290 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
291 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
292 skb_pull(skb, sizeof(he_mu));
295 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
296 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
297 /* rtap.len and rtap.pad are undone immediately */
298 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
302 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
305 rthdr = skb_push(skb, rtap_len);
306 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
307 it_present = &rthdr->it_present;
309 /* radiotap header, set always present flags */
310 rthdr->it_len = cpu_to_le16(rtap_len);
311 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
312 BIT(IEEE80211_RADIOTAP_CHANNEL) |
313 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
316 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
318 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
320 BIT(IEEE80211_RADIOTAP_EXT) |
321 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
322 put_unaligned_le32(it_present_val, it_present);
324 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
325 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
328 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
329 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
330 BIT(IEEE80211_RADIOTAP_EXT);
331 put_unaligned_le32(it_present_val, it_present);
333 it_present_val = rtap.present;
336 put_unaligned_le32(it_present_val, it_present);
338 pos = (void *)(it_present + 1);
340 /* the order of the following fields is important */
342 /* IEEE80211_RADIOTAP_TSFT */
343 if (ieee80211_have_rx_timestamp(status)) {
345 while ((pos - (u8 *)rthdr) & 7)
348 ieee80211_calculate_rx_timestamp(local, status,
351 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
355 /* IEEE80211_RADIOTAP_FLAGS */
356 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
357 *pos |= IEEE80211_RADIOTAP_F_FCS;
358 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
359 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
360 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
361 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
364 /* IEEE80211_RADIOTAP_RATE */
365 if (!rate || status->encoding != RX_ENC_LEGACY) {
367 * Without rate information don't add it. If we have,
368 * MCS information is a separate field in radiotap,
369 * added below. The byte here is needed as padding
370 * for the channel though, so initialise it to 0.
375 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
376 if (status->bw == RATE_INFO_BW_10)
378 else if (status->bw == RATE_INFO_BW_5)
380 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
384 /* IEEE80211_RADIOTAP_CHANNEL */
385 put_unaligned_le16(status->freq, pos);
387 if (status->bw == RATE_INFO_BW_10)
388 channel_flags |= IEEE80211_CHAN_HALF;
389 else if (status->bw == RATE_INFO_BW_5)
390 channel_flags |= IEEE80211_CHAN_QUARTER;
392 if (status->band == NL80211_BAND_5GHZ)
393 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
394 else if (status->encoding != RX_ENC_LEGACY)
395 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
396 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
397 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
399 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
401 channel_flags |= IEEE80211_CHAN_2GHZ;
402 put_unaligned_le16(channel_flags, pos);
405 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
406 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
407 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
408 *pos = status->signal;
410 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
414 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
416 if (!status->chains) {
417 /* IEEE80211_RADIOTAP_ANTENNA */
418 *pos = status->antenna;
422 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
424 /* IEEE80211_RADIOTAP_RX_FLAGS */
425 /* ensure 2 byte alignment for the 2 byte field as required */
426 if ((pos - (u8 *)rthdr) & 1)
428 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
429 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
430 put_unaligned_le16(rx_flags, pos);
433 if (status->encoding == RX_ENC_HT) {
436 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
437 *pos++ = local->hw.radiotap_mcs_details;
439 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
440 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
441 if (status->bw == RATE_INFO_BW_40)
442 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
443 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
444 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
445 if (status->enc_flags & RX_ENC_FLAG_LDPC)
446 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
447 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
448 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
450 *pos++ = status->rate_idx;
453 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
456 /* ensure 4 byte alignment */
457 while ((pos - (u8 *)rthdr) & 3)
460 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
461 put_unaligned_le32(status->ampdu_reference, pos);
463 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
464 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
465 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
466 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
467 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
468 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
469 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
470 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
471 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
472 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
473 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
474 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
475 put_unaligned_le16(flags, pos);
477 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
478 *pos++ = status->ampdu_delimiter_crc;
484 if (status->encoding == RX_ENC_VHT) {
485 u16 known = local->hw.radiotap_vht_details;
487 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
488 put_unaligned_le16(known, pos);
491 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
492 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
493 /* in VHT, STBC is binary */
494 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
495 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
496 if (status->enc_flags & RX_ENC_FLAG_BF)
497 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
500 switch (status->bw) {
501 case RATE_INFO_BW_80:
504 case RATE_INFO_BW_160:
507 case RATE_INFO_BW_40:
514 *pos = (status->rate_idx << 4) | status->nss;
517 if (status->enc_flags & RX_ENC_FLAG_LDPC)
518 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
526 if (local->hw.radiotap_timestamp.units_pos >= 0) {
528 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
531 cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP);
533 /* ensure 8 byte alignment */
534 while ((pos - (u8 *)rthdr) & 7)
537 put_unaligned_le64(status->device_timestamp, pos);
540 if (local->hw.radiotap_timestamp.accuracy >= 0) {
541 accuracy = local->hw.radiotap_timestamp.accuracy;
542 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
544 put_unaligned_le16(accuracy, pos);
547 *pos++ = local->hw.radiotap_timestamp.units_pos;
551 if (status->encoding == RX_ENC_HE &&
552 status->flag & RX_FLAG_RADIOTAP_HE) {
553 #define HE_PREP(f, val) cpu_to_le16(FIELD_PREP(IEEE80211_RADIOTAP_HE_##f, val))
555 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
556 he.data6 |= HE_PREP(DATA6_NSTS,
557 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
559 he.data3 |= HE_PREP(DATA3_STBC, 1);
561 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
564 #define CHECK_GI(s) \
565 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
566 (int)NL80211_RATE_INFO_HE_GI_##s)
572 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
573 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
574 he.data3 |= HE_PREP(DATA3_CODING,
575 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
577 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
579 switch (status->bw) {
580 case RATE_INFO_BW_20:
581 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
582 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
584 case RATE_INFO_BW_40:
585 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
586 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
588 case RATE_INFO_BW_80:
589 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
590 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
592 case RATE_INFO_BW_160:
593 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
594 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
596 case RATE_INFO_BW_HE_RU:
597 #define CHECK_RU_ALLOC(s) \
598 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
599 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
607 CHECK_RU_ALLOC(2x996);
609 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
613 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
616 /* ensure 2 byte alignment */
617 while ((pos - (u8 *)rthdr) & 1)
619 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE);
620 memcpy(pos, &he, sizeof(he));
624 if (status->encoding == RX_ENC_HE &&
625 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
626 /* ensure 2 byte alignment */
627 while ((pos - (u8 *)rthdr) & 1)
629 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU);
630 memcpy(pos, &he_mu, sizeof(he_mu));
631 pos += sizeof(he_mu);
634 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
635 *pos++ = status->chain_signal[chain];
639 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
640 /* ensure 2 byte alignment for the vendor field as required */
641 if ((pos - (u8 *)rthdr) & 1)
643 *pos++ = rtap.oui[0];
644 *pos++ = rtap.oui[1];
645 *pos++ = rtap.oui[2];
647 put_unaligned_le16(rtap.len, pos);
649 /* align the actual payload as requested */
650 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
652 /* data (and possible padding) already follows */
656 static struct sk_buff *
657 ieee80211_make_monitor_skb(struct ieee80211_local *local,
658 struct sk_buff **origskb,
659 struct ieee80211_rate *rate,
660 int rtap_space, bool use_origskb)
662 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
663 int rt_hdrlen, needed_headroom;
666 /* room for the radiotap header based on driver features */
667 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
668 needed_headroom = rt_hdrlen - rtap_space;
671 /* only need to expand headroom if necessary */
676 * This shouldn't trigger often because most devices have an
677 * RX header they pull before we get here, and that should
678 * be big enough for our radiotap information. We should
679 * probably export the length to drivers so that we can have
680 * them allocate enough headroom to start with.
682 if (skb_headroom(skb) < needed_headroom &&
683 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
689 * Need to make a copy and possibly remove radiotap header
690 * and FCS from the original.
692 skb = skb_copy_expand(*origskb, needed_headroom, 0, GFP_ATOMIC);
698 /* prepend radiotap information */
699 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
701 skb_reset_mac_header(skb);
702 skb->ip_summed = CHECKSUM_UNNECESSARY;
703 skb->pkt_type = PACKET_OTHERHOST;
704 skb->protocol = htons(ETH_P_802_2);
710 * This function copies a received frame to all monitor interfaces and
711 * returns a cleaned-up SKB that no longer includes the FCS nor the
712 * radiotap header the driver might have added.
714 static struct sk_buff *
715 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
716 struct ieee80211_rate *rate)
718 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
719 struct ieee80211_sub_if_data *sdata;
720 struct sk_buff *monskb = NULL;
721 int present_fcs_len = 0;
722 unsigned int rtap_space = 0;
723 struct ieee80211_sub_if_data *monitor_sdata =
724 rcu_dereference(local->monitor_sdata);
725 bool only_monitor = false;
727 if (status->flag & RX_FLAG_RADIOTAP_HE)
728 rtap_space += sizeof(struct ieee80211_radiotap_he);
730 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
731 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
733 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
734 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
736 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
740 * First, we may need to make a copy of the skb because
741 * (1) we need to modify it for radiotap (if not present), and
742 * (2) the other RX handlers will modify the skb we got.
744 * We don't need to, of course, if we aren't going to return
745 * the SKB because it has a bad FCS/PLCP checksum.
748 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
749 if (unlikely(origskb->len <= FCS_LEN)) {
752 dev_kfree_skb(origskb);
755 present_fcs_len = FCS_LEN;
758 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
759 if (!pskb_may_pull(origskb, 2 + rtap_space)) {
760 dev_kfree_skb(origskb);
764 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
766 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
768 dev_kfree_skb(origskb);
772 remove_monitor_info(origskb, present_fcs_len, rtap_space);
776 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
778 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
779 bool last_monitor = list_is_last(&sdata->u.mntr.list,
783 monskb = ieee80211_make_monitor_skb(local, &origskb,
795 skb = skb_clone(monskb, GFP_ATOMIC);
799 skb->dev = sdata->dev;
800 ieee80211_rx_stats(skb->dev, skb->len);
801 netif_receive_skb(skb);
809 /* this happens if last_monitor was erroneously false */
810 dev_kfree_skb(monskb);
816 remove_monitor_info(origskb, present_fcs_len, rtap_space);
820 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
822 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
823 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
824 int tid, seqno_idx, security_idx;
826 /* does the frame have a qos control field? */
827 if (ieee80211_is_data_qos(hdr->frame_control)) {
828 u8 *qc = ieee80211_get_qos_ctl(hdr);
829 /* frame has qos control */
830 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
831 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
832 status->rx_flags |= IEEE80211_RX_AMSDU;
838 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
840 * Sequence numbers for management frames, QoS data
841 * frames with a broadcast/multicast address in the
842 * Address 1 field, and all non-QoS data frames sent
843 * by QoS STAs are assigned using an additional single
844 * modulo-4096 counter, [...]
846 * We also use that counter for non-QoS STAs.
848 seqno_idx = IEEE80211_NUM_TIDS;
850 if (ieee80211_is_mgmt(hdr->frame_control))
851 security_idx = IEEE80211_NUM_TIDS;
855 rx->seqno_idx = seqno_idx;
856 rx->security_idx = security_idx;
857 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
858 * For now, set skb->priority to 0 for other cases. */
859 rx->skb->priority = (tid > 7) ? 0 : tid;
863 * DOC: Packet alignment
865 * Drivers always need to pass packets that are aligned to two-byte boundaries
868 * Additionally, should, if possible, align the payload data in a way that
869 * guarantees that the contained IP header is aligned to a four-byte
870 * boundary. In the case of regular frames, this simply means aligning the
871 * payload to a four-byte boundary (because either the IP header is directly
872 * contained, or IV/RFC1042 headers that have a length divisible by four are
873 * in front of it). If the payload data is not properly aligned and the
874 * architecture doesn't support efficient unaligned operations, mac80211
875 * will align the data.
877 * With A-MSDU frames, however, the payload data address must yield two modulo
878 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
879 * push the IP header further back to a multiple of four again. Thankfully, the
880 * specs were sane enough this time around to require padding each A-MSDU
881 * subframe to a length that is a multiple of four.
883 * Padding like Atheros hardware adds which is between the 802.11 header and
884 * the payload is not supported, the driver is required to move the 802.11
885 * header to be directly in front of the payload in that case.
887 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
889 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
890 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
897 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
899 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
901 if (is_multicast_ether_addr(hdr->addr1))
904 return ieee80211_is_robust_mgmt_frame(skb);
908 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
910 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
912 if (!is_multicast_ether_addr(hdr->addr1))
915 return ieee80211_is_robust_mgmt_frame(skb);
919 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
920 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
922 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
923 struct ieee80211_mmie *mmie;
924 struct ieee80211_mmie_16 *mmie16;
926 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
929 if (!ieee80211_is_robust_mgmt_frame(skb))
930 return -1; /* not a robust management frame */
932 mmie = (struct ieee80211_mmie *)
933 (skb->data + skb->len - sizeof(*mmie));
934 if (mmie->element_id == WLAN_EID_MMIE &&
935 mmie->length == sizeof(*mmie) - 2)
936 return le16_to_cpu(mmie->key_id);
938 mmie16 = (struct ieee80211_mmie_16 *)
939 (skb->data + skb->len - sizeof(*mmie16));
940 if (skb->len >= 24 + sizeof(*mmie16) &&
941 mmie16->element_id == WLAN_EID_MMIE &&
942 mmie16->length == sizeof(*mmie16) - 2)
943 return le16_to_cpu(mmie16->key_id);
948 static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
951 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
956 fc = hdr->frame_control;
957 hdrlen = ieee80211_hdrlen(fc);
959 if (skb->len < hdrlen + cs->hdr_len)
962 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
963 keyid &= cs->key_idx_mask;
964 keyid >>= cs->key_idx_shift;
969 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
971 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
972 char *dev_addr = rx->sdata->vif.addr;
974 if (ieee80211_is_data(hdr->frame_control)) {
975 if (is_multicast_ether_addr(hdr->addr1)) {
976 if (ieee80211_has_tods(hdr->frame_control) ||
977 !ieee80211_has_fromds(hdr->frame_control))
978 return RX_DROP_MONITOR;
979 if (ether_addr_equal(hdr->addr3, dev_addr))
980 return RX_DROP_MONITOR;
982 if (!ieee80211_has_a4(hdr->frame_control))
983 return RX_DROP_MONITOR;
984 if (ether_addr_equal(hdr->addr4, dev_addr))
985 return RX_DROP_MONITOR;
989 /* If there is not an established peer link and this is not a peer link
990 * establisment frame, beacon or probe, drop the frame.
993 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
994 struct ieee80211_mgmt *mgmt;
996 if (!ieee80211_is_mgmt(hdr->frame_control))
997 return RX_DROP_MONITOR;
999 if (ieee80211_is_action(hdr->frame_control)) {
1002 /* make sure category field is present */
1003 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1004 return RX_DROP_MONITOR;
1006 mgmt = (struct ieee80211_mgmt *)hdr;
1007 category = mgmt->u.action.category;
1008 if (category != WLAN_CATEGORY_MESH_ACTION &&
1009 category != WLAN_CATEGORY_SELF_PROTECTED)
1010 return RX_DROP_MONITOR;
1014 if (ieee80211_is_probe_req(hdr->frame_control) ||
1015 ieee80211_is_probe_resp(hdr->frame_control) ||
1016 ieee80211_is_beacon(hdr->frame_control) ||
1017 ieee80211_is_auth(hdr->frame_control))
1020 return RX_DROP_MONITOR;
1026 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1029 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1030 struct sk_buff *tail = skb_peek_tail(frames);
1031 struct ieee80211_rx_status *status;
1033 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1039 status = IEEE80211_SKB_RXCB(tail);
1040 if (status->flag & RX_FLAG_AMSDU_MORE)
1046 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1047 struct tid_ampdu_rx *tid_agg_rx,
1049 struct sk_buff_head *frames)
1051 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1052 struct sk_buff *skb;
1053 struct ieee80211_rx_status *status;
1055 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1057 if (skb_queue_empty(skb_list))
1060 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1061 __skb_queue_purge(skb_list);
1065 /* release frames from the reorder ring buffer */
1066 tid_agg_rx->stored_mpdu_num--;
1067 while ((skb = __skb_dequeue(skb_list))) {
1068 status = IEEE80211_SKB_RXCB(skb);
1069 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1070 __skb_queue_tail(frames, skb);
1074 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1075 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1078 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1079 struct tid_ampdu_rx *tid_agg_rx,
1081 struct sk_buff_head *frames)
1085 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1087 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1088 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1089 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1095 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1096 * the skb was added to the buffer longer than this time ago, the earlier
1097 * frames that have not yet been received are assumed to be lost and the skb
1098 * can be released for processing. This may also release other skb's from the
1099 * reorder buffer if there are no additional gaps between the frames.
1101 * Callers must hold tid_agg_rx->reorder_lock.
1103 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1105 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1106 struct tid_ampdu_rx *tid_agg_rx,
1107 struct sk_buff_head *frames)
1111 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1113 /* release the buffer until next missing frame */
1114 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1115 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1116 tid_agg_rx->stored_mpdu_num) {
1118 * No buffers ready to be released, but check whether any
1119 * frames in the reorder buffer have timed out.
1122 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1123 j = (j + 1) % tid_agg_rx->buf_size) {
1124 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1129 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1130 HT_RX_REORDER_BUF_TIMEOUT))
1131 goto set_release_timer;
1133 /* don't leave incomplete A-MSDUs around */
1134 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1135 i = (i + 1) % tid_agg_rx->buf_size)
1136 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1138 ht_dbg_ratelimited(sdata,
1139 "release an RX reorder frame due to timeout on earlier frames\n");
1140 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1144 * Increment the head seq# also for the skipped slots.
1146 tid_agg_rx->head_seq_num =
1147 (tid_agg_rx->head_seq_num +
1148 skipped) & IEEE80211_SN_MASK;
1151 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1152 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1154 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1157 if (tid_agg_rx->stored_mpdu_num) {
1158 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1160 for (; j != (index - 1) % tid_agg_rx->buf_size;
1161 j = (j + 1) % tid_agg_rx->buf_size) {
1162 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1168 if (!tid_agg_rx->removed)
1169 mod_timer(&tid_agg_rx->reorder_timer,
1170 tid_agg_rx->reorder_time[j] + 1 +
1171 HT_RX_REORDER_BUF_TIMEOUT);
1173 del_timer(&tid_agg_rx->reorder_timer);
1178 * As this function belongs to the RX path it must be under
1179 * rcu_read_lock protection. It returns false if the frame
1180 * can be processed immediately, true if it was consumed.
1182 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1183 struct tid_ampdu_rx *tid_agg_rx,
1184 struct sk_buff *skb,
1185 struct sk_buff_head *frames)
1187 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1188 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1189 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1190 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1191 u16 head_seq_num, buf_size;
1195 spin_lock(&tid_agg_rx->reorder_lock);
1198 * Offloaded BA sessions have no known starting sequence number so pick
1199 * one from first Rxed frame for this tid after BA was started.
1201 if (unlikely(tid_agg_rx->auto_seq)) {
1202 tid_agg_rx->auto_seq = false;
1203 tid_agg_rx->ssn = mpdu_seq_num;
1204 tid_agg_rx->head_seq_num = mpdu_seq_num;
1207 buf_size = tid_agg_rx->buf_size;
1208 head_seq_num = tid_agg_rx->head_seq_num;
1211 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1214 if (unlikely(!tid_agg_rx->started)) {
1215 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1219 tid_agg_rx->started = true;
1222 /* frame with out of date sequence number */
1223 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1229 * If frame the sequence number exceeds our buffering window
1230 * size release some previous frames to make room for this one.
1232 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1233 head_seq_num = ieee80211_sn_inc(
1234 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1235 /* release stored frames up to new head to stack */
1236 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1237 head_seq_num, frames);
1240 /* Now the new frame is always in the range of the reordering buffer */
1242 index = mpdu_seq_num % tid_agg_rx->buf_size;
1244 /* check if we already stored this frame */
1245 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1251 * If the current MPDU is in the right order and nothing else
1252 * is stored we can process it directly, no need to buffer it.
1253 * If it is first but there's something stored, we may be able
1254 * to release frames after this one.
1256 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1257 tid_agg_rx->stored_mpdu_num == 0) {
1258 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1259 tid_agg_rx->head_seq_num =
1260 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1265 /* put the frame in the reordering buffer */
1266 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1267 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1268 tid_agg_rx->reorder_time[index] = jiffies;
1269 tid_agg_rx->stored_mpdu_num++;
1270 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1274 spin_unlock(&tid_agg_rx->reorder_lock);
1279 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1280 * true if the MPDU was buffered, false if it should be processed.
1282 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1283 struct sk_buff_head *frames)
1285 struct sk_buff *skb = rx->skb;
1286 struct ieee80211_local *local = rx->local;
1287 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1288 struct sta_info *sta = rx->sta;
1289 struct tid_ampdu_rx *tid_agg_rx;
1293 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1294 is_multicast_ether_addr(hdr->addr1))
1298 * filter the QoS data rx stream according to
1299 * STA/TID and check if this STA/TID is on aggregation
1305 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1306 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1307 tid = ieee80211_get_tid(hdr);
1309 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1311 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1312 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1313 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1314 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1315 WLAN_BACK_RECIPIENT,
1316 WLAN_REASON_QSTA_REQUIRE_SETUP);
1320 /* qos null data frames are excluded */
1321 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1324 /* not part of a BA session */
1325 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1326 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1329 /* new, potentially un-ordered, ampdu frame - process it */
1331 /* reset session timer */
1332 if (tid_agg_rx->timeout)
1333 tid_agg_rx->last_rx = jiffies;
1335 /* if this mpdu is fragmented - terminate rx aggregation session */
1336 sc = le16_to_cpu(hdr->seq_ctrl);
1337 if (sc & IEEE80211_SCTL_FRAG) {
1338 skb_queue_tail(&rx->sdata->skb_queue, skb);
1339 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1344 * No locking needed -- we will only ever process one
1345 * RX packet at a time, and thus own tid_agg_rx. All
1346 * other code manipulating it needs to (and does) make
1347 * sure that we cannot get to it any more before doing
1350 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1355 __skb_queue_tail(frames, skb);
1358 static ieee80211_rx_result debug_noinline
1359 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1361 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1362 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1364 if (status->flag & RX_FLAG_DUP_VALIDATED)
1368 * Drop duplicate 802.11 retransmissions
1369 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1372 if (rx->skb->len < 24)
1375 if (ieee80211_is_ctl(hdr->frame_control) ||
1376 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1377 is_multicast_ether_addr(hdr->addr1))
1383 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1384 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1385 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1386 rx->sta->rx_stats.num_duplicates++;
1387 return RX_DROP_UNUSABLE;
1388 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1389 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1395 static ieee80211_rx_result debug_noinline
1396 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1398 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1400 /* Drop disallowed frame classes based on STA auth/assoc state;
1401 * IEEE 802.11, Chap 5.5.
1403 * mac80211 filters only based on association state, i.e. it drops
1404 * Class 3 frames from not associated stations. hostapd sends
1405 * deauth/disassoc frames when needed. In addition, hostapd is
1406 * responsible for filtering on both auth and assoc states.
1409 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1410 return ieee80211_rx_mesh_check(rx);
1412 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1413 ieee80211_is_pspoll(hdr->frame_control)) &&
1414 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1415 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1416 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1417 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1419 * accept port control frames from the AP even when it's not
1420 * yet marked ASSOC to prevent a race where we don't set the
1421 * assoc bit quickly enough before it sends the first frame
1423 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1424 ieee80211_is_data_present(hdr->frame_control)) {
1425 unsigned int hdrlen;
1428 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1430 if (rx->skb->len < hdrlen + 8)
1431 return RX_DROP_MONITOR;
1433 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1434 if (ethertype == rx->sdata->control_port_protocol)
1438 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1439 cfg80211_rx_spurious_frame(rx->sdata->dev,
1442 return RX_DROP_UNUSABLE;
1444 return RX_DROP_MONITOR;
1451 static ieee80211_rx_result debug_noinline
1452 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1454 struct ieee80211_local *local;
1455 struct ieee80211_hdr *hdr;
1456 struct sk_buff *skb;
1460 hdr = (struct ieee80211_hdr *) skb->data;
1462 if (!local->pspolling)
1465 if (!ieee80211_has_fromds(hdr->frame_control))
1466 /* this is not from AP */
1469 if (!ieee80211_is_data(hdr->frame_control))
1472 if (!ieee80211_has_moredata(hdr->frame_control)) {
1473 /* AP has no more frames buffered for us */
1474 local->pspolling = false;
1478 /* more data bit is set, let's request a new frame from the AP */
1479 ieee80211_send_pspoll(local, rx->sdata);
1484 static void sta_ps_start(struct sta_info *sta)
1486 struct ieee80211_sub_if_data *sdata = sta->sdata;
1487 struct ieee80211_local *local = sdata->local;
1491 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1492 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1493 ps = &sdata->bss->ps;
1497 atomic_inc(&ps->num_sta_ps);
1498 set_sta_flag(sta, WLAN_STA_PS_STA);
1499 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1500 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1501 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1502 sta->sta.addr, sta->sta.aid);
1504 ieee80211_clear_fast_xmit(sta);
1506 if (!sta->sta.txq[0])
1509 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1510 if (txq_has_queue(sta->sta.txq[tid]))
1511 set_bit(tid, &sta->txq_buffered_tids);
1513 clear_bit(tid, &sta->txq_buffered_tids);
1517 static void sta_ps_end(struct sta_info *sta)
1519 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1520 sta->sta.addr, sta->sta.aid);
1522 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1524 * Clear the flag only if the other one is still set
1525 * so that the TX path won't start TX'ing new frames
1526 * directly ... In the case that the driver flag isn't
1527 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1529 clear_sta_flag(sta, WLAN_STA_PS_STA);
1530 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1531 sta->sta.addr, sta->sta.aid);
1535 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1536 clear_sta_flag(sta, WLAN_STA_PS_STA);
1537 ieee80211_sta_ps_deliver_wakeup(sta);
1540 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1542 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1545 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1547 /* Don't let the same PS state be set twice */
1548 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1549 if ((start && in_ps) || (!start && !in_ps))
1559 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1561 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1563 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1565 if (test_sta_flag(sta, WLAN_STA_SP))
1568 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1569 ieee80211_sta_ps_deliver_poll_response(sta);
1571 set_sta_flag(sta, WLAN_STA_PSPOLL);
1573 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1575 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1577 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1578 int ac = ieee80211_ac_from_tid(tid);
1581 * If this AC is not trigger-enabled do nothing unless the
1582 * driver is calling us after it already checked.
1584 * NB: This could/should check a separate bitmap of trigger-
1585 * enabled queues, but for now we only implement uAPSD w/o
1586 * TSPEC changes to the ACs, so they're always the same.
1588 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1589 tid != IEEE80211_NUM_TIDS)
1592 /* if we are in a service period, do nothing */
1593 if (test_sta_flag(sta, WLAN_STA_SP))
1596 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1597 ieee80211_sta_ps_deliver_uapsd(sta);
1599 set_sta_flag(sta, WLAN_STA_UAPSD);
1601 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1603 static ieee80211_rx_result debug_noinline
1604 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1606 struct ieee80211_sub_if_data *sdata = rx->sdata;
1607 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1608 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1613 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1614 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1618 * The device handles station powersave, so don't do anything about
1619 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1620 * it to mac80211 since they're handled.)
1622 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1626 * Don't do anything if the station isn't already asleep. In
1627 * the uAPSD case, the station will probably be marked asleep,
1628 * in the PS-Poll case the station must be confused ...
1630 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1633 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1634 ieee80211_sta_pspoll(&rx->sta->sta);
1636 /* Free PS Poll skb here instead of returning RX_DROP that would
1637 * count as an dropped frame. */
1638 dev_kfree_skb(rx->skb);
1641 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1642 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1643 ieee80211_has_pm(hdr->frame_control) &&
1644 (ieee80211_is_data_qos(hdr->frame_control) ||
1645 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1646 u8 tid = ieee80211_get_tid(hdr);
1648 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1654 static ieee80211_rx_result debug_noinline
1655 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1657 struct sta_info *sta = rx->sta;
1658 struct sk_buff *skb = rx->skb;
1659 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1660 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1667 * Update last_rx only for IBSS packets which are for the current
1668 * BSSID and for station already AUTHORIZED to avoid keeping the
1669 * current IBSS network alive in cases where other STAs start
1670 * using different BSSID. This will also give the station another
1671 * chance to restart the authentication/authorization in case
1672 * something went wrong the first time.
1674 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1675 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1676 NL80211_IFTYPE_ADHOC);
1677 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1678 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1679 sta->rx_stats.last_rx = jiffies;
1680 if (ieee80211_is_data(hdr->frame_control) &&
1681 !is_multicast_ether_addr(hdr->addr1))
1682 sta->rx_stats.last_rate =
1683 sta_stats_encode_rate(status);
1685 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1686 sta->rx_stats.last_rx = jiffies;
1687 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1689 * Mesh beacons will update last_rx when if they are found to
1690 * match the current local configuration when processed.
1692 sta->rx_stats.last_rx = jiffies;
1693 if (ieee80211_is_data(hdr->frame_control))
1694 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1697 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1698 ieee80211_sta_rx_notify(rx->sdata, hdr);
1700 sta->rx_stats.fragments++;
1702 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1703 sta->rx_stats.bytes += rx->skb->len;
1704 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1706 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1707 sta->rx_stats.last_signal = status->signal;
1708 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1711 if (status->chains) {
1712 sta->rx_stats.chains = status->chains;
1713 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1714 int signal = status->chain_signal[i];
1716 if (!(status->chains & BIT(i)))
1719 sta->rx_stats.chain_signal_last[i] = signal;
1720 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1726 * Change STA power saving mode only at the end of a frame
1727 * exchange sequence, and only for a data or management
1728 * frame as specified in IEEE 802.11-2016 11.2.3.2
1730 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1731 !ieee80211_has_morefrags(hdr->frame_control) &&
1732 !is_multicast_ether_addr(hdr->addr1) &&
1733 (ieee80211_is_mgmt(hdr->frame_control) ||
1734 ieee80211_is_data(hdr->frame_control)) &&
1735 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1736 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1737 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1738 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1739 if (!ieee80211_has_pm(hdr->frame_control))
1742 if (ieee80211_has_pm(hdr->frame_control))
1747 /* mesh power save support */
1748 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1749 ieee80211_mps_rx_h_sta_process(sta, hdr);
1752 * Drop (qos-)data::nullfunc frames silently, since they
1753 * are used only to control station power saving mode.
1755 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1756 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1759 * If we receive a 4-addr nullfunc frame from a STA
1760 * that was not moved to a 4-addr STA vlan yet send
1761 * the event to userspace and for older hostapd drop
1762 * the frame to the monitor interface.
1764 if (ieee80211_has_a4(hdr->frame_control) &&
1765 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1766 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1767 !rx->sdata->u.vlan.sta))) {
1768 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1769 cfg80211_rx_unexpected_4addr_frame(
1770 rx->sdata->dev, sta->sta.addr,
1772 return RX_DROP_MONITOR;
1775 * Update counter and free packet here to avoid
1776 * counting this as a dropped packed.
1778 sta->rx_stats.packets++;
1779 dev_kfree_skb(rx->skb);
1784 } /* ieee80211_rx_h_sta_process */
1786 static ieee80211_rx_result debug_noinline
1787 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1789 struct sk_buff *skb = rx->skb;
1790 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1791 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1794 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1795 struct ieee80211_key *sta_ptk = NULL;
1796 int mmie_keyidx = -1;
1798 const struct ieee80211_cipher_scheme *cs = NULL;
1803 * There are four types of keys:
1804 * - GTK (group keys)
1805 * - IGTK (group keys for management frames)
1806 * - PTK (pairwise keys)
1807 * - STK (station-to-station pairwise keys)
1809 * When selecting a key, we have to distinguish between multicast
1810 * (including broadcast) and unicast frames, the latter can only
1811 * use PTKs and STKs while the former always use GTKs and IGTKs.
1812 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1813 * unicast frames can also use key indices like GTKs. Hence, if we
1814 * don't have a PTK/STK we check the key index for a WEP key.
1816 * Note that in a regular BSS, multicast frames are sent by the
1817 * AP only, associated stations unicast the frame to the AP first
1818 * which then multicasts it on their behalf.
1820 * There is also a slight problem in IBSS mode: GTKs are negotiated
1821 * with each station, that is something we don't currently handle.
1822 * The spec seems to expect that one negotiates the same key with
1823 * every station but there's no such requirement; VLANs could be
1827 /* start without a key */
1829 fc = hdr->frame_control;
1832 int keyid = rx->sta->ptk_idx;
1834 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1835 cs = rx->sta->cipher_scheme;
1836 keyid = ieee80211_get_cs_keyid(cs, rx->skb);
1837 if (unlikely(keyid < 0))
1838 return RX_DROP_UNUSABLE;
1840 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1843 if (!ieee80211_has_protected(fc))
1844 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1846 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1848 if ((status->flag & RX_FLAG_DECRYPTED) &&
1849 (status->flag & RX_FLAG_IV_STRIPPED))
1851 /* Skip decryption if the frame is not protected. */
1852 if (!ieee80211_has_protected(fc))
1854 } else if (mmie_keyidx >= 0) {
1855 /* Broadcast/multicast robust management frame / BIP */
1856 if ((status->flag & RX_FLAG_DECRYPTED) &&
1857 (status->flag & RX_FLAG_IV_STRIPPED))
1860 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1861 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1862 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1864 if (ieee80211_is_group_privacy_action(skb) &&
1865 test_sta_flag(rx->sta, WLAN_STA_MFP))
1866 return RX_DROP_MONITOR;
1868 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1871 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1872 } else if (!ieee80211_has_protected(fc)) {
1874 * The frame was not protected, so skip decryption. However, we
1875 * need to set rx->key if there is a key that could have been
1876 * used so that the frame may be dropped if encryption would
1877 * have been expected.
1879 struct ieee80211_key *key = NULL;
1880 struct ieee80211_sub_if_data *sdata = rx->sdata;
1883 if (ieee80211_is_mgmt(fc) &&
1884 is_multicast_ether_addr(hdr->addr1) &&
1885 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1889 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1890 key = rcu_dereference(rx->sta->gtk[i]);
1896 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1897 key = rcu_dereference(sdata->keys[i]);
1910 * The device doesn't give us the IV so we won't be
1911 * able to look up the key. That's ok though, we
1912 * don't need to decrypt the frame, we just won't
1913 * be able to keep statistics accurate.
1914 * Except for key threshold notifications, should
1915 * we somehow allow the driver to tell us which key
1916 * the hardware used if this flag is set?
1918 if ((status->flag & RX_FLAG_DECRYPTED) &&
1919 (status->flag & RX_FLAG_IV_STRIPPED))
1922 hdrlen = ieee80211_hdrlen(fc);
1925 keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
1927 if (unlikely(keyidx < 0))
1928 return RX_DROP_UNUSABLE;
1930 if (rx->skb->len < 8 + hdrlen)
1931 return RX_DROP_UNUSABLE; /* TODO: count this? */
1933 * no need to call ieee80211_wep_get_keyidx,
1934 * it verifies a bunch of things we've done already
1936 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1937 keyidx = keyid >> 6;
1940 /* check per-station GTK first, if multicast packet */
1941 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1942 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1944 /* if not found, try default key */
1946 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1949 * RSNA-protected unicast frames should always be
1950 * sent with pairwise or station-to-station keys,
1951 * but for WEP we allow using a key index as well.
1954 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1955 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1956 !is_multicast_ether_addr(hdr->addr1))
1962 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1963 return RX_DROP_MONITOR;
1965 /* TODO: add threshold stuff again */
1967 return RX_DROP_MONITOR;
1970 switch (rx->key->conf.cipher) {
1971 case WLAN_CIPHER_SUITE_WEP40:
1972 case WLAN_CIPHER_SUITE_WEP104:
1973 result = ieee80211_crypto_wep_decrypt(rx);
1975 case WLAN_CIPHER_SUITE_TKIP:
1976 result = ieee80211_crypto_tkip_decrypt(rx);
1978 case WLAN_CIPHER_SUITE_CCMP:
1979 result = ieee80211_crypto_ccmp_decrypt(
1980 rx, IEEE80211_CCMP_MIC_LEN);
1982 case WLAN_CIPHER_SUITE_CCMP_256:
1983 result = ieee80211_crypto_ccmp_decrypt(
1984 rx, IEEE80211_CCMP_256_MIC_LEN);
1986 case WLAN_CIPHER_SUITE_AES_CMAC:
1987 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1989 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1990 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1992 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1993 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1994 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1996 case WLAN_CIPHER_SUITE_GCMP:
1997 case WLAN_CIPHER_SUITE_GCMP_256:
1998 result = ieee80211_crypto_gcmp_decrypt(rx);
2001 result = ieee80211_crypto_hw_decrypt(rx);
2004 /* the hdr variable is invalid after the decrypt handlers */
2006 /* either the frame has been decrypted or will be dropped */
2007 status->flag |= RX_FLAG_DECRYPTED;
2012 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2016 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2017 skb_queue_head_init(&cache->entries[i].skb_list);
2020 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2024 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2025 __skb_queue_purge(&cache->entries[i].skb_list);
2028 static inline struct ieee80211_fragment_entry *
2029 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2030 unsigned int frag, unsigned int seq, int rx_queue,
2031 struct sk_buff **skb)
2033 struct ieee80211_fragment_entry *entry;
2035 entry = &cache->entries[cache->next++];
2036 if (cache->next >= IEEE80211_FRAGMENT_MAX)
2039 __skb_queue_purge(&entry->skb_list);
2041 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2043 entry->first_frag_time = jiffies;
2045 entry->rx_queue = rx_queue;
2046 entry->last_frag = frag;
2047 entry->check_sequential_pn = false;
2048 entry->extra_len = 0;
2053 static inline struct ieee80211_fragment_entry *
2054 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2055 unsigned int frag, unsigned int seq,
2056 int rx_queue, struct ieee80211_hdr *hdr)
2058 struct ieee80211_fragment_entry *entry;
2062 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2063 struct ieee80211_hdr *f_hdr;
2067 idx = IEEE80211_FRAGMENT_MAX - 1;
2069 entry = &cache->entries[idx];
2070 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2071 entry->rx_queue != rx_queue ||
2072 entry->last_frag + 1 != frag)
2075 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
2078 * Check ftype and addresses are equal, else check next fragment
2080 if (((hdr->frame_control ^ f_hdr->frame_control) &
2081 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2082 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2083 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2086 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2087 __skb_queue_purge(&entry->skb_list);
2096 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2099 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2100 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2101 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2102 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2103 ieee80211_has_protected(fc);
2106 static ieee80211_rx_result debug_noinline
2107 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2109 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2110 struct ieee80211_hdr *hdr;
2113 unsigned int frag, seq;
2114 struct ieee80211_fragment_entry *entry;
2115 struct sk_buff *skb;
2116 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2118 hdr = (struct ieee80211_hdr *)rx->skb->data;
2119 fc = hdr->frame_control;
2121 if (ieee80211_is_ctl(fc))
2124 sc = le16_to_cpu(hdr->seq_ctrl);
2125 frag = sc & IEEE80211_SCTL_FRAG;
2128 cache = &rx->sta->frags;
2130 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2133 if (is_multicast_ether_addr(hdr->addr1))
2134 return RX_DROP_MONITOR;
2136 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2138 if (skb_linearize(rx->skb))
2139 return RX_DROP_UNUSABLE;
2142 * skb_linearize() might change the skb->data and
2143 * previously cached variables (in this case, hdr) need to
2144 * be refreshed with the new data.
2146 hdr = (struct ieee80211_hdr *)rx->skb->data;
2147 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2150 /* This is the first fragment of a new frame. */
2151 entry = ieee80211_reassemble_add(cache, frag, seq,
2152 rx->seqno_idx, &(rx->skb));
2153 if (requires_sequential_pn(rx, fc)) {
2154 int queue = rx->security_idx;
2156 /* Store CCMP/GCMP PN so that we can verify that the
2157 * next fragment has a sequential PN value.
2159 entry->check_sequential_pn = true;
2160 entry->is_protected = true;
2161 entry->key_color = rx->key->color;
2162 memcpy(entry->last_pn,
2163 rx->key->u.ccmp.rx_pn[queue],
2164 IEEE80211_CCMP_PN_LEN);
2165 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2167 offsetof(struct ieee80211_key,
2169 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2170 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2171 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2172 IEEE80211_GCMP_PN_LEN);
2173 } else if (rx->key &&
2174 (ieee80211_has_protected(fc) ||
2175 (status->flag & RX_FLAG_DECRYPTED))) {
2176 entry->is_protected = true;
2177 entry->key_color = rx->key->color;
2182 /* This is a fragment for a frame that should already be pending in
2183 * fragment cache. Add this fragment to the end of the pending entry.
2185 entry = ieee80211_reassemble_find(cache, frag, seq,
2186 rx->seqno_idx, hdr);
2188 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2189 return RX_DROP_MONITOR;
2192 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2193 * MPDU PN values are not incrementing in steps of 1."
2194 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2195 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2197 if (entry->check_sequential_pn) {
2199 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2201 if (!requires_sequential_pn(rx, fc))
2202 return RX_DROP_UNUSABLE;
2204 /* Prevent mixed key and fragment cache attacks */
2205 if (entry->key_color != rx->key->color)
2206 return RX_DROP_UNUSABLE;
2208 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2209 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2215 rpn = rx->ccm_gcm.pn;
2216 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2217 return RX_DROP_UNUSABLE;
2218 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2219 } else if (entry->is_protected &&
2221 (!ieee80211_has_protected(fc) &&
2222 !(status->flag & RX_FLAG_DECRYPTED)) ||
2223 rx->key->color != entry->key_color)) {
2224 /* Drop this as a mixed key or fragment cache attack, even
2225 * if for TKIP Michael MIC should protect us, and WEP is a
2226 * lost cause anyway.
2228 return RX_DROP_UNUSABLE;
2229 } else if (entry->is_protected && rx->key &&
2230 entry->key_color != rx->key->color &&
2231 (status->flag & RX_FLAG_DECRYPTED)) {
2232 return RX_DROP_UNUSABLE;
2235 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2236 __skb_queue_tail(&entry->skb_list, rx->skb);
2237 entry->last_frag = frag;
2238 entry->extra_len += rx->skb->len;
2239 if (ieee80211_has_morefrags(fc)) {
2244 rx->skb = __skb_dequeue(&entry->skb_list);
2245 if (skb_tailroom(rx->skb) < entry->extra_len) {
2246 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2247 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2249 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2250 __skb_queue_purge(&entry->skb_list);
2251 return RX_DROP_UNUSABLE;
2254 while ((skb = __skb_dequeue(&entry->skb_list))) {
2255 skb_put_data(rx->skb, skb->data, skb->len);
2260 ieee80211_led_rx(rx->local);
2262 rx->sta->rx_stats.packets++;
2266 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2268 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2274 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2276 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
2277 struct sk_buff *skb = rx->skb;
2278 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2281 * Pass through unencrypted frames if the hardware has
2282 * decrypted them already.
2284 if (status->flag & RX_FLAG_DECRYPTED)
2287 /* check mesh EAPOL frames first */
2288 if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
2289 ieee80211_is_data(fc))) {
2290 struct ieee80211s_hdr *mesh_hdr;
2291 u16 hdr_len = ieee80211_hdrlen(fc);
2292 u16 ethertype_offset;
2295 if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
2298 /* make sure fixed part of mesh header is there, also checks skb len */
2299 if (!pskb_may_pull(rx->skb, hdr_len + 6))
2302 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
2303 ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
2304 sizeof(rfc1042_header);
2306 if (skb_copy_bits(rx->skb, ethertype_offset, ðertype, 2) == 0 &&
2307 ethertype == rx->sdata->control_port_protocol)
2312 /* Drop unencrypted frames if key is set. */
2313 if (unlikely(!ieee80211_has_protected(fc) &&
2314 !ieee80211_is_any_nullfunc(fc) &&
2315 ieee80211_is_data(fc) && rx->key))
2321 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2323 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2324 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2325 __le16 fc = hdr->frame_control;
2328 * Pass through unencrypted frames if the hardware has
2329 * decrypted them already.
2331 if (status->flag & RX_FLAG_DECRYPTED)
2334 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2335 if (unlikely(!ieee80211_has_protected(fc) &&
2336 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2338 if (ieee80211_is_deauth(fc) ||
2339 ieee80211_is_disassoc(fc))
2340 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2345 /* BIP does not use Protected field, so need to check MMIE */
2346 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2347 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2348 if (ieee80211_is_deauth(fc) ||
2349 ieee80211_is_disassoc(fc))
2350 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2356 * When using MFP, Action frames are not allowed prior to
2357 * having configured keys.
2359 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2360 ieee80211_is_robust_mgmt_frame(rx->skb)))
2368 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2370 struct ieee80211_sub_if_data *sdata = rx->sdata;
2371 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2372 bool check_port_control = false;
2373 struct ethhdr *ehdr;
2376 *port_control = false;
2377 if (ieee80211_has_a4(hdr->frame_control) &&
2378 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2381 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2382 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2384 if (!sdata->u.mgd.use_4addr)
2387 check_port_control = true;
2390 if (is_multicast_ether_addr(hdr->addr1) &&
2391 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2394 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2398 ehdr = (struct ethhdr *) rx->skb->data;
2399 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2400 *port_control = true;
2401 else if (check_port_control)
2408 * requires that rx->skb is a frame with ethernet header
2410 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2412 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2413 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2414 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2417 * Allow EAPOL frames to us/the PAE group address regardless of
2418 * whether the frame was encrypted or not, and always disallow
2419 * all other destination addresses for them.
2421 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2422 return ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2423 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2425 if (ieee80211_802_1x_port_control(rx) ||
2426 ieee80211_drop_unencrypted(rx, fc))
2432 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2433 struct ieee80211_rx_data *rx)
2435 struct ieee80211_sub_if_data *sdata = rx->sdata;
2436 struct net_device *dev = sdata->dev;
2438 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2439 skb->protocol == cpu_to_be16(ETH_P_PREAUTH)) &&
2440 sdata->control_port_over_nl80211)) {
2441 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2442 bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2444 cfg80211_rx_control_port(dev, skb, noencrypt);
2447 struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2449 memset(skb->cb, 0, sizeof(skb->cb));
2452 * 802.1X over 802.11 requires that the authenticator address
2453 * be used for EAPOL frames. However, 802.1X allows the use of
2454 * the PAE group address instead. If the interface is part of
2455 * a bridge and we pass the frame with the PAE group address,
2456 * then the bridge will forward it to the network (even if the
2457 * client was not associated yet), which isn't supposed to
2459 * To avoid that, rewrite the destination address to our own
2460 * address, so that the authenticator (e.g. hostapd) will see
2461 * the frame, but bridge won't forward it anywhere else. Note
2462 * that due to earlier filtering, the only other address can
2463 * be the PAE group address.
2465 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2466 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2467 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2469 /* deliver to local stack */
2471 napi_gro_receive(rx->napi, skb);
2473 netif_receive_skb(skb);
2478 * requires that rx->skb is a frame with ethernet header
2481 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2483 struct ieee80211_sub_if_data *sdata = rx->sdata;
2484 struct net_device *dev = sdata->dev;
2485 struct sk_buff *skb, *xmit_skb;
2486 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2487 struct sta_info *dsta;
2492 ieee80211_rx_stats(dev, skb->len);
2495 /* The seqno index has the same property as needed
2496 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2497 * for non-QoS-data frames. Here we know it's a data
2498 * frame, so count MSDUs.
2500 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
2501 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2502 u64_stats_update_end(&rx->sta->rx_stats.syncp);
2505 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2506 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2507 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2508 ehdr->h_proto != rx->sdata->control_port_protocol &&
2509 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2510 if (is_multicast_ether_addr(ehdr->h_dest) &&
2511 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2513 * send multicast frames both to higher layers in
2514 * local net stack and back to the wireless medium
2516 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2518 net_info_ratelimited("%s: failed to clone multicast frame\n",
2520 } else if (!is_multicast_ether_addr(ehdr->h_dest)) {
2521 dsta = sta_info_get(sdata, skb->data);
2524 * The destination station is associated to
2525 * this AP (in this VLAN), so send the frame
2526 * directly to it and do not pass it to local
2535 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2537 /* 'align' will only take the values 0 or 2 here since all
2538 * frames are required to be aligned to 2-byte boundaries
2539 * when being passed to mac80211; the code here works just
2540 * as well if that isn't true, but mac80211 assumes it can
2541 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2545 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2547 if (WARN_ON(skb_headroom(skb) < 3)) {
2551 u8 *data = skb->data;
2552 size_t len = skb_headlen(skb);
2554 memmove(skb->data, data, len);
2555 skb_set_tail_pointer(skb, len);
2562 skb->protocol = eth_type_trans(skb, dev);
2563 ieee80211_deliver_skb_to_local_stack(skb, rx);
2568 * Send to wireless media and increase priority by 256 to
2569 * keep the received priority instead of reclassifying
2570 * the frame (see cfg80211_classify8021d).
2572 xmit_skb->priority += 256;
2573 xmit_skb->protocol = htons(ETH_P_802_3);
2574 skb_reset_network_header(xmit_skb);
2575 skb_reset_mac_header(xmit_skb);
2576 dev_queue_xmit(xmit_skb);
2580 static ieee80211_rx_result debug_noinline
2581 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2583 struct net_device *dev = rx->sdata->dev;
2584 struct sk_buff *skb = rx->skb;
2585 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2586 __le16 fc = hdr->frame_control;
2587 struct sk_buff_head frame_list;
2588 struct ethhdr ethhdr;
2589 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2591 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2594 } else switch (rx->sdata->vif.type) {
2595 case NL80211_IFTYPE_AP:
2596 case NL80211_IFTYPE_AP_VLAN:
2599 case NL80211_IFTYPE_STATION:
2601 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2604 case NL80211_IFTYPE_MESH_POINT:
2612 __skb_queue_head_init(&frame_list);
2614 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2615 rx->sdata->vif.addr,
2616 rx->sdata->vif.type,
2618 return RX_DROP_UNUSABLE;
2620 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2621 rx->sdata->vif.type,
2622 rx->local->hw.extra_tx_headroom,
2623 check_da, check_sa);
2625 while (!skb_queue_empty(&frame_list)) {
2626 rx->skb = __skb_dequeue(&frame_list);
2628 if (!ieee80211_frame_allowed(rx, fc)) {
2629 dev_kfree_skb(rx->skb);
2633 ieee80211_deliver_skb(rx);
2639 static ieee80211_rx_result debug_noinline
2640 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2642 struct sk_buff *skb = rx->skb;
2643 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2644 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2645 __le16 fc = hdr->frame_control;
2647 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2650 if (unlikely(!ieee80211_is_data(fc)))
2653 if (unlikely(!ieee80211_is_data_present(fc)))
2654 return RX_DROP_MONITOR;
2656 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2657 switch (rx->sdata->vif.type) {
2658 case NL80211_IFTYPE_AP_VLAN:
2659 if (!rx->sdata->u.vlan.sta)
2660 return RX_DROP_UNUSABLE;
2662 case NL80211_IFTYPE_STATION:
2663 if (!rx->sdata->u.mgd.use_4addr)
2664 return RX_DROP_UNUSABLE;
2667 return RX_DROP_UNUSABLE;
2671 if (is_multicast_ether_addr(hdr->addr1))
2672 return RX_DROP_UNUSABLE;
2676 * We should not receive A-MSDUs on pre-HT connections,
2677 * and HT connections cannot use old ciphers. Thus drop
2678 * them, as in those cases we couldn't even have SPP
2681 switch (rx->key->conf.cipher) {
2682 case WLAN_CIPHER_SUITE_WEP40:
2683 case WLAN_CIPHER_SUITE_WEP104:
2684 case WLAN_CIPHER_SUITE_TKIP:
2685 return RX_DROP_UNUSABLE;
2691 return __ieee80211_rx_h_amsdu(rx, 0);
2694 #ifdef CONFIG_MAC80211_MESH
2695 static ieee80211_rx_result
2696 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2698 struct ieee80211_hdr *fwd_hdr, *hdr;
2699 struct ieee80211_tx_info *info;
2700 struct ieee80211s_hdr *mesh_hdr;
2701 struct sk_buff *skb = rx->skb, *fwd_skb;
2702 struct ieee80211_local *local = rx->local;
2703 struct ieee80211_sub_if_data *sdata = rx->sdata;
2704 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2708 hdr = (struct ieee80211_hdr *) skb->data;
2709 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2711 /* make sure fixed part of mesh header is there, also checks skb len */
2712 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2713 return RX_DROP_MONITOR;
2715 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2717 /* make sure full mesh header is there, also checks skb len */
2718 if (!pskb_may_pull(rx->skb,
2719 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2720 return RX_DROP_MONITOR;
2722 /* reload pointers */
2723 hdr = (struct ieee80211_hdr *) skb->data;
2724 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2726 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2727 return RX_DROP_MONITOR;
2729 /* frame is in RMC, don't forward */
2730 if (ieee80211_is_data(hdr->frame_control) &&
2731 is_multicast_ether_addr(hdr->addr1) &&
2732 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2733 return RX_DROP_MONITOR;
2735 if (!ieee80211_is_data(hdr->frame_control))
2739 return RX_DROP_MONITOR;
2741 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2742 struct mesh_path *mppath;
2746 if (is_multicast_ether_addr(hdr->addr1)) {
2747 mpp_addr = hdr->addr3;
2748 proxied_addr = mesh_hdr->eaddr1;
2749 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2750 MESH_FLAGS_AE_A5_A6) {
2751 /* has_a4 already checked in ieee80211_rx_mesh_check */
2752 mpp_addr = hdr->addr4;
2753 proxied_addr = mesh_hdr->eaddr2;
2755 return RX_DROP_MONITOR;
2759 mppath = mpp_path_lookup(sdata, proxied_addr);
2761 mpp_path_add(sdata, proxied_addr, mpp_addr);
2763 spin_lock_bh(&mppath->state_lock);
2764 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2765 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2766 mppath->exp_time = jiffies;
2767 spin_unlock_bh(&mppath->state_lock);
2772 /* Frame has reached destination. Don't forward */
2773 if (!is_multicast_ether_addr(hdr->addr1) &&
2774 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2777 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2778 q = sdata->vif.hw_queue[ac];
2779 if (ieee80211_queue_stopped(&local->hw, q)) {
2780 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2781 return RX_DROP_MONITOR;
2783 skb_set_queue_mapping(skb, q);
2785 if (!--mesh_hdr->ttl) {
2786 if (!is_multicast_ether_addr(hdr->addr1))
2787 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2788 dropped_frames_ttl);
2792 if (!ifmsh->mshcfg.dot11MeshForwarding)
2795 if (sdata->crypto_tx_tailroom_needed_cnt)
2796 tailroom = IEEE80211_ENCRYPT_TAILROOM;
2798 fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2799 sdata->encrypt_headroom,
2800 tailroom, GFP_ATOMIC);
2804 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2805 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2806 info = IEEE80211_SKB_CB(fwd_skb);
2807 memset(info, 0, sizeof(*info));
2808 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2809 info->control.vif = &rx->sdata->vif;
2810 info->control.jiffies = jiffies;
2811 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2812 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2813 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2814 /* update power mode indication when forwarding */
2815 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2816 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2817 /* mesh power mode flags updated in mesh_nexthop_lookup */
2818 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2820 /* unable to resolve next hop */
2821 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2823 WLAN_REASON_MESH_PATH_NOFORWARD,
2825 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2827 return RX_DROP_MONITOR;
2830 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2831 ieee80211_add_pending_skb(local, fwd_skb);
2833 if (is_multicast_ether_addr(hdr->addr1))
2835 return RX_DROP_MONITOR;
2839 static ieee80211_rx_result debug_noinline
2840 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2842 struct ieee80211_sub_if_data *sdata = rx->sdata;
2843 struct ieee80211_local *local = rx->local;
2844 struct net_device *dev = sdata->dev;
2845 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2846 __le16 fc = hdr->frame_control;
2850 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2853 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2854 return RX_DROP_MONITOR;
2857 * Send unexpected-4addr-frame event to hostapd. For older versions,
2858 * also drop the frame to cooked monitor interfaces.
2860 if (ieee80211_has_a4(hdr->frame_control) &&
2861 sdata->vif.type == NL80211_IFTYPE_AP) {
2863 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2864 cfg80211_rx_unexpected_4addr_frame(
2865 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2866 return RX_DROP_MONITOR;
2869 err = __ieee80211_data_to_8023(rx, &port_control);
2871 return RX_DROP_UNUSABLE;
2873 if (!ieee80211_frame_allowed(rx, fc))
2874 return RX_DROP_MONITOR;
2876 /* directly handle TDLS channel switch requests/responses */
2877 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2878 cpu_to_be16(ETH_P_TDLS))) {
2879 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2881 if (pskb_may_pull(rx->skb,
2882 offsetof(struct ieee80211_tdls_data, u)) &&
2883 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2884 tf->category == WLAN_CATEGORY_TDLS &&
2885 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2886 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2887 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2888 schedule_work(&local->tdls_chsw_work);
2890 rx->sta->rx_stats.packets++;
2896 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2897 unlikely(port_control) && sdata->bss) {
2898 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2906 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2907 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2908 !is_multicast_ether_addr(
2909 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2910 (!local->scanning &&
2911 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
2912 mod_timer(&local->dynamic_ps_timer, jiffies +
2913 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2915 ieee80211_deliver_skb(rx);
2920 static ieee80211_rx_result debug_noinline
2921 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2923 struct sk_buff *skb = rx->skb;
2924 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2925 struct tid_ampdu_rx *tid_agg_rx;
2929 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2932 if (ieee80211_is_back_req(bar->frame_control)) {
2934 __le16 control, start_seq_num;
2935 } __packed bar_data;
2936 struct ieee80211_event event = {
2937 .type = BAR_RX_EVENT,
2941 return RX_DROP_MONITOR;
2943 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2944 &bar_data, sizeof(bar_data)))
2945 return RX_DROP_MONITOR;
2947 tid = le16_to_cpu(bar_data.control) >> 12;
2949 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
2950 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
2951 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
2952 WLAN_BACK_RECIPIENT,
2953 WLAN_REASON_QSTA_REQUIRE_SETUP);
2955 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2957 return RX_DROP_MONITOR;
2959 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2960 event.u.ba.tid = tid;
2961 event.u.ba.ssn = start_seq_num;
2962 event.u.ba.sta = &rx->sta->sta;
2964 /* reset session timer */
2965 if (tid_agg_rx->timeout)
2966 mod_timer(&tid_agg_rx->session_timer,
2967 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2969 spin_lock(&tid_agg_rx->reorder_lock);
2970 /* release stored frames up to start of BAR */
2971 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2972 start_seq_num, frames);
2973 spin_unlock(&tid_agg_rx->reorder_lock);
2975 drv_event_callback(rx->local, rx->sdata, &event);
2982 * After this point, we only want management frames,
2983 * so we can drop all remaining control frames to
2984 * cooked monitor interfaces.
2986 return RX_DROP_MONITOR;
2989 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2990 struct ieee80211_mgmt *mgmt,
2993 struct ieee80211_local *local = sdata->local;
2994 struct sk_buff *skb;
2995 struct ieee80211_mgmt *resp;
2997 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2998 /* Not to own unicast address */
3002 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
3003 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
3004 /* Not from the current AP or not associated yet. */
3008 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3009 /* Too short SA Query request frame */
3013 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3017 skb_reserve(skb, local->hw.extra_tx_headroom);
3018 resp = skb_put_zero(skb, 24);
3019 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3020 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3021 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3022 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3023 IEEE80211_STYPE_ACTION);
3024 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3025 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3026 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3027 memcpy(resp->u.action.u.sa_query.trans_id,
3028 mgmt->u.action.u.sa_query.trans_id,
3029 WLAN_SA_QUERY_TR_ID_LEN);
3031 ieee80211_tx_skb(sdata, skb);
3034 static ieee80211_rx_result debug_noinline
3035 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3037 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3038 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3041 * From here on, look only at management frames.
3042 * Data and control frames are already handled,
3043 * and unknown (reserved) frames are useless.
3045 if (rx->skb->len < 24)
3046 return RX_DROP_MONITOR;
3048 if (!ieee80211_is_mgmt(mgmt->frame_control))
3049 return RX_DROP_MONITOR;
3051 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3052 ieee80211_is_beacon(mgmt->frame_control) &&
3053 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3056 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3057 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3058 sig = status->signal;
3060 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
3061 rx->skb->data, rx->skb->len,
3063 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3066 if (ieee80211_drop_unencrypted_mgmt(rx))
3067 return RX_DROP_UNUSABLE;
3072 static ieee80211_rx_result debug_noinline
3073 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3075 struct ieee80211_local *local = rx->local;
3076 struct ieee80211_sub_if_data *sdata = rx->sdata;
3077 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3078 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3079 int len = rx->skb->len;
3081 if (!ieee80211_is_action(mgmt->frame_control))
3084 /* drop too small frames */
3085 if (len < IEEE80211_MIN_ACTION_SIZE)
3086 return RX_DROP_UNUSABLE;
3088 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3089 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3090 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3091 return RX_DROP_UNUSABLE;
3093 switch (mgmt->u.action.category) {
3094 case WLAN_CATEGORY_HT:
3095 /* reject HT action frames from stations not supporting HT */
3096 if (!rx->sta->sta.ht_cap.ht_supported)
3099 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3100 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3101 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3102 sdata->vif.type != NL80211_IFTYPE_AP &&
3103 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3106 /* verify action & smps_control/chanwidth are present */
3107 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3110 switch (mgmt->u.action.u.ht_smps.action) {
3111 case WLAN_HT_ACTION_SMPS: {
3112 struct ieee80211_supported_band *sband;
3113 enum ieee80211_smps_mode smps_mode;
3114 struct sta_opmode_info sta_opmode = {};
3116 /* convert to HT capability */
3117 switch (mgmt->u.action.u.ht_smps.smps_control) {
3118 case WLAN_HT_SMPS_CONTROL_DISABLED:
3119 smps_mode = IEEE80211_SMPS_OFF;
3121 case WLAN_HT_SMPS_CONTROL_STATIC:
3122 smps_mode = IEEE80211_SMPS_STATIC;
3124 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3125 smps_mode = IEEE80211_SMPS_DYNAMIC;
3131 /* if no change do nothing */
3132 if (rx->sta->sta.smps_mode == smps_mode)
3134 rx->sta->sta.smps_mode = smps_mode;
3135 sta_opmode.smps_mode =
3136 ieee80211_smps_mode_to_smps_mode(smps_mode);
3137 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3139 sband = rx->local->hw.wiphy->bands[status->band];
3141 rate_control_rate_update(local, sband, rx->sta,
3142 IEEE80211_RC_SMPS_CHANGED);
3143 cfg80211_sta_opmode_change_notify(sdata->dev,
3149 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3150 struct ieee80211_supported_band *sband;
3151 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3152 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3153 struct sta_opmode_info sta_opmode = {};
3155 /* If it doesn't support 40 MHz it can't change ... */
3156 if (!(rx->sta->sta.ht_cap.cap &
3157 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3160 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3161 max_bw = IEEE80211_STA_RX_BW_20;
3163 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
3165 /* set cur_max_bandwidth and recalc sta bw */
3166 rx->sta->cur_max_bandwidth = max_bw;
3167 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
3169 if (rx->sta->sta.bandwidth == new_bw)
3172 rx->sta->sta.bandwidth = new_bw;
3173 sband = rx->local->hw.wiphy->bands[status->band];
3175 ieee80211_sta_rx_bw_to_chan_width(rx->sta);
3176 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3178 rate_control_rate_update(local, sband, rx->sta,
3179 IEEE80211_RC_BW_CHANGED);
3180 cfg80211_sta_opmode_change_notify(sdata->dev,
3191 case WLAN_CATEGORY_PUBLIC:
3192 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3194 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3198 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3200 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3201 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3203 if (len < offsetof(struct ieee80211_mgmt,
3204 u.action.u.ext_chan_switch.variable))
3207 case WLAN_CATEGORY_VHT:
3208 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3209 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3210 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3211 sdata->vif.type != NL80211_IFTYPE_AP &&
3212 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3215 /* verify action code is present */
3216 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3219 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3220 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3221 /* verify opmode is present */
3222 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3226 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3227 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3235 case WLAN_CATEGORY_BACK:
3236 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3237 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3238 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3239 sdata->vif.type != NL80211_IFTYPE_AP &&
3240 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3243 /* verify action_code is present */
3244 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3247 switch (mgmt->u.action.u.addba_req.action_code) {
3248 case WLAN_ACTION_ADDBA_REQ:
3249 if (len < (IEEE80211_MIN_ACTION_SIZE +
3250 sizeof(mgmt->u.action.u.addba_req)))
3253 case WLAN_ACTION_ADDBA_RESP:
3254 if (len < (IEEE80211_MIN_ACTION_SIZE +
3255 sizeof(mgmt->u.action.u.addba_resp)))
3258 case WLAN_ACTION_DELBA:
3259 if (len < (IEEE80211_MIN_ACTION_SIZE +
3260 sizeof(mgmt->u.action.u.delba)))
3268 case WLAN_CATEGORY_SPECTRUM_MGMT:
3269 /* verify action_code is present */
3270 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3273 switch (mgmt->u.action.u.measurement.action_code) {
3274 case WLAN_ACTION_SPCT_MSR_REQ:
3275 if (status->band != NL80211_BAND_5GHZ)
3278 if (len < (IEEE80211_MIN_ACTION_SIZE +
3279 sizeof(mgmt->u.action.u.measurement)))
3282 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3285 ieee80211_process_measurement_req(sdata, mgmt, len);
3287 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3289 if (len < (IEEE80211_MIN_ACTION_SIZE +
3290 sizeof(mgmt->u.action.u.chan_switch)))
3293 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3294 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3295 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3298 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3299 bssid = sdata->u.mgd.bssid;
3300 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3301 bssid = sdata->u.ibss.bssid;
3302 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3307 if (!ether_addr_equal(mgmt->bssid, bssid))
3314 case WLAN_CATEGORY_SA_QUERY:
3315 if (len < (IEEE80211_MIN_ACTION_SIZE +
3316 sizeof(mgmt->u.action.u.sa_query)))
3319 switch (mgmt->u.action.u.sa_query.action) {
3320 case WLAN_ACTION_SA_QUERY_REQUEST:
3321 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3323 ieee80211_process_sa_query_req(sdata, mgmt, len);
3327 case WLAN_CATEGORY_SELF_PROTECTED:
3328 if (len < (IEEE80211_MIN_ACTION_SIZE +
3329 sizeof(mgmt->u.action.u.self_prot.action_code)))
3332 switch (mgmt->u.action.u.self_prot.action_code) {
3333 case WLAN_SP_MESH_PEERING_OPEN:
3334 case WLAN_SP_MESH_PEERING_CLOSE:
3335 case WLAN_SP_MESH_PEERING_CONFIRM:
3336 if (!ieee80211_vif_is_mesh(&sdata->vif))
3338 if (sdata->u.mesh.user_mpm)
3339 /* userspace handles this frame */
3342 case WLAN_SP_MGK_INFORM:
3343 case WLAN_SP_MGK_ACK:
3344 if (!ieee80211_vif_is_mesh(&sdata->vif))
3349 case WLAN_CATEGORY_MESH_ACTION:
3350 if (len < (IEEE80211_MIN_ACTION_SIZE +
3351 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3354 if (!ieee80211_vif_is_mesh(&sdata->vif))
3356 if (mesh_action_is_path_sel(mgmt) &&
3357 !mesh_path_sel_is_hwmp(sdata))
3365 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3366 /* will return in the next handlers */
3371 rx->sta->rx_stats.packets++;
3372 dev_kfree_skb(rx->skb);
3376 skb_queue_tail(&sdata->skb_queue, rx->skb);
3377 ieee80211_queue_work(&local->hw, &sdata->work);
3379 rx->sta->rx_stats.packets++;
3383 static ieee80211_rx_result debug_noinline
3384 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3386 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3389 /* skip known-bad action frames and return them in the next handler */
3390 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3394 * Getting here means the kernel doesn't know how to handle
3395 * it, but maybe userspace does ... include returned frames
3396 * so userspace can register for those to know whether ones
3397 * it transmitted were processed or returned.
3400 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3401 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3402 sig = status->signal;
3404 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
3405 rx->skb->data, rx->skb->len, 0)) {
3407 rx->sta->rx_stats.packets++;
3408 dev_kfree_skb(rx->skb);
3415 static ieee80211_rx_result debug_noinline
3416 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3418 struct ieee80211_local *local = rx->local;
3419 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3420 struct sk_buff *nskb;
3421 struct ieee80211_sub_if_data *sdata = rx->sdata;
3422 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3424 if (!ieee80211_is_action(mgmt->frame_control))
3428 * For AP mode, hostapd is responsible for handling any action
3429 * frames that we didn't handle, including returning unknown
3430 * ones. For all other modes we will return them to the sender,
3431 * setting the 0x80 bit in the action category, as required by
3432 * 802.11-2012 9.24.4.
3433 * Newer versions of hostapd shall also use the management frame
3434 * registration mechanisms, but older ones still use cooked
3435 * monitor interfaces so push all frames there.
3437 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3438 (sdata->vif.type == NL80211_IFTYPE_AP ||
3439 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3440 return RX_DROP_MONITOR;
3442 if (is_multicast_ether_addr(mgmt->da))
3443 return RX_DROP_MONITOR;
3445 /* do not return rejected action frames */
3446 if (mgmt->u.action.category & 0x80)
3447 return RX_DROP_UNUSABLE;
3449 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3452 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3454 nmgmt->u.action.category |= 0x80;
3455 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3456 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3458 memset(nskb->cb, 0, sizeof(nskb->cb));
3460 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3461 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3463 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3464 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3465 IEEE80211_TX_CTL_NO_CCK_RATE;
3466 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3468 local->hw.offchannel_tx_hw_queue;
3471 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3474 dev_kfree_skb(rx->skb);
3478 static ieee80211_rx_result debug_noinline
3479 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3481 struct ieee80211_sub_if_data *sdata = rx->sdata;
3482 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3485 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3487 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3488 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3489 sdata->vif.type != NL80211_IFTYPE_OCB &&
3490 sdata->vif.type != NL80211_IFTYPE_STATION)
3491 return RX_DROP_MONITOR;
3494 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3495 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3496 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3497 /* process for all: mesh, mlme, ibss */
3499 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3500 if (is_multicast_ether_addr(mgmt->da) &&
3501 !is_broadcast_ether_addr(mgmt->da))
3502 return RX_DROP_MONITOR;
3504 /* process only for station/IBSS */
3505 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3506 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3507 return RX_DROP_MONITOR;
3509 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3510 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3511 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3512 if (is_multicast_ether_addr(mgmt->da) &&
3513 !is_broadcast_ether_addr(mgmt->da))
3514 return RX_DROP_MONITOR;
3516 /* process only for station */
3517 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3518 return RX_DROP_MONITOR;
3520 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3521 /* process only for ibss and mesh */
3522 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3523 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3524 return RX_DROP_MONITOR;
3527 return RX_DROP_MONITOR;
3530 /* queue up frame and kick off work to process it */
3531 skb_queue_tail(&sdata->skb_queue, rx->skb);
3532 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3534 rx->sta->rx_stats.packets++;
3539 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3540 struct ieee80211_rate *rate)
3542 struct ieee80211_sub_if_data *sdata;
3543 struct ieee80211_local *local = rx->local;
3544 struct sk_buff *skb = rx->skb, *skb2;
3545 struct net_device *prev_dev = NULL;
3546 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3547 int needed_headroom;
3550 * If cooked monitor has been processed already, then
3551 * don't do it again. If not, set the flag.
3553 if (rx->flags & IEEE80211_RX_CMNTR)
3555 rx->flags |= IEEE80211_RX_CMNTR;
3557 /* If there are no cooked monitor interfaces, just free the SKB */
3558 if (!local->cooked_mntrs)
3561 /* vendor data is long removed here */
3562 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3563 /* room for the radiotap header based on driver features */
3564 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3566 if (skb_headroom(skb) < needed_headroom &&
3567 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3570 /* prepend radiotap information */
3571 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3574 skb_reset_mac_header(skb);
3575 skb->ip_summed = CHECKSUM_UNNECESSARY;
3576 skb->pkt_type = PACKET_OTHERHOST;
3577 skb->protocol = htons(ETH_P_802_2);
3579 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3580 if (!ieee80211_sdata_running(sdata))
3583 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3584 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3588 skb2 = skb_clone(skb, GFP_ATOMIC);
3590 skb2->dev = prev_dev;
3591 netif_receive_skb(skb2);
3595 prev_dev = sdata->dev;
3596 ieee80211_rx_stats(sdata->dev, skb->len);
3600 skb->dev = prev_dev;
3601 netif_receive_skb(skb);
3609 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3610 ieee80211_rx_result res)
3613 case RX_DROP_MONITOR:
3614 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3616 rx->sta->rx_stats.dropped++;
3619 struct ieee80211_rate *rate = NULL;
3620 struct ieee80211_supported_band *sband;
3621 struct ieee80211_rx_status *status;
3623 status = IEEE80211_SKB_RXCB((rx->skb));
3625 sband = rx->local->hw.wiphy->bands[status->band];
3626 if (status->encoding == RX_ENC_LEGACY)
3627 rate = &sband->bitrates[status->rate_idx];
3629 ieee80211_rx_cooked_monitor(rx, rate);
3632 case RX_DROP_UNUSABLE:
3633 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3635 rx->sta->rx_stats.dropped++;
3636 dev_kfree_skb(rx->skb);
3639 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3644 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3645 struct sk_buff_head *frames)
3647 ieee80211_rx_result res = RX_DROP_MONITOR;
3648 struct sk_buff *skb;
3650 #define CALL_RXH(rxh) \
3653 if (res != RX_CONTINUE) \
3657 /* Lock here to avoid hitting all of the data used in the RX
3658 * path (e.g. key data, station data, ...) concurrently when
3659 * a frame is released from the reorder buffer due to timeout
3660 * from the timer, potentially concurrently with RX from the
3663 spin_lock_bh(&rx->local->rx_path_lock);
3665 while ((skb = __skb_dequeue(frames))) {
3667 * all the other fields are valid across frames
3668 * that belong to an aMPDU since they are on the
3669 * same TID from the same station
3673 CALL_RXH(ieee80211_rx_h_check_more_data);
3674 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3675 CALL_RXH(ieee80211_rx_h_sta_process);
3676 CALL_RXH(ieee80211_rx_h_decrypt);
3677 CALL_RXH(ieee80211_rx_h_defragment);
3678 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3679 /* must be after MMIC verify so header is counted in MPDU mic */
3680 #ifdef CONFIG_MAC80211_MESH
3681 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3682 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3684 CALL_RXH(ieee80211_rx_h_amsdu);
3685 CALL_RXH(ieee80211_rx_h_data);
3687 /* special treatment -- needs the queue */
3688 res = ieee80211_rx_h_ctrl(rx, frames);
3689 if (res != RX_CONTINUE)
3692 CALL_RXH(ieee80211_rx_h_mgmt_check);
3693 CALL_RXH(ieee80211_rx_h_action);
3694 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3695 CALL_RXH(ieee80211_rx_h_action_return);
3696 CALL_RXH(ieee80211_rx_h_mgmt);
3699 ieee80211_rx_handlers_result(rx, res);
3704 spin_unlock_bh(&rx->local->rx_path_lock);
3707 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3709 struct sk_buff_head reorder_release;
3710 ieee80211_rx_result res = RX_DROP_MONITOR;
3712 __skb_queue_head_init(&reorder_release);
3714 #define CALL_RXH(rxh) \
3717 if (res != RX_CONTINUE) \
3721 CALL_RXH(ieee80211_rx_h_check_dup);
3722 CALL_RXH(ieee80211_rx_h_check);
3724 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3726 ieee80211_rx_handlers(rx, &reorder_release);
3730 ieee80211_rx_handlers_result(rx, res);
3736 * This function makes calls into the RX path, therefore
3737 * it has to be invoked under RCU read lock.
3739 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3741 struct sk_buff_head frames;
3742 struct ieee80211_rx_data rx = {
3744 .sdata = sta->sdata,
3745 .local = sta->local,
3746 /* This is OK -- must be QoS data frame */
3747 .security_idx = tid,
3749 .napi = NULL, /* must be NULL to not have races */
3751 struct tid_ampdu_rx *tid_agg_rx;
3753 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3757 __skb_queue_head_init(&frames);
3759 spin_lock(&tid_agg_rx->reorder_lock);
3760 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3761 spin_unlock(&tid_agg_rx->reorder_lock);
3763 if (!skb_queue_empty(&frames)) {
3764 struct ieee80211_event event = {
3765 .type = BA_FRAME_TIMEOUT,
3767 .u.ba.sta = &sta->sta,
3769 drv_event_callback(rx.local, rx.sdata, &event);
3772 ieee80211_rx_handlers(&rx, &frames);
3775 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3776 u16 ssn, u64 filtered,
3779 struct sta_info *sta;
3780 struct tid_ampdu_rx *tid_agg_rx;
3781 struct sk_buff_head frames;
3782 struct ieee80211_rx_data rx = {
3783 /* This is OK -- must be QoS data frame */
3784 .security_idx = tid,
3789 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3792 __skb_queue_head_init(&frames);
3794 sta = container_of(pubsta, struct sta_info, sta);
3797 rx.sdata = sta->sdata;
3798 rx.local = sta->local;
3801 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3805 spin_lock_bh(&tid_agg_rx->reorder_lock);
3807 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3810 /* release all frames in the reorder buffer */
3811 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3812 IEEE80211_SN_MODULO;
3813 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3815 /* update ssn to match received ssn */
3816 tid_agg_rx->head_seq_num = ssn;
3818 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3822 /* handle the case that received ssn is behind the mac ssn.
3823 * it can be tid_agg_rx->buf_size behind and still be valid */
3824 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3825 if (diff >= tid_agg_rx->buf_size) {
3826 tid_agg_rx->reorder_buf_filtered = 0;
3829 filtered = filtered >> diff;
3833 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3834 int index = (ssn + i) % tid_agg_rx->buf_size;
3836 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3837 if (filtered & BIT_ULL(i))
3838 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3841 /* now process also frames that the filter marking released */
3842 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3845 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3847 ieee80211_rx_handlers(&rx, &frames);
3852 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3854 /* main receive path */
3856 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3858 struct ieee80211_sub_if_data *sdata = rx->sdata;
3859 struct sk_buff *skb = rx->skb;
3860 struct ieee80211_hdr *hdr = (void *)skb->data;
3861 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3862 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3863 bool multicast = is_multicast_ether_addr(hdr->addr1);
3865 switch (sdata->vif.type) {
3866 case NL80211_IFTYPE_STATION:
3867 if (!bssid && !sdata->u.mgd.use_4addr)
3869 if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
3873 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3874 case NL80211_IFTYPE_ADHOC:
3877 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3878 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
3880 if (ieee80211_is_beacon(hdr->frame_control))
3882 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3885 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3889 if (status->encoding != RX_ENC_LEGACY)
3890 rate_idx = 0; /* TODO: HT/VHT rates */
3892 rate_idx = status->rate_idx;
3893 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3897 case NL80211_IFTYPE_OCB:
3900 if (!ieee80211_is_data_present(hdr->frame_control))
3902 if (!is_broadcast_ether_addr(bssid))
3905 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3909 if (status->encoding != RX_ENC_LEGACY)
3910 rate_idx = 0; /* TODO: HT rates */
3912 rate_idx = status->rate_idx;
3913 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3917 case NL80211_IFTYPE_MESH_POINT:
3918 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
3922 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3923 case NL80211_IFTYPE_AP_VLAN:
3924 case NL80211_IFTYPE_AP:
3926 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3928 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3930 * Accept public action frames even when the
3931 * BSSID doesn't match, this is used for P2P
3932 * and location updates. Note that mac80211
3933 * itself never looks at these frames.
3936 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3938 if (ieee80211_is_public_action(hdr, skb->len))
3940 return ieee80211_is_beacon(hdr->frame_control);
3943 if (!ieee80211_has_tods(hdr->frame_control)) {
3944 /* ignore data frames to TDLS-peers */
3945 if (ieee80211_is_data(hdr->frame_control))
3947 /* ignore action frames to TDLS-peers */
3948 if (ieee80211_is_action(hdr->frame_control) &&
3949 !is_broadcast_ether_addr(bssid) &&
3950 !ether_addr_equal(bssid, hdr->addr1))
3955 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3956 * the BSSID - we've checked that already but may have accepted
3957 * the wildcard (ff:ff:ff:ff:ff:ff).
3960 * The BSSID of the Data frame is determined as follows:
3961 * a) If the STA is contained within an AP or is associated
3962 * with an AP, the BSSID is the address currently in use
3963 * by the STA contained in the AP.
3965 * So we should not accept data frames with an address that's
3968 * Accepting it also opens a security problem because stations
3969 * could encrypt it with the GTK and inject traffic that way.
3971 if (ieee80211_is_data(hdr->frame_control) && multicast)
3975 case NL80211_IFTYPE_WDS:
3976 if (bssid || !ieee80211_is_data(hdr->frame_control))
3978 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3979 case NL80211_IFTYPE_P2P_DEVICE:
3980 return ieee80211_is_public_action(hdr, skb->len) ||
3981 ieee80211_is_probe_req(hdr->frame_control) ||
3982 ieee80211_is_probe_resp(hdr->frame_control) ||
3983 ieee80211_is_beacon(hdr->frame_control);
3984 case NL80211_IFTYPE_NAN:
3985 /* Currently no frames on NAN interface are allowed */
3995 void ieee80211_check_fast_rx(struct sta_info *sta)
3997 struct ieee80211_sub_if_data *sdata = sta->sdata;
3998 struct ieee80211_local *local = sdata->local;
3999 struct ieee80211_key *key;
4000 struct ieee80211_fast_rx fastrx = {
4002 .vif_type = sdata->vif.type,
4003 .control_port_protocol = sdata->control_port_protocol,
4004 }, *old, *new = NULL;
4005 bool assign = false;
4007 /* use sparse to check that we don't return without updating */
4008 __acquire(check_fast_rx);
4010 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4011 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4012 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4013 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4015 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4017 /* fast-rx doesn't do reordering */
4018 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4019 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4022 switch (sdata->vif.type) {
4023 case NL80211_IFTYPE_STATION:
4024 if (sta->sta.tdls) {
4025 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4026 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4027 fastrx.expected_ds_bits = 0;
4029 fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
4030 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4031 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4032 fastrx.expected_ds_bits =
4033 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4036 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4037 fastrx.expected_ds_bits |=
4038 cpu_to_le16(IEEE80211_FCTL_TODS);
4039 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4040 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4043 if (!sdata->u.mgd.powersave)
4046 /* software powersave is a huge mess, avoid all of it */
4047 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4049 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4050 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4053 case NL80211_IFTYPE_AP_VLAN:
4054 case NL80211_IFTYPE_AP:
4055 /* parallel-rx requires this, at least with calls to
4056 * ieee80211_sta_ps_transition()
4058 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4060 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4061 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4062 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4064 fastrx.internal_forward =
4065 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4066 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4067 !sdata->u.vlan.sta);
4069 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4070 sdata->u.vlan.sta) {
4071 fastrx.expected_ds_bits |=
4072 cpu_to_le16(IEEE80211_FCTL_FROMDS);
4073 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4074 fastrx.internal_forward = 0;
4082 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4086 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4088 key = rcu_dereference(sdata->default_unicast_key);
4090 switch (key->conf.cipher) {
4091 case WLAN_CIPHER_SUITE_TKIP:
4092 /* we don't want to deal with MMIC in fast-rx */
4094 case WLAN_CIPHER_SUITE_CCMP:
4095 case WLAN_CIPHER_SUITE_CCMP_256:
4096 case WLAN_CIPHER_SUITE_GCMP:
4097 case WLAN_CIPHER_SUITE_GCMP_256:
4100 /* we also don't want to deal with WEP or cipher scheme
4101 * since those require looking up the key idx in the
4102 * frame, rather than assuming the PTK is used
4103 * (we need to revisit this once we implement the real
4104 * PTK index, which is now valid in the spec, but we
4105 * haven't implemented that part yet)
4111 fastrx.icv_len = key->conf.icv_len;
4118 __release(check_fast_rx);
4121 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4123 spin_lock_bh(&sta->lock);
4124 old = rcu_dereference_protected(sta->fast_rx, true);
4125 rcu_assign_pointer(sta->fast_rx, new);
4126 spin_unlock_bh(&sta->lock);
4129 kfree_rcu(old, rcu_head);
4132 void ieee80211_clear_fast_rx(struct sta_info *sta)
4134 struct ieee80211_fast_rx *old;
4136 spin_lock_bh(&sta->lock);
4137 old = rcu_dereference_protected(sta->fast_rx, true);
4138 RCU_INIT_POINTER(sta->fast_rx, NULL);
4139 spin_unlock_bh(&sta->lock);
4142 kfree_rcu(old, rcu_head);
4145 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4147 struct ieee80211_local *local = sdata->local;
4148 struct sta_info *sta;
4150 lockdep_assert_held(&local->sta_mtx);
4152 list_for_each_entry(sta, &local->sta_list, list) {
4153 if (sdata != sta->sdata &&
4154 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4156 ieee80211_check_fast_rx(sta);
4160 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4162 struct ieee80211_local *local = sdata->local;
4164 mutex_lock(&local->sta_mtx);
4165 __ieee80211_check_fast_rx_iface(sdata);
4166 mutex_unlock(&local->sta_mtx);
4169 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4170 struct ieee80211_fast_rx *fast_rx)
4172 struct sk_buff *skb = rx->skb;
4173 struct ieee80211_hdr *hdr = (void *)skb->data;
4174 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4175 struct sta_info *sta = rx->sta;
4176 int orig_len = skb->len;
4177 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4178 int snap_offs = hdrlen;
4180 u8 snap[sizeof(rfc1042_header)];
4182 } *payload __aligned(2);
4186 } addrs __aligned(2);
4187 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
4189 if (fast_rx->uses_rss)
4190 stats = this_cpu_ptr(sta->pcpu_rx_stats);
4192 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4193 * to a common data structure; drivers can implement that per queue
4194 * but we don't have that information in mac80211
4196 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4199 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4201 /* If using encryption, we also need to have:
4202 * - PN_VALIDATED: similar, but the implementation is tricky
4203 * - DECRYPTED: necessary for PN_VALIDATED
4206 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4209 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4212 if (unlikely(ieee80211_is_frag(hdr)))
4215 /* Since our interface address cannot be multicast, this
4216 * implicitly also rejects multicast frames without the
4219 * We shouldn't get any *data* frames not addressed to us
4220 * (AP mode will accept multicast *management* frames), but
4221 * punting here will make it go through the full checks in
4222 * ieee80211_accept_frame().
4224 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4227 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4228 IEEE80211_FCTL_TODS)) !=
4229 fast_rx->expected_ds_bits)
4232 /* assign the key to drop unencrypted frames (later)
4233 * and strip the IV/MIC if necessary
4235 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4236 /* GCMP header length is the same */
4237 snap_offs += IEEE80211_CCMP_HDR_LEN;
4240 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4241 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4244 payload = (void *)(skb->data + snap_offs);
4246 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4249 /* Don't handle these here since they require special code.
4250 * Accept AARP and IPX even though they should come with a
4251 * bridge-tunnel header - but if we get them this way then
4252 * there's little point in discarding them.
4254 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4255 payload->proto == fast_rx->control_port_protocol))
4259 /* after this point, don't punt to the slowpath! */
4261 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4262 pskb_trim(skb, skb->len - fast_rx->icv_len))
4265 if (unlikely(fast_rx->sta_notify)) {
4266 ieee80211_sta_rx_notify(rx->sdata, hdr);
4267 fast_rx->sta_notify = false;
4270 /* statistics part of ieee80211_rx_h_sta_process() */
4271 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4272 stats->last_signal = status->signal;
4273 if (!fast_rx->uses_rss)
4274 ewma_signal_add(&sta->rx_stats_avg.signal,
4278 if (status->chains) {
4281 stats->chains = status->chains;
4282 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4283 int signal = status->chain_signal[i];
4285 if (!(status->chains & BIT(i)))
4288 stats->chain_signal_last[i] = signal;
4289 if (!fast_rx->uses_rss)
4290 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4294 /* end of statistics */
4296 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4299 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4300 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4307 stats->last_rx = jiffies;
4308 stats->last_rate = sta_stats_encode_rate(status);
4313 /* do the header conversion - first grab the addresses */
4314 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4315 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4316 /* remove the SNAP but leave the ethertype */
4317 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4318 /* push the addresses in front */
4319 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4321 skb->dev = fast_rx->dev;
4323 ieee80211_rx_stats(fast_rx->dev, skb->len);
4325 /* The seqno index has the same property as needed
4326 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4327 * for non-QoS-data frames. Here we know it's a data
4328 * frame, so count MSDUs.
4330 u64_stats_update_begin(&stats->syncp);
4331 stats->msdu[rx->seqno_idx]++;
4332 stats->bytes += orig_len;
4333 u64_stats_update_end(&stats->syncp);
4335 if (fast_rx->internal_forward) {
4336 struct sk_buff *xmit_skb = NULL;
4337 bool multicast = is_multicast_ether_addr(skb->data);
4340 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4341 } else if (sta_info_get(rx->sdata, skb->data)) {
4348 * Send to wireless media and increase priority by 256
4349 * to keep the received priority instead of
4350 * reclassifying the frame (see cfg80211_classify8021d).
4352 xmit_skb->priority += 256;
4353 xmit_skb->protocol = htons(ETH_P_802_3);
4354 skb_reset_network_header(xmit_skb);
4355 skb_reset_mac_header(xmit_skb);
4356 dev_queue_xmit(xmit_skb);
4363 /* deliver to local stack */
4364 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4365 memset(skb->cb, 0, sizeof(skb->cb));
4367 napi_gro_receive(rx->napi, skb);
4369 netif_receive_skb(skb);
4379 * This function returns whether or not the SKB
4380 * was destined for RX processing or not, which,
4381 * if consume is true, is equivalent to whether
4382 * or not the skb was consumed.
4384 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4385 struct sk_buff *skb, bool consume)
4387 struct ieee80211_local *local = rx->local;
4388 struct ieee80211_sub_if_data *sdata = rx->sdata;
4392 /* See if we can do fast-rx; if we have to copy we already lost,
4393 * so punt in that case. We should never have to deliver a data
4394 * frame to multiple interfaces anyway.
4396 * We skip the ieee80211_accept_frame() call and do the necessary
4397 * checking inside ieee80211_invoke_fast_rx().
4399 if (consume && rx->sta) {
4400 struct ieee80211_fast_rx *fast_rx;
4402 fast_rx = rcu_dereference(rx->sta->fast_rx);
4403 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4407 if (!ieee80211_accept_frame(rx))
4411 skb = skb_copy(skb, GFP_ATOMIC);
4413 if (net_ratelimit())
4414 wiphy_debug(local->hw.wiphy,
4415 "failed to copy skb for %s\n",
4423 ieee80211_invoke_rx_handlers(rx);
4428 * This is the actual Rx frames handler. as it belongs to Rx path it must
4429 * be called with rcu_read_lock protection.
4431 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4432 struct ieee80211_sta *pubsta,
4433 struct sk_buff *skb,
4434 struct napi_struct *napi)
4436 struct ieee80211_local *local = hw_to_local(hw);
4437 struct ieee80211_sub_if_data *sdata;
4438 struct ieee80211_hdr *hdr;
4440 struct ieee80211_rx_data rx;
4441 struct ieee80211_sub_if_data *prev;
4442 struct rhlist_head *tmp;
4445 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4446 memset(&rx, 0, sizeof(rx));
4451 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4452 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4454 if (ieee80211_is_mgmt(fc)) {
4455 /* drop frame if too short for header */
4456 if (skb->len < ieee80211_hdrlen(fc))
4459 err = skb_linearize(skb);
4461 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4469 hdr = (struct ieee80211_hdr *)skb->data;
4470 ieee80211_parse_qos(&rx);
4471 ieee80211_verify_alignment(&rx);
4473 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4474 ieee80211_is_beacon(hdr->frame_control)))
4475 ieee80211_scan_rx(local, skb);
4477 if (ieee80211_is_data(fc)) {
4478 struct sta_info *sta, *prev_sta;
4481 rx.sta = container_of(pubsta, struct sta_info, sta);
4482 rx.sdata = rx.sta->sdata;
4483 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4490 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4497 rx.sdata = prev_sta->sdata;
4498 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4505 rx.sdata = prev_sta->sdata;
4507 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4515 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4516 if (!ieee80211_sdata_running(sdata))
4519 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4520 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4524 * frame is destined for this interface, but if it's
4525 * not also for the previous one we handle that after
4526 * the loop to avoid copying the SKB once too much
4534 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4536 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4542 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4545 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4554 * This is the receive path handler. It is called by a low level driver when an
4555 * 802.11 MPDU is received from the hardware.
4557 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4558 struct sk_buff *skb, struct napi_struct *napi)
4560 struct ieee80211_local *local = hw_to_local(hw);
4561 struct ieee80211_rate *rate = NULL;
4562 struct ieee80211_supported_band *sband;
4563 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4565 WARN_ON_ONCE(softirq_count() == 0);
4567 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4570 sband = local->hw.wiphy->bands[status->band];
4571 if (WARN_ON(!sband))
4575 * If we're suspending, it is possible although not too likely
4576 * that we'd be receiving frames after having already partially
4577 * quiesced the stack. We can't process such frames then since
4578 * that might, for example, cause stations to be added or other
4579 * driver callbacks be invoked.
4581 if (unlikely(local->quiescing || local->suspended))
4584 /* We might be during a HW reconfig, prevent Rx for the same reason */
4585 if (unlikely(local->in_reconfig))
4589 * The same happens when we're not even started,
4590 * but that's worth a warning.
4592 if (WARN_ON(!local->started))
4595 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4597 * Validate the rate, unless a PLCP error means that
4598 * we probably can't have a valid rate here anyway.
4601 switch (status->encoding) {
4604 * rate_idx is MCS index, which can be [0-76]
4607 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4609 * Anything else would be some sort of driver or
4610 * hardware error. The driver should catch hardware
4613 if (WARN(status->rate_idx > 76,
4614 "Rate marked as an HT rate but passed "
4615 "status->rate_idx is not "
4616 "an MCS index [0-76]: %d (0x%02x)\n",
4622 if (WARN_ONCE(status->rate_idx > 9 ||
4625 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4626 status->rate_idx, status->nss))
4630 if (WARN_ONCE(status->rate_idx > 11 ||
4633 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4634 status->rate_idx, status->nss))
4641 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4643 rate = &sband->bitrates[status->rate_idx];
4647 status->rx_flags = 0;
4650 * key references and virtual interfaces are protected using RCU
4651 * and this requires that we are in a read-side RCU section during
4652 * receive processing
4657 * Frames with failed FCS/PLCP checksum are not returned,
4658 * all other frames are returned without radiotap header
4659 * if it was previously present.
4660 * Also, frames with less than 16 bytes are dropped.
4662 skb = ieee80211_rx_monitor(local, skb, rate);
4668 ieee80211_tpt_led_trig_rx(local,
4669 ((struct ieee80211_hdr *)skb->data)->frame_control,
4672 __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
4680 EXPORT_SYMBOL(ieee80211_rx_napi);
4682 /* This is a version of the rx handler that can be called from hard irq
4683 * context. Post the skb on the queue and schedule the tasklet */
4684 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
4686 struct ieee80211_local *local = hw_to_local(hw);
4688 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4690 skb->pkt_type = IEEE80211_RX_MSG;
4691 skb_queue_tail(&local->skb_queue, skb);
4692 tasklet_schedule(&local->tasklet);
4694 EXPORT_SYMBOL(ieee80211_rx_irqsafe);