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;
292 u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
294 struct ieee80211_rx_status *status)
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 == 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;
338 ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
340 ieee80211_rx_h_parse_qos,
346 static ieee80211_txrx_result
347 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
350 rx->sta->channel_use_raw += rx->u.rx.load;
351 rx->sdata->channel_use_raw += rx->u.rx.load;
352 return TXRX_CONTINUE;
355 static ieee80211_txrx_result
356 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
358 struct ieee80211_local *local = rx->local;
359 struct sk_buff *skb = rx->skb;
361 if (unlikely(local->sta_hw_scanning))
362 return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
364 if (unlikely(local->sta_sw_scanning)) {
365 /* drop all the other packets during a software scan anyway */
366 if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status)
372 if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
373 /* scanning finished during invoking of handlers */
374 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
378 return TXRX_CONTINUE;
381 static ieee80211_txrx_result
382 ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
384 struct ieee80211_hdr *hdr;
385 hdr = (struct ieee80211_hdr *) rx->skb->data;
387 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
388 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
389 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
390 rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
392 if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
393 rx->local->dot11FrameDuplicateCount++;
394 rx->sta->num_duplicates++;
398 rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
401 if (unlikely(rx->skb->len < 16)) {
402 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
406 /* Drop disallowed frame classes based on STA auth/assoc state;
407 * IEEE 802.11, Chap 5.5.
409 * 80211.o does filtering only based on association state, i.e., it
410 * drops Class 3 frames from not associated stations. hostapd sends
411 * deauth/disassoc frames when needed. In addition, hostapd is
412 * responsible for filtering on both auth and assoc states.
414 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
415 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
416 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
417 rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
418 (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
419 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
420 !(rx->fc & IEEE80211_FCTL_TODS) &&
421 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
422 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
423 /* Drop IBSS frames and frames for other hosts
431 return TXRX_CONTINUE;
435 static ieee80211_txrx_result
436 ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
438 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
441 ieee80211_txrx_result result = TXRX_DROP;
442 struct ieee80211_key *stakey = NULL;
447 * There are three types of keys:
449 * - PTK (pairwise keys)
450 * - STK (station-to-station pairwise keys)
452 * When selecting a key, we have to distinguish between multicast
453 * (including broadcast) and unicast frames, the latter can only
454 * use PTKs and STKs while the former always use GTKs. Unless, of
455 * course, actual WEP keys ("pre-RSNA") are used, then unicast
456 * frames can also use key indizes like GTKs. Hence, if we don't
457 * have a PTK/STK we check the key index for a WEP key.
459 * Note that in a regular BSS, multicast frames are sent by the
460 * AP only, associated stations unicast the frame to the AP first
461 * which then multicasts it on their behalf.
463 * There is also a slight problem in IBSS mode: GTKs are negotiated
464 * with each station, that is something we don't currently handle.
465 * The spec seems to expect that one negotiates the same key with
466 * every station but there's no such requirement; VLANs could be
470 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
471 return TXRX_CONTINUE;
474 * No point in finding a key and decrypting if the frame is neither
475 * addressed to us nor a multicast frame.
477 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
478 return TXRX_CONTINUE;
481 stakey = rcu_dereference(rx->sta->key);
483 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
487 * The device doesn't give us the IV so we won't be
488 * able to look up the key. That's ok though, we
489 * don't need to decrypt the frame, we just won't
490 * be able to keep statistics accurate.
491 * Except for key threshold notifications, should
492 * we somehow allow the driver to tell us which key
493 * the hardware used if this flag is set?
495 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
496 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
497 return TXRX_CONTINUE;
499 hdrlen = ieee80211_get_hdrlen(rx->fc);
501 if (rx->skb->len < 8 + hdrlen)
502 return TXRX_DROP; /* TODO: count this? */
505 * no need to call ieee80211_wep_get_keyidx,
506 * it verifies a bunch of things we've done already
508 keyidx = rx->skb->data[hdrlen + 3] >> 6;
510 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
513 * RSNA-protected unicast frames should always be sent with
514 * pairwise or station-to-station keys, but for WEP we allow
515 * using a key index as well.
517 if (rx->key && rx->key->conf.alg != ALG_WEP &&
518 !is_multicast_ether_addr(hdr->addr1))
523 rx->key->tx_rx_count++;
524 /* TODO: add threshold stuff again */
526 #ifdef CONFIG_MAC80211_DEBUG
528 printk(KERN_DEBUG "%s: RX protected frame,"
529 " but have no key\n", rx->dev->name);
530 #endif /* CONFIG_MAC80211_DEBUG */
534 /* Check for weak IVs if possible */
535 if (rx->sta && rx->key->conf.alg == ALG_WEP &&
536 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
537 (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
538 !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) &&
539 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
540 rx->sta->wep_weak_iv_count++;
542 switch (rx->key->conf.alg) {
544 result = ieee80211_crypto_wep_decrypt(rx);
547 result = ieee80211_crypto_tkip_decrypt(rx);
550 result = ieee80211_crypto_ccmp_decrypt(rx);
554 /* either the frame has been decrypted or will be dropped */
555 rx->u.rx.status->flag |= RX_FLAG_DECRYPTED;
560 static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
562 struct ieee80211_sub_if_data *sdata;
563 DECLARE_MAC_BUF(mac);
565 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
568 atomic_inc(&sdata->bss->num_sta_ps);
569 sta->flags |= WLAN_STA_PS;
571 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
572 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
573 dev->name, print_mac(mac, sta->addr), sta->aid);
574 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
577 static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
579 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
582 struct ieee80211_sub_if_data *sdata;
583 struct ieee80211_tx_packet_data *pkt_data;
584 DECLARE_MAC_BUF(mac);
586 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
588 atomic_dec(&sdata->bss->num_sta_ps);
589 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
591 if (!skb_queue_empty(&sta->ps_tx_buf)) {
592 if (local->ops->set_tim)
593 local->ops->set_tim(local_to_hw(local), sta->aid, 0);
595 bss_tim_clear(local, sdata->bss, sta->aid);
597 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
598 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
599 dev->name, print_mac(mac, sta->addr), sta->aid);
600 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
601 /* Send all buffered frames to the station */
602 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
603 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
605 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
608 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
609 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
610 local->total_ps_buffered--;
612 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
613 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
614 "since STA not sleeping anymore\n", dev->name,
615 print_mac(mac, sta->addr), sta->aid);
616 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
617 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
624 static ieee80211_txrx_result
625 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
627 struct sta_info *sta = rx->sta;
628 struct net_device *dev = rx->dev;
629 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
632 return TXRX_CONTINUE;
634 /* Update last_rx only for IBSS packets which are for the current
635 * BSSID to avoid keeping the current IBSS network alive in cases where
636 * other STAs are using different BSSID. */
637 if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
638 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
639 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
640 sta->last_rx = jiffies;
642 if (!is_multicast_ether_addr(hdr->addr1) ||
643 rx->sdata->type == IEEE80211_IF_TYPE_STA) {
644 /* Update last_rx only for unicast frames in order to prevent
645 * the Probe Request frames (the only broadcast frames from a
646 * STA in infrastructure mode) from keeping a connection alive.
648 sta->last_rx = jiffies;
651 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
652 return TXRX_CONTINUE;
655 sta->rx_bytes += rx->skb->len;
656 sta->last_rssi = rx->u.rx.status->ssi;
657 sta->last_signal = rx->u.rx.status->signal;
658 sta->last_noise = rx->u.rx.status->noise;
660 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
661 /* Change STA power saving mode only in the end of a frame
662 * exchange sequence */
663 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
664 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
665 else if (!(sta->flags & WLAN_STA_PS) &&
666 (rx->fc & IEEE80211_FCTL_PM))
667 ap_sta_ps_start(dev, sta);
670 /* Drop data::nullfunc frames silently, since they are used only to
671 * control station power saving mode. */
672 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
673 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
674 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
675 /* Update counter and free packet here to avoid counting this
676 * as a dropped packed. */
678 dev_kfree_skb(rx->skb);
682 return TXRX_CONTINUE;
683 } /* ieee80211_rx_h_sta_process */
685 static inline struct ieee80211_fragment_entry *
686 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
687 unsigned int frag, unsigned int seq, int rx_queue,
688 struct sk_buff **skb)
690 struct ieee80211_fragment_entry *entry;
693 idx = sdata->fragment_next;
694 entry = &sdata->fragments[sdata->fragment_next++];
695 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
696 sdata->fragment_next = 0;
698 if (!skb_queue_empty(&entry->skb_list)) {
699 #ifdef CONFIG_MAC80211_DEBUG
700 struct ieee80211_hdr *hdr =
701 (struct ieee80211_hdr *) entry->skb_list.next->data;
702 DECLARE_MAC_BUF(mac);
703 DECLARE_MAC_BUF(mac2);
704 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
705 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
706 "addr1=%s addr2=%s\n",
707 sdata->dev->name, idx,
708 jiffies - entry->first_frag_time, entry->seq,
709 entry->last_frag, print_mac(mac, hdr->addr1),
710 print_mac(mac2, hdr->addr2));
711 #endif /* CONFIG_MAC80211_DEBUG */
712 __skb_queue_purge(&entry->skb_list);
715 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
717 entry->first_frag_time = jiffies;
719 entry->rx_queue = rx_queue;
720 entry->last_frag = frag;
722 entry->extra_len = 0;
727 static inline struct ieee80211_fragment_entry *
728 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
729 u16 fc, unsigned int frag, unsigned int seq,
730 int rx_queue, struct ieee80211_hdr *hdr)
732 struct ieee80211_fragment_entry *entry;
735 idx = sdata->fragment_next;
736 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
737 struct ieee80211_hdr *f_hdr;
742 idx = IEEE80211_FRAGMENT_MAX - 1;
744 entry = &sdata->fragments[idx];
745 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
746 entry->rx_queue != rx_queue ||
747 entry->last_frag + 1 != frag)
750 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
751 f_fc = le16_to_cpu(f_hdr->frame_control);
753 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
754 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
755 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
758 if (entry->first_frag_time + 2 * HZ < jiffies) {
759 __skb_queue_purge(&entry->skb_list);
768 static ieee80211_txrx_result
769 ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
771 struct ieee80211_hdr *hdr;
773 unsigned int frag, seq;
774 struct ieee80211_fragment_entry *entry;
776 DECLARE_MAC_BUF(mac);
778 hdr = (struct ieee80211_hdr *) rx->skb->data;
779 sc = le16_to_cpu(hdr->seq_ctrl);
780 frag = sc & IEEE80211_SCTL_FRAG;
782 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
783 (rx->skb)->len < 24 ||
784 is_multicast_ether_addr(hdr->addr1))) {
788 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
790 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
793 /* This is the first fragment of a new frame. */
794 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
795 rx->u.rx.queue, &(rx->skb));
796 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
797 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
798 /* Store CCMP PN so that we can verify that the next
799 * fragment has a sequential PN value. */
801 memcpy(entry->last_pn,
802 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
808 /* This is a fragment for a frame that should already be pending in
809 * fragment cache. Add this fragment to the end of the pending entry.
811 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
812 rx->u.rx.queue, hdr);
814 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
818 /* Verify that MPDUs within one MSDU have sequential PN values.
819 * (IEEE 802.11i, 8.3.3.4.5) */
822 u8 pn[CCMP_PN_LEN], *rpn;
823 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
825 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
826 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
831 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
832 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
834 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
836 " PN=%02x%02x%02x%02x%02x%02x "
837 "(expected %02x%02x%02x%02x%02x%02x)\n",
838 rx->dev->name, print_mac(mac, hdr->addr2),
839 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
840 rpn[5], pn[0], pn[1], pn[2], pn[3],
844 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
847 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
848 __skb_queue_tail(&entry->skb_list, rx->skb);
849 entry->last_frag = frag;
850 entry->extra_len += rx->skb->len;
851 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
856 rx->skb = __skb_dequeue(&entry->skb_list);
857 if (skb_tailroom(rx->skb) < entry->extra_len) {
858 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
859 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
861 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
862 __skb_queue_purge(&entry->skb_list);
866 while ((skb = __skb_dequeue(&entry->skb_list))) {
867 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
871 /* Complete frame has been reassembled - process it now */
872 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
876 rx->sta->rx_packets++;
877 if (is_multicast_ether_addr(hdr->addr1))
878 rx->local->dot11MulticastReceivedFrameCount++;
880 ieee80211_led_rx(rx->local);
881 return TXRX_CONTINUE;
884 static ieee80211_txrx_result
885 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
887 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
890 DECLARE_MAC_BUF(mac);
892 if (likely(!rx->sta ||
893 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
894 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
895 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
896 return TXRX_CONTINUE;
898 if ((sdata->type != IEEE80211_IF_TYPE_AP) &&
899 (sdata->type != IEEE80211_IF_TYPE_VLAN))
902 skb = skb_dequeue(&rx->sta->tx_filtered);
904 skb = skb_dequeue(&rx->sta->ps_tx_buf);
906 rx->local->total_ps_buffered--;
908 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
909 skb_queue_empty(&rx->sta->ps_tx_buf);
912 struct ieee80211_hdr *hdr =
913 (struct ieee80211_hdr *) skb->data;
915 /* tell TX path to send one frame even though the STA may
916 * still remain is PS mode after this frame exchange */
919 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
920 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
921 print_mac(mac, rx->sta->addr), rx->sta->aid,
922 skb_queue_len(&rx->sta->ps_tx_buf));
923 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
925 /* Use MoreData flag to indicate whether there are more
926 * buffered frames for this STA */
927 if (no_pending_pkts) {
928 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
929 rx->sta->flags &= ~WLAN_STA_TIM;
931 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
935 if (no_pending_pkts) {
936 if (rx->local->ops->set_tim)
937 rx->local->ops->set_tim(local_to_hw(rx->local),
940 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
942 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
943 } else if (!rx->u.rx.sent_ps_buffered) {
944 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
945 "though there is no buffered frames for it\n",
946 rx->dev->name, print_mac(mac, rx->sta->addr));
947 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
951 /* Free PS Poll skb here instead of returning TXRX_DROP that would
952 * count as an dropped frame. */
953 dev_kfree_skb(rx->skb);
958 static ieee80211_txrx_result
959 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
962 u8 *data = rx->skb->data;
963 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
965 if (!WLAN_FC_IS_QOS_DATA(fc))
966 return TXRX_CONTINUE;
968 /* remove the qos control field, update frame type and meta-data */
969 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
970 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
971 /* change frame type to non QOS */
972 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
973 hdr->frame_control = cpu_to_le16(fc);
975 return TXRX_CONTINUE;
979 ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx)
981 if (unlikely(rx->sdata->ieee802_1x_pac &&
982 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)))) {
983 #ifdef CONFIG_MAC80211_DEBUG
984 printk(KERN_DEBUG "%s: dropped frame "
985 "(unauthorized port)\n", rx->dev->name);
986 #endif /* CONFIG_MAC80211_DEBUG */
994 ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx)
997 * Pass through unencrypted frames if the hardware has
998 * decrypted them already.
1000 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
1003 /* Drop unencrypted frames if key is set. */
1004 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
1005 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
1006 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
1007 (rx->key || rx->sdata->drop_unencrypted))) {
1008 if (net_ratelimit())
1009 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
1010 "encryption\n", rx->dev->name);
1017 ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
1019 struct net_device *dev = rx->dev;
1020 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
1021 u16 fc, hdrlen, ethertype;
1025 struct sk_buff *skb = rx->skb;
1026 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1027 DECLARE_MAC_BUF(mac);
1028 DECLARE_MAC_BUF(mac2);
1029 DECLARE_MAC_BUF(mac3);
1030 DECLARE_MAC_BUF(mac4);
1034 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1037 hdrlen = ieee80211_get_hdrlen(fc);
1039 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1041 * IEEE 802.11 address fields:
1042 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1043 * 0 0 DA SA BSSID n/a
1044 * 0 1 DA BSSID SA n/a
1045 * 1 0 BSSID SA DA n/a
1049 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
1050 case IEEE80211_FCTL_TODS:
1052 memcpy(dst, hdr->addr3, ETH_ALEN);
1053 memcpy(src, hdr->addr2, ETH_ALEN);
1055 if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
1056 sdata->type != IEEE80211_IF_TYPE_VLAN)) {
1057 if (net_ratelimit())
1058 printk(KERN_DEBUG "%s: dropped ToDS frame "
1059 "(BSSID=%s SA=%s DA=%s)\n",
1061 print_mac(mac, hdr->addr1),
1062 print_mac(mac2, hdr->addr2),
1063 print_mac(mac3, hdr->addr3));
1067 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1069 memcpy(dst, hdr->addr3, ETH_ALEN);
1070 memcpy(src, hdr->addr4, ETH_ALEN);
1072 if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
1073 if (net_ratelimit())
1074 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
1075 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1077 print_mac(mac, hdr->addr1),
1078 print_mac(mac2, hdr->addr2),
1079 print_mac(mac3, hdr->addr3),
1080 print_mac(mac4, hdr->addr4));
1084 case IEEE80211_FCTL_FROMDS:
1086 memcpy(dst, hdr->addr1, ETH_ALEN);
1087 memcpy(src, hdr->addr3, ETH_ALEN);
1089 if (sdata->type != IEEE80211_IF_TYPE_STA ||
1090 (is_multicast_ether_addr(dst) &&
1091 !compare_ether_addr(src, dev->dev_addr)))
1096 memcpy(dst, hdr->addr1, ETH_ALEN);
1097 memcpy(src, hdr->addr2, ETH_ALEN);
1099 if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
1100 if (net_ratelimit()) {
1101 printk(KERN_DEBUG "%s: dropped IBSS frame "
1102 "(DA=%s SA=%s BSSID=%s)\n",
1104 print_mac(mac, hdr->addr1),
1105 print_mac(mac2, hdr->addr2),
1106 print_mac(mac3, hdr->addr3));
1113 if (unlikely(skb->len - hdrlen < 8)) {
1114 if (net_ratelimit()) {
1115 printk(KERN_DEBUG "%s: RX too short data frame "
1116 "payload\n", dev->name);
1121 payload = skb->data + hdrlen;
1122 ethertype = (payload[6] << 8) | payload[7];
1124 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1125 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1126 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1127 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1128 * replace EtherType */
1129 skb_pull(skb, hdrlen + 6);
1130 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1131 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1133 struct ethhdr *ehdr;
1136 skb_pull(skb, hdrlen);
1137 len = htons(skb->len);
1138 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1139 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1140 memcpy(ehdr->h_source, src, ETH_ALEN);
1141 ehdr->h_proto = len;
1147 * requires that rx->skb is a frame with ethernet header
1149 static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx)
1151 static const u8 pae_group_addr[ETH_ALEN]
1152 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1153 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1156 * Allow EAPOL frames to us/the PAE group address regardless
1157 * of whether the frame was encrypted or not.
1159 if (ehdr->h_proto == htons(ETH_P_PAE) &&
1160 (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 ||
1161 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1164 if (ieee80211_802_1x_port_control(rx) ||
1165 ieee80211_drop_unencrypted(rx))
1172 * requires that rx->skb is a frame with ethernet header
1175 ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1177 struct net_device *dev = rx->dev;
1178 struct ieee80211_local *local = rx->local;
1179 struct sk_buff *skb, *xmit_skb;
1180 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1181 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1182 struct sta_info *dsta;
1187 if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP ||
1188 sdata->type == IEEE80211_IF_TYPE_VLAN) &&
1189 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
1190 if (is_multicast_ether_addr(ehdr->h_dest)) {
1192 * send multicast frames both to higher layers in
1193 * local net stack and back to the wireless medium
1195 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1196 if (!xmit_skb && net_ratelimit())
1197 printk(KERN_DEBUG "%s: failed to clone "
1198 "multicast frame\n", dev->name);
1200 dsta = sta_info_get(local, skb->data);
1201 if (dsta && dsta->dev == dev) {
1203 * The destination station is associated to
1204 * this AP (in this VLAN), so send the frame
1205 * directly to it and do not pass it to local
1217 /* deliver to local stack */
1218 skb->protocol = eth_type_trans(skb, dev);
1219 memset(skb->cb, 0, sizeof(skb->cb));
1224 /* send to wireless media */
1225 xmit_skb->protocol = htons(ETH_P_802_3);
1226 skb_reset_network_header(xmit_skb);
1227 skb_reset_mac_header(xmit_skb);
1228 dev_queue_xmit(xmit_skb);
1232 static ieee80211_txrx_result
1233 ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1235 struct net_device *dev = rx->dev;
1236 struct ieee80211_local *local = rx->local;
1239 struct sk_buff *skb = rx->skb, *frame = NULL;
1240 const struct ethhdr *eth;
1244 DECLARE_MAC_BUF(mac);
1247 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1248 return TXRX_CONTINUE;
1250 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1253 if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU))
1254 return TXRX_CONTINUE;
1256 err = ieee80211_data_to_8023(rx);
1262 dev->stats.rx_packets++;
1263 dev->stats.rx_bytes += skb->len;
1265 /* skip the wrapping header */
1266 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
1270 while (skb != frame) {
1272 __be16 len = eth->h_proto;
1273 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
1275 remaining = skb->len;
1276 memcpy(dst, eth->h_dest, ETH_ALEN);
1277 memcpy(src, eth->h_source, ETH_ALEN);
1279 padding = ((4 - subframe_len) & 0x3);
1280 /* the last MSDU has no padding */
1281 if (subframe_len > remaining) {
1282 printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
1286 skb_pull(skb, sizeof(struct ethhdr));
1287 /* if last subframe reuse skb */
1288 if (remaining <= subframe_len + padding)
1291 frame = dev_alloc_skb(local->hw.extra_tx_headroom +
1297 skb_reserve(frame, local->hw.extra_tx_headroom +
1298 sizeof(struct ethhdr));
1299 memcpy(skb_put(frame, ntohs(len)), skb->data,
1302 eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
1305 printk(KERN_DEBUG "%s: wrong buffer size ",
1307 dev_kfree_skb(frame);
1312 skb_reset_network_header(frame);
1314 frame->priority = skb->priority;
1317 payload = frame->data;
1318 ethertype = (payload[6] << 8) | payload[7];
1320 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1321 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1322 compare_ether_addr(payload,
1323 bridge_tunnel_header) == 0)) {
1324 /* remove RFC1042 or Bridge-Tunnel
1325 * encapsulation and replace EtherType */
1327 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1328 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1330 memcpy(skb_push(frame, sizeof(__be16)),
1331 &len, sizeof(__be16));
1332 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1333 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1336 if (!ieee80211_frame_allowed(rx)) {
1337 if (skb == frame) /* last frame */
1339 dev_kfree_skb(frame);
1343 ieee80211_deliver_skb(rx);
1349 static ieee80211_txrx_result
1350 ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
1352 struct net_device *dev = rx->dev;
1357 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1358 return TXRX_CONTINUE;
1360 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1363 err = ieee80211_data_to_8023(rx);
1367 if (!ieee80211_frame_allowed(rx))
1372 dev->stats.rx_packets++;
1373 dev->stats.rx_bytes += rx->skb->len;
1375 ieee80211_deliver_skb(rx);
1380 static ieee80211_txrx_result
1381 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1383 struct ieee80211_sub_if_data *sdata;
1385 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
1388 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1389 if ((sdata->type == IEEE80211_IF_TYPE_STA ||
1390 sdata->type == IEEE80211_IF_TYPE_IBSS) &&
1391 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
1392 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
1399 static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1400 struct ieee80211_local *local,
1401 ieee80211_rx_handler *handlers,
1402 struct ieee80211_txrx_data *rx,
1403 struct sta_info *sta)
1405 ieee80211_rx_handler *handler;
1406 ieee80211_txrx_result res = TXRX_DROP;
1408 for (handler = handlers; *handler != NULL; handler++) {
1409 res = (*handler)(rx);
1415 I802_DEBUG_INC(local->rx_handlers_drop);
1420 I802_DEBUG_INC(local->rx_handlers_queued);
1426 if (res == TXRX_DROP)
1427 dev_kfree_skb(rx->skb);
1431 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1432 ieee80211_rx_handler *handlers,
1433 struct ieee80211_txrx_data *rx,
1434 struct sta_info *sta)
1436 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1438 dev_kfree_skb(rx->skb);
1441 static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1442 struct ieee80211_hdr *hdr,
1443 struct sta_info *sta,
1444 struct ieee80211_txrx_data *rx)
1447 DECLARE_MAC_BUF(mac);
1448 DECLARE_MAC_BUF(mac2);
1450 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1451 if (rx->skb->len >= hdrlen + 4)
1452 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1456 if (net_ratelimit())
1457 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
1458 "failure from %s to %s keyidx=%d\n",
1459 dev->name, print_mac(mac, hdr->addr2),
1460 print_mac(mac2, hdr->addr1), keyidx);
1464 * Some hardware seem to generate incorrect Michael MIC
1465 * reports; ignore them to avoid triggering countermeasures.
1467 if (net_ratelimit())
1468 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1469 "error for unknown address %s\n",
1470 dev->name, print_mac(mac, hdr->addr2));
1474 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
1475 if (net_ratelimit())
1476 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1477 "error for a frame with no PROTECTED flag (src "
1478 "%s)\n", dev->name, print_mac(mac, hdr->addr2));
1482 if (rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) {
1484 * APs with pairwise keys should never receive Michael MIC
1485 * errors for non-zero keyidx because these are reserved for
1486 * group keys and only the AP is sending real multicast
1487 * frames in the BSS.
1489 if (net_ratelimit())
1490 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1491 "a frame with non-zero keyidx (%d)"
1492 " (src %s)\n", dev->name, keyidx,
1493 print_mac(mac, hdr->addr2));
1497 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1498 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1499 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
1500 if (net_ratelimit())
1501 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1502 "error for a frame that cannot be encrypted "
1503 "(fc=0x%04x) (src %s)\n",
1504 dev->name, rx->fc, print_mac(mac, hdr->addr2));
1508 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
1510 dev_kfree_skb(rx->skb);
1514 ieee80211_rx_handler ieee80211_rx_handlers[] =
1516 ieee80211_rx_h_if_stats,
1517 ieee80211_rx_h_passive_scan,
1518 ieee80211_rx_h_check,
1519 ieee80211_rx_h_decrypt,
1520 ieee80211_rx_h_sta_process,
1521 ieee80211_rx_h_defragment,
1522 ieee80211_rx_h_ps_poll,
1523 ieee80211_rx_h_michael_mic_verify,
1524 /* this must be after decryption - so header is counted in MPDU mic
1525 * must be before pae and data, so QOS_DATA format frames
1526 * are not passed to user space by these functions
1528 ieee80211_rx_h_remove_qos_control,
1529 ieee80211_rx_h_amsdu,
1530 ieee80211_rx_h_data,
1531 ieee80211_rx_h_mgmt,
1535 /* main receive path */
1537 static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1538 u8 *bssid, struct ieee80211_txrx_data *rx,
1539 struct ieee80211_hdr *hdr)
1541 int multicast = is_multicast_ether_addr(hdr->addr1);
1543 switch (sdata->type) {
1544 case IEEE80211_IF_TYPE_STA:
1547 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1548 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1550 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1551 } else if (!multicast &&
1552 compare_ether_addr(sdata->dev->dev_addr,
1554 if (!(sdata->dev->flags & IFF_PROMISC))
1556 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1559 case IEEE80211_IF_TYPE_IBSS:
1562 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1563 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1565 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1566 } else if (!multicast &&
1567 compare_ether_addr(sdata->dev->dev_addr,
1569 if (!(sdata->dev->flags & IFF_PROMISC))
1571 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1572 } else if (!rx->sta)
1573 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1576 case IEEE80211_IF_TYPE_VLAN:
1577 case IEEE80211_IF_TYPE_AP:
1579 if (compare_ether_addr(sdata->dev->dev_addr,
1582 } else if (!ieee80211_bssid_match(bssid,
1583 sdata->dev->dev_addr)) {
1584 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1586 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1588 if (sdata->dev == sdata->local->mdev &&
1589 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1590 /* do not receive anything via
1591 * master device when not scanning */
1594 case IEEE80211_IF_TYPE_WDS:
1596 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1598 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1601 case IEEE80211_IF_TYPE_MNTR:
1602 /* take everything */
1604 case IEEE80211_IF_TYPE_INVALID:
1605 /* should never get here */
1614 * This is the actual Rx frames handler. as it blongs to Rx path it must
1615 * be called with rcu_read_lock protection.
1617 void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, struct sk_buff *skb,
1618 struct ieee80211_rx_status *status, u32 load)
1620 struct ieee80211_local *local = hw_to_local(hw);
1621 struct ieee80211_sub_if_data *sdata;
1622 struct sta_info *sta;
1623 struct ieee80211_hdr *hdr;
1624 struct ieee80211_txrx_data rx;
1627 struct ieee80211_sub_if_data *prev = NULL;
1628 struct sk_buff *skb_new;
1632 hdr = (struct ieee80211_hdr *) skb->data;
1633 memset(&rx, 0, sizeof(rx));
1637 rx.u.rx.status = status;
1638 rx.u.rx.load = load;
1639 rx.fc = le16_to_cpu(hdr->frame_control);
1640 type = rx.fc & IEEE80211_FCTL_FTYPE;
1643 * Drivers are required to align the payload data to a four-byte
1644 * boundary, so the last two bits of the address where it starts
1645 * may not be set. The header is required to be directly before
1646 * the payload data, padding like atheros hardware adds which is
1647 * inbetween the 802.11 header and the payload is not supported,
1648 * the driver is required to move the 802.11 header further back
1651 hdrlen = ieee80211_get_hdrlen(rx.fc);
1652 WARN_ON_ONCE(((unsigned long)(skb->data + hdrlen)) & 3);
1654 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
1655 local->dot11ReceivedFragmentCount++;
1657 sta = rx.sta = sta_info_get(local, hdr->addr2);
1659 rx.dev = rx.sta->dev;
1660 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1663 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1664 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
1668 if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
1669 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
1671 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
1672 sta) != TXRX_CONTINUE)
1676 if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) &&
1677 !atomic_read(&local->iff_promiscs) &&
1678 !is_multicast_ether_addr(hdr->addr1)) {
1679 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1680 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
1687 bssid = ieee80211_get_bssid(hdr, skb->len);
1689 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1690 if (!netif_running(sdata->dev))
1693 if (sdata->type == IEEE80211_IF_TYPE_MNTR)
1696 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1697 prepares = prepare_for_handlers(sdata, bssid, &rx, hdr);
1698 /* prepare_for_handlers can change sta */
1705 * frame is destined for this interface, but if it's not
1706 * also for the previous one we handle that after the
1707 * loop to avoid copying the SKB once too much
1716 * frame was destined for the previous interface
1717 * so invoke RX handlers for it
1720 skb_new = skb_copy(skb, GFP_ATOMIC);
1722 if (net_ratelimit())
1723 printk(KERN_DEBUG "%s: failed to copy "
1724 "multicast frame for %s",
1725 wiphy_name(local->hw.wiphy),
1729 rx.fc = le16_to_cpu(hdr->frame_control);
1733 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1738 rx.fc = le16_to_cpu(hdr->frame_control);
1742 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1753 * This is the receive path handler. It is called by a low level driver when an
1754 * 802.11 MPDU is received from the hardware.
1756 void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1757 struct ieee80211_rx_status *status)
1759 struct ieee80211_local *local = hw_to_local(hw);
1763 * key references and virtual interfaces are protected using RCU
1764 * and this requires that we are in a read-side RCU section during
1765 * receive processing
1770 * Frames with failed FCS/PLCP checksum are not returned,
1771 * all other frames are returned without radiotap header
1772 * if it was previously present.
1773 * Also, frames with less than 16 bytes are dropped.
1775 skb = ieee80211_rx_monitor(local, skb, status);
1781 pkt_load = ieee80211_rx_load_stats(local, skb, status);
1783 __ieee80211_rx_handle_packet(hw, skb, status, pkt_load);
1787 EXPORT_SYMBOL(__ieee80211_rx);
1789 /* This is a version of the rx handler that can be called from hard irq
1790 * context. Post the skb on the queue and schedule the tasklet */
1791 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
1792 struct ieee80211_rx_status *status)
1794 struct ieee80211_local *local = hw_to_local(hw);
1796 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
1798 skb->dev = local->mdev;
1799 /* copy status into skb->cb for use by tasklet */
1800 memcpy(skb->cb, status, sizeof(*status));
1801 skb->pkt_type = IEEE80211_RX_MSG;
1802 skb_queue_tail(&local->skb_queue, skb);
1803 tasklet_schedule(&local->tasklet);
1805 EXPORT_SYMBOL(ieee80211_rx_irqsafe);