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 <net/mac80211.h>
20 #include <net/ieee80211_radiotap.h>
22 #include "ieee80211_i.h"
23 #include "driver-ops.h"
32 * monitor mode reception
34 * This function cleans up the SKB, i.e. it removes all the stuff
35 * only useful for monitoring.
37 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
40 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
41 if (likely(skb->len > FCS_LEN))
42 __pskb_trim(skb, skb->len - FCS_LEN);
54 static inline int should_drop_frame(struct sk_buff *skb,
57 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
58 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
60 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
62 if (unlikely(skb->len < 16 + present_fcs_len))
64 if (ieee80211_is_ctl(hdr->frame_control) &&
65 !ieee80211_is_pspoll(hdr->frame_control) &&
66 !ieee80211_is_back_req(hdr->frame_control))
72 ieee80211_rx_radiotap_len(struct ieee80211_local *local,
73 struct ieee80211_rx_status *status)
77 /* always present fields */
78 len = sizeof(struct ieee80211_radiotap_header) + 9;
80 if (status->flag & RX_FLAG_TSFT)
82 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
85 if (len & 1) /* padding for RX_FLAGS if necessary */
88 if (status->flag & RX_FLAG_HT) /* HT info */
95 * ieee80211_add_rx_radiotap_header - add radiotap header
97 * add a radiotap header containing all the fields which the hardware provided.
100 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
102 struct ieee80211_rate *rate,
105 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
106 struct ieee80211_radiotap_header *rthdr;
110 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
111 memset(rthdr, 0, rtap_len);
113 /* radiotap header, set always present flags */
115 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
116 (1 << IEEE80211_RADIOTAP_CHANNEL) |
117 (1 << IEEE80211_RADIOTAP_ANTENNA) |
118 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
119 rthdr->it_len = cpu_to_le16(rtap_len);
121 pos = (unsigned char *)(rthdr+1);
123 /* the order of the following fields is important */
125 /* IEEE80211_RADIOTAP_TSFT */
126 if (status->flag & RX_FLAG_TSFT) {
127 put_unaligned_le64(status->mactime, pos);
129 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
133 /* IEEE80211_RADIOTAP_FLAGS */
134 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
135 *pos |= IEEE80211_RADIOTAP_F_FCS;
136 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
137 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
138 if (status->flag & RX_FLAG_SHORTPRE)
139 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
142 /* IEEE80211_RADIOTAP_RATE */
143 if (status->flag & RX_FLAG_HT) {
145 * TODO: add following information into radiotap header once
146 * suitable fields are defined for it:
147 * - MCS index (status->rate_idx)
148 * - HT40 (status->flag & RX_FLAG_40MHZ)
149 * - short-GI (status->flag & RX_FLAG_SHORT_GI)
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->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,
175 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
176 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
177 *pos = status->signal;
179 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
183 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
185 /* IEEE80211_RADIOTAP_ANTENNA */
186 *pos = status->antenna;
189 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
191 /* IEEE80211_RADIOTAP_RX_FLAGS */
192 /* ensure 2 byte alignment for the 2 byte field as required */
193 if ((pos - (u8 *)rthdr) & 1)
195 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
196 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
197 put_unaligned_le16(rx_flags, pos);
200 if (status->flag & RX_FLAG_HT) {
201 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
202 *pos++ = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
203 IEEE80211_RADIOTAP_MCS_HAVE_GI |
204 IEEE80211_RADIOTAP_MCS_HAVE_BW;
206 if (status->flag & RX_FLAG_SHORT_GI)
207 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
208 if (status->flag & RX_FLAG_40MHZ)
209 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
211 *pos++ = status->rate_idx;
216 * This function copies a received frame to all monitor interfaces and
217 * returns a cleaned-up SKB that no longer includes the FCS nor the
218 * radiotap header the driver might have added.
220 static struct sk_buff *
221 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
222 struct ieee80211_rate *rate)
224 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
225 struct ieee80211_sub_if_data *sdata;
226 int needed_headroom = 0;
227 struct sk_buff *skb, *skb2;
228 struct net_device *prev_dev = NULL;
229 int present_fcs_len = 0;
232 * First, we may need to make a copy of the skb because
233 * (1) we need to modify it for radiotap (if not present), and
234 * (2) the other RX handlers will modify the skb we got.
236 * We don't need to, of course, if we aren't going to return
237 * the SKB because it has a bad FCS/PLCP checksum.
240 /* room for the radiotap header based on driver features */
241 needed_headroom = ieee80211_rx_radiotap_len(local, status);
243 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
244 present_fcs_len = FCS_LEN;
246 /* make sure hdr->frame_control is on the linear part */
247 if (!pskb_may_pull(origskb, 2)) {
248 dev_kfree_skb(origskb);
252 if (!local->monitors) {
253 if (should_drop_frame(origskb, present_fcs_len)) {
254 dev_kfree_skb(origskb);
258 return remove_monitor_info(local, origskb);
261 if (should_drop_frame(origskb, present_fcs_len)) {
262 /* only need to expand headroom if necessary */
267 * This shouldn't trigger often because most devices have an
268 * RX header they pull before we get here, and that should
269 * be big enough for our radiotap information. We should
270 * probably export the length to drivers so that we can have
271 * them allocate enough headroom to start with.
273 if (skb_headroom(skb) < needed_headroom &&
274 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
280 * Need to make a copy and possibly remove radiotap header
281 * and FCS from the original.
283 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
285 origskb = remove_monitor_info(local, origskb);
291 /* prepend radiotap information */
292 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
294 skb_reset_mac_header(skb);
295 skb->ip_summed = CHECKSUM_UNNECESSARY;
296 skb->pkt_type = PACKET_OTHERHOST;
297 skb->protocol = htons(ETH_P_802_2);
299 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
300 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
303 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
306 if (!ieee80211_sdata_running(sdata))
310 skb2 = skb_clone(skb, GFP_ATOMIC);
312 skb2->dev = prev_dev;
313 netif_receive_skb(skb2);
317 prev_dev = sdata->dev;
318 sdata->dev->stats.rx_packets++;
319 sdata->dev->stats.rx_bytes += skb->len;
324 netif_receive_skb(skb);
332 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
334 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
335 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
338 /* does the frame have a qos control field? */
339 if (ieee80211_is_data_qos(hdr->frame_control)) {
340 u8 *qc = ieee80211_get_qos_ctl(hdr);
341 /* frame has qos control */
342 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
343 if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
344 status->rx_flags |= IEEE80211_RX_AMSDU;
347 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
349 * Sequence numbers for management frames, QoS data
350 * frames with a broadcast/multicast address in the
351 * Address 1 field, and all non-QoS data frames sent
352 * by QoS STAs are assigned using an additional single
353 * modulo-4096 counter, [...]
355 * We also use that counter for non-QoS STAs.
357 tid = NUM_RX_DATA_QUEUES - 1;
361 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
362 * For now, set skb->priority to 0 for other cases. */
363 rx->skb->priority = (tid > 7) ? 0 : tid;
367 * DOC: Packet alignment
369 * Drivers always need to pass packets that are aligned to two-byte boundaries
372 * Additionally, should, if possible, align the payload data in a way that
373 * guarantees that the contained IP header is aligned to a four-byte
374 * boundary. In the case of regular frames, this simply means aligning the
375 * payload to a four-byte boundary (because either the IP header is directly
376 * contained, or IV/RFC1042 headers that have a length divisible by four are
377 * in front of it). If the payload data is not properly aligned and the
378 * architecture doesn't support efficient unaligned operations, mac80211
379 * will align the data.
381 * With A-MSDU frames, however, the payload data address must yield two modulo
382 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
383 * push the IP header further back to a multiple of four again. Thankfully, the
384 * specs were sane enough this time around to require padding each A-MSDU
385 * subframe to a length that is a multiple of four.
387 * Padding like Atheros hardware adds which is inbetween the 802.11 header and
388 * the payload is not supported, the driver is required to move the 802.11
389 * header to be directly in front of the payload in that case.
391 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
393 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
394 WARN_ONCE((unsigned long)rx->skb->data & 1,
395 "unaligned packet at 0x%p\n", rx->skb->data);
402 static ieee80211_rx_result debug_noinline
403 ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
405 struct ieee80211_local *local = rx->local;
406 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
407 struct sk_buff *skb = rx->skb;
409 if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN)))
412 if (test_bit(SCAN_HW_SCANNING, &local->scanning) ||
413 test_bit(SCAN_SW_SCANNING, &local->scanning))
414 return ieee80211_scan_rx(rx->sdata, skb);
416 /* scanning finished during invoking of handlers */
417 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
418 return RX_DROP_UNUSABLE;
422 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
424 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
426 if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
429 return ieee80211_is_robust_mgmt_frame(hdr);
433 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
435 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
437 if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
440 return ieee80211_is_robust_mgmt_frame(hdr);
444 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
445 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
447 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
448 struct ieee80211_mmie *mmie;
450 if (skb->len < 24 + sizeof(*mmie) ||
451 !is_multicast_ether_addr(hdr->da))
454 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
455 return -1; /* not a robust management frame */
457 mmie = (struct ieee80211_mmie *)
458 (skb->data + skb->len - sizeof(*mmie));
459 if (mmie->element_id != WLAN_EID_MMIE ||
460 mmie->length != sizeof(*mmie) - 2)
463 return le16_to_cpu(mmie->key_id);
467 static ieee80211_rx_result
468 ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
470 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
471 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
472 char *dev_addr = rx->sdata->vif.addr;
474 if (ieee80211_is_data(hdr->frame_control)) {
475 if (is_multicast_ether_addr(hdr->addr1)) {
476 if (ieee80211_has_tods(hdr->frame_control) ||
477 !ieee80211_has_fromds(hdr->frame_control))
478 return RX_DROP_MONITOR;
479 if (memcmp(hdr->addr3, dev_addr, ETH_ALEN) == 0)
480 return RX_DROP_MONITOR;
482 if (!ieee80211_has_a4(hdr->frame_control))
483 return RX_DROP_MONITOR;
484 if (memcmp(hdr->addr4, dev_addr, ETH_ALEN) == 0)
485 return RX_DROP_MONITOR;
489 /* If there is not an established peer link and this is not a peer link
490 * establisment frame, beacon or probe, drop the frame.
493 if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) {
494 struct ieee80211_mgmt *mgmt;
496 if (!ieee80211_is_mgmt(hdr->frame_control))
497 return RX_DROP_MONITOR;
499 if (ieee80211_is_action(hdr->frame_control)) {
500 mgmt = (struct ieee80211_mgmt *)hdr;
501 if (mgmt->u.action.category != WLAN_CATEGORY_MESH_PLINK)
502 return RX_DROP_MONITOR;
506 if (ieee80211_is_probe_req(hdr->frame_control) ||
507 ieee80211_is_probe_resp(hdr->frame_control) ||
508 ieee80211_is_beacon(hdr->frame_control))
511 return RX_DROP_MONITOR;
515 #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
517 if (ieee80211_is_data(hdr->frame_control) &&
518 is_multicast_ether_addr(hdr->addr1) &&
519 mesh_rmc_check(hdr->addr3, msh_h_get(hdr, hdrlen), rx->sdata))
520 return RX_DROP_MONITOR;
526 #define SEQ_MODULO 0x1000
527 #define SEQ_MASK 0xfff
529 static inline int seq_less(u16 sq1, u16 sq2)
531 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
534 static inline u16 seq_inc(u16 sq)
536 return (sq + 1) & SEQ_MASK;
539 static inline u16 seq_sub(u16 sq1, u16 sq2)
541 return (sq1 - sq2) & SEQ_MASK;
545 static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
546 struct tid_ampdu_rx *tid_agg_rx,
549 struct ieee80211_local *local = hw_to_local(hw);
550 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
551 struct ieee80211_rx_status *status;
553 lockdep_assert_held(&tid_agg_rx->reorder_lock);
558 /* release the frame from the reorder ring buffer */
559 tid_agg_rx->stored_mpdu_num--;
560 tid_agg_rx->reorder_buf[index] = NULL;
561 status = IEEE80211_SKB_RXCB(skb);
562 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
563 skb_queue_tail(&local->rx_skb_queue, skb);
566 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
569 static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw,
570 struct tid_ampdu_rx *tid_agg_rx,
575 lockdep_assert_held(&tid_agg_rx->reorder_lock);
577 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
578 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
579 tid_agg_rx->buf_size;
580 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
585 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
586 * the skb was added to the buffer longer than this time ago, the earlier
587 * frames that have not yet been received are assumed to be lost and the skb
588 * can be released for processing. This may also release other skb's from the
589 * reorder buffer if there are no additional gaps between the frames.
591 * Callers must hold tid_agg_rx->reorder_lock.
593 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
595 static void ieee80211_sta_reorder_release(struct ieee80211_hw *hw,
596 struct tid_ampdu_rx *tid_agg_rx)
600 lockdep_assert_held(&tid_agg_rx->reorder_lock);
602 /* release the buffer until next missing frame */
603 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
604 tid_agg_rx->buf_size;
605 if (!tid_agg_rx->reorder_buf[index] &&
606 tid_agg_rx->stored_mpdu_num > 1) {
608 * No buffers ready to be released, but check whether any
609 * frames in the reorder buffer have timed out.
612 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
613 j = (j + 1) % tid_agg_rx->buf_size) {
614 if (!tid_agg_rx->reorder_buf[j]) {
618 if (!time_after(jiffies, tid_agg_rx->reorder_time[j] +
619 HT_RX_REORDER_BUF_TIMEOUT))
620 goto set_release_timer;
622 #ifdef CONFIG_MAC80211_HT_DEBUG
624 wiphy_debug(hw->wiphy,
625 "release an RX reorder frame due to timeout on earlier frames\n");
627 ieee80211_release_reorder_frame(hw, tid_agg_rx, j);
630 * Increment the head seq# also for the skipped slots.
632 tid_agg_rx->head_seq_num =
633 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
636 } else while (tid_agg_rx->reorder_buf[index]) {
637 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
638 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
639 tid_agg_rx->buf_size;
642 if (tid_agg_rx->stored_mpdu_num) {
643 j = index = seq_sub(tid_agg_rx->head_seq_num,
644 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
646 for (; j != (index - 1) % tid_agg_rx->buf_size;
647 j = (j + 1) % tid_agg_rx->buf_size) {
648 if (tid_agg_rx->reorder_buf[j])
654 mod_timer(&tid_agg_rx->reorder_timer,
655 tid_agg_rx->reorder_time[j] +
656 HT_RX_REORDER_BUF_TIMEOUT);
658 del_timer(&tid_agg_rx->reorder_timer);
663 * As this function belongs to the RX path it must be under
664 * rcu_read_lock protection. It returns false if the frame
665 * can be processed immediately, true if it was consumed.
667 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
668 struct tid_ampdu_rx *tid_agg_rx,
671 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
672 u16 sc = le16_to_cpu(hdr->seq_ctrl);
673 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
674 u16 head_seq_num, buf_size;
678 spin_lock(&tid_agg_rx->reorder_lock);
680 buf_size = tid_agg_rx->buf_size;
681 head_seq_num = tid_agg_rx->head_seq_num;
683 /* frame with out of date sequence number */
684 if (seq_less(mpdu_seq_num, head_seq_num)) {
690 * If frame the sequence number exceeds our buffering window
691 * size release some previous frames to make room for this one.
693 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
694 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
695 /* release stored frames up to new head to stack */
696 ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num);
699 /* Now the new frame is always in the range of the reordering buffer */
701 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
703 /* check if we already stored this frame */
704 if (tid_agg_rx->reorder_buf[index]) {
710 * If the current MPDU is in the right order and nothing else
711 * is stored we can process it directly, no need to buffer it.
713 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
714 tid_agg_rx->stored_mpdu_num == 0) {
715 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
720 /* put the frame in the reordering buffer */
721 tid_agg_rx->reorder_buf[index] = skb;
722 tid_agg_rx->reorder_time[index] = jiffies;
723 tid_agg_rx->stored_mpdu_num++;
724 ieee80211_sta_reorder_release(hw, tid_agg_rx);
727 spin_unlock(&tid_agg_rx->reorder_lock);
732 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
733 * true if the MPDU was buffered, false if it should be processed.
735 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx)
737 struct sk_buff *skb = rx->skb;
738 struct ieee80211_local *local = rx->local;
739 struct ieee80211_hw *hw = &local->hw;
740 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
741 struct sta_info *sta = rx->sta;
742 struct tid_ampdu_rx *tid_agg_rx;
746 if (!ieee80211_is_data_qos(hdr->frame_control))
750 * filter the QoS data rx stream according to
751 * STA/TID and check if this STA/TID is on aggregation
757 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
759 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
763 /* qos null data frames are excluded */
764 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
767 /* new, potentially un-ordered, ampdu frame - process it */
769 /* reset session timer */
770 if (tid_agg_rx->timeout)
771 mod_timer(&tid_agg_rx->session_timer,
772 TU_TO_EXP_TIME(tid_agg_rx->timeout));
774 /* if this mpdu is fragmented - terminate rx aggregation session */
775 sc = le16_to_cpu(hdr->seq_ctrl);
776 if (sc & IEEE80211_SCTL_FRAG) {
777 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
778 skb_queue_tail(&rx->sdata->skb_queue, skb);
779 ieee80211_queue_work(&local->hw, &rx->sdata->work);
784 * No locking needed -- we will only ever process one
785 * RX packet at a time, and thus own tid_agg_rx. All
786 * other code manipulating it needs to (and does) make
787 * sure that we cannot get to it any more before doing
790 if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb))
794 skb_queue_tail(&local->rx_skb_queue, skb);
797 static ieee80211_rx_result debug_noinline
798 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
800 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
801 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
803 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
804 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
805 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
806 rx->sta->last_seq_ctrl[rx->queue] ==
808 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
809 rx->local->dot11FrameDuplicateCount++;
810 rx->sta->num_duplicates++;
812 return RX_DROP_UNUSABLE;
814 rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl;
817 if (unlikely(rx->skb->len < 16)) {
818 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
819 return RX_DROP_MONITOR;
822 /* Drop disallowed frame classes based on STA auth/assoc state;
823 * IEEE 802.11, Chap 5.5.
825 * mac80211 filters only based on association state, i.e. it drops
826 * Class 3 frames from not associated stations. hostapd sends
827 * deauth/disassoc frames when needed. In addition, hostapd is
828 * responsible for filtering on both auth and assoc states.
831 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
832 return ieee80211_rx_mesh_check(rx);
834 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
835 ieee80211_is_pspoll(hdr->frame_control)) &&
836 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
837 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
838 (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) {
839 if ((!ieee80211_has_fromds(hdr->frame_control) &&
840 !ieee80211_has_tods(hdr->frame_control) &&
841 ieee80211_is_data(hdr->frame_control)) ||
842 !(status->rx_flags & IEEE80211_RX_RA_MATCH)) {
843 /* Drop IBSS frames and frames for other hosts
845 return RX_DROP_MONITOR;
848 return RX_DROP_MONITOR;
855 static ieee80211_rx_result debug_noinline
856 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
858 struct sk_buff *skb = rx->skb;
859 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
860 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
863 ieee80211_rx_result result = RX_DROP_UNUSABLE;
864 struct ieee80211_key *sta_ptk = NULL;
865 int mmie_keyidx = -1;
871 * There are four types of keys:
873 * - IGTK (group keys for management frames)
874 * - PTK (pairwise keys)
875 * - STK (station-to-station pairwise keys)
877 * When selecting a key, we have to distinguish between multicast
878 * (including broadcast) and unicast frames, the latter can only
879 * use PTKs and STKs while the former always use GTKs and IGTKs.
880 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
881 * unicast frames can also use key indices like GTKs. Hence, if we
882 * don't have a PTK/STK we check the key index for a WEP key.
884 * Note that in a regular BSS, multicast frames are sent by the
885 * AP only, associated stations unicast the frame to the AP first
886 * which then multicasts it on their behalf.
888 * There is also a slight problem in IBSS mode: GTKs are negotiated
889 * with each station, that is something we don't currently handle.
890 * The spec seems to expect that one negotiates the same key with
891 * every station but there's no such requirement; VLANs could be
896 * No point in finding a key and decrypting if the frame is neither
897 * addressed to us nor a multicast frame.
899 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
902 /* start without a key */
906 sta_ptk = rcu_dereference(rx->sta->ptk);
908 fc = hdr->frame_control;
910 if (!ieee80211_has_protected(fc))
911 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
913 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
915 if ((status->flag & RX_FLAG_DECRYPTED) &&
916 (status->flag & RX_FLAG_IV_STRIPPED))
918 /* Skip decryption if the frame is not protected. */
919 if (!ieee80211_has_protected(fc))
921 } else if (mmie_keyidx >= 0) {
922 /* Broadcast/multicast robust management frame / BIP */
923 if ((status->flag & RX_FLAG_DECRYPTED) &&
924 (status->flag & RX_FLAG_IV_STRIPPED))
927 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
928 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
929 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
931 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
933 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
934 } else if (!ieee80211_has_protected(fc)) {
936 * The frame was not protected, so skip decryption. However, we
937 * need to set rx->key if there is a key that could have been
938 * used so that the frame may be dropped if encryption would
939 * have been expected.
941 struct ieee80211_key *key = NULL;
942 struct ieee80211_sub_if_data *sdata = rx->sdata;
945 if (ieee80211_is_mgmt(fc) &&
946 is_multicast_ether_addr(hdr->addr1) &&
947 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
951 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
952 key = rcu_dereference(rx->sta->gtk[i]);
958 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
959 key = rcu_dereference(sdata->keys[i]);
971 * The device doesn't give us the IV so we won't be
972 * able to look up the key. That's ok though, we
973 * don't need to decrypt the frame, we just won't
974 * be able to keep statistics accurate.
975 * Except for key threshold notifications, should
976 * we somehow allow the driver to tell us which key
977 * the hardware used if this flag is set?
979 if ((status->flag & RX_FLAG_DECRYPTED) &&
980 (status->flag & RX_FLAG_IV_STRIPPED))
983 hdrlen = ieee80211_hdrlen(fc);
985 if (rx->skb->len < 8 + hdrlen)
986 return RX_DROP_UNUSABLE; /* TODO: count this? */
989 * no need to call ieee80211_wep_get_keyidx,
990 * it verifies a bunch of things we've done already
992 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
995 /* check per-station GTK first, if multicast packet */
996 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
997 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
999 /* if not found, try default key */
1001 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1004 * RSNA-protected unicast frames should always be
1005 * sent with pairwise or station-to-station keys,
1006 * but for WEP we allow using a key index as well.
1009 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1010 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1011 !is_multicast_ether_addr(hdr->addr1))
1017 rx->key->tx_rx_count++;
1018 /* TODO: add threshold stuff again */
1020 return RX_DROP_MONITOR;
1023 if (skb_linearize(rx->skb))
1024 return RX_DROP_UNUSABLE;
1025 /* the hdr variable is invalid now! */
1027 switch (rx->key->conf.cipher) {
1028 case WLAN_CIPHER_SUITE_WEP40:
1029 case WLAN_CIPHER_SUITE_WEP104:
1030 /* Check for weak IVs if possible */
1031 if (rx->sta && ieee80211_is_data(fc) &&
1032 (!(status->flag & RX_FLAG_IV_STRIPPED) ||
1033 !(status->flag & RX_FLAG_DECRYPTED)) &&
1034 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
1035 rx->sta->wep_weak_iv_count++;
1037 result = ieee80211_crypto_wep_decrypt(rx);
1039 case WLAN_CIPHER_SUITE_TKIP:
1040 result = ieee80211_crypto_tkip_decrypt(rx);
1042 case WLAN_CIPHER_SUITE_CCMP:
1043 result = ieee80211_crypto_ccmp_decrypt(rx);
1045 case WLAN_CIPHER_SUITE_AES_CMAC:
1046 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1050 * We can reach here only with HW-only algorithms
1051 * but why didn't it decrypt the frame?!
1053 return RX_DROP_UNUSABLE;
1056 /* either the frame has been decrypted or will be dropped */
1057 status->flag |= RX_FLAG_DECRYPTED;
1062 static ieee80211_rx_result debug_noinline
1063 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1065 struct ieee80211_local *local;
1066 struct ieee80211_hdr *hdr;
1067 struct sk_buff *skb;
1071 hdr = (struct ieee80211_hdr *) skb->data;
1073 if (!local->pspolling)
1076 if (!ieee80211_has_fromds(hdr->frame_control))
1077 /* this is not from AP */
1080 if (!ieee80211_is_data(hdr->frame_control))
1083 if (!ieee80211_has_moredata(hdr->frame_control)) {
1084 /* AP has no more frames buffered for us */
1085 local->pspolling = false;
1089 /* more data bit is set, let's request a new frame from the AP */
1090 ieee80211_send_pspoll(local, rx->sdata);
1095 static void ap_sta_ps_start(struct sta_info *sta)
1097 struct ieee80211_sub_if_data *sdata = sta->sdata;
1098 struct ieee80211_local *local = sdata->local;
1100 atomic_inc(&sdata->bss->num_sta_ps);
1101 set_sta_flags(sta, WLAN_STA_PS_STA);
1102 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1103 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1104 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1105 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
1106 sdata->name, sta->sta.addr, sta->sta.aid);
1107 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1110 static void ap_sta_ps_end(struct sta_info *sta)
1112 struct ieee80211_sub_if_data *sdata = sta->sdata;
1114 atomic_dec(&sdata->bss->num_sta_ps);
1116 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1117 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
1118 sdata->name, sta->sta.addr, sta->sta.aid);
1119 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1121 if (test_sta_flags(sta, WLAN_STA_PS_DRIVER)) {
1122 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1123 printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n",
1124 sdata->name, sta->sta.addr, sta->sta.aid);
1125 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1129 ieee80211_sta_ps_deliver_wakeup(sta);
1132 int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1134 struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1137 WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
1139 /* Don't let the same PS state be set twice */
1140 in_ps = test_sta_flags(sta_inf, WLAN_STA_PS_STA);
1141 if ((start && in_ps) || (!start && !in_ps))
1145 ap_sta_ps_start(sta_inf);
1147 ap_sta_ps_end(sta_inf);
1151 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1153 static ieee80211_rx_result debug_noinline
1154 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1156 struct sta_info *sta = rx->sta;
1157 struct sk_buff *skb = rx->skb;
1158 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1159 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1165 * Update last_rx only for IBSS packets which are for the current
1166 * BSSID to avoid keeping the current IBSS network alive in cases
1167 * where other STAs start using different BSSID.
1169 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1170 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1171 NL80211_IFTYPE_ADHOC);
1172 if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0)
1173 sta->last_rx = jiffies;
1174 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1176 * Mesh beacons will update last_rx when if they are found to
1177 * match the current local configuration when processed.
1179 sta->last_rx = jiffies;
1182 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
1185 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1186 ieee80211_sta_rx_notify(rx->sdata, hdr);
1188 sta->rx_fragments++;
1189 sta->rx_bytes += rx->skb->len;
1190 sta->last_signal = status->signal;
1191 ewma_add(&sta->avg_signal, -status->signal);
1194 * Change STA power saving mode only at the end of a frame
1195 * exchange sequence.
1197 if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
1198 !ieee80211_has_morefrags(hdr->frame_control) &&
1199 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1200 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1201 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1202 if (test_sta_flags(sta, WLAN_STA_PS_STA)) {
1204 * Ignore doze->wake transitions that are
1205 * indicated by non-data frames, the standard
1206 * is unclear here, but for example going to
1207 * PS mode and then scanning would cause a
1208 * doze->wake transition for the probe request,
1209 * and that is clearly undesirable.
1211 if (ieee80211_is_data(hdr->frame_control) &&
1212 !ieee80211_has_pm(hdr->frame_control))
1215 if (ieee80211_has_pm(hdr->frame_control))
1216 ap_sta_ps_start(sta);
1221 * Drop (qos-)data::nullfunc frames silently, since they
1222 * are used only to control station power saving mode.
1224 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1225 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1226 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1229 * If we receive a 4-addr nullfunc frame from a STA
1230 * that was not moved to a 4-addr STA vlan yet, drop
1231 * the frame to the monitor interface, to make sure
1232 * that hostapd sees it
1234 if (ieee80211_has_a4(hdr->frame_control) &&
1235 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1236 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1237 !rx->sdata->u.vlan.sta)))
1238 return RX_DROP_MONITOR;
1240 * Update counter and free packet here to avoid
1241 * counting this as a dropped packed.
1244 dev_kfree_skb(rx->skb);
1249 } /* ieee80211_rx_h_sta_process */
1251 static inline struct ieee80211_fragment_entry *
1252 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1253 unsigned int frag, unsigned int seq, int rx_queue,
1254 struct sk_buff **skb)
1256 struct ieee80211_fragment_entry *entry;
1259 idx = sdata->fragment_next;
1260 entry = &sdata->fragments[sdata->fragment_next++];
1261 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1262 sdata->fragment_next = 0;
1264 if (!skb_queue_empty(&entry->skb_list)) {
1265 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1266 struct ieee80211_hdr *hdr =
1267 (struct ieee80211_hdr *) entry->skb_list.next->data;
1268 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
1269 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
1270 "addr1=%pM addr2=%pM\n",
1272 jiffies - entry->first_frag_time, entry->seq,
1273 entry->last_frag, hdr->addr1, hdr->addr2);
1275 __skb_queue_purge(&entry->skb_list);
1278 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1280 entry->first_frag_time = jiffies;
1282 entry->rx_queue = rx_queue;
1283 entry->last_frag = frag;
1285 entry->extra_len = 0;
1290 static inline struct ieee80211_fragment_entry *
1291 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
1292 unsigned int frag, unsigned int seq,
1293 int rx_queue, struct ieee80211_hdr *hdr)
1295 struct ieee80211_fragment_entry *entry;
1298 idx = sdata->fragment_next;
1299 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1300 struct ieee80211_hdr *f_hdr;
1304 idx = IEEE80211_FRAGMENT_MAX - 1;
1306 entry = &sdata->fragments[idx];
1307 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1308 entry->rx_queue != rx_queue ||
1309 entry->last_frag + 1 != frag)
1312 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1315 * Check ftype and addresses are equal, else check next fragment
1317 if (((hdr->frame_control ^ f_hdr->frame_control) &
1318 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1319 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
1320 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
1323 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1324 __skb_queue_purge(&entry->skb_list);
1333 static ieee80211_rx_result debug_noinline
1334 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1336 struct ieee80211_hdr *hdr;
1339 unsigned int frag, seq;
1340 struct ieee80211_fragment_entry *entry;
1341 struct sk_buff *skb;
1342 struct ieee80211_rx_status *status;
1344 hdr = (struct ieee80211_hdr *)rx->skb->data;
1345 fc = hdr->frame_control;
1346 sc = le16_to_cpu(hdr->seq_ctrl);
1347 frag = sc & IEEE80211_SCTL_FRAG;
1349 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
1350 (rx->skb)->len < 24 ||
1351 is_multicast_ether_addr(hdr->addr1))) {
1352 /* not fragmented */
1355 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1357 if (skb_linearize(rx->skb))
1358 return RX_DROP_UNUSABLE;
1361 * skb_linearize() might change the skb->data and
1362 * previously cached variables (in this case, hdr) need to
1363 * be refreshed with the new data.
1365 hdr = (struct ieee80211_hdr *)rx->skb->data;
1366 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1369 /* This is the first fragment of a new frame. */
1370 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
1371 rx->queue, &(rx->skb));
1372 if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
1373 ieee80211_has_protected(fc)) {
1374 int queue = ieee80211_is_mgmt(fc) ?
1375 NUM_RX_DATA_QUEUES : rx->queue;
1376 /* Store CCMP PN so that we can verify that the next
1377 * fragment has a sequential PN value. */
1379 memcpy(entry->last_pn,
1380 rx->key->u.ccmp.rx_pn[queue],
1386 /* This is a fragment for a frame that should already be pending in
1387 * fragment cache. Add this fragment to the end of the pending entry.
1389 entry = ieee80211_reassemble_find(rx->sdata, frag, seq, rx->queue, hdr);
1391 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1392 return RX_DROP_MONITOR;
1395 /* Verify that MPDUs within one MSDU have sequential PN values.
1396 * (IEEE 802.11i, 8.3.3.4.5) */
1399 u8 pn[CCMP_PN_LEN], *rpn;
1401 if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
1402 return RX_DROP_UNUSABLE;
1403 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
1404 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
1409 queue = ieee80211_is_mgmt(fc) ?
1410 NUM_RX_DATA_QUEUES : rx->queue;
1411 rpn = rx->key->u.ccmp.rx_pn[queue];
1412 if (memcmp(pn, rpn, CCMP_PN_LEN))
1413 return RX_DROP_UNUSABLE;
1414 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
1417 skb_pull(rx->skb, ieee80211_hdrlen(fc));
1418 __skb_queue_tail(&entry->skb_list, rx->skb);
1419 entry->last_frag = frag;
1420 entry->extra_len += rx->skb->len;
1421 if (ieee80211_has_morefrags(fc)) {
1426 rx->skb = __skb_dequeue(&entry->skb_list);
1427 if (skb_tailroom(rx->skb) < entry->extra_len) {
1428 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
1429 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1431 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1432 __skb_queue_purge(&entry->skb_list);
1433 return RX_DROP_UNUSABLE;
1436 while ((skb = __skb_dequeue(&entry->skb_list))) {
1437 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1441 /* Complete frame has been reassembled - process it now */
1442 status = IEEE80211_SKB_RXCB(rx->skb);
1443 status->rx_flags |= IEEE80211_RX_FRAGMENTED;
1447 rx->sta->rx_packets++;
1448 if (is_multicast_ether_addr(hdr->addr1))
1449 rx->local->dot11MulticastReceivedFrameCount++;
1451 ieee80211_led_rx(rx->local);
1455 static ieee80211_rx_result debug_noinline
1456 ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1458 struct ieee80211_sub_if_data *sdata = rx->sdata;
1459 __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
1460 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1462 if (likely(!rx->sta || !ieee80211_is_pspoll(fc) ||
1463 !(status->rx_flags & IEEE80211_RX_RA_MATCH)))
1466 if ((sdata->vif.type != NL80211_IFTYPE_AP) &&
1467 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1468 return RX_DROP_UNUSABLE;
1470 if (!test_sta_flags(rx->sta, WLAN_STA_PS_DRIVER))
1471 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1473 set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
1475 /* Free PS Poll skb here instead of returning RX_DROP that would
1476 * count as an dropped frame. */
1477 dev_kfree_skb(rx->skb);
1482 static ieee80211_rx_result debug_noinline
1483 ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
1485 u8 *data = rx->skb->data;
1486 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
1488 if (!ieee80211_is_data_qos(hdr->frame_control))
1491 /* remove the qos control field, update frame type and meta-data */
1492 memmove(data + IEEE80211_QOS_CTL_LEN, data,
1493 ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
1494 hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
1495 /* change frame type to non QOS */
1496 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1502 ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1504 if (unlikely(!rx->sta ||
1505 !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED)))
1512 ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1514 struct sk_buff *skb = rx->skb;
1515 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1518 * Pass through unencrypted frames if the hardware has
1519 * decrypted them already.
1521 if (status->flag & RX_FLAG_DECRYPTED)
1524 /* Drop unencrypted frames if key is set. */
1525 if (unlikely(!ieee80211_has_protected(fc) &&
1526 !ieee80211_is_nullfunc(fc) &&
1527 ieee80211_is_data(fc) &&
1528 (rx->key || rx->sdata->drop_unencrypted)))
1535 ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1537 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1538 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1539 __le16 fc = hdr->frame_control;
1542 * Pass through unencrypted frames if the hardware has
1543 * decrypted them already.
1545 if (status->flag & RX_FLAG_DECRYPTED)
1548 if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) {
1549 if (unlikely(!ieee80211_has_protected(fc) &&
1550 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1552 if (ieee80211_is_deauth(fc))
1553 cfg80211_send_unprot_deauth(rx->sdata->dev,
1556 else if (ieee80211_is_disassoc(fc))
1557 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1562 /* BIP does not use Protected field, so need to check MMIE */
1563 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
1564 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
1565 if (ieee80211_is_deauth(fc))
1566 cfg80211_send_unprot_deauth(rx->sdata->dev,
1569 else if (ieee80211_is_disassoc(fc))
1570 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1576 * When using MFP, Action frames are not allowed prior to
1577 * having configured keys.
1579 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1580 ieee80211_is_robust_mgmt_frame(
1581 (struct ieee80211_hdr *) rx->skb->data)))
1589 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
1591 struct ieee80211_sub_if_data *sdata = rx->sdata;
1592 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1593 bool check_port_control = false;
1594 struct ethhdr *ehdr;
1597 if (ieee80211_has_a4(hdr->frame_control) &&
1598 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1601 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1602 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
1604 if (!sdata->u.mgd.use_4addr)
1607 check_port_control = true;
1610 if (is_multicast_ether_addr(hdr->addr1) &&
1611 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
1614 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
1615 if (ret < 0 || !check_port_control)
1618 ehdr = (struct ethhdr *) rx->skb->data;
1619 if (ehdr->h_proto != rx->sdata->control_port_protocol)
1626 * requires that rx->skb is a frame with ethernet header
1628 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
1630 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
1631 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1632 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1635 * Allow EAPOL frames to us/the PAE group address regardless
1636 * of whether the frame was encrypted or not.
1638 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
1639 (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 ||
1640 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1643 if (ieee80211_802_1x_port_control(rx) ||
1644 ieee80211_drop_unencrypted(rx, fc))
1651 * requires that rx->skb is a frame with ethernet header
1654 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1656 struct ieee80211_sub_if_data *sdata = rx->sdata;
1657 struct net_device *dev = sdata->dev;
1658 struct sk_buff *skb, *xmit_skb;
1659 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1660 struct sta_info *dsta;
1661 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1666 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1667 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1668 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
1669 (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
1670 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
1671 if (is_multicast_ether_addr(ehdr->h_dest)) {
1673 * send multicast frames both to higher layers in
1674 * local net stack and back to the wireless medium
1676 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1677 if (!xmit_skb && net_ratelimit())
1678 printk(KERN_DEBUG "%s: failed to clone "
1679 "multicast frame\n", dev->name);
1681 dsta = sta_info_get(sdata, skb->data);
1684 * The destination station is associated to
1685 * this AP (in this VLAN), so send the frame
1686 * directly to it and do not pass it to local
1696 int align __maybe_unused;
1698 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1700 * 'align' will only take the values 0 or 2 here
1701 * since all frames are required to be aligned
1702 * to 2-byte boundaries when being passed to
1703 * mac80211. That also explains the __skb_push()
1706 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
1708 if (WARN_ON(skb_headroom(skb) < 3)) {
1712 u8 *data = skb->data;
1713 size_t len = skb_headlen(skb);
1715 memmove(skb->data, data, len);
1716 skb_set_tail_pointer(skb, len);
1722 /* deliver to local stack */
1723 skb->protocol = eth_type_trans(skb, dev);
1724 memset(skb->cb, 0, sizeof(skb->cb));
1725 netif_receive_skb(skb);
1730 /* send to wireless media */
1731 xmit_skb->protocol = htons(ETH_P_802_3);
1732 skb_reset_network_header(xmit_skb);
1733 skb_reset_mac_header(xmit_skb);
1734 dev_queue_xmit(xmit_skb);
1738 static ieee80211_rx_result debug_noinline
1739 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1741 struct net_device *dev = rx->sdata->dev;
1742 struct sk_buff *skb = rx->skb;
1743 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1744 __le16 fc = hdr->frame_control;
1745 struct sk_buff_head frame_list;
1746 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1748 if (unlikely(!ieee80211_is_data(fc)))
1751 if (unlikely(!ieee80211_is_data_present(fc)))
1752 return RX_DROP_MONITOR;
1754 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
1757 if (ieee80211_has_a4(hdr->frame_control) &&
1758 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1759 !rx->sdata->u.vlan.sta)
1760 return RX_DROP_UNUSABLE;
1762 if (is_multicast_ether_addr(hdr->addr1) &&
1763 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1764 rx->sdata->u.vlan.sta) ||
1765 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1766 rx->sdata->u.mgd.use_4addr)))
1767 return RX_DROP_UNUSABLE;
1770 __skb_queue_head_init(&frame_list);
1772 if (skb_linearize(skb))
1773 return RX_DROP_UNUSABLE;
1775 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
1776 rx->sdata->vif.type,
1777 rx->local->hw.extra_tx_headroom);
1779 while (!skb_queue_empty(&frame_list)) {
1780 rx->skb = __skb_dequeue(&frame_list);
1782 if (!ieee80211_frame_allowed(rx, fc)) {
1783 dev_kfree_skb(rx->skb);
1786 dev->stats.rx_packets++;
1787 dev->stats.rx_bytes += rx->skb->len;
1789 ieee80211_deliver_skb(rx);
1795 #ifdef CONFIG_MAC80211_MESH
1796 static ieee80211_rx_result
1797 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1799 struct ieee80211_hdr *hdr;
1800 struct ieee80211s_hdr *mesh_hdr;
1801 unsigned int hdrlen;
1802 struct sk_buff *skb = rx->skb, *fwd_skb;
1803 struct ieee80211_local *local = rx->local;
1804 struct ieee80211_sub_if_data *sdata = rx->sdata;
1805 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1807 hdr = (struct ieee80211_hdr *) skb->data;
1808 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1809 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1811 if (!ieee80211_is_data(hdr->frame_control))
1816 return RX_DROP_MONITOR;
1818 if (mesh_hdr->flags & MESH_FLAGS_AE) {
1819 struct mesh_path *mppath;
1823 if (is_multicast_ether_addr(hdr->addr1)) {
1824 mpp_addr = hdr->addr3;
1825 proxied_addr = mesh_hdr->eaddr1;
1827 mpp_addr = hdr->addr4;
1828 proxied_addr = mesh_hdr->eaddr2;
1832 mppath = mpp_path_lookup(proxied_addr, sdata);
1834 mpp_path_add(proxied_addr, mpp_addr, sdata);
1836 spin_lock_bh(&mppath->state_lock);
1837 if (compare_ether_addr(mppath->mpp, mpp_addr) != 0)
1838 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
1839 spin_unlock_bh(&mppath->state_lock);
1844 /* Frame has reached destination. Don't forward */
1845 if (!is_multicast_ether_addr(hdr->addr1) &&
1846 compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0)
1851 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
1853 IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
1854 dropped_frames_ttl);
1856 struct ieee80211_hdr *fwd_hdr;
1857 struct ieee80211_tx_info *info;
1859 fwd_skb = skb_copy(skb, GFP_ATOMIC);
1861 if (!fwd_skb && net_ratelimit())
1862 printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
1867 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
1868 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
1869 info = IEEE80211_SKB_CB(fwd_skb);
1870 memset(info, 0, sizeof(*info));
1871 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1872 info->control.vif = &rx->sdata->vif;
1873 skb_set_queue_mapping(skb,
1874 ieee80211_select_queue(rx->sdata, fwd_skb));
1875 ieee80211_set_qos_hdr(local, skb);
1876 if (is_multicast_ether_addr(fwd_hdr->addr1))
1877 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1882 * Save TA to addr1 to send TA a path error if a
1883 * suitable next hop is not found
1885 memcpy(fwd_hdr->addr1, fwd_hdr->addr2,
1887 err = mesh_nexthop_lookup(fwd_skb, sdata);
1888 /* Failed to immediately resolve next hop:
1889 * fwded frame was dropped or will be added
1890 * later to the pending skb queue. */
1892 return RX_DROP_MONITOR;
1894 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1897 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1899 ieee80211_add_pending_skb(local, fwd_skb);
1904 if (is_multicast_ether_addr(hdr->addr1) ||
1905 sdata->dev->flags & IFF_PROMISC)
1908 return RX_DROP_MONITOR;
1912 static ieee80211_rx_result debug_noinline
1913 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1915 struct ieee80211_sub_if_data *sdata = rx->sdata;
1916 struct ieee80211_local *local = rx->local;
1917 struct net_device *dev = sdata->dev;
1918 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1919 __le16 fc = hdr->frame_control;
1922 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
1925 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
1926 return RX_DROP_MONITOR;
1929 * Allow the cooked monitor interface of an AP to see 4-addr frames so
1930 * that a 4-addr station can be detected and moved into a separate VLAN
1932 if (ieee80211_has_a4(hdr->frame_control) &&
1933 sdata->vif.type == NL80211_IFTYPE_AP)
1934 return RX_DROP_MONITOR;
1936 err = __ieee80211_data_to_8023(rx);
1938 return RX_DROP_UNUSABLE;
1940 if (!ieee80211_frame_allowed(rx, fc))
1941 return RX_DROP_MONITOR;
1945 dev->stats.rx_packets++;
1946 dev->stats.rx_bytes += rx->skb->len;
1948 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
1949 !is_multicast_ether_addr(
1950 ((struct ethhdr *)rx->skb->data)->h_dest) &&
1951 (!local->scanning &&
1952 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
1953 mod_timer(&local->dynamic_ps_timer, jiffies +
1954 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
1957 ieee80211_deliver_skb(rx);
1962 static ieee80211_rx_result debug_noinline
1963 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
1965 struct ieee80211_local *local = rx->local;
1966 struct ieee80211_hw *hw = &local->hw;
1967 struct sk_buff *skb = rx->skb;
1968 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
1969 struct tid_ampdu_rx *tid_agg_rx;
1973 if (likely(!ieee80211_is_ctl(bar->frame_control)))
1976 if (ieee80211_is_back_req(bar->frame_control)) {
1978 __le16 control, start_seq_num;
1979 } __packed bar_data;
1982 return RX_DROP_MONITOR;
1984 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
1985 &bar_data, sizeof(bar_data)))
1986 return RX_DROP_MONITOR;
1988 tid = le16_to_cpu(bar_data.control) >> 12;
1990 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
1992 return RX_DROP_MONITOR;
1994 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
1996 /* reset session timer */
1997 if (tid_agg_rx->timeout)
1998 mod_timer(&tid_agg_rx->session_timer,
1999 TU_TO_EXP_TIME(tid_agg_rx->timeout));
2001 spin_lock(&tid_agg_rx->reorder_lock);
2002 /* release stored frames up to start of BAR */
2003 ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num);
2004 spin_unlock(&tid_agg_rx->reorder_lock);
2011 * After this point, we only want management frames,
2012 * so we can drop all remaining control frames to
2013 * cooked monitor interfaces.
2015 return RX_DROP_MONITOR;
2018 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2019 struct ieee80211_mgmt *mgmt,
2022 struct ieee80211_local *local = sdata->local;
2023 struct sk_buff *skb;
2024 struct ieee80211_mgmt *resp;
2026 if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) {
2027 /* Not to own unicast address */
2031 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
2032 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
2033 /* Not from the current AP or not associated yet. */
2037 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2038 /* Too short SA Query request frame */
2042 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2046 skb_reserve(skb, local->hw.extra_tx_headroom);
2047 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2048 memset(resp, 0, 24);
2049 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2050 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
2051 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2052 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2053 IEEE80211_STYPE_ACTION);
2054 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2055 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2056 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2057 memcpy(resp->u.action.u.sa_query.trans_id,
2058 mgmt->u.action.u.sa_query.trans_id,
2059 WLAN_SA_QUERY_TR_ID_LEN);
2061 ieee80211_tx_skb(sdata, skb);
2064 static ieee80211_rx_result debug_noinline
2065 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2067 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2068 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2071 * From here on, look only at management frames.
2072 * Data and control frames are already handled,
2073 * and unknown (reserved) frames are useless.
2075 if (rx->skb->len < 24)
2076 return RX_DROP_MONITOR;
2078 if (!ieee80211_is_mgmt(mgmt->frame_control))
2079 return RX_DROP_MONITOR;
2081 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
2082 return RX_DROP_MONITOR;
2084 if (ieee80211_drop_unencrypted_mgmt(rx))
2085 return RX_DROP_UNUSABLE;
2090 static ieee80211_rx_result debug_noinline
2091 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2093 struct ieee80211_local *local = rx->local;
2094 struct ieee80211_sub_if_data *sdata = rx->sdata;
2095 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2096 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2097 int len = rx->skb->len;
2099 if (!ieee80211_is_action(mgmt->frame_control))
2102 /* drop too small frames */
2103 if (len < IEEE80211_MIN_ACTION_SIZE)
2104 return RX_DROP_UNUSABLE;
2106 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
2107 return RX_DROP_UNUSABLE;
2109 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
2110 return RX_DROP_UNUSABLE;
2112 switch (mgmt->u.action.category) {
2113 case WLAN_CATEGORY_BACK:
2115 * The aggregation code is not prepared to handle
2116 * anything but STA/AP due to the BSSID handling;
2117 * IBSS could work in the code but isn't supported
2118 * by drivers or the standard.
2120 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2121 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2122 sdata->vif.type != NL80211_IFTYPE_AP)
2125 /* verify action_code is present */
2126 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2129 switch (mgmt->u.action.u.addba_req.action_code) {
2130 case WLAN_ACTION_ADDBA_REQ:
2131 if (len < (IEEE80211_MIN_ACTION_SIZE +
2132 sizeof(mgmt->u.action.u.addba_req)))
2135 case WLAN_ACTION_ADDBA_RESP:
2136 if (len < (IEEE80211_MIN_ACTION_SIZE +
2137 sizeof(mgmt->u.action.u.addba_resp)))
2140 case WLAN_ACTION_DELBA:
2141 if (len < (IEEE80211_MIN_ACTION_SIZE +
2142 sizeof(mgmt->u.action.u.delba)))
2150 case WLAN_CATEGORY_SPECTRUM_MGMT:
2151 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
2154 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2157 /* verify action_code is present */
2158 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2161 switch (mgmt->u.action.u.measurement.action_code) {
2162 case WLAN_ACTION_SPCT_MSR_REQ:
2163 if (len < (IEEE80211_MIN_ACTION_SIZE +
2164 sizeof(mgmt->u.action.u.measurement)))
2166 ieee80211_process_measurement_req(sdata, mgmt, len);
2168 case WLAN_ACTION_SPCT_CHL_SWITCH:
2169 if (len < (IEEE80211_MIN_ACTION_SIZE +
2170 sizeof(mgmt->u.action.u.chan_switch)))
2173 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2176 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
2182 case WLAN_CATEGORY_SA_QUERY:
2183 if (len < (IEEE80211_MIN_ACTION_SIZE +
2184 sizeof(mgmt->u.action.u.sa_query)))
2187 switch (mgmt->u.action.u.sa_query.action) {
2188 case WLAN_ACTION_SA_QUERY_REQUEST:
2189 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2191 ieee80211_process_sa_query_req(sdata, mgmt, len);
2195 case WLAN_CATEGORY_MESH_PLINK:
2196 if (!ieee80211_vif_is_mesh(&sdata->vif))
2199 case WLAN_CATEGORY_MESH_PATH_SEL:
2200 if (!mesh_path_sel_is_hwmp(sdata))
2208 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
2209 /* will return in the next handlers */
2214 rx->sta->rx_packets++;
2215 dev_kfree_skb(rx->skb);
2219 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2220 skb_queue_tail(&sdata->skb_queue, rx->skb);
2221 ieee80211_queue_work(&local->hw, &sdata->work);
2223 rx->sta->rx_packets++;
2227 static ieee80211_rx_result debug_noinline
2228 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2230 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2232 /* skip known-bad action frames and return them in the next handler */
2233 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
2237 * Getting here means the kernel doesn't know how to handle
2238 * it, but maybe userspace does ... include returned frames
2239 * so userspace can register for those to know whether ones
2240 * it transmitted were processed or returned.
2243 if (cfg80211_rx_mgmt(rx->sdata->dev, status->freq,
2244 rx->skb->data, rx->skb->len,
2247 rx->sta->rx_packets++;
2248 dev_kfree_skb(rx->skb);
2256 static ieee80211_rx_result debug_noinline
2257 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2259 struct ieee80211_local *local = rx->local;
2260 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2261 struct sk_buff *nskb;
2262 struct ieee80211_sub_if_data *sdata = rx->sdata;
2263 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2265 if (!ieee80211_is_action(mgmt->frame_control))
2269 * For AP mode, hostapd is responsible for handling any action
2270 * frames that we didn't handle, including returning unknown
2271 * ones. For all other modes we will return them to the sender,
2272 * setting the 0x80 bit in the action category, as required by
2273 * 802.11-2007 7.3.1.11.
2274 * Newer versions of hostapd shall also use the management frame
2275 * registration mechanisms, but older ones still use cooked
2276 * monitor interfaces so push all frames there.
2278 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
2279 (sdata->vif.type == NL80211_IFTYPE_AP ||
2280 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2281 return RX_DROP_MONITOR;
2283 /* do not return rejected action frames */
2284 if (mgmt->u.action.category & 0x80)
2285 return RX_DROP_UNUSABLE;
2287 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2290 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
2292 nmgmt->u.action.category |= 0x80;
2293 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2294 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
2296 memset(nskb->cb, 0, sizeof(nskb->cb));
2298 ieee80211_tx_skb(rx->sdata, nskb);
2300 dev_kfree_skb(rx->skb);
2304 static ieee80211_rx_result debug_noinline
2305 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
2307 struct ieee80211_sub_if_data *sdata = rx->sdata;
2308 ieee80211_rx_result rxs;
2309 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2312 rxs = ieee80211_work_rx_mgmt(rx->sdata, rx->skb);
2313 if (rxs != RX_CONTINUE)
2316 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
2318 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2319 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2320 sdata->vif.type != NL80211_IFTYPE_STATION)
2321 return RX_DROP_MONITOR;
2324 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2325 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2326 /* process for all: mesh, mlme, ibss */
2328 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2329 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
2330 if (is_multicast_ether_addr(mgmt->da) &&
2331 !is_broadcast_ether_addr(mgmt->da))
2332 return RX_DROP_MONITOR;
2334 /* process only for station */
2335 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2336 return RX_DROP_MONITOR;
2338 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2339 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2340 /* process only for ibss */
2341 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
2342 return RX_DROP_MONITOR;
2345 return RX_DROP_MONITOR;
2348 /* queue up frame and kick off work to process it */
2349 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2350 skb_queue_tail(&sdata->skb_queue, rx->skb);
2351 ieee80211_queue_work(&rx->local->hw, &sdata->work);
2353 rx->sta->rx_packets++;
2358 static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr *hdr,
2359 struct ieee80211_rx_data *rx)
2362 unsigned int hdrlen;
2364 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2365 if (rx->skb->len >= hdrlen + 4)
2366 keyidx = rx->skb->data[hdrlen + 3] >> 6;
2372 * Some hardware seem to generate incorrect Michael MIC
2373 * reports; ignore them to avoid triggering countermeasures.
2378 if (!ieee80211_has_protected(hdr->frame_control))
2381 if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) {
2383 * APs with pairwise keys should never receive Michael MIC
2384 * errors for non-zero keyidx because these are reserved for
2385 * group keys and only the AP is sending real multicast
2386 * frames in the BSS.
2391 if (!ieee80211_is_data(hdr->frame_control) &&
2392 !ieee80211_is_auth(hdr->frame_control))
2395 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL,
2399 /* TODO: use IEEE80211_RX_FRAGMENTED */
2400 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2401 struct ieee80211_rate *rate)
2403 struct ieee80211_sub_if_data *sdata;
2404 struct ieee80211_local *local = rx->local;
2405 struct ieee80211_rtap_hdr {
2406 struct ieee80211_radiotap_header hdr;
2412 struct sk_buff *skb = rx->skb, *skb2;
2413 struct net_device *prev_dev = NULL;
2414 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2417 * If cooked monitor has been processed already, then
2418 * don't do it again. If not, set the flag.
2420 if (rx->flags & IEEE80211_RX_CMNTR)
2422 rx->flags |= IEEE80211_RX_CMNTR;
2424 if (skb_headroom(skb) < sizeof(*rthdr) &&
2425 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
2428 rthdr = (void *)skb_push(skb, sizeof(*rthdr));
2429 memset(rthdr, 0, sizeof(*rthdr));
2430 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
2431 rthdr->hdr.it_present =
2432 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
2433 (1 << IEEE80211_RADIOTAP_CHANNEL));
2436 rthdr->rate_or_pad = rate->bitrate / 5;
2437 rthdr->hdr.it_present |=
2438 cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
2440 rthdr->chan_freq = cpu_to_le16(status->freq);
2442 if (status->band == IEEE80211_BAND_5GHZ)
2443 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
2444 IEEE80211_CHAN_5GHZ);
2446 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
2447 IEEE80211_CHAN_2GHZ);
2449 skb_set_mac_header(skb, 0);
2450 skb->ip_summed = CHECKSUM_UNNECESSARY;
2451 skb->pkt_type = PACKET_OTHERHOST;
2452 skb->protocol = htons(ETH_P_802_2);
2454 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2455 if (!ieee80211_sdata_running(sdata))
2458 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
2459 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
2463 skb2 = skb_clone(skb, GFP_ATOMIC);
2465 skb2->dev = prev_dev;
2466 netif_receive_skb(skb2);
2470 prev_dev = sdata->dev;
2471 sdata->dev->stats.rx_packets++;
2472 sdata->dev->stats.rx_bytes += skb->len;
2476 skb->dev = prev_dev;
2477 netif_receive_skb(skb);
2485 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
2486 ieee80211_rx_result res)
2489 case RX_DROP_MONITOR:
2490 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2492 rx->sta->rx_dropped++;
2495 struct ieee80211_rate *rate = NULL;
2496 struct ieee80211_supported_band *sband;
2497 struct ieee80211_rx_status *status;
2499 status = IEEE80211_SKB_RXCB((rx->skb));
2501 sband = rx->local->hw.wiphy->bands[status->band];
2502 if (!(status->flag & RX_FLAG_HT))
2503 rate = &sband->bitrates[status->rate_idx];
2505 ieee80211_rx_cooked_monitor(rx, rate);
2508 case RX_DROP_UNUSABLE:
2509 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2511 rx->sta->rx_dropped++;
2512 dev_kfree_skb(rx->skb);
2515 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
2520 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx)
2522 ieee80211_rx_result res = RX_DROP_MONITOR;
2523 struct sk_buff *skb;
2525 #define CALL_RXH(rxh) \
2528 if (res != RX_CONTINUE) \
2532 spin_lock(&rx->local->rx_skb_queue.lock);
2533 if (rx->local->running_rx_handler)
2536 rx->local->running_rx_handler = true;
2538 while ((skb = __skb_dequeue(&rx->local->rx_skb_queue))) {
2539 spin_unlock(&rx->local->rx_skb_queue.lock);
2542 * all the other fields are valid across frames
2543 * that belong to an aMPDU since they are on the
2544 * same TID from the same station
2549 CALL_RXH(ieee80211_rx_h_decrypt)
2550 CALL_RXH(ieee80211_rx_h_check_more_data)
2551 CALL_RXH(ieee80211_rx_h_sta_process)
2552 CALL_RXH(ieee80211_rx_h_defragment)
2553 CALL_RXH(ieee80211_rx_h_ps_poll)
2554 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2555 /* must be after MMIC verify so header is counted in MPDU mic */
2556 CALL_RXH(ieee80211_rx_h_remove_qos_control)
2557 CALL_RXH(ieee80211_rx_h_amsdu)
2558 #ifdef CONFIG_MAC80211_MESH
2559 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
2560 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2562 CALL_RXH(ieee80211_rx_h_data)
2563 CALL_RXH(ieee80211_rx_h_ctrl);
2564 CALL_RXH(ieee80211_rx_h_mgmt_check)
2565 CALL_RXH(ieee80211_rx_h_action)
2566 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
2567 CALL_RXH(ieee80211_rx_h_action_return)
2568 CALL_RXH(ieee80211_rx_h_mgmt)
2571 ieee80211_rx_handlers_result(rx, res);
2572 spin_lock(&rx->local->rx_skb_queue.lock);
2576 rx->local->running_rx_handler = false;
2579 spin_unlock(&rx->local->rx_skb_queue.lock);
2582 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
2584 ieee80211_rx_result res = RX_DROP_MONITOR;
2586 #define CALL_RXH(rxh) \
2589 if (res != RX_CONTINUE) \
2593 CALL_RXH(ieee80211_rx_h_passive_scan)
2594 CALL_RXH(ieee80211_rx_h_check)
2596 ieee80211_rx_reorder_ampdu(rx);
2598 ieee80211_rx_handlers(rx);
2602 ieee80211_rx_handlers_result(rx, res);
2608 * This function makes calls into the RX path, therefore
2609 * it has to be invoked under RCU read lock.
2611 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
2613 struct ieee80211_rx_data rx = {
2615 .sdata = sta->sdata,
2616 .local = sta->local,
2619 struct tid_ampdu_rx *tid_agg_rx;
2621 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
2625 spin_lock(&tid_agg_rx->reorder_lock);
2626 ieee80211_sta_reorder_release(&sta->local->hw, tid_agg_rx);
2627 spin_unlock(&tid_agg_rx->reorder_lock);
2629 ieee80211_rx_handlers(&rx);
2632 /* main receive path */
2634 static int prepare_for_handlers(struct ieee80211_rx_data *rx,
2635 struct ieee80211_hdr *hdr)
2637 struct ieee80211_sub_if_data *sdata = rx->sdata;
2638 struct sk_buff *skb = rx->skb;
2639 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2640 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
2641 int multicast = is_multicast_ether_addr(hdr->addr1);
2643 switch (sdata->vif.type) {
2644 case NL80211_IFTYPE_STATION:
2645 if (!bssid && !sdata->u.mgd.use_4addr)
2648 compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) {
2649 if (!(sdata->dev->flags & IFF_PROMISC))
2651 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2654 case NL80211_IFTYPE_ADHOC:
2657 if (ieee80211_is_beacon(hdr->frame_control)) {
2660 else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
2661 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN))
2663 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2664 } else if (!multicast &&
2665 compare_ether_addr(sdata->vif.addr,
2667 if (!(sdata->dev->flags & IFF_PROMISC))
2669 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2670 } else if (!rx->sta) {
2672 if (status->flag & RX_FLAG_HT)
2673 rate_idx = 0; /* TODO: HT rates */
2675 rate_idx = status->rate_idx;
2676 rx->sta = ieee80211_ibss_add_sta(sdata, bssid,
2677 hdr->addr2, BIT(rate_idx), GFP_ATOMIC);
2680 case NL80211_IFTYPE_MESH_POINT:
2682 compare_ether_addr(sdata->vif.addr,
2684 if (!(sdata->dev->flags & IFF_PROMISC))
2687 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2690 case NL80211_IFTYPE_AP_VLAN:
2691 case NL80211_IFTYPE_AP:
2693 if (compare_ether_addr(sdata->vif.addr,
2696 } else if (!ieee80211_bssid_match(bssid,
2698 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
2699 !ieee80211_is_beacon(hdr->frame_control))
2701 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2704 case NL80211_IFTYPE_WDS:
2705 if (bssid || !ieee80211_is_data(hdr->frame_control))
2707 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
2711 /* should never get here */
2720 * This function returns whether or not the SKB
2721 * was destined for RX processing or not, which,
2722 * if consume is true, is equivalent to whether
2723 * or not the skb was consumed.
2725 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
2726 struct sk_buff *skb, bool consume)
2728 struct ieee80211_local *local = rx->local;
2729 struct ieee80211_sub_if_data *sdata = rx->sdata;
2730 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2731 struct ieee80211_hdr *hdr = (void *)skb->data;
2735 status->rx_flags |= IEEE80211_RX_RA_MATCH;
2736 prepares = prepare_for_handlers(rx, hdr);
2741 if (status->flag & RX_FLAG_MMIC_ERROR) {
2742 if (status->rx_flags & IEEE80211_RX_RA_MATCH)
2743 ieee80211_rx_michael_mic_report(hdr, rx);
2748 skb = skb_copy(skb, GFP_ATOMIC);
2750 if (net_ratelimit())
2751 wiphy_debug(local->hw.wiphy,
2752 "failed to copy skb for %s\n",
2760 ieee80211_invoke_rx_handlers(rx);
2765 * This is the actual Rx frames handler. as it blongs to Rx path it must
2766 * be called with rcu_read_lock protection.
2768 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2769 struct sk_buff *skb)
2771 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2772 struct ieee80211_local *local = hw_to_local(hw);
2773 struct ieee80211_sub_if_data *sdata;
2774 struct ieee80211_hdr *hdr;
2776 struct ieee80211_rx_data rx;
2777 struct ieee80211_sub_if_data *prev;
2778 struct sta_info *sta, *tmp, *prev_sta;
2781 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
2782 memset(&rx, 0, sizeof(rx));
2786 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
2787 local->dot11ReceivedFragmentCount++;
2789 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
2790 test_bit(SCAN_SW_SCANNING, &local->scanning)))
2791 status->rx_flags |= IEEE80211_RX_IN_SCAN;
2793 if (ieee80211_is_mgmt(fc))
2794 err = skb_linearize(skb);
2796 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
2803 hdr = (struct ieee80211_hdr *)skb->data;
2804 ieee80211_parse_qos(&rx);
2805 ieee80211_verify_alignment(&rx);
2807 if (ieee80211_is_data(fc)) {
2810 for_each_sta_info(local, hdr->addr2, sta, tmp) {
2817 rx.sdata = prev_sta->sdata;
2818 ieee80211_prepare_and_rx_handle(&rx, skb, false);
2825 rx.sdata = prev_sta->sdata;
2827 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2835 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2836 if (!ieee80211_sdata_running(sdata))
2839 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2840 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2844 * frame is destined for this interface, but if it's
2845 * not also for the previous one we handle that after
2846 * the loop to avoid copying the SKB once too much
2854 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2856 ieee80211_prepare_and_rx_handle(&rx, skb, false);
2862 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2865 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2874 * This is the receive path handler. It is called by a low level driver when an
2875 * 802.11 MPDU is received from the hardware.
2877 void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2879 struct ieee80211_local *local = hw_to_local(hw);
2880 struct ieee80211_rate *rate = NULL;
2881 struct ieee80211_supported_band *sband;
2882 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2884 WARN_ON_ONCE(softirq_count() == 0);
2886 if (WARN_ON(status->band < 0 ||
2887 status->band >= IEEE80211_NUM_BANDS))
2890 sband = local->hw.wiphy->bands[status->band];
2891 if (WARN_ON(!sband))
2895 * If we're suspending, it is possible although not too likely
2896 * that we'd be receiving frames after having already partially
2897 * quiesced the stack. We can't process such frames then since
2898 * that might, for example, cause stations to be added or other
2899 * driver callbacks be invoked.
2901 if (unlikely(local->quiescing || local->suspended))
2905 * The same happens when we're not even started,
2906 * but that's worth a warning.
2908 if (WARN_ON(!local->started))
2911 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
2913 * Validate the rate, unless a PLCP error means that
2914 * we probably can't have a valid rate here anyway.
2917 if (status->flag & RX_FLAG_HT) {
2919 * rate_idx is MCS index, which can be [0-76]
2922 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
2924 * Anything else would be some sort of driver or
2925 * hardware error. The driver should catch hardware
2928 if (WARN((status->rate_idx < 0 ||
2929 status->rate_idx > 76),
2930 "Rate marked as an HT rate but passed "
2931 "status->rate_idx is not "
2932 "an MCS index [0-76]: %d (0x%02x)\n",
2937 if (WARN_ON(status->rate_idx < 0 ||
2938 status->rate_idx >= sband->n_bitrates))
2940 rate = &sband->bitrates[status->rate_idx];
2944 status->rx_flags = 0;
2947 * key references and virtual interfaces are protected using RCU
2948 * and this requires that we are in a read-side RCU section during
2949 * receive processing
2954 * Frames with failed FCS/PLCP checksum are not returned,
2955 * all other frames are returned without radiotap header
2956 * if it was previously present.
2957 * Also, frames with less than 16 bytes are dropped.
2959 skb = ieee80211_rx_monitor(local, skb, rate);
2965 ieee80211_tpt_led_trig_rx(local,
2966 ((struct ieee80211_hdr *)skb->data)->frame_control,
2968 __ieee80211_rx_handle_packet(hw, skb);
2976 EXPORT_SYMBOL(ieee80211_rx);
2978 /* This is a version of the rx handler that can be called from hard irq
2979 * context. Post the skb on the queue and schedule the tasklet */
2980 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
2982 struct ieee80211_local *local = hw_to_local(hw);
2984 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
2986 skb->pkt_type = IEEE80211_RX_MSG;
2987 skb_queue_tail(&local->skb_queue, skb);
2988 tasklet_schedule(&local->tasklet);
2990 EXPORT_SYMBOL(ieee80211_rx_irqsafe);