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"
22 #include "ieee80211_common.h"
29 * monitor mode reception
31 * This function cleans up the SKB, i.e. it removes all the stuff
32 * only useful for monitoring.
34 static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
38 skb_pull(skb, rtap_len);
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 ieee80211_rx_status *status,
59 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
61 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
63 if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len))
65 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
66 cpu_to_le16(IEEE80211_FTYPE_CTL))
72 * This function copies a received frame to all monitor interfaces and
73 * returns a cleaned-up SKB that no longer includes the FCS nor the
74 * radiotap header the driver might have added.
76 static struct sk_buff *
77 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
78 struct ieee80211_rx_status *status)
80 struct ieee80211_sub_if_data *sdata;
81 struct ieee80211_rate *rate;
82 int needed_headroom = 0;
83 struct ieee80211_rtap_hdr {
84 struct ieee80211_radiotap_header hdr;
90 u8 padding_for_rxflags;
92 } __attribute__ ((packed)) *rthdr;
93 struct sk_buff *skb, *skb2;
94 struct net_device *prev_dev = NULL;
95 int present_fcs_len = 0;
99 * First, we may need to make a copy of the skb because
100 * (1) we need to modify it for radiotap (if not present), and
101 * (2) the other RX handlers will modify the skb we got.
103 * We don't need to, of course, if we aren't going to return
104 * the SKB because it has a bad FCS/PLCP checksum.
106 if (status->flag & RX_FLAG_RADIOTAP)
107 rtap_len = ieee80211_get_radiotap_len(origskb->data);
109 needed_headroom = sizeof(*rthdr);
111 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
112 present_fcs_len = FCS_LEN;
114 if (!local->monitors) {
115 if (should_drop_frame(status, origskb, present_fcs_len,
117 dev_kfree_skb(origskb);
121 return remove_monitor_info(local, origskb, rtap_len);
124 if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) {
125 /* only need to expand headroom if necessary */
130 * This shouldn't trigger often because most devices have an
131 * RX header they pull before we get here, and that should
132 * be big enough for our radiotap information. We should
133 * probably export the length to drivers so that we can have
134 * them allocate enough headroom to start with.
136 if (skb_headroom(skb) < needed_headroom &&
137 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) {
143 * Need to make a copy and possibly remove radiotap header
144 * and FCS from the original.
146 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
148 origskb = remove_monitor_info(local, origskb, rtap_len);
154 /* if necessary, prepend radiotap information */
155 if (!(status->flag & RX_FLAG_RADIOTAP)) {
156 rthdr = (void *) skb_push(skb, sizeof(*rthdr));
157 memset(rthdr, 0, sizeof(*rthdr));
158 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
159 rthdr->hdr.it_present =
160 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
161 (1 << IEEE80211_RADIOTAP_RATE) |
162 (1 << IEEE80211_RADIOTAP_CHANNEL) |
163 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |
164 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
165 rthdr->flags = local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS ?
166 IEEE80211_RADIOTAP_F_FCS : 0;
168 /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
171 (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
173 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
175 rate = ieee80211_get_rate(local, status->phymode,
178 rthdr->rate = rate->rate / 5;
180 rthdr->chan_freq = cpu_to_le16(status->freq);
182 if (status->phymode == MODE_IEEE80211A)
184 cpu_to_le16(IEEE80211_CHAN_OFDM |
185 IEEE80211_CHAN_5GHZ);
188 cpu_to_le16(IEEE80211_CHAN_DYN |
189 IEEE80211_CHAN_2GHZ);
191 rthdr->antsignal = status->ssi;
194 skb_set_mac_header(skb, 0);
195 skb->ip_summed = CHECKSUM_UNNECESSARY;
196 skb->pkt_type = PACKET_OTHERHOST;
197 skb->protocol = htons(ETH_P_802_2);
199 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
200 if (!netif_running(sdata->dev))
203 if (sdata->type != IEEE80211_IF_TYPE_MNTR)
207 skb2 = skb_clone(skb, GFP_ATOMIC);
209 skb2->dev = prev_dev;
214 prev_dev = sdata->dev;
215 sdata->dev->stats.rx_packets++;
216 sdata->dev->stats.rx_bytes += skb->len;
231 * these don't have dev/sdata fields in the rx data
232 * The sta value should also not be used because it may
233 * be NULL even though a STA (in IBSS mode) will be added.
236 static ieee80211_txrx_result
237 ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
239 u8 *data = rx->skb->data;
242 /* does the frame have a qos control field? */
243 if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
244 u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
245 /* frame has qos control */
246 tid = qc[0] & QOS_CONTROL_TID_MASK;
248 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
249 /* Separate TID for management frames */
250 tid = NUM_RX_DATA_QUEUES - 1;
252 /* no qos control present */
253 tid = 0; /* 802.1d - Best Effort */
257 I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
258 /* only a debug counter, sta might not be assigned properly yet */
260 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
262 rx->u.rx.queue = tid;
263 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
264 * For now, set skb->priority to 0 for other cases. */
265 rx->skb->priority = (tid > 7) ? 0 : tid;
267 return TXRX_CONTINUE;
270 static ieee80211_txrx_result
271 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
273 struct ieee80211_local *local = rx->local;
274 struct sk_buff *skb = rx->skb;
275 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
276 u32 load = 0, hdrtime;
277 struct ieee80211_rate *rate;
278 struct ieee80211_hw_mode *mode = local->hw.conf.mode;
281 /* Estimate total channel use caused by this frame */
283 if (unlikely(mode->num_rates < 0))
284 return TXRX_CONTINUE;
286 rate = &mode->rates[0];
287 for (i = 0; i < mode->num_rates; i++) {
288 if (mode->rates[i].val == rx->u.rx.status->rate) {
289 rate = &mode->rates[i];
294 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
295 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
297 if (mode->mode == MODE_IEEE80211A ||
298 (mode->mode == MODE_IEEE80211G &&
299 rate->flags & IEEE80211_RATE_ERP))
300 hdrtime = CHAN_UTIL_HDR_SHORT;
302 hdrtime = CHAN_UTIL_HDR_LONG;
305 if (!is_multicast_ether_addr(hdr->addr1))
308 load += skb->len * rate->rate_inv;
310 /* Divide channel_use by 8 to avoid wrapping around the counter */
311 load >>= CHAN_UTIL_SHIFT;
312 local->channel_use_raw += load;
313 rx->u.rx.load = load;
315 return TXRX_CONTINUE;
318 ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
320 ieee80211_rx_h_parse_qos,
321 ieee80211_rx_h_load_stats,
327 static ieee80211_txrx_result
328 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
331 rx->sta->channel_use_raw += rx->u.rx.load;
332 rx->sdata->channel_use_raw += rx->u.rx.load;
333 return TXRX_CONTINUE;
336 static ieee80211_txrx_result
337 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
339 struct ieee80211_local *local = rx->local;
340 struct sk_buff *skb = rx->skb;
342 if (unlikely(local->sta_scanning != 0)) {
343 ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
347 if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
348 /* scanning finished during invoking of handlers */
349 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
353 return TXRX_CONTINUE;
356 static ieee80211_txrx_result
357 ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
359 struct ieee80211_hdr *hdr;
360 hdr = (struct ieee80211_hdr *) rx->skb->data;
362 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
363 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
364 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
365 rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
367 if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
368 rx->local->dot11FrameDuplicateCount++;
369 rx->sta->num_duplicates++;
373 rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
376 if (unlikely(rx->skb->len < 16)) {
377 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
381 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
382 rx->skb->pkt_type = PACKET_OTHERHOST;
383 else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0)
384 rx->skb->pkt_type = PACKET_HOST;
385 else if (is_multicast_ether_addr(hdr->addr1)) {
386 if (is_broadcast_ether_addr(hdr->addr1))
387 rx->skb->pkt_type = PACKET_BROADCAST;
389 rx->skb->pkt_type = PACKET_MULTICAST;
391 rx->skb->pkt_type = PACKET_OTHERHOST;
393 /* Drop disallowed frame classes based on STA auth/assoc state;
394 * IEEE 802.11, Chap 5.5.
396 * 80211.o does filtering only based on association state, i.e., it
397 * drops Class 3 frames from not associated stations. hostapd sends
398 * deauth/disassoc frames when needed. In addition, hostapd is
399 * responsible for filtering on both auth and assoc states.
401 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
402 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
403 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
404 rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
405 (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
406 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
407 !(rx->fc & IEEE80211_FCTL_TODS) &&
408 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
409 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
410 /* Drop IBSS frames and frames for other hosts
415 if (!rx->local->apdev)
418 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
419 ieee80211_msg_sta_not_assoc);
423 return TXRX_CONTINUE;
427 static ieee80211_txrx_result
428 ieee80211_rx_h_load_key(struct ieee80211_txrx_data *rx)
430 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
433 struct ieee80211_key *stakey = NULL;
438 * There are three types of keys:
440 * - PTK (pairwise keys)
441 * - STK (station-to-station pairwise keys)
443 * When selecting a key, we have to distinguish between multicast
444 * (including broadcast) and unicast frames, the latter can only
445 * use PTKs and STKs while the former always use GTKs. Unless, of
446 * course, actual WEP keys ("pre-RSNA") are used, then unicast
447 * frames can also use key indizes like GTKs. Hence, if we don't
448 * have a PTK/STK we check the key index for a WEP key.
450 * Note that in a regular BSS, multicast frames are sent by the
451 * AP only, associated stations unicast the frame to the AP first
452 * which then multicasts it on their behalf.
454 * There is also a slight problem in IBSS mode: GTKs are negotiated
455 * with each station, that is something we don't currently handle.
456 * The spec seems to expect that one negotiates the same key with
457 * every station but there's no such requirement; VLANs could be
461 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
462 return TXRX_CONTINUE;
465 * No point in finding a key if the frame is neither
466 * addressed to us nor a multicast frame.
468 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
469 return TXRX_CONTINUE;
472 stakey = rcu_dereference(rx->sta->key);
474 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
478 * The device doesn't give us the IV so we won't be
479 * able to look up the key. That's ok though, we
480 * don't need to decrypt the frame, we just won't
481 * be able to keep statistics accurate.
482 * Except for key threshold notifications, should
483 * we somehow allow the driver to tell us which key
484 * the hardware used if this flag is set?
486 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
487 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
488 return TXRX_CONTINUE;
490 hdrlen = ieee80211_get_hdrlen(rx->fc);
492 if (rx->skb->len < 8 + hdrlen)
493 return TXRX_DROP; /* TODO: count this? */
496 * no need to call ieee80211_wep_get_keyidx,
497 * it verifies a bunch of things we've done already
499 keyidx = rx->skb->data[hdrlen + 3] >> 6;
501 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
504 * RSNA-protected unicast frames should always be sent with
505 * pairwise or station-to-station keys, but for WEP we allow
506 * using a key index as well.
508 if (rx->key && rx->key->conf.alg != ALG_WEP &&
509 !is_multicast_ether_addr(hdr->addr1))
514 rx->key->tx_rx_count++;
515 /* TODO: add threshold stuff again */
518 return TXRX_CONTINUE;
521 static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
523 struct ieee80211_sub_if_data *sdata;
524 DECLARE_MAC_BUF(mac);
526 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
529 atomic_inc(&sdata->bss->num_sta_ps);
530 sta->flags |= WLAN_STA_PS;
532 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
533 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
534 dev->name, print_mac(mac, sta->addr), sta->aid);
535 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
538 static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
540 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
543 struct ieee80211_sub_if_data *sdata;
544 struct ieee80211_tx_packet_data *pkt_data;
545 DECLARE_MAC_BUF(mac);
547 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
549 atomic_dec(&sdata->bss->num_sta_ps);
550 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
552 if (!skb_queue_empty(&sta->ps_tx_buf)) {
553 if (local->ops->set_tim)
554 local->ops->set_tim(local_to_hw(local), sta->aid, 0);
556 bss_tim_clear(local, sdata->bss, sta->aid);
558 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
559 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
560 dev->name, print_mac(mac, sta->addr), sta->aid);
561 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
562 /* Send all buffered frames to the station */
563 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
564 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
566 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
569 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
570 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
571 local->total_ps_buffered--;
573 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
574 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
575 "since STA not sleeping anymore\n", dev->name,
576 print_mac(mac, sta->addr), sta->aid);
577 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
578 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
585 static ieee80211_txrx_result
586 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
588 struct sta_info *sta = rx->sta;
589 struct net_device *dev = rx->dev;
590 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
593 return TXRX_CONTINUE;
595 /* Update last_rx only for IBSS packets which are for the current
596 * BSSID to avoid keeping the current IBSS network alive in cases where
597 * other STAs are using different BSSID. */
598 if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
599 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
600 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
601 sta->last_rx = jiffies;
603 if (!is_multicast_ether_addr(hdr->addr1) ||
604 rx->sdata->type == IEEE80211_IF_TYPE_STA) {
605 /* Update last_rx only for unicast frames in order to prevent
606 * the Probe Request frames (the only broadcast frames from a
607 * STA in infrastructure mode) from keeping a connection alive.
609 sta->last_rx = jiffies;
612 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
613 return TXRX_CONTINUE;
616 sta->rx_bytes += rx->skb->len;
617 sta->last_rssi = rx->u.rx.status->ssi;
618 sta->last_signal = rx->u.rx.status->signal;
619 sta->last_noise = rx->u.rx.status->noise;
621 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
622 /* Change STA power saving mode only in the end of a frame
623 * exchange sequence */
624 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
625 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
626 else if (!(sta->flags & WLAN_STA_PS) &&
627 (rx->fc & IEEE80211_FCTL_PM))
628 ap_sta_ps_start(dev, sta);
631 /* Drop data::nullfunc frames silently, since they are used only to
632 * control station power saving mode. */
633 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
634 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
635 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
636 /* Update counter and free packet here to avoid counting this
637 * as a dropped packed. */
639 dev_kfree_skb(rx->skb);
643 return TXRX_CONTINUE;
644 } /* ieee80211_rx_h_sta_process */
646 static ieee80211_txrx_result
647 ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
649 if (!rx->sta || !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
650 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
651 !rx->key || rx->key->conf.alg != ALG_WEP ||
652 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
653 return TXRX_CONTINUE;
655 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
656 if (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
657 !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED))
658 if (ieee80211_wep_is_weak_iv(rx->skb, rx->key))
659 rx->sta->wep_weak_iv_count++;
661 return TXRX_CONTINUE;
664 static ieee80211_txrx_result
665 ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
667 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
668 return TXRX_CONTINUE;
672 printk(KERN_DEBUG "%s: RX protected frame,"
673 " but have no key\n", rx->dev->name);
677 switch (rx->key->conf.alg) {
679 return ieee80211_crypto_wep_decrypt(rx);
681 return ieee80211_crypto_tkip_decrypt(rx);
683 return ieee80211_crypto_ccmp_decrypt(rx);
685 return TXRX_CONTINUE;
693 static inline struct ieee80211_fragment_entry *
694 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
695 unsigned int frag, unsigned int seq, int rx_queue,
696 struct sk_buff **skb)
698 struct ieee80211_fragment_entry *entry;
701 idx = sdata->fragment_next;
702 entry = &sdata->fragments[sdata->fragment_next++];
703 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
704 sdata->fragment_next = 0;
706 if (!skb_queue_empty(&entry->skb_list)) {
707 #ifdef CONFIG_MAC80211_DEBUG
708 struct ieee80211_hdr *hdr =
709 (struct ieee80211_hdr *) entry->skb_list.next->data;
710 DECLARE_MAC_BUF(mac);
711 DECLARE_MAC_BUF(mac2);
712 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
713 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
714 "addr1=%s addr2=%s\n",
715 sdata->dev->name, idx,
716 jiffies - entry->first_frag_time, entry->seq,
717 entry->last_frag, print_mac(mac, hdr->addr1),
718 print_mac(mac2, hdr->addr2));
719 #endif /* CONFIG_MAC80211_DEBUG */
720 __skb_queue_purge(&entry->skb_list);
723 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
725 entry->first_frag_time = jiffies;
727 entry->rx_queue = rx_queue;
728 entry->last_frag = frag;
730 entry->extra_len = 0;
735 static inline struct ieee80211_fragment_entry *
736 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
737 u16 fc, unsigned int frag, unsigned int seq,
738 int rx_queue, struct ieee80211_hdr *hdr)
740 struct ieee80211_fragment_entry *entry;
743 idx = sdata->fragment_next;
744 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
745 struct ieee80211_hdr *f_hdr;
750 idx = IEEE80211_FRAGMENT_MAX - 1;
752 entry = &sdata->fragments[idx];
753 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
754 entry->rx_queue != rx_queue ||
755 entry->last_frag + 1 != frag)
758 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
759 f_fc = le16_to_cpu(f_hdr->frame_control);
761 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
762 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
763 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
766 if (entry->first_frag_time + 2 * HZ < jiffies) {
767 __skb_queue_purge(&entry->skb_list);
776 static ieee80211_txrx_result
777 ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
779 struct ieee80211_hdr *hdr;
781 unsigned int frag, seq;
782 struct ieee80211_fragment_entry *entry;
784 DECLARE_MAC_BUF(mac);
786 hdr = (struct ieee80211_hdr *) rx->skb->data;
787 sc = le16_to_cpu(hdr->seq_ctrl);
788 frag = sc & IEEE80211_SCTL_FRAG;
790 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
791 (rx->skb)->len < 24 ||
792 is_multicast_ether_addr(hdr->addr1))) {
796 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
798 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
801 /* This is the first fragment of a new frame. */
802 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
803 rx->u.rx.queue, &(rx->skb));
804 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
805 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
806 /* Store CCMP PN so that we can verify that the next
807 * fragment has a sequential PN value. */
809 memcpy(entry->last_pn,
810 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
816 /* This is a fragment for a frame that should already be pending in
817 * fragment cache. Add this fragment to the end of the pending entry.
819 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
820 rx->u.rx.queue, hdr);
822 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
826 /* Verify that MPDUs within one MSDU have sequential PN values.
827 * (IEEE 802.11i, 8.3.3.4.5) */
830 u8 pn[CCMP_PN_LEN], *rpn;
831 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
833 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
834 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
839 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
840 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
842 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
844 " PN=%02x%02x%02x%02x%02x%02x "
845 "(expected %02x%02x%02x%02x%02x%02x)\n",
846 rx->dev->name, print_mac(mac, hdr->addr2),
847 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
848 rpn[5], pn[0], pn[1], pn[2], pn[3],
852 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
855 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
856 __skb_queue_tail(&entry->skb_list, rx->skb);
857 entry->last_frag = frag;
858 entry->extra_len += rx->skb->len;
859 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
864 rx->skb = __skb_dequeue(&entry->skb_list);
865 if (skb_tailroom(rx->skb) < entry->extra_len) {
866 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
867 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
869 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
870 __skb_queue_purge(&entry->skb_list);
874 while ((skb = __skb_dequeue(&entry->skb_list))) {
875 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
879 /* Complete frame has been reassembled - process it now */
880 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
884 rx->sta->rx_packets++;
885 if (is_multicast_ether_addr(hdr->addr1))
886 rx->local->dot11MulticastReceivedFrameCount++;
888 ieee80211_led_rx(rx->local);
889 return TXRX_CONTINUE;
892 static ieee80211_txrx_result
893 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
897 DECLARE_MAC_BUF(mac);
899 if (likely(!rx->sta ||
900 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
901 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
902 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
903 return TXRX_CONTINUE;
905 skb = skb_dequeue(&rx->sta->tx_filtered);
907 skb = skb_dequeue(&rx->sta->ps_tx_buf);
909 rx->local->total_ps_buffered--;
911 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
912 skb_queue_empty(&rx->sta->ps_tx_buf);
915 struct ieee80211_hdr *hdr =
916 (struct ieee80211_hdr *) skb->data;
918 /* tell TX path to send one frame even though the STA may
919 * still remain is PS mode after this frame exchange */
922 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
923 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
924 print_mac(mac, rx->sta->addr), rx->sta->aid,
925 skb_queue_len(&rx->sta->ps_tx_buf));
926 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
928 /* Use MoreData flag to indicate whether there are more
929 * buffered frames for this STA */
930 if (no_pending_pkts) {
931 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
932 rx->sta->flags &= ~WLAN_STA_TIM;
934 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
938 if (no_pending_pkts) {
939 if (rx->local->ops->set_tim)
940 rx->local->ops->set_tim(local_to_hw(rx->local),
943 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
945 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
946 } else if (!rx->u.rx.sent_ps_buffered) {
947 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
948 "though there is no buffered frames for it\n",
949 rx->dev->name, print_mac(mac, rx->sta->addr));
950 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
954 /* Free PS Poll skb here instead of returning TXRX_DROP that would
955 * count as an dropped frame. */
956 dev_kfree_skb(rx->skb);
961 static ieee80211_txrx_result
962 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
965 u8 *data = rx->skb->data;
966 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
968 if (!WLAN_FC_IS_QOS_DATA(fc))
969 return TXRX_CONTINUE;
971 /* remove the qos control field, update frame type and meta-data */
972 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
973 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
974 /* change frame type to non QOS */
975 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
976 hdr->frame_control = cpu_to_le16(fc);
978 return TXRX_CONTINUE;
981 static ieee80211_txrx_result
982 ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
984 if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
985 rx->sdata->type != IEEE80211_IF_TYPE_STA &&
986 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
987 /* Pass both encrypted and unencrypted EAPOL frames to user
988 * space for processing. */
989 if (!rx->local->apdev)
991 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
992 ieee80211_msg_normal);
996 if (unlikely(rx->sdata->ieee802_1x &&
997 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
998 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
999 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
1000 !ieee80211_is_eapol(rx->skb))) {
1001 #ifdef CONFIG_MAC80211_DEBUG
1002 struct ieee80211_hdr *hdr =
1003 (struct ieee80211_hdr *) rx->skb->data;
1004 DECLARE_MAC_BUF(mac);
1005 printk(KERN_DEBUG "%s: dropped frame from %s"
1006 " (unauthorized port)\n", rx->dev->name,
1007 print_mac(mac, hdr->addr2));
1008 #endif /* CONFIG_MAC80211_DEBUG */
1012 return TXRX_CONTINUE;
1015 static ieee80211_txrx_result
1016 ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
1019 * Pass through unencrypted frames if the hardware has
1020 * decrypted them already.
1022 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
1023 return TXRX_CONTINUE;
1025 /* Drop unencrypted frames if key is set. */
1026 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
1027 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
1028 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
1029 (rx->key || rx->sdata->drop_unencrypted) &&
1030 (rx->sdata->eapol == 0 ||
1031 !ieee80211_is_eapol(rx->skb)))) {
1032 if (net_ratelimit())
1033 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
1034 "encryption\n", rx->dev->name);
1037 return TXRX_CONTINUE;
1040 static ieee80211_txrx_result
1041 ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
1043 struct net_device *dev = rx->dev;
1044 struct ieee80211_local *local = rx->local;
1045 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
1046 u16 fc, hdrlen, ethertype;
1050 struct sk_buff *skb = rx->skb, *skb2;
1051 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1052 DECLARE_MAC_BUF(mac);
1053 DECLARE_MAC_BUF(mac2);
1054 DECLARE_MAC_BUF(mac3);
1055 DECLARE_MAC_BUF(mac4);
1058 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1059 return TXRX_CONTINUE;
1061 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1064 hdrlen = ieee80211_get_hdrlen(fc);
1066 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1068 * IEEE 802.11 address fields:
1069 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1070 * 0 0 DA SA BSSID n/a
1071 * 0 1 DA BSSID SA n/a
1072 * 1 0 BSSID SA DA n/a
1076 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
1077 case IEEE80211_FCTL_TODS:
1079 memcpy(dst, hdr->addr3, ETH_ALEN);
1080 memcpy(src, hdr->addr2, ETH_ALEN);
1082 if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
1083 sdata->type != IEEE80211_IF_TYPE_VLAN)) {
1084 if (net_ratelimit())
1085 printk(KERN_DEBUG "%s: dropped ToDS frame "
1086 "(BSSID=%s SA=%s DA=%s)\n",
1088 print_mac(mac, hdr->addr1),
1089 print_mac(mac2, hdr->addr2),
1090 print_mac(mac3, hdr->addr3));
1094 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1096 memcpy(dst, hdr->addr3, ETH_ALEN);
1097 memcpy(src, hdr->addr4, ETH_ALEN);
1099 if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
1100 if (net_ratelimit())
1101 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
1102 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1104 print_mac(mac, hdr->addr1),
1105 print_mac(mac2, hdr->addr2),
1106 print_mac(mac3, hdr->addr3),
1107 print_mac(mac4, hdr->addr4));
1111 case IEEE80211_FCTL_FROMDS:
1113 memcpy(dst, hdr->addr1, ETH_ALEN);
1114 memcpy(src, hdr->addr3, ETH_ALEN);
1116 if (sdata->type != IEEE80211_IF_TYPE_STA ||
1117 (is_multicast_ether_addr(dst) &&
1118 !compare_ether_addr(src, dev->dev_addr)))
1123 memcpy(dst, hdr->addr1, ETH_ALEN);
1124 memcpy(src, hdr->addr2, ETH_ALEN);
1126 if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
1127 if (net_ratelimit()) {
1128 printk(KERN_DEBUG "%s: dropped IBSS frame "
1129 "(DA=%s SA=%s BSSID=%s)\n",
1131 print_mac(mac, hdr->addr1),
1132 print_mac(mac2, hdr->addr2),
1133 print_mac(mac3, hdr->addr3));
1140 payload = skb->data + hdrlen;
1142 if (unlikely(skb->len - hdrlen < 8)) {
1143 if (net_ratelimit()) {
1144 printk(KERN_DEBUG "%s: RX too short data frame "
1145 "payload\n", dev->name);
1150 ethertype = (payload[6] << 8) | payload[7];
1152 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1153 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1154 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1155 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1156 * replace EtherType */
1157 skb_pull(skb, hdrlen + 6);
1158 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1159 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1161 struct ethhdr *ehdr;
1163 skb_pull(skb, hdrlen);
1164 len = htons(skb->len);
1165 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1166 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1167 memcpy(ehdr->h_source, src, ETH_ALEN);
1168 ehdr->h_proto = len;
1174 dev->stats.rx_packets++;
1175 dev->stats.rx_bytes += skb->len;
1177 if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP
1178 || sdata->type == IEEE80211_IF_TYPE_VLAN) &&
1179 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
1180 if (is_multicast_ether_addr(skb->data)) {
1181 /* send multicast frames both to higher layers in
1182 * local net stack and back to the wireless media */
1183 skb2 = skb_copy(skb, GFP_ATOMIC);
1184 if (!skb2 && net_ratelimit())
1185 printk(KERN_DEBUG "%s: failed to clone "
1186 "multicast frame\n", dev->name);
1188 struct sta_info *dsta;
1189 dsta = sta_info_get(local, skb->data);
1190 if (dsta && !dsta->dev) {
1191 if (net_ratelimit())
1192 printk(KERN_DEBUG "Station with null "
1193 "dev structure!\n");
1194 } else if (dsta && dsta->dev == dev) {
1195 /* Destination station is associated to this
1196 * AP, so send the frame directly to it and
1197 * do not pass the frame to local net stack.
1208 /* deliver to local stack */
1209 skb->protocol = eth_type_trans(skb, dev);
1210 memset(skb->cb, 0, sizeof(skb->cb));
1215 /* send to wireless media */
1216 skb2->protocol = __constant_htons(ETH_P_802_3);
1217 skb_set_network_header(skb2, 0);
1218 skb_set_mac_header(skb2, 0);
1219 dev_queue_xmit(skb2);
1225 static ieee80211_txrx_result
1226 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1228 struct ieee80211_sub_if_data *sdata;
1230 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
1233 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1234 if ((sdata->type == IEEE80211_IF_TYPE_STA ||
1235 sdata->type == IEEE80211_IF_TYPE_IBSS) &&
1236 !rx->local->user_space_mlme) {
1237 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
1239 /* Management frames are sent to hostapd for processing */
1240 if (!rx->local->apdev)
1242 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
1243 ieee80211_msg_normal);
1248 static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1249 struct ieee80211_local *local,
1250 ieee80211_rx_handler *handlers,
1251 struct ieee80211_txrx_data *rx,
1252 struct sta_info *sta)
1254 ieee80211_rx_handler *handler;
1255 ieee80211_txrx_result res = TXRX_DROP;
1257 for (handler = handlers; *handler != NULL; handler++) {
1258 res = (*handler)(rx);
1264 I802_DEBUG_INC(local->rx_handlers_drop);
1269 I802_DEBUG_INC(local->rx_handlers_queued);
1275 if (res == TXRX_DROP)
1276 dev_kfree_skb(rx->skb);
1280 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1281 ieee80211_rx_handler *handlers,
1282 struct ieee80211_txrx_data *rx,
1283 struct sta_info *sta)
1285 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1287 dev_kfree_skb(rx->skb);
1290 static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1291 struct ieee80211_hdr *hdr,
1292 struct sta_info *sta,
1293 struct ieee80211_txrx_data *rx)
1296 DECLARE_MAC_BUF(mac);
1297 DECLARE_MAC_BUF(mac2);
1299 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1300 if (rx->skb->len >= hdrlen + 4)
1301 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1305 if (net_ratelimit())
1306 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
1307 "failure from %s to %s keyidx=%d\n",
1308 dev->name, print_mac(mac, hdr->addr2),
1309 print_mac(mac2, hdr->addr1), keyidx);
1313 * Some hardware seem to generate incorrect Michael MIC
1314 * reports; ignore them to avoid triggering countermeasures.
1316 if (net_ratelimit())
1317 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1318 "error for unknown address %s\n",
1319 dev->name, print_mac(mac, hdr->addr2));
1323 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
1324 if (net_ratelimit())
1325 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1326 "error for a frame with no PROTECTED flag (src "
1327 "%s)\n", dev->name, print_mac(mac, hdr->addr2));
1331 if (rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) {
1333 * APs with pairwise keys should never receive Michael MIC
1334 * errors for non-zero keyidx because these are reserved for
1335 * group keys and only the AP is sending real multicast
1336 * frames in the BSS.
1338 if (net_ratelimit())
1339 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1340 "a frame with non-zero keyidx (%d)"
1341 " (src %s)\n", dev->name, keyidx,
1342 print_mac(mac, hdr->addr2));
1346 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1347 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1348 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
1349 if (net_ratelimit())
1350 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1351 "error for a frame that cannot be encrypted "
1352 "(fc=0x%04x) (src %s)\n",
1353 dev->name, rx->fc, print_mac(mac, hdr->addr2));
1357 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
1359 dev_kfree_skb(rx->skb);
1363 ieee80211_rx_handler ieee80211_rx_handlers[] =
1365 ieee80211_rx_h_if_stats,
1366 ieee80211_rx_h_passive_scan,
1367 ieee80211_rx_h_check,
1368 ieee80211_rx_h_load_key,
1369 ieee80211_rx_h_sta_process,
1370 ieee80211_rx_h_wep_weak_iv_detection,
1371 ieee80211_rx_h_decrypt,
1372 ieee80211_rx_h_defragment,
1373 ieee80211_rx_h_ps_poll,
1374 ieee80211_rx_h_michael_mic_verify,
1375 /* this must be after decryption - so header is counted in MPDU mic
1376 * must be before pae and data, so QOS_DATA format frames
1377 * are not passed to user space by these functions
1379 ieee80211_rx_h_remove_qos_control,
1380 ieee80211_rx_h_802_1x_pae,
1381 ieee80211_rx_h_drop_unencrypted,
1382 ieee80211_rx_h_data,
1383 ieee80211_rx_h_mgmt,
1387 /* main receive path */
1389 static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1390 u8 *bssid, struct ieee80211_txrx_data *rx,
1391 struct ieee80211_hdr *hdr)
1393 int multicast = is_multicast_ether_addr(hdr->addr1);
1395 switch (sdata->type) {
1396 case IEEE80211_IF_TYPE_STA:
1399 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1400 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1402 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1403 } else if (!multicast &&
1404 compare_ether_addr(sdata->dev->dev_addr,
1406 if (!(sdata->dev->flags & IFF_PROMISC))
1408 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1411 case IEEE80211_IF_TYPE_IBSS:
1414 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1415 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1417 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1418 } else if (!multicast &&
1419 compare_ether_addr(sdata->dev->dev_addr,
1421 if (!(sdata->dev->flags & IFF_PROMISC))
1423 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1424 } else if (!rx->sta)
1425 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1428 case IEEE80211_IF_TYPE_VLAN:
1429 case IEEE80211_IF_TYPE_AP:
1431 if (compare_ether_addr(sdata->dev->dev_addr,
1434 } else if (!ieee80211_bssid_match(bssid,
1435 sdata->dev->dev_addr)) {
1436 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1438 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1440 if (sdata->dev == sdata->local->mdev &&
1441 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1442 /* do not receive anything via
1443 * master device when not scanning */
1446 case IEEE80211_IF_TYPE_WDS:
1448 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1450 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1453 case IEEE80211_IF_TYPE_MNTR:
1454 /* take everything */
1456 case IEEE80211_IF_TYPE_MGMT:
1457 /* should never get here */
1466 * This is the receive path handler. It is called by a low level driver when an
1467 * 802.11 MPDU is received from the hardware.
1469 void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1470 struct ieee80211_rx_status *status)
1472 struct ieee80211_local *local = hw_to_local(hw);
1473 struct ieee80211_sub_if_data *sdata;
1474 struct sta_info *sta;
1475 struct ieee80211_hdr *hdr;
1476 struct ieee80211_txrx_data rx;
1479 struct ieee80211_sub_if_data *prev = NULL;
1480 struct sk_buff *skb_new;
1484 * key references and virtual interfaces are protected using RCU
1485 * and this requires that we are in a read-side RCU section during
1486 * receive processing
1491 * Frames with failed FCS/PLCP checksum are not returned,
1492 * all other frames are returned without radiotap header
1493 * if it was previously present.
1494 * Also, frames with less than 16 bytes are dropped.
1496 skb = ieee80211_rx_monitor(local, skb, status);
1502 hdr = (struct ieee80211_hdr *) skb->data;
1503 memset(&rx, 0, sizeof(rx));
1507 rx.u.rx.status = status;
1508 rx.fc = le16_to_cpu(hdr->frame_control);
1509 type = rx.fc & IEEE80211_FCTL_FTYPE;
1511 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
1512 local->dot11ReceivedFragmentCount++;
1514 sta = rx.sta = sta_info_get(local, hdr->addr2);
1516 rx.dev = rx.sta->dev;
1517 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1520 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1521 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
1525 if (unlikely(local->sta_scanning))
1526 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
1528 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
1529 sta) != TXRX_CONTINUE)
1533 if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) &&
1534 !local->iff_promiscs && !is_multicast_ether_addr(hdr->addr1)) {
1535 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1536 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
1543 bssid = ieee80211_get_bssid(hdr, skb->len);
1545 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1546 if (!netif_running(sdata->dev))
1549 if (sdata->type == IEEE80211_IF_TYPE_MNTR)
1552 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1553 prepres = prepare_for_handlers(sdata, bssid, &rx, hdr);
1554 /* prepare_for_handlers can change sta */
1561 * frame is destined for this interface, but if it's not
1562 * also for the previous one we handle that after the
1563 * loop to avoid copying the SKB once too much
1572 * frame was destined for the previous interface
1573 * so invoke RX handlers for it
1576 skb_new = skb_copy(skb, GFP_ATOMIC);
1578 if (net_ratelimit())
1579 printk(KERN_DEBUG "%s: failed to copy "
1580 "multicast frame for %s",
1581 wiphy_name(local->hw.wiphy),
1588 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1596 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1607 EXPORT_SYMBOL(__ieee80211_rx);
1609 /* This is a version of the rx handler that can be called from hard irq
1610 * context. Post the skb on the queue and schedule the tasklet */
1611 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
1612 struct ieee80211_rx_status *status)
1614 struct ieee80211_local *local = hw_to_local(hw);
1616 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
1618 skb->dev = local->mdev;
1619 /* copy status into skb->cb for use by tasklet */
1620 memcpy(skb->cb, status, sizeof(*status));
1621 skb->pkt_type = IEEE80211_RX_MSG;
1622 skb_queue_tail(&local->skb_queue, skb);
1623 tasklet_schedule(&local->tasklet);
1625 EXPORT_SYMBOL(ieee80211_rx_irqsafe);