blob: b86330138d67defacc4ce94a25a5c336e20115a4 [file] [log] [blame]
Johannes Berg571ecf62007-07-27 15:43:22 +02001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
Johannes Berg84040802010-02-15 12:46:39 +02005 * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg571ecf62007-07-27 15:43:22 +02006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
S.Çağlar Onurab466232008-02-14 17:36:47 +020012#include <linux/jiffies.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020014#include <linux/kernel.h>
15#include <linux/skbuff.h>
16#include <linux/netdevice.h>
17#include <linux/etherdevice.h>
Johannes Bergd4e46a32007-09-14 11:10:24 -040018#include <linux/rcupdate.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040019#include <linux/export.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020020#include <net/mac80211.h>
21#include <net/ieee80211_radiotap.h>
Johannes Bergd26ad372012-02-20 11:38:41 +010022#include <asm/unaligned.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020023
24#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020025#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040026#include "led.h"
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +010027#include "mesh.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020028#include "wep.h"
29#include "wpa.h"
30#include "tkip.h"
31#include "wme.h"
Johannes Berg1d8d3de2011-12-16 15:28:57 +010032#include "rate.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020033
Johannes Bergb2e77712007-09-26 15:19:39 +020034/*
35 * monitor mode reception
36 *
37 * This function cleans up the SKB, i.e. it removes all the stuff
38 * only useful for monitoring.
39 */
40static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
Johannes Berg0869aea2009-10-28 10:03:35 +010041 struct sk_buff *skb)
Johannes Bergb2e77712007-09-26 15:19:39 +020042{
Johannes Bergb2e77712007-09-26 15:19:39 +020043 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
44 if (likely(skb->len > FCS_LEN))
Zhu Yie3cf8b32010-03-29 17:35:07 +080045 __pskb_trim(skb, skb->len - FCS_LEN);
Johannes Bergb2e77712007-09-26 15:19:39 +020046 else {
47 /* driver bug */
48 WARN_ON(1);
49 dev_kfree_skb(skb);
Dan Carpenter06247602012-11-27 20:31:19 +030050 return NULL;
Johannes Bergb2e77712007-09-26 15:19:39 +020051 }
52 }
53
54 return skb;
55}
56
Johannes Berg1df332e2012-10-26 00:09:11 +020057static inline int should_drop_frame(struct sk_buff *skb, int present_fcs_len)
Johannes Bergb2e77712007-09-26 15:19:39 +020058{
Johannes Bergf1d58c22009-06-17 13:13:00 +020059 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg605f1a52012-11-22 10:20:58 +010060 struct ieee80211_hdr *hdr;
61
Emmanuel Grumbach0059b2b2014-02-05 16:36:01 +020062 hdr = (void *)(skb->data);
Johannes Bergb2e77712007-09-26 15:19:39 +020063
Johannes Berg4c298672012-07-05 11:34:31 +020064 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
65 RX_FLAG_FAILED_PLCP_CRC |
66 RX_FLAG_AMPDU_IS_ZEROLEN))
Johannes Bergb2e77712007-09-26 15:19:39 +020067 return 1;
Emmanuel Grumbach0059b2b2014-02-05 16:36:01 +020068 if (unlikely(skb->len < 16 + present_fcs_len))
Johannes Bergb2e77712007-09-26 15:19:39 +020069 return 1;
Harvey Harrison87228f52008-06-11 14:21:59 -070070 if (ieee80211_is_ctl(hdr->frame_control) &&
71 !ieee80211_is_pspoll(hdr->frame_control) &&
72 !ieee80211_is_back_req(hdr->frame_control))
Johannes Bergb2e77712007-09-26 15:19:39 +020073 return 1;
74 return 0;
75}
76
Bruno Randolf601ae7f2008-05-08 19:22:43 +020077static int
Johannes Berg90b9e4462012-11-16 10:09:08 +010078ieee80211_rx_radiotap_space(struct ieee80211_local *local,
79 struct ieee80211_rx_status *status)
Bruno Randolf601ae7f2008-05-08 19:22:43 +020080{
81 int len;
82
83 /* always present fields */
Johannes Berga144f372013-07-03 13:34:02 +020084 len = sizeof(struct ieee80211_radiotap_header) + 8;
Bruno Randolf601ae7f2008-05-08 19:22:43 +020085
Johannes Berga144f372013-07-03 13:34:02 +020086 /* allocate extra bitmaps */
Johannes Berga144f372013-07-03 13:34:02 +020087 if (status->chains)
88 len += 4 * hweight8(status->chains);
Johannes Berg90b9e4462012-11-16 10:09:08 +010089
90 if (ieee80211_have_rx_timestamp(status)) {
91 len = ALIGN(len, 8);
Bruno Randolf601ae7f2008-05-08 19:22:43 +020092 len += 8;
Johannes Berg90b9e4462012-11-16 10:09:08 +010093 }
Johannes Berg7fee5372009-01-30 11:13:06 +010094 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
Bruno Randolf601ae7f2008-05-08 19:22:43 +020095 len += 1;
Bruno Randolf601ae7f2008-05-08 19:22:43 +020096
Johannes Berga144f372013-07-03 13:34:02 +020097 /* antenna field, if we don't have per-chain info */
98 if (!status->chains)
99 len += 1;
100
Johannes Berg90b9e4462012-11-16 10:09:08 +0100101 /* padding for RX_FLAGS if necessary */
102 len = ALIGN(len, 2);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200103
Johannes Berg6d744ba2011-01-27 14:13:17 +0100104 if (status->flag & RX_FLAG_HT) /* HT info */
105 len += 3;
106
Johannes Berg4c298672012-07-05 11:34:31 +0200107 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
Johannes Berg90b9e4462012-11-16 10:09:08 +0100108 len = ALIGN(len, 4);
Johannes Berg4c298672012-07-05 11:34:31 +0200109 len += 8;
110 }
111
Johannes Berg51648922012-11-22 23:00:18 +0100112 if (status->flag & RX_FLAG_VHT) {
113 len = ALIGN(len, 2);
114 len += 12;
115 }
116
Johannes Berga144f372013-07-03 13:34:02 +0200117 if (status->chains) {
118 /* antenna and antenna signal fields */
119 len += 2 * hweight8(status->chains);
120 }
121
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200122 return len;
123}
124
Johannes Berg00ea6de2012-09-05 15:54:51 +0200125/*
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200126 * ieee80211_add_rx_radiotap_header - add radiotap header
127 *
128 * add a radiotap header containing all the fields which the hardware provided.
129 */
130static void
131ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
132 struct sk_buff *skb,
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200133 struct ieee80211_rate *rate,
Felix Fietkau973ef212012-04-16 14:56:48 +0200134 int rtap_len, bool has_fcs)
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200135{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200136 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200137 struct ieee80211_radiotap_header *rthdr;
138 unsigned char *pos;
Johannes Berga144f372013-07-03 13:34:02 +0200139 __le32 *it_present;
140 u32 it_present_val;
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100141 u16 rx_flags = 0;
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200142 u16 channel_flags = 0;
Johannes Berga144f372013-07-03 13:34:02 +0200143 int mpdulen, chain;
144 unsigned long chains = status->chains;
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800145
146 mpdulen = skb->len;
147 if (!(has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)))
148 mpdulen += FCS_LEN;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200149
150 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
151 memset(rthdr, 0, rtap_len);
Johannes Berga144f372013-07-03 13:34:02 +0200152 it_present = &rthdr->it_present;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200153
154 /* radiotap header, set always present flags */
Emmanuel Grumbach0059b2b2014-02-05 16:36:01 +0200155 rthdr->it_len = cpu_to_le16(rtap_len);
Johannes Berga144f372013-07-03 13:34:02 +0200156 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
157 BIT(IEEE80211_RADIOTAP_CHANNEL) |
158 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200159
Johannes Berga144f372013-07-03 13:34:02 +0200160 if (!status->chains)
161 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
162
163 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
164 it_present_val |=
165 BIT(IEEE80211_RADIOTAP_EXT) |
166 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
167 put_unaligned_le32(it_present_val, it_present);
168 it_present++;
169 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
170 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
171 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200172
Johannes Berga144f372013-07-03 13:34:02 +0200173 put_unaligned_le32(it_present_val, it_present);
174
175 pos = (void *)(it_present + 1);
176
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200177 /* the order of the following fields is important */
178
179 /* IEEE80211_RADIOTAP_TSFT */
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800180 if (ieee80211_have_rx_timestamp(status)) {
Johannes Berg90b9e4462012-11-16 10:09:08 +0100181 /* padding */
182 while ((pos - (u8 *)rthdr) & 7)
183 *pos++ = 0;
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800184 put_unaligned_le64(
185 ieee80211_calculate_rx_timestamp(local, status,
186 mpdulen, 0),
187 pos);
Johannes Berg1df332e2012-10-26 00:09:11 +0200188 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200189 pos += 8;
190 }
191
192 /* IEEE80211_RADIOTAP_FLAGS */
Felix Fietkau973ef212012-04-16 14:56:48 +0200193 if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200194 *pos |= IEEE80211_RADIOTAP_F_FCS;
Johannes Bergaae89832009-03-13 12:52:10 +0100195 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
196 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
Bruno Randolfb4f28bb2008-07-30 17:19:55 +0200197 if (status->flag & RX_FLAG_SHORTPRE)
198 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200199 pos++;
200
201 /* IEEE80211_RADIOTAP_RATE */
Johannes Berg56146182012-11-09 15:07:02 +0100202 if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200203 /*
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100204 * Without rate information don't add it. If we have,
Mohammed Shafi Shajakhan38f37be2011-02-07 10:10:04 +0530205 * MCS information is a separate field in radiotap,
Johannes Berg73b48092011-04-18 17:05:21 +0200206 * added below. The byte here is needed as padding
207 * for the channel though, so initialise it to 0.
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200208 */
209 *pos = 0;
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200210 } else {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200211 int shift = 0;
Jouni Malinenebe6c7b2009-01-10 11:47:33 +0200212 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200213 if (status->flag & RX_FLAG_10MHZ)
214 shift = 1;
215 else if (status->flag & RX_FLAG_5MHZ)
216 shift = 2;
217 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200218 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200219 pos++;
220
221 /* IEEE80211_RADIOTAP_CHANNEL */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100222 put_unaligned_le16(status->freq, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200223 pos += 2;
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200224 if (status->flag & RX_FLAG_10MHZ)
225 channel_flags |= IEEE80211_CHAN_HALF;
226 else if (status->flag & RX_FLAG_5MHZ)
227 channel_flags |= IEEE80211_CHAN_QUARTER;
228
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200229 if (status->band == IEEE80211_BAND_5GHZ)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200230 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
Johannes Berg56146182012-11-09 15:07:02 +0100231 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200232 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100233 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200234 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100235 else if (rate)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200236 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100237 else
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200238 channel_flags |= IEEE80211_CHAN_2GHZ;
239 put_unaligned_le16(channel_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200240 pos += 2;
241
242 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
Felix Fietkaufe8431f2012-03-01 18:00:07 +0100243 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM &&
244 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200245 *pos = status->signal;
246 rthdr->it_present |=
247 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
248 pos++;
249 }
250
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200251 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
252
Johannes Berga144f372013-07-03 13:34:02 +0200253 if (!status->chains) {
254 /* IEEE80211_RADIOTAP_ANTENNA */
255 *pos = status->antenna;
256 pos++;
257 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200258
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200259 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
260
261 /* IEEE80211_RADIOTAP_RX_FLAGS */
262 /* ensure 2 byte alignment for the 2 byte field as required */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100263 if ((pos - (u8 *)rthdr) & 1)
Johannes Berg90b9e4462012-11-16 10:09:08 +0100264 *pos++ = 0;
Johannes Bergaae89832009-03-13 12:52:10 +0100265 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100266 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
267 put_unaligned_le16(rx_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200268 pos += 2;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100269
270 if (status->flag & RX_FLAG_HT) {
Oleksij Rempel786677d2013-05-24 12:05:45 +0200271 unsigned int stbc;
272
Johannes Berg6d744ba2011-01-27 14:13:17 +0100273 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
Johannes Bergac55d2f2012-05-10 09:09:10 +0200274 *pos++ = local->hw.radiotap_mcs_details;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100275 *pos = 0;
276 if (status->flag & RX_FLAG_SHORT_GI)
277 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
278 if (status->flag & RX_FLAG_40MHZ)
279 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
Johannes Bergac55d2f2012-05-10 09:09:10 +0200280 if (status->flag & RX_FLAG_HT_GF)
281 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
Oleksij Rempel786677d2013-05-24 12:05:45 +0200282 stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
283 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100284 pos++;
285 *pos++ = status->rate_idx;
286 }
Johannes Berg4c298672012-07-05 11:34:31 +0200287
288 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
289 u16 flags = 0;
290
291 /* ensure 4 byte alignment */
292 while ((pos - (u8 *)rthdr) & 3)
293 pos++;
294 rthdr->it_present |=
295 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
296 put_unaligned_le32(status->ampdu_reference, pos);
297 pos += 4;
298 if (status->flag & RX_FLAG_AMPDU_REPORT_ZEROLEN)
299 flags |= IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN;
300 if (status->flag & RX_FLAG_AMPDU_IS_ZEROLEN)
301 flags |= IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN;
302 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
303 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
304 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
305 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
306 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
307 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
308 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
309 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
310 put_unaligned_le16(flags, pos);
311 pos += 2;
312 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
313 *pos++ = status->ampdu_delimiter_crc;
314 else
315 *pos++ = 0;
316 *pos++ = 0;
317 }
Johannes Berg90b9e4462012-11-16 10:09:08 +0100318
Johannes Berg51648922012-11-22 23:00:18 +0100319 if (status->flag & RX_FLAG_VHT) {
320 u16 known = local->hw.radiotap_vht_details;
321
322 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
323 /* known field - how to handle 80+80? */
324 if (status->flag & RX_FLAG_80P80MHZ)
325 known &= ~IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
326 put_unaligned_le16(known, pos);
327 pos += 2;
328 /* flags */
329 if (status->flag & RX_FLAG_SHORT_GI)
330 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
331 pos++;
332 /* bandwidth */
333 if (status->flag & RX_FLAG_80MHZ)
334 *pos++ = 4;
335 else if (status->flag & RX_FLAG_80P80MHZ)
336 *pos++ = 0; /* marked not known above */
337 else if (status->flag & RX_FLAG_160MHZ)
338 *pos++ = 11;
339 else if (status->flag & RX_FLAG_40MHZ)
340 *pos++ = 1;
341 else /* 20 MHz */
342 *pos++ = 0;
343 /* MCS/NSS */
344 *pos = (status->rate_idx << 4) | status->vht_nss;
345 pos += 4;
346 /* coding field */
347 pos++;
348 /* group ID */
349 pos++;
350 /* partial_aid */
351 pos += 2;
352 }
353
Johannes Berga144f372013-07-03 13:34:02 +0200354 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
355 *pos++ = status->chain_signal[chain];
356 *pos++ = chain;
357 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200358}
359
Johannes Bergb2e77712007-09-26 15:19:39 +0200360/*
361 * This function copies a received frame to all monitor interfaces and
362 * returns a cleaned-up SKB that no longer includes the FCS nor the
363 * radiotap header the driver might have added.
364 */
365static struct sk_buff *
366ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
Johannes Berg8318d782008-01-24 19:38:38 +0100367 struct ieee80211_rate *rate)
Johannes Bergb2e77712007-09-26 15:19:39 +0200368{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200369 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200370 struct ieee80211_sub_if_data *sdata;
Johannes Berg293702a2012-03-02 13:18:19 +0100371 int needed_headroom;
Johannes Bergb2e77712007-09-26 15:19:39 +0200372 struct sk_buff *skb, *skb2;
373 struct net_device *prev_dev = NULL;
374 int present_fcs_len = 0;
Johannes Bergb2e77712007-09-26 15:19:39 +0200375
376 /*
377 * First, we may need to make a copy of the skb because
378 * (1) we need to modify it for radiotap (if not present), and
379 * (2) the other RX handlers will modify the skb we got.
380 *
381 * We don't need to, of course, if we aren't going to return
382 * the SKB because it has a bad FCS/PLCP checksum.
383 */
Johannes Berg0869aea2009-10-28 10:03:35 +0100384
Johannes Bergb2e77712007-09-26 15:19:39 +0200385 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
386 present_fcs_len = FCS_LEN;
387
Emmanuel Grumbach0059b2b2014-02-05 16:36:01 +0200388 /* ensure hdr->frame_control is in skb head */
389 if (!pskb_may_pull(origskb, 2)) {
Zhu Yie3cf8b32010-03-29 17:35:07 +0800390 dev_kfree_skb(origskb);
391 return NULL;
392 }
393
Johannes Bergb2e77712007-09-26 15:19:39 +0200394 if (!local->monitors) {
Johannes Berg0869aea2009-10-28 10:03:35 +0100395 if (should_drop_frame(origskb, present_fcs_len)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200396 dev_kfree_skb(origskb);
397 return NULL;
398 }
399
Johannes Berg0869aea2009-10-28 10:03:35 +0100400 return remove_monitor_info(local, origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200401 }
402
Helmut Schaa751413e2012-12-05 14:36:12 +0100403 /* room for the radiotap header based on driver features */
404 needed_headroom = ieee80211_rx_radiotap_space(local, status);
405
Johannes Berg0869aea2009-10-28 10:03:35 +0100406 if (should_drop_frame(origskb, present_fcs_len)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200407 /* only need to expand headroom if necessary */
408 skb = origskb;
409 origskb = NULL;
410
411 /*
412 * This shouldn't trigger often because most devices have an
413 * RX header they pull before we get here, and that should
414 * be big enough for our radiotap information. We should
415 * probably export the length to drivers so that we can have
416 * them allocate enough headroom to start with.
417 */
418 if (skb_headroom(skb) < needed_headroom &&
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100419 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200420 dev_kfree_skb(skb);
421 return NULL;
422 }
423 } else {
424 /*
425 * Need to make a copy and possibly remove radiotap header
426 * and FCS from the original.
427 */
428 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
429
Johannes Berg0869aea2009-10-28 10:03:35 +0100430 origskb = remove_monitor_info(local, origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200431
432 if (!skb)
433 return origskb;
434 }
435
Johannes Berg0869aea2009-10-28 10:03:35 +0100436 /* prepend radiotap information */
Felix Fietkau973ef212012-04-16 14:56:48 +0200437 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
438 true);
Johannes Bergb2e77712007-09-26 15:19:39 +0200439
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100440 skb_reset_mac_header(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200441 skb->ip_summed = CHECKSUM_UNNECESSARY;
442 skb->pkt_type = PACKET_OTHERHOST;
443 skb->protocol = htons(ETH_P_802_2);
444
445 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200446 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
Johannes Bergb2e77712007-09-26 15:19:39 +0200447 continue;
448
Michael Wu3d30d942008-01-31 19:48:27 +0100449 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
450 continue;
451
Johannes Berg9607e6b2009-12-23 13:15:31 +0100452 if (!ieee80211_sdata_running(sdata))
Johannes Berg47846c92009-11-25 17:46:19 +0100453 continue;
454
Johannes Bergb2e77712007-09-26 15:19:39 +0200455 if (prev_dev) {
456 skb2 = skb_clone(skb, GFP_ATOMIC);
457 if (skb2) {
458 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400459 netif_receive_skb(skb2);
Johannes Bergb2e77712007-09-26 15:19:39 +0200460 }
461 }
462
463 prev_dev = sdata->dev;
464 sdata->dev->stats.rx_packets++;
465 sdata->dev->stats.rx_bytes += skb->len;
466 }
467
468 if (prev_dev) {
469 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400470 netif_receive_skb(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200471 } else
472 dev_kfree_skb(skb);
473
474 return origskb;
475}
476
Johannes Berg5cf121c2008-02-25 16:27:43 +0100477static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +0200478{
Harvey Harrison238f74a2008-07-02 11:05:34 -0700479 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200480 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg9e262972011-07-07 18:45:03 +0200481 int tid, seqno_idx, security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200482
483 /* does the frame have a qos control field? */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700484 if (ieee80211_is_data_qos(hdr->frame_control)) {
485 u8 *qc = ieee80211_get_qos_ctl(hdr);
Johannes Berg6e0d1142007-07-27 15:43:22 +0200486 /* frame has qos control */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700487 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
Johannes Berg04b7dcf2011-06-22 10:06:59 +0200488 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
Johannes Berg554891e2010-09-24 12:38:25 +0200489 status->rx_flags |= IEEE80211_RX_AMSDU;
Johannes Berg9e262972011-07-07 18:45:03 +0200490
491 seqno_idx = tid;
492 security_idx = tid;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200493 } else {
Johannes Berg1411f9b2008-07-10 10:11:02 +0200494 /*
495 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
496 *
497 * Sequence numbers for management frames, QoS data
498 * frames with a broadcast/multicast address in the
499 * Address 1 field, and all non-QoS data frames sent
500 * by QoS STAs are assigned using an additional single
501 * modulo-4096 counter, [...]
502 *
503 * We also use that counter for non-QoS STAs.
504 */
Johannes Berg5a306f52012-11-14 23:22:21 +0100505 seqno_idx = IEEE80211_NUM_TIDS;
Johannes Berg9e262972011-07-07 18:45:03 +0200506 security_idx = 0;
507 if (ieee80211_is_mgmt(hdr->frame_control))
Johannes Berg5a306f52012-11-14 23:22:21 +0100508 security_idx = IEEE80211_NUM_TIDS;
Johannes Berg9e262972011-07-07 18:45:03 +0200509 tid = 0;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200510 }
Johannes Berg52865dfd2007-07-27 15:43:22 +0200511
Johannes Berg9e262972011-07-07 18:45:03 +0200512 rx->seqno_idx = seqno_idx;
513 rx->security_idx = security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200514 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
515 * For now, set skb->priority to 0 for other cases. */
516 rx->skb->priority = (tid > 7) ? 0 : tid;
Johannes Berg38f37142008-01-29 17:07:43 +0100517}
Johannes Berg6e0d1142007-07-27 15:43:22 +0200518
Johannes Bergd1c3a372009-01-07 00:26:10 +0100519/**
520 * DOC: Packet alignment
521 *
522 * Drivers always need to pass packets that are aligned to two-byte boundaries
523 * to the stack.
524 *
525 * Additionally, should, if possible, align the payload data in a way that
526 * guarantees that the contained IP header is aligned to a four-byte
527 * boundary. In the case of regular frames, this simply means aligning the
528 * payload to a four-byte boundary (because either the IP header is directly
529 * contained, or IV/RFC1042 headers that have a length divisible by four are
Kalle Valo59d9cb02009-12-17 13:54:57 +0100530 * in front of it). If the payload data is not properly aligned and the
531 * architecture doesn't support efficient unaligned operations, mac80211
532 * will align the data.
Johannes Bergd1c3a372009-01-07 00:26:10 +0100533 *
534 * With A-MSDU frames, however, the payload data address must yield two modulo
535 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
536 * push the IP header further back to a multiple of four again. Thankfully, the
537 * specs were sane enough this time around to require padding each A-MSDU
538 * subframe to a length that is a multiple of four.
539 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300540 * Padding like Atheros hardware adds which is between the 802.11 header and
Johannes Bergd1c3a372009-01-07 00:26:10 +0100541 * the payload is not supported, the driver is required to move the 802.11
542 * header to be directly in front of the payload in that case.
543 */
544static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
Johannes Berg38f37142008-01-29 17:07:43 +0100545{
Kalle Valo59d9cb02009-12-17 13:54:57 +0100546#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
547 WARN_ONCE((unsigned long)rx->skb->data & 1,
548 "unaligned packet at 0x%p\n", rx->skb->data);
Johannes Bergd1c3a372009-01-07 00:26:10 +0100549#endif
Johannes Berg6e0d1142007-07-27 15:43:22 +0200550}
551
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +0200552
Johannes Berg571ecf62007-07-27 15:43:22 +0200553/* rx handlers */
554
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200555static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
556{
557 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
558
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100559 if (is_multicast_ether_addr(hdr->addr1))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200560 return 0;
561
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100562 return ieee80211_is_robust_mgmt_frame(skb);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200563}
564
565
566static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
567{
568 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
569
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100570 if (!is_multicast_ether_addr(hdr->addr1))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200571 return 0;
572
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100573 return ieee80211_is_robust_mgmt_frame(skb);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200574}
575
576
577/* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
578static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
579{
580 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
581 struct ieee80211_mmie *mmie;
582
Johannes Berg1df332e2012-10-26 00:09:11 +0200583 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200584 return -1;
585
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100586 if (!ieee80211_is_robust_mgmt_frame(skb))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200587 return -1; /* not a robust management frame */
588
589 mmie = (struct ieee80211_mmie *)
590 (skb->data + skb->len - sizeof(*mmie));
591 if (mmie->element_id != WLAN_EID_MMIE ||
592 mmie->length != sizeof(*mmie) - 2)
593 return -1;
594
595 return le16_to_cpu(mmie->key_id);
596}
597
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200598static int iwl80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
599 struct sk_buff *skb)
600{
601 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
602 __le16 fc;
603 int hdrlen;
604 u8 keyid;
605
606 fc = hdr->frame_control;
607 hdrlen = ieee80211_hdrlen(fc);
608
609 if (skb->len < hdrlen + cs->hdr_len)
610 return -EINVAL;
611
612 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
613 keyid &= cs->key_idx_mask;
614 keyid >>= cs->key_idx_shift;
615
616 return keyid;
617}
618
Johannes Berg1df332e2012-10-26 00:09:11 +0200619static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100620{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700621 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg47846c92009-11-25 17:46:19 +0100622 char *dev_addr = rx->sdata->vif.addr;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100623
Harvey Harrisona7767f92008-07-02 16:30:51 -0700624 if (ieee80211_is_data(hdr->frame_control)) {
Javier Cardona3c5772a2009-08-10 12:15:48 -0700625 if (is_multicast_ether_addr(hdr->addr1)) {
626 if (ieee80211_has_tods(hdr->frame_control) ||
Johannes Berg1df332e2012-10-26 00:09:11 +0200627 !ieee80211_has_fromds(hdr->frame_control))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700628 return RX_DROP_MONITOR;
Joe Perchesb203ca32012-05-08 18:56:52 +0000629 if (ether_addr_equal(hdr->addr3, dev_addr))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700630 return RX_DROP_MONITOR;
631 } else {
632 if (!ieee80211_has_a4(hdr->frame_control))
633 return RX_DROP_MONITOR;
Joe Perchesb203ca32012-05-08 18:56:52 +0000634 if (ether_addr_equal(hdr->addr4, dev_addr))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700635 return RX_DROP_MONITOR;
636 }
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100637 }
638
639 /* If there is not an established peer link and this is not a peer link
640 * establisment frame, beacon or probe, drop the frame.
641 */
642
Javier Cardona57cf8042011-05-13 10:45:43 -0700643 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100644 struct ieee80211_mgmt *mgmt;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100645
Harvey Harrisona7767f92008-07-02 16:30:51 -0700646 if (!ieee80211_is_mgmt(hdr->frame_control))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100647 return RX_DROP_MONITOR;
648
Harvey Harrisona7767f92008-07-02 16:30:51 -0700649 if (ieee80211_is_action(hdr->frame_control)) {
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700650 u8 category;
Johannes Berg9b395bc2012-10-26 00:36:40 +0200651
652 /* make sure category field is present */
653 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
654 return RX_DROP_MONITOR;
655
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100656 mgmt = (struct ieee80211_mgmt *)hdr;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700657 category = mgmt->u.action.category;
658 if (category != WLAN_CATEGORY_MESH_ACTION &&
Johannes Berg1df332e2012-10-26 00:09:11 +0200659 category != WLAN_CATEGORY_SELF_PROTECTED)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100660 return RX_DROP_MONITOR;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100661 return RX_CONTINUE;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100662 }
663
Harvey Harrisona7767f92008-07-02 16:30:51 -0700664 if (ieee80211_is_probe_req(hdr->frame_control) ||
665 ieee80211_is_probe_resp(hdr->frame_control) ||
Javier Cardona71839122011-04-07 15:08:31 -0700666 ieee80211_is_beacon(hdr->frame_control) ||
667 ieee80211_is_auth(hdr->frame_control))
Harvey Harrisona7767f92008-07-02 16:30:51 -0700668 return RX_CONTINUE;
669
670 return RX_DROP_MONITOR;
Harvey Harrisona7767f92008-07-02 16:30:51 -0700671 }
672
Johannes Berg902acc72008-02-23 15:17:19 +0100673 return RX_CONTINUE;
674}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100675
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200676static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100677 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000678 int index,
679 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100680{
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100681 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
Christian Lamparter4cfda472010-12-27 23:21:26 +0100682 struct ieee80211_rx_status *status;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100683
Johannes Bergdd318572010-11-29 11:09:16 +0100684 lockdep_assert_held(&tid_agg_rx->reorder_lock);
685
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100686 if (!skb)
687 goto no_frame;
688
Christian Lamparter071d9ac2010-08-05 01:36:36 +0200689 /* release the frame from the reorder ring buffer */
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100690 tid_agg_rx->stored_mpdu_num--;
691 tid_agg_rx->reorder_buf[index] = NULL;
Christian Lamparter4cfda472010-12-27 23:21:26 +0100692 status = IEEE80211_SKB_RXCB(skb);
693 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000694 __skb_queue_tail(frames, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100695
696no_frame:
Johannes Berg9a886582013-02-15 19:25:00 +0100697 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100698}
699
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200700static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100701 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000702 u16 head_seq_num,
703 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100704{
705 int index;
706
Johannes Bergdd318572010-11-29 11:09:16 +0100707 lockdep_assert_held(&tid_agg_rx->reorder_lock);
708
Johannes Berg9a886582013-02-15 19:25:00 +0100709 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
Karl Beldan2e3049b2013-10-24 15:53:32 +0200710 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000711 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
712 frames);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100713 }
714}
715
716/*
717 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
718 * the skb was added to the buffer longer than this time ago, the earlier
719 * frames that have not yet been received are assumed to be lost and the skb
720 * can be released for processing. This may also release other skb's from the
721 * reorder buffer if there are no additional gaps between the frames.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200722 *
723 * Callers must hold tid_agg_rx->reorder_lock.
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100724 */
725#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
726
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200727static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000728 struct tid_ampdu_rx *tid_agg_rx,
729 struct sk_buff_head *frames)
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200730{
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200731 int index, j;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200732
Johannes Bergdd318572010-11-29 11:09:16 +0100733 lockdep_assert_held(&tid_agg_rx->reorder_lock);
734
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200735 /* release the buffer until next missing frame */
Karl Beldan2e3049b2013-10-24 15:53:32 +0200736 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200737 if (!tid_agg_rx->reorder_buf[index] &&
Eliad Peller07ae2df2012-02-01 18:48:09 +0200738 tid_agg_rx->stored_mpdu_num) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200739 /*
740 * No buffers ready to be released, but check whether any
741 * frames in the reorder buffer have timed out.
742 */
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200743 int skipped = 1;
744 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
745 j = (j + 1) % tid_agg_rx->buf_size) {
746 if (!tid_agg_rx->reorder_buf[j]) {
747 skipped++;
748 continue;
749 }
Daniel Halperin499fe9a2011-03-24 16:01:48 -0700750 if (skipped &&
751 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200752 HT_RX_REORDER_BUF_TIMEOUT))
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200753 goto set_release_timer;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200754
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200755 ht_dbg_ratelimited(sdata,
756 "release an RX reorder frame due to timeout on earlier frames\n");
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000757 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
758 frames);
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200759
760 /*
761 * Increment the head seq# also for the skipped slots.
762 */
763 tid_agg_rx->head_seq_num =
Johannes Berg9a886582013-02-15 19:25:00 +0100764 (tid_agg_rx->head_seq_num +
765 skipped) & IEEE80211_SN_MASK;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200766 skipped = 0;
767 }
768 } else while (tid_agg_rx->reorder_buf[index]) {
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000769 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
770 frames);
Karl Beldan2e3049b2013-10-24 15:53:32 +0200771 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200772 }
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200773
774 if (tid_agg_rx->stored_mpdu_num) {
Karl Beldan2e3049b2013-10-24 15:53:32 +0200775 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200776
777 for (; j != (index - 1) % tid_agg_rx->buf_size;
778 j = (j + 1) % tid_agg_rx->buf_size) {
779 if (tid_agg_rx->reorder_buf[j])
780 break;
781 }
782
783 set_release_timer:
784
785 mod_timer(&tid_agg_rx->reorder_timer,
Christian Lamparter334df732011-04-24 20:41:16 +0200786 tid_agg_rx->reorder_time[j] + 1 +
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200787 HT_RX_REORDER_BUF_TIMEOUT);
788 } else {
789 del_timer(&tid_agg_rx->reorder_timer);
790 }
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200791}
792
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100793/*
794 * As this function belongs to the RX path it must be under
795 * rcu_read_lock protection. It returns false if the frame
796 * can be processed immediately, true if it was consumed.
797 */
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200798static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100799 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000800 struct sk_buff *skb,
801 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100802{
803 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
804 u16 sc = le16_to_cpu(hdr->seq_ctrl);
805 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
806 u16 head_seq_num, buf_size;
807 int index;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200808 bool ret = true;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100809
Johannes Bergdd318572010-11-29 11:09:16 +0100810 spin_lock(&tid_agg_rx->reorder_lock);
811
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100812 buf_size = tid_agg_rx->buf_size;
813 head_seq_num = tid_agg_rx->head_seq_num;
814
815 /* frame with out of date sequence number */
Johannes Berg9a886582013-02-15 19:25:00 +0100816 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100817 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200818 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100819 }
820
821 /*
822 * If frame the sequence number exceeds our buffering window
823 * size release some previous frames to make room for this one.
824 */
Johannes Berg9a886582013-02-15 19:25:00 +0100825 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
826 head_seq_num = ieee80211_sn_inc(
827 ieee80211_sn_sub(mpdu_seq_num, buf_size));
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100828 /* release stored frames up to new head to stack */
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200829 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000830 head_seq_num, frames);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100831 }
832
833 /* Now the new frame is always in the range of the reordering buffer */
834
Karl Beldan2e3049b2013-10-24 15:53:32 +0200835 index = mpdu_seq_num % tid_agg_rx->buf_size;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100836
837 /* check if we already stored this frame */
838 if (tid_agg_rx->reorder_buf[index]) {
839 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200840 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100841 }
842
843 /*
844 * If the current MPDU is in the right order and nothing else
845 * is stored we can process it directly, no need to buffer it.
Johannes Bergc835b212011-03-15 23:17:01 +0100846 * If it is first but there's something stored, we may be able
847 * to release frames after this one.
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100848 */
849 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
850 tid_agg_rx->stored_mpdu_num == 0) {
Johannes Berg9a886582013-02-15 19:25:00 +0100851 tid_agg_rx->head_seq_num =
852 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200853 ret = false;
854 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100855 }
856
857 /* put the frame in the reordering buffer */
858 tid_agg_rx->reorder_buf[index] = skb;
859 tid_agg_rx->reorder_time[index] = jiffies;
860 tid_agg_rx->stored_mpdu_num++;
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000861 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100862
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200863 out:
864 spin_unlock(&tid_agg_rx->reorder_lock);
865 return ret;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100866}
867
868/*
869 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
870 * true if the MPDU was buffered, false if it should be processed.
871 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000872static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
873 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100874{
Johannes Berg2569a822009-11-25 17:46:17 +0100875 struct sk_buff *skb = rx->skb;
876 struct ieee80211_local *local = rx->local;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100877 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Thomas Pedersen660c6a42011-11-03 21:11:12 -0700878 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg2569a822009-11-25 17:46:17 +0100879 struct sta_info *sta = rx->sta;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100880 struct tid_ampdu_rx *tid_agg_rx;
881 u16 sc;
Thomas Pedersen6cc00d52011-11-03 21:11:11 -0700882 u8 tid, ack_policy;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100883
Johannes Berg051a41f2013-11-20 11:28:27 +0100884 if (!ieee80211_is_data_qos(hdr->frame_control) ||
885 is_multicast_ether_addr(hdr->addr1))
Johannes Berg2569a822009-11-25 17:46:17 +0100886 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100887
888 /*
889 * filter the QoS data rx stream according to
890 * STA/TID and check if this STA/TID is on aggregation
891 */
892
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100893 if (!sta)
Johannes Berg2569a822009-11-25 17:46:17 +0100894 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100895
Thomas Pedersen6cc00d52011-11-03 21:11:11 -0700896 ack_policy = *ieee80211_get_qos_ctl(hdr) &
897 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100898 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
899
Johannes Berga87f7362010-06-10 10:21:38 +0200900 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
901 if (!tid_agg_rx)
902 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100903
904 /* qos null data frames are excluded */
905 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
Johannes Berga87f7362010-06-10 10:21:38 +0200906 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100907
Thomas Pedersen6cc00d52011-11-03 21:11:11 -0700908 /* not part of a BA session */
909 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
910 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
911 goto dont_reorder;
912
Thomas Pedersen660c6a42011-11-03 21:11:12 -0700913 /* not actually part of this BA session */
914 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
915 goto dont_reorder;
916
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100917 /* new, potentially un-ordered, ampdu frame - process it */
918
919 /* reset session timer */
920 if (tid_agg_rx->timeout)
Felix Fietkau12d3952f2012-03-18 22:58:06 +0100921 tid_agg_rx->last_rx = jiffies;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100922
923 /* if this mpdu is fragmented - terminate rx aggregation session */
924 sc = le16_to_cpu(hdr->seq_ctrl);
925 if (sc & IEEE80211_SCTL_FRAG) {
Johannes Bergc1475ca2010-06-10 10:21:37 +0200926 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg344eec62010-06-10 10:21:36 +0200927 skb_queue_tail(&rx->sdata->skb_queue, skb);
928 ieee80211_queue_work(&local->hw, &rx->sdata->work);
Johannes Berg2569a822009-11-25 17:46:17 +0100929 return;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100930 }
931
Johannes Berga87f7362010-06-10 10:21:38 +0200932 /*
933 * No locking needed -- we will only ever process one
934 * RX packet at a time, and thus own tid_agg_rx. All
935 * other code manipulating it needs to (and does) make
936 * sure that we cannot get to it any more before doing
937 * anything with it.
938 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000939 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
940 frames))
Johannes Berg2569a822009-11-25 17:46:17 +0100941 return;
942
943 dont_reorder:
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000944 __skb_queue_tail(frames, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100945}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100946
Johannes Berg49461622008-06-30 15:10:45 +0200947static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100948ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +0200949{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700950 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200951 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +0200952
Johannes Berg6b0f3272013-07-11 22:33:26 +0200953 /*
954 * Drop duplicate 802.11 retransmissions
955 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
956 */
957 if (rx->skb->len >= 24 && rx->sta &&
958 !ieee80211_is_ctl(hdr->frame_control) &&
959 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
960 !is_multicast_ether_addr(hdr->addr1)) {
Harvey Harrisona7767f92008-07-02 16:30:51 -0700961 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
Johannes Berg9e262972011-07-07 18:45:03 +0200962 rx->sta->last_seq_ctrl[rx->seqno_idx] ==
Johannes Berg571ecf62007-07-27 15:43:22 +0200963 hdr->seq_ctrl)) {
Johannes Berg554891e2010-09-24 12:38:25 +0200964 if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
Johannes Berg571ecf62007-07-27 15:43:22 +0200965 rx->local->dot11FrameDuplicateCount++;
966 rx->sta->num_duplicates++;
967 }
Felix Fietkaub1f93312011-02-04 19:20:08 +0100968 return RX_DROP_UNUSABLE;
Michal Kazior0cfcefe2013-09-23 15:34:38 +0200969 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
Johannes Berg9e262972011-07-07 18:45:03 +0200970 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
Michal Kazior0cfcefe2013-09-23 15:34:38 +0200971 }
Johannes Berg571ecf62007-07-27 15:43:22 +0200972 }
973
Johannes Berg571ecf62007-07-27 15:43:22 +0200974 if (unlikely(rx->skb->len < 16)) {
975 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
Johannes Berge4c26ad2008-01-31 19:48:21 +0100976 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +0200977 }
978
Johannes Berg571ecf62007-07-27 15:43:22 +0200979 /* Drop disallowed frame classes based on STA auth/assoc state;
980 * IEEE 802.11, Chap 5.5.
981 *
Johannes Bergccd7b362008-09-11 00:01:56 +0200982 * mac80211 filters only based on association state, i.e. it drops
983 * Class 3 frames from not associated stations. hostapd sends
Johannes Berg571ecf62007-07-27 15:43:22 +0200984 * deauth/disassoc frames when needed. In addition, hostapd is
985 * responsible for filtering on both auth and assoc states.
986 */
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100987
Johannes Berg902acc72008-02-23 15:17:19 +0100988 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100989 return ieee80211_rx_mesh_check(rx);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100990
Harvey Harrisona7767f92008-07-02 16:30:51 -0700991 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
992 ieee80211_is_pspoll(hdr->frame_control)) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200993 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Bill Jordan1be7fe82010-10-01 11:20:41 -0400994 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200995 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
Johannes Berg7852e362012-01-20 13:55:24 +0100996 /*
997 * accept port control frames from the AP even when it's not
998 * yet marked ASSOC to prevent a race where we don't set the
999 * assoc bit quickly enough before it sends the first frame
1000 */
1001 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
Guy Eilam2a33bee2011-08-17 15:18:15 +03001002 ieee80211_is_data_present(hdr->frame_control)) {
Johannes Berg6dbda2d2012-10-26 00:41:23 +02001003 unsigned int hdrlen;
1004 __be16 ethertype;
Guy Eilam2a33bee2011-08-17 15:18:15 +03001005
Johannes Berg6dbda2d2012-10-26 00:41:23 +02001006 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1007
1008 if (rx->skb->len < hdrlen + 8)
1009 return RX_DROP_MONITOR;
1010
1011 skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
1012 if (ethertype == rx->sdata->control_port_protocol)
Guy Eilam2a33bee2011-08-17 15:18:15 +03001013 return RX_CONTINUE;
1014 }
Johannes Berg21fc7562011-11-04 11:18:13 +01001015
1016 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1017 cfg80211_rx_spurious_frame(rx->sdata->dev,
1018 hdr->addr2,
1019 GFP_ATOMIC))
1020 return RX_DROP_UNUSABLE;
1021
Johannes Berge4c26ad2008-01-31 19:48:21 +01001022 return RX_DROP_MONITOR;
Guy Eilam2a33bee2011-08-17 15:18:15 +03001023 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001024
Johannes Berg9ae54c82008-01-31 19:48:20 +01001025 return RX_CONTINUE;
Johannes Berg570bd532007-07-27 15:43:22 +02001026}
1027
1028
Johannes Berg49461622008-06-30 15:10:45 +02001029static ieee80211_rx_result debug_noinline
Kalle Valo572e0012009-02-10 17:09:31 +02001030ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1031{
1032 struct ieee80211_local *local;
1033 struct ieee80211_hdr *hdr;
1034 struct sk_buff *skb;
1035
1036 local = rx->local;
1037 skb = rx->skb;
1038 hdr = (struct ieee80211_hdr *) skb->data;
1039
1040 if (!local->pspolling)
1041 return RX_CONTINUE;
1042
1043 if (!ieee80211_has_fromds(hdr->frame_control))
1044 /* this is not from AP */
1045 return RX_CONTINUE;
1046
1047 if (!ieee80211_is_data(hdr->frame_control))
1048 return RX_CONTINUE;
1049
1050 if (!ieee80211_has_moredata(hdr->frame_control)) {
1051 /* AP has no more frames buffered for us */
1052 local->pspolling = false;
1053 return RX_CONTINUE;
1054 }
1055
1056 /* more data bit is set, let's request a new frame from the AP */
1057 ieee80211_send_pspoll(local, rx->sdata);
1058
1059 return RX_CONTINUE;
1060}
1061
Marco Porschd012a602012-10-10 12:39:50 -07001062static void sta_ps_start(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001063{
Johannes Berg133b8222008-09-16 14:18:59 +02001064 struct ieee80211_sub_if_data *sdata = sta->sdata;
Christian Lamparter4571d3b2008-11-30 00:48:41 +01001065 struct ieee80211_local *local = sdata->local;
Marco Porschd012a602012-10-10 12:39:50 -07001066 struct ps_data *ps;
Joe Perches0795af52007-10-03 17:59:30 -07001067
Marco Porschd012a602012-10-10 12:39:50 -07001068 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1069 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1070 ps = &sdata->bss->ps;
1071 else
1072 return;
1073
1074 atomic_inc(&ps->num_sta_ps);
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001075 set_sta_flag(sta, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001076 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1077 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001078 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1079 sta->sta.addr, sta->sta.aid);
Johannes Berg571ecf62007-07-27 15:43:22 +02001080}
1081
Marco Porschd012a602012-10-10 12:39:50 -07001082static void sta_ps_end(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001083{
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001084 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1085 sta->sta.addr, sta->sta.aid);
Johannes Berg004c8722008-02-20 11:21:35 +01001086
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001087 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001088 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1089 sta->sta.addr, sta->sta.aid);
Johannes Bergaf818582009-11-06 11:35:50 +01001090 return;
1091 }
1092
1093 ieee80211_sta_ps_deliver_wakeup(sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001094}
1095
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001096int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1097{
1098 struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1099 bool in_ps;
1100
1101 WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
1102
1103 /* Don't let the same PS state be set twice */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001104 in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001105 if ((start && in_ps) || (!start && !in_ps))
1106 return -EINVAL;
1107
1108 if (start)
Marco Porschd012a602012-10-10 12:39:50 -07001109 sta_ps_start(sta_inf);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001110 else
Marco Porschd012a602012-10-10 12:39:50 -07001111 sta_ps_end(sta_inf);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001112
1113 return 0;
1114}
1115EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1116
Johannes Berg49461622008-06-30 15:10:45 +02001117static ieee80211_rx_result debug_noinline
Johannes Berg47086fc2011-09-29 16:04:33 +02001118ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1119{
1120 struct ieee80211_sub_if_data *sdata = rx->sdata;
1121 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1122 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1123 int tid, ac;
1124
1125 if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH))
1126 return RX_CONTINUE;
1127
1128 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1129 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1130 return RX_CONTINUE;
1131
1132 /*
1133 * The device handles station powersave, so don't do anything about
1134 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1135 * it to mac80211 since they're handled.)
1136 */
1137 if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
1138 return RX_CONTINUE;
1139
1140 /*
1141 * Don't do anything if the station isn't already asleep. In
1142 * the uAPSD case, the station will probably be marked asleep,
1143 * in the PS-Poll case the station must be confused ...
1144 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001145 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
Johannes Berg47086fc2011-09-29 16:04:33 +02001146 return RX_CONTINUE;
1147
1148 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001149 if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
1150 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
Johannes Bergdeeaee12011-09-29 16:04:35 +02001151 ieee80211_sta_ps_deliver_poll_response(rx->sta);
1152 else
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001153 set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
Johannes Bergdeeaee12011-09-29 16:04:35 +02001154 }
Johannes Berg47086fc2011-09-29 16:04:33 +02001155
1156 /* Free PS Poll skb here instead of returning RX_DROP that would
1157 * count as an dropped frame. */
1158 dev_kfree_skb(rx->skb);
1159
1160 return RX_QUEUED;
1161 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1162 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1163 ieee80211_has_pm(hdr->frame_control) &&
1164 (ieee80211_is_data_qos(hdr->frame_control) ||
1165 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1166 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1167 ac = ieee802_1d_to_ac[tid & 7];
1168
1169 /*
1170 * If this AC is not trigger-enabled do nothing.
1171 *
1172 * NB: This could/should check a separate bitmap of trigger-
1173 * enabled queues, but for now we only implement uAPSD w/o
1174 * TSPEC changes to the ACs, so they're always the same.
1175 */
1176 if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
1177 return RX_CONTINUE;
1178
1179 /* if we are in a service period, do nothing */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001180 if (test_sta_flag(rx->sta, WLAN_STA_SP))
Johannes Berg47086fc2011-09-29 16:04:33 +02001181 return RX_CONTINUE;
1182
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001183 if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
Johannes Berg47086fc2011-09-29 16:04:33 +02001184 ieee80211_sta_ps_deliver_uapsd(rx->sta);
1185 else
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001186 set_sta_flag(rx->sta, WLAN_STA_UAPSD);
Johannes Berg47086fc2011-09-29 16:04:33 +02001187 }
1188
1189 return RX_CONTINUE;
1190}
1191
1192static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001193ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001194{
1195 struct sta_info *sta = rx->sta;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001196 struct sk_buff *skb = rx->skb;
1197 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1198 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkauef0621e2013-04-22 16:29:31 +02001199 int i;
Johannes Berg571ecf62007-07-27 15:43:22 +02001200
1201 if (!sta)
Johannes Berg9ae54c82008-01-31 19:48:20 +01001202 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001203
Johannes Bergb291ba12009-07-10 15:29:03 +02001204 /*
1205 * Update last_rx only for IBSS packets which are for the current
Antonio Quartullie584da5e2012-11-25 23:13:42 +01001206 * BSSID and for station already AUTHORIZED to avoid keeping the
1207 * current IBSS network alive in cases where other STAs start
1208 * using different BSSID. This will also give the station another
1209 * chance to restart the authentication/authorization in case
1210 * something went wrong the first time.
Johannes Bergb291ba12009-07-10 15:29:03 +02001211 */
Johannes Berg05c914f2008-09-11 00:01:58 +02001212 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Ron Rindjunsky71364712007-12-25 17:00:36 +02001213 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
Johannes Berg05c914f2008-09-11 00:01:58 +02001214 NL80211_IFTYPE_ADHOC);
Antonio Quartullie584da5e2012-11-25 23:13:42 +01001215 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1216 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001217 sta->last_rx = jiffies;
Felix Fietkau3af63342011-02-27 22:08:01 +01001218 if (ieee80211_is_data(hdr->frame_control)) {
1219 sta->last_rx_rate_idx = status->rate_idx;
1220 sta->last_rx_rate_flag = status->flag;
Johannes Berg56146182012-11-09 15:07:02 +01001221 sta->last_rx_rate_vht_nss = status->vht_nss;
Felix Fietkau3af63342011-02-27 22:08:01 +01001222 }
1223 }
Johannes Bergb291ba12009-07-10 15:29:03 +02001224 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1225 /*
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001226 * Mesh beacons will update last_rx when if they are found to
1227 * match the current local configuration when processed.
Johannes Berg571ecf62007-07-27 15:43:22 +02001228 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001229 sta->last_rx = jiffies;
Felix Fietkau3af63342011-02-27 22:08:01 +01001230 if (ieee80211_is_data(hdr->frame_control)) {
1231 sta->last_rx_rate_idx = status->rate_idx;
1232 sta->last_rx_rate_flag = status->flag;
Johannes Berg56146182012-11-09 15:07:02 +01001233 sta->last_rx_rate_vht_nss = status->vht_nss;
Felix Fietkau3af63342011-02-27 22:08:01 +01001234 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001235 }
1236
Johannes Berg554891e2010-09-24 12:38:25 +02001237 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001238 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001239
Kalle Valo3cf335d2009-03-22 21:57:06 +02001240 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1241 ieee80211_sta_rx_notify(rx->sdata, hdr);
1242
Johannes Berg571ecf62007-07-27 15:43:22 +02001243 sta->rx_fragments++;
1244 sta->rx_bytes += rx->skb->len;
Felix Fietkaufe8431f2012-03-01 18:00:07 +01001245 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1246 sta->last_signal = status->signal;
1247 ewma_add(&sta->avg_signal, -status->signal);
1248 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001249
Felix Fietkauef0621e2013-04-22 16:29:31 +02001250 if (status->chains) {
1251 sta->chains = status->chains;
1252 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1253 int signal = status->chain_signal[i];
1254
1255 if (!(status->chains & BIT(i)))
1256 continue;
1257
1258 sta->chain_signal_last[i] = signal;
1259 ewma_add(&sta->chain_signal_avg[i], -signal);
1260 }
1261 }
1262
Johannes Berg72eaa432008-11-26 15:02:58 +01001263 /*
1264 * Change STA power saving mode only at the end of a frame
1265 * exchange sequence.
1266 */
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001267 if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
1268 !ieee80211_has_morefrags(hdr->frame_control) &&
Christian Lamparter4cfda472010-12-27 23:21:26 +01001269 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001270 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
Johannes Bergb4ba5442014-01-24 14:41:44 +01001271 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1272 /* PM bit is only checked in frames where it isn't reserved,
1273 * in AP mode it's reserved in non-bufferable management frames
1274 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1275 */
1276 (!ieee80211_is_mgmt(hdr->frame_control) ||
1277 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001278 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
Johannes Bergb4ba5442014-01-24 14:41:44 +01001279 if (!ieee80211_has_pm(hdr->frame_control))
Marco Porschd012a602012-10-10 12:39:50 -07001280 sta_ps_end(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001281 } else {
1282 if (ieee80211_has_pm(hdr->frame_control))
Marco Porschd012a602012-10-10 12:39:50 -07001283 sta_ps_start(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001284 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001285 }
1286
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001287 /* mesh power save support */
1288 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1289 ieee80211_mps_rx_h_sta_process(sta, hdr);
1290
Johannes Berg22403de2009-10-30 12:55:03 +01001291 /*
1292 * Drop (qos-)data::nullfunc frames silently, since they
1293 * are used only to control station power saving mode.
1294 */
1295 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1296 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001297 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
Felix Fietkaud5242152010-01-08 18:06:26 +01001298
1299 /*
1300 * If we receive a 4-addr nullfunc frame from a STA
Johannes Berge7f4a942011-11-04 11:18:20 +01001301 * that was not moved to a 4-addr STA vlan yet send
1302 * the event to userspace and for older hostapd drop
1303 * the frame to the monitor interface.
Felix Fietkaud5242152010-01-08 18:06:26 +01001304 */
1305 if (ieee80211_has_a4(hdr->frame_control) &&
1306 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1307 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
Johannes Berge7f4a942011-11-04 11:18:20 +01001308 !rx->sdata->u.vlan.sta))) {
1309 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1310 cfg80211_rx_unexpected_4addr_frame(
1311 rx->sdata->dev, sta->sta.addr,
1312 GFP_ATOMIC);
Felix Fietkaud5242152010-01-08 18:06:26 +01001313 return RX_DROP_MONITOR;
Johannes Berge7f4a942011-11-04 11:18:20 +01001314 }
Johannes Berg22403de2009-10-30 12:55:03 +01001315 /*
1316 * Update counter and free packet here to avoid
1317 * counting this as a dropped packed.
1318 */
Johannes Berg571ecf62007-07-27 15:43:22 +02001319 sta->rx_packets++;
1320 dev_kfree_skb(rx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001321 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001322 }
1323
Johannes Berg9ae54c82008-01-31 19:48:20 +01001324 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001325} /* ieee80211_rx_h_sta_process */
1326
Johan Almbladh86c228a2013-08-14 15:29:46 +02001327static ieee80211_rx_result debug_noinline
1328ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1329{
1330 struct sk_buff *skb = rx->skb;
1331 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1332 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1333 int keyidx;
1334 int hdrlen;
1335 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1336 struct ieee80211_key *sta_ptk = NULL;
1337 int mmie_keyidx = -1;
1338 __le16 fc;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001339 const struct ieee80211_cipher_scheme *cs = NULL;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001340
1341 /*
1342 * Key selection 101
1343 *
1344 * There are four types of keys:
1345 * - GTK (group keys)
1346 * - IGTK (group keys for management frames)
1347 * - PTK (pairwise keys)
1348 * - STK (station-to-station pairwise keys)
1349 *
1350 * When selecting a key, we have to distinguish between multicast
1351 * (including broadcast) and unicast frames, the latter can only
1352 * use PTKs and STKs while the former always use GTKs and IGTKs.
1353 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1354 * unicast frames can also use key indices like GTKs. Hence, if we
1355 * don't have a PTK/STK we check the key index for a WEP key.
1356 *
1357 * Note that in a regular BSS, multicast frames are sent by the
1358 * AP only, associated stations unicast the frame to the AP first
1359 * which then multicasts it on their behalf.
1360 *
1361 * There is also a slight problem in IBSS mode: GTKs are negotiated
1362 * with each station, that is something we don't currently handle.
1363 * The spec seems to expect that one negotiates the same key with
1364 * every station but there's no such requirement; VLANs could be
1365 * possible.
1366 */
1367
1368 /*
1369 * No point in finding a key and decrypting if the frame is neither
1370 * addressed to us nor a multicast frame.
1371 */
1372 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
1373 return RX_CONTINUE;
1374
1375 /* start without a key */
1376 rx->key = NULL;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001377 fc = hdr->frame_control;
1378
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001379 if (rx->sta) {
1380 int keyid = rx->sta->ptk_idx;
1381
1382 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1383 cs = rx->sta->cipher_scheme;
1384 keyid = iwl80211_get_cs_keyid(cs, rx->skb);
1385 if (unlikely(keyid < 0))
1386 return RX_DROP_UNUSABLE;
1387 }
1388 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1389 }
1390
Johan Almbladh86c228a2013-08-14 15:29:46 +02001391 if (!ieee80211_has_protected(fc))
1392 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1393
1394 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1395 rx->key = sta_ptk;
1396 if ((status->flag & RX_FLAG_DECRYPTED) &&
1397 (status->flag & RX_FLAG_IV_STRIPPED))
1398 return RX_CONTINUE;
1399 /* Skip decryption if the frame is not protected. */
1400 if (!ieee80211_has_protected(fc))
1401 return RX_CONTINUE;
1402 } else if (mmie_keyidx >= 0) {
1403 /* Broadcast/multicast robust management frame / BIP */
1404 if ((status->flag & RX_FLAG_DECRYPTED) &&
1405 (status->flag & RX_FLAG_IV_STRIPPED))
1406 return RX_CONTINUE;
1407
1408 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1409 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1410 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1411 if (rx->sta)
1412 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
1413 if (!rx->key)
1414 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1415 } else if (!ieee80211_has_protected(fc)) {
1416 /*
1417 * The frame was not protected, so skip decryption. However, we
1418 * need to set rx->key if there is a key that could have been
1419 * used so that the frame may be dropped if encryption would
1420 * have been expected.
1421 */
1422 struct ieee80211_key *key = NULL;
1423 struct ieee80211_sub_if_data *sdata = rx->sdata;
1424 int i;
1425
1426 if (ieee80211_is_mgmt(fc) &&
1427 is_multicast_ether_addr(hdr->addr1) &&
1428 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1429 rx->key = key;
1430 else {
1431 if (rx->sta) {
1432 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1433 key = rcu_dereference(rx->sta->gtk[i]);
1434 if (key)
1435 break;
1436 }
1437 }
1438 if (!key) {
1439 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1440 key = rcu_dereference(sdata->keys[i]);
1441 if (key)
1442 break;
1443 }
1444 }
1445 if (key)
1446 rx->key = key;
1447 }
1448 return RX_CONTINUE;
1449 } else {
1450 u8 keyid;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001451
Johan Almbladh86c228a2013-08-14 15:29:46 +02001452 /*
1453 * The device doesn't give us the IV so we won't be
1454 * able to look up the key. That's ok though, we
1455 * don't need to decrypt the frame, we just won't
1456 * be able to keep statistics accurate.
1457 * Except for key threshold notifications, should
1458 * we somehow allow the driver to tell us which key
1459 * the hardware used if this flag is set?
1460 */
1461 if ((status->flag & RX_FLAG_DECRYPTED) &&
1462 (status->flag & RX_FLAG_IV_STRIPPED))
1463 return RX_CONTINUE;
1464
1465 hdrlen = ieee80211_hdrlen(fc);
1466
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001467 if (cs) {
1468 keyidx = iwl80211_get_cs_keyid(cs, rx->skb);
Johan Almbladh86c228a2013-08-14 15:29:46 +02001469
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001470 if (unlikely(keyidx < 0))
1471 return RX_DROP_UNUSABLE;
1472 } else {
1473 if (rx->skb->len < 8 + hdrlen)
1474 return RX_DROP_UNUSABLE; /* TODO: count this? */
1475 /*
1476 * no need to call ieee80211_wep_get_keyidx,
1477 * it verifies a bunch of things we've done already
1478 */
1479 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1480 keyidx = keyid >> 6;
1481 }
Johan Almbladh86c228a2013-08-14 15:29:46 +02001482
1483 /* check per-station GTK first, if multicast packet */
1484 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1485 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1486
1487 /* if not found, try default key */
1488 if (!rx->key) {
1489 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1490
1491 /*
1492 * RSNA-protected unicast frames should always be
1493 * sent with pairwise or station-to-station keys,
1494 * but for WEP we allow using a key index as well.
1495 */
1496 if (rx->key &&
1497 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1498 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1499 !is_multicast_ether_addr(hdr->addr1))
1500 rx->key = NULL;
1501 }
1502 }
1503
1504 if (rx->key) {
1505 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1506 return RX_DROP_MONITOR;
1507
1508 rx->key->tx_rx_count++;
1509 /* TODO: add threshold stuff again */
1510 } else {
1511 return RX_DROP_MONITOR;
1512 }
1513
1514 switch (rx->key->conf.cipher) {
1515 case WLAN_CIPHER_SUITE_WEP40:
1516 case WLAN_CIPHER_SUITE_WEP104:
1517 result = ieee80211_crypto_wep_decrypt(rx);
1518 break;
1519 case WLAN_CIPHER_SUITE_TKIP:
1520 result = ieee80211_crypto_tkip_decrypt(rx);
1521 break;
1522 case WLAN_CIPHER_SUITE_CCMP:
1523 result = ieee80211_crypto_ccmp_decrypt(rx);
1524 break;
1525 case WLAN_CIPHER_SUITE_AES_CMAC:
1526 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1527 break;
1528 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001529 result = ieee80211_crypto_hw_decrypt(rx);
Johan Almbladh86c228a2013-08-14 15:29:46 +02001530 }
1531
1532 /* the hdr variable is invalid after the decrypt handlers */
1533
1534 /* either the frame has been decrypted or will be dropped */
1535 status->flag |= RX_FLAG_DECRYPTED;
1536
1537 return result;
1538}
1539
Johannes Berg571ecf62007-07-27 15:43:22 +02001540static inline struct ieee80211_fragment_entry *
1541ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1542 unsigned int frag, unsigned int seq, int rx_queue,
1543 struct sk_buff **skb)
1544{
1545 struct ieee80211_fragment_entry *entry;
Johannes Berg571ecf62007-07-27 15:43:22 +02001546
Johannes Berg571ecf62007-07-27 15:43:22 +02001547 entry = &sdata->fragments[sdata->fragment_next++];
1548 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1549 sdata->fragment_next = 0;
1550
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001551 if (!skb_queue_empty(&entry->skb_list))
Johannes Berg571ecf62007-07-27 15:43:22 +02001552 __skb_queue_purge(&entry->skb_list);
Johannes Berg571ecf62007-07-27 15:43:22 +02001553
1554 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1555 *skb = NULL;
1556 entry->first_frag_time = jiffies;
1557 entry->seq = seq;
1558 entry->rx_queue = rx_queue;
1559 entry->last_frag = frag;
1560 entry->ccmp = 0;
1561 entry->extra_len = 0;
1562
1563 return entry;
1564}
1565
1566static inline struct ieee80211_fragment_entry *
1567ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001568 unsigned int frag, unsigned int seq,
Johannes Berg571ecf62007-07-27 15:43:22 +02001569 int rx_queue, struct ieee80211_hdr *hdr)
1570{
1571 struct ieee80211_fragment_entry *entry;
1572 int i, idx;
1573
1574 idx = sdata->fragment_next;
1575 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1576 struct ieee80211_hdr *f_hdr;
Johannes Berg571ecf62007-07-27 15:43:22 +02001577
1578 idx--;
1579 if (idx < 0)
1580 idx = IEEE80211_FRAGMENT_MAX - 1;
1581
1582 entry = &sdata->fragments[idx];
1583 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1584 entry->rx_queue != rx_queue ||
1585 entry->last_frag + 1 != frag)
1586 continue;
1587
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001588 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001589
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001590 /*
1591 * Check ftype and addresses are equal, else check next fragment
1592 */
1593 if (((hdr->frame_control ^ f_hdr->frame_control) &
1594 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
Joe Perchesb203ca32012-05-08 18:56:52 +00001595 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1596 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
Johannes Berg571ecf62007-07-27 15:43:22 +02001597 continue;
1598
S.Çağlar Onurab466232008-02-14 17:36:47 +02001599 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001600 __skb_queue_purge(&entry->skb_list);
1601 continue;
1602 }
1603 return entry;
1604 }
1605
1606 return NULL;
1607}
1608
Johannes Berg49461622008-06-30 15:10:45 +02001609static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001610ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001611{
1612 struct ieee80211_hdr *hdr;
1613 u16 sc;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001614 __le16 fc;
Johannes Berg571ecf62007-07-27 15:43:22 +02001615 unsigned int frag, seq;
1616 struct ieee80211_fragment_entry *entry;
1617 struct sk_buff *skb;
Johannes Berg554891e2010-09-24 12:38:25 +02001618 struct ieee80211_rx_status *status;
Johannes Berg571ecf62007-07-27 15:43:22 +02001619
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001620 hdr = (struct ieee80211_hdr *)rx->skb->data;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001621 fc = hdr->frame_control;
Javier Cardonaf7fbf702012-10-25 11:10:18 -07001622
1623 if (ieee80211_is_ctl(fc))
1624 return RX_CONTINUE;
1625
Johannes Berg571ecf62007-07-27 15:43:22 +02001626 sc = le16_to_cpu(hdr->seq_ctrl);
1627 frag = sc & IEEE80211_SCTL_FRAG;
1628
Harvey Harrison358c8d92008-07-15 18:44:13 -07001629 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
Johannes Berg571ecf62007-07-27 15:43:22 +02001630 is_multicast_ether_addr(hdr->addr1))) {
1631 /* not fragmented */
1632 goto out;
1633 }
1634 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1635
Zhu Yie3cf8b32010-03-29 17:35:07 +08001636 if (skb_linearize(rx->skb))
1637 return RX_DROP_UNUSABLE;
1638
Abhijeet Kolekar058897a2010-05-11 11:22:11 -07001639 /*
1640 * skb_linearize() might change the skb->data and
1641 * previously cached variables (in this case, hdr) need to
1642 * be refreshed with the new data.
1643 */
1644 hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001645 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1646
1647 if (frag == 0) {
1648 /* This is the first fragment of a new frame. */
1649 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
Johannes Berg9e262972011-07-07 18:45:03 +02001650 rx->seqno_idx, &(rx->skb));
Johannes Berg97359d12010-08-10 09:46:38 +02001651 if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
Harvey Harrison358c8d92008-07-15 18:44:13 -07001652 ieee80211_has_protected(fc)) {
Johannes Berg9e262972011-07-07 18:45:03 +02001653 int queue = rx->security_idx;
Johannes Berg571ecf62007-07-27 15:43:22 +02001654 /* Store CCMP PN so that we can verify that the next
1655 * fragment has a sequential PN value. */
1656 entry->ccmp = 1;
1657 memcpy(entry->last_pn,
Jouni Malinen91902522010-06-11 10:27:33 -07001658 rx->key->u.ccmp.rx_pn[queue],
Johannes Berg4325f6c2013-05-08 13:09:08 +02001659 IEEE80211_CCMP_PN_LEN);
Johannes Berg571ecf62007-07-27 15:43:22 +02001660 }
Johannes Berg9ae54c82008-01-31 19:48:20 +01001661 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001662 }
1663
1664 /* This is a fragment for a frame that should already be pending in
1665 * fragment cache. Add this fragment to the end of the pending entry.
1666 */
Johannes Berg9e262972011-07-07 18:45:03 +02001667 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1668 rx->seqno_idx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02001669 if (!entry) {
1670 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001671 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +02001672 }
1673
1674 /* Verify that MPDUs within one MSDU have sequential PN values.
1675 * (IEEE 802.11i, 8.3.3.4.5) */
1676 if (entry->ccmp) {
1677 int i;
Johannes Berg4325f6c2013-05-08 13:09:08 +02001678 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
Jouni Malinen91902522010-06-11 10:27:33 -07001679 int queue;
Johannes Berg97359d12010-08-10 09:46:38 +02001680 if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
Johannes Berge4c26ad2008-01-31 19:48:21 +01001681 return RX_DROP_UNUSABLE;
Johannes Berg4325f6c2013-05-08 13:09:08 +02001682 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
1683 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001684 pn[i]++;
1685 if (pn[i])
1686 break;
1687 }
Johannes Berg9e262972011-07-07 18:45:03 +02001688 queue = rx->security_idx;
Jouni Malinen91902522010-06-11 10:27:33 -07001689 rpn = rx->key->u.ccmp.rx_pn[queue];
Johannes Berg4325f6c2013-05-08 13:09:08 +02001690 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001691 return RX_DROP_UNUSABLE;
Johannes Berg4325f6c2013-05-08 13:09:08 +02001692 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
Johannes Berg571ecf62007-07-27 15:43:22 +02001693 }
1694
Harvey Harrison358c8d92008-07-15 18:44:13 -07001695 skb_pull(rx->skb, ieee80211_hdrlen(fc));
Johannes Berg571ecf62007-07-27 15:43:22 +02001696 __skb_queue_tail(&entry->skb_list, rx->skb);
1697 entry->last_frag = frag;
1698 entry->extra_len += rx->skb->len;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001699 if (ieee80211_has_morefrags(fc)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001700 rx->skb = NULL;
Johannes Berg9ae54c82008-01-31 19:48:20 +01001701 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001702 }
1703
1704 rx->skb = __skb_dequeue(&entry->skb_list);
1705 if (skb_tailroom(rx->skb) < entry->extra_len) {
1706 I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
1707 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1708 GFP_ATOMIC))) {
1709 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1710 __skb_queue_purge(&entry->skb_list);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001711 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001712 }
1713 }
1714 while ((skb = __skb_dequeue(&entry->skb_list))) {
1715 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1716 dev_kfree_skb(skb);
1717 }
1718
1719 /* Complete frame has been reassembled - process it now */
Johannes Berg554891e2010-09-24 12:38:25 +02001720 status = IEEE80211_SKB_RXCB(rx->skb);
1721 status->rx_flags |= IEEE80211_RX_FRAGMENTED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001722
1723 out:
1724 if (rx->sta)
1725 rx->sta->rx_packets++;
1726 if (is_multicast_ether_addr(hdr->addr1))
1727 rx->local->dot11MulticastReceivedFrameCount++;
1728 else
1729 ieee80211_led_rx(rx->local);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001730 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001731}
1732
Johannes Berg1df332e2012-10-26 00:09:11 +02001733static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001734{
Johannes Berg1df332e2012-10-26 00:09:11 +02001735 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001736 return -EACCES;
Johannes Berg571ecf62007-07-27 15:43:22 +02001737
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001738 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001739}
1740
Johannes Berg1df332e2012-10-26 00:09:11 +02001741static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Berg571ecf62007-07-27 15:43:22 +02001742{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001743 struct sk_buff *skb = rx->skb;
1744 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1745
Johannes Berg3017b802007-08-28 17:01:53 -04001746 /*
Johannes Berg7848ba72007-09-14 11:10:25 -04001747 * Pass through unencrypted frames if the hardware has
1748 * decrypted them already.
Johannes Berg3017b802007-08-28 17:01:53 -04001749 */
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001750 if (status->flag & RX_FLAG_DECRYPTED)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001751 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001752
1753 /* Drop unencrypted frames if key is set. */
Harvey Harrison358c8d92008-07-15 18:44:13 -07001754 if (unlikely(!ieee80211_has_protected(fc) &&
1755 !ieee80211_is_nullfunc(fc) &&
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001756 ieee80211_is_data(fc) &&
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001757 (rx->key || rx->sdata->drop_unencrypted)))
1758 return -EACCES;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001759
1760 return 0;
1761}
1762
Johannes Berg1df332e2012-10-26 00:09:11 +02001763static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001764{
1765 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Jouni Malinene3efca02010-03-28 22:31:15 -07001766 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001767 __le16 fc = hdr->frame_control;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001768
Jouni Malinene3efca02010-03-28 22:31:15 -07001769 /*
1770 * Pass through unencrypted frames if the hardware has
1771 * decrypted them already.
1772 */
1773 if (status->flag & RX_FLAG_DECRYPTED)
1774 return 0;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01001775
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001776 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
Jouni Malinend211e902010-03-28 22:29:52 -07001777 if (unlikely(!ieee80211_has_protected(fc) &&
1778 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02001779 rx->key)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +02001780 if (ieee80211_is_deauth(fc) ||
1781 ieee80211_is_disassoc(fc))
1782 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1783 rx->skb->data,
1784 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001785 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02001786 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001787 /* BIP does not use Protected field, so need to check MMIE */
Joe Perchesf64f9e72009-11-29 16:55:45 -08001788 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02001789 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +02001790 if (ieee80211_is_deauth(fc) ||
1791 ieee80211_is_disassoc(fc))
1792 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1793 rx->skb->data,
1794 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001795 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02001796 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001797 /*
1798 * When using MFP, Action frames are not allowed prior to
1799 * having configured keys.
1800 */
1801 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
Johannes Bergd8ca16d2014-01-23 16:20:29 +01001802 ieee80211_is_robust_mgmt_frame(rx->skb)))
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03001803 return -EACCES;
1804 }
Johannes Bergb3fc9c62008-04-13 10:12:47 +02001805
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001806 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001807}
1808
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001809static int
Felix Fietkau4114fa22011-04-12 19:15:22 +02001810__ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
Johannes Berg571ecf62007-07-27 15:43:22 +02001811{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001812 struct ieee80211_sub_if_data *sdata = rx->sdata;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001813 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001814 bool check_port_control = false;
1815 struct ethhdr *ehdr;
1816 int ret;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001817
Felix Fietkau4114fa22011-04-12 19:15:22 +02001818 *port_control = false;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001819 if (ieee80211_has_a4(hdr->frame_control) &&
1820 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001821 return -1;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001822
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001823 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1824 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
1825
1826 if (!sdata->u.mgd.use_4addr)
1827 return -1;
1828 else
1829 check_port_control = true;
1830 }
1831
Johannes Berg9bc383d2009-11-19 11:55:19 +01001832 if (is_multicast_ether_addr(hdr->addr1) &&
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001833 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001834 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02001835
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001836 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
Felix Fietkau4114fa22011-04-12 19:15:22 +02001837 if (ret < 0)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001838 return ret;
1839
1840 ehdr = (struct ethhdr *) rx->skb->data;
Felix Fietkau4114fa22011-04-12 19:15:22 +02001841 if (ehdr->h_proto == rx->sdata->control_port_protocol)
1842 *port_control = true;
1843 else if (check_port_control)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01001844 return -1;
1845
1846 return 0;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001847}
Johannes Berg571ecf62007-07-27 15:43:22 +02001848
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001849/*
1850 * requires that rx->skb is a frame with ethernet header
1851 */
Harvey Harrison358c8d92008-07-15 18:44:13 -07001852static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001853{
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301854 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001855 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
1856 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1857
1858 /*
1859 * Allow EAPOL frames to us/the PAE group address regardless
1860 * of whether the frame was encrypted or not.
1861 */
Johannes Berga621fa42010-08-27 14:26:54 +03001862 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
Joe Perches3bc79452012-05-08 18:56:53 +00001863 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
1864 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001865 return true;
1866
1867 if (ieee80211_802_1x_port_control(rx) ||
Harvey Harrison358c8d92008-07-15 18:44:13 -07001868 ieee80211_drop_unencrypted(rx, fc))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001869 return false;
1870
1871 return true;
1872}
1873
1874/*
1875 * requires that rx->skb is a frame with ethernet header
1876 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001877static void
Johannes Berg5cf121c2008-02-25 16:27:43 +01001878ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001879{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001880 struct ieee80211_sub_if_data *sdata = rx->sdata;
1881 struct net_device *dev = sdata->dev;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001882 struct sk_buff *skb, *xmit_skb;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001883 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
1884 struct sta_info *dsta;
Johannes Berg554891e2010-09-24 12:38:25 +02001885 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001886
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001887 skb = rx->skb;
1888 xmit_skb = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +02001889
Johannes Berg05c914f2008-09-11 00:01:58 +02001890 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1891 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
Johannes Berg213cd112008-09-11 00:01:54 +02001892 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
Johannes Berg554891e2010-09-24 12:38:25 +02001893 (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
Johannes Berg9bc383d2009-11-19 11:55:19 +01001894 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001895 if (is_multicast_ether_addr(ehdr->h_dest)) {
1896 /*
1897 * send multicast frames both to higher layers in
1898 * local net stack and back to the wireless medium
1899 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001900 xmit_skb = skb_copy(skb, GFP_ATOMIC);
Joe Perchese87cc472012-05-13 21:56:26 +00001901 if (!xmit_skb)
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001902 net_info_ratelimited("%s: failed to clone multicast frame\n",
Joe Perchese87cc472012-05-13 21:56:26 +00001903 dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +02001904 } else {
Johannes Bergabe60632009-11-25 17:46:18 +01001905 dsta = sta_info_get(sdata, skb->data);
1906 if (dsta) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001907 /*
1908 * The destination station is associated to
1909 * this AP (in this VLAN), so send the frame
1910 * directly to it and do not pass it to local
1911 * net stack.
Johannes Berg571ecf62007-07-27 15:43:22 +02001912 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001913 xmit_skb = skb;
Johannes Berg571ecf62007-07-27 15:43:22 +02001914 skb = NULL;
1915 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001916 }
1917 }
1918
Kalle Valo59d9cb02009-12-17 13:54:57 +01001919#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Johannes Berg9e890a1f2013-12-04 09:16:31 +01001920 if (skb) {
1921 /* 'align' will only take the values 0 or 2 here since all
1922 * frames are required to be aligned to 2-byte boundaries
1923 * when being passed to mac80211; the code here works just
1924 * as well if that isn't true, but mac80211 assumes it can
1925 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
Johannes Bergd1c3a372009-01-07 00:26:10 +01001926 */
Johannes Berg9e890a1f2013-12-04 09:16:31 +01001927 int align;
1928
1929 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
Johannes Bergd1c3a372009-01-07 00:26:10 +01001930 if (align) {
1931 if (WARN_ON(skb_headroom(skb) < 3)) {
1932 dev_kfree_skb(skb);
1933 skb = NULL;
1934 } else {
1935 u8 *data = skb->data;
Zhu Yi8ce0b582009-10-28 13:13:52 -07001936 size_t len = skb_headlen(skb);
1937 skb->data -= align;
1938 memmove(skb->data, data, len);
1939 skb_set_tail_pointer(skb, len);
Johannes Bergd1c3a372009-01-07 00:26:10 +01001940 }
1941 }
Johannes Berg9e890a1f2013-12-04 09:16:31 +01001942 }
Johannes Bergd1c3a372009-01-07 00:26:10 +01001943#endif
1944
Johannes Berg9e890a1f2013-12-04 09:16:31 +01001945 if (skb) {
1946 /* deliver to local stack */
1947 skb->protocol = eth_type_trans(skb, dev);
1948 memset(skb->cb, 0, sizeof(skb->cb));
1949 netif_receive_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001950 }
1951
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001952 if (xmit_skb) {
Helmut Schaaaef6c922011-12-21 09:11:35 +01001953 /*
1954 * Send to wireless media and increase priority by 256 to
1955 * keep the received priority instead of reclassifying
1956 * the frame (see cfg80211_classify8021d).
1957 */
1958 xmit_skb->priority += 256;
YOSHIFUJI Hideakif831e902007-12-12 03:54:23 +09001959 xmit_skb->protocol = htons(ETH_P_802_3);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001960 skb_reset_network_header(xmit_skb);
1961 skb_reset_mac_header(xmit_skb);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001962 dev_queue_xmit(xmit_skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001963 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001964}
1965
Johannes Berg49461622008-06-30 15:10:45 +02001966static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001967ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001968{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001969 struct net_device *dev = rx->sdata->dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001970 struct sk_buff *skb = rx->skb;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001971 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1972 __le16 fc = hdr->frame_control;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001973 struct sk_buff_head frame_list;
Johannes Berg554891e2010-09-24 12:38:25 +02001974 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001975
Harvey Harrison358c8d92008-07-15 18:44:13 -07001976 if (unlikely(!ieee80211_is_data(fc)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001977 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001978
Harvey Harrison358c8d92008-07-15 18:44:13 -07001979 if (unlikely(!ieee80211_is_data_present(fc)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001980 return RX_DROP_MONITOR;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001981
Johannes Berg554891e2010-09-24 12:38:25 +02001982 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
Johannes Berg9ae54c82008-01-31 19:48:20 +01001983 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001984
Zhu Yieaf85ca2009-12-01 10:18:37 +08001985 if (ieee80211_has_a4(hdr->frame_control) &&
1986 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1987 !rx->sdata->u.vlan.sta)
1988 return RX_DROP_UNUSABLE;
1989
1990 if (is_multicast_ether_addr(hdr->addr1) &&
1991 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1992 rx->sdata->u.vlan.sta) ||
1993 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1994 rx->sdata->u.mgd.use_4addr)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001995 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001996
1997 skb->dev = dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08001998 __skb_queue_head_init(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02001999
Zhu Yie3cf8b32010-03-29 17:35:07 +08002000 if (skb_linearize(skb))
2001 return RX_DROP_UNUSABLE;
2002
Zhu Yieaf85ca2009-12-01 10:18:37 +08002003 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2004 rx->sdata->vif.type,
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -07002005 rx->local->hw.extra_tx_headroom, true);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002006
Zhu Yieaf85ca2009-12-01 10:18:37 +08002007 while (!skb_queue_empty(&frame_list)) {
2008 rx->skb = __skb_dequeue(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002009
Harvey Harrison358c8d92008-07-15 18:44:13 -07002010 if (!ieee80211_frame_allowed(rx, fc)) {
Zhu Yieaf85ca2009-12-01 10:18:37 +08002011 dev_kfree_skb(rx->skb);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002012 continue;
2013 }
Zhu Yieaf85ca2009-12-01 10:18:37 +08002014 dev->stats.rx_packets++;
2015 dev->stats.rx_bytes += rx->skb->len;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002016
2017 ieee80211_deliver_skb(rx);
2018 }
2019
Johannes Berg9ae54c82008-01-31 19:48:20 +01002020 return RX_QUEUED;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002021}
2022
Ingo Molnarbf94e172008-10-12 23:51:38 -07002023#ifdef CONFIG_MAC80211_MESH
Davide Pesaventob0dee572008-09-27 17:29:12 +02002024static ieee80211_rx_result
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002025ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2026{
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002027 struct ieee80211_hdr *fwd_hdr, *hdr;
2028 struct ieee80211_tx_info *info;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002029 struct ieee80211s_hdr *mesh_hdr;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002030 struct sk_buff *skb = rx->skb, *fwd_skb;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02002031 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002032 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02002033 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002034 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002035 u16 q, hdrlen;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002036
2037 hdr = (struct ieee80211_hdr *) skb->data;
2038 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Johannes Berg9b395bc2012-10-26 00:36:40 +02002039
2040 /* make sure fixed part of mesh header is there, also checks skb len */
2041 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2042 return RX_DROP_MONITOR;
2043
2044 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2045
2046 /* make sure full mesh header is there, also checks skb len */
2047 if (!pskb_may_pull(rx->skb,
2048 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2049 return RX_DROP_MONITOR;
2050
2051 /* reload pointers */
2052 hdr = (struct ieee80211_hdr *) skb->data;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002053 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2054
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07002055 /* frame is in RMC, don't forward */
2056 if (ieee80211_is_data(hdr->frame_control) &&
2057 is_multicast_ether_addr(hdr->addr1) &&
Johannes Bergbf7cd942013-02-15 14:40:31 +01002058 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07002059 return RX_DROP_MONITOR;
2060
Javier Cardona555cb712012-10-24 12:43:30 -07002061 if (!ieee80211_is_data(hdr->frame_control) ||
2062 !(status->rx_flags & IEEE80211_RX_RA_MATCH))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002063 return RX_CONTINUE;
2064
2065 if (!mesh_hdr->ttl)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002066 return RX_DROP_MONITOR;
2067
Javier Cardona43b7b312009-10-15 18:10:51 -07002068 if (mesh_hdr->flags & MESH_FLAGS_AE) {
YanBo79617de2008-09-22 13:30:32 +08002069 struct mesh_path *mppath;
Javier Cardona43b7b312009-10-15 18:10:51 -07002070 char *proxied_addr;
2071 char *mpp_addr;
2072
2073 if (is_multicast_ether_addr(hdr->addr1)) {
2074 mpp_addr = hdr->addr3;
2075 proxied_addr = mesh_hdr->eaddr1;
Johannes Berg9b395bc2012-10-26 00:36:40 +02002076 } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
2077 /* has_a4 already checked in ieee80211_rx_mesh_check */
Javier Cardona43b7b312009-10-15 18:10:51 -07002078 mpp_addr = hdr->addr4;
2079 proxied_addr = mesh_hdr->eaddr2;
Johannes Berg9b395bc2012-10-26 00:36:40 +02002080 } else {
2081 return RX_DROP_MONITOR;
Javier Cardona43b7b312009-10-15 18:10:51 -07002082 }
YanBo79617de2008-09-22 13:30:32 +08002083
YanBo79617de2008-09-22 13:30:32 +08002084 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01002085 mppath = mpp_path_lookup(sdata, proxied_addr);
YanBo79617de2008-09-22 13:30:32 +08002086 if (!mppath) {
Johannes Bergbf7cd942013-02-15 14:40:31 +01002087 mpp_path_add(sdata, proxied_addr, mpp_addr);
YanBo79617de2008-09-22 13:30:32 +08002088 } else {
2089 spin_lock_bh(&mppath->state_lock);
Joe Perchesb203ca32012-05-08 18:56:52 +00002090 if (!ether_addr_equal(mppath->mpp, mpp_addr))
Javier Cardona43b7b312009-10-15 18:10:51 -07002091 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
YanBo79617de2008-09-22 13:30:32 +08002092 spin_unlock_bh(&mppath->state_lock);
2093 }
2094 rcu_read_unlock();
2095 }
2096
Javier Cardona3c5772a2009-08-10 12:15:48 -07002097 /* Frame has reached destination. Don't forward */
2098 if (!is_multicast_ether_addr(hdr->addr1) &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002099 ether_addr_equal(sdata->vif.addr, hdr->addr3))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002100 return RX_CONTINUE;
2101
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002102 q = ieee80211_select_queue_80211(sdata, skb, hdr);
Thomas Pedersend3c15972011-11-24 17:15:23 -08002103 if (ieee80211_queue_stopped(&local->hw, q)) {
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002104 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
Thomas Pedersend3c15972011-11-24 17:15:23 -08002105 return RX_DROP_MONITOR;
2106 }
2107 skb_set_queue_mapping(skb, q);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002108
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002109 if (!--mesh_hdr->ttl) {
2110 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
Javier Cardona2ac64cd2012-10-24 12:43:31 -07002111 goto out;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002112 }
2113
Chun-Yeow Yeohd6655082012-03-02 02:03:19 +08002114 if (!ifmsh->mshcfg.dot11MeshForwarding)
2115 goto out;
2116
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002117 fwd_skb = skb_copy(skb, GFP_ATOMIC);
2118 if (!fwd_skb) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002119 net_info_ratelimited("%s: failed to clone mesh frame\n",
Joe Perchese87cc472012-05-13 21:56:26 +00002120 sdata->name);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002121 goto out;
2122 }
2123
2124 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
Thomas Pedersen9d6d6f42013-04-08 11:06:12 -07002125 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002126 info = IEEE80211_SKB_CB(fwd_skb);
2127 memset(info, 0, sizeof(*info));
2128 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2129 info->control.vif = &rx->sdata->vif;
2130 info->control.jiffies = jiffies;
2131 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2132 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2133 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002134 /* update power mode indication when forwarding */
2135 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
Johannes Bergbf7cd942013-02-15 14:40:31 +01002136 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002137 /* mesh power mode flags updated in mesh_nexthop_lookup */
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002138 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2139 } else {
2140 /* unable to resolve next hop */
Johannes Bergbf7cd942013-02-15 14:40:31 +01002141 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
Chun-Yeow Yeohf63f8422013-11-13 15:39:12 +08002142 fwd_hdr->addr3, 0,
2143 WLAN_REASON_MESH_PATH_NOFORWARD,
2144 fwd_hdr->addr2);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002145 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
Jesper Juhl74b8cc32012-01-14 21:52:17 +01002146 kfree_skb(fwd_skb);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002147 return RX_DROP_MONITOR;
2148 }
2149
2150 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2151 ieee80211_add_pending_skb(local, fwd_skb);
Johannes Bergb51aff02010-12-22 10:15:07 +01002152 out:
Javier Cardona3c5772a2009-08-10 12:15:48 -07002153 if (is_multicast_ether_addr(hdr->addr1) ||
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002154 sdata->dev->flags & IFF_PROMISC)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002155 return RX_CONTINUE;
2156 else
2157 return RX_DROP_MONITOR;
2158}
Ingo Molnarbf94e172008-10-12 23:51:38 -07002159#endif
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002160
2161static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002162ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002163{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002164 struct ieee80211_sub_if_data *sdata = rx->sdata;
Vivek Natarajane15276a2010-02-08 17:47:01 +05302165 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002166 struct net_device *dev = sdata->dev;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002167 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2168 __le16 fc = hdr->frame_control;
Felix Fietkau4114fa22011-04-12 19:15:22 +02002169 bool port_control;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002170 int err;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002171
Harvey Harrison358c8d92008-07-15 18:44:13 -07002172 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002173 return RX_CONTINUE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002174
Harvey Harrison358c8d92008-07-15 18:44:13 -07002175 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002176 return RX_DROP_MONITOR;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002177
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002178 /*
Johannes Berge7f4a942011-11-04 11:18:20 +01002179 * Send unexpected-4addr-frame event to hostapd. For older versions,
2180 * also drop the frame to cooked monitor interfaces.
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002181 */
2182 if (ieee80211_has_a4(hdr->frame_control) &&
Johannes Berge7f4a942011-11-04 11:18:20 +01002183 sdata->vif.type == NL80211_IFTYPE_AP) {
2184 if (rx->sta &&
2185 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2186 cfg80211_rx_unexpected_4addr_frame(
2187 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002188 return RX_DROP_MONITOR;
Johannes Berge7f4a942011-11-04 11:18:20 +01002189 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002190
Felix Fietkau4114fa22011-04-12 19:15:22 +02002191 err = __ieee80211_data_to_8023(rx, &port_control);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002192 if (unlikely(err))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002193 return RX_DROP_UNUSABLE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002194
Harvey Harrison358c8d92008-07-15 18:44:13 -07002195 if (!ieee80211_frame_allowed(rx, fc))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002196 return RX_DROP_MONITOR;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002197
Felix Fietkau4114fa22011-04-12 19:15:22 +02002198 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2199 unlikely(port_control) && sdata->bss) {
2200 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2201 u.ap);
2202 dev = sdata->dev;
2203 rx->sdata = sdata;
2204 }
2205
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002206 rx->skb->dev = dev;
2207
2208 dev->stats.rx_packets++;
2209 dev->stats.rx_bytes += rx->skb->len;
2210
Helmut Schaa08ca9442010-11-30 12:19:34 +01002211 if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
Rajkumar Manoharan8c99f692011-02-02 22:57:53 +05302212 !is_multicast_ether_addr(
2213 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2214 (!local->scanning &&
2215 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
Vivek Natarajane15276a2010-02-08 17:47:01 +05302216 mod_timer(&local->dynamic_ps_timer, jiffies +
2217 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
2218 }
2219
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002220 ieee80211_deliver_skb(rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02002221
Johannes Berg9ae54c82008-01-31 19:48:20 +01002222 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002223}
2224
Johannes Berg49461622008-06-30 15:10:45 +02002225static ieee80211_rx_result debug_noinline
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002226ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
Ron Rindjunsky71364712007-12-25 17:00:36 +02002227{
Ron Rindjunsky71364712007-12-25 17:00:36 +02002228 struct sk_buff *skb = rx->skb;
Harvey Harrisona7767f92008-07-02 16:30:51 -07002229 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002230 struct tid_ampdu_rx *tid_agg_rx;
2231 u16 start_seq_num;
2232 u16 tid;
2233
Harvey Harrisona7767f92008-07-02 16:30:51 -07002234 if (likely(!ieee80211_is_ctl(bar->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002235 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002236
Harvey Harrisona7767f92008-07-02 16:30:51 -07002237 if (ieee80211_is_back_req(bar->frame_control)) {
Johannes Berg8ae59772010-05-30 14:52:58 +02002238 struct {
2239 __le16 control, start_seq_num;
2240 } __packed bar_data;
2241
Ron Rindjunsky71364712007-12-25 17:00:36 +02002242 if (!rx->sta)
Johannes Berga02ae752009-11-16 12:00:40 +01002243 return RX_DROP_MONITOR;
Johannes Berg8ae59772010-05-30 14:52:58 +02002244
2245 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2246 &bar_data, sizeof(bar_data)))
2247 return RX_DROP_MONITOR;
2248
Johannes Berg8ae59772010-05-30 14:52:58 +02002249 tid = le16_to_cpu(bar_data.control) >> 12;
Johannes Berga87f7362010-06-10 10:21:38 +02002250
2251 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2252 if (!tid_agg_rx)
Johannes Berga02ae752009-11-16 12:00:40 +01002253 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002254
Johannes Berg8ae59772010-05-30 14:52:58 +02002255 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002256
2257 /* reset session timer */
Johannes Berg20ad19d2009-02-10 21:25:45 +01002258 if (tid_agg_rx->timeout)
2259 mod_timer(&tid_agg_rx->session_timer,
2260 TU_TO_EXP_TIME(tid_agg_rx->timeout));
Ron Rindjunsky71364712007-12-25 17:00:36 +02002261
Johannes Bergdd318572010-11-29 11:09:16 +01002262 spin_lock(&tid_agg_rx->reorder_lock);
Johannes Berga02ae752009-11-16 12:00:40 +01002263 /* release stored frames up to start of BAR */
Johannes Bergd3b2fb52012-06-22 12:48:38 +02002264 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002265 start_seq_num, frames);
Johannes Bergdd318572010-11-29 11:09:16 +01002266 spin_unlock(&tid_agg_rx->reorder_lock);
2267
Johannes Berga02ae752009-11-16 12:00:40 +01002268 kfree_skb(skb);
2269 return RX_QUEUED;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002270 }
2271
Johannes Berg08daeca2010-05-30 14:53:43 +02002272 /*
2273 * After this point, we only want management frames,
2274 * so we can drop all remaining control frames to
2275 * cooked monitor interfaces.
2276 */
2277 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002278}
2279
Jouni Malinenf4f727a2009-01-10 11:46:53 +02002280static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2281 struct ieee80211_mgmt *mgmt,
2282 size_t len)
Jouni Malinenfea14732009-01-08 13:32:06 +02002283{
2284 struct ieee80211_local *local = sdata->local;
2285 struct sk_buff *skb;
2286 struct ieee80211_mgmt *resp;
2287
Joe Perchesb203ca32012-05-08 18:56:52 +00002288 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
Jouni Malinenfea14732009-01-08 13:32:06 +02002289 /* Not to own unicast address */
2290 return;
2291 }
2292
Joe Perchesb203ca32012-05-08 18:56:52 +00002293 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2294 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002295 /* Not from the current AP or not associated yet. */
Jouni Malinenfea14732009-01-08 13:32:06 +02002296 return;
2297 }
2298
2299 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2300 /* Too short SA Query request frame */
2301 return;
2302 }
2303
2304 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2305 if (skb == NULL)
2306 return;
2307
2308 skb_reserve(skb, local->hw.extra_tx_headroom);
2309 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2310 memset(resp, 0, 24);
2311 memcpy(resp->da, mgmt->sa, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002312 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +01002313 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
Jouni Malinenfea14732009-01-08 13:32:06 +02002314 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2315 IEEE80211_STYPE_ACTION);
2316 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2317 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2318 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2319 memcpy(resp->u.action.u.sa_query.trans_id,
2320 mgmt->u.action.u.sa_query.trans_id,
2321 WLAN_SA_QUERY_TR_ID_LEN);
2322
Johannes Berg62ae67b2009-11-18 18:42:05 +01002323 ieee80211_tx_skb(sdata, skb);
Jouni Malinenfea14732009-01-08 13:32:06 +02002324}
2325
Johannes Berg49461622008-06-30 15:10:45 +02002326static ieee80211_rx_result debug_noinline
Johannes Berg2e161f72010-08-12 15:38:38 +02002327ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2328{
2329 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002330 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002331
2332 /*
2333 * From here on, look only at management frames.
2334 * Data and control frames are already handled,
2335 * and unknown (reserved) frames are useless.
2336 */
2337 if (rx->skb->len < 24)
2338 return RX_DROP_MONITOR;
2339
2340 if (!ieee80211_is_mgmt(mgmt->frame_control))
2341 return RX_DROP_MONITOR;
2342
Johannes Bergee971922011-11-04 11:18:18 +01002343 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2344 ieee80211_is_beacon(mgmt->frame_control) &&
2345 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
Johannes Berg804483e2012-03-05 22:18:41 +01002346 int sig = 0;
2347
2348 if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
2349 sig = status->signal;
2350
Johannes Bergee971922011-11-04 11:18:18 +01002351 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2352 rx->skb->data, rx->skb->len,
Ben Greear37c73b52012-10-26 14:49:25 -07002353 status->freq, sig);
Johannes Bergee971922011-11-04 11:18:18 +01002354 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2355 }
2356
Johannes Berg554891e2010-09-24 12:38:25 +02002357 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg2e161f72010-08-12 15:38:38 +02002358 return RX_DROP_MONITOR;
2359
2360 if (ieee80211_drop_unencrypted_mgmt(rx))
2361 return RX_DROP_UNUSABLE;
2362
2363 return RX_CONTINUE;
2364}
2365
2366static ieee80211_rx_result debug_noinline
Johannes Bergde1ede72008-09-09 14:42:50 +02002367ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2368{
2369 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002370 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergde1ede72008-09-09 14:42:50 +02002371 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002372 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergde1ede72008-09-09 14:42:50 +02002373 int len = rx->skb->len;
2374
2375 if (!ieee80211_is_action(mgmt->frame_control))
2376 return RX_CONTINUE;
2377
Jouni Malinen026331c2010-02-15 12:53:10 +02002378 /* drop too small frames */
2379 if (len < IEEE80211_MIN_ACTION_SIZE)
2380 return RX_DROP_UNUSABLE;
2381
Marco Porsch815b8092012-12-05 15:04:26 -08002382 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002383 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2384 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg84040802010-02-15 12:46:39 +02002385 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002386
Johannes Berg554891e2010-09-24 12:38:25 +02002387 if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
Johannes Berg84040802010-02-15 12:46:39 +02002388 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002389
Johannes Bergde1ede72008-09-09 14:42:50 +02002390 switch (mgmt->u.action.category) {
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002391 case WLAN_CATEGORY_HT:
2392 /* reject HT action frames from stations not supporting HT */
2393 if (!rx->sta->sta.ht_cap.ht_supported)
2394 goto invalid;
2395
2396 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2397 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2398 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2399 sdata->vif.type != NL80211_IFTYPE_AP &&
2400 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2401 break;
2402
Johannes Bergec61cd62012-12-28 12:12:10 +01002403 /* verify action & smps_control/chanwidth are present */
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002404 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2405 goto invalid;
2406
2407 switch (mgmt->u.action.u.ht_smps.action) {
2408 case WLAN_HT_ACTION_SMPS: {
2409 struct ieee80211_supported_band *sband;
Johannes Bergaf0ed692013-02-12 14:21:00 +01002410 enum ieee80211_smps_mode smps_mode;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002411
2412 /* convert to HT capability */
2413 switch (mgmt->u.action.u.ht_smps.smps_control) {
2414 case WLAN_HT_SMPS_CONTROL_DISABLED:
Johannes Bergaf0ed692013-02-12 14:21:00 +01002415 smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002416 break;
2417 case WLAN_HT_SMPS_CONTROL_STATIC:
Johannes Bergaf0ed692013-02-12 14:21:00 +01002418 smps_mode = IEEE80211_SMPS_STATIC;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002419 break;
2420 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
Johannes Bergaf0ed692013-02-12 14:21:00 +01002421 smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002422 break;
2423 default:
2424 goto invalid;
2425 }
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002426
2427 /* if no change do nothing */
Johannes Bergaf0ed692013-02-12 14:21:00 +01002428 if (rx->sta->sta.smps_mode == smps_mode)
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002429 goto handled;
Johannes Bergaf0ed692013-02-12 14:21:00 +01002430 rx->sta->sta.smps_mode = smps_mode;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002431
2432 sband = rx->local->hw.wiphy->bands[status->band];
2433
Johannes Berg64f68e52012-03-28 10:58:37 +02002434 rate_control_rate_update(local, sband, rx->sta,
2435 IEEE80211_RC_SMPS_CHANGED);
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002436 goto handled;
2437 }
Johannes Bergec61cd62012-12-28 12:12:10 +01002438 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2439 struct ieee80211_supported_band *sband;
2440 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002441 enum ieee80211_sta_rx_bandwidth new_bw;
Johannes Bergec61cd62012-12-28 12:12:10 +01002442
2443 /* If it doesn't support 40 MHz it can't change ... */
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002444 if (!(rx->sta->sta.ht_cap.cap &
2445 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Johannes Bergec61cd62012-12-28 12:12:10 +01002446 goto handled;
2447
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002448 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
2449 new_bw = IEEE80211_STA_RX_BW_20;
Johannes Bergec61cd62012-12-28 12:12:10 +01002450 else
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002451 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
2452
2453 if (rx->sta->sta.bandwidth == new_bw)
2454 goto handled;
Johannes Bergec61cd62012-12-28 12:12:10 +01002455
2456 sband = rx->local->hw.wiphy->bands[status->band];
2457
2458 rate_control_rate_update(local, sband, rx->sta,
2459 IEEE80211_RC_BW_CHANGED);
2460 goto handled;
2461 }
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002462 default:
2463 goto invalid;
2464 }
2465
2466 break;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01002467 case WLAN_CATEGORY_PUBLIC:
2468 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2469 goto invalid;
2470 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2471 break;
2472 if (!rx->sta)
2473 break;
2474 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
2475 break;
2476 if (mgmt->u.action.u.ext_chan_switch.action_code !=
2477 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
2478 break;
2479 if (len < offsetof(struct ieee80211_mgmt,
2480 u.action.u.ext_chan_switch.variable))
2481 goto invalid;
2482 goto queue;
Johannes Berg0af83d32012-12-27 18:55:36 +01002483 case WLAN_CATEGORY_VHT:
2484 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2485 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2486 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2487 sdata->vif.type != NL80211_IFTYPE_AP &&
2488 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2489 break;
2490
2491 /* verify action code is present */
2492 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2493 goto invalid;
2494
2495 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
2496 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
2497 u8 opmode;
2498
2499 /* verify opmode is present */
2500 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2501 goto invalid;
2502
2503 opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
2504
2505 ieee80211_vht_handle_opmode(rx->sdata, rx->sta,
Johannes Bergbee7f582013-02-07 22:24:55 +01002506 opmode, status->band,
2507 false);
Johannes Berg0af83d32012-12-27 18:55:36 +01002508 goto handled;
2509 }
2510 default:
2511 break;
2512 }
2513 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002514 case WLAN_CATEGORY_BACK:
Johannes Berg8abd3f92009-02-10 21:25:47 +01002515 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
Thomas Pedersenae2772b2011-10-26 14:47:29 -07002516 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg8abd3f92009-02-10 21:25:47 +01002517 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
Alexander Simon13c40c52011-11-30 16:56:34 +01002518 sdata->vif.type != NL80211_IFTYPE_AP &&
2519 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Johannes Berg84040802010-02-15 12:46:39 +02002520 break;
Johannes Berg8abd3f92009-02-10 21:25:47 +01002521
Jouni Malinen026331c2010-02-15 12:53:10 +02002522 /* verify action_code is present */
2523 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2524 break;
2525
Johannes Bergde1ede72008-09-09 14:42:50 +02002526 switch (mgmt->u.action.u.addba_req.action_code) {
2527 case WLAN_ACTION_ADDBA_REQ:
2528 if (len < (IEEE80211_MIN_ACTION_SIZE +
2529 sizeof(mgmt->u.action.u.addba_req)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002530 goto invalid;
2531 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002532 case WLAN_ACTION_ADDBA_RESP:
2533 if (len < (IEEE80211_MIN_ACTION_SIZE +
2534 sizeof(mgmt->u.action.u.addba_resp)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002535 goto invalid;
2536 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002537 case WLAN_ACTION_DELBA:
2538 if (len < (IEEE80211_MIN_ACTION_SIZE +
2539 sizeof(mgmt->u.action.u.delba)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002540 goto invalid;
2541 break;
2542 default:
2543 goto invalid;
Johannes Bergde1ede72008-09-09 14:42:50 +02002544 }
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002545
Johannes Berg8b58ff82010-06-10 10:21:51 +02002546 goto queue;
Johannes Berg39192c02008-09-09 14:49:03 +02002547 case WLAN_CATEGORY_SPECTRUM_MGMT:
Jouni Malinen026331c2010-02-15 12:53:10 +02002548 /* verify action_code is present */
2549 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2550 break;
2551
Johannes Berg39192c02008-09-09 14:49:03 +02002552 switch (mgmt->u.action.u.measurement.action_code) {
2553 case WLAN_ACTION_SPCT_MSR_REQ:
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002554 if (status->band != IEEE80211_BAND_5GHZ)
2555 break;
2556
Johannes Berg39192c02008-09-09 14:49:03 +02002557 if (len < (IEEE80211_MIN_ACTION_SIZE +
2558 sizeof(mgmt->u.action.u.measurement)))
Johannes Berg84040802010-02-15 12:46:39 +02002559 break;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002560
Johannes Bergcc32abd2009-05-15 11:52:31 +02002561 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002562 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02002563
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002564 ieee80211_process_measurement_req(sdata, mgmt, len);
2565 goto handled;
2566 case WLAN_ACTION_SPCT_CHL_SWITCH: {
2567 u8 *bssid;
2568 if (len < (IEEE80211_MIN_ACTION_SIZE +
2569 sizeof(mgmt->u.action.u.chan_switch)))
2570 break;
2571
2572 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07002573 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2574 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002575 break;
2576
2577 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2578 bssid = sdata->u.mgd.bssid;
2579 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2580 bssid = sdata->u.ibss.bssid;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07002581 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
2582 bssid = mgmt->sa;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002583 else
2584 break;
2585
2586 if (!ether_addr_equal(mgmt->bssid, bssid))
Johannes Berg84040802010-02-15 12:46:39 +02002587 break;
Sujithc481ec92009-01-06 09:28:37 +05302588
Johannes Berg8b58ff82010-06-10 10:21:51 +02002589 goto queue;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002590 }
Johannes Berg39192c02008-09-09 14:49:03 +02002591 }
2592 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002593 case WLAN_CATEGORY_SA_QUERY:
2594 if (len < (IEEE80211_MIN_ACTION_SIZE +
2595 sizeof(mgmt->u.action.u.sa_query)))
Johannes Berg84040802010-02-15 12:46:39 +02002596 break;
2597
Jouni Malinenfea14732009-01-08 13:32:06 +02002598 switch (mgmt->u.action.u.sa_query.action) {
2599 case WLAN_ACTION_SA_QUERY_REQUEST:
2600 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002601 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002602 ieee80211_process_sa_query_req(sdata, mgmt, len);
Johannes Berg84040802010-02-15 12:46:39 +02002603 goto handled;
Jouni Malinenfea14732009-01-08 13:32:06 +02002604 }
2605 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -07002606 case WLAN_CATEGORY_SELF_PROTECTED:
Johannes Berg9b395bc2012-10-26 00:36:40 +02002607 if (len < (IEEE80211_MIN_ACTION_SIZE +
2608 sizeof(mgmt->u.action.u.self_prot.action_code)))
2609 break;
2610
Thomas Pedersen8db09852011-08-12 20:01:00 -07002611 switch (mgmt->u.action.u.self_prot.action_code) {
2612 case WLAN_SP_MESH_PEERING_OPEN:
2613 case WLAN_SP_MESH_PEERING_CLOSE:
2614 case WLAN_SP_MESH_PEERING_CONFIRM:
2615 if (!ieee80211_vif_is_mesh(&sdata->vif))
2616 goto invalid;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08002617 if (sdata->u.mesh.user_mpm)
Thomas Pedersen8db09852011-08-12 20:01:00 -07002618 /* userspace handles this frame */
2619 break;
2620 goto queue;
2621 case WLAN_SP_MGK_INFORM:
2622 case WLAN_SP_MGK_ACK:
2623 if (!ieee80211_vif_is_mesh(&sdata->vif))
2624 goto invalid;
2625 break;
2626 }
2627 break;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -07002628 case WLAN_CATEGORY_MESH_ACTION:
Johannes Berg9b395bc2012-10-26 00:36:40 +02002629 if (len < (IEEE80211_MIN_ACTION_SIZE +
2630 sizeof(mgmt->u.action.u.mesh_action.action_code)))
2631 break;
2632
Johannes Berg77a121c2010-06-10 10:21:34 +02002633 if (!ieee80211_vif_is_mesh(&sdata->vif))
2634 break;
Thomas Pedersen25d49e42011-08-11 19:35:15 -07002635 if (mesh_action_is_path_sel(mgmt) &&
Johannes Berg1df332e2012-10-26 00:09:11 +02002636 !mesh_path_sel_is_hwmp(sdata))
Javier Cardonac7108a72010-12-16 17:37:50 -08002637 break;
2638 goto queue;
Johannes Berg84040802010-02-15 12:46:39 +02002639 }
Jouni Malinen026331c2010-02-15 12:53:10 +02002640
Johannes Berg2e161f72010-08-12 15:38:38 +02002641 return RX_CONTINUE;
2642
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002643 invalid:
Johannes Berg554891e2010-09-24 12:38:25 +02002644 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
Johannes Berg2e161f72010-08-12 15:38:38 +02002645 /* will return in the next handlers */
2646 return RX_CONTINUE;
2647
2648 handled:
2649 if (rx->sta)
2650 rx->sta->rx_packets++;
2651 dev_kfree_skb(rx->skb);
2652 return RX_QUEUED;
2653
2654 queue:
2655 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2656 skb_queue_tail(&sdata->skb_queue, rx->skb);
2657 ieee80211_queue_work(&local->hw, &sdata->work);
2658 if (rx->sta)
2659 rx->sta->rx_packets++;
2660 return RX_QUEUED;
2661}
2662
2663static ieee80211_rx_result debug_noinline
2664ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2665{
Johannes Berg554891e2010-09-24 12:38:25 +02002666 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg804483e2012-03-05 22:18:41 +01002667 int sig = 0;
Johannes Berg2e161f72010-08-12 15:38:38 +02002668
2669 /* skip known-bad action frames and return them in the next handler */
Johannes Berg554891e2010-09-24 12:38:25 +02002670 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
Johannes Berg2e161f72010-08-12 15:38:38 +02002671 return RX_CONTINUE;
Felix Fietkaud7907442010-01-07 20:23:53 +01002672
Jouni Malinen026331c2010-02-15 12:53:10 +02002673 /*
2674 * Getting here means the kernel doesn't know how to handle
2675 * it, but maybe userspace does ... include returned frames
2676 * so userspace can register for those to know whether ones
2677 * it transmitted were processed or returned.
2678 */
Jouni Malinen026331c2010-02-15 12:53:10 +02002679
Johannes Berg804483e2012-03-05 22:18:41 +01002680 if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
2681 sig = status->signal;
2682
Johannes Berg71bbc992012-06-15 15:30:18 +02002683 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +03002684 rx->skb->data, rx->skb->len, 0, GFP_ATOMIC)) {
Johannes Berg2e161f72010-08-12 15:38:38 +02002685 if (rx->sta)
2686 rx->sta->rx_packets++;
2687 dev_kfree_skb(rx->skb);
2688 return RX_QUEUED;
2689 }
2690
Johannes Berg2e161f72010-08-12 15:38:38 +02002691 return RX_CONTINUE;
2692}
2693
2694static ieee80211_rx_result debug_noinline
2695ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2696{
2697 struct ieee80211_local *local = rx->local;
2698 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2699 struct sk_buff *nskb;
2700 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02002701 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002702
2703 if (!ieee80211_is_action(mgmt->frame_control))
2704 return RX_CONTINUE;
2705
2706 /*
2707 * For AP mode, hostapd is responsible for handling any action
2708 * frames that we didn't handle, including returning unknown
2709 * ones. For all other modes we will return them to the sender,
2710 * setting the 0x80 bit in the action category, as required by
Johannes Berg4b5ebcc2012-06-27 15:38:56 +02002711 * 802.11-2012 9.24.4.
Johannes Berg2e161f72010-08-12 15:38:38 +02002712 * Newer versions of hostapd shall also use the management frame
2713 * registration mechanisms, but older ones still use cooked
2714 * monitor interfaces so push all frames there.
2715 */
Johannes Berg554891e2010-09-24 12:38:25 +02002716 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
Johannes Berg2e161f72010-08-12 15:38:38 +02002717 (sdata->vif.type == NL80211_IFTYPE_AP ||
2718 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
2719 return RX_DROP_MONITOR;
Jouni Malinen026331c2010-02-15 12:53:10 +02002720
Johannes Berg4b5ebcc2012-06-27 15:38:56 +02002721 if (is_multicast_ether_addr(mgmt->da))
2722 return RX_DROP_MONITOR;
2723
Johannes Berg84040802010-02-15 12:46:39 +02002724 /* do not return rejected action frames */
2725 if (mgmt->u.action.category & 0x80)
2726 return RX_DROP_UNUSABLE;
2727
2728 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
2729 GFP_ATOMIC);
2730 if (nskb) {
John W. Linville292b4df2010-06-24 11:13:56 -04002731 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
Johannes Berg84040802010-02-15 12:46:39 +02002732
John W. Linville292b4df2010-06-24 11:13:56 -04002733 nmgmt->u.action.category |= 0x80;
2734 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
2735 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
Johannes Berg84040802010-02-15 12:46:39 +02002736
2737 memset(nskb->cb, 0, sizeof(nskb->cb));
2738
Johannes Berg07e5a5f2013-03-07 13:22:05 +01002739 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
2740 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
2741
2742 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
2743 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
2744 IEEE80211_TX_CTL_NO_CCK_RATE;
2745 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
2746 info->hw_queue =
2747 local->hw.offchannel_tx_hw_queue;
2748 }
2749
2750 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
2751 status->band);
Johannes Bergde1ede72008-09-09 14:42:50 +02002752 }
Johannes Berg39192c02008-09-09 14:49:03 +02002753 dev_kfree_skb(rx->skb);
2754 return RX_QUEUED;
Johannes Bergde1ede72008-09-09 14:42:50 +02002755}
2756
2757static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002758ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02002759{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002760 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg77a121c2010-06-10 10:21:34 +02002761 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
2762 __le16 stype;
Johannes Berg571ecf62007-07-27 15:43:22 +02002763
Johannes Berg77a121c2010-06-10 10:21:34 +02002764 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
Johannes Berg472dbc42008-09-11 00:01:49 +02002765
Johannes Berg77a121c2010-06-10 10:21:34 +02002766 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
2767 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2768 sdata->vif.type != NL80211_IFTYPE_STATION)
2769 return RX_DROP_MONITOR;
Johannes Bergf9d540e2007-09-28 14:02:09 +02002770
Johannes Berg77a121c2010-06-10 10:21:34 +02002771 switch (stype) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002772 case cpu_to_le16(IEEE80211_STYPE_AUTH):
Johannes Berg77a121c2010-06-10 10:21:34 +02002773 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2774 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2775 /* process for all: mesh, mlme, ibss */
2776 break;
Johannes Berg66e67e42012-01-20 13:55:27 +01002777 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
2778 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
Johannes Berg77a121c2010-06-10 10:21:34 +02002779 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2780 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
Christian Lamparter2c313332010-11-29 20:53:23 +01002781 if (is_multicast_ether_addr(mgmt->da) &&
2782 !is_broadcast_ether_addr(mgmt->da))
2783 return RX_DROP_MONITOR;
2784
Johannes Berg77a121c2010-06-10 10:21:34 +02002785 /* process only for station */
2786 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2787 return RX_DROP_MONITOR;
2788 break;
2789 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
Thomas Pedersen9fb04b52013-02-14 11:20:14 -08002790 /* process only for ibss and mesh */
2791 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2792 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Johannes Berg77a121c2010-06-10 10:21:34 +02002793 return RX_DROP_MONITOR;
2794 break;
2795 default:
2796 return RX_DROP_MONITOR;
2797 }
Johannes Berg46900292009-02-15 12:44:28 +01002798
Johannes Berg77a121c2010-06-10 10:21:34 +02002799 /* queue up frame and kick off work to process it */
Johannes Bergc1475ca2010-06-10 10:21:37 +02002800 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg77a121c2010-06-10 10:21:34 +02002801 skb_queue_tail(&sdata->skb_queue, rx->skb);
2802 ieee80211_queue_work(&rx->local->hw, &sdata->work);
Johannes Berg8b58ff82010-06-10 10:21:51 +02002803 if (rx->sta)
2804 rx->sta->rx_packets++;
Johannes Berg77a121c2010-06-10 10:21:34 +02002805
2806 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002807}
2808
Johannes Berg5cf121c2008-02-25 16:27:43 +01002809/* TODO: use IEEE80211_RX_FRAGMENTED */
Johannes Berg5f0b7de2009-11-16 13:58:21 +01002810static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
2811 struct ieee80211_rate *rate)
Michael Wu3d30d942008-01-31 19:48:27 +01002812{
2813 struct ieee80211_sub_if_data *sdata;
2814 struct ieee80211_local *local = rx->local;
Michael Wu3d30d942008-01-31 19:48:27 +01002815 struct sk_buff *skb = rx->skb, *skb2;
2816 struct net_device *prev_dev = NULL;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002817 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg293702a2012-03-02 13:18:19 +01002818 int needed_headroom;
Michael Wu3d30d942008-01-31 19:48:27 +01002819
Johannes Berg554891e2010-09-24 12:38:25 +02002820 /*
2821 * If cooked monitor has been processed already, then
2822 * don't do it again. If not, set the flag.
2823 */
2824 if (rx->flags & IEEE80211_RX_CMNTR)
John W. Linville7c1e1832010-09-24 15:52:49 -04002825 goto out_free_skb;
Johannes Berg554891e2010-09-24 12:38:25 +02002826 rx->flags |= IEEE80211_RX_CMNTR;
John W. Linville7c1e1832010-09-24 15:52:49 -04002827
Johannes Berg152c4772011-10-21 10:22:22 +02002828 /* If there are no cooked monitor interfaces, just free the SKB */
2829 if (!local->cooked_mntrs)
2830 goto out_free_skb;
2831
Johannes Berg293702a2012-03-02 13:18:19 +01002832 /* room for the radiotap header based on driver features */
Johannes Berg90b9e4462012-11-16 10:09:08 +01002833 needed_headroom = ieee80211_rx_radiotap_space(local, status);
Johannes Berg293702a2012-03-02 13:18:19 +01002834
2835 if (skb_headroom(skb) < needed_headroom &&
2836 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
Michael Wu3d30d942008-01-31 19:48:27 +01002837 goto out_free_skb;
2838
Johannes Berg293702a2012-03-02 13:18:19 +01002839 /* prepend radiotap information */
Felix Fietkau973ef212012-04-16 14:56:48 +02002840 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
2841 false);
Michael Wu3d30d942008-01-31 19:48:27 +01002842
2843 skb_set_mac_header(skb, 0);
2844 skb->ip_summed = CHECKSUM_UNNECESSARY;
2845 skb->pkt_type = PACKET_OTHERHOST;
2846 skb->protocol = htons(ETH_P_802_2);
2847
2848 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01002849 if (!ieee80211_sdata_running(sdata))
Michael Wu3d30d942008-01-31 19:48:27 +01002850 continue;
2851
Johannes Berg05c914f2008-09-11 00:01:58 +02002852 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
Michael Wu3d30d942008-01-31 19:48:27 +01002853 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
2854 continue;
2855
2856 if (prev_dev) {
2857 skb2 = skb_clone(skb, GFP_ATOMIC);
2858 if (skb2) {
2859 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04002860 netif_receive_skb(skb2);
Michael Wu3d30d942008-01-31 19:48:27 +01002861 }
2862 }
2863
2864 prev_dev = sdata->dev;
2865 sdata->dev->stats.rx_packets++;
2866 sdata->dev->stats.rx_bytes += skb->len;
2867 }
2868
2869 if (prev_dev) {
2870 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04002871 netif_receive_skb(skb);
Johannes Berg554891e2010-09-24 12:38:25 +02002872 return;
2873 }
Michael Wu3d30d942008-01-31 19:48:27 +01002874
2875 out_free_skb:
2876 dev_kfree_skb(skb);
2877}
2878
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002879static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
2880 ieee80211_rx_result res)
2881{
2882 switch (res) {
2883 case RX_DROP_MONITOR:
2884 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2885 if (rx->sta)
2886 rx->sta->rx_dropped++;
2887 /* fall through */
2888 case RX_CONTINUE: {
2889 struct ieee80211_rate *rate = NULL;
2890 struct ieee80211_supported_band *sband;
2891 struct ieee80211_rx_status *status;
2892
2893 status = IEEE80211_SKB_RXCB((rx->skb));
2894
2895 sband = rx->local->hw.wiphy->bands[status->band];
Johannes Berg56146182012-11-09 15:07:02 +01002896 if (!(status->flag & RX_FLAG_HT) &&
2897 !(status->flag & RX_FLAG_VHT))
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002898 rate = &sband->bitrates[status->rate_idx];
2899
2900 ieee80211_rx_cooked_monitor(rx, rate);
2901 break;
2902 }
2903 case RX_DROP_UNUSABLE:
2904 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
2905 if (rx->sta)
2906 rx->sta->rx_dropped++;
2907 dev_kfree_skb(rx->skb);
2908 break;
2909 case RX_QUEUED:
2910 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
2911 break;
2912 }
2913}
2914
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002915static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
2916 struct sk_buff_head *frames)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002917{
2918 ieee80211_rx_result res = RX_DROP_MONITOR;
2919 struct sk_buff *skb;
2920
2921#define CALL_RXH(rxh) \
2922 do { \
2923 res = rxh(rx); \
2924 if (res != RX_CONTINUE) \
2925 goto rxh_next; \
2926 } while (0);
2927
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002928 spin_lock_bh(&rx->local->rx_path_lock);
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002929
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002930 while ((skb = __skb_dequeue(frames))) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002931 /*
2932 * all the other fields are valid across frames
2933 * that belong to an aMPDU since they are on the
2934 * same TID from the same station
2935 */
2936 rx->skb = skb;
2937
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002938 CALL_RXH(ieee80211_rx_h_check_more_data)
Johannes Berg47086fc2011-09-29 16:04:33 +02002939 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002940 CALL_RXH(ieee80211_rx_h_sta_process)
Johan Almbladh86c228a2013-08-14 15:29:46 +02002941 CALL_RXH(ieee80211_rx_h_decrypt)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002942 CALL_RXH(ieee80211_rx_h_defragment)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002943 CALL_RXH(ieee80211_rx_h_michael_mic_verify)
2944 /* must be after MMIC verify so header is counted in MPDU mic */
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002945#ifdef CONFIG_MAC80211_MESH
2946 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
2947 CALL_RXH(ieee80211_rx_h_mesh_fwding);
2948#endif
Javier Cardona2154c812011-09-07 17:49:53 -07002949 CALL_RXH(ieee80211_rx_h_amsdu)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002950 CALL_RXH(ieee80211_rx_h_data)
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002951
2952 /* special treatment -- needs the queue */
2953 res = ieee80211_rx_h_ctrl(rx, frames);
2954 if (res != RX_CONTINUE)
2955 goto rxh_next;
2956
Johannes Berg2e161f72010-08-12 15:38:38 +02002957 CALL_RXH(ieee80211_rx_h_mgmt_check)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002958 CALL_RXH(ieee80211_rx_h_action)
Johannes Berg2e161f72010-08-12 15:38:38 +02002959 CALL_RXH(ieee80211_rx_h_userspace_mgmt)
2960 CALL_RXH(ieee80211_rx_h_action_return)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002961 CALL_RXH(ieee80211_rx_h_mgmt)
2962
2963 rxh_next:
2964 ieee80211_rx_handlers_result(rx, res);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002965
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002966#undef CALL_RXH
2967 }
Christian Lamparter24a8fda2010-12-30 17:25:29 +01002968
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002969 spin_unlock_bh(&rx->local->rx_path_lock);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002970}
Johannes Berg571ecf62007-07-27 15:43:22 +02002971
Johannes Berg4406c372010-09-24 11:21:06 +02002972static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
Johannes Berg58905292008-01-31 19:48:25 +01002973{
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002974 struct sk_buff_head reorder_release;
Johannes Berg58905292008-01-31 19:48:25 +01002975 ieee80211_rx_result res = RX_DROP_MONITOR;
2976
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002977 __skb_queue_head_init(&reorder_release);
2978
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002979#define CALL_RXH(rxh) \
2980 do { \
2981 res = rxh(rx); \
2982 if (res != RX_CONTINUE) \
Johannes Berg2569a822009-11-25 17:46:17 +01002983 goto rxh_next; \
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002984 } while (0);
Johannes Berg58905292008-01-31 19:48:25 +01002985
Johannes Berg49461622008-06-30 15:10:45 +02002986 CALL_RXH(ieee80211_rx_h_check)
Johannes Berg2569a822009-11-25 17:46:17 +01002987
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002988 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
Johannes Berg2569a822009-11-25 17:46:17 +01002989
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002990 ieee80211_rx_handlers(rx, &reorder_release);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002991 return;
Johannes Berg49461622008-06-30 15:10:45 +02002992
Johannes Berg2569a822009-11-25 17:46:17 +01002993 rxh_next:
Christian Lamparteraa0c8632010-08-05 01:36:04 +02002994 ieee80211_rx_handlers_result(rx, res);
2995
2996#undef CALL_RXH
Johannes Berg58905292008-01-31 19:48:25 +01002997}
2998
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02002999/*
Johannes Bergdd318572010-11-29 11:09:16 +01003000 * This function makes calls into the RX path, therefore
3001 * it has to be invoked under RCU read lock.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003002 */
3003void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3004{
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003005 struct sk_buff_head frames;
Johannes Berg554891e2010-09-24 12:38:25 +02003006 struct ieee80211_rx_data rx = {
3007 .sta = sta,
3008 .sdata = sta->sdata,
3009 .local = sta->local,
Johannes Berg9e262972011-07-07 18:45:03 +02003010 /* This is OK -- must be QoS data frame */
3011 .security_idx = tid,
3012 .seqno_idx = tid,
Helmut Schaafcf8bd32011-04-01 15:46:05 +02003013 .flags = 0,
Johannes Berg554891e2010-09-24 12:38:25 +02003014 };
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003015 struct tid_ampdu_rx *tid_agg_rx;
3016
3017 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3018 if (!tid_agg_rx)
3019 return;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003020
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003021 __skb_queue_head_init(&frames);
3022
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003023 spin_lock(&tid_agg_rx->reorder_lock);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003024 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003025 spin_unlock(&tid_agg_rx->reorder_lock);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003026
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003027 ieee80211_rx_handlers(&rx, &frames);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003028}
3029
Johannes Berg571ecf62007-07-27 15:43:22 +02003030/* main receive path */
3031
Johannes Berg3c2723f52014-01-07 16:23:24 +01003032static bool prepare_for_handlers(struct ieee80211_rx_data *rx,
3033 struct ieee80211_hdr *hdr)
Johannes Berg23a24de2007-07-27 15:43:22 +02003034{
Johannes Berg20b01f82010-09-24 11:21:05 +02003035 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01003036 struct sk_buff *skb = rx->skb;
3037 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3038 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
Johannes Berg23a24de2007-07-27 15:43:22 +02003039 int multicast = is_multicast_ether_addr(hdr->addr1);
3040
Johannes Berg51fb61e2007-12-19 01:31:27 +01003041 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003042 case NL80211_IFTYPE_STATION:
Johannes Berg9bc383d2009-11-19 11:55:19 +01003043 if (!bssid && !sdata->u.mgd.use_4addr)
Johannes Berg3c2723f52014-01-07 16:23:24 +01003044 return false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003045 if (!multicast &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003046 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
Felix Fietkau4f312332011-02-05 23:48:37 +01003047 if (!(sdata->dev->flags & IFF_PROMISC) ||
3048 sdata->u.mgd.use_4addr)
Johannes Berg3c2723f52014-01-07 16:23:24 +01003049 return false;
Johannes Berg554891e2010-09-24 12:38:25 +02003050 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02003051 }
3052 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02003053 case NL80211_IFTYPE_ADHOC:
Johannes Berg23a24de2007-07-27 15:43:22 +02003054 if (!bssid)
Johannes Berg3c2723f52014-01-07 16:23:24 +01003055 return false;
Felix Fietkau6329b8d2013-09-17 11:15:43 +02003056 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3057 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003058 return false;
Harvey Harrisona7767f92008-07-02 16:30:51 -07003059 if (ieee80211_is_beacon(hdr->frame_control)) {
Johannes Berg3c2723f52014-01-07 16:23:24 +01003060 return true;
Johannes Bergd48b2962012-07-06 22:19:27 +02003061 } else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
Johannes Berg3c2723f52014-01-07 16:23:24 +01003062 return false;
Johannes Berg23a24de2007-07-27 15:43:22 +02003063 } else if (!multicast &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003064 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
Johannes Berg4150c572007-09-17 01:29:23 -04003065 if (!(sdata->dev->flags & IFF_PROMISC))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003066 return false;
Johannes Berg554891e2010-09-24 12:38:25 +02003067 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003068 } else if (!rx->sta) {
3069 int rate_idx;
Johannes Berg56146182012-11-09 15:07:02 +01003070 if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
3071 rate_idx = 0; /* TODO: HT/VHT rates */
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003072 else
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01003073 rate_idx = status->rate_idx;
Johannes Berg8bf11d82011-12-15 11:17:37 +01003074 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3075 BIT(rate_idx));
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003076 }
Johannes Berg23a24de2007-07-27 15:43:22 +02003077 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02003078 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg6032f932008-02-23 15:17:07 +01003079 if (!multicast &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003080 !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
Johannes Berg6032f932008-02-23 15:17:07 +01003081 if (!(sdata->dev->flags & IFF_PROMISC))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003082 return false;
Johannes Berg6032f932008-02-23 15:17:07 +01003083
Johannes Berg554891e2010-09-24 12:38:25 +02003084 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg6032f932008-02-23 15:17:07 +01003085 }
3086 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02003087 case NL80211_IFTYPE_AP_VLAN:
3088 case NL80211_IFTYPE_AP:
Johannes Berg23a24de2007-07-27 15:43:22 +02003089 if (!bssid) {
Joe Perchesb203ca32012-05-08 18:56:52 +00003090 if (!ether_addr_equal(sdata->vif.addr, hdr->addr1))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003091 return false;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003092 } else if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
Johannes Berg3df6eae2011-12-06 10:39:40 +01003093 /*
3094 * Accept public action frames even when the
3095 * BSSID doesn't match, this is used for P2P
3096 * and location updates. Note that mac80211
3097 * itself never looks at these frames.
3098 */
Johannes Berg2b9ccd42013-05-13 16:42:40 +02003099 if (!multicast &&
3100 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003101 return false;
Johannes Bergd48b2962012-07-06 22:19:27 +02003102 if (ieee80211_is_public_action(hdr, skb->len))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003103 return true;
Johannes Bergd48b2962012-07-06 22:19:27 +02003104 if (!ieee80211_is_beacon(hdr->frame_control))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003105 return false;
Johannes Berg554891e2010-09-24 12:38:25 +02003106 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
Johannes Berg23a24de2007-07-27 15:43:22 +02003107 }
Johannes Berg23a24de2007-07-27 15:43:22 +02003108 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02003109 case NL80211_IFTYPE_WDS:
Harvey Harrisona7767f92008-07-02 16:30:51 -07003110 if (bssid || !ieee80211_is_data(hdr->frame_control))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003111 return false;
Joe Perchesb203ca32012-05-08 18:56:52 +00003112 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003113 return false;
Johannes Berg23a24de2007-07-27 15:43:22 +02003114 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003115 case NL80211_IFTYPE_P2P_DEVICE:
3116 if (!ieee80211_is_public_action(hdr, skb->len) &&
3117 !ieee80211_is_probe_req(hdr->frame_control) &&
3118 !ieee80211_is_probe_resp(hdr->frame_control) &&
3119 !ieee80211_is_beacon(hdr->frame_control))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003120 return false;
Johannes Berg1b737f82013-04-18 23:42:19 +02003121 if (!ether_addr_equal(sdata->vif.addr, hdr->addr1) &&
3122 !multicast)
Johannes Bergf142c6b2012-06-18 20:07:15 +02003123 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
3124 break;
Johannes Berg2ca27bc2010-09-16 14:58:23 +02003125 default:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02003126 /* should never get here */
Johannes Bergf142c6b2012-06-18 20:07:15 +02003127 WARN_ON_ONCE(1);
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02003128 break;
Johannes Berg23a24de2007-07-27 15:43:22 +02003129 }
3130
Johannes Berg3c2723f52014-01-07 16:23:24 +01003131 return true;
Johannes Berg23a24de2007-07-27 15:43:22 +02003132}
3133
Johannes Berg571ecf62007-07-27 15:43:22 +02003134/*
Johannes Berg4406c372010-09-24 11:21:06 +02003135 * This function returns whether or not the SKB
3136 * was destined for RX processing or not, which,
3137 * if consume is true, is equivalent to whether
3138 * or not the skb was consumed.
3139 */
3140static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
3141 struct sk_buff *skb, bool consume)
3142{
3143 struct ieee80211_local *local = rx->local;
3144 struct ieee80211_sub_if_data *sdata = rx->sdata;
3145 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3146 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg4406c372010-09-24 11:21:06 +02003147
3148 rx->skb = skb;
Johannes Berg554891e2010-09-24 12:38:25 +02003149 status->rx_flags |= IEEE80211_RX_RA_MATCH;
Johannes Berg4406c372010-09-24 11:21:06 +02003150
Emmanuel Grumbach40791942014-01-07 13:10:20 +02003151 if (!prepare_for_handlers(rx, hdr))
Johannes Berg4406c372010-09-24 11:21:06 +02003152 return false;
3153
Johannes Berg4406c372010-09-24 11:21:06 +02003154 if (!consume) {
3155 skb = skb_copy(skb, GFP_ATOMIC);
3156 if (!skb) {
3157 if (net_ratelimit())
3158 wiphy_debug(local->hw.wiphy,
Ben Greearb305dae2011-01-08 10:30:54 -08003159 "failed to copy skb for %s\n",
Johannes Berg4406c372010-09-24 11:21:06 +02003160 sdata->name);
3161 return true;
3162 }
3163
3164 rx->skb = skb;
3165 }
3166
3167 ieee80211_invoke_rx_handlers(rx);
3168 return true;
3169}
3170
3171/*
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003172 * This is the actual Rx frames handler. as it blongs to Rx path it must
3173 * be called with rcu_read_lock protection.
Johannes Berg571ecf62007-07-27 15:43:22 +02003174 */
Ron Rindjunsky71ebb4a2008-01-21 12:39:12 +02003175static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
Christian Lamparter071d9ac2010-08-05 01:36:36 +02003176 struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02003177{
3178 struct ieee80211_local *local = hw_to_local(hw);
3179 struct ieee80211_sub_if_data *sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02003180 struct ieee80211_hdr *hdr;
Zhu Yie3cf8b32010-03-29 17:35:07 +08003181 __le16 fc;
Johannes Berg5cf121c2008-02-25 16:27:43 +01003182 struct ieee80211_rx_data rx;
Johannes Berg4406c372010-09-24 11:21:06 +02003183 struct ieee80211_sub_if_data *prev;
Ben Greear56af3262010-09-23 10:22:24 -07003184 struct sta_info *sta, *tmp, *prev_sta;
Zhu Yie3cf8b32010-03-29 17:35:07 +08003185 int err = 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02003186
Zhu Yie3cf8b32010-03-29 17:35:07 +08003187 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
Johannes Berg571ecf62007-07-27 15:43:22 +02003188 memset(&rx, 0, sizeof(rx));
3189 rx.skb = skb;
3190 rx.local = local;
Johannes Berg72abd812007-09-17 01:29:22 -04003191
Zhu Yie3cf8b32010-03-29 17:35:07 +08003192 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
Johannes Berg571ecf62007-07-27 15:43:22 +02003193 local->dot11ReceivedFragmentCount++;
Johannes Berg571ecf62007-07-27 15:43:22 +02003194
Johannes Berg4a4f1a52012-10-26 00:33:36 +02003195 if (ieee80211_is_mgmt(fc)) {
3196 /* drop frame if too short for header */
3197 if (skb->len < ieee80211_hdrlen(fc))
3198 err = -ENOBUFS;
3199 else
3200 err = skb_linearize(skb);
3201 } else {
Zhu Yie3cf8b32010-03-29 17:35:07 +08003202 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
Johannes Berg4a4f1a52012-10-26 00:33:36 +02003203 }
Zhu Yie3cf8b32010-03-29 17:35:07 +08003204
3205 if (err) {
3206 dev_kfree_skb(skb);
3207 return;
3208 }
3209
3210 hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg38f37142008-01-29 17:07:43 +01003211 ieee80211_parse_qos(&rx);
Johannes Bergd1c3a372009-01-07 00:26:10 +01003212 ieee80211_verify_alignment(&rx);
Johannes Berg38f37142008-01-29 17:07:43 +01003213
Johannes Bergd48b2962012-07-06 22:19:27 +02003214 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
3215 ieee80211_is_beacon(hdr->frame_control)))
3216 ieee80211_scan_rx(local, skb);
3217
Zhu Yie3cf8b32010-03-29 17:35:07 +08003218 if (ieee80211_is_data(fc)) {
Ben Greear56af3262010-09-23 10:22:24 -07003219 prev_sta = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02003220
Johannes Berg7852e362012-01-20 13:55:24 +01003221 for_each_sta_info(local, hdr->addr2, sta, tmp) {
Ben Greear56af3262010-09-23 10:22:24 -07003222 if (!prev_sta) {
3223 prev_sta = sta;
3224 continue;
3225 }
3226
3227 rx.sta = prev_sta;
3228 rx.sdata = prev_sta->sdata;
Johannes Berg4406c372010-09-24 11:21:06 +02003229 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Johannes Berg571ecf62007-07-27 15:43:22 +02003230
Ben Greear56af3262010-09-23 10:22:24 -07003231 prev_sta = sta;
Johannes Berg4406c372010-09-24 11:21:06 +02003232 }
Ben Greear56af3262010-09-23 10:22:24 -07003233
3234 if (prev_sta) {
3235 rx.sta = prev_sta;
3236 rx.sdata = prev_sta->sdata;
3237
Johannes Berg4406c372010-09-24 11:21:06 +02003238 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
Ben Greear56af3262010-09-23 10:22:24 -07003239 return;
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05303240 goto out;
Ben Greear56af3262010-09-23 10:22:24 -07003241 }
Johannes Berg4406c372010-09-24 11:21:06 +02003242 }
3243
Johannes Berg4b0dd982010-09-24 11:21:07 +02003244 prev = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02003245
Johannes Berg4b0dd982010-09-24 11:21:07 +02003246 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3247 if (!ieee80211_sdata_running(sdata))
3248 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01003249
Johannes Berg4b0dd982010-09-24 11:21:07 +02003250 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
3251 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3252 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01003253
Johannes Berg4b0dd982010-09-24 11:21:07 +02003254 /*
3255 * frame is destined for this interface, but if it's
3256 * not also for the previous one we handle that after
3257 * the loop to avoid copying the SKB once too much
3258 */
Johannes Bergb2e77712007-09-26 15:19:39 +02003259
Johannes Berg4b0dd982010-09-24 11:21:07 +02003260 if (!prev) {
Johannes Berg340e11f2007-07-27 15:43:22 +02003261 prev = sdata;
Johannes Berg4b0dd982010-09-24 11:21:07 +02003262 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02003263 }
Felix Fietkau4bb29f82010-01-22 00:36:39 +01003264
Johannes Berg7852e362012-01-20 13:55:24 +01003265 rx.sta = sta_info_get_bss(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02003266 rx.sdata = prev;
3267 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Felix Fietkau4bb29f82010-01-22 00:36:39 +01003268
Johannes Berg4b0dd982010-09-24 11:21:07 +02003269 prev = sdata;
3270 }
Johannes Berg4406c372010-09-24 11:21:06 +02003271
Johannes Berg4b0dd982010-09-24 11:21:07 +02003272 if (prev) {
Johannes Berg7852e362012-01-20 13:55:24 +01003273 rx.sta = sta_info_get_bss(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02003274 rx.sdata = prev;
3275
3276 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3277 return;
Johannes Berg571ecf62007-07-27 15:43:22 +02003278 }
Johannes Berg4406c372010-09-24 11:21:06 +02003279
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05303280 out:
Johannes Berg4406c372010-09-24 11:21:06 +02003281 dev_kfree_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02003282}
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003283
3284/*
3285 * This is the receive path handler. It is called by a low level driver when an
3286 * 802.11 MPDU is received from the hardware.
3287 */
John W. Linville103bf9f2009-08-20 16:34:15 -04003288void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003289{
3290 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg8318d782008-01-24 19:38:38 +01003291 struct ieee80211_rate *rate = NULL;
3292 struct ieee80211_supported_band *sband;
Johannes Bergf1d58c22009-06-17 13:13:00 +02003293 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg8318d782008-01-24 19:38:38 +01003294
Johannes Bergd20ef632009-10-11 15:10:40 +02003295 WARN_ON_ONCE(softirq_count() == 0);
3296
Johannes Berg444e38032012-09-30 17:08:35 +02003297 if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
Johannes Berg77a980d2009-08-24 11:46:30 +02003298 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01003299
3300 sband = local->hw.wiphy->bands[status->band];
Johannes Berg77a980d2009-08-24 11:46:30 +02003301 if (WARN_ON(!sband))
3302 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01003303
Johannes Berg89c3a8a2009-07-28 18:10:17 +02003304 /*
3305 * If we're suspending, it is possible although not too likely
3306 * that we'd be receiving frames after having already partially
3307 * quiesced the stack. We can't process such frames then since
3308 * that might, for example, cause stations to be added or other
3309 * driver callbacks be invoked.
3310 */
Johannes Berg77a980d2009-08-24 11:46:30 +02003311 if (unlikely(local->quiescing || local->suspended))
3312 goto drop;
Johannes Berg89c3a8a2009-07-28 18:10:17 +02003313
Arik Nemtsov04800ad2012-06-06 11:25:02 +03003314 /* We might be during a HW reconfig, prevent Rx for the same reason */
3315 if (unlikely(local->in_reconfig))
3316 goto drop;
3317
Johannes Bergea77f122009-08-21 14:44:45 +02003318 /*
3319 * The same happens when we're not even started,
3320 * but that's worth a warning.
3321 */
Johannes Berg77a980d2009-08-24 11:46:30 +02003322 if (WARN_ON(!local->started))
3323 goto drop;
Johannes Bergea77f122009-08-21 14:44:45 +02003324
Johannes Bergfc885182010-07-30 13:23:12 +02003325 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05003326 /*
Johannes Bergfc885182010-07-30 13:23:12 +02003327 * Validate the rate, unless a PLCP error means that
3328 * we probably can't have a valid rate here anyway.
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05003329 */
Johannes Bergfc885182010-07-30 13:23:12 +02003330
3331 if (status->flag & RX_FLAG_HT) {
3332 /*
3333 * rate_idx is MCS index, which can be [0-76]
3334 * as documented on:
3335 *
3336 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
3337 *
3338 * Anything else would be some sort of driver or
3339 * hardware error. The driver should catch hardware
3340 * errors.
3341 */
Johannes Berg444e38032012-09-30 17:08:35 +02003342 if (WARN(status->rate_idx > 76,
Johannes Bergfc885182010-07-30 13:23:12 +02003343 "Rate marked as an HT rate but passed "
3344 "status->rate_idx is not "
3345 "an MCS index [0-76]: %d (0x%02x)\n",
3346 status->rate_idx,
3347 status->rate_idx))
3348 goto drop;
Johannes Berg56146182012-11-09 15:07:02 +01003349 } else if (status->flag & RX_FLAG_VHT) {
3350 if (WARN_ONCE(status->rate_idx > 9 ||
3351 !status->vht_nss ||
3352 status->vht_nss > 8,
3353 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
3354 status->rate_idx, status->vht_nss))
3355 goto drop;
Johannes Bergfc885182010-07-30 13:23:12 +02003356 } else {
Johannes Berg444e38032012-09-30 17:08:35 +02003357 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
Johannes Bergfc885182010-07-30 13:23:12 +02003358 goto drop;
3359 rate = &sband->bitrates[status->rate_idx];
3360 }
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003361 }
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003362
Johannes Berg554891e2010-09-24 12:38:25 +02003363 status->rx_flags = 0;
3364
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003365 /*
3366 * key references and virtual interfaces are protected using RCU
3367 * and this requires that we are in a read-side RCU section during
3368 * receive processing
3369 */
3370 rcu_read_lock();
3371
3372 /*
3373 * Frames with failed FCS/PLCP checksum are not returned,
3374 * all other frames are returned without radiotap header
3375 * if it was previously present.
3376 * Also, frames with less than 16 bytes are dropped.
3377 */
Johannes Bergf1d58c22009-06-17 13:13:00 +02003378 skb = ieee80211_rx_monitor(local, skb, rate);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003379 if (!skb) {
3380 rcu_read_unlock();
3381 return;
3382 }
3383
Johannes Berge1e54062010-11-30 08:58:45 +01003384 ieee80211_tpt_led_trig_rx(local,
3385 ((struct ieee80211_hdr *)skb->data)->frame_control,
3386 skb->len);
Christian Lamparter071d9ac2010-08-05 01:36:36 +02003387 __ieee80211_rx_handle_packet(hw, skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003388
3389 rcu_read_unlock();
Johannes Berg77a980d2009-08-24 11:46:30 +02003390
3391 return;
3392 drop:
3393 kfree_skb(skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003394}
John W. Linville103bf9f2009-08-20 16:34:15 -04003395EXPORT_SYMBOL(ieee80211_rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02003396
3397/* This is a version of the rx handler that can be called from hard irq
3398 * context. Post the skb on the queue and schedule the tasklet */
Johannes Bergf1d58c22009-06-17 13:13:00 +02003399void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02003400{
3401 struct ieee80211_local *local = hw_to_local(hw);
3402
3403 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
3404
Johannes Berg571ecf62007-07-27 15:43:22 +02003405 skb->pkt_type = IEEE80211_RX_MSG;
3406 skb_queue_tail(&local->skb_queue, skb);
3407 tasklet_schedule(&local->tasklet);
3408}
3409EXPORT_SYMBOL(ieee80211_rx_irqsafe);