2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/jiffies.h>
14 #include <linux/slab.h>
15 #include <linux/kernel.h>
16 #include <linux/skbuff.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/rcupdate.h>
20 #include <linux/export.h>
21 #include <net/mac80211.h>
22 #include <net/ieee80211_radiotap.h>
23 #include <asm/unaligned.h>
25 #include "ieee80211_i.h"
26 #include "driver-ops.h"
35 static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
37 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
39 u64_stats_update_begin(&tstats->syncp);
41 tstats->rx_bytes += len;
42 u64_stats_update_end(&tstats->syncp);
46 * monitor mode reception
48 * This function cleans up the SKB, i.e. it removes all the stuff
49 * only useful for monitoring.
51 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
53 unsigned int rtap_vendor_space)
55 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
56 if (likely(skb->len > FCS_LEN))
57 __pskb_trim(skb, skb->len - FCS_LEN);
66 __pskb_pull(skb, rtap_vendor_space);
71 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
72 unsigned int rtap_vendor_space)
74 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
75 struct ieee80211_hdr *hdr;
77 hdr = (void *)(skb->data + rtap_vendor_space);
79 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
80 RX_FLAG_FAILED_PLCP_CRC |
81 RX_FLAG_AMPDU_IS_ZEROLEN))
84 if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space))
87 if (ieee80211_is_ctl(hdr->frame_control) &&
88 !ieee80211_is_pspoll(hdr->frame_control) &&
89 !ieee80211_is_back_req(hdr->frame_control))
96 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
97 struct ieee80211_rx_status *status,
102 /* always present fields */
103 len = sizeof(struct ieee80211_radiotap_header) + 8;
105 /* allocate extra bitmaps */
107 len += 4 * hweight8(status->chains);
109 if (ieee80211_have_rx_timestamp(status)) {
113 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
116 /* antenna field, if we don't have per-chain info */
120 /* padding for RX_FLAGS if necessary */
123 if (status->flag & RX_FLAG_HT) /* HT info */
126 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
131 if (status->flag & RX_FLAG_VHT) {
136 if (status->chains) {
137 /* antenna and antenna signal fields */
138 len += 2 * hweight8(status->chains);
141 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
142 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
144 /* vendor presence bitmap */
146 /* alignment for fixed 6-byte vendor data header */
148 /* vendor data header */
150 if (WARN_ON(rtap->align == 0))
152 len = ALIGN(len, rtap->align);
153 len += rtap->len + rtap->pad;
160 * ieee80211_add_rx_radiotap_header - add radiotap header
162 * add a radiotap header containing all the fields which the hardware provided.
165 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
167 struct ieee80211_rate *rate,
168 int rtap_len, bool has_fcs)
170 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
171 struct ieee80211_radiotap_header *rthdr;
176 u16 channel_flags = 0;
178 unsigned long chains = status->chains;
179 struct ieee80211_vendor_radiotap rtap = {};
181 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
182 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
183 /* rtap.len and rtap.pad are undone immediately */
184 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
188 if (!(has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)))
191 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
192 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
193 it_present = &rthdr->it_present;
195 /* radiotap header, set always present flags */
196 rthdr->it_len = cpu_to_le16(rtap_len);
197 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
198 BIT(IEEE80211_RADIOTAP_CHANNEL) |
199 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
202 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
204 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
206 BIT(IEEE80211_RADIOTAP_EXT) |
207 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
208 put_unaligned_le32(it_present_val, it_present);
210 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
211 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
214 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
215 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
216 BIT(IEEE80211_RADIOTAP_EXT);
217 put_unaligned_le32(it_present_val, it_present);
219 it_present_val = rtap.present;
222 put_unaligned_le32(it_present_val, it_present);
224 pos = (void *)(it_present + 1);
226 /* the order of the following fields is important */
228 /* IEEE80211_RADIOTAP_TSFT */
229 if (ieee80211_have_rx_timestamp(status)) {
231 while ((pos - (u8 *)rthdr) & 7)
234 ieee80211_calculate_rx_timestamp(local, status,
237 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
241 /* IEEE80211_RADIOTAP_FLAGS */
242 if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
243 *pos |= IEEE80211_RADIOTAP_F_FCS;
244 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
245 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
246 if (status->flag & RX_FLAG_SHORTPRE)
247 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
250 /* IEEE80211_RADIOTAP_RATE */
251 if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
253 * Without rate information don't add it. If we have,
254 * MCS information is a separate field in radiotap,
255 * added below. The byte here is needed as padding
256 * for the channel though, so initialise it to 0.
261 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
262 if (status->flag & RX_FLAG_10MHZ)
264 else if (status->flag & RX_FLAG_5MHZ)
266 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
270 /* IEEE80211_RADIOTAP_CHANNEL */
271 put_unaligned_le16(status->freq, pos);
273 if (status->flag & RX_FLAG_10MHZ)
274 channel_flags |= IEEE80211_CHAN_HALF;
275 else if (status->flag & RX_FLAG_5MHZ)
276 channel_flags |= IEEE80211_CHAN_QUARTER;
278 if (status->band == IEEE80211_BAND_5GHZ)
279 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
280 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
281 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
282 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
283 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
285 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
287 channel_flags |= IEEE80211_CHAN_2GHZ;
288 put_unaligned_le16(channel_flags, pos);
291 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
292 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM &&
293 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
294 *pos = status->signal;
296 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
300 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
302 if (!status->chains) {
303 /* IEEE80211_RADIOTAP_ANTENNA */
304 *pos = status->antenna;
308 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
310 /* IEEE80211_RADIOTAP_RX_FLAGS */
311 /* ensure 2 byte alignment for the 2 byte field as required */
312 if ((pos - (u8 *)rthdr) & 1)
314 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
315 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
316 put_unaligned_le16(rx_flags, pos);
319 if (status->flag & RX_FLAG_HT) {
322 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
323 *pos++ = local->hw.radiotap_mcs_details;
325 if (status->flag & RX_FLAG_SHORT_GI)
326 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
327 if (status->flag & RX_FLAG_40MHZ)
328 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
329 if (status->flag & RX_FLAG_HT_GF)
330 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
331 if (status->flag & RX_FLAG_LDPC)
332 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
333 stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
334 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
336 *pos++ = status->rate_idx;
339 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
342 /* ensure 4 byte alignment */
343 while ((pos - (u8 *)rthdr) & 3)
346 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
347 put_unaligned_le32(status->ampdu_reference, pos);
349 if (status->flag & RX_FLAG_AMPDU_REPORT_ZEROLEN)
350 flags |= IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN;
351 if (status->flag & RX_FLAG_AMPDU_IS_ZEROLEN)
352 flags |= IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN;
353 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
354 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
355 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
356 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
357 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
358 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
359 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
360 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
361 put_unaligned_le16(flags, pos);
363 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
364 *pos++ = status->ampdu_delimiter_crc;
370 if (status->flag & RX_FLAG_VHT) {
371 u16 known = local->hw.radiotap_vht_details;
373 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
374 put_unaligned_le16(known, pos);
377 if (status->flag & RX_FLAG_SHORT_GI)
378 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
379 /* in VHT, STBC is binary */
380 if (status->flag & RX_FLAG_STBC_MASK)
381 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
382 if (status->vht_flag & RX_VHT_FLAG_BF)
383 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
386 if (status->vht_flag & RX_VHT_FLAG_80MHZ)
388 else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
390 else if (status->flag & RX_FLAG_40MHZ)
395 *pos = (status->rate_idx << 4) | status->vht_nss;
398 if (status->flag & RX_FLAG_LDPC)
399 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
407 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
408 *pos++ = status->chain_signal[chain];
412 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
413 /* ensure 2 byte alignment for the vendor field as required */
414 if ((pos - (u8 *)rthdr) & 1)
416 *pos++ = rtap.oui[0];
417 *pos++ = rtap.oui[1];
418 *pos++ = rtap.oui[2];
420 put_unaligned_le16(rtap.len, pos);
422 /* align the actual payload as requested */
423 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
425 /* data (and possible padding) already follows */
430 * This function copies a received frame to all monitor interfaces and
431 * returns a cleaned-up SKB that no longer includes the FCS nor the
432 * radiotap header the driver might have added.
434 static struct sk_buff *
435 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
436 struct ieee80211_rate *rate)
438 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
439 struct ieee80211_sub_if_data *sdata;
440 int rt_hdrlen, needed_headroom;
441 struct sk_buff *skb, *skb2;
442 struct net_device *prev_dev = NULL;
443 int present_fcs_len = 0;
444 unsigned int rtap_vendor_space = 0;
446 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
447 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
449 rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad;
453 * First, we may need to make a copy of the skb because
454 * (1) we need to modify it for radiotap (if not present), and
455 * (2) the other RX handlers will modify the skb we got.
457 * We don't need to, of course, if we aren't going to return
458 * the SKB because it has a bad FCS/PLCP checksum.
461 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
462 present_fcs_len = FCS_LEN;
464 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
465 if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) {
466 dev_kfree_skb(origskb);
470 if (!local->monitors) {
471 if (should_drop_frame(origskb, present_fcs_len,
472 rtap_vendor_space)) {
473 dev_kfree_skb(origskb);
477 return remove_monitor_info(local, origskb, rtap_vendor_space);
480 /* room for the radiotap header based on driver features */
481 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb);
482 needed_headroom = rt_hdrlen - rtap_vendor_space;
484 if (should_drop_frame(origskb, present_fcs_len, rtap_vendor_space)) {
485 /* only need to expand headroom if necessary */
490 * This shouldn't trigger often because most devices have an
491 * RX header they pull before we get here, and that should
492 * be big enough for our radiotap information. We should
493 * probably export the length to drivers so that we can have
494 * them allocate enough headroom to start with.
496 if (skb_headroom(skb) < needed_headroom &&
497 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
503 * Need to make a copy and possibly remove radiotap header
504 * and FCS from the original.
506 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
508 origskb = remove_monitor_info(local, origskb,
515 /* prepend radiotap information */
516 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
518 skb_reset_mac_header(skb);
519 skb->ip_summed = CHECKSUM_UNNECESSARY;
520 skb->pkt_type = PACKET_OTHERHOST;
521 skb->protocol = htons(ETH_P_802_2);
523 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
524 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
527 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
530 if (!ieee80211_sdata_running(sdata))
534 skb2 = skb_clone(skb, GFP_ATOMIC);
536 skb2->dev = prev_dev;
537 netif_receive_skb(skb2);
541 prev_dev = sdata->dev;
542 ieee80211_rx_stats(sdata->dev, skb->len);
547 netif_receive_skb(skb);
554 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
556 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
557 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
558 int tid, seqno_idx, security_idx;
560 /* does the frame have a qos control field? */
561 if (ieee80211_is_data_qos(hdr->frame_control)) {
562 u8 *qc = ieee80211_get_qos_ctl(hdr);
563 /* frame has qos control */
564 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
565 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
566 status->rx_flags |= IEEE80211_RX_AMSDU;
572 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
574 * Sequence numbers for management frames, QoS data
575 * frames with a broadcast/multicast address in the
576 * Address 1 field, and all non-QoS data frames sent
577 * by QoS STAs are assigned using an additional single
578 * modulo-4096 counter, [...]
580 * We also use that counter for non-QoS STAs.
582 seqno_idx = IEEE80211_NUM_TIDS;
584 if (ieee80211_is_mgmt(hdr->frame_control))
585 security_idx = IEEE80211_NUM_TIDS;
589 rx->seqno_idx = seqno_idx;
590 rx->security_idx = security_idx;
591 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
592 * For now, set skb->priority to 0 for other cases. */
593 rx->skb->priority = (tid > 7) ? 0 : tid;
597 * DOC: Packet alignment
599 * Drivers always need to pass packets that are aligned to two-byte boundaries
602 * Additionally, should, if possible, align the payload data in a way that
603 * guarantees that the contained IP header is aligned to a four-byte
604 * boundary. In the case of regular frames, this simply means aligning the
605 * payload to a four-byte boundary (because either the IP header is directly
606 * contained, or IV/RFC1042 headers that have a length divisible by four are
607 * in front of it). If the payload data is not properly aligned and the
608 * architecture doesn't support efficient unaligned operations, mac80211
609 * will align the data.
611 * With A-MSDU frames, however, the payload data address must yield two modulo
612 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
613 * push the IP header further back to a multiple of four again. Thankfully, the
614 * specs were sane enough this time around to require padding each A-MSDU
615 * subframe to a length that is a multiple of four.
617 * Padding like Atheros hardware adds which is between the 802.11 header and
618 * the payload is not supported, the driver is required to move the 802.11
619 * header to be directly in front of the payload in that case.
621 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
623 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
624 WARN_ONCE((unsigned long)rx->skb->data & 1,
625 "unaligned packet at 0x%p\n", rx->skb->data);
632 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
634 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
636 if (is_multicast_ether_addr(hdr->addr1))
639 return ieee80211_is_robust_mgmt_frame(skb);
643 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
645 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
647 if (!is_multicast_ether_addr(hdr->addr1))
650 return ieee80211_is_robust_mgmt_frame(skb);
654 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
655 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
657 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
658 struct ieee80211_mmie *mmie;
659 struct ieee80211_mmie_16 *mmie16;
661 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
664 if (!ieee80211_is_robust_mgmt_frame(skb))
665 return -1; /* not a robust management frame */
667 mmie = (struct ieee80211_mmie *)
668 (skb->data + skb->len - sizeof(*mmie));
669 if (mmie->element_id == WLAN_EID_MMIE &&
670 mmie->length == sizeof(*mmie) - 2)
671 return le16_to_cpu(mmie->key_id);
673 mmie16 = (struct ieee80211_mmie_16 *)
674 (skb->data + skb->len - sizeof(*mmie16));
675 if (skb->len >= 24 + sizeof(*mmie16) &&
676 mmie16->element_id == WLAN_EID_MMIE &&
677 mmie16->length == sizeof(*mmie16) - 2)
678 return le16_to_cpu(mmie16->key_id);
683 static int iwl80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
686 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
691 fc = hdr->frame_control;
692 hdrlen = ieee80211_hdrlen(fc);
694 if (skb->len < hdrlen + cs->hdr_len)
697 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
698 keyid &= cs->key_idx_mask;
699 keyid >>= cs->key_idx_shift;
704 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
706 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
707 char *dev_addr = rx->sdata->vif.addr;
709 if (ieee80211_is_data(hdr->frame_control)) {
710 if (is_multicast_ether_addr(hdr->addr1)) {
711 if (ieee80211_has_tods(hdr->frame_control) ||
712 !ieee80211_has_fromds(hdr->frame_control))
713 return RX_DROP_MONITOR;
714 if (ether_addr_equal(hdr->addr3, dev_addr))
715 return RX_DROP_MONITOR;
717 if (!ieee80211_has_a4(hdr->frame_control))
718 return RX_DROP_MONITOR;
719 if (ether_addr_equal(hdr->addr4, dev_addr))
720 return RX_DROP_MONITOR;
724 /* If there is not an established peer link and this is not a peer link
725 * establisment frame, beacon or probe, drop the frame.
728 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
729 struct ieee80211_mgmt *mgmt;
731 if (!ieee80211_is_mgmt(hdr->frame_control))
732 return RX_DROP_MONITOR;
734 if (ieee80211_is_action(hdr->frame_control)) {
737 /* make sure category field is present */
738 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
739 return RX_DROP_MONITOR;
741 mgmt = (struct ieee80211_mgmt *)hdr;
742 category = mgmt->u.action.category;
743 if (category != WLAN_CATEGORY_MESH_ACTION &&
744 category != WLAN_CATEGORY_SELF_PROTECTED)
745 return RX_DROP_MONITOR;
749 if (ieee80211_is_probe_req(hdr->frame_control) ||
750 ieee80211_is_probe_resp(hdr->frame_control) ||
751 ieee80211_is_beacon(hdr->frame_control) ||
752 ieee80211_is_auth(hdr->frame_control))
755 return RX_DROP_MONITOR;
761 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
762 struct tid_ampdu_rx *tid_agg_rx,
764 struct sk_buff_head *frames)
766 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
768 struct ieee80211_rx_status *status;
770 lockdep_assert_held(&tid_agg_rx->reorder_lock);
772 if (skb_queue_empty(skb_list))
775 if (!ieee80211_rx_reorder_ready(skb_list)) {
776 __skb_queue_purge(skb_list);
780 /* release frames from the reorder ring buffer */
781 tid_agg_rx->stored_mpdu_num--;
782 while ((skb = __skb_dequeue(skb_list))) {
783 status = IEEE80211_SKB_RXCB(skb);
784 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
785 __skb_queue_tail(frames, skb);
789 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
792 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
793 struct tid_ampdu_rx *tid_agg_rx,
795 struct sk_buff_head *frames)
799 lockdep_assert_held(&tid_agg_rx->reorder_lock);
801 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
802 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
803 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
809 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
810 * the skb was added to the buffer longer than this time ago, the earlier
811 * frames that have not yet been received are assumed to be lost and the skb
812 * can be released for processing. This may also release other skb's from the
813 * reorder buffer if there are no additional gaps between the frames.
815 * Callers must hold tid_agg_rx->reorder_lock.
817 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
819 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
820 struct tid_ampdu_rx *tid_agg_rx,
821 struct sk_buff_head *frames)
825 lockdep_assert_held(&tid_agg_rx->reorder_lock);
827 /* release the buffer until next missing frame */
828 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
829 if (!ieee80211_rx_reorder_ready(&tid_agg_rx->reorder_buf[index]) &&
830 tid_agg_rx->stored_mpdu_num) {
832 * No buffers ready to be released, but check whether any
833 * frames in the reorder buffer have timed out.
836 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
837 j = (j + 1) % tid_agg_rx->buf_size) {
838 if (!ieee80211_rx_reorder_ready(
839 &tid_agg_rx->reorder_buf[j])) {
844 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
845 HT_RX_REORDER_BUF_TIMEOUT))
846 goto set_release_timer;
848 /* don't leave incomplete A-MSDUs around */
849 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
850 i = (i + 1) % tid_agg_rx->buf_size)
851 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
853 ht_dbg_ratelimited(sdata,
854 "release an RX reorder frame due to timeout on earlier frames\n");
855 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
859 * Increment the head seq# also for the skipped slots.
861 tid_agg_rx->head_seq_num =
862 (tid_agg_rx->head_seq_num +
863 skipped) & IEEE80211_SN_MASK;
866 } else while (ieee80211_rx_reorder_ready(
867 &tid_agg_rx->reorder_buf[index])) {
868 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
870 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
873 if (tid_agg_rx->stored_mpdu_num) {
874 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
876 for (; j != (index - 1) % tid_agg_rx->buf_size;
877 j = (j + 1) % tid_agg_rx->buf_size) {
878 if (ieee80211_rx_reorder_ready(
879 &tid_agg_rx->reorder_buf[j]))
885 if (!tid_agg_rx->removed)
886 mod_timer(&tid_agg_rx->reorder_timer,
887 tid_agg_rx->reorder_time[j] + 1 +
888 HT_RX_REORDER_BUF_TIMEOUT);
890 del_timer(&tid_agg_rx->reorder_timer);
895 * As this function belongs to the RX path it must be under
896 * rcu_read_lock protection. It returns false if the frame
897 * can be processed immediately, true if it was consumed.
899 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
900 struct tid_ampdu_rx *tid_agg_rx,
902 struct sk_buff_head *frames)
904 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
905 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
906 u16 sc = le16_to_cpu(hdr->seq_ctrl);
907 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
908 u16 head_seq_num, buf_size;
912 spin_lock(&tid_agg_rx->reorder_lock);
915 * Offloaded BA sessions have no known starting sequence number so pick
916 * one from first Rxed frame for this tid after BA was started.
918 if (unlikely(tid_agg_rx->auto_seq)) {
919 tid_agg_rx->auto_seq = false;
920 tid_agg_rx->ssn = mpdu_seq_num;
921 tid_agg_rx->head_seq_num = mpdu_seq_num;
924 buf_size = tid_agg_rx->buf_size;
925 head_seq_num = tid_agg_rx->head_seq_num;
927 /* frame with out of date sequence number */
928 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
934 * If frame the sequence number exceeds our buffering window
935 * size release some previous frames to make room for this one.
937 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
938 head_seq_num = ieee80211_sn_inc(
939 ieee80211_sn_sub(mpdu_seq_num, buf_size));
940 /* release stored frames up to new head to stack */
941 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
942 head_seq_num, frames);
945 /* Now the new frame is always in the range of the reordering buffer */
947 index = mpdu_seq_num % tid_agg_rx->buf_size;
949 /* check if we already stored this frame */
950 if (ieee80211_rx_reorder_ready(&tid_agg_rx->reorder_buf[index])) {
956 * If the current MPDU is in the right order and nothing else
957 * is stored we can process it directly, no need to buffer it.
958 * If it is first but there's something stored, we may be able
959 * to release frames after this one.
961 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
962 tid_agg_rx->stored_mpdu_num == 0) {
963 if (!(status->flag & RX_FLAG_AMSDU_MORE))
964 tid_agg_rx->head_seq_num =
965 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
970 /* put the frame in the reordering buffer */
971 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
972 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
973 tid_agg_rx->reorder_time[index] = jiffies;
974 tid_agg_rx->stored_mpdu_num++;
975 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
979 spin_unlock(&tid_agg_rx->reorder_lock);
984 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
985 * true if the MPDU was buffered, false if it should be processed.
987 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
988 struct sk_buff_head *frames)
990 struct sk_buff *skb = rx->skb;
991 struct ieee80211_local *local = rx->local;
992 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
993 struct sta_info *sta = rx->sta;
994 struct tid_ampdu_rx *tid_agg_rx;
998 if (!ieee80211_is_data_qos(hdr->frame_control) ||
999 is_multicast_ether_addr(hdr->addr1))
1003 * filter the QoS data rx stream according to
1004 * STA/TID and check if this STA/TID is on aggregation
1010 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1011 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1012 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1014 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1018 /* qos null data frames are excluded */
1019 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1022 /* not part of a BA session */
1023 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1024 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1027 /* new, potentially un-ordered, ampdu frame - process it */
1029 /* reset session timer */
1030 if (tid_agg_rx->timeout)
1031 tid_agg_rx->last_rx = jiffies;
1033 /* if this mpdu is fragmented - terminate rx aggregation session */
1034 sc = le16_to_cpu(hdr->seq_ctrl);
1035 if (sc & IEEE80211_SCTL_FRAG) {
1036 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
1037 skb_queue_tail(&rx->sdata->skb_queue, skb);
1038 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1043 * No locking needed -- we will only ever process one
1044 * RX packet at a time, and thus own tid_agg_rx. All
1045 * other code manipulating it needs to (and does) make
1046 * sure that we cannot get to it any more before doing
1049 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1054 __skb_queue_tail(frames, skb);
1057 static ieee80211_rx_result debug_noinline
1058 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1060 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1061 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1064 * Drop duplicate 802.11 retransmissions
1065 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1068 if (rx->skb->len < 24)
1071 if (ieee80211_is_ctl(hdr->frame_control) ||
1072 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
1073 is_multicast_ether_addr(hdr->addr1))
1077 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1078 rx->sta->last_seq_ctrl[rx->seqno_idx] ==
1080 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1081 rx->sta->num_duplicates++;
1082 return RX_DROP_UNUSABLE;
1083 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1084 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1091 static ieee80211_rx_result debug_noinline
1092 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1094 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1096 if (unlikely(rx->skb->len < 16)) {
1097 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
1098 return RX_DROP_MONITOR;
1101 /* Drop disallowed frame classes based on STA auth/assoc state;
1102 * IEEE 802.11, Chap 5.5.
1104 * mac80211 filters only based on association state, i.e. it drops
1105 * Class 3 frames from not associated stations. hostapd sends
1106 * deauth/disassoc frames when needed. In addition, hostapd is
1107 * responsible for filtering on both auth and assoc states.
1110 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1111 return ieee80211_rx_mesh_check(rx);
1113 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1114 ieee80211_is_pspoll(hdr->frame_control)) &&
1115 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1116 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1117 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1118 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1120 * accept port control frames from the AP even when it's not
1121 * yet marked ASSOC to prevent a race where we don't set the
1122 * assoc bit quickly enough before it sends the first frame
1124 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1125 ieee80211_is_data_present(hdr->frame_control)) {
1126 unsigned int hdrlen;
1129 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1131 if (rx->skb->len < hdrlen + 8)
1132 return RX_DROP_MONITOR;
1134 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1135 if (ethertype == rx->sdata->control_port_protocol)
1139 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1140 cfg80211_rx_spurious_frame(rx->sdata->dev,
1143 return RX_DROP_UNUSABLE;
1145 return RX_DROP_MONITOR;
1152 static ieee80211_rx_result debug_noinline
1153 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1155 struct ieee80211_local *local;
1156 struct ieee80211_hdr *hdr;
1157 struct sk_buff *skb;
1161 hdr = (struct ieee80211_hdr *) skb->data;
1163 if (!local->pspolling)
1166 if (!ieee80211_has_fromds(hdr->frame_control))
1167 /* this is not from AP */
1170 if (!ieee80211_is_data(hdr->frame_control))
1173 if (!ieee80211_has_moredata(hdr->frame_control)) {
1174 /* AP has no more frames buffered for us */
1175 local->pspolling = false;
1179 /* more data bit is set, let's request a new frame from the AP */
1180 ieee80211_send_pspoll(local, rx->sdata);
1185 static void sta_ps_start(struct sta_info *sta)
1187 struct ieee80211_sub_if_data *sdata = sta->sdata;
1188 struct ieee80211_local *local = sdata->local;
1192 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1193 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1194 ps = &sdata->bss->ps;
1198 atomic_inc(&ps->num_sta_ps);
1199 set_sta_flag(sta, WLAN_STA_PS_STA);
1200 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1201 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1202 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1203 sta->sta.addr, sta->sta.aid);
1205 ieee80211_clear_fast_xmit(sta);
1207 if (!sta->sta.txq[0])
1210 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1211 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
1213 if (!skb_queue_len(&txqi->queue))
1214 set_bit(tid, &sta->txq_buffered_tids);
1216 clear_bit(tid, &sta->txq_buffered_tids);
1220 static void sta_ps_end(struct sta_info *sta)
1222 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1223 sta->sta.addr, sta->sta.aid);
1225 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1227 * Clear the flag only if the other one is still set
1228 * so that the TX path won't start TX'ing new frames
1229 * directly ... In the case that the driver flag isn't
1230 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1232 clear_sta_flag(sta, WLAN_STA_PS_STA);
1233 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1234 sta->sta.addr, sta->sta.aid);
1238 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1239 clear_sta_flag(sta, WLAN_STA_PS_STA);
1240 ieee80211_sta_ps_deliver_wakeup(sta);
1243 int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1245 struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1248 WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
1250 /* Don't let the same PS state be set twice */
1251 in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
1252 if ((start && in_ps) || (!start && !in_ps))
1256 sta_ps_start(sta_inf);
1258 sta_ps_end(sta_inf);
1262 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1264 static ieee80211_rx_result debug_noinline
1265 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1267 struct ieee80211_sub_if_data *sdata = rx->sdata;
1268 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1269 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1275 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1276 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1280 * The device handles station powersave, so don't do anything about
1281 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1282 * it to mac80211 since they're handled.)
1284 if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
1288 * Don't do anything if the station isn't already asleep. In
1289 * the uAPSD case, the station will probably be marked asleep,
1290 * in the PS-Poll case the station must be confused ...
1292 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1295 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1296 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1297 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1298 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1300 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
1303 /* Free PS Poll skb here instead of returning RX_DROP that would
1304 * count as an dropped frame. */
1305 dev_kfree_skb(rx->skb);
1308 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1309 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1310 ieee80211_has_pm(hdr->frame_control) &&
1311 (ieee80211_is_data_qos(hdr->frame_control) ||
1312 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1313 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1314 ac = ieee802_1d_to_ac[tid & 7];
1317 * If this AC is not trigger-enabled do nothing.
1319 * NB: This could/should check a separate bitmap of trigger-
1320 * enabled queues, but for now we only implement uAPSD w/o
1321 * TSPEC changes to the ACs, so they're always the same.
1323 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1326 /* if we are in a service period, do nothing */
1327 if (test_sta_flag(rx->sta, WLAN_STA_SP))
1330 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1331 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1333 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
1339 static ieee80211_rx_result debug_noinline
1340 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1342 struct sta_info *sta = rx->sta;
1343 struct sk_buff *skb = rx->skb;
1344 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1345 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1352 * Update last_rx only for IBSS packets which are for the current
1353 * BSSID and for station already AUTHORIZED to avoid keeping the
1354 * current IBSS network alive in cases where other STAs start
1355 * using different BSSID. This will also give the station another
1356 * chance to restart the authentication/authorization in case
1357 * something went wrong the first time.
1359 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1360 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1361 NL80211_IFTYPE_ADHOC);
1362 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1363 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1364 sta->last_rx = jiffies;
1365 if (ieee80211_is_data(hdr->frame_control) &&
1366 !is_multicast_ether_addr(hdr->addr1)) {
1367 sta->last_rx_rate_idx = status->rate_idx;
1368 sta->last_rx_rate_flag = status->flag;
1369 sta->last_rx_rate_vht_flag = status->vht_flag;
1370 sta->last_rx_rate_vht_nss = status->vht_nss;
1373 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1374 sta->last_rx = jiffies;
1375 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1377 * Mesh beacons will update last_rx when if they are found to
1378 * match the current local configuration when processed.
1380 sta->last_rx = jiffies;
1381 if (ieee80211_is_data(hdr->frame_control)) {
1382 sta->last_rx_rate_idx = status->rate_idx;
1383 sta->last_rx_rate_flag = status->flag;
1384 sta->last_rx_rate_vht_flag = status->vht_flag;
1385 sta->last_rx_rate_vht_nss = status->vht_nss;
1389 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1390 ieee80211_sta_rx_notify(rx->sdata, hdr);
1392 sta->rx_fragments++;
1393 sta->rx_bytes += rx->skb->len;
1394 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1395 sta->last_signal = status->signal;
1396 ewma_add(&sta->avg_signal, -status->signal);
1399 if (status->chains) {
1400 sta->chains = status->chains;
1401 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1402 int signal = status->chain_signal[i];
1404 if (!(status->chains & BIT(i)))
1407 sta->chain_signal_last[i] = signal;
1408 ewma_add(&sta->chain_signal_avg[i], -signal);
1413 * Change STA power saving mode only at the end of a frame
1414 * exchange sequence.
1416 if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
1417 !ieee80211_has_morefrags(hdr->frame_control) &&
1418 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1419 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1420 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1421 /* PM bit is only checked in frames where it isn't reserved,
1422 * in AP mode it's reserved in non-bufferable management frames
1423 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1425 (!ieee80211_is_mgmt(hdr->frame_control) ||
1426 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
1427 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1428 if (!ieee80211_has_pm(hdr->frame_control))
1431 if (ieee80211_has_pm(hdr->frame_control))
1436 /* mesh power save support */
1437 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1438 ieee80211_mps_rx_h_sta_process(sta, hdr);
1441 * Drop (qos-)data::nullfunc frames silently, since they
1442 * are used only to control station power saving mode.
1444 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1445 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1446 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1449 * If we receive a 4-addr nullfunc frame from a STA
1450 * that was not moved to a 4-addr STA vlan yet send
1451 * the event to userspace and for older hostapd drop
1452 * the frame to the monitor interface.
1454 if (ieee80211_has_a4(hdr->frame_control) &&
1455 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1456 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1457 !rx->sdata->u.vlan.sta))) {
1458 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1459 cfg80211_rx_unexpected_4addr_frame(
1460 rx->sdata->dev, sta->sta.addr,
1462 return RX_DROP_MONITOR;
1465 * Update counter and free packet here to avoid
1466 * counting this as a dropped packed.
1469 dev_kfree_skb(rx->skb);
1474 } /* ieee80211_rx_h_sta_process */
1476 static ieee80211_rx_result debug_noinline
1477 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1479 struct sk_buff *skb = rx->skb;
1480 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1481 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1484 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1485 struct ieee80211_key *sta_ptk = NULL;
1486 int mmie_keyidx = -1;
1488 const struct ieee80211_cipher_scheme *cs = NULL;
1493 * There are four types of keys:
1494 * - GTK (group keys)
1495 * - IGTK (group keys for management frames)
1496 * - PTK (pairwise keys)
1497 * - STK (station-to-station pairwise keys)
1499 * When selecting a key, we have to distinguish between multicast
1500 * (including broadcast) and unicast frames, the latter can only
1501 * use PTKs and STKs while the former always use GTKs and IGTKs.
1502 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1503 * unicast frames can also use key indices like GTKs. Hence, if we
1504 * don't have a PTK/STK we check the key index for a WEP key.
1506 * Note that in a regular BSS, multicast frames are sent by the
1507 * AP only, associated stations unicast the frame to the AP first
1508 * which then multicasts it on their behalf.
1510 * There is also a slight problem in IBSS mode: GTKs are negotiated
1511 * with each station, that is something we don't currently handle.
1512 * The spec seems to expect that one negotiates the same key with
1513 * every station but there's no such requirement; VLANs could be
1517 /* start without a key */
1519 fc = hdr->frame_control;
1522 int keyid = rx->sta->ptk_idx;
1524 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1525 cs = rx->sta->cipher_scheme;
1526 keyid = iwl80211_get_cs_keyid(cs, rx->skb);
1527 if (unlikely(keyid < 0))
1528 return RX_DROP_UNUSABLE;
1530 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1533 if (!ieee80211_has_protected(fc))
1534 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1536 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1538 if ((status->flag & RX_FLAG_DECRYPTED) &&
1539 (status->flag & RX_FLAG_IV_STRIPPED))
1541 /* Skip decryption if the frame is not protected. */
1542 if (!ieee80211_has_protected(fc))
1544 } else if (mmie_keyidx >= 0) {
1545 /* Broadcast/multicast robust management frame / BIP */
1546 if ((status->flag & RX_FLAG_DECRYPTED) &&
1547 (status->flag & RX_FLAG_IV_STRIPPED))
1550 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1551 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1552 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1554 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1556 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1557 } else if (!ieee80211_has_protected(fc)) {
1559 * The frame was not protected, so skip decryption. However, we
1560 * need to set rx->key if there is a key that could have been
1561 * used so that the frame may be dropped if encryption would
1562 * have been expected.
1564 struct ieee80211_key *key = NULL;
1565 struct ieee80211_sub_if_data *sdata = rx->sdata;
1568 if (ieee80211_is_mgmt(fc) &&
1569 is_multicast_ether_addr(hdr->addr1) &&
1570 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1574 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1575 key = rcu_dereference(rx->sta->gtk[i]);
1581 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1582 key = rcu_dereference(sdata->keys[i]);
1595 * The device doesn't give us the IV so we won't be
1596 * able to look up the key. That's ok though, we
1597 * don't need to decrypt the frame, we just won't
1598 * be able to keep statistics accurate.
1599 * Except for key threshold notifications, should
1600 * we somehow allow the driver to tell us which key
1601 * the hardware used if this flag is set?
1603 if ((status->flag & RX_FLAG_DECRYPTED) &&
1604 (status->flag & RX_FLAG_IV_STRIPPED))
1607 hdrlen = ieee80211_hdrlen(fc);
1610 keyidx = iwl80211_get_cs_keyid(cs, rx->skb);
1612 if (unlikely(keyidx < 0))
1613 return RX_DROP_UNUSABLE;
1615 if (rx->skb->len < 8 + hdrlen)
1616 return RX_DROP_UNUSABLE; /* TODO: count this? */
1618 * no need to call ieee80211_wep_get_keyidx,
1619 * it verifies a bunch of things we've done already
1621 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1622 keyidx = keyid >> 6;
1625 /* check per-station GTK first, if multicast packet */
1626 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1627 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1629 /* if not found, try default key */
1631 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1634 * RSNA-protected unicast frames should always be
1635 * sent with pairwise or station-to-station keys,
1636 * but for WEP we allow using a key index as well.
1639 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1640 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1641 !is_multicast_ether_addr(hdr->addr1))
1647 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1648 return RX_DROP_MONITOR;
1650 rx->key->tx_rx_count++;
1651 /* TODO: add threshold stuff again */
1653 return RX_DROP_MONITOR;
1656 switch (rx->key->conf.cipher) {
1657 case WLAN_CIPHER_SUITE_WEP40:
1658 case WLAN_CIPHER_SUITE_WEP104:
1659 result = ieee80211_crypto_wep_decrypt(rx);
1661 case WLAN_CIPHER_SUITE_TKIP:
1662 result = ieee80211_crypto_tkip_decrypt(rx);
1664 case WLAN_CIPHER_SUITE_CCMP:
1665 result = ieee80211_crypto_ccmp_decrypt(
1666 rx, IEEE80211_CCMP_MIC_LEN);
1668 case WLAN_CIPHER_SUITE_CCMP_256:
1669 result = ieee80211_crypto_ccmp_decrypt(
1670 rx, IEEE80211_CCMP_256_MIC_LEN);
1672 case WLAN_CIPHER_SUITE_AES_CMAC:
1673 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1675 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1676 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1678 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1679 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1680 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1682 case WLAN_CIPHER_SUITE_GCMP:
1683 case WLAN_CIPHER_SUITE_GCMP_256:
1684 result = ieee80211_crypto_gcmp_decrypt(rx);
1687 result = ieee80211_crypto_hw_decrypt(rx);
1690 /* the hdr variable is invalid after the decrypt handlers */
1692 /* either the frame has been decrypted or will be dropped */
1693 status->flag |= RX_FLAG_DECRYPTED;
1698 static inline struct ieee80211_fragment_entry *
1699 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1700 unsigned int frag, unsigned int seq, int rx_queue,
1701 struct sk_buff **skb)
1703 struct ieee80211_fragment_entry *entry;
1705 entry = &sdata->fragments[sdata->fragment_next++];
1706 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1707 sdata->fragment_next = 0;
1709 if (!skb_queue_empty(&entry->skb_list))
1710 __skb_queue_purge(&entry->skb_list);
1712 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1714 entry->first_frag_time = jiffies;
1716 entry->rx_queue = rx_queue;
1717 entry->last_frag = frag;
1719 entry->extra_len = 0;
1724 static inline struct ieee80211_fragment_entry *
1725 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
1726 unsigned int frag, unsigned int seq,
1727 int rx_queue, struct ieee80211_hdr *hdr)
1729 struct ieee80211_fragment_entry *entry;
1732 idx = sdata->fragment_next;
1733 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1734 struct ieee80211_hdr *f_hdr;
1738 idx = IEEE80211_FRAGMENT_MAX - 1;
1740 entry = &sdata->fragments[idx];
1741 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1742 entry->rx_queue != rx_queue ||
1743 entry->last_frag + 1 != frag)
1746 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1749 * Check ftype and addresses are equal, else check next fragment
1751 if (((hdr->frame_control ^ f_hdr->frame_control) &
1752 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1753 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1754 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
1757 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1758 __skb_queue_purge(&entry->skb_list);
1767 static ieee80211_rx_result debug_noinline
1768 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1770 struct ieee80211_hdr *hdr;
1773 unsigned int frag, seq;
1774 struct ieee80211_fragment_entry *entry;
1775 struct sk_buff *skb;
1776 struct ieee80211_rx_status *status;
1778 hdr = (struct ieee80211_hdr *)rx->skb->data;
1779 fc = hdr->frame_control;
1781 if (ieee80211_is_ctl(fc))
1784 sc = le16_to_cpu(hdr->seq_ctrl);
1785 frag = sc & IEEE80211_SCTL_FRAG;
1787 if (is_multicast_ether_addr(hdr->addr1)) {
1788 I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
1792 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
1795 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1797 if (skb_linearize(rx->skb))
1798 return RX_DROP_UNUSABLE;
1801 * skb_linearize() might change the skb->data and
1802 * previously cached variables (in this case, hdr) need to
1803 * be refreshed with the new data.
1805 hdr = (struct ieee80211_hdr *)rx->skb->data;
1806 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1809 /* This is the first fragment of a new frame. */
1810 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
1811 rx->seqno_idx, &(rx->skb));
1813 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
1814 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256) &&
1815 ieee80211_has_protected(fc)) {
1816 int queue = rx->security_idx;
1817 /* Store CCMP PN so that we can verify that the next
1818 * fragment has a sequential PN value. */
1820 memcpy(entry->last_pn,
1821 rx->key->u.ccmp.rx_pn[queue],
1822 IEEE80211_CCMP_PN_LEN);
1827 /* This is a fragment for a frame that should already be pending in
1828 * fragment cache. Add this fragment to the end of the pending entry.
1830 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1831 rx->seqno_idx, hdr);
1833 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1834 return RX_DROP_MONITOR;
1837 /* Verify that MPDUs within one MSDU have sequential PN values.
1838 * (IEEE 802.11i, 8.3.3.4.5) */
1841 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
1844 (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
1845 rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256))
1846 return RX_DROP_UNUSABLE;
1847 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
1848 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
1853 queue = rx->security_idx;
1854 rpn = rx->key->u.ccmp.rx_pn[queue];
1855 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
1856 return RX_DROP_UNUSABLE;
1857 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
1860 skb_pull(rx->skb, ieee80211_hdrlen(fc));
1861 __skb_queue_tail(&entry->skb_list, rx->skb);
1862 entry->last_frag = frag;
1863 entry->extra_len += rx->skb->len;
1864 if (ieee80211_has_morefrags(fc)) {
1869 rx->skb = __skb_dequeue(&entry->skb_list);
1870 if (skb_tailroom(rx->skb) < entry->extra_len) {
1871 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
1872 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1874 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1875 __skb_queue_purge(&entry->skb_list);
1876 return RX_DROP_UNUSABLE;
1879 while ((skb = __skb_dequeue(&entry->skb_list))) {
1880 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1884 /* Complete frame has been reassembled - process it now */
1885 status = IEEE80211_SKB_RXCB(rx->skb);
1886 status->rx_flags |= IEEE80211_RX_FRAGMENTED;
1889 ieee80211_led_rx(rx->local);
1892 rx->sta->rx_packets++;
1896 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1898 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
1904 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1906 struct sk_buff *skb = rx->skb;
1907 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1910 * Pass through unencrypted frames if the hardware has
1911 * decrypted them already.
1913 if (status->flag & RX_FLAG_DECRYPTED)
1916 /* Drop unencrypted frames if key is set. */
1917 if (unlikely(!ieee80211_has_protected(fc) &&
1918 !ieee80211_is_nullfunc(fc) &&
1919 ieee80211_is_data(fc) && rx->key))
1925 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1927 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1928 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1929 __le16 fc = hdr->frame_control;
1932 * Pass through unencrypted frames if the hardware has
1933 * decrypted them already.
1935 if (status->flag & RX_FLAG_DECRYPTED)
1938 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
1939 if (unlikely(!ieee80211_has_protected(fc) &&
1940 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1942 if (ieee80211_is_deauth(fc) ||
1943 ieee80211_is_disassoc(fc))
1944 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1949 /* BIP does not use Protected field, so need to check MMIE */
1950 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
1951 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
1952 if (ieee80211_is_deauth(fc) ||
1953 ieee80211_is_disassoc(fc))
1954 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1960 * When using MFP, Action frames are not allowed prior to
1961 * having configured keys.
1963 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1964 ieee80211_is_robust_mgmt_frame(rx->skb)))
1972 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
1974 struct ieee80211_sub_if_data *sdata = rx->sdata;
1975 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1976 bool check_port_control = false;
1977 struct ethhdr *ehdr;
1980 *port_control = false;
1981 if (ieee80211_has_a4(hdr->frame_control) &&
1982 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1985 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1986 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
1988 if (!sdata->u.mgd.use_4addr)
1991 check_port_control = true;
1994 if (is_multicast_ether_addr(hdr->addr1) &&
1995 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
1998 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2002 ehdr = (struct ethhdr *) rx->skb->data;
2003 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2004 *port_control = true;
2005 else if (check_port_control)
2012 * requires that rx->skb is a frame with ethernet header
2014 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2016 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2017 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2018 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2021 * Allow EAPOL frames to us/the PAE group address regardless
2022 * of whether the frame was encrypted or not.
2024 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
2025 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2026 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
2029 if (ieee80211_802_1x_port_control(rx) ||
2030 ieee80211_drop_unencrypted(rx, fc))
2037 * requires that rx->skb is a frame with ethernet header
2040 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2042 struct ieee80211_sub_if_data *sdata = rx->sdata;
2043 struct net_device *dev = sdata->dev;
2044 struct sk_buff *skb, *xmit_skb;
2045 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2046 struct sta_info *dsta;
2051 ieee80211_rx_stats(dev, skb->len);
2053 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2054 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2055 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2056 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2057 if (is_multicast_ether_addr(ehdr->h_dest)) {
2059 * send multicast frames both to higher layers in
2060 * local net stack and back to the wireless medium
2062 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2064 net_info_ratelimited("%s: failed to clone multicast frame\n",
2067 dsta = sta_info_get(sdata, skb->data);
2070 * The destination station is associated to
2071 * this AP (in this VLAN), so send the frame
2072 * directly to it and do not pass it to local
2081 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2083 /* 'align' will only take the values 0 or 2 here since all
2084 * frames are required to be aligned to 2-byte boundaries
2085 * when being passed to mac80211; the code here works just
2086 * as well if that isn't true, but mac80211 assumes it can
2087 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2091 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2093 if (WARN_ON(skb_headroom(skb) < 3)) {
2097 u8 *data = skb->data;
2098 size_t len = skb_headlen(skb);
2100 memmove(skb->data, data, len);
2101 skb_set_tail_pointer(skb, len);
2108 /* deliver to local stack */
2109 skb->protocol = eth_type_trans(skb, dev);
2110 memset(skb->cb, 0, sizeof(skb->cb));
2111 if (rx->local->napi)
2112 napi_gro_receive(rx->local->napi, skb);
2114 netif_receive_skb(skb);
2119 * Send to wireless media and increase priority by 256 to
2120 * keep the received priority instead of reclassifying
2121 * the frame (see cfg80211_classify8021d).
2123 xmit_skb->priority += 256;
2124 xmit_skb->protocol = htons(ETH_P_802_3);
2125 skb_reset_network_header(xmit_skb);
2126 skb_reset_mac_header(xmit_skb);
2127 dev_queue_xmit(xmit_skb);
2131 static ieee80211_rx_result debug_noinline
2132 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2134 struct net_device *dev = rx->sdata->dev;
2135 struct sk_buff *skb = rx->skb;
2136 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2137 __le16 fc = hdr->frame_control;
2138 struct sk_buff_head frame_list;
2139 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2141 if (unlikely(!ieee80211_is_data(fc)))
2144 if (unlikely(!ieee80211_is_data_present(fc)))
2145 return RX_DROP_MONITOR;
2147 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2150 if (ieee80211_has_a4(hdr->frame_control) &&
2151 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2152 !rx->sdata->u.vlan.sta)
2153 return RX_DROP_UNUSABLE;
2155 if (is_multicast_ether_addr(hdr->addr1) &&
2156 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2157 rx->sdata->u.vlan.sta) ||
2158 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
2159 rx->sdata->u.mgd.use_4addr)))
2160 return RX_DROP_UNUSABLE;
2163 __skb_queue_head_init(&frame_list);
2165 if (skb_linearize(skb))
2166 return RX_DROP_UNUSABLE;
2168 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2169 rx->sdata->vif.type,
2170 rx->local->hw.extra_tx_headroom, true);
2172 while (!skb_queue_empty(&frame_list)) {
2173 rx->skb = __skb_dequeue(&frame_list);
2175 if (!ieee80211_frame_allowed(rx, fc)) {
2176 dev_kfree_skb(rx->skb);
2180 ieee80211_deliver_skb(rx);
2186 #ifdef CONFIG_MAC80211_MESH
2187 static ieee80211_rx_result
2188 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2190 struct ieee80211_hdr *fwd_hdr, *hdr;
2191 struct ieee80211_tx_info *info;
2192 struct ieee80211s_hdr *mesh_hdr;
2193 struct sk_buff *skb = rx->skb, *fwd_skb;
2194 struct ieee80211_local *local = rx->local;
2195 struct ieee80211_sub_if_data *sdata = rx->sdata;
2196 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2199 hdr = (struct ieee80211_hdr *) skb->data;
2200 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2202 /* make sure fixed part of mesh header is there, also checks skb len */
2203 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2204 return RX_DROP_MONITOR;
2206 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2208 /* make sure full mesh header is there, also checks skb len */
2209 if (!pskb_may_pull(rx->skb,
2210 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2211 return RX_DROP_MONITOR;
2213 /* reload pointers */
2214 hdr = (struct ieee80211_hdr *) skb->data;
2215 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2217 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2218 return RX_DROP_MONITOR;
2220 /* frame is in RMC, don't forward */
2221 if (ieee80211_is_data(hdr->frame_control) &&
2222 is_multicast_ether_addr(hdr->addr1) &&
2223 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2224 return RX_DROP_MONITOR;
2226 if (!ieee80211_is_data(hdr->frame_control))
2230 return RX_DROP_MONITOR;
2232 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2233 struct mesh_path *mppath;
2237 if (is_multicast_ether_addr(hdr->addr1)) {
2238 mpp_addr = hdr->addr3;
2239 proxied_addr = mesh_hdr->eaddr1;
2240 } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
2241 /* has_a4 already checked in ieee80211_rx_mesh_check */
2242 mpp_addr = hdr->addr4;
2243 proxied_addr = mesh_hdr->eaddr2;
2245 return RX_DROP_MONITOR;
2249 mppath = mpp_path_lookup(sdata, proxied_addr);
2251 mpp_path_add(sdata, proxied_addr, mpp_addr);
2253 spin_lock_bh(&mppath->state_lock);
2254 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2255 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2256 spin_unlock_bh(&mppath->state_lock);
2261 /* Frame has reached destination. Don't forward */
2262 if (!is_multicast_ether_addr(hdr->addr1) &&
2263 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2266 q = ieee80211_select_queue_80211(sdata, skb, hdr);
2267 if (ieee80211_queue_stopped(&local->hw, q)) {
2268 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2269 return RX_DROP_MONITOR;
2271 skb_set_queue_mapping(skb, q);
2273 if (!--mesh_hdr->ttl) {
2274 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
2278 if (!ifmsh->mshcfg.dot11MeshForwarding)
2281 fwd_skb = skb_copy(skb, GFP_ATOMIC);
2283 net_info_ratelimited("%s: failed to clone mesh frame\n",
2288 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2289 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2290 info = IEEE80211_SKB_CB(fwd_skb);
2291 memset(info, 0, sizeof(*info));
2292 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2293 info->control.vif = &rx->sdata->vif;
2294 info->control.jiffies = jiffies;
2295 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2296 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2297 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2298 /* update power mode indication when forwarding */
2299 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2300 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2301 /* mesh power mode flags updated in mesh_nexthop_lookup */
2302 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2304 /* unable to resolve next hop */
2305 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2307 WLAN_REASON_MESH_PATH_NOFORWARD,
2309 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2311 return RX_DROP_MONITOR;
2314 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2315 ieee80211_add_pending_skb(local, fwd_skb);
2317 if (is_multicast_ether_addr(hdr->addr1))
2319 return RX_DROP_MONITOR;
2323 static ieee80211_rx_result debug_noinline
2324 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2326 struct ieee80211_sub_if_data *sdata = rx->sdata;
2327 struct ieee80211_local *local = rx->local;
2328 struct net_device *dev = sdata->dev;
2329 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2330 __le16 fc = hdr->frame_control;
2334 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2337 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2338 return RX_DROP_MONITOR;
2341 /* The seqno index has the same property as needed
2342 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2343 * for non-QoS-data frames. Here we know it's a data
2344 * frame, so count MSDUs.
2346 rx->sta->rx_msdu[rx->seqno_idx]++;
2350 * Send unexpected-4addr-frame event to hostapd. For older versions,
2351 * also drop the frame to cooked monitor interfaces.
2353 if (ieee80211_has_a4(hdr->frame_control) &&
2354 sdata->vif.type == NL80211_IFTYPE_AP) {
2356 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2357 cfg80211_rx_unexpected_4addr_frame(
2358 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2359 return RX_DROP_MONITOR;
2362 err = __ieee80211_data_to_8023(rx, &port_control);
2364 return RX_DROP_UNUSABLE;
2366 if (!ieee80211_frame_allowed(rx, fc))
2367 return RX_DROP_MONITOR;
2369 /* directly handle TDLS channel switch requests/responses */
2370 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2371 cpu_to_be16(ETH_P_TDLS))) {
2372 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2374 if (pskb_may_pull(rx->skb,
2375 offsetof(struct ieee80211_tdls_data, u)) &&
2376 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2377 tf->category == WLAN_CATEGORY_TDLS &&
2378 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2379 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2380 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TDLS_CHSW;
2381 skb_queue_tail(&sdata->skb_queue, rx->skb);
2382 ieee80211_queue_work(&rx->local->hw, &sdata->work);
2384 rx->sta->rx_packets++;
2390 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2391 unlikely(port_control) && sdata->bss) {
2392 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2400 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2401 !is_multicast_ether_addr(
2402 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2403 (!local->scanning &&
2404 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
2405 mod_timer(&local->dynamic_ps_timer, jiffies +
2406 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2409 ieee80211_deliver_skb(rx);
2414 static ieee80211_rx_result debug_noinline
2415 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2417 struct sk_buff *skb = rx->skb;
2418 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2419 struct tid_ampdu_rx *tid_agg_rx;
2423 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2426 if (ieee80211_is_back_req(bar->frame_control)) {
2428 __le16 control, start_seq_num;
2429 } __packed bar_data;
2430 struct ieee80211_event event = {
2431 .type = BAR_RX_EVENT,
2435 return RX_DROP_MONITOR;
2437 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2438 &bar_data, sizeof(bar_data)))
2439 return RX_DROP_MONITOR;
2441 tid = le16_to_cpu(bar_data.control) >> 12;
2443 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2445 return RX_DROP_MONITOR;
2447 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2448 event.u.ba.tid = tid;
2449 event.u.ba.ssn = start_seq_num;
2450 event.u.ba.sta = &rx->sta->sta;
2452 /* reset session timer */
2453 if (tid_agg_rx->timeout)
2454 mod_timer(&tid_agg_rx->session_timer,
2455 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2457 spin_lock(&tid_agg_rx->reorder_lock);
2458 /* release stored frames up to start of BAR */
2459 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2460 start_seq_num, frames);
2461 spin_unlock(&tid_agg_rx->reorder_lock);
2463 drv_event_callback(rx->local, rx->sdata, &event);
2470 * After this point, we only want management frames,
2471 * so we can drop all remaining control frames to
2472 * cooked monitor interfaces.
2474 return RX_DROP_MONITOR;
2477 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2478 struct ieee80211_mgmt *mgmt,
2481 struct ieee80211_local *local = sdata->local;
2482 struct sk_buff *skb;
2483 struct ieee80211_mgmt *resp;
2485 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2486 /* Not to own unicast address */
2490 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2491 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2492 /* Not from the current AP or not associated yet. */
2496 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2497 /* Too short SA Query request frame */
2501 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2505 skb_reserve(skb, local->hw.extra_tx_headroom);
2506 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2507 memset(resp, 0, 24);
2508 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2509 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2510 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2511 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2512 IEEE80211_STYPE_ACTION);
2513 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2514 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2515 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2516 memcpy(resp->u.action.u.sa_query.trans_id,
2517 mgmt->u.action.u.sa_query.trans_id,
2518 WLAN_SA_QUERY_TR_ID_LEN);
2520 ieee80211_tx_skb(sdata, skb);
2523 static ieee80211_rx_result debug_noinline
2524 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2526 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2527 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2530 * From here on, look only at management frames.
2531 * Data and control frames are already handled,
2532 * and unknown (reserved) frames are useless.
2534 if (rx->skb->len < 24)
2535 return RX_DROP_MONITOR;
2537 if (!ieee80211_is_mgmt(mgmt->frame_control))
2538 return RX_DROP_MONITOR;
2540 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2541 ieee80211_is_beacon(mgmt->frame_control) &&
2542 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2545 if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
2546 sig = status->signal;
2548 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2549 rx->skb->data, rx->skb->len,
2551 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2554 if (ieee80211_drop_unencrypted_mgmt(rx))
2555 return RX_DROP_UNUSABLE;
2560 static ieee80211_rx_result debug_noinline
2561 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2563 struct ieee80211_local *local = rx->local;
2564 struct ieee80211_sub_if_data *sdata = rx->sdata;
2565 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2566 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2567 int len = rx->skb->len;
2569 if (!ieee80211_is_action(mgmt->frame_control))
2572 /* drop too small frames */
2573 if (len < IEEE80211_MIN_ACTION_SIZE)
2574 return RX_DROP_UNUSABLE;
2576 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
2577 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2578 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
2579 return RX_DROP_UNUSABLE;
2581 switch (mgmt->u.action.category) {
2582 case WLAN_CATEGORY_HT:
2583 /* reject HT action frames from stations not supporting HT */
2584 if (!rx->sta->sta.ht_cap.ht_supported)
2587 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2588 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2589 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2590 sdata->vif.type != NL80211_IFTYPE_AP &&
2591 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2594 /* verify action & smps_control/chanwidth are present */
2595 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2598 switch (mgmt->u.action.u.ht_smps.action) {
2599 case WLAN_HT_ACTION_SMPS: {
2600 struct ieee80211_supported_band *sband;
2601 enum ieee80211_smps_mode smps_mode;
2603 /* convert to HT capability */
2604 switch (mgmt->u.action.u.ht_smps.smps_control) {
2605 case WLAN_HT_SMPS_CONTROL_DISABLED:
2606 smps_mode = IEEE80211_SMPS_OFF;
2608 case WLAN_HT_SMPS_CONTROL_STATIC:
2609 smps_mode = IEEE80211_SMPS_STATIC;
2611 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
2612 smps_mode = IEEE80211_SMPS_DYNAMIC;
2618 /* if no change do nothing */
2619 if (rx->sta->sta.smps_mode == smps_mode)
2621 rx->sta->sta.smps_mode = smps_mode;
2623 sband = rx->local->hw.wiphy->bands[status->band];
2625 rate_control_rate_update(local, sband, rx->sta,
2626 IEEE80211_RC_SMPS_CHANGED);
2629 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2630 struct ieee80211_supported_band *sband;
2631 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
2632 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
2634 /* If it doesn't support 40 MHz it can't change ... */
2635 if (!(rx->sta->sta.ht_cap.cap &
2636 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
2639 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
2640 max_bw = IEEE80211_STA_RX_BW_20;
2642 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
2644 /* set cur_max_bandwidth and recalc sta bw */
2645 rx->sta->cur_max_bandwidth = max_bw;
2646 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
2648 if (rx->sta->sta.bandwidth == new_bw)
2651 rx->sta->sta.bandwidth = new_bw;
2652 sband = rx->local->hw.wiphy->bands[status->band];
2654 rate_control_rate_update(local, sband, rx->sta,
2655 IEEE80211_RC_BW_CHANGED);
2663 case WLAN_CATEGORY_PUBLIC:
2664 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2666 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2670 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
2672 if (mgmt->u.action.u.ext_chan_switch.action_code !=
2673 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
2675 if (len < offsetof(struct ieee80211_mgmt,
2676 u.action.u.ext_chan_switch.variable))
2679 case WLAN_CATEGORY_VHT:
2680 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2681 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2682 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2683 sdata->vif.type != NL80211_IFTYPE_AP &&
2684 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2687 /* verify action code is present */
2688 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2691 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
2692 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
2695 /* verify opmode is present */
2696 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2699 opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
2701 ieee80211_vht_handle_opmode(rx->sdata, rx->sta,
2702 opmode, status->band,
2710 case WLAN_CATEGORY_BACK:
2711 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2712 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2713 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2714 sdata->vif.type != NL80211_IFTYPE_AP &&
2715 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2718 /* verify action_code is present */
2719 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2722 switch (mgmt->u.action.u.addba_req.action_code) {
2723 case WLAN_ACTION_ADDBA_REQ:
2724 if (len < (IEEE80211_MIN_ACTION_SIZE +
2725 sizeof(mgmt->u.action.u.addba_req)))
2728 case WLAN_ACTION_ADDBA_RESP:
2729 if (len < (IEEE80211_MIN_ACTION_SIZE +
2730 sizeof(mgmt->u.action.u.addba_resp)))
2733 case WLAN_ACTION_DELBA:
2734 if (len < (IEEE80211_MIN_ACTION_SIZE +
2735 sizeof(mgmt->u.action.u.delba)))
2743 case WLAN_CATEGORY_SPECTRUM_MGMT:
2744 /* verify action_code is present */
2745 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2748 switch (mgmt->u.action.u.measurement.action_code) {
2749 case WLAN_ACTION_SPCT_MSR_REQ:
2750 if (status->band != IEEE80211_BAND_5GHZ)
2753 if (len < (IEEE80211_MIN_ACTION_SIZE +
2754 sizeof(mgmt->u.action.u.measurement)))
2757 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2760 ieee80211_process_measurement_req(sdata, mgmt, len);
2762 case WLAN_ACTION_SPCT_CHL_SWITCH: {
2764 if (len < (IEEE80211_MIN_ACTION_SIZE +
2765 sizeof(mgmt->u.action.u.chan_switch)))
2768 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2769 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2770 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
2773 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2774 bssid = sdata->u.mgd.bssid;
2775 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2776 bssid = sdata->u.ibss.bssid;
2777 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
2782 if (!ether_addr_equal(mgmt->bssid, bssid))
2789 case WLAN_CATEGORY_SA_QUERY:
2790 if (len < (IEEE80211_MIN_ACTION_SIZE +
2791 sizeof(mgmt->u.action.u.sa_query)))
2794 switch (mgmt->u.action.u.sa_query.action) {
2795 case WLAN_ACTION_SA_QUERY_REQUEST:
2796 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2798 ieee80211_process_sa_query_req(sdata, mgmt, len);
2802 case WLAN_CATEGORY_SELF_PROTECTED:
2803 if (len < (IEEE80211_MIN_ACTION_SIZE +
2804 sizeof(mgmt->u.action.u.self_prot.action_code)))
2807 switch (mgmt->u.action.u.self_prot.action_code) {
2808 case WLAN_SP_MESH_PEERING_OPEN:
2809 case WLAN_SP_MESH_PEERING_CLOSE:
2810 case WLAN_SP_MESH_PEERING_CONFIRM:
2811 if (!ieee80211_vif_is_mesh(&sdata->vif))
2813 if (sdata->u.mesh.user_mpm)
2814 /* userspace handles this frame */
2817 case WLAN_SP_MGK_INFORM:
2818 case WLAN_SP_MGK_ACK:
2819 if (!ieee80211_vif_is_mesh(&sdata->vif))
2824 case WLAN_CATEGORY_MESH_ACTION:
2825 if (len < (IEEE80211_MIN_ACTION_SIZE +
2826 sizeof(mgmt->u.action.u.mesh_action.action_code)))
2829 if (!ieee80211_vif_is_mesh(&sdata->vif))
2831 if (mesh_action_is_path_sel(mgmt) &&
2832 !mesh_path_sel_is_hwmp(sdata))
2840 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
2841 /* will return in the next handlers */
2846 rx->sta->rx_packets++;
2847 dev_kfree_skb(rx->skb);
2851 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2852 skb_queue_tail(&sdata->skb_queue, rx->skb);
2853 ieee80211_queue_work(&local->hw, &sdata->work);
2855 rx->sta->rx_packets++;
2859 static ieee80211_rx_result debug_noinline
2860 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2862 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2865 /* skip known-bad action frames and return them in the next handler */
2866 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
2870 * Getting here means the kernel doesn't know how to handle
2871 * it, but maybe userspace does ... include returned frames
2872 * so userspace can register for those to know whether ones
2873 * it transmitted were processed or returned.
2876 if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
2877 sig = status->signal;
2879 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
2880 rx->skb->data, rx->skb->len, 0)) {
2882 rx->sta->rx_packets++;
2883 dev_kfree_skb(rx->skb);
2890 static ieee80211_rx_result debug_noinline
2891 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2893 struct ieee80211_local *local = rx->local;
2894 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2895 struct sk_buff *nskb;
2896 struct ieee80211_sub_if_data *sdata = rx->sdata;
2897 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2899 if (!ieee80211_is_action(mgmt->frame_control))
2903 * For AP mode, hostapd is responsible for handling any action
2904 * frames that we didn't handle, including returning unknown
2905 * ones. For all other modes we will return them to the sender,
2906 * setting the 0x80 bit in the action category, as required by
2907 * 802.11-2012 9.24.4.
2908 * Newer versions of hostapd shall also use the management frame
2909 * registration mechanisms, but older ones still use cooked
2910 * monitor interfaces so push all frames there.
2912 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
2913 (sdata->vif.type == NL80211_IFTYPE_AP ||
2914 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2915 return RX_DROP_MONITOR;
2917 if (is_multicast_ether_addr(mgmt->da))
2918 return RX_DROP_MONITOR;
2920 /* do not return rejected action frames */
2921 if (mgmt->u.action.category & 0x80)
2922 return RX_DROP_UNUSABLE;
2924 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2927 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
2929 nmgmt->u.action.category |= 0x80;
2930 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2931 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
2933 memset(nskb->cb, 0, sizeof(nskb->cb));
2935 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
2936 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
2938 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
2939 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
2940 IEEE80211_TX_CTL_NO_CCK_RATE;
2941 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
2943 local->hw.offchannel_tx_hw_queue;
2946 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
2949 dev_kfree_skb(rx->skb);
2953 static ieee80211_rx_result debug_noinline
2954 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
2956 struct ieee80211_sub_if_data *sdata = rx->sdata;
2957 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2960 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
2962 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2963 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2964 sdata->vif.type != NL80211_IFTYPE_OCB &&
2965 sdata->vif.type != NL80211_IFTYPE_STATION)
2966 return RX_DROP_MONITOR;
2969 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2970 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2971 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2972 /* process for all: mesh, mlme, ibss */
2974 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
2975 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
2976 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2977 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
2978 if (is_multicast_ether_addr(mgmt->da) &&
2979 !is_broadcast_ether_addr(mgmt->da))
2980 return RX_DROP_MONITOR;
2982 /* process only for station */
2983 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2984 return RX_DROP_MONITOR;
2986 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2987 /* process only for ibss and mesh */
2988 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2989 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
2990 return RX_DROP_MONITOR;
2993 return RX_DROP_MONITOR;
2996 /* queue up frame and kick off work to process it */
2997 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2998 skb_queue_tail(&sdata->skb_queue, rx->skb);
2999 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3001 rx->sta->rx_packets++;
3006 /* TODO: use IEEE80211_RX_FRAGMENTED */
3007 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3008 struct ieee80211_rate *rate)
3010 struct ieee80211_sub_if_data *sdata;
3011 struct ieee80211_local *local = rx->local;
3012 struct sk_buff *skb = rx->skb, *skb2;
3013 struct net_device *prev_dev = NULL;
3014 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3015 int needed_headroom;
3018 * If cooked monitor has been processed already, then
3019 * don't do it again. If not, set the flag.
3021 if (rx->flags & IEEE80211_RX_CMNTR)
3023 rx->flags |= IEEE80211_RX_CMNTR;
3025 /* If there are no cooked monitor interfaces, just free the SKB */
3026 if (!local->cooked_mntrs)
3029 /* vendor data is long removed here */
3030 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3031 /* room for the radiotap header based on driver features */
3032 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3034 if (skb_headroom(skb) < needed_headroom &&
3035 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3038 /* prepend radiotap information */
3039 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3042 skb_set_mac_header(skb, 0);
3043 skb->ip_summed = CHECKSUM_UNNECESSARY;
3044 skb->pkt_type = PACKET_OTHERHOST;
3045 skb->protocol = htons(ETH_P_802_2);
3047 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3048 if (!ieee80211_sdata_running(sdata))
3051 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3052 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
3056 skb2 = skb_clone(skb, GFP_ATOMIC);
3058 skb2->dev = prev_dev;
3059 netif_receive_skb(skb2);
3063 prev_dev = sdata->dev;
3064 ieee80211_rx_stats(sdata->dev, skb->len);
3068 skb->dev = prev_dev;
3069 netif_receive_skb(skb);
3077 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3078 ieee80211_rx_result res)
3081 case RX_DROP_MONITOR:
3082 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3084 rx->sta->rx_dropped++;
3087 struct ieee80211_rate *rate = NULL;
3088 struct ieee80211_supported_band *sband;
3089 struct ieee80211_rx_status *status;
3091 status = IEEE80211_SKB_RXCB((rx->skb));
3093 sband = rx->local->hw.wiphy->bands[status->band];
3094 if (!(status->flag & RX_FLAG_HT) &&
3095 !(status->flag & RX_FLAG_VHT))
3096 rate = &sband->bitrates[status->rate_idx];
3098 ieee80211_rx_cooked_monitor(rx, rate);
3101 case RX_DROP_UNUSABLE:
3102 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3104 rx->sta->rx_dropped++;
3105 dev_kfree_skb(rx->skb);
3108 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3113 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3114 struct sk_buff_head *frames)
3116 ieee80211_rx_result res = RX_DROP_MONITOR;
3117 struct sk_buff *skb;
3119 #define CALL_RXH(rxh) \
3122 if (res != RX_CONTINUE) \
3126 /* Lock here to avoid hitting all of the data used in the RX
3127 * path (e.g. key data, station data, ...) concurrently when
3128 * a frame is released from the reorder buffer due to timeout
3129 * from the timer, potentially concurrently with RX from the
3132 spin_lock_bh(&rx->local->rx_path_lock);
3134 while ((skb = __skb_dequeue(frames))) {
3136 * all the other fields are valid across frames
3137 * that belong to an aMPDU since they are on the
3138 * same TID from the same station
3142 CALL_RXH(ieee80211_rx_h_check_more_data)
3143 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
3144 CALL_RXH(ieee80211_rx_h_sta_process)
3145 CALL_RXH(ieee80211_rx_h_decrypt)
3146 CALL_RXH(ieee80211_rx_h_defragment)
3147 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
3148 /* must be after MMIC verify so header is counted in MPDU mic */
3149 #ifdef CONFIG_MAC80211_MESH
3150 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3151 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3153 CALL_RXH(ieee80211_rx_h_amsdu)
3154 CALL_RXH(ieee80211_rx_h_data)
3156 /* special treatment -- needs the queue */
3157 res = ieee80211_rx_h_ctrl(rx, frames);
3158 if (res != RX_CONTINUE)
3161 CALL_RXH(ieee80211_rx_h_mgmt_check)
3162 CALL_RXH(ieee80211_rx_h_action)
3163 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
3164 CALL_RXH(ieee80211_rx_h_action_return)
3165 CALL_RXH(ieee80211_rx_h_mgmt)
3168 ieee80211_rx_handlers_result(rx, res);
3173 spin_unlock_bh(&rx->local->rx_path_lock);
3176 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3178 struct sk_buff_head reorder_release;
3179 ieee80211_rx_result res = RX_DROP_MONITOR;
3181 __skb_queue_head_init(&reorder_release);
3183 #define CALL_RXH(rxh) \
3186 if (res != RX_CONTINUE) \
3190 CALL_RXH(ieee80211_rx_h_check_dup)
3191 CALL_RXH(ieee80211_rx_h_check)
3193 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3195 ieee80211_rx_handlers(rx, &reorder_release);
3199 ieee80211_rx_handlers_result(rx, res);
3205 * This function makes calls into the RX path, therefore
3206 * it has to be invoked under RCU read lock.
3208 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3210 struct sk_buff_head frames;
3211 struct ieee80211_rx_data rx = {
3213 .sdata = sta->sdata,
3214 .local = sta->local,
3215 /* This is OK -- must be QoS data frame */
3216 .security_idx = tid,
3220 struct tid_ampdu_rx *tid_agg_rx;
3222 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3226 __skb_queue_head_init(&frames);
3228 spin_lock(&tid_agg_rx->reorder_lock);
3229 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3230 spin_unlock(&tid_agg_rx->reorder_lock);
3232 if (!skb_queue_empty(&frames)) {
3233 struct ieee80211_event event = {
3234 .type = BA_FRAME_TIMEOUT,
3236 .u.ba.sta = &sta->sta,
3238 drv_event_callback(rx.local, rx.sdata, &event);
3241 ieee80211_rx_handlers(&rx, &frames);
3244 /* main receive path */
3246 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3248 struct ieee80211_sub_if_data *sdata = rx->sdata;
3249 struct sk_buff *skb = rx->skb;
3250 struct ieee80211_hdr *hdr = (void *)skb->data;
3251 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3252 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3253 int multicast = is_multicast_ether_addr(hdr->addr1);
3255 switch (sdata->vif.type) {
3256 case NL80211_IFTYPE_STATION:
3257 if (!bssid && !sdata->u.mgd.use_4addr)
3261 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3262 case NL80211_IFTYPE_ADHOC:
3265 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3266 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
3268 if (ieee80211_is_beacon(hdr->frame_control))
3270 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3273 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3277 if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
3278 rate_idx = 0; /* TODO: HT/VHT rates */
3280 rate_idx = status->rate_idx;
3281 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3285 case NL80211_IFTYPE_OCB:
3288 if (ieee80211_is_beacon(hdr->frame_control))
3290 if (!is_broadcast_ether_addr(bssid))
3293 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3297 if (status->flag & RX_FLAG_HT)
3298 rate_idx = 0; /* TODO: HT rates */
3300 rate_idx = status->rate_idx;
3301 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3305 case NL80211_IFTYPE_MESH_POINT:
3308 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3309 case NL80211_IFTYPE_AP_VLAN:
3310 case NL80211_IFTYPE_AP:
3312 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3314 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3316 * Accept public action frames even when the
3317 * BSSID doesn't match, this is used for P2P
3318 * and location updates. Note that mac80211
3319 * itself never looks at these frames.
3322 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3324 if (ieee80211_is_public_action(hdr, skb->len))
3326 return ieee80211_is_beacon(hdr->frame_control);
3329 if (!ieee80211_has_tods(hdr->frame_control)) {
3330 /* ignore data frames to TDLS-peers */
3331 if (ieee80211_is_data(hdr->frame_control))
3333 /* ignore action frames to TDLS-peers */
3334 if (ieee80211_is_action(hdr->frame_control) &&
3335 !ether_addr_equal(bssid, hdr->addr1))
3339 case NL80211_IFTYPE_WDS:
3340 if (bssid || !ieee80211_is_data(hdr->frame_control))
3342 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3343 case NL80211_IFTYPE_P2P_DEVICE:
3344 return ieee80211_is_public_action(hdr, skb->len) ||
3345 ieee80211_is_probe_req(hdr->frame_control) ||
3346 ieee80211_is_probe_resp(hdr->frame_control) ||
3347 ieee80211_is_beacon(hdr->frame_control);
3357 * This function returns whether or not the SKB
3358 * was destined for RX processing or not, which,
3359 * if consume is true, is equivalent to whether
3360 * or not the skb was consumed.
3362 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
3363 struct sk_buff *skb, bool consume)
3365 struct ieee80211_local *local = rx->local;
3366 struct ieee80211_sub_if_data *sdata = rx->sdata;
3370 if (!ieee80211_accept_frame(rx))
3374 skb = skb_copy(skb, GFP_ATOMIC);
3376 if (net_ratelimit())
3377 wiphy_debug(local->hw.wiphy,
3378 "failed to copy skb for %s\n",
3386 ieee80211_invoke_rx_handlers(rx);
3391 * This is the actual Rx frames handler. as it belongs to Rx path it must
3392 * be called with rcu_read_lock protection.
3394 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
3395 struct sk_buff *skb)
3397 struct ieee80211_local *local = hw_to_local(hw);
3398 struct ieee80211_sub_if_data *sdata;
3399 struct ieee80211_hdr *hdr;
3401 struct ieee80211_rx_data rx;
3402 struct ieee80211_sub_if_data *prev;
3403 struct sta_info *sta, *prev_sta;
3404 struct rhash_head *tmp;
3407 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
3408 memset(&rx, 0, sizeof(rx));
3412 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
3413 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
3415 if (ieee80211_is_mgmt(fc)) {
3416 /* drop frame if too short for header */
3417 if (skb->len < ieee80211_hdrlen(fc))
3420 err = skb_linearize(skb);
3422 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
3430 hdr = (struct ieee80211_hdr *)skb->data;
3431 ieee80211_parse_qos(&rx);
3432 ieee80211_verify_alignment(&rx);
3434 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
3435 ieee80211_is_beacon(hdr->frame_control)))
3436 ieee80211_scan_rx(local, skb);
3438 if (ieee80211_is_data(fc)) {
3439 const struct bucket_table *tbl;
3443 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
3445 for_each_sta_info(local, tbl, hdr->addr2, sta, tmp) {
3452 rx.sdata = prev_sta->sdata;
3453 ieee80211_prepare_and_rx_handle(&rx, skb, false);
3460 rx.sdata = prev_sta->sdata;
3462 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3470 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3471 if (!ieee80211_sdata_running(sdata))
3474 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
3475 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3479 * frame is destined for this interface, but if it's
3480 * not also for the previous one we handle that after
3481 * the loop to avoid copying the SKB once too much
3489 rx.sta = sta_info_get_bss(prev, hdr->addr2);
3491 ieee80211_prepare_and_rx_handle(&rx, skb, false);
3497 rx.sta = sta_info_get_bss(prev, hdr->addr2);
3500 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3509 * This is the receive path handler. It is called by a low level driver when an
3510 * 802.11 MPDU is received from the hardware.
3512 void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
3514 struct ieee80211_local *local = hw_to_local(hw);
3515 struct ieee80211_rate *rate = NULL;
3516 struct ieee80211_supported_band *sband;
3517 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3519 WARN_ON_ONCE(softirq_count() == 0);
3521 if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
3524 sband = local->hw.wiphy->bands[status->band];
3525 if (WARN_ON(!sband))
3529 * If we're suspending, it is possible although not too likely
3530 * that we'd be receiving frames after having already partially
3531 * quiesced the stack. We can't process such frames then since
3532 * that might, for example, cause stations to be added or other
3533 * driver callbacks be invoked.
3535 if (unlikely(local->quiescing || local->suspended))
3538 /* We might be during a HW reconfig, prevent Rx for the same reason */
3539 if (unlikely(local->in_reconfig))
3543 * The same happens when we're not even started,
3544 * but that's worth a warning.
3546 if (WARN_ON(!local->started))
3549 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
3551 * Validate the rate, unless a PLCP error means that
3552 * we probably can't have a valid rate here anyway.
3555 if (status->flag & RX_FLAG_HT) {
3557 * rate_idx is MCS index, which can be [0-76]
3560 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
3562 * Anything else would be some sort of driver or
3563 * hardware error. The driver should catch hardware
3566 if (WARN(status->rate_idx > 76,
3567 "Rate marked as an HT rate but passed "
3568 "status->rate_idx is not "
3569 "an MCS index [0-76]: %d (0x%02x)\n",
3573 } else if (status->flag & RX_FLAG_VHT) {
3574 if (WARN_ONCE(status->rate_idx > 9 ||
3576 status->vht_nss > 8,
3577 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
3578 status->rate_idx, status->vht_nss))
3581 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
3583 rate = &sband->bitrates[status->rate_idx];
3587 status->rx_flags = 0;
3590 * key references and virtual interfaces are protected using RCU
3591 * and this requires that we are in a read-side RCU section during
3592 * receive processing
3597 * Frames with failed FCS/PLCP checksum are not returned,
3598 * all other frames are returned without radiotap header
3599 * if it was previously present.
3600 * Also, frames with less than 16 bytes are dropped.
3602 skb = ieee80211_rx_monitor(local, skb, rate);
3608 ieee80211_tpt_led_trig_rx(local,
3609 ((struct ieee80211_hdr *)skb->data)->frame_control,
3611 __ieee80211_rx_handle_packet(hw, skb);
3619 EXPORT_SYMBOL(ieee80211_rx);
3621 /* This is a version of the rx handler that can be called from hard irq
3622 * context. Post the skb on the queue and schedule the tasklet */
3623 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
3625 struct ieee80211_local *local = hw_to_local(hw);
3627 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3629 skb->pkt_type = IEEE80211_RX_MSG;
3630 skb_queue_tail(&local->skb_queue, skb);
3631 tasklet_schedule(&local->tasklet);
3633 EXPORT_SYMBOL(ieee80211_rx_irqsafe);