]>
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 | ||
12 | #include <linux/kernel.h> | |
13 | #include <linux/skbuff.h> | |
14 | #include <linux/netdevice.h> | |
15 | #include <linux/etherdevice.h> | |
16 | #include <net/iw_handler.h> | |
17 | #include <net/mac80211.h> | |
18 | #include <net/ieee80211_radiotap.h> | |
19 | ||
20 | #include "ieee80211_i.h" | |
21 | #include "ieee80211_led.h" | |
22 | #include "ieee80211_common.h" | |
23 | #include "wep.h" | |
24 | #include "wpa.h" | |
25 | #include "tkip.h" | |
26 | #include "wme.h" | |
27 | ||
28 | /* pre-rx handlers | |
29 | * | |
30 | * these don't have dev/sdata fields in the rx data | |
52865dfd JB |
31 | * The sta value should also not be used because it may |
32 | * be NULL even though a STA (in IBSS mode) will be added. | |
571ecf67 JB |
33 | */ |
34 | ||
6e0d114d JB |
35 | static ieee80211_txrx_result |
36 | ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx) | |
37 | { | |
38 | u8 *data = rx->skb->data; | |
39 | int tid; | |
40 | ||
41 | /* does the frame have a qos control field? */ | |
42 | if (WLAN_FC_IS_QOS_DATA(rx->fc)) { | |
43 | u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN; | |
44 | /* frame has qos control */ | |
45 | tid = qc[0] & QOS_CONTROL_TID_MASK; | |
46 | } else { | |
47 | if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) { | |
48 | /* Separate TID for management frames */ | |
49 | tid = NUM_RX_DATA_QUEUES - 1; | |
50 | } else { | |
51 | /* no qos control present */ | |
52 | tid = 0; /* 802.1d - Best Effort */ | |
53 | } | |
54 | } | |
52865dfd | 55 | |
6e0d114d | 56 | I802_DEBUG_INC(rx->local->wme_rx_queue[tid]); |
52865dfd JB |
57 | /* only a debug counter, sta might not be assigned properly yet */ |
58 | if (rx->sta) | |
6e0d114d | 59 | I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]); |
6e0d114d JB |
60 | |
61 | rx->u.rx.queue = tid; | |
62 | /* Set skb->priority to 1d tag if highest order bit of TID is not set. | |
63 | * For now, set skb->priority to 0 for other cases. */ | |
64 | rx->skb->priority = (tid > 7) ? 0 : tid; | |
65 | ||
66 | return TXRX_CONTINUE; | |
67 | } | |
68 | ||
571ecf67 JB |
69 | static ieee80211_txrx_result |
70 | ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx) | |
71 | { | |
72 | struct ieee80211_local *local = rx->local; | |
73 | struct sk_buff *skb = rx->skb; | |
74 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
75 | u32 load = 0, hdrtime; | |
76 | struct ieee80211_rate *rate; | |
77 | struct ieee80211_hw_mode *mode = local->hw.conf.mode; | |
78 | int i; | |
79 | ||
80 | /* Estimate total channel use caused by this frame */ | |
81 | ||
82 | if (unlikely(mode->num_rates < 0)) | |
83 | return TXRX_CONTINUE; | |
84 | ||
85 | rate = &mode->rates[0]; | |
86 | for (i = 0; i < mode->num_rates; i++) { | |
87 | if (mode->rates[i].val == rx->u.rx.status->rate) { | |
88 | rate = &mode->rates[i]; | |
89 | break; | |
90 | } | |
91 | } | |
92 | ||
93 | /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values, | |
94 | * 1 usec = 1/8 * (1080 / 10) = 13.5 */ | |
95 | ||
96 | if (mode->mode == MODE_IEEE80211A || | |
97 | mode->mode == MODE_ATHEROS_TURBO || | |
98 | mode->mode == MODE_ATHEROS_TURBOG || | |
99 | (mode->mode == MODE_IEEE80211G && | |
100 | rate->flags & IEEE80211_RATE_ERP)) | |
101 | hdrtime = CHAN_UTIL_HDR_SHORT; | |
102 | else | |
103 | hdrtime = CHAN_UTIL_HDR_LONG; | |
104 | ||
105 | load = hdrtime; | |
106 | if (!is_multicast_ether_addr(hdr->addr1)) | |
107 | load += hdrtime; | |
108 | ||
109 | load += skb->len * rate->rate_inv; | |
110 | ||
111 | /* Divide channel_use by 8 to avoid wrapping around the counter */ | |
112 | load >>= CHAN_UTIL_SHIFT; | |
113 | local->channel_use_raw += load; | |
571ecf67 JB |
114 | rx->u.rx.load = load; |
115 | ||
116 | return TXRX_CONTINUE; | |
117 | } | |
118 | ||
119 | ieee80211_rx_handler ieee80211_rx_pre_handlers[] = | |
120 | { | |
121 | ieee80211_rx_h_parse_qos, | |
122 | ieee80211_rx_h_load_stats, | |
123 | NULL | |
124 | }; | |
125 | ||
126 | /* rx handlers */ | |
127 | ||
128 | static ieee80211_txrx_result | |
129 | ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx) | |
130 | { | |
52865dfd JB |
131 | if (rx->sta) |
132 | rx->sta->channel_use_raw += rx->u.rx.load; | |
571ecf67 JB |
133 | rx->sdata->channel_use_raw += rx->u.rx.load; |
134 | return TXRX_CONTINUE; | |
135 | } | |
136 | ||
137 | static void | |
138 | ieee80211_rx_monitor(struct net_device *dev, struct sk_buff *skb, | |
139 | struct ieee80211_rx_status *status) | |
140 | { | |
141 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
142 | struct ieee80211_sub_if_data *sdata; | |
143 | struct ieee80211_rate *rate; | |
144 | struct ieee80211_rtap_hdr { | |
145 | struct ieee80211_radiotap_header hdr; | |
146 | u8 flags; | |
147 | u8 rate; | |
148 | __le16 chan_freq; | |
149 | __le16 chan_flags; | |
150 | u8 antsignal; | |
151 | } __attribute__ ((packed)) *rthdr; | |
152 | ||
153 | skb->dev = dev; | |
154 | ||
155 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
156 | ||
157 | if (status->flag & RX_FLAG_RADIOTAP) | |
158 | goto out; | |
159 | ||
160 | if (skb_headroom(skb) < sizeof(*rthdr)) { | |
161 | I802_DEBUG_INC(local->rx_expand_skb_head); | |
162 | if (pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) { | |
163 | dev_kfree_skb(skb); | |
164 | return; | |
165 | } | |
166 | } | |
167 | ||
168 | rthdr = (struct ieee80211_rtap_hdr *) skb_push(skb, sizeof(*rthdr)); | |
169 | memset(rthdr, 0, sizeof(*rthdr)); | |
170 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); | |
171 | rthdr->hdr.it_present = | |
172 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | | |
173 | (1 << IEEE80211_RADIOTAP_RATE) | | |
174 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | |
175 | (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)); | |
176 | rthdr->flags = local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS ? | |
177 | IEEE80211_RADIOTAP_F_FCS : 0; | |
178 | rate = ieee80211_get_rate(local, status->phymode, status->rate); | |
179 | if (rate) | |
180 | rthdr->rate = rate->rate / 5; | |
181 | rthdr->chan_freq = cpu_to_le16(status->freq); | |
182 | rthdr->chan_flags = | |
183 | status->phymode == MODE_IEEE80211A ? | |
184 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ) : | |
185 | cpu_to_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ); | |
186 | rthdr->antsignal = status->ssi; | |
187 | ||
188 | out: | |
189 | sdata->stats.rx_packets++; | |
190 | sdata->stats.rx_bytes += skb->len; | |
191 | ||
192 | skb_set_mac_header(skb, 0); | |
193 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
194 | skb->pkt_type = PACKET_OTHERHOST; | |
195 | skb->protocol = htons(ETH_P_802_2); | |
196 | memset(skb->cb, 0, sizeof(skb->cb)); | |
197 | netif_rx(skb); | |
198 | } | |
199 | ||
200 | static ieee80211_txrx_result | |
201 | ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx) | |
202 | { | |
203 | if (rx->sdata->type == IEEE80211_IF_TYPE_MNTR) { | |
204 | ieee80211_rx_monitor(rx->dev, rx->skb, rx->u.rx.status); | |
205 | return TXRX_QUEUED; | |
206 | } | |
207 | ||
208 | if (rx->u.rx.status->flag & RX_FLAG_RADIOTAP) | |
209 | skb_pull(rx->skb, ieee80211_get_radiotap_len(rx->skb->data)); | |
210 | ||
211 | return TXRX_CONTINUE; | |
212 | } | |
213 | ||
214 | static ieee80211_txrx_result | |
215 | ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx) | |
216 | { | |
217 | struct ieee80211_local *local = rx->local; | |
218 | struct sk_buff *skb = rx->skb; | |
219 | ||
220 | if (unlikely(local->sta_scanning != 0)) { | |
221 | ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status); | |
222 | return TXRX_QUEUED; | |
223 | } | |
224 | ||
225 | if (unlikely(rx->u.rx.in_scan)) { | |
226 | /* scanning finished during invoking of handlers */ | |
227 | I802_DEBUG_INC(local->rx_handlers_drop_passive_scan); | |
228 | return TXRX_DROP; | |
229 | } | |
230 | ||
231 | return TXRX_CONTINUE; | |
232 | } | |
233 | ||
234 | static ieee80211_txrx_result | |
235 | ieee80211_rx_h_check(struct ieee80211_txrx_data *rx) | |
236 | { | |
237 | struct ieee80211_hdr *hdr; | |
571ecf67 JB |
238 | hdr = (struct ieee80211_hdr *) rx->skb->data; |
239 | ||
240 | /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */ | |
241 | if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) { | |
242 | if (unlikely(rx->fc & IEEE80211_FCTL_RETRY && | |
243 | rx->sta->last_seq_ctrl[rx->u.rx.queue] == | |
244 | hdr->seq_ctrl)) { | |
245 | if (rx->u.rx.ra_match) { | |
246 | rx->local->dot11FrameDuplicateCount++; | |
247 | rx->sta->num_duplicates++; | |
248 | } | |
249 | return TXRX_DROP; | |
250 | } else | |
251 | rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl; | |
252 | } | |
253 | ||
254 | if ((rx->local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) && | |
255 | rx->skb->len > FCS_LEN) | |
256 | skb_trim(rx->skb, rx->skb->len - FCS_LEN); | |
257 | ||
258 | if (unlikely(rx->skb->len < 16)) { | |
259 | I802_DEBUG_INC(rx->local->rx_handlers_drop_short); | |
260 | return TXRX_DROP; | |
261 | } | |
262 | ||
263 | if (!rx->u.rx.ra_match) | |
264 | rx->skb->pkt_type = PACKET_OTHERHOST; | |
265 | else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0) | |
266 | rx->skb->pkt_type = PACKET_HOST; | |
267 | else if (is_multicast_ether_addr(hdr->addr1)) { | |
268 | if (is_broadcast_ether_addr(hdr->addr1)) | |
269 | rx->skb->pkt_type = PACKET_BROADCAST; | |
270 | else | |
271 | rx->skb->pkt_type = PACKET_MULTICAST; | |
272 | } else | |
273 | rx->skb->pkt_type = PACKET_OTHERHOST; | |
274 | ||
275 | /* Drop disallowed frame classes based on STA auth/assoc state; | |
276 | * IEEE 802.11, Chap 5.5. | |
277 | * | |
278 | * 80211.o does filtering only based on association state, i.e., it | |
279 | * drops Class 3 frames from not associated stations. hostapd sends | |
280 | * deauth/disassoc frames when needed. In addition, hostapd is | |
281 | * responsible for filtering on both auth and assoc states. | |
282 | */ | |
283 | if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA || | |
284 | ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL && | |
285 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) && | |
286 | rx->sdata->type != IEEE80211_IF_TYPE_IBSS && | |
287 | (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) { | |
288 | if ((!(rx->fc & IEEE80211_FCTL_FROMDS) && | |
289 | !(rx->fc & IEEE80211_FCTL_TODS) && | |
290 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) | |
291 | || !rx->u.rx.ra_match) { | |
292 | /* Drop IBSS frames and frames for other hosts | |
293 | * silently. */ | |
294 | return TXRX_DROP; | |
295 | } | |
296 | ||
297 | if (!rx->local->apdev) | |
298 | return TXRX_DROP; | |
299 | ||
300 | ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status, | |
301 | ieee80211_msg_sta_not_assoc); | |
302 | return TXRX_QUEUED; | |
303 | } | |
304 | ||
570bd537 JB |
305 | return TXRX_CONTINUE; |
306 | } | |
307 | ||
308 | ||
309 | static ieee80211_txrx_result | |
310 | ieee80211_rx_h_load_key(struct ieee80211_txrx_data *rx) | |
311 | { | |
312 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; | |
3017b80b JB |
313 | int keyidx; |
314 | int hdrlen; | |
570bd537 | 315 | |
3017b80b JB |
316 | /* |
317 | * Key selection 101 | |
318 | * | |
319 | * There are three types of keys: | |
320 | * - GTK (group keys) | |
321 | * - PTK (pairwise keys) | |
322 | * - STK (station-to-station pairwise keys) | |
323 | * | |
324 | * When selecting a key, we have to distinguish between multicast | |
325 | * (including broadcast) and unicast frames, the latter can only | |
326 | * use PTKs and STKs while the former always use GTKs. Unless, of | |
327 | * course, actual WEP keys ("pre-RSNA") are used, then unicast | |
328 | * frames can also use key indizes like GTKs. Hence, if we don't | |
329 | * have a PTK/STK we check the key index for a WEP key. | |
330 | * | |
331 | * There is also a slight problem in IBSS mode: GTKs are negotiated | |
332 | * with each station, that is something we don't currently handle. | |
333 | */ | |
334 | ||
335 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) | |
336 | return TXRX_CONTINUE; | |
571ecf67 | 337 | |
3017b80b JB |
338 | /* |
339 | * No point in finding a key if the frame is neither | |
340 | * addressed to us nor a multicast frame. | |
341 | */ | |
342 | if (!rx->u.rx.ra_match) | |
343 | return TXRX_CONTINUE; | |
344 | ||
345 | if (!is_multicast_ether_addr(hdr->addr1) && rx->sta && rx->sta->key) { | |
571ecf67 JB |
346 | rx->key = rx->sta->key; |
347 | } else { | |
3017b80b JB |
348 | /* |
349 | * The device doesn't give us the IV so we won't be | |
350 | * able to look up the key. That's ok though, we | |
351 | * don't need to decrypt the frame, we just won't | |
352 | * be able to keep statistics accurate. | |
353 | * Except for key threshold notifications, should | |
354 | * we somehow allow the driver to tell us which key | |
355 | * the hardware used if this flag is set? | |
356 | */ | |
357 | if (!(rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV)) | |
358 | return TXRX_CONTINUE; | |
359 | ||
360 | hdrlen = ieee80211_get_hdrlen(rx->fc); | |
361 | ||
362 | if (rx->skb->len < 8 + hdrlen) | |
363 | return TXRX_DROP; /* TODO: count this? */ | |
364 | ||
365 | /* | |
366 | * no need to call ieee80211_wep_get_keyidx, | |
367 | * it verifies a bunch of things we've done already | |
368 | */ | |
369 | keyidx = rx->skb->data[hdrlen + 3] >> 6; | |
370 | ||
371 | rx->key = rx->sdata->keys[keyidx]; | |
372 | ||
373 | /* | |
374 | * RSNA-protected unicast frames should always be sent with | |
375 | * pairwise or station-to-station keys, but for WEP we allow | |
376 | * using a key index as well. | |
377 | */ | |
378 | if (rx->key && rx->key->alg != ALG_WEP && | |
379 | !is_multicast_ether_addr(hdr->addr1)) | |
380 | rx->key = NULL; | |
571ecf67 JB |
381 | } |
382 | ||
3017b80b | 383 | if (rx->key) { |
571ecf67 JB |
384 | rx->key->tx_rx_count++; |
385 | if (unlikely(rx->local->key_tx_rx_threshold && | |
386 | rx->key->tx_rx_count > | |
387 | rx->local->key_tx_rx_threshold)) { | |
388 | ieee80211_key_threshold_notify(rx->dev, rx->key, | |
389 | rx->sta); | |
390 | } | |
391 | } | |
392 | ||
393 | return TXRX_CONTINUE; | |
394 | } | |
395 | ||
396 | static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta) | |
397 | { | |
398 | struct ieee80211_sub_if_data *sdata; | |
399 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); | |
400 | ||
401 | if (sdata->bss) | |
402 | atomic_inc(&sdata->bss->num_sta_ps); | |
403 | sta->flags |= WLAN_STA_PS; | |
404 | sta->pspoll = 0; | |
405 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
406 | printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d enters power " | |
407 | "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid); | |
408 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
409 | } | |
410 | ||
411 | static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta) | |
412 | { | |
413 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
414 | struct sk_buff *skb; | |
415 | int sent = 0; | |
416 | struct ieee80211_sub_if_data *sdata; | |
417 | struct ieee80211_tx_packet_data *pkt_data; | |
418 | ||
419 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); | |
420 | if (sdata->bss) | |
421 | atomic_dec(&sdata->bss->num_sta_ps); | |
422 | sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM); | |
423 | sta->pspoll = 0; | |
424 | if (!skb_queue_empty(&sta->ps_tx_buf)) { | |
425 | if (local->ops->set_tim) | |
426 | local->ops->set_tim(local_to_hw(local), sta->aid, 0); | |
427 | if (sdata->bss) | |
428 | bss_tim_clear(local, sdata->bss, sta->aid); | |
429 | } | |
430 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
431 | printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d exits power " | |
432 | "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid); | |
433 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
434 | /* Send all buffered frames to the station */ | |
435 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { | |
436 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; | |
437 | sent++; | |
438 | pkt_data->requeue = 1; | |
439 | dev_queue_xmit(skb); | |
440 | } | |
441 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { | |
442 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; | |
443 | local->total_ps_buffered--; | |
444 | sent++; | |
445 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
446 | printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d send PS frame " | |
447 | "since STA not sleeping anymore\n", dev->name, | |
448 | MAC_ARG(sta->addr), sta->aid); | |
449 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
450 | pkt_data->requeue = 1; | |
451 | dev_queue_xmit(skb); | |
452 | } | |
453 | ||
454 | return sent; | |
455 | } | |
456 | ||
457 | static ieee80211_txrx_result | |
458 | ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx) | |
459 | { | |
460 | struct sta_info *sta = rx->sta; | |
461 | struct net_device *dev = rx->dev; | |
462 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; | |
463 | ||
464 | if (!sta) | |
465 | return TXRX_CONTINUE; | |
466 | ||
467 | /* Update last_rx only for IBSS packets which are for the current | |
468 | * BSSID to avoid keeping the current IBSS network alive in cases where | |
469 | * other STAs are using different BSSID. */ | |
470 | if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) { | |
471 | u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len); | |
472 | if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0) | |
473 | sta->last_rx = jiffies; | |
474 | } else | |
475 | if (!is_multicast_ether_addr(hdr->addr1) || | |
476 | rx->sdata->type == IEEE80211_IF_TYPE_STA) { | |
477 | /* Update last_rx only for unicast frames in order to prevent | |
478 | * the Probe Request frames (the only broadcast frames from a | |
479 | * STA in infrastructure mode) from keeping a connection alive. | |
480 | */ | |
481 | sta->last_rx = jiffies; | |
482 | } | |
483 | ||
484 | if (!rx->u.rx.ra_match) | |
485 | return TXRX_CONTINUE; | |
486 | ||
487 | sta->rx_fragments++; | |
488 | sta->rx_bytes += rx->skb->len; | |
489 | sta->last_rssi = (sta->last_rssi * 15 + | |
490 | rx->u.rx.status->ssi) / 16; | |
491 | sta->last_signal = (sta->last_signal * 15 + | |
492 | rx->u.rx.status->signal) / 16; | |
493 | sta->last_noise = (sta->last_noise * 15 + | |
494 | rx->u.rx.status->noise) / 16; | |
495 | ||
496 | if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) { | |
497 | /* Change STA power saving mode only in the end of a frame | |
498 | * exchange sequence */ | |
499 | if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM)) | |
500 | rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta); | |
501 | else if (!(sta->flags & WLAN_STA_PS) && | |
502 | (rx->fc & IEEE80211_FCTL_PM)) | |
503 | ap_sta_ps_start(dev, sta); | |
504 | } | |
505 | ||
506 | /* Drop data::nullfunc frames silently, since they are used only to | |
507 | * control station power saving mode. */ | |
508 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && | |
509 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) { | |
510 | I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); | |
511 | /* Update counter and free packet here to avoid counting this | |
512 | * as a dropped packed. */ | |
513 | sta->rx_packets++; | |
514 | dev_kfree_skb(rx->skb); | |
515 | return TXRX_QUEUED; | |
516 | } | |
517 | ||
518 | return TXRX_CONTINUE; | |
519 | } /* ieee80211_rx_h_sta_process */ | |
520 | ||
521 | static ieee80211_txrx_result | |
522 | ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx) | |
523 | { | |
524 | if (!rx->sta || !(rx->fc & IEEE80211_FCTL_PROTECTED) || | |
525 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || | |
526 | !rx->key || rx->key->alg != ALG_WEP || !rx->u.rx.ra_match) | |
527 | return TXRX_CONTINUE; | |
528 | ||
529 | /* Check for weak IVs, if hwaccel did not remove IV from the frame */ | |
530 | if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) || | |
531 | rx->key->force_sw_encrypt) { | |
532 | u8 *iv = ieee80211_wep_is_weak_iv(rx->skb, rx->key); | |
533 | if (iv) { | |
534 | rx->sta->wep_weak_iv_count++; | |
535 | } | |
536 | } | |
537 | ||
538 | return TXRX_CONTINUE; | |
539 | } | |
540 | ||
541 | static ieee80211_txrx_result | |
542 | ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx) | |
543 | { | |
571ecf67 JB |
544 | if ((rx->key && rx->key->alg != ALG_WEP) || |
545 | !(rx->fc & IEEE80211_FCTL_PROTECTED) || | |
546 | ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA && | |
547 | ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || | |
548 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH))) | |
549 | return TXRX_CONTINUE; | |
550 | ||
551 | if (!rx->key) { | |
1a84f3fd JB |
552 | if (net_ratelimit()) |
553 | printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n", | |
554 | rx->dev->name); | |
571ecf67 JB |
555 | return TXRX_DROP; |
556 | } | |
557 | ||
558 | if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED) || | |
559 | rx->key->force_sw_encrypt) { | |
560 | if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) { | |
1a84f3fd JB |
561 | if (net_ratelimit()) |
562 | printk(KERN_DEBUG "%s: RX WEP frame, decrypt " | |
563 | "failed\n", rx->dev->name); | |
571ecf67 JB |
564 | return TXRX_DROP; |
565 | } | |
566 | } else if (rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) { | |
567 | ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key); | |
568 | /* remove ICV */ | |
569 | skb_trim(rx->skb, rx->skb->len - 4); | |
570 | } | |
571 | ||
572 | return TXRX_CONTINUE; | |
573 | } | |
574 | ||
575 | static inline struct ieee80211_fragment_entry * | |
576 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, | |
577 | unsigned int frag, unsigned int seq, int rx_queue, | |
578 | struct sk_buff **skb) | |
579 | { | |
580 | struct ieee80211_fragment_entry *entry; | |
581 | int idx; | |
582 | ||
583 | idx = sdata->fragment_next; | |
584 | entry = &sdata->fragments[sdata->fragment_next++]; | |
585 | if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) | |
586 | sdata->fragment_next = 0; | |
587 | ||
588 | if (!skb_queue_empty(&entry->skb_list)) { | |
589 | #ifdef CONFIG_MAC80211_DEBUG | |
590 | struct ieee80211_hdr *hdr = | |
591 | (struct ieee80211_hdr *) entry->skb_list.next->data; | |
592 | printk(KERN_DEBUG "%s: RX reassembly removed oldest " | |
593 | "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " | |
594 | "addr1=" MAC_FMT " addr2=" MAC_FMT "\n", | |
595 | sdata->dev->name, idx, | |
596 | jiffies - entry->first_frag_time, entry->seq, | |
597 | entry->last_frag, MAC_ARG(hdr->addr1), | |
598 | MAC_ARG(hdr->addr2)); | |
599 | #endif /* CONFIG_MAC80211_DEBUG */ | |
600 | __skb_queue_purge(&entry->skb_list); | |
601 | } | |
602 | ||
603 | __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ | |
604 | *skb = NULL; | |
605 | entry->first_frag_time = jiffies; | |
606 | entry->seq = seq; | |
607 | entry->rx_queue = rx_queue; | |
608 | entry->last_frag = frag; | |
609 | entry->ccmp = 0; | |
610 | entry->extra_len = 0; | |
611 | ||
612 | return entry; | |
613 | } | |
614 | ||
615 | static inline struct ieee80211_fragment_entry * | |
616 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, | |
617 | u16 fc, unsigned int frag, unsigned int seq, | |
618 | int rx_queue, struct ieee80211_hdr *hdr) | |
619 | { | |
620 | struct ieee80211_fragment_entry *entry; | |
621 | int i, idx; | |
622 | ||
623 | idx = sdata->fragment_next; | |
624 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { | |
625 | struct ieee80211_hdr *f_hdr; | |
626 | u16 f_fc; | |
627 | ||
628 | idx--; | |
629 | if (idx < 0) | |
630 | idx = IEEE80211_FRAGMENT_MAX - 1; | |
631 | ||
632 | entry = &sdata->fragments[idx]; | |
633 | if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || | |
634 | entry->rx_queue != rx_queue || | |
635 | entry->last_frag + 1 != frag) | |
636 | continue; | |
637 | ||
638 | f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data; | |
639 | f_fc = le16_to_cpu(f_hdr->frame_control); | |
640 | ||
641 | if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) || | |
642 | compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 || | |
643 | compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0) | |
644 | continue; | |
645 | ||
646 | if (entry->first_frag_time + 2 * HZ < jiffies) { | |
647 | __skb_queue_purge(&entry->skb_list); | |
648 | continue; | |
649 | } | |
650 | return entry; | |
651 | } | |
652 | ||
653 | return NULL; | |
654 | } | |
655 | ||
656 | static ieee80211_txrx_result | |
657 | ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx) | |
658 | { | |
659 | struct ieee80211_hdr *hdr; | |
660 | u16 sc; | |
661 | unsigned int frag, seq; | |
662 | struct ieee80211_fragment_entry *entry; | |
663 | struct sk_buff *skb; | |
664 | ||
665 | hdr = (struct ieee80211_hdr *) rx->skb->data; | |
666 | sc = le16_to_cpu(hdr->seq_ctrl); | |
667 | frag = sc & IEEE80211_SCTL_FRAG; | |
668 | ||
669 | if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) || | |
670 | (rx->skb)->len < 24 || | |
671 | is_multicast_ether_addr(hdr->addr1))) { | |
672 | /* not fragmented */ | |
673 | goto out; | |
674 | } | |
675 | I802_DEBUG_INC(rx->local->rx_handlers_fragments); | |
676 | ||
677 | seq = (sc & IEEE80211_SCTL_SEQ) >> 4; | |
678 | ||
679 | if (frag == 0) { | |
680 | /* This is the first fragment of a new frame. */ | |
681 | entry = ieee80211_reassemble_add(rx->sdata, frag, seq, | |
682 | rx->u.rx.queue, &(rx->skb)); | |
683 | if (rx->key && rx->key->alg == ALG_CCMP && | |
684 | (rx->fc & IEEE80211_FCTL_PROTECTED)) { | |
685 | /* Store CCMP PN so that we can verify that the next | |
686 | * fragment has a sequential PN value. */ | |
687 | entry->ccmp = 1; | |
688 | memcpy(entry->last_pn, | |
689 | rx->key->u.ccmp.rx_pn[rx->u.rx.queue], | |
690 | CCMP_PN_LEN); | |
691 | } | |
692 | return TXRX_QUEUED; | |
693 | } | |
694 | ||
695 | /* This is a fragment for a frame that should already be pending in | |
696 | * fragment cache. Add this fragment to the end of the pending entry. | |
697 | */ | |
698 | entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq, | |
699 | rx->u.rx.queue, hdr); | |
700 | if (!entry) { | |
701 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | |
702 | return TXRX_DROP; | |
703 | } | |
704 | ||
705 | /* Verify that MPDUs within one MSDU have sequential PN values. | |
706 | * (IEEE 802.11i, 8.3.3.4.5) */ | |
707 | if (entry->ccmp) { | |
708 | int i; | |
709 | u8 pn[CCMP_PN_LEN], *rpn; | |
710 | if (!rx->key || rx->key->alg != ALG_CCMP) | |
711 | return TXRX_DROP; | |
712 | memcpy(pn, entry->last_pn, CCMP_PN_LEN); | |
713 | for (i = CCMP_PN_LEN - 1; i >= 0; i--) { | |
714 | pn[i]++; | |
715 | if (pn[i]) | |
716 | break; | |
717 | } | |
718 | rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue]; | |
719 | if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) { | |
1a84f3fd JB |
720 | if (net_ratelimit()) |
721 | printk(KERN_DEBUG "%s: defrag: CCMP PN not " | |
722 | "sequential A2=" MAC_FMT | |
723 | " PN=%02x%02x%02x%02x%02x%02x " | |
724 | "(expected %02x%02x%02x%02x%02x%02x)\n", | |
725 | rx->dev->name, MAC_ARG(hdr->addr2), | |
726 | rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], | |
727 | rpn[5], pn[0], pn[1], pn[2], pn[3], | |
728 | pn[4], pn[5]); | |
571ecf67 JB |
729 | return TXRX_DROP; |
730 | } | |
731 | memcpy(entry->last_pn, pn, CCMP_PN_LEN); | |
732 | } | |
733 | ||
734 | skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc)); | |
735 | __skb_queue_tail(&entry->skb_list, rx->skb); | |
736 | entry->last_frag = frag; | |
737 | entry->extra_len += rx->skb->len; | |
738 | if (rx->fc & IEEE80211_FCTL_MOREFRAGS) { | |
739 | rx->skb = NULL; | |
740 | return TXRX_QUEUED; | |
741 | } | |
742 | ||
743 | rx->skb = __skb_dequeue(&entry->skb_list); | |
744 | if (skb_tailroom(rx->skb) < entry->extra_len) { | |
745 | I802_DEBUG_INC(rx->local->rx_expand_skb_head2); | |
746 | if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, | |
747 | GFP_ATOMIC))) { | |
748 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | |
749 | __skb_queue_purge(&entry->skb_list); | |
750 | return TXRX_DROP; | |
751 | } | |
752 | } | |
753 | while ((skb = __skb_dequeue(&entry->skb_list))) { | |
754 | memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len); | |
755 | dev_kfree_skb(skb); | |
756 | } | |
757 | ||
758 | /* Complete frame has been reassembled - process it now */ | |
759 | rx->fragmented = 1; | |
760 | ||
761 | out: | |
762 | if (rx->sta) | |
763 | rx->sta->rx_packets++; | |
764 | if (is_multicast_ether_addr(hdr->addr1)) | |
765 | rx->local->dot11MulticastReceivedFrameCount++; | |
766 | else | |
767 | ieee80211_led_rx(rx->local); | |
768 | return TXRX_CONTINUE; | |
769 | } | |
770 | ||
771 | static ieee80211_txrx_result | |
772 | ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx) | |
773 | { | |
774 | struct sk_buff *skb; | |
775 | int no_pending_pkts; | |
776 | ||
777 | if (likely(!rx->sta || | |
778 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL || | |
779 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL || | |
780 | !rx->u.rx.ra_match)) | |
781 | return TXRX_CONTINUE; | |
782 | ||
783 | skb = skb_dequeue(&rx->sta->tx_filtered); | |
784 | if (!skb) { | |
785 | skb = skb_dequeue(&rx->sta->ps_tx_buf); | |
786 | if (skb) | |
787 | rx->local->total_ps_buffered--; | |
788 | } | |
789 | no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) && | |
790 | skb_queue_empty(&rx->sta->ps_tx_buf); | |
791 | ||
792 | if (skb) { | |
793 | struct ieee80211_hdr *hdr = | |
794 | (struct ieee80211_hdr *) skb->data; | |
795 | ||
796 | /* tell TX path to send one frame even though the STA may | |
797 | * still remain is PS mode after this frame exchange */ | |
798 | rx->sta->pspoll = 1; | |
799 | ||
800 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
801 | printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS Poll (entries " | |
802 | "after %d)\n", | |
803 | MAC_ARG(rx->sta->addr), rx->sta->aid, | |
804 | skb_queue_len(&rx->sta->ps_tx_buf)); | |
805 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
806 | ||
807 | /* Use MoreData flag to indicate whether there are more | |
808 | * buffered frames for this STA */ | |
809 | if (no_pending_pkts) { | |
810 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); | |
811 | rx->sta->flags &= ~WLAN_STA_TIM; | |
812 | } else | |
813 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); | |
814 | ||
815 | dev_queue_xmit(skb); | |
816 | ||
817 | if (no_pending_pkts) { | |
818 | if (rx->local->ops->set_tim) | |
819 | rx->local->ops->set_tim(local_to_hw(rx->local), | |
820 | rx->sta->aid, 0); | |
821 | if (rx->sdata->bss) | |
822 | bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid); | |
823 | } | |
824 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
825 | } else if (!rx->u.rx.sent_ps_buffered) { | |
826 | printk(KERN_DEBUG "%s: STA " MAC_FMT " sent PS Poll even " | |
827 | "though there is no buffered frames for it\n", | |
828 | rx->dev->name, MAC_ARG(rx->sta->addr)); | |
829 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
830 | ||
831 | } | |
832 | ||
833 | /* Free PS Poll skb here instead of returning TXRX_DROP that would | |
834 | * count as an dropped frame. */ | |
835 | dev_kfree_skb(rx->skb); | |
836 | ||
837 | return TXRX_QUEUED; | |
838 | } | |
839 | ||
6e0d114d JB |
840 | static ieee80211_txrx_result |
841 | ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx) | |
842 | { | |
843 | u16 fc = rx->fc; | |
844 | u8 *data = rx->skb->data; | |
845 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data; | |
846 | ||
847 | if (!WLAN_FC_IS_QOS_DATA(fc)) | |
848 | return TXRX_CONTINUE; | |
849 | ||
850 | /* remove the qos control field, update frame type and meta-data */ | |
851 | memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2); | |
852 | hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2); | |
853 | /* change frame type to non QOS */ | |
854 | rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA; | |
855 | hdr->frame_control = cpu_to_le16(fc); | |
856 | ||
857 | return TXRX_CONTINUE; | |
858 | } | |
859 | ||
571ecf67 JB |
860 | static ieee80211_txrx_result |
861 | ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx) | |
862 | { | |
863 | if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) && | |
864 | rx->sdata->type != IEEE80211_IF_TYPE_STA && rx->u.rx.ra_match) { | |
865 | /* Pass both encrypted and unencrypted EAPOL frames to user | |
866 | * space for processing. */ | |
867 | if (!rx->local->apdev) | |
868 | return TXRX_DROP; | |
869 | ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status, | |
870 | ieee80211_msg_normal); | |
871 | return TXRX_QUEUED; | |
872 | } | |
873 | ||
874 | if (unlikely(rx->sdata->ieee802_1x && | |
875 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && | |
876 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC && | |
877 | (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) && | |
878 | !ieee80211_is_eapol(rx->skb))) { | |
879 | #ifdef CONFIG_MAC80211_DEBUG | |
880 | struct ieee80211_hdr *hdr = | |
881 | (struct ieee80211_hdr *) rx->skb->data; | |
882 | printk(KERN_DEBUG "%s: dropped frame from " MAC_FMT | |
883 | " (unauthorized port)\n", rx->dev->name, | |
884 | MAC_ARG(hdr->addr2)); | |
885 | #endif /* CONFIG_MAC80211_DEBUG */ | |
886 | return TXRX_DROP; | |
887 | } | |
888 | ||
889 | return TXRX_CONTINUE; | |
890 | } | |
891 | ||
892 | static ieee80211_txrx_result | |
893 | ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx) | |
894 | { | |
3017b80b JB |
895 | /* |
896 | * Pass through unencrypted frames if the hardware might have | |
897 | * decrypted them already without telling us, but that can only | |
898 | * be true if we either didn't find a key or the found key is | |
899 | * uploaded to the hardware. | |
900 | */ | |
901 | if ((rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) && | |
902 | (!rx->key || !rx->key->force_sw_encrypt)) | |
571ecf67 JB |
903 | return TXRX_CONTINUE; |
904 | ||
905 | /* Drop unencrypted frames if key is set. */ | |
906 | if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) && | |
907 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && | |
908 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC && | |
909 | (rx->key || rx->sdata->drop_unencrypted) && | |
910 | (rx->sdata->eapol == 0 || | |
911 | !ieee80211_is_eapol(rx->skb)))) { | |
1a84f3fd JB |
912 | if (net_ratelimit()) |
913 | printk(KERN_DEBUG "%s: RX non-WEP frame, but expected " | |
914 | "encryption\n", rx->dev->name); | |
571ecf67 JB |
915 | return TXRX_DROP; |
916 | } | |
917 | return TXRX_CONTINUE; | |
918 | } | |
919 | ||
920 | static ieee80211_txrx_result | |
921 | ieee80211_rx_h_data(struct ieee80211_txrx_data *rx) | |
922 | { | |
923 | struct net_device *dev = rx->dev; | |
924 | struct ieee80211_local *local = rx->local; | |
925 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; | |
926 | u16 fc, hdrlen, ethertype; | |
927 | u8 *payload; | |
928 | u8 dst[ETH_ALEN]; | |
929 | u8 src[ETH_ALEN]; | |
930 | struct sk_buff *skb = rx->skb, *skb2; | |
931 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
932 | ||
933 | fc = rx->fc; | |
934 | if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) | |
935 | return TXRX_CONTINUE; | |
936 | ||
937 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) | |
938 | return TXRX_DROP; | |
939 | ||
940 | hdrlen = ieee80211_get_hdrlen(fc); | |
941 | ||
942 | /* convert IEEE 802.11 header + possible LLC headers into Ethernet | |
943 | * header | |
944 | * IEEE 802.11 address fields: | |
945 | * ToDS FromDS Addr1 Addr2 Addr3 Addr4 | |
946 | * 0 0 DA SA BSSID n/a | |
947 | * 0 1 DA BSSID SA n/a | |
948 | * 1 0 BSSID SA DA n/a | |
949 | * 1 1 RA TA DA SA | |
950 | */ | |
951 | ||
952 | switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { | |
953 | case IEEE80211_FCTL_TODS: | |
954 | /* BSSID SA DA */ | |
955 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
956 | memcpy(src, hdr->addr2, ETH_ALEN); | |
957 | ||
958 | if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP && | |
959 | sdata->type != IEEE80211_IF_TYPE_VLAN)) { | |
1a84f3fd JB |
960 | if (net_ratelimit()) |
961 | printk(KERN_DEBUG "%s: dropped ToDS frame " | |
962 | "(BSSID=" MAC_FMT | |
963 | " SA=" MAC_FMT | |
964 | " DA=" MAC_FMT ")\n", | |
965 | dev->name, | |
966 | MAC_ARG(hdr->addr1), | |
967 | MAC_ARG(hdr->addr2), | |
968 | MAC_ARG(hdr->addr3)); | |
571ecf67 JB |
969 | return TXRX_DROP; |
970 | } | |
971 | break; | |
972 | case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): | |
973 | /* RA TA DA SA */ | |
974 | memcpy(dst, hdr->addr3, ETH_ALEN); | |
975 | memcpy(src, hdr->addr4, ETH_ALEN); | |
976 | ||
977 | if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) { | |
1a84f3fd JB |
978 | if (net_ratelimit()) |
979 | printk(KERN_DEBUG "%s: dropped FromDS&ToDS " | |
980 | "frame (RA=" MAC_FMT | |
981 | " TA=" MAC_FMT " DA=" MAC_FMT | |
982 | " SA=" MAC_FMT ")\n", | |
983 | rx->dev->name, | |
984 | MAC_ARG(hdr->addr1), | |
985 | MAC_ARG(hdr->addr2), | |
986 | MAC_ARG(hdr->addr3), | |
987 | MAC_ARG(hdr->addr4)); | |
571ecf67 JB |
988 | return TXRX_DROP; |
989 | } | |
990 | break; | |
991 | case IEEE80211_FCTL_FROMDS: | |
992 | /* DA BSSID SA */ | |
993 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
994 | memcpy(src, hdr->addr3, ETH_ALEN); | |
995 | ||
996 | if (sdata->type != IEEE80211_IF_TYPE_STA) { | |
997 | return TXRX_DROP; | |
998 | } | |
999 | break; | |
1000 | case 0: | |
1001 | /* DA SA BSSID */ | |
1002 | memcpy(dst, hdr->addr1, ETH_ALEN); | |
1003 | memcpy(src, hdr->addr2, ETH_ALEN); | |
1004 | ||
1005 | if (sdata->type != IEEE80211_IF_TYPE_IBSS) { | |
1006 | if (net_ratelimit()) { | |
1007 | printk(KERN_DEBUG "%s: dropped IBSS frame (DA=" | |
1008 | MAC_FMT " SA=" MAC_FMT " BSSID=" MAC_FMT | |
1009 | ")\n", | |
1010 | dev->name, MAC_ARG(hdr->addr1), | |
1011 | MAC_ARG(hdr->addr2), | |
1012 | MAC_ARG(hdr->addr3)); | |
1013 | } | |
1014 | return TXRX_DROP; | |
1015 | } | |
1016 | break; | |
1017 | } | |
1018 | ||
1019 | payload = skb->data + hdrlen; | |
1020 | ||
1021 | if (unlikely(skb->len - hdrlen < 8)) { | |
1022 | if (net_ratelimit()) { | |
1023 | printk(KERN_DEBUG "%s: RX too short data frame " | |
1024 | "payload\n", dev->name); | |
1025 | } | |
1026 | return TXRX_DROP; | |
1027 | } | |
1028 | ||
1029 | ethertype = (payload[6] << 8) | payload[7]; | |
1030 | ||
1031 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && | |
1032 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | |
1033 | compare_ether_addr(payload, bridge_tunnel_header) == 0)) { | |
1034 | /* remove RFC1042 or Bridge-Tunnel encapsulation and | |
1035 | * replace EtherType */ | |
1036 | skb_pull(skb, hdrlen + 6); | |
1037 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); | |
1038 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); | |
1039 | } else { | |
1040 | struct ethhdr *ehdr; | |
1041 | __be16 len; | |
1042 | skb_pull(skb, hdrlen); | |
1043 | len = htons(skb->len); | |
1044 | ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr)); | |
1045 | memcpy(ehdr->h_dest, dst, ETH_ALEN); | |
1046 | memcpy(ehdr->h_source, src, ETH_ALEN); | |
1047 | ehdr->h_proto = len; | |
1048 | } | |
1049 | skb->dev = dev; | |
1050 | ||
1051 | skb2 = NULL; | |
1052 | ||
1053 | sdata->stats.rx_packets++; | |
1054 | sdata->stats.rx_bytes += skb->len; | |
1055 | ||
1056 | if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP | |
1057 | || sdata->type == IEEE80211_IF_TYPE_VLAN) && rx->u.rx.ra_match) { | |
1058 | if (is_multicast_ether_addr(skb->data)) { | |
1059 | /* send multicast frames both to higher layers in | |
1060 | * local net stack and back to the wireless media */ | |
1061 | skb2 = skb_copy(skb, GFP_ATOMIC); | |
1a84f3fd | 1062 | if (!skb2 && net_ratelimit()) |
571ecf67 JB |
1063 | printk(KERN_DEBUG "%s: failed to clone " |
1064 | "multicast frame\n", dev->name); | |
1065 | } else { | |
1066 | struct sta_info *dsta; | |
1067 | dsta = sta_info_get(local, skb->data); | |
1068 | if (dsta && !dsta->dev) { | |
1a84f3fd JB |
1069 | if (net_ratelimit()) |
1070 | printk(KERN_DEBUG "Station with null " | |
1071 | "dev structure!\n"); | |
571ecf67 JB |
1072 | } else if (dsta && dsta->dev == dev) { |
1073 | /* Destination station is associated to this | |
1074 | * AP, so send the frame directly to it and | |
1075 | * do not pass the frame to local net stack. | |
1076 | */ | |
1077 | skb2 = skb; | |
1078 | skb = NULL; | |
1079 | } | |
1080 | if (dsta) | |
1081 | sta_info_put(dsta); | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | if (skb) { | |
1086 | /* deliver to local stack */ | |
1087 | skb->protocol = eth_type_trans(skb, dev); | |
1088 | memset(skb->cb, 0, sizeof(skb->cb)); | |
1089 | netif_rx(skb); | |
1090 | } | |
1091 | ||
1092 | if (skb2) { | |
1093 | /* send to wireless media */ | |
1094 | skb2->protocol = __constant_htons(ETH_P_802_3); | |
1095 | skb_set_network_header(skb2, 0); | |
1096 | skb_set_mac_header(skb2, 0); | |
1097 | dev_queue_xmit(skb2); | |
1098 | } | |
1099 | ||
1100 | return TXRX_QUEUED; | |
1101 | } | |
1102 | ||
1103 | static ieee80211_txrx_result | |
1104 | ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx) | |
1105 | { | |
1106 | struct ieee80211_sub_if_data *sdata; | |
1107 | ||
1108 | if (!rx->u.rx.ra_match) | |
1109 | return TXRX_DROP; | |
1110 | ||
1111 | sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); | |
1112 | if ((sdata->type == IEEE80211_IF_TYPE_STA || | |
1113 | sdata->type == IEEE80211_IF_TYPE_IBSS) && | |
1114 | !rx->local->user_space_mlme) { | |
1115 | ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status); | |
1116 | } else { | |
1117 | /* Management frames are sent to hostapd for processing */ | |
1118 | if (!rx->local->apdev) | |
1119 | return TXRX_DROP; | |
1120 | ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status, | |
1121 | ieee80211_msg_normal); | |
1122 | } | |
1123 | return TXRX_QUEUED; | |
1124 | } | |
1125 | ||
1126 | static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers( | |
1127 | struct ieee80211_local *local, | |
1128 | ieee80211_rx_handler *handlers, | |
1129 | struct ieee80211_txrx_data *rx, | |
1130 | struct sta_info *sta) | |
1131 | { | |
1132 | ieee80211_rx_handler *handler; | |
1133 | ieee80211_txrx_result res = TXRX_DROP; | |
1134 | ||
1135 | for (handler = handlers; *handler != NULL; handler++) { | |
1136 | res = (*handler)(rx); | |
8e6f0032 JB |
1137 | |
1138 | switch (res) { | |
1139 | case TXRX_CONTINUE: | |
1140 | continue; | |
1141 | case TXRX_DROP: | |
1142 | I802_DEBUG_INC(local->rx_handlers_drop); | |
1143 | if (sta) | |
1144 | sta->rx_dropped++; | |
1145 | break; | |
1146 | case TXRX_QUEUED: | |
1147 | I802_DEBUG_INC(local->rx_handlers_queued); | |
571ecf67 JB |
1148 | break; |
1149 | } | |
8e6f0032 | 1150 | break; |
571ecf67 JB |
1151 | } |
1152 | ||
8e6f0032 | 1153 | if (res == TXRX_DROP) |
571ecf67 | 1154 | dev_kfree_skb(rx->skb); |
571ecf67 JB |
1155 | return res; |
1156 | } | |
1157 | ||
1158 | static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local, | |
1159 | ieee80211_rx_handler *handlers, | |
1160 | struct ieee80211_txrx_data *rx, | |
1161 | struct sta_info *sta) | |
1162 | { | |
1163 | if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) == | |
1164 | TXRX_CONTINUE) | |
1165 | dev_kfree_skb(rx->skb); | |
1166 | } | |
1167 | ||
1168 | static void ieee80211_rx_michael_mic_report(struct net_device *dev, | |
1169 | struct ieee80211_hdr *hdr, | |
1170 | struct sta_info *sta, | |
1171 | struct ieee80211_txrx_data *rx) | |
1172 | { | |
1173 | int keyidx, hdrlen; | |
1174 | ||
1175 | hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb); | |
1176 | if (rx->skb->len >= hdrlen + 4) | |
1177 | keyidx = rx->skb->data[hdrlen + 3] >> 6; | |
1178 | else | |
1179 | keyidx = -1; | |
1180 | ||
1181 | /* TODO: verify that this is not triggered by fragmented | |
1182 | * frames (hw does not verify MIC for them). */ | |
1a84f3fd JB |
1183 | if (net_ratelimit()) |
1184 | printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC " | |
1185 | "failure from " MAC_FMT " to " MAC_FMT " keyidx=%d\n", | |
1186 | dev->name, MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr1), | |
1187 | keyidx); | |
571ecf67 JB |
1188 | |
1189 | if (!sta) { | |
1190 | /* Some hardware versions seem to generate incorrect | |
1191 | * Michael MIC reports; ignore them to avoid triggering | |
1192 | * countermeasures. */ | |
1a84f3fd JB |
1193 | if (net_ratelimit()) |
1194 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " | |
1195 | "error for unknown address " MAC_FMT "\n", | |
1196 | dev->name, MAC_ARG(hdr->addr2)); | |
571ecf67 JB |
1197 | goto ignore; |
1198 | } | |
1199 | ||
1200 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) { | |
1a84f3fd JB |
1201 | if (net_ratelimit()) |
1202 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " | |
1203 | "error for a frame with no ISWEP flag (src " | |
1204 | MAC_FMT ")\n", dev->name, MAC_ARG(hdr->addr2)); | |
571ecf67 JB |
1205 | goto ignore; |
1206 | } | |
1207 | ||
1208 | if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) && | |
1209 | rx->sdata->type == IEEE80211_IF_TYPE_AP) { | |
1210 | keyidx = ieee80211_wep_get_keyidx(rx->skb); | |
1211 | /* AP with Pairwise keys support should never receive Michael | |
1212 | * MIC errors for non-zero keyidx because these are reserved | |
1213 | * for group keys and only the AP is sending real multicast | |
1214 | * frames in BSS. */ | |
1215 | if (keyidx) { | |
1a84f3fd JB |
1216 | if (net_ratelimit()) |
1217 | printk(KERN_DEBUG "%s: ignored Michael MIC " | |
1218 | "error for a frame with non-zero keyidx" | |
1219 | " (%d) (src " MAC_FMT ")\n", dev->name, | |
1220 | keyidx, MAC_ARG(hdr->addr2)); | |
571ecf67 JB |
1221 | goto ignore; |
1222 | } | |
1223 | } | |
1224 | ||
1225 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA && | |
1226 | ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || | |
1227 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) { | |
1a84f3fd JB |
1228 | if (net_ratelimit()) |
1229 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " | |
1230 | "error for a frame that cannot be encrypted " | |
1231 | "(fc=0x%04x) (src " MAC_FMT ")\n", | |
1232 | dev->name, rx->fc, MAC_ARG(hdr->addr2)); | |
571ecf67 JB |
1233 | goto ignore; |
1234 | } | |
1235 | ||
1236 | do { | |
1237 | union iwreq_data wrqu; | |
1238 | char *buf = kmalloc(128, GFP_ATOMIC); | |
1239 | if (!buf) | |
1240 | break; | |
1241 | ||
1242 | /* TODO: needed parameters: count, key type, TSC */ | |
1243 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" | |
1244 | "keyid=%d %scast addr=" MAC_FMT ")", | |
1245 | keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni", | |
1246 | MAC_ARG(hdr->addr2)); | |
1247 | memset(&wrqu, 0, sizeof(wrqu)); | |
1248 | wrqu.data.length = strlen(buf); | |
1249 | wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf); | |
1250 | kfree(buf); | |
1251 | } while (0); | |
1252 | ||
1253 | /* TODO: consider verifying the MIC error report with software | |
1254 | * implementation if we get too many spurious reports from the | |
1255 | * hardware. */ | |
1256 | if (!rx->local->apdev) | |
1257 | goto ignore; | |
1258 | ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status, | |
1259 | ieee80211_msg_michael_mic_failure); | |
1260 | return; | |
1261 | ||
1262 | ignore: | |
1263 | dev_kfree_skb(rx->skb); | |
1264 | rx->skb = NULL; | |
1265 | } | |
1266 | ||
1267 | ieee80211_rx_handler ieee80211_rx_handlers[] = | |
1268 | { | |
1269 | ieee80211_rx_h_if_stats, | |
1270 | ieee80211_rx_h_monitor, | |
1271 | ieee80211_rx_h_passive_scan, | |
1272 | ieee80211_rx_h_check, | |
570bd537 | 1273 | ieee80211_rx_h_load_key, |
571ecf67 JB |
1274 | ieee80211_rx_h_sta_process, |
1275 | ieee80211_rx_h_ccmp_decrypt, | |
1276 | ieee80211_rx_h_tkip_decrypt, | |
1277 | ieee80211_rx_h_wep_weak_iv_detection, | |
1278 | ieee80211_rx_h_wep_decrypt, | |
1279 | ieee80211_rx_h_defragment, | |
1280 | ieee80211_rx_h_ps_poll, | |
1281 | ieee80211_rx_h_michael_mic_verify, | |
1282 | /* this must be after decryption - so header is counted in MPDU mic | |
1283 | * must be before pae and data, so QOS_DATA format frames | |
1284 | * are not passed to user space by these functions | |
1285 | */ | |
1286 | ieee80211_rx_h_remove_qos_control, | |
1287 | ieee80211_rx_h_802_1x_pae, | |
1288 | ieee80211_rx_h_drop_unencrypted, | |
1289 | ieee80211_rx_h_data, | |
1290 | ieee80211_rx_h_mgmt, | |
1291 | NULL | |
1292 | }; | |
1293 | ||
1294 | /* main receive path */ | |
1295 | ||
23a24def JB |
1296 | static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata, |
1297 | u8 *bssid, struct ieee80211_txrx_data *rx, | |
1298 | struct ieee80211_hdr *hdr) | |
1299 | { | |
1300 | int multicast = is_multicast_ether_addr(hdr->addr1); | |
1301 | ||
1302 | switch (sdata->type) { | |
1303 | case IEEE80211_IF_TYPE_STA: | |
1304 | if (!bssid) | |
1305 | return 0; | |
1306 | if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { | |
1307 | if (!rx->u.rx.in_scan) | |
1308 | return 0; | |
1309 | rx->u.rx.ra_match = 0; | |
1310 | } else if (!multicast && | |
1311 | compare_ether_addr(sdata->dev->dev_addr, | |
1312 | hdr->addr1) != 0) { | |
1313 | if (!sdata->promisc) | |
1314 | return 0; | |
1315 | rx->u.rx.ra_match = 0; | |
1316 | } | |
1317 | break; | |
1318 | case IEEE80211_IF_TYPE_IBSS: | |
1319 | if (!bssid) | |
1320 | return 0; | |
1321 | if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { | |
1322 | if (!rx->u.rx.in_scan) | |
1323 | return 0; | |
1324 | rx->u.rx.ra_match = 0; | |
1325 | } else if (!multicast && | |
1326 | compare_ether_addr(sdata->dev->dev_addr, | |
1327 | hdr->addr1) != 0) { | |
1328 | if (!sdata->promisc) | |
1329 | return 0; | |
1330 | rx->u.rx.ra_match = 0; | |
1331 | } else if (!rx->sta) | |
1332 | rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb, | |
1333 | bssid, hdr->addr2); | |
1334 | break; | |
1335 | case IEEE80211_IF_TYPE_AP: | |
1336 | if (!bssid) { | |
1337 | if (compare_ether_addr(sdata->dev->dev_addr, | |
1338 | hdr->addr1)) | |
1339 | return 0; | |
1340 | } else if (!ieee80211_bssid_match(bssid, | |
1341 | sdata->dev->dev_addr)) { | |
1342 | if (!rx->u.rx.in_scan) | |
1343 | return 0; | |
1344 | rx->u.rx.ra_match = 0; | |
1345 | } | |
1346 | if (sdata->dev == sdata->local->mdev && !rx->u.rx.in_scan) | |
1347 | /* do not receive anything via | |
1348 | * master device when not scanning */ | |
1349 | return 0; | |
1350 | break; | |
1351 | case IEEE80211_IF_TYPE_WDS: | |
1352 | if (bssid || | |
1353 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) | |
1354 | return 0; | |
1355 | if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2)) | |
1356 | return 0; | |
1357 | break; | |
1358 | } | |
1359 | ||
1360 | return 1; | |
1361 | } | |
1362 | ||
571ecf67 JB |
1363 | /* |
1364 | * This is the receive path handler. It is called by a low level driver when an | |
1365 | * 802.11 MPDU is received from the hardware. | |
1366 | */ | |
1367 | void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, | |
1368 | struct ieee80211_rx_status *status) | |
1369 | { | |
1370 | struct ieee80211_local *local = hw_to_local(hw); | |
1371 | struct ieee80211_sub_if_data *sdata; | |
1372 | struct sta_info *sta; | |
1373 | struct ieee80211_hdr *hdr; | |
1374 | struct ieee80211_txrx_data rx; | |
1375 | u16 type; | |
23a24def | 1376 | int radiotap_len = 0, prepres; |
8e6f0032 JB |
1377 | struct ieee80211_sub_if_data *prev = NULL; |
1378 | struct sk_buff *skb_new; | |
1379 | u8 *bssid; | |
571ecf67 JB |
1380 | |
1381 | if (status->flag & RX_FLAG_RADIOTAP) { | |
1382 | radiotap_len = ieee80211_get_radiotap_len(skb->data); | |
1383 | skb_pull(skb, radiotap_len); | |
1384 | } | |
1385 | ||
1386 | hdr = (struct ieee80211_hdr *) skb->data; | |
1387 | memset(&rx, 0, sizeof(rx)); | |
1388 | rx.skb = skb; | |
1389 | rx.local = local; | |
1390 | ||
1391 | rx.u.rx.status = status; | |
1392 | rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0; | |
1393 | type = rx.fc & IEEE80211_FCTL_FTYPE; | |
1394 | if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT) | |
1395 | local->dot11ReceivedFragmentCount++; | |
571ecf67 | 1396 | |
23a24def | 1397 | if (skb->len >= 16) { |
571ecf67 | 1398 | sta = rx.sta = sta_info_get(local, hdr->addr2); |
23a24def JB |
1399 | if (sta) { |
1400 | rx.dev = rx.sta->dev; | |
1401 | rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev); | |
1402 | } | |
1403 | } else | |
571ecf67 JB |
1404 | sta = rx.sta = NULL; |
1405 | ||
571ecf67 JB |
1406 | if ((status->flag & RX_FLAG_MMIC_ERROR)) { |
1407 | ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx); | |
1408 | goto end; | |
1409 | } | |
1410 | ||
1411 | if (unlikely(local->sta_scanning)) | |
1412 | rx.u.rx.in_scan = 1; | |
1413 | ||
1414 | if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx, | |
1415 | sta) != TXRX_CONTINUE) | |
1416 | goto end; | |
1417 | skb = rx.skb; | |
1418 | ||
1419 | skb_push(skb, radiotap_len); | |
1420 | if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS) && | |
23a24def | 1421 | !local->iff_promiscs && !is_multicast_ether_addr(hdr->addr1)) { |
571ecf67 JB |
1422 | rx.u.rx.ra_match = 1; |
1423 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx, | |
23a24def | 1424 | rx.sta); |
8e6f0032 JB |
1425 | sta_info_put(sta); |
1426 | return; | |
1427 | } | |
1428 | ||
1429 | bssid = ieee80211_get_bssid(hdr, skb->len - radiotap_len); | |
1430 | ||
1431 | read_lock(&local->sub_if_lock); | |
1432 | list_for_each_entry(sdata, &local->sub_if_list, list) { | |
1433 | rx.u.rx.ra_match = 1; | |
23a24def | 1434 | |
2a8a9a88 JB |
1435 | if (!netif_running(sdata->dev)) |
1436 | continue; | |
1437 | ||
23a24def JB |
1438 | prepres = prepare_for_handlers(sdata, bssid, &rx, hdr); |
1439 | /* prepare_for_handlers can change sta */ | |
1440 | sta = rx.sta; | |
1441 | ||
1442 | if (!prepres) | |
1443 | continue; | |
8e6f0032 | 1444 | |
340e11f3 JB |
1445 | /* |
1446 | * frame is destined for this interface, but if it's not | |
1447 | * also for the previous one we handle that after the | |
1448 | * loop to avoid copying the SKB once too much | |
1449 | */ | |
1450 | ||
1451 | if (!prev) { | |
1452 | prev = sdata; | |
1453 | continue; | |
8e6f0032 | 1454 | } |
340e11f3 JB |
1455 | |
1456 | /* | |
1457 | * frame was destined for the previous interface | |
1458 | * so invoke RX handlers for it | |
1459 | */ | |
1460 | ||
1461 | skb_new = skb_copy(skb, GFP_ATOMIC); | |
1462 | if (!skb_new) { | |
1463 | if (net_ratelimit()) | |
1464 | printk(KERN_DEBUG "%s: failed to copy " | |
1465 | "multicast frame for %s", | |
1466 | local->mdev->name, prev->dev->name); | |
1467 | continue; | |
1468 | } | |
1469 | rx.skb = skb_new; | |
1470 | rx.dev = prev->dev; | |
1471 | rx.sdata = prev; | |
1472 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, | |
1473 | &rx, sta); | |
8e6f0032 | 1474 | prev = sdata; |
571ecf67 | 1475 | } |
8e6f0032 JB |
1476 | if (prev) { |
1477 | rx.skb = skb; | |
1478 | rx.dev = prev->dev; | |
1479 | rx.sdata = prev; | |
1480 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, | |
1481 | &rx, sta); | |
1482 | } else | |
1483 | dev_kfree_skb(skb); | |
1484 | read_unlock(&local->sub_if_lock); | |
571ecf67 | 1485 | |
8e6f0032 | 1486 | end: |
571ecf67 JB |
1487 | if (sta) |
1488 | sta_info_put(sta); | |
1489 | } | |
1490 | EXPORT_SYMBOL(__ieee80211_rx); | |
1491 | ||
1492 | /* This is a version of the rx handler that can be called from hard irq | |
1493 | * context. Post the skb on the queue and schedule the tasklet */ | |
1494 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb, | |
1495 | struct ieee80211_rx_status *status) | |
1496 | { | |
1497 | struct ieee80211_local *local = hw_to_local(hw); | |
1498 | ||
1499 | BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); | |
1500 | ||
1501 | skb->dev = local->mdev; | |
1502 | /* copy status into skb->cb for use by tasklet */ | |
1503 | memcpy(skb->cb, status, sizeof(*status)); | |
1504 | skb->pkt_type = IEEE80211_RX_MSG; | |
1505 | skb_queue_tail(&local->skb_queue, skb); | |
1506 | tasklet_schedule(&local->tasklet); | |
1507 | } | |
1508 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |