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>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/jiffies.h>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/rcupdate.h>
19 #include <linux/export.h>
20 #include <net/mac80211.h>
21 #include <net/ieee80211_radiotap.h>
22 #include <asm/unaligned.h>
24 #include "ieee80211_i.h"
25 #include "driver-ops.h"
35 * monitor mode reception
37 * This function cleans up the SKB, i.e. it removes all the stuff
38 * only useful for monitoring.
40 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
43 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
44 if (likely(skb->len > FCS_LEN))
45 __pskb_trim(skb, skb->len - FCS_LEN);
57 static inline int should_drop_frame(struct sk_buff *skb,
60 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
61 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
63 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
65 if (unlikely(skb->len < 16 + present_fcs_len))
67 if (ieee80211_is_ctl(hdr->frame_control) &&
68 !ieee80211_is_pspoll(hdr->frame_control) &&
69 !ieee80211_is_back_req(hdr->frame_control))
75 ieee80211_rx_radiotap_len(struct ieee80211_local *local,
76 struct ieee80211_rx_status *status)
80 /* always present fields */
81 len = sizeof(struct ieee80211_radiotap_header) + 9;
83 if (status->flag & RX_FLAG_MACTIME_MPDU)
85 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
88 if (len & 1) /* padding for RX_FLAGS if necessary */
91 if (status->flag & RX_FLAG_HT) /* HT info */
98 * ieee80211_add_rx_radiotap_header - add radiotap header
100 * add a radiotap header containing all the fields which the hardware provided.
103 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
105 struct ieee80211_rate *rate,
106 int rtap_len, bool has_fcs)
108 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
109 struct ieee80211_radiotap_header *rthdr;
113 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
114 memset(rthdr, 0, rtap_len);
116 /* radiotap header, set always present flags */
118 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
119 (1 << IEEE80211_RADIOTAP_CHANNEL) |
120 (1 << IEEE80211_RADIOTAP_ANTENNA) |
121 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
122 rthdr->it_len = cpu_to_le16(rtap_len);
124 pos = (unsigned char *)(rthdr+1);
126 /* the order of the following fields is important */
128 /* IEEE80211_RADIOTAP_TSFT */
129 if (status->flag & RX_FLAG_MACTIME_MPDU) {
130 put_unaligned_le64(status->mactime, pos);
132 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
136 /* IEEE80211_RADIOTAP_FLAGS */
137 if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
138 *pos |= IEEE80211_RADIOTAP_F_FCS;
139 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
140 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
141 if (status->flag & RX_FLAG_SHORTPRE)
142 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
145 /* IEEE80211_RADIOTAP_RATE */
146 if (!rate || status->flag & RX_FLAG_HT) {
148 * Without rate information don't add it. If we have,
149 * MCS information is a separate field in radiotap,
150 * added below. The byte here is needed as padding
151 * for the channel though, so initialise it to 0.
155 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
156 *pos = rate->bitrate / 5;
160 /* IEEE80211_RADIOTAP_CHANNEL */
161 put_unaligned_le16(status->freq, pos);
163 if (status->band == IEEE80211_BAND_5GHZ)
164 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
166 else if (status->flag & RX_FLAG_HT)
167 put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
169 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
170 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
173 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
176 put_unaligned_le16(IEEE80211_CHAN_2GHZ, pos);
179 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
180 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM &&
181 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
182 *pos = status->signal;
184 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
188 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
190 /* IEEE80211_RADIOTAP_ANTENNA */
191 *pos = status->antenna;
194 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
196 /* IEEE80211_RADIOTAP_RX_FLAGS */
197 /* ensure 2 byte alignment for the 2 byte field as required */
198 if ((pos - (u8 *)rthdr) & 1)
200 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
201 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
202 put_unaligned_le16(rx_flags, pos);
205 if (status->flag & RX_FLAG_HT) {
206 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
207 *pos++ = local->hw.radiotap_mcs_details;
209 if (status->flag & RX_FLAG_SHORT_GI)
210 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
211 if (status->flag & RX_FLAG_40MHZ)
212 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
213 if (status->flag & RX_FLAG_HT_GF)
214 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
216 *pos++ = status->rate_idx;
221 * This function copies a received frame to all monitor interfaces and
222 * returns a cleaned-up SKB that no longer includes the FCS nor the
223 * radiotap header the driver might have added.
225 static struct sk_buff *
226 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
227 struct ieee80211_rate *rate)
229 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
230 struct ieee80211_sub_if_data *sdata;
232 struct sk_buff *skb, *skb2;
233 struct net_device *prev_dev = NULL;
234 int present_fcs_len = 0;
237 * First, we may need to make a copy of the skb because
238 * (1) we need to modify it for radiotap (if not present), and
239 * (2) the other RX handlers will modify the skb we got.
241 * We don't need to, of course, if we aren't going to return
242 * the SKB because it has a bad FCS/PLCP checksum.
245 /* room for the radiotap header based on driver features */
246 needed_headroom = ieee80211_rx_radiotap_len(local, status);
248 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
249 present_fcs_len = FCS_LEN;
251 /* make sure hdr->frame_control is on the linear part */
252 if (!pskb_may_pull(origskb, 2)) {
253 dev_kfree_skb(origskb);
257 if (!local->monitors) {
258 if (should_drop_frame(origskb, present_fcs_len)) {
259 dev_kfree_skb(origskb);
263 return remove_monitor_info(local, origskb);
266 if (should_drop_frame(origskb, present_fcs_len)) {
267 /* only need to expand headroom if necessary */
272 * This shouldn't trigger often because most devices have an
273 * RX header they pull before we get here, and that should
274 * be big enough for our radiotap information. We should
275 * probably export the length to drivers so that we can have
276 * them allocate enough headroom to start with.
278 if (skb_headroom(skb) < needed_headroom &&
279 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
285 * Need to make a copy and possibly remove radiotap header
286 * and FCS from the original.
288 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
290 origskb = remove_monitor_info(local, origskb);
296 /* prepend radiotap information */
297 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
300 skb_reset_mac_header(skb);
301 skb->ip_summed = CHECKSUM_UNNECESSARY;
302 skb->pkt_type = PACKET_OTHERHOST;
303 skb->protocol = htons(ETH_P_802_2);
305 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
306 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
309 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
312 if (!ieee80211_sdata_running(sdata))
316 skb2 = skb_clone(skb, GFP_ATOMIC);
318 skb2->dev = prev_dev;
319 netif_receive_skb(skb2);
323 prev_dev = sdata->dev;
324 sdata->dev->stats.rx_packets++;
325 sdata->dev->stats.rx_bytes += skb->len;
330 netif_receive_skb(skb);
338 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
340 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
341 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
342 int tid, seqno_idx, security_idx;
344 /* does the frame have a qos control field? */
345 if (ieee80211_is_data_qos(hdr->frame_control)) {
346 u8 *qc = ieee80211_get_qos_ctl(hdr);
347 /* frame has qos control */
348 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
349 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
350 status->rx_flags |= IEEE80211_RX_AMSDU;
356 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
358 * Sequence numbers for management frames, QoS data
359 * frames with a broadcast/multicast address in the
360 * Address 1 field, and all non-QoS data frames sent
361 * by QoS STAs are assigned using an additional single
362 * modulo-4096 counter, [...]
364 * We also use that counter for non-QoS STAs.
366 seqno_idx = NUM_RX_DATA_QUEUES;
368 if (ieee80211_is_mgmt(hdr->frame_control))
369 security_idx = NUM_RX_DATA_QUEUES;
373 rx->seqno_idx = seqno_idx;
374 rx->security_idx = security_idx;
375 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
376 * For now, set skb->priority to 0 for other cases. */
377 rx->skb->priority = (tid > 7) ? 0 : tid;
381 * DOC: Packet alignment
383 * Drivers always need to pass packets that are aligned to two-byte boundaries
386 * Additionally, should, if possible, align the payload data in a way that
387 * guarantees that the contained IP header is aligned to a four-byte
388 * boundary. In the case of regular frames, this simply means aligning the
389 * payload to a four-byte boundary (because either the IP header is directly
390 * contained, or IV/RFC1042 headers that have a length divisible by four are
391 * in front of it). If the payload data is not properly aligned and the
392 * architecture doesn't support efficient unaligned operations, mac80211
393 * will align the data.
395 * With A-MSDU frames, however, the payload data address must yield two modulo
396 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
397 * push the IP header further back to a multiple of four again. Thankfully, the
398 * specs were sane enough this time around to require padding each A-MSDU
399 * subframe to a length that is a multiple of four.
401 * Padding like Atheros hardware adds which is between the 802.11 header and
402 * the payload is not supported, the driver is required to move the 802.11
403 * header to be directly in front of the payload in that case.
405 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
407 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
408 WARN_ONCE((unsigned long)rx->skb->data & 1,
409 "unaligned packet at 0x%p\n", rx->skb->data);
416 static ieee80211_rx_result debug_noinline
417 ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
419 struct ieee80211_local *local = rx->local;
420 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
421 struct sk_buff *skb = rx->skb;
423 if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
424 !local->sched_scanning))
427 if (test_bit(SCAN_HW_SCANNING, &local->scanning) ||
428 test_bit(SCAN_SW_SCANNING, &local->scanning) ||
429 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning) ||
430 local->sched_scanning)
431 return ieee80211_scan_rx(rx->sdata, skb);
433 /* scanning finished during invoking of handlers */
434 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
435 return RX_DROP_UNUSABLE;
439 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
441 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
443 if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
446 return ieee80211_is_robust_mgmt_frame(hdr);
450 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
452 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
454 if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
457 return ieee80211_is_robust_mgmt_frame(hdr);
461 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
462 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
464 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
465 struct ieee80211_mmie *mmie;
467 if (skb->len < 24 + sizeof(*mmie) ||
468 !is_multicast_ether_addr(hdr->da))
471 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
472 return -1; /* not a robust management frame */
474 mmie = (struct ieee80211_mmie *)
475 (skb->data + skb->len - sizeof(*mmie));
476 if (mmie->element_id != WLAN_EID_MMIE ||
477 mmie->length != sizeof(*mmie) - 2)
480 return le16_to_cpu(mmie->key_id);
484 static ieee80211_rx_result
485 ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
487 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
488 char *dev_addr = rx->sdata->vif.addr;
490 if (ieee80211_is_data(hdr->frame_control)) {
491 if (is_multicast_ether_addr(hdr->addr1)) {
492 if (ieee80211_has_tods(hdr->frame_control) ||
493 !ieee80211_has_fromds(hdr->frame_control))
494 return RX_DROP_MONITOR;
495 if (ether_addr_equal(hdr->addr3, dev_addr))
496 return RX_DROP_MONITOR;
498 if (!ieee80211_has_a4(hdr->frame_control))
499 return RX_DROP_MONITOR;
500 if (ether_addr_equal(hdr->addr4, dev_addr))
501 return RX_DROP_MONITOR;
505 /* If there is not an established peer link and this is not a peer link
506 * establisment frame, beacon or probe, drop the frame.
509 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
510 struct ieee80211_mgmt *mgmt;
512 if (!ieee80211_is_mgmt(hdr->frame_control))
513 return RX_DROP_MONITOR;
515 if (ieee80211_is_action(hdr->frame_control)) {
517 mgmt = (struct ieee80211_mgmt *)hdr;
518 category = mgmt->u.action.category;
519 if (category != WLAN_CATEGORY_MESH_ACTION &&
520 category != WLAN_CATEGORY_SELF_PROTECTED)
521 return RX_DROP_MONITOR;
525 if (ieee80211_is_probe_req(hdr->frame_control) ||
526 ieee80211_is_probe_resp(hdr->frame_control) ||
527 ieee80211_is_beacon(hdr->frame_control) ||
528 ieee80211_is_auth(hdr->frame_control))
531 return RX_DROP_MONITOR;
538 #define SEQ_MODULO 0x1000
539 #define SEQ_MASK 0xfff
541 static inline int seq_less(u16 sq1, u16 sq2)
543 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
546 static inline u16 seq_inc(u16 sq)
548 return (sq + 1) & SEQ_MASK;
551 static inline u16 seq_sub(u16 sq1, u16 sq2)
553 return (sq1 - sq2) & SEQ_MASK;
557 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
558 struct tid_ampdu_rx *tid_agg_rx,
561 struct ieee80211_local *local = sdata->local;
562 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
563 struct ieee80211_rx_status *status;
565 lockdep_assert_held(&tid_agg_rx->reorder_lock);
570 /* release the frame from the reorder ring buffer */
571 tid_agg_rx->stored_mpdu_num--;
572 tid_agg_rx->reorder_buf[index] = NULL;
573 status = IEEE80211_SKB_RXCB(skb);
574 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
575 skb_queue_tail(&local->rx_skb_queue, skb);
578 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
581 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
582 struct tid_ampdu_rx *tid_agg_rx,
587 lockdep_assert_held(&tid_agg_rx->reorder_lock);
589 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
590 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
591 tid_agg_rx->buf_size;
592 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index);
597 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
598 * the skb was added to the buffer longer than this time ago, the earlier
599 * frames that have not yet been received are assumed to be lost and the skb
600 * can be released for processing. This may also release other skb's from the
601 * reorder buffer if there are no additional gaps between the frames.
603 * Callers must hold tid_agg_rx->reorder_lock.
605 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
607 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
608 struct tid_ampdu_rx *tid_agg_rx)
612 lockdep_assert_held(&tid_agg_rx->reorder_lock);
614 /* release the buffer until next missing frame */
615 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
616 tid_agg_rx->buf_size;
617 if (!tid_agg_rx->reorder_buf[index] &&
618 tid_agg_rx->stored_mpdu_num) {
620 * No buffers ready to be released, but check whether any
621 * frames in the reorder buffer have timed out.
624 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
625 j = (j + 1) % tid_agg_rx->buf_size) {
626 if (!tid_agg_rx->reorder_buf[j]) {
631 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
632 HT_RX_REORDER_BUF_TIMEOUT))
633 goto set_release_timer;
635 ht_dbg_ratelimited(sdata,
636 "release an RX reorder frame due to timeout on earlier frames\n");
637 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j);
640 * Increment the head seq# also for the skipped slots.
642 tid_agg_rx->head_seq_num =
643 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
646 } else while (tid_agg_rx->reorder_buf[index]) {
647 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index);
648 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
649 tid_agg_rx->buf_size;
652 if (tid_agg_rx->stored_mpdu_num) {
653 j = index = seq_sub(tid_agg_rx->head_seq_num,
654 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
656 for (; j != (index - 1) % tid_agg_rx->buf_size;
657 j = (j + 1) % tid_agg_rx->buf_size) {
658 if (tid_agg_rx->reorder_buf[j])
664 mod_timer(&tid_agg_rx->reorder_timer,
665 tid_agg_rx->reorder_time[j] + 1 +
666 HT_RX_REORDER_BUF_TIMEOUT);
668 del_timer(&tid_agg_rx->reorder_timer);
673 * As this function belongs to the RX path it must be under
674 * rcu_read_lock protection. It returns false if the frame
675 * can be processed immediately, true if it was consumed.
677 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
678 struct tid_ampdu_rx *tid_agg_rx,
681 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
682 u16 sc = le16_to_cpu(hdr->seq_ctrl);
683 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
684 u16 head_seq_num, buf_size;
688 spin_lock(&tid_agg_rx->reorder_lock);
690 buf_size = tid_agg_rx->buf_size;
691 head_seq_num = tid_agg_rx->head_seq_num;
693 /* frame with out of date sequence number */
694 if (seq_less(mpdu_seq_num, head_seq_num)) {
700 * If frame the sequence number exceeds our buffering window
701 * size release some previous frames to make room for this one.
703 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
704 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
705 /* release stored frames up to new head to stack */
706 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
710 /* Now the new frame is always in the range of the reordering buffer */
712 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
714 /* check if we already stored this frame */
715 if (tid_agg_rx->reorder_buf[index]) {
721 * If the current MPDU is in the right order and nothing else
722 * is stored we can process it directly, no need to buffer it.
723 * If it is first but there's something stored, we may be able
724 * to release frames after this one.
726 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
727 tid_agg_rx->stored_mpdu_num == 0) {
728 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
733 /* put the frame in the reordering buffer */
734 tid_agg_rx->reorder_buf[index] = skb;
735 tid_agg_rx->reorder_time[index] = jiffies;
736 tid_agg_rx->stored_mpdu_num++;
737 ieee80211_sta_reorder_release(sdata, tid_agg_rx);
740 spin_unlock(&tid_agg_rx->reorder_lock);
745 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
746 * true if the MPDU was buffered, false if it should be processed.
748 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx)
750 struct sk_buff *skb = rx->skb;
751 struct ieee80211_local *local = rx->local;
752 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
753 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
754 struct sta_info *sta = rx->sta;
755 struct tid_ampdu_rx *tid_agg_rx;
759 if (!ieee80211_is_data_qos(hdr->frame_control))
763 * filter the QoS data rx stream according to
764 * STA/TID and check if this STA/TID is on aggregation
770 ack_policy = *ieee80211_get_qos_ctl(hdr) &
771 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
772 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
774 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
778 /* qos null data frames are excluded */
779 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
782 /* not part of a BA session */
783 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
784 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
787 /* not actually part of this BA session */
788 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
791 /* new, potentially un-ordered, ampdu frame - process it */
793 /* reset session timer */
794 if (tid_agg_rx->timeout)
795 tid_agg_rx->last_rx = jiffies;
797 /* if this mpdu is fragmented - terminate rx aggregation session */
798 sc = le16_to_cpu(hdr->seq_ctrl);
799 if (sc & IEEE80211_SCTL_FRAG) {
800 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
801 skb_queue_tail(&rx->sdata->skb_queue, skb);
802 ieee80211_queue_work(&local->hw, &rx->sdata->work);
807 * No locking needed -- we will only ever process one
808 * RX packet at a time, and thus own tid_agg_rx. All
809 * other code manipulating it needs to (and does) make
810 * sure that we cannot get to it any more before doing
813 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb))
817 skb_queue_tail(&local->rx_skb_queue, skb);
820 static ieee80211_rx_result debug_noinline
821 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
823 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
824 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
826 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
827 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
828 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
829 rx->sta->last_seq_ctrl[rx->seqno_idx] ==
831 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
832 rx->local->dot11FrameDuplicateCount++;
833 rx->sta->num_duplicates++;
835 return RX_DROP_UNUSABLE;
837 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
840 if (unlikely(rx->skb->len < 16)) {
841 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
842 return RX_DROP_MONITOR;
845 /* Drop disallowed frame classes based on STA auth/assoc state;
846 * IEEE 802.11, Chap 5.5.
848 * mac80211 filters only based on association state, i.e. it drops
849 * Class 3 frames from not associated stations. hostapd sends
850 * deauth/disassoc frames when needed. In addition, hostapd is
851 * responsible for filtering on both auth and assoc states.
854 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
855 return ieee80211_rx_mesh_check(rx);
857 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
858 ieee80211_is_pspoll(hdr->frame_control)) &&
859 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
860 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
861 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
863 * accept port control frames from the AP even when it's not
864 * yet marked ASSOC to prevent a race where we don't set the
865 * assoc bit quickly enough before it sends the first frame
867 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
868 ieee80211_is_data_present(hdr->frame_control)) {
872 payload = rx->skb->data +
873 ieee80211_hdrlen(hdr->frame_control);
874 ethertype = (payload[6] << 8) | payload[7];
875 if (cpu_to_be16(ethertype) ==
876 rx->sdata->control_port_protocol)
880 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
881 cfg80211_rx_spurious_frame(rx->sdata->dev,
884 return RX_DROP_UNUSABLE;
886 return RX_DROP_MONITOR;
893 static ieee80211_rx_result debug_noinline
894 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
896 struct sk_buff *skb = rx->skb;
897 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
898 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
901 ieee80211_rx_result result = RX_DROP_UNUSABLE;
902 struct ieee80211_key *sta_ptk = NULL;
903 int mmie_keyidx = -1;
909 * There are four types of keys:
911 * - IGTK (group keys for management frames)
912 * - PTK (pairwise keys)
913 * - STK (station-to-station pairwise keys)
915 * When selecting a key, we have to distinguish between multicast
916 * (including broadcast) and unicast frames, the latter can only
917 * use PTKs and STKs while the former always use GTKs and IGTKs.
918 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
919 * unicast frames can also use key indices like GTKs. Hence, if we
920 * don't have a PTK/STK we check the key index for a WEP key.
922 * Note that in a regular BSS, multicast frames are sent by the
923 * AP only, associated stations unicast the frame to the AP first
924 * which then multicasts it on their behalf.
926 * There is also a slight problem in IBSS mode: GTKs are negotiated
927 * with each station, that is something we don't currently handle.
928 * The spec seems to expect that one negotiates the same key with
929 * every station but there's no such requirement; VLANs could be
934 * No point in finding a key and decrypting if the frame is neither
935 * addressed to us nor a multicast frame.
937 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
940 /* start without a key */
944 sta_ptk = rcu_dereference(rx->sta->ptk);
946 fc = hdr->frame_control;
948 if (!ieee80211_has_protected(fc))
949 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
951 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
953 if ((status->flag & RX_FLAG_DECRYPTED) &&
954 (status->flag & RX_FLAG_IV_STRIPPED))
956 /* Skip decryption if the frame is not protected. */
957 if (!ieee80211_has_protected(fc))
959 } else if (mmie_keyidx >= 0) {
960 /* Broadcast/multicast robust management frame / BIP */
961 if ((status->flag & RX_FLAG_DECRYPTED) &&
962 (status->flag & RX_FLAG_IV_STRIPPED))
965 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
966 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
967 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
969 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
971 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
972 } else if (!ieee80211_has_protected(fc)) {
974 * The frame was not protected, so skip decryption. However, we
975 * need to set rx->key if there is a key that could have been
976 * used so that the frame may be dropped if encryption would
977 * have been expected.
979 struct ieee80211_key *key = NULL;
980 struct ieee80211_sub_if_data *sdata = rx->sdata;
983 if (ieee80211_is_mgmt(fc) &&
984 is_multicast_ether_addr(hdr->addr1) &&
985 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
989 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
990 key = rcu_dereference(rx->sta->gtk[i]);
996 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
997 key = rcu_dereference(sdata->keys[i]);
1009 * The device doesn't give us the IV so we won't be
1010 * able to look up the key. That's ok though, we
1011 * don't need to decrypt the frame, we just won't
1012 * be able to keep statistics accurate.
1013 * Except for key threshold notifications, should
1014 * we somehow allow the driver to tell us which key
1015 * the hardware used if this flag is set?
1017 if ((status->flag & RX_FLAG_DECRYPTED) &&
1018 (status->flag & RX_FLAG_IV_STRIPPED))
1021 hdrlen = ieee80211_hdrlen(fc);
1023 if (rx->skb->len < 8 + hdrlen)
1024 return RX_DROP_UNUSABLE; /* TODO: count this? */
1027 * no need to call ieee80211_wep_get_keyidx,
1028 * it verifies a bunch of things we've done already
1030 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1031 keyidx = keyid >> 6;
1033 /* check per-station GTK first, if multicast packet */
1034 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1035 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1037 /* if not found, try default key */
1039 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1042 * RSNA-protected unicast frames should always be
1043 * sent with pairwise or station-to-station keys,
1044 * but for WEP we allow using a key index as well.
1047 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1048 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1049 !is_multicast_ether_addr(hdr->addr1))
1055 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1056 return RX_DROP_MONITOR;
1058 rx->key->tx_rx_count++;
1059 /* TODO: add threshold stuff again */
1061 return RX_DROP_MONITOR;
1064 switch (rx->key->conf.cipher) {
1065 case WLAN_CIPHER_SUITE_WEP40:
1066 case WLAN_CIPHER_SUITE_WEP104:
1067 result = ieee80211_crypto_wep_decrypt(rx);
1069 case WLAN_CIPHER_SUITE_TKIP:
1070 result = ieee80211_crypto_tkip_decrypt(rx);
1072 case WLAN_CIPHER_SUITE_CCMP:
1073 result = ieee80211_crypto_ccmp_decrypt(rx);
1075 case WLAN_CIPHER_SUITE_AES_CMAC:
1076 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1080 * We can reach here only with HW-only algorithms
1081 * but why didn't it decrypt the frame?!
1083 return RX_DROP_UNUSABLE;
1086 /* the hdr variable is invalid after the decrypt handlers */
1088 /* either the frame has been decrypted or will be dropped */
1089 status->flag |= RX_FLAG_DECRYPTED;
1094 static ieee80211_rx_result debug_noinline
1095 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1097 struct ieee80211_local *local;
1098 struct ieee80211_hdr *hdr;
1099 struct sk_buff *skb;
1103 hdr = (struct ieee80211_hdr *) skb->data;
1105 if (!local->pspolling)
1108 if (!ieee80211_has_fromds(hdr->frame_control))
1109 /* this is not from AP */
1112 if (!ieee80211_is_data(hdr->frame_control))
1115 if (!ieee80211_has_moredata(hdr->frame_control)) {
1116 /* AP has no more frames buffered for us */
1117 local->pspolling = false;
1121 /* more data bit is set, let's request a new frame from the AP */
1122 ieee80211_send_pspoll(local, rx->sdata);
1127 static void ap_sta_ps_start(struct sta_info *sta)
1129 struct ieee80211_sub_if_data *sdata = sta->sdata;
1130 struct ieee80211_local *local = sdata->local;
1132 atomic_inc(&sdata->bss->num_sta_ps);
1133 set_sta_flag(sta, WLAN_STA_PS_STA);
1134 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1135 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1136 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1137 sta->sta.addr, sta->sta.aid);
1140 static void ap_sta_ps_end(struct sta_info *sta)
1142 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1143 sta->sta.addr, sta->sta.aid);
1145 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1146 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1147 sta->sta.addr, sta->sta.aid);
1151 ieee80211_sta_ps_deliver_wakeup(sta);
1154 int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1156 struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1159 WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
1161 /* Don't let the same PS state be set twice */
1162 in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
1163 if ((start && in_ps) || (!start && !in_ps))
1167 ap_sta_ps_start(sta_inf);
1169 ap_sta_ps_end(sta_inf);
1173 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1175 static ieee80211_rx_result debug_noinline
1176 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1178 struct ieee80211_sub_if_data *sdata = rx->sdata;
1179 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1180 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1183 if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH))
1186 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1187 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1191 * The device handles station powersave, so don't do anything about
1192 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1193 * it to mac80211 since they're handled.)
1195 if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
1199 * Don't do anything if the station isn't already asleep. In
1200 * the uAPSD case, the station will probably be marked asleep,
1201 * in the PS-Poll case the station must be confused ...
1203 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1206 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1207 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1208 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1209 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1211 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
1214 /* Free PS Poll skb here instead of returning RX_DROP that would
1215 * count as an dropped frame. */
1216 dev_kfree_skb(rx->skb);
1219 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1220 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1221 ieee80211_has_pm(hdr->frame_control) &&
1222 (ieee80211_is_data_qos(hdr->frame_control) ||
1223 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1224 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1225 ac = ieee802_1d_to_ac[tid & 7];
1228 * If this AC is not trigger-enabled do nothing.
1230 * NB: This could/should check a separate bitmap of trigger-
1231 * enabled queues, but for now we only implement uAPSD w/o
1232 * TSPEC changes to the ACs, so they're always the same.
1234 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1237 /* if we are in a service period, do nothing */
1238 if (test_sta_flag(rx->sta, WLAN_STA_SP))
1241 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1242 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1244 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
1250 static ieee80211_rx_result debug_noinline
1251 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1253 struct sta_info *sta = rx->sta;
1254 struct sk_buff *skb = rx->skb;
1255 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1256 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1262 * Update last_rx only for IBSS packets which are for the current
1263 * BSSID to avoid keeping the current IBSS network alive in cases
1264 * where other STAs start using different BSSID.
1266 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1267 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1268 NL80211_IFTYPE_ADHOC);
1269 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid)) {
1270 sta->last_rx = jiffies;
1271 if (ieee80211_is_data(hdr->frame_control)) {
1272 sta->last_rx_rate_idx = status->rate_idx;
1273 sta->last_rx_rate_flag = status->flag;
1276 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1278 * Mesh beacons will update last_rx when if they are found to
1279 * match the current local configuration when processed.
1281 sta->last_rx = jiffies;
1282 if (ieee80211_is_data(hdr->frame_control)) {
1283 sta->last_rx_rate_idx = status->rate_idx;
1284 sta->last_rx_rate_flag = status->flag;
1288 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
1291 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1292 ieee80211_sta_rx_notify(rx->sdata, hdr);
1294 sta->rx_fragments++;
1295 sta->rx_bytes += rx->skb->len;
1296 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1297 sta->last_signal = status->signal;
1298 ewma_add(&sta->avg_signal, -status->signal);
1302 * Change STA power saving mode only at the end of a frame
1303 * exchange sequence.
1305 if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
1306 !ieee80211_has_morefrags(hdr->frame_control) &&
1307 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1308 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1309 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1310 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1312 * Ignore doze->wake transitions that are
1313 * indicated by non-data frames, the standard
1314 * is unclear here, but for example going to
1315 * PS mode and then scanning would cause a
1316 * doze->wake transition for the probe request,
1317 * and that is clearly undesirable.
1319 if (ieee80211_is_data(hdr->frame_control) &&
1320 !ieee80211_has_pm(hdr->frame_control))
1323 if (ieee80211_has_pm(hdr->frame_control))
1324 ap_sta_ps_start(sta);
1329 * Drop (qos-)data::nullfunc frames silently, since they
1330 * are used only to control station power saving mode.
1332 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1333 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1334 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1337 * If we receive a 4-addr nullfunc frame from a STA
1338 * that was not moved to a 4-addr STA vlan yet send
1339 * the event to userspace and for older hostapd drop
1340 * the frame to the monitor interface.
1342 if (ieee80211_has_a4(hdr->frame_control) &&
1343 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1344 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1345 !rx->sdata->u.vlan.sta))) {
1346 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1347 cfg80211_rx_unexpected_4addr_frame(
1348 rx->sdata->dev, sta->sta.addr,
1350 return RX_DROP_MONITOR;
1353 * Update counter and free packet here to avoid
1354 * counting this as a dropped packed.
1357 dev_kfree_skb(rx->skb);
1362 } /* ieee80211_rx_h_sta_process */
1364 static inline struct ieee80211_fragment_entry *
1365 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1366 unsigned int frag, unsigned int seq, int rx_queue,
1367 struct sk_buff **skb)
1369 struct ieee80211_fragment_entry *entry;
1372 idx = sdata->fragment_next;
1373 entry = &sdata->fragments[sdata->fragment_next++];
1374 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1375 sdata->fragment_next = 0;
1377 if (!skb_queue_empty(&entry->skb_list))
1378 __skb_queue_purge(&entry->skb_list);
1380 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1382 entry->first_frag_time = jiffies;
1384 entry->rx_queue = rx_queue;
1385 entry->last_frag = frag;
1387 entry->extra_len = 0;
1392 static inline struct ieee80211_fragment_entry *
1393 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
1394 unsigned int frag, unsigned int seq,
1395 int rx_queue, struct ieee80211_hdr *hdr)
1397 struct ieee80211_fragment_entry *entry;
1400 idx = sdata->fragment_next;
1401 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1402 struct ieee80211_hdr *f_hdr;
1406 idx = IEEE80211_FRAGMENT_MAX - 1;
1408 entry = &sdata->fragments[idx];
1409 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1410 entry->rx_queue != rx_queue ||
1411 entry->last_frag + 1 != frag)
1414 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1417 * Check ftype and addresses are equal, else check next fragment
1419 if (((hdr->frame_control ^ f_hdr->frame_control) &
1420 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1421 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1422 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
1425 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1426 __skb_queue_purge(&entry->skb_list);
1435 static ieee80211_rx_result debug_noinline
1436 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1438 struct ieee80211_hdr *hdr;
1441 unsigned int frag, seq;
1442 struct ieee80211_fragment_entry *entry;
1443 struct sk_buff *skb;
1444 struct ieee80211_rx_status *status;
1446 hdr = (struct ieee80211_hdr *)rx->skb->data;
1447 fc = hdr->frame_control;
1448 sc = le16_to_cpu(hdr->seq_ctrl);
1449 frag = sc & IEEE80211_SCTL_FRAG;
1451 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
1452 (rx->skb)->len < 24 ||
1453 is_multicast_ether_addr(hdr->addr1))) {
1454 /* not fragmented */
1457 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1459 if (skb_linearize(rx->skb))
1460 return RX_DROP_UNUSABLE;
1463 * skb_linearize() might change the skb->data and
1464 * previously cached variables (in this case, hdr) need to
1465 * be refreshed with the new data.
1467 hdr = (struct ieee80211_hdr *)rx->skb->data;
1468 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1471 /* This is the first fragment of a new frame. */
1472 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
1473 rx->seqno_idx, &(rx->skb));
1474 if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
1475 ieee80211_has_protected(fc)) {
1476 int queue = rx->security_idx;
1477 /* Store CCMP PN so that we can verify that the next
1478 * fragment has a sequential PN value. */
1480 memcpy(entry->last_pn,
1481 rx->key->u.ccmp.rx_pn[queue],
1487 /* This is a fragment for a frame that should already be pending in
1488 * fragment cache. Add this fragment to the end of the pending entry.
1490 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1491 rx->seqno_idx, hdr);
1493 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1494 return RX_DROP_MONITOR;
1497 /* Verify that MPDUs within one MSDU have sequential PN values.
1498 * (IEEE 802.11i, 8.3.3.4.5) */
1501 u8 pn[CCMP_PN_LEN], *rpn;
1503 if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
1504 return RX_DROP_UNUSABLE;
1505 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
1506 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
1511 queue = rx->security_idx;
1512 rpn = rx->key->u.ccmp.rx_pn[queue];
1513 if (memcmp(pn, rpn, CCMP_PN_LEN))
1514 return RX_DROP_UNUSABLE;
1515 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
1518 skb_pull(rx->skb, ieee80211_hdrlen(fc));
1519 __skb_queue_tail(&entry->skb_list, rx->skb);
1520 entry->last_frag = frag;
1521 entry->extra_len += rx->skb->len;
1522 if (ieee80211_has_morefrags(fc)) {
1527 rx->skb = __skb_dequeue(&entry->skb_list);
1528 if (skb_tailroom(rx->skb) < entry->extra_len) {
1529 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
1530 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1532 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1533 __skb_queue_purge(&entry->skb_list);
1534 return RX_DROP_UNUSABLE;
1537 while ((skb = __skb_dequeue(&entry->skb_list))) {
1538 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1542 /* Complete frame has been reassembled - process it now */
1543 status = IEEE80211_SKB_RXCB(rx->skb);
1544 status->rx_flags |= IEEE80211_RX_FRAGMENTED;
1548 rx->sta->rx_packets++;
1549 if (is_multicast_ether_addr(hdr->addr1))
1550 rx->local->dot11MulticastReceivedFrameCount++;
1552 ieee80211_led_rx(rx->local);
1557 ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1559 if (unlikely(!rx->sta ||
1560 !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
1567 ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1569 struct sk_buff *skb = rx->skb;
1570 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1573 * Pass through unencrypted frames if the hardware has
1574 * decrypted them already.
1576 if (status->flag & RX_FLAG_DECRYPTED)
1579 /* Drop unencrypted frames if key is set. */
1580 if (unlikely(!ieee80211_has_protected(fc) &&
1581 !ieee80211_is_nullfunc(fc) &&
1582 ieee80211_is_data(fc) &&
1583 (rx->key || rx->sdata->drop_unencrypted)))
1590 ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1592 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1593 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1594 __le16 fc = hdr->frame_control;
1597 * Pass through unencrypted frames if the hardware has
1598 * decrypted them already.
1600 if (status->flag & RX_FLAG_DECRYPTED)
1603 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
1604 if (unlikely(!ieee80211_has_protected(fc) &&
1605 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1607 if (ieee80211_is_deauth(fc))
1608 cfg80211_send_unprot_deauth(rx->sdata->dev,
1611 else if (ieee80211_is_disassoc(fc))
1612 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1617 /* BIP does not use Protected field, so need to check MMIE */
1618 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
1619 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
1620 if (ieee80211_is_deauth(fc))
1621 cfg80211_send_unprot_deauth(rx->sdata->dev,
1624 else if (ieee80211_is_disassoc(fc))
1625 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1631 * When using MFP, Action frames are not allowed prior to
1632 * having configured keys.
1634 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1635 ieee80211_is_robust_mgmt_frame(
1636 (struct ieee80211_hdr *) rx->skb->data)))
1644 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
1646 struct ieee80211_sub_if_data *sdata = rx->sdata;
1647 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1648 bool check_port_control = false;
1649 struct ethhdr *ehdr;
1652 *port_control = false;
1653 if (ieee80211_has_a4(hdr->frame_control) &&
1654 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1657 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1658 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
1660 if (!sdata->u.mgd.use_4addr)
1663 check_port_control = true;
1666 if (is_multicast_ether_addr(hdr->addr1) &&
1667 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
1670 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
1674 ehdr = (struct ethhdr *) rx->skb->data;
1675 if (ehdr->h_proto == rx->sdata->control_port_protocol)
1676 *port_control = true;
1677 else if (check_port_control)
1684 * requires that rx->skb is a frame with ethernet header
1686 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
1688 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
1689 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1690 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1693 * Allow EAPOL frames to us/the PAE group address regardless
1694 * of whether the frame was encrypted or not.
1696 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
1697 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
1698 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
1701 if (ieee80211_802_1x_port_control(rx) ||
1702 ieee80211_drop_unencrypted(rx, fc))
1709 * requires that rx->skb is a frame with ethernet header
1712 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1714 struct ieee80211_sub_if_data *sdata = rx->sdata;
1715 struct net_device *dev = sdata->dev;
1716 struct sk_buff *skb, *xmit_skb;
1717 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1718 struct sta_info *dsta;
1719 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1724 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1725 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1726 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
1727 (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
1728 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
1729 if (is_multicast_ether_addr(ehdr->h_dest)) {
1731 * send multicast frames both to higher layers in
1732 * local net stack and back to the wireless medium
1734 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1736 net_info_ratelimited("%s: failed to clone multicast frame\n",
1739 dsta = sta_info_get(sdata, skb->data);
1742 * The destination station is associated to
1743 * this AP (in this VLAN), so send the frame
1744 * directly to it and do not pass it to local
1754 int align __maybe_unused;
1756 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1758 * 'align' will only take the values 0 or 2 here
1759 * since all frames are required to be aligned
1760 * to 2-byte boundaries when being passed to
1761 * mac80211. That also explains the __skb_push()
1764 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
1766 if (WARN_ON(skb_headroom(skb) < 3)) {
1770 u8 *data = skb->data;
1771 size_t len = skb_headlen(skb);
1773 memmove(skb->data, data, len);
1774 skb_set_tail_pointer(skb, len);
1780 /* deliver to local stack */
1781 skb->protocol = eth_type_trans(skb, dev);
1782 memset(skb->cb, 0, sizeof(skb->cb));
1783 netif_receive_skb(skb);
1789 * Send to wireless media and increase priority by 256 to
1790 * keep the received priority instead of reclassifying
1791 * the frame (see cfg80211_classify8021d).
1793 xmit_skb->priority += 256;
1794 xmit_skb->protocol = htons(ETH_P_802_3);
1795 skb_reset_network_header(xmit_skb);
1796 skb_reset_mac_header(xmit_skb);
1797 dev_queue_xmit(xmit_skb);
1801 static ieee80211_rx_result debug_noinline
1802 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1804 struct net_device *dev = rx->sdata->dev;
1805 struct sk_buff *skb = rx->skb;
1806 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1807 __le16 fc = hdr->frame_control;
1808 struct sk_buff_head frame_list;
1809 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1811 if (unlikely(!ieee80211_is_data(fc)))
1814 if (unlikely(!ieee80211_is_data_present(fc)))
1815 return RX_DROP_MONITOR;
1817 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
1820 if (ieee80211_has_a4(hdr->frame_control) &&
1821 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1822 !rx->sdata->u.vlan.sta)
1823 return RX_DROP_UNUSABLE;
1825 if (is_multicast_ether_addr(hdr->addr1) &&
1826 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1827 rx->sdata->u.vlan.sta) ||
1828 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1829 rx->sdata->u.mgd.use_4addr)))
1830 return RX_DROP_UNUSABLE;
1833 __skb_queue_head_init(&frame_list);
1835 if (skb_linearize(skb))
1836 return RX_DROP_UNUSABLE;
1838 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
1839 rx->sdata->vif.type,
1840 rx->local->hw.extra_tx_headroom, true);
1842 while (!skb_queue_empty(&frame_list)) {
1843 rx->skb = __skb_dequeue(&frame_list);
1845 if (!ieee80211_frame_allowed(rx, fc)) {
1846 dev_kfree_skb(rx->skb);
1849 dev->stats.rx_packets++;
1850 dev->stats.rx_bytes += rx->skb->len;
1852 ieee80211_deliver_skb(rx);
1858 #ifdef CONFIG_MAC80211_MESH
1859 static ieee80211_rx_result
1860 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1862 struct ieee80211_hdr *fwd_hdr, *hdr;
1863 struct ieee80211_tx_info *info;
1864 struct ieee80211s_hdr *mesh_hdr;
1865 struct sk_buff *skb = rx->skb, *fwd_skb;
1866 struct ieee80211_local *local = rx->local;
1867 struct ieee80211_sub_if_data *sdata = rx->sdata;
1868 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1869 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1870 __le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_NOFORWARD);
1873 hdr = (struct ieee80211_hdr *) skb->data;
1874 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1875 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1877 /* frame is in RMC, don't forward */
1878 if (ieee80211_is_data(hdr->frame_control) &&
1879 is_multicast_ether_addr(hdr->addr1) &&
1880 mesh_rmc_check(hdr->addr3, mesh_hdr, rx->sdata))
1881 return RX_DROP_MONITOR;
1883 if (!ieee80211_is_data(hdr->frame_control))
1887 return RX_DROP_MONITOR;
1889 if (mesh_hdr->flags & MESH_FLAGS_AE) {
1890 struct mesh_path *mppath;
1894 if (is_multicast_ether_addr(hdr->addr1)) {
1895 mpp_addr = hdr->addr3;
1896 proxied_addr = mesh_hdr->eaddr1;
1898 mpp_addr = hdr->addr4;
1899 proxied_addr = mesh_hdr->eaddr2;
1903 mppath = mpp_path_lookup(proxied_addr, sdata);
1905 mpp_path_add(proxied_addr, mpp_addr, sdata);
1907 spin_lock_bh(&mppath->state_lock);
1908 if (!ether_addr_equal(mppath->mpp, mpp_addr))
1909 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
1910 spin_unlock_bh(&mppath->state_lock);
1915 /* Frame has reached destination. Don't forward */
1916 if (!is_multicast_ether_addr(hdr->addr1) &&
1917 ether_addr_equal(sdata->vif.addr, hdr->addr3))
1920 q = ieee80211_select_queue_80211(sdata, skb, hdr);
1921 if (ieee80211_queue_stopped(&local->hw, q)) {
1922 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
1923 return RX_DROP_MONITOR;
1925 skb_set_queue_mapping(skb, q);
1927 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
1930 if (!--mesh_hdr->ttl) {
1931 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
1932 return RX_DROP_MONITOR;
1935 if (!ifmsh->mshcfg.dot11MeshForwarding)
1938 fwd_skb = skb_copy(skb, GFP_ATOMIC);
1940 net_info_ratelimited("%s: failed to clone mesh frame\n",
1945 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
1946 info = IEEE80211_SKB_CB(fwd_skb);
1947 memset(info, 0, sizeof(*info));
1948 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1949 info->control.vif = &rx->sdata->vif;
1950 info->control.jiffies = jiffies;
1951 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
1952 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
1953 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
1954 } else if (!mesh_nexthop_lookup(fwd_skb, sdata)) {
1955 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
1957 /* unable to resolve next hop */
1958 mesh_path_error_tx(ifmsh->mshcfg.element_ttl, fwd_hdr->addr3,
1959 0, reason, fwd_hdr->addr2, sdata);
1960 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
1962 return RX_DROP_MONITOR;
1965 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
1966 ieee80211_add_pending_skb(local, fwd_skb);
1968 if (is_multicast_ether_addr(hdr->addr1) ||
1969 sdata->dev->flags & IFF_PROMISC)
1972 return RX_DROP_MONITOR;
1976 static ieee80211_rx_result debug_noinline
1977 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1979 struct ieee80211_sub_if_data *sdata = rx->sdata;
1980 struct ieee80211_local *local = rx->local;
1981 struct net_device *dev = sdata->dev;
1982 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1983 __le16 fc = hdr->frame_control;
1987 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
1990 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
1991 return RX_DROP_MONITOR;
1994 * Send unexpected-4addr-frame event to hostapd. For older versions,
1995 * also drop the frame to cooked monitor interfaces.
1997 if (ieee80211_has_a4(hdr->frame_control) &&
1998 sdata->vif.type == NL80211_IFTYPE_AP) {
2000 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2001 cfg80211_rx_unexpected_4addr_frame(
2002 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
2003 return RX_DROP_MONITOR;
2006 err = __ieee80211_data_to_8023(rx, &port_control);
2008 return RX_DROP_UNUSABLE;
2010 if (!ieee80211_frame_allowed(rx, fc))
2011 return RX_DROP_MONITOR;
2013 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2014 unlikely(port_control) && sdata->bss) {
2015 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2023 dev->stats.rx_packets++;
2024 dev->stats.rx_bytes += rx->skb->len;
2026 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2027 !is_multicast_ether_addr(
2028 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2029 (!local->scanning &&
2030 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
2031 mod_timer(&local->dynamic_ps_timer, jiffies +
2032 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2035 ieee80211_deliver_skb(rx);
2040 static ieee80211_rx_result debug_noinline
2041 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
2043 struct sk_buff *skb = rx->skb;
2044 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2045 struct tid_ampdu_rx *tid_agg_rx;
2049 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2052 if (ieee80211_is_back_req(bar->frame_control)) {
2054 __le16 control, start_seq_num;
2055 } __packed bar_data;
2058 return RX_DROP_MONITOR;
2060 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2061 &bar_data, sizeof(bar_data)))
2062 return RX_DROP_MONITOR;
2064 tid = le16_to_cpu(bar_data.control) >> 12;
2066 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2068 return RX_DROP_MONITOR;
2070 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2072 /* reset session timer */
2073 if (tid_agg_rx->timeout)
2074 mod_timer(&tid_agg_rx->session_timer,
2075 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2077 spin_lock(&tid_agg_rx->reorder_lock);
2078 /* release stored frames up to start of BAR */
2079 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
2081 spin_unlock(&tid_agg_rx->reorder_lock);
2088 * After this point, we only want management frames,
2089 * so we can drop all remaining control frames to
2090 * cooked monitor interfaces.
2092 return RX_DROP_MONITOR;
2095 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2096 struct ieee80211_mgmt *mgmt,
2099 struct ieee80211_local *local = sdata->local;
2100 struct sk_buff *skb;
2101 struct ieee80211_mgmt *resp;
2103 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
2104 /* Not to own unicast address */
2108 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2109 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
2110 /* Not from the current AP or not associated yet. */
2114 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2115 /* Too short SA Query request frame */
2119 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2123 skb_reserve(skb, local->hw.extra_tx_headroom);
2124 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2125 memset(resp, 0, 24);
2126 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2127 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2128 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2129 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2130 IEEE80211_STYPE_ACTION);
2131 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2132 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2133 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2134 memcpy(resp->u.action.u.sa_query.trans_id,
2135 mgmt->u.action.u.sa_query.trans_id,
2136 WLAN_SA_QUERY_TR_ID_LEN);
2138 ieee80211_tx_skb(sdata, skb);
2141 static ieee80211_rx_result debug_noinline
2142 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2144 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2145 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2148 * From here on, look only at management frames.
2149 * Data and control frames are already handled,
2150 * and unknown (reserved) frames are useless.
2152 if (rx->skb->len < 24)
2153 return RX_DROP_MONITOR;
2155 if (!ieee80211_is_mgmt(mgmt->frame_control))
2156 return RX_DROP_MONITOR;
2158 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2159 ieee80211_is_beacon(mgmt->frame_control) &&
2160 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
2163 if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
2164 sig = status->signal;
2166 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2167 rx->skb->data, rx->skb->len,
2168 status->freq, sig, GFP_ATOMIC);
2169 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2172 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
2173 return RX_DROP_MONITOR;
2175 if (ieee80211_drop_unencrypted_mgmt(rx))
2176 return RX_DROP_UNUSABLE;
2181 static ieee80211_rx_result debug_noinline
2182 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2184 struct ieee80211_local *local = rx->local;
2185 struct ieee80211_sub_if_data *sdata = rx->sdata;
2186 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2187 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2188 int len = rx->skb->len;
2190 if (!ieee80211_is_action(mgmt->frame_control))
2193 /* drop too small frames */
2194 if (len < IEEE80211_MIN_ACTION_SIZE)
2195 return RX_DROP_UNUSABLE;
2197 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
2198 return RX_DROP_UNUSABLE;
2200 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
2201 return RX_DROP_UNUSABLE;
2203 switch (mgmt->u.action.category) {
2204 case WLAN_CATEGORY_HT:
2205 /* reject HT action frames from stations not supporting HT */
2206 if (!rx->sta->sta.ht_cap.ht_supported)
2209 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2210 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2211 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2212 sdata->vif.type != NL80211_IFTYPE_AP &&
2213 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2216 /* verify action & smps_control are present */
2217 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2220 switch (mgmt->u.action.u.ht_smps.action) {
2221 case WLAN_HT_ACTION_SMPS: {
2222 struct ieee80211_supported_band *sband;
2225 /* convert to HT capability */
2226 switch (mgmt->u.action.u.ht_smps.smps_control) {
2227 case WLAN_HT_SMPS_CONTROL_DISABLED:
2228 smps = WLAN_HT_CAP_SM_PS_DISABLED;
2230 case WLAN_HT_SMPS_CONTROL_STATIC:
2231 smps = WLAN_HT_CAP_SM_PS_STATIC;
2233 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
2234 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
2239 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
2241 /* if no change do nothing */
2242 if ((rx->sta->sta.ht_cap.cap &
2243 IEEE80211_HT_CAP_SM_PS) == smps)
2246 rx->sta->sta.ht_cap.cap &= ~IEEE80211_HT_CAP_SM_PS;
2247 rx->sta->sta.ht_cap.cap |= smps;
2249 sband = rx->local->hw.wiphy->bands[status->band];
2251 rate_control_rate_update(local, sband, rx->sta,
2252 IEEE80211_RC_SMPS_CHANGED);
2260 case WLAN_CATEGORY_BACK:
2261 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2262 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2263 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2264 sdata->vif.type != NL80211_IFTYPE_AP &&
2265 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2268 /* verify action_code is present */
2269 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2272 switch (mgmt->u.action.u.addba_req.action_code) {
2273 case WLAN_ACTION_ADDBA_REQ:
2274 if (len < (IEEE80211_MIN_ACTION_SIZE +
2275 sizeof(mgmt->u.action.u.addba_req)))
2278 case WLAN_ACTION_ADDBA_RESP:
2279 if (len < (IEEE80211_MIN_ACTION_SIZE +
2280 sizeof(mgmt->u.action.u.addba_resp)))
2283 case WLAN_ACTION_DELBA:
2284 if (len < (IEEE80211_MIN_ACTION_SIZE +
2285 sizeof(mgmt->u.action.u.delba)))
2293 case WLAN_CATEGORY_SPECTRUM_MGMT:
2294 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
2297 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2300 /* verify action_code is present */
2301 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2304 switch (mgmt->u.action.u.measurement.action_code) {
2305 case WLAN_ACTION_SPCT_MSR_REQ:
2306 if (len < (IEEE80211_MIN_ACTION_SIZE +
2307 sizeof(mgmt->u.action.u.measurement)))
2309 ieee80211_process_measurement_req(sdata, mgmt, len);
2311 case WLAN_ACTION_SPCT_CHL_SWITCH:
2312 if (len < (IEEE80211_MIN_ACTION_SIZE +
2313 sizeof(mgmt->u.action.u.chan_switch)))
2316 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2319 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
2325 case WLAN_CATEGORY_SA_QUERY:
2326 if (len < (IEEE80211_MIN_ACTION_SIZE +
2327 sizeof(mgmt->u.action.u.sa_query)))
2330 switch (mgmt->u.action.u.sa_query.action) {
2331 case WLAN_ACTION_SA_QUERY_REQUEST:
2332 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2334 ieee80211_process_sa_query_req(sdata, mgmt, len);
2338 case WLAN_CATEGORY_SELF_PROTECTED:
2339 switch (mgmt->u.action.u.self_prot.action_code) {
2340 case WLAN_SP_MESH_PEERING_OPEN:
2341 case WLAN_SP_MESH_PEERING_CLOSE:
2342 case WLAN_SP_MESH_PEERING_CONFIRM:
2343 if (!ieee80211_vif_is_mesh(&sdata->vif))
2345 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
2346 /* userspace handles this frame */
2349 case WLAN_SP_MGK_INFORM:
2350 case WLAN_SP_MGK_ACK:
2351 if (!ieee80211_vif_is_mesh(&sdata->vif))
2356 case WLAN_CATEGORY_MESH_ACTION:
2357 if (!ieee80211_vif_is_mesh(&sdata->vif))
2359 if (mesh_action_is_path_sel(mgmt) &&
2360 (!mesh_path_sel_is_hwmp(sdata)))
2368 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
2369 /* will return in the next handlers */
2374 rx->sta->rx_packets++;
2375 dev_kfree_skb(rx->skb);
2379 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2380 skb_queue_tail(&sdata->skb_queue, rx->skb);
2381 ieee80211_queue_work(&local->hw, &sdata->work);
2383 rx->sta->rx_packets++;
2387 static ieee80211_rx_result debug_noinline
2388 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2390 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2393 /* skip known-bad action frames and return them in the next handler */
2394 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
2398 * Getting here means the kernel doesn't know how to handle
2399 * it, but maybe userspace does ... include returned frames
2400 * so userspace can register for those to know whether ones
2401 * it transmitted were processed or returned.
2404 if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
2405 sig = status->signal;
2407 if (cfg80211_rx_mgmt(rx->sdata->dev, status->freq, sig,
2408 rx->skb->data, rx->skb->len,
2411 rx->sta->rx_packets++;
2412 dev_kfree_skb(rx->skb);
2420 static ieee80211_rx_result debug_noinline
2421 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2423 struct ieee80211_local *local = rx->local;
2424 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2425 struct sk_buff *nskb;
2426 struct ieee80211_sub_if_data *sdata = rx->sdata;
2427 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2429 if (!ieee80211_is_action(mgmt->frame_control))
2433 * For AP mode, hostapd is responsible for handling any action
2434 * frames that we didn't handle, including returning unknown
2435 * ones. For all other modes we will return them to the sender,
2436 * setting the 0x80 bit in the action category, as required by
2437 * 802.11-2007 7.3.1.11.
2438 * Newer versions of hostapd shall also use the management frame
2439 * registration mechanisms, but older ones still use cooked
2440 * monitor interfaces so push all frames there.
2442 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
2443 (sdata->vif.type == NL80211_IFTYPE_AP ||
2444 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2445 return RX_DROP_MONITOR;
2447 /* do not return rejected action frames */
2448 if (mgmt->u.action.category & 0x80)
2449 return RX_DROP_UNUSABLE;
2451 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2454 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
2456 nmgmt->u.action.category |= 0x80;
2457 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2458 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
2460 memset(nskb->cb, 0, sizeof(nskb->cb));
2462 ieee80211_tx_skb(rx->sdata, nskb);
2464 dev_kfree_skb(rx->skb);
2468 static ieee80211_rx_result debug_noinline
2469 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
2471 struct ieee80211_sub_if_data *sdata = rx->sdata;
2472 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2475 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
2477 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2478 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2479 sdata->vif.type != NL80211_IFTYPE_STATION)
2480 return RX_DROP_MONITOR;
2483 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2484 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2485 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2486 /* process for all: mesh, mlme, ibss */
2488 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
2489 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
2490 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2491 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
2492 if (is_multicast_ether_addr(mgmt->da) &&
2493 !is_broadcast_ether_addr(mgmt->da))
2494 return RX_DROP_MONITOR;
2496 /* process only for station */
2497 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2498 return RX_DROP_MONITOR;
2500 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2501 /* process only for ibss */
2502 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
2503 return RX_DROP_MONITOR;
2506 return RX_DROP_MONITOR;
2509 /* queue up frame and kick off work to process it */
2510 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2511 skb_queue_tail(&sdata->skb_queue, rx->skb);
2512 ieee80211_queue_work(&rx->local->hw, &sdata->work);
2514 rx->sta->rx_packets++;
2519 /* TODO: use IEEE80211_RX_FRAGMENTED */
2520 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2521 struct ieee80211_rate *rate)
2523 struct ieee80211_sub_if_data *sdata;
2524 struct ieee80211_local *local = rx->local;
2525 struct sk_buff *skb = rx->skb, *skb2;
2526 struct net_device *prev_dev = NULL;
2527 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2528 int needed_headroom;
2531 * If cooked monitor has been processed already, then
2532 * don't do it again. If not, set the flag.
2534 if (rx->flags & IEEE80211_RX_CMNTR)
2536 rx->flags |= IEEE80211_RX_CMNTR;
2538 /* If there are no cooked monitor interfaces, just free the SKB */
2539 if (!local->cooked_mntrs)
2542 /* room for the radiotap header based on driver features */
2543 needed_headroom = ieee80211_rx_radiotap_len(local, status);
2545 if (skb_headroom(skb) < needed_headroom &&
2546 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
2549 /* prepend radiotap information */
2550 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
2553 skb_set_mac_header(skb, 0);
2554 skb->ip_summed = CHECKSUM_UNNECESSARY;
2555 skb->pkt_type = PACKET_OTHERHOST;
2556 skb->protocol = htons(ETH_P_802_2);
2558 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2559 if (!ieee80211_sdata_running(sdata))
2562 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
2563 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
2567 skb2 = skb_clone(skb, GFP_ATOMIC);
2569 skb2->dev = prev_dev;
2570 netif_receive_skb(skb2);
2574 prev_dev = sdata->dev;
2575 sdata->dev->stats.rx_packets++;
2576 sdata->dev->stats.rx_bytes += skb->len;
2580 skb->dev = prev_dev;
2581 netif_receive_skb(skb);
2589 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
2590 ieee80211_rx_result res)
2593 case RX_DROP_MONITOR:
2594 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2596 rx->sta->rx_dropped++;
2599 struct ieee80211_rate *rate = NULL;
2600 struct ieee80211_supported_band *sband;
2601 struct ieee80211_rx_status *status;
2603 status = IEEE80211_SKB_RXCB((rx->skb));
2605 sband = rx->local->hw.wiphy->bands[status->band];
2606 if (!(status->flag & RX_FLAG_HT))
2607 rate = &sband->bitrates[status->rate_idx];
2609 ieee80211_rx_cooked_monitor(rx, rate);
2612 case RX_DROP_UNUSABLE:
2613 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2615 rx->sta->rx_dropped++;
2616 dev_kfree_skb(rx->skb);
2619 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
2624 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx)
2626 ieee80211_rx_result res = RX_DROP_MONITOR;
2627 struct sk_buff *skb;
2629 #define CALL_RXH(rxh) \
2632 if (res != RX_CONTINUE) \
2636 spin_lock(&rx->local->rx_skb_queue.lock);
2637 if (rx->local->running_rx_handler)
2640 rx->local->running_rx_handler = true;
2642 while ((skb = __skb_dequeue(&rx->local->rx_skb_queue))) {
2643 spin_unlock(&rx->local->rx_skb_queue.lock);
2646 * all the other fields are valid across frames
2647 * that belong to an aMPDU since they are on the
2648 * same TID from the same station
2652 CALL_RXH(ieee80211_rx_h_decrypt)
2653 CALL_RXH(ieee80211_rx_h_check_more_data)
2654 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
2655 CALL_RXH(ieee80211_rx_h_sta_process)
2656 CALL_RXH(ieee80211_rx_h_defragment)
2657 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2658 /* must be after MMIC verify so header is counted in MPDU mic */
2659 #ifdef CONFIG_MAC80211_MESH
2660 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
2661 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2663 CALL_RXH(ieee80211_rx_h_amsdu)
2664 CALL_RXH(ieee80211_rx_h_data)
2665 CALL_RXH(ieee80211_rx_h_ctrl);
2666 CALL_RXH(ieee80211_rx_h_mgmt_check)
2667 CALL_RXH(ieee80211_rx_h_action)
2668 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
2669 CALL_RXH(ieee80211_rx_h_action_return)
2670 CALL_RXH(ieee80211_rx_h_mgmt)
2673 ieee80211_rx_handlers_result(rx, res);
2674 spin_lock(&rx->local->rx_skb_queue.lock);
2678 rx->local->running_rx_handler = false;
2681 spin_unlock(&rx->local->rx_skb_queue.lock);
2684 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
2686 ieee80211_rx_result res = RX_DROP_MONITOR;
2688 #define CALL_RXH(rxh) \
2691 if (res != RX_CONTINUE) \
2695 CALL_RXH(ieee80211_rx_h_passive_scan)
2696 CALL_RXH(ieee80211_rx_h_check)
2698 ieee80211_rx_reorder_ampdu(rx);
2700 ieee80211_rx_handlers(rx);
2704 ieee80211_rx_handlers_result(rx, res);
2710 * This function makes calls into the RX path, therefore
2711 * it has to be invoked under RCU read lock.
2713 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
2715 struct ieee80211_rx_data rx = {
2717 .sdata = sta->sdata,
2718 .local = sta->local,
2719 /* This is OK -- must be QoS data frame */
2720 .security_idx = tid,
2724 struct tid_ampdu_rx *tid_agg_rx;
2726 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
2730 spin_lock(&tid_agg_rx->reorder_lock);
2731 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx);
2732 spin_unlock(&tid_agg_rx->reorder_lock);
2734 ieee80211_rx_handlers(&rx);
2737 /* main receive path */
2739 static int prepare_for_handlers(struct ieee80211_rx_data *rx,
2740 struct ieee80211_hdr *hdr)
2742 struct ieee80211_sub_if_data *sdata = rx->sdata;
2743 struct sk_buff *skb = rx->skb;
2744 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2745 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
2746 int multicast = is_multicast_ether_addr(hdr->addr1);
2748 switch (sdata->vif.type) {
2749 case NL80211_IFTYPE_STATION:
2750 if (!bssid && !sdata->u.mgd.use_4addr)
2753 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
2754 if (!(sdata->dev->flags & IFF_PROMISC) ||
2755 sdata->u.mgd.use_4addr)
2757 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2760 case NL80211_IFTYPE_ADHOC:
2763 if (ieee80211_is_beacon(hdr->frame_control)) {
2766 else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
2767 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN))
2769 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2770 } else if (!multicast &&
2771 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
2772 if (!(sdata->dev->flags & IFF_PROMISC))
2774 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2775 } else if (!rx->sta) {
2777 if (status->flag & RX_FLAG_HT)
2778 rate_idx = 0; /* TODO: HT rates */
2780 rate_idx = status->rate_idx;
2781 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
2785 case NL80211_IFTYPE_MESH_POINT:
2787 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
2788 if (!(sdata->dev->flags & IFF_PROMISC))
2791 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2794 case NL80211_IFTYPE_AP_VLAN:
2795 case NL80211_IFTYPE_AP:
2797 if (!ether_addr_equal(sdata->vif.addr, hdr->addr1))
2799 } else if (!ieee80211_bssid_match(bssid,
2802 * Accept public action frames even when the
2803 * BSSID doesn't match, this is used for P2P
2804 * and location updates. Note that mac80211
2805 * itself never looks at these frames.
2807 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
2808 ieee80211_is_public_action(hdr, skb->len))
2810 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
2811 !ieee80211_is_beacon(hdr->frame_control))
2813 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2816 case NL80211_IFTYPE_WDS:
2817 if (bssid || !ieee80211_is_data(hdr->frame_control))
2819 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
2823 /* should never get here */
2832 * This function returns whether or not the SKB
2833 * was destined for RX processing or not, which,
2834 * if consume is true, is equivalent to whether
2835 * or not the skb was consumed.
2837 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
2838 struct sk_buff *skb, bool consume)
2840 struct ieee80211_local *local = rx->local;
2841 struct ieee80211_sub_if_data *sdata = rx->sdata;
2842 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2843 struct ieee80211_hdr *hdr = (void *)skb->data;
2847 status->rx_flags |= IEEE80211_RX_RA_MATCH;
2848 prepares = prepare_for_handlers(rx, hdr);
2854 skb = skb_copy(skb, GFP_ATOMIC);
2856 if (net_ratelimit())
2857 wiphy_debug(local->hw.wiphy,
2858 "failed to copy skb for %s\n",
2866 ieee80211_invoke_rx_handlers(rx);
2871 * This is the actual Rx frames handler. as it blongs to Rx path it must
2872 * be called with rcu_read_lock protection.
2874 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2875 struct sk_buff *skb)
2877 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2878 struct ieee80211_local *local = hw_to_local(hw);
2879 struct ieee80211_sub_if_data *sdata;
2880 struct ieee80211_hdr *hdr;
2882 struct ieee80211_rx_data rx;
2883 struct ieee80211_sub_if_data *prev;
2884 struct sta_info *sta, *tmp, *prev_sta;
2887 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
2888 memset(&rx, 0, sizeof(rx));
2892 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
2893 local->dot11ReceivedFragmentCount++;
2895 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
2896 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning) ||
2897 test_bit(SCAN_SW_SCANNING, &local->scanning)))
2898 status->rx_flags |= IEEE80211_RX_IN_SCAN;
2900 if (ieee80211_is_mgmt(fc))
2901 err = skb_linearize(skb);
2903 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
2910 hdr = (struct ieee80211_hdr *)skb->data;
2911 ieee80211_parse_qos(&rx);
2912 ieee80211_verify_alignment(&rx);
2914 if (ieee80211_is_data(fc)) {
2917 for_each_sta_info(local, hdr->addr2, sta, tmp) {
2924 rx.sdata = prev_sta->sdata;
2925 ieee80211_prepare_and_rx_handle(&rx, skb, false);
2932 rx.sdata = prev_sta->sdata;
2934 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2942 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2943 if (!ieee80211_sdata_running(sdata))
2946 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2947 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2951 * frame is destined for this interface, but if it's
2952 * not also for the previous one we handle that after
2953 * the loop to avoid copying the SKB once too much
2961 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2963 ieee80211_prepare_and_rx_handle(&rx, skb, false);
2969 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2972 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2981 * This is the receive path handler. It is called by a low level driver when an
2982 * 802.11 MPDU is received from the hardware.
2984 void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2986 struct ieee80211_local *local = hw_to_local(hw);
2987 struct ieee80211_rate *rate = NULL;
2988 struct ieee80211_supported_band *sband;
2989 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2991 WARN_ON_ONCE(softirq_count() == 0);
2993 if (WARN_ON(status->band < 0 ||
2994 status->band >= IEEE80211_NUM_BANDS))
2997 sband = local->hw.wiphy->bands[status->band];
2998 if (WARN_ON(!sband))
3002 * If we're suspending, it is possible although not too likely
3003 * that we'd be receiving frames after having already partially
3004 * quiesced the stack. We can't process such frames then since
3005 * that might, for example, cause stations to be added or other
3006 * driver callbacks be invoked.
3008 if (unlikely(local->quiescing || local->suspended))
3011 /* We might be during a HW reconfig, prevent Rx for the same reason */
3012 if (unlikely(local->in_reconfig))
3016 * The same happens when we're not even started,
3017 * but that's worth a warning.
3019 if (WARN_ON(!local->started))
3022 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
3024 * Validate the rate, unless a PLCP error means that
3025 * we probably can't have a valid rate here anyway.
3028 if (status->flag & RX_FLAG_HT) {
3030 * rate_idx is MCS index, which can be [0-76]
3033 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
3035 * Anything else would be some sort of driver or
3036 * hardware error. The driver should catch hardware
3039 if (WARN((status->rate_idx < 0 ||
3040 status->rate_idx > 76),
3041 "Rate marked as an HT rate but passed "
3042 "status->rate_idx is not "
3043 "an MCS index [0-76]: %d (0x%02x)\n",
3048 if (WARN_ON(status->rate_idx < 0 ||
3049 status->rate_idx >= sband->n_bitrates))
3051 rate = &sband->bitrates[status->rate_idx];
3055 status->rx_flags = 0;
3058 * key references and virtual interfaces are protected using RCU
3059 * and this requires that we are in a read-side RCU section during
3060 * receive processing
3065 * Frames with failed FCS/PLCP checksum are not returned,
3066 * all other frames are returned without radiotap header
3067 * if it was previously present.
3068 * Also, frames with less than 16 bytes are dropped.
3070 skb = ieee80211_rx_monitor(local, skb, rate);
3076 ieee80211_tpt_led_trig_rx(local,
3077 ((struct ieee80211_hdr *)skb->data)->frame_control,
3079 __ieee80211_rx_handle_packet(hw, skb);
3087 EXPORT_SYMBOL(ieee80211_rx);
3089 /* This is a version of the rx handler that can be called from hard irq
3090 * context. Post the skb on the queue and schedule the tasklet */
3091 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
3093 struct ieee80211_local *local = hw_to_local(hw);
3095 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3097 skb->pkt_type = IEEE80211_RX_MSG;
3098 skb_queue_tail(&local->skb_queue, skb);
3099 tasklet_schedule(&local->tasklet);
3101 EXPORT_SYMBOL(ieee80211_rx_irqsafe);