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 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 |
122 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
125 if (ieee80211_is_ctl(hdr->frame_control) &&
126 !ieee80211_is_pspoll(hdr->frame_control) &&
127 !ieee80211_is_back_req(hdr->frame_control))
134 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
135 struct ieee80211_rx_status *status,
140 /* always present fields */
141 len = sizeof(struct ieee80211_radiotap_header) + 8;
143 /* allocate extra bitmaps */
145 len += 4 * hweight8(status->chains);
146 /* vendor presence bitmap */
147 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)
150 if (ieee80211_have_rx_timestamp(status)) {
154 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
157 /* antenna field, if we don't have per-chain info */
161 /* padding for RX_FLAGS if necessary */
164 if (status->encoding == RX_ENC_HT) /* HT info */
167 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
172 if (status->encoding == RX_ENC_VHT) {
177 if (local->hw.radiotap_timestamp.units_pos >= 0) {
182 if (status->encoding == RX_ENC_HE &&
183 status->flag & RX_FLAG_RADIOTAP_HE) {
186 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
189 if (status->encoding == RX_ENC_HE &&
190 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
193 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
196 if (status->flag & RX_FLAG_NO_PSDU)
199 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
202 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4);
205 if (status->chains) {
206 /* antenna and antenna signal fields */
207 len += 2 * hweight8(status->chains);
210 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
211 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
213 /* alignment for fixed 6-byte vendor data header */
215 /* vendor data header */
217 if (WARN_ON(rtap->align == 0))
219 len = ALIGN(len, rtap->align);
220 len += rtap->len + rtap->pad;
226 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
231 struct ieee80211_hdr_3addr hdr;
234 } __packed __aligned(2) action;
239 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
241 if (skb->len < rtap_space + sizeof(action) +
242 VHT_MUMIMO_GROUPS_DATA_LEN)
245 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
248 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
250 if (!ieee80211_is_action(action.hdr.frame_control))
253 if (action.category != WLAN_CATEGORY_VHT)
256 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
259 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
262 skb = skb_copy(skb, GFP_ATOMIC);
266 skb_queue_tail(&sdata->skb_queue, skb);
267 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
271 * ieee80211_add_rx_radiotap_header - add radiotap header
273 * add a radiotap header containing all the fields which the hardware provided.
276 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
278 struct ieee80211_rate *rate,
279 int rtap_len, bool has_fcs)
281 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
282 struct ieee80211_radiotap_header *rthdr;
287 u16 channel_flags = 0;
289 unsigned long chains = status->chains;
290 struct ieee80211_vendor_radiotap rtap = {};
291 struct ieee80211_radiotap_he he = {};
292 struct ieee80211_radiotap_he_mu he_mu = {};
293 struct ieee80211_radiotap_lsig lsig = {};
295 if (status->flag & RX_FLAG_RADIOTAP_HE) {
296 he = *(struct ieee80211_radiotap_he *)skb->data;
297 skb_pull(skb, sizeof(he));
298 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
301 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
302 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
303 skb_pull(skb, sizeof(he_mu));
306 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
307 lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
308 skb_pull(skb, sizeof(lsig));
311 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
312 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
313 /* rtap.len and rtap.pad are undone immediately */
314 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
318 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
321 rthdr = skb_push(skb, rtap_len);
322 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
323 it_present = &rthdr->it_present;
325 /* radiotap header, set always present flags */
326 rthdr->it_len = cpu_to_le16(rtap_len);
327 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
328 BIT(IEEE80211_RADIOTAP_CHANNEL) |
329 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
332 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
334 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
336 BIT(IEEE80211_RADIOTAP_EXT) |
337 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
338 put_unaligned_le32(it_present_val, it_present);
340 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
341 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
344 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
345 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
346 BIT(IEEE80211_RADIOTAP_EXT);
347 put_unaligned_le32(it_present_val, it_present);
349 it_present_val = rtap.present;
352 put_unaligned_le32(it_present_val, it_present);
354 pos = (void *)(it_present + 1);
356 /* the order of the following fields is important */
358 /* IEEE80211_RADIOTAP_TSFT */
359 if (ieee80211_have_rx_timestamp(status)) {
361 while ((pos - (u8 *)rthdr) & 7)
364 ieee80211_calculate_rx_timestamp(local, status,
367 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
371 /* IEEE80211_RADIOTAP_FLAGS */
372 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
373 *pos |= IEEE80211_RADIOTAP_F_FCS;
374 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
375 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
376 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
377 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
380 /* IEEE80211_RADIOTAP_RATE */
381 if (!rate || status->encoding != RX_ENC_LEGACY) {
383 * Without rate information don't add it. If we have,
384 * MCS information is a separate field in radiotap,
385 * added below. The byte here is needed as padding
386 * for the channel though, so initialise it to 0.
391 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
392 if (status->bw == RATE_INFO_BW_10)
394 else if (status->bw == RATE_INFO_BW_5)
396 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
400 /* IEEE80211_RADIOTAP_CHANNEL */
401 put_unaligned_le16(status->freq, pos);
403 if (status->bw == RATE_INFO_BW_10)
404 channel_flags |= IEEE80211_CHAN_HALF;
405 else if (status->bw == RATE_INFO_BW_5)
406 channel_flags |= IEEE80211_CHAN_QUARTER;
408 if (status->band == NL80211_BAND_5GHZ)
409 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
410 else if (status->encoding != RX_ENC_LEGACY)
411 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
412 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
413 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
415 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
417 channel_flags |= IEEE80211_CHAN_2GHZ;
418 put_unaligned_le16(channel_flags, pos);
421 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
422 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
423 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
424 *pos = status->signal;
426 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
430 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
432 if (!status->chains) {
433 /* IEEE80211_RADIOTAP_ANTENNA */
434 *pos = status->antenna;
438 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
440 /* IEEE80211_RADIOTAP_RX_FLAGS */
441 /* ensure 2 byte alignment for the 2 byte field as required */
442 if ((pos - (u8 *)rthdr) & 1)
444 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
445 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
446 put_unaligned_le16(rx_flags, pos);
449 if (status->encoding == RX_ENC_HT) {
452 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
453 *pos++ = local->hw.radiotap_mcs_details;
455 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
456 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
457 if (status->bw == RATE_INFO_BW_40)
458 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
459 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
460 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
461 if (status->enc_flags & RX_ENC_FLAG_LDPC)
462 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
463 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
464 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
466 *pos++ = status->rate_idx;
469 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
472 /* ensure 4 byte alignment */
473 while ((pos - (u8 *)rthdr) & 3)
476 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
477 put_unaligned_le32(status->ampdu_reference, pos);
479 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
480 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
481 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
482 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
483 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
484 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
485 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
486 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
487 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
488 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
489 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
490 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
491 put_unaligned_le16(flags, pos);
493 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
494 *pos++ = status->ampdu_delimiter_crc;
500 if (status->encoding == RX_ENC_VHT) {
501 u16 known = local->hw.radiotap_vht_details;
503 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
504 put_unaligned_le16(known, pos);
507 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
508 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
509 /* in VHT, STBC is binary */
510 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
511 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
512 if (status->enc_flags & RX_ENC_FLAG_BF)
513 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
516 switch (status->bw) {
517 case RATE_INFO_BW_80:
520 case RATE_INFO_BW_160:
523 case RATE_INFO_BW_40:
530 *pos = (status->rate_idx << 4) | status->nss;
533 if (status->enc_flags & RX_ENC_FLAG_LDPC)
534 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
542 if (local->hw.radiotap_timestamp.units_pos >= 0) {
544 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
547 cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP);
549 /* ensure 8 byte alignment */
550 while ((pos - (u8 *)rthdr) & 7)
553 put_unaligned_le64(status->device_timestamp, pos);
556 if (local->hw.radiotap_timestamp.accuracy >= 0) {
557 accuracy = local->hw.radiotap_timestamp.accuracy;
558 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
560 put_unaligned_le16(accuracy, pos);
563 *pos++ = local->hw.radiotap_timestamp.units_pos;
567 if (status->encoding == RX_ENC_HE &&
568 status->flag & RX_FLAG_RADIOTAP_HE) {
569 #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
571 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
572 he.data6 |= HE_PREP(DATA6_NSTS,
573 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
575 he.data3 |= HE_PREP(DATA3_STBC, 1);
577 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
580 #define CHECK_GI(s) \
581 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
582 (int)NL80211_RATE_INFO_HE_GI_##s)
588 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
589 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
590 he.data3 |= HE_PREP(DATA3_CODING,
591 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
593 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
595 switch (status->bw) {
596 case RATE_INFO_BW_20:
597 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
598 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
600 case RATE_INFO_BW_40:
601 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
602 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
604 case RATE_INFO_BW_80:
605 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
606 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
608 case RATE_INFO_BW_160:
609 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
610 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
612 case RATE_INFO_BW_HE_RU:
613 #define CHECK_RU_ALLOC(s) \
614 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
615 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
623 CHECK_RU_ALLOC(2x996);
625 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
629 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
632 /* ensure 2 byte alignment */
633 while ((pos - (u8 *)rthdr) & 1)
635 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE);
636 memcpy(pos, &he, sizeof(he));
640 if (status->encoding == RX_ENC_HE &&
641 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
642 /* ensure 2 byte alignment */
643 while ((pos - (u8 *)rthdr) & 1)
645 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU);
646 memcpy(pos, &he_mu, sizeof(he_mu));
647 pos += sizeof(he_mu);
650 if (status->flag & RX_FLAG_NO_PSDU) {
652 cpu_to_le32(1 << IEEE80211_RADIOTAP_ZERO_LEN_PSDU);
653 *pos++ = status->zero_length_psdu_type;
656 if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
657 /* ensure 2 byte alignment */
658 while ((pos - (u8 *)rthdr) & 1)
660 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_LSIG);
661 memcpy(pos, &lsig, sizeof(lsig));
665 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
666 *pos++ = status->chain_signal[chain];
670 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
671 /* ensure 2 byte alignment for the vendor field as required */
672 if ((pos - (u8 *)rthdr) & 1)
674 *pos++ = rtap.oui[0];
675 *pos++ = rtap.oui[1];
676 *pos++ = rtap.oui[2];
678 put_unaligned_le16(rtap.len, pos);
680 /* align the actual payload as requested */
681 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
683 /* data (and possible padding) already follows */
687 static struct sk_buff *
688 ieee80211_make_monitor_skb(struct ieee80211_local *local,
689 struct sk_buff **origskb,
690 struct ieee80211_rate *rate,
691 int rtap_space, bool use_origskb)
693 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
694 int rt_hdrlen, needed_headroom;
697 /* room for the radiotap header based on driver features */
698 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
699 needed_headroom = rt_hdrlen - rtap_space;
702 /* only need to expand headroom if necessary */
707 * This shouldn't trigger often because most devices have an
708 * RX header they pull before we get here, and that should
709 * be big enough for our radiotap information. We should
710 * probably export the length to drivers so that we can have
711 * them allocate enough headroom to start with.
713 if (skb_headroom(skb) < needed_headroom &&
714 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
720 * Need to make a copy and possibly remove radiotap header
721 * and FCS from the original.
723 skb = skb_copy_expand(*origskb, needed_headroom, 0, GFP_ATOMIC);
729 /* prepend radiotap information */
730 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
732 skb_reset_mac_header(skb);
733 skb->ip_summed = CHECKSUM_UNNECESSARY;
734 skb->pkt_type = PACKET_OTHERHOST;
735 skb->protocol = htons(ETH_P_802_2);
741 * This function copies a received frame to all monitor interfaces and
742 * returns a cleaned-up SKB that no longer includes the FCS nor the
743 * radiotap header the driver might have added.
745 static struct sk_buff *
746 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
747 struct ieee80211_rate *rate)
749 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
750 struct ieee80211_sub_if_data *sdata;
751 struct sk_buff *monskb = NULL;
752 int present_fcs_len = 0;
753 unsigned int rtap_space = 0;
754 struct ieee80211_sub_if_data *monitor_sdata =
755 rcu_dereference(local->monitor_sdata);
756 bool only_monitor = false;
757 unsigned int min_head_len;
759 if (status->flag & RX_FLAG_RADIOTAP_HE)
760 rtap_space += sizeof(struct ieee80211_radiotap_he);
762 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
763 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
765 if (status->flag & RX_FLAG_RADIOTAP_LSIG)
766 rtap_space += sizeof(struct ieee80211_radiotap_lsig);
768 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
769 struct ieee80211_vendor_radiotap *rtap =
770 (void *)(origskb->data + rtap_space);
772 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
775 min_head_len = rtap_space;
778 * First, we may need to make a copy of the skb because
779 * (1) we need to modify it for radiotap (if not present), and
780 * (2) the other RX handlers will modify the skb we got.
782 * We don't need to, of course, if we aren't going to return
783 * the SKB because it has a bad FCS/PLCP checksum.
786 if (!(status->flag & RX_FLAG_NO_PSDU)) {
787 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
788 if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
791 dev_kfree_skb(origskb);
794 present_fcs_len = FCS_LEN;
797 /* also consider the hdr->frame_control */
801 /* ensure that the expected data elements are in skb head */
802 if (!pskb_may_pull(origskb, min_head_len)) {
803 dev_kfree_skb(origskb);
807 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
809 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
811 dev_kfree_skb(origskb);
815 remove_monitor_info(origskb, present_fcs_len, rtap_space);
819 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
821 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
822 bool last_monitor = list_is_last(&sdata->u.mntr.list,
826 monskb = ieee80211_make_monitor_skb(local, &origskb,
838 skb = skb_clone(monskb, GFP_ATOMIC);
842 skb->dev = sdata->dev;
843 ieee80211_rx_stats(skb->dev, skb->len);
844 netif_receive_skb(skb);
852 /* this happens if last_monitor was erroneously false */
853 dev_kfree_skb(monskb);
859 remove_monitor_info(origskb, present_fcs_len, rtap_space);
863 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
865 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
866 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
867 int tid, seqno_idx, security_idx;
869 /* does the frame have a qos control field? */
870 if (ieee80211_is_data_qos(hdr->frame_control)) {
871 u8 *qc = ieee80211_get_qos_ctl(hdr);
872 /* frame has qos control */
873 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
874 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
875 status->rx_flags |= IEEE80211_RX_AMSDU;
881 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
883 * Sequence numbers for management frames, QoS data
884 * frames with a broadcast/multicast address in the
885 * Address 1 field, and all non-QoS data frames sent
886 * by QoS STAs are assigned using an additional single
887 * modulo-4096 counter, [...]
889 * We also use that counter for non-QoS STAs.
891 seqno_idx = IEEE80211_NUM_TIDS;
893 if (ieee80211_is_mgmt(hdr->frame_control))
894 security_idx = IEEE80211_NUM_TIDS;
898 rx->seqno_idx = seqno_idx;
899 rx->security_idx = security_idx;
900 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
901 * For now, set skb->priority to 0 for other cases. */
902 rx->skb->priority = (tid > 7) ? 0 : tid;
906 * DOC: Packet alignment
908 * Drivers always need to pass packets that are aligned to two-byte boundaries
911 * Additionally, should, if possible, align the payload data in a way that
912 * guarantees that the contained IP header is aligned to a four-byte
913 * boundary. In the case of regular frames, this simply means aligning the
914 * payload to a four-byte boundary (because either the IP header is directly
915 * contained, or IV/RFC1042 headers that have a length divisible by four are
916 * in front of it). If the payload data is not properly aligned and the
917 * architecture doesn't support efficient unaligned operations, mac80211
918 * will align the data.
920 * With A-MSDU frames, however, the payload data address must yield two modulo
921 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
922 * push the IP header further back to a multiple of four again. Thankfully, the
923 * specs were sane enough this time around to require padding each A-MSDU
924 * subframe to a length that is a multiple of four.
926 * Padding like Atheros hardware adds which is between the 802.11 header and
927 * the payload is not supported, the driver is required to move the 802.11
928 * header to be directly in front of the payload in that case.
930 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
932 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
933 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
940 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
942 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
944 if (is_multicast_ether_addr(hdr->addr1))
947 return ieee80211_is_robust_mgmt_frame(skb);
951 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
953 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
955 if (!is_multicast_ether_addr(hdr->addr1))
958 return ieee80211_is_robust_mgmt_frame(skb);
962 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
963 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
965 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
966 struct ieee80211_mmie *mmie;
967 struct ieee80211_mmie_16 *mmie16;
969 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
972 if (!ieee80211_is_robust_mgmt_frame(skb))
973 return -1; /* not a robust management frame */
975 mmie = (struct ieee80211_mmie *)
976 (skb->data + skb->len - sizeof(*mmie));
977 if (mmie->element_id == WLAN_EID_MMIE &&
978 mmie->length == sizeof(*mmie) - 2)
979 return le16_to_cpu(mmie->key_id);
981 mmie16 = (struct ieee80211_mmie_16 *)
982 (skb->data + skb->len - sizeof(*mmie16));
983 if (skb->len >= 24 + sizeof(*mmie16) &&
984 mmie16->element_id == WLAN_EID_MMIE &&
985 mmie16->length == sizeof(*mmie16) - 2)
986 return le16_to_cpu(mmie16->key_id);
991 static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
994 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
999 fc = hdr->frame_control;
1000 hdrlen = ieee80211_hdrlen(fc);
1002 if (skb->len < hdrlen + cs->hdr_len)
1005 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
1006 keyid &= cs->key_idx_mask;
1007 keyid >>= cs->key_idx_shift;
1012 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1014 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1015 char *dev_addr = rx->sdata->vif.addr;
1017 if (ieee80211_is_data(hdr->frame_control)) {
1018 if (is_multicast_ether_addr(hdr->addr1)) {
1019 if (ieee80211_has_tods(hdr->frame_control) ||
1020 !ieee80211_has_fromds(hdr->frame_control))
1021 return RX_DROP_MONITOR;
1022 if (ether_addr_equal(hdr->addr3, dev_addr))
1023 return RX_DROP_MONITOR;
1025 if (!ieee80211_has_a4(hdr->frame_control))
1026 return RX_DROP_MONITOR;
1027 if (ether_addr_equal(hdr->addr4, dev_addr))
1028 return RX_DROP_MONITOR;
1032 /* If there is not an established peer link and this is not a peer link
1033 * establisment frame, beacon or probe, drop the frame.
1036 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1037 struct ieee80211_mgmt *mgmt;
1039 if (!ieee80211_is_mgmt(hdr->frame_control))
1040 return RX_DROP_MONITOR;
1042 if (ieee80211_is_action(hdr->frame_control)) {
1045 /* make sure category field is present */
1046 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1047 return RX_DROP_MONITOR;
1049 mgmt = (struct ieee80211_mgmt *)hdr;
1050 category = mgmt->u.action.category;
1051 if (category != WLAN_CATEGORY_MESH_ACTION &&
1052 category != WLAN_CATEGORY_SELF_PROTECTED)
1053 return RX_DROP_MONITOR;
1057 if (ieee80211_is_probe_req(hdr->frame_control) ||
1058 ieee80211_is_probe_resp(hdr->frame_control) ||
1059 ieee80211_is_beacon(hdr->frame_control) ||
1060 ieee80211_is_auth(hdr->frame_control))
1063 return RX_DROP_MONITOR;
1069 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1072 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1073 struct sk_buff *tail = skb_peek_tail(frames);
1074 struct ieee80211_rx_status *status;
1076 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1082 status = IEEE80211_SKB_RXCB(tail);
1083 if (status->flag & RX_FLAG_AMSDU_MORE)
1089 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1090 struct tid_ampdu_rx *tid_agg_rx,
1092 struct sk_buff_head *frames)
1094 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1095 struct sk_buff *skb;
1096 struct ieee80211_rx_status *status;
1098 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1100 if (skb_queue_empty(skb_list))
1103 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1104 __skb_queue_purge(skb_list);
1108 /* release frames from the reorder ring buffer */
1109 tid_agg_rx->stored_mpdu_num--;
1110 while ((skb = __skb_dequeue(skb_list))) {
1111 status = IEEE80211_SKB_RXCB(skb);
1112 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1113 __skb_queue_tail(frames, skb);
1117 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1118 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1121 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1122 struct tid_ampdu_rx *tid_agg_rx,
1124 struct sk_buff_head *frames)
1128 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1130 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1131 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1132 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1138 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1139 * the skb was added to the buffer longer than this time ago, the earlier
1140 * frames that have not yet been received are assumed to be lost and the skb
1141 * can be released for processing. This may also release other skb's from the
1142 * reorder buffer if there are no additional gaps between the frames.
1144 * Callers must hold tid_agg_rx->reorder_lock.
1146 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1148 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1149 struct tid_ampdu_rx *tid_agg_rx,
1150 struct sk_buff_head *frames)
1154 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1156 /* release the buffer until next missing frame */
1157 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1158 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1159 tid_agg_rx->stored_mpdu_num) {
1161 * No buffers ready to be released, but check whether any
1162 * frames in the reorder buffer have timed out.
1165 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1166 j = (j + 1) % tid_agg_rx->buf_size) {
1167 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1172 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1173 HT_RX_REORDER_BUF_TIMEOUT))
1174 goto set_release_timer;
1176 /* don't leave incomplete A-MSDUs around */
1177 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1178 i = (i + 1) % tid_agg_rx->buf_size)
1179 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1181 ht_dbg_ratelimited(sdata,
1182 "release an RX reorder frame due to timeout on earlier frames\n");
1183 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1187 * Increment the head seq# also for the skipped slots.
1189 tid_agg_rx->head_seq_num =
1190 (tid_agg_rx->head_seq_num +
1191 skipped) & IEEE80211_SN_MASK;
1194 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1195 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1197 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1200 if (tid_agg_rx->stored_mpdu_num) {
1201 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1203 for (; j != (index - 1) % tid_agg_rx->buf_size;
1204 j = (j + 1) % tid_agg_rx->buf_size) {
1205 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1211 if (!tid_agg_rx->removed)
1212 mod_timer(&tid_agg_rx->reorder_timer,
1213 tid_agg_rx->reorder_time[j] + 1 +
1214 HT_RX_REORDER_BUF_TIMEOUT);
1216 del_timer(&tid_agg_rx->reorder_timer);
1221 * As this function belongs to the RX path it must be under
1222 * rcu_read_lock protection. It returns false if the frame
1223 * can be processed immediately, true if it was consumed.
1225 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1226 struct tid_ampdu_rx *tid_agg_rx,
1227 struct sk_buff *skb,
1228 struct sk_buff_head *frames)
1230 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1231 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1232 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1233 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1234 u16 head_seq_num, buf_size;
1238 spin_lock(&tid_agg_rx->reorder_lock);
1241 * Offloaded BA sessions have no known starting sequence number so pick
1242 * one from first Rxed frame for this tid after BA was started.
1244 if (unlikely(tid_agg_rx->auto_seq)) {
1245 tid_agg_rx->auto_seq = false;
1246 tid_agg_rx->ssn = mpdu_seq_num;
1247 tid_agg_rx->head_seq_num = mpdu_seq_num;
1250 buf_size = tid_agg_rx->buf_size;
1251 head_seq_num = tid_agg_rx->head_seq_num;
1254 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1257 if (unlikely(!tid_agg_rx->started)) {
1258 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1262 tid_agg_rx->started = true;
1265 /* frame with out of date sequence number */
1266 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1272 * If frame the sequence number exceeds our buffering window
1273 * size release some previous frames to make room for this one.
1275 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1276 head_seq_num = ieee80211_sn_inc(
1277 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1278 /* release stored frames up to new head to stack */
1279 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1280 head_seq_num, frames);
1283 /* Now the new frame is always in the range of the reordering buffer */
1285 index = mpdu_seq_num % tid_agg_rx->buf_size;
1287 /* check if we already stored this frame */
1288 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1294 * If the current MPDU is in the right order and nothing else
1295 * is stored we can process it directly, no need to buffer it.
1296 * If it is first but there's something stored, we may be able
1297 * to release frames after this one.
1299 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1300 tid_agg_rx->stored_mpdu_num == 0) {
1301 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1302 tid_agg_rx->head_seq_num =
1303 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1308 /* put the frame in the reordering buffer */
1309 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1310 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1311 tid_agg_rx->reorder_time[index] = jiffies;
1312 tid_agg_rx->stored_mpdu_num++;
1313 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1317 spin_unlock(&tid_agg_rx->reorder_lock);
1322 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1323 * true if the MPDU was buffered, false if it should be processed.
1325 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1326 struct sk_buff_head *frames)
1328 struct sk_buff *skb = rx->skb;
1329 struct ieee80211_local *local = rx->local;
1330 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1331 struct sta_info *sta = rx->sta;
1332 struct tid_ampdu_rx *tid_agg_rx;
1336 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1337 is_multicast_ether_addr(hdr->addr1))
1341 * filter the QoS data rx stream according to
1342 * STA/TID and check if this STA/TID is on aggregation
1348 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1349 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1350 tid = ieee80211_get_tid(hdr);
1352 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1354 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1355 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1356 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1357 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1358 WLAN_BACK_RECIPIENT,
1359 WLAN_REASON_QSTA_REQUIRE_SETUP);
1363 /* qos null data frames are excluded */
1364 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1367 /* not part of a BA session */
1368 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1369 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1372 /* new, potentially un-ordered, ampdu frame - process it */
1374 /* reset session timer */
1375 if (tid_agg_rx->timeout)
1376 tid_agg_rx->last_rx = jiffies;
1378 /* if this mpdu is fragmented - terminate rx aggregation session */
1379 sc = le16_to_cpu(hdr->seq_ctrl);
1380 if (sc & IEEE80211_SCTL_FRAG) {
1381 skb_queue_tail(&rx->sdata->skb_queue, skb);
1382 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1387 * No locking needed -- we will only ever process one
1388 * RX packet at a time, and thus own tid_agg_rx. All
1389 * other code manipulating it needs to (and does) make
1390 * sure that we cannot get to it any more before doing
1393 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1398 __skb_queue_tail(frames, skb);
1401 static ieee80211_rx_result debug_noinline
1402 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1404 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1405 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1407 if (status->flag & RX_FLAG_DUP_VALIDATED)
1411 * Drop duplicate 802.11 retransmissions
1412 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1415 if (rx->skb->len < 24)
1418 if (ieee80211_is_ctl(hdr->frame_control) ||
1419 ieee80211_is_nullfunc(hdr->frame_control) ||
1420 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
1421 is_multicast_ether_addr(hdr->addr1))
1427 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1428 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1429 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1430 rx->sta->rx_stats.num_duplicates++;
1431 return RX_DROP_UNUSABLE;
1432 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1433 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1439 static ieee80211_rx_result debug_noinline
1440 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1442 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1444 /* Drop disallowed frame classes based on STA auth/assoc state;
1445 * IEEE 802.11, Chap 5.5.
1447 * mac80211 filters only based on association state, i.e. it drops
1448 * Class 3 frames from not associated stations. hostapd sends
1449 * deauth/disassoc frames when needed. In addition, hostapd is
1450 * responsible for filtering on both auth and assoc states.
1453 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1454 return ieee80211_rx_mesh_check(rx);
1456 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1457 ieee80211_is_pspoll(hdr->frame_control)) &&
1458 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1459 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1460 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1461 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1463 * accept port control frames from the AP even when it's not
1464 * yet marked ASSOC to prevent a race where we don't set the
1465 * assoc bit quickly enough before it sends the first frame
1467 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1468 ieee80211_is_data_present(hdr->frame_control)) {
1469 unsigned int hdrlen;
1472 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1474 if (rx->skb->len < hdrlen + 8)
1475 return RX_DROP_MONITOR;
1477 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1478 if (ethertype == rx->sdata->control_port_protocol)
1482 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1483 cfg80211_rx_spurious_frame(rx->sdata->dev,
1486 return RX_DROP_UNUSABLE;
1488 return RX_DROP_MONITOR;
1495 static ieee80211_rx_result debug_noinline
1496 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1498 struct ieee80211_local *local;
1499 struct ieee80211_hdr *hdr;
1500 struct sk_buff *skb;
1504 hdr = (struct ieee80211_hdr *) skb->data;
1506 if (!local->pspolling)
1509 if (!ieee80211_has_fromds(hdr->frame_control))
1510 /* this is not from AP */
1513 if (!ieee80211_is_data(hdr->frame_control))
1516 if (!ieee80211_has_moredata(hdr->frame_control)) {
1517 /* AP has no more frames buffered for us */
1518 local->pspolling = false;
1522 /* more data bit is set, let's request a new frame from the AP */
1523 ieee80211_send_pspoll(local, rx->sdata);
1528 static void sta_ps_start(struct sta_info *sta)
1530 struct ieee80211_sub_if_data *sdata = sta->sdata;
1531 struct ieee80211_local *local = sdata->local;
1535 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1536 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1537 ps = &sdata->bss->ps;
1541 atomic_inc(&ps->num_sta_ps);
1542 set_sta_flag(sta, WLAN_STA_PS_STA);
1543 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1544 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1545 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1546 sta->sta.addr, sta->sta.aid);
1548 ieee80211_clear_fast_xmit(sta);
1550 if (!sta->sta.txq[0])
1553 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1554 if (txq_has_queue(sta->sta.txq[tid]))
1555 set_bit(tid, &sta->txq_buffered_tids);
1557 clear_bit(tid, &sta->txq_buffered_tids);
1561 static void sta_ps_end(struct sta_info *sta)
1563 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1564 sta->sta.addr, sta->sta.aid);
1566 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1568 * Clear the flag only if the other one is still set
1569 * so that the TX path won't start TX'ing new frames
1570 * directly ... In the case that the driver flag isn't
1571 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1573 clear_sta_flag(sta, WLAN_STA_PS_STA);
1574 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1575 sta->sta.addr, sta->sta.aid);
1579 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1580 clear_sta_flag(sta, WLAN_STA_PS_STA);
1581 ieee80211_sta_ps_deliver_wakeup(sta);
1584 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1586 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1589 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1591 /* Don't let the same PS state be set twice */
1592 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1593 if ((start && in_ps) || (!start && !in_ps))
1603 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1605 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1607 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1609 if (test_sta_flag(sta, WLAN_STA_SP))
1612 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1613 ieee80211_sta_ps_deliver_poll_response(sta);
1615 set_sta_flag(sta, WLAN_STA_PSPOLL);
1617 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1619 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1621 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1622 int ac = ieee80211_ac_from_tid(tid);
1625 * If this AC is not trigger-enabled do nothing unless the
1626 * driver is calling us after it already checked.
1628 * NB: This could/should check a separate bitmap of trigger-
1629 * enabled queues, but for now we only implement uAPSD w/o
1630 * TSPEC changes to the ACs, so they're always the same.
1632 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1633 tid != IEEE80211_NUM_TIDS)
1636 /* if we are in a service period, do nothing */
1637 if (test_sta_flag(sta, WLAN_STA_SP))
1640 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1641 ieee80211_sta_ps_deliver_uapsd(sta);
1643 set_sta_flag(sta, WLAN_STA_UAPSD);
1645 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1647 static ieee80211_rx_result debug_noinline
1648 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1650 struct ieee80211_sub_if_data *sdata = rx->sdata;
1651 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1652 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1657 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1658 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1662 * The device handles station powersave, so don't do anything about
1663 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1664 * it to mac80211 since they're handled.)
1666 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1670 * Don't do anything if the station isn't already asleep. In
1671 * the uAPSD case, the station will probably be marked asleep,
1672 * in the PS-Poll case the station must be confused ...
1674 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1677 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1678 ieee80211_sta_pspoll(&rx->sta->sta);
1680 /* Free PS Poll skb here instead of returning RX_DROP that would
1681 * count as an dropped frame. */
1682 dev_kfree_skb(rx->skb);
1685 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1686 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1687 ieee80211_has_pm(hdr->frame_control) &&
1688 (ieee80211_is_data_qos(hdr->frame_control) ||
1689 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1690 u8 tid = ieee80211_get_tid(hdr);
1692 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1698 static ieee80211_rx_result debug_noinline
1699 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1701 struct sta_info *sta = rx->sta;
1702 struct sk_buff *skb = rx->skb;
1703 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1704 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1711 * Update last_rx only for IBSS packets which are for the current
1712 * BSSID and for station already AUTHORIZED to avoid keeping the
1713 * current IBSS network alive in cases where other STAs start
1714 * using different BSSID. This will also give the station another
1715 * chance to restart the authentication/authorization in case
1716 * something went wrong the first time.
1718 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1719 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1720 NL80211_IFTYPE_ADHOC);
1721 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1722 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1723 sta->rx_stats.last_rx = jiffies;
1724 if (ieee80211_is_data(hdr->frame_control) &&
1725 !is_multicast_ether_addr(hdr->addr1))
1726 sta->rx_stats.last_rate =
1727 sta_stats_encode_rate(status);
1729 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1730 sta->rx_stats.last_rx = jiffies;
1731 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1733 * Mesh beacons will update last_rx when if they are found to
1734 * match the current local configuration when processed.
1736 sta->rx_stats.last_rx = jiffies;
1737 if (ieee80211_is_data(hdr->frame_control))
1738 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1741 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1742 ieee80211_sta_rx_notify(rx->sdata, hdr);
1744 sta->rx_stats.fragments++;
1746 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1747 sta->rx_stats.bytes += rx->skb->len;
1748 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1750 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1751 sta->rx_stats.last_signal = status->signal;
1752 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1755 if (status->chains) {
1756 sta->rx_stats.chains = status->chains;
1757 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1758 int signal = status->chain_signal[i];
1760 if (!(status->chains & BIT(i)))
1763 sta->rx_stats.chain_signal_last[i] = signal;
1764 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1770 * Change STA power saving mode only at the end of a frame
1771 * exchange sequence, and only for a data or management
1772 * frame as specified in IEEE 802.11-2016 11.2.3.2
1774 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1775 !ieee80211_has_morefrags(hdr->frame_control) &&
1776 !is_multicast_ether_addr(hdr->addr1) &&
1777 (ieee80211_is_mgmt(hdr->frame_control) ||
1778 ieee80211_is_data(hdr->frame_control)) &&
1779 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1780 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1781 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1782 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1783 if (!ieee80211_has_pm(hdr->frame_control))
1786 if (ieee80211_has_pm(hdr->frame_control))
1791 /* mesh power save support */
1792 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1793 ieee80211_mps_rx_h_sta_process(sta, hdr);
1796 * Drop (qos-)data::nullfunc frames silently, since they
1797 * are used only to control station power saving mode.
1799 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1800 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1801 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1804 * If we receive a 4-addr nullfunc frame from a STA
1805 * that was not moved to a 4-addr STA vlan yet send
1806 * the event to userspace and for older hostapd drop
1807 * the frame to the monitor interface.
1809 if (ieee80211_has_a4(hdr->frame_control) &&
1810 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1811 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1812 !rx->sdata->u.vlan.sta))) {
1813 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1814 cfg80211_rx_unexpected_4addr_frame(
1815 rx->sdata->dev, sta->sta.addr,
1817 return RX_DROP_MONITOR;
1820 * Update counter and free packet here to avoid
1821 * counting this as a dropped packed.
1823 sta->rx_stats.packets++;
1824 dev_kfree_skb(rx->skb);
1829 } /* ieee80211_rx_h_sta_process */
1831 static ieee80211_rx_result debug_noinline
1832 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1834 struct sk_buff *skb = rx->skb;
1835 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1836 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1839 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1840 struct ieee80211_key *sta_ptk = NULL;
1841 int mmie_keyidx = -1;
1843 const struct ieee80211_cipher_scheme *cs = NULL;
1848 * There are four types of keys:
1849 * - GTK (group keys)
1850 * - IGTK (group keys for management frames)
1851 * - PTK (pairwise keys)
1852 * - STK (station-to-station pairwise keys)
1854 * When selecting a key, we have to distinguish between multicast
1855 * (including broadcast) and unicast frames, the latter can only
1856 * use PTKs and STKs while the former always use GTKs and IGTKs.
1857 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1858 * unicast frames can also use key indices like GTKs. Hence, if we
1859 * don't have a PTK/STK we check the key index for a WEP key.
1861 * Note that in a regular BSS, multicast frames are sent by the
1862 * AP only, associated stations unicast the frame to the AP first
1863 * which then multicasts it on their behalf.
1865 * There is also a slight problem in IBSS mode: GTKs are negotiated
1866 * with each station, that is something we don't currently handle.
1867 * The spec seems to expect that one negotiates the same key with
1868 * every station but there's no such requirement; VLANs could be
1872 /* start without a key */
1874 fc = hdr->frame_control;
1877 int keyid = rx->sta->ptk_idx;
1879 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1880 cs = rx->sta->cipher_scheme;
1881 keyid = ieee80211_get_cs_keyid(cs, rx->skb);
1882 if (unlikely(keyid < 0))
1883 return RX_DROP_UNUSABLE;
1885 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1888 if (!ieee80211_has_protected(fc))
1889 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1891 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1893 if ((status->flag & RX_FLAG_DECRYPTED) &&
1894 (status->flag & RX_FLAG_IV_STRIPPED))
1896 /* Skip decryption if the frame is not protected. */
1897 if (!ieee80211_has_protected(fc))
1899 } else if (mmie_keyidx >= 0) {
1900 /* Broadcast/multicast robust management frame / BIP */
1901 if ((status->flag & RX_FLAG_DECRYPTED) &&
1902 (status->flag & RX_FLAG_IV_STRIPPED))
1905 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1906 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1907 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1909 if (ieee80211_is_group_privacy_action(skb) &&
1910 test_sta_flag(rx->sta, WLAN_STA_MFP))
1911 return RX_DROP_MONITOR;
1913 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1916 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1917 } else if (!ieee80211_has_protected(fc)) {
1919 * The frame was not protected, so skip decryption. However, we
1920 * need to set rx->key if there is a key that could have been
1921 * used so that the frame may be dropped if encryption would
1922 * have been expected.
1924 struct ieee80211_key *key = NULL;
1925 struct ieee80211_sub_if_data *sdata = rx->sdata;
1928 if (ieee80211_is_mgmt(fc) &&
1929 is_multicast_ether_addr(hdr->addr1) &&
1930 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1934 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1935 key = rcu_dereference(rx->sta->gtk[i]);
1941 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1942 key = rcu_dereference(sdata->keys[i]);
1955 * The device doesn't give us the IV so we won't be
1956 * able to look up the key. That's ok though, we
1957 * don't need to decrypt the frame, we just won't
1958 * be able to keep statistics accurate.
1959 * Except for key threshold notifications, should
1960 * we somehow allow the driver to tell us which key
1961 * the hardware used if this flag is set?
1963 if ((status->flag & RX_FLAG_DECRYPTED) &&
1964 (status->flag & RX_FLAG_IV_STRIPPED))
1967 hdrlen = ieee80211_hdrlen(fc);
1970 keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
1972 if (unlikely(keyidx < 0))
1973 return RX_DROP_UNUSABLE;
1975 if (rx->skb->len < 8 + hdrlen)
1976 return RX_DROP_UNUSABLE; /* TODO: count this? */
1978 * no need to call ieee80211_wep_get_keyidx,
1979 * it verifies a bunch of things we've done already
1981 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1982 keyidx = keyid >> 6;
1985 /* check per-station GTK first, if multicast packet */
1986 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1987 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1989 /* if not found, try default key */
1991 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1994 * RSNA-protected unicast frames should always be
1995 * sent with pairwise or station-to-station keys,
1996 * but for WEP we allow using a key index as well.
1999 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2000 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2001 !is_multicast_ether_addr(hdr->addr1))
2007 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2008 return RX_DROP_MONITOR;
2010 /* TODO: add threshold stuff again */
2012 return RX_DROP_MONITOR;
2015 switch (rx->key->conf.cipher) {
2016 case WLAN_CIPHER_SUITE_WEP40:
2017 case WLAN_CIPHER_SUITE_WEP104:
2018 result = ieee80211_crypto_wep_decrypt(rx);
2020 case WLAN_CIPHER_SUITE_TKIP:
2021 result = ieee80211_crypto_tkip_decrypt(rx);
2023 case WLAN_CIPHER_SUITE_CCMP:
2024 result = ieee80211_crypto_ccmp_decrypt(
2025 rx, IEEE80211_CCMP_MIC_LEN);
2027 case WLAN_CIPHER_SUITE_CCMP_256:
2028 result = ieee80211_crypto_ccmp_decrypt(
2029 rx, IEEE80211_CCMP_256_MIC_LEN);
2031 case WLAN_CIPHER_SUITE_AES_CMAC:
2032 result = ieee80211_crypto_aes_cmac_decrypt(rx);
2034 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2035 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2037 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2038 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2039 result = ieee80211_crypto_aes_gmac_decrypt(rx);
2041 case WLAN_CIPHER_SUITE_GCMP:
2042 case WLAN_CIPHER_SUITE_GCMP_256:
2043 result = ieee80211_crypto_gcmp_decrypt(rx);
2046 result = ieee80211_crypto_hw_decrypt(rx);
2049 /* the hdr variable is invalid after the decrypt handlers */
2051 /* either the frame has been decrypted or will be dropped */
2052 status->flag |= RX_FLAG_DECRYPTED;
2057 static inline struct ieee80211_fragment_entry *
2058 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
2059 unsigned int frag, unsigned int seq, int rx_queue,
2060 struct sk_buff **skb)
2062 struct ieee80211_fragment_entry *entry;
2064 entry = &sdata->fragments[sdata->fragment_next++];
2065 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
2066 sdata->fragment_next = 0;
2068 if (!skb_queue_empty(&entry->skb_list))
2069 __skb_queue_purge(&entry->skb_list);
2071 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2073 entry->first_frag_time = jiffies;
2075 entry->rx_queue = rx_queue;
2076 entry->last_frag = frag;
2077 entry->check_sequential_pn = false;
2078 entry->extra_len = 0;
2083 static inline struct ieee80211_fragment_entry *
2084 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
2085 unsigned int frag, unsigned int seq,
2086 int rx_queue, struct ieee80211_hdr *hdr)
2088 struct ieee80211_fragment_entry *entry;
2091 idx = sdata->fragment_next;
2092 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2093 struct ieee80211_hdr *f_hdr;
2094 struct sk_buff *f_skb;
2098 idx = IEEE80211_FRAGMENT_MAX - 1;
2100 entry = &sdata->fragments[idx];
2101 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2102 entry->rx_queue != rx_queue ||
2103 entry->last_frag + 1 != frag)
2106 f_skb = __skb_peek(&entry->skb_list);
2107 f_hdr = (struct ieee80211_hdr *) f_skb->data;
2110 * Check ftype and addresses are equal, else check next fragment
2112 if (((hdr->frame_control ^ f_hdr->frame_control) &
2113 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2114 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2115 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2118 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2119 __skb_queue_purge(&entry->skb_list);
2128 static ieee80211_rx_result debug_noinline
2129 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2131 struct ieee80211_hdr *hdr;
2134 unsigned int frag, seq;
2135 struct ieee80211_fragment_entry *entry;
2136 struct sk_buff *skb;
2138 hdr = (struct ieee80211_hdr *)rx->skb->data;
2139 fc = hdr->frame_control;
2141 if (ieee80211_is_ctl(fc))
2144 sc = le16_to_cpu(hdr->seq_ctrl);
2145 frag = sc & IEEE80211_SCTL_FRAG;
2147 if (is_multicast_ether_addr(hdr->addr1)) {
2148 I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
2152 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2155 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2157 if (skb_linearize(rx->skb))
2158 return RX_DROP_UNUSABLE;
2161 * skb_linearize() might change the skb->data and
2162 * previously cached variables (in this case, hdr) need to
2163 * be refreshed with the new data.
2165 hdr = (struct ieee80211_hdr *)rx->skb->data;
2166 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2169 /* This is the first fragment of a new frame. */
2170 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
2171 rx->seqno_idx, &(rx->skb));
2173 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2174 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2175 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2176 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2177 ieee80211_has_protected(fc)) {
2178 int queue = rx->security_idx;
2180 /* Store CCMP/GCMP PN so that we can verify that the
2181 * next fragment has a sequential PN value.
2183 entry->check_sequential_pn = true;
2184 memcpy(entry->last_pn,
2185 rx->key->u.ccmp.rx_pn[queue],
2186 IEEE80211_CCMP_PN_LEN);
2187 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2189 offsetof(struct ieee80211_key,
2191 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2192 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2193 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2194 IEEE80211_GCMP_PN_LEN);
2199 /* This is a fragment for a frame that should already be pending in
2200 * fragment cache. Add this fragment to the end of the pending entry.
2202 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
2203 rx->seqno_idx, hdr);
2205 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2206 return RX_DROP_MONITOR;
2209 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2210 * MPDU PN values are not incrementing in steps of 1."
2211 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2212 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2214 if (entry->check_sequential_pn) {
2216 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2220 (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
2221 rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 &&
2222 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP &&
2223 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256))
2224 return RX_DROP_UNUSABLE;
2225 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2226 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2231 queue = rx->security_idx;
2232 rpn = rx->key->u.ccmp.rx_pn[queue];
2233 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2234 return RX_DROP_UNUSABLE;
2235 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2238 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2239 __skb_queue_tail(&entry->skb_list, rx->skb);
2240 entry->last_frag = frag;
2241 entry->extra_len += rx->skb->len;
2242 if (ieee80211_has_morefrags(fc)) {
2247 rx->skb = __skb_dequeue(&entry->skb_list);
2248 if (skb_tailroom(rx->skb) < entry->extra_len) {
2249 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2250 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2252 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2253 __skb_queue_purge(&entry->skb_list);
2254 return RX_DROP_UNUSABLE;
2257 while ((skb = __skb_dequeue(&entry->skb_list))) {
2258 skb_put_data(rx->skb, skb->data, skb->len);
2263 ieee80211_led_rx(rx->local);
2266 rx->sta->rx_stats.packets++;
2270 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2272 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2278 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2280 struct sk_buff *skb = rx->skb;
2281 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2284 * Pass through unencrypted frames if the hardware has
2285 * decrypted them already.
2287 if (status->flag & RX_FLAG_DECRYPTED)
2290 /* Drop unencrypted frames if key is set. */
2291 if (unlikely(!ieee80211_has_protected(fc) &&
2292 !ieee80211_is_nullfunc(fc) &&
2293 ieee80211_is_data(fc) && rx->key))
2299 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2301 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2302 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2303 __le16 fc = hdr->frame_control;
2306 * Pass through unencrypted frames if the hardware has
2307 * decrypted them already.
2309 if (status->flag & RX_FLAG_DECRYPTED)
2312 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2313 if (unlikely(!ieee80211_has_protected(fc) &&
2314 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2316 if (ieee80211_is_deauth(fc) ||
2317 ieee80211_is_disassoc(fc))
2318 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2323 /* BIP does not use Protected field, so need to check MMIE */
2324 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2325 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2326 if (ieee80211_is_deauth(fc) ||
2327 ieee80211_is_disassoc(fc))
2328 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2334 * When using MFP, Action frames are not allowed prior to
2335 * having configured keys.
2337 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2338 ieee80211_is_robust_mgmt_frame(rx->skb)))
2346 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2348 struct ieee80211_sub_if_data *sdata = rx->sdata;
2349 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2350 bool check_port_control = false;
2351 struct ethhdr *ehdr;
2354 *port_control = false;
2355 if (ieee80211_has_a4(hdr->frame_control) &&
2356 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2359 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2360 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2362 if (!sdata->u.mgd.use_4addr)
2364 else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2365 check_port_control = true;
2368 if (is_multicast_ether_addr(hdr->addr1) &&
2369 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2372 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2376 ehdr = (struct ethhdr *) rx->skb->data;
2377 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2378 *port_control = true;
2379 else if (check_port_control)
2386 * requires that rx->skb is a frame with ethernet header
2388 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2390 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2391 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2392 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2395 * Allow EAPOL frames to us/the PAE group address regardless
2396 * of whether the frame was encrypted or not.
2398 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
2399 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2400 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
2403 if (ieee80211_802_1x_port_control(rx) ||
2404 ieee80211_drop_unencrypted(rx, fc))
2410 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2411 struct ieee80211_rx_data *rx)
2413 struct ieee80211_sub_if_data *sdata = rx->sdata;
2414 struct net_device *dev = sdata->dev;
2416 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2417 skb->protocol == cpu_to_be16(ETH_P_PREAUTH)) &&
2418 sdata->control_port_over_nl80211)) {
2419 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2420 bool noencrypt = status->flag & RX_FLAG_DECRYPTED;
2422 cfg80211_rx_control_port(dev, skb, noencrypt);
2425 /* deliver to local stack */
2427 napi_gro_receive(rx->napi, skb);
2429 netif_receive_skb(skb);
2434 * requires that rx->skb is a frame with ethernet header
2437 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2439 struct ieee80211_sub_if_data *sdata = rx->sdata;
2440 struct net_device *dev = sdata->dev;
2441 struct sk_buff *skb, *xmit_skb;
2442 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2443 struct sta_info *dsta;
2448 ieee80211_rx_stats(dev, skb->len);
2451 /* The seqno index has the same property as needed
2452 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2453 * for non-QoS-data frames. Here we know it's a data
2454 * frame, so count MSDUs.
2456 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
2457 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2458 u64_stats_update_end(&rx->sta->rx_stats.syncp);
2461 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2462 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2463 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2464 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2465 if (is_multicast_ether_addr(ehdr->h_dest) &&
2466 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2468 * send multicast frames both to higher layers in
2469 * local net stack and back to the wireless medium
2471 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2473 net_info_ratelimited("%s: failed to clone multicast frame\n",
2475 } else if (!is_multicast_ether_addr(ehdr->h_dest) &&
2476 !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
2477 dsta = sta_info_get(sdata, ehdr->h_dest);
2480 * The destination station is associated to
2481 * this AP (in this VLAN), so send the frame
2482 * directly to it and do not pass it to local
2491 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2493 /* 'align' will only take the values 0 or 2 here since all
2494 * frames are required to be aligned to 2-byte boundaries
2495 * when being passed to mac80211; the code here works just
2496 * as well if that isn't true, but mac80211 assumes it can
2497 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2501 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2503 if (WARN_ON(skb_headroom(skb) < 3)) {
2507 u8 *data = skb->data;
2508 size_t len = skb_headlen(skb);
2510 memmove(skb->data, data, len);
2511 skb_set_tail_pointer(skb, len);
2518 skb->protocol = eth_type_trans(skb, dev);
2519 memset(skb->cb, 0, sizeof(skb->cb));
2521 ieee80211_deliver_skb_to_local_stack(skb, rx);
2526 * Send to wireless media and increase priority by 256 to
2527 * keep the received priority instead of reclassifying
2528 * the frame (see cfg80211_classify8021d).
2530 xmit_skb->priority += 256;
2531 xmit_skb->protocol = htons(ETH_P_802_3);
2532 skb_reset_network_header(xmit_skb);
2533 skb_reset_mac_header(xmit_skb);
2534 dev_queue_xmit(xmit_skb);
2538 static ieee80211_rx_result debug_noinline
2539 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2541 struct net_device *dev = rx->sdata->dev;
2542 struct sk_buff *skb = rx->skb;
2543 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2544 __le16 fc = hdr->frame_control;
2545 struct sk_buff_head frame_list;
2546 struct ethhdr ethhdr;
2547 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2549 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2552 } else switch (rx->sdata->vif.type) {
2553 case NL80211_IFTYPE_AP:
2554 case NL80211_IFTYPE_AP_VLAN:
2557 case NL80211_IFTYPE_STATION:
2559 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2562 case NL80211_IFTYPE_MESH_POINT:
2570 __skb_queue_head_init(&frame_list);
2572 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2573 rx->sdata->vif.addr,
2574 rx->sdata->vif.type,
2576 return RX_DROP_UNUSABLE;
2578 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2579 rx->sdata->vif.type,
2580 rx->local->hw.extra_tx_headroom,
2581 check_da, check_sa);
2583 while (!skb_queue_empty(&frame_list)) {
2584 rx->skb = __skb_dequeue(&frame_list);
2586 if (!ieee80211_frame_allowed(rx, fc)) {
2587 dev_kfree_skb(rx->skb);
2591 ieee80211_deliver_skb(rx);
2597 static ieee80211_rx_result debug_noinline
2598 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2600 struct sk_buff *skb = rx->skb;
2601 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2602 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2603 __le16 fc = hdr->frame_control;
2605 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2608 if (unlikely(!ieee80211_is_data(fc)))
2611 if (unlikely(!ieee80211_is_data_present(fc)))
2612 return RX_DROP_MONITOR;
2614 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2615 switch (rx->sdata->vif.type) {
2616 case NL80211_IFTYPE_AP_VLAN:
2617 if (!rx->sdata->u.vlan.sta)
2618 return RX_DROP_UNUSABLE;
2620 case NL80211_IFTYPE_STATION:
2621 if (!rx->sdata->u.mgd.use_4addr)
2622 return RX_DROP_UNUSABLE;
2625 return RX_DROP_UNUSABLE;
2629 if (is_multicast_ether_addr(hdr->addr1))
2630 return RX_DROP_UNUSABLE;
2632 return __ieee80211_rx_h_amsdu(rx, 0);
2635 #ifdef CONFIG_MAC80211_MESH
2636 static ieee80211_rx_result
2637 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2639 struct ieee80211_hdr *fwd_hdr, *hdr;
2640 struct ieee80211_tx_info *info;
2641 struct ieee80211s_hdr *mesh_hdr;
2642 struct sk_buff *skb = rx->skb, *fwd_skb;
2643 struct ieee80211_local *local = rx->local;
2644 struct ieee80211_sub_if_data *sdata = rx->sdata;
2645 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2648 hdr = (struct ieee80211_hdr *) skb->data;
2649 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2651 /* make sure fixed part of mesh header is there, also checks skb len */
2652 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2653 return RX_DROP_MONITOR;
2655 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2657 /* make sure full mesh header is there, also checks skb len */
2658 if (!pskb_may_pull(rx->skb,
2659 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2660 return RX_DROP_MONITOR;
2662 /* reload pointers */
2663 hdr = (struct ieee80211_hdr *) skb->data;
2664 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2666 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2667 return RX_DROP_MONITOR;
2669 /* frame is in RMC, don't forward */
2670 if (ieee80211_is_data(hdr->frame_control) &&
2671 is_multicast_ether_addr(hdr->addr1) &&
2672 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2673 return RX_DROP_MONITOR;
2675 if (!ieee80211_is_data(hdr->frame_control))
2679 return RX_DROP_MONITOR;
2681 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2682 struct mesh_path *mppath;
2686 if (is_multicast_ether_addr(hdr->addr1)) {
2687 mpp_addr = hdr->addr3;
2688 proxied_addr = mesh_hdr->eaddr1;
2689 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2690 MESH_FLAGS_AE_A5_A6) {
2691 /* has_a4 already checked in ieee80211_rx_mesh_check */
2692 mpp_addr = hdr->addr4;
2693 proxied_addr = mesh_hdr->eaddr2;
2695 return RX_DROP_MONITOR;
2699 mppath = mpp_path_lookup(sdata, proxied_addr);
2701 mpp_path_add(sdata, proxied_addr, mpp_addr);
2703 spin_lock_bh(&mppath->state_lock);
2704 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2705 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2706 mppath->exp_time = jiffies;
2707 spin_unlock_bh(&mppath->state_lock);
2712 /* Frame has reached destination. Don't forward */
2713 if (!is_multicast_ether_addr(hdr->addr1) &&
2714 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2717 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2718 q = sdata->vif.hw_queue[ac];
2719 if (ieee80211_queue_stopped(&local->hw, q)) {
2720 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2721 return RX_DROP_MONITOR;
2723 skb_set_queue_mapping(skb, q);
2725 if (!--mesh_hdr->ttl) {
2726 if (!is_multicast_ether_addr(hdr->addr1))
2727 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2728 dropped_frames_ttl);
2732 if (!ifmsh->mshcfg.dot11MeshForwarding)
2735 fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2736 sdata->encrypt_headroom, 0, GFP_ATOMIC);
2740 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2741 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2742 info = IEEE80211_SKB_CB(fwd_skb);
2743 memset(info, 0, sizeof(*info));
2744 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2745 info->control.vif = &rx->sdata->vif;
2746 info->control.jiffies = jiffies;
2747 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2748 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2749 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2750 /* update power mode indication when forwarding */
2751 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2752 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2753 /* mesh power mode flags updated in mesh_nexthop_lookup */
2754 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2756 /* unable to resolve next hop */
2757 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2759 WLAN_REASON_MESH_PATH_NOFORWARD,
2761 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2763 return RX_DROP_MONITOR;
2766 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2767 ieee80211_add_pending_skb(local, fwd_skb);
2769 if (is_multicast_ether_addr(hdr->addr1))
2771 return RX_DROP_MONITOR;
2775 static ieee80211_rx_result debug_noinline
2776 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2778 struct ieee80211_sub_if_data *sdata = rx->sdata;
2779 struct ieee80211_local *local = rx->local;
2780 struct net_device *dev = sdata->dev;
2781 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2782 __le16 fc = hdr->frame_control;
2786 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2789 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2790 return RX_DROP_MONITOR;
2793 * Send unexpected-4addr-frame event to hostapd. For older versions,
2794 * also drop the frame to cooked monitor interfaces.
2796 if (ieee80211_has_a4(hdr->frame_control) &&
2797 sdata->vif.type == NL80211_IFTYPE_AP) {
2799 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2800 cfg80211_rx_unexpected_4addr_frame(
2801 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2802 return RX_DROP_MONITOR;
2805 err = __ieee80211_data_to_8023(rx, &port_control);
2807 return RX_DROP_UNUSABLE;
2809 if (!ieee80211_frame_allowed(rx, fc))
2810 return RX_DROP_MONITOR;
2812 /* directly handle TDLS channel switch requests/responses */
2813 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2814 cpu_to_be16(ETH_P_TDLS))) {
2815 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2817 if (pskb_may_pull(rx->skb,
2818 offsetof(struct ieee80211_tdls_data, u)) &&
2819 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2820 tf->category == WLAN_CATEGORY_TDLS &&
2821 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2822 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2823 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2824 schedule_work(&local->tdls_chsw_work);
2826 rx->sta->rx_stats.packets++;
2832 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2833 unlikely(port_control) && sdata->bss) {
2834 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2842 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2843 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2844 !is_multicast_ether_addr(
2845 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2846 (!local->scanning &&
2847 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
2848 mod_timer(&local->dynamic_ps_timer, jiffies +
2849 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2851 ieee80211_deliver_skb(rx);
2856 static ieee80211_rx_result debug_noinline
2857 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2859 struct sk_buff *skb = rx->skb;
2860 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2861 struct tid_ampdu_rx *tid_agg_rx;
2865 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2868 if (ieee80211_is_back_req(bar->frame_control)) {
2870 __le16 control, start_seq_num;
2871 } __packed bar_data;
2872 struct ieee80211_event event = {
2873 .type = BAR_RX_EVENT,
2877 return RX_DROP_MONITOR;
2879 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2880 &bar_data, sizeof(bar_data)))
2881 return RX_DROP_MONITOR;
2883 tid = le16_to_cpu(bar_data.control) >> 12;
2885 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
2886 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
2887 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
2888 WLAN_BACK_RECIPIENT,
2889 WLAN_REASON_QSTA_REQUIRE_SETUP);
2891 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2893 return RX_DROP_MONITOR;
2895 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2896 event.u.ba.tid = tid;
2897 event.u.ba.ssn = start_seq_num;
2898 event.u.ba.sta = &rx->sta->sta;
2900 /* reset session timer */
2901 if (tid_agg_rx->timeout)
2902 mod_timer(&tid_agg_rx->session_timer,
2903 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2905 spin_lock(&tid_agg_rx->reorder_lock);
2906 /* release stored frames up to start of BAR */
2907 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2908 start_seq_num, frames);
2909 spin_unlock(&tid_agg_rx->reorder_lock);
2911 drv_event_callback(rx->local, rx->sdata, &event);
2918 * After this point, we only want management frames,
2919 * so we can drop all remaining control frames to
2920 * cooked monitor interfaces.
2922 return RX_DROP_MONITOR;
2925 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2926 struct ieee80211_mgmt *mgmt,
2929 struct ieee80211_local *local = sdata->local;
2930 struct sk_buff *skb;
2931 struct ieee80211_mgmt *resp;
2933 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2934 /* Not to own unicast address */
2938 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2939 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2940 /* Not from the current AP or not associated yet. */
2944 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2945 /* Too short SA Query request frame */
2949 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2953 skb_reserve(skb, local->hw.extra_tx_headroom);
2954 resp = skb_put_zero(skb, 24);
2955 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2956 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2957 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2958 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2959 IEEE80211_STYPE_ACTION);
2960 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2961 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2962 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2963 memcpy(resp->u.action.u.sa_query.trans_id,
2964 mgmt->u.action.u.sa_query.trans_id,
2965 WLAN_SA_QUERY_TR_ID_LEN);
2967 ieee80211_tx_skb(sdata, skb);
2970 static ieee80211_rx_result debug_noinline
2971 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2973 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2974 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2977 * From here on, look only at management frames.
2978 * Data and control frames are already handled,
2979 * and unknown (reserved) frames are useless.
2981 if (rx->skb->len < 24)
2982 return RX_DROP_MONITOR;
2984 if (!ieee80211_is_mgmt(mgmt->frame_control))
2985 return RX_DROP_MONITOR;
2987 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2988 ieee80211_is_beacon(mgmt->frame_control) &&
2989 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2992 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
2993 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
2994 sig = status->signal;
2996 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2997 rx->skb->data, rx->skb->len,
2999 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3002 if (ieee80211_drop_unencrypted_mgmt(rx))
3003 return RX_DROP_UNUSABLE;
3008 static ieee80211_rx_result debug_noinline
3009 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3011 struct ieee80211_local *local = rx->local;
3012 struct ieee80211_sub_if_data *sdata = rx->sdata;
3013 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3014 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3015 int len = rx->skb->len;
3017 if (!ieee80211_is_action(mgmt->frame_control))
3020 /* drop too small frames */
3021 if (len < IEEE80211_MIN_ACTION_SIZE)
3022 return RX_DROP_UNUSABLE;
3024 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3025 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3026 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3027 return RX_DROP_UNUSABLE;
3029 switch (mgmt->u.action.category) {
3030 case WLAN_CATEGORY_HT:
3031 /* reject HT action frames from stations not supporting HT */
3032 if (!rx->sta->sta.ht_cap.ht_supported)
3035 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3036 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3037 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3038 sdata->vif.type != NL80211_IFTYPE_AP &&
3039 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3042 /* verify action & smps_control/chanwidth are present */
3043 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3046 switch (mgmt->u.action.u.ht_smps.action) {
3047 case WLAN_HT_ACTION_SMPS: {
3048 struct ieee80211_supported_band *sband;
3049 enum ieee80211_smps_mode smps_mode;
3050 struct sta_opmode_info sta_opmode = {};
3052 /* convert to HT capability */
3053 switch (mgmt->u.action.u.ht_smps.smps_control) {
3054 case WLAN_HT_SMPS_CONTROL_DISABLED:
3055 smps_mode = IEEE80211_SMPS_OFF;
3057 case WLAN_HT_SMPS_CONTROL_STATIC:
3058 smps_mode = IEEE80211_SMPS_STATIC;
3060 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3061 smps_mode = IEEE80211_SMPS_DYNAMIC;
3067 /* if no change do nothing */
3068 if (rx->sta->sta.smps_mode == smps_mode)
3070 rx->sta->sta.smps_mode = smps_mode;
3071 sta_opmode.smps_mode =
3072 ieee80211_smps_mode_to_smps_mode(smps_mode);
3073 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3075 sband = rx->local->hw.wiphy->bands[status->band];
3077 rate_control_rate_update(local, sband, rx->sta,
3078 IEEE80211_RC_SMPS_CHANGED);
3079 cfg80211_sta_opmode_change_notify(sdata->dev,
3085 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3086 struct ieee80211_supported_band *sband;
3087 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3088 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3089 struct sta_opmode_info sta_opmode = {};
3091 /* If it doesn't support 40 MHz it can't change ... */
3092 if (!(rx->sta->sta.ht_cap.cap &
3093 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3096 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3097 max_bw = IEEE80211_STA_RX_BW_20;
3099 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
3101 /* set cur_max_bandwidth and recalc sta bw */
3102 rx->sta->cur_max_bandwidth = max_bw;
3103 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
3105 if (rx->sta->sta.bandwidth == new_bw)
3108 rx->sta->sta.bandwidth = new_bw;
3109 sband = rx->local->hw.wiphy->bands[status->band];
3111 ieee80211_sta_rx_bw_to_chan_width(rx->sta);
3112 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3114 rate_control_rate_update(local, sband, rx->sta,
3115 IEEE80211_RC_BW_CHANGED);
3116 cfg80211_sta_opmode_change_notify(sdata->dev,
3127 case WLAN_CATEGORY_PUBLIC:
3128 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3130 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3134 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3136 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3137 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3139 if (len < offsetof(struct ieee80211_mgmt,
3140 u.action.u.ext_chan_switch.variable))
3143 case WLAN_CATEGORY_VHT:
3144 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3145 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3146 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3147 sdata->vif.type != NL80211_IFTYPE_AP &&
3148 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3151 /* verify action code is present */
3152 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3155 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3156 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3157 /* verify opmode is present */
3158 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3162 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3163 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3171 case WLAN_CATEGORY_BACK:
3172 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3173 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3174 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3175 sdata->vif.type != NL80211_IFTYPE_AP &&
3176 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3179 /* verify action_code is present */
3180 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3183 switch (mgmt->u.action.u.addba_req.action_code) {
3184 case WLAN_ACTION_ADDBA_REQ:
3185 if (len < (IEEE80211_MIN_ACTION_SIZE +
3186 sizeof(mgmt->u.action.u.addba_req)))
3189 case WLAN_ACTION_ADDBA_RESP:
3190 if (len < (IEEE80211_MIN_ACTION_SIZE +
3191 sizeof(mgmt->u.action.u.addba_resp)))
3194 case WLAN_ACTION_DELBA:
3195 if (len < (IEEE80211_MIN_ACTION_SIZE +
3196 sizeof(mgmt->u.action.u.delba)))
3204 case WLAN_CATEGORY_SPECTRUM_MGMT:
3205 /* verify action_code is present */
3206 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3209 switch (mgmt->u.action.u.measurement.action_code) {
3210 case WLAN_ACTION_SPCT_MSR_REQ:
3211 if (status->band != NL80211_BAND_5GHZ)
3214 if (len < (IEEE80211_MIN_ACTION_SIZE +
3215 sizeof(mgmt->u.action.u.measurement)))
3218 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3221 ieee80211_process_measurement_req(sdata, mgmt, len);
3223 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3225 if (len < (IEEE80211_MIN_ACTION_SIZE +
3226 sizeof(mgmt->u.action.u.chan_switch)))
3229 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3230 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3231 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3234 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3235 bssid = sdata->u.mgd.bssid;
3236 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3237 bssid = sdata->u.ibss.bssid;
3238 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3243 if (!ether_addr_equal(mgmt->bssid, bssid))
3250 case WLAN_CATEGORY_SA_QUERY:
3251 if (len < (IEEE80211_MIN_ACTION_SIZE +
3252 sizeof(mgmt->u.action.u.sa_query)))
3255 switch (mgmt->u.action.u.sa_query.action) {
3256 case WLAN_ACTION_SA_QUERY_REQUEST:
3257 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3259 ieee80211_process_sa_query_req(sdata, mgmt, len);
3263 case WLAN_CATEGORY_SELF_PROTECTED:
3264 if (len < (IEEE80211_MIN_ACTION_SIZE +
3265 sizeof(mgmt->u.action.u.self_prot.action_code)))
3268 switch (mgmt->u.action.u.self_prot.action_code) {
3269 case WLAN_SP_MESH_PEERING_OPEN:
3270 case WLAN_SP_MESH_PEERING_CLOSE:
3271 case WLAN_SP_MESH_PEERING_CONFIRM:
3272 if (!ieee80211_vif_is_mesh(&sdata->vif))
3274 if (sdata->u.mesh.user_mpm)
3275 /* userspace handles this frame */
3278 case WLAN_SP_MGK_INFORM:
3279 case WLAN_SP_MGK_ACK:
3280 if (!ieee80211_vif_is_mesh(&sdata->vif))
3285 case WLAN_CATEGORY_MESH_ACTION:
3286 if (len < (IEEE80211_MIN_ACTION_SIZE +
3287 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3290 if (!ieee80211_vif_is_mesh(&sdata->vif))
3292 if (mesh_action_is_path_sel(mgmt) &&
3293 !mesh_path_sel_is_hwmp(sdata))
3301 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3302 /* will return in the next handlers */
3307 rx->sta->rx_stats.packets++;
3308 dev_kfree_skb(rx->skb);
3312 skb_queue_tail(&sdata->skb_queue, rx->skb);
3313 ieee80211_queue_work(&local->hw, &sdata->work);
3315 rx->sta->rx_stats.packets++;
3319 static ieee80211_rx_result debug_noinline
3320 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3322 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3325 /* skip known-bad action frames and return them in the next handler */
3326 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3330 * Getting here means the kernel doesn't know how to handle
3331 * it, but maybe userspace does ... include returned frames
3332 * so userspace can register for those to know whether ones
3333 * it transmitted were processed or returned.
3336 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3337 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3338 sig = status->signal;
3340 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
3341 rx->skb->data, rx->skb->len, 0)) {
3343 rx->sta->rx_stats.packets++;
3344 dev_kfree_skb(rx->skb);
3351 static ieee80211_rx_result debug_noinline
3352 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3354 struct ieee80211_local *local = rx->local;
3355 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3356 struct sk_buff *nskb;
3357 struct ieee80211_sub_if_data *sdata = rx->sdata;
3358 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3360 if (!ieee80211_is_action(mgmt->frame_control))
3364 * For AP mode, hostapd is responsible for handling any action
3365 * frames that we didn't handle, including returning unknown
3366 * ones. For all other modes we will return them to the sender,
3367 * setting the 0x80 bit in the action category, as required by
3368 * 802.11-2012 9.24.4.
3369 * Newer versions of hostapd shall also use the management frame
3370 * registration mechanisms, but older ones still use cooked
3371 * monitor interfaces so push all frames there.
3373 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3374 (sdata->vif.type == NL80211_IFTYPE_AP ||
3375 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3376 return RX_DROP_MONITOR;
3378 if (is_multicast_ether_addr(mgmt->da))
3379 return RX_DROP_MONITOR;
3381 /* do not return rejected action frames */
3382 if (mgmt->u.action.category & 0x80)
3383 return RX_DROP_UNUSABLE;
3385 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3388 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3390 nmgmt->u.action.category |= 0x80;
3391 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3392 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3394 memset(nskb->cb, 0, sizeof(nskb->cb));
3396 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3397 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3399 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3400 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3401 IEEE80211_TX_CTL_NO_CCK_RATE;
3402 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3404 local->hw.offchannel_tx_hw_queue;
3407 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3410 dev_kfree_skb(rx->skb);
3414 static ieee80211_rx_result debug_noinline
3415 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3417 struct ieee80211_sub_if_data *sdata = rx->sdata;
3418 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3421 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3423 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3424 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3425 sdata->vif.type != NL80211_IFTYPE_OCB &&
3426 sdata->vif.type != NL80211_IFTYPE_STATION)
3427 return RX_DROP_MONITOR;
3430 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3431 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3432 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3433 /* process for all: mesh, mlme, ibss */
3435 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3436 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3437 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3438 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3439 if (is_multicast_ether_addr(mgmt->da) &&
3440 !is_broadcast_ether_addr(mgmt->da))
3441 return RX_DROP_MONITOR;
3443 /* process only for station */
3444 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3445 return RX_DROP_MONITOR;
3447 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3448 /* process only for ibss and mesh */
3449 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3450 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3451 return RX_DROP_MONITOR;
3454 return RX_DROP_MONITOR;
3457 /* queue up frame and kick off work to process it */
3458 skb_queue_tail(&sdata->skb_queue, rx->skb);
3459 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3461 rx->sta->rx_stats.packets++;
3466 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3467 struct ieee80211_rate *rate)
3469 struct ieee80211_sub_if_data *sdata;
3470 struct ieee80211_local *local = rx->local;
3471 struct sk_buff *skb = rx->skb, *skb2;
3472 struct net_device *prev_dev = NULL;
3473 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3474 int needed_headroom;
3477 * If cooked monitor has been processed already, then
3478 * don't do it again. If not, set the flag.
3480 if (rx->flags & IEEE80211_RX_CMNTR)
3482 rx->flags |= IEEE80211_RX_CMNTR;
3484 /* If there are no cooked monitor interfaces, just free the SKB */
3485 if (!local->cooked_mntrs)
3488 /* vendor data is long removed here */
3489 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3490 /* room for the radiotap header based on driver features */
3491 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3493 if (skb_headroom(skb) < needed_headroom &&
3494 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3497 /* prepend radiotap information */
3498 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3501 skb_reset_mac_header(skb);
3502 skb->ip_summed = CHECKSUM_UNNECESSARY;
3503 skb->pkt_type = PACKET_OTHERHOST;
3504 skb->protocol = htons(ETH_P_802_2);
3506 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3507 if (!ieee80211_sdata_running(sdata))
3510 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3511 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3515 skb2 = skb_clone(skb, GFP_ATOMIC);
3517 skb2->dev = prev_dev;
3518 netif_receive_skb(skb2);
3522 prev_dev = sdata->dev;
3523 ieee80211_rx_stats(sdata->dev, skb->len);
3527 skb->dev = prev_dev;
3528 netif_receive_skb(skb);
3536 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3537 ieee80211_rx_result res)
3540 case RX_DROP_MONITOR:
3541 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3543 rx->sta->rx_stats.dropped++;
3546 struct ieee80211_rate *rate = NULL;
3547 struct ieee80211_supported_band *sband;
3548 struct ieee80211_rx_status *status;
3550 status = IEEE80211_SKB_RXCB((rx->skb));
3552 sband = rx->local->hw.wiphy->bands[status->band];
3553 if (status->encoding == RX_ENC_LEGACY)
3554 rate = &sband->bitrates[status->rate_idx];
3556 ieee80211_rx_cooked_monitor(rx, rate);
3559 case RX_DROP_UNUSABLE:
3560 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3562 rx->sta->rx_stats.dropped++;
3563 dev_kfree_skb(rx->skb);
3566 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3571 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3572 struct sk_buff_head *frames)
3574 ieee80211_rx_result res = RX_DROP_MONITOR;
3575 struct sk_buff *skb;
3577 #define CALL_RXH(rxh) \
3580 if (res != RX_CONTINUE) \
3584 /* Lock here to avoid hitting all of the data used in the RX
3585 * path (e.g. key data, station data, ...) concurrently when
3586 * a frame is released from the reorder buffer due to timeout
3587 * from the timer, potentially concurrently with RX from the
3590 spin_lock_bh(&rx->local->rx_path_lock);
3592 while ((skb = __skb_dequeue(frames))) {
3594 * all the other fields are valid across frames
3595 * that belong to an aMPDU since they are on the
3596 * same TID from the same station
3600 CALL_RXH(ieee80211_rx_h_check_more_data);
3601 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3602 CALL_RXH(ieee80211_rx_h_sta_process);
3603 CALL_RXH(ieee80211_rx_h_decrypt);
3604 CALL_RXH(ieee80211_rx_h_defragment);
3605 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3606 /* must be after MMIC verify so header is counted in MPDU mic */
3607 #ifdef CONFIG_MAC80211_MESH
3608 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3609 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3611 CALL_RXH(ieee80211_rx_h_amsdu);
3612 CALL_RXH(ieee80211_rx_h_data);
3614 /* special treatment -- needs the queue */
3615 res = ieee80211_rx_h_ctrl(rx, frames);
3616 if (res != RX_CONTINUE)
3619 CALL_RXH(ieee80211_rx_h_mgmt_check);
3620 CALL_RXH(ieee80211_rx_h_action);
3621 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3622 CALL_RXH(ieee80211_rx_h_action_return);
3623 CALL_RXH(ieee80211_rx_h_mgmt);
3626 ieee80211_rx_handlers_result(rx, res);
3631 spin_unlock_bh(&rx->local->rx_path_lock);
3634 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3636 struct sk_buff_head reorder_release;
3637 ieee80211_rx_result res = RX_DROP_MONITOR;
3639 __skb_queue_head_init(&reorder_release);
3641 #define CALL_RXH(rxh) \
3644 if (res != RX_CONTINUE) \
3648 CALL_RXH(ieee80211_rx_h_check_dup);
3649 CALL_RXH(ieee80211_rx_h_check);
3651 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3653 ieee80211_rx_handlers(rx, &reorder_release);
3657 ieee80211_rx_handlers_result(rx, res);
3663 * This function makes calls into the RX path, therefore
3664 * it has to be invoked under RCU read lock.
3666 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3668 struct sk_buff_head frames;
3669 struct ieee80211_rx_data rx = {
3671 .sdata = sta->sdata,
3672 .local = sta->local,
3673 /* This is OK -- must be QoS data frame */
3674 .security_idx = tid,
3676 .napi = NULL, /* must be NULL to not have races */
3678 struct tid_ampdu_rx *tid_agg_rx;
3680 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3684 __skb_queue_head_init(&frames);
3686 spin_lock(&tid_agg_rx->reorder_lock);
3687 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3688 spin_unlock(&tid_agg_rx->reorder_lock);
3690 if (!skb_queue_empty(&frames)) {
3691 struct ieee80211_event event = {
3692 .type = BA_FRAME_TIMEOUT,
3694 .u.ba.sta = &sta->sta,
3696 drv_event_callback(rx.local, rx.sdata, &event);
3699 ieee80211_rx_handlers(&rx, &frames);
3702 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3703 u16 ssn, u64 filtered,
3706 struct sta_info *sta;
3707 struct tid_ampdu_rx *tid_agg_rx;
3708 struct sk_buff_head frames;
3709 struct ieee80211_rx_data rx = {
3710 /* This is OK -- must be QoS data frame */
3711 .security_idx = tid,
3716 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3719 __skb_queue_head_init(&frames);
3721 sta = container_of(pubsta, struct sta_info, sta);
3724 rx.sdata = sta->sdata;
3725 rx.local = sta->local;
3728 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3732 spin_lock_bh(&tid_agg_rx->reorder_lock);
3734 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3737 /* release all frames in the reorder buffer */
3738 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3739 IEEE80211_SN_MODULO;
3740 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3742 /* update ssn to match received ssn */
3743 tid_agg_rx->head_seq_num = ssn;
3745 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3749 /* handle the case that received ssn is behind the mac ssn.
3750 * it can be tid_agg_rx->buf_size behind and still be valid */
3751 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3752 if (diff >= tid_agg_rx->buf_size) {
3753 tid_agg_rx->reorder_buf_filtered = 0;
3756 filtered = filtered >> diff;
3760 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3761 int index = (ssn + i) % tid_agg_rx->buf_size;
3763 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3764 if (filtered & BIT_ULL(i))
3765 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3768 /* now process also frames that the filter marking released */
3769 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3772 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3774 ieee80211_rx_handlers(&rx, &frames);
3779 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3781 /* main receive path */
3783 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3785 struct ieee80211_sub_if_data *sdata = rx->sdata;
3786 struct sk_buff *skb = rx->skb;
3787 struct ieee80211_hdr *hdr = (void *)skb->data;
3788 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3789 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3790 bool multicast = is_multicast_ether_addr(hdr->addr1);
3792 switch (sdata->vif.type) {
3793 case NL80211_IFTYPE_STATION:
3794 if (!bssid && !sdata->u.mgd.use_4addr)
3798 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3799 case NL80211_IFTYPE_ADHOC:
3802 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3803 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
3805 if (ieee80211_is_beacon(hdr->frame_control))
3807 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3810 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3814 if (status->encoding != RX_ENC_LEGACY)
3815 rate_idx = 0; /* TODO: HT/VHT rates */
3817 rate_idx = status->rate_idx;
3818 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3822 case NL80211_IFTYPE_OCB:
3825 if (!ieee80211_is_data_present(hdr->frame_control))
3827 if (!is_broadcast_ether_addr(bssid))
3830 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3834 if (status->encoding != RX_ENC_LEGACY)
3835 rate_idx = 0; /* TODO: HT rates */
3837 rate_idx = status->rate_idx;
3838 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3842 case NL80211_IFTYPE_MESH_POINT:
3843 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
3847 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3848 case NL80211_IFTYPE_AP_VLAN:
3849 case NL80211_IFTYPE_AP:
3851 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3853 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3855 * Accept public action frames even when the
3856 * BSSID doesn't match, this is used for P2P
3857 * and location updates. Note that mac80211
3858 * itself never looks at these frames.
3861 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3863 if (ieee80211_is_public_action(hdr, skb->len))
3865 return ieee80211_is_beacon(hdr->frame_control);
3868 if (!ieee80211_has_tods(hdr->frame_control)) {
3869 /* ignore data frames to TDLS-peers */
3870 if (ieee80211_is_data(hdr->frame_control))
3872 /* ignore action frames to TDLS-peers */
3873 if (ieee80211_is_action(hdr->frame_control) &&
3874 !is_broadcast_ether_addr(bssid) &&
3875 !ether_addr_equal(bssid, hdr->addr1))
3880 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3881 * the BSSID - we've checked that already but may have accepted
3882 * the wildcard (ff:ff:ff:ff:ff:ff).
3885 * The BSSID of the Data frame is determined as follows:
3886 * a) If the STA is contained within an AP or is associated
3887 * with an AP, the BSSID is the address currently in use
3888 * by the STA contained in the AP.
3890 * So we should not accept data frames with an address that's
3893 * Accepting it also opens a security problem because stations
3894 * could encrypt it with the GTK and inject traffic that way.
3896 if (ieee80211_is_data(hdr->frame_control) && multicast)
3900 case NL80211_IFTYPE_WDS:
3901 if (bssid || !ieee80211_is_data(hdr->frame_control))
3903 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3904 case NL80211_IFTYPE_P2P_DEVICE:
3905 return ieee80211_is_public_action(hdr, skb->len) ||
3906 ieee80211_is_probe_req(hdr->frame_control) ||
3907 ieee80211_is_probe_resp(hdr->frame_control) ||
3908 ieee80211_is_beacon(hdr->frame_control);
3909 case NL80211_IFTYPE_NAN:
3910 /* Currently no frames on NAN interface are allowed */
3920 void ieee80211_check_fast_rx(struct sta_info *sta)
3922 struct ieee80211_sub_if_data *sdata = sta->sdata;
3923 struct ieee80211_local *local = sdata->local;
3924 struct ieee80211_key *key;
3925 struct ieee80211_fast_rx fastrx = {
3927 .vif_type = sdata->vif.type,
3928 .control_port_protocol = sdata->control_port_protocol,
3929 }, *old, *new = NULL;
3930 bool assign = false;
3932 /* use sparse to check that we don't return without updating */
3933 __acquire(check_fast_rx);
3935 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
3936 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
3937 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
3938 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
3940 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
3942 /* fast-rx doesn't do reordering */
3943 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
3944 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
3947 switch (sdata->vif.type) {
3948 case NL80211_IFTYPE_STATION:
3949 if (sta->sta.tdls) {
3950 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3951 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3952 fastrx.expected_ds_bits = 0;
3954 fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
3955 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3956 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3957 fastrx.expected_ds_bits =
3958 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3961 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
3962 fastrx.expected_ds_bits |=
3963 cpu_to_le16(IEEE80211_FCTL_TODS);
3964 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3965 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3968 if (!sdata->u.mgd.powersave)
3971 /* software powersave is a huge mess, avoid all of it */
3972 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
3974 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3975 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3978 case NL80211_IFTYPE_AP_VLAN:
3979 case NL80211_IFTYPE_AP:
3980 /* parallel-rx requires this, at least with calls to
3981 * ieee80211_sta_ps_transition()
3983 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
3985 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3986 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3987 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
3989 fastrx.internal_forward =
3990 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
3991 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
3992 !sdata->u.vlan.sta);
3994 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3995 sdata->u.vlan.sta) {
3996 fastrx.expected_ds_bits |=
3997 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3998 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3999 fastrx.internal_forward = 0;
4007 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4011 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4013 switch (key->conf.cipher) {
4014 case WLAN_CIPHER_SUITE_TKIP:
4015 /* we don't want to deal with MMIC in fast-rx */
4017 case WLAN_CIPHER_SUITE_CCMP:
4018 case WLAN_CIPHER_SUITE_CCMP_256:
4019 case WLAN_CIPHER_SUITE_GCMP:
4020 case WLAN_CIPHER_SUITE_GCMP_256:
4023 /* we also don't want to deal with WEP or cipher scheme
4024 * since those require looking up the key idx in the
4025 * frame, rather than assuming the PTK is used
4026 * (we need to revisit this once we implement the real
4027 * PTK index, which is now valid in the spec, but we
4028 * haven't implemented that part yet)
4034 fastrx.icv_len = key->conf.icv_len;
4041 __release(check_fast_rx);
4044 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4046 spin_lock_bh(&sta->lock);
4047 old = rcu_dereference_protected(sta->fast_rx, true);
4048 rcu_assign_pointer(sta->fast_rx, new);
4049 spin_unlock_bh(&sta->lock);
4052 kfree_rcu(old, rcu_head);
4055 void ieee80211_clear_fast_rx(struct sta_info *sta)
4057 struct ieee80211_fast_rx *old;
4059 spin_lock_bh(&sta->lock);
4060 old = rcu_dereference_protected(sta->fast_rx, true);
4061 RCU_INIT_POINTER(sta->fast_rx, NULL);
4062 spin_unlock_bh(&sta->lock);
4065 kfree_rcu(old, rcu_head);
4068 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4070 struct ieee80211_local *local = sdata->local;
4071 struct sta_info *sta;
4073 lockdep_assert_held(&local->sta_mtx);
4075 list_for_each_entry_rcu(sta, &local->sta_list, list) {
4076 if (sdata != sta->sdata &&
4077 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4079 ieee80211_check_fast_rx(sta);
4083 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4085 struct ieee80211_local *local = sdata->local;
4087 mutex_lock(&local->sta_mtx);
4088 __ieee80211_check_fast_rx_iface(sdata);
4089 mutex_unlock(&local->sta_mtx);
4092 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4093 struct ieee80211_fast_rx *fast_rx)
4095 struct sk_buff *skb = rx->skb;
4096 struct ieee80211_hdr *hdr = (void *)skb->data;
4097 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4098 struct sta_info *sta = rx->sta;
4099 int orig_len = skb->len;
4100 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4101 int snap_offs = hdrlen;
4103 u8 snap[sizeof(rfc1042_header)];
4105 } *payload __aligned(2);
4109 } addrs __aligned(2);
4110 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
4112 if (fast_rx->uses_rss)
4113 stats = this_cpu_ptr(sta->pcpu_rx_stats);
4115 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4116 * to a common data structure; drivers can implement that per queue
4117 * but we don't have that information in mac80211
4119 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4122 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4124 /* If using encryption, we also need to have:
4125 * - PN_VALIDATED: similar, but the implementation is tricky
4126 * - DECRYPTED: necessary for PN_VALIDATED
4129 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4132 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4135 if (unlikely(ieee80211_is_frag(hdr)))
4138 /* Since our interface address cannot be multicast, this
4139 * implicitly also rejects multicast frames without the
4142 * We shouldn't get any *data* frames not addressed to us
4143 * (AP mode will accept multicast *management* frames), but
4144 * punting here will make it go through the full checks in
4145 * ieee80211_accept_frame().
4147 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4150 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4151 IEEE80211_FCTL_TODS)) !=
4152 fast_rx->expected_ds_bits)
4155 /* assign the key to drop unencrypted frames (later)
4156 * and strip the IV/MIC if necessary
4158 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4159 /* GCMP header length is the same */
4160 snap_offs += IEEE80211_CCMP_HDR_LEN;
4163 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4164 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4167 payload = (void *)(skb->data + snap_offs);
4169 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4172 /* Don't handle these here since they require special code.
4173 * Accept AARP and IPX even though they should come with a
4174 * bridge-tunnel header - but if we get them this way then
4175 * there's little point in discarding them.
4177 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4178 payload->proto == fast_rx->control_port_protocol))
4182 /* after this point, don't punt to the slowpath! */
4184 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4185 pskb_trim(skb, skb->len - fast_rx->icv_len))
4188 if (unlikely(fast_rx->sta_notify)) {
4189 ieee80211_sta_rx_notify(rx->sdata, hdr);
4190 fast_rx->sta_notify = false;
4193 /* statistics part of ieee80211_rx_h_sta_process() */
4194 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4195 stats->last_signal = status->signal;
4196 if (!fast_rx->uses_rss)
4197 ewma_signal_add(&sta->rx_stats_avg.signal,
4201 if (status->chains) {
4204 stats->chains = status->chains;
4205 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4206 int signal = status->chain_signal[i];
4208 if (!(status->chains & BIT(i)))
4211 stats->chain_signal_last[i] = signal;
4212 if (!fast_rx->uses_rss)
4213 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4217 /* end of statistics */
4219 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4222 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4223 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4230 stats->last_rx = jiffies;
4231 stats->last_rate = sta_stats_encode_rate(status);
4236 /* do the header conversion - first grab the addresses */
4237 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4238 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4239 /* remove the SNAP but leave the ethertype */
4240 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4241 /* push the addresses in front */
4242 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4244 skb->dev = fast_rx->dev;
4246 ieee80211_rx_stats(fast_rx->dev, skb->len);
4248 /* The seqno index has the same property as needed
4249 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4250 * for non-QoS-data frames. Here we know it's a data
4251 * frame, so count MSDUs.
4253 u64_stats_update_begin(&stats->syncp);
4254 stats->msdu[rx->seqno_idx]++;
4255 stats->bytes += orig_len;
4256 u64_stats_update_end(&stats->syncp);
4258 if (fast_rx->internal_forward) {
4259 struct sk_buff *xmit_skb = NULL;
4260 if (is_multicast_ether_addr(addrs.da)) {
4261 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4262 } else if (!ether_addr_equal(addrs.da, addrs.sa) &&
4263 sta_info_get(rx->sdata, addrs.da)) {
4270 * Send to wireless media and increase priority by 256
4271 * to keep the received priority instead of
4272 * reclassifying the frame (see cfg80211_classify8021d).
4274 xmit_skb->priority += 256;
4275 xmit_skb->protocol = htons(ETH_P_802_3);
4276 skb_reset_network_header(xmit_skb);
4277 skb_reset_mac_header(xmit_skb);
4278 dev_queue_xmit(xmit_skb);
4285 /* deliver to local stack */
4286 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4287 memset(skb->cb, 0, sizeof(skb->cb));
4289 napi_gro_receive(rx->napi, skb);
4291 netif_receive_skb(skb);
4301 * This function returns whether or not the SKB
4302 * was destined for RX processing or not, which,
4303 * if consume is true, is equivalent to whether
4304 * or not the skb was consumed.
4306 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4307 struct sk_buff *skb, bool consume)
4309 struct ieee80211_local *local = rx->local;
4310 struct ieee80211_sub_if_data *sdata = rx->sdata;
4314 /* See if we can do fast-rx; if we have to copy we already lost,
4315 * so punt in that case. We should never have to deliver a data
4316 * frame to multiple interfaces anyway.
4318 * We skip the ieee80211_accept_frame() call and do the necessary
4319 * checking inside ieee80211_invoke_fast_rx().
4321 if (consume && rx->sta) {
4322 struct ieee80211_fast_rx *fast_rx;
4324 fast_rx = rcu_dereference(rx->sta->fast_rx);
4325 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4329 if (!ieee80211_accept_frame(rx))
4333 skb = skb_copy(skb, GFP_ATOMIC);
4335 if (net_ratelimit())
4336 wiphy_debug(local->hw.wiphy,
4337 "failed to copy skb for %s\n",
4345 ieee80211_invoke_rx_handlers(rx);
4350 * This is the actual Rx frames handler. as it belongs to Rx path it must
4351 * be called with rcu_read_lock protection.
4353 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4354 struct ieee80211_sta *pubsta,
4355 struct sk_buff *skb,
4356 struct napi_struct *napi)
4358 struct ieee80211_local *local = hw_to_local(hw);
4359 struct ieee80211_sub_if_data *sdata;
4360 struct ieee80211_hdr *hdr;
4362 struct ieee80211_rx_data rx;
4363 struct ieee80211_sub_if_data *prev;
4364 struct rhlist_head *tmp;
4367 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4368 memset(&rx, 0, sizeof(rx));
4373 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4374 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4376 if (ieee80211_is_mgmt(fc)) {
4377 /* drop frame if too short for header */
4378 if (skb->len < ieee80211_hdrlen(fc))
4381 err = skb_linearize(skb);
4383 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4391 hdr = (struct ieee80211_hdr *)skb->data;
4392 ieee80211_parse_qos(&rx);
4393 ieee80211_verify_alignment(&rx);
4395 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4396 ieee80211_is_beacon(hdr->frame_control)))
4397 ieee80211_scan_rx(local, skb);
4399 if (ieee80211_is_data(fc)) {
4400 struct sta_info *sta, *prev_sta;
4403 rx.sta = container_of(pubsta, struct sta_info, sta);
4404 rx.sdata = rx.sta->sdata;
4405 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4412 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4419 rx.sdata = prev_sta->sdata;
4420 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4427 rx.sdata = prev_sta->sdata;
4429 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4437 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4438 if (!ieee80211_sdata_running(sdata))
4441 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4442 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4446 * frame is destined for this interface, but if it's
4447 * not also for the previous one we handle that after
4448 * the loop to avoid copying the SKB once too much
4456 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4458 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4464 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4467 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4476 * This is the receive path handler. It is called by a low level driver when an
4477 * 802.11 MPDU is received from the hardware.
4479 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4480 struct sk_buff *skb, struct napi_struct *napi)
4482 struct ieee80211_local *local = hw_to_local(hw);
4483 struct ieee80211_rate *rate = NULL;
4484 struct ieee80211_supported_band *sband;
4485 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4487 WARN_ON_ONCE(softirq_count() == 0);
4489 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4492 sband = local->hw.wiphy->bands[status->band];
4493 if (WARN_ON(!sband))
4497 * If we're suspending, it is possible although not too likely
4498 * that we'd be receiving frames after having already partially
4499 * quiesced the stack. We can't process such frames then since
4500 * that might, for example, cause stations to be added or other
4501 * driver callbacks be invoked.
4503 if (unlikely(local->quiescing || local->suspended))
4506 /* We might be during a HW reconfig, prevent Rx for the same reason */
4507 if (unlikely(local->in_reconfig))
4511 * The same happens when we're not even started,
4512 * but that's worth a warning.
4514 if (WARN_ON(!local->started))
4517 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4519 * Validate the rate, unless a PLCP error means that
4520 * we probably can't have a valid rate here anyway.
4523 switch (status->encoding) {
4526 * rate_idx is MCS index, which can be [0-76]
4529 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4531 * Anything else would be some sort of driver or
4532 * hardware error. The driver should catch hardware
4535 if (WARN(status->rate_idx > 76,
4536 "Rate marked as an HT rate but passed "
4537 "status->rate_idx is not "
4538 "an MCS index [0-76]: %d (0x%02x)\n",
4544 if (WARN_ONCE(status->rate_idx > 9 ||
4547 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4548 status->rate_idx, status->nss))
4552 if (WARN_ONCE(status->rate_idx > 11 ||
4555 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4556 status->rate_idx, status->nss))
4563 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4565 rate = &sband->bitrates[status->rate_idx];
4569 status->rx_flags = 0;
4572 * key references and virtual interfaces are protected using RCU
4573 * and this requires that we are in a read-side RCU section during
4574 * receive processing
4579 * Frames with failed FCS/PLCP checksum are not returned,
4580 * all other frames are returned without radiotap header
4581 * if it was previously present.
4582 * Also, frames with less than 16 bytes are dropped.
4584 skb = ieee80211_rx_monitor(local, skb, rate);
4590 ieee80211_tpt_led_trig_rx(local,
4591 ((struct ieee80211_hdr *)skb->data)->frame_control,
4594 __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
4602 EXPORT_SYMBOL(ieee80211_rx_napi);
4604 /* This is a version of the rx handler that can be called from hard irq
4605 * context. Post the skb on the queue and schedule the tasklet */
4606 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
4608 struct ieee80211_local *local = hw_to_local(hw);
4610 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4612 skb->pkt_type = IEEE80211_RX_MSG;
4613 skb_queue_tail(&local->skb_queue, skb);
4614 tasklet_schedule(&local->tasklet);
4616 EXPORT_SYMBOL(ieee80211_rx_irqsafe);