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