blob: 097b42d286e24cc1cc1b98328727853c73de642d [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>
Johannes Berg571ecf62007-07-27 15:43:22 +020019#include <net/mac80211.h>
20#include <net/ieee80211_radiotap.h>
21
22#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020023#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040024#include "led.h"
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +010025#include "mesh.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020026#include "wep.h"
27#include "wpa.h"
28#include "tkip.h"
29#include "wme.h"
30
Johannes Bergb2e77712007-09-26 15:19:39 +020031/*
32 * monitor mode reception
33 *
34 * This function cleans up the SKB, i.e. it removes all the stuff
35 * only useful for monitoring.
36 */
37static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
Johannes Berg0869aea2009-10-28 10:03:35 +010038 struct sk_buff *skb)
Johannes Bergb2e77712007-09-26 15:19:39 +020039{
Johannes Bergb2e77712007-09-26 15:19:39 +020040 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
41 if (likely(skb->len > FCS_LEN))
Zhu Yie3cf8b32010-03-29 17:35:07 +080042 __pskb_trim(skb, skb->len - FCS_LEN);
Johannes Bergb2e77712007-09-26 15:19:39 +020043 else {
44 /* driver bug */
45 WARN_ON(1);
46 dev_kfree_skb(skb);
47 skb = NULL;
48 }
49 }
50
51 return skb;
52}
53
Johannes Bergf1d58c22009-06-17 13:13:00 +020054static inline int should_drop_frame(struct sk_buff *skb,
Johannes Berg0869aea2009-10-28 10:03:35 +010055 int present_fcs_len)
Johannes Bergb2e77712007-09-26 15:19:39 +020056{
Johannes Bergf1d58c22009-06-17 13:13:00 +020057 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Harvey Harrison182503a2008-06-22 16:45:29 -070058 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Bergb2e77712007-09-26 15:19:39 +020059
60 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
61 return 1;
Johannes Berg0869aea2009-10-28 10:03:35 +010062 if (unlikely(skb->len < 16 + present_fcs_len))
Johannes Bergb2e77712007-09-26 15:19:39 +020063 return 1;
Harvey Harrison87228f52008-06-11 14:21:59 -070064 if (ieee80211_is_ctl(hdr->frame_control) &&
65 !ieee80211_is_pspoll(hdr->frame_control) &&
66 !ieee80211_is_back_req(hdr->frame_control))
Johannes Bergb2e77712007-09-26 15:19:39 +020067 return 1;
68 return 0;
69}
70
Bruno Randolf601ae7f2008-05-08 19:22:43 +020071static int
72ieee80211_rx_radiotap_len(struct ieee80211_local *local,
73 struct ieee80211_rx_status *status)
74{
75 int len;
76
77 /* always present fields */
78 len = sizeof(struct ieee80211_radiotap_header) + 9;
79
Johannes Berg6ebacbb2011-02-23 15:06:08 +010080 if (status->flag & RX_FLAG_MACTIME_MPDU)
Bruno Randolf601ae7f2008-05-08 19:22:43 +020081 len += 8;
Johannes Berg7fee5372009-01-30 11:13:06 +010082 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
Bruno Randolf601ae7f2008-05-08 19:22:43 +020083 len += 1;
Bruno Randolf601ae7f2008-05-08 19:22:43 +020084
85 if (len & 1) /* padding for RX_FLAGS if necessary */
86 len++;
87
Johannes Berg6d744ba2011-01-27 14:13:17 +010088 if (status->flag & RX_FLAG_HT) /* HT info */
89 len += 3;
90
Bruno Randolf601ae7f2008-05-08 19:22:43 +020091 return len;
92}
93
Johannes Bergd1c3a372009-01-07 00:26:10 +010094/*
Bruno Randolf601ae7f2008-05-08 19:22:43 +020095 * ieee80211_add_rx_radiotap_header - add radiotap header
96 *
97 * add a radiotap header containing all the fields which the hardware provided.
98 */
99static void
100ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
101 struct sk_buff *skb,
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200102 struct ieee80211_rate *rate,
103 int rtap_len)
104{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200105 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200106 struct ieee80211_radiotap_header *rthdr;
107 unsigned char *pos;
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100108 u16 rx_flags = 0;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200109
110 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
111 memset(rthdr, 0, rtap_len);
112
113 /* radiotap header, set always present flags */
114 rthdr->it_present =
115 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200116 (1 << IEEE80211_RADIOTAP_CHANNEL) |
117 (1 << IEEE80211_RADIOTAP_ANTENNA) |
118 (1 << IEEE80211_RADIOTAP_RX_FLAGS));
119 rthdr->it_len = cpu_to_le16(rtap_len);
120
121 pos = (unsigned char *)(rthdr+1);
122
123 /* the order of the following fields is important */
124
125 /* IEEE80211_RADIOTAP_TSFT */
Johannes Berg6ebacbb2011-02-23 15:06:08 +0100126 if (status->flag & RX_FLAG_MACTIME_MPDU) {
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100127 put_unaligned_le64(status->mactime, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200128 rthdr->it_present |=
129 cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
130 pos += 8;
131 }
132
133 /* IEEE80211_RADIOTAP_FLAGS */
134 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
135 *pos |= IEEE80211_RADIOTAP_F_FCS;
Johannes Bergaae89832009-03-13 12:52:10 +0100136 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
137 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
Bruno Randolfb4f28bb2008-07-30 17:19:55 +0200138 if (status->flag & RX_FLAG_SHORTPRE)
139 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200140 pos++;
141
142 /* IEEE80211_RADIOTAP_RATE */
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100143 if (!rate || status->flag & RX_FLAG_HT) {
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200144 /*
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100145 * Without rate information don't add it. If we have,
Mohammed Shafi Shajakhan38f37be2011-02-07 10:10:04 +0530146 * MCS information is a separate field in radiotap,
Johannes Berg73b48092011-04-18 17:05:21 +0200147 * added below. The byte here is needed as padding
148 * for the channel though, so initialise it to 0.
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200149 */
150 *pos = 0;
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200151 } else {
Jouni Malinenebe6c7b2009-01-10 11:47:33 +0200152 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200153 *pos = rate->bitrate / 5;
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200154 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200155 pos++;
156
157 /* IEEE80211_RADIOTAP_CHANNEL */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100158 put_unaligned_le16(status->freq, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200159 pos += 2;
160 if (status->band == IEEE80211_BAND_5GHZ)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100161 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
162 pos);
Johannes Berg5f0b7de2009-11-16 13:58:21 +0100163 else if (status->flag & RX_FLAG_HT)
164 put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
165 pos);
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100166 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100167 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
168 pos);
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100169 else if (rate)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100170 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
171 pos);
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100172 else
173 put_unaligned_le16(IEEE80211_CHAN_2GHZ, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200174 pos += 2;
175
176 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
177 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
178 *pos = status->signal;
179 rthdr->it_present |=
180 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
181 pos++;
182 }
183
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200184 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
185
186 /* IEEE80211_RADIOTAP_ANTENNA */
187 *pos = status->antenna;
188 pos++;
189
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200190 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
191
192 /* IEEE80211_RADIOTAP_RX_FLAGS */
193 /* ensure 2 byte alignment for the 2 byte field as required */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100194 if ((pos - (u8 *)rthdr) & 1)
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200195 pos++;
Johannes Bergaae89832009-03-13 12:52:10 +0100196 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100197 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
198 put_unaligned_le16(rx_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200199 pos += 2;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100200
201 if (status->flag & RX_FLAG_HT) {
202 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
203 *pos++ = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
204 IEEE80211_RADIOTAP_MCS_HAVE_GI |
205 IEEE80211_RADIOTAP_MCS_HAVE_BW;
206 *pos = 0;
207 if (status->flag & RX_FLAG_SHORT_GI)
208 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
209 if (status->flag & RX_FLAG_40MHZ)
210 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
211 pos++;
212 *pos++ = status->rate_idx;
213 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200214}
215
Johannes Bergb2e77712007-09-26 15:19:39 +0200216/*
217 * This function copies a received frame to all monitor interfaces and
218 * returns a cleaned-up SKB that no longer includes the FCS nor the
219 * radiotap header the driver might have added.
220 */
221static struct sk_buff *
222ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
Johannes Berg8318d782008-01-24 19:38:38 +0100223 struct ieee80211_rate *rate)
Johannes Bergb2e77712007-09-26 15:19:39 +0200224{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200225 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200226 struct ieee80211_sub_if_data *sdata;
Johannes Bergb2e77712007-09-26 15:19:39 +0200227 int needed_headroom = 0;
Johannes Bergb2e77712007-09-26 15:19:39 +0200228 struct sk_buff *skb, *skb2;
229 struct net_device *prev_dev = NULL;
230 int present_fcs_len = 0;
Johannes Bergb2e77712007-09-26 15:19:39 +0200231
232 /*
233 * First, we may need to make a copy of the skb because
234 * (1) we need to modify it for radiotap (if not present), and
235 * (2) the other RX handlers will modify the skb we got.
236 *
237 * We don't need to, of course, if we aren't going to return
238 * the SKB because it has a bad FCS/PLCP checksum.
239 */
Johannes Berg0869aea2009-10-28 10:03:35 +0100240
241 /* room for the radiotap header based on driver features */
242 needed_headroom = ieee80211_rx_radiotap_len(local, status);
Johannes Bergb2e77712007-09-26 15:19:39 +0200243
244 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
245 present_fcs_len = FCS_LEN;
246
Zhu Yie3cf8b32010-03-29 17:35:07 +0800247 /* make sure hdr->frame_control is on the linear part */
248 if (!pskb_may_pull(origskb, 2)) {
249 dev_kfree_skb(origskb);
250 return NULL;
251 }
252
Johannes Bergb2e77712007-09-26 15:19:39 +0200253 if (!local->monitors) {
Johannes Berg0869aea2009-10-28 10:03:35 +0100254 if (should_drop_frame(origskb, present_fcs_len)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200255 dev_kfree_skb(origskb);
256 return NULL;
257 }
258
Johannes Berg0869aea2009-10-28 10:03:35 +0100259 return remove_monitor_info(local, origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200260 }
261
Johannes Berg0869aea2009-10-28 10:03:35 +0100262 if (should_drop_frame(origskb, present_fcs_len)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200263 /* only need to expand headroom if necessary */
264 skb = origskb;
265 origskb = NULL;
266
267 /*
268 * This shouldn't trigger often because most devices have an
269 * RX header they pull before we get here, and that should
270 * be big enough for our radiotap information. We should
271 * probably export the length to drivers so that we can have
272 * them allocate enough headroom to start with.
273 */
274 if (skb_headroom(skb) < needed_headroom &&
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100275 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200276 dev_kfree_skb(skb);
277 return NULL;
278 }
279 } else {
280 /*
281 * Need to make a copy and possibly remove radiotap header
282 * and FCS from the original.
283 */
284 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
285
Johannes Berg0869aea2009-10-28 10:03:35 +0100286 origskb = remove_monitor_info(local, origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200287
288 if (!skb)
289 return origskb;
290 }
291
Johannes Berg0869aea2009-10-28 10:03:35 +0100292 /* prepend radiotap information */
293 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
Johannes Bergb2e77712007-09-26 15:19:39 +0200294
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100295 skb_reset_mac_header(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200296 skb->ip_summed = CHECKSUM_UNNECESSARY;
297 skb->pkt_type = PACKET_OTHERHOST;
298 skb->protocol = htons(ETH_P_802_2);
299
300 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200301 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
Johannes Bergb2e77712007-09-26 15:19:39 +0200302 continue;
303
Michael Wu3d30d942008-01-31 19:48:27 +0100304 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
305 continue;
306
Johannes Berg9607e6b2009-12-23 13:15:31 +0100307 if (!ieee80211_sdata_running(sdata))
Johannes Berg47846c92009-11-25 17:46:19 +0100308 continue;
309
Johannes Bergb2e77712007-09-26 15:19:39 +0200310 if (prev_dev) {
311 skb2 = skb_clone(skb, GFP_ATOMIC);
312 if (skb2) {
313 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400314 netif_receive_skb(skb2);
Johannes Bergb2e77712007-09-26 15:19:39 +0200315 }
316 }
317
318 prev_dev = sdata->dev;
319 sdata->dev->stats.rx_packets++;
320 sdata->dev->stats.rx_bytes += skb->len;
321 }
322
323 if (prev_dev) {
324 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400325 netif_receive_skb(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200326 } else
327 dev_kfree_skb(skb);
328
329 return origskb;
330}
331
332
Johannes Berg5cf121c2008-02-25 16:27:43 +0100333static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +0200334{
Harvey Harrison238f74a2008-07-02 11:05:34 -0700335 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200336 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg9e262972011-07-07 18:45:03 +0200337 int tid, seqno_idx, security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200338
339 /* does the frame have a qos control field? */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700340 if (ieee80211_is_data_qos(hdr->frame_control)) {
341 u8 *qc = ieee80211_get_qos_ctl(hdr);
Johannes Berg6e0d1142007-07-27 15:43:22 +0200342 /* frame has qos control */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700343 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
Johannes Berg04b7dcf2011-06-22 10:06:59 +0200344 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
Johannes Berg554891e2010-09-24 12:38:25 +0200345 status->rx_flags |= IEEE80211_RX_AMSDU;
Johannes Berg9e262972011-07-07 18:45:03 +0200346
347 seqno_idx = tid;
348 security_idx = tid;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200349 } else {
Johannes Berg1411f9b2008-07-10 10:11:02 +0200350 /*
351 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
352 *
353 * Sequence numbers for management frames, QoS data
354 * frames with a broadcast/multicast address in the
355 * Address 1 field, and all non-QoS data frames sent
356 * by QoS STAs are assigned using an additional single
357 * modulo-4096 counter, [...]
358 *
359 * We also use that counter for non-QoS STAs.
360 */
Johannes Berg9e262972011-07-07 18:45:03 +0200361 seqno_idx = NUM_RX_DATA_QUEUES;
362 security_idx = 0;
363 if (ieee80211_is_mgmt(hdr->frame_control))
364 security_idx = NUM_RX_DATA_QUEUES;
365 tid = 0;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200366 }
Johannes Berg52865dfd2007-07-27 15:43:22 +0200367
Johannes Berg9e262972011-07-07 18:45:03 +0200368 rx->seqno_idx = seqno_idx;
369 rx->security_idx = security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200370 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
371 * For now, set skb->priority to 0 for other cases. */
372 rx->skb->priority = (tid > 7) ? 0 : tid;
Johannes Berg38f37142008-01-29 17:07:43 +0100373}
Johannes Berg6e0d1142007-07-27 15:43:22 +0200374
Johannes Bergd1c3a372009-01-07 00:26:10 +0100375/**
376 * DOC: Packet alignment
377 *
378 * Drivers always need to pass packets that are aligned to two-byte boundaries
379 * to the stack.
380 *
381 * Additionally, should, if possible, align the payload data in a way that
382 * guarantees that the contained IP header is aligned to a four-byte
383 * boundary. In the case of regular frames, this simply means aligning the
384 * payload to a four-byte boundary (because either the IP header is directly
385 * contained, or IV/RFC1042 headers that have a length divisible by four are
Kalle Valo59d9cb02009-12-17 13:54:57 +0100386 * in front of it). If the payload data is not properly aligned and the
387 * architecture doesn't support efficient unaligned operations, mac80211
388 * will align the data.
Johannes Bergd1c3a372009-01-07 00:26:10 +0100389 *
390 * With A-MSDU frames, however, the payload data address must yield two modulo
391 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
392 * push the IP header further back to a multiple of four again. Thankfully, the
393 * specs were sane enough this time around to require padding each A-MSDU
394 * subframe to a length that is a multiple of four.
395 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300396 * Padding like Atheros hardware adds which is between the 802.11 header and
Johannes Bergd1c3a372009-01-07 00:26:10 +0100397 * the payload is not supported, the driver is required to move the 802.11
398 * header to be directly in front of the payload in that case.
399 */
400static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
Johannes Berg38f37142008-01-29 17:07:43 +0100401{
Kalle Valo59d9cb02009-12-17 13:54:57 +0100402#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
403 WARN_ONCE((unsigned long)rx->skb->data & 1,
404 "unaligned packet at 0x%p\n", rx->skb->data);
Johannes Bergd1c3a372009-01-07 00:26:10 +0100405#endif
Johannes Berg6e0d1142007-07-27 15:43:22 +0200406}
407
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +0200408
Johannes Berg571ecf62007-07-27 15:43:22 +0200409/* rx handlers */
410
Johannes Berg49461622008-06-30 15:10:45 +0200411static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100412ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +0200413{
414 struct ieee80211_local *local = rx->local;
Johannes Berg554891e2010-09-24 12:38:25 +0200415 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +0200416 struct sk_buff *skb = rx->skb;
417
Luciano Coelho79f460c2011-05-11 17:09:36 +0300418 if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
419 !local->sched_scanning))
Johannes Berg4080c7c2010-09-24 11:21:08 +0200420 return RX_CONTINUE;
421
Ben Greearb23b0252011-02-04 11:54:17 -0800422 if (test_bit(SCAN_HW_SCANNING, &local->scanning) ||
Luciano Coelho79f460c2011-05-11 17:09:36 +0300423 test_bit(SCAN_SW_SCANNING, &local->scanning) ||
424 local->sched_scanning)
Johannes Bergf1d58c22009-06-17 13:13:00 +0200425 return ieee80211_scan_rx(rx->sdata, skb);
Zhu Yiece8edd2007-11-22 10:53:21 +0800426
Johannes Berg4080c7c2010-09-24 11:21:08 +0200427 /* scanning finished during invoking of handlers */
428 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
429 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200430}
431
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200432
433static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
434{
435 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
436
437 if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
438 return 0;
439
440 return ieee80211_is_robust_mgmt_frame(hdr);
441}
442
443
444static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
445{
446 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
447
448 if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
449 return 0;
450
451 return ieee80211_is_robust_mgmt_frame(hdr);
452}
453
454
455/* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
456static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
457{
458 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
459 struct ieee80211_mmie *mmie;
460
461 if (skb->len < 24 + sizeof(*mmie) ||
462 !is_multicast_ether_addr(hdr->da))
463 return -1;
464
465 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
466 return -1; /* not a robust management frame */
467
468 mmie = (struct ieee80211_mmie *)
469 (skb->data + skb->len - sizeof(*mmie));
470 if (mmie->element_id != WLAN_EID_MMIE ||
471 mmie->length != sizeof(*mmie) - 2)
472 return -1;
473
474 return le16_to_cpu(mmie->key_id);
475}
476
477
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100478static ieee80211_rx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100479ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100480{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700481 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg47846c92009-11-25 17:46:19 +0100482 char *dev_addr = rx->sdata->vif.addr;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100483
Harvey Harrisona7767f92008-07-02 16:30:51 -0700484 if (ieee80211_is_data(hdr->frame_control)) {
Javier Cardona3c5772a2009-08-10 12:15:48 -0700485 if (is_multicast_ether_addr(hdr->addr1)) {
486 if (ieee80211_has_tods(hdr->frame_control) ||
487 !ieee80211_has_fromds(hdr->frame_control))
488 return RX_DROP_MONITOR;
489 if (memcmp(hdr->addr3, dev_addr, ETH_ALEN) == 0)
490 return RX_DROP_MONITOR;
491 } else {
492 if (!ieee80211_has_a4(hdr->frame_control))
493 return RX_DROP_MONITOR;
494 if (memcmp(hdr->addr4, dev_addr, ETH_ALEN) == 0)
495 return RX_DROP_MONITOR;
496 }
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100497 }
498
499 /* If there is not an established peer link and this is not a peer link
500 * establisment frame, beacon or probe, drop the frame.
501 */
502
Javier Cardona57cf8042011-05-13 10:45:43 -0700503 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100504 struct ieee80211_mgmt *mgmt;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100505
Harvey Harrisona7767f92008-07-02 16:30:51 -0700506 if (!ieee80211_is_mgmt(hdr->frame_control))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100507 return RX_DROP_MONITOR;
508
Harvey Harrisona7767f92008-07-02 16:30:51 -0700509 if (ieee80211_is_action(hdr->frame_control)) {
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700510 u8 category;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100511 mgmt = (struct ieee80211_mgmt *)hdr;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700512 category = mgmt->u.action.category;
513 if (category != WLAN_CATEGORY_MESH_ACTION &&
514 category != WLAN_CATEGORY_SELF_PROTECTED)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100515 return RX_DROP_MONITOR;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100516 return RX_CONTINUE;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100517 }
518
Harvey Harrisona7767f92008-07-02 16:30:51 -0700519 if (ieee80211_is_probe_req(hdr->frame_control) ||
520 ieee80211_is_probe_resp(hdr->frame_control) ||
Javier Cardona71839122011-04-07 15:08:31 -0700521 ieee80211_is_beacon(hdr->frame_control) ||
522 ieee80211_is_auth(hdr->frame_control))
Harvey Harrisona7767f92008-07-02 16:30:51 -0700523 return RX_CONTINUE;
524
525 return RX_DROP_MONITOR;
526
527 }
528
Johannes Berg902acc72008-02-23 15:17:19 +0100529 return RX_CONTINUE;
530}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100531
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100532#define SEQ_MODULO 0x1000
533#define SEQ_MASK 0xfff
534
535static inline int seq_less(u16 sq1, u16 sq2)
536{
537 return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1);
538}
539
540static inline u16 seq_inc(u16 sq)
541{
542 return (sq + 1) & SEQ_MASK;
543}
544
545static inline u16 seq_sub(u16 sq1, u16 sq2)
546{
547 return (sq1 - sq2) & SEQ_MASK;
548}
549
550
551static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
552 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100553 int index)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100554{
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100555 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100556 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
Christian Lamparter4cfda472010-12-27 23:21:26 +0100557 struct ieee80211_rx_status *status;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100558
Johannes Bergdd318572010-11-29 11:09:16 +0100559 lockdep_assert_held(&tid_agg_rx->reorder_lock);
560
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100561 if (!skb)
562 goto no_frame;
563
Christian Lamparter071d9ac2010-08-05 01:36:36 +0200564 /* release the frame from the reorder ring buffer */
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100565 tid_agg_rx->stored_mpdu_num--;
566 tid_agg_rx->reorder_buf[index] = NULL;
Christian Lamparter4cfda472010-12-27 23:21:26 +0100567 status = IEEE80211_SKB_RXCB(skb);
568 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100569 skb_queue_tail(&local->rx_skb_queue, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100570
571no_frame:
572 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
573}
574
575static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw,
576 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100577 u16 head_seq_num)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100578{
579 int index;
580
Johannes Bergdd318572010-11-29 11:09:16 +0100581 lockdep_assert_held(&tid_agg_rx->reorder_lock);
582
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100583 while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
584 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
585 tid_agg_rx->buf_size;
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100586 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100587 }
588}
589
590/*
591 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
592 * the skb was added to the buffer longer than this time ago, the earlier
593 * frames that have not yet been received are assumed to be lost and the skb
594 * can be released for processing. This may also release other skb's from the
595 * reorder buffer if there are no additional gaps between the frames.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200596 *
597 * Callers must hold tid_agg_rx->reorder_lock.
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100598 */
599#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
600
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200601static void ieee80211_sta_reorder_release(struct ieee80211_hw *hw,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100602 struct tid_ampdu_rx *tid_agg_rx)
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200603{
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200604 int index, j;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200605
Johannes Bergdd318572010-11-29 11:09:16 +0100606 lockdep_assert_held(&tid_agg_rx->reorder_lock);
607
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200608 /* release the buffer until next missing frame */
609 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
610 tid_agg_rx->buf_size;
611 if (!tid_agg_rx->reorder_buf[index] &&
612 tid_agg_rx->stored_mpdu_num > 1) {
613 /*
614 * No buffers ready to be released, but check whether any
615 * frames in the reorder buffer have timed out.
616 */
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200617 int skipped = 1;
618 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
619 j = (j + 1) % tid_agg_rx->buf_size) {
620 if (!tid_agg_rx->reorder_buf[j]) {
621 skipped++;
622 continue;
623 }
Daniel Halperin499fe9a2011-03-24 16:01:48 -0700624 if (skipped &&
625 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200626 HT_RX_REORDER_BUF_TIMEOUT))
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200627 goto set_release_timer;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200628
629#ifdef CONFIG_MAC80211_HT_DEBUG
630 if (net_ratelimit())
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700631 wiphy_debug(hw->wiphy,
632 "release an RX reorder frame due to timeout on earlier frames\n");
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200633#endif
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100634 ieee80211_release_reorder_frame(hw, tid_agg_rx, j);
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200635
636 /*
637 * Increment the head seq# also for the skipped slots.
638 */
639 tid_agg_rx->head_seq_num =
640 (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK;
641 skipped = 0;
642 }
643 } else while (tid_agg_rx->reorder_buf[index]) {
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100644 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200645 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) %
646 tid_agg_rx->buf_size;
647 }
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200648
649 if (tid_agg_rx->stored_mpdu_num) {
650 j = index = seq_sub(tid_agg_rx->head_seq_num,
651 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
652
653 for (; j != (index - 1) % tid_agg_rx->buf_size;
654 j = (j + 1) % tid_agg_rx->buf_size) {
655 if (tid_agg_rx->reorder_buf[j])
656 break;
657 }
658
659 set_release_timer:
660
661 mod_timer(&tid_agg_rx->reorder_timer,
Christian Lamparter334df732011-04-24 20:41:16 +0200662 tid_agg_rx->reorder_time[j] + 1 +
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200663 HT_RX_REORDER_BUF_TIMEOUT);
664 } else {
665 del_timer(&tid_agg_rx->reorder_timer);
666 }
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200667}
668
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100669/*
670 * As this function belongs to the RX path it must be under
671 * rcu_read_lock protection. It returns false if the frame
672 * can be processed immediately, true if it was consumed.
673 */
674static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
675 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100676 struct sk_buff *skb)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100677{
678 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
679 u16 sc = le16_to_cpu(hdr->seq_ctrl);
680 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
681 u16 head_seq_num, buf_size;
682 int index;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200683 bool ret = true;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100684
Johannes Bergdd318572010-11-29 11:09:16 +0100685 spin_lock(&tid_agg_rx->reorder_lock);
686
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100687 buf_size = tid_agg_rx->buf_size;
688 head_seq_num = tid_agg_rx->head_seq_num;
689
690 /* frame with out of date sequence number */
691 if (seq_less(mpdu_seq_num, head_seq_num)) {
692 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200693 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100694 }
695
696 /*
697 * If frame the sequence number exceeds our buffering window
698 * size release some previous frames to make room for this one.
699 */
700 if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) {
701 head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size));
702 /* release stored frames up to new head to stack */
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100703 ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100704 }
705
706 /* Now the new frame is always in the range of the reordering buffer */
707
708 index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size;
709
710 /* check if we already stored this frame */
711 if (tid_agg_rx->reorder_buf[index]) {
712 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200713 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100714 }
715
716 /*
717 * If the current MPDU is in the right order and nothing else
718 * is stored we can process it directly, no need to buffer it.
Johannes Bergc835b212011-03-15 23:17:01 +0100719 * If it is first but there's something stored, we may be able
720 * to release frames after this one.
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100721 */
722 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
723 tid_agg_rx->stored_mpdu_num == 0) {
724 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200725 ret = false;
726 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100727 }
728
729 /* put the frame in the reordering buffer */
730 tid_agg_rx->reorder_buf[index] = skb;
731 tid_agg_rx->reorder_time[index] = jiffies;
732 tid_agg_rx->stored_mpdu_num++;
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100733 ieee80211_sta_reorder_release(hw, tid_agg_rx);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100734
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200735 out:
736 spin_unlock(&tid_agg_rx->reorder_lock);
737 return ret;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100738}
739
740/*
741 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
742 * true if the MPDU was buffered, false if it should be processed.
743 */
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100744static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100745{
Johannes Berg2569a822009-11-25 17:46:17 +0100746 struct sk_buff *skb = rx->skb;
747 struct ieee80211_local *local = rx->local;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100748 struct ieee80211_hw *hw = &local->hw;
749 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Johannes Berg2569a822009-11-25 17:46:17 +0100750 struct sta_info *sta = rx->sta;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100751 struct tid_ampdu_rx *tid_agg_rx;
752 u16 sc;
753 int tid;
754
755 if (!ieee80211_is_data_qos(hdr->frame_control))
Johannes Berg2569a822009-11-25 17:46:17 +0100756 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100757
758 /*
759 * filter the QoS data rx stream according to
760 * STA/TID and check if this STA/TID is on aggregation
761 */
762
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100763 if (!sta)
Johannes Berg2569a822009-11-25 17:46:17 +0100764 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100765
766 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
767
Johannes Berga87f7362010-06-10 10:21:38 +0200768 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
769 if (!tid_agg_rx)
770 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100771
772 /* qos null data frames are excluded */
773 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
Johannes Berga87f7362010-06-10 10:21:38 +0200774 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100775
776 /* new, potentially un-ordered, ampdu frame - process it */
777
778 /* reset session timer */
779 if (tid_agg_rx->timeout)
780 mod_timer(&tid_agg_rx->session_timer,
781 TU_TO_EXP_TIME(tid_agg_rx->timeout));
782
783 /* if this mpdu is fragmented - terminate rx aggregation session */
784 sc = le16_to_cpu(hdr->seq_ctrl);
785 if (sc & IEEE80211_SCTL_FRAG) {
Johannes Bergc1475ca2010-06-10 10:21:37 +0200786 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg344eec62010-06-10 10:21:36 +0200787 skb_queue_tail(&rx->sdata->skb_queue, skb);
788 ieee80211_queue_work(&local->hw, &rx->sdata->work);
Johannes Berg2569a822009-11-25 17:46:17 +0100789 return;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100790 }
791
Johannes Berga87f7362010-06-10 10:21:38 +0200792 /*
793 * No locking needed -- we will only ever process one
794 * RX packet at a time, and thus own tid_agg_rx. All
795 * other code manipulating it needs to (and does) make
796 * sure that we cannot get to it any more before doing
797 * anything with it.
798 */
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100799 if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb))
Johannes Berg2569a822009-11-25 17:46:17 +0100800 return;
801
802 dont_reorder:
Christian Lamparter24a8fda2010-12-30 17:25:29 +0100803 skb_queue_tail(&local->rx_skb_queue, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100804}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100805
Johannes Berg49461622008-06-30 15:10:45 +0200806static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100807ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +0200808{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700809 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200810 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +0200811
812 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
813 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
Harvey Harrisona7767f92008-07-02 16:30:51 -0700814 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
Johannes Berg9e262972011-07-07 18:45:03 +0200815 rx->sta->last_seq_ctrl[rx->seqno_idx] ==
Johannes Berg571ecf62007-07-27 15:43:22 +0200816 hdr->seq_ctrl)) {
Johannes Berg554891e2010-09-24 12:38:25 +0200817 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200818 rx->local->dot11FrameDuplicateCount++;
819 rx->sta->num_duplicates++;
820 }
Felix Fietkaub1f93312011-02-04 19:20:08 +0100821 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200822 } else
Johannes Berg9e262972011-07-07 18:45:03 +0200823 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
Johannes Berg571ecf62007-07-27 15:43:22 +0200824 }
825
Johannes Berg571ecf62007-07-27 15:43:22 +0200826 if (unlikely(rx->skb->len < 16)) {
827 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100828 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200829 }
830
Johannes Berg571ecf62007-07-27 15:43:22 +0200831 /* Drop disallowed frame classes based on STA auth/assoc state;
832 * IEEE 802.11, Chap 5.5.
833 *
Johannes Bergccd7b362008-09-11 00:01:56 +0200834 * mac80211 filters only based on association state, i.e. it drops
835 * Class 3 frames from not associated stations. hostapd sends
Johannes Berg571ecf62007-07-27 15:43:22 +0200836 * deauth/disassoc frames when needed. In addition, hostapd is
837 * responsible for filtering on both auth and assoc states.
838 */
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100839
Johannes Berg902acc72008-02-23 15:17:19 +0100840 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100841 return ieee80211_rx_mesh_check(rx);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100842
Harvey Harrisona7767f92008-07-02 16:30:51 -0700843 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
844 ieee80211_is_pspoll(hdr->frame_control)) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200845 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Bill Jordan1be7fe82010-10-01 11:20:41 -0400846 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200847 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
Guy Eilam2a33bee2011-08-17 15:18:15 +0300848 if (rx->sta && rx->sta->dummy &&
849 ieee80211_is_data_present(hdr->frame_control)) {
850 u16 ethertype;
851 u8 *payload;
852
853 payload = rx->skb->data +
854 ieee80211_hdrlen(hdr->frame_control);
855 ethertype = (payload[6] << 8) | payload[7];
856 if (cpu_to_be16(ethertype) ==
857 rx->sdata->control_port_protocol)
858 return RX_CONTINUE;
859 }
Johannes Berge4c26ad2008-01-31 19:48:21 +0100860 return RX_DROP_MONITOR;
Guy Eilam2a33bee2011-08-17 15:18:15 +0300861 }
Johannes Berg571ecf62007-07-27 15:43:22 +0200862
Johannes Berg9ae54c82008-01-31 19:48:20 +0100863 return RX_CONTINUE;
Johannes Berg570bd532007-07-27 15:43:22 +0200864}
865
866
Johannes Berg49461622008-06-30 15:10:45 +0200867static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100868ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
Johannes Berg570bd532007-07-27 15:43:22 +0200869{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +0100870 struct sk_buff *skb = rx->skb;
871 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
872 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg3017b802007-08-28 17:01:53 -0400873 int keyidx;
874 int hdrlen;
Johannes Berge4c26ad2008-01-31 19:48:21 +0100875 ieee80211_rx_result result = RX_DROP_UNUSABLE;
Johannes Berge31b8212010-10-05 19:39:30 +0200876 struct ieee80211_key *sta_ptk = NULL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200877 int mmie_keyidx = -1;
Johannes Berg761ab472010-05-28 14:24:19 +0200878 __le16 fc;
Johannes Berg570bd532007-07-27 15:43:22 +0200879
Johannes Berg3017b802007-08-28 17:01:53 -0400880 /*
881 * Key selection 101
882 *
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200883 * There are four types of keys:
Johannes Berg3017b802007-08-28 17:01:53 -0400884 * - GTK (group keys)
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200885 * - IGTK (group keys for management frames)
Johannes Berg3017b802007-08-28 17:01:53 -0400886 * - PTK (pairwise keys)
887 * - STK (station-to-station pairwise keys)
888 *
889 * When selecting a key, we have to distinguish between multicast
890 * (including broadcast) and unicast frames, the latter can only
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200891 * use PTKs and STKs while the former always use GTKs and IGTKs.
892 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
893 * unicast frames can also use key indices like GTKs. Hence, if we
894 * don't have a PTK/STK we check the key index for a WEP key.
Johannes Berg3017b802007-08-28 17:01:53 -0400895 *
Johannes Berg8dc06a12007-08-28 17:01:55 -0400896 * Note that in a regular BSS, multicast frames are sent by the
897 * AP only, associated stations unicast the frame to the AP first
898 * which then multicasts it on their behalf.
899 *
Johannes Berg3017b802007-08-28 17:01:53 -0400900 * There is also a slight problem in IBSS mode: GTKs are negotiated
901 * with each station, that is something we don't currently handle.
Johannes Berg8dc06a12007-08-28 17:01:55 -0400902 * The spec seems to expect that one negotiates the same key with
903 * every station but there's no such requirement; VLANs could be
904 * possible.
Johannes Berg3017b802007-08-28 17:01:53 -0400905 */
Johannes Berg571ecf62007-07-27 15:43:22 +0200906
Johannes Berg3017b802007-08-28 17:01:53 -0400907 /*
Johannes Berg1990af82007-09-26 17:53:15 +0200908 * No point in finding a key and decrypting if the frame is neither
Johannes Berg3017b802007-08-28 17:01:53 -0400909 * addressed to us nor a multicast frame.
910 */
Johannes Berg554891e2010-09-24 12:38:25 +0200911 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100912 return RX_CONTINUE;
Johannes Berg3017b802007-08-28 17:01:53 -0400913
Johannes Berg2569a822009-11-25 17:46:17 +0100914 /* start without a key */
915 rx->key = NULL;
916
Johannes Bergd4e46a32007-09-14 11:10:24 -0400917 if (rx->sta)
Johannes Berge31b8212010-10-05 19:39:30 +0200918 sta_ptk = rcu_dereference(rx->sta->ptk);
Johannes Bergd4e46a32007-09-14 11:10:24 -0400919
Johannes Berg761ab472010-05-28 14:24:19 +0200920 fc = hdr->frame_control;
921
922 if (!ieee80211_has_protected(fc))
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300923 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
924
Johannes Berge31b8212010-10-05 19:39:30 +0200925 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
926 rx->key = sta_ptk;
Johannes Bergdc1580d2010-08-10 09:46:40 +0200927 if ((status->flag & RX_FLAG_DECRYPTED) &&
928 (status->flag & RX_FLAG_IV_STRIPPED))
929 return RX_CONTINUE;
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300930 /* Skip decryption if the frame is not protected. */
Johannes Berg761ab472010-05-28 14:24:19 +0200931 if (!ieee80211_has_protected(fc))
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300932 return RX_CONTINUE;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200933 } else if (mmie_keyidx >= 0) {
934 /* Broadcast/multicast robust management frame / BIP */
Johannes Bergeb9fb5b2009-11-16 13:58:20 +0100935 if ((status->flag & RX_FLAG_DECRYPTED) &&
936 (status->flag & RX_FLAG_IV_STRIPPED))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200937 return RX_CONTINUE;
938
939 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
940 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
941 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
Johannes Berge31b8212010-10-05 19:39:30 +0200942 if (rx->sta)
943 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
944 if (!rx->key)
945 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
Johannes Berg761ab472010-05-28 14:24:19 +0200946 } else if (!ieee80211_has_protected(fc)) {
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300947 /*
948 * The frame was not protected, so skip decryption. However, we
949 * need to set rx->key if there is a key that could have been
950 * used so that the frame may be dropped if encryption would
951 * have been expected.
952 */
953 struct ieee80211_key *key = NULL;
Johannes Berg897bed82010-12-09 19:49:00 +0100954 struct ieee80211_sub_if_data *sdata = rx->sdata;
955 int i;
956
Johannes Berg761ab472010-05-28 14:24:19 +0200957 if (ieee80211_is_mgmt(fc) &&
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300958 is_multicast_ether_addr(hdr->addr1) &&
959 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
960 rx->key = key;
Johannes Berg897bed82010-12-09 19:49:00 +0100961 else {
962 if (rx->sta) {
963 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
964 key = rcu_dereference(rx->sta->gtk[i]);
965 if (key)
966 break;
967 }
968 }
969 if (!key) {
970 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
971 key = rcu_dereference(sdata->keys[i]);
972 if (key)
973 break;
974 }
975 }
976 if (key)
977 rx->key = key;
978 }
Jouni Malinen0c7c10c2009-05-08 12:34:10 +0300979 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200980 } else {
Zhu Yi39184b12010-04-08 15:35:10 +0800981 u8 keyid;
Johannes Berg3017b802007-08-28 17:01:53 -0400982 /*
983 * The device doesn't give us the IV so we won't be
984 * able to look up the key. That's ok though, we
985 * don't need to decrypt the frame, we just won't
986 * be able to keep statistics accurate.
987 * Except for key threshold notifications, should
988 * we somehow allow the driver to tell us which key
989 * the hardware used if this flag is set?
990 */
Johannes Bergeb9fb5b2009-11-16 13:58:20 +0100991 if ((status->flag & RX_FLAG_DECRYPTED) &&
992 (status->flag & RX_FLAG_IV_STRIPPED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100993 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +0200994
Johannes Berg761ab472010-05-28 14:24:19 +0200995 hdrlen = ieee80211_hdrlen(fc);
Johannes Berg571ecf62007-07-27 15:43:22 +0200996
Johannes Berg3017b802007-08-28 17:01:53 -0400997 if (rx->skb->len < 8 + hdrlen)
Johannes Berge4c26ad2008-01-31 19:48:21 +0100998 return RX_DROP_UNUSABLE; /* TODO: count this? */
Johannes Berg571ecf62007-07-27 15:43:22 +0200999
Johannes Berg3017b802007-08-28 17:01:53 -04001000 /*
1001 * no need to call ieee80211_wep_get_keyidx,
1002 * it verifies a bunch of things we've done already
1003 */
Zhu Yi39184b12010-04-08 15:35:10 +08001004 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1005 keyidx = keyid >> 6;
Johannes Berg3017b802007-08-28 17:01:53 -04001006
Johannes Berge31b8212010-10-05 19:39:30 +02001007 /* check per-station GTK first, if multicast packet */
1008 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1009 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
Johannes Berg3017b802007-08-28 17:01:53 -04001010
Johannes Berge31b8212010-10-05 19:39:30 +02001011 /* if not found, try default key */
1012 if (!rx->key) {
1013 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1014
1015 /*
1016 * RSNA-protected unicast frames should always be
1017 * sent with pairwise or station-to-station keys,
1018 * but for WEP we allow using a key index as well.
1019 */
1020 if (rx->key &&
1021 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1022 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1023 !is_multicast_ether_addr(hdr->addr1))
1024 rx->key = NULL;
1025 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001026 }
1027
Johannes Berg3017b802007-08-28 17:01:53 -04001028 if (rx->key) {
Johannes Berg95acac62011-07-12 12:30:59 +02001029 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1030 return RX_DROP_MONITOR;
1031
Johannes Berg571ecf62007-07-27 15:43:22 +02001032 rx->key->tx_rx_count++;
Johannes Berg011bfcc2007-09-17 01:29:25 -04001033 /* TODO: add threshold stuff again */
Johannes Berg1990af82007-09-26 17:53:15 +02001034 } else {
Johannes Berge4c26ad2008-01-31 19:48:21 +01001035 return RX_DROP_MONITOR;
Johannes Berg70f08762007-09-26 17:53:14 +02001036 }
1037
Zhu Yi39184b12010-04-08 15:35:10 +08001038 if (skb_linearize(rx->skb))
1039 return RX_DROP_UNUSABLE;
Johannes Berg761ab472010-05-28 14:24:19 +02001040 /* the hdr variable is invalid now! */
Johannes Berg1990af82007-09-26 17:53:15 +02001041
Johannes Berg97359d12010-08-10 09:46:38 +02001042 switch (rx->key->conf.cipher) {
1043 case WLAN_CIPHER_SUITE_WEP40:
1044 case WLAN_CIPHER_SUITE_WEP104:
Johannes Berg761ab472010-05-28 14:24:19 +02001045 /* Check for weak IVs if possible */
1046 if (rx->sta && ieee80211_is_data(fc) &&
1047 (!(status->flag & RX_FLAG_IV_STRIPPED) ||
1048 !(status->flag & RX_FLAG_DECRYPTED)) &&
1049 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
1050 rx->sta->wep_weak_iv_count++;
1051
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001052 result = ieee80211_crypto_wep_decrypt(rx);
1053 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001054 case WLAN_CIPHER_SUITE_TKIP:
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001055 result = ieee80211_crypto_tkip_decrypt(rx);
1056 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001057 case WLAN_CIPHER_SUITE_CCMP:
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001058 result = ieee80211_crypto_ccmp_decrypt(rx);
1059 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001060 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001061 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1062 break;
Johannes Berg3ffc2a92010-08-27 14:26:52 +03001063 default:
1064 /*
1065 * We can reach here only with HW-only algorithms
1066 * but why didn't it decrypt the frame?!
1067 */
1068 return RX_DROP_UNUSABLE;
Johannes Berg70f08762007-09-26 17:53:14 +02001069 }
1070
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001071 /* either the frame has been decrypted or will be dropped */
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001072 status->flag |= RX_FLAG_DECRYPTED;
Mattias Nisslere2f036d2007-10-07 16:35:31 +02001073
1074 return result;
Johannes Berg70f08762007-09-26 17:53:14 +02001075}
1076
Kalle Valo572e0012009-02-10 17:09:31 +02001077static ieee80211_rx_result debug_noinline
1078ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1079{
1080 struct ieee80211_local *local;
1081 struct ieee80211_hdr *hdr;
1082 struct sk_buff *skb;
1083
1084 local = rx->local;
1085 skb = rx->skb;
1086 hdr = (struct ieee80211_hdr *) skb->data;
1087
1088 if (!local->pspolling)
1089 return RX_CONTINUE;
1090
1091 if (!ieee80211_has_fromds(hdr->frame_control))
1092 /* this is not from AP */
1093 return RX_CONTINUE;
1094
1095 if (!ieee80211_is_data(hdr->frame_control))
1096 return RX_CONTINUE;
1097
1098 if (!ieee80211_has_moredata(hdr->frame_control)) {
1099 /* AP has no more frames buffered for us */
1100 local->pspolling = false;
1101 return RX_CONTINUE;
1102 }
1103
1104 /* more data bit is set, let's request a new frame from the AP */
1105 ieee80211_send_pspoll(local, rx->sdata);
1106
1107 return RX_CONTINUE;
1108}
1109
Johannes Berg133b8222008-09-16 14:18:59 +02001110static void ap_sta_ps_start(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001111{
Johannes Berg133b8222008-09-16 14:18:59 +02001112 struct ieee80211_sub_if_data *sdata = sta->sdata;
Christian Lamparter4571d3b2008-11-30 00:48:41 +01001113 struct ieee80211_local *local = sdata->local;
Joe Perches0795af52007-10-03 17:59:30 -07001114
Johannes Berg3e122be2008-07-09 14:40:34 +02001115 atomic_inc(&sdata->bss->num_sta_ps);
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001116 set_sta_flag(sta, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001117 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1118 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001119#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Johannes Berg0c68ae262008-10-27 15:56:10 -07001120 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001121 sdata->name, sta->sta.addr, sta->sta.aid);
Johannes Berg571ecf62007-07-27 15:43:22 +02001122#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1123}
1124
Johannes Bergff9458d2009-10-30 12:56:02 +01001125static void ap_sta_ps_end(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001126{
Johannes Berg133b8222008-09-16 14:18:59 +02001127 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02001128
Johannes Berg3e122be2008-07-09 14:40:34 +02001129 atomic_dec(&sdata->bss->num_sta_ps);
Johannes Berg004c8722008-02-20 11:21:35 +01001130
Johannes Berg571ecf62007-07-27 15:43:22 +02001131#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Johannes Berg0c68ae262008-10-27 15:56:10 -07001132 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001133 sdata->name, sta->sta.addr, sta->sta.aid);
Johannes Berg571ecf62007-07-27 15:43:22 +02001134#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Berg004c8722008-02-20 11:21:35 +01001135
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001136 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001137#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Johannes Bergaf818582009-11-06 11:35:50 +01001138 printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001139 sdata->name, sta->sta.addr, sta->sta.aid);
Johannes Berg571ecf62007-07-27 15:43:22 +02001140#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Bergaf818582009-11-06 11:35:50 +01001141 return;
1142 }
1143
1144 ieee80211_sta_ps_deliver_wakeup(sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001145}
1146
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001147int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1148{
1149 struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1150 bool in_ps;
1151
1152 WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
1153
1154 /* Don't let the same PS state be set twice */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001155 in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001156 if ((start && in_ps) || (!start && !in_ps))
1157 return -EINVAL;
1158
1159 if (start)
1160 ap_sta_ps_start(sta_inf);
1161 else
1162 ap_sta_ps_end(sta_inf);
1163
1164 return 0;
1165}
1166EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1167
Johannes Berg49461622008-06-30 15:10:45 +02001168static ieee80211_rx_result debug_noinline
Johannes Berg47086fc2011-09-29 16:04:33 +02001169ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1170{
1171 struct ieee80211_sub_if_data *sdata = rx->sdata;
1172 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1173 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1174 int tid, ac;
1175
1176 if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH))
1177 return RX_CONTINUE;
1178
1179 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1180 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1181 return RX_CONTINUE;
1182
1183 /*
1184 * The device handles station powersave, so don't do anything about
1185 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1186 * it to mac80211 since they're handled.)
1187 */
1188 if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
1189 return RX_CONTINUE;
1190
1191 /*
1192 * Don't do anything if the station isn't already asleep. In
1193 * the uAPSD case, the station will probably be marked asleep,
1194 * in the PS-Poll case the station must be confused ...
1195 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001196 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
Johannes Berg47086fc2011-09-29 16:04:33 +02001197 return RX_CONTINUE;
1198
1199 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001200 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1201 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
Johannes Bergdeeaee12011-09-29 16:04:35 +02001202 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1203 else
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001204 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
Johannes Bergdeeaee12011-09-29 16:04:35 +02001205 }
Johannes Berg47086fc2011-09-29 16:04:33 +02001206
1207 /* Free PS Poll skb here instead of returning RX_DROP that would
1208 * count as an dropped frame. */
1209 dev_kfree_skb(rx->skb);
1210
1211 return RX_QUEUED;
1212 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1213 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1214 ieee80211_has_pm(hdr->frame_control) &&
1215 (ieee80211_is_data_qos(hdr->frame_control) ||
1216 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1217 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1218 ac = ieee802_1d_to_ac[tid & 7];
1219
1220 /*
1221 * If this AC is not trigger-enabled do nothing.
1222 *
1223 * NB: This could/should check a separate bitmap of trigger-
1224 * enabled queues, but for now we only implement uAPSD w/o
1225 * TSPEC changes to the ACs, so they're always the same.
1226 */
1227 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1228 return RX_CONTINUE;
1229
1230 /* if we are in a service period, do nothing */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001231 if (test_sta_flag(rx->sta, WLAN_STA_SP))
Johannes Berg47086fc2011-09-29 16:04:33 +02001232 return RX_CONTINUE;
1233
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001234 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
Johannes Berg47086fc2011-09-29 16:04:33 +02001235 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1236 else
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001237 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
Johannes Berg47086fc2011-09-29 16:04:33 +02001238 }
1239
1240 return RX_CONTINUE;
1241}
1242
1243static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001244ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001245{
1246 struct sta_info *sta = rx->sta;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001247 struct sk_buff *skb = rx->skb;
1248 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1249 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001250
1251 if (!sta)
Johannes Berg9ae54c82008-01-31 19:48:20 +01001252 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001253
Johannes Bergb291ba12009-07-10 15:29:03 +02001254 /*
1255 * Update last_rx only for IBSS packets which are for the current
1256 * BSSID to avoid keeping the current IBSS network alive in cases
1257 * where other STAs start using different BSSID.
1258 */
Johannes Berg05c914f2008-09-11 00:01:58 +02001259 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Ron Rindjunsky71364712007-12-25 17:00:36 +02001260 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
Johannes Berg05c914f2008-09-11 00:01:58 +02001261 NL80211_IFTYPE_ADHOC);
Felix Fietkau3af63342011-02-27 22:08:01 +01001262 if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001263 sta->last_rx = jiffies;
Felix Fietkau3af63342011-02-27 22:08:01 +01001264 if (ieee80211_is_data(hdr->frame_control)) {
1265 sta->last_rx_rate_idx = status->rate_idx;
1266 sta->last_rx_rate_flag = status->flag;
1267 }
1268 }
Johannes Bergb291ba12009-07-10 15:29:03 +02001269 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1270 /*
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001271 * Mesh beacons will update last_rx when if they are found to
1272 * match the current local configuration when processed.
Johannes Berg571ecf62007-07-27 15:43:22 +02001273 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001274 sta->last_rx = jiffies;
Felix Fietkau3af63342011-02-27 22:08:01 +01001275 if (ieee80211_is_data(hdr->frame_control)) {
1276 sta->last_rx_rate_idx = status->rate_idx;
1277 sta->last_rx_rate_flag = status->flag;
1278 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001279 }
1280
Johannes Berg554891e2010-09-24 12:38:25 +02001281 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001282 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001283
Kalle Valo3cf335d2009-03-22 21:57:06 +02001284 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1285 ieee80211_sta_rx_notify(rx->sdata, hdr);
1286
Johannes Berg571ecf62007-07-27 15:43:22 +02001287 sta->rx_fragments++;
1288 sta->rx_bytes += rx->skb->len;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001289 sta->last_signal = status->signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +09001290 ewma_add(&sta->avg_signal, -status->signal);
Johannes Berg571ecf62007-07-27 15:43:22 +02001291
Johannes Berg72eaa432008-11-26 15:02:58 +01001292 /*
1293 * Change STA power saving mode only at the end of a frame
1294 * exchange sequence.
1295 */
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001296 if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
1297 !ieee80211_has_morefrags(hdr->frame_control) &&
Christian Lamparter4cfda472010-12-27 23:21:26 +01001298 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001299 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1300 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001301 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
Johannes Berg72eaa432008-11-26 15:02:58 +01001302 /*
1303 * Ignore doze->wake transitions that are
1304 * indicated by non-data frames, the standard
1305 * is unclear here, but for example going to
1306 * PS mode and then scanning would cause a
1307 * doze->wake transition for the probe request,
1308 * and that is clearly undesirable.
1309 */
1310 if (ieee80211_is_data(hdr->frame_control) &&
1311 !ieee80211_has_pm(hdr->frame_control))
Johannes Bergff9458d2009-10-30 12:56:02 +01001312 ap_sta_ps_end(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001313 } else {
1314 if (ieee80211_has_pm(hdr->frame_control))
1315 ap_sta_ps_start(sta);
1316 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001317 }
1318
Johannes Berg22403de2009-10-30 12:55:03 +01001319 /*
1320 * Drop (qos-)data::nullfunc frames silently, since they
1321 * are used only to control station power saving mode.
1322 */
1323 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1324 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001325 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
Felix Fietkaud5242152010-01-08 18:06:26 +01001326
1327 /*
1328 * If we receive a 4-addr nullfunc frame from a STA
1329 * that was not moved to a 4-addr STA vlan yet, drop
1330 * the frame to the monitor interface, to make sure
1331 * that hostapd sees it
1332 */
1333 if (ieee80211_has_a4(hdr->frame_control) &&
1334 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1335 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1336 !rx->sdata->u.vlan.sta)))
1337 return RX_DROP_MONITOR;
Johannes Berg22403de2009-10-30 12:55:03 +01001338 /*
1339 * Update counter and free packet here to avoid
1340 * counting this as a dropped packed.
1341 */
Johannes Berg571ecf62007-07-27 15:43:22 +02001342 sta->rx_packets++;
1343 dev_kfree_skb(rx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001344 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001345 }
1346
Johannes Berg9ae54c82008-01-31 19:48:20 +01001347 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001348} /* ieee80211_rx_h_sta_process */
1349
Johannes Berg571ecf62007-07-27 15:43:22 +02001350static inline struct ieee80211_fragment_entry *
1351ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1352 unsigned int frag, unsigned int seq, int rx_queue,
1353 struct sk_buff **skb)
1354{
1355 struct ieee80211_fragment_entry *entry;
1356 int idx;
1357
1358 idx = sdata->fragment_next;
1359 entry = &sdata->fragments[sdata->fragment_next++];
1360 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1361 sdata->fragment_next = 0;
1362
1363 if (!skb_queue_empty(&entry->skb_list)) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001364#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg571ecf62007-07-27 15:43:22 +02001365 struct ieee80211_hdr *hdr =
1366 (struct ieee80211_hdr *) entry->skb_list.next->data;
1367 printk(KERN_DEBUG "%s: RX reassembly removed oldest "
1368 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
Johannes Berg0c68ae262008-10-27 15:56:10 -07001369 "addr1=%pM addr2=%pM\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001370 sdata->name, idx,
Johannes Berg571ecf62007-07-27 15:43:22 +02001371 jiffies - entry->first_frag_time, entry->seq,
Johannes Berg0c68ae262008-10-27 15:56:10 -07001372 entry->last_frag, hdr->addr1, hdr->addr2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001373#endif
Johannes Berg571ecf62007-07-27 15:43:22 +02001374 __skb_queue_purge(&entry->skb_list);
1375 }
1376
1377 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1378 *skb = NULL;
1379 entry->first_frag_time = jiffies;
1380 entry->seq = seq;
1381 entry->rx_queue = rx_queue;
1382 entry->last_frag = frag;
1383 entry->ccmp = 0;
1384 entry->extra_len = 0;
1385
1386 return entry;
1387}
1388
1389static inline struct ieee80211_fragment_entry *
1390ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001391 unsigned int frag, unsigned int seq,
Johannes Berg571ecf62007-07-27 15:43:22 +02001392 int rx_queue, struct ieee80211_hdr *hdr)
1393{
1394 struct ieee80211_fragment_entry *entry;
1395 int i, idx;
1396
1397 idx = sdata->fragment_next;
1398 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1399 struct ieee80211_hdr *f_hdr;
Johannes Berg571ecf62007-07-27 15:43:22 +02001400
1401 idx--;
1402 if (idx < 0)
1403 idx = IEEE80211_FRAGMENT_MAX - 1;
1404
1405 entry = &sdata->fragments[idx];
1406 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1407 entry->rx_queue != rx_queue ||
1408 entry->last_frag + 1 != frag)
1409 continue;
1410
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001411 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001412
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001413 /*
1414 * Check ftype and addresses are equal, else check next fragment
1415 */
1416 if (((hdr->frame_control ^ f_hdr->frame_control) &
1417 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
Johannes Berg571ecf62007-07-27 15:43:22 +02001418 compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
1419 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
1420 continue;
1421
S.Çağlar Onurab466232008-02-14 17:36:47 +02001422 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001423 __skb_queue_purge(&entry->skb_list);
1424 continue;
1425 }
1426 return entry;
1427 }
1428
1429 return NULL;
1430}
1431
Johannes Berg49461622008-06-30 15:10:45 +02001432static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001433ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001434{
1435 struct ieee80211_hdr *hdr;
1436 u16 sc;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001437 __le16 fc;
Johannes Berg571ecf62007-07-27 15:43:22 +02001438 unsigned int frag, seq;
1439 struct ieee80211_fragment_entry *entry;
1440 struct sk_buff *skb;
Johannes Berg554891e2010-09-24 12:38:25 +02001441 struct ieee80211_rx_status *status;
Johannes Berg571ecf62007-07-27 15:43:22 +02001442
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001443 hdr = (struct ieee80211_hdr *)rx->skb->data;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001444 fc = hdr->frame_control;
Johannes Berg571ecf62007-07-27 15:43:22 +02001445 sc = le16_to_cpu(hdr->seq_ctrl);
1446 frag = sc & IEEE80211_SCTL_FRAG;
1447
Harvey Harrison358c8d92008-07-15 18:44:13 -07001448 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
Johannes Berg571ecf62007-07-27 15:43:22 +02001449 (rx->skb)->len < 24 ||
1450 is_multicast_ether_addr(hdr->addr1))) {
1451 /* not fragmented */
1452 goto out;
1453 }
1454 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1455
Zhu Yie3cf8b32010-03-29 17:35:07 +08001456 if (skb_linearize(rx->skb))
1457 return RX_DROP_UNUSABLE;
1458
Abhijeet Kolekar058897a2010-05-11 11:22:11 -07001459 /*
1460 * skb_linearize() might change the skb->data and
1461 * previously cached variables (in this case, hdr) need to
1462 * be refreshed with the new data.
1463 */
1464 hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001465 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1466
1467 if (frag == 0) {
1468 /* This is the first fragment of a new frame. */
1469 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
Johannes Berg9e262972011-07-07 18:45:03 +02001470 rx->seqno_idx, &(rx->skb));
Johannes Berg97359d12010-08-10 09:46:38 +02001471 if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
Harvey Harrison358c8d92008-07-15 18:44:13 -07001472 ieee80211_has_protected(fc)) {
Johannes Berg9e262972011-07-07 18:45:03 +02001473 int queue = rx->security_idx;
Johannes Berg571ecf62007-07-27 15:43:22 +02001474 /* Store CCMP PN so that we can verify that the next
1475 * fragment has a sequential PN value. */
1476 entry->ccmp = 1;
1477 memcpy(entry->last_pn,
Jouni Malinen91902522010-06-11 10:27:33 -07001478 rx->key->u.ccmp.rx_pn[queue],
Johannes Berg571ecf62007-07-27 15:43:22 +02001479 CCMP_PN_LEN);
1480 }
Johannes Berg9ae54c82008-01-31 19:48:20 +01001481 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001482 }
1483
1484 /* This is a fragment for a frame that should already be pending in
1485 * fragment cache. Add this fragment to the end of the pending entry.
1486 */
Johannes Berg9e262972011-07-07 18:45:03 +02001487 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1488 rx->seqno_idx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02001489 if (!entry) {
1490 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001491 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +02001492 }
1493
1494 /* Verify that MPDUs within one MSDU have sequential PN values.
1495 * (IEEE 802.11i, 8.3.3.4.5) */
1496 if (entry->ccmp) {
1497 int i;
1498 u8 pn[CCMP_PN_LEN], *rpn;
Jouni Malinen91902522010-06-11 10:27:33 -07001499 int queue;
Johannes Berg97359d12010-08-10 09:46:38 +02001500 if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
Johannes Berge4c26ad2008-01-31 19:48:21 +01001501 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001502 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
1503 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
1504 pn[i]++;
1505 if (pn[i])
1506 break;
1507 }
Johannes Berg9e262972011-07-07 18:45:03 +02001508 queue = rx->security_idx;
Jouni Malinen91902522010-06-11 10:27:33 -07001509 rpn = rx->key->u.ccmp.rx_pn[queue];
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001510 if (memcmp(pn, rpn, CCMP_PN_LEN))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001511 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001512 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
1513 }
1514
Harvey Harrison358c8d92008-07-15 18:44:13 -07001515 skb_pull(rx->skb, ieee80211_hdrlen(fc));
Johannes Berg571ecf62007-07-27 15:43:22 +02001516 __skb_queue_tail(&entry->skb_list, rx->skb);
1517 entry->last_frag = frag;
1518 entry->extra_len += rx->skb->len;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001519 if (ieee80211_has_morefrags(fc)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001520 rx->skb = NULL;
Johannes Berg9ae54c82008-01-31 19:48:20 +01001521 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001522 }
1523
1524 rx->skb = __skb_dequeue(&entry->skb_list);
1525 if (skb_tailroom(rx->skb) < entry->extra_len) {
1526 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
1527 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1528 GFP_ATOMIC))) {
1529 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1530 __skb_queue_purge(&entry->skb_list);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001531 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001532 }
1533 }
1534 while ((skb = __skb_dequeue(&entry->skb_list))) {
1535 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1536 dev_kfree_skb(skb);
1537 }
1538
1539 /* Complete frame has been reassembled - process it now */
Johannes Berg554891e2010-09-24 12:38:25 +02001540 status = IEEE80211_SKB_RXCB(rx->skb);
1541 status->rx_flags |= IEEE80211_RX_FRAGMENTED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001542
1543 out:
1544 if (rx->sta)
1545 rx->sta->rx_packets++;
1546 if (is_multicast_ether_addr(hdr->addr1))
1547 rx->local->dot11MulticastReceivedFrameCount++;
1548 else
1549 ieee80211_led_rx(rx->local);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001550 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001551}
1552
Johannes Berg49461622008-06-30 15:10:45 +02001553static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001554ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +02001555{
Johannes Berg6e0d1142007-07-27 15:43:22 +02001556 u8 *data = rx->skb->data;
Harvey Harrison238f74a2008-07-02 11:05:34 -07001557 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
Johannes Berg6e0d1142007-07-27 15:43:22 +02001558
Harvey Harrison238f74a2008-07-02 11:05:34 -07001559 if (!ieee80211_is_data_qos(hdr->frame_control))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001560 return RX_CONTINUE;
Johannes Berg6e0d1142007-07-27 15:43:22 +02001561
1562 /* remove the qos control field, update frame type and meta-data */
Harvey Harrison238f74a2008-07-02 11:05:34 -07001563 memmove(data + IEEE80211_QOS_CTL_LEN, data,
1564 ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
1565 hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
Johannes Berg6e0d1142007-07-27 15:43:22 +02001566 /* change frame type to non QOS */
Harvey Harrison238f74a2008-07-02 11:05:34 -07001567 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Johannes Berg6e0d1142007-07-27 15:43:22 +02001568
Johannes Berg9ae54c82008-01-31 19:48:20 +01001569 return RX_CONTINUE;
Johannes Berg6e0d1142007-07-27 15:43:22 +02001570}
1571
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001572static int
Johannes Berg5cf121c2008-02-25 16:27:43 +01001573ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001574{
Johannes Berg07346f812008-05-03 01:02:02 +02001575 if (unlikely(!rx->sta ||
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001576 !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001577 return -EACCES;
Johannes Berg571ecf62007-07-27 15:43:22 +02001578
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001579 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001580}
1581
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001582static int
Harvey Harrison358c8d92008-07-15 18:44:13 -07001583ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Berg571ecf62007-07-27 15:43:22 +02001584{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001585 struct sk_buff *skb = rx->skb;
1586 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1587
Johannes Berg3017b802007-08-28 17:01:53 -04001588 /*
Johannes Berg7848ba72007-09-14 11:10:25 -04001589 * Pass through unencrypted frames if the hardware has
1590 * decrypted them already.
Johannes Berg3017b802007-08-28 17:01:53 -04001591 */
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001592 if (status->flag & RX_FLAG_DECRYPTED)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001593 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001594
1595 /* Drop unencrypted frames if key is set. */
Harvey Harrison358c8d92008-07-15 18:44:13 -07001596 if (unlikely(!ieee80211_has_protected(fc) &&
1597 !ieee80211_is_nullfunc(fc) &&
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001598 ieee80211_is_data(fc) &&
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001599 (rx->key || rx->sdata->drop_unencrypted)))
1600 return -EACCES;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001601
1602 return 0;
1603}
1604
1605static int
1606ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
1607{
1608 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Jouni Malinene3efca02010-03-28 22:31:15 -07001609 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001610 __le16 fc = hdr->frame_control;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001611
Jouni Malinene3efca02010-03-28 22:31:15 -07001612 /*
1613 * Pass through unencrypted frames if the hardware has
1614 * decrypted them already.
1615 */
1616 if (status->flag & RX_FLAG_DECRYPTED)
1617 return 0;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001618
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001619 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
Jouni Malinend211e902010-03-28 22:29:52 -07001620 if (unlikely(!ieee80211_has_protected(fc) &&
1621 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02001622 rx->key)) {
1623 if (ieee80211_is_deauth(fc))
1624 cfg80211_send_unprot_deauth(rx->sdata->dev,
1625 rx->skb->data,
1626 rx->skb->len);
1627 else if (ieee80211_is_disassoc(fc))
1628 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1629 rx->skb->data,
1630 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001631 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02001632 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001633 /* BIP does not use Protected field, so need to check MMIE */
Joe Perchesf64f9e72009-11-29 16:55:45 -08001634 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02001635 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
1636 if (ieee80211_is_deauth(fc))
1637 cfg80211_send_unprot_deauth(rx->sdata->dev,
1638 rx->skb->data,
1639 rx->skb->len);
1640 else if (ieee80211_is_disassoc(fc))
1641 cfg80211_send_unprot_disassoc(rx->sdata->dev,
1642 rx->skb->data,
1643 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001644 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02001645 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001646 /*
1647 * When using MFP, Action frames are not allowed prior to
1648 * having configured keys.
1649 */
1650 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1651 ieee80211_is_robust_mgmt_frame(
1652 (struct ieee80211_hdr *) rx->skb->data)))
1653 return -EACCES;
1654 }
Johannes Bergb3fc9c62008-04-13 10:12:47 +02001655
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001656 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001657}
1658
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001659static int
Felix Fietkau4114fa22011-04-12 19:15:22 +02001660__ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
Johannes Berg571ecf62007-07-27 15:43:22 +02001661{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001662 struct ieee80211_sub_if_data *sdata = rx->sdata;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001663 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001664 bool check_port_control = false;
1665 struct ethhdr *ehdr;
1666 int ret;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001667
Felix Fietkau4114fa22011-04-12 19:15:22 +02001668 *port_control = false;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001669 if (ieee80211_has_a4(hdr->frame_control) &&
1670 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001671 return -1;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001672
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001673 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1674 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
1675
1676 if (!sdata->u.mgd.use_4addr)
1677 return -1;
1678 else
1679 check_port_control = true;
1680 }
1681
Johannes Berg9bc383d2009-11-19 11:55:19 +01001682 if (is_multicast_ether_addr(hdr->addr1) &&
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001683 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001684 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001685
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001686 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
Felix Fietkau4114fa22011-04-12 19:15:22 +02001687 if (ret < 0)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001688 return ret;
1689
1690 ehdr = (struct ethhdr *) rx->skb->data;
Felix Fietkau4114fa22011-04-12 19:15:22 +02001691 if (ehdr->h_proto == rx->sdata->control_port_protocol)
1692 *port_control = true;
1693 else if (check_port_control)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001694 return -1;
1695
1696 return 0;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001697}
Johannes Berg571ecf62007-07-27 15:43:22 +02001698
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001699/*
1700 * requires that rx->skb is a frame with ethernet header
1701 */
Harvey Harrison358c8d92008-07-15 18:44:13 -07001702static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001703{
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301704 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001705 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1706 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1707
1708 /*
1709 * Allow EAPOL frames to us/the PAE group address regardless
1710 * of whether the frame was encrypted or not.
1711 */
Johannes Berga621fa42010-08-27 14:26:54 +03001712 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
Johannes Berg47846c92009-11-25 17:46:19 +01001713 (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 ||
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001714 compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
1715 return true;
1716
1717 if (ieee80211_802_1x_port_control(rx) ||
Harvey Harrison358c8d92008-07-15 18:44:13 -07001718 ieee80211_drop_unencrypted(rx, fc))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001719 return false;
1720
1721 return true;
1722}
1723
1724/*
1725 * requires that rx->skb is a frame with ethernet header
1726 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001727static void
Johannes Berg5cf121c2008-02-25 16:27:43 +01001728ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001729{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001730 struct ieee80211_sub_if_data *sdata = rx->sdata;
1731 struct net_device *dev = sdata->dev;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001732 struct sk_buff *skb, *xmit_skb;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001733 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1734 struct sta_info *dsta;
Johannes Berg554891e2010-09-24 12:38:25 +02001735 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001736
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001737 skb = rx->skb;
1738 xmit_skb = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +02001739
Johannes Berg05c914f2008-09-11 00:01:58 +02001740 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1741 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
Johannes Berg213cd112008-09-11 00:01:54 +02001742 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
Johannes Berg554891e2010-09-24 12:38:25 +02001743 (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
Johannes Berg9bc383d2009-11-19 11:55:19 +01001744 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001745 if (is_multicast_ether_addr(ehdr->h_dest)) {
1746 /*
1747 * send multicast frames both to higher layers in
1748 * local net stack and back to the wireless medium
1749 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001750 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1751 if (!xmit_skb && net_ratelimit())
Johannes Berg571ecf62007-07-27 15:43:22 +02001752 printk(KERN_DEBUG "%s: failed to clone "
1753 "multicast frame\n", dev->name);
1754 } else {
Johannes Bergabe60632009-11-25 17:46:18 +01001755 dsta = sta_info_get(sdata, skb->data);
1756 if (dsta) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001757 /*
1758 * The destination station is associated to
1759 * this AP (in this VLAN), so send the frame
1760 * directly to it and do not pass it to local
1761 * net stack.
Johannes Berg571ecf62007-07-27 15:43:22 +02001762 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001763 xmit_skb = skb;
Johannes Berg571ecf62007-07-27 15:43:22 +02001764 skb = NULL;
1765 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001766 }
1767 }
1768
1769 if (skb) {
Johannes Bergd1c3a372009-01-07 00:26:10 +01001770 int align __maybe_unused;
1771
Kalle Valo59d9cb02009-12-17 13:54:57 +01001772#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Johannes Bergd1c3a372009-01-07 00:26:10 +01001773 /*
1774 * 'align' will only take the values 0 or 2 here
1775 * since all frames are required to be aligned
1776 * to 2-byte boundaries when being passed to
1777 * mac80211. That also explains the __skb_push()
1778 * below.
1779 */
matthieu castetdacb6f12009-06-04 22:16:18 +02001780 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
Johannes Bergd1c3a372009-01-07 00:26:10 +01001781 if (align) {
1782 if (WARN_ON(skb_headroom(skb) < 3)) {
1783 dev_kfree_skb(skb);
1784 skb = NULL;
1785 } else {
1786 u8 *data = skb->data;
Zhu Yi8ce0b582009-10-28 13:13:52 -07001787 size_t len = skb_headlen(skb);
1788 skb->data -= align;
1789 memmove(skb->data, data, len);
1790 skb_set_tail_pointer(skb, len);
Johannes Bergd1c3a372009-01-07 00:26:10 +01001791 }
1792 }
1793#endif
1794
1795 if (skb) {
1796 /* deliver to local stack */
1797 skb->protocol = eth_type_trans(skb, dev);
1798 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville5548a8a2010-06-24 14:25:56 -04001799 netif_receive_skb(skb);
Johannes Bergd1c3a372009-01-07 00:26:10 +01001800 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001801 }
1802
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001803 if (xmit_skb) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001804 /* send to wireless media */
YOSHIFUJI Hideakif831e902007-12-12 03:54:23 +09001805 xmit_skb->protocol = htons(ETH_P_802_3);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001806 skb_reset_network_header(xmit_skb);
1807 skb_reset_mac_header(xmit_skb);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001808 dev_queue_xmit(xmit_skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001809 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001810}
1811
Johannes Berg49461622008-06-30 15:10:45 +02001812static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001813ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001814{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001815 struct net_device *dev = rx->sdata->dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001816 struct sk_buff *skb = rx->skb;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001817 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1818 __le16 fc = hdr->frame_control;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001819 struct sk_buff_head frame_list;
Johannes Berg554891e2010-09-24 12:38:25 +02001820 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001821
Harvey Harrison358c8d92008-07-15 18:44:13 -07001822 if (unlikely(!ieee80211_is_data(fc)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001823 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001824
Harvey Harrison358c8d92008-07-15 18:44:13 -07001825 if (unlikely(!ieee80211_is_data_present(fc)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001826 return RX_DROP_MONITOR;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001827
Johannes Berg554891e2010-09-24 12:38:25 +02001828 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001829 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001830
Zhu Yieaf85ca2009-12-01 10:18:37 +08001831 if (ieee80211_has_a4(hdr->frame_control) &&
1832 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1833 !rx->sdata->u.vlan.sta)
1834 return RX_DROP_UNUSABLE;
1835
1836 if (is_multicast_ether_addr(hdr->addr1) &&
1837 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1838 rx->sdata->u.vlan.sta) ||
1839 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1840 rx->sdata->u.mgd.use_4addr)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001841 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001842
1843 skb->dev = dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001844 __skb_queue_head_init(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001845
Zhu Yie3cf8b32010-03-29 17:35:07 +08001846 if (skb_linearize(skb))
1847 return RX_DROP_UNUSABLE;
1848
Zhu Yieaf85ca2009-12-01 10:18:37 +08001849 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
1850 rx->sdata->vif.type,
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -07001851 rx->local->hw.extra_tx_headroom, true);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001852
Zhu Yieaf85ca2009-12-01 10:18:37 +08001853 while (!skb_queue_empty(&frame_list)) {
1854 rx->skb = __skb_dequeue(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001855
Harvey Harrison358c8d92008-07-15 18:44:13 -07001856 if (!ieee80211_frame_allowed(rx, fc)) {
Zhu Yieaf85ca2009-12-01 10:18:37 +08001857 dev_kfree_skb(rx->skb);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001858 continue;
1859 }
Zhu Yieaf85ca2009-12-01 10:18:37 +08001860 dev->stats.rx_packets++;
1861 dev->stats.rx_bytes += rx->skb->len;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001862
1863 ieee80211_deliver_skb(rx);
1864 }
1865
Johannes Berg9ae54c82008-01-31 19:48:20 +01001866 return RX_QUEUED;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001867}
1868
Ingo Molnarbf94e172008-10-12 23:51:38 -07001869#ifdef CONFIG_MAC80211_MESH
Davide Pesaventob0dee572008-09-27 17:29:12 +02001870static ieee80211_rx_result
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001871ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1872{
1873 struct ieee80211_hdr *hdr;
1874 struct ieee80211s_hdr *mesh_hdr;
1875 unsigned int hdrlen;
1876 struct sk_buff *skb = rx->skb, *fwd_skb;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001877 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001878 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02001879 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001880
1881 hdr = (struct ieee80211_hdr *) skb->data;
1882 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1883 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1884
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07001885 /* frame is in RMC, don't forward */
1886 if (ieee80211_is_data(hdr->frame_control) &&
1887 is_multicast_ether_addr(hdr->addr1) &&
1888 mesh_rmc_check(hdr->addr3, mesh_hdr, rx->sdata))
1889 return RX_DROP_MONITOR;
1890
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001891 if (!ieee80211_is_data(hdr->frame_control))
1892 return RX_CONTINUE;
1893
1894 if (!mesh_hdr->ttl)
1895 /* illegal frame */
1896 return RX_DROP_MONITOR;
1897
Javier Cardonacfee66b2011-09-06 13:05:21 -07001898 if (ieee80211_queue_stopped(&local->hw, skb_get_queue_mapping(skb))) {
1899 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1900 dropped_frames_congestion);
1901 return RX_DROP_MONITOR;
1902 }
1903
Javier Cardona43b7b312009-10-15 18:10:51 -07001904 if (mesh_hdr->flags & MESH_FLAGS_AE) {
YanBo79617de2008-09-22 13:30:32 +08001905 struct mesh_path *mppath;
Javier Cardona43b7b312009-10-15 18:10:51 -07001906 char *proxied_addr;
1907 char *mpp_addr;
1908
1909 if (is_multicast_ether_addr(hdr->addr1)) {
1910 mpp_addr = hdr->addr3;
1911 proxied_addr = mesh_hdr->eaddr1;
1912 } else {
1913 mpp_addr = hdr->addr4;
1914 proxied_addr = mesh_hdr->eaddr2;
1915 }
YanBo79617de2008-09-22 13:30:32 +08001916
YanBo79617de2008-09-22 13:30:32 +08001917 rcu_read_lock();
Javier Cardona43b7b312009-10-15 18:10:51 -07001918 mppath = mpp_path_lookup(proxied_addr, sdata);
YanBo79617de2008-09-22 13:30:32 +08001919 if (!mppath) {
Javier Cardona43b7b312009-10-15 18:10:51 -07001920 mpp_path_add(proxied_addr, mpp_addr, sdata);
YanBo79617de2008-09-22 13:30:32 +08001921 } else {
1922 spin_lock_bh(&mppath->state_lock);
Javier Cardona43b7b312009-10-15 18:10:51 -07001923 if (compare_ether_addr(mppath->mpp, mpp_addr) != 0)
1924 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
YanBo79617de2008-09-22 13:30:32 +08001925 spin_unlock_bh(&mppath->state_lock);
1926 }
1927 rcu_read_unlock();
1928 }
1929
Javier Cardona3c5772a2009-08-10 12:15:48 -07001930 /* Frame has reached destination. Don't forward */
1931 if (!is_multicast_ether_addr(hdr->addr1) &&
Johannes Berg47846c92009-11-25 17:46:19 +01001932 compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001933 return RX_CONTINUE;
1934
1935 mesh_hdr->ttl--;
1936
Johannes Berg554891e2010-09-24 12:38:25 +02001937 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001938 if (!mesh_hdr->ttl)
Johannes Berg472dbc42008-09-11 00:01:49 +02001939 IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001940 dropped_frames_ttl);
1941 else {
1942 struct ieee80211_hdr *fwd_hdr;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001943 struct ieee80211_tx_info *info;
1944
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001945 fwd_skb = skb_copy(skb, GFP_ATOMIC);
1946
1947 if (!fwd_skb && net_ratelimit())
1948 printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001949 sdata->name);
Milton Miller919bbad2010-12-30 02:01:03 -06001950 if (!fwd_skb)
Johannes Bergb51aff02010-12-22 10:15:07 +01001951 goto out;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001952
1953 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
Johannes Berg47846c92009-11-25 17:46:19 +01001954 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001955 info = IEEE80211_SKB_CB(fwd_skb);
1956 memset(info, 0, sizeof(*info));
1957 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
Johannes Berg5061b0c2009-07-14 00:33:34 +02001958 info->control.vif = &rx->sdata->vif;
Javier Cardona4777be42011-09-07 17:49:52 -07001959 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
Daniel Walkerc8a61a72009-08-18 10:59:00 -07001960 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1961 fwded_mcast);
Javier Cardona4777be42011-09-07 17:49:52 -07001962 skb_set_queue_mapping(fwd_skb,
1963 ieee80211_select_queue(sdata, fwd_skb));
Javier Cardona2154c812011-09-07 17:49:53 -07001964 ieee80211_set_qos_hdr(sdata, fwd_skb);
Javier Cardona4777be42011-09-07 17:49:52 -07001965 } else {
Javier Cardona3c5772a2009-08-10 12:15:48 -07001966 int err;
1967 /*
1968 * Save TA to addr1 to send TA a path error if a
1969 * suitable next hop is not found
1970 */
1971 memcpy(fwd_hdr->addr1, fwd_hdr->addr2,
Javier Cardona249b4052009-07-07 10:55:03 -07001972 ETH_ALEN);
Javier Cardona3c5772a2009-08-10 12:15:48 -07001973 err = mesh_nexthop_lookup(fwd_skb, sdata);
Javier Cardona249b4052009-07-07 10:55:03 -07001974 /* Failed to immediately resolve next hop:
1975 * fwded frame was dropped or will be added
1976 * later to the pending skb queue. */
1977 if (err)
1978 return RX_DROP_MONITOR;
Daniel Walkerc8a61a72009-08-18 10:59:00 -07001979
1980 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1981 fwded_unicast);
Javier Cardona249b4052009-07-07 10:55:03 -07001982 }
1983 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1984 fwded_frames);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001985 ieee80211_add_pending_skb(local, fwd_skb);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001986 }
1987 }
1988
Johannes Bergb51aff02010-12-22 10:15:07 +01001989 out:
Javier Cardona3c5772a2009-08-10 12:15:48 -07001990 if (is_multicast_ether_addr(hdr->addr1) ||
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001991 sdata->dev->flags & IFF_PROMISC)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001992 return RX_CONTINUE;
1993 else
1994 return RX_DROP_MONITOR;
1995}
Ingo Molnarbf94e172008-10-12 23:51:38 -07001996#endif
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001997
1998static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001999ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002000{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002001 struct ieee80211_sub_if_data *sdata = rx->sdata;
Vivek Natarajane15276a2010-02-08 17:47:01 +05302002 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002003 struct net_device *dev = sdata->dev;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002004 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2005 __le16 fc = hdr->frame_control;
Felix Fietkau4114fa22011-04-12 19:15:22 +02002006 bool port_control;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002007 int err;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002008
Harvey Harrison358c8d92008-07-15 18:44:13 -07002009 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002010 return RX_CONTINUE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002011
Harvey Harrison358c8d92008-07-15 18:44:13 -07002012 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002013 return RX_DROP_MONITOR;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002014
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002015 /*
2016 * Allow the cooked monitor interface of an AP to see 4-addr frames so
2017 * that a 4-addr station can be detected and moved into a separate VLAN
2018 */
2019 if (ieee80211_has_a4(hdr->frame_control) &&
2020 sdata->vif.type == NL80211_IFTYPE_AP)
2021 return RX_DROP_MONITOR;
2022
Felix Fietkau4114fa22011-04-12 19:15:22 +02002023 err = __ieee80211_data_to_8023(rx, &port_control);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002024 if (unlikely(err))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002025 return RX_DROP_UNUSABLE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002026
Harvey Harrison358c8d92008-07-15 18:44:13 -07002027 if (!ieee80211_frame_allowed(rx, fc))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002028 return RX_DROP_MONITOR;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002029
Felix Fietkau4114fa22011-04-12 19:15:22 +02002030 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2031 unlikely(port_control) && sdata->bss) {
2032 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2033 u.ap);
2034 dev = sdata->dev;
2035 rx->sdata = sdata;
2036 }
2037
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002038 rx->skb->dev = dev;
2039
2040 dev->stats.rx_packets++;
2041 dev->stats.rx_bytes += rx->skb->len;
2042
Helmut Schaa08ca9442010-11-30 12:19:34 +01002043 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
Rajkumar Manoharan8c99f692011-02-02 22:57:53 +05302044 !is_multicast_ether_addr(
2045 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2046 (!local->scanning &&
2047 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
Vivek Natarajane15276a2010-02-08 17:47:01 +05302048 mod_timer(&local->dynamic_ps_timer, jiffies +
2049 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2050 }
2051
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002052 ieee80211_deliver_skb(rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02002053
Johannes Berg9ae54c82008-01-31 19:48:20 +01002054 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002055}
2056
Johannes Berg49461622008-06-30 15:10:45 +02002057static ieee80211_rx_result debug_noinline
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002058ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
Ron Rindjunsky71364712007-12-25 17:00:36 +02002059{
2060 struct ieee80211_local *local = rx->local;
2061 struct ieee80211_hw *hw = &local->hw;
2062 struct sk_buff *skb = rx->skb;
Harvey Harrisona7767f92008-07-02 16:30:51 -07002063 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002064 struct tid_ampdu_rx *tid_agg_rx;
2065 u16 start_seq_num;
2066 u16 tid;
2067
Harvey Harrisona7767f92008-07-02 16:30:51 -07002068 if (likely(!ieee80211_is_ctl(bar->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002069 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002070
Harvey Harrisona7767f92008-07-02 16:30:51 -07002071 if (ieee80211_is_back_req(bar->frame_control)) {
Johannes Berg8ae59772010-05-30 14:52:58 +02002072 struct {
2073 __le16 control, start_seq_num;
2074 } __packed bar_data;
2075
Ron Rindjunsky71364712007-12-25 17:00:36 +02002076 if (!rx->sta)
Johannes Berga02ae752009-11-16 12:00:40 +01002077 return RX_DROP_MONITOR;
Johannes Berg8ae59772010-05-30 14:52:58 +02002078
2079 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2080 &bar_data, sizeof(bar_data)))
2081 return RX_DROP_MONITOR;
2082
Johannes Berg8ae59772010-05-30 14:52:58 +02002083 tid = le16_to_cpu(bar_data.control) >> 12;
Johannes Berga87f7362010-06-10 10:21:38 +02002084
2085 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2086 if (!tid_agg_rx)
Johannes Berga02ae752009-11-16 12:00:40 +01002087 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002088
Johannes Berg8ae59772010-05-30 14:52:58 +02002089 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002090
2091 /* reset session timer */
Johannes Berg20ad19d2009-02-10 21:25:45 +01002092 if (tid_agg_rx->timeout)
2093 mod_timer(&tid_agg_rx->session_timer,
2094 TU_TO_EXP_TIME(tid_agg_rx->timeout));
Ron Rindjunsky71364712007-12-25 17:00:36 +02002095
Johannes Bergdd318572010-11-29 11:09:16 +01002096 spin_lock(&tid_agg_rx->reorder_lock);
Johannes Berga02ae752009-11-16 12:00:40 +01002097 /* release stored frames up to start of BAR */
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002098 ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num);
Johannes Bergdd318572010-11-29 11:09:16 +01002099 spin_unlock(&tid_agg_rx->reorder_lock);
2100
Johannes Berga02ae752009-11-16 12:00:40 +01002101 kfree_skb(skb);
2102 return RX_QUEUED;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002103 }
2104
Johannes Berg08daeca2010-05-30 14:53:43 +02002105 /*
2106 * After this point, we only want management frames,
2107 * so we can drop all remaining control frames to
2108 * cooked monitor interfaces.
2109 */
2110 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002111}
2112
Jouni Malinenf4f727a2009-01-10 11:46:53 +02002113static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2114 struct ieee80211_mgmt *mgmt,
2115 size_t len)
Jouni Malinenfea14732009-01-08 13:32:06 +02002116{
2117 struct ieee80211_local *local = sdata->local;
2118 struct sk_buff *skb;
2119 struct ieee80211_mgmt *resp;
2120
Johannes Berg47846c92009-11-25 17:46:19 +01002121 if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) {
Jouni Malinenfea14732009-01-08 13:32:06 +02002122 /* Not to own unicast address */
2123 return;
2124 }
2125
Johannes Berg46900292009-02-15 12:44:28 +01002126 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
2127 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002128 /* Not from the current AP or not associated yet. */
Jouni Malinenfea14732009-01-08 13:32:06 +02002129 return;
2130 }
2131
2132 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2133 /* Too short SA Query request frame */
2134 return;
2135 }
2136
2137 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2138 if (skb == NULL)
2139 return;
2140
2141 skb_reserve(skb, local->hw.extra_tx_headroom);
2142 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2143 memset(resp, 0, 24);
2144 memcpy(resp->da, mgmt->sa, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002145 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +01002146 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
Jouni Malinenfea14732009-01-08 13:32:06 +02002147 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2148 IEEE80211_STYPE_ACTION);
2149 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2150 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2151 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2152 memcpy(resp->u.action.u.sa_query.trans_id,
2153 mgmt->u.action.u.sa_query.trans_id,
2154 WLAN_SA_QUERY_TR_ID_LEN);
2155
Johannes Berg62ae67b2009-11-18 18:42:05 +01002156 ieee80211_tx_skb(sdata, skb);
Jouni Malinenfea14732009-01-08 13:32:06 +02002157}
2158
Johannes Berg49461622008-06-30 15:10:45 +02002159static ieee80211_rx_result debug_noinline
Johannes Berg2e161f72010-08-12 15:38:38 +02002160ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2161{
2162 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002163 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002164
2165 /*
2166 * From here on, look only at management frames.
2167 * Data and control frames are already handled,
2168 * and unknown (reserved) frames are useless.
2169 */
2170 if (rx->skb->len < 24)
2171 return RX_DROP_MONITOR;
2172
2173 if (!ieee80211_is_mgmt(mgmt->frame_control))
2174 return RX_DROP_MONITOR;
2175
Johannes Berg554891e2010-09-24 12:38:25 +02002176 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg2e161f72010-08-12 15:38:38 +02002177 return RX_DROP_MONITOR;
2178
2179 if (ieee80211_drop_unencrypted_mgmt(rx))
2180 return RX_DROP_UNUSABLE;
2181
2182 return RX_CONTINUE;
2183}
2184
2185static ieee80211_rx_result debug_noinline
Johannes Bergde1ede72008-09-09 14:42:50 +02002186ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2187{
2188 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002189 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergde1ede72008-09-09 14:42:50 +02002190 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002191 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergde1ede72008-09-09 14:42:50 +02002192 int len = rx->skb->len;
2193
2194 if (!ieee80211_is_action(mgmt->frame_control))
2195 return RX_CONTINUE;
2196
Jouni Malinen026331c2010-02-15 12:53:10 +02002197 /* drop too small frames */
2198 if (len < IEEE80211_MIN_ACTION_SIZE)
2199 return RX_DROP_UNUSABLE;
2200
2201 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC)
Johannes Berg84040802010-02-15 12:46:39 +02002202 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002203
Johannes Berg554891e2010-09-24 12:38:25 +02002204 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg84040802010-02-15 12:46:39 +02002205 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002206
Johannes Bergde1ede72008-09-09 14:42:50 +02002207 switch (mgmt->u.action.category) {
2208 case WLAN_CATEGORY_BACK:
Johannes Berg8abd3f92009-02-10 21:25:47 +01002209 /*
2210 * The aggregation code is not prepared to handle
2211 * anything but STA/AP due to the BSSID handling;
2212 * IBSS could work in the code but isn't supported
2213 * by drivers or the standard.
2214 */
2215 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2216 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2217 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg84040802010-02-15 12:46:39 +02002218 break;
Johannes Berg8abd3f92009-02-10 21:25:47 +01002219
Jouni Malinen026331c2010-02-15 12:53:10 +02002220 /* verify action_code is present */
2221 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2222 break;
2223
Johannes Bergde1ede72008-09-09 14:42:50 +02002224 switch (mgmt->u.action.u.addba_req.action_code) {
2225 case WLAN_ACTION_ADDBA_REQ:
2226 if (len < (IEEE80211_MIN_ACTION_SIZE +
2227 sizeof(mgmt->u.action.u.addba_req)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002228 goto invalid;
2229 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002230 case WLAN_ACTION_ADDBA_RESP:
2231 if (len < (IEEE80211_MIN_ACTION_SIZE +
2232 sizeof(mgmt->u.action.u.addba_resp)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002233 goto invalid;
2234 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002235 case WLAN_ACTION_DELBA:
2236 if (len < (IEEE80211_MIN_ACTION_SIZE +
2237 sizeof(mgmt->u.action.u.delba)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002238 goto invalid;
2239 break;
2240 default:
2241 goto invalid;
Johannes Bergde1ede72008-09-09 14:42:50 +02002242 }
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002243
Johannes Berg8b58ff82010-06-10 10:21:51 +02002244 goto queue;
Johannes Berg39192c02008-09-09 14:49:03 +02002245 case WLAN_CATEGORY_SPECTRUM_MGMT:
2246 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
Johannes Berg84040802010-02-15 12:46:39 +02002247 break;
Johannes Berg46900292009-02-15 12:44:28 +01002248
2249 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002250 break;
Johannes Berg46900292009-02-15 12:44:28 +01002251
Jouni Malinen026331c2010-02-15 12:53:10 +02002252 /* verify action_code is present */
2253 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2254 break;
2255
Johannes Berg39192c02008-09-09 14:49:03 +02002256 switch (mgmt->u.action.u.measurement.action_code) {
2257 case WLAN_ACTION_SPCT_MSR_REQ:
2258 if (len < (IEEE80211_MIN_ACTION_SIZE +
2259 sizeof(mgmt->u.action.u.measurement)))
Johannes Berg84040802010-02-15 12:46:39 +02002260 break;
Johannes Berg39192c02008-09-09 14:49:03 +02002261 ieee80211_process_measurement_req(sdata, mgmt, len);
Johannes Berg84040802010-02-15 12:46:39 +02002262 goto handled;
Sujithc481ec92009-01-06 09:28:37 +05302263 case WLAN_ACTION_SPCT_CHL_SWITCH:
2264 if (len < (IEEE80211_MIN_ACTION_SIZE +
2265 sizeof(mgmt->u.action.u.chan_switch)))
Johannes Berg84040802010-02-15 12:46:39 +02002266 break;
Sujithc481ec92009-01-06 09:28:37 +05302267
Johannes Bergcc32abd2009-05-15 11:52:31 +02002268 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002269 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02002270
Johannes Berg46900292009-02-15 12:44:28 +01002271 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
Johannes Berg84040802010-02-15 12:46:39 +02002272 break;
Sujithc481ec92009-01-06 09:28:37 +05302273
Johannes Berg8b58ff82010-06-10 10:21:51 +02002274 goto queue;
Johannes Berg39192c02008-09-09 14:49:03 +02002275 }
2276 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002277 case WLAN_CATEGORY_SA_QUERY:
2278 if (len < (IEEE80211_MIN_ACTION_SIZE +
2279 sizeof(mgmt->u.action.u.sa_query)))
Johannes Berg84040802010-02-15 12:46:39 +02002280 break;
2281
Jouni Malinenfea14732009-01-08 13:32:06 +02002282 switch (mgmt->u.action.u.sa_query.action) {
2283 case WLAN_ACTION_SA_QUERY_REQUEST:
2284 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002285 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002286 ieee80211_process_sa_query_req(sdata, mgmt, len);
Johannes Berg84040802010-02-15 12:46:39 +02002287 goto handled;
Jouni Malinenfea14732009-01-08 13:32:06 +02002288 }
2289 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -07002290 case WLAN_CATEGORY_SELF_PROTECTED:
2291 switch (mgmt->u.action.u.self_prot.action_code) {
2292 case WLAN_SP_MESH_PEERING_OPEN:
2293 case WLAN_SP_MESH_PEERING_CLOSE:
2294 case WLAN_SP_MESH_PEERING_CONFIRM:
2295 if (!ieee80211_vif_is_mesh(&sdata->vif))
2296 goto invalid;
2297 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
2298 /* userspace handles this frame */
2299 break;
2300 goto queue;
2301 case WLAN_SP_MGK_INFORM:
2302 case WLAN_SP_MGK_ACK:
2303 if (!ieee80211_vif_is_mesh(&sdata->vif))
2304 goto invalid;
2305 break;
2306 }
2307 break;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -07002308 case WLAN_CATEGORY_MESH_ACTION:
Johannes Berg77a121c2010-06-10 10:21:34 +02002309 if (!ieee80211_vif_is_mesh(&sdata->vif))
2310 break;
Thomas Pedersen25d49e42011-08-11 19:35:15 -07002311 if (mesh_action_is_path_sel(mgmt) &&
2312 (!mesh_path_sel_is_hwmp(sdata)))
Javier Cardonac7108a72010-12-16 17:37:50 -08002313 break;
2314 goto queue;
Johannes Berg84040802010-02-15 12:46:39 +02002315 }
Jouni Malinen026331c2010-02-15 12:53:10 +02002316
Johannes Berg2e161f72010-08-12 15:38:38 +02002317 return RX_CONTINUE;
2318
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002319 invalid:
Johannes Berg554891e2010-09-24 12:38:25 +02002320 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
Johannes Berg2e161f72010-08-12 15:38:38 +02002321 /* will return in the next handlers */
2322 return RX_CONTINUE;
2323
2324 handled:
2325 if (rx->sta)
2326 rx->sta->rx_packets++;
2327 dev_kfree_skb(rx->skb);
2328 return RX_QUEUED;
2329
2330 queue:
2331 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2332 skb_queue_tail(&sdata->skb_queue, rx->skb);
2333 ieee80211_queue_work(&local->hw, &sdata->work);
2334 if (rx->sta)
2335 rx->sta->rx_packets++;
2336 return RX_QUEUED;
2337}
2338
2339static ieee80211_rx_result debug_noinline
2340ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2341{
Johannes Berg554891e2010-09-24 12:38:25 +02002342 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002343
2344 /* skip known-bad action frames and return them in the next handler */
Johannes Berg554891e2010-09-24 12:38:25 +02002345 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
Johannes Berg2e161f72010-08-12 15:38:38 +02002346 return RX_CONTINUE;
Felix Fietkaud7907442010-01-07 20:23:53 +01002347
Jouni Malinen026331c2010-02-15 12:53:10 +02002348 /*
2349 * Getting here means the kernel doesn't know how to handle
2350 * it, but maybe userspace does ... include returned frames
2351 * so userspace can register for those to know whether ones
2352 * it transmitted were processed or returned.
2353 */
Jouni Malinen026331c2010-02-15 12:53:10 +02002354
Johannes Berg2e161f72010-08-12 15:38:38 +02002355 if (cfg80211_rx_mgmt(rx->sdata->dev, status->freq,
2356 rx->skb->data, rx->skb->len,
2357 GFP_ATOMIC)) {
2358 if (rx->sta)
2359 rx->sta->rx_packets++;
2360 dev_kfree_skb(rx->skb);
2361 return RX_QUEUED;
2362 }
2363
2364
2365 return RX_CONTINUE;
2366}
2367
2368static ieee80211_rx_result debug_noinline
2369ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2370{
2371 struct ieee80211_local *local = rx->local;
2372 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2373 struct sk_buff *nskb;
2374 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02002375 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002376
2377 if (!ieee80211_is_action(mgmt->frame_control))
2378 return RX_CONTINUE;
2379
2380 /*
2381 * For AP mode, hostapd is responsible for handling any action
2382 * frames that we didn't handle, including returning unknown
2383 * ones. For all other modes we will return them to the sender,
2384 * setting the 0x80 bit in the action category, as required by
2385 * 802.11-2007 7.3.1.11.
2386 * Newer versions of hostapd shall also use the management frame
2387 * registration mechanisms, but older ones still use cooked
2388 * monitor interfaces so push all frames there.
2389 */
Johannes Berg554891e2010-09-24 12:38:25 +02002390 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
Johannes Berg2e161f72010-08-12 15:38:38 +02002391 (sdata->vif.type == NL80211_IFTYPE_AP ||
2392 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2393 return RX_DROP_MONITOR;
Jouni Malinen026331c2010-02-15 12:53:10 +02002394
Johannes Berg84040802010-02-15 12:46:39 +02002395 /* do not return rejected action frames */
2396 if (mgmt->u.action.category & 0x80)
2397 return RX_DROP_UNUSABLE;
2398
2399 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2400 GFP_ATOMIC);
2401 if (nskb) {
John W. Linville292b4df2010-06-24 11:13:56 -04002402 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
Johannes Berg84040802010-02-15 12:46:39 +02002403
John W. Linville292b4df2010-06-24 11:13:56 -04002404 nmgmt->u.action.category |= 0x80;
2405 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2406 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
Johannes Berg84040802010-02-15 12:46:39 +02002407
2408 memset(nskb->cb, 0, sizeof(nskb->cb));
2409
2410 ieee80211_tx_skb(rx->sdata, nskb);
Johannes Bergde1ede72008-09-09 14:42:50 +02002411 }
Johannes Berg39192c02008-09-09 14:49:03 +02002412 dev_kfree_skb(rx->skb);
2413 return RX_QUEUED;
Johannes Bergde1ede72008-09-09 14:42:50 +02002414}
2415
2416static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002417ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02002418{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002419 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002420 ieee80211_rx_result rxs;
Johannes Berg77a121c2010-06-10 10:21:34 +02002421 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2422 __le16 stype;
Johannes Berg571ecf62007-07-27 15:43:22 +02002423
Johannes Bergaf6b6372009-12-23 13:15:35 +01002424 rxs = ieee80211_work_rx_mgmt(rx->sdata, rx->skb);
2425 if (rxs != RX_CONTINUE)
2426 return rxs;
2427
Johannes Berg77a121c2010-06-10 10:21:34 +02002428 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
Johannes Berg472dbc42008-09-11 00:01:49 +02002429
Johannes Berg77a121c2010-06-10 10:21:34 +02002430 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2431 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2432 sdata->vif.type != NL80211_IFTYPE_STATION)
2433 return RX_DROP_MONITOR;
Johannes Bergf9d540e2007-09-28 14:02:09 +02002434
Johannes Berg77a121c2010-06-10 10:21:34 +02002435 switch (stype) {
2436 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2437 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2438 /* process for all: mesh, mlme, ibss */
2439 break;
2440 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2441 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
Christian Lamparter2c313332010-11-29 20:53:23 +01002442 if (is_multicast_ether_addr(mgmt->da) &&
2443 !is_broadcast_ether_addr(mgmt->da))
2444 return RX_DROP_MONITOR;
2445
Johannes Berg77a121c2010-06-10 10:21:34 +02002446 /* process only for station */
2447 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2448 return RX_DROP_MONITOR;
2449 break;
2450 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2451 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2452 /* process only for ibss */
2453 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
2454 return RX_DROP_MONITOR;
2455 break;
2456 default:
2457 return RX_DROP_MONITOR;
2458 }
Johannes Berg46900292009-02-15 12:44:28 +01002459
Johannes Berg77a121c2010-06-10 10:21:34 +02002460 /* queue up frame and kick off work to process it */
Johannes Bergc1475ca2010-06-10 10:21:37 +02002461 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg77a121c2010-06-10 10:21:34 +02002462 skb_queue_tail(&sdata->skb_queue, rx->skb);
2463 ieee80211_queue_work(&rx->local->hw, &sdata->work);
Johannes Berg8b58ff82010-06-10 10:21:51 +02002464 if (rx->sta)
2465 rx->sta->rx_packets++;
Johannes Berg77a121c2010-06-10 10:21:34 +02002466
2467 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002468}
2469
Johannes Berg5cf121c2008-02-25 16:27:43 +01002470/* TODO: use IEEE80211_RX_FRAGMENTED */
Johannes Berg5f0b7de2009-11-16 13:58:21 +01002471static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2472 struct ieee80211_rate *rate)
Michael Wu3d30d942008-01-31 19:48:27 +01002473{
2474 struct ieee80211_sub_if_data *sdata;
2475 struct ieee80211_local *local = rx->local;
2476 struct ieee80211_rtap_hdr {
2477 struct ieee80211_radiotap_header hdr;
2478 u8 flags;
Johannes Berg5f0b7de2009-11-16 13:58:21 +01002479 u8 rate_or_pad;
Michael Wu3d30d942008-01-31 19:48:27 +01002480 __le16 chan_freq;
2481 __le16 chan_flags;
Eric Dumazetbc105022010-06-03 03:21:52 -07002482 } __packed *rthdr;
Michael Wu3d30d942008-01-31 19:48:27 +01002483 struct sk_buff *skb = rx->skb, *skb2;
2484 struct net_device *prev_dev = NULL;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002485 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Michael Wu3d30d942008-01-31 19:48:27 +01002486
Johannes Berg554891e2010-09-24 12:38:25 +02002487 /*
2488 * If cooked monitor has been processed already, then
2489 * don't do it again. If not, set the flag.
2490 */
2491 if (rx->flags & IEEE80211_RX_CMNTR)
John W. Linville7c1e1832010-09-24 15:52:49 -04002492 goto out_free_skb;
Johannes Berg554891e2010-09-24 12:38:25 +02002493 rx->flags |= IEEE80211_RX_CMNTR;
John W. Linville7c1e1832010-09-24 15:52:49 -04002494
Michael Wu3d30d942008-01-31 19:48:27 +01002495 if (skb_headroom(skb) < sizeof(*rthdr) &&
2496 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
2497 goto out_free_skb;
2498
2499 rthdr = (void *)skb_push(skb, sizeof(*rthdr));
2500 memset(rthdr, 0, sizeof(*rthdr));
2501 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
2502 rthdr->hdr.it_present =
2503 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
Michael Wu3d30d942008-01-31 19:48:27 +01002504 (1 << IEEE80211_RADIOTAP_CHANNEL));
2505
Johannes Berg5f0b7de2009-11-16 13:58:21 +01002506 if (rate) {
2507 rthdr->rate_or_pad = rate->bitrate / 5;
2508 rthdr->hdr.it_present |=
2509 cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
2510 }
Michael Wu3d30d942008-01-31 19:48:27 +01002511 rthdr->chan_freq = cpu_to_le16(status->freq);
2512
2513 if (status->band == IEEE80211_BAND_5GHZ)
2514 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
2515 IEEE80211_CHAN_5GHZ);
2516 else
2517 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
2518 IEEE80211_CHAN_2GHZ);
2519
2520 skb_set_mac_header(skb, 0);
2521 skb->ip_summed = CHECKSUM_UNNECESSARY;
2522 skb->pkt_type = PACKET_OTHERHOST;
2523 skb->protocol = htons(ETH_P_802_2);
2524
2525 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01002526 if (!ieee80211_sdata_running(sdata))
Michael Wu3d30d942008-01-31 19:48:27 +01002527 continue;
2528
Johannes Berg05c914f2008-09-11 00:01:58 +02002529 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
Michael Wu3d30d942008-01-31 19:48:27 +01002530 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
2531 continue;
2532
2533 if (prev_dev) {
2534 skb2 = skb_clone(skb, GFP_ATOMIC);
2535 if (skb2) {
2536 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04002537 netif_receive_skb(skb2);
Michael Wu3d30d942008-01-31 19:48:27 +01002538 }
2539 }
2540
2541 prev_dev = sdata->dev;
2542 sdata->dev->stats.rx_packets++;
2543 sdata->dev->stats.rx_bytes += skb->len;
2544 }
2545
2546 if (prev_dev) {
2547 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04002548 netif_receive_skb(skb);
Johannes Berg554891e2010-09-24 12:38:25 +02002549 return;
2550 }
Michael Wu3d30d942008-01-31 19:48:27 +01002551
2552 out_free_skb:
2553 dev_kfree_skb(skb);
2554}
2555
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002556static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
2557 ieee80211_rx_result res)
2558{
2559 switch (res) {
2560 case RX_DROP_MONITOR:
2561 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2562 if (rx->sta)
2563 rx->sta->rx_dropped++;
2564 /* fall through */
2565 case RX_CONTINUE: {
2566 struct ieee80211_rate *rate = NULL;
2567 struct ieee80211_supported_band *sband;
2568 struct ieee80211_rx_status *status;
2569
2570 status = IEEE80211_SKB_RXCB((rx->skb));
2571
2572 sband = rx->local->hw.wiphy->bands[status->band];
2573 if (!(status->flag & RX_FLAG_HT))
2574 rate = &sband->bitrates[status->rate_idx];
2575
2576 ieee80211_rx_cooked_monitor(rx, rate);
2577 break;
2578 }
2579 case RX_DROP_UNUSABLE:
2580 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2581 if (rx->sta)
2582 rx->sta->rx_dropped++;
2583 dev_kfree_skb(rx->skb);
2584 break;
2585 case RX_QUEUED:
2586 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
2587 break;
2588 }
2589}
2590
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002591static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002592{
2593 ieee80211_rx_result res = RX_DROP_MONITOR;
2594 struct sk_buff *skb;
2595
2596#define CALL_RXH(rxh) \
2597 do { \
2598 res = rxh(rx); \
2599 if (res != RX_CONTINUE) \
2600 goto rxh_next; \
2601 } while (0);
2602
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002603 spin_lock(&rx->local->rx_skb_queue.lock);
2604 if (rx->local->running_rx_handler)
2605 goto unlock;
2606
2607 rx->local->running_rx_handler = true;
2608
2609 while ((skb = __skb_dequeue(&rx->local->rx_skb_queue))) {
2610 spin_unlock(&rx->local->rx_skb_queue.lock);
2611
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002612 /*
2613 * all the other fields are valid across frames
2614 * that belong to an aMPDU since they are on the
2615 * same TID from the same station
2616 */
2617 rx->skb = skb;
2618
2619 CALL_RXH(ieee80211_rx_h_decrypt)
2620 CALL_RXH(ieee80211_rx_h_check_more_data)
Johannes Berg47086fc2011-09-29 16:04:33 +02002621 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002622 CALL_RXH(ieee80211_rx_h_sta_process)
2623 CALL_RXH(ieee80211_rx_h_defragment)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002624 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2625 /* must be after MMIC verify so header is counted in MPDU mic */
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002626#ifdef CONFIG_MAC80211_MESH
2627 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
2628 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2629#endif
Javier Cardona2154c812011-09-07 17:49:53 -07002630 CALL_RXH(ieee80211_rx_h_remove_qos_control)
2631 CALL_RXH(ieee80211_rx_h_amsdu)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002632 CALL_RXH(ieee80211_rx_h_data)
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002633 CALL_RXH(ieee80211_rx_h_ctrl);
Johannes Berg2e161f72010-08-12 15:38:38 +02002634 CALL_RXH(ieee80211_rx_h_mgmt_check)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002635 CALL_RXH(ieee80211_rx_h_action)
Johannes Berg2e161f72010-08-12 15:38:38 +02002636 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
2637 CALL_RXH(ieee80211_rx_h_action_return)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002638 CALL_RXH(ieee80211_rx_h_mgmt)
2639
2640 rxh_next:
2641 ieee80211_rx_handlers_result(rx, res);
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002642 spin_lock(&rx->local->rx_skb_queue.lock);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002643#undef CALL_RXH
2644 }
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002645
2646 rx->local->running_rx_handler = false;
2647
2648 unlock:
2649 spin_unlock(&rx->local->rx_skb_queue.lock);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002650}
Johannes Berg571ecf62007-07-27 15:43:22 +02002651
Johannes Berg4406c372010-09-24 11:21:06 +02002652static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
Johannes Berg58905292008-01-31 19:48:25 +01002653{
Johannes Berg58905292008-01-31 19:48:25 +01002654 ieee80211_rx_result res = RX_DROP_MONITOR;
2655
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002656#define CALL_RXH(rxh) \
2657 do { \
2658 res = rxh(rx); \
2659 if (res != RX_CONTINUE) \
Johannes Berg2569a822009-11-25 17:46:17 +01002660 goto rxh_next; \
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002661 } while (0);
Johannes Berg58905292008-01-31 19:48:25 +01002662
Johannes Berg49461622008-06-30 15:10:45 +02002663 CALL_RXH(ieee80211_rx_h_passive_scan)
2664 CALL_RXH(ieee80211_rx_h_check)
Johannes Berg2569a822009-11-25 17:46:17 +01002665
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002666 ieee80211_rx_reorder_ampdu(rx);
Johannes Berg2569a822009-11-25 17:46:17 +01002667
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002668 ieee80211_rx_handlers(rx);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002669 return;
Johannes Berg49461622008-06-30 15:10:45 +02002670
Johannes Berg2569a822009-11-25 17:46:17 +01002671 rxh_next:
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002672 ieee80211_rx_handlers_result(rx, res);
2673
2674#undef CALL_RXH
Johannes Berg58905292008-01-31 19:48:25 +01002675}
2676
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02002677/*
Johannes Bergdd318572010-11-29 11:09:16 +01002678 * This function makes calls into the RX path, therefore
2679 * it has to be invoked under RCU read lock.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02002680 */
2681void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
2682{
Johannes Berg554891e2010-09-24 12:38:25 +02002683 struct ieee80211_rx_data rx = {
2684 .sta = sta,
2685 .sdata = sta->sdata,
2686 .local = sta->local,
Johannes Berg9e262972011-07-07 18:45:03 +02002687 /* This is OK -- must be QoS data frame */
2688 .security_idx = tid,
2689 .seqno_idx = tid,
Helmut Schaafcf8bd32011-04-01 15:46:05 +02002690 .flags = 0,
Johannes Berg554891e2010-09-24 12:38:25 +02002691 };
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02002692 struct tid_ampdu_rx *tid_agg_rx;
2693
2694 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
2695 if (!tid_agg_rx)
2696 return;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02002697
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02002698 spin_lock(&tid_agg_rx->reorder_lock);
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002699 ieee80211_sta_reorder_release(&sta->local->hw, tid_agg_rx);
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02002700 spin_unlock(&tid_agg_rx->reorder_lock);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02002701
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002702 ieee80211_rx_handlers(&rx);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02002703}
2704
Johannes Berg571ecf62007-07-27 15:43:22 +02002705/* main receive path */
2706
Johannes Berg20b01f82010-09-24 11:21:05 +02002707static int prepare_for_handlers(struct ieee80211_rx_data *rx,
Johannes Berg23a24de2007-07-27 15:43:22 +02002708 struct ieee80211_hdr *hdr)
2709{
Johannes Berg20b01f82010-09-24 11:21:05 +02002710 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002711 struct sk_buff *skb = rx->skb;
2712 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2713 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
Johannes Berg23a24de2007-07-27 15:43:22 +02002714 int multicast = is_multicast_ether_addr(hdr->addr1);
2715
Johannes Berg51fb61e2007-12-19 01:31:27 +01002716 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002717 case NL80211_IFTYPE_STATION:
Johannes Berg9bc383d2009-11-19 11:55:19 +01002718 if (!bssid && !sdata->u.mgd.use_4addr)
Johannes Berg23a24de2007-07-27 15:43:22 +02002719 return 0;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002720 if (!multicast &&
Johannes Berg47846c92009-11-25 17:46:19 +01002721 compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) {
Felix Fietkau4f312332011-02-05 23:48:37 +01002722 if (!(sdata->dev->flags & IFF_PROMISC) ||
2723 sdata->u.mgd.use_4addr)
Johannes Berg23a24de2007-07-27 15:43:22 +02002724 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002725 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02002726 }
2727 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002728 case NL80211_IFTYPE_ADHOC:
Johannes Berg23a24de2007-07-27 15:43:22 +02002729 if (!bssid)
2730 return 0;
Harvey Harrisona7767f92008-07-02 16:30:51 -07002731 if (ieee80211_is_beacon(hdr->frame_control)) {
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002732 return 1;
Vladimir Koutny87291c02008-06-13 16:50:44 +02002733 }
Johannes Berg46900292009-02-15 12:44:28 +01002734 else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
Johannes Berg554891e2010-09-24 12:38:25 +02002735 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN))
Johannes Berg23a24de2007-07-27 15:43:22 +02002736 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002737 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02002738 } else if (!multicast &&
Johannes Berg47846c92009-11-25 17:46:19 +01002739 compare_ether_addr(sdata->vif.addr,
Johannes Berg23a24de2007-07-27 15:43:22 +02002740 hdr->addr1) != 0) {
Johannes Berg4150c572007-09-17 01:29:23 -04002741 if (!(sdata->dev->flags & IFF_PROMISC))
Johannes Berg23a24de2007-07-27 15:43:22 +02002742 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002743 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02002744 } else if (!rx->sta) {
2745 int rate_idx;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002746 if (status->flag & RX_FLAG_HT)
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02002747 rate_idx = 0; /* TODO: HT rates */
2748 else
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002749 rate_idx = status->rate_idx;
Johannes Berg34e89502010-02-03 13:59:58 +01002750 rx->sta = ieee80211_ibss_add_sta(sdata, bssid,
2751 hdr->addr2, BIT(rate_idx), GFP_ATOMIC);
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02002752 }
Johannes Berg23a24de2007-07-27 15:43:22 +02002753 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002754 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg6032f932008-02-23 15:17:07 +01002755 if (!multicast &&
Johannes Berg47846c92009-11-25 17:46:19 +01002756 compare_ether_addr(sdata->vif.addr,
Johannes Berg6032f932008-02-23 15:17:07 +01002757 hdr->addr1) != 0) {
2758 if (!(sdata->dev->flags & IFF_PROMISC))
2759 return 0;
2760
Johannes Berg554891e2010-09-24 12:38:25 +02002761 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg6032f932008-02-23 15:17:07 +01002762 }
2763 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002764 case NL80211_IFTYPE_AP_VLAN:
2765 case NL80211_IFTYPE_AP:
Johannes Berg23a24de2007-07-27 15:43:22 +02002766 if (!bssid) {
Johannes Berg47846c92009-11-25 17:46:19 +01002767 if (compare_ether_addr(sdata->vif.addr,
Johannes Berg23a24de2007-07-27 15:43:22 +02002768 hdr->addr1))
2769 return 0;
2770 } else if (!ieee80211_bssid_match(bssid,
Johannes Berg47846c92009-11-25 17:46:19 +01002771 sdata->vif.addr)) {
Arik Nemtsov771bbd02011-02-01 13:23:05 +02002772 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
Arik Nemtsova21fa872011-08-23 10:21:27 +03002773 !ieee80211_is_beacon(hdr->frame_control) &&
2774 !(ieee80211_is_action(hdr->frame_control) &&
2775 sdata->vif.p2p))
Johannes Berg23a24de2007-07-27 15:43:22 +02002776 return 0;
Johannes Berg554891e2010-09-24 12:38:25 +02002777 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02002778 }
Johannes Berg23a24de2007-07-27 15:43:22 +02002779 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002780 case NL80211_IFTYPE_WDS:
Harvey Harrisona7767f92008-07-02 16:30:51 -07002781 if (bssid || !ieee80211_is_data(hdr->frame_control))
Johannes Berg23a24de2007-07-27 15:43:22 +02002782 return 0;
2783 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
2784 return 0;
2785 break;
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002786 default:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02002787 /* should never get here */
2788 WARN_ON(1);
2789 break;
Johannes Berg23a24de2007-07-27 15:43:22 +02002790 }
2791
2792 return 1;
2793}
2794
Johannes Berg571ecf62007-07-27 15:43:22 +02002795/*
Johannes Berg4406c372010-09-24 11:21:06 +02002796 * This function returns whether or not the SKB
2797 * was destined for RX processing or not, which,
2798 * if consume is true, is equivalent to whether
2799 * or not the skb was consumed.
2800 */
2801static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
2802 struct sk_buff *skb, bool consume)
2803{
2804 struct ieee80211_local *local = rx->local;
2805 struct ieee80211_sub_if_data *sdata = rx->sdata;
2806 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2807 struct ieee80211_hdr *hdr = (void *)skb->data;
2808 int prepares;
2809
2810 rx->skb = skb;
Johannes Berg554891e2010-09-24 12:38:25 +02002811 status->rx_flags |= IEEE80211_RX_RA_MATCH;
Johannes Berg4406c372010-09-24 11:21:06 +02002812 prepares = prepare_for_handlers(rx, hdr);
2813
2814 if (!prepares)
2815 return false;
2816
Johannes Berg4406c372010-09-24 11:21:06 +02002817 if (!consume) {
2818 skb = skb_copy(skb, GFP_ATOMIC);
2819 if (!skb) {
2820 if (net_ratelimit())
2821 wiphy_debug(local->hw.wiphy,
Ben Greearb305dae2011-01-08 10:30:54 -08002822 "failed to copy skb for %s\n",
Johannes Berg4406c372010-09-24 11:21:06 +02002823 sdata->name);
2824 return true;
2825 }
2826
2827 rx->skb = skb;
2828 }
2829
2830 ieee80211_invoke_rx_handlers(rx);
2831 return true;
2832}
2833
2834/*
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002835 * This is the actual Rx frames handler. as it blongs to Rx path it must
2836 * be called with rcu_read_lock protection.
Johannes Berg571ecf62007-07-27 15:43:22 +02002837 */
Ron Rindjunsky71ebb4a2008-01-21 12:39:12 +02002838static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
Christian Lamparter071d9ac2010-08-05 01:36:36 +02002839 struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02002840{
Johannes Berg554891e2010-09-24 12:38:25 +02002841 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02002842 struct ieee80211_local *local = hw_to_local(hw);
2843 struct ieee80211_sub_if_data *sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02002844 struct ieee80211_hdr *hdr;
Zhu Yie3cf8b32010-03-29 17:35:07 +08002845 __le16 fc;
Johannes Berg5cf121c2008-02-25 16:27:43 +01002846 struct ieee80211_rx_data rx;
Johannes Berg4406c372010-09-24 11:21:06 +02002847 struct ieee80211_sub_if_data *prev;
Ben Greear56af3262010-09-23 10:22:24 -07002848 struct sta_info *sta, *tmp, *prev_sta;
Zhu Yie3cf8b32010-03-29 17:35:07 +08002849 int err = 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02002850
Zhu Yie3cf8b32010-03-29 17:35:07 +08002851 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
Johannes Berg571ecf62007-07-27 15:43:22 +02002852 memset(&rx, 0, sizeof(rx));
2853 rx.skb = skb;
2854 rx.local = local;
Johannes Berg72abd812007-09-17 01:29:22 -04002855
Zhu Yie3cf8b32010-03-29 17:35:07 +08002856 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
Johannes Berg571ecf62007-07-27 15:43:22 +02002857 local->dot11ReceivedFragmentCount++;
Johannes Berg571ecf62007-07-27 15:43:22 +02002858
Helmut Schaa142b9f52009-07-23 13:18:01 +02002859 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
Ben Greearb23b0252011-02-04 11:54:17 -08002860 test_bit(SCAN_SW_SCANNING, &local->scanning)))
Johannes Berg554891e2010-09-24 12:38:25 +02002861 status->rx_flags |= IEEE80211_RX_IN_SCAN;
Johannes Berg571ecf62007-07-27 15:43:22 +02002862
Zhu Yie3cf8b32010-03-29 17:35:07 +08002863 if (ieee80211_is_mgmt(fc))
2864 err = skb_linearize(skb);
2865 else
2866 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
2867
2868 if (err) {
2869 dev_kfree_skb(skb);
2870 return;
2871 }
2872
2873 hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg38f37142008-01-29 17:07:43 +01002874 ieee80211_parse_qos(&rx);
Johannes Bergd1c3a372009-01-07 00:26:10 +01002875 ieee80211_verify_alignment(&rx);
Johannes Berg38f37142008-01-29 17:07:43 +01002876
Zhu Yie3cf8b32010-03-29 17:35:07 +08002877 if (ieee80211_is_data(fc)) {
Ben Greear56af3262010-09-23 10:22:24 -07002878 prev_sta = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02002879
Guy Eilam2a33bee2011-08-17 15:18:15 +03002880 for_each_sta_info_rx(local, hdr->addr2, sta, tmp) {
Ben Greear56af3262010-09-23 10:22:24 -07002881 if (!prev_sta) {
2882 prev_sta = sta;
2883 continue;
2884 }
2885
2886 rx.sta = prev_sta;
2887 rx.sdata = prev_sta->sdata;
Johannes Berg4406c372010-09-24 11:21:06 +02002888 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Johannes Berg571ecf62007-07-27 15:43:22 +02002889
Ben Greear56af3262010-09-23 10:22:24 -07002890 prev_sta = sta;
Johannes Berg4406c372010-09-24 11:21:06 +02002891 }
Ben Greear56af3262010-09-23 10:22:24 -07002892
2893 if (prev_sta) {
2894 rx.sta = prev_sta;
2895 rx.sdata = prev_sta->sdata;
2896
Johannes Berg4406c372010-09-24 11:21:06 +02002897 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
Ben Greear56af3262010-09-23 10:22:24 -07002898 return;
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05302899 goto out;
Ben Greear56af3262010-09-23 10:22:24 -07002900 }
Johannes Berg4406c372010-09-24 11:21:06 +02002901 }
2902
Johannes Berg4b0dd982010-09-24 11:21:07 +02002903 prev = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02002904
Johannes Berg4b0dd982010-09-24 11:21:07 +02002905 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2906 if (!ieee80211_sdata_running(sdata))
2907 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01002908
Johannes Berg4b0dd982010-09-24 11:21:07 +02002909 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2910 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2911 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01002912
Johannes Berg4b0dd982010-09-24 11:21:07 +02002913 /*
2914 * frame is destined for this interface, but if it's
2915 * not also for the previous one we handle that after
2916 * the loop to avoid copying the SKB once too much
2917 */
Johannes Bergb2e77712007-09-26 15:19:39 +02002918
Johannes Berg4b0dd982010-09-24 11:21:07 +02002919 if (!prev) {
Johannes Berg340e11f2007-07-27 15:43:22 +02002920 prev = sdata;
Johannes Berg4b0dd982010-09-24 11:21:07 +02002921 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02002922 }
Felix Fietkau4bb29f82010-01-22 00:36:39 +01002923
Guy Eilam2a33bee2011-08-17 15:18:15 +03002924 rx.sta = sta_info_get_bss_rx(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02002925 rx.sdata = prev;
2926 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Felix Fietkau4bb29f82010-01-22 00:36:39 +01002927
Johannes Berg4b0dd982010-09-24 11:21:07 +02002928 prev = sdata;
2929 }
Johannes Berg4406c372010-09-24 11:21:06 +02002930
Johannes Berg4b0dd982010-09-24 11:21:07 +02002931 if (prev) {
Guy Eilam2a33bee2011-08-17 15:18:15 +03002932 rx.sta = sta_info_get_bss_rx(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02002933 rx.sdata = prev;
2934
2935 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2936 return;
Johannes Berg571ecf62007-07-27 15:43:22 +02002937 }
Johannes Berg4406c372010-09-24 11:21:06 +02002938
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05302939 out:
Johannes Berg4406c372010-09-24 11:21:06 +02002940 dev_kfree_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02002941}
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002942
2943/*
2944 * This is the receive path handler. It is called by a low level driver when an
2945 * 802.11 MPDU is received from the hardware.
2946 */
John W. Linville103bf9f2009-08-20 16:34:15 -04002947void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02002948{
2949 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg8318d782008-01-24 19:38:38 +01002950 struct ieee80211_rate *rate = NULL;
2951 struct ieee80211_supported_band *sband;
Johannes Bergf1d58c22009-06-17 13:13:00 +02002952 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg8318d782008-01-24 19:38:38 +01002953
Johannes Bergd20ef632009-10-11 15:10:40 +02002954 WARN_ON_ONCE(softirq_count() == 0);
2955
Johannes Berg77a980d2009-08-24 11:46:30 +02002956 if (WARN_ON(status->band < 0 ||
2957 status->band >= IEEE80211_NUM_BANDS))
2958 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01002959
2960 sband = local->hw.wiphy->bands[status->band];
Johannes Berg77a980d2009-08-24 11:46:30 +02002961 if (WARN_ON(!sband))
2962 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01002963
Johannes Berg89c3a8a2009-07-28 18:10:17 +02002964 /*
2965 * If we're suspending, it is possible although not too likely
2966 * that we'd be receiving frames after having already partially
2967 * quiesced the stack. We can't process such frames then since
2968 * that might, for example, cause stations to be added or other
2969 * driver callbacks be invoked.
2970 */
Johannes Berg77a980d2009-08-24 11:46:30 +02002971 if (unlikely(local->quiescing || local->suspended))
2972 goto drop;
Johannes Berg89c3a8a2009-07-28 18:10:17 +02002973
Johannes Bergea77f122009-08-21 14:44:45 +02002974 /*
2975 * The same happens when we're not even started,
2976 * but that's worth a warning.
2977 */
Johannes Berg77a980d2009-08-24 11:46:30 +02002978 if (WARN_ON(!local->started))
2979 goto drop;
Johannes Bergea77f122009-08-21 14:44:45 +02002980
Johannes Bergfc885182010-07-30 13:23:12 +02002981 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05002982 /*
Johannes Bergfc885182010-07-30 13:23:12 +02002983 * Validate the rate, unless a PLCP error means that
2984 * we probably can't have a valid rate here anyway.
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05002985 */
Johannes Bergfc885182010-07-30 13:23:12 +02002986
2987 if (status->flag & RX_FLAG_HT) {
2988 /*
2989 * rate_idx is MCS index, which can be [0-76]
2990 * as documented on:
2991 *
2992 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
2993 *
2994 * Anything else would be some sort of driver or
2995 * hardware error. The driver should catch hardware
2996 * errors.
2997 */
2998 if (WARN((status->rate_idx < 0 ||
2999 status->rate_idx > 76),
3000 "Rate marked as an HT rate but passed "
3001 "status->rate_idx is not "
3002 "an MCS index [0-76]: %d (0x%02x)\n",
3003 status->rate_idx,
3004 status->rate_idx))
3005 goto drop;
3006 } else {
3007 if (WARN_ON(status->rate_idx < 0 ||
3008 status->rate_idx >= sband->n_bitrates))
3009 goto drop;
3010 rate = &sband->bitrates[status->rate_idx];
3011 }
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003012 }
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003013
Johannes Berg554891e2010-09-24 12:38:25 +02003014 status->rx_flags = 0;
3015
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003016 /*
3017 * key references and virtual interfaces are protected using RCU
3018 * and this requires that we are in a read-side RCU section during
3019 * receive processing
3020 */
3021 rcu_read_lock();
3022
3023 /*
3024 * Frames with failed FCS/PLCP checksum are not returned,
3025 * all other frames are returned without radiotap header
3026 * if it was previously present.
3027 * Also, frames with less than 16 bytes are dropped.
3028 */
Johannes Bergf1d58c22009-06-17 13:13:00 +02003029 skb = ieee80211_rx_monitor(local, skb, rate);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003030 if (!skb) {
3031 rcu_read_unlock();
3032 return;
3033 }
3034
Johannes Berge1e54062010-11-30 08:58:45 +01003035 ieee80211_tpt_led_trig_rx(local,
3036 ((struct ieee80211_hdr *)skb->data)->frame_control,
3037 skb->len);
Christian Lamparter071d9ac2010-08-05 01:36:36 +02003038 __ieee80211_rx_handle_packet(hw, skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003039
3040 rcu_read_unlock();
Johannes Berg77a980d2009-08-24 11:46:30 +02003041
3042 return;
3043 drop:
3044 kfree_skb(skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003045}
John W. Linville103bf9f2009-08-20 16:34:15 -04003046EXPORT_SYMBOL(ieee80211_rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02003047
3048/* This is a version of the rx handler that can be called from hard irq
3049 * context. Post the skb on the queue and schedule the tasklet */
Johannes Bergf1d58c22009-06-17 13:13:00 +02003050void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02003051{
3052 struct ieee80211_local *local = hw_to_local(hw);
3053
3054 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3055
Johannes Berg571ecf62007-07-27 15:43:22 +02003056 skb->pkt_type = IEEE80211_RX_MSG;
3057 skb_queue_tail(&local->skb_queue, skb);
3058 tasklet_schedule(&local->tasklet);
3059}
3060EXPORT_SYMBOL(ieee80211_rx_irqsafe);