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