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