blob: 75a1e204b9b6bb5e50fd12ff8222470ac7e11e9c [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 *
Johannes Berg8dc06a12007-08-28 17:01:55 -0400330 * Note that in a regular BSS, multicast frames are sent by the
331 * AP only, associated stations unicast the frame to the AP first
332 * which then multicasts it on their behalf.
333 *
Johannes Berg3017b802007-08-28 17:01:53 -0400334 * There is also a slight problem in IBSS mode: GTKs are negotiated
335 * with each station, that is something we don't currently handle.
Johannes Berg8dc06a12007-08-28 17:01:55 -0400336 * The spec seems to expect that one negotiates the same key with
337 * every station but there's no such requirement; VLANs could be
338 * possible.
Johannes Berg3017b802007-08-28 17:01:53 -0400339 */
Johannes Berg571ecf62007-07-27 15:43:22 +0200340
Johannes Berg3017b802007-08-28 17:01:53 -0400341 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
342 return TXRX_CONTINUE;
343
344 /*
345 * No point in finding a key if the frame is neither
346 * addressed to us nor a multicast frame.
347 */
Jiri Slabybadffb72007-08-28 17:01:54 -0400348 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg3017b802007-08-28 17:01:53 -0400349 return TXRX_CONTINUE;
350
351 if (!is_multicast_ether_addr(hdr->addr1) && rx->sta && rx->sta->key) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200352 rx->key = rx->sta->key;
353 } else {
Johannes Berg3017b802007-08-28 17:01:53 -0400354 /*
355 * The device doesn't give us the IV so we won't be
356 * able to look up the key. That's ok though, we
357 * don't need to decrypt the frame, we just won't
358 * be able to keep statistics accurate.
359 * Except for key threshold notifications, should
360 * we somehow allow the driver to tell us which key
361 * the hardware used if this flag is set?
362 */
363 if (!(rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV))
364 return TXRX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200365
Johannes Berg3017b802007-08-28 17:01:53 -0400366 hdrlen = ieee80211_get_hdrlen(rx->fc);
Johannes Berg571ecf62007-07-27 15:43:22 +0200367
Johannes Berg3017b802007-08-28 17:01:53 -0400368 if (rx->skb->len < 8 + hdrlen)
369 return TXRX_DROP; /* TODO: count this? */
Johannes Berg571ecf62007-07-27 15:43:22 +0200370
Johannes Berg3017b802007-08-28 17:01:53 -0400371 /*
372 * no need to call ieee80211_wep_get_keyidx,
373 * it verifies a bunch of things we've done already
374 */
375 keyidx = rx->skb->data[hdrlen + 3] >> 6;
376
377 rx->key = rx->sdata->keys[keyidx];
378
379 /*
380 * RSNA-protected unicast frames should always be sent with
381 * pairwise or station-to-station keys, but for WEP we allow
382 * using a key index as well.
383 */
Johannes Berg8f20fc22007-08-28 17:01:54 -0400384 if (rx->key && rx->key->conf.alg != ALG_WEP &&
Johannes Berg3017b802007-08-28 17:01:53 -0400385 !is_multicast_ether_addr(hdr->addr1))
386 rx->key = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +0200387 }
388
Johannes Berg3017b802007-08-28 17:01:53 -0400389 if (rx->key) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200390 rx->key->tx_rx_count++;
391 if (unlikely(rx->local->key_tx_rx_threshold &&
392 rx->key->tx_rx_count >
393 rx->local->key_tx_rx_threshold)) {
394 ieee80211_key_threshold_notify(rx->dev, rx->key,
395 rx->sta);
396 }
397 }
398
399 return TXRX_CONTINUE;
400}
401
402static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
403{
404 struct ieee80211_sub_if_data *sdata;
405 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
406
407 if (sdata->bss)
408 atomic_inc(&sdata->bss->num_sta_ps);
409 sta->flags |= WLAN_STA_PS;
410 sta->pspoll = 0;
411#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
412 printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d enters power "
413 "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
414#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
415}
416
417static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
418{
419 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
420 struct sk_buff *skb;
421 int sent = 0;
422 struct ieee80211_sub_if_data *sdata;
423 struct ieee80211_tx_packet_data *pkt_data;
424
425 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
426 if (sdata->bss)
427 atomic_dec(&sdata->bss->num_sta_ps);
428 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
429 sta->pspoll = 0;
430 if (!skb_queue_empty(&sta->ps_tx_buf)) {
431 if (local->ops->set_tim)
432 local->ops->set_tim(local_to_hw(local), sta->aid, 0);
433 if (sdata->bss)
434 bss_tim_clear(local, sdata->bss, sta->aid);
435 }
436#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
437 printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d exits power "
438 "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
439#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
440 /* Send all buffered frames to the station */
441 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
442 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
443 sent++;
Jiri Slabye8bf9642007-08-28 17:01:54 -0400444 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200445 dev_queue_xmit(skb);
446 }
447 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
448 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
449 local->total_ps_buffered--;
450 sent++;
451#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
452 printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d send PS frame "
453 "since STA not sleeping anymore\n", dev->name,
454 MAC_ARG(sta->addr), sta->aid);
455#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Jiri Slabye8bf9642007-08-28 17:01:54 -0400456 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200457 dev_queue_xmit(skb);
458 }
459
460 return sent;
461}
462
463static ieee80211_txrx_result
464ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
465{
466 struct sta_info *sta = rx->sta;
467 struct net_device *dev = rx->dev;
468 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
469
470 if (!sta)
471 return TXRX_CONTINUE;
472
473 /* Update last_rx only for IBSS packets which are for the current
474 * BSSID to avoid keeping the current IBSS network alive in cases where
475 * other STAs are using different BSSID. */
476 if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
477 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
478 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
479 sta->last_rx = jiffies;
480 } else
481 if (!is_multicast_ether_addr(hdr->addr1) ||
482 rx->sdata->type == IEEE80211_IF_TYPE_STA) {
483 /* Update last_rx only for unicast frames in order to prevent
484 * the Probe Request frames (the only broadcast frames from a
485 * STA in infrastructure mode) from keeping a connection alive.
486 */
487 sta->last_rx = jiffies;
488 }
489
Jiri Slabybadffb72007-08-28 17:01:54 -0400490 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg571ecf62007-07-27 15:43:22 +0200491 return TXRX_CONTINUE;
492
493 sta->rx_fragments++;
494 sta->rx_bytes += rx->skb->len;
Larry Finger6c55aa92007-08-28 17:01:55 -0400495 sta->last_rssi = rx->u.rx.status->ssi;
496 sta->last_signal = rx->u.rx.status->signal;
497 sta->last_noise = rx->u.rx.status->noise;
Johannes Berg571ecf62007-07-27 15:43:22 +0200498
499 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
500 /* Change STA power saving mode only in the end of a frame
501 * exchange sequence */
502 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
503 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
504 else if (!(sta->flags & WLAN_STA_PS) &&
505 (rx->fc & IEEE80211_FCTL_PM))
506 ap_sta_ps_start(dev, sta);
507 }
508
509 /* Drop data::nullfunc frames silently, since they are used only to
510 * control station power saving mode. */
511 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
512 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
513 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
514 /* Update counter and free packet here to avoid counting this
515 * as a dropped packed. */
516 sta->rx_packets++;
517 dev_kfree_skb(rx->skb);
518 return TXRX_QUEUED;
519 }
520
521 return TXRX_CONTINUE;
522} /* ieee80211_rx_h_sta_process */
523
524static ieee80211_txrx_result
525ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
526{
527 if (!rx->sta || !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
528 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
Johannes Berg8f20fc22007-08-28 17:01:54 -0400529 !rx->key || rx->key->conf.alg != ALG_WEP ||
Jiri Slabybadffb72007-08-28 17:01:54 -0400530 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg571ecf62007-07-27 15:43:22 +0200531 return TXRX_CONTINUE;
532
533 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
534 if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) ||
Johannes Berg11a843b2007-08-28 17:01:55 -0400535 !(rx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Johannes Berg8f20fc22007-08-28 17:01:54 -0400536 if (ieee80211_wep_is_weak_iv(rx->skb, rx->key))
Johannes Berg571ecf62007-07-27 15:43:22 +0200537 rx->sta->wep_weak_iv_count++;
Johannes Berg571ecf62007-07-27 15:43:22 +0200538
539 return TXRX_CONTINUE;
540}
541
542static ieee80211_txrx_result
543ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
544{
Johannes Berg8f20fc22007-08-28 17:01:54 -0400545 if ((rx->key && rx->key->conf.alg != ALG_WEP) ||
Johannes Berg571ecf62007-07-27 15:43:22 +0200546 !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
547 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
548 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
549 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
550 return TXRX_CONTINUE;
551
552 if (!rx->key) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400553 if (net_ratelimit())
554 printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
555 rx->dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +0200556 return TXRX_DROP;
557 }
558
559 if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED) ||
Johannes Berg11a843b2007-08-28 17:01:55 -0400560 !(rx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200561 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400562 if (net_ratelimit())
563 printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
564 "failed\n", rx->dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +0200565 return TXRX_DROP;
566 }
567 } else if (rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
568 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
569 /* remove ICV */
570 skb_trim(rx->skb, rx->skb->len - 4);
571 }
572
573 return TXRX_CONTINUE;
574}
575
576static inline struct ieee80211_fragment_entry *
577ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
578 unsigned int frag, unsigned int seq, int rx_queue,
579 struct sk_buff **skb)
580{
581 struct ieee80211_fragment_entry *entry;
582 int idx;
583
584 idx = sdata->fragment_next;
585 entry = &sdata->fragments[sdata->fragment_next++];
586 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
587 sdata->fragment_next = 0;
588
589 if (!skb_queue_empty(&entry->skb_list)) {
590#ifdef CONFIG_MAC80211_DEBUG
591 struct ieee80211_hdr *hdr =
592 (struct ieee80211_hdr *) entry->skb_list.next->data;
593 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
594 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
595 "addr1=" MAC_FMT " addr2=" MAC_FMT "\n",
596 sdata->dev->name, idx,
597 jiffies - entry->first_frag_time, entry->seq,
598 entry->last_frag, MAC_ARG(hdr->addr1),
599 MAC_ARG(hdr->addr2));
600#endif /* CONFIG_MAC80211_DEBUG */
601 __skb_queue_purge(&entry->skb_list);
602 }
603
604 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
605 *skb = NULL;
606 entry->first_frag_time = jiffies;
607 entry->seq = seq;
608 entry->rx_queue = rx_queue;
609 entry->last_frag = frag;
610 entry->ccmp = 0;
611 entry->extra_len = 0;
612
613 return entry;
614}
615
616static inline struct ieee80211_fragment_entry *
617ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
618 u16 fc, unsigned int frag, unsigned int seq,
619 int rx_queue, struct ieee80211_hdr *hdr)
620{
621 struct ieee80211_fragment_entry *entry;
622 int i, idx;
623
624 idx = sdata->fragment_next;
625 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
626 struct ieee80211_hdr *f_hdr;
627 u16 f_fc;
628
629 idx--;
630 if (idx < 0)
631 idx = IEEE80211_FRAGMENT_MAX - 1;
632
633 entry = &sdata->fragments[idx];
634 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
635 entry->rx_queue != rx_queue ||
636 entry->last_frag + 1 != frag)
637 continue;
638
639 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
640 f_fc = le16_to_cpu(f_hdr->frame_control);
641
642 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
643 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
644 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
645 continue;
646
647 if (entry->first_frag_time + 2 * HZ < jiffies) {
648 __skb_queue_purge(&entry->skb_list);
649 continue;
650 }
651 return entry;
652 }
653
654 return NULL;
655}
656
657static ieee80211_txrx_result
658ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
659{
660 struct ieee80211_hdr *hdr;
661 u16 sc;
662 unsigned int frag, seq;
663 struct ieee80211_fragment_entry *entry;
664 struct sk_buff *skb;
665
666 hdr = (struct ieee80211_hdr *) rx->skb->data;
667 sc = le16_to_cpu(hdr->seq_ctrl);
668 frag = sc & IEEE80211_SCTL_FRAG;
669
670 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
671 (rx->skb)->len < 24 ||
672 is_multicast_ether_addr(hdr->addr1))) {
673 /* not fragmented */
674 goto out;
675 }
676 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
677
678 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
679
680 if (frag == 0) {
681 /* This is the first fragment of a new frame. */
682 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
683 rx->u.rx.queue, &(rx->skb));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400684 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
Johannes Berg571ecf62007-07-27 15:43:22 +0200685 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
686 /* Store CCMP PN so that we can verify that the next
687 * fragment has a sequential PN value. */
688 entry->ccmp = 1;
689 memcpy(entry->last_pn,
690 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
691 CCMP_PN_LEN);
692 }
693 return TXRX_QUEUED;
694 }
695
696 /* This is a fragment for a frame that should already be pending in
697 * fragment cache. Add this fragment to the end of the pending entry.
698 */
699 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
700 rx->u.rx.queue, hdr);
701 if (!entry) {
702 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
703 return TXRX_DROP;
704 }
705
706 /* Verify that MPDUs within one MSDU have sequential PN values.
707 * (IEEE 802.11i, 8.3.3.4.5) */
708 if (entry->ccmp) {
709 int i;
710 u8 pn[CCMP_PN_LEN], *rpn;
Johannes Berg8f20fc22007-08-28 17:01:54 -0400711 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
Johannes Berg571ecf62007-07-27 15:43:22 +0200712 return TXRX_DROP;
713 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
714 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
715 pn[i]++;
716 if (pn[i])
717 break;
718 }
719 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
720 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400721 if (net_ratelimit())
722 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
723 "sequential A2=" MAC_FMT
724 " PN=%02x%02x%02x%02x%02x%02x "
725 "(expected %02x%02x%02x%02x%02x%02x)\n",
726 rx->dev->name, MAC_ARG(hdr->addr2),
727 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
728 rpn[5], pn[0], pn[1], pn[2], pn[3],
729 pn[4], pn[5]);
Johannes Berg571ecf62007-07-27 15:43:22 +0200730 return TXRX_DROP;
731 }
732 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
733 }
734
735 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
736 __skb_queue_tail(&entry->skb_list, rx->skb);
737 entry->last_frag = frag;
738 entry->extra_len += rx->skb->len;
739 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
740 rx->skb = NULL;
741 return TXRX_QUEUED;
742 }
743
744 rx->skb = __skb_dequeue(&entry->skb_list);
745 if (skb_tailroom(rx->skb) < entry->extra_len) {
746 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
747 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
748 GFP_ATOMIC))) {
749 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
750 __skb_queue_purge(&entry->skb_list);
751 return TXRX_DROP;
752 }
753 }
754 while ((skb = __skb_dequeue(&entry->skb_list))) {
755 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
756 dev_kfree_skb(skb);
757 }
758
759 /* Complete frame has been reassembled - process it now */
Jiri Slabybadffb72007-08-28 17:01:54 -0400760 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200761
762 out:
763 if (rx->sta)
764 rx->sta->rx_packets++;
765 if (is_multicast_ether_addr(hdr->addr1))
766 rx->local->dot11MulticastReceivedFrameCount++;
767 else
768 ieee80211_led_rx(rx->local);
769 return TXRX_CONTINUE;
770}
771
772static ieee80211_txrx_result
773ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
774{
775 struct sk_buff *skb;
776 int no_pending_pkts;
777
778 if (likely(!rx->sta ||
779 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
780 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
Jiri Slabybadffb72007-08-28 17:01:54 -0400781 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
Johannes Berg571ecf62007-07-27 15:43:22 +0200782 return TXRX_CONTINUE;
783
784 skb = skb_dequeue(&rx->sta->tx_filtered);
785 if (!skb) {
786 skb = skb_dequeue(&rx->sta->ps_tx_buf);
787 if (skb)
788 rx->local->total_ps_buffered--;
789 }
790 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
791 skb_queue_empty(&rx->sta->ps_tx_buf);
792
793 if (skb) {
794 struct ieee80211_hdr *hdr =
795 (struct ieee80211_hdr *) skb->data;
796
797 /* tell TX path to send one frame even though the STA may
798 * still remain is PS mode after this frame exchange */
799 rx->sta->pspoll = 1;
800
801#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
802 printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS Poll (entries "
803 "after %d)\n",
804 MAC_ARG(rx->sta->addr), rx->sta->aid,
805 skb_queue_len(&rx->sta->ps_tx_buf));
806#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
807
808 /* Use MoreData flag to indicate whether there are more
809 * buffered frames for this STA */
810 if (no_pending_pkts) {
811 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
812 rx->sta->flags &= ~WLAN_STA_TIM;
813 } else
814 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
815
816 dev_queue_xmit(skb);
817
818 if (no_pending_pkts) {
819 if (rx->local->ops->set_tim)
820 rx->local->ops->set_tim(local_to_hw(rx->local),
821 rx->sta->aid, 0);
822 if (rx->sdata->bss)
823 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
824 }
825#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
826 } else if (!rx->u.rx.sent_ps_buffered) {
827 printk(KERN_DEBUG "%s: STA " MAC_FMT " sent PS Poll even "
828 "though there is no buffered frames for it\n",
829 rx->dev->name, MAC_ARG(rx->sta->addr));
830#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
831
832 }
833
834 /* Free PS Poll skb here instead of returning TXRX_DROP that would
835 * count as an dropped frame. */
836 dev_kfree_skb(rx->skb);
837
838 return TXRX_QUEUED;
839}
840
841static ieee80211_txrx_result
Johannes Berg6e0d1142007-07-27 15:43:22 +0200842ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
843{
844 u16 fc = rx->fc;
845 u8 *data = rx->skb->data;
846 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
847
848 if (!WLAN_FC_IS_QOS_DATA(fc))
849 return TXRX_CONTINUE;
850
851 /* remove the qos control field, update frame type and meta-data */
852 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
853 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
854 /* change frame type to non QOS */
855 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
856 hdr->frame_control = cpu_to_le16(fc);
857
858 return TXRX_CONTINUE;
859}
860
861static ieee80211_txrx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200862ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
863{
864 if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
Jiri Slabybadffb72007-08-28 17:01:54 -0400865 rx->sdata->type != IEEE80211_IF_TYPE_STA &&
866 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200867 /* Pass both encrypted and unencrypted EAPOL frames to user
868 * space for processing. */
869 if (!rx->local->apdev)
870 return TXRX_DROP;
871 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
872 ieee80211_msg_normal);
873 return TXRX_QUEUED;
874 }
875
876 if (unlikely(rx->sdata->ieee802_1x &&
877 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
878 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
879 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
880 !ieee80211_is_eapol(rx->skb))) {
881#ifdef CONFIG_MAC80211_DEBUG
882 struct ieee80211_hdr *hdr =
883 (struct ieee80211_hdr *) rx->skb->data;
884 printk(KERN_DEBUG "%s: dropped frame from " MAC_FMT
885 " (unauthorized port)\n", rx->dev->name,
886 MAC_ARG(hdr->addr2));
887#endif /* CONFIG_MAC80211_DEBUG */
888 return TXRX_DROP;
889 }
890
891 return TXRX_CONTINUE;
892}
893
894static ieee80211_txrx_result
895ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
896{
Johannes Berg3017b802007-08-28 17:01:53 -0400897 /*
898 * Pass through unencrypted frames if the hardware might have
899 * decrypted them already without telling us, but that can only
900 * be true if we either didn't find a key or the found key is
901 * uploaded to the hardware.
902 */
903 if ((rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) &&
Johannes Berg11a843b2007-08-28 17:01:55 -0400904 (!rx->key || (rx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)))
Johannes Berg571ecf62007-07-27 15:43:22 +0200905 return TXRX_CONTINUE;
906
907 /* Drop unencrypted frames if key is set. */
908 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
909 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
910 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
911 (rx->key || rx->sdata->drop_unencrypted) &&
912 (rx->sdata->eapol == 0 ||
913 !ieee80211_is_eapol(rx->skb)))) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400914 if (net_ratelimit())
915 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
916 "encryption\n", rx->dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +0200917 return TXRX_DROP;
918 }
919 return TXRX_CONTINUE;
920}
921
922static ieee80211_txrx_result
923ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
924{
925 struct net_device *dev = rx->dev;
926 struct ieee80211_local *local = rx->local;
927 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
928 u16 fc, hdrlen, ethertype;
929 u8 *payload;
930 u8 dst[ETH_ALEN];
931 u8 src[ETH_ALEN];
932 struct sk_buff *skb = rx->skb, *skb2;
933 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
934
935 fc = rx->fc;
936 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
937 return TXRX_CONTINUE;
938
939 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
940 return TXRX_DROP;
941
942 hdrlen = ieee80211_get_hdrlen(fc);
943
944 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
945 * header
946 * IEEE 802.11 address fields:
947 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
948 * 0 0 DA SA BSSID n/a
949 * 0 1 DA BSSID SA n/a
950 * 1 0 BSSID SA DA n/a
951 * 1 1 RA TA DA SA
952 */
953
954 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
955 case IEEE80211_FCTL_TODS:
956 /* BSSID SA DA */
957 memcpy(dst, hdr->addr3, ETH_ALEN);
958 memcpy(src, hdr->addr2, ETH_ALEN);
959
960 if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
961 sdata->type != IEEE80211_IF_TYPE_VLAN)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400962 if (net_ratelimit())
963 printk(KERN_DEBUG "%s: dropped ToDS frame "
964 "(BSSID=" MAC_FMT
965 " SA=" MAC_FMT
966 " DA=" MAC_FMT ")\n",
967 dev->name,
968 MAC_ARG(hdr->addr1),
969 MAC_ARG(hdr->addr2),
970 MAC_ARG(hdr->addr3));
Johannes Berg571ecf62007-07-27 15:43:22 +0200971 return TXRX_DROP;
972 }
973 break;
974 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
975 /* RA TA DA SA */
976 memcpy(dst, hdr->addr3, ETH_ALEN);
977 memcpy(src, hdr->addr4, ETH_ALEN);
978
979 if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400980 if (net_ratelimit())
981 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
982 "frame (RA=" MAC_FMT
983 " TA=" MAC_FMT " DA=" MAC_FMT
984 " SA=" MAC_FMT ")\n",
985 rx->dev->name,
986 MAC_ARG(hdr->addr1),
987 MAC_ARG(hdr->addr2),
988 MAC_ARG(hdr->addr3),
989 MAC_ARG(hdr->addr4));
Johannes Berg571ecf62007-07-27 15:43:22 +0200990 return TXRX_DROP;
991 }
992 break;
993 case IEEE80211_FCTL_FROMDS:
994 /* DA BSSID SA */
995 memcpy(dst, hdr->addr1, ETH_ALEN);
996 memcpy(src, hdr->addr3, ETH_ALEN);
997
John W. Linvilleb3316152007-08-28 17:01:55 -0400998 if (sdata->type != IEEE80211_IF_TYPE_STA ||
999 (is_multicast_ether_addr(dst) &&
1000 !compare_ether_addr(src, dev->dev_addr)))
Johannes Berg571ecf62007-07-27 15:43:22 +02001001 return TXRX_DROP;
Johannes Berg571ecf62007-07-27 15:43:22 +02001002 break;
1003 case 0:
1004 /* DA SA BSSID */
1005 memcpy(dst, hdr->addr1, ETH_ALEN);
1006 memcpy(src, hdr->addr2, ETH_ALEN);
1007
1008 if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
1009 if (net_ratelimit()) {
1010 printk(KERN_DEBUG "%s: dropped IBSS frame (DA="
1011 MAC_FMT " SA=" MAC_FMT " BSSID=" MAC_FMT
1012 ")\n",
1013 dev->name, MAC_ARG(hdr->addr1),
1014 MAC_ARG(hdr->addr2),
1015 MAC_ARG(hdr->addr3));
1016 }
1017 return TXRX_DROP;
1018 }
1019 break;
1020 }
1021
1022 payload = skb->data + hdrlen;
1023
1024 if (unlikely(skb->len - hdrlen < 8)) {
1025 if (net_ratelimit()) {
1026 printk(KERN_DEBUG "%s: RX too short data frame "
1027 "payload\n", dev->name);
1028 }
1029 return TXRX_DROP;
1030 }
1031
1032 ethertype = (payload[6] << 8) | payload[7];
1033
1034 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1035 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1036 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1037 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1038 * replace EtherType */
1039 skb_pull(skb, hdrlen + 6);
1040 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1041 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1042 } else {
1043 struct ethhdr *ehdr;
1044 __be16 len;
1045 skb_pull(skb, hdrlen);
1046 len = htons(skb->len);
1047 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1048 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1049 memcpy(ehdr->h_source, src, ETH_ALEN);
1050 ehdr->h_proto = len;
1051 }
1052 skb->dev = dev;
1053
1054 skb2 = NULL;
1055
1056 sdata->stats.rx_packets++;
1057 sdata->stats.rx_bytes += skb->len;
1058
1059 if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP
Jiri Slabybadffb72007-08-28 17:01:54 -04001060 || sdata->type == IEEE80211_IF_TYPE_VLAN) &&
1061 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001062 if (is_multicast_ether_addr(skb->data)) {
1063 /* send multicast frames both to higher layers in
1064 * local net stack and back to the wireless media */
1065 skb2 = skb_copy(skb, GFP_ATOMIC);
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001066 if (!skb2 && net_ratelimit())
Johannes Berg571ecf62007-07-27 15:43:22 +02001067 printk(KERN_DEBUG "%s: failed to clone "
1068 "multicast frame\n", dev->name);
1069 } else {
1070 struct sta_info *dsta;
1071 dsta = sta_info_get(local, skb->data);
1072 if (dsta && !dsta->dev) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001073 if (net_ratelimit())
1074 printk(KERN_DEBUG "Station with null "
1075 "dev structure!\n");
Johannes Berg571ecf62007-07-27 15:43:22 +02001076 } else if (dsta && dsta->dev == dev) {
1077 /* Destination station is associated to this
1078 * AP, so send the frame directly to it and
1079 * do not pass the frame to local net stack.
1080 */
1081 skb2 = skb;
1082 skb = NULL;
1083 }
1084 if (dsta)
1085 sta_info_put(dsta);
1086 }
1087 }
1088
1089 if (skb) {
1090 /* deliver to local stack */
1091 skb->protocol = eth_type_trans(skb, dev);
1092 memset(skb->cb, 0, sizeof(skb->cb));
1093 netif_rx(skb);
1094 }
1095
1096 if (skb2) {
1097 /* send to wireless media */
1098 skb2->protocol = __constant_htons(ETH_P_802_3);
1099 skb_set_network_header(skb2, 0);
1100 skb_set_mac_header(skb2, 0);
1101 dev_queue_xmit(skb2);
1102 }
1103
1104 return TXRX_QUEUED;
1105}
1106
1107static ieee80211_txrx_result
1108ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1109{
1110 struct ieee80211_sub_if_data *sdata;
1111
Jiri Slabybadffb72007-08-28 17:01:54 -04001112 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg571ecf62007-07-27 15:43:22 +02001113 return TXRX_DROP;
1114
1115 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1116 if ((sdata->type == IEEE80211_IF_TYPE_STA ||
1117 sdata->type == IEEE80211_IF_TYPE_IBSS) &&
1118 !rx->local->user_space_mlme) {
1119 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
1120 } else {
1121 /* Management frames are sent to hostapd for processing */
1122 if (!rx->local->apdev)
1123 return TXRX_DROP;
1124 ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
1125 ieee80211_msg_normal);
1126 }
1127 return TXRX_QUEUED;
1128}
1129
1130static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1131 struct ieee80211_local *local,
1132 ieee80211_rx_handler *handlers,
1133 struct ieee80211_txrx_data *rx,
1134 struct sta_info *sta)
1135{
1136 ieee80211_rx_handler *handler;
1137 ieee80211_txrx_result res = TXRX_DROP;
1138
1139 for (handler = handlers; *handler != NULL; handler++) {
1140 res = (*handler)(rx);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001141
1142 switch (res) {
1143 case TXRX_CONTINUE:
1144 continue;
1145 case TXRX_DROP:
1146 I802_DEBUG_INC(local->rx_handlers_drop);
1147 if (sta)
1148 sta->rx_dropped++;
1149 break;
1150 case TXRX_QUEUED:
1151 I802_DEBUG_INC(local->rx_handlers_queued);
Johannes Berg571ecf62007-07-27 15:43:22 +02001152 break;
1153 }
Johannes Berg8e6f00322007-07-27 15:43:22 +02001154 break;
Johannes Berg571ecf62007-07-27 15:43:22 +02001155 }
1156
Johannes Berg8e6f00322007-07-27 15:43:22 +02001157 if (res == TXRX_DROP)
Johannes Berg571ecf62007-07-27 15:43:22 +02001158 dev_kfree_skb(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001159 return res;
1160}
1161
1162static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1163 ieee80211_rx_handler *handlers,
1164 struct ieee80211_txrx_data *rx,
1165 struct sta_info *sta)
1166{
1167 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1168 TXRX_CONTINUE)
1169 dev_kfree_skb(rx->skb);
1170}
1171
1172static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1173 struct ieee80211_hdr *hdr,
1174 struct sta_info *sta,
1175 struct ieee80211_txrx_data *rx)
1176{
1177 int keyidx, hdrlen;
1178
1179 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1180 if (rx->skb->len >= hdrlen + 4)
1181 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1182 else
1183 keyidx = -1;
1184
1185 /* TODO: verify that this is not triggered by fragmented
1186 * frames (hw does not verify MIC for them). */
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001187 if (net_ratelimit())
1188 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
1189 "failure from " MAC_FMT " to " MAC_FMT " keyidx=%d\n",
1190 dev->name, MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr1),
1191 keyidx);
Johannes Berg571ecf62007-07-27 15:43:22 +02001192
1193 if (!sta) {
1194 /* Some hardware versions seem to generate incorrect
1195 * Michael MIC reports; ignore them to avoid triggering
1196 * countermeasures. */
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001197 if (net_ratelimit())
1198 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1199 "error for unknown address " MAC_FMT "\n",
1200 dev->name, MAC_ARG(hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001201 goto ignore;
1202 }
1203
1204 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001205 if (net_ratelimit())
1206 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1207 "error for a frame with no ISWEP flag (src "
1208 MAC_FMT ")\n", dev->name, MAC_ARG(hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001209 goto ignore;
1210 }
1211
1212 if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) &&
Johannes Bergeb063c12007-08-28 17:01:53 -04001213 rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001214 /* AP with Pairwise keys support should never receive Michael
1215 * MIC errors for non-zero keyidx because these are reserved
1216 * for group keys and only the AP is sending real multicast
1217 * frames in BSS. */
Johannes Bergeb063c12007-08-28 17:01:53 -04001218 if (net_ratelimit())
1219 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1220 "a frame with non-zero keyidx (%d)"
1221 " (src " MAC_FMT ")\n", dev->name, keyidx,
1222 MAC_ARG(hdr->addr2));
1223 goto ignore;
Johannes Berg571ecf62007-07-27 15:43:22 +02001224 }
1225
1226 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1227 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1228 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001229 if (net_ratelimit())
1230 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1231 "error for a frame that cannot be encrypted "
1232 "(fc=0x%04x) (src " MAC_FMT ")\n",
1233 dev->name, rx->fc, MAC_ARG(hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001234 goto ignore;
1235 }
1236
Johannes Berg571ecf62007-07-27 15:43:22 +02001237 /* TODO: consider verifying the MIC error report with software
1238 * implementation if we get too many spurious reports from the
1239 * hardware. */
Johannes Berg571ecf62007-07-27 15:43:22 +02001240
Johannes Bergeb063c12007-08-28 17:01:53 -04001241 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02001242 ignore:
1243 dev_kfree_skb(rx->skb);
1244 rx->skb = NULL;
1245}
1246
1247ieee80211_rx_handler ieee80211_rx_handlers[] =
1248{
1249 ieee80211_rx_h_if_stats,
1250 ieee80211_rx_h_monitor,
1251 ieee80211_rx_h_passive_scan,
1252 ieee80211_rx_h_check,
Johannes Berg570bd532007-07-27 15:43:22 +02001253 ieee80211_rx_h_load_key,
Johannes Berg571ecf62007-07-27 15:43:22 +02001254 ieee80211_rx_h_sta_process,
1255 ieee80211_rx_h_ccmp_decrypt,
1256 ieee80211_rx_h_tkip_decrypt,
1257 ieee80211_rx_h_wep_weak_iv_detection,
1258 ieee80211_rx_h_wep_decrypt,
1259 ieee80211_rx_h_defragment,
1260 ieee80211_rx_h_ps_poll,
1261 ieee80211_rx_h_michael_mic_verify,
1262 /* this must be after decryption - so header is counted in MPDU mic
1263 * must be before pae and data, so QOS_DATA format frames
1264 * are not passed to user space by these functions
1265 */
1266 ieee80211_rx_h_remove_qos_control,
1267 ieee80211_rx_h_802_1x_pae,
1268 ieee80211_rx_h_drop_unencrypted,
1269 ieee80211_rx_h_data,
1270 ieee80211_rx_h_mgmt,
1271 NULL
1272};
1273
1274/* main receive path */
1275
Johannes Berg23a24de2007-07-27 15:43:22 +02001276static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1277 u8 *bssid, struct ieee80211_txrx_data *rx,
1278 struct ieee80211_hdr *hdr)
1279{
1280 int multicast = is_multicast_ether_addr(hdr->addr1);
1281
1282 switch (sdata->type) {
1283 case IEEE80211_IF_TYPE_STA:
1284 if (!bssid)
1285 return 0;
1286 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001287 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001288 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001289 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001290 } else if (!multicast &&
1291 compare_ether_addr(sdata->dev->dev_addr,
1292 hdr->addr1) != 0) {
Jiri Slaby13262ff2007-08-28 17:01:54 -04001293 if (!(sdata->flags & IEEE80211_SDATA_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02001294 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001295 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001296 }
1297 break;
1298 case IEEE80211_IF_TYPE_IBSS:
1299 if (!bssid)
1300 return 0;
1301 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001302 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001303 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001304 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001305 } else if (!multicast &&
1306 compare_ether_addr(sdata->dev->dev_addr,
1307 hdr->addr1) != 0) {
Jiri Slaby13262ff2007-08-28 17:01:54 -04001308 if (!(sdata->flags & IEEE80211_SDATA_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02001309 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001310 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001311 } else if (!rx->sta)
1312 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1313 bssid, hdr->addr2);
1314 break;
1315 case IEEE80211_IF_TYPE_AP:
1316 if (!bssid) {
1317 if (compare_ether_addr(sdata->dev->dev_addr,
1318 hdr->addr1))
1319 return 0;
1320 } else if (!ieee80211_bssid_match(bssid,
1321 sdata->dev->dev_addr)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001322 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001323 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001324 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001325 }
Jiri Slabybadffb72007-08-28 17:01:54 -04001326 if (sdata->dev == sdata->local->mdev &&
1327 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001328 /* do not receive anything via
1329 * master device when not scanning */
1330 return 0;
1331 break;
1332 case IEEE80211_IF_TYPE_WDS:
1333 if (bssid ||
1334 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1335 return 0;
1336 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1337 return 0;
1338 break;
1339 }
1340
1341 return 1;
1342}
1343
Johannes Berg571ecf62007-07-27 15:43:22 +02001344/*
1345 * This is the receive path handler. It is called by a low level driver when an
1346 * 802.11 MPDU is received from the hardware.
1347 */
1348void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1349 struct ieee80211_rx_status *status)
1350{
1351 struct ieee80211_local *local = hw_to_local(hw);
1352 struct ieee80211_sub_if_data *sdata;
1353 struct sta_info *sta;
1354 struct ieee80211_hdr *hdr;
1355 struct ieee80211_txrx_data rx;
1356 u16 type;
Johannes Berg23a24de2007-07-27 15:43:22 +02001357 int radiotap_len = 0, prepres;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001358 struct ieee80211_sub_if_data *prev = NULL;
1359 struct sk_buff *skb_new;
1360 u8 *bssid;
Johannes Berg571ecf62007-07-27 15:43:22 +02001361
1362 if (status->flag & RX_FLAG_RADIOTAP) {
1363 radiotap_len = ieee80211_get_radiotap_len(skb->data);
1364 skb_pull(skb, radiotap_len);
1365 }
1366
1367 hdr = (struct ieee80211_hdr *) skb->data;
1368 memset(&rx, 0, sizeof(rx));
1369 rx.skb = skb;
1370 rx.local = local;
1371
1372 rx.u.rx.status = status;
1373 rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0;
1374 type = rx.fc & IEEE80211_FCTL_FTYPE;
1375 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
1376 local->dot11ReceivedFragmentCount++;
Johannes Berg571ecf62007-07-27 15:43:22 +02001377
Johannes Berg23a24de2007-07-27 15:43:22 +02001378 if (skb->len >= 16) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001379 sta = rx.sta = sta_info_get(local, hdr->addr2);
Johannes Berg23a24de2007-07-27 15:43:22 +02001380 if (sta) {
1381 rx.dev = rx.sta->dev;
1382 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1383 }
1384 } else
Johannes Berg571ecf62007-07-27 15:43:22 +02001385 sta = rx.sta = NULL;
1386
Johannes Berg571ecf62007-07-27 15:43:22 +02001387 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1388 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
1389 goto end;
1390 }
1391
1392 if (unlikely(local->sta_scanning))
Jiri Slabybadffb72007-08-28 17:01:54 -04001393 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
Johannes Berg571ecf62007-07-27 15:43:22 +02001394
1395 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
1396 sta) != TXRX_CONTINUE)
1397 goto end;
1398 skb = rx.skb;
1399
1400 skb_push(skb, radiotap_len);
1401 if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS) &&
Johannes Berg23a24de2007-07-27 15:43:22 +02001402 !local->iff_promiscs && !is_multicast_ether_addr(hdr->addr1)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001403 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg571ecf62007-07-27 15:43:22 +02001404 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
Johannes Berg23a24de2007-07-27 15:43:22 +02001405 rx.sta);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001406 sta_info_put(sta);
1407 return;
1408 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001409
Johannes Berg8e6f00322007-07-27 15:43:22 +02001410 bssid = ieee80211_get_bssid(hdr, skb->len - radiotap_len);
Johannes Berg571ecf62007-07-27 15:43:22 +02001411
Johannes Berg8e6f00322007-07-27 15:43:22 +02001412 read_lock(&local->sub_if_lock);
1413 list_for_each_entry(sdata, &local->sub_if_list, list) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001414 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001415
Johannes Berg2a8a9a82007-08-28 17:01:52 -04001416 if (!netif_running(sdata->dev))
1417 continue;
1418
Johannes Berg23a24de2007-07-27 15:43:22 +02001419 prepres = prepare_for_handlers(sdata, bssid, &rx, hdr);
1420 /* prepare_for_handlers can change sta */
1421 sta = rx.sta;
1422
1423 if (!prepres)
1424 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001425
Johannes Berg340e11f2007-07-27 15:43:22 +02001426 /*
1427 * frame is destined for this interface, but if it's not
1428 * also for the previous one we handle that after the
1429 * loop to avoid copying the SKB once too much
1430 */
1431
1432 if (!prev) {
1433 prev = sdata;
1434 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001435 }
Johannes Berg340e11f2007-07-27 15:43:22 +02001436
1437 /*
1438 * frame was destined for the previous interface
1439 * so invoke RX handlers for it
1440 */
1441
1442 skb_new = skb_copy(skb, GFP_ATOMIC);
1443 if (!skb_new) {
1444 if (net_ratelimit())
1445 printk(KERN_DEBUG "%s: failed to copy "
1446 "multicast frame for %s",
1447 local->mdev->name, prev->dev->name);
1448 continue;
1449 }
1450 rx.skb = skb_new;
1451 rx.dev = prev->dev;
1452 rx.sdata = prev;
1453 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1454 &rx, sta);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001455 prev = sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02001456 }
Johannes Berg8e6f00322007-07-27 15:43:22 +02001457 if (prev) {
1458 rx.skb = skb;
1459 rx.dev = prev->dev;
1460 rx.sdata = prev;
1461 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1462 &rx, sta);
1463 } else
1464 dev_kfree_skb(skb);
1465 read_unlock(&local->sub_if_lock);
Johannes Berg571ecf62007-07-27 15:43:22 +02001466
Johannes Berg8e6f00322007-07-27 15:43:22 +02001467 end:
Johannes Berg571ecf62007-07-27 15:43:22 +02001468 if (sta)
1469 sta_info_put(sta);
1470}
1471EXPORT_SYMBOL(__ieee80211_rx);
1472
1473/* This is a version of the rx handler that can be called from hard irq
1474 * context. Post the skb on the queue and schedule the tasklet */
1475void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
1476 struct ieee80211_rx_status *status)
1477{
1478 struct ieee80211_local *local = hw_to_local(hw);
1479
1480 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
1481
1482 skb->dev = local->mdev;
1483 /* copy status into skb->cb for use by tasklet */
1484 memcpy(skb->cb, status, sizeof(*status));
1485 skb->pkt_type = IEEE80211_RX_MSG;
1486 skb_queue_tail(&local->skb_queue, skb);
1487 tasklet_schedule(&local->tasklet);
1488}
1489EXPORT_SYMBOL(ieee80211_rx_irqsafe);