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))
121 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
124 if (ieee80211_is_ctl(hdr->frame_control) &&
125 !ieee80211_is_pspoll(hdr->frame_control) &&
126 !ieee80211_is_back_req(hdr->frame_control))
133 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
134 struct ieee80211_rx_status *status,
139 /* always present fields */
140 len = sizeof(struct ieee80211_radiotap_header) + 8;
142 /* allocate extra bitmaps */
144 len += 4 * hweight8(status->chains);
146 if (ieee80211_have_rx_timestamp(status)) {
150 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
153 /* antenna field, if we don't have per-chain info */
157 /* padding for RX_FLAGS if necessary */
160 if (status->encoding == RX_ENC_HT) /* HT info */
163 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
168 if (status->encoding == RX_ENC_VHT) {
173 if (local->hw.radiotap_timestamp.units_pos >= 0) {
178 if (status->encoding == RX_ENC_HE &&
179 status->flag & RX_FLAG_RADIOTAP_HE) {
182 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
185 if (status->encoding == RX_ENC_HE &&
186 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
189 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
192 if (status->chains) {
193 /* antenna and antenna signal fields */
194 len += 2 * hweight8(status->chains);
197 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
198 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
200 /* vendor presence bitmap */
202 /* alignment for fixed 6-byte vendor data header */
204 /* vendor data header */
206 if (WARN_ON(rtap->align == 0))
208 len = ALIGN(len, rtap->align);
209 len += rtap->len + rtap->pad;
215 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
220 struct ieee80211_hdr_3addr hdr;
228 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
230 if (skb->len < rtap_space + sizeof(action) +
231 VHT_MUMIMO_GROUPS_DATA_LEN)
234 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
237 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
239 if (!ieee80211_is_action(action.hdr.frame_control))
242 if (action.category != WLAN_CATEGORY_VHT)
245 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
248 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
251 skb = skb_copy(skb, GFP_ATOMIC);
255 skb_queue_tail(&sdata->skb_queue, skb);
256 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
260 * ieee80211_add_rx_radiotap_header - add radiotap header
262 * add a radiotap header containing all the fields which the hardware provided.
265 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
267 struct ieee80211_rate *rate,
268 int rtap_len, bool has_fcs)
270 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
271 struct ieee80211_radiotap_header *rthdr;
276 u16 channel_flags = 0;
278 unsigned long chains = status->chains;
279 struct ieee80211_vendor_radiotap rtap = {};
280 struct ieee80211_radiotap_he he = {};
281 struct ieee80211_radiotap_he_mu he_mu = {};
283 if (status->flag & RX_FLAG_RADIOTAP_HE) {
284 he = *(struct ieee80211_radiotap_he *)skb->data;
285 skb_pull(skb, sizeof(he));
286 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
289 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
290 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
291 skb_pull(skb, sizeof(he_mu));
294 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
295 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
296 /* rtap.len and rtap.pad are undone immediately */
297 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
301 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
304 rthdr = skb_push(skb, rtap_len);
305 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
306 it_present = &rthdr->it_present;
308 /* radiotap header, set always present flags */
309 rthdr->it_len = cpu_to_le16(rtap_len);
310 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
311 BIT(IEEE80211_RADIOTAP_CHANNEL) |
312 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
315 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
317 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
319 BIT(IEEE80211_RADIOTAP_EXT) |
320 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
321 put_unaligned_le32(it_present_val, it_present);
323 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
324 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
327 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
328 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
329 BIT(IEEE80211_RADIOTAP_EXT);
330 put_unaligned_le32(it_present_val, it_present);
332 it_present_val = rtap.present;
335 put_unaligned_le32(it_present_val, it_present);
337 pos = (void *)(it_present + 1);
339 /* the order of the following fields is important */
341 /* IEEE80211_RADIOTAP_TSFT */
342 if (ieee80211_have_rx_timestamp(status)) {
344 while ((pos - (u8 *)rthdr) & 7)
347 ieee80211_calculate_rx_timestamp(local, status,
350 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
354 /* IEEE80211_RADIOTAP_FLAGS */
355 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
356 *pos |= IEEE80211_RADIOTAP_F_FCS;
357 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
358 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
359 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
360 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
363 /* IEEE80211_RADIOTAP_RATE */
364 if (!rate || status->encoding != RX_ENC_LEGACY) {
366 * Without rate information don't add it. If we have,
367 * MCS information is a separate field in radiotap,
368 * added below. The byte here is needed as padding
369 * for the channel though, so initialise it to 0.
374 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
375 if (status->bw == RATE_INFO_BW_10)
377 else if (status->bw == RATE_INFO_BW_5)
379 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
383 /* IEEE80211_RADIOTAP_CHANNEL */
384 put_unaligned_le16(status->freq, pos);
386 if (status->bw == RATE_INFO_BW_10)
387 channel_flags |= IEEE80211_CHAN_HALF;
388 else if (status->bw == RATE_INFO_BW_5)
389 channel_flags |= IEEE80211_CHAN_QUARTER;
391 if (status->band == NL80211_BAND_5GHZ)
392 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
393 else if (status->encoding != RX_ENC_LEGACY)
394 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
395 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
396 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
398 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
400 channel_flags |= IEEE80211_CHAN_2GHZ;
401 put_unaligned_le16(channel_flags, pos);
404 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
405 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
406 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
407 *pos = status->signal;
409 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
413 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
415 if (!status->chains) {
416 /* IEEE80211_RADIOTAP_ANTENNA */
417 *pos = status->antenna;
421 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
423 /* IEEE80211_RADIOTAP_RX_FLAGS */
424 /* ensure 2 byte alignment for the 2 byte field as required */
425 if ((pos - (u8 *)rthdr) & 1)
427 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
428 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
429 put_unaligned_le16(rx_flags, pos);
432 if (status->encoding == RX_ENC_HT) {
435 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
436 *pos++ = local->hw.radiotap_mcs_details;
438 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
439 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
440 if (status->bw == RATE_INFO_BW_40)
441 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
442 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
443 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
444 if (status->enc_flags & RX_ENC_FLAG_LDPC)
445 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
446 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
447 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
449 *pos++ = status->rate_idx;
452 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
455 /* ensure 4 byte alignment */
456 while ((pos - (u8 *)rthdr) & 3)
459 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
460 put_unaligned_le32(status->ampdu_reference, pos);
462 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
463 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
464 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
465 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
466 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
467 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
468 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
469 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
470 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
471 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
472 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
473 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
474 put_unaligned_le16(flags, pos);
476 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
477 *pos++ = status->ampdu_delimiter_crc;
483 if (status->encoding == RX_ENC_VHT) {
484 u16 known = local->hw.radiotap_vht_details;
486 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
487 put_unaligned_le16(known, pos);
490 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
491 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
492 /* in VHT, STBC is binary */
493 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
494 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
495 if (status->enc_flags & RX_ENC_FLAG_BF)
496 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
499 switch (status->bw) {
500 case RATE_INFO_BW_80:
503 case RATE_INFO_BW_160:
506 case RATE_INFO_BW_40:
513 *pos = (status->rate_idx << 4) | status->nss;
516 if (status->enc_flags & RX_ENC_FLAG_LDPC)
517 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
525 if (local->hw.radiotap_timestamp.units_pos >= 0) {
527 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
530 cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP);
532 /* ensure 8 byte alignment */
533 while ((pos - (u8 *)rthdr) & 7)
536 put_unaligned_le64(status->device_timestamp, pos);
539 if (local->hw.radiotap_timestamp.accuracy >= 0) {
540 accuracy = local->hw.radiotap_timestamp.accuracy;
541 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
543 put_unaligned_le16(accuracy, pos);
546 *pos++ = local->hw.radiotap_timestamp.units_pos;
550 if (status->encoding == RX_ENC_HE &&
551 status->flag & RX_FLAG_RADIOTAP_HE) {
552 #define HE_PREP(f, val) cpu_to_le16(FIELD_PREP(IEEE80211_RADIOTAP_HE_##f, val))
554 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
555 he.data6 |= HE_PREP(DATA6_NSTS,
556 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
558 he.data3 |= HE_PREP(DATA3_STBC, 1);
560 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
563 #define CHECK_GI(s) \
564 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
565 (int)NL80211_RATE_INFO_HE_GI_##s)
571 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
572 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
573 he.data3 |= HE_PREP(DATA3_CODING,
574 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
576 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
578 switch (status->bw) {
579 case RATE_INFO_BW_20:
580 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
581 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
583 case RATE_INFO_BW_40:
584 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
585 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
587 case RATE_INFO_BW_80:
588 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
589 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
591 case RATE_INFO_BW_160:
592 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
593 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
595 case RATE_INFO_BW_HE_RU:
596 #define CHECK_RU_ALLOC(s) \
597 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
598 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
606 CHECK_RU_ALLOC(2x996);
608 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
612 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
615 /* ensure 2 byte alignment */
616 while ((pos - (u8 *)rthdr) & 1)
618 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE);
619 memcpy(pos, &he, sizeof(he));
623 if (status->encoding == RX_ENC_HE &&
624 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
625 /* ensure 2 byte alignment */
626 while ((pos - (u8 *)rthdr) & 1)
628 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU);
629 memcpy(pos, &he_mu, sizeof(he_mu));
630 pos += sizeof(he_mu);
633 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
634 *pos++ = status->chain_signal[chain];
638 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
639 /* ensure 2 byte alignment for the vendor field as required */
640 if ((pos - (u8 *)rthdr) & 1)
642 *pos++ = rtap.oui[0];
643 *pos++ = rtap.oui[1];
644 *pos++ = rtap.oui[2];
646 put_unaligned_le16(rtap.len, pos);
648 /* align the actual payload as requested */
649 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
651 /* data (and possible padding) already follows */
655 static struct sk_buff *
656 ieee80211_make_monitor_skb(struct ieee80211_local *local,
657 struct sk_buff **origskb,
658 struct ieee80211_rate *rate,
659 int rtap_space, bool use_origskb)
661 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
662 int rt_hdrlen, needed_headroom;
665 /* room for the radiotap header based on driver features */
666 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
667 needed_headroom = rt_hdrlen - rtap_space;
670 /* only need to expand headroom if necessary */
675 * This shouldn't trigger often because most devices have an
676 * RX header they pull before we get here, and that should
677 * be big enough for our radiotap information. We should
678 * probably export the length to drivers so that we can have
679 * them allocate enough headroom to start with.
681 if (skb_headroom(skb) < needed_headroom &&
682 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
688 * Need to make a copy and possibly remove radiotap header
689 * and FCS from the original.
691 skb = skb_copy_expand(*origskb, needed_headroom, 0, GFP_ATOMIC);
697 /* prepend radiotap information */
698 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
700 skb_reset_mac_header(skb);
701 skb->ip_summed = CHECKSUM_UNNECESSARY;
702 skb->pkt_type = PACKET_OTHERHOST;
703 skb->protocol = htons(ETH_P_802_2);
709 * This function copies a received frame to all monitor interfaces and
710 * returns a cleaned-up SKB that no longer includes the FCS nor the
711 * radiotap header the driver might have added.
713 static struct sk_buff *
714 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
715 struct ieee80211_rate *rate)
717 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
718 struct ieee80211_sub_if_data *sdata;
719 struct sk_buff *monskb = NULL;
720 int present_fcs_len = 0;
721 unsigned int rtap_space = 0;
722 struct ieee80211_sub_if_data *monitor_sdata =
723 rcu_dereference(local->monitor_sdata);
724 bool only_monitor = false;
726 if (status->flag & RX_FLAG_RADIOTAP_HE)
727 rtap_space += sizeof(struct ieee80211_radiotap_he);
729 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
730 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
732 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
733 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
735 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
739 * First, we may need to make a copy of the skb because
740 * (1) we need to modify it for radiotap (if not present), and
741 * (2) the other RX handlers will modify the skb we got.
743 * We don't need to, of course, if we aren't going to return
744 * the SKB because it has a bad FCS/PLCP checksum.
747 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
748 if (unlikely(origskb->len <= FCS_LEN)) {
751 dev_kfree_skb(origskb);
754 present_fcs_len = FCS_LEN;
757 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
758 if (!pskb_may_pull(origskb, 2 + rtap_space)) {
759 dev_kfree_skb(origskb);
763 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
765 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
767 dev_kfree_skb(origskb);
771 remove_monitor_info(origskb, present_fcs_len, rtap_space);
775 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
777 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
778 bool last_monitor = list_is_last(&sdata->u.mntr.list,
782 monskb = ieee80211_make_monitor_skb(local, &origskb,
794 skb = skb_clone(monskb, GFP_ATOMIC);
798 skb->dev = sdata->dev;
799 ieee80211_rx_stats(skb->dev, skb->len);
800 netif_receive_skb(skb);
808 /* this happens if last_monitor was erroneously false */
809 dev_kfree_skb(monskb);
815 remove_monitor_info(origskb, present_fcs_len, rtap_space);
819 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
821 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
822 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
823 int tid, seqno_idx, security_idx;
825 /* does the frame have a qos control field? */
826 if (ieee80211_is_data_qos(hdr->frame_control)) {
827 u8 *qc = ieee80211_get_qos_ctl(hdr);
828 /* frame has qos control */
829 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
830 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
831 status->rx_flags |= IEEE80211_RX_AMSDU;
837 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
839 * Sequence numbers for management frames, QoS data
840 * frames with a broadcast/multicast address in the
841 * Address 1 field, and all non-QoS data frames sent
842 * by QoS STAs are assigned using an additional single
843 * modulo-4096 counter, [...]
845 * We also use that counter for non-QoS STAs.
847 seqno_idx = IEEE80211_NUM_TIDS;
849 if (ieee80211_is_mgmt(hdr->frame_control))
850 security_idx = IEEE80211_NUM_TIDS;
854 rx->seqno_idx = seqno_idx;
855 rx->security_idx = security_idx;
856 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
857 * For now, set skb->priority to 0 for other cases. */
858 rx->skb->priority = (tid > 7) ? 0 : tid;
862 * DOC: Packet alignment
864 * Drivers always need to pass packets that are aligned to two-byte boundaries
867 * Additionally, should, if possible, align the payload data in a way that
868 * guarantees that the contained IP header is aligned to a four-byte
869 * boundary. In the case of regular frames, this simply means aligning the
870 * payload to a four-byte boundary (because either the IP header is directly
871 * contained, or IV/RFC1042 headers that have a length divisible by four are
872 * in front of it). If the payload data is not properly aligned and the
873 * architecture doesn't support efficient unaligned operations, mac80211
874 * will align the data.
876 * With A-MSDU frames, however, the payload data address must yield two modulo
877 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
878 * push the IP header further back to a multiple of four again. Thankfully, the
879 * specs were sane enough this time around to require padding each A-MSDU
880 * subframe to a length that is a multiple of four.
882 * Padding like Atheros hardware adds which is between the 802.11 header and
883 * the payload is not supported, the driver is required to move the 802.11
884 * header to be directly in front of the payload in that case.
886 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
888 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
889 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
896 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
898 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
900 if (is_multicast_ether_addr(hdr->addr1))
903 return ieee80211_is_robust_mgmt_frame(skb);
907 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
909 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
911 if (!is_multicast_ether_addr(hdr->addr1))
914 return ieee80211_is_robust_mgmt_frame(skb);
918 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
919 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
921 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
922 struct ieee80211_mmie *mmie;
923 struct ieee80211_mmie_16 *mmie16;
925 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
928 if (!ieee80211_is_robust_mgmt_frame(skb))
929 return -1; /* not a robust management frame */
931 mmie = (struct ieee80211_mmie *)
932 (skb->data + skb->len - sizeof(*mmie));
933 if (mmie->element_id == WLAN_EID_MMIE &&
934 mmie->length == sizeof(*mmie) - 2)
935 return le16_to_cpu(mmie->key_id);
937 mmie16 = (struct ieee80211_mmie_16 *)
938 (skb->data + skb->len - sizeof(*mmie16));
939 if (skb->len >= 24 + sizeof(*mmie16) &&
940 mmie16->element_id == WLAN_EID_MMIE &&
941 mmie16->length == sizeof(*mmie16) - 2)
942 return le16_to_cpu(mmie16->key_id);
947 static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
950 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
955 fc = hdr->frame_control;
956 hdrlen = ieee80211_hdrlen(fc);
958 if (skb->len < hdrlen + cs->hdr_len)
961 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
962 keyid &= cs->key_idx_mask;
963 keyid >>= cs->key_idx_shift;
968 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
970 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
971 char *dev_addr = rx->sdata->vif.addr;
973 if (ieee80211_is_data(hdr->frame_control)) {
974 if (is_multicast_ether_addr(hdr->addr1)) {
975 if (ieee80211_has_tods(hdr->frame_control) ||
976 !ieee80211_has_fromds(hdr->frame_control))
977 return RX_DROP_MONITOR;
978 if (ether_addr_equal(hdr->addr3, dev_addr))
979 return RX_DROP_MONITOR;
981 if (!ieee80211_has_a4(hdr->frame_control))
982 return RX_DROP_MONITOR;
983 if (ether_addr_equal(hdr->addr4, dev_addr))
984 return RX_DROP_MONITOR;
988 /* If there is not an established peer link and this is not a peer link
989 * establisment frame, beacon or probe, drop the frame.
992 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
993 struct ieee80211_mgmt *mgmt;
995 if (!ieee80211_is_mgmt(hdr->frame_control))
996 return RX_DROP_MONITOR;
998 if (ieee80211_is_action(hdr->frame_control)) {
1001 /* make sure category field is present */
1002 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1003 return RX_DROP_MONITOR;
1005 mgmt = (struct ieee80211_mgmt *)hdr;
1006 category = mgmt->u.action.category;
1007 if (category != WLAN_CATEGORY_MESH_ACTION &&
1008 category != WLAN_CATEGORY_SELF_PROTECTED)
1009 return RX_DROP_MONITOR;
1013 if (ieee80211_is_probe_req(hdr->frame_control) ||
1014 ieee80211_is_probe_resp(hdr->frame_control) ||
1015 ieee80211_is_beacon(hdr->frame_control) ||
1016 ieee80211_is_auth(hdr->frame_control))
1019 return RX_DROP_MONITOR;
1025 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1028 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1029 struct sk_buff *tail = skb_peek_tail(frames);
1030 struct ieee80211_rx_status *status;
1032 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1038 status = IEEE80211_SKB_RXCB(tail);
1039 if (status->flag & RX_FLAG_AMSDU_MORE)
1045 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1046 struct tid_ampdu_rx *tid_agg_rx,
1048 struct sk_buff_head *frames)
1050 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1051 struct sk_buff *skb;
1052 struct ieee80211_rx_status *status;
1054 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1056 if (skb_queue_empty(skb_list))
1059 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1060 __skb_queue_purge(skb_list);
1064 /* release frames from the reorder ring buffer */
1065 tid_agg_rx->stored_mpdu_num--;
1066 while ((skb = __skb_dequeue(skb_list))) {
1067 status = IEEE80211_SKB_RXCB(skb);
1068 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1069 __skb_queue_tail(frames, skb);
1073 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1074 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1077 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1078 struct tid_ampdu_rx *tid_agg_rx,
1080 struct sk_buff_head *frames)
1084 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1086 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1087 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1088 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1094 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1095 * the skb was added to the buffer longer than this time ago, the earlier
1096 * frames that have not yet been received are assumed to be lost and the skb
1097 * can be released for processing. This may also release other skb's from the
1098 * reorder buffer if there are no additional gaps between the frames.
1100 * Callers must hold tid_agg_rx->reorder_lock.
1102 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1104 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1105 struct tid_ampdu_rx *tid_agg_rx,
1106 struct sk_buff_head *frames)
1110 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1112 /* release the buffer until next missing frame */
1113 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1114 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1115 tid_agg_rx->stored_mpdu_num) {
1117 * No buffers ready to be released, but check whether any
1118 * frames in the reorder buffer have timed out.
1121 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1122 j = (j + 1) % tid_agg_rx->buf_size) {
1123 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1128 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1129 HT_RX_REORDER_BUF_TIMEOUT))
1130 goto set_release_timer;
1132 /* don't leave incomplete A-MSDUs around */
1133 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1134 i = (i + 1) % tid_agg_rx->buf_size)
1135 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1137 ht_dbg_ratelimited(sdata,
1138 "release an RX reorder frame due to timeout on earlier frames\n");
1139 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1143 * Increment the head seq# also for the skipped slots.
1145 tid_agg_rx->head_seq_num =
1146 (tid_agg_rx->head_seq_num +
1147 skipped) & IEEE80211_SN_MASK;
1150 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1151 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1153 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1156 if (tid_agg_rx->stored_mpdu_num) {
1157 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1159 for (; j != (index - 1) % tid_agg_rx->buf_size;
1160 j = (j + 1) % tid_agg_rx->buf_size) {
1161 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1167 if (!tid_agg_rx->removed)
1168 mod_timer(&tid_agg_rx->reorder_timer,
1169 tid_agg_rx->reorder_time[j] + 1 +
1170 HT_RX_REORDER_BUF_TIMEOUT);
1172 del_timer(&tid_agg_rx->reorder_timer);
1177 * As this function belongs to the RX path it must be under
1178 * rcu_read_lock protection. It returns false if the frame
1179 * can be processed immediately, true if it was consumed.
1181 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1182 struct tid_ampdu_rx *tid_agg_rx,
1183 struct sk_buff *skb,
1184 struct sk_buff_head *frames)
1186 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1187 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1188 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1189 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1190 u16 head_seq_num, buf_size;
1194 spin_lock(&tid_agg_rx->reorder_lock);
1197 * Offloaded BA sessions have no known starting sequence number so pick
1198 * one from first Rxed frame for this tid after BA was started.
1200 if (unlikely(tid_agg_rx->auto_seq)) {
1201 tid_agg_rx->auto_seq = false;
1202 tid_agg_rx->ssn = mpdu_seq_num;
1203 tid_agg_rx->head_seq_num = mpdu_seq_num;
1206 buf_size = tid_agg_rx->buf_size;
1207 head_seq_num = tid_agg_rx->head_seq_num;
1210 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1213 if (unlikely(!tid_agg_rx->started)) {
1214 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1218 tid_agg_rx->started = true;
1221 /* frame with out of date sequence number */
1222 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1228 * If frame the sequence number exceeds our buffering window
1229 * size release some previous frames to make room for this one.
1231 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1232 head_seq_num = ieee80211_sn_inc(
1233 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1234 /* release stored frames up to new head to stack */
1235 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1236 head_seq_num, frames);
1239 /* Now the new frame is always in the range of the reordering buffer */
1241 index = mpdu_seq_num % tid_agg_rx->buf_size;
1243 /* check if we already stored this frame */
1244 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1250 * If the current MPDU is in the right order and nothing else
1251 * is stored we can process it directly, no need to buffer it.
1252 * If it is first but there's something stored, we may be able
1253 * to release frames after this one.
1255 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1256 tid_agg_rx->stored_mpdu_num == 0) {
1257 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1258 tid_agg_rx->head_seq_num =
1259 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1264 /* put the frame in the reordering buffer */
1265 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1266 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1267 tid_agg_rx->reorder_time[index] = jiffies;
1268 tid_agg_rx->stored_mpdu_num++;
1269 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1273 spin_unlock(&tid_agg_rx->reorder_lock);
1278 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1279 * true if the MPDU was buffered, false if it should be processed.
1281 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1282 struct sk_buff_head *frames)
1284 struct sk_buff *skb = rx->skb;
1285 struct ieee80211_local *local = rx->local;
1286 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1287 struct sta_info *sta = rx->sta;
1288 struct tid_ampdu_rx *tid_agg_rx;
1292 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1293 is_multicast_ether_addr(hdr->addr1))
1297 * filter the QoS data rx stream according to
1298 * STA/TID and check if this STA/TID is on aggregation
1304 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1305 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1306 tid = ieee80211_get_tid(hdr);
1308 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1310 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1311 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1312 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1313 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1314 WLAN_BACK_RECIPIENT,
1315 WLAN_REASON_QSTA_REQUIRE_SETUP);
1319 /* qos null data frames are excluded */
1320 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1323 /* not part of a BA session */
1324 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1325 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1328 /* new, potentially un-ordered, ampdu frame - process it */
1330 /* reset session timer */
1331 if (tid_agg_rx->timeout)
1332 tid_agg_rx->last_rx = jiffies;
1334 /* if this mpdu is fragmented - terminate rx aggregation session */
1335 sc = le16_to_cpu(hdr->seq_ctrl);
1336 if (sc & IEEE80211_SCTL_FRAG) {
1337 skb_queue_tail(&rx->sdata->skb_queue, skb);
1338 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1343 * No locking needed -- we will only ever process one
1344 * RX packet at a time, and thus own tid_agg_rx. All
1345 * other code manipulating it needs to (and does) make
1346 * sure that we cannot get to it any more before doing
1349 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1354 __skb_queue_tail(frames, skb);
1357 static ieee80211_rx_result debug_noinline
1358 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1360 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1361 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1363 if (status->flag & RX_FLAG_DUP_VALIDATED)
1367 * Drop duplicate 802.11 retransmissions
1368 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1371 if (rx->skb->len < 24)
1374 if (ieee80211_is_ctl(hdr->frame_control) ||
1375 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
1376 is_multicast_ether_addr(hdr->addr1))
1382 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1383 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1384 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1385 rx->sta->rx_stats.num_duplicates++;
1386 return RX_DROP_UNUSABLE;
1387 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1388 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1394 static ieee80211_rx_result debug_noinline
1395 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1397 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1399 /* Drop disallowed frame classes based on STA auth/assoc state;
1400 * IEEE 802.11, Chap 5.5.
1402 * mac80211 filters only based on association state, i.e. it drops
1403 * Class 3 frames from not associated stations. hostapd sends
1404 * deauth/disassoc frames when needed. In addition, hostapd is
1405 * responsible for filtering on both auth and assoc states.
1408 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1409 return ieee80211_rx_mesh_check(rx);
1411 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1412 ieee80211_is_pspoll(hdr->frame_control)) &&
1413 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1414 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1415 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1416 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1418 * accept port control frames from the AP even when it's not
1419 * yet marked ASSOC to prevent a race where we don't set the
1420 * assoc bit quickly enough before it sends the first frame
1422 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1423 ieee80211_is_data_present(hdr->frame_control)) {
1424 unsigned int hdrlen;
1427 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1429 if (rx->skb->len < hdrlen + 8)
1430 return RX_DROP_MONITOR;
1432 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1433 if (ethertype == rx->sdata->control_port_protocol)
1437 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1438 cfg80211_rx_spurious_frame(rx->sdata->dev,
1441 return RX_DROP_UNUSABLE;
1443 return RX_DROP_MONITOR;
1450 static ieee80211_rx_result debug_noinline
1451 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1453 struct ieee80211_local *local;
1454 struct ieee80211_hdr *hdr;
1455 struct sk_buff *skb;
1459 hdr = (struct ieee80211_hdr *) skb->data;
1461 if (!local->pspolling)
1464 if (!ieee80211_has_fromds(hdr->frame_control))
1465 /* this is not from AP */
1468 if (!ieee80211_is_data(hdr->frame_control))
1471 if (!ieee80211_has_moredata(hdr->frame_control)) {
1472 /* AP has no more frames buffered for us */
1473 local->pspolling = false;
1477 /* more data bit is set, let's request a new frame from the AP */
1478 ieee80211_send_pspoll(local, rx->sdata);
1483 static void sta_ps_start(struct sta_info *sta)
1485 struct ieee80211_sub_if_data *sdata = sta->sdata;
1486 struct ieee80211_local *local = sdata->local;
1490 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1491 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1492 ps = &sdata->bss->ps;
1496 atomic_inc(&ps->num_sta_ps);
1497 set_sta_flag(sta, WLAN_STA_PS_STA);
1498 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1499 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1500 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1501 sta->sta.addr, sta->sta.aid);
1503 ieee80211_clear_fast_xmit(sta);
1505 if (!sta->sta.txq[0])
1508 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1509 if (txq_has_queue(sta->sta.txq[tid]))
1510 set_bit(tid, &sta->txq_buffered_tids);
1512 clear_bit(tid, &sta->txq_buffered_tids);
1516 static void sta_ps_end(struct sta_info *sta)
1518 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1519 sta->sta.addr, sta->sta.aid);
1521 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1523 * Clear the flag only if the other one is still set
1524 * so that the TX path won't start TX'ing new frames
1525 * directly ... In the case that the driver flag isn't
1526 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1528 clear_sta_flag(sta, WLAN_STA_PS_STA);
1529 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1530 sta->sta.addr, sta->sta.aid);
1534 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1535 clear_sta_flag(sta, WLAN_STA_PS_STA);
1536 ieee80211_sta_ps_deliver_wakeup(sta);
1539 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1541 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1544 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1546 /* Don't let the same PS state be set twice */
1547 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1548 if ((start && in_ps) || (!start && !in_ps))
1558 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1560 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1562 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1564 if (test_sta_flag(sta, WLAN_STA_SP))
1567 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1568 ieee80211_sta_ps_deliver_poll_response(sta);
1570 set_sta_flag(sta, WLAN_STA_PSPOLL);
1572 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1574 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1576 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1577 int ac = ieee80211_ac_from_tid(tid);
1580 * If this AC is not trigger-enabled do nothing unless the
1581 * driver is calling us after it already checked.
1583 * NB: This could/should check a separate bitmap of trigger-
1584 * enabled queues, but for now we only implement uAPSD w/o
1585 * TSPEC changes to the ACs, so they're always the same.
1587 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1588 tid != IEEE80211_NUM_TIDS)
1591 /* if we are in a service period, do nothing */
1592 if (test_sta_flag(sta, WLAN_STA_SP))
1595 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1596 ieee80211_sta_ps_deliver_uapsd(sta);
1598 set_sta_flag(sta, WLAN_STA_UAPSD);
1600 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1602 static ieee80211_rx_result debug_noinline
1603 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1605 struct ieee80211_sub_if_data *sdata = rx->sdata;
1606 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1607 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1612 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1613 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1617 * The device handles station powersave, so don't do anything about
1618 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1619 * it to mac80211 since they're handled.)
1621 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1625 * Don't do anything if the station isn't already asleep. In
1626 * the uAPSD case, the station will probably be marked asleep,
1627 * in the PS-Poll case the station must be confused ...
1629 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1632 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1633 ieee80211_sta_pspoll(&rx->sta->sta);
1635 /* Free PS Poll skb here instead of returning RX_DROP that would
1636 * count as an dropped frame. */
1637 dev_kfree_skb(rx->skb);
1640 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1641 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1642 ieee80211_has_pm(hdr->frame_control) &&
1643 (ieee80211_is_data_qos(hdr->frame_control) ||
1644 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1645 u8 tid = ieee80211_get_tid(hdr);
1647 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1653 static ieee80211_rx_result debug_noinline
1654 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1656 struct sta_info *sta = rx->sta;
1657 struct sk_buff *skb = rx->skb;
1658 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1659 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1666 * Update last_rx only for IBSS packets which are for the current
1667 * BSSID and for station already AUTHORIZED to avoid keeping the
1668 * current IBSS network alive in cases where other STAs start
1669 * using different BSSID. This will also give the station another
1670 * chance to restart the authentication/authorization in case
1671 * something went wrong the first time.
1673 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1674 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1675 NL80211_IFTYPE_ADHOC);
1676 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1677 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1678 sta->rx_stats.last_rx = jiffies;
1679 if (ieee80211_is_data(hdr->frame_control) &&
1680 !is_multicast_ether_addr(hdr->addr1))
1681 sta->rx_stats.last_rate =
1682 sta_stats_encode_rate(status);
1684 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1685 sta->rx_stats.last_rx = jiffies;
1686 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1688 * Mesh beacons will update last_rx when if they are found to
1689 * match the current local configuration when processed.
1691 sta->rx_stats.last_rx = jiffies;
1692 if (ieee80211_is_data(hdr->frame_control))
1693 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1696 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1697 ieee80211_sta_rx_notify(rx->sdata, hdr);
1699 sta->rx_stats.fragments++;
1701 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1702 sta->rx_stats.bytes += rx->skb->len;
1703 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1705 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1706 sta->rx_stats.last_signal = status->signal;
1707 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1710 if (status->chains) {
1711 sta->rx_stats.chains = status->chains;
1712 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1713 int signal = status->chain_signal[i];
1715 if (!(status->chains & BIT(i)))
1718 sta->rx_stats.chain_signal_last[i] = signal;
1719 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1725 * Change STA power saving mode only at the end of a frame
1726 * exchange sequence, and only for a data or management
1727 * frame as specified in IEEE 802.11-2016 11.2.3.2
1729 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1730 !ieee80211_has_morefrags(hdr->frame_control) &&
1731 !is_multicast_ether_addr(hdr->addr1) &&
1732 (ieee80211_is_mgmt(hdr->frame_control) ||
1733 ieee80211_is_data(hdr->frame_control)) &&
1734 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1735 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1736 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1737 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1738 if (!ieee80211_has_pm(hdr->frame_control))
1741 if (ieee80211_has_pm(hdr->frame_control))
1746 /* mesh power save support */
1747 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1748 ieee80211_mps_rx_h_sta_process(sta, hdr);
1751 * Drop (qos-)data::nullfunc frames silently, since they
1752 * are used only to control station power saving mode.
1754 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1755 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1756 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1759 * If we receive a 4-addr nullfunc frame from a STA
1760 * that was not moved to a 4-addr STA vlan yet send
1761 * the event to userspace and for older hostapd drop
1762 * the frame to the monitor interface.
1764 if (ieee80211_has_a4(hdr->frame_control) &&
1765 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1766 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1767 !rx->sdata->u.vlan.sta))) {
1768 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1769 cfg80211_rx_unexpected_4addr_frame(
1770 rx->sdata->dev, sta->sta.addr,
1772 return RX_DROP_MONITOR;
1775 * Update counter and free packet here to avoid
1776 * counting this as a dropped packed.
1778 sta->rx_stats.packets++;
1779 dev_kfree_skb(rx->skb);
1784 } /* ieee80211_rx_h_sta_process */
1786 static ieee80211_rx_result debug_noinline
1787 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1789 struct sk_buff *skb = rx->skb;
1790 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1791 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1794 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1795 struct ieee80211_key *sta_ptk = NULL;
1796 int mmie_keyidx = -1;
1798 const struct ieee80211_cipher_scheme *cs = NULL;
1803 * There are four types of keys:
1804 * - GTK (group keys)
1805 * - IGTK (group keys for management frames)
1806 * - PTK (pairwise keys)
1807 * - STK (station-to-station pairwise keys)
1809 * When selecting a key, we have to distinguish between multicast
1810 * (including broadcast) and unicast frames, the latter can only
1811 * use PTKs and STKs while the former always use GTKs and IGTKs.
1812 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1813 * unicast frames can also use key indices like GTKs. Hence, if we
1814 * don't have a PTK/STK we check the key index for a WEP key.
1816 * Note that in a regular BSS, multicast frames are sent by the
1817 * AP only, associated stations unicast the frame to the AP first
1818 * which then multicasts it on their behalf.
1820 * There is also a slight problem in IBSS mode: GTKs are negotiated
1821 * with each station, that is something we don't currently handle.
1822 * The spec seems to expect that one negotiates the same key with
1823 * every station but there's no such requirement; VLANs could be
1827 /* start without a key */
1829 fc = hdr->frame_control;
1832 int keyid = rx->sta->ptk_idx;
1834 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1835 cs = rx->sta->cipher_scheme;
1836 keyid = ieee80211_get_cs_keyid(cs, rx->skb);
1837 if (unlikely(keyid < 0))
1838 return RX_DROP_UNUSABLE;
1840 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1843 if (!ieee80211_has_protected(fc))
1844 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1846 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1848 if ((status->flag & RX_FLAG_DECRYPTED) &&
1849 (status->flag & RX_FLAG_IV_STRIPPED))
1851 /* Skip decryption if the frame is not protected. */
1852 if (!ieee80211_has_protected(fc))
1854 } else if (mmie_keyidx >= 0) {
1855 /* Broadcast/multicast robust management frame / BIP */
1856 if ((status->flag & RX_FLAG_DECRYPTED) &&
1857 (status->flag & RX_FLAG_IV_STRIPPED))
1860 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1861 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1862 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1864 if (ieee80211_is_group_privacy_action(skb) &&
1865 test_sta_flag(rx->sta, WLAN_STA_MFP))
1866 return RX_DROP_MONITOR;
1868 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1871 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1872 } else if (!ieee80211_has_protected(fc)) {
1874 * The frame was not protected, so skip decryption. However, we
1875 * need to set rx->key if there is a key that could have been
1876 * used so that the frame may be dropped if encryption would
1877 * have been expected.
1879 struct ieee80211_key *key = NULL;
1880 struct ieee80211_sub_if_data *sdata = rx->sdata;
1883 if (ieee80211_is_mgmt(fc) &&
1884 is_multicast_ether_addr(hdr->addr1) &&
1885 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1889 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1890 key = rcu_dereference(rx->sta->gtk[i]);
1896 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1897 key = rcu_dereference(sdata->keys[i]);
1910 * The device doesn't give us the IV so we won't be
1911 * able to look up the key. That's ok though, we
1912 * don't need to decrypt the frame, we just won't
1913 * be able to keep statistics accurate.
1914 * Except for key threshold notifications, should
1915 * we somehow allow the driver to tell us which key
1916 * the hardware used if this flag is set?
1918 if ((status->flag & RX_FLAG_DECRYPTED) &&
1919 (status->flag & RX_FLAG_IV_STRIPPED))
1922 hdrlen = ieee80211_hdrlen(fc);
1925 keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
1927 if (unlikely(keyidx < 0))
1928 return RX_DROP_UNUSABLE;
1930 if (rx->skb->len < 8 + hdrlen)
1931 return RX_DROP_UNUSABLE; /* TODO: count this? */
1933 * no need to call ieee80211_wep_get_keyidx,
1934 * it verifies a bunch of things we've done already
1936 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1937 keyidx = keyid >> 6;
1940 /* check per-station GTK first, if multicast packet */
1941 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1942 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1944 /* if not found, try default key */
1946 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1949 * RSNA-protected unicast frames should always be
1950 * sent with pairwise or station-to-station keys,
1951 * but for WEP we allow using a key index as well.
1954 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1955 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1956 !is_multicast_ether_addr(hdr->addr1))
1962 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1963 return RX_DROP_MONITOR;
1965 /* TODO: add threshold stuff again */
1967 return RX_DROP_MONITOR;
1970 switch (rx->key->conf.cipher) {
1971 case WLAN_CIPHER_SUITE_WEP40:
1972 case WLAN_CIPHER_SUITE_WEP104:
1973 result = ieee80211_crypto_wep_decrypt(rx);
1975 case WLAN_CIPHER_SUITE_TKIP:
1976 result = ieee80211_crypto_tkip_decrypt(rx);
1978 case WLAN_CIPHER_SUITE_CCMP:
1979 result = ieee80211_crypto_ccmp_decrypt(
1980 rx, IEEE80211_CCMP_MIC_LEN);
1982 case WLAN_CIPHER_SUITE_CCMP_256:
1983 result = ieee80211_crypto_ccmp_decrypt(
1984 rx, IEEE80211_CCMP_256_MIC_LEN);
1986 case WLAN_CIPHER_SUITE_AES_CMAC:
1987 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1989 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1990 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1992 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1993 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1994 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1996 case WLAN_CIPHER_SUITE_GCMP:
1997 case WLAN_CIPHER_SUITE_GCMP_256:
1998 result = ieee80211_crypto_gcmp_decrypt(rx);
2001 result = ieee80211_crypto_hw_decrypt(rx);
2004 /* the hdr variable is invalid after the decrypt handlers */
2006 /* either the frame has been decrypted or will be dropped */
2007 status->flag |= RX_FLAG_DECRYPTED;
2012 static inline struct ieee80211_fragment_entry *
2013 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
2014 unsigned int frag, unsigned int seq, int rx_queue,
2015 struct sk_buff **skb)
2017 struct ieee80211_fragment_entry *entry;
2019 entry = &sdata->fragments[sdata->fragment_next++];
2020 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
2021 sdata->fragment_next = 0;
2023 if (!skb_queue_empty(&entry->skb_list))
2024 __skb_queue_purge(&entry->skb_list);
2026 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2028 entry->first_frag_time = jiffies;
2030 entry->rx_queue = rx_queue;
2031 entry->last_frag = frag;
2032 entry->check_sequential_pn = false;
2033 entry->extra_len = 0;
2038 static inline struct ieee80211_fragment_entry *
2039 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
2040 unsigned int frag, unsigned int seq,
2041 int rx_queue, struct ieee80211_hdr *hdr)
2043 struct ieee80211_fragment_entry *entry;
2046 idx = sdata->fragment_next;
2047 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2048 struct ieee80211_hdr *f_hdr;
2052 idx = IEEE80211_FRAGMENT_MAX - 1;
2054 entry = &sdata->fragments[idx];
2055 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2056 entry->rx_queue != rx_queue ||
2057 entry->last_frag + 1 != frag)
2060 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
2063 * Check ftype and addresses are equal, else check next fragment
2065 if (((hdr->frame_control ^ f_hdr->frame_control) &
2066 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2067 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2068 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2071 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2072 __skb_queue_purge(&entry->skb_list);
2081 static ieee80211_rx_result debug_noinline
2082 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2084 struct ieee80211_hdr *hdr;
2087 unsigned int frag, seq;
2088 struct ieee80211_fragment_entry *entry;
2089 struct sk_buff *skb;
2091 hdr = (struct ieee80211_hdr *)rx->skb->data;
2092 fc = hdr->frame_control;
2094 if (ieee80211_is_ctl(fc))
2097 sc = le16_to_cpu(hdr->seq_ctrl);
2098 frag = sc & IEEE80211_SCTL_FRAG;
2100 if (is_multicast_ether_addr(hdr->addr1)) {
2101 I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
2105 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2108 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2110 if (skb_linearize(rx->skb))
2111 return RX_DROP_UNUSABLE;
2114 * skb_linearize() might change the skb->data and
2115 * previously cached variables (in this case, hdr) need to
2116 * be refreshed with the new data.
2118 hdr = (struct ieee80211_hdr *)rx->skb->data;
2119 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2122 /* This is the first fragment of a new frame. */
2123 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
2124 rx->seqno_idx, &(rx->skb));
2126 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2127 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2128 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2129 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2130 ieee80211_has_protected(fc)) {
2131 int queue = rx->security_idx;
2133 /* Store CCMP/GCMP PN so that we can verify that the
2134 * next fragment has a sequential PN value.
2136 entry->check_sequential_pn = true;
2137 memcpy(entry->last_pn,
2138 rx->key->u.ccmp.rx_pn[queue],
2139 IEEE80211_CCMP_PN_LEN);
2140 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2142 offsetof(struct ieee80211_key,
2144 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2145 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2146 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2147 IEEE80211_GCMP_PN_LEN);
2152 /* This is a fragment for a frame that should already be pending in
2153 * fragment cache. Add this fragment to the end of the pending entry.
2155 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
2156 rx->seqno_idx, hdr);
2158 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2159 return RX_DROP_MONITOR;
2162 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2163 * MPDU PN values are not incrementing in steps of 1."
2164 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2165 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2167 if (entry->check_sequential_pn) {
2169 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
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 return RX_DROP_UNUSABLE;
2178 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2179 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2184 queue = rx->security_idx;
2185 rpn = rx->key->u.ccmp.rx_pn[queue];
2186 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2187 return RX_DROP_UNUSABLE;
2188 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2191 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2192 __skb_queue_tail(&entry->skb_list, rx->skb);
2193 entry->last_frag = frag;
2194 entry->extra_len += rx->skb->len;
2195 if (ieee80211_has_morefrags(fc)) {
2200 rx->skb = __skb_dequeue(&entry->skb_list);
2201 if (skb_tailroom(rx->skb) < entry->extra_len) {
2202 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2203 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2205 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2206 __skb_queue_purge(&entry->skb_list);
2207 return RX_DROP_UNUSABLE;
2210 while ((skb = __skb_dequeue(&entry->skb_list))) {
2211 skb_put_data(rx->skb, skb->data, skb->len);
2216 ieee80211_led_rx(rx->local);
2219 rx->sta->rx_stats.packets++;
2223 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2225 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2231 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2233 struct sk_buff *skb = rx->skb;
2234 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2237 * Pass through unencrypted frames if the hardware has
2238 * decrypted them already.
2240 if (status->flag & RX_FLAG_DECRYPTED)
2243 /* Drop unencrypted frames if key is set. */
2244 if (unlikely(!ieee80211_has_protected(fc) &&
2245 !ieee80211_is_nullfunc(fc) &&
2246 ieee80211_is_data(fc) && rx->key))
2252 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2254 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2255 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2256 __le16 fc = hdr->frame_control;
2259 * Pass through unencrypted frames if the hardware has
2260 * decrypted them already.
2262 if (status->flag & RX_FLAG_DECRYPTED)
2265 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2266 if (unlikely(!ieee80211_has_protected(fc) &&
2267 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2269 if (ieee80211_is_deauth(fc) ||
2270 ieee80211_is_disassoc(fc))
2271 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2276 /* BIP does not use Protected field, so need to check MMIE */
2277 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2278 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2279 if (ieee80211_is_deauth(fc) ||
2280 ieee80211_is_disassoc(fc))
2281 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2287 * When using MFP, Action frames are not allowed prior to
2288 * having configured keys.
2290 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2291 ieee80211_is_robust_mgmt_frame(rx->skb)))
2299 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2301 struct ieee80211_sub_if_data *sdata = rx->sdata;
2302 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2303 bool check_port_control = false;
2304 struct ethhdr *ehdr;
2307 *port_control = false;
2308 if (ieee80211_has_a4(hdr->frame_control) &&
2309 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2312 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2313 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2315 if (!sdata->u.mgd.use_4addr)
2318 check_port_control = true;
2321 if (is_multicast_ether_addr(hdr->addr1) &&
2322 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2325 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2329 ehdr = (struct ethhdr *) rx->skb->data;
2330 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2331 *port_control = true;
2332 else if (check_port_control)
2339 * requires that rx->skb is a frame with ethernet header
2341 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2343 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2344 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2345 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2348 * Allow EAPOL frames to us/the PAE group address regardless
2349 * of whether the frame was encrypted or not.
2351 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
2352 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2353 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
2356 if (ieee80211_802_1x_port_control(rx) ||
2357 ieee80211_drop_unencrypted(rx, fc))
2363 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2364 struct ieee80211_rx_data *rx)
2366 struct ieee80211_sub_if_data *sdata = rx->sdata;
2367 struct net_device *dev = sdata->dev;
2369 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2370 skb->protocol == cpu_to_be16(ETH_P_PREAUTH)) &&
2371 sdata->control_port_over_nl80211)) {
2372 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2373 bool noencrypt = status->flag & RX_FLAG_DECRYPTED;
2375 cfg80211_rx_control_port(dev, skb, noencrypt);
2378 /* deliver to local stack */
2380 napi_gro_receive(rx->napi, skb);
2382 netif_receive_skb(skb);
2387 * requires that rx->skb is a frame with ethernet header
2390 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2392 struct ieee80211_sub_if_data *sdata = rx->sdata;
2393 struct net_device *dev = sdata->dev;
2394 struct sk_buff *skb, *xmit_skb;
2395 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2396 struct sta_info *dsta;
2401 ieee80211_rx_stats(dev, skb->len);
2404 /* The seqno index has the same property as needed
2405 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2406 * for non-QoS-data frames. Here we know it's a data
2407 * frame, so count MSDUs.
2409 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
2410 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2411 u64_stats_update_end(&rx->sta->rx_stats.syncp);
2414 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2415 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2416 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2417 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2418 if (is_multicast_ether_addr(ehdr->h_dest) &&
2419 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2421 * send multicast frames both to higher layers in
2422 * local net stack and back to the wireless medium
2424 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2426 net_info_ratelimited("%s: failed to clone multicast frame\n",
2428 } else if (!is_multicast_ether_addr(ehdr->h_dest)) {
2429 dsta = sta_info_get(sdata, skb->data);
2432 * The destination station is associated to
2433 * this AP (in this VLAN), so send the frame
2434 * directly to it and do not pass it to local
2443 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2445 /* 'align' will only take the values 0 or 2 here since all
2446 * frames are required to be aligned to 2-byte boundaries
2447 * when being passed to mac80211; the code here works just
2448 * as well if that isn't true, but mac80211 assumes it can
2449 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2453 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2455 if (WARN_ON(skb_headroom(skb) < 3)) {
2459 u8 *data = skb->data;
2460 size_t len = skb_headlen(skb);
2462 memmove(skb->data, data, len);
2463 skb_set_tail_pointer(skb, len);
2470 skb->protocol = eth_type_trans(skb, dev);
2471 memset(skb->cb, 0, sizeof(skb->cb));
2473 ieee80211_deliver_skb_to_local_stack(skb, rx);
2478 * Send to wireless media and increase priority by 256 to
2479 * keep the received priority instead of reclassifying
2480 * the frame (see cfg80211_classify8021d).
2482 xmit_skb->priority += 256;
2483 xmit_skb->protocol = htons(ETH_P_802_3);
2484 skb_reset_network_header(xmit_skb);
2485 skb_reset_mac_header(xmit_skb);
2486 dev_queue_xmit(xmit_skb);
2490 static ieee80211_rx_result debug_noinline
2491 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2493 struct net_device *dev = rx->sdata->dev;
2494 struct sk_buff *skb = rx->skb;
2495 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2496 __le16 fc = hdr->frame_control;
2497 struct sk_buff_head frame_list;
2498 struct ethhdr ethhdr;
2499 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2501 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2504 } else switch (rx->sdata->vif.type) {
2505 case NL80211_IFTYPE_AP:
2506 case NL80211_IFTYPE_AP_VLAN:
2509 case NL80211_IFTYPE_STATION:
2511 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2514 case NL80211_IFTYPE_MESH_POINT:
2522 __skb_queue_head_init(&frame_list);
2524 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2525 rx->sdata->vif.addr,
2526 rx->sdata->vif.type,
2528 return RX_DROP_UNUSABLE;
2530 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2531 rx->sdata->vif.type,
2532 rx->local->hw.extra_tx_headroom,
2533 check_da, check_sa);
2535 while (!skb_queue_empty(&frame_list)) {
2536 rx->skb = __skb_dequeue(&frame_list);
2538 if (!ieee80211_frame_allowed(rx, fc)) {
2539 dev_kfree_skb(rx->skb);
2543 ieee80211_deliver_skb(rx);
2549 static ieee80211_rx_result debug_noinline
2550 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2552 struct sk_buff *skb = rx->skb;
2553 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2554 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2555 __le16 fc = hdr->frame_control;
2557 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2560 if (unlikely(!ieee80211_is_data(fc)))
2563 if (unlikely(!ieee80211_is_data_present(fc)))
2564 return RX_DROP_MONITOR;
2566 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2567 switch (rx->sdata->vif.type) {
2568 case NL80211_IFTYPE_AP_VLAN:
2569 if (!rx->sdata->u.vlan.sta)
2570 return RX_DROP_UNUSABLE;
2572 case NL80211_IFTYPE_STATION:
2573 if (!rx->sdata->u.mgd.use_4addr)
2574 return RX_DROP_UNUSABLE;
2577 return RX_DROP_UNUSABLE;
2581 if (is_multicast_ether_addr(hdr->addr1))
2582 return RX_DROP_UNUSABLE;
2584 return __ieee80211_rx_h_amsdu(rx, 0);
2587 #ifdef CONFIG_MAC80211_MESH
2588 static ieee80211_rx_result
2589 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2591 struct ieee80211_hdr *fwd_hdr, *hdr;
2592 struct ieee80211_tx_info *info;
2593 struct ieee80211s_hdr *mesh_hdr;
2594 struct sk_buff *skb = rx->skb, *fwd_skb;
2595 struct ieee80211_local *local = rx->local;
2596 struct ieee80211_sub_if_data *sdata = rx->sdata;
2597 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2600 hdr = (struct ieee80211_hdr *) skb->data;
2601 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2603 /* make sure fixed part of mesh header is there, also checks skb len */
2604 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2605 return RX_DROP_MONITOR;
2607 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2609 /* make sure full mesh header is there, also checks skb len */
2610 if (!pskb_may_pull(rx->skb,
2611 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2612 return RX_DROP_MONITOR;
2614 /* reload pointers */
2615 hdr = (struct ieee80211_hdr *) skb->data;
2616 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2618 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2619 return RX_DROP_MONITOR;
2621 /* frame is in RMC, don't forward */
2622 if (ieee80211_is_data(hdr->frame_control) &&
2623 is_multicast_ether_addr(hdr->addr1) &&
2624 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2625 return RX_DROP_MONITOR;
2627 if (!ieee80211_is_data(hdr->frame_control))
2631 return RX_DROP_MONITOR;
2633 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2634 struct mesh_path *mppath;
2638 if (is_multicast_ether_addr(hdr->addr1)) {
2639 mpp_addr = hdr->addr3;
2640 proxied_addr = mesh_hdr->eaddr1;
2641 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2642 MESH_FLAGS_AE_A5_A6) {
2643 /* has_a4 already checked in ieee80211_rx_mesh_check */
2644 mpp_addr = hdr->addr4;
2645 proxied_addr = mesh_hdr->eaddr2;
2647 return RX_DROP_MONITOR;
2651 mppath = mpp_path_lookup(sdata, proxied_addr);
2653 mpp_path_add(sdata, proxied_addr, mpp_addr);
2655 spin_lock_bh(&mppath->state_lock);
2656 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2657 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2658 mppath->exp_time = jiffies;
2659 spin_unlock_bh(&mppath->state_lock);
2664 /* Frame has reached destination. Don't forward */
2665 if (!is_multicast_ether_addr(hdr->addr1) &&
2666 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2669 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2670 q = sdata->vif.hw_queue[ac];
2671 if (ieee80211_queue_stopped(&local->hw, q)) {
2672 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2673 return RX_DROP_MONITOR;
2675 skb_set_queue_mapping(skb, q);
2677 if (!--mesh_hdr->ttl) {
2678 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
2682 if (!ifmsh->mshcfg.dot11MeshForwarding)
2685 fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2686 sdata->encrypt_headroom, 0, GFP_ATOMIC);
2690 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2691 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2692 info = IEEE80211_SKB_CB(fwd_skb);
2693 memset(info, 0, sizeof(*info));
2694 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2695 info->control.vif = &rx->sdata->vif;
2696 info->control.jiffies = jiffies;
2697 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2698 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2699 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2700 /* update power mode indication when forwarding */
2701 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2702 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2703 /* mesh power mode flags updated in mesh_nexthop_lookup */
2704 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2706 /* unable to resolve next hop */
2707 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2709 WLAN_REASON_MESH_PATH_NOFORWARD,
2711 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2713 return RX_DROP_MONITOR;
2716 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2717 ieee80211_add_pending_skb(local, fwd_skb);
2719 if (is_multicast_ether_addr(hdr->addr1))
2721 return RX_DROP_MONITOR;
2725 static ieee80211_rx_result debug_noinline
2726 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2728 struct ieee80211_sub_if_data *sdata = rx->sdata;
2729 struct ieee80211_local *local = rx->local;
2730 struct net_device *dev = sdata->dev;
2731 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2732 __le16 fc = hdr->frame_control;
2736 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2739 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2740 return RX_DROP_MONITOR;
2743 * Send unexpected-4addr-frame event to hostapd. For older versions,
2744 * also drop the frame to cooked monitor interfaces.
2746 if (ieee80211_has_a4(hdr->frame_control) &&
2747 sdata->vif.type == NL80211_IFTYPE_AP) {
2749 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2750 cfg80211_rx_unexpected_4addr_frame(
2751 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2752 return RX_DROP_MONITOR;
2755 err = __ieee80211_data_to_8023(rx, &port_control);
2757 return RX_DROP_UNUSABLE;
2759 if (!ieee80211_frame_allowed(rx, fc))
2760 return RX_DROP_MONITOR;
2762 /* directly handle TDLS channel switch requests/responses */
2763 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2764 cpu_to_be16(ETH_P_TDLS))) {
2765 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2767 if (pskb_may_pull(rx->skb,
2768 offsetof(struct ieee80211_tdls_data, u)) &&
2769 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2770 tf->category == WLAN_CATEGORY_TDLS &&
2771 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2772 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2773 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2774 schedule_work(&local->tdls_chsw_work);
2776 rx->sta->rx_stats.packets++;
2782 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2783 unlikely(port_control) && sdata->bss) {
2784 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2792 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2793 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2794 !is_multicast_ether_addr(
2795 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2796 (!local->scanning &&
2797 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
2798 mod_timer(&local->dynamic_ps_timer, jiffies +
2799 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2801 ieee80211_deliver_skb(rx);
2806 static ieee80211_rx_result debug_noinline
2807 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2809 struct sk_buff *skb = rx->skb;
2810 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2811 struct tid_ampdu_rx *tid_agg_rx;
2815 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2818 if (ieee80211_is_back_req(bar->frame_control)) {
2820 __le16 control, start_seq_num;
2821 } __packed bar_data;
2822 struct ieee80211_event event = {
2823 .type = BAR_RX_EVENT,
2827 return RX_DROP_MONITOR;
2829 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2830 &bar_data, sizeof(bar_data)))
2831 return RX_DROP_MONITOR;
2833 tid = le16_to_cpu(bar_data.control) >> 12;
2835 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
2836 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
2837 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
2838 WLAN_BACK_RECIPIENT,
2839 WLAN_REASON_QSTA_REQUIRE_SETUP);
2841 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2843 return RX_DROP_MONITOR;
2845 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2846 event.u.ba.tid = tid;
2847 event.u.ba.ssn = start_seq_num;
2848 event.u.ba.sta = &rx->sta->sta;
2850 /* reset session timer */
2851 if (tid_agg_rx->timeout)
2852 mod_timer(&tid_agg_rx->session_timer,
2853 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2855 spin_lock(&tid_agg_rx->reorder_lock);
2856 /* release stored frames up to start of BAR */
2857 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2858 start_seq_num, frames);
2859 spin_unlock(&tid_agg_rx->reorder_lock);
2861 drv_event_callback(rx->local, rx->sdata, &event);
2868 * After this point, we only want management frames,
2869 * so we can drop all remaining control frames to
2870 * cooked monitor interfaces.
2872 return RX_DROP_MONITOR;
2875 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2876 struct ieee80211_mgmt *mgmt,
2879 struct ieee80211_local *local = sdata->local;
2880 struct sk_buff *skb;
2881 struct ieee80211_mgmt *resp;
2883 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2884 /* Not to own unicast address */
2888 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2889 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2890 /* Not from the current AP or not associated yet. */
2894 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2895 /* Too short SA Query request frame */
2899 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2903 skb_reserve(skb, local->hw.extra_tx_headroom);
2904 resp = skb_put_zero(skb, 24);
2905 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2906 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2907 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2908 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2909 IEEE80211_STYPE_ACTION);
2910 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2911 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2912 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2913 memcpy(resp->u.action.u.sa_query.trans_id,
2914 mgmt->u.action.u.sa_query.trans_id,
2915 WLAN_SA_QUERY_TR_ID_LEN);
2917 ieee80211_tx_skb(sdata, skb);
2920 static ieee80211_rx_result debug_noinline
2921 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2923 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2924 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2927 * From here on, look only at management frames.
2928 * Data and control frames are already handled,
2929 * and unknown (reserved) frames are useless.
2931 if (rx->skb->len < 24)
2932 return RX_DROP_MONITOR;
2934 if (!ieee80211_is_mgmt(mgmt->frame_control))
2935 return RX_DROP_MONITOR;
2937 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2938 ieee80211_is_beacon(mgmt->frame_control) &&
2939 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2942 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
2943 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
2944 sig = status->signal;
2946 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2947 rx->skb->data, rx->skb->len,
2949 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2952 if (ieee80211_drop_unencrypted_mgmt(rx))
2953 return RX_DROP_UNUSABLE;
2958 static ieee80211_rx_result debug_noinline
2959 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2961 struct ieee80211_local *local = rx->local;
2962 struct ieee80211_sub_if_data *sdata = rx->sdata;
2963 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2964 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2965 int len = rx->skb->len;
2967 if (!ieee80211_is_action(mgmt->frame_control))
2970 /* drop too small frames */
2971 if (len < IEEE80211_MIN_ACTION_SIZE)
2972 return RX_DROP_UNUSABLE;
2974 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
2975 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2976 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
2977 return RX_DROP_UNUSABLE;
2979 switch (mgmt->u.action.category) {
2980 case WLAN_CATEGORY_HT:
2981 /* reject HT action frames from stations not supporting HT */
2982 if (!rx->sta->sta.ht_cap.ht_supported)
2985 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2986 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2987 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2988 sdata->vif.type != NL80211_IFTYPE_AP &&
2989 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2992 /* verify action & smps_control/chanwidth are present */
2993 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2996 switch (mgmt->u.action.u.ht_smps.action) {
2997 case WLAN_HT_ACTION_SMPS: {
2998 struct ieee80211_supported_band *sband;
2999 enum ieee80211_smps_mode smps_mode;
3000 struct sta_opmode_info sta_opmode = {};
3002 /* convert to HT capability */
3003 switch (mgmt->u.action.u.ht_smps.smps_control) {
3004 case WLAN_HT_SMPS_CONTROL_DISABLED:
3005 smps_mode = IEEE80211_SMPS_OFF;
3007 case WLAN_HT_SMPS_CONTROL_STATIC:
3008 smps_mode = IEEE80211_SMPS_STATIC;
3010 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3011 smps_mode = IEEE80211_SMPS_DYNAMIC;
3017 /* if no change do nothing */
3018 if (rx->sta->sta.smps_mode == smps_mode)
3020 rx->sta->sta.smps_mode = smps_mode;
3021 sta_opmode.smps_mode =
3022 ieee80211_smps_mode_to_smps_mode(smps_mode);
3023 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3025 sband = rx->local->hw.wiphy->bands[status->band];
3027 rate_control_rate_update(local, sband, rx->sta,
3028 IEEE80211_RC_SMPS_CHANGED);
3029 cfg80211_sta_opmode_change_notify(sdata->dev,
3035 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3036 struct ieee80211_supported_band *sband;
3037 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3038 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3039 struct sta_opmode_info sta_opmode = {};
3041 /* If it doesn't support 40 MHz it can't change ... */
3042 if (!(rx->sta->sta.ht_cap.cap &
3043 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3046 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3047 max_bw = IEEE80211_STA_RX_BW_20;
3049 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
3051 /* set cur_max_bandwidth and recalc sta bw */
3052 rx->sta->cur_max_bandwidth = max_bw;
3053 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
3055 if (rx->sta->sta.bandwidth == new_bw)
3058 rx->sta->sta.bandwidth = new_bw;
3059 sband = rx->local->hw.wiphy->bands[status->band];
3061 ieee80211_sta_rx_bw_to_chan_width(rx->sta);
3062 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3064 rate_control_rate_update(local, sband, rx->sta,
3065 IEEE80211_RC_BW_CHANGED);
3066 cfg80211_sta_opmode_change_notify(sdata->dev,
3077 case WLAN_CATEGORY_PUBLIC:
3078 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3080 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3084 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3086 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3087 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3089 if (len < offsetof(struct ieee80211_mgmt,
3090 u.action.u.ext_chan_switch.variable))
3093 case WLAN_CATEGORY_VHT:
3094 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3095 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3096 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3097 sdata->vif.type != NL80211_IFTYPE_AP &&
3098 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3101 /* verify action code is present */
3102 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3105 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3106 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3107 /* verify opmode is present */
3108 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3112 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3113 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3121 case WLAN_CATEGORY_BACK:
3122 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3123 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3124 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3125 sdata->vif.type != NL80211_IFTYPE_AP &&
3126 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3129 /* verify action_code is present */
3130 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3133 switch (mgmt->u.action.u.addba_req.action_code) {
3134 case WLAN_ACTION_ADDBA_REQ:
3135 if (len < (IEEE80211_MIN_ACTION_SIZE +
3136 sizeof(mgmt->u.action.u.addba_req)))
3139 case WLAN_ACTION_ADDBA_RESP:
3140 if (len < (IEEE80211_MIN_ACTION_SIZE +
3141 sizeof(mgmt->u.action.u.addba_resp)))
3144 case WLAN_ACTION_DELBA:
3145 if (len < (IEEE80211_MIN_ACTION_SIZE +
3146 sizeof(mgmt->u.action.u.delba)))
3154 case WLAN_CATEGORY_SPECTRUM_MGMT:
3155 /* verify action_code is present */
3156 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3159 switch (mgmt->u.action.u.measurement.action_code) {
3160 case WLAN_ACTION_SPCT_MSR_REQ:
3161 if (status->band != NL80211_BAND_5GHZ)
3164 if (len < (IEEE80211_MIN_ACTION_SIZE +
3165 sizeof(mgmt->u.action.u.measurement)))
3168 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3171 ieee80211_process_measurement_req(sdata, mgmt, len);
3173 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3175 if (len < (IEEE80211_MIN_ACTION_SIZE +
3176 sizeof(mgmt->u.action.u.chan_switch)))
3179 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3180 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3181 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3184 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3185 bssid = sdata->u.mgd.bssid;
3186 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3187 bssid = sdata->u.ibss.bssid;
3188 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3193 if (!ether_addr_equal(mgmt->bssid, bssid))
3200 case WLAN_CATEGORY_SA_QUERY:
3201 if (len < (IEEE80211_MIN_ACTION_SIZE +
3202 sizeof(mgmt->u.action.u.sa_query)))
3205 switch (mgmt->u.action.u.sa_query.action) {
3206 case WLAN_ACTION_SA_QUERY_REQUEST:
3207 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3209 ieee80211_process_sa_query_req(sdata, mgmt, len);
3213 case WLAN_CATEGORY_SELF_PROTECTED:
3214 if (len < (IEEE80211_MIN_ACTION_SIZE +
3215 sizeof(mgmt->u.action.u.self_prot.action_code)))
3218 switch (mgmt->u.action.u.self_prot.action_code) {
3219 case WLAN_SP_MESH_PEERING_OPEN:
3220 case WLAN_SP_MESH_PEERING_CLOSE:
3221 case WLAN_SP_MESH_PEERING_CONFIRM:
3222 if (!ieee80211_vif_is_mesh(&sdata->vif))
3224 if (sdata->u.mesh.user_mpm)
3225 /* userspace handles this frame */
3228 case WLAN_SP_MGK_INFORM:
3229 case WLAN_SP_MGK_ACK:
3230 if (!ieee80211_vif_is_mesh(&sdata->vif))
3235 case WLAN_CATEGORY_MESH_ACTION:
3236 if (len < (IEEE80211_MIN_ACTION_SIZE +
3237 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3240 if (!ieee80211_vif_is_mesh(&sdata->vif))
3242 if (mesh_action_is_path_sel(mgmt) &&
3243 !mesh_path_sel_is_hwmp(sdata))
3251 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3252 /* will return in the next handlers */
3257 rx->sta->rx_stats.packets++;
3258 dev_kfree_skb(rx->skb);
3262 skb_queue_tail(&sdata->skb_queue, rx->skb);
3263 ieee80211_queue_work(&local->hw, &sdata->work);
3265 rx->sta->rx_stats.packets++;
3269 static ieee80211_rx_result debug_noinline
3270 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3272 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3275 /* skip known-bad action frames and return them in the next handler */
3276 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3280 * Getting here means the kernel doesn't know how to handle
3281 * it, but maybe userspace does ... include returned frames
3282 * so userspace can register for those to know whether ones
3283 * it transmitted were processed or returned.
3286 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3287 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3288 sig = status->signal;
3290 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
3291 rx->skb->data, rx->skb->len, 0)) {
3293 rx->sta->rx_stats.packets++;
3294 dev_kfree_skb(rx->skb);
3301 static ieee80211_rx_result debug_noinline
3302 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3304 struct ieee80211_local *local = rx->local;
3305 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3306 struct sk_buff *nskb;
3307 struct ieee80211_sub_if_data *sdata = rx->sdata;
3308 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3310 if (!ieee80211_is_action(mgmt->frame_control))
3314 * For AP mode, hostapd is responsible for handling any action
3315 * frames that we didn't handle, including returning unknown
3316 * ones. For all other modes we will return them to the sender,
3317 * setting the 0x80 bit in the action category, as required by
3318 * 802.11-2012 9.24.4.
3319 * Newer versions of hostapd shall also use the management frame
3320 * registration mechanisms, but older ones still use cooked
3321 * monitor interfaces so push all frames there.
3323 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3324 (sdata->vif.type == NL80211_IFTYPE_AP ||
3325 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3326 return RX_DROP_MONITOR;
3328 if (is_multicast_ether_addr(mgmt->da))
3329 return RX_DROP_MONITOR;
3331 /* do not return rejected action frames */
3332 if (mgmt->u.action.category & 0x80)
3333 return RX_DROP_UNUSABLE;
3335 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3338 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3340 nmgmt->u.action.category |= 0x80;
3341 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3342 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3344 memset(nskb->cb, 0, sizeof(nskb->cb));
3346 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3347 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3349 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3350 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3351 IEEE80211_TX_CTL_NO_CCK_RATE;
3352 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3354 local->hw.offchannel_tx_hw_queue;
3357 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3360 dev_kfree_skb(rx->skb);
3364 static ieee80211_rx_result debug_noinline
3365 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3367 struct ieee80211_sub_if_data *sdata = rx->sdata;
3368 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3371 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3373 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3374 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3375 sdata->vif.type != NL80211_IFTYPE_OCB &&
3376 sdata->vif.type != NL80211_IFTYPE_STATION)
3377 return RX_DROP_MONITOR;
3380 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3381 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3382 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3383 /* process for all: mesh, mlme, ibss */
3385 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3386 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3387 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3388 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3389 if (is_multicast_ether_addr(mgmt->da) &&
3390 !is_broadcast_ether_addr(mgmt->da))
3391 return RX_DROP_MONITOR;
3393 /* process only for station */
3394 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3395 return RX_DROP_MONITOR;
3397 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3398 /* process only for ibss and mesh */
3399 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3400 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3401 return RX_DROP_MONITOR;
3404 return RX_DROP_MONITOR;
3407 /* queue up frame and kick off work to process it */
3408 skb_queue_tail(&sdata->skb_queue, rx->skb);
3409 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3411 rx->sta->rx_stats.packets++;
3416 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3417 struct ieee80211_rate *rate)
3419 struct ieee80211_sub_if_data *sdata;
3420 struct ieee80211_local *local = rx->local;
3421 struct sk_buff *skb = rx->skb, *skb2;
3422 struct net_device *prev_dev = NULL;
3423 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3424 int needed_headroom;
3427 * If cooked monitor has been processed already, then
3428 * don't do it again. If not, set the flag.
3430 if (rx->flags & IEEE80211_RX_CMNTR)
3432 rx->flags |= IEEE80211_RX_CMNTR;
3434 /* If there are no cooked monitor interfaces, just free the SKB */
3435 if (!local->cooked_mntrs)
3438 /* vendor data is long removed here */
3439 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3440 /* room for the radiotap header based on driver features */
3441 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3443 if (skb_headroom(skb) < needed_headroom &&
3444 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3447 /* prepend radiotap information */
3448 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3451 skb_reset_mac_header(skb);
3452 skb->ip_summed = CHECKSUM_UNNECESSARY;
3453 skb->pkt_type = PACKET_OTHERHOST;
3454 skb->protocol = htons(ETH_P_802_2);
3456 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3457 if (!ieee80211_sdata_running(sdata))
3460 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3461 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3465 skb2 = skb_clone(skb, GFP_ATOMIC);
3467 skb2->dev = prev_dev;
3468 netif_receive_skb(skb2);
3472 prev_dev = sdata->dev;
3473 ieee80211_rx_stats(sdata->dev, skb->len);
3477 skb->dev = prev_dev;
3478 netif_receive_skb(skb);
3486 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3487 ieee80211_rx_result res)
3490 case RX_DROP_MONITOR:
3491 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3493 rx->sta->rx_stats.dropped++;
3496 struct ieee80211_rate *rate = NULL;
3497 struct ieee80211_supported_band *sband;
3498 struct ieee80211_rx_status *status;
3500 status = IEEE80211_SKB_RXCB((rx->skb));
3502 sband = rx->local->hw.wiphy->bands[status->band];
3503 if (status->encoding == RX_ENC_LEGACY)
3504 rate = &sband->bitrates[status->rate_idx];
3506 ieee80211_rx_cooked_monitor(rx, rate);
3509 case RX_DROP_UNUSABLE:
3510 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3512 rx->sta->rx_stats.dropped++;
3513 dev_kfree_skb(rx->skb);
3516 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3521 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3522 struct sk_buff_head *frames)
3524 ieee80211_rx_result res = RX_DROP_MONITOR;
3525 struct sk_buff *skb;
3527 #define CALL_RXH(rxh) \
3530 if (res != RX_CONTINUE) \
3534 /* Lock here to avoid hitting all of the data used in the RX
3535 * path (e.g. key data, station data, ...) concurrently when
3536 * a frame is released from the reorder buffer due to timeout
3537 * from the timer, potentially concurrently with RX from the
3540 spin_lock_bh(&rx->local->rx_path_lock);
3542 while ((skb = __skb_dequeue(frames))) {
3544 * all the other fields are valid across frames
3545 * that belong to an aMPDU since they are on the
3546 * same TID from the same station
3550 CALL_RXH(ieee80211_rx_h_check_more_data);
3551 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3552 CALL_RXH(ieee80211_rx_h_sta_process);
3553 CALL_RXH(ieee80211_rx_h_decrypt);
3554 CALL_RXH(ieee80211_rx_h_defragment);
3555 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3556 /* must be after MMIC verify so header is counted in MPDU mic */
3557 #ifdef CONFIG_MAC80211_MESH
3558 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3559 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3561 CALL_RXH(ieee80211_rx_h_amsdu);
3562 CALL_RXH(ieee80211_rx_h_data);
3564 /* special treatment -- needs the queue */
3565 res = ieee80211_rx_h_ctrl(rx, frames);
3566 if (res != RX_CONTINUE)
3569 CALL_RXH(ieee80211_rx_h_mgmt_check);
3570 CALL_RXH(ieee80211_rx_h_action);
3571 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3572 CALL_RXH(ieee80211_rx_h_action_return);
3573 CALL_RXH(ieee80211_rx_h_mgmt);
3576 ieee80211_rx_handlers_result(rx, res);
3581 spin_unlock_bh(&rx->local->rx_path_lock);
3584 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3586 struct sk_buff_head reorder_release;
3587 ieee80211_rx_result res = RX_DROP_MONITOR;
3589 __skb_queue_head_init(&reorder_release);
3591 #define CALL_RXH(rxh) \
3594 if (res != RX_CONTINUE) \
3598 CALL_RXH(ieee80211_rx_h_check_dup);
3599 CALL_RXH(ieee80211_rx_h_check);
3601 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3603 ieee80211_rx_handlers(rx, &reorder_release);
3607 ieee80211_rx_handlers_result(rx, res);
3613 * This function makes calls into the RX path, therefore
3614 * it has to be invoked under RCU read lock.
3616 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3618 struct sk_buff_head frames;
3619 struct ieee80211_rx_data rx = {
3621 .sdata = sta->sdata,
3622 .local = sta->local,
3623 /* This is OK -- must be QoS data frame */
3624 .security_idx = tid,
3626 .napi = NULL, /* must be NULL to not have races */
3628 struct tid_ampdu_rx *tid_agg_rx;
3630 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3634 __skb_queue_head_init(&frames);
3636 spin_lock(&tid_agg_rx->reorder_lock);
3637 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3638 spin_unlock(&tid_agg_rx->reorder_lock);
3640 if (!skb_queue_empty(&frames)) {
3641 struct ieee80211_event event = {
3642 .type = BA_FRAME_TIMEOUT,
3644 .u.ba.sta = &sta->sta,
3646 drv_event_callback(rx.local, rx.sdata, &event);
3649 ieee80211_rx_handlers(&rx, &frames);
3652 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3653 u16 ssn, u64 filtered,
3656 struct sta_info *sta;
3657 struct tid_ampdu_rx *tid_agg_rx;
3658 struct sk_buff_head frames;
3659 struct ieee80211_rx_data rx = {
3660 /* This is OK -- must be QoS data frame */
3661 .security_idx = tid,
3666 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3669 __skb_queue_head_init(&frames);
3671 sta = container_of(pubsta, struct sta_info, sta);
3674 rx.sdata = sta->sdata;
3675 rx.local = sta->local;
3678 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3682 spin_lock_bh(&tid_agg_rx->reorder_lock);
3684 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3687 /* release all frames in the reorder buffer */
3688 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3689 IEEE80211_SN_MODULO;
3690 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3692 /* update ssn to match received ssn */
3693 tid_agg_rx->head_seq_num = ssn;
3695 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3699 /* handle the case that received ssn is behind the mac ssn.
3700 * it can be tid_agg_rx->buf_size behind and still be valid */
3701 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3702 if (diff >= tid_agg_rx->buf_size) {
3703 tid_agg_rx->reorder_buf_filtered = 0;
3706 filtered = filtered >> diff;
3710 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3711 int index = (ssn + i) % tid_agg_rx->buf_size;
3713 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3714 if (filtered & BIT_ULL(i))
3715 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3718 /* now process also frames that the filter marking released */
3719 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3722 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3724 ieee80211_rx_handlers(&rx, &frames);
3729 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3731 /* main receive path */
3733 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3735 struct ieee80211_sub_if_data *sdata = rx->sdata;
3736 struct sk_buff *skb = rx->skb;
3737 struct ieee80211_hdr *hdr = (void *)skb->data;
3738 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3739 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3740 bool multicast = is_multicast_ether_addr(hdr->addr1);
3742 switch (sdata->vif.type) {
3743 case NL80211_IFTYPE_STATION:
3744 if (!bssid && !sdata->u.mgd.use_4addr)
3748 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3749 case NL80211_IFTYPE_ADHOC:
3752 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3753 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
3755 if (ieee80211_is_beacon(hdr->frame_control))
3757 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3760 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3764 if (status->encoding != RX_ENC_LEGACY)
3765 rate_idx = 0; /* TODO: HT/VHT rates */
3767 rate_idx = status->rate_idx;
3768 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3772 case NL80211_IFTYPE_OCB:
3775 if (!ieee80211_is_data_present(hdr->frame_control))
3777 if (!is_broadcast_ether_addr(bssid))
3780 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3784 if (status->encoding != RX_ENC_LEGACY)
3785 rate_idx = 0; /* TODO: HT rates */
3787 rate_idx = status->rate_idx;
3788 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3792 case NL80211_IFTYPE_MESH_POINT:
3793 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
3797 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3798 case NL80211_IFTYPE_AP_VLAN:
3799 case NL80211_IFTYPE_AP:
3801 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3803 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3805 * Accept public action frames even when the
3806 * BSSID doesn't match, this is used for P2P
3807 * and location updates. Note that mac80211
3808 * itself never looks at these frames.
3811 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3813 if (ieee80211_is_public_action(hdr, skb->len))
3815 return ieee80211_is_beacon(hdr->frame_control);
3818 if (!ieee80211_has_tods(hdr->frame_control)) {
3819 /* ignore data frames to TDLS-peers */
3820 if (ieee80211_is_data(hdr->frame_control))
3822 /* ignore action frames to TDLS-peers */
3823 if (ieee80211_is_action(hdr->frame_control) &&
3824 !is_broadcast_ether_addr(bssid) &&
3825 !ether_addr_equal(bssid, hdr->addr1))
3830 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3831 * the BSSID - we've checked that already but may have accepted
3832 * the wildcard (ff:ff:ff:ff:ff:ff).
3835 * The BSSID of the Data frame is determined as follows:
3836 * a) If the STA is contained within an AP or is associated
3837 * with an AP, the BSSID is the address currently in use
3838 * by the STA contained in the AP.
3840 * So we should not accept data frames with an address that's
3843 * Accepting it also opens a security problem because stations
3844 * could encrypt it with the GTK and inject traffic that way.
3846 if (ieee80211_is_data(hdr->frame_control) && multicast)
3850 case NL80211_IFTYPE_WDS:
3851 if (bssid || !ieee80211_is_data(hdr->frame_control))
3853 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3854 case NL80211_IFTYPE_P2P_DEVICE:
3855 return ieee80211_is_public_action(hdr, skb->len) ||
3856 ieee80211_is_probe_req(hdr->frame_control) ||
3857 ieee80211_is_probe_resp(hdr->frame_control) ||
3858 ieee80211_is_beacon(hdr->frame_control);
3859 case NL80211_IFTYPE_NAN:
3860 /* Currently no frames on NAN interface are allowed */
3870 void ieee80211_check_fast_rx(struct sta_info *sta)
3872 struct ieee80211_sub_if_data *sdata = sta->sdata;
3873 struct ieee80211_local *local = sdata->local;
3874 struct ieee80211_key *key;
3875 struct ieee80211_fast_rx fastrx = {
3877 .vif_type = sdata->vif.type,
3878 .control_port_protocol = sdata->control_port_protocol,
3879 }, *old, *new = NULL;
3880 bool assign = false;
3882 /* use sparse to check that we don't return without updating */
3883 __acquire(check_fast_rx);
3885 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
3886 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
3887 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
3888 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
3890 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
3892 /* fast-rx doesn't do reordering */
3893 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
3894 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
3897 switch (sdata->vif.type) {
3898 case NL80211_IFTYPE_STATION:
3899 if (sta->sta.tdls) {
3900 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3901 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3902 fastrx.expected_ds_bits = 0;
3904 fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
3905 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3906 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3907 fastrx.expected_ds_bits =
3908 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3911 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
3912 fastrx.expected_ds_bits |=
3913 cpu_to_le16(IEEE80211_FCTL_TODS);
3914 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3915 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3918 if (!sdata->u.mgd.powersave)
3921 /* software powersave is a huge mess, avoid all of it */
3922 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
3924 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3925 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3928 case NL80211_IFTYPE_AP_VLAN:
3929 case NL80211_IFTYPE_AP:
3930 /* parallel-rx requires this, at least with calls to
3931 * ieee80211_sta_ps_transition()
3933 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
3935 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3936 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3937 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
3939 fastrx.internal_forward =
3940 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
3941 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
3942 !sdata->u.vlan.sta);
3944 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3945 sdata->u.vlan.sta) {
3946 fastrx.expected_ds_bits |=
3947 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3948 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3949 fastrx.internal_forward = 0;
3957 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3961 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
3963 switch (key->conf.cipher) {
3964 case WLAN_CIPHER_SUITE_TKIP:
3965 /* we don't want to deal with MMIC in fast-rx */
3967 case WLAN_CIPHER_SUITE_CCMP:
3968 case WLAN_CIPHER_SUITE_CCMP_256:
3969 case WLAN_CIPHER_SUITE_GCMP:
3970 case WLAN_CIPHER_SUITE_GCMP_256:
3973 /* we also don't want to deal with WEP or cipher scheme
3974 * since those require looking up the key idx in the
3975 * frame, rather than assuming the PTK is used
3976 * (we need to revisit this once we implement the real
3977 * PTK index, which is now valid in the spec, but we
3978 * haven't implemented that part yet)
3984 fastrx.icv_len = key->conf.icv_len;
3991 __release(check_fast_rx);
3994 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
3996 spin_lock_bh(&sta->lock);
3997 old = rcu_dereference_protected(sta->fast_rx, true);
3998 rcu_assign_pointer(sta->fast_rx, new);
3999 spin_unlock_bh(&sta->lock);
4002 kfree_rcu(old, rcu_head);
4005 void ieee80211_clear_fast_rx(struct sta_info *sta)
4007 struct ieee80211_fast_rx *old;
4009 spin_lock_bh(&sta->lock);
4010 old = rcu_dereference_protected(sta->fast_rx, true);
4011 RCU_INIT_POINTER(sta->fast_rx, NULL);
4012 spin_unlock_bh(&sta->lock);
4015 kfree_rcu(old, rcu_head);
4018 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4020 struct ieee80211_local *local = sdata->local;
4021 struct sta_info *sta;
4023 lockdep_assert_held(&local->sta_mtx);
4025 list_for_each_entry_rcu(sta, &local->sta_list, list) {
4026 if (sdata != sta->sdata &&
4027 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4029 ieee80211_check_fast_rx(sta);
4033 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4035 struct ieee80211_local *local = sdata->local;
4037 mutex_lock(&local->sta_mtx);
4038 __ieee80211_check_fast_rx_iface(sdata);
4039 mutex_unlock(&local->sta_mtx);
4042 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4043 struct ieee80211_fast_rx *fast_rx)
4045 struct sk_buff *skb = rx->skb;
4046 struct ieee80211_hdr *hdr = (void *)skb->data;
4047 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4048 struct sta_info *sta = rx->sta;
4049 int orig_len = skb->len;
4050 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4051 int snap_offs = hdrlen;
4053 u8 snap[sizeof(rfc1042_header)];
4055 } *payload __aligned(2);
4059 } addrs __aligned(2);
4060 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
4062 if (fast_rx->uses_rss)
4063 stats = this_cpu_ptr(sta->pcpu_rx_stats);
4065 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4066 * to a common data structure; drivers can implement that per queue
4067 * but we don't have that information in mac80211
4069 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4072 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4074 /* If using encryption, we also need to have:
4075 * - PN_VALIDATED: similar, but the implementation is tricky
4076 * - DECRYPTED: necessary for PN_VALIDATED
4079 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4082 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4085 if (unlikely(ieee80211_is_frag(hdr)))
4088 /* Since our interface address cannot be multicast, this
4089 * implicitly also rejects multicast frames without the
4092 * We shouldn't get any *data* frames not addressed to us
4093 * (AP mode will accept multicast *management* frames), but
4094 * punting here will make it go through the full checks in
4095 * ieee80211_accept_frame().
4097 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4100 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4101 IEEE80211_FCTL_TODS)) !=
4102 fast_rx->expected_ds_bits)
4105 /* assign the key to drop unencrypted frames (later)
4106 * and strip the IV/MIC if necessary
4108 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4109 /* GCMP header length is the same */
4110 snap_offs += IEEE80211_CCMP_HDR_LEN;
4113 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4114 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4117 payload = (void *)(skb->data + snap_offs);
4119 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4122 /* Don't handle these here since they require special code.
4123 * Accept AARP and IPX even though they should come with a
4124 * bridge-tunnel header - but if we get them this way then
4125 * there's little point in discarding them.
4127 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4128 payload->proto == fast_rx->control_port_protocol))
4132 /* after this point, don't punt to the slowpath! */
4134 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4135 pskb_trim(skb, skb->len - fast_rx->icv_len))
4138 if (unlikely(fast_rx->sta_notify)) {
4139 ieee80211_sta_rx_notify(rx->sdata, hdr);
4140 fast_rx->sta_notify = false;
4143 /* statistics part of ieee80211_rx_h_sta_process() */
4144 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4145 stats->last_signal = status->signal;
4146 if (!fast_rx->uses_rss)
4147 ewma_signal_add(&sta->rx_stats_avg.signal,
4151 if (status->chains) {
4154 stats->chains = status->chains;
4155 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4156 int signal = status->chain_signal[i];
4158 if (!(status->chains & BIT(i)))
4161 stats->chain_signal_last[i] = signal;
4162 if (!fast_rx->uses_rss)
4163 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4167 /* end of statistics */
4169 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4172 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4173 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4180 stats->last_rx = jiffies;
4181 stats->last_rate = sta_stats_encode_rate(status);
4186 /* do the header conversion - first grab the addresses */
4187 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4188 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4189 /* remove the SNAP but leave the ethertype */
4190 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4191 /* push the addresses in front */
4192 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4194 skb->dev = fast_rx->dev;
4196 ieee80211_rx_stats(fast_rx->dev, skb->len);
4198 /* The seqno index has the same property as needed
4199 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4200 * for non-QoS-data frames. Here we know it's a data
4201 * frame, so count MSDUs.
4203 u64_stats_update_begin(&stats->syncp);
4204 stats->msdu[rx->seqno_idx]++;
4205 stats->bytes += orig_len;
4206 u64_stats_update_end(&stats->syncp);
4208 if (fast_rx->internal_forward) {
4209 struct sk_buff *xmit_skb = NULL;
4210 bool multicast = is_multicast_ether_addr(skb->data);
4213 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4214 } else if (sta_info_get(rx->sdata, skb->data)) {
4221 * Send to wireless media and increase priority by 256
4222 * to keep the received priority instead of
4223 * reclassifying the frame (see cfg80211_classify8021d).
4225 xmit_skb->priority += 256;
4226 xmit_skb->protocol = htons(ETH_P_802_3);
4227 skb_reset_network_header(xmit_skb);
4228 skb_reset_mac_header(xmit_skb);
4229 dev_queue_xmit(xmit_skb);
4236 /* deliver to local stack */
4237 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4238 memset(skb->cb, 0, sizeof(skb->cb));
4240 napi_gro_receive(rx->napi, skb);
4242 netif_receive_skb(skb);
4252 * This function returns whether or not the SKB
4253 * was destined for RX processing or not, which,
4254 * if consume is true, is equivalent to whether
4255 * or not the skb was consumed.
4257 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4258 struct sk_buff *skb, bool consume)
4260 struct ieee80211_local *local = rx->local;
4261 struct ieee80211_sub_if_data *sdata = rx->sdata;
4265 /* See if we can do fast-rx; if we have to copy we already lost,
4266 * so punt in that case. We should never have to deliver a data
4267 * frame to multiple interfaces anyway.
4269 * We skip the ieee80211_accept_frame() call and do the necessary
4270 * checking inside ieee80211_invoke_fast_rx().
4272 if (consume && rx->sta) {
4273 struct ieee80211_fast_rx *fast_rx;
4275 fast_rx = rcu_dereference(rx->sta->fast_rx);
4276 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4280 if (!ieee80211_accept_frame(rx))
4284 skb = skb_copy(skb, GFP_ATOMIC);
4286 if (net_ratelimit())
4287 wiphy_debug(local->hw.wiphy,
4288 "failed to copy skb for %s\n",
4296 ieee80211_invoke_rx_handlers(rx);
4301 * This is the actual Rx frames handler. as it belongs to Rx path it must
4302 * be called with rcu_read_lock protection.
4304 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4305 struct ieee80211_sta *pubsta,
4306 struct sk_buff *skb,
4307 struct napi_struct *napi)
4309 struct ieee80211_local *local = hw_to_local(hw);
4310 struct ieee80211_sub_if_data *sdata;
4311 struct ieee80211_hdr *hdr;
4313 struct ieee80211_rx_data rx;
4314 struct ieee80211_sub_if_data *prev;
4315 struct rhlist_head *tmp;
4318 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4319 memset(&rx, 0, sizeof(rx));
4324 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4325 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4327 if (ieee80211_is_mgmt(fc)) {
4328 /* drop frame if too short for header */
4329 if (skb->len < ieee80211_hdrlen(fc))
4332 err = skb_linearize(skb);
4334 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4342 hdr = (struct ieee80211_hdr *)skb->data;
4343 ieee80211_parse_qos(&rx);
4344 ieee80211_verify_alignment(&rx);
4346 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4347 ieee80211_is_beacon(hdr->frame_control)))
4348 ieee80211_scan_rx(local, skb);
4350 if (ieee80211_is_data(fc)) {
4351 struct sta_info *sta, *prev_sta;
4354 rx.sta = container_of(pubsta, struct sta_info, sta);
4355 rx.sdata = rx.sta->sdata;
4356 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4363 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4370 rx.sdata = prev_sta->sdata;
4371 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4378 rx.sdata = prev_sta->sdata;
4380 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4388 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4389 if (!ieee80211_sdata_running(sdata))
4392 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4393 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4397 * frame is destined for this interface, but if it's
4398 * not also for the previous one we handle that after
4399 * the loop to avoid copying the SKB once too much
4407 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4409 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4415 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4418 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4427 * This is the receive path handler. It is called by a low level driver when an
4428 * 802.11 MPDU is received from the hardware.
4430 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4431 struct sk_buff *skb, struct napi_struct *napi)
4433 struct ieee80211_local *local = hw_to_local(hw);
4434 struct ieee80211_rate *rate = NULL;
4435 struct ieee80211_supported_band *sband;
4436 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4438 WARN_ON_ONCE(softirq_count() == 0);
4440 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4443 sband = local->hw.wiphy->bands[status->band];
4444 if (WARN_ON(!sband))
4448 * If we're suspending, it is possible although not too likely
4449 * that we'd be receiving frames after having already partially
4450 * quiesced the stack. We can't process such frames then since
4451 * that might, for example, cause stations to be added or other
4452 * driver callbacks be invoked.
4454 if (unlikely(local->quiescing || local->suspended))
4457 /* We might be during a HW reconfig, prevent Rx for the same reason */
4458 if (unlikely(local->in_reconfig))
4462 * The same happens when we're not even started,
4463 * but that's worth a warning.
4465 if (WARN_ON(!local->started))
4468 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4470 * Validate the rate, unless a PLCP error means that
4471 * we probably can't have a valid rate here anyway.
4474 switch (status->encoding) {
4477 * rate_idx is MCS index, which can be [0-76]
4480 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4482 * Anything else would be some sort of driver or
4483 * hardware error. The driver should catch hardware
4486 if (WARN(status->rate_idx > 76,
4487 "Rate marked as an HT rate but passed "
4488 "status->rate_idx is not "
4489 "an MCS index [0-76]: %d (0x%02x)\n",
4495 if (WARN_ONCE(status->rate_idx > 9 ||
4498 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4499 status->rate_idx, status->nss))
4503 if (WARN_ONCE(status->rate_idx > 11 ||
4506 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4507 status->rate_idx, status->nss))
4514 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4516 rate = &sband->bitrates[status->rate_idx];
4520 status->rx_flags = 0;
4523 * key references and virtual interfaces are protected using RCU
4524 * and this requires that we are in a read-side RCU section during
4525 * receive processing
4530 * Frames with failed FCS/PLCP checksum are not returned,
4531 * all other frames are returned without radiotap header
4532 * if it was previously present.
4533 * Also, frames with less than 16 bytes are dropped.
4535 skb = ieee80211_rx_monitor(local, skb, rate);
4541 ieee80211_tpt_led_trig_rx(local,
4542 ((struct ieee80211_hdr *)skb->data)->frame_control,
4545 __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
4553 EXPORT_SYMBOL(ieee80211_rx_napi);
4555 /* This is a version of the rx handler that can be called from hard irq
4556 * context. Post the skb on the queue and schedule the tasklet */
4557 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
4559 struct ieee80211_local *local = hw_to_local(hw);
4561 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4563 skb->pkt_type = IEEE80211_RX_MSG;
4564 skb_queue_tail(&local->skb_queue, skb);
4565 tasklet_schedule(&local->tasklet);
4567 EXPORT_SYMBOL(ieee80211_rx_irqsafe);