blob: 64742f2765c4846c36d3f9304314059023215d0a [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 Bergd98ad832014-09-03 15:24:57 +03006 * Copyright 2013-2014 Intel Mobile Communications GmbH
Sara Sharonb7540d82017-02-06 15:28:42 +02007 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
Johannes Bergc096b922018-04-20 13:49:18 +03008 * Copyright (C) 2018 Intel Corporation
Johannes Berg571ecf62007-07-27 15:43:22 +02009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
S.Çağlar Onurab466232008-02-14 17:36:47 +020015#include <linux/jiffies.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020017#include <linux/kernel.h>
18#include <linux/skbuff.h>
19#include <linux/netdevice.h>
20#include <linux/etherdevice.h>
Johannes Bergd4e46a32007-09-14 11:10:24 -040021#include <linux/rcupdate.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040022#include <linux/export.h>
Sara Sharon06470f72016-01-28 16:19:25 +020023#include <linux/bitops.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020024#include <net/mac80211.h>
25#include <net/ieee80211_radiotap.h>
Johannes Bergd26ad372012-02-20 11:38:41 +010026#include <asm/unaligned.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020027
28#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020029#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040030#include "led.h"
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +010031#include "mesh.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020032#include "wep.h"
33#include "wpa.h"
34#include "tkip.h"
35#include "wme.h"
Johannes Berg1d8d3de2011-12-16 15:28:57 +010036#include "rate.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020037
Johannes Berg5a490512015-04-22 17:10:38 +020038static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
39{
40 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
41
42 u64_stats_update_begin(&tstats->syncp);
43 tstats->rx_packets++;
44 tstats->rx_bytes += len;
45 u64_stats_update_end(&tstats->syncp);
46}
47
Johannes Berga6828492015-06-16 15:17:15 +020048static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
49 enum nl80211_iftype type)
50{
51 __le16 fc = hdr->frame_control;
52
53 if (ieee80211_is_data(fc)) {
54 if (len < 24) /* drop incorrect hdr len (data) */
55 return NULL;
56
57 if (ieee80211_has_a4(fc))
58 return NULL;
59 if (ieee80211_has_tods(fc))
60 return hdr->addr1;
61 if (ieee80211_has_fromds(fc))
62 return hdr->addr2;
63
64 return hdr->addr3;
65 }
66
67 if (ieee80211_is_mgmt(fc)) {
68 if (len < 24) /* drop incorrect hdr len (mgmt) */
69 return NULL;
70 return hdr->addr3;
71 }
72
73 if (ieee80211_is_ctl(fc)) {
74 if (ieee80211_is_pspoll(fc))
75 return hdr->addr1;
76
77 if (ieee80211_is_back_req(fc)) {
78 switch (type) {
79 case NL80211_IFTYPE_STATION:
80 return hdr->addr2;
81 case NL80211_IFTYPE_AP:
82 case NL80211_IFTYPE_AP_VLAN:
83 return hdr->addr1;
84 default:
85 break; /* fall through to the return */
86 }
87 }
88 }
89
90 return NULL;
91}
92
Johannes Bergb2e77712007-09-26 15:19:39 +020093/*
94 * monitor mode reception
95 *
96 * This function cleans up the SKB, i.e. it removes all the stuff
97 * only useful for monitoring.
98 */
Johannes Berg30841f52017-04-11 15:38:56 +020099static void remove_monitor_info(struct sk_buff *skb,
100 unsigned int present_fcs_len,
Johannes Bergc096b922018-04-20 13:49:18 +0300101 unsigned int rtap_space)
Johannes Bergb2e77712007-09-26 15:19:39 +0200102{
Johannes Berg30841f52017-04-11 15:38:56 +0200103 if (present_fcs_len)
104 __pskb_trim(skb, skb->len - present_fcs_len);
Johannes Bergc096b922018-04-20 13:49:18 +0300105 __pskb_pull(skb, rtap_space);
Johannes Bergb2e77712007-09-26 15:19:39 +0200106}
107
Johannes Berg1f7bba72014-11-06 22:56:36 +0100108static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
Johannes Bergc096b922018-04-20 13:49:18 +0300109 unsigned int rtap_space)
Johannes Bergb2e77712007-09-26 15:19:39 +0200110{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200111 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg1f7bba72014-11-06 22:56:36 +0100112 struct ieee80211_hdr *hdr;
113
Johannes Bergc096b922018-04-20 13:49:18 +0300114 hdr = (void *)(skb->data + rtap_space);
Johannes Bergb2e77712007-09-26 15:19:39 +0200115
Johannes Berg4c298672012-07-05 11:34:31 +0200116 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
Grzegorz Bajorski17883042015-12-11 14:39:46 +0100117 RX_FLAG_FAILED_PLCP_CRC |
118 RX_FLAG_ONLY_MONITOR))
Zhao, Gang6b59db72014-04-21 12:52:59 +0800119 return true;
120
Johannes Bergc096b922018-04-20 13:49:18 +0300121 if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
Zhao, Gang6b59db72014-04-21 12:52:59 +0800122 return true;
123
Harvey Harrison87228f52008-06-11 14:21:59 -0700124 if (ieee80211_is_ctl(hdr->frame_control) &&
125 !ieee80211_is_pspoll(hdr->frame_control) &&
126 !ieee80211_is_back_req(hdr->frame_control))
Zhao, Gang6b59db72014-04-21 12:52:59 +0800127 return true;
128
129 return false;
Johannes Bergb2e77712007-09-26 15:19:39 +0200130}
131
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200132static int
Johannes Berg1f7bba72014-11-06 22:56:36 +0100133ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
134 struct ieee80211_rx_status *status,
135 struct sk_buff *skb)
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200136{
137 int len;
138
139 /* always present fields */
Johannes Berga144f372013-07-03 13:34:02 +0200140 len = sizeof(struct ieee80211_radiotap_header) + 8;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200141
Johannes Berga144f372013-07-03 13:34:02 +0200142 /* allocate extra bitmaps */
Johannes Berga144f372013-07-03 13:34:02 +0200143 if (status->chains)
144 len += 4 * hweight8(status->chains);
Johannes Berg90b9e4462012-11-16 10:09:08 +0100145
146 if (ieee80211_have_rx_timestamp(status)) {
147 len = ALIGN(len, 8);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200148 len += 8;
Johannes Berg90b9e4462012-11-16 10:09:08 +0100149 }
Johannes Berg30686bf2015-06-02 21:39:54 +0200150 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200151 len += 1;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200152
Johannes Berga144f372013-07-03 13:34:02 +0200153 /* antenna field, if we don't have per-chain info */
154 if (!status->chains)
155 len += 1;
156
Johannes Berg90b9e4462012-11-16 10:09:08 +0100157 /* padding for RX_FLAGS if necessary */
158 len = ALIGN(len, 2);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200159
Johannes Bergda6a4352017-04-26 12:14:59 +0200160 if (status->encoding == RX_ENC_HT) /* HT info */
Johannes Berg6d744ba2011-01-27 14:13:17 +0100161 len += 3;
162
Johannes Berg4c298672012-07-05 11:34:31 +0200163 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
Johannes Berg90b9e4462012-11-16 10:09:08 +0100164 len = ALIGN(len, 4);
Johannes Berg4c298672012-07-05 11:34:31 +0200165 len += 8;
166 }
167
Johannes Bergda6a4352017-04-26 12:14:59 +0200168 if (status->encoding == RX_ENC_VHT) {
Johannes Berg51648922012-11-22 23:00:18 +0100169 len = ALIGN(len, 2);
170 len += 12;
171 }
172
Johannes Berg99ee7ca2016-08-29 23:25:17 +0300173 if (local->hw.radiotap_timestamp.units_pos >= 0) {
174 len = ALIGN(len, 8);
175 len += 12;
176 }
177
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300178 if (status->encoding == RX_ENC_HE &&
179 status->flag & RX_FLAG_RADIOTAP_HE) {
180 len = ALIGN(len, 2);
181 len += 12;
182 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
183 }
184
185 if (status->encoding == RX_ENC_HE &&
186 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
187 len = ALIGN(len, 2);
188 len += 12;
189 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
190 }
191
Johannes Berga144f372013-07-03 13:34:02 +0200192 if (status->chains) {
193 /* antenna and antenna signal fields */
194 len += 2 * hweight8(status->chains);
195 }
196
Johannes Berg1f7bba72014-11-06 22:56:36 +0100197 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
198 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
199
200 /* vendor presence bitmap */
201 len += 4;
202 /* alignment for fixed 6-byte vendor data header */
203 len = ALIGN(len, 2);
204 /* vendor data header */
205 len += 6;
206 if (WARN_ON(rtap->align == 0))
207 rtap->align = 1;
208 len = ALIGN(len, rtap->align);
209 len += rtap->len + rtap->pad;
210 }
211
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200212 return len;
213}
214
Johannes Berg9e478062017-04-13 14:23:49 +0200215static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
216 struct sk_buff *skb,
Johannes Bergc096b922018-04-20 13:49:18 +0300217 int rtap_space)
Johannes Berg9e478062017-04-13 14:23:49 +0200218{
219 struct {
220 struct ieee80211_hdr_3addr hdr;
221 u8 category;
222 u8 action_code;
223 } __packed action;
224
225 if (!sdata)
226 return;
227
228 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
229
Johannes Bergc096b922018-04-20 13:49:18 +0300230 if (skb->len < rtap_space + sizeof(action) +
Johannes Berg9e478062017-04-13 14:23:49 +0200231 VHT_MUMIMO_GROUPS_DATA_LEN)
232 return;
233
234 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
235 return;
236
Johannes Bergc096b922018-04-20 13:49:18 +0300237 skb_copy_bits(skb, rtap_space, &action, sizeof(action));
Johannes Berg9e478062017-04-13 14:23:49 +0200238
239 if (!ieee80211_is_action(action.hdr.frame_control))
240 return;
241
242 if (action.category != WLAN_CATEGORY_VHT)
243 return;
244
245 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
246 return;
247
248 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
249 return;
250
251 skb = skb_copy(skb, GFP_ATOMIC);
252 if (!skb)
253 return;
254
Johannes Berg9e478062017-04-13 14:23:49 +0200255 skb_queue_tail(&sdata->skb_queue, skb);
256 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
257}
258
Johannes Berg00ea6de2012-09-05 15:54:51 +0200259/*
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200260 * ieee80211_add_rx_radiotap_header - add radiotap header
261 *
262 * add a radiotap header containing all the fields which the hardware provided.
263 */
264static void
265ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
266 struct sk_buff *skb,
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200267 struct ieee80211_rate *rate,
Felix Fietkau973ef212012-04-16 14:56:48 +0200268 int rtap_len, bool has_fcs)
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200269{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200270 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200271 struct ieee80211_radiotap_header *rthdr;
272 unsigned char *pos;
Johannes Berga144f372013-07-03 13:34:02 +0200273 __le32 *it_present;
274 u32 it_present_val;
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100275 u16 rx_flags = 0;
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200276 u16 channel_flags = 0;
Johannes Berga144f372013-07-03 13:34:02 +0200277 int mpdulen, chain;
278 unsigned long chains = status->chains;
Johannes Berg1f7bba72014-11-06 22:56:36 +0100279 struct ieee80211_vendor_radiotap rtap = {};
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300280 struct ieee80211_radiotap_he he = {};
281 struct ieee80211_radiotap_he_mu he_mu = {};
282
283 if (status->flag & RX_FLAG_RADIOTAP_HE) {
284 he = *(struct ieee80211_radiotap_he *)skb->data;
285 skb_pull(skb, sizeof(he));
286 WARN_ON_ONCE(status->encoding != RX_ENC_HE);
287 }
288
289 if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
290 he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
291 skb_pull(skb, sizeof(he_mu));
292 }
Johannes Berg1f7bba72014-11-06 22:56:36 +0100293
294 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
295 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
296 /* rtap.len and rtap.pad are undone immediately */
297 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
298 }
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800299
300 mpdulen = skb->len;
Johannes Berg30686bf2015-06-02 21:39:54 +0200301 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800302 mpdulen += FCS_LEN;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200303
Johannes Bergd58ff352017-06-16 14:29:23 +0200304 rthdr = skb_push(skb, rtap_len);
Johannes Berg1f7bba72014-11-06 22:56:36 +0100305 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
Johannes Berga144f372013-07-03 13:34:02 +0200306 it_present = &rthdr->it_present;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200307
308 /* radiotap header, set always present flags */
Emmanuel Grumbach0059b2b2014-02-05 16:36:01 +0200309 rthdr->it_len = cpu_to_le16(rtap_len);
Johannes Berga144f372013-07-03 13:34:02 +0200310 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
311 BIT(IEEE80211_RADIOTAP_CHANNEL) |
312 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200313
Johannes Berga144f372013-07-03 13:34:02 +0200314 if (!status->chains)
315 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
316
317 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
318 it_present_val |=
319 BIT(IEEE80211_RADIOTAP_EXT) |
320 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
321 put_unaligned_le32(it_present_val, it_present);
322 it_present++;
323 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
324 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
325 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200326
Johannes Berg1f7bba72014-11-06 22:56:36 +0100327 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
328 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
329 BIT(IEEE80211_RADIOTAP_EXT);
330 put_unaligned_le32(it_present_val, it_present);
331 it_present++;
332 it_present_val = rtap.present;
333 }
334
Johannes Berga144f372013-07-03 13:34:02 +0200335 put_unaligned_le32(it_present_val, it_present);
336
337 pos = (void *)(it_present + 1);
338
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200339 /* the order of the following fields is important */
340
341 /* IEEE80211_RADIOTAP_TSFT */
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800342 if (ieee80211_have_rx_timestamp(status)) {
Johannes Berg90b9e4462012-11-16 10:09:08 +0100343 /* padding */
344 while ((pos - (u8 *)rthdr) & 7)
345 *pos++ = 0;
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800346 put_unaligned_le64(
347 ieee80211_calculate_rx_timestamp(local, status,
348 mpdulen, 0),
349 pos);
Johannes Berg1df332e2012-10-26 00:09:11 +0200350 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200351 pos += 8;
352 }
353
354 /* IEEE80211_RADIOTAP_FLAGS */
Johannes Berg30686bf2015-06-02 21:39:54 +0200355 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200356 *pos |= IEEE80211_RADIOTAP_F_FCS;
Johannes Bergaae89832009-03-13 12:52:10 +0100357 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
358 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200359 if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
Bruno Randolfb4f28bb2008-07-30 17:19:55 +0200360 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200361 pos++;
362
363 /* IEEE80211_RADIOTAP_RATE */
Johannes Bergda6a4352017-04-26 12:14:59 +0200364 if (!rate || status->encoding != RX_ENC_LEGACY) {
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200365 /*
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100366 * Without rate information don't add it. If we have,
Mohammed Shafi Shajakhan38f37be2011-02-07 10:10:04 +0530367 * MCS information is a separate field in radiotap,
Johannes Berg73b48092011-04-18 17:05:21 +0200368 * added below. The byte here is needed as padding
369 * for the channel though, so initialise it to 0.
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200370 */
371 *pos = 0;
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200372 } else {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200373 int shift = 0;
Jouni Malinenebe6c7b2009-01-10 11:47:33 +0200374 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
Johannes Bergda6a4352017-04-26 12:14:59 +0200375 if (status->bw == RATE_INFO_BW_10)
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200376 shift = 1;
Johannes Bergda6a4352017-04-26 12:14:59 +0200377 else if (status->bw == RATE_INFO_BW_5)
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200378 shift = 2;
379 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200380 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200381 pos++;
382
383 /* IEEE80211_RADIOTAP_CHANNEL */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100384 put_unaligned_le16(status->freq, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200385 pos += 2;
Johannes Bergda6a4352017-04-26 12:14:59 +0200386 if (status->bw == RATE_INFO_BW_10)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200387 channel_flags |= IEEE80211_CHAN_HALF;
Johannes Bergda6a4352017-04-26 12:14:59 +0200388 else if (status->bw == RATE_INFO_BW_5)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200389 channel_flags |= IEEE80211_CHAN_QUARTER;
390
Johannes Berg57fbcce2016-04-12 15:56:15 +0200391 if (status->band == NL80211_BAND_5GHZ)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200392 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
Johannes Bergda6a4352017-04-26 12:14:59 +0200393 else if (status->encoding != RX_ENC_LEGACY)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200394 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100395 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200396 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100397 else if (rate)
Mathy Vanhoef3a5c5e82015-01-20 15:05:08 +0100398 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100399 else
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200400 channel_flags |= IEEE80211_CHAN_2GHZ;
401 put_unaligned_le16(channel_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200402 pos += 2;
403
404 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
Johannes Berg30686bf2015-06-02 21:39:54 +0200405 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
Felix Fietkaufe8431f2012-03-01 18:00:07 +0100406 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200407 *pos = status->signal;
408 rthdr->it_present |=
409 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
410 pos++;
411 }
412
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200413 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
414
Johannes Berga144f372013-07-03 13:34:02 +0200415 if (!status->chains) {
416 /* IEEE80211_RADIOTAP_ANTENNA */
417 *pos = status->antenna;
418 pos++;
419 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200420
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200421 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
422
423 /* IEEE80211_RADIOTAP_RX_FLAGS */
424 /* ensure 2 byte alignment for the 2 byte field as required */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100425 if ((pos - (u8 *)rthdr) & 1)
Johannes Berg90b9e4462012-11-16 10:09:08 +0100426 *pos++ = 0;
Johannes Bergaae89832009-03-13 12:52:10 +0100427 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100428 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
429 put_unaligned_le16(rx_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200430 pos += 2;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100431
Johannes Bergda6a4352017-04-26 12:14:59 +0200432 if (status->encoding == RX_ENC_HT) {
Oleksij Rempel786677d2013-05-24 12:05:45 +0200433 unsigned int stbc;
434
Johannes Berg6d744ba2011-01-27 14:13:17 +0100435 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
Johannes Bergac55d2f2012-05-10 09:09:10 +0200436 *pos++ = local->hw.radiotap_mcs_details;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100437 *pos = 0;
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200438 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
Johannes Berg6d744ba2011-01-27 14:13:17 +0100439 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
Johannes Bergda6a4352017-04-26 12:14:59 +0200440 if (status->bw == RATE_INFO_BW_40)
Johannes Berg6d744ba2011-01-27 14:13:17 +0100441 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200442 if (status->enc_flags & RX_ENC_FLAG_HT_GF)
Johannes Bergac55d2f2012-05-10 09:09:10 +0200443 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200444 if (status->enc_flags & RX_ENC_FLAG_LDPC)
Emmanuel Grumbach63c361f2014-02-05 12:48:53 +0200445 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200446 stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
Oleksij Rempel786677d2013-05-24 12:05:45 +0200447 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100448 pos++;
449 *pos++ = status->rate_idx;
450 }
Johannes Berg4c298672012-07-05 11:34:31 +0200451
452 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
453 u16 flags = 0;
454
455 /* ensure 4 byte alignment */
456 while ((pos - (u8 *)rthdr) & 3)
457 pos++;
458 rthdr->it_present |=
459 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
460 put_unaligned_le32(status->ampdu_reference, pos);
461 pos += 4;
Johannes Berg4c298672012-07-05 11:34:31 +0200462 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
463 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
464 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
465 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
466 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
467 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
468 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
469 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
Johannes Berg7299d6f2018-02-19 14:48:39 +0200470 if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
471 flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
472 if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
473 flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
Johannes Berg4c298672012-07-05 11:34:31 +0200474 put_unaligned_le16(flags, pos);
475 pos += 2;
476 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
477 *pos++ = status->ampdu_delimiter_crc;
478 else
479 *pos++ = 0;
480 *pos++ = 0;
481 }
Johannes Berg90b9e4462012-11-16 10:09:08 +0100482
Johannes Bergda6a4352017-04-26 12:14:59 +0200483 if (status->encoding == RX_ENC_VHT) {
Johannes Berg51648922012-11-22 23:00:18 +0100484 u16 known = local->hw.radiotap_vht_details;
485
486 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
Johannes Berg51648922012-11-22 23:00:18 +0100487 put_unaligned_le16(known, pos);
488 pos += 2;
489 /* flags */
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200490 if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
Johannes Berg51648922012-11-22 23:00:18 +0100491 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
Emmanuel Grumbach63c361f2014-02-05 12:48:53 +0200492 /* in VHT, STBC is binary */
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200493 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
Emmanuel Grumbach63c361f2014-02-05 12:48:53 +0200494 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200495 if (status->enc_flags & RX_ENC_FLAG_BF)
Emmanuel Grumbachfb378c22014-03-04 10:35:25 +0200496 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
Johannes Berg51648922012-11-22 23:00:18 +0100497 pos++;
498 /* bandwidth */
Johannes Bergda6a4352017-04-26 12:14:59 +0200499 switch (status->bw) {
500 case RATE_INFO_BW_80:
Johannes Berg51648922012-11-22 23:00:18 +0100501 *pos++ = 4;
Johannes Bergda6a4352017-04-26 12:14:59 +0200502 break;
503 case RATE_INFO_BW_160:
Johannes Berg51648922012-11-22 23:00:18 +0100504 *pos++ = 11;
Johannes Bergda6a4352017-04-26 12:14:59 +0200505 break;
506 case RATE_INFO_BW_40:
Johannes Berg51648922012-11-22 23:00:18 +0100507 *pos++ = 1;
Johannes Bergda6a4352017-04-26 12:14:59 +0200508 break;
509 default:
Johannes Berg51648922012-11-22 23:00:18 +0100510 *pos++ = 0;
Johannes Bergda6a4352017-04-26 12:14:59 +0200511 }
Johannes Berg51648922012-11-22 23:00:18 +0100512 /* MCS/NSS */
Johannes Berg8613c942017-04-26 13:51:41 +0200513 *pos = (status->rate_idx << 4) | status->nss;
Johannes Berg51648922012-11-22 23:00:18 +0100514 pos += 4;
515 /* coding field */
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200516 if (status->enc_flags & RX_ENC_FLAG_LDPC)
Emmanuel Grumbach63c361f2014-02-05 12:48:53 +0200517 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
Johannes Berg51648922012-11-22 23:00:18 +0100518 pos++;
519 /* group ID */
520 pos++;
521 /* partial_aid */
522 pos += 2;
523 }
524
Johannes Berg99ee7ca2016-08-29 23:25:17 +0300525 if (local->hw.radiotap_timestamp.units_pos >= 0) {
526 u16 accuracy = 0;
527 u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
528
529 rthdr->it_present |=
530 cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP);
531
532 /* ensure 8 byte alignment */
533 while ((pos - (u8 *)rthdr) & 7)
534 pos++;
535
536 put_unaligned_le64(status->device_timestamp, pos);
537 pos += sizeof(u64);
538
539 if (local->hw.radiotap_timestamp.accuracy >= 0) {
540 accuracy = local->hw.radiotap_timestamp.accuracy;
541 flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
542 }
543 put_unaligned_le16(accuracy, pos);
544 pos += sizeof(u16);
545
546 *pos++ = local->hw.radiotap_timestamp.units_pos;
547 *pos++ = flags;
548 }
549
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300550 if (status->encoding == RX_ENC_HE &&
551 status->flag & RX_FLAG_RADIOTAP_HE) {
552#define HE_PREP(f, val) cpu_to_le16(FIELD_PREP(IEEE80211_RADIOTAP_HE_##f, val))
553
554 if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
555 he.data6 |= HE_PREP(DATA6_NSTS,
556 FIELD_GET(RX_ENC_FLAG_STBC_MASK,
557 status->enc_flags));
558 he.data3 |= HE_PREP(DATA3_STBC, 1);
559 } else {
560 he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
561 }
562
563#define CHECK_GI(s) \
564 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
565 (int)NL80211_RATE_INFO_HE_GI_##s)
566
567 CHECK_GI(0_8);
568 CHECK_GI(1_6);
569 CHECK_GI(3_2);
570
571 he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
572 he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
573 he.data3 |= HE_PREP(DATA3_CODING,
574 !!(status->enc_flags & RX_ENC_FLAG_LDPC));
575
576 he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
577
578 switch (status->bw) {
579 case RATE_INFO_BW_20:
580 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
581 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
582 break;
583 case RATE_INFO_BW_40:
584 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
585 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
586 break;
587 case RATE_INFO_BW_80:
588 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
589 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
590 break;
591 case RATE_INFO_BW_160:
592 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
593 IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
594 break;
595 case RATE_INFO_BW_HE_RU:
596#define CHECK_RU_ALLOC(s) \
597 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
598 NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
599
600 CHECK_RU_ALLOC(26);
601 CHECK_RU_ALLOC(52);
602 CHECK_RU_ALLOC(106);
603 CHECK_RU_ALLOC(242);
604 CHECK_RU_ALLOC(484);
605 CHECK_RU_ALLOC(996);
606 CHECK_RU_ALLOC(2x996);
607
608 he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
609 status->he_ru + 4);
610 break;
611 default:
612 WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
613 }
614
615 /* ensure 2 byte alignment */
616 while ((pos - (u8 *)rthdr) & 1)
617 pos++;
618 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE);
619 memcpy(pos, &he, sizeof(he));
620 pos += sizeof(he);
621 }
622
623 if (status->encoding == RX_ENC_HE &&
624 status->flag & RX_FLAG_RADIOTAP_HE_MU) {
625 /* ensure 2 byte alignment */
626 while ((pos - (u8 *)rthdr) & 1)
627 pos++;
628 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU);
629 memcpy(pos, &he_mu, sizeof(he_mu));
630 pos += sizeof(he_mu);
631 }
632
Johannes Berga144f372013-07-03 13:34:02 +0200633 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
634 *pos++ = status->chain_signal[chain];
635 *pos++ = chain;
636 }
Johannes Berg1f7bba72014-11-06 22:56:36 +0100637
638 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
639 /* ensure 2 byte alignment for the vendor field as required */
640 if ((pos - (u8 *)rthdr) & 1)
641 *pos++ = 0;
642 *pos++ = rtap.oui[0];
643 *pos++ = rtap.oui[1];
644 *pos++ = rtap.oui[2];
645 *pos++ = rtap.subns;
646 put_unaligned_le16(rtap.len, pos);
647 pos += 2;
648 /* align the actual payload as requested */
649 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
650 *pos++ = 0;
651 /* data (and possible padding) already follows */
652 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200653}
654
Johannes Berg127f60b2017-04-13 15:50:27 +0200655static struct sk_buff *
656ieee80211_make_monitor_skb(struct ieee80211_local *local,
657 struct sk_buff **origskb,
658 struct ieee80211_rate *rate,
Johannes Bergc096b922018-04-20 13:49:18 +0300659 int rtap_space, bool use_origskb)
Johannes Berg127f60b2017-04-13 15:50:27 +0200660{
661 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
662 int rt_hdrlen, needed_headroom;
663 struct sk_buff *skb;
664
665 /* room for the radiotap header based on driver features */
666 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
Johannes Bergc096b922018-04-20 13:49:18 +0300667 needed_headroom = rt_hdrlen - rtap_space;
Johannes Berg127f60b2017-04-13 15:50:27 +0200668
669 if (use_origskb) {
670 /* only need to expand headroom if necessary */
671 skb = *origskb;
672 *origskb = NULL;
673
674 /*
675 * This shouldn't trigger often because most devices have an
676 * RX header they pull before we get here, and that should
677 * be big enough for our radiotap information. We should
678 * probably export the length to drivers so that we can have
679 * them allocate enough headroom to start with.
680 */
681 if (skb_headroom(skb) < needed_headroom &&
682 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
683 dev_kfree_skb(skb);
684 return NULL;
685 }
686 } else {
687 /*
688 * Need to make a copy and possibly remove radiotap header
689 * and FCS from the original.
690 */
691 skb = skb_copy_expand(*origskb, needed_headroom, 0, GFP_ATOMIC);
692
693 if (!skb)
694 return NULL;
695 }
696
697 /* prepend radiotap information */
698 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
699
700 skb_reset_mac_header(skb);
701 skb->ip_summed = CHECKSUM_UNNECESSARY;
702 skb->pkt_type = PACKET_OTHERHOST;
703 skb->protocol = htons(ETH_P_802_2);
704
705 return skb;
706}
707
Johannes Bergb2e77712007-09-26 15:19:39 +0200708/*
709 * This function copies a received frame to all monitor interfaces and
710 * returns a cleaned-up SKB that no longer includes the FCS nor the
711 * radiotap header the driver might have added.
712 */
713static struct sk_buff *
714ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
Johannes Berg8318d782008-01-24 19:38:38 +0100715 struct ieee80211_rate *rate)
Johannes Bergb2e77712007-09-26 15:19:39 +0200716{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200717 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200718 struct ieee80211_sub_if_data *sdata;
Johannes Berg127f60b2017-04-13 15:50:27 +0200719 struct sk_buff *monskb = NULL;
Johannes Bergb2e77712007-09-26 15:19:39 +0200720 int present_fcs_len = 0;
Johannes Bergc096b922018-04-20 13:49:18 +0300721 unsigned int rtap_space = 0;
Aviya Erenfeld42bd20d2016-08-29 23:25:16 +0300722 struct ieee80211_sub_if_data *monitor_sdata =
723 rcu_dereference(local->monitor_sdata);
Johannes Berg127f60b2017-04-13 15:50:27 +0200724 bool only_monitor = false;
Johannes Berg1f7bba72014-11-06 22:56:36 +0100725
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300726 if (status->flag & RX_FLAG_RADIOTAP_HE)
727 rtap_space += sizeof(struct ieee80211_radiotap_he);
728
729 if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
730 rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
731
Johannes Berg1f7bba72014-11-06 22:56:36 +0100732 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
733 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
734
Johannes Bergc096b922018-04-20 13:49:18 +0300735 rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
Johannes Berg1f7bba72014-11-06 22:56:36 +0100736 }
Johannes Bergb2e77712007-09-26 15:19:39 +0200737
738 /*
739 * First, we may need to make a copy of the skb because
740 * (1) we need to modify it for radiotap (if not present), and
741 * (2) the other RX handlers will modify the skb we got.
742 *
743 * We don't need to, of course, if we aren't going to return
744 * the SKB because it has a bad FCS/PLCP checksum.
745 */
Johannes Berg0869aea2009-10-28 10:03:35 +0100746
Johannes Berg30841f52017-04-11 15:38:56 +0200747 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
748 if (unlikely(origskb->len <= FCS_LEN)) {
749 /* driver bug */
750 WARN_ON(1);
751 dev_kfree_skb(origskb);
752 return NULL;
753 }
Johannes Bergb2e77712007-09-26 15:19:39 +0200754 present_fcs_len = FCS_LEN;
Johannes Berg30841f52017-04-11 15:38:56 +0200755 }
Johannes Bergb2e77712007-09-26 15:19:39 +0200756
Johannes Berg1f7bba72014-11-06 22:56:36 +0100757 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
Johannes Bergc096b922018-04-20 13:49:18 +0300758 if (!pskb_may_pull(origskb, 2 + rtap_space)) {
Zhu Yie3cf8b32010-03-29 17:35:07 +0800759 dev_kfree_skb(origskb);
760 return NULL;
761 }
762
Johannes Bergc096b922018-04-20 13:49:18 +0300763 only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
Johannes Berg127f60b2017-04-13 15:50:27 +0200764
Grzegorz Bajorski17883042015-12-11 14:39:46 +0100765 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
Johannes Berg127f60b2017-04-13 15:50:27 +0200766 if (only_monitor) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200767 dev_kfree_skb(origskb);
768 return NULL;
769 }
770
Johannes Bergc096b922018-04-20 13:49:18 +0300771 remove_monitor_info(origskb, present_fcs_len, rtap_space);
Johannes Berg30841f52017-04-11 15:38:56 +0200772 return origskb;
Johannes Bergb2e77712007-09-26 15:19:39 +0200773 }
774
Johannes Bergc096b922018-04-20 13:49:18 +0300775 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
Johannes Berg9e478062017-04-13 14:23:49 +0200776
Johannes Bergf64331d2017-04-13 13:28:18 +0200777 list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
Johannes Berg127f60b2017-04-13 15:50:27 +0200778 bool last_monitor = list_is_last(&sdata->u.mntr.list,
779 &local->mon_list);
780
781 if (!monskb)
782 monskb = ieee80211_make_monitor_skb(local, &origskb,
Johannes Bergc096b922018-04-20 13:49:18 +0300783 rate, rtap_space,
Johannes Berg127f60b2017-04-13 15:50:27 +0200784 only_monitor &&
785 last_monitor);
786
787 if (monskb) {
788 struct sk_buff *skb;
789
790 if (last_monitor) {
791 skb = monskb;
792 monskb = NULL;
793 } else {
794 skb = skb_clone(monskb, GFP_ATOMIC);
795 }
796
797 if (skb) {
798 skb->dev = sdata->dev;
799 ieee80211_rx_stats(skb->dev, skb->len);
800 netif_receive_skb(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200801 }
802 }
803
Johannes Berg127f60b2017-04-13 15:50:27 +0200804 if (last_monitor)
805 break;
Johannes Bergb2e77712007-09-26 15:19:39 +0200806 }
807
Johannes Berg127f60b2017-04-13 15:50:27 +0200808 /* this happens if last_monitor was erroneously false */
809 dev_kfree_skb(monskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200810
Johannes Berg127f60b2017-04-13 15:50:27 +0200811 /* ditto */
812 if (!origskb)
813 return NULL;
814
Johannes Bergc096b922018-04-20 13:49:18 +0300815 remove_monitor_info(origskb, present_fcs_len, rtap_space);
Johannes Bergb2e77712007-09-26 15:19:39 +0200816 return origskb;
817}
818
Johannes Berg5cf121c2008-02-25 16:27:43 +0100819static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +0200820{
Harvey Harrison238f74a2008-07-02 11:05:34 -0700821 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200822 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg9e262972011-07-07 18:45:03 +0200823 int tid, seqno_idx, security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200824
825 /* does the frame have a qos control field? */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700826 if (ieee80211_is_data_qos(hdr->frame_control)) {
827 u8 *qc = ieee80211_get_qos_ctl(hdr);
Johannes Berg6e0d1142007-07-27 15:43:22 +0200828 /* frame has qos control */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700829 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
Johannes Berg04b7dcf2011-06-22 10:06:59 +0200830 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
Johannes Berg554891e2010-09-24 12:38:25 +0200831 status->rx_flags |= IEEE80211_RX_AMSDU;
Johannes Berg9e262972011-07-07 18:45:03 +0200832
833 seqno_idx = tid;
834 security_idx = tid;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200835 } else {
Johannes Berg1411f9b2008-07-10 10:11:02 +0200836 /*
837 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
838 *
839 * Sequence numbers for management frames, QoS data
840 * frames with a broadcast/multicast address in the
841 * Address 1 field, and all non-QoS data frames sent
842 * by QoS STAs are assigned using an additional single
843 * modulo-4096 counter, [...]
844 *
845 * We also use that counter for non-QoS STAs.
846 */
Johannes Berg5a306f52012-11-14 23:22:21 +0100847 seqno_idx = IEEE80211_NUM_TIDS;
Johannes Berg9e262972011-07-07 18:45:03 +0200848 security_idx = 0;
849 if (ieee80211_is_mgmt(hdr->frame_control))
Johannes Berg5a306f52012-11-14 23:22:21 +0100850 security_idx = IEEE80211_NUM_TIDS;
Johannes Berg9e262972011-07-07 18:45:03 +0200851 tid = 0;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200852 }
Johannes Berg52865dfd2007-07-27 15:43:22 +0200853
Johannes Berg9e262972011-07-07 18:45:03 +0200854 rx->seqno_idx = seqno_idx;
855 rx->security_idx = security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200856 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
857 * For now, set skb->priority to 0 for other cases. */
858 rx->skb->priority = (tid > 7) ? 0 : tid;
Johannes Berg38f37142008-01-29 17:07:43 +0100859}
Johannes Berg6e0d1142007-07-27 15:43:22 +0200860
Johannes Bergd1c3a372009-01-07 00:26:10 +0100861/**
862 * DOC: Packet alignment
863 *
864 * Drivers always need to pass packets that are aligned to two-byte boundaries
865 * to the stack.
866 *
867 * Additionally, should, if possible, align the payload data in a way that
868 * guarantees that the contained IP header is aligned to a four-byte
869 * boundary. In the case of regular frames, this simply means aligning the
870 * payload to a four-byte boundary (because either the IP header is directly
871 * contained, or IV/RFC1042 headers that have a length divisible by four are
Kalle Valo59d9cb02009-12-17 13:54:57 +0100872 * in front of it). If the payload data is not properly aligned and the
873 * architecture doesn't support efficient unaligned operations, mac80211
874 * will align the data.
Johannes Bergd1c3a372009-01-07 00:26:10 +0100875 *
876 * With A-MSDU frames, however, the payload data address must yield two modulo
877 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
878 * push the IP header further back to a multiple of four again. Thankfully, the
879 * specs were sane enough this time around to require padding each A-MSDU
880 * subframe to a length that is a multiple of four.
881 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300882 * Padding like Atheros hardware adds which is between the 802.11 header and
Johannes Bergd1c3a372009-01-07 00:26:10 +0100883 * the payload is not supported, the driver is required to move the 802.11
884 * header to be directly in front of the payload in that case.
885 */
886static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
Johannes Berg38f37142008-01-29 17:07:43 +0100887{
Kalle Valo59d9cb02009-12-17 13:54:57 +0100888#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg441275e2015-11-06 12:34:24 +0100889 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
Johannes Bergd1c3a372009-01-07 00:26:10 +0100890#endif
Johannes Berg6e0d1142007-07-27 15:43:22 +0200891}
892
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +0200893
Johannes Berg571ecf62007-07-27 15:43:22 +0200894/* rx handlers */
895
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200896static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
897{
898 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
899
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100900 if (is_multicast_ether_addr(hdr->addr1))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200901 return 0;
902
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100903 return ieee80211_is_robust_mgmt_frame(skb);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200904}
905
906
907static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
908{
909 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
910
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100911 if (!is_multicast_ether_addr(hdr->addr1))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200912 return 0;
913
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100914 return ieee80211_is_robust_mgmt_frame(skb);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200915}
916
917
918/* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
919static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
920{
921 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
922 struct ieee80211_mmie *mmie;
Jouni Malinen56c52da2015-01-24 19:52:08 +0200923 struct ieee80211_mmie_16 *mmie16;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200924
Johannes Berg1df332e2012-10-26 00:09:11 +0200925 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200926 return -1;
927
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100928 if (!ieee80211_is_robust_mgmt_frame(skb))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200929 return -1; /* not a robust management frame */
930
931 mmie = (struct ieee80211_mmie *)
932 (skb->data + skb->len - sizeof(*mmie));
Jouni Malinen56c52da2015-01-24 19:52:08 +0200933 if (mmie->element_id == WLAN_EID_MMIE &&
934 mmie->length == sizeof(*mmie) - 2)
935 return le16_to_cpu(mmie->key_id);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200936
Jouni Malinen56c52da2015-01-24 19:52:08 +0200937 mmie16 = (struct ieee80211_mmie_16 *)
938 (skb->data + skb->len - sizeof(*mmie16));
939 if (skb->len >= 24 + sizeof(*mmie16) &&
940 mmie16->element_id == WLAN_EID_MMIE &&
941 mmie16->length == sizeof(*mmie16) - 2)
942 return le16_to_cpu(mmie16->key_id);
943
944 return -1;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200945}
946
Johannes Berg2c61cf92016-03-17 15:02:55 +0200947static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
948 struct sk_buff *skb)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200949{
950 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
951 __le16 fc;
952 int hdrlen;
953 u8 keyid;
954
955 fc = hdr->frame_control;
956 hdrlen = ieee80211_hdrlen(fc);
957
958 if (skb->len < hdrlen + cs->hdr_len)
959 return -EINVAL;
960
961 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
962 keyid &= cs->key_idx_mask;
963 keyid >>= cs->key_idx_shift;
964
965 return keyid;
966}
967
Johannes Berg1df332e2012-10-26 00:09:11 +0200968static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100969{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700970 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg47846c92009-11-25 17:46:19 +0100971 char *dev_addr = rx->sdata->vif.addr;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100972
Harvey Harrisona7767f92008-07-02 16:30:51 -0700973 if (ieee80211_is_data(hdr->frame_control)) {
Javier Cardona3c5772a2009-08-10 12:15:48 -0700974 if (is_multicast_ether_addr(hdr->addr1)) {
975 if (ieee80211_has_tods(hdr->frame_control) ||
Johannes Berg1df332e2012-10-26 00:09:11 +0200976 !ieee80211_has_fromds(hdr->frame_control))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700977 return RX_DROP_MONITOR;
Joe Perchesb203ca32012-05-08 18:56:52 +0000978 if (ether_addr_equal(hdr->addr3, dev_addr))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700979 return RX_DROP_MONITOR;
980 } else {
981 if (!ieee80211_has_a4(hdr->frame_control))
982 return RX_DROP_MONITOR;
Joe Perchesb203ca32012-05-08 18:56:52 +0000983 if (ether_addr_equal(hdr->addr4, dev_addr))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700984 return RX_DROP_MONITOR;
985 }
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100986 }
987
988 /* If there is not an established peer link and this is not a peer link
989 * establisment frame, beacon or probe, drop the frame.
990 */
991
Javier Cardona57cf8042011-05-13 10:45:43 -0700992 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100993 struct ieee80211_mgmt *mgmt;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100994
Harvey Harrisona7767f92008-07-02 16:30:51 -0700995 if (!ieee80211_is_mgmt(hdr->frame_control))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100996 return RX_DROP_MONITOR;
997
Harvey Harrisona7767f92008-07-02 16:30:51 -0700998 if (ieee80211_is_action(hdr->frame_control)) {
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700999 u8 category;
Johannes Berg9b395bc2012-10-26 00:36:40 +02001000
1001 /* make sure category field is present */
1002 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1003 return RX_DROP_MONITOR;
1004
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001005 mgmt = (struct ieee80211_mgmt *)hdr;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -07001006 category = mgmt->u.action.category;
1007 if (category != WLAN_CATEGORY_MESH_ACTION &&
Johannes Berg1df332e2012-10-26 00:09:11 +02001008 category != WLAN_CATEGORY_SELF_PROTECTED)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001009 return RX_DROP_MONITOR;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001010 return RX_CONTINUE;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001011 }
1012
Harvey Harrisona7767f92008-07-02 16:30:51 -07001013 if (ieee80211_is_probe_req(hdr->frame_control) ||
1014 ieee80211_is_probe_resp(hdr->frame_control) ||
Javier Cardona71839122011-04-07 15:08:31 -07001015 ieee80211_is_beacon(hdr->frame_control) ||
1016 ieee80211_is_auth(hdr->frame_control))
Harvey Harrisona7767f92008-07-02 16:30:51 -07001017 return RX_CONTINUE;
1018
1019 return RX_DROP_MONITOR;
Harvey Harrisona7767f92008-07-02 16:30:51 -07001020 }
1021
Johannes Berg902acc72008-02-23 15:17:19 +01001022 return RX_CONTINUE;
1023}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001024
Johannes Bergfb4ea052016-01-28 16:19:24 +02001025static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1026 int index)
1027{
1028 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1029 struct sk_buff *tail = skb_peek_tail(frames);
1030 struct ieee80211_rx_status *status;
1031
Sara Sharon06470f72016-01-28 16:19:25 +02001032 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1033 return true;
1034
Johannes Bergfb4ea052016-01-28 16:19:24 +02001035 if (!tail)
1036 return false;
1037
1038 status = IEEE80211_SKB_RXCB(tail);
1039 if (status->flag & RX_FLAG_AMSDU_MORE)
1040 return false;
1041
1042 return true;
1043}
1044
Johannes Bergd3b2fb52012-06-22 12:48:38 +02001045static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001046 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001047 int index,
1048 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001049{
Michal Kazior83eb9352014-07-16 12:09:31 +02001050 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1051 struct sk_buff *skb;
Christian Lamparter4cfda472010-12-27 23:21:26 +01001052 struct ieee80211_rx_status *status;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001053
Johannes Bergdd318572010-11-29 11:09:16 +01001054 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1055
Michal Kazior83eb9352014-07-16 12:09:31 +02001056 if (skb_queue_empty(skb_list))
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001057 goto no_frame;
1058
Johannes Bergfb4ea052016-01-28 16:19:24 +02001059 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
Michal Kazior83eb9352014-07-16 12:09:31 +02001060 __skb_queue_purge(skb_list);
1061 goto no_frame;
1062 }
1063
1064 /* release frames from the reorder ring buffer */
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001065 tid_agg_rx->stored_mpdu_num--;
Michal Kazior83eb9352014-07-16 12:09:31 +02001066 while ((skb = __skb_dequeue(skb_list))) {
1067 status = IEEE80211_SKB_RXCB(skb);
1068 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1069 __skb_queue_tail(frames, skb);
1070 }
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001071
1072no_frame:
Sara Sharon06470f72016-01-28 16:19:25 +02001073 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
Johannes Berg9a886582013-02-15 19:25:00 +01001074 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001075}
1076
Johannes Bergd3b2fb52012-06-22 12:48:38 +02001077static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001078 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001079 u16 head_seq_num,
1080 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001081{
1082 int index;
1083
Johannes Bergdd318572010-11-29 11:09:16 +01001084 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1085
Johannes Berg9a886582013-02-15 19:25:00 +01001086 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
Karl Beldan2e3049b2013-10-24 15:53:32 +02001087 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001088 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1089 frames);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001090 }
1091}
1092
1093/*
1094 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1095 * the skb was added to the buffer longer than this time ago, the earlier
1096 * frames that have not yet been received are assumed to be lost and the skb
1097 * can be released for processing. This may also release other skb's from the
1098 * reorder buffer if there are no additional gaps between the frames.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001099 *
1100 * Callers must hold tid_agg_rx->reorder_lock.
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001101 */
1102#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1103
Johannes Bergd3b2fb52012-06-22 12:48:38 +02001104static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001105 struct tid_ampdu_rx *tid_agg_rx,
1106 struct sk_buff_head *frames)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001107{
Michal Kazior83eb9352014-07-16 12:09:31 +02001108 int index, i, j;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001109
Johannes Bergdd318572010-11-29 11:09:16 +01001110 lockdep_assert_held(&tid_agg_rx->reorder_lock);
1111
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001112 /* release the buffer until next missing frame */
Karl Beldan2e3049b2013-10-24 15:53:32 +02001113 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Johannes Bergfb4ea052016-01-28 16:19:24 +02001114 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
Eliad Peller07ae2df2012-02-01 18:48:09 +02001115 tid_agg_rx->stored_mpdu_num) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001116 /*
1117 * No buffers ready to be released, but check whether any
1118 * frames in the reorder buffer have timed out.
1119 */
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001120 int skipped = 1;
1121 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1122 j = (j + 1) % tid_agg_rx->buf_size) {
Johannes Bergfb4ea052016-01-28 16:19:24 +02001123 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001124 skipped++;
1125 continue;
1126 }
Daniel Halperin499fe9a2011-03-24 16:01:48 -07001127 if (skipped &&
1128 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001129 HT_RX_REORDER_BUF_TIMEOUT))
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001130 goto set_release_timer;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001131
Michal Kazior83eb9352014-07-16 12:09:31 +02001132 /* don't leave incomplete A-MSDUs around */
1133 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1134 i = (i + 1) % tid_agg_rx->buf_size)
1135 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1136
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001137 ht_dbg_ratelimited(sdata,
1138 "release an RX reorder frame due to timeout on earlier frames\n");
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001139 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1140 frames);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001141
1142 /*
1143 * Increment the head seq# also for the skipped slots.
1144 */
1145 tid_agg_rx->head_seq_num =
Johannes Berg9a886582013-02-15 19:25:00 +01001146 (tid_agg_rx->head_seq_num +
1147 skipped) & IEEE80211_SN_MASK;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001148 skipped = 0;
1149 }
Johannes Bergfb4ea052016-01-28 16:19:24 +02001150 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001151 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1152 frames);
Karl Beldan2e3049b2013-10-24 15:53:32 +02001153 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001154 }
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001155
1156 if (tid_agg_rx->stored_mpdu_num) {
Karl Beldan2e3049b2013-10-24 15:53:32 +02001157 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001158
1159 for (; j != (index - 1) % tid_agg_rx->buf_size;
1160 j = (j + 1) % tid_agg_rx->buf_size) {
Johannes Bergfb4ea052016-01-28 16:19:24 +02001161 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001162 break;
1163 }
1164
1165 set_release_timer:
1166
Johannes Berg788211d2015-04-01 14:20:42 +02001167 if (!tid_agg_rx->removed)
1168 mod_timer(&tid_agg_rx->reorder_timer,
1169 tid_agg_rx->reorder_time[j] + 1 +
1170 HT_RX_REORDER_BUF_TIMEOUT);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001171 } else {
1172 del_timer(&tid_agg_rx->reorder_timer);
1173 }
Christian Lamparteraa0c8632010-08-05 01:36:04 +02001174}
1175
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001176/*
1177 * As this function belongs to the RX path it must be under
1178 * rcu_read_lock protection. It returns false if the frame
1179 * can be processed immediately, true if it was consumed.
1180 */
Johannes Bergd3b2fb52012-06-22 12:48:38 +02001181static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001182 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001183 struct sk_buff *skb,
1184 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001185{
1186 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Michal Kazior83eb9352014-07-16 12:09:31 +02001187 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001188 u16 sc = le16_to_cpu(hdr->seq_ctrl);
1189 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1190 u16 head_seq_num, buf_size;
1191 int index;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001192 bool ret = true;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001193
Johannes Bergdd318572010-11-29 11:09:16 +01001194 spin_lock(&tid_agg_rx->reorder_lock);
1195
Michal Kazior4549cf22014-09-02 14:05:10 +02001196 /*
1197 * Offloaded BA sessions have no known starting sequence number so pick
1198 * one from first Rxed frame for this tid after BA was started.
1199 */
1200 if (unlikely(tid_agg_rx->auto_seq)) {
1201 tid_agg_rx->auto_seq = false;
1202 tid_agg_rx->ssn = mpdu_seq_num;
1203 tid_agg_rx->head_seq_num = mpdu_seq_num;
1204 }
1205
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001206 buf_size = tid_agg_rx->buf_size;
1207 head_seq_num = tid_agg_rx->head_seq_num;
1208
Sara Sharonb7540d82017-02-06 15:28:42 +02001209 /*
1210 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1211 * be reordered.
1212 */
1213 if (unlikely(!tid_agg_rx->started)) {
1214 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1215 ret = false;
1216 goto out;
1217 }
1218 tid_agg_rx->started = true;
1219 }
1220
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001221 /* frame with out of date sequence number */
Johannes Berg9a886582013-02-15 19:25:00 +01001222 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001223 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001224 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001225 }
1226
1227 /*
1228 * If frame the sequence number exceeds our buffering window
1229 * size release some previous frames to make room for this one.
1230 */
Johannes Berg9a886582013-02-15 19:25:00 +01001231 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1232 head_seq_num = ieee80211_sn_inc(
1233 ieee80211_sn_sub(mpdu_seq_num, buf_size));
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001234 /* release stored frames up to new head to stack */
Johannes Bergd3b2fb52012-06-22 12:48:38 +02001235 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001236 head_seq_num, frames);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001237 }
1238
1239 /* Now the new frame is always in the range of the reordering buffer */
1240
Karl Beldan2e3049b2013-10-24 15:53:32 +02001241 index = mpdu_seq_num % tid_agg_rx->buf_size;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001242
1243 /* check if we already stored this frame */
Johannes Bergfb4ea052016-01-28 16:19:24 +02001244 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001245 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001246 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001247 }
1248
1249 /*
1250 * If the current MPDU is in the right order and nothing else
1251 * is stored we can process it directly, no need to buffer it.
Johannes Bergc835b212011-03-15 23:17:01 +01001252 * If it is first but there's something stored, we may be able
1253 * to release frames after this one.
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001254 */
1255 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1256 tid_agg_rx->stored_mpdu_num == 0) {
Michal Kazior83eb9352014-07-16 12:09:31 +02001257 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1258 tid_agg_rx->head_seq_num =
1259 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001260 ret = false;
1261 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001262 }
1263
1264 /* put the frame in the reordering buffer */
Michal Kazior83eb9352014-07-16 12:09:31 +02001265 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1266 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1267 tid_agg_rx->reorder_time[index] = jiffies;
1268 tid_agg_rx->stored_mpdu_num++;
1269 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1270 }
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001271
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001272 out:
1273 spin_unlock(&tid_agg_rx->reorder_lock);
1274 return ret;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001275}
1276
1277/*
1278 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1279 * true if the MPDU was buffered, false if it should be processed.
1280 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001281static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1282 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001283{
Johannes Berg2569a822009-11-25 17:46:17 +01001284 struct sk_buff *skb = rx->skb;
1285 struct ieee80211_local *local = rx->local;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001286 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Johannes Berg2569a822009-11-25 17:46:17 +01001287 struct sta_info *sta = rx->sta;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001288 struct tid_ampdu_rx *tid_agg_rx;
1289 u16 sc;
Thomas Pedersen6cc00d52011-11-03 21:11:11 -07001290 u8 tid, ack_policy;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001291
Johannes Berg051a41f2013-11-20 11:28:27 +01001292 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1293 is_multicast_ether_addr(hdr->addr1))
Johannes Berg2569a822009-11-25 17:46:17 +01001294 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001295
1296 /*
1297 * filter the QoS data rx stream according to
1298 * STA/TID and check if this STA/TID is on aggregation
1299 */
1300
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001301 if (!sta)
Johannes Berg2569a822009-11-25 17:46:17 +01001302 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001303
Thomas Pedersen6cc00d52011-11-03 21:11:11 -07001304 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1305 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02001306 tid = ieee80211_get_tid(hdr);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001307
Johannes Berga87f7362010-06-10 10:21:38 +02001308 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
Johannes Bergbfe40fa2016-08-29 23:25:18 +03001309 if (!tid_agg_rx) {
1310 if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1311 !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1312 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1313 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1314 WLAN_BACK_RECIPIENT,
1315 WLAN_REASON_QSTA_REQUIRE_SETUP);
Johannes Berga87f7362010-06-10 10:21:38 +02001316 goto dont_reorder;
Johannes Bergbfe40fa2016-08-29 23:25:18 +03001317 }
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001318
1319 /* qos null data frames are excluded */
1320 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
Johannes Berga87f7362010-06-10 10:21:38 +02001321 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001322
Thomas Pedersen6cc00d52011-11-03 21:11:11 -07001323 /* not part of a BA session */
1324 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1325 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1326 goto dont_reorder;
1327
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001328 /* new, potentially un-ordered, ampdu frame - process it */
1329
1330 /* reset session timer */
1331 if (tid_agg_rx->timeout)
Felix Fietkau12d3952f2012-03-18 22:58:06 +01001332 tid_agg_rx->last_rx = jiffies;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001333
1334 /* if this mpdu is fragmented - terminate rx aggregation session */
1335 sc = le16_to_cpu(hdr->seq_ctrl);
1336 if (sc & IEEE80211_SCTL_FRAG) {
Johannes Berg344eec62010-06-10 10:21:36 +02001337 skb_queue_tail(&rx->sdata->skb_queue, skb);
1338 ieee80211_queue_work(&local->hw, &rx->sdata->work);
Johannes Berg2569a822009-11-25 17:46:17 +01001339 return;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001340 }
1341
Johannes Berga87f7362010-06-10 10:21:38 +02001342 /*
1343 * No locking needed -- we will only ever process one
1344 * RX packet at a time, and thus own tid_agg_rx. All
1345 * other code manipulating it needs to (and does) make
1346 * sure that we cannot get to it any more before doing
1347 * anything with it.
1348 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001349 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1350 frames))
Johannes Berg2569a822009-11-25 17:46:17 +01001351 return;
1352
1353 dont_reorder:
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001354 __skb_queue_tail(frames, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001355}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001356
Johannes Berg49461622008-06-30 15:10:45 +02001357static ieee80211_rx_result debug_noinline
Johannes Berg03954422014-11-11 16:49:25 +01001358ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001359{
Harvey Harrisona7767f92008-07-02 16:30:51 -07001360 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02001361 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001362
Sara Sharonf9cfa5f2015-12-08 16:04:33 +02001363 if (status->flag & RX_FLAG_DUP_VALIDATED)
1364 return RX_CONTINUE;
1365
Johannes Berg6b0f3272013-07-11 22:33:26 +02001366 /*
1367 * Drop duplicate 802.11 retransmissions
1368 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1369 */
Johannes Berg03954422014-11-11 16:49:25 +01001370
1371 if (rx->skb->len < 24)
1372 return RX_CONTINUE;
1373
1374 if (ieee80211_is_ctl(hdr->frame_control) ||
1375 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
1376 is_multicast_ether_addr(hdr->addr1))
1377 return RX_CONTINUE;
1378
Johannes Berga732fa72015-10-14 18:27:07 +02001379 if (!rx->sta)
1380 return RX_CONTINUE;
1381
1382 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1383 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1384 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001385 rx->sta->rx_stats.num_duplicates++;
Johannes Berga732fa72015-10-14 18:27:07 +02001386 return RX_DROP_UNUSABLE;
1387 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1388 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
Johannes Berg571ecf62007-07-27 15:43:22 +02001389 }
1390
Johannes Berg03954422014-11-11 16:49:25 +01001391 return RX_CONTINUE;
1392}
1393
1394static ieee80211_rx_result debug_noinline
1395ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1396{
1397 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1398
Johannes Berg571ecf62007-07-27 15:43:22 +02001399 /* Drop disallowed frame classes based on STA auth/assoc state;
1400 * IEEE 802.11, Chap 5.5.
1401 *
Johannes Bergccd7b362008-09-11 00:01:56 +02001402 * mac80211 filters only based on association state, i.e. it drops
1403 * Class 3 frames from not associated stations. hostapd sends
Johannes Berg571ecf62007-07-27 15:43:22 +02001404 * deauth/disassoc frames when needed. In addition, hostapd is
1405 * responsible for filtering on both auth and assoc states.
1406 */
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001407
Johannes Berg902acc72008-02-23 15:17:19 +01001408 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001409 return ieee80211_rx_mesh_check(rx);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001410
Harvey Harrisona7767f92008-07-02 16:30:51 -07001411 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1412 ieee80211_is_pspoll(hdr->frame_control)) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001413 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Bill Jordan1be7fe82010-10-01 11:20:41 -04001414 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
Rostislav Lisovy239281f2014-11-03 10:33:19 +01001415 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001416 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
Johannes Berg7852e362012-01-20 13:55:24 +01001417 /*
1418 * accept port control frames from the AP even when it's not
1419 * yet marked ASSOC to prevent a race where we don't set the
1420 * assoc bit quickly enough before it sends the first frame
1421 */
1422 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
Guy Eilam2a33bee2011-08-17 15:18:15 +03001423 ieee80211_is_data_present(hdr->frame_control)) {
Johannes Berg6dbda2d2012-10-26 00:41:23 +02001424 unsigned int hdrlen;
1425 __be16 ethertype;
Guy Eilam2a33bee2011-08-17 15:18:15 +03001426
Johannes Berg6dbda2d2012-10-26 00:41:23 +02001427 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1428
1429 if (rx->skb->len < hdrlen + 8)
1430 return RX_DROP_MONITOR;
1431
1432 skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
1433 if (ethertype == rx->sdata->control_port_protocol)
Guy Eilam2a33bee2011-08-17 15:18:15 +03001434 return RX_CONTINUE;
1435 }
Johannes Berg21fc7562011-11-04 11:18:13 +01001436
1437 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1438 cfg80211_rx_spurious_frame(rx->sdata->dev,
1439 hdr->addr2,
1440 GFP_ATOMIC))
1441 return RX_DROP_UNUSABLE;
1442
Johannes Berge4c26ad2008-01-31 19:48:21 +01001443 return RX_DROP_MONITOR;
Guy Eilam2a33bee2011-08-17 15:18:15 +03001444 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001445
Johannes Berg9ae54c82008-01-31 19:48:20 +01001446 return RX_CONTINUE;
Johannes Berg570bd532007-07-27 15:43:22 +02001447}
1448
1449
Johannes Berg49461622008-06-30 15:10:45 +02001450static ieee80211_rx_result debug_noinline
Kalle Valo572e0012009-02-10 17:09:31 +02001451ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1452{
1453 struct ieee80211_local *local;
1454 struct ieee80211_hdr *hdr;
1455 struct sk_buff *skb;
1456
1457 local = rx->local;
1458 skb = rx->skb;
1459 hdr = (struct ieee80211_hdr *) skb->data;
1460
1461 if (!local->pspolling)
1462 return RX_CONTINUE;
1463
1464 if (!ieee80211_has_fromds(hdr->frame_control))
1465 /* this is not from AP */
1466 return RX_CONTINUE;
1467
1468 if (!ieee80211_is_data(hdr->frame_control))
1469 return RX_CONTINUE;
1470
1471 if (!ieee80211_has_moredata(hdr->frame_control)) {
1472 /* AP has no more frames buffered for us */
1473 local->pspolling = false;
1474 return RX_CONTINUE;
1475 }
1476
1477 /* more data bit is set, let's request a new frame from the AP */
1478 ieee80211_send_pspoll(local, rx->sdata);
1479
1480 return RX_CONTINUE;
1481}
1482
Marco Porschd012a602012-10-10 12:39:50 -07001483static void sta_ps_start(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001484{
Johannes Berg133b8222008-09-16 14:18:59 +02001485 struct ieee80211_sub_if_data *sdata = sta->sdata;
Christian Lamparter4571d3b2008-11-30 00:48:41 +01001486 struct ieee80211_local *local = sdata->local;
Marco Porschd012a602012-10-10 12:39:50 -07001487 struct ps_data *ps;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001488 int tid;
Joe Perches0795af52007-10-03 17:59:30 -07001489
Marco Porschd012a602012-10-10 12:39:50 -07001490 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1491 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1492 ps = &sdata->bss->ps;
1493 else
1494 return;
1495
1496 atomic_inc(&ps->num_sta_ps);
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001497 set_sta_flag(sta, WLAN_STA_PS_STA);
Johannes Berg30686bf2015-06-02 21:39:54 +02001498 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001499 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001500 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1501 sta->sta.addr, sta->sta.aid);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001502
Johannes Berg17c18bf2015-03-21 15:25:43 +01001503 ieee80211_clear_fast_xmit(sta);
1504
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001505 if (!sta->sta.txq[0])
1506 return;
1507
1508 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
Toke Høiland-Jørgensenbb42f2d2016-09-22 19:04:20 +02001509 if (txq_has_queue(sta->sta.txq[tid]))
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001510 set_bit(tid, &sta->txq_buffered_tids);
1511 else
1512 clear_bit(tid, &sta->txq_buffered_tids);
1513 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001514}
1515
Marco Porschd012a602012-10-10 12:39:50 -07001516static void sta_ps_end(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001517{
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001518 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1519 sta->sta.addr, sta->sta.aid);
Johannes Berg004c8722008-02-20 11:21:35 +01001520
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001521 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
Johannes Berge3685e02014-02-20 11:19:58 +01001522 /*
1523 * Clear the flag only if the other one is still set
1524 * so that the TX path won't start TX'ing new frames
1525 * directly ... In the case that the driver flag isn't
1526 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1527 */
1528 clear_sta_flag(sta, WLAN_STA_PS_STA);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001529 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1530 sta->sta.addr, sta->sta.aid);
Johannes Bergaf818582009-11-06 11:35:50 +01001531 return;
1532 }
1533
Johannes Berg5ac2e352014-05-27 16:32:27 +02001534 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1535 clear_sta_flag(sta, WLAN_STA_PS_STA);
Johannes Bergaf818582009-11-06 11:35:50 +01001536 ieee80211_sta_ps_deliver_wakeup(sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001537}
1538
Johannes Bergcf471612015-06-16 16:16:38 +02001539int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001540{
Johannes Bergcf471612015-06-16 16:16:38 +02001541 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001542 bool in_ps;
1543
Johannes Bergcf471612015-06-16 16:16:38 +02001544 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001545
1546 /* Don't let the same PS state be set twice */
Johannes Bergcf471612015-06-16 16:16:38 +02001547 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001548 if ((start && in_ps) || (!start && !in_ps))
1549 return -EINVAL;
1550
1551 if (start)
Johannes Bergcf471612015-06-16 16:16:38 +02001552 sta_ps_start(sta);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001553 else
Johannes Bergcf471612015-06-16 16:16:38 +02001554 sta_ps_end(sta);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001555
1556 return 0;
1557}
1558EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1559
Johannes Berg46fa38e2016-05-03 16:58:00 +03001560void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1561{
1562 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1563
1564 if (test_sta_flag(sta, WLAN_STA_SP))
1565 return;
1566
1567 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1568 ieee80211_sta_ps_deliver_poll_response(sta);
1569 else
1570 set_sta_flag(sta, WLAN_STA_PSPOLL);
1571}
1572EXPORT_SYMBOL(ieee80211_sta_pspoll);
1573
1574void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1575{
1576 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
Amadeusz Sławiński731977e2017-01-24 16:42:10 +01001577 int ac = ieee80211_ac_from_tid(tid);
Johannes Berg46fa38e2016-05-03 16:58:00 +03001578
1579 /*
Emmanuel Grumbach0aa419e2016-10-18 23:12:10 +03001580 * If this AC is not trigger-enabled do nothing unless the
1581 * driver is calling us after it already checked.
Johannes Berg46fa38e2016-05-03 16:58:00 +03001582 *
1583 * NB: This could/should check a separate bitmap of trigger-
1584 * enabled queues, but for now we only implement uAPSD w/o
1585 * TSPEC changes to the ACs, so they're always the same.
1586 */
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03001587 if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1588 tid != IEEE80211_NUM_TIDS)
Johannes Berg46fa38e2016-05-03 16:58:00 +03001589 return;
1590
1591 /* if we are in a service period, do nothing */
1592 if (test_sta_flag(sta, WLAN_STA_SP))
1593 return;
1594
1595 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1596 ieee80211_sta_ps_deliver_uapsd(sta);
1597 else
1598 set_sta_flag(sta, WLAN_STA_UAPSD);
1599}
1600EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1601
Johannes Berg49461622008-06-30 15:10:45 +02001602static ieee80211_rx_result debug_noinline
Johannes Berg47086fc2011-09-29 16:04:33 +02001603ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1604{
1605 struct ieee80211_sub_if_data *sdata = rx->sdata;
1606 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1607 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg47086fc2011-09-29 16:04:33 +02001608
Johannes Berg5c900672015-04-22 14:48:34 +02001609 if (!rx->sta)
Johannes Berg47086fc2011-09-29 16:04:33 +02001610 return RX_CONTINUE;
1611
1612 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1613 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1614 return RX_CONTINUE;
1615
1616 /*
1617 * The device handles station powersave, so don't do anything about
1618 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1619 * it to mac80211 since they're handled.)
1620 */
Johannes Berg30686bf2015-06-02 21:39:54 +02001621 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
Johannes Berg47086fc2011-09-29 16:04:33 +02001622 return RX_CONTINUE;
1623
1624 /*
1625 * Don't do anything if the station isn't already asleep. In
1626 * the uAPSD case, the station will probably be marked asleep,
1627 * in the PS-Poll case the station must be confused ...
1628 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001629 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
Johannes Berg47086fc2011-09-29 16:04:33 +02001630 return RX_CONTINUE;
1631
1632 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
Johannes Berg46fa38e2016-05-03 16:58:00 +03001633 ieee80211_sta_pspoll(&rx->sta->sta);
Johannes Berg47086fc2011-09-29 16:04:33 +02001634
1635 /* Free PS Poll skb here instead of returning RX_DROP that would
1636 * count as an dropped frame. */
1637 dev_kfree_skb(rx->skb);
1638
1639 return RX_QUEUED;
1640 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1641 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1642 ieee80211_has_pm(hdr->frame_control) &&
1643 (ieee80211_is_data_qos(hdr->frame_control) ||
1644 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02001645 u8 tid = ieee80211_get_tid(hdr);
Johannes Berg47086fc2011-09-29 16:04:33 +02001646
Johannes Berg46fa38e2016-05-03 16:58:00 +03001647 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
Johannes Berg47086fc2011-09-29 16:04:33 +02001648 }
1649
1650 return RX_CONTINUE;
1651}
1652
1653static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001654ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001655{
1656 struct sta_info *sta = rx->sta;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01001657 struct sk_buff *skb = rx->skb;
1658 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1659 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkauef0621e2013-04-22 16:29:31 +02001660 int i;
Johannes Berg571ecf62007-07-27 15:43:22 +02001661
1662 if (!sta)
Johannes Berg9ae54c82008-01-31 19:48:20 +01001663 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001664
Johannes Bergb291ba12009-07-10 15:29:03 +02001665 /*
1666 * Update last_rx only for IBSS packets which are for the current
Antonio Quartullie584da5e2012-11-25 23:13:42 +01001667 * BSSID and for station already AUTHORIZED to avoid keeping the
1668 * current IBSS network alive in cases where other STAs start
1669 * using different BSSID. This will also give the station another
1670 * chance to restart the authentication/authorization in case
1671 * something went wrong the first time.
Johannes Bergb291ba12009-07-10 15:29:03 +02001672 */
Johannes Berg05c914f2008-09-11 00:01:58 +02001673 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Ron Rindjunsky71364712007-12-25 17:00:36 +02001674 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
Johannes Berg05c914f2008-09-11 00:01:58 +02001675 NL80211_IFTYPE_ADHOC);
Antonio Quartullie584da5e2012-11-25 23:13:42 +01001676 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1677 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001678 sta->rx_stats.last_rx = jiffies;
Henning Roggef4ebddf2014-05-01 10:03:46 +02001679 if (ieee80211_is_data(hdr->frame_control) &&
Johannes Berg4f6b1b32016-03-31 20:02:08 +03001680 !is_multicast_ether_addr(hdr->addr1))
1681 sta->rx_stats.last_rate =
1682 sta_stats_encode_rate(status);
Felix Fietkau3af63342011-02-27 22:08:01 +01001683 }
Rostislav Lisovy239281f2014-11-03 10:33:19 +01001684 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001685 sta->rx_stats.last_rx = jiffies;
Johannes Bergb291ba12009-07-10 15:29:03 +02001686 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1687 /*
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001688 * Mesh beacons will update last_rx when if they are found to
1689 * match the current local configuration when processed.
Johannes Berg571ecf62007-07-27 15:43:22 +02001690 */
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001691 sta->rx_stats.last_rx = jiffies;
Johannes Berg4f6b1b32016-03-31 20:02:08 +03001692 if (ieee80211_is_data(hdr->frame_control))
1693 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
Johannes Berg571ecf62007-07-27 15:43:22 +02001694 }
1695
Kalle Valo3cf335d2009-03-22 21:57:06 +02001696 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1697 ieee80211_sta_rx_notify(rx->sdata, hdr);
1698
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001699 sta->rx_stats.fragments++;
Johannes Berg0f9c5a62016-03-31 20:02:09 +03001700
1701 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001702 sta->rx_stats.bytes += rx->skb->len;
Johannes Berg0f9c5a62016-03-31 20:02:09 +03001703 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1704
Felix Fietkaufe8431f2012-03-01 18:00:07 +01001705 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001706 sta->rx_stats.last_signal = status->signal;
Johannes Berg0be6ed12016-03-31 20:02:05 +03001707 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
Felix Fietkaufe8431f2012-03-01 18:00:07 +01001708 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001709
Felix Fietkauef0621e2013-04-22 16:29:31 +02001710 if (status->chains) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001711 sta->rx_stats.chains = status->chains;
Felix Fietkauef0621e2013-04-22 16:29:31 +02001712 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1713 int signal = status->chain_signal[i];
1714
1715 if (!(status->chains & BIT(i)))
1716 continue;
1717
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001718 sta->rx_stats.chain_signal_last[i] = signal;
Johannes Berg0be6ed12016-03-31 20:02:05 +03001719 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001720 -signal);
Felix Fietkauef0621e2013-04-22 16:29:31 +02001721 }
1722 }
1723
Johannes Berg72eaa432008-11-26 15:02:58 +01001724 /*
1725 * Change STA power saving mode only at the end of a frame
Emmanuel Grumbach9fef6542017-10-29 11:51:07 +02001726 * exchange sequence, and only for a data or management
1727 * frame as specified in IEEE 802.11-2016 11.2.3.2
Johannes Berg72eaa432008-11-26 15:02:58 +01001728 */
Johannes Berg30686bf2015-06-02 21:39:54 +02001729 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001730 !ieee80211_has_morefrags(hdr->frame_control) &&
Emmanuel Grumbach9fef6542017-10-29 11:51:07 +02001731 (ieee80211_is_mgmt(hdr->frame_control) ||
1732 ieee80211_is_data(hdr->frame_control)) &&
Christian Lamparter4cfda472010-12-27 23:21:26 +01001733 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001734 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
Emmanuel Grumbach9fef6542017-10-29 11:51:07 +02001735 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001736 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
Johannes Bergb4ba5442014-01-24 14:41:44 +01001737 if (!ieee80211_has_pm(hdr->frame_control))
Marco Porschd012a602012-10-10 12:39:50 -07001738 sta_ps_end(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001739 } else {
1740 if (ieee80211_has_pm(hdr->frame_control))
Marco Porschd012a602012-10-10 12:39:50 -07001741 sta_ps_start(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001742 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001743 }
1744
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001745 /* mesh power save support */
1746 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1747 ieee80211_mps_rx_h_sta_process(sta, hdr);
1748
Johannes Berg22403de2009-10-30 12:55:03 +01001749 /*
1750 * Drop (qos-)data::nullfunc frames silently, since they
1751 * are used only to control station power saving mode.
1752 */
1753 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1754 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001755 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
Felix Fietkaud5242152010-01-08 18:06:26 +01001756
1757 /*
1758 * If we receive a 4-addr nullfunc frame from a STA
Johannes Berge7f4a942011-11-04 11:18:20 +01001759 * that was not moved to a 4-addr STA vlan yet send
1760 * the event to userspace and for older hostapd drop
1761 * the frame to the monitor interface.
Felix Fietkaud5242152010-01-08 18:06:26 +01001762 */
1763 if (ieee80211_has_a4(hdr->frame_control) &&
1764 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1765 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
Johannes Berge7f4a942011-11-04 11:18:20 +01001766 !rx->sdata->u.vlan.sta))) {
1767 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1768 cfg80211_rx_unexpected_4addr_frame(
1769 rx->sdata->dev, sta->sta.addr,
1770 GFP_ATOMIC);
Felix Fietkaud5242152010-01-08 18:06:26 +01001771 return RX_DROP_MONITOR;
Johannes Berge7f4a942011-11-04 11:18:20 +01001772 }
Johannes Berg22403de2009-10-30 12:55:03 +01001773 /*
1774 * Update counter and free packet here to avoid
1775 * counting this as a dropped packed.
1776 */
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001777 sta->rx_stats.packets++;
Johannes Berg571ecf62007-07-27 15:43:22 +02001778 dev_kfree_skb(rx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001779 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001780 }
1781
Johannes Berg9ae54c82008-01-31 19:48:20 +01001782 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001783} /* ieee80211_rx_h_sta_process */
1784
Johan Almbladh86c228a2013-08-14 15:29:46 +02001785static ieee80211_rx_result debug_noinline
1786ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1787{
1788 struct sk_buff *skb = rx->skb;
1789 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1790 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1791 int keyidx;
1792 int hdrlen;
1793 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1794 struct ieee80211_key *sta_ptk = NULL;
1795 int mmie_keyidx = -1;
1796 __le16 fc;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001797 const struct ieee80211_cipher_scheme *cs = NULL;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001798
1799 /*
1800 * Key selection 101
1801 *
1802 * There are four types of keys:
1803 * - GTK (group keys)
1804 * - IGTK (group keys for management frames)
1805 * - PTK (pairwise keys)
1806 * - STK (station-to-station pairwise keys)
1807 *
1808 * When selecting a key, we have to distinguish between multicast
1809 * (including broadcast) and unicast frames, the latter can only
1810 * use PTKs and STKs while the former always use GTKs and IGTKs.
1811 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1812 * unicast frames can also use key indices like GTKs. Hence, if we
1813 * don't have a PTK/STK we check the key index for a WEP key.
1814 *
1815 * Note that in a regular BSS, multicast frames are sent by the
1816 * AP only, associated stations unicast the frame to the AP first
1817 * which then multicasts it on their behalf.
1818 *
1819 * There is also a slight problem in IBSS mode: GTKs are negotiated
1820 * with each station, that is something we don't currently handle.
1821 * The spec seems to expect that one negotiates the same key with
1822 * every station but there's no such requirement; VLANs could be
1823 * possible.
1824 */
1825
Johan Almbladh86c228a2013-08-14 15:29:46 +02001826 /* start without a key */
1827 rx->key = NULL;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001828 fc = hdr->frame_control;
1829
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001830 if (rx->sta) {
1831 int keyid = rx->sta->ptk_idx;
1832
1833 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1834 cs = rx->sta->cipher_scheme;
Johannes Berg2c61cf92016-03-17 15:02:55 +02001835 keyid = ieee80211_get_cs_keyid(cs, rx->skb);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001836 if (unlikely(keyid < 0))
1837 return RX_DROP_UNUSABLE;
1838 }
1839 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1840 }
1841
Johan Almbladh86c228a2013-08-14 15:29:46 +02001842 if (!ieee80211_has_protected(fc))
1843 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1844
1845 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1846 rx->key = sta_ptk;
1847 if ((status->flag & RX_FLAG_DECRYPTED) &&
1848 (status->flag & RX_FLAG_IV_STRIPPED))
1849 return RX_CONTINUE;
1850 /* Skip decryption if the frame is not protected. */
1851 if (!ieee80211_has_protected(fc))
1852 return RX_CONTINUE;
1853 } else if (mmie_keyidx >= 0) {
1854 /* Broadcast/multicast robust management frame / BIP */
1855 if ((status->flag & RX_FLAG_DECRYPTED) &&
1856 (status->flag & RX_FLAG_IV_STRIPPED))
1857 return RX_CONTINUE;
1858
1859 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1860 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1861 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
Masashi Honma46f6b062016-06-22 19:55:20 +09001862 if (rx->sta) {
1863 if (ieee80211_is_group_privacy_action(skb) &&
1864 test_sta_flag(rx->sta, WLAN_STA_MFP))
1865 return RX_DROP_MONITOR;
1866
Johan Almbladh86c228a2013-08-14 15:29:46 +02001867 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
Masashi Honma46f6b062016-06-22 19:55:20 +09001868 }
Johan Almbladh86c228a2013-08-14 15:29:46 +02001869 if (!rx->key)
1870 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1871 } else if (!ieee80211_has_protected(fc)) {
1872 /*
1873 * The frame was not protected, so skip decryption. However, we
1874 * need to set rx->key if there is a key that could have been
1875 * used so that the frame may be dropped if encryption would
1876 * have been expected.
1877 */
1878 struct ieee80211_key *key = NULL;
1879 struct ieee80211_sub_if_data *sdata = rx->sdata;
1880 int i;
1881
1882 if (ieee80211_is_mgmt(fc) &&
1883 is_multicast_ether_addr(hdr->addr1) &&
1884 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1885 rx->key = key;
1886 else {
1887 if (rx->sta) {
1888 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1889 key = rcu_dereference(rx->sta->gtk[i]);
1890 if (key)
1891 break;
1892 }
1893 }
1894 if (!key) {
1895 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1896 key = rcu_dereference(sdata->keys[i]);
1897 if (key)
1898 break;
1899 }
1900 }
1901 if (key)
1902 rx->key = key;
1903 }
1904 return RX_CONTINUE;
1905 } else {
1906 u8 keyid;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001907
Johan Almbladh86c228a2013-08-14 15:29:46 +02001908 /*
1909 * The device doesn't give us the IV so we won't be
1910 * able to look up the key. That's ok though, we
1911 * don't need to decrypt the frame, we just won't
1912 * be able to keep statistics accurate.
1913 * Except for key threshold notifications, should
1914 * we somehow allow the driver to tell us which key
1915 * the hardware used if this flag is set?
1916 */
1917 if ((status->flag & RX_FLAG_DECRYPTED) &&
1918 (status->flag & RX_FLAG_IV_STRIPPED))
1919 return RX_CONTINUE;
1920
1921 hdrlen = ieee80211_hdrlen(fc);
1922
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001923 if (cs) {
Johannes Berg2c61cf92016-03-17 15:02:55 +02001924 keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
Johan Almbladh86c228a2013-08-14 15:29:46 +02001925
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001926 if (unlikely(keyidx < 0))
1927 return RX_DROP_UNUSABLE;
1928 } else {
1929 if (rx->skb->len < 8 + hdrlen)
1930 return RX_DROP_UNUSABLE; /* TODO: count this? */
1931 /*
1932 * no need to call ieee80211_wep_get_keyidx,
1933 * it verifies a bunch of things we've done already
1934 */
1935 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1936 keyidx = keyid >> 6;
1937 }
Johan Almbladh86c228a2013-08-14 15:29:46 +02001938
1939 /* check per-station GTK first, if multicast packet */
1940 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1941 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1942
1943 /* if not found, try default key */
1944 if (!rx->key) {
1945 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1946
1947 /*
1948 * RSNA-protected unicast frames should always be
1949 * sent with pairwise or station-to-station keys,
1950 * but for WEP we allow using a key index as well.
1951 */
1952 if (rx->key &&
1953 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1954 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1955 !is_multicast_ether_addr(hdr->addr1))
1956 rx->key = NULL;
1957 }
1958 }
1959
1960 if (rx->key) {
1961 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1962 return RX_DROP_MONITOR;
1963
Johan Almbladh86c228a2013-08-14 15:29:46 +02001964 /* TODO: add threshold stuff again */
1965 } else {
1966 return RX_DROP_MONITOR;
1967 }
1968
1969 switch (rx->key->conf.cipher) {
1970 case WLAN_CIPHER_SUITE_WEP40:
1971 case WLAN_CIPHER_SUITE_WEP104:
1972 result = ieee80211_crypto_wep_decrypt(rx);
1973 break;
1974 case WLAN_CIPHER_SUITE_TKIP:
1975 result = ieee80211_crypto_tkip_decrypt(rx);
1976 break;
1977 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +02001978 result = ieee80211_crypto_ccmp_decrypt(
1979 rx, IEEE80211_CCMP_MIC_LEN);
1980 break;
1981 case WLAN_CIPHER_SUITE_CCMP_256:
1982 result = ieee80211_crypto_ccmp_decrypt(
1983 rx, IEEE80211_CCMP_256_MIC_LEN);
Johan Almbladh86c228a2013-08-14 15:29:46 +02001984 break;
1985 case WLAN_CIPHER_SUITE_AES_CMAC:
1986 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1987 break;
Jouni Malinen56c52da2015-01-24 19:52:08 +02001988 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1989 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1990 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +02001991 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1992 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1993 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1994 break;
Jouni Malinen00b9cfa2015-01-24 19:52:06 +02001995 case WLAN_CIPHER_SUITE_GCMP:
1996 case WLAN_CIPHER_SUITE_GCMP_256:
1997 result = ieee80211_crypto_gcmp_decrypt(rx);
1998 break;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001999 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002000 result = ieee80211_crypto_hw_decrypt(rx);
Johan Almbladh86c228a2013-08-14 15:29:46 +02002001 }
2002
2003 /* the hdr variable is invalid after the decrypt handlers */
2004
2005 /* either the frame has been decrypted or will be dropped */
2006 status->flag |= RX_FLAG_DECRYPTED;
2007
2008 return result;
2009}
2010
Johannes Berg571ecf62007-07-27 15:43:22 +02002011static inline struct ieee80211_fragment_entry *
2012ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
2013 unsigned int frag, unsigned int seq, int rx_queue,
2014 struct sk_buff **skb)
2015{
2016 struct ieee80211_fragment_entry *entry;
Johannes Berg571ecf62007-07-27 15:43:22 +02002017
Johannes Berg571ecf62007-07-27 15:43:22 +02002018 entry = &sdata->fragments[sdata->fragment_next++];
2019 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
2020 sdata->fragment_next = 0;
2021
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002022 if (!skb_queue_empty(&entry->skb_list))
Johannes Berg571ecf62007-07-27 15:43:22 +02002023 __skb_queue_purge(&entry->skb_list);
Johannes Berg571ecf62007-07-27 15:43:22 +02002024
2025 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2026 *skb = NULL;
2027 entry->first_frag_time = jiffies;
2028 entry->seq = seq;
2029 entry->rx_queue = rx_queue;
2030 entry->last_frag = frag;
Johannes Berg9acc54b2016-02-26 22:13:40 +01002031 entry->check_sequential_pn = false;
Johannes Berg571ecf62007-07-27 15:43:22 +02002032 entry->extra_len = 0;
2033
2034 return entry;
2035}
2036
2037static inline struct ieee80211_fragment_entry *
2038ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07002039 unsigned int frag, unsigned int seq,
Johannes Berg571ecf62007-07-27 15:43:22 +02002040 int rx_queue, struct ieee80211_hdr *hdr)
2041{
2042 struct ieee80211_fragment_entry *entry;
2043 int i, idx;
2044
2045 idx = sdata->fragment_next;
2046 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2047 struct ieee80211_hdr *f_hdr;
Johannes Berg571ecf62007-07-27 15:43:22 +02002048
2049 idx--;
2050 if (idx < 0)
2051 idx = IEEE80211_FRAGMENT_MAX - 1;
2052
2053 entry = &sdata->fragments[idx];
2054 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2055 entry->rx_queue != rx_queue ||
2056 entry->last_frag + 1 != frag)
2057 continue;
2058
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07002059 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02002060
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07002061 /*
2062 * Check ftype and addresses are equal, else check next fragment
2063 */
2064 if (((hdr->frame_control ^ f_hdr->frame_control) &
2065 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002066 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2067 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
Johannes Berg571ecf62007-07-27 15:43:22 +02002068 continue;
2069
S.Çağlar Onurab466232008-02-14 17:36:47 +02002070 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02002071 __skb_queue_purge(&entry->skb_list);
2072 continue;
2073 }
2074 return entry;
2075 }
2076
2077 return NULL;
2078}
2079
Johannes Berg49461622008-06-30 15:10:45 +02002080static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002081ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02002082{
2083 struct ieee80211_hdr *hdr;
2084 u16 sc;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002085 __le16 fc;
Johannes Berg571ecf62007-07-27 15:43:22 +02002086 unsigned int frag, seq;
2087 struct ieee80211_fragment_entry *entry;
2088 struct sk_buff *skb;
2089
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07002090 hdr = (struct ieee80211_hdr *)rx->skb->data;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002091 fc = hdr->frame_control;
Javier Cardonaf7fbf702012-10-25 11:10:18 -07002092
2093 if (ieee80211_is_ctl(fc))
2094 return RX_CONTINUE;
2095
Johannes Berg571ecf62007-07-27 15:43:22 +02002096 sc = le16_to_cpu(hdr->seq_ctrl);
2097 frag = sc & IEEE80211_SCTL_FRAG;
2098
Johannes Bergb8fff402014-11-03 13:57:46 +01002099 if (is_multicast_ether_addr(hdr->addr1)) {
Johannes Bergc206ca62015-04-22 20:47:28 +02002100 I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
Andreas Müllerd0259332014-12-12 12:11:11 +01002101 goto out_no_led;
Johannes Berg571ecf62007-07-27 15:43:22 +02002102 }
Johannes Bergb8fff402014-11-03 13:57:46 +01002103
Andreas Müllerd0259332014-12-12 12:11:11 +01002104 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2105 goto out;
2106
Johannes Berg571ecf62007-07-27 15:43:22 +02002107 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2108
Zhu Yie3cf8b32010-03-29 17:35:07 +08002109 if (skb_linearize(rx->skb))
2110 return RX_DROP_UNUSABLE;
2111
Abhijeet Kolekar058897a2010-05-11 11:22:11 -07002112 /*
2113 * skb_linearize() might change the skb->data and
2114 * previously cached variables (in this case, hdr) need to
2115 * be refreshed with the new data.
2116 */
2117 hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02002118 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2119
2120 if (frag == 0) {
2121 /* This is the first fragment of a new frame. */
2122 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
Johannes Berg9e262972011-07-07 18:45:03 +02002123 rx->seqno_idx, &(rx->skb));
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +02002124 if (rx->key &&
2125 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
Johannes Berg9acc54b2016-02-26 22:13:40 +01002126 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2127 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2128 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
Harvey Harrison358c8d92008-07-15 18:44:13 -07002129 ieee80211_has_protected(fc)) {
Johannes Berg9e262972011-07-07 18:45:03 +02002130 int queue = rx->security_idx;
Johannes Berg9acc54b2016-02-26 22:13:40 +01002131
2132 /* Store CCMP/GCMP PN so that we can verify that the
2133 * next fragment has a sequential PN value.
2134 */
2135 entry->check_sequential_pn = true;
Johannes Berg571ecf62007-07-27 15:43:22 +02002136 memcpy(entry->last_pn,
Jouni Malinen91902522010-06-11 10:27:33 -07002137 rx->key->u.ccmp.rx_pn[queue],
Johannes Berg4325f6c2013-05-08 13:09:08 +02002138 IEEE80211_CCMP_PN_LEN);
Johannes Berg9acc54b2016-02-26 22:13:40 +01002139 BUILD_BUG_ON(offsetof(struct ieee80211_key,
2140 u.ccmp.rx_pn) !=
2141 offsetof(struct ieee80211_key,
2142 u.gcmp.rx_pn));
2143 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2144 sizeof(rx->key->u.gcmp.rx_pn[queue]));
2145 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2146 IEEE80211_GCMP_PN_LEN);
Johannes Berg571ecf62007-07-27 15:43:22 +02002147 }
Johannes Berg9ae54c82008-01-31 19:48:20 +01002148 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002149 }
2150
2151 /* This is a fragment for a frame that should already be pending in
2152 * fragment cache. Add this fragment to the end of the pending entry.
2153 */
Johannes Berg9e262972011-07-07 18:45:03 +02002154 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
2155 rx->seqno_idx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02002156 if (!entry) {
2157 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
Johannes Berge4c26ad2008-01-31 19:48:21 +01002158 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +02002159 }
2160
Johannes Berg9acc54b2016-02-26 22:13:40 +01002161 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
2162 * MPDU PN values are not incrementing in steps of 1."
2163 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2164 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2165 */
2166 if (entry->check_sequential_pn) {
Johannes Berg571ecf62007-07-27 15:43:22 +02002167 int i;
Johannes Berg4325f6c2013-05-08 13:09:08 +02002168 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
Jouni Malinen91902522010-06-11 10:27:33 -07002169 int queue;
Johannes Berg9acc54b2016-02-26 22:13:40 +01002170
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +02002171 if (!rx->key ||
2172 (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
Johannes Berg9acc54b2016-02-26 22:13:40 +01002173 rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 &&
2174 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP &&
2175 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002176 return RX_DROP_UNUSABLE;
Johannes Berg4325f6c2013-05-08 13:09:08 +02002177 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2178 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
Johannes Berg571ecf62007-07-27 15:43:22 +02002179 pn[i]++;
2180 if (pn[i])
2181 break;
2182 }
Johannes Berg9e262972011-07-07 18:45:03 +02002183 queue = rx->security_idx;
Jouni Malinen91902522010-06-11 10:27:33 -07002184 rpn = rx->key->u.ccmp.rx_pn[queue];
Johannes Berg4325f6c2013-05-08 13:09:08 +02002185 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002186 return RX_DROP_UNUSABLE;
Johannes Berg4325f6c2013-05-08 13:09:08 +02002187 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
Johannes Berg571ecf62007-07-27 15:43:22 +02002188 }
2189
Harvey Harrison358c8d92008-07-15 18:44:13 -07002190 skb_pull(rx->skb, ieee80211_hdrlen(fc));
Johannes Berg571ecf62007-07-27 15:43:22 +02002191 __skb_queue_tail(&entry->skb_list, rx->skb);
2192 entry->last_frag = frag;
2193 entry->extra_len += rx->skb->len;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002194 if (ieee80211_has_morefrags(fc)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02002195 rx->skb = NULL;
Johannes Berg9ae54c82008-01-31 19:48:20 +01002196 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002197 }
2198
2199 rx->skb = __skb_dequeue(&entry->skb_list);
2200 if (skb_tailroom(rx->skb) < entry->extra_len) {
Johannes Bergf1160432015-04-22 20:25:20 +02002201 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
Johannes Berg571ecf62007-07-27 15:43:22 +02002202 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2203 GFP_ATOMIC))) {
2204 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2205 __skb_queue_purge(&entry->skb_list);
Johannes Berge4c26ad2008-01-31 19:48:21 +01002206 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02002207 }
2208 }
2209 while ((skb = __skb_dequeue(&entry->skb_list))) {
Johannes Berg59ae1d12017-06-16 14:29:20 +02002210 skb_put_data(rx->skb, skb->data, skb->len);
Johannes Berg571ecf62007-07-27 15:43:22 +02002211 dev_kfree_skb(skb);
2212 }
2213
Johannes Berg571ecf62007-07-27 15:43:22 +02002214 out:
Andreas Müllerd0259332014-12-12 12:11:11 +01002215 ieee80211_led_rx(rx->local);
2216 out_no_led:
Johannes Berg571ecf62007-07-27 15:43:22 +02002217 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02002218 rx->sta->rx_stats.packets++;
Johannes Berg9ae54c82008-01-31 19:48:20 +01002219 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02002220}
2221
Johannes Berg1df332e2012-10-26 00:09:11 +02002222static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02002223{
Johannes Berg1df332e2012-10-26 00:09:11 +02002224 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002225 return -EACCES;
Johannes Berg571ecf62007-07-27 15:43:22 +02002226
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002227 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02002228}
2229
Johannes Berg1df332e2012-10-26 00:09:11 +02002230static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Berg571ecf62007-07-27 15:43:22 +02002231{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002232 struct sk_buff *skb = rx->skb;
2233 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2234
Johannes Berg3017b802007-08-28 17:01:53 -04002235 /*
Johannes Berg7848ba72007-09-14 11:10:25 -04002236 * Pass through unencrypted frames if the hardware has
2237 * decrypted them already.
Johannes Berg3017b802007-08-28 17:01:53 -04002238 */
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002239 if (status->flag & RX_FLAG_DECRYPTED)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002240 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02002241
2242 /* Drop unencrypted frames if key is set. */
Harvey Harrison358c8d92008-07-15 18:44:13 -07002243 if (unlikely(!ieee80211_has_protected(fc) &&
2244 !ieee80211_is_nullfunc(fc) &&
Johannes Berge8f4fb72015-03-20 11:37:36 +01002245 ieee80211_is_data(fc) && rx->key))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002246 return -EACCES;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002247
2248 return 0;
2249}
2250
Johannes Berg1df332e2012-10-26 00:09:11 +02002251static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002252{
2253 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Jouni Malinene3efca02010-03-28 22:31:15 -07002254 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002255 __le16 fc = hdr->frame_control;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002256
Jouni Malinene3efca02010-03-28 22:31:15 -07002257 /*
2258 * Pass through unencrypted frames if the hardware has
2259 * decrypted them already.
2260 */
2261 if (status->flag & RX_FLAG_DECRYPTED)
2262 return 0;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002263
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002264 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
Jouni Malinend211e902010-03-28 22:29:52 -07002265 if (unlikely(!ieee80211_has_protected(fc) &&
2266 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02002267 rx->key)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002268 if (ieee80211_is_deauth(fc) ||
2269 ieee80211_is_disassoc(fc))
2270 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2271 rx->skb->data,
2272 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002273 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02002274 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002275 /* BIP does not use Protected field, so need to check MMIE */
Joe Perchesf64f9e72009-11-29 16:55:45 -08002276 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02002277 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002278 if (ieee80211_is_deauth(fc) ||
2279 ieee80211_is_disassoc(fc))
2280 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2281 rx->skb->data,
2282 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002283 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02002284 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002285 /*
2286 * When using MFP, Action frames are not allowed prior to
2287 * having configured keys.
2288 */
2289 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
Johannes Bergd8ca16d2014-01-23 16:20:29 +01002290 ieee80211_is_robust_mgmt_frame(rx->skb)))
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002291 return -EACCES;
2292 }
Johannes Bergb3fc9c62008-04-13 10:12:47 +02002293
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002294 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02002295}
2296
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002297static int
Felix Fietkau4114fa22011-04-12 19:15:22 +02002298__ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
Johannes Berg571ecf62007-07-27 15:43:22 +02002299{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002300 struct ieee80211_sub_if_data *sdata = rx->sdata;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002301 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002302 bool check_port_control = false;
2303 struct ethhdr *ehdr;
2304 int ret;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002305
Felix Fietkau4114fa22011-04-12 19:15:22 +02002306 *port_control = false;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002307 if (ieee80211_has_a4(hdr->frame_control) &&
2308 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002309 return -1;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002310
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002311 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2312 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2313
2314 if (!sdata->u.mgd.use_4addr)
2315 return -1;
2316 else
2317 check_port_control = true;
2318 }
2319
Johannes Berg9bc383d2009-11-19 11:55:19 +01002320 if (is_multicast_ether_addr(hdr->addr1) &&
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002321 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002322 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02002323
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002324 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
Felix Fietkau4114fa22011-04-12 19:15:22 +02002325 if (ret < 0)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002326 return ret;
2327
2328 ehdr = (struct ethhdr *) rx->skb->data;
Felix Fietkau4114fa22011-04-12 19:15:22 +02002329 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2330 *port_control = true;
2331 else if (check_port_control)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002332 return -1;
2333
2334 return 0;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002335}
Johannes Berg571ecf62007-07-27 15:43:22 +02002336
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002337/*
2338 * requires that rx->skb is a frame with ethernet header
2339 */
Harvey Harrison358c8d92008-07-15 18:44:13 -07002340static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002341{
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05302342 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002343 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2344 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2345
2346 /*
2347 * Allow EAPOL frames to us/the PAE group address regardless
2348 * of whether the frame was encrypted or not.
2349 */
Johannes Berga621fa42010-08-27 14:26:54 +03002350 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
Joe Perches3bc79452012-05-08 18:56:53 +00002351 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2352 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002353 return true;
2354
2355 if (ieee80211_802_1x_port_control(rx) ||
Harvey Harrison358c8d92008-07-15 18:44:13 -07002356 ieee80211_drop_unencrypted(rx, fc))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002357 return false;
2358
2359 return true;
2360}
2361
Denis Kenzior018f6fb2018-03-26 12:52:51 -05002362static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2363 struct ieee80211_rx_data *rx)
2364{
2365 struct ieee80211_sub_if_data *sdata = rx->sdata;
2366 struct net_device *dev = sdata->dev;
2367
2368 if (unlikely((skb->protocol == sdata->control_port_protocol ||
2369 skb->protocol == cpu_to_be16(ETH_P_PREAUTH)) &&
2370 sdata->control_port_over_nl80211)) {
2371 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2372 bool noencrypt = status->flag & RX_FLAG_DECRYPTED;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05002373
Denis Kenziora948f712018-07-03 15:05:48 -05002374 cfg80211_rx_control_port(dev, skb, noencrypt);
Denis Kenzior018f6fb2018-03-26 12:52:51 -05002375 dev_kfree_skb(skb);
2376 } else {
2377 /* deliver to local stack */
2378 if (rx->napi)
2379 napi_gro_receive(rx->napi, skb);
2380 else
2381 netif_receive_skb(skb);
2382 }
2383}
2384
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002385/*
2386 * requires that rx->skb is a frame with ethernet header
2387 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002388static void
Johannes Berg5cf121c2008-02-25 16:27:43 +01002389ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002390{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002391 struct ieee80211_sub_if_data *sdata = rx->sdata;
2392 struct net_device *dev = sdata->dev;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002393 struct sk_buff *skb, *xmit_skb;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002394 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2395 struct sta_info *dsta;
Johannes Berg571ecf62007-07-27 15:43:22 +02002396
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002397 skb = rx->skb;
2398 xmit_skb = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +02002399
Johannes Berg5a490512015-04-22 17:10:38 +02002400 ieee80211_rx_stats(dev, skb->len);
2401
Johannes Bergde8f18d2016-03-31 20:02:03 +03002402 if (rx->sta) {
2403 /* The seqno index has the same property as needed
2404 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2405 * for non-QoS-data frames. Here we know it's a data
2406 * frame, so count MSDUs.
2407 */
Johannes Berg0f9c5a62016-03-31 20:02:09 +03002408 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
Johannes Bergde8f18d2016-03-31 20:02:03 +03002409 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
Johannes Berg0f9c5a62016-03-31 20:02:09 +03002410 u64_stats_update_end(&rx->sta->rx_stats.syncp);
Johannes Bergde8f18d2016-03-31 20:02:03 +03002411 }
2412
Johannes Berg05c914f2008-09-11 00:01:58 +02002413 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2414 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
Johannes Berg213cd112008-09-11 00:01:54 +02002415 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
Johannes Berg9bc383d2009-11-19 11:55:19 +01002416 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
Michael Braun72f15d52016-10-10 19:12:21 +02002417 if (is_multicast_ether_addr(ehdr->h_dest) &&
2418 ieee80211_vif_get_num_mcast_if(sdata) != 0) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002419 /*
2420 * send multicast frames both to higher layers in
2421 * local net stack and back to the wireless medium
2422 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002423 xmit_skb = skb_copy(skb, GFP_ATOMIC);
Joe Perchese87cc472012-05-13 21:56:26 +00002424 if (!xmit_skb)
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002425 net_info_ratelimited("%s: failed to clone multicast frame\n",
Joe Perchese87cc472012-05-13 21:56:26 +00002426 dev->name);
Michael Braun72f15d52016-10-10 19:12:21 +02002427 } else if (!is_multicast_ether_addr(ehdr->h_dest)) {
Johannes Bergabe60632009-11-25 17:46:18 +01002428 dsta = sta_info_get(sdata, skb->data);
2429 if (dsta) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002430 /*
2431 * The destination station is associated to
2432 * this AP (in this VLAN), so send the frame
2433 * directly to it and do not pass it to local
2434 * net stack.
Johannes Berg571ecf62007-07-27 15:43:22 +02002435 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002436 xmit_skb = skb;
Johannes Berg571ecf62007-07-27 15:43:22 +02002437 skb = NULL;
2438 }
Johannes Berg571ecf62007-07-27 15:43:22 +02002439 }
2440 }
2441
Kalle Valo59d9cb02009-12-17 13:54:57 +01002442#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002443 if (skb) {
2444 /* 'align' will only take the values 0 or 2 here since all
2445 * frames are required to be aligned to 2-byte boundaries
2446 * when being passed to mac80211; the code here works just
2447 * as well if that isn't true, but mac80211 assumes it can
2448 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
Johannes Bergd1c3a372009-01-07 00:26:10 +01002449 */
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002450 int align;
2451
2452 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
Johannes Bergd1c3a372009-01-07 00:26:10 +01002453 if (align) {
2454 if (WARN_ON(skb_headroom(skb) < 3)) {
2455 dev_kfree_skb(skb);
2456 skb = NULL;
2457 } else {
2458 u8 *data = skb->data;
Zhu Yi8ce0b582009-10-28 13:13:52 -07002459 size_t len = skb_headlen(skb);
2460 skb->data -= align;
2461 memmove(skb->data, data, len);
2462 skb_set_tail_pointer(skb, len);
Johannes Bergd1c3a372009-01-07 00:26:10 +01002463 }
2464 }
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002465 }
Johannes Bergd1c3a372009-01-07 00:26:10 +01002466#endif
2467
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002468 if (skb) {
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002469 skb->protocol = eth_type_trans(skb, dev);
2470 memset(skb->cb, 0, sizeof(skb->cb));
Denis Kenzior018f6fb2018-03-26 12:52:51 -05002471
2472 ieee80211_deliver_skb_to_local_stack(skb, rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02002473 }
2474
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002475 if (xmit_skb) {
Helmut Schaaaef6c922011-12-21 09:11:35 +01002476 /*
2477 * Send to wireless media and increase priority by 256 to
2478 * keep the received priority instead of reclassifying
2479 * the frame (see cfg80211_classify8021d).
2480 */
2481 xmit_skb->priority += 256;
YOSHIFUJI Hideakif831e902007-12-12 03:54:23 +09002482 xmit_skb->protocol = htons(ETH_P_802_3);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002483 skb_reset_network_header(xmit_skb);
2484 skb_reset_mac_header(xmit_skb);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002485 dev_queue_xmit(xmit_skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02002486 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002487}
2488
Johannes Berg49461622008-06-30 15:10:45 +02002489static ieee80211_rx_result debug_noinline
Felix Fietkau24bba072018-02-27 13:03:07 +01002490__ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002491{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002492 struct net_device *dev = rx->sdata->dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08002493 struct sk_buff *skb = rx->skb;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002494 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2495 __le16 fc = hdr->frame_control;
Zhu Yieaf85ca2009-12-01 10:18:37 +08002496 struct sk_buff_head frame_list;
Johannes Berg7f6990c2016-10-05 15:29:49 +02002497 struct ethhdr ethhdr;
Johannes Berge2b52272016-10-05 16:42:06 +02002498 const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002499
Johannes Bergea720932016-10-05 10:14:42 +02002500 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
Johannes Berge2b52272016-10-05 16:42:06 +02002501 check_da = NULL;
2502 check_sa = NULL;
2503 } else switch (rx->sdata->vif.type) {
2504 case NL80211_IFTYPE_AP:
2505 case NL80211_IFTYPE_AP_VLAN:
2506 check_da = NULL;
2507 break;
2508 case NL80211_IFTYPE_STATION:
2509 if (!rx->sta ||
2510 !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2511 check_sa = NULL;
2512 break;
2513 case NL80211_IFTYPE_MESH_POINT:
2514 check_sa = NULL;
2515 break;
2516 default:
2517 break;
Johannes Bergea720932016-10-05 10:14:42 +02002518 }
Zhu Yieaf85ca2009-12-01 10:18:37 +08002519
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002520 skb->dev = dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08002521 __skb_queue_head_init(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002522
Johannes Berg7f6990c2016-10-05 15:29:49 +02002523 if (ieee80211_data_to_8023_exthdr(skb, &ethhdr,
2524 rx->sdata->vif.addr,
Felix Fietkau24bba072018-02-27 13:03:07 +01002525 rx->sdata->vif.type,
2526 data_offset))
Johannes Berg7f6990c2016-10-05 15:29:49 +02002527 return RX_DROP_UNUSABLE;
2528
Zhu Yieaf85ca2009-12-01 10:18:37 +08002529 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2530 rx->sdata->vif.type,
Johannes Berg8b935ee2016-10-05 16:17:01 +02002531 rx->local->hw.extra_tx_headroom,
Johannes Berge2b52272016-10-05 16:42:06 +02002532 check_da, check_sa);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002533
Zhu Yieaf85ca2009-12-01 10:18:37 +08002534 while (!skb_queue_empty(&frame_list)) {
2535 rx->skb = __skb_dequeue(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002536
Harvey Harrison358c8d92008-07-15 18:44:13 -07002537 if (!ieee80211_frame_allowed(rx, fc)) {
Zhu Yieaf85ca2009-12-01 10:18:37 +08002538 dev_kfree_skb(rx->skb);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002539 continue;
2540 }
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002541
2542 ieee80211_deliver_skb(rx);
2543 }
2544
Johannes Berg9ae54c82008-01-31 19:48:20 +01002545 return RX_QUEUED;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002546}
2547
Felix Fietkau24bba072018-02-27 13:03:07 +01002548static ieee80211_rx_result debug_noinline
2549ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2550{
2551 struct sk_buff *skb = rx->skb;
2552 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2553 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2554 __le16 fc = hdr->frame_control;
2555
2556 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2557 return RX_CONTINUE;
2558
2559 if (unlikely(!ieee80211_is_data(fc)))
2560 return RX_CONTINUE;
2561
2562 if (unlikely(!ieee80211_is_data_present(fc)))
2563 return RX_DROP_MONITOR;
2564
2565 if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2566 switch (rx->sdata->vif.type) {
2567 case NL80211_IFTYPE_AP_VLAN:
2568 if (!rx->sdata->u.vlan.sta)
2569 return RX_DROP_UNUSABLE;
2570 break;
2571 case NL80211_IFTYPE_STATION:
2572 if (!rx->sdata->u.mgd.use_4addr)
2573 return RX_DROP_UNUSABLE;
2574 break;
2575 default:
2576 return RX_DROP_UNUSABLE;
2577 }
2578 }
2579
2580 if (is_multicast_ether_addr(hdr->addr1))
2581 return RX_DROP_UNUSABLE;
2582
2583 return __ieee80211_rx_h_amsdu(rx, 0);
2584}
2585
Ingo Molnarbf94e172008-10-12 23:51:38 -07002586#ifdef CONFIG_MAC80211_MESH
Davide Pesaventob0dee572008-09-27 17:29:12 +02002587static ieee80211_rx_result
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002588ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2589{
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002590 struct ieee80211_hdr *fwd_hdr, *hdr;
2591 struct ieee80211_tx_info *info;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002592 struct ieee80211s_hdr *mesh_hdr;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002593 struct sk_buff *skb = rx->skb, *fwd_skb;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02002594 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002595 struct ieee80211_sub_if_data *sdata = rx->sdata;
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002596 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Michal Kaziorcf440122016-01-25 14:43:24 +01002597 u16 ac, q, hdrlen;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002598
2599 hdr = (struct ieee80211_hdr *) skb->data;
2600 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Johannes Berg9b395bc2012-10-26 00:36:40 +02002601
2602 /* make sure fixed part of mesh header is there, also checks skb len */
2603 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2604 return RX_DROP_MONITOR;
2605
2606 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2607
2608 /* make sure full mesh header is there, also checks skb len */
2609 if (!pskb_may_pull(rx->skb,
2610 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2611 return RX_DROP_MONITOR;
2612
2613 /* reload pointers */
2614 hdr = (struct ieee80211_hdr *) skb->data;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002615 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2616
Bob Copelandd0c22112015-03-02 14:28:52 -05002617 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2618 return RX_DROP_MONITOR;
2619
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07002620 /* frame is in RMC, don't forward */
2621 if (ieee80211_is_data(hdr->frame_control) &&
2622 is_multicast_ether_addr(hdr->addr1) &&
Johannes Bergbf7cd942013-02-15 14:40:31 +01002623 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07002624 return RX_DROP_MONITOR;
2625
Johannes Berg5c900672015-04-22 14:48:34 +02002626 if (!ieee80211_is_data(hdr->frame_control))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002627 return RX_CONTINUE;
2628
2629 if (!mesh_hdr->ttl)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002630 return RX_DROP_MONITOR;
2631
Javier Cardona43b7b312009-10-15 18:10:51 -07002632 if (mesh_hdr->flags & MESH_FLAGS_AE) {
YanBo79617de2008-09-22 13:30:32 +08002633 struct mesh_path *mppath;
Javier Cardona43b7b312009-10-15 18:10:51 -07002634 char *proxied_addr;
2635 char *mpp_addr;
2636
2637 if (is_multicast_ether_addr(hdr->addr1)) {
2638 mpp_addr = hdr->addr3;
2639 proxied_addr = mesh_hdr->eaddr1;
Rajkumar Manoharan5667c862017-05-14 21:41:55 -07002640 } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2641 MESH_FLAGS_AE_A5_A6) {
Johannes Berg9b395bc2012-10-26 00:36:40 +02002642 /* has_a4 already checked in ieee80211_rx_mesh_check */
Javier Cardona43b7b312009-10-15 18:10:51 -07002643 mpp_addr = hdr->addr4;
2644 proxied_addr = mesh_hdr->eaddr2;
Johannes Berg9b395bc2012-10-26 00:36:40 +02002645 } else {
2646 return RX_DROP_MONITOR;
Javier Cardona43b7b312009-10-15 18:10:51 -07002647 }
YanBo79617de2008-09-22 13:30:32 +08002648
YanBo79617de2008-09-22 13:30:32 +08002649 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01002650 mppath = mpp_path_lookup(sdata, proxied_addr);
YanBo79617de2008-09-22 13:30:32 +08002651 if (!mppath) {
Johannes Bergbf7cd942013-02-15 14:40:31 +01002652 mpp_path_add(sdata, proxied_addr, mpp_addr);
YanBo79617de2008-09-22 13:30:32 +08002653 } else {
2654 spin_lock_bh(&mppath->state_lock);
Joe Perchesb203ca32012-05-08 18:56:52 +00002655 if (!ether_addr_equal(mppath->mpp, mpp_addr))
Javier Cardona43b7b312009-10-15 18:10:51 -07002656 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
Henning Roggeab1c7902016-02-03 13:58:37 +01002657 mppath->exp_time = jiffies;
YanBo79617de2008-09-22 13:30:32 +08002658 spin_unlock_bh(&mppath->state_lock);
2659 }
2660 rcu_read_unlock();
2661 }
2662
Javier Cardona3c5772a2009-08-10 12:15:48 -07002663 /* Frame has reached destination. Don't forward */
2664 if (!is_multicast_ether_addr(hdr->addr1) &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002665 ether_addr_equal(sdata->vif.addr, hdr->addr3))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002666 return RX_CONTINUE;
2667
Michal Kaziorcf440122016-01-25 14:43:24 +01002668 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2669 q = sdata->vif.hw_queue[ac];
Thomas Pedersend3c15972011-11-24 17:15:23 -08002670 if (ieee80211_queue_stopped(&local->hw, q)) {
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002671 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
Thomas Pedersend3c15972011-11-24 17:15:23 -08002672 return RX_DROP_MONITOR;
2673 }
2674 skb_set_queue_mapping(skb, q);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002675
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002676 if (!--mesh_hdr->ttl) {
2677 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
Javier Cardona2ac64cd2012-10-24 12:43:31 -07002678 goto out;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002679 }
2680
Chun-Yeow Yeohd6655082012-03-02 02:03:19 +08002681 if (!ifmsh->mshcfg.dot11MeshForwarding)
2682 goto out;
2683
Cedric Izoardc38c39b2017-01-11 14:39:07 +00002684 fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2685 sdata->encrypt_headroom, 0, GFP_ATOMIC);
Joe Perches0c3d5a92018-03-12 08:07:12 -07002686 if (!fwd_skb)
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002687 goto out;
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002688
2689 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
Thomas Pedersen9d6d6f42013-04-08 11:06:12 -07002690 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002691 info = IEEE80211_SKB_CB(fwd_skb);
2692 memset(info, 0, sizeof(*info));
2693 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2694 info->control.vif = &rx->sdata->vif;
2695 info->control.jiffies = jiffies;
2696 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2697 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2698 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002699 /* update power mode indication when forwarding */
2700 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
Johannes Bergbf7cd942013-02-15 14:40:31 +01002701 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002702 /* mesh power mode flags updated in mesh_nexthop_lookup */
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002703 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2704 } else {
2705 /* unable to resolve next hop */
Johannes Bergbf7cd942013-02-15 14:40:31 +01002706 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
Chun-Yeow Yeohf63f8422013-11-13 15:39:12 +08002707 fwd_hdr->addr3, 0,
2708 WLAN_REASON_MESH_PATH_NOFORWARD,
2709 fwd_hdr->addr2);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002710 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
Jesper Juhl74b8cc32012-01-14 21:52:17 +01002711 kfree_skb(fwd_skb);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002712 return RX_DROP_MONITOR;
2713 }
2714
2715 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2716 ieee80211_add_pending_skb(local, fwd_skb);
Johannes Bergb51aff02010-12-22 10:15:07 +01002717 out:
Johannes Bergdf140462015-04-22 14:40:58 +02002718 if (is_multicast_ether_addr(hdr->addr1))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002719 return RX_CONTINUE;
Johannes Bergdf140462015-04-22 14:40:58 +02002720 return RX_DROP_MONITOR;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002721}
Ingo Molnarbf94e172008-10-12 23:51:38 -07002722#endif
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002723
2724static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002725ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002726{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002727 struct ieee80211_sub_if_data *sdata = rx->sdata;
Vivek Natarajane15276a2010-02-08 17:47:01 +05302728 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002729 struct net_device *dev = sdata->dev;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002730 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2731 __le16 fc = hdr->frame_control;
Felix Fietkau4114fa22011-04-12 19:15:22 +02002732 bool port_control;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002733 int err;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002734
Harvey Harrison358c8d92008-07-15 18:44:13 -07002735 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002736 return RX_CONTINUE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002737
Harvey Harrison358c8d92008-07-15 18:44:13 -07002738 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002739 return RX_DROP_MONITOR;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002740
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002741 /*
Johannes Berge7f4a942011-11-04 11:18:20 +01002742 * Send unexpected-4addr-frame event to hostapd. For older versions,
2743 * also drop the frame to cooked monitor interfaces.
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002744 */
2745 if (ieee80211_has_a4(hdr->frame_control) &&
Johannes Berge7f4a942011-11-04 11:18:20 +01002746 sdata->vif.type == NL80211_IFTYPE_AP) {
2747 if (rx->sta &&
2748 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2749 cfg80211_rx_unexpected_4addr_frame(
2750 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002751 return RX_DROP_MONITOR;
Johannes Berge7f4a942011-11-04 11:18:20 +01002752 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002753
Felix Fietkau4114fa22011-04-12 19:15:22 +02002754 err = __ieee80211_data_to_8023(rx, &port_control);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002755 if (unlikely(err))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002756 return RX_DROP_UNUSABLE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002757
Harvey Harrison358c8d92008-07-15 18:44:13 -07002758 if (!ieee80211_frame_allowed(rx, fc))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002759 return RX_DROP_MONITOR;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002760
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02002761 /* directly handle TDLS channel switch requests/responses */
2762 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2763 cpu_to_be16(ETH_P_TDLS))) {
2764 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2765
2766 if (pskb_may_pull(rx->skb,
2767 offsetof(struct ieee80211_tdls_data, u)) &&
2768 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2769 tf->category == WLAN_CATEGORY_TDLS &&
2770 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2771 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
Arik Nemtsovc8ff71e2015-07-08 15:41:45 +03002772 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2773 schedule_work(&local->tdls_chsw_work);
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02002774 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02002775 rx->sta->rx_stats.packets++;
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02002776
2777 return RX_QUEUED;
2778 }
2779 }
2780
Felix Fietkau4114fa22011-04-12 19:15:22 +02002781 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2782 unlikely(port_control) && sdata->bss) {
2783 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2784 u.ap);
2785 dev = sdata->dev;
2786 rx->sdata = sdata;
2787 }
2788
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002789 rx->skb->dev = dev;
2790
Johannes Berg602fae42016-03-17 15:02:52 +02002791 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2792 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
Rajkumar Manoharan8c99f692011-02-02 22:57:53 +05302793 !is_multicast_ether_addr(
2794 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2795 (!local->scanning &&
Johannes Berg602fae42016-03-17 15:02:52 +02002796 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
2797 mod_timer(&local->dynamic_ps_timer, jiffies +
2798 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
Vivek Natarajane15276a2010-02-08 17:47:01 +05302799
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002800 ieee80211_deliver_skb(rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02002801
Johannes Berg9ae54c82008-01-31 19:48:20 +01002802 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002803}
2804
Johannes Berg49461622008-06-30 15:10:45 +02002805static ieee80211_rx_result debug_noinline
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002806ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
Ron Rindjunsky71364712007-12-25 17:00:36 +02002807{
Ron Rindjunsky71364712007-12-25 17:00:36 +02002808 struct sk_buff *skb = rx->skb;
Harvey Harrisona7767f92008-07-02 16:30:51 -07002809 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002810 struct tid_ampdu_rx *tid_agg_rx;
2811 u16 start_seq_num;
2812 u16 tid;
2813
Harvey Harrisona7767f92008-07-02 16:30:51 -07002814 if (likely(!ieee80211_is_ctl(bar->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002815 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002816
Harvey Harrisona7767f92008-07-02 16:30:51 -07002817 if (ieee80211_is_back_req(bar->frame_control)) {
Johannes Berg8ae59772010-05-30 14:52:58 +02002818 struct {
2819 __le16 control, start_seq_num;
2820 } __packed bar_data;
Emmanuel Grumbach63822462015-04-20 22:53:37 +03002821 struct ieee80211_event event = {
2822 .type = BAR_RX_EVENT,
2823 };
Johannes Berg8ae59772010-05-30 14:52:58 +02002824
Ron Rindjunsky71364712007-12-25 17:00:36 +02002825 if (!rx->sta)
Johannes Berga02ae752009-11-16 12:00:40 +01002826 return RX_DROP_MONITOR;
Johannes Berg8ae59772010-05-30 14:52:58 +02002827
2828 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2829 &bar_data, sizeof(bar_data)))
2830 return RX_DROP_MONITOR;
2831
Johannes Berg8ae59772010-05-30 14:52:58 +02002832 tid = le16_to_cpu(bar_data.control) >> 12;
Johannes Berga87f7362010-06-10 10:21:38 +02002833
Johannes Berg53f24972016-08-29 23:25:19 +03002834 if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
2835 !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
2836 ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
2837 WLAN_BACK_RECIPIENT,
2838 WLAN_REASON_QSTA_REQUIRE_SETUP);
2839
Johannes Berga87f7362010-06-10 10:21:38 +02002840 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2841 if (!tid_agg_rx)
Johannes Berga02ae752009-11-16 12:00:40 +01002842 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002843
Johannes Berg8ae59772010-05-30 14:52:58 +02002844 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
Emmanuel Grumbach63822462015-04-20 22:53:37 +03002845 event.u.ba.tid = tid;
2846 event.u.ba.ssn = start_seq_num;
2847 event.u.ba.sta = &rx->sta->sta;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002848
2849 /* reset session timer */
Johannes Berg20ad19d2009-02-10 21:25:45 +01002850 if (tid_agg_rx->timeout)
2851 mod_timer(&tid_agg_rx->session_timer,
2852 TU_TO_EXP_TIME(tid_agg_rx->timeout));
Ron Rindjunsky71364712007-12-25 17:00:36 +02002853
Johannes Bergdd318572010-11-29 11:09:16 +01002854 spin_lock(&tid_agg_rx->reorder_lock);
Johannes Berga02ae752009-11-16 12:00:40 +01002855 /* release stored frames up to start of BAR */
Johannes Bergd3b2fb52012-06-22 12:48:38 +02002856 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002857 start_seq_num, frames);
Johannes Bergdd318572010-11-29 11:09:16 +01002858 spin_unlock(&tid_agg_rx->reorder_lock);
2859
Emmanuel Grumbach63822462015-04-20 22:53:37 +03002860 drv_event_callback(rx->local, rx->sdata, &event);
2861
Johannes Berga02ae752009-11-16 12:00:40 +01002862 kfree_skb(skb);
2863 return RX_QUEUED;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002864 }
2865
Johannes Berg08daeca2010-05-30 14:53:43 +02002866 /*
2867 * After this point, we only want management frames,
2868 * so we can drop all remaining control frames to
2869 * cooked monitor interfaces.
2870 */
2871 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002872}
2873
Jouni Malinenf4f727a2009-01-10 11:46:53 +02002874static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2875 struct ieee80211_mgmt *mgmt,
2876 size_t len)
Jouni Malinenfea14732009-01-08 13:32:06 +02002877{
2878 struct ieee80211_local *local = sdata->local;
2879 struct sk_buff *skb;
2880 struct ieee80211_mgmt *resp;
2881
Joe Perchesb203ca32012-05-08 18:56:52 +00002882 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
Jouni Malinenfea14732009-01-08 13:32:06 +02002883 /* Not to own unicast address */
2884 return;
2885 }
2886
Joe Perchesb203ca32012-05-08 18:56:52 +00002887 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2888 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002889 /* Not from the current AP or not associated yet. */
Jouni Malinenfea14732009-01-08 13:32:06 +02002890 return;
2891 }
2892
2893 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2894 /* Too short SA Query request frame */
2895 return;
2896 }
2897
2898 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2899 if (skb == NULL)
2900 return;
2901
2902 skb_reserve(skb, local->hw.extra_tx_headroom);
Johannes Bergb080db52017-06-16 14:29:19 +02002903 resp = skb_put_zero(skb, 24);
Jouni Malinenfea14732009-01-08 13:32:06 +02002904 memcpy(resp->da, mgmt->sa, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002905 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +01002906 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
Jouni Malinenfea14732009-01-08 13:32:06 +02002907 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2908 IEEE80211_STYPE_ACTION);
2909 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2910 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2911 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2912 memcpy(resp->u.action.u.sa_query.trans_id,
2913 mgmt->u.action.u.sa_query.trans_id,
2914 WLAN_SA_QUERY_TR_ID_LEN);
2915
Johannes Berg62ae67b2009-11-18 18:42:05 +01002916 ieee80211_tx_skb(sdata, skb);
Jouni Malinenfea14732009-01-08 13:32:06 +02002917}
2918
Johannes Berg49461622008-06-30 15:10:45 +02002919static ieee80211_rx_result debug_noinline
Johannes Berg2e161f72010-08-12 15:38:38 +02002920ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2921{
2922 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002923 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002924
2925 /*
2926 * From here on, look only at management frames.
2927 * Data and control frames are already handled,
2928 * and unknown (reserved) frames are useless.
2929 */
2930 if (rx->skb->len < 24)
2931 return RX_DROP_MONITOR;
2932
2933 if (!ieee80211_is_mgmt(mgmt->frame_control))
2934 return RX_DROP_MONITOR;
2935
Johannes Bergee971922011-11-04 11:18:18 +01002936 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2937 ieee80211_is_beacon(mgmt->frame_control) &&
2938 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
Johannes Berg804483e2012-03-05 22:18:41 +01002939 int sig = 0;
2940
Tosoni1ad22fb2018-03-14 16:58:34 +00002941 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
2942 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
Johannes Berg804483e2012-03-05 22:18:41 +01002943 sig = status->signal;
2944
Johannes Bergee971922011-11-04 11:18:18 +01002945 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2946 rx->skb->data, rx->skb->len,
Ben Greear37c73b52012-10-26 14:49:25 -07002947 status->freq, sig);
Johannes Bergee971922011-11-04 11:18:18 +01002948 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2949 }
2950
Johannes Berg2e161f72010-08-12 15:38:38 +02002951 if (ieee80211_drop_unencrypted_mgmt(rx))
2952 return RX_DROP_UNUSABLE;
2953
2954 return RX_CONTINUE;
2955}
2956
2957static ieee80211_rx_result debug_noinline
Johannes Bergde1ede72008-09-09 14:42:50 +02002958ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2959{
2960 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01002961 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergde1ede72008-09-09 14:42:50 +02002962 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002963 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergde1ede72008-09-09 14:42:50 +02002964 int len = rx->skb->len;
2965
2966 if (!ieee80211_is_action(mgmt->frame_control))
2967 return RX_CONTINUE;
2968
Jouni Malinen026331c2010-02-15 12:53:10 +02002969 /* drop too small frames */
2970 if (len < IEEE80211_MIN_ACTION_SIZE)
2971 return RX_DROP_UNUSABLE;
2972
Marco Porsch815b8092012-12-05 15:04:26 -08002973 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002974 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2975 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg84040802010-02-15 12:46:39 +02002976 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002977
Johannes Bergde1ede72008-09-09 14:42:50 +02002978 switch (mgmt->u.action.category) {
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002979 case WLAN_CATEGORY_HT:
2980 /* reject HT action frames from stations not supporting HT */
2981 if (!rx->sta->sta.ht_cap.ht_supported)
2982 goto invalid;
2983
2984 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2985 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2986 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2987 sdata->vif.type != NL80211_IFTYPE_AP &&
2988 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2989 break;
2990
Johannes Bergec61cd62012-12-28 12:12:10 +01002991 /* verify action & smps_control/chanwidth are present */
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002992 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2993 goto invalid;
2994
2995 switch (mgmt->u.action.u.ht_smps.action) {
2996 case WLAN_HT_ACTION_SMPS: {
2997 struct ieee80211_supported_band *sband;
Johannes Bergaf0ed692013-02-12 14:21:00 +01002998 enum ieee80211_smps_mode smps_mode;
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +05302999 struct sta_opmode_info sta_opmode = {};
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003000
3001 /* convert to HT capability */
3002 switch (mgmt->u.action.u.ht_smps.smps_control) {
3003 case WLAN_HT_SMPS_CONTROL_DISABLED:
Johannes Bergaf0ed692013-02-12 14:21:00 +01003004 smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003005 break;
3006 case WLAN_HT_SMPS_CONTROL_STATIC:
Johannes Bergaf0ed692013-02-12 14:21:00 +01003007 smps_mode = IEEE80211_SMPS_STATIC;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003008 break;
3009 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
Johannes Bergaf0ed692013-02-12 14:21:00 +01003010 smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003011 break;
3012 default:
3013 goto invalid;
3014 }
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003015
3016 /* if no change do nothing */
Johannes Bergaf0ed692013-02-12 14:21:00 +01003017 if (rx->sta->sta.smps_mode == smps_mode)
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003018 goto handled;
Johannes Bergaf0ed692013-02-12 14:21:00 +01003019 rx->sta->sta.smps_mode = smps_mode;
tamizhr@codeaurora.org57566b22018-03-27 19:16:16 +05303020 sta_opmode.smps_mode =
3021 ieee80211_smps_mode_to_smps_mode(smps_mode);
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +05303022 sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003023
3024 sband = rx->local->hw.wiphy->bands[status->band];
3025
Johannes Berg64f68e52012-03-28 10:58:37 +02003026 rate_control_rate_update(local, sband, rx->sta,
3027 IEEE80211_RC_SMPS_CHANGED);
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +05303028 cfg80211_sta_opmode_change_notify(sdata->dev,
3029 rx->sta->addr,
3030 &sta_opmode,
3031 GFP_KERNEL);
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003032 goto handled;
3033 }
Johannes Bergec61cd62012-12-28 12:12:10 +01003034 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3035 struct ieee80211_supported_band *sband;
3036 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
Eliad Peller1c45c5c2014-12-14 11:05:51 +02003037 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +05303038 struct sta_opmode_info sta_opmode = {};
Johannes Bergec61cd62012-12-28 12:12:10 +01003039
3040 /* If it doesn't support 40 MHz it can't change ... */
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003041 if (!(rx->sta->sta.ht_cap.cap &
3042 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Johannes Bergec61cd62012-12-28 12:12:10 +01003043 goto handled;
3044
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003045 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
Eliad Peller1c45c5c2014-12-14 11:05:51 +02003046 max_bw = IEEE80211_STA_RX_BW_20;
Johannes Bergec61cd62012-12-28 12:12:10 +01003047 else
Eliad Peller1c45c5c2014-12-14 11:05:51 +02003048 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
3049
3050 /* set cur_max_bandwidth and recalc sta bw */
3051 rx->sta->cur_max_bandwidth = max_bw;
3052 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003053
3054 if (rx->sta->sta.bandwidth == new_bw)
3055 goto handled;
Johannes Bergec61cd62012-12-28 12:12:10 +01003056
Eliad Peller1c45c5c2014-12-14 11:05:51 +02003057 rx->sta->sta.bandwidth = new_bw;
Johannes Bergec61cd62012-12-28 12:12:10 +01003058 sband = rx->local->hw.wiphy->bands[status->band];
tamizhr@codeaurora.org97f5f422018-03-27 19:16:17 +05303059 sta_opmode.bw =
3060 ieee80211_sta_rx_bw_to_chan_width(rx->sta);
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +05303061 sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
Johannes Bergec61cd62012-12-28 12:12:10 +01003062
3063 rate_control_rate_update(local, sband, rx->sta,
3064 IEEE80211_RC_BW_CHANGED);
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +05303065 cfg80211_sta_opmode_change_notify(sdata->dev,
3066 rx->sta->addr,
3067 &sta_opmode,
3068 GFP_KERNEL);
Johannes Bergec61cd62012-12-28 12:12:10 +01003069 goto handled;
3070 }
Johannes Berg1d8d3de2011-12-16 15:28:57 +01003071 default:
3072 goto invalid;
3073 }
3074
3075 break;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003076 case WLAN_CATEGORY_PUBLIC:
3077 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3078 goto invalid;
3079 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3080 break;
3081 if (!rx->sta)
3082 break;
3083 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3084 break;
3085 if (mgmt->u.action.u.ext_chan_switch.action_code !=
3086 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3087 break;
3088 if (len < offsetof(struct ieee80211_mgmt,
3089 u.action.u.ext_chan_switch.variable))
3090 goto invalid;
3091 goto queue;
Johannes Berg0af83d32012-12-27 18:55:36 +01003092 case WLAN_CATEGORY_VHT:
3093 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3094 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3095 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3096 sdata->vif.type != NL80211_IFTYPE_AP &&
3097 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3098 break;
3099
3100 /* verify action code is present */
3101 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3102 goto invalid;
3103
3104 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3105 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
Johannes Berg0af83d32012-12-27 18:55:36 +01003106 /* verify opmode is present */
3107 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3108 goto invalid;
Johannes Bergd2941df2016-10-20 08:52:50 +02003109 goto queue;
Johannes Berg0af83d32012-12-27 18:55:36 +01003110 }
Sara Sharon23a1f8d2015-12-08 16:04:31 +02003111 case WLAN_VHT_ACTION_GROUPID_MGMT: {
3112 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3113 goto invalid;
3114 goto queue;
3115 }
Johannes Berg0af83d32012-12-27 18:55:36 +01003116 default:
3117 break;
3118 }
3119 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02003120 case WLAN_CATEGORY_BACK:
Johannes Berg8abd3f92009-02-10 21:25:47 +01003121 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
Thomas Pedersenae2772b2011-10-26 14:47:29 -07003122 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg8abd3f92009-02-10 21:25:47 +01003123 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
Alexander Simon13c40c52011-11-30 16:56:34 +01003124 sdata->vif.type != NL80211_IFTYPE_AP &&
3125 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Johannes Berg84040802010-02-15 12:46:39 +02003126 break;
Johannes Berg8abd3f92009-02-10 21:25:47 +01003127
Jouni Malinen026331c2010-02-15 12:53:10 +02003128 /* verify action_code is present */
3129 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3130 break;
3131
Johannes Bergde1ede72008-09-09 14:42:50 +02003132 switch (mgmt->u.action.u.addba_req.action_code) {
3133 case WLAN_ACTION_ADDBA_REQ:
3134 if (len < (IEEE80211_MIN_ACTION_SIZE +
3135 sizeof(mgmt->u.action.u.addba_req)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02003136 goto invalid;
3137 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02003138 case WLAN_ACTION_ADDBA_RESP:
3139 if (len < (IEEE80211_MIN_ACTION_SIZE +
3140 sizeof(mgmt->u.action.u.addba_resp)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02003141 goto invalid;
3142 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02003143 case WLAN_ACTION_DELBA:
3144 if (len < (IEEE80211_MIN_ACTION_SIZE +
3145 sizeof(mgmt->u.action.u.delba)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02003146 goto invalid;
3147 break;
3148 default:
3149 goto invalid;
Johannes Bergde1ede72008-09-09 14:42:50 +02003150 }
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02003151
Johannes Berg8b58ff82010-06-10 10:21:51 +02003152 goto queue;
Johannes Berg39192c02008-09-09 14:49:03 +02003153 case WLAN_CATEGORY_SPECTRUM_MGMT:
Jouni Malinen026331c2010-02-15 12:53:10 +02003154 /* verify action_code is present */
3155 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3156 break;
3157
Johannes Berg39192c02008-09-09 14:49:03 +02003158 switch (mgmt->u.action.u.measurement.action_code) {
3159 case WLAN_ACTION_SPCT_MSR_REQ:
Johannes Berg57fbcce2016-04-12 15:56:15 +02003160 if (status->band != NL80211_BAND_5GHZ)
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003161 break;
3162
Johannes Berg39192c02008-09-09 14:49:03 +02003163 if (len < (IEEE80211_MIN_ACTION_SIZE +
3164 sizeof(mgmt->u.action.u.measurement)))
Johannes Berg84040802010-02-15 12:46:39 +02003165 break;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003166
Johannes Bergcc32abd2009-05-15 11:52:31 +02003167 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02003168 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02003169
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003170 ieee80211_process_measurement_req(sdata, mgmt, len);
3171 goto handled;
3172 case WLAN_ACTION_SPCT_CHL_SWITCH: {
3173 u8 *bssid;
3174 if (len < (IEEE80211_MIN_ACTION_SIZE +
3175 sizeof(mgmt->u.action.u.chan_switch)))
3176 break;
3177
3178 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003179 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3180 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003181 break;
3182
3183 if (sdata->vif.type == NL80211_IFTYPE_STATION)
3184 bssid = sdata->u.mgd.bssid;
3185 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3186 bssid = sdata->u.ibss.bssid;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003187 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3188 bssid = mgmt->sa;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003189 else
3190 break;
3191
3192 if (!ether_addr_equal(mgmt->bssid, bssid))
Johannes Berg84040802010-02-15 12:46:39 +02003193 break;
Sujithc481ec92009-01-06 09:28:37 +05303194
Johannes Berg8b58ff82010-06-10 10:21:51 +02003195 goto queue;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003196 }
Johannes Berg39192c02008-09-09 14:49:03 +02003197 }
3198 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02003199 case WLAN_CATEGORY_SA_QUERY:
3200 if (len < (IEEE80211_MIN_ACTION_SIZE +
3201 sizeof(mgmt->u.action.u.sa_query)))
Johannes Berg84040802010-02-15 12:46:39 +02003202 break;
3203
Jouni Malinenfea14732009-01-08 13:32:06 +02003204 switch (mgmt->u.action.u.sa_query.action) {
3205 case WLAN_ACTION_SA_QUERY_REQUEST:
3206 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02003207 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02003208 ieee80211_process_sa_query_req(sdata, mgmt, len);
Johannes Berg84040802010-02-15 12:46:39 +02003209 goto handled;
Jouni Malinenfea14732009-01-08 13:32:06 +02003210 }
3211 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -07003212 case WLAN_CATEGORY_SELF_PROTECTED:
Johannes Berg9b395bc2012-10-26 00:36:40 +02003213 if (len < (IEEE80211_MIN_ACTION_SIZE +
3214 sizeof(mgmt->u.action.u.self_prot.action_code)))
3215 break;
3216
Thomas Pedersen8db09852011-08-12 20:01:00 -07003217 switch (mgmt->u.action.u.self_prot.action_code) {
3218 case WLAN_SP_MESH_PEERING_OPEN:
3219 case WLAN_SP_MESH_PEERING_CLOSE:
3220 case WLAN_SP_MESH_PEERING_CONFIRM:
3221 if (!ieee80211_vif_is_mesh(&sdata->vif))
3222 goto invalid;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08003223 if (sdata->u.mesh.user_mpm)
Thomas Pedersen8db09852011-08-12 20:01:00 -07003224 /* userspace handles this frame */
3225 break;
3226 goto queue;
3227 case WLAN_SP_MGK_INFORM:
3228 case WLAN_SP_MGK_ACK:
3229 if (!ieee80211_vif_is_mesh(&sdata->vif))
3230 goto invalid;
3231 break;
3232 }
3233 break;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -07003234 case WLAN_CATEGORY_MESH_ACTION:
Johannes Berg9b395bc2012-10-26 00:36:40 +02003235 if (len < (IEEE80211_MIN_ACTION_SIZE +
3236 sizeof(mgmt->u.action.u.mesh_action.action_code)))
3237 break;
3238
Johannes Berg77a121c2010-06-10 10:21:34 +02003239 if (!ieee80211_vif_is_mesh(&sdata->vif))
3240 break;
Thomas Pedersen25d49e42011-08-11 19:35:15 -07003241 if (mesh_action_is_path_sel(mgmt) &&
Johannes Berg1df332e2012-10-26 00:09:11 +02003242 !mesh_path_sel_is_hwmp(sdata))
Javier Cardonac7108a72010-12-16 17:37:50 -08003243 break;
3244 goto queue;
Johannes Berg84040802010-02-15 12:46:39 +02003245 }
Jouni Malinen026331c2010-02-15 12:53:10 +02003246
Johannes Berg2e161f72010-08-12 15:38:38 +02003247 return RX_CONTINUE;
3248
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02003249 invalid:
Johannes Berg554891e2010-09-24 12:38:25 +02003250 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
Johannes Berg2e161f72010-08-12 15:38:38 +02003251 /* will return in the next handlers */
3252 return RX_CONTINUE;
3253
3254 handled:
3255 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003256 rx->sta->rx_stats.packets++;
Johannes Berg2e161f72010-08-12 15:38:38 +02003257 dev_kfree_skb(rx->skb);
3258 return RX_QUEUED;
3259
3260 queue:
Johannes Berg2e161f72010-08-12 15:38:38 +02003261 skb_queue_tail(&sdata->skb_queue, rx->skb);
3262 ieee80211_queue_work(&local->hw, &sdata->work);
3263 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003264 rx->sta->rx_stats.packets++;
Johannes Berg2e161f72010-08-12 15:38:38 +02003265 return RX_QUEUED;
3266}
3267
3268static ieee80211_rx_result debug_noinline
3269ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3270{
Johannes Berg554891e2010-09-24 12:38:25 +02003271 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg804483e2012-03-05 22:18:41 +01003272 int sig = 0;
Johannes Berg2e161f72010-08-12 15:38:38 +02003273
3274 /* skip known-bad action frames and return them in the next handler */
Johannes Berg554891e2010-09-24 12:38:25 +02003275 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
Johannes Berg2e161f72010-08-12 15:38:38 +02003276 return RX_CONTINUE;
Felix Fietkaud7907442010-01-07 20:23:53 +01003277
Jouni Malinen026331c2010-02-15 12:53:10 +02003278 /*
3279 * Getting here means the kernel doesn't know how to handle
3280 * it, but maybe userspace does ... include returned frames
3281 * so userspace can register for those to know whether ones
3282 * it transmitted were processed or returned.
3283 */
Jouni Malinen026331c2010-02-15 12:53:10 +02003284
Tosoni1ad22fb2018-03-14 16:58:34 +00003285 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3286 !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
Johannes Berg804483e2012-03-05 22:18:41 +01003287 sig = status->signal;
3288
Johannes Berg71bbc992012-06-15 15:30:18 +02003289 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -07003290 rx->skb->data, rx->skb->len, 0)) {
Johannes Berg2e161f72010-08-12 15:38:38 +02003291 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003292 rx->sta->rx_stats.packets++;
Johannes Berg2e161f72010-08-12 15:38:38 +02003293 dev_kfree_skb(rx->skb);
3294 return RX_QUEUED;
3295 }
3296
Johannes Berg2e161f72010-08-12 15:38:38 +02003297 return RX_CONTINUE;
3298}
3299
3300static ieee80211_rx_result debug_noinline
3301ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3302{
3303 struct ieee80211_local *local = rx->local;
3304 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3305 struct sk_buff *nskb;
3306 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02003307 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02003308
3309 if (!ieee80211_is_action(mgmt->frame_control))
3310 return RX_CONTINUE;
3311
3312 /*
3313 * For AP mode, hostapd is responsible for handling any action
3314 * frames that we didn't handle, including returning unknown
3315 * ones. For all other modes we will return them to the sender,
3316 * setting the 0x80 bit in the action category, as required by
Johannes Berg4b5ebcc2012-06-27 15:38:56 +02003317 * 802.11-2012 9.24.4.
Johannes Berg2e161f72010-08-12 15:38:38 +02003318 * Newer versions of hostapd shall also use the management frame
3319 * registration mechanisms, but older ones still use cooked
3320 * monitor interfaces so push all frames there.
3321 */
Johannes Berg554891e2010-09-24 12:38:25 +02003322 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
Johannes Berg2e161f72010-08-12 15:38:38 +02003323 (sdata->vif.type == NL80211_IFTYPE_AP ||
3324 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3325 return RX_DROP_MONITOR;
Jouni Malinen026331c2010-02-15 12:53:10 +02003326
Johannes Berg4b5ebcc2012-06-27 15:38:56 +02003327 if (is_multicast_ether_addr(mgmt->da))
3328 return RX_DROP_MONITOR;
3329
Johannes Berg84040802010-02-15 12:46:39 +02003330 /* do not return rejected action frames */
3331 if (mgmt->u.action.category & 0x80)
3332 return RX_DROP_UNUSABLE;
3333
3334 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3335 GFP_ATOMIC);
3336 if (nskb) {
John W. Linville292b4df2010-06-24 11:13:56 -04003337 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
Johannes Berg84040802010-02-15 12:46:39 +02003338
John W. Linville292b4df2010-06-24 11:13:56 -04003339 nmgmt->u.action.category |= 0x80;
3340 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3341 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
Johannes Berg84040802010-02-15 12:46:39 +02003342
3343 memset(nskb->cb, 0, sizeof(nskb->cb));
3344
Johannes Berg07e5a5f2013-03-07 13:22:05 +01003345 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3346 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3347
3348 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3349 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3350 IEEE80211_TX_CTL_NO_CCK_RATE;
Johannes Berg30686bf2015-06-02 21:39:54 +02003351 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
Johannes Berg07e5a5f2013-03-07 13:22:05 +01003352 info->hw_queue =
3353 local->hw.offchannel_tx_hw_queue;
3354 }
3355
3356 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
Johannes Bergb9771d42018-05-28 15:47:41 +02003357 status->band, 0);
Johannes Bergde1ede72008-09-09 14:42:50 +02003358 }
Johannes Berg39192c02008-09-09 14:49:03 +02003359 dev_kfree_skb(rx->skb);
3360 return RX_QUEUED;
Johannes Bergde1ede72008-09-09 14:42:50 +02003361}
3362
3363static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01003364ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02003365{
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01003366 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg77a121c2010-06-10 10:21:34 +02003367 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3368 __le16 stype;
Johannes Berg571ecf62007-07-27 15:43:22 +02003369
Johannes Berg77a121c2010-06-10 10:21:34 +02003370 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
Johannes Berg472dbc42008-09-11 00:01:49 +02003371
Johannes Berg77a121c2010-06-10 10:21:34 +02003372 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3373 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003374 sdata->vif.type != NL80211_IFTYPE_OCB &&
Johannes Berg77a121c2010-06-10 10:21:34 +02003375 sdata->vif.type != NL80211_IFTYPE_STATION)
3376 return RX_DROP_MONITOR;
Johannes Bergf9d540e2007-09-28 14:02:09 +02003377
Johannes Berg77a121c2010-06-10 10:21:34 +02003378 switch (stype) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003379 case cpu_to_le16(IEEE80211_STYPE_AUTH):
Johannes Berg77a121c2010-06-10 10:21:34 +02003380 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3381 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3382 /* process for all: mesh, mlme, ibss */
3383 break;
Johannes Berg66e67e42012-01-20 13:55:27 +01003384 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3385 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
Johannes Berg77a121c2010-06-10 10:21:34 +02003386 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3387 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
Christian Lamparter2c313332010-11-29 20:53:23 +01003388 if (is_multicast_ether_addr(mgmt->da) &&
3389 !is_broadcast_ether_addr(mgmt->da))
3390 return RX_DROP_MONITOR;
3391
Johannes Berg77a121c2010-06-10 10:21:34 +02003392 /* process only for station */
3393 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3394 return RX_DROP_MONITOR;
3395 break;
3396 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
Thomas Pedersen9fb04b52013-02-14 11:20:14 -08003397 /* process only for ibss and mesh */
3398 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3399 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Johannes Berg77a121c2010-06-10 10:21:34 +02003400 return RX_DROP_MONITOR;
3401 break;
3402 default:
3403 return RX_DROP_MONITOR;
3404 }
Johannes Berg46900292009-02-15 12:44:28 +01003405
Johannes Berg77a121c2010-06-10 10:21:34 +02003406 /* queue up frame and kick off work to process it */
3407 skb_queue_tail(&sdata->skb_queue, rx->skb);
3408 ieee80211_queue_work(&rx->local->hw, &sdata->work);
Johannes Berg8b58ff82010-06-10 10:21:51 +02003409 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003410 rx->sta->rx_stats.packets++;
Johannes Berg77a121c2010-06-10 10:21:34 +02003411
3412 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02003413}
3414
Johannes Berg5f0b7de2009-11-16 13:58:21 +01003415static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3416 struct ieee80211_rate *rate)
Michael Wu3d30d942008-01-31 19:48:27 +01003417{
3418 struct ieee80211_sub_if_data *sdata;
3419 struct ieee80211_local *local = rx->local;
Michael Wu3d30d942008-01-31 19:48:27 +01003420 struct sk_buff *skb = rx->skb, *skb2;
3421 struct net_device *prev_dev = NULL;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01003422 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg293702a2012-03-02 13:18:19 +01003423 int needed_headroom;
Michael Wu3d30d942008-01-31 19:48:27 +01003424
Johannes Berg554891e2010-09-24 12:38:25 +02003425 /*
3426 * If cooked monitor has been processed already, then
3427 * don't do it again. If not, set the flag.
3428 */
3429 if (rx->flags & IEEE80211_RX_CMNTR)
John W. Linville7c1e1832010-09-24 15:52:49 -04003430 goto out_free_skb;
Johannes Berg554891e2010-09-24 12:38:25 +02003431 rx->flags |= IEEE80211_RX_CMNTR;
John W. Linville7c1e1832010-09-24 15:52:49 -04003432
Johannes Berg152c4772011-10-21 10:22:22 +02003433 /* If there are no cooked monitor interfaces, just free the SKB */
3434 if (!local->cooked_mntrs)
3435 goto out_free_skb;
3436
Johannes Berg1f7bba72014-11-06 22:56:36 +01003437 /* vendor data is long removed here */
3438 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
Johannes Berg293702a2012-03-02 13:18:19 +01003439 /* room for the radiotap header based on driver features */
Johannes Berg1f7bba72014-11-06 22:56:36 +01003440 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
Johannes Berg293702a2012-03-02 13:18:19 +01003441
3442 if (skb_headroom(skb) < needed_headroom &&
3443 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
Michael Wu3d30d942008-01-31 19:48:27 +01003444 goto out_free_skb;
3445
Johannes Berg293702a2012-03-02 13:18:19 +01003446 /* prepend radiotap information */
Felix Fietkau973ef212012-04-16 14:56:48 +02003447 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3448 false);
Michael Wu3d30d942008-01-31 19:48:27 +01003449
Zhang Shengjud57a5442016-03-03 01:16:56 +00003450 skb_reset_mac_header(skb);
Michael Wu3d30d942008-01-31 19:48:27 +01003451 skb->ip_summed = CHECKSUM_UNNECESSARY;
3452 skb->pkt_type = PACKET_OTHERHOST;
3453 skb->protocol = htons(ETH_P_802_2);
3454
3455 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01003456 if (!ieee80211_sdata_running(sdata))
Michael Wu3d30d942008-01-31 19:48:27 +01003457 continue;
3458
Johannes Berg05c914f2008-09-11 00:01:58 +02003459 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
Aviya Erenfeldd8212182016-08-29 23:25:15 +03003460 !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
Michael Wu3d30d942008-01-31 19:48:27 +01003461 continue;
3462
3463 if (prev_dev) {
3464 skb2 = skb_clone(skb, GFP_ATOMIC);
3465 if (skb2) {
3466 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04003467 netif_receive_skb(skb2);
Michael Wu3d30d942008-01-31 19:48:27 +01003468 }
3469 }
3470
3471 prev_dev = sdata->dev;
Johannes Berg5a490512015-04-22 17:10:38 +02003472 ieee80211_rx_stats(sdata->dev, skb->len);
Michael Wu3d30d942008-01-31 19:48:27 +01003473 }
3474
3475 if (prev_dev) {
3476 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04003477 netif_receive_skb(skb);
Johannes Berg554891e2010-09-24 12:38:25 +02003478 return;
3479 }
Michael Wu3d30d942008-01-31 19:48:27 +01003480
3481 out_free_skb:
3482 dev_kfree_skb(skb);
3483}
3484
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003485static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3486 ieee80211_rx_result res)
3487{
3488 switch (res) {
3489 case RX_DROP_MONITOR:
3490 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3491 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003492 rx->sta->rx_stats.dropped++;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003493 /* fall through */
3494 case RX_CONTINUE: {
3495 struct ieee80211_rate *rate = NULL;
3496 struct ieee80211_supported_band *sband;
3497 struct ieee80211_rx_status *status;
3498
3499 status = IEEE80211_SKB_RXCB((rx->skb));
3500
3501 sband = rx->local->hw.wiphy->bands[status->band];
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003502 if (status->encoding == RX_ENC_LEGACY)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003503 rate = &sband->bitrates[status->rate_idx];
3504
3505 ieee80211_rx_cooked_monitor(rx, rate);
3506 break;
3507 }
3508 case RX_DROP_UNUSABLE:
3509 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3510 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003511 rx->sta->rx_stats.dropped++;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003512 dev_kfree_skb(rx->skb);
3513 break;
3514 case RX_QUEUED:
3515 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3516 break;
3517 }
3518}
3519
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003520static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3521 struct sk_buff_head *frames)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003522{
3523 ieee80211_rx_result res = RX_DROP_MONITOR;
3524 struct sk_buff *skb;
3525
3526#define CALL_RXH(rxh) \
3527 do { \
3528 res = rxh(rx); \
3529 if (res != RX_CONTINUE) \
3530 goto rxh_next; \
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003531 } while (0)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003532
Johannes Berg45ceeee2015-03-16 09:08:20 +01003533 /* Lock here to avoid hitting all of the data used in the RX
3534 * path (e.g. key data, station data, ...) concurrently when
3535 * a frame is released from the reorder buffer due to timeout
3536 * from the timer, potentially concurrently with RX from the
3537 * driver.
3538 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003539 spin_lock_bh(&rx->local->rx_path_lock);
Christian Lamparter24a8fda2010-12-30 17:25:29 +01003540
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003541 while ((skb = __skb_dequeue(frames))) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003542 /*
3543 * all the other fields are valid across frames
3544 * that belong to an aMPDU since they are on the
3545 * same TID from the same station
3546 */
3547 rx->skb = skb;
3548
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003549 CALL_RXH(ieee80211_rx_h_check_more_data);
3550 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3551 CALL_RXH(ieee80211_rx_h_sta_process);
3552 CALL_RXH(ieee80211_rx_h_decrypt);
3553 CALL_RXH(ieee80211_rx_h_defragment);
3554 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003555 /* must be after MMIC verify so header is counted in MPDU mic */
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003556#ifdef CONFIG_MAC80211_MESH
3557 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3558 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3559#endif
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003560 CALL_RXH(ieee80211_rx_h_amsdu);
3561 CALL_RXH(ieee80211_rx_h_data);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003562
3563 /* special treatment -- needs the queue */
3564 res = ieee80211_rx_h_ctrl(rx, frames);
3565 if (res != RX_CONTINUE)
3566 goto rxh_next;
3567
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003568 CALL_RXH(ieee80211_rx_h_mgmt_check);
3569 CALL_RXH(ieee80211_rx_h_action);
3570 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3571 CALL_RXH(ieee80211_rx_h_action_return);
3572 CALL_RXH(ieee80211_rx_h_mgmt);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003573
3574 rxh_next:
3575 ieee80211_rx_handlers_result(rx, res);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003576
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003577#undef CALL_RXH
3578 }
Christian Lamparter24a8fda2010-12-30 17:25:29 +01003579
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003580 spin_unlock_bh(&rx->local->rx_path_lock);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003581}
Johannes Berg571ecf62007-07-27 15:43:22 +02003582
Johannes Berg4406c372010-09-24 11:21:06 +02003583static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
Johannes Berg58905292008-01-31 19:48:25 +01003584{
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003585 struct sk_buff_head reorder_release;
Johannes Berg58905292008-01-31 19:48:25 +01003586 ieee80211_rx_result res = RX_DROP_MONITOR;
3587
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003588 __skb_queue_head_init(&reorder_release);
3589
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02003590#define CALL_RXH(rxh) \
3591 do { \
3592 res = rxh(rx); \
3593 if (res != RX_CONTINUE) \
Johannes Berg2569a822009-11-25 17:46:17 +01003594 goto rxh_next; \
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003595 } while (0)
Johannes Berg58905292008-01-31 19:48:25 +01003596
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003597 CALL_RXH(ieee80211_rx_h_check_dup);
3598 CALL_RXH(ieee80211_rx_h_check);
Johannes Berg2569a822009-11-25 17:46:17 +01003599
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003600 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
Johannes Berg2569a822009-11-25 17:46:17 +01003601
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003602 ieee80211_rx_handlers(rx, &reorder_release);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003603 return;
Johannes Berg49461622008-06-30 15:10:45 +02003604
Johannes Berg2569a822009-11-25 17:46:17 +01003605 rxh_next:
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003606 ieee80211_rx_handlers_result(rx, res);
3607
3608#undef CALL_RXH
Johannes Berg58905292008-01-31 19:48:25 +01003609}
3610
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003611/*
Johannes Bergdd318572010-11-29 11:09:16 +01003612 * This function makes calls into the RX path, therefore
3613 * it has to be invoked under RCU read lock.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003614 */
3615void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3616{
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003617 struct sk_buff_head frames;
Johannes Berg554891e2010-09-24 12:38:25 +02003618 struct ieee80211_rx_data rx = {
3619 .sta = sta,
3620 .sdata = sta->sdata,
3621 .local = sta->local,
Johannes Berg9e262972011-07-07 18:45:03 +02003622 /* This is OK -- must be QoS data frame */
3623 .security_idx = tid,
3624 .seqno_idx = tid,
Johannes Bergaf9f9b22015-06-11 16:02:32 +02003625 .napi = NULL, /* must be NULL to not have races */
Johannes Berg554891e2010-09-24 12:38:25 +02003626 };
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003627 struct tid_ampdu_rx *tid_agg_rx;
3628
3629 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3630 if (!tid_agg_rx)
3631 return;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003632
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003633 __skb_queue_head_init(&frames);
3634
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003635 spin_lock(&tid_agg_rx->reorder_lock);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003636 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003637 spin_unlock(&tid_agg_rx->reorder_lock);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003638
Emmanuel Grumbachb497de62015-04-20 22:53:38 +03003639 if (!skb_queue_empty(&frames)) {
3640 struct ieee80211_event event = {
3641 .type = BA_FRAME_TIMEOUT,
3642 .u.ba.tid = tid,
3643 .u.ba.sta = &sta->sta,
3644 };
3645 drv_event_callback(rx.local, rx.sdata, &event);
3646 }
3647
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003648 ieee80211_rx_handlers(&rx, &frames);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003649}
3650
Sara Sharon06470f72016-01-28 16:19:25 +02003651void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3652 u16 ssn, u64 filtered,
3653 u16 received_mpdus)
3654{
3655 struct sta_info *sta;
3656 struct tid_ampdu_rx *tid_agg_rx;
3657 struct sk_buff_head frames;
3658 struct ieee80211_rx_data rx = {
3659 /* This is OK -- must be QoS data frame */
3660 .security_idx = tid,
3661 .seqno_idx = tid,
3662 };
3663 int i, diff;
3664
3665 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3666 return;
3667
3668 __skb_queue_head_init(&frames);
3669
3670 sta = container_of(pubsta, struct sta_info, sta);
3671
3672 rx.sta = sta;
3673 rx.sdata = sta->sdata;
3674 rx.local = sta->local;
3675
3676 rcu_read_lock();
3677 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3678 if (!tid_agg_rx)
3679 goto out;
3680
3681 spin_lock_bh(&tid_agg_rx->reorder_lock);
3682
3683 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3684 int release;
3685
3686 /* release all frames in the reorder buffer */
3687 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3688 IEEE80211_SN_MODULO;
3689 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3690 release, &frames);
3691 /* update ssn to match received ssn */
3692 tid_agg_rx->head_seq_num = ssn;
3693 } else {
3694 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3695 &frames);
3696 }
3697
3698 /* handle the case that received ssn is behind the mac ssn.
3699 * it can be tid_agg_rx->buf_size behind and still be valid */
3700 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3701 if (diff >= tid_agg_rx->buf_size) {
3702 tid_agg_rx->reorder_buf_filtered = 0;
3703 goto release;
3704 }
3705 filtered = filtered >> diff;
3706 ssn += diff;
3707
3708 /* update bitmap */
3709 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3710 int index = (ssn + i) % tid_agg_rx->buf_size;
3711
3712 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3713 if (filtered & BIT_ULL(i))
3714 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3715 }
3716
3717 /* now process also frames that the filter marking released */
3718 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3719
3720release:
3721 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3722
3723 ieee80211_rx_handlers(&rx, &frames);
3724
3725 out:
3726 rcu_read_unlock();
3727}
3728EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3729
Johannes Berg571ecf62007-07-27 15:43:22 +02003730/* main receive path */
3731
Johannes Berga58fbe12015-04-22 15:08:39 +02003732static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
Johannes Berg23a24de2007-07-27 15:43:22 +02003733{
Johannes Berg20b01f82010-09-24 11:21:05 +02003734 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01003735 struct sk_buff *skb = rx->skb;
Johannes Berga58fbe12015-04-22 15:08:39 +02003736 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01003737 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3738 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
Luca Coelhoe5f2e062017-04-26 10:58:54 +03003739 bool multicast = is_multicast_ether_addr(hdr->addr1);
Johannes Berg23a24de2007-07-27 15:43:22 +02003740
Johannes Berg51fb61e2007-12-19 01:31:27 +01003741 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003742 case NL80211_IFTYPE_STATION:
Johannes Berg9bc383d2009-11-19 11:55:19 +01003743 if (!bssid && !sdata->u.mgd.use_4addr)
Johannes Berg3c2723f52014-01-07 16:23:24 +01003744 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003745 if (multicast)
3746 return true;
3747 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
Johannes Berg05c914f2008-09-11 00:01:58 +02003748 case NL80211_IFTYPE_ADHOC:
Johannes Berg23a24de2007-07-27 15:43:22 +02003749 if (!bssid)
Johannes Berg3c2723f52014-01-07 16:23:24 +01003750 return false;
Felix Fietkau6329b8d2013-09-17 11:15:43 +02003751 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3752 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003753 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003754 if (ieee80211_is_beacon(hdr->frame_control))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003755 return true;
Johannes Berga58fbe12015-04-22 15:08:39 +02003756 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003757 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003758 if (!multicast &&
3759 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
Johannes Bergdf140462015-04-22 14:40:58 +02003760 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003761 if (!rx->sta) {
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003762 int rate_idx;
Johannes Bergda6a4352017-04-26 12:14:59 +02003763 if (status->encoding != RX_ENC_LEGACY)
Johannes Berg56146182012-11-09 15:07:02 +01003764 rate_idx = 0; /* TODO: HT/VHT rates */
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003765 else
Johannes Bergeb9fb5b82009-11-16 13:58:20 +01003766 rate_idx = status->rate_idx;
Johannes Berg8bf11d82011-12-15 11:17:37 +01003767 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3768 BIT(rate_idx));
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003769 }
Johannes Berga58fbe12015-04-22 15:08:39 +02003770 return true;
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003771 case NL80211_IFTYPE_OCB:
3772 if (!bssid)
3773 return false;
Bertold Van den Berghcc117292015-08-05 16:02:42 +02003774 if (!ieee80211_is_data_present(hdr->frame_control))
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003775 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003776 if (!is_broadcast_ether_addr(bssid))
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003777 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003778 if (!multicast &&
3779 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
Johannes Bergdf140462015-04-22 14:40:58 +02003780 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003781 if (!rx->sta) {
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003782 int rate_idx;
Johannes Bergda6a4352017-04-26 12:14:59 +02003783 if (status->encoding != RX_ENC_LEGACY)
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003784 rate_idx = 0; /* TODO: HT rates */
3785 else
3786 rate_idx = status->rate_idx;
3787 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3788 BIT(rate_idx));
3789 }
Johannes Berga58fbe12015-04-22 15:08:39 +02003790 return true;
Johannes Berg05c914f2008-09-11 00:01:58 +02003791 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg736a80b2018-01-04 15:51:53 +01003792 if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
3793 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003794 if (multicast)
3795 return true;
3796 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
Johannes Berg05c914f2008-09-11 00:01:58 +02003797 case NL80211_IFTYPE_AP_VLAN:
3798 case NL80211_IFTYPE_AP:
Johannes Berga58fbe12015-04-22 15:08:39 +02003799 if (!bssid)
3800 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3801
3802 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
Johannes Berg3df6eae2011-12-06 10:39:40 +01003803 /*
3804 * Accept public action frames even when the
3805 * BSSID doesn't match, this is used for P2P
3806 * and location updates. Note that mac80211
3807 * itself never looks at these frames.
3808 */
Johannes Berg2b9ccd42013-05-13 16:42:40 +02003809 if (!multicast &&
3810 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003811 return false;
Johannes Bergd48b2962012-07-06 22:19:27 +02003812 if (ieee80211_is_public_action(hdr, skb->len))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003813 return true;
Johannes Berg5c900672015-04-22 14:48:34 +02003814 return ieee80211_is_beacon(hdr->frame_control);
Johannes Berga58fbe12015-04-22 15:08:39 +02003815 }
3816
3817 if (!ieee80211_has_tods(hdr->frame_control)) {
Arik Nemtsovdb8e1732014-07-17 17:14:30 +03003818 /* ignore data frames to TDLS-peers */
3819 if (ieee80211_is_data(hdr->frame_control))
3820 return false;
3821 /* ignore action frames to TDLS-peers */
3822 if (ieee80211_is_action(hdr->frame_control) &&
Jouni Malinen1ec7bae2016-03-01 00:29:00 +02003823 !is_broadcast_ether_addr(bssid) &&
Arik Nemtsovdb8e1732014-07-17 17:14:30 +03003824 !ether_addr_equal(bssid, hdr->addr1))
3825 return false;
Johannes Berg23a24de2007-07-27 15:43:22 +02003826 }
Johannes Berg3018e942017-04-20 21:32:16 +02003827
3828 /*
3829 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3830 * the BSSID - we've checked that already but may have accepted
3831 * the wildcard (ff:ff:ff:ff:ff:ff).
3832 *
3833 * It also says:
3834 * The BSSID of the Data frame is determined as follows:
3835 * a) If the STA is contained within an AP or is associated
3836 * with an AP, the BSSID is the address currently in use
3837 * by the STA contained in the AP.
3838 *
3839 * So we should not accept data frames with an address that's
3840 * multicast.
3841 *
3842 * Accepting it also opens a security problem because stations
3843 * could encrypt it with the GTK and inject traffic that way.
3844 */
3845 if (ieee80211_is_data(hdr->frame_control) && multicast)
3846 return false;
3847
Johannes Berga58fbe12015-04-22 15:08:39 +02003848 return true;
Johannes Berg05c914f2008-09-11 00:01:58 +02003849 case NL80211_IFTYPE_WDS:
Harvey Harrisona7767f92008-07-02 16:30:51 -07003850 if (bssid || !ieee80211_is_data(hdr->frame_control))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003851 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003852 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
Johannes Bergf142c6b2012-06-18 20:07:15 +02003853 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berga58fbe12015-04-22 15:08:39 +02003854 return ieee80211_is_public_action(hdr, skb->len) ||
3855 ieee80211_is_probe_req(hdr->frame_control) ||
3856 ieee80211_is_probe_resp(hdr->frame_control) ||
3857 ieee80211_is_beacon(hdr->frame_control);
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003858 case NL80211_IFTYPE_NAN:
3859 /* Currently no frames on NAN interface are allowed */
3860 return false;
Johannes Berg2ca27bc2010-09-16 14:58:23 +02003861 default:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02003862 break;
Johannes Berg23a24de2007-07-27 15:43:22 +02003863 }
3864
Johannes Berga58fbe12015-04-22 15:08:39 +02003865 WARN_ON_ONCE(1);
3866 return false;
Johannes Berg23a24de2007-07-27 15:43:22 +02003867}
3868
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003869void ieee80211_check_fast_rx(struct sta_info *sta)
3870{
3871 struct ieee80211_sub_if_data *sdata = sta->sdata;
3872 struct ieee80211_local *local = sdata->local;
3873 struct ieee80211_key *key;
3874 struct ieee80211_fast_rx fastrx = {
3875 .dev = sdata->dev,
3876 .vif_type = sdata->vif.type,
3877 .control_port_protocol = sdata->control_port_protocol,
3878 }, *old, *new = NULL;
3879 bool assign = false;
3880
3881 /* use sparse to check that we don't return without updating */
3882 __acquire(check_fast_rx);
3883
3884 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
3885 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
3886 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
3887 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
3888
Johannes Bergc9c59622016-03-31 20:02:11 +03003889 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
3890
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003891 /* fast-rx doesn't do reordering */
3892 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
3893 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
3894 goto clear;
3895
3896 switch (sdata->vif.type) {
3897 case NL80211_IFTYPE_STATION:
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003898 if (sta->sta.tdls) {
3899 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3900 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3901 fastrx.expected_ds_bits = 0;
3902 } else {
3903 fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
3904 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3905 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3906 fastrx.expected_ds_bits =
3907 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3908 }
Felix Fietkau1d870162018-02-23 10:06:05 +01003909
Felix Fietkau9251a472018-02-23 13:55:50 +01003910 if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
3911 fastrx.expected_ds_bits |=
3912 cpu_to_le16(IEEE80211_FCTL_TODS);
3913 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3914 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3915 }
3916
Felix Fietkau1d870162018-02-23 10:06:05 +01003917 if (!sdata->u.mgd.powersave)
3918 break;
3919
3920 /* software powersave is a huge mess, avoid all of it */
3921 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
3922 goto clear;
3923 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3924 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3925 goto clear;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003926 break;
3927 case NL80211_IFTYPE_AP_VLAN:
3928 case NL80211_IFTYPE_AP:
3929 /* parallel-rx requires this, at least with calls to
3930 * ieee80211_sta_ps_transition()
3931 */
3932 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
3933 goto clear;
3934 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3935 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3936 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
3937
3938 fastrx.internal_forward =
3939 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
3940 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
3941 !sdata->u.vlan.sta);
Felix Fietkau59cae5b2018-02-23 10:06:04 +01003942
3943 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3944 sdata->u.vlan.sta) {
3945 fastrx.expected_ds_bits |=
3946 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3947 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3948 fastrx.internal_forward = 0;
3949 }
3950
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003951 break;
3952 default:
3953 goto clear;
3954 }
3955
3956 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3957 goto clear;
3958
3959 rcu_read_lock();
3960 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
3961 if (key) {
3962 switch (key->conf.cipher) {
3963 case WLAN_CIPHER_SUITE_TKIP:
3964 /* we don't want to deal with MMIC in fast-rx */
3965 goto clear_rcu;
3966 case WLAN_CIPHER_SUITE_CCMP:
3967 case WLAN_CIPHER_SUITE_CCMP_256:
3968 case WLAN_CIPHER_SUITE_GCMP:
3969 case WLAN_CIPHER_SUITE_GCMP_256:
3970 break;
3971 default:
3972 /* we also don't want to deal with WEP or cipher scheme
3973 * since those require looking up the key idx in the
3974 * frame, rather than assuming the PTK is used
3975 * (we need to revisit this once we implement the real
3976 * PTK index, which is now valid in the spec, but we
3977 * haven't implemented that part yet)
3978 */
3979 goto clear_rcu;
3980 }
3981
3982 fastrx.key = true;
3983 fastrx.icv_len = key->conf.icv_len;
3984 }
3985
3986 assign = true;
3987 clear_rcu:
3988 rcu_read_unlock();
3989 clear:
3990 __release(check_fast_rx);
3991
3992 if (assign)
3993 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
3994
3995 spin_lock_bh(&sta->lock);
3996 old = rcu_dereference_protected(sta->fast_rx, true);
3997 rcu_assign_pointer(sta->fast_rx, new);
3998 spin_unlock_bh(&sta->lock);
3999
4000 if (old)
4001 kfree_rcu(old, rcu_head);
4002}
4003
4004void ieee80211_clear_fast_rx(struct sta_info *sta)
4005{
4006 struct ieee80211_fast_rx *old;
4007
4008 spin_lock_bh(&sta->lock);
4009 old = rcu_dereference_protected(sta->fast_rx, true);
4010 RCU_INIT_POINTER(sta->fast_rx, NULL);
4011 spin_unlock_bh(&sta->lock);
4012
4013 if (old)
4014 kfree_rcu(old, rcu_head);
4015}
4016
4017void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4018{
4019 struct ieee80211_local *local = sdata->local;
4020 struct sta_info *sta;
4021
4022 lockdep_assert_held(&local->sta_mtx);
4023
4024 list_for_each_entry_rcu(sta, &local->sta_list, list) {
4025 if (sdata != sta->sdata &&
4026 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4027 continue;
4028 ieee80211_check_fast_rx(sta);
4029 }
4030}
4031
4032void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4033{
4034 struct ieee80211_local *local = sdata->local;
4035
4036 mutex_lock(&local->sta_mtx);
4037 __ieee80211_check_fast_rx_iface(sdata);
4038 mutex_unlock(&local->sta_mtx);
4039}
4040
4041static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4042 struct ieee80211_fast_rx *fast_rx)
4043{
4044 struct sk_buff *skb = rx->skb;
4045 struct ieee80211_hdr *hdr = (void *)skb->data;
4046 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4047 struct sta_info *sta = rx->sta;
4048 int orig_len = skb->len;
Felix Fietkau24bba072018-02-27 13:03:07 +01004049 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4050 int snap_offs = hdrlen;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004051 struct {
4052 u8 snap[sizeof(rfc1042_header)];
4053 __be16 proto;
4054 } *payload __aligned(2);
4055 struct {
4056 u8 da[ETH_ALEN];
4057 u8 sa[ETH_ALEN];
4058 } addrs __aligned(2);
Johannes Bergc9c59622016-03-31 20:02:11 +03004059 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
4060
4061 if (fast_rx->uses_rss)
4062 stats = this_cpu_ptr(sta->pcpu_rx_stats);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004063
4064 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4065 * to a common data structure; drivers can implement that per queue
4066 * but we don't have that information in mac80211
4067 */
4068 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4069 return false;
4070
4071#define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4072
4073 /* If using encryption, we also need to have:
4074 * - PN_VALIDATED: similar, but the implementation is tricky
4075 * - DECRYPTED: necessary for PN_VALIDATED
4076 */
4077 if (fast_rx->key &&
4078 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4079 return false;
4080
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004081 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4082 return false;
4083
4084 if (unlikely(ieee80211_is_frag(hdr)))
4085 return false;
4086
4087 /* Since our interface address cannot be multicast, this
4088 * implicitly also rejects multicast frames without the
4089 * explicit check.
4090 *
4091 * We shouldn't get any *data* frames not addressed to us
4092 * (AP mode will accept multicast *management* frames), but
4093 * punting here will make it go through the full checks in
4094 * ieee80211_accept_frame().
4095 */
4096 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4097 return false;
4098
4099 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4100 IEEE80211_FCTL_TODS)) !=
4101 fast_rx->expected_ds_bits)
Felix Fietkaub323ac12018-02-23 10:06:03 +01004102 return false;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004103
4104 /* assign the key to drop unencrypted frames (later)
4105 * and strip the IV/MIC if necessary
4106 */
4107 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4108 /* GCMP header length is the same */
4109 snap_offs += IEEE80211_CCMP_HDR_LEN;
4110 }
4111
Felix Fietkau24bba072018-02-27 13:03:07 +01004112 if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4113 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4114 goto drop;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004115
Felix Fietkau24bba072018-02-27 13:03:07 +01004116 payload = (void *)(skb->data + snap_offs);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004117
Felix Fietkau24bba072018-02-27 13:03:07 +01004118 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4119 return false;
4120
4121 /* Don't handle these here since they require special code.
4122 * Accept AARP and IPX even though they should come with a
4123 * bridge-tunnel header - but if we get them this way then
4124 * there's little point in discarding them.
4125 */
4126 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4127 payload->proto == fast_rx->control_port_protocol))
4128 return false;
4129 }
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004130
4131 /* after this point, don't punt to the slowpath! */
4132
4133 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4134 pskb_trim(skb, skb->len - fast_rx->icv_len))
4135 goto drop;
4136
4137 if (unlikely(fast_rx->sta_notify)) {
4138 ieee80211_sta_rx_notify(rx->sdata, hdr);
4139 fast_rx->sta_notify = false;
4140 }
4141
4142 /* statistics part of ieee80211_rx_h_sta_process() */
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004143 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
Johannes Bergc9c59622016-03-31 20:02:11 +03004144 stats->last_signal = status->signal;
4145 if (!fast_rx->uses_rss)
4146 ewma_signal_add(&sta->rx_stats_avg.signal,
4147 -status->signal);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004148 }
4149
4150 if (status->chains) {
4151 int i;
4152
Johannes Bergc9c59622016-03-31 20:02:11 +03004153 stats->chains = status->chains;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004154 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4155 int signal = status->chain_signal[i];
4156
4157 if (!(status->chains & BIT(i)))
4158 continue;
4159
Johannes Bergc9c59622016-03-31 20:02:11 +03004160 stats->chain_signal_last[i] = signal;
4161 if (!fast_rx->uses_rss)
4162 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4163 -signal);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004164 }
4165 }
4166 /* end of statistics */
4167
4168 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4169 goto drop;
4170
Felix Fietkau24bba072018-02-27 13:03:07 +01004171 if (status->rx_flags & IEEE80211_RX_AMSDU) {
4172 if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4173 RX_QUEUED)
4174 goto drop;
4175
4176 return true;
4177 }
4178
4179 stats->last_rx = jiffies;
4180 stats->last_rate = sta_stats_encode_rate(status);
4181
4182 stats->fragments++;
4183 stats->packets++;
4184
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004185 /* do the header conversion - first grab the addresses */
4186 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4187 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4188 /* remove the SNAP but leave the ethertype */
4189 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4190 /* push the addresses in front */
4191 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4192
4193 skb->dev = fast_rx->dev;
4194
4195 ieee80211_rx_stats(fast_rx->dev, skb->len);
4196
4197 /* The seqno index has the same property as needed
4198 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4199 * for non-QoS-data frames. Here we know it's a data
4200 * frame, so count MSDUs.
4201 */
Johannes Bergc9c59622016-03-31 20:02:11 +03004202 u64_stats_update_begin(&stats->syncp);
4203 stats->msdu[rx->seqno_idx]++;
4204 stats->bytes += orig_len;
4205 u64_stats_update_end(&stats->syncp);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004206
4207 if (fast_rx->internal_forward) {
Johannes Bergeeb0d562016-12-14 16:47:43 +01004208 struct sk_buff *xmit_skb = NULL;
4209 bool multicast = is_multicast_ether_addr(skb->data);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004210
Johannes Bergeeb0d562016-12-14 16:47:43 +01004211 if (multicast) {
4212 xmit_skb = skb_copy(skb, GFP_ATOMIC);
4213 } else if (sta_info_get(rx->sdata, skb->data)) {
4214 xmit_skb = skb;
4215 skb = NULL;
4216 }
4217
4218 if (xmit_skb) {
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004219 /*
4220 * Send to wireless media and increase priority by 256
4221 * to keep the received priority instead of
4222 * reclassifying the frame (see cfg80211_classify8021d).
4223 */
Johannes Bergeeb0d562016-12-14 16:47:43 +01004224 xmit_skb->priority += 256;
4225 xmit_skb->protocol = htons(ETH_P_802_3);
4226 skb_reset_network_header(xmit_skb);
4227 skb_reset_mac_header(xmit_skb);
4228 dev_queue_xmit(xmit_skb);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004229 }
Johannes Bergeeb0d562016-12-14 16:47:43 +01004230
4231 if (!skb)
4232 return true;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004233 }
4234
4235 /* deliver to local stack */
4236 skb->protocol = eth_type_trans(skb, fast_rx->dev);
4237 memset(skb->cb, 0, sizeof(skb->cb));
4238 if (rx->napi)
4239 napi_gro_receive(rx->napi, skb);
4240 else
4241 netif_receive_skb(skb);
4242
4243 return true;
4244 drop:
4245 dev_kfree_skb(skb);
Johannes Bergc9c59622016-03-31 20:02:11 +03004246 stats->dropped++;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004247 return true;
4248}
4249
Johannes Berg571ecf62007-07-27 15:43:22 +02004250/*
Johannes Berg4406c372010-09-24 11:21:06 +02004251 * This function returns whether or not the SKB
4252 * was destined for RX processing or not, which,
4253 * if consume is true, is equivalent to whether
4254 * or not the skb was consumed.
4255 */
4256static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4257 struct sk_buff *skb, bool consume)
4258{
4259 struct ieee80211_local *local = rx->local;
4260 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg4406c372010-09-24 11:21:06 +02004261
4262 rx->skb = skb;
Johannes Berg4406c372010-09-24 11:21:06 +02004263
Johannes Berg49ddf8e2016-03-31 20:02:10 +03004264 /* See if we can do fast-rx; if we have to copy we already lost,
4265 * so punt in that case. We should never have to deliver a data
4266 * frame to multiple interfaces anyway.
4267 *
4268 * We skip the ieee80211_accept_frame() call and do the necessary
4269 * checking inside ieee80211_invoke_fast_rx().
4270 */
4271 if (consume && rx->sta) {
4272 struct ieee80211_fast_rx *fast_rx;
4273
4274 fast_rx = rcu_dereference(rx->sta->fast_rx);
4275 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4276 return true;
4277 }
4278
Johannes Berga58fbe12015-04-22 15:08:39 +02004279 if (!ieee80211_accept_frame(rx))
Johannes Berg4406c372010-09-24 11:21:06 +02004280 return false;
4281
Johannes Berg4406c372010-09-24 11:21:06 +02004282 if (!consume) {
4283 skb = skb_copy(skb, GFP_ATOMIC);
4284 if (!skb) {
4285 if (net_ratelimit())
4286 wiphy_debug(local->hw.wiphy,
Ben Greearb305dae2011-01-08 10:30:54 -08004287 "failed to copy skb for %s\n",
Johannes Berg4406c372010-09-24 11:21:06 +02004288 sdata->name);
4289 return true;
4290 }
4291
4292 rx->skb = skb;
4293 }
4294
4295 ieee80211_invoke_rx_handlers(rx);
4296 return true;
4297}
4298
4299/*
Zhao, Gang6b59db72014-04-21 12:52:59 +08004300 * This is the actual Rx frames handler. as it belongs to Rx path it must
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004301 * be called with rcu_read_lock protection.
Johannes Berg571ecf62007-07-27 15:43:22 +02004302 */
Ron Rindjunsky71ebb4a2008-01-21 12:39:12 +02004303static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
Johannes Bergd63b5482016-03-31 20:02:02 +03004304 struct ieee80211_sta *pubsta,
Johannes Bergaf9f9b22015-06-11 16:02:32 +02004305 struct sk_buff *skb,
4306 struct napi_struct *napi)
Johannes Berg571ecf62007-07-27 15:43:22 +02004307{
4308 struct ieee80211_local *local = hw_to_local(hw);
4309 struct ieee80211_sub_if_data *sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02004310 struct ieee80211_hdr *hdr;
Zhu Yie3cf8b32010-03-29 17:35:07 +08004311 __le16 fc;
Johannes Berg5cf121c2008-02-25 16:27:43 +01004312 struct ieee80211_rx_data rx;
Johannes Berg4406c372010-09-24 11:21:06 +02004313 struct ieee80211_sub_if_data *prev;
Herbert Xu83e7e4c2016-09-19 19:00:10 +08004314 struct rhlist_head *tmp;
Zhu Yie3cf8b32010-03-29 17:35:07 +08004315 int err = 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02004316
Zhu Yie3cf8b32010-03-29 17:35:07 +08004317 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
Johannes Berg571ecf62007-07-27 15:43:22 +02004318 memset(&rx, 0, sizeof(rx));
4319 rx.skb = skb;
4320 rx.local = local;
Johannes Bergaf9f9b22015-06-11 16:02:32 +02004321 rx.napi = napi;
Johannes Berg72abd812007-09-17 01:29:22 -04004322
Zhu Yie3cf8b32010-03-29 17:35:07 +08004323 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
Johannes Bergc206ca62015-04-22 20:47:28 +02004324 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
Johannes Berg571ecf62007-07-27 15:43:22 +02004325
Johannes Berg4a4f1a52012-10-26 00:33:36 +02004326 if (ieee80211_is_mgmt(fc)) {
4327 /* drop frame if too short for header */
4328 if (skb->len < ieee80211_hdrlen(fc))
4329 err = -ENOBUFS;
4330 else
4331 err = skb_linearize(skb);
4332 } else {
Zhu Yie3cf8b32010-03-29 17:35:07 +08004333 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
Johannes Berg4a4f1a52012-10-26 00:33:36 +02004334 }
Zhu Yie3cf8b32010-03-29 17:35:07 +08004335
4336 if (err) {
4337 dev_kfree_skb(skb);
4338 return;
4339 }
4340
4341 hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg38f37142008-01-29 17:07:43 +01004342 ieee80211_parse_qos(&rx);
Johannes Bergd1c3a372009-01-07 00:26:10 +01004343 ieee80211_verify_alignment(&rx);
Johannes Berg38f37142008-01-29 17:07:43 +01004344
Johannes Bergd48b2962012-07-06 22:19:27 +02004345 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4346 ieee80211_is_beacon(hdr->frame_control)))
4347 ieee80211_scan_rx(local, skb);
4348
Johannes Berg19d19e92017-02-27 09:38:11 +01004349 if (ieee80211_is_data(fc)) {
Johannes Bergd63b5482016-03-31 20:02:02 +03004350 struct sta_info *sta, *prev_sta;
Johannes Berg7bedd0c2015-02-13 21:55:15 +01004351
Johannes Berg19d19e92017-02-27 09:38:11 +01004352 if (pubsta) {
4353 rx.sta = container_of(pubsta, struct sta_info, sta);
4354 rx.sdata = rx.sta->sdata;
4355 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4356 return;
4357 goto out;
4358 }
4359
Ben Greear56af3262010-09-23 10:22:24 -07004360 prev_sta = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02004361
Herbert Xu83e7e4c2016-09-19 19:00:10 +08004362 for_each_sta_info(local, hdr->addr2, sta, tmp) {
Ben Greear56af3262010-09-23 10:22:24 -07004363 if (!prev_sta) {
4364 prev_sta = sta;
4365 continue;
4366 }
4367
4368 rx.sta = prev_sta;
4369 rx.sdata = prev_sta->sdata;
Johannes Berg4406c372010-09-24 11:21:06 +02004370 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Johannes Berg571ecf62007-07-27 15:43:22 +02004371
Ben Greear56af3262010-09-23 10:22:24 -07004372 prev_sta = sta;
Johannes Berg4406c372010-09-24 11:21:06 +02004373 }
Ben Greear56af3262010-09-23 10:22:24 -07004374
4375 if (prev_sta) {
4376 rx.sta = prev_sta;
4377 rx.sdata = prev_sta->sdata;
4378
Johannes Berg4406c372010-09-24 11:21:06 +02004379 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
Ben Greear56af3262010-09-23 10:22:24 -07004380 return;
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05304381 goto out;
Ben Greear56af3262010-09-23 10:22:24 -07004382 }
Johannes Berg4406c372010-09-24 11:21:06 +02004383 }
4384
Johannes Berg4b0dd982010-09-24 11:21:07 +02004385 prev = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02004386
Johannes Berg4b0dd982010-09-24 11:21:07 +02004387 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4388 if (!ieee80211_sdata_running(sdata))
4389 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01004390
Johannes Berg4b0dd982010-09-24 11:21:07 +02004391 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4392 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4393 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01004394
Johannes Berg4b0dd982010-09-24 11:21:07 +02004395 /*
4396 * frame is destined for this interface, but if it's
4397 * not also for the previous one we handle that after
4398 * the loop to avoid copying the SKB once too much
4399 */
Johannes Bergb2e77712007-09-26 15:19:39 +02004400
Johannes Berg4b0dd982010-09-24 11:21:07 +02004401 if (!prev) {
Johannes Berg340e11f2007-07-27 15:43:22 +02004402 prev = sdata;
Johannes Berg4b0dd982010-09-24 11:21:07 +02004403 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02004404 }
Felix Fietkau4bb29f82010-01-22 00:36:39 +01004405
Johannes Berg7852e362012-01-20 13:55:24 +01004406 rx.sta = sta_info_get_bss(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02004407 rx.sdata = prev;
4408 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Felix Fietkau4bb29f82010-01-22 00:36:39 +01004409
Johannes Berg4b0dd982010-09-24 11:21:07 +02004410 prev = sdata;
4411 }
Johannes Berg4406c372010-09-24 11:21:06 +02004412
Johannes Berg4b0dd982010-09-24 11:21:07 +02004413 if (prev) {
Johannes Berg7852e362012-01-20 13:55:24 +01004414 rx.sta = sta_info_get_bss(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02004415 rx.sdata = prev;
4416
4417 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4418 return;
Johannes Berg571ecf62007-07-27 15:43:22 +02004419 }
Johannes Berg4406c372010-09-24 11:21:06 +02004420
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05304421 out:
Johannes Berg4406c372010-09-24 11:21:06 +02004422 dev_kfree_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02004423}
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004424
4425/*
4426 * This is the receive path handler. It is called by a low level driver when an
4427 * 802.11 MPDU is received from the hardware.
4428 */
Johannes Bergd63b5482016-03-31 20:02:02 +03004429void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4430 struct sk_buff *skb, struct napi_struct *napi)
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004431{
4432 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg8318d782008-01-24 19:38:38 +01004433 struct ieee80211_rate *rate = NULL;
4434 struct ieee80211_supported_band *sband;
Johannes Bergf1d58c22009-06-17 13:13:00 +02004435 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg8318d782008-01-24 19:38:38 +01004436
Johannes Bergd20ef632009-10-11 15:10:40 +02004437 WARN_ON_ONCE(softirq_count() == 0);
4438
Johannes Berg57fbcce2016-04-12 15:56:15 +02004439 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
Johannes Berg77a980d2009-08-24 11:46:30 +02004440 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01004441
4442 sband = local->hw.wiphy->bands[status->band];
Johannes Berg77a980d2009-08-24 11:46:30 +02004443 if (WARN_ON(!sband))
4444 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01004445
Johannes Berg89c3a8a2009-07-28 18:10:17 +02004446 /*
4447 * If we're suspending, it is possible although not too likely
4448 * that we'd be receiving frames after having already partially
4449 * quiesced the stack. We can't process such frames then since
4450 * that might, for example, cause stations to be added or other
4451 * driver callbacks be invoked.
4452 */
Johannes Berg77a980d2009-08-24 11:46:30 +02004453 if (unlikely(local->quiescing || local->suspended))
4454 goto drop;
Johannes Berg89c3a8a2009-07-28 18:10:17 +02004455
Arik Nemtsov04800ad2012-06-06 11:25:02 +03004456 /* We might be during a HW reconfig, prevent Rx for the same reason */
4457 if (unlikely(local->in_reconfig))
4458 goto drop;
4459
Johannes Bergea77f122009-08-21 14:44:45 +02004460 /*
4461 * The same happens when we're not even started,
4462 * but that's worth a warning.
4463 */
Johannes Berg77a980d2009-08-24 11:46:30 +02004464 if (WARN_ON(!local->started))
4465 goto drop;
Johannes Bergea77f122009-08-21 14:44:45 +02004466
Johannes Bergfc885182010-07-30 13:23:12 +02004467 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05004468 /*
Johannes Bergfc885182010-07-30 13:23:12 +02004469 * Validate the rate, unless a PLCP error means that
4470 * we probably can't have a valid rate here anyway.
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05004471 */
Johannes Bergfc885182010-07-30 13:23:12 +02004472
Johannes Bergda6a4352017-04-26 12:14:59 +02004473 switch (status->encoding) {
4474 case RX_ENC_HT:
Johannes Bergfc885182010-07-30 13:23:12 +02004475 /*
4476 * rate_idx is MCS index, which can be [0-76]
4477 * as documented on:
4478 *
4479 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4480 *
4481 * Anything else would be some sort of driver or
4482 * hardware error. The driver should catch hardware
4483 * errors.
4484 */
Johannes Berg444e3802012-09-30 17:08:35 +02004485 if (WARN(status->rate_idx > 76,
Johannes Bergfc885182010-07-30 13:23:12 +02004486 "Rate marked as an HT rate but passed "
4487 "status->rate_idx is not "
4488 "an MCS index [0-76]: %d (0x%02x)\n",
4489 status->rate_idx,
4490 status->rate_idx))
4491 goto drop;
Johannes Bergda6a4352017-04-26 12:14:59 +02004492 break;
4493 case RX_ENC_VHT:
Johannes Berg56146182012-11-09 15:07:02 +01004494 if (WARN_ONCE(status->rate_idx > 9 ||
Johannes Berg8613c942017-04-26 13:51:41 +02004495 !status->nss ||
4496 status->nss > 8,
Johannes Berg56146182012-11-09 15:07:02 +01004497 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
Johannes Berg8613c942017-04-26 13:51:41 +02004498 status->rate_idx, status->nss))
Johannes Berg56146182012-11-09 15:07:02 +01004499 goto drop;
Johannes Bergda6a4352017-04-26 12:14:59 +02004500 break;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004501 case RX_ENC_HE:
4502 if (WARN_ONCE(status->rate_idx > 11 ||
4503 !status->nss ||
4504 status->nss > 8,
4505 "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4506 status->rate_idx, status->nss))
4507 goto drop;
4508 break;
Johannes Bergda6a4352017-04-26 12:14:59 +02004509 default:
4510 WARN_ON_ONCE(1);
4511 /* fall through */
4512 case RX_ENC_LEGACY:
Johannes Berg444e3802012-09-30 17:08:35 +02004513 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
Johannes Bergfc885182010-07-30 13:23:12 +02004514 goto drop;
4515 rate = &sband->bitrates[status->rate_idx];
4516 }
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02004517 }
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004518
Johannes Berg554891e2010-09-24 12:38:25 +02004519 status->rx_flags = 0;
4520
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004521 /*
4522 * key references and virtual interfaces are protected using RCU
4523 * and this requires that we are in a read-side RCU section during
4524 * receive processing
4525 */
4526 rcu_read_lock();
4527
4528 /*
4529 * Frames with failed FCS/PLCP checksum are not returned,
4530 * all other frames are returned without radiotap header
4531 * if it was previously present.
4532 * Also, frames with less than 16 bytes are dropped.
4533 */
Johannes Bergf1d58c22009-06-17 13:13:00 +02004534 skb = ieee80211_rx_monitor(local, skb, rate);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004535 if (!skb) {
4536 rcu_read_unlock();
4537 return;
4538 }
4539
Johannes Berge1e54062010-11-30 08:58:45 +01004540 ieee80211_tpt_led_trig_rx(local,
4541 ((struct ieee80211_hdr *)skb->data)->frame_control,
4542 skb->len);
Johannes Bergd63b5482016-03-31 20:02:02 +03004543
4544 __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004545
4546 rcu_read_unlock();
Johannes Berg77a980d2009-08-24 11:46:30 +02004547
4548 return;
4549 drop:
4550 kfree_skb(skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004551}
Johannes Bergaf9f9b22015-06-11 16:02:32 +02004552EXPORT_SYMBOL(ieee80211_rx_napi);
Johannes Berg571ecf62007-07-27 15:43:22 +02004553
4554/* This is a version of the rx handler that can be called from hard irq
4555 * context. Post the skb on the queue and schedule the tasklet */
Johannes Bergf1d58c22009-06-17 13:13:00 +02004556void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02004557{
4558 struct ieee80211_local *local = hw_to_local(hw);
4559
4560 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4561
Johannes Berg571ecf62007-07-27 15:43:22 +02004562 skb->pkt_type = IEEE80211_RX_MSG;
4563 skb_queue_tail(&local->skb_queue, skb);
4564 tasklet_schedule(&local->tasklet);
4565}
4566EXPORT_SYMBOL(ieee80211_rx_irqsafe);