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"
30 * these don't have dev/sdata fields in the rx data
31 * The sta value should also not be used because it may
32 * be NULL even though a STA (in IBSS mode) will be added.
35 static ieee80211_txrx_result
36 ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
38 u8 *data = rx->skb->data;
41 /* does the frame have a qos control field? */
42 if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
43 u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
44 /* frame has qos control */
45 tid = qc[0] & QOS_CONTROL_TID_MASK;
47 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
48 /* Separate TID for management frames */
49 tid = NUM_RX_DATA_QUEUES - 1;
51 /* no qos control present */
52 tid = 0; /* 802.1d - Best Effort */
56 I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
57 /* only a debug counter, sta might not be assigned properly yet */
59 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
62 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
63 * For now, set skb->priority to 0 for other cases. */
64 rx->skb->priority = (tid > 7) ? 0 : tid;
69 static ieee80211_txrx_result
70 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
72 struct ieee80211_local *local = rx->local;
73 struct sk_buff *skb = rx->skb;
74 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
75 u32 load = 0, hdrtime;
76 struct ieee80211_rate *rate;
77 struct ieee80211_hw_mode *mode = local->hw.conf.mode;
80 /* Estimate total channel use caused by this frame */
82 if (unlikely(mode->num_rates < 0))
85 rate = &mode->rates[0];
86 for (i = 0; i < mode->num_rates; i++) {
87 if (mode->rates[i].val == rx->u.rx.status->rate) {
88 rate = &mode->rates[i];
93 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
94 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
96 if (mode->mode == MODE_IEEE80211A ||
97 (mode->mode == MODE_IEEE80211G &&
98 rate->flags & IEEE80211_RATE_ERP))
99 hdrtime = CHAN_UTIL_HDR_SHORT;
101 hdrtime = CHAN_UTIL_HDR_LONG;
104 if (!is_multicast_ether_addr(hdr->addr1))
107 load += skb->len * rate->rate_inv;
109 /* Divide channel_use by 8 to avoid wrapping around the counter */
110 load >>= CHAN_UTIL_SHIFT;
111 local->channel_use_raw += load;
112 rx->u.rx.load = load;
114 return TXRX_CONTINUE;
117 ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
119 ieee80211_rx_h_parse_qos,
120 ieee80211_rx_h_load_stats,
126 static ieee80211_txrx_result
127 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
130 rx->sta->channel_use_raw += rx->u.rx.load;
131 rx->sdata->channel_use_raw += rx->u.rx.load;
132 return TXRX_CONTINUE;
136 ieee80211_rx_monitor(struct net_device *dev, struct sk_buff *skb,
137 struct ieee80211_rx_status *status)
139 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
140 struct ieee80211_rate *rate;
141 struct ieee80211_rtap_hdr {
142 struct ieee80211_radiotap_header hdr;
148 u8 padding_for_rxflags;
150 } __attribute__ ((packed)) *rthdr;
154 if (status->flag & RX_FLAG_RADIOTAP)
157 if (skb_headroom(skb) < sizeof(*rthdr)) {
158 I802_DEBUG_INC(local->rx_expand_skb_head);
159 if (pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) {
165 rthdr = (struct ieee80211_rtap_hdr *) skb_push(skb, sizeof(*rthdr));
166 memset(rthdr, 0, sizeof(*rthdr));
167 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
168 rthdr->hdr.it_present =
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));
174 rthdr->flags = local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS ?
175 IEEE80211_RADIOTAP_F_FCS : 0;
177 /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
180 (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
181 rthdr->rx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
183 rate = ieee80211_get_rate(local, status->phymode, status->rate);
185 rthdr->rate = rate->rate / 5;
187 rthdr->chan_freq = cpu_to_le16(status->freq);
189 status->phymode == MODE_IEEE80211A ?
190 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ) :
191 cpu_to_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ);
192 rthdr->antsignal = status->ssi;
195 dev->stats.rx_packets++;
196 dev->stats.rx_bytes += skb->len;
198 skb_set_mac_header(skb, 0);
199 skb->ip_summed = CHECKSUM_UNNECESSARY;
200 skb->pkt_type = PACKET_OTHERHOST;
201 skb->protocol = htons(ETH_P_802_2);
202 memset(skb->cb, 0, sizeof(skb->cb));
206 static ieee80211_txrx_result
207 ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
209 if (rx->sdata->type == IEEE80211_IF_TYPE_MNTR) {
210 ieee80211_rx_monitor(rx->dev, rx->skb, rx->u.rx.status);
215 * Drop frames with failed FCS/PLCP checksums here, they are only
216 * relevant for monitor mode, the rest of the stack should never
219 if (rx->u.rx.status->flag &
220 (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
223 if (rx->u.rx.status->flag & RX_FLAG_RADIOTAP)
224 skb_pull(rx->skb, ieee80211_get_radiotap_len(rx->skb->data));
226 return TXRX_CONTINUE;
229 static ieee80211_txrx_result
230 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
232 struct ieee80211_local *local = rx->local;
233 struct sk_buff *skb = rx->skb;
235 if (unlikely(local->sta_scanning != 0)) {
236 ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
240 if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
241 /* scanning finished during invoking of handlers */
242 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
246 return TXRX_CONTINUE;
249 static ieee80211_txrx_result
250 ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
252 struct ieee80211_hdr *hdr;
253 hdr = (struct ieee80211_hdr *) rx->skb->data;
255 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
256 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
257 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
258 rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
260 if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
261 rx->local->dot11FrameDuplicateCount++;
262 rx->sta->num_duplicates++;
266 rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
269 if ((rx->local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) &&
270 rx->skb->len > FCS_LEN)
271 skb_trim(rx->skb, rx->skb->len - FCS_LEN);
273 if (unlikely(rx->skb->len < 16)) {
274 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
278 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
279 rx->skb->pkt_type = PACKET_OTHERHOST;
280 else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0)
281 rx->skb->pkt_type = PACKET_HOST;
282 else if (is_multicast_ether_addr(hdr->addr1)) {
283 if (is_broadcast_ether_addr(hdr->addr1))
284 rx->skb->pkt_type = PACKET_BROADCAST;
286 rx->skb->pkt_type = PACKET_MULTICAST;
288 rx->skb->pkt_type = PACKET_OTHERHOST;
290 /* Drop disallowed frame classes based on STA auth/assoc state;
291 * IEEE 802.11, Chap 5.5.
293 * 80211.o does filtering only based on association state, i.e., it
294 * drops Class 3 frames from not associated stations. hostapd sends
295 * deauth/disassoc frames when needed. In addition, hostapd is
296 * responsible for filtering on both auth and assoc states.
298 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
299 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
300 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
301 rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
302 (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
303 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
304 !(rx->fc & IEEE80211_FCTL_TODS) &&
305 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
306 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
307 /* Drop IBSS frames and frames for other hosts
312 if (!rx->local->apdev)
315 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
316 ieee80211_msg_sta_not_assoc);
320 return TXRX_CONTINUE;
324 static ieee80211_txrx_result
325 ieee80211_rx_h_load_key(struct ieee80211_txrx_data *rx)
327 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
330 struct ieee80211_key *stakey = NULL;
335 * There are three types of keys:
337 * - PTK (pairwise keys)
338 * - STK (station-to-station pairwise keys)
340 * When selecting a key, we have to distinguish between multicast
341 * (including broadcast) and unicast frames, the latter can only
342 * use PTKs and STKs while the former always use GTKs. Unless, of
343 * course, actual WEP keys ("pre-RSNA") are used, then unicast
344 * frames can also use key indizes like GTKs. Hence, if we don't
345 * have a PTK/STK we check the key index for a WEP key.
347 * Note that in a regular BSS, multicast frames are sent by the
348 * AP only, associated stations unicast the frame to the AP first
349 * which then multicasts it on their behalf.
351 * There is also a slight problem in IBSS mode: GTKs are negotiated
352 * with each station, that is something we don't currently handle.
353 * The spec seems to expect that one negotiates the same key with
354 * every station but there's no such requirement; VLANs could be
358 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
359 return TXRX_CONTINUE;
362 * No point in finding a key if the frame is neither
363 * addressed to us nor a multicast frame.
365 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
366 return TXRX_CONTINUE;
369 stakey = rcu_dereference(rx->sta->key);
371 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
375 * The device doesn't give us the IV so we won't be
376 * able to look up the key. That's ok though, we
377 * don't need to decrypt the frame, we just won't
378 * be able to keep statistics accurate.
379 * Except for key threshold notifications, should
380 * we somehow allow the driver to tell us which key
381 * the hardware used if this flag is set?
383 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
384 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
385 return TXRX_CONTINUE;
387 hdrlen = ieee80211_get_hdrlen(rx->fc);
389 if (rx->skb->len < 8 + hdrlen)
390 return TXRX_DROP; /* TODO: count this? */
393 * no need to call ieee80211_wep_get_keyidx,
394 * it verifies a bunch of things we've done already
396 keyidx = rx->skb->data[hdrlen + 3] >> 6;
398 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
401 * RSNA-protected unicast frames should always be sent with
402 * pairwise or station-to-station keys, but for WEP we allow
403 * using a key index as well.
405 if (rx->key && rx->key->conf.alg != ALG_WEP &&
406 !is_multicast_ether_addr(hdr->addr1))
411 rx->key->tx_rx_count++;
412 if (unlikely(rx->local->key_tx_rx_threshold &&
413 rx->key->tx_rx_count >
414 rx->local->key_tx_rx_threshold)) {
415 ieee80211_key_threshold_notify(rx->dev, rx->key,
420 return TXRX_CONTINUE;
423 static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
425 struct ieee80211_sub_if_data *sdata;
426 DECLARE_MAC_BUF(mac);
428 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
431 atomic_inc(&sdata->bss->num_sta_ps);
432 sta->flags |= WLAN_STA_PS;
434 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
435 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
436 dev->name, print_mac(mac, sta->addr), sta->aid);
437 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
440 static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
442 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
445 struct ieee80211_sub_if_data *sdata;
446 struct ieee80211_tx_packet_data *pkt_data;
447 DECLARE_MAC_BUF(mac);
449 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
451 atomic_dec(&sdata->bss->num_sta_ps);
452 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
454 if (!skb_queue_empty(&sta->ps_tx_buf)) {
455 if (local->ops->set_tim)
456 local->ops->set_tim(local_to_hw(local), sta->aid, 0);
458 bss_tim_clear(local, sdata->bss, sta->aid);
460 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
461 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
462 dev->name, print_mac(mac, sta->addr), sta->aid);
463 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
464 /* Send all buffered frames to the station */
465 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
466 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
468 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
471 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
472 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
473 local->total_ps_buffered--;
475 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
476 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
477 "since STA not sleeping anymore\n", dev->name,
478 print_mac(mac, sta->addr), sta->aid);
479 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
480 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
487 static ieee80211_txrx_result
488 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
490 struct sta_info *sta = rx->sta;
491 struct net_device *dev = rx->dev;
492 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
495 return TXRX_CONTINUE;
497 /* Update last_rx only for IBSS packets which are for the current
498 * BSSID to avoid keeping the current IBSS network alive in cases where
499 * other STAs are using different BSSID. */
500 if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
501 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
502 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
503 sta->last_rx = jiffies;
505 if (!is_multicast_ether_addr(hdr->addr1) ||
506 rx->sdata->type == IEEE80211_IF_TYPE_STA) {
507 /* Update last_rx only for unicast frames in order to prevent
508 * the Probe Request frames (the only broadcast frames from a
509 * STA in infrastructure mode) from keeping a connection alive.
511 sta->last_rx = jiffies;
514 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
515 return TXRX_CONTINUE;
518 sta->rx_bytes += rx->skb->len;
519 sta->last_rssi = rx->u.rx.status->ssi;
520 sta->last_signal = rx->u.rx.status->signal;
521 sta->last_noise = rx->u.rx.status->noise;
523 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
524 /* Change STA power saving mode only in the end of a frame
525 * exchange sequence */
526 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
527 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
528 else if (!(sta->flags & WLAN_STA_PS) &&
529 (rx->fc & IEEE80211_FCTL_PM))
530 ap_sta_ps_start(dev, sta);
533 /* Drop data::nullfunc frames silently, since they are used only to
534 * control station power saving mode. */
535 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
536 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
537 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
538 /* Update counter and free packet here to avoid counting this
539 * as a dropped packed. */
541 dev_kfree_skb(rx->skb);
545 return TXRX_CONTINUE;
546 } /* ieee80211_rx_h_sta_process */
548 static ieee80211_txrx_result
549 ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
551 if (!rx->sta || !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
552 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
553 !rx->key || rx->key->conf.alg != ALG_WEP ||
554 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
555 return TXRX_CONTINUE;
557 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
558 if (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
559 !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED))
560 if (ieee80211_wep_is_weak_iv(rx->skb, rx->key))
561 rx->sta->wep_weak_iv_count++;
563 return TXRX_CONTINUE;
566 static ieee80211_txrx_result
567 ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
569 if ((rx->key && rx->key->conf.alg != ALG_WEP) ||
570 !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
571 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
572 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
573 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
574 return TXRX_CONTINUE;
578 printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
583 if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) {
584 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
586 printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
587 "failed\n", rx->dev->name);
590 } else if (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) {
591 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
593 skb_trim(rx->skb, rx->skb->len - 4);
596 return TXRX_CONTINUE;
599 static inline struct ieee80211_fragment_entry *
600 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
601 unsigned int frag, unsigned int seq, int rx_queue,
602 struct sk_buff **skb)
604 struct ieee80211_fragment_entry *entry;
607 idx = sdata->fragment_next;
608 entry = &sdata->fragments[sdata->fragment_next++];
609 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
610 sdata->fragment_next = 0;
612 if (!skb_queue_empty(&entry->skb_list)) {
613 #ifdef CONFIG_MAC80211_DEBUG
614 struct ieee80211_hdr *hdr =
615 (struct ieee80211_hdr *) entry->skb_list.next->data;
616 DECLARE_MAC_BUF(mac);
617 DECLARE_MAC_BUF(mac2);
618 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
619 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
620 "addr1=%s addr2=%s\n",
621 sdata->dev->name, idx,
622 jiffies - entry->first_frag_time, entry->seq,
623 entry->last_frag, print_mac(mac, hdr->addr1),
624 print_mac(mac2, hdr->addr2));
625 #endif /* CONFIG_MAC80211_DEBUG */
626 __skb_queue_purge(&entry->skb_list);
629 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
631 entry->first_frag_time = jiffies;
633 entry->rx_queue = rx_queue;
634 entry->last_frag = frag;
636 entry->extra_len = 0;
641 static inline struct ieee80211_fragment_entry *
642 ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
643 u16 fc, unsigned int frag, unsigned int seq,
644 int rx_queue, struct ieee80211_hdr *hdr)
646 struct ieee80211_fragment_entry *entry;
649 idx = sdata->fragment_next;
650 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
651 struct ieee80211_hdr *f_hdr;
656 idx = IEEE80211_FRAGMENT_MAX - 1;
658 entry = &sdata->fragments[idx];
659 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
660 entry->rx_queue != rx_queue ||
661 entry->last_frag + 1 != frag)
664 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
665 f_fc = le16_to_cpu(f_hdr->frame_control);
667 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
668 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
669 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
672 if (entry->first_frag_time + 2 * HZ < jiffies) {
673 __skb_queue_purge(&entry->skb_list);
682 static ieee80211_txrx_result
683 ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
685 struct ieee80211_hdr *hdr;
687 unsigned int frag, seq;
688 struct ieee80211_fragment_entry *entry;
690 DECLARE_MAC_BUF(mac);
692 hdr = (struct ieee80211_hdr *) rx->skb->data;
693 sc = le16_to_cpu(hdr->seq_ctrl);
694 frag = sc & IEEE80211_SCTL_FRAG;
696 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
697 (rx->skb)->len < 24 ||
698 is_multicast_ether_addr(hdr->addr1))) {
702 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
704 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
707 /* This is the first fragment of a new frame. */
708 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
709 rx->u.rx.queue, &(rx->skb));
710 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
711 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
712 /* Store CCMP PN so that we can verify that the next
713 * fragment has a sequential PN value. */
715 memcpy(entry->last_pn,
716 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
722 /* This is a fragment for a frame that should already be pending in
723 * fragment cache. Add this fragment to the end of the pending entry.
725 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
726 rx->u.rx.queue, hdr);
728 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
732 /* Verify that MPDUs within one MSDU have sequential PN values.
733 * (IEEE 802.11i, 8.3.3.4.5) */
736 u8 pn[CCMP_PN_LEN], *rpn;
737 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
739 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
740 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
745 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
746 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
748 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
750 " PN=%02x%02x%02x%02x%02x%02x "
751 "(expected %02x%02x%02x%02x%02x%02x)\n",
752 rx->dev->name, print_mac(mac, hdr->addr2),
753 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
754 rpn[5], pn[0], pn[1], pn[2], pn[3],
758 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
761 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
762 __skb_queue_tail(&entry->skb_list, rx->skb);
763 entry->last_frag = frag;
764 entry->extra_len += rx->skb->len;
765 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
770 rx->skb = __skb_dequeue(&entry->skb_list);
771 if (skb_tailroom(rx->skb) < entry->extra_len) {
772 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
773 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
775 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
776 __skb_queue_purge(&entry->skb_list);
780 while ((skb = __skb_dequeue(&entry->skb_list))) {
781 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
785 /* Complete frame has been reassembled - process it now */
786 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
790 rx->sta->rx_packets++;
791 if (is_multicast_ether_addr(hdr->addr1))
792 rx->local->dot11MulticastReceivedFrameCount++;
794 ieee80211_led_rx(rx->local);
795 return TXRX_CONTINUE;
798 static ieee80211_txrx_result
799 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
803 DECLARE_MAC_BUF(mac);
805 if (likely(!rx->sta ||
806 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
807 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
808 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
809 return TXRX_CONTINUE;
811 skb = skb_dequeue(&rx->sta->tx_filtered);
813 skb = skb_dequeue(&rx->sta->ps_tx_buf);
815 rx->local->total_ps_buffered--;
817 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
818 skb_queue_empty(&rx->sta->ps_tx_buf);
821 struct ieee80211_hdr *hdr =
822 (struct ieee80211_hdr *) skb->data;
824 /* tell TX path to send one frame even though the STA may
825 * still remain is PS mode after this frame exchange */
828 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
829 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
830 print_mac(mac, rx->sta->addr), rx->sta->aid,
831 skb_queue_len(&rx->sta->ps_tx_buf));
832 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
834 /* Use MoreData flag to indicate whether there are more
835 * buffered frames for this STA */
836 if (no_pending_pkts) {
837 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
838 rx->sta->flags &= ~WLAN_STA_TIM;
840 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
844 if (no_pending_pkts) {
845 if (rx->local->ops->set_tim)
846 rx->local->ops->set_tim(local_to_hw(rx->local),
849 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
851 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
852 } else if (!rx->u.rx.sent_ps_buffered) {
853 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
854 "though there is no buffered frames for it\n",
855 rx->dev->name, print_mac(mac, rx->sta->addr));
856 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
860 /* Free PS Poll skb here instead of returning TXRX_DROP that would
861 * count as an dropped frame. */
862 dev_kfree_skb(rx->skb);
867 static ieee80211_txrx_result
868 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
871 u8 *data = rx->skb->data;
872 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
874 if (!WLAN_FC_IS_QOS_DATA(fc))
875 return TXRX_CONTINUE;
877 /* remove the qos control field, update frame type and meta-data */
878 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
879 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
880 /* change frame type to non QOS */
881 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
882 hdr->frame_control = cpu_to_le16(fc);
884 return TXRX_CONTINUE;
887 static ieee80211_txrx_result
888 ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
890 if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
891 rx->sdata->type != IEEE80211_IF_TYPE_STA &&
892 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
893 /* Pass both encrypted and unencrypted EAPOL frames to user
894 * space for processing. */
895 if (!rx->local->apdev)
897 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
898 ieee80211_msg_normal);
902 if (unlikely(rx->sdata->ieee802_1x &&
903 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
904 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
905 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
906 !ieee80211_is_eapol(rx->skb))) {
907 #ifdef CONFIG_MAC80211_DEBUG
908 struct ieee80211_hdr *hdr =
909 (struct ieee80211_hdr *) rx->skb->data;
910 DECLARE_MAC_BUF(mac);
911 printk(KERN_DEBUG "%s: dropped frame from %s"
912 " (unauthorized port)\n", rx->dev->name,
913 print_mac(mac, hdr->addr2));
914 #endif /* CONFIG_MAC80211_DEBUG */
918 return TXRX_CONTINUE;
921 static ieee80211_txrx_result
922 ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
925 * Pass through unencrypted frames if the hardware has
926 * decrypted them already.
928 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
929 return TXRX_CONTINUE;
931 /* Drop unencrypted frames if key is set. */
932 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
933 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
934 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
935 (rx->key || rx->sdata->drop_unencrypted) &&
936 (rx->sdata->eapol == 0 ||
937 !ieee80211_is_eapol(rx->skb)))) {
939 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
940 "encryption\n", rx->dev->name);
943 return TXRX_CONTINUE;
946 static ieee80211_txrx_result
947 ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
949 struct net_device *dev = rx->dev;
950 struct ieee80211_local *local = rx->local;
951 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
952 u16 fc, hdrlen, ethertype;
956 struct sk_buff *skb = rx->skb, *skb2;
957 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
958 DECLARE_MAC_BUF(mac);
959 DECLARE_MAC_BUF(mac2);
960 DECLARE_MAC_BUF(mac3);
961 DECLARE_MAC_BUF(mac4);
964 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
965 return TXRX_CONTINUE;
967 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
970 hdrlen = ieee80211_get_hdrlen(fc);
972 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
974 * IEEE 802.11 address fields:
975 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
976 * 0 0 DA SA BSSID n/a
977 * 0 1 DA BSSID SA n/a
978 * 1 0 BSSID SA DA n/a
982 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
983 case IEEE80211_FCTL_TODS:
985 memcpy(dst, hdr->addr3, ETH_ALEN);
986 memcpy(src, hdr->addr2, ETH_ALEN);
988 if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
989 sdata->type != IEEE80211_IF_TYPE_VLAN)) {
991 printk(KERN_DEBUG "%s: dropped ToDS frame "
992 "(BSSID=%s SA=%s DA=%s)\n",
994 print_mac(mac, hdr->addr1),
995 print_mac(mac2, hdr->addr2),
996 print_mac(mac3, hdr->addr3));
1000 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1002 memcpy(dst, hdr->addr3, ETH_ALEN);
1003 memcpy(src, hdr->addr4, ETH_ALEN);
1005 if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
1006 if (net_ratelimit())
1007 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
1008 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1010 print_mac(mac, hdr->addr1),
1011 print_mac(mac2, hdr->addr2),
1012 print_mac(mac3, hdr->addr3),
1013 print_mac(mac4, hdr->addr4));
1017 case IEEE80211_FCTL_FROMDS:
1019 memcpy(dst, hdr->addr1, ETH_ALEN);
1020 memcpy(src, hdr->addr3, ETH_ALEN);
1022 if (sdata->type != IEEE80211_IF_TYPE_STA ||
1023 (is_multicast_ether_addr(dst) &&
1024 !compare_ether_addr(src, dev->dev_addr)))
1029 memcpy(dst, hdr->addr1, ETH_ALEN);
1030 memcpy(src, hdr->addr2, ETH_ALEN);
1032 if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
1033 if (net_ratelimit()) {
1034 printk(KERN_DEBUG "%s: dropped IBSS frame "
1035 "(DA=%s SA=%s BSSID=%s)\n",
1037 print_mac(mac, hdr->addr1),
1038 print_mac(mac2, hdr->addr2),
1039 print_mac(mac3, hdr->addr3));
1046 payload = skb->data + hdrlen;
1048 if (unlikely(skb->len - hdrlen < 8)) {
1049 if (net_ratelimit()) {
1050 printk(KERN_DEBUG "%s: RX too short data frame "
1051 "payload\n", dev->name);
1056 ethertype = (payload[6] << 8) | payload[7];
1058 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1059 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1060 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1061 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1062 * replace EtherType */
1063 skb_pull(skb, hdrlen + 6);
1064 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1065 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1067 struct ethhdr *ehdr;
1069 skb_pull(skb, hdrlen);
1070 len = htons(skb->len);
1071 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1072 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1073 memcpy(ehdr->h_source, src, ETH_ALEN);
1074 ehdr->h_proto = len;
1080 dev->stats.rx_packets++;
1081 dev->stats.rx_bytes += skb->len;
1083 if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP
1084 || sdata->type == IEEE80211_IF_TYPE_VLAN) &&
1085 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
1086 if (is_multicast_ether_addr(skb->data)) {
1087 /* send multicast frames both to higher layers in
1088 * local net stack and back to the wireless media */
1089 skb2 = skb_copy(skb, GFP_ATOMIC);
1090 if (!skb2 && net_ratelimit())
1091 printk(KERN_DEBUG "%s: failed to clone "
1092 "multicast frame\n", dev->name);
1094 struct sta_info *dsta;
1095 dsta = sta_info_get(local, skb->data);
1096 if (dsta && !dsta->dev) {
1097 if (net_ratelimit())
1098 printk(KERN_DEBUG "Station with null "
1099 "dev structure!\n");
1100 } else if (dsta && dsta->dev == dev) {
1101 /* Destination station is associated to this
1102 * AP, so send the frame directly to it and
1103 * do not pass the frame to local net stack.
1114 /* deliver to local stack */
1115 skb->protocol = eth_type_trans(skb, dev);
1116 memset(skb->cb, 0, sizeof(skb->cb));
1121 /* send to wireless media */
1122 skb2->protocol = __constant_htons(ETH_P_802_3);
1123 skb_set_network_header(skb2, 0);
1124 skb_set_mac_header(skb2, 0);
1125 dev_queue_xmit(skb2);
1131 static ieee80211_txrx_result
1132 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1134 struct ieee80211_sub_if_data *sdata;
1136 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
1139 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1140 if ((sdata->type == IEEE80211_IF_TYPE_STA ||
1141 sdata->type == IEEE80211_IF_TYPE_IBSS) &&
1142 !rx->local->user_space_mlme) {
1143 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
1145 /* Management frames are sent to hostapd for processing */
1146 if (!rx->local->apdev)
1148 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
1149 ieee80211_msg_normal);
1154 static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1155 struct ieee80211_local *local,
1156 ieee80211_rx_handler *handlers,
1157 struct ieee80211_txrx_data *rx,
1158 struct sta_info *sta)
1160 ieee80211_rx_handler *handler;
1161 ieee80211_txrx_result res = TXRX_DROP;
1163 for (handler = handlers; *handler != NULL; handler++) {
1164 res = (*handler)(rx);
1170 I802_DEBUG_INC(local->rx_handlers_drop);
1175 I802_DEBUG_INC(local->rx_handlers_queued);
1181 if (res == TXRX_DROP)
1182 dev_kfree_skb(rx->skb);
1186 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1187 ieee80211_rx_handler *handlers,
1188 struct ieee80211_txrx_data *rx,
1189 struct sta_info *sta)
1191 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1193 dev_kfree_skb(rx->skb);
1196 static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1197 struct ieee80211_hdr *hdr,
1198 struct sta_info *sta,
1199 struct ieee80211_txrx_data *rx)
1202 DECLARE_MAC_BUF(mac);
1203 DECLARE_MAC_BUF(mac2);
1205 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1206 if (rx->skb->len >= hdrlen + 4)
1207 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1211 if (net_ratelimit())
1212 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
1213 "failure from %s to %s keyidx=%d\n",
1214 dev->name, print_mac(mac, hdr->addr2),
1215 print_mac(mac2, hdr->addr1), keyidx);
1219 * Some hardware seem to generate incorrect Michael MIC
1220 * reports; ignore them to avoid triggering countermeasures.
1222 if (net_ratelimit())
1223 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1224 "error for unknown address %s\n",
1225 dev->name, print_mac(mac, hdr->addr2));
1229 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
1230 if (net_ratelimit())
1231 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1232 "error for a frame with no PROTECTED flag (src "
1233 "%s)\n", dev->name, print_mac(mac, hdr->addr2));
1237 if (rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) {
1239 * APs with pairwise keys should never receive Michael MIC
1240 * errors for non-zero keyidx because these are reserved for
1241 * group keys and only the AP is sending real multicast
1242 * frames in the BSS.
1244 if (net_ratelimit())
1245 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1246 "a frame with non-zero keyidx (%d)"
1247 " (src %s)\n", dev->name, keyidx,
1248 print_mac(mac, hdr->addr2));
1252 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1253 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1254 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
1255 if (net_ratelimit())
1256 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1257 "error for a frame that cannot be encrypted "
1258 "(fc=0x%04x) (src %s)\n",
1259 dev->name, rx->fc, print_mac(mac, hdr->addr2));
1263 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
1265 dev_kfree_skb(rx->skb);
1269 ieee80211_rx_handler ieee80211_rx_handlers[] =
1271 ieee80211_rx_h_if_stats,
1272 ieee80211_rx_h_monitor,
1273 ieee80211_rx_h_passive_scan,
1274 ieee80211_rx_h_check,
1275 ieee80211_rx_h_load_key,
1276 ieee80211_rx_h_sta_process,
1277 ieee80211_rx_h_ccmp_decrypt,
1278 ieee80211_rx_h_tkip_decrypt,
1279 ieee80211_rx_h_wep_weak_iv_detection,
1280 ieee80211_rx_h_wep_decrypt,
1281 ieee80211_rx_h_defragment,
1282 ieee80211_rx_h_ps_poll,
1283 ieee80211_rx_h_michael_mic_verify,
1284 /* this must be after decryption - so header is counted in MPDU mic
1285 * must be before pae and data, so QOS_DATA format frames
1286 * are not passed to user space by these functions
1288 ieee80211_rx_h_remove_qos_control,
1289 ieee80211_rx_h_802_1x_pae,
1290 ieee80211_rx_h_drop_unencrypted,
1291 ieee80211_rx_h_data,
1292 ieee80211_rx_h_mgmt,
1296 /* main receive path */
1298 static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1299 u8 *bssid, struct ieee80211_txrx_data *rx,
1300 struct ieee80211_hdr *hdr)
1302 int multicast = is_multicast_ether_addr(hdr->addr1);
1304 switch (sdata->type) {
1305 case IEEE80211_IF_TYPE_STA:
1308 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1309 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1311 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1312 } else if (!multicast &&
1313 compare_ether_addr(sdata->dev->dev_addr,
1315 if (!(sdata->flags & IEEE80211_SDATA_PROMISC))
1317 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1320 case IEEE80211_IF_TYPE_IBSS:
1323 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1324 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1326 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1327 } else if (!multicast &&
1328 compare_ether_addr(sdata->dev->dev_addr,
1330 if (!(sdata->flags & IEEE80211_SDATA_PROMISC))
1332 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1333 } else if (!rx->sta)
1334 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1337 case IEEE80211_IF_TYPE_AP:
1339 if (compare_ether_addr(sdata->dev->dev_addr,
1342 } else if (!ieee80211_bssid_match(bssid,
1343 sdata->dev->dev_addr)) {
1344 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1346 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
1348 if (sdata->dev == sdata->local->mdev &&
1349 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
1350 /* do not receive anything via
1351 * master device when not scanning */
1354 case IEEE80211_IF_TYPE_WDS:
1356 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1358 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1367 * This is the receive path handler. It is called by a low level driver when an
1368 * 802.11 MPDU is received from the hardware.
1370 void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1371 struct ieee80211_rx_status *status)
1373 struct ieee80211_local *local = hw_to_local(hw);
1374 struct ieee80211_sub_if_data *sdata;
1375 struct sta_info *sta;
1376 struct ieee80211_hdr *hdr;
1377 struct ieee80211_txrx_data rx;
1379 int radiotap_len = 0, prepres;
1380 struct ieee80211_sub_if_data *prev = NULL;
1381 struct sk_buff *skb_new;
1385 if (status->flag & RX_FLAG_RADIOTAP) {
1386 radiotap_len = ieee80211_get_radiotap_len(skb->data);
1387 skb_pull(skb, radiotap_len);
1391 * key references are protected using RCU and this requires that
1392 * we are in a read-site RCU section during receive processing
1396 hdr = (struct ieee80211_hdr *) skb->data;
1397 memset(&rx, 0, sizeof(rx));
1401 rx.u.rx.status = status;
1402 rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0;
1403 type = rx.fc & IEEE80211_FCTL_FTYPE;
1405 bogon = status->flag & (RX_FLAG_FAILED_FCS_CRC |
1406 RX_FLAG_FAILED_PLCP_CRC);
1408 if (!bogon && (type == IEEE80211_FTYPE_DATA ||
1409 type == IEEE80211_FTYPE_MGMT))
1410 local->dot11ReceivedFragmentCount++;
1412 if (!bogon && skb->len >= 16) {
1413 sta = rx.sta = sta_info_get(local, hdr->addr2);
1415 rx.dev = rx.sta->dev;
1416 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1419 sta = rx.sta = NULL;
1421 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1422 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
1426 if (unlikely(local->sta_scanning))
1427 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
1429 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
1430 sta) != TXRX_CONTINUE)
1434 skb_push(skb, radiotap_len);
1435 if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) &&
1436 !local->iff_promiscs && !is_multicast_ether_addr(hdr->addr1)) {
1437 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1438 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
1445 bssid = ieee80211_get_bssid(hdr, skb->len - radiotap_len);
1447 read_lock(&local->sub_if_lock);
1448 list_for_each_entry(sdata, &local->sub_if_list, list) {
1449 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1451 if (!netif_running(sdata->dev))
1454 prepres = prepare_for_handlers(sdata, bssid, &rx, hdr);
1455 /* prepare_for_handlers can change sta */
1462 * frame is destined for this interface, but if it's not
1463 * also for the previous one we handle that after the
1464 * loop to avoid copying the SKB once too much
1473 * frame was destined for the previous interface
1474 * so invoke RX handlers for it
1477 skb_new = skb_copy(skb, GFP_ATOMIC);
1479 if (net_ratelimit())
1480 printk(KERN_DEBUG "%s: failed to copy "
1481 "multicast frame for %s",
1482 local->mdev->name, prev->dev->name);
1488 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1496 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1500 read_unlock(&local->sub_if_lock);
1508 EXPORT_SYMBOL(__ieee80211_rx);
1510 /* This is a version of the rx handler that can be called from hard irq
1511 * context. Post the skb on the queue and schedule the tasklet */
1512 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
1513 struct ieee80211_rx_status *status)
1515 struct ieee80211_local *local = hw_to_local(hw);
1517 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
1519 skb->dev = local->mdev;
1520 /* copy status into skb->cb for use by tasklet */
1521 memcpy(skb->cb, status, sizeof(*status));
1522 skb->pkt_type = IEEE80211_RX_MSG;
1523 skb_queue_tail(&local->skb_queue, skb);
1524 tasklet_schedule(&local->tasklet);
1526 EXPORT_SYMBOL(ieee80211_rx_irqsafe);