2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/jiffies.h>
15 #include <linux/slab.h>
16 #include <linux/kernel.h>
17 #include <linux/skbuff.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/rcupdate.h>
21 #include <linux/export.h>
22 #include <linux/bitops.h>
23 #include <net/mac80211.h>
24 #include <net/ieee80211_radiotap.h>
25 #include <asm/unaligned.h>
27 #include "ieee80211_i.h"
28 #include "driver-ops.h"
37 static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
39 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
41 u64_stats_update_begin(&tstats->syncp);
43 tstats->rx_bytes += len;
44 u64_stats_update_end(&tstats->syncp);
47 static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
48 enum nl80211_iftype type)
50 __le16 fc = hdr->frame_control;
52 if (ieee80211_is_data(fc)) {
53 if (len < 24) /* drop incorrect hdr len (data) */
56 if (ieee80211_has_a4(fc))
58 if (ieee80211_has_tods(fc))
60 if (ieee80211_has_fromds(fc))
66 if (ieee80211_is_mgmt(fc)) {
67 if (len < 24) /* drop incorrect hdr len (mgmt) */
72 if (ieee80211_is_ctl(fc)) {
73 if (ieee80211_is_pspoll(fc))
76 if (ieee80211_is_back_req(fc)) {
78 case NL80211_IFTYPE_STATION:
80 case NL80211_IFTYPE_AP:
81 case NL80211_IFTYPE_AP_VLAN:
84 break; /* fall through to the return */
93 * monitor mode reception
95 * This function cleans up the SKB, i.e. it removes all the stuff
96 * only useful for monitoring.
98 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
100 unsigned int rtap_vendor_space)
102 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
103 if (likely(skb->len > FCS_LEN))
104 __pskb_trim(skb, skb->len - FCS_LEN);
113 __pskb_pull(skb, rtap_vendor_space);
118 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
119 unsigned int rtap_vendor_space)
121 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
122 struct ieee80211_hdr *hdr;
124 hdr = (void *)(skb->data + rtap_vendor_space);
126 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
127 RX_FLAG_FAILED_PLCP_CRC |
128 RX_FLAG_ONLY_MONITOR))
131 if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space))
134 if (ieee80211_is_ctl(hdr->frame_control) &&
135 !ieee80211_is_pspoll(hdr->frame_control) &&
136 !ieee80211_is_back_req(hdr->frame_control))
143 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
144 struct ieee80211_rx_status *status,
149 /* always present fields */
150 len = sizeof(struct ieee80211_radiotap_header) + 8;
152 /* allocate extra bitmaps */
154 len += 4 * hweight8(status->chains);
156 if (ieee80211_have_rx_timestamp(status)) {
160 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
163 /* antenna field, if we don't have per-chain info */
167 /* padding for RX_FLAGS if necessary */
170 if (status->flag & RX_FLAG_HT) /* HT info */
173 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
178 if (status->flag & RX_FLAG_VHT) {
183 if (status->chains) {
184 /* antenna and antenna signal fields */
185 len += 2 * hweight8(status->chains);
188 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
189 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
191 /* vendor presence bitmap */
193 /* alignment for fixed 6-byte vendor data header */
195 /* vendor data header */
197 if (WARN_ON(rtap->align == 0))
199 len = ALIGN(len, rtap->align);
200 len += rtap->len + rtap->pad;
207 * ieee80211_add_rx_radiotap_header - add radiotap header
209 * add a radiotap header containing all the fields which the hardware provided.
212 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
214 struct ieee80211_rate *rate,
215 int rtap_len, bool has_fcs)
217 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
218 struct ieee80211_radiotap_header *rthdr;
223 u16 channel_flags = 0;
225 unsigned long chains = status->chains;
226 struct ieee80211_vendor_radiotap rtap = {};
228 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
229 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
230 /* rtap.len and rtap.pad are undone immediately */
231 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
235 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
238 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
239 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
240 it_present = &rthdr->it_present;
242 /* radiotap header, set always present flags */
243 rthdr->it_len = cpu_to_le16(rtap_len);
244 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
245 BIT(IEEE80211_RADIOTAP_CHANNEL) |
246 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
249 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
251 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
253 BIT(IEEE80211_RADIOTAP_EXT) |
254 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
255 put_unaligned_le32(it_present_val, it_present);
257 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
258 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
261 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
262 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
263 BIT(IEEE80211_RADIOTAP_EXT);
264 put_unaligned_le32(it_present_val, it_present);
266 it_present_val = rtap.present;
269 put_unaligned_le32(it_present_val, it_present);
271 pos = (void *)(it_present + 1);
273 /* the order of the following fields is important */
275 /* IEEE80211_RADIOTAP_TSFT */
276 if (ieee80211_have_rx_timestamp(status)) {
278 while ((pos - (u8 *)rthdr) & 7)
281 ieee80211_calculate_rx_timestamp(local, status,
284 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
288 /* IEEE80211_RADIOTAP_FLAGS */
289 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
290 *pos |= IEEE80211_RADIOTAP_F_FCS;
291 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
292 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
293 if (status->flag & RX_FLAG_SHORTPRE)
294 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
297 /* IEEE80211_RADIOTAP_RATE */
298 if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
300 * Without rate information don't add it. If we have,
301 * MCS information is a separate field in radiotap,
302 * added below. The byte here is needed as padding
303 * for the channel though, so initialise it to 0.
308 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
309 if (status->flag & RX_FLAG_10MHZ)
311 else if (status->flag & RX_FLAG_5MHZ)
313 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
317 /* IEEE80211_RADIOTAP_CHANNEL */
318 put_unaligned_le16(status->freq, pos);
320 if (status->flag & RX_FLAG_10MHZ)
321 channel_flags |= IEEE80211_CHAN_HALF;
322 else if (status->flag & RX_FLAG_5MHZ)
323 channel_flags |= IEEE80211_CHAN_QUARTER;
325 if (status->band == IEEE80211_BAND_5GHZ)
326 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
327 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
328 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
329 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
330 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
332 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
334 channel_flags |= IEEE80211_CHAN_2GHZ;
335 put_unaligned_le16(channel_flags, pos);
338 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
339 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
340 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
341 *pos = status->signal;
343 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
347 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
349 if (!status->chains) {
350 /* IEEE80211_RADIOTAP_ANTENNA */
351 *pos = status->antenna;
355 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
357 /* IEEE80211_RADIOTAP_RX_FLAGS */
358 /* ensure 2 byte alignment for the 2 byte field as required */
359 if ((pos - (u8 *)rthdr) & 1)
361 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
362 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
363 put_unaligned_le16(rx_flags, pos);
366 if (status->flag & RX_FLAG_HT) {
369 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
370 *pos++ = local->hw.radiotap_mcs_details;
372 if (status->flag & RX_FLAG_SHORT_GI)
373 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
374 if (status->flag & RX_FLAG_40MHZ)
375 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
376 if (status->flag & RX_FLAG_HT_GF)
377 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
378 if (status->flag & RX_FLAG_LDPC)
379 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
380 stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
381 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
383 *pos++ = status->rate_idx;
386 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
389 /* ensure 4 byte alignment */
390 while ((pos - (u8 *)rthdr) & 3)
393 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
394 put_unaligned_le32(status->ampdu_reference, pos);
396 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
397 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
398 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
399 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
400 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
401 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
402 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
403 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
404 put_unaligned_le16(flags, pos);
406 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
407 *pos++ = status->ampdu_delimiter_crc;
413 if (status->flag & RX_FLAG_VHT) {
414 u16 known = local->hw.radiotap_vht_details;
416 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
417 put_unaligned_le16(known, pos);
420 if (status->flag & RX_FLAG_SHORT_GI)
421 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
422 /* in VHT, STBC is binary */
423 if (status->flag & RX_FLAG_STBC_MASK)
424 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
425 if (status->vht_flag & RX_VHT_FLAG_BF)
426 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
429 if (status->vht_flag & RX_VHT_FLAG_80MHZ)
431 else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
433 else if (status->flag & RX_FLAG_40MHZ)
438 *pos = (status->rate_idx << 4) | status->vht_nss;
441 if (status->flag & RX_FLAG_LDPC)
442 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
450 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
451 *pos++ = status->chain_signal[chain];
455 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
456 /* ensure 2 byte alignment for the vendor field as required */
457 if ((pos - (u8 *)rthdr) & 1)
459 *pos++ = rtap.oui[0];
460 *pos++ = rtap.oui[1];
461 *pos++ = rtap.oui[2];
463 put_unaligned_le16(rtap.len, pos);
465 /* align the actual payload as requested */
466 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
468 /* data (and possible padding) already follows */
473 * This function copies a received frame to all monitor interfaces and
474 * returns a cleaned-up SKB that no longer includes the FCS nor the
475 * radiotap header the driver might have added.
477 static struct sk_buff *
478 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
479 struct ieee80211_rate *rate)
481 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
482 struct ieee80211_sub_if_data *sdata;
483 int rt_hdrlen, needed_headroom;
484 struct sk_buff *skb, *skb2;
485 struct net_device *prev_dev = NULL;
486 int present_fcs_len = 0;
487 unsigned int rtap_vendor_space = 0;
489 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
490 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
492 rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad;
496 * First, we may need to make a copy of the skb because
497 * (1) we need to modify it for radiotap (if not present), and
498 * (2) the other RX handlers will modify the skb we got.
500 * We don't need to, of course, if we aren't going to return
501 * the SKB because it has a bad FCS/PLCP checksum.
504 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
505 present_fcs_len = FCS_LEN;
507 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
508 if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) {
509 dev_kfree_skb(origskb);
513 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
514 if (should_drop_frame(origskb, present_fcs_len,
515 rtap_vendor_space)) {
516 dev_kfree_skb(origskb);
520 return remove_monitor_info(local, origskb, rtap_vendor_space);
523 /* room for the radiotap header based on driver features */
524 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb);
525 needed_headroom = rt_hdrlen - rtap_vendor_space;
527 if (should_drop_frame(origskb, present_fcs_len, rtap_vendor_space)) {
528 /* only need to expand headroom if necessary */
533 * This shouldn't trigger often because most devices have an
534 * RX header they pull before we get here, and that should
535 * be big enough for our radiotap information. We should
536 * probably export the length to drivers so that we can have
537 * them allocate enough headroom to start with.
539 if (skb_headroom(skb) < needed_headroom &&
540 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
546 * Need to make a copy and possibly remove radiotap header
547 * and FCS from the original.
549 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
551 origskb = remove_monitor_info(local, origskb,
558 /* prepend radiotap information */
559 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
561 skb_reset_mac_header(skb);
562 skb->ip_summed = CHECKSUM_UNNECESSARY;
563 skb->pkt_type = PACKET_OTHERHOST;
564 skb->protocol = htons(ETH_P_802_2);
566 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
567 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
570 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
573 if (!ieee80211_sdata_running(sdata))
577 skb2 = skb_clone(skb, GFP_ATOMIC);
579 skb2->dev = prev_dev;
580 netif_receive_skb(skb2);
584 prev_dev = sdata->dev;
585 ieee80211_rx_stats(sdata->dev, skb->len);
590 netif_receive_skb(skb);
597 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
599 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
600 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
601 int tid, seqno_idx, security_idx;
603 /* does the frame have a qos control field? */
604 if (ieee80211_is_data_qos(hdr->frame_control)) {
605 u8 *qc = ieee80211_get_qos_ctl(hdr);
606 /* frame has qos control */
607 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
608 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
609 status->rx_flags |= IEEE80211_RX_AMSDU;
615 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
617 * Sequence numbers for management frames, QoS data
618 * frames with a broadcast/multicast address in the
619 * Address 1 field, and all non-QoS data frames sent
620 * by QoS STAs are assigned using an additional single
621 * modulo-4096 counter, [...]
623 * We also use that counter for non-QoS STAs.
625 seqno_idx = IEEE80211_NUM_TIDS;
627 if (ieee80211_is_mgmt(hdr->frame_control))
628 security_idx = IEEE80211_NUM_TIDS;
632 rx->seqno_idx = seqno_idx;
633 rx->security_idx = security_idx;
634 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
635 * For now, set skb->priority to 0 for other cases. */
636 rx->skb->priority = (tid > 7) ? 0 : tid;
640 * DOC: Packet alignment
642 * Drivers always need to pass packets that are aligned to two-byte boundaries
645 * Additionally, should, if possible, align the payload data in a way that
646 * guarantees that the contained IP header is aligned to a four-byte
647 * boundary. In the case of regular frames, this simply means aligning the
648 * payload to a four-byte boundary (because either the IP header is directly
649 * contained, or IV/RFC1042 headers that have a length divisible by four are
650 * in front of it). If the payload data is not properly aligned and the
651 * architecture doesn't support efficient unaligned operations, mac80211
652 * will align the data.
654 * With A-MSDU frames, however, the payload data address must yield two modulo
655 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
656 * push the IP header further back to a multiple of four again. Thankfully, the
657 * specs were sane enough this time around to require padding each A-MSDU
658 * subframe to a length that is a multiple of four.
660 * Padding like Atheros hardware adds which is between the 802.11 header and
661 * the payload is not supported, the driver is required to move the 802.11
662 * header to be directly in front of the payload in that case.
664 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
666 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
667 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
674 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
676 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
678 if (is_multicast_ether_addr(hdr->addr1))
681 return ieee80211_is_robust_mgmt_frame(skb);
685 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
687 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
689 if (!is_multicast_ether_addr(hdr->addr1))
692 return ieee80211_is_robust_mgmt_frame(skb);
696 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
697 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
699 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
700 struct ieee80211_mmie *mmie;
701 struct ieee80211_mmie_16 *mmie16;
703 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
706 if (!ieee80211_is_robust_mgmt_frame(skb))
707 return -1; /* not a robust management frame */
709 mmie = (struct ieee80211_mmie *)
710 (skb->data + skb->len - sizeof(*mmie));
711 if (mmie->element_id == WLAN_EID_MMIE &&
712 mmie->length == sizeof(*mmie) - 2)
713 return le16_to_cpu(mmie->key_id);
715 mmie16 = (struct ieee80211_mmie_16 *)
716 (skb->data + skb->len - sizeof(*mmie16));
717 if (skb->len >= 24 + sizeof(*mmie16) &&
718 mmie16->element_id == WLAN_EID_MMIE &&
719 mmie16->length == sizeof(*mmie16) - 2)
720 return le16_to_cpu(mmie16->key_id);
725 static int iwl80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
728 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
733 fc = hdr->frame_control;
734 hdrlen = ieee80211_hdrlen(fc);
736 if (skb->len < hdrlen + cs->hdr_len)
739 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
740 keyid &= cs->key_idx_mask;
741 keyid >>= cs->key_idx_shift;
746 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
748 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
749 char *dev_addr = rx->sdata->vif.addr;
751 if (ieee80211_is_data(hdr->frame_control)) {
752 if (is_multicast_ether_addr(hdr->addr1)) {
753 if (ieee80211_has_tods(hdr->frame_control) ||
754 !ieee80211_has_fromds(hdr->frame_control))
755 return RX_DROP_MONITOR;
756 if (ether_addr_equal(hdr->addr3, dev_addr))
757 return RX_DROP_MONITOR;
759 if (!ieee80211_has_a4(hdr->frame_control))
760 return RX_DROP_MONITOR;
761 if (ether_addr_equal(hdr->addr4, dev_addr))
762 return RX_DROP_MONITOR;
766 /* If there is not an established peer link and this is not a peer link
767 * establisment frame, beacon or probe, drop the frame.
770 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
771 struct ieee80211_mgmt *mgmt;
773 if (!ieee80211_is_mgmt(hdr->frame_control))
774 return RX_DROP_MONITOR;
776 if (ieee80211_is_action(hdr->frame_control)) {
779 /* make sure category field is present */
780 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
781 return RX_DROP_MONITOR;
783 mgmt = (struct ieee80211_mgmt *)hdr;
784 category = mgmt->u.action.category;
785 if (category != WLAN_CATEGORY_MESH_ACTION &&
786 category != WLAN_CATEGORY_SELF_PROTECTED)
787 return RX_DROP_MONITOR;
791 if (ieee80211_is_probe_req(hdr->frame_control) ||
792 ieee80211_is_probe_resp(hdr->frame_control) ||
793 ieee80211_is_beacon(hdr->frame_control) ||
794 ieee80211_is_auth(hdr->frame_control))
797 return RX_DROP_MONITOR;
803 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
806 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
807 struct sk_buff *tail = skb_peek_tail(frames);
808 struct ieee80211_rx_status *status;
810 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
816 status = IEEE80211_SKB_RXCB(tail);
817 if (status->flag & RX_FLAG_AMSDU_MORE)
823 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
824 struct tid_ampdu_rx *tid_agg_rx,
826 struct sk_buff_head *frames)
828 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
830 struct ieee80211_rx_status *status;
832 lockdep_assert_held(&tid_agg_rx->reorder_lock);
834 if (skb_queue_empty(skb_list))
837 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
838 __skb_queue_purge(skb_list);
842 /* release frames from the reorder ring buffer */
843 tid_agg_rx->stored_mpdu_num--;
844 while ((skb = __skb_dequeue(skb_list))) {
845 status = IEEE80211_SKB_RXCB(skb);
846 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
847 __skb_queue_tail(frames, skb);
851 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
852 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
855 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
856 struct tid_ampdu_rx *tid_agg_rx,
858 struct sk_buff_head *frames)
862 lockdep_assert_held(&tid_agg_rx->reorder_lock);
864 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
865 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
866 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
872 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
873 * the skb was added to the buffer longer than this time ago, the earlier
874 * frames that have not yet been received are assumed to be lost and the skb
875 * can be released for processing. This may also release other skb's from the
876 * reorder buffer if there are no additional gaps between the frames.
878 * Callers must hold tid_agg_rx->reorder_lock.
880 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
882 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
883 struct tid_ampdu_rx *tid_agg_rx,
884 struct sk_buff_head *frames)
888 lockdep_assert_held(&tid_agg_rx->reorder_lock);
890 /* release the buffer until next missing frame */
891 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
892 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
893 tid_agg_rx->stored_mpdu_num) {
895 * No buffers ready to be released, but check whether any
896 * frames in the reorder buffer have timed out.
899 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
900 j = (j + 1) % tid_agg_rx->buf_size) {
901 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
906 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
907 HT_RX_REORDER_BUF_TIMEOUT))
908 goto set_release_timer;
910 /* don't leave incomplete A-MSDUs around */
911 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
912 i = (i + 1) % tid_agg_rx->buf_size)
913 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
915 ht_dbg_ratelimited(sdata,
916 "release an RX reorder frame due to timeout on earlier frames\n");
917 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
921 * Increment the head seq# also for the skipped slots.
923 tid_agg_rx->head_seq_num =
924 (tid_agg_rx->head_seq_num +
925 skipped) & IEEE80211_SN_MASK;
928 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
929 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
931 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
934 if (tid_agg_rx->stored_mpdu_num) {
935 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
937 for (; j != (index - 1) % tid_agg_rx->buf_size;
938 j = (j + 1) % tid_agg_rx->buf_size) {
939 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
945 if (!tid_agg_rx->removed)
946 mod_timer(&tid_agg_rx->reorder_timer,
947 tid_agg_rx->reorder_time[j] + 1 +
948 HT_RX_REORDER_BUF_TIMEOUT);
950 del_timer(&tid_agg_rx->reorder_timer);
955 * As this function belongs to the RX path it must be under
956 * rcu_read_lock protection. It returns false if the frame
957 * can be processed immediately, true if it was consumed.
959 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
960 struct tid_ampdu_rx *tid_agg_rx,
962 struct sk_buff_head *frames)
964 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
965 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
966 u16 sc = le16_to_cpu(hdr->seq_ctrl);
967 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
968 u16 head_seq_num, buf_size;
972 spin_lock(&tid_agg_rx->reorder_lock);
975 * Offloaded BA sessions have no known starting sequence number so pick
976 * one from first Rxed frame for this tid after BA was started.
978 if (unlikely(tid_agg_rx->auto_seq)) {
979 tid_agg_rx->auto_seq = false;
980 tid_agg_rx->ssn = mpdu_seq_num;
981 tid_agg_rx->head_seq_num = mpdu_seq_num;
984 buf_size = tid_agg_rx->buf_size;
985 head_seq_num = tid_agg_rx->head_seq_num;
987 /* frame with out of date sequence number */
988 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
994 * If frame the sequence number exceeds our buffering window
995 * size release some previous frames to make room for this one.
997 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
998 head_seq_num = ieee80211_sn_inc(
999 ieee80211_sn_sub(mpdu_seq_num, buf_size));
1000 /* release stored frames up to new head to stack */
1001 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1002 head_seq_num, frames);
1005 /* Now the new frame is always in the range of the reordering buffer */
1007 index = mpdu_seq_num % tid_agg_rx->buf_size;
1009 /* check if we already stored this frame */
1010 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1016 * If the current MPDU is in the right order and nothing else
1017 * is stored we can process it directly, no need to buffer it.
1018 * If it is first but there's something stored, we may be able
1019 * to release frames after this one.
1021 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1022 tid_agg_rx->stored_mpdu_num == 0) {
1023 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1024 tid_agg_rx->head_seq_num =
1025 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1030 /* put the frame in the reordering buffer */
1031 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1032 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1033 tid_agg_rx->reorder_time[index] = jiffies;
1034 tid_agg_rx->stored_mpdu_num++;
1035 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1039 spin_unlock(&tid_agg_rx->reorder_lock);
1044 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1045 * true if the MPDU was buffered, false if it should be processed.
1047 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1048 struct sk_buff_head *frames)
1050 struct sk_buff *skb = rx->skb;
1051 struct ieee80211_local *local = rx->local;
1052 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1053 struct sta_info *sta = rx->sta;
1054 struct tid_ampdu_rx *tid_agg_rx;
1058 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1059 is_multicast_ether_addr(hdr->addr1))
1063 * filter the QoS data rx stream according to
1064 * STA/TID and check if this STA/TID is on aggregation
1070 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1071 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1072 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1074 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1078 /* qos null data frames are excluded */
1079 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1082 /* not part of a BA session */
1083 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1084 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1087 /* new, potentially un-ordered, ampdu frame - process it */
1089 /* reset session timer */
1090 if (tid_agg_rx->timeout)
1091 tid_agg_rx->last_rx = jiffies;
1093 /* if this mpdu is fragmented - terminate rx aggregation session */
1094 sc = le16_to_cpu(hdr->seq_ctrl);
1095 if (sc & IEEE80211_SCTL_FRAG) {
1096 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
1097 skb_queue_tail(&rx->sdata->skb_queue, skb);
1098 ieee80211_queue_work(&local->hw, &rx->sdata->work);
1103 * No locking needed -- we will only ever process one
1104 * RX packet at a time, and thus own tid_agg_rx. All
1105 * other code manipulating it needs to (and does) make
1106 * sure that we cannot get to it any more before doing
1109 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1114 __skb_queue_tail(frames, skb);
1117 static ieee80211_rx_result debug_noinline
1118 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1120 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1121 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1123 if (status->flag & RX_FLAG_DUP_VALIDATED)
1127 * Drop duplicate 802.11 retransmissions
1128 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1131 if (rx->skb->len < 24)
1134 if (ieee80211_is_ctl(hdr->frame_control) ||
1135 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
1136 is_multicast_ether_addr(hdr->addr1))
1142 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1143 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1144 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1145 rx->sta->rx_stats.num_duplicates++;
1146 return RX_DROP_UNUSABLE;
1147 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1148 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1154 static ieee80211_rx_result debug_noinline
1155 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1157 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1159 /* Drop disallowed frame classes based on STA auth/assoc state;
1160 * IEEE 802.11, Chap 5.5.
1162 * mac80211 filters only based on association state, i.e. it drops
1163 * Class 3 frames from not associated stations. hostapd sends
1164 * deauth/disassoc frames when needed. In addition, hostapd is
1165 * responsible for filtering on both auth and assoc states.
1168 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1169 return ieee80211_rx_mesh_check(rx);
1171 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1172 ieee80211_is_pspoll(hdr->frame_control)) &&
1173 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1174 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
1175 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1176 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1178 * accept port control frames from the AP even when it's not
1179 * yet marked ASSOC to prevent a race where we don't set the
1180 * assoc bit quickly enough before it sends the first frame
1182 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1183 ieee80211_is_data_present(hdr->frame_control)) {
1184 unsigned int hdrlen;
1187 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1189 if (rx->skb->len < hdrlen + 8)
1190 return RX_DROP_MONITOR;
1192 skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2);
1193 if (ethertype == rx->sdata->control_port_protocol)
1197 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1198 cfg80211_rx_spurious_frame(rx->sdata->dev,
1201 return RX_DROP_UNUSABLE;
1203 return RX_DROP_MONITOR;
1210 static ieee80211_rx_result debug_noinline
1211 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1213 struct ieee80211_local *local;
1214 struct ieee80211_hdr *hdr;
1215 struct sk_buff *skb;
1219 hdr = (struct ieee80211_hdr *) skb->data;
1221 if (!local->pspolling)
1224 if (!ieee80211_has_fromds(hdr->frame_control))
1225 /* this is not from AP */
1228 if (!ieee80211_is_data(hdr->frame_control))
1231 if (!ieee80211_has_moredata(hdr->frame_control)) {
1232 /* AP has no more frames buffered for us */
1233 local->pspolling = false;
1237 /* more data bit is set, let's request a new frame from the AP */
1238 ieee80211_send_pspoll(local, rx->sdata);
1243 static void sta_ps_start(struct sta_info *sta)
1245 struct ieee80211_sub_if_data *sdata = sta->sdata;
1246 struct ieee80211_local *local = sdata->local;
1250 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1251 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1252 ps = &sdata->bss->ps;
1256 atomic_inc(&ps->num_sta_ps);
1257 set_sta_flag(sta, WLAN_STA_PS_STA);
1258 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1259 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1260 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1261 sta->sta.addr, sta->sta.aid);
1263 ieee80211_clear_fast_xmit(sta);
1265 if (!sta->sta.txq[0])
1268 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1269 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
1271 if (!skb_queue_len(&txqi->queue))
1272 set_bit(tid, &sta->txq_buffered_tids);
1274 clear_bit(tid, &sta->txq_buffered_tids);
1278 static void sta_ps_end(struct sta_info *sta)
1280 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1281 sta->sta.addr, sta->sta.aid);
1283 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1285 * Clear the flag only if the other one is still set
1286 * so that the TX path won't start TX'ing new frames
1287 * directly ... In the case that the driver flag isn't
1288 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1290 clear_sta_flag(sta, WLAN_STA_PS_STA);
1291 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1292 sta->sta.addr, sta->sta.aid);
1296 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1297 clear_sta_flag(sta, WLAN_STA_PS_STA);
1298 ieee80211_sta_ps_deliver_wakeup(sta);
1301 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1303 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1306 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1308 /* Don't let the same PS state be set twice */
1309 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1310 if ((start && in_ps) || (!start && !in_ps))
1320 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1322 static ieee80211_rx_result debug_noinline
1323 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1325 struct ieee80211_sub_if_data *sdata = rx->sdata;
1326 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1327 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1333 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1334 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1338 * The device handles station powersave, so don't do anything about
1339 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1340 * it to mac80211 since they're handled.)
1342 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1346 * Don't do anything if the station isn't already asleep. In
1347 * the uAPSD case, the station will probably be marked asleep,
1348 * in the PS-Poll case the station must be confused ...
1350 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1353 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1354 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1355 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1356 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1358 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
1361 /* Free PS Poll skb here instead of returning RX_DROP that would
1362 * count as an dropped frame. */
1363 dev_kfree_skb(rx->skb);
1366 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1367 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1368 ieee80211_has_pm(hdr->frame_control) &&
1369 (ieee80211_is_data_qos(hdr->frame_control) ||
1370 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1371 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1372 ac = ieee802_1d_to_ac[tid & 7];
1375 * If this AC is not trigger-enabled do nothing.
1377 * NB: This could/should check a separate bitmap of trigger-
1378 * enabled queues, but for now we only implement uAPSD w/o
1379 * TSPEC changes to the ACs, so they're always the same.
1381 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1384 /* if we are in a service period, do nothing */
1385 if (test_sta_flag(rx->sta, WLAN_STA_SP))
1388 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1389 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1391 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
1397 static ieee80211_rx_result debug_noinline
1398 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1400 struct sta_info *sta = rx->sta;
1401 struct sk_buff *skb = rx->skb;
1402 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1403 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1410 * Update last_rx only for IBSS packets which are for the current
1411 * BSSID and for station already AUTHORIZED to avoid keeping the
1412 * current IBSS network alive in cases where other STAs start
1413 * using different BSSID. This will also give the station another
1414 * chance to restart the authentication/authorization in case
1415 * something went wrong the first time.
1417 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1418 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1419 NL80211_IFTYPE_ADHOC);
1420 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1421 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1422 sta->rx_stats.last_rx = jiffies;
1423 if (ieee80211_is_data(hdr->frame_control) &&
1424 !is_multicast_ether_addr(hdr->addr1)) {
1425 sta->rx_stats.last_rate_idx =
1427 sta->rx_stats.last_rate_flag =
1429 sta->rx_stats.last_rate_vht_flag =
1431 sta->rx_stats.last_rate_vht_nss =
1435 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1436 sta->rx_stats.last_rx = jiffies;
1437 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1439 * Mesh beacons will update last_rx when if they are found to
1440 * match the current local configuration when processed.
1442 sta->rx_stats.last_rx = jiffies;
1443 if (ieee80211_is_data(hdr->frame_control)) {
1444 sta->rx_stats.last_rate_idx = status->rate_idx;
1445 sta->rx_stats.last_rate_flag = status->flag;
1446 sta->rx_stats.last_rate_vht_flag = status->vht_flag;
1447 sta->rx_stats.last_rate_vht_nss = status->vht_nss;
1451 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1452 ieee80211_sta_rx_notify(rx->sdata, hdr);
1454 sta->rx_stats.fragments++;
1455 sta->rx_stats.bytes += rx->skb->len;
1456 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1457 sta->rx_stats.last_signal = status->signal;
1458 ewma_signal_add(&sta->rx_stats.avg_signal, -status->signal);
1461 if (status->chains) {
1462 sta->rx_stats.chains = status->chains;
1463 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1464 int signal = status->chain_signal[i];
1466 if (!(status->chains & BIT(i)))
1469 sta->rx_stats.chain_signal_last[i] = signal;
1470 ewma_signal_add(&sta->rx_stats.chain_signal_avg[i],
1476 * Change STA power saving mode only at the end of a frame
1477 * exchange sequence.
1479 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1480 !ieee80211_has_morefrags(hdr->frame_control) &&
1481 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1482 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1483 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1484 /* PM bit is only checked in frames where it isn't reserved,
1485 * in AP mode it's reserved in non-bufferable management frames
1486 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1488 (!ieee80211_is_mgmt(hdr->frame_control) ||
1489 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
1490 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1491 if (!ieee80211_has_pm(hdr->frame_control))
1494 if (ieee80211_has_pm(hdr->frame_control))
1499 /* mesh power save support */
1500 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1501 ieee80211_mps_rx_h_sta_process(sta, hdr);
1504 * Drop (qos-)data::nullfunc frames silently, since they
1505 * are used only to control station power saving mode.
1507 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1508 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1509 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1512 * If we receive a 4-addr nullfunc frame from a STA
1513 * that was not moved to a 4-addr STA vlan yet send
1514 * the event to userspace and for older hostapd drop
1515 * the frame to the monitor interface.
1517 if (ieee80211_has_a4(hdr->frame_control) &&
1518 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1519 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1520 !rx->sdata->u.vlan.sta))) {
1521 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1522 cfg80211_rx_unexpected_4addr_frame(
1523 rx->sdata->dev, sta->sta.addr,
1525 return RX_DROP_MONITOR;
1528 * Update counter and free packet here to avoid
1529 * counting this as a dropped packed.
1531 sta->rx_stats.packets++;
1532 dev_kfree_skb(rx->skb);
1537 } /* ieee80211_rx_h_sta_process */
1539 static ieee80211_rx_result debug_noinline
1540 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1542 struct sk_buff *skb = rx->skb;
1543 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1544 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1547 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1548 struct ieee80211_key *sta_ptk = NULL;
1549 int mmie_keyidx = -1;
1551 const struct ieee80211_cipher_scheme *cs = NULL;
1556 * There are four types of keys:
1557 * - GTK (group keys)
1558 * - IGTK (group keys for management frames)
1559 * - PTK (pairwise keys)
1560 * - STK (station-to-station pairwise keys)
1562 * When selecting a key, we have to distinguish between multicast
1563 * (including broadcast) and unicast frames, the latter can only
1564 * use PTKs and STKs while the former always use GTKs and IGTKs.
1565 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1566 * unicast frames can also use key indices like GTKs. Hence, if we
1567 * don't have a PTK/STK we check the key index for a WEP key.
1569 * Note that in a regular BSS, multicast frames are sent by the
1570 * AP only, associated stations unicast the frame to the AP first
1571 * which then multicasts it on their behalf.
1573 * There is also a slight problem in IBSS mode: GTKs are negotiated
1574 * with each station, that is something we don't currently handle.
1575 * The spec seems to expect that one negotiates the same key with
1576 * every station but there's no such requirement; VLANs could be
1580 /* start without a key */
1582 fc = hdr->frame_control;
1585 int keyid = rx->sta->ptk_idx;
1587 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1588 cs = rx->sta->cipher_scheme;
1589 keyid = iwl80211_get_cs_keyid(cs, rx->skb);
1590 if (unlikely(keyid < 0))
1591 return RX_DROP_UNUSABLE;
1593 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1596 if (!ieee80211_has_protected(fc))
1597 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1599 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1601 if ((status->flag & RX_FLAG_DECRYPTED) &&
1602 (status->flag & RX_FLAG_IV_STRIPPED))
1604 /* Skip decryption if the frame is not protected. */
1605 if (!ieee80211_has_protected(fc))
1607 } else if (mmie_keyidx >= 0) {
1608 /* Broadcast/multicast robust management frame / BIP */
1609 if ((status->flag & RX_FLAG_DECRYPTED) &&
1610 (status->flag & RX_FLAG_IV_STRIPPED))
1613 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1614 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1615 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1617 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1619 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1620 } else if (!ieee80211_has_protected(fc)) {
1622 * The frame was not protected, so skip decryption. However, we
1623 * need to set rx->key if there is a key that could have been
1624 * used so that the frame may be dropped if encryption would
1625 * have been expected.
1627 struct ieee80211_key *key = NULL;
1628 struct ieee80211_sub_if_data *sdata = rx->sdata;
1631 if (ieee80211_is_mgmt(fc) &&
1632 is_multicast_ether_addr(hdr->addr1) &&
1633 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1637 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1638 key = rcu_dereference(rx->sta->gtk[i]);
1644 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1645 key = rcu_dereference(sdata->keys[i]);
1658 * The device doesn't give us the IV so we won't be
1659 * able to look up the key. That's ok though, we
1660 * don't need to decrypt the frame, we just won't
1661 * be able to keep statistics accurate.
1662 * Except for key threshold notifications, should
1663 * we somehow allow the driver to tell us which key
1664 * the hardware used if this flag is set?
1666 if ((status->flag & RX_FLAG_DECRYPTED) &&
1667 (status->flag & RX_FLAG_IV_STRIPPED))
1670 hdrlen = ieee80211_hdrlen(fc);
1673 keyidx = iwl80211_get_cs_keyid(cs, rx->skb);
1675 if (unlikely(keyidx < 0))
1676 return RX_DROP_UNUSABLE;
1678 if (rx->skb->len < 8 + hdrlen)
1679 return RX_DROP_UNUSABLE; /* TODO: count this? */
1681 * no need to call ieee80211_wep_get_keyidx,
1682 * it verifies a bunch of things we've done already
1684 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1685 keyidx = keyid >> 6;
1688 /* check per-station GTK first, if multicast packet */
1689 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1690 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1692 /* if not found, try default key */
1694 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1697 * RSNA-protected unicast frames should always be
1698 * sent with pairwise or station-to-station keys,
1699 * but for WEP we allow using a key index as well.
1702 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1703 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1704 !is_multicast_ether_addr(hdr->addr1))
1710 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1711 return RX_DROP_MONITOR;
1713 /* TODO: add threshold stuff again */
1715 return RX_DROP_MONITOR;
1718 switch (rx->key->conf.cipher) {
1719 case WLAN_CIPHER_SUITE_WEP40:
1720 case WLAN_CIPHER_SUITE_WEP104:
1721 result = ieee80211_crypto_wep_decrypt(rx);
1723 case WLAN_CIPHER_SUITE_TKIP:
1724 result = ieee80211_crypto_tkip_decrypt(rx);
1726 case WLAN_CIPHER_SUITE_CCMP:
1727 result = ieee80211_crypto_ccmp_decrypt(
1728 rx, IEEE80211_CCMP_MIC_LEN);
1730 case WLAN_CIPHER_SUITE_CCMP_256:
1731 result = ieee80211_crypto_ccmp_decrypt(
1732 rx, IEEE80211_CCMP_256_MIC_LEN);
1734 case WLAN_CIPHER_SUITE_AES_CMAC:
1735 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1737 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1738 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1740 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1741 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1742 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1744 case WLAN_CIPHER_SUITE_GCMP:
1745 case WLAN_CIPHER_SUITE_GCMP_256:
1746 result = ieee80211_crypto_gcmp_decrypt(rx);
1749 result = ieee80211_crypto_hw_decrypt(rx);
1752 /* the hdr variable is invalid after the decrypt handlers */
1754 /* either the frame has been decrypted or will be dropped */
1755 status->flag |= RX_FLAG_DECRYPTED;
1760 static inline struct ieee80211_fragment_entry *
1761 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1762 unsigned int frag, unsigned int seq, int rx_queue,
1763 struct sk_buff **skb)
1765 struct ieee80211_fragment_entry *entry;
1767 entry = &sdata->fragments[sdata->fragment_next++];
1768 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1769 sdata->fragment_next = 0;
1771 if (!skb_queue_empty(&entry->skb_list))
1772 __skb_queue_purge(&entry->skb_list);
1774 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1776 entry->first_frag_time = jiffies;
1778 entry->rx_queue = rx_queue;
1779 entry->last_frag = frag;
1781 entry->extra_len = 0;
1786 static inline struct ieee80211_fragment_entry *
1787 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
1788 unsigned int frag, unsigned int seq,
1789 int rx_queue, struct ieee80211_hdr *hdr)
1791 struct ieee80211_fragment_entry *entry;
1794 idx = sdata->fragment_next;
1795 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1796 struct ieee80211_hdr *f_hdr;
1800 idx = IEEE80211_FRAGMENT_MAX - 1;
1802 entry = &sdata->fragments[idx];
1803 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1804 entry->rx_queue != rx_queue ||
1805 entry->last_frag + 1 != frag)
1808 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1811 * Check ftype and addresses are equal, else check next fragment
1813 if (((hdr->frame_control ^ f_hdr->frame_control) &
1814 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1815 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1816 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
1819 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1820 __skb_queue_purge(&entry->skb_list);
1829 static ieee80211_rx_result debug_noinline
1830 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1832 struct ieee80211_hdr *hdr;
1835 unsigned int frag, seq;
1836 struct ieee80211_fragment_entry *entry;
1837 struct sk_buff *skb;
1838 struct ieee80211_rx_status *status;
1840 hdr = (struct ieee80211_hdr *)rx->skb->data;
1841 fc = hdr->frame_control;
1843 if (ieee80211_is_ctl(fc))
1846 sc = le16_to_cpu(hdr->seq_ctrl);
1847 frag = sc & IEEE80211_SCTL_FRAG;
1849 if (is_multicast_ether_addr(hdr->addr1)) {
1850 I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
1854 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
1857 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1859 if (skb_linearize(rx->skb))
1860 return RX_DROP_UNUSABLE;
1863 * skb_linearize() might change the skb->data and
1864 * previously cached variables (in this case, hdr) need to
1865 * be refreshed with the new data.
1867 hdr = (struct ieee80211_hdr *)rx->skb->data;
1868 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1871 /* This is the first fragment of a new frame. */
1872 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
1873 rx->seqno_idx, &(rx->skb));
1875 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
1876 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256) &&
1877 ieee80211_has_protected(fc)) {
1878 int queue = rx->security_idx;
1879 /* Store CCMP PN so that we can verify that the next
1880 * fragment has a sequential PN value. */
1882 memcpy(entry->last_pn,
1883 rx->key->u.ccmp.rx_pn[queue],
1884 IEEE80211_CCMP_PN_LEN);
1889 /* This is a fragment for a frame that should already be pending in
1890 * fragment cache. Add this fragment to the end of the pending entry.
1892 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1893 rx->seqno_idx, hdr);
1895 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1896 return RX_DROP_MONITOR;
1899 /* Verify that MPDUs within one MSDU have sequential PN values.
1900 * (IEEE 802.11i, 8.3.3.4.5) */
1903 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
1906 (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
1907 rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256))
1908 return RX_DROP_UNUSABLE;
1909 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
1910 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
1915 queue = rx->security_idx;
1916 rpn = rx->key->u.ccmp.rx_pn[queue];
1917 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
1918 return RX_DROP_UNUSABLE;
1919 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
1922 skb_pull(rx->skb, ieee80211_hdrlen(fc));
1923 __skb_queue_tail(&entry->skb_list, rx->skb);
1924 entry->last_frag = frag;
1925 entry->extra_len += rx->skb->len;
1926 if (ieee80211_has_morefrags(fc)) {
1931 rx->skb = __skb_dequeue(&entry->skb_list);
1932 if (skb_tailroom(rx->skb) < entry->extra_len) {
1933 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
1934 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1936 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1937 __skb_queue_purge(&entry->skb_list);
1938 return RX_DROP_UNUSABLE;
1941 while ((skb = __skb_dequeue(&entry->skb_list))) {
1942 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1946 /* Complete frame has been reassembled - process it now */
1947 status = IEEE80211_SKB_RXCB(rx->skb);
1950 ieee80211_led_rx(rx->local);
1953 rx->sta->rx_stats.packets++;
1957 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1959 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
1965 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1967 struct sk_buff *skb = rx->skb;
1968 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1971 * Pass through unencrypted frames if the hardware has
1972 * decrypted them already.
1974 if (status->flag & RX_FLAG_DECRYPTED)
1977 /* Drop unencrypted frames if key is set. */
1978 if (unlikely(!ieee80211_has_protected(fc) &&
1979 !ieee80211_is_nullfunc(fc) &&
1980 ieee80211_is_data(fc) && rx->key))
1986 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1988 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1989 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1990 __le16 fc = hdr->frame_control;
1993 * Pass through unencrypted frames if the hardware has
1994 * decrypted them already.
1996 if (status->flag & RX_FLAG_DECRYPTED)
1999 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2000 if (unlikely(!ieee80211_has_protected(fc) &&
2001 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2003 if (ieee80211_is_deauth(fc) ||
2004 ieee80211_is_disassoc(fc))
2005 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2010 /* BIP does not use Protected field, so need to check MMIE */
2011 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2012 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2013 if (ieee80211_is_deauth(fc) ||
2014 ieee80211_is_disassoc(fc))
2015 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2021 * When using MFP, Action frames are not allowed prior to
2022 * having configured keys.
2024 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2025 ieee80211_is_robust_mgmt_frame(rx->skb)))
2033 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2035 struct ieee80211_sub_if_data *sdata = rx->sdata;
2036 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2037 bool check_port_control = false;
2038 struct ethhdr *ehdr;
2041 *port_control = false;
2042 if (ieee80211_has_a4(hdr->frame_control) &&
2043 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2046 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2047 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2049 if (!sdata->u.mgd.use_4addr)
2052 check_port_control = true;
2055 if (is_multicast_ether_addr(hdr->addr1) &&
2056 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2059 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2063 ehdr = (struct ethhdr *) rx->skb->data;
2064 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2065 *port_control = true;
2066 else if (check_port_control)
2073 * requires that rx->skb is a frame with ethernet header
2075 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2077 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2078 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2079 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2082 * Allow EAPOL frames to us/the PAE group address regardless
2083 * of whether the frame was encrypted or not.
2085 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
2086 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2087 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
2090 if (ieee80211_802_1x_port_control(rx) ||
2091 ieee80211_drop_unencrypted(rx, fc))
2098 * requires that rx->skb is a frame with ethernet header
2101 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2103 struct ieee80211_sub_if_data *sdata = rx->sdata;
2104 struct net_device *dev = sdata->dev;
2105 struct sk_buff *skb, *xmit_skb;
2106 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2107 struct sta_info *dsta;
2112 ieee80211_rx_stats(dev, skb->len);
2114 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2115 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2116 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2117 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2118 if (is_multicast_ether_addr(ehdr->h_dest)) {
2120 * send multicast frames both to higher layers in
2121 * local net stack and back to the wireless medium
2123 xmit_skb = skb_copy(skb, GFP_ATOMIC);
2125 net_info_ratelimited("%s: failed to clone multicast frame\n",
2128 dsta = sta_info_get(sdata, skb->data);
2131 * The destination station is associated to
2132 * this AP (in this VLAN), so send the frame
2133 * directly to it and do not pass it to local
2142 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2144 /* 'align' will only take the values 0 or 2 here since all
2145 * frames are required to be aligned to 2-byte boundaries
2146 * when being passed to mac80211; the code here works just
2147 * as well if that isn't true, but mac80211 assumes it can
2148 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2152 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2154 if (WARN_ON(skb_headroom(skb) < 3)) {
2158 u8 *data = skb->data;
2159 size_t len = skb_headlen(skb);
2161 memmove(skb->data, data, len);
2162 skb_set_tail_pointer(skb, len);
2169 /* deliver to local stack */
2170 skb->protocol = eth_type_trans(skb, dev);
2171 memset(skb->cb, 0, sizeof(skb->cb));
2173 napi_gro_receive(rx->napi, skb);
2175 netif_receive_skb(skb);
2180 * Send to wireless media and increase priority by 256 to
2181 * keep the received priority instead of reclassifying
2182 * the frame (see cfg80211_classify8021d).
2184 xmit_skb->priority += 256;
2185 xmit_skb->protocol = htons(ETH_P_802_3);
2186 skb_reset_network_header(xmit_skb);
2187 skb_reset_mac_header(xmit_skb);
2188 dev_queue_xmit(xmit_skb);
2192 static ieee80211_rx_result debug_noinline
2193 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2195 struct net_device *dev = rx->sdata->dev;
2196 struct sk_buff *skb = rx->skb;
2197 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2198 __le16 fc = hdr->frame_control;
2199 struct sk_buff_head frame_list;
2200 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2202 if (unlikely(!ieee80211_is_data(fc)))
2205 if (unlikely(!ieee80211_is_data_present(fc)))
2206 return RX_DROP_MONITOR;
2208 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2211 if (ieee80211_has_a4(hdr->frame_control) &&
2212 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2213 !rx->sdata->u.vlan.sta)
2214 return RX_DROP_UNUSABLE;
2216 if (is_multicast_ether_addr(hdr->addr1) &&
2217 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2218 rx->sdata->u.vlan.sta) ||
2219 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
2220 rx->sdata->u.mgd.use_4addr)))
2221 return RX_DROP_UNUSABLE;
2224 __skb_queue_head_init(&frame_list);
2226 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2227 rx->sdata->vif.type,
2228 rx->local->hw.extra_tx_headroom, true);
2230 while (!skb_queue_empty(&frame_list)) {
2231 rx->skb = __skb_dequeue(&frame_list);
2233 if (!ieee80211_frame_allowed(rx, fc)) {
2234 dev_kfree_skb(rx->skb);
2238 ieee80211_deliver_skb(rx);
2244 #ifdef CONFIG_MAC80211_MESH
2245 static ieee80211_rx_result
2246 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2248 struct ieee80211_hdr *fwd_hdr, *hdr;
2249 struct ieee80211_tx_info *info;
2250 struct ieee80211s_hdr *mesh_hdr;
2251 struct sk_buff *skb = rx->skb, *fwd_skb;
2252 struct ieee80211_local *local = rx->local;
2253 struct ieee80211_sub_if_data *sdata = rx->sdata;
2254 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2257 hdr = (struct ieee80211_hdr *) skb->data;
2258 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2260 /* make sure fixed part of mesh header is there, also checks skb len */
2261 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2262 return RX_DROP_MONITOR;
2264 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2266 /* make sure full mesh header is there, also checks skb len */
2267 if (!pskb_may_pull(rx->skb,
2268 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2269 return RX_DROP_MONITOR;
2271 /* reload pointers */
2272 hdr = (struct ieee80211_hdr *) skb->data;
2273 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2275 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2276 return RX_DROP_MONITOR;
2278 /* frame is in RMC, don't forward */
2279 if (ieee80211_is_data(hdr->frame_control) &&
2280 is_multicast_ether_addr(hdr->addr1) &&
2281 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2282 return RX_DROP_MONITOR;
2284 if (!ieee80211_is_data(hdr->frame_control))
2288 return RX_DROP_MONITOR;
2290 if (mesh_hdr->flags & MESH_FLAGS_AE) {
2291 struct mesh_path *mppath;
2295 if (is_multicast_ether_addr(hdr->addr1)) {
2296 mpp_addr = hdr->addr3;
2297 proxied_addr = mesh_hdr->eaddr1;
2298 } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
2299 /* has_a4 already checked in ieee80211_rx_mesh_check */
2300 mpp_addr = hdr->addr4;
2301 proxied_addr = mesh_hdr->eaddr2;
2303 return RX_DROP_MONITOR;
2307 mppath = mpp_path_lookup(sdata, proxied_addr);
2309 mpp_path_add(sdata, proxied_addr, mpp_addr);
2311 spin_lock_bh(&mppath->state_lock);
2312 if (!ether_addr_equal(mppath->mpp, mpp_addr))
2313 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2314 mppath->exp_time = jiffies;
2315 spin_unlock_bh(&mppath->state_lock);
2320 /* Frame has reached destination. Don't forward */
2321 if (!is_multicast_ether_addr(hdr->addr1) &&
2322 ether_addr_equal(sdata->vif.addr, hdr->addr3))
2325 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2326 q = sdata->vif.hw_queue[ac];
2327 if (ieee80211_queue_stopped(&local->hw, q)) {
2328 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2329 return RX_DROP_MONITOR;
2331 skb_set_queue_mapping(skb, q);
2333 if (!--mesh_hdr->ttl) {
2334 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
2338 if (!ifmsh->mshcfg.dot11MeshForwarding)
2341 fwd_skb = skb_copy(skb, GFP_ATOMIC);
2343 net_info_ratelimited("%s: failed to clone mesh frame\n",
2348 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
2349 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2350 info = IEEE80211_SKB_CB(fwd_skb);
2351 memset(info, 0, sizeof(*info));
2352 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2353 info->control.vif = &rx->sdata->vif;
2354 info->control.jiffies = jiffies;
2355 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2356 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2357 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2358 /* update power mode indication when forwarding */
2359 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2360 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2361 /* mesh power mode flags updated in mesh_nexthop_lookup */
2362 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2364 /* unable to resolve next hop */
2365 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2367 WLAN_REASON_MESH_PATH_NOFORWARD,
2369 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2371 return RX_DROP_MONITOR;
2374 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2375 ieee80211_add_pending_skb(local, fwd_skb);
2377 if (is_multicast_ether_addr(hdr->addr1))
2379 return RX_DROP_MONITOR;
2383 static ieee80211_rx_result debug_noinline
2384 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2386 struct ieee80211_sub_if_data *sdata = rx->sdata;
2387 struct ieee80211_local *local = rx->local;
2388 struct net_device *dev = sdata->dev;
2389 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2390 __le16 fc = hdr->frame_control;
2394 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2397 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2398 return RX_DROP_MONITOR;
2401 /* The seqno index has the same property as needed
2402 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2403 * for non-QoS-data frames. Here we know it's a data
2404 * frame, so count MSDUs.
2406 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2410 * Send unexpected-4addr-frame event to hostapd. For older versions,
2411 * also drop the frame to cooked monitor interfaces.
2413 if (ieee80211_has_a4(hdr->frame_control) &&
2414 sdata->vif.type == NL80211_IFTYPE_AP) {
2416 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2417 cfg80211_rx_unexpected_4addr_frame(
2418 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2419 return RX_DROP_MONITOR;
2422 err = __ieee80211_data_to_8023(rx, &port_control);
2424 return RX_DROP_UNUSABLE;
2426 if (!ieee80211_frame_allowed(rx, fc))
2427 return RX_DROP_MONITOR;
2429 /* directly handle TDLS channel switch requests/responses */
2430 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2431 cpu_to_be16(ETH_P_TDLS))) {
2432 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2434 if (pskb_may_pull(rx->skb,
2435 offsetof(struct ieee80211_tdls_data, u)) &&
2436 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2437 tf->category == WLAN_CATEGORY_TDLS &&
2438 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2439 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
2440 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2441 schedule_work(&local->tdls_chsw_work);
2443 rx->sta->rx_stats.packets++;
2449 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2450 unlikely(port_control) && sdata->bss) {
2451 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2459 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2460 !is_multicast_ether_addr(
2461 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2462 (!local->scanning &&
2463 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
2464 mod_timer(&local->dynamic_ps_timer, jiffies +
2465 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2468 ieee80211_deliver_skb(rx);
2473 static ieee80211_rx_result debug_noinline
2474 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
2476 struct sk_buff *skb = rx->skb;
2477 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2478 struct tid_ampdu_rx *tid_agg_rx;
2482 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2485 if (ieee80211_is_back_req(bar->frame_control)) {
2487 __le16 control, start_seq_num;
2488 } __packed bar_data;
2489 struct ieee80211_event event = {
2490 .type = BAR_RX_EVENT,
2494 return RX_DROP_MONITOR;
2496 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2497 &bar_data, sizeof(bar_data)))
2498 return RX_DROP_MONITOR;
2500 tid = le16_to_cpu(bar_data.control) >> 12;
2502 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2504 return RX_DROP_MONITOR;
2506 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2507 event.u.ba.tid = tid;
2508 event.u.ba.ssn = start_seq_num;
2509 event.u.ba.sta = &rx->sta->sta;
2511 /* reset session timer */
2512 if (tid_agg_rx->timeout)
2513 mod_timer(&tid_agg_rx->session_timer,
2514 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2516 spin_lock(&tid_agg_rx->reorder_lock);
2517 /* release stored frames up to start of BAR */
2518 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2519 start_seq_num, frames);
2520 spin_unlock(&tid_agg_rx->reorder_lock);
2522 drv_event_callback(rx->local, rx->sdata, &event);
2529 * After this point, we only want management frames,
2530 * so we can drop all remaining control frames to
2531 * cooked monitor interfaces.
2533 return RX_DROP_MONITOR;
2536 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2537 struct ieee80211_mgmt *mgmt,
2540 struct ieee80211_local *local = sdata->local;
2541 struct sk_buff *skb;
2542 struct ieee80211_mgmt *resp;
2544 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2545 /* Not to own unicast address */
2549 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2550 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2551 /* Not from the current AP or not associated yet. */
2555 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2556 /* Too short SA Query request frame */
2560 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2564 skb_reserve(skb, local->hw.extra_tx_headroom);
2565 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2566 memset(resp, 0, 24);
2567 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2568 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2569 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2570 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2571 IEEE80211_STYPE_ACTION);
2572 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2573 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2574 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2575 memcpy(resp->u.action.u.sa_query.trans_id,
2576 mgmt->u.action.u.sa_query.trans_id,
2577 WLAN_SA_QUERY_TR_ID_LEN);
2579 ieee80211_tx_skb(sdata, skb);
2582 static ieee80211_rx_result debug_noinline
2583 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2585 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2586 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2589 * From here on, look only at management frames.
2590 * Data and control frames are already handled,
2591 * and unknown (reserved) frames are useless.
2593 if (rx->skb->len < 24)
2594 return RX_DROP_MONITOR;
2596 if (!ieee80211_is_mgmt(mgmt->frame_control))
2597 return RX_DROP_MONITOR;
2599 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2600 ieee80211_is_beacon(mgmt->frame_control) &&
2601 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2604 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
2605 sig = status->signal;
2607 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2608 rx->skb->data, rx->skb->len,
2610 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2613 if (ieee80211_drop_unencrypted_mgmt(rx))
2614 return RX_DROP_UNUSABLE;
2619 static ieee80211_rx_result debug_noinline
2620 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2622 struct ieee80211_local *local = rx->local;
2623 struct ieee80211_sub_if_data *sdata = rx->sdata;
2624 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2625 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2626 int len = rx->skb->len;
2628 if (!ieee80211_is_action(mgmt->frame_control))
2631 /* drop too small frames */
2632 if (len < IEEE80211_MIN_ACTION_SIZE)
2633 return RX_DROP_UNUSABLE;
2635 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
2636 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2637 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
2638 return RX_DROP_UNUSABLE;
2640 switch (mgmt->u.action.category) {
2641 case WLAN_CATEGORY_HT:
2642 /* reject HT action frames from stations not supporting HT */
2643 if (!rx->sta->sta.ht_cap.ht_supported)
2646 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2647 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2648 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2649 sdata->vif.type != NL80211_IFTYPE_AP &&
2650 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2653 /* verify action & smps_control/chanwidth are present */
2654 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2657 switch (mgmt->u.action.u.ht_smps.action) {
2658 case WLAN_HT_ACTION_SMPS: {
2659 struct ieee80211_supported_band *sband;
2660 enum ieee80211_smps_mode smps_mode;
2662 /* convert to HT capability */
2663 switch (mgmt->u.action.u.ht_smps.smps_control) {
2664 case WLAN_HT_SMPS_CONTROL_DISABLED:
2665 smps_mode = IEEE80211_SMPS_OFF;
2667 case WLAN_HT_SMPS_CONTROL_STATIC:
2668 smps_mode = IEEE80211_SMPS_STATIC;
2670 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
2671 smps_mode = IEEE80211_SMPS_DYNAMIC;
2677 /* if no change do nothing */
2678 if (rx->sta->sta.smps_mode == smps_mode)
2680 rx->sta->sta.smps_mode = smps_mode;
2682 sband = rx->local->hw.wiphy->bands[status->band];
2684 rate_control_rate_update(local, sband, rx->sta,
2685 IEEE80211_RC_SMPS_CHANGED);
2688 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2689 struct ieee80211_supported_band *sband;
2690 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
2691 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
2693 /* If it doesn't support 40 MHz it can't change ... */
2694 if (!(rx->sta->sta.ht_cap.cap &
2695 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
2698 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
2699 max_bw = IEEE80211_STA_RX_BW_20;
2701 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
2703 /* set cur_max_bandwidth and recalc sta bw */
2704 rx->sta->cur_max_bandwidth = max_bw;
2705 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
2707 if (rx->sta->sta.bandwidth == new_bw)
2710 rx->sta->sta.bandwidth = new_bw;
2711 sband = rx->local->hw.wiphy->bands[status->band];
2713 rate_control_rate_update(local, sband, rx->sta,
2714 IEEE80211_RC_BW_CHANGED);
2722 case WLAN_CATEGORY_PUBLIC:
2723 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2725 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2729 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
2731 if (mgmt->u.action.u.ext_chan_switch.action_code !=
2732 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
2734 if (len < offsetof(struct ieee80211_mgmt,
2735 u.action.u.ext_chan_switch.variable))
2738 case WLAN_CATEGORY_VHT:
2739 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2740 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2741 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2742 sdata->vif.type != NL80211_IFTYPE_AP &&
2743 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2746 /* verify action code is present */
2747 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2750 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
2751 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
2754 /* verify opmode is present */
2755 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2758 opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
2760 ieee80211_vht_handle_opmode(rx->sdata, rx->sta,
2761 opmode, status->band);
2764 case WLAN_VHT_ACTION_GROUPID_MGMT: {
2765 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
2773 case WLAN_CATEGORY_BACK:
2774 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2775 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2776 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2777 sdata->vif.type != NL80211_IFTYPE_AP &&
2778 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2781 /* verify action_code is present */
2782 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2785 switch (mgmt->u.action.u.addba_req.action_code) {
2786 case WLAN_ACTION_ADDBA_REQ:
2787 if (len < (IEEE80211_MIN_ACTION_SIZE +
2788 sizeof(mgmt->u.action.u.addba_req)))
2791 case WLAN_ACTION_ADDBA_RESP:
2792 if (len < (IEEE80211_MIN_ACTION_SIZE +
2793 sizeof(mgmt->u.action.u.addba_resp)))
2796 case WLAN_ACTION_DELBA:
2797 if (len < (IEEE80211_MIN_ACTION_SIZE +
2798 sizeof(mgmt->u.action.u.delba)))
2806 case WLAN_CATEGORY_SPECTRUM_MGMT:
2807 /* verify action_code is present */
2808 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2811 switch (mgmt->u.action.u.measurement.action_code) {
2812 case WLAN_ACTION_SPCT_MSR_REQ:
2813 if (status->band != IEEE80211_BAND_5GHZ)
2816 if (len < (IEEE80211_MIN_ACTION_SIZE +
2817 sizeof(mgmt->u.action.u.measurement)))
2820 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2823 ieee80211_process_measurement_req(sdata, mgmt, len);
2825 case WLAN_ACTION_SPCT_CHL_SWITCH: {
2827 if (len < (IEEE80211_MIN_ACTION_SIZE +
2828 sizeof(mgmt->u.action.u.chan_switch)))
2831 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2832 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2833 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
2836 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2837 bssid = sdata->u.mgd.bssid;
2838 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2839 bssid = sdata->u.ibss.bssid;
2840 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
2845 if (!ether_addr_equal(mgmt->bssid, bssid))
2852 case WLAN_CATEGORY_SA_QUERY:
2853 if (len < (IEEE80211_MIN_ACTION_SIZE +
2854 sizeof(mgmt->u.action.u.sa_query)))
2857 switch (mgmt->u.action.u.sa_query.action) {
2858 case WLAN_ACTION_SA_QUERY_REQUEST:
2859 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2861 ieee80211_process_sa_query_req(sdata, mgmt, len);
2865 case WLAN_CATEGORY_SELF_PROTECTED:
2866 if (len < (IEEE80211_MIN_ACTION_SIZE +
2867 sizeof(mgmt->u.action.u.self_prot.action_code)))
2870 switch (mgmt->u.action.u.self_prot.action_code) {
2871 case WLAN_SP_MESH_PEERING_OPEN:
2872 case WLAN_SP_MESH_PEERING_CLOSE:
2873 case WLAN_SP_MESH_PEERING_CONFIRM:
2874 if (!ieee80211_vif_is_mesh(&sdata->vif))
2876 if (sdata->u.mesh.user_mpm)
2877 /* userspace handles this frame */
2880 case WLAN_SP_MGK_INFORM:
2881 case WLAN_SP_MGK_ACK:
2882 if (!ieee80211_vif_is_mesh(&sdata->vif))
2887 case WLAN_CATEGORY_MESH_ACTION:
2888 if (len < (IEEE80211_MIN_ACTION_SIZE +
2889 sizeof(mgmt->u.action.u.mesh_action.action_code)))
2892 if (!ieee80211_vif_is_mesh(&sdata->vif))
2894 if (mesh_action_is_path_sel(mgmt) &&
2895 !mesh_path_sel_is_hwmp(sdata))
2903 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
2904 /* will return in the next handlers */
2909 rx->sta->rx_stats.packets++;
2910 dev_kfree_skb(rx->skb);
2914 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2915 skb_queue_tail(&sdata->skb_queue, rx->skb);
2916 ieee80211_queue_work(&local->hw, &sdata->work);
2918 rx->sta->rx_stats.packets++;
2922 static ieee80211_rx_result debug_noinline
2923 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2925 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2928 /* skip known-bad action frames and return them in the next handler */
2929 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
2933 * Getting here means the kernel doesn't know how to handle
2934 * it, but maybe userspace does ... include returned frames
2935 * so userspace can register for those to know whether ones
2936 * it transmitted were processed or returned.
2939 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
2940 sig = status->signal;
2942 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
2943 rx->skb->data, rx->skb->len, 0)) {
2945 rx->sta->rx_stats.packets++;
2946 dev_kfree_skb(rx->skb);
2953 static ieee80211_rx_result debug_noinline
2954 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2956 struct ieee80211_local *local = rx->local;
2957 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2958 struct sk_buff *nskb;
2959 struct ieee80211_sub_if_data *sdata = rx->sdata;
2960 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2962 if (!ieee80211_is_action(mgmt->frame_control))
2966 * For AP mode, hostapd is responsible for handling any action
2967 * frames that we didn't handle, including returning unknown
2968 * ones. For all other modes we will return them to the sender,
2969 * setting the 0x80 bit in the action category, as required by
2970 * 802.11-2012 9.24.4.
2971 * Newer versions of hostapd shall also use the management frame
2972 * registration mechanisms, but older ones still use cooked
2973 * monitor interfaces so push all frames there.
2975 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
2976 (sdata->vif.type == NL80211_IFTYPE_AP ||
2977 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2978 return RX_DROP_MONITOR;
2980 if (is_multicast_ether_addr(mgmt->da))
2981 return RX_DROP_MONITOR;
2983 /* do not return rejected action frames */
2984 if (mgmt->u.action.category & 0x80)
2985 return RX_DROP_UNUSABLE;
2987 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2990 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
2992 nmgmt->u.action.category |= 0x80;
2993 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2994 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
2996 memset(nskb->cb, 0, sizeof(nskb->cb));
2998 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
2999 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3001 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3002 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3003 IEEE80211_TX_CTL_NO_CCK_RATE;
3004 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3006 local->hw.offchannel_tx_hw_queue;
3009 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3012 dev_kfree_skb(rx->skb);
3016 static ieee80211_rx_result debug_noinline
3017 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3019 struct ieee80211_sub_if_data *sdata = rx->sdata;
3020 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3023 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3025 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3026 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3027 sdata->vif.type != NL80211_IFTYPE_OCB &&
3028 sdata->vif.type != NL80211_IFTYPE_STATION)
3029 return RX_DROP_MONITOR;
3032 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3033 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3034 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3035 /* process for all: mesh, mlme, ibss */
3037 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3038 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3039 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3040 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3041 if (is_multicast_ether_addr(mgmt->da) &&
3042 !is_broadcast_ether_addr(mgmt->da))
3043 return RX_DROP_MONITOR;
3045 /* process only for station */
3046 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3047 return RX_DROP_MONITOR;
3049 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3050 /* process only for ibss and mesh */
3051 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3052 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3053 return RX_DROP_MONITOR;
3056 return RX_DROP_MONITOR;
3059 /* queue up frame and kick off work to process it */
3060 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
3061 skb_queue_tail(&sdata->skb_queue, rx->skb);
3062 ieee80211_queue_work(&rx->local->hw, &sdata->work);
3064 rx->sta->rx_stats.packets++;
3069 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3070 struct ieee80211_rate *rate)
3072 struct ieee80211_sub_if_data *sdata;
3073 struct ieee80211_local *local = rx->local;
3074 struct sk_buff *skb = rx->skb, *skb2;
3075 struct net_device *prev_dev = NULL;
3076 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3077 int needed_headroom;
3080 * If cooked monitor has been processed already, then
3081 * don't do it again. If not, set the flag.
3083 if (rx->flags & IEEE80211_RX_CMNTR)
3085 rx->flags |= IEEE80211_RX_CMNTR;
3087 /* If there are no cooked monitor interfaces, just free the SKB */
3088 if (!local->cooked_mntrs)
3091 /* vendor data is long removed here */
3092 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3093 /* room for the radiotap header based on driver features */
3094 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3096 if (skb_headroom(skb) < needed_headroom &&
3097 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3100 /* prepend radiotap information */
3101 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3104 skb_set_mac_header(skb, 0);
3105 skb->ip_summed = CHECKSUM_UNNECESSARY;
3106 skb->pkt_type = PACKET_OTHERHOST;
3107 skb->protocol = htons(ETH_P_802_2);
3109 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3110 if (!ieee80211_sdata_running(sdata))
3113 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3114 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
3118 skb2 = skb_clone(skb, GFP_ATOMIC);
3120 skb2->dev = prev_dev;
3121 netif_receive_skb(skb2);
3125 prev_dev = sdata->dev;
3126 ieee80211_rx_stats(sdata->dev, skb->len);
3130 skb->dev = prev_dev;
3131 netif_receive_skb(skb);
3139 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3140 ieee80211_rx_result res)
3143 case RX_DROP_MONITOR:
3144 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3146 rx->sta->rx_stats.dropped++;
3149 struct ieee80211_rate *rate = NULL;
3150 struct ieee80211_supported_band *sband;
3151 struct ieee80211_rx_status *status;
3153 status = IEEE80211_SKB_RXCB((rx->skb));
3155 sband = rx->local->hw.wiphy->bands[status->band];
3156 if (!(status->flag & RX_FLAG_HT) &&
3157 !(status->flag & RX_FLAG_VHT))
3158 rate = &sband->bitrates[status->rate_idx];
3160 ieee80211_rx_cooked_monitor(rx, rate);
3163 case RX_DROP_UNUSABLE:
3164 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3166 rx->sta->rx_stats.dropped++;
3167 dev_kfree_skb(rx->skb);
3170 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3175 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3176 struct sk_buff_head *frames)
3178 ieee80211_rx_result res = RX_DROP_MONITOR;
3179 struct sk_buff *skb;
3181 #define CALL_RXH(rxh) \
3184 if (res != RX_CONTINUE) \
3188 /* Lock here to avoid hitting all of the data used in the RX
3189 * path (e.g. key data, station data, ...) concurrently when
3190 * a frame is released from the reorder buffer due to timeout
3191 * from the timer, potentially concurrently with RX from the
3194 spin_lock_bh(&rx->local->rx_path_lock);
3196 while ((skb = __skb_dequeue(frames))) {
3198 * all the other fields are valid across frames
3199 * that belong to an aMPDU since they are on the
3200 * same TID from the same station
3204 CALL_RXH(ieee80211_rx_h_check_more_data)
3205 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
3206 CALL_RXH(ieee80211_rx_h_sta_process)
3207 CALL_RXH(ieee80211_rx_h_decrypt)
3208 CALL_RXH(ieee80211_rx_h_defragment)
3209 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
3210 /* must be after MMIC verify so header is counted in MPDU mic */
3211 #ifdef CONFIG_MAC80211_MESH
3212 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3213 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3215 CALL_RXH(ieee80211_rx_h_amsdu)
3216 CALL_RXH(ieee80211_rx_h_data)
3218 /* special treatment -- needs the queue */
3219 res = ieee80211_rx_h_ctrl(rx, frames);
3220 if (res != RX_CONTINUE)
3223 CALL_RXH(ieee80211_rx_h_mgmt_check)
3224 CALL_RXH(ieee80211_rx_h_action)
3225 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
3226 CALL_RXH(ieee80211_rx_h_action_return)
3227 CALL_RXH(ieee80211_rx_h_mgmt)
3230 ieee80211_rx_handlers_result(rx, res);
3235 spin_unlock_bh(&rx->local->rx_path_lock);
3238 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3240 struct sk_buff_head reorder_release;
3241 ieee80211_rx_result res = RX_DROP_MONITOR;
3243 __skb_queue_head_init(&reorder_release);
3245 #define CALL_RXH(rxh) \
3248 if (res != RX_CONTINUE) \
3252 CALL_RXH(ieee80211_rx_h_check_dup)
3253 CALL_RXH(ieee80211_rx_h_check)
3255 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3257 ieee80211_rx_handlers(rx, &reorder_release);
3261 ieee80211_rx_handlers_result(rx, res);
3267 * This function makes calls into the RX path, therefore
3268 * it has to be invoked under RCU read lock.
3270 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3272 struct sk_buff_head frames;
3273 struct ieee80211_rx_data rx = {
3275 .sdata = sta->sdata,
3276 .local = sta->local,
3277 /* This is OK -- must be QoS data frame */
3278 .security_idx = tid,
3280 .napi = NULL, /* must be NULL to not have races */
3282 struct tid_ampdu_rx *tid_agg_rx;
3284 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3288 __skb_queue_head_init(&frames);
3290 spin_lock(&tid_agg_rx->reorder_lock);
3291 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3292 spin_unlock(&tid_agg_rx->reorder_lock);
3294 if (!skb_queue_empty(&frames)) {
3295 struct ieee80211_event event = {
3296 .type = BA_FRAME_TIMEOUT,
3298 .u.ba.sta = &sta->sta,
3300 drv_event_callback(rx.local, rx.sdata, &event);
3303 ieee80211_rx_handlers(&rx, &frames);
3306 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3307 u16 ssn, u64 filtered,
3310 struct sta_info *sta;
3311 struct tid_ampdu_rx *tid_agg_rx;
3312 struct sk_buff_head frames;
3313 struct ieee80211_rx_data rx = {
3314 /* This is OK -- must be QoS data frame */
3315 .security_idx = tid,
3320 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3323 __skb_queue_head_init(&frames);
3325 sta = container_of(pubsta, struct sta_info, sta);
3328 rx.sdata = sta->sdata;
3329 rx.local = sta->local;
3332 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3336 spin_lock_bh(&tid_agg_rx->reorder_lock);
3338 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3341 /* release all frames in the reorder buffer */
3342 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3343 IEEE80211_SN_MODULO;
3344 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3346 /* update ssn to match received ssn */
3347 tid_agg_rx->head_seq_num = ssn;
3349 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3353 /* handle the case that received ssn is behind the mac ssn.
3354 * it can be tid_agg_rx->buf_size behind and still be valid */
3355 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3356 if (diff >= tid_agg_rx->buf_size) {
3357 tid_agg_rx->reorder_buf_filtered = 0;
3360 filtered = filtered >> diff;
3364 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3365 int index = (ssn + i) % tid_agg_rx->buf_size;
3367 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3368 if (filtered & BIT_ULL(i))
3369 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3372 /* now process also frames that the filter marking released */
3373 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3376 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3378 ieee80211_rx_handlers(&rx, &frames);
3383 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3385 /* main receive path */
3387 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3389 struct ieee80211_sub_if_data *sdata = rx->sdata;
3390 struct sk_buff *skb = rx->skb;
3391 struct ieee80211_hdr *hdr = (void *)skb->data;
3392 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3393 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
3394 int multicast = is_multicast_ether_addr(hdr->addr1);
3396 switch (sdata->vif.type) {
3397 case NL80211_IFTYPE_STATION:
3398 if (!bssid && !sdata->u.mgd.use_4addr)
3402 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3403 case NL80211_IFTYPE_ADHOC:
3406 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3407 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
3409 if (ieee80211_is_beacon(hdr->frame_control))
3411 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
3414 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3418 if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
3419 rate_idx = 0; /* TODO: HT/VHT rates */
3421 rate_idx = status->rate_idx;
3422 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3426 case NL80211_IFTYPE_OCB:
3429 if (!ieee80211_is_data_present(hdr->frame_control))
3431 if (!is_broadcast_ether_addr(bssid))
3434 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
3438 if (status->flag & RX_FLAG_HT)
3439 rate_idx = 0; /* TODO: HT rates */
3441 rate_idx = status->rate_idx;
3442 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3446 case NL80211_IFTYPE_MESH_POINT:
3449 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3450 case NL80211_IFTYPE_AP_VLAN:
3451 case NL80211_IFTYPE_AP:
3453 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3455 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
3457 * Accept public action frames even when the
3458 * BSSID doesn't match, this is used for P2P
3459 * and location updates. Note that mac80211
3460 * itself never looks at these frames.
3463 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3465 if (ieee80211_is_public_action(hdr, skb->len))
3467 return ieee80211_is_beacon(hdr->frame_control);
3470 if (!ieee80211_has_tods(hdr->frame_control)) {
3471 /* ignore data frames to TDLS-peers */
3472 if (ieee80211_is_data(hdr->frame_control))
3474 /* ignore action frames to TDLS-peers */
3475 if (ieee80211_is_action(hdr->frame_control) &&
3476 !ether_addr_equal(bssid, hdr->addr1))
3480 case NL80211_IFTYPE_WDS:
3481 if (bssid || !ieee80211_is_data(hdr->frame_control))
3483 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
3484 case NL80211_IFTYPE_P2P_DEVICE:
3485 return ieee80211_is_public_action(hdr, skb->len) ||
3486 ieee80211_is_probe_req(hdr->frame_control) ||
3487 ieee80211_is_probe_resp(hdr->frame_control) ||
3488 ieee80211_is_beacon(hdr->frame_control);
3498 * This function returns whether or not the SKB
3499 * was destined for RX processing or not, which,
3500 * if consume is true, is equivalent to whether
3501 * or not the skb was consumed.
3503 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
3504 struct sk_buff *skb, bool consume)
3506 struct ieee80211_local *local = rx->local;
3507 struct ieee80211_sub_if_data *sdata = rx->sdata;
3511 if (!ieee80211_accept_frame(rx))
3515 skb = skb_copy(skb, GFP_ATOMIC);
3517 if (net_ratelimit())
3518 wiphy_debug(local->hw.wiphy,
3519 "failed to copy skb for %s\n",
3527 ieee80211_invoke_rx_handlers(rx);
3532 * This is the actual Rx frames handler. as it belongs to Rx path it must
3533 * be called with rcu_read_lock protection.
3535 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
3536 struct sk_buff *skb,
3537 struct napi_struct *napi)
3539 struct ieee80211_local *local = hw_to_local(hw);
3540 struct ieee80211_sub_if_data *sdata;
3541 struct ieee80211_hdr *hdr;
3543 struct ieee80211_rx_data rx;
3544 struct ieee80211_sub_if_data *prev;
3545 struct sta_info *sta, *prev_sta;
3546 struct rhash_head *tmp;
3549 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
3550 memset(&rx, 0, sizeof(rx));
3555 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
3556 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
3558 if (ieee80211_is_mgmt(fc)) {
3559 /* drop frame if too short for header */
3560 if (skb->len < ieee80211_hdrlen(fc))
3563 err = skb_linearize(skb);
3565 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
3573 hdr = (struct ieee80211_hdr *)skb->data;
3574 ieee80211_parse_qos(&rx);
3575 ieee80211_verify_alignment(&rx);
3577 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
3578 ieee80211_is_beacon(hdr->frame_control)))
3579 ieee80211_scan_rx(local, skb);
3581 if (ieee80211_is_data(fc)) {
3582 const struct bucket_table *tbl;
3586 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
3588 for_each_sta_info(local, tbl, hdr->addr2, sta, tmp) {
3595 rx.sdata = prev_sta->sdata;
3596 ieee80211_prepare_and_rx_handle(&rx, skb, false);
3603 rx.sdata = prev_sta->sdata;
3605 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3613 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3614 if (!ieee80211_sdata_running(sdata))
3617 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
3618 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3622 * frame is destined for this interface, but if it's
3623 * not also for the previous one we handle that after
3624 * the loop to avoid copying the SKB once too much
3632 rx.sta = sta_info_get_bss(prev, hdr->addr2);
3634 ieee80211_prepare_and_rx_handle(&rx, skb, false);
3640 rx.sta = sta_info_get_bss(prev, hdr->addr2);
3643 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3652 * This is the receive path handler. It is called by a low level driver when an
3653 * 802.11 MPDU is received from the hardware.
3655 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct sk_buff *skb,
3656 struct napi_struct *napi)
3658 struct ieee80211_local *local = hw_to_local(hw);
3659 struct ieee80211_rate *rate = NULL;
3660 struct ieee80211_supported_band *sband;
3661 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3663 WARN_ON_ONCE(softirq_count() == 0);
3665 if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
3668 sband = local->hw.wiphy->bands[status->band];
3669 if (WARN_ON(!sband))
3673 * If we're suspending, it is possible although not too likely
3674 * that we'd be receiving frames after having already partially
3675 * quiesced the stack. We can't process such frames then since
3676 * that might, for example, cause stations to be added or other
3677 * driver callbacks be invoked.
3679 if (unlikely(local->quiescing || local->suspended))
3682 /* We might be during a HW reconfig, prevent Rx for the same reason */
3683 if (unlikely(local->in_reconfig))
3687 * The same happens when we're not even started,
3688 * but that's worth a warning.
3690 if (WARN_ON(!local->started))
3693 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
3695 * Validate the rate, unless a PLCP error means that
3696 * we probably can't have a valid rate here anyway.
3699 if (status->flag & RX_FLAG_HT) {
3701 * rate_idx is MCS index, which can be [0-76]
3704 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
3706 * Anything else would be some sort of driver or
3707 * hardware error. The driver should catch hardware
3710 if (WARN(status->rate_idx > 76,
3711 "Rate marked as an HT rate but passed "
3712 "status->rate_idx is not "
3713 "an MCS index [0-76]: %d (0x%02x)\n",
3717 } else if (status->flag & RX_FLAG_VHT) {
3718 if (WARN_ONCE(status->rate_idx > 9 ||
3720 status->vht_nss > 8,
3721 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
3722 status->rate_idx, status->vht_nss))
3725 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
3727 rate = &sband->bitrates[status->rate_idx];
3731 status->rx_flags = 0;
3734 * key references and virtual interfaces are protected using RCU
3735 * and this requires that we are in a read-side RCU section during
3736 * receive processing
3741 * Frames with failed FCS/PLCP checksum are not returned,
3742 * all other frames are returned without radiotap header
3743 * if it was previously present.
3744 * Also, frames with less than 16 bytes are dropped.
3746 skb = ieee80211_rx_monitor(local, skb, rate);
3752 ieee80211_tpt_led_trig_rx(local,
3753 ((struct ieee80211_hdr *)skb->data)->frame_control,
3755 __ieee80211_rx_handle_packet(hw, skb, napi);
3763 EXPORT_SYMBOL(ieee80211_rx_napi);
3765 /* This is a version of the rx handler that can be called from hard irq
3766 * context. Post the skb on the queue and schedule the tasklet */
3767 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
3769 struct ieee80211_local *local = hw_to_local(hw);
3771 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3773 skb->pkt_type = IEEE80211_RX_MSG;
3774 skb_queue_tail(&local->skb_queue, skb);
3775 tasklet_schedule(&local->tasklet);
3777 EXPORT_SYMBOL(ieee80211_rx_irqsafe);