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