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 skb_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)
84 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
87 if (len & 1) /* padding for RX_FLAGS if necessary */
94 * ieee80211_add_rx_radiotap_header - add radiotap header
96 * add a radiotap header containing all the fields which the hardware provided.
99 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
101 struct ieee80211_rate *rate,
104 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
105 struct ieee80211_radiotap_header *rthdr;
109 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
110 memset(rthdr, 0, rtap_len);
112 /* radiotap header, set always present flags */
114 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
115 (1 << IEEE80211_RADIOTAP_CHANNEL) |
116 (1 << IEEE80211_RADIOTAP_ANTENNA) |
117 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
118 rthdr->it_len = cpu_to_le16(rtap_len);
120 pos = (unsigned char *)(rthdr+1);
122 /* the order of the following fields is important */
124 /* IEEE80211_RADIOTAP_TSFT */
125 if (status->flag & RX_FLAG_TSFT) {
126 put_unaligned_le64(status->mactime, pos);
128 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
132 /* IEEE80211_RADIOTAP_FLAGS */
133 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
134 *pos |= IEEE80211_RADIOTAP_F_FCS;
135 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
136 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
137 if (status->flag & RX_FLAG_SHORTPRE)
138 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
141 /* IEEE80211_RADIOTAP_RATE */
142 if (status->flag & RX_FLAG_HT) {
144 * TODO: add following information into radiotap header once
145 * suitable fields are defined for it:
146 * - MCS index (status->rate_idx)
147 * - HT40 (status->flag & RX_FLAG_40MHZ)
148 * - short-GI (status->flag & RX_FLAG_SHORT_GI)
152 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
153 *pos = rate->bitrate / 5;
157 /* IEEE80211_RADIOTAP_CHANNEL */
158 put_unaligned_le16(status->freq, pos);
160 if (status->band == IEEE80211_BAND_5GHZ)
161 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
163 else if (status->flag & RX_FLAG_HT)
164 put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
166 else if (rate->flags & IEEE80211_RATE_ERP_G)
167 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
170 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
174 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
175 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
176 *pos = status->signal;
178 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
182 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
184 /* IEEE80211_RADIOTAP_ANTENNA */
185 *pos = status->antenna;
188 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
190 /* IEEE80211_RADIOTAP_RX_FLAGS */
191 /* ensure 2 byte alignment for the 2 byte field as required */
192 if ((pos - (u8 *)rthdr) & 1)
194 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
195 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
196 put_unaligned_le16(rx_flags, pos);
201 * This function copies a received frame to all monitor interfaces and
202 * returns a cleaned-up SKB that no longer includes the FCS nor the
203 * radiotap header the driver might have added.
205 static struct sk_buff *
206 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
207 struct ieee80211_rate *rate)
209 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
210 struct ieee80211_sub_if_data *sdata;
211 int needed_headroom = 0;
212 struct sk_buff *skb, *skb2;
213 struct net_device *prev_dev = NULL;
214 int present_fcs_len = 0;
217 * First, we may need to make a copy of the skb because
218 * (1) we need to modify it for radiotap (if not present), and
219 * (2) the other RX handlers will modify the skb we got.
221 * We don't need to, of course, if we aren't going to return
222 * the SKB because it has a bad FCS/PLCP checksum.
225 /* room for the radiotap header based on driver features */
226 needed_headroom = ieee80211_rx_radiotap_len(local, status);
228 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
229 present_fcs_len = FCS_LEN;
231 if (!local->monitors) {
232 if (should_drop_frame(origskb, present_fcs_len)) {
233 dev_kfree_skb(origskb);
237 return remove_monitor_info(local, origskb);
240 if (should_drop_frame(origskb, present_fcs_len)) {
241 /* only need to expand headroom if necessary */
246 * This shouldn't trigger often because most devices have an
247 * RX header they pull before we get here, and that should
248 * be big enough for our radiotap information. We should
249 * probably export the length to drivers so that we can have
250 * them allocate enough headroom to start with.
252 if (skb_headroom(skb) < needed_headroom &&
253 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
259 * Need to make a copy and possibly remove radiotap header
260 * and FCS from the original.
262 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
264 origskb = remove_monitor_info(local, origskb);
270 /* prepend radiotap information */
271 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
273 skb_reset_mac_header(skb);
274 skb->ip_summed = CHECKSUM_UNNECESSARY;
275 skb->pkt_type = PACKET_OTHERHOST;
276 skb->protocol = htons(ETH_P_802_2);
278 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
279 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
282 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
285 if (!ieee80211_sdata_running(sdata))
289 skb2 = skb_clone(skb, GFP_ATOMIC);
291 skb2->dev = prev_dev;
296 prev_dev = sdata->dev;
297 sdata->dev->stats.rx_packets++;
298 sdata->dev->stats.rx_bytes += skb->len;
311 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
313 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
316 /* does the frame have a qos control field? */
317 if (ieee80211_is_data_qos(hdr->frame_control)) {
318 u8 *qc = ieee80211_get_qos_ctl(hdr);
319 /* frame has qos control */
320 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
321 if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
322 rx->flags |= IEEE80211_RX_AMSDU;
324 rx->flags &= ~IEEE80211_RX_AMSDU;
327 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
329 * Sequence numbers for management frames, QoS data
330 * frames with a broadcast/multicast address in the
331 * Address 1 field, and all non-QoS data frames sent
332 * by QoS STAs are assigned using an additional single
333 * modulo-4096 counter, [...]
335 * We also use that counter for non-QoS STAs.
337 tid = NUM_RX_DATA_QUEUES - 1;
341 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
342 * For now, set skb->priority to 0 for other cases. */
343 rx->skb->priority = (tid > 7) ? 0 : tid;
347 * DOC: Packet alignment
349 * Drivers always need to pass packets that are aligned to two-byte boundaries
352 * Additionally, should, if possible, align the payload data in a way that
353 * guarantees that the contained IP header is aligned to a four-byte
354 * boundary. In the case of regular frames, this simply means aligning the
355 * payload to a four-byte boundary (because either the IP header is directly
356 * contained, or IV/RFC1042 headers that have a length divisible by four are
357 * in front of it). If the payload data is not properly aligned and the
358 * architecture doesn't support efficient unaligned operations, mac80211
359 * will align the data.
361 * With A-MSDU frames, however, the payload data address must yield two modulo
362 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
363 * push the IP header further back to a multiple of four again. Thankfully, the
364 * specs were sane enough this time around to require padding each A-MSDU
365 * subframe to a length that is a multiple of four.
367 * Padding like Atheros hardware adds which is inbetween the 802.11 header and
368 * the payload is not supported, the driver is required to move the 802.11
369 * header to be directly in front of the payload in that case.
371 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
373 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
374 WARN_ONCE((unsigned long)rx->skb->data & 1,
375 "unaligned packet at 0x%p\n", rx->skb->data);
382 static ieee80211_rx_result debug_noinline
383 ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
385 struct ieee80211_local *local = rx->local;
386 struct sk_buff *skb = rx->skb;
388 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning)))
389 return ieee80211_scan_rx(rx->sdata, skb);
391 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning) &&
392 (rx->flags & IEEE80211_RX_IN_SCAN))) {
393 /* drop all the other packets during a software scan anyway */
394 if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
399 if (unlikely(rx->flags & IEEE80211_RX_IN_SCAN)) {
400 /* scanning finished during invoking of handlers */
401 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
402 return RX_DROP_UNUSABLE;
409 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
411 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
413 if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
416 return ieee80211_is_robust_mgmt_frame(hdr);
420 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
422 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
424 if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
427 return ieee80211_is_robust_mgmt_frame(hdr);
431 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
432 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
434 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
435 struct ieee80211_mmie *mmie;
437 if (skb->len < 24 + sizeof(*mmie) ||
438 !is_multicast_ether_addr(hdr->da))
441 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
442 return -1; /* not a robust management frame */
444 mmie = (struct ieee80211_mmie *)
445 (skb->data + skb->len - sizeof(*mmie));
446 if (mmie->element_id != WLAN_EID_MMIE ||
447 mmie->length != sizeof(*mmie) - 2)
450 return le16_to_cpu(mmie->key_id);
454 static ieee80211_rx_result
455 ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
457 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
458 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
459 char *dev_addr = rx->sdata->vif.addr;
461 if (ieee80211_is_data(hdr->frame_control)) {
462 if (is_multicast_ether_addr(hdr->addr1)) {
463 if (ieee80211_has_tods(hdr->frame_control) ||
464 !ieee80211_has_fromds(hdr->frame_control))
465 return RX_DROP_MONITOR;
466 if (memcmp(hdr->addr3, dev_addr, ETH_ALEN) == 0)
467 return RX_DROP_MONITOR;
469 if (!ieee80211_has_a4(hdr->frame_control))
470 return RX_DROP_MONITOR;
471 if (memcmp(hdr->addr4, dev_addr, ETH_ALEN) == 0)
472 return RX_DROP_MONITOR;
476 /* If there is not an established peer link and this is not a peer link
477 * establisment frame, beacon or probe, drop the frame.
480 if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) {
481 struct ieee80211_mgmt *mgmt;
483 if (!ieee80211_is_mgmt(hdr->frame_control))
484 return RX_DROP_MONITOR;
486 if (ieee80211_is_action(hdr->frame_control)) {
487 mgmt = (struct ieee80211_mgmt *)hdr;
488 if (mgmt->u.action.category != MESH_PLINK_CATEGORY)
489 return RX_DROP_MONITOR;
493 if (ieee80211_is_probe_req(hdr->frame_control) ||
494 ieee80211_is_probe_resp(hdr->frame_control) ||
495 ieee80211_is_beacon(hdr->frame_control))
498 return RX_DROP_MONITOR;
502 #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
504 if (ieee80211_is_data(hdr->frame_control) &&
505 is_multicast_ether_addr(hdr->addr1) &&
506 mesh_rmc_check(hdr->addr3, msh_h_get(hdr, hdrlen), rx->sdata))
507 return RX_DROP_MONITOR;
513 #define SEQ_MODULO 0x1000
514 #define SEQ_MASK 0xfff
516 static inline int seq_less(u16 sq1, u16 sq2)
518 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
521 static inline u16 seq_inc(u16 sq)
523 return (sq + 1) & SEQ_MASK;
526 static inline u16 seq_sub(u16 sq1, u16 sq2)
528 return (sq1 - sq2) & SEQ_MASK;
532 static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
533 struct tid_ampdu_rx *tid_agg_rx,
535 struct sk_buff_head *frames)
537 struct ieee80211_supported_band *sband;
538 struct ieee80211_rate *rate = NULL;
539 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
540 struct ieee80211_rx_status *status;
545 status = IEEE80211_SKB_RXCB(skb);
547 /* release the reordered frames to stack */
548 sband = hw->wiphy->bands[status->band];
549 if (!(status->flag & RX_FLAG_HT))
550 rate = &sband->bitrates[status->rate_idx];
551 tid_agg_rx->stored_mpdu_num--;
552 tid_agg_rx->reorder_buf[index] = NULL;
553 __skb_queue_tail(frames, skb);
556 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
559 static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw,
560 struct tid_ampdu_rx *tid_agg_rx,
562 struct sk_buff_head *frames)
566 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
567 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
568 tid_agg_rx->buf_size;
569 ieee80211_release_reorder_frame(hw, tid_agg_rx, index, frames);
574 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
575 * the skb was added to the buffer longer than this time ago, the earlier
576 * frames that have not yet been received are assumed to be lost and the skb
577 * can be released for processing. This may also release other skb's from the
578 * reorder buffer if there are no additional gaps between the frames.
580 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
583 * As this function belongs to the RX path it must be under
584 * rcu_read_lock protection. It returns false if the frame
585 * can be processed immediately, true if it was consumed.
587 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
588 struct tid_ampdu_rx *tid_agg_rx,
590 struct sk_buff_head *frames)
592 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
593 u16 sc = le16_to_cpu(hdr->seq_ctrl);
594 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
595 u16 head_seq_num, buf_size;
598 buf_size = tid_agg_rx->buf_size;
599 head_seq_num = tid_agg_rx->head_seq_num;
601 /* frame with out of date sequence number */
602 if (seq_less(mpdu_seq_num, head_seq_num)) {
608 * If frame the sequence number exceeds our buffering window
609 * size release some previous frames to make room for this one.
611 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
612 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
613 /* release stored frames up to new head to stack */
614 ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num,
618 /* Now the new frame is always in the range of the reordering buffer */
620 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
622 /* check if we already stored this frame */
623 if (tid_agg_rx->reorder_buf[index]) {
629 * If the current MPDU is in the right order and nothing else
630 * is stored we can process it directly, no need to buffer it.
632 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
633 tid_agg_rx->stored_mpdu_num == 0) {
634 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
638 /* put the frame in the reordering buffer */
639 tid_agg_rx->reorder_buf[index] = skb;
640 tid_agg_rx->reorder_time[index] = jiffies;
641 tid_agg_rx->stored_mpdu_num++;
642 /* release the buffer until next missing frame */
643 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
644 tid_agg_rx->buf_size;
645 if (!tid_agg_rx->reorder_buf[index] &&
646 tid_agg_rx->stored_mpdu_num > 1) {
648 * No buffers ready to be released, but check whether any
649 * frames in the reorder buffer have timed out.
653 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
654 j = (j + 1) % tid_agg_rx->buf_size) {
655 if (!tid_agg_rx->reorder_buf[j]) {
659 if (!time_after(jiffies, tid_agg_rx->reorder_time[j] +
660 HT_RX_REORDER_BUF_TIMEOUT))
663 #ifdef CONFIG_MAC80211_HT_DEBUG
665 printk(KERN_DEBUG "%s: release an RX reorder "
666 "frame due to timeout on earlier "
668 wiphy_name(hw->wiphy));
670 ieee80211_release_reorder_frame(hw, tid_agg_rx,
674 * Increment the head seq# also for the skipped slots.
676 tid_agg_rx->head_seq_num =
677 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
680 } else while (tid_agg_rx->reorder_buf[index]) {
681 ieee80211_release_reorder_frame(hw, tid_agg_rx, index, frames);
682 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
683 tid_agg_rx->buf_size;
690 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
691 * true if the MPDU was buffered, false if it should be processed.
693 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
694 struct sk_buff_head *frames)
696 struct sk_buff *skb = rx->skb;
697 struct ieee80211_local *local = rx->local;
698 struct ieee80211_hw *hw = &local->hw;
699 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
700 struct sta_info *sta = rx->sta;
701 struct tid_ampdu_rx *tid_agg_rx;
705 if (!ieee80211_is_data_qos(hdr->frame_control))
709 * filter the QoS data rx stream according to
710 * STA/TID and check if this STA/TID is on aggregation
716 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
718 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL)
721 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
723 /* qos null data frames are excluded */
724 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
727 /* new, potentially un-ordered, ampdu frame - process it */
729 /* reset session timer */
730 if (tid_agg_rx->timeout)
731 mod_timer(&tid_agg_rx->session_timer,
732 TU_TO_EXP_TIME(tid_agg_rx->timeout));
734 /* if this mpdu is fragmented - terminate rx aggregation session */
735 sc = le16_to_cpu(hdr->seq_ctrl);
736 if (sc & IEEE80211_SCTL_FRAG) {
737 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
738 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
743 if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, frames))
747 __skb_queue_tail(frames, skb);
750 static ieee80211_rx_result debug_noinline
751 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
753 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
755 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
756 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
757 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
758 rx->sta->last_seq_ctrl[rx->queue] ==
760 if (rx->flags & IEEE80211_RX_RA_MATCH) {
761 rx->local->dot11FrameDuplicateCount++;
762 rx->sta->num_duplicates++;
764 return RX_DROP_MONITOR;
766 rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl;
769 if (unlikely(rx->skb->len < 16)) {
770 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
771 return RX_DROP_MONITOR;
774 /* Drop disallowed frame classes based on STA auth/assoc state;
775 * IEEE 802.11, Chap 5.5.
777 * mac80211 filters only based on association state, i.e. it drops
778 * Class 3 frames from not associated stations. hostapd sends
779 * deauth/disassoc frames when needed. In addition, hostapd is
780 * responsible for filtering on both auth and assoc states.
783 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
784 return ieee80211_rx_mesh_check(rx);
786 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
787 ieee80211_is_pspoll(hdr->frame_control)) &&
788 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
789 (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) {
790 if ((!ieee80211_has_fromds(hdr->frame_control) &&
791 !ieee80211_has_tods(hdr->frame_control) &&
792 ieee80211_is_data(hdr->frame_control)) ||
793 !(rx->flags & IEEE80211_RX_RA_MATCH)) {
794 /* Drop IBSS frames and frames for other hosts
796 return RX_DROP_MONITOR;
799 return RX_DROP_MONITOR;
806 static ieee80211_rx_result debug_noinline
807 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
809 struct sk_buff *skb = rx->skb;
810 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
811 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
814 ieee80211_rx_result result = RX_DROP_UNUSABLE;
815 struct ieee80211_key *stakey = NULL;
816 int mmie_keyidx = -1;
821 * There are four types of keys:
823 * - IGTK (group keys for management frames)
824 * - PTK (pairwise keys)
825 * - STK (station-to-station pairwise keys)
827 * When selecting a key, we have to distinguish between multicast
828 * (including broadcast) and unicast frames, the latter can only
829 * use PTKs and STKs while the former always use GTKs and IGTKs.
830 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
831 * unicast frames can also use key indices like GTKs. Hence, if we
832 * don't have a PTK/STK we check the key index for a WEP key.
834 * Note that in a regular BSS, multicast frames are sent by the
835 * AP only, associated stations unicast the frame to the AP first
836 * which then multicasts it on their behalf.
838 * There is also a slight problem in IBSS mode: GTKs are negotiated
839 * with each station, that is something we don't currently handle.
840 * The spec seems to expect that one negotiates the same key with
841 * every station but there's no such requirement; VLANs could be
846 * No point in finding a key and decrypting if the frame is neither
847 * addressed to us nor a multicast frame.
849 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
852 /* start without a key */
856 stakey = rcu_dereference(rx->sta->key);
858 if (!ieee80211_has_protected(hdr->frame_control))
859 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
861 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
863 /* Skip decryption if the frame is not protected. */
864 if (!ieee80211_has_protected(hdr->frame_control))
866 } else if (mmie_keyidx >= 0) {
867 /* Broadcast/multicast robust management frame / BIP */
868 if ((status->flag & RX_FLAG_DECRYPTED) &&
869 (status->flag & RX_FLAG_IV_STRIPPED))
872 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
873 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
874 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
875 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
876 } else if (!ieee80211_has_protected(hdr->frame_control)) {
878 * The frame was not protected, so skip decryption. However, we
879 * need to set rx->key if there is a key that could have been
880 * used so that the frame may be dropped if encryption would
881 * have been expected.
883 struct ieee80211_key *key = NULL;
884 if (ieee80211_is_mgmt(hdr->frame_control) &&
885 is_multicast_ether_addr(hdr->addr1) &&
886 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
888 else if ((key = rcu_dereference(rx->sdata->default_key)))
893 * The device doesn't give us the IV so we won't be
894 * able to look up the key. That's ok though, we
895 * don't need to decrypt the frame, we just won't
896 * be able to keep statistics accurate.
897 * Except for key threshold notifications, should
898 * we somehow allow the driver to tell us which key
899 * the hardware used if this flag is set?
901 if ((status->flag & RX_FLAG_DECRYPTED) &&
902 (status->flag & RX_FLAG_IV_STRIPPED))
905 hdrlen = ieee80211_hdrlen(hdr->frame_control);
907 if (rx->skb->len < 8 + hdrlen)
908 return RX_DROP_UNUSABLE; /* TODO: count this? */
911 * no need to call ieee80211_wep_get_keyidx,
912 * it verifies a bunch of things we've done already
914 keyidx = rx->skb->data[hdrlen + 3] >> 6;
916 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
919 * RSNA-protected unicast frames should always be sent with
920 * pairwise or station-to-station keys, but for WEP we allow
921 * using a key index as well.
923 if (rx->key && rx->key->conf.alg != ALG_WEP &&
924 !is_multicast_ether_addr(hdr->addr1))
929 rx->key->tx_rx_count++;
930 /* TODO: add threshold stuff again */
932 return RX_DROP_MONITOR;
935 /* Check for weak IVs if possible */
936 if (rx->sta && rx->key->conf.alg == ALG_WEP &&
937 ieee80211_is_data(hdr->frame_control) &&
938 (!(status->flag & RX_FLAG_IV_STRIPPED) ||
939 !(status->flag & RX_FLAG_DECRYPTED)) &&
940 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
941 rx->sta->wep_weak_iv_count++;
943 switch (rx->key->conf.alg) {
945 result = ieee80211_crypto_wep_decrypt(rx);
948 result = ieee80211_crypto_tkip_decrypt(rx);
951 result = ieee80211_crypto_ccmp_decrypt(rx);
954 result = ieee80211_crypto_aes_cmac_decrypt(rx);
958 /* either the frame has been decrypted or will be dropped */
959 status->flag |= RX_FLAG_DECRYPTED;
964 static ieee80211_rx_result debug_noinline
965 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
967 struct ieee80211_local *local;
968 struct ieee80211_hdr *hdr;
973 hdr = (struct ieee80211_hdr *) skb->data;
975 if (!local->pspolling)
978 if (!ieee80211_has_fromds(hdr->frame_control))
979 /* this is not from AP */
982 if (!ieee80211_is_data(hdr->frame_control))
985 if (!ieee80211_has_moredata(hdr->frame_control)) {
986 /* AP has no more frames buffered for us */
987 local->pspolling = false;
991 /* more data bit is set, let's request a new frame from the AP */
992 ieee80211_send_pspoll(local, rx->sdata);
997 static void ap_sta_ps_start(struct sta_info *sta)
999 struct ieee80211_sub_if_data *sdata = sta->sdata;
1000 struct ieee80211_local *local = sdata->local;
1002 atomic_inc(&sdata->bss->num_sta_ps);
1003 set_sta_flags(sta, WLAN_STA_PS_STA);
1004 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1005 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1006 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
1007 sdata->name, sta->sta.addr, sta->sta.aid);
1008 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1011 static void ap_sta_ps_end(struct sta_info *sta)
1013 struct ieee80211_sub_if_data *sdata = sta->sdata;
1015 atomic_dec(&sdata->bss->num_sta_ps);
1017 clear_sta_flags(sta, WLAN_STA_PS_STA);
1019 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1020 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
1021 sdata->name, sta->sta.addr, sta->sta.aid);
1022 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1024 if (test_sta_flags(sta, WLAN_STA_PS_DRIVER)) {
1025 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1026 printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n",
1027 sdata->name, sta->sta.addr, sta->sta.aid);
1028 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1032 ieee80211_sta_ps_deliver_wakeup(sta);
1035 static ieee80211_rx_result debug_noinline
1036 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1038 struct sta_info *sta = rx->sta;
1039 struct sk_buff *skb = rx->skb;
1040 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1041 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1047 * Update last_rx only for IBSS packets which are for the current
1048 * BSSID to avoid keeping the current IBSS network alive in cases
1049 * where other STAs start using different BSSID.
1051 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1052 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1053 NL80211_IFTYPE_ADHOC);
1054 if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0)
1055 sta->last_rx = jiffies;
1056 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1058 * Mesh beacons will update last_rx when if they are found to
1059 * match the current local configuration when processed.
1061 sta->last_rx = jiffies;
1064 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
1067 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1068 ieee80211_sta_rx_notify(rx->sdata, hdr);
1070 sta->rx_fragments++;
1071 sta->rx_bytes += rx->skb->len;
1072 sta->last_signal = status->signal;
1075 * Change STA power saving mode only at the end of a frame
1076 * exchange sequence.
1078 if (!ieee80211_has_morefrags(hdr->frame_control) &&
1079 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1080 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1081 if (test_sta_flags(sta, WLAN_STA_PS_STA)) {
1083 * Ignore doze->wake transitions that are
1084 * indicated by non-data frames, the standard
1085 * is unclear here, but for example going to
1086 * PS mode and then scanning would cause a
1087 * doze->wake transition for the probe request,
1088 * and that is clearly undesirable.
1090 if (ieee80211_is_data(hdr->frame_control) &&
1091 !ieee80211_has_pm(hdr->frame_control))
1094 if (ieee80211_has_pm(hdr->frame_control))
1095 ap_sta_ps_start(sta);
1100 * Drop (qos-)data::nullfunc frames silently, since they
1101 * are used only to control station power saving mode.
1103 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1104 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1105 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1108 * If we receive a 4-addr nullfunc frame from a STA
1109 * that was not moved to a 4-addr STA vlan yet, drop
1110 * the frame to the monitor interface, to make sure
1111 * that hostapd sees it
1113 if (ieee80211_has_a4(hdr->frame_control) &&
1114 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1115 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1116 !rx->sdata->u.vlan.sta)))
1117 return RX_DROP_MONITOR;
1119 * Update counter and free packet here to avoid
1120 * counting this as a dropped packed.
1123 dev_kfree_skb(rx->skb);
1128 } /* ieee80211_rx_h_sta_process */
1130 static inline struct ieee80211_fragment_entry *
1131 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1132 unsigned int frag, unsigned int seq, int rx_queue,
1133 struct sk_buff **skb)
1135 struct ieee80211_fragment_entry *entry;
1138 idx = sdata->fragment_next;
1139 entry = &sdata->fragments[sdata->fragment_next++];
1140 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1141 sdata->fragment_next = 0;
1143 if (!skb_queue_empty(&entry->skb_list)) {
1144 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1145 struct ieee80211_hdr *hdr =
1146 (struct ieee80211_hdr *) entry->skb_list.next->data;
1147 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
1148 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
1149 "addr1=%pM addr2=%pM\n",
1151 jiffies - entry->first_frag_time, entry->seq,
1152 entry->last_frag, hdr->addr1, hdr->addr2);
1154 __skb_queue_purge(&entry->skb_list);
1157 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1159 entry->first_frag_time = jiffies;
1161 entry->rx_queue = rx_queue;
1162 entry->last_frag = frag;
1164 entry->extra_len = 0;
1169 static inline struct ieee80211_fragment_entry *
1170 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
1171 unsigned int frag, unsigned int seq,
1172 int rx_queue, struct ieee80211_hdr *hdr)
1174 struct ieee80211_fragment_entry *entry;
1177 idx = sdata->fragment_next;
1178 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1179 struct ieee80211_hdr *f_hdr;
1183 idx = IEEE80211_FRAGMENT_MAX - 1;
1185 entry = &sdata->fragments[idx];
1186 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1187 entry->rx_queue != rx_queue ||
1188 entry->last_frag + 1 != frag)
1191 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
1194 * Check ftype and addresses are equal, else check next fragment
1196 if (((hdr->frame_control ^ f_hdr->frame_control) &
1197 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
1198 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
1199 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
1202 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
1203 __skb_queue_purge(&entry->skb_list);
1212 static ieee80211_rx_result debug_noinline
1213 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1215 struct ieee80211_hdr *hdr;
1218 unsigned int frag, seq;
1219 struct ieee80211_fragment_entry *entry;
1220 struct sk_buff *skb;
1222 hdr = (struct ieee80211_hdr *)rx->skb->data;
1223 fc = hdr->frame_control;
1224 sc = le16_to_cpu(hdr->seq_ctrl);
1225 frag = sc & IEEE80211_SCTL_FRAG;
1227 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
1228 (rx->skb)->len < 24 ||
1229 is_multicast_ether_addr(hdr->addr1))) {
1230 /* not fragmented */
1233 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1235 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1238 /* This is the first fragment of a new frame. */
1239 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
1240 rx->queue, &(rx->skb));
1241 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
1242 ieee80211_has_protected(fc)) {
1243 /* Store CCMP PN so that we can verify that the next
1244 * fragment has a sequential PN value. */
1246 memcpy(entry->last_pn,
1247 rx->key->u.ccmp.rx_pn[rx->queue],
1253 /* This is a fragment for a frame that should already be pending in
1254 * fragment cache. Add this fragment to the end of the pending entry.
1256 entry = ieee80211_reassemble_find(rx->sdata, frag, seq, rx->queue, hdr);
1258 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1259 return RX_DROP_MONITOR;
1262 /* Verify that MPDUs within one MSDU have sequential PN values.
1263 * (IEEE 802.11i, 8.3.3.4.5) */
1266 u8 pn[CCMP_PN_LEN], *rpn;
1267 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
1268 return RX_DROP_UNUSABLE;
1269 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
1270 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
1275 rpn = rx->key->u.ccmp.rx_pn[rx->queue];
1276 if (memcmp(pn, rpn, CCMP_PN_LEN))
1277 return RX_DROP_UNUSABLE;
1278 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
1281 skb_pull(rx->skb, ieee80211_hdrlen(fc));
1282 __skb_queue_tail(&entry->skb_list, rx->skb);
1283 entry->last_frag = frag;
1284 entry->extra_len += rx->skb->len;
1285 if (ieee80211_has_morefrags(fc)) {
1290 rx->skb = __skb_dequeue(&entry->skb_list);
1291 if (skb_tailroom(rx->skb) < entry->extra_len) {
1292 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
1293 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1295 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1296 __skb_queue_purge(&entry->skb_list);
1297 return RX_DROP_UNUSABLE;
1300 while ((skb = __skb_dequeue(&entry->skb_list))) {
1301 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1305 /* Complete frame has been reassembled - process it now */
1306 rx->flags |= IEEE80211_RX_FRAGMENTED;
1310 rx->sta->rx_packets++;
1311 if (is_multicast_ether_addr(hdr->addr1))
1312 rx->local->dot11MulticastReceivedFrameCount++;
1314 ieee80211_led_rx(rx->local);
1318 static ieee80211_rx_result debug_noinline
1319 ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1321 struct ieee80211_sub_if_data *sdata = rx->sdata;
1322 __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
1324 if (likely(!rx->sta || !ieee80211_is_pspoll(fc) ||
1325 !(rx->flags & IEEE80211_RX_RA_MATCH)))
1328 if ((sdata->vif.type != NL80211_IFTYPE_AP) &&
1329 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1330 return RX_DROP_UNUSABLE;
1332 if (!test_sta_flags(rx->sta, WLAN_STA_PS_DRIVER))
1333 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1335 set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
1337 /* Free PS Poll skb here instead of returning RX_DROP that would
1338 * count as an dropped frame. */
1339 dev_kfree_skb(rx->skb);
1344 static ieee80211_rx_result debug_noinline
1345 ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
1347 u8 *data = rx->skb->data;
1348 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
1350 if (!ieee80211_is_data_qos(hdr->frame_control))
1353 /* remove the qos control field, update frame type and meta-data */
1354 memmove(data + IEEE80211_QOS_CTL_LEN, data,
1355 ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
1356 hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
1357 /* change frame type to non QOS */
1358 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1364 ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1366 if (unlikely(!rx->sta ||
1367 !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED)))
1374 ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1376 struct sk_buff *skb = rx->skb;
1377 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1380 * Pass through unencrypted frames if the hardware has
1381 * decrypted them already.
1383 if (status->flag & RX_FLAG_DECRYPTED)
1386 /* Drop unencrypted frames if key is set. */
1387 if (unlikely(!ieee80211_has_protected(fc) &&
1388 !ieee80211_is_nullfunc(fc) &&
1389 ieee80211_is_data(fc) &&
1390 (rx->key || rx->sdata->drop_unencrypted)))
1397 ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1399 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1400 __le16 fc = hdr->frame_control;
1403 res = ieee80211_drop_unencrypted(rx, fc);
1407 if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) {
1408 if (unlikely(ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1411 /* BIP does not use Protected field, so need to check MMIE */
1412 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
1413 ieee80211_get_mmie_keyidx(rx->skb) < 0 &&
1417 * When using MFP, Action frames are not allowed prior to
1418 * having configured keys.
1420 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1421 ieee80211_is_robust_mgmt_frame(
1422 (struct ieee80211_hdr *) rx->skb->data)))
1430 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
1432 struct ieee80211_sub_if_data *sdata = rx->sdata;
1433 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1435 if (ieee80211_has_a4(hdr->frame_control) &&
1436 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1439 if (is_multicast_ether_addr(hdr->addr1) &&
1440 ((sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta) ||
1441 (sdata->vif.type == NL80211_IFTYPE_STATION && sdata->u.mgd.use_4addr)))
1444 return ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
1448 * requires that rx->skb is a frame with ethernet header
1450 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
1452 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
1453 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1454 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1457 * Allow EAPOL frames to us/the PAE group address regardless
1458 * of whether the frame was encrypted or not.
1460 if (ehdr->h_proto == htons(ETH_P_PAE) &&
1461 (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 ||
1462 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1465 if (ieee80211_802_1x_port_control(rx) ||
1466 ieee80211_drop_unencrypted(rx, fc))
1473 * requires that rx->skb is a frame with ethernet header
1476 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1478 struct ieee80211_sub_if_data *sdata = rx->sdata;
1479 struct net_device *dev = sdata->dev;
1480 struct sk_buff *skb, *xmit_skb;
1481 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1482 struct sta_info *dsta;
1487 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1488 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1489 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
1490 (rx->flags & IEEE80211_RX_RA_MATCH) &&
1491 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
1492 if (is_multicast_ether_addr(ehdr->h_dest)) {
1494 * send multicast frames both to higher layers in
1495 * local net stack and back to the wireless medium
1497 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1498 if (!xmit_skb && net_ratelimit())
1499 printk(KERN_DEBUG "%s: failed to clone "
1500 "multicast frame\n", dev->name);
1502 dsta = sta_info_get(sdata, skb->data);
1505 * The destination station is associated to
1506 * this AP (in this VLAN), so send the frame
1507 * directly to it and do not pass it to local
1517 int align __maybe_unused;
1519 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1521 * 'align' will only take the values 0 or 2 here
1522 * since all frames are required to be aligned
1523 * to 2-byte boundaries when being passed to
1524 * mac80211. That also explains the __skb_push()
1527 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
1529 if (WARN_ON(skb_headroom(skb) < 3)) {
1533 u8 *data = skb->data;
1534 size_t len = skb_headlen(skb);
1536 memmove(skb->data, data, len);
1537 skb_set_tail_pointer(skb, len);
1543 /* deliver to local stack */
1544 skb->protocol = eth_type_trans(skb, dev);
1545 memset(skb->cb, 0, sizeof(skb->cb));
1551 /* send to wireless media */
1552 xmit_skb->protocol = htons(ETH_P_802_3);
1553 skb_reset_network_header(xmit_skb);
1554 skb_reset_mac_header(xmit_skb);
1555 dev_queue_xmit(xmit_skb);
1559 static ieee80211_rx_result debug_noinline
1560 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1562 struct net_device *dev = rx->sdata->dev;
1563 struct sk_buff *skb = rx->skb;
1564 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1565 __le16 fc = hdr->frame_control;
1566 struct sk_buff_head frame_list;
1568 if (unlikely(!ieee80211_is_data(fc)))
1571 if (unlikely(!ieee80211_is_data_present(fc)))
1572 return RX_DROP_MONITOR;
1574 if (!(rx->flags & IEEE80211_RX_AMSDU))
1577 if (ieee80211_has_a4(hdr->frame_control) &&
1578 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1579 !rx->sdata->u.vlan.sta)
1580 return RX_DROP_UNUSABLE;
1582 if (is_multicast_ether_addr(hdr->addr1) &&
1583 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1584 rx->sdata->u.vlan.sta) ||
1585 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1586 rx->sdata->u.mgd.use_4addr)))
1587 return RX_DROP_UNUSABLE;
1590 __skb_queue_head_init(&frame_list);
1592 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
1593 rx->sdata->vif.type,
1594 rx->local->hw.extra_tx_headroom);
1596 while (!skb_queue_empty(&frame_list)) {
1597 rx->skb = __skb_dequeue(&frame_list);
1599 if (!ieee80211_frame_allowed(rx, fc)) {
1600 dev_kfree_skb(rx->skb);
1603 dev->stats.rx_packets++;
1604 dev->stats.rx_bytes += rx->skb->len;
1606 ieee80211_deliver_skb(rx);
1612 #ifdef CONFIG_MAC80211_MESH
1613 static ieee80211_rx_result
1614 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1616 struct ieee80211_hdr *hdr;
1617 struct ieee80211s_hdr *mesh_hdr;
1618 unsigned int hdrlen;
1619 struct sk_buff *skb = rx->skb, *fwd_skb;
1620 struct ieee80211_local *local = rx->local;
1621 struct ieee80211_sub_if_data *sdata = rx->sdata;
1623 hdr = (struct ieee80211_hdr *) skb->data;
1624 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1625 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1627 if (!ieee80211_is_data(hdr->frame_control))
1632 return RX_DROP_MONITOR;
1634 if (mesh_hdr->flags & MESH_FLAGS_AE) {
1635 struct mesh_path *mppath;
1639 if (is_multicast_ether_addr(hdr->addr1)) {
1640 mpp_addr = hdr->addr3;
1641 proxied_addr = mesh_hdr->eaddr1;
1643 mpp_addr = hdr->addr4;
1644 proxied_addr = mesh_hdr->eaddr2;
1648 mppath = mpp_path_lookup(proxied_addr, sdata);
1650 mpp_path_add(proxied_addr, mpp_addr, sdata);
1652 spin_lock_bh(&mppath->state_lock);
1653 if (compare_ether_addr(mppath->mpp, mpp_addr) != 0)
1654 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
1655 spin_unlock_bh(&mppath->state_lock);
1660 /* Frame has reached destination. Don't forward */
1661 if (!is_multicast_ether_addr(hdr->addr1) &&
1662 compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0)
1667 if (rx->flags & IEEE80211_RX_RA_MATCH) {
1669 IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
1670 dropped_frames_ttl);
1672 struct ieee80211_hdr *fwd_hdr;
1673 struct ieee80211_tx_info *info;
1675 fwd_skb = skb_copy(skb, GFP_ATOMIC);
1677 if (!fwd_skb && net_ratelimit())
1678 printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
1681 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
1682 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
1683 info = IEEE80211_SKB_CB(fwd_skb);
1684 memset(info, 0, sizeof(*info));
1685 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1686 info->control.vif = &rx->sdata->vif;
1687 skb_set_queue_mapping(skb,
1688 ieee80211_select_queue(rx->sdata, fwd_skb));
1689 ieee80211_set_qos_hdr(local, skb);
1690 if (is_multicast_ether_addr(fwd_hdr->addr1))
1691 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1696 * Save TA to addr1 to send TA a path error if a
1697 * suitable next hop is not found
1699 memcpy(fwd_hdr->addr1, fwd_hdr->addr2,
1701 err = mesh_nexthop_lookup(fwd_skb, sdata);
1702 /* Failed to immediately resolve next hop:
1703 * fwded frame was dropped or will be added
1704 * later to the pending skb queue. */
1706 return RX_DROP_MONITOR;
1708 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1711 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1713 ieee80211_add_pending_skb(local, fwd_skb);
1717 if (is_multicast_ether_addr(hdr->addr1) ||
1718 sdata->dev->flags & IFF_PROMISC)
1721 return RX_DROP_MONITOR;
1725 static ieee80211_rx_result debug_noinline
1726 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1728 struct ieee80211_sub_if_data *sdata = rx->sdata;
1729 struct ieee80211_local *local = rx->local;
1730 struct net_device *dev = sdata->dev;
1731 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1732 __le16 fc = hdr->frame_control;
1735 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
1738 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
1739 return RX_DROP_MONITOR;
1742 * Allow the cooked monitor interface of an AP to see 4-addr frames so
1743 * that a 4-addr station can be detected and moved into a separate VLAN
1745 if (ieee80211_has_a4(hdr->frame_control) &&
1746 sdata->vif.type == NL80211_IFTYPE_AP)
1747 return RX_DROP_MONITOR;
1749 err = __ieee80211_data_to_8023(rx);
1751 return RX_DROP_UNUSABLE;
1753 if (!ieee80211_frame_allowed(rx, fc))
1754 return RX_DROP_MONITOR;
1758 dev->stats.rx_packets++;
1759 dev->stats.rx_bytes += rx->skb->len;
1761 if (ieee80211_is_data(hdr->frame_control) &&
1762 !is_multicast_ether_addr(hdr->addr1) &&
1763 local->hw.conf.dynamic_ps_timeout > 0 && local->ps_sdata) {
1764 mod_timer(&local->dynamic_ps_timer, jiffies +
1765 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
1768 ieee80211_deliver_skb(rx);
1773 static ieee80211_rx_result debug_noinline
1774 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
1776 struct ieee80211_local *local = rx->local;
1777 struct ieee80211_hw *hw = &local->hw;
1778 struct sk_buff *skb = rx->skb;
1779 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
1780 struct tid_ampdu_rx *tid_agg_rx;
1784 if (likely(!ieee80211_is_ctl(bar->frame_control)))
1787 if (ieee80211_is_back_req(bar->frame_control)) {
1789 return RX_DROP_MONITOR;
1790 tid = le16_to_cpu(bar->control) >> 12;
1791 if (rx->sta->ampdu_mlme.tid_state_rx[tid]
1792 != HT_AGG_STATE_OPERATIONAL)
1793 return RX_DROP_MONITOR;
1794 tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid];
1796 start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
1798 /* reset session timer */
1799 if (tid_agg_rx->timeout)
1800 mod_timer(&tid_agg_rx->session_timer,
1801 TU_TO_EXP_TIME(tid_agg_rx->timeout));
1803 /* release stored frames up to start of BAR */
1804 ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num,
1813 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
1814 struct ieee80211_mgmt *mgmt,
1817 struct ieee80211_local *local = sdata->local;
1818 struct sk_buff *skb;
1819 struct ieee80211_mgmt *resp;
1821 if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) {
1822 /* Not to own unicast address */
1826 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
1827 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
1828 /* Not from the current AP or not associated yet. */
1832 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
1833 /* Too short SA Query request frame */
1837 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
1841 skb_reserve(skb, local->hw.extra_tx_headroom);
1842 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
1843 memset(resp, 0, 24);
1844 memcpy(resp->da, mgmt->sa, ETH_ALEN);
1845 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
1846 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1847 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1848 IEEE80211_STYPE_ACTION);
1849 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
1850 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
1851 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
1852 memcpy(resp->u.action.u.sa_query.trans_id,
1853 mgmt->u.action.u.sa_query.trans_id,
1854 WLAN_SA_QUERY_TR_ID_LEN);
1856 ieee80211_tx_skb(sdata, skb);
1859 static ieee80211_rx_result debug_noinline
1860 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1862 struct ieee80211_local *local = rx->local;
1863 struct ieee80211_sub_if_data *sdata = rx->sdata;
1864 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
1865 struct sk_buff *nskb;
1866 struct ieee80211_rx_status *status;
1867 int len = rx->skb->len;
1869 if (!ieee80211_is_action(mgmt->frame_control))
1872 /* drop too small frames */
1873 if (len < IEEE80211_MIN_ACTION_SIZE)
1874 return RX_DROP_UNUSABLE;
1876 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
1877 return RX_DROP_UNUSABLE;
1879 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
1880 return RX_DROP_UNUSABLE;
1882 if (ieee80211_drop_unencrypted_mgmt(rx))
1883 return RX_DROP_UNUSABLE;
1885 switch (mgmt->u.action.category) {
1886 case WLAN_CATEGORY_BACK:
1888 * The aggregation code is not prepared to handle
1889 * anything but STA/AP due to the BSSID handling;
1890 * IBSS could work in the code but isn't supported
1891 * by drivers or the standard.
1893 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1894 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1895 sdata->vif.type != NL80211_IFTYPE_AP)
1898 /* verify action_code is present */
1899 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
1902 switch (mgmt->u.action.u.addba_req.action_code) {
1903 case WLAN_ACTION_ADDBA_REQ:
1904 if (len < (IEEE80211_MIN_ACTION_SIZE +
1905 sizeof(mgmt->u.action.u.addba_req)))
1906 return RX_DROP_MONITOR;
1907 ieee80211_process_addba_request(local, rx->sta, mgmt, len);
1909 case WLAN_ACTION_ADDBA_RESP:
1910 if (len < (IEEE80211_MIN_ACTION_SIZE +
1911 sizeof(mgmt->u.action.u.addba_resp)))
1913 ieee80211_process_addba_resp(local, rx->sta, mgmt, len);
1915 case WLAN_ACTION_DELBA:
1916 if (len < (IEEE80211_MIN_ACTION_SIZE +
1917 sizeof(mgmt->u.action.u.delba)))
1919 ieee80211_process_delba(sdata, rx->sta, mgmt, len);
1923 case WLAN_CATEGORY_SPECTRUM_MGMT:
1924 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
1927 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1930 /* verify action_code is present */
1931 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
1934 switch (mgmt->u.action.u.measurement.action_code) {
1935 case WLAN_ACTION_SPCT_MSR_REQ:
1936 if (len < (IEEE80211_MIN_ACTION_SIZE +
1937 sizeof(mgmt->u.action.u.measurement)))
1939 ieee80211_process_measurement_req(sdata, mgmt, len);
1941 case WLAN_ACTION_SPCT_CHL_SWITCH:
1942 if (len < (IEEE80211_MIN_ACTION_SIZE +
1943 sizeof(mgmt->u.action.u.chan_switch)))
1946 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1949 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
1952 return ieee80211_sta_rx_mgmt(sdata, rx->skb);
1955 case WLAN_CATEGORY_SA_QUERY:
1956 if (len < (IEEE80211_MIN_ACTION_SIZE +
1957 sizeof(mgmt->u.action.u.sa_query)))
1960 switch (mgmt->u.action.u.sa_query.action) {
1961 case WLAN_ACTION_SA_QUERY_REQUEST:
1962 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1964 ieee80211_process_sa_query_req(sdata, mgmt, len);
1968 case MESH_PLINK_CATEGORY:
1969 case MESH_PATH_SEL_CATEGORY:
1970 if (ieee80211_vif_is_mesh(&sdata->vif))
1971 return ieee80211_mesh_rx_mgmt(sdata, rx->skb);
1976 * For AP mode, hostapd is responsible for handling any action
1977 * frames that we didn't handle, including returning unknown
1978 * ones. For all other modes we will return them to the sender,
1979 * setting the 0x80 bit in the action category, as required by
1980 * 802.11-2007 7.3.1.11.
1982 if (sdata->vif.type == NL80211_IFTYPE_AP ||
1983 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1984 return RX_DROP_MONITOR;
1987 * Getting here means the kernel doesn't know how to handle
1988 * it, but maybe userspace does ... include returned frames
1989 * so userspace can register for those to know whether ones
1990 * it transmitted were processed or returned.
1992 status = IEEE80211_SKB_RXCB(rx->skb);
1994 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1995 cfg80211_rx_action(rx->sdata->dev, status->freq,
1996 rx->skb->data, rx->skb->len,
2000 /* do not return rejected action frames */
2001 if (mgmt->u.action.category & 0x80)
2002 return RX_DROP_UNUSABLE;
2004 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2007 struct ieee80211_mgmt *mgmt = (void *)nskb->data;
2009 mgmt->u.action.category |= 0x80;
2010 memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
2011 memcpy(mgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
2013 memset(nskb->cb, 0, sizeof(nskb->cb));
2015 ieee80211_tx_skb(rx->sdata, nskb);
2020 rx->sta->rx_packets++;
2021 dev_kfree_skb(rx->skb);
2025 static ieee80211_rx_result debug_noinline
2026 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
2028 struct ieee80211_sub_if_data *sdata = rx->sdata;
2029 ieee80211_rx_result rxs;
2031 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
2032 return RX_DROP_MONITOR;
2034 if (ieee80211_drop_unencrypted_mgmt(rx))
2035 return RX_DROP_UNUSABLE;
2037 rxs = ieee80211_work_rx_mgmt(rx->sdata, rx->skb);
2038 if (rxs != RX_CONTINUE)
2041 if (ieee80211_vif_is_mesh(&sdata->vif))
2042 return ieee80211_mesh_rx_mgmt(sdata, rx->skb);
2044 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2045 return ieee80211_ibss_rx_mgmt(sdata, rx->skb);
2047 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2048 return ieee80211_sta_rx_mgmt(sdata, rx->skb);
2050 return RX_DROP_MONITOR;
2053 static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr *hdr,
2054 struct ieee80211_rx_data *rx)
2057 unsigned int hdrlen;
2059 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2060 if (rx->skb->len >= hdrlen + 4)
2061 keyidx = rx->skb->data[hdrlen + 3] >> 6;
2067 * Some hardware seem to generate incorrect Michael MIC
2068 * reports; ignore them to avoid triggering countermeasures.
2073 if (!ieee80211_has_protected(hdr->frame_control))
2076 if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) {
2078 * APs with pairwise keys should never receive Michael MIC
2079 * errors for non-zero keyidx because these are reserved for
2080 * group keys and only the AP is sending real multicast
2081 * frames in the BSS.
2086 if (!ieee80211_is_data(hdr->frame_control) &&
2087 !ieee80211_is_auth(hdr->frame_control))
2090 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL,
2094 /* TODO: use IEEE80211_RX_FRAGMENTED */
2095 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2096 struct ieee80211_rate *rate)
2098 struct ieee80211_sub_if_data *sdata;
2099 struct ieee80211_local *local = rx->local;
2100 struct ieee80211_rtap_hdr {
2101 struct ieee80211_radiotap_header hdr;
2106 } __attribute__ ((packed)) *rthdr;
2107 struct sk_buff *skb = rx->skb, *skb2;
2108 struct net_device *prev_dev = NULL;
2109 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2111 if (status->flag & RX_FLAG_INTERNAL_CMTR)
2114 if (skb_headroom(skb) < sizeof(*rthdr) &&
2115 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
2118 rthdr = (void *)skb_push(skb, sizeof(*rthdr));
2119 memset(rthdr, 0, sizeof(*rthdr));
2120 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
2121 rthdr->hdr.it_present =
2122 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
2123 (1 << IEEE80211_RADIOTAP_CHANNEL));
2126 rthdr->rate_or_pad = rate->bitrate / 5;
2127 rthdr->hdr.it_present |=
2128 cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
2130 rthdr->chan_freq = cpu_to_le16(status->freq);
2132 if (status->band == IEEE80211_BAND_5GHZ)
2133 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
2134 IEEE80211_CHAN_5GHZ);
2136 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
2137 IEEE80211_CHAN_2GHZ);
2139 skb_set_mac_header(skb, 0);
2140 skb->ip_summed = CHECKSUM_UNNECESSARY;
2141 skb->pkt_type = PACKET_OTHERHOST;
2142 skb->protocol = htons(ETH_P_802_2);
2144 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2145 if (!ieee80211_sdata_running(sdata))
2148 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
2149 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
2153 skb2 = skb_clone(skb, GFP_ATOMIC);
2155 skb2->dev = prev_dev;
2160 prev_dev = sdata->dev;
2161 sdata->dev->stats.rx_packets++;
2162 sdata->dev->stats.rx_bytes += skb->len;
2166 skb->dev = prev_dev;
2172 status->flag |= RX_FLAG_INTERNAL_CMTR;
2180 static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
2181 struct ieee80211_rx_data *rx,
2182 struct sk_buff *skb,
2183 struct ieee80211_rate *rate)
2185 struct sk_buff_head reorder_release;
2186 ieee80211_rx_result res = RX_DROP_MONITOR;
2188 __skb_queue_head_init(&reorder_release);
2193 #define CALL_RXH(rxh) \
2196 if (res != RX_CONTINUE) \
2201 * NB: the rxh_next label works even if we jump
2202 * to it from here because then the list will
2203 * be empty, which is a trivial check
2205 CALL_RXH(ieee80211_rx_h_passive_scan)
2206 CALL_RXH(ieee80211_rx_h_check)
2208 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
2210 while ((skb = __skb_dequeue(&reorder_release))) {
2212 * all the other fields are valid across frames
2213 * that belong to an aMPDU since they are on the
2214 * same TID from the same station
2218 CALL_RXH(ieee80211_rx_h_decrypt)
2219 CALL_RXH(ieee80211_rx_h_check_more_data)
2220 CALL_RXH(ieee80211_rx_h_sta_process)
2221 CALL_RXH(ieee80211_rx_h_defragment)
2222 CALL_RXH(ieee80211_rx_h_ps_poll)
2223 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2224 /* must be after MMIC verify so header is counted in MPDU mic */
2225 CALL_RXH(ieee80211_rx_h_remove_qos_control)
2226 CALL_RXH(ieee80211_rx_h_amsdu)
2227 #ifdef CONFIG_MAC80211_MESH
2228 if (ieee80211_vif_is_mesh(&sdata->vif))
2229 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2231 CALL_RXH(ieee80211_rx_h_data)
2233 /* special treatment -- needs the queue */
2234 res = ieee80211_rx_h_ctrl(rx, &reorder_release);
2235 if (res != RX_CONTINUE)
2238 CALL_RXH(ieee80211_rx_h_action)
2239 CALL_RXH(ieee80211_rx_h_mgmt)
2245 case RX_DROP_MONITOR:
2246 I802_DEBUG_INC(sdata->local->rx_handlers_drop);
2248 rx->sta->rx_dropped++;
2251 ieee80211_rx_cooked_monitor(rx, rate);
2253 case RX_DROP_UNUSABLE:
2254 I802_DEBUG_INC(sdata->local->rx_handlers_drop);
2256 rx->sta->rx_dropped++;
2257 dev_kfree_skb(rx->skb);
2260 I802_DEBUG_INC(sdata->local->rx_handlers_queued);
2266 /* main receive path */
2268 static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2269 struct ieee80211_rx_data *rx,
2270 struct ieee80211_hdr *hdr)
2272 struct sk_buff *skb = rx->skb;
2273 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2274 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
2275 int multicast = is_multicast_ether_addr(hdr->addr1);
2277 switch (sdata->vif.type) {
2278 case NL80211_IFTYPE_STATION:
2279 if (!bssid && !sdata->u.mgd.use_4addr)
2282 compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) {
2283 if (!(sdata->dev->flags & IFF_PROMISC))
2285 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2288 case NL80211_IFTYPE_ADHOC:
2291 if (ieee80211_is_beacon(hdr->frame_control)) {
2294 else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
2295 if (!(rx->flags & IEEE80211_RX_IN_SCAN))
2297 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2298 } else if (!multicast &&
2299 compare_ether_addr(sdata->vif.addr,
2301 if (!(sdata->dev->flags & IFF_PROMISC))
2303 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2304 } else if (!rx->sta) {
2306 if (status->flag & RX_FLAG_HT)
2307 rate_idx = 0; /* TODO: HT rates */
2309 rate_idx = status->rate_idx;
2310 rx->sta = ieee80211_ibss_add_sta(sdata, bssid,
2311 hdr->addr2, BIT(rate_idx), GFP_ATOMIC);
2314 case NL80211_IFTYPE_MESH_POINT:
2316 compare_ether_addr(sdata->vif.addr,
2318 if (!(sdata->dev->flags & IFF_PROMISC))
2321 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2324 case NL80211_IFTYPE_AP_VLAN:
2325 case NL80211_IFTYPE_AP:
2327 if (compare_ether_addr(sdata->vif.addr,
2330 } else if (!ieee80211_bssid_match(bssid,
2332 if (!(rx->flags & IEEE80211_RX_IN_SCAN))
2334 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2337 case NL80211_IFTYPE_WDS:
2338 if (bssid || !ieee80211_is_data(hdr->frame_control))
2340 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
2343 case NL80211_IFTYPE_MONITOR:
2344 case NL80211_IFTYPE_UNSPECIFIED:
2345 case __NL80211_IFTYPE_AFTER_LAST:
2346 /* should never get here */
2355 * This is the actual Rx frames handler. as it blongs to Rx path it must
2356 * be called with rcu_read_lock protection.
2358 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2359 struct sk_buff *skb,
2360 struct ieee80211_rate *rate)
2362 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2363 struct ieee80211_local *local = hw_to_local(hw);
2364 struct ieee80211_sub_if_data *sdata;
2365 struct ieee80211_hdr *hdr;
2366 struct ieee80211_rx_data rx;
2368 struct ieee80211_sub_if_data *prev = NULL;
2369 struct sk_buff *skb_new;
2370 struct sta_info *sta, *tmp;
2371 bool found_sta = false;
2373 hdr = (struct ieee80211_hdr *)skb->data;
2374 memset(&rx, 0, sizeof(rx));
2378 if (ieee80211_is_data(hdr->frame_control) || ieee80211_is_mgmt(hdr->frame_control))
2379 local->dot11ReceivedFragmentCount++;
2381 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
2382 test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
2383 rx.flags |= IEEE80211_RX_IN_SCAN;
2385 ieee80211_parse_qos(&rx);
2386 ieee80211_verify_alignment(&rx);
2388 if (ieee80211_is_data(hdr->frame_control)) {
2389 for_each_sta_info(local, hdr->addr2, sta, tmp) {
2392 rx.sdata = sta->sdata;
2394 rx.flags |= IEEE80211_RX_RA_MATCH;
2395 prepares = prepare_for_handlers(rx.sdata, &rx, hdr);
2397 if (status->flag & RX_FLAG_MMIC_ERROR) {
2398 if (rx.flags & IEEE80211_RX_RA_MATCH)
2399 ieee80211_rx_michael_mic_report(hdr, &rx);
2406 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2407 if (!ieee80211_sdata_running(sdata))
2410 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2411 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2415 * frame is destined for this interface, but if it's
2416 * not also for the previous one we handle that after
2417 * the loop to avoid copying the SKB once too much
2425 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2427 rx.flags |= IEEE80211_RX_RA_MATCH;
2428 prepares = prepare_for_handlers(prev, &rx, hdr);
2433 if (status->flag & RX_FLAG_MMIC_ERROR) {
2435 if (rx.flags & IEEE80211_RX_RA_MATCH)
2436 ieee80211_rx_michael_mic_report(hdr,
2442 * frame was destined for the previous interface
2443 * so invoke RX handlers for it
2446 skb_new = skb_copy(skb, GFP_ATOMIC);
2448 if (net_ratelimit())
2449 printk(KERN_DEBUG "%s: failed to copy "
2450 "multicast frame for %s\n",
2451 wiphy_name(local->hw.wiphy),
2455 ieee80211_invoke_rx_handlers(prev, &rx, skb_new, rate);
2461 rx.sta = sta_info_get_bss(prev, hdr->addr2);
2463 rx.flags |= IEEE80211_RX_RA_MATCH;
2464 prepares = prepare_for_handlers(prev, &rx, hdr);
2471 ieee80211_invoke_rx_handlers(prev, &rx, skb, rate);
2477 * This is the receive path handler. It is called by a low level driver when an
2478 * 802.11 MPDU is received from the hardware.
2480 void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2482 struct ieee80211_local *local = hw_to_local(hw);
2483 struct ieee80211_rate *rate = NULL;
2484 struct ieee80211_supported_band *sband;
2485 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2487 WARN_ON_ONCE(softirq_count() == 0);
2489 if (WARN_ON(status->band < 0 ||
2490 status->band >= IEEE80211_NUM_BANDS))
2493 sband = local->hw.wiphy->bands[status->band];
2494 if (WARN_ON(!sband))
2498 * If we're suspending, it is possible although not too likely
2499 * that we'd be receiving frames after having already partially
2500 * quiesced the stack. We can't process such frames then since
2501 * that might, for example, cause stations to be added or other
2502 * driver callbacks be invoked.
2504 if (unlikely(local->quiescing || local->suspended))
2508 * The same happens when we're not even started,
2509 * but that's worth a warning.
2511 if (WARN_ON(!local->started))
2514 if (status->flag & RX_FLAG_HT) {
2516 * rate_idx is MCS index, which can be [0-76] as documented on:
2518 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
2520 * Anything else would be some sort of driver or hardware error.
2521 * The driver should catch hardware errors.
2523 if (WARN((status->rate_idx < 0 ||
2524 status->rate_idx > 76),
2525 "Rate marked as an HT rate but passed "
2526 "status->rate_idx is not "
2527 "an MCS index [0-76]: %d (0x%02x)\n",
2532 if (WARN_ON(status->rate_idx < 0 ||
2533 status->rate_idx >= sband->n_bitrates))
2535 rate = &sband->bitrates[status->rate_idx];
2539 * key references and virtual interfaces are protected using RCU
2540 * and this requires that we are in a read-side RCU section during
2541 * receive processing
2546 * Frames with failed FCS/PLCP checksum are not returned,
2547 * all other frames are returned without radiotap header
2548 * if it was previously present.
2549 * Also, frames with less than 16 bytes are dropped.
2551 skb = ieee80211_rx_monitor(local, skb, rate);
2557 __ieee80211_rx_handle_packet(hw, skb, rate);
2565 EXPORT_SYMBOL(ieee80211_rx);
2567 /* This is a version of the rx handler that can be called from hard irq
2568 * context. Post the skb on the queue and schedule the tasklet */
2569 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
2571 struct ieee80211_local *local = hw_to_local(hw);
2573 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
2575 skb->pkt_type = IEEE80211_RX_MSG;
2576 skb_queue_tail(&local->skb_queue, skb);
2577 tasklet_schedule(&local->tasklet);
2579 EXPORT_SYMBOL(ieee80211_rx_irqsafe);