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))
71 * This function copies a received frame to all monitor interfaces and
72 * returns a cleaned-up SKB that no longer includes the FCS nor the
73 * radiotap header the driver might have added.
75 static struct sk_buff *
76 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
77 struct ieee80211_rx_status *status)
79 struct ieee80211_sub_if_data *sdata;
80 struct ieee80211_rate *rate;
81 int needed_headroom = 0;
82 struct ieee80211_radiotap_header *rthdr;
83 __le64 *rttsft = NULL;
84 struct ieee80211_rtap_fixed_data {
90 u8 padding_for_rxflags;
92 } __attribute__ ((packed)) *rtfixed;
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 /* room for radiotap header, always present fields and TSFT */
110 needed_headroom = sizeof(*rthdr) + sizeof(*rtfixed) + 8;
112 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
113 present_fcs_len = FCS_LEN;
115 if (!local->monitors) {
116 if (should_drop_frame(status, origskb, present_fcs_len,
118 dev_kfree_skb(origskb);
122 return remove_monitor_info(local, origskb, rtap_len);
125 if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) {
126 /* only need to expand headroom if necessary */
131 * This shouldn't trigger often because most devices have an
132 * RX header they pull before we get here, and that should
133 * be big enough for our radiotap information. We should
134 * probably export the length to drivers so that we can have
135 * them allocate enough headroom to start with.
137 if (skb_headroom(skb) < needed_headroom &&
138 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
144 * Need to make a copy and possibly remove radiotap header
145 * and FCS from the original.
147 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
149 origskb = remove_monitor_info(local, origskb, rtap_len);
155 /* if necessary, prepend radiotap information */
156 if (!(status->flag & RX_FLAG_RADIOTAP)) {
157 rtfixed = (void *) skb_push(skb, sizeof(*rtfixed));
158 rtap_len = sizeof(*rthdr) + sizeof(*rtfixed);
159 if (status->flag & RX_FLAG_TSFT) {
160 rttsft = (void *) skb_push(skb, sizeof(*rttsft));
163 rthdr = (void *) skb_push(skb, sizeof(*rthdr));
164 memset(rthdr, 0, sizeof(*rthdr));
165 memset(rtfixed, 0, sizeof(*rtfixed));
167 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
168 (1 << IEEE80211_RADIOTAP_RATE) |
169 (1 << IEEE80211_RADIOTAP_CHANNEL) |
170 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |
171 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
173 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
174 rtfixed->flags |= IEEE80211_RADIOTAP_F_FCS;
177 *rttsft = cpu_to_le64(status->mactime);
179 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
182 /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
183 rtfixed->rx_flags = 0;
185 (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
187 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
189 rate = ieee80211_get_rate(local, status->phymode,
192 rtfixed->rate = rate->rate / 5;
194 rtfixed->chan_freq = cpu_to_le16(status->freq);
196 if (status->phymode == MODE_IEEE80211A)
197 rtfixed->chan_flags =
198 cpu_to_le16(IEEE80211_CHAN_OFDM |
199 IEEE80211_CHAN_5GHZ);
201 rtfixed->chan_flags =
202 cpu_to_le16(IEEE80211_CHAN_DYN |
203 IEEE80211_CHAN_2GHZ);
205 rtfixed->antsignal = status->ssi;
206 rthdr->it_len = cpu_to_le16(rtap_len);
209 skb_set_mac_header(skb, 0);
210 skb->ip_summed = CHECKSUM_UNNECESSARY;
211 skb->pkt_type = PACKET_OTHERHOST;
212 skb->protocol = htons(ETH_P_802_2);
214 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
215 if (!netif_running(sdata->dev))
218 if (sdata->type != IEEE80211_IF_TYPE_MNTR)
222 skb2 = skb_clone(skb, GFP_ATOMIC);
224 skb2->dev = prev_dev;
229 prev_dev = sdata->dev;
230 sdata->dev->stats.rx_packets++;
231 sdata->dev->stats.rx_bytes += skb->len;
246 * these don't have dev/sdata fields in the rx data
247 * The sta value should also not be used because it may
248 * be NULL even though a STA (in IBSS mode) will be added.
251 static ieee80211_txrx_result
252 ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
254 u8 *data = rx->skb->data;
257 /* does the frame have a qos control field? */
258 if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
259 u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
260 /* frame has qos control */
261 tid = qc[0] & QOS_CONTROL_TID_MASK;
262 if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
263 rx->flags |= IEEE80211_TXRXD_RX_AMSDU;
265 rx->flags &= ~IEEE80211_TXRXD_RX_AMSDU;
267 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
268 /* Separate TID for management frames */
269 tid = NUM_RX_DATA_QUEUES - 1;
271 /* no qos control present */
272 tid = 0; /* 802.1d - Best Effort */
276 I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
277 /* only a debug counter, sta might not be assigned properly yet */
279 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
281 rx->u.rx.queue = tid;
282 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
283 * For now, set skb->priority to 0 for other cases. */
284 rx->skb->priority = (tid > 7) ? 0 : tid;
286 return TXRX_CONTINUE;
289 static ieee80211_txrx_result
290 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
292 struct ieee80211_local *local = rx->local;
293 struct sk_buff *skb = rx->skb;
294 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
295 u32 load = 0, hdrtime;
296 struct ieee80211_rate *rate;
297 struct ieee80211_hw_mode *mode = local->hw.conf.mode;
300 /* Estimate total channel use caused by this frame */
302 if (unlikely(mode->num_rates < 0))
303 return TXRX_CONTINUE;
305 rate = &mode->rates[0];
306 for (i = 0; i < mode->num_rates; i++) {
307 if (mode->rates[i].val == rx->u.rx.status->rate) {
308 rate = &mode->rates[i];
313 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
314 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
316 if (mode->mode == MODE_IEEE80211A ||
317 (mode->mode == MODE_IEEE80211G &&
318 rate->flags & IEEE80211_RATE_ERP))
319 hdrtime = CHAN_UTIL_HDR_SHORT;
321 hdrtime = CHAN_UTIL_HDR_LONG;
324 if (!is_multicast_ether_addr(hdr->addr1))
327 load += skb->len * rate->rate_inv;
329 /* Divide channel_use by 8 to avoid wrapping around the counter */
330 load >>= CHAN_UTIL_SHIFT;
331 local->channel_use_raw += load;
332 rx->u.rx.load = load;
334 return TXRX_CONTINUE;
337 ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
339 ieee80211_rx_h_parse_qos,
340 ieee80211_rx_h_load_stats,
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 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
407 rx->skb->pkt_type = PACKET_OTHERHOST;
408 else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0)
409 rx->skb->pkt_type = PACKET_HOST;
410 else if (is_multicast_ether_addr(hdr->addr1)) {
411 if (is_broadcast_ether_addr(hdr->addr1))
412 rx->skb->pkt_type = PACKET_BROADCAST;
414 rx->skb->pkt_type = PACKET_MULTICAST;
416 rx->skb->pkt_type = PACKET_OTHERHOST;
418 /* Drop disallowed frame classes based on STA auth/assoc state;
419 * IEEE 802.11, Chap 5.5.
421 * 80211.o does filtering only based on association state, i.e., it
422 * drops Class 3 frames from not associated stations. hostapd sends
423 * deauth/disassoc frames when needed. In addition, hostapd is
424 * responsible for filtering on both auth and assoc states.
426 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
427 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
428 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
429 rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
430 (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
431 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
432 !(rx->fc & IEEE80211_FCTL_TODS) &&
433 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
434 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
435 /* Drop IBSS frames and frames for other hosts
443 return TXRX_CONTINUE;
447 static ieee80211_txrx_result
448 ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
450 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
453 ieee80211_txrx_result result = TXRX_DROP;
454 struct ieee80211_key *stakey = NULL;
459 * There are three types of keys:
461 * - PTK (pairwise keys)
462 * - STK (station-to-station pairwise keys)
464 * When selecting a key, we have to distinguish between multicast
465 * (including broadcast) and unicast frames, the latter can only
466 * use PTKs and STKs while the former always use GTKs. Unless, of
467 * course, actual WEP keys ("pre-RSNA") are used, then unicast
468 * frames can also use key indizes like GTKs. Hence, if we don't
469 * have a PTK/STK we check the key index for a WEP key.
471 * Note that in a regular BSS, multicast frames are sent by the
472 * AP only, associated stations unicast the frame to the AP first
473 * which then multicasts it on their behalf.
475 * There is also a slight problem in IBSS mode: GTKs are negotiated
476 * with each station, that is something we don't currently handle.
477 * The spec seems to expect that one negotiates the same key with
478 * every station but there's no such requirement; VLANs could be
482 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
483 return TXRX_CONTINUE;
486 * No point in finding a key and decrypting if the frame is neither
487 * addressed to us nor a multicast frame.
489 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
490 return TXRX_CONTINUE;
493 stakey = rcu_dereference(rx->sta->key);
495 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
499 * The device doesn't give us the IV so we won't be
500 * able to look up the key. That's ok though, we
501 * don't need to decrypt the frame, we just won't
502 * be able to keep statistics accurate.
503 * Except for key threshold notifications, should
504 * we somehow allow the driver to tell us which key
505 * the hardware used if this flag is set?
507 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
508 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
509 return TXRX_CONTINUE;
511 hdrlen = ieee80211_get_hdrlen(rx->fc);
513 if (rx->skb->len < 8 + hdrlen)
514 return TXRX_DROP; /* TODO: count this? */
517 * no need to call ieee80211_wep_get_keyidx,
518 * it verifies a bunch of things we've done already
520 keyidx = rx->skb->data[hdrlen + 3] >> 6;
522 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
525 * RSNA-protected unicast frames should always be sent with
526 * pairwise or station-to-station keys, but for WEP we allow
527 * using a key index as well.
529 if (rx->key && rx->key->conf.alg != ALG_WEP &&
530 !is_multicast_ether_addr(hdr->addr1))
535 rx->key->tx_rx_count++;
536 /* TODO: add threshold stuff again */
538 #ifdef CONFIG_MAC80211_DEBUG
540 printk(KERN_DEBUG "%s: RX protected frame,"
541 " but have no key\n", rx->dev->name);
542 #endif /* CONFIG_MAC80211_DEBUG */
546 /* Check for weak IVs if possible */
547 if (rx->sta && rx->key->conf.alg == ALG_WEP &&
548 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
549 (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
550 !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) &&
551 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
552 rx->sta->wep_weak_iv_count++;
554 switch (rx->key->conf.alg) {
556 result = ieee80211_crypto_wep_decrypt(rx);
559 result = ieee80211_crypto_tkip_decrypt(rx);
562 result = ieee80211_crypto_ccmp_decrypt(rx);
566 /* either the frame has been decrypted or will be dropped */
567 rx->u.rx.status->flag |= RX_FLAG_DECRYPTED;
572 static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
574 struct ieee80211_sub_if_data *sdata;
575 DECLARE_MAC_BUF(mac);
577 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
580 atomic_inc(&sdata->bss->num_sta_ps);
581 sta->flags |= WLAN_STA_PS;
583 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
584 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
585 dev->name, print_mac(mac, sta->addr), sta->aid);
586 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
589 static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
591 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
594 struct ieee80211_sub_if_data *sdata;
595 struct ieee80211_tx_packet_data *pkt_data;
596 DECLARE_MAC_BUF(mac);
598 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
600 atomic_dec(&sdata->bss->num_sta_ps);
601 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
603 if (!skb_queue_empty(&sta->ps_tx_buf)) {
604 if (local->ops->set_tim)
605 local->ops->set_tim(local_to_hw(local), sta->aid, 0);
607 bss_tim_clear(local, sdata->bss, sta->aid);
609 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
610 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
611 dev->name, print_mac(mac, sta->addr), sta->aid);
612 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
613 /* Send all buffered frames to the station */
614 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
615 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
617 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
620 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
621 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
622 local->total_ps_buffered--;
624 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
625 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
626 "since STA not sleeping anymore\n", dev->name,
627 print_mac(mac, sta->addr), sta->aid);
628 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
629 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
636 static ieee80211_txrx_result
637 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
639 struct sta_info *sta = rx->sta;
640 struct net_device *dev = rx->dev;
641 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
644 return TXRX_CONTINUE;
646 /* Update last_rx only for IBSS packets which are for the current
647 * BSSID to avoid keeping the current IBSS network alive in cases where
648 * other STAs are using different BSSID. */
649 if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
650 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
651 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
652 sta->last_rx = jiffies;
654 if (!is_multicast_ether_addr(hdr->addr1) ||
655 rx->sdata->type == IEEE80211_IF_TYPE_STA) {
656 /* Update last_rx only for unicast frames in order to prevent
657 * the Probe Request frames (the only broadcast frames from a
658 * STA in infrastructure mode) from keeping a connection alive.
660 sta->last_rx = jiffies;
663 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
664 return TXRX_CONTINUE;
667 sta->rx_bytes += rx->skb->len;
668 sta->last_rssi = rx->u.rx.status->ssi;
669 sta->last_signal = rx->u.rx.status->signal;
670 sta->last_noise = rx->u.rx.status->noise;
672 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
673 /* Change STA power saving mode only in the end of a frame
674 * exchange sequence */
675 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
676 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
677 else if (!(sta->flags & WLAN_STA_PS) &&
678 (rx->fc & IEEE80211_FCTL_PM))
679 ap_sta_ps_start(dev, sta);
682 /* Drop data::nullfunc frames silently, since they are used only to
683 * control station power saving mode. */
684 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
685 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
686 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
687 /* Update counter and free packet here to avoid counting this
688 * as a dropped packed. */
690 dev_kfree_skb(rx->skb);
694 return TXRX_CONTINUE;
695 } /* ieee80211_rx_h_sta_process */
697 static inline struct ieee80211_fragment_entry *
698 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
699 unsigned int frag, unsigned int seq, int rx_queue,
700 struct sk_buff **skb)
702 struct ieee80211_fragment_entry *entry;
705 idx = sdata->fragment_next;
706 entry = &sdata->fragments[sdata->fragment_next++];
707 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
708 sdata->fragment_next = 0;
710 if (!skb_queue_empty(&entry->skb_list)) {
711 #ifdef CONFIG_MAC80211_DEBUG
712 struct ieee80211_hdr *hdr =
713 (struct ieee80211_hdr *) entry->skb_list.next->data;
714 DECLARE_MAC_BUF(mac);
715 DECLARE_MAC_BUF(mac2);
716 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
717 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
718 "addr1=%s addr2=%s\n",
719 sdata->dev->name, idx,
720 jiffies - entry->first_frag_time, entry->seq,
721 entry->last_frag, print_mac(mac, hdr->addr1),
722 print_mac(mac2, hdr->addr2));
723 #endif /* CONFIG_MAC80211_DEBUG */
724 __skb_queue_purge(&entry->skb_list);
727 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
729 entry->first_frag_time = jiffies;
731 entry->rx_queue = rx_queue;
732 entry->last_frag = frag;
734 entry->extra_len = 0;
739 static inline struct ieee80211_fragment_entry *
740 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
741 u16 fc, unsigned int frag, unsigned int seq,
742 int rx_queue, struct ieee80211_hdr *hdr)
744 struct ieee80211_fragment_entry *entry;
747 idx = sdata->fragment_next;
748 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
749 struct ieee80211_hdr *f_hdr;
754 idx = IEEE80211_FRAGMENT_MAX - 1;
756 entry = &sdata->fragments[idx];
757 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
758 entry->rx_queue != rx_queue ||
759 entry->last_frag + 1 != frag)
762 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
763 f_fc = le16_to_cpu(f_hdr->frame_control);
765 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
766 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
767 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
770 if (entry->first_frag_time + 2 * HZ < jiffies) {
771 __skb_queue_purge(&entry->skb_list);
780 static ieee80211_txrx_result
781 ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
783 struct ieee80211_hdr *hdr;
785 unsigned int frag, seq;
786 struct ieee80211_fragment_entry *entry;
788 DECLARE_MAC_BUF(mac);
790 hdr = (struct ieee80211_hdr *) rx->skb->data;
791 sc = le16_to_cpu(hdr->seq_ctrl);
792 frag = sc & IEEE80211_SCTL_FRAG;
794 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
795 (rx->skb)->len < 24 ||
796 is_multicast_ether_addr(hdr->addr1))) {
800 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
802 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
805 /* This is the first fragment of a new frame. */
806 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
807 rx->u.rx.queue, &(rx->skb));
808 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
809 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
810 /* Store CCMP PN so that we can verify that the next
811 * fragment has a sequential PN value. */
813 memcpy(entry->last_pn,
814 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
820 /* This is a fragment for a frame that should already be pending in
821 * fragment cache. Add this fragment to the end of the pending entry.
823 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
824 rx->u.rx.queue, hdr);
826 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
830 /* Verify that MPDUs within one MSDU have sequential PN values.
831 * (IEEE 802.11i, 8.3.3.4.5) */
834 u8 pn[CCMP_PN_LEN], *rpn;
835 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
837 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
838 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
843 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
844 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
846 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
848 " PN=%02x%02x%02x%02x%02x%02x "
849 "(expected %02x%02x%02x%02x%02x%02x)\n",
850 rx->dev->name, print_mac(mac, hdr->addr2),
851 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
852 rpn[5], pn[0], pn[1], pn[2], pn[3],
856 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
859 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
860 __skb_queue_tail(&entry->skb_list, rx->skb);
861 entry->last_frag = frag;
862 entry->extra_len += rx->skb->len;
863 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
868 rx->skb = __skb_dequeue(&entry->skb_list);
869 if (skb_tailroom(rx->skb) < entry->extra_len) {
870 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
871 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
873 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
874 __skb_queue_purge(&entry->skb_list);
878 while ((skb = __skb_dequeue(&entry->skb_list))) {
879 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
883 /* Complete frame has been reassembled - process it now */
884 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
888 rx->sta->rx_packets++;
889 if (is_multicast_ether_addr(hdr->addr1))
890 rx->local->dot11MulticastReceivedFrameCount++;
892 ieee80211_led_rx(rx->local);
893 return TXRX_CONTINUE;
896 static ieee80211_txrx_result
897 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
901 DECLARE_MAC_BUF(mac);
903 if (likely(!rx->sta ||
904 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
905 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
906 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
907 return TXRX_CONTINUE;
909 skb = skb_dequeue(&rx->sta->tx_filtered);
911 skb = skb_dequeue(&rx->sta->ps_tx_buf);
913 rx->local->total_ps_buffered--;
915 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
916 skb_queue_empty(&rx->sta->ps_tx_buf);
919 struct ieee80211_hdr *hdr =
920 (struct ieee80211_hdr *) skb->data;
922 /* tell TX path to send one frame even though the STA may
923 * still remain is PS mode after this frame exchange */
926 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
927 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
928 print_mac(mac, rx->sta->addr), rx->sta->aid,
929 skb_queue_len(&rx->sta->ps_tx_buf));
930 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
932 /* Use MoreData flag to indicate whether there are more
933 * buffered frames for this STA */
934 if (no_pending_pkts) {
935 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
936 rx->sta->flags &= ~WLAN_STA_TIM;
938 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
942 if (no_pending_pkts) {
943 if (rx->local->ops->set_tim)
944 rx->local->ops->set_tim(local_to_hw(rx->local),
947 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
949 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
950 } else if (!rx->u.rx.sent_ps_buffered) {
951 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
952 "though there is no buffered frames for it\n",
953 rx->dev->name, print_mac(mac, rx->sta->addr));
954 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
958 /* Free PS Poll skb here instead of returning TXRX_DROP that would
959 * count as an dropped frame. */
960 dev_kfree_skb(rx->skb);
965 static ieee80211_txrx_result
966 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
969 u8 *data = rx->skb->data;
970 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
972 if (!WLAN_FC_IS_QOS_DATA(fc))
973 return TXRX_CONTINUE;
975 /* remove the qos control field, update frame type and meta-data */
976 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
977 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
978 /* change frame type to non QOS */
979 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
980 hdr->frame_control = cpu_to_le16(fc);
982 return TXRX_CONTINUE;
986 ieee80211_drop_802_1x_pae(struct ieee80211_txrx_data *rx, int hdrlen)
988 if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb, hdrlen) &&
989 rx->sdata->type != IEEE80211_IF_TYPE_STA &&
990 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
993 if (unlikely(rx->sdata->ieee802_1x &&
994 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
995 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
996 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
997 !ieee80211_is_eapol(rx->skb, hdrlen))) {
998 #ifdef CONFIG_MAC80211_DEBUG
999 printk(KERN_DEBUG "%s: dropped frame "
1000 "(unauthorized port)\n", rx->dev->name);
1001 #endif /* CONFIG_MAC80211_DEBUG */
1009 ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx, int hdrlen)
1012 * Pass through unencrypted frames if the hardware has
1013 * decrypted them already.
1015 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
1018 /* Drop unencrypted frames if key is set. */
1019 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
1020 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
1021 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
1022 (rx->key || rx->sdata->drop_unencrypted) &&
1023 (rx->sdata->eapol == 0 ||
1024 !ieee80211_is_eapol(rx->skb, hdrlen)))) {
1025 if (net_ratelimit())
1026 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
1027 "encryption\n", rx->dev->name);
1034 ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
1036 struct net_device *dev = rx->dev;
1037 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
1038 u16 fc, hdrlen, ethertype;
1042 struct sk_buff *skb = rx->skb;
1043 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1044 DECLARE_MAC_BUF(mac);
1045 DECLARE_MAC_BUF(mac2);
1046 DECLARE_MAC_BUF(mac3);
1047 DECLARE_MAC_BUF(mac4);
1051 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1054 hdrlen = ieee80211_get_hdrlen(fc);
1056 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1058 * IEEE 802.11 address fields:
1059 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1060 * 0 0 DA SA BSSID n/a
1061 * 0 1 DA BSSID SA n/a
1062 * 1 0 BSSID SA DA n/a
1066 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
1067 case IEEE80211_FCTL_TODS:
1069 memcpy(dst, hdr->addr3, ETH_ALEN);
1070 memcpy(src, hdr->addr2, ETH_ALEN);
1072 if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
1073 sdata->type != IEEE80211_IF_TYPE_VLAN)) {
1074 if (net_ratelimit())
1075 printk(KERN_DEBUG "%s: dropped ToDS frame "
1076 "(BSSID=%s SA=%s DA=%s)\n",
1078 print_mac(mac, hdr->addr1),
1079 print_mac(mac2, hdr->addr2),
1080 print_mac(mac3, hdr->addr3));
1084 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1086 memcpy(dst, hdr->addr3, ETH_ALEN);
1087 memcpy(src, hdr->addr4, ETH_ALEN);
1089 if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
1090 if (net_ratelimit())
1091 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
1092 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1094 print_mac(mac, hdr->addr1),
1095 print_mac(mac2, hdr->addr2),
1096 print_mac(mac3, hdr->addr3),
1097 print_mac(mac4, hdr->addr4));
1101 case IEEE80211_FCTL_FROMDS:
1103 memcpy(dst, hdr->addr1, ETH_ALEN);
1104 memcpy(src, hdr->addr3, ETH_ALEN);
1106 if (sdata->type != IEEE80211_IF_TYPE_STA ||
1107 (is_multicast_ether_addr(dst) &&
1108 !compare_ether_addr(src, dev->dev_addr)))
1113 memcpy(dst, hdr->addr1, ETH_ALEN);
1114 memcpy(src, hdr->addr2, ETH_ALEN);
1116 if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
1117 if (net_ratelimit()) {
1118 printk(KERN_DEBUG "%s: dropped IBSS frame "
1119 "(DA=%s SA=%s BSSID=%s)\n",
1121 print_mac(mac, hdr->addr1),
1122 print_mac(mac2, hdr->addr2),
1123 print_mac(mac3, hdr->addr3));
1130 if (unlikely(skb->len - hdrlen < 8)) {
1131 if (net_ratelimit()) {
1132 printk(KERN_DEBUG "%s: RX too short data frame "
1133 "payload\n", dev->name);
1138 payload = skb->data + hdrlen;
1139 ethertype = (payload[6] << 8) | payload[7];
1141 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1142 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1143 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1144 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1145 * replace EtherType */
1146 skb_pull(skb, hdrlen + 6);
1147 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1148 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1150 struct ethhdr *ehdr;
1152 skb_pull(skb, hdrlen);
1153 len = htons(skb->len);
1154 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1155 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1156 memcpy(ehdr->h_source, src, ETH_ALEN);
1157 ehdr->h_proto = len;
1163 ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1165 struct net_device *dev = rx->dev;
1166 struct ieee80211_local *local = rx->local;
1167 struct sk_buff *skb, *xmit_skb;
1168 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1173 if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP
1174 || sdata->type == IEEE80211_IF_TYPE_VLAN) &&
1175 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
1176 if (is_multicast_ether_addr(skb->data)) {
1177 /* send multicast frames both to higher layers in
1178 * local net stack and back to the wireless media */
1179 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1180 if (!xmit_skb && net_ratelimit())
1181 printk(KERN_DEBUG "%s: failed to clone "
1182 "multicast frame\n", dev->name);
1184 struct sta_info *dsta;
1185 dsta = sta_info_get(local, skb->data);
1186 if (dsta && !dsta->dev) {
1187 if (net_ratelimit())
1188 printk(KERN_DEBUG "Station with null "
1189 "dev structure!\n");
1190 } else if (dsta && dsta->dev == dev) {
1191 /* Destination station is associated to this
1192 * AP, so send the frame directly to it and
1193 * do not pass the frame to local net stack.
1204 /* deliver to local stack */
1205 skb->protocol = eth_type_trans(skb, dev);
1206 memset(skb->cb, 0, sizeof(skb->cb));
1211 /* send to wireless media */
1212 xmit_skb->protocol = htons(ETH_P_802_3);
1213 skb_set_network_header(xmit_skb, 0);
1214 skb_set_mac_header(xmit_skb, 0);
1215 dev_queue_xmit(xmit_skb);
1219 static ieee80211_txrx_result
1220 ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1222 struct net_device *dev = rx->dev;
1223 struct ieee80211_local *local = rx->local;
1226 struct sk_buff *skb = rx->skb, *frame = NULL;
1227 const struct ethhdr *eth;
1231 DECLARE_MAC_BUF(mac);
1234 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1235 return TXRX_CONTINUE;
1237 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1240 if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU))
1241 return TXRX_CONTINUE;
1243 err = ieee80211_data_to_8023(rx);
1249 dev->stats.rx_packets++;
1250 dev->stats.rx_bytes += skb->len;
1252 /* skip the wrapping header */
1253 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
1257 while (skb != frame) {
1259 __be16 len = eth->h_proto;
1260 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
1262 remaining = skb->len;
1263 memcpy(dst, eth->h_dest, ETH_ALEN);
1264 memcpy(src, eth->h_source, ETH_ALEN);
1266 padding = ((4 - subframe_len) & 0x3);
1267 /* the last MSDU has no padding */
1268 if (subframe_len > remaining) {
1269 printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
1273 skb_pull(skb, sizeof(struct ethhdr));
1274 /* if last subframe reuse skb */
1275 if (remaining <= subframe_len + padding)
1278 frame = dev_alloc_skb(local->hw.extra_tx_headroom +
1284 skb_reserve(frame, local->hw.extra_tx_headroom +
1285 sizeof(struct ethhdr));
1286 memcpy(skb_put(frame, ntohs(len)), skb->data,
1289 eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
1292 printk(KERN_DEBUG "%s: wrong buffer size ",
1294 dev_kfree_skb(frame);
1299 skb_set_network_header(frame, 0);
1301 frame->priority = skb->priority;
1304 if ((ieee80211_drop_802_1x_pae(rx, 0)) ||
1305 (ieee80211_drop_unencrypted(rx, 0))) {
1306 if (skb == frame) /* last frame */
1308 dev_kfree_skb(frame);
1312 payload = frame->data;
1313 ethertype = (payload[6] << 8) | payload[7];
1315 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1316 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1317 compare_ether_addr(payload,
1318 bridge_tunnel_header) == 0)) {
1319 /* remove RFC1042 or Bridge-Tunnel
1320 * encapsulation and replace EtherType */
1322 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1323 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1325 memcpy(skb_push(frame, sizeof(__be16)), &len,
1327 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1328 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1332 ieee80211_deliver_skb(rx);
1338 static ieee80211_txrx_result
1339 ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
1341 struct net_device *dev = rx->dev;
1346 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1347 return TXRX_CONTINUE;
1349 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1352 hdrlen = ieee80211_get_hdrlen(fc);
1354 if ((ieee80211_drop_802_1x_pae(rx, hdrlen)) ||
1355 (ieee80211_drop_unencrypted(rx, hdrlen)))
1358 err = ieee80211_data_to_8023(rx);
1364 dev->stats.rx_packets++;
1365 dev->stats.rx_bytes += rx->skb->len;
1367 ieee80211_deliver_skb(rx);
1372 static ieee80211_txrx_result
1373 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1375 struct ieee80211_sub_if_data *sdata;
1377 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
1380 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1381 if ((sdata->type == IEEE80211_IF_TYPE_STA ||
1382 sdata->type == IEEE80211_IF_TYPE_IBSS) &&
1383 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
1384 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
1391 static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1392 struct ieee80211_local *local,
1393 ieee80211_rx_handler *handlers,
1394 struct ieee80211_txrx_data *rx,
1395 struct sta_info *sta)
1397 ieee80211_rx_handler *handler;
1398 ieee80211_txrx_result res = TXRX_DROP;
1400 for (handler = handlers; *handler != NULL; handler++) {
1401 res = (*handler)(rx);
1407 I802_DEBUG_INC(local->rx_handlers_drop);
1412 I802_DEBUG_INC(local->rx_handlers_queued);
1418 if (res == TXRX_DROP)
1419 dev_kfree_skb(rx->skb);
1423 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1424 ieee80211_rx_handler *handlers,
1425 struct ieee80211_txrx_data *rx,
1426 struct sta_info *sta)
1428 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1430 dev_kfree_skb(rx->skb);
1433 static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1434 struct ieee80211_hdr *hdr,
1435 struct sta_info *sta,
1436 struct ieee80211_txrx_data *rx)
1439 DECLARE_MAC_BUF(mac);
1440 DECLARE_MAC_BUF(mac2);
1442 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1443 if (rx->skb->len >= hdrlen + 4)
1444 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1448 if (net_ratelimit())
1449 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
1450 "failure from %s to %s keyidx=%d\n",
1451 dev->name, print_mac(mac, hdr->addr2),
1452 print_mac(mac2, hdr->addr1), keyidx);
1456 * Some hardware seem to generate incorrect Michael MIC
1457 * reports; ignore them to avoid triggering countermeasures.
1459 if (net_ratelimit())
1460 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1461 "error for unknown address %s\n",
1462 dev->name, print_mac(mac, hdr->addr2));
1466 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
1467 if (net_ratelimit())
1468 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1469 "error for a frame with no PROTECTED flag (src "
1470 "%s)\n", dev->name, print_mac(mac, hdr->addr2));
1474 if (rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) {
1476 * APs with pairwise keys should never receive Michael MIC
1477 * errors for non-zero keyidx because these are reserved for
1478 * group keys and only the AP is sending real multicast
1479 * frames in the BSS.
1481 if (net_ratelimit())
1482 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1483 "a frame with non-zero keyidx (%d)"
1484 " (src %s)\n", dev->name, keyidx,
1485 print_mac(mac, hdr->addr2));
1489 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1490 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1491 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
1492 if (net_ratelimit())
1493 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1494 "error for a frame that cannot be encrypted "
1495 "(fc=0x%04x) (src %s)\n",
1496 dev->name, rx->fc, print_mac(mac, hdr->addr2));
1500 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
1502 dev_kfree_skb(rx->skb);
1506 ieee80211_rx_handler ieee80211_rx_handlers[] =
1508 ieee80211_rx_h_if_stats,
1509 ieee80211_rx_h_passive_scan,
1510 ieee80211_rx_h_check,
1511 ieee80211_rx_h_decrypt,
1512 ieee80211_rx_h_sta_process,
1513 ieee80211_rx_h_defragment,
1514 ieee80211_rx_h_ps_poll,
1515 ieee80211_rx_h_michael_mic_verify,
1516 /* this must be after decryption - so header is counted in MPDU mic
1517 * must be before pae and data, so QOS_DATA format frames
1518 * are not passed to user space by these functions
1520 ieee80211_rx_h_remove_qos_control,
1521 ieee80211_rx_h_amsdu,
1522 ieee80211_rx_h_data,
1523 ieee80211_rx_h_mgmt,
1527 /* main receive path */
1529 static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1530 u8 *bssid, struct ieee80211_txrx_data *rx,
1531 struct ieee80211_hdr *hdr)
1533 int multicast = is_multicast_ether_addr(hdr->addr1);
1535 switch (sdata->type) {
1536 case IEEE80211_IF_TYPE_STA:
1539 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1540 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1542 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1543 } else if (!multicast &&
1544 compare_ether_addr(sdata->dev->dev_addr,
1546 if (!(sdata->dev->flags & IFF_PROMISC))
1548 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1551 case IEEE80211_IF_TYPE_IBSS:
1554 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1555 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1557 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1558 } else if (!multicast &&
1559 compare_ether_addr(sdata->dev->dev_addr,
1561 if (!(sdata->dev->flags & IFF_PROMISC))
1563 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1564 } else if (!rx->sta)
1565 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1568 case IEEE80211_IF_TYPE_VLAN:
1569 case IEEE80211_IF_TYPE_AP:
1571 if (compare_ether_addr(sdata->dev->dev_addr,
1574 } else if (!ieee80211_bssid_match(bssid,
1575 sdata->dev->dev_addr)) {
1576 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1578 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1580 if (sdata->dev == sdata->local->mdev &&
1581 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1582 /* do not receive anything via
1583 * master device when not scanning */
1586 case IEEE80211_IF_TYPE_WDS:
1588 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1590 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1593 case IEEE80211_IF_TYPE_MNTR:
1594 /* take everything */
1596 case IEEE80211_IF_TYPE_INVALID:
1597 /* should never get here */
1606 * This is the receive path handler. It is called by a low level driver when an
1607 * 802.11 MPDU is received from the hardware.
1609 void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1610 struct ieee80211_rx_status *status)
1612 struct ieee80211_local *local = hw_to_local(hw);
1613 struct ieee80211_sub_if_data *sdata;
1614 struct sta_info *sta;
1615 struct ieee80211_hdr *hdr;
1616 struct ieee80211_txrx_data rx;
1619 struct ieee80211_sub_if_data *prev = NULL;
1620 struct sk_buff *skb_new;
1625 * key references and virtual interfaces are protected using RCU
1626 * and this requires that we are in a read-side RCU section during
1627 * receive processing
1632 * Frames with failed FCS/PLCP checksum are not returned,
1633 * all other frames are returned without radiotap header
1634 * if it was previously present.
1635 * Also, frames with less than 16 bytes are dropped.
1637 skb = ieee80211_rx_monitor(local, skb, status);
1643 hdr = (struct ieee80211_hdr *) skb->data;
1644 memset(&rx, 0, sizeof(rx));
1648 rx.u.rx.status = status;
1649 rx.fc = le16_to_cpu(hdr->frame_control);
1650 type = rx.fc & IEEE80211_FCTL_FTYPE;
1653 * Drivers are required to align the payload data to a four-byte
1654 * boundary, so the last two bits of the address where it starts
1655 * may not be set. The header is required to be directly before
1656 * the payload data, padding like atheros hardware adds which is
1657 * inbetween the 802.11 header and the payload is not supported,
1658 * the driver is required to move the 802.11 header further back
1661 hdrlen = ieee80211_get_hdrlen(rx.fc);
1662 WARN_ON_ONCE(((unsigned long)(skb->data + hdrlen)) & 3);
1664 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
1665 local->dot11ReceivedFragmentCount++;
1667 sta = rx.sta = sta_info_get(local, hdr->addr2);
1669 rx.dev = rx.sta->dev;
1670 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1673 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1674 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
1678 if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
1679 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
1681 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
1682 sta) != TXRX_CONTINUE)
1686 if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) &&
1687 !atomic_read(&local->iff_promiscs) &&
1688 !is_multicast_ether_addr(hdr->addr1)) {
1689 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1690 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
1697 bssid = ieee80211_get_bssid(hdr, skb->len);
1699 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1700 if (!netif_running(sdata->dev))
1703 if (sdata->type == IEEE80211_IF_TYPE_MNTR)
1706 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1707 prepres = prepare_for_handlers(sdata, bssid, &rx, hdr);
1708 /* prepare_for_handlers can change sta */
1715 * frame is destined for this interface, but if it's not
1716 * also for the previous one we handle that after the
1717 * loop to avoid copying the SKB once too much
1726 * frame was destined for the previous interface
1727 * so invoke RX handlers for it
1730 skb_new = skb_copy(skb, GFP_ATOMIC);
1732 if (net_ratelimit())
1733 printk(KERN_DEBUG "%s: failed to copy "
1734 "multicast frame for %s",
1735 wiphy_name(local->hw.wiphy),
1742 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1750 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1761 EXPORT_SYMBOL(__ieee80211_rx);
1763 /* This is a version of the rx handler that can be called from hard irq
1764 * context. Post the skb on the queue and schedule the tasklet */
1765 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
1766 struct ieee80211_rx_status *status)
1768 struct ieee80211_local *local = hw_to_local(hw);
1770 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
1772 skb->dev = local->mdev;
1773 /* copy status into skb->cb for use by tasklet */
1774 memcpy(skb->cb, status, sizeof(*status));
1775 skb->pkt_type = IEEE80211_RX_MSG;
1776 skb_queue_tail(&local->skb_queue, skb);
1777 tasklet_schedule(&local->tasklet);
1779 EXPORT_SYMBOL(ieee80211_rx_irqsafe);