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>
23 #include "ieee80211_i.h"
24 #include "driver-ops.h"
33 * monitor mode reception
35 * This function cleans up the SKB, i.e. it removes all the stuff
36 * only useful for monitoring.
38 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
41 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
42 if (likely(skb->len > FCS_LEN))
43 __pskb_trim(skb, skb->len - FCS_LEN);
55 static inline int should_drop_frame(struct sk_buff *skb,
58 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
59 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
61 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
63 if (unlikely(skb->len < 16 + present_fcs_len))
65 if (ieee80211_is_ctl(hdr->frame_control) &&
66 !ieee80211_is_pspoll(hdr->frame_control) &&
67 !ieee80211_is_back_req(hdr->frame_control))
73 ieee80211_rx_radiotap_len(struct ieee80211_local *local,
74 struct ieee80211_rx_status *status)
78 /* always present fields */
79 len = sizeof(struct ieee80211_radiotap_header) + 9;
81 if (status->flag & RX_FLAG_MACTIME_MPDU)
83 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
86 if (len & 1) /* padding for RX_FLAGS if necessary */
89 if (status->flag & RX_FLAG_HT) /* HT info */
96 * ieee80211_add_rx_radiotap_header - add radiotap header
98 * add a radiotap header containing all the fields which the hardware provided.
101 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
103 struct ieee80211_rate *rate,
106 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
107 struct ieee80211_radiotap_header *rthdr;
111 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
112 memset(rthdr, 0, rtap_len);
114 /* radiotap header, set always present flags */
116 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
117 (1 << IEEE80211_RADIOTAP_CHANNEL) |
118 (1 << IEEE80211_RADIOTAP_ANTENNA) |
119 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
120 rthdr->it_len = cpu_to_le16(rtap_len);
122 pos = (unsigned char *)(rthdr+1);
124 /* the order of the following fields is important */
126 /* IEEE80211_RADIOTAP_TSFT */
127 if (status->flag & RX_FLAG_MACTIME_MPDU) {
128 put_unaligned_le64(status->mactime, pos);
130 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
134 /* IEEE80211_RADIOTAP_FLAGS */
135 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
136 *pos |= IEEE80211_RADIOTAP_F_FCS;
137 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
138 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
139 if (status->flag & RX_FLAG_SHORTPRE)
140 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
143 /* IEEE80211_RADIOTAP_RATE */
144 if (!rate || status->flag & RX_FLAG_HT) {
146 * Without rate information don't add it. If we have,
147 * MCS information is a separate field in radiotap,
148 * added below. The byte here is needed as padding
149 * for the channel though, so initialise it to 0.
153 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
154 *pos = rate->bitrate / 5;
158 /* IEEE80211_RADIOTAP_CHANNEL */
159 put_unaligned_le16(status->freq, pos);
161 if (status->band == IEEE80211_BAND_5GHZ)
162 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
164 else if (status->flag & RX_FLAG_HT)
165 put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
167 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
168 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
171 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
174 put_unaligned_le16(IEEE80211_CHAN_2GHZ, pos);
177 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
178 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
179 *pos = status->signal;
181 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
185 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
187 /* IEEE80211_RADIOTAP_ANTENNA */
188 *pos = status->antenna;
191 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
193 /* IEEE80211_RADIOTAP_RX_FLAGS */
194 /* ensure 2 byte alignment for the 2 byte field as required */
195 if ((pos - (u8 *)rthdr) & 1)
197 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
198 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
199 put_unaligned_le16(rx_flags, pos);
202 if (status->flag & RX_FLAG_HT) {
203 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
204 *pos++ = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
205 IEEE80211_RADIOTAP_MCS_HAVE_GI |
206 IEEE80211_RADIOTAP_MCS_HAVE_BW;
208 if (status->flag & RX_FLAG_SHORT_GI)
209 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
210 if (status->flag & RX_FLAG_40MHZ)
211 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
213 *pos++ = status->rate_idx;
218 * This function copies a received frame to all monitor interfaces and
219 * returns a cleaned-up SKB that no longer includes the FCS nor the
220 * radiotap header the driver might have added.
222 static struct sk_buff *
223 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
224 struct ieee80211_rate *rate)
226 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
227 struct ieee80211_sub_if_data *sdata;
228 int needed_headroom = 0;
229 struct sk_buff *skb, *skb2;
230 struct net_device *prev_dev = NULL;
231 int present_fcs_len = 0;
234 * First, we may need to make a copy of the skb because
235 * (1) we need to modify it for radiotap (if not present), and
236 * (2) the other RX handlers will modify the skb we got.
238 * We don't need to, of course, if we aren't going to return
239 * the SKB because it has a bad FCS/PLCP checksum.
242 /* room for the radiotap header based on driver features */
243 needed_headroom = ieee80211_rx_radiotap_len(local, status);
245 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
246 present_fcs_len = FCS_LEN;
248 /* make sure hdr->frame_control is on the linear part */
249 if (!pskb_may_pull(origskb, 2)) {
250 dev_kfree_skb(origskb);
254 if (!local->monitors) {
255 if (should_drop_frame(origskb, present_fcs_len)) {
256 dev_kfree_skb(origskb);
260 return remove_monitor_info(local, origskb);
263 if (should_drop_frame(origskb, present_fcs_len)) {
264 /* only need to expand headroom if necessary */
269 * This shouldn't trigger often because most devices have an
270 * RX header they pull before we get here, and that should
271 * be big enough for our radiotap information. We should
272 * probably export the length to drivers so that we can have
273 * them allocate enough headroom to start with.
275 if (skb_headroom(skb) < needed_headroom &&
276 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
282 * Need to make a copy and possibly remove radiotap header
283 * and FCS from the original.
285 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
287 origskb = remove_monitor_info(local, origskb);
293 /* prepend radiotap information */
294 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
296 skb_reset_mac_header(skb);
297 skb->ip_summed = CHECKSUM_UNNECESSARY;
298 skb->pkt_type = PACKET_OTHERHOST;
299 skb->protocol = htons(ETH_P_802_2);
301 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
302 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
305 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
308 if (!ieee80211_sdata_running(sdata))
312 skb2 = skb_clone(skb, GFP_ATOMIC);
314 skb2->dev = prev_dev;
315 netif_receive_skb(skb2);
319 prev_dev = sdata->dev;
320 sdata->dev->stats.rx_packets++;
321 sdata->dev->stats.rx_bytes += skb->len;
326 netif_receive_skb(skb);
334 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
336 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
337 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
338 int tid, seqno_idx, security_idx;
340 /* does the frame have a qos control field? */
341 if (ieee80211_is_data_qos(hdr->frame_control)) {
342 u8 *qc = ieee80211_get_qos_ctl(hdr);
343 /* frame has qos control */
344 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
345 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
346 status->rx_flags |= IEEE80211_RX_AMSDU;
352 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
354 * Sequence numbers for management frames, QoS data
355 * frames with a broadcast/multicast address in the
356 * Address 1 field, and all non-QoS data frames sent
357 * by QoS STAs are assigned using an additional single
358 * modulo-4096 counter, [...]
360 * We also use that counter for non-QoS STAs.
362 seqno_idx = NUM_RX_DATA_QUEUES;
364 if (ieee80211_is_mgmt(hdr->frame_control))
365 security_idx = NUM_RX_DATA_QUEUES;
369 rx->seqno_idx = seqno_idx;
370 rx->security_idx = security_idx;
371 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
372 * For now, set skb->priority to 0 for other cases. */
373 rx->skb->priority = (tid > 7) ? 0 : tid;
377 * DOC: Packet alignment
379 * Drivers always need to pass packets that are aligned to two-byte boundaries
382 * Additionally, should, if possible, align the payload data in a way that
383 * guarantees that the contained IP header is aligned to a four-byte
384 * boundary. In the case of regular frames, this simply means aligning the
385 * payload to a four-byte boundary (because either the IP header is directly
386 * contained, or IV/RFC1042 headers that have a length divisible by four are
387 * in front of it). If the payload data is not properly aligned and the
388 * architecture doesn't support efficient unaligned operations, mac80211
389 * will align the data.
391 * With A-MSDU frames, however, the payload data address must yield two modulo
392 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
393 * push the IP header further back to a multiple of four again. Thankfully, the
394 * specs were sane enough this time around to require padding each A-MSDU
395 * subframe to a length that is a multiple of four.
397 * Padding like Atheros hardware adds which is between the 802.11 header and
398 * the payload is not supported, the driver is required to move the 802.11
399 * header to be directly in front of the payload in that case.
401 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
403 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
404 WARN_ONCE((unsigned long)rx->skb->data & 1,
405 "unaligned packet at 0x%p\n", rx->skb->data);
412 static ieee80211_rx_result debug_noinline
413 ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
415 struct ieee80211_local *local = rx->local;
416 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
417 struct sk_buff *skb = rx->skb;
419 if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
420 !local->sched_scanning))
423 if (test_bit(SCAN_HW_SCANNING, &local->scanning) ||
424 local->sched_scanning)
425 return ieee80211_scan_rx(rx->sdata, skb);
427 if (test_bit(SCAN_SW_SCANNING, &local->scanning)) {
428 /* drop all the other packets during a software scan anyway */
429 if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
434 /* scanning finished during invoking of handlers */
435 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
436 return RX_DROP_UNUSABLE;
440 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
442 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
444 if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
447 return ieee80211_is_robust_mgmt_frame(hdr);
451 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
453 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
455 if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
458 return ieee80211_is_robust_mgmt_frame(hdr);
462 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
463 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
465 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
466 struct ieee80211_mmie *mmie;
468 if (skb->len < 24 + sizeof(*mmie) ||
469 !is_multicast_ether_addr(hdr->da))
472 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
473 return -1; /* not a robust management frame */
475 mmie = (struct ieee80211_mmie *)
476 (skb->data + skb->len - sizeof(*mmie));
477 if (mmie->element_id != WLAN_EID_MMIE ||
478 mmie->length != sizeof(*mmie) - 2)
481 return le16_to_cpu(mmie->key_id);
485 static ieee80211_rx_result
486 ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
488 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
489 char *dev_addr = rx->sdata->vif.addr;
491 if (ieee80211_is_data(hdr->frame_control)) {
492 if (is_multicast_ether_addr(hdr->addr1)) {
493 if (ieee80211_has_tods(hdr->frame_control) ||
494 !ieee80211_has_fromds(hdr->frame_control))
495 return RX_DROP_MONITOR;
496 if (memcmp(hdr->addr3, dev_addr, ETH_ALEN) == 0)
497 return RX_DROP_MONITOR;
499 if (!ieee80211_has_a4(hdr->frame_control))
500 return RX_DROP_MONITOR;
501 if (memcmp(hdr->addr4, dev_addr, ETH_ALEN) == 0)
502 return RX_DROP_MONITOR;
506 /* If there is not an established peer link and this is not a peer link
507 * establisment frame, beacon or probe, drop the frame.
510 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
511 struct ieee80211_mgmt *mgmt;
513 if (!ieee80211_is_mgmt(hdr->frame_control))
514 return RX_DROP_MONITOR;
516 if (ieee80211_is_action(hdr->frame_control)) {
519 /* make sure category field is present */
520 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
521 return RX_DROP_MONITOR;
523 mgmt = (struct ieee80211_mgmt *)hdr;
524 category = mgmt->u.action.category;
525 if (category != WLAN_CATEGORY_MESH_ACTION &&
526 category != WLAN_CATEGORY_SELF_PROTECTED)
527 return RX_DROP_MONITOR;
531 if (ieee80211_is_probe_req(hdr->frame_control) ||
532 ieee80211_is_probe_resp(hdr->frame_control) ||
533 ieee80211_is_beacon(hdr->frame_control) ||
534 ieee80211_is_auth(hdr->frame_control))
537 return RX_DROP_MONITOR;
544 #define SEQ_MODULO 0x1000
545 #define SEQ_MASK 0xfff
547 static inline int seq_less(u16 sq1, u16 sq2)
549 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
552 static inline u16 seq_inc(u16 sq)
554 return (sq + 1) & SEQ_MASK;
557 static inline u16 seq_sub(u16 sq1, u16 sq2)
559 return (sq1 - sq2) & SEQ_MASK;
563 static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
564 struct tid_ampdu_rx *tid_agg_rx,
567 struct ieee80211_local *local = hw_to_local(hw);
568 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
569 struct ieee80211_rx_status *status;
571 lockdep_assert_held(&tid_agg_rx->reorder_lock);
576 /* release the frame from the reorder ring buffer */
577 tid_agg_rx->stored_mpdu_num--;
578 tid_agg_rx->reorder_buf[index] = NULL;
579 status = IEEE80211_SKB_RXCB(skb);
580 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
581 skb_queue_tail(&local->rx_skb_queue, skb);
584 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
587 static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw,
588 struct tid_ampdu_rx *tid_agg_rx,
593 lockdep_assert_held(&tid_agg_rx->reorder_lock);
595 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
596 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
597 tid_agg_rx->buf_size;
598 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
603 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
604 * the skb was added to the buffer longer than this time ago, the earlier
605 * frames that have not yet been received are assumed to be lost and the skb
606 * can be released for processing. This may also release other skb's from the
607 * reorder buffer if there are no additional gaps between the frames.
609 * Callers must hold tid_agg_rx->reorder_lock.
611 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
613 static void ieee80211_sta_reorder_release(struct ieee80211_hw *hw,
614 struct tid_ampdu_rx *tid_agg_rx)
618 lockdep_assert_held(&tid_agg_rx->reorder_lock);
620 /* release the buffer until next missing frame */
621 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
622 tid_agg_rx->buf_size;
623 if (!tid_agg_rx->reorder_buf[index] &&
624 tid_agg_rx->stored_mpdu_num) {
626 * No buffers ready to be released, but check whether any
627 * frames in the reorder buffer have timed out.
630 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
631 j = (j + 1) % tid_agg_rx->buf_size) {
632 if (!tid_agg_rx->reorder_buf[j]) {
637 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
638 HT_RX_REORDER_BUF_TIMEOUT))
639 goto set_release_timer;
641 #ifdef CONFIG_MAC80211_HT_DEBUG
643 wiphy_debug(hw->wiphy,
644 "release an RX reorder frame due to timeout on earlier frames\n");
646 ieee80211_release_reorder_frame(hw, tid_agg_rx, j);
649 * Increment the head seq# also for the skipped slots.
651 tid_agg_rx->head_seq_num =
652 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
655 } else while (tid_agg_rx->reorder_buf[index]) {
656 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
657 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
658 tid_agg_rx->buf_size;
661 if (tid_agg_rx->stored_mpdu_num) {
662 j = index = seq_sub(tid_agg_rx->head_seq_num,
663 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
665 for (; j != (index - 1) % tid_agg_rx->buf_size;
666 j = (j + 1) % tid_agg_rx->buf_size) {
667 if (tid_agg_rx->reorder_buf[j])
673 mod_timer(&tid_agg_rx->reorder_timer,
674 tid_agg_rx->reorder_time[j] + 1 +
675 HT_RX_REORDER_BUF_TIMEOUT);
677 del_timer(&tid_agg_rx->reorder_timer);
682 * As this function belongs to the RX path it must be under
683 * rcu_read_lock protection. It returns false if the frame
684 * can be processed immediately, true if it was consumed.
686 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
687 struct tid_ampdu_rx *tid_agg_rx,
690 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
691 u16 sc = le16_to_cpu(hdr->seq_ctrl);
692 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
693 u16 head_seq_num, buf_size;
697 spin_lock(&tid_agg_rx->reorder_lock);
699 buf_size = tid_agg_rx->buf_size;
700 head_seq_num = tid_agg_rx->head_seq_num;
702 /* frame with out of date sequence number */
703 if (seq_less(mpdu_seq_num, head_seq_num)) {
709 * If frame the sequence number exceeds our buffering window
710 * size release some previous frames to make room for this one.
712 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
713 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
714 /* release stored frames up to new head to stack */
715 ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num);
718 /* Now the new frame is always in the range of the reordering buffer */
720 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
722 /* check if we already stored this frame */
723 if (tid_agg_rx->reorder_buf[index]) {
729 * If the current MPDU is in the right order and nothing else
730 * is stored we can process it directly, no need to buffer it.
731 * If it is first but there's something stored, we may be able
732 * to release frames after this one.
734 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
735 tid_agg_rx->stored_mpdu_num == 0) {
736 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
741 /* put the frame in the reordering buffer */
742 tid_agg_rx->reorder_buf[index] = skb;
743 tid_agg_rx->reorder_time[index] = jiffies;
744 tid_agg_rx->stored_mpdu_num++;
745 ieee80211_sta_reorder_release(hw, tid_agg_rx);
748 spin_unlock(&tid_agg_rx->reorder_lock);
753 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
754 * true if the MPDU was buffered, false if it should be processed.
756 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx)
758 struct sk_buff *skb = rx->skb;
759 struct ieee80211_local *local = rx->local;
760 struct ieee80211_hw *hw = &local->hw;
761 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
762 struct sta_info *sta = rx->sta;
763 struct tid_ampdu_rx *tid_agg_rx;
767 if (!ieee80211_is_data_qos(hdr->frame_control))
771 * filter the QoS data rx stream according to
772 * STA/TID and check if this STA/TID is on aggregation
778 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
780 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
784 /* qos null data frames are excluded */
785 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
788 /* new, potentially un-ordered, ampdu frame - process it */
790 /* reset session timer */
791 if (tid_agg_rx->timeout)
792 mod_timer(&tid_agg_rx->session_timer,
793 TU_TO_EXP_TIME(tid_agg_rx->timeout));
795 /* if this mpdu is fragmented - terminate rx aggregation session */
796 sc = le16_to_cpu(hdr->seq_ctrl);
797 if (sc & IEEE80211_SCTL_FRAG) {
798 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
799 skb_queue_tail(&rx->sdata->skb_queue, skb);
800 ieee80211_queue_work(&local->hw, &rx->sdata->work);
805 * No locking needed -- we will only ever process one
806 * RX packet at a time, and thus own tid_agg_rx. All
807 * other code manipulating it needs to (and does) make
808 * sure that we cannot get to it any more before doing
811 if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb))
815 skb_queue_tail(&local->rx_skb_queue, skb);
818 static ieee80211_rx_result debug_noinline
819 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
821 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
822 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
824 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
825 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
826 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
827 rx->sta->last_seq_ctrl[rx->seqno_idx] ==
829 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
830 rx->local->dot11FrameDuplicateCount++;
831 rx->sta->num_duplicates++;
833 return RX_DROP_UNUSABLE;
835 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
838 if (unlikely(rx->skb->len < 16)) {
839 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
840 return RX_DROP_MONITOR;
843 /* Drop disallowed frame classes based on STA auth/assoc state;
844 * IEEE 802.11, Chap 5.5.
846 * mac80211 filters only based on association state, i.e. it drops
847 * Class 3 frames from not associated stations. hostapd sends
848 * deauth/disassoc frames when needed. In addition, hostapd is
849 * responsible for filtering on both auth and assoc states.
852 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
853 return ieee80211_rx_mesh_check(rx);
855 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
856 ieee80211_is_pspoll(hdr->frame_control)) &&
857 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
858 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
859 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
860 if (rx->sta && rx->sta->dummy &&
861 ieee80211_is_data_present(hdr->frame_control)) {
865 payload = rx->skb->data +
866 ieee80211_hdrlen(hdr->frame_control);
867 ethertype = (payload[6] << 8) | payload[7];
868 if (cpu_to_be16(ethertype) ==
869 rx->sdata->control_port_protocol)
872 return RX_DROP_MONITOR;
879 static ieee80211_rx_result debug_noinline
880 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
882 struct sk_buff *skb = rx->skb;
883 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
884 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
887 ieee80211_rx_result result = RX_DROP_UNUSABLE;
888 struct ieee80211_key *sta_ptk = NULL;
889 int mmie_keyidx = -1;
895 * There are four types of keys:
897 * - IGTK (group keys for management frames)
898 * - PTK (pairwise keys)
899 * - STK (station-to-station pairwise keys)
901 * When selecting a key, we have to distinguish between multicast
902 * (including broadcast) and unicast frames, the latter can only
903 * use PTKs and STKs while the former always use GTKs and IGTKs.
904 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
905 * unicast frames can also use key indices like GTKs. Hence, if we
906 * don't have a PTK/STK we check the key index for a WEP key.
908 * Note that in a regular BSS, multicast frames are sent by the
909 * AP only, associated stations unicast the frame to the AP first
910 * which then multicasts it on their behalf.
912 * There is also a slight problem in IBSS mode: GTKs are negotiated
913 * with each station, that is something we don't currently handle.
914 * The spec seems to expect that one negotiates the same key with
915 * every station but there's no such requirement; VLANs could be
920 * No point in finding a key and decrypting if the frame is neither
921 * addressed to us nor a multicast frame.
923 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
926 /* start without a key */
930 sta_ptk = rcu_dereference(rx->sta->ptk);
932 fc = hdr->frame_control;
934 if (!ieee80211_has_protected(fc))
935 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
937 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
939 if ((status->flag & RX_FLAG_DECRYPTED) &&
940 (status->flag & RX_FLAG_IV_STRIPPED))
942 /* Skip decryption if the frame is not protected. */
943 if (!ieee80211_has_protected(fc))
945 } else if (mmie_keyidx >= 0) {
946 /* Broadcast/multicast robust management frame / BIP */
947 if ((status->flag & RX_FLAG_DECRYPTED) &&
948 (status->flag & RX_FLAG_IV_STRIPPED))
951 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
952 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
953 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
955 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
957 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
958 } else if (!ieee80211_has_protected(fc)) {
960 * The frame was not protected, so skip decryption. However, we
961 * need to set rx->key if there is a key that could have been
962 * used so that the frame may be dropped if encryption would
963 * have been expected.
965 struct ieee80211_key *key = NULL;
966 struct ieee80211_sub_if_data *sdata = rx->sdata;
969 if (ieee80211_is_mgmt(fc) &&
970 is_multicast_ether_addr(hdr->addr1) &&
971 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
975 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
976 key = rcu_dereference(rx->sta->gtk[i]);
982 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
983 key = rcu_dereference(sdata->keys[i]);
995 * The device doesn't give us the IV so we won't be
996 * able to look up the key. That's ok though, we
997 * don't need to decrypt the frame, we just won't
998 * be able to keep statistics accurate.
999 * Except for key threshold notifications, should
1000 * we somehow allow the driver to tell us which key
1001 * the hardware used if this flag is set?
1003 if ((status->flag & RX_FLAG_DECRYPTED) &&
1004 (status->flag & RX_FLAG_IV_STRIPPED))
1007 hdrlen = ieee80211_hdrlen(fc);
1009 if (rx->skb->len < 8 + hdrlen)
1010 return RX_DROP_UNUSABLE; /* TODO: count this? */
1013 * no need to call ieee80211_wep_get_keyidx,
1014 * it verifies a bunch of things we've done already
1016 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1017 keyidx = keyid >> 6;
1019 /* check per-station GTK first, if multicast packet */
1020 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1021 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1023 /* if not found, try default key */
1025 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1028 * RSNA-protected unicast frames should always be
1029 * sent with pairwise or station-to-station keys,
1030 * but for WEP we allow using a key index as well.
1033 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1034 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1035 !is_multicast_ether_addr(hdr->addr1))
1041 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1042 return RX_DROP_MONITOR;
1044 rx->key->tx_rx_count++;
1045 /* TODO: add threshold stuff again */
1047 return RX_DROP_MONITOR;
1050 if (skb_linearize(rx->skb))
1051 return RX_DROP_UNUSABLE;
1052 /* the hdr variable is invalid now! */
1054 switch (rx->key->conf.cipher) {
1055 case WLAN_CIPHER_SUITE_WEP40:
1056 case WLAN_CIPHER_SUITE_WEP104:
1057 /* Check for weak IVs if possible */
1058 if (rx->sta && ieee80211_is_data(fc) &&
1059 (!(status->flag & RX_FLAG_IV_STRIPPED) ||
1060 !(status->flag & RX_FLAG_DECRYPTED)) &&
1061 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
1062 rx->sta->wep_weak_iv_count++;
1064 result = ieee80211_crypto_wep_decrypt(rx);
1066 case WLAN_CIPHER_SUITE_TKIP:
1067 result = ieee80211_crypto_tkip_decrypt(rx);
1069 case WLAN_CIPHER_SUITE_CCMP:
1070 result = ieee80211_crypto_ccmp_decrypt(rx);
1072 case WLAN_CIPHER_SUITE_AES_CMAC:
1073 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1077 * We can reach here only with HW-only algorithms
1078 * but why didn't it decrypt the frame?!
1080 return RX_DROP_UNUSABLE;
1083 /* either the frame has been decrypted or will be dropped */
1084 status->flag |= RX_FLAG_DECRYPTED;
1089 static ieee80211_rx_result debug_noinline
1090 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1092 struct ieee80211_local *local;
1093 struct ieee80211_hdr *hdr;
1094 struct sk_buff *skb;
1098 hdr = (struct ieee80211_hdr *) skb->data;
1100 if (!local->pspolling)
1103 if (!ieee80211_has_fromds(hdr->frame_control))
1104 /* this is not from AP */
1107 if (!ieee80211_is_data(hdr->frame_control))
1110 if (!ieee80211_has_moredata(hdr->frame_control)) {
1111 /* AP has no more frames buffered for us */
1112 local->pspolling = false;
1116 /* more data bit is set, let's request a new frame from the AP */
1117 ieee80211_send_pspoll(local, rx->sdata);
1122 static void ap_sta_ps_start(struct sta_info *sta)
1124 struct ieee80211_sub_if_data *sdata = sta->sdata;
1125 struct ieee80211_local *local = sdata->local;
1127 atomic_inc(&sdata->bss->num_sta_ps);
1128 set_sta_flag(sta, WLAN_STA_PS_STA);
1129 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1130 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1131 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1132 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
1133 sdata->name, sta->sta.addr, sta->sta.aid);
1134 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1137 static void ap_sta_ps_end(struct sta_info *sta)
1139 struct ieee80211_sub_if_data *sdata = sta->sdata;
1141 atomic_dec(&sdata->bss->num_sta_ps);
1143 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1144 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
1145 sdata->name, sta->sta.addr, sta->sta.aid);
1146 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1148 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1149 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1150 printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n",
1151 sdata->name, sta->sta.addr, sta->sta.aid);
1152 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1156 ieee80211_sta_ps_deliver_wakeup(sta);
1159 int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1161 struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1164 WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
1166 /* Don't let the same PS state be set twice */
1167 in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
1168 if ((start && in_ps) || (!start && !in_ps))
1172 ap_sta_ps_start(sta_inf);
1174 ap_sta_ps_end(sta_inf);
1178 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1180 static ieee80211_rx_result debug_noinline
1181 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1183 struct ieee80211_sub_if_data *sdata = rx->sdata;
1184 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1185 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1188 if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH))
1191 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1192 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1196 * The device handles station powersave, so don't do anything about
1197 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1198 * it to mac80211 since they're handled.)
1200 if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
1204 * Don't do anything if the station isn't already asleep. In
1205 * the uAPSD case, the station will probably be marked asleep,
1206 * in the PS-Poll case the station must be confused ...
1208 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1211 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1212 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1213 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1214 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1216 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
1219 /* Free PS Poll skb here instead of returning RX_DROP that would
1220 * count as an dropped frame. */
1221 dev_kfree_skb(rx->skb);
1224 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1225 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1226 ieee80211_has_pm(hdr->frame_control) &&
1227 (ieee80211_is_data_qos(hdr->frame_control) ||
1228 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1229 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1230 ac = ieee802_1d_to_ac[tid & 7];
1233 * If this AC is not trigger-enabled do nothing.
1235 * NB: This could/should check a separate bitmap of trigger-
1236 * enabled queues, but for now we only implement uAPSD w/o
1237 * TSPEC changes to the ACs, so they're always the same.
1239 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1242 /* if we are in a service period, do nothing */
1243 if (test_sta_flag(rx->sta, WLAN_STA_SP))
1246 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
1247 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1249 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
1255 static ieee80211_rx_result debug_noinline
1256 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1258 struct sta_info *sta = rx->sta;
1259 struct sk_buff *skb = rx->skb;
1260 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1261 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1267 * Update last_rx only for IBSS packets which are for the current
1268 * BSSID to avoid keeping the current IBSS network alive in cases
1269 * where other STAs start using different BSSID.
1271 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1272 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1273 NL80211_IFTYPE_ADHOC);
1274 if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0) {
1275 sta->last_rx = jiffies;
1276 if (ieee80211_is_data(hdr->frame_control)) {
1277 sta->last_rx_rate_idx = status->rate_idx;
1278 sta->last_rx_rate_flag = status->flag;
1281 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1283 * Mesh beacons will update last_rx when if they are found to
1284 * match the current local configuration when processed.
1286 sta->last_rx = jiffies;
1287 if (ieee80211_is_data(hdr->frame_control)) {
1288 sta->last_rx_rate_idx = status->rate_idx;
1289 sta->last_rx_rate_flag = status->flag;
1293 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
1296 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1297 ieee80211_sta_rx_notify(rx->sdata, hdr);
1299 sta->rx_fragments++;
1300 sta->rx_bytes += rx->skb->len;
1301 sta->last_signal = status->signal;
1302 ewma_add(&sta->avg_signal, -status->signal);
1305 * Change STA power saving mode only at the end of a frame
1306 * exchange sequence.
1308 if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
1309 !ieee80211_has_morefrags(hdr->frame_control) &&
1310 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1311 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1312 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1313 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1315 * Ignore doze->wake transitions that are
1316 * indicated by non-data frames, the standard
1317 * is unclear here, but for example going to
1318 * PS mode and then scanning would cause a
1319 * doze->wake transition for the probe request,
1320 * and that is clearly undesirable.
1322 if (ieee80211_is_data(hdr->frame_control) &&
1323 !ieee80211_has_pm(hdr->frame_control))
1326 if (ieee80211_has_pm(hdr->frame_control))
1327 ap_sta_ps_start(sta);
1332 * Drop (qos-)data::nullfunc frames silently, since they
1333 * are used only to control station power saving mode.
1335 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1336 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1337 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1340 * If we receive a 4-addr nullfunc frame from a STA
1341 * that was not moved to a 4-addr STA vlan yet, drop
1342 * the frame to the monitor interface, to make sure
1343 * that hostapd sees it
1345 if (ieee80211_has_a4(hdr->frame_control) &&
1346 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1347 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1348 !rx->sdata->u.vlan.sta)))
1349 return RX_DROP_MONITOR;
1351 * Update counter and free packet here to avoid
1352 * counting this as a dropped packed.
1355 dev_kfree_skb(rx->skb);
1360 } /* ieee80211_rx_h_sta_process */
1362 static inline struct ieee80211_fragment_entry *
1363 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1364 unsigned int frag, unsigned int seq, int rx_queue,
1365 struct sk_buff **skb)
1367 struct ieee80211_fragment_entry *entry;
1370 idx = sdata->fragment_next;
1371 entry = &sdata->fragments[sdata->fragment_next++];
1372 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1373 sdata->fragment_next = 0;
1375 if (!skb_queue_empty(&entry->skb_list)) {
1376 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1377 struct ieee80211_hdr *hdr =
1378 (struct ieee80211_hdr *) entry->skb_list.next->data;
1379 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
1380 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
1381 "addr1=%pM addr2=%pM\n",
1383 jiffies - entry->first_frag_time, entry->seq,
1384 entry->last_frag, hdr->addr1, hdr->addr2);
1386 __skb_queue_purge(&entry->skb_list);
1389 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1391 entry->first_frag_time = jiffies;
1393 entry->rx_queue = rx_queue;
1394 entry->last_frag = frag;
1396 entry->extra_len = 0;
1401 static inline struct ieee80211_fragment_entry *
1402 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
1403 unsigned int frag, unsigned int seq,
1404 int rx_queue, struct ieee80211_hdr *hdr)
1406 struct ieee80211_fragment_entry *entry;
1409 idx = sdata->fragment_next;
1410 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1411 struct ieee80211_hdr *f_hdr;
1415 idx = IEEE80211_FRAGMENT_MAX - 1;
1417 entry = &sdata->fragments[idx];
1418 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1419 entry->rx_queue != rx_queue ||
1420 entry->last_frag + 1 != frag)
1423 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1426 * Check ftype and addresses are equal, else check next fragment
1428 if (((hdr->frame_control ^ f_hdr->frame_control) &
1429 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1430 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
1431 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
1434 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1435 __skb_queue_purge(&entry->skb_list);
1444 static ieee80211_rx_result debug_noinline
1445 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1447 struct ieee80211_hdr *hdr;
1450 unsigned int frag, seq;
1451 struct ieee80211_fragment_entry *entry;
1452 struct sk_buff *skb;
1453 struct ieee80211_rx_status *status;
1455 hdr = (struct ieee80211_hdr *)rx->skb->data;
1456 fc = hdr->frame_control;
1458 if (ieee80211_is_ctl(fc))
1461 sc = le16_to_cpu(hdr->seq_ctrl);
1462 frag = sc & IEEE80211_SCTL_FRAG;
1464 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
1465 is_multicast_ether_addr(hdr->addr1))) {
1466 /* not fragmented */
1469 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1471 if (skb_linearize(rx->skb))
1472 return RX_DROP_UNUSABLE;
1475 * skb_linearize() might change the skb->data and
1476 * previously cached variables (in this case, hdr) need to
1477 * be refreshed with the new data.
1479 hdr = (struct ieee80211_hdr *)rx->skb->data;
1480 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1483 /* This is the first fragment of a new frame. */
1484 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
1485 rx->seqno_idx, &(rx->skb));
1486 if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
1487 ieee80211_has_protected(fc)) {
1488 int queue = rx->security_idx;
1489 /* Store CCMP PN so that we can verify that the next
1490 * fragment has a sequential PN value. */
1492 memcpy(entry->last_pn,
1493 rx->key->u.ccmp.rx_pn[queue],
1499 /* This is a fragment for a frame that should already be pending in
1500 * fragment cache. Add this fragment to the end of the pending entry.
1502 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1503 rx->seqno_idx, hdr);
1505 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1506 return RX_DROP_MONITOR;
1509 /* Verify that MPDUs within one MSDU have sequential PN values.
1510 * (IEEE 802.11i, 8.3.3.4.5) */
1513 u8 pn[CCMP_PN_LEN], *rpn;
1515 if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
1516 return RX_DROP_UNUSABLE;
1517 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
1518 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
1523 queue = rx->security_idx;
1524 rpn = rx->key->u.ccmp.rx_pn[queue];
1525 if (memcmp(pn, rpn, CCMP_PN_LEN))
1526 return RX_DROP_UNUSABLE;
1527 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
1530 skb_pull(rx->skb, ieee80211_hdrlen(fc));
1531 __skb_queue_tail(&entry->skb_list, rx->skb);
1532 entry->last_frag = frag;
1533 entry->extra_len += rx->skb->len;
1534 if (ieee80211_has_morefrags(fc)) {
1539 rx->skb = __skb_dequeue(&entry->skb_list);
1540 if (skb_tailroom(rx->skb) < entry->extra_len) {
1541 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
1542 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1544 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1545 __skb_queue_purge(&entry->skb_list);
1546 return RX_DROP_UNUSABLE;
1549 while ((skb = __skb_dequeue(&entry->skb_list))) {
1550 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1554 /* Complete frame has been reassembled - process it now */
1555 status = IEEE80211_SKB_RXCB(rx->skb);
1556 status->rx_flags |= IEEE80211_RX_FRAGMENTED;
1560 rx->sta->rx_packets++;
1561 if (is_multicast_ether_addr(hdr->addr1))
1562 rx->local->dot11MulticastReceivedFrameCount++;
1564 ieee80211_led_rx(rx->local);
1568 static ieee80211_rx_result debug_noinline
1569 ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
1571 u8 *data = rx->skb->data;
1572 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
1574 if (!ieee80211_is_data_qos(hdr->frame_control))
1577 /* remove the qos control field, update frame type and meta-data */
1578 memmove(data + IEEE80211_QOS_CTL_LEN, data,
1579 ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
1580 hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
1581 /* change frame type to non QOS */
1582 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1588 ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1590 if (unlikely(!rx->sta ||
1591 !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
1598 ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1600 struct sk_buff *skb = rx->skb;
1601 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1604 * Pass through unencrypted frames if the hardware has
1605 * decrypted them already.
1607 if (status->flag & RX_FLAG_DECRYPTED)
1610 /* Drop unencrypted frames if key is set. */
1611 if (unlikely(!ieee80211_has_protected(fc) &&
1612 !ieee80211_is_nullfunc(fc) &&
1613 ieee80211_is_data(fc) &&
1614 (rx->key || rx->sdata->drop_unencrypted)))
1621 ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1623 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1624 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1625 __le16 fc = hdr->frame_control;
1628 * Pass through unencrypted frames if the hardware has
1629 * decrypted them already.
1631 if (status->flag & RX_FLAG_DECRYPTED)
1634 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
1635 if (unlikely(!ieee80211_has_protected(fc) &&
1636 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1638 if (ieee80211_is_deauth(fc))
1639 cfg80211_send_unprot_deauth(rx->sdata->dev,
1642 else if (ieee80211_is_disassoc(fc))
1643 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1648 /* BIP does not use Protected field, so need to check MMIE */
1649 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
1650 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
1651 if (ieee80211_is_deauth(fc))
1652 cfg80211_send_unprot_deauth(rx->sdata->dev,
1655 else if (ieee80211_is_disassoc(fc))
1656 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1662 * When using MFP, Action frames are not allowed prior to
1663 * having configured keys.
1665 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1666 ieee80211_is_robust_mgmt_frame(
1667 (struct ieee80211_hdr *) rx->skb->data)))
1675 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
1677 struct ieee80211_sub_if_data *sdata = rx->sdata;
1678 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1679 bool check_port_control = false;
1680 struct ethhdr *ehdr;
1683 *port_control = false;
1684 if (ieee80211_has_a4(hdr->frame_control) &&
1685 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1688 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1689 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
1691 if (!sdata->u.mgd.use_4addr)
1694 check_port_control = true;
1697 if (is_multicast_ether_addr(hdr->addr1) &&
1698 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
1701 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
1705 ehdr = (struct ethhdr *) rx->skb->data;
1706 if (ehdr->h_proto == rx->sdata->control_port_protocol)
1707 *port_control = true;
1708 else if (check_port_control)
1715 * requires that rx->skb is a frame with ethernet header
1717 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
1719 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
1720 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1721 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1724 * Allow EAPOL frames to us/the PAE group address regardless
1725 * of whether the frame was encrypted or not.
1727 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
1728 (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 ||
1729 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1732 if (ieee80211_802_1x_port_control(rx) ||
1733 ieee80211_drop_unencrypted(rx, fc))
1740 * requires that rx->skb is a frame with ethernet header
1743 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1745 struct ieee80211_sub_if_data *sdata = rx->sdata;
1746 struct net_device *dev = sdata->dev;
1747 struct sk_buff *skb, *xmit_skb;
1748 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1749 struct sta_info *dsta;
1750 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1755 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1756 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1757 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
1758 (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
1759 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
1760 if (is_multicast_ether_addr(ehdr->h_dest)) {
1762 * send multicast frames both to higher layers in
1763 * local net stack and back to the wireless medium
1765 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1766 if (!xmit_skb && net_ratelimit())
1767 printk(KERN_DEBUG "%s: failed to clone "
1768 "multicast frame\n", dev->name);
1770 dsta = sta_info_get(sdata, skb->data);
1773 * The destination station is associated to
1774 * this AP (in this VLAN), so send the frame
1775 * directly to it and do not pass it to local
1785 int align __maybe_unused;
1787 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1789 * 'align' will only take the values 0 or 2 here
1790 * since all frames are required to be aligned
1791 * to 2-byte boundaries when being passed to
1792 * mac80211. That also explains the __skb_push()
1795 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
1797 if (WARN_ON(skb_headroom(skb) < 3)) {
1801 u8 *data = skb->data;
1802 size_t len = skb_headlen(skb);
1804 memmove(skb->data, data, len);
1805 skb_set_tail_pointer(skb, len);
1811 /* deliver to local stack */
1812 skb->protocol = eth_type_trans(skb, dev);
1813 memset(skb->cb, 0, sizeof(skb->cb));
1814 netif_receive_skb(skb);
1819 /* send to wireless media */
1820 xmit_skb->protocol = htons(ETH_P_802_3);
1821 skb_reset_network_header(xmit_skb);
1822 skb_reset_mac_header(xmit_skb);
1823 dev_queue_xmit(xmit_skb);
1827 static ieee80211_rx_result debug_noinline
1828 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1830 struct net_device *dev = rx->sdata->dev;
1831 struct sk_buff *skb = rx->skb;
1832 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1833 __le16 fc = hdr->frame_control;
1834 struct sk_buff_head frame_list;
1835 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1837 if (unlikely(!ieee80211_is_data(fc)))
1840 if (unlikely(!ieee80211_is_data_present(fc)))
1841 return RX_DROP_MONITOR;
1843 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
1846 if (ieee80211_has_a4(hdr->frame_control) &&
1847 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1848 !rx->sdata->u.vlan.sta)
1849 return RX_DROP_UNUSABLE;
1851 if (is_multicast_ether_addr(hdr->addr1) &&
1852 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1853 rx->sdata->u.vlan.sta) ||
1854 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1855 rx->sdata->u.mgd.use_4addr)))
1856 return RX_DROP_UNUSABLE;
1859 __skb_queue_head_init(&frame_list);
1861 if (skb_linearize(skb))
1862 return RX_DROP_UNUSABLE;
1864 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
1865 rx->sdata->vif.type,
1866 rx->local->hw.extra_tx_headroom, true);
1868 while (!skb_queue_empty(&frame_list)) {
1869 rx->skb = __skb_dequeue(&frame_list);
1871 if (!ieee80211_frame_allowed(rx, fc)) {
1872 dev_kfree_skb(rx->skb);
1875 dev->stats.rx_packets++;
1876 dev->stats.rx_bytes += rx->skb->len;
1878 ieee80211_deliver_skb(rx);
1884 #ifdef CONFIG_MAC80211_MESH
1885 static ieee80211_rx_result
1886 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1888 struct ieee80211_hdr *hdr;
1889 struct ieee80211s_hdr *mesh_hdr;
1890 unsigned int hdrlen;
1891 struct sk_buff *skb = rx->skb, *fwd_skb;
1892 struct ieee80211_local *local = rx->local;
1893 struct ieee80211_sub_if_data *sdata = rx->sdata;
1894 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1896 hdr = (struct ieee80211_hdr *) skb->data;
1897 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1899 /* make sure fixed part of mesh header is there, also checks skb len */
1900 if (!pskb_may_pull(rx->skb, hdrlen + 6))
1901 return RX_DROP_MONITOR;
1903 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1905 /* make sure full mesh header is there, also checks skb len */
1906 if (!pskb_may_pull(rx->skb,
1907 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
1908 return RX_DROP_MONITOR;
1910 /* reload pointers */
1911 hdr = (struct ieee80211_hdr *) skb->data;
1912 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1914 /* frame is in RMC, don't forward */
1915 if (ieee80211_is_data(hdr->frame_control) &&
1916 is_multicast_ether_addr(hdr->addr1) &&
1917 mesh_rmc_check(hdr->addr3, mesh_hdr, rx->sdata))
1918 return RX_DROP_MONITOR;
1920 if (!ieee80211_is_data(hdr->frame_control) ||
1921 !(status->rx_flags & IEEE80211_RX_RA_MATCH))
1926 return RX_DROP_MONITOR;
1928 if (ieee80211_queue_stopped(&local->hw, skb_get_queue_mapping(skb))) {
1929 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1930 dropped_frames_congestion);
1931 return RX_DROP_MONITOR;
1934 if (mesh_hdr->flags & MESH_FLAGS_AE) {
1935 struct mesh_path *mppath;
1939 if (is_multicast_ether_addr(hdr->addr1)) {
1940 mpp_addr = hdr->addr3;
1941 proxied_addr = mesh_hdr->eaddr1;
1942 } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
1943 /* has_a4 already checked in ieee80211_rx_mesh_check */
1944 mpp_addr = hdr->addr4;
1945 proxied_addr = mesh_hdr->eaddr2;
1947 return RX_DROP_MONITOR;
1951 mppath = mpp_path_lookup(proxied_addr, sdata);
1953 mpp_path_add(proxied_addr, mpp_addr, sdata);
1955 spin_lock_bh(&mppath->state_lock);
1956 if (compare_ether_addr(mppath->mpp, mpp_addr) != 0)
1957 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
1958 spin_unlock_bh(&mppath->state_lock);
1963 /* Frame has reached destination. Don't forward */
1964 if (!is_multicast_ether_addr(hdr->addr1) &&
1965 compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0)
1972 IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
1973 dropped_frames_ttl);
1975 struct ieee80211_hdr *fwd_hdr;
1976 struct ieee80211_tx_info *info;
1978 fwd_skb = skb_copy(skb, GFP_ATOMIC);
1980 if (!fwd_skb && net_ratelimit())
1981 printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
1986 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
1987 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
1988 info = IEEE80211_SKB_CB(fwd_skb);
1989 memset(info, 0, sizeof(*info));
1990 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1991 info->control.vif = &rx->sdata->vif;
1992 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
1993 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1995 skb_set_queue_mapping(fwd_skb,
1996 ieee80211_select_queue(sdata, fwd_skb));
1997 ieee80211_set_qos_hdr(sdata, fwd_skb);
2001 * Save TA to addr1 to send TA a path error if a
2002 * suitable next hop is not found
2004 memcpy(fwd_hdr->addr1, fwd_hdr->addr2,
2006 err = mesh_nexthop_lookup(fwd_skb, sdata);
2007 /* Failed to immediately resolve next hop:
2008 * fwded frame was dropped or will be added
2009 * later to the pending skb queue. */
2011 return RX_DROP_MONITOR;
2013 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
2016 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
2018 ieee80211_add_pending_skb(local, fwd_skb);
2023 if (is_multicast_ether_addr(hdr->addr1) ||
2024 sdata->dev->flags & IFF_PROMISC)
2027 return RX_DROP_MONITOR;
2031 static ieee80211_rx_result debug_noinline
2032 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2034 struct ieee80211_sub_if_data *sdata = rx->sdata;
2035 struct ieee80211_local *local = rx->local;
2036 struct net_device *dev = sdata->dev;
2037 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2038 __le16 fc = hdr->frame_control;
2042 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2045 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2046 return RX_DROP_MONITOR;
2049 * Allow the cooked monitor interface of an AP to see 4-addr frames so
2050 * that a 4-addr station can be detected and moved into a separate VLAN
2052 if (ieee80211_has_a4(hdr->frame_control) &&
2053 sdata->vif.type == NL80211_IFTYPE_AP)
2054 return RX_DROP_MONITOR;
2056 err = __ieee80211_data_to_8023(rx, &port_control);
2058 return RX_DROP_UNUSABLE;
2060 if (!ieee80211_frame_allowed(rx, fc))
2061 return RX_DROP_MONITOR;
2063 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2064 unlikely(port_control) && sdata->bss) {
2065 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2073 dev->stats.rx_packets++;
2074 dev->stats.rx_bytes += rx->skb->len;
2076 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
2077 !is_multicast_ether_addr(
2078 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2079 (!local->scanning &&
2080 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
2081 mod_timer(&local->dynamic_ps_timer, jiffies +
2082 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2085 ieee80211_deliver_skb(rx);
2090 static ieee80211_rx_result debug_noinline
2091 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
2093 struct ieee80211_local *local = rx->local;
2094 struct ieee80211_hw *hw = &local->hw;
2095 struct sk_buff *skb = rx->skb;
2096 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
2097 struct tid_ampdu_rx *tid_agg_rx;
2101 if (likely(!ieee80211_is_ctl(bar->frame_control)))
2104 if (ieee80211_is_back_req(bar->frame_control)) {
2106 __le16 control, start_seq_num;
2107 } __packed bar_data;
2110 return RX_DROP_MONITOR;
2112 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2113 &bar_data, sizeof(bar_data)))
2114 return RX_DROP_MONITOR;
2116 tid = le16_to_cpu(bar_data.control) >> 12;
2118 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2120 return RX_DROP_MONITOR;
2122 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
2124 /* reset session timer */
2125 if (tid_agg_rx->timeout)
2126 mod_timer(&tid_agg_rx->session_timer,
2127 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2129 spin_lock(&tid_agg_rx->reorder_lock);
2130 /* release stored frames up to start of BAR */
2131 ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num);
2132 spin_unlock(&tid_agg_rx->reorder_lock);
2139 * After this point, we only want management frames,
2140 * so we can drop all remaining control frames to
2141 * cooked monitor interfaces.
2143 return RX_DROP_MONITOR;
2146 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2147 struct ieee80211_mgmt *mgmt,
2150 struct ieee80211_local *local = sdata->local;
2151 struct sk_buff *skb;
2152 struct ieee80211_mgmt *resp;
2154 if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) {
2155 /* Not to own unicast address */
2159 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
2160 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
2161 /* Not from the current AP or not associated yet. */
2165 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2166 /* Too short SA Query request frame */
2170 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2174 skb_reserve(skb, local->hw.extra_tx_headroom);
2175 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2176 memset(resp, 0, 24);
2177 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2178 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2179 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2180 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2181 IEEE80211_STYPE_ACTION);
2182 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2183 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2184 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2185 memcpy(resp->u.action.u.sa_query.trans_id,
2186 mgmt->u.action.u.sa_query.trans_id,
2187 WLAN_SA_QUERY_TR_ID_LEN);
2189 ieee80211_tx_skb(sdata, skb);
2192 static ieee80211_rx_result debug_noinline
2193 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2195 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2196 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2199 * From here on, look only at management frames.
2200 * Data and control frames are already handled,
2201 * and unknown (reserved) frames are useless.
2203 if (rx->skb->len < 24)
2204 return RX_DROP_MONITOR;
2206 if (!ieee80211_is_mgmt(mgmt->frame_control))
2207 return RX_DROP_MONITOR;
2209 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
2210 return RX_DROP_MONITOR;
2212 if (ieee80211_drop_unencrypted_mgmt(rx))
2213 return RX_DROP_UNUSABLE;
2218 static ieee80211_rx_result debug_noinline
2219 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2221 struct ieee80211_local *local = rx->local;
2222 struct ieee80211_sub_if_data *sdata = rx->sdata;
2223 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2224 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2225 int len = rx->skb->len;
2227 if (!ieee80211_is_action(mgmt->frame_control))
2230 /* drop too small frames */
2231 if (len < IEEE80211_MIN_ACTION_SIZE)
2232 return RX_DROP_UNUSABLE;
2234 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
2235 return RX_DROP_UNUSABLE;
2237 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
2238 return RX_DROP_UNUSABLE;
2240 switch (mgmt->u.action.category) {
2241 case WLAN_CATEGORY_BACK:
2243 * The aggregation code is not prepared to handle
2244 * anything but STA/AP due to the BSSID handling;
2245 * IBSS could work in the code but isn't supported
2246 * by drivers or the standard.
2248 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2249 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2250 sdata->vif.type != NL80211_IFTYPE_AP)
2253 /* verify action_code is present */
2254 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2257 switch (mgmt->u.action.u.addba_req.action_code) {
2258 case WLAN_ACTION_ADDBA_REQ:
2259 if (len < (IEEE80211_MIN_ACTION_SIZE +
2260 sizeof(mgmt->u.action.u.addba_req)))
2263 case WLAN_ACTION_ADDBA_RESP:
2264 if (len < (IEEE80211_MIN_ACTION_SIZE +
2265 sizeof(mgmt->u.action.u.addba_resp)))
2268 case WLAN_ACTION_DELBA:
2269 if (len < (IEEE80211_MIN_ACTION_SIZE +
2270 sizeof(mgmt->u.action.u.delba)))
2278 case WLAN_CATEGORY_SPECTRUM_MGMT:
2279 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
2282 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2285 /* verify action_code is present */
2286 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2289 switch (mgmt->u.action.u.measurement.action_code) {
2290 case WLAN_ACTION_SPCT_MSR_REQ:
2291 if (len < (IEEE80211_MIN_ACTION_SIZE +
2292 sizeof(mgmt->u.action.u.measurement)))
2294 ieee80211_process_measurement_req(sdata, mgmt, len);
2296 case WLAN_ACTION_SPCT_CHL_SWITCH:
2297 if (len < (IEEE80211_MIN_ACTION_SIZE +
2298 sizeof(mgmt->u.action.u.chan_switch)))
2301 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2304 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
2310 case WLAN_CATEGORY_SA_QUERY:
2311 if (len < (IEEE80211_MIN_ACTION_SIZE +
2312 sizeof(mgmt->u.action.u.sa_query)))
2315 switch (mgmt->u.action.u.sa_query.action) {
2316 case WLAN_ACTION_SA_QUERY_REQUEST:
2317 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2319 ieee80211_process_sa_query_req(sdata, mgmt, len);
2323 case WLAN_CATEGORY_SELF_PROTECTED:
2324 if (len < (IEEE80211_MIN_ACTION_SIZE +
2325 sizeof(mgmt->u.action.u.self_prot.action_code)))
2328 switch (mgmt->u.action.u.self_prot.action_code) {
2329 case WLAN_SP_MESH_PEERING_OPEN:
2330 case WLAN_SP_MESH_PEERING_CLOSE:
2331 case WLAN_SP_MESH_PEERING_CONFIRM:
2332 if (!ieee80211_vif_is_mesh(&sdata->vif))
2334 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
2335 /* userspace handles this frame */
2338 case WLAN_SP_MGK_INFORM:
2339 case WLAN_SP_MGK_ACK:
2340 if (!ieee80211_vif_is_mesh(&sdata->vif))
2345 case WLAN_CATEGORY_MESH_ACTION:
2346 if (len < (IEEE80211_MIN_ACTION_SIZE +
2347 sizeof(mgmt->u.action.u.mesh_action.action_code)))
2350 if (!ieee80211_vif_is_mesh(&sdata->vif))
2352 if (mesh_action_is_path_sel(mgmt) &&
2353 (!mesh_path_sel_is_hwmp(sdata)))
2361 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
2362 /* will return in the next handlers */
2367 rx->sta->rx_packets++;
2368 dev_kfree_skb(rx->skb);
2372 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2373 skb_queue_tail(&sdata->skb_queue, rx->skb);
2374 ieee80211_queue_work(&local->hw, &sdata->work);
2376 rx->sta->rx_packets++;
2380 static ieee80211_rx_result debug_noinline
2381 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2383 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2385 /* skip known-bad action frames and return them in the next handler */
2386 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
2390 * Getting here means the kernel doesn't know how to handle
2391 * it, but maybe userspace does ... include returned frames
2392 * so userspace can register for those to know whether ones
2393 * it transmitted were processed or returned.
2396 if (cfg80211_rx_mgmt(rx->sdata->dev, status->freq,
2397 rx->skb->data, rx->skb->len,
2400 rx->sta->rx_packets++;
2401 dev_kfree_skb(rx->skb);
2409 static ieee80211_rx_result debug_noinline
2410 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2412 struct ieee80211_local *local = rx->local;
2413 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2414 struct sk_buff *nskb;
2415 struct ieee80211_sub_if_data *sdata = rx->sdata;
2416 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2418 if (!ieee80211_is_action(mgmt->frame_control))
2422 * For AP mode, hostapd is responsible for handling any action
2423 * frames that we didn't handle, including returning unknown
2424 * ones. For all other modes we will return them to the sender,
2425 * setting the 0x80 bit in the action category, as required by
2426 * 802.11-2012 9.24.4.
2427 * Newer versions of hostapd shall also use the management frame
2428 * registration mechanisms, but older ones still use cooked
2429 * monitor interfaces so push all frames there.
2431 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
2432 (sdata->vif.type == NL80211_IFTYPE_AP ||
2433 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2434 return RX_DROP_MONITOR;
2436 if (is_multicast_ether_addr(mgmt->da))
2437 return RX_DROP_MONITOR;
2439 /* do not return rejected action frames */
2440 if (mgmt->u.action.category & 0x80)
2441 return RX_DROP_UNUSABLE;
2443 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2446 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
2448 nmgmt->u.action.category |= 0x80;
2449 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2450 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
2452 memset(nskb->cb, 0, sizeof(nskb->cb));
2454 ieee80211_tx_skb(rx->sdata, nskb);
2456 dev_kfree_skb(rx->skb);
2460 static ieee80211_rx_result debug_noinline
2461 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
2463 struct ieee80211_sub_if_data *sdata = rx->sdata;
2464 ieee80211_rx_result rxs;
2465 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2468 rxs = ieee80211_work_rx_mgmt(rx->sdata, rx->skb);
2469 if (rxs != RX_CONTINUE)
2472 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
2474 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2475 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2476 sdata->vif.type != NL80211_IFTYPE_STATION)
2477 return RX_DROP_MONITOR;
2480 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2481 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2482 /* process for all: mesh, mlme, ibss */
2484 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2485 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
2486 if (is_multicast_ether_addr(mgmt->da) &&
2487 !is_broadcast_ether_addr(mgmt->da))
2488 return RX_DROP_MONITOR;
2490 /* process only for station */
2491 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2492 return RX_DROP_MONITOR;
2494 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2495 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2496 /* process only for ibss */
2497 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
2498 return RX_DROP_MONITOR;
2501 return RX_DROP_MONITOR;
2504 /* queue up frame and kick off work to process it */
2505 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2506 skb_queue_tail(&sdata->skb_queue, rx->skb);
2507 ieee80211_queue_work(&rx->local->hw, &sdata->work);
2509 rx->sta->rx_packets++;
2514 /* TODO: use IEEE80211_RX_FRAGMENTED */
2515 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2516 struct ieee80211_rate *rate)
2518 struct ieee80211_sub_if_data *sdata;
2519 struct ieee80211_local *local = rx->local;
2520 struct ieee80211_rtap_hdr {
2521 struct ieee80211_radiotap_header hdr;
2527 struct sk_buff *skb = rx->skb, *skb2;
2528 struct net_device *prev_dev = NULL;
2529 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2532 * If cooked monitor has been processed already, then
2533 * don't do it again. If not, set the flag.
2535 if (rx->flags & IEEE80211_RX_CMNTR)
2537 rx->flags |= IEEE80211_RX_CMNTR;
2539 if (skb_headroom(skb) < sizeof(*rthdr) &&
2540 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
2543 rthdr = (void *)skb_push(skb, sizeof(*rthdr));
2544 memset(rthdr, 0, sizeof(*rthdr));
2545 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
2546 rthdr->hdr.it_present =
2547 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
2548 (1 << IEEE80211_RADIOTAP_CHANNEL));
2551 rthdr->rate_or_pad = rate->bitrate / 5;
2552 rthdr->hdr.it_present |=
2553 cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
2555 rthdr->chan_freq = cpu_to_le16(status->freq);
2557 if (status->band == IEEE80211_BAND_5GHZ)
2558 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
2559 IEEE80211_CHAN_5GHZ);
2561 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
2562 IEEE80211_CHAN_2GHZ);
2564 skb_set_mac_header(skb, 0);
2565 skb->ip_summed = CHECKSUM_UNNECESSARY;
2566 skb->pkt_type = PACKET_OTHERHOST;
2567 skb->protocol = htons(ETH_P_802_2);
2569 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2570 if (!ieee80211_sdata_running(sdata))
2573 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
2574 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
2578 skb2 = skb_clone(skb, GFP_ATOMIC);
2580 skb2->dev = prev_dev;
2581 netif_receive_skb(skb2);
2585 prev_dev = sdata->dev;
2586 sdata->dev->stats.rx_packets++;
2587 sdata->dev->stats.rx_bytes += skb->len;
2591 skb->dev = prev_dev;
2592 netif_receive_skb(skb);
2600 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
2601 ieee80211_rx_result res)
2604 case RX_DROP_MONITOR:
2605 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2607 rx->sta->rx_dropped++;
2610 struct ieee80211_rate *rate = NULL;
2611 struct ieee80211_supported_band *sband;
2612 struct ieee80211_rx_status *status;
2614 status = IEEE80211_SKB_RXCB((rx->skb));
2616 sband = rx->local->hw.wiphy->bands[status->band];
2617 if (!(status->flag & RX_FLAG_HT))
2618 rate = &sband->bitrates[status->rate_idx];
2620 ieee80211_rx_cooked_monitor(rx, rate);
2623 case RX_DROP_UNUSABLE:
2624 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2626 rx->sta->rx_dropped++;
2627 dev_kfree_skb(rx->skb);
2630 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
2635 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx)
2637 ieee80211_rx_result res = RX_DROP_MONITOR;
2638 struct sk_buff *skb;
2640 #define CALL_RXH(rxh) \
2643 if (res != RX_CONTINUE) \
2647 spin_lock(&rx->local->rx_skb_queue.lock);
2648 if (rx->local->running_rx_handler)
2651 rx->local->running_rx_handler = true;
2653 while ((skb = __skb_dequeue(&rx->local->rx_skb_queue))) {
2654 spin_unlock(&rx->local->rx_skb_queue.lock);
2657 * all the other fields are valid across frames
2658 * that belong to an aMPDU since they are on the
2659 * same TID from the same station
2663 CALL_RXH(ieee80211_rx_h_decrypt)
2664 CALL_RXH(ieee80211_rx_h_check_more_data)
2665 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
2666 CALL_RXH(ieee80211_rx_h_sta_process)
2667 CALL_RXH(ieee80211_rx_h_defragment)
2668 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2669 /* must be after MMIC verify so header is counted in MPDU mic */
2670 #ifdef CONFIG_MAC80211_MESH
2671 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
2672 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2674 CALL_RXH(ieee80211_rx_h_remove_qos_control)
2675 CALL_RXH(ieee80211_rx_h_amsdu)
2676 CALL_RXH(ieee80211_rx_h_data)
2677 CALL_RXH(ieee80211_rx_h_ctrl);
2678 CALL_RXH(ieee80211_rx_h_mgmt_check)
2679 CALL_RXH(ieee80211_rx_h_action)
2680 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
2681 CALL_RXH(ieee80211_rx_h_action_return)
2682 CALL_RXH(ieee80211_rx_h_mgmt)
2685 ieee80211_rx_handlers_result(rx, res);
2686 spin_lock(&rx->local->rx_skb_queue.lock);
2690 rx->local->running_rx_handler = false;
2693 spin_unlock(&rx->local->rx_skb_queue.lock);
2696 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
2698 ieee80211_rx_result res = RX_DROP_MONITOR;
2700 #define CALL_RXH(rxh) \
2703 if (res != RX_CONTINUE) \
2707 CALL_RXH(ieee80211_rx_h_passive_scan)
2708 CALL_RXH(ieee80211_rx_h_check)
2710 ieee80211_rx_reorder_ampdu(rx);
2712 ieee80211_rx_handlers(rx);
2716 ieee80211_rx_handlers_result(rx, res);
2722 * This function makes calls into the RX path, therefore
2723 * it has to be invoked under RCU read lock.
2725 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
2727 struct ieee80211_rx_data rx = {
2729 .sdata = sta->sdata,
2730 .local = sta->local,
2731 /* This is OK -- must be QoS data frame */
2732 .security_idx = tid,
2736 struct tid_ampdu_rx *tid_agg_rx;
2738 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
2742 spin_lock(&tid_agg_rx->reorder_lock);
2743 ieee80211_sta_reorder_release(&sta->local->hw, tid_agg_rx);
2744 spin_unlock(&tid_agg_rx->reorder_lock);
2746 ieee80211_rx_handlers(&rx);
2749 /* main receive path */
2751 static int prepare_for_handlers(struct ieee80211_rx_data *rx,
2752 struct ieee80211_hdr *hdr)
2754 struct ieee80211_sub_if_data *sdata = rx->sdata;
2755 struct sk_buff *skb = rx->skb;
2756 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2757 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
2758 int multicast = is_multicast_ether_addr(hdr->addr1);
2760 switch (sdata->vif.type) {
2761 case NL80211_IFTYPE_STATION:
2762 if (!bssid && !sdata->u.mgd.use_4addr)
2765 compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) {
2766 if (!(sdata->dev->flags & IFF_PROMISC) ||
2767 sdata->u.mgd.use_4addr)
2769 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2772 case NL80211_IFTYPE_ADHOC:
2775 if (ieee80211_is_beacon(hdr->frame_control)) {
2778 else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
2779 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN))
2781 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2782 } else if (!multicast &&
2783 compare_ether_addr(sdata->vif.addr,
2785 if (!(sdata->dev->flags & IFF_PROMISC))
2787 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2788 } else if (!rx->sta) {
2790 if (status->flag & RX_FLAG_HT)
2791 rate_idx = 0; /* TODO: HT rates */
2793 rate_idx = status->rate_idx;
2794 rx->sta = ieee80211_ibss_add_sta(sdata, bssid,
2795 hdr->addr2, BIT(rate_idx), GFP_ATOMIC);
2798 case NL80211_IFTYPE_MESH_POINT:
2800 compare_ether_addr(sdata->vif.addr,
2802 if (!(sdata->dev->flags & IFF_PROMISC))
2805 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2808 case NL80211_IFTYPE_AP_VLAN:
2809 case NL80211_IFTYPE_AP:
2811 if (compare_ether_addr(sdata->vif.addr,
2814 } else if (!ieee80211_bssid_match(bssid,
2816 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
2817 !ieee80211_is_beacon(hdr->frame_control) &&
2818 !(ieee80211_is_action(hdr->frame_control) &&
2821 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2824 case NL80211_IFTYPE_WDS:
2825 if (bssid || !ieee80211_is_data(hdr->frame_control))
2827 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
2831 /* should never get here */
2840 * This function returns whether or not the SKB
2841 * was destined for RX processing or not, which,
2842 * if consume is true, is equivalent to whether
2843 * or not the skb was consumed.
2845 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
2846 struct sk_buff *skb, bool consume)
2848 struct ieee80211_local *local = rx->local;
2849 struct ieee80211_sub_if_data *sdata = rx->sdata;
2850 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2851 struct ieee80211_hdr *hdr = (void *)skb->data;
2855 status->rx_flags |= IEEE80211_RX_RA_MATCH;
2856 prepares = prepare_for_handlers(rx, hdr);
2862 skb = skb_copy(skb, GFP_ATOMIC);
2864 if (net_ratelimit())
2865 wiphy_debug(local->hw.wiphy,
2866 "failed to copy skb for %s\n",
2874 ieee80211_invoke_rx_handlers(rx);
2879 * This is the actual Rx frames handler. as it blongs to Rx path it must
2880 * be called with rcu_read_lock protection.
2882 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2883 struct sk_buff *skb)
2885 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2886 struct ieee80211_local *local = hw_to_local(hw);
2887 struct ieee80211_sub_if_data *sdata;
2888 struct ieee80211_hdr *hdr;
2890 struct ieee80211_rx_data rx;
2891 struct ieee80211_sub_if_data *prev;
2892 struct sta_info *sta, *tmp, *prev_sta;
2895 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
2896 memset(&rx, 0, sizeof(rx));
2900 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
2901 local->dot11ReceivedFragmentCount++;
2903 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
2904 test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
2905 status->rx_flags |= IEEE80211_RX_IN_SCAN;
2907 if (ieee80211_is_mgmt(fc)) {
2908 /* drop frame if too short for header */
2909 if (skb->len < ieee80211_hdrlen(fc))
2912 err = skb_linearize(skb);
2914 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
2922 hdr = (struct ieee80211_hdr *)skb->data;
2923 ieee80211_parse_qos(&rx);
2924 ieee80211_verify_alignment(&rx);
2926 if (ieee80211_is_data(fc)) {
2929 for_each_sta_info_rx(local, hdr->addr2, sta, tmp) {
2936 rx.sdata = prev_sta->sdata;
2937 ieee80211_prepare_and_rx_handle(&rx, skb, false);
2944 rx.sdata = prev_sta->sdata;
2946 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2954 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2955 if (!ieee80211_sdata_running(sdata))
2958 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2959 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2963 * frame is destined for this interface, but if it's
2964 * not also for the previous one we handle that after
2965 * the loop to avoid copying the SKB once too much
2973 rx.sta = sta_info_get_bss_rx(prev, hdr->addr2);
2975 ieee80211_prepare_and_rx_handle(&rx, skb, false);
2981 rx.sta = sta_info_get_bss_rx(prev, hdr->addr2);
2984 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2993 * This is the receive path handler. It is called by a low level driver when an
2994 * 802.11 MPDU is received from the hardware.
2996 void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2998 struct ieee80211_local *local = hw_to_local(hw);
2999 struct ieee80211_rate *rate = NULL;
3000 struct ieee80211_supported_band *sband;
3001 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3003 WARN_ON_ONCE(softirq_count() == 0);
3005 if (WARN_ON(status->band < 0 ||
3006 status->band >= IEEE80211_NUM_BANDS))
3009 sband = local->hw.wiphy->bands[status->band];
3010 if (WARN_ON(!sband))
3014 * If we're suspending, it is possible although not too likely
3015 * that we'd be receiving frames after having already partially
3016 * quiesced the stack. We can't process such frames then since
3017 * that might, for example, cause stations to be added or other
3018 * driver callbacks be invoked.
3020 if (unlikely(local->quiescing || local->suspended))
3024 * The same happens when we're not even started,
3025 * but that's worth a warning.
3027 if (WARN_ON(!local->started))
3030 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
3032 * Validate the rate, unless a PLCP error means that
3033 * we probably can't have a valid rate here anyway.
3036 if (status->flag & RX_FLAG_HT) {
3038 * rate_idx is MCS index, which can be [0-76]
3041 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
3043 * Anything else would be some sort of driver or
3044 * hardware error. The driver should catch hardware
3047 if (WARN((status->rate_idx < 0 ||
3048 status->rate_idx > 76),
3049 "Rate marked as an HT rate but passed "
3050 "status->rate_idx is not "
3051 "an MCS index [0-76]: %d (0x%02x)\n",
3056 if (WARN_ON(status->rate_idx < 0 ||
3057 status->rate_idx >= sband->n_bitrates))
3059 rate = &sband->bitrates[status->rate_idx];
3063 status->rx_flags = 0;
3066 * key references and virtual interfaces are protected using RCU
3067 * and this requires that we are in a read-side RCU section during
3068 * receive processing
3073 * Frames with failed FCS/PLCP checksum are not returned,
3074 * all other frames are returned without radiotap header
3075 * if it was previously present.
3076 * Also, frames with less than 16 bytes are dropped.
3078 skb = ieee80211_rx_monitor(local, skb, rate);
3084 ieee80211_tpt_led_trig_rx(local,
3085 ((struct ieee80211_hdr *)skb->data)->frame_control,
3087 __ieee80211_rx_handle_packet(hw, skb);
3095 EXPORT_SYMBOL(ieee80211_rx);
3097 /* This is a version of the rx handler that can be called from hard irq
3098 * context. Post the skb on the queue and schedule the tasklet */
3099 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
3101 struct ieee80211_local *local = hw_to_local(hw);
3103 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3105 skb->pkt_type = IEEE80211_RX_MSG;
3106 skb_queue_tail(&local->skb_queue, skb);
3107 tasklet_schedule(&local->tasklet);
3109 EXPORT_SYMBOL(ieee80211_rx_irqsafe);