]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
571ecf67 JB |
2 | /* |
3 | * Copyright 2002-2005, Instant802 Networks, Inc. | |
4 | * Copyright 2005-2006, Devicescape Software, Inc. | |
5 | * Copyright 2006-2007 Jiri Benc <[email protected]> | |
84040805 | 6 | * Copyright 2007-2010 Johannes Berg <[email protected]> |
d98ad83e | 7 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
b7540d8f | 8 | * Copyright(c) 2015 - 2017 Intel Deutschland GmbH |
c4d800dc | 9 | * Copyright (C) 2018-2020 Intel Corporation |
571ecf67 JB |
10 | */ |
11 | ||
ab46623e | 12 | #include <linux/jiffies.h> |
5a0e3ad6 | 13 | #include <linux/slab.h> |
571ecf67 JB |
14 | #include <linux/kernel.h> |
15 | #include <linux/skbuff.h> | |
16 | #include <linux/netdevice.h> | |
17 | #include <linux/etherdevice.h> | |
d4e46a3d | 18 | #include <linux/rcupdate.h> |
bc3b2d7f | 19 | #include <linux/export.h> |
06470f74 | 20 | #include <linux/bitops.h> |
571ecf67 JB |
21 | #include <net/mac80211.h> |
22 | #include <net/ieee80211_radiotap.h> | |
d26ad377 | 23 | #include <asm/unaligned.h> |
571ecf67 JB |
24 | |
25 | #include "ieee80211_i.h" | |
24487981 | 26 | #include "driver-ops.h" |
2c8dccc7 | 27 | #include "led.h" |
33b64eb2 | 28 | #include "mesh.h" |
571ecf67 JB |
29 | #include "wep.h" |
30 | #include "wpa.h" | |
31 | #include "tkip.h" | |
32 | #include "wme.h" | |
1d8d3dec | 33 | #include "rate.h" |
571ecf67 | 34 | |
b2e7771e JB |
35 | /* |
36 | * monitor mode reception | |
37 | * | |
38 | * This function cleans up the SKB, i.e. it removes all the stuff | |
39 | * only useful for monitoring. | |
40 | */ | |
c1129924 JB |
41 | static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb, |
42 | unsigned int present_fcs_len, | |
43 | unsigned int rtap_space) | |
b2e7771e | 44 | { |
c1129924 JB |
45 | struct ieee80211_hdr *hdr; |
46 | unsigned int hdrlen; | |
47 | __le16 fc; | |
48 | ||
30841f5c JB |
49 | if (present_fcs_len) |
50 | __pskb_trim(skb, skb->len - present_fcs_len); | |
c096b92a | 51 | __pskb_pull(skb, rtap_space); |
c1129924 JB |
52 | |
53 | hdr = (void *)skb->data; | |
54 | fc = hdr->frame_control; | |
55 | ||
56 | /* | |
57 | * Remove the HT-Control field (if present) on management | |
58 | * frames after we've sent the frame to monitoring. We | |
59 | * (currently) don't need it, and don't properly parse | |
60 | * frames with it present, due to the assumption of a | |
61 | * fixed management header length. | |
62 | */ | |
63 | if (likely(!ieee80211_is_mgmt(fc) || !ieee80211_has_order(fc))) | |
64 | return skb; | |
65 | ||
66 | hdrlen = ieee80211_hdrlen(fc); | |
67 | hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_ORDER); | |
68 | ||
69 | if (!pskb_may_pull(skb, hdrlen)) { | |
70 | dev_kfree_skb(skb); | |
71 | return NULL; | |
72 | } | |
73 | ||
74 | memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data, | |
75 | hdrlen - IEEE80211_HT_CTL_LEN); | |
76 | __pskb_pull(skb, IEEE80211_HT_CTL_LEN); | |
77 | ||
78 | return skb; | |
b2e7771e JB |
79 | } |
80 | ||
1f7bba79 | 81 | static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len, |
c096b92a | 82 | unsigned int rtap_space) |
b2e7771e | 83 | { |
f1d58c25 | 84 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
1f7bba79 JB |
85 | struct ieee80211_hdr *hdr; |
86 | ||
c096b92a | 87 | hdr = (void *)(skb->data + rtap_space); |
b2e7771e | 88 | |
4c298677 | 89 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | |
17883048 | 90 | RX_FLAG_FAILED_PLCP_CRC | |
c3d1f875 ST |
91 | RX_FLAG_ONLY_MONITOR | |
92 | RX_FLAG_NO_PSDU)) | |
6b59db7d ZG |
93 | return true; |
94 | ||
c096b92a | 95 | if (unlikely(skb->len < 16 + present_fcs_len + rtap_space)) |
6b59db7d ZG |
96 | return true; |
97 | ||
87228f57 HH |
98 | if (ieee80211_is_ctl(hdr->frame_control) && |
99 | !ieee80211_is_pspoll(hdr->frame_control) && | |
100 | !ieee80211_is_back_req(hdr->frame_control)) | |
6b59db7d ZG |
101 | return true; |
102 | ||
103 | return false; | |
b2e7771e JB |
104 | } |
105 | ||
601ae7f2 | 106 | static int |
1f7bba79 JB |
107 | ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local, |
108 | struct ieee80211_rx_status *status, | |
109 | struct sk_buff *skb) | |
601ae7f2 BR |
110 | { |
111 | int len; | |
112 | ||
113 | /* always present fields */ | |
a144f378 | 114 | len = sizeof(struct ieee80211_radiotap_header) + 8; |
601ae7f2 | 115 | |
a144f378 | 116 | /* allocate extra bitmaps */ |
a144f378 JB |
117 | if (status->chains) |
118 | len += 4 * hweight8(status->chains); | |
efc38dd7 JB |
119 | /* vendor presence bitmap */ |
120 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) | |
121 | len += 4; | |
90b9e446 JB |
122 | |
123 | if (ieee80211_have_rx_timestamp(status)) { | |
124 | len = ALIGN(len, 8); | |
601ae7f2 | 125 | len += 8; |
90b9e446 | 126 | } |
30686bf7 | 127 | if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) |
601ae7f2 | 128 | len += 1; |
601ae7f2 | 129 | |
a144f378 JB |
130 | /* antenna field, if we don't have per-chain info */ |
131 | if (!status->chains) | |
132 | len += 1; | |
133 | ||
90b9e446 JB |
134 | /* padding for RX_FLAGS if necessary */ |
135 | len = ALIGN(len, 2); | |
601ae7f2 | 136 | |
da6a4352 | 137 | if (status->encoding == RX_ENC_HT) /* HT info */ |
6d744bac JB |
138 | len += 3; |
139 | ||
4c298677 | 140 | if (status->flag & RX_FLAG_AMPDU_DETAILS) { |
90b9e446 | 141 | len = ALIGN(len, 4); |
4c298677 JB |
142 | len += 8; |
143 | } | |
144 | ||
da6a4352 | 145 | if (status->encoding == RX_ENC_VHT) { |
51648921 JB |
146 | len = ALIGN(len, 2); |
147 | len += 12; | |
148 | } | |
149 | ||
99ee7cae JB |
150 | if (local->hw.radiotap_timestamp.units_pos >= 0) { |
151 | len = ALIGN(len, 8); | |
152 | len += 12; | |
153 | } | |
154 | ||
41cbb0f5 LC |
155 | if (status->encoding == RX_ENC_HE && |
156 | status->flag & RX_FLAG_RADIOTAP_HE) { | |
157 | len = ALIGN(len, 2); | |
158 | len += 12; | |
159 | BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12); | |
160 | } | |
161 | ||
162 | if (status->encoding == RX_ENC_HE && | |
163 | status->flag & RX_FLAG_RADIOTAP_HE_MU) { | |
164 | len = ALIGN(len, 2); | |
165 | len += 12; | |
166 | BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12); | |
167 | } | |
168 | ||
c3d1f875 ST |
169 | if (status->flag & RX_FLAG_NO_PSDU) |
170 | len += 1; | |
171 | ||
d1332e7b ST |
172 | if (status->flag & RX_FLAG_RADIOTAP_LSIG) { |
173 | len = ALIGN(len, 2); | |
174 | len += 4; | |
175 | BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4); | |
176 | } | |
177 | ||
a144f378 JB |
178 | if (status->chains) { |
179 | /* antenna and antenna signal fields */ | |
180 | len += 2 * hweight8(status->chains); | |
181 | } | |
182 | ||
1f7bba79 | 183 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { |
c15353be LK |
184 | struct ieee80211_vendor_radiotap *rtap; |
185 | int vendor_data_offset = 0; | |
186 | ||
187 | /* | |
188 | * The position to look at depends on the existence (or non- | |
189 | * existence) of other elements, so take that into account... | |
190 | */ | |
191 | if (status->flag & RX_FLAG_RADIOTAP_HE) | |
192 | vendor_data_offset += | |
193 | sizeof(struct ieee80211_radiotap_he); | |
194 | if (status->flag & RX_FLAG_RADIOTAP_HE_MU) | |
195 | vendor_data_offset += | |
196 | sizeof(struct ieee80211_radiotap_he_mu); | |
197 | if (status->flag & RX_FLAG_RADIOTAP_LSIG) | |
198 | vendor_data_offset += | |
199 | sizeof(struct ieee80211_radiotap_lsig); | |
200 | ||
201 | rtap = (void *)&skb->data[vendor_data_offset]; | |
1f7bba79 | 202 | |
1f7bba79 JB |
203 | /* alignment for fixed 6-byte vendor data header */ |
204 | len = ALIGN(len, 2); | |
205 | /* vendor data header */ | |
206 | len += 6; | |
207 | if (WARN_ON(rtap->align == 0)) | |
208 | rtap->align = 1; | |
209 | len = ALIGN(len, rtap->align); | |
210 | len += rtap->len + rtap->pad; | |
211 | } | |
212 | ||
601ae7f2 BR |
213 | return len; |
214 | } | |
215 | ||
9e478066 JB |
216 | static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata, |
217 | struct sk_buff *skb, | |
c096b92a | 218 | int rtap_space) |
9e478066 JB |
219 | { |
220 | struct { | |
221 | struct ieee80211_hdr_3addr hdr; | |
222 | u8 category; | |
223 | u8 action_code; | |
7c53eb5d | 224 | } __packed __aligned(2) action; |
9e478066 JB |
225 | |
226 | if (!sdata) | |
227 | return; | |
228 | ||
229 | BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1); | |
230 | ||
c096b92a | 231 | if (skb->len < rtap_space + sizeof(action) + |
9e478066 JB |
232 | VHT_MUMIMO_GROUPS_DATA_LEN) |
233 | return; | |
234 | ||
235 | if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr)) | |
236 | return; | |
237 | ||
c096b92a | 238 | skb_copy_bits(skb, rtap_space, &action, sizeof(action)); |
9e478066 JB |
239 | |
240 | if (!ieee80211_is_action(action.hdr.frame_control)) | |
241 | return; | |
242 | ||
243 | if (action.category != WLAN_CATEGORY_VHT) | |
244 | return; | |
245 | ||
246 | if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT) | |
247 | return; | |
248 | ||
249 | if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr)) | |
250 | return; | |
251 | ||
252 | skb = skb_copy(skb, GFP_ATOMIC); | |
253 | if (!skb) | |
254 | return; | |
255 | ||
9e478066 JB |
256 | skb_queue_tail(&sdata->skb_queue, skb); |
257 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); | |
258 | } | |
259 | ||
00ea6deb | 260 | /* |
601ae7f2 BR |
261 | * ieee80211_add_rx_radiotap_header - add radiotap header |
262 | * | |
263 | * add a radiotap header containing all the fields which the hardware provided. | |
264 | */ | |
265 | static void | |
266 | ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, | |
267 | struct sk_buff *skb, | |
601ae7f2 | 268 | struct ieee80211_rate *rate, |
973ef21a | 269 | int rtap_len, bool has_fcs) |
601ae7f2 | 270 | { |
f1d58c25 | 271 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
601ae7f2 BR |
272 | struct ieee80211_radiotap_header *rthdr; |
273 | unsigned char *pos; | |
a144f378 JB |
274 | __le32 *it_present; |
275 | u32 it_present_val; | |
6a86b9c7 | 276 | u16 rx_flags = 0; |
a5e70697 | 277 | u16 channel_flags = 0; |
a144f378 JB |
278 | int mpdulen, chain; |
279 | unsigned long chains = status->chains; | |
1f7bba79 | 280 | struct ieee80211_vendor_radiotap rtap = {}; |
41cbb0f5 LC |
281 | struct ieee80211_radiotap_he he = {}; |
282 | struct ieee80211_radiotap_he_mu he_mu = {}; | |
d1332e7b | 283 | struct ieee80211_radiotap_lsig lsig = {}; |
41cbb0f5 LC |
284 | |
285 | if (status->flag & RX_FLAG_RADIOTAP_HE) { | |
286 | he = *(struct ieee80211_radiotap_he *)skb->data; | |
287 | skb_pull(skb, sizeof(he)); | |
288 | WARN_ON_ONCE(status->encoding != RX_ENC_HE); | |
289 | } | |
290 | ||
291 | if (status->flag & RX_FLAG_RADIOTAP_HE_MU) { | |
292 | he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data; | |
293 | skb_pull(skb, sizeof(he_mu)); | |
294 | } | |
1f7bba79 | 295 | |
d1332e7b ST |
296 | if (status->flag & RX_FLAG_RADIOTAP_LSIG) { |
297 | lsig = *(struct ieee80211_radiotap_lsig *)skb->data; | |
298 | skb_pull(skb, sizeof(lsig)); | |
299 | } | |
300 | ||
1f7bba79 JB |
301 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { |
302 | rtap = *(struct ieee80211_vendor_radiotap *)skb->data; | |
303 | /* rtap.len and rtap.pad are undone immediately */ | |
304 | skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad); | |
305 | } | |
f4bda337 TP |
306 | |
307 | mpdulen = skb->len; | |
30686bf7 | 308 | if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))) |
f4bda337 | 309 | mpdulen += FCS_LEN; |
601ae7f2 | 310 | |
d58ff351 | 311 | rthdr = skb_push(skb, rtap_len); |
1f7bba79 | 312 | memset(rthdr, 0, rtap_len - rtap.len - rtap.pad); |
a144f378 | 313 | it_present = &rthdr->it_present; |
601ae7f2 BR |
314 | |
315 | /* radiotap header, set always present flags */ | |
0059b2b1 | 316 | rthdr->it_len = cpu_to_le16(rtap_len); |
a144f378 JB |
317 | it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) | |
318 | BIT(IEEE80211_RADIOTAP_CHANNEL) | | |
319 | BIT(IEEE80211_RADIOTAP_RX_FLAGS); | |
320 | ||
321 | if (!status->chains) | |
322 | it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA); | |
323 | ||
324 | for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) { | |
325 | it_present_val |= | |
326 | BIT(IEEE80211_RADIOTAP_EXT) | | |
327 | BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE); | |
328 | put_unaligned_le32(it_present_val, it_present); | |
329 | it_present++; | |
330 | it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) | | |
331 | BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL); | |
332 | } | |
601ae7f2 | 333 | |
1f7bba79 JB |
334 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { |
335 | it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) | | |
336 | BIT(IEEE80211_RADIOTAP_EXT); | |
337 | put_unaligned_le32(it_present_val, it_present); | |
338 | it_present++; | |
339 | it_present_val = rtap.present; | |
340 | } | |
341 | ||
a144f378 JB |
342 | put_unaligned_le32(it_present_val, it_present); |
343 | ||
344 | pos = (void *)(it_present + 1); | |
345 | ||
601ae7f2 BR |
346 | /* the order of the following fields is important */ |
347 | ||
348 | /* IEEE80211_RADIOTAP_TSFT */ | |
f4bda337 | 349 | if (ieee80211_have_rx_timestamp(status)) { |
90b9e446 JB |
350 | /* padding */ |
351 | while ((pos - (u8 *)rthdr) & 7) | |
352 | *pos++ = 0; | |
f4bda337 TP |
353 | put_unaligned_le64( |
354 | ieee80211_calculate_rx_timestamp(local, status, | |
355 | mpdulen, 0), | |
356 | pos); | |
1df332e8 | 357 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT); |
601ae7f2 BR |
358 | pos += 8; |
359 | } | |
360 | ||
361 | /* IEEE80211_RADIOTAP_FLAGS */ | |
30686bf7 | 362 | if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) |
601ae7f2 | 363 | *pos |= IEEE80211_RADIOTAP_F_FCS; |
aae89831 JB |
364 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
365 | *pos |= IEEE80211_RADIOTAP_F_BADFCS; | |
7fdd69c5 | 366 | if (status->enc_flags & RX_ENC_FLAG_SHORTPRE) |
b4f28bbb | 367 | *pos |= IEEE80211_RADIOTAP_F_SHORTPRE; |
601ae7f2 BR |
368 | pos++; |
369 | ||
370 | /* IEEE80211_RADIOTAP_RATE */ | |
da6a4352 | 371 | if (!rate || status->encoding != RX_ENC_LEGACY) { |
0fb8ca45 | 372 | /* |
f8d1ccf1 | 373 | * Without rate information don't add it. If we have, |
38f37be2 | 374 | * MCS information is a separate field in radiotap, |
73b48099 JB |
375 | * added below. The byte here is needed as padding |
376 | * for the channel though, so initialise it to 0. | |
0fb8ca45 JM |
377 | */ |
378 | *pos = 0; | |
8d6f658e | 379 | } else { |
2103dec1 | 380 | int shift = 0; |
ebe6c7ba | 381 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE); |
da6a4352 | 382 | if (status->bw == RATE_INFO_BW_10) |
2103dec1 | 383 | shift = 1; |
da6a4352 | 384 | else if (status->bw == RATE_INFO_BW_5) |
2103dec1 SW |
385 | shift = 2; |
386 | *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift)); | |
8d6f658e | 387 | } |
601ae7f2 BR |
388 | pos++; |
389 | ||
390 | /* IEEE80211_RADIOTAP_CHANNEL */ | |
3b23c184 | 391 | /* TODO: frequency offset in KHz */ |
6a86b9c7 | 392 | put_unaligned_le16(status->freq, pos); |
601ae7f2 | 393 | pos += 2; |
da6a4352 | 394 | if (status->bw == RATE_INFO_BW_10) |
a5e70697 | 395 | channel_flags |= IEEE80211_CHAN_HALF; |
da6a4352 | 396 | else if (status->bw == RATE_INFO_BW_5) |
a5e70697 SW |
397 | channel_flags |= IEEE80211_CHAN_QUARTER; |
398 | ||
412a84b5 AD |
399 | if (status->band == NL80211_BAND_5GHZ || |
400 | status->band == NL80211_BAND_6GHZ) | |
a5e70697 | 401 | channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ; |
da6a4352 | 402 | else if (status->encoding != RX_ENC_LEGACY) |
a5e70697 | 403 | channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; |
f8d1ccf1 | 404 | else if (rate && rate->flags & IEEE80211_RATE_ERP_G) |
a5e70697 | 405 | channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ; |
f8d1ccf1 | 406 | else if (rate) |
3a5c5e81 | 407 | channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ; |
f8d1ccf1 | 408 | else |
a5e70697 SW |
409 | channel_flags |= IEEE80211_CHAN_2GHZ; |
410 | put_unaligned_le16(channel_flags, pos); | |
601ae7f2 BR |
411 | pos += 2; |
412 | ||
413 | /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */ | |
30686bf7 | 414 | if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) && |
fe8431f8 | 415 | !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { |
601ae7f2 BR |
416 | *pos = status->signal; |
417 | rthdr->it_present |= | |
418 | cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL); | |
419 | pos++; | |
420 | } | |
421 | ||
601ae7f2 BR |
422 | /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */ |
423 | ||
a144f378 JB |
424 | if (!status->chains) { |
425 | /* IEEE80211_RADIOTAP_ANTENNA */ | |
426 | *pos = status->antenna; | |
427 | pos++; | |
428 | } | |
601ae7f2 | 429 | |
601ae7f2 BR |
430 | /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */ |
431 | ||
432 | /* IEEE80211_RADIOTAP_RX_FLAGS */ | |
433 | /* ensure 2 byte alignment for the 2 byte field as required */ | |
6a86b9c7 | 434 | if ((pos - (u8 *)rthdr) & 1) |
90b9e446 | 435 | *pos++ = 0; |
aae89831 | 436 | if (status->flag & RX_FLAG_FAILED_PLCP_CRC) |
6a86b9c7 JB |
437 | rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP; |
438 | put_unaligned_le16(rx_flags, pos); | |
601ae7f2 | 439 | pos += 2; |
6d744bac | 440 | |
da6a4352 | 441 | if (status->encoding == RX_ENC_HT) { |
786677d1 OR |
442 | unsigned int stbc; |
443 | ||
6d744bac | 444 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS); |
ac55d2fe | 445 | *pos++ = local->hw.radiotap_mcs_details; |
6d744bac | 446 | *pos = 0; |
7fdd69c5 | 447 | if (status->enc_flags & RX_ENC_FLAG_SHORT_GI) |
6d744bac | 448 | *pos |= IEEE80211_RADIOTAP_MCS_SGI; |
da6a4352 | 449 | if (status->bw == RATE_INFO_BW_40) |
6d744bac | 450 | *pos |= IEEE80211_RADIOTAP_MCS_BW_40; |
7fdd69c5 | 451 | if (status->enc_flags & RX_ENC_FLAG_HT_GF) |
ac55d2fe | 452 | *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF; |
7fdd69c5 | 453 | if (status->enc_flags & RX_ENC_FLAG_LDPC) |
63c361f5 | 454 | *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC; |
7fdd69c5 | 455 | stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT; |
786677d1 | 456 | *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT; |
6d744bac JB |
457 | pos++; |
458 | *pos++ = status->rate_idx; | |
459 | } | |
4c298677 JB |
460 | |
461 | if (status->flag & RX_FLAG_AMPDU_DETAILS) { | |
462 | u16 flags = 0; | |
463 | ||
464 | /* ensure 4 byte alignment */ | |
465 | while ((pos - (u8 *)rthdr) & 3) | |
466 | pos++; | |
467 | rthdr->it_present |= | |
468 | cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS); | |
469 | put_unaligned_le32(status->ampdu_reference, pos); | |
470 | pos += 4; | |
4c298677 JB |
471 | if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN) |
472 | flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN; | |
473 | if (status->flag & RX_FLAG_AMPDU_IS_LAST) | |
474 | flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST; | |
475 | if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR) | |
476 | flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR; | |
477 | if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN) | |
478 | flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN; | |
7299d6f7 JB |
479 | if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN) |
480 | flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN; | |
481 | if (status->flag & RX_FLAG_AMPDU_EOF_BIT) | |
482 | flags |= IEEE80211_RADIOTAP_AMPDU_EOF; | |
4c298677 JB |
483 | put_unaligned_le16(flags, pos); |
484 | pos += 2; | |
485 | if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN) | |
486 | *pos++ = status->ampdu_delimiter_crc; | |
487 | else | |
488 | *pos++ = 0; | |
489 | *pos++ = 0; | |
490 | } | |
90b9e446 | 491 | |
da6a4352 | 492 | if (status->encoding == RX_ENC_VHT) { |
51648921 JB |
493 | u16 known = local->hw.radiotap_vht_details; |
494 | ||
495 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT); | |
51648921 JB |
496 | put_unaligned_le16(known, pos); |
497 | pos += 2; | |
498 | /* flags */ | |
7fdd69c5 | 499 | if (status->enc_flags & RX_ENC_FLAG_SHORT_GI) |
51648921 | 500 | *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI; |
63c361f5 | 501 | /* in VHT, STBC is binary */ |
7fdd69c5 | 502 | if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) |
63c361f5 | 503 | *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC; |
7fdd69c5 | 504 | if (status->enc_flags & RX_ENC_FLAG_BF) |
fb378c23 | 505 | *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED; |
51648921 JB |
506 | pos++; |
507 | /* bandwidth */ | |
da6a4352 JB |
508 | switch (status->bw) { |
509 | case RATE_INFO_BW_80: | |
51648921 | 510 | *pos++ = 4; |
da6a4352 JB |
511 | break; |
512 | case RATE_INFO_BW_160: | |
51648921 | 513 | *pos++ = 11; |
da6a4352 JB |
514 | break; |
515 | case RATE_INFO_BW_40: | |
51648921 | 516 | *pos++ = 1; |
da6a4352 JB |
517 | break; |
518 | default: | |
51648921 | 519 | *pos++ = 0; |
da6a4352 | 520 | } |
51648921 | 521 | /* MCS/NSS */ |
8613c948 | 522 | *pos = (status->rate_idx << 4) | status->nss; |
51648921 JB |
523 | pos += 4; |
524 | /* coding field */ | |
7fdd69c5 | 525 | if (status->enc_flags & RX_ENC_FLAG_LDPC) |
63c361f5 | 526 | *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0; |
51648921 JB |
527 | pos++; |
528 | /* group ID */ | |
529 | pos++; | |
530 | /* partial_aid */ | |
531 | pos += 2; | |
532 | } | |
533 | ||
99ee7cae JB |
534 | if (local->hw.radiotap_timestamp.units_pos >= 0) { |
535 | u16 accuracy = 0; | |
536 | u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT; | |
537 | ||
538 | rthdr->it_present |= | |
539 | cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP); | |
540 | ||
541 | /* ensure 8 byte alignment */ | |
542 | while ((pos - (u8 *)rthdr) & 7) | |
543 | pos++; | |
544 | ||
545 | put_unaligned_le64(status->device_timestamp, pos); | |
546 | pos += sizeof(u64); | |
547 | ||
548 | if (local->hw.radiotap_timestamp.accuracy >= 0) { | |
549 | accuracy = local->hw.radiotap_timestamp.accuracy; | |
550 | flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY; | |
551 | } | |
552 | put_unaligned_le16(accuracy, pos); | |
553 | pos += sizeof(u16); | |
554 | ||
555 | *pos++ = local->hw.radiotap_timestamp.units_pos; | |
556 | *pos++ = flags; | |
557 | } | |
558 | ||
41cbb0f5 LC |
559 | if (status->encoding == RX_ENC_HE && |
560 | status->flag & RX_FLAG_RADIOTAP_HE) { | |
331aead5 | 561 | #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f) |
41cbb0f5 LC |
562 | |
563 | if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) { | |
564 | he.data6 |= HE_PREP(DATA6_NSTS, | |
565 | FIELD_GET(RX_ENC_FLAG_STBC_MASK, | |
566 | status->enc_flags)); | |
567 | he.data3 |= HE_PREP(DATA3_STBC, 1); | |
568 | } else { | |
569 | he.data6 |= HE_PREP(DATA6_NSTS, status->nss); | |
570 | } | |
571 | ||
572 | #define CHECK_GI(s) \ | |
573 | BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \ | |
574 | (int)NL80211_RATE_INFO_HE_GI_##s) | |
575 | ||
576 | CHECK_GI(0_8); | |
577 | CHECK_GI(1_6); | |
578 | CHECK_GI(3_2); | |
579 | ||
580 | he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx); | |
581 | he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm); | |
582 | he.data3 |= HE_PREP(DATA3_CODING, | |
583 | !!(status->enc_flags & RX_ENC_FLAG_LDPC)); | |
584 | ||
585 | he.data5 |= HE_PREP(DATA5_GI, status->he_gi); | |
586 | ||
587 | switch (status->bw) { | |
588 | case RATE_INFO_BW_20: | |
589 | he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC, | |
590 | IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ); | |
591 | break; | |
592 | case RATE_INFO_BW_40: | |
593 | he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC, | |
594 | IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ); | |
595 | break; | |
596 | case RATE_INFO_BW_80: | |
597 | he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC, | |
598 | IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ); | |
599 | break; | |
600 | case RATE_INFO_BW_160: | |
601 | he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC, | |
602 | IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ); | |
603 | break; | |
604 | case RATE_INFO_BW_HE_RU: | |
605 | #define CHECK_RU_ALLOC(s) \ | |
606 | BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \ | |
607 | NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4) | |
608 | ||
609 | CHECK_RU_ALLOC(26); | |
610 | CHECK_RU_ALLOC(52); | |
611 | CHECK_RU_ALLOC(106); | |
612 | CHECK_RU_ALLOC(242); | |
613 | CHECK_RU_ALLOC(484); | |
614 | CHECK_RU_ALLOC(996); | |
615 | CHECK_RU_ALLOC(2x996); | |
616 | ||
617 | he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC, | |
618 | status->he_ru + 4); | |
619 | break; | |
620 | default: | |
621 | WARN_ONCE(1, "Invalid SU BW %d\n", status->bw); | |
622 | } | |
623 | ||
624 | /* ensure 2 byte alignment */ | |
625 | while ((pos - (u8 *)rthdr) & 1) | |
626 | pos++; | |
627 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE); | |
628 | memcpy(pos, &he, sizeof(he)); | |
629 | pos += sizeof(he); | |
630 | } | |
631 | ||
632 | if (status->encoding == RX_ENC_HE && | |
633 | status->flag & RX_FLAG_RADIOTAP_HE_MU) { | |
634 | /* ensure 2 byte alignment */ | |
635 | while ((pos - (u8 *)rthdr) & 1) | |
636 | pos++; | |
637 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU); | |
638 | memcpy(pos, &he_mu, sizeof(he_mu)); | |
639 | pos += sizeof(he_mu); | |
640 | } | |
641 | ||
c3d1f875 ST |
642 | if (status->flag & RX_FLAG_NO_PSDU) { |
643 | rthdr->it_present |= | |
644 | cpu_to_le32(1 << IEEE80211_RADIOTAP_ZERO_LEN_PSDU); | |
645 | *pos++ = status->zero_length_psdu_type; | |
646 | } | |
647 | ||
d1332e7b ST |
648 | if (status->flag & RX_FLAG_RADIOTAP_LSIG) { |
649 | /* ensure 2 byte alignment */ | |
650 | while ((pos - (u8 *)rthdr) & 1) | |
651 | pos++; | |
652 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_LSIG); | |
653 | memcpy(pos, &lsig, sizeof(lsig)); | |
654 | pos += sizeof(lsig); | |
655 | } | |
656 | ||
a144f378 JB |
657 | for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) { |
658 | *pos++ = status->chain_signal[chain]; | |
659 | *pos++ = chain; | |
660 | } | |
1f7bba79 JB |
661 | |
662 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { | |
663 | /* ensure 2 byte alignment for the vendor field as required */ | |
664 | if ((pos - (u8 *)rthdr) & 1) | |
665 | *pos++ = 0; | |
666 | *pos++ = rtap.oui[0]; | |
667 | *pos++ = rtap.oui[1]; | |
668 | *pos++ = rtap.oui[2]; | |
669 | *pos++ = rtap.subns; | |
670 | put_unaligned_le16(rtap.len, pos); | |
671 | pos += 2; | |
672 | /* align the actual payload as requested */ | |
673 | while ((pos - (u8 *)rthdr) & (rtap.align - 1)) | |
674 | *pos++ = 0; | |
675 | /* data (and possible padding) already follows */ | |
676 | } | |
601ae7f2 BR |
677 | } |
678 | ||
127f60bf JB |
679 | static struct sk_buff * |
680 | ieee80211_make_monitor_skb(struct ieee80211_local *local, | |
681 | struct sk_buff **origskb, | |
682 | struct ieee80211_rate *rate, | |
c096b92a | 683 | int rtap_space, bool use_origskb) |
127f60bf JB |
684 | { |
685 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb); | |
686 | int rt_hdrlen, needed_headroom; | |
687 | struct sk_buff *skb; | |
688 | ||
689 | /* room for the radiotap header based on driver features */ | |
690 | rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb); | |
c096b92a | 691 | needed_headroom = rt_hdrlen - rtap_space; |
127f60bf JB |
692 | |
693 | if (use_origskb) { | |
694 | /* only need to expand headroom if necessary */ | |
695 | skb = *origskb; | |
696 | *origskb = NULL; | |
697 | ||
698 | /* | |
699 | * This shouldn't trigger often because most devices have an | |
700 | * RX header they pull before we get here, and that should | |
701 | * be big enough for our radiotap information. We should | |
702 | * probably export the length to drivers so that we can have | |
703 | * them allocate enough headroom to start with. | |
704 | */ | |
705 | if (skb_headroom(skb) < needed_headroom && | |
706 | pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) { | |
707 | dev_kfree_skb(skb); | |
708 | return NULL; | |
709 | } | |
710 | } else { | |
711 | /* | |
712 | * Need to make a copy and possibly remove radiotap header | |
713 | * and FCS from the original. | |
714 | */ | |
715 | skb = skb_copy_expand(*origskb, needed_headroom, 0, GFP_ATOMIC); | |
716 | ||
717 | if (!skb) | |
718 | return NULL; | |
719 | } | |
720 | ||
721 | /* prepend radiotap information */ | |
722 | ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true); | |
723 | ||
724 | skb_reset_mac_header(skb); | |
725 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
726 | skb->pkt_type = PACKET_OTHERHOST; | |
727 | skb->protocol = htons(ETH_P_802_2); | |
728 | ||
729 | return skb; | |
730 | } | |
731 | ||
b2e7771e JB |
732 | /* |
733 | * This function copies a received frame to all monitor interfaces and | |
734 | * returns a cleaned-up SKB that no longer includes the FCS nor the | |
735 | * radiotap header the driver might have added. | |
736 | */ | |
737 | static struct sk_buff * | |
738 | ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, | |
8318d78a | 739 | struct ieee80211_rate *rate) |
b2e7771e | 740 | { |
f1d58c25 | 741 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb); |
b2e7771e | 742 | struct ieee80211_sub_if_data *sdata; |
127f60bf | 743 | struct sk_buff *monskb = NULL; |
b2e7771e | 744 | int present_fcs_len = 0; |
c096b92a | 745 | unsigned int rtap_space = 0; |
42bd20d9 AE |
746 | struct ieee80211_sub_if_data *monitor_sdata = |
747 | rcu_dereference(local->monitor_sdata); | |
127f60bf | 748 | bool only_monitor = false; |
8020919a | 749 | unsigned int min_head_len; |
1f7bba79 | 750 | |
41cbb0f5 LC |
751 | if (status->flag & RX_FLAG_RADIOTAP_HE) |
752 | rtap_space += sizeof(struct ieee80211_radiotap_he); | |
753 | ||
754 | if (status->flag & RX_FLAG_RADIOTAP_HE_MU) | |
755 | rtap_space += sizeof(struct ieee80211_radiotap_he_mu); | |
756 | ||
d359bbce IP |
757 | if (status->flag & RX_FLAG_RADIOTAP_LSIG) |
758 | rtap_space += sizeof(struct ieee80211_radiotap_lsig); | |
759 | ||
1f7bba79 | 760 | if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) { |
d359bbce IP |
761 | struct ieee80211_vendor_radiotap *rtap = |
762 | (void *)(origskb->data + rtap_space); | |
1f7bba79 | 763 | |
c096b92a | 764 | rtap_space += sizeof(*rtap) + rtap->len + rtap->pad; |
1f7bba79 | 765 | } |
b2e7771e | 766 | |
8020919a IP |
767 | min_head_len = rtap_space; |
768 | ||
b2e7771e JB |
769 | /* |
770 | * First, we may need to make a copy of the skb because | |
771 | * (1) we need to modify it for radiotap (if not present), and | |
772 | * (2) the other RX handlers will modify the skb we got. | |
773 | * | |
774 | * We don't need to, of course, if we aren't going to return | |
775 | * the SKB because it has a bad FCS/PLCP checksum. | |
776 | */ | |
0869aea0 | 777 | |
8020919a IP |
778 | if (!(status->flag & RX_FLAG_NO_PSDU)) { |
779 | if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) { | |
780 | if (unlikely(origskb->len <= FCS_LEN + rtap_space)) { | |
781 | /* driver bug */ | |
782 | WARN_ON(1); | |
783 | dev_kfree_skb(origskb); | |
784 | return NULL; | |
785 | } | |
786 | present_fcs_len = FCS_LEN; | |
30841f5c | 787 | } |
8020919a IP |
788 | |
789 | /* also consider the hdr->frame_control */ | |
790 | min_head_len += 2; | |
30841f5c | 791 | } |
b2e7771e | 792 | |
8020919a IP |
793 | /* ensure that the expected data elements are in skb head */ |
794 | if (!pskb_may_pull(origskb, min_head_len)) { | |
e3cf8b3f ZY |
795 | dev_kfree_skb(origskb); |
796 | return NULL; | |
797 | } | |
798 | ||
c096b92a | 799 | only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space); |
127f60bf | 800 | |
17883048 | 801 | if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) { |
127f60bf | 802 | if (only_monitor) { |
b2e7771e JB |
803 | dev_kfree_skb(origskb); |
804 | return NULL; | |
805 | } | |
806 | ||
c1129924 JB |
807 | return ieee80211_clean_skb(origskb, present_fcs_len, |
808 | rtap_space); | |
b2e7771e JB |
809 | } |
810 | ||
c096b92a | 811 | ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space); |
9e478066 | 812 | |
f64331d5 | 813 | list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) { |
127f60bf JB |
814 | bool last_monitor = list_is_last(&sdata->u.mntr.list, |
815 | &local->mon_list); | |
816 | ||
817 | if (!monskb) | |
818 | monskb = ieee80211_make_monitor_skb(local, &origskb, | |
c096b92a | 819 | rate, rtap_space, |
127f60bf JB |
820 | only_monitor && |
821 | last_monitor); | |
822 | ||
823 | if (monskb) { | |
824 | struct sk_buff *skb; | |
825 | ||
826 | if (last_monitor) { | |
827 | skb = monskb; | |
828 | monskb = NULL; | |
829 | } else { | |
830 | skb = skb_clone(monskb, GFP_ATOMIC); | |
831 | } | |
832 | ||
833 | if (skb) { | |
834 | skb->dev = sdata->dev; | |
36ec144f | 835 | dev_sw_netstats_rx_add(skb->dev, skb->len); |
127f60bf | 836 | netif_receive_skb(skb); |
b2e7771e JB |
837 | } |
838 | } | |
839 | ||
127f60bf JB |
840 | if (last_monitor) |
841 | break; | |
b2e7771e JB |
842 | } |
843 | ||
127f60bf JB |
844 | /* this happens if last_monitor was erroneously false */ |
845 | dev_kfree_skb(monskb); | |
846 | ||
847 | /* ditto */ | |
848 | if (!origskb) | |
849 | return NULL; | |
b2e7771e | 850 | |
c1129924 | 851 | return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space); |
b2e7771e JB |
852 | } |
853 | ||
5cf121c3 | 854 | static void ieee80211_parse_qos(struct ieee80211_rx_data *rx) |
6e0d114d | 855 | { |
238f74a2 | 856 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
554891e6 | 857 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
9e26297a | 858 | int tid, seqno_idx, security_idx; |
6e0d114d JB |
859 | |
860 | /* does the frame have a qos control field? */ | |
238f74a2 HH |
861 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
862 | u8 *qc = ieee80211_get_qos_ctl(hdr); | |
6e0d114d | 863 | /* frame has qos control */ |
238f74a2 | 864 | tid = *qc & IEEE80211_QOS_CTL_TID_MASK; |
04b7dcf9 | 865 | if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT) |
554891e6 | 866 | status->rx_flags |= IEEE80211_RX_AMSDU; |
9e26297a JB |
867 | |
868 | seqno_idx = tid; | |
869 | security_idx = tid; | |
6e0d114d | 870 | } else { |
1411f9b5 JB |
871 | /* |
872 | * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"): | |
873 | * | |
874 | * Sequence numbers for management frames, QoS data | |
875 | * frames with a broadcast/multicast address in the | |
876 | * Address 1 field, and all non-QoS data frames sent | |
877 | * by QoS STAs are assigned using an additional single | |
878 | * modulo-4096 counter, [...] | |
879 | * | |
880 | * We also use that counter for non-QoS STAs. | |
881 | */ | |
5a306f58 | 882 | seqno_idx = IEEE80211_NUM_TIDS; |
9e26297a JB |
883 | security_idx = 0; |
884 | if (ieee80211_is_mgmt(hdr->frame_control)) | |
5a306f58 | 885 | security_idx = IEEE80211_NUM_TIDS; |
9e26297a | 886 | tid = 0; |
6e0d114d | 887 | } |
52865dfd | 888 | |
9e26297a JB |
889 | rx->seqno_idx = seqno_idx; |
890 | rx->security_idx = security_idx; | |
6e0d114d JB |
891 | /* Set skb->priority to 1d tag if highest order bit of TID is not set. |
892 | * For now, set skb->priority to 0 for other cases. */ | |
893 | rx->skb->priority = (tid > 7) ? 0 : tid; | |
38f3714d | 894 | } |
6e0d114d | 895 | |
d1c3a37c JB |
896 | /** |
897 | * DOC: Packet alignment | |
898 | * | |
899 | * Drivers always need to pass packets that are aligned to two-byte boundaries | |
900 | * to the stack. | |
901 | * | |
902 | * Additionally, should, if possible, align the payload data in a way that | |
903 | * guarantees that the contained IP header is aligned to a four-byte | |
904 | * boundary. In the case of regular frames, this simply means aligning the | |
905 | * payload to a four-byte boundary (because either the IP header is directly | |
906 | * contained, or IV/RFC1042 headers that have a length divisible by four are | |
59d9cb07 KV |
907 | * in front of it). If the payload data is not properly aligned and the |
908 | * architecture doesn't support efficient unaligned operations, mac80211 | |
909 | * will align the data. | |
d1c3a37c JB |
910 | * |
911 | * With A-MSDU frames, however, the payload data address must yield two modulo | |
912 | * four because there are 14-byte 802.3 headers within the A-MSDU frames that | |
913 | * push the IP header further back to a multiple of four again. Thankfully, the | |
914 | * specs were sane enough this time around to require padding each A-MSDU | |
915 | * subframe to a length that is a multiple of four. | |
916 | * | |
25985edc | 917 | * Padding like Atheros hardware adds which is between the 802.11 header and |
d1c3a37c JB |
918 | * the payload is not supported, the driver is required to move the 802.11 |
919 | * header to be directly in front of the payload in that case. | |
920 | */ | |
921 | static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx) | |
38f3714d | 922 | { |
59d9cb07 | 923 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
441275e1 | 924 | WARN_ON_ONCE((unsigned long)rx->skb->data & 1); |
d1c3a37c | 925 | #endif |
6e0d114d JB |
926 | } |
927 | ||
6368e4b1 | 928 | |
571ecf67 JB |
929 | /* rx handlers */ |
930 | ||
3cfcf6ac JM |
931 | static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb) |
932 | { | |
933 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
934 | ||
d8ca16db | 935 | if (is_multicast_ether_addr(hdr->addr1)) |
3cfcf6ac JM |
936 | return 0; |
937 | ||
d8ca16db | 938 | return ieee80211_is_robust_mgmt_frame(skb); |
3cfcf6ac JM |
939 | } |
940 | ||
941 | ||
942 | static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb) | |
943 | { | |
944 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
945 | ||
d8ca16db | 946 | if (!is_multicast_ether_addr(hdr->addr1)) |
3cfcf6ac JM |
947 | return 0; |
948 | ||
d8ca16db | 949 | return ieee80211_is_robust_mgmt_frame(skb); |
3cfcf6ac JM |
950 | } |
951 | ||
952 | ||
953 | /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */ | |
954 | static int ieee80211_get_mmie_keyidx(struct sk_buff *skb) | |
955 | { | |
956 | struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data; | |
957 | struct ieee80211_mmie *mmie; | |
56c52da2 | 958 | struct ieee80211_mmie_16 *mmie16; |
3cfcf6ac | 959 | |
1df332e8 | 960 | if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da)) |
3cfcf6ac JM |
961 | return -1; |
962 | ||
af2d14b0 JM |
963 | if (!ieee80211_is_robust_mgmt_frame(skb) && |
964 | !ieee80211_is_beacon(hdr->frame_control)) | |
3cfcf6ac JM |
965 | return -1; /* not a robust management frame */ |
966 | ||
967 | mmie = (struct ieee80211_mmie *) | |
968 | (skb->data + skb->len - sizeof(*mmie)); | |
56c52da2 JM |
969 | if (mmie->element_id == WLAN_EID_MMIE && |
970 | mmie->length == sizeof(*mmie) - 2) | |
971 | return le16_to_cpu(mmie->key_id); | |
972 | ||
973 | mmie16 = (struct ieee80211_mmie_16 *) | |
974 | (skb->data + skb->len - sizeof(*mmie16)); | |
975 | if (skb->len >= 24 + sizeof(*mmie16) && | |
976 | mmie16->element_id == WLAN_EID_MMIE && | |
977 | mmie16->length == sizeof(*mmie16) - 2) | |
978 | return le16_to_cpu(mmie16->key_id); | |
979 | ||
980 | return -1; | |
3cfcf6ac JM |
981 | } |
982 | ||
96fc6efb AW |
983 | static int ieee80211_get_keyid(struct sk_buff *skb, |
984 | const struct ieee80211_cipher_scheme *cs) | |
2475b1cc MS |
985 | { |
986 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
987 | __le16 fc; | |
988 | int hdrlen; | |
96fc6efb AW |
989 | int minlen; |
990 | u8 key_idx_off; | |
991 | u8 key_idx_shift; | |
2475b1cc MS |
992 | u8 keyid; |
993 | ||
994 | fc = hdr->frame_control; | |
995 | hdrlen = ieee80211_hdrlen(fc); | |
996 | ||
96fc6efb AW |
997 | if (cs) { |
998 | minlen = hdrlen + cs->hdr_len; | |
999 | key_idx_off = hdrlen + cs->key_idx_off; | |
1000 | key_idx_shift = cs->key_idx_shift; | |
1001 | } else { | |
1002 | /* WEP, TKIP, CCMP and GCMP */ | |
1003 | minlen = hdrlen + IEEE80211_WEP_IV_LEN; | |
1004 | key_idx_off = hdrlen + 3; | |
1005 | key_idx_shift = 6; | |
1006 | } | |
1007 | ||
1008 | if (unlikely(skb->len < minlen)) | |
2475b1cc MS |
1009 | return -EINVAL; |
1010 | ||
96fc6efb AW |
1011 | skb_copy_bits(skb, key_idx_off, &keyid, 1); |
1012 | ||
1013 | if (cs) | |
1014 | keyid &= cs->key_idx_mask; | |
1015 | keyid >>= key_idx_shift; | |
1016 | ||
1017 | /* cs could use more than the usual two bits for the keyid */ | |
1018 | if (unlikely(keyid >= NUM_DEFAULT_KEYS)) | |
1019 | return -EINVAL; | |
2475b1cc MS |
1020 | |
1021 | return keyid; | |
1022 | } | |
1023 | ||
1df332e8 | 1024 | static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx) |
33b64eb2 | 1025 | { |
a7767f95 | 1026 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
47846c9b | 1027 | char *dev_addr = rx->sdata->vif.addr; |
d6d1a5a7 | 1028 | |
a7767f95 | 1029 | if (ieee80211_is_data(hdr->frame_control)) { |
3c5772a5 JC |
1030 | if (is_multicast_ether_addr(hdr->addr1)) { |
1031 | if (ieee80211_has_tods(hdr->frame_control) || | |
1df332e8 | 1032 | !ieee80211_has_fromds(hdr->frame_control)) |
3c5772a5 | 1033 | return RX_DROP_MONITOR; |
b203ca39 | 1034 | if (ether_addr_equal(hdr->addr3, dev_addr)) |
3c5772a5 JC |
1035 | return RX_DROP_MONITOR; |
1036 | } else { | |
1037 | if (!ieee80211_has_a4(hdr->frame_control)) | |
1038 | return RX_DROP_MONITOR; | |
b203ca39 | 1039 | if (ether_addr_equal(hdr->addr4, dev_addr)) |
3c5772a5 JC |
1040 | return RX_DROP_MONITOR; |
1041 | } | |
33b64eb2 LCC |
1042 | } |
1043 | ||
1044 | /* If there is not an established peer link and this is not a peer link | |
1045 | * establisment frame, beacon or probe, drop the frame. | |
1046 | */ | |
1047 | ||
57cf8043 | 1048 | if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) { |
33b64eb2 | 1049 | struct ieee80211_mgmt *mgmt; |
d6d1a5a7 | 1050 | |
a7767f95 | 1051 | if (!ieee80211_is_mgmt(hdr->frame_control)) |
33b64eb2 LCC |
1052 | return RX_DROP_MONITOR; |
1053 | ||
a7767f95 | 1054 | if (ieee80211_is_action(hdr->frame_control)) { |
d3aaec8a | 1055 | u8 category; |
9b395bc3 JB |
1056 | |
1057 | /* make sure category field is present */ | |
1058 | if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE) | |
1059 | return RX_DROP_MONITOR; | |
1060 | ||
33b64eb2 | 1061 | mgmt = (struct ieee80211_mgmt *)hdr; |
d3aaec8a JC |
1062 | category = mgmt->u.action.category; |
1063 | if (category != WLAN_CATEGORY_MESH_ACTION && | |
1df332e8 | 1064 | category != WLAN_CATEGORY_SELF_PROTECTED) |
33b64eb2 | 1065 | return RX_DROP_MONITOR; |
33b64eb2 | 1066 | return RX_CONTINUE; |
33b64eb2 LCC |
1067 | } |
1068 | ||
a7767f95 HH |
1069 | if (ieee80211_is_probe_req(hdr->frame_control) || |
1070 | ieee80211_is_probe_resp(hdr->frame_control) || | |
71839121 JC |
1071 | ieee80211_is_beacon(hdr->frame_control) || |
1072 | ieee80211_is_auth(hdr->frame_control)) | |
a7767f95 HH |
1073 | return RX_CONTINUE; |
1074 | ||
1075 | return RX_DROP_MONITOR; | |
a7767f95 HH |
1076 | } |
1077 | ||
902acc78 JB |
1078 | return RX_CONTINUE; |
1079 | } | |
33b64eb2 | 1080 | |
fb4ea054 JB |
1081 | static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx, |
1082 | int index) | |
1083 | { | |
1084 | struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index]; | |
1085 | struct sk_buff *tail = skb_peek_tail(frames); | |
1086 | struct ieee80211_rx_status *status; | |
1087 | ||
06470f74 SS |
1088 | if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index)) |
1089 | return true; | |
1090 | ||
fb4ea054 JB |
1091 | if (!tail) |
1092 | return false; | |
1093 | ||
1094 | status = IEEE80211_SKB_RXCB(tail); | |
1095 | if (status->flag & RX_FLAG_AMSDU_MORE) | |
1096 | return false; | |
1097 | ||
1098 | return true; | |
1099 | } | |
1100 | ||
d3b2fb53 | 1101 | static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata, |
1edfb1af | 1102 | struct tid_ampdu_rx *tid_agg_rx, |
f9e124fb CL |
1103 | int index, |
1104 | struct sk_buff_head *frames) | |
1edfb1af | 1105 | { |
83eb935e MK |
1106 | struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index]; |
1107 | struct sk_buff *skb; | |
4cfda47b | 1108 | struct ieee80211_rx_status *status; |
1edfb1af | 1109 | |
dd318575 JB |
1110 | lockdep_assert_held(&tid_agg_rx->reorder_lock); |
1111 | ||
83eb935e | 1112 | if (skb_queue_empty(skb_list)) |
1edfb1af JB |
1113 | goto no_frame; |
1114 | ||
fb4ea054 | 1115 | if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) { |
83eb935e MK |
1116 | __skb_queue_purge(skb_list); |
1117 | goto no_frame; | |
1118 | } | |
1119 | ||
1120 | /* release frames from the reorder ring buffer */ | |
1edfb1af | 1121 | tid_agg_rx->stored_mpdu_num--; |
83eb935e MK |
1122 | while ((skb = __skb_dequeue(skb_list))) { |
1123 | status = IEEE80211_SKB_RXCB(skb); | |
1124 | status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE; | |
1125 | __skb_queue_tail(frames, skb); | |
1126 | } | |
1edfb1af JB |
1127 | |
1128 | no_frame: | |
06470f74 | 1129 | tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index); |
9a886586 | 1130 | tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num); |
1edfb1af JB |
1131 | } |
1132 | ||
d3b2fb53 | 1133 | static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata, |
1edfb1af | 1134 | struct tid_ampdu_rx *tid_agg_rx, |
f9e124fb CL |
1135 | u16 head_seq_num, |
1136 | struct sk_buff_head *frames) | |
1edfb1af JB |
1137 | { |
1138 | int index; | |
1139 | ||
dd318575 JB |
1140 | lockdep_assert_held(&tid_agg_rx->reorder_lock); |
1141 | ||
9a886586 | 1142 | while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) { |
2e3049b7 | 1143 | index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
f9e124fb CL |
1144 | ieee80211_release_reorder_frame(sdata, tid_agg_rx, index, |
1145 | frames); | |
1edfb1af JB |
1146 | } |
1147 | } | |
1148 | ||
1149 | /* | |
1150 | * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If | |
1151 | * the skb was added to the buffer longer than this time ago, the earlier | |
1152 | * frames that have not yet been received are assumed to be lost and the skb | |
1153 | * can be released for processing. This may also release other skb's from the | |
1154 | * reorder buffer if there are no additional gaps between the frames. | |
2bff8ebf CL |
1155 | * |
1156 | * Callers must hold tid_agg_rx->reorder_lock. | |
1edfb1af JB |
1157 | */ |
1158 | #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10) | |
1159 | ||
d3b2fb53 | 1160 | static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata, |
f9e124fb CL |
1161 | struct tid_ampdu_rx *tid_agg_rx, |
1162 | struct sk_buff_head *frames) | |
aa0c8636 | 1163 | { |
83eb935e | 1164 | int index, i, j; |
aa0c8636 | 1165 | |
dd318575 JB |
1166 | lockdep_assert_held(&tid_agg_rx->reorder_lock); |
1167 | ||
aa0c8636 | 1168 | /* release the buffer until next missing frame */ |
2e3049b7 | 1169 | index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
fb4ea054 | 1170 | if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) && |
07ae2dfc | 1171 | tid_agg_rx->stored_mpdu_num) { |
aa0c8636 CL |
1172 | /* |
1173 | * No buffers ready to be released, but check whether any | |
1174 | * frames in the reorder buffer have timed out. | |
1175 | */ | |
aa0c8636 CL |
1176 | int skipped = 1; |
1177 | for (j = (index + 1) % tid_agg_rx->buf_size; j != index; | |
1178 | j = (j + 1) % tid_agg_rx->buf_size) { | |
fb4ea054 | 1179 | if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) { |
aa0c8636 CL |
1180 | skipped++; |
1181 | continue; | |
1182 | } | |
499fe9a4 DH |
1183 | if (skipped && |
1184 | !time_after(jiffies, tid_agg_rx->reorder_time[j] + | |
aa0c8636 | 1185 | HT_RX_REORDER_BUF_TIMEOUT)) |
2bff8ebf | 1186 | goto set_release_timer; |
aa0c8636 | 1187 | |
83eb935e MK |
1188 | /* don't leave incomplete A-MSDUs around */ |
1189 | for (i = (index + 1) % tid_agg_rx->buf_size; i != j; | |
1190 | i = (i + 1) % tid_agg_rx->buf_size) | |
1191 | __skb_queue_purge(&tid_agg_rx->reorder_buf[i]); | |
1192 | ||
bdcbd8e0 JB |
1193 | ht_dbg_ratelimited(sdata, |
1194 | "release an RX reorder frame due to timeout on earlier frames\n"); | |
f9e124fb CL |
1195 | ieee80211_release_reorder_frame(sdata, tid_agg_rx, j, |
1196 | frames); | |
aa0c8636 CL |
1197 | |
1198 | /* | |
1199 | * Increment the head seq# also for the skipped slots. | |
1200 | */ | |
1201 | tid_agg_rx->head_seq_num = | |
9a886586 JB |
1202 | (tid_agg_rx->head_seq_num + |
1203 | skipped) & IEEE80211_SN_MASK; | |
aa0c8636 CL |
1204 | skipped = 0; |
1205 | } | |
fb4ea054 | 1206 | } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) { |
f9e124fb CL |
1207 | ieee80211_release_reorder_frame(sdata, tid_agg_rx, index, |
1208 | frames); | |
2e3049b7 | 1209 | index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
aa0c8636 | 1210 | } |
2bff8ebf CL |
1211 | |
1212 | if (tid_agg_rx->stored_mpdu_num) { | |
2e3049b7 | 1213 | j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
2bff8ebf CL |
1214 | |
1215 | for (; j != (index - 1) % tid_agg_rx->buf_size; | |
1216 | j = (j + 1) % tid_agg_rx->buf_size) { | |
fb4ea054 | 1217 | if (ieee80211_rx_reorder_ready(tid_agg_rx, j)) |
2bff8ebf CL |
1218 | break; |
1219 | } | |
1220 | ||
1221 | set_release_timer: | |
1222 | ||
788211d8 JB |
1223 | if (!tid_agg_rx->removed) |
1224 | mod_timer(&tid_agg_rx->reorder_timer, | |
1225 | tid_agg_rx->reorder_time[j] + 1 + | |
1226 | HT_RX_REORDER_BUF_TIMEOUT); | |
2bff8ebf CL |
1227 | } else { |
1228 | del_timer(&tid_agg_rx->reorder_timer); | |
1229 | } | |
aa0c8636 CL |
1230 | } |
1231 | ||
1edfb1af JB |
1232 | /* |
1233 | * As this function belongs to the RX path it must be under | |
1234 | * rcu_read_lock protection. It returns false if the frame | |
1235 | * can be processed immediately, true if it was consumed. | |
1236 | */ | |
d3b2fb53 | 1237 | static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata, |
1edfb1af | 1238 | struct tid_ampdu_rx *tid_agg_rx, |
f9e124fb CL |
1239 | struct sk_buff *skb, |
1240 | struct sk_buff_head *frames) | |
1edfb1af JB |
1241 | { |
1242 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
83eb935e | 1243 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
1edfb1af JB |
1244 | u16 sc = le16_to_cpu(hdr->seq_ctrl); |
1245 | u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; | |
1246 | u16 head_seq_num, buf_size; | |
1247 | int index; | |
2bff8ebf | 1248 | bool ret = true; |
1edfb1af | 1249 | |
dd318575 JB |
1250 | spin_lock(&tid_agg_rx->reorder_lock); |
1251 | ||
4549cf2b MK |
1252 | /* |
1253 | * Offloaded BA sessions have no known starting sequence number so pick | |
1254 | * one from first Rxed frame for this tid after BA was started. | |
1255 | */ | |
1256 | if (unlikely(tid_agg_rx->auto_seq)) { | |
1257 | tid_agg_rx->auto_seq = false; | |
1258 | tid_agg_rx->ssn = mpdu_seq_num; | |
1259 | tid_agg_rx->head_seq_num = mpdu_seq_num; | |
1260 | } | |
1261 | ||
1edfb1af JB |
1262 | buf_size = tid_agg_rx->buf_size; |
1263 | head_seq_num = tid_agg_rx->head_seq_num; | |
1264 | ||
b7540d8f SS |
1265 | /* |
1266 | * If the current MPDU's SN is smaller than the SSN, it shouldn't | |
1267 | * be reordered. | |
1268 | */ | |
1269 | if (unlikely(!tid_agg_rx->started)) { | |
1270 | if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) { | |
1271 | ret = false; | |
1272 | goto out; | |
1273 | } | |
1274 | tid_agg_rx->started = true; | |
1275 | } | |
1276 | ||
1edfb1af | 1277 | /* frame with out of date sequence number */ |
9a886586 | 1278 | if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) { |
1edfb1af | 1279 | dev_kfree_skb(skb); |
2bff8ebf | 1280 | goto out; |
1edfb1af JB |
1281 | } |
1282 | ||
1283 | /* | |
1284 | * If frame the sequence number exceeds our buffering window | |
1285 | * size release some previous frames to make room for this one. | |
1286 | */ | |
9a886586 JB |
1287 | if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) { |
1288 | head_seq_num = ieee80211_sn_inc( | |
1289 | ieee80211_sn_sub(mpdu_seq_num, buf_size)); | |
1edfb1af | 1290 | /* release stored frames up to new head to stack */ |
d3b2fb53 | 1291 | ieee80211_release_reorder_frames(sdata, tid_agg_rx, |
f9e124fb | 1292 | head_seq_num, frames); |
1edfb1af JB |
1293 | } |
1294 | ||
1295 | /* Now the new frame is always in the range of the reordering buffer */ | |
1296 | ||
2e3049b7 | 1297 | index = mpdu_seq_num % tid_agg_rx->buf_size; |
1edfb1af JB |
1298 | |
1299 | /* check if we already stored this frame */ | |
fb4ea054 | 1300 | if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) { |
1edfb1af | 1301 | dev_kfree_skb(skb); |
2bff8ebf | 1302 | goto out; |
1edfb1af JB |
1303 | } |
1304 | ||
1305 | /* | |
1306 | * If the current MPDU is in the right order and nothing else | |
1307 | * is stored we can process it directly, no need to buffer it. | |
c835b214 JB |
1308 | * If it is first but there's something stored, we may be able |
1309 | * to release frames after this one. | |
1edfb1af JB |
1310 | */ |
1311 | if (mpdu_seq_num == tid_agg_rx->head_seq_num && | |
1312 | tid_agg_rx->stored_mpdu_num == 0) { | |
83eb935e MK |
1313 | if (!(status->flag & RX_FLAG_AMSDU_MORE)) |
1314 | tid_agg_rx->head_seq_num = | |
1315 | ieee80211_sn_inc(tid_agg_rx->head_seq_num); | |
2bff8ebf CL |
1316 | ret = false; |
1317 | goto out; | |
1edfb1af JB |
1318 | } |
1319 | ||
1320 | /* put the frame in the reordering buffer */ | |
83eb935e MK |
1321 | __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb); |
1322 | if (!(status->flag & RX_FLAG_AMSDU_MORE)) { | |
1323 | tid_agg_rx->reorder_time[index] = jiffies; | |
1324 | tid_agg_rx->stored_mpdu_num++; | |
1325 | ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames); | |
1326 | } | |
1edfb1af | 1327 | |
2bff8ebf CL |
1328 | out: |
1329 | spin_unlock(&tid_agg_rx->reorder_lock); | |
1330 | return ret; | |
1edfb1af JB |
1331 | } |
1332 | ||
1333 | /* | |
1334 | * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns | |
1335 | * true if the MPDU was buffered, false if it should be processed. | |
1336 | */ | |
f9e124fb CL |
1337 | static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx, |
1338 | struct sk_buff_head *frames) | |
1edfb1af | 1339 | { |
2569a826 JB |
1340 | struct sk_buff *skb = rx->skb; |
1341 | struct ieee80211_local *local = rx->local; | |
1edfb1af | 1342 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
2569a826 | 1343 | struct sta_info *sta = rx->sta; |
1edfb1af JB |
1344 | struct tid_ampdu_rx *tid_agg_rx; |
1345 | u16 sc; | |
6cc00d54 | 1346 | u8 tid, ack_policy; |
1edfb1af | 1347 | |
051a41fa JB |
1348 | if (!ieee80211_is_data_qos(hdr->frame_control) || |
1349 | is_multicast_ether_addr(hdr->addr1)) | |
2569a826 | 1350 | goto dont_reorder; |
1edfb1af JB |
1351 | |
1352 | /* | |
1353 | * filter the QoS data rx stream according to | |
1354 | * STA/TID and check if this STA/TID is on aggregation | |
1355 | */ | |
1356 | ||
1edfb1af | 1357 | if (!sta) |
2569a826 | 1358 | goto dont_reorder; |
1edfb1af | 1359 | |
6cc00d54 TP |
1360 | ack_policy = *ieee80211_get_qos_ctl(hdr) & |
1361 | IEEE80211_QOS_CTL_ACK_POLICY_MASK; | |
a1f2ba04 | 1362 | tid = ieee80211_get_tid(hdr); |
1edfb1af | 1363 | |
a87f736d | 1364 | tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); |
bfe40fa3 JB |
1365 | if (!tid_agg_rx) { |
1366 | if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK && | |
1367 | !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) && | |
1368 | !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg)) | |
1369 | ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid, | |
1370 | WLAN_BACK_RECIPIENT, | |
1371 | WLAN_REASON_QSTA_REQUIRE_SETUP); | |
a87f736d | 1372 | goto dont_reorder; |
bfe40fa3 | 1373 | } |
1edfb1af JB |
1374 | |
1375 | /* qos null data frames are excluded */ | |
1376 | if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC))) | |
a87f736d | 1377 | goto dont_reorder; |
1edfb1af | 1378 | |
6cc00d54 TP |
1379 | /* not part of a BA session */ |
1380 | if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK && | |
1381 | ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL) | |
1382 | goto dont_reorder; | |
1383 | ||
1edfb1af JB |
1384 | /* new, potentially un-ordered, ampdu frame - process it */ |
1385 | ||
1386 | /* reset session timer */ | |
1387 | if (tid_agg_rx->timeout) | |
12d3952f | 1388 | tid_agg_rx->last_rx = jiffies; |
1edfb1af JB |
1389 | |
1390 | /* if this mpdu is fragmented - terminate rx aggregation session */ | |
1391 | sc = le16_to_cpu(hdr->seq_ctrl); | |
1392 | if (sc & IEEE80211_SCTL_FRAG) { | |
344eec67 JB |
1393 | skb_queue_tail(&rx->sdata->skb_queue, skb); |
1394 | ieee80211_queue_work(&local->hw, &rx->sdata->work); | |
2569a826 | 1395 | return; |
1edfb1af JB |
1396 | } |
1397 | ||
a87f736d JB |
1398 | /* |
1399 | * No locking needed -- we will only ever process one | |
1400 | * RX packet at a time, and thus own tid_agg_rx. All | |
1401 | * other code manipulating it needs to (and does) make | |
1402 | * sure that we cannot get to it any more before doing | |
1403 | * anything with it. | |
1404 | */ | |
f9e124fb CL |
1405 | if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb, |
1406 | frames)) | |
2569a826 JB |
1407 | return; |
1408 | ||
1409 | dont_reorder: | |
f9e124fb | 1410 | __skb_queue_tail(frames, skb); |
1edfb1af | 1411 | } |
33b64eb2 | 1412 | |
49461622 | 1413 | static ieee80211_rx_result debug_noinline |
0395442a | 1414 | ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx) |
571ecf67 | 1415 | { |
a7767f95 | 1416 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
554891e6 | 1417 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
571ecf67 | 1418 | |
f9cfa5f3 SS |
1419 | if (status->flag & RX_FLAG_DUP_VALIDATED) |
1420 | return RX_CONTINUE; | |
1421 | ||
6b0f3274 JB |
1422 | /* |
1423 | * Drop duplicate 802.11 retransmissions | |
1424 | * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery") | |
1425 | */ | |
0395442a JB |
1426 | |
1427 | if (rx->skb->len < 24) | |
1428 | return RX_CONTINUE; | |
1429 | ||
1430 | if (ieee80211_is_ctl(hdr->frame_control) || | |
30b2f0be | 1431 | ieee80211_is_any_nullfunc(hdr->frame_control) || |
0395442a JB |
1432 | is_multicast_ether_addr(hdr->addr1)) |
1433 | return RX_CONTINUE; | |
1434 | ||
a732fa70 JB |
1435 | if (!rx->sta) |
1436 | return RX_CONTINUE; | |
1437 | ||
1438 | if (unlikely(ieee80211_has_retry(hdr->frame_control) && | |
1439 | rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) { | |
1440 | I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount); | |
e5a9f8d0 | 1441 | rx->sta->rx_stats.num_duplicates++; |
a732fa70 JB |
1442 | return RX_DROP_UNUSABLE; |
1443 | } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) { | |
1444 | rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl; | |
571ecf67 JB |
1445 | } |
1446 | ||
0395442a JB |
1447 | return RX_CONTINUE; |
1448 | } | |
1449 | ||
1450 | static ieee80211_rx_result debug_noinline | |
1451 | ieee80211_rx_h_check(struct ieee80211_rx_data *rx) | |
1452 | { | |
1453 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | |
1454 | ||
571ecf67 JB |
1455 | /* Drop disallowed frame classes based on STA auth/assoc state; |
1456 | * IEEE 802.11, Chap 5.5. | |
1457 | * | |
ccd7b362 JB |
1458 | * mac80211 filters only based on association state, i.e. it drops |
1459 | * Class 3 frames from not associated stations. hostapd sends | |
571ecf67 JB |
1460 | * deauth/disassoc frames when needed. In addition, hostapd is |
1461 | * responsible for filtering on both auth and assoc states. | |
1462 | */ | |
33b64eb2 | 1463 | |
902acc78 | 1464 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
33b64eb2 | 1465 | return ieee80211_rx_mesh_check(rx); |
33b64eb2 | 1466 | |
a7767f95 HH |
1467 | if (unlikely((ieee80211_is_data(hdr->frame_control) || |
1468 | ieee80211_is_pspoll(hdr->frame_control)) && | |
05c914fe | 1469 | rx->sdata->vif.type != NL80211_IFTYPE_ADHOC && |
239281f8 | 1470 | rx->sdata->vif.type != NL80211_IFTYPE_OCB && |
c2c98fde | 1471 | (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) { |
7852e361 JB |
1472 | /* |
1473 | * accept port control frames from the AP even when it's not | |
1474 | * yet marked ASSOC to prevent a race where we don't set the | |
1475 | * assoc bit quickly enough before it sends the first frame | |
1476 | */ | |
1477 | if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION && | |
2a33bee2 | 1478 | ieee80211_is_data_present(hdr->frame_control)) { |
6dbda2d0 JB |
1479 | unsigned int hdrlen; |
1480 | __be16 ethertype; | |
1481 | ||
1482 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
1483 | ||
1484 | if (rx->skb->len < hdrlen + 8) | |
1485 | return RX_DROP_MONITOR; | |
1486 | ||
1487 | skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2); | |
1488 | if (ethertype == rx->sdata->control_port_protocol) | |
2a33bee2 GE |
1489 | return RX_CONTINUE; |
1490 | } | |
21fc7560 JB |
1491 | |
1492 | if (rx->sdata->vif.type == NL80211_IFTYPE_AP && | |
1493 | cfg80211_rx_spurious_frame(rx->sdata->dev, | |
1494 | hdr->addr2, | |
1495 | GFP_ATOMIC)) | |
1496 | return RX_DROP_UNUSABLE; | |
1497 | ||
e4c26add | 1498 | return RX_DROP_MONITOR; |
2a33bee2 | 1499 | } |
571ecf67 | 1500 | |
9ae54c84 | 1501 | return RX_CONTINUE; |
570bd537 JB |
1502 | } |
1503 | ||
1504 | ||
572e0012 KV |
1505 | static ieee80211_rx_result debug_noinline |
1506 | ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx) | |
1507 | { | |
1508 | struct ieee80211_local *local; | |
1509 | struct ieee80211_hdr *hdr; | |
1510 | struct sk_buff *skb; | |
1511 | ||
1512 | local = rx->local; | |
1513 | skb = rx->skb; | |
1514 | hdr = (struct ieee80211_hdr *) skb->data; | |
1515 | ||
1516 | if (!local->pspolling) | |
1517 | return RX_CONTINUE; | |
1518 | ||
1519 | if (!ieee80211_has_fromds(hdr->frame_control)) | |
1520 | /* this is not from AP */ | |
1521 | return RX_CONTINUE; | |
1522 | ||
1523 | if (!ieee80211_is_data(hdr->frame_control)) | |
1524 | return RX_CONTINUE; | |
1525 | ||
1526 | if (!ieee80211_has_moredata(hdr->frame_control)) { | |
1527 | /* AP has no more frames buffered for us */ | |
1528 | local->pspolling = false; | |
1529 | return RX_CONTINUE; | |
1530 | } | |
1531 | ||
1532 | /* more data bit is set, let's request a new frame from the AP */ | |
1533 | ieee80211_send_pspoll(local, rx->sdata); | |
1534 | ||
1535 | return RX_CONTINUE; | |
1536 | } | |
1537 | ||
d012a605 | 1538 | static void sta_ps_start(struct sta_info *sta) |
571ecf67 | 1539 | { |
133b8226 | 1540 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
4571d3bf | 1541 | struct ieee80211_local *local = sdata->local; |
d012a605 | 1542 | struct ps_data *ps; |
ba8c3d6f | 1543 | int tid; |
0795af57 | 1544 | |
d012a605 MP |
1545 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP || |
1546 | sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
1547 | ps = &sdata->bss->ps; | |
1548 | else | |
1549 | return; | |
1550 | ||
1551 | atomic_inc(&ps->num_sta_ps); | |
c2c98fde | 1552 | set_sta_flag(sta, WLAN_STA_PS_STA); |
30686bf7 | 1553 | if (!ieee80211_hw_check(&local->hw, AP_LINK_PS)) |
d057e5a3 | 1554 | drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta); |
bdcbd8e0 JB |
1555 | ps_dbg(sdata, "STA %pM aid %d enters power save mode\n", |
1556 | sta->sta.addr, sta->sta.aid); | |
ba8c3d6f | 1557 | |
17c18bf8 JB |
1558 | ieee80211_clear_fast_xmit(sta); |
1559 | ||
ba8c3d6f FF |
1560 | if (!sta->sta.txq[0]) |
1561 | return; | |
1562 | ||
adf8ed01 | 1563 | for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) { |
b49c15e1 FF |
1564 | struct ieee80211_txq *txq = sta->sta.txq[tid]; |
1565 | struct txq_info *txqi = to_txq_info(txq); | |
1566 | ||
1567 | spin_lock(&local->active_txq_lock[txq->ac]); | |
1568 | if (!list_empty(&txqi->schedule_order)) | |
1569 | list_del_init(&txqi->schedule_order); | |
1570 | spin_unlock(&local->active_txq_lock[txq->ac]); | |
1571 | ||
1572 | if (txq_has_queue(txq)) | |
ba8c3d6f FF |
1573 | set_bit(tid, &sta->txq_buffered_tids); |
1574 | else | |
1575 | clear_bit(tid, &sta->txq_buffered_tids); | |
1576 | } | |
571ecf67 JB |
1577 | } |
1578 | ||
d012a605 | 1579 | static void sta_ps_end(struct sta_info *sta) |
571ecf67 | 1580 | { |
bdcbd8e0 JB |
1581 | ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n", |
1582 | sta->sta.addr, sta->sta.aid); | |
004c872e | 1583 | |
c2c98fde | 1584 | if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) { |
e3685e03 JB |
1585 | /* |
1586 | * Clear the flag only if the other one is still set | |
1587 | * so that the TX path won't start TX'ing new frames | |
1588 | * directly ... In the case that the driver flag isn't | |
1589 | * set ieee80211_sta_ps_deliver_wakeup() will clear it. | |
1590 | */ | |
1591 | clear_sta_flag(sta, WLAN_STA_PS_STA); | |
bdcbd8e0 JB |
1592 | ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n", |
1593 | sta->sta.addr, sta->sta.aid); | |
af818581 JB |
1594 | return; |
1595 | } | |
1596 | ||
5ac2e350 JB |
1597 | set_sta_flag(sta, WLAN_STA_PS_DELIVER); |
1598 | clear_sta_flag(sta, WLAN_STA_PS_STA); | |
af818581 | 1599 | ieee80211_sta_ps_deliver_wakeup(sta); |
571ecf67 JB |
1600 | } |
1601 | ||
cf47161a | 1602 | int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start) |
d057e5a3 | 1603 | { |
cf47161a | 1604 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
d057e5a3 AN |
1605 | bool in_ps; |
1606 | ||
cf47161a | 1607 | WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS)); |
d057e5a3 AN |
1608 | |
1609 | /* Don't let the same PS state be set twice */ | |
cf47161a | 1610 | in_ps = test_sta_flag(sta, WLAN_STA_PS_STA); |
d057e5a3 AN |
1611 | if ((start && in_ps) || (!start && !in_ps)) |
1612 | return -EINVAL; | |
1613 | ||
1614 | if (start) | |
cf47161a | 1615 | sta_ps_start(sta); |
d057e5a3 | 1616 | else |
cf47161a | 1617 | sta_ps_end(sta); |
d057e5a3 AN |
1618 | |
1619 | return 0; | |
1620 | } | |
1621 | EXPORT_SYMBOL(ieee80211_sta_ps_transition); | |
1622 | ||
46fa38e8 JB |
1623 | void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta) |
1624 | { | |
1625 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); | |
1626 | ||
1627 | if (test_sta_flag(sta, WLAN_STA_SP)) | |
1628 | return; | |
1629 | ||
1630 | if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER)) | |
1631 | ieee80211_sta_ps_deliver_poll_response(sta); | |
1632 | else | |
1633 | set_sta_flag(sta, WLAN_STA_PSPOLL); | |
1634 | } | |
1635 | EXPORT_SYMBOL(ieee80211_sta_pspoll); | |
1636 | ||
1637 | void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid) | |
1638 | { | |
1639 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); | |
731977e9 | 1640 | int ac = ieee80211_ac_from_tid(tid); |
46fa38e8 JB |
1641 | |
1642 | /* | |
0aa419ec EG |
1643 | * If this AC is not trigger-enabled do nothing unless the |
1644 | * driver is calling us after it already checked. | |
46fa38e8 JB |
1645 | * |
1646 | * NB: This could/should check a separate bitmap of trigger- | |
1647 | * enabled queues, but for now we only implement uAPSD w/o | |
1648 | * TSPEC changes to the ACs, so they're always the same. | |
1649 | */ | |
f438ceb8 EG |
1650 | if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) && |
1651 | tid != IEEE80211_NUM_TIDS) | |
46fa38e8 JB |
1652 | return; |
1653 | ||
1654 | /* if we are in a service period, do nothing */ | |
1655 | if (test_sta_flag(sta, WLAN_STA_SP)) | |
1656 | return; | |
1657 | ||
1658 | if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER)) | |
1659 | ieee80211_sta_ps_deliver_uapsd(sta); | |
1660 | else | |
1661 | set_sta_flag(sta, WLAN_STA_UAPSD); | |
1662 | } | |
1663 | EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger); | |
1664 | ||
47086fc5 JB |
1665 | static ieee80211_rx_result debug_noinline |
1666 | ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx) | |
1667 | { | |
1668 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
1669 | struct ieee80211_hdr *hdr = (void *)rx->skb->data; | |
1670 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | |
47086fc5 | 1671 | |
5c90067c | 1672 | if (!rx->sta) |
47086fc5 JB |
1673 | return RX_CONTINUE; |
1674 | ||
1675 | if (sdata->vif.type != NL80211_IFTYPE_AP && | |
1676 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN) | |
1677 | return RX_CONTINUE; | |
1678 | ||
1679 | /* | |
1680 | * The device handles station powersave, so don't do anything about | |
1681 | * uAPSD and PS-Poll frames (the latter shouldn't even come up from | |
1682 | * it to mac80211 since they're handled.) | |
1683 | */ | |
30686bf7 | 1684 | if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS)) |
47086fc5 JB |
1685 | return RX_CONTINUE; |
1686 | ||
1687 | /* | |
1688 | * Don't do anything if the station isn't already asleep. In | |
1689 | * the uAPSD case, the station will probably be marked asleep, | |
1690 | * in the PS-Poll case the station must be confused ... | |
1691 | */ | |
c2c98fde | 1692 | if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA)) |
47086fc5 JB |
1693 | return RX_CONTINUE; |
1694 | ||
1695 | if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) { | |
46fa38e8 | 1696 | ieee80211_sta_pspoll(&rx->sta->sta); |
47086fc5 JB |
1697 | |
1698 | /* Free PS Poll skb here instead of returning RX_DROP that would | |
1699 | * count as an dropped frame. */ | |
1700 | dev_kfree_skb(rx->skb); | |
1701 | ||
1702 | return RX_QUEUED; | |
1703 | } else if (!ieee80211_has_morefrags(hdr->frame_control) && | |
1704 | !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) && | |
1705 | ieee80211_has_pm(hdr->frame_control) && | |
1706 | (ieee80211_is_data_qos(hdr->frame_control) || | |
1707 | ieee80211_is_qos_nullfunc(hdr->frame_control))) { | |
a1f2ba04 | 1708 | u8 tid = ieee80211_get_tid(hdr); |
47086fc5 | 1709 | |
46fa38e8 | 1710 | ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid); |
47086fc5 JB |
1711 | } |
1712 | ||
1713 | return RX_CONTINUE; | |
1714 | } | |
1715 | ||
49461622 | 1716 | static ieee80211_rx_result debug_noinline |
5cf121c3 | 1717 | ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx) |
571ecf67 JB |
1718 | { |
1719 | struct sta_info *sta = rx->sta; | |
eb9fb5b8 JB |
1720 | struct sk_buff *skb = rx->skb; |
1721 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | |
1722 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
ef0621e8 | 1723 | int i; |
571ecf67 JB |
1724 | |
1725 | if (!sta) | |
9ae54c84 | 1726 | return RX_CONTINUE; |
571ecf67 | 1727 | |
b291ba11 JB |
1728 | /* |
1729 | * Update last_rx only for IBSS packets which are for the current | |
e584da5e AQ |
1730 | * BSSID and for station already AUTHORIZED to avoid keeping the |
1731 | * current IBSS network alive in cases where other STAs start | |
1732 | * using different BSSID. This will also give the station another | |
1733 | * chance to restart the authentication/authorization in case | |
1734 | * something went wrong the first time. | |
b291ba11 | 1735 | */ |
05c914fe | 1736 | if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
71364716 | 1737 | u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, |
05c914fe | 1738 | NL80211_IFTYPE_ADHOC); |
e584da5e AQ |
1739 | if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) && |
1740 | test_sta_flag(sta, WLAN_STA_AUTHORIZED)) { | |
e5a9f8d0 | 1741 | sta->rx_stats.last_rx = jiffies; |
f4ebddf9 | 1742 | if (ieee80211_is_data(hdr->frame_control) && |
4f6b1b3d JB |
1743 | !is_multicast_ether_addr(hdr->addr1)) |
1744 | sta->rx_stats.last_rate = | |
1745 | sta_stats_encode_rate(status); | |
3af6334c | 1746 | } |
239281f8 | 1747 | } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) { |
e5a9f8d0 | 1748 | sta->rx_stats.last_rx = jiffies; |
09a740ce | 1749 | } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) && |
f879ac8e | 1750 | !is_multicast_ether_addr(hdr->addr1)) { |
b291ba11 | 1751 | /* |
33b64eb2 LCC |
1752 | * Mesh beacons will update last_rx when if they are found to |
1753 | * match the current local configuration when processed. | |
571ecf67 | 1754 | */ |
e5a9f8d0 | 1755 | sta->rx_stats.last_rx = jiffies; |
4f6b1b3d JB |
1756 | if (ieee80211_is_data(hdr->frame_control)) |
1757 | sta->rx_stats.last_rate = sta_stats_encode_rate(status); | |
571ecf67 JB |
1758 | } |
1759 | ||
e5a9f8d0 | 1760 | sta->rx_stats.fragments++; |
0f9c5a61 JB |
1761 | |
1762 | u64_stats_update_begin(&rx->sta->rx_stats.syncp); | |
e5a9f8d0 | 1763 | sta->rx_stats.bytes += rx->skb->len; |
0f9c5a61 JB |
1764 | u64_stats_update_end(&rx->sta->rx_stats.syncp); |
1765 | ||
fe8431f8 | 1766 | if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { |
e5a9f8d0 | 1767 | sta->rx_stats.last_signal = status->signal; |
0be6ed13 | 1768 | ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal); |
fe8431f8 | 1769 | } |
571ecf67 | 1770 | |
ef0621e8 | 1771 | if (status->chains) { |
e5a9f8d0 | 1772 | sta->rx_stats.chains = status->chains; |
ef0621e8 FF |
1773 | for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) { |
1774 | int signal = status->chain_signal[i]; | |
1775 | ||
1776 | if (!(status->chains & BIT(i))) | |
1777 | continue; | |
1778 | ||
e5a9f8d0 | 1779 | sta->rx_stats.chain_signal_last[i] = signal; |
0be6ed13 | 1780 | ewma_signal_add(&sta->rx_stats_avg.chain_signal[i], |
e5a9f8d0 | 1781 | -signal); |
ef0621e8 FF |
1782 | } |
1783 | } | |
1784 | ||
09a740ce TP |
1785 | if (ieee80211_is_s1g_beacon(hdr->frame_control)) |
1786 | return RX_CONTINUE; | |
1787 | ||
72eaa43a JB |
1788 | /* |
1789 | * Change STA power saving mode only at the end of a frame | |
9fef6544 EG |
1790 | * exchange sequence, and only for a data or management |
1791 | * frame as specified in IEEE 802.11-2016 11.2.3.2 | |
72eaa43a | 1792 | */ |
30686bf7 | 1793 | if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) && |
d057e5a3 | 1794 | !ieee80211_has_morefrags(hdr->frame_control) && |
20932750 | 1795 | !is_multicast_ether_addr(hdr->addr1) && |
9fef6544 EG |
1796 | (ieee80211_is_mgmt(hdr->frame_control) || |
1797 | ieee80211_is_data(hdr->frame_control)) && | |
4cfda47b | 1798 | !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) && |
05c914fe | 1799 | (rx->sdata->vif.type == NL80211_IFTYPE_AP || |
9fef6544 | 1800 | rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) { |
c2c98fde | 1801 | if (test_sta_flag(sta, WLAN_STA_PS_STA)) { |
b4ba544c | 1802 | if (!ieee80211_has_pm(hdr->frame_control)) |
d012a605 | 1803 | sta_ps_end(sta); |
72eaa43a JB |
1804 | } else { |
1805 | if (ieee80211_has_pm(hdr->frame_control)) | |
d012a605 | 1806 | sta_ps_start(sta); |
72eaa43a | 1807 | } |
571ecf67 JB |
1808 | } |
1809 | ||
3f52b7e3 MP |
1810 | /* mesh power save support */ |
1811 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) | |
1812 | ieee80211_mps_rx_h_sta_process(sta, hdr); | |
1813 | ||
22403def JB |
1814 | /* |
1815 | * Drop (qos-)data::nullfunc frames silently, since they | |
1816 | * are used only to control station power saving mode. | |
1817 | */ | |
30b2f0be | 1818 | if (ieee80211_is_any_nullfunc(hdr->frame_control)) { |
571ecf67 | 1819 | I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); |
d524215f FF |
1820 | |
1821 | /* | |
1822 | * If we receive a 4-addr nullfunc frame from a STA | |
e7f4a940 JB |
1823 | * that was not moved to a 4-addr STA vlan yet send |
1824 | * the event to userspace and for older hostapd drop | |
1825 | * the frame to the monitor interface. | |
d524215f FF |
1826 | */ |
1827 | if (ieee80211_has_a4(hdr->frame_control) && | |
1828 | (rx->sdata->vif.type == NL80211_IFTYPE_AP || | |
1829 | (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | |
e7f4a940 JB |
1830 | !rx->sdata->u.vlan.sta))) { |
1831 | if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT)) | |
1832 | cfg80211_rx_unexpected_4addr_frame( | |
1833 | rx->sdata->dev, sta->sta.addr, | |
1834 | GFP_ATOMIC); | |
d524215f | 1835 | return RX_DROP_MONITOR; |
e7f4a940 | 1836 | } |
22403def JB |
1837 | /* |
1838 | * Update counter and free packet here to avoid | |
1839 | * counting this as a dropped packed. | |
1840 | */ | |
e5a9f8d0 | 1841 | sta->rx_stats.packets++; |
571ecf67 | 1842 | dev_kfree_skb(rx->skb); |
9ae54c84 | 1843 | return RX_QUEUED; |
571ecf67 JB |
1844 | } |
1845 | ||
9ae54c84 | 1846 | return RX_CONTINUE; |
571ecf67 JB |
1847 | } /* ieee80211_rx_h_sta_process */ |
1848 | ||
af2d14b0 JM |
1849 | static struct ieee80211_key * |
1850 | ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx) | |
1851 | { | |
1852 | struct ieee80211_key *key = NULL; | |
1853 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
1854 | int idx2; | |
1855 | ||
1856 | /* Make sure key gets set if either BIGTK key index is set so that | |
1857 | * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected | |
1858 | * Beacon frames and Beacon frames that claim to use another BIGTK key | |
1859 | * index (i.e., a key that we do not have). | |
1860 | */ | |
1861 | ||
1862 | if (idx < 0) { | |
1863 | idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS; | |
1864 | idx2 = idx + 1; | |
1865 | } else { | |
1866 | if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) | |
1867 | idx2 = idx + 1; | |
1868 | else | |
1869 | idx2 = idx - 1; | |
1870 | } | |
1871 | ||
1872 | if (rx->sta) | |
1873 | key = rcu_dereference(rx->sta->gtk[idx]); | |
1874 | if (!key) | |
1875 | key = rcu_dereference(sdata->keys[idx]); | |
1876 | if (!key && rx->sta) | |
1877 | key = rcu_dereference(rx->sta->gtk[idx2]); | |
1878 | if (!key) | |
1879 | key = rcu_dereference(sdata->keys[idx2]); | |
1880 | ||
1881 | return key; | |
1882 | } | |
1883 | ||
86c228a7 JA |
1884 | static ieee80211_rx_result debug_noinline |
1885 | ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx) | |
1886 | { | |
1887 | struct sk_buff *skb = rx->skb; | |
1888 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | |
1889 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
1890 | int keyidx; | |
86c228a7 JA |
1891 | ieee80211_rx_result result = RX_DROP_UNUSABLE; |
1892 | struct ieee80211_key *sta_ptk = NULL; | |
96fc6efb | 1893 | struct ieee80211_key *ptk_idx = NULL; |
86c228a7 JA |
1894 | int mmie_keyidx = -1; |
1895 | __le16 fc; | |
2475b1cc | 1896 | const struct ieee80211_cipher_scheme *cs = NULL; |
86c228a7 | 1897 | |
09a740ce TP |
1898 | if (ieee80211_is_ext(hdr->frame_control)) |
1899 | return RX_CONTINUE; | |
1900 | ||
86c228a7 JA |
1901 | /* |
1902 | * Key selection 101 | |
1903 | * | |
af2d14b0 | 1904 | * There are five types of keys: |
86c228a7 JA |
1905 | * - GTK (group keys) |
1906 | * - IGTK (group keys for management frames) | |
af2d14b0 | 1907 | * - BIGTK (group keys for Beacon frames) |
86c228a7 JA |
1908 | * - PTK (pairwise keys) |
1909 | * - STK (station-to-station pairwise keys) | |
1910 | * | |
1911 | * When selecting a key, we have to distinguish between multicast | |
1912 | * (including broadcast) and unicast frames, the latter can only | |
af2d14b0 JM |
1913 | * use PTKs and STKs while the former always use GTKs, IGTKs, and |
1914 | * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used, | |
1915 | * then unicast frames can also use key indices like GTKs. Hence, if we | |
86c228a7 JA |
1916 | * don't have a PTK/STK we check the key index for a WEP key. |
1917 | * | |
1918 | * Note that in a regular BSS, multicast frames are sent by the | |
1919 | * AP only, associated stations unicast the frame to the AP first | |
1920 | * which then multicasts it on their behalf. | |
1921 | * | |
1922 | * There is also a slight problem in IBSS mode: GTKs are negotiated | |
1923 | * with each station, that is something we don't currently handle. | |
1924 | * The spec seems to expect that one negotiates the same key with | |
1925 | * every station but there's no such requirement; VLANs could be | |
1926 | * possible. | |
1927 | */ | |
1928 | ||
86c228a7 JA |
1929 | /* start without a key */ |
1930 | rx->key = NULL; | |
2475b1cc | 1931 | fc = hdr->frame_control; |
86c228a7 | 1932 | |
2475b1cc MS |
1933 | if (rx->sta) { |
1934 | int keyid = rx->sta->ptk_idx; | |
96fc6efb | 1935 | sta_ptk = rcu_dereference(rx->sta->ptk[keyid]); |
86c228a7 | 1936 | |
96fc6efb | 1937 | if (ieee80211_has_protected(fc)) { |
2475b1cc | 1938 | cs = rx->sta->cipher_scheme; |
96fc6efb AW |
1939 | keyid = ieee80211_get_keyid(rx->skb, cs); |
1940 | ||
2475b1cc MS |
1941 | if (unlikely(keyid < 0)) |
1942 | return RX_DROP_UNUSABLE; | |
96fc6efb AW |
1943 | |
1944 | ptk_idx = rcu_dereference(rx->sta->ptk[keyid]); | |
2475b1cc | 1945 | } |
2475b1cc | 1946 | } |
86c228a7 JA |
1947 | |
1948 | if (!ieee80211_has_protected(fc)) | |
1949 | mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb); | |
1950 | ||
1951 | if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) { | |
96fc6efb | 1952 | rx->key = ptk_idx ? ptk_idx : sta_ptk; |
86c228a7 JA |
1953 | if ((status->flag & RX_FLAG_DECRYPTED) && |
1954 | (status->flag & RX_FLAG_IV_STRIPPED)) | |
1955 | return RX_CONTINUE; | |
1956 | /* Skip decryption if the frame is not protected. */ | |
1957 | if (!ieee80211_has_protected(fc)) | |
1958 | return RX_CONTINUE; | |
af2d14b0 JM |
1959 | } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) { |
1960 | /* Broadcast/multicast robust management frame / BIP */ | |
1961 | if ((status->flag & RX_FLAG_DECRYPTED) && | |
1962 | (status->flag & RX_FLAG_IV_STRIPPED)) | |
1963 | return RX_CONTINUE; | |
1964 | ||
1965 | if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS || | |
1966 | mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS + | |
9eaf183a JM |
1967 | NUM_DEFAULT_BEACON_KEYS) { |
1968 | cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, | |
1969 | skb->data, | |
1970 | skb->len); | |
af2d14b0 | 1971 | return RX_DROP_MONITOR; /* unexpected BIP keyidx */ |
9eaf183a | 1972 | } |
af2d14b0 JM |
1973 | |
1974 | rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx); | |
1975 | if (!rx->key) | |
1976 | return RX_CONTINUE; /* Beacon protection not in use */ | |
86c228a7 JA |
1977 | } else if (mmie_keyidx >= 0) { |
1978 | /* Broadcast/multicast robust management frame / BIP */ | |
1979 | if ((status->flag & RX_FLAG_DECRYPTED) && | |
1980 | (status->flag & RX_FLAG_IV_STRIPPED)) | |
1981 | return RX_CONTINUE; | |
1982 | ||
1983 | if (mmie_keyidx < NUM_DEFAULT_KEYS || | |
1984 | mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) | |
1985 | return RX_DROP_MONITOR; /* unexpected BIP keyidx */ | |
46f6b060 MH |
1986 | if (rx->sta) { |
1987 | if (ieee80211_is_group_privacy_action(skb) && | |
1988 | test_sta_flag(rx->sta, WLAN_STA_MFP)) | |
1989 | return RX_DROP_MONITOR; | |
1990 | ||
86c228a7 | 1991 | rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]); |
46f6b060 | 1992 | } |
86c228a7 JA |
1993 | if (!rx->key) |
1994 | rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]); | |
1995 | } else if (!ieee80211_has_protected(fc)) { | |
1996 | /* | |
1997 | * The frame was not protected, so skip decryption. However, we | |
1998 | * need to set rx->key if there is a key that could have been | |
1999 | * used so that the frame may be dropped if encryption would | |
2000 | * have been expected. | |
2001 | */ | |
2002 | struct ieee80211_key *key = NULL; | |
2003 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
2004 | int i; | |
2005 | ||
af2d14b0 JM |
2006 | if (ieee80211_is_beacon(fc)) { |
2007 | key = ieee80211_rx_get_bigtk(rx, -1); | |
2008 | } else if (ieee80211_is_mgmt(fc) && | |
2009 | is_multicast_ether_addr(hdr->addr1)) { | |
2010 | key = rcu_dereference(rx->sdata->default_mgmt_key); | |
2011 | } else { | |
86c228a7 JA |
2012 | if (rx->sta) { |
2013 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
2014 | key = rcu_dereference(rx->sta->gtk[i]); | |
2015 | if (key) | |
2016 | break; | |
2017 | } | |
2018 | } | |
2019 | if (!key) { | |
2020 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
2021 | key = rcu_dereference(sdata->keys[i]); | |
2022 | if (key) | |
2023 | break; | |
2024 | } | |
2025 | } | |
86c228a7 | 2026 | } |
af2d14b0 JM |
2027 | if (key) |
2028 | rx->key = key; | |
86c228a7 JA |
2029 | return RX_CONTINUE; |
2030 | } else { | |
86c228a7 JA |
2031 | /* |
2032 | * The device doesn't give us the IV so we won't be | |
2033 | * able to look up the key. That's ok though, we | |
2034 | * don't need to decrypt the frame, we just won't | |
2035 | * be able to keep statistics accurate. | |
2036 | * Except for key threshold notifications, should | |
2037 | * we somehow allow the driver to tell us which key | |
2038 | * the hardware used if this flag is set? | |
2039 | */ | |
2040 | if ((status->flag & RX_FLAG_DECRYPTED) && | |
2041 | (status->flag & RX_FLAG_IV_STRIPPED)) | |
2042 | return RX_CONTINUE; | |
2043 | ||
96fc6efb | 2044 | keyidx = ieee80211_get_keyid(rx->skb, cs); |
86c228a7 | 2045 | |
96fc6efb AW |
2046 | if (unlikely(keyidx < 0)) |
2047 | return RX_DROP_UNUSABLE; | |
86c228a7 JA |
2048 | |
2049 | /* check per-station GTK first, if multicast packet */ | |
2050 | if (is_multicast_ether_addr(hdr->addr1) && rx->sta) | |
2051 | rx->key = rcu_dereference(rx->sta->gtk[keyidx]); | |
2052 | ||
2053 | /* if not found, try default key */ | |
2054 | if (!rx->key) { | |
2055 | rx->key = rcu_dereference(rx->sdata->keys[keyidx]); | |
2056 | ||
2057 | /* | |
2058 | * RSNA-protected unicast frames should always be | |
2059 | * sent with pairwise or station-to-station keys, | |
2060 | * but for WEP we allow using a key index as well. | |
2061 | */ | |
2062 | if (rx->key && | |
2063 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 && | |
2064 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 && | |
2065 | !is_multicast_ether_addr(hdr->addr1)) | |
2066 | rx->key = NULL; | |
2067 | } | |
2068 | } | |
2069 | ||
2070 | if (rx->key) { | |
2071 | if (unlikely(rx->key->flags & KEY_FLAG_TAINTED)) | |
2072 | return RX_DROP_MONITOR; | |
2073 | ||
86c228a7 JA |
2074 | /* TODO: add threshold stuff again */ |
2075 | } else { | |
2076 | return RX_DROP_MONITOR; | |
2077 | } | |
2078 | ||
2079 | switch (rx->key->conf.cipher) { | |
2080 | case WLAN_CIPHER_SUITE_WEP40: | |
2081 | case WLAN_CIPHER_SUITE_WEP104: | |
2082 | result = ieee80211_crypto_wep_decrypt(rx); | |
2083 | break; | |
2084 | case WLAN_CIPHER_SUITE_TKIP: | |
2085 | result = ieee80211_crypto_tkip_decrypt(rx); | |
2086 | break; | |
2087 | case WLAN_CIPHER_SUITE_CCMP: | |
2b2ba0db JM |
2088 | result = ieee80211_crypto_ccmp_decrypt( |
2089 | rx, IEEE80211_CCMP_MIC_LEN); | |
2090 | break; | |
2091 | case WLAN_CIPHER_SUITE_CCMP_256: | |
2092 | result = ieee80211_crypto_ccmp_decrypt( | |
2093 | rx, IEEE80211_CCMP_256_MIC_LEN); | |
86c228a7 JA |
2094 | break; |
2095 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
2096 | result = ieee80211_crypto_aes_cmac_decrypt(rx); | |
2097 | break; | |
56c52da2 JM |
2098 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
2099 | result = ieee80211_crypto_aes_cmac_256_decrypt(rx); | |
2100 | break; | |
8ade538b JM |
2101 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
2102 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
2103 | result = ieee80211_crypto_aes_gmac_decrypt(rx); | |
2104 | break; | |
00b9cfa3 JM |
2105 | case WLAN_CIPHER_SUITE_GCMP: |
2106 | case WLAN_CIPHER_SUITE_GCMP_256: | |
2107 | result = ieee80211_crypto_gcmp_decrypt(rx); | |
2108 | break; | |
86c228a7 | 2109 | default: |
2475b1cc | 2110 | result = ieee80211_crypto_hw_decrypt(rx); |
86c228a7 JA |
2111 | } |
2112 | ||
2113 | /* the hdr variable is invalid after the decrypt handlers */ | |
2114 | ||
2115 | /* either the frame has been decrypted or will be dropped */ | |
2116 | status->flag |= RX_FLAG_DECRYPTED; | |
2117 | ||
9eaf183a JM |
2118 | if (unlikely(ieee80211_is_beacon(fc) && result == RX_DROP_UNUSABLE)) |
2119 | cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, | |
2120 | skb->data, skb->len); | |
2121 | ||
86c228a7 JA |
2122 | return result; |
2123 | } | |
2124 | ||
571ecf67 JB |
2125 | static inline struct ieee80211_fragment_entry * |
2126 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, | |
2127 | unsigned int frag, unsigned int seq, int rx_queue, | |
2128 | struct sk_buff **skb) | |
2129 | { | |
2130 | struct ieee80211_fragment_entry *entry; | |
571ecf67 | 2131 | |
571ecf67 JB |
2132 | entry = &sdata->fragments[sdata->fragment_next++]; |
2133 | if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) | |
2134 | sdata->fragment_next = 0; | |
2135 | ||
bdcbd8e0 | 2136 | if (!skb_queue_empty(&entry->skb_list)) |
571ecf67 | 2137 | __skb_queue_purge(&entry->skb_list); |
571ecf67 JB |
2138 | |
2139 | __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ | |
2140 | *skb = NULL; | |
2141 | entry->first_frag_time = jiffies; | |
2142 | entry->seq = seq; | |
2143 | entry->rx_queue = rx_queue; | |
2144 | entry->last_frag = frag; | |
9acc54be | 2145 | entry->check_sequential_pn = false; |
571ecf67 JB |
2146 | entry->extra_len = 0; |
2147 | ||
2148 | return entry; | |
2149 | } | |
2150 | ||
2151 | static inline struct ieee80211_fragment_entry * | |
2152 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, | |
b73d70ad | 2153 | unsigned int frag, unsigned int seq, |
571ecf67 JB |
2154 | int rx_queue, struct ieee80211_hdr *hdr) |
2155 | { | |
2156 | struct ieee80211_fragment_entry *entry; | |
2157 | int i, idx; | |
2158 | ||
2159 | idx = sdata->fragment_next; | |
2160 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { | |
2161 | struct ieee80211_hdr *f_hdr; | |
7957a9de | 2162 | struct sk_buff *f_skb; |
571ecf67 JB |
2163 | |
2164 | idx--; | |
2165 | if (idx < 0) | |
2166 | idx = IEEE80211_FRAGMENT_MAX - 1; | |
2167 | ||
2168 | entry = &sdata->fragments[idx]; | |
2169 | if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || | |
2170 | entry->rx_queue != rx_queue || | |
2171 | entry->last_frag + 1 != frag) | |
2172 | continue; | |
2173 | ||
7957a9de DM |
2174 | f_skb = __skb_peek(&entry->skb_list); |
2175 | f_hdr = (struct ieee80211_hdr *) f_skb->data; | |
571ecf67 | 2176 | |
b73d70ad HH |
2177 | /* |
2178 | * Check ftype and addresses are equal, else check next fragment | |
2179 | */ | |
2180 | if (((hdr->frame_control ^ f_hdr->frame_control) & | |
2181 | cpu_to_le16(IEEE80211_FCTL_FTYPE)) || | |
b203ca39 JP |
2182 | !ether_addr_equal(hdr->addr1, f_hdr->addr1) || |
2183 | !ether_addr_equal(hdr->addr2, f_hdr->addr2)) | |
571ecf67 JB |
2184 | continue; |
2185 | ||
ab46623e | 2186 | if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
571ecf67 JB |
2187 | __skb_queue_purge(&entry->skb_list); |
2188 | continue; | |
2189 | } | |
2190 | return entry; | |
2191 | } | |
2192 | ||
2193 | return NULL; | |
2194 | } | |
2195 | ||
49461622 | 2196 | static ieee80211_rx_result debug_noinline |
5cf121c3 | 2197 | ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx) |
571ecf67 JB |
2198 | { |
2199 | struct ieee80211_hdr *hdr; | |
2200 | u16 sc; | |
358c8d9d | 2201 | __le16 fc; |
571ecf67 JB |
2202 | unsigned int frag, seq; |
2203 | struct ieee80211_fragment_entry *entry; | |
2204 | struct sk_buff *skb; | |
2205 | ||
b73d70ad | 2206 | hdr = (struct ieee80211_hdr *)rx->skb->data; |
358c8d9d | 2207 | fc = hdr->frame_control; |
f7fbf70e | 2208 | |
09a740ce | 2209 | if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc)) |
f7fbf70e JC |
2210 | return RX_CONTINUE; |
2211 | ||
571ecf67 JB |
2212 | sc = le16_to_cpu(hdr->seq_ctrl); |
2213 | frag = sc & IEEE80211_SCTL_FRAG; | |
2214 | ||
b8fff407 | 2215 | if (is_multicast_ether_addr(hdr->addr1)) { |
c206ca67 | 2216 | I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount); |
d025933e | 2217 | goto out_no_led; |
571ecf67 | 2218 | } |
b8fff407 | 2219 | |
d025933e AM |
2220 | if (likely(!ieee80211_has_morefrags(fc) && frag == 0)) |
2221 | goto out; | |
2222 | ||
571ecf67 JB |
2223 | I802_DEBUG_INC(rx->local->rx_handlers_fragments); |
2224 | ||
e3cf8b3f ZY |
2225 | if (skb_linearize(rx->skb)) |
2226 | return RX_DROP_UNUSABLE; | |
2227 | ||
058897a4 AK |
2228 | /* |
2229 | * skb_linearize() might change the skb->data and | |
2230 | * previously cached variables (in this case, hdr) need to | |
2231 | * be refreshed with the new data. | |
2232 | */ | |
2233 | hdr = (struct ieee80211_hdr *)rx->skb->data; | |
571ecf67 JB |
2234 | seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
2235 | ||
2236 | if (frag == 0) { | |
2237 | /* This is the first fragment of a new frame. */ | |
2238 | entry = ieee80211_reassemble_add(rx->sdata, frag, seq, | |
9e26297a | 2239 | rx->seqno_idx, &(rx->skb)); |
2b2ba0db JM |
2240 | if (rx->key && |
2241 | (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP || | |
9acc54be JB |
2242 | rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 || |
2243 | rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP || | |
2244 | rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) && | |
358c8d9d | 2245 | ieee80211_has_protected(fc)) { |
9e26297a | 2246 | int queue = rx->security_idx; |
9acc54be JB |
2247 | |
2248 | /* Store CCMP/GCMP PN so that we can verify that the | |
2249 | * next fragment has a sequential PN value. | |
2250 | */ | |
2251 | entry->check_sequential_pn = true; | |
571ecf67 | 2252 | memcpy(entry->last_pn, |
9190252c | 2253 | rx->key->u.ccmp.rx_pn[queue], |
4325f6ca | 2254 | IEEE80211_CCMP_PN_LEN); |
9acc54be JB |
2255 | BUILD_BUG_ON(offsetof(struct ieee80211_key, |
2256 | u.ccmp.rx_pn) != | |
2257 | offsetof(struct ieee80211_key, | |
2258 | u.gcmp.rx_pn)); | |
2259 | BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) != | |
2260 | sizeof(rx->key->u.gcmp.rx_pn[queue])); | |
2261 | BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != | |
2262 | IEEE80211_GCMP_PN_LEN); | |
571ecf67 | 2263 | } |
9ae54c84 | 2264 | return RX_QUEUED; |
571ecf67 JB |
2265 | } |
2266 | ||
2267 | /* This is a fragment for a frame that should already be pending in | |
2268 | * fragment cache. Add this fragment to the end of the pending entry. | |
2269 | */ | |
9e26297a JB |
2270 | entry = ieee80211_reassemble_find(rx->sdata, frag, seq, |
2271 | rx->seqno_idx, hdr); | |
571ecf67 JB |
2272 | if (!entry) { |
2273 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | |
e4c26add | 2274 | return RX_DROP_MONITOR; |
571ecf67 JB |
2275 | } |
2276 | ||
9acc54be JB |
2277 | /* "The receiver shall discard MSDUs and MMPDUs whose constituent |
2278 | * MPDU PN values are not incrementing in steps of 1." | |
2279 | * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP) | |
2280 | * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP) | |
2281 | */ | |
2282 | if (entry->check_sequential_pn) { | |
571ecf67 | 2283 | int i; |
4325f6ca | 2284 | u8 pn[IEEE80211_CCMP_PN_LEN], *rpn; |
9190252c | 2285 | int queue; |
9acc54be | 2286 | |
2b2ba0db JM |
2287 | if (!rx->key || |
2288 | (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP && | |
9acc54be JB |
2289 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 && |
2290 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP && | |
2291 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256)) | |
e4c26add | 2292 | return RX_DROP_UNUSABLE; |
4325f6ca JB |
2293 | memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN); |
2294 | for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) { | |
571ecf67 JB |
2295 | pn[i]++; |
2296 | if (pn[i]) | |
2297 | break; | |
2298 | } | |
9e26297a | 2299 | queue = rx->security_idx; |
9190252c | 2300 | rpn = rx->key->u.ccmp.rx_pn[queue]; |
4325f6ca | 2301 | if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN)) |
e4c26add | 2302 | return RX_DROP_UNUSABLE; |
4325f6ca | 2303 | memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN); |
571ecf67 JB |
2304 | } |
2305 | ||
358c8d9d | 2306 | skb_pull(rx->skb, ieee80211_hdrlen(fc)); |
571ecf67 JB |
2307 | __skb_queue_tail(&entry->skb_list, rx->skb); |
2308 | entry->last_frag = frag; | |
2309 | entry->extra_len += rx->skb->len; | |
358c8d9d | 2310 | if (ieee80211_has_morefrags(fc)) { |
571ecf67 | 2311 | rx->skb = NULL; |
9ae54c84 | 2312 | return RX_QUEUED; |
571ecf67 JB |
2313 | } |
2314 | ||
2315 | rx->skb = __skb_dequeue(&entry->skb_list); | |
2316 | if (skb_tailroom(rx->skb) < entry->extra_len) { | |
f1160434 | 2317 | I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag); |
571ecf67 JB |
2318 | if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, |
2319 | GFP_ATOMIC))) { | |
2320 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | |
2321 | __skb_queue_purge(&entry->skb_list); | |
e4c26add | 2322 | return RX_DROP_UNUSABLE; |
571ecf67 JB |
2323 | } |
2324 | } | |
2325 | while ((skb = __skb_dequeue(&entry->skb_list))) { | |
59ae1d12 | 2326 | skb_put_data(rx->skb, skb->data, skb->len); |
571ecf67 JB |
2327 | dev_kfree_skb(skb); |
2328 | } | |
2329 | ||
571ecf67 | 2330 | out: |
d025933e AM |
2331 | ieee80211_led_rx(rx->local); |
2332 | out_no_led: | |
571ecf67 | 2333 | if (rx->sta) |
e5a9f8d0 | 2334 | rx->sta->rx_stats.packets++; |
9ae54c84 | 2335 | return RX_CONTINUE; |
571ecf67 JB |
2336 | } |
2337 | ||
1df332e8 | 2338 | static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx) |
571ecf67 | 2339 | { |
1df332e8 | 2340 | if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED))) |
76ee65bf | 2341 | return -EACCES; |
571ecf67 | 2342 | |
76ee65bf | 2343 | return 0; |
571ecf67 JB |
2344 | } |
2345 | ||
1df332e8 | 2346 | static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc) |
571ecf67 | 2347 | { |
0b467b63 | 2348 | struct ieee80211_hdr *hdr = (void *)rx->skb->data; |
eb9fb5b8 JB |
2349 | struct sk_buff *skb = rx->skb; |
2350 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | |
2351 | ||
3017b80b | 2352 | /* |
7848ba7d JB |
2353 | * Pass through unencrypted frames if the hardware has |
2354 | * decrypted them already. | |
3017b80b | 2355 | */ |
eb9fb5b8 | 2356 | if (status->flag & RX_FLAG_DECRYPTED) |
76ee65bf | 2357 | return 0; |
571ecf67 | 2358 | |
0b467b63 MT |
2359 | /* check mesh EAPOL frames first */ |
2360 | if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) && | |
2361 | ieee80211_is_data(fc))) { | |
2362 | struct ieee80211s_hdr *mesh_hdr; | |
2363 | u16 hdr_len = ieee80211_hdrlen(fc); | |
2364 | u16 ethertype_offset; | |
2365 | __be16 ethertype; | |
2366 | ||
2367 | if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr)) | |
2368 | goto drop_check; | |
2369 | ||
2370 | /* make sure fixed part of mesh header is there, also checks skb len */ | |
2371 | if (!pskb_may_pull(rx->skb, hdr_len + 6)) | |
2372 | goto drop_check; | |
2373 | ||
2374 | mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len); | |
2375 | ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) + | |
2376 | sizeof(rfc1042_header); | |
2377 | ||
2378 | if (skb_copy_bits(rx->skb, ethertype_offset, ðertype, 2) == 0 && | |
2379 | ethertype == rx->sdata->control_port_protocol) | |
2380 | return 0; | |
2381 | } | |
2382 | ||
2383 | drop_check: | |
571ecf67 | 2384 | /* Drop unencrypted frames if key is set. */ |
358c8d9d | 2385 | if (unlikely(!ieee80211_has_protected(fc) && |
30b2f0be | 2386 | !ieee80211_is_any_nullfunc(fc) && |
e8f4fb7c | 2387 | ieee80211_is_data(fc) && rx->key)) |
76ee65bf | 2388 | return -EACCES; |
bef5d1c7 JB |
2389 | |
2390 | return 0; | |
2391 | } | |
2392 | ||
1df332e8 | 2393 | static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx) |
bef5d1c7 JB |
2394 | { |
2395 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | |
e3efca0a | 2396 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
bef5d1c7 | 2397 | __le16 fc = hdr->frame_control; |
bef5d1c7 | 2398 | |
e3efca0a JM |
2399 | /* |
2400 | * Pass through unencrypted frames if the hardware has | |
2401 | * decrypted them already. | |
2402 | */ | |
2403 | if (status->flag & RX_FLAG_DECRYPTED) | |
2404 | return 0; | |
bef5d1c7 | 2405 | |
c2c98fde | 2406 | if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) { |
d211e90e JM |
2407 | if (unlikely(!ieee80211_has_protected(fc) && |
2408 | ieee80211_is_unicast_robust_mgmt_frame(rx->skb) && | |
cf4e594e | 2409 | rx->key)) { |
6ff57cf8 JB |
2410 | if (ieee80211_is_deauth(fc) || |
2411 | ieee80211_is_disassoc(fc)) | |
2412 | cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, | |
2413 | rx->skb->data, | |
2414 | rx->skb->len); | |
f2ca3ea4 | 2415 | return -EACCES; |
cf4e594e | 2416 | } |
f2ca3ea4 | 2417 | /* BIP does not use Protected field, so need to check MMIE */ |
f64f9e71 | 2418 | if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) && |
cf4e594e | 2419 | ieee80211_get_mmie_keyidx(rx->skb) < 0)) { |
6ff57cf8 JB |
2420 | if (ieee80211_is_deauth(fc) || |
2421 | ieee80211_is_disassoc(fc)) | |
2422 | cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, | |
2423 | rx->skb->data, | |
2424 | rx->skb->len); | |
f2ca3ea4 | 2425 | return -EACCES; |
cf4e594e | 2426 | } |
af2d14b0 | 2427 | if (unlikely(ieee80211_is_beacon(fc) && rx->key && |
9eaf183a JM |
2428 | ieee80211_get_mmie_keyidx(rx->skb) < 0)) { |
2429 | cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, | |
2430 | rx->skb->data, | |
2431 | rx->skb->len); | |
af2d14b0 | 2432 | return -EACCES; |
9eaf183a | 2433 | } |
f2ca3ea4 JM |
2434 | /* |
2435 | * When using MFP, Action frames are not allowed prior to | |
2436 | * having configured keys. | |
2437 | */ | |
2438 | if (unlikely(ieee80211_is_action(fc) && !rx->key && | |
d8ca16db | 2439 | ieee80211_is_robust_mgmt_frame(rx->skb))) |
f2ca3ea4 JM |
2440 | return -EACCES; |
2441 | } | |
b3fc9c6c | 2442 | |
76ee65bf | 2443 | return 0; |
571ecf67 JB |
2444 | } |
2445 | ||
76ee65bf | 2446 | static int |
4114fa21 | 2447 | __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control) |
571ecf67 | 2448 | { |
eb9fb5b8 | 2449 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
f14543ee | 2450 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
fbb327c5 FF |
2451 | bool check_port_control = false; |
2452 | struct ethhdr *ehdr; | |
2453 | int ret; | |
f14543ee | 2454 | |
4114fa21 | 2455 | *port_control = false; |
9bc383de JB |
2456 | if (ieee80211_has_a4(hdr->frame_control) && |
2457 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta) | |
f14543ee | 2458 | return -1; |
9bc383de | 2459 | |
fbb327c5 FF |
2460 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
2461 | !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) { | |
2462 | ||
2463 | if (!sdata->u.mgd.use_4addr) | |
2464 | return -1; | |
1ecef20c | 2465 | else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr)) |
fbb327c5 FF |
2466 | check_port_control = true; |
2467 | } | |
2468 | ||
9bc383de | 2469 | if (is_multicast_ether_addr(hdr->addr1) && |
fbb327c5 | 2470 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta) |
f14543ee | 2471 | return -1; |
571ecf67 | 2472 | |
fbb327c5 | 2473 | ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type); |
4114fa21 | 2474 | if (ret < 0) |
fbb327c5 FF |
2475 | return ret; |
2476 | ||
2477 | ehdr = (struct ethhdr *) rx->skb->data; | |
4114fa21 FF |
2478 | if (ehdr->h_proto == rx->sdata->control_port_protocol) |
2479 | *port_control = true; | |
2480 | else if (check_port_control) | |
fbb327c5 FF |
2481 | return -1; |
2482 | ||
2483 | return 0; | |
76ee65bf | 2484 | } |
571ecf67 | 2485 | |
ce3edf6d JB |
2486 | /* |
2487 | * requires that rx->skb is a frame with ethernet header | |
2488 | */ | |
358c8d9d | 2489 | static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc) |
ce3edf6d | 2490 | { |
c97c23e3 | 2491 | static const u8 pae_group_addr[ETH_ALEN] __aligned(2) |
ce3edf6d JB |
2492 | = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 }; |
2493 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; | |
2494 | ||
2495 | /* | |
2496 | * Allow EAPOL frames to us/the PAE group address regardless | |
2497 | * of whether the frame was encrypted or not. | |
2498 | */ | |
a621fa4d | 2499 | if (ehdr->h_proto == rx->sdata->control_port_protocol && |
3bc7945e JP |
2500 | (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) || |
2501 | ether_addr_equal(ehdr->h_dest, pae_group_addr))) | |
ce3edf6d JB |
2502 | return true; |
2503 | ||
2504 | if (ieee80211_802_1x_port_control(rx) || | |
358c8d9d | 2505 | ieee80211_drop_unencrypted(rx, fc)) |
ce3edf6d JB |
2506 | return false; |
2507 | ||
2508 | return true; | |
2509 | } | |
2510 | ||
018f6fbf DK |
2511 | static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb, |
2512 | struct ieee80211_rx_data *rx) | |
2513 | { | |
2514 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
2515 | struct net_device *dev = sdata->dev; | |
2516 | ||
2517 | if (unlikely((skb->protocol == sdata->control_port_protocol || | |
7f3f96ce MT |
2518 | (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) && |
2519 | !sdata->control_port_no_preauth)) && | |
018f6fbf DK |
2520 | sdata->control_port_over_nl80211)) { |
2521 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | |
f8b43c5c | 2522 | bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED); |
018f6fbf | 2523 | |
a948f713 | 2524 | cfg80211_rx_control_port(dev, skb, noencrypt); |
018f6fbf DK |
2525 | dev_kfree_skb(skb); |
2526 | } else { | |
c8a41c6a DK |
2527 | memset(skb->cb, 0, sizeof(skb->cb)); |
2528 | ||
018f6fbf | 2529 | /* deliver to local stack */ |
c5d1686b FF |
2530 | if (rx->list) |
2531 | list_add_tail(&skb->list, rx->list); | |
018f6fbf DK |
2532 | else |
2533 | netif_receive_skb(skb); | |
2534 | } | |
2535 | } | |
2536 | ||
ce3edf6d JB |
2537 | /* |
2538 | * requires that rx->skb is a frame with ethernet header | |
2539 | */ | |
76ee65bf | 2540 | static void |
5cf121c3 | 2541 | ieee80211_deliver_skb(struct ieee80211_rx_data *rx) |
76ee65bf | 2542 | { |
eb9fb5b8 JB |
2543 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
2544 | struct net_device *dev = sdata->dev; | |
76ee65bf | 2545 | struct sk_buff *skb, *xmit_skb; |
ce3edf6d JB |
2546 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
2547 | struct sta_info *dsta; | |
571ecf67 | 2548 | |
76ee65bf RR |
2549 | skb = rx->skb; |
2550 | xmit_skb = NULL; | |
571ecf67 | 2551 | |
36ec144f | 2552 | dev_sw_netstats_rx_add(dev, skb->len); |
5a490510 | 2553 | |
de8f18d3 JB |
2554 | if (rx->sta) { |
2555 | /* The seqno index has the same property as needed | |
2556 | * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS | |
2557 | * for non-QoS-data frames. Here we know it's a data | |
2558 | * frame, so count MSDUs. | |
2559 | */ | |
0f9c5a61 | 2560 | u64_stats_update_begin(&rx->sta->rx_stats.syncp); |
de8f18d3 | 2561 | rx->sta->rx_stats.msdu[rx->seqno_idx]++; |
0f9c5a61 | 2562 | u64_stats_update_end(&rx->sta->rx_stats.syncp); |
de8f18d3 JB |
2563 | } |
2564 | ||
05c914fe JB |
2565 | if ((sdata->vif.type == NL80211_IFTYPE_AP || |
2566 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) && | |
213cd118 | 2567 | !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) && |
9bc383de | 2568 | (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) { |
72f15d53 MB |
2569 | if (is_multicast_ether_addr(ehdr->h_dest) && |
2570 | ieee80211_vif_get_num_mcast_if(sdata) != 0) { | |
ce3edf6d JB |
2571 | /* |
2572 | * send multicast frames both to higher layers in | |
2573 | * local net stack and back to the wireless medium | |
2574 | */ | |
76ee65bf | 2575 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
e87cc472 | 2576 | if (!xmit_skb) |
bdcbd8e0 | 2577 | net_info_ratelimited("%s: failed to clone multicast frame\n", |
e87cc472 | 2578 | dev->name); |
42dca5ef JB |
2579 | } else if (!is_multicast_ether_addr(ehdr->h_dest) && |
2580 | !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) { | |
2581 | dsta = sta_info_get(sdata, ehdr->h_dest); | |
abe60632 | 2582 | if (dsta) { |
ce3edf6d JB |
2583 | /* |
2584 | * The destination station is associated to | |
2585 | * this AP (in this VLAN), so send the frame | |
2586 | * directly to it and do not pass it to local | |
2587 | * net stack. | |
571ecf67 | 2588 | */ |
76ee65bf | 2589 | xmit_skb = skb; |
571ecf67 JB |
2590 | skb = NULL; |
2591 | } | |
571ecf67 JB |
2592 | } |
2593 | } | |
2594 | ||
59d9cb07 | 2595 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
9e890a1f JB |
2596 | if (skb) { |
2597 | /* 'align' will only take the values 0 or 2 here since all | |
2598 | * frames are required to be aligned to 2-byte boundaries | |
2599 | * when being passed to mac80211; the code here works just | |
2600 | * as well if that isn't true, but mac80211 assumes it can | |
2601 | * access fields as 2-byte aligned (e.g. for ether_addr_equal) | |
d1c3a37c | 2602 | */ |
9e890a1f JB |
2603 | int align; |
2604 | ||
2605 | align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3; | |
d1c3a37c JB |
2606 | if (align) { |
2607 | if (WARN_ON(skb_headroom(skb) < 3)) { | |
2608 | dev_kfree_skb(skb); | |
2609 | skb = NULL; | |
2610 | } else { | |
2611 | u8 *data = skb->data; | |
8ce0b589 ZY |
2612 | size_t len = skb_headlen(skb); |
2613 | skb->data -= align; | |
2614 | memmove(skb->data, data, len); | |
2615 | skb_set_tail_pointer(skb, len); | |
d1c3a37c JB |
2616 | } |
2617 | } | |
9e890a1f | 2618 | } |
d1c3a37c JB |
2619 | #endif |
2620 | ||
9e890a1f | 2621 | if (skb) { |
9e890a1f | 2622 | skb->protocol = eth_type_trans(skb, dev); |
018f6fbf | 2623 | ieee80211_deliver_skb_to_local_stack(skb, rx); |
571ecf67 JB |
2624 | } |
2625 | ||
76ee65bf | 2626 | if (xmit_skb) { |
aef6c928 HS |
2627 | /* |
2628 | * Send to wireless media and increase priority by 256 to | |
2629 | * keep the received priority instead of reclassifying | |
2630 | * the frame (see cfg80211_classify8021d). | |
2631 | */ | |
2632 | xmit_skb->priority += 256; | |
f831e909 | 2633 | xmit_skb->protocol = htons(ETH_P_802_3); |
ce3edf6d JB |
2634 | skb_reset_network_header(xmit_skb); |
2635 | skb_reset_mac_header(xmit_skb); | |
76ee65bf | 2636 | dev_queue_xmit(xmit_skb); |
571ecf67 | 2637 | } |
76ee65bf RR |
2638 | } |
2639 | ||
49461622 | 2640 | static ieee80211_rx_result debug_noinline |
24bba078 | 2641 | __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset) |
fd4c7f2f | 2642 | { |
eb9fb5b8 | 2643 | struct net_device *dev = rx->sdata->dev; |
eaf85ca7 | 2644 | struct sk_buff *skb = rx->skb; |
358c8d9d HH |
2645 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
2646 | __le16 fc = hdr->frame_control; | |
eaf85ca7 | 2647 | struct sk_buff_head frame_list; |
7f6990c8 | 2648 | struct ethhdr ethhdr; |
e2b5227f | 2649 | const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source; |
fd4c7f2f | 2650 | |
ea720935 | 2651 | if (unlikely(ieee80211_has_a4(hdr->frame_control))) { |
e2b5227f JB |
2652 | check_da = NULL; |
2653 | check_sa = NULL; | |
2654 | } else switch (rx->sdata->vif.type) { | |
2655 | case NL80211_IFTYPE_AP: | |
2656 | case NL80211_IFTYPE_AP_VLAN: | |
2657 | check_da = NULL; | |
2658 | break; | |
2659 | case NL80211_IFTYPE_STATION: | |
2660 | if (!rx->sta || | |
2661 | !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER)) | |
2662 | check_sa = NULL; | |
2663 | break; | |
2664 | case NL80211_IFTYPE_MESH_POINT: | |
2665 | check_sa = NULL; | |
2666 | break; | |
2667 | default: | |
2668 | break; | |
ea720935 | 2669 | } |
fd4c7f2f | 2670 | |
eaf85ca7 ZY |
2671 | skb->dev = dev; |
2672 | __skb_queue_head_init(&frame_list); | |
fd4c7f2f | 2673 | |
7f6990c8 JB |
2674 | if (ieee80211_data_to_8023_exthdr(skb, ðhdr, |
2675 | rx->sdata->vif.addr, | |
24bba078 FF |
2676 | rx->sdata->vif.type, |
2677 | data_offset)) | |
7f6990c8 JB |
2678 | return RX_DROP_UNUSABLE; |
2679 | ||
eaf85ca7 ZY |
2680 | ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr, |
2681 | rx->sdata->vif.type, | |
8b935ee2 | 2682 | rx->local->hw.extra_tx_headroom, |
e2b5227f | 2683 | check_da, check_sa); |
fd4c7f2f | 2684 | |
eaf85ca7 ZY |
2685 | while (!skb_queue_empty(&frame_list)) { |
2686 | rx->skb = __skb_dequeue(&frame_list); | |
fd4c7f2f | 2687 | |
358c8d9d | 2688 | if (!ieee80211_frame_allowed(rx, fc)) { |
eaf85ca7 | 2689 | dev_kfree_skb(rx->skb); |
ce3edf6d JB |
2690 | continue; |
2691 | } | |
fd4c7f2f RR |
2692 | |
2693 | ieee80211_deliver_skb(rx); | |
2694 | } | |
2695 | ||
9ae54c84 | 2696 | return RX_QUEUED; |
fd4c7f2f RR |
2697 | } |
2698 | ||
24bba078 FF |
2699 | static ieee80211_rx_result debug_noinline |
2700 | ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx) | |
2701 | { | |
2702 | struct sk_buff *skb = rx->skb; | |
2703 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | |
2704 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
2705 | __le16 fc = hdr->frame_control; | |
2706 | ||
2707 | if (!(status->rx_flags & IEEE80211_RX_AMSDU)) | |
2708 | return RX_CONTINUE; | |
2709 | ||
2710 | if (unlikely(!ieee80211_is_data(fc))) | |
2711 | return RX_CONTINUE; | |
2712 | ||
2713 | if (unlikely(!ieee80211_is_data_present(fc))) | |
2714 | return RX_DROP_MONITOR; | |
2715 | ||
2716 | if (unlikely(ieee80211_has_a4(hdr->frame_control))) { | |
2717 | switch (rx->sdata->vif.type) { | |
2718 | case NL80211_IFTYPE_AP_VLAN: | |
2719 | if (!rx->sdata->u.vlan.sta) | |
2720 | return RX_DROP_UNUSABLE; | |
2721 | break; | |
2722 | case NL80211_IFTYPE_STATION: | |
2723 | if (!rx->sdata->u.mgd.use_4addr) | |
2724 | return RX_DROP_UNUSABLE; | |
2725 | break; | |
2726 | default: | |
2727 | return RX_DROP_UNUSABLE; | |
2728 | } | |
2729 | } | |
2730 | ||
2731 | if (is_multicast_ether_addr(hdr->addr1)) | |
2732 | return RX_DROP_UNUSABLE; | |
2733 | ||
2734 | return __ieee80211_rx_h_amsdu(rx, 0); | |
2735 | } | |
2736 | ||
bf94e17b | 2737 | #ifdef CONFIG_MAC80211_MESH |
b0dee578 | 2738 | static ieee80211_rx_result |
e32f85f7 LCC |
2739 | ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx) |
2740 | { | |
30789eb6 TP |
2741 | struct ieee80211_hdr *fwd_hdr, *hdr; |
2742 | struct ieee80211_tx_info *info; | |
e32f85f7 | 2743 | struct ieee80211s_hdr *mesh_hdr; |
e32f85f7 | 2744 | struct sk_buff *skb = rx->skb, *fwd_skb; |
3b8d81e0 | 2745 | struct ieee80211_local *local = rx->local; |
eb9fb5b8 | 2746 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
30789eb6 | 2747 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
cf440128 | 2748 | u16 ac, q, hdrlen; |
51d0af22 | 2749 | int tailroom = 0; |
e32f85f7 LCC |
2750 | |
2751 | hdr = (struct ieee80211_hdr *) skb->data; | |
2752 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
9b395bc3 JB |
2753 | |
2754 | /* make sure fixed part of mesh header is there, also checks skb len */ | |
2755 | if (!pskb_may_pull(rx->skb, hdrlen + 6)) | |
2756 | return RX_DROP_MONITOR; | |
2757 | ||
2758 | mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); | |
2759 | ||
2760 | /* make sure full mesh header is there, also checks skb len */ | |
2761 | if (!pskb_may_pull(rx->skb, | |
2762 | hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr))) | |
2763 | return RX_DROP_MONITOR; | |
2764 | ||
2765 | /* reload pointers */ | |
2766 | hdr = (struct ieee80211_hdr *) skb->data; | |
e32f85f7 LCC |
2767 | mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); |
2768 | ||
d0c22119 BC |
2769 | if (ieee80211_drop_unencrypted(rx, hdr->frame_control)) |
2770 | return RX_DROP_MONITOR; | |
2771 | ||
2157fdd6 TP |
2772 | /* frame is in RMC, don't forward */ |
2773 | if (ieee80211_is_data(hdr->frame_control) && | |
2774 | is_multicast_ether_addr(hdr->addr1) && | |
bf7cd94d | 2775 | mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr)) |
2157fdd6 TP |
2776 | return RX_DROP_MONITOR; |
2777 | ||
5c90067c | 2778 | if (!ieee80211_is_data(hdr->frame_control)) |
e32f85f7 LCC |
2779 | return RX_CONTINUE; |
2780 | ||
2781 | if (!mesh_hdr->ttl) | |
e32f85f7 LCC |
2782 | return RX_DROP_MONITOR; |
2783 | ||
43b7b314 | 2784 | if (mesh_hdr->flags & MESH_FLAGS_AE) { |
79617dee | 2785 | struct mesh_path *mppath; |
43b7b314 JC |
2786 | char *proxied_addr; |
2787 | char *mpp_addr; | |
2788 | ||
2789 | if (is_multicast_ether_addr(hdr->addr1)) { | |
2790 | mpp_addr = hdr->addr3; | |
2791 | proxied_addr = mesh_hdr->eaddr1; | |
5667c86a RM |
2792 | } else if ((mesh_hdr->flags & MESH_FLAGS_AE) == |
2793 | MESH_FLAGS_AE_A5_A6) { | |
9b395bc3 | 2794 | /* has_a4 already checked in ieee80211_rx_mesh_check */ |
43b7b314 JC |
2795 | mpp_addr = hdr->addr4; |
2796 | proxied_addr = mesh_hdr->eaddr2; | |
9b395bc3 JB |
2797 | } else { |
2798 | return RX_DROP_MONITOR; | |
43b7b314 | 2799 | } |
79617dee | 2800 | |
79617dee | 2801 | rcu_read_lock(); |
bf7cd94d | 2802 | mppath = mpp_path_lookup(sdata, proxied_addr); |
79617dee | 2803 | if (!mppath) { |
bf7cd94d | 2804 | mpp_path_add(sdata, proxied_addr, mpp_addr); |
79617dee Y |
2805 | } else { |
2806 | spin_lock_bh(&mppath->state_lock); | |
b203ca39 | 2807 | if (!ether_addr_equal(mppath->mpp, mpp_addr)) |
43b7b314 | 2808 | memcpy(mppath->mpp, mpp_addr, ETH_ALEN); |
ab1c7906 | 2809 | mppath->exp_time = jiffies; |
79617dee Y |
2810 | spin_unlock_bh(&mppath->state_lock); |
2811 | } | |
2812 | rcu_read_unlock(); | |
2813 | } | |
2814 | ||
3c5772a5 JC |
2815 | /* Frame has reached destination. Don't forward */ |
2816 | if (!is_multicast_ether_addr(hdr->addr1) && | |
b203ca39 | 2817 | ether_addr_equal(sdata->vif.addr, hdr->addr3)) |
e32f85f7 LCC |
2818 | return RX_CONTINUE; |
2819 | ||
cf440128 MK |
2820 | ac = ieee80211_select_queue_80211(sdata, skb, hdr); |
2821 | q = sdata->vif.hw_queue[ac]; | |
d3c1597b | 2822 | if (ieee80211_queue_stopped(&local->hw, q)) { |
30789eb6 | 2823 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion); |
d3c1597b TP |
2824 | return RX_DROP_MONITOR; |
2825 | } | |
2826 | skb_set_queue_mapping(skb, q); | |
e32f85f7 | 2827 | |
30789eb6 | 2828 | if (!--mesh_hdr->ttl) { |
a0dc0203 BC |
2829 | if (!is_multicast_ether_addr(hdr->addr1)) |
2830 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, | |
2831 | dropped_frames_ttl); | |
2ac64cd1 | 2832 | goto out; |
30789eb6 TP |
2833 | } |
2834 | ||
d665508b CYY |
2835 | if (!ifmsh->mshcfg.dot11MeshForwarding) |
2836 | goto out; | |
2837 | ||
51d0af22 FF |
2838 | if (sdata->crypto_tx_tailroom_needed_cnt) |
2839 | tailroom = IEEE80211_ENCRYPT_TAILROOM; | |
2840 | ||
c38c39bf | 2841 | fwd_skb = skb_copy_expand(skb, local->tx_headroom + |
51d0af22 FF |
2842 | sdata->encrypt_headroom, |
2843 | tailroom, GFP_ATOMIC); | |
0c3d5a96 | 2844 | if (!fwd_skb) |
30789eb6 | 2845 | goto out; |
30789eb6 TP |
2846 | |
2847 | fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data; | |
9d6d6f49 | 2848 | fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY); |
30789eb6 TP |
2849 | info = IEEE80211_SKB_CB(fwd_skb); |
2850 | memset(info, 0, sizeof(*info)); | |
cc20ff2c | 2851 | info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING; |
30789eb6 TP |
2852 | info->control.vif = &rx->sdata->vif; |
2853 | info->control.jiffies = jiffies; | |
2854 | if (is_multicast_ether_addr(fwd_hdr->addr1)) { | |
2855 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast); | |
2856 | memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN); | |
3f52b7e3 MP |
2857 | /* update power mode indication when forwarding */ |
2858 | ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr); | |
bf7cd94d | 2859 | } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) { |
3f52b7e3 | 2860 | /* mesh power mode flags updated in mesh_nexthop_lookup */ |
30789eb6 TP |
2861 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast); |
2862 | } else { | |
2863 | /* unable to resolve next hop */ | |
bf7cd94d | 2864 | mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl, |
f63f8421 CYY |
2865 | fwd_hdr->addr3, 0, |
2866 | WLAN_REASON_MESH_PATH_NOFORWARD, | |
2867 | fwd_hdr->addr2); | |
30789eb6 | 2868 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route); |
74b8cc3d | 2869 | kfree_skb(fwd_skb); |
30789eb6 | 2870 | return RX_DROP_MONITOR; |
e32f85f7 LCC |
2871 | } |
2872 | ||
30789eb6 TP |
2873 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames); |
2874 | ieee80211_add_pending_skb(local, fwd_skb); | |
b51aff05 | 2875 | out: |
df140465 | 2876 | if (is_multicast_ether_addr(hdr->addr1)) |
e32f85f7 | 2877 | return RX_CONTINUE; |
df140465 | 2878 | return RX_DROP_MONITOR; |
e32f85f7 | 2879 | } |
bf94e17b | 2880 | #endif |
e32f85f7 | 2881 | |
49461622 | 2882 | static ieee80211_rx_result debug_noinline |
5cf121c3 | 2883 | ieee80211_rx_h_data(struct ieee80211_rx_data *rx) |
76ee65bf | 2884 | { |
eb9fb5b8 | 2885 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
e15276a4 | 2886 | struct ieee80211_local *local = rx->local; |
eb9fb5b8 | 2887 | struct net_device *dev = sdata->dev; |
358c8d9d HH |
2888 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
2889 | __le16 fc = hdr->frame_control; | |
4114fa21 | 2890 | bool port_control; |
ce3edf6d | 2891 | int err; |
76ee65bf | 2892 | |
358c8d9d | 2893 | if (unlikely(!ieee80211_is_data(hdr->frame_control))) |
9ae54c84 | 2894 | return RX_CONTINUE; |
76ee65bf | 2895 | |
358c8d9d | 2896 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) |
e4c26add | 2897 | return RX_DROP_MONITOR; |
76ee65bf | 2898 | |
f14543ee | 2899 | /* |
e7f4a940 JB |
2900 | * Send unexpected-4addr-frame event to hostapd. For older versions, |
2901 | * also drop the frame to cooked monitor interfaces. | |
f14543ee FF |
2902 | */ |
2903 | if (ieee80211_has_a4(hdr->frame_control) && | |
e7f4a940 JB |
2904 | sdata->vif.type == NL80211_IFTYPE_AP) { |
2905 | if (rx->sta && | |
2906 | !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT)) | |
2907 | cfg80211_rx_unexpected_4addr_frame( | |
2908 | rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC); | |
f14543ee | 2909 | return RX_DROP_MONITOR; |
e7f4a940 | 2910 | } |
f14543ee | 2911 | |
4114fa21 | 2912 | err = __ieee80211_data_to_8023(rx, &port_control); |
76ee65bf | 2913 | if (unlikely(err)) |
e4c26add | 2914 | return RX_DROP_UNUSABLE; |
76ee65bf | 2915 | |
358c8d9d | 2916 | if (!ieee80211_frame_allowed(rx, fc)) |
e4c26add | 2917 | return RX_DROP_MONITOR; |
ce3edf6d | 2918 | |
8a4d32f3 AN |
2919 | /* directly handle TDLS channel switch requests/responses */ |
2920 | if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto == | |
2921 | cpu_to_be16(ETH_P_TDLS))) { | |
2922 | struct ieee80211_tdls_data *tf = (void *)rx->skb->data; | |
2923 | ||
2924 | if (pskb_may_pull(rx->skb, | |
2925 | offsetof(struct ieee80211_tdls_data, u)) && | |
2926 | tf->payload_type == WLAN_TDLS_SNAP_RFTYPE && | |
2927 | tf->category == WLAN_CATEGORY_TDLS && | |
2928 | (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST || | |
2929 | tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) { | |
c8ff71e6 AN |
2930 | skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb); |
2931 | schedule_work(&local->tdls_chsw_work); | |
8a4d32f3 | 2932 | if (rx->sta) |
e5a9f8d0 | 2933 | rx->sta->rx_stats.packets++; |
8a4d32f3 AN |
2934 | |
2935 | return RX_QUEUED; | |
2936 | } | |
2937 | } | |
2938 | ||
4114fa21 FF |
2939 | if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
2940 | unlikely(port_control) && sdata->bss) { | |
2941 | sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, | |
2942 | u.ap); | |
2943 | dev = sdata->dev; | |
2944 | rx->sdata = sdata; | |
2945 | } | |
2946 | ||
76ee65bf RR |
2947 | rx->skb->dev = dev; |
2948 | ||
602fae42 JB |
2949 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) && |
2950 | local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 && | |
8c99f691 RM |
2951 | !is_multicast_ether_addr( |
2952 | ((struct ethhdr *)rx->skb->data)->h_dest) && | |
2953 | (!local->scanning && | |
602fae42 JB |
2954 | !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) |
2955 | mod_timer(&local->dynamic_ps_timer, jiffies + | |
2956 | msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); | |
e15276a4 | 2957 | |
76ee65bf | 2958 | ieee80211_deliver_skb(rx); |
571ecf67 | 2959 | |
9ae54c84 | 2960 | return RX_QUEUED; |
571ecf67 JB |
2961 | } |
2962 | ||
49461622 | 2963 | static ieee80211_rx_result debug_noinline |
f9e124fb | 2964 | ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames) |
71364716 | 2965 | { |
71364716 | 2966 | struct sk_buff *skb = rx->skb; |
a7767f95 | 2967 | struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data; |
71364716 RR |
2968 | struct tid_ampdu_rx *tid_agg_rx; |
2969 | u16 start_seq_num; | |
2970 | u16 tid; | |
2971 | ||
a7767f95 | 2972 | if (likely(!ieee80211_is_ctl(bar->frame_control))) |
9ae54c84 | 2973 | return RX_CONTINUE; |
71364716 | 2974 | |
a7767f95 | 2975 | if (ieee80211_is_back_req(bar->frame_control)) { |
8ae5977f JB |
2976 | struct { |
2977 | __le16 control, start_seq_num; | |
2978 | } __packed bar_data; | |
6382246e EG |
2979 | struct ieee80211_event event = { |
2980 | .type = BAR_RX_EVENT, | |
2981 | }; | |
8ae5977f | 2982 | |
71364716 | 2983 | if (!rx->sta) |
a02ae758 | 2984 | return RX_DROP_MONITOR; |
8ae5977f JB |
2985 | |
2986 | if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control), | |
2987 | &bar_data, sizeof(bar_data))) | |
2988 | return RX_DROP_MONITOR; | |
2989 | ||
8ae5977f | 2990 | tid = le16_to_cpu(bar_data.control) >> 12; |
a87f736d | 2991 | |
53f24974 JB |
2992 | if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) && |
2993 | !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg)) | |
2994 | ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid, | |
2995 | WLAN_BACK_RECIPIENT, | |
2996 | WLAN_REASON_QSTA_REQUIRE_SETUP); | |
2997 | ||
a87f736d JB |
2998 | tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]); |
2999 | if (!tid_agg_rx) | |
a02ae758 | 3000 | return RX_DROP_MONITOR; |
71364716 | 3001 | |
8ae5977f | 3002 | start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4; |
6382246e EG |
3003 | event.u.ba.tid = tid; |
3004 | event.u.ba.ssn = start_seq_num; | |
3005 | event.u.ba.sta = &rx->sta->sta; | |
71364716 RR |
3006 | |
3007 | /* reset session timer */ | |
20ad19d0 JB |
3008 | if (tid_agg_rx->timeout) |
3009 | mod_timer(&tid_agg_rx->session_timer, | |
3010 | TU_TO_EXP_TIME(tid_agg_rx->timeout)); | |
71364716 | 3011 | |
dd318575 | 3012 | spin_lock(&tid_agg_rx->reorder_lock); |
a02ae758 | 3013 | /* release stored frames up to start of BAR */ |
d3b2fb53 | 3014 | ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx, |
f9e124fb | 3015 | start_seq_num, frames); |
dd318575 JB |
3016 | spin_unlock(&tid_agg_rx->reorder_lock); |
3017 | ||
6382246e EG |
3018 | drv_event_callback(rx->local, rx->sdata, &event); |
3019 | ||
a02ae758 JB |
3020 | kfree_skb(skb); |
3021 | return RX_QUEUED; | |
71364716 RR |
3022 | } |
3023 | ||
08daecae JB |
3024 | /* |
3025 | * After this point, we only want management frames, | |
3026 | * so we can drop all remaining control frames to | |
3027 | * cooked monitor interfaces. | |
3028 | */ | |
3029 | return RX_DROP_MONITOR; | |
71364716 RR |
3030 | } |
3031 | ||
f4f727a6 JM |
3032 | static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata, |
3033 | struct ieee80211_mgmt *mgmt, | |
3034 | size_t len) | |
fea14732 JM |
3035 | { |
3036 | struct ieee80211_local *local = sdata->local; | |
3037 | struct sk_buff *skb; | |
3038 | struct ieee80211_mgmt *resp; | |
3039 | ||
b203ca39 | 3040 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) { |
fea14732 JM |
3041 | /* Not to own unicast address */ |
3042 | return; | |
3043 | } | |
3044 | ||
b203ca39 JP |
3045 | if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) || |
3046 | !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) { | |
77fdaa12 | 3047 | /* Not from the current AP or not associated yet. */ |
fea14732 JM |
3048 | return; |
3049 | } | |
3050 | ||
3051 | if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) { | |
3052 | /* Too short SA Query request frame */ | |
3053 | return; | |
3054 | } | |
3055 | ||
3056 | skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom); | |
3057 | if (skb == NULL) | |
3058 | return; | |
3059 | ||
3060 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
b080db58 | 3061 | resp = skb_put_zero(skb, 24); |
fea14732 | 3062 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
47846c9b | 3063 | memcpy(resp->sa, sdata->vif.addr, ETH_ALEN); |
46900298 | 3064 | memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN); |
fea14732 JM |
3065 | resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
3066 | IEEE80211_STYPE_ACTION); | |
3067 | skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query)); | |
3068 | resp->u.action.category = WLAN_CATEGORY_SA_QUERY; | |
3069 | resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE; | |
3070 | memcpy(resp->u.action.u.sa_query.trans_id, | |
3071 | mgmt->u.action.u.sa_query.trans_id, | |
3072 | WLAN_SA_QUERY_TR_ID_LEN); | |
3073 | ||
62ae67be | 3074 | ieee80211_tx_skb(sdata, skb); |
fea14732 JM |
3075 | } |
3076 | ||
2e161f78 JB |
3077 | static ieee80211_rx_result debug_noinline |
3078 | ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx) | |
3079 | { | |
3080 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; | |
554891e6 | 3081 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
2e161f78 | 3082 | |
09a740ce TP |
3083 | if (ieee80211_is_s1g_beacon(mgmt->frame_control)) |
3084 | return RX_CONTINUE; | |
3085 | ||
2e161f78 JB |
3086 | /* |
3087 | * From here on, look only at management frames. | |
3088 | * Data and control frames are already handled, | |
3089 | * and unknown (reserved) frames are useless. | |
3090 | */ | |
3091 | if (rx->skb->len < 24) | |
3092 | return RX_DROP_MONITOR; | |
3093 | ||
3094 | if (!ieee80211_is_mgmt(mgmt->frame_control)) | |
3095 | return RX_DROP_MONITOR; | |
3096 | ||
ee971924 JB |
3097 | if (rx->sdata->vif.type == NL80211_IFTYPE_AP && |
3098 | ieee80211_is_beacon(mgmt->frame_control) && | |
3099 | !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) { | |
804483e9 JB |
3100 | int sig = 0; |
3101 | ||
1ad22fb5 T |
3102 | if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) && |
3103 | !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) | |
804483e9 JB |
3104 | sig = status->signal; |
3105 | ||
e76fede8 TP |
3106 | cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy, |
3107 | rx->skb->data, rx->skb->len, | |
3108 | ieee80211_rx_status_to_khz(status), | |
3109 | sig); | |
ee971924 JB |
3110 | rx->flags |= IEEE80211_RX_BEACON_REPORTED; |
3111 | } | |
3112 | ||
2e161f78 JB |
3113 | if (ieee80211_drop_unencrypted_mgmt(rx)) |
3114 | return RX_DROP_UNUSABLE; | |
3115 | ||
3116 | return RX_CONTINUE; | |
3117 | } | |
3118 | ||
de1ede7a JB |
3119 | static ieee80211_rx_result debug_noinline |
3120 | ieee80211_rx_h_action(struct ieee80211_rx_data *rx) | |
3121 | { | |
3122 | struct ieee80211_local *local = rx->local; | |
eb9fb5b8 | 3123 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
de1ede7a | 3124 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; |
554891e6 | 3125 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
de1ede7a JB |
3126 | int len = rx->skb->len; |
3127 | ||
3128 | if (!ieee80211_is_action(mgmt->frame_control)) | |
3129 | return RX_CONTINUE; | |
3130 | ||
026331c4 JM |
3131 | /* drop too small frames */ |
3132 | if (len < IEEE80211_MIN_ACTION_SIZE) | |
84040805 | 3133 | return RX_DROP_UNUSABLE; |
de1ede7a | 3134 | |
815b8092 | 3135 | if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC && |
cd7760e6 SW |
3136 | mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED && |
3137 | mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT) | |
84040805 | 3138 | return RX_DROP_UNUSABLE; |
de1ede7a | 3139 | |
de1ede7a | 3140 | switch (mgmt->u.action.category) { |
1d8d3dec JB |
3141 | case WLAN_CATEGORY_HT: |
3142 | /* reject HT action frames from stations not supporting HT */ | |
3143 | if (!rx->sta->sta.ht_cap.ht_supported) | |
3144 | goto invalid; | |
3145 | ||
3146 | if (sdata->vif.type != NL80211_IFTYPE_STATION && | |
3147 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && | |
3148 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | |
3149 | sdata->vif.type != NL80211_IFTYPE_AP && | |
3150 | sdata->vif.type != NL80211_IFTYPE_ADHOC) | |
3151 | break; | |
3152 | ||
ec61cd63 | 3153 | /* verify action & smps_control/chanwidth are present */ |
1d8d3dec JB |
3154 | if (len < IEEE80211_MIN_ACTION_SIZE + 2) |
3155 | goto invalid; | |
3156 | ||
3157 | switch (mgmt->u.action.u.ht_smps.action) { | |
3158 | case WLAN_HT_ACTION_SMPS: { | |
3159 | struct ieee80211_supported_band *sband; | |
af0ed69b | 3160 | enum ieee80211_smps_mode smps_mode; |
ff84e7bf | 3161 | struct sta_opmode_info sta_opmode = {}; |
1d8d3dec | 3162 | |
c4d800dc IP |
3163 | if (sdata->vif.type != NL80211_IFTYPE_AP && |
3164 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN) | |
3165 | goto handled; | |
3166 | ||
1d8d3dec JB |
3167 | /* convert to HT capability */ |
3168 | switch (mgmt->u.action.u.ht_smps.smps_control) { | |
3169 | case WLAN_HT_SMPS_CONTROL_DISABLED: | |
af0ed69b | 3170 | smps_mode = IEEE80211_SMPS_OFF; |
1d8d3dec JB |
3171 | break; |
3172 | case WLAN_HT_SMPS_CONTROL_STATIC: | |
af0ed69b | 3173 | smps_mode = IEEE80211_SMPS_STATIC; |
1d8d3dec JB |
3174 | break; |
3175 | case WLAN_HT_SMPS_CONTROL_DYNAMIC: | |
af0ed69b | 3176 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
1d8d3dec JB |
3177 | break; |
3178 | default: | |
3179 | goto invalid; | |
3180 | } | |
1d8d3dec JB |
3181 | |
3182 | /* if no change do nothing */ | |
af0ed69b | 3183 | if (rx->sta->sta.smps_mode == smps_mode) |
1d8d3dec | 3184 | goto handled; |
af0ed69b | 3185 | rx->sta->sta.smps_mode = smps_mode; |
57566b20 TCR |
3186 | sta_opmode.smps_mode = |
3187 | ieee80211_smps_mode_to_smps_mode(smps_mode); | |
ff84e7bf | 3188 | sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED; |
1d8d3dec JB |
3189 | |
3190 | sband = rx->local->hw.wiphy->bands[status->band]; | |
3191 | ||
64f68e5d JB |
3192 | rate_control_rate_update(local, sband, rx->sta, |
3193 | IEEE80211_RC_SMPS_CHANGED); | |
ff84e7bf TCR |
3194 | cfg80211_sta_opmode_change_notify(sdata->dev, |
3195 | rx->sta->addr, | |
3196 | &sta_opmode, | |
c752cac9 | 3197 | GFP_ATOMIC); |
1d8d3dec JB |
3198 | goto handled; |
3199 | } | |
ec61cd63 JB |
3200 | case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: { |
3201 | struct ieee80211_supported_band *sband; | |
3202 | u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth; | |
1c45c5ce | 3203 | enum ieee80211_sta_rx_bandwidth max_bw, new_bw; |
ff84e7bf | 3204 | struct sta_opmode_info sta_opmode = {}; |
ec61cd63 JB |
3205 | |
3206 | /* If it doesn't support 40 MHz it can't change ... */ | |
e1a0c6b3 JB |
3207 | if (!(rx->sta->sta.ht_cap.cap & |
3208 | IEEE80211_HT_CAP_SUP_WIDTH_20_40)) | |
ec61cd63 JB |
3209 | goto handled; |
3210 | ||
e1a0c6b3 | 3211 | if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ) |
1c45c5ce | 3212 | max_bw = IEEE80211_STA_RX_BW_20; |
e1a0c6b3 | 3213 | else |
1c45c5ce EP |
3214 | max_bw = ieee80211_sta_cap_rx_bw(rx->sta); |
3215 | ||
3216 | /* set cur_max_bandwidth and recalc sta bw */ | |
3217 | rx->sta->cur_max_bandwidth = max_bw; | |
3218 | new_bw = ieee80211_sta_cur_vht_bw(rx->sta); | |
ec61cd63 | 3219 | |
e1a0c6b3 | 3220 | if (rx->sta->sta.bandwidth == new_bw) |
ec61cd63 JB |
3221 | goto handled; |
3222 | ||
1c45c5ce | 3223 | rx->sta->sta.bandwidth = new_bw; |
ec61cd63 | 3224 | sband = rx->local->hw.wiphy->bands[status->band]; |
97f5f425 TCR |
3225 | sta_opmode.bw = |
3226 | ieee80211_sta_rx_bw_to_chan_width(rx->sta); | |
ff84e7bf | 3227 | sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED; |
ec61cd63 JB |
3228 | |
3229 | rate_control_rate_update(local, sband, rx->sta, | |
3230 | IEEE80211_RC_BW_CHANGED); | |
ff84e7bf TCR |
3231 | cfg80211_sta_opmode_change_notify(sdata->dev, |
3232 | rx->sta->addr, | |
3233 | &sta_opmode, | |
c752cac9 | 3234 | GFP_ATOMIC); |
ec61cd63 JB |
3235 | goto handled; |
3236 | } | |
1d8d3dec JB |
3237 | default: |
3238 | goto invalid; | |
3239 | } | |
3240 | ||
0af83d3d | 3241 | break; |
1b3a2e49 JB |
3242 | case WLAN_CATEGORY_PUBLIC: |
3243 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) | |
3244 | goto invalid; | |
3245 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
3246 | break; | |
3247 | if (!rx->sta) | |
3248 | break; | |
3249 | if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) | |
3250 | break; | |
3251 | if (mgmt->u.action.u.ext_chan_switch.action_code != | |
3252 | WLAN_PUB_ACTION_EXT_CHANSW_ANN) | |
3253 | break; | |
3254 | if (len < offsetof(struct ieee80211_mgmt, | |
3255 | u.action.u.ext_chan_switch.variable)) | |
3256 | goto invalid; | |
3257 | goto queue; | |
0af83d3d JB |
3258 | case WLAN_CATEGORY_VHT: |
3259 | if (sdata->vif.type != NL80211_IFTYPE_STATION && | |
3260 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && | |
3261 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | |
3262 | sdata->vif.type != NL80211_IFTYPE_AP && | |
3263 | sdata->vif.type != NL80211_IFTYPE_ADHOC) | |
3264 | break; | |
3265 | ||
3266 | /* verify action code is present */ | |
3267 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) | |
3268 | goto invalid; | |
3269 | ||
3270 | switch (mgmt->u.action.u.vht_opmode_notif.action_code) { | |
3271 | case WLAN_VHT_ACTION_OPMODE_NOTIF: { | |
0af83d3d JB |
3272 | /* verify opmode is present */ |
3273 | if (len < IEEE80211_MIN_ACTION_SIZE + 2) | |
3274 | goto invalid; | |
d2941df8 | 3275 | goto queue; |
0af83d3d | 3276 | } |
23a1f8d4 SS |
3277 | case WLAN_VHT_ACTION_GROUPID_MGMT: { |
3278 | if (len < IEEE80211_MIN_ACTION_SIZE + 25) | |
3279 | goto invalid; | |
3280 | goto queue; | |
3281 | } | |
0af83d3d JB |
3282 | default: |
3283 | break; | |
3284 | } | |
1d8d3dec | 3285 | break; |
de1ede7a | 3286 | case WLAN_CATEGORY_BACK: |
8abd3f9b | 3287 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
ae2772b3 | 3288 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && |
8abd3f9b | 3289 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
13c40c54 AS |
3290 | sdata->vif.type != NL80211_IFTYPE_AP && |
3291 | sdata->vif.type != NL80211_IFTYPE_ADHOC) | |
84040805 | 3292 | break; |
8abd3f9b | 3293 | |
026331c4 JM |
3294 | /* verify action_code is present */ |
3295 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) | |
3296 | break; | |
3297 | ||
de1ede7a JB |
3298 | switch (mgmt->u.action.u.addba_req.action_code) { |
3299 | case WLAN_ACTION_ADDBA_REQ: | |
3300 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
3301 | sizeof(mgmt->u.action.u.addba_req))) | |
bed7ee6e JB |
3302 | goto invalid; |
3303 | break; | |
de1ede7a JB |
3304 | case WLAN_ACTION_ADDBA_RESP: |
3305 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
3306 | sizeof(mgmt->u.action.u.addba_resp))) | |
bed7ee6e JB |
3307 | goto invalid; |
3308 | break; | |
de1ede7a JB |
3309 | case WLAN_ACTION_DELBA: |
3310 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
3311 | sizeof(mgmt->u.action.u.delba))) | |
bed7ee6e JB |
3312 | goto invalid; |
3313 | break; | |
3314 | default: | |
3315 | goto invalid; | |
de1ede7a | 3316 | } |
bed7ee6e | 3317 | |
8b58ff83 | 3318 | goto queue; |
39192c0b | 3319 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
026331c4 JM |
3320 | /* verify action_code is present */ |
3321 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) | |
3322 | break; | |
3323 | ||
39192c0b JB |
3324 | switch (mgmt->u.action.u.measurement.action_code) { |
3325 | case WLAN_ACTION_SPCT_MSR_REQ: | |
57fbcce3 | 3326 | if (status->band != NL80211_BAND_5GHZ) |
cd7760e6 SW |
3327 | break; |
3328 | ||
39192c0b JB |
3329 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
3330 | sizeof(mgmt->u.action.u.measurement))) | |
84040805 | 3331 | break; |
cd7760e6 SW |
3332 | |
3333 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
3334 | break; | |
3335 | ||
39192c0b | 3336 | ieee80211_process_measurement_req(sdata, mgmt, len); |
84040805 | 3337 | goto handled; |
cd7760e6 SW |
3338 | case WLAN_ACTION_SPCT_CHL_SWITCH: { |
3339 | u8 *bssid; | |
3340 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
3341 | sizeof(mgmt->u.action.u.chan_switch))) | |
84040805 | 3342 | break; |
cc32abd4 | 3343 | |
cd7760e6 | 3344 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
b8456a14 CYY |
3345 | sdata->vif.type != NL80211_IFTYPE_ADHOC && |
3346 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT) | |
cd7760e6 SW |
3347 | break; |
3348 | ||
3349 | if (sdata->vif.type == NL80211_IFTYPE_STATION) | |
3350 | bssid = sdata->u.mgd.bssid; | |
3351 | else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) | |
3352 | bssid = sdata->u.ibss.bssid; | |
b8456a14 CYY |
3353 | else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
3354 | bssid = mgmt->sa; | |
cd7760e6 SW |
3355 | else |
3356 | break; | |
3357 | ||
3358 | if (!ether_addr_equal(mgmt->bssid, bssid)) | |
84040805 | 3359 | break; |
c481ec97 | 3360 | |
8b58ff83 | 3361 | goto queue; |
cd7760e6 | 3362 | } |
39192c0b JB |
3363 | } |
3364 | break; | |
8db09850 | 3365 | case WLAN_CATEGORY_SELF_PROTECTED: |
9b395bc3 JB |
3366 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
3367 | sizeof(mgmt->u.action.u.self_prot.action_code))) | |
3368 | break; | |
3369 | ||
8db09850 TP |
3370 | switch (mgmt->u.action.u.self_prot.action_code) { |
3371 | case WLAN_SP_MESH_PEERING_OPEN: | |
3372 | case WLAN_SP_MESH_PEERING_CLOSE: | |
3373 | case WLAN_SP_MESH_PEERING_CONFIRM: | |
3374 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | |
3375 | goto invalid; | |
a6dad6a2 | 3376 | if (sdata->u.mesh.user_mpm) |
8db09850 TP |
3377 | /* userspace handles this frame */ |
3378 | break; | |
3379 | goto queue; | |
3380 | case WLAN_SP_MGK_INFORM: | |
3381 | case WLAN_SP_MGK_ACK: | |
3382 | if (!ieee80211_vif_is_mesh(&sdata->vif)) | |
3383 | goto invalid; | |
3384 | break; | |
3385 | } | |
3386 | break; | |
d3aaec8a | 3387 | case WLAN_CATEGORY_MESH_ACTION: |
9b395bc3 JB |
3388 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
3389 | sizeof(mgmt->u.action.u.mesh_action.action_code))) | |
3390 | break; | |
3391 | ||
77a121c3 JB |
3392 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
3393 | break; | |
25d49e4d | 3394 | if (mesh_action_is_path_sel(mgmt) && |
1df332e8 | 3395 | !mesh_path_sel_is_hwmp(sdata)) |
c7108a71 JC |
3396 | break; |
3397 | goto queue; | |
84040805 | 3398 | } |
026331c4 | 3399 | |
2e161f78 JB |
3400 | return RX_CONTINUE; |
3401 | ||
bed7ee6e | 3402 | invalid: |
554891e6 | 3403 | status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM; |
2e161f78 JB |
3404 | /* will return in the next handlers */ |
3405 | return RX_CONTINUE; | |
3406 | ||
3407 | handled: | |
3408 | if (rx->sta) | |
e5a9f8d0 | 3409 | rx->sta->rx_stats.packets++; |
2e161f78 JB |
3410 | dev_kfree_skb(rx->skb); |
3411 | return RX_QUEUED; | |
3412 | ||
3413 | queue: | |
2e161f78 JB |
3414 | skb_queue_tail(&sdata->skb_queue, rx->skb); |
3415 | ieee80211_queue_work(&local->hw, &sdata->work); | |
3416 | if (rx->sta) | |
e5a9f8d0 | 3417 | rx->sta->rx_stats.packets++; |
2e161f78 JB |
3418 | return RX_QUEUED; |
3419 | } | |
3420 | ||
3421 | static ieee80211_rx_result debug_noinline | |
3422 | ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx) | |
3423 | { | |
554891e6 | 3424 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
804483e9 | 3425 | int sig = 0; |
2e161f78 JB |
3426 | |
3427 | /* skip known-bad action frames and return them in the next handler */ | |
554891e6 | 3428 | if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) |
2e161f78 | 3429 | return RX_CONTINUE; |
d7907448 | 3430 | |
026331c4 JM |
3431 | /* |
3432 | * Getting here means the kernel doesn't know how to handle | |
3433 | * it, but maybe userspace does ... include returned frames | |
3434 | * so userspace can register for those to know whether ones | |
3435 | * it transmitted were processed or returned. | |
3436 | */ | |
026331c4 | 3437 | |
1ad22fb5 T |
3438 | if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) && |
3439 | !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) | |
804483e9 JB |
3440 | sig = status->signal; |
3441 | ||
e76fede8 TP |
3442 | if (cfg80211_rx_mgmt_khz(&rx->sdata->wdev, |
3443 | ieee80211_rx_status_to_khz(status), sig, | |
3444 | rx->skb->data, rx->skb->len, 0)) { | |
2e161f78 | 3445 | if (rx->sta) |
e5a9f8d0 | 3446 | rx->sta->rx_stats.packets++; |
2e161f78 JB |
3447 | dev_kfree_skb(rx->skb); |
3448 | return RX_QUEUED; | |
3449 | } | |
3450 | ||
2e161f78 JB |
3451 | return RX_CONTINUE; |
3452 | } | |
3453 | ||
1ea02224 JB |
3454 | static ieee80211_rx_result debug_noinline |
3455 | ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx) | |
3456 | { | |
3457 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
3458 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; | |
3459 | int len = rx->skb->len; | |
3460 | ||
3461 | if (!ieee80211_is_action(mgmt->frame_control)) | |
3462 | return RX_CONTINUE; | |
3463 | ||
3464 | switch (mgmt->u.action.category) { | |
3465 | case WLAN_CATEGORY_SA_QUERY: | |
3466 | if (len < (IEEE80211_MIN_ACTION_SIZE + | |
3467 | sizeof(mgmt->u.action.u.sa_query))) | |
3468 | break; | |
3469 | ||
3470 | switch (mgmt->u.action.u.sa_query.action) { | |
3471 | case WLAN_ACTION_SA_QUERY_REQUEST: | |
3472 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
3473 | break; | |
3474 | ieee80211_process_sa_query_req(sdata, mgmt, len); | |
3475 | goto handled; | |
3476 | } | |
3477 | break; | |
3478 | } | |
3479 | ||
3480 | return RX_CONTINUE; | |
3481 | ||
3482 | handled: | |
3483 | if (rx->sta) | |
3484 | rx->sta->rx_stats.packets++; | |
3485 | dev_kfree_skb(rx->skb); | |
3486 | return RX_QUEUED; | |
3487 | } | |
3488 | ||
2e161f78 JB |
3489 | static ieee80211_rx_result debug_noinline |
3490 | ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx) | |
3491 | { | |
3492 | struct ieee80211_local *local = rx->local; | |
3493 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; | |
3494 | struct sk_buff *nskb; | |
3495 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
554891e6 | 3496 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
2e161f78 JB |
3497 | |
3498 | if (!ieee80211_is_action(mgmt->frame_control)) | |
3499 | return RX_CONTINUE; | |
3500 | ||
3501 | /* | |
3502 | * For AP mode, hostapd is responsible for handling any action | |
3503 | * frames that we didn't handle, including returning unknown | |
3504 | * ones. For all other modes we will return them to the sender, | |
3505 | * setting the 0x80 bit in the action category, as required by | |
4b5ebccc | 3506 | * 802.11-2012 9.24.4. |
2e161f78 JB |
3507 | * Newer versions of hostapd shall also use the management frame |
3508 | * registration mechanisms, but older ones still use cooked | |
3509 | * monitor interfaces so push all frames there. | |
3510 | */ | |
554891e6 | 3511 | if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) && |
2e161f78 JB |
3512 | (sdata->vif.type == NL80211_IFTYPE_AP || |
3513 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) | |
3514 | return RX_DROP_MONITOR; | |
026331c4 | 3515 | |
4b5ebccc JB |
3516 | if (is_multicast_ether_addr(mgmt->da)) |
3517 | return RX_DROP_MONITOR; | |
3518 | ||
84040805 JB |
3519 | /* do not return rejected action frames */ |
3520 | if (mgmt->u.action.category & 0x80) | |
3521 | return RX_DROP_UNUSABLE; | |
3522 | ||
3523 | nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0, | |
3524 | GFP_ATOMIC); | |
3525 | if (nskb) { | |
292b4df6 | 3526 | struct ieee80211_mgmt *nmgmt = (void *)nskb->data; |
84040805 | 3527 | |
292b4df6 JL |
3528 | nmgmt->u.action.category |= 0x80; |
3529 | memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN); | |
3530 | memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN); | |
84040805 JB |
3531 | |
3532 | memset(nskb->cb, 0, sizeof(nskb->cb)); | |
3533 | ||
07e5a5f5 JB |
3534 | if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) { |
3535 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb); | |
3536 | ||
3537 | info->flags = IEEE80211_TX_CTL_TX_OFFCHAN | | |
3538 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK | | |
3539 | IEEE80211_TX_CTL_NO_CCK_RATE; | |
30686bf7 | 3540 | if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) |
07e5a5f5 JB |
3541 | info->hw_queue = |
3542 | local->hw.offchannel_tx_hw_queue; | |
3543 | } | |
3544 | ||
3545 | __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, | |
08aca29a | 3546 | status->band); |
de1ede7a | 3547 | } |
39192c0b JB |
3548 | dev_kfree_skb(rx->skb); |
3549 | return RX_QUEUED; | |
de1ede7a JB |
3550 | } |
3551 | ||
09a740ce TP |
3552 | static ieee80211_rx_result debug_noinline |
3553 | ieee80211_rx_h_ext(struct ieee80211_rx_data *rx) | |
3554 | { | |
3555 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
3556 | struct ieee80211_hdr *hdr = (void *)rx->skb->data; | |
3557 | ||
3558 | if (!ieee80211_is_ext(hdr->frame_control)) | |
3559 | return RX_CONTINUE; | |
3560 | ||
3561 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
3562 | return RX_DROP_MONITOR; | |
3563 | ||
3564 | /* for now only beacons are ext, so queue them */ | |
3565 | skb_queue_tail(&sdata->skb_queue, rx->skb); | |
3566 | ieee80211_queue_work(&rx->local->hw, &sdata->work); | |
3567 | if (rx->sta) | |
3568 | rx->sta->rx_stats.packets++; | |
3569 | ||
3570 | return RX_QUEUED; | |
3571 | } | |
3572 | ||
49461622 | 3573 | static ieee80211_rx_result debug_noinline |
5cf121c3 | 3574 | ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx) |
571ecf67 | 3575 | { |
eb9fb5b8 | 3576 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
77a121c3 JB |
3577 | struct ieee80211_mgmt *mgmt = (void *)rx->skb->data; |
3578 | __le16 stype; | |
571ecf67 | 3579 | |
77a121c3 | 3580 | stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE); |
472dbc45 | 3581 | |
77a121c3 JB |
3582 | if (!ieee80211_vif_is_mesh(&sdata->vif) && |
3583 | sdata->vif.type != NL80211_IFTYPE_ADHOC && | |
239281f8 | 3584 | sdata->vif.type != NL80211_IFTYPE_OCB && |
77a121c3 JB |
3585 | sdata->vif.type != NL80211_IFTYPE_STATION) |
3586 | return RX_DROP_MONITOR; | |
472dbc45 | 3587 | |
77a121c3 | 3588 | switch (stype) { |
66e67e41 | 3589 | case cpu_to_le16(IEEE80211_STYPE_AUTH): |
77a121c3 JB |
3590 | case cpu_to_le16(IEEE80211_STYPE_BEACON): |
3591 | case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP): | |
3592 | /* process for all: mesh, mlme, ibss */ | |
3593 | break; | |
95697f99 JB |
3594 | case cpu_to_le16(IEEE80211_STYPE_DEAUTH): |
3595 | if (is_multicast_ether_addr(mgmt->da) && | |
3596 | !is_broadcast_ether_addr(mgmt->da)) | |
3597 | return RX_DROP_MONITOR; | |
3598 | ||
3599 | /* process only for station/IBSS */ | |
3600 | if (sdata->vif.type != NL80211_IFTYPE_STATION && | |
3601 | sdata->vif.type != NL80211_IFTYPE_ADHOC) | |
3602 | return RX_DROP_MONITOR; | |
3603 | break; | |
66e67e41 JB |
3604 | case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP): |
3605 | case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP): | |
77a121c3 | 3606 | case cpu_to_le16(IEEE80211_STYPE_DISASSOC): |
2c31333a CL |
3607 | if (is_multicast_ether_addr(mgmt->da) && |
3608 | !is_broadcast_ether_addr(mgmt->da)) | |
3609 | return RX_DROP_MONITOR; | |
3610 | ||
77a121c3 JB |
3611 | /* process only for station */ |
3612 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
3613 | return RX_DROP_MONITOR; | |
3614 | break; | |
3615 | case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ): | |
9fb04b50 TP |
3616 | /* process only for ibss and mesh */ |
3617 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC && | |
3618 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT) | |
77a121c3 JB |
3619 | return RX_DROP_MONITOR; |
3620 | break; | |
3621 | default: | |
3622 | return RX_DROP_MONITOR; | |
3623 | } | |
f9d540ee | 3624 | |
77a121c3 JB |
3625 | /* queue up frame and kick off work to process it */ |
3626 | skb_queue_tail(&sdata->skb_queue, rx->skb); | |
3627 | ieee80211_queue_work(&rx->local->hw, &sdata->work); | |
8b58ff83 | 3628 | if (rx->sta) |
e5a9f8d0 | 3629 | rx->sta->rx_stats.packets++; |
46900298 | 3630 | |
77a121c3 | 3631 | return RX_QUEUED; |
571ecf67 JB |
3632 | } |
3633 | ||
5f0b7de5 JB |
3634 | static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx, |
3635 | struct ieee80211_rate *rate) | |
3d30d949 MW |
3636 | { |
3637 | struct ieee80211_sub_if_data *sdata; | |
3638 | struct ieee80211_local *local = rx->local; | |
3d30d949 MW |
3639 | struct sk_buff *skb = rx->skb, *skb2; |
3640 | struct net_device *prev_dev = NULL; | |
eb9fb5b8 | 3641 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
293702a3 | 3642 | int needed_headroom; |
3d30d949 | 3643 | |
554891e6 JB |
3644 | /* |
3645 | * If cooked monitor has been processed already, then | |
3646 | * don't do it again. If not, set the flag. | |
3647 | */ | |
3648 | if (rx->flags & IEEE80211_RX_CMNTR) | |
7c1e1831 | 3649 | goto out_free_skb; |
554891e6 | 3650 | rx->flags |= IEEE80211_RX_CMNTR; |
7c1e1831 | 3651 | |
152c477a JB |
3652 | /* If there are no cooked monitor interfaces, just free the SKB */ |
3653 | if (!local->cooked_mntrs) | |
3654 | goto out_free_skb; | |
3655 | ||
1f7bba79 JB |
3656 | /* vendor data is long removed here */ |
3657 | status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA; | |
293702a3 | 3658 | /* room for the radiotap header based on driver features */ |
1f7bba79 | 3659 | needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb); |
3d30d949 | 3660 | |
293702a3 JB |
3661 | if (skb_headroom(skb) < needed_headroom && |
3662 | pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) | |
3663 | goto out_free_skb; | |
3d30d949 | 3664 | |
293702a3 | 3665 | /* prepend radiotap information */ |
973ef21a FF |
3666 | ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom, |
3667 | false); | |
3d30d949 | 3668 | |
d57a544d | 3669 | skb_reset_mac_header(skb); |
3d30d949 MW |
3670 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
3671 | skb->pkt_type = PACKET_OTHERHOST; | |
3672 | skb->protocol = htons(ETH_P_802_2); | |
3673 | ||
3674 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
9607e6b6 | 3675 | if (!ieee80211_sdata_running(sdata)) |
3d30d949 MW |
3676 | continue; |
3677 | ||
05c914fe | 3678 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR || |
d8212184 | 3679 | !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)) |
3d30d949 MW |
3680 | continue; |
3681 | ||
3682 | if (prev_dev) { | |
3683 | skb2 = skb_clone(skb, GFP_ATOMIC); | |
3684 | if (skb2) { | |
3685 | skb2->dev = prev_dev; | |
5548a8a1 | 3686 | netif_receive_skb(skb2); |
3d30d949 MW |
3687 | } |
3688 | } | |
3689 | ||
3690 | prev_dev = sdata->dev; | |
36ec144f | 3691 | dev_sw_netstats_rx_add(sdata->dev, skb->len); |
3d30d949 MW |
3692 | } |
3693 | ||
3694 | if (prev_dev) { | |
3695 | skb->dev = prev_dev; | |
5548a8a1 | 3696 | netif_receive_skb(skb); |
554891e6 JB |
3697 | return; |
3698 | } | |
3d30d949 MW |
3699 | |
3700 | out_free_skb: | |
3701 | dev_kfree_skb(skb); | |
3702 | } | |
3703 | ||
aa0c8636 CL |
3704 | static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx, |
3705 | ieee80211_rx_result res) | |
3706 | { | |
3707 | switch (res) { | |
3708 | case RX_DROP_MONITOR: | |
3709 | I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); | |
3710 | if (rx->sta) | |
e5a9f8d0 | 3711 | rx->sta->rx_stats.dropped++; |
fc0561dc | 3712 | fallthrough; |
aa0c8636 CL |
3713 | case RX_CONTINUE: { |
3714 | struct ieee80211_rate *rate = NULL; | |
3715 | struct ieee80211_supported_band *sband; | |
3716 | struct ieee80211_rx_status *status; | |
3717 | ||
3718 | status = IEEE80211_SKB_RXCB((rx->skb)); | |
3719 | ||
3720 | sband = rx->local->hw.wiphy->bands[status->band]; | |
41cbb0f5 | 3721 | if (status->encoding == RX_ENC_LEGACY) |
aa0c8636 CL |
3722 | rate = &sband->bitrates[status->rate_idx]; |
3723 | ||
3724 | ieee80211_rx_cooked_monitor(rx, rate); | |
3725 | break; | |
3726 | } | |
3727 | case RX_DROP_UNUSABLE: | |
3728 | I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); | |
3729 | if (rx->sta) | |
e5a9f8d0 | 3730 | rx->sta->rx_stats.dropped++; |
aa0c8636 CL |
3731 | dev_kfree_skb(rx->skb); |
3732 | break; | |
3733 | case RX_QUEUED: | |
3734 | I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued); | |
3735 | break; | |
3736 | } | |
3737 | } | |
571ecf67 | 3738 | |
f9e124fb CL |
3739 | static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx, |
3740 | struct sk_buff_head *frames) | |
58905290 | 3741 | { |
58905290 | 3742 | ieee80211_rx_result res = RX_DROP_MONITOR; |
aa0c8636 | 3743 | struct sk_buff *skb; |
8944b79f | 3744 | |
e32f85f7 LCC |
3745 | #define CALL_RXH(rxh) \ |
3746 | do { \ | |
3747 | res = rxh(rx); \ | |
3748 | if (res != RX_CONTINUE) \ | |
2569a826 | 3749 | goto rxh_next; \ |
8ebaa5b0 | 3750 | } while (0) |
49461622 | 3751 | |
45ceeee8 JB |
3752 | /* Lock here to avoid hitting all of the data used in the RX |
3753 | * path (e.g. key data, station data, ...) concurrently when | |
3754 | * a frame is released from the reorder buffer due to timeout | |
3755 | * from the timer, potentially concurrently with RX from the | |
3756 | * driver. | |
3757 | */ | |
f9e124fb | 3758 | spin_lock_bh(&rx->local->rx_path_lock); |
24a8fdad | 3759 | |
f9e124fb | 3760 | while ((skb = __skb_dequeue(frames))) { |
2569a826 JB |
3761 | /* |
3762 | * all the other fields are valid across frames | |
3763 | * that belong to an aMPDU since they are on the | |
3764 | * same TID from the same station | |
3765 | */ | |
3766 | rx->skb = skb; | |
3767 | ||
8ebaa5b0 JB |
3768 | CALL_RXH(ieee80211_rx_h_check_more_data); |
3769 | CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll); | |
3770 | CALL_RXH(ieee80211_rx_h_sta_process); | |
3771 | CALL_RXH(ieee80211_rx_h_decrypt); | |
3772 | CALL_RXH(ieee80211_rx_h_defragment); | |
3773 | CALL_RXH(ieee80211_rx_h_michael_mic_verify); | |
2569a826 | 3774 | /* must be after MMIC verify so header is counted in MPDU mic */ |
bf94e17b | 3775 | #ifdef CONFIG_MAC80211_MESH |
aa0c8636 | 3776 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
2569a826 | 3777 | CALL_RXH(ieee80211_rx_h_mesh_fwding); |
bf94e17b | 3778 | #endif |
8ebaa5b0 JB |
3779 | CALL_RXH(ieee80211_rx_h_amsdu); |
3780 | CALL_RXH(ieee80211_rx_h_data); | |
f9e124fb CL |
3781 | |
3782 | /* special treatment -- needs the queue */ | |
3783 | res = ieee80211_rx_h_ctrl(rx, frames); | |
3784 | if (res != RX_CONTINUE) | |
3785 | goto rxh_next; | |
3786 | ||
8ebaa5b0 JB |
3787 | CALL_RXH(ieee80211_rx_h_mgmt_check); |
3788 | CALL_RXH(ieee80211_rx_h_action); | |
3789 | CALL_RXH(ieee80211_rx_h_userspace_mgmt); | |
1ea02224 | 3790 | CALL_RXH(ieee80211_rx_h_action_post_userspace); |
8ebaa5b0 | 3791 | CALL_RXH(ieee80211_rx_h_action_return); |
09a740ce | 3792 | CALL_RXH(ieee80211_rx_h_ext); |
8ebaa5b0 | 3793 | CALL_RXH(ieee80211_rx_h_mgmt); |
49461622 | 3794 | |
aa0c8636 CL |
3795 | rxh_next: |
3796 | ieee80211_rx_handlers_result(rx, res); | |
f9e124fb | 3797 | |
49461622 | 3798 | #undef CALL_RXH |
aa0c8636 | 3799 | } |
24a8fdad | 3800 | |
f9e124fb | 3801 | spin_unlock_bh(&rx->local->rx_path_lock); |
aa0c8636 CL |
3802 | } |
3803 | ||
4406c376 | 3804 | static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx) |
aa0c8636 | 3805 | { |
f9e124fb | 3806 | struct sk_buff_head reorder_release; |
aa0c8636 CL |
3807 | ieee80211_rx_result res = RX_DROP_MONITOR; |
3808 | ||
f9e124fb CL |
3809 | __skb_queue_head_init(&reorder_release); |
3810 | ||
aa0c8636 CL |
3811 | #define CALL_RXH(rxh) \ |
3812 | do { \ | |
3813 | res = rxh(rx); \ | |
3814 | if (res != RX_CONTINUE) \ | |
3815 | goto rxh_next; \ | |
8ebaa5b0 | 3816 | } while (0) |
aa0c8636 | 3817 | |
8ebaa5b0 JB |
3818 | CALL_RXH(ieee80211_rx_h_check_dup); |
3819 | CALL_RXH(ieee80211_rx_h_check); | |
aa0c8636 | 3820 | |
f9e124fb | 3821 | ieee80211_rx_reorder_ampdu(rx, &reorder_release); |
aa0c8636 | 3822 | |
f9e124fb | 3823 | ieee80211_rx_handlers(rx, &reorder_release); |
aa0c8636 | 3824 | return; |
49461622 | 3825 | |
2569a826 | 3826 | rxh_next: |
aa0c8636 CL |
3827 | ieee80211_rx_handlers_result(rx, res); |
3828 | ||
3829 | #undef CALL_RXH | |
58905290 JB |
3830 | } |
3831 | ||
2bff8ebf | 3832 | /* |
dd318575 JB |
3833 | * This function makes calls into the RX path, therefore |
3834 | * it has to be invoked under RCU read lock. | |
2bff8ebf CL |
3835 | */ |
3836 | void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid) | |
3837 | { | |
f9e124fb | 3838 | struct sk_buff_head frames; |
554891e6 JB |
3839 | struct ieee80211_rx_data rx = { |
3840 | .sta = sta, | |
3841 | .sdata = sta->sdata, | |
3842 | .local = sta->local, | |
9e26297a JB |
3843 | /* This is OK -- must be QoS data frame */ |
3844 | .security_idx = tid, | |
3845 | .seqno_idx = tid, | |
554891e6 | 3846 | }; |
2c15a0cf CL |
3847 | struct tid_ampdu_rx *tid_agg_rx; |
3848 | ||
3849 | tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); | |
3850 | if (!tid_agg_rx) | |
3851 | return; | |
2bff8ebf | 3852 | |
f9e124fb CL |
3853 | __skb_queue_head_init(&frames); |
3854 | ||
2c15a0cf | 3855 | spin_lock(&tid_agg_rx->reorder_lock); |
f9e124fb | 3856 | ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames); |
2c15a0cf | 3857 | spin_unlock(&tid_agg_rx->reorder_lock); |
2bff8ebf | 3858 | |
b497de63 EG |
3859 | if (!skb_queue_empty(&frames)) { |
3860 | struct ieee80211_event event = { | |
3861 | .type = BA_FRAME_TIMEOUT, | |
3862 | .u.ba.tid = tid, | |
3863 | .u.ba.sta = &sta->sta, | |
3864 | }; | |
3865 | drv_event_callback(rx.local, rx.sdata, &event); | |
3866 | } | |
3867 | ||
f9e124fb | 3868 | ieee80211_rx_handlers(&rx, &frames); |
2bff8ebf CL |
3869 | } |
3870 | ||
06470f74 SS |
3871 | void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid, |
3872 | u16 ssn, u64 filtered, | |
3873 | u16 received_mpdus) | |
3874 | { | |
3875 | struct sta_info *sta; | |
3876 | struct tid_ampdu_rx *tid_agg_rx; | |
3877 | struct sk_buff_head frames; | |
3878 | struct ieee80211_rx_data rx = { | |
3879 | /* This is OK -- must be QoS data frame */ | |
3880 | .security_idx = tid, | |
3881 | .seqno_idx = tid, | |
3882 | }; | |
3883 | int i, diff; | |
3884 | ||
3885 | if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS)) | |
3886 | return; | |
3887 | ||
3888 | __skb_queue_head_init(&frames); | |
3889 | ||
3890 | sta = container_of(pubsta, struct sta_info, sta); | |
3891 | ||
3892 | rx.sta = sta; | |
3893 | rx.sdata = sta->sdata; | |
3894 | rx.local = sta->local; | |
3895 | ||
3896 | rcu_read_lock(); | |
3897 | tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); | |
3898 | if (!tid_agg_rx) | |
3899 | goto out; | |
3900 | ||
3901 | spin_lock_bh(&tid_agg_rx->reorder_lock); | |
3902 | ||
3903 | if (received_mpdus >= IEEE80211_SN_MODULO >> 1) { | |
3904 | int release; | |
3905 | ||
3906 | /* release all frames in the reorder buffer */ | |
3907 | release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) % | |
3908 | IEEE80211_SN_MODULO; | |
3909 | ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, | |
3910 | release, &frames); | |
3911 | /* update ssn to match received ssn */ | |
3912 | tid_agg_rx->head_seq_num = ssn; | |
3913 | } else { | |
3914 | ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn, | |
3915 | &frames); | |
3916 | } | |
3917 | ||
3918 | /* handle the case that received ssn is behind the mac ssn. | |
3919 | * it can be tid_agg_rx->buf_size behind and still be valid */ | |
3920 | diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK; | |
3921 | if (diff >= tid_agg_rx->buf_size) { | |
3922 | tid_agg_rx->reorder_buf_filtered = 0; | |
3923 | goto release; | |
3924 | } | |
3925 | filtered = filtered >> diff; | |
3926 | ssn += diff; | |
3927 | ||
3928 | /* update bitmap */ | |
3929 | for (i = 0; i < tid_agg_rx->buf_size; i++) { | |
3930 | int index = (ssn + i) % tid_agg_rx->buf_size; | |
3931 | ||
3932 | tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index); | |
3933 | if (filtered & BIT_ULL(i)) | |
3934 | tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index); | |
3935 | } | |
3936 | ||
3937 | /* now process also frames that the filter marking released */ | |
3938 | ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames); | |
3939 | ||
3940 | release: | |
3941 | spin_unlock_bh(&tid_agg_rx->reorder_lock); | |
3942 | ||
3943 | ieee80211_rx_handlers(&rx, &frames); | |
3944 | ||
3945 | out: | |
3946 | rcu_read_unlock(); | |
3947 | } | |
3948 | EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames); | |
3949 | ||
571ecf67 JB |
3950 | /* main receive path */ |
3951 | ||
a58fbe1a | 3952 | static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) |
23a24def | 3953 | { |
20b01f80 | 3954 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
eb9fb5b8 | 3955 | struct sk_buff *skb = rx->skb; |
a58fbe1a | 3956 | struct ieee80211_hdr *hdr = (void *)skb->data; |
eb9fb5b8 JB |
3957 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
3958 | u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); | |
09a740ce TP |
3959 | bool multicast = is_multicast_ether_addr(hdr->addr1) || |
3960 | ieee80211_is_s1g_beacon(hdr->frame_control); | |
23a24def | 3961 | |
51fb61e7 | 3962 | switch (sdata->vif.type) { |
05c914fe | 3963 | case NL80211_IFTYPE_STATION: |
9bc383de | 3964 | if (!bssid && !sdata->u.mgd.use_4addr) |
3c2723f5 | 3965 | return false; |
588f7d39 JB |
3966 | if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta) |
3967 | return false; | |
a58fbe1a JB |
3968 | if (multicast) |
3969 | return true; | |
3970 | return ether_addr_equal(sdata->vif.addr, hdr->addr1); | |
05c914fe | 3971 | case NL80211_IFTYPE_ADHOC: |
23a24def | 3972 | if (!bssid) |
3c2723f5 | 3973 | return false; |
6329b8d9 FF |
3974 | if (ether_addr_equal(sdata->vif.addr, hdr->addr2) || |
3975 | ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2)) | |
3c2723f5 | 3976 | return false; |
a58fbe1a | 3977 | if (ieee80211_is_beacon(hdr->frame_control)) |
3c2723f5 | 3978 | return true; |
a58fbe1a | 3979 | if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) |
3c2723f5 | 3980 | return false; |
a58fbe1a JB |
3981 | if (!multicast && |
3982 | !ether_addr_equal(sdata->vif.addr, hdr->addr1)) | |
df140465 | 3983 | return false; |
a58fbe1a | 3984 | if (!rx->sta) { |
0fb8ca45 | 3985 | int rate_idx; |
da6a4352 | 3986 | if (status->encoding != RX_ENC_LEGACY) |
5614618e | 3987 | rate_idx = 0; /* TODO: HT/VHT rates */ |
0fb8ca45 | 3988 | else |
eb9fb5b8 | 3989 | rate_idx = status->rate_idx; |
8bf11d8d JB |
3990 | ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2, |
3991 | BIT(rate_idx)); | |
0fb8ca45 | 3992 | } |
a58fbe1a | 3993 | return true; |
239281f8 RL |
3994 | case NL80211_IFTYPE_OCB: |
3995 | if (!bssid) | |
3996 | return false; | |
cc117298 | 3997 | if (!ieee80211_is_data_present(hdr->frame_control)) |
239281f8 | 3998 | return false; |
a58fbe1a | 3999 | if (!is_broadcast_ether_addr(bssid)) |
239281f8 | 4000 | return false; |
a58fbe1a JB |
4001 | if (!multicast && |
4002 | !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1)) | |
df140465 | 4003 | return false; |
a58fbe1a | 4004 | if (!rx->sta) { |
239281f8 | 4005 | int rate_idx; |
da6a4352 | 4006 | if (status->encoding != RX_ENC_LEGACY) |
239281f8 RL |
4007 | rate_idx = 0; /* TODO: HT rates */ |
4008 | else | |
4009 | rate_idx = status->rate_idx; | |
4010 | ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2, | |
4011 | BIT(rate_idx)); | |
4012 | } | |
a58fbe1a | 4013 | return true; |
05c914fe | 4014 | case NL80211_IFTYPE_MESH_POINT: |
736a80bb JB |
4015 | if (ether_addr_equal(sdata->vif.addr, hdr->addr2)) |
4016 | return false; | |
a58fbe1a JB |
4017 | if (multicast) |
4018 | return true; | |
4019 | return ether_addr_equal(sdata->vif.addr, hdr->addr1); | |
05c914fe JB |
4020 | case NL80211_IFTYPE_AP_VLAN: |
4021 | case NL80211_IFTYPE_AP: | |
a58fbe1a JB |
4022 | if (!bssid) |
4023 | return ether_addr_equal(sdata->vif.addr, hdr->addr1); | |
4024 | ||
4025 | if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) { | |
3df6eaea JB |
4026 | /* |
4027 | * Accept public action frames even when the | |
4028 | * BSSID doesn't match, this is used for P2P | |
4029 | * and location updates. Note that mac80211 | |
4030 | * itself never looks at these frames. | |
4031 | */ | |
2b9ccd4e JB |
4032 | if (!multicast && |
4033 | !ether_addr_equal(sdata->vif.addr, hdr->addr1)) | |
3c2723f5 | 4034 | return false; |
d48b2968 | 4035 | if (ieee80211_is_public_action(hdr, skb->len)) |
3c2723f5 | 4036 | return true; |
5c90067c | 4037 | return ieee80211_is_beacon(hdr->frame_control); |
a58fbe1a JB |
4038 | } |
4039 | ||
4040 | if (!ieee80211_has_tods(hdr->frame_control)) { | |
db8e1732 AN |
4041 | /* ignore data frames to TDLS-peers */ |
4042 | if (ieee80211_is_data(hdr->frame_control)) | |
4043 | return false; | |
4044 | /* ignore action frames to TDLS-peers */ | |
4045 | if (ieee80211_is_action(hdr->frame_control) && | |
1ec7bae8 | 4046 | !is_broadcast_ether_addr(bssid) && |
db8e1732 AN |
4047 | !ether_addr_equal(bssid, hdr->addr1)) |
4048 | return false; | |
23a24def | 4049 | } |
3018e947 JB |
4050 | |
4051 | /* | |
4052 | * 802.11-2016 Table 9-26 says that for data frames, A1 must be | |
4053 | * the BSSID - we've checked that already but may have accepted | |
4054 | * the wildcard (ff:ff:ff:ff:ff:ff). | |
4055 | * | |
4056 | * It also says: | |
4057 | * The BSSID of the Data frame is determined as follows: | |
4058 | * a) If the STA is contained within an AP or is associated | |
4059 | * with an AP, the BSSID is the address currently in use | |
4060 | * by the STA contained in the AP. | |
4061 | * | |
4062 | * So we should not accept data frames with an address that's | |
4063 | * multicast. | |
4064 | * | |
4065 | * Accepting it also opens a security problem because stations | |
4066 | * could encrypt it with the GTK and inject traffic that way. | |
4067 | */ | |
4068 | if (ieee80211_is_data(hdr->frame_control) && multicast) | |
4069 | return false; | |
4070 | ||
a58fbe1a | 4071 | return true; |
f142c6b9 | 4072 | case NL80211_IFTYPE_P2P_DEVICE: |
a58fbe1a JB |
4073 | return ieee80211_is_public_action(hdr, skb->len) || |
4074 | ieee80211_is_probe_req(hdr->frame_control) || | |
4075 | ieee80211_is_probe_resp(hdr->frame_control) || | |
4076 | ieee80211_is_beacon(hdr->frame_control); | |
cb3b7d87 AB |
4077 | case NL80211_IFTYPE_NAN: |
4078 | /* Currently no frames on NAN interface are allowed */ | |
4079 | return false; | |
2ca27bcf | 4080 | default: |
fb1c1cd6 | 4081 | break; |
23a24def JB |
4082 | } |
4083 | ||
a58fbe1a JB |
4084 | WARN_ON_ONCE(1); |
4085 | return false; | |
23a24def JB |
4086 | } |
4087 | ||
49ddf8e6 JB |
4088 | void ieee80211_check_fast_rx(struct sta_info *sta) |
4089 | { | |
4090 | struct ieee80211_sub_if_data *sdata = sta->sdata; | |
4091 | struct ieee80211_local *local = sdata->local; | |
4092 | struct ieee80211_key *key; | |
4093 | struct ieee80211_fast_rx fastrx = { | |
4094 | .dev = sdata->dev, | |
4095 | .vif_type = sdata->vif.type, | |
4096 | .control_port_protocol = sdata->control_port_protocol, | |
4097 | }, *old, *new = NULL; | |
80a915ec | 4098 | bool set_offload = false; |
49ddf8e6 | 4099 | bool assign = false; |
80a915ec | 4100 | bool offload; |
49ddf8e6 JB |
4101 | |
4102 | /* use sparse to check that we don't return without updating */ | |
4103 | __acquire(check_fast_rx); | |
4104 | ||
4105 | BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header)); | |
4106 | BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN); | |
4107 | ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header); | |
4108 | ether_addr_copy(fastrx.vif_addr, sdata->vif.addr); | |
4109 | ||
c9c5962b JB |
4110 | fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS); |
4111 | ||
49ddf8e6 JB |
4112 | /* fast-rx doesn't do reordering */ |
4113 | if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) && | |
4114 | !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER)) | |
4115 | goto clear; | |
4116 | ||
4117 | switch (sdata->vif.type) { | |
4118 | case NL80211_IFTYPE_STATION: | |
49ddf8e6 JB |
4119 | if (sta->sta.tdls) { |
4120 | fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1); | |
4121 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2); | |
4122 | fastrx.expected_ds_bits = 0; | |
4123 | } else { | |
49ddf8e6 JB |
4124 | fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1); |
4125 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3); | |
4126 | fastrx.expected_ds_bits = | |
4127 | cpu_to_le16(IEEE80211_FCTL_FROMDS); | |
4128 | } | |
1d870162 | 4129 | |
9251a473 FF |
4130 | if (sdata->u.mgd.use_4addr && !sta->sta.tdls) { |
4131 | fastrx.expected_ds_bits |= | |
4132 | cpu_to_le16(IEEE80211_FCTL_TODS); | |
4133 | fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3); | |
4134 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4); | |
4135 | } | |
4136 | ||
1d870162 FF |
4137 | if (!sdata->u.mgd.powersave) |
4138 | break; | |
4139 | ||
4140 | /* software powersave is a huge mess, avoid all of it */ | |
4141 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) | |
4142 | goto clear; | |
4143 | if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) && | |
4144 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) | |
4145 | goto clear; | |
49ddf8e6 JB |
4146 | break; |
4147 | case NL80211_IFTYPE_AP_VLAN: | |
4148 | case NL80211_IFTYPE_AP: | |
4149 | /* parallel-rx requires this, at least with calls to | |
4150 | * ieee80211_sta_ps_transition() | |
4151 | */ | |
4152 | if (!ieee80211_hw_check(&local->hw, AP_LINK_PS)) | |
4153 | goto clear; | |
4154 | fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3); | |
4155 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2); | |
4156 | fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS); | |
4157 | ||
4158 | fastrx.internal_forward = | |
4159 | !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) && | |
4160 | (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || | |
4161 | !sdata->u.vlan.sta); | |
59cae5b9 FF |
4162 | |
4163 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | |
4164 | sdata->u.vlan.sta) { | |
4165 | fastrx.expected_ds_bits |= | |
4166 | cpu_to_le16(IEEE80211_FCTL_FROMDS); | |
4167 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4); | |
4168 | fastrx.internal_forward = 0; | |
4169 | } | |
4170 | ||
49ddf8e6 JB |
4171 | break; |
4172 | default: | |
4173 | goto clear; | |
4174 | } | |
4175 | ||
4176 | if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
4177 | goto clear; | |
4178 | ||
4179 | rcu_read_lock(); | |
4180 | key = rcu_dereference(sta->ptk[sta->ptk_idx]); | |
622d3b4e FF |
4181 | if (!key) |
4182 | key = rcu_dereference(sdata->default_unicast_key); | |
49ddf8e6 JB |
4183 | if (key) { |
4184 | switch (key->conf.cipher) { | |
4185 | case WLAN_CIPHER_SUITE_TKIP: | |
4186 | /* we don't want to deal with MMIC in fast-rx */ | |
4187 | goto clear_rcu; | |
4188 | case WLAN_CIPHER_SUITE_CCMP: | |
4189 | case WLAN_CIPHER_SUITE_CCMP_256: | |
4190 | case WLAN_CIPHER_SUITE_GCMP: | |
4191 | case WLAN_CIPHER_SUITE_GCMP_256: | |
4192 | break; | |
4193 | default: | |
96fc6efb AW |
4194 | /* We also don't want to deal with |
4195 | * WEP or cipher scheme. | |
49ddf8e6 JB |
4196 | */ |
4197 | goto clear_rcu; | |
4198 | } | |
4199 | ||
4200 | fastrx.key = true; | |
4201 | fastrx.icv_len = key->conf.icv_len; | |
4202 | } | |
4203 | ||
4204 | assign = true; | |
4205 | clear_rcu: | |
4206 | rcu_read_unlock(); | |
4207 | clear: | |
4208 | __release(check_fast_rx); | |
4209 | ||
4210 | if (assign) | |
4211 | new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL); | |
4212 | ||
80a915ec FF |
4213 | offload = assign && |
4214 | (sdata->vif.offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED); | |
4215 | ||
4216 | if (offload) | |
4217 | set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD); | |
4218 | else | |
4219 | set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD); | |
4220 | ||
4221 | if (set_offload) | |
4222 | drv_sta_set_decap_offload(local, sdata, &sta->sta, assign); | |
4223 | ||
49ddf8e6 JB |
4224 | spin_lock_bh(&sta->lock); |
4225 | old = rcu_dereference_protected(sta->fast_rx, true); | |
4226 | rcu_assign_pointer(sta->fast_rx, new); | |
4227 | spin_unlock_bh(&sta->lock); | |
4228 | ||
4229 | if (old) | |
4230 | kfree_rcu(old, rcu_head); | |
4231 | } | |
4232 | ||
4233 | void ieee80211_clear_fast_rx(struct sta_info *sta) | |
4234 | { | |
4235 | struct ieee80211_fast_rx *old; | |
4236 | ||
4237 | spin_lock_bh(&sta->lock); | |
4238 | old = rcu_dereference_protected(sta->fast_rx, true); | |
4239 | RCU_INIT_POINTER(sta->fast_rx, NULL); | |
4240 | spin_unlock_bh(&sta->lock); | |
4241 | ||
4242 | if (old) | |
4243 | kfree_rcu(old, rcu_head); | |
4244 | } | |
4245 | ||
4246 | void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata) | |
4247 | { | |
4248 | struct ieee80211_local *local = sdata->local; | |
4249 | struct sta_info *sta; | |
4250 | ||
4251 | lockdep_assert_held(&local->sta_mtx); | |
4252 | ||
253216ff | 4253 | list_for_each_entry(sta, &local->sta_list, list) { |
49ddf8e6 JB |
4254 | if (sdata != sta->sdata && |
4255 | (!sta->sdata->bss || sta->sdata->bss != sdata->bss)) | |
4256 | continue; | |
4257 | ieee80211_check_fast_rx(sta); | |
4258 | } | |
4259 | } | |
4260 | ||
4261 | void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata) | |
4262 | { | |
4263 | struct ieee80211_local *local = sdata->local; | |
4264 | ||
4265 | mutex_lock(&local->sta_mtx); | |
4266 | __ieee80211_check_fast_rx_iface(sdata); | |
4267 | mutex_unlock(&local->sta_mtx); | |
4268 | } | |
4269 | ||
80a915ec FF |
4270 | static void ieee80211_rx_8023(struct ieee80211_rx_data *rx, |
4271 | struct ieee80211_fast_rx *fast_rx, | |
4272 | int orig_len) | |
4273 | { | |
4274 | struct ieee80211_sta_rx_stats *stats; | |
4275 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | |
4276 | struct sta_info *sta = rx->sta; | |
4277 | struct sk_buff *skb = rx->skb; | |
4278 | void *sa = skb->data + ETH_ALEN; | |
4279 | void *da = skb->data; | |
4280 | ||
4281 | stats = &sta->rx_stats; | |
4282 | if (fast_rx->uses_rss) | |
4283 | stats = this_cpu_ptr(sta->pcpu_rx_stats); | |
4284 | ||
4285 | /* statistics part of ieee80211_rx_h_sta_process() */ | |
4286 | if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { | |
4287 | stats->last_signal = status->signal; | |
4288 | if (!fast_rx->uses_rss) | |
4289 | ewma_signal_add(&sta->rx_stats_avg.signal, | |
4290 | -status->signal); | |
4291 | } | |
4292 | ||
4293 | if (status->chains) { | |
4294 | int i; | |
4295 | ||
4296 | stats->chains = status->chains; | |
4297 | for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) { | |
4298 | int signal = status->chain_signal[i]; | |
4299 | ||
4300 | if (!(status->chains & BIT(i))) | |
4301 | continue; | |
4302 | ||
4303 | stats->chain_signal_last[i] = signal; | |
4304 | if (!fast_rx->uses_rss) | |
4305 | ewma_signal_add(&sta->rx_stats_avg.chain_signal[i], | |
4306 | -signal); | |
4307 | } | |
4308 | } | |
4309 | /* end of statistics */ | |
4310 | ||
4311 | stats->last_rx = jiffies; | |
4312 | stats->last_rate = sta_stats_encode_rate(status); | |
4313 | ||
4314 | stats->fragments++; | |
4315 | stats->packets++; | |
4316 | ||
4317 | skb->dev = fast_rx->dev; | |
4318 | ||
4319 | dev_sw_netstats_rx_add(fast_rx->dev, skb->len); | |
4320 | ||
4321 | /* The seqno index has the same property as needed | |
4322 | * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS | |
4323 | * for non-QoS-data frames. Here we know it's a data | |
4324 | * frame, so count MSDUs. | |
4325 | */ | |
4326 | u64_stats_update_begin(&stats->syncp); | |
4327 | stats->msdu[rx->seqno_idx]++; | |
4328 | stats->bytes += orig_len; | |
4329 | u64_stats_update_end(&stats->syncp); | |
4330 | ||
4331 | if (fast_rx->internal_forward) { | |
4332 | struct sk_buff *xmit_skb = NULL; | |
4333 | if (is_multicast_ether_addr(da)) { | |
4334 | xmit_skb = skb_copy(skb, GFP_ATOMIC); | |
4335 | } else if (!ether_addr_equal(da, sa) && | |
4336 | sta_info_get(rx->sdata, da)) { | |
4337 | xmit_skb = skb; | |
4338 | skb = NULL; | |
4339 | } | |
4340 | ||
4341 | if (xmit_skb) { | |
4342 | /* | |
4343 | * Send to wireless media and increase priority by 256 | |
4344 | * to keep the received priority instead of | |
4345 | * reclassifying the frame (see cfg80211_classify8021d). | |
4346 | */ | |
4347 | xmit_skb->priority += 256; | |
4348 | xmit_skb->protocol = htons(ETH_P_802_3); | |
4349 | skb_reset_network_header(xmit_skb); | |
4350 | skb_reset_mac_header(xmit_skb); | |
4351 | dev_queue_xmit(xmit_skb); | |
4352 | } | |
4353 | ||
4354 | if (!skb) | |
4355 | return; | |
4356 | } | |
4357 | ||
4358 | /* deliver to local stack */ | |
4359 | skb->protocol = eth_type_trans(skb, fast_rx->dev); | |
4360 | memset(skb->cb, 0, sizeof(skb->cb)); | |
4361 | if (rx->list) | |
4362 | list_add_tail(&skb->list, rx->list); | |
4363 | else | |
4364 | netif_receive_skb(skb); | |
4365 | ||
4366 | } | |
4367 | ||
49ddf8e6 JB |
4368 | static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx, |
4369 | struct ieee80211_fast_rx *fast_rx) | |
4370 | { | |
4371 | struct sk_buff *skb = rx->skb; | |
4372 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
4373 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | |
4374 | struct sta_info *sta = rx->sta; | |
4375 | int orig_len = skb->len; | |
24bba078 FF |
4376 | int hdrlen = ieee80211_hdrlen(hdr->frame_control); |
4377 | int snap_offs = hdrlen; | |
49ddf8e6 JB |
4378 | struct { |
4379 | u8 snap[sizeof(rfc1042_header)]; | |
4380 | __be16 proto; | |
4381 | } *payload __aligned(2); | |
4382 | struct { | |
4383 | u8 da[ETH_ALEN]; | |
4384 | u8 sa[ETH_ALEN]; | |
4385 | } addrs __aligned(2); | |
c9c5962b JB |
4386 | struct ieee80211_sta_rx_stats *stats = &sta->rx_stats; |
4387 | ||
49ddf8e6 JB |
4388 | /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write |
4389 | * to a common data structure; drivers can implement that per queue | |
4390 | * but we don't have that information in mac80211 | |
4391 | */ | |
4392 | if (!(status->flag & RX_FLAG_DUP_VALIDATED)) | |
4393 | return false; | |
4394 | ||
4395 | #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED) | |
4396 | ||
4397 | /* If using encryption, we also need to have: | |
4398 | * - PN_VALIDATED: similar, but the implementation is tricky | |
4399 | * - DECRYPTED: necessary for PN_VALIDATED | |
4400 | */ | |
4401 | if (fast_rx->key && | |
4402 | (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS) | |
4403 | return false; | |
4404 | ||
49ddf8e6 JB |
4405 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) |
4406 | return false; | |
4407 | ||
4408 | if (unlikely(ieee80211_is_frag(hdr))) | |
4409 | return false; | |
4410 | ||
4411 | /* Since our interface address cannot be multicast, this | |
4412 | * implicitly also rejects multicast frames without the | |
4413 | * explicit check. | |
4414 | * | |
4415 | * We shouldn't get any *data* frames not addressed to us | |
4416 | * (AP mode will accept multicast *management* frames), but | |
4417 | * punting here will make it go through the full checks in | |
4418 | * ieee80211_accept_frame(). | |
4419 | */ | |
4420 | if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1)) | |
4421 | return false; | |
4422 | ||
4423 | if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS | | |
4424 | IEEE80211_FCTL_TODS)) != | |
4425 | fast_rx->expected_ds_bits) | |
b323ac19 | 4426 | return false; |
49ddf8e6 JB |
4427 | |
4428 | /* assign the key to drop unencrypted frames (later) | |
4429 | * and strip the IV/MIC if necessary | |
4430 | */ | |
4431 | if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) { | |
4432 | /* GCMP header length is the same */ | |
4433 | snap_offs += IEEE80211_CCMP_HDR_LEN; | |
4434 | } | |
4435 | ||
24bba078 FF |
4436 | if (!(status->rx_flags & IEEE80211_RX_AMSDU)) { |
4437 | if (!pskb_may_pull(skb, snap_offs + sizeof(*payload))) | |
4438 | goto drop; | |
49ddf8e6 | 4439 | |
24bba078 | 4440 | payload = (void *)(skb->data + snap_offs); |
49ddf8e6 | 4441 | |
24bba078 FF |
4442 | if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr)) |
4443 | return false; | |
4444 | ||
4445 | /* Don't handle these here since they require special code. | |
4446 | * Accept AARP and IPX even though they should come with a | |
4447 | * bridge-tunnel header - but if we get them this way then | |
4448 | * there's little point in discarding them. | |
4449 | */ | |
4450 | if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) || | |
4451 | payload->proto == fast_rx->control_port_protocol)) | |
4452 | return false; | |
4453 | } | |
49ddf8e6 JB |
4454 | |
4455 | /* after this point, don't punt to the slowpath! */ | |
4456 | ||
4457 | if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) && | |
4458 | pskb_trim(skb, skb->len - fast_rx->icv_len)) | |
4459 | goto drop; | |
4460 | ||
49ddf8e6 JB |
4461 | if (rx->key && !ieee80211_has_protected(hdr->frame_control)) |
4462 | goto drop; | |
4463 | ||
24bba078 FF |
4464 | if (status->rx_flags & IEEE80211_RX_AMSDU) { |
4465 | if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) != | |
4466 | RX_QUEUED) | |
4467 | goto drop; | |
4468 | ||
4469 | return true; | |
4470 | } | |
4471 | ||
49ddf8e6 JB |
4472 | /* do the header conversion - first grab the addresses */ |
4473 | ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs); | |
4474 | ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs); | |
4475 | /* remove the SNAP but leave the ethertype */ | |
4476 | skb_pull(skb, snap_offs + sizeof(rfc1042_header)); | |
4477 | /* push the addresses in front */ | |
4478 | memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs)); | |
4479 | ||
80a915ec | 4480 | ieee80211_rx_8023(rx, fast_rx, orig_len); |
49ddf8e6 JB |
4481 | |
4482 | return true; | |
4483 | drop: | |
4484 | dev_kfree_skb(skb); | |
80a915ec FF |
4485 | if (fast_rx->uses_rss) |
4486 | stats = this_cpu_ptr(sta->pcpu_rx_stats); | |
4487 | ||
c9c5962b | 4488 | stats->dropped++; |
49ddf8e6 JB |
4489 | return true; |
4490 | } | |
4491 | ||
4406c376 JB |
4492 | /* |
4493 | * This function returns whether or not the SKB | |
4494 | * was destined for RX processing or not, which, | |
4495 | * if consume is true, is equivalent to whether | |
4496 | * or not the skb was consumed. | |
4497 | */ | |
4498 | static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, | |
4499 | struct sk_buff *skb, bool consume) | |
4500 | { | |
4501 | struct ieee80211_local *local = rx->local; | |
4502 | struct ieee80211_sub_if_data *sdata = rx->sdata; | |
4406c376 JB |
4503 | |
4504 | rx->skb = skb; | |
4406c376 | 4505 | |
49ddf8e6 JB |
4506 | /* See if we can do fast-rx; if we have to copy we already lost, |
4507 | * so punt in that case. We should never have to deliver a data | |
4508 | * frame to multiple interfaces anyway. | |
4509 | * | |
4510 | * We skip the ieee80211_accept_frame() call and do the necessary | |
4511 | * checking inside ieee80211_invoke_fast_rx(). | |
4512 | */ | |
4513 | if (consume && rx->sta) { | |
4514 | struct ieee80211_fast_rx *fast_rx; | |
4515 | ||
4516 | fast_rx = rcu_dereference(rx->sta->fast_rx); | |
4517 | if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx)) | |
4518 | return true; | |
4519 | } | |
4520 | ||
a58fbe1a | 4521 | if (!ieee80211_accept_frame(rx)) |
4406c376 JB |
4522 | return false; |
4523 | ||
4406c376 JB |
4524 | if (!consume) { |
4525 | skb = skb_copy(skb, GFP_ATOMIC); | |
4526 | if (!skb) { | |
4527 | if (net_ratelimit()) | |
4528 | wiphy_debug(local->hw.wiphy, | |
b305dae4 | 4529 | "failed to copy skb for %s\n", |
4406c376 JB |
4530 | sdata->name); |
4531 | return true; | |
4532 | } | |
4533 | ||
4534 | rx->skb = skb; | |
4535 | } | |
4536 | ||
4537 | ieee80211_invoke_rx_handlers(rx); | |
4538 | return true; | |
4539 | } | |
4540 | ||
80a915ec FF |
4541 | static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw, |
4542 | struct ieee80211_sta *pubsta, | |
4543 | struct sk_buff *skb, | |
4544 | struct list_head *list) | |
4545 | { | |
4546 | struct ieee80211_local *local = hw_to_local(hw); | |
4547 | struct ieee80211_fast_rx *fast_rx; | |
4548 | struct ieee80211_rx_data rx; | |
4549 | ||
4550 | memset(&rx, 0, sizeof(rx)); | |
4551 | rx.skb = skb; | |
4552 | rx.local = local; | |
4553 | rx.list = list; | |
4554 | ||
4555 | I802_DEBUG_INC(local->dot11ReceivedFragmentCount); | |
4556 | ||
4557 | /* drop frame if too short for header */ | |
4558 | if (skb->len < sizeof(struct ethhdr)) | |
4559 | goto drop; | |
4560 | ||
4561 | if (!pubsta) | |
4562 | goto drop; | |
4563 | ||
4564 | rx.sta = container_of(pubsta, struct sta_info, sta); | |
4565 | rx.sdata = rx.sta->sdata; | |
4566 | ||
4567 | fast_rx = rcu_dereference(rx.sta->fast_rx); | |
4568 | if (!fast_rx) | |
4569 | goto drop; | |
4570 | ||
4571 | ieee80211_rx_8023(&rx, fast_rx, skb->len); | |
4572 | return; | |
4573 | ||
4574 | drop: | |
4575 | dev_kfree_skb(skb); | |
4576 | } | |
4577 | ||
571ecf67 | 4578 | /* |
6b59db7d | 4579 | * This is the actual Rx frames handler. as it belongs to Rx path it must |
6368e4b1 | 4580 | * be called with rcu_read_lock protection. |
571ecf67 | 4581 | */ |
71ebb4aa | 4582 | static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, |
d63b548f | 4583 | struct ieee80211_sta *pubsta, |
af9f9b22 | 4584 | struct sk_buff *skb, |
c5d1686b | 4585 | struct list_head *list) |
571ecf67 JB |
4586 | { |
4587 | struct ieee80211_local *local = hw_to_local(hw); | |
4588 | struct ieee80211_sub_if_data *sdata; | |
571ecf67 | 4589 | struct ieee80211_hdr *hdr; |
e3cf8b3f | 4590 | __le16 fc; |
5cf121c3 | 4591 | struct ieee80211_rx_data rx; |
4406c376 | 4592 | struct ieee80211_sub_if_data *prev; |
83e7e4ce | 4593 | struct rhlist_head *tmp; |
e3cf8b3f | 4594 | int err = 0; |
571ecf67 | 4595 | |
e3cf8b3f | 4596 | fc = ((struct ieee80211_hdr *)skb->data)->frame_control; |
571ecf67 JB |
4597 | memset(&rx, 0, sizeof(rx)); |
4598 | rx.skb = skb; | |
4599 | rx.local = local; | |
c5d1686b | 4600 | rx.list = list; |
72abd81b | 4601 | |
e3cf8b3f | 4602 | if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc)) |
c206ca67 | 4603 | I802_DEBUG_INC(local->dot11ReceivedFragmentCount); |
571ecf67 | 4604 | |
4a4f1a58 JB |
4605 | if (ieee80211_is_mgmt(fc)) { |
4606 | /* drop frame if too short for header */ | |
4607 | if (skb->len < ieee80211_hdrlen(fc)) | |
4608 | err = -ENOBUFS; | |
4609 | else | |
4610 | err = skb_linearize(skb); | |
4611 | } else { | |
e3cf8b3f | 4612 | err = !pskb_may_pull(skb, ieee80211_hdrlen(fc)); |
4a4f1a58 | 4613 | } |
e3cf8b3f ZY |
4614 | |
4615 | if (err) { | |
4616 | dev_kfree_skb(skb); | |
4617 | return; | |
4618 | } | |
4619 | ||
4620 | hdr = (struct ieee80211_hdr *)skb->data; | |
38f3714d | 4621 | ieee80211_parse_qos(&rx); |
d1c3a37c | 4622 | ieee80211_verify_alignment(&rx); |
38f3714d | 4623 | |
d48b2968 | 4624 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) || |
cd418ba6 TP |
4625 | ieee80211_is_beacon(hdr->frame_control) || |
4626 | ieee80211_is_s1g_beacon(hdr->frame_control))) | |
d48b2968 JB |
4627 | ieee80211_scan_rx(local, skb); |
4628 | ||
19d19e96 | 4629 | if (ieee80211_is_data(fc)) { |
d63b548f | 4630 | struct sta_info *sta, *prev_sta; |
7bedd0cf | 4631 | |
19d19e96 JB |
4632 | if (pubsta) { |
4633 | rx.sta = container_of(pubsta, struct sta_info, sta); | |
4634 | rx.sdata = rx.sta->sdata; | |
4635 | if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) | |
4636 | return; | |
4637 | goto out; | |
4638 | } | |
4639 | ||
56af3268 | 4640 | prev_sta = NULL; |
4406c376 | 4641 | |
83e7e4ce | 4642 | for_each_sta_info(local, hdr->addr2, sta, tmp) { |
56af3268 BG |
4643 | if (!prev_sta) { |
4644 | prev_sta = sta; | |
4645 | continue; | |
4646 | } | |
4647 | ||
4648 | rx.sta = prev_sta; | |
4649 | rx.sdata = prev_sta->sdata; | |
4406c376 | 4650 | ieee80211_prepare_and_rx_handle(&rx, skb, false); |
abe60632 | 4651 | |
56af3268 | 4652 | prev_sta = sta; |
4406c376 | 4653 | } |
56af3268 BG |
4654 | |
4655 | if (prev_sta) { | |
4656 | rx.sta = prev_sta; | |
4657 | rx.sdata = prev_sta->sdata; | |
4658 | ||
4406c376 | 4659 | if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) |
56af3268 | 4660 | return; |
8e26d5ad | 4661 | goto out; |
56af3268 | 4662 | } |
4406c376 JB |
4663 | } |
4664 | ||
4b0dd98e | 4665 | prev = NULL; |
b2e7771e | 4666 | |
4b0dd98e JB |
4667 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
4668 | if (!ieee80211_sdata_running(sdata)) | |
4669 | continue; | |
340e11f3 | 4670 | |
4b0dd98e JB |
4671 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR || |
4672 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
4673 | continue; | |
340e11f3 | 4674 | |
4b0dd98e JB |
4675 | /* |
4676 | * frame is destined for this interface, but if it's | |
4677 | * not also for the previous one we handle that after | |
4678 | * the loop to avoid copying the SKB once too much | |
4679 | */ | |
4bb29f8c | 4680 | |
4b0dd98e | 4681 | if (!prev) { |
abe60632 | 4682 | prev = sdata; |
4b0dd98e | 4683 | continue; |
340e11f3 | 4684 | } |
4bb29f8c | 4685 | |
7852e361 | 4686 | rx.sta = sta_info_get_bss(prev, hdr->addr2); |
4b0dd98e JB |
4687 | rx.sdata = prev; |
4688 | ieee80211_prepare_and_rx_handle(&rx, skb, false); | |
4bb29f8c | 4689 | |
4b0dd98e JB |
4690 | prev = sdata; |
4691 | } | |
4692 | ||
4693 | if (prev) { | |
7852e361 | 4694 | rx.sta = sta_info_get_bss(prev, hdr->addr2); |
4b0dd98e | 4695 | rx.sdata = prev; |
4406c376 | 4696 | |
4b0dd98e JB |
4697 | if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) |
4698 | return; | |
571ecf67 | 4699 | } |
4406c376 | 4700 | |
8e26d5ad | 4701 | out: |
4406c376 | 4702 | dev_kfree_skb(skb); |
571ecf67 | 4703 | } |
6368e4b1 RR |
4704 | |
4705 | /* | |
4706 | * This is the receive path handler. It is called by a low level driver when an | |
4707 | * 802.11 MPDU is received from the hardware. | |
4708 | */ | |
c5d1686b FF |
4709 | void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, |
4710 | struct sk_buff *skb, struct list_head *list) | |
6368e4b1 RR |
4711 | { |
4712 | struct ieee80211_local *local = hw_to_local(hw); | |
8318d78a JB |
4713 | struct ieee80211_rate *rate = NULL; |
4714 | struct ieee80211_supported_band *sband; | |
f1d58c25 | 4715 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
8318d78a | 4716 | |
d20ef63d JB |
4717 | WARN_ON_ONCE(softirq_count() == 0); |
4718 | ||
57fbcce3 | 4719 | if (WARN_ON(status->band >= NUM_NL80211_BANDS)) |
77a980dc | 4720 | goto drop; |
8318d78a JB |
4721 | |
4722 | sband = local->hw.wiphy->bands[status->band]; | |
77a980dc JB |
4723 | if (WARN_ON(!sband)) |
4724 | goto drop; | |
8318d78a | 4725 | |
89c3a8ac JB |
4726 | /* |
4727 | * If we're suspending, it is possible although not too likely | |
4728 | * that we'd be receiving frames after having already partially | |
4729 | * quiesced the stack. We can't process such frames then since | |
4730 | * that might, for example, cause stations to be added or other | |
4731 | * driver callbacks be invoked. | |
4732 | */ | |
77a980dc JB |
4733 | if (unlikely(local->quiescing || local->suspended)) |
4734 | goto drop; | |
89c3a8ac | 4735 | |
04800ada AN |
4736 | /* We might be during a HW reconfig, prevent Rx for the same reason */ |
4737 | if (unlikely(local->in_reconfig)) | |
4738 | goto drop; | |
4739 | ||
ea77f12f JB |
4740 | /* |
4741 | * The same happens when we're not even started, | |
4742 | * but that's worth a warning. | |
4743 | */ | |
77a980dc JB |
4744 | if (WARN_ON(!local->started)) |
4745 | goto drop; | |
ea77f12f | 4746 | |
fc885189 | 4747 | if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) { |
e5d6eb83 | 4748 | /* |
fc885189 JB |
4749 | * Validate the rate, unless a PLCP error means that |
4750 | * we probably can't have a valid rate here anyway. | |
e5d6eb83 | 4751 | */ |
fc885189 | 4752 | |
da6a4352 JB |
4753 | switch (status->encoding) { |
4754 | case RX_ENC_HT: | |
fc885189 JB |
4755 | /* |
4756 | * rate_idx is MCS index, which can be [0-76] | |
4757 | * as documented on: | |
4758 | * | |
59d4bfc1 | 4759 | * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n |
fc885189 JB |
4760 | * |
4761 | * Anything else would be some sort of driver or | |
4762 | * hardware error. The driver should catch hardware | |
4763 | * errors. | |
4764 | */ | |
444e3803 | 4765 | if (WARN(status->rate_idx > 76, |
fc885189 JB |
4766 | "Rate marked as an HT rate but passed " |
4767 | "status->rate_idx is not " | |
4768 | "an MCS index [0-76]: %d (0x%02x)\n", | |
4769 | status->rate_idx, | |
4770 | status->rate_idx)) | |
4771 | goto drop; | |
da6a4352 JB |
4772 | break; |
4773 | case RX_ENC_VHT: | |
5614618e | 4774 | if (WARN_ONCE(status->rate_idx > 9 || |
8613c948 JB |
4775 | !status->nss || |
4776 | status->nss > 8, | |
5614618e | 4777 | "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n", |
8613c948 | 4778 | status->rate_idx, status->nss)) |
5614618e | 4779 | goto drop; |
da6a4352 | 4780 | break; |
41cbb0f5 LC |
4781 | case RX_ENC_HE: |
4782 | if (WARN_ONCE(status->rate_idx > 11 || | |
4783 | !status->nss || | |
4784 | status->nss > 8, | |
4785 | "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n", | |
4786 | status->rate_idx, status->nss)) | |
4787 | goto drop; | |
4788 | break; | |
da6a4352 JB |
4789 | default: |
4790 | WARN_ON_ONCE(1); | |
fc0561dc | 4791 | fallthrough; |
da6a4352 | 4792 | case RX_ENC_LEGACY: |
444e3803 | 4793 | if (WARN_ON(status->rate_idx >= sband->n_bitrates)) |
fc885189 JB |
4794 | goto drop; |
4795 | rate = &sband->bitrates[status->rate_idx]; | |
4796 | } | |
0fb8ca45 | 4797 | } |
6368e4b1 | 4798 | |
554891e6 JB |
4799 | status->rx_flags = 0; |
4800 | ||
261e411b AN |
4801 | kcov_remote_start_common(skb_get_kcov_handle(skb)); |
4802 | ||
6368e4b1 RR |
4803 | /* |
4804 | * Frames with failed FCS/PLCP checksum are not returned, | |
4805 | * all other frames are returned without radiotap header | |
4806 | * if it was previously present. | |
4807 | * Also, frames with less than 16 bytes are dropped. | |
4808 | */ | |
80a915ec FF |
4809 | if (!(status->flag & RX_FLAG_8023)) |
4810 | skb = ieee80211_rx_monitor(local, skb, rate); | |
261e411b AN |
4811 | if (skb) { |
4812 | ieee80211_tpt_led_trig_rx(local, | |
4813 | ((struct ieee80211_hdr *)skb->data)->frame_control, | |
4814 | skb->len); | |
d63b548f | 4815 | |
80a915ec FF |
4816 | if (status->flag & RX_FLAG_8023) |
4817 | __ieee80211_rx_handle_8023(hw, pubsta, skb, list); | |
4818 | else | |
4819 | __ieee80211_rx_handle_packet(hw, pubsta, skb, list); | |
261e411b | 4820 | } |
77a980dc | 4821 | |
261e411b | 4822 | kcov_remote_stop(); |
77a980dc JB |
4823 | return; |
4824 | drop: | |
4825 | kfree_skb(skb); | |
6368e4b1 | 4826 | } |
c5d1686b FF |
4827 | EXPORT_SYMBOL(ieee80211_rx_list); |
4828 | ||
4829 | void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, | |
4830 | struct sk_buff *skb, struct napi_struct *napi) | |
4831 | { | |
4832 | struct sk_buff *tmp; | |
4833 | LIST_HEAD(list); | |
4834 | ||
4835 | ||
4836 | /* | |
4837 | * key references and virtual interfaces are protected using RCU | |
4838 | * and this requires that we are in a read-side RCU section during | |
4839 | * receive processing | |
4840 | */ | |
4841 | rcu_read_lock(); | |
4842 | ieee80211_rx_list(hw, pubsta, skb, &list); | |
4843 | rcu_read_unlock(); | |
4844 | ||
4845 | if (!napi) { | |
4846 | netif_receive_skb_list(&list); | |
4847 | return; | |
4848 | } | |
4849 | ||
4850 | list_for_each_entry_safe(skb, tmp, &list, list) { | |
4851 | skb_list_del_init(skb); | |
4852 | napi_gro_receive(napi, skb); | |
4853 | } | |
4854 | } | |
af9f9b22 | 4855 | EXPORT_SYMBOL(ieee80211_rx_napi); |
571ecf67 JB |
4856 | |
4857 | /* This is a version of the rx handler that can be called from hard irq | |
4858 | * context. Post the skb on the queue and schedule the tasklet */ | |
f1d58c25 | 4859 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb) |
571ecf67 JB |
4860 | { |
4861 | struct ieee80211_local *local = hw_to_local(hw); | |
4862 | ||
4863 | BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); | |
4864 | ||
571ecf67 JB |
4865 | skb->pkt_type = IEEE80211_RX_MSG; |
4866 | skb_queue_tail(&local->skb_queue, skb); | |
4867 | tasklet_schedule(&local->tasklet); | |
4868 | } | |
4869 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |