blob: 48574f6c0e74af0c76c87d860cf590d32c315145 [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
S.Çağlar Onurab466232008-02-14 17:36:47 +020012#include <linux/jiffies.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020013#include <linux/kernel.h>
14#include <linux/skbuff.h>
15#include <linux/netdevice.h>
16#include <linux/etherdevice.h>
Johannes Bergd4e46a32007-09-14 11:10:24 -040017#include <linux/rcupdate.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020018#include <net/mac80211.h>
19#include <net/ieee80211_radiotap.h>
20
21#include "ieee80211_i.h"
22#include "ieee80211_led.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020023#include "wep.h"
24#include "wpa.h"
25#include "tkip.h"
26#include "wme.h"
27
Ron Rindjunsky71364712007-12-25 17:00:36 +020028u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
29 struct tid_ampdu_rx *tid_agg_rx,
30 struct sk_buff *skb, u16 mpdu_seq_num,
31 int bar_req);
Johannes Bergb2e77712007-09-26 15:19:39 +020032/*
33 * monitor mode reception
34 *
35 * This function cleans up the SKB, i.e. it removes all the stuff
36 * only useful for monitoring.
37 */
38static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
39 struct sk_buff *skb,
40 int rtap_len)
41{
42 skb_pull(skb, rtap_len);
43
44 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
45 if (likely(skb->len > FCS_LEN))
46 skb_trim(skb, skb->len - FCS_LEN);
47 else {
48 /* driver bug */
49 WARN_ON(1);
50 dev_kfree_skb(skb);
51 skb = NULL;
52 }
53 }
54
55 return skb;
56}
57
58static inline int should_drop_frame(struct ieee80211_rx_status *status,
59 struct sk_buff *skb,
60 int present_fcs_len,
61 int radiotap_len)
62{
63 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
64
65 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
66 return 1;
67 if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len))
68 return 1;
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +020069 if (((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
70 cpu_to_le16(IEEE80211_FTYPE_CTL)) &&
71 ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) !=
Ron Rindjunsky71364712007-12-25 17:00:36 +020072 cpu_to_le16(IEEE80211_STYPE_PSPOLL)) &&
73 ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) !=
74 cpu_to_le16(IEEE80211_STYPE_BACK_REQ)))
Johannes Bergb2e77712007-09-26 15:19:39 +020075 return 1;
76 return 0;
77}
78
79/*
80 * This function copies a received frame to all monitor interfaces and
81 * returns a cleaned-up SKB that no longer includes the FCS nor the
82 * radiotap header the driver might have added.
83 */
84static struct sk_buff *
85ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
Johannes Berg8318d782008-01-24 19:38:38 +010086 struct ieee80211_rx_status *status,
87 struct ieee80211_rate *rate)
Johannes Bergb2e77712007-09-26 15:19:39 +020088{
89 struct ieee80211_sub_if_data *sdata;
Johannes Bergb2e77712007-09-26 15:19:39 +020090 int needed_headroom = 0;
Johannes Bergc49e5ea2007-12-11 21:33:42 +010091 struct ieee80211_radiotap_header *rthdr;
92 __le64 *rttsft = NULL;
93 struct ieee80211_rtap_fixed_data {
Johannes Bergb2e77712007-09-26 15:19:39 +020094 u8 flags;
95 u8 rate;
96 __le16 chan_freq;
97 __le16 chan_flags;
98 u8 antsignal;
99 u8 padding_for_rxflags;
100 __le16 rx_flags;
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100101 } __attribute__ ((packed)) *rtfixed;
Johannes Bergb2e77712007-09-26 15:19:39 +0200102 struct sk_buff *skb, *skb2;
103 struct net_device *prev_dev = NULL;
104 int present_fcs_len = 0;
105 int rtap_len = 0;
106
107 /*
108 * First, we may need to make a copy of the skb because
109 * (1) we need to modify it for radiotap (if not present), and
110 * (2) the other RX handlers will modify the skb we got.
111 *
112 * We don't need to, of course, if we aren't going to return
113 * the SKB because it has a bad FCS/PLCP checksum.
114 */
115 if (status->flag & RX_FLAG_RADIOTAP)
116 rtap_len = ieee80211_get_radiotap_len(origskb->data);
117 else
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100118 /* room for radiotap header, always present fields and TSFT */
119 needed_headroom = sizeof(*rthdr) + sizeof(*rtfixed) + 8;
Johannes Bergb2e77712007-09-26 15:19:39 +0200120
121 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
122 present_fcs_len = FCS_LEN;
123
124 if (!local->monitors) {
125 if (should_drop_frame(status, origskb, present_fcs_len,
126 rtap_len)) {
127 dev_kfree_skb(origskb);
128 return NULL;
129 }
130
131 return remove_monitor_info(local, origskb, rtap_len);
132 }
133
134 if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) {
135 /* only need to expand headroom if necessary */
136 skb = origskb;
137 origskb = NULL;
138
139 /*
140 * This shouldn't trigger often because most devices have an
141 * RX header they pull before we get here, and that should
142 * be big enough for our radiotap information. We should
143 * probably export the length to drivers so that we can have
144 * them allocate enough headroom to start with.
145 */
146 if (skb_headroom(skb) < needed_headroom &&
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100147 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200148 dev_kfree_skb(skb);
149 return NULL;
150 }
151 } else {
152 /*
153 * Need to make a copy and possibly remove radiotap header
154 * and FCS from the original.
155 */
156 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
157
158 origskb = remove_monitor_info(local, origskb, rtap_len);
159
160 if (!skb)
161 return origskb;
162 }
163
164 /* if necessary, prepend radiotap information */
165 if (!(status->flag & RX_FLAG_RADIOTAP)) {
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100166 rtfixed = (void *) skb_push(skb, sizeof(*rtfixed));
167 rtap_len = sizeof(*rthdr) + sizeof(*rtfixed);
168 if (status->flag & RX_FLAG_TSFT) {
169 rttsft = (void *) skb_push(skb, sizeof(*rttsft));
170 rtap_len += 8;
171 }
Johannes Bergb2e77712007-09-26 15:19:39 +0200172 rthdr = (void *) skb_push(skb, sizeof(*rthdr));
173 memset(rthdr, 0, sizeof(*rthdr));
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100174 memset(rtfixed, 0, sizeof(*rtfixed));
175 rthdr->it_present =
Johannes Bergb2e77712007-09-26 15:19:39 +0200176 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
177 (1 << IEEE80211_RADIOTAP_RATE) |
178 (1 << IEEE80211_RADIOTAP_CHANNEL) |
179 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |
180 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100181 rtfixed->flags = 0;
182 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
183 rtfixed->flags |= IEEE80211_RADIOTAP_F_FCS;
184
185 if (rttsft) {
186 *rttsft = cpu_to_le64(status->mactime);
187 rthdr->it_present |=
188 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
189 }
Johannes Bergb2e77712007-09-26 15:19:39 +0200190
191 /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100192 rtfixed->rx_flags = 0;
Johannes Bergb2e77712007-09-26 15:19:39 +0200193 if (status->flag &
194 (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100195 rtfixed->rx_flags |=
Johannes Bergb2e77712007-09-26 15:19:39 +0200196 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
197
Johannes Berg8318d782008-01-24 19:38:38 +0100198 rtfixed->rate = rate->bitrate / 5;
Johannes Bergb2e77712007-09-26 15:19:39 +0200199
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100200 rtfixed->chan_freq = cpu_to_le16(status->freq);
Johannes Bergb2e77712007-09-26 15:19:39 +0200201
Johannes Berg8318d782008-01-24 19:38:38 +0100202 if (status->band == IEEE80211_BAND_5GHZ)
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100203 rtfixed->chan_flags =
Johannes Bergb2e77712007-09-26 15:19:39 +0200204 cpu_to_le16(IEEE80211_CHAN_OFDM |
205 IEEE80211_CHAN_5GHZ);
206 else
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100207 rtfixed->chan_flags =
Johannes Bergb2e77712007-09-26 15:19:39 +0200208 cpu_to_le16(IEEE80211_CHAN_DYN |
209 IEEE80211_CHAN_2GHZ);
210
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100211 rtfixed->antsignal = status->ssi;
212 rthdr->it_len = cpu_to_le16(rtap_len);
Johannes Bergb2e77712007-09-26 15:19:39 +0200213 }
214
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100215 skb_reset_mac_header(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200216 skb->ip_summed = CHECKSUM_UNNECESSARY;
217 skb->pkt_type = PACKET_OTHERHOST;
218 skb->protocol = htons(ETH_P_802_2);
219
220 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
221 if (!netif_running(sdata->dev))
222 continue;
223
Johannes Berg51fb61e2007-12-19 01:31:27 +0100224 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR)
Johannes Bergb2e77712007-09-26 15:19:39 +0200225 continue;
226
Michael Wu3d30d942008-01-31 19:48:27 +0100227 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
228 continue;
229
Johannes Bergb2e77712007-09-26 15:19:39 +0200230 if (prev_dev) {
231 skb2 = skb_clone(skb, GFP_ATOMIC);
232 if (skb2) {
233 skb2->dev = prev_dev;
234 netif_rx(skb2);
235 }
236 }
237
238 prev_dev = sdata->dev;
239 sdata->dev->stats.rx_packets++;
240 sdata->dev->stats.rx_bytes += skb->len;
241 }
242
243 if (prev_dev) {
244 skb->dev = prev_dev;
245 netif_rx(skb);
246 } else
247 dev_kfree_skb(skb);
248
249 return origskb;
250}
251
252
Johannes Berg38f37142008-01-29 17:07:43 +0100253static void ieee80211_parse_qos(struct ieee80211_txrx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +0200254{
255 u8 *data = rx->skb->data;
256 int tid;
257
258 /* does the frame have a qos control field? */
259 if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
260 u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
261 /* frame has qos control */
262 tid = qc[0] & QOS_CONTROL_TID_MASK;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +0200263 if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
Ron Rindjunsky64bd4b62007-11-29 10:35:53 +0200264 rx->flags |= IEEE80211_TXRXD_RX_AMSDU;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +0200265 else
Ron Rindjunsky64bd4b62007-11-29 10:35:53 +0200266 rx->flags &= ~IEEE80211_TXRXD_RX_AMSDU;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200267 } else {
268 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
269 /* Separate TID for management frames */
270 tid = NUM_RX_DATA_QUEUES - 1;
271 } else {
272 /* no qos control present */
273 tid = 0; /* 802.1d - Best Effort */
274 }
275 }
Johannes Berg52865dfd2007-07-27 15:43:22 +0200276
Johannes Berg6e0d1142007-07-27 15:43:22 +0200277 I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
Johannes Berg52865dfd2007-07-27 15:43:22 +0200278 /* only a debug counter, sta might not be assigned properly yet */
279 if (rx->sta)
Johannes Berg6e0d1142007-07-27 15:43:22 +0200280 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
Johannes Berg6e0d1142007-07-27 15:43:22 +0200281
282 rx->u.rx.queue = tid;
283 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
284 * For now, set skb->priority to 0 for other cases. */
285 rx->skb->priority = (tid > 7) ? 0 : tid;
Johannes Berg38f37142008-01-29 17:07:43 +0100286}
Johannes Berg6e0d1142007-07-27 15:43:22 +0200287
Johannes Berg38f37142008-01-29 17:07:43 +0100288static void ieee80211_verify_ip_alignment(struct ieee80211_txrx_data *rx)
289{
290#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
291 int hdrlen;
292
293 if (!WLAN_FC_DATA_PRESENT(rx->fc))
294 return;
295
296 /*
297 * Drivers are required to align the payload data in a way that
298 * guarantees that the contained IP header is aligned to a four-
299 * byte boundary. In the case of regular frames, this simply means
300 * aligning the payload to a four-byte boundary (because either
301 * the IP header is directly contained, or IV/RFC1042 headers that
302 * have a length divisible by four are in front of it.
303 *
304 * With A-MSDU frames, however, the payload data address must
305 * yield two modulo four because there are 14-byte 802.3 headers
306 * within the A-MSDU frames that push the IP header further back
307 * to a multiple of four again. Thankfully, the specs were sane
308 * enough this time around to require padding each A-MSDU subframe
309 * to a length that is a multiple of four.
310 *
311 * Padding like atheros hardware adds which is inbetween the 802.11
312 * header and the payload is not supported, the driver is required
313 * to move the 802.11 header further back in that case.
314 */
315 hdrlen = ieee80211_get_hdrlen(rx->fc);
316 if (rx->flags & IEEE80211_TXRXD_RX_AMSDU)
317 hdrlen += ETH_HLEN;
318 WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3);
319#endif
Johannes Berg6e0d1142007-07-27 15:43:22 +0200320}
321
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +0200322
Ron Rindjunsky71ebb4a2008-01-21 12:39:12 +0200323static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
Johannes Berg8318d782008-01-24 19:38:38 +0100324 struct sk_buff *skb,
325 struct ieee80211_rx_status *status,
326 struct ieee80211_rate *rate)
Johannes Berg571ecf62007-07-27 15:43:22 +0200327{
Johannes Berg571ecf62007-07-27 15:43:22 +0200328 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
329 u32 load = 0, hdrtime;
Johannes Berg571ecf62007-07-27 15:43:22 +0200330
331 /* Estimate total channel use caused by this frame */
332
Johannes Berg571ecf62007-07-27 15:43:22 +0200333 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
334 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
335
Johannes Berg8318d782008-01-24 19:38:38 +0100336 if (status->band == IEEE80211_BAND_5GHZ ||
337 (status->band == IEEE80211_BAND_5GHZ &&
338 rate->flags & IEEE80211_RATE_ERP_G))
Johannes Berg571ecf62007-07-27 15:43:22 +0200339 hdrtime = CHAN_UTIL_HDR_SHORT;
340 else
341 hdrtime = CHAN_UTIL_HDR_LONG;
342
343 load = hdrtime;
344 if (!is_multicast_ether_addr(hdr->addr1))
345 load += hdrtime;
346
Johannes Berg8318d782008-01-24 19:38:38 +0100347 /* TODO: optimise again */
348 load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
Johannes Berg571ecf62007-07-27 15:43:22 +0200349
350 /* Divide channel_use by 8 to avoid wrapping around the counter */
351 load >>= CHAN_UTIL_SHIFT;
Johannes Berg571ecf62007-07-27 15:43:22 +0200352
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +0200353 return load;
Johannes Berg571ecf62007-07-27 15:43:22 +0200354}
355
Johannes Berg571ecf62007-07-27 15:43:22 +0200356/* rx handlers */
357
Johannes Berg9ae54c82008-01-31 19:48:20 +0100358static ieee80211_rx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200359ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
360{
Johannes Berg52865dfd2007-07-27 15:43:22 +0200361 if (rx->sta)
362 rx->sta->channel_use_raw += rx->u.rx.load;
Johannes Berg571ecf62007-07-27 15:43:22 +0200363 rx->sdata->channel_use_raw += rx->u.rx.load;
Johannes Berg9ae54c82008-01-31 19:48:20 +0100364 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200365}
366
Johannes Berg9ae54c82008-01-31 19:48:20 +0100367static ieee80211_rx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200368ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
369{
370 struct ieee80211_local *local = rx->local;
371 struct sk_buff *skb = rx->skb;
372
Zhu Yiece8edd2007-11-22 10:53:21 +0800373 if (unlikely(local->sta_hw_scanning))
374 return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
375
376 if (unlikely(local->sta_sw_scanning)) {
377 /* drop all the other packets during a software scan anyway */
378 if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status)
Johannes Berg9ae54c82008-01-31 19:48:20 +0100379 != RX_QUEUED)
Zhu Yiece8edd2007-11-22 10:53:21 +0800380 dev_kfree_skb(skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100381 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200382 }
383
Jiri Slabybadffb72007-08-28 17:01:54 -0400384 if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200385 /* scanning finished during invoking of handlers */
386 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100387 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200388 }
389
Johannes Berg9ae54c82008-01-31 19:48:20 +0100390 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200391}
392
Johannes Berg9ae54c82008-01-31 19:48:20 +0100393static ieee80211_rx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200394ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
395{
396 struct ieee80211_hdr *hdr;
Johannes Berg571ecf62007-07-27 15:43:22 +0200397 hdr = (struct ieee80211_hdr *) rx->skb->data;
398
399 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
400 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
401 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
402 rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
403 hdr->seq_ctrl)) {
Jiri Slabybadffb72007-08-28 17:01:54 -0400404 if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200405 rx->local->dot11FrameDuplicateCount++;
406 rx->sta->num_duplicates++;
407 }
Johannes Berge4c26ad2008-01-31 19:48:21 +0100408 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200409 } else
410 rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
411 }
412
Johannes Berg571ecf62007-07-27 15:43:22 +0200413 if (unlikely(rx->skb->len < 16)) {
414 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100415 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200416 }
417
Johannes Berg571ecf62007-07-27 15:43:22 +0200418 /* Drop disallowed frame classes based on STA auth/assoc state;
419 * IEEE 802.11, Chap 5.5.
420 *
421 * 80211.o does filtering only based on association state, i.e., it
422 * drops Class 3 frames from not associated stations. hostapd sends
423 * deauth/disassoc frames when needed. In addition, hostapd is
424 * responsible for filtering on both auth and assoc states.
425 */
426 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
427 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
428 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100429 rx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Johannes Berg571ecf62007-07-27 15:43:22 +0200430 (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
431 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
432 !(rx->fc & IEEE80211_FCTL_TODS) &&
433 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
Jiri Slabybadffb72007-08-28 17:01:54 -0400434 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200435 /* Drop IBSS frames and frames for other hosts
436 * silently. */
Johannes Berge4c26ad2008-01-31 19:48:21 +0100437 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200438 }
439
Johannes Berge4c26ad2008-01-31 19:48:21 +0100440 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200441 }
442
Johannes Berg9ae54c82008-01-31 19:48:20 +0100443 return RX_CONTINUE;
Johannes Berg570bd532007-07-27 15:43:22 +0200444}
445
446
Johannes Berg9ae54c82008-01-31 19:48:20 +0100447static ieee80211_rx_result
Johannes Berg1990af82007-09-26 17:53:15 +0200448ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
Johannes Berg570bd532007-07-27 15:43:22 +0200449{
450 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
Johannes Berg3017b802007-08-28 17:01:53 -0400451 int keyidx;
452 int hdrlen;
Johannes Berge4c26ad2008-01-31 19:48:21 +0100453 ieee80211_rx_result result = RX_DROP_UNUSABLE;
Johannes Bergd4e46a32007-09-14 11:10:24 -0400454 struct ieee80211_key *stakey = NULL;
Johannes Berg570bd532007-07-27 15:43:22 +0200455
Johannes Berg3017b802007-08-28 17:01:53 -0400456 /*
457 * Key selection 101
458 *
459 * There are three types of keys:
460 * - GTK (group keys)
461 * - PTK (pairwise keys)
462 * - STK (station-to-station pairwise keys)
463 *
464 * When selecting a key, we have to distinguish between multicast
465 * (including broadcast) and unicast frames, the latter can only
466 * use PTKs and STKs while the former always use GTKs. Unless, of
467 * course, actual WEP keys ("pre-RSNA") are used, then unicast
468 * frames can also use key indizes like GTKs. Hence, if we don't
469 * have a PTK/STK we check the key index for a WEP key.
470 *
Johannes Berg8dc06a12007-08-28 17:01:55 -0400471 * Note that in a regular BSS, multicast frames are sent by the
472 * AP only, associated stations unicast the frame to the AP first
473 * which then multicasts it on their behalf.
474 *
Johannes Berg3017b802007-08-28 17:01:53 -0400475 * There is also a slight problem in IBSS mode: GTKs are negotiated
476 * with each station, that is something we don't currently handle.
Johannes Berg8dc06a12007-08-28 17:01:55 -0400477 * The spec seems to expect that one negotiates the same key with
478 * every station but there's no such requirement; VLANs could be
479 * possible.
Johannes Berg3017b802007-08-28 17:01:53 -0400480 */
Johannes Berg571ecf62007-07-27 15:43:22 +0200481
Johannes Berg3017b802007-08-28 17:01:53 -0400482 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100483 return RX_CONTINUE;
Johannes Berg3017b802007-08-28 17:01:53 -0400484
485 /*
Johannes Berg1990af82007-09-26 17:53:15 +0200486 * No point in finding a key and decrypting if the frame is neither
Johannes Berg3017b802007-08-28 17:01:53 -0400487 * addressed to us nor a multicast frame.
488 */
Jiri Slabybadffb72007-08-28 17:01:54 -0400489 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100490 return RX_CONTINUE;
Johannes Berg3017b802007-08-28 17:01:53 -0400491
Johannes Bergd4e46a32007-09-14 11:10:24 -0400492 if (rx->sta)
493 stakey = rcu_dereference(rx->sta->key);
494
495 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
496 rx->key = stakey;
Johannes Berg571ecf62007-07-27 15:43:22 +0200497 } else {
Johannes Berg3017b802007-08-28 17:01:53 -0400498 /*
499 * The device doesn't give us the IV so we won't be
500 * able to look up the key. That's ok though, we
501 * don't need to decrypt the frame, we just won't
502 * be able to keep statistics accurate.
503 * Except for key threshold notifications, should
504 * we somehow allow the driver to tell us which key
505 * the hardware used if this flag is set?
506 */
Johannes Berg7848ba72007-09-14 11:10:25 -0400507 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
508 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100509 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200510
Johannes Berg3017b802007-08-28 17:01:53 -0400511 hdrlen = ieee80211_get_hdrlen(rx->fc);
Johannes Berg571ecf62007-07-27 15:43:22 +0200512
Johannes Berg3017b802007-08-28 17:01:53 -0400513 if (rx->skb->len < 8 + hdrlen)
Johannes Berge4c26ad2008-01-31 19:48:21 +0100514 return RX_DROP_UNUSABLE; /* TODO: count this? */
Johannes Berg571ecf62007-07-27 15:43:22 +0200515
Johannes Berg3017b802007-08-28 17:01:53 -0400516 /*
517 * no need to call ieee80211_wep_get_keyidx,
518 * it verifies a bunch of things we've done already
519 */
520 keyidx = rx->skb->data[hdrlen + 3] >> 6;
521
Johannes Bergd4e46a32007-09-14 11:10:24 -0400522 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
Johannes Berg3017b802007-08-28 17:01:53 -0400523
524 /*
525 * RSNA-protected unicast frames should always be sent with
526 * pairwise or station-to-station keys, but for WEP we allow
527 * using a key index as well.
528 */
Johannes Berg8f20fc22007-08-28 17:01:54 -0400529 if (rx->key && rx->key->conf.alg != ALG_WEP &&
Johannes Berg3017b802007-08-28 17:01:53 -0400530 !is_multicast_ether_addr(hdr->addr1))
531 rx->key = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +0200532 }
533
Johannes Berg3017b802007-08-28 17:01:53 -0400534 if (rx->key) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200535 rx->key->tx_rx_count++;
Johannes Berg011bfcc2007-09-17 01:29:25 -0400536 /* TODO: add threshold stuff again */
Johannes Berg1990af82007-09-26 17:53:15 +0200537 } else {
John W. Linville7f3ad892007-11-06 17:12:31 -0500538#ifdef CONFIG_MAC80211_DEBUG
Johannes Berg70f08762007-09-26 17:53:14 +0200539 if (net_ratelimit())
540 printk(KERN_DEBUG "%s: RX protected frame,"
541 " but have no key\n", rx->dev->name);
John W. Linville7f3ad892007-11-06 17:12:31 -0500542#endif /* CONFIG_MAC80211_DEBUG */
Johannes Berge4c26ad2008-01-31 19:48:21 +0100543 return RX_DROP_MONITOR;
Johannes Berg70f08762007-09-26 17:53:14 +0200544 }
545
Johannes Berg1990af82007-09-26 17:53:15 +0200546 /* Check for weak IVs if possible */
547 if (rx->sta && rx->key->conf.alg == ALG_WEP &&
548 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
549 (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
550 !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) &&
551 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
552 rx->sta->wep_weak_iv_count++;
553
Johannes Berg70f08762007-09-26 17:53:14 +0200554 switch (rx->key->conf.alg) {
555 case ALG_WEP:
Mattias Nisslere2f036d2007-10-07 16:35:31 +0200556 result = ieee80211_crypto_wep_decrypt(rx);
557 break;
Johannes Berg70f08762007-09-26 17:53:14 +0200558 case ALG_TKIP:
Mattias Nisslere2f036d2007-10-07 16:35:31 +0200559 result = ieee80211_crypto_tkip_decrypt(rx);
560 break;
Johannes Berg70f08762007-09-26 17:53:14 +0200561 case ALG_CCMP:
Mattias Nisslere2f036d2007-10-07 16:35:31 +0200562 result = ieee80211_crypto_ccmp_decrypt(rx);
563 break;
Johannes Berg70f08762007-09-26 17:53:14 +0200564 }
565
Mattias Nisslere2f036d2007-10-07 16:35:31 +0200566 /* either the frame has been decrypted or will be dropped */
567 rx->u.rx.status->flag |= RX_FLAG_DECRYPTED;
568
569 return result;
Johannes Berg70f08762007-09-26 17:53:14 +0200570}
571
Johannes Berg571ecf62007-07-27 15:43:22 +0200572static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
573{
574 struct ieee80211_sub_if_data *sdata;
Joe Perches0795af52007-10-03 17:59:30 -0700575 DECLARE_MAC_BUF(mac);
576
Johannes Berg571ecf62007-07-27 15:43:22 +0200577 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
578
579 if (sdata->bss)
580 atomic_inc(&sdata->bss->num_sta_ps);
581 sta->flags |= WLAN_STA_PS;
Johannes Berg4a9a66e2008-02-19 11:31:14 +0100582 sta->flags &= ~WLAN_STA_PSPOLL;
Johannes Berg571ecf62007-07-27 15:43:22 +0200583#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700584 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
585 dev->name, print_mac(mac, sta->addr), sta->aid);
Johannes Berg571ecf62007-07-27 15:43:22 +0200586#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
587}
588
589static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
590{
591 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
592 struct sk_buff *skb;
593 int sent = 0;
594 struct ieee80211_sub_if_data *sdata;
595 struct ieee80211_tx_packet_data *pkt_data;
Joe Perches0795af52007-10-03 17:59:30 -0700596 DECLARE_MAC_BUF(mac);
Johannes Berg571ecf62007-07-27 15:43:22 +0200597
598 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
Johannes Berg004c8722008-02-20 11:21:35 +0100599
Johannes Berg571ecf62007-07-27 15:43:22 +0200600 if (sdata->bss)
601 atomic_dec(&sdata->bss->num_sta_ps);
Johannes Berg004c8722008-02-20 11:21:35 +0100602
Johannes Berg836341a2008-02-20 02:07:21 +0100603 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_PSPOLL);
Johannes Berg004c8722008-02-20 11:21:35 +0100604
605 if (!skb_queue_empty(&sta->ps_tx_buf))
606 sta_info_clear_tim_bit(sta);
607
Johannes Berg571ecf62007-07-27 15:43:22 +0200608#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700609 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
610 dev->name, print_mac(mac, sta->addr), sta->aid);
Johannes Berg571ecf62007-07-27 15:43:22 +0200611#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Berg004c8722008-02-20 11:21:35 +0100612
Johannes Berg571ecf62007-07-27 15:43:22 +0200613 /* Send all buffered frames to the station */
614 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
615 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
616 sent++;
Jiri Slabye8bf9642007-08-28 17:01:54 -0400617 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200618 dev_queue_xmit(skb);
619 }
620 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
621 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
622 local->total_ps_buffered--;
623 sent++;
624#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700625 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
Johannes Berg571ecf62007-07-27 15:43:22 +0200626 "since STA not sleeping anymore\n", dev->name,
Joe Perches0795af52007-10-03 17:59:30 -0700627 print_mac(mac, sta->addr), sta->aid);
Johannes Berg571ecf62007-07-27 15:43:22 +0200628#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Jiri Slabye8bf9642007-08-28 17:01:54 -0400629 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200630 dev_queue_xmit(skb);
631 }
632
633 return sent;
634}
635
Johannes Berg9ae54c82008-01-31 19:48:20 +0100636static ieee80211_rx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200637ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
638{
639 struct sta_info *sta = rx->sta;
640 struct net_device *dev = rx->dev;
641 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
642
643 if (!sta)
Johannes Berg9ae54c82008-01-31 19:48:20 +0100644 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200645
646 /* Update last_rx only for IBSS packets which are for the current
647 * BSSID to avoid keeping the current IBSS network alive in cases where
648 * other STAs are using different BSSID. */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100649 if (rx->sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Ron Rindjunsky71364712007-12-25 17:00:36 +0200650 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
651 IEEE80211_IF_TYPE_IBSS);
Johannes Berg571ecf62007-07-27 15:43:22 +0200652 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
653 sta->last_rx = jiffies;
654 } else
655 if (!is_multicast_ether_addr(hdr->addr1) ||
Johannes Berg51fb61e2007-12-19 01:31:27 +0100656 rx->sdata->vif.type == IEEE80211_IF_TYPE_STA) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200657 /* Update last_rx only for unicast frames in order to prevent
658 * the Probe Request frames (the only broadcast frames from a
659 * STA in infrastructure mode) from keeping a connection alive.
660 */
661 sta->last_rx = jiffies;
662 }
663
Jiri Slabybadffb72007-08-28 17:01:54 -0400664 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100665 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200666
667 sta->rx_fragments++;
668 sta->rx_bytes += rx->skb->len;
Larry Finger6c55aa92007-08-28 17:01:55 -0400669 sta->last_rssi = rx->u.rx.status->ssi;
670 sta->last_signal = rx->u.rx.status->signal;
671 sta->last_noise = rx->u.rx.status->noise;
Johannes Berg571ecf62007-07-27 15:43:22 +0200672
673 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
674 /* Change STA power saving mode only in the end of a frame
675 * exchange sequence */
676 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
677 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
678 else if (!(sta->flags & WLAN_STA_PS) &&
679 (rx->fc & IEEE80211_FCTL_PM))
680 ap_sta_ps_start(dev, sta);
681 }
682
683 /* Drop data::nullfunc frames silently, since they are used only to
684 * control station power saving mode. */
685 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
686 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
687 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
688 /* Update counter and free packet here to avoid counting this
689 * as a dropped packed. */
690 sta->rx_packets++;
691 dev_kfree_skb(rx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100692 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200693 }
694
Johannes Berg9ae54c82008-01-31 19:48:20 +0100695 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200696} /* ieee80211_rx_h_sta_process */
697
Johannes Berg571ecf62007-07-27 15:43:22 +0200698static inline struct ieee80211_fragment_entry *
699ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
700 unsigned int frag, unsigned int seq, int rx_queue,
701 struct sk_buff **skb)
702{
703 struct ieee80211_fragment_entry *entry;
704 int idx;
705
706 idx = sdata->fragment_next;
707 entry = &sdata->fragments[sdata->fragment_next++];
708 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
709 sdata->fragment_next = 0;
710
711 if (!skb_queue_empty(&entry->skb_list)) {
712#ifdef CONFIG_MAC80211_DEBUG
713 struct ieee80211_hdr *hdr =
714 (struct ieee80211_hdr *) entry->skb_list.next->data;
Joe Perches0795af52007-10-03 17:59:30 -0700715 DECLARE_MAC_BUF(mac);
716 DECLARE_MAC_BUF(mac2);
Johannes Berg571ecf62007-07-27 15:43:22 +0200717 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
718 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
Joe Perches0795af52007-10-03 17:59:30 -0700719 "addr1=%s addr2=%s\n",
Johannes Berg571ecf62007-07-27 15:43:22 +0200720 sdata->dev->name, idx,
721 jiffies - entry->first_frag_time, entry->seq,
Joe Perches0795af52007-10-03 17:59:30 -0700722 entry->last_frag, print_mac(mac, hdr->addr1),
723 print_mac(mac2, hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +0200724#endif /* CONFIG_MAC80211_DEBUG */
725 __skb_queue_purge(&entry->skb_list);
726 }
727
728 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
729 *skb = NULL;
730 entry->first_frag_time = jiffies;
731 entry->seq = seq;
732 entry->rx_queue = rx_queue;
733 entry->last_frag = frag;
734 entry->ccmp = 0;
735 entry->extra_len = 0;
736
737 return entry;
738}
739
740static inline struct ieee80211_fragment_entry *
741ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
742 u16 fc, unsigned int frag, unsigned int seq,
743 int rx_queue, struct ieee80211_hdr *hdr)
744{
745 struct ieee80211_fragment_entry *entry;
746 int i, idx;
747
748 idx = sdata->fragment_next;
749 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
750 struct ieee80211_hdr *f_hdr;
751 u16 f_fc;
752
753 idx--;
754 if (idx < 0)
755 idx = IEEE80211_FRAGMENT_MAX - 1;
756
757 entry = &sdata->fragments[idx];
758 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
759 entry->rx_queue != rx_queue ||
760 entry->last_frag + 1 != frag)
761 continue;
762
763 f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
764 f_fc = le16_to_cpu(f_hdr->frame_control);
765
766 if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
767 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
768 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
769 continue;
770
S.Çağlar Onurab466232008-02-14 17:36:47 +0200771 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200772 __skb_queue_purge(&entry->skb_list);
773 continue;
774 }
775 return entry;
776 }
777
778 return NULL;
779}
780
Johannes Berg9ae54c82008-01-31 19:48:20 +0100781static ieee80211_rx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200782ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
783{
784 struct ieee80211_hdr *hdr;
785 u16 sc;
786 unsigned int frag, seq;
787 struct ieee80211_fragment_entry *entry;
788 struct sk_buff *skb;
Joe Perches0795af52007-10-03 17:59:30 -0700789 DECLARE_MAC_BUF(mac);
Johannes Berg571ecf62007-07-27 15:43:22 +0200790
791 hdr = (struct ieee80211_hdr *) rx->skb->data;
792 sc = le16_to_cpu(hdr->seq_ctrl);
793 frag = sc & IEEE80211_SCTL_FRAG;
794
795 if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
796 (rx->skb)->len < 24 ||
797 is_multicast_ether_addr(hdr->addr1))) {
798 /* not fragmented */
799 goto out;
800 }
801 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
802
803 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
804
805 if (frag == 0) {
806 /* This is the first fragment of a new frame. */
807 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
808 rx->u.rx.queue, &(rx->skb));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400809 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
Johannes Berg571ecf62007-07-27 15:43:22 +0200810 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
811 /* Store CCMP PN so that we can verify that the next
812 * fragment has a sequential PN value. */
813 entry->ccmp = 1;
814 memcpy(entry->last_pn,
815 rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
816 CCMP_PN_LEN);
817 }
Johannes Berg9ae54c82008-01-31 19:48:20 +0100818 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200819 }
820
821 /* This is a fragment for a frame that should already be pending in
822 * fragment cache. Add this fragment to the end of the pending entry.
823 */
824 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
825 rx->u.rx.queue, hdr);
826 if (!entry) {
827 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100828 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200829 }
830
831 /* Verify that MPDUs within one MSDU have sequential PN values.
832 * (IEEE 802.11i, 8.3.3.4.5) */
833 if (entry->ccmp) {
834 int i;
835 u8 pn[CCMP_PN_LEN], *rpn;
Johannes Berg8f20fc22007-08-28 17:01:54 -0400836 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
Johannes Berge4c26ad2008-01-31 19:48:21 +0100837 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200838 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
839 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
840 pn[i]++;
841 if (pn[i])
842 break;
843 }
844 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
845 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400846 if (net_ratelimit())
847 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
Joe Perches0795af52007-10-03 17:59:30 -0700848 "sequential A2=%s"
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400849 " PN=%02x%02x%02x%02x%02x%02x "
850 "(expected %02x%02x%02x%02x%02x%02x)\n",
Joe Perches0795af52007-10-03 17:59:30 -0700851 rx->dev->name, print_mac(mac, hdr->addr2),
Johannes Berg1a84f3f2007-08-28 17:01:52 -0400852 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
853 rpn[5], pn[0], pn[1], pn[2], pn[3],
854 pn[4], pn[5]);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100855 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200856 }
857 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
858 }
859
860 skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
861 __skb_queue_tail(&entry->skb_list, rx->skb);
862 entry->last_frag = frag;
863 entry->extra_len += rx->skb->len;
864 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
865 rx->skb = NULL;
Johannes Berg9ae54c82008-01-31 19:48:20 +0100866 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200867 }
868
869 rx->skb = __skb_dequeue(&entry->skb_list);
870 if (skb_tailroom(rx->skb) < entry->extra_len) {
871 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
872 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
873 GFP_ATOMIC))) {
874 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
875 __skb_queue_purge(&entry->skb_list);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100876 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200877 }
878 }
879 while ((skb = __skb_dequeue(&entry->skb_list))) {
880 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
881 dev_kfree_skb(skb);
882 }
883
884 /* Complete frame has been reassembled - process it now */
Jiri Slabybadffb72007-08-28 17:01:54 -0400885 rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200886
887 out:
888 if (rx->sta)
889 rx->sta->rx_packets++;
890 if (is_multicast_ether_addr(hdr->addr1))
891 rx->local->dot11MulticastReceivedFrameCount++;
892 else
893 ieee80211_led_rx(rx->local);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100894 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200895}
896
Johannes Berg9ae54c82008-01-31 19:48:20 +0100897static ieee80211_rx_result
Johannes Berg571ecf62007-07-27 15:43:22 +0200898ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
899{
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +0200900 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
Johannes Berg571ecf62007-07-27 15:43:22 +0200901 struct sk_buff *skb;
902 int no_pending_pkts;
Joe Perches0795af52007-10-03 17:59:30 -0700903 DECLARE_MAC_BUF(mac);
Johannes Berg571ecf62007-07-27 15:43:22 +0200904
905 if (likely(!rx->sta ||
906 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
907 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
Jiri Slabybadffb72007-08-28 17:01:54 -0400908 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100909 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200910
Johannes Berg51fb61e2007-12-19 01:31:27 +0100911 if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) &&
912 (sdata->vif.type != IEEE80211_IF_TYPE_VLAN))
Johannes Berge4c26ad2008-01-31 19:48:21 +0100913 return RX_DROP_UNUSABLE;
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +0200914
Johannes Berg571ecf62007-07-27 15:43:22 +0200915 skb = skb_dequeue(&rx->sta->tx_filtered);
916 if (!skb) {
917 skb = skb_dequeue(&rx->sta->ps_tx_buf);
918 if (skb)
919 rx->local->total_ps_buffered--;
920 }
921 no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
922 skb_queue_empty(&rx->sta->ps_tx_buf);
923
924 if (skb) {
925 struct ieee80211_hdr *hdr =
926 (struct ieee80211_hdr *) skb->data;
927
Johannes Berg4a9a66e2008-02-19 11:31:14 +0100928 /*
929 * Tell TX path to send one frame even though the STA may
930 * still remain is PS mode after this frame exchange.
931 */
932 rx->sta->flags |= WLAN_STA_PSPOLL;
Johannes Berg571ecf62007-07-27 15:43:22 +0200933
934#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700935 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
936 print_mac(mac, rx->sta->addr), rx->sta->aid,
Johannes Berg571ecf62007-07-27 15:43:22 +0200937 skb_queue_len(&rx->sta->ps_tx_buf));
938#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
939
940 /* Use MoreData flag to indicate whether there are more
941 * buffered frames for this STA */
Johannes Berg836341a2008-02-20 02:07:21 +0100942 if (no_pending_pkts)
Johannes Berg571ecf62007-07-27 15:43:22 +0200943 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
Johannes Berg836341a2008-02-20 02:07:21 +0100944 else
Johannes Berg571ecf62007-07-27 15:43:22 +0200945 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
946
947 dev_queue_xmit(skb);
948
Johannes Berg004c8722008-02-20 11:21:35 +0100949 if (no_pending_pkts)
950 sta_info_clear_tim_bit(rx->sta);
Johannes Berg571ecf62007-07-27 15:43:22 +0200951#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
952 } else if (!rx->u.rx.sent_ps_buffered) {
Johannes Berg004c8722008-02-20 11:21:35 +0100953 /*
954 * FIXME: This can be the result of a race condition between
955 * us expiring a frame and the station polling for it.
956 * Should we send it a null-func frame indicating we
957 * have nothing buffered for it?
958 */
Joe Perches0795af52007-10-03 17:59:30 -0700959 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
Johannes Berg571ecf62007-07-27 15:43:22 +0200960 "though there is no buffered frames for it\n",
Joe Perches0795af52007-10-03 17:59:30 -0700961 rx->dev->name, print_mac(mac, rx->sta->addr));
Johannes Berg571ecf62007-07-27 15:43:22 +0200962#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Berg571ecf62007-07-27 15:43:22 +0200963 }
964
Johannes Berg9ae54c82008-01-31 19:48:20 +0100965 /* Free PS Poll skb here instead of returning RX_DROP that would
Johannes Berg571ecf62007-07-27 15:43:22 +0200966 * count as an dropped frame. */
967 dev_kfree_skb(rx->skb);
968
Johannes Berg9ae54c82008-01-31 19:48:20 +0100969 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +0200970}
971
Johannes Berg9ae54c82008-01-31 19:48:20 +0100972static ieee80211_rx_result
Johannes Berg6e0d1142007-07-27 15:43:22 +0200973ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
974{
975 u16 fc = rx->fc;
976 u8 *data = rx->skb->data;
977 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
978
979 if (!WLAN_FC_IS_QOS_DATA(fc))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100980 return RX_CONTINUE;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200981
982 /* remove the qos control field, update frame type and meta-data */
983 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
984 hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
985 /* change frame type to non QOS */
986 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
987 hdr->frame_control = cpu_to_le16(fc);
988
Johannes Berg9ae54c82008-01-31 19:48:20 +0100989 return RX_CONTINUE;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200990}
991
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +0200992static int
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100993ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +0200994{
Johannes Berg238814f2008-01-28 17:19:37 +0100995 if (unlikely(!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED))) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200996#ifdef CONFIG_MAC80211_DEBUG
Johannes Berg238814f2008-01-28 17:19:37 +0100997 if (net_ratelimit())
998 printk(KERN_DEBUG "%s: dropped frame "
999 "(unauthorized port)\n", rx->dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +02001000#endif /* CONFIG_MAC80211_DEBUG */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001001 return -EACCES;
Johannes Berg571ecf62007-07-27 15:43:22 +02001002 }
1003
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001004 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001005}
1006
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001007static int
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001008ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001009{
Johannes Berg3017b802007-08-28 17:01:53 -04001010 /*
Johannes Berg7848ba72007-09-14 11:10:25 -04001011 * Pass through unencrypted frames if the hardware has
1012 * decrypted them already.
Johannes Berg3017b802007-08-28 17:01:53 -04001013 */
Johannes Berg7848ba72007-09-14 11:10:25 -04001014 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001015 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001016
1017 /* Drop unencrypted frames if key is set. */
1018 if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
1019 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
1020 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001021 (rx->key || rx->sdata->drop_unencrypted))) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001022 if (net_ratelimit())
1023 printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
1024 "encryption\n", rx->dev->name);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001025 return -EACCES;
Johannes Berg571ecf62007-07-27 15:43:22 +02001026 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001027 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001028}
1029
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001030static int
1031ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001032{
1033 struct net_device *dev = rx->dev;
Johannes Berg571ecf62007-07-27 15:43:22 +02001034 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
1035 u16 fc, hdrlen, ethertype;
1036 u8 *payload;
1037 u8 dst[ETH_ALEN];
1038 u8 src[ETH_ALEN];
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001039 struct sk_buff *skb = rx->skb;
Johannes Berg571ecf62007-07-27 15:43:22 +02001040 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Joe Perches0795af52007-10-03 17:59:30 -07001041 DECLARE_MAC_BUF(mac);
1042 DECLARE_MAC_BUF(mac2);
1043 DECLARE_MAC_BUF(mac3);
1044 DECLARE_MAC_BUF(mac4);
Johannes Berg571ecf62007-07-27 15:43:22 +02001045
1046 fc = rx->fc;
Johannes Berg571ecf62007-07-27 15:43:22 +02001047
1048 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001049 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001050
1051 hdrlen = ieee80211_get_hdrlen(fc);
1052
1053 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1054 * header
1055 * IEEE 802.11 address fields:
1056 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1057 * 0 0 DA SA BSSID n/a
1058 * 0 1 DA BSSID SA n/a
1059 * 1 0 BSSID SA DA n/a
1060 * 1 1 RA TA DA SA
1061 */
1062
1063 switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
1064 case IEEE80211_FCTL_TODS:
1065 /* BSSID SA DA */
1066 memcpy(dst, hdr->addr3, ETH_ALEN);
1067 memcpy(src, hdr->addr2, ETH_ALEN);
1068
Johannes Berg51fb61e2007-12-19 01:31:27 +01001069 if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_AP &&
1070 sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001071 if (net_ratelimit())
1072 printk(KERN_DEBUG "%s: dropped ToDS frame "
Joe Perches0795af52007-10-03 17:59:30 -07001073 "(BSSID=%s SA=%s DA=%s)\n",
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001074 dev->name,
Joe Perches0795af52007-10-03 17:59:30 -07001075 print_mac(mac, hdr->addr1),
1076 print_mac(mac2, hdr->addr2),
1077 print_mac(mac3, hdr->addr3));
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001078 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001079 }
1080 break;
1081 case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1082 /* RA TA DA SA */
1083 memcpy(dst, hdr->addr3, ETH_ALEN);
1084 memcpy(src, hdr->addr4, ETH_ALEN);
1085
Johannes Berg51fb61e2007-12-19 01:31:27 +01001086 if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001087 if (net_ratelimit())
1088 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
Joe Perches0795af52007-10-03 17:59:30 -07001089 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001090 rx->dev->name,
Joe Perches0795af52007-10-03 17:59:30 -07001091 print_mac(mac, hdr->addr1),
1092 print_mac(mac2, hdr->addr2),
1093 print_mac(mac3, hdr->addr3),
1094 print_mac(mac4, hdr->addr4));
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001095 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001096 }
1097 break;
1098 case IEEE80211_FCTL_FROMDS:
1099 /* DA BSSID SA */
1100 memcpy(dst, hdr->addr1, ETH_ALEN);
1101 memcpy(src, hdr->addr3, ETH_ALEN);
1102
Johannes Berg51fb61e2007-12-19 01:31:27 +01001103 if (sdata->vif.type != IEEE80211_IF_TYPE_STA ||
John W. Linvilleb3316152007-08-28 17:01:55 -04001104 (is_multicast_ether_addr(dst) &&
1105 !compare_ether_addr(src, dev->dev_addr)))
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001106 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001107 break;
1108 case 0:
1109 /* DA SA BSSID */
1110 memcpy(dst, hdr->addr1, ETH_ALEN);
1111 memcpy(src, hdr->addr2, ETH_ALEN);
1112
Johannes Berg51fb61e2007-12-19 01:31:27 +01001113 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001114 if (net_ratelimit()) {
Joe Perches0795af52007-10-03 17:59:30 -07001115 printk(KERN_DEBUG "%s: dropped IBSS frame "
1116 "(DA=%s SA=%s BSSID=%s)\n",
1117 dev->name,
1118 print_mac(mac, hdr->addr1),
1119 print_mac(mac2, hdr->addr2),
1120 print_mac(mac3, hdr->addr3));
Johannes Berg571ecf62007-07-27 15:43:22 +02001121 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001122 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001123 }
1124 break;
1125 }
1126
Johannes Berg571ecf62007-07-27 15:43:22 +02001127 if (unlikely(skb->len - hdrlen < 8)) {
1128 if (net_ratelimit()) {
1129 printk(KERN_DEBUG "%s: RX too short data frame "
1130 "payload\n", dev->name);
1131 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001132 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001133 }
1134
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001135 payload = skb->data + hdrlen;
Johannes Berg571ecf62007-07-27 15:43:22 +02001136 ethertype = (payload[6] << 8) | payload[7];
1137
1138 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1139 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1140 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1141 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1142 * replace EtherType */
1143 skb_pull(skb, hdrlen + 6);
1144 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1145 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1146 } else {
1147 struct ethhdr *ehdr;
1148 __be16 len;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001149
Johannes Berg571ecf62007-07-27 15:43:22 +02001150 skb_pull(skb, hdrlen);
1151 len = htons(skb->len);
1152 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1153 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1154 memcpy(ehdr->h_source, src, ETH_ALEN);
1155 ehdr->h_proto = len;
1156 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001157 return 0;
1158}
Johannes Berg571ecf62007-07-27 15:43:22 +02001159
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001160/*
1161 * requires that rx->skb is a frame with ethernet header
1162 */
1163static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx)
1164{
1165 static const u8 pae_group_addr[ETH_ALEN]
1166 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1167 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1168
1169 /*
1170 * Allow EAPOL frames to us/the PAE group address regardless
1171 * of whether the frame was encrypted or not.
1172 */
1173 if (ehdr->h_proto == htons(ETH_P_PAE) &&
1174 (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 ||
1175 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1176 return true;
1177
1178 if (ieee80211_802_1x_port_control(rx) ||
1179 ieee80211_drop_unencrypted(rx))
1180 return false;
1181
1182 return true;
1183}
1184
1185/*
1186 * requires that rx->skb is a frame with ethernet header
1187 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001188static void
1189ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1190{
1191 struct net_device *dev = rx->dev;
1192 struct ieee80211_local *local = rx->local;
1193 struct sk_buff *skb, *xmit_skb;
1194 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001195 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1196 struct sta_info *dsta;
Johannes Berg571ecf62007-07-27 15:43:22 +02001197
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001198 skb = rx->skb;
1199 xmit_skb = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +02001200
Johannes Berg51fb61e2007-12-19 01:31:27 +01001201 if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP ||
1202 sdata->vif.type == IEEE80211_IF_TYPE_VLAN) &&
Jiri Slabybadffb72007-08-28 17:01:54 -04001203 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001204 if (is_multicast_ether_addr(ehdr->h_dest)) {
1205 /*
1206 * send multicast frames both to higher layers in
1207 * local net stack and back to the wireless medium
1208 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001209 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1210 if (!xmit_skb && net_ratelimit())
Johannes Berg571ecf62007-07-27 15:43:22 +02001211 printk(KERN_DEBUG "%s: failed to clone "
1212 "multicast frame\n", dev->name);
1213 } else {
Johannes Berg571ecf62007-07-27 15:43:22 +02001214 dsta = sta_info_get(local, skb->data);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001215 if (dsta && dsta->dev == dev) {
1216 /*
1217 * The destination station is associated to
1218 * this AP (in this VLAN), so send the frame
1219 * directly to it and do not pass it to local
1220 * net stack.
Johannes Berg571ecf62007-07-27 15:43:22 +02001221 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001222 xmit_skb = skb;
Johannes Berg571ecf62007-07-27 15:43:22 +02001223 skb = NULL;
1224 }
1225 if (dsta)
1226 sta_info_put(dsta);
1227 }
1228 }
1229
1230 if (skb) {
1231 /* deliver to local stack */
1232 skb->protocol = eth_type_trans(skb, dev);
1233 memset(skb->cb, 0, sizeof(skb->cb));
1234 netif_rx(skb);
1235 }
1236
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001237 if (xmit_skb) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001238 /* send to wireless media */
YOSHIFUJI Hideakif831e902007-12-12 03:54:23 +09001239 xmit_skb->protocol = htons(ETH_P_802_3);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001240 skb_reset_network_header(xmit_skb);
1241 skb_reset_mac_header(xmit_skb);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001242 dev_queue_xmit(xmit_skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001243 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001244}
1245
Johannes Berg9ae54c82008-01-31 19:48:20 +01001246static ieee80211_rx_result
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001247ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1248{
1249 struct net_device *dev = rx->dev;
1250 struct ieee80211_local *local = rx->local;
1251 u16 fc, ethertype;
1252 u8 *payload;
1253 struct sk_buff *skb = rx->skb, *frame = NULL;
1254 const struct ethhdr *eth;
1255 int remaining, err;
1256 u8 dst[ETH_ALEN];
1257 u8 src[ETH_ALEN];
1258 DECLARE_MAC_BUF(mac);
1259
1260 fc = rx->fc;
1261 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001262 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001263
1264 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001265 return RX_DROP_MONITOR;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001266
Ron Rindjunsky64bd4b62007-11-29 10:35:53 +02001267 if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001268 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001269
1270 err = ieee80211_data_to_8023(rx);
1271 if (unlikely(err))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001272 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001273
1274 skb->dev = dev;
1275
1276 dev->stats.rx_packets++;
1277 dev->stats.rx_bytes += skb->len;
1278
1279 /* skip the wrapping header */
1280 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
1281 if (!eth)
Johannes Berge4c26ad2008-01-31 19:48:21 +01001282 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001283
1284 while (skb != frame) {
1285 u8 padding;
1286 __be16 len = eth->h_proto;
1287 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
1288
1289 remaining = skb->len;
1290 memcpy(dst, eth->h_dest, ETH_ALEN);
1291 memcpy(src, eth->h_source, ETH_ALEN);
1292
1293 padding = ((4 - subframe_len) & 0x3);
1294 /* the last MSDU has no padding */
1295 if (subframe_len > remaining) {
1296 printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001297 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001298 }
1299
1300 skb_pull(skb, sizeof(struct ethhdr));
1301 /* if last subframe reuse skb */
1302 if (remaining <= subframe_len + padding)
1303 frame = skb;
1304 else {
1305 frame = dev_alloc_skb(local->hw.extra_tx_headroom +
1306 subframe_len);
1307
1308 if (frame == NULL)
Johannes Berge4c26ad2008-01-31 19:48:21 +01001309 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001310
1311 skb_reserve(frame, local->hw.extra_tx_headroom +
1312 sizeof(struct ethhdr));
1313 memcpy(skb_put(frame, ntohs(len)), skb->data,
1314 ntohs(len));
1315
1316 eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
1317 padding);
1318 if (!eth) {
1319 printk(KERN_DEBUG "%s: wrong buffer size ",
1320 dev->name);
1321 dev_kfree_skb(frame);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001322 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001323 }
1324 }
1325
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001326 skb_reset_network_header(frame);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001327 frame->dev = dev;
1328 frame->priority = skb->priority;
1329 rx->skb = frame;
1330
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001331 payload = frame->data;
1332 ethertype = (payload[6] << 8) | payload[7];
1333
1334 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001335 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1336 compare_ether_addr(payload,
1337 bridge_tunnel_header) == 0)) {
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001338 /* remove RFC1042 or Bridge-Tunnel
1339 * encapsulation and replace EtherType */
1340 skb_pull(frame, 6);
1341 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1342 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1343 } else {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001344 memcpy(skb_push(frame, sizeof(__be16)),
1345 &len, sizeof(__be16));
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001346 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
1347 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
1348 }
1349
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001350 if (!ieee80211_frame_allowed(rx)) {
1351 if (skb == frame) /* last frame */
Johannes Berge4c26ad2008-01-31 19:48:21 +01001352 return RX_DROP_UNUSABLE;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001353 dev_kfree_skb(frame);
1354 continue;
1355 }
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001356
1357 ieee80211_deliver_skb(rx);
1358 }
1359
Johannes Berg9ae54c82008-01-31 19:48:20 +01001360 return RX_QUEUED;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001361}
1362
Johannes Berg9ae54c82008-01-31 19:48:20 +01001363static ieee80211_rx_result
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001364ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
1365{
1366 struct net_device *dev = rx->dev;
1367 u16 fc;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001368 int err;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001369
1370 fc = rx->fc;
1371 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001372 return RX_CONTINUE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001373
1374 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001375 return RX_DROP_MONITOR;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001376
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001377 err = ieee80211_data_to_8023(rx);
1378 if (unlikely(err))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001379 return RX_DROP_UNUSABLE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001380
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001381 if (!ieee80211_frame_allowed(rx))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001382 return RX_DROP_MONITOR;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001383
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001384 rx->skb->dev = dev;
1385
1386 dev->stats.rx_packets++;
1387 dev->stats.rx_bytes += rx->skb->len;
1388
1389 ieee80211_deliver_skb(rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02001390
Johannes Berg9ae54c82008-01-31 19:48:20 +01001391 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001392}
1393
Johannes Berg9ae54c82008-01-31 19:48:20 +01001394static ieee80211_rx_result
Ron Rindjunsky71364712007-12-25 17:00:36 +02001395ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
1396{
1397 struct ieee80211_local *local = rx->local;
1398 struct ieee80211_hw *hw = &local->hw;
1399 struct sk_buff *skb = rx->skb;
1400 struct ieee80211_bar *bar = (struct ieee80211_bar *) skb->data;
1401 struct tid_ampdu_rx *tid_agg_rx;
1402 u16 start_seq_num;
1403 u16 tid;
1404
1405 if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001406 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02001407
1408 if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) {
1409 if (!rx->sta)
Johannes Berg9ae54c82008-01-31 19:48:20 +01001410 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02001411 tid = le16_to_cpu(bar->control) >> 12;
1412 tid_agg_rx = &(rx->sta->ampdu_mlme.tid_rx[tid]);
1413 if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
Johannes Berg9ae54c82008-01-31 19:48:20 +01001414 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02001415
1416 start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
1417
1418 /* reset session timer */
1419 if (tid_agg_rx->timeout) {
1420 unsigned long expires =
1421 jiffies + (tid_agg_rx->timeout / 1000) * HZ;
1422 mod_timer(&tid_agg_rx->session_timer, expires);
1423 }
1424
1425 /* manage reordering buffer according to requested */
1426 /* sequence number */
1427 rcu_read_lock();
1428 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
1429 start_seq_num, 1);
1430 rcu_read_unlock();
Johannes Berge4c26ad2008-01-31 19:48:21 +01001431 return RX_DROP_UNUSABLE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02001432 }
1433
Johannes Berg9ae54c82008-01-31 19:48:20 +01001434 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02001435}
1436
Johannes Berg9ae54c82008-01-31 19:48:20 +01001437static ieee80211_rx_result
Johannes Berg571ecf62007-07-27 15:43:22 +02001438ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
1439{
1440 struct ieee80211_sub_if_data *sdata;
1441
Jiri Slabybadffb72007-08-28 17:01:54 -04001442 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001443 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +02001444
1445 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001446 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1447 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
Johannes Bergddd3d2b2007-09-26 17:53:20 +02001448 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
Johannes Berg571ecf62007-07-27 15:43:22 +02001449 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
Johannes Bergf9d540e2007-09-28 14:02:09 +02001450 else
Johannes Berge4c26ad2008-01-31 19:48:21 +01001451 return RX_DROP_MONITOR;
Johannes Bergf9d540e2007-09-28 14:02:09 +02001452
Johannes Berg9ae54c82008-01-31 19:48:20 +01001453 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001454}
1455
Johannes Berg571ecf62007-07-27 15:43:22 +02001456static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1457 struct ieee80211_hdr *hdr,
Johannes Berg571ecf62007-07-27 15:43:22 +02001458 struct ieee80211_txrx_data *rx)
1459{
1460 int keyidx, hdrlen;
Joe Perches0795af52007-10-03 17:59:30 -07001461 DECLARE_MAC_BUF(mac);
1462 DECLARE_MAC_BUF(mac2);
Johannes Berg571ecf62007-07-27 15:43:22 +02001463
1464 hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
1465 if (rx->skb->len >= hdrlen + 4)
1466 keyidx = rx->skb->data[hdrlen + 3] >> 6;
1467 else
1468 keyidx = -1;
1469
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001470 if (net_ratelimit())
1471 printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
Joe Perches0795af52007-10-03 17:59:30 -07001472 "failure from %s to %s keyidx=%d\n",
1473 dev->name, print_mac(mac, hdr->addr2),
1474 print_mac(mac2, hdr->addr1), keyidx);
Johannes Berg571ecf62007-07-27 15:43:22 +02001475
Johannes Berg8944b792008-01-31 19:48:26 +01001476 if (!rx->sta) {
Johannes Bergaa0daf02007-09-10 14:15:25 +02001477 /*
1478 * Some hardware seem to generate incorrect Michael MIC
1479 * reports; ignore them to avoid triggering countermeasures.
1480 */
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001481 if (net_ratelimit())
1482 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
Joe Perches0795af52007-10-03 17:59:30 -07001483 "error for unknown address %s\n",
1484 dev->name, print_mac(mac, hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001485 goto ignore;
1486 }
1487
1488 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001489 if (net_ratelimit())
1490 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
Johannes Bergaa0daf02007-09-10 14:15:25 +02001491 "error for a frame with no PROTECTED flag (src "
Joe Perches0795af52007-10-03 17:59:30 -07001492 "%s)\n", dev->name, print_mac(mac, hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001493 goto ignore;
1494 }
1495
Johannes Berg51fb61e2007-12-19 01:31:27 +01001496 if (rx->sdata->vif.type == IEEE80211_IF_TYPE_AP && keyidx) {
Johannes Bergaa0daf02007-09-10 14:15:25 +02001497 /*
1498 * APs with pairwise keys should never receive Michael MIC
1499 * errors for non-zero keyidx because these are reserved for
1500 * group keys and only the AP is sending real multicast
1501 * frames in the BSS.
1502 */
Johannes Bergeb063c12007-08-28 17:01:53 -04001503 if (net_ratelimit())
1504 printk(KERN_DEBUG "%s: ignored Michael MIC error for "
1505 "a frame with non-zero keyidx (%d)"
Joe Perches0795af52007-10-03 17:59:30 -07001506 " (src %s)\n", dev->name, keyidx,
1507 print_mac(mac, hdr->addr2));
Johannes Bergeb063c12007-08-28 17:01:53 -04001508 goto ignore;
Johannes Berg571ecf62007-07-27 15:43:22 +02001509 }
1510
1511 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
1512 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
1513 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
Johannes Berg1a84f3f2007-08-28 17:01:52 -04001514 if (net_ratelimit())
1515 printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
1516 "error for a frame that cannot be encrypted "
Joe Perches0795af52007-10-03 17:59:30 -07001517 "(fc=0x%04x) (src %s)\n",
1518 dev->name, rx->fc, print_mac(mac, hdr->addr2));
Johannes Berg571ecf62007-07-27 15:43:22 +02001519 goto ignore;
1520 }
1521
Johannes Bergeb063c12007-08-28 17:01:53 -04001522 mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02001523 ignore:
1524 dev_kfree_skb(rx->skb);
1525 rx->skb = NULL;
1526}
1527
Michael Wu3d30d942008-01-31 19:48:27 +01001528static void ieee80211_rx_cooked_monitor(struct ieee80211_txrx_data *rx)
1529{
1530 struct ieee80211_sub_if_data *sdata;
1531 struct ieee80211_local *local = rx->local;
1532 struct ieee80211_rtap_hdr {
1533 struct ieee80211_radiotap_header hdr;
1534 u8 flags;
1535 u8 rate;
1536 __le16 chan_freq;
1537 __le16 chan_flags;
1538 } __attribute__ ((packed)) *rthdr;
1539 struct sk_buff *skb = rx->skb, *skb2;
1540 struct net_device *prev_dev = NULL;
1541 struct ieee80211_rx_status *status = rx->u.rx.status;
1542
1543 if (rx->flags & IEEE80211_TXRXD_RX_CMNTR_REPORTED)
1544 goto out_free_skb;
1545
1546 if (skb_headroom(skb) < sizeof(*rthdr) &&
1547 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
1548 goto out_free_skb;
1549
1550 rthdr = (void *)skb_push(skb, sizeof(*rthdr));
1551 memset(rthdr, 0, sizeof(*rthdr));
1552 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1553 rthdr->hdr.it_present =
1554 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
1555 (1 << IEEE80211_RADIOTAP_RATE) |
1556 (1 << IEEE80211_RADIOTAP_CHANNEL));
1557
1558 rthdr->rate = rx->u.rx.rate->bitrate / 5;
1559 rthdr->chan_freq = cpu_to_le16(status->freq);
1560
1561 if (status->band == IEEE80211_BAND_5GHZ)
1562 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
1563 IEEE80211_CHAN_5GHZ);
1564 else
1565 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
1566 IEEE80211_CHAN_2GHZ);
1567
1568 skb_set_mac_header(skb, 0);
1569 skb->ip_summed = CHECKSUM_UNNECESSARY;
1570 skb->pkt_type = PACKET_OTHERHOST;
1571 skb->protocol = htons(ETH_P_802_2);
1572
1573 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1574 if (!netif_running(sdata->dev))
1575 continue;
1576
1577 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR ||
1578 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
1579 continue;
1580
1581 if (prev_dev) {
1582 skb2 = skb_clone(skb, GFP_ATOMIC);
1583 if (skb2) {
1584 skb2->dev = prev_dev;
1585 netif_rx(skb2);
1586 }
1587 }
1588
1589 prev_dev = sdata->dev;
1590 sdata->dev->stats.rx_packets++;
1591 sdata->dev->stats.rx_bytes += skb->len;
1592 }
1593
1594 if (prev_dev) {
1595 skb->dev = prev_dev;
1596 netif_rx(skb);
1597 skb = NULL;
1598 } else
1599 goto out_free_skb;
1600
1601 rx->flags |= IEEE80211_TXRXD_RX_CMNTR_REPORTED;
1602 return;
1603
1604 out_free_skb:
1605 dev_kfree_skb(skb);
1606}
1607
Johannes Berg58905292008-01-31 19:48:25 +01001608typedef ieee80211_rx_result (*ieee80211_rx_handler)(struct ieee80211_txrx_data *);
1609static ieee80211_rx_handler ieee80211_rx_handlers[] =
Johannes Berg571ecf62007-07-27 15:43:22 +02001610{
1611 ieee80211_rx_h_if_stats,
Johannes Berg571ecf62007-07-27 15:43:22 +02001612 ieee80211_rx_h_passive_scan,
1613 ieee80211_rx_h_check,
Johannes Berg4f0d18e2007-09-26 15:19:40 +02001614 ieee80211_rx_h_decrypt,
Johannes Berg70f08762007-09-26 17:53:14 +02001615 ieee80211_rx_h_sta_process,
Johannes Berg571ecf62007-07-27 15:43:22 +02001616 ieee80211_rx_h_defragment,
1617 ieee80211_rx_h_ps_poll,
1618 ieee80211_rx_h_michael_mic_verify,
1619 /* this must be after decryption - so header is counted in MPDU mic
1620 * must be before pae and data, so QOS_DATA format frames
1621 * are not passed to user space by these functions
1622 */
1623 ieee80211_rx_h_remove_qos_control,
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001624 ieee80211_rx_h_amsdu,
Johannes Berg571ecf62007-07-27 15:43:22 +02001625 ieee80211_rx_h_data,
Ron Rindjunsky71364712007-12-25 17:00:36 +02001626 ieee80211_rx_h_ctrl,
Johannes Berg571ecf62007-07-27 15:43:22 +02001627 ieee80211_rx_h_mgmt,
1628 NULL
1629};
1630
Johannes Berg8944b792008-01-31 19:48:26 +01001631static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
Johannes Berg58905292008-01-31 19:48:25 +01001632 struct ieee80211_txrx_data *rx,
Johannes Berg8944b792008-01-31 19:48:26 +01001633 struct sk_buff *skb)
Johannes Berg58905292008-01-31 19:48:25 +01001634{
1635 ieee80211_rx_handler *handler;
1636 ieee80211_rx_result res = RX_DROP_MONITOR;
1637
Johannes Berg8944b792008-01-31 19:48:26 +01001638 rx->skb = skb;
1639 rx->sdata = sdata;
1640 rx->dev = sdata->dev;
1641
Johannes Berg58905292008-01-31 19:48:25 +01001642 for (handler = ieee80211_rx_handlers; *handler != NULL; handler++) {
1643 res = (*handler)(rx);
1644
1645 switch (res) {
1646 case RX_CONTINUE:
1647 continue;
1648 case RX_DROP_UNUSABLE:
1649 case RX_DROP_MONITOR:
Johannes Berg8944b792008-01-31 19:48:26 +01001650 I802_DEBUG_INC(sdata->local->rx_handlers_drop);
1651 if (rx->sta)
1652 rx->sta->rx_dropped++;
Johannes Berg58905292008-01-31 19:48:25 +01001653 break;
1654 case RX_QUEUED:
Johannes Berg8944b792008-01-31 19:48:26 +01001655 I802_DEBUG_INC(sdata->local->rx_handlers_queued);
Johannes Berg58905292008-01-31 19:48:25 +01001656 break;
1657 }
1658 break;
1659 }
1660
1661 switch (res) {
Johannes Berg58905292008-01-31 19:48:25 +01001662 case RX_CONTINUE:
Michael Wu3d30d942008-01-31 19:48:27 +01001663 case RX_DROP_MONITOR:
1664 ieee80211_rx_cooked_monitor(rx);
1665 break;
1666 case RX_DROP_UNUSABLE:
Johannes Berg58905292008-01-31 19:48:25 +01001667 dev_kfree_skb(rx->skb);
1668 break;
1669 }
1670}
1671
Johannes Berg571ecf62007-07-27 15:43:22 +02001672/* main receive path */
1673
Johannes Berg23a24de2007-07-27 15:43:22 +02001674static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1675 u8 *bssid, struct ieee80211_txrx_data *rx,
1676 struct ieee80211_hdr *hdr)
1677{
1678 int multicast = is_multicast_ether_addr(hdr->addr1);
1679
Johannes Berg51fb61e2007-12-19 01:31:27 +01001680 switch (sdata->vif.type) {
Johannes Berg23a24de2007-07-27 15:43:22 +02001681 case IEEE80211_IF_TYPE_STA:
1682 if (!bssid)
1683 return 0;
1684 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001685 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001686 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001687 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001688 } else if (!multicast &&
1689 compare_ether_addr(sdata->dev->dev_addr,
1690 hdr->addr1) != 0) {
Johannes Berg4150c572007-09-17 01:29:23 -04001691 if (!(sdata->dev->flags & IFF_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02001692 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001693 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001694 }
1695 break;
1696 case IEEE80211_IF_TYPE_IBSS:
1697 if (!bssid)
1698 return 0;
Bruno Randolf9d9bf772008-02-18 11:21:36 +09001699 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
1700 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
1701 return 1;
1702 else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001703 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001704 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001705 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001706 } else if (!multicast &&
1707 compare_ether_addr(sdata->dev->dev_addr,
1708 hdr->addr1) != 0) {
Johannes Berg4150c572007-09-17 01:29:23 -04001709 if (!(sdata->dev->flags & IFF_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02001710 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001711 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001712 } else if (!rx->sta)
1713 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1714 bssid, hdr->addr2);
1715 break;
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02001716 case IEEE80211_IF_TYPE_VLAN:
Johannes Berg23a24de2007-07-27 15:43:22 +02001717 case IEEE80211_IF_TYPE_AP:
1718 if (!bssid) {
1719 if (compare_ether_addr(sdata->dev->dev_addr,
1720 hdr->addr1))
1721 return 0;
1722 } else if (!ieee80211_bssid_match(bssid,
1723 sdata->dev->dev_addr)) {
Jiri Slabybadffb72007-08-28 17:01:54 -04001724 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001725 return 0;
Jiri Slabybadffb72007-08-28 17:01:54 -04001726 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02001727 }
Jiri Slabybadffb72007-08-28 17:01:54 -04001728 if (sdata->dev == sdata->local->mdev &&
1729 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02001730 /* do not receive anything via
1731 * master device when not scanning */
1732 return 0;
1733 break;
1734 case IEEE80211_IF_TYPE_WDS:
1735 if (bssid ||
1736 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
1737 return 0;
1738 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1739 return 0;
1740 break;
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02001741 case IEEE80211_IF_TYPE_MNTR:
1742 /* take everything */
1743 break;
Johannes Berga2897552007-09-28 14:01:25 +02001744 case IEEE80211_IF_TYPE_INVALID:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02001745 /* should never get here */
1746 WARN_ON(1);
1747 break;
Johannes Berg23a24de2007-07-27 15:43:22 +02001748 }
1749
1750 return 1;
1751}
1752
Johannes Berg571ecf62007-07-27 15:43:22 +02001753/*
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02001754 * This is the actual Rx frames handler. as it blongs to Rx path it must
1755 * be called with rcu_read_lock protection.
Johannes Berg571ecf62007-07-27 15:43:22 +02001756 */
Ron Rindjunsky71ebb4a2008-01-21 12:39:12 +02001757static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1758 struct sk_buff *skb,
1759 struct ieee80211_rx_status *status,
Johannes Berg8318d782008-01-24 19:38:38 +01001760 u32 load,
1761 struct ieee80211_rate *rate)
Johannes Berg571ecf62007-07-27 15:43:22 +02001762{
1763 struct ieee80211_local *local = hw_to_local(hw);
1764 struct ieee80211_sub_if_data *sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02001765 struct ieee80211_hdr *hdr;
1766 struct ieee80211_txrx_data rx;
1767 u16 type;
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02001768 int prepares;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001769 struct ieee80211_sub_if_data *prev = NULL;
1770 struct sk_buff *skb_new;
1771 u8 *bssid;
Johannes Berg571ecf62007-07-27 15:43:22 +02001772
1773 hdr = (struct ieee80211_hdr *) skb->data;
1774 memset(&rx, 0, sizeof(rx));
1775 rx.skb = skb;
1776 rx.local = local;
1777
1778 rx.u.rx.status = status;
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02001779 rx.u.rx.load = load;
Johannes Berg8318d782008-01-24 19:38:38 +01001780 rx.u.rx.rate = rate;
Johannes Bergb2e77712007-09-26 15:19:39 +02001781 rx.fc = le16_to_cpu(hdr->frame_control);
Johannes Berg571ecf62007-07-27 15:43:22 +02001782 type = rx.fc & IEEE80211_FCTL_FTYPE;
Johannes Berg72abd812007-09-17 01:29:22 -04001783
Johannes Bergb2e77712007-09-26 15:19:39 +02001784 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
Johannes Berg571ecf62007-07-27 15:43:22 +02001785 local->dot11ReceivedFragmentCount++;
Johannes Berg571ecf62007-07-27 15:43:22 +02001786
Johannes Berg8944b792008-01-31 19:48:26 +01001787 rx.sta = sta_info_get(local, hdr->addr2);
1788 if (rx.sta) {
Johannes Bergb2e77712007-09-26 15:19:39 +02001789 rx.dev = rx.sta->dev;
1790 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
1791 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001792
Johannes Berg571ecf62007-07-27 15:43:22 +02001793 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
Johannes Berg8944b792008-01-31 19:48:26 +01001794 ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02001795 goto end;
1796 }
1797
Zhu Yiece8edd2007-11-22 10:53:21 +08001798 if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
Jiri Slabybadffb72007-08-28 17:01:54 -04001799 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
Johannes Berg571ecf62007-07-27 15:43:22 +02001800
Johannes Berg38f37142008-01-29 17:07:43 +01001801 ieee80211_parse_qos(&rx);
1802 ieee80211_verify_ip_alignment(&rx);
1803
Johannes Berg571ecf62007-07-27 15:43:22 +02001804 skb = rx.skb;
1805
Johannes Berg79010422007-09-18 17:29:21 -04001806 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg2a8a9a82007-08-28 17:01:52 -04001807 if (!netif_running(sdata->dev))
1808 continue;
1809
Johannes Berg51fb61e2007-12-19 01:31:27 +01001810 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR)
Johannes Bergb2e77712007-09-26 15:19:39 +02001811 continue;
1812
Johannes Berg51fb61e2007-12-19 01:31:27 +01001813 bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
Johannes Bergb2e77712007-09-26 15:19:39 +02001814 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02001815 prepares = prepare_for_handlers(sdata, bssid, &rx, hdr);
Johannes Berg23a24de2007-07-27 15:43:22 +02001816
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02001817 if (!prepares)
Johannes Berg23a24de2007-07-27 15:43:22 +02001818 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001819
Johannes Berg340e11f2007-07-27 15:43:22 +02001820 /*
1821 * frame is destined for this interface, but if it's not
1822 * also for the previous one we handle that after the
1823 * loop to avoid copying the SKB once too much
1824 */
1825
1826 if (!prev) {
1827 prev = sdata;
1828 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02001829 }
Johannes Berg340e11f2007-07-27 15:43:22 +02001830
1831 /*
1832 * frame was destined for the previous interface
1833 * so invoke RX handlers for it
1834 */
1835
1836 skb_new = skb_copy(skb, GFP_ATOMIC);
1837 if (!skb_new) {
1838 if (net_ratelimit())
1839 printk(KERN_DEBUG "%s: failed to copy "
1840 "multicast frame for %s",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001841 wiphy_name(local->hw.wiphy),
1842 prev->dev->name);
Johannes Berg340e11f2007-07-27 15:43:22 +02001843 continue;
1844 }
Helmut Schaa69f817b2007-12-21 15:16:35 +01001845 rx.fc = le16_to_cpu(hdr->frame_control);
Johannes Berg8944b792008-01-31 19:48:26 +01001846 ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001847 prev = sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02001848 }
Johannes Berg8e6f00322007-07-27 15:43:22 +02001849 if (prev) {
Helmut Schaa69f817b2007-12-21 15:16:35 +01001850 rx.fc = le16_to_cpu(hdr->frame_control);
Johannes Berg8944b792008-01-31 19:48:26 +01001851 ieee80211_invoke_rx_handlers(prev, &rx, skb);
Johannes Berg8e6f00322007-07-27 15:43:22 +02001852 } else
1853 dev_kfree_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001854
Johannes Berg8e6f00322007-07-27 15:43:22 +02001855 end:
Johannes Berg8944b792008-01-31 19:48:26 +01001856 if (rx.sta)
1857 sta_info_put(rx.sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001858}
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02001859
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001860#define SEQ_MODULO 0x1000
1861#define SEQ_MASK 0xfff
1862
1863static inline int seq_less(u16 sq1, u16 sq2)
1864{
1865 return (((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1));
1866}
1867
1868static inline u16 seq_inc(u16 sq)
1869{
1870 return ((sq + 1) & SEQ_MASK);
1871}
1872
1873static inline u16 seq_sub(u16 sq1, u16 sq2)
1874{
1875 return ((sq1 - sq2) & SEQ_MASK);
1876}
1877
1878
Ron Rindjunsky71364712007-12-25 17:00:36 +02001879/*
1880 * As it function blongs to Rx path it must be called with
1881 * the proper rcu_read_lock protection for its flow.
1882 */
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001883u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
1884 struct tid_ampdu_rx *tid_agg_rx,
1885 struct sk_buff *skb, u16 mpdu_seq_num,
1886 int bar_req)
1887{
1888 struct ieee80211_local *local = hw_to_local(hw);
1889 struct ieee80211_rx_status status;
1890 u16 head_seq_num, buf_size;
1891 int index;
1892 u32 pkt_load;
Johannes Berg8318d782008-01-24 19:38:38 +01001893 struct ieee80211_supported_band *sband;
1894 struct ieee80211_rate *rate;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001895
1896 buf_size = tid_agg_rx->buf_size;
1897 head_seq_num = tid_agg_rx->head_seq_num;
1898
1899 /* frame with out of date sequence number */
1900 if (seq_less(mpdu_seq_num, head_seq_num)) {
1901 dev_kfree_skb(skb);
1902 return 1;
1903 }
1904
1905 /* if frame sequence number exceeds our buffering window size or
1906 * block Ack Request arrived - release stored frames */
1907 if ((!seq_less(mpdu_seq_num, head_seq_num + buf_size)) || (bar_req)) {
1908 /* new head to the ordering buffer */
1909 if (bar_req)
1910 head_seq_num = mpdu_seq_num;
1911 else
1912 head_seq_num =
1913 seq_inc(seq_sub(mpdu_seq_num, buf_size));
1914 /* release stored frames up to new head to stack */
1915 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1916 index = seq_sub(tid_agg_rx->head_seq_num,
1917 tid_agg_rx->ssn)
1918 % tid_agg_rx->buf_size;
1919
1920 if (tid_agg_rx->reorder_buf[index]) {
1921 /* release the reordered frames to stack */
1922 memcpy(&status,
1923 tid_agg_rx->reorder_buf[index]->cb,
1924 sizeof(status));
Johannes Berg8318d782008-01-24 19:38:38 +01001925 sband = local->hw.wiphy->bands[status.band];
1926 rate = &sband->bitrates[status.rate_idx];
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001927 pkt_load = ieee80211_rx_load_stats(local,
1928 tid_agg_rx->reorder_buf[index],
Johannes Berg8318d782008-01-24 19:38:38 +01001929 &status, rate);
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001930 __ieee80211_rx_handle_packet(hw,
1931 tid_agg_rx->reorder_buf[index],
Johannes Berg8318d782008-01-24 19:38:38 +01001932 &status, pkt_load, rate);
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001933 tid_agg_rx->stored_mpdu_num--;
1934 tid_agg_rx->reorder_buf[index] = NULL;
1935 }
1936 tid_agg_rx->head_seq_num =
1937 seq_inc(tid_agg_rx->head_seq_num);
1938 }
1939 if (bar_req)
1940 return 1;
1941 }
1942
1943 /* now the new frame is always in the range of the reordering */
1944 /* buffer window */
1945 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn)
1946 % tid_agg_rx->buf_size;
1947 /* check if we already stored this frame */
1948 if (tid_agg_rx->reorder_buf[index]) {
1949 dev_kfree_skb(skb);
1950 return 1;
1951 }
1952
1953 /* if arrived mpdu is in the right order and nothing else stored */
1954 /* release it immediately */
1955 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1956 tid_agg_rx->stored_mpdu_num == 0) {
1957 tid_agg_rx->head_seq_num =
1958 seq_inc(tid_agg_rx->head_seq_num);
1959 return 0;
1960 }
1961
1962 /* put the frame in the reordering buffer */
1963 tid_agg_rx->reorder_buf[index] = skb;
1964 tid_agg_rx->stored_mpdu_num++;
1965 /* release the buffer until next missing frame */
1966 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
1967 % tid_agg_rx->buf_size;
1968 while (tid_agg_rx->reorder_buf[index]) {
1969 /* release the reordered frame back to stack */
1970 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
1971 sizeof(status));
Johannes Berg8318d782008-01-24 19:38:38 +01001972 sband = local->hw.wiphy->bands[status.band];
1973 rate = &sband->bitrates[status.rate_idx];
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001974 pkt_load = ieee80211_rx_load_stats(local,
1975 tid_agg_rx->reorder_buf[index],
Johannes Berg8318d782008-01-24 19:38:38 +01001976 &status, rate);
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001977 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
Johannes Berg8318d782008-01-24 19:38:38 +01001978 &status, pkt_load, rate);
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001979 tid_agg_rx->stored_mpdu_num--;
1980 tid_agg_rx->reorder_buf[index] = NULL;
1981 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
1982 index = seq_sub(tid_agg_rx->head_seq_num,
1983 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
1984 }
1985 return 1;
1986}
1987
Ron Rindjunsky71ebb4a2008-01-21 12:39:12 +02001988static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
1989 struct sk_buff *skb)
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001990{
1991 struct ieee80211_hw *hw = &local->hw;
1992 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1993 struct sta_info *sta;
1994 struct tid_ampdu_rx *tid_agg_rx;
1995 u16 fc, sc;
1996 u16 mpdu_seq_num;
1997 u8 ret = 0, *qc;
1998 int tid;
1999
2000 sta = sta_info_get(local, hdr->addr2);
2001 if (!sta)
2002 return ret;
2003
2004 fc = le16_to_cpu(hdr->frame_control);
2005
2006 /* filter the QoS data rx stream according to
2007 * STA/TID and check if this STA/TID is on aggregation */
2008 if (!WLAN_FC_IS_QOS_DATA(fc))
2009 goto end_reorder;
2010
2011 qc = skb->data + ieee80211_get_hdrlen(fc) - QOS_CONTROL_LEN;
2012 tid = qc[0] & QOS_CONTROL_TID_MASK;
2013 tid_agg_rx = &(sta->ampdu_mlme.tid_rx[tid]);
2014
2015 if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
2016 goto end_reorder;
2017
2018 /* null data frames are excluded */
Ron Rindjunsky8b6bbe72008-01-23 18:17:13 +02002019 if (unlikely(fc & IEEE80211_STYPE_NULLFUNC))
Ron Rindjunskyb5807812007-12-25 17:00:35 +02002020 goto end_reorder;
2021
2022 /* new un-ordered ampdu frame - process it */
2023
2024 /* reset session timer */
2025 if (tid_agg_rx->timeout) {
2026 unsigned long expires =
2027 jiffies + (tid_agg_rx->timeout / 1000) * HZ;
2028 mod_timer(&tid_agg_rx->session_timer, expires);
2029 }
2030
2031 /* if this mpdu is fragmented - terminate rx aggregation session */
2032 sc = le16_to_cpu(hdr->seq_ctrl);
2033 if (sc & IEEE80211_SCTL_FRAG) {
2034 ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr,
2035 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
2036 ret = 1;
2037 goto end_reorder;
2038 }
2039
2040 /* according to mpdu sequence number deal with reordering buffer */
2041 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
2042 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
2043 mpdu_seq_num, 0);
2044end_reorder:
2045 if (sta)
2046 sta_info_put(sta);
2047 return ret;
2048}
2049
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002050/*
2051 * This is the receive path handler. It is called by a low level driver when an
2052 * 802.11 MPDU is received from the hardware.
2053 */
2054void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2055 struct ieee80211_rx_status *status)
2056{
2057 struct ieee80211_local *local = hw_to_local(hw);
2058 u32 pkt_load;
Johannes Berg8318d782008-01-24 19:38:38 +01002059 struct ieee80211_rate *rate = NULL;
2060 struct ieee80211_supported_band *sband;
2061
2062 if (status->band < 0 ||
2063 status->band > IEEE80211_NUM_BANDS) {
2064 WARN_ON(1);
2065 return;
2066 }
2067
2068 sband = local->hw.wiphy->bands[status->band];
2069
2070 if (!sband ||
2071 status->rate_idx < 0 ||
2072 status->rate_idx >= sband->n_bitrates) {
2073 WARN_ON(1);
2074 return;
2075 }
2076
2077 rate = &sband->bitrates[status->rate_idx];
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002078
2079 /*
2080 * key references and virtual interfaces are protected using RCU
2081 * and this requires that we are in a read-side RCU section during
2082 * receive processing
2083 */
2084 rcu_read_lock();
2085
2086 /*
2087 * Frames with failed FCS/PLCP checksum are not returned,
2088 * all other frames are returned without radiotap header
2089 * if it was previously present.
2090 * Also, frames with less than 16 bytes are dropped.
2091 */
Johannes Berg8318d782008-01-24 19:38:38 +01002092 skb = ieee80211_rx_monitor(local, skb, status, rate);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002093 if (!skb) {
2094 rcu_read_unlock();
2095 return;
2096 }
2097
Johannes Berg8318d782008-01-24 19:38:38 +01002098 pkt_load = ieee80211_rx_load_stats(local, skb, status, rate);
Ron Rindjunskyb5807812007-12-25 17:00:35 +02002099 local->channel_use_raw += pkt_load;
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002100
Ron Rindjunskyb5807812007-12-25 17:00:35 +02002101 if (!ieee80211_rx_reorder_ampdu(local, skb))
Johannes Berg8318d782008-01-24 19:38:38 +01002102 __ieee80211_rx_handle_packet(hw, skb, status, pkt_load, rate);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002103
2104 rcu_read_unlock();
2105}
Johannes Berg571ecf62007-07-27 15:43:22 +02002106EXPORT_SYMBOL(__ieee80211_rx);
2107
2108/* This is a version of the rx handler that can be called from hard irq
2109 * context. Post the skb on the queue and schedule the tasklet */
2110void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
2111 struct ieee80211_rx_status *status)
2112{
2113 struct ieee80211_local *local = hw_to_local(hw);
2114
2115 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
2116
2117 skb->dev = local->mdev;
2118 /* copy status into skb->cb for use by tasklet */
2119 memcpy(skb->cb, status, sizeof(*status));
2120 skb->pkt_type = IEEE80211_RX_MSG;
2121 skb_queue_tail(&local->skb_queue, skb);
2122 tasklet_schedule(&local->tasklet);
2123}
2124EXPORT_SYMBOL(ieee80211_rx_irqsafe);