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