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