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
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/jiffies.h>
14 #include <linux/slab.h>
15 #include <linux/kernel.h>
16 #include <linux/skbuff.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/rcupdate.h>
20 #include <linux/export.h>
21 #include <net/mac80211.h>
22 #include <net/ieee80211_radiotap.h>
23 #include <asm/unaligned.h>
25 #include "ieee80211_i.h"
26 #include "driver-ops.h"
35 static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
37 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
39 u64_stats_update_begin(&tstats->syncp);
41 tstats->rx_bytes += len;
42 u64_stats_update_end(&tstats->syncp);
45 static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
46 enum nl80211_iftype type)
48 __le16 fc = hdr->frame_control;
50 if (ieee80211_is_data(fc)) {
51 if (len < 24) /* drop incorrect hdr len (data) */
54 if (ieee80211_has_a4(fc))
56 if (ieee80211_has_tods(fc))
58 if (ieee80211_has_fromds(fc))
64 if (ieee80211_is_mgmt(fc)) {
65 if (len < 24) /* drop incorrect hdr len (mgmt) */
70 if (ieee80211_is_ctl(fc)) {
71 if (ieee80211_is_pspoll(fc))
74 if (ieee80211_is_back_req(fc)) {
76 case NL80211_IFTYPE_STATION:
78 case NL80211_IFTYPE_AP:
79 case NL80211_IFTYPE_AP_VLAN:
82 break; /* fall through to the return */
91 * monitor mode reception
93 * This function cleans up the SKB, i.e. it removes all the stuff
94 * only useful for monitoring.
96 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
98 unsigned int rtap_vendor_space)
100 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
101 if (likely(skb->len > FCS_LEN))
102 __pskb_trim(skb, skb->len - FCS_LEN);
111 __pskb_pull(skb, rtap_vendor_space);
116 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
117 unsigned int rtap_vendor_space)
119 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
120 struct ieee80211_hdr *hdr;
122 hdr = (void *)(skb->data + rtap_vendor_space);
124 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
125 RX_FLAG_FAILED_PLCP_CRC))
128 if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space))
131 if (ieee80211_is_ctl(hdr->frame_control) &&
132 !ieee80211_is_pspoll(hdr->frame_control) &&
133 !ieee80211_is_back_req(hdr->frame_control))
140 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
141 struct ieee80211_rx_status *status,
146 /* always present fields */
147 len = sizeof(struct ieee80211_radiotap_header) + 8;
149 /* allocate extra bitmaps */
151 len += 4 * hweight8(status->chains);
152 /* vendor presence bitmap */
153 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)
156 if (ieee80211_have_rx_timestamp(status)) {
160 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
163 /* antenna field, if we don't have per-chain info */
167 /* padding for RX_FLAGS if necessary */
170 if (status->flag & RX_FLAG_HT) /* HT info */
173 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
178 if (status->flag & RX_FLAG_VHT) {
183 if (status->chains) {
184 /* antenna and antenna signal fields */
185 len += 2 * hweight8(status->chains);
188 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
189 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
191 /* alignment for fixed 6-byte vendor data header */
193 /* vendor data header */
195 if (WARN_ON(rtap->align == 0))
197 len = ALIGN(len, rtap->align);
198 len += rtap->len + rtap->pad;
205 * ieee80211_add_rx_radiotap_header - add radiotap header
207 * add a radiotap header containing all the fields which the hardware provided.
210 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
212 struct ieee80211_rate *rate,
213 int rtap_len, bool has_fcs)
215 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
216 struct ieee80211_radiotap_header *rthdr;
221 u16 channel_flags = 0;
223 unsigned long chains = status->chains;
224 struct ieee80211_vendor_radiotap rtap = {};
226 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
227 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
228 /* rtap.len and rtap.pad are undone immediately */
229 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
233 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
236 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
237 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
238 it_present = &rthdr->it_present;
240 /* radiotap header, set always present flags */
241 rthdr->it_len = cpu_to_le16(rtap_len);
242 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
243 BIT(IEEE80211_RADIOTAP_CHANNEL) |
244 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
247 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
249 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
251 BIT(IEEE80211_RADIOTAP_EXT) |
252 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
253 put_unaligned_le32(it_present_val, it_present);
255 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
256 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
259 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
260 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
261 BIT(IEEE80211_RADIOTAP_EXT);
262 put_unaligned_le32(it_present_val, it_present);
264 it_present_val = rtap.present;
267 put_unaligned_le32(it_present_val, it_present);
269 pos = (void *)(it_present + 1);
271 /* the order of the following fields is important */
273 /* IEEE80211_RADIOTAP_TSFT */
274 if (ieee80211_have_rx_timestamp(status)) {
276 while ((pos - (u8 *)rthdr) & 7)
279 ieee80211_calculate_rx_timestamp(local, status,
282 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
286 /* IEEE80211_RADIOTAP_FLAGS */
287 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
288 *pos |= IEEE80211_RADIOTAP_F_FCS;
289 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
290 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
291 if (status->flag & RX_FLAG_SHORTPRE)
292 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
295 /* IEEE80211_RADIOTAP_RATE */
296 if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
298 * Without rate information don't add it. If we have,
299 * MCS information is a separate field in radiotap,
300 * added below. The byte here is needed as padding
301 * for the channel though, so initialise it to 0.
306 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
307 if (status->flag & RX_FLAG_10MHZ)
309 else if (status->flag & RX_FLAG_5MHZ)
311 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
315 /* IEEE80211_RADIOTAP_CHANNEL */
316 put_unaligned_le16(status->freq, pos);
318 if (status->flag & RX_FLAG_10MHZ)
319 channel_flags |= IEEE80211_CHAN_HALF;
320 else if (status->flag & RX_FLAG_5MHZ)
321 channel_flags |= IEEE80211_CHAN_QUARTER;
323 if (status->band == IEEE80211_BAND_5GHZ)
324 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
325 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
326 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
327 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
328 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
330 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
332 channel_flags |= IEEE80211_CHAN_2GHZ;
333 put_unaligned_le16(channel_flags, pos);
336 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
337 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
338 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
339 *pos = status->signal;
341 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
345 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
347 if (!status->chains) {
348 /* IEEE80211_RADIOTAP_ANTENNA */
349 *pos = status->antenna;
353 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
355 /* IEEE80211_RADIOTAP_RX_FLAGS */
356 /* ensure 2 byte alignment for the 2 byte field as required */
357 if ((pos - (u8 *)rthdr) & 1)
359 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
360 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
361 put_unaligned_le16(rx_flags, pos);
364 if (status->flag & RX_FLAG_HT) {
367 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
368 *pos++ = local->hw.radiotap_mcs_details;
370 if (status->flag & RX_FLAG_SHORT_GI)
371 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
372 if (status->flag & RX_FLAG_40MHZ)
373 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
374 if (status->flag & RX_FLAG_HT_GF)
375 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
376 if (status->flag & RX_FLAG_LDPC)
377 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
378 stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
379 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
381 *pos++ = status->rate_idx;
384 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
387 /* ensure 4 byte alignment */
388 while ((pos - (u8 *)rthdr) & 3)
391 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
392 put_unaligned_le32(status->ampdu_reference, pos);
394 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
395 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
396 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
397 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
398 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
399 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
400 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
401 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
402 put_unaligned_le16(flags, pos);
404 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
405 *pos++ = status->ampdu_delimiter_crc;
411 if (status->flag & RX_FLAG_VHT) {
412 u16 known = local->hw.radiotap_vht_details;
414 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
415 put_unaligned_le16(known, pos);
418 if (status->flag & RX_FLAG_SHORT_GI)
419 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
420 /* in VHT, STBC is binary */
421 if (status->flag & RX_FLAG_STBC_MASK)
422 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
423 if (status->vht_flag & RX_VHT_FLAG_BF)
424 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
427 if (status->vht_flag & RX_VHT_FLAG_80MHZ)
429 else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
431 else if (status->flag & RX_FLAG_40MHZ)
436 *pos = (status->rate_idx << 4) | status->vht_nss;
439 if (status->flag & RX_FLAG_LDPC)
440 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
448 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
449 *pos++ = status->chain_signal[chain];
453 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
454 /* ensure 2 byte alignment for the vendor field as required */
455 if ((pos - (u8 *)rthdr) & 1)
457 *pos++ = rtap.oui[0];
458 *pos++ = rtap.oui[1];
459 *pos++ = rtap.oui[2];
461 put_unaligned_le16(rtap.len, pos);
463 /* align the actual payload as requested */
464 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
466 /* data (and possible padding) already follows */
471 * This function copies a received frame to all monitor interfaces and
472 * returns a cleaned-up SKB that no longer includes the FCS nor the
473 * radiotap header the driver might have added.
475 static struct sk_buff *
476 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
477 struct ieee80211_rate *rate)
479 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
480 struct ieee80211_sub_if_data *sdata;
481 int rt_hdrlen, needed_headroom;
482 struct sk_buff *skb, *skb2;
483 struct net_device *prev_dev = NULL;
484 int present_fcs_len = 0;
485 unsigned int rtap_vendor_space = 0;
487 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
488 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
490 rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad;
494 * First, we may need to make a copy of the skb because
495 * (1) we need to modify it for radiotap (if not present), and
496 * (2) the other RX handlers will modify the skb we got.
498 * We don't need to, of course, if we aren't going to return
499 * the SKB because it has a bad FCS/PLCP checksum.
502 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
503 present_fcs_len = FCS_LEN;
505 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
506 if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) {
507 dev_kfree_skb(origskb);
511 if (!local->monitors) {
512 if (should_drop_frame(origskb, present_fcs_len,
513 rtap_vendor_space)) {
514 dev_kfree_skb(origskb);
518 return remove_monitor_info(local, origskb, rtap_vendor_space);
521 /* room for the radiotap header based on driver features */
522 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb);
523 needed_headroom = rt_hdrlen - rtap_vendor_space;
525 if (should_drop_frame(origskb, present_fcs_len, rtap_vendor_space)) {
526 /* only need to expand headroom if necessary */
531 * This shouldn't trigger often because most devices have an
532 * RX header they pull before we get here, and that should
533 * be big enough for our radiotap information. We should
534 * probably export the length to drivers so that we can have
535 * them allocate enough headroom to start with.
537 if (skb_headroom(skb) < needed_headroom &&
538 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
544 * Need to make a copy and possibly remove radiotap header
545 * and FCS from the original.
547 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
549 origskb = remove_monitor_info(local, origskb,
556 /* prepend radiotap information */
557 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
559 skb_reset_mac_header(skb);
560 skb->ip_summed = CHECKSUM_UNNECESSARY;
561 skb->pkt_type = PACKET_OTHERHOST;
562 skb->protocol = htons(ETH_P_802_2);
564 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
565 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
568 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
571 if (!ieee80211_sdata_running(sdata))
575 skb2 = skb_clone(skb, GFP_ATOMIC);
577 skb2->dev = prev_dev;
578 netif_receive_skb(skb2);
582 prev_dev = sdata->dev;
583 ieee80211_rx_stats(sdata->dev, skb->len);
588 netif_receive_skb(skb);
595 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
597 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
598 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
599 int tid, seqno_idx, security_idx;
601 /* does the frame have a qos control field? */
602 if (ieee80211_is_data_qos(hdr->frame_control)) {
603 u8 *qc = ieee80211_get_qos_ctl(hdr);
604 /* frame has qos control */
605 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
606 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
607 status->rx_flags |= IEEE80211_RX_AMSDU;
613 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
615 * Sequence numbers for management frames, QoS data
616 * frames with a broadcast/multicast address in the
617 * Address 1 field, and all non-QoS data frames sent
618 * by QoS STAs are assigned using an additional single
619 * modulo-4096 counter, [...]
621 * We also use that counter for non-QoS STAs.
623 seqno_idx = IEEE80211_NUM_TIDS;
625 if (ieee80211_is_mgmt(hdr->frame_control))
626 security_idx = IEEE80211_NUM_TIDS;
630 rx->seqno_idx = seqno_idx;
631 rx->security_idx = security_idx;
632 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
633 * For now, set skb->priority to 0 for other cases. */
634 rx->skb->priority = (tid > 7) ? 0 : tid;
638 * DOC: Packet alignment
640 * Drivers always need to pass packets that are aligned to two-byte boundaries
643 * Additionally, should, if possible, align the payload data in a way that
644 * guarantees that the contained IP header is aligned to a four-byte
645 * boundary. In the case of regular frames, this simply means aligning the
646 * payload to a four-byte boundary (because either the IP header is directly
647 * contained, or IV/RFC1042 headers that have a length divisible by four are
648 * in front of it). If the payload data is not properly aligned and the
649 * architecture doesn't support efficient unaligned operations, mac80211
650 * will align the data.
652 * With A-MSDU frames, however, the payload data address must yield two modulo
653 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
654 * push the IP header further back to a multiple of four again. Thankfully, the
655 * specs were sane enough this time around to require padding each A-MSDU
656 * subframe to a length that is a multiple of four.
658 * Padding like Atheros hardware adds which is between the 802.11 header and
659 * the payload is not supported, the driver is required to move the 802.11
660 * header to be directly in front of the payload in that case.
662 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
664 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
665 WARN_ONCE((unsigned long)rx->skb->data & 1,
666 "unaligned packet at 0x%p\n", rx->skb->data);
673 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
675 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
677 if (is_multicast_ether_addr(hdr->addr1))
680 return ieee80211_is_robust_mgmt_frame(skb);
684 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
686 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
688 if (!is_multicast_ether_addr(hdr->addr1))
691 return ieee80211_is_robust_mgmt_frame(skb);
695 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
696 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
698 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
699 struct ieee80211_mmie *mmie;
700 struct ieee80211_mmie_16 *mmie16;
702 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
705 if (!ieee80211_is_robust_mgmt_frame(skb))
706 return -1; /* not a robust management frame */
708 mmie = (struct ieee80211_mmie *)
709 (skb->data + skb->len - sizeof(*mmie));
710 if (mmie->element_id == WLAN_EID_MMIE &&
711 mmie->length == sizeof(*mmie) - 2)
712 return le16_to_cpu(mmie->key_id);
714 mmie16 = (struct ieee80211_mmie_16 *)
715 (skb->data + skb->len - sizeof(*mmie16));
716 if (skb->len >= 24 + sizeof(*mmie16) &&
717 mmie16->element_id == WLAN_EID_MMIE &&
718 mmie16->length == sizeof(*mmie16) - 2)
719 return le16_to_cpu(mmie16->key_id);
724 static int iwl80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
727 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
732 fc = hdr->frame_control;
733 hdrlen = ieee80211_hdrlen(fc);
735 if (skb->len < hdrlen + cs->hdr_len)
738 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
739 keyid &= cs->key_idx_mask;
740 keyid >>= cs->key_idx_shift;
745 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
747 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
748 char *dev_addr = rx->sdata->vif.addr;
750 if (ieee80211_is_data(hdr->frame_control)) {
751 if (is_multicast_ether_addr(hdr->addr1)) {
752 if (ieee80211_has_tods(hdr->frame_control) ||
753 !ieee80211_has_fromds(hdr->frame_control))
754 return RX_DROP_MONITOR;
755 if (ether_addr_equal(hdr->addr3, dev_addr))
756 return RX_DROP_MONITOR;
758 if (!ieee80211_has_a4(hdr->frame_control))
759 return RX_DROP_MONITOR;
760 if (ether_addr_equal(hdr->addr4, dev_addr))
761 return RX_DROP_MONITOR;
765 /* If there is not an established peer link and this is not a peer link
766 * establisment frame, beacon or probe, drop the frame.
769 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
770 struct ieee80211_mgmt *mgmt;
772 if (!ieee80211_is_mgmt(hdr->frame_control))
773 return RX_DROP_MONITOR;
775 if (ieee80211_is_action(hdr->frame_control)) {
778 /* make sure category field is present */
779 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
780 return RX_DROP_MONITOR;
782 mgmt = (struct ieee80211_mgmt *)hdr;
783 category = mgmt->u.action.category;
784 if (category != WLAN_CATEGORY_MESH_ACTION &&
785 category != WLAN_CATEGORY_SELF_PROTECTED)
786 return RX_DROP_MONITOR;
790 if (ieee80211_is_probe_req(hdr->frame_control) ||
791 ieee80211_is_probe_resp(hdr->frame_control) ||
792 ieee80211_is_beacon(hdr->frame_control) ||
793 ieee80211_is_auth(hdr->frame_control))
796 return RX_DROP_MONITOR;
802 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
803 struct tid_ampdu_rx *tid_agg_rx,
805 struct sk_buff_head *frames)
807 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
809 struct ieee80211_rx_status *status;
811 lockdep_assert_held(&tid_agg_rx->reorder_lock);
813 if (skb_queue_empty(skb_list))
816 if (!ieee80211_rx_reorder_ready(skb_list)) {
817 __skb_queue_purge(skb_list);
821 /* release frames from the reorder ring buffer */
822 tid_agg_rx->stored_mpdu_num--;
823 while ((skb = __skb_dequeue(skb_list))) {
824 status = IEEE80211_SKB_RXCB(skb);
825 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
826 __skb_queue_tail(frames, skb);
830 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
833 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
834 struct tid_ampdu_rx *tid_agg_rx,
836 struct sk_buff_head *frames)
840 lockdep_assert_held(&tid_agg_rx->reorder_lock);
842 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
843 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
844 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
850 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
851 * the skb was added to the buffer longer than this time ago, the earlier
852 * frames that have not yet been received are assumed to be lost and the skb
853 * can be released for processing. This may also release other skb's from the
854 * reorder buffer if there are no additional gaps between the frames.
856 * Callers must hold tid_agg_rx->reorder_lock.
858 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
860 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
861 struct tid_ampdu_rx *tid_agg_rx,
862 struct sk_buff_head *frames)
866 lockdep_assert_held(&tid_agg_rx->reorder_lock);
868 /* release the buffer until next missing frame */
869 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
870 if (!ieee80211_rx_reorder_ready(&tid_agg_rx->reorder_buf[index]) &&
871 tid_agg_rx->stored_mpdu_num) {
873 * No buffers ready to be released, but check whether any
874 * frames in the reorder buffer have timed out.
877 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
878 j = (j + 1) % tid_agg_rx->buf_size) {
879 if (!ieee80211_rx_reorder_ready(
880 &tid_agg_rx->reorder_buf[j])) {
885 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
886 HT_RX_REORDER_BUF_TIMEOUT))
887 goto set_release_timer;
889 /* don't leave incomplete A-MSDUs around */
890 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
891 i = (i + 1) % tid_agg_rx->buf_size)
892 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
894 ht_dbg_ratelimited(sdata,
895 "release an RX reorder frame due to timeout on earlier frames\n");
896 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
900 * Increment the head seq# also for the skipped slots.
902 tid_agg_rx->head_seq_num =
903 (tid_agg_rx->head_seq_num +
904 skipped) & IEEE80211_SN_MASK;
907 } else while (ieee80211_rx_reorder_ready(
908 &tid_agg_rx->reorder_buf[index])) {
909 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
911 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
914 if (tid_agg_rx->stored_mpdu_num) {
915 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
917 for (; j != (index - 1) % tid_agg_rx->buf_size;
918 j = (j + 1) % tid_agg_rx->buf_size) {
919 if (ieee80211_rx_reorder_ready(
920 &tid_agg_rx->reorder_buf[j]))
926 if (!tid_agg_rx->removed)
927 mod_timer(&tid_agg_rx->reorder_timer,
928 tid_agg_rx->reorder_time[j] + 1 +
929 HT_RX_REORDER_BUF_TIMEOUT);
931 del_timer(&tid_agg_rx->reorder_timer);
936 * As this function belongs to the RX path it must be under
937 * rcu_read_lock protection. It returns false if the frame
938 * can be processed immediately, true if it was consumed.
940 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
941 struct tid_ampdu_rx *tid_agg_rx,
943 struct sk_buff_head *frames)
945 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
946 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
947 u16 sc = le16_to_cpu(hdr->seq_ctrl);
948 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
949 u16 head_seq_num, buf_size;
953 spin_lock(&tid_agg_rx->reorder_lock);
956 * Offloaded BA sessions have no known starting sequence number so pick
957 * one from first Rxed frame for this tid after BA was started.
959 if (unlikely(tid_agg_rx->auto_seq)) {
960 tid_agg_rx->auto_seq = false;
961 tid_agg_rx->ssn = mpdu_seq_num;
962 tid_agg_rx->head_seq_num = mpdu_seq_num;
965 buf_size = tid_agg_rx->buf_size;
966 head_seq_num = tid_agg_rx->head_seq_num;
968 /* frame with out of date sequence number */
969 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
975 * If frame the sequence number exceeds our buffering window
976 * size release some previous frames to make room for this one.
978 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
979 head_seq_num = ieee80211_sn_inc(
980 ieee80211_sn_sub(mpdu_seq_num, buf_size));
981 /* release stored frames up to new head to stack */
982 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
983 head_seq_num, frames);
986 /* Now the new frame is always in the range of the reordering buffer */
988 index = mpdu_seq_num % tid_agg_rx->buf_size;
990 /* check if we already stored this frame */
991 if (ieee80211_rx_reorder_ready(&tid_agg_rx->reorder_buf[index])) {
997 * If the current MPDU is in the right order and nothing else
998 * is stored we can process it directly, no need to buffer it.
999 * If it is first but there's something stored, we may be able
1000 * to release frames after this one.
1002 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1003 tid_agg_rx->stored_mpdu_num == 0) {
1004 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1005 tid_agg_rx->head_seq_num =
1006 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1011 /* put the frame in the reordering buffer */
1012 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1013 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1014 tid_agg_rx->reorder_time[index] = jiffies;
1015 tid_agg_rx->stored_mpdu_num++;
1016 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1020 spin_unlock(&tid_agg_rx->reorder_lock);
1025 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1026 * true if the MPDU was buffered, false if it should be processed.
1028 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1029 struct sk_buff_head *frames)
1031 struct sk_buff *skb = rx->skb;
1032 struct ieee80211_local *local = rx->local;
1033 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1034 struct sta_info *sta = rx->sta;
1035 struct tid_ampdu_rx *tid_agg_rx;
1039 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1040 is_multicast_ether_addr(hdr->addr1))
1044 * filter the QoS data rx stream according to
1045 * STA/TID and check if this STA/TID is on aggregation
1051 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1052 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1053 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1055 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1059 /* qos null data frames are excluded */
1060 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1063 /* not part of a BA session */
1064 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1065 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1068 /* new, potentially un-ordered, ampdu frame - process it */
1070 /* reset session timer */
1071 if (tid_agg_rx->timeout)
1072 tid_agg_rx->last_rx = jiffies;
1074 /* if this mpdu is fragmented - terminate rx aggregation session */
1075 sc = le16_to_cpu(hdr->seq_ctrl);
1076 if (sc & IEEE80211_SCTL_FRAG) {
1077 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
1078 skb_queue_tail(&rx->sdata->skb_queue, skb);
1079 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1084 * No locking needed -- we will only ever process one
1085 * RX packet at a time, and thus own tid_agg_rx. All
1086 * other code manipulating it needs to (and does) make
1087 * sure that we cannot get to it any more before doing
1090 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1095 __skb_queue_tail(frames, skb);
1098 static ieee80211_rx_result debug_noinline
1099 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1101 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1102 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1105 * Drop duplicate 802.11 retransmissions
1106 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1109 if (rx->skb->len < 24)
1112 if (ieee80211_is_ctl(hdr->frame_control) ||
1113 ieee80211_is_nullfunc(hdr->frame_control) ||
1114 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
1115 is_multicast_ether_addr(hdr->addr1))
1121 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1122 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1123 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1124 rx->sta->rx_stats.num_duplicates++;
1125 return RX_DROP_UNUSABLE;
1126 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1127 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1133 static ieee80211_rx_result debug_noinline
1134 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1136 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1138 /* Drop disallowed frame classes based on STA auth/assoc state;
1139 * IEEE 802.11, Chap 5.5.
1141 * mac80211 filters only based on association state, i.e. it drops
1142 * Class 3 frames from not associated stations. hostapd sends
1143 * deauth/disassoc frames when needed. In addition, hostapd is
1144 * responsible for filtering on both auth and assoc states.
1147 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1148 return ieee80211_rx_mesh_check(rx);
1150 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1151 ieee80211_is_pspoll(hdr->frame_control)) &&
1152 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1153 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1154 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1155 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1157 * accept port control frames from the AP even when it's not
1158 * yet marked ASSOC to prevent a race where we don't set the
1159 * assoc bit quickly enough before it sends the first frame
1161 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1162 ieee80211_is_data_present(hdr->frame_control)) {
1163 unsigned int hdrlen;
1166 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1168 if (rx->skb->len < hdrlen + 8)
1169 return RX_DROP_MONITOR;
1171 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1172 if (ethertype == rx->sdata->control_port_protocol)
1176 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1177 cfg80211_rx_spurious_frame(rx->sdata->dev,
1180 return RX_DROP_UNUSABLE;
1182 return RX_DROP_MONITOR;
1189 static ieee80211_rx_result debug_noinline
1190 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1192 struct ieee80211_local *local;
1193 struct ieee80211_hdr *hdr;
1194 struct sk_buff *skb;
1198 hdr = (struct ieee80211_hdr *) skb->data;
1200 if (!local->pspolling)
1203 if (!ieee80211_has_fromds(hdr->frame_control))
1204 /* this is not from AP */
1207 if (!ieee80211_is_data(hdr->frame_control))
1210 if (!ieee80211_has_moredata(hdr->frame_control)) {
1211 /* AP has no more frames buffered for us */
1212 local->pspolling = false;
1216 /* more data bit is set, let's request a new frame from the AP */
1217 ieee80211_send_pspoll(local, rx->sdata);
1222 static void sta_ps_start(struct sta_info *sta)
1224 struct ieee80211_sub_if_data *sdata = sta->sdata;
1225 struct ieee80211_local *local = sdata->local;
1229 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1230 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1231 ps = &sdata->bss->ps;
1235 atomic_inc(&ps->num_sta_ps);
1236 set_sta_flag(sta, WLAN_STA_PS_STA);
1237 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1238 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1239 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1240 sta->sta.addr, sta->sta.aid);
1242 ieee80211_clear_fast_xmit(sta);
1244 if (!sta->sta.txq[0])
1247 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1248 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
1250 if (!skb_queue_len(&txqi->queue))
1251 set_bit(tid, &sta->txq_buffered_tids);
1253 clear_bit(tid, &sta->txq_buffered_tids);
1257 static void sta_ps_end(struct sta_info *sta)
1259 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1260 sta->sta.addr, sta->sta.aid);
1262 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1264 * Clear the flag only if the other one is still set
1265 * so that the TX path won't start TX'ing new frames
1266 * directly ... In the case that the driver flag isn't
1267 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1269 clear_sta_flag(sta, WLAN_STA_PS_STA);
1270 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1271 sta->sta.addr, sta->sta.aid);
1275 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1276 clear_sta_flag(sta, WLAN_STA_PS_STA);
1277 ieee80211_sta_ps_deliver_wakeup(sta);
1280 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1282 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1285 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1287 /* Don't let the same PS state be set twice */
1288 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1289 if ((start && in_ps) || (!start && !in_ps))
1299 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1301 static ieee80211_rx_result debug_noinline
1302 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1304 struct ieee80211_sub_if_data *sdata = rx->sdata;
1305 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1306 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1312 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1313 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1317 * The device handles station powersave, so don't do anything about
1318 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1319 * it to mac80211 since they're handled.)
1321 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1325 * Don't do anything if the station isn't already asleep. In
1326 * the uAPSD case, the station will probably be marked asleep,
1327 * in the PS-Poll case the station must be confused ...
1329 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1332 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1333 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1334 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1335 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1337 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
1340 /* Free PS Poll skb here instead of returning RX_DROP that would
1341 * count as an dropped frame. */
1342 dev_kfree_skb(rx->skb);
1345 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1346 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1347 ieee80211_has_pm(hdr->frame_control) &&
1348 (ieee80211_is_data_qos(hdr->frame_control) ||
1349 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1350 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1351 ac = ieee802_1d_to_ac[tid & 7];
1354 * If this AC is not trigger-enabled do nothing.
1356 * NB: This could/should check a separate bitmap of trigger-
1357 * enabled queues, but for now we only implement uAPSD w/o
1358 * TSPEC changes to the ACs, so they're always the same.
1360 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1363 /* if we are in a service period, do nothing */
1364 if (test_sta_flag(rx->sta, WLAN_STA_SP))
1367 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1368 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1370 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
1376 static ieee80211_rx_result debug_noinline
1377 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1379 struct sta_info *sta = rx->sta;
1380 struct sk_buff *skb = rx->skb;
1381 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1382 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1389 * Update last_rx only for IBSS packets which are for the current
1390 * BSSID and for station already AUTHORIZED to avoid keeping the
1391 * current IBSS network alive in cases where other STAs start
1392 * using different BSSID. This will also give the station another
1393 * chance to restart the authentication/authorization in case
1394 * something went wrong the first time.
1396 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1397 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1398 NL80211_IFTYPE_ADHOC);
1399 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1400 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1401 sta->rx_stats.last_rx = jiffies;
1402 if (ieee80211_is_data(hdr->frame_control) &&
1403 !is_multicast_ether_addr(hdr->addr1)) {
1404 sta->rx_stats.last_rate_idx =
1406 sta->rx_stats.last_rate_flag =
1408 sta->rx_stats.last_rate_vht_flag =
1410 sta->rx_stats.last_rate_vht_nss =
1414 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1415 sta->rx_stats.last_rx = jiffies;
1416 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1418 * Mesh beacons will update last_rx when if they are found to
1419 * match the current local configuration when processed.
1421 sta->rx_stats.last_rx = jiffies;
1422 if (ieee80211_is_data(hdr->frame_control)) {
1423 sta->rx_stats.last_rate_idx = status->rate_idx;
1424 sta->rx_stats.last_rate_flag = status->flag;
1425 sta->rx_stats.last_rate_vht_flag = status->vht_flag;
1426 sta->rx_stats.last_rate_vht_nss = status->vht_nss;
1430 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1431 ieee80211_sta_rx_notify(rx->sdata, hdr);
1433 sta->rx_stats.fragments++;
1434 sta->rx_stats.bytes += rx->skb->len;
1435 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1436 sta->rx_stats.last_signal = status->signal;
1437 ewma_signal_add(&sta->rx_stats.avg_signal, -status->signal);
1440 if (status->chains) {
1441 sta->rx_stats.chains = status->chains;
1442 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1443 int signal = status->chain_signal[i];
1445 if (!(status->chains & BIT(i)))
1448 sta->rx_stats.chain_signal_last[i] = signal;
1449 ewma_signal_add(&sta->rx_stats.chain_signal_avg[i],
1455 * Change STA power saving mode only at the end of a frame
1456 * exchange sequence.
1458 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1459 !ieee80211_has_morefrags(hdr->frame_control) &&
1460 !ieee80211_is_back_req(hdr->frame_control) &&
1461 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1462 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1463 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1465 * PM bit is only checked in frames where it isn't reserved,
1466 * in AP mode it's reserved in non-bufferable management frames
1467 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1468 * BAR frames should be ignored as specified in
1469 * IEEE 802.11-2012 10.2.1.2.
1471 (!ieee80211_is_mgmt(hdr->frame_control) ||
1472 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
1473 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1474 if (!ieee80211_has_pm(hdr->frame_control))
1477 if (ieee80211_has_pm(hdr->frame_control))
1482 /* mesh power save support */
1483 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1484 ieee80211_mps_rx_h_sta_process(sta, hdr);
1487 * Drop (qos-)data::nullfunc frames silently, since they
1488 * are used only to control station power saving mode.
1490 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1491 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1492 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1495 * If we receive a 4-addr nullfunc frame from a STA
1496 * that was not moved to a 4-addr STA vlan yet send
1497 * the event to userspace and for older hostapd drop
1498 * the frame to the monitor interface.
1500 if (ieee80211_has_a4(hdr->frame_control) &&
1501 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1502 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1503 !rx->sdata->u.vlan.sta))) {
1504 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1505 cfg80211_rx_unexpected_4addr_frame(
1506 rx->sdata->dev, sta->sta.addr,
1508 return RX_DROP_MONITOR;
1511 * Update counter and free packet here to avoid
1512 * counting this as a dropped packed.
1514 sta->rx_stats.packets++;
1515 dev_kfree_skb(rx->skb);
1520 } /* ieee80211_rx_h_sta_process */
1522 static ieee80211_rx_result debug_noinline
1523 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1525 struct sk_buff *skb = rx->skb;
1526 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1527 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1530 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1531 struct ieee80211_key *sta_ptk = NULL;
1532 int mmie_keyidx = -1;
1534 const struct ieee80211_cipher_scheme *cs = NULL;
1539 * There are four types of keys:
1540 * - GTK (group keys)
1541 * - IGTK (group keys for management frames)
1542 * - PTK (pairwise keys)
1543 * - STK (station-to-station pairwise keys)
1545 * When selecting a key, we have to distinguish between multicast
1546 * (including broadcast) and unicast frames, the latter can only
1547 * use PTKs and STKs while the former always use GTKs and IGTKs.
1548 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1549 * unicast frames can also use key indices like GTKs. Hence, if we
1550 * don't have a PTK/STK we check the key index for a WEP key.
1552 * Note that in a regular BSS, multicast frames are sent by the
1553 * AP only, associated stations unicast the frame to the AP first
1554 * which then multicasts it on their behalf.
1556 * There is also a slight problem in IBSS mode: GTKs are negotiated
1557 * with each station, that is something we don't currently handle.
1558 * The spec seems to expect that one negotiates the same key with
1559 * every station but there's no such requirement; VLANs could be
1563 /* start without a key */
1565 fc = hdr->frame_control;
1568 int keyid = rx->sta->ptk_idx;
1570 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1571 cs = rx->sta->cipher_scheme;
1572 keyid = iwl80211_get_cs_keyid(cs, rx->skb);
1573 if (unlikely(keyid < 0))
1574 return RX_DROP_UNUSABLE;
1576 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1579 if (!ieee80211_has_protected(fc))
1580 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1582 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1584 if ((status->flag & RX_FLAG_DECRYPTED) &&
1585 (status->flag & RX_FLAG_IV_STRIPPED))
1587 /* Skip decryption if the frame is not protected. */
1588 if (!ieee80211_has_protected(fc))
1590 } else if (mmie_keyidx >= 0) {
1591 /* Broadcast/multicast robust management frame / BIP */
1592 if ((status->flag & RX_FLAG_DECRYPTED) &&
1593 (status->flag & RX_FLAG_IV_STRIPPED))
1596 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1597 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1598 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1600 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1602 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1603 } else if (!ieee80211_has_protected(fc)) {
1605 * The frame was not protected, so skip decryption. However, we
1606 * need to set rx->key if there is a key that could have been
1607 * used so that the frame may be dropped if encryption would
1608 * have been expected.
1610 struct ieee80211_key *key = NULL;
1611 struct ieee80211_sub_if_data *sdata = rx->sdata;
1614 if (ieee80211_is_mgmt(fc) &&
1615 is_multicast_ether_addr(hdr->addr1) &&
1616 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1620 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1621 key = rcu_dereference(rx->sta->gtk[i]);
1627 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1628 key = rcu_dereference(sdata->keys[i]);
1641 * The device doesn't give us the IV so we won't be
1642 * able to look up the key. That's ok though, we
1643 * don't need to decrypt the frame, we just won't
1644 * be able to keep statistics accurate.
1645 * Except for key threshold notifications, should
1646 * we somehow allow the driver to tell us which key
1647 * the hardware used if this flag is set?
1649 if ((status->flag & RX_FLAG_DECRYPTED) &&
1650 (status->flag & RX_FLAG_IV_STRIPPED))
1653 hdrlen = ieee80211_hdrlen(fc);
1656 keyidx = iwl80211_get_cs_keyid(cs, rx->skb);
1658 if (unlikely(keyidx < 0))
1659 return RX_DROP_UNUSABLE;
1661 if (rx->skb->len < 8 + hdrlen)
1662 return RX_DROP_UNUSABLE; /* TODO: count this? */
1664 * no need to call ieee80211_wep_get_keyidx,
1665 * it verifies a bunch of things we've done already
1667 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1668 keyidx = keyid >> 6;
1671 /* check per-station GTK first, if multicast packet */
1672 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1673 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1675 /* if not found, try default key */
1677 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1680 * RSNA-protected unicast frames should always be
1681 * sent with pairwise or station-to-station keys,
1682 * but for WEP we allow using a key index as well.
1685 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1686 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1687 !is_multicast_ether_addr(hdr->addr1))
1693 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1694 return RX_DROP_MONITOR;
1696 /* TODO: add threshold stuff again */
1698 return RX_DROP_MONITOR;
1701 switch (rx->key->conf.cipher) {
1702 case WLAN_CIPHER_SUITE_WEP40:
1703 case WLAN_CIPHER_SUITE_WEP104:
1704 result = ieee80211_crypto_wep_decrypt(rx);
1706 case WLAN_CIPHER_SUITE_TKIP:
1707 result = ieee80211_crypto_tkip_decrypt(rx);
1709 case WLAN_CIPHER_SUITE_CCMP:
1710 result = ieee80211_crypto_ccmp_decrypt(
1711 rx, IEEE80211_CCMP_MIC_LEN);
1713 case WLAN_CIPHER_SUITE_CCMP_256:
1714 result = ieee80211_crypto_ccmp_decrypt(
1715 rx, IEEE80211_CCMP_256_MIC_LEN);
1717 case WLAN_CIPHER_SUITE_AES_CMAC:
1718 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1720 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1721 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1723 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1724 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1725 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1727 case WLAN_CIPHER_SUITE_GCMP:
1728 case WLAN_CIPHER_SUITE_GCMP_256:
1729 result = ieee80211_crypto_gcmp_decrypt(rx);
1732 result = ieee80211_crypto_hw_decrypt(rx);
1735 /* the hdr variable is invalid after the decrypt handlers */
1737 /* either the frame has been decrypted or will be dropped */
1738 status->flag |= RX_FLAG_DECRYPTED;
1743 static inline struct ieee80211_fragment_entry *
1744 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1745 unsigned int frag, unsigned int seq, int rx_queue,
1746 struct sk_buff **skb)
1748 struct ieee80211_fragment_entry *entry;
1750 entry = &sdata->fragments[sdata->fragment_next++];
1751 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1752 sdata->fragment_next = 0;
1754 if (!skb_queue_empty(&entry->skb_list))
1755 __skb_queue_purge(&entry->skb_list);
1757 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1759 entry->first_frag_time = jiffies;
1761 entry->rx_queue = rx_queue;
1762 entry->last_frag = frag;
1763 entry->check_sequential_pn = false;
1764 entry->extra_len = 0;
1769 static inline struct ieee80211_fragment_entry *
1770 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
1771 unsigned int frag, unsigned int seq,
1772 int rx_queue, struct ieee80211_hdr *hdr)
1774 struct ieee80211_fragment_entry *entry;
1777 idx = sdata->fragment_next;
1778 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1779 struct ieee80211_hdr *f_hdr;
1783 idx = IEEE80211_FRAGMENT_MAX - 1;
1785 entry = &sdata->fragments[idx];
1786 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1787 entry->rx_queue != rx_queue ||
1788 entry->last_frag + 1 != frag)
1791 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1794 * Check ftype and addresses are equal, else check next fragment
1796 if (((hdr->frame_control ^ f_hdr->frame_control) &
1797 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1798 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1799 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
1802 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1803 __skb_queue_purge(&entry->skb_list);
1812 static ieee80211_rx_result debug_noinline
1813 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1815 struct ieee80211_hdr *hdr;
1818 unsigned int frag, seq;
1819 struct ieee80211_fragment_entry *entry;
1820 struct sk_buff *skb;
1821 struct ieee80211_rx_status *status;
1823 hdr = (struct ieee80211_hdr *)rx->skb->data;
1824 fc = hdr->frame_control;
1826 if (ieee80211_is_ctl(fc))
1829 sc = le16_to_cpu(hdr->seq_ctrl);
1830 frag = sc & IEEE80211_SCTL_FRAG;
1832 if (is_multicast_ether_addr(hdr->addr1)) {
1833 I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
1837 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
1840 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1842 if (skb_linearize(rx->skb))
1843 return RX_DROP_UNUSABLE;
1846 * skb_linearize() might change the skb->data and
1847 * previously cached variables (in this case, hdr) need to
1848 * be refreshed with the new data.
1850 hdr = (struct ieee80211_hdr *)rx->skb->data;
1851 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1854 /* This is the first fragment of a new frame. */
1855 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
1856 rx->seqno_idx, &(rx->skb));
1858 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
1859 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
1860 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
1861 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
1862 ieee80211_has_protected(fc)) {
1863 int queue = rx->security_idx;
1865 /* Store CCMP/GCMP PN so that we can verify that the
1866 * next fragment has a sequential PN value.
1868 entry->check_sequential_pn = true;
1869 memcpy(entry->last_pn,
1870 rx->key->u.ccmp.rx_pn[queue],
1871 IEEE80211_CCMP_PN_LEN);
1872 BUILD_BUG_ON(offsetof(struct ieee80211_key,
1874 offsetof(struct ieee80211_key,
1876 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
1877 sizeof(rx->key->u.gcmp.rx_pn[queue]));
1878 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
1879 IEEE80211_GCMP_PN_LEN);
1884 /* This is a fragment for a frame that should already be pending in
1885 * fragment cache. Add this fragment to the end of the pending entry.
1887 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1888 rx->seqno_idx, hdr);
1890 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1891 return RX_DROP_MONITOR;
1894 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
1895 * MPDU PN values are not incrementing in steps of 1."
1896 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
1897 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
1899 if (entry->check_sequential_pn) {
1901 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
1905 (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
1906 rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 &&
1907 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP &&
1908 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256))
1909 return RX_DROP_UNUSABLE;
1910 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
1911 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
1916 queue = rx->security_idx;
1917 rpn = rx->key->u.ccmp.rx_pn[queue];
1918 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
1919 return RX_DROP_UNUSABLE;
1920 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
1923 skb_pull(rx->skb, ieee80211_hdrlen(fc));
1924 __skb_queue_tail(&entry->skb_list, rx->skb);
1925 entry->last_frag = frag;
1926 entry->extra_len += rx->skb->len;
1927 if (ieee80211_has_morefrags(fc)) {
1932 rx->skb = __skb_dequeue(&entry->skb_list);
1933 if (skb_tailroom(rx->skb) < entry->extra_len) {
1934 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
1935 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1937 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1938 __skb_queue_purge(&entry->skb_list);
1939 return RX_DROP_UNUSABLE;
1942 while ((skb = __skb_dequeue(&entry->skb_list))) {
1943 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1947 /* Complete frame has been reassembled - process it now */
1948 status = IEEE80211_SKB_RXCB(rx->skb);
1951 ieee80211_led_rx(rx->local);
1954 rx->sta->rx_stats.packets++;
1958 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1960 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
1966 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1968 struct sk_buff *skb = rx->skb;
1969 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1972 * Pass through unencrypted frames if the hardware has
1973 * decrypted them already.
1975 if (status->flag & RX_FLAG_DECRYPTED)
1978 /* Drop unencrypted frames if key is set. */
1979 if (unlikely(!ieee80211_has_protected(fc) &&
1980 !ieee80211_is_nullfunc(fc) &&
1981 ieee80211_is_data(fc) && rx->key))
1987 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1989 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1990 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1991 __le16 fc = hdr->frame_control;
1994 * Pass through unencrypted frames if the hardware has
1995 * decrypted them already.
1997 if (status->flag & RX_FLAG_DECRYPTED)
2000 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2001 if (unlikely(!ieee80211_has_protected(fc) &&
2002 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2004 if (ieee80211_is_deauth(fc) ||
2005 ieee80211_is_disassoc(fc))
2006 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2011 /* BIP does not use Protected field, so need to check MMIE */
2012 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2013 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2014 if (ieee80211_is_deauth(fc) ||
2015 ieee80211_is_disassoc(fc))
2016 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2022 * When using MFP, Action frames are not allowed prior to
2023 * having configured keys.
2025 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2026 ieee80211_is_robust_mgmt_frame(rx->skb)))
2034 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2036 struct ieee80211_sub_if_data *sdata = rx->sdata;
2037 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2038 bool check_port_control = false;
2039 struct ethhdr *ehdr;
2042 *port_control = false;
2043 if (ieee80211_has_a4(hdr->frame_control) &&
2044 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2047 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2048 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2050 if (!sdata->u.mgd.use_4addr)
2053 check_port_control = true;
2056 if (is_multicast_ether_addr(hdr->addr1) &&
2057 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2060 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2064 ehdr = (struct ethhdr *) rx->skb->data;
2065 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2066 *port_control = true;
2067 else if (check_port_control)
2074 * requires that rx->skb is a frame with ethernet header
2076 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2078 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2079 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2080 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2083 * Allow EAPOL frames to us/the PAE group address regardless
2084 * of whether the frame was encrypted or not.
2086 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
2087 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2088 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
2091 if (ieee80211_802_1x_port_control(rx) ||
2092 ieee80211_drop_unencrypted(rx, fc))
2099 * requires that rx->skb is a frame with ethernet header
2102 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2104 struct ieee80211_sub_if_data *sdata = rx->sdata;
2105 struct net_device *dev = sdata->dev;
2106 struct sk_buff *skb, *xmit_skb;
2107 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2108 struct sta_info *dsta;
2113 ieee80211_rx_stats(dev, skb->len);
2115 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2116 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2117 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2118 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2119 if (is_multicast_ether_addr(ehdr->h_dest)) {
2121 * send multicast frames both to higher layers in
2122 * local net stack and back to the wireless medium
2124 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2126 net_info_ratelimited("%s: failed to clone multicast frame\n",
2129 dsta = sta_info_get(sdata, skb->data);
2132 * The destination station is associated to
2133 * this AP (in this VLAN), so send the frame
2134 * directly to it and do not pass it to local
2143 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2145 /* 'align' will only take the values 0 or 2 here since all
2146 * frames are required to be aligned to 2-byte boundaries
2147 * when being passed to mac80211; the code here works just
2148 * as well if that isn't true, but mac80211 assumes it can
2149 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2153 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2155 if (WARN_ON(skb_headroom(skb) < 3)) {
2159 u8 *data = skb->data;
2160 size_t len = skb_headlen(skb);
2162 memmove(skb->data, data, len);
2163 skb_set_tail_pointer(skb, len);
2170 /* deliver to local stack */
2171 skb->protocol = eth_type_trans(skb, dev);
2172 memset(skb->cb, 0, sizeof(skb->cb));
2174 napi_gro_receive(rx->napi, skb);
2176 netif_receive_skb(skb);
2181 * Send to wireless media and increase priority by 256 to
2182 * keep the received priority instead of reclassifying
2183 * the frame (see cfg80211_classify8021d).
2185 xmit_skb->priority += 256;
2186 xmit_skb->protocol = htons(ETH_P_802_3);
2187 skb_reset_network_header(xmit_skb);
2188 skb_reset_mac_header(xmit_skb);
2189 dev_queue_xmit(xmit_skb);
2193 static ieee80211_rx_result debug_noinline
2194 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2196 struct net_device *dev = rx->sdata->dev;
2197 struct sk_buff *skb = rx->skb;
2198 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2199 __le16 fc = hdr->frame_control;
2200 struct sk_buff_head frame_list;
2201 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2203 if (unlikely(!ieee80211_is_data(fc)))
2206 if (unlikely(!ieee80211_is_data_present(fc)))
2207 return RX_DROP_MONITOR;
2209 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2212 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2213 switch (rx->sdata->vif.type) {
2214 case NL80211_IFTYPE_AP_VLAN:
2215 if (!rx->sdata->u.vlan.sta)
2216 return RX_DROP_UNUSABLE;
2218 case NL80211_IFTYPE_STATION:
2219 if (!rx->sdata->u.mgd.use_4addr)
2220 return RX_DROP_UNUSABLE;
2223 return RX_DROP_UNUSABLE;
2227 if (is_multicast_ether_addr(hdr->addr1))
2228 return RX_DROP_UNUSABLE;
2231 __skb_queue_head_init(&frame_list);
2233 if (skb_linearize(skb))
2234 return RX_DROP_UNUSABLE;
2236 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2237 rx->sdata->vif.type,
2238 rx->local->hw.extra_tx_headroom, true);
2240 while (!skb_queue_empty(&frame_list)) {
2241 rx->skb = __skb_dequeue(&frame_list);
2243 if (!ieee80211_frame_allowed(rx, fc)) {
2244 dev_kfree_skb(rx->skb);
2248 ieee80211_deliver_skb(rx);
2254 #ifdef CONFIG_MAC80211_MESH
2255 static ieee80211_rx_result
2256 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2258 struct ieee80211_hdr *fwd_hdr, *hdr;
2259 struct ieee80211_tx_info *info;
2260 struct ieee80211s_hdr *mesh_hdr;
2261 struct sk_buff *skb = rx->skb, *fwd_skb;
2262 struct ieee80211_local *local = rx->local;
2263 struct ieee80211_sub_if_data *sdata = rx->sdata;
2264 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2267 hdr = (struct ieee80211_hdr *) skb->data;
2268 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2270 /* make sure fixed part of mesh header is there, also checks skb len */
2271 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2272 return RX_DROP_MONITOR;
2274 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2276 /* make sure full mesh header is there, also checks skb len */
2277 if (!pskb_may_pull(rx->skb,
2278 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2279 return RX_DROP_MONITOR;
2281 /* reload pointers */
2282 hdr = (struct ieee80211_hdr *) skb->data;
2283 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2285 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2286 return RX_DROP_MONITOR;
2288 /* frame is in RMC, don't forward */
2289 if (ieee80211_is_data(hdr->frame_control) &&
2290 is_multicast_ether_addr(hdr->addr1) &&
2291 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2292 return RX_DROP_MONITOR;
2294 if (!ieee80211_is_data(hdr->frame_control))
2298 return RX_DROP_MONITOR;
2300 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2301 struct mesh_path *mppath;
2305 if (is_multicast_ether_addr(hdr->addr1)) {
2306 mpp_addr = hdr->addr3;
2307 proxied_addr = mesh_hdr->eaddr1;
2308 } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
2309 /* has_a4 already checked in ieee80211_rx_mesh_check */
2310 mpp_addr = hdr->addr4;
2311 proxied_addr = mesh_hdr->eaddr2;
2313 return RX_DROP_MONITOR;
2317 mppath = mpp_path_lookup(sdata, proxied_addr);
2319 mpp_path_add(sdata, proxied_addr, mpp_addr);
2321 spin_lock_bh(&mppath->state_lock);
2322 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2323 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2324 spin_unlock_bh(&mppath->state_lock);
2329 /* Frame has reached destination. Don't forward */
2330 if (!is_multicast_ether_addr(hdr->addr1) &&
2331 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2334 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2335 q = sdata->vif.hw_queue[ac];
2336 if (ieee80211_queue_stopped(&local->hw, q)) {
2337 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2338 return RX_DROP_MONITOR;
2340 skb_set_queue_mapping(skb, q);
2342 if (!--mesh_hdr->ttl) {
2343 if (!is_multicast_ether_addr(hdr->addr1))
2344 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2345 dropped_frames_ttl);
2349 if (!ifmsh->mshcfg.dot11MeshForwarding)
2352 fwd_skb = skb_copy(skb, GFP_ATOMIC);
2354 net_info_ratelimited("%s: failed to clone mesh frame\n",
2359 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2360 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2361 info = IEEE80211_SKB_CB(fwd_skb);
2362 memset(info, 0, sizeof(*info));
2363 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2364 info->control.vif = &rx->sdata->vif;
2365 info->control.jiffies = jiffies;
2366 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2367 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2368 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2369 /* update power mode indication when forwarding */
2370 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2371 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2372 /* mesh power mode flags updated in mesh_nexthop_lookup */
2373 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2375 /* unable to resolve next hop */
2376 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2378 WLAN_REASON_MESH_PATH_NOFORWARD,
2380 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2382 return RX_DROP_MONITOR;
2385 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2386 ieee80211_add_pending_skb(local, fwd_skb);
2388 if (is_multicast_ether_addr(hdr->addr1))
2390 return RX_DROP_MONITOR;
2394 static ieee80211_rx_result debug_noinline
2395 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2397 struct ieee80211_sub_if_data *sdata = rx->sdata;
2398 struct ieee80211_local *local = rx->local;
2399 struct net_device *dev = sdata->dev;
2400 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2401 __le16 fc = hdr->frame_control;
2405 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2408 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2409 return RX_DROP_MONITOR;
2412 /* The seqno index has the same property as needed
2413 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2414 * for non-QoS-data frames. Here we know it's a data
2415 * frame, so count MSDUs.
2417 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2421 * Send unexpected-4addr-frame event to hostapd. For older versions,
2422 * also drop the frame to cooked monitor interfaces.
2424 if (ieee80211_has_a4(hdr->frame_control) &&
2425 sdata->vif.type == NL80211_IFTYPE_AP) {
2427 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2428 cfg80211_rx_unexpected_4addr_frame(
2429 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2430 return RX_DROP_MONITOR;
2433 err = __ieee80211_data_to_8023(rx, &port_control);
2435 return RX_DROP_UNUSABLE;
2437 if (!ieee80211_frame_allowed(rx, fc))
2438 return RX_DROP_MONITOR;
2440 /* directly handle TDLS channel switch requests/responses */
2441 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2442 cpu_to_be16(ETH_P_TDLS))) {
2443 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2445 if (pskb_may_pull(rx->skb,
2446 offsetof(struct ieee80211_tdls_data, u)) &&
2447 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2448 tf->category == WLAN_CATEGORY_TDLS &&
2449 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2450 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2451 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2452 schedule_work(&local->tdls_chsw_work);
2454 rx->sta->rx_stats.packets++;
2460 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2461 unlikely(port_control) && sdata->bss) {
2462 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2470 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2471 !is_multicast_ether_addr(
2472 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2473 (!local->scanning &&
2474 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
2475 mod_timer(&local->dynamic_ps_timer, jiffies +
2476 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2479 ieee80211_deliver_skb(rx);
2484 static ieee80211_rx_result debug_noinline
2485 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2487 struct sk_buff *skb = rx->skb;
2488 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2489 struct tid_ampdu_rx *tid_agg_rx;
2493 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2496 if (ieee80211_is_back_req(bar->frame_control)) {
2498 __le16 control, start_seq_num;
2499 } __packed bar_data;
2500 struct ieee80211_event event = {
2501 .type = BAR_RX_EVENT,
2505 return RX_DROP_MONITOR;
2507 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2508 &bar_data, sizeof(bar_data)))
2509 return RX_DROP_MONITOR;
2511 tid = le16_to_cpu(bar_data.control) >> 12;
2513 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2515 return RX_DROP_MONITOR;
2517 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2518 event.u.ba.tid = tid;
2519 event.u.ba.ssn = start_seq_num;
2520 event.u.ba.sta = &rx->sta->sta;
2522 /* reset session timer */
2523 if (tid_agg_rx->timeout)
2524 mod_timer(&tid_agg_rx->session_timer,
2525 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2527 spin_lock(&tid_agg_rx->reorder_lock);
2528 /* release stored frames up to start of BAR */
2529 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2530 start_seq_num, frames);
2531 spin_unlock(&tid_agg_rx->reorder_lock);
2533 drv_event_callback(rx->local, rx->sdata, &event);
2540 * After this point, we only want management frames,
2541 * so we can drop all remaining control frames to
2542 * cooked monitor interfaces.
2544 return RX_DROP_MONITOR;
2547 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2548 struct ieee80211_mgmt *mgmt,
2551 struct ieee80211_local *local = sdata->local;
2552 struct sk_buff *skb;
2553 struct ieee80211_mgmt *resp;
2555 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2556 /* Not to own unicast address */
2560 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2561 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2562 /* Not from the current AP or not associated yet. */
2566 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2567 /* Too short SA Query request frame */
2571 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2575 skb_reserve(skb, local->hw.extra_tx_headroom);
2576 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2577 memset(resp, 0, 24);
2578 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2579 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2580 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2581 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2582 IEEE80211_STYPE_ACTION);
2583 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2584 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2585 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2586 memcpy(resp->u.action.u.sa_query.trans_id,
2587 mgmt->u.action.u.sa_query.trans_id,
2588 WLAN_SA_QUERY_TR_ID_LEN);
2590 ieee80211_tx_skb(sdata, skb);
2593 static ieee80211_rx_result debug_noinline
2594 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2596 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2597 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2600 * From here on, look only at management frames.
2601 * Data and control frames are already handled,
2602 * and unknown (reserved) frames are useless.
2604 if (rx->skb->len < 24)
2605 return RX_DROP_MONITOR;
2607 if (!ieee80211_is_mgmt(mgmt->frame_control))
2608 return RX_DROP_MONITOR;
2610 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2611 ieee80211_is_beacon(mgmt->frame_control) &&
2612 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2615 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
2616 sig = status->signal;
2618 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2619 rx->skb->data, rx->skb->len,
2621 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2624 if (ieee80211_drop_unencrypted_mgmt(rx))
2625 return RX_DROP_UNUSABLE;
2630 static ieee80211_rx_result debug_noinline
2631 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2633 struct ieee80211_local *local = rx->local;
2634 struct ieee80211_sub_if_data *sdata = rx->sdata;
2635 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2636 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2637 int len = rx->skb->len;
2639 if (!ieee80211_is_action(mgmt->frame_control))
2642 /* drop too small frames */
2643 if (len < IEEE80211_MIN_ACTION_SIZE)
2644 return RX_DROP_UNUSABLE;
2646 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
2647 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2648 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
2649 return RX_DROP_UNUSABLE;
2651 switch (mgmt->u.action.category) {
2652 case WLAN_CATEGORY_HT:
2653 /* reject HT action frames from stations not supporting HT */
2654 if (!rx->sta->sta.ht_cap.ht_supported)
2657 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2658 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2659 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2660 sdata->vif.type != NL80211_IFTYPE_AP &&
2661 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2664 /* verify action & smps_control/chanwidth are present */
2665 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2668 switch (mgmt->u.action.u.ht_smps.action) {
2669 case WLAN_HT_ACTION_SMPS: {
2670 struct ieee80211_supported_band *sband;
2671 enum ieee80211_smps_mode smps_mode;
2673 /* convert to HT capability */
2674 switch (mgmt->u.action.u.ht_smps.smps_control) {
2675 case WLAN_HT_SMPS_CONTROL_DISABLED:
2676 smps_mode = IEEE80211_SMPS_OFF;
2678 case WLAN_HT_SMPS_CONTROL_STATIC:
2679 smps_mode = IEEE80211_SMPS_STATIC;
2681 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
2682 smps_mode = IEEE80211_SMPS_DYNAMIC;
2688 /* if no change do nothing */
2689 if (rx->sta->sta.smps_mode == smps_mode)
2691 rx->sta->sta.smps_mode = smps_mode;
2693 sband = rx->local->hw.wiphy->bands[status->band];
2695 rate_control_rate_update(local, sband, rx->sta,
2696 IEEE80211_RC_SMPS_CHANGED);
2699 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2700 struct ieee80211_supported_band *sband;
2701 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
2702 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
2704 /* If it doesn't support 40 MHz it can't change ... */
2705 if (!(rx->sta->sta.ht_cap.cap &
2706 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
2709 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
2710 max_bw = IEEE80211_STA_RX_BW_20;
2712 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
2714 /* set cur_max_bandwidth and recalc sta bw */
2715 rx->sta->cur_max_bandwidth = max_bw;
2716 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
2718 if (rx->sta->sta.bandwidth == new_bw)
2721 rx->sta->sta.bandwidth = new_bw;
2722 sband = rx->local->hw.wiphy->bands[status->band];
2724 rate_control_rate_update(local, sband, rx->sta,
2725 IEEE80211_RC_BW_CHANGED);
2733 case WLAN_CATEGORY_PUBLIC:
2734 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2736 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2740 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
2742 if (mgmt->u.action.u.ext_chan_switch.action_code !=
2743 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
2745 if (len < offsetof(struct ieee80211_mgmt,
2746 u.action.u.ext_chan_switch.variable))
2749 case WLAN_CATEGORY_VHT:
2750 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2751 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2752 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2753 sdata->vif.type != NL80211_IFTYPE_AP &&
2754 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2757 /* verify action code is present */
2758 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2761 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
2762 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
2765 /* verify opmode is present */
2766 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2769 opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
2771 ieee80211_vht_handle_opmode(rx->sdata, rx->sta,
2772 opmode, status->band);
2779 case WLAN_CATEGORY_BACK:
2780 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2781 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2782 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2783 sdata->vif.type != NL80211_IFTYPE_AP &&
2784 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2787 /* verify action_code is present */
2788 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2791 switch (mgmt->u.action.u.addba_req.action_code) {
2792 case WLAN_ACTION_ADDBA_REQ:
2793 if (len < (IEEE80211_MIN_ACTION_SIZE +
2794 sizeof(mgmt->u.action.u.addba_req)))
2797 case WLAN_ACTION_ADDBA_RESP:
2798 if (len < (IEEE80211_MIN_ACTION_SIZE +
2799 sizeof(mgmt->u.action.u.addba_resp)))
2802 case WLAN_ACTION_DELBA:
2803 if (len < (IEEE80211_MIN_ACTION_SIZE +
2804 sizeof(mgmt->u.action.u.delba)))
2812 case WLAN_CATEGORY_SPECTRUM_MGMT:
2813 /* verify action_code is present */
2814 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2817 switch (mgmt->u.action.u.measurement.action_code) {
2818 case WLAN_ACTION_SPCT_MSR_REQ:
2819 if (status->band != IEEE80211_BAND_5GHZ)
2822 if (len < (IEEE80211_MIN_ACTION_SIZE +
2823 sizeof(mgmt->u.action.u.measurement)))
2826 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2829 ieee80211_process_measurement_req(sdata, mgmt, len);
2831 case WLAN_ACTION_SPCT_CHL_SWITCH: {
2833 if (len < (IEEE80211_MIN_ACTION_SIZE +
2834 sizeof(mgmt->u.action.u.chan_switch)))
2837 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2838 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2839 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
2842 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2843 bssid = sdata->u.mgd.bssid;
2844 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2845 bssid = sdata->u.ibss.bssid;
2846 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
2851 if (!ether_addr_equal(mgmt->bssid, bssid))
2858 case WLAN_CATEGORY_SA_QUERY:
2859 if (len < (IEEE80211_MIN_ACTION_SIZE +
2860 sizeof(mgmt->u.action.u.sa_query)))
2863 switch (mgmt->u.action.u.sa_query.action) {
2864 case WLAN_ACTION_SA_QUERY_REQUEST:
2865 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2867 ieee80211_process_sa_query_req(sdata, mgmt, len);
2871 case WLAN_CATEGORY_SELF_PROTECTED:
2872 if (len < (IEEE80211_MIN_ACTION_SIZE +
2873 sizeof(mgmt->u.action.u.self_prot.action_code)))
2876 switch (mgmt->u.action.u.self_prot.action_code) {
2877 case WLAN_SP_MESH_PEERING_OPEN:
2878 case WLAN_SP_MESH_PEERING_CLOSE:
2879 case WLAN_SP_MESH_PEERING_CONFIRM:
2880 if (!ieee80211_vif_is_mesh(&sdata->vif))
2882 if (sdata->u.mesh.user_mpm)
2883 /* userspace handles this frame */
2886 case WLAN_SP_MGK_INFORM:
2887 case WLAN_SP_MGK_ACK:
2888 if (!ieee80211_vif_is_mesh(&sdata->vif))
2893 case WLAN_CATEGORY_MESH_ACTION:
2894 if (len < (IEEE80211_MIN_ACTION_SIZE +
2895 sizeof(mgmt->u.action.u.mesh_action.action_code)))
2898 if (!ieee80211_vif_is_mesh(&sdata->vif))
2900 if (mesh_action_is_path_sel(mgmt) &&
2901 !mesh_path_sel_is_hwmp(sdata))
2909 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
2910 /* will return in the next handlers */
2915 rx->sta->rx_stats.packets++;
2916 dev_kfree_skb(rx->skb);
2920 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2921 skb_queue_tail(&sdata->skb_queue, rx->skb);
2922 ieee80211_queue_work(&local->hw, &sdata->work);
2924 rx->sta->rx_stats.packets++;
2928 static ieee80211_rx_result debug_noinline
2929 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2931 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2934 /* skip known-bad action frames and return them in the next handler */
2935 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
2939 * Getting here means the kernel doesn't know how to handle
2940 * it, but maybe userspace does ... include returned frames
2941 * so userspace can register for those to know whether ones
2942 * it transmitted were processed or returned.
2945 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
2946 sig = status->signal;
2948 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
2949 rx->skb->data, rx->skb->len, 0)) {
2951 rx->sta->rx_stats.packets++;
2952 dev_kfree_skb(rx->skb);
2959 static ieee80211_rx_result debug_noinline
2960 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2962 struct ieee80211_local *local = rx->local;
2963 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2964 struct sk_buff *nskb;
2965 struct ieee80211_sub_if_data *sdata = rx->sdata;
2966 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2968 if (!ieee80211_is_action(mgmt->frame_control))
2972 * For AP mode, hostapd is responsible for handling any action
2973 * frames that we didn't handle, including returning unknown
2974 * ones. For all other modes we will return them to the sender,
2975 * setting the 0x80 bit in the action category, as required by
2976 * 802.11-2012 9.24.4.
2977 * Newer versions of hostapd shall also use the management frame
2978 * registration mechanisms, but older ones still use cooked
2979 * monitor interfaces so push all frames there.
2981 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
2982 (sdata->vif.type == NL80211_IFTYPE_AP ||
2983 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2984 return RX_DROP_MONITOR;
2986 if (is_multicast_ether_addr(mgmt->da))
2987 return RX_DROP_MONITOR;
2989 /* do not return rejected action frames */
2990 if (mgmt->u.action.category & 0x80)
2991 return RX_DROP_UNUSABLE;
2993 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2996 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
2998 nmgmt->u.action.category |= 0x80;
2999 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3000 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3002 memset(nskb->cb, 0, sizeof(nskb->cb));
3004 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3005 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3007 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3008 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3009 IEEE80211_TX_CTL_NO_CCK_RATE;
3010 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3012 local->hw.offchannel_tx_hw_queue;
3015 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3018 dev_kfree_skb(rx->skb);
3022 static ieee80211_rx_result debug_noinline
3023 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3025 struct ieee80211_sub_if_data *sdata = rx->sdata;
3026 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3029 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3031 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3032 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3033 sdata->vif.type != NL80211_IFTYPE_OCB &&
3034 sdata->vif.type != NL80211_IFTYPE_STATION)
3035 return RX_DROP_MONITOR;
3038 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3039 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3040 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3041 /* process for all: mesh, mlme, ibss */
3043 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3044 if (is_multicast_ether_addr(mgmt->da) &&
3045 !is_broadcast_ether_addr(mgmt->da))
3046 return RX_DROP_MONITOR;
3048 /* process only for station/IBSS */
3049 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3050 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3051 return RX_DROP_MONITOR;
3053 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3054 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3055 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3056 if (is_multicast_ether_addr(mgmt->da) &&
3057 !is_broadcast_ether_addr(mgmt->da))
3058 return RX_DROP_MONITOR;
3060 /* process only for station */
3061 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3062 return RX_DROP_MONITOR;
3064 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3065 /* process only for ibss and mesh */
3066 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3067 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3068 return RX_DROP_MONITOR;
3071 return RX_DROP_MONITOR;
3074 /* queue up frame and kick off work to process it */
3075 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
3076 skb_queue_tail(&sdata->skb_queue, rx->skb);
3077 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3079 rx->sta->rx_stats.packets++;
3084 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3085 struct ieee80211_rate *rate)
3087 struct ieee80211_sub_if_data *sdata;
3088 struct ieee80211_local *local = rx->local;
3089 struct sk_buff *skb = rx->skb, *skb2;
3090 struct net_device *prev_dev = NULL;
3091 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3092 int needed_headroom;
3095 * If cooked monitor has been processed already, then
3096 * don't do it again. If not, set the flag.
3098 if (rx->flags & IEEE80211_RX_CMNTR)
3100 rx->flags |= IEEE80211_RX_CMNTR;
3102 /* If there are no cooked monitor interfaces, just free the SKB */
3103 if (!local->cooked_mntrs)
3106 /* vendor data is long removed here */
3107 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3108 /* room for the radiotap header based on driver features */
3109 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3111 if (skb_headroom(skb) < needed_headroom &&
3112 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3115 /* prepend radiotap information */
3116 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3119 skb_set_mac_header(skb, 0);
3120 skb->ip_summed = CHECKSUM_UNNECESSARY;
3121 skb->pkt_type = PACKET_OTHERHOST;
3122 skb->protocol = htons(ETH_P_802_2);
3124 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3125 if (!ieee80211_sdata_running(sdata))
3128 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3129 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
3133 skb2 = skb_clone(skb, GFP_ATOMIC);
3135 skb2->dev = prev_dev;
3136 netif_receive_skb(skb2);
3140 prev_dev = sdata->dev;
3141 ieee80211_rx_stats(sdata->dev, skb->len);
3145 skb->dev = prev_dev;
3146 netif_receive_skb(skb);
3154 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3155 ieee80211_rx_result res)
3158 case RX_DROP_MONITOR:
3159 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3161 rx->sta->rx_stats.dropped++;
3164 struct ieee80211_rate *rate = NULL;
3165 struct ieee80211_supported_band *sband;
3166 struct ieee80211_rx_status *status;
3168 status = IEEE80211_SKB_RXCB((rx->skb));
3170 sband = rx->local->hw.wiphy->bands[status->band];
3171 if (!(status->flag & RX_FLAG_HT) &&
3172 !(status->flag & RX_FLAG_VHT))
3173 rate = &sband->bitrates[status->rate_idx];
3175 ieee80211_rx_cooked_monitor(rx, rate);
3178 case RX_DROP_UNUSABLE:
3179 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3181 rx->sta->rx_stats.dropped++;
3182 dev_kfree_skb(rx->skb);
3185 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3190 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3191 struct sk_buff_head *frames)
3193 ieee80211_rx_result res = RX_DROP_MONITOR;
3194 struct sk_buff *skb;
3196 #define CALL_RXH(rxh) \
3199 if (res != RX_CONTINUE) \
3203 /* Lock here to avoid hitting all of the data used in the RX
3204 * path (e.g. key data, station data, ...) concurrently when
3205 * a frame is released from the reorder buffer due to timeout
3206 * from the timer, potentially concurrently with RX from the
3209 spin_lock_bh(&rx->local->rx_path_lock);
3211 while ((skb = __skb_dequeue(frames))) {
3213 * all the other fields are valid across frames
3214 * that belong to an aMPDU since they are on the
3215 * same TID from the same station
3219 CALL_RXH(ieee80211_rx_h_check_more_data)
3220 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
3221 CALL_RXH(ieee80211_rx_h_sta_process)
3222 CALL_RXH(ieee80211_rx_h_decrypt)
3223 CALL_RXH(ieee80211_rx_h_defragment)
3224 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
3225 /* must be after MMIC verify so header is counted in MPDU mic */
3226 #ifdef CONFIG_MAC80211_MESH
3227 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3228 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3230 CALL_RXH(ieee80211_rx_h_amsdu)
3231 CALL_RXH(ieee80211_rx_h_data)
3233 /* special treatment -- needs the queue */
3234 res = ieee80211_rx_h_ctrl(rx, frames);
3235 if (res != RX_CONTINUE)
3238 CALL_RXH(ieee80211_rx_h_mgmt_check)
3239 CALL_RXH(ieee80211_rx_h_action)
3240 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
3241 CALL_RXH(ieee80211_rx_h_action_return)
3242 CALL_RXH(ieee80211_rx_h_mgmt)
3245 ieee80211_rx_handlers_result(rx, res);
3250 spin_unlock_bh(&rx->local->rx_path_lock);
3253 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3255 struct sk_buff_head reorder_release;
3256 ieee80211_rx_result res = RX_DROP_MONITOR;
3258 __skb_queue_head_init(&reorder_release);
3260 #define CALL_RXH(rxh) \
3263 if (res != RX_CONTINUE) \
3267 CALL_RXH(ieee80211_rx_h_check_dup)
3268 CALL_RXH(ieee80211_rx_h_check)
3270 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3272 ieee80211_rx_handlers(rx, &reorder_release);
3276 ieee80211_rx_handlers_result(rx, res);
3282 * This function makes calls into the RX path, therefore
3283 * it has to be invoked under RCU read lock.
3285 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3287 struct sk_buff_head frames;
3288 struct ieee80211_rx_data rx = {
3290 .sdata = sta->sdata,
3291 .local = sta->local,
3292 /* This is OK -- must be QoS data frame */
3293 .security_idx = tid,
3295 .napi = NULL, /* must be NULL to not have races */
3297 struct tid_ampdu_rx *tid_agg_rx;
3299 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3303 __skb_queue_head_init(&frames);
3305 spin_lock(&tid_agg_rx->reorder_lock);
3306 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3307 spin_unlock(&tid_agg_rx->reorder_lock);
3309 if (!skb_queue_empty(&frames)) {
3310 struct ieee80211_event event = {
3311 .type = BA_FRAME_TIMEOUT,
3313 .u.ba.sta = &sta->sta,
3315 drv_event_callback(rx.local, rx.sdata, &event);
3318 ieee80211_rx_handlers(&rx, &frames);
3321 /* main receive path */
3323 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3325 struct ieee80211_sub_if_data *sdata = rx->sdata;
3326 struct sk_buff *skb = rx->skb;
3327 struct ieee80211_hdr *hdr = (void *)skb->data;
3328 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3329 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3330 int multicast = is_multicast_ether_addr(hdr->addr1);
3332 switch (sdata->vif.type) {
3333 case NL80211_IFTYPE_STATION:
3334 if (!bssid && !sdata->u.mgd.use_4addr)
3336 if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
3340 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3341 case NL80211_IFTYPE_ADHOC:
3344 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3345 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
3347 if (ieee80211_is_beacon(hdr->frame_control))
3349 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3352 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3356 if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
3357 rate_idx = 0; /* TODO: HT/VHT rates */
3359 rate_idx = status->rate_idx;
3360 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3364 case NL80211_IFTYPE_OCB:
3367 if (!ieee80211_is_data_present(hdr->frame_control))
3369 if (!is_broadcast_ether_addr(bssid))
3372 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3376 if (status->flag & RX_FLAG_HT)
3377 rate_idx = 0; /* TODO: HT rates */
3379 rate_idx = status->rate_idx;
3380 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3384 case NL80211_IFTYPE_MESH_POINT:
3385 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
3389 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3390 case NL80211_IFTYPE_AP_VLAN:
3391 case NL80211_IFTYPE_AP:
3393 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3395 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3397 * Accept public action frames even when the
3398 * BSSID doesn't match, this is used for P2P
3399 * and location updates. Note that mac80211
3400 * itself never looks at these frames.
3403 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3405 if (ieee80211_is_public_action(hdr, skb->len))
3407 return ieee80211_is_beacon(hdr->frame_control);
3410 if (!ieee80211_has_tods(hdr->frame_control)) {
3411 /* ignore data frames to TDLS-peers */
3412 if (ieee80211_is_data(hdr->frame_control))
3414 /* ignore action frames to TDLS-peers */
3415 if (ieee80211_is_action(hdr->frame_control) &&
3416 !is_broadcast_ether_addr(bssid) &&
3417 !ether_addr_equal(bssid, hdr->addr1))
3422 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3423 * the BSSID - we've checked that already but may have accepted
3424 * the wildcard (ff:ff:ff:ff:ff:ff).
3427 * The BSSID of the Data frame is determined as follows:
3428 * a) If the STA is contained within an AP or is associated
3429 * with an AP, the BSSID is the address currently in use
3430 * by the STA contained in the AP.
3432 * So we should not accept data frames with an address that's
3435 * Accepting it also opens a security problem because stations
3436 * could encrypt it with the GTK and inject traffic that way.
3438 if (ieee80211_is_data(hdr->frame_control) && multicast)
3442 case NL80211_IFTYPE_WDS:
3443 if (bssid || !ieee80211_is_data(hdr->frame_control))
3445 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3446 case NL80211_IFTYPE_P2P_DEVICE:
3447 return ieee80211_is_public_action(hdr, skb->len) ||
3448 ieee80211_is_probe_req(hdr->frame_control) ||
3449 ieee80211_is_probe_resp(hdr->frame_control) ||
3450 ieee80211_is_beacon(hdr->frame_control);
3460 * This function returns whether or not the SKB
3461 * was destined for RX processing or not, which,
3462 * if consume is true, is equivalent to whether
3463 * or not the skb was consumed.
3465 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
3466 struct sk_buff *skb, bool consume)
3468 struct ieee80211_local *local = rx->local;
3469 struct ieee80211_sub_if_data *sdata = rx->sdata;
3473 if (!ieee80211_accept_frame(rx))
3477 skb = skb_copy(skb, GFP_ATOMIC);
3479 if (net_ratelimit())
3480 wiphy_debug(local->hw.wiphy,
3481 "failed to copy skb for %s\n",
3489 ieee80211_invoke_rx_handlers(rx);
3494 * This is the actual Rx frames handler. as it belongs to Rx path it must
3495 * be called with rcu_read_lock protection.
3497 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
3498 struct sk_buff *skb,
3499 struct napi_struct *napi)
3501 struct ieee80211_local *local = hw_to_local(hw);
3502 struct ieee80211_sub_if_data *sdata;
3503 struct ieee80211_hdr *hdr;
3505 struct ieee80211_rx_data rx;
3506 struct ieee80211_sub_if_data *prev;
3507 struct sta_info *sta, *prev_sta;
3508 struct rhash_head *tmp;
3511 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
3512 memset(&rx, 0, sizeof(rx));
3517 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
3518 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
3520 if (ieee80211_is_mgmt(fc)) {
3521 /* drop frame if too short for header */
3522 if (skb->len < ieee80211_hdrlen(fc))
3525 err = skb_linearize(skb);
3527 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
3535 hdr = (struct ieee80211_hdr *)skb->data;
3536 ieee80211_parse_qos(&rx);
3537 ieee80211_verify_alignment(&rx);
3539 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
3540 ieee80211_is_beacon(hdr->frame_control)))
3541 ieee80211_scan_rx(local, skb);
3543 if (ieee80211_is_data(fc)) {
3544 const struct bucket_table *tbl;
3548 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
3550 for_each_sta_info(local, tbl, hdr->addr2, sta, tmp) {
3557 rx.sdata = prev_sta->sdata;
3558 ieee80211_prepare_and_rx_handle(&rx, skb, false);
3565 rx.sdata = prev_sta->sdata;
3567 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3575 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3576 if (!ieee80211_sdata_running(sdata))
3579 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
3580 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3584 * frame is destined for this interface, but if it's
3585 * not also for the previous one we handle that after
3586 * the loop to avoid copying the SKB once too much
3594 rx.sta = sta_info_get_bss(prev, hdr->addr2);
3596 ieee80211_prepare_and_rx_handle(&rx, skb, false);
3602 rx.sta = sta_info_get_bss(prev, hdr->addr2);
3605 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3614 * This is the receive path handler. It is called by a low level driver when an
3615 * 802.11 MPDU is received from the hardware.
3617 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct sk_buff *skb,
3618 struct napi_struct *napi)
3620 struct ieee80211_local *local = hw_to_local(hw);
3621 struct ieee80211_rate *rate = NULL;
3622 struct ieee80211_supported_band *sband;
3623 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3625 WARN_ON_ONCE(softirq_count() == 0);
3627 if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
3630 sband = local->hw.wiphy->bands[status->band];
3631 if (WARN_ON(!sband))
3635 * If we're suspending, it is possible although not too likely
3636 * that we'd be receiving frames after having already partially
3637 * quiesced the stack. We can't process such frames then since
3638 * that might, for example, cause stations to be added or other
3639 * driver callbacks be invoked.
3641 if (unlikely(local->quiescing || local->suspended))
3644 /* We might be during a HW reconfig, prevent Rx for the same reason */
3645 if (unlikely(local->in_reconfig))
3649 * The same happens when we're not even started,
3650 * but that's worth a warning.
3652 if (WARN_ON(!local->started))
3655 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
3657 * Validate the rate, unless a PLCP error means that
3658 * we probably can't have a valid rate here anyway.
3661 if (status->flag & RX_FLAG_HT) {
3663 * rate_idx is MCS index, which can be [0-76]
3666 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
3668 * Anything else would be some sort of driver or
3669 * hardware error. The driver should catch hardware
3672 if (WARN(status->rate_idx > 76,
3673 "Rate marked as an HT rate but passed "
3674 "status->rate_idx is not "
3675 "an MCS index [0-76]: %d (0x%02x)\n",
3679 } else if (status->flag & RX_FLAG_VHT) {
3680 if (WARN_ONCE(status->rate_idx > 9 ||
3682 status->vht_nss > 8,
3683 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
3684 status->rate_idx, status->vht_nss))
3687 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
3689 rate = &sband->bitrates[status->rate_idx];
3693 status->rx_flags = 0;
3696 * key references and virtual interfaces are protected using RCU
3697 * and this requires that we are in a read-side RCU section during
3698 * receive processing
3703 * Frames with failed FCS/PLCP checksum are not returned,
3704 * all other frames are returned without radiotap header
3705 * if it was previously present.
3706 * Also, frames with less than 16 bytes are dropped.
3708 skb = ieee80211_rx_monitor(local, skb, rate);
3714 ieee80211_tpt_led_trig_rx(local,
3715 ((struct ieee80211_hdr *)skb->data)->frame_control,
3717 __ieee80211_rx_handle_packet(hw, skb, napi);
3725 EXPORT_SYMBOL(ieee80211_rx_napi);
3727 /* This is a version of the rx handler that can be called from hard irq
3728 * context. Post the skb on the queue and schedule the tasklet */
3729 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
3731 struct ieee80211_local *local = hw_to_local(hw);
3733 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3735 skb->pkt_type = IEEE80211_RX_MSG;
3736 skb_queue_tail(&local->skb_queue, skb);
3737 tasklet_schedule(&local->tasklet);
3739 EXPORT_SYMBOL(ieee80211_rx_irqsafe);