2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/jiffies.h>
15 #include <linux/slab.h>
16 #include <linux/kernel.h>
17 #include <linux/skbuff.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/rcupdate.h>
21 #include <linux/export.h>
22 #include <linux/bitops.h>
23 #include <net/mac80211.h>
24 #include <net/ieee80211_radiotap.h>
25 #include <asm/unaligned.h>
27 #include "ieee80211_i.h"
28 #include "driver-ops.h"
37 static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
39 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
41 u64_stats_update_begin(&tstats->syncp);
43 tstats->rx_bytes += len;
44 u64_stats_update_end(&tstats->syncp);
47 static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
48 enum nl80211_iftype type)
50 __le16 fc = hdr->frame_control;
52 if (ieee80211_is_data(fc)) {
53 if (len < 24) /* drop incorrect hdr len (data) */
56 if (ieee80211_has_a4(fc))
58 if (ieee80211_has_tods(fc))
60 if (ieee80211_has_fromds(fc))
66 if (ieee80211_is_mgmt(fc)) {
67 if (len < 24) /* drop incorrect hdr len (mgmt) */
72 if (ieee80211_is_ctl(fc)) {
73 if (ieee80211_is_pspoll(fc))
76 if (ieee80211_is_back_req(fc)) {
78 case NL80211_IFTYPE_STATION:
80 case NL80211_IFTYPE_AP:
81 case NL80211_IFTYPE_AP_VLAN:
84 break; /* fall through to the return */
93 * monitor mode reception
95 * This function cleans up the SKB, i.e. it removes all the stuff
96 * only useful for monitoring.
98 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
100 unsigned int rtap_vendor_space)
102 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
103 if (likely(skb->len > FCS_LEN))
104 __pskb_trim(skb, skb->len - FCS_LEN);
113 __pskb_pull(skb, rtap_vendor_space);
118 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
119 unsigned int rtap_vendor_space)
121 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
122 struct ieee80211_hdr *hdr;
124 hdr = (void *)(skb->data + rtap_vendor_space);
126 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
127 RX_FLAG_FAILED_PLCP_CRC |
128 RX_FLAG_ONLY_MONITOR))
131 if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space))
134 if (ieee80211_is_ctl(hdr->frame_control) &&
135 !ieee80211_is_pspoll(hdr->frame_control) &&
136 !ieee80211_is_back_req(hdr->frame_control))
143 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
144 struct ieee80211_rx_status *status,
149 /* always present fields */
150 len = sizeof(struct ieee80211_radiotap_header) + 8;
152 /* allocate extra bitmaps */
154 len += 4 * hweight8(status->chains);
155 /* vendor presence bitmap */
156 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)
159 if (ieee80211_have_rx_timestamp(status)) {
163 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
166 /* antenna field, if we don't have per-chain info */
170 /* padding for RX_FLAGS if necessary */
173 if (status->flag & RX_FLAG_HT) /* HT info */
176 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
181 if (status->flag & RX_FLAG_VHT) {
186 if (local->hw.radiotap_timestamp.units_pos >= 0) {
191 if (status->chains) {
192 /* antenna and antenna signal fields */
193 len += 2 * hweight8(status->chains);
196 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
197 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
199 /* alignment for fixed 6-byte vendor data header */
201 /* vendor data header */
203 if (WARN_ON(rtap->align == 0))
205 len = ALIGN(len, rtap->align);
206 len += rtap->len + rtap->pad;
212 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
214 int rtap_vendor_space)
217 struct ieee80211_hdr_3addr hdr;
220 } __packed __aligned(2) action;
225 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
227 if (skb->len < rtap_vendor_space + sizeof(action) +
228 VHT_MUMIMO_GROUPS_DATA_LEN)
231 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
234 skb_copy_bits(skb, rtap_vendor_space, &action, sizeof(action));
236 if (!ieee80211_is_action(action.hdr.frame_control))
239 if (action.category != WLAN_CATEGORY_VHT)
242 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
245 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
248 skb = skb_copy(skb, GFP_ATOMIC);
252 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
253 skb_queue_tail(&sdata->skb_queue, skb);
254 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
258 * ieee80211_add_rx_radiotap_header - add radiotap header
260 * add a radiotap header containing all the fields which the hardware provided.
263 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
265 struct ieee80211_rate *rate,
266 int rtap_len, bool has_fcs)
268 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
269 struct ieee80211_radiotap_header *rthdr;
274 u16 channel_flags = 0;
276 unsigned long chains = status->chains;
277 struct ieee80211_vendor_radiotap rtap = {};
279 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
280 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
281 /* rtap.len and rtap.pad are undone immediately */
282 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
286 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
289 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
290 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
291 it_present = &rthdr->it_present;
293 /* radiotap header, set always present flags */
294 rthdr->it_len = cpu_to_le16(rtap_len);
295 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
296 BIT(IEEE80211_RADIOTAP_CHANNEL) |
297 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
300 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
302 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
304 BIT(IEEE80211_RADIOTAP_EXT) |
305 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
306 put_unaligned_le32(it_present_val, it_present);
308 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
309 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
312 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
313 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
314 BIT(IEEE80211_RADIOTAP_EXT);
315 put_unaligned_le32(it_present_val, it_present);
317 it_present_val = rtap.present;
320 put_unaligned_le32(it_present_val, it_present);
322 pos = (void *)(it_present + 1);
324 /* the order of the following fields is important */
326 /* IEEE80211_RADIOTAP_TSFT */
327 if (ieee80211_have_rx_timestamp(status)) {
329 while ((pos - (u8 *)rthdr) & 7)
332 ieee80211_calculate_rx_timestamp(local, status,
335 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
339 /* IEEE80211_RADIOTAP_FLAGS */
340 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
341 *pos |= IEEE80211_RADIOTAP_F_FCS;
342 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
343 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
344 if (status->flag & RX_FLAG_SHORTPRE)
345 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
348 /* IEEE80211_RADIOTAP_RATE */
349 if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
351 * Without rate information don't add it. If we have,
352 * MCS information is a separate field in radiotap,
353 * added below. The byte here is needed as padding
354 * for the channel though, so initialise it to 0.
359 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
360 if (status->flag & RX_FLAG_10MHZ)
362 else if (status->flag & RX_FLAG_5MHZ)
364 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
368 /* IEEE80211_RADIOTAP_CHANNEL */
369 put_unaligned_le16(status->freq, pos);
371 if (status->flag & RX_FLAG_10MHZ)
372 channel_flags |= IEEE80211_CHAN_HALF;
373 else if (status->flag & RX_FLAG_5MHZ)
374 channel_flags |= IEEE80211_CHAN_QUARTER;
376 if (status->band == NL80211_BAND_5GHZ)
377 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
378 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
379 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
380 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
381 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
383 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
385 channel_flags |= IEEE80211_CHAN_2GHZ;
386 put_unaligned_le16(channel_flags, pos);
389 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
390 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
391 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
392 *pos = status->signal;
394 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
398 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
400 if (!status->chains) {
401 /* IEEE80211_RADIOTAP_ANTENNA */
402 *pos = status->antenna;
406 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
408 /* IEEE80211_RADIOTAP_RX_FLAGS */
409 /* ensure 2 byte alignment for the 2 byte field as required */
410 if ((pos - (u8 *)rthdr) & 1)
412 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
413 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
414 put_unaligned_le16(rx_flags, pos);
417 if (status->flag & RX_FLAG_HT) {
420 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
421 *pos++ = local->hw.radiotap_mcs_details;
423 if (status->flag & RX_FLAG_SHORT_GI)
424 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
425 if (status->flag & RX_FLAG_40MHZ)
426 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
427 if (status->flag & RX_FLAG_HT_GF)
428 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
429 if (status->flag & RX_FLAG_LDPC)
430 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
431 stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
432 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
434 *pos++ = status->rate_idx;
437 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
440 /* ensure 4 byte alignment */
441 while ((pos - (u8 *)rthdr) & 3)
444 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
445 put_unaligned_le32(status->ampdu_reference, pos);
447 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
448 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
449 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
450 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
451 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
452 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
453 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
454 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
455 put_unaligned_le16(flags, pos);
457 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
458 *pos++ = status->ampdu_delimiter_crc;
464 if (status->flag & RX_FLAG_VHT) {
465 u16 known = local->hw.radiotap_vht_details;
467 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
468 put_unaligned_le16(known, pos);
471 if (status->flag & RX_FLAG_SHORT_GI)
472 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
473 /* in VHT, STBC is binary */
474 if (status->flag & RX_FLAG_STBC_MASK)
475 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
476 if (status->vht_flag & RX_VHT_FLAG_BF)
477 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
480 if (status->vht_flag & RX_VHT_FLAG_80MHZ)
482 else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
484 else if (status->flag & RX_FLAG_40MHZ)
489 *pos = (status->rate_idx << 4) | status->vht_nss;
492 if (status->flag & RX_FLAG_LDPC)
493 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
501 if (local->hw.radiotap_timestamp.units_pos >= 0) {
503 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
506 cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP);
508 /* ensure 8 byte alignment */
509 while ((pos - (u8 *)rthdr) & 7)
512 put_unaligned_le64(status->device_timestamp, pos);
515 if (local->hw.radiotap_timestamp.accuracy >= 0) {
516 accuracy = local->hw.radiotap_timestamp.accuracy;
517 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
519 put_unaligned_le16(accuracy, pos);
522 *pos++ = local->hw.radiotap_timestamp.units_pos;
526 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
527 *pos++ = status->chain_signal[chain];
531 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
532 /* ensure 2 byte alignment for the vendor field as required */
533 if ((pos - (u8 *)rthdr) & 1)
535 *pos++ = rtap.oui[0];
536 *pos++ = rtap.oui[1];
537 *pos++ = rtap.oui[2];
539 put_unaligned_le16(rtap.len, pos);
541 /* align the actual payload as requested */
542 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
544 /* data (and possible padding) already follows */
549 * This function copies a received frame to all monitor interfaces and
550 * returns a cleaned-up SKB that no longer includes the FCS nor the
551 * radiotap header the driver might have added.
553 static struct sk_buff *
554 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
555 struct ieee80211_rate *rate)
557 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
558 struct ieee80211_sub_if_data *sdata;
559 int rt_hdrlen, needed_headroom;
560 struct sk_buff *skb, *skb2;
561 struct net_device *prev_dev = NULL;
562 int present_fcs_len = 0;
563 unsigned int rtap_vendor_space = 0;
564 struct ieee80211_sub_if_data *monitor_sdata =
565 rcu_dereference(local->monitor_sdata);
567 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
568 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
570 rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad;
574 * First, we may need to make a copy of the skb because
575 * (1) we need to modify it for radiotap (if not present), and
576 * (2) the other RX handlers will modify the skb we got.
578 * We don't need to, of course, if we aren't going to return
579 * the SKB because it has a bad FCS/PLCP checksum.
582 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
583 present_fcs_len = FCS_LEN;
585 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
586 if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) {
587 dev_kfree_skb(origskb);
591 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
592 if (should_drop_frame(origskb, present_fcs_len,
593 rtap_vendor_space)) {
594 dev_kfree_skb(origskb);
598 return remove_monitor_info(local, origskb, rtap_vendor_space);
601 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_vendor_space);
603 /* room for the radiotap header based on driver features */
604 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb);
605 needed_headroom = rt_hdrlen - rtap_vendor_space;
607 if (should_drop_frame(origskb, present_fcs_len, rtap_vendor_space)) {
608 /* only need to expand headroom if necessary */
613 * This shouldn't trigger often because most devices have an
614 * RX header they pull before we get here, and that should
615 * be big enough for our radiotap information. We should
616 * probably export the length to drivers so that we can have
617 * them allocate enough headroom to start with.
619 if (skb_headroom(skb) < needed_headroom &&
620 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
626 * Need to make a copy and possibly remove radiotap header
627 * and FCS from the original.
629 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
631 origskb = remove_monitor_info(local, origskb,
638 /* prepend radiotap information */
639 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
641 skb_reset_mac_header(skb);
642 skb->ip_summed = CHECKSUM_UNNECESSARY;
643 skb->pkt_type = PACKET_OTHERHOST;
644 skb->protocol = htons(ETH_P_802_2);
646 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
647 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
650 if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
653 if (!ieee80211_sdata_running(sdata))
657 skb2 = skb_clone(skb, GFP_ATOMIC);
659 skb2->dev = prev_dev;
660 netif_receive_skb(skb2);
664 prev_dev = sdata->dev;
665 ieee80211_rx_stats(sdata->dev, skb->len);
670 netif_receive_skb(skb);
677 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
679 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
680 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
681 int tid, seqno_idx, security_idx;
683 /* does the frame have a qos control field? */
684 if (ieee80211_is_data_qos(hdr->frame_control)) {
685 u8 *qc = ieee80211_get_qos_ctl(hdr);
686 /* frame has qos control */
687 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
688 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
689 status->rx_flags |= IEEE80211_RX_AMSDU;
695 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
697 * Sequence numbers for management frames, QoS data
698 * frames with a broadcast/multicast address in the
699 * Address 1 field, and all non-QoS data frames sent
700 * by QoS STAs are assigned using an additional single
701 * modulo-4096 counter, [...]
703 * We also use that counter for non-QoS STAs.
705 seqno_idx = IEEE80211_NUM_TIDS;
707 if (ieee80211_is_mgmt(hdr->frame_control))
708 security_idx = IEEE80211_NUM_TIDS;
712 rx->seqno_idx = seqno_idx;
713 rx->security_idx = security_idx;
714 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
715 * For now, set skb->priority to 0 for other cases. */
716 rx->skb->priority = (tid > 7) ? 0 : tid;
720 * DOC: Packet alignment
722 * Drivers always need to pass packets that are aligned to two-byte boundaries
725 * Additionally, should, if possible, align the payload data in a way that
726 * guarantees that the contained IP header is aligned to a four-byte
727 * boundary. In the case of regular frames, this simply means aligning the
728 * payload to a four-byte boundary (because either the IP header is directly
729 * contained, or IV/RFC1042 headers that have a length divisible by four are
730 * in front of it). If the payload data is not properly aligned and the
731 * architecture doesn't support efficient unaligned operations, mac80211
732 * will align the data.
734 * With A-MSDU frames, however, the payload data address must yield two modulo
735 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
736 * push the IP header further back to a multiple of four again. Thankfully, the
737 * specs were sane enough this time around to require padding each A-MSDU
738 * subframe to a length that is a multiple of four.
740 * Padding like Atheros hardware adds which is between the 802.11 header and
741 * the payload is not supported, the driver is required to move the 802.11
742 * header to be directly in front of the payload in that case.
744 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
746 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
747 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
754 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
756 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
758 if (is_multicast_ether_addr(hdr->addr1))
761 return ieee80211_is_robust_mgmt_frame(skb);
765 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
767 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
769 if (!is_multicast_ether_addr(hdr->addr1))
772 return ieee80211_is_robust_mgmt_frame(skb);
776 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
777 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
779 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
780 struct ieee80211_mmie *mmie;
781 struct ieee80211_mmie_16 *mmie16;
783 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
786 if (!ieee80211_is_robust_mgmt_frame(skb))
787 return -1; /* not a robust management frame */
789 mmie = (struct ieee80211_mmie *)
790 (skb->data + skb->len - sizeof(*mmie));
791 if (mmie->element_id == WLAN_EID_MMIE &&
792 mmie->length == sizeof(*mmie) - 2)
793 return le16_to_cpu(mmie->key_id);
795 mmie16 = (struct ieee80211_mmie_16 *)
796 (skb->data + skb->len - sizeof(*mmie16));
797 if (skb->len >= 24 + sizeof(*mmie16) &&
798 mmie16->element_id == WLAN_EID_MMIE &&
799 mmie16->length == sizeof(*mmie16) - 2)
800 return le16_to_cpu(mmie16->key_id);
805 static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
808 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
813 fc = hdr->frame_control;
814 hdrlen = ieee80211_hdrlen(fc);
816 if (skb->len < hdrlen + cs->hdr_len)
819 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
820 keyid &= cs->key_idx_mask;
821 keyid >>= cs->key_idx_shift;
826 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
828 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
829 char *dev_addr = rx->sdata->vif.addr;
831 if (ieee80211_is_data(hdr->frame_control)) {
832 if (is_multicast_ether_addr(hdr->addr1)) {
833 if (ieee80211_has_tods(hdr->frame_control) ||
834 !ieee80211_has_fromds(hdr->frame_control))
835 return RX_DROP_MONITOR;
836 if (ether_addr_equal(hdr->addr3, dev_addr))
837 return RX_DROP_MONITOR;
839 if (!ieee80211_has_a4(hdr->frame_control))
840 return RX_DROP_MONITOR;
841 if (ether_addr_equal(hdr->addr4, dev_addr))
842 return RX_DROP_MONITOR;
846 /* If there is not an established peer link and this is not a peer link
847 * establisment frame, beacon or probe, drop the frame.
850 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
851 struct ieee80211_mgmt *mgmt;
853 if (!ieee80211_is_mgmt(hdr->frame_control))
854 return RX_DROP_MONITOR;
856 if (ieee80211_is_action(hdr->frame_control)) {
859 /* make sure category field is present */
860 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
861 return RX_DROP_MONITOR;
863 mgmt = (struct ieee80211_mgmt *)hdr;
864 category = mgmt->u.action.category;
865 if (category != WLAN_CATEGORY_MESH_ACTION &&
866 category != WLAN_CATEGORY_SELF_PROTECTED)
867 return RX_DROP_MONITOR;
871 if (ieee80211_is_probe_req(hdr->frame_control) ||
872 ieee80211_is_probe_resp(hdr->frame_control) ||
873 ieee80211_is_beacon(hdr->frame_control) ||
874 ieee80211_is_auth(hdr->frame_control))
877 return RX_DROP_MONITOR;
883 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
886 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
887 struct sk_buff *tail = skb_peek_tail(frames);
888 struct ieee80211_rx_status *status;
890 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
896 status = IEEE80211_SKB_RXCB(tail);
897 if (status->flag & RX_FLAG_AMSDU_MORE)
903 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
904 struct tid_ampdu_rx *tid_agg_rx,
906 struct sk_buff_head *frames)
908 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
910 struct ieee80211_rx_status *status;
912 lockdep_assert_held(&tid_agg_rx->reorder_lock);
914 if (skb_queue_empty(skb_list))
917 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
918 __skb_queue_purge(skb_list);
922 /* release frames from the reorder ring buffer */
923 tid_agg_rx->stored_mpdu_num--;
924 while ((skb = __skb_dequeue(skb_list))) {
925 status = IEEE80211_SKB_RXCB(skb);
926 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
927 __skb_queue_tail(frames, skb);
931 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
932 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
935 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
936 struct tid_ampdu_rx *tid_agg_rx,
938 struct sk_buff_head *frames)
942 lockdep_assert_held(&tid_agg_rx->reorder_lock);
944 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
945 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
946 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
952 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
953 * the skb was added to the buffer longer than this time ago, the earlier
954 * frames that have not yet been received are assumed to be lost and the skb
955 * can be released for processing. This may also release other skb's from the
956 * reorder buffer if there are no additional gaps between the frames.
958 * Callers must hold tid_agg_rx->reorder_lock.
960 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
962 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
963 struct tid_ampdu_rx *tid_agg_rx,
964 struct sk_buff_head *frames)
968 lockdep_assert_held(&tid_agg_rx->reorder_lock);
970 /* release the buffer until next missing frame */
971 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
972 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
973 tid_agg_rx->stored_mpdu_num) {
975 * No buffers ready to be released, but check whether any
976 * frames in the reorder buffer have timed out.
979 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
980 j = (j + 1) % tid_agg_rx->buf_size) {
981 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
986 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
987 HT_RX_REORDER_BUF_TIMEOUT))
988 goto set_release_timer;
990 /* don't leave incomplete A-MSDUs around */
991 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
992 i = (i + 1) % tid_agg_rx->buf_size)
993 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
995 ht_dbg_ratelimited(sdata,
996 "release an RX reorder frame due to timeout on earlier frames\n");
997 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1001 * Increment the head seq# also for the skipped slots.
1003 tid_agg_rx->head_seq_num =
1004 (tid_agg_rx->head_seq_num +
1005 skipped) & IEEE80211_SN_MASK;
1008 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1009 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1011 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1014 if (tid_agg_rx->stored_mpdu_num) {
1015 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1017 for (; j != (index - 1) % tid_agg_rx->buf_size;
1018 j = (j + 1) % tid_agg_rx->buf_size) {
1019 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1025 if (!tid_agg_rx->removed)
1026 mod_timer(&tid_agg_rx->reorder_timer,
1027 tid_agg_rx->reorder_time[j] + 1 +
1028 HT_RX_REORDER_BUF_TIMEOUT);
1030 del_timer(&tid_agg_rx->reorder_timer);
1035 * As this function belongs to the RX path it must be under
1036 * rcu_read_lock protection. It returns false if the frame
1037 * can be processed immediately, true if it was consumed.
1039 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1040 struct tid_ampdu_rx *tid_agg_rx,
1041 struct sk_buff *skb,
1042 struct sk_buff_head *frames)
1044 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1045 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1046 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1047 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1048 u16 head_seq_num, buf_size;
1052 spin_lock(&tid_agg_rx->reorder_lock);
1055 * Offloaded BA sessions have no known starting sequence number so pick
1056 * one from first Rxed frame for this tid after BA was started.
1058 if (unlikely(tid_agg_rx->auto_seq)) {
1059 tid_agg_rx->auto_seq = false;
1060 tid_agg_rx->ssn = mpdu_seq_num;
1061 tid_agg_rx->head_seq_num = mpdu_seq_num;
1064 buf_size = tid_agg_rx->buf_size;
1065 head_seq_num = tid_agg_rx->head_seq_num;
1068 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1071 if (unlikely(!tid_agg_rx->started)) {
1072 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1076 tid_agg_rx->started = true;
1079 /* frame with out of date sequence number */
1080 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1086 * If frame the sequence number exceeds our buffering window
1087 * size release some previous frames to make room for this one.
1089 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1090 head_seq_num = ieee80211_sn_inc(
1091 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1092 /* release stored frames up to new head to stack */
1093 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1094 head_seq_num, frames);
1097 /* Now the new frame is always in the range of the reordering buffer */
1099 index = mpdu_seq_num % tid_agg_rx->buf_size;
1101 /* check if we already stored this frame */
1102 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1108 * If the current MPDU is in the right order and nothing else
1109 * is stored we can process it directly, no need to buffer it.
1110 * If it is first but there's something stored, we may be able
1111 * to release frames after this one.
1113 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1114 tid_agg_rx->stored_mpdu_num == 0) {
1115 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1116 tid_agg_rx->head_seq_num =
1117 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1122 /* put the frame in the reordering buffer */
1123 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1124 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1125 tid_agg_rx->reorder_time[index] = jiffies;
1126 tid_agg_rx->stored_mpdu_num++;
1127 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1131 spin_unlock(&tid_agg_rx->reorder_lock);
1136 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1137 * true if the MPDU was buffered, false if it should be processed.
1139 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1140 struct sk_buff_head *frames)
1142 struct sk_buff *skb = rx->skb;
1143 struct ieee80211_local *local = rx->local;
1144 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1145 struct sta_info *sta = rx->sta;
1146 struct tid_ampdu_rx *tid_agg_rx;
1150 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1151 is_multicast_ether_addr(hdr->addr1))
1155 * filter the QoS data rx stream according to
1156 * STA/TID and check if this STA/TID is on aggregation
1162 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1163 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1164 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1166 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1168 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1169 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1170 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1171 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1172 WLAN_BACK_RECIPIENT,
1173 WLAN_REASON_QSTA_REQUIRE_SETUP);
1177 /* qos null data frames are excluded */
1178 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1181 /* not part of a BA session */
1182 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
1185 /* new, potentially un-ordered, ampdu frame - process it */
1187 /* reset session timer */
1188 if (tid_agg_rx->timeout)
1189 tid_agg_rx->last_rx = jiffies;
1191 /* if this mpdu is fragmented - terminate rx aggregation session */
1192 sc = le16_to_cpu(hdr->seq_ctrl);
1193 if (sc & IEEE80211_SCTL_FRAG) {
1194 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
1195 skb_queue_tail(&rx->sdata->skb_queue, skb);
1196 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1201 * No locking needed -- we will only ever process one
1202 * RX packet at a time, and thus own tid_agg_rx. All
1203 * other code manipulating it needs to (and does) make
1204 * sure that we cannot get to it any more before doing
1207 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1212 __skb_queue_tail(frames, skb);
1215 static ieee80211_rx_result debug_noinline
1216 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1218 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1219 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1221 if (status->flag & RX_FLAG_DUP_VALIDATED)
1225 * Drop duplicate 802.11 retransmissions
1226 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1229 if (rx->skb->len < 24)
1232 if (ieee80211_is_ctl(hdr->frame_control) ||
1233 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1234 is_multicast_ether_addr(hdr->addr1))
1240 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1241 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1242 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1243 rx->sta->rx_stats.num_duplicates++;
1244 return RX_DROP_UNUSABLE;
1245 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1246 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1252 static ieee80211_rx_result debug_noinline
1253 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1255 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1257 /* Drop disallowed frame classes based on STA auth/assoc state;
1258 * IEEE 802.11, Chap 5.5.
1260 * mac80211 filters only based on association state, i.e. it drops
1261 * Class 3 frames from not associated stations. hostapd sends
1262 * deauth/disassoc frames when needed. In addition, hostapd is
1263 * responsible for filtering on both auth and assoc states.
1266 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1267 return ieee80211_rx_mesh_check(rx);
1269 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1270 ieee80211_is_pspoll(hdr->frame_control)) &&
1271 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1272 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1273 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1274 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1276 * accept port control frames from the AP even when it's not
1277 * yet marked ASSOC to prevent a race where we don't set the
1278 * assoc bit quickly enough before it sends the first frame
1280 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1281 ieee80211_is_data_present(hdr->frame_control)) {
1282 unsigned int hdrlen;
1285 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1287 if (rx->skb->len < hdrlen + 8)
1288 return RX_DROP_MONITOR;
1290 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1291 if (ethertype == rx->sdata->control_port_protocol)
1295 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1296 cfg80211_rx_spurious_frame(rx->sdata->dev,
1299 return RX_DROP_UNUSABLE;
1301 return RX_DROP_MONITOR;
1308 static ieee80211_rx_result debug_noinline
1309 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1311 struct ieee80211_local *local;
1312 struct ieee80211_hdr *hdr;
1313 struct sk_buff *skb;
1317 hdr = (struct ieee80211_hdr *) skb->data;
1319 if (!local->pspolling)
1322 if (!ieee80211_has_fromds(hdr->frame_control))
1323 /* this is not from AP */
1326 if (!ieee80211_is_data(hdr->frame_control))
1329 if (!ieee80211_has_moredata(hdr->frame_control)) {
1330 /* AP has no more frames buffered for us */
1331 local->pspolling = false;
1335 /* more data bit is set, let's request a new frame from the AP */
1336 ieee80211_send_pspoll(local, rx->sdata);
1341 static void sta_ps_start(struct sta_info *sta)
1343 struct ieee80211_sub_if_data *sdata = sta->sdata;
1344 struct ieee80211_local *local = sdata->local;
1348 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1349 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1350 ps = &sdata->bss->ps;
1354 atomic_inc(&ps->num_sta_ps);
1355 set_sta_flag(sta, WLAN_STA_PS_STA);
1356 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1357 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1358 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1359 sta->sta.addr, sta->sta.aid);
1361 ieee80211_clear_fast_xmit(sta);
1363 if (!sta->sta.txq[0])
1366 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1367 if (txq_has_queue(sta->sta.txq[tid]))
1368 set_bit(tid, &sta->txq_buffered_tids);
1370 clear_bit(tid, &sta->txq_buffered_tids);
1374 static void sta_ps_end(struct sta_info *sta)
1376 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1377 sta->sta.addr, sta->sta.aid);
1379 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1381 * Clear the flag only if the other one is still set
1382 * so that the TX path won't start TX'ing new frames
1383 * directly ... In the case that the driver flag isn't
1384 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1386 clear_sta_flag(sta, WLAN_STA_PS_STA);
1387 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1388 sta->sta.addr, sta->sta.aid);
1392 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1393 clear_sta_flag(sta, WLAN_STA_PS_STA);
1394 ieee80211_sta_ps_deliver_wakeup(sta);
1397 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1399 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1402 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1404 /* Don't let the same PS state be set twice */
1405 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1406 if ((start && in_ps) || (!start && !in_ps))
1416 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1418 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1420 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1422 if (test_sta_flag(sta, WLAN_STA_SP))
1425 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1426 ieee80211_sta_ps_deliver_poll_response(sta);
1428 set_sta_flag(sta, WLAN_STA_PSPOLL);
1430 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1432 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1434 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1435 u8 ac = ieee802_1d_to_ac[tid & 7];
1438 * If this AC is not trigger-enabled do nothing.
1440 * NB: This could/should check a separate bitmap of trigger-
1441 * enabled queues, but for now we only implement uAPSD w/o
1442 * TSPEC changes to the ACs, so they're always the same.
1444 if (!(sta->sta.uapsd_queues & BIT(ac)))
1447 /* if we are in a service period, do nothing */
1448 if (test_sta_flag(sta, WLAN_STA_SP))
1451 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1452 ieee80211_sta_ps_deliver_uapsd(sta);
1454 set_sta_flag(sta, WLAN_STA_UAPSD);
1456 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1458 static ieee80211_rx_result debug_noinline
1459 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1461 struct ieee80211_sub_if_data *sdata = rx->sdata;
1462 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1463 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1468 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1469 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1473 * The device handles station powersave, so don't do anything about
1474 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1475 * it to mac80211 since they're handled.)
1477 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1481 * Don't do anything if the station isn't already asleep. In
1482 * the uAPSD case, the station will probably be marked asleep,
1483 * in the PS-Poll case the station must be confused ...
1485 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1488 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1489 ieee80211_sta_pspoll(&rx->sta->sta);
1491 /* Free PS Poll skb here instead of returning RX_DROP that would
1492 * count as an dropped frame. */
1493 dev_kfree_skb(rx->skb);
1496 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1497 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1498 ieee80211_has_pm(hdr->frame_control) &&
1499 (ieee80211_is_data_qos(hdr->frame_control) ||
1500 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1503 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1505 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1511 static ieee80211_rx_result debug_noinline
1512 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1514 struct sta_info *sta = rx->sta;
1515 struct sk_buff *skb = rx->skb;
1516 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1517 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1524 * Update last_rx only for IBSS packets which are for the current
1525 * BSSID and for station already AUTHORIZED to avoid keeping the
1526 * current IBSS network alive in cases where other STAs start
1527 * using different BSSID. This will also give the station another
1528 * chance to restart the authentication/authorization in case
1529 * something went wrong the first time.
1531 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1532 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1533 NL80211_IFTYPE_ADHOC);
1534 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1535 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1536 sta->rx_stats.last_rx = jiffies;
1537 if (ieee80211_is_data(hdr->frame_control) &&
1538 !is_multicast_ether_addr(hdr->addr1))
1539 sta->rx_stats.last_rate =
1540 sta_stats_encode_rate(status);
1542 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1543 sta->rx_stats.last_rx = jiffies;
1544 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1546 * Mesh beacons will update last_rx when if they are found to
1547 * match the current local configuration when processed.
1549 sta->rx_stats.last_rx = jiffies;
1550 if (ieee80211_is_data(hdr->frame_control))
1551 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1554 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1555 ieee80211_sta_rx_notify(rx->sdata, hdr);
1557 sta->rx_stats.fragments++;
1559 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1560 sta->rx_stats.bytes += rx->skb->len;
1561 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1563 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1564 sta->rx_stats.last_signal = status->signal;
1565 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1568 if (status->chains) {
1569 sta->rx_stats.chains = status->chains;
1570 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1571 int signal = status->chain_signal[i];
1573 if (!(status->chains & BIT(i)))
1576 sta->rx_stats.chain_signal_last[i] = signal;
1577 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1583 * Change STA power saving mode only at the end of a frame
1584 * exchange sequence.
1586 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1587 !ieee80211_has_morefrags(hdr->frame_control) &&
1588 !ieee80211_is_back_req(hdr->frame_control) &&
1589 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1590 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1591 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1593 * PM bit is only checked in frames where it isn't reserved,
1594 * in AP mode it's reserved in non-bufferable management frames
1595 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1596 * BAR frames should be ignored as specified in
1597 * IEEE 802.11-2012 10.2.1.2.
1599 (!ieee80211_is_mgmt(hdr->frame_control) ||
1600 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
1601 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1602 if (!ieee80211_has_pm(hdr->frame_control))
1605 if (ieee80211_has_pm(hdr->frame_control))
1610 /* mesh power save support */
1611 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1612 ieee80211_mps_rx_h_sta_process(sta, hdr);
1615 * Drop (qos-)data::nullfunc frames silently, since they
1616 * are used only to control station power saving mode.
1618 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1619 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1622 * If we receive a 4-addr nullfunc frame from a STA
1623 * that was not moved to a 4-addr STA vlan yet send
1624 * the event to userspace and for older hostapd drop
1625 * the frame to the monitor interface.
1627 if (ieee80211_has_a4(hdr->frame_control) &&
1628 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1629 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1630 !rx->sdata->u.vlan.sta))) {
1631 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1632 cfg80211_rx_unexpected_4addr_frame(
1633 rx->sdata->dev, sta->sta.addr,
1635 return RX_DROP_MONITOR;
1638 * Update counter and free packet here to avoid
1639 * counting this as a dropped packed.
1641 sta->rx_stats.packets++;
1642 dev_kfree_skb(rx->skb);
1647 } /* ieee80211_rx_h_sta_process */
1649 static ieee80211_rx_result debug_noinline
1650 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1652 struct sk_buff *skb = rx->skb;
1653 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1654 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1657 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1658 struct ieee80211_key *sta_ptk = NULL;
1659 int mmie_keyidx = -1;
1661 const struct ieee80211_cipher_scheme *cs = NULL;
1666 * There are four types of keys:
1667 * - GTK (group keys)
1668 * - IGTK (group keys for management frames)
1669 * - PTK (pairwise keys)
1670 * - STK (station-to-station pairwise keys)
1672 * When selecting a key, we have to distinguish between multicast
1673 * (including broadcast) and unicast frames, the latter can only
1674 * use PTKs and STKs while the former always use GTKs and IGTKs.
1675 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1676 * unicast frames can also use key indices like GTKs. Hence, if we
1677 * don't have a PTK/STK we check the key index for a WEP key.
1679 * Note that in a regular BSS, multicast frames are sent by the
1680 * AP only, associated stations unicast the frame to the AP first
1681 * which then multicasts it on their behalf.
1683 * There is also a slight problem in IBSS mode: GTKs are negotiated
1684 * with each station, that is something we don't currently handle.
1685 * The spec seems to expect that one negotiates the same key with
1686 * every station but there's no such requirement; VLANs could be
1690 /* start without a key */
1692 fc = hdr->frame_control;
1695 int keyid = rx->sta->ptk_idx;
1697 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1698 cs = rx->sta->cipher_scheme;
1699 keyid = ieee80211_get_cs_keyid(cs, rx->skb);
1700 if (unlikely(keyid < 0))
1701 return RX_DROP_UNUSABLE;
1703 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1706 if (!ieee80211_has_protected(fc))
1707 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1709 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1711 if ((status->flag & RX_FLAG_DECRYPTED) &&
1712 (status->flag & RX_FLAG_IV_STRIPPED))
1714 /* Skip decryption if the frame is not protected. */
1715 if (!ieee80211_has_protected(fc))
1717 } else if (mmie_keyidx >= 0) {
1718 /* Broadcast/multicast robust management frame / BIP */
1719 if ((status->flag & RX_FLAG_DECRYPTED) &&
1720 (status->flag & RX_FLAG_IV_STRIPPED))
1723 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1724 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1725 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1727 if (ieee80211_is_group_privacy_action(skb) &&
1728 test_sta_flag(rx->sta, WLAN_STA_MFP))
1729 return RX_DROP_MONITOR;
1731 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1734 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1735 } else if (!ieee80211_has_protected(fc)) {
1737 * The frame was not protected, so skip decryption. However, we
1738 * need to set rx->key if there is a key that could have been
1739 * used so that the frame may be dropped if encryption would
1740 * have been expected.
1742 struct ieee80211_key *key = NULL;
1743 struct ieee80211_sub_if_data *sdata = rx->sdata;
1746 if (ieee80211_is_mgmt(fc) &&
1747 is_multicast_ether_addr(hdr->addr1) &&
1748 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1752 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1753 key = rcu_dereference(rx->sta->gtk[i]);
1759 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1760 key = rcu_dereference(sdata->keys[i]);
1773 * The device doesn't give us the IV so we won't be
1774 * able to look up the key. That's ok though, we
1775 * don't need to decrypt the frame, we just won't
1776 * be able to keep statistics accurate.
1777 * Except for key threshold notifications, should
1778 * we somehow allow the driver to tell us which key
1779 * the hardware used if this flag is set?
1781 if ((status->flag & RX_FLAG_DECRYPTED) &&
1782 (status->flag & RX_FLAG_IV_STRIPPED))
1785 hdrlen = ieee80211_hdrlen(fc);
1788 keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
1790 if (unlikely(keyidx < 0))
1791 return RX_DROP_UNUSABLE;
1793 if (rx->skb->len < 8 + hdrlen)
1794 return RX_DROP_UNUSABLE; /* TODO: count this? */
1796 * no need to call ieee80211_wep_get_keyidx,
1797 * it verifies a bunch of things we've done already
1799 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1800 keyidx = keyid >> 6;
1803 /* check per-station GTK first, if multicast packet */
1804 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1805 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1807 /* if not found, try default key */
1809 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1812 * RSNA-protected unicast frames should always be
1813 * sent with pairwise or station-to-station keys,
1814 * but for WEP we allow using a key index as well.
1817 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1818 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1819 !is_multicast_ether_addr(hdr->addr1))
1825 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1826 return RX_DROP_MONITOR;
1828 /* TODO: add threshold stuff again */
1830 return RX_DROP_MONITOR;
1833 switch (rx->key->conf.cipher) {
1834 case WLAN_CIPHER_SUITE_WEP40:
1835 case WLAN_CIPHER_SUITE_WEP104:
1836 result = ieee80211_crypto_wep_decrypt(rx);
1838 case WLAN_CIPHER_SUITE_TKIP:
1839 result = ieee80211_crypto_tkip_decrypt(rx);
1841 case WLAN_CIPHER_SUITE_CCMP:
1842 result = ieee80211_crypto_ccmp_decrypt(
1843 rx, IEEE80211_CCMP_MIC_LEN);
1845 case WLAN_CIPHER_SUITE_CCMP_256:
1846 result = ieee80211_crypto_ccmp_decrypt(
1847 rx, IEEE80211_CCMP_256_MIC_LEN);
1849 case WLAN_CIPHER_SUITE_AES_CMAC:
1850 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1852 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1853 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1855 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1856 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1857 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1859 case WLAN_CIPHER_SUITE_GCMP:
1860 case WLAN_CIPHER_SUITE_GCMP_256:
1861 result = ieee80211_crypto_gcmp_decrypt(rx);
1864 result = ieee80211_crypto_hw_decrypt(rx);
1867 /* the hdr variable is invalid after the decrypt handlers */
1869 /* either the frame has been decrypted or will be dropped */
1870 status->flag |= RX_FLAG_DECRYPTED;
1875 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
1879 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
1880 skb_queue_head_init(&cache->entries[i].skb_list);
1883 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
1887 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
1888 __skb_queue_purge(&cache->entries[i].skb_list);
1891 static inline struct ieee80211_fragment_entry *
1892 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
1893 unsigned int frag, unsigned int seq, int rx_queue,
1894 struct sk_buff **skb)
1896 struct ieee80211_fragment_entry *entry;
1898 entry = &cache->entries[cache->next++];
1899 if (cache->next >= IEEE80211_FRAGMENT_MAX)
1902 __skb_queue_purge(&entry->skb_list);
1904 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1906 entry->first_frag_time = jiffies;
1908 entry->rx_queue = rx_queue;
1909 entry->last_frag = frag;
1910 entry->check_sequential_pn = false;
1911 entry->extra_len = 0;
1916 static inline struct ieee80211_fragment_entry *
1917 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
1918 unsigned int frag, unsigned int seq,
1919 int rx_queue, struct ieee80211_hdr *hdr)
1921 struct ieee80211_fragment_entry *entry;
1925 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1926 struct ieee80211_hdr *f_hdr;
1930 idx = IEEE80211_FRAGMENT_MAX - 1;
1932 entry = &cache->entries[idx];
1933 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1934 entry->rx_queue != rx_queue ||
1935 entry->last_frag + 1 != frag)
1938 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1941 * Check ftype and addresses are equal, else check next fragment
1943 if (((hdr->frame_control ^ f_hdr->frame_control) &
1944 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1945 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1946 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
1949 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1950 __skb_queue_purge(&entry->skb_list);
1959 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
1962 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
1963 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
1964 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
1965 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
1966 ieee80211_has_protected(fc);
1969 static ieee80211_rx_result debug_noinline
1970 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1972 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
1973 struct ieee80211_hdr *hdr;
1976 unsigned int frag, seq;
1977 struct ieee80211_fragment_entry *entry;
1978 struct sk_buff *skb;
1979 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1981 hdr = (struct ieee80211_hdr *)rx->skb->data;
1982 fc = hdr->frame_control;
1984 if (ieee80211_is_ctl(fc))
1987 sc = le16_to_cpu(hdr->seq_ctrl);
1988 frag = sc & IEEE80211_SCTL_FRAG;
1991 cache = &rx->sta->frags;
1993 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
1996 if (is_multicast_ether_addr(hdr->addr1))
1997 return RX_DROP_MONITOR;
1999 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2001 if (skb_linearize(rx->skb))
2002 return RX_DROP_UNUSABLE;
2005 * skb_linearize() might change the skb->data and
2006 * previously cached variables (in this case, hdr) need to
2007 * be refreshed with the new data.
2009 hdr = (struct ieee80211_hdr *)rx->skb->data;
2010 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2013 /* This is the first fragment of a new frame. */
2014 entry = ieee80211_reassemble_add(cache, frag, seq,
2015 rx->seqno_idx, &(rx->skb));
2016 if (requires_sequential_pn(rx, fc)) {
2017 int queue = rx->security_idx;
2019 /* Store CCMP/GCMP PN so that we can verify that the
2020 * next fragment has a sequential PN value.
2022 entry->check_sequential_pn = true;
2023 entry->is_protected = true;
2024 entry->key_color = rx->key->color;
2025 memcpy(entry->last_pn,
2026 rx->key->u.ccmp.rx_pn[queue],
2027 IEEE80211_CCMP_PN_LEN);
2028 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2030 offsetof(struct ieee80211_key,
2032 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2033 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2034 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2035 IEEE80211_GCMP_PN_LEN);
2036 } else if (rx->key &&
2037 (ieee80211_has_protected(fc) ||
2038 (status->flag & RX_FLAG_DECRYPTED))) {
2039 entry->is_protected = true;
2040 entry->key_color = rx->key->color;
2045 /* This is a fragment for a frame that should already be pending in
2046 * fragment cache. Add this fragment to the end of the pending entry.
2048 entry = ieee80211_reassemble_find(cache, frag, seq,
2049 rx->seqno_idx, hdr);
2051 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2052 return RX_DROP_MONITOR;
2055 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2056 * MPDU PN values are not incrementing in steps of 1."
2057 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2058 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2060 if (entry->check_sequential_pn) {
2062 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2064 if (!requires_sequential_pn(rx, fc))
2065 return RX_DROP_UNUSABLE;
2067 /* Prevent mixed key and fragment cache attacks */
2068 if (entry->key_color != rx->key->color)
2069 return RX_DROP_UNUSABLE;
2071 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2072 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2078 rpn = rx->ccm_gcm.pn;
2079 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2080 return RX_DROP_UNUSABLE;
2081 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2082 } else if (entry->is_protected &&
2084 (!ieee80211_has_protected(fc) &&
2085 !(status->flag & RX_FLAG_DECRYPTED)) ||
2086 rx->key->color != entry->key_color)) {
2087 /* Drop this as a mixed key or fragment cache attack, even
2088 * if for TKIP Michael MIC should protect us, and WEP is a
2089 * lost cause anyway.
2091 return RX_DROP_UNUSABLE;
2092 } else if (entry->is_protected && rx->key &&
2093 entry->key_color != rx->key->color &&
2094 (status->flag & RX_FLAG_DECRYPTED)) {
2095 return RX_DROP_UNUSABLE;
2098 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2099 __skb_queue_tail(&entry->skb_list, rx->skb);
2100 entry->last_frag = frag;
2101 entry->extra_len += rx->skb->len;
2102 if (ieee80211_has_morefrags(fc)) {
2107 rx->skb = __skb_dequeue(&entry->skb_list);
2108 if (skb_tailroom(rx->skb) < entry->extra_len) {
2109 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2110 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2112 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2113 __skb_queue_purge(&entry->skb_list);
2114 return RX_DROP_UNUSABLE;
2117 while ((skb = __skb_dequeue(&entry->skb_list))) {
2118 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
2122 /* Complete frame has been reassembled - process it now */
2123 status = IEEE80211_SKB_RXCB(rx->skb);
2126 ieee80211_led_rx(rx->local);
2128 rx->sta->rx_stats.packets++;
2132 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2134 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2140 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2142 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
2143 struct sk_buff *skb = rx->skb;
2144 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2147 * Pass through unencrypted frames if the hardware has
2148 * decrypted them already.
2150 if (status->flag & RX_FLAG_DECRYPTED)
2153 /* check mesh EAPOL frames first */
2154 if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
2155 ieee80211_is_data(fc))) {
2156 struct ieee80211s_hdr *mesh_hdr;
2157 u16 hdr_len = ieee80211_hdrlen(fc);
2158 u16 ethertype_offset;
2161 if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
2164 /* make sure fixed part of mesh header is there, also checks skb len */
2165 if (!pskb_may_pull(rx->skb, hdr_len + 6))
2168 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
2169 ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
2170 sizeof(rfc1042_header);
2172 if (skb_copy_bits(rx->skb, ethertype_offset, ðertype, 2) == 0 &&
2173 ethertype == rx->sdata->control_port_protocol)
2178 /* Drop unencrypted frames if key is set. */
2179 if (unlikely(!ieee80211_has_protected(fc) &&
2180 !ieee80211_is_any_nullfunc(fc) &&
2181 ieee80211_is_data(fc) && rx->key))
2187 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2189 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2190 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2191 __le16 fc = hdr->frame_control;
2194 * Pass through unencrypted frames if the hardware has
2195 * decrypted them already.
2197 if (status->flag & RX_FLAG_DECRYPTED)
2200 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2201 if (unlikely(!ieee80211_has_protected(fc) &&
2202 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2204 if (ieee80211_is_deauth(fc) ||
2205 ieee80211_is_disassoc(fc))
2206 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2211 /* BIP does not use Protected field, so need to check MMIE */
2212 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2213 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2214 if (ieee80211_is_deauth(fc) ||
2215 ieee80211_is_disassoc(fc))
2216 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2222 * When using MFP, Action frames are not allowed prior to
2223 * having configured keys.
2225 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2226 ieee80211_is_robust_mgmt_frame(rx->skb)))
2234 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2236 struct ieee80211_sub_if_data *sdata = rx->sdata;
2237 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2238 bool check_port_control = false;
2239 struct ethhdr *ehdr;
2242 *port_control = false;
2243 if (ieee80211_has_a4(hdr->frame_control) &&
2244 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2247 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2248 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2250 if (!sdata->u.mgd.use_4addr)
2253 check_port_control = true;
2256 if (is_multicast_ether_addr(hdr->addr1) &&
2257 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2260 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2264 ehdr = (struct ethhdr *) rx->skb->data;
2265 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2266 *port_control = true;
2267 else if (check_port_control)
2274 * requires that rx->skb is a frame with ethernet header
2276 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2278 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2279 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2280 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2283 * Allow EAPOL frames to us/the PAE group address regardless of
2284 * whether the frame was encrypted or not, and always disallow
2285 * all other destination addresses for them.
2287 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2288 return ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2289 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2291 if (ieee80211_802_1x_port_control(rx) ||
2292 ieee80211_drop_unencrypted(rx, fc))
2299 * requires that rx->skb is a frame with ethernet header
2302 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2304 struct ieee80211_sub_if_data *sdata = rx->sdata;
2305 struct net_device *dev = sdata->dev;
2306 struct sk_buff *skb, *xmit_skb;
2307 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2308 struct sta_info *dsta;
2313 ieee80211_rx_stats(dev, skb->len);
2316 /* The seqno index has the same property as needed
2317 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2318 * for non-QoS-data frames. Here we know it's a data
2319 * frame, so count MSDUs.
2321 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
2322 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2323 u64_stats_update_end(&rx->sta->rx_stats.syncp);
2326 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2327 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2328 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2329 ehdr->h_proto != rx->sdata->control_port_protocol &&
2330 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2331 if (is_multicast_ether_addr(ehdr->h_dest)) {
2333 * send multicast frames both to higher layers in
2334 * local net stack and back to the wireless medium
2336 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2338 net_info_ratelimited("%s: failed to clone multicast frame\n",
2341 dsta = sta_info_get(sdata, skb->data);
2344 * The destination station is associated to
2345 * this AP (in this VLAN), so send the frame
2346 * directly to it and do not pass it to local
2355 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2357 /* 'align' will only take the values 0 or 2 here since all
2358 * frames are required to be aligned to 2-byte boundaries
2359 * when being passed to mac80211; the code here works just
2360 * as well if that isn't true, but mac80211 assumes it can
2361 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2365 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2367 if (WARN_ON(skb_headroom(skb) < 3)) {
2371 u8 *data = skb->data;
2372 size_t len = skb_headlen(skb);
2374 memmove(skb->data, data, len);
2375 skb_set_tail_pointer(skb, len);
2382 struct ethhdr *ehdr = (struct ethhdr *)skb->data;
2384 /* deliver to local stack */
2385 skb->protocol = eth_type_trans(skb, dev);
2386 memset(skb->cb, 0, sizeof(skb->cb));
2389 * 802.1X over 802.11 requires that the authenticator address
2390 * be used for EAPOL frames. However, 802.1X allows the use of
2391 * the PAE group address instead. If the interface is part of
2392 * a bridge and we pass the frame with the PAE group address,
2393 * then the bridge will forward it to the network (even if the
2394 * client was not associated yet), which isn't supposed to
2396 * To avoid that, rewrite the destination address to our own
2397 * address, so that the authenticator (e.g. hostapd) will see
2398 * the frame, but bridge won't forward it anywhere else. Note
2399 * that due to earlier filtering, the only other address can
2400 * be the PAE group address.
2402 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2403 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2404 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2407 napi_gro_receive(rx->napi, skb);
2409 netif_receive_skb(skb);
2414 * Send to wireless media and increase priority by 256 to
2415 * keep the received priority instead of reclassifying
2416 * the frame (see cfg80211_classify8021d).
2418 xmit_skb->priority += 256;
2419 xmit_skb->protocol = htons(ETH_P_802_3);
2420 skb_reset_network_header(xmit_skb);
2421 skb_reset_mac_header(xmit_skb);
2422 dev_queue_xmit(xmit_skb);
2426 static ieee80211_rx_result debug_noinline
2427 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2429 struct net_device *dev = rx->sdata->dev;
2430 struct sk_buff *skb = rx->skb;
2431 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2432 __le16 fc = hdr->frame_control;
2433 struct sk_buff_head frame_list;
2434 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2435 struct ethhdr ethhdr;
2436 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2438 if (unlikely(!ieee80211_is_data(fc)))
2441 if (unlikely(!ieee80211_is_data_present(fc)))
2442 return RX_DROP_MONITOR;
2444 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2447 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2448 switch (rx->sdata->vif.type) {
2449 case NL80211_IFTYPE_AP_VLAN:
2450 if (!rx->sdata->u.vlan.sta)
2451 return RX_DROP_UNUSABLE;
2453 case NL80211_IFTYPE_STATION:
2454 if (!rx->sdata->u.mgd.use_4addr)
2455 return RX_DROP_UNUSABLE;
2458 return RX_DROP_UNUSABLE;
2462 } else switch (rx->sdata->vif.type) {
2463 case NL80211_IFTYPE_AP:
2464 case NL80211_IFTYPE_AP_VLAN:
2467 case NL80211_IFTYPE_STATION:
2469 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2472 case NL80211_IFTYPE_MESH_POINT:
2479 if (is_multicast_ether_addr(hdr->addr1))
2480 return RX_DROP_UNUSABLE;
2483 __skb_queue_head_init(&frame_list);
2485 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2486 rx->sdata->vif.addr,
2487 rx->sdata->vif.type,
2489 return RX_DROP_UNUSABLE;
2493 * We should not receive A-MSDUs on pre-HT connections,
2494 * and HT connections cannot use old ciphers. Thus drop
2495 * them, as in those cases we couldn't even have SPP
2498 switch (rx->key->conf.cipher) {
2499 case WLAN_CIPHER_SUITE_WEP40:
2500 case WLAN_CIPHER_SUITE_WEP104:
2501 case WLAN_CIPHER_SUITE_TKIP:
2502 return RX_DROP_UNUSABLE;
2508 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2509 rx->sdata->vif.type,
2510 rx->local->hw.extra_tx_headroom,
2511 check_da, check_sa);
2513 while (!skb_queue_empty(&frame_list)) {
2514 rx->skb = __skb_dequeue(&frame_list);
2516 if (!ieee80211_frame_allowed(rx, fc)) {
2517 dev_kfree_skb(rx->skb);
2521 ieee80211_deliver_skb(rx);
2527 #ifdef CONFIG_MAC80211_MESH
2528 static ieee80211_rx_result
2529 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2531 struct ieee80211_hdr *fwd_hdr, *hdr;
2532 struct ieee80211_tx_info *info;
2533 struct ieee80211s_hdr *mesh_hdr;
2534 struct sk_buff *skb = rx->skb, *fwd_skb;
2535 struct ieee80211_local *local = rx->local;
2536 struct ieee80211_sub_if_data *sdata = rx->sdata;
2537 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2540 hdr = (struct ieee80211_hdr *) skb->data;
2541 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2543 /* make sure fixed part of mesh header is there, also checks skb len */
2544 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2545 return RX_DROP_MONITOR;
2547 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2549 /* make sure full mesh header is there, also checks skb len */
2550 if (!pskb_may_pull(rx->skb,
2551 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2552 return RX_DROP_MONITOR;
2554 /* reload pointers */
2555 hdr = (struct ieee80211_hdr *) skb->data;
2556 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2558 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2559 return RX_DROP_MONITOR;
2561 /* frame is in RMC, don't forward */
2562 if (ieee80211_is_data(hdr->frame_control) &&
2563 is_multicast_ether_addr(hdr->addr1) &&
2564 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2565 return RX_DROP_MONITOR;
2567 if (!ieee80211_is_data(hdr->frame_control))
2571 return RX_DROP_MONITOR;
2573 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2574 struct mesh_path *mppath;
2578 if (is_multicast_ether_addr(hdr->addr1)) {
2579 mpp_addr = hdr->addr3;
2580 proxied_addr = mesh_hdr->eaddr1;
2581 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2582 MESH_FLAGS_AE_A5_A6) {
2583 /* has_a4 already checked in ieee80211_rx_mesh_check */
2584 mpp_addr = hdr->addr4;
2585 proxied_addr = mesh_hdr->eaddr2;
2587 return RX_DROP_MONITOR;
2591 mppath = mpp_path_lookup(sdata, proxied_addr);
2593 mpp_path_add(sdata, proxied_addr, mpp_addr);
2595 spin_lock_bh(&mppath->state_lock);
2596 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2597 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2598 mppath->exp_time = jiffies;
2599 spin_unlock_bh(&mppath->state_lock);
2604 /* Frame has reached destination. Don't forward */
2605 if (!is_multicast_ether_addr(hdr->addr1) &&
2606 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2609 ac = ieee802_1d_to_ac[skb->priority];
2610 q = sdata->vif.hw_queue[ac];
2611 if (ieee80211_queue_stopped(&local->hw, q)) {
2612 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2613 return RX_DROP_MONITOR;
2615 skb_set_queue_mapping(skb, ac);
2617 if (!--mesh_hdr->ttl) {
2618 if (!is_multicast_ether_addr(hdr->addr1))
2619 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2620 dropped_frames_ttl);
2624 if (!ifmsh->mshcfg.dot11MeshForwarding)
2627 fwd_skb = skb_copy(skb, GFP_ATOMIC);
2629 net_info_ratelimited("%s: failed to clone mesh frame\n",
2634 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2635 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2636 info = IEEE80211_SKB_CB(fwd_skb);
2637 memset(info, 0, sizeof(*info));
2638 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2639 info->control.vif = &rx->sdata->vif;
2640 info->control.jiffies = jiffies;
2641 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2642 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2643 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2644 /* update power mode indication when forwarding */
2645 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2646 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2647 /* mesh power mode flags updated in mesh_nexthop_lookup */
2648 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2650 /* unable to resolve next hop */
2651 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2653 WLAN_REASON_MESH_PATH_NOFORWARD,
2655 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2657 return RX_DROP_MONITOR;
2660 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2661 ieee80211_add_pending_skb(local, fwd_skb);
2663 if (is_multicast_ether_addr(hdr->addr1))
2665 return RX_DROP_MONITOR;
2669 static ieee80211_rx_result debug_noinline
2670 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2672 struct ieee80211_sub_if_data *sdata = rx->sdata;
2673 struct ieee80211_local *local = rx->local;
2674 struct net_device *dev = sdata->dev;
2675 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2676 __le16 fc = hdr->frame_control;
2680 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2683 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2684 return RX_DROP_MONITOR;
2687 * Send unexpected-4addr-frame event to hostapd. For older versions,
2688 * also drop the frame to cooked monitor interfaces.
2690 if (ieee80211_has_a4(hdr->frame_control) &&
2691 sdata->vif.type == NL80211_IFTYPE_AP) {
2693 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2694 cfg80211_rx_unexpected_4addr_frame(
2695 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2696 return RX_DROP_MONITOR;
2699 err = __ieee80211_data_to_8023(rx, &port_control);
2701 return RX_DROP_UNUSABLE;
2703 if (!ieee80211_frame_allowed(rx, fc))
2704 return RX_DROP_MONITOR;
2706 /* directly handle TDLS channel switch requests/responses */
2707 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2708 cpu_to_be16(ETH_P_TDLS))) {
2709 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2711 if (pskb_may_pull(rx->skb,
2712 offsetof(struct ieee80211_tdls_data, u)) &&
2713 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2714 tf->category == WLAN_CATEGORY_TDLS &&
2715 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2716 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2717 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2718 schedule_work(&local->tdls_chsw_work);
2720 rx->sta->rx_stats.packets++;
2726 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2727 unlikely(port_control) && sdata->bss) {
2728 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2736 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2737 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2738 !is_multicast_ether_addr(
2739 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2740 (!local->scanning &&
2741 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
2742 mod_timer(&local->dynamic_ps_timer, jiffies +
2743 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2745 ieee80211_deliver_skb(rx);
2750 static ieee80211_rx_result debug_noinline
2751 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2753 struct sk_buff *skb = rx->skb;
2754 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2755 struct tid_ampdu_rx *tid_agg_rx;
2759 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2762 if (ieee80211_is_back_req(bar->frame_control)) {
2764 __le16 control, start_seq_num;
2765 } __packed bar_data;
2766 struct ieee80211_event event = {
2767 .type = BAR_RX_EVENT,
2771 return RX_DROP_MONITOR;
2773 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2774 &bar_data, sizeof(bar_data)))
2775 return RX_DROP_MONITOR;
2777 tid = le16_to_cpu(bar_data.control) >> 12;
2779 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
2780 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
2781 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
2782 WLAN_BACK_RECIPIENT,
2783 WLAN_REASON_QSTA_REQUIRE_SETUP);
2785 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2787 return RX_DROP_MONITOR;
2789 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2790 event.u.ba.tid = tid;
2791 event.u.ba.ssn = start_seq_num;
2792 event.u.ba.sta = &rx->sta->sta;
2794 /* reset session timer */
2795 if (tid_agg_rx->timeout)
2796 mod_timer(&tid_agg_rx->session_timer,
2797 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2799 spin_lock(&tid_agg_rx->reorder_lock);
2800 /* release stored frames up to start of BAR */
2801 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2802 start_seq_num, frames);
2803 spin_unlock(&tid_agg_rx->reorder_lock);
2805 drv_event_callback(rx->local, rx->sdata, &event);
2812 * After this point, we only want management frames,
2813 * so we can drop all remaining control frames to
2814 * cooked monitor interfaces.
2816 return RX_DROP_MONITOR;
2819 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2820 struct ieee80211_mgmt *mgmt,
2823 struct ieee80211_local *local = sdata->local;
2824 struct sk_buff *skb;
2825 struct ieee80211_mgmt *resp;
2827 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2828 /* Not to own unicast address */
2832 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2833 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2834 /* Not from the current AP or not associated yet. */
2838 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2839 /* Too short SA Query request frame */
2843 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2847 skb_reserve(skb, local->hw.extra_tx_headroom);
2848 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2849 memset(resp, 0, 24);
2850 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2851 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2852 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2853 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2854 IEEE80211_STYPE_ACTION);
2855 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2856 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2857 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2858 memcpy(resp->u.action.u.sa_query.trans_id,
2859 mgmt->u.action.u.sa_query.trans_id,
2860 WLAN_SA_QUERY_TR_ID_LEN);
2862 ieee80211_tx_skb(sdata, skb);
2865 static ieee80211_rx_result debug_noinline
2866 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2868 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2869 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2872 * From here on, look only at management frames.
2873 * Data and control frames are already handled,
2874 * and unknown (reserved) frames are useless.
2876 if (rx->skb->len < 24)
2877 return RX_DROP_MONITOR;
2879 if (!ieee80211_is_mgmt(mgmt->frame_control))
2880 return RX_DROP_MONITOR;
2882 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2883 ieee80211_is_beacon(mgmt->frame_control) &&
2884 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2887 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
2888 sig = status->signal;
2890 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2891 rx->skb->data, rx->skb->len,
2893 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2896 if (ieee80211_drop_unencrypted_mgmt(rx))
2897 return RX_DROP_UNUSABLE;
2902 static ieee80211_rx_result debug_noinline
2903 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2905 struct ieee80211_local *local = rx->local;
2906 struct ieee80211_sub_if_data *sdata = rx->sdata;
2907 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2908 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2909 int len = rx->skb->len;
2911 if (!ieee80211_is_action(mgmt->frame_control))
2914 /* drop too small frames */
2915 if (len < IEEE80211_MIN_ACTION_SIZE)
2916 return RX_DROP_UNUSABLE;
2918 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
2919 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2920 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
2921 return RX_DROP_UNUSABLE;
2923 switch (mgmt->u.action.category) {
2924 case WLAN_CATEGORY_HT:
2925 /* reject HT action frames from stations not supporting HT */
2926 if (!rx->sta->sta.ht_cap.ht_supported)
2929 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2930 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2931 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2932 sdata->vif.type != NL80211_IFTYPE_AP &&
2933 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2936 /* verify action & smps_control/chanwidth are present */
2937 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2940 switch (mgmt->u.action.u.ht_smps.action) {
2941 case WLAN_HT_ACTION_SMPS: {
2942 struct ieee80211_supported_band *sband;
2943 enum ieee80211_smps_mode smps_mode;
2945 /* convert to HT capability */
2946 switch (mgmt->u.action.u.ht_smps.smps_control) {
2947 case WLAN_HT_SMPS_CONTROL_DISABLED:
2948 smps_mode = IEEE80211_SMPS_OFF;
2950 case WLAN_HT_SMPS_CONTROL_STATIC:
2951 smps_mode = IEEE80211_SMPS_STATIC;
2953 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
2954 smps_mode = IEEE80211_SMPS_DYNAMIC;
2960 /* if no change do nothing */
2961 if (rx->sta->sta.smps_mode == smps_mode)
2963 rx->sta->sta.smps_mode = smps_mode;
2965 sband = rx->local->hw.wiphy->bands[status->band];
2967 rate_control_rate_update(local, sband, rx->sta,
2968 IEEE80211_RC_SMPS_CHANGED);
2971 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2972 struct ieee80211_supported_band *sband;
2973 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
2974 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
2976 /* If it doesn't support 40 MHz it can't change ... */
2977 if (!(rx->sta->sta.ht_cap.cap &
2978 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
2981 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
2982 max_bw = IEEE80211_STA_RX_BW_20;
2984 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
2986 /* set cur_max_bandwidth and recalc sta bw */
2987 rx->sta->cur_max_bandwidth = max_bw;
2988 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
2990 if (rx->sta->sta.bandwidth == new_bw)
2993 rx->sta->sta.bandwidth = new_bw;
2994 sband = rx->local->hw.wiphy->bands[status->band];
2996 rate_control_rate_update(local, sband, rx->sta,
2997 IEEE80211_RC_BW_CHANGED);
3005 case WLAN_CATEGORY_PUBLIC:
3006 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3008 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3012 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3014 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3015 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3017 if (len < offsetof(struct ieee80211_mgmt,
3018 u.action.u.ext_chan_switch.variable))
3021 case WLAN_CATEGORY_VHT:
3022 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3023 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3024 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3025 sdata->vif.type != NL80211_IFTYPE_AP &&
3026 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3029 /* verify action code is present */
3030 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3033 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3034 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3035 /* verify opmode is present */
3036 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3040 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3041 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3049 case WLAN_CATEGORY_BACK:
3050 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3051 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3052 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3053 sdata->vif.type != NL80211_IFTYPE_AP &&
3054 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3057 /* verify action_code is present */
3058 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3061 switch (mgmt->u.action.u.addba_req.action_code) {
3062 case WLAN_ACTION_ADDBA_REQ:
3063 if (len < (IEEE80211_MIN_ACTION_SIZE +
3064 sizeof(mgmt->u.action.u.addba_req)))
3067 case WLAN_ACTION_ADDBA_RESP:
3068 if (len < (IEEE80211_MIN_ACTION_SIZE +
3069 sizeof(mgmt->u.action.u.addba_resp)))
3072 case WLAN_ACTION_DELBA:
3073 if (len < (IEEE80211_MIN_ACTION_SIZE +
3074 sizeof(mgmt->u.action.u.delba)))
3082 case WLAN_CATEGORY_SPECTRUM_MGMT:
3083 /* verify action_code is present */
3084 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3087 switch (mgmt->u.action.u.measurement.action_code) {
3088 case WLAN_ACTION_SPCT_MSR_REQ:
3089 if (status->band != NL80211_BAND_5GHZ)
3092 if (len < (IEEE80211_MIN_ACTION_SIZE +
3093 sizeof(mgmt->u.action.u.measurement)))
3096 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3099 ieee80211_process_measurement_req(sdata, mgmt, len);
3101 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3103 if (len < (IEEE80211_MIN_ACTION_SIZE +
3104 sizeof(mgmt->u.action.u.chan_switch)))
3107 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3108 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3109 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3112 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3113 bssid = sdata->u.mgd.bssid;
3114 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3115 bssid = sdata->u.ibss.bssid;
3116 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3121 if (!ether_addr_equal(mgmt->bssid, bssid))
3128 case WLAN_CATEGORY_SA_QUERY:
3129 if (len < (IEEE80211_MIN_ACTION_SIZE +
3130 sizeof(mgmt->u.action.u.sa_query)))
3133 switch (mgmt->u.action.u.sa_query.action) {
3134 case WLAN_ACTION_SA_QUERY_REQUEST:
3135 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3137 ieee80211_process_sa_query_req(sdata, mgmt, len);
3141 case WLAN_CATEGORY_SELF_PROTECTED:
3142 if (len < (IEEE80211_MIN_ACTION_SIZE +
3143 sizeof(mgmt->u.action.u.self_prot.action_code)))
3146 switch (mgmt->u.action.u.self_prot.action_code) {
3147 case WLAN_SP_MESH_PEERING_OPEN:
3148 case WLAN_SP_MESH_PEERING_CLOSE:
3149 case WLAN_SP_MESH_PEERING_CONFIRM:
3150 if (!ieee80211_vif_is_mesh(&sdata->vif))
3152 if (sdata->u.mesh.user_mpm)
3153 /* userspace handles this frame */
3156 case WLAN_SP_MGK_INFORM:
3157 case WLAN_SP_MGK_ACK:
3158 if (!ieee80211_vif_is_mesh(&sdata->vif))
3163 case WLAN_CATEGORY_MESH_ACTION:
3164 if (len < (IEEE80211_MIN_ACTION_SIZE +
3165 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3168 if (!ieee80211_vif_is_mesh(&sdata->vif))
3170 if (mesh_action_is_path_sel(mgmt) &&
3171 !mesh_path_sel_is_hwmp(sdata))
3179 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3180 /* will return in the next handlers */
3185 rx->sta->rx_stats.packets++;
3186 dev_kfree_skb(rx->skb);
3190 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
3191 skb_queue_tail(&sdata->skb_queue, rx->skb);
3192 ieee80211_queue_work(&local->hw, &sdata->work);
3194 rx->sta->rx_stats.packets++;
3198 static ieee80211_rx_result debug_noinline
3199 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3201 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3204 /* skip known-bad action frames and return them in the next handler */
3205 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3209 * Getting here means the kernel doesn't know how to handle
3210 * it, but maybe userspace does ... include returned frames
3211 * so userspace can register for those to know whether ones
3212 * it transmitted were processed or returned.
3215 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
3216 sig = status->signal;
3218 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
3219 rx->skb->data, rx->skb->len, 0)) {
3221 rx->sta->rx_stats.packets++;
3222 dev_kfree_skb(rx->skb);
3229 static ieee80211_rx_result debug_noinline
3230 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3232 struct ieee80211_local *local = rx->local;
3233 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3234 struct sk_buff *nskb;
3235 struct ieee80211_sub_if_data *sdata = rx->sdata;
3236 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3238 if (!ieee80211_is_action(mgmt->frame_control))
3242 * For AP mode, hostapd is responsible for handling any action
3243 * frames that we didn't handle, including returning unknown
3244 * ones. For all other modes we will return them to the sender,
3245 * setting the 0x80 bit in the action category, as required by
3246 * 802.11-2012 9.24.4.
3247 * Newer versions of hostapd shall also use the management frame
3248 * registration mechanisms, but older ones still use cooked
3249 * monitor interfaces so push all frames there.
3251 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3252 (sdata->vif.type == NL80211_IFTYPE_AP ||
3253 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3254 return RX_DROP_MONITOR;
3256 if (is_multicast_ether_addr(mgmt->da))
3257 return RX_DROP_MONITOR;
3259 /* do not return rejected action frames */
3260 if (mgmt->u.action.category & 0x80)
3261 return RX_DROP_UNUSABLE;
3263 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3266 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3268 nmgmt->u.action.category |= 0x80;
3269 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3270 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3272 memset(nskb->cb, 0, sizeof(nskb->cb));
3274 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3275 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3277 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3278 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3279 IEEE80211_TX_CTL_NO_CCK_RATE;
3280 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3282 local->hw.offchannel_tx_hw_queue;
3285 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3288 dev_kfree_skb(rx->skb);
3292 static ieee80211_rx_result debug_noinline
3293 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3295 struct ieee80211_sub_if_data *sdata = rx->sdata;
3296 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3299 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3301 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3302 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3303 sdata->vif.type != NL80211_IFTYPE_OCB &&
3304 sdata->vif.type != NL80211_IFTYPE_STATION)
3305 return RX_DROP_MONITOR;
3308 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3309 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3310 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3311 /* process for all: mesh, mlme, ibss */
3313 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3314 if (is_multicast_ether_addr(mgmt->da) &&
3315 !is_broadcast_ether_addr(mgmt->da))
3316 return RX_DROP_MONITOR;
3318 /* process only for station/IBSS */
3319 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3320 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3321 return RX_DROP_MONITOR;
3323 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3324 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3325 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3326 if (is_multicast_ether_addr(mgmt->da) &&
3327 !is_broadcast_ether_addr(mgmt->da))
3328 return RX_DROP_MONITOR;
3330 /* process only for station */
3331 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3332 return RX_DROP_MONITOR;
3334 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3335 /* process only for ibss and mesh */
3336 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3337 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3338 return RX_DROP_MONITOR;
3341 return RX_DROP_MONITOR;
3344 /* queue up frame and kick off work to process it */
3345 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
3346 skb_queue_tail(&sdata->skb_queue, rx->skb);
3347 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3349 rx->sta->rx_stats.packets++;
3354 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3355 struct ieee80211_rate *rate)
3357 struct ieee80211_sub_if_data *sdata;
3358 struct ieee80211_local *local = rx->local;
3359 struct sk_buff *skb = rx->skb, *skb2;
3360 struct net_device *prev_dev = NULL;
3361 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3362 int needed_headroom;
3365 * If cooked monitor has been processed already, then
3366 * don't do it again. If not, set the flag.
3368 if (rx->flags & IEEE80211_RX_CMNTR)
3370 rx->flags |= IEEE80211_RX_CMNTR;
3372 /* If there are no cooked monitor interfaces, just free the SKB */
3373 if (!local->cooked_mntrs)
3376 /* vendor data is long removed here */
3377 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3378 /* room for the radiotap header based on driver features */
3379 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3381 if (skb_headroom(skb) < needed_headroom &&
3382 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3385 /* prepend radiotap information */
3386 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3389 skb_reset_mac_header(skb);
3390 skb->ip_summed = CHECKSUM_UNNECESSARY;
3391 skb->pkt_type = PACKET_OTHERHOST;
3392 skb->protocol = htons(ETH_P_802_2);
3394 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3395 if (!ieee80211_sdata_running(sdata))
3398 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3399 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3403 skb2 = skb_clone(skb, GFP_ATOMIC);
3405 skb2->dev = prev_dev;
3406 netif_receive_skb(skb2);
3410 prev_dev = sdata->dev;
3411 ieee80211_rx_stats(sdata->dev, skb->len);
3415 skb->dev = prev_dev;
3416 netif_receive_skb(skb);
3424 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3425 ieee80211_rx_result res)
3428 case RX_DROP_MONITOR:
3429 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3431 rx->sta->rx_stats.dropped++;
3434 struct ieee80211_rate *rate = NULL;
3435 struct ieee80211_supported_band *sband;
3436 struct ieee80211_rx_status *status;
3438 status = IEEE80211_SKB_RXCB((rx->skb));
3440 sband = rx->local->hw.wiphy->bands[status->band];
3441 if (!(status->flag & RX_FLAG_HT) &&
3442 !(status->flag & RX_FLAG_VHT))
3443 rate = &sband->bitrates[status->rate_idx];
3445 ieee80211_rx_cooked_monitor(rx, rate);
3448 case RX_DROP_UNUSABLE:
3449 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3451 rx->sta->rx_stats.dropped++;
3452 dev_kfree_skb(rx->skb);
3455 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3460 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3461 struct sk_buff_head *frames)
3463 ieee80211_rx_result res = RX_DROP_MONITOR;
3464 struct sk_buff *skb;
3466 #define CALL_RXH(rxh) \
3469 if (res != RX_CONTINUE) \
3473 /* Lock here to avoid hitting all of the data used in the RX
3474 * path (e.g. key data, station data, ...) concurrently when
3475 * a frame is released from the reorder buffer due to timeout
3476 * from the timer, potentially concurrently with RX from the
3479 spin_lock_bh(&rx->local->rx_path_lock);
3481 while ((skb = __skb_dequeue(frames))) {
3483 * all the other fields are valid across frames
3484 * that belong to an aMPDU since they are on the
3485 * same TID from the same station
3489 CALL_RXH(ieee80211_rx_h_check_more_data);
3490 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3491 CALL_RXH(ieee80211_rx_h_sta_process);
3492 CALL_RXH(ieee80211_rx_h_decrypt);
3493 CALL_RXH(ieee80211_rx_h_defragment);
3494 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3495 /* must be after MMIC verify so header is counted in MPDU mic */
3496 #ifdef CONFIG_MAC80211_MESH
3497 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3498 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3500 CALL_RXH(ieee80211_rx_h_amsdu);
3501 CALL_RXH(ieee80211_rx_h_data);
3503 /* special treatment -- needs the queue */
3504 res = ieee80211_rx_h_ctrl(rx, frames);
3505 if (res != RX_CONTINUE)
3508 CALL_RXH(ieee80211_rx_h_mgmt_check);
3509 CALL_RXH(ieee80211_rx_h_action);
3510 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3511 CALL_RXH(ieee80211_rx_h_action_return);
3512 CALL_RXH(ieee80211_rx_h_mgmt);
3515 ieee80211_rx_handlers_result(rx, res);
3520 spin_unlock_bh(&rx->local->rx_path_lock);
3523 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3525 struct sk_buff_head reorder_release;
3526 ieee80211_rx_result res = RX_DROP_MONITOR;
3528 __skb_queue_head_init(&reorder_release);
3530 #define CALL_RXH(rxh) \
3533 if (res != RX_CONTINUE) \
3537 CALL_RXH(ieee80211_rx_h_check_dup);
3538 CALL_RXH(ieee80211_rx_h_check);
3540 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3542 ieee80211_rx_handlers(rx, &reorder_release);
3546 ieee80211_rx_handlers_result(rx, res);
3552 * This function makes calls into the RX path, therefore
3553 * it has to be invoked under RCU read lock.
3555 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3557 struct sk_buff_head frames;
3558 struct ieee80211_rx_data rx = {
3560 .sdata = sta->sdata,
3561 .local = sta->local,
3562 /* This is OK -- must be QoS data frame */
3563 .security_idx = tid,
3565 .napi = NULL, /* must be NULL to not have races */
3567 struct tid_ampdu_rx *tid_agg_rx;
3569 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3573 __skb_queue_head_init(&frames);
3575 spin_lock(&tid_agg_rx->reorder_lock);
3576 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3577 spin_unlock(&tid_agg_rx->reorder_lock);
3579 if (!skb_queue_empty(&frames)) {
3580 struct ieee80211_event event = {
3581 .type = BA_FRAME_TIMEOUT,
3583 .u.ba.sta = &sta->sta,
3585 drv_event_callback(rx.local, rx.sdata, &event);
3588 ieee80211_rx_handlers(&rx, &frames);
3591 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3592 u16 ssn, u64 filtered,
3595 struct sta_info *sta;
3596 struct tid_ampdu_rx *tid_agg_rx;
3597 struct sk_buff_head frames;
3598 struct ieee80211_rx_data rx = {
3599 /* This is OK -- must be QoS data frame */
3600 .security_idx = tid,
3605 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3608 __skb_queue_head_init(&frames);
3610 sta = container_of(pubsta, struct sta_info, sta);
3613 rx.sdata = sta->sdata;
3614 rx.local = sta->local;
3617 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3621 spin_lock_bh(&tid_agg_rx->reorder_lock);
3623 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3626 /* release all frames in the reorder buffer */
3627 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3628 IEEE80211_SN_MODULO;
3629 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3631 /* update ssn to match received ssn */
3632 tid_agg_rx->head_seq_num = ssn;
3634 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3638 /* handle the case that received ssn is behind the mac ssn.
3639 * it can be tid_agg_rx->buf_size behind and still be valid */
3640 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3641 if (diff >= tid_agg_rx->buf_size) {
3642 tid_agg_rx->reorder_buf_filtered = 0;
3645 filtered = filtered >> diff;
3649 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3650 int index = (ssn + i) % tid_agg_rx->buf_size;
3652 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3653 if (filtered & BIT_ULL(i))
3654 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3657 /* now process also frames that the filter marking released */
3658 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3661 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3663 ieee80211_rx_handlers(&rx, &frames);
3668 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3670 /* main receive path */
3672 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3674 struct ieee80211_sub_if_data *sdata = rx->sdata;
3675 struct sk_buff *skb = rx->skb;
3676 struct ieee80211_hdr *hdr = (void *)skb->data;
3677 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3678 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3679 int multicast = is_multicast_ether_addr(hdr->addr1);
3681 switch (sdata->vif.type) {
3682 case NL80211_IFTYPE_STATION:
3683 if (!bssid && !sdata->u.mgd.use_4addr)
3685 if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
3689 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3690 case NL80211_IFTYPE_ADHOC:
3693 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3694 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
3695 !is_valid_ether_addr(hdr->addr2))
3697 if (ieee80211_is_beacon(hdr->frame_control))
3699 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3702 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3706 if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
3707 rate_idx = 0; /* TODO: HT/VHT rates */
3709 rate_idx = status->rate_idx;
3710 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3714 case NL80211_IFTYPE_OCB:
3717 if (!ieee80211_is_data_present(hdr->frame_control))
3719 if (!is_broadcast_ether_addr(bssid))
3722 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3726 if (status->flag & RX_FLAG_HT)
3727 rate_idx = 0; /* TODO: HT rates */
3729 rate_idx = status->rate_idx;
3730 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3734 case NL80211_IFTYPE_MESH_POINT:
3735 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
3739 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3740 case NL80211_IFTYPE_AP_VLAN:
3741 case NL80211_IFTYPE_AP:
3743 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3745 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3747 * Accept public action frames even when the
3748 * BSSID doesn't match, this is used for P2P
3749 * and location updates. Note that mac80211
3750 * itself never looks at these frames.
3753 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3755 if (ieee80211_is_public_action(hdr, skb->len))
3757 return ieee80211_is_beacon(hdr->frame_control);
3760 if (!ieee80211_has_tods(hdr->frame_control)) {
3761 /* ignore data frames to TDLS-peers */
3762 if (ieee80211_is_data(hdr->frame_control))
3764 /* ignore action frames to TDLS-peers */
3765 if (ieee80211_is_action(hdr->frame_control) &&
3766 !is_broadcast_ether_addr(bssid) &&
3767 !ether_addr_equal(bssid, hdr->addr1))
3772 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3773 * the BSSID - we've checked that already but may have accepted
3774 * the wildcard (ff:ff:ff:ff:ff:ff).
3777 * The BSSID of the Data frame is determined as follows:
3778 * a) If the STA is contained within an AP or is associated
3779 * with an AP, the BSSID is the address currently in use
3780 * by the STA contained in the AP.
3782 * So we should not accept data frames with an address that's
3785 * Accepting it also opens a security problem because stations
3786 * could encrypt it with the GTK and inject traffic that way.
3788 if (ieee80211_is_data(hdr->frame_control) && multicast)
3792 case NL80211_IFTYPE_WDS:
3793 if (bssid || !ieee80211_is_data(hdr->frame_control))
3795 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3796 case NL80211_IFTYPE_P2P_DEVICE:
3797 return ieee80211_is_public_action(hdr, skb->len) ||
3798 ieee80211_is_probe_req(hdr->frame_control) ||
3799 ieee80211_is_probe_resp(hdr->frame_control) ||
3800 ieee80211_is_beacon(hdr->frame_control);
3801 case NL80211_IFTYPE_NAN:
3802 /* Currently no frames on NAN interface are allowed */
3812 void ieee80211_check_fast_rx(struct sta_info *sta)
3814 struct ieee80211_sub_if_data *sdata = sta->sdata;
3815 struct ieee80211_local *local = sdata->local;
3816 struct ieee80211_key *key;
3817 struct ieee80211_fast_rx fastrx = {
3819 .vif_type = sdata->vif.type,
3820 .control_port_protocol = sdata->control_port_protocol,
3821 }, *old, *new = NULL;
3822 bool assign = false;
3824 /* use sparse to check that we don't return without updating */
3825 __acquire(check_fast_rx);
3827 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
3828 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
3829 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
3830 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
3832 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
3834 /* fast-rx doesn't do reordering */
3835 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
3836 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
3839 switch (sdata->vif.type) {
3840 case NL80211_IFTYPE_STATION:
3841 /* 4-addr is harder to deal with, later maybe */
3842 if (sdata->u.mgd.use_4addr)
3844 /* software powersave is a huge mess, avoid all of it */
3845 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
3847 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3848 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3850 if (sta->sta.tdls) {
3851 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3852 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3853 fastrx.expected_ds_bits = 0;
3855 fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
3856 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3857 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3858 fastrx.expected_ds_bits =
3859 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3862 case NL80211_IFTYPE_AP_VLAN:
3863 case NL80211_IFTYPE_AP:
3864 /* parallel-rx requires this, at least with calls to
3865 * ieee80211_sta_ps_transition()
3867 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
3869 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3870 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3871 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
3873 fastrx.internal_forward =
3874 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
3875 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
3876 !sdata->u.vlan.sta);
3882 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3886 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
3888 key = rcu_dereference(sdata->default_unicast_key);
3890 switch (key->conf.cipher) {
3891 case WLAN_CIPHER_SUITE_TKIP:
3892 /* we don't want to deal with MMIC in fast-rx */
3894 case WLAN_CIPHER_SUITE_CCMP:
3895 case WLAN_CIPHER_SUITE_CCMP_256:
3896 case WLAN_CIPHER_SUITE_GCMP:
3897 case WLAN_CIPHER_SUITE_GCMP_256:
3900 /* we also don't want to deal with WEP or cipher scheme
3901 * since those require looking up the key idx in the
3902 * frame, rather than assuming the PTK is used
3903 * (we need to revisit this once we implement the real
3904 * PTK index, which is now valid in the spec, but we
3905 * haven't implemented that part yet)
3911 fastrx.icv_len = key->conf.icv_len;
3918 __release(check_fast_rx);
3921 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
3923 spin_lock_bh(&sta->lock);
3924 old = rcu_dereference_protected(sta->fast_rx, true);
3925 rcu_assign_pointer(sta->fast_rx, new);
3926 spin_unlock_bh(&sta->lock);
3929 kfree_rcu(old, rcu_head);
3932 void ieee80211_clear_fast_rx(struct sta_info *sta)
3934 struct ieee80211_fast_rx *old;
3936 spin_lock_bh(&sta->lock);
3937 old = rcu_dereference_protected(sta->fast_rx, true);
3938 RCU_INIT_POINTER(sta->fast_rx, NULL);
3939 spin_unlock_bh(&sta->lock);
3942 kfree_rcu(old, rcu_head);
3945 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
3947 struct ieee80211_local *local = sdata->local;
3948 struct sta_info *sta;
3950 lockdep_assert_held(&local->sta_mtx);
3952 list_for_each_entry(sta, &local->sta_list, list) {
3953 if (sdata != sta->sdata &&
3954 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3956 ieee80211_check_fast_rx(sta);
3960 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
3962 struct ieee80211_local *local = sdata->local;
3964 mutex_lock(&local->sta_mtx);
3965 __ieee80211_check_fast_rx_iface(sdata);
3966 mutex_unlock(&local->sta_mtx);
3969 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
3970 struct ieee80211_fast_rx *fast_rx)
3972 struct sk_buff *skb = rx->skb;
3973 struct ieee80211_hdr *hdr = (void *)skb->data;
3974 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3975 struct sta_info *sta = rx->sta;
3976 int orig_len = skb->len;
3977 int snap_offs = ieee80211_hdrlen(hdr->frame_control);
3979 u8 snap[sizeof(rfc1042_header)];
3981 } *payload __aligned(2);
3985 } addrs __aligned(2);
3986 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
3988 if (fast_rx->uses_rss)
3989 stats = this_cpu_ptr(sta->pcpu_rx_stats);
3991 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
3992 * to a common data structure; drivers can implement that per queue
3993 * but we don't have that information in mac80211
3995 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
3998 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4000 /* If using encryption, we also need to have:
4001 * - PN_VALIDATED: similar, but the implementation is tricky
4002 * - DECRYPTED: necessary for PN_VALIDATED
4005 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4008 /* we don't deal with A-MSDU deaggregation here */
4009 if (status->rx_flags & IEEE80211_RX_AMSDU)
4012 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4015 if (unlikely(ieee80211_is_frag(hdr)))
4018 /* Since our interface address cannot be multicast, this
4019 * implicitly also rejects multicast frames without the
4022 * We shouldn't get any *data* frames not addressed to us
4023 * (AP mode will accept multicast *management* frames), but
4024 * punting here will make it go through the full checks in
4025 * ieee80211_accept_frame().
4027 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4030 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4031 IEEE80211_FCTL_TODS)) !=
4032 fast_rx->expected_ds_bits)
4035 /* assign the key to drop unencrypted frames (later)
4036 * and strip the IV/MIC if necessary
4038 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4039 /* GCMP header length is the same */
4040 snap_offs += IEEE80211_CCMP_HDR_LEN;
4043 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4045 payload = (void *)(skb->data + snap_offs);
4047 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4050 /* Don't handle these here since they require special code.
4051 * Accept AARP and IPX even though they should come with a
4052 * bridge-tunnel header - but if we get them this way then
4053 * there's little point in discarding them.
4055 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4056 payload->proto == fast_rx->control_port_protocol))
4059 /* after this point, don't punt to the slowpath! */
4061 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4062 pskb_trim(skb, skb->len - fast_rx->icv_len))
4065 if (unlikely(fast_rx->sta_notify)) {
4066 ieee80211_sta_rx_notify(rx->sdata, hdr);
4067 fast_rx->sta_notify = false;
4070 /* statistics part of ieee80211_rx_h_sta_process() */
4071 stats->last_rx = jiffies;
4072 stats->last_rate = sta_stats_encode_rate(status);
4077 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4078 stats->last_signal = status->signal;
4079 if (!fast_rx->uses_rss)
4080 ewma_signal_add(&sta->rx_stats_avg.signal,
4084 if (status->chains) {
4087 stats->chains = status->chains;
4088 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4089 int signal = status->chain_signal[i];
4091 if (!(status->chains & BIT(i)))
4094 stats->chain_signal_last[i] = signal;
4095 if (!fast_rx->uses_rss)
4096 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4100 /* end of statistics */
4102 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4105 /* do the header conversion - first grab the addresses */
4106 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4107 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4108 /* remove the SNAP but leave the ethertype */
4109 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4110 /* push the addresses in front */
4111 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4113 skb->dev = fast_rx->dev;
4115 ieee80211_rx_stats(fast_rx->dev, skb->len);
4117 /* The seqno index has the same property as needed
4118 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4119 * for non-QoS-data frames. Here we know it's a data
4120 * frame, so count MSDUs.
4122 u64_stats_update_begin(&stats->syncp);
4123 stats->msdu[rx->seqno_idx]++;
4124 stats->bytes += orig_len;
4125 u64_stats_update_end(&stats->syncp);
4127 if (fast_rx->internal_forward) {
4128 struct sk_buff *xmit_skb = NULL;
4129 bool multicast = is_multicast_ether_addr(skb->data);
4132 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4133 } else if (sta_info_get(rx->sdata, skb->data)) {
4140 * Send to wireless media and increase priority by 256
4141 * to keep the received priority instead of
4142 * reclassifying the frame (see cfg80211_classify8021d).
4144 xmit_skb->priority += 256;
4145 xmit_skb->protocol = htons(ETH_P_802_3);
4146 skb_reset_network_header(xmit_skb);
4147 skb_reset_mac_header(xmit_skb);
4148 dev_queue_xmit(xmit_skb);
4155 /* deliver to local stack */
4156 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4157 memset(skb->cb, 0, sizeof(skb->cb));
4159 napi_gro_receive(rx->napi, skb);
4161 netif_receive_skb(skb);
4171 * This function returns whether or not the SKB
4172 * was destined for RX processing or not, which,
4173 * if consume is true, is equivalent to whether
4174 * or not the skb was consumed.
4176 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4177 struct sk_buff *skb, bool consume)
4179 struct ieee80211_local *local = rx->local;
4180 struct ieee80211_sub_if_data *sdata = rx->sdata;
4184 /* See if we can do fast-rx; if we have to copy we already lost,
4185 * so punt in that case. We should never have to deliver a data
4186 * frame to multiple interfaces anyway.
4188 * We skip the ieee80211_accept_frame() call and do the necessary
4189 * checking inside ieee80211_invoke_fast_rx().
4191 if (consume && rx->sta) {
4192 struct ieee80211_fast_rx *fast_rx;
4194 fast_rx = rcu_dereference(rx->sta->fast_rx);
4195 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4199 if (!ieee80211_accept_frame(rx))
4203 skb = skb_copy(skb, GFP_ATOMIC);
4205 if (net_ratelimit())
4206 wiphy_debug(local->hw.wiphy,
4207 "failed to copy skb for %s\n",
4215 ieee80211_invoke_rx_handlers(rx);
4220 * This is the actual Rx frames handler. as it belongs to Rx path it must
4221 * be called with rcu_read_lock protection.
4223 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4224 struct ieee80211_sta *pubsta,
4225 struct sk_buff *skb,
4226 struct napi_struct *napi)
4228 struct ieee80211_local *local = hw_to_local(hw);
4229 struct ieee80211_sub_if_data *sdata;
4230 struct ieee80211_hdr *hdr;
4232 struct ieee80211_rx_data rx;
4233 struct ieee80211_sub_if_data *prev;
4234 struct rhlist_head *tmp;
4237 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4238 memset(&rx, 0, sizeof(rx));
4243 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4244 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4246 if (ieee80211_is_mgmt(fc)) {
4247 /* drop frame if too short for header */
4248 if (skb->len < ieee80211_hdrlen(fc))
4251 err = skb_linearize(skb);
4253 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4261 hdr = (struct ieee80211_hdr *)skb->data;
4262 ieee80211_parse_qos(&rx);
4263 ieee80211_verify_alignment(&rx);
4265 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4266 ieee80211_is_beacon(hdr->frame_control)))
4267 ieee80211_scan_rx(local, skb);
4269 if (ieee80211_is_data(fc)) {
4270 struct sta_info *sta, *prev_sta;
4273 rx.sta = container_of(pubsta, struct sta_info, sta);
4274 rx.sdata = rx.sta->sdata;
4275 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4282 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4289 rx.sdata = prev_sta->sdata;
4290 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4297 rx.sdata = prev_sta->sdata;
4299 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4307 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4308 if (!ieee80211_sdata_running(sdata))
4311 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4312 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4316 * frame is destined for this interface, but if it's
4317 * not also for the previous one we handle that after
4318 * the loop to avoid copying the SKB once too much
4326 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4328 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4334 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4337 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4346 * This is the receive path handler. It is called by a low level driver when an
4347 * 802.11 MPDU is received from the hardware.
4349 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4350 struct sk_buff *skb, struct napi_struct *napi)
4352 struct ieee80211_local *local = hw_to_local(hw);
4353 struct ieee80211_rate *rate = NULL;
4354 struct ieee80211_supported_band *sband;
4355 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4357 WARN_ON_ONCE(softirq_count() == 0);
4359 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4362 sband = local->hw.wiphy->bands[status->band];
4363 if (WARN_ON(!sband))
4367 * If we're suspending, it is possible although not too likely
4368 * that we'd be receiving frames after having already partially
4369 * quiesced the stack. We can't process such frames then since
4370 * that might, for example, cause stations to be added or other
4371 * driver callbacks be invoked.
4373 if (unlikely(local->quiescing || local->suspended))
4376 /* We might be during a HW reconfig, prevent Rx for the same reason */
4377 if (unlikely(local->in_reconfig))
4381 * The same happens when we're not even started,
4382 * but that's worth a warning.
4384 if (WARN_ON(!local->started))
4387 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4389 * Validate the rate, unless a PLCP error means that
4390 * we probably can't have a valid rate here anyway.
4393 if (status->flag & RX_FLAG_HT) {
4395 * rate_idx is MCS index, which can be [0-76]
4398 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4400 * Anything else would be some sort of driver or
4401 * hardware error. The driver should catch hardware
4404 if (WARN(status->rate_idx > 76,
4405 "Rate marked as an HT rate but passed "
4406 "status->rate_idx is not "
4407 "an MCS index [0-76]: %d (0x%02x)\n",
4411 } else if (status->flag & RX_FLAG_VHT) {
4412 if (WARN_ONCE(status->rate_idx > 9 ||
4414 status->vht_nss > 8,
4415 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4416 status->rate_idx, status->vht_nss))
4419 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4421 rate = &sband->bitrates[status->rate_idx];
4425 status->rx_flags = 0;
4428 * key references and virtual interfaces are protected using RCU
4429 * and this requires that we are in a read-side RCU section during
4430 * receive processing
4435 * Frames with failed FCS/PLCP checksum are not returned,
4436 * all other frames are returned without radiotap header
4437 * if it was previously present.
4438 * Also, frames with less than 16 bytes are dropped.
4440 skb = ieee80211_rx_monitor(local, skb, rate);
4446 ieee80211_tpt_led_trig_rx(local,
4447 ((struct ieee80211_hdr *)skb->data)->frame_control,
4450 __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
4458 EXPORT_SYMBOL(ieee80211_rx_napi);
4460 /* This is a version of the rx handler that can be called from hard irq
4461 * context. Post the skb on the queue and schedule the tasklet */
4462 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
4464 struct ieee80211_local *local = hw_to_local(hw);
4466 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4468 skb->pkt_type = IEEE80211_RX_MSG;
4469 skb_queue_tail(&local->skb_queue, skb);
4470 tasklet_schedule(&local->tasklet);
4472 EXPORT_SYMBOL(ieee80211_rx_irqsafe);