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_BLOCKACK &&
1183 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1186 /* new, potentially un-ordered, ampdu frame - process it */
1188 /* reset session timer */
1189 if (tid_agg_rx->timeout)
1190 tid_agg_rx->last_rx = jiffies;
1192 /* if this mpdu is fragmented - terminate rx aggregation session */
1193 sc = le16_to_cpu(hdr->seq_ctrl);
1194 if (sc & IEEE80211_SCTL_FRAG) {
1195 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
1196 skb_queue_tail(&rx->sdata->skb_queue, skb);
1197 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1202 * No locking needed -- we will only ever process one
1203 * RX packet at a time, and thus own tid_agg_rx. All
1204 * other code manipulating it needs to (and does) make
1205 * sure that we cannot get to it any more before doing
1208 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1213 __skb_queue_tail(frames, skb);
1216 static ieee80211_rx_result debug_noinline
1217 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1219 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1220 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1222 if (status->flag & RX_FLAG_DUP_VALIDATED)
1226 * Drop duplicate 802.11 retransmissions
1227 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1230 if (rx->skb->len < 24)
1233 if (ieee80211_is_ctl(hdr->frame_control) ||
1234 ieee80211_is_any_nullfunc(hdr->frame_control) ||
1235 is_multicast_ether_addr(hdr->addr1))
1241 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1242 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1243 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1244 rx->sta->rx_stats.num_duplicates++;
1245 return RX_DROP_UNUSABLE;
1246 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1247 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1253 static ieee80211_rx_result debug_noinline
1254 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1256 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1258 /* Drop disallowed frame classes based on STA auth/assoc state;
1259 * IEEE 802.11, Chap 5.5.
1261 * mac80211 filters only based on association state, i.e. it drops
1262 * Class 3 frames from not associated stations. hostapd sends
1263 * deauth/disassoc frames when needed. In addition, hostapd is
1264 * responsible for filtering on both auth and assoc states.
1267 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1268 return ieee80211_rx_mesh_check(rx);
1270 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1271 ieee80211_is_pspoll(hdr->frame_control)) &&
1272 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1273 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1274 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1275 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1277 * accept port control frames from the AP even when it's not
1278 * yet marked ASSOC to prevent a race where we don't set the
1279 * assoc bit quickly enough before it sends the first frame
1281 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1282 ieee80211_is_data_present(hdr->frame_control)) {
1283 unsigned int hdrlen;
1286 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1288 if (rx->skb->len < hdrlen + 8)
1289 return RX_DROP_MONITOR;
1291 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1292 if (ethertype == rx->sdata->control_port_protocol)
1296 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1297 cfg80211_rx_spurious_frame(rx->sdata->dev,
1300 return RX_DROP_UNUSABLE;
1302 return RX_DROP_MONITOR;
1309 static ieee80211_rx_result debug_noinline
1310 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1312 struct ieee80211_local *local;
1313 struct ieee80211_hdr *hdr;
1314 struct sk_buff *skb;
1318 hdr = (struct ieee80211_hdr *) skb->data;
1320 if (!local->pspolling)
1323 if (!ieee80211_has_fromds(hdr->frame_control))
1324 /* this is not from AP */
1327 if (!ieee80211_is_data(hdr->frame_control))
1330 if (!ieee80211_has_moredata(hdr->frame_control)) {
1331 /* AP has no more frames buffered for us */
1332 local->pspolling = false;
1336 /* more data bit is set, let's request a new frame from the AP */
1337 ieee80211_send_pspoll(local, rx->sdata);
1342 static void sta_ps_start(struct sta_info *sta)
1344 struct ieee80211_sub_if_data *sdata = sta->sdata;
1345 struct ieee80211_local *local = sdata->local;
1349 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1350 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1351 ps = &sdata->bss->ps;
1355 atomic_inc(&ps->num_sta_ps);
1356 set_sta_flag(sta, WLAN_STA_PS_STA);
1357 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1358 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1359 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1360 sta->sta.addr, sta->sta.aid);
1362 ieee80211_clear_fast_xmit(sta);
1364 if (!sta->sta.txq[0])
1367 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1368 if (txq_has_queue(sta->sta.txq[tid]))
1369 set_bit(tid, &sta->txq_buffered_tids);
1371 clear_bit(tid, &sta->txq_buffered_tids);
1375 static void sta_ps_end(struct sta_info *sta)
1377 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1378 sta->sta.addr, sta->sta.aid);
1380 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1382 * Clear the flag only if the other one is still set
1383 * so that the TX path won't start TX'ing new frames
1384 * directly ... In the case that the driver flag isn't
1385 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1387 clear_sta_flag(sta, WLAN_STA_PS_STA);
1388 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1389 sta->sta.addr, sta->sta.aid);
1393 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1394 clear_sta_flag(sta, WLAN_STA_PS_STA);
1395 ieee80211_sta_ps_deliver_wakeup(sta);
1398 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1400 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1403 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1405 /* Don't let the same PS state be set twice */
1406 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1407 if ((start && in_ps) || (!start && !in_ps))
1417 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1419 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1421 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1423 if (test_sta_flag(sta, WLAN_STA_SP))
1426 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1427 ieee80211_sta_ps_deliver_poll_response(sta);
1429 set_sta_flag(sta, WLAN_STA_PSPOLL);
1431 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1433 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1435 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1436 u8 ac = ieee802_1d_to_ac[tid & 7];
1439 * If this AC is not trigger-enabled do nothing.
1441 * NB: This could/should check a separate bitmap of trigger-
1442 * enabled queues, but for now we only implement uAPSD w/o
1443 * TSPEC changes to the ACs, so they're always the same.
1445 if (!(sta->sta.uapsd_queues & BIT(ac)))
1448 /* if we are in a service period, do nothing */
1449 if (test_sta_flag(sta, WLAN_STA_SP))
1452 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1453 ieee80211_sta_ps_deliver_uapsd(sta);
1455 set_sta_flag(sta, WLAN_STA_UAPSD);
1457 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1459 static ieee80211_rx_result debug_noinline
1460 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1462 struct ieee80211_sub_if_data *sdata = rx->sdata;
1463 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1464 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1469 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1470 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1474 * The device handles station powersave, so don't do anything about
1475 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1476 * it to mac80211 since they're handled.)
1478 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1482 * Don't do anything if the station isn't already asleep. In
1483 * the uAPSD case, the station will probably be marked asleep,
1484 * in the PS-Poll case the station must be confused ...
1486 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1489 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1490 ieee80211_sta_pspoll(&rx->sta->sta);
1492 /* Free PS Poll skb here instead of returning RX_DROP that would
1493 * count as an dropped frame. */
1494 dev_kfree_skb(rx->skb);
1497 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1498 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1499 ieee80211_has_pm(hdr->frame_control) &&
1500 (ieee80211_is_data_qos(hdr->frame_control) ||
1501 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1504 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1506 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1512 static ieee80211_rx_result debug_noinline
1513 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1515 struct sta_info *sta = rx->sta;
1516 struct sk_buff *skb = rx->skb;
1517 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1518 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1525 * Update last_rx only for IBSS packets which are for the current
1526 * BSSID and for station already AUTHORIZED to avoid keeping the
1527 * current IBSS network alive in cases where other STAs start
1528 * using different BSSID. This will also give the station another
1529 * chance to restart the authentication/authorization in case
1530 * something went wrong the first time.
1532 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1533 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1534 NL80211_IFTYPE_ADHOC);
1535 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1536 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1537 sta->rx_stats.last_rx = jiffies;
1538 if (ieee80211_is_data(hdr->frame_control) &&
1539 !is_multicast_ether_addr(hdr->addr1))
1540 sta->rx_stats.last_rate =
1541 sta_stats_encode_rate(status);
1543 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1544 sta->rx_stats.last_rx = jiffies;
1545 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1547 * Mesh beacons will update last_rx when if they are found to
1548 * match the current local configuration when processed.
1550 sta->rx_stats.last_rx = jiffies;
1551 if (ieee80211_is_data(hdr->frame_control))
1552 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1555 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1556 ieee80211_sta_rx_notify(rx->sdata, hdr);
1558 sta->rx_stats.fragments++;
1560 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1561 sta->rx_stats.bytes += rx->skb->len;
1562 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1564 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1565 sta->rx_stats.last_signal = status->signal;
1566 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1569 if (status->chains) {
1570 sta->rx_stats.chains = status->chains;
1571 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1572 int signal = status->chain_signal[i];
1574 if (!(status->chains & BIT(i)))
1577 sta->rx_stats.chain_signal_last[i] = signal;
1578 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1584 * Change STA power saving mode only at the end of a frame
1585 * exchange sequence.
1587 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1588 !ieee80211_has_morefrags(hdr->frame_control) &&
1589 !ieee80211_is_back_req(hdr->frame_control) &&
1590 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1591 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1592 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1594 * PM bit is only checked in frames where it isn't reserved,
1595 * in AP mode it's reserved in non-bufferable management frames
1596 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1597 * BAR frames should be ignored as specified in
1598 * IEEE 802.11-2012 10.2.1.2.
1600 (!ieee80211_is_mgmt(hdr->frame_control) ||
1601 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
1602 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1603 if (!ieee80211_has_pm(hdr->frame_control))
1606 if (ieee80211_has_pm(hdr->frame_control))
1611 /* mesh power save support */
1612 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1613 ieee80211_mps_rx_h_sta_process(sta, hdr);
1616 * Drop (qos-)data::nullfunc frames silently, since they
1617 * are used only to control station power saving mode.
1619 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1620 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1623 * If we receive a 4-addr nullfunc frame from a STA
1624 * that was not moved to a 4-addr STA vlan yet send
1625 * the event to userspace and for older hostapd drop
1626 * the frame to the monitor interface.
1628 if (ieee80211_has_a4(hdr->frame_control) &&
1629 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1630 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1631 !rx->sdata->u.vlan.sta))) {
1632 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1633 cfg80211_rx_unexpected_4addr_frame(
1634 rx->sdata->dev, sta->sta.addr,
1636 return RX_DROP_MONITOR;
1639 * Update counter and free packet here to avoid
1640 * counting this as a dropped packed.
1642 sta->rx_stats.packets++;
1643 dev_kfree_skb(rx->skb);
1648 } /* ieee80211_rx_h_sta_process */
1650 static ieee80211_rx_result debug_noinline
1651 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1653 struct sk_buff *skb = rx->skb;
1654 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1655 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1658 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1659 struct ieee80211_key *sta_ptk = NULL;
1660 int mmie_keyidx = -1;
1662 const struct ieee80211_cipher_scheme *cs = NULL;
1667 * There are four types of keys:
1668 * - GTK (group keys)
1669 * - IGTK (group keys for management frames)
1670 * - PTK (pairwise keys)
1671 * - STK (station-to-station pairwise keys)
1673 * When selecting a key, we have to distinguish between multicast
1674 * (including broadcast) and unicast frames, the latter can only
1675 * use PTKs and STKs while the former always use GTKs and IGTKs.
1676 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1677 * unicast frames can also use key indices like GTKs. Hence, if we
1678 * don't have a PTK/STK we check the key index for a WEP key.
1680 * Note that in a regular BSS, multicast frames are sent by the
1681 * AP only, associated stations unicast the frame to the AP first
1682 * which then multicasts it on their behalf.
1684 * There is also a slight problem in IBSS mode: GTKs are negotiated
1685 * with each station, that is something we don't currently handle.
1686 * The spec seems to expect that one negotiates the same key with
1687 * every station but there's no such requirement; VLANs could be
1691 /* start without a key */
1693 fc = hdr->frame_control;
1696 int keyid = rx->sta->ptk_idx;
1698 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1699 cs = rx->sta->cipher_scheme;
1700 keyid = ieee80211_get_cs_keyid(cs, rx->skb);
1701 if (unlikely(keyid < 0))
1702 return RX_DROP_UNUSABLE;
1704 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1707 if (!ieee80211_has_protected(fc))
1708 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1710 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1712 if ((status->flag & RX_FLAG_DECRYPTED) &&
1713 (status->flag & RX_FLAG_IV_STRIPPED))
1715 /* Skip decryption if the frame is not protected. */
1716 if (!ieee80211_has_protected(fc))
1718 } else if (mmie_keyidx >= 0) {
1719 /* Broadcast/multicast robust management frame / BIP */
1720 if ((status->flag & RX_FLAG_DECRYPTED) &&
1721 (status->flag & RX_FLAG_IV_STRIPPED))
1724 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1725 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1726 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1728 if (ieee80211_is_group_privacy_action(skb) &&
1729 test_sta_flag(rx->sta, WLAN_STA_MFP))
1730 return RX_DROP_MONITOR;
1732 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1735 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1736 } else if (!ieee80211_has_protected(fc)) {
1738 * The frame was not protected, so skip decryption. However, we
1739 * need to set rx->key if there is a key that could have been
1740 * used so that the frame may be dropped if encryption would
1741 * have been expected.
1743 struct ieee80211_key *key = NULL;
1744 struct ieee80211_sub_if_data *sdata = rx->sdata;
1747 if (ieee80211_is_mgmt(fc) &&
1748 is_multicast_ether_addr(hdr->addr1) &&
1749 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1753 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1754 key = rcu_dereference(rx->sta->gtk[i]);
1760 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1761 key = rcu_dereference(sdata->keys[i]);
1774 * The device doesn't give us the IV so we won't be
1775 * able to look up the key. That's ok though, we
1776 * don't need to decrypt the frame, we just won't
1777 * be able to keep statistics accurate.
1778 * Except for key threshold notifications, should
1779 * we somehow allow the driver to tell us which key
1780 * the hardware used if this flag is set?
1782 if ((status->flag & RX_FLAG_DECRYPTED) &&
1783 (status->flag & RX_FLAG_IV_STRIPPED))
1786 hdrlen = ieee80211_hdrlen(fc);
1789 keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
1791 if (unlikely(keyidx < 0))
1792 return RX_DROP_UNUSABLE;
1794 if (rx->skb->len < 8 + hdrlen)
1795 return RX_DROP_UNUSABLE; /* TODO: count this? */
1797 * no need to call ieee80211_wep_get_keyidx,
1798 * it verifies a bunch of things we've done already
1800 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1801 keyidx = keyid >> 6;
1804 /* check per-station GTK first, if multicast packet */
1805 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1806 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1808 /* if not found, try default key */
1810 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1813 * RSNA-protected unicast frames should always be
1814 * sent with pairwise or station-to-station keys,
1815 * but for WEP we allow using a key index as well.
1818 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1819 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1820 !is_multicast_ether_addr(hdr->addr1))
1826 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1827 return RX_DROP_MONITOR;
1829 /* TODO: add threshold stuff again */
1831 return RX_DROP_MONITOR;
1834 switch (rx->key->conf.cipher) {
1835 case WLAN_CIPHER_SUITE_WEP40:
1836 case WLAN_CIPHER_SUITE_WEP104:
1837 result = ieee80211_crypto_wep_decrypt(rx);
1839 case WLAN_CIPHER_SUITE_TKIP:
1840 result = ieee80211_crypto_tkip_decrypt(rx);
1842 case WLAN_CIPHER_SUITE_CCMP:
1843 result = ieee80211_crypto_ccmp_decrypt(
1844 rx, IEEE80211_CCMP_MIC_LEN);
1846 case WLAN_CIPHER_SUITE_CCMP_256:
1847 result = ieee80211_crypto_ccmp_decrypt(
1848 rx, IEEE80211_CCMP_256_MIC_LEN);
1850 case WLAN_CIPHER_SUITE_AES_CMAC:
1851 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1853 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1854 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1856 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1857 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1858 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1860 case WLAN_CIPHER_SUITE_GCMP:
1861 case WLAN_CIPHER_SUITE_GCMP_256:
1862 result = ieee80211_crypto_gcmp_decrypt(rx);
1865 result = ieee80211_crypto_hw_decrypt(rx);
1868 /* the hdr variable is invalid after the decrypt handlers */
1870 /* either the frame has been decrypted or will be dropped */
1871 status->flag |= RX_FLAG_DECRYPTED;
1876 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
1880 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
1881 skb_queue_head_init(&cache->entries[i].skb_list);
1884 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
1888 for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
1889 __skb_queue_purge(&cache->entries[i].skb_list);
1892 static inline struct ieee80211_fragment_entry *
1893 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
1894 unsigned int frag, unsigned int seq, int rx_queue,
1895 struct sk_buff **skb)
1897 struct ieee80211_fragment_entry *entry;
1899 entry = &cache->entries[cache->next++];
1900 if (cache->next >= IEEE80211_FRAGMENT_MAX)
1903 __skb_queue_purge(&entry->skb_list);
1905 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1907 entry->first_frag_time = jiffies;
1909 entry->rx_queue = rx_queue;
1910 entry->last_frag = frag;
1911 entry->check_sequential_pn = false;
1912 entry->extra_len = 0;
1917 static inline struct ieee80211_fragment_entry *
1918 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
1919 unsigned int frag, unsigned int seq,
1920 int rx_queue, struct ieee80211_hdr *hdr)
1922 struct ieee80211_fragment_entry *entry;
1926 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1927 struct ieee80211_hdr *f_hdr;
1931 idx = IEEE80211_FRAGMENT_MAX - 1;
1933 entry = &cache->entries[idx];
1934 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1935 entry->rx_queue != rx_queue ||
1936 entry->last_frag + 1 != frag)
1939 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1942 * Check ftype and addresses are equal, else check next fragment
1944 if (((hdr->frame_control ^ f_hdr->frame_control) &
1945 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1946 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1947 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
1950 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1951 __skb_queue_purge(&entry->skb_list);
1960 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
1963 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
1964 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
1965 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
1966 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
1967 ieee80211_has_protected(fc);
1970 static ieee80211_rx_result debug_noinline
1971 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1973 struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
1974 struct ieee80211_hdr *hdr;
1977 unsigned int frag, seq;
1978 struct ieee80211_fragment_entry *entry;
1979 struct sk_buff *skb;
1980 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1982 hdr = (struct ieee80211_hdr *)rx->skb->data;
1983 fc = hdr->frame_control;
1985 if (ieee80211_is_ctl(fc))
1988 sc = le16_to_cpu(hdr->seq_ctrl);
1989 frag = sc & IEEE80211_SCTL_FRAG;
1992 cache = &rx->sta->frags;
1994 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
1997 if (is_multicast_ether_addr(hdr->addr1))
1998 return RX_DROP_MONITOR;
2000 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2002 if (skb_linearize(rx->skb))
2003 return RX_DROP_UNUSABLE;
2006 * skb_linearize() might change the skb->data and
2007 * previously cached variables (in this case, hdr) need to
2008 * be refreshed with the new data.
2010 hdr = (struct ieee80211_hdr *)rx->skb->data;
2011 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2014 /* This is the first fragment of a new frame. */
2015 entry = ieee80211_reassemble_add(cache, frag, seq,
2016 rx->seqno_idx, &(rx->skb));
2017 if (requires_sequential_pn(rx, fc)) {
2018 int queue = rx->security_idx;
2020 /* Store CCMP/GCMP PN so that we can verify that the
2021 * next fragment has a sequential PN value.
2023 entry->check_sequential_pn = true;
2024 entry->is_protected = true;
2025 entry->key_color = rx->key->color;
2026 memcpy(entry->last_pn,
2027 rx->key->u.ccmp.rx_pn[queue],
2028 IEEE80211_CCMP_PN_LEN);
2029 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2031 offsetof(struct ieee80211_key,
2033 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2034 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2035 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2036 IEEE80211_GCMP_PN_LEN);
2037 } else if (rx->key &&
2038 (ieee80211_has_protected(fc) ||
2039 (status->flag & RX_FLAG_DECRYPTED))) {
2040 entry->is_protected = true;
2041 entry->key_color = rx->key->color;
2046 /* This is a fragment for a frame that should already be pending in
2047 * fragment cache. Add this fragment to the end of the pending entry.
2049 entry = ieee80211_reassemble_find(cache, frag, seq,
2050 rx->seqno_idx, hdr);
2052 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2053 return RX_DROP_MONITOR;
2056 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2057 * MPDU PN values are not incrementing in steps of 1."
2058 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2059 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2061 if (entry->check_sequential_pn) {
2063 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2065 if (!requires_sequential_pn(rx, fc))
2066 return RX_DROP_UNUSABLE;
2068 /* Prevent mixed key and fragment cache attacks */
2069 if (entry->key_color != rx->key->color)
2070 return RX_DROP_UNUSABLE;
2072 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2073 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2079 rpn = rx->ccm_gcm.pn;
2080 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2081 return RX_DROP_UNUSABLE;
2082 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2083 } else if (entry->is_protected &&
2085 (!ieee80211_has_protected(fc) &&
2086 !(status->flag & RX_FLAG_DECRYPTED)) ||
2087 rx->key->color != entry->key_color)) {
2088 /* Drop this as a mixed key or fragment cache attack, even
2089 * if for TKIP Michael MIC should protect us, and WEP is a
2090 * lost cause anyway.
2092 return RX_DROP_UNUSABLE;
2093 } else if (entry->is_protected && rx->key &&
2094 entry->key_color != rx->key->color &&
2095 (status->flag & RX_FLAG_DECRYPTED)) {
2096 return RX_DROP_UNUSABLE;
2099 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2100 __skb_queue_tail(&entry->skb_list, rx->skb);
2101 entry->last_frag = frag;
2102 entry->extra_len += rx->skb->len;
2103 if (ieee80211_has_morefrags(fc)) {
2108 rx->skb = __skb_dequeue(&entry->skb_list);
2109 if (skb_tailroom(rx->skb) < entry->extra_len) {
2110 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2111 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2113 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2114 __skb_queue_purge(&entry->skb_list);
2115 return RX_DROP_UNUSABLE;
2118 while ((skb = __skb_dequeue(&entry->skb_list))) {
2119 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
2123 /* Complete frame has been reassembled - process it now */
2124 status = IEEE80211_SKB_RXCB(rx->skb);
2127 ieee80211_led_rx(rx->local);
2129 rx->sta->rx_stats.packets++;
2133 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2135 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2141 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2143 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
2144 struct sk_buff *skb = rx->skb;
2145 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2148 * Pass through unencrypted frames if the hardware has
2149 * decrypted them already.
2151 if (status->flag & RX_FLAG_DECRYPTED)
2154 /* check mesh EAPOL frames first */
2155 if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
2156 ieee80211_is_data(fc))) {
2157 struct ieee80211s_hdr *mesh_hdr;
2158 u16 hdr_len = ieee80211_hdrlen(fc);
2159 u16 ethertype_offset;
2162 if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
2165 /* make sure fixed part of mesh header is there, also checks skb len */
2166 if (!pskb_may_pull(rx->skb, hdr_len + 6))
2169 mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
2170 ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
2171 sizeof(rfc1042_header);
2173 if (skb_copy_bits(rx->skb, ethertype_offset, ðertype, 2) == 0 &&
2174 ethertype == rx->sdata->control_port_protocol)
2179 /* Drop unencrypted frames if key is set. */
2180 if (unlikely(!ieee80211_has_protected(fc) &&
2181 !ieee80211_is_any_nullfunc(fc) &&
2182 ieee80211_is_data(fc) && rx->key))
2188 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2190 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2191 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2192 __le16 fc = hdr->frame_control;
2195 * Pass through unencrypted frames if the hardware has
2196 * decrypted them already.
2198 if (status->flag & RX_FLAG_DECRYPTED)
2201 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2202 if (unlikely(!ieee80211_has_protected(fc) &&
2203 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2205 if (ieee80211_is_deauth(fc) ||
2206 ieee80211_is_disassoc(fc))
2207 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2212 /* BIP does not use Protected field, so need to check MMIE */
2213 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2214 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2215 if (ieee80211_is_deauth(fc) ||
2216 ieee80211_is_disassoc(fc))
2217 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2223 * When using MFP, Action frames are not allowed prior to
2224 * having configured keys.
2226 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2227 ieee80211_is_robust_mgmt_frame(rx->skb)))
2235 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2237 struct ieee80211_sub_if_data *sdata = rx->sdata;
2238 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2239 bool check_port_control = false;
2240 struct ethhdr *ehdr;
2243 *port_control = false;
2244 if (ieee80211_has_a4(hdr->frame_control) &&
2245 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2248 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2249 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2251 if (!sdata->u.mgd.use_4addr)
2254 check_port_control = true;
2257 if (is_multicast_ether_addr(hdr->addr1) &&
2258 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2261 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2265 ehdr = (struct ethhdr *) rx->skb->data;
2266 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2267 *port_control = true;
2268 else if (check_port_control)
2275 * requires that rx->skb is a frame with ethernet header
2277 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2279 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2280 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2281 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2284 * Allow EAPOL frames to us/the PAE group address regardless of
2285 * whether the frame was encrypted or not, and always disallow
2286 * all other destination addresses for them.
2288 if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2289 return ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2290 ether_addr_equal(ehdr->h_dest, pae_group_addr);
2292 if (ieee80211_802_1x_port_control(rx) ||
2293 ieee80211_drop_unencrypted(rx, fc))
2300 * requires that rx->skb is a frame with ethernet header
2303 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2305 struct ieee80211_sub_if_data *sdata = rx->sdata;
2306 struct net_device *dev = sdata->dev;
2307 struct sk_buff *skb, *xmit_skb;
2308 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2309 struct sta_info *dsta;
2314 ieee80211_rx_stats(dev, skb->len);
2317 /* The seqno index has the same property as needed
2318 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2319 * for non-QoS-data frames. Here we know it's a data
2320 * frame, so count MSDUs.
2322 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
2323 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2324 u64_stats_update_end(&rx->sta->rx_stats.syncp);
2327 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2328 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2329 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2330 ehdr->h_proto != rx->sdata->control_port_protocol &&
2331 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2332 if (is_multicast_ether_addr(ehdr->h_dest)) {
2334 * send multicast frames both to higher layers in
2335 * local net stack and back to the wireless medium
2337 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2339 net_info_ratelimited("%s: failed to clone multicast frame\n",
2342 dsta = sta_info_get(sdata, skb->data);
2345 * The destination station is associated to
2346 * this AP (in this VLAN), so send the frame
2347 * directly to it and do not pass it to local
2356 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2358 /* 'align' will only take the values 0 or 2 here since all
2359 * frames are required to be aligned to 2-byte boundaries
2360 * when being passed to mac80211; the code here works just
2361 * as well if that isn't true, but mac80211 assumes it can
2362 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2366 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2368 if (WARN_ON(skb_headroom(skb) < 3)) {
2372 u8 *data = skb->data;
2373 size_t len = skb_headlen(skb);
2375 memmove(skb->data, data, len);
2376 skb_set_tail_pointer(skb, len);
2383 struct ethhdr *ehdr = (struct ethhdr *)skb->data;
2385 /* deliver to local stack */
2386 skb->protocol = eth_type_trans(skb, dev);
2387 memset(skb->cb, 0, sizeof(skb->cb));
2390 * 802.1X over 802.11 requires that the authenticator address
2391 * be used for EAPOL frames. However, 802.1X allows the use of
2392 * the PAE group address instead. If the interface is part of
2393 * a bridge and we pass the frame with the PAE group address,
2394 * then the bridge will forward it to the network (even if the
2395 * client was not associated yet), which isn't supposed to
2397 * To avoid that, rewrite the destination address to our own
2398 * address, so that the authenticator (e.g. hostapd) will see
2399 * the frame, but bridge won't forward it anywhere else. Note
2400 * that due to earlier filtering, the only other address can
2401 * be the PAE group address.
2403 if (unlikely(skb->protocol == sdata->control_port_protocol &&
2404 !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2405 ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2408 napi_gro_receive(rx->napi, skb);
2410 netif_receive_skb(skb);
2415 * Send to wireless media and increase priority by 256 to
2416 * keep the received priority instead of reclassifying
2417 * the frame (see cfg80211_classify8021d).
2419 xmit_skb->priority += 256;
2420 xmit_skb->protocol = htons(ETH_P_802_3);
2421 skb_reset_network_header(xmit_skb);
2422 skb_reset_mac_header(xmit_skb);
2423 dev_queue_xmit(xmit_skb);
2427 static ieee80211_rx_result debug_noinline
2428 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2430 struct net_device *dev = rx->sdata->dev;
2431 struct sk_buff *skb = rx->skb;
2432 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2433 __le16 fc = hdr->frame_control;
2434 struct sk_buff_head frame_list;
2435 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2436 struct ethhdr ethhdr;
2437 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2439 if (unlikely(!ieee80211_is_data(fc)))
2442 if (unlikely(!ieee80211_is_data_present(fc)))
2443 return RX_DROP_MONITOR;
2445 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2448 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2449 switch (rx->sdata->vif.type) {
2450 case NL80211_IFTYPE_AP_VLAN:
2451 if (!rx->sdata->u.vlan.sta)
2452 return RX_DROP_UNUSABLE;
2454 case NL80211_IFTYPE_STATION:
2455 if (!rx->sdata->u.mgd.use_4addr)
2456 return RX_DROP_UNUSABLE;
2459 return RX_DROP_UNUSABLE;
2463 } else switch (rx->sdata->vif.type) {
2464 case NL80211_IFTYPE_AP:
2465 case NL80211_IFTYPE_AP_VLAN:
2468 case NL80211_IFTYPE_STATION:
2470 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2473 case NL80211_IFTYPE_MESH_POINT:
2480 if (is_multicast_ether_addr(hdr->addr1))
2481 return RX_DROP_UNUSABLE;
2484 __skb_queue_head_init(&frame_list);
2486 if (ieee80211_data_to_8023_exthdr(skb, ðhdr,
2487 rx->sdata->vif.addr,
2488 rx->sdata->vif.type,
2490 return RX_DROP_UNUSABLE;
2494 * We should not receive A-MSDUs on pre-HT connections,
2495 * and HT connections cannot use old ciphers. Thus drop
2496 * them, as in those cases we couldn't even have SPP
2499 switch (rx->key->conf.cipher) {
2500 case WLAN_CIPHER_SUITE_WEP40:
2501 case WLAN_CIPHER_SUITE_WEP104:
2502 case WLAN_CIPHER_SUITE_TKIP:
2503 return RX_DROP_UNUSABLE;
2509 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2510 rx->sdata->vif.type,
2511 rx->local->hw.extra_tx_headroom,
2512 check_da, check_sa);
2514 while (!skb_queue_empty(&frame_list)) {
2515 rx->skb = __skb_dequeue(&frame_list);
2517 if (!ieee80211_frame_allowed(rx, fc)) {
2518 dev_kfree_skb(rx->skb);
2522 ieee80211_deliver_skb(rx);
2528 #ifdef CONFIG_MAC80211_MESH
2529 static ieee80211_rx_result
2530 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2532 struct ieee80211_hdr *fwd_hdr, *hdr;
2533 struct ieee80211_tx_info *info;
2534 struct ieee80211s_hdr *mesh_hdr;
2535 struct sk_buff *skb = rx->skb, *fwd_skb;
2536 struct ieee80211_local *local = rx->local;
2537 struct ieee80211_sub_if_data *sdata = rx->sdata;
2538 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2541 hdr = (struct ieee80211_hdr *) skb->data;
2542 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2544 /* make sure fixed part of mesh header is there, also checks skb len */
2545 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2546 return RX_DROP_MONITOR;
2548 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2550 /* make sure full mesh header is there, also checks skb len */
2551 if (!pskb_may_pull(rx->skb,
2552 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2553 return RX_DROP_MONITOR;
2555 /* reload pointers */
2556 hdr = (struct ieee80211_hdr *) skb->data;
2557 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2559 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2560 return RX_DROP_MONITOR;
2562 /* frame is in RMC, don't forward */
2563 if (ieee80211_is_data(hdr->frame_control) &&
2564 is_multicast_ether_addr(hdr->addr1) &&
2565 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2566 return RX_DROP_MONITOR;
2568 if (!ieee80211_is_data(hdr->frame_control))
2572 return RX_DROP_MONITOR;
2574 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2575 struct mesh_path *mppath;
2579 if (is_multicast_ether_addr(hdr->addr1)) {
2580 mpp_addr = hdr->addr3;
2581 proxied_addr = mesh_hdr->eaddr1;
2582 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2583 MESH_FLAGS_AE_A5_A6) {
2584 /* has_a4 already checked in ieee80211_rx_mesh_check */
2585 mpp_addr = hdr->addr4;
2586 proxied_addr = mesh_hdr->eaddr2;
2588 return RX_DROP_MONITOR;
2592 mppath = mpp_path_lookup(sdata, proxied_addr);
2594 mpp_path_add(sdata, proxied_addr, mpp_addr);
2596 spin_lock_bh(&mppath->state_lock);
2597 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2598 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2599 mppath->exp_time = jiffies;
2600 spin_unlock_bh(&mppath->state_lock);
2605 /* Frame has reached destination. Don't forward */
2606 if (!is_multicast_ether_addr(hdr->addr1) &&
2607 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2610 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2611 q = sdata->vif.hw_queue[ac];
2612 if (ieee80211_queue_stopped(&local->hw, q)) {
2613 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2614 return RX_DROP_MONITOR;
2616 skb_set_queue_mapping(skb, q);
2618 if (!--mesh_hdr->ttl) {
2619 if (!is_multicast_ether_addr(hdr->addr1))
2620 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2621 dropped_frames_ttl);
2625 if (!ifmsh->mshcfg.dot11MeshForwarding)
2628 fwd_skb = skb_copy(skb, GFP_ATOMIC);
2630 net_info_ratelimited("%s: failed to clone mesh frame\n",
2635 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2636 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2637 info = IEEE80211_SKB_CB(fwd_skb);
2638 memset(info, 0, sizeof(*info));
2639 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2640 info->control.vif = &rx->sdata->vif;
2641 info->control.jiffies = jiffies;
2642 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2643 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2644 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2645 /* update power mode indication when forwarding */
2646 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2647 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2648 /* mesh power mode flags updated in mesh_nexthop_lookup */
2649 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2651 /* unable to resolve next hop */
2652 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2654 WLAN_REASON_MESH_PATH_NOFORWARD,
2656 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2658 return RX_DROP_MONITOR;
2661 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2662 ieee80211_add_pending_skb(local, fwd_skb);
2664 if (is_multicast_ether_addr(hdr->addr1))
2666 return RX_DROP_MONITOR;
2670 static ieee80211_rx_result debug_noinline
2671 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2673 struct ieee80211_sub_if_data *sdata = rx->sdata;
2674 struct ieee80211_local *local = rx->local;
2675 struct net_device *dev = sdata->dev;
2676 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2677 __le16 fc = hdr->frame_control;
2681 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2684 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2685 return RX_DROP_MONITOR;
2688 * Send unexpected-4addr-frame event to hostapd. For older versions,
2689 * also drop the frame to cooked monitor interfaces.
2691 if (ieee80211_has_a4(hdr->frame_control) &&
2692 sdata->vif.type == NL80211_IFTYPE_AP) {
2694 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2695 cfg80211_rx_unexpected_4addr_frame(
2696 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2697 return RX_DROP_MONITOR;
2700 err = __ieee80211_data_to_8023(rx, &port_control);
2702 return RX_DROP_UNUSABLE;
2704 if (!ieee80211_frame_allowed(rx, fc))
2705 return RX_DROP_MONITOR;
2707 /* directly handle TDLS channel switch requests/responses */
2708 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2709 cpu_to_be16(ETH_P_TDLS))) {
2710 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2712 if (pskb_may_pull(rx->skb,
2713 offsetof(struct ieee80211_tdls_data, u)) &&
2714 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2715 tf->category == WLAN_CATEGORY_TDLS &&
2716 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2717 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2718 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2719 schedule_work(&local->tdls_chsw_work);
2721 rx->sta->rx_stats.packets++;
2727 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2728 unlikely(port_control) && sdata->bss) {
2729 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2737 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2738 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2739 !is_multicast_ether_addr(
2740 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2741 (!local->scanning &&
2742 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
2743 mod_timer(&local->dynamic_ps_timer, jiffies +
2744 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2746 ieee80211_deliver_skb(rx);
2751 static ieee80211_rx_result debug_noinline
2752 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2754 struct sk_buff *skb = rx->skb;
2755 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2756 struct tid_ampdu_rx *tid_agg_rx;
2760 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2763 if (ieee80211_is_back_req(bar->frame_control)) {
2765 __le16 control, start_seq_num;
2766 } __packed bar_data;
2767 struct ieee80211_event event = {
2768 .type = BAR_RX_EVENT,
2772 return RX_DROP_MONITOR;
2774 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2775 &bar_data, sizeof(bar_data)))
2776 return RX_DROP_MONITOR;
2778 tid = le16_to_cpu(bar_data.control) >> 12;
2780 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
2781 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
2782 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
2783 WLAN_BACK_RECIPIENT,
2784 WLAN_REASON_QSTA_REQUIRE_SETUP);
2786 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2788 return RX_DROP_MONITOR;
2790 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2791 event.u.ba.tid = tid;
2792 event.u.ba.ssn = start_seq_num;
2793 event.u.ba.sta = &rx->sta->sta;
2795 /* reset session timer */
2796 if (tid_agg_rx->timeout)
2797 mod_timer(&tid_agg_rx->session_timer,
2798 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2800 spin_lock(&tid_agg_rx->reorder_lock);
2801 /* release stored frames up to start of BAR */
2802 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2803 start_seq_num, frames);
2804 spin_unlock(&tid_agg_rx->reorder_lock);
2806 drv_event_callback(rx->local, rx->sdata, &event);
2813 * After this point, we only want management frames,
2814 * so we can drop all remaining control frames to
2815 * cooked monitor interfaces.
2817 return RX_DROP_MONITOR;
2820 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2821 struct ieee80211_mgmt *mgmt,
2824 struct ieee80211_local *local = sdata->local;
2825 struct sk_buff *skb;
2826 struct ieee80211_mgmt *resp;
2828 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2829 /* Not to own unicast address */
2833 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2834 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2835 /* Not from the current AP or not associated yet. */
2839 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2840 /* Too short SA Query request frame */
2844 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2848 skb_reserve(skb, local->hw.extra_tx_headroom);
2849 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2850 memset(resp, 0, 24);
2851 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2852 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2853 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2854 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2855 IEEE80211_STYPE_ACTION);
2856 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2857 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2858 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2859 memcpy(resp->u.action.u.sa_query.trans_id,
2860 mgmt->u.action.u.sa_query.trans_id,
2861 WLAN_SA_QUERY_TR_ID_LEN);
2863 ieee80211_tx_skb(sdata, skb);
2866 static ieee80211_rx_result debug_noinline
2867 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2869 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2870 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2873 * From here on, look only at management frames.
2874 * Data and control frames are already handled,
2875 * and unknown (reserved) frames are useless.
2877 if (rx->skb->len < 24)
2878 return RX_DROP_MONITOR;
2880 if (!ieee80211_is_mgmt(mgmt->frame_control))
2881 return RX_DROP_MONITOR;
2883 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2884 ieee80211_is_beacon(mgmt->frame_control) &&
2885 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2888 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
2889 sig = status->signal;
2891 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2892 rx->skb->data, rx->skb->len,
2894 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2897 if (ieee80211_drop_unencrypted_mgmt(rx))
2898 return RX_DROP_UNUSABLE;
2903 static ieee80211_rx_result debug_noinline
2904 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2906 struct ieee80211_local *local = rx->local;
2907 struct ieee80211_sub_if_data *sdata = rx->sdata;
2908 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2909 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2910 int len = rx->skb->len;
2912 if (!ieee80211_is_action(mgmt->frame_control))
2915 /* drop too small frames */
2916 if (len < IEEE80211_MIN_ACTION_SIZE)
2917 return RX_DROP_UNUSABLE;
2919 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
2920 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2921 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
2922 return RX_DROP_UNUSABLE;
2924 switch (mgmt->u.action.category) {
2925 case WLAN_CATEGORY_HT:
2926 /* reject HT action frames from stations not supporting HT */
2927 if (!rx->sta->sta.ht_cap.ht_supported)
2930 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2931 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2932 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2933 sdata->vif.type != NL80211_IFTYPE_AP &&
2934 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2937 /* verify action & smps_control/chanwidth are present */
2938 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2941 switch (mgmt->u.action.u.ht_smps.action) {
2942 case WLAN_HT_ACTION_SMPS: {
2943 struct ieee80211_supported_band *sband;
2944 enum ieee80211_smps_mode smps_mode;
2946 /* convert to HT capability */
2947 switch (mgmt->u.action.u.ht_smps.smps_control) {
2948 case WLAN_HT_SMPS_CONTROL_DISABLED:
2949 smps_mode = IEEE80211_SMPS_OFF;
2951 case WLAN_HT_SMPS_CONTROL_STATIC:
2952 smps_mode = IEEE80211_SMPS_STATIC;
2954 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
2955 smps_mode = IEEE80211_SMPS_DYNAMIC;
2961 /* if no change do nothing */
2962 if (rx->sta->sta.smps_mode == smps_mode)
2964 rx->sta->sta.smps_mode = smps_mode;
2966 sband = rx->local->hw.wiphy->bands[status->band];
2968 rate_control_rate_update(local, sband, rx->sta,
2969 IEEE80211_RC_SMPS_CHANGED);
2972 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2973 struct ieee80211_supported_band *sband;
2974 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
2975 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
2977 /* If it doesn't support 40 MHz it can't change ... */
2978 if (!(rx->sta->sta.ht_cap.cap &
2979 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
2982 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
2983 max_bw = IEEE80211_STA_RX_BW_20;
2985 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
2987 /* set cur_max_bandwidth and recalc sta bw */
2988 rx->sta->cur_max_bandwidth = max_bw;
2989 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
2991 if (rx->sta->sta.bandwidth == new_bw)
2994 rx->sta->sta.bandwidth = new_bw;
2995 sband = rx->local->hw.wiphy->bands[status->band];
2997 rate_control_rate_update(local, sband, rx->sta,
2998 IEEE80211_RC_BW_CHANGED);
3006 case WLAN_CATEGORY_PUBLIC:
3007 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3009 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3013 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3015 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3016 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3018 if (len < offsetof(struct ieee80211_mgmt,
3019 u.action.u.ext_chan_switch.variable))
3022 case WLAN_CATEGORY_VHT:
3023 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3024 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3025 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3026 sdata->vif.type != NL80211_IFTYPE_AP &&
3027 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3030 /* verify action code is present */
3031 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3034 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3035 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3036 /* verify opmode is present */
3037 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3041 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3042 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3050 case WLAN_CATEGORY_BACK:
3051 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3052 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3053 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3054 sdata->vif.type != NL80211_IFTYPE_AP &&
3055 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3058 /* verify action_code is present */
3059 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3062 switch (mgmt->u.action.u.addba_req.action_code) {
3063 case WLAN_ACTION_ADDBA_REQ:
3064 if (len < (IEEE80211_MIN_ACTION_SIZE +
3065 sizeof(mgmt->u.action.u.addba_req)))
3068 case WLAN_ACTION_ADDBA_RESP:
3069 if (len < (IEEE80211_MIN_ACTION_SIZE +
3070 sizeof(mgmt->u.action.u.addba_resp)))
3073 case WLAN_ACTION_DELBA:
3074 if (len < (IEEE80211_MIN_ACTION_SIZE +
3075 sizeof(mgmt->u.action.u.delba)))
3083 case WLAN_CATEGORY_SPECTRUM_MGMT:
3084 /* verify action_code is present */
3085 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3088 switch (mgmt->u.action.u.measurement.action_code) {
3089 case WLAN_ACTION_SPCT_MSR_REQ:
3090 if (status->band != NL80211_BAND_5GHZ)
3093 if (len < (IEEE80211_MIN_ACTION_SIZE +
3094 sizeof(mgmt->u.action.u.measurement)))
3097 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3100 ieee80211_process_measurement_req(sdata, mgmt, len);
3102 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3104 if (len < (IEEE80211_MIN_ACTION_SIZE +
3105 sizeof(mgmt->u.action.u.chan_switch)))
3108 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3109 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3110 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3113 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3114 bssid = sdata->u.mgd.bssid;
3115 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3116 bssid = sdata->u.ibss.bssid;
3117 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3122 if (!ether_addr_equal(mgmt->bssid, bssid))
3129 case WLAN_CATEGORY_SA_QUERY:
3130 if (len < (IEEE80211_MIN_ACTION_SIZE +
3131 sizeof(mgmt->u.action.u.sa_query)))
3134 switch (mgmt->u.action.u.sa_query.action) {
3135 case WLAN_ACTION_SA_QUERY_REQUEST:
3136 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3138 ieee80211_process_sa_query_req(sdata, mgmt, len);
3142 case WLAN_CATEGORY_SELF_PROTECTED:
3143 if (len < (IEEE80211_MIN_ACTION_SIZE +
3144 sizeof(mgmt->u.action.u.self_prot.action_code)))
3147 switch (mgmt->u.action.u.self_prot.action_code) {
3148 case WLAN_SP_MESH_PEERING_OPEN:
3149 case WLAN_SP_MESH_PEERING_CLOSE:
3150 case WLAN_SP_MESH_PEERING_CONFIRM:
3151 if (!ieee80211_vif_is_mesh(&sdata->vif))
3153 if (sdata->u.mesh.user_mpm)
3154 /* userspace handles this frame */
3157 case WLAN_SP_MGK_INFORM:
3158 case WLAN_SP_MGK_ACK:
3159 if (!ieee80211_vif_is_mesh(&sdata->vif))
3164 case WLAN_CATEGORY_MESH_ACTION:
3165 if (len < (IEEE80211_MIN_ACTION_SIZE +
3166 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3169 if (!ieee80211_vif_is_mesh(&sdata->vif))
3171 if (mesh_action_is_path_sel(mgmt) &&
3172 !mesh_path_sel_is_hwmp(sdata))
3180 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3181 /* will return in the next handlers */
3186 rx->sta->rx_stats.packets++;
3187 dev_kfree_skb(rx->skb);
3191 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
3192 skb_queue_tail(&sdata->skb_queue, rx->skb);
3193 ieee80211_queue_work(&local->hw, &sdata->work);
3195 rx->sta->rx_stats.packets++;
3199 static ieee80211_rx_result debug_noinline
3200 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3202 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3205 /* skip known-bad action frames and return them in the next handler */
3206 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3210 * Getting here means the kernel doesn't know how to handle
3211 * it, but maybe userspace does ... include returned frames
3212 * so userspace can register for those to know whether ones
3213 * it transmitted were processed or returned.
3216 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
3217 sig = status->signal;
3219 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
3220 rx->skb->data, rx->skb->len, 0)) {
3222 rx->sta->rx_stats.packets++;
3223 dev_kfree_skb(rx->skb);
3230 static ieee80211_rx_result debug_noinline
3231 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3233 struct ieee80211_local *local = rx->local;
3234 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3235 struct sk_buff *nskb;
3236 struct ieee80211_sub_if_data *sdata = rx->sdata;
3237 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3239 if (!ieee80211_is_action(mgmt->frame_control))
3243 * For AP mode, hostapd is responsible for handling any action
3244 * frames that we didn't handle, including returning unknown
3245 * ones. For all other modes we will return them to the sender,
3246 * setting the 0x80 bit in the action category, as required by
3247 * 802.11-2012 9.24.4.
3248 * Newer versions of hostapd shall also use the management frame
3249 * registration mechanisms, but older ones still use cooked
3250 * monitor interfaces so push all frames there.
3252 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3253 (sdata->vif.type == NL80211_IFTYPE_AP ||
3254 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3255 return RX_DROP_MONITOR;
3257 if (is_multicast_ether_addr(mgmt->da))
3258 return RX_DROP_MONITOR;
3260 /* do not return rejected action frames */
3261 if (mgmt->u.action.category & 0x80)
3262 return RX_DROP_UNUSABLE;
3264 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3267 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3269 nmgmt->u.action.category |= 0x80;
3270 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3271 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3273 memset(nskb->cb, 0, sizeof(nskb->cb));
3275 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3276 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3278 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3279 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3280 IEEE80211_TX_CTL_NO_CCK_RATE;
3281 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3283 local->hw.offchannel_tx_hw_queue;
3286 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3289 dev_kfree_skb(rx->skb);
3293 static ieee80211_rx_result debug_noinline
3294 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3296 struct ieee80211_sub_if_data *sdata = rx->sdata;
3297 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3300 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3302 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3303 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3304 sdata->vif.type != NL80211_IFTYPE_OCB &&
3305 sdata->vif.type != NL80211_IFTYPE_STATION)
3306 return RX_DROP_MONITOR;
3309 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3310 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3311 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3312 /* process for all: mesh, mlme, ibss */
3314 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3315 if (is_multicast_ether_addr(mgmt->da) &&
3316 !is_broadcast_ether_addr(mgmt->da))
3317 return RX_DROP_MONITOR;
3319 /* process only for station/IBSS */
3320 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3321 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3322 return RX_DROP_MONITOR;
3324 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3325 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3326 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3327 if (is_multicast_ether_addr(mgmt->da) &&
3328 !is_broadcast_ether_addr(mgmt->da))
3329 return RX_DROP_MONITOR;
3331 /* process only for station */
3332 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3333 return RX_DROP_MONITOR;
3335 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3336 /* process only for ibss and mesh */
3337 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3338 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3339 return RX_DROP_MONITOR;
3342 return RX_DROP_MONITOR;
3345 /* queue up frame and kick off work to process it */
3346 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
3347 skb_queue_tail(&sdata->skb_queue, rx->skb);
3348 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3350 rx->sta->rx_stats.packets++;
3355 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3356 struct ieee80211_rate *rate)
3358 struct ieee80211_sub_if_data *sdata;
3359 struct ieee80211_local *local = rx->local;
3360 struct sk_buff *skb = rx->skb, *skb2;
3361 struct net_device *prev_dev = NULL;
3362 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3363 int needed_headroom;
3366 * If cooked monitor has been processed already, then
3367 * don't do it again. If not, set the flag.
3369 if (rx->flags & IEEE80211_RX_CMNTR)
3371 rx->flags |= IEEE80211_RX_CMNTR;
3373 /* If there are no cooked monitor interfaces, just free the SKB */
3374 if (!local->cooked_mntrs)
3377 /* vendor data is long removed here */
3378 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3379 /* room for the radiotap header based on driver features */
3380 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3382 if (skb_headroom(skb) < needed_headroom &&
3383 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3386 /* prepend radiotap information */
3387 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3390 skb_reset_mac_header(skb);
3391 skb->ip_summed = CHECKSUM_UNNECESSARY;
3392 skb->pkt_type = PACKET_OTHERHOST;
3393 skb->protocol = htons(ETH_P_802_2);
3395 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3396 if (!ieee80211_sdata_running(sdata))
3399 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3400 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3404 skb2 = skb_clone(skb, GFP_ATOMIC);
3406 skb2->dev = prev_dev;
3407 netif_receive_skb(skb2);
3411 prev_dev = sdata->dev;
3412 ieee80211_rx_stats(sdata->dev, skb->len);
3416 skb->dev = prev_dev;
3417 netif_receive_skb(skb);
3425 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3426 ieee80211_rx_result res)
3429 case RX_DROP_MONITOR:
3430 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3432 rx->sta->rx_stats.dropped++;
3435 struct ieee80211_rate *rate = NULL;
3436 struct ieee80211_supported_band *sband;
3437 struct ieee80211_rx_status *status;
3439 status = IEEE80211_SKB_RXCB((rx->skb));
3441 sband = rx->local->hw.wiphy->bands[status->band];
3442 if (!(status->flag & RX_FLAG_HT) &&
3443 !(status->flag & RX_FLAG_VHT))
3444 rate = &sband->bitrates[status->rate_idx];
3446 ieee80211_rx_cooked_monitor(rx, rate);
3449 case RX_DROP_UNUSABLE:
3450 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3452 rx->sta->rx_stats.dropped++;
3453 dev_kfree_skb(rx->skb);
3456 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3461 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3462 struct sk_buff_head *frames)
3464 ieee80211_rx_result res = RX_DROP_MONITOR;
3465 struct sk_buff *skb;
3467 #define CALL_RXH(rxh) \
3470 if (res != RX_CONTINUE) \
3474 /* Lock here to avoid hitting all of the data used in the RX
3475 * path (e.g. key data, station data, ...) concurrently when
3476 * a frame is released from the reorder buffer due to timeout
3477 * from the timer, potentially concurrently with RX from the
3480 spin_lock_bh(&rx->local->rx_path_lock);
3482 while ((skb = __skb_dequeue(frames))) {
3484 * all the other fields are valid across frames
3485 * that belong to an aMPDU since they are on the
3486 * same TID from the same station
3490 CALL_RXH(ieee80211_rx_h_check_more_data);
3491 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3492 CALL_RXH(ieee80211_rx_h_sta_process);
3493 CALL_RXH(ieee80211_rx_h_decrypt);
3494 CALL_RXH(ieee80211_rx_h_defragment);
3495 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3496 /* must be after MMIC verify so header is counted in MPDU mic */
3497 #ifdef CONFIG_MAC80211_MESH
3498 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3499 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3501 CALL_RXH(ieee80211_rx_h_amsdu);
3502 CALL_RXH(ieee80211_rx_h_data);
3504 /* special treatment -- needs the queue */
3505 res = ieee80211_rx_h_ctrl(rx, frames);
3506 if (res != RX_CONTINUE)
3509 CALL_RXH(ieee80211_rx_h_mgmt_check);
3510 CALL_RXH(ieee80211_rx_h_action);
3511 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3512 CALL_RXH(ieee80211_rx_h_action_return);
3513 CALL_RXH(ieee80211_rx_h_mgmt);
3516 ieee80211_rx_handlers_result(rx, res);
3521 spin_unlock_bh(&rx->local->rx_path_lock);
3524 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3526 struct sk_buff_head reorder_release;
3527 ieee80211_rx_result res = RX_DROP_MONITOR;
3529 __skb_queue_head_init(&reorder_release);
3531 #define CALL_RXH(rxh) \
3534 if (res != RX_CONTINUE) \
3538 CALL_RXH(ieee80211_rx_h_check_dup);
3539 CALL_RXH(ieee80211_rx_h_check);
3541 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3543 ieee80211_rx_handlers(rx, &reorder_release);
3547 ieee80211_rx_handlers_result(rx, res);
3553 * This function makes calls into the RX path, therefore
3554 * it has to be invoked under RCU read lock.
3556 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3558 struct sk_buff_head frames;
3559 struct ieee80211_rx_data rx = {
3561 .sdata = sta->sdata,
3562 .local = sta->local,
3563 /* This is OK -- must be QoS data frame */
3564 .security_idx = tid,
3566 .napi = NULL, /* must be NULL to not have races */
3568 struct tid_ampdu_rx *tid_agg_rx;
3570 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3574 __skb_queue_head_init(&frames);
3576 spin_lock(&tid_agg_rx->reorder_lock);
3577 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3578 spin_unlock(&tid_agg_rx->reorder_lock);
3580 if (!skb_queue_empty(&frames)) {
3581 struct ieee80211_event event = {
3582 .type = BA_FRAME_TIMEOUT,
3584 .u.ba.sta = &sta->sta,
3586 drv_event_callback(rx.local, rx.sdata, &event);
3589 ieee80211_rx_handlers(&rx, &frames);
3592 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3593 u16 ssn, u64 filtered,
3596 struct sta_info *sta;
3597 struct tid_ampdu_rx *tid_agg_rx;
3598 struct sk_buff_head frames;
3599 struct ieee80211_rx_data rx = {
3600 /* This is OK -- must be QoS data frame */
3601 .security_idx = tid,
3606 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3609 __skb_queue_head_init(&frames);
3611 sta = container_of(pubsta, struct sta_info, sta);
3614 rx.sdata = sta->sdata;
3615 rx.local = sta->local;
3618 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3622 spin_lock_bh(&tid_agg_rx->reorder_lock);
3624 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3627 /* release all frames in the reorder buffer */
3628 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3629 IEEE80211_SN_MODULO;
3630 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3632 /* update ssn to match received ssn */
3633 tid_agg_rx->head_seq_num = ssn;
3635 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3639 /* handle the case that received ssn is behind the mac ssn.
3640 * it can be tid_agg_rx->buf_size behind and still be valid */
3641 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3642 if (diff >= tid_agg_rx->buf_size) {
3643 tid_agg_rx->reorder_buf_filtered = 0;
3646 filtered = filtered >> diff;
3650 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3651 int index = (ssn + i) % tid_agg_rx->buf_size;
3653 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3654 if (filtered & BIT_ULL(i))
3655 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3658 /* now process also frames that the filter marking released */
3659 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3662 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3664 ieee80211_rx_handlers(&rx, &frames);
3669 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3671 /* main receive path */
3673 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3675 struct ieee80211_sub_if_data *sdata = rx->sdata;
3676 struct sk_buff *skb = rx->skb;
3677 struct ieee80211_hdr *hdr = (void *)skb->data;
3678 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3679 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3680 int multicast = is_multicast_ether_addr(hdr->addr1);
3682 switch (sdata->vif.type) {
3683 case NL80211_IFTYPE_STATION:
3684 if (!bssid && !sdata->u.mgd.use_4addr)
3686 if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
3690 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3691 case NL80211_IFTYPE_ADHOC:
3694 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3695 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
3696 !is_valid_ether_addr(hdr->addr2))
3698 if (ieee80211_is_beacon(hdr->frame_control))
3700 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3703 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3707 if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
3708 rate_idx = 0; /* TODO: HT/VHT rates */
3710 rate_idx = status->rate_idx;
3711 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3715 case NL80211_IFTYPE_OCB:
3718 if (!ieee80211_is_data_present(hdr->frame_control))
3720 if (!is_broadcast_ether_addr(bssid))
3723 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3727 if (status->flag & RX_FLAG_HT)
3728 rate_idx = 0; /* TODO: HT rates */
3730 rate_idx = status->rate_idx;
3731 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3735 case NL80211_IFTYPE_MESH_POINT:
3736 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
3740 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3741 case NL80211_IFTYPE_AP_VLAN:
3742 case NL80211_IFTYPE_AP:
3744 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3746 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3748 * Accept public action frames even when the
3749 * BSSID doesn't match, this is used for P2P
3750 * and location updates. Note that mac80211
3751 * itself never looks at these frames.
3754 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3756 if (ieee80211_is_public_action(hdr, skb->len))
3758 return ieee80211_is_beacon(hdr->frame_control);
3761 if (!ieee80211_has_tods(hdr->frame_control)) {
3762 /* ignore data frames to TDLS-peers */
3763 if (ieee80211_is_data(hdr->frame_control))
3765 /* ignore action frames to TDLS-peers */
3766 if (ieee80211_is_action(hdr->frame_control) &&
3767 !is_broadcast_ether_addr(bssid) &&
3768 !ether_addr_equal(bssid, hdr->addr1))
3773 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3774 * the BSSID - we've checked that already but may have accepted
3775 * the wildcard (ff:ff:ff:ff:ff:ff).
3778 * The BSSID of the Data frame is determined as follows:
3779 * a) If the STA is contained within an AP or is associated
3780 * with an AP, the BSSID is the address currently in use
3781 * by the STA contained in the AP.
3783 * So we should not accept data frames with an address that's
3786 * Accepting it also opens a security problem because stations
3787 * could encrypt it with the GTK and inject traffic that way.
3789 if (ieee80211_is_data(hdr->frame_control) && multicast)
3793 case NL80211_IFTYPE_WDS:
3794 if (bssid || !ieee80211_is_data(hdr->frame_control))
3796 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3797 case NL80211_IFTYPE_P2P_DEVICE:
3798 return ieee80211_is_public_action(hdr, skb->len) ||
3799 ieee80211_is_probe_req(hdr->frame_control) ||
3800 ieee80211_is_probe_resp(hdr->frame_control) ||
3801 ieee80211_is_beacon(hdr->frame_control);
3802 case NL80211_IFTYPE_NAN:
3803 /* Currently no frames on NAN interface are allowed */
3813 void ieee80211_check_fast_rx(struct sta_info *sta)
3815 struct ieee80211_sub_if_data *sdata = sta->sdata;
3816 struct ieee80211_local *local = sdata->local;
3817 struct ieee80211_key *key;
3818 struct ieee80211_fast_rx fastrx = {
3820 .vif_type = sdata->vif.type,
3821 .control_port_protocol = sdata->control_port_protocol,
3822 }, *old, *new = NULL;
3823 bool assign = false;
3825 /* use sparse to check that we don't return without updating */
3826 __acquire(check_fast_rx);
3828 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
3829 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
3830 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
3831 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
3833 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
3835 /* fast-rx doesn't do reordering */
3836 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
3837 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
3840 switch (sdata->vif.type) {
3841 case NL80211_IFTYPE_STATION:
3842 /* 4-addr is harder to deal with, later maybe */
3843 if (sdata->u.mgd.use_4addr)
3845 /* software powersave is a huge mess, avoid all of it */
3846 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
3848 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3849 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3851 if (sta->sta.tdls) {
3852 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3853 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3854 fastrx.expected_ds_bits = 0;
3856 fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
3857 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3858 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3859 fastrx.expected_ds_bits =
3860 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3863 case NL80211_IFTYPE_AP_VLAN:
3864 case NL80211_IFTYPE_AP:
3865 /* parallel-rx requires this, at least with calls to
3866 * ieee80211_sta_ps_transition()
3868 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
3870 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3871 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3872 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
3874 fastrx.internal_forward =
3875 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
3876 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
3877 !sdata->u.vlan.sta);
3883 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3887 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
3889 key = rcu_dereference(sdata->default_unicast_key);
3891 switch (key->conf.cipher) {
3892 case WLAN_CIPHER_SUITE_TKIP:
3893 /* we don't want to deal with MMIC in fast-rx */
3895 case WLAN_CIPHER_SUITE_CCMP:
3896 case WLAN_CIPHER_SUITE_CCMP_256:
3897 case WLAN_CIPHER_SUITE_GCMP:
3898 case WLAN_CIPHER_SUITE_GCMP_256:
3901 /* we also don't want to deal with WEP or cipher scheme
3902 * since those require looking up the key idx in the
3903 * frame, rather than assuming the PTK is used
3904 * (we need to revisit this once we implement the real
3905 * PTK index, which is now valid in the spec, but we
3906 * haven't implemented that part yet)
3912 fastrx.icv_len = key->conf.icv_len;
3919 __release(check_fast_rx);
3922 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
3924 spin_lock_bh(&sta->lock);
3925 old = rcu_dereference_protected(sta->fast_rx, true);
3926 rcu_assign_pointer(sta->fast_rx, new);
3927 spin_unlock_bh(&sta->lock);
3930 kfree_rcu(old, rcu_head);
3933 void ieee80211_clear_fast_rx(struct sta_info *sta)
3935 struct ieee80211_fast_rx *old;
3937 spin_lock_bh(&sta->lock);
3938 old = rcu_dereference_protected(sta->fast_rx, true);
3939 RCU_INIT_POINTER(sta->fast_rx, NULL);
3940 spin_unlock_bh(&sta->lock);
3943 kfree_rcu(old, rcu_head);
3946 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
3948 struct ieee80211_local *local = sdata->local;
3949 struct sta_info *sta;
3951 lockdep_assert_held(&local->sta_mtx);
3953 list_for_each_entry(sta, &local->sta_list, list) {
3954 if (sdata != sta->sdata &&
3955 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3957 ieee80211_check_fast_rx(sta);
3961 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
3963 struct ieee80211_local *local = sdata->local;
3965 mutex_lock(&local->sta_mtx);
3966 __ieee80211_check_fast_rx_iface(sdata);
3967 mutex_unlock(&local->sta_mtx);
3970 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
3971 struct ieee80211_fast_rx *fast_rx)
3973 struct sk_buff *skb = rx->skb;
3974 struct ieee80211_hdr *hdr = (void *)skb->data;
3975 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3976 struct sta_info *sta = rx->sta;
3977 int orig_len = skb->len;
3978 int snap_offs = ieee80211_hdrlen(hdr->frame_control);
3980 u8 snap[sizeof(rfc1042_header)];
3982 } *payload __aligned(2);
3986 } addrs __aligned(2);
3987 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
3989 if (fast_rx->uses_rss)
3990 stats = this_cpu_ptr(sta->pcpu_rx_stats);
3992 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
3993 * to a common data structure; drivers can implement that per queue
3994 * but we don't have that information in mac80211
3996 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
3999 #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4001 /* If using encryption, we also need to have:
4002 * - PN_VALIDATED: similar, but the implementation is tricky
4003 * - DECRYPTED: necessary for PN_VALIDATED
4006 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4009 /* we don't deal with A-MSDU deaggregation here */
4010 if (status->rx_flags & IEEE80211_RX_AMSDU)
4013 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4016 if (unlikely(ieee80211_is_frag(hdr)))
4019 /* Since our interface address cannot be multicast, this
4020 * implicitly also rejects multicast frames without the
4023 * We shouldn't get any *data* frames not addressed to us
4024 * (AP mode will accept multicast *management* frames), but
4025 * punting here will make it go through the full checks in
4026 * ieee80211_accept_frame().
4028 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4031 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4032 IEEE80211_FCTL_TODS)) !=
4033 fast_rx->expected_ds_bits)
4036 /* assign the key to drop unencrypted frames (later)
4037 * and strip the IV/MIC if necessary
4039 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4040 /* GCMP header length is the same */
4041 snap_offs += IEEE80211_CCMP_HDR_LEN;
4044 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4046 payload = (void *)(skb->data + snap_offs);
4048 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4051 /* Don't handle these here since they require special code.
4052 * Accept AARP and IPX even though they should come with a
4053 * bridge-tunnel header - but if we get them this way then
4054 * there's little point in discarding them.
4056 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4057 payload->proto == fast_rx->control_port_protocol))
4060 /* after this point, don't punt to the slowpath! */
4062 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4063 pskb_trim(skb, skb->len - fast_rx->icv_len))
4066 if (unlikely(fast_rx->sta_notify)) {
4067 ieee80211_sta_rx_notify(rx->sdata, hdr);
4068 fast_rx->sta_notify = false;
4071 /* statistics part of ieee80211_rx_h_sta_process() */
4072 stats->last_rx = jiffies;
4073 stats->last_rate = sta_stats_encode_rate(status);
4078 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4079 stats->last_signal = status->signal;
4080 if (!fast_rx->uses_rss)
4081 ewma_signal_add(&sta->rx_stats_avg.signal,
4085 if (status->chains) {
4088 stats->chains = status->chains;
4089 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4090 int signal = status->chain_signal[i];
4092 if (!(status->chains & BIT(i)))
4095 stats->chain_signal_last[i] = signal;
4096 if (!fast_rx->uses_rss)
4097 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4101 /* end of statistics */
4103 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4106 /* do the header conversion - first grab the addresses */
4107 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4108 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4109 /* remove the SNAP but leave the ethertype */
4110 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4111 /* push the addresses in front */
4112 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4114 skb->dev = fast_rx->dev;
4116 ieee80211_rx_stats(fast_rx->dev, skb->len);
4118 /* The seqno index has the same property as needed
4119 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4120 * for non-QoS-data frames. Here we know it's a data
4121 * frame, so count MSDUs.
4123 u64_stats_update_begin(&stats->syncp);
4124 stats->msdu[rx->seqno_idx]++;
4125 stats->bytes += orig_len;
4126 u64_stats_update_end(&stats->syncp);
4128 if (fast_rx->internal_forward) {
4129 struct sk_buff *xmit_skb = NULL;
4130 bool multicast = is_multicast_ether_addr(skb->data);
4133 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4134 } else if (sta_info_get(rx->sdata, skb->data)) {
4141 * Send to wireless media and increase priority by 256
4142 * to keep the received priority instead of
4143 * reclassifying the frame (see cfg80211_classify8021d).
4145 xmit_skb->priority += 256;
4146 xmit_skb->protocol = htons(ETH_P_802_3);
4147 skb_reset_network_header(xmit_skb);
4148 skb_reset_mac_header(xmit_skb);
4149 dev_queue_xmit(xmit_skb);
4156 /* deliver to local stack */
4157 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4158 memset(skb->cb, 0, sizeof(skb->cb));
4160 napi_gro_receive(rx->napi, skb);
4162 netif_receive_skb(skb);
4172 * This function returns whether or not the SKB
4173 * was destined for RX processing or not, which,
4174 * if consume is true, is equivalent to whether
4175 * or not the skb was consumed.
4177 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4178 struct sk_buff *skb, bool consume)
4180 struct ieee80211_local *local = rx->local;
4181 struct ieee80211_sub_if_data *sdata = rx->sdata;
4185 /* See if we can do fast-rx; if we have to copy we already lost,
4186 * so punt in that case. We should never have to deliver a data
4187 * frame to multiple interfaces anyway.
4189 * We skip the ieee80211_accept_frame() call and do the necessary
4190 * checking inside ieee80211_invoke_fast_rx().
4192 if (consume && rx->sta) {
4193 struct ieee80211_fast_rx *fast_rx;
4195 fast_rx = rcu_dereference(rx->sta->fast_rx);
4196 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4200 if (!ieee80211_accept_frame(rx))
4204 skb = skb_copy(skb, GFP_ATOMIC);
4206 if (net_ratelimit())
4207 wiphy_debug(local->hw.wiphy,
4208 "failed to copy skb for %s\n",
4216 ieee80211_invoke_rx_handlers(rx);
4221 * This is the actual Rx frames handler. as it belongs to Rx path it must
4222 * be called with rcu_read_lock protection.
4224 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4225 struct ieee80211_sta *pubsta,
4226 struct sk_buff *skb,
4227 struct napi_struct *napi)
4229 struct ieee80211_local *local = hw_to_local(hw);
4230 struct ieee80211_sub_if_data *sdata;
4231 struct ieee80211_hdr *hdr;
4233 struct ieee80211_rx_data rx;
4234 struct ieee80211_sub_if_data *prev;
4235 struct rhlist_head *tmp;
4238 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4239 memset(&rx, 0, sizeof(rx));
4244 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4245 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4247 if (ieee80211_is_mgmt(fc)) {
4248 /* drop frame if too short for header */
4249 if (skb->len < ieee80211_hdrlen(fc))
4252 err = skb_linearize(skb);
4254 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4262 hdr = (struct ieee80211_hdr *)skb->data;
4263 ieee80211_parse_qos(&rx);
4264 ieee80211_verify_alignment(&rx);
4266 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4267 ieee80211_is_beacon(hdr->frame_control)))
4268 ieee80211_scan_rx(local, skb);
4270 if (ieee80211_is_data(fc)) {
4271 struct sta_info *sta, *prev_sta;
4274 rx.sta = container_of(pubsta, struct sta_info, sta);
4275 rx.sdata = rx.sta->sdata;
4276 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4283 for_each_sta_info(local, hdr->addr2, sta, tmp) {
4290 rx.sdata = prev_sta->sdata;
4291 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4298 rx.sdata = prev_sta->sdata;
4300 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4308 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4309 if (!ieee80211_sdata_running(sdata))
4312 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4313 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4317 * frame is destined for this interface, but if it's
4318 * not also for the previous one we handle that after
4319 * the loop to avoid copying the SKB once too much
4327 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4329 ieee80211_prepare_and_rx_handle(&rx, skb, false);
4335 rx.sta = sta_info_get_bss(prev, hdr->addr2);
4338 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4347 * This is the receive path handler. It is called by a low level driver when an
4348 * 802.11 MPDU is received from the hardware.
4350 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4351 struct sk_buff *skb, struct napi_struct *napi)
4353 struct ieee80211_local *local = hw_to_local(hw);
4354 struct ieee80211_rate *rate = NULL;
4355 struct ieee80211_supported_band *sband;
4356 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4358 WARN_ON_ONCE(softirq_count() == 0);
4360 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4363 sband = local->hw.wiphy->bands[status->band];
4364 if (WARN_ON(!sband))
4368 * If we're suspending, it is possible although not too likely
4369 * that we'd be receiving frames after having already partially
4370 * quiesced the stack. We can't process such frames then since
4371 * that might, for example, cause stations to be added or other
4372 * driver callbacks be invoked.
4374 if (unlikely(local->quiescing || local->suspended))
4377 /* We might be during a HW reconfig, prevent Rx for the same reason */
4378 if (unlikely(local->in_reconfig))
4382 * The same happens when we're not even started,
4383 * but that's worth a warning.
4385 if (WARN_ON(!local->started))
4388 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4390 * Validate the rate, unless a PLCP error means that
4391 * we probably can't have a valid rate here anyway.
4394 if (status->flag & RX_FLAG_HT) {
4396 * rate_idx is MCS index, which can be [0-76]
4399 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4401 * Anything else would be some sort of driver or
4402 * hardware error. The driver should catch hardware
4405 if (WARN(status->rate_idx > 76,
4406 "Rate marked as an HT rate but passed "
4407 "status->rate_idx is not "
4408 "an MCS index [0-76]: %d (0x%02x)\n",
4412 } else if (status->flag & RX_FLAG_VHT) {
4413 if (WARN_ONCE(status->rate_idx > 9 ||
4415 status->vht_nss > 8,
4416 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4417 status->rate_idx, status->vht_nss))
4420 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4422 rate = &sband->bitrates[status->rate_idx];
4426 status->rx_flags = 0;
4429 * key references and virtual interfaces are protected using RCU
4430 * and this requires that we are in a read-side RCU section during
4431 * receive processing
4436 * Frames with failed FCS/PLCP checksum are not returned,
4437 * all other frames are returned without radiotap header
4438 * if it was previously present.
4439 * Also, frames with less than 16 bytes are dropped.
4441 skb = ieee80211_rx_monitor(local, skb, rate);
4447 ieee80211_tpt_led_trig_rx(local,
4448 ((struct ieee80211_hdr *)skb->data)->frame_control,
4451 __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
4459 EXPORT_SYMBOL(ieee80211_rx_napi);
4461 /* This is a version of the rx handler that can be called from hard irq
4462 * context. Post the skb on the queue and schedule the tasklet */
4463 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
4465 struct ieee80211_local *local = hw_to_local(hw);
4467 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4469 skb->pkt_type = IEEE80211_RX_MSG;
4470 skb_queue_tail(&local->skb_queue, skb);
4471 tasklet_schedule(&local->tasklet);
4473 EXPORT_SYMBOL(ieee80211_rx_irqsafe);