blob: e2c6f5cd1cf747678b4128b170078d7b1a96ad50 [file] [log] [blame]
Johannes Berg571ecf62007-07-27 15:43:22 +02001/*
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>
6 *
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.
10 */
11
12#include <linux/kernel.h>
13#include <linux/skbuff.h>
14#include <linux/netdevice.h>
15#include <linux/etherdevice.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020016#include <net/mac80211.h>
17#include <net/ieee80211_radiotap.h>
18
19#include "ieee80211_i.h"
20#include "ieee80211_led.h"
21#include "ieee80211_common.h"
22#include "wep.h"
23#include "wpa.h"
24#include "tkip.h"
25#include "wme.h"
26
27/* pre-rx handlers
28 *
29 * these don't have dev/sdata fields in the rx data
Johannes Berg52865dfd2007-07-27 15:43:22 +020030 * The sta value should also not be used because it may
31 * be NULL even though a STA (in IBSS mode) will be added.
Johannes Berg571ecf62007-07-27 15:43:22 +020032 */
33
34static ieee80211_txrx_result
Johannes Berg6e0d1142007-07-27 15:43:22 +020035ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
36{
37 u8 *data = rx->skb->data;
38 int tid;
39
40 /* does the frame have a qos control field? */
41 if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
42 u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
43 /* frame has qos control */
44 tid = qc[0] & QOS_CONTROL_TID_MASK;
45 } else {
46 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
47 /* Separate TID for management frames */
48 tid = NUM_RX_DATA_QUEUES - 1;
49 } else {
50 /* no qos control present */
51 tid = 0; /* 802.1d - Best Effort */
52 }
53 }
Johannes Berg52865dfd2007-07-27 15:43:22 +020054
Johannes Berg6e0d1142007-07-27 15:43:22 +020055 I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
Johannes Berg52865dfd2007-07-27 15:43:22 +020056 /* only a debug counter, sta might not be assigned properly yet */
57 if (rx->sta)
Johannes Berg6e0d1142007-07-27 15:43:22 +020058 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
Johannes Berg6e0d1142007-07-27 15:43:22 +020059
60 rx->u.rx.queue = tid;
61 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
62 * For now, set skb->priority to 0 for other cases. */
63 rx->skb->priority = (tid > 7) ? 0 : tid;
64
65 return TXRX_CONTINUE;
66}
67
68static ieee80211_txrx_result
Johannes Berg571ecf62007-07-27 15:43:22 +020069ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
70{
71 struct ieee80211_local *local = rx->local;
72 struct sk_buff *skb = rx->skb;
73 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
74 u32 load = 0, hdrtime;
75 struct ieee80211_rate *rate;
76 struct ieee80211_hw_mode *mode = local->hw.conf.mode;
77 int i;
78
79 /* Estimate total channel use caused by this frame */
80
81 if (unlikely(mode->num_rates < 0))
82 return TXRX_CONTINUE;
83
84 rate = &mode->rates[0];
85 for (i = 0; i < mode->num_rates; i++) {
86 if (mode->rates[i].val == rx->u.rx.status->rate) {
87 rate = &mode->rates[i];
88 break;
89 }
90 }
91
92 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
93 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
94
95 if (mode->mode == MODE_IEEE80211A ||
96 mode->mode == MODE_ATHEROS_TURBO ||
97 mode->mode == MODE_ATHEROS_TURBOG ||
98 (mode->mode == MODE_IEEE80211G &&
99 rate->flags & IEEE80211_RATE_ERP))
100 hdrtime = CHAN_UTIL_HDR_SHORT;
101 else
102 hdrtime = CHAN_UTIL_HDR_LONG;
103
104 load = hdrtime;
105 if (!is_multicast_ether_addr(hdr->addr1))
106 load += hdrtime;
107
108 load += skb->len * rate->rate_inv;
109
110 /* Divide channel_use by 8 to avoid wrapping around the counter */
111 load >>= CHAN_UTIL_SHIFT;
112 local->channel_use_raw += load;
Johannes Berg571ecf62007-07-27 15:43:22 +0200113 rx->u.rx.load = load;
114
115 return TXRX_CONTINUE;
116}
117
118ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
119{
120 ieee80211_rx_h_parse_qos,
121 ieee80211_rx_h_load_stats,
122 NULL
123};
124
125/* rx handlers */
126
127static ieee80211_txrx_result
128ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
129{
Johannes Berg52865dfd2007-07-27 15:43:22 +0200130 if (rx->sta)
131 rx->sta->channel_use_raw += rx->u.rx.load;
Johannes Berg571ecf62007-07-27 15:43:22 +0200132 rx->sdata->channel_use_raw += rx->u.rx.load;
133 return TXRX_CONTINUE;
134}
135
136static void
137ieee80211_rx_monitor(struct net_device *dev, struct sk_buff *skb,
138 struct ieee80211_rx_status *status)
139{
140 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
141 struct ieee80211_sub_if_data *sdata;
142 struct ieee80211_rate *rate;
143 struct ieee80211_rtap_hdr {
144 struct ieee80211_radiotap_header hdr;
145 u8 flags;
146 u8 rate;
147 __le16 chan_freq;
148 __le16 chan_flags;
149 u8 antsignal;
150 } __attribute__ ((packed)) *rthdr;
151
152 skb->dev = dev;
153
154 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
155
156 if (status->flag & RX_FLAG_RADIOTAP)
157 goto out;
158
159 if (skb_headroom(skb) < sizeof(*rthdr)) {
160 I802_DEBUG_INC(local->rx_expand_skb_head);
161 if (pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) {
162 dev_kfree_skb(skb);
163 return;
164 }
165 }
166
167 rthdr = (struct ieee80211_rtap_hdr *) skb_push(skb, sizeof(*rthdr));
168 memset(rthdr, 0, sizeof(*rthdr));
169 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
170 rthdr->hdr.it_present =
171 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
172 (1 << IEEE80211_RADIOTAP_RATE) |
173 (1 << IEEE80211_RADIOTAP_CHANNEL) |
174 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL));
175 rthdr->flags = local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS ?
176 IEEE80211_RADIOTAP_F_FCS : 0;
177 rate = ieee80211_get_rate(local, status->phymode, status->rate);
178 if (rate)
179 rthdr->rate = rate->rate / 5;
180 rthdr->chan_freq = cpu_to_le16(status->freq);
181 rthdr->chan_flags =
182 status->phymode == MODE_IEEE80211A ?
183 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ) :
184 cpu_to_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ);
185 rthdr->antsignal = status->ssi;
186
187 out:
188 sdata->stats.rx_packets++;
189 sdata->stats.rx_bytes += skb->len;
190
191 skb_set_mac_header(skb, 0);
192 skb->ip_summed = CHECKSUM_UNNECESSARY;
193 skb->pkt_type = PACKET_OTHERHOST;
194 skb->protocol = htons(ETH_P_802_2);
195 memset(skb->cb, 0, sizeof(skb->cb));
196 netif_rx(skb);
197}
198
199static ieee80211_txrx_result
200ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
201{
202 if (rx->sdata->type == IEEE80211_IF_TYPE_MNTR) {
203 ieee80211_rx_monitor(rx->dev, rx->skb, rx->u.rx.status);
204 return TXRX_QUEUED;
205 }
206
207 if (rx->u.rx.status->flag & RX_FLAG_RADIOTAP)
208 skb_pull(rx->skb, ieee80211_get_radiotap_len(rx->skb->data));
209
210 return TXRX_CONTINUE;
211}
212
213static ieee80211_txrx_result
214ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
215{
216 struct ieee80211_local *local = rx->local;
217 struct sk_buff *skb = rx->skb;
218
219 if (unlikely(local->sta_scanning != 0)) {
220 ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
221 return TXRX_QUEUED;
222 }
223
Jiri Slabybadffb72007-08-28 17:01:54 -0400224 if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200225 /* scanning finished during invoking of handlers */
226 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
227 return TXRX_DROP;
228 }
229
230 return TXRX_CONTINUE;
231}
232
233static ieee80211_txrx_result
234ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
235{
236 struct ieee80211_hdr *hdr;
Johannes Berg571ecf62007-07-27 15:43:22 +0200237 hdr = (struct ieee80211_hdr *) rx->skb->data;
238
239 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
240 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
241 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
242 rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
243 hdr->seq_ctrl)) {
Jiri Slabybadffb72007-08-28 17:01:54 -0400244 if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200245 rx->local->dot11FrameDuplicateCount++;
246 rx->sta->num_duplicates++;
247 }
248 return TXRX_DROP;
249 } else
250 rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
251 }
252
253 if ((rx->local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) &&
254 rx->skb->len > FCS_LEN)
255 skb_trim(rx->skb, rx->skb->len - FCS_LEN);
256
257 if (unlikely(rx->skb->len < 16)) {
258 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
259 return TXRX_DROP;
260 }
261
Jiri Slabybadffb72007-08-28 17:01:54 -0400262 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg571ecf62007-07-27 15:43:22 +0200263 rx->skb->pkt_type = PACKET_OTHERHOST;
264 else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0)
265 rx->skb->pkt_type = PACKET_HOST;
266 else if (is_multicast_ether_addr(hdr->addr1)) {
267 if (is_broadcast_ether_addr(hdr->addr1))
268 rx->skb->pkt_type = PACKET_BROADCAST;
269 else
270 rx->skb->pkt_type = PACKET_MULTICAST;
271 } else
272 rx->skb->pkt_type = PACKET_OTHERHOST;
273
274 /* Drop disallowed frame classes based on STA auth/assoc state;
275 * IEEE 802.11, Chap 5.5.
276 *
277 * 80211.o does filtering only based on association state, i.e., it
278 * drops Class 3 frames from not associated stations. hostapd sends
279 * deauth/disassoc frames when needed. In addition, hostapd is
280 * responsible for filtering on both auth and assoc states.
281 */
282 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
283 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
284 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
285 rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
286 (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
287 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
288 !(rx->fc & IEEE80211_FCTL_TODS) &&
289 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
Jiri Slabybadffb72007-08-28 17:01:54 -0400290 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200291 /* Drop IBSS frames and frames for other hosts
292 * silently. */
293 return TXRX_DROP;
294 }
295
296 if (!rx->local->apdev)
297 return TXRX_DROP;
298
299 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
300 ieee80211_msg_sta_not_assoc);
301 return TXRX_QUEUED;
302 }
303
Johannes Berg570bd532007-07-27 15:43:22 +0200304 return TXRX_CONTINUE;
305}
306
307
308static ieee80211_txrx_result
309ieee80211_rx_h_load_key(struct ieee80211_txrx_data *rx)
310{
311 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
Johannes Berg3017b802007-08-28 17:01:53 -0400312 int keyidx;
313 int hdrlen;
Johannes Berg570bd532007-07-27 15:43:22 +0200314
Johannes Berg3017b802007-08-28 17:01:53 -0400315 /*
316 * Key selection 101
317 *
318 * There are three types of keys:
319 * - GTK (group keys)
320 * - PTK (pairwise keys)
321 * - STK (station-to-station pairwise keys)
322 *
323 * When selecting a key, we have to distinguish between multicast
324 * (including broadcast) and unicast frames, the latter can only
325 * use PTKs and STKs while the former always use GTKs. Unless, of
326 * course, actual WEP keys ("pre-RSNA") are used, then unicast
327 * frames can also use key indizes like GTKs. Hence, if we don't
328 * have a PTK/STK we check the key index for a WEP key.
329 *
330 * There is also a slight problem in IBSS mode: GTKs are negotiated
331 * with each station, that is something we don't currently handle.
332 */
Johannes Berg571ecf62007-07-27 15:43:22 +0200333
Johannes Berg3017b802007-08-28 17:01:53 -0400334 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
335 return TXRX_CONTINUE;
336
337 /*
338 * No point in finding a key if the frame is neither
339 * addressed to us nor a multicast frame.
340 */
Jiri Slabybadffb72007-08-28 17:01:54 -0400341 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg3017b802007-08-28 17:01:53 -0400342 return TXRX_CONTINUE;
343
344 if (!is_multicast_ether_addr(hdr->addr1) && rx->sta && rx->sta->key) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200345 rx->key = rx->sta->key;
346 } else {
Johannes Berg3017b802007-08-28 17:01:53 -0400347 /*
348 * The device doesn't give us the IV so we won't be
349 * able to look up the key. That's ok though, we
350 * don't need to decrypt the frame, we just won't
351 * be able to keep statistics accurate.
352 * Except for key threshold notifications, should
353 * we somehow allow the driver to tell us which key
354 * the hardware used if this flag is set?
355 */
356 if (!(rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV))
357 return TXRX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200358
Johannes Berg3017b802007-08-28 17:01:53 -0400359 hdrlen = ieee80211_get_hdrlen(rx->fc);
Johannes Berg571ecf62007-07-27 15:43:22 +0200360
Johannes Berg3017b802007-08-28 17:01:53 -0400361 if (rx->skb->len < 8 + hdrlen)
362 return TXRX_DROP; /* TODO: count this? */
Johannes Berg571ecf62007-07-27 15:43:22 +0200363
Johannes Berg3017b802007-08-28 17:01:53 -0400364 /*
365 * no need to call ieee80211_wep_get_keyidx,
366 * it verifies a bunch of things we've done already
367 */
368 keyidx = rx->skb->data[hdrlen + 3] >> 6;
369
370 rx->key = rx->sdata->keys[keyidx];
371
372 /*
373 * RSNA-protected unicast frames should always be sent with
374 * pairwise or station-to-station keys, but for WEP we allow
375 * using a key index as well.
376 */
Johannes Berg8f20fc22007-08-28 17:01:54 -0400377 if (rx->key && rx->key->conf.alg != ALG_WEP &&
Johannes Berg3017b802007-08-28 17:01:53 -0400378 !is_multicast_ether_addr(hdr->addr1))
379 rx->key = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +0200380 }
381
Johannes Berg3017b802007-08-28 17:01:53 -0400382 if (rx->key) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200383 rx->key->tx_rx_count++;
384 if (unlikely(rx->local->key_tx_rx_threshold &&
385 rx->key->tx_rx_count >
386 rx->local->key_tx_rx_threshold)) {
387 ieee80211_key_threshold_notify(rx->dev, rx->key,
388 rx->sta);
389 }
390 }
391
392 return TXRX_CONTINUE;
393}
394
395static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
396{
397 struct ieee80211_sub_if_data *sdata;
398 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
399
400 if (sdata->bss)
401 atomic_inc(&sdata->bss->num_sta_ps);
402 sta->flags |= WLAN_STA_PS;
403 sta->pspoll = 0;
404#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
405 printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d enters power "
406 "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
407#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
408}
409
410static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
411{
412 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
413 struct sk_buff *skb;
414 int sent = 0;
415 struct ieee80211_sub_if_data *sdata;
416 struct ieee80211_tx_packet_data *pkt_data;
417
418 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
419 if (sdata->bss)
420 atomic_dec(&sdata->bss->num_sta_ps);
421 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
422 sta->pspoll = 0;
423 if (!skb_queue_empty(&sta->ps_tx_buf)) {
424 if (local->ops->set_tim)
425 local->ops->set_tim(local_to_hw(local), sta->aid, 0);
426 if (sdata->bss)
427 bss_tim_clear(local, sdata->bss, sta->aid);
428 }
429#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
430 printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d exits power "
431 "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
432#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
433 /* Send all buffered frames to the station */
434 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
435 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
436 sent++;
Jiri Slabye8bf9642007-08-28 17:01:54 -0400437 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200438 dev_queue_xmit(skb);
439 }
440 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
441 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
442 local->total_ps_buffered--;
443 sent++;
444#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
445 printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d send PS frame "
446 "since STA not sleeping anymore\n", dev->name,
447 MAC_ARG(sta->addr), sta->aid);
448#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Jiri Slabye8bf9642007-08-28 17:01:54 -0400449 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200450 dev_queue_xmit(skb);
451 }
452
453 return sent;
454}
455
456static ieee80211_txrx_result
457ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
458{
459 struct sta_info *sta = rx->sta;
460 struct net_device *dev = rx->dev;
461 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
462
463 if (!sta)
464 return TXRX_CONTINUE;
465
466 /* Update last_rx only for IBSS packets which are for the current
467 * BSSID to avoid keeping the current IBSS network alive in cases where
468 * other STAs are using different BSSID. */
469 if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
470 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
471 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
472 sta->last_rx = jiffies;
473 } else
474 if (!is_multicast_ether_addr(hdr->addr1) ||
475 rx->sdata->type == IEEE80211_IF_TYPE_STA) {
476 /* Update last_rx only for unicast frames in order to prevent
477 * the Probe Request frames (the only broadcast frames from a
478 * STA in infrastructure mode) from keeping a connection alive.
479 */
480 sta->last_rx = jiffies;
481 }
482
Jiri Slabybadffb72007-08-28 17:01:54 -0400483 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg571ecf62007-07-27 15:43:22 +0200484 return TXRX_CONTINUE;
485
486 sta->rx_fragments++;
487 sta->rx_bytes += rx->skb->len;
Larry Finger6c55aa92007-08-28 17:01:55 -0400488 sta->last_rssi = rx->u.rx.status->ssi;
489 sta->last_signal = rx->u.rx.status->signal;
490 sta->last_noise = rx->u.rx.status->noise;
Johannes Berg571ecf62007-07-27 15:43:22 +0200491
492 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
493 /* Change STA power saving mode only in the end of a frame
494 * exchange sequence */
495 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
496 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
497 else if (!(sta->flags & WLAN_STA_PS) &&
498 (rx->fc & IEEE80211_FCTL_PM))
499 ap_sta_ps_start(dev, sta);
500 }
501
502 /* Drop data::nullfunc frames silently, since they are used only to
503 * control station power saving mode. */
504 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
505 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
506 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
507 /* Update counter and free packet here to avoid counting this
508 * as a dropped packed. */
509 sta->rx_packets++;
510 dev_kfree_skb(rx->skb);
511 return TXRX_QUEUED;
512 }
513
514 return TXRX_CONTINUE;
515} /* ieee80211_rx_h_sta_process */
516
517static ieee80211_txrx_result
518ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
519{
520 if (!rx->sta || !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
521 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
Johannes Berg8f20fc22007-08-28 17:01:54 -0400522 !rx->key || rx->key->conf.alg != ALG_WEP ||
Jiri Slabybadffb72007-08-28 17:01:54 -0400523 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg571ecf62007-07-27 15:43:22 +0200524 return TXRX_CONTINUE;
525
526 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
527 if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) ||
Johannes Berg11a843b2007-08-28 17:01:55 -0400528 !(rx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Johannes Berg8f20fc22007-08-28 17:01:54 -0400529 if (ieee80211_wep_is_weak_iv(rx->skb, rx->key))
Johannes Berg571ecf62007-07-27 15:43:22 +0200530 rx->sta->wep_weak_iv_count++;
Johannes Berg571ecf62007-07-27 15:43:22 +0200531
532 return TXRX_CONTINUE;
533}
534
535static ieee80211_txrx_result
536ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
537{
Johannes Berg8f20fc22007-08-28 17:01:54 -0400538 if ((rx->key && rx->key->conf.alg != ALG_WEP) ||
Johannes Berg571ecf62007-07-27 15:43:22 +0200539 !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
540 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
541 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
542 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
543 return TXRX_CONTINUE;
544
545 if (!rx->key) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400546 if (net_ratelimit())
547 printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
548 rx->dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +0200549 return TXRX_DROP;
550 }
551
552 if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED) ||
Johannes Berg11a843b2007-08-28 17:01:55 -0400553 !(rx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200554 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400555 if (net_ratelimit())
556 printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
557 "failed\n", rx->dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +0200558 return TXRX_DROP;
559 }
560 } else if (rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
561 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
562 /* remove ICV */
563 skb_trim(rx->skb, rx->skb->len - 4);
564 }
565
566 return TXRX_CONTINUE;
567}
568
569static inline struct ieee80211_fragment_entry *
570ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
571 unsigned int frag, unsigned int seq, int rx_queue,
572 struct sk_buff **skb)
573{
574 struct ieee80211_fragment_entry *entry;
575 int idx;
576
577 idx = sdata->fragment_next;
578 entry = &sdata->fragments[sdata->fragment_next++];
579 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
580 sdata->fragment_next = 0;
581
582 if (!skb_queue_empty(&entry->skb_list)) {
583#ifdef CONFIG_MAC80211_DEBUG
584 struct ieee80211_hdr *hdr =
585 (struct ieee80211_hdr *) entry->skb_list.next->data;
586 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
587 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
588 "addr1=" MAC_FMT " addr2=" MAC_FMT "\n",
589 sdata->dev->name, idx,
590 jiffies - entry->first_frag_time, entry->seq,
591 entry->last_frag, MAC_ARG(hdr->addr1),
592 MAC_ARG(hdr->addr2));
593#endif /* CONFIG_MAC80211_DEBUG */
594 __skb_queue_purge(&entry->skb_list);
595 }
596
597 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
598 *skb = NULL;
599 entry->first_frag_time = jiffies;
600 entry->seq = seq;
601 entry->rx_queue = rx_queue;
602 entry->last_frag = frag;
603 entry->ccmp = 0;
604 entry->extra_len = 0;
605
606 return entry;
607}
608
609static inline struct ieee80211_fragment_entry *
610ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
611 u16 fc, unsigned int frag, unsigned int seq,
612 int rx_queue, struct ieee80211_hdr *hdr)
613{
614 struct ieee80211_fragment_entry *entry;
615 int i, idx;
616
617 idx = sdata->fragment_next;
618 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
619 struct ieee80211_hdr *f_hdr;
620 u16 f_fc;
621
622 idx--;
623 if (idx < 0)
624 idx = IEEE80211_FRAGMENT_MAX - 1;
625
626 entry = &sdata->fragments[idx];
627 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
628 entry->rx_queue != rx_queue ||
629 entry->last_frag + 1 != frag)
630 continue;
631
632 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
633 f_fc = le16_to_cpu(f_hdr->frame_control);
634
635 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
636 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
637 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
638 continue;
639
640 if (entry->first_frag_time + 2 * HZ < jiffies) {
641 __skb_queue_purge(&entry->skb_list);
642 continue;
643 }
644 return entry;
645 }
646
647 return NULL;
648}
649
650static ieee80211_txrx_result
651ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
652{
653 struct ieee80211_hdr *hdr;
654 u16 sc;
655 unsigned int frag, seq;
656 struct ieee80211_fragment_entry *entry;
657 struct sk_buff *skb;
658
659 hdr = (struct ieee80211_hdr *) rx->skb->data;
660 sc = le16_to_cpu(hdr->seq_ctrl);
661 frag = sc & IEEE80211_SCTL_FRAG;
662
663 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
664 (rx->skb)->len < 24 ||
665 is_multicast_ether_addr(hdr->addr1))) {
666 /* not fragmented */
667 goto out;
668 }
669 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
670
671 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
672
673 if (frag == 0) {
674 /* This is the first fragment of a new frame. */
675 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
676 rx->u.rx.queue, &(rx->skb));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400677 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
Johannes Berg571ecf62007-07-27 15:43:22 +0200678 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
679 /* Store CCMP PN so that we can verify that the next
680 * fragment has a sequential PN value. */
681 entry->ccmp = 1;
682 memcpy(entry->last_pn,
683 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
684 CCMP_PN_LEN);
685 }
686 return TXRX_QUEUED;
687 }
688
689 /* This is a fragment for a frame that should already be pending in
690 * fragment cache. Add this fragment to the end of the pending entry.
691 */
692 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
693 rx->u.rx.queue, hdr);
694 if (!entry) {
695 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
696 return TXRX_DROP;
697 }
698
699 /* Verify that MPDUs within one MSDU have sequential PN values.
700 * (IEEE 802.11i, 8.3.3.4.5) */
701 if (entry->ccmp) {
702 int i;
703 u8 pn[CCMP_PN_LEN], *rpn;
Johannes Berg8f20fc22007-08-28 17:01:54 -0400704 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
Johannes Berg571ecf62007-07-27 15:43:22 +0200705 return TXRX_DROP;
706 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
707 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
708 pn[i]++;
709 if (pn[i])
710 break;
711 }
712 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
713 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400714 if (net_ratelimit())
715 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
716 "sequential A2=" MAC_FMT
717 " PN=%02x%02x%02x%02x%02x%02x "
718 "(expected %02x%02x%02x%02x%02x%02x)\n",
719 rx->dev->name, MAC_ARG(hdr->addr2),
720 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
721 rpn[5], pn[0], pn[1], pn[2], pn[3],
722 pn[4], pn[5]);
Johannes Berg571ecf62007-07-27 15:43:22 +0200723 return TXRX_DROP;
724 }
725 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
726 }
727
728 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
729 __skb_queue_tail(&entry->skb_list, rx->skb);
730 entry->last_frag = frag;
731 entry->extra_len += rx->skb->len;
732 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
733 rx->skb = NULL;
734 return TXRX_QUEUED;
735 }
736
737 rx->skb = __skb_dequeue(&entry->skb_list);
738 if (skb_tailroom(rx->skb) < entry->extra_len) {
739 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
740 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
741 GFP_ATOMIC))) {
742 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
743 __skb_queue_purge(&entry->skb_list);
744 return TXRX_DROP;
745 }
746 }
747 while ((skb = __skb_dequeue(&entry->skb_list))) {
748 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
749 dev_kfree_skb(skb);
750 }
751
752 /* Complete frame has been reassembled - process it now */
Jiri Slabybadffb72007-08-28 17:01:54 -0400753 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200754
755 out:
756 if (rx->sta)
757 rx->sta->rx_packets++;
758 if (is_multicast_ether_addr(hdr->addr1))
759 rx->local->dot11MulticastReceivedFrameCount++;
760 else
761 ieee80211_led_rx(rx->local);
762 return TXRX_CONTINUE;
763}
764
765static ieee80211_txrx_result
766ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
767{
768 struct sk_buff *skb;
769 int no_pending_pkts;
770
771 if (likely(!rx->sta ||
772 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
773 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
Jiri Slabybadffb72007-08-28 17:01:54 -0400774 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
Johannes Berg571ecf62007-07-27 15:43:22 +0200775 return TXRX_CONTINUE;
776
777 skb = skb_dequeue(&rx->sta->tx_filtered);
778 if (!skb) {
779 skb = skb_dequeue(&rx->sta->ps_tx_buf);
780 if (skb)
781 rx->local->total_ps_buffered--;
782 }
783 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
784 skb_queue_empty(&rx->sta->ps_tx_buf);
785
786 if (skb) {
787 struct ieee80211_hdr *hdr =
788 (struct ieee80211_hdr *) skb->data;
789
790 /* tell TX path to send one frame even though the STA may
791 * still remain is PS mode after this frame exchange */
792 rx->sta->pspoll = 1;
793
794#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
795 printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS Poll (entries "
796 "after %d)\n",
797 MAC_ARG(rx->sta->addr), rx->sta->aid,
798 skb_queue_len(&rx->sta->ps_tx_buf));
799#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
800
801 /* Use MoreData flag to indicate whether there are more
802 * buffered frames for this STA */
803 if (no_pending_pkts) {
804 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
805 rx->sta->flags &= ~WLAN_STA_TIM;
806 } else
807 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
808
809 dev_queue_xmit(skb);
810
811 if (no_pending_pkts) {
812 if (rx->local->ops->set_tim)
813 rx->local->ops->set_tim(local_to_hw(rx->local),
814 rx->sta->aid, 0);
815 if (rx->sdata->bss)
816 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
817 }
818#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
819 } else if (!rx->u.rx.sent_ps_buffered) {
820 printk(KERN_DEBUG "%s: STA " MAC_FMT " sent PS Poll even "
821 "though there is no buffered frames for it\n",
822 rx->dev->name, MAC_ARG(rx->sta->addr));
823#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
824
825 }
826
827 /* Free PS Poll skb here instead of returning TXRX_DROP that would
828 * count as an dropped frame. */
829 dev_kfree_skb(rx->skb);
830
831 return TXRX_QUEUED;
832}
833
834static ieee80211_txrx_result
Johannes Berg6e0d1142007-07-27 15:43:22 +0200835ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
836{
837 u16 fc = rx->fc;
838 u8 *data = rx->skb->data;
839 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
840
841 if (!WLAN_FC_IS_QOS_DATA(fc))
842 return TXRX_CONTINUE;
843
844 /* remove the qos control field, update frame type and meta-data */
845 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
846 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
847 /* change frame type to non QOS */
848 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
849 hdr->frame_control = cpu_to_le16(fc);
850
851 return TXRX_CONTINUE;
852}
853
854static ieee80211_txrx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200855ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
856{
857 if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
Jiri Slabybadffb72007-08-28 17:01:54 -0400858 rx->sdata->type != IEEE80211_IF_TYPE_STA &&
859 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200860 /* Pass both encrypted and unencrypted EAPOL frames to user
861 * space for processing. */
862 if (!rx->local->apdev)
863 return TXRX_DROP;
864 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
865 ieee80211_msg_normal);
866 return TXRX_QUEUED;
867 }
868
869 if (unlikely(rx->sdata->ieee802_1x &&
870 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
871 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
872 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
873 !ieee80211_is_eapol(rx->skb))) {
874#ifdef CONFIG_MAC80211_DEBUG
875 struct ieee80211_hdr *hdr =
876 (struct ieee80211_hdr *) rx->skb->data;
877 printk(KERN_DEBUG "%s: dropped frame from " MAC_FMT
878 " (unauthorized port)\n", rx->dev->name,
879 MAC_ARG(hdr->addr2));
880#endif /* CONFIG_MAC80211_DEBUG */
881 return TXRX_DROP;
882 }
883
884 return TXRX_CONTINUE;
885}
886
887static ieee80211_txrx_result
888ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
889{
Johannes Berg3017b802007-08-28 17:01:53 -0400890 /*
891 * Pass through unencrypted frames if the hardware might have
892 * decrypted them already without telling us, but that can only
893 * be true if we either didn't find a key or the found key is
894 * uploaded to the hardware.
895 */
896 if ((rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) &&
Johannes Berg11a843b2007-08-28 17:01:55 -0400897 (!rx->key || (rx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)))
Johannes Berg571ecf62007-07-27 15:43:22 +0200898 return TXRX_CONTINUE;
899
900 /* Drop unencrypted frames if key is set. */
901 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
902 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
903 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
904 (rx->key || rx->sdata->drop_unencrypted) &&
905 (rx->sdata->eapol == 0 ||
906 !ieee80211_is_eapol(rx->skb)))) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400907 if (net_ratelimit())
908 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
909 "encryption\n", rx->dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +0200910 return TXRX_DROP;
911 }
912 return TXRX_CONTINUE;
913}
914
915static ieee80211_txrx_result
916ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
917{
918 struct net_device *dev = rx->dev;
919 struct ieee80211_local *local = rx->local;
920 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
921 u16 fc, hdrlen, ethertype;
922 u8 *payload;
923 u8 dst[ETH_ALEN];
924 u8 src[ETH_ALEN];
925 struct sk_buff *skb = rx->skb, *skb2;
926 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
927
928 fc = rx->fc;
929 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
930 return TXRX_CONTINUE;
931
932 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
933 return TXRX_DROP;
934
935 hdrlen = ieee80211_get_hdrlen(fc);
936
937 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
938 * header
939 * IEEE 802.11 address fields:
940 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
941 * 0 0 DA SA BSSID n/a
942 * 0 1 DA BSSID SA n/a
943 * 1 0 BSSID SA DA n/a
944 * 1 1 RA TA DA SA
945 */
946
947 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
948 case IEEE80211_FCTL_TODS:
949 /* BSSID SA DA */
950 memcpy(dst, hdr->addr3, ETH_ALEN);
951 memcpy(src, hdr->addr2, ETH_ALEN);
952
953 if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
954 sdata->type != IEEE80211_IF_TYPE_VLAN)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400955 if (net_ratelimit())
956 printk(KERN_DEBUG "%s: dropped ToDS frame "
957 "(BSSID=" MAC_FMT
958 " SA=" MAC_FMT
959 " DA=" MAC_FMT ")\n",
960 dev->name,
961 MAC_ARG(hdr->addr1),
962 MAC_ARG(hdr->addr2),
963 MAC_ARG(hdr->addr3));
Johannes Berg571ecf62007-07-27 15:43:22 +0200964 return TXRX_DROP;
965 }
966 break;
967 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
968 /* RA TA DA SA */
969 memcpy(dst, hdr->addr3, ETH_ALEN);
970 memcpy(src, hdr->addr4, ETH_ALEN);
971
972 if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400973 if (net_ratelimit())
974 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
975 "frame (RA=" MAC_FMT
976 " TA=" MAC_FMT " DA=" MAC_FMT
977 " SA=" MAC_FMT ")\n",
978 rx->dev->name,
979 MAC_ARG(hdr->addr1),
980 MAC_ARG(hdr->addr2),
981 MAC_ARG(hdr->addr3),
982 MAC_ARG(hdr->addr4));
Johannes Berg571ecf62007-07-27 15:43:22 +0200983 return TXRX_DROP;
984 }
985 break;
986 case IEEE80211_FCTL_FROMDS:
987 /* DA BSSID SA */
988 memcpy(dst, hdr->addr1, ETH_ALEN);
989 memcpy(src, hdr->addr3, ETH_ALEN);
990
991 if (sdata->type != IEEE80211_IF_TYPE_STA) {
992 return TXRX_DROP;
993 }
994 break;
995 case 0:
996 /* DA SA BSSID */
997 memcpy(dst, hdr->addr1, ETH_ALEN);
998 memcpy(src, hdr->addr2, ETH_ALEN);
999
1000 if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
1001 if (net_ratelimit()) {
1002 printk(KERN_DEBUG "%s: dropped IBSS frame (DA="
1003 MAC_FMT " SA=" MAC_FMT " BSSID=" MAC_FMT
1004 ")\n",
1005 dev->name, MAC_ARG(hdr->addr1),
1006 MAC_ARG(hdr->addr2),
1007 MAC_ARG(hdr->addr3));
1008 }
1009 return TXRX_DROP;
1010 }
1011 break;
1012 }
1013
1014 payload = skb->data + hdrlen;
1015
1016 if (unlikely(skb->len - hdrlen < 8)) {
1017 if (net_ratelimit()) {
1018 printk(KERN_DEBUG "%s: RX too short data frame "
1019 "payload\n", dev->name);
1020 }
1021 return TXRX_DROP;
1022 }
1023
1024 ethertype = (payload[6] << 8) | payload[7];
1025
1026 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1027 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1028 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1029 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1030 * replace EtherType */
1031 skb_pull(skb, hdrlen + 6);
1032 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1033 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1034 } else {
1035 struct ethhdr *ehdr;
1036 __be16 len;
1037 skb_pull(skb, hdrlen);
1038 len = htons(skb->len);
1039 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1040 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1041 memcpy(ehdr->h_source, src, ETH_ALEN);
1042 ehdr->h_proto = len;
1043 }
1044 skb->dev = dev;
1045
1046 skb2 = NULL;
1047
1048 sdata->stats.rx_packets++;
1049 sdata->stats.rx_bytes += skb->len;
1050
1051 if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP
Jiri Slabybadffb72007-08-28 17:01:54 -04001052 || sdata->type == IEEE80211_IF_TYPE_VLAN) &&
1053 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001054 if (is_multicast_ether_addr(skb->data)) {
1055 /* send multicast frames both to higher layers in
1056 * local net stack and back to the wireless media */
1057 skb2 = skb_copy(skb, GFP_ATOMIC);
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001058 if (!skb2 && net_ratelimit())
Johannes Berg571ecf62007-07-27 15:43:22 +02001059 printk(KERN_DEBUG "%s: failed to clone "
1060 "multicast frame\n", dev->name);
1061 } else {
1062 struct sta_info *dsta;
1063 dsta = sta_info_get(local, skb->data);
1064 if (dsta && !dsta->dev) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001065 if (net_ratelimit())
1066 printk(KERN_DEBUG "Station with null "
1067 "dev structure!\n");
Johannes Berg571ecf62007-07-27 15:43:22 +02001068 } else if (dsta && dsta->dev == dev) {
1069 /* Destination station is associated to this
1070 * AP, so send the frame directly to it and
1071 * do not pass the frame to local net stack.
1072 */
1073 skb2 = skb;
1074 skb = NULL;
1075 }
1076 if (dsta)
1077 sta_info_put(dsta);
1078 }
1079 }
1080
1081 if (skb) {
1082 /* deliver to local stack */
1083 skb->protocol = eth_type_trans(skb, dev);
1084 memset(skb->cb, 0, sizeof(skb->cb));
1085 netif_rx(skb);
1086 }
1087
1088 if (skb2) {
1089 /* send to wireless media */
1090 skb2->protocol = __constant_htons(ETH_P_802_3);
1091 skb_set_network_header(skb2, 0);
1092 skb_set_mac_header(skb2, 0);
1093 dev_queue_xmit(skb2);
1094 }
1095
1096 return TXRX_QUEUED;
1097}
1098
1099static ieee80211_txrx_result
1100ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1101{
1102 struct ieee80211_sub_if_data *sdata;
1103
Jiri Slabybadffb72007-08-28 17:01:54 -04001104 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg571ecf62007-07-27 15:43:22 +02001105 return TXRX_DROP;
1106
1107 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1108 if ((sdata->type == IEEE80211_IF_TYPE_STA ||
1109 sdata->type == IEEE80211_IF_TYPE_IBSS) &&
1110 !rx->local->user_space_mlme) {
1111 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
1112 } else {
1113 /* Management frames are sent to hostapd for processing */
1114 if (!rx->local->apdev)
1115 return TXRX_DROP;
1116 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
1117 ieee80211_msg_normal);
1118 }
1119 return TXRX_QUEUED;
1120}
1121
1122static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1123 struct ieee80211_local *local,
1124 ieee80211_rx_handler *handlers,
1125 struct ieee80211_txrx_data *rx,
1126 struct sta_info *sta)
1127{
1128 ieee80211_rx_handler *handler;
1129 ieee80211_txrx_result res = TXRX_DROP;
1130
1131 for (handler = handlers; *handler != NULL; handler++) {
1132 res = (*handler)(rx);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001133
1134 switch (res) {
1135 case TXRX_CONTINUE:
1136 continue;
1137 case TXRX_DROP:
1138 I802_DEBUG_INC(local->rx_handlers_drop);
1139 if (sta)
1140 sta->rx_dropped++;
1141 break;
1142 case TXRX_QUEUED:
1143 I802_DEBUG_INC(local->rx_handlers_queued);
Johannes Berg571ecf62007-07-27 15:43:22 +02001144 break;
1145 }
Johannes Berg8e6f00322007-07-27 15:43:22 +02001146 break;
Johannes Berg571ecf62007-07-27 15:43:22 +02001147 }
1148
Johannes Berg8e6f00322007-07-27 15:43:22 +02001149 if (res == TXRX_DROP)
Johannes Berg571ecf62007-07-27 15:43:22 +02001150 dev_kfree_skb(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001151 return res;
1152}
1153
1154static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1155 ieee80211_rx_handler *handlers,
1156 struct ieee80211_txrx_data *rx,
1157 struct sta_info *sta)
1158{
1159 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1160 TXRX_CONTINUE)
1161 dev_kfree_skb(rx->skb);
1162}
1163
1164static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1165 struct ieee80211_hdr *hdr,
1166 struct sta_info *sta,
1167 struct ieee80211_txrx_data *rx)
1168{
1169 int keyidx, hdrlen;
1170
1171 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1172 if (rx->skb->len >= hdrlen + 4)
1173 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1174 else
1175 keyidx = -1;
1176
1177 /* TODO: verify that this is not triggered by fragmented
1178 * frames (hw does not verify MIC for them). */
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001179 if (net_ratelimit())
1180 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
1181 "failure from " MAC_FMT " to " MAC_FMT " keyidx=%d\n",
1182 dev->name, MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr1),
1183 keyidx);
Johannes Berg571ecf62007-07-27 15:43:22 +02001184
1185 if (!sta) {
1186 /* Some hardware versions seem to generate incorrect
1187 * Michael MIC reports; ignore them to avoid triggering
1188 * countermeasures. */
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001189 if (net_ratelimit())
1190 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1191 "error for unknown address " MAC_FMT "\n",
1192 dev->name, MAC_ARG(hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001193 goto ignore;
1194 }
1195
1196 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001197 if (net_ratelimit())
1198 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1199 "error for a frame with no ISWEP flag (src "
1200 MAC_FMT ")\n", dev->name, MAC_ARG(hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001201 goto ignore;
1202 }
1203
1204 if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) &&
Johannes Bergeb063c12007-08-28 17:01:53 -04001205 rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001206 /* AP with Pairwise keys support should never receive Michael
1207 * MIC errors for non-zero keyidx because these are reserved
1208 * for group keys and only the AP is sending real multicast
1209 * frames in BSS. */
Johannes Bergeb063c12007-08-28 17:01:53 -04001210 if (net_ratelimit())
1211 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1212 "a frame with non-zero keyidx (%d)"
1213 " (src " MAC_FMT ")\n", dev->name, keyidx,
1214 MAC_ARG(hdr->addr2));
1215 goto ignore;
Johannes Berg571ecf62007-07-27 15:43:22 +02001216 }
1217
1218 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1219 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1220 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001221 if (net_ratelimit())
1222 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1223 "error for a frame that cannot be encrypted "
1224 "(fc=0x%04x) (src " MAC_FMT ")\n",
1225 dev->name, rx->fc, MAC_ARG(hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001226 goto ignore;
1227 }
1228
Johannes Berg571ecf62007-07-27 15:43:22 +02001229 /* TODO: consider verifying the MIC error report with software
1230 * implementation if we get too many spurious reports from the
1231 * hardware. */
Johannes Berg571ecf62007-07-27 15:43:22 +02001232
Johannes Bergeb063c12007-08-28 17:01:53 -04001233 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02001234 ignore:
1235 dev_kfree_skb(rx->skb);
1236 rx->skb = NULL;
1237}
1238
1239ieee80211_rx_handler ieee80211_rx_handlers[] =
1240{
1241 ieee80211_rx_h_if_stats,
1242 ieee80211_rx_h_monitor,
1243 ieee80211_rx_h_passive_scan,
1244 ieee80211_rx_h_check,
Johannes Berg570bd532007-07-27 15:43:22 +02001245 ieee80211_rx_h_load_key,
Johannes Berg571ecf62007-07-27 15:43:22 +02001246 ieee80211_rx_h_sta_process,
1247 ieee80211_rx_h_ccmp_decrypt,
1248 ieee80211_rx_h_tkip_decrypt,
1249 ieee80211_rx_h_wep_weak_iv_detection,
1250 ieee80211_rx_h_wep_decrypt,
1251 ieee80211_rx_h_defragment,
1252 ieee80211_rx_h_ps_poll,
1253 ieee80211_rx_h_michael_mic_verify,
1254 /* this must be after decryption - so header is counted in MPDU mic
1255 * must be before pae and data, so QOS_DATA format frames
1256 * are not passed to user space by these functions
1257 */
1258 ieee80211_rx_h_remove_qos_control,
1259 ieee80211_rx_h_802_1x_pae,
1260 ieee80211_rx_h_drop_unencrypted,
1261 ieee80211_rx_h_data,
1262 ieee80211_rx_h_mgmt,
1263 NULL
1264};
1265
1266/* main receive path */
1267
Johannes Berg23a24de2007-07-27 15:43:22 +02001268static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1269 u8 *bssid, struct ieee80211_txrx_data *rx,
1270 struct ieee80211_hdr *hdr)
1271{
1272 int multicast = is_multicast_ether_addr(hdr->addr1);
1273
1274 switch (sdata->type) {
1275 case IEEE80211_IF_TYPE_STA:
1276 if (!bssid)
1277 return 0;
1278 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001279 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001280 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001281 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001282 } else if (!multicast &&
1283 compare_ether_addr(sdata->dev->dev_addr,
1284 hdr->addr1) != 0) {
Jiri Slaby13262ff2007-08-28 17:01:54 -04001285 if (!(sdata->flags & IEEE80211_SDATA_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02001286 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001287 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001288 }
1289 break;
1290 case IEEE80211_IF_TYPE_IBSS:
1291 if (!bssid)
1292 return 0;
1293 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001294 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001295 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001296 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001297 } else if (!multicast &&
1298 compare_ether_addr(sdata->dev->dev_addr,
1299 hdr->addr1) != 0) {
Jiri Slaby13262ff2007-08-28 17:01:54 -04001300 if (!(sdata->flags & IEEE80211_SDATA_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02001301 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001302 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001303 } else if (!rx->sta)
1304 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1305 bssid, hdr->addr2);
1306 break;
1307 case IEEE80211_IF_TYPE_AP:
1308 if (!bssid) {
1309 if (compare_ether_addr(sdata->dev->dev_addr,
1310 hdr->addr1))
1311 return 0;
1312 } else if (!ieee80211_bssid_match(bssid,
1313 sdata->dev->dev_addr)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001314 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001315 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001316 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001317 }
Jiri Slabybadffb72007-08-28 17:01:54 -04001318 if (sdata->dev == sdata->local->mdev &&
1319 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001320 /* do not receive anything via
1321 * master device when not scanning */
1322 return 0;
1323 break;
1324 case IEEE80211_IF_TYPE_WDS:
1325 if (bssid ||
1326 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1327 return 0;
1328 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1329 return 0;
1330 break;
1331 }
1332
1333 return 1;
1334}
1335
Johannes Berg571ecf62007-07-27 15:43:22 +02001336/*
1337 * This is the receive path handler. It is called by a low level driver when an
1338 * 802.11 MPDU is received from the hardware.
1339 */
1340void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1341 struct ieee80211_rx_status *status)
1342{
1343 struct ieee80211_local *local = hw_to_local(hw);
1344 struct ieee80211_sub_if_data *sdata;
1345 struct sta_info *sta;
1346 struct ieee80211_hdr *hdr;
1347 struct ieee80211_txrx_data rx;
1348 u16 type;
Johannes Berg23a24de2007-07-27 15:43:22 +02001349 int radiotap_len = 0, prepres;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001350 struct ieee80211_sub_if_data *prev = NULL;
1351 struct sk_buff *skb_new;
1352 u8 *bssid;
Johannes Berg571ecf62007-07-27 15:43:22 +02001353
1354 if (status->flag & RX_FLAG_RADIOTAP) {
1355 radiotap_len = ieee80211_get_radiotap_len(skb->data);
1356 skb_pull(skb, radiotap_len);
1357 }
1358
1359 hdr = (struct ieee80211_hdr *) skb->data;
1360 memset(&rx, 0, sizeof(rx));
1361 rx.skb = skb;
1362 rx.local = local;
1363
1364 rx.u.rx.status = status;
1365 rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0;
1366 type = rx.fc & IEEE80211_FCTL_FTYPE;
1367 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
1368 local->dot11ReceivedFragmentCount++;
Johannes Berg571ecf62007-07-27 15:43:22 +02001369
Johannes Berg23a24de2007-07-27 15:43:22 +02001370 if (skb->len >= 16) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001371 sta = rx.sta = sta_info_get(local, hdr->addr2);
Johannes Berg23a24de2007-07-27 15:43:22 +02001372 if (sta) {
1373 rx.dev = rx.sta->dev;
1374 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1375 }
1376 } else
Johannes Berg571ecf62007-07-27 15:43:22 +02001377 sta = rx.sta = NULL;
1378
Johannes Berg571ecf62007-07-27 15:43:22 +02001379 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1380 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
1381 goto end;
1382 }
1383
1384 if (unlikely(local->sta_scanning))
Jiri Slabybadffb72007-08-28 17:01:54 -04001385 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
Johannes Berg571ecf62007-07-27 15:43:22 +02001386
1387 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
1388 sta) != TXRX_CONTINUE)
1389 goto end;
1390 skb = rx.skb;
1391
1392 skb_push(skb, radiotap_len);
1393 if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS) &&
Johannes Berg23a24de2007-07-27 15:43:22 +02001394 !local->iff_promiscs && !is_multicast_ether_addr(hdr->addr1)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001395 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg571ecf62007-07-27 15:43:22 +02001396 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
Johannes Berg23a24de2007-07-27 15:43:22 +02001397 rx.sta);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001398 sta_info_put(sta);
1399 return;
1400 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001401
Johannes Berg8e6f00322007-07-27 15:43:22 +02001402 bssid = ieee80211_get_bssid(hdr, skb->len - radiotap_len);
Johannes Berg571ecf62007-07-27 15:43:22 +02001403
Johannes Berg8e6f00322007-07-27 15:43:22 +02001404 read_lock(&local->sub_if_lock);
1405 list_for_each_entry(sdata, &local->sub_if_list, list) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001406 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001407
Johannes Berg2a8a9a82007-08-28 17:01:52 -04001408 if (!netif_running(sdata->dev))
1409 continue;
1410
Johannes Berg23a24de2007-07-27 15:43:22 +02001411 prepres = prepare_for_handlers(sdata, bssid, &rx, hdr);
1412 /* prepare_for_handlers can change sta */
1413 sta = rx.sta;
1414
1415 if (!prepres)
1416 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001417
Johannes Berg340e11f2007-07-27 15:43:22 +02001418 /*
1419 * frame is destined for this interface, but if it's not
1420 * also for the previous one we handle that after the
1421 * loop to avoid copying the SKB once too much
1422 */
1423
1424 if (!prev) {
1425 prev = sdata;
1426 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001427 }
Johannes Berg340e11f2007-07-27 15:43:22 +02001428
1429 /*
1430 * frame was destined for the previous interface
1431 * so invoke RX handlers for it
1432 */
1433
1434 skb_new = skb_copy(skb, GFP_ATOMIC);
1435 if (!skb_new) {
1436 if (net_ratelimit())
1437 printk(KERN_DEBUG "%s: failed to copy "
1438 "multicast frame for %s",
1439 local->mdev->name, prev->dev->name);
1440 continue;
1441 }
1442 rx.skb = skb_new;
1443 rx.dev = prev->dev;
1444 rx.sdata = prev;
1445 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1446 &rx, sta);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001447 prev = sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02001448 }
Johannes Berg8e6f00322007-07-27 15:43:22 +02001449 if (prev) {
1450 rx.skb = skb;
1451 rx.dev = prev->dev;
1452 rx.sdata = prev;
1453 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1454 &rx, sta);
1455 } else
1456 dev_kfree_skb(skb);
1457 read_unlock(&local->sub_if_lock);
Johannes Berg571ecf62007-07-27 15:43:22 +02001458
Johannes Berg8e6f00322007-07-27 15:43:22 +02001459 end:
Johannes Berg571ecf62007-07-27 15:43:22 +02001460 if (sta)
1461 sta_info_put(sta);
1462}
1463EXPORT_SYMBOL(__ieee80211_rx);
1464
1465/* This is a version of the rx handler that can be called from hard irq
1466 * context. Post the skb on the queue and schedule the tasklet */
1467void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
1468 struct ieee80211_rx_status *status)
1469{
1470 struct ieee80211_local *local = hw_to_local(hw);
1471
1472 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
1473
1474 skb->dev = local->mdev;
1475 /* copy status into skb->cb for use by tasklet */
1476 memcpy(skb->cb, status, sizeof(*status));
1477 skb->pkt_type = IEEE80211_RX_MSG;
1478 skb_queue_tail(&local->skb_queue, skb);
1479 tasklet_schedule(&local->tasklet);
1480}
1481EXPORT_SYMBOL(ieee80211_rx_irqsafe);