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