]>
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> | |
5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | |
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> |
571ecf67 JB |
13 | #include <linux/kernel.h> |
14 | #include <linux/skbuff.h> | |
15 | #include <linux/netdevice.h> | |
16 | #include <linux/etherdevice.h> | |
d4e46a3d | 17 | #include <linux/rcupdate.h> |
571ecf67 JB |
18 | #include <net/mac80211.h> |
19 | #include <net/ieee80211_radiotap.h> | |
20 | ||
21 | #include "ieee80211_i.h" | |
22 | #include "ieee80211_led.h" | |
33b64eb2 | 23 | #include "mesh.h" |
571ecf67 JB |
24 | #include "wep.h" |
25 | #include "wpa.h" | |
26 | #include "tkip.h" | |
27 | #include "wme.h" | |
28 | ||
71364716 RR |
29 | u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, |
30 | struct tid_ampdu_rx *tid_agg_rx, | |
31 | struct sk_buff *skb, u16 mpdu_seq_num, | |
32 | int bar_req); | |
b2e7771e JB |
33 | /* |
34 | * monitor mode reception | |
35 | * | |
36 | * This function cleans up the SKB, i.e. it removes all the stuff | |
37 | * only useful for monitoring. | |
38 | */ | |
39 | static struct sk_buff *remove_monitor_info(struct ieee80211_local *local, | |
40 | struct sk_buff *skb, | |
41 | int rtap_len) | |
42 | { | |
43 | skb_pull(skb, rtap_len); | |
44 | ||
45 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) { | |
46 | if (likely(skb->len > FCS_LEN)) | |
47 | skb_trim(skb, skb->len - FCS_LEN); | |
48 | else { | |
49 | /* driver bug */ | |
50 | WARN_ON(1); | |
51 | dev_kfree_skb(skb); | |
52 | skb = NULL; | |
53 | } | |
54 | } | |
55 | ||
56 | return skb; | |
57 | } | |
58 | ||
59 | static inline int should_drop_frame(struct ieee80211_rx_status *status, | |
60 | struct sk_buff *skb, | |
61 | int present_fcs_len, | |
62 | int radiotap_len) | |
63 | { | |
64 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
65 | ||
66 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) | |
67 | return 1; | |
68 | if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len)) | |
69 | return 1; | |
98f0b0a3 RR |
70 | if (((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) == |
71 | cpu_to_le16(IEEE80211_FTYPE_CTL)) && | |
72 | ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) != | |
71364716 RR |
73 | cpu_to_le16(IEEE80211_STYPE_PSPOLL)) && |
74 | ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) != | |
75 | cpu_to_le16(IEEE80211_STYPE_BACK_REQ))) | |
b2e7771e JB |
76 | return 1; |
77 | return 0; | |
78 | } | |
79 | ||
80 | /* | |
81 | * This function copies a received frame to all monitor interfaces and | |
82 | * returns a cleaned-up SKB that no longer includes the FCS nor the | |
83 | * radiotap header the driver might have added. | |
84 | */ | |
85 | static struct sk_buff * | |
86 | ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, | |
8318d78a JB |
87 | struct ieee80211_rx_status *status, |
88 | struct ieee80211_rate *rate) | |
b2e7771e JB |
89 | { |
90 | struct ieee80211_sub_if_data *sdata; | |
b2e7771e | 91 | int needed_headroom = 0; |
c49e5ea3 JB |
92 | struct ieee80211_radiotap_header *rthdr; |
93 | __le64 *rttsft = NULL; | |
94 | struct ieee80211_rtap_fixed_data { | |
b2e7771e JB |
95 | u8 flags; |
96 | u8 rate; | |
97 | __le16 chan_freq; | |
98 | __le16 chan_flags; | |
99 | u8 antsignal; | |
100 | u8 padding_for_rxflags; | |
101 | __le16 rx_flags; | |
c49e5ea3 | 102 | } __attribute__ ((packed)) *rtfixed; |
b2e7771e JB |
103 | struct sk_buff *skb, *skb2; |
104 | struct net_device *prev_dev = NULL; | |
105 | int present_fcs_len = 0; | |
106 | int rtap_len = 0; | |
107 | ||
108 | /* | |
109 | * First, we may need to make a copy of the skb because | |
110 | * (1) we need to modify it for radiotap (if not present), and | |
111 | * (2) the other RX handlers will modify the skb we got. | |
112 | * | |
113 | * We don't need to, of course, if we aren't going to return | |
114 | * the SKB because it has a bad FCS/PLCP checksum. | |
115 | */ | |
116 | if (status->flag & RX_FLAG_RADIOTAP) | |
117 | rtap_len = ieee80211_get_radiotap_len(origskb->data); | |
118 | else | |
c49e5ea3 JB |
119 | /* room for radiotap header, always present fields and TSFT */ |
120 | needed_headroom = sizeof(*rthdr) + sizeof(*rtfixed) + 8; | |
b2e7771e JB |
121 | |
122 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) | |
123 | present_fcs_len = FCS_LEN; | |
124 | ||
125 | if (!local->monitors) { | |
126 | if (should_drop_frame(status, origskb, present_fcs_len, | |
127 | rtap_len)) { | |
128 | dev_kfree_skb(origskb); | |
129 | return NULL; | |
130 | } | |
131 | ||
132 | return remove_monitor_info(local, origskb, rtap_len); | |
133 | } | |
134 | ||
135 | if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) { | |
136 | /* only need to expand headroom if necessary */ | |
137 | skb = origskb; | |
138 | origskb = NULL; | |
139 | ||
140 | /* | |
141 | * This shouldn't trigger often because most devices have an | |
142 | * RX header they pull before we get here, and that should | |
143 | * be big enough for our radiotap information. We should | |
144 | * probably export the length to drivers so that we can have | |
145 | * them allocate enough headroom to start with. | |
146 | */ | |
147 | if (skb_headroom(skb) < needed_headroom && | |
c49e5ea3 | 148 | pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) { |
b2e7771e JB |
149 | dev_kfree_skb(skb); |
150 | return NULL; | |
151 | } | |
152 | } else { | |
153 | /* | |
154 | * Need to make a copy and possibly remove radiotap header | |
155 | * and FCS from the original. | |
156 | */ | |
157 | skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC); | |
158 | ||
159 | origskb = remove_monitor_info(local, origskb, rtap_len); | |
160 | ||
161 | if (!skb) | |
162 | return origskb; | |
163 | } | |
164 | ||
165 | /* if necessary, prepend radiotap information */ | |
166 | if (!(status->flag & RX_FLAG_RADIOTAP)) { | |
c49e5ea3 JB |
167 | rtfixed = (void *) skb_push(skb, sizeof(*rtfixed)); |
168 | rtap_len = sizeof(*rthdr) + sizeof(*rtfixed); | |
169 | if (status->flag & RX_FLAG_TSFT) { | |
170 | rttsft = (void *) skb_push(skb, sizeof(*rttsft)); | |
171 | rtap_len += 8; | |
172 | } | |
b2e7771e JB |
173 | rthdr = (void *) skb_push(skb, sizeof(*rthdr)); |
174 | memset(rthdr, 0, sizeof(*rthdr)); | |
c49e5ea3 JB |
175 | memset(rtfixed, 0, sizeof(*rtfixed)); |
176 | rthdr->it_present = | |
b2e7771e JB |
177 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
178 | (1 << IEEE80211_RADIOTAP_RATE) | | |
179 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | |
180 | (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | | |
181 | (1 << IEEE80211_RADIOTAP_RX_FLAGS)); | |
c49e5ea3 JB |
182 | rtfixed->flags = 0; |
183 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) | |
184 | rtfixed->flags |= IEEE80211_RADIOTAP_F_FCS; | |
185 | ||
186 | if (rttsft) { | |
187 | *rttsft = cpu_to_le64(status->mactime); | |
188 | rthdr->it_present |= | |
189 | cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT); | |
190 | } | |
b2e7771e JB |
191 | |
192 | /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */ | |
c49e5ea3 | 193 | rtfixed->rx_flags = 0; |
b2e7771e JB |
194 | if (status->flag & |
195 | (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) | |
c49e5ea3 | 196 | rtfixed->rx_flags |= |
b2e7771e JB |
197 | cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS); |
198 | ||
8318d78a | 199 | rtfixed->rate = rate->bitrate / 5; |
b2e7771e | 200 | |
c49e5ea3 | 201 | rtfixed->chan_freq = cpu_to_le16(status->freq); |
b2e7771e | 202 | |
8318d78a | 203 | if (status->band == IEEE80211_BAND_5GHZ) |
c49e5ea3 | 204 | rtfixed->chan_flags = |
b2e7771e JB |
205 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
206 | IEEE80211_CHAN_5GHZ); | |
207 | else | |
c49e5ea3 | 208 | rtfixed->chan_flags = |
b2e7771e JB |
209 | cpu_to_le16(IEEE80211_CHAN_DYN | |
210 | IEEE80211_CHAN_2GHZ); | |
211 | ||
c49e5ea3 JB |
212 | rtfixed->antsignal = status->ssi; |
213 | rthdr->it_len = cpu_to_le16(rtap_len); | |
b2e7771e JB |
214 | } |
215 | ||
ce3edf6d | 216 | skb_reset_mac_header(skb); |
b2e7771e JB |
217 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
218 | skb->pkt_type = PACKET_OTHERHOST; | |
219 | skb->protocol = htons(ETH_P_802_2); | |
220 | ||
221 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
222 | if (!netif_running(sdata->dev)) | |
223 | continue; | |
224 | ||
51fb61e7 | 225 | if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR) |
b2e7771e JB |
226 | continue; |
227 | ||
3d30d949 MW |
228 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) |
229 | continue; | |
230 | ||
b2e7771e JB |
231 | if (prev_dev) { |
232 | skb2 = skb_clone(skb, GFP_ATOMIC); | |
233 | if (skb2) { | |
234 | skb2->dev = prev_dev; | |
235 | netif_rx(skb2); | |
236 | } | |
237 | } | |
238 | ||
239 | prev_dev = sdata->dev; | |
240 | sdata->dev->stats.rx_packets++; | |
241 | sdata->dev->stats.rx_bytes += skb->len; | |
242 | } | |
243 | ||
244 | if (prev_dev) { | |
245 | skb->dev = prev_dev; | |
246 | netif_rx(skb); | |
247 | } else | |
248 | dev_kfree_skb(skb); | |
249 | ||
250 | return origskb; | |
251 | } | |
252 | ||
253 | ||
38f3714d | 254 | static void ieee80211_parse_qos(struct ieee80211_txrx_data *rx) |
6e0d114d JB |
255 | { |
256 | u8 *data = rx->skb->data; | |
257 | int tid; | |
258 | ||
259 | /* does the frame have a qos control field? */ | |
260 | if (WLAN_FC_IS_QOS_DATA(rx->fc)) { | |
261 | u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN; | |
262 | /* frame has qos control */ | |
263 | tid = qc[0] & QOS_CONTROL_TID_MASK; | |
fd4c7f2f | 264 | if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT) |
64bd4b69 | 265 | rx->flags |= IEEE80211_TXRXD_RX_AMSDU; |
fd4c7f2f | 266 | else |
64bd4b69 | 267 | rx->flags &= ~IEEE80211_TXRXD_RX_AMSDU; |
6e0d114d JB |
268 | } else { |
269 | if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) { | |
270 | /* Separate TID for management frames */ | |
271 | tid = NUM_RX_DATA_QUEUES - 1; | |
272 | } else { | |
273 | /* no qos control present */ | |
274 | tid = 0; /* 802.1d - Best Effort */ | |
275 | } | |
276 | } | |
52865dfd | 277 | |
6e0d114d | 278 | I802_DEBUG_INC(rx->local->wme_rx_queue[tid]); |
52865dfd JB |
279 | /* only a debug counter, sta might not be assigned properly yet */ |
280 | if (rx->sta) | |
6e0d114d | 281 | I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]); |
6e0d114d JB |
282 | |
283 | rx->u.rx.queue = tid; | |
284 | /* Set skb->priority to 1d tag if highest order bit of TID is not set. | |
285 | * For now, set skb->priority to 0 for other cases. */ | |
286 | rx->skb->priority = (tid > 7) ? 0 : tid; | |
38f3714d | 287 | } |
6e0d114d | 288 | |
38f3714d JB |
289 | static void ieee80211_verify_ip_alignment(struct ieee80211_txrx_data *rx) |
290 | { | |
291 | #ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT | |
292 | int hdrlen; | |
293 | ||
294 | if (!WLAN_FC_DATA_PRESENT(rx->fc)) | |
295 | return; | |
296 | ||
297 | /* | |
298 | * Drivers are required to align the payload data in a way that | |
299 | * guarantees that the contained IP header is aligned to a four- | |
300 | * byte boundary. In the case of regular frames, this simply means | |
301 | * aligning the payload to a four-byte boundary (because either | |
302 | * the IP header is directly contained, or IV/RFC1042 headers that | |
303 | * have a length divisible by four are in front of it. | |
304 | * | |
305 | * With A-MSDU frames, however, the payload data address must | |
306 | * yield two modulo four because there are 14-byte 802.3 headers | |
307 | * within the A-MSDU frames that push the IP header further back | |
308 | * to a multiple of four again. Thankfully, the specs were sane | |
309 | * enough this time around to require padding each A-MSDU subframe | |
310 | * to a length that is a multiple of four. | |
311 | * | |
312 | * Padding like atheros hardware adds which is inbetween the 802.11 | |
313 | * header and the payload is not supported, the driver is required | |
314 | * to move the 802.11 header further back in that case. | |
315 | */ | |
316 | hdrlen = ieee80211_get_hdrlen(rx->fc); | |
317 | if (rx->flags & IEEE80211_TXRXD_RX_AMSDU) | |
318 | hdrlen += ETH_HLEN; | |
319 | WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3); | |
320 | #endif | |
6e0d114d JB |
321 | } |
322 | ||
6368e4b1 | 323 | |
71ebb4aa | 324 | static u32 ieee80211_rx_load_stats(struct ieee80211_local *local, |
8318d78a JB |
325 | struct sk_buff *skb, |
326 | struct ieee80211_rx_status *status, | |
327 | struct ieee80211_rate *rate) | |
571ecf67 | 328 | { |
571ecf67 JB |
329 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
330 | u32 load = 0, hdrtime; | |
571ecf67 JB |
331 | |
332 | /* Estimate total channel use caused by this frame */ | |
333 | ||
571ecf67 JB |
334 | /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values, |
335 | * 1 usec = 1/8 * (1080 / 10) = 13.5 */ | |
336 | ||
8318d78a JB |
337 | if (status->band == IEEE80211_BAND_5GHZ || |
338 | (status->band == IEEE80211_BAND_5GHZ && | |
339 | rate->flags & IEEE80211_RATE_ERP_G)) | |
571ecf67 JB |
340 | hdrtime = CHAN_UTIL_HDR_SHORT; |
341 | else | |
342 | hdrtime = CHAN_UTIL_HDR_LONG; | |
343 | ||
344 | load = hdrtime; | |
345 | if (!is_multicast_ether_addr(hdr->addr1)) | |
346 | load += hdrtime; | |
347 | ||
8318d78a JB |
348 | /* TODO: optimise again */ |
349 | load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate; | |
571ecf67 JB |
350 | |
351 | /* Divide channel_use by 8 to avoid wrapping around the counter */ | |
352 | load >>= CHAN_UTIL_SHIFT; | |
571ecf67 | 353 | |
6368e4b1 | 354 | return load; |
571ecf67 JB |
355 | } |
356 | ||
571ecf67 JB |
357 | /* rx handlers */ |
358 | ||
9ae54c84 | 359 | static ieee80211_rx_result |
571ecf67 JB |
360 | ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx) |
361 | { | |
52865dfd JB |
362 | if (rx->sta) |
363 | rx->sta->channel_use_raw += rx->u.rx.load; | |
571ecf67 | 364 | rx->sdata->channel_use_raw += rx->u.rx.load; |
9ae54c84 | 365 | return RX_CONTINUE; |
571ecf67 JB |
366 | } |
367 | ||
9ae54c84 | 368 | static ieee80211_rx_result |
571ecf67 JB |
369 | ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx) |
370 | { | |
371 | struct ieee80211_local *local = rx->local; | |
372 | struct sk_buff *skb = rx->skb; | |
373 | ||
ece8eddd ZY |
374 | if (unlikely(local->sta_hw_scanning)) |
375 | return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status); | |
376 | ||
377 | if (unlikely(local->sta_sw_scanning)) { | |
378 | /* drop all the other packets during a software scan anyway */ | |
379 | if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status) | |
9ae54c84 | 380 | != RX_QUEUED) |
ece8eddd | 381 | dev_kfree_skb(skb); |
9ae54c84 | 382 | return RX_QUEUED; |
571ecf67 JB |
383 | } |
384 | ||
badffb72 | 385 | if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) { |
571ecf67 JB |
386 | /* scanning finished during invoking of handlers */ |
387 | I802_DEBUG_INC(local->rx_handlers_drop_passive_scan); | |
e4c26add | 388 | return RX_DROP_UNUSABLE; |
571ecf67 JB |
389 | } |
390 | ||
9ae54c84 | 391 | return RX_CONTINUE; |
571ecf67 JB |
392 | } |
393 | ||
33b64eb2 LCC |
394 | static ieee80211_rx_result |
395 | ieee80211_rx_mesh_check(struct ieee80211_txrx_data *rx) | |
396 | { | |
397 | int hdrlen = ieee80211_get_hdrlen(rx->fc); | |
398 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; | |
d6d1a5a7 JB |
399 | |
400 | #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l)) | |
401 | ||
33b64eb2 LCC |
402 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) { |
403 | if (!((rx->fc & IEEE80211_FCTL_FROMDS) && | |
404 | (rx->fc & IEEE80211_FCTL_TODS))) | |
405 | return RX_DROP_MONITOR; | |
406 | if (memcmp(hdr->addr4, rx->dev->dev_addr, ETH_ALEN) == 0) | |
407 | return RX_DROP_MONITOR; | |
408 | } | |
409 | ||
410 | /* If there is not an established peer link and this is not a peer link | |
411 | * establisment frame, beacon or probe, drop the frame. | |
412 | */ | |
413 | ||
d6d1a5a7 | 414 | if (!rx->sta || sta_plink_state(rx->sta) != ESTAB) { |
33b64eb2 | 415 | struct ieee80211_mgmt *mgmt; |
d6d1a5a7 | 416 | |
33b64eb2 LCC |
417 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT) |
418 | return RX_DROP_MONITOR; | |
419 | ||
420 | switch (rx->fc & IEEE80211_FCTL_STYPE) { | |
421 | case IEEE80211_STYPE_ACTION: | |
422 | mgmt = (struct ieee80211_mgmt *)hdr; | |
423 | if (mgmt->u.action.category != PLINK_CATEGORY) | |
424 | return RX_DROP_MONITOR; | |
425 | /* fall through on else */ | |
426 | case IEEE80211_STYPE_PROBE_REQ: | |
427 | case IEEE80211_STYPE_PROBE_RESP: | |
428 | case IEEE80211_STYPE_BEACON: | |
429 | return RX_CONTINUE; | |
430 | break; | |
431 | default: | |
432 | return RX_DROP_MONITOR; | |
433 | } | |
434 | ||
435 | } else if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && | |
436 | is_broadcast_ether_addr(hdr->addr1) && | |
437 | mesh_rmc_check(hdr->addr4, msh_h_get(hdr, hdrlen), rx->dev)) | |
438 | return RX_DROP_MONITOR; | |
902acc78 | 439 | #undef msh_h_get |
d6d1a5a7 | 440 | |
902acc78 JB |
441 | return RX_CONTINUE; |
442 | } | |
33b64eb2 LCC |
443 | |
444 | ||
9ae54c84 | 445 | static ieee80211_rx_result |
571ecf67 JB |
446 | ieee80211_rx_h_check(struct ieee80211_txrx_data *rx) |
447 | { | |
448 | struct ieee80211_hdr *hdr; | |
33b64eb2 | 449 | |
571ecf67 JB |
450 | hdr = (struct ieee80211_hdr *) rx->skb->data; |
451 | ||
452 | /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */ | |
453 | if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) { | |
454 | if (unlikely(rx->fc & IEEE80211_FCTL_RETRY && | |
455 | rx->sta->last_seq_ctrl[rx->u.rx.queue] == | |
456 | hdr->seq_ctrl)) { | |
badffb72 | 457 | if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) { |
571ecf67 JB |
458 | rx->local->dot11FrameDuplicateCount++; |
459 | rx->sta->num_duplicates++; | |
460 | } | |
e4c26add | 461 | return RX_DROP_MONITOR; |
571ecf67 JB |
462 | } else |
463 | rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl; | |
464 | } | |
465 | ||
571ecf67 JB |
466 | if (unlikely(rx->skb->len < 16)) { |
467 | I802_DEBUG_INC(rx->local->rx_handlers_drop_short); | |
e4c26add | 468 | return RX_DROP_MONITOR; |
571ecf67 JB |
469 | } |
470 | ||
571ecf67 JB |
471 | /* Drop disallowed frame classes based on STA auth/assoc state; |
472 | * IEEE 802.11, Chap 5.5. | |
473 | * | |
474 | * 80211.o does filtering only based on association state, i.e., it | |
475 | * drops Class 3 frames from not associated stations. hostapd sends | |
476 | * deauth/disassoc frames when needed. In addition, hostapd is | |
477 | * responsible for filtering on both auth and assoc states. | |
478 | */ | |
33b64eb2 | 479 | |
902acc78 | 480 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
33b64eb2 | 481 | return ieee80211_rx_mesh_check(rx); |
33b64eb2 | 482 | |
571ecf67 JB |
483 | if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA || |
484 | ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL && | |
485 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) && | |
51fb61e7 | 486 | rx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
571ecf67 JB |
487 | (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) { |
488 | if ((!(rx->fc & IEEE80211_FCTL_FROMDS) && | |
489 | !(rx->fc & IEEE80211_FCTL_TODS) && | |
490 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) | |
badffb72 | 491 | || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) { |
571ecf67 JB |
492 | /* Drop IBSS frames and frames for other hosts |
493 | * silently. */ | |
e4c26add | 494 | return RX_DROP_MONITOR; |
571ecf67 JB |
495 | } |
496 | ||
e4c26add | 497 | return RX_DROP_MONITOR; |
571ecf67 JB |
498 | } |
499 | ||
9ae54c84 | 500 | return RX_CONTINUE; |
570bd537 JB |
501 | } |
502 | ||
503 | ||
9ae54c84 | 504 | static ieee80211_rx_result |
1990af8d | 505 | ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx) |
570bd537 JB |
506 | { |
507 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; | |
3017b80b JB |
508 | int keyidx; |
509 | int hdrlen; | |
e4c26add | 510 | ieee80211_rx_result result = RX_DROP_UNUSABLE; |
d4e46a3d | 511 | struct ieee80211_key *stakey = NULL; |
570bd537 | 512 | |
3017b80b JB |
513 | /* |
514 | * Key selection 101 | |
515 | * | |
516 | * There are three types of keys: | |
517 | * - GTK (group keys) | |
518 | * - PTK (pairwise keys) | |
519 | * - STK (station-to-station pairwise keys) | |
520 | * | |
521 | * When selecting a key, we have to distinguish between multicast | |
522 | * (including broadcast) and unicast frames, the latter can only | |
523 | * use PTKs and STKs while the former always use GTKs. Unless, of | |
524 | * course, actual WEP keys ("pre-RSNA") are used, then unicast | |
525 | * frames can also use key indizes like GTKs. Hence, if we don't | |
526 | * have a PTK/STK we check the key index for a WEP key. | |
527 | * | |
8dc06a1c JB |
528 | * Note that in a regular BSS, multicast frames are sent by the |
529 | * AP only, associated stations unicast the frame to the AP first | |
530 | * which then multicasts it on their behalf. | |
531 | * | |
3017b80b JB |
532 | * There is also a slight problem in IBSS mode: GTKs are negotiated |
533 | * with each station, that is something we don't currently handle. | |
8dc06a1c JB |
534 | * The spec seems to expect that one negotiates the same key with |
535 | * every station but there's no such requirement; VLANs could be | |
536 | * possible. | |
3017b80b JB |
537 | */ |
538 | ||
539 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) | |
9ae54c84 | 540 | return RX_CONTINUE; |
571ecf67 | 541 | |
3017b80b | 542 | /* |
1990af8d | 543 | * No point in finding a key and decrypting if the frame is neither |
3017b80b JB |
544 | * addressed to us nor a multicast frame. |
545 | */ | |
badffb72 | 546 | if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
9ae54c84 | 547 | return RX_CONTINUE; |
3017b80b | 548 | |
d4e46a3d JB |
549 | if (rx->sta) |
550 | stakey = rcu_dereference(rx->sta->key); | |
551 | ||
552 | if (!is_multicast_ether_addr(hdr->addr1) && stakey) { | |
553 | rx->key = stakey; | |
571ecf67 | 554 | } else { |
3017b80b JB |
555 | /* |
556 | * The device doesn't give us the IV so we won't be | |
557 | * able to look up the key. That's ok though, we | |
558 | * don't need to decrypt the frame, we just won't | |
559 | * be able to keep statistics accurate. | |
560 | * Except for key threshold notifications, should | |
561 | * we somehow allow the driver to tell us which key | |
562 | * the hardware used if this flag is set? | |
563 | */ | |
7848ba7d JB |
564 | if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) && |
565 | (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) | |
9ae54c84 | 566 | return RX_CONTINUE; |
3017b80b JB |
567 | |
568 | hdrlen = ieee80211_get_hdrlen(rx->fc); | |
569 | ||
570 | if (rx->skb->len < 8 + hdrlen) | |
e4c26add | 571 | return RX_DROP_UNUSABLE; /* TODO: count this? */ |
3017b80b JB |
572 | |
573 | /* | |
574 | * no need to call ieee80211_wep_get_keyidx, | |
575 | * it verifies a bunch of things we've done already | |
576 | */ | |
577 | keyidx = rx->skb->data[hdrlen + 3] >> 6; | |
578 | ||
d4e46a3d | 579 | rx->key = rcu_dereference(rx->sdata->keys[keyidx]); |
3017b80b JB |
580 | |
581 | /* | |
582 | * RSNA-protected unicast frames should always be sent with | |
583 | * pairwise or station-to-station keys, but for WEP we allow | |
584 | * using a key index as well. | |
585 | */ | |
8f20fc24 | 586 | if (rx->key && rx->key->conf.alg != ALG_WEP && |
3017b80b JB |
587 | !is_multicast_ether_addr(hdr->addr1)) |
588 | rx->key = NULL; | |
571ecf67 JB |
589 | } |
590 | ||
3017b80b | 591 | if (rx->key) { |
571ecf67 | 592 | rx->key->tx_rx_count++; |
011bfcc4 | 593 | /* TODO: add threshold stuff again */ |
1990af8d | 594 | } else { |
7f3ad894 | 595 | #ifdef CONFIG_MAC80211_DEBUG |
70f08765 JB |
596 | if (net_ratelimit()) |
597 | printk(KERN_DEBUG "%s: RX protected frame," | |
598 | " but have no key\n", rx->dev->name); | |
7f3ad894 | 599 | #endif /* CONFIG_MAC80211_DEBUG */ |
e4c26add | 600 | return RX_DROP_MONITOR; |
70f08765 JB |
601 | } |
602 | ||
1990af8d JB |
603 | /* Check for weak IVs if possible */ |
604 | if (rx->sta && rx->key->conf.alg == ALG_WEP && | |
605 | ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && | |
606 | (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) || | |
607 | !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) && | |
608 | ieee80211_wep_is_weak_iv(rx->skb, rx->key)) | |
609 | rx->sta->wep_weak_iv_count++; | |
610 | ||
70f08765 JB |
611 | switch (rx->key->conf.alg) { |
612 | case ALG_WEP: | |
e2f036da MN |
613 | result = ieee80211_crypto_wep_decrypt(rx); |
614 | break; | |
70f08765 | 615 | case ALG_TKIP: |
e2f036da MN |
616 | result = ieee80211_crypto_tkip_decrypt(rx); |
617 | break; | |
70f08765 | 618 | case ALG_CCMP: |
e2f036da MN |
619 | result = ieee80211_crypto_ccmp_decrypt(rx); |
620 | break; | |
70f08765 JB |
621 | } |
622 | ||
e2f036da MN |
623 | /* either the frame has been decrypted or will be dropped */ |
624 | rx->u.rx.status->flag |= RX_FLAG_DECRYPTED; | |
625 | ||
626 | return result; | |
70f08765 JB |
627 | } |
628 | ||
571ecf67 JB |
629 | static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta) |
630 | { | |
631 | struct ieee80211_sub_if_data *sdata; | |
0795af57 JP |
632 | DECLARE_MAC_BUF(mac); |
633 | ||
571ecf67 JB |
634 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
635 | ||
636 | if (sdata->bss) | |
637 | atomic_inc(&sdata->bss->num_sta_ps); | |
638 | sta->flags |= WLAN_STA_PS; | |
4a9a66e9 | 639 | sta->flags &= ~WLAN_STA_PSPOLL; |
571ecf67 | 640 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
0795af57 JP |
641 | printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n", |
642 | dev->name, print_mac(mac, sta->addr), sta->aid); | |
571ecf67 JB |
643 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
644 | } | |
645 | ||
646 | static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta) | |
647 | { | |
648 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
649 | struct sk_buff *skb; | |
650 | int sent = 0; | |
651 | struct ieee80211_sub_if_data *sdata; | |
652 | struct ieee80211_tx_packet_data *pkt_data; | |
0795af57 | 653 | DECLARE_MAC_BUF(mac); |
571ecf67 JB |
654 | |
655 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); | |
004c872e | 656 | |
571ecf67 JB |
657 | if (sdata->bss) |
658 | atomic_dec(&sdata->bss->num_sta_ps); | |
004c872e | 659 | |
836341a7 | 660 | sta->flags &= ~(WLAN_STA_PS | WLAN_STA_PSPOLL); |
004c872e JB |
661 | |
662 | if (!skb_queue_empty(&sta->ps_tx_buf)) | |
663 | sta_info_clear_tim_bit(sta); | |
664 | ||
571ecf67 | 665 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
0795af57 JP |
666 | printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n", |
667 | dev->name, print_mac(mac, sta->addr), sta->aid); | |
571ecf67 | 668 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
004c872e | 669 | |
571ecf67 JB |
670 | /* Send all buffered frames to the station */ |
671 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { | |
672 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; | |
673 | sent++; | |
e8bf9649 | 674 | pkt_data->flags |= IEEE80211_TXPD_REQUEUE; |
571ecf67 JB |
675 | dev_queue_xmit(skb); |
676 | } | |
677 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { | |
678 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; | |
679 | local->total_ps_buffered--; | |
680 | sent++; | |
681 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
0795af57 | 682 | printk(KERN_DEBUG "%s: STA %s aid %d send PS frame " |
571ecf67 | 683 | "since STA not sleeping anymore\n", dev->name, |
0795af57 | 684 | print_mac(mac, sta->addr), sta->aid); |
571ecf67 | 685 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
e8bf9649 | 686 | pkt_data->flags |= IEEE80211_TXPD_REQUEUE; |
571ecf67 JB |
687 | dev_queue_xmit(skb); |
688 | } | |
689 | ||
690 | return sent; | |
691 | } | |
692 | ||
9ae54c84 | 693 | static ieee80211_rx_result |
571ecf67 JB |
694 | ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx) |
695 | { | |
696 | struct sta_info *sta = rx->sta; | |
697 | struct net_device *dev = rx->dev; | |
698 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; | |
699 | ||
700 | if (!sta) | |
9ae54c84 | 701 | return RX_CONTINUE; |
571ecf67 JB |
702 | |
703 | /* Update last_rx only for IBSS packets which are for the current | |
704 | * BSSID to avoid keeping the current IBSS network alive in cases where | |
705 | * other STAs are using different BSSID. */ | |
51fb61e7 | 706 | if (rx->sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
71364716 RR |
707 | u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, |
708 | IEEE80211_IF_TYPE_IBSS); | |
571ecf67 JB |
709 | if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0) |
710 | sta->last_rx = jiffies; | |
711 | } else | |
712 | if (!is_multicast_ether_addr(hdr->addr1) || | |
51fb61e7 | 713 | rx->sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
571ecf67 JB |
714 | /* Update last_rx only for unicast frames in order to prevent |
715 | * the Probe Request frames (the only broadcast frames from a | |
716 | * STA in infrastructure mode) from keeping a connection alive. | |
33b64eb2 LCC |
717 | * Mesh beacons will update last_rx when if they are found to |
718 | * match the current local configuration when processed. | |
571ecf67 JB |
719 | */ |
720 | sta->last_rx = jiffies; | |
721 | } | |
722 | ||
badffb72 | 723 | if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
9ae54c84 | 724 | return RX_CONTINUE; |
571ecf67 JB |
725 | |
726 | sta->rx_fragments++; | |
727 | sta->rx_bytes += rx->skb->len; | |
6c55aa97 LF |
728 | sta->last_rssi = rx->u.rx.status->ssi; |
729 | sta->last_signal = rx->u.rx.status->signal; | |
730 | sta->last_noise = rx->u.rx.status->noise; | |
571ecf67 JB |
731 | |
732 | if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) { | |
733 | /* Change STA power saving mode only in the end of a frame | |
734 | * exchange sequence */ | |
735 | if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM)) | |
736 | rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta); | |
737 | else if (!(sta->flags & WLAN_STA_PS) && | |
738 | (rx->fc & IEEE80211_FCTL_PM)) | |
739 | ap_sta_ps_start(dev, sta); | |
740 | } | |
741 | ||
742 | /* Drop data::nullfunc frames silently, since they are used only to | |
743 | * control station power saving mode. */ | |
744 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && | |
745 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) { | |
746 | I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); | |
747 | /* Update counter and free packet here to avoid counting this | |
748 | * as a dropped packed. */ | |
749 | sta->rx_packets++; | |
750 | dev_kfree_skb(rx->skb); | |
9ae54c84 | 751 | return RX_QUEUED; |
571ecf67 JB |
752 | } |
753 | ||
9ae54c84 | 754 | return RX_CONTINUE; |
571ecf67 JB |
755 | } /* ieee80211_rx_h_sta_process */ |
756 | ||
571ecf67 JB |
757 | static inline struct ieee80211_fragment_entry * |
758 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, | |
759 | unsigned int frag, unsigned int seq, int rx_queue, | |
760 | struct sk_buff **skb) | |
761 | { | |
762 | struct ieee80211_fragment_entry *entry; | |
763 | int idx; | |
764 | ||
765 | idx = sdata->fragment_next; | |
766 | entry = &sdata->fragments[sdata->fragment_next++]; | |
767 | if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) | |
768 | sdata->fragment_next = 0; | |
769 | ||
770 | if (!skb_queue_empty(&entry->skb_list)) { | |
771 | #ifdef CONFIG_MAC80211_DEBUG | |
772 | struct ieee80211_hdr *hdr = | |
773 | (struct ieee80211_hdr *) entry->skb_list.next->data; | |
0795af57 JP |
774 | DECLARE_MAC_BUF(mac); |
775 | DECLARE_MAC_BUF(mac2); | |
571ecf67 JB |
776 | printk(KERN_DEBUG "%s: RX reassembly removed oldest " |
777 | "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " | |
0795af57 | 778 | "addr1=%s addr2=%s\n", |
571ecf67 JB |
779 | sdata->dev->name, idx, |
780 | jiffies - entry->first_frag_time, entry->seq, | |
0795af57 JP |
781 | entry->last_frag, print_mac(mac, hdr->addr1), |
782 | print_mac(mac2, hdr->addr2)); | |
571ecf67 JB |
783 | #endif /* CONFIG_MAC80211_DEBUG */ |
784 | __skb_queue_purge(&entry->skb_list); | |
785 | } | |
786 | ||
787 | __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ | |
788 | *skb = NULL; | |
789 | entry->first_frag_time = jiffies; | |
790 | entry->seq = seq; | |
791 | entry->rx_queue = rx_queue; | |
792 | entry->last_frag = frag; | |
793 | entry->ccmp = 0; | |
794 | entry->extra_len = 0; | |
795 | ||
796 | return entry; | |
797 | } | |
798 | ||
799 | static inline struct ieee80211_fragment_entry * | |
800 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, | |
801 | u16 fc, unsigned int frag, unsigned int seq, | |
802 | int rx_queue, struct ieee80211_hdr *hdr) | |
803 | { | |
804 | struct ieee80211_fragment_entry *entry; | |
805 | int i, idx; | |
806 | ||
807 | idx = sdata->fragment_next; | |
808 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { | |
809 | struct ieee80211_hdr *f_hdr; | |
810 | u16 f_fc; | |
811 | ||
812 | idx--; | |
813 | if (idx < 0) | |
814 | idx = IEEE80211_FRAGMENT_MAX - 1; | |
815 | ||
816 | entry = &sdata->fragments[idx]; | |
817 | if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || | |
818 | entry->rx_queue != rx_queue || | |
819 | entry->last_frag + 1 != frag) | |
820 | continue; | |
821 | ||
822 | f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data; | |
823 | f_fc = le16_to_cpu(f_hdr->frame_control); | |
824 | ||
825 | if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) || | |
826 | compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 || | |
827 | compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0) | |
828 | continue; | |
829 | ||
ab46623e | 830 | if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
571ecf67 JB |
831 | __skb_queue_purge(&entry->skb_list); |
832 | continue; | |
833 | } | |
834 | return entry; | |
835 | } | |
836 | ||
837 | return NULL; | |
838 | } | |
839 | ||
9ae54c84 | 840 | static ieee80211_rx_result |
571ecf67 JB |
841 | ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx) |
842 | { | |
843 | struct ieee80211_hdr *hdr; | |
844 | u16 sc; | |
845 | unsigned int frag, seq; | |
846 | struct ieee80211_fragment_entry *entry; | |
847 | struct sk_buff *skb; | |
0795af57 | 848 | DECLARE_MAC_BUF(mac); |
571ecf67 JB |
849 | |
850 | hdr = (struct ieee80211_hdr *) rx->skb->data; | |
851 | sc = le16_to_cpu(hdr->seq_ctrl); | |
852 | frag = sc & IEEE80211_SCTL_FRAG; | |
853 | ||
854 | if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) || | |
855 | (rx->skb)->len < 24 || | |
856 | is_multicast_ether_addr(hdr->addr1))) { | |
857 | /* not fragmented */ | |
858 | goto out; | |
859 | } | |
860 | I802_DEBUG_INC(rx->local->rx_handlers_fragments); | |
861 | ||
862 | seq = (sc & IEEE80211_SCTL_SEQ) >> 4; | |
863 | ||
864 | if (frag == 0) { | |
865 | /* This is the first fragment of a new frame. */ | |
866 | entry = ieee80211_reassemble_add(rx->sdata, frag, seq, | |
867 | rx->u.rx.queue, &(rx->skb)); | |
8f20fc24 | 868 | if (rx->key && rx->key->conf.alg == ALG_CCMP && |
571ecf67 JB |
869 | (rx->fc & IEEE80211_FCTL_PROTECTED)) { |
870 | /* Store CCMP PN so that we can verify that the next | |
871 | * fragment has a sequential PN value. */ | |
872 | entry->ccmp = 1; | |
873 | memcpy(entry->last_pn, | |
874 | rx->key->u.ccmp.rx_pn[rx->u.rx.queue], | |
875 | CCMP_PN_LEN); | |
876 | } | |
9ae54c84 | 877 | return RX_QUEUED; |
571ecf67 JB |
878 | } |
879 | ||
880 | /* This is a fragment for a frame that should already be pending in | |
881 | * fragment cache. Add this fragment to the end of the pending entry. | |
882 | */ | |
883 | entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq, | |
884 | rx->u.rx.queue, hdr); | |
885 | if (!entry) { | |
886 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | |
e4c26add | 887 | return RX_DROP_MONITOR; |
571ecf67 JB |
888 | } |
889 | ||
890 | /* Verify that MPDUs within one MSDU have sequential PN values. | |
891 | * (IEEE 802.11i, 8.3.3.4.5) */ | |
892 | if (entry->ccmp) { | |
893 | int i; | |
894 | u8 pn[CCMP_PN_LEN], *rpn; | |
8f20fc24 | 895 | if (!rx->key || rx->key->conf.alg != ALG_CCMP) |
e4c26add | 896 | return RX_DROP_UNUSABLE; |
571ecf67 JB |
897 | memcpy(pn, entry->last_pn, CCMP_PN_LEN); |
898 | for (i = CCMP_PN_LEN - 1; i >= 0; i--) { | |
899 | pn[i]++; | |
900 | if (pn[i]) | |
901 | break; | |
902 | } | |
903 | rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue]; | |
904 | if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) { | |
1a84f3fd JB |
905 | if (net_ratelimit()) |
906 | printk(KERN_DEBUG "%s: defrag: CCMP PN not " | |
0795af57 | 907 | "sequential A2=%s" |
1a84f3fd JB |
908 | " PN=%02x%02x%02x%02x%02x%02x " |
909 | "(expected %02x%02x%02x%02x%02x%02x)\n", | |
0795af57 | 910 | rx->dev->name, print_mac(mac, hdr->addr2), |
1a84f3fd JB |
911 | rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], |
912 | rpn[5], pn[0], pn[1], pn[2], pn[3], | |
913 | pn[4], pn[5]); | |
e4c26add | 914 | return RX_DROP_UNUSABLE; |
571ecf67 JB |
915 | } |
916 | memcpy(entry->last_pn, pn, CCMP_PN_LEN); | |
917 | } | |
918 | ||
919 | skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc)); | |
920 | __skb_queue_tail(&entry->skb_list, rx->skb); | |
921 | entry->last_frag = frag; | |
922 | entry->extra_len += rx->skb->len; | |
923 | if (rx->fc & IEEE80211_FCTL_MOREFRAGS) { | |
924 | rx->skb = NULL; | |
9ae54c84 | 925 | return RX_QUEUED; |
571ecf67 JB |
926 | } |
927 | ||
928 | rx->skb = __skb_dequeue(&entry->skb_list); | |
929 | if (skb_tailroom(rx->skb) < entry->extra_len) { | |
930 | I802_DEBUG_INC(rx->local->rx_expand_skb_head2); | |
931 | if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, | |
932 | GFP_ATOMIC))) { | |
933 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | |
934 | __skb_queue_purge(&entry->skb_list); | |
e4c26add | 935 | return RX_DROP_UNUSABLE; |
571ecf67 JB |
936 | } |
937 | } | |
938 | while ((skb = __skb_dequeue(&entry->skb_list))) { | |
939 | memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len); | |
940 | dev_kfree_skb(skb); | |
941 | } | |
942 | ||
943 | /* Complete frame has been reassembled - process it now */ | |
badffb72 | 944 | rx->flags |= IEEE80211_TXRXD_FRAGMENTED; |
571ecf67 JB |
945 | |
946 | out: | |
947 | if (rx->sta) | |
948 | rx->sta->rx_packets++; | |
949 | if (is_multicast_ether_addr(hdr->addr1)) | |
950 | rx->local->dot11MulticastReceivedFrameCount++; | |
951 | else | |
952 | ieee80211_led_rx(rx->local); | |
9ae54c84 | 953 | return RX_CONTINUE; |
571ecf67 JB |
954 | } |
955 | ||
9ae54c84 | 956 | static ieee80211_rx_result |
571ecf67 JB |
957 | ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx) |
958 | { | |
98f0b0a3 | 959 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); |
571ecf67 JB |
960 | struct sk_buff *skb; |
961 | int no_pending_pkts; | |
0795af57 | 962 | DECLARE_MAC_BUF(mac); |
571ecf67 JB |
963 | |
964 | if (likely(!rx->sta || | |
965 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL || | |
966 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL || | |
badffb72 | 967 | !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))) |
9ae54c84 | 968 | return RX_CONTINUE; |
571ecf67 | 969 | |
51fb61e7 JB |
970 | if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) && |
971 | (sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) | |
e4c26add | 972 | return RX_DROP_UNUSABLE; |
98f0b0a3 | 973 | |
571ecf67 JB |
974 | skb = skb_dequeue(&rx->sta->tx_filtered); |
975 | if (!skb) { | |
976 | skb = skb_dequeue(&rx->sta->ps_tx_buf); | |
977 | if (skb) | |
978 | rx->local->total_ps_buffered--; | |
979 | } | |
980 | no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) && | |
981 | skb_queue_empty(&rx->sta->ps_tx_buf); | |
982 | ||
983 | if (skb) { | |
984 | struct ieee80211_hdr *hdr = | |
985 | (struct ieee80211_hdr *) skb->data; | |
986 | ||
4a9a66e9 JB |
987 | /* |
988 | * Tell TX path to send one frame even though the STA may | |
989 | * still remain is PS mode after this frame exchange. | |
990 | */ | |
991 | rx->sta->flags |= WLAN_STA_PSPOLL; | |
571ecf67 JB |
992 | |
993 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
0795af57 JP |
994 | printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n", |
995 | print_mac(mac, rx->sta->addr), rx->sta->aid, | |
571ecf67 JB |
996 | skb_queue_len(&rx->sta->ps_tx_buf)); |
997 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
998 | ||
999 | /* Use MoreData flag to indicate whether there are more | |
1000 | * buffered frames for this STA */ | |
836341a7 | 1001 | if (no_pending_pkts) |
571ecf67 | 1002 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
836341a7 | 1003 | else |
571ecf67 JB |
1004 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
1005 | ||
1006 | dev_queue_xmit(skb); | |
1007 | ||
004c872e JB |
1008 | if (no_pending_pkts) |
1009 | sta_info_clear_tim_bit(rx->sta); | |
571ecf67 JB |
1010 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
1011 | } else if (!rx->u.rx.sent_ps_buffered) { | |
004c872e JB |
1012 | /* |
1013 | * FIXME: This can be the result of a race condition between | |
1014 | * us expiring a frame and the station polling for it. | |
1015 | * Should we send it a null-func frame indicating we | |
1016 | * have nothing buffered for it? | |
1017 | */ | |
0795af57 | 1018 | printk(KERN_DEBUG "%s: STA %s sent PS Poll even " |
571ecf67 | 1019 | "though there is no buffered frames for it\n", |
0795af57 | 1020 | rx->dev->name, print_mac(mac, rx->sta->addr)); |
571ecf67 | 1021 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
571ecf67 JB |
1022 | } |
1023 | ||
9ae54c84 | 1024 | /* Free PS Poll skb here instead of returning RX_DROP that would |
571ecf67 JB |
1025 | * count as an dropped frame. */ |
1026 | dev_kfree_skb(rx->skb); | |
1027 | ||
9ae54c84 | 1028 | return RX_QUEUED; |
571ecf67 JB |
1029 | } |
1030 | ||
9ae54c84 | 1031 | static ieee80211_rx_result |
6e0d114d JB |
1032 | ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx) |
1033 | { | |
1034 | u16 fc = rx->fc; | |
1035 | u8 *data = rx->skb->data; | |
1036 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data; | |
1037 | ||
1038 | if (!WLAN_FC_IS_QOS_DATA(fc)) | |
9ae54c84 | 1039 | return RX_CONTINUE; |
6e0d114d JB |
1040 | |
1041 | /* remove the qos control field, update frame type and meta-data */ | |
1042 | memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2); | |
1043 | hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2); | |
1044 | /* change frame type to non QOS */ | |
1045 | rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA; | |
1046 | hdr->frame_control = cpu_to_le16(fc); | |
1047 | ||
9ae54c84 | 1048 | return RX_CONTINUE; |
6e0d114d JB |
1049 | } |
1050 | ||
76ee65bf | 1051 | static int |
ce3edf6d | 1052 | ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx) |
571ecf67 | 1053 | { |
238814fd | 1054 | if (unlikely(!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED))) { |
571ecf67 | 1055 | #ifdef CONFIG_MAC80211_DEBUG |
238814fd JB |
1056 | if (net_ratelimit()) |
1057 | printk(KERN_DEBUG "%s: dropped frame " | |
1058 | "(unauthorized port)\n", rx->dev->name); | |
571ecf67 | 1059 | #endif /* CONFIG_MAC80211_DEBUG */ |
76ee65bf | 1060 | return -EACCES; |
571ecf67 JB |
1061 | } |
1062 | ||
76ee65bf | 1063 | return 0; |
571ecf67 JB |
1064 | } |
1065 | ||
76ee65bf | 1066 | static int |
ce3edf6d | 1067 | ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx) |
571ecf67 | 1068 | { |
3017b80b | 1069 | /* |
7848ba7d JB |
1070 | * Pass through unencrypted frames if the hardware has |
1071 | * decrypted them already. | |
3017b80b | 1072 | */ |
7848ba7d | 1073 | if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED) |
76ee65bf | 1074 | return 0; |
571ecf67 JB |
1075 | |
1076 | /* Drop unencrypted frames if key is set. */ | |
1077 | if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) && | |
1078 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && | |
1079 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC && | |
ce3edf6d | 1080 | (rx->key || rx->sdata->drop_unencrypted))) { |
1a84f3fd JB |
1081 | if (net_ratelimit()) |
1082 | printk(KERN_DEBUG "%s: RX non-WEP frame, but expected " | |
1083 | "encryption\n", rx->dev->name); | |
76ee65bf | 1084 | return -EACCES; |
571ecf67 | 1085 | } |
76ee65bf | 1086 | return 0; |
571ecf67 JB |
1087 | } |
1088 | ||
76ee65bf RR |
1089 | static int |
1090 | ieee80211_data_to_8023(struct ieee80211_txrx_data *rx) | |
571ecf67 JB |
1091 | { |
1092 | struct net_device *dev = rx->dev; | |
571ecf67 JB |
1093 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
1094 | u16 fc, hdrlen, ethertype; | |
1095 | u8 *payload; | |
1096 | u8 dst[ETH_ALEN]; | |
1097 | u8 src[ETH_ALEN]; | |
76ee65bf | 1098 | struct sk_buff *skb = rx->skb; |
571ecf67 | 1099 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
0795af57 JP |
1100 | DECLARE_MAC_BUF(mac); |
1101 | DECLARE_MAC_BUF(mac2); | |
1102 | DECLARE_MAC_BUF(mac3); | |
1103 | DECLARE_MAC_BUF(mac4); | |
571ecf67 JB |
1104 | |
1105 | fc = rx->fc; | |
571ecf67 JB |
1106 | |
1107 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) | |
76ee65bf | 1108 | return -1; |
571ecf67 JB |
1109 | |
1110 | hdrlen = ieee80211_get_hdrlen(fc); | |
1111 | ||
902acc78 | 1112 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
33b64eb2 LCC |
1113 | int meshhdrlen = ieee80211_get_mesh_hdrlen( |
1114 | (struct ieee80211s_hdr *) (skb->data + hdrlen)); | |
1115 | /* Copy on cb: | |
1116 | * - mesh header: to be used for mesh forwarding | |
1117 | * decision. It will also be used as mesh header template at | |
1118 | * tx.c:ieee80211_subif_start_xmit() if interface | |
1119 | * type is mesh and skb->pkt_type == PACKET_OTHERHOST | |
1120 | * - ta: to be used if a RERR needs to be sent. | |
1121 | */ | |
1122 | memcpy(skb->cb, skb->data + hdrlen, meshhdrlen); | |
1123 | memcpy(MESH_PREQ(skb), hdr->addr2, ETH_ALEN); | |
1124 | hdrlen += meshhdrlen; | |
1125 | } | |
33b64eb2 | 1126 | |
571ecf67 JB |
1127 | /* convert IEEE 802.11 header + possible LLC headers into Ethernet |
1128 | * header | |
1129 | * IEEE 802.11 address fields: | |
1130 | * ToDS FromDS Addr1 Addr2 Addr3 Addr4 | |
1131 | * 0 0 DA SA BSSID n/a | |
1132 | * 0 1 DA BSSID SA n/a | |
1133 | * 1 0 BSSID SA DA n/a | |
1134 | * 1 1 RA TA DA SA | |
1135 | */ | |
1136 | ||
1137 | switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { | |
1138 | case IEEE80211_FCTL_TODS: | |
1139 | /* BSSID SA DA */ | |
1140 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
1141 | memcpy(src, hdr->addr2, ETH_ALEN); | |
1142 | ||
51fb61e7 JB |
1143 | if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_AP && |
1144 | sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) { | |
1a84f3fd JB |
1145 | if (net_ratelimit()) |
1146 | printk(KERN_DEBUG "%s: dropped ToDS frame " | |
0795af57 | 1147 | "(BSSID=%s SA=%s DA=%s)\n", |
1a84f3fd | 1148 | dev->name, |
0795af57 JP |
1149 | print_mac(mac, hdr->addr1), |
1150 | print_mac(mac2, hdr->addr2), | |
1151 | print_mac(mac3, hdr->addr3)); | |
76ee65bf | 1152 | return -1; |
571ecf67 JB |
1153 | } |
1154 | break; | |
1155 | case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): | |
1156 | /* RA TA DA SA */ | |
1157 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
1158 | memcpy(src, hdr->addr4, ETH_ALEN); | |
1159 | ||
33b64eb2 LCC |
1160 | if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS && |
1161 | sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) { | |
1162 | if (net_ratelimit()) | |
1163 | printk(KERN_DEBUG "%s: dropped FromDS&ToDS " | |
0795af57 | 1164 | "frame (RA=%s TA=%s DA=%s SA=%s)\n", |
1a84f3fd | 1165 | rx->dev->name, |
0795af57 JP |
1166 | print_mac(mac, hdr->addr1), |
1167 | print_mac(mac2, hdr->addr2), | |
1168 | print_mac(mac3, hdr->addr3), | |
1169 | print_mac(mac4, hdr->addr4)); | |
76ee65bf | 1170 | return -1; |
571ecf67 JB |
1171 | } |
1172 | break; | |
1173 | case IEEE80211_FCTL_FROMDS: | |
1174 | /* DA BSSID SA */ | |
1175 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
1176 | memcpy(src, hdr->addr3, ETH_ALEN); | |
1177 | ||
51fb61e7 | 1178 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA || |
b3316157 JL |
1179 | (is_multicast_ether_addr(dst) && |
1180 | !compare_ether_addr(src, dev->dev_addr))) | |
76ee65bf | 1181 | return -1; |
571ecf67 JB |
1182 | break; |
1183 | case 0: | |
1184 | /* DA SA BSSID */ | |
1185 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
1186 | memcpy(src, hdr->addr2, ETH_ALEN); | |
1187 | ||
51fb61e7 | 1188 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS) { |
571ecf67 | 1189 | if (net_ratelimit()) { |
0795af57 JP |
1190 | printk(KERN_DEBUG "%s: dropped IBSS frame " |
1191 | "(DA=%s SA=%s BSSID=%s)\n", | |
1192 | dev->name, | |
1193 | print_mac(mac, hdr->addr1), | |
1194 | print_mac(mac2, hdr->addr2), | |
1195 | print_mac(mac3, hdr->addr3)); | |
571ecf67 | 1196 | } |
76ee65bf | 1197 | return -1; |
571ecf67 JB |
1198 | } |
1199 | break; | |
1200 | } | |
1201 | ||
571ecf67 JB |
1202 | if (unlikely(skb->len - hdrlen < 8)) { |
1203 | if (net_ratelimit()) { | |
1204 | printk(KERN_DEBUG "%s: RX too short data frame " | |
1205 | "payload\n", dev->name); | |
1206 | } | |
76ee65bf | 1207 | return -1; |
571ecf67 JB |
1208 | } |
1209 | ||
76ee65bf | 1210 | payload = skb->data + hdrlen; |
571ecf67 JB |
1211 | ethertype = (payload[6] << 8) | payload[7]; |
1212 | ||
1213 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && | |
1214 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | |
1215 | compare_ether_addr(payload, bridge_tunnel_header) == 0)) { | |
1216 | /* remove RFC1042 or Bridge-Tunnel encapsulation and | |
1217 | * replace EtherType */ | |
1218 | skb_pull(skb, hdrlen + 6); | |
1219 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); | |
1220 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); | |
1221 | } else { | |
1222 | struct ethhdr *ehdr; | |
1223 | __be16 len; | |
ce3edf6d | 1224 | |
571ecf67 JB |
1225 | skb_pull(skb, hdrlen); |
1226 | len = htons(skb->len); | |
1227 | ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr)); | |
1228 | memcpy(ehdr->h_dest, dst, ETH_ALEN); | |
1229 | memcpy(ehdr->h_source, src, ETH_ALEN); | |
1230 | ehdr->h_proto = len; | |
1231 | } | |
76ee65bf RR |
1232 | return 0; |
1233 | } | |
571ecf67 | 1234 | |
ce3edf6d JB |
1235 | /* |
1236 | * requires that rx->skb is a frame with ethernet header | |
1237 | */ | |
1238 | static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx) | |
1239 | { | |
1240 | static const u8 pae_group_addr[ETH_ALEN] | |
1241 | = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 }; | |
1242 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; | |
1243 | ||
1244 | /* | |
1245 | * Allow EAPOL frames to us/the PAE group address regardless | |
1246 | * of whether the frame was encrypted or not. | |
1247 | */ | |
1248 | if (ehdr->h_proto == htons(ETH_P_PAE) && | |
1249 | (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 || | |
1250 | compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0)) | |
1251 | return true; | |
1252 | ||
1253 | if (ieee80211_802_1x_port_control(rx) || | |
1254 | ieee80211_drop_unencrypted(rx)) | |
1255 | return false; | |
1256 | ||
1257 | return true; | |
1258 | } | |
1259 | ||
1260 | /* | |
1261 | * requires that rx->skb is a frame with ethernet header | |
1262 | */ | |
76ee65bf RR |
1263 | static void |
1264 | ieee80211_deliver_skb(struct ieee80211_txrx_data *rx) | |
1265 | { | |
1266 | struct net_device *dev = rx->dev; | |
1267 | struct ieee80211_local *local = rx->local; | |
1268 | struct sk_buff *skb, *xmit_skb; | |
1269 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
ce3edf6d JB |
1270 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
1271 | struct sta_info *dsta; | |
571ecf67 | 1272 | |
76ee65bf RR |
1273 | skb = rx->skb; |
1274 | xmit_skb = NULL; | |
571ecf67 | 1275 | |
51fb61e7 JB |
1276 | if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP || |
1277 | sdata->vif.type == IEEE80211_IF_TYPE_VLAN) && | |
badffb72 | 1278 | (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) { |
ce3edf6d JB |
1279 | if (is_multicast_ether_addr(ehdr->h_dest)) { |
1280 | /* | |
1281 | * send multicast frames both to higher layers in | |
1282 | * local net stack and back to the wireless medium | |
1283 | */ | |
76ee65bf RR |
1284 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
1285 | if (!xmit_skb && net_ratelimit()) | |
571ecf67 JB |
1286 | printk(KERN_DEBUG "%s: failed to clone " |
1287 | "multicast frame\n", dev->name); | |
1288 | } else { | |
571ecf67 | 1289 | dsta = sta_info_get(local, skb->data); |
ce3edf6d JB |
1290 | if (dsta && dsta->dev == dev) { |
1291 | /* | |
1292 | * The destination station is associated to | |
1293 | * this AP (in this VLAN), so send the frame | |
1294 | * directly to it and do not pass it to local | |
1295 | * net stack. | |
571ecf67 | 1296 | */ |
76ee65bf | 1297 | xmit_skb = skb; |
571ecf67 JB |
1298 | skb = NULL; |
1299 | } | |
1300 | if (dsta) | |
1301 | sta_info_put(dsta); | |
1302 | } | |
1303 | } | |
1304 | ||
33b64eb2 | 1305 | /* Mesh forwarding */ |
902acc78 | 1306 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
33b64eb2 LCC |
1307 | u8 *mesh_ttl = &((struct ieee80211s_hdr *)skb->cb)->ttl; |
1308 | (*mesh_ttl)--; | |
1309 | ||
1310 | if (is_multicast_ether_addr(skb->data)) { | |
1311 | if (*mesh_ttl > 0) { | |
1312 | xmit_skb = skb_copy(skb, GFP_ATOMIC); | |
1313 | if (!xmit_skb && net_ratelimit()) | |
1314 | printk(KERN_DEBUG "%s: failed to clone " | |
1315 | "multicast frame\n", dev->name); | |
1316 | else | |
1317 | xmit_skb->pkt_type = PACKET_OTHERHOST; | |
1318 | } else | |
902acc78 JB |
1319 | IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta, |
1320 | dropped_frames_ttl); | |
33b64eb2 LCC |
1321 | } else if (skb->pkt_type != PACKET_OTHERHOST && |
1322 | compare_ether_addr(dev->dev_addr, skb->data) != 0) { | |
1323 | if (*mesh_ttl == 0) { | |
902acc78 JB |
1324 | IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta, |
1325 | dropped_frames_ttl); | |
33b64eb2 LCC |
1326 | dev_kfree_skb(skb); |
1327 | skb = NULL; | |
1328 | } else { | |
1329 | xmit_skb = skb; | |
1330 | xmit_skb->pkt_type = PACKET_OTHERHOST; | |
1331 | if (!(dev->flags & IFF_PROMISC)) | |
1332 | skb = NULL; | |
1333 | } | |
1334 | } | |
1335 | } | |
33b64eb2 | 1336 | |
571ecf67 JB |
1337 | if (skb) { |
1338 | /* deliver to local stack */ | |
1339 | skb->protocol = eth_type_trans(skb, dev); | |
1340 | memset(skb->cb, 0, sizeof(skb->cb)); | |
1341 | netif_rx(skb); | |
1342 | } | |
1343 | ||
76ee65bf | 1344 | if (xmit_skb) { |
571ecf67 | 1345 | /* send to wireless media */ |
f831e909 | 1346 | xmit_skb->protocol = htons(ETH_P_802_3); |
ce3edf6d JB |
1347 | skb_reset_network_header(xmit_skb); |
1348 | skb_reset_mac_header(xmit_skb); | |
76ee65bf | 1349 | dev_queue_xmit(xmit_skb); |
571ecf67 | 1350 | } |
76ee65bf RR |
1351 | } |
1352 | ||
9ae54c84 | 1353 | static ieee80211_rx_result |
fd4c7f2f RR |
1354 | ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx) |
1355 | { | |
1356 | struct net_device *dev = rx->dev; | |
1357 | struct ieee80211_local *local = rx->local; | |
1358 | u16 fc, ethertype; | |
1359 | u8 *payload; | |
1360 | struct sk_buff *skb = rx->skb, *frame = NULL; | |
1361 | const struct ethhdr *eth; | |
1362 | int remaining, err; | |
1363 | u8 dst[ETH_ALEN]; | |
1364 | u8 src[ETH_ALEN]; | |
1365 | DECLARE_MAC_BUF(mac); | |
1366 | ||
1367 | fc = rx->fc; | |
1368 | if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) | |
9ae54c84 | 1369 | return RX_CONTINUE; |
fd4c7f2f RR |
1370 | |
1371 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) | |
e4c26add | 1372 | return RX_DROP_MONITOR; |
fd4c7f2f | 1373 | |
64bd4b69 | 1374 | if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU)) |
9ae54c84 | 1375 | return RX_CONTINUE; |
fd4c7f2f RR |
1376 | |
1377 | err = ieee80211_data_to_8023(rx); | |
1378 | if (unlikely(err)) | |
e4c26add | 1379 | return RX_DROP_UNUSABLE; |
fd4c7f2f RR |
1380 | |
1381 | skb->dev = dev; | |
1382 | ||
1383 | dev->stats.rx_packets++; | |
1384 | dev->stats.rx_bytes += skb->len; | |
1385 | ||
1386 | /* skip the wrapping header */ | |
1387 | eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr)); | |
1388 | if (!eth) | |
e4c26add | 1389 | return RX_DROP_UNUSABLE; |
fd4c7f2f RR |
1390 | |
1391 | while (skb != frame) { | |
1392 | u8 padding; | |
1393 | __be16 len = eth->h_proto; | |
1394 | unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len); | |
1395 | ||
1396 | remaining = skb->len; | |
1397 | memcpy(dst, eth->h_dest, ETH_ALEN); | |
1398 | memcpy(src, eth->h_source, ETH_ALEN); | |
1399 | ||
1400 | padding = ((4 - subframe_len) & 0x3); | |
1401 | /* the last MSDU has no padding */ | |
1402 | if (subframe_len > remaining) { | |
1403 | printk(KERN_DEBUG "%s: wrong buffer size", dev->name); | |
e4c26add | 1404 | return RX_DROP_UNUSABLE; |
fd4c7f2f RR |
1405 | } |
1406 | ||
1407 | skb_pull(skb, sizeof(struct ethhdr)); | |
1408 | /* if last subframe reuse skb */ | |
1409 | if (remaining <= subframe_len + padding) | |
1410 | frame = skb; | |
1411 | else { | |
1412 | frame = dev_alloc_skb(local->hw.extra_tx_headroom + | |
1413 | subframe_len); | |
1414 | ||
1415 | if (frame == NULL) | |
e4c26add | 1416 | return RX_DROP_UNUSABLE; |
fd4c7f2f RR |
1417 | |
1418 | skb_reserve(frame, local->hw.extra_tx_headroom + | |
1419 | sizeof(struct ethhdr)); | |
1420 | memcpy(skb_put(frame, ntohs(len)), skb->data, | |
1421 | ntohs(len)); | |
1422 | ||
1423 | eth = (struct ethhdr *) skb_pull(skb, ntohs(len) + | |
1424 | padding); | |
1425 | if (!eth) { | |
1426 | printk(KERN_DEBUG "%s: wrong buffer size ", | |
1427 | dev->name); | |
1428 | dev_kfree_skb(frame); | |
e4c26add | 1429 | return RX_DROP_UNUSABLE; |
fd4c7f2f RR |
1430 | } |
1431 | } | |
1432 | ||
ce3edf6d | 1433 | skb_reset_network_header(frame); |
fd4c7f2f RR |
1434 | frame->dev = dev; |
1435 | frame->priority = skb->priority; | |
1436 | rx->skb = frame; | |
1437 | ||
fd4c7f2f RR |
1438 | payload = frame->data; |
1439 | ethertype = (payload[6] << 8) | payload[7]; | |
1440 | ||
1441 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && | |
ce3edf6d JB |
1442 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
1443 | compare_ether_addr(payload, | |
1444 | bridge_tunnel_header) == 0)) { | |
fd4c7f2f RR |
1445 | /* remove RFC1042 or Bridge-Tunnel |
1446 | * encapsulation and replace EtherType */ | |
1447 | skb_pull(frame, 6); | |
1448 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); | |
1449 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); | |
1450 | } else { | |
ce3edf6d JB |
1451 | memcpy(skb_push(frame, sizeof(__be16)), |
1452 | &len, sizeof(__be16)); | |
fd4c7f2f RR |
1453 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); |
1454 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); | |
1455 | } | |
1456 | ||
ce3edf6d JB |
1457 | if (!ieee80211_frame_allowed(rx)) { |
1458 | if (skb == frame) /* last frame */ | |
e4c26add | 1459 | return RX_DROP_UNUSABLE; |
ce3edf6d JB |
1460 | dev_kfree_skb(frame); |
1461 | continue; | |
1462 | } | |
fd4c7f2f RR |
1463 | |
1464 | ieee80211_deliver_skb(rx); | |
1465 | } | |
1466 | ||
9ae54c84 | 1467 | return RX_QUEUED; |
fd4c7f2f RR |
1468 | } |
1469 | ||
9ae54c84 | 1470 | static ieee80211_rx_result |
76ee65bf RR |
1471 | ieee80211_rx_h_data(struct ieee80211_txrx_data *rx) |
1472 | { | |
1473 | struct net_device *dev = rx->dev; | |
1474 | u16 fc; | |
ce3edf6d | 1475 | int err; |
76ee65bf RR |
1476 | |
1477 | fc = rx->fc; | |
1478 | if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) | |
9ae54c84 | 1479 | return RX_CONTINUE; |
76ee65bf RR |
1480 | |
1481 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) | |
e4c26add | 1482 | return RX_DROP_MONITOR; |
76ee65bf | 1483 | |
76ee65bf RR |
1484 | err = ieee80211_data_to_8023(rx); |
1485 | if (unlikely(err)) | |
e4c26add | 1486 | return RX_DROP_UNUSABLE; |
76ee65bf | 1487 | |
ce3edf6d | 1488 | if (!ieee80211_frame_allowed(rx)) |
e4c26add | 1489 | return RX_DROP_MONITOR; |
ce3edf6d | 1490 | |
76ee65bf RR |
1491 | rx->skb->dev = dev; |
1492 | ||
1493 | dev->stats.rx_packets++; | |
1494 | dev->stats.rx_bytes += rx->skb->len; | |
1495 | ||
1496 | ieee80211_deliver_skb(rx); | |
571ecf67 | 1497 | |
9ae54c84 | 1498 | return RX_QUEUED; |
571ecf67 JB |
1499 | } |
1500 | ||
9ae54c84 | 1501 | static ieee80211_rx_result |
71364716 RR |
1502 | ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx) |
1503 | { | |
1504 | struct ieee80211_local *local = rx->local; | |
1505 | struct ieee80211_hw *hw = &local->hw; | |
1506 | struct sk_buff *skb = rx->skb; | |
1507 | struct ieee80211_bar *bar = (struct ieee80211_bar *) skb->data; | |
1508 | struct tid_ampdu_rx *tid_agg_rx; | |
1509 | u16 start_seq_num; | |
1510 | u16 tid; | |
1511 | ||
1512 | if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL)) | |
9ae54c84 | 1513 | return RX_CONTINUE; |
71364716 RR |
1514 | |
1515 | if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) { | |
1516 | if (!rx->sta) | |
9ae54c84 | 1517 | return RX_CONTINUE; |
71364716 RR |
1518 | tid = le16_to_cpu(bar->control) >> 12; |
1519 | tid_agg_rx = &(rx->sta->ampdu_mlme.tid_rx[tid]); | |
1520 | if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL) | |
9ae54c84 | 1521 | return RX_CONTINUE; |
71364716 RR |
1522 | |
1523 | start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4; | |
1524 | ||
1525 | /* reset session timer */ | |
1526 | if (tid_agg_rx->timeout) { | |
1527 | unsigned long expires = | |
1528 | jiffies + (tid_agg_rx->timeout / 1000) * HZ; | |
1529 | mod_timer(&tid_agg_rx->session_timer, expires); | |
1530 | } | |
1531 | ||
1532 | /* manage reordering buffer according to requested */ | |
1533 | /* sequence number */ | |
1534 | rcu_read_lock(); | |
1535 | ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL, | |
1536 | start_seq_num, 1); | |
1537 | rcu_read_unlock(); | |
e4c26add | 1538 | return RX_DROP_UNUSABLE; |
71364716 RR |
1539 | } |
1540 | ||
9ae54c84 | 1541 | return RX_CONTINUE; |
71364716 RR |
1542 | } |
1543 | ||
9ae54c84 | 1544 | static ieee80211_rx_result |
571ecf67 JB |
1545 | ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx) |
1546 | { | |
1547 | struct ieee80211_sub_if_data *sdata; | |
1548 | ||
badffb72 | 1549 | if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
e4c26add | 1550 | return RX_DROP_MONITOR; |
571ecf67 JB |
1551 | |
1552 | sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); | |
51fb61e7 | 1553 | if ((sdata->vif.type == IEEE80211_IF_TYPE_STA || |
33b64eb2 LCC |
1554 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS || |
1555 | sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) && | |
ddd3d2be | 1556 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) |
571ecf67 | 1557 | ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status); |
f9d540ee | 1558 | else |
e4c26add | 1559 | return RX_DROP_MONITOR; |
f9d540ee | 1560 | |
9ae54c84 | 1561 | return RX_QUEUED; |
571ecf67 JB |
1562 | } |
1563 | ||
571ecf67 JB |
1564 | static void ieee80211_rx_michael_mic_report(struct net_device *dev, |
1565 | struct ieee80211_hdr *hdr, | |
571ecf67 JB |
1566 | struct ieee80211_txrx_data *rx) |
1567 | { | |
1568 | int keyidx, hdrlen; | |
0795af57 JP |
1569 | DECLARE_MAC_BUF(mac); |
1570 | DECLARE_MAC_BUF(mac2); | |
571ecf67 JB |
1571 | |
1572 | hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb); | |
1573 | if (rx->skb->len >= hdrlen + 4) | |
1574 | keyidx = rx->skb->data[hdrlen + 3] >> 6; | |
1575 | else | |
1576 | keyidx = -1; | |
1577 | ||
1a84f3fd JB |
1578 | if (net_ratelimit()) |
1579 | printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC " | |
0795af57 JP |
1580 | "failure from %s to %s keyidx=%d\n", |
1581 | dev->name, print_mac(mac, hdr->addr2), | |
1582 | print_mac(mac2, hdr->addr1), keyidx); | |
571ecf67 | 1583 | |
8944b79f | 1584 | if (!rx->sta) { |
aa0daf0e JB |
1585 | /* |
1586 | * Some hardware seem to generate incorrect Michael MIC | |
1587 | * reports; ignore them to avoid triggering countermeasures. | |
1588 | */ | |
1a84f3fd JB |
1589 | if (net_ratelimit()) |
1590 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " | |
0795af57 JP |
1591 | "error for unknown address %s\n", |
1592 | dev->name, print_mac(mac, hdr->addr2)); | |
571ecf67 JB |
1593 | goto ignore; |
1594 | } | |
1595 | ||
1596 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) { | |
1a84f3fd JB |
1597 | if (net_ratelimit()) |
1598 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " | |
aa0daf0e | 1599 | "error for a frame with no PROTECTED flag (src " |
0795af57 | 1600 | "%s)\n", dev->name, print_mac(mac, hdr->addr2)); |
571ecf67 JB |
1601 | goto ignore; |
1602 | } | |
1603 | ||
51fb61e7 | 1604 | if (rx->sdata->vif.type == IEEE80211_IF_TYPE_AP && keyidx) { |
aa0daf0e JB |
1605 | /* |
1606 | * APs with pairwise keys should never receive Michael MIC | |
1607 | * errors for non-zero keyidx because these are reserved for | |
1608 | * group keys and only the AP is sending real multicast | |
1609 | * frames in the BSS. | |
1610 | */ | |
eb063c17 JB |
1611 | if (net_ratelimit()) |
1612 | printk(KERN_DEBUG "%s: ignored Michael MIC error for " | |
1613 | "a frame with non-zero keyidx (%d)" | |
0795af57 JP |
1614 | " (src %s)\n", dev->name, keyidx, |
1615 | print_mac(mac, hdr->addr2)); | |
eb063c17 | 1616 | goto ignore; |
571ecf67 JB |
1617 | } |
1618 | ||
1619 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA && | |
1620 | ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || | |
1621 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) { | |
1a84f3fd JB |
1622 | if (net_ratelimit()) |
1623 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " | |
1624 | "error for a frame that cannot be encrypted " | |
0795af57 JP |
1625 | "(fc=0x%04x) (src %s)\n", |
1626 | dev->name, rx->fc, print_mac(mac, hdr->addr2)); | |
571ecf67 JB |
1627 | goto ignore; |
1628 | } | |
1629 | ||
eb063c17 | 1630 | mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr); |
571ecf67 JB |
1631 | ignore: |
1632 | dev_kfree_skb(rx->skb); | |
1633 | rx->skb = NULL; | |
1634 | } | |
1635 | ||
3d30d949 MW |
1636 | static void ieee80211_rx_cooked_monitor(struct ieee80211_txrx_data *rx) |
1637 | { | |
1638 | struct ieee80211_sub_if_data *sdata; | |
1639 | struct ieee80211_local *local = rx->local; | |
1640 | struct ieee80211_rtap_hdr { | |
1641 | struct ieee80211_radiotap_header hdr; | |
1642 | u8 flags; | |
1643 | u8 rate; | |
1644 | __le16 chan_freq; | |
1645 | __le16 chan_flags; | |
1646 | } __attribute__ ((packed)) *rthdr; | |
1647 | struct sk_buff *skb = rx->skb, *skb2; | |
1648 | struct net_device *prev_dev = NULL; | |
1649 | struct ieee80211_rx_status *status = rx->u.rx.status; | |
1650 | ||
1651 | if (rx->flags & IEEE80211_TXRXD_RX_CMNTR_REPORTED) | |
1652 | goto out_free_skb; | |
1653 | ||
1654 | if (skb_headroom(skb) < sizeof(*rthdr) && | |
1655 | pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) | |
1656 | goto out_free_skb; | |
1657 | ||
1658 | rthdr = (void *)skb_push(skb, sizeof(*rthdr)); | |
1659 | memset(rthdr, 0, sizeof(*rthdr)); | |
1660 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); | |
1661 | rthdr->hdr.it_present = | |
1662 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | | |
1663 | (1 << IEEE80211_RADIOTAP_RATE) | | |
1664 | (1 << IEEE80211_RADIOTAP_CHANNEL)); | |
1665 | ||
1666 | rthdr->rate = rx->u.rx.rate->bitrate / 5; | |
1667 | rthdr->chan_freq = cpu_to_le16(status->freq); | |
1668 | ||
1669 | if (status->band == IEEE80211_BAND_5GHZ) | |
1670 | rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM | | |
1671 | IEEE80211_CHAN_5GHZ); | |
1672 | else | |
1673 | rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN | | |
1674 | IEEE80211_CHAN_2GHZ); | |
1675 | ||
1676 | skb_set_mac_header(skb, 0); | |
1677 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
1678 | skb->pkt_type = PACKET_OTHERHOST; | |
1679 | skb->protocol = htons(ETH_P_802_2); | |
1680 | ||
1681 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
1682 | if (!netif_running(sdata->dev)) | |
1683 | continue; | |
1684 | ||
1685 | if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || | |
1686 | !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) | |
1687 | continue; | |
1688 | ||
1689 | if (prev_dev) { | |
1690 | skb2 = skb_clone(skb, GFP_ATOMIC); | |
1691 | if (skb2) { | |
1692 | skb2->dev = prev_dev; | |
1693 | netif_rx(skb2); | |
1694 | } | |
1695 | } | |
1696 | ||
1697 | prev_dev = sdata->dev; | |
1698 | sdata->dev->stats.rx_packets++; | |
1699 | sdata->dev->stats.rx_bytes += skb->len; | |
1700 | } | |
1701 | ||
1702 | if (prev_dev) { | |
1703 | skb->dev = prev_dev; | |
1704 | netif_rx(skb); | |
1705 | skb = NULL; | |
1706 | } else | |
1707 | goto out_free_skb; | |
1708 | ||
1709 | rx->flags |= IEEE80211_TXRXD_RX_CMNTR_REPORTED; | |
1710 | return; | |
1711 | ||
1712 | out_free_skb: | |
1713 | dev_kfree_skb(skb); | |
1714 | } | |
1715 | ||
58905290 JB |
1716 | typedef ieee80211_rx_result (*ieee80211_rx_handler)(struct ieee80211_txrx_data *); |
1717 | static ieee80211_rx_handler ieee80211_rx_handlers[] = | |
571ecf67 JB |
1718 | { |
1719 | ieee80211_rx_h_if_stats, | |
571ecf67 JB |
1720 | ieee80211_rx_h_passive_scan, |
1721 | ieee80211_rx_h_check, | |
4f0d18e2 | 1722 | ieee80211_rx_h_decrypt, |
70f08765 | 1723 | ieee80211_rx_h_sta_process, |
571ecf67 JB |
1724 | ieee80211_rx_h_defragment, |
1725 | ieee80211_rx_h_ps_poll, | |
1726 | ieee80211_rx_h_michael_mic_verify, | |
1727 | /* this must be after decryption - so header is counted in MPDU mic | |
1728 | * must be before pae and data, so QOS_DATA format frames | |
1729 | * are not passed to user space by these functions | |
1730 | */ | |
1731 | ieee80211_rx_h_remove_qos_control, | |
fd4c7f2f | 1732 | ieee80211_rx_h_amsdu, |
571ecf67 | 1733 | ieee80211_rx_h_data, |
71364716 | 1734 | ieee80211_rx_h_ctrl, |
571ecf67 JB |
1735 | ieee80211_rx_h_mgmt, |
1736 | NULL | |
1737 | }; | |
1738 | ||
8944b79f | 1739 | static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata, |
58905290 | 1740 | struct ieee80211_txrx_data *rx, |
8944b79f | 1741 | struct sk_buff *skb) |
58905290 JB |
1742 | { |
1743 | ieee80211_rx_handler *handler; | |
1744 | ieee80211_rx_result res = RX_DROP_MONITOR; | |
1745 | ||
8944b79f JB |
1746 | rx->skb = skb; |
1747 | rx->sdata = sdata; | |
1748 | rx->dev = sdata->dev; | |
1749 | ||
58905290 JB |
1750 | for (handler = ieee80211_rx_handlers; *handler != NULL; handler++) { |
1751 | res = (*handler)(rx); | |
1752 | ||
1753 | switch (res) { | |
1754 | case RX_CONTINUE: | |
1755 | continue; | |
1756 | case RX_DROP_UNUSABLE: | |
1757 | case RX_DROP_MONITOR: | |
8944b79f JB |
1758 | I802_DEBUG_INC(sdata->local->rx_handlers_drop); |
1759 | if (rx->sta) | |
1760 | rx->sta->rx_dropped++; | |
58905290 JB |
1761 | break; |
1762 | case RX_QUEUED: | |
8944b79f | 1763 | I802_DEBUG_INC(sdata->local->rx_handlers_queued); |
58905290 JB |
1764 | break; |
1765 | } | |
1766 | break; | |
1767 | } | |
1768 | ||
1769 | switch (res) { | |
3d30d949 | 1770 | case RX_CONTINUE: |
58905290 | 1771 | case RX_DROP_MONITOR: |
3d30d949 MW |
1772 | ieee80211_rx_cooked_monitor(rx); |
1773 | break; | |
58905290 | 1774 | case RX_DROP_UNUSABLE: |
58905290 JB |
1775 | dev_kfree_skb(rx->skb); |
1776 | break; | |
1777 | } | |
1778 | } | |
1779 | ||
571ecf67 JB |
1780 | /* main receive path */ |
1781 | ||
23a24def JB |
1782 | static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata, |
1783 | u8 *bssid, struct ieee80211_txrx_data *rx, | |
1784 | struct ieee80211_hdr *hdr) | |
1785 | { | |
1786 | int multicast = is_multicast_ether_addr(hdr->addr1); | |
1787 | ||
51fb61e7 | 1788 | switch (sdata->vif.type) { |
23a24def JB |
1789 | case IEEE80211_IF_TYPE_STA: |
1790 | if (!bssid) | |
1791 | return 0; | |
1792 | if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { | |
badffb72 | 1793 | if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) |
23a24def | 1794 | return 0; |
badffb72 | 1795 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
23a24def JB |
1796 | } else if (!multicast && |
1797 | compare_ether_addr(sdata->dev->dev_addr, | |
1798 | hdr->addr1) != 0) { | |
4150c572 | 1799 | if (!(sdata->dev->flags & IFF_PROMISC)) |
23a24def | 1800 | return 0; |
badffb72 | 1801 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
23a24def JB |
1802 | } |
1803 | break; | |
1804 | case IEEE80211_IF_TYPE_IBSS: | |
1805 | if (!bssid) | |
1806 | return 0; | |
9d9bf77d BR |
1807 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && |
1808 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) | |
1809 | return 1; | |
1810 | else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { | |
badffb72 | 1811 | if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) |
23a24def | 1812 | return 0; |
badffb72 | 1813 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
23a24def JB |
1814 | } else if (!multicast && |
1815 | compare_ether_addr(sdata->dev->dev_addr, | |
1816 | hdr->addr1) != 0) { | |
4150c572 | 1817 | if (!(sdata->dev->flags & IFF_PROMISC)) |
23a24def | 1818 | return 0; |
badffb72 | 1819 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
23a24def JB |
1820 | } else if (!rx->sta) |
1821 | rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb, | |
1822 | bssid, hdr->addr2); | |
1823 | break; | |
6032f934 JB |
1824 | case IEEE80211_IF_TYPE_MESH_POINT: |
1825 | if (!multicast && | |
1826 | compare_ether_addr(sdata->dev->dev_addr, | |
1827 | hdr->addr1) != 0) { | |
1828 | if (!(sdata->dev->flags & IFF_PROMISC)) | |
1829 | return 0; | |
1830 | ||
1831 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; | |
1832 | } | |
1833 | break; | |
fb1c1cd6 | 1834 | case IEEE80211_IF_TYPE_VLAN: |
23a24def JB |
1835 | case IEEE80211_IF_TYPE_AP: |
1836 | if (!bssid) { | |
1837 | if (compare_ether_addr(sdata->dev->dev_addr, | |
1838 | hdr->addr1)) | |
1839 | return 0; | |
1840 | } else if (!ieee80211_bssid_match(bssid, | |
1841 | sdata->dev->dev_addr)) { | |
badffb72 | 1842 | if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) |
23a24def | 1843 | return 0; |
badffb72 | 1844 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
23a24def | 1845 | } |
badffb72 JS |
1846 | if (sdata->dev == sdata->local->mdev && |
1847 | !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) | |
23a24def JB |
1848 | /* do not receive anything via |
1849 | * master device when not scanning */ | |
1850 | return 0; | |
1851 | break; | |
1852 | case IEEE80211_IF_TYPE_WDS: | |
1853 | if (bssid || | |
1854 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) | |
1855 | return 0; | |
1856 | if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2)) | |
1857 | return 0; | |
1858 | break; | |
fb1c1cd6 JB |
1859 | case IEEE80211_IF_TYPE_MNTR: |
1860 | /* take everything */ | |
1861 | break; | |
a2897552 | 1862 | case IEEE80211_IF_TYPE_INVALID: |
fb1c1cd6 JB |
1863 | /* should never get here */ |
1864 | WARN_ON(1); | |
1865 | break; | |
23a24def JB |
1866 | } |
1867 | ||
1868 | return 1; | |
1869 | } | |
1870 | ||
571ecf67 | 1871 | /* |
6368e4b1 RR |
1872 | * This is the actual Rx frames handler. as it blongs to Rx path it must |
1873 | * be called with rcu_read_lock protection. | |
571ecf67 | 1874 | */ |
71ebb4aa RR |
1875 | static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, |
1876 | struct sk_buff *skb, | |
1877 | struct ieee80211_rx_status *status, | |
8318d78a JB |
1878 | u32 load, |
1879 | struct ieee80211_rate *rate) | |
571ecf67 JB |
1880 | { |
1881 | struct ieee80211_local *local = hw_to_local(hw); | |
1882 | struct ieee80211_sub_if_data *sdata; | |
571ecf67 JB |
1883 | struct ieee80211_hdr *hdr; |
1884 | struct ieee80211_txrx_data rx; | |
1885 | u16 type; | |
6368e4b1 | 1886 | int prepares; |
8e6f0032 JB |
1887 | struct ieee80211_sub_if_data *prev = NULL; |
1888 | struct sk_buff *skb_new; | |
1889 | u8 *bssid; | |
571ecf67 JB |
1890 | |
1891 | hdr = (struct ieee80211_hdr *) skb->data; | |
1892 | memset(&rx, 0, sizeof(rx)); | |
1893 | rx.skb = skb; | |
1894 | rx.local = local; | |
1895 | ||
1896 | rx.u.rx.status = status; | |
6368e4b1 | 1897 | rx.u.rx.load = load; |
8318d78a | 1898 | rx.u.rx.rate = rate; |
b2e7771e | 1899 | rx.fc = le16_to_cpu(hdr->frame_control); |
571ecf67 | 1900 | type = rx.fc & IEEE80211_FCTL_FTYPE; |
72abd81b | 1901 | |
b2e7771e | 1902 | if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT) |
571ecf67 | 1903 | local->dot11ReceivedFragmentCount++; |
571ecf67 | 1904 | |
8944b79f JB |
1905 | rx.sta = sta_info_get(local, hdr->addr2); |
1906 | if (rx.sta) { | |
b2e7771e JB |
1907 | rx.dev = rx.sta->dev; |
1908 | rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev); | |
1909 | } | |
571ecf67 | 1910 | |
571ecf67 | 1911 | if ((status->flag & RX_FLAG_MMIC_ERROR)) { |
8944b79f | 1912 | ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx); |
571ecf67 JB |
1913 | goto end; |
1914 | } | |
1915 | ||
ece8eddd | 1916 | if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning)) |
badffb72 | 1917 | rx.flags |= IEEE80211_TXRXD_RXIN_SCAN; |
571ecf67 | 1918 | |
38f3714d JB |
1919 | ieee80211_parse_qos(&rx); |
1920 | ieee80211_verify_ip_alignment(&rx); | |
1921 | ||
571ecf67 JB |
1922 | skb = rx.skb; |
1923 | ||
79010420 | 1924 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
2a8a9a88 JB |
1925 | if (!netif_running(sdata->dev)) |
1926 | continue; | |
1927 | ||
51fb61e7 | 1928 | if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) |
b2e7771e JB |
1929 | continue; |
1930 | ||
51fb61e7 | 1931 | bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); |
b2e7771e | 1932 | rx.flags |= IEEE80211_TXRXD_RXRA_MATCH; |
6368e4b1 | 1933 | prepares = prepare_for_handlers(sdata, bssid, &rx, hdr); |
23a24def | 1934 | |
6368e4b1 | 1935 | if (!prepares) |
23a24def | 1936 | continue; |
8e6f0032 | 1937 | |
340e11f3 JB |
1938 | /* |
1939 | * frame is destined for this interface, but if it's not | |
1940 | * also for the previous one we handle that after the | |
1941 | * loop to avoid copying the SKB once too much | |
1942 | */ | |
1943 | ||
1944 | if (!prev) { | |
1945 | prev = sdata; | |
1946 | continue; | |
8e6f0032 | 1947 | } |
340e11f3 JB |
1948 | |
1949 | /* | |
1950 | * frame was destined for the previous interface | |
1951 | * so invoke RX handlers for it | |
1952 | */ | |
1953 | ||
1954 | skb_new = skb_copy(skb, GFP_ATOMIC); | |
1955 | if (!skb_new) { | |
1956 | if (net_ratelimit()) | |
1957 | printk(KERN_DEBUG "%s: failed to copy " | |
1958 | "multicast frame for %s", | |
dd1cd4c6 JB |
1959 | wiphy_name(local->hw.wiphy), |
1960 | prev->dev->name); | |
340e11f3 JB |
1961 | continue; |
1962 | } | |
69f817b6 | 1963 | rx.fc = le16_to_cpu(hdr->frame_control); |
8944b79f | 1964 | ieee80211_invoke_rx_handlers(prev, &rx, skb_new); |
8e6f0032 | 1965 | prev = sdata; |
571ecf67 | 1966 | } |
8e6f0032 | 1967 | if (prev) { |
69f817b6 | 1968 | rx.fc = le16_to_cpu(hdr->frame_control); |
8944b79f | 1969 | ieee80211_invoke_rx_handlers(prev, &rx, skb); |
8e6f0032 JB |
1970 | } else |
1971 | dev_kfree_skb(skb); | |
571ecf67 | 1972 | |
8e6f0032 | 1973 | end: |
8944b79f JB |
1974 | if (rx.sta) |
1975 | sta_info_put(rx.sta); | |
571ecf67 | 1976 | } |
6368e4b1 | 1977 | |
b580781e RR |
1978 | #define SEQ_MODULO 0x1000 |
1979 | #define SEQ_MASK 0xfff | |
1980 | ||
1981 | static inline int seq_less(u16 sq1, u16 sq2) | |
1982 | { | |
1983 | return (((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1)); | |
1984 | } | |
1985 | ||
1986 | static inline u16 seq_inc(u16 sq) | |
1987 | { | |
1988 | return ((sq + 1) & SEQ_MASK); | |
1989 | } | |
1990 | ||
1991 | static inline u16 seq_sub(u16 sq1, u16 sq2) | |
1992 | { | |
1993 | return ((sq1 - sq2) & SEQ_MASK); | |
1994 | } | |
1995 | ||
1996 | ||
71364716 RR |
1997 | /* |
1998 | * As it function blongs to Rx path it must be called with | |
1999 | * the proper rcu_read_lock protection for its flow. | |
2000 | */ | |
b580781e RR |
2001 | u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, |
2002 | struct tid_ampdu_rx *tid_agg_rx, | |
2003 | struct sk_buff *skb, u16 mpdu_seq_num, | |
2004 | int bar_req) | |
2005 | { | |
2006 | struct ieee80211_local *local = hw_to_local(hw); | |
2007 | struct ieee80211_rx_status status; | |
2008 | u16 head_seq_num, buf_size; | |
2009 | int index; | |
2010 | u32 pkt_load; | |
8318d78a JB |
2011 | struct ieee80211_supported_band *sband; |
2012 | struct ieee80211_rate *rate; | |
b580781e RR |
2013 | |
2014 | buf_size = tid_agg_rx->buf_size; | |
2015 | head_seq_num = tid_agg_rx->head_seq_num; | |
2016 | ||
2017 | /* frame with out of date sequence number */ | |
2018 | if (seq_less(mpdu_seq_num, head_seq_num)) { | |
2019 | dev_kfree_skb(skb); | |
2020 | return 1; | |
2021 | } | |
2022 | ||
2023 | /* if frame sequence number exceeds our buffering window size or | |
2024 | * block Ack Request arrived - release stored frames */ | |
2025 | if ((!seq_less(mpdu_seq_num, head_seq_num + buf_size)) || (bar_req)) { | |
2026 | /* new head to the ordering buffer */ | |
2027 | if (bar_req) | |
2028 | head_seq_num = mpdu_seq_num; | |
2029 | else | |
2030 | head_seq_num = | |
2031 | seq_inc(seq_sub(mpdu_seq_num, buf_size)); | |
2032 | /* release stored frames up to new head to stack */ | |
2033 | while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) { | |
2034 | index = seq_sub(tid_agg_rx->head_seq_num, | |
2035 | tid_agg_rx->ssn) | |
2036 | % tid_agg_rx->buf_size; | |
2037 | ||
2038 | if (tid_agg_rx->reorder_buf[index]) { | |
2039 | /* release the reordered frames to stack */ | |
2040 | memcpy(&status, | |
2041 | tid_agg_rx->reorder_buf[index]->cb, | |
2042 | sizeof(status)); | |
8318d78a JB |
2043 | sband = local->hw.wiphy->bands[status.band]; |
2044 | rate = &sband->bitrates[status.rate_idx]; | |
b580781e RR |
2045 | pkt_load = ieee80211_rx_load_stats(local, |
2046 | tid_agg_rx->reorder_buf[index], | |
8318d78a | 2047 | &status, rate); |
b580781e RR |
2048 | __ieee80211_rx_handle_packet(hw, |
2049 | tid_agg_rx->reorder_buf[index], | |
8318d78a | 2050 | &status, pkt_load, rate); |
b580781e RR |
2051 | tid_agg_rx->stored_mpdu_num--; |
2052 | tid_agg_rx->reorder_buf[index] = NULL; | |
2053 | } | |
2054 | tid_agg_rx->head_seq_num = | |
2055 | seq_inc(tid_agg_rx->head_seq_num); | |
2056 | } | |
2057 | if (bar_req) | |
2058 | return 1; | |
2059 | } | |
2060 | ||
2061 | /* now the new frame is always in the range of the reordering */ | |
2062 | /* buffer window */ | |
2063 | index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) | |
2064 | % tid_agg_rx->buf_size; | |
2065 | /* check if we already stored this frame */ | |
2066 | if (tid_agg_rx->reorder_buf[index]) { | |
2067 | dev_kfree_skb(skb); | |
2068 | return 1; | |
2069 | } | |
2070 | ||
2071 | /* if arrived mpdu is in the right order and nothing else stored */ | |
2072 | /* release it immediately */ | |
2073 | if (mpdu_seq_num == tid_agg_rx->head_seq_num && | |
2074 | tid_agg_rx->stored_mpdu_num == 0) { | |
2075 | tid_agg_rx->head_seq_num = | |
2076 | seq_inc(tid_agg_rx->head_seq_num); | |
2077 | return 0; | |
2078 | } | |
2079 | ||
2080 | /* put the frame in the reordering buffer */ | |
2081 | tid_agg_rx->reorder_buf[index] = skb; | |
2082 | tid_agg_rx->stored_mpdu_num++; | |
2083 | /* release the buffer until next missing frame */ | |
2084 | index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) | |
2085 | % tid_agg_rx->buf_size; | |
2086 | while (tid_agg_rx->reorder_buf[index]) { | |
2087 | /* release the reordered frame back to stack */ | |
2088 | memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, | |
2089 | sizeof(status)); | |
8318d78a JB |
2090 | sband = local->hw.wiphy->bands[status.band]; |
2091 | rate = &sband->bitrates[status.rate_idx]; | |
b580781e RR |
2092 | pkt_load = ieee80211_rx_load_stats(local, |
2093 | tid_agg_rx->reorder_buf[index], | |
8318d78a | 2094 | &status, rate); |
b580781e | 2095 | __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], |
8318d78a | 2096 | &status, pkt_load, rate); |
b580781e RR |
2097 | tid_agg_rx->stored_mpdu_num--; |
2098 | tid_agg_rx->reorder_buf[index] = NULL; | |
2099 | tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); | |
2100 | index = seq_sub(tid_agg_rx->head_seq_num, | |
2101 | tid_agg_rx->ssn) % tid_agg_rx->buf_size; | |
2102 | } | |
2103 | return 1; | |
2104 | } | |
2105 | ||
71ebb4aa RR |
2106 | static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local, |
2107 | struct sk_buff *skb) | |
b580781e RR |
2108 | { |
2109 | struct ieee80211_hw *hw = &local->hw; | |
2110 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
2111 | struct sta_info *sta; | |
2112 | struct tid_ampdu_rx *tid_agg_rx; | |
2113 | u16 fc, sc; | |
2114 | u16 mpdu_seq_num; | |
2115 | u8 ret = 0, *qc; | |
2116 | int tid; | |
2117 | ||
2118 | sta = sta_info_get(local, hdr->addr2); | |
2119 | if (!sta) | |
2120 | return ret; | |
2121 | ||
2122 | fc = le16_to_cpu(hdr->frame_control); | |
2123 | ||
2124 | /* filter the QoS data rx stream according to | |
2125 | * STA/TID and check if this STA/TID is on aggregation */ | |
2126 | if (!WLAN_FC_IS_QOS_DATA(fc)) | |
2127 | goto end_reorder; | |
2128 | ||
2129 | qc = skb->data + ieee80211_get_hdrlen(fc) - QOS_CONTROL_LEN; | |
2130 | tid = qc[0] & QOS_CONTROL_TID_MASK; | |
2131 | tid_agg_rx = &(sta->ampdu_mlme.tid_rx[tid]); | |
2132 | ||
2133 | if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL) | |
2134 | goto end_reorder; | |
2135 | ||
2136 | /* null data frames are excluded */ | |
8b6bbe75 | 2137 | if (unlikely(fc & IEEE80211_STYPE_NULLFUNC)) |
b580781e RR |
2138 | goto end_reorder; |
2139 | ||
2140 | /* new un-ordered ampdu frame - process it */ | |
2141 | ||
2142 | /* reset session timer */ | |
2143 | if (tid_agg_rx->timeout) { | |
2144 | unsigned long expires = | |
2145 | jiffies + (tid_agg_rx->timeout / 1000) * HZ; | |
2146 | mod_timer(&tid_agg_rx->session_timer, expires); | |
2147 | } | |
2148 | ||
2149 | /* if this mpdu is fragmented - terminate rx aggregation session */ | |
2150 | sc = le16_to_cpu(hdr->seq_ctrl); | |
2151 | if (sc & IEEE80211_SCTL_FRAG) { | |
2152 | ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, | |
2153 | tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP); | |
2154 | ret = 1; | |
2155 | goto end_reorder; | |
2156 | } | |
2157 | ||
2158 | /* according to mpdu sequence number deal with reordering buffer */ | |
2159 | mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; | |
2160 | ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, | |
2161 | mpdu_seq_num, 0); | |
2162 | end_reorder: | |
2163 | if (sta) | |
2164 | sta_info_put(sta); | |
2165 | return ret; | |
2166 | } | |
2167 | ||
6368e4b1 RR |
2168 | /* |
2169 | * This is the receive path handler. It is called by a low level driver when an | |
2170 | * 802.11 MPDU is received from the hardware. | |
2171 | */ | |
2172 | void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, | |
2173 | struct ieee80211_rx_status *status) | |
2174 | { | |
2175 | struct ieee80211_local *local = hw_to_local(hw); | |
2176 | u32 pkt_load; | |
8318d78a JB |
2177 | struct ieee80211_rate *rate = NULL; |
2178 | struct ieee80211_supported_band *sband; | |
2179 | ||
2180 | if (status->band < 0 || | |
2181 | status->band > IEEE80211_NUM_BANDS) { | |
2182 | WARN_ON(1); | |
2183 | return; | |
2184 | } | |
2185 | ||
2186 | sband = local->hw.wiphy->bands[status->band]; | |
2187 | ||
2188 | if (!sband || | |
2189 | status->rate_idx < 0 || | |
2190 | status->rate_idx >= sband->n_bitrates) { | |
2191 | WARN_ON(1); | |
2192 | return; | |
2193 | } | |
2194 | ||
2195 | rate = &sband->bitrates[status->rate_idx]; | |
6368e4b1 RR |
2196 | |
2197 | /* | |
2198 | * key references and virtual interfaces are protected using RCU | |
2199 | * and this requires that we are in a read-side RCU section during | |
2200 | * receive processing | |
2201 | */ | |
2202 | rcu_read_lock(); | |
2203 | ||
2204 | /* | |
2205 | * Frames with failed FCS/PLCP checksum are not returned, | |
2206 | * all other frames are returned without radiotap header | |
2207 | * if it was previously present. | |
2208 | * Also, frames with less than 16 bytes are dropped. | |
2209 | */ | |
8318d78a | 2210 | skb = ieee80211_rx_monitor(local, skb, status, rate); |
6368e4b1 RR |
2211 | if (!skb) { |
2212 | rcu_read_unlock(); | |
2213 | return; | |
2214 | } | |
2215 | ||
8318d78a | 2216 | pkt_load = ieee80211_rx_load_stats(local, skb, status, rate); |
b580781e | 2217 | local->channel_use_raw += pkt_load; |
6368e4b1 | 2218 | |
b580781e | 2219 | if (!ieee80211_rx_reorder_ampdu(local, skb)) |
8318d78a | 2220 | __ieee80211_rx_handle_packet(hw, skb, status, pkt_load, rate); |
6368e4b1 RR |
2221 | |
2222 | rcu_read_unlock(); | |
2223 | } | |
571ecf67 JB |
2224 | EXPORT_SYMBOL(__ieee80211_rx); |
2225 | ||
2226 | /* This is a version of the rx handler that can be called from hard irq | |
2227 | * context. Post the skb on the queue and schedule the tasklet */ | |
2228 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb, | |
2229 | struct ieee80211_rx_status *status) | |
2230 | { | |
2231 | struct ieee80211_local *local = hw_to_local(hw); | |
2232 | ||
2233 | BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); | |
2234 | ||
2235 | skb->dev = local->mdev; | |
2236 | /* copy status into skb->cb for use by tasklet */ | |
2237 | memcpy(skb->cb, status, sizeof(*status)); | |
2238 | skb->pkt_type = IEEE80211_RX_MSG; | |
2239 | skb_queue_tail(&local->skb_queue, skb); | |
2240 | tasklet_schedule(&local->tasklet); | |
2241 | } | |
2242 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |