blob: fb123e2e081a4c51495331f4d8cad945e53c3f40 [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>
Johannes Berg84040802010-02-15 12:46:39 +02005 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg571ecf62007-07-27 15:43:22 +02006 *
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020014#include <linux/kernel.h>
15#include <linux/skbuff.h>
16#include <linux/netdevice.h>
17#include <linux/etherdevice.h>
Johannes Bergd4e46a32007-09-14 11:10:24 -040018#include <linux/rcupdate.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040019#include <linux/export.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020020#include <net/mac80211.h>
21#include <net/ieee80211_radiotap.h>
22
23#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020024#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040025#include "led.h"
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +010026#include "mesh.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020027#include "wep.h"
28#include "wpa.h"
29#include "tkip.h"
30#include "wme.h"
31
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,
Johannes Berg0869aea02009-10-28 10:03:35 +010039 struct sk_buff *skb)
Johannes Bergb2e77712007-09-26 15:19:39 +020040{
Johannes Bergb2e77712007-09-26 15:19:39 +020041 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
42 if (likely(skb->len > FCS_LEN))
Zhu Yie3cf8b3f2010-03-29 17:35:07 +080043 __pskb_trim(skb, skb->len - FCS_LEN);
Johannes Bergb2e77712007-09-26 15:19:39 +020044 else {
45 /* driver bug */
46 WARN_ON(1);
47 dev_kfree_skb(skb);
48 skb = NULL;
49 }
50 }
51
52 return skb;
53}
54
Johannes Bergf1d58c22009-06-17 13:13:00 +020055static inline int should_drop_frame(struct sk_buff *skb,
Johannes Berg0869aea02009-10-28 10:03:35 +010056 int present_fcs_len)
Johannes Bergb2e77712007-09-26 15:19:39 +020057{
Johannes Bergf1d58c22009-06-17 13:13:00 +020058 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Harvey Harrison182503a2008-06-22 16:45:29 -070059 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Bergb2e77712007-09-26 15:19:39 +020060
61 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
62 return 1;
Johannes Berg0869aea02009-10-28 10:03:35 +010063 if (unlikely(skb->len < 16 + present_fcs_len))
Johannes Bergb2e77712007-09-26 15:19:39 +020064 return 1;
Harvey Harrison87228f52008-06-11 14:21:59 -070065 if (ieee80211_is_ctl(hdr->frame_control) &&
66 !ieee80211_is_pspoll(hdr->frame_control) &&
67 !ieee80211_is_back_req(hdr->frame_control))
Johannes Bergb2e77712007-09-26 15:19:39 +020068 return 1;
69 return 0;
70}
71
Bruno Randolf601ae7f2008-05-08 19:22:43 +020072static int
73ieee80211_rx_radiotap_len(struct ieee80211_local *local,
74 struct ieee80211_rx_status *status)
75{
76 int len;
77
78 /* always present fields */
79 len = sizeof(struct ieee80211_radiotap_header) + 9;
80
Johannes Berg6ebacbb2011-02-23 15:06:08 +010081 if (status->flag & RX_FLAG_MACTIME_MPDU)
Bruno Randolf601ae7f2008-05-08 19:22:43 +020082 len += 8;
Johannes Berg7fee5372009-01-30 11:13:06 +010083 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
Bruno Randolf601ae7f2008-05-08 19:22:43 +020084 len += 1;
Bruno Randolf601ae7f2008-05-08 19:22:43 +020085
86 if (len & 1) /* padding for RX_FLAGS if necessary */
87 len++;
88
Johannes Berg6d744ba2011-01-27 14:13:17 +010089 if (status->flag & RX_FLAG_HT) /* HT info */
90 len += 3;
91
Bruno Randolf601ae7f2008-05-08 19:22:43 +020092 return len;
93}
94
Johannes Bergd1c3a372009-01-07 00:26:10 +010095/*
Bruno Randolf601ae7f2008-05-08 19:22:43 +020096 * ieee80211_add_rx_radiotap_header - add radiotap header
97 *
98 * add a radiotap header containing all the fields which the hardware provided.
99 */
100static void
101ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
102 struct sk_buff *skb,
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200103 struct ieee80211_rate *rate,
104 int rtap_len)
105{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200106 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200107 struct ieee80211_radiotap_header *rthdr;
108 unsigned char *pos;
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100109 u16 rx_flags = 0;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200110
111 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
112 memset(rthdr, 0, rtap_len);
113
114 /* radiotap header, set always present flags */
115 rthdr->it_present =
116 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200117 (1 << IEEE80211_RADIOTAP_CHANNEL) |
118 (1 << IEEE80211_RADIOTAP_ANTENNA) |
119 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
120 rthdr->it_len = cpu_to_le16(rtap_len);
121
122 pos = (unsigned char *)(rthdr+1);
123
124 /* the order of the following fields is important */
125
126 /* IEEE80211_RADIOTAP_TSFT */
Johannes Berg6ebacbb2011-02-23 15:06:08 +0100127 if (status->flag & RX_FLAG_MACTIME_MPDU) {
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100128 put_unaligned_le64(status->mactime, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200129 rthdr->it_present |=
130 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
131 pos += 8;
132 }
133
134 /* IEEE80211_RADIOTAP_FLAGS */
135 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
136 *pos |= IEEE80211_RADIOTAP_F_FCS;
Johannes Bergaae89832009-03-13 12:52:10 +0100137 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
138 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
Bruno Randolfb4f28bb2008-07-30 17:19:55 +0200139 if (status->flag & RX_FLAG_SHORTPRE)
140 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200141 pos++;
142
143 /* IEEE80211_RADIOTAP_RATE */
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100144 if (!rate || status->flag & RX_FLAG_HT) {
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200145 /*
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100146 * Without rate information don't add it. If we have,
Mohammed Shafi Shajakhan38f37be2011-02-07 10:10:04 +0530147 * MCS information is a separate field in radiotap,
Johannes Berg73b48092011-04-18 17:05:21 +0200148 * added below. The byte here is needed as padding
149 * for the channel though, so initialise it to 0.
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200150 */
151 *pos = 0;
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200152 } else {
Jouni Malinenebe6c7b2009-01-10 11:47:33 +0200153 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200154 *pos = rate->bitrate / 5;
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200155 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200156 pos++;
157
158 /* IEEE80211_RADIOTAP_CHANNEL */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100159 put_unaligned_le16(status->freq, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200160 pos += 2;
161 if (status->band == IEEE80211_BAND_5GHZ)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100162 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
163 pos);
Johannes Berg5f0b7de2009-11-16 13:58:21 +0100164 else if (status->flag & RX_FLAG_HT)
165 put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
166 pos);
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100167 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100168 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
169 pos);
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100170 else if (rate)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100171 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
172 pos);
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100173 else
174 put_unaligned_le16(IEEE80211_CHAN_2GHZ, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200175 pos += 2;
176
177 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
178 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
179 *pos = status->signal;
180 rthdr->it_present |=
181 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
182 pos++;
183 }
184
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200185 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
186
187 /* IEEE80211_RADIOTAP_ANTENNA */
188 *pos = status->antenna;
189 pos++;
190
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200191 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
192
193 /* IEEE80211_RADIOTAP_RX_FLAGS */
194 /* ensure 2 byte alignment for the 2 byte field as required */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100195 if ((pos - (u8 *)rthdr) & 1)
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200196 pos++;
Johannes Bergaae89832009-03-13 12:52:10 +0100197 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100198 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
199 put_unaligned_le16(rx_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200200 pos += 2;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100201
202 if (status->flag & RX_FLAG_HT) {
203 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
204 *pos++ = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
205 IEEE80211_RADIOTAP_MCS_HAVE_GI |
206 IEEE80211_RADIOTAP_MCS_HAVE_BW;
207 *pos = 0;
208 if (status->flag & RX_FLAG_SHORT_GI)
209 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
210 if (status->flag & RX_FLAG_40MHZ)
211 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
212 pos++;
213 *pos++ = status->rate_idx;
214 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200215}
216
Johannes Bergb2e77712007-09-26 15:19:39 +0200217/*
218 * This function copies a received frame to all monitor interfaces and
219 * returns a cleaned-up SKB that no longer includes the FCS nor the
220 * radiotap header the driver might have added.
221 */
222static struct sk_buff *
223ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
Johannes Berg8318d782008-01-24 19:38:38 +0100224 struct ieee80211_rate *rate)
Johannes Bergb2e77712007-09-26 15:19:39 +0200225{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200226 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200227 struct ieee80211_sub_if_data *sdata;
Johannes Bergb2e77712007-09-26 15:19:39 +0200228 int needed_headroom = 0;
Johannes Bergb2e77712007-09-26 15:19:39 +0200229 struct sk_buff *skb, *skb2;
230 struct net_device *prev_dev = NULL;
231 int present_fcs_len = 0;
Johannes Bergb2e77712007-09-26 15:19:39 +0200232
233 /*
234 * First, we may need to make a copy of the skb because
235 * (1) we need to modify it for radiotap (if not present), and
236 * (2) the other RX handlers will modify the skb we got.
237 *
238 * We don't need to, of course, if we aren't going to return
239 * the SKB because it has a bad FCS/PLCP checksum.
240 */
Johannes Berg0869aea02009-10-28 10:03:35 +0100241
242 /* room for the radiotap header based on driver features */
243 needed_headroom = ieee80211_rx_radiotap_len(local, status);
Johannes Bergb2e77712007-09-26 15:19:39 +0200244
245 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
246 present_fcs_len = FCS_LEN;
247
Zhu Yie3cf8b3f2010-03-29 17:35:07 +0800248 /* make sure hdr->frame_control is on the linear part */
249 if (!pskb_may_pull(origskb, 2)) {
250 dev_kfree_skb(origskb);
251 return NULL;
252 }
253
Johannes Bergb2e77712007-09-26 15:19:39 +0200254 if (!local->monitors) {
Johannes Berg0869aea02009-10-28 10:03:35 +0100255 if (should_drop_frame(origskb, present_fcs_len)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200256 dev_kfree_skb(origskb);
257 return NULL;
258 }
259
Johannes Berg0869aea02009-10-28 10:03:35 +0100260 return remove_monitor_info(local, origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200261 }
262
Johannes Berg0869aea02009-10-28 10:03:35 +0100263 if (should_drop_frame(origskb, present_fcs_len)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200264 /* only need to expand headroom if necessary */
265 skb = origskb;
266 origskb = NULL;
267
268 /*
269 * This shouldn't trigger often because most devices have an
270 * RX header they pull before we get here, and that should
271 * be big enough for our radiotap information. We should
272 * probably export the length to drivers so that we can have
273 * them allocate enough headroom to start with.
274 */
275 if (skb_headroom(skb) < needed_headroom &&
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100276 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200277 dev_kfree_skb(skb);
278 return NULL;
279 }
280 } else {
281 /*
282 * Need to make a copy and possibly remove radiotap header
283 * and FCS from the original.
284 */
285 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
286
Johannes Berg0869aea02009-10-28 10:03:35 +0100287 origskb = remove_monitor_info(local, origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200288
289 if (!skb)
290 return origskb;
291 }
292
Johannes Berg0869aea02009-10-28 10:03:35 +0100293 /* prepend radiotap information */
294 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
Johannes Bergb2e77712007-09-26 15:19:39 +0200295
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100296 skb_reset_mac_header(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200297 skb->ip_summed = CHECKSUM_UNNECESSARY;
298 skb->pkt_type = PACKET_OTHERHOST;
299 skb->protocol = htons(ETH_P_802_2);
300
301 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200302 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
Johannes Bergb2e77712007-09-26 15:19:39 +0200303 continue;
304
Michael Wu3d30d942008-01-31 19:48:27 +0100305 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
306 continue;
307
Johannes Berg9607e6b662009-12-23 13:15:31 +0100308 if (!ieee80211_sdata_running(sdata))
Johannes Berg47846c92009-11-25 17:46:19 +0100309 continue;
310
Johannes Bergb2e77712007-09-26 15:19:39 +0200311 if (prev_dev) {
312 skb2 = skb_clone(skb, GFP_ATOMIC);
313 if (skb2) {
314 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400315 netif_receive_skb(skb2);
Johannes Bergb2e77712007-09-26 15:19:39 +0200316 }
317 }
318
319 prev_dev = sdata->dev;
320 sdata->dev->stats.rx_packets++;
321 sdata->dev->stats.rx_bytes += skb->len;
322 }
323
324 if (prev_dev) {
325 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400326 netif_receive_skb(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200327 } else
328 dev_kfree_skb(skb);
329
330 return origskb;
331}
332
333
Johannes Berg5cf121c2008-02-25 16:27:43 +0100334static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +0200335{
Harvey Harrison238f74a2008-07-02 11:05:34 -0700336 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200337 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg9e262972011-07-07 18:45:03 +0200338 int tid, seqno_idx, security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200339
340 /* does the frame have a qos control field? */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700341 if (ieee80211_is_data_qos(hdr->frame_control)) {
342 u8 *qc = ieee80211_get_qos_ctl(hdr);
Johannes Berg6e0d1142007-07-27 15:43:22 +0200343 /* frame has qos control */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700344 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
Johannes Berg04b7dcf2011-06-22 10:06:59 +0200345 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
Johannes Berg554891e2010-09-24 12:38:25 +0200346 status->rx_flags |= IEEE80211_RX_AMSDU;
Johannes Berg9e262972011-07-07 18:45:03 +0200347
348 seqno_idx = tid;
349 security_idx = tid;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200350 } else {
Johannes Berg1411f9b2008-07-10 10:11:02 +0200351 /*
352 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
353 *
354 * Sequence numbers for management frames, QoS data
355 * frames with a broadcast/multicast address in the
356 * Address 1 field, and all non-QoS data frames sent
357 * by QoS STAs are assigned using an additional single
358 * modulo-4096 counter, [...]
359 *
360 * We also use that counter for non-QoS STAs.
361 */
Johannes Berg9e262972011-07-07 18:45:03 +0200362 seqno_idx = NUM_RX_DATA_QUEUES;
363 security_idx = 0;
364 if (ieee80211_is_mgmt(hdr->frame_control))
365 security_idx = NUM_RX_DATA_QUEUES;
366 tid = 0;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200367 }
Johannes Berg52865dfd2007-07-27 15:43:22 +0200368
Johannes Berg9e262972011-07-07 18:45:03 +0200369 rx->seqno_idx = seqno_idx;
370 rx->security_idx = security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200371 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
372 * For now, set skb->priority to 0 for other cases. */
373 rx->skb->priority = (tid > 7) ? 0 : tid;
Johannes Berg38f37142008-01-29 17:07:43 +0100374}
Johannes Berg6e0d1142007-07-27 15:43:22 +0200375
Johannes Bergd1c3a372009-01-07 00:26:10 +0100376/**
377 * DOC: Packet alignment
378 *
379 * Drivers always need to pass packets that are aligned to two-byte boundaries
380 * to the stack.
381 *
382 * Additionally, should, if possible, align the payload data in a way that
383 * guarantees that the contained IP header is aligned to a four-byte
384 * boundary. In the case of regular frames, this simply means aligning the
385 * payload to a four-byte boundary (because either the IP header is directly
386 * contained, or IV/RFC1042 headers that have a length divisible by four are
Kalle Valo59d9cb02009-12-17 13:54:57 +0100387 * in front of it). If the payload data is not properly aligned and the
388 * architecture doesn't support efficient unaligned operations, mac80211
389 * will align the data.
Johannes Bergd1c3a372009-01-07 00:26:10 +0100390 *
391 * With A-MSDU frames, however, the payload data address must yield two modulo
392 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
393 * push the IP header further back to a multiple of four again. Thankfully, the
394 * specs were sane enough this time around to require padding each A-MSDU
395 * subframe to a length that is a multiple of four.
396 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300397 * Padding like Atheros hardware adds which is between the 802.11 header and
Johannes Bergd1c3a372009-01-07 00:26:10 +0100398 * the payload is not supported, the driver is required to move the 802.11
399 * header to be directly in front of the payload in that case.
400 */
401static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
Johannes Berg38f37142008-01-29 17:07:43 +0100402{
Kalle Valo59d9cb02009-12-17 13:54:57 +0100403#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
404 WARN_ONCE((unsigned long)rx->skb->data & 1,
405 "unaligned packet at 0x%p\n", rx->skb->data);
Johannes Bergd1c3a372009-01-07 00:26:10 +0100406#endif
Johannes Berg6e0d1142007-07-27 15:43:22 +0200407}
408
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +0200409
Johannes Berg571ecf62007-07-27 15:43:22 +0200410/* rx handlers */
411
Johannes Berg49461622008-06-30 15:10:45 +0200412static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100413ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +0200414{
415 struct ieee80211_local *local = rx->local;
Johannes Berg554891e2010-09-24 12:38:25 +0200416 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +0200417 struct sk_buff *skb = rx->skb;
418
Luciano Coelho79f460c2011-05-11 17:09:36 +0300419 if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
420 !local->sched_scanning))
Johannes Berg4080c7c2010-09-24 11:21:08 +0200421 return RX_CONTINUE;
422
Ben Greearb23b0252011-02-04 11:54:17 -0800423 if (test_bit(SCAN_HW_SCANNING, &local->scanning) ||
Luciano Coelho79f460c2011-05-11 17:09:36 +0300424 test_bit(SCAN_SW_SCANNING, &local->scanning) ||
425 local->sched_scanning)
Johannes Bergf1d58c22009-06-17 13:13:00 +0200426 return ieee80211_scan_rx(rx->sdata, skb);
Zhu Yiece8edd2007-11-22 10:53:21 +0800427
Johannes Berg4080c7c2010-09-24 11:21:08 +0200428 /* scanning finished during invoking of handlers */
429 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
430 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200431}
432
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200433
434static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
435{
436 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
437
438 if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
439 return 0;
440
441 return ieee80211_is_robust_mgmt_frame(hdr);
442}
443
444
445static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
446{
447 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
448
449 if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
450 return 0;
451
452 return ieee80211_is_robust_mgmt_frame(hdr);
453}
454
455
456/* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
457static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
458{
459 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
460 struct ieee80211_mmie *mmie;
461
462 if (skb->len < 24 + sizeof(*mmie) ||
463 !is_multicast_ether_addr(hdr->da))
464 return -1;
465
466 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
467 return -1; /* not a robust management frame */
468
469 mmie = (struct ieee80211_mmie *)
470 (skb->data + skb->len - sizeof(*mmie));
471 if (mmie->element_id != WLAN_EID_MMIE ||
472 mmie->length != sizeof(*mmie) - 2)
473 return -1;
474
475 return le16_to_cpu(mmie->key_id);
476}
477
478
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100479static ieee80211_rx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100480ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100481{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700482 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg47846c92009-11-25 17:46:19 +0100483 char *dev_addr = rx->sdata->vif.addr;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100484
Harvey Harrisona7767f92008-07-02 16:30:51 -0700485 if (ieee80211_is_data(hdr->frame_control)) {
Javier Cardona3c5772a2009-08-10 12:15:48 -0700486 if (is_multicast_ether_addr(hdr->addr1)) {
487 if (ieee80211_has_tods(hdr->frame_control) ||
488 !ieee80211_has_fromds(hdr->frame_control))
489 return RX_DROP_MONITOR;
490 if (memcmp(hdr->addr3, dev_addr, ETH_ALEN) == 0)
491 return RX_DROP_MONITOR;
492 } else {
493 if (!ieee80211_has_a4(hdr->frame_control))
494 return RX_DROP_MONITOR;
495 if (memcmp(hdr->addr4, dev_addr, ETH_ALEN) == 0)
496 return RX_DROP_MONITOR;
497 }
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100498 }
499
500 /* If there is not an established peer link and this is not a peer link
501 * establisment frame, beacon or probe, drop the frame.
502 */
503
Javier Cardona57cf8042011-05-13 10:45:43 -0700504 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100505 struct ieee80211_mgmt *mgmt;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100506
Harvey Harrisona7767f92008-07-02 16:30:51 -0700507 if (!ieee80211_is_mgmt(hdr->frame_control))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100508 return RX_DROP_MONITOR;
509
Harvey Harrisona7767f92008-07-02 16:30:51 -0700510 if (ieee80211_is_action(hdr->frame_control)) {
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700511 u8 category;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100512 mgmt = (struct ieee80211_mgmt *)hdr;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700513 category = mgmt->u.action.category;
514 if (category != WLAN_CATEGORY_MESH_ACTION &&
515 category != WLAN_CATEGORY_SELF_PROTECTED)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100516 return RX_DROP_MONITOR;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100517 return RX_CONTINUE;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100518 }
519
Harvey Harrisona7767f92008-07-02 16:30:51 -0700520 if (ieee80211_is_probe_req(hdr->frame_control) ||
521 ieee80211_is_probe_resp(hdr->frame_control) ||
Javier Cardona71839122011-04-07 15:08:31 -0700522 ieee80211_is_beacon(hdr->frame_control) ||
523 ieee80211_is_auth(hdr->frame_control))
Harvey Harrisona7767f92008-07-02 16:30:51 -0700524 return RX_CONTINUE;
525
526 return RX_DROP_MONITOR;
527
528 }
529
Johannes Berg902acc72008-02-23 15:17:19 +0100530 return RX_CONTINUE;
531}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100532
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100533#define SEQ_MODULO 0x1000
534#define SEQ_MASK 0xfff
535
536static inline int seq_less(u16 sq1, u16 sq2)
537{
538 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
539}
540
541static inline u16 seq_inc(u16 sq)
542{
543 return (sq + 1) & SEQ_MASK;
544}
545
546static inline u16 seq_sub(u16 sq1, u16 sq2)
547{
548 return (sq1 - sq2) & SEQ_MASK;
549}
550
551
552static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
553 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100554 int index)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100555{
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100556 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100557 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
Christian Lamparter4cfda472010-12-27 23:21:26 +0100558 struct ieee80211_rx_status *status;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100559
Johannes Bergdd318572010-11-29 11:09:16 +0100560 lockdep_assert_held(&tid_agg_rx->reorder_lock);
561
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100562 if (!skb)
563 goto no_frame;
564
Christian Lamparter071d9ac2010-08-05 01:36:36 +0200565 /* release the frame from the reorder ring buffer */
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100566 tid_agg_rx->stored_mpdu_num--;
567 tid_agg_rx->reorder_buf[index] = NULL;
Christian Lamparter4cfda472010-12-27 23:21:26 +0100568 status = IEEE80211_SKB_RXCB(skb);
569 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100570 skb_queue_tail(&local->rx_skb_queue, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100571
572no_frame:
573 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
574}
575
576static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw,
577 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100578 u16 head_seq_num)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100579{
580 int index;
581
Johannes Bergdd318572010-11-29 11:09:16 +0100582 lockdep_assert_held(&tid_agg_rx->reorder_lock);
583
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100584 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
585 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
586 tid_agg_rx->buf_size;
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100587 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100588 }
589}
590
591/*
592 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
593 * the skb was added to the buffer longer than this time ago, the earlier
594 * frames that have not yet been received are assumed to be lost and the skb
595 * can be released for processing. This may also release other skb's from the
596 * reorder buffer if there are no additional gaps between the frames.
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200597 *
598 * Callers must hold tid_agg_rx->reorder_lock.
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100599 */
600#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
601
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200602static void ieee80211_sta_reorder_release(struct ieee80211_hw *hw,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100603 struct tid_ampdu_rx *tid_agg_rx)
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200604{
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200605 int index, j;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200606
Johannes Bergdd318572010-11-29 11:09:16 +0100607 lockdep_assert_held(&tid_agg_rx->reorder_lock);
608
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200609 /* release the buffer until next missing frame */
610 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
611 tid_agg_rx->buf_size;
612 if (!tid_agg_rx->reorder_buf[index] &&
613 tid_agg_rx->stored_mpdu_num > 1) {
614 /*
615 * No buffers ready to be released, but check whether any
616 * frames in the reorder buffer have timed out.
617 */
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200618 int skipped = 1;
619 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
620 j = (j + 1) % tid_agg_rx->buf_size) {
621 if (!tid_agg_rx->reorder_buf[j]) {
622 skipped++;
623 continue;
624 }
Daniel Halperin499fe9a2011-03-24 16:01:48 -0700625 if (skipped &&
626 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200627 HT_RX_REORDER_BUF_TIMEOUT))
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200628 goto set_release_timer;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200629
630#ifdef CONFIG_MAC80211_HT_DEBUG
631 if (net_ratelimit())
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700632 wiphy_debug(hw->wiphy,
633 "release an RX reorder frame due to timeout on earlier frames\n");
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200634#endif
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100635 ieee80211_release_reorder_frame(hw, tid_agg_rx, j);
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200636
637 /*
638 * Increment the head seq# also for the skipped slots.
639 */
640 tid_agg_rx->head_seq_num =
641 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
642 skipped = 0;
643 }
644 } else while (tid_agg_rx->reorder_buf[index]) {
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100645 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200646 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
647 tid_agg_rx->buf_size;
648 }
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200649
650 if (tid_agg_rx->stored_mpdu_num) {
651 j = index = seq_sub(tid_agg_rx->head_seq_num,
652 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
653
654 for (; j != (index - 1) % tid_agg_rx->buf_size;
655 j = (j + 1) % tid_agg_rx->buf_size) {
656 if (tid_agg_rx->reorder_buf[j])
657 break;
658 }
659
660 set_release_timer:
661
662 mod_timer(&tid_agg_rx->reorder_timer,
Christian Lamparter334df732011-04-24 20:41:16 +0200663 tid_agg_rx->reorder_time[j] + 1 +
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200664 HT_RX_REORDER_BUF_TIMEOUT);
665 } else {
666 del_timer(&tid_agg_rx->reorder_timer);
667 }
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200668}
669
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100670/*
671 * As this function belongs to the RX path it must be under
672 * rcu_read_lock protection. It returns false if the frame
673 * can be processed immediately, true if it was consumed.
674 */
675static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
676 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100677 struct sk_buff *skb)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100678{
679 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
680 u16 sc = le16_to_cpu(hdr->seq_ctrl);
681 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
682 u16 head_seq_num, buf_size;
683 int index;
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200684 bool ret = true;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100685
Johannes Bergdd318572010-11-29 11:09:16 +0100686 spin_lock(&tid_agg_rx->reorder_lock);
687
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100688 buf_size = tid_agg_rx->buf_size;
689 head_seq_num = tid_agg_rx->head_seq_num;
690
691 /* frame with out of date sequence number */
692 if (seq_less(mpdu_seq_num, head_seq_num)) {
693 dev_kfree_skb(skb);
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200694 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100695 }
696
697 /*
698 * If frame the sequence number exceeds our buffering window
699 * size release some previous frames to make room for this one.
700 */
701 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
702 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
703 /* release stored frames up to new head to stack */
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100704 ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100705 }
706
707 /* Now the new frame is always in the range of the reordering buffer */
708
709 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
710
711 /* check if we already stored this frame */
712 if (tid_agg_rx->reorder_buf[index]) {
713 dev_kfree_skb(skb);
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200714 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100715 }
716
717 /*
718 * If the current MPDU is in the right order and nothing else
719 * is stored we can process it directly, no need to buffer it.
Johannes Bergc835b212011-03-15 23:17:01 +0100720 * If it is first but there's something stored, we may be able
721 * to release frames after this one.
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100722 */
723 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
724 tid_agg_rx->stored_mpdu_num == 0) {
725 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200726 ret = false;
727 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100728 }
729
730 /* put the frame in the reordering buffer */
731 tid_agg_rx->reorder_buf[index] = skb;
732 tid_agg_rx->reorder_time[index] = jiffies;
733 tid_agg_rx->stored_mpdu_num++;
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100734 ieee80211_sta_reorder_release(hw, tid_agg_rx);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100735
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +0200736 out:
737 spin_unlock(&tid_agg_rx->reorder_lock);
738 return ret;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100739}
740
741/*
742 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
743 * true if the MPDU was buffered, false if it should be processed.
744 */
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100745static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100746{
Johannes Berg2569a822009-11-25 17:46:17 +0100747 struct sk_buff *skb = rx->skb;
748 struct ieee80211_local *local = rx->local;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100749 struct ieee80211_hw *hw = &local->hw;
750 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Johannes Berg2569a822009-11-25 17:46:17 +0100751 struct sta_info *sta = rx->sta;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100752 struct tid_ampdu_rx *tid_agg_rx;
753 u16 sc;
754 int tid;
755
756 if (!ieee80211_is_data_qos(hdr->frame_control))
Johannes Berg2569a822009-11-25 17:46:17 +0100757 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100758
759 /*
760 * filter the QoS data rx stream according to
761 * STA/TID and check if this STA/TID is on aggregation
762 */
763
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100764 if (!sta)
Johannes Berg2569a822009-11-25 17:46:17 +0100765 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100766
767 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
768
Johannes Berga87f7362010-06-10 10:21:38 +0200769 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
770 if (!tid_agg_rx)
771 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100772
773 /* qos null data frames are excluded */
774 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
Johannes Berga87f7362010-06-10 10:21:38 +0200775 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100776
777 /* new, potentially un-ordered, ampdu frame - process it */
778
779 /* reset session timer */
780 if (tid_agg_rx->timeout)
781 mod_timer(&tid_agg_rx->session_timer,
782 TU_TO_EXP_TIME(tid_agg_rx->timeout));
783
784 /* if this mpdu is fragmented - terminate rx aggregation session */
785 sc = le16_to_cpu(hdr->seq_ctrl);
786 if (sc & IEEE80211_SCTL_FRAG) {
Johannes Bergc1475ca2010-06-10 10:21:37 +0200787 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg344eec62010-06-10 10:21:36 +0200788 skb_queue_tail(&rx->sdata->skb_queue, skb);
789 ieee80211_queue_work(&local->hw, &rx->sdata->work);
Johannes Berg2569a822009-11-25 17:46:17 +0100790 return;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100791 }
792
Johannes Berga87f7362010-06-10 10:21:38 +0200793 /*
794 * No locking needed -- we will only ever process one
795 * RX packet at a time, and thus own tid_agg_rx. All
796 * other code manipulating it needs to (and does) make
797 * sure that we cannot get to it any more before doing
798 * anything with it.
799 */
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100800 if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb))
Johannes Berg2569a822009-11-25 17:46:17 +0100801 return;
802
803 dont_reorder:
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100804 skb_queue_tail(&local->rx_skb_queue, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100805}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100806
Johannes Berg49461622008-06-30 15:10:45 +0200807static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100808ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +0200809{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700810 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200811 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +0200812
813 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
814 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
Harvey Harrisona7767f92008-07-02 16:30:51 -0700815 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
Johannes Berg9e262972011-07-07 18:45:03 +0200816 rx->sta->last_seq_ctrl[rx->seqno_idx] ==
Johannes Berg571ecf62007-07-27 15:43:22 +0200817 hdr->seq_ctrl)) {
Johannes Berg554891e2010-09-24 12:38:25 +0200818 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200819 rx->local->dot11FrameDuplicateCount++;
820 rx->sta->num_duplicates++;
821 }
Felix Fietkaub1f93312011-02-04 19:20:08 +0100822 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200823 } else
Johannes Berg9e262972011-07-07 18:45:03 +0200824 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
Johannes Berg571ecf62007-07-27 15:43:22 +0200825 }
826
Johannes Berg571ecf62007-07-27 15:43:22 +0200827 if (unlikely(rx->skb->len < 16)) {
828 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100829 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200830 }
831
Johannes Berg571ecf62007-07-27 15:43:22 +0200832 /* Drop disallowed frame classes based on STA auth/assoc state;
833 * IEEE 802.11, Chap 5.5.
834 *
Johannes Bergccd7b362008-09-11 00:01:56 +0200835 * mac80211 filters only based on association state, i.e. it drops
836 * Class 3 frames from not associated stations. hostapd sends
Johannes Berg571ecf62007-07-27 15:43:22 +0200837 * deauth/disassoc frames when needed. In addition, hostapd is
838 * responsible for filtering on both auth and assoc states.
839 */
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100840
Johannes Berg902acc72008-02-23 15:17:19 +0100841 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100842 return ieee80211_rx_mesh_check(rx);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100843
Harvey Harrisona7767f92008-07-02 16:30:51 -0700844 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
845 ieee80211_is_pspoll(hdr->frame_control)) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200846 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Bill Jordan1be7fe82010-10-01 11:20:41 -0400847 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200848 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
Guy Eilam2a33bee2011-08-17 15:18:15 +0300849 if (rx->sta && rx->sta->dummy &&
850 ieee80211_is_data_present(hdr->frame_control)) {
851 u16 ethertype;
852 u8 *payload;
853
854 payload = rx->skb->data +
855 ieee80211_hdrlen(hdr->frame_control);
856 ethertype = (payload[6] << 8) | payload[7];
857 if (cpu_to_be16(ethertype) ==
858 rx->sdata->control_port_protocol)
859 return RX_CONTINUE;
860 }
Johannes Berge4c26ad2008-01-31 19:48:21 +0100861 return RX_DROP_MONITOR;
Guy Eilam2a33bee2011-08-17 15:18:15 +0300862 }
Johannes Berg571ecf62007-07-27 15:43:22 +0200863
Johannes Berg9ae54c82008-01-31 19:48:20 +0100864 return RX_CONTINUE;
Johannes Berg570bd532007-07-27 15:43:22 +0200865}
866
867
Johannes Berg49461622008-06-30 15:10:45 +0200868static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100869ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
Johannes Berg570bd532007-07-27 15:43:22 +0200870{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +0100871 struct sk_buff *skb = rx->skb;
872 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
873 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg3017b802007-08-28 17:01:53 -0400874 int keyidx;
875 int hdrlen;
Johannes Berge4c26ad2008-01-31 19:48:21 +0100876 ieee80211_rx_result result = RX_DROP_UNUSABLE;
Johannes Berge31b8212010-10-05 19:39:30 +0200877 struct ieee80211_key *sta_ptk = NULL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200878 int mmie_keyidx = -1;
Johannes Berg761ab472010-05-28 14:24:19 +0200879 __le16 fc;
Johannes Berg570bd532007-07-27 15:43:22 +0200880
Johannes Berg3017b802007-08-28 17:01:53 -0400881 /*
882 * Key selection 101
883 *
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200884 * There are four types of keys:
Johannes Berg3017b802007-08-28 17:01:53 -0400885 * - GTK (group keys)
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200886 * - IGTK (group keys for management frames)
Johannes Berg3017b802007-08-28 17:01:53 -0400887 * - PTK (pairwise keys)
888 * - STK (station-to-station pairwise keys)
889 *
890 * When selecting a key, we have to distinguish between multicast
891 * (including broadcast) and unicast frames, the latter can only
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200892 * use PTKs and STKs while the former always use GTKs and IGTKs.
893 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
894 * unicast frames can also use key indices like GTKs. Hence, if we
895 * don't have a PTK/STK we check the key index for a WEP key.
Johannes Berg3017b802007-08-28 17:01:53 -0400896 *
Johannes Berg8dc06a12007-08-28 17:01:55 -0400897 * Note that in a regular BSS, multicast frames are sent by the
898 * AP only, associated stations unicast the frame to the AP first
899 * which then multicasts it on their behalf.
900 *
Johannes Berg3017b802007-08-28 17:01:53 -0400901 * There is also a slight problem in IBSS mode: GTKs are negotiated
902 * with each station, that is something we don't currently handle.
Johannes Berg8dc06a12007-08-28 17:01:55 -0400903 * The spec seems to expect that one negotiates the same key with
904 * every station but there's no such requirement; VLANs could be
905 * possible.
Johannes Berg3017b802007-08-28 17:01:53 -0400906 */
Johannes Berg571ecf62007-07-27 15:43:22 +0200907
Johannes Berg3017b802007-08-28 17:01:53 -0400908 /*
Johannes Berg1990af82007-09-26 17:53:15 +0200909 * No point in finding a key and decrypting if the frame is neither
Johannes Berg3017b802007-08-28 17:01:53 -0400910 * addressed to us nor a multicast frame.
911 */
Johannes Berg554891e2010-09-24 12:38:25 +0200912 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100913 return RX_CONTINUE;
Johannes Berg3017b802007-08-28 17:01:53 -0400914
Johannes Berg2569a822009-11-25 17:46:17 +0100915 /* start without a key */
916 rx->key = NULL;
917
Johannes Bergd4e46a32007-09-14 11:10:24 -0400918 if (rx->sta)
Johannes Berge31b8212010-10-05 19:39:30 +0200919 sta_ptk = rcu_dereference(rx->sta->ptk);
Johannes Bergd4e46a32007-09-14 11:10:24 -0400920
Johannes Berg761ab472010-05-28 14:24:19 +0200921 fc = hdr->frame_control;
922
923 if (!ieee80211_has_protected(fc))
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300924 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
925
Johannes Berge31b8212010-10-05 19:39:30 +0200926 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
927 rx->key = sta_ptk;
Johannes Bergdc1580d2010-08-10 09:46:40 +0200928 if ((status->flag & RX_FLAG_DECRYPTED) &&
929 (status->flag & RX_FLAG_IV_STRIPPED))
930 return RX_CONTINUE;
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300931 /* Skip decryption if the frame is not protected. */
Johannes Berg761ab472010-05-28 14:24:19 +0200932 if (!ieee80211_has_protected(fc))
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300933 return RX_CONTINUE;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200934 } else if (mmie_keyidx >= 0) {
935 /* Broadcast/multicast robust management frame / BIP */
Johannes Bergeb9fb5b82009-11-16 13:58:20 +0100936 if ((status->flag & RX_FLAG_DECRYPTED) &&
937 (status->flag & RX_FLAG_IV_STRIPPED))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200938 return RX_CONTINUE;
939
940 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
941 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
942 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
Johannes Berge31b8212010-10-05 19:39:30 +0200943 if (rx->sta)
944 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
945 if (!rx->key)
946 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
Johannes Berg761ab472010-05-28 14:24:19 +0200947 } else if (!ieee80211_has_protected(fc)) {
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300948 /*
949 * The frame was not protected, so skip decryption. However, we
950 * need to set rx->key if there is a key that could have been
951 * used so that the frame may be dropped if encryption would
952 * have been expected.
953 */
954 struct ieee80211_key *key = NULL;
Johannes Berg897bed82010-12-09 19:49:00 +0100955 struct ieee80211_sub_if_data *sdata = rx->sdata;
956 int i;
957
Johannes Berg761ab472010-05-28 14:24:19 +0200958 if (ieee80211_is_mgmt(fc) &&
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300959 is_multicast_ether_addr(hdr->addr1) &&
960 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
961 rx->key = key;
Johannes Berg897bed82010-12-09 19:49:00 +0100962 else {
963 if (rx->sta) {
964 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
965 key = rcu_dereference(rx->sta->gtk[i]);
966 if (key)
967 break;
968 }
969 }
970 if (!key) {
971 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
972 key = rcu_dereference(sdata->keys[i]);
973 if (key)
974 break;
975 }
976 }
977 if (key)
978 rx->key = key;
979 }
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300980 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200981 } else {
Zhu Yi39184b12010-04-08 15:35:10 +0800982 u8 keyid;
Johannes Berg3017b802007-08-28 17:01:53 -0400983 /*
984 * The device doesn't give us the IV so we won't be
985 * able to look up the key. That's ok though, we
986 * don't need to decrypt the frame, we just won't
987 * be able to keep statistics accurate.
988 * Except for key threshold notifications, should
989 * we somehow allow the driver to tell us which key
990 * the hardware used if this flag is set?
991 */
Johannes Bergeb9fb5b82009-11-16 13:58:20 +0100992 if ((status->flag & RX_FLAG_DECRYPTED) &&
993 (status->flag & RX_FLAG_IV_STRIPPED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100994 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200995
Johannes Berg761ab472010-05-28 14:24:19 +0200996 hdrlen = ieee80211_hdrlen(fc);
Johannes Berg571ecf62007-07-27 15:43:22 +0200997
Johannes Berg3017b802007-08-28 17:01:53 -0400998 if (rx->skb->len < 8 + hdrlen)
Johannes Berge4c26ad2008-01-31 19:48:21 +0100999 return RX_DROP_UNUSABLE; /* TODO: count this? */
Johannes Berg571ecf62007-07-27 15:43:22 +02001000
Johannes Berg3017b802007-08-28 17:01:53 -04001001 /*
1002 * no need to call ieee80211_wep_get_keyidx,
1003 * it verifies a bunch of things we've done already
1004 */
Zhu Yi39184b12010-04-08 15:35:10 +08001005 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1006 keyidx = keyid >> 6;
Johannes Berg3017b802007-08-28 17:01:53 -04001007
Johannes Berge31b8212010-10-05 19:39:30 +02001008 /* check per-station GTK first, if multicast packet */
1009 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1010 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
Johannes Berg3017b802007-08-28 17:01:53 -04001011
Johannes Berge31b8212010-10-05 19:39:30 +02001012 /* if not found, try default key */
1013 if (!rx->key) {
1014 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1015
1016 /*
1017 * RSNA-protected unicast frames should always be
1018 * sent with pairwise or station-to-station keys,
1019 * but for WEP we allow using a key index as well.
1020 */
1021 if (rx->key &&
1022 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1023 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1024 !is_multicast_ether_addr(hdr->addr1))
1025 rx->key = NULL;
1026 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001027 }
1028
Johannes Berg3017b802007-08-28 17:01:53 -04001029 if (rx->key) {
Johannes Berg95acac62011-07-12 12:30:59 +02001030 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1031 return RX_DROP_MONITOR;
1032
Johannes Berg571ecf62007-07-27 15:43:22 +02001033 rx->key->tx_rx_count++;
Johannes Berg011bfcc2007-09-17 01:29:25 -04001034 /* TODO: add threshold stuff again */
Johannes Berg1990af82007-09-26 17:53:15 +02001035 } else {
Johannes Berge4c26ad2008-01-31 19:48:21 +01001036 return RX_DROP_MONITOR;
Johannes Berg70f08762007-09-26 17:53:14 +02001037 }
1038
Zhu Yi39184b12010-04-08 15:35:10 +08001039 if (skb_linearize(rx->skb))
1040 return RX_DROP_UNUSABLE;
Johannes Berg761ab472010-05-28 14:24:19 +02001041 /* the hdr variable is invalid now! */
Johannes Berg1990af82007-09-26 17:53:15 +02001042
Johannes Berg97359d12010-08-10 09:46:38 +02001043 switch (rx->key->conf.cipher) {
1044 case WLAN_CIPHER_SUITE_WEP40:
1045 case WLAN_CIPHER_SUITE_WEP104:
Johannes Berg761ab472010-05-28 14:24:19 +02001046 /* Check for weak IVs if possible */
1047 if (rx->sta && ieee80211_is_data(fc) &&
1048 (!(status->flag & RX_FLAG_IV_STRIPPED) ||
1049 !(status->flag & RX_FLAG_DECRYPTED)) &&
1050 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
1051 rx->sta->wep_weak_iv_count++;
1052
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001053 result = ieee80211_crypto_wep_decrypt(rx);
1054 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001055 case WLAN_CIPHER_SUITE_TKIP:
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001056 result = ieee80211_crypto_tkip_decrypt(rx);
1057 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001058 case WLAN_CIPHER_SUITE_CCMP:
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001059 result = ieee80211_crypto_ccmp_decrypt(rx);
1060 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001061 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001062 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1063 break;
Johannes Berg3ffc2a92010-08-27 14:26:52 +03001064 default:
1065 /*
1066 * We can reach here only with HW-only algorithms
1067 * but why didn't it decrypt the frame?!
1068 */
1069 return RX_DROP_UNUSABLE;
Johannes Berg70f08762007-09-26 17:53:14 +02001070 }
1071
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001072 /* either the frame has been decrypted or will be dropped */
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001073 status->flag |= RX_FLAG_DECRYPTED;
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001074
1075 return result;
Johannes Berg70f08762007-09-26 17:53:14 +02001076}
1077
Kalle Valo572e0012009-02-10 17:09:31 +02001078static ieee80211_rx_result debug_noinline
1079ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1080{
1081 struct ieee80211_local *local;
1082 struct ieee80211_hdr *hdr;
1083 struct sk_buff *skb;
1084
1085 local = rx->local;
1086 skb = rx->skb;
1087 hdr = (struct ieee80211_hdr *) skb->data;
1088
1089 if (!local->pspolling)
1090 return RX_CONTINUE;
1091
1092 if (!ieee80211_has_fromds(hdr->frame_control))
1093 /* this is not from AP */
1094 return RX_CONTINUE;
1095
1096 if (!ieee80211_is_data(hdr->frame_control))
1097 return RX_CONTINUE;
1098
1099 if (!ieee80211_has_moredata(hdr->frame_control)) {
1100 /* AP has no more frames buffered for us */
1101 local->pspolling = false;
1102 return RX_CONTINUE;
1103 }
1104
1105 /* more data bit is set, let's request a new frame from the AP */
1106 ieee80211_send_pspoll(local, rx->sdata);
1107
1108 return RX_CONTINUE;
1109}
1110
Johannes Berg133b8222008-09-16 14:18:59 +02001111static void ap_sta_ps_start(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001112{
Johannes Berg133b8222008-09-16 14:18:59 +02001113 struct ieee80211_sub_if_data *sdata = sta->sdata;
Christian Lamparter4571d3b2008-11-30 00:48:41 +01001114 struct ieee80211_local *local = sdata->local;
Joe Perches0795af52007-10-03 17:59:30 -07001115
Johannes Berg3e122be2008-07-09 14:40:34 +02001116 atomic_inc(&sdata->bss->num_sta_ps);
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001117 set_sta_flag(sta, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001118 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1119 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001120#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Johannes Berg0c68ae262008-10-27 15:56:10 -07001121 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001122 sdata->name, sta->sta.addr, sta->sta.aid);
Johannes Berg571ecf62007-07-27 15:43:22 +02001123#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1124}
1125
Johannes Bergff9458d2009-10-30 12:56:02 +01001126static void ap_sta_ps_end(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001127{
Johannes Berg133b8222008-09-16 14:18:59 +02001128 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02001129
Johannes Berg3e122be2008-07-09 14:40:34 +02001130 atomic_dec(&sdata->bss->num_sta_ps);
Johannes Berg004c8722008-02-20 11:21:35 +01001131
Johannes Berg571ecf62007-07-27 15:43:22 +02001132#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Johannes Berg0c68ae262008-10-27 15:56:10 -07001133 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001134 sdata->name, sta->sta.addr, sta->sta.aid);
Johannes Berg571ecf62007-07-27 15:43:22 +02001135#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Berg004c8722008-02-20 11:21:35 +01001136
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001137 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001138#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Johannes Bergaf818582009-11-06 11:35:50 +01001139 printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001140 sdata->name, sta->sta.addr, sta->sta.aid);
Johannes Berg571ecf62007-07-27 15:43:22 +02001141#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Bergaf818582009-11-06 11:35:50 +01001142 return;
1143 }
1144
1145 ieee80211_sta_ps_deliver_wakeup(sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001146}
1147
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001148int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1149{
1150 struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1151 bool in_ps;
1152
1153 WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
1154
1155 /* Don't let the same PS state be set twice */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001156 in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001157 if ((start && in_ps) || (!start && !in_ps))
1158 return -EINVAL;
1159
1160 if (start)
1161 ap_sta_ps_start(sta_inf);
1162 else
1163 ap_sta_ps_end(sta_inf);
1164
1165 return 0;
1166}
1167EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1168
Johannes Berg49461622008-06-30 15:10:45 +02001169static ieee80211_rx_result debug_noinline
Johannes Berg47086fc2011-09-29 16:04:33 +02001170ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1171{
1172 struct ieee80211_sub_if_data *sdata = rx->sdata;
1173 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1174 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1175 int tid, ac;
1176
1177 if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH))
1178 return RX_CONTINUE;
1179
1180 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1181 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1182 return RX_CONTINUE;
1183
1184 /*
1185 * The device handles station powersave, so don't do anything about
1186 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1187 * it to mac80211 since they're handled.)
1188 */
1189 if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
1190 return RX_CONTINUE;
1191
1192 /*
1193 * Don't do anything if the station isn't already asleep. In
1194 * the uAPSD case, the station will probably be marked asleep,
1195 * in the PS-Poll case the station must be confused ...
1196 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001197 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
Johannes Berg47086fc2011-09-29 16:04:33 +02001198 return RX_CONTINUE;
1199
1200 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001201 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1202 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
Johannes Bergdeeaee192011-09-29 16:04:35 +02001203 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1204 else
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001205 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
Johannes Bergdeeaee192011-09-29 16:04:35 +02001206 }
Johannes Berg47086fc2011-09-29 16:04:33 +02001207
1208 /* Free PS Poll skb here instead of returning RX_DROP that would
1209 * count as an dropped frame. */
1210 dev_kfree_skb(rx->skb);
1211
1212 return RX_QUEUED;
1213 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1214 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1215 ieee80211_has_pm(hdr->frame_control) &&
1216 (ieee80211_is_data_qos(hdr->frame_control) ||
1217 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1218 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1219 ac = ieee802_1d_to_ac[tid & 7];
1220
1221 /*
1222 * If this AC is not trigger-enabled do nothing.
1223 *
1224 * NB: This could/should check a separate bitmap of trigger-
1225 * enabled queues, but for now we only implement uAPSD w/o
1226 * TSPEC changes to the ACs, so they're always the same.
1227 */
1228 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1229 return RX_CONTINUE;
1230
1231 /* if we are in a service period, do nothing */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001232 if (test_sta_flag(rx->sta, WLAN_STA_SP))
Johannes Berg47086fc2011-09-29 16:04:33 +02001233 return RX_CONTINUE;
1234
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001235 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
Johannes Berg47086fc2011-09-29 16:04:33 +02001236 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1237 else
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001238 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
Johannes Berg47086fc2011-09-29 16:04:33 +02001239 }
1240
1241 return RX_CONTINUE;
1242}
1243
1244static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001245ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001246{
1247 struct sta_info *sta = rx->sta;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001248 struct sk_buff *skb = rx->skb;
1249 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1250 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001251
1252 if (!sta)
Johannes Berg9ae54c82008-01-31 19:48:20 +01001253 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001254
Johannes Bergb291ba12009-07-10 15:29:03 +02001255 /*
1256 * Update last_rx only for IBSS packets which are for the current
1257 * BSSID to avoid keeping the current IBSS network alive in cases
1258 * where other STAs start using different BSSID.
1259 */
Johannes Berg05c914f2008-09-11 00:01:58 +02001260 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Ron Rindjunsky71364712007-12-25 17:00:36 +02001261 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
Johannes Berg05c914f2008-09-11 00:01:58 +02001262 NL80211_IFTYPE_ADHOC);
Felix Fietkau3af63342011-02-27 22:08:01 +01001263 if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001264 sta->last_rx = jiffies;
Felix Fietkau3af63342011-02-27 22:08:01 +01001265 if (ieee80211_is_data(hdr->frame_control)) {
1266 sta->last_rx_rate_idx = status->rate_idx;
1267 sta->last_rx_rate_flag = status->flag;
1268 }
1269 }
Johannes Bergb291ba12009-07-10 15:29:03 +02001270 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1271 /*
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001272 * Mesh beacons will update last_rx when if they are found to
1273 * match the current local configuration when processed.
Johannes Berg571ecf62007-07-27 15:43:22 +02001274 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001275 sta->last_rx = jiffies;
Felix Fietkau3af63342011-02-27 22:08:01 +01001276 if (ieee80211_is_data(hdr->frame_control)) {
1277 sta->last_rx_rate_idx = status->rate_idx;
1278 sta->last_rx_rate_flag = status->flag;
1279 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001280 }
1281
Johannes Berg554891e2010-09-24 12:38:25 +02001282 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001283 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001284
Kalle Valo3cf335d52009-03-22 21:57:06 +02001285 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1286 ieee80211_sta_rx_notify(rx->sdata, hdr);
1287
Johannes Berg571ecf62007-07-27 15:43:22 +02001288 sta->rx_fragments++;
1289 sta->rx_bytes += rx->skb->len;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001290 sta->last_signal = status->signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +09001291 ewma_add(&sta->avg_signal, -status->signal);
Johannes Berg571ecf62007-07-27 15:43:22 +02001292
Johannes Berg72eaa432008-11-26 15:02:58 +01001293 /*
1294 * Change STA power saving mode only at the end of a frame
1295 * exchange sequence.
1296 */
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001297 if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
1298 !ieee80211_has_morefrags(hdr->frame_control) &&
Christian Lamparter4cfda472010-12-27 23:21:26 +01001299 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001300 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1301 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001302 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
Johannes Berg72eaa432008-11-26 15:02:58 +01001303 /*
1304 * Ignore doze->wake transitions that are
1305 * indicated by non-data frames, the standard
1306 * is unclear here, but for example going to
1307 * PS mode and then scanning would cause a
1308 * doze->wake transition for the probe request,
1309 * and that is clearly undesirable.
1310 */
1311 if (ieee80211_is_data(hdr->frame_control) &&
1312 !ieee80211_has_pm(hdr->frame_control))
Johannes Bergff9458d2009-10-30 12:56:02 +01001313 ap_sta_ps_end(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001314 } else {
1315 if (ieee80211_has_pm(hdr->frame_control))
1316 ap_sta_ps_start(sta);
1317 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001318 }
1319
Johannes Berg22403de2009-10-30 12:55:03 +01001320 /*
1321 * Drop (qos-)data::nullfunc frames silently, since they
1322 * are used only to control station power saving mode.
1323 */
1324 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1325 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001326 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
Felix Fietkaud5242152010-01-08 18:06:26 +01001327
1328 /*
1329 * If we receive a 4-addr nullfunc frame from a STA
1330 * that was not moved to a 4-addr STA vlan yet, drop
1331 * the frame to the monitor interface, to make sure
1332 * that hostapd sees it
1333 */
1334 if (ieee80211_has_a4(hdr->frame_control) &&
1335 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1336 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1337 !rx->sdata->u.vlan.sta)))
1338 return RX_DROP_MONITOR;
Johannes Berg22403de2009-10-30 12:55:03 +01001339 /*
1340 * Update counter and free packet here to avoid
1341 * counting this as a dropped packed.
1342 */
Johannes Berg571ecf62007-07-27 15:43:22 +02001343 sta->rx_packets++;
1344 dev_kfree_skb(rx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001345 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001346 }
1347
Johannes Berg9ae54c82008-01-31 19:48:20 +01001348 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001349} /* ieee80211_rx_h_sta_process */
1350
Johannes Berg571ecf62007-07-27 15:43:22 +02001351static inline struct ieee80211_fragment_entry *
1352ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1353 unsigned int frag, unsigned int seq, int rx_queue,
1354 struct sk_buff **skb)
1355{
1356 struct ieee80211_fragment_entry *entry;
1357 int idx;
1358
1359 idx = sdata->fragment_next;
1360 entry = &sdata->fragments[sdata->fragment_next++];
1361 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1362 sdata->fragment_next = 0;
1363
1364 if (!skb_queue_empty(&entry->skb_list)) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001365#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg571ecf62007-07-27 15:43:22 +02001366 struct ieee80211_hdr *hdr =
1367 (struct ieee80211_hdr *) entry->skb_list.next->data;
1368 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
1369 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
Johannes Berg0c68ae262008-10-27 15:56:10 -07001370 "addr1=%pM addr2=%pM\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001371 sdata->name, idx,
Johannes Berg571ecf62007-07-27 15:43:22 +02001372 jiffies - entry->first_frag_time, entry->seq,
Johannes Berg0c68ae262008-10-27 15:56:10 -07001373 entry->last_frag, hdr->addr1, hdr->addr2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001374#endif
Johannes Berg571ecf62007-07-27 15:43:22 +02001375 __skb_queue_purge(&entry->skb_list);
1376 }
1377
1378 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1379 *skb = NULL;
1380 entry->first_frag_time = jiffies;
1381 entry->seq = seq;
1382 entry->rx_queue = rx_queue;
1383 entry->last_frag = frag;
1384 entry->ccmp = 0;
1385 entry->extra_len = 0;
1386
1387 return entry;
1388}
1389
1390static inline struct ieee80211_fragment_entry *
1391ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001392 unsigned int frag, unsigned int seq,
Johannes Berg571ecf62007-07-27 15:43:22 +02001393 int rx_queue, struct ieee80211_hdr *hdr)
1394{
1395 struct ieee80211_fragment_entry *entry;
1396 int i, idx;
1397
1398 idx = sdata->fragment_next;
1399 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1400 struct ieee80211_hdr *f_hdr;
Johannes Berg571ecf62007-07-27 15:43:22 +02001401
1402 idx--;
1403 if (idx < 0)
1404 idx = IEEE80211_FRAGMENT_MAX - 1;
1405
1406 entry = &sdata->fragments[idx];
1407 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1408 entry->rx_queue != rx_queue ||
1409 entry->last_frag + 1 != frag)
1410 continue;
1411
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001412 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001413
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001414 /*
1415 * Check ftype and addresses are equal, else check next fragment
1416 */
1417 if (((hdr->frame_control ^ f_hdr->frame_control) &
1418 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
Johannes Berg571ecf62007-07-27 15:43:22 +02001419 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
1420 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
1421 continue;
1422
S.Çağlar Onurab466232008-02-14 17:36:47 +02001423 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001424 __skb_queue_purge(&entry->skb_list);
1425 continue;
1426 }
1427 return entry;
1428 }
1429
1430 return NULL;
1431}
1432
Johannes Berg49461622008-06-30 15:10:45 +02001433static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001434ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001435{
1436 struct ieee80211_hdr *hdr;
1437 u16 sc;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001438 __le16 fc;
Johannes Berg571ecf62007-07-27 15:43:22 +02001439 unsigned int frag, seq;
1440 struct ieee80211_fragment_entry *entry;
1441 struct sk_buff *skb;
Johannes Berg554891e2010-09-24 12:38:25 +02001442 struct ieee80211_rx_status *status;
Johannes Berg571ecf62007-07-27 15:43:22 +02001443
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001444 hdr = (struct ieee80211_hdr *)rx->skb->data;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001445 fc = hdr->frame_control;
Johannes Berg571ecf62007-07-27 15:43:22 +02001446 sc = le16_to_cpu(hdr->seq_ctrl);
1447 frag = sc & IEEE80211_SCTL_FRAG;
1448
Harvey Harrison358c8d92008-07-15 18:44:13 -07001449 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
Johannes Berg571ecf62007-07-27 15:43:22 +02001450 (rx->skb)->len < 24 ||
1451 is_multicast_ether_addr(hdr->addr1))) {
1452 /* not fragmented */
1453 goto out;
1454 }
1455 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1456
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08001457 if (skb_linearize(rx->skb))
1458 return RX_DROP_UNUSABLE;
1459
Abhijeet Kolekar058897a2010-05-11 11:22:11 -07001460 /*
1461 * skb_linearize() might change the skb->data and
1462 * previously cached variables (in this case, hdr) need to
1463 * be refreshed with the new data.
1464 */
1465 hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001466 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1467
1468 if (frag == 0) {
1469 /* This is the first fragment of a new frame. */
1470 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
Johannes Berg9e262972011-07-07 18:45:03 +02001471 rx->seqno_idx, &(rx->skb));
Johannes Berg97359d12010-08-10 09:46:38 +02001472 if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
Harvey Harrison358c8d92008-07-15 18:44:13 -07001473 ieee80211_has_protected(fc)) {
Johannes Berg9e262972011-07-07 18:45:03 +02001474 int queue = rx->security_idx;
Johannes Berg571ecf62007-07-27 15:43:22 +02001475 /* Store CCMP PN so that we can verify that the next
1476 * fragment has a sequential PN value. */
1477 entry->ccmp = 1;
1478 memcpy(entry->last_pn,
Jouni Malinen91902522010-06-11 10:27:33 -07001479 rx->key->u.ccmp.rx_pn[queue],
Johannes Berg571ecf62007-07-27 15:43:22 +02001480 CCMP_PN_LEN);
1481 }
Johannes Berg9ae54c82008-01-31 19:48:20 +01001482 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001483 }
1484
1485 /* This is a fragment for a frame that should already be pending in
1486 * fragment cache. Add this fragment to the end of the pending entry.
1487 */
Johannes Berg9e262972011-07-07 18:45:03 +02001488 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1489 rx->seqno_idx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02001490 if (!entry) {
1491 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001492 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +02001493 }
1494
1495 /* Verify that MPDUs within one MSDU have sequential PN values.
1496 * (IEEE 802.11i, 8.3.3.4.5) */
1497 if (entry->ccmp) {
1498 int i;
1499 u8 pn[CCMP_PN_LEN], *rpn;
Jouni Malinen91902522010-06-11 10:27:33 -07001500 int queue;
Johannes Berg97359d12010-08-10 09:46:38 +02001501 if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
Johannes Berge4c26ad2008-01-31 19:48:21 +01001502 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001503 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
1504 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
1505 pn[i]++;
1506 if (pn[i])
1507 break;
1508 }
Johannes Berg9e262972011-07-07 18:45:03 +02001509 queue = rx->security_idx;
Jouni Malinen91902522010-06-11 10:27:33 -07001510 rpn = rx->key->u.ccmp.rx_pn[queue];
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001511 if (memcmp(pn, rpn, CCMP_PN_LEN))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001512 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001513 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
1514 }
1515
Harvey Harrison358c8d92008-07-15 18:44:13 -07001516 skb_pull(rx->skb, ieee80211_hdrlen(fc));
Johannes Berg571ecf62007-07-27 15:43:22 +02001517 __skb_queue_tail(&entry->skb_list, rx->skb);
1518 entry->last_frag = frag;
1519 entry->extra_len += rx->skb->len;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001520 if (ieee80211_has_morefrags(fc)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001521 rx->skb = NULL;
Johannes Berg9ae54c82008-01-31 19:48:20 +01001522 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001523 }
1524
1525 rx->skb = __skb_dequeue(&entry->skb_list);
1526 if (skb_tailroom(rx->skb) < entry->extra_len) {
1527 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
1528 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1529 GFP_ATOMIC))) {
1530 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1531 __skb_queue_purge(&entry->skb_list);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001532 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001533 }
1534 }
1535 while ((skb = __skb_dequeue(&entry->skb_list))) {
1536 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1537 dev_kfree_skb(skb);
1538 }
1539
1540 /* Complete frame has been reassembled - process it now */
Johannes Berg554891e2010-09-24 12:38:25 +02001541 status = IEEE80211_SKB_RXCB(rx->skb);
1542 status->rx_flags |= IEEE80211_RX_FRAGMENTED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001543
1544 out:
1545 if (rx->sta)
1546 rx->sta->rx_packets++;
1547 if (is_multicast_ether_addr(hdr->addr1))
1548 rx->local->dot11MulticastReceivedFrameCount++;
1549 else
1550 ieee80211_led_rx(rx->local);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001551 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001552}
1553
Johannes Berg49461622008-06-30 15:10:45 +02001554static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001555ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +02001556{
Johannes Berg6e0d1142007-07-27 15:43:22 +02001557 u8 *data = rx->skb->data;
Harvey Harrison238f74a2008-07-02 11:05:34 -07001558 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
Johannes Berg6e0d1142007-07-27 15:43:22 +02001559
Harvey Harrison238f74a2008-07-02 11:05:34 -07001560 if (!ieee80211_is_data_qos(hdr->frame_control))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001561 return RX_CONTINUE;
Johannes Berg6e0d1142007-07-27 15:43:22 +02001562
1563 /* remove the qos control field, update frame type and meta-data */
Harvey Harrison238f74a2008-07-02 11:05:34 -07001564 memmove(data + IEEE80211_QOS_CTL_LEN, data,
1565 ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
1566 hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
Johannes Berg6e0d1142007-07-27 15:43:22 +02001567 /* change frame type to non QOS */
Harvey Harrison238f74a2008-07-02 11:05:34 -07001568 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Johannes Berg6e0d1142007-07-27 15:43:22 +02001569
Johannes Berg9ae54c82008-01-31 19:48:20 +01001570 return RX_CONTINUE;
Johannes Berg6e0d1142007-07-27 15:43:22 +02001571}
1572
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001573static int
Johannes Berg5cf121c2008-02-25 16:27:43 +01001574ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001575{
Johannes Berg07346f812008-05-03 01:02:02 +02001576 if (unlikely(!rx->sta ||
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001577 !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001578 return -EACCES;
Johannes Berg571ecf62007-07-27 15:43:22 +02001579
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001580 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001581}
1582
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001583static int
Harvey Harrison358c8d92008-07-15 18:44:13 -07001584ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Berg571ecf62007-07-27 15:43:22 +02001585{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001586 struct sk_buff *skb = rx->skb;
1587 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1588
Johannes Berg3017b802007-08-28 17:01:53 -04001589 /*
Johannes Berg7848ba72007-09-14 11:10:25 -04001590 * Pass through unencrypted frames if the hardware has
1591 * decrypted them already.
Johannes Berg3017b802007-08-28 17:01:53 -04001592 */
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001593 if (status->flag & RX_FLAG_DECRYPTED)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001594 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001595
1596 /* Drop unencrypted frames if key is set. */
Harvey Harrison358c8d92008-07-15 18:44:13 -07001597 if (unlikely(!ieee80211_has_protected(fc) &&
1598 !ieee80211_is_nullfunc(fc) &&
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001599 ieee80211_is_data(fc) &&
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001600 (rx->key || rx->sdata->drop_unencrypted)))
1601 return -EACCES;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001602
1603 return 0;
1604}
1605
1606static int
1607ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1608{
1609 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Jouni Malinene3efca02010-03-28 22:31:15 -07001610 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001611 __le16 fc = hdr->frame_control;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001612
Jouni Malinene3efca02010-03-28 22:31:15 -07001613 /*
1614 * Pass through unencrypted frames if the hardware has
1615 * decrypted them already.
1616 */
1617 if (status->flag & RX_FLAG_DECRYPTED)
1618 return 0;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001619
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001620 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
Jouni Malinend211e902010-03-28 22:29:52 -07001621 if (unlikely(!ieee80211_has_protected(fc) &&
1622 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02001623 rx->key)) {
1624 if (ieee80211_is_deauth(fc))
1625 cfg80211_send_unprot_deauth(rx->sdata->dev,
1626 rx->skb->data,
1627 rx->skb->len);
1628 else if (ieee80211_is_disassoc(fc))
1629 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1630 rx->skb->data,
1631 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001632 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02001633 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001634 /* BIP does not use Protected field, so need to check MMIE */
Joe Perchesf64f9e72009-11-29 16:55:45 -08001635 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02001636 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
1637 if (ieee80211_is_deauth(fc))
1638 cfg80211_send_unprot_deauth(rx->sdata->dev,
1639 rx->skb->data,
1640 rx->skb->len);
1641 else if (ieee80211_is_disassoc(fc))
1642 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1643 rx->skb->data,
1644 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001645 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02001646 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001647 /*
1648 * When using MFP, Action frames are not allowed prior to
1649 * having configured keys.
1650 */
1651 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1652 ieee80211_is_robust_mgmt_frame(
1653 (struct ieee80211_hdr *) rx->skb->data)))
1654 return -EACCES;
1655 }
Johannes Bergb3fc9c62008-04-13 10:12:47 +02001656
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001657 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001658}
1659
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001660static int
Felix Fietkau4114fa22011-04-12 19:15:22 +02001661__ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
Johannes Berg571ecf62007-07-27 15:43:22 +02001662{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001663 struct ieee80211_sub_if_data *sdata = rx->sdata;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001664 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001665 bool check_port_control = false;
1666 struct ethhdr *ehdr;
1667 int ret;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001668
Felix Fietkau4114fa22011-04-12 19:15:22 +02001669 *port_control = false;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001670 if (ieee80211_has_a4(hdr->frame_control) &&
1671 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001672 return -1;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001673
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001674 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1675 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
1676
1677 if (!sdata->u.mgd.use_4addr)
1678 return -1;
1679 else
1680 check_port_control = true;
1681 }
1682
Johannes Berg9bc383d2009-11-19 11:55:19 +01001683 if (is_multicast_ether_addr(hdr->addr1) &&
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001684 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001685 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001686
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001687 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
Felix Fietkau4114fa22011-04-12 19:15:22 +02001688 if (ret < 0)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001689 return ret;
1690
1691 ehdr = (struct ethhdr *) rx->skb->data;
Felix Fietkau4114fa22011-04-12 19:15:22 +02001692 if (ehdr->h_proto == rx->sdata->control_port_protocol)
1693 *port_control = true;
1694 else if (check_port_control)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001695 return -1;
1696
1697 return 0;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001698}
Johannes Berg571ecf62007-07-27 15:43:22 +02001699
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001700/*
1701 * requires that rx->skb is a frame with ethernet header
1702 */
Harvey Harrison358c8d92008-07-15 18:44:13 -07001703static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001704{
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301705 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001706 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1707 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1708
1709 /*
1710 * Allow EAPOL frames to us/the PAE group address regardless
1711 * of whether the frame was encrypted or not.
1712 */
Johannes Berga621fa42010-08-27 14:26:54 +03001713 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
Johannes Berg47846c92009-11-25 17:46:19 +01001714 (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 ||
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001715 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1716 return true;
1717
1718 if (ieee80211_802_1x_port_control(rx) ||
Harvey Harrison358c8d92008-07-15 18:44:13 -07001719 ieee80211_drop_unencrypted(rx, fc))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001720 return false;
1721
1722 return true;
1723}
1724
1725/*
1726 * requires that rx->skb is a frame with ethernet header
1727 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001728static void
Johannes Berg5cf121c2008-02-25 16:27:43 +01001729ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001730{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001731 struct ieee80211_sub_if_data *sdata = rx->sdata;
1732 struct net_device *dev = sdata->dev;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001733 struct sk_buff *skb, *xmit_skb;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001734 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1735 struct sta_info *dsta;
Johannes Berg554891e2010-09-24 12:38:25 +02001736 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001737
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001738 skb = rx->skb;
1739 xmit_skb = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +02001740
Johannes Berg05c914f2008-09-11 00:01:58 +02001741 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1742 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
Johannes Berg213cd112008-09-11 00:01:54 +02001743 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
Johannes Berg554891e2010-09-24 12:38:25 +02001744 (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
Johannes Berg9bc383d2009-11-19 11:55:19 +01001745 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001746 if (is_multicast_ether_addr(ehdr->h_dest)) {
1747 /*
1748 * send multicast frames both to higher layers in
1749 * local net stack and back to the wireless medium
1750 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001751 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1752 if (!xmit_skb && net_ratelimit())
Johannes Berg571ecf62007-07-27 15:43:22 +02001753 printk(KERN_DEBUG "%s: failed to clone "
1754 "multicast frame\n", dev->name);
1755 } else {
Johannes Bergabe60632009-11-25 17:46:18 +01001756 dsta = sta_info_get(sdata, skb->data);
1757 if (dsta) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001758 /*
1759 * The destination station is associated to
1760 * this AP (in this VLAN), so send the frame
1761 * directly to it and do not pass it to local
1762 * net stack.
Johannes Berg571ecf62007-07-27 15:43:22 +02001763 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001764 xmit_skb = skb;
Johannes Berg571ecf62007-07-27 15:43:22 +02001765 skb = NULL;
1766 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001767 }
1768 }
1769
1770 if (skb) {
Johannes Bergd1c3a372009-01-07 00:26:10 +01001771 int align __maybe_unused;
1772
Kalle Valo59d9cb02009-12-17 13:54:57 +01001773#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Johannes Bergd1c3a372009-01-07 00:26:10 +01001774 /*
1775 * 'align' will only take the values 0 or 2 here
1776 * since all frames are required to be aligned
1777 * to 2-byte boundaries when being passed to
1778 * mac80211. That also explains the __skb_push()
1779 * below.
1780 */
matthieu castetdacb6f12009-06-04 22:16:18 +02001781 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
Johannes Bergd1c3a372009-01-07 00:26:10 +01001782 if (align) {
1783 if (WARN_ON(skb_headroom(skb) < 3)) {
1784 dev_kfree_skb(skb);
1785 skb = NULL;
1786 } else {
1787 u8 *data = skb->data;
Zhu Yi8ce0b582009-10-28 13:13:52 -07001788 size_t len = skb_headlen(skb);
1789 skb->data -= align;
1790 memmove(skb->data, data, len);
1791 skb_set_tail_pointer(skb, len);
Johannes Bergd1c3a372009-01-07 00:26:10 +01001792 }
1793 }
1794#endif
1795
1796 if (skb) {
1797 /* deliver to local stack */
1798 skb->protocol = eth_type_trans(skb, dev);
1799 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville5548a8a2010-06-24 14:25:56 -04001800 netif_receive_skb(skb);
Johannes Bergd1c3a372009-01-07 00:26:10 +01001801 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001802 }
1803
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001804 if (xmit_skb) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001805 /* send to wireless media */
YOSHIFUJI Hideakif831e902007-12-12 03:54:23 +09001806 xmit_skb->protocol = htons(ETH_P_802_3);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001807 skb_reset_network_header(xmit_skb);
1808 skb_reset_mac_header(xmit_skb);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001809 dev_queue_xmit(xmit_skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001810 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001811}
1812
Johannes Berg49461622008-06-30 15:10:45 +02001813static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001814ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001815{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001816 struct net_device *dev = rx->sdata->dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001817 struct sk_buff *skb = rx->skb;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001818 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1819 __le16 fc = hdr->frame_control;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001820 struct sk_buff_head frame_list;
Johannes Berg554891e2010-09-24 12:38:25 +02001821 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001822
Harvey Harrison358c8d92008-07-15 18:44:13 -07001823 if (unlikely(!ieee80211_is_data(fc)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001824 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001825
Harvey Harrison358c8d92008-07-15 18:44:13 -07001826 if (unlikely(!ieee80211_is_data_present(fc)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001827 return RX_DROP_MONITOR;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001828
Johannes Berg554891e2010-09-24 12:38:25 +02001829 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001830 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001831
Zhu Yieaf85ca2009-12-01 10:18:37 +08001832 if (ieee80211_has_a4(hdr->frame_control) &&
1833 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1834 !rx->sdata->u.vlan.sta)
1835 return RX_DROP_UNUSABLE;
1836
1837 if (is_multicast_ether_addr(hdr->addr1) &&
1838 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1839 rx->sdata->u.vlan.sta) ||
1840 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1841 rx->sdata->u.mgd.use_4addr)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001842 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001843
1844 skb->dev = dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001845 __skb_queue_head_init(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001846
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08001847 if (skb_linearize(skb))
1848 return RX_DROP_UNUSABLE;
1849
Zhu Yieaf85ca2009-12-01 10:18:37 +08001850 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
1851 rx->sdata->vif.type,
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -07001852 rx->local->hw.extra_tx_headroom, true);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001853
Zhu Yieaf85ca2009-12-01 10:18:37 +08001854 while (!skb_queue_empty(&frame_list)) {
1855 rx->skb = __skb_dequeue(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001856
Harvey Harrison358c8d92008-07-15 18:44:13 -07001857 if (!ieee80211_frame_allowed(rx, fc)) {
Zhu Yieaf85ca2009-12-01 10:18:37 +08001858 dev_kfree_skb(rx->skb);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001859 continue;
1860 }
Zhu Yieaf85ca2009-12-01 10:18:37 +08001861 dev->stats.rx_packets++;
1862 dev->stats.rx_bytes += rx->skb->len;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001863
1864 ieee80211_deliver_skb(rx);
1865 }
1866
Johannes Berg9ae54c82008-01-31 19:48:20 +01001867 return RX_QUEUED;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001868}
1869
Ingo Molnarbf94e172008-10-12 23:51:38 -07001870#ifdef CONFIG_MAC80211_MESH
Davide Pesaventob0dee572008-09-27 17:29:12 +02001871static ieee80211_rx_result
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001872ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1873{
1874 struct ieee80211_hdr *hdr;
1875 struct ieee80211s_hdr *mesh_hdr;
1876 unsigned int hdrlen;
1877 struct sk_buff *skb = rx->skb, *fwd_skb;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001878 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001879 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02001880 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001881
1882 hdr = (struct ieee80211_hdr *) skb->data;
1883 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1884 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1885
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07001886 /* frame is in RMC, don't forward */
1887 if (ieee80211_is_data(hdr->frame_control) &&
1888 is_multicast_ether_addr(hdr->addr1) &&
1889 mesh_rmc_check(hdr->addr3, mesh_hdr, rx->sdata))
1890 return RX_DROP_MONITOR;
1891
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001892 if (!ieee80211_is_data(hdr->frame_control))
1893 return RX_CONTINUE;
1894
1895 if (!mesh_hdr->ttl)
1896 /* illegal frame */
1897 return RX_DROP_MONITOR;
1898
Javier Cardonacfee66b2011-09-06 13:05:21 -07001899 if (ieee80211_queue_stopped(&local->hw, skb_get_queue_mapping(skb))) {
1900 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1901 dropped_frames_congestion);
1902 return RX_DROP_MONITOR;
1903 }
1904
Javier Cardona43b7b312009-10-15 18:10:51 -07001905 if (mesh_hdr->flags & MESH_FLAGS_AE) {
YanBo79617de2008-09-22 13:30:32 +08001906 struct mesh_path *mppath;
Javier Cardona43b7b312009-10-15 18:10:51 -07001907 char *proxied_addr;
1908 char *mpp_addr;
1909
1910 if (is_multicast_ether_addr(hdr->addr1)) {
1911 mpp_addr = hdr->addr3;
1912 proxied_addr = mesh_hdr->eaddr1;
1913 } else {
1914 mpp_addr = hdr->addr4;
1915 proxied_addr = mesh_hdr->eaddr2;
1916 }
YanBo79617de2008-09-22 13:30:32 +08001917
YanBo79617de2008-09-22 13:30:32 +08001918 rcu_read_lock();
Javier Cardona43b7b312009-10-15 18:10:51 -07001919 mppath = mpp_path_lookup(proxied_addr, sdata);
YanBo79617de2008-09-22 13:30:32 +08001920 if (!mppath) {
Javier Cardona43b7b312009-10-15 18:10:51 -07001921 mpp_path_add(proxied_addr, mpp_addr, sdata);
YanBo79617de2008-09-22 13:30:32 +08001922 } else {
1923 spin_lock_bh(&mppath->state_lock);
Javier Cardona43b7b312009-10-15 18:10:51 -07001924 if (compare_ether_addr(mppath->mpp, mpp_addr) != 0)
1925 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
YanBo79617de2008-09-22 13:30:32 +08001926 spin_unlock_bh(&mppath->state_lock);
1927 }
1928 rcu_read_unlock();
1929 }
1930
Javier Cardona3c5772a2009-08-10 12:15:48 -07001931 /* Frame has reached destination. Don't forward */
1932 if (!is_multicast_ether_addr(hdr->addr1) &&
Johannes Berg47846c92009-11-25 17:46:19 +01001933 compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001934 return RX_CONTINUE;
1935
1936 mesh_hdr->ttl--;
1937
Johannes Berg554891e2010-09-24 12:38:25 +02001938 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001939 if (!mesh_hdr->ttl)
Johannes Berg472dbc42008-09-11 00:01:49 +02001940 IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001941 dropped_frames_ttl);
1942 else {
1943 struct ieee80211_hdr *fwd_hdr;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001944 struct ieee80211_tx_info *info;
1945
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001946 fwd_skb = skb_copy(skb, GFP_ATOMIC);
1947
1948 if (!fwd_skb && net_ratelimit())
1949 printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001950 sdata->name);
Milton Miller919bbad2010-12-30 02:01:03 -06001951 if (!fwd_skb)
Johannes Bergb51aff02010-12-22 10:15:07 +01001952 goto out;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001953
1954 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
Johannes Berg47846c92009-11-25 17:46:19 +01001955 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001956 info = IEEE80211_SKB_CB(fwd_skb);
1957 memset(info, 0, sizeof(*info));
1958 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
Johannes Berg5061b0c2009-07-14 00:33:34 +02001959 info->control.vif = &rx->sdata->vif;
Javier Cardona4777be42011-09-07 17:49:52 -07001960 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
Daniel Walkerc8a61a72009-08-18 10:59:00 -07001961 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1962 fwded_mcast);
Javier Cardona4777be42011-09-07 17:49:52 -07001963 skb_set_queue_mapping(fwd_skb,
1964 ieee80211_select_queue(sdata, fwd_skb));
Javier Cardona2154c81c2011-09-07 17:49:53 -07001965 ieee80211_set_qos_hdr(sdata, fwd_skb);
Javier Cardona4777be42011-09-07 17:49:52 -07001966 } else {
Javier Cardona3c5772a2009-08-10 12:15:48 -07001967 int err;
1968 /*
1969 * Save TA to addr1 to send TA a path error if a
1970 * suitable next hop is not found
1971 */
1972 memcpy(fwd_hdr->addr1, fwd_hdr->addr2,
Javier Cardona249b4052009-07-07 10:55:03 -07001973 ETH_ALEN);
Javier Cardona3c5772a2009-08-10 12:15:48 -07001974 err = mesh_nexthop_lookup(fwd_skb, sdata);
Javier Cardona249b4052009-07-07 10:55:03 -07001975 /* Failed to immediately resolve next hop:
1976 * fwded frame was dropped or will be added
1977 * later to the pending skb queue. */
1978 if (err)
1979 return RX_DROP_MONITOR;
Daniel Walkerc8a61a72009-08-18 10:59:00 -07001980
1981 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1982 fwded_unicast);
Javier Cardona249b4052009-07-07 10:55:03 -07001983 }
1984 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1985 fwded_frames);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001986 ieee80211_add_pending_skb(local, fwd_skb);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001987 }
1988 }
1989
Johannes Bergb51aff02010-12-22 10:15:07 +01001990 out:
Javier Cardona3c5772a2009-08-10 12:15:48 -07001991 if (is_multicast_ether_addr(hdr->addr1) ||
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001992 sdata->dev->flags & IFF_PROMISC)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001993 return RX_CONTINUE;
1994 else
1995 return RX_DROP_MONITOR;
1996}
Ingo Molnarbf94e172008-10-12 23:51:38 -07001997#endif
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001998
1999static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002000ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002001{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002002 struct ieee80211_sub_if_data *sdata = rx->sdata;
Vivek Natarajane15276a2010-02-08 17:47:01 +05302003 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002004 struct net_device *dev = sdata->dev;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002005 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2006 __le16 fc = hdr->frame_control;
Felix Fietkau4114fa22011-04-12 19:15:22 +02002007 bool port_control;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002008 int err;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002009
Harvey Harrison358c8d92008-07-15 18:44:13 -07002010 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002011 return RX_CONTINUE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002012
Harvey Harrison358c8d92008-07-15 18:44:13 -07002013 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002014 return RX_DROP_MONITOR;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002015
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002016 /*
2017 * Allow the cooked monitor interface of an AP to see 4-addr frames so
2018 * that a 4-addr station can be detected and moved into a separate VLAN
2019 */
2020 if (ieee80211_has_a4(hdr->frame_control) &&
2021 sdata->vif.type == NL80211_IFTYPE_AP)
2022 return RX_DROP_MONITOR;
2023
Felix Fietkau4114fa22011-04-12 19:15:22 +02002024 err = __ieee80211_data_to_8023(rx, &port_control);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002025 if (unlikely(err))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002026 return RX_DROP_UNUSABLE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002027
Harvey Harrison358c8d92008-07-15 18:44:13 -07002028 if (!ieee80211_frame_allowed(rx, fc))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002029 return RX_DROP_MONITOR;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002030
Felix Fietkau4114fa22011-04-12 19:15:22 +02002031 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2032 unlikely(port_control) && sdata->bss) {
2033 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2034 u.ap);
2035 dev = sdata->dev;
2036 rx->sdata = sdata;
2037 }
2038
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002039 rx->skb->dev = dev;
2040
2041 dev->stats.rx_packets++;
2042 dev->stats.rx_bytes += rx->skb->len;
2043
Helmut Schaa08ca9442010-11-30 12:19:34 +01002044 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
Rajkumar Manoharan8c99f692011-02-02 22:57:53 +05302045 !is_multicast_ether_addr(
2046 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2047 (!local->scanning &&
2048 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
Vivek Natarajane15276a2010-02-08 17:47:01 +05302049 mod_timer(&local->dynamic_ps_timer, jiffies +
2050 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2051 }
2052
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002053 ieee80211_deliver_skb(rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02002054
Johannes Berg9ae54c82008-01-31 19:48:20 +01002055 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002056}
2057
Johannes Berg49461622008-06-30 15:10:45 +02002058static ieee80211_rx_result debug_noinline
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002059ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
Ron Rindjunsky71364712007-12-25 17:00:36 +02002060{
2061 struct ieee80211_local *local = rx->local;
2062 struct ieee80211_hw *hw = &local->hw;
2063 struct sk_buff *skb = rx->skb;
Harvey Harrisona7767f92008-07-02 16:30:51 -07002064 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002065 struct tid_ampdu_rx *tid_agg_rx;
2066 u16 start_seq_num;
2067 u16 tid;
2068
Harvey Harrisona7767f92008-07-02 16:30:51 -07002069 if (likely(!ieee80211_is_ctl(bar->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002070 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002071
Harvey Harrisona7767f92008-07-02 16:30:51 -07002072 if (ieee80211_is_back_req(bar->frame_control)) {
Johannes Berg8ae59772010-05-30 14:52:58 +02002073 struct {
2074 __le16 control, start_seq_num;
2075 } __packed bar_data;
2076
Ron Rindjunsky71364712007-12-25 17:00:36 +02002077 if (!rx->sta)
Johannes Berga02ae752009-11-16 12:00:40 +01002078 return RX_DROP_MONITOR;
Johannes Berg8ae59772010-05-30 14:52:58 +02002079
2080 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2081 &bar_data, sizeof(bar_data)))
2082 return RX_DROP_MONITOR;
2083
Johannes Berg8ae59772010-05-30 14:52:58 +02002084 tid = le16_to_cpu(bar_data.control) >> 12;
Johannes Berga87f7362010-06-10 10:21:38 +02002085
2086 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2087 if (!tid_agg_rx)
Johannes Berga02ae752009-11-16 12:00:40 +01002088 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002089
Johannes Berg8ae59772010-05-30 14:52:58 +02002090 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002091
2092 /* reset session timer */
Johannes Berg20ad19d2009-02-10 21:25:45 +01002093 if (tid_agg_rx->timeout)
2094 mod_timer(&tid_agg_rx->session_timer,
2095 TU_TO_EXP_TIME(tid_agg_rx->timeout));
Ron Rindjunsky71364712007-12-25 17:00:36 +02002096
Johannes Bergdd318572010-11-29 11:09:16 +01002097 spin_lock(&tid_agg_rx->reorder_lock);
Johannes Berga02ae752009-11-16 12:00:40 +01002098 /* release stored frames up to start of BAR */
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002099 ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num);
Johannes Bergdd318572010-11-29 11:09:16 +01002100 spin_unlock(&tid_agg_rx->reorder_lock);
2101
Johannes Berga02ae752009-11-16 12:00:40 +01002102 kfree_skb(skb);
2103 return RX_QUEUED;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002104 }
2105
Johannes Berg08daeca2010-05-30 14:53:43 +02002106 /*
2107 * After this point, we only want management frames,
2108 * so we can drop all remaining control frames to
2109 * cooked monitor interfaces.
2110 */
2111 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002112}
2113
Jouni Malinenf4f727a2009-01-10 11:46:53 +02002114static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2115 struct ieee80211_mgmt *mgmt,
2116 size_t len)
Jouni Malinenfea14732009-01-08 13:32:06 +02002117{
2118 struct ieee80211_local *local = sdata->local;
2119 struct sk_buff *skb;
2120 struct ieee80211_mgmt *resp;
2121
Johannes Berg47846c92009-11-25 17:46:19 +01002122 if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) {
Jouni Malinenfea14732009-01-08 13:32:06 +02002123 /* Not to own unicast address */
2124 return;
2125 }
2126
Johannes Berg46900292009-02-15 12:44:28 +01002127 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
2128 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002129 /* Not from the current AP or not associated yet. */
Jouni Malinenfea14732009-01-08 13:32:06 +02002130 return;
2131 }
2132
2133 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2134 /* Too short SA Query request frame */
2135 return;
2136 }
2137
2138 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2139 if (skb == NULL)
2140 return;
2141
2142 skb_reserve(skb, local->hw.extra_tx_headroom);
2143 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2144 memset(resp, 0, 24);
2145 memcpy(resp->da, mgmt->sa, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002146 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +01002147 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
Jouni Malinenfea14732009-01-08 13:32:06 +02002148 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2149 IEEE80211_STYPE_ACTION);
2150 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2151 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2152 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2153 memcpy(resp->u.action.u.sa_query.trans_id,
2154 mgmt->u.action.u.sa_query.trans_id,
2155 WLAN_SA_QUERY_TR_ID_LEN);
2156
Johannes Berg62ae67b2009-11-18 18:42:05 +01002157 ieee80211_tx_skb(sdata, skb);
Jouni Malinenfea14732009-01-08 13:32:06 +02002158}
2159
Johannes Berg49461622008-06-30 15:10:45 +02002160static ieee80211_rx_result debug_noinline
Johannes Berg2e161f782010-08-12 15:38:38 +02002161ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2162{
2163 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002164 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f782010-08-12 15:38:38 +02002165
2166 /*
2167 * From here on, look only at management frames.
2168 * Data and control frames are already handled,
2169 * and unknown (reserved) frames are useless.
2170 */
2171 if (rx->skb->len < 24)
2172 return RX_DROP_MONITOR;
2173
2174 if (!ieee80211_is_mgmt(mgmt->frame_control))
2175 return RX_DROP_MONITOR;
2176
Johannes Berg554891e2010-09-24 12:38:25 +02002177 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg2e161f782010-08-12 15:38:38 +02002178 return RX_DROP_MONITOR;
2179
2180 if (ieee80211_drop_unencrypted_mgmt(rx))
2181 return RX_DROP_UNUSABLE;
2182
2183 return RX_CONTINUE;
2184}
2185
2186static ieee80211_rx_result debug_noinline
Johannes Bergde1ede72008-09-09 14:42:50 +02002187ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2188{
2189 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002190 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergde1ede72008-09-09 14:42:50 +02002191 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002192 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergde1ede72008-09-09 14:42:50 +02002193 int len = rx->skb->len;
2194
2195 if (!ieee80211_is_action(mgmt->frame_control))
2196 return RX_CONTINUE;
2197
Jouni Malinen026331c2010-02-15 12:53:10 +02002198 /* drop too small frames */
2199 if (len < IEEE80211_MIN_ACTION_SIZE)
2200 return RX_DROP_UNUSABLE;
2201
2202 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
Johannes Berg84040802010-02-15 12:46:39 +02002203 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002204
Johannes Berg554891e2010-09-24 12:38:25 +02002205 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg84040802010-02-15 12:46:39 +02002206 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002207
Johannes Bergde1ede72008-09-09 14:42:50 +02002208 switch (mgmt->u.action.category) {
2209 case WLAN_CATEGORY_BACK:
Johannes Berg8abd3f92009-02-10 21:25:47 +01002210 /*
2211 * The aggregation code is not prepared to handle
2212 * anything but STA/AP due to the BSSID handling;
2213 * IBSS could work in the code but isn't supported
2214 * by drivers or the standard.
2215 */
2216 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2217 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2218 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg84040802010-02-15 12:46:39 +02002219 break;
Johannes Berg8abd3f92009-02-10 21:25:47 +01002220
Jouni Malinen026331c2010-02-15 12:53:10 +02002221 /* verify action_code is present */
2222 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2223 break;
2224
Johannes Bergde1ede72008-09-09 14:42:50 +02002225 switch (mgmt->u.action.u.addba_req.action_code) {
2226 case WLAN_ACTION_ADDBA_REQ:
2227 if (len < (IEEE80211_MIN_ACTION_SIZE +
2228 sizeof(mgmt->u.action.u.addba_req)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002229 goto invalid;
2230 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002231 case WLAN_ACTION_ADDBA_RESP:
2232 if (len < (IEEE80211_MIN_ACTION_SIZE +
2233 sizeof(mgmt->u.action.u.addba_resp)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002234 goto invalid;
2235 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002236 case WLAN_ACTION_DELBA:
2237 if (len < (IEEE80211_MIN_ACTION_SIZE +
2238 sizeof(mgmt->u.action.u.delba)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002239 goto invalid;
2240 break;
2241 default:
2242 goto invalid;
Johannes Bergde1ede72008-09-09 14:42:50 +02002243 }
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002244
Johannes Berg8b58ff82010-06-10 10:21:51 +02002245 goto queue;
Johannes Berg39192c02008-09-09 14:49:03 +02002246 case WLAN_CATEGORY_SPECTRUM_MGMT:
2247 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
Johannes Berg84040802010-02-15 12:46:39 +02002248 break;
Johannes Berg46900292009-02-15 12:44:28 +01002249
2250 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002251 break;
Johannes Berg46900292009-02-15 12:44:28 +01002252
Jouni Malinen026331c2010-02-15 12:53:10 +02002253 /* verify action_code is present */
2254 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2255 break;
2256
Johannes Berg39192c02008-09-09 14:49:03 +02002257 switch (mgmt->u.action.u.measurement.action_code) {
2258 case WLAN_ACTION_SPCT_MSR_REQ:
2259 if (len < (IEEE80211_MIN_ACTION_SIZE +
2260 sizeof(mgmt->u.action.u.measurement)))
Johannes Berg84040802010-02-15 12:46:39 +02002261 break;
Johannes Berg39192c02008-09-09 14:49:03 +02002262 ieee80211_process_measurement_req(sdata, mgmt, len);
Johannes Berg84040802010-02-15 12:46:39 +02002263 goto handled;
Sujithc481ec92009-01-06 09:28:37 +05302264 case WLAN_ACTION_SPCT_CHL_SWITCH:
2265 if (len < (IEEE80211_MIN_ACTION_SIZE +
2266 sizeof(mgmt->u.action.u.chan_switch)))
Johannes Berg84040802010-02-15 12:46:39 +02002267 break;
Sujithc481ec92009-01-06 09:28:37 +05302268
Johannes Bergcc32abd2009-05-15 11:52:31 +02002269 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002270 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02002271
Johannes Berg46900292009-02-15 12:44:28 +01002272 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
Johannes Berg84040802010-02-15 12:46:39 +02002273 break;
Sujithc481ec92009-01-06 09:28:37 +05302274
Johannes Berg8b58ff82010-06-10 10:21:51 +02002275 goto queue;
Johannes Berg39192c02008-09-09 14:49:03 +02002276 }
2277 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002278 case WLAN_CATEGORY_SA_QUERY:
2279 if (len < (IEEE80211_MIN_ACTION_SIZE +
2280 sizeof(mgmt->u.action.u.sa_query)))
Johannes Berg84040802010-02-15 12:46:39 +02002281 break;
2282
Jouni Malinenfea14732009-01-08 13:32:06 +02002283 switch (mgmt->u.action.u.sa_query.action) {
2284 case WLAN_ACTION_SA_QUERY_REQUEST:
2285 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002286 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002287 ieee80211_process_sa_query_req(sdata, mgmt, len);
Johannes Berg84040802010-02-15 12:46:39 +02002288 goto handled;
Jouni Malinenfea14732009-01-08 13:32:06 +02002289 }
2290 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -07002291 case WLAN_CATEGORY_SELF_PROTECTED:
2292 switch (mgmt->u.action.u.self_prot.action_code) {
2293 case WLAN_SP_MESH_PEERING_OPEN:
2294 case WLAN_SP_MESH_PEERING_CLOSE:
2295 case WLAN_SP_MESH_PEERING_CONFIRM:
2296 if (!ieee80211_vif_is_mesh(&sdata->vif))
2297 goto invalid;
2298 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
2299 /* userspace handles this frame */
2300 break;
2301 goto queue;
2302 case WLAN_SP_MGK_INFORM:
2303 case WLAN_SP_MGK_ACK:
2304 if (!ieee80211_vif_is_mesh(&sdata->vif))
2305 goto invalid;
2306 break;
2307 }
2308 break;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -07002309 case WLAN_CATEGORY_MESH_ACTION:
Johannes Berg77a121c2010-06-10 10:21:34 +02002310 if (!ieee80211_vif_is_mesh(&sdata->vif))
2311 break;
Thomas Pedersen25d49e42011-08-11 19:35:15 -07002312 if (mesh_action_is_path_sel(mgmt) &&
2313 (!mesh_path_sel_is_hwmp(sdata)))
Javier Cardonac7108a72010-12-16 17:37:50 -08002314 break;
2315 goto queue;
Johannes Berg84040802010-02-15 12:46:39 +02002316 }
Jouni Malinen026331c2010-02-15 12:53:10 +02002317
Johannes Berg2e161f782010-08-12 15:38:38 +02002318 return RX_CONTINUE;
2319
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002320 invalid:
Johannes Berg554891e2010-09-24 12:38:25 +02002321 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
Johannes Berg2e161f782010-08-12 15:38:38 +02002322 /* will return in the next handlers */
2323 return RX_CONTINUE;
2324
2325 handled:
2326 if (rx->sta)
2327 rx->sta->rx_packets++;
2328 dev_kfree_skb(rx->skb);
2329 return RX_QUEUED;
2330
2331 queue:
2332 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2333 skb_queue_tail(&sdata->skb_queue, rx->skb);
2334 ieee80211_queue_work(&local->hw, &sdata->work);
2335 if (rx->sta)
2336 rx->sta->rx_packets++;
2337 return RX_QUEUED;
2338}
2339
2340static ieee80211_rx_result debug_noinline
2341ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2342{
Johannes Berg554891e2010-09-24 12:38:25 +02002343 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f782010-08-12 15:38:38 +02002344
2345 /* skip known-bad action frames and return them in the next handler */
Johannes Berg554891e2010-09-24 12:38:25 +02002346 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
Johannes Berg2e161f782010-08-12 15:38:38 +02002347 return RX_CONTINUE;
Felix Fietkaud7907442010-01-07 20:23:53 +01002348
Jouni Malinen026331c2010-02-15 12:53:10 +02002349 /*
2350 * Getting here means the kernel doesn't know how to handle
2351 * it, but maybe userspace does ... include returned frames
2352 * so userspace can register for those to know whether ones
2353 * it transmitted were processed or returned.
2354 */
Jouni Malinen026331c2010-02-15 12:53:10 +02002355
Johannes Berg2e161f782010-08-12 15:38:38 +02002356 if (cfg80211_rx_mgmt(rx->sdata->dev, status->freq,
2357 rx->skb->data, rx->skb->len,
2358 GFP_ATOMIC)) {
2359 if (rx->sta)
2360 rx->sta->rx_packets++;
2361 dev_kfree_skb(rx->skb);
2362 return RX_QUEUED;
2363 }
2364
2365
2366 return RX_CONTINUE;
2367}
2368
2369static ieee80211_rx_result debug_noinline
2370ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2371{
2372 struct ieee80211_local *local = rx->local;
2373 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2374 struct sk_buff *nskb;
2375 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02002376 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f782010-08-12 15:38:38 +02002377
2378 if (!ieee80211_is_action(mgmt->frame_control))
2379 return RX_CONTINUE;
2380
2381 /*
2382 * For AP mode, hostapd is responsible for handling any action
2383 * frames that we didn't handle, including returning unknown
2384 * ones. For all other modes we will return them to the sender,
2385 * setting the 0x80 bit in the action category, as required by
2386 * 802.11-2007 7.3.1.11.
2387 * Newer versions of hostapd shall also use the management frame
2388 * registration mechanisms, but older ones still use cooked
2389 * monitor interfaces so push all frames there.
2390 */
Johannes Berg554891e2010-09-24 12:38:25 +02002391 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
Johannes Berg2e161f782010-08-12 15:38:38 +02002392 (sdata->vif.type == NL80211_IFTYPE_AP ||
2393 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2394 return RX_DROP_MONITOR;
Jouni Malinen026331c2010-02-15 12:53:10 +02002395
Johannes Berg84040802010-02-15 12:46:39 +02002396 /* do not return rejected action frames */
2397 if (mgmt->u.action.category & 0x80)
2398 return RX_DROP_UNUSABLE;
2399
2400 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2401 GFP_ATOMIC);
2402 if (nskb) {
John W. Linville292b4df2010-06-24 11:13:56 -04002403 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
Johannes Berg84040802010-02-15 12:46:39 +02002404
John W. Linville292b4df2010-06-24 11:13:56 -04002405 nmgmt->u.action.category |= 0x80;
2406 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2407 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
Johannes Berg84040802010-02-15 12:46:39 +02002408
2409 memset(nskb->cb, 0, sizeof(nskb->cb));
2410
2411 ieee80211_tx_skb(rx->sdata, nskb);
Johannes Bergde1ede72008-09-09 14:42:50 +02002412 }
Johannes Berg39192c02008-09-09 14:49:03 +02002413 dev_kfree_skb(rx->skb);
2414 return RX_QUEUED;
Johannes Bergde1ede72008-09-09 14:42:50 +02002415}
2416
2417static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002418ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02002419{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002420 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002421 ieee80211_rx_result rxs;
Johannes Berg77a121c2010-06-10 10:21:34 +02002422 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2423 __le16 stype;
Johannes Berg571ecf62007-07-27 15:43:22 +02002424
Johannes Bergaf6b6372009-12-23 13:15:35 +01002425 rxs = ieee80211_work_rx_mgmt(rx->sdata, rx->skb);
2426 if (rxs != RX_CONTINUE)
2427 return rxs;
2428
Johannes Berg77a121c2010-06-10 10:21:34 +02002429 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
Johannes Berg472dbc42008-09-11 00:01:49 +02002430
Johannes Berg77a121c2010-06-10 10:21:34 +02002431 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2432 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2433 sdata->vif.type != NL80211_IFTYPE_STATION)
2434 return RX_DROP_MONITOR;
Johannes Bergf9d540e2007-09-28 14:02:09 +02002435
Johannes Berg77a121c2010-06-10 10:21:34 +02002436 switch (stype) {
2437 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2438 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2439 /* process for all: mesh, mlme, ibss */
2440 break;
2441 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2442 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
Christian Lamparter2c31333a2010-11-29 20:53:23 +01002443 if (is_multicast_ether_addr(mgmt->da) &&
2444 !is_broadcast_ether_addr(mgmt->da))
2445 return RX_DROP_MONITOR;
2446
Johannes Berg77a121c2010-06-10 10:21:34 +02002447 /* process only for station */
2448 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2449 return RX_DROP_MONITOR;
2450 break;
2451 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2452 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2453 /* process only for ibss */
2454 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
2455 return RX_DROP_MONITOR;
2456 break;
2457 default:
2458 return RX_DROP_MONITOR;
2459 }
Johannes Berg46900292009-02-15 12:44:28 +01002460
Johannes Berg77a121c2010-06-10 10:21:34 +02002461 /* queue up frame and kick off work to process it */
Johannes Bergc1475ca2010-06-10 10:21:37 +02002462 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg77a121c2010-06-10 10:21:34 +02002463 skb_queue_tail(&sdata->skb_queue, rx->skb);
2464 ieee80211_queue_work(&rx->local->hw, &sdata->work);
Johannes Berg8b58ff82010-06-10 10:21:51 +02002465 if (rx->sta)
2466 rx->sta->rx_packets++;
Johannes Berg77a121c2010-06-10 10:21:34 +02002467
2468 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002469}
2470
Johannes Berg5cf121c2008-02-25 16:27:43 +01002471/* TODO: use IEEE80211_RX_FRAGMENTED */
Johannes Berg5f0b7de2009-11-16 13:58:21 +01002472static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2473 struct ieee80211_rate *rate)
Michael Wu3d30d942008-01-31 19:48:27 +01002474{
2475 struct ieee80211_sub_if_data *sdata;
2476 struct ieee80211_local *local = rx->local;
2477 struct ieee80211_rtap_hdr {
2478 struct ieee80211_radiotap_header hdr;
2479 u8 flags;
Johannes Berg5f0b7de2009-11-16 13:58:21 +01002480 u8 rate_or_pad;
Michael Wu3d30d942008-01-31 19:48:27 +01002481 __le16 chan_freq;
2482 __le16 chan_flags;
Eric Dumazetbc105022010-06-03 03:21:52 -07002483 } __packed *rthdr;
Michael Wu3d30d942008-01-31 19:48:27 +01002484 struct sk_buff *skb = rx->skb, *skb2;
2485 struct net_device *prev_dev = NULL;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002486 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Michael Wu3d30d942008-01-31 19:48:27 +01002487
Johannes Berg554891e2010-09-24 12:38:25 +02002488 /*
2489 * If cooked monitor has been processed already, then
2490 * don't do it again. If not, set the flag.
2491 */
2492 if (rx->flags & IEEE80211_RX_CMNTR)
John W. Linville7c1e1832010-09-24 15:52:49 -04002493 goto out_free_skb;
Johannes Berg554891e2010-09-24 12:38:25 +02002494 rx->flags |= IEEE80211_RX_CMNTR;
John W. Linville7c1e1832010-09-24 15:52:49 -04002495
Michael Wu3d30d942008-01-31 19:48:27 +01002496 if (skb_headroom(skb) < sizeof(*rthdr) &&
2497 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
2498 goto out_free_skb;
2499
2500 rthdr = (void *)skb_push(skb, sizeof(*rthdr));
2501 memset(rthdr, 0, sizeof(*rthdr));
2502 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
2503 rthdr->hdr.it_present =
2504 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
Michael Wu3d30d942008-01-31 19:48:27 +01002505 (1 << IEEE80211_RADIOTAP_CHANNEL));
2506
Johannes Berg5f0b7de2009-11-16 13:58:21 +01002507 if (rate) {
2508 rthdr->rate_or_pad = rate->bitrate / 5;
2509 rthdr->hdr.it_present |=
2510 cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
2511 }
Michael Wu3d30d942008-01-31 19:48:27 +01002512 rthdr->chan_freq = cpu_to_le16(status->freq);
2513
2514 if (status->band == IEEE80211_BAND_5GHZ)
2515 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
2516 IEEE80211_CHAN_5GHZ);
2517 else
2518 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
2519 IEEE80211_CHAN_2GHZ);
2520
2521 skb_set_mac_header(skb, 0);
2522 skb->ip_summed = CHECKSUM_UNNECESSARY;
2523 skb->pkt_type = PACKET_OTHERHOST;
2524 skb->protocol = htons(ETH_P_802_2);
2525
2526 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +01002527 if (!ieee80211_sdata_running(sdata))
Michael Wu3d30d942008-01-31 19:48:27 +01002528 continue;
2529
Johannes Berg05c914f2008-09-11 00:01:58 +02002530 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
Michael Wu3d30d942008-01-31 19:48:27 +01002531 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
2532 continue;
2533
2534 if (prev_dev) {
2535 skb2 = skb_clone(skb, GFP_ATOMIC);
2536 if (skb2) {
2537 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04002538 netif_receive_skb(skb2);
Michael Wu3d30d942008-01-31 19:48:27 +01002539 }
2540 }
2541
2542 prev_dev = sdata->dev;
2543 sdata->dev->stats.rx_packets++;
2544 sdata->dev->stats.rx_bytes += skb->len;
2545 }
2546
2547 if (prev_dev) {
2548 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04002549 netif_receive_skb(skb);
Johannes Berg554891e2010-09-24 12:38:25 +02002550 return;
2551 }
Michael Wu3d30d942008-01-31 19:48:27 +01002552
2553 out_free_skb:
2554 dev_kfree_skb(skb);
2555}
2556
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002557static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
2558 ieee80211_rx_result res)
2559{
2560 switch (res) {
2561 case RX_DROP_MONITOR:
2562 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2563 if (rx->sta)
2564 rx->sta->rx_dropped++;
2565 /* fall through */
2566 case RX_CONTINUE: {
2567 struct ieee80211_rate *rate = NULL;
2568 struct ieee80211_supported_band *sband;
2569 struct ieee80211_rx_status *status;
2570
2571 status = IEEE80211_SKB_RXCB((rx->skb));
2572
2573 sband = rx->local->hw.wiphy->bands[status->band];
2574 if (!(status->flag & RX_FLAG_HT))
2575 rate = &sband->bitrates[status->rate_idx];
2576
2577 ieee80211_rx_cooked_monitor(rx, rate);
2578 break;
2579 }
2580 case RX_DROP_UNUSABLE:
2581 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2582 if (rx->sta)
2583 rx->sta->rx_dropped++;
2584 dev_kfree_skb(rx->skb);
2585 break;
2586 case RX_QUEUED:
2587 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
2588 break;
2589 }
2590}
2591
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002592static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002593{
2594 ieee80211_rx_result res = RX_DROP_MONITOR;
2595 struct sk_buff *skb;
2596
2597#define CALL_RXH(rxh) \
2598 do { \
2599 res = rxh(rx); \
2600 if (res != RX_CONTINUE) \
2601 goto rxh_next; \
2602 } while (0);
2603
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002604 spin_lock(&rx->local->rx_skb_queue.lock);
2605 if (rx->local->running_rx_handler)
2606 goto unlock;
2607
2608 rx->local->running_rx_handler = true;
2609
2610 while ((skb = __skb_dequeue(&rx->local->rx_skb_queue))) {
2611 spin_unlock(&rx->local->rx_skb_queue.lock);
2612
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002613 /*
2614 * all the other fields are valid across frames
2615 * that belong to an aMPDU since they are on the
2616 * same TID from the same station
2617 */
2618 rx->skb = skb;
2619
2620 CALL_RXH(ieee80211_rx_h_decrypt)
2621 CALL_RXH(ieee80211_rx_h_check_more_data)
Johannes Berg47086fc2011-09-29 16:04:33 +02002622 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002623 CALL_RXH(ieee80211_rx_h_sta_process)
2624 CALL_RXH(ieee80211_rx_h_defragment)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002625 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2626 /* must be after MMIC verify so header is counted in MPDU mic */
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002627#ifdef CONFIG_MAC80211_MESH
2628 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
2629 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2630#endif
Javier Cardona2154c81c2011-09-07 17:49:53 -07002631 CALL_RXH(ieee80211_rx_h_remove_qos_control)
2632 CALL_RXH(ieee80211_rx_h_amsdu)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002633 CALL_RXH(ieee80211_rx_h_data)
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002634 CALL_RXH(ieee80211_rx_h_ctrl);
Johannes Berg2e161f782010-08-12 15:38:38 +02002635 CALL_RXH(ieee80211_rx_h_mgmt_check)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002636 CALL_RXH(ieee80211_rx_h_action)
Johannes Berg2e161f782010-08-12 15:38:38 +02002637 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
2638 CALL_RXH(ieee80211_rx_h_action_return)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002639 CALL_RXH(ieee80211_rx_h_mgmt)
2640
2641 rxh_next:
2642 ieee80211_rx_handlers_result(rx, res);
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002643 spin_lock(&rx->local->rx_skb_queue.lock);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002644#undef CALL_RXH
2645 }
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002646
2647 rx->local->running_rx_handler = false;
2648
2649 unlock:
2650 spin_unlock(&rx->local->rx_skb_queue.lock);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002651}
Johannes Berg571ecf62007-07-27 15:43:22 +02002652
Johannes Berg4406c372010-09-24 11:21:06 +02002653static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
Johannes Berg58905292008-01-31 19:48:25 +01002654{
Johannes Berg58905292008-01-31 19:48:25 +01002655 ieee80211_rx_result res = RX_DROP_MONITOR;
2656
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002657#define CALL_RXH(rxh) \
2658 do { \
2659 res = rxh(rx); \
2660 if (res != RX_CONTINUE) \
Johannes Berg2569a822009-11-25 17:46:17 +01002661 goto rxh_next; \
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002662 } while (0);
Johannes Berg58905292008-01-31 19:48:25 +01002663
Johannes Berg49461622008-06-30 15:10:45 +02002664 CALL_RXH(ieee80211_rx_h_passive_scan)
2665 CALL_RXH(ieee80211_rx_h_check)
Johannes Berg2569a822009-11-25 17:46:17 +01002666
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002667 ieee80211_rx_reorder_ampdu(rx);
Johannes Berg2569a822009-11-25 17:46:17 +01002668
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002669 ieee80211_rx_handlers(rx);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002670 return;
Johannes Berg49461622008-06-30 15:10:45 +02002671
Johannes Berg2569a822009-11-25 17:46:17 +01002672 rxh_next:
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002673 ieee80211_rx_handlers_result(rx, res);
2674
2675#undef CALL_RXH
Johannes Berg58905292008-01-31 19:48:25 +01002676}
2677
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +02002678/*
Johannes Bergdd318572010-11-29 11:09:16 +01002679 * This function makes calls into the RX path, therefore
2680 * it has to be invoked under RCU read lock.
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +02002681 */
2682void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
2683{
Johannes Berg554891e2010-09-24 12:38:25 +02002684 struct ieee80211_rx_data rx = {
2685 .sta = sta,
2686 .sdata = sta->sdata,
2687 .local = sta->local,
Johannes Berg9e262972011-07-07 18:45:03 +02002688 /* This is OK -- must be QoS data frame */
2689 .security_idx = tid,
2690 .seqno_idx = tid,
Helmut Schaafcf8bd32011-04-01 15:46:05 +02002691 .flags = 0,
Johannes Berg554891e2010-09-24 12:38:25 +02002692 };
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02002693 struct tid_ampdu_rx *tid_agg_rx;
2694
2695 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
2696 if (!tid_agg_rx)
2697 return;
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +02002698
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02002699 spin_lock(&tid_agg_rx->reorder_lock);
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002700 ieee80211_sta_reorder_release(&sta->local->hw, tid_agg_rx);
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02002701 spin_unlock(&tid_agg_rx->reorder_lock);
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +02002702
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002703 ieee80211_rx_handlers(&rx);
Christian Lamparter2bff8ebf2010-08-05 01:36:41 +02002704}
2705
Johannes Berg571ecf62007-07-27 15:43:22 +02002706/* main receive path */
2707
Johannes Berg20b01f82010-09-24 11:21:05 +02002708static int prepare_for_handlers(struct ieee80211_rx_data *rx,
Johannes Berg23a24de2007-07-27 15:43:22 +02002709 struct ieee80211_hdr *hdr)
2710{
Johannes Berg20b01f82010-09-24 11:21:05 +02002711 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002712 struct sk_buff *skb = rx->skb;
2713 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2714 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
Johannes Berg23a24de2007-07-27 15:43:22 +02002715 int multicast = is_multicast_ether_addr(hdr->addr1);
2716
Johannes Berg51fb61e2007-12-19 01:31:27 +01002717 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002718 case NL80211_IFTYPE_STATION:
Johannes Berg9bc383d2009-11-19 11:55:19 +01002719 if (!bssid && !sdata->u.mgd.use_4addr)
Johannes Berg23a24de2007-07-27 15:43:22 +02002720 return 0;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002721 if (!multicast &&
Johannes Berg47846c92009-11-25 17:46:19 +01002722 compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) {
Felix Fietkau4f312332011-02-05 23:48:37 +01002723 if (!(sdata->dev->flags & IFF_PROMISC) ||
2724 sdata->u.mgd.use_4addr)
Johannes Berg23a24de2007-07-27 15:43:22 +02002725 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002726 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02002727 }
2728 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002729 case NL80211_IFTYPE_ADHOC:
Johannes Berg23a24de2007-07-27 15:43:22 +02002730 if (!bssid)
2731 return 0;
Harvey Harrisona7767f92008-07-02 16:30:51 -07002732 if (ieee80211_is_beacon(hdr->frame_control)) {
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002733 return 1;
Vladimir Koutny87291c02008-06-13 16:50:44 +02002734 }
Johannes Berg46900292009-02-15 12:44:28 +01002735 else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
Johannes Berg554891e2010-09-24 12:38:25 +02002736 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02002737 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002738 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02002739 } else if (!multicast &&
Johannes Berg47846c92009-11-25 17:46:19 +01002740 compare_ether_addr(sdata->vif.addr,
Johannes Berg23a24de2007-07-27 15:43:22 +02002741 hdr->addr1) != 0) {
Johannes Berg4150c572007-09-17 01:29:23 -04002742 if (!(sdata->dev->flags & IFF_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02002743 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002744 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02002745 } else if (!rx->sta) {
2746 int rate_idx;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002747 if (status->flag & RX_FLAG_HT)
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02002748 rate_idx = 0; /* TODO: HT rates */
2749 else
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002750 rate_idx = status->rate_idx;
Johannes Berg34e89502010-02-03 13:59:58 +01002751 rx->sta = ieee80211_ibss_add_sta(sdata, bssid,
2752 hdr->addr2, BIT(rate_idx), GFP_ATOMIC);
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02002753 }
Johannes Berg23a24de2007-07-27 15:43:22 +02002754 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002755 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg6032f932008-02-23 15:17:07 +01002756 if (!multicast &&
Johannes Berg47846c92009-11-25 17:46:19 +01002757 compare_ether_addr(sdata->vif.addr,
Johannes Berg6032f932008-02-23 15:17:07 +01002758 hdr->addr1) != 0) {
2759 if (!(sdata->dev->flags & IFF_PROMISC))
2760 return 0;
2761
Johannes Berg554891e2010-09-24 12:38:25 +02002762 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg6032f932008-02-23 15:17:07 +01002763 }
2764 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002765 case NL80211_IFTYPE_AP_VLAN:
2766 case NL80211_IFTYPE_AP:
Johannes Berg23a24de2007-07-27 15:43:22 +02002767 if (!bssid) {
Johannes Berg47846c92009-11-25 17:46:19 +01002768 if (compare_ether_addr(sdata->vif.addr,
Johannes Berg23a24de2007-07-27 15:43:22 +02002769 hdr->addr1))
2770 return 0;
2771 } else if (!ieee80211_bssid_match(bssid,
Johannes Berg47846c92009-11-25 17:46:19 +01002772 sdata->vif.addr)) {
Arik Nemtsov771bbd02011-02-01 13:23:05 +02002773 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
Arik Nemtsova21fa872011-08-23 10:21:27 +03002774 !ieee80211_is_beacon(hdr->frame_control) &&
2775 !(ieee80211_is_action(hdr->frame_control) &&
2776 sdata->vif.p2p))
Johannes Berg23a24de2007-07-27 15:43:22 +02002777 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002778 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02002779 }
Johannes Berg23a24de2007-07-27 15:43:22 +02002780 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002781 case NL80211_IFTYPE_WDS:
Harvey Harrisona7767f92008-07-02 16:30:51 -07002782 if (bssid || !ieee80211_is_data(hdr->frame_control))
Johannes Berg23a24de2007-07-27 15:43:22 +02002783 return 0;
2784 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
2785 return 0;
2786 break;
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002787 default:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02002788 /* should never get here */
2789 WARN_ON(1);
2790 break;
Johannes Berg23a24de2007-07-27 15:43:22 +02002791 }
2792
2793 return 1;
2794}
2795
Johannes Berg571ecf62007-07-27 15:43:22 +02002796/*
Johannes Berg4406c372010-09-24 11:21:06 +02002797 * This function returns whether or not the SKB
2798 * was destined for RX processing or not, which,
2799 * if consume is true, is equivalent to whether
2800 * or not the skb was consumed.
2801 */
2802static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
2803 struct sk_buff *skb, bool consume)
2804{
2805 struct ieee80211_local *local = rx->local;
2806 struct ieee80211_sub_if_data *sdata = rx->sdata;
2807 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2808 struct ieee80211_hdr *hdr = (void *)skb->data;
2809 int prepares;
2810
2811 rx->skb = skb;
Johannes Berg554891e2010-09-24 12:38:25 +02002812 status->rx_flags |= IEEE80211_RX_RA_MATCH;
Johannes Berg4406c372010-09-24 11:21:06 +02002813 prepares = prepare_for_handlers(rx, hdr);
2814
2815 if (!prepares)
2816 return false;
2817
Johannes Berg4406c372010-09-24 11:21:06 +02002818 if (!consume) {
2819 skb = skb_copy(skb, GFP_ATOMIC);
2820 if (!skb) {
2821 if (net_ratelimit())
2822 wiphy_debug(local->hw.wiphy,
Ben Greearb305dae2011-01-08 10:30:54 -08002823 "failed to copy skb for %s\n",
Johannes Berg4406c372010-09-24 11:21:06 +02002824 sdata->name);
2825 return true;
2826 }
2827
2828 rx->skb = skb;
2829 }
2830
2831 ieee80211_invoke_rx_handlers(rx);
2832 return true;
2833}
2834
2835/*
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002836 * This is the actual Rx frames handler. as it blongs to Rx path it must
2837 * be called with rcu_read_lock protection.
Johannes Berg571ecf62007-07-27 15:43:22 +02002838 */
Ron Rindjunsky71ebb4aa2008-01-21 12:39:12 +02002839static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
Christian Lamparter071d9ac2010-08-05 01:36:36 +02002840 struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02002841{
Johannes Berg554891e2010-09-24 12:38:25 +02002842 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02002843 struct ieee80211_local *local = hw_to_local(hw);
2844 struct ieee80211_sub_if_data *sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02002845 struct ieee80211_hdr *hdr;
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08002846 __le16 fc;
Johannes Berg5cf121c2008-02-25 16:27:43 +01002847 struct ieee80211_rx_data rx;
Johannes Berg4406c372010-09-24 11:21:06 +02002848 struct ieee80211_sub_if_data *prev;
Ben Greear56af3262010-09-23 10:22:24 -07002849 struct sta_info *sta, *tmp, *prev_sta;
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08002850 int err = 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02002851
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08002852 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
Johannes Berg571ecf62007-07-27 15:43:22 +02002853 memset(&rx, 0, sizeof(rx));
2854 rx.skb = skb;
2855 rx.local = local;
Johannes Berg72abd812007-09-17 01:29:22 -04002856
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08002857 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
Johannes Berg571ecf62007-07-27 15:43:22 +02002858 local->dot11ReceivedFragmentCount++;
Johannes Berg571ecf62007-07-27 15:43:22 +02002859
Helmut Schaa142b9f52009-07-23 13:18:01 +02002860 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
Ben Greearb23b0252011-02-04 11:54:17 -08002861 test_bit(SCAN_SW_SCANNING, &local->scanning)))
Johannes Berg554891e2010-09-24 12:38:25 +02002862 status->rx_flags |= IEEE80211_RX_IN_SCAN;
Johannes Berg571ecf62007-07-27 15:43:22 +02002863
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08002864 if (ieee80211_is_mgmt(fc))
2865 err = skb_linearize(skb);
2866 else
2867 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
2868
2869 if (err) {
2870 dev_kfree_skb(skb);
2871 return;
2872 }
2873
2874 hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg38f37142008-01-29 17:07:43 +01002875 ieee80211_parse_qos(&rx);
Johannes Bergd1c3a372009-01-07 00:26:10 +01002876 ieee80211_verify_alignment(&rx);
Johannes Berg38f37142008-01-29 17:07:43 +01002877
Zhu Yie3cf8b3f2010-03-29 17:35:07 +08002878 if (ieee80211_is_data(fc)) {
Ben Greear56af3262010-09-23 10:22:24 -07002879 prev_sta = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02002880
Guy Eilam2a33bee2011-08-17 15:18:15 +03002881 for_each_sta_info_rx(local, hdr->addr2, sta, tmp) {
Ben Greear56af3262010-09-23 10:22:24 -07002882 if (!prev_sta) {
2883 prev_sta = sta;
2884 continue;
2885 }
2886
2887 rx.sta = prev_sta;
2888 rx.sdata = prev_sta->sdata;
Johannes Berg4406c372010-09-24 11:21:06 +02002889 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Johannes Berg571ecf62007-07-27 15:43:22 +02002890
Ben Greear56af3262010-09-23 10:22:24 -07002891 prev_sta = sta;
Johannes Berg4406c372010-09-24 11:21:06 +02002892 }
Ben Greear56af3262010-09-23 10:22:24 -07002893
2894 if (prev_sta) {
2895 rx.sta = prev_sta;
2896 rx.sdata = prev_sta->sdata;
2897
Johannes Berg4406c372010-09-24 11:21:06 +02002898 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
Ben Greear56af3262010-09-23 10:22:24 -07002899 return;
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05302900 goto out;
Ben Greear56af3262010-09-23 10:22:24 -07002901 }
Johannes Berg4406c372010-09-24 11:21:06 +02002902 }
2903
Johannes Berg4b0dd982010-09-24 11:21:07 +02002904 prev = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02002905
Johannes Berg4b0dd982010-09-24 11:21:07 +02002906 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2907 if (!ieee80211_sdata_running(sdata))
2908 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01002909
Johannes Berg4b0dd982010-09-24 11:21:07 +02002910 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2911 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2912 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01002913
Johannes Berg4b0dd982010-09-24 11:21:07 +02002914 /*
2915 * frame is destined for this interface, but if it's
2916 * not also for the previous one we handle that after
2917 * the loop to avoid copying the SKB once too much
2918 */
Johannes Bergb2e77712007-09-26 15:19:39 +02002919
Johannes Berg4b0dd982010-09-24 11:21:07 +02002920 if (!prev) {
Johannes Berg340e11f2007-07-27 15:43:22 +02002921 prev = sdata;
Johannes Berg4b0dd982010-09-24 11:21:07 +02002922 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02002923 }
Felix Fietkau4bb29f82010-01-22 00:36:39 +01002924
Guy Eilam2a33bee2011-08-17 15:18:15 +03002925 rx.sta = sta_info_get_bss_rx(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02002926 rx.sdata = prev;
2927 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Felix Fietkau4bb29f82010-01-22 00:36:39 +01002928
Johannes Berg4b0dd982010-09-24 11:21:07 +02002929 prev = sdata;
2930 }
Johannes Berg4406c372010-09-24 11:21:06 +02002931
Johannes Berg4b0dd982010-09-24 11:21:07 +02002932 if (prev) {
Guy Eilam2a33bee2011-08-17 15:18:15 +03002933 rx.sta = sta_info_get_bss_rx(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02002934 rx.sdata = prev;
2935
2936 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2937 return;
Johannes Berg571ecf62007-07-27 15:43:22 +02002938 }
Johannes Berg4406c372010-09-24 11:21:06 +02002939
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05302940 out:
Johannes Berg4406c372010-09-24 11:21:06 +02002941 dev_kfree_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02002942}
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002943
2944/*
2945 * This is the receive path handler. It is called by a low level driver when an
2946 * 802.11 MPDU is received from the hardware.
2947 */
John W. Linville103bf9f2009-08-20 16:34:15 -04002948void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002949{
2950 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg8318d782008-01-24 19:38:38 +01002951 struct ieee80211_rate *rate = NULL;
2952 struct ieee80211_supported_band *sband;
Johannes Bergf1d58c22009-06-17 13:13:00 +02002953 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg8318d782008-01-24 19:38:38 +01002954
Johannes Bergd20ef632009-10-11 15:10:40 +02002955 WARN_ON_ONCE(softirq_count() == 0);
2956
Johannes Berg77a980d2009-08-24 11:46:30 +02002957 if (WARN_ON(status->band < 0 ||
2958 status->band >= IEEE80211_NUM_BANDS))
2959 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01002960
2961 sband = local->hw.wiphy->bands[status->band];
Johannes Berg77a980d2009-08-24 11:46:30 +02002962 if (WARN_ON(!sband))
2963 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01002964
Johannes Berg89c3a8a2009-07-28 18:10:17 +02002965 /*
2966 * If we're suspending, it is possible although not too likely
2967 * that we'd be receiving frames after having already partially
2968 * quiesced the stack. We can't process such frames then since
2969 * that might, for example, cause stations to be added or other
2970 * driver callbacks be invoked.
2971 */
Johannes Berg77a980d2009-08-24 11:46:30 +02002972 if (unlikely(local->quiescing || local->suspended))
2973 goto drop;
Johannes Berg89c3a8a2009-07-28 18:10:17 +02002974
Johannes Bergea77f122009-08-21 14:44:45 +02002975 /*
2976 * The same happens when we're not even started,
2977 * but that's worth a warning.
2978 */
Johannes Berg77a980d2009-08-24 11:46:30 +02002979 if (WARN_ON(!local->started))
2980 goto drop;
Johannes Bergea77f122009-08-21 14:44:45 +02002981
Johannes Bergfc885182010-07-30 13:23:12 +02002982 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05002983 /*
Johannes Bergfc885182010-07-30 13:23:12 +02002984 * Validate the rate, unless a PLCP error means that
2985 * we probably can't have a valid rate here anyway.
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05002986 */
Johannes Bergfc885182010-07-30 13:23:12 +02002987
2988 if (status->flag & RX_FLAG_HT) {
2989 /*
2990 * rate_idx is MCS index, which can be [0-76]
2991 * as documented on:
2992 *
2993 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
2994 *
2995 * Anything else would be some sort of driver or
2996 * hardware error. The driver should catch hardware
2997 * errors.
2998 */
2999 if (WARN((status->rate_idx < 0 ||
3000 status->rate_idx > 76),
3001 "Rate marked as an HT rate but passed "
3002 "status->rate_idx is not "
3003 "an MCS index [0-76]: %d (0x%02x)\n",
3004 status->rate_idx,
3005 status->rate_idx))
3006 goto drop;
3007 } else {
3008 if (WARN_ON(status->rate_idx < 0 ||
3009 status->rate_idx >= sband->n_bitrates))
3010 goto drop;
3011 rate = &sband->bitrates[status->rate_idx];
3012 }
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003013 }
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003014
Johannes Berg554891e2010-09-24 12:38:25 +02003015 status->rx_flags = 0;
3016
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003017 /*
3018 * key references and virtual interfaces are protected using RCU
3019 * and this requires that we are in a read-side RCU section during
3020 * receive processing
3021 */
3022 rcu_read_lock();
3023
3024 /*
3025 * Frames with failed FCS/PLCP checksum are not returned,
3026 * all other frames are returned without radiotap header
3027 * if it was previously present.
3028 * Also, frames with less than 16 bytes are dropped.
3029 */
Johannes Bergf1d58c22009-06-17 13:13:00 +02003030 skb = ieee80211_rx_monitor(local, skb, rate);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003031 if (!skb) {
3032 rcu_read_unlock();
3033 return;
3034 }
3035
Johannes Berge1e54062010-11-30 08:58:45 +01003036 ieee80211_tpt_led_trig_rx(local,
3037 ((struct ieee80211_hdr *)skb->data)->frame_control,
3038 skb->len);
Christian Lamparter071d9ac2010-08-05 01:36:36 +02003039 __ieee80211_rx_handle_packet(hw, skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003040
3041 rcu_read_unlock();
Johannes Berg77a980d2009-08-24 11:46:30 +02003042
3043 return;
3044 drop:
3045 kfree_skb(skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003046}
John W. Linville103bf9f2009-08-20 16:34:15 -04003047EXPORT_SYMBOL(ieee80211_rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02003048
3049/* This is a version of the rx handler that can be called from hard irq
3050 * context. Post the skb on the queue and schedule the tasklet */
Johannes Bergf1d58c22009-06-17 13:13:00 +02003051void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02003052{
3053 struct ieee80211_local *local = hw_to_local(hw);
3054
3055 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3056
Johannes Berg571ecf62007-07-27 15:43:22 +02003057 skb->pkt_type = IEEE80211_RX_MSG;
3058 skb_queue_tail(&local->skb_queue, skb);
3059 tasklet_schedule(&local->tasklet);
3060}
3061EXPORT_SYMBOL(ieee80211_rx_irqsafe);