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 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/kernel.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/rcupdate.h>
17 #include <net/mac80211.h>
18 #include <net/ieee80211_radiotap.h>
20 #include "ieee80211_i.h"
21 #include "ieee80211_led.h"
28 * monitor mode reception
30 * This function cleans up the SKB, i.e. it removes all the stuff
31 * only useful for monitoring.
33 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
37 skb_pull(skb, rtap_len);
39 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
40 if (likely(skb->len > FCS_LEN))
41 skb_trim(skb, skb->len - FCS_LEN);
53 static inline int should_drop_frame(struct ieee80211_rx_status *status,
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 + radiotap_len))
64 if (((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
65 cpu_to_le16(IEEE80211_FTYPE_CTL)) &&
66 ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) !=
67 cpu_to_le16(IEEE80211_STYPE_PSPOLL)))
73 * This function copies a received frame to all monitor interfaces and
74 * returns a cleaned-up SKB that no longer includes the FCS nor the
75 * radiotap header the driver might have added.
77 static struct sk_buff *
78 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
79 struct ieee80211_rx_status *status)
81 struct ieee80211_sub_if_data *sdata;
82 struct ieee80211_rate *rate;
83 int needed_headroom = 0;
84 struct ieee80211_radiotap_header *rthdr;
85 __le64 *rttsft = NULL;
86 struct ieee80211_rtap_fixed_data {
92 u8 padding_for_rxflags;
94 } __attribute__ ((packed)) *rtfixed;
95 struct sk_buff *skb, *skb2;
96 struct net_device *prev_dev = NULL;
97 int present_fcs_len = 0;
101 * First, we may need to make a copy of the skb because
102 * (1) we need to modify it for radiotap (if not present), and
103 * (2) the other RX handlers will modify the skb we got.
105 * We don't need to, of course, if we aren't going to return
106 * the SKB because it has a bad FCS/PLCP checksum.
108 if (status->flag & RX_FLAG_RADIOTAP)
109 rtap_len = ieee80211_get_radiotap_len(origskb->data);
111 /* room for radiotap header, always present fields and TSFT */
112 needed_headroom = sizeof(*rthdr) + sizeof(*rtfixed) + 8;
114 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
115 present_fcs_len = FCS_LEN;
117 if (!local->monitors) {
118 if (should_drop_frame(status, origskb, present_fcs_len,
120 dev_kfree_skb(origskb);
124 return remove_monitor_info(local, origskb, rtap_len);
127 if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) {
128 /* only need to expand headroom if necessary */
133 * This shouldn't trigger often because most devices have an
134 * RX header they pull before we get here, and that should
135 * be big enough for our radiotap information. We should
136 * probably export the length to drivers so that we can have
137 * them allocate enough headroom to start with.
139 if (skb_headroom(skb) < needed_headroom &&
140 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
146 * Need to make a copy and possibly remove radiotap header
147 * and FCS from the original.
149 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
151 origskb = remove_monitor_info(local, origskb, rtap_len);
157 /* if necessary, prepend radiotap information */
158 if (!(status->flag & RX_FLAG_RADIOTAP)) {
159 rtfixed = (void *) skb_push(skb, sizeof(*rtfixed));
160 rtap_len = sizeof(*rthdr) + sizeof(*rtfixed);
161 if (status->flag & RX_FLAG_TSFT) {
162 rttsft = (void *) skb_push(skb, sizeof(*rttsft));
165 rthdr = (void *) skb_push(skb, sizeof(*rthdr));
166 memset(rthdr, 0, sizeof(*rthdr));
167 memset(rtfixed, 0, sizeof(*rtfixed));
169 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
170 (1 << IEEE80211_RADIOTAP_RATE) |
171 (1 << IEEE80211_RADIOTAP_CHANNEL) |
172 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |
173 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
175 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
176 rtfixed->flags |= IEEE80211_RADIOTAP_F_FCS;
179 *rttsft = cpu_to_le64(status->mactime);
181 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
184 /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
185 rtfixed->rx_flags = 0;
187 (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
189 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
191 rate = ieee80211_get_rate(local, status->phymode,
194 rtfixed->rate = rate->rate / 5;
196 rtfixed->chan_freq = cpu_to_le16(status->freq);
198 if (status->phymode == MODE_IEEE80211A)
199 rtfixed->chan_flags =
200 cpu_to_le16(IEEE80211_CHAN_OFDM |
201 IEEE80211_CHAN_5GHZ);
203 rtfixed->chan_flags =
204 cpu_to_le16(IEEE80211_CHAN_DYN |
205 IEEE80211_CHAN_2GHZ);
207 rtfixed->antsignal = status->ssi;
208 rthdr->it_len = cpu_to_le16(rtap_len);
211 skb_reset_mac_header(skb);
212 skb->ip_summed = CHECKSUM_UNNECESSARY;
213 skb->pkt_type = PACKET_OTHERHOST;
214 skb->protocol = htons(ETH_P_802_2);
216 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
217 if (!netif_running(sdata->dev))
220 if (sdata->type != IEEE80211_IF_TYPE_MNTR)
224 skb2 = skb_clone(skb, GFP_ATOMIC);
226 skb2->dev = prev_dev;
231 prev_dev = sdata->dev;
232 sdata->dev->stats.rx_packets++;
233 sdata->dev->stats.rx_bytes += skb->len;
248 * these don't have dev/sdata fields in the rx data
249 * The sta value should also not be used because it may
250 * be NULL even though a STA (in IBSS mode) will be added.
253 static ieee80211_txrx_result
254 ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
256 u8 *data = rx->skb->data;
259 /* does the frame have a qos control field? */
260 if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
261 u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
262 /* frame has qos control */
263 tid = qc[0] & QOS_CONTROL_TID_MASK;
264 if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
265 rx->flags |= IEEE80211_TXRXD_RX_AMSDU;
267 rx->flags &= ~IEEE80211_TXRXD_RX_AMSDU;
269 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
270 /* Separate TID for management frames */
271 tid = NUM_RX_DATA_QUEUES - 1;
273 /* no qos control present */
274 tid = 0; /* 802.1d - Best Effort */
278 I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
279 /* only a debug counter, sta might not be assigned properly yet */
281 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
283 rx->u.rx.queue = tid;
284 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
285 * For now, set skb->priority to 0 for other cases. */
286 rx->skb->priority = (tid > 7) ? 0 : tid;
288 return TXRX_CONTINUE;
291 static ieee80211_txrx_result
292 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
294 struct ieee80211_local *local = rx->local;
295 struct sk_buff *skb = rx->skb;
296 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
297 u32 load = 0, hdrtime;
298 struct ieee80211_rate *rate;
299 struct ieee80211_hw_mode *mode = local->hw.conf.mode;
302 /* Estimate total channel use caused by this frame */
304 if (unlikely(mode->num_rates < 0))
305 return TXRX_CONTINUE;
307 rate = &mode->rates[0];
308 for (i = 0; i < mode->num_rates; i++) {
309 if (mode->rates[i].val == rx->u.rx.status->rate) {
310 rate = &mode->rates[i];
315 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
316 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
318 if (mode->mode == MODE_IEEE80211A ||
319 (mode->mode == MODE_IEEE80211G &&
320 rate->flags & IEEE80211_RATE_ERP))
321 hdrtime = CHAN_UTIL_HDR_SHORT;
323 hdrtime = CHAN_UTIL_HDR_LONG;
326 if (!is_multicast_ether_addr(hdr->addr1))
329 load += skb->len * rate->rate_inv;
331 /* Divide channel_use by 8 to avoid wrapping around the counter */
332 load >>= CHAN_UTIL_SHIFT;
333 local->channel_use_raw += load;
334 rx->u.rx.load = load;
336 return TXRX_CONTINUE;
339 ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
341 ieee80211_rx_h_parse_qos,
342 ieee80211_rx_h_load_stats,
348 static ieee80211_txrx_result
349 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
352 rx->sta->channel_use_raw += rx->u.rx.load;
353 rx->sdata->channel_use_raw += rx->u.rx.load;
354 return TXRX_CONTINUE;
357 static ieee80211_txrx_result
358 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
360 struct ieee80211_local *local = rx->local;
361 struct sk_buff *skb = rx->skb;
363 if (unlikely(local->sta_hw_scanning))
364 return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
366 if (unlikely(local->sta_sw_scanning)) {
367 /* drop all the other packets during a software scan anyway */
368 if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status)
374 if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
375 /* scanning finished during invoking of handlers */
376 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
380 return TXRX_CONTINUE;
383 static ieee80211_txrx_result
384 ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
386 struct ieee80211_hdr *hdr;
387 hdr = (struct ieee80211_hdr *) rx->skb->data;
389 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
390 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
391 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
392 rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
394 if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
395 rx->local->dot11FrameDuplicateCount++;
396 rx->sta->num_duplicates++;
400 rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
403 if (unlikely(rx->skb->len < 16)) {
404 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
408 /* Drop disallowed frame classes based on STA auth/assoc state;
409 * IEEE 802.11, Chap 5.5.
411 * 80211.o does filtering only based on association state, i.e., it
412 * drops Class 3 frames from not associated stations. hostapd sends
413 * deauth/disassoc frames when needed. In addition, hostapd is
414 * responsible for filtering on both auth and assoc states.
416 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
417 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
418 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
419 rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
420 (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
421 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
422 !(rx->fc & IEEE80211_FCTL_TODS) &&
423 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
424 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
425 /* Drop IBSS frames and frames for other hosts
433 return TXRX_CONTINUE;
437 static ieee80211_txrx_result
438 ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
440 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
443 ieee80211_txrx_result result = TXRX_DROP;
444 struct ieee80211_key *stakey = NULL;
449 * There are three types of keys:
451 * - PTK (pairwise keys)
452 * - STK (station-to-station pairwise keys)
454 * When selecting a key, we have to distinguish between multicast
455 * (including broadcast) and unicast frames, the latter can only
456 * use PTKs and STKs while the former always use GTKs. Unless, of
457 * course, actual WEP keys ("pre-RSNA") are used, then unicast
458 * frames can also use key indizes like GTKs. Hence, if we don't
459 * have a PTK/STK we check the key index for a WEP key.
461 * Note that in a regular BSS, multicast frames are sent by the
462 * AP only, associated stations unicast the frame to the AP first
463 * which then multicasts it on their behalf.
465 * There is also a slight problem in IBSS mode: GTKs are negotiated
466 * with each station, that is something we don't currently handle.
467 * The spec seems to expect that one negotiates the same key with
468 * every station but there's no such requirement; VLANs could be
472 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
473 return TXRX_CONTINUE;
476 * No point in finding a key and decrypting if the frame is neither
477 * addressed to us nor a multicast frame.
479 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
480 return TXRX_CONTINUE;
483 stakey = rcu_dereference(rx->sta->key);
485 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
489 * The device doesn't give us the IV so we won't be
490 * able to look up the key. That's ok though, we
491 * don't need to decrypt the frame, we just won't
492 * be able to keep statistics accurate.
493 * Except for key threshold notifications, should
494 * we somehow allow the driver to tell us which key
495 * the hardware used if this flag is set?
497 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
498 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
499 return TXRX_CONTINUE;
501 hdrlen = ieee80211_get_hdrlen(rx->fc);
503 if (rx->skb->len < 8 + hdrlen)
504 return TXRX_DROP; /* TODO: count this? */
507 * no need to call ieee80211_wep_get_keyidx,
508 * it verifies a bunch of things we've done already
510 keyidx = rx->skb->data[hdrlen + 3] >> 6;
512 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
515 * RSNA-protected unicast frames should always be sent with
516 * pairwise or station-to-station keys, but for WEP we allow
517 * using a key index as well.
519 if (rx->key && rx->key->conf.alg != ALG_WEP &&
520 !is_multicast_ether_addr(hdr->addr1))
525 rx->key->tx_rx_count++;
526 /* TODO: add threshold stuff again */
528 #ifdef CONFIG_MAC80211_DEBUG
530 printk(KERN_DEBUG "%s: RX protected frame,"
531 " but have no key\n", rx->dev->name);
532 #endif /* CONFIG_MAC80211_DEBUG */
536 /* Check for weak IVs if possible */
537 if (rx->sta && rx->key->conf.alg == ALG_WEP &&
538 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
539 (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
540 !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) &&
541 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
542 rx->sta->wep_weak_iv_count++;
544 switch (rx->key->conf.alg) {
546 result = ieee80211_crypto_wep_decrypt(rx);
549 result = ieee80211_crypto_tkip_decrypt(rx);
552 result = ieee80211_crypto_ccmp_decrypt(rx);
556 /* either the frame has been decrypted or will be dropped */
557 rx->u.rx.status->flag |= RX_FLAG_DECRYPTED;
562 static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
564 struct ieee80211_sub_if_data *sdata;
565 DECLARE_MAC_BUF(mac);
567 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
570 atomic_inc(&sdata->bss->num_sta_ps);
571 sta->flags |= WLAN_STA_PS;
573 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
574 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
575 dev->name, print_mac(mac, sta->addr), sta->aid);
576 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
579 static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
581 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
584 struct ieee80211_sub_if_data *sdata;
585 struct ieee80211_tx_packet_data *pkt_data;
586 DECLARE_MAC_BUF(mac);
588 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
590 atomic_dec(&sdata->bss->num_sta_ps);
591 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
593 if (!skb_queue_empty(&sta->ps_tx_buf)) {
594 if (local->ops->set_tim)
595 local->ops->set_tim(local_to_hw(local), sta->aid, 0);
597 bss_tim_clear(local, sdata->bss, sta->aid);
599 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
600 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
601 dev->name, print_mac(mac, sta->addr), sta->aid);
602 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
603 /* Send all buffered frames to the station */
604 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
605 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
607 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
610 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
611 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
612 local->total_ps_buffered--;
614 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
615 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
616 "since STA not sleeping anymore\n", dev->name,
617 print_mac(mac, sta->addr), sta->aid);
618 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
619 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
626 static ieee80211_txrx_result
627 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
629 struct sta_info *sta = rx->sta;
630 struct net_device *dev = rx->dev;
631 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
634 return TXRX_CONTINUE;
636 /* Update last_rx only for IBSS packets which are for the current
637 * BSSID to avoid keeping the current IBSS network alive in cases where
638 * other STAs are using different BSSID. */
639 if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
640 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
641 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
642 sta->last_rx = jiffies;
644 if (!is_multicast_ether_addr(hdr->addr1) ||
645 rx->sdata->type == IEEE80211_IF_TYPE_STA) {
646 /* Update last_rx only for unicast frames in order to prevent
647 * the Probe Request frames (the only broadcast frames from a
648 * STA in infrastructure mode) from keeping a connection alive.
650 sta->last_rx = jiffies;
653 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
654 return TXRX_CONTINUE;
657 sta->rx_bytes += rx->skb->len;
658 sta->last_rssi = rx->u.rx.status->ssi;
659 sta->last_signal = rx->u.rx.status->signal;
660 sta->last_noise = rx->u.rx.status->noise;
662 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
663 /* Change STA power saving mode only in the end of a frame
664 * exchange sequence */
665 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
666 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
667 else if (!(sta->flags & WLAN_STA_PS) &&
668 (rx->fc & IEEE80211_FCTL_PM))
669 ap_sta_ps_start(dev, sta);
672 /* Drop data::nullfunc frames silently, since they are used only to
673 * control station power saving mode. */
674 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
675 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
676 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
677 /* Update counter and free packet here to avoid counting this
678 * as a dropped packed. */
680 dev_kfree_skb(rx->skb);
684 return TXRX_CONTINUE;
685 } /* ieee80211_rx_h_sta_process */
687 static inline struct ieee80211_fragment_entry *
688 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
689 unsigned int frag, unsigned int seq, int rx_queue,
690 struct sk_buff **skb)
692 struct ieee80211_fragment_entry *entry;
695 idx = sdata->fragment_next;
696 entry = &sdata->fragments[sdata->fragment_next++];
697 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
698 sdata->fragment_next = 0;
700 if (!skb_queue_empty(&entry->skb_list)) {
701 #ifdef CONFIG_MAC80211_DEBUG
702 struct ieee80211_hdr *hdr =
703 (struct ieee80211_hdr *) entry->skb_list.next->data;
704 DECLARE_MAC_BUF(mac);
705 DECLARE_MAC_BUF(mac2);
706 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
707 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
708 "addr1=%s addr2=%s\n",
709 sdata->dev->name, idx,
710 jiffies - entry->first_frag_time, entry->seq,
711 entry->last_frag, print_mac(mac, hdr->addr1),
712 print_mac(mac2, hdr->addr2));
713 #endif /* CONFIG_MAC80211_DEBUG */
714 __skb_queue_purge(&entry->skb_list);
717 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
719 entry->first_frag_time = jiffies;
721 entry->rx_queue = rx_queue;
722 entry->last_frag = frag;
724 entry->extra_len = 0;
729 static inline struct ieee80211_fragment_entry *
730 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
731 u16 fc, unsigned int frag, unsigned int seq,
732 int rx_queue, struct ieee80211_hdr *hdr)
734 struct ieee80211_fragment_entry *entry;
737 idx = sdata->fragment_next;
738 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
739 struct ieee80211_hdr *f_hdr;
744 idx = IEEE80211_FRAGMENT_MAX - 1;
746 entry = &sdata->fragments[idx];
747 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
748 entry->rx_queue != rx_queue ||
749 entry->last_frag + 1 != frag)
752 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
753 f_fc = le16_to_cpu(f_hdr->frame_control);
755 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
756 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
757 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
760 if (entry->first_frag_time + 2 * HZ < jiffies) {
761 __skb_queue_purge(&entry->skb_list);
770 static ieee80211_txrx_result
771 ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
773 struct ieee80211_hdr *hdr;
775 unsigned int frag, seq;
776 struct ieee80211_fragment_entry *entry;
778 DECLARE_MAC_BUF(mac);
780 hdr = (struct ieee80211_hdr *) rx->skb->data;
781 sc = le16_to_cpu(hdr->seq_ctrl);
782 frag = sc & IEEE80211_SCTL_FRAG;
784 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
785 (rx->skb)->len < 24 ||
786 is_multicast_ether_addr(hdr->addr1))) {
790 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
792 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
795 /* This is the first fragment of a new frame. */
796 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
797 rx->u.rx.queue, &(rx->skb));
798 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
799 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
800 /* Store CCMP PN so that we can verify that the next
801 * fragment has a sequential PN value. */
803 memcpy(entry->last_pn,
804 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
810 /* This is a fragment for a frame that should already be pending in
811 * fragment cache. Add this fragment to the end of the pending entry.
813 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
814 rx->u.rx.queue, hdr);
816 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
820 /* Verify that MPDUs within one MSDU have sequential PN values.
821 * (IEEE 802.11i, 8.3.3.4.5) */
824 u8 pn[CCMP_PN_LEN], *rpn;
825 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
827 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
828 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
833 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
834 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
836 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
838 " PN=%02x%02x%02x%02x%02x%02x "
839 "(expected %02x%02x%02x%02x%02x%02x)\n",
840 rx->dev->name, print_mac(mac, hdr->addr2),
841 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
842 rpn[5], pn[0], pn[1], pn[2], pn[3],
846 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
849 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
850 __skb_queue_tail(&entry->skb_list, rx->skb);
851 entry->last_frag = frag;
852 entry->extra_len += rx->skb->len;
853 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
858 rx->skb = __skb_dequeue(&entry->skb_list);
859 if (skb_tailroom(rx->skb) < entry->extra_len) {
860 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
861 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
863 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
864 __skb_queue_purge(&entry->skb_list);
868 while ((skb = __skb_dequeue(&entry->skb_list))) {
869 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
873 /* Complete frame has been reassembled - process it now */
874 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
878 rx->sta->rx_packets++;
879 if (is_multicast_ether_addr(hdr->addr1))
880 rx->local->dot11MulticastReceivedFrameCount++;
882 ieee80211_led_rx(rx->local);
883 return TXRX_CONTINUE;
886 static ieee80211_txrx_result
887 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
889 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
892 DECLARE_MAC_BUF(mac);
894 if (likely(!rx->sta ||
895 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
896 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
897 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
898 return TXRX_CONTINUE;
900 if ((sdata->type != IEEE80211_IF_TYPE_AP) &&
901 (sdata->type != IEEE80211_IF_TYPE_VLAN))
904 skb = skb_dequeue(&rx->sta->tx_filtered);
906 skb = skb_dequeue(&rx->sta->ps_tx_buf);
908 rx->local->total_ps_buffered--;
910 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
911 skb_queue_empty(&rx->sta->ps_tx_buf);
914 struct ieee80211_hdr *hdr =
915 (struct ieee80211_hdr *) skb->data;
917 /* tell TX path to send one frame even though the STA may
918 * still remain is PS mode after this frame exchange */
921 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
922 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
923 print_mac(mac, rx->sta->addr), rx->sta->aid,
924 skb_queue_len(&rx->sta->ps_tx_buf));
925 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
927 /* Use MoreData flag to indicate whether there are more
928 * buffered frames for this STA */
929 if (no_pending_pkts) {
930 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
931 rx->sta->flags &= ~WLAN_STA_TIM;
933 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
937 if (no_pending_pkts) {
938 if (rx->local->ops->set_tim)
939 rx->local->ops->set_tim(local_to_hw(rx->local),
942 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
944 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
945 } else if (!rx->u.rx.sent_ps_buffered) {
946 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
947 "though there is no buffered frames for it\n",
948 rx->dev->name, print_mac(mac, rx->sta->addr));
949 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
953 /* Free PS Poll skb here instead of returning TXRX_DROP that would
954 * count as an dropped frame. */
955 dev_kfree_skb(rx->skb);
960 static ieee80211_txrx_result
961 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
964 u8 *data = rx->skb->data;
965 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
967 if (!WLAN_FC_IS_QOS_DATA(fc))
968 return TXRX_CONTINUE;
970 /* remove the qos control field, update frame type and meta-data */
971 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
972 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
973 /* change frame type to non QOS */
974 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
975 hdr->frame_control = cpu_to_le16(fc);
977 return TXRX_CONTINUE;
981 ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx)
983 if (unlikely(rx->sdata->ieee802_1x_pac &&
984 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)))) {
985 #ifdef CONFIG_MAC80211_DEBUG
986 printk(KERN_DEBUG "%s: dropped frame "
987 "(unauthorized port)\n", rx->dev->name);
988 #endif /* CONFIG_MAC80211_DEBUG */
996 ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx)
999 * Pass through unencrypted frames if the hardware has
1000 * decrypted them already.
1002 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
1005 /* Drop unencrypted frames if key is set. */
1006 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
1007 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
1008 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
1009 (rx->key || rx->sdata->drop_unencrypted))) {
1010 if (net_ratelimit())
1011 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
1012 "encryption\n", rx->dev->name);
1019 ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
1021 struct net_device *dev = rx->dev;
1022 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
1023 u16 fc, hdrlen, ethertype;
1027 struct sk_buff *skb = rx->skb;
1028 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1029 DECLARE_MAC_BUF(mac);
1030 DECLARE_MAC_BUF(mac2);
1031 DECLARE_MAC_BUF(mac3);
1032 DECLARE_MAC_BUF(mac4);
1036 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1039 hdrlen = ieee80211_get_hdrlen(fc);
1041 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1043 * IEEE 802.11 address fields:
1044 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1045 * 0 0 DA SA BSSID n/a
1046 * 0 1 DA BSSID SA n/a
1047 * 1 0 BSSID SA DA n/a
1051 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
1052 case IEEE80211_FCTL_TODS:
1054 memcpy(dst, hdr->addr3, ETH_ALEN);
1055 memcpy(src, hdr->addr2, ETH_ALEN);
1057 if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
1058 sdata->type != IEEE80211_IF_TYPE_VLAN)) {
1059 if (net_ratelimit())
1060 printk(KERN_DEBUG "%s: dropped ToDS frame "
1061 "(BSSID=%s SA=%s DA=%s)\n",
1063 print_mac(mac, hdr->addr1),
1064 print_mac(mac2, hdr->addr2),
1065 print_mac(mac3, hdr->addr3));
1069 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1071 memcpy(dst, hdr->addr3, ETH_ALEN);
1072 memcpy(src, hdr->addr4, ETH_ALEN);
1074 if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
1075 if (net_ratelimit())
1076 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
1077 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1079 print_mac(mac, hdr->addr1),
1080 print_mac(mac2, hdr->addr2),
1081 print_mac(mac3, hdr->addr3),
1082 print_mac(mac4, hdr->addr4));
1086 case IEEE80211_FCTL_FROMDS:
1088 memcpy(dst, hdr->addr1, ETH_ALEN);
1089 memcpy(src, hdr->addr3, ETH_ALEN);
1091 if (sdata->type != IEEE80211_IF_TYPE_STA ||
1092 (is_multicast_ether_addr(dst) &&
1093 !compare_ether_addr(src, dev->dev_addr)))
1098 memcpy(dst, hdr->addr1, ETH_ALEN);
1099 memcpy(src, hdr->addr2, ETH_ALEN);
1101 if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
1102 if (net_ratelimit()) {
1103 printk(KERN_DEBUG "%s: dropped IBSS frame "
1104 "(DA=%s SA=%s BSSID=%s)\n",
1106 print_mac(mac, hdr->addr1),
1107 print_mac(mac2, hdr->addr2),
1108 print_mac(mac3, hdr->addr3));
1115 if (unlikely(skb->len - hdrlen < 8)) {
1116 if (net_ratelimit()) {
1117 printk(KERN_DEBUG "%s: RX too short data frame "
1118 "payload\n", dev->name);
1123 payload = skb->data + hdrlen;
1124 ethertype = (payload[6] << 8) | payload[7];
1126 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1127 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1128 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1129 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1130 * replace EtherType */
1131 skb_pull(skb, hdrlen + 6);
1132 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1133 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1135 struct ethhdr *ehdr;
1138 skb_pull(skb, hdrlen);
1139 len = htons(skb->len);
1140 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1141 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1142 memcpy(ehdr->h_source, src, ETH_ALEN);
1143 ehdr->h_proto = len;
1149 * requires that rx->skb is a frame with ethernet header
1151 static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx)
1153 static const u8 pae_group_addr[ETH_ALEN]
1154 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1155 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1158 * Allow EAPOL frames to us/the PAE group address regardless
1159 * of whether the frame was encrypted or not.
1161 if (ehdr->h_proto == htons(ETH_P_PAE) &&
1162 (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 ||
1163 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1166 if (ieee80211_802_1x_port_control(rx) ||
1167 ieee80211_drop_unencrypted(rx))
1174 * requires that rx->skb is a frame with ethernet header
1177 ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1179 struct net_device *dev = rx->dev;
1180 struct ieee80211_local *local = rx->local;
1181 struct sk_buff *skb, *xmit_skb;
1182 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1183 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1184 struct sta_info *dsta;
1189 if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP ||
1190 sdata->type == IEEE80211_IF_TYPE_VLAN) &&
1191 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
1192 if (is_multicast_ether_addr(ehdr->h_dest)) {
1194 * send multicast frames both to higher layers in
1195 * local net stack and back to the wireless medium
1197 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1198 if (!xmit_skb && net_ratelimit())
1199 printk(KERN_DEBUG "%s: failed to clone "
1200 "multicast frame\n", dev->name);
1202 dsta = sta_info_get(local, skb->data);
1203 if (dsta && dsta->dev == dev) {
1205 * The destination station is associated to
1206 * this AP (in this VLAN), so send the frame
1207 * directly to it and do not pass it to local
1219 /* deliver to local stack */
1220 skb->protocol = eth_type_trans(skb, dev);
1221 memset(skb->cb, 0, sizeof(skb->cb));
1226 /* send to wireless media */
1227 xmit_skb->protocol = htons(ETH_P_802_3);
1228 skb_reset_network_header(xmit_skb);
1229 skb_reset_mac_header(xmit_skb);
1230 dev_queue_xmit(xmit_skb);
1234 static ieee80211_txrx_result
1235 ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1237 struct net_device *dev = rx->dev;
1238 struct ieee80211_local *local = rx->local;
1241 struct sk_buff *skb = rx->skb, *frame = NULL;
1242 const struct ethhdr *eth;
1246 DECLARE_MAC_BUF(mac);
1249 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1250 return TXRX_CONTINUE;
1252 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1255 if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU))
1256 return TXRX_CONTINUE;
1258 err = ieee80211_data_to_8023(rx);
1264 dev->stats.rx_packets++;
1265 dev->stats.rx_bytes += skb->len;
1267 /* skip the wrapping header */
1268 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
1272 while (skb != frame) {
1274 __be16 len = eth->h_proto;
1275 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
1277 remaining = skb->len;
1278 memcpy(dst, eth->h_dest, ETH_ALEN);
1279 memcpy(src, eth->h_source, ETH_ALEN);
1281 padding = ((4 - subframe_len) & 0x3);
1282 /* the last MSDU has no padding */
1283 if (subframe_len > remaining) {
1284 printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
1288 skb_pull(skb, sizeof(struct ethhdr));
1289 /* if last subframe reuse skb */
1290 if (remaining <= subframe_len + padding)
1293 frame = dev_alloc_skb(local->hw.extra_tx_headroom +
1299 skb_reserve(frame, local->hw.extra_tx_headroom +
1300 sizeof(struct ethhdr));
1301 memcpy(skb_put(frame, ntohs(len)), skb->data,
1304 eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
1307 printk(KERN_DEBUG "%s: wrong buffer size ",
1309 dev_kfree_skb(frame);
1314 skb_reset_network_header(frame);
1316 frame->priority = skb->priority;
1319 payload = frame->data;
1320 ethertype = (payload[6] << 8) | payload[7];
1322 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1323 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1324 compare_ether_addr(payload,
1325 bridge_tunnel_header) == 0)) {
1326 /* remove RFC1042 or Bridge-Tunnel
1327 * encapsulation and replace EtherType */
1329 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1330 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1332 memcpy(skb_push(frame, sizeof(__be16)),
1333 &len, sizeof(__be16));
1334 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1335 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1338 if (!ieee80211_frame_allowed(rx)) {
1339 if (skb == frame) /* last frame */
1341 dev_kfree_skb(frame);
1345 ieee80211_deliver_skb(rx);
1351 static ieee80211_txrx_result
1352 ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
1354 struct net_device *dev = rx->dev;
1359 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1360 return TXRX_CONTINUE;
1362 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1365 err = ieee80211_data_to_8023(rx);
1369 if (!ieee80211_frame_allowed(rx))
1374 dev->stats.rx_packets++;
1375 dev->stats.rx_bytes += rx->skb->len;
1377 ieee80211_deliver_skb(rx);
1382 static ieee80211_txrx_result
1383 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1385 struct ieee80211_sub_if_data *sdata;
1387 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
1390 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1391 if ((sdata->type == IEEE80211_IF_TYPE_STA ||
1392 sdata->type == IEEE80211_IF_TYPE_IBSS) &&
1393 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
1394 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
1401 static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1402 struct ieee80211_local *local,
1403 ieee80211_rx_handler *handlers,
1404 struct ieee80211_txrx_data *rx,
1405 struct sta_info *sta)
1407 ieee80211_rx_handler *handler;
1408 ieee80211_txrx_result res = TXRX_DROP;
1410 for (handler = handlers; *handler != NULL; handler++) {
1411 res = (*handler)(rx);
1417 I802_DEBUG_INC(local->rx_handlers_drop);
1422 I802_DEBUG_INC(local->rx_handlers_queued);
1428 if (res == TXRX_DROP)
1429 dev_kfree_skb(rx->skb);
1433 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1434 ieee80211_rx_handler *handlers,
1435 struct ieee80211_txrx_data *rx,
1436 struct sta_info *sta)
1438 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1440 dev_kfree_skb(rx->skb);
1443 static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1444 struct ieee80211_hdr *hdr,
1445 struct sta_info *sta,
1446 struct ieee80211_txrx_data *rx)
1449 DECLARE_MAC_BUF(mac);
1450 DECLARE_MAC_BUF(mac2);
1452 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1453 if (rx->skb->len >= hdrlen + 4)
1454 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1458 if (net_ratelimit())
1459 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
1460 "failure from %s to %s keyidx=%d\n",
1461 dev->name, print_mac(mac, hdr->addr2),
1462 print_mac(mac2, hdr->addr1), keyidx);
1466 * Some hardware seem to generate incorrect Michael MIC
1467 * reports; ignore them to avoid triggering countermeasures.
1469 if (net_ratelimit())
1470 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1471 "error for unknown address %s\n",
1472 dev->name, print_mac(mac, hdr->addr2));
1476 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
1477 if (net_ratelimit())
1478 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1479 "error for a frame with no PROTECTED flag (src "
1480 "%s)\n", dev->name, print_mac(mac, hdr->addr2));
1484 if (rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) {
1486 * APs with pairwise keys should never receive Michael MIC
1487 * errors for non-zero keyidx because these are reserved for
1488 * group keys and only the AP is sending real multicast
1489 * frames in the BSS.
1491 if (net_ratelimit())
1492 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1493 "a frame with non-zero keyidx (%d)"
1494 " (src %s)\n", dev->name, keyidx,
1495 print_mac(mac, hdr->addr2));
1499 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1500 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1501 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
1502 if (net_ratelimit())
1503 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1504 "error for a frame that cannot be encrypted "
1505 "(fc=0x%04x) (src %s)\n",
1506 dev->name, rx->fc, print_mac(mac, hdr->addr2));
1510 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
1512 dev_kfree_skb(rx->skb);
1516 ieee80211_rx_handler ieee80211_rx_handlers[] =
1518 ieee80211_rx_h_if_stats,
1519 ieee80211_rx_h_passive_scan,
1520 ieee80211_rx_h_check,
1521 ieee80211_rx_h_decrypt,
1522 ieee80211_rx_h_sta_process,
1523 ieee80211_rx_h_defragment,
1524 ieee80211_rx_h_ps_poll,
1525 ieee80211_rx_h_michael_mic_verify,
1526 /* this must be after decryption - so header is counted in MPDU mic
1527 * must be before pae and data, so QOS_DATA format frames
1528 * are not passed to user space by these functions
1530 ieee80211_rx_h_remove_qos_control,
1531 ieee80211_rx_h_amsdu,
1532 ieee80211_rx_h_data,
1533 ieee80211_rx_h_mgmt,
1537 /* main receive path */
1539 static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1540 u8 *bssid, struct ieee80211_txrx_data *rx,
1541 struct ieee80211_hdr *hdr)
1543 int multicast = is_multicast_ether_addr(hdr->addr1);
1545 switch (sdata->type) {
1546 case IEEE80211_IF_TYPE_STA:
1549 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1550 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1552 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1553 } else if (!multicast &&
1554 compare_ether_addr(sdata->dev->dev_addr,
1556 if (!(sdata->dev->flags & IFF_PROMISC))
1558 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1561 case IEEE80211_IF_TYPE_IBSS:
1564 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1565 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1567 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1568 } else if (!multicast &&
1569 compare_ether_addr(sdata->dev->dev_addr,
1571 if (!(sdata->dev->flags & IFF_PROMISC))
1573 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1574 } else if (!rx->sta)
1575 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1578 case IEEE80211_IF_TYPE_VLAN:
1579 case IEEE80211_IF_TYPE_AP:
1581 if (compare_ether_addr(sdata->dev->dev_addr,
1584 } else if (!ieee80211_bssid_match(bssid,
1585 sdata->dev->dev_addr)) {
1586 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1588 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1590 if (sdata->dev == sdata->local->mdev &&
1591 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1592 /* do not receive anything via
1593 * master device when not scanning */
1596 case IEEE80211_IF_TYPE_WDS:
1598 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1600 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1603 case IEEE80211_IF_TYPE_MNTR:
1604 /* take everything */
1606 case IEEE80211_IF_TYPE_INVALID:
1607 /* should never get here */
1616 * This is the receive path handler. It is called by a low level driver when an
1617 * 802.11 MPDU is received from the hardware.
1619 void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1620 struct ieee80211_rx_status *status)
1622 struct ieee80211_local *local = hw_to_local(hw);
1623 struct ieee80211_sub_if_data *sdata;
1624 struct sta_info *sta;
1625 struct ieee80211_hdr *hdr;
1626 struct ieee80211_txrx_data rx;
1629 struct ieee80211_sub_if_data *prev = NULL;
1630 struct sk_buff *skb_new;
1635 * key references and virtual interfaces are protected using RCU
1636 * and this requires that we are in a read-side RCU section during
1637 * receive processing
1642 * Frames with failed FCS/PLCP checksum are not returned,
1643 * all other frames are returned without radiotap header
1644 * if it was previously present.
1645 * Also, frames with less than 16 bytes are dropped.
1647 skb = ieee80211_rx_monitor(local, skb, status);
1653 hdr = (struct ieee80211_hdr *) skb->data;
1654 memset(&rx, 0, sizeof(rx));
1658 rx.u.rx.status = status;
1659 rx.fc = le16_to_cpu(hdr->frame_control);
1660 type = rx.fc & IEEE80211_FCTL_FTYPE;
1663 * Drivers are required to align the payload data to a four-byte
1664 * boundary, so the last two bits of the address where it starts
1665 * may not be set. The header is required to be directly before
1666 * the payload data, padding like atheros hardware adds which is
1667 * inbetween the 802.11 header and the payload is not supported,
1668 * the driver is required to move the 802.11 header further back
1671 hdrlen = ieee80211_get_hdrlen(rx.fc);
1672 WARN_ON_ONCE(((unsigned long)(skb->data + hdrlen)) & 3);
1674 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
1675 local->dot11ReceivedFragmentCount++;
1677 sta = rx.sta = sta_info_get(local, hdr->addr2);
1679 rx.dev = rx.sta->dev;
1680 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1683 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1684 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
1688 if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
1689 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
1691 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
1692 sta) != TXRX_CONTINUE)
1696 if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) &&
1697 !atomic_read(&local->iff_promiscs) &&
1698 !is_multicast_ether_addr(hdr->addr1)) {
1699 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1700 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
1707 bssid = ieee80211_get_bssid(hdr, skb->len);
1709 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1710 if (!netif_running(sdata->dev))
1713 if (sdata->type == IEEE80211_IF_TYPE_MNTR)
1716 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1717 prepres = prepare_for_handlers(sdata, bssid, &rx, hdr);
1718 /* prepare_for_handlers can change sta */
1725 * frame is destined for this interface, but if it's not
1726 * also for the previous one we handle that after the
1727 * loop to avoid copying the SKB once too much
1736 * frame was destined for the previous interface
1737 * so invoke RX handlers for it
1740 skb_new = skb_copy(skb, GFP_ATOMIC);
1742 if (net_ratelimit())
1743 printk(KERN_DEBUG "%s: failed to copy "
1744 "multicast frame for %s",
1745 wiphy_name(local->hw.wiphy),
1752 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1760 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1771 EXPORT_SYMBOL(__ieee80211_rx);
1773 /* This is a version of the rx handler that can be called from hard irq
1774 * context. Post the skb on the queue and schedule the tasklet */
1775 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
1776 struct ieee80211_rx_status *status)
1778 struct ieee80211_local *local = hw_to_local(hw);
1780 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
1782 skb->dev = local->mdev;
1783 /* copy status into skb->cb for use by tasklet */
1784 memcpy(skb->cb, status, sizeof(*status));
1785 skb->pkt_type = IEEE80211_RX_MSG;
1786 skb_queue_tail(&local->skb_queue, skb);
1787 tasklet_schedule(&local->tasklet);
1789 EXPORT_SYMBOL(ieee80211_rx_irqsafe);