blob: 2e8a9024625a2ae49ac046bccac671c77911120f [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
Johannes Bergfb4ea052016-01-28 16:19:24 +02007 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
Johannes Berg571ecf62007-07-27 15:43:22 +02008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
S.Çağlar Onurab466232008-02-14 17:36:47 +020014#include <linux/jiffies.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020016#include <linux/kernel.h>
17#include <linux/skbuff.h>
18#include <linux/netdevice.h>
19#include <linux/etherdevice.h>
Johannes Bergd4e46a32007-09-14 11:10:24 -040020#include <linux/rcupdate.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040021#include <linux/export.h>
Sara Sharon06470f72016-01-28 16:19:25 +020022#include <linux/bitops.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020023#include <net/mac80211.h>
24#include <net/ieee80211_radiotap.h>
Johannes Bergd26ad372012-02-20 11:38:41 +010025#include <asm/unaligned.h>
Johannes Berg571ecf62007-07-27 15:43:22 +020026
27#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020028#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040029#include "led.h"
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +010030#include "mesh.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020031#include "wep.h"
32#include "wpa.h"
33#include "tkip.h"
34#include "wme.h"
Johannes Berg1d8d3de2011-12-16 15:28:57 +010035#include "rate.h"
Johannes Berg571ecf62007-07-27 15:43:22 +020036
Johannes Berg5a490512015-04-22 17:10:38 +020037static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
38{
39 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
40
41 u64_stats_update_begin(&tstats->syncp);
42 tstats->rx_packets++;
43 tstats->rx_bytes += len;
44 u64_stats_update_end(&tstats->syncp);
45}
46
Johannes Berga6828492015-06-16 15:17:15 +020047static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
48 enum nl80211_iftype type)
49{
50 __le16 fc = hdr->frame_control;
51
52 if (ieee80211_is_data(fc)) {
53 if (len < 24) /* drop incorrect hdr len (data) */
54 return NULL;
55
56 if (ieee80211_has_a4(fc))
57 return NULL;
58 if (ieee80211_has_tods(fc))
59 return hdr->addr1;
60 if (ieee80211_has_fromds(fc))
61 return hdr->addr2;
62
63 return hdr->addr3;
64 }
65
66 if (ieee80211_is_mgmt(fc)) {
67 if (len < 24) /* drop incorrect hdr len (mgmt) */
68 return NULL;
69 return hdr->addr3;
70 }
71
72 if (ieee80211_is_ctl(fc)) {
73 if (ieee80211_is_pspoll(fc))
74 return hdr->addr1;
75
76 if (ieee80211_is_back_req(fc)) {
77 switch (type) {
78 case NL80211_IFTYPE_STATION:
79 return hdr->addr2;
80 case NL80211_IFTYPE_AP:
81 case NL80211_IFTYPE_AP_VLAN:
82 return hdr->addr1;
83 default:
84 break; /* fall through to the return */
85 }
86 }
87 }
88
89 return NULL;
90}
91
Johannes Bergb2e77712007-09-26 15:19:39 +020092/*
93 * monitor mode reception
94 *
95 * This function cleans up the SKB, i.e. it removes all the stuff
96 * only useful for monitoring.
97 */
98static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
Johannes Berg1f7bba72014-11-06 22:56:36 +010099 struct sk_buff *skb,
100 unsigned int rtap_vendor_space)
Johannes Bergb2e77712007-09-26 15:19:39 +0200101{
Johannes Berg30686bf2015-06-02 21:39:54 +0200102 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200103 if (likely(skb->len > FCS_LEN))
Zhu Yie3cf8b32010-03-29 17:35:07 +0800104 __pskb_trim(skb, skb->len - FCS_LEN);
Johannes Bergb2e77712007-09-26 15:19:39 +0200105 else {
106 /* driver bug */
107 WARN_ON(1);
108 dev_kfree_skb(skb);
Dan Carpenter06247602012-11-27 20:31:19 +0300109 return NULL;
Johannes Bergb2e77712007-09-26 15:19:39 +0200110 }
111 }
112
Johannes Berg1f7bba72014-11-06 22:56:36 +0100113 __pskb_pull(skb, rtap_vendor_space);
114
Johannes Bergb2e77712007-09-26 15:19:39 +0200115 return skb;
116}
117
Johannes Berg1f7bba72014-11-06 22:56:36 +0100118static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
119 unsigned int rtap_vendor_space)
Johannes Bergb2e77712007-09-26 15:19:39 +0200120{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200121 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg1f7bba72014-11-06 22:56:36 +0100122 struct ieee80211_hdr *hdr;
123
124 hdr = (void *)(skb->data + rtap_vendor_space);
Johannes Bergb2e77712007-09-26 15:19:39 +0200125
Johannes Berg4c298672012-07-05 11:34:31 +0200126 if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
Grzegorz Bajorski17883042015-12-11 14:39:46 +0100127 RX_FLAG_FAILED_PLCP_CRC |
128 RX_FLAG_ONLY_MONITOR))
Zhao, Gang6b59db72014-04-21 12:52:59 +0800129 return true;
130
Johannes Berg1f7bba72014-11-06 22:56:36 +0100131 if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space))
Zhao, Gang6b59db72014-04-21 12:52:59 +0800132 return true;
133
Harvey Harrison87228f52008-06-11 14:21:59 -0700134 if (ieee80211_is_ctl(hdr->frame_control) &&
135 !ieee80211_is_pspoll(hdr->frame_control) &&
136 !ieee80211_is_back_req(hdr->frame_control))
Zhao, Gang6b59db72014-04-21 12:52:59 +0800137 return true;
138
139 return false;
Johannes Bergb2e77712007-09-26 15:19:39 +0200140}
141
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200142static int
Johannes Berg1f7bba72014-11-06 22:56:36 +0100143ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
144 struct ieee80211_rx_status *status,
145 struct sk_buff *skb)
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200146{
147 int len;
148
149 /* always present fields */
Johannes Berga144f372013-07-03 13:34:02 +0200150 len = sizeof(struct ieee80211_radiotap_header) + 8;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200151
Johannes Berga144f372013-07-03 13:34:02 +0200152 /* allocate extra bitmaps */
Johannes Berga144f372013-07-03 13:34:02 +0200153 if (status->chains)
154 len += 4 * hweight8(status->chains);
Johannes Berg90b9e4462012-11-16 10:09:08 +0100155
156 if (ieee80211_have_rx_timestamp(status)) {
157 len = ALIGN(len, 8);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200158 len += 8;
Johannes Berg90b9e4462012-11-16 10:09:08 +0100159 }
Johannes Berg30686bf2015-06-02 21:39:54 +0200160 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200161 len += 1;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200162
Johannes Berga144f372013-07-03 13:34:02 +0200163 /* antenna field, if we don't have per-chain info */
164 if (!status->chains)
165 len += 1;
166
Johannes Berg90b9e4462012-11-16 10:09:08 +0100167 /* padding for RX_FLAGS if necessary */
168 len = ALIGN(len, 2);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200169
Johannes Berg6d744ba2011-01-27 14:13:17 +0100170 if (status->flag & RX_FLAG_HT) /* HT info */
171 len += 3;
172
Johannes Berg4c298672012-07-05 11:34:31 +0200173 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
Johannes Berg90b9e4462012-11-16 10:09:08 +0100174 len = ALIGN(len, 4);
Johannes Berg4c298672012-07-05 11:34:31 +0200175 len += 8;
176 }
177
Johannes Berg51648922012-11-22 23:00:18 +0100178 if (status->flag & RX_FLAG_VHT) {
179 len = ALIGN(len, 2);
180 len += 12;
181 }
182
Johannes Berga144f372013-07-03 13:34:02 +0200183 if (status->chains) {
184 /* antenna and antenna signal fields */
185 len += 2 * hweight8(status->chains);
186 }
187
Johannes Berg1f7bba72014-11-06 22:56:36 +0100188 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
189 struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
190
191 /* vendor presence bitmap */
192 len += 4;
193 /* alignment for fixed 6-byte vendor data header */
194 len = ALIGN(len, 2);
195 /* vendor data header */
196 len += 6;
197 if (WARN_ON(rtap->align == 0))
198 rtap->align = 1;
199 len = ALIGN(len, rtap->align);
200 len += rtap->len + rtap->pad;
201 }
202
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200203 return len;
204}
205
Johannes Berg00ea6de2012-09-05 15:54:51 +0200206/*
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200207 * ieee80211_add_rx_radiotap_header - add radiotap header
208 *
209 * add a radiotap header containing all the fields which the hardware provided.
210 */
211static void
212ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
213 struct sk_buff *skb,
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200214 struct ieee80211_rate *rate,
Felix Fietkau973ef212012-04-16 14:56:48 +0200215 int rtap_len, bool has_fcs)
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200216{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200217 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200218 struct ieee80211_radiotap_header *rthdr;
219 unsigned char *pos;
Johannes Berga144f372013-07-03 13:34:02 +0200220 __le32 *it_present;
221 u32 it_present_val;
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100222 u16 rx_flags = 0;
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200223 u16 channel_flags = 0;
Johannes Berga144f372013-07-03 13:34:02 +0200224 int mpdulen, chain;
225 unsigned long chains = status->chains;
Johannes Berg1f7bba72014-11-06 22:56:36 +0100226 struct ieee80211_vendor_radiotap rtap = {};
227
228 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
229 rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
230 /* rtap.len and rtap.pad are undone immediately */
231 skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
232 }
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800233
234 mpdulen = skb->len;
Johannes Berg30686bf2015-06-02 21:39:54 +0200235 if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800236 mpdulen += FCS_LEN;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200237
238 rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
Johannes Berg1f7bba72014-11-06 22:56:36 +0100239 memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
Johannes Berga144f372013-07-03 13:34:02 +0200240 it_present = &rthdr->it_present;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200241
242 /* radiotap header, set always present flags */
Emmanuel Grumbach0059b2b2014-02-05 16:36:01 +0200243 rthdr->it_len = cpu_to_le16(rtap_len);
Johannes Berga144f372013-07-03 13:34:02 +0200244 it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
245 BIT(IEEE80211_RADIOTAP_CHANNEL) |
246 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200247
Johannes Berga144f372013-07-03 13:34:02 +0200248 if (!status->chains)
249 it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
250
251 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
252 it_present_val |=
253 BIT(IEEE80211_RADIOTAP_EXT) |
254 BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
255 put_unaligned_le32(it_present_val, it_present);
256 it_present++;
257 it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
258 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
259 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200260
Johannes Berg1f7bba72014-11-06 22:56:36 +0100261 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
262 it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
263 BIT(IEEE80211_RADIOTAP_EXT);
264 put_unaligned_le32(it_present_val, it_present);
265 it_present++;
266 it_present_val = rtap.present;
267 }
268
Johannes Berga144f372013-07-03 13:34:02 +0200269 put_unaligned_le32(it_present_val, it_present);
270
271 pos = (void *)(it_present + 1);
272
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200273 /* the order of the following fields is important */
274
275 /* IEEE80211_RADIOTAP_TSFT */
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800276 if (ieee80211_have_rx_timestamp(status)) {
Johannes Berg90b9e4462012-11-16 10:09:08 +0100277 /* padding */
278 while ((pos - (u8 *)rthdr) & 7)
279 *pos++ = 0;
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800280 put_unaligned_le64(
281 ieee80211_calculate_rx_timestamp(local, status,
282 mpdulen, 0),
283 pos);
Johannes Berg1df332e2012-10-26 00:09:11 +0200284 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200285 pos += 8;
286 }
287
288 /* IEEE80211_RADIOTAP_FLAGS */
Johannes Berg30686bf2015-06-02 21:39:54 +0200289 if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200290 *pos |= IEEE80211_RADIOTAP_F_FCS;
Johannes Bergaae89832009-03-13 12:52:10 +0100291 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
292 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
Bruno Randolfb4f28bb2008-07-30 17:19:55 +0200293 if (status->flag & RX_FLAG_SHORTPRE)
294 *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200295 pos++;
296
297 /* IEEE80211_RADIOTAP_RATE */
Johannes Berg56146182012-11-09 15:07:02 +0100298 if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200299 /*
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100300 * Without rate information don't add it. If we have,
Mohammed Shafi Shajakhan38f37be2011-02-07 10:10:04 +0530301 * MCS information is a separate field in radiotap,
Johannes Berg73b48092011-04-18 17:05:21 +0200302 * added below. The byte here is needed as padding
303 * for the channel though, so initialise it to 0.
Jouni Malinen0fb8ca42008-12-12 14:38:33 +0200304 */
305 *pos = 0;
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200306 } else {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200307 int shift = 0;
Jouni Malinenebe6c7b2009-01-10 11:47:33 +0200308 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200309 if (status->flag & RX_FLAG_10MHZ)
310 shift = 1;
311 else if (status->flag & RX_FLAG_5MHZ)
312 shift = 2;
313 *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
Jouni Malinen8d6f6582008-12-15 10:37:50 +0200314 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200315 pos++;
316
317 /* IEEE80211_RADIOTAP_CHANNEL */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100318 put_unaligned_le16(status->freq, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200319 pos += 2;
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200320 if (status->flag & RX_FLAG_10MHZ)
321 channel_flags |= IEEE80211_CHAN_HALF;
322 else if (status->flag & RX_FLAG_5MHZ)
323 channel_flags |= IEEE80211_CHAN_QUARTER;
324
Johannes Berg57fbcce2016-04-12 15:56:15 +0200325 if (status->band == NL80211_BAND_5GHZ)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200326 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
Johannes Berg56146182012-11-09 15:07:02 +0100327 else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200328 channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100329 else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200330 channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100331 else if (rate)
Mathy Vanhoef3a5c5e82015-01-20 15:05:08 +0100332 channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
Johannes Bergf8d1ccf2011-11-08 12:28:33 +0100333 else
Simon Wunderlicha5e70692013-07-08 16:55:52 +0200334 channel_flags |= IEEE80211_CHAN_2GHZ;
335 put_unaligned_le16(channel_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200336 pos += 2;
337
338 /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
Johannes Berg30686bf2015-06-02 21:39:54 +0200339 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
Felix Fietkaufe8431f2012-03-01 18:00:07 +0100340 !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200341 *pos = status->signal;
342 rthdr->it_present |=
343 cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
344 pos++;
345 }
346
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200347 /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
348
Johannes Berga144f372013-07-03 13:34:02 +0200349 if (!status->chains) {
350 /* IEEE80211_RADIOTAP_ANTENNA */
351 *pos = status->antenna;
352 pos++;
353 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200354
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200355 /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
356
357 /* IEEE80211_RADIOTAP_RX_FLAGS */
358 /* ensure 2 byte alignment for the 2 byte field as required */
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100359 if ((pos - (u8 *)rthdr) & 1)
Johannes Berg90b9e4462012-11-16 10:09:08 +0100360 *pos++ = 0;
Johannes Bergaae89832009-03-13 12:52:10 +0100361 if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
Johannes Berg6a86b9c2009-10-28 09:58:52 +0100362 rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
363 put_unaligned_le16(rx_flags, pos);
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200364 pos += 2;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100365
366 if (status->flag & RX_FLAG_HT) {
Oleksij Rempel786677d2013-05-24 12:05:45 +0200367 unsigned int stbc;
368
Johannes Berg6d744ba2011-01-27 14:13:17 +0100369 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
Johannes Bergac55d2f2012-05-10 09:09:10 +0200370 *pos++ = local->hw.radiotap_mcs_details;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100371 *pos = 0;
372 if (status->flag & RX_FLAG_SHORT_GI)
373 *pos |= IEEE80211_RADIOTAP_MCS_SGI;
374 if (status->flag & RX_FLAG_40MHZ)
375 *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
Johannes Bergac55d2f2012-05-10 09:09:10 +0200376 if (status->flag & RX_FLAG_HT_GF)
377 *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
Emmanuel Grumbach63c361f2014-02-05 12:48:53 +0200378 if (status->flag & RX_FLAG_LDPC)
379 *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
Oleksij Rempel786677d2013-05-24 12:05:45 +0200380 stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
381 *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
Johannes Berg6d744ba2011-01-27 14:13:17 +0100382 pos++;
383 *pos++ = status->rate_idx;
384 }
Johannes Berg4c298672012-07-05 11:34:31 +0200385
386 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
387 u16 flags = 0;
388
389 /* ensure 4 byte alignment */
390 while ((pos - (u8 *)rthdr) & 3)
391 pos++;
392 rthdr->it_present |=
393 cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
394 put_unaligned_le32(status->ampdu_reference, pos);
395 pos += 4;
Johannes Berg4c298672012-07-05 11:34:31 +0200396 if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
397 flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
398 if (status->flag & RX_FLAG_AMPDU_IS_LAST)
399 flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
400 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
401 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
402 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
403 flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
404 put_unaligned_le16(flags, pos);
405 pos += 2;
406 if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
407 *pos++ = status->ampdu_delimiter_crc;
408 else
409 *pos++ = 0;
410 *pos++ = 0;
411 }
Johannes Berg90b9e4462012-11-16 10:09:08 +0100412
Johannes Berg51648922012-11-22 23:00:18 +0100413 if (status->flag & RX_FLAG_VHT) {
414 u16 known = local->hw.radiotap_vht_details;
415
416 rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
Johannes Berg51648922012-11-22 23:00:18 +0100417 put_unaligned_le16(known, pos);
418 pos += 2;
419 /* flags */
420 if (status->flag & RX_FLAG_SHORT_GI)
421 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
Emmanuel Grumbach63c361f2014-02-05 12:48:53 +0200422 /* in VHT, STBC is binary */
423 if (status->flag & RX_FLAG_STBC_MASK)
424 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
Emmanuel Grumbachfb378c22014-03-04 10:35:25 +0200425 if (status->vht_flag & RX_VHT_FLAG_BF)
426 *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
Johannes Berg51648922012-11-22 23:00:18 +0100427 pos++;
428 /* bandwidth */
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200429 if (status->vht_flag & RX_VHT_FLAG_80MHZ)
Johannes Berg51648922012-11-22 23:00:18 +0100430 *pos++ = 4;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200431 else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
Johannes Berg51648922012-11-22 23:00:18 +0100432 *pos++ = 11;
433 else if (status->flag & RX_FLAG_40MHZ)
434 *pos++ = 1;
435 else /* 20 MHz */
436 *pos++ = 0;
437 /* MCS/NSS */
438 *pos = (status->rate_idx << 4) | status->vht_nss;
439 pos += 4;
440 /* coding field */
Emmanuel Grumbach63c361f2014-02-05 12:48:53 +0200441 if (status->flag & RX_FLAG_LDPC)
442 *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
Johannes Berg51648922012-11-22 23:00:18 +0100443 pos++;
444 /* group ID */
445 pos++;
446 /* partial_aid */
447 pos += 2;
448 }
449
Johannes Berga144f372013-07-03 13:34:02 +0200450 for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
451 *pos++ = status->chain_signal[chain];
452 *pos++ = chain;
453 }
Johannes Berg1f7bba72014-11-06 22:56:36 +0100454
455 if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
456 /* ensure 2 byte alignment for the vendor field as required */
457 if ((pos - (u8 *)rthdr) & 1)
458 *pos++ = 0;
459 *pos++ = rtap.oui[0];
460 *pos++ = rtap.oui[1];
461 *pos++ = rtap.oui[2];
462 *pos++ = rtap.subns;
463 put_unaligned_le16(rtap.len, pos);
464 pos += 2;
465 /* align the actual payload as requested */
466 while ((pos - (u8 *)rthdr) & (rtap.align - 1))
467 *pos++ = 0;
468 /* data (and possible padding) already follows */
469 }
Bruno Randolf601ae7f2008-05-08 19:22:43 +0200470}
471
Johannes Bergb2e77712007-09-26 15:19:39 +0200472/*
473 * This function copies a received frame to all monitor interfaces and
474 * returns a cleaned-up SKB that no longer includes the FCS nor the
475 * radiotap header the driver might have added.
476 */
477static struct sk_buff *
478ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
Johannes Berg8318d782008-01-24 19:38:38 +0100479 struct ieee80211_rate *rate)
Johannes Bergb2e77712007-09-26 15:19:39 +0200480{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200481 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200482 struct ieee80211_sub_if_data *sdata;
Johannes Berg1f7bba72014-11-06 22:56:36 +0100483 int rt_hdrlen, needed_headroom;
Johannes Bergb2e77712007-09-26 15:19:39 +0200484 struct sk_buff *skb, *skb2;
485 struct net_device *prev_dev = NULL;
486 int present_fcs_len = 0;
Johannes Berg1f7bba72014-11-06 22:56:36 +0100487 unsigned int rtap_vendor_space = 0;
488
489 if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
490 struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
491
492 rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad;
493 }
Johannes Bergb2e77712007-09-26 15:19:39 +0200494
495 /*
496 * First, we may need to make a copy of the skb because
497 * (1) we need to modify it for radiotap (if not present), and
498 * (2) the other RX handlers will modify the skb we got.
499 *
500 * We don't need to, of course, if we aren't going to return
501 * the SKB because it has a bad FCS/PLCP checksum.
502 */
Johannes Berg0869aea2009-10-28 10:03:35 +0100503
Johannes Berg30686bf2015-06-02 21:39:54 +0200504 if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
Johannes Bergb2e77712007-09-26 15:19:39 +0200505 present_fcs_len = FCS_LEN;
506
Johannes Berg1f7bba72014-11-06 22:56:36 +0100507 /* ensure hdr->frame_control and vendor radiotap data are in skb head */
508 if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) {
Zhu Yie3cf8b32010-03-29 17:35:07 +0800509 dev_kfree_skb(origskb);
510 return NULL;
511 }
512
Grzegorz Bajorski17883042015-12-11 14:39:46 +0100513 if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
Johannes Berg1f7bba72014-11-06 22:56:36 +0100514 if (should_drop_frame(origskb, present_fcs_len,
515 rtap_vendor_space)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200516 dev_kfree_skb(origskb);
517 return NULL;
518 }
519
Johannes Berg1f7bba72014-11-06 22:56:36 +0100520 return remove_monitor_info(local, origskb, rtap_vendor_space);
Johannes Bergb2e77712007-09-26 15:19:39 +0200521 }
522
Helmut Schaa751413e2012-12-05 14:36:12 +0100523 /* room for the radiotap header based on driver features */
Johannes Berg1f7bba72014-11-06 22:56:36 +0100524 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb);
525 needed_headroom = rt_hdrlen - rtap_vendor_space;
Helmut Schaa751413e2012-12-05 14:36:12 +0100526
Johannes Berg1f7bba72014-11-06 22:56:36 +0100527 if (should_drop_frame(origskb, present_fcs_len, rtap_vendor_space)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200528 /* only need to expand headroom if necessary */
529 skb = origskb;
530 origskb = NULL;
531
532 /*
533 * This shouldn't trigger often because most devices have an
534 * RX header they pull before we get here, and that should
535 * be big enough for our radiotap information. We should
536 * probably export the length to drivers so that we can have
537 * them allocate enough headroom to start with.
538 */
539 if (skb_headroom(skb) < needed_headroom &&
Johannes Bergc49e5ea2007-12-11 21:33:42 +0100540 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
Johannes Bergb2e77712007-09-26 15:19:39 +0200541 dev_kfree_skb(skb);
542 return NULL;
543 }
544 } else {
545 /*
546 * Need to make a copy and possibly remove radiotap header
547 * and FCS from the original.
548 */
549 skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
550
Johannes Berg1f7bba72014-11-06 22:56:36 +0100551 origskb = remove_monitor_info(local, origskb,
552 rtap_vendor_space);
Johannes Bergb2e77712007-09-26 15:19:39 +0200553
554 if (!skb)
555 return origskb;
556 }
557
Johannes Berg0869aea2009-10-28 10:03:35 +0100558 /* prepend radiotap information */
Johannes Berg1f7bba72014-11-06 22:56:36 +0100559 ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
Johannes Bergb2e77712007-09-26 15:19:39 +0200560
Johannes Bergce3edf6d02007-12-19 01:31:22 +0100561 skb_reset_mac_header(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200562 skb->ip_summed = CHECKSUM_UNNECESSARY;
563 skb->pkt_type = PACKET_OTHERHOST;
564 skb->protocol = htons(ETH_P_802_2);
565
566 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200567 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
Johannes Bergb2e77712007-09-26 15:19:39 +0200568 continue;
569
Michael Wu3d30d942008-01-31 19:48:27 +0100570 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
571 continue;
572
Johannes Berg9607e6b2009-12-23 13:15:31 +0100573 if (!ieee80211_sdata_running(sdata))
Johannes Berg47846c92009-11-25 17:46:19 +0100574 continue;
575
Johannes Bergb2e77712007-09-26 15:19:39 +0200576 if (prev_dev) {
577 skb2 = skb_clone(skb, GFP_ATOMIC);
578 if (skb2) {
579 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400580 netif_receive_skb(skb2);
Johannes Bergb2e77712007-09-26 15:19:39 +0200581 }
582 }
583
584 prev_dev = sdata->dev;
Johannes Berg5a490512015-04-22 17:10:38 +0200585 ieee80211_rx_stats(sdata->dev, skb->len);
Johannes Bergb2e77712007-09-26 15:19:39 +0200586 }
587
588 if (prev_dev) {
589 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -0400590 netif_receive_skb(skb);
Johannes Bergb2e77712007-09-26 15:19:39 +0200591 } else
592 dev_kfree_skb(skb);
593
594 return origskb;
595}
596
Johannes Berg5cf121c2008-02-25 16:27:43 +0100597static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
Johannes Berg6e0d1142007-07-27 15:43:22 +0200598{
Harvey Harrison238f74a2008-07-02 11:05:34 -0700599 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +0200600 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg9e262972011-07-07 18:45:03 +0200601 int tid, seqno_idx, security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200602
603 /* does the frame have a qos control field? */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700604 if (ieee80211_is_data_qos(hdr->frame_control)) {
605 u8 *qc = ieee80211_get_qos_ctl(hdr);
Johannes Berg6e0d1142007-07-27 15:43:22 +0200606 /* frame has qos control */
Harvey Harrison238f74a2008-07-02 11:05:34 -0700607 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
Johannes Berg04b7dcf2011-06-22 10:06:59 +0200608 if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
Johannes Berg554891e2010-09-24 12:38:25 +0200609 status->rx_flags |= IEEE80211_RX_AMSDU;
Johannes Berg9e262972011-07-07 18:45:03 +0200610
611 seqno_idx = tid;
612 security_idx = tid;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200613 } else {
Johannes Berg1411f9b2008-07-10 10:11:02 +0200614 /*
615 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
616 *
617 * Sequence numbers for management frames, QoS data
618 * frames with a broadcast/multicast address in the
619 * Address 1 field, and all non-QoS data frames sent
620 * by QoS STAs are assigned using an additional single
621 * modulo-4096 counter, [...]
622 *
623 * We also use that counter for non-QoS STAs.
624 */
Johannes Berg5a306f52012-11-14 23:22:21 +0100625 seqno_idx = IEEE80211_NUM_TIDS;
Johannes Berg9e262972011-07-07 18:45:03 +0200626 security_idx = 0;
627 if (ieee80211_is_mgmt(hdr->frame_control))
Johannes Berg5a306f52012-11-14 23:22:21 +0100628 security_idx = IEEE80211_NUM_TIDS;
Johannes Berg9e262972011-07-07 18:45:03 +0200629 tid = 0;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200630 }
Johannes Berg52865dfd2007-07-27 15:43:22 +0200631
Johannes Berg9e262972011-07-07 18:45:03 +0200632 rx->seqno_idx = seqno_idx;
633 rx->security_idx = security_idx;
Johannes Berg6e0d1142007-07-27 15:43:22 +0200634 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
635 * For now, set skb->priority to 0 for other cases. */
636 rx->skb->priority = (tid > 7) ? 0 : tid;
Johannes Berg38f37142008-01-29 17:07:43 +0100637}
Johannes Berg6e0d1142007-07-27 15:43:22 +0200638
Johannes Bergd1c3a372009-01-07 00:26:10 +0100639/**
640 * DOC: Packet alignment
641 *
642 * Drivers always need to pass packets that are aligned to two-byte boundaries
643 * to the stack.
644 *
645 * Additionally, should, if possible, align the payload data in a way that
646 * guarantees that the contained IP header is aligned to a four-byte
647 * boundary. In the case of regular frames, this simply means aligning the
648 * payload to a four-byte boundary (because either the IP header is directly
649 * contained, or IV/RFC1042 headers that have a length divisible by four are
Kalle Valo59d9cb02009-12-17 13:54:57 +0100650 * in front of it). If the payload data is not properly aligned and the
651 * architecture doesn't support efficient unaligned operations, mac80211
652 * will align the data.
Johannes Bergd1c3a372009-01-07 00:26:10 +0100653 *
654 * With A-MSDU frames, however, the payload data address must yield two modulo
655 * four because there are 14-byte 802.3 headers within the A-MSDU frames that
656 * push the IP header further back to a multiple of four again. Thankfully, the
657 * specs were sane enough this time around to require padding each A-MSDU
658 * subframe to a length that is a multiple of four.
659 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300660 * Padding like Atheros hardware adds which is between the 802.11 header and
Johannes Bergd1c3a372009-01-07 00:26:10 +0100661 * the payload is not supported, the driver is required to move the 802.11
662 * header to be directly in front of the payload in that case.
663 */
664static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
Johannes Berg38f37142008-01-29 17:07:43 +0100665{
Kalle Valo59d9cb02009-12-17 13:54:57 +0100666#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg441275e2015-11-06 12:34:24 +0100667 WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
Johannes Bergd1c3a372009-01-07 00:26:10 +0100668#endif
Johannes Berg6e0d1142007-07-27 15:43:22 +0200669}
670
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +0200671
Johannes Berg571ecf62007-07-27 15:43:22 +0200672/* rx handlers */
673
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200674static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
675{
676 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
677
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100678 if (is_multicast_ether_addr(hdr->addr1))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200679 return 0;
680
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100681 return ieee80211_is_robust_mgmt_frame(skb);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200682}
683
684
685static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
686{
687 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
688
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100689 if (!is_multicast_ether_addr(hdr->addr1))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200690 return 0;
691
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100692 return ieee80211_is_robust_mgmt_frame(skb);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200693}
694
695
696/* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
697static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
698{
699 struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
700 struct ieee80211_mmie *mmie;
Jouni Malinen56c52da2015-01-24 19:52:08 +0200701 struct ieee80211_mmie_16 *mmie16;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200702
Johannes Berg1df332e2012-10-26 00:09:11 +0200703 if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200704 return -1;
705
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100706 if (!ieee80211_is_robust_mgmt_frame(skb))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200707 return -1; /* not a robust management frame */
708
709 mmie = (struct ieee80211_mmie *)
710 (skb->data + skb->len - sizeof(*mmie));
Jouni Malinen56c52da2015-01-24 19:52:08 +0200711 if (mmie->element_id == WLAN_EID_MMIE &&
712 mmie->length == sizeof(*mmie) - 2)
713 return le16_to_cpu(mmie->key_id);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200714
Jouni Malinen56c52da2015-01-24 19:52:08 +0200715 mmie16 = (struct ieee80211_mmie_16 *)
716 (skb->data + skb->len - sizeof(*mmie16));
717 if (skb->len >= 24 + sizeof(*mmie16) &&
718 mmie16->element_id == WLAN_EID_MMIE &&
719 mmie16->length == sizeof(*mmie16) - 2)
720 return le16_to_cpu(mmie16->key_id);
721
722 return -1;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200723}
724
Johannes Berg2c61cf92016-03-17 15:02:55 +0200725static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
726 struct sk_buff *skb)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200727{
728 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
729 __le16 fc;
730 int hdrlen;
731 u8 keyid;
732
733 fc = hdr->frame_control;
734 hdrlen = ieee80211_hdrlen(fc);
735
736 if (skb->len < hdrlen + cs->hdr_len)
737 return -EINVAL;
738
739 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
740 keyid &= cs->key_idx_mask;
741 keyid >>= cs->key_idx_shift;
742
743 return keyid;
744}
745
Johannes Berg1df332e2012-10-26 00:09:11 +0200746static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100747{
Harvey Harrisona7767f92008-07-02 16:30:51 -0700748 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg47846c92009-11-25 17:46:19 +0100749 char *dev_addr = rx->sdata->vif.addr;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100750
Harvey Harrisona7767f92008-07-02 16:30:51 -0700751 if (ieee80211_is_data(hdr->frame_control)) {
Javier Cardona3c5772a2009-08-10 12:15:48 -0700752 if (is_multicast_ether_addr(hdr->addr1)) {
753 if (ieee80211_has_tods(hdr->frame_control) ||
Johannes Berg1df332e2012-10-26 00:09:11 +0200754 !ieee80211_has_fromds(hdr->frame_control))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700755 return RX_DROP_MONITOR;
Joe Perchesb203ca32012-05-08 18:56:52 +0000756 if (ether_addr_equal(hdr->addr3, dev_addr))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700757 return RX_DROP_MONITOR;
758 } else {
759 if (!ieee80211_has_a4(hdr->frame_control))
760 return RX_DROP_MONITOR;
Joe Perchesb203ca32012-05-08 18:56:52 +0000761 if (ether_addr_equal(hdr->addr4, dev_addr))
Javier Cardona3c5772a2009-08-10 12:15:48 -0700762 return RX_DROP_MONITOR;
763 }
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100764 }
765
766 /* If there is not an established peer link and this is not a peer link
767 * establisment frame, beacon or probe, drop the frame.
768 */
769
Javier Cardona57cf8042011-05-13 10:45:43 -0700770 if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100771 struct ieee80211_mgmt *mgmt;
Johannes Bergd6d1a5a2008-02-25 16:24:38 +0100772
Harvey Harrisona7767f92008-07-02 16:30:51 -0700773 if (!ieee80211_is_mgmt(hdr->frame_control))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100774 return RX_DROP_MONITOR;
775
Harvey Harrisona7767f92008-07-02 16:30:51 -0700776 if (ieee80211_is_action(hdr->frame_control)) {
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700777 u8 category;
Johannes Berg9b395bc2012-10-26 00:36:40 +0200778
779 /* make sure category field is present */
780 if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
781 return RX_DROP_MONITOR;
782
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100783 mgmt = (struct ieee80211_mgmt *)hdr;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -0700784 category = mgmt->u.action.category;
785 if (category != WLAN_CATEGORY_MESH_ACTION &&
Johannes Berg1df332e2012-10-26 00:09:11 +0200786 category != WLAN_CATEGORY_SELF_PROTECTED)
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100787 return RX_DROP_MONITOR;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100788 return RX_CONTINUE;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100789 }
790
Harvey Harrisona7767f92008-07-02 16:30:51 -0700791 if (ieee80211_is_probe_req(hdr->frame_control) ||
792 ieee80211_is_probe_resp(hdr->frame_control) ||
Javier Cardona71839122011-04-07 15:08:31 -0700793 ieee80211_is_beacon(hdr->frame_control) ||
794 ieee80211_is_auth(hdr->frame_control))
Harvey Harrisona7767f92008-07-02 16:30:51 -0700795 return RX_CONTINUE;
796
797 return RX_DROP_MONITOR;
Harvey Harrisona7767f92008-07-02 16:30:51 -0700798 }
799
Johannes Berg902acc72008-02-23 15:17:19 +0100800 return RX_CONTINUE;
801}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100802
Johannes Bergfb4ea052016-01-28 16:19:24 +0200803static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
804 int index)
805{
806 struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
807 struct sk_buff *tail = skb_peek_tail(frames);
808 struct ieee80211_rx_status *status;
809
Sara Sharon06470f72016-01-28 16:19:25 +0200810 if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
811 return true;
812
Johannes Bergfb4ea052016-01-28 16:19:24 +0200813 if (!tail)
814 return false;
815
816 status = IEEE80211_SKB_RXCB(tail);
817 if (status->flag & RX_FLAG_AMSDU_MORE)
818 return false;
819
820 return true;
821}
822
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200823static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100824 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000825 int index,
826 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100827{
Michal Kazior83eb9352014-07-16 12:09:31 +0200828 struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
829 struct sk_buff *skb;
Christian Lamparter4cfda472010-12-27 23:21:26 +0100830 struct ieee80211_rx_status *status;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100831
Johannes Bergdd318572010-11-29 11:09:16 +0100832 lockdep_assert_held(&tid_agg_rx->reorder_lock);
833
Michal Kazior83eb9352014-07-16 12:09:31 +0200834 if (skb_queue_empty(skb_list))
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100835 goto no_frame;
836
Johannes Bergfb4ea052016-01-28 16:19:24 +0200837 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
Michal Kazior83eb9352014-07-16 12:09:31 +0200838 __skb_queue_purge(skb_list);
839 goto no_frame;
840 }
841
842 /* release frames from the reorder ring buffer */
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100843 tid_agg_rx->stored_mpdu_num--;
Michal Kazior83eb9352014-07-16 12:09:31 +0200844 while ((skb = __skb_dequeue(skb_list))) {
845 status = IEEE80211_SKB_RXCB(skb);
846 status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
847 __skb_queue_tail(frames, skb);
848 }
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100849
850no_frame:
Sara Sharon06470f72016-01-28 16:19:25 +0200851 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
Johannes Berg9a886582013-02-15 19:25:00 +0100852 tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100853}
854
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200855static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100856 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000857 u16 head_seq_num,
858 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100859{
860 int index;
861
Johannes Bergdd318572010-11-29 11:09:16 +0100862 lockdep_assert_held(&tid_agg_rx->reorder_lock);
863
Johannes Berg9a886582013-02-15 19:25:00 +0100864 while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
Karl Beldan2e3049b2013-10-24 15:53:32 +0200865 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000866 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
867 frames);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100868 }
869}
870
871/*
872 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
873 * the skb was added to the buffer longer than this time ago, the earlier
874 * frames that have not yet been received are assumed to be lost and the skb
875 * can be released for processing. This may also release other skb's from the
876 * reorder buffer if there are no additional gaps between the frames.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200877 *
878 * Callers must hold tid_agg_rx->reorder_lock.
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100879 */
880#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
881
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200882static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000883 struct tid_ampdu_rx *tid_agg_rx,
884 struct sk_buff_head *frames)
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200885{
Michal Kazior83eb9352014-07-16 12:09:31 +0200886 int index, i, j;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200887
Johannes Bergdd318572010-11-29 11:09:16 +0100888 lockdep_assert_held(&tid_agg_rx->reorder_lock);
889
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200890 /* release the buffer until next missing frame */
Karl Beldan2e3049b2013-10-24 15:53:32 +0200891 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Johannes Bergfb4ea052016-01-28 16:19:24 +0200892 if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
Eliad Peller07ae2df2012-02-01 18:48:09 +0200893 tid_agg_rx->stored_mpdu_num) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200894 /*
895 * No buffers ready to be released, but check whether any
896 * frames in the reorder buffer have timed out.
897 */
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200898 int skipped = 1;
899 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
900 j = (j + 1) % tid_agg_rx->buf_size) {
Johannes Bergfb4ea052016-01-28 16:19:24 +0200901 if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200902 skipped++;
903 continue;
904 }
Daniel Halperin499fe9a2011-03-24 16:01:48 -0700905 if (skipped &&
906 !time_after(jiffies, tid_agg_rx->reorder_time[j] +
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200907 HT_RX_REORDER_BUF_TIMEOUT))
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200908 goto set_release_timer;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200909
Michal Kazior83eb9352014-07-16 12:09:31 +0200910 /* don't leave incomplete A-MSDUs around */
911 for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
912 i = (i + 1) % tid_agg_rx->buf_size)
913 __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
914
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200915 ht_dbg_ratelimited(sdata,
916 "release an RX reorder frame due to timeout on earlier frames\n");
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000917 ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
918 frames);
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200919
920 /*
921 * Increment the head seq# also for the skipped slots.
922 */
923 tid_agg_rx->head_seq_num =
Johannes Berg9a886582013-02-15 19:25:00 +0100924 (tid_agg_rx->head_seq_num +
925 skipped) & IEEE80211_SN_MASK;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200926 skipped = 0;
927 }
Johannes Bergfb4ea052016-01-28 16:19:24 +0200928 } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000929 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
930 frames);
Karl Beldan2e3049b2013-10-24 15:53:32 +0200931 index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200932 }
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200933
934 if (tid_agg_rx->stored_mpdu_num) {
Karl Beldan2e3049b2013-10-24 15:53:32 +0200935 j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200936
937 for (; j != (index - 1) % tid_agg_rx->buf_size;
938 j = (j + 1) % tid_agg_rx->buf_size) {
Johannes Bergfb4ea052016-01-28 16:19:24 +0200939 if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200940 break;
941 }
942
943 set_release_timer:
944
Johannes Berg788211d2015-04-01 14:20:42 +0200945 if (!tid_agg_rx->removed)
946 mod_timer(&tid_agg_rx->reorder_timer,
947 tid_agg_rx->reorder_time[j] + 1 +
948 HT_RX_REORDER_BUF_TIMEOUT);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200949 } else {
950 del_timer(&tid_agg_rx->reorder_timer);
951 }
Christian Lamparteraa0c8632010-08-05 01:36:04 +0200952}
953
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100954/*
955 * As this function belongs to the RX path it must be under
956 * rcu_read_lock protection. It returns false if the frame
957 * can be processed immediately, true if it was consumed.
958 */
Johannes Bergd3b2fb52012-06-22 12:48:38 +0200959static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100960 struct tid_ampdu_rx *tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +0000961 struct sk_buff *skb,
962 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100963{
964 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Michal Kazior83eb9352014-07-16 12:09:31 +0200965 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100966 u16 sc = le16_to_cpu(hdr->seq_ctrl);
967 u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
968 u16 head_seq_num, buf_size;
969 int index;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200970 bool ret = true;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100971
Johannes Bergdd318572010-11-29 11:09:16 +0100972 spin_lock(&tid_agg_rx->reorder_lock);
973
Michal Kazior4549cf22014-09-02 14:05:10 +0200974 /*
975 * Offloaded BA sessions have no known starting sequence number so pick
976 * one from first Rxed frame for this tid after BA was started.
977 */
978 if (unlikely(tid_agg_rx->auto_seq)) {
979 tid_agg_rx->auto_seq = false;
980 tid_agg_rx->ssn = mpdu_seq_num;
981 tid_agg_rx->head_seq_num = mpdu_seq_num;
982 }
983
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100984 buf_size = tid_agg_rx->buf_size;
985 head_seq_num = tid_agg_rx->head_seq_num;
986
987 /* frame with out of date sequence number */
Johannes Berg9a886582013-02-15 19:25:00 +0100988 if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100989 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +0200990 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +0100991 }
992
993 /*
994 * If frame the sequence number exceeds our buffering window
995 * size release some previous frames to make room for this one.
996 */
Johannes Berg9a886582013-02-15 19:25:00 +0100997 if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
998 head_seq_num = ieee80211_sn_inc(
999 ieee80211_sn_sub(mpdu_seq_num, buf_size));
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001000 /* release stored frames up to new head to stack */
Johannes Bergd3b2fb52012-06-22 12:48:38 +02001001 ieee80211_release_reorder_frames(sdata, tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001002 head_seq_num, frames);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001003 }
1004
1005 /* Now the new frame is always in the range of the reordering buffer */
1006
Karl Beldan2e3049b2013-10-24 15:53:32 +02001007 index = mpdu_seq_num % tid_agg_rx->buf_size;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001008
1009 /* check if we already stored this frame */
Johannes Bergfb4ea052016-01-28 16:19:24 +02001010 if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001011 dev_kfree_skb(skb);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001012 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001013 }
1014
1015 /*
1016 * If the current MPDU is in the right order and nothing else
1017 * is stored we can process it directly, no need to buffer it.
Johannes Bergc835b212011-03-15 23:17:01 +01001018 * If it is first but there's something stored, we may be able
1019 * to release frames after this one.
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001020 */
1021 if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1022 tid_agg_rx->stored_mpdu_num == 0) {
Michal Kazior83eb9352014-07-16 12:09:31 +02001023 if (!(status->flag & RX_FLAG_AMSDU_MORE))
1024 tid_agg_rx->head_seq_num =
1025 ieee80211_sn_inc(tid_agg_rx->head_seq_num);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001026 ret = false;
1027 goto out;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001028 }
1029
1030 /* put the frame in the reordering buffer */
Michal Kazior83eb9352014-07-16 12:09:31 +02001031 __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1032 if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1033 tid_agg_rx->reorder_time[index] = jiffies;
1034 tid_agg_rx->stored_mpdu_num++;
1035 ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1036 }
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001037
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02001038 out:
1039 spin_unlock(&tid_agg_rx->reorder_lock);
1040 return ret;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001041}
1042
1043/*
1044 * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1045 * true if the MPDU was buffered, false if it should be processed.
1046 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001047static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1048 struct sk_buff_head *frames)
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001049{
Johannes Berg2569a822009-11-25 17:46:17 +01001050 struct sk_buff *skb = rx->skb;
1051 struct ieee80211_local *local = rx->local;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001052 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Johannes Berg2569a822009-11-25 17:46:17 +01001053 struct sta_info *sta = rx->sta;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001054 struct tid_ampdu_rx *tid_agg_rx;
1055 u16 sc;
Thomas Pedersen6cc00d52011-11-03 21:11:11 -07001056 u8 tid, ack_policy;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001057
Johannes Berg051a41f2013-11-20 11:28:27 +01001058 if (!ieee80211_is_data_qos(hdr->frame_control) ||
1059 is_multicast_ether_addr(hdr->addr1))
Johannes Berg2569a822009-11-25 17:46:17 +01001060 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001061
1062 /*
1063 * filter the QoS data rx stream according to
1064 * STA/TID and check if this STA/TID is on aggregation
1065 */
1066
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001067 if (!sta)
Johannes Berg2569a822009-11-25 17:46:17 +01001068 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001069
Thomas Pedersen6cc00d52011-11-03 21:11:11 -07001070 ack_policy = *ieee80211_get_qos_ctl(hdr) &
1071 IEEE80211_QOS_CTL_ACK_POLICY_MASK;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001072 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
1073
Johannes Berga87f7362010-06-10 10:21:38 +02001074 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1075 if (!tid_agg_rx)
1076 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001077
1078 /* qos null data frames are excluded */
1079 if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
Johannes Berga87f7362010-06-10 10:21:38 +02001080 goto dont_reorder;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001081
Thomas Pedersen6cc00d52011-11-03 21:11:11 -07001082 /* not part of a BA session */
1083 if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1084 ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1085 goto dont_reorder;
1086
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001087 /* new, potentially un-ordered, ampdu frame - process it */
1088
1089 /* reset session timer */
1090 if (tid_agg_rx->timeout)
Felix Fietkau12d3952f2012-03-18 22:58:06 +01001091 tid_agg_rx->last_rx = jiffies;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001092
1093 /* if this mpdu is fragmented - terminate rx aggregation session */
1094 sc = le16_to_cpu(hdr->seq_ctrl);
1095 if (sc & IEEE80211_SCTL_FRAG) {
Johannes Bergc1475ca2010-06-10 10:21:37 +02001096 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg344eec62010-06-10 10:21:36 +02001097 skb_queue_tail(&rx->sdata->skb_queue, skb);
1098 ieee80211_queue_work(&local->hw, &rx->sdata->work);
Johannes Berg2569a822009-11-25 17:46:17 +01001099 return;
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001100 }
1101
Johannes Berga87f7362010-06-10 10:21:38 +02001102 /*
1103 * No locking needed -- we will only ever process one
1104 * RX packet at a time, and thus own tid_agg_rx. All
1105 * other code manipulating it needs to (and does) make
1106 * sure that we cannot get to it any more before doing
1107 * anything with it.
1108 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001109 if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1110 frames))
Johannes Berg2569a822009-11-25 17:46:17 +01001111 return;
1112
1113 dont_reorder:
Christian Lamparterf9e124f2013-02-04 17:44:44 +00001114 __skb_queue_tail(frames, skb);
Johannes Berg1edfb1a2009-11-25 17:46:16 +01001115}
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001116
Johannes Berg49461622008-06-30 15:10:45 +02001117static ieee80211_rx_result debug_noinline
Johannes Berg03954422014-11-11 16:49:25 +01001118ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001119{
Harvey Harrisona7767f92008-07-02 16:30:51 -07001120 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02001121 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001122
Sara Sharonf9cfa5f2015-12-08 16:04:33 +02001123 if (status->flag & RX_FLAG_DUP_VALIDATED)
1124 return RX_CONTINUE;
1125
Johannes Berg6b0f3272013-07-11 22:33:26 +02001126 /*
1127 * Drop duplicate 802.11 retransmissions
1128 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1129 */
Johannes Berg03954422014-11-11 16:49:25 +01001130
1131 if (rx->skb->len < 24)
1132 return RX_CONTINUE;
1133
1134 if (ieee80211_is_ctl(hdr->frame_control) ||
1135 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
1136 is_multicast_ether_addr(hdr->addr1))
1137 return RX_CONTINUE;
1138
Johannes Berga732fa72015-10-14 18:27:07 +02001139 if (!rx->sta)
1140 return RX_CONTINUE;
1141
1142 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1143 rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1144 I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001145 rx->sta->rx_stats.num_duplicates++;
Johannes Berga732fa72015-10-14 18:27:07 +02001146 return RX_DROP_UNUSABLE;
1147 } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1148 rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
Johannes Berg571ecf62007-07-27 15:43:22 +02001149 }
1150
Johannes Berg03954422014-11-11 16:49:25 +01001151 return RX_CONTINUE;
1152}
1153
1154static ieee80211_rx_result debug_noinline
1155ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1156{
1157 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1158
Johannes Berg571ecf62007-07-27 15:43:22 +02001159 /* Drop disallowed frame classes based on STA auth/assoc state;
1160 * IEEE 802.11, Chap 5.5.
1161 *
Johannes Bergccd7b362008-09-11 00:01:56 +02001162 * mac80211 filters only based on association state, i.e. it drops
1163 * Class 3 frames from not associated stations. hostapd sends
Johannes Berg571ecf62007-07-27 15:43:22 +02001164 * deauth/disassoc frames when needed. In addition, hostapd is
1165 * responsible for filtering on both auth and assoc states.
1166 */
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001167
Johannes Berg902acc72008-02-23 15:17:19 +01001168 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001169 return ieee80211_rx_mesh_check(rx);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001170
Harvey Harrisona7767f92008-07-02 16:30:51 -07001171 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1172 ieee80211_is_pspoll(hdr->frame_control)) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001173 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Bill Jordan1be7fe82010-10-01 11:20:41 -04001174 rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
Rostislav Lisovy239281f2014-11-03 10:33:19 +01001175 rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001176 (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
Johannes Berg7852e362012-01-20 13:55:24 +01001177 /*
1178 * accept port control frames from the AP even when it's not
1179 * yet marked ASSOC to prevent a race where we don't set the
1180 * assoc bit quickly enough before it sends the first frame
1181 */
1182 if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
Guy Eilam2a33bee2011-08-17 15:18:15 +03001183 ieee80211_is_data_present(hdr->frame_control)) {
Johannes Berg6dbda2d2012-10-26 00:41:23 +02001184 unsigned int hdrlen;
1185 __be16 ethertype;
Guy Eilam2a33bee2011-08-17 15:18:15 +03001186
Johannes Berg6dbda2d2012-10-26 00:41:23 +02001187 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1188
1189 if (rx->skb->len < hdrlen + 8)
1190 return RX_DROP_MONITOR;
1191
1192 skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
1193 if (ethertype == rx->sdata->control_port_protocol)
Guy Eilam2a33bee2011-08-17 15:18:15 +03001194 return RX_CONTINUE;
1195 }
Johannes Berg21fc7562011-11-04 11:18:13 +01001196
1197 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1198 cfg80211_rx_spurious_frame(rx->sdata->dev,
1199 hdr->addr2,
1200 GFP_ATOMIC))
1201 return RX_DROP_UNUSABLE;
1202
Johannes Berge4c26ad2008-01-31 19:48:21 +01001203 return RX_DROP_MONITOR;
Guy Eilam2a33bee2011-08-17 15:18:15 +03001204 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001205
Johannes Berg9ae54c82008-01-31 19:48:20 +01001206 return RX_CONTINUE;
Johannes Berg570bd532007-07-27 15:43:22 +02001207}
1208
1209
Johannes Berg49461622008-06-30 15:10:45 +02001210static ieee80211_rx_result debug_noinline
Kalle Valo572e0012009-02-10 17:09:31 +02001211ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1212{
1213 struct ieee80211_local *local;
1214 struct ieee80211_hdr *hdr;
1215 struct sk_buff *skb;
1216
1217 local = rx->local;
1218 skb = rx->skb;
1219 hdr = (struct ieee80211_hdr *) skb->data;
1220
1221 if (!local->pspolling)
1222 return RX_CONTINUE;
1223
1224 if (!ieee80211_has_fromds(hdr->frame_control))
1225 /* this is not from AP */
1226 return RX_CONTINUE;
1227
1228 if (!ieee80211_is_data(hdr->frame_control))
1229 return RX_CONTINUE;
1230
1231 if (!ieee80211_has_moredata(hdr->frame_control)) {
1232 /* AP has no more frames buffered for us */
1233 local->pspolling = false;
1234 return RX_CONTINUE;
1235 }
1236
1237 /* more data bit is set, let's request a new frame from the AP */
1238 ieee80211_send_pspoll(local, rx->sdata);
1239
1240 return RX_CONTINUE;
1241}
1242
Marco Porschd012a602012-10-10 12:39:50 -07001243static void sta_ps_start(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001244{
Johannes Berg133b8222008-09-16 14:18:59 +02001245 struct ieee80211_sub_if_data *sdata = sta->sdata;
Christian Lamparter4571d3b2008-11-30 00:48:41 +01001246 struct ieee80211_local *local = sdata->local;
Marco Porschd012a602012-10-10 12:39:50 -07001247 struct ps_data *ps;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001248 int tid;
Joe Perches0795af52007-10-03 17:59:30 -07001249
Marco Porschd012a602012-10-10 12:39:50 -07001250 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1251 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1252 ps = &sdata->bss->ps;
1253 else
1254 return;
1255
1256 atomic_inc(&ps->num_sta_ps);
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001257 set_sta_flag(sta, WLAN_STA_PS_STA);
Johannes Berg30686bf2015-06-02 21:39:54 +02001258 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001259 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001260 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1261 sta->sta.addr, sta->sta.aid);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001262
Johannes Berg17c18bf2015-03-21 15:25:43 +01001263 ieee80211_clear_fast_xmit(sta);
1264
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001265 if (!sta->sta.txq[0])
1266 return;
1267
1268 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1269 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
1270
Michal Kaziorfa962b92016-05-19 10:37:49 +02001271 if (!txqi->tin.backlog_packets)
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001272 set_bit(tid, &sta->txq_buffered_tids);
1273 else
1274 clear_bit(tid, &sta->txq_buffered_tids);
1275 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001276}
1277
Marco Porschd012a602012-10-10 12:39:50 -07001278static void sta_ps_end(struct sta_info *sta)
Johannes Berg571ecf62007-07-27 15:43:22 +02001279{
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001280 ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1281 sta->sta.addr, sta->sta.aid);
Johannes Berg004c8722008-02-20 11:21:35 +01001282
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001283 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
Johannes Berge3685e02014-02-20 11:19:58 +01001284 /*
1285 * Clear the flag only if the other one is still set
1286 * so that the TX path won't start TX'ing new frames
1287 * directly ... In the case that the driver flag isn't
1288 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1289 */
1290 clear_sta_flag(sta, WLAN_STA_PS_STA);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001291 ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1292 sta->sta.addr, sta->sta.aid);
Johannes Bergaf818582009-11-06 11:35:50 +01001293 return;
1294 }
1295
Johannes Berg5ac2e352014-05-27 16:32:27 +02001296 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1297 clear_sta_flag(sta, WLAN_STA_PS_STA);
Johannes Bergaf818582009-11-06 11:35:50 +01001298 ieee80211_sta_ps_deliver_wakeup(sta);
Johannes Berg571ecf62007-07-27 15:43:22 +02001299}
1300
Johannes Bergcf471612015-06-16 16:16:38 +02001301int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001302{
Johannes Bergcf471612015-06-16 16:16:38 +02001303 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001304 bool in_ps;
1305
Johannes Bergcf471612015-06-16 16:16:38 +02001306 WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001307
1308 /* Don't let the same PS state be set twice */
Johannes Bergcf471612015-06-16 16:16:38 +02001309 in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001310 if ((start && in_ps) || (!start && !in_ps))
1311 return -EINVAL;
1312
1313 if (start)
Johannes Bergcf471612015-06-16 16:16:38 +02001314 sta_ps_start(sta);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001315 else
Johannes Bergcf471612015-06-16 16:16:38 +02001316 sta_ps_end(sta);
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001317
1318 return 0;
1319}
1320EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1321
Johannes Berg46fa38e2016-05-03 16:58:00 +03001322void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1323{
1324 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1325
1326 if (test_sta_flag(sta, WLAN_STA_SP))
1327 return;
1328
1329 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1330 ieee80211_sta_ps_deliver_poll_response(sta);
1331 else
1332 set_sta_flag(sta, WLAN_STA_PSPOLL);
1333}
1334EXPORT_SYMBOL(ieee80211_sta_pspoll);
1335
1336void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1337{
1338 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1339 u8 ac = ieee802_1d_to_ac[tid & 7];
1340
1341 /*
1342 * If this AC is not trigger-enabled do nothing.
1343 *
1344 * NB: This could/should check a separate bitmap of trigger-
1345 * enabled queues, but for now we only implement uAPSD w/o
1346 * TSPEC changes to the ACs, so they're always the same.
1347 */
1348 if (!(sta->sta.uapsd_queues & BIT(ac)))
1349 return;
1350
1351 /* if we are in a service period, do nothing */
1352 if (test_sta_flag(sta, WLAN_STA_SP))
1353 return;
1354
1355 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1356 ieee80211_sta_ps_deliver_uapsd(sta);
1357 else
1358 set_sta_flag(sta, WLAN_STA_UAPSD);
1359}
1360EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1361
Johannes Berg49461622008-06-30 15:10:45 +02001362static ieee80211_rx_result debug_noinline
Johannes Berg47086fc2011-09-29 16:04:33 +02001363ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1364{
1365 struct ieee80211_sub_if_data *sdata = rx->sdata;
1366 struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1367 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg47086fc2011-09-29 16:04:33 +02001368
Johannes Berg5c900672015-04-22 14:48:34 +02001369 if (!rx->sta)
Johannes Berg47086fc2011-09-29 16:04:33 +02001370 return RX_CONTINUE;
1371
1372 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1373 sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1374 return RX_CONTINUE;
1375
1376 /*
1377 * The device handles station powersave, so don't do anything about
1378 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1379 * it to mac80211 since they're handled.)
1380 */
Johannes Berg30686bf2015-06-02 21:39:54 +02001381 if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
Johannes Berg47086fc2011-09-29 16:04:33 +02001382 return RX_CONTINUE;
1383
1384 /*
1385 * Don't do anything if the station isn't already asleep. In
1386 * the uAPSD case, the station will probably be marked asleep,
1387 * in the PS-Poll case the station must be confused ...
1388 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001389 if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
Johannes Berg47086fc2011-09-29 16:04:33 +02001390 return RX_CONTINUE;
1391
1392 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
Johannes Berg46fa38e2016-05-03 16:58:00 +03001393 ieee80211_sta_pspoll(&rx->sta->sta);
Johannes Berg47086fc2011-09-29 16:04:33 +02001394
1395 /* Free PS Poll skb here instead of returning RX_DROP that would
1396 * count as an dropped frame. */
1397 dev_kfree_skb(rx->skb);
1398
1399 return RX_QUEUED;
1400 } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1401 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1402 ieee80211_has_pm(hdr->frame_control) &&
1403 (ieee80211_is_data_qos(hdr->frame_control) ||
1404 ieee80211_is_qos_nullfunc(hdr->frame_control))) {
Johannes Berg46fa38e2016-05-03 16:58:00 +03001405 u8 tid;
1406
Johannes Berg47086fc2011-09-29 16:04:33 +02001407 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
Johannes Berg47086fc2011-09-29 16:04:33 +02001408
Johannes Berg46fa38e2016-05-03 16:58:00 +03001409 ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
Johannes Berg47086fc2011-09-29 16:04:33 +02001410 }
1411
1412 return RX_CONTINUE;
1413}
1414
1415static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001416ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001417{
1418 struct sta_info *sta = rx->sta;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01001419 struct sk_buff *skb = rx->skb;
1420 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1421 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkauef0621e2013-04-22 16:29:31 +02001422 int i;
Johannes Berg571ecf62007-07-27 15:43:22 +02001423
1424 if (!sta)
Johannes Berg9ae54c82008-01-31 19:48:20 +01001425 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001426
Johannes Bergb291ba12009-07-10 15:29:03 +02001427 /*
1428 * Update last_rx only for IBSS packets which are for the current
Antonio Quartullie584da5e2012-11-25 23:13:42 +01001429 * BSSID and for station already AUTHORIZED to avoid keeping the
1430 * current IBSS network alive in cases where other STAs start
1431 * using different BSSID. This will also give the station another
1432 * chance to restart the authentication/authorization in case
1433 * something went wrong the first time.
Johannes Bergb291ba12009-07-10 15:29:03 +02001434 */
Johannes Berg05c914f2008-09-11 00:01:58 +02001435 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Ron Rindjunsky71364712007-12-25 17:00:36 +02001436 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
Johannes Berg05c914f2008-09-11 00:01:58 +02001437 NL80211_IFTYPE_ADHOC);
Antonio Quartullie584da5e2012-11-25 23:13:42 +01001438 if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1439 test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001440 sta->rx_stats.last_rx = jiffies;
Henning Roggef4ebddf2014-05-01 10:03:46 +02001441 if (ieee80211_is_data(hdr->frame_control) &&
Johannes Berg4f6b1b32016-03-31 20:02:08 +03001442 !is_multicast_ether_addr(hdr->addr1))
1443 sta->rx_stats.last_rate =
1444 sta_stats_encode_rate(status);
Felix Fietkau3af63342011-02-27 22:08:01 +01001445 }
Rostislav Lisovy239281f2014-11-03 10:33:19 +01001446 } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001447 sta->rx_stats.last_rx = jiffies;
Johannes Bergb291ba12009-07-10 15:29:03 +02001448 } else if (!is_multicast_ether_addr(hdr->addr1)) {
1449 /*
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001450 * Mesh beacons will update last_rx when if they are found to
1451 * match the current local configuration when processed.
Johannes Berg571ecf62007-07-27 15:43:22 +02001452 */
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001453 sta->rx_stats.last_rx = jiffies;
Johannes Berg4f6b1b32016-03-31 20:02:08 +03001454 if (ieee80211_is_data(hdr->frame_control))
1455 sta->rx_stats.last_rate = sta_stats_encode_rate(status);
Johannes Berg571ecf62007-07-27 15:43:22 +02001456 }
1457
Kalle Valo3cf335d2009-03-22 21:57:06 +02001458 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
1459 ieee80211_sta_rx_notify(rx->sdata, hdr);
1460
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001461 sta->rx_stats.fragments++;
Johannes Berg0f9c5a62016-03-31 20:02:09 +03001462
1463 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001464 sta->rx_stats.bytes += rx->skb->len;
Johannes Berg0f9c5a62016-03-31 20:02:09 +03001465 u64_stats_update_end(&rx->sta->rx_stats.syncp);
1466
Felix Fietkaufe8431f2012-03-01 18:00:07 +01001467 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001468 sta->rx_stats.last_signal = status->signal;
Johannes Berg0be6ed12016-03-31 20:02:05 +03001469 ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
Felix Fietkaufe8431f2012-03-01 18:00:07 +01001470 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001471
Felix Fietkauef0621e2013-04-22 16:29:31 +02001472 if (status->chains) {
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001473 sta->rx_stats.chains = status->chains;
Felix Fietkauef0621e2013-04-22 16:29:31 +02001474 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1475 int signal = status->chain_signal[i];
1476
1477 if (!(status->chains & BIT(i)))
1478 continue;
1479
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001480 sta->rx_stats.chain_signal_last[i] = signal;
Johannes Berg0be6ed12016-03-31 20:02:05 +03001481 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001482 -signal);
Felix Fietkauef0621e2013-04-22 16:29:31 +02001483 }
1484 }
1485
Johannes Berg72eaa432008-11-26 15:02:58 +01001486 /*
1487 * Change STA power saving mode only at the end of a frame
1488 * exchange sequence.
1489 */
Johannes Berg30686bf2015-06-02 21:39:54 +02001490 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001491 !ieee80211_has_morefrags(hdr->frame_control) &&
Christian Lamparter4cfda472010-12-27 23:21:26 +01001492 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001493 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
Johannes Bergb4ba5442014-01-24 14:41:44 +01001494 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1495 /* PM bit is only checked in frames where it isn't reserved,
1496 * in AP mode it's reserved in non-bufferable management frames
1497 * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1498 */
1499 (!ieee80211_is_mgmt(hdr->frame_control) ||
1500 ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001501 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
Johannes Bergb4ba5442014-01-24 14:41:44 +01001502 if (!ieee80211_has_pm(hdr->frame_control))
Marco Porschd012a602012-10-10 12:39:50 -07001503 sta_ps_end(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001504 } else {
1505 if (ieee80211_has_pm(hdr->frame_control))
Marco Porschd012a602012-10-10 12:39:50 -07001506 sta_ps_start(sta);
Johannes Berg72eaa432008-11-26 15:02:58 +01001507 }
Johannes Berg571ecf62007-07-27 15:43:22 +02001508 }
1509
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001510 /* mesh power save support */
1511 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1512 ieee80211_mps_rx_h_sta_process(sta, hdr);
1513
Johannes Berg22403de2009-10-30 12:55:03 +01001514 /*
1515 * Drop (qos-)data::nullfunc frames silently, since they
1516 * are used only to control station power saving mode.
1517 */
1518 if (ieee80211_is_nullfunc(hdr->frame_control) ||
1519 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001520 I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
Felix Fietkaud5242152010-01-08 18:06:26 +01001521
1522 /*
1523 * If we receive a 4-addr nullfunc frame from a STA
Johannes Berge7f4a942011-11-04 11:18:20 +01001524 * that was not moved to a 4-addr STA vlan yet send
1525 * the event to userspace and for older hostapd drop
1526 * the frame to the monitor interface.
Felix Fietkaud5242152010-01-08 18:06:26 +01001527 */
1528 if (ieee80211_has_a4(hdr->frame_control) &&
1529 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1530 (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
Johannes Berge7f4a942011-11-04 11:18:20 +01001531 !rx->sdata->u.vlan.sta))) {
1532 if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1533 cfg80211_rx_unexpected_4addr_frame(
1534 rx->sdata->dev, sta->sta.addr,
1535 GFP_ATOMIC);
Felix Fietkaud5242152010-01-08 18:06:26 +01001536 return RX_DROP_MONITOR;
Johannes Berge7f4a942011-11-04 11:18:20 +01001537 }
Johannes Berg22403de2009-10-30 12:55:03 +01001538 /*
1539 * Update counter and free packet here to avoid
1540 * counting this as a dropped packed.
1541 */
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001542 sta->rx_stats.packets++;
Johannes Berg571ecf62007-07-27 15:43:22 +02001543 dev_kfree_skb(rx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001544 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001545 }
1546
Johannes Berg9ae54c82008-01-31 19:48:20 +01001547 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001548} /* ieee80211_rx_h_sta_process */
1549
Johan Almbladh86c228a2013-08-14 15:29:46 +02001550static ieee80211_rx_result debug_noinline
1551ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1552{
1553 struct sk_buff *skb = rx->skb;
1554 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1555 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1556 int keyidx;
1557 int hdrlen;
1558 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1559 struct ieee80211_key *sta_ptk = NULL;
1560 int mmie_keyidx = -1;
1561 __le16 fc;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001562 const struct ieee80211_cipher_scheme *cs = NULL;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001563
1564 /*
1565 * Key selection 101
1566 *
1567 * There are four types of keys:
1568 * - GTK (group keys)
1569 * - IGTK (group keys for management frames)
1570 * - PTK (pairwise keys)
1571 * - STK (station-to-station pairwise keys)
1572 *
1573 * When selecting a key, we have to distinguish between multicast
1574 * (including broadcast) and unicast frames, the latter can only
1575 * use PTKs and STKs while the former always use GTKs and IGTKs.
1576 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
1577 * unicast frames can also use key indices like GTKs. Hence, if we
1578 * don't have a PTK/STK we check the key index for a WEP key.
1579 *
1580 * Note that in a regular BSS, multicast frames are sent by the
1581 * AP only, associated stations unicast the frame to the AP first
1582 * which then multicasts it on their behalf.
1583 *
1584 * There is also a slight problem in IBSS mode: GTKs are negotiated
1585 * with each station, that is something we don't currently handle.
1586 * The spec seems to expect that one negotiates the same key with
1587 * every station but there's no such requirement; VLANs could be
1588 * possible.
1589 */
1590
Johan Almbladh86c228a2013-08-14 15:29:46 +02001591 /* start without a key */
1592 rx->key = NULL;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001593 fc = hdr->frame_control;
1594
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001595 if (rx->sta) {
1596 int keyid = rx->sta->ptk_idx;
1597
1598 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
1599 cs = rx->sta->cipher_scheme;
Johannes Berg2c61cf92016-03-17 15:02:55 +02001600 keyid = ieee80211_get_cs_keyid(cs, rx->skb);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001601 if (unlikely(keyid < 0))
1602 return RX_DROP_UNUSABLE;
1603 }
1604 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1605 }
1606
Johan Almbladh86c228a2013-08-14 15:29:46 +02001607 if (!ieee80211_has_protected(fc))
1608 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1609
1610 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1611 rx->key = sta_ptk;
1612 if ((status->flag & RX_FLAG_DECRYPTED) &&
1613 (status->flag & RX_FLAG_IV_STRIPPED))
1614 return RX_CONTINUE;
1615 /* Skip decryption if the frame is not protected. */
1616 if (!ieee80211_has_protected(fc))
1617 return RX_CONTINUE;
1618 } else if (mmie_keyidx >= 0) {
1619 /* Broadcast/multicast robust management frame / BIP */
1620 if ((status->flag & RX_FLAG_DECRYPTED) &&
1621 (status->flag & RX_FLAG_IV_STRIPPED))
1622 return RX_CONTINUE;
1623
1624 if (mmie_keyidx < NUM_DEFAULT_KEYS ||
1625 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1626 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
Masashi Honma46f6b062016-06-22 19:55:20 +09001627 if (rx->sta) {
1628 if (ieee80211_is_group_privacy_action(skb) &&
1629 test_sta_flag(rx->sta, WLAN_STA_MFP))
1630 return RX_DROP_MONITOR;
1631
Johan Almbladh86c228a2013-08-14 15:29:46 +02001632 rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
Masashi Honma46f6b062016-06-22 19:55:20 +09001633 }
Johan Almbladh86c228a2013-08-14 15:29:46 +02001634 if (!rx->key)
1635 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
1636 } else if (!ieee80211_has_protected(fc)) {
1637 /*
1638 * The frame was not protected, so skip decryption. However, we
1639 * need to set rx->key if there is a key that could have been
1640 * used so that the frame may be dropped if encryption would
1641 * have been expected.
1642 */
1643 struct ieee80211_key *key = NULL;
1644 struct ieee80211_sub_if_data *sdata = rx->sdata;
1645 int i;
1646
1647 if (ieee80211_is_mgmt(fc) &&
1648 is_multicast_ether_addr(hdr->addr1) &&
1649 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
1650 rx->key = key;
1651 else {
1652 if (rx->sta) {
1653 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1654 key = rcu_dereference(rx->sta->gtk[i]);
1655 if (key)
1656 break;
1657 }
1658 }
1659 if (!key) {
1660 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1661 key = rcu_dereference(sdata->keys[i]);
1662 if (key)
1663 break;
1664 }
1665 }
1666 if (key)
1667 rx->key = key;
1668 }
1669 return RX_CONTINUE;
1670 } else {
1671 u8 keyid;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001672
Johan Almbladh86c228a2013-08-14 15:29:46 +02001673 /*
1674 * The device doesn't give us the IV so we won't be
1675 * able to look up the key. That's ok though, we
1676 * don't need to decrypt the frame, we just won't
1677 * be able to keep statistics accurate.
1678 * Except for key threshold notifications, should
1679 * we somehow allow the driver to tell us which key
1680 * the hardware used if this flag is set?
1681 */
1682 if ((status->flag & RX_FLAG_DECRYPTED) &&
1683 (status->flag & RX_FLAG_IV_STRIPPED))
1684 return RX_CONTINUE;
1685
1686 hdrlen = ieee80211_hdrlen(fc);
1687
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001688 if (cs) {
Johannes Berg2c61cf92016-03-17 15:02:55 +02001689 keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
Johan Almbladh86c228a2013-08-14 15:29:46 +02001690
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001691 if (unlikely(keyidx < 0))
1692 return RX_DROP_UNUSABLE;
1693 } else {
1694 if (rx->skb->len < 8 + hdrlen)
1695 return RX_DROP_UNUSABLE; /* TODO: count this? */
1696 /*
1697 * no need to call ieee80211_wep_get_keyidx,
1698 * it verifies a bunch of things we've done already
1699 */
1700 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1701 keyidx = keyid >> 6;
1702 }
Johan Almbladh86c228a2013-08-14 15:29:46 +02001703
1704 /* check per-station GTK first, if multicast packet */
1705 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
1706 rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
1707
1708 /* if not found, try default key */
1709 if (!rx->key) {
1710 rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
1711
1712 /*
1713 * RSNA-protected unicast frames should always be
1714 * sent with pairwise or station-to-station keys,
1715 * but for WEP we allow using a key index as well.
1716 */
1717 if (rx->key &&
1718 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1719 rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
1720 !is_multicast_ether_addr(hdr->addr1))
1721 rx->key = NULL;
1722 }
1723 }
1724
1725 if (rx->key) {
1726 if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
1727 return RX_DROP_MONITOR;
1728
Johan Almbladh86c228a2013-08-14 15:29:46 +02001729 /* TODO: add threshold stuff again */
1730 } else {
1731 return RX_DROP_MONITOR;
1732 }
1733
1734 switch (rx->key->conf.cipher) {
1735 case WLAN_CIPHER_SUITE_WEP40:
1736 case WLAN_CIPHER_SUITE_WEP104:
1737 result = ieee80211_crypto_wep_decrypt(rx);
1738 break;
1739 case WLAN_CIPHER_SUITE_TKIP:
1740 result = ieee80211_crypto_tkip_decrypt(rx);
1741 break;
1742 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +02001743 result = ieee80211_crypto_ccmp_decrypt(
1744 rx, IEEE80211_CCMP_MIC_LEN);
1745 break;
1746 case WLAN_CIPHER_SUITE_CCMP_256:
1747 result = ieee80211_crypto_ccmp_decrypt(
1748 rx, IEEE80211_CCMP_256_MIC_LEN);
Johan Almbladh86c228a2013-08-14 15:29:46 +02001749 break;
1750 case WLAN_CIPHER_SUITE_AES_CMAC:
1751 result = ieee80211_crypto_aes_cmac_decrypt(rx);
1752 break;
Jouni Malinen56c52da2015-01-24 19:52:08 +02001753 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1754 result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
1755 break;
Jouni Malinen8ade5382015-01-24 19:52:09 +02001756 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1757 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1758 result = ieee80211_crypto_aes_gmac_decrypt(rx);
1759 break;
Jouni Malinen00b9cfa2015-01-24 19:52:06 +02001760 case WLAN_CIPHER_SUITE_GCMP:
1761 case WLAN_CIPHER_SUITE_GCMP_256:
1762 result = ieee80211_crypto_gcmp_decrypt(rx);
1763 break;
Johan Almbladh86c228a2013-08-14 15:29:46 +02001764 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001765 result = ieee80211_crypto_hw_decrypt(rx);
Johan Almbladh86c228a2013-08-14 15:29:46 +02001766 }
1767
1768 /* the hdr variable is invalid after the decrypt handlers */
1769
1770 /* either the frame has been decrypted or will be dropped */
1771 status->flag |= RX_FLAG_DECRYPTED;
1772
1773 return result;
1774}
1775
Johannes Berg571ecf62007-07-27 15:43:22 +02001776static inline struct ieee80211_fragment_entry *
1777ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1778 unsigned int frag, unsigned int seq, int rx_queue,
1779 struct sk_buff **skb)
1780{
1781 struct ieee80211_fragment_entry *entry;
Johannes Berg571ecf62007-07-27 15:43:22 +02001782
Johannes Berg571ecf62007-07-27 15:43:22 +02001783 entry = &sdata->fragments[sdata->fragment_next++];
1784 if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
1785 sdata->fragment_next = 0;
1786
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001787 if (!skb_queue_empty(&entry->skb_list))
Johannes Berg571ecf62007-07-27 15:43:22 +02001788 __skb_queue_purge(&entry->skb_list);
Johannes Berg571ecf62007-07-27 15:43:22 +02001789
1790 __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
1791 *skb = NULL;
1792 entry->first_frag_time = jiffies;
1793 entry->seq = seq;
1794 entry->rx_queue = rx_queue;
1795 entry->last_frag = frag;
Johannes Berg9acc54b2016-02-26 22:13:40 +01001796 entry->check_sequential_pn = false;
Johannes Berg571ecf62007-07-27 15:43:22 +02001797 entry->extra_len = 0;
1798
1799 return entry;
1800}
1801
1802static inline struct ieee80211_fragment_entry *
1803ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001804 unsigned int frag, unsigned int seq,
Johannes Berg571ecf62007-07-27 15:43:22 +02001805 int rx_queue, struct ieee80211_hdr *hdr)
1806{
1807 struct ieee80211_fragment_entry *entry;
1808 int i, idx;
1809
1810 idx = sdata->fragment_next;
1811 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
1812 struct ieee80211_hdr *f_hdr;
Johannes Berg571ecf62007-07-27 15:43:22 +02001813
1814 idx--;
1815 if (idx < 0)
1816 idx = IEEE80211_FRAGMENT_MAX - 1;
1817
1818 entry = &sdata->fragments[idx];
1819 if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
1820 entry->rx_queue != rx_queue ||
1821 entry->last_frag + 1 != frag)
1822 continue;
1823
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001824 f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001825
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001826 /*
1827 * Check ftype and addresses are equal, else check next fragment
1828 */
1829 if (((hdr->frame_control ^ f_hdr->frame_control) &
1830 cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
Joe Perchesb203ca32012-05-08 18:56:52 +00001831 !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
1832 !ether_addr_equal(hdr->addr2, f_hdr->addr2))
Johannes Berg571ecf62007-07-27 15:43:22 +02001833 continue;
1834
S.Çağlar Onurab466232008-02-14 17:36:47 +02001835 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001836 __skb_queue_purge(&entry->skb_list);
1837 continue;
1838 }
1839 return entry;
1840 }
1841
1842 return NULL;
1843}
1844
Johannes Berg49461622008-06-30 15:10:45 +02001845static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01001846ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001847{
1848 struct ieee80211_hdr *hdr;
1849 u16 sc;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001850 __le16 fc;
Johannes Berg571ecf62007-07-27 15:43:22 +02001851 unsigned int frag, seq;
1852 struct ieee80211_fragment_entry *entry;
1853 struct sk_buff *skb;
Johannes Berg554891e2010-09-24 12:38:25 +02001854 struct ieee80211_rx_status *status;
Johannes Berg571ecf62007-07-27 15:43:22 +02001855
Harvey Harrisonb73d70a2008-07-15 18:44:12 -07001856 hdr = (struct ieee80211_hdr *)rx->skb->data;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001857 fc = hdr->frame_control;
Javier Cardonaf7fbf702012-10-25 11:10:18 -07001858
1859 if (ieee80211_is_ctl(fc))
1860 return RX_CONTINUE;
1861
Johannes Berg571ecf62007-07-27 15:43:22 +02001862 sc = le16_to_cpu(hdr->seq_ctrl);
1863 frag = sc & IEEE80211_SCTL_FRAG;
1864
Johannes Bergb8fff402014-11-03 13:57:46 +01001865 if (is_multicast_ether_addr(hdr->addr1)) {
Johannes Bergc206ca62015-04-22 20:47:28 +02001866 I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
Andreas Müllerd0259332014-12-12 12:11:11 +01001867 goto out_no_led;
Johannes Berg571ecf62007-07-27 15:43:22 +02001868 }
Johannes Bergb8fff402014-11-03 13:57:46 +01001869
Andreas Müllerd0259332014-12-12 12:11:11 +01001870 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
1871 goto out;
1872
Johannes Berg571ecf62007-07-27 15:43:22 +02001873 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1874
Zhu Yie3cf8b32010-03-29 17:35:07 +08001875 if (skb_linearize(rx->skb))
1876 return RX_DROP_UNUSABLE;
1877
Abhijeet Kolekar058897a2010-05-11 11:22:11 -07001878 /*
1879 * skb_linearize() might change the skb->data and
1880 * previously cached variables (in this case, hdr) need to
1881 * be refreshed with the new data.
1882 */
1883 hdr = (struct ieee80211_hdr *)rx->skb->data;
Johannes Berg571ecf62007-07-27 15:43:22 +02001884 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1885
1886 if (frag == 0) {
1887 /* This is the first fragment of a new frame. */
1888 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
Johannes Berg9e262972011-07-07 18:45:03 +02001889 rx->seqno_idx, &(rx->skb));
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +02001890 if (rx->key &&
1891 (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
Johannes Berg9acc54b2016-02-26 22:13:40 +01001892 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
1893 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
1894 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
Harvey Harrison358c8d92008-07-15 18:44:13 -07001895 ieee80211_has_protected(fc)) {
Johannes Berg9e262972011-07-07 18:45:03 +02001896 int queue = rx->security_idx;
Johannes Berg9acc54b2016-02-26 22:13:40 +01001897
1898 /* Store CCMP/GCMP PN so that we can verify that the
1899 * next fragment has a sequential PN value.
1900 */
1901 entry->check_sequential_pn = true;
Johannes Berg571ecf62007-07-27 15:43:22 +02001902 memcpy(entry->last_pn,
Jouni Malinen91902522010-06-11 10:27:33 -07001903 rx->key->u.ccmp.rx_pn[queue],
Johannes Berg4325f6c2013-05-08 13:09:08 +02001904 IEEE80211_CCMP_PN_LEN);
Johannes Berg9acc54b2016-02-26 22:13:40 +01001905 BUILD_BUG_ON(offsetof(struct ieee80211_key,
1906 u.ccmp.rx_pn) !=
1907 offsetof(struct ieee80211_key,
1908 u.gcmp.rx_pn));
1909 BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
1910 sizeof(rx->key->u.gcmp.rx_pn[queue]));
1911 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
1912 IEEE80211_GCMP_PN_LEN);
Johannes Berg571ecf62007-07-27 15:43:22 +02001913 }
Johannes Berg9ae54c82008-01-31 19:48:20 +01001914 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001915 }
1916
1917 /* This is a fragment for a frame that should already be pending in
1918 * fragment cache. Add this fragment to the end of the pending entry.
1919 */
Johannes Berg9e262972011-07-07 18:45:03 +02001920 entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
1921 rx->seqno_idx, hdr);
Johannes Berg571ecf62007-07-27 15:43:22 +02001922 if (!entry) {
1923 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001924 return RX_DROP_MONITOR;
Johannes Berg571ecf62007-07-27 15:43:22 +02001925 }
1926
Johannes Berg9acc54b2016-02-26 22:13:40 +01001927 /* "The receiver shall discard MSDUs and MMPDUs whose constituent
1928 * MPDU PN values are not incrementing in steps of 1."
1929 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
1930 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
1931 */
1932 if (entry->check_sequential_pn) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001933 int i;
Johannes Berg4325f6c2013-05-08 13:09:08 +02001934 u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
Jouni Malinen91902522010-06-11 10:27:33 -07001935 int queue;
Johannes Berg9acc54b2016-02-26 22:13:40 +01001936
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +02001937 if (!rx->key ||
1938 (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
Johannes Berg9acc54b2016-02-26 22:13:40 +01001939 rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 &&
1940 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP &&
1941 rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001942 return RX_DROP_UNUSABLE;
Johannes Berg4325f6c2013-05-08 13:09:08 +02001943 memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
1944 for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001945 pn[i]++;
1946 if (pn[i])
1947 break;
1948 }
Johannes Berg9e262972011-07-07 18:45:03 +02001949 queue = rx->security_idx;
Jouni Malinen91902522010-06-11 10:27:33 -07001950 rpn = rx->key->u.ccmp.rx_pn[queue];
Johannes Berg4325f6c2013-05-08 13:09:08 +02001951 if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
Johannes Berge4c26ad2008-01-31 19:48:21 +01001952 return RX_DROP_UNUSABLE;
Johannes Berg4325f6c2013-05-08 13:09:08 +02001953 memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
Johannes Berg571ecf62007-07-27 15:43:22 +02001954 }
1955
Harvey Harrison358c8d92008-07-15 18:44:13 -07001956 skb_pull(rx->skb, ieee80211_hdrlen(fc));
Johannes Berg571ecf62007-07-27 15:43:22 +02001957 __skb_queue_tail(&entry->skb_list, rx->skb);
1958 entry->last_frag = frag;
1959 entry->extra_len += rx->skb->len;
Harvey Harrison358c8d92008-07-15 18:44:13 -07001960 if (ieee80211_has_morefrags(fc)) {
Johannes Berg571ecf62007-07-27 15:43:22 +02001961 rx->skb = NULL;
Johannes Berg9ae54c82008-01-31 19:48:20 +01001962 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02001963 }
1964
1965 rx->skb = __skb_dequeue(&entry->skb_list);
1966 if (skb_tailroom(rx->skb) < entry->extra_len) {
Johannes Bergf1160432015-04-22 20:25:20 +02001967 I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
Johannes Berg571ecf62007-07-27 15:43:22 +02001968 if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
1969 GFP_ATOMIC))) {
1970 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
1971 __skb_queue_purge(&entry->skb_list);
Johannes Berge4c26ad2008-01-31 19:48:21 +01001972 return RX_DROP_UNUSABLE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001973 }
1974 }
1975 while ((skb = __skb_dequeue(&entry->skb_list))) {
1976 memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
1977 dev_kfree_skb(skb);
1978 }
1979
1980 /* Complete frame has been reassembled - process it now */
Johannes Berg554891e2010-09-24 12:38:25 +02001981 status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02001982
1983 out:
Andreas Müllerd0259332014-12-12 12:11:11 +01001984 ieee80211_led_rx(rx->local);
1985 out_no_led:
Johannes Berg571ecf62007-07-27 15:43:22 +02001986 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001987 rx->sta->rx_stats.packets++;
Johannes Berg9ae54c82008-01-31 19:48:20 +01001988 return RX_CONTINUE;
Johannes Berg571ecf62007-07-27 15:43:22 +02001989}
1990
Johannes Berg1df332e2012-10-26 00:09:11 +02001991static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02001992{
Johannes Berg1df332e2012-10-26 00:09:11 +02001993 if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001994 return -EACCES;
Johannes Berg571ecf62007-07-27 15:43:22 +02001995
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02001996 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02001997}
1998
Johannes Berg1df332e2012-10-26 00:09:11 +02001999static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Berg571ecf62007-07-27 15:43:22 +02002000{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002001 struct sk_buff *skb = rx->skb;
2002 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2003
Johannes Berg3017b802007-08-28 17:01:53 -04002004 /*
Johannes Berg7848ba72007-09-14 11:10:25 -04002005 * Pass through unencrypted frames if the hardware has
2006 * decrypted them already.
Johannes Berg3017b802007-08-28 17:01:53 -04002007 */
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002008 if (status->flag & RX_FLAG_DECRYPTED)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002009 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02002010
2011 /* Drop unencrypted frames if key is set. */
Harvey Harrison358c8d92008-07-15 18:44:13 -07002012 if (unlikely(!ieee80211_has_protected(fc) &&
2013 !ieee80211_is_nullfunc(fc) &&
Johannes Berge8f4fb72015-03-20 11:37:36 +01002014 ieee80211_is_data(fc) && rx->key))
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002015 return -EACCES;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002016
2017 return 0;
2018}
2019
Johannes Berg1df332e2012-10-26 00:09:11 +02002020static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002021{
2022 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Jouni Malinene3efca02010-03-28 22:31:15 -07002023 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002024 __le16 fc = hdr->frame_control;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002025
Jouni Malinene3efca02010-03-28 22:31:15 -07002026 /*
2027 * Pass through unencrypted frames if the hardware has
2028 * decrypted them already.
2029 */
2030 if (status->flag & RX_FLAG_DECRYPTED)
2031 return 0;
Johannes Bergbef5d1c2010-02-16 11:05:00 +01002032
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002033 if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
Jouni Malinend211e902010-03-28 22:29:52 -07002034 if (unlikely(!ieee80211_has_protected(fc) &&
2035 ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02002036 rx->key)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002037 if (ieee80211_is_deauth(fc) ||
2038 ieee80211_is_disassoc(fc))
2039 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2040 rx->skb->data,
2041 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002042 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02002043 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002044 /* BIP does not use Protected field, so need to check MMIE */
Joe Perchesf64f9e72009-11-29 16:55:45 -08002045 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
Jouni Malinencf4e5942010-12-16 00:52:40 +02002046 ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002047 if (ieee80211_is_deauth(fc) ||
2048 ieee80211_is_disassoc(fc))
2049 cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2050 rx->skb->data,
2051 rx->skb->len);
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002052 return -EACCES;
Jouni Malinencf4e5942010-12-16 00:52:40 +02002053 }
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002054 /*
2055 * When using MFP, Action frames are not allowed prior to
2056 * having configured keys.
2057 */
2058 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
Johannes Bergd8ca16d2014-01-23 16:20:29 +01002059 ieee80211_is_robust_mgmt_frame(rx->skb)))
Jouni Malinenf2ca3ea2009-05-08 12:36:03 +03002060 return -EACCES;
2061 }
Johannes Bergb3fc9c62008-04-13 10:12:47 +02002062
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002063 return 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02002064}
2065
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002066static int
Felix Fietkau4114fa22011-04-12 19:15:22 +02002067__ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
Johannes Berg571ecf62007-07-27 15:43:22 +02002068{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002069 struct ieee80211_sub_if_data *sdata = rx->sdata;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002070 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002071 bool check_port_control = false;
2072 struct ethhdr *ehdr;
2073 int ret;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002074
Felix Fietkau4114fa22011-04-12 19:15:22 +02002075 *port_control = false;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002076 if (ieee80211_has_a4(hdr->frame_control) &&
2077 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002078 return -1;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002079
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002080 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2081 !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2082
2083 if (!sdata->u.mgd.use_4addr)
2084 return -1;
2085 else
2086 check_port_control = true;
2087 }
2088
Johannes Berg9bc383d2009-11-19 11:55:19 +01002089 if (is_multicast_ether_addr(hdr->addr1) &&
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002090 sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002091 return -1;
Johannes Berg571ecf62007-07-27 15:43:22 +02002092
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002093 ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
Felix Fietkau4114fa22011-04-12 19:15:22 +02002094 if (ret < 0)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002095 return ret;
2096
2097 ehdr = (struct ethhdr *) rx->skb->data;
Felix Fietkau4114fa22011-04-12 19:15:22 +02002098 if (ehdr->h_proto == rx->sdata->control_port_protocol)
2099 *port_control = true;
2100 else if (check_port_control)
Felix Fietkaufbb327c2011-01-18 15:48:48 +01002101 return -1;
2102
2103 return 0;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002104}
Johannes Berg571ecf62007-07-27 15:43:22 +02002105
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002106/*
2107 * requires that rx->skb is a frame with ethernet header
2108 */
Harvey Harrison358c8d92008-07-15 18:44:13 -07002109static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002110{
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05302111 static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002112 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2113 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2114
2115 /*
2116 * Allow EAPOL frames to us/the PAE group address regardless
2117 * of whether the frame was encrypted or not.
2118 */
Johannes Berga621fa42010-08-27 14:26:54 +03002119 if (ehdr->h_proto == rx->sdata->control_port_protocol &&
Joe Perches3bc79452012-05-08 18:56:53 +00002120 (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2121 ether_addr_equal(ehdr->h_dest, pae_group_addr)))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002122 return true;
2123
2124 if (ieee80211_802_1x_port_control(rx) ||
Harvey Harrison358c8d92008-07-15 18:44:13 -07002125 ieee80211_drop_unencrypted(rx, fc))
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002126 return false;
2127
2128 return true;
2129}
2130
2131/*
2132 * requires that rx->skb is a frame with ethernet header
2133 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002134static void
Johannes Berg5cf121c2008-02-25 16:27:43 +01002135ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002136{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002137 struct ieee80211_sub_if_data *sdata = rx->sdata;
2138 struct net_device *dev = sdata->dev;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002139 struct sk_buff *skb, *xmit_skb;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002140 struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2141 struct sta_info *dsta;
Johannes Berg571ecf62007-07-27 15:43:22 +02002142
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002143 skb = rx->skb;
2144 xmit_skb = NULL;
Johannes Berg571ecf62007-07-27 15:43:22 +02002145
Johannes Berg5a490512015-04-22 17:10:38 +02002146 ieee80211_rx_stats(dev, skb->len);
2147
Johannes Bergde8f18d2016-03-31 20:02:03 +03002148 if (rx->sta) {
2149 /* The seqno index has the same property as needed
2150 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2151 * for non-QoS-data frames. Here we know it's a data
2152 * frame, so count MSDUs.
2153 */
Johannes Berg0f9c5a62016-03-31 20:02:09 +03002154 u64_stats_update_begin(&rx->sta->rx_stats.syncp);
Johannes Bergde8f18d2016-03-31 20:02:03 +03002155 rx->sta->rx_stats.msdu[rx->seqno_idx]++;
Johannes Berg0f9c5a62016-03-31 20:02:09 +03002156 u64_stats_update_end(&rx->sta->rx_stats.syncp);
Johannes Bergde8f18d2016-03-31 20:02:03 +03002157 }
2158
Johannes Berg05c914f2008-09-11 00:01:58 +02002159 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2160 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
Johannes Berg213cd112008-09-11 00:01:54 +02002161 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
Johannes Berg9bc383d2009-11-19 11:55:19 +01002162 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002163 if (is_multicast_ether_addr(ehdr->h_dest)) {
2164 /*
2165 * send multicast frames both to higher layers in
2166 * local net stack and back to the wireless medium
2167 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002168 xmit_skb = skb_copy(skb, GFP_ATOMIC);
Joe Perchese87cc472012-05-13 21:56:26 +00002169 if (!xmit_skb)
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002170 net_info_ratelimited("%s: failed to clone multicast frame\n",
Joe Perchese87cc472012-05-13 21:56:26 +00002171 dev->name);
Johannes Berg571ecf62007-07-27 15:43:22 +02002172 } else {
Johannes Bergabe60632009-11-25 17:46:18 +01002173 dsta = sta_info_get(sdata, skb->data);
2174 if (dsta) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002175 /*
2176 * The destination station is associated to
2177 * this AP (in this VLAN), so send the frame
2178 * directly to it and do not pass it to local
2179 * net stack.
Johannes Berg571ecf62007-07-27 15:43:22 +02002180 */
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002181 xmit_skb = skb;
Johannes Berg571ecf62007-07-27 15:43:22 +02002182 skb = NULL;
2183 }
Johannes Berg571ecf62007-07-27 15:43:22 +02002184 }
2185 }
2186
Kalle Valo59d9cb02009-12-17 13:54:57 +01002187#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002188 if (skb) {
2189 /* 'align' will only take the values 0 or 2 here since all
2190 * frames are required to be aligned to 2-byte boundaries
2191 * when being passed to mac80211; the code here works just
2192 * as well if that isn't true, but mac80211 assumes it can
2193 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
Johannes Bergd1c3a372009-01-07 00:26:10 +01002194 */
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002195 int align;
2196
2197 align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
Johannes Bergd1c3a372009-01-07 00:26:10 +01002198 if (align) {
2199 if (WARN_ON(skb_headroom(skb) < 3)) {
2200 dev_kfree_skb(skb);
2201 skb = NULL;
2202 } else {
2203 u8 *data = skb->data;
Zhu Yi8ce0b582009-10-28 13:13:52 -07002204 size_t len = skb_headlen(skb);
2205 skb->data -= align;
2206 memmove(skb->data, data, len);
2207 skb_set_tail_pointer(skb, len);
Johannes Bergd1c3a372009-01-07 00:26:10 +01002208 }
2209 }
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002210 }
Johannes Bergd1c3a372009-01-07 00:26:10 +01002211#endif
2212
Johannes Berg9e890a1f2013-12-04 09:16:31 +01002213 if (skb) {
2214 /* deliver to local stack */
2215 skb->protocol = eth_type_trans(skb, dev);
2216 memset(skb->cb, 0, sizeof(skb->cb));
Johannes Bergaf9f9b22015-06-11 16:02:32 +02002217 if (rx->napi)
2218 napi_gro_receive(rx->napi, skb);
Johannes Berg06d181a2014-02-04 20:51:09 +01002219 else
2220 netif_receive_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02002221 }
2222
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002223 if (xmit_skb) {
Helmut Schaaaef6c922011-12-21 09:11:35 +01002224 /*
2225 * Send to wireless media and increase priority by 256 to
2226 * keep the received priority instead of reclassifying
2227 * the frame (see cfg80211_classify8021d).
2228 */
2229 xmit_skb->priority += 256;
YOSHIFUJI Hideakif831e902007-12-12 03:54:23 +09002230 xmit_skb->protocol = htons(ETH_P_802_3);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002231 skb_reset_network_header(xmit_skb);
2232 skb_reset_mac_header(xmit_skb);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002233 dev_queue_xmit(xmit_skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02002234 }
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002235}
2236
Johannes Berg49461622008-06-30 15:10:45 +02002237static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002238ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002239{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002240 struct net_device *dev = rx->sdata->dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08002241 struct sk_buff *skb = rx->skb;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002242 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2243 __le16 fc = hdr->frame_control;
Zhu Yieaf85ca2009-12-01 10:18:37 +08002244 struct sk_buff_head frame_list;
Johannes Berg554891e2010-09-24 12:38:25 +02002245 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002246
Harvey Harrison358c8d92008-07-15 18:44:13 -07002247 if (unlikely(!ieee80211_is_data(fc)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002248 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002249
Harvey Harrison358c8d92008-07-15 18:44:13 -07002250 if (unlikely(!ieee80211_is_data_present(fc)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002251 return RX_DROP_MONITOR;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002252
Johannes Berg554891e2010-09-24 12:38:25 +02002253 if (!(status->rx_flags & IEEE80211_RX_AMSDU))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002254 return RX_CONTINUE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002255
Zhu Yieaf85ca2009-12-01 10:18:37 +08002256 if (ieee80211_has_a4(hdr->frame_control) &&
2257 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2258 !rx->sdata->u.vlan.sta)
2259 return RX_DROP_UNUSABLE;
2260
2261 if (is_multicast_ether_addr(hdr->addr1) &&
2262 ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2263 rx->sdata->u.vlan.sta) ||
2264 (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
2265 rx->sdata->u.mgd.use_4addr)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002266 return RX_DROP_UNUSABLE;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002267
2268 skb->dev = dev;
Zhu Yieaf85ca2009-12-01 10:18:37 +08002269 __skb_queue_head_init(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002270
Zhu Yieaf85ca2009-12-01 10:18:37 +08002271 ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2272 rx->sdata->vif.type,
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -07002273 rx->local->hw.extra_tx_headroom, true);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002274
Zhu Yieaf85ca2009-12-01 10:18:37 +08002275 while (!skb_queue_empty(&frame_list)) {
2276 rx->skb = __skb_dequeue(&frame_list);
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002277
Harvey Harrison358c8d92008-07-15 18:44:13 -07002278 if (!ieee80211_frame_allowed(rx, fc)) {
Zhu Yieaf85ca2009-12-01 10:18:37 +08002279 dev_kfree_skb(rx->skb);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002280 continue;
2281 }
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002282
2283 ieee80211_deliver_skb(rx);
2284 }
2285
Johannes Berg9ae54c82008-01-31 19:48:20 +01002286 return RX_QUEUED;
Ron Rindjunskyfd4c7f22007-11-26 16:14:33 +02002287}
2288
Ingo Molnarbf94e172008-10-12 23:51:38 -07002289#ifdef CONFIG_MAC80211_MESH
Davide Pesaventob0dee572008-09-27 17:29:12 +02002290static ieee80211_rx_result
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002291ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2292{
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002293 struct ieee80211_hdr *fwd_hdr, *hdr;
2294 struct ieee80211_tx_info *info;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002295 struct ieee80211s_hdr *mesh_hdr;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002296 struct sk_buff *skb = rx->skb, *fwd_skb;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02002297 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002298 struct ieee80211_sub_if_data *sdata = rx->sdata;
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002299 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Michal Kaziorcf440122016-01-25 14:43:24 +01002300 u16 ac, q, hdrlen;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002301
2302 hdr = (struct ieee80211_hdr *) skb->data;
2303 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Johannes Berg9b395bc2012-10-26 00:36:40 +02002304
2305 /* make sure fixed part of mesh header is there, also checks skb len */
2306 if (!pskb_may_pull(rx->skb, hdrlen + 6))
2307 return RX_DROP_MONITOR;
2308
2309 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2310
2311 /* make sure full mesh header is there, also checks skb len */
2312 if (!pskb_may_pull(rx->skb,
2313 hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2314 return RX_DROP_MONITOR;
2315
2316 /* reload pointers */
2317 hdr = (struct ieee80211_hdr *) skb->data;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002318 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2319
Bob Copelandd0c22112015-03-02 14:28:52 -05002320 if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2321 return RX_DROP_MONITOR;
2322
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07002323 /* frame is in RMC, don't forward */
2324 if (ieee80211_is_data(hdr->frame_control) &&
2325 is_multicast_ether_addr(hdr->addr1) &&
Johannes Bergbf7cd942013-02-15 14:40:31 +01002326 mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
Thomas Pedersen2157fdd2011-09-01 12:32:14 -07002327 return RX_DROP_MONITOR;
2328
Johannes Berg5c900672015-04-22 14:48:34 +02002329 if (!ieee80211_is_data(hdr->frame_control))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002330 return RX_CONTINUE;
2331
2332 if (!mesh_hdr->ttl)
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002333 return RX_DROP_MONITOR;
2334
Javier Cardona43b7b312009-10-15 18:10:51 -07002335 if (mesh_hdr->flags & MESH_FLAGS_AE) {
YanBo79617de2008-09-22 13:30:32 +08002336 struct mesh_path *mppath;
Javier Cardona43b7b312009-10-15 18:10:51 -07002337 char *proxied_addr;
2338 char *mpp_addr;
2339
2340 if (is_multicast_ether_addr(hdr->addr1)) {
2341 mpp_addr = hdr->addr3;
2342 proxied_addr = mesh_hdr->eaddr1;
Johannes Berg9b395bc2012-10-26 00:36:40 +02002343 } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
2344 /* has_a4 already checked in ieee80211_rx_mesh_check */
Javier Cardona43b7b312009-10-15 18:10:51 -07002345 mpp_addr = hdr->addr4;
2346 proxied_addr = mesh_hdr->eaddr2;
Johannes Berg9b395bc2012-10-26 00:36:40 +02002347 } else {
2348 return RX_DROP_MONITOR;
Javier Cardona43b7b312009-10-15 18:10:51 -07002349 }
YanBo79617de2008-09-22 13:30:32 +08002350
YanBo79617de2008-09-22 13:30:32 +08002351 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01002352 mppath = mpp_path_lookup(sdata, proxied_addr);
YanBo79617de2008-09-22 13:30:32 +08002353 if (!mppath) {
Johannes Bergbf7cd942013-02-15 14:40:31 +01002354 mpp_path_add(sdata, proxied_addr, mpp_addr);
YanBo79617de2008-09-22 13:30:32 +08002355 } else {
2356 spin_lock_bh(&mppath->state_lock);
Joe Perchesb203ca32012-05-08 18:56:52 +00002357 if (!ether_addr_equal(mppath->mpp, mpp_addr))
Javier Cardona43b7b312009-10-15 18:10:51 -07002358 memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
Henning Roggeab1c7902016-02-03 13:58:37 +01002359 mppath->exp_time = jiffies;
YanBo79617de2008-09-22 13:30:32 +08002360 spin_unlock_bh(&mppath->state_lock);
2361 }
2362 rcu_read_unlock();
2363 }
2364
Javier Cardona3c5772a2009-08-10 12:15:48 -07002365 /* Frame has reached destination. Don't forward */
2366 if (!is_multicast_ether_addr(hdr->addr1) &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002367 ether_addr_equal(sdata->vif.addr, hdr->addr3))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002368 return RX_CONTINUE;
2369
Michal Kaziorcf440122016-01-25 14:43:24 +01002370 ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2371 q = sdata->vif.hw_queue[ac];
Thomas Pedersend3c15972011-11-24 17:15:23 -08002372 if (ieee80211_queue_stopped(&local->hw, q)) {
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002373 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
Thomas Pedersend3c15972011-11-24 17:15:23 -08002374 return RX_DROP_MONITOR;
2375 }
2376 skb_set_queue_mapping(skb, q);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002377
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002378 if (!--mesh_hdr->ttl) {
2379 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
Javier Cardona2ac64cd2012-10-24 12:43:31 -07002380 goto out;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002381 }
2382
Chun-Yeow Yeohd6655082012-03-02 02:03:19 +08002383 if (!ifmsh->mshcfg.dot11MeshForwarding)
2384 goto out;
2385
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002386 fwd_skb = skb_copy(skb, GFP_ATOMIC);
2387 if (!fwd_skb) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002388 net_info_ratelimited("%s: failed to clone mesh frame\n",
Joe Perchese87cc472012-05-13 21:56:26 +00002389 sdata->name);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002390 goto out;
2391 }
2392
2393 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
Thomas Pedersen9d6d6f42013-04-08 11:06:12 -07002394 fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002395 info = IEEE80211_SKB_CB(fwd_skb);
2396 memset(info, 0, sizeof(*info));
2397 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
2398 info->control.vif = &rx->sdata->vif;
2399 info->control.jiffies = jiffies;
2400 if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2401 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2402 memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002403 /* update power mode indication when forwarding */
2404 ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
Johannes Bergbf7cd942013-02-15 14:40:31 +01002405 } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002406 /* mesh power mode flags updated in mesh_nexthop_lookup */
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002407 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2408 } else {
2409 /* unable to resolve next hop */
Johannes Bergbf7cd942013-02-15 14:40:31 +01002410 mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
Chun-Yeow Yeohf63f8422013-11-13 15:39:12 +08002411 fwd_hdr->addr3, 0,
2412 WLAN_REASON_MESH_PATH_NOFORWARD,
2413 fwd_hdr->addr2);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002414 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
Jesper Juhl74b8cc32012-01-14 21:52:17 +01002415 kfree_skb(fwd_skb);
Thomas Pedersen30789eb2011-11-24 17:15:26 -08002416 return RX_DROP_MONITOR;
2417 }
2418
2419 IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2420 ieee80211_add_pending_skb(local, fwd_skb);
Johannes Bergb51aff02010-12-22 10:15:07 +01002421 out:
Johannes Bergdf140462015-04-22 14:40:58 +02002422 if (is_multicast_ether_addr(hdr->addr1))
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002423 return RX_CONTINUE;
Johannes Bergdf140462015-04-22 14:40:58 +02002424 return RX_DROP_MONITOR;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002425}
Ingo Molnarbf94e172008-10-12 23:51:38 -07002426#endif
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02002427
2428static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01002429ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002430{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002431 struct ieee80211_sub_if_data *sdata = rx->sdata;
Vivek Natarajane15276a2010-02-08 17:47:01 +05302432 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002433 struct net_device *dev = sdata->dev;
Harvey Harrison358c8d92008-07-15 18:44:13 -07002434 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2435 __le16 fc = hdr->frame_control;
Felix Fietkau4114fa22011-04-12 19:15:22 +02002436 bool port_control;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002437 int err;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002438
Harvey Harrison358c8d92008-07-15 18:44:13 -07002439 if (unlikely(!ieee80211_is_data(hdr->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002440 return RX_CONTINUE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002441
Harvey Harrison358c8d92008-07-15 18:44:13 -07002442 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002443 return RX_DROP_MONITOR;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002444
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002445 /*
Johannes Berge7f4a942011-11-04 11:18:20 +01002446 * Send unexpected-4addr-frame event to hostapd. For older versions,
2447 * also drop the frame to cooked monitor interfaces.
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002448 */
2449 if (ieee80211_has_a4(hdr->frame_control) &&
Johannes Berge7f4a942011-11-04 11:18:20 +01002450 sdata->vif.type == NL80211_IFTYPE_AP) {
2451 if (rx->sta &&
2452 !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
2453 cfg80211_rx_unexpected_4addr_frame(
2454 rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002455 return RX_DROP_MONITOR;
Johannes Berge7f4a942011-11-04 11:18:20 +01002456 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002457
Felix Fietkau4114fa22011-04-12 19:15:22 +02002458 err = __ieee80211_data_to_8023(rx, &port_control);
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002459 if (unlikely(err))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002460 return RX_DROP_UNUSABLE;
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002461
Harvey Harrison358c8d92008-07-15 18:44:13 -07002462 if (!ieee80211_frame_allowed(rx, fc))
Johannes Berge4c26ad2008-01-31 19:48:21 +01002463 return RX_DROP_MONITOR;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002464
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02002465 /* directly handle TDLS channel switch requests/responses */
2466 if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
2467 cpu_to_be16(ETH_P_TDLS))) {
2468 struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
2469
2470 if (pskb_may_pull(rx->skb,
2471 offsetof(struct ieee80211_tdls_data, u)) &&
2472 tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
2473 tf->category == WLAN_CATEGORY_TDLS &&
2474 (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
2475 tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
Arik Nemtsovc8ff71e2015-07-08 15:41:45 +03002476 skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
2477 schedule_work(&local->tdls_chsw_work);
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02002478 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02002479 rx->sta->rx_stats.packets++;
Arik Nemtsov8a4d32f2014-11-09 18:50:20 +02002480
2481 return RX_QUEUED;
2482 }
2483 }
2484
Felix Fietkau4114fa22011-04-12 19:15:22 +02002485 if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2486 unlikely(port_control) && sdata->bss) {
2487 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2488 u.ap);
2489 dev = sdata->dev;
2490 rx->sdata = sdata;
2491 }
2492
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002493 rx->skb->dev = dev;
2494
Johannes Berg602fae42016-03-17 15:02:52 +02002495 if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2496 local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
Rajkumar Manoharan8c99f692011-02-02 22:57:53 +05302497 !is_multicast_ether_addr(
2498 ((struct ethhdr *)rx->skb->data)->h_dest) &&
2499 (!local->scanning &&
Johannes Berg602fae42016-03-17 15:02:52 +02002500 !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
2501 mod_timer(&local->dynamic_ps_timer, jiffies +
2502 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
Vivek Natarajane15276a2010-02-08 17:47:01 +05302503
Ron Rindjunsky76ee65b2007-11-22 19:49:12 +02002504 ieee80211_deliver_skb(rx);
Johannes Berg571ecf62007-07-27 15:43:22 +02002505
Johannes Berg9ae54c82008-01-31 19:48:20 +01002506 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02002507}
2508
Johannes Berg49461622008-06-30 15:10:45 +02002509static ieee80211_rx_result debug_noinline
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002510ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
Ron Rindjunsky71364712007-12-25 17:00:36 +02002511{
Ron Rindjunsky71364712007-12-25 17:00:36 +02002512 struct sk_buff *skb = rx->skb;
Harvey Harrisona7767f92008-07-02 16:30:51 -07002513 struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002514 struct tid_ampdu_rx *tid_agg_rx;
2515 u16 start_seq_num;
2516 u16 tid;
2517
Harvey Harrisona7767f92008-07-02 16:30:51 -07002518 if (likely(!ieee80211_is_ctl(bar->frame_control)))
Johannes Berg9ae54c82008-01-31 19:48:20 +01002519 return RX_CONTINUE;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002520
Harvey Harrisona7767f92008-07-02 16:30:51 -07002521 if (ieee80211_is_back_req(bar->frame_control)) {
Johannes Berg8ae59772010-05-30 14:52:58 +02002522 struct {
2523 __le16 control, start_seq_num;
2524 } __packed bar_data;
Emmanuel Grumbach63822462015-04-20 22:53:37 +03002525 struct ieee80211_event event = {
2526 .type = BAR_RX_EVENT,
2527 };
Johannes Berg8ae59772010-05-30 14:52:58 +02002528
Ron Rindjunsky71364712007-12-25 17:00:36 +02002529 if (!rx->sta)
Johannes Berga02ae752009-11-16 12:00:40 +01002530 return RX_DROP_MONITOR;
Johannes Berg8ae59772010-05-30 14:52:58 +02002531
2532 if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
2533 &bar_data, sizeof(bar_data)))
2534 return RX_DROP_MONITOR;
2535
Johannes Berg8ae59772010-05-30 14:52:58 +02002536 tid = le16_to_cpu(bar_data.control) >> 12;
Johannes Berga87f7362010-06-10 10:21:38 +02002537
2538 tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
2539 if (!tid_agg_rx)
Johannes Berga02ae752009-11-16 12:00:40 +01002540 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002541
Johannes Berg8ae59772010-05-30 14:52:58 +02002542 start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
Emmanuel Grumbach63822462015-04-20 22:53:37 +03002543 event.u.ba.tid = tid;
2544 event.u.ba.ssn = start_seq_num;
2545 event.u.ba.sta = &rx->sta->sta;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002546
2547 /* reset session timer */
Johannes Berg20ad19d2009-02-10 21:25:45 +01002548 if (tid_agg_rx->timeout)
2549 mod_timer(&tid_agg_rx->session_timer,
2550 TU_TO_EXP_TIME(tid_agg_rx->timeout));
Ron Rindjunsky71364712007-12-25 17:00:36 +02002551
Johannes Bergdd318572010-11-29 11:09:16 +01002552 spin_lock(&tid_agg_rx->reorder_lock);
Johannes Berga02ae752009-11-16 12:00:40 +01002553 /* release stored frames up to start of BAR */
Johannes Bergd3b2fb52012-06-22 12:48:38 +02002554 ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
Christian Lamparterf9e124f2013-02-04 17:44:44 +00002555 start_seq_num, frames);
Johannes Bergdd318572010-11-29 11:09:16 +01002556 spin_unlock(&tid_agg_rx->reorder_lock);
2557
Emmanuel Grumbach63822462015-04-20 22:53:37 +03002558 drv_event_callback(rx->local, rx->sdata, &event);
2559
Johannes Berga02ae752009-11-16 12:00:40 +01002560 kfree_skb(skb);
2561 return RX_QUEUED;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002562 }
2563
Johannes Berg08daeca2010-05-30 14:53:43 +02002564 /*
2565 * After this point, we only want management frames,
2566 * so we can drop all remaining control frames to
2567 * cooked monitor interfaces.
2568 */
2569 return RX_DROP_MONITOR;
Ron Rindjunsky71364712007-12-25 17:00:36 +02002570}
2571
Jouni Malinenf4f727a2009-01-10 11:46:53 +02002572static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
2573 struct ieee80211_mgmt *mgmt,
2574 size_t len)
Jouni Malinenfea14732009-01-08 13:32:06 +02002575{
2576 struct ieee80211_local *local = sdata->local;
2577 struct sk_buff *skb;
2578 struct ieee80211_mgmt *resp;
2579
Joe Perchesb203ca32012-05-08 18:56:52 +00002580 if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
Jouni Malinenfea14732009-01-08 13:32:06 +02002581 /* Not to own unicast address */
2582 return;
2583 }
2584
Joe Perchesb203ca32012-05-08 18:56:52 +00002585 if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
2586 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002587 /* Not from the current AP or not associated yet. */
Jouni Malinenfea14732009-01-08 13:32:06 +02002588 return;
2589 }
2590
2591 if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
2592 /* Too short SA Query request frame */
2593 return;
2594 }
2595
2596 skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
2597 if (skb == NULL)
2598 return;
2599
2600 skb_reserve(skb, local->hw.extra_tx_headroom);
2601 resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
2602 memset(resp, 0, 24);
2603 memcpy(resp->da, mgmt->sa, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002604 memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +01002605 memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
Jouni Malinenfea14732009-01-08 13:32:06 +02002606 resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2607 IEEE80211_STYPE_ACTION);
2608 skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
2609 resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
2610 resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
2611 memcpy(resp->u.action.u.sa_query.trans_id,
2612 mgmt->u.action.u.sa_query.trans_id,
2613 WLAN_SA_QUERY_TR_ID_LEN);
2614
Johannes Berg62ae67b2009-11-18 18:42:05 +01002615 ieee80211_tx_skb(sdata, skb);
Jouni Malinenfea14732009-01-08 13:32:06 +02002616}
2617
Johannes Berg49461622008-06-30 15:10:45 +02002618static ieee80211_rx_result debug_noinline
Johannes Berg2e161f72010-08-12 15:38:38 +02002619ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
2620{
2621 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002622 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002623
2624 /*
2625 * From here on, look only at management frames.
2626 * Data and control frames are already handled,
2627 * and unknown (reserved) frames are useless.
2628 */
2629 if (rx->skb->len < 24)
2630 return RX_DROP_MONITOR;
2631
2632 if (!ieee80211_is_mgmt(mgmt->frame_control))
2633 return RX_DROP_MONITOR;
2634
Johannes Bergee971922011-11-04 11:18:18 +01002635 if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
2636 ieee80211_is_beacon(mgmt->frame_control) &&
2637 !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
Johannes Berg804483e2012-03-05 22:18:41 +01002638 int sig = 0;
2639
Johannes Berg30686bf2015-06-02 21:39:54 +02002640 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
Johannes Berg804483e2012-03-05 22:18:41 +01002641 sig = status->signal;
2642
Johannes Bergee971922011-11-04 11:18:18 +01002643 cfg80211_report_obss_beacon(rx->local->hw.wiphy,
2644 rx->skb->data, rx->skb->len,
Ben Greear37c73b52012-10-26 14:49:25 -07002645 status->freq, sig);
Johannes Bergee971922011-11-04 11:18:18 +01002646 rx->flags |= IEEE80211_RX_BEACON_REPORTED;
2647 }
2648
Johannes Berg2e161f72010-08-12 15:38:38 +02002649 if (ieee80211_drop_unencrypted_mgmt(rx))
2650 return RX_DROP_UNUSABLE;
2651
2652 return RX_CONTINUE;
2653}
2654
2655static ieee80211_rx_result debug_noinline
Johannes Bergde1ede72008-09-09 14:42:50 +02002656ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2657{
2658 struct ieee80211_local *local = rx->local;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01002659 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergde1ede72008-09-09 14:42:50 +02002660 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
Johannes Berg554891e2010-09-24 12:38:25 +02002661 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Bergde1ede72008-09-09 14:42:50 +02002662 int len = rx->skb->len;
2663
2664 if (!ieee80211_is_action(mgmt->frame_control))
2665 return RX_CONTINUE;
2666
Jouni Malinen026331c2010-02-15 12:53:10 +02002667 /* drop too small frames */
2668 if (len < IEEE80211_MIN_ACTION_SIZE)
2669 return RX_DROP_UNUSABLE;
2670
Marco Porsch815b8092012-12-05 15:04:26 -08002671 if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002672 mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
2673 mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg84040802010-02-15 12:46:39 +02002674 return RX_DROP_UNUSABLE;
Johannes Bergde1ede72008-09-09 14:42:50 +02002675
Johannes Bergde1ede72008-09-09 14:42:50 +02002676 switch (mgmt->u.action.category) {
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002677 case WLAN_CATEGORY_HT:
2678 /* reject HT action frames from stations not supporting HT */
2679 if (!rx->sta->sta.ht_cap.ht_supported)
2680 goto invalid;
2681
2682 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2683 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2684 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2685 sdata->vif.type != NL80211_IFTYPE_AP &&
2686 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2687 break;
2688
Johannes Bergec61cd62012-12-28 12:12:10 +01002689 /* verify action & smps_control/chanwidth are present */
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002690 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2691 goto invalid;
2692
2693 switch (mgmt->u.action.u.ht_smps.action) {
2694 case WLAN_HT_ACTION_SMPS: {
2695 struct ieee80211_supported_band *sband;
Johannes Bergaf0ed692013-02-12 14:21:00 +01002696 enum ieee80211_smps_mode smps_mode;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002697
2698 /* convert to HT capability */
2699 switch (mgmt->u.action.u.ht_smps.smps_control) {
2700 case WLAN_HT_SMPS_CONTROL_DISABLED:
Johannes Bergaf0ed692013-02-12 14:21:00 +01002701 smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002702 break;
2703 case WLAN_HT_SMPS_CONTROL_STATIC:
Johannes Bergaf0ed692013-02-12 14:21:00 +01002704 smps_mode = IEEE80211_SMPS_STATIC;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002705 break;
2706 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
Johannes Bergaf0ed692013-02-12 14:21:00 +01002707 smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002708 break;
2709 default:
2710 goto invalid;
2711 }
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002712
2713 /* if no change do nothing */
Johannes Bergaf0ed692013-02-12 14:21:00 +01002714 if (rx->sta->sta.smps_mode == smps_mode)
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002715 goto handled;
Johannes Bergaf0ed692013-02-12 14:21:00 +01002716 rx->sta->sta.smps_mode = smps_mode;
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002717
2718 sband = rx->local->hw.wiphy->bands[status->band];
2719
Johannes Berg64f68e52012-03-28 10:58:37 +02002720 rate_control_rate_update(local, sband, rx->sta,
2721 IEEE80211_RC_SMPS_CHANGED);
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002722 goto handled;
2723 }
Johannes Bergec61cd62012-12-28 12:12:10 +01002724 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2725 struct ieee80211_supported_band *sband;
2726 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
Eliad Peller1c45c5c2014-12-14 11:05:51 +02002727 enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
Johannes Bergec61cd62012-12-28 12:12:10 +01002728
2729 /* If it doesn't support 40 MHz it can't change ... */
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002730 if (!(rx->sta->sta.ht_cap.cap &
2731 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Johannes Bergec61cd62012-12-28 12:12:10 +01002732 goto handled;
2733
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002734 if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
Eliad Peller1c45c5c2014-12-14 11:05:51 +02002735 max_bw = IEEE80211_STA_RX_BW_20;
Johannes Bergec61cd62012-12-28 12:12:10 +01002736 else
Eliad Peller1c45c5c2014-12-14 11:05:51 +02002737 max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
2738
2739 /* set cur_max_bandwidth and recalc sta bw */
2740 rx->sta->cur_max_bandwidth = max_bw;
2741 new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002742
2743 if (rx->sta->sta.bandwidth == new_bw)
2744 goto handled;
Johannes Bergec61cd62012-12-28 12:12:10 +01002745
Eliad Peller1c45c5c2014-12-14 11:05:51 +02002746 rx->sta->sta.bandwidth = new_bw;
Johannes Bergec61cd62012-12-28 12:12:10 +01002747 sband = rx->local->hw.wiphy->bands[status->band];
2748
2749 rate_control_rate_update(local, sband, rx->sta,
2750 IEEE80211_RC_BW_CHANGED);
2751 goto handled;
2752 }
Johannes Berg1d8d3de2011-12-16 15:28:57 +01002753 default:
2754 goto invalid;
2755 }
2756
2757 break;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01002758 case WLAN_CATEGORY_PUBLIC:
2759 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2760 goto invalid;
2761 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2762 break;
2763 if (!rx->sta)
2764 break;
2765 if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
2766 break;
2767 if (mgmt->u.action.u.ext_chan_switch.action_code !=
2768 WLAN_PUB_ACTION_EXT_CHANSW_ANN)
2769 break;
2770 if (len < offsetof(struct ieee80211_mgmt,
2771 u.action.u.ext_chan_switch.variable))
2772 goto invalid;
2773 goto queue;
Johannes Berg0af83d32012-12-27 18:55:36 +01002774 case WLAN_CATEGORY_VHT:
2775 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2776 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2777 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2778 sdata->vif.type != NL80211_IFTYPE_AP &&
2779 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2780 break;
2781
2782 /* verify action code is present */
2783 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2784 goto invalid;
2785
2786 switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
2787 case WLAN_VHT_ACTION_OPMODE_NOTIF: {
2788 u8 opmode;
2789
2790 /* verify opmode is present */
2791 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2792 goto invalid;
2793
2794 opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
2795
2796 ieee80211_vht_handle_opmode(rx->sdata, rx->sta,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02002797 opmode, status->band);
Johannes Berg0af83d32012-12-27 18:55:36 +01002798 goto handled;
2799 }
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002800 case WLAN_VHT_ACTION_GROUPID_MGMT: {
2801 if (len < IEEE80211_MIN_ACTION_SIZE + 25)
2802 goto invalid;
2803 goto queue;
2804 }
Johannes Berg0af83d32012-12-27 18:55:36 +01002805 default:
2806 break;
2807 }
2808 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002809 case WLAN_CATEGORY_BACK:
Johannes Berg8abd3f92009-02-10 21:25:47 +01002810 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
Thomas Pedersenae2772b2011-10-26 14:47:29 -07002811 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg8abd3f92009-02-10 21:25:47 +01002812 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
Alexander Simon13c40c52011-11-30 16:56:34 +01002813 sdata->vif.type != NL80211_IFTYPE_AP &&
2814 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Johannes Berg84040802010-02-15 12:46:39 +02002815 break;
Johannes Berg8abd3f92009-02-10 21:25:47 +01002816
Jouni Malinen026331c2010-02-15 12:53:10 +02002817 /* verify action_code is present */
2818 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2819 break;
2820
Johannes Bergde1ede72008-09-09 14:42:50 +02002821 switch (mgmt->u.action.u.addba_req.action_code) {
2822 case WLAN_ACTION_ADDBA_REQ:
2823 if (len < (IEEE80211_MIN_ACTION_SIZE +
2824 sizeof(mgmt->u.action.u.addba_req)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002825 goto invalid;
2826 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002827 case WLAN_ACTION_ADDBA_RESP:
2828 if (len < (IEEE80211_MIN_ACTION_SIZE +
2829 sizeof(mgmt->u.action.u.addba_resp)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002830 goto invalid;
2831 break;
Johannes Bergde1ede72008-09-09 14:42:50 +02002832 case WLAN_ACTION_DELBA:
2833 if (len < (IEEE80211_MIN_ACTION_SIZE +
2834 sizeof(mgmt->u.action.u.delba)))
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002835 goto invalid;
2836 break;
2837 default:
2838 goto invalid;
Johannes Bergde1ede72008-09-09 14:42:50 +02002839 }
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002840
Johannes Berg8b58ff82010-06-10 10:21:51 +02002841 goto queue;
Johannes Berg39192c02008-09-09 14:49:03 +02002842 case WLAN_CATEGORY_SPECTRUM_MGMT:
Jouni Malinen026331c2010-02-15 12:53:10 +02002843 /* verify action_code is present */
2844 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
2845 break;
2846
Johannes Berg39192c02008-09-09 14:49:03 +02002847 switch (mgmt->u.action.u.measurement.action_code) {
2848 case WLAN_ACTION_SPCT_MSR_REQ:
Johannes Berg57fbcce2016-04-12 15:56:15 +02002849 if (status->band != NL80211_BAND_5GHZ)
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002850 break;
2851
Johannes Berg39192c02008-09-09 14:49:03 +02002852 if (len < (IEEE80211_MIN_ACTION_SIZE +
2853 sizeof(mgmt->u.action.u.measurement)))
Johannes Berg84040802010-02-15 12:46:39 +02002854 break;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002855
Johannes Bergcc32abd2009-05-15 11:52:31 +02002856 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002857 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02002858
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002859 ieee80211_process_measurement_req(sdata, mgmt, len);
2860 goto handled;
2861 case WLAN_ACTION_SPCT_CHL_SWITCH: {
2862 u8 *bssid;
2863 if (len < (IEEE80211_MIN_ACTION_SIZE +
2864 sizeof(mgmt->u.action.u.chan_switch)))
2865 break;
2866
2867 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07002868 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2869 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002870 break;
2871
2872 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2873 bssid = sdata->u.mgd.bssid;
2874 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2875 bssid = sdata->u.ibss.bssid;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07002876 else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
2877 bssid = mgmt->sa;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002878 else
2879 break;
2880
2881 if (!ether_addr_equal(mgmt->bssid, bssid))
Johannes Berg84040802010-02-15 12:46:39 +02002882 break;
Sujithc481ec92009-01-06 09:28:37 +05302883
Johannes Berg8b58ff82010-06-10 10:21:51 +02002884 goto queue;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002885 }
Johannes Berg39192c02008-09-09 14:49:03 +02002886 }
2887 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002888 case WLAN_CATEGORY_SA_QUERY:
2889 if (len < (IEEE80211_MIN_ACTION_SIZE +
2890 sizeof(mgmt->u.action.u.sa_query)))
Johannes Berg84040802010-02-15 12:46:39 +02002891 break;
2892
Jouni Malinenfea14732009-01-08 13:32:06 +02002893 switch (mgmt->u.action.u.sa_query.action) {
2894 case WLAN_ACTION_SA_QUERY_REQUEST:
2895 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg84040802010-02-15 12:46:39 +02002896 break;
Jouni Malinenfea14732009-01-08 13:32:06 +02002897 ieee80211_process_sa_query_req(sdata, mgmt, len);
Johannes Berg84040802010-02-15 12:46:39 +02002898 goto handled;
Jouni Malinenfea14732009-01-08 13:32:06 +02002899 }
2900 break;
Thomas Pedersen8db09852011-08-12 20:01:00 -07002901 case WLAN_CATEGORY_SELF_PROTECTED:
Johannes Berg9b395bc2012-10-26 00:36:40 +02002902 if (len < (IEEE80211_MIN_ACTION_SIZE +
2903 sizeof(mgmt->u.action.u.self_prot.action_code)))
2904 break;
2905
Thomas Pedersen8db09852011-08-12 20:01:00 -07002906 switch (mgmt->u.action.u.self_prot.action_code) {
2907 case WLAN_SP_MESH_PEERING_OPEN:
2908 case WLAN_SP_MESH_PEERING_CLOSE:
2909 case WLAN_SP_MESH_PEERING_CONFIRM:
2910 if (!ieee80211_vif_is_mesh(&sdata->vif))
2911 goto invalid;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08002912 if (sdata->u.mesh.user_mpm)
Thomas Pedersen8db09852011-08-12 20:01:00 -07002913 /* userspace handles this frame */
2914 break;
2915 goto queue;
2916 case WLAN_SP_MGK_INFORM:
2917 case WLAN_SP_MGK_ACK:
2918 if (!ieee80211_vif_is_mesh(&sdata->vif))
2919 goto invalid;
2920 break;
2921 }
2922 break;
Javier Cardonad3aaec8a2011-05-03 16:57:09 -07002923 case WLAN_CATEGORY_MESH_ACTION:
Johannes Berg9b395bc2012-10-26 00:36:40 +02002924 if (len < (IEEE80211_MIN_ACTION_SIZE +
2925 sizeof(mgmt->u.action.u.mesh_action.action_code)))
2926 break;
2927
Johannes Berg77a121c2010-06-10 10:21:34 +02002928 if (!ieee80211_vif_is_mesh(&sdata->vif))
2929 break;
Thomas Pedersen25d49e42011-08-11 19:35:15 -07002930 if (mesh_action_is_path_sel(mgmt) &&
Johannes Berg1df332e2012-10-26 00:09:11 +02002931 !mesh_path_sel_is_hwmp(sdata))
Javier Cardonac7108a72010-12-16 17:37:50 -08002932 break;
2933 goto queue;
Johannes Berg84040802010-02-15 12:46:39 +02002934 }
Jouni Malinen026331c2010-02-15 12:53:10 +02002935
Johannes Berg2e161f72010-08-12 15:38:38 +02002936 return RX_CONTINUE;
2937
Johannes Bergbed7ee6e2010-06-10 10:21:35 +02002938 invalid:
Johannes Berg554891e2010-09-24 12:38:25 +02002939 status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
Johannes Berg2e161f72010-08-12 15:38:38 +02002940 /* will return in the next handlers */
2941 return RX_CONTINUE;
2942
2943 handled:
2944 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02002945 rx->sta->rx_stats.packets++;
Johannes Berg2e161f72010-08-12 15:38:38 +02002946 dev_kfree_skb(rx->skb);
2947 return RX_QUEUED;
2948
2949 queue:
2950 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
2951 skb_queue_tail(&sdata->skb_queue, rx->skb);
2952 ieee80211_queue_work(&local->hw, &sdata->work);
2953 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02002954 rx->sta->rx_stats.packets++;
Johannes Berg2e161f72010-08-12 15:38:38 +02002955 return RX_QUEUED;
2956}
2957
2958static ieee80211_rx_result debug_noinline
2959ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
2960{
Johannes Berg554891e2010-09-24 12:38:25 +02002961 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg804483e2012-03-05 22:18:41 +01002962 int sig = 0;
Johannes Berg2e161f72010-08-12 15:38:38 +02002963
2964 /* skip known-bad action frames and return them in the next handler */
Johannes Berg554891e2010-09-24 12:38:25 +02002965 if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
Johannes Berg2e161f72010-08-12 15:38:38 +02002966 return RX_CONTINUE;
Felix Fietkaud7907442010-01-07 20:23:53 +01002967
Jouni Malinen026331c2010-02-15 12:53:10 +02002968 /*
2969 * Getting here means the kernel doesn't know how to handle
2970 * it, but maybe userspace does ... include returned frames
2971 * so userspace can register for those to know whether ones
2972 * it transmitted were processed or returned.
2973 */
Jouni Malinen026331c2010-02-15 12:53:10 +02002974
Johannes Berg30686bf2015-06-02 21:39:54 +02002975 if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
Johannes Berg804483e2012-03-05 22:18:41 +01002976 sig = status->signal;
2977
Johannes Berg71bbc992012-06-15 15:30:18 +02002978 if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -07002979 rx->skb->data, rx->skb->len, 0)) {
Johannes Berg2e161f72010-08-12 15:38:38 +02002980 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02002981 rx->sta->rx_stats.packets++;
Johannes Berg2e161f72010-08-12 15:38:38 +02002982 dev_kfree_skb(rx->skb);
2983 return RX_QUEUED;
2984 }
2985
Johannes Berg2e161f72010-08-12 15:38:38 +02002986 return RX_CONTINUE;
2987}
2988
2989static ieee80211_rx_result debug_noinline
2990ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
2991{
2992 struct ieee80211_local *local = rx->local;
2993 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
2994 struct sk_buff *nskb;
2995 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg554891e2010-09-24 12:38:25 +02002996 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Johannes Berg2e161f72010-08-12 15:38:38 +02002997
2998 if (!ieee80211_is_action(mgmt->frame_control))
2999 return RX_CONTINUE;
3000
3001 /*
3002 * For AP mode, hostapd is responsible for handling any action
3003 * frames that we didn't handle, including returning unknown
3004 * ones. For all other modes we will return them to the sender,
3005 * setting the 0x80 bit in the action category, as required by
Johannes Berg4b5ebcc2012-06-27 15:38:56 +02003006 * 802.11-2012 9.24.4.
Johannes Berg2e161f72010-08-12 15:38:38 +02003007 * Newer versions of hostapd shall also use the management frame
3008 * registration mechanisms, but older ones still use cooked
3009 * monitor interfaces so push all frames there.
3010 */
Johannes Berg554891e2010-09-24 12:38:25 +02003011 if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
Johannes Berg2e161f72010-08-12 15:38:38 +02003012 (sdata->vif.type == NL80211_IFTYPE_AP ||
3013 sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3014 return RX_DROP_MONITOR;
Jouni Malinen026331c2010-02-15 12:53:10 +02003015
Johannes Berg4b5ebcc2012-06-27 15:38:56 +02003016 if (is_multicast_ether_addr(mgmt->da))
3017 return RX_DROP_MONITOR;
3018
Johannes Berg84040802010-02-15 12:46:39 +02003019 /* do not return rejected action frames */
3020 if (mgmt->u.action.category & 0x80)
3021 return RX_DROP_UNUSABLE;
3022
3023 nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3024 GFP_ATOMIC);
3025 if (nskb) {
John W. Linville292b4df2010-06-24 11:13:56 -04003026 struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
Johannes Berg84040802010-02-15 12:46:39 +02003027
John W. Linville292b4df2010-06-24 11:13:56 -04003028 nmgmt->u.action.category |= 0x80;
3029 memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3030 memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
Johannes Berg84040802010-02-15 12:46:39 +02003031
3032 memset(nskb->cb, 0, sizeof(nskb->cb));
3033
Johannes Berg07e5a5f2013-03-07 13:22:05 +01003034 if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3035 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3036
3037 info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3038 IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3039 IEEE80211_TX_CTL_NO_CCK_RATE;
Johannes Berg30686bf2015-06-02 21:39:54 +02003040 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
Johannes Berg07e5a5f2013-03-07 13:22:05 +01003041 info->hw_queue =
3042 local->hw.offchannel_tx_hw_queue;
3043 }
3044
3045 __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3046 status->band);
Johannes Bergde1ede72008-09-09 14:42:50 +02003047 }
Johannes Berg39192c02008-09-09 14:49:03 +02003048 dev_kfree_skb(rx->skb);
3049 return RX_QUEUED;
Johannes Bergde1ede72008-09-09 14:42:50 +02003050}
3051
3052static ieee80211_rx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +01003053ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
Johannes Berg571ecf62007-07-27 15:43:22 +02003054{
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01003055 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg77a121c2010-06-10 10:21:34 +02003056 struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3057 __le16 stype;
Johannes Berg571ecf62007-07-27 15:43:22 +02003058
Johannes Berg77a121c2010-06-10 10:21:34 +02003059 stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
Johannes Berg472dbc42008-09-11 00:01:49 +02003060
Johannes Berg77a121c2010-06-10 10:21:34 +02003061 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3062 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003063 sdata->vif.type != NL80211_IFTYPE_OCB &&
Johannes Berg77a121c2010-06-10 10:21:34 +02003064 sdata->vif.type != NL80211_IFTYPE_STATION)
3065 return RX_DROP_MONITOR;
Johannes Bergf9d540e2007-09-28 14:02:09 +02003066
Johannes Berg77a121c2010-06-10 10:21:34 +02003067 switch (stype) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003068 case cpu_to_le16(IEEE80211_STYPE_AUTH):
Johannes Berg77a121c2010-06-10 10:21:34 +02003069 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3070 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3071 /* process for all: mesh, mlme, ibss */
3072 break;
Johannes Berg66e67e42012-01-20 13:55:27 +01003073 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3074 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
Johannes Berg77a121c2010-06-10 10:21:34 +02003075 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3076 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
Christian Lamparter2c313332010-11-29 20:53:23 +01003077 if (is_multicast_ether_addr(mgmt->da) &&
3078 !is_broadcast_ether_addr(mgmt->da))
3079 return RX_DROP_MONITOR;
3080
Johannes Berg77a121c2010-06-10 10:21:34 +02003081 /* process only for station */
3082 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3083 return RX_DROP_MONITOR;
3084 break;
3085 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
Thomas Pedersen9fb04b52013-02-14 11:20:14 -08003086 /* process only for ibss and mesh */
3087 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3088 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Johannes Berg77a121c2010-06-10 10:21:34 +02003089 return RX_DROP_MONITOR;
3090 break;
3091 default:
3092 return RX_DROP_MONITOR;
3093 }
Johannes Berg46900292009-02-15 12:44:28 +01003094
Johannes Berg77a121c2010-06-10 10:21:34 +02003095 /* queue up frame and kick off work to process it */
Johannes Bergc1475ca2010-06-10 10:21:37 +02003096 rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
Johannes Berg77a121c2010-06-10 10:21:34 +02003097 skb_queue_tail(&sdata->skb_queue, rx->skb);
3098 ieee80211_queue_work(&rx->local->hw, &sdata->work);
Johannes Berg8b58ff82010-06-10 10:21:51 +02003099 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003100 rx->sta->rx_stats.packets++;
Johannes Berg77a121c2010-06-10 10:21:34 +02003101
3102 return RX_QUEUED;
Johannes Berg571ecf62007-07-27 15:43:22 +02003103}
3104
Johannes Berg5f0b7de2009-11-16 13:58:21 +01003105static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3106 struct ieee80211_rate *rate)
Michael Wu3d30d942008-01-31 19:48:27 +01003107{
3108 struct ieee80211_sub_if_data *sdata;
3109 struct ieee80211_local *local = rx->local;
Michael Wu3d30d942008-01-31 19:48:27 +01003110 struct sk_buff *skb = rx->skb, *skb2;
3111 struct net_device *prev_dev = NULL;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01003112 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg293702a2012-03-02 13:18:19 +01003113 int needed_headroom;
Michael Wu3d30d942008-01-31 19:48:27 +01003114
Johannes Berg554891e2010-09-24 12:38:25 +02003115 /*
3116 * If cooked monitor has been processed already, then
3117 * don't do it again. If not, set the flag.
3118 */
3119 if (rx->flags & IEEE80211_RX_CMNTR)
John W. Linville7c1e1832010-09-24 15:52:49 -04003120 goto out_free_skb;
Johannes Berg554891e2010-09-24 12:38:25 +02003121 rx->flags |= IEEE80211_RX_CMNTR;
John W. Linville7c1e1832010-09-24 15:52:49 -04003122
Johannes Berg152c4772011-10-21 10:22:22 +02003123 /* If there are no cooked monitor interfaces, just free the SKB */
3124 if (!local->cooked_mntrs)
3125 goto out_free_skb;
3126
Johannes Berg1f7bba72014-11-06 22:56:36 +01003127 /* vendor data is long removed here */
3128 status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
Johannes Berg293702a2012-03-02 13:18:19 +01003129 /* room for the radiotap header based on driver features */
Johannes Berg1f7bba72014-11-06 22:56:36 +01003130 needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
Johannes Berg293702a2012-03-02 13:18:19 +01003131
3132 if (skb_headroom(skb) < needed_headroom &&
3133 pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
Michael Wu3d30d942008-01-31 19:48:27 +01003134 goto out_free_skb;
3135
Johannes Berg293702a2012-03-02 13:18:19 +01003136 /* prepend radiotap information */
Felix Fietkau973ef212012-04-16 14:56:48 +02003137 ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3138 false);
Michael Wu3d30d942008-01-31 19:48:27 +01003139
Zhang Shengjud57a5442016-03-03 01:16:56 +00003140 skb_reset_mac_header(skb);
Michael Wu3d30d942008-01-31 19:48:27 +01003141 skb->ip_summed = CHECKSUM_UNNECESSARY;
3142 skb->pkt_type = PACKET_OTHERHOST;
3143 skb->protocol = htons(ETH_P_802_2);
3144
3145 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01003146 if (!ieee80211_sdata_running(sdata))
Michael Wu3d30d942008-01-31 19:48:27 +01003147 continue;
3148
Johannes Berg05c914f2008-09-11 00:01:58 +02003149 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
Michael Wu3d30d942008-01-31 19:48:27 +01003150 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
3151 continue;
3152
3153 if (prev_dev) {
3154 skb2 = skb_clone(skb, GFP_ATOMIC);
3155 if (skb2) {
3156 skb2->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04003157 netif_receive_skb(skb2);
Michael Wu3d30d942008-01-31 19:48:27 +01003158 }
3159 }
3160
3161 prev_dev = sdata->dev;
Johannes Berg5a490512015-04-22 17:10:38 +02003162 ieee80211_rx_stats(sdata->dev, skb->len);
Michael Wu3d30d942008-01-31 19:48:27 +01003163 }
3164
3165 if (prev_dev) {
3166 skb->dev = prev_dev;
John W. Linville5548a8a2010-06-24 14:25:56 -04003167 netif_receive_skb(skb);
Johannes Berg554891e2010-09-24 12:38:25 +02003168 return;
3169 }
Michael Wu3d30d942008-01-31 19:48:27 +01003170
3171 out_free_skb:
3172 dev_kfree_skb(skb);
3173}
3174
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003175static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3176 ieee80211_rx_result res)
3177{
3178 switch (res) {
3179 case RX_DROP_MONITOR:
3180 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3181 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003182 rx->sta->rx_stats.dropped++;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003183 /* fall through */
3184 case RX_CONTINUE: {
3185 struct ieee80211_rate *rate = NULL;
3186 struct ieee80211_supported_band *sband;
3187 struct ieee80211_rx_status *status;
3188
3189 status = IEEE80211_SKB_RXCB((rx->skb));
3190
3191 sband = rx->local->hw.wiphy->bands[status->band];
Johannes Berg56146182012-11-09 15:07:02 +01003192 if (!(status->flag & RX_FLAG_HT) &&
3193 !(status->flag & RX_FLAG_VHT))
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003194 rate = &sband->bitrates[status->rate_idx];
3195
3196 ieee80211_rx_cooked_monitor(rx, rate);
3197 break;
3198 }
3199 case RX_DROP_UNUSABLE:
3200 I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3201 if (rx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003202 rx->sta->rx_stats.dropped++;
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003203 dev_kfree_skb(rx->skb);
3204 break;
3205 case RX_QUEUED:
3206 I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3207 break;
3208 }
3209}
3210
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003211static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3212 struct sk_buff_head *frames)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003213{
3214 ieee80211_rx_result res = RX_DROP_MONITOR;
3215 struct sk_buff *skb;
3216
3217#define CALL_RXH(rxh) \
3218 do { \
3219 res = rxh(rx); \
3220 if (res != RX_CONTINUE) \
3221 goto rxh_next; \
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003222 } while (0)
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003223
Johannes Berg45ceeee2015-03-16 09:08:20 +01003224 /* Lock here to avoid hitting all of the data used in the RX
3225 * path (e.g. key data, station data, ...) concurrently when
3226 * a frame is released from the reorder buffer due to timeout
3227 * from the timer, potentially concurrently with RX from the
3228 * driver.
3229 */
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003230 spin_lock_bh(&rx->local->rx_path_lock);
Christian Lamparter24a8fda2010-12-30 17:25:29 +01003231
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003232 while ((skb = __skb_dequeue(frames))) {
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003233 /*
3234 * all the other fields are valid across frames
3235 * that belong to an aMPDU since they are on the
3236 * same TID from the same station
3237 */
3238 rx->skb = skb;
3239
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003240 CALL_RXH(ieee80211_rx_h_check_more_data);
3241 CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3242 CALL_RXH(ieee80211_rx_h_sta_process);
3243 CALL_RXH(ieee80211_rx_h_decrypt);
3244 CALL_RXH(ieee80211_rx_h_defragment);
3245 CALL_RXH(ieee80211_rx_h_michael_mic_verify);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003246 /* must be after MMIC verify so header is counted in MPDU mic */
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003247#ifdef CONFIG_MAC80211_MESH
3248 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3249 CALL_RXH(ieee80211_rx_h_mesh_fwding);
3250#endif
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003251 CALL_RXH(ieee80211_rx_h_amsdu);
3252 CALL_RXH(ieee80211_rx_h_data);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003253
3254 /* special treatment -- needs the queue */
3255 res = ieee80211_rx_h_ctrl(rx, frames);
3256 if (res != RX_CONTINUE)
3257 goto rxh_next;
3258
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003259 CALL_RXH(ieee80211_rx_h_mgmt_check);
3260 CALL_RXH(ieee80211_rx_h_action);
3261 CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3262 CALL_RXH(ieee80211_rx_h_action_return);
3263 CALL_RXH(ieee80211_rx_h_mgmt);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003264
3265 rxh_next:
3266 ieee80211_rx_handlers_result(rx, res);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003267
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003268#undef CALL_RXH
3269 }
Christian Lamparter24a8fda2010-12-30 17:25:29 +01003270
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003271 spin_unlock_bh(&rx->local->rx_path_lock);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003272}
Johannes Berg571ecf62007-07-27 15:43:22 +02003273
Johannes Berg4406c372010-09-24 11:21:06 +02003274static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
Johannes Berg58905292008-01-31 19:48:25 +01003275{
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003276 struct sk_buff_head reorder_release;
Johannes Berg58905292008-01-31 19:48:25 +01003277 ieee80211_rx_result res = RX_DROP_MONITOR;
3278
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003279 __skb_queue_head_init(&reorder_release);
3280
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02003281#define CALL_RXH(rxh) \
3282 do { \
3283 res = rxh(rx); \
3284 if (res != RX_CONTINUE) \
Johannes Berg2569a822009-11-25 17:46:17 +01003285 goto rxh_next; \
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003286 } while (0)
Johannes Berg58905292008-01-31 19:48:25 +01003287
Johannes Berg8ebaa5b2016-03-31 20:02:04 +03003288 CALL_RXH(ieee80211_rx_h_check_dup);
3289 CALL_RXH(ieee80211_rx_h_check);
Johannes Berg2569a822009-11-25 17:46:17 +01003290
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003291 ieee80211_rx_reorder_ampdu(rx, &reorder_release);
Johannes Berg2569a822009-11-25 17:46:17 +01003292
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003293 ieee80211_rx_handlers(rx, &reorder_release);
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003294 return;
Johannes Berg49461622008-06-30 15:10:45 +02003295
Johannes Berg2569a822009-11-25 17:46:17 +01003296 rxh_next:
Christian Lamparteraa0c8632010-08-05 01:36:04 +02003297 ieee80211_rx_handlers_result(rx, res);
3298
3299#undef CALL_RXH
Johannes Berg58905292008-01-31 19:48:25 +01003300}
3301
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003302/*
Johannes Bergdd318572010-11-29 11:09:16 +01003303 * This function makes calls into the RX path, therefore
3304 * it has to be invoked under RCU read lock.
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003305 */
3306void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3307{
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003308 struct sk_buff_head frames;
Johannes Berg554891e2010-09-24 12:38:25 +02003309 struct ieee80211_rx_data rx = {
3310 .sta = sta,
3311 .sdata = sta->sdata,
3312 .local = sta->local,
Johannes Berg9e262972011-07-07 18:45:03 +02003313 /* This is OK -- must be QoS data frame */
3314 .security_idx = tid,
3315 .seqno_idx = tid,
Johannes Bergaf9f9b22015-06-11 16:02:32 +02003316 .napi = NULL, /* must be NULL to not have races */
Johannes Berg554891e2010-09-24 12:38:25 +02003317 };
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003318 struct tid_ampdu_rx *tid_agg_rx;
3319
3320 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3321 if (!tid_agg_rx)
3322 return;
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003323
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003324 __skb_queue_head_init(&frames);
3325
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003326 spin_lock(&tid_agg_rx->reorder_lock);
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003327 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
Christian Lamparter2c15a0c2010-08-24 19:22:42 +02003328 spin_unlock(&tid_agg_rx->reorder_lock);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003329
Emmanuel Grumbachb497de62015-04-20 22:53:38 +03003330 if (!skb_queue_empty(&frames)) {
3331 struct ieee80211_event event = {
3332 .type = BA_FRAME_TIMEOUT,
3333 .u.ba.tid = tid,
3334 .u.ba.sta = &sta->sta,
3335 };
3336 drv_event_callback(rx.local, rx.sdata, &event);
3337 }
3338
Christian Lamparterf9e124f2013-02-04 17:44:44 +00003339 ieee80211_rx_handlers(&rx, &frames);
Christian Lamparter2bff8eb2010-08-05 01:36:41 +02003340}
3341
Sara Sharon06470f72016-01-28 16:19:25 +02003342void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
3343 u16 ssn, u64 filtered,
3344 u16 received_mpdus)
3345{
3346 struct sta_info *sta;
3347 struct tid_ampdu_rx *tid_agg_rx;
3348 struct sk_buff_head frames;
3349 struct ieee80211_rx_data rx = {
3350 /* This is OK -- must be QoS data frame */
3351 .security_idx = tid,
3352 .seqno_idx = tid,
3353 };
3354 int i, diff;
3355
3356 if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
3357 return;
3358
3359 __skb_queue_head_init(&frames);
3360
3361 sta = container_of(pubsta, struct sta_info, sta);
3362
3363 rx.sta = sta;
3364 rx.sdata = sta->sdata;
3365 rx.local = sta->local;
3366
3367 rcu_read_lock();
3368 tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3369 if (!tid_agg_rx)
3370 goto out;
3371
3372 spin_lock_bh(&tid_agg_rx->reorder_lock);
3373
3374 if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
3375 int release;
3376
3377 /* release all frames in the reorder buffer */
3378 release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
3379 IEEE80211_SN_MODULO;
3380 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
3381 release, &frames);
3382 /* update ssn to match received ssn */
3383 tid_agg_rx->head_seq_num = ssn;
3384 } else {
3385 ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
3386 &frames);
3387 }
3388
3389 /* handle the case that received ssn is behind the mac ssn.
3390 * it can be tid_agg_rx->buf_size behind and still be valid */
3391 diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
3392 if (diff >= tid_agg_rx->buf_size) {
3393 tid_agg_rx->reorder_buf_filtered = 0;
3394 goto release;
3395 }
3396 filtered = filtered >> diff;
3397 ssn += diff;
3398
3399 /* update bitmap */
3400 for (i = 0; i < tid_agg_rx->buf_size; i++) {
3401 int index = (ssn + i) % tid_agg_rx->buf_size;
3402
3403 tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
3404 if (filtered & BIT_ULL(i))
3405 tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
3406 }
3407
3408 /* now process also frames that the filter marking released */
3409 ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
3410
3411release:
3412 spin_unlock_bh(&tid_agg_rx->reorder_lock);
3413
3414 ieee80211_rx_handlers(&rx, &frames);
3415
3416 out:
3417 rcu_read_unlock();
3418}
3419EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
3420
Johannes Berg571ecf62007-07-27 15:43:22 +02003421/* main receive path */
3422
Johannes Berga58fbe12015-04-22 15:08:39 +02003423static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
Johannes Berg23a24de2007-07-27 15:43:22 +02003424{
Johannes Berg20b01f82010-09-24 11:21:05 +02003425 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01003426 struct sk_buff *skb = rx->skb;
Johannes Berga58fbe12015-04-22 15:08:39 +02003427 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01003428 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3429 u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
Johannes Berg23a24de2007-07-27 15:43:22 +02003430 int multicast = is_multicast_ether_addr(hdr->addr1);
3431
Johannes Berg51fb61e2007-12-19 01:31:27 +01003432 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003433 case NL80211_IFTYPE_STATION:
Johannes Berg9bc383d2009-11-19 11:55:19 +01003434 if (!bssid && !sdata->u.mgd.use_4addr)
Johannes Berg3c2723f52014-01-07 16:23:24 +01003435 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003436 if (multicast)
3437 return true;
3438 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
Johannes Berg05c914f2008-09-11 00:01:58 +02003439 case NL80211_IFTYPE_ADHOC:
Johannes Berg23a24de2007-07-27 15:43:22 +02003440 if (!bssid)
Johannes Berg3c2723f52014-01-07 16:23:24 +01003441 return false;
Felix Fietkau6329b8d2013-09-17 11:15:43 +02003442 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3443 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003444 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003445 if (ieee80211_is_beacon(hdr->frame_control))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003446 return true;
Johannes Berga58fbe12015-04-22 15:08:39 +02003447 if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003448 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003449 if (!multicast &&
3450 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
Johannes Bergdf140462015-04-22 14:40:58 +02003451 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003452 if (!rx->sta) {
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003453 int rate_idx;
Johannes Berg56146182012-11-09 15:07:02 +01003454 if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
3455 rate_idx = 0; /* TODO: HT/VHT rates */
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003456 else
Johannes Bergeb9fb5b2009-11-16 13:58:20 +01003457 rate_idx = status->rate_idx;
Johannes Berg8bf11d82011-12-15 11:17:37 +01003458 ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
3459 BIT(rate_idx));
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02003460 }
Johannes Berga58fbe12015-04-22 15:08:39 +02003461 return true;
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003462 case NL80211_IFTYPE_OCB:
3463 if (!bssid)
3464 return false;
Bertold Van den Berghcc117292015-08-05 16:02:42 +02003465 if (!ieee80211_is_data_present(hdr->frame_control))
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003466 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003467 if (!is_broadcast_ether_addr(bssid))
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003468 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003469 if (!multicast &&
3470 !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
Johannes Bergdf140462015-04-22 14:40:58 +02003471 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003472 if (!rx->sta) {
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003473 int rate_idx;
3474 if (status->flag & RX_FLAG_HT)
3475 rate_idx = 0; /* TODO: HT rates */
3476 else
3477 rate_idx = status->rate_idx;
3478 ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
3479 BIT(rate_idx));
3480 }
Johannes Berga58fbe12015-04-22 15:08:39 +02003481 return true;
Johannes Berg05c914f2008-09-11 00:01:58 +02003482 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga58fbe12015-04-22 15:08:39 +02003483 if (multicast)
3484 return true;
3485 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
Johannes Berg05c914f2008-09-11 00:01:58 +02003486 case NL80211_IFTYPE_AP_VLAN:
3487 case NL80211_IFTYPE_AP:
Johannes Berga58fbe12015-04-22 15:08:39 +02003488 if (!bssid)
3489 return ether_addr_equal(sdata->vif.addr, hdr->addr1);
3490
3491 if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
Johannes Berg3df6eae2011-12-06 10:39:40 +01003492 /*
3493 * Accept public action frames even when the
3494 * BSSID doesn't match, this is used for P2P
3495 * and location updates. Note that mac80211
3496 * itself never looks at these frames.
3497 */
Johannes Berg2b9ccd42013-05-13 16:42:40 +02003498 if (!multicast &&
3499 !ether_addr_equal(sdata->vif.addr, hdr->addr1))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003500 return false;
Johannes Bergd48b2962012-07-06 22:19:27 +02003501 if (ieee80211_is_public_action(hdr, skb->len))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003502 return true;
Johannes Berg5c900672015-04-22 14:48:34 +02003503 return ieee80211_is_beacon(hdr->frame_control);
Johannes Berga58fbe12015-04-22 15:08:39 +02003504 }
3505
3506 if (!ieee80211_has_tods(hdr->frame_control)) {
Arik Nemtsovdb8e1732014-07-17 17:14:30 +03003507 /* ignore data frames to TDLS-peers */
3508 if (ieee80211_is_data(hdr->frame_control))
3509 return false;
3510 /* ignore action frames to TDLS-peers */
3511 if (ieee80211_is_action(hdr->frame_control) &&
Jouni Malinen1ec7bae2016-03-01 00:29:00 +02003512 !is_broadcast_ether_addr(bssid) &&
Arik Nemtsovdb8e1732014-07-17 17:14:30 +03003513 !ether_addr_equal(bssid, hdr->addr1))
3514 return false;
Johannes Berg23a24de2007-07-27 15:43:22 +02003515 }
Johannes Berga58fbe12015-04-22 15:08:39 +02003516 return true;
Johannes Berg05c914f2008-09-11 00:01:58 +02003517 case NL80211_IFTYPE_WDS:
Harvey Harrisona7767f92008-07-02 16:30:51 -07003518 if (bssid || !ieee80211_is_data(hdr->frame_control))
Johannes Berg3c2723f52014-01-07 16:23:24 +01003519 return false;
Johannes Berga58fbe12015-04-22 15:08:39 +02003520 return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
Johannes Bergf142c6b2012-06-18 20:07:15 +02003521 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berga58fbe12015-04-22 15:08:39 +02003522 return ieee80211_is_public_action(hdr, skb->len) ||
3523 ieee80211_is_probe_req(hdr->frame_control) ||
3524 ieee80211_is_probe_resp(hdr->frame_control) ||
3525 ieee80211_is_beacon(hdr->frame_control);
Johannes Berg2ca27bc2010-09-16 14:58:23 +02003526 default:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +02003527 break;
Johannes Berg23a24de2007-07-27 15:43:22 +02003528 }
3529
Johannes Berga58fbe12015-04-22 15:08:39 +02003530 WARN_ON_ONCE(1);
3531 return false;
Johannes Berg23a24de2007-07-27 15:43:22 +02003532}
3533
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003534void ieee80211_check_fast_rx(struct sta_info *sta)
3535{
3536 struct ieee80211_sub_if_data *sdata = sta->sdata;
3537 struct ieee80211_local *local = sdata->local;
3538 struct ieee80211_key *key;
3539 struct ieee80211_fast_rx fastrx = {
3540 .dev = sdata->dev,
3541 .vif_type = sdata->vif.type,
3542 .control_port_protocol = sdata->control_port_protocol,
3543 }, *old, *new = NULL;
3544 bool assign = false;
3545
3546 /* use sparse to check that we don't return without updating */
3547 __acquire(check_fast_rx);
3548
3549 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
3550 BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
3551 ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
3552 ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
3553
Johannes Bergc9c59622016-03-31 20:02:11 +03003554 fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
3555
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003556 /* fast-rx doesn't do reordering */
3557 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
3558 !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
3559 goto clear;
3560
3561 switch (sdata->vif.type) {
3562 case NL80211_IFTYPE_STATION:
3563 /* 4-addr is harder to deal with, later maybe */
3564 if (sdata->u.mgd.use_4addr)
3565 goto clear;
3566 /* software powersave is a huge mess, avoid all of it */
3567 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
3568 goto clear;
3569 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3570 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3571 goto clear;
3572 if (sta->sta.tdls) {
3573 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3574 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3575 fastrx.expected_ds_bits = 0;
3576 } else {
3577 fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
3578 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
3579 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3580 fastrx.expected_ds_bits =
3581 cpu_to_le16(IEEE80211_FCTL_FROMDS);
3582 }
3583 break;
3584 case NL80211_IFTYPE_AP_VLAN:
3585 case NL80211_IFTYPE_AP:
3586 /* parallel-rx requires this, at least with calls to
3587 * ieee80211_sta_ps_transition()
3588 */
3589 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
3590 goto clear;
3591 fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
3592 fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3593 fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
3594
3595 fastrx.internal_forward =
3596 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
3597 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
3598 !sdata->u.vlan.sta);
3599 break;
3600 default:
3601 goto clear;
3602 }
3603
3604 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3605 goto clear;
3606
3607 rcu_read_lock();
3608 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
3609 if (key) {
3610 switch (key->conf.cipher) {
3611 case WLAN_CIPHER_SUITE_TKIP:
3612 /* we don't want to deal with MMIC in fast-rx */
3613 goto clear_rcu;
3614 case WLAN_CIPHER_SUITE_CCMP:
3615 case WLAN_CIPHER_SUITE_CCMP_256:
3616 case WLAN_CIPHER_SUITE_GCMP:
3617 case WLAN_CIPHER_SUITE_GCMP_256:
3618 break;
3619 default:
3620 /* we also don't want to deal with WEP or cipher scheme
3621 * since those require looking up the key idx in the
3622 * frame, rather than assuming the PTK is used
3623 * (we need to revisit this once we implement the real
3624 * PTK index, which is now valid in the spec, but we
3625 * haven't implemented that part yet)
3626 */
3627 goto clear_rcu;
3628 }
3629
3630 fastrx.key = true;
3631 fastrx.icv_len = key->conf.icv_len;
3632 }
3633
3634 assign = true;
3635 clear_rcu:
3636 rcu_read_unlock();
3637 clear:
3638 __release(check_fast_rx);
3639
3640 if (assign)
3641 new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
3642
3643 spin_lock_bh(&sta->lock);
3644 old = rcu_dereference_protected(sta->fast_rx, true);
3645 rcu_assign_pointer(sta->fast_rx, new);
3646 spin_unlock_bh(&sta->lock);
3647
3648 if (old)
3649 kfree_rcu(old, rcu_head);
3650}
3651
3652void ieee80211_clear_fast_rx(struct sta_info *sta)
3653{
3654 struct ieee80211_fast_rx *old;
3655
3656 spin_lock_bh(&sta->lock);
3657 old = rcu_dereference_protected(sta->fast_rx, true);
3658 RCU_INIT_POINTER(sta->fast_rx, NULL);
3659 spin_unlock_bh(&sta->lock);
3660
3661 if (old)
3662 kfree_rcu(old, rcu_head);
3663}
3664
3665void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
3666{
3667 struct ieee80211_local *local = sdata->local;
3668 struct sta_info *sta;
3669
3670 lockdep_assert_held(&local->sta_mtx);
3671
3672 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3673 if (sdata != sta->sdata &&
3674 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3675 continue;
3676 ieee80211_check_fast_rx(sta);
3677 }
3678}
3679
3680void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
3681{
3682 struct ieee80211_local *local = sdata->local;
3683
3684 mutex_lock(&local->sta_mtx);
3685 __ieee80211_check_fast_rx_iface(sdata);
3686 mutex_unlock(&local->sta_mtx);
3687}
3688
3689static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
3690 struct ieee80211_fast_rx *fast_rx)
3691{
3692 struct sk_buff *skb = rx->skb;
3693 struct ieee80211_hdr *hdr = (void *)skb->data;
3694 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3695 struct sta_info *sta = rx->sta;
3696 int orig_len = skb->len;
3697 int snap_offs = ieee80211_hdrlen(hdr->frame_control);
3698 struct {
3699 u8 snap[sizeof(rfc1042_header)];
3700 __be16 proto;
3701 } *payload __aligned(2);
3702 struct {
3703 u8 da[ETH_ALEN];
3704 u8 sa[ETH_ALEN];
3705 } addrs __aligned(2);
Johannes Bergc9c59622016-03-31 20:02:11 +03003706 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
3707
3708 if (fast_rx->uses_rss)
3709 stats = this_cpu_ptr(sta->pcpu_rx_stats);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003710
3711 /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
3712 * to a common data structure; drivers can implement that per queue
3713 * but we don't have that information in mac80211
3714 */
3715 if (!(status->flag & RX_FLAG_DUP_VALIDATED))
3716 return false;
3717
3718#define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
3719
3720 /* If using encryption, we also need to have:
3721 * - PN_VALIDATED: similar, but the implementation is tricky
3722 * - DECRYPTED: necessary for PN_VALIDATED
3723 */
3724 if (fast_rx->key &&
3725 (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
3726 return false;
3727
3728 /* we don't deal with A-MSDU deaggregation here */
3729 if (status->rx_flags & IEEE80211_RX_AMSDU)
3730 return false;
3731
3732 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
3733 return false;
3734
3735 if (unlikely(ieee80211_is_frag(hdr)))
3736 return false;
3737
3738 /* Since our interface address cannot be multicast, this
3739 * implicitly also rejects multicast frames without the
3740 * explicit check.
3741 *
3742 * We shouldn't get any *data* frames not addressed to us
3743 * (AP mode will accept multicast *management* frames), but
3744 * punting here will make it go through the full checks in
3745 * ieee80211_accept_frame().
3746 */
3747 if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
3748 return false;
3749
3750 if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
3751 IEEE80211_FCTL_TODS)) !=
3752 fast_rx->expected_ds_bits)
3753 goto drop;
3754
3755 /* assign the key to drop unencrypted frames (later)
3756 * and strip the IV/MIC if necessary
3757 */
3758 if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
3759 /* GCMP header length is the same */
3760 snap_offs += IEEE80211_CCMP_HDR_LEN;
3761 }
3762
3763 if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
3764 goto drop;
3765 payload = (void *)(skb->data + snap_offs);
3766
3767 if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
3768 return false;
3769
3770 /* Don't handle these here since they require special code.
3771 * Accept AARP and IPX even though they should come with a
3772 * bridge-tunnel header - but if we get them this way then
3773 * there's little point in discarding them.
3774 */
3775 if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
3776 payload->proto == fast_rx->control_port_protocol))
3777 return false;
3778
3779 /* after this point, don't punt to the slowpath! */
3780
3781 if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
3782 pskb_trim(skb, skb->len - fast_rx->icv_len))
3783 goto drop;
3784
3785 if (unlikely(fast_rx->sta_notify)) {
3786 ieee80211_sta_rx_notify(rx->sdata, hdr);
3787 fast_rx->sta_notify = false;
3788 }
3789
3790 /* statistics part of ieee80211_rx_h_sta_process() */
Johannes Bergc9c59622016-03-31 20:02:11 +03003791 stats->last_rx = jiffies;
3792 stats->last_rate = sta_stats_encode_rate(status);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003793
Johannes Bergc9c59622016-03-31 20:02:11 +03003794 stats->fragments++;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003795
3796 if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
Johannes Bergc9c59622016-03-31 20:02:11 +03003797 stats->last_signal = status->signal;
3798 if (!fast_rx->uses_rss)
3799 ewma_signal_add(&sta->rx_stats_avg.signal,
3800 -status->signal);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003801 }
3802
3803 if (status->chains) {
3804 int i;
3805
Johannes Bergc9c59622016-03-31 20:02:11 +03003806 stats->chains = status->chains;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003807 for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
3808 int signal = status->chain_signal[i];
3809
3810 if (!(status->chains & BIT(i)))
3811 continue;
3812
Johannes Bergc9c59622016-03-31 20:02:11 +03003813 stats->chain_signal_last[i] = signal;
3814 if (!fast_rx->uses_rss)
3815 ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
3816 -signal);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003817 }
3818 }
3819 /* end of statistics */
3820
3821 if (rx->key && !ieee80211_has_protected(hdr->frame_control))
3822 goto drop;
3823
3824 /* do the header conversion - first grab the addresses */
3825 ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
3826 ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
3827 /* remove the SNAP but leave the ethertype */
3828 skb_pull(skb, snap_offs + sizeof(rfc1042_header));
3829 /* push the addresses in front */
3830 memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
3831
3832 skb->dev = fast_rx->dev;
3833
3834 ieee80211_rx_stats(fast_rx->dev, skb->len);
3835
3836 /* The seqno index has the same property as needed
3837 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
3838 * for non-QoS-data frames. Here we know it's a data
3839 * frame, so count MSDUs.
3840 */
Johannes Bergc9c59622016-03-31 20:02:11 +03003841 u64_stats_update_begin(&stats->syncp);
3842 stats->msdu[rx->seqno_idx]++;
3843 stats->bytes += orig_len;
3844 u64_stats_update_end(&stats->syncp);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003845
3846 if (fast_rx->internal_forward) {
3847 struct sta_info *dsta = sta_info_get(rx->sdata, skb->data);
3848
3849 if (dsta) {
3850 /*
3851 * Send to wireless media and increase priority by 256
3852 * to keep the received priority instead of
3853 * reclassifying the frame (see cfg80211_classify8021d).
3854 */
3855 skb->priority += 256;
3856 skb->protocol = htons(ETH_P_802_3);
3857 skb_reset_network_header(skb);
3858 skb_reset_mac_header(skb);
3859 dev_queue_xmit(skb);
3860 return true;
3861 }
3862 }
3863
3864 /* deliver to local stack */
3865 skb->protocol = eth_type_trans(skb, fast_rx->dev);
3866 memset(skb->cb, 0, sizeof(skb->cb));
3867 if (rx->napi)
3868 napi_gro_receive(rx->napi, skb);
3869 else
3870 netif_receive_skb(skb);
3871
3872 return true;
3873 drop:
3874 dev_kfree_skb(skb);
Johannes Bergc9c59622016-03-31 20:02:11 +03003875 stats->dropped++;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003876 return true;
3877}
3878
Johannes Berg571ecf62007-07-27 15:43:22 +02003879/*
Johannes Berg4406c372010-09-24 11:21:06 +02003880 * This function returns whether or not the SKB
3881 * was destined for RX processing or not, which,
3882 * if consume is true, is equivalent to whether
3883 * or not the skb was consumed.
3884 */
3885static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
3886 struct sk_buff *skb, bool consume)
3887{
3888 struct ieee80211_local *local = rx->local;
3889 struct ieee80211_sub_if_data *sdata = rx->sdata;
Johannes Berg4406c372010-09-24 11:21:06 +02003890
3891 rx->skb = skb;
Johannes Berg4406c372010-09-24 11:21:06 +02003892
Johannes Berg49ddf8e2016-03-31 20:02:10 +03003893 /* See if we can do fast-rx; if we have to copy we already lost,
3894 * so punt in that case. We should never have to deliver a data
3895 * frame to multiple interfaces anyway.
3896 *
3897 * We skip the ieee80211_accept_frame() call and do the necessary
3898 * checking inside ieee80211_invoke_fast_rx().
3899 */
3900 if (consume && rx->sta) {
3901 struct ieee80211_fast_rx *fast_rx;
3902
3903 fast_rx = rcu_dereference(rx->sta->fast_rx);
3904 if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
3905 return true;
3906 }
3907
Johannes Berga58fbe12015-04-22 15:08:39 +02003908 if (!ieee80211_accept_frame(rx))
Johannes Berg4406c372010-09-24 11:21:06 +02003909 return false;
3910
Johannes Berg4406c372010-09-24 11:21:06 +02003911 if (!consume) {
3912 skb = skb_copy(skb, GFP_ATOMIC);
3913 if (!skb) {
3914 if (net_ratelimit())
3915 wiphy_debug(local->hw.wiphy,
Ben Greearb305dae2011-01-08 10:30:54 -08003916 "failed to copy skb for %s\n",
Johannes Berg4406c372010-09-24 11:21:06 +02003917 sdata->name);
3918 return true;
3919 }
3920
3921 rx->skb = skb;
3922 }
3923
3924 ieee80211_invoke_rx_handlers(rx);
3925 return true;
3926}
3927
3928/*
Zhao, Gang6b59db72014-04-21 12:52:59 +08003929 * This is the actual Rx frames handler. as it belongs to Rx path it must
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02003930 * be called with rcu_read_lock protection.
Johannes Berg571ecf62007-07-27 15:43:22 +02003931 */
Ron Rindjunsky71ebb4a2008-01-21 12:39:12 +02003932static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
Johannes Bergd63b5482016-03-31 20:02:02 +03003933 struct ieee80211_sta *pubsta,
Johannes Bergaf9f9b22015-06-11 16:02:32 +02003934 struct sk_buff *skb,
3935 struct napi_struct *napi)
Johannes Berg571ecf62007-07-27 15:43:22 +02003936{
3937 struct ieee80211_local *local = hw_to_local(hw);
3938 struct ieee80211_sub_if_data *sdata;
Johannes Berg571ecf62007-07-27 15:43:22 +02003939 struct ieee80211_hdr *hdr;
Zhu Yie3cf8b32010-03-29 17:35:07 +08003940 __le16 fc;
Johannes Berg5cf121c2008-02-25 16:27:43 +01003941 struct ieee80211_rx_data rx;
Johannes Berg4406c372010-09-24 11:21:06 +02003942 struct ieee80211_sub_if_data *prev;
Johannes Berg7bedd0c2015-02-13 21:55:15 +01003943 struct rhash_head *tmp;
Zhu Yie3cf8b32010-03-29 17:35:07 +08003944 int err = 0;
Johannes Berg571ecf62007-07-27 15:43:22 +02003945
Zhu Yie3cf8b32010-03-29 17:35:07 +08003946 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
Johannes Berg571ecf62007-07-27 15:43:22 +02003947 memset(&rx, 0, sizeof(rx));
3948 rx.skb = skb;
3949 rx.local = local;
Johannes Bergaf9f9b22015-06-11 16:02:32 +02003950 rx.napi = napi;
Johannes Berg72abd812007-09-17 01:29:22 -04003951
Zhu Yie3cf8b32010-03-29 17:35:07 +08003952 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
Johannes Bergc206ca62015-04-22 20:47:28 +02003953 I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
Johannes Berg571ecf62007-07-27 15:43:22 +02003954
Johannes Berg4a4f1a52012-10-26 00:33:36 +02003955 if (ieee80211_is_mgmt(fc)) {
3956 /* drop frame if too short for header */
3957 if (skb->len < ieee80211_hdrlen(fc))
3958 err = -ENOBUFS;
3959 else
3960 err = skb_linearize(skb);
3961 } else {
Zhu Yie3cf8b32010-03-29 17:35:07 +08003962 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
Johannes Berg4a4f1a52012-10-26 00:33:36 +02003963 }
Zhu Yie3cf8b32010-03-29 17:35:07 +08003964
3965 if (err) {
3966 dev_kfree_skb(skb);
3967 return;
3968 }
3969
3970 hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berg38f37142008-01-29 17:07:43 +01003971 ieee80211_parse_qos(&rx);
Johannes Bergd1c3a372009-01-07 00:26:10 +01003972 ieee80211_verify_alignment(&rx);
Johannes Berg38f37142008-01-29 17:07:43 +01003973
Johannes Bergd48b2962012-07-06 22:19:27 +02003974 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
3975 ieee80211_is_beacon(hdr->frame_control)))
3976 ieee80211_scan_rx(local, skb);
3977
Johannes Bergd63b5482016-03-31 20:02:02 +03003978 if (pubsta) {
3979 rx.sta = container_of(pubsta, struct sta_info, sta);
3980 rx.sdata = rx.sta->sdata;
3981 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
3982 return;
3983 goto out;
3984 } else if (ieee80211_is_data(fc)) {
3985 struct sta_info *sta, *prev_sta;
Johannes Berg7bedd0c2015-02-13 21:55:15 +01003986 const struct bucket_table *tbl;
3987
Ben Greear56af3262010-09-23 10:22:24 -07003988 prev_sta = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02003989
Johannes Berg7bedd0c2015-02-13 21:55:15 +01003990 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
3991
3992 for_each_sta_info(local, tbl, hdr->addr2, sta, tmp) {
Ben Greear56af3262010-09-23 10:22:24 -07003993 if (!prev_sta) {
3994 prev_sta = sta;
3995 continue;
3996 }
3997
3998 rx.sta = prev_sta;
3999 rx.sdata = prev_sta->sdata;
Johannes Berg4406c372010-09-24 11:21:06 +02004000 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Johannes Berg571ecf62007-07-27 15:43:22 +02004001
Ben Greear56af3262010-09-23 10:22:24 -07004002 prev_sta = sta;
Johannes Berg4406c372010-09-24 11:21:06 +02004003 }
Ben Greear56af3262010-09-23 10:22:24 -07004004
4005 if (prev_sta) {
4006 rx.sta = prev_sta;
4007 rx.sdata = prev_sta->sdata;
4008
Johannes Berg4406c372010-09-24 11:21:06 +02004009 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
Ben Greear56af3262010-09-23 10:22:24 -07004010 return;
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05304011 goto out;
Ben Greear56af3262010-09-23 10:22:24 -07004012 }
Johannes Berg4406c372010-09-24 11:21:06 +02004013 }
4014
Johannes Berg4b0dd982010-09-24 11:21:07 +02004015 prev = NULL;
Johannes Berg4406c372010-09-24 11:21:06 +02004016
Johannes Berg4b0dd982010-09-24 11:21:07 +02004017 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4018 if (!ieee80211_sdata_running(sdata))
4019 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01004020
Johannes Berg4b0dd982010-09-24 11:21:07 +02004021 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4022 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4023 continue;
Johannes Bergabe60632009-11-25 17:46:18 +01004024
Johannes Berg4b0dd982010-09-24 11:21:07 +02004025 /*
4026 * frame is destined for this interface, but if it's
4027 * not also for the previous one we handle that after
4028 * the loop to avoid copying the SKB once too much
4029 */
Johannes Bergb2e77712007-09-26 15:19:39 +02004030
Johannes Berg4b0dd982010-09-24 11:21:07 +02004031 if (!prev) {
Johannes Berg340e11f2007-07-27 15:43:22 +02004032 prev = sdata;
Johannes Berg4b0dd982010-09-24 11:21:07 +02004033 continue;
Johannes Berg8e6f00322007-07-27 15:43:22 +02004034 }
Felix Fietkau4bb29f82010-01-22 00:36:39 +01004035
Johannes Berg7852e362012-01-20 13:55:24 +01004036 rx.sta = sta_info_get_bss(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02004037 rx.sdata = prev;
4038 ieee80211_prepare_and_rx_handle(&rx, skb, false);
Felix Fietkau4bb29f82010-01-22 00:36:39 +01004039
Johannes Berg4b0dd982010-09-24 11:21:07 +02004040 prev = sdata;
4041 }
Johannes Berg4406c372010-09-24 11:21:06 +02004042
Johannes Berg4b0dd982010-09-24 11:21:07 +02004043 if (prev) {
Johannes Berg7852e362012-01-20 13:55:24 +01004044 rx.sta = sta_info_get_bss(prev, hdr->addr2);
Johannes Berg4b0dd982010-09-24 11:21:07 +02004045 rx.sdata = prev;
4046
4047 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4048 return;
Johannes Berg571ecf62007-07-27 15:43:22 +02004049 }
Johannes Berg4406c372010-09-24 11:21:06 +02004050
Senthil Balasubramanian8e26d5a2010-11-30 20:15:38 +05304051 out:
Johannes Berg4406c372010-09-24 11:21:06 +02004052 dev_kfree_skb(skb);
Johannes Berg571ecf62007-07-27 15:43:22 +02004053}
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004054
4055/*
4056 * This is the receive path handler. It is called by a low level driver when an
4057 * 802.11 MPDU is received from the hardware.
4058 */
Johannes Bergd63b5482016-03-31 20:02:02 +03004059void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4060 struct sk_buff *skb, struct napi_struct *napi)
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004061{
4062 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg8318d782008-01-24 19:38:38 +01004063 struct ieee80211_rate *rate = NULL;
4064 struct ieee80211_supported_band *sband;
Johannes Bergf1d58c22009-06-17 13:13:00 +02004065 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Johannes Berg8318d782008-01-24 19:38:38 +01004066
Johannes Bergd20ef632009-10-11 15:10:40 +02004067 WARN_ON_ONCE(softirq_count() == 0);
4068
Johannes Berg57fbcce2016-04-12 15:56:15 +02004069 if (WARN_ON(status->band >= NUM_NL80211_BANDS))
Johannes Berg77a980d2009-08-24 11:46:30 +02004070 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01004071
4072 sband = local->hw.wiphy->bands[status->band];
Johannes Berg77a980d2009-08-24 11:46:30 +02004073 if (WARN_ON(!sband))
4074 goto drop;
Johannes Berg8318d782008-01-24 19:38:38 +01004075
Johannes Berg89c3a8a2009-07-28 18:10:17 +02004076 /*
4077 * If we're suspending, it is possible although not too likely
4078 * that we'd be receiving frames after having already partially
4079 * quiesced the stack. We can't process such frames then since
4080 * that might, for example, cause stations to be added or other
4081 * driver callbacks be invoked.
4082 */
Johannes Berg77a980d2009-08-24 11:46:30 +02004083 if (unlikely(local->quiescing || local->suspended))
4084 goto drop;
Johannes Berg89c3a8a2009-07-28 18:10:17 +02004085
Arik Nemtsov04800ad2012-06-06 11:25:02 +03004086 /* We might be during a HW reconfig, prevent Rx for the same reason */
4087 if (unlikely(local->in_reconfig))
4088 goto drop;
4089
Johannes Bergea77f122009-08-21 14:44:45 +02004090 /*
4091 * The same happens when we're not even started,
4092 * but that's worth a warning.
4093 */
Johannes Berg77a980d2009-08-24 11:46:30 +02004094 if (WARN_ON(!local->started))
4095 goto drop;
Johannes Bergea77f122009-08-21 14:44:45 +02004096
Johannes Bergfc885182010-07-30 13:23:12 +02004097 if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05004098 /*
Johannes Bergfc885182010-07-30 13:23:12 +02004099 * Validate the rate, unless a PLCP error means that
4100 * we probably can't have a valid rate here anyway.
Luis R. Rodrigueze5d6eb82009-11-09 16:03:22 -05004101 */
Johannes Bergfc885182010-07-30 13:23:12 +02004102
4103 if (status->flag & RX_FLAG_HT) {
4104 /*
4105 * rate_idx is MCS index, which can be [0-76]
4106 * as documented on:
4107 *
4108 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
4109 *
4110 * Anything else would be some sort of driver or
4111 * hardware error. The driver should catch hardware
4112 * errors.
4113 */
Johannes Berg444e38032012-09-30 17:08:35 +02004114 if (WARN(status->rate_idx > 76,
Johannes Bergfc885182010-07-30 13:23:12 +02004115 "Rate marked as an HT rate but passed "
4116 "status->rate_idx is not "
4117 "an MCS index [0-76]: %d (0x%02x)\n",
4118 status->rate_idx,
4119 status->rate_idx))
4120 goto drop;
Johannes Berg56146182012-11-09 15:07:02 +01004121 } else if (status->flag & RX_FLAG_VHT) {
4122 if (WARN_ONCE(status->rate_idx > 9 ||
4123 !status->vht_nss ||
4124 status->vht_nss > 8,
4125 "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4126 status->rate_idx, status->vht_nss))
4127 goto drop;
Johannes Bergfc885182010-07-30 13:23:12 +02004128 } else {
Johannes Berg444e38032012-09-30 17:08:35 +02004129 if (WARN_ON(status->rate_idx >= sband->n_bitrates))
Johannes Bergfc885182010-07-30 13:23:12 +02004130 goto drop;
4131 rate = &sband->bitrates[status->rate_idx];
4132 }
Jouni Malinen0fb8ca42008-12-12 14:38:33 +02004133 }
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004134
Johannes Berg554891e2010-09-24 12:38:25 +02004135 status->rx_flags = 0;
4136
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004137 /*
4138 * key references and virtual interfaces are protected using RCU
4139 * and this requires that we are in a read-side RCU section during
4140 * receive processing
4141 */
4142 rcu_read_lock();
4143
4144 /*
4145 * Frames with failed FCS/PLCP checksum are not returned,
4146 * all other frames are returned without radiotap header
4147 * if it was previously present.
4148 * Also, frames with less than 16 bytes are dropped.
4149 */
Johannes Bergf1d58c22009-06-17 13:13:00 +02004150 skb = ieee80211_rx_monitor(local, skb, rate);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004151 if (!skb) {
4152 rcu_read_unlock();
4153 return;
4154 }
4155
Johannes Berge1e54062010-11-30 08:58:45 +01004156 ieee80211_tpt_led_trig_rx(local,
4157 ((struct ieee80211_hdr *)skb->data)->frame_control,
4158 skb->len);
Johannes Bergd63b5482016-03-31 20:02:02 +03004159
4160 __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004161
4162 rcu_read_unlock();
Johannes Berg77a980d2009-08-24 11:46:30 +02004163
4164 return;
4165 drop:
4166 kfree_skb(skb);
Ron Rindjunsky6368e4b2007-12-24 13:36:39 +02004167}
Johannes Bergaf9f9b22015-06-11 16:02:32 +02004168EXPORT_SYMBOL(ieee80211_rx_napi);
Johannes Berg571ecf62007-07-27 15:43:22 +02004169
4170/* This is a version of the rx handler that can be called from hard irq
4171 * context. Post the skb on the queue and schedule the tasklet */
Johannes Bergf1d58c22009-06-17 13:13:00 +02004172void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
Johannes Berg571ecf62007-07-27 15:43:22 +02004173{
4174 struct ieee80211_local *local = hw_to_local(hw);
4175
4176 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4177
Johannes Berg571ecf62007-07-27 15:43:22 +02004178 skb->pkt_type = IEEE80211_RX_MSG;
4179 skb_queue_tail(&local->skb_queue, skb);
4180 tasklet_schedule(&local->tasklet);
4181}
4182EXPORT_SYMBOL(ieee80211_rx_irqsafe);