/spare/repo/netdev-2.6 branch 'master'
[linux-2.6] / net / ieee80211 / ieee80211_rx.c
1 /*
2  * Original code based Host AP (software wireless LAN access point) driver
3  * for Intersil Prism2/2.5/3 - hostap.o module, common routines
4  *
5  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6  * <jkmaline@cc.hut.fi>
7  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8  * Copyright (c) 2004, Intel Corporation
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation. See README and COPYING for
13  * more details.
14  */
15
16 #include <linux/compiler.h>
17 #include <linux/config.h>
18 #include <linux/errno.h>
19 #include <linux/if_arp.h>
20 #include <linux/in6.h>
21 #include <linux/in.h>
22 #include <linux/ip.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/netdevice.h>
26 #include <linux/proc_fs.h>
27 #include <linux/skbuff.h>
28 #include <linux/slab.h>
29 #include <linux/tcp.h>
30 #include <linux/types.h>
31 #include <linux/version.h>
32 #include <linux/wireless.h>
33 #include <linux/etherdevice.h>
34 #include <asm/uaccess.h>
35 #include <linux/ctype.h>
36
37 #include <net/ieee80211.h>
38
39 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
40                                         struct sk_buff *skb,
41                                         struct ieee80211_rx_stats *rx_stats)
42 {
43         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
44         u16 fc = le16_to_cpu(hdr->frame_ctl);
45
46         skb->dev = ieee->dev;
47         skb->mac.raw = skb->data;
48         skb_pull(skb, ieee80211_get_hdrlen(fc));
49         skb->pkt_type = PACKET_OTHERHOST;
50         skb->protocol = __constant_htons(ETH_P_80211_RAW);
51         memset(skb->cb, 0, sizeof(skb->cb));
52         netif_rx(skb);
53 }
54
55
56 /* Called only as a tasklet (software IRQ) */
57 static struct ieee80211_frag_entry *
58 ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
59                           unsigned int frag, u8 *src, u8 *dst)
60 {
61         struct ieee80211_frag_entry *entry;
62         int i;
63
64         for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
65                 entry = &ieee->frag_cache[i];
66                 if (entry->skb != NULL &&
67                     time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
68                         IEEE80211_DEBUG_FRAG(
69                                 "expiring fragment cache entry "
70                                 "seq=%u last_frag=%u\n",
71                                 entry->seq, entry->last_frag);
72                         dev_kfree_skb_any(entry->skb);
73                         entry->skb = NULL;
74                 }
75
76                 if (entry->skb != NULL && entry->seq == seq &&
77                     (entry->last_frag + 1 == frag || frag == -1) &&
78                     memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
79                     memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
80                         return entry;
81         }
82
83         return NULL;
84 }
85
86 /* Called only as a tasklet (software IRQ) */
87 static struct sk_buff *
88 ieee80211_frag_cache_get(struct ieee80211_device *ieee,
89                          struct ieee80211_hdr *hdr)
90 {
91         struct sk_buff *skb = NULL;
92         u16 sc;
93         unsigned int frag, seq;
94         struct ieee80211_frag_entry *entry;
95
96         sc = le16_to_cpu(hdr->seq_ctl);
97         frag = WLAN_GET_SEQ_FRAG(sc);
98         seq = WLAN_GET_SEQ_SEQ(sc);
99
100         if (frag == 0) {
101                 /* Reserve enough space to fit maximum frame length */
102                 skb = dev_alloc_skb(ieee->dev->mtu +
103                                     sizeof(struct ieee80211_hdr) +
104                                     8 /* LLC */ +
105                                     2 /* alignment */ +
106                                     8 /* WEP */ + ETH_ALEN /* WDS */);
107                 if (skb == NULL)
108                         return NULL;
109
110                 entry = &ieee->frag_cache[ieee->frag_next_idx];
111                 ieee->frag_next_idx++;
112                 if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
113                         ieee->frag_next_idx = 0;
114
115                 if (entry->skb != NULL)
116                         dev_kfree_skb_any(entry->skb);
117
118                 entry->first_frag_time = jiffies;
119                 entry->seq = seq;
120                 entry->last_frag = frag;
121                 entry->skb = skb;
122                 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
123                 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
124         } else {
125                 /* received a fragment of a frame for which the head fragment
126                  * should have already been received */
127                 entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
128                                                   hdr->addr1);
129                 if (entry != NULL) {
130                         entry->last_frag = frag;
131                         skb = entry->skb;
132                 }
133         }
134
135         return skb;
136 }
137
138
139 /* Called only as a tasklet (software IRQ) */
140 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
141                                            struct ieee80211_hdr *hdr)
142 {
143         u16 sc;
144         unsigned int seq;
145         struct ieee80211_frag_entry *entry;
146
147         sc = le16_to_cpu(hdr->seq_ctl);
148         seq = WLAN_GET_SEQ_SEQ(sc);
149
150         entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
151                                           hdr->addr1);
152
153         if (entry == NULL) {
154                 IEEE80211_DEBUG_FRAG(
155                         "could not invalidate fragment cache "
156                         "entry (seq=%u)\n", seq);
157                 return -1;
158         }
159
160         entry->skb = NULL;
161         return 0;
162 }
163
164
165 #ifdef NOT_YET
166 /* ieee80211_rx_frame_mgtmt
167  *
168  * Responsible for handling management control frames
169  *
170  * Called by ieee80211_rx */
171 static inline int
172 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
173                         struct ieee80211_rx_stats *rx_stats, u16 type,
174                         u16 stype)
175 {
176         if (ieee->iw_mode == IW_MODE_MASTER) {
177                 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
178                        ieee->dev->name);
179                 return 0;
180 /*
181   hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr *)
182   skb->data);*/
183         }
184
185         if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
186                 if (stype == WLAN_FC_STYPE_BEACON &&
187                     ieee->iw_mode == IW_MODE_MASTER) {
188                         struct sk_buff *skb2;
189                         /* Process beacon frames also in kernel driver to
190                          * update STA(AP) table statistics */
191                         skb2 = skb_clone(skb, GFP_ATOMIC);
192                         if (skb2)
193                                 hostap_rx(skb2->dev, skb2, rx_stats);
194                 }
195
196                 /* send management frames to the user space daemon for
197                  * processing */
198                 ieee->apdevstats.rx_packets++;
199                 ieee->apdevstats.rx_bytes += skb->len;
200                 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
201                 return 0;
202         }
203
204             if (ieee->iw_mode == IW_MODE_MASTER) {
205                 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
206                         printk(KERN_DEBUG "%s: unknown management frame "
207                                "(type=0x%02x, stype=0x%02x) dropped\n",
208                                skb->dev->name, type, stype);
209                         return -1;
210                 }
211
212                 hostap_rx(skb->dev, skb, rx_stats);
213                 return 0;
214         }
215
216         printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
217                "received in non-Host AP mode\n", skb->dev->name);
218         return -1;
219 }
220 #endif
221
222
223 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
224 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
225 static unsigned char rfc1042_header[] =
226 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
227 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
228 static unsigned char bridge_tunnel_header[] =
229 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
230 /* No encapsulation header if EtherType < 0x600 (=length) */
231
232 /* Called by ieee80211_rx_frame_decrypt */
233 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
234                                     struct sk_buff *skb)
235 {
236         struct net_device *dev = ieee->dev;
237         u16 fc, ethertype;
238         struct ieee80211_hdr *hdr;
239         u8 *pos;
240
241         if (skb->len < 24)
242                 return 0;
243
244         hdr = (struct ieee80211_hdr *) skb->data;
245         fc = le16_to_cpu(hdr->frame_ctl);
246
247         /* check that the frame is unicast frame to us */
248         if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
249             IEEE80211_FCTL_TODS &&
250             memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
251             memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
252                 /* ToDS frame with own addr BSSID and DA */
253         } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
254                    IEEE80211_FCTL_FROMDS &&
255                    memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
256                 /* FromDS frame with own addr as DA */
257         } else
258                 return 0;
259
260         if (skb->len < 24 + 8)
261                 return 0;
262
263         /* check for port access entity Ethernet type */
264         pos = skb->data + 24;
265         ethertype = (pos[6] << 8) | pos[7];
266         if (ethertype == ETH_P_PAE)
267                 return 1;
268
269         return 0;
270 }
271
272 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
273 static inline int
274 ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
275                            struct ieee80211_crypt_data *crypt)
276 {
277         struct ieee80211_hdr *hdr;
278         int res, hdrlen;
279
280         if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
281                 return 0;
282
283         hdr = (struct ieee80211_hdr *) skb->data;
284         hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
285
286 #ifdef CONFIG_IEEE80211_CRYPT_TKIP
287         if (ieee->tkip_countermeasures &&
288             strcmp(crypt->ops->name, "TKIP") == 0) {
289                 if (net_ratelimit()) {
290                         printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
291                                "received packet from " MAC_FMT "\n",
292                                ieee->dev->name, MAC_ARG(hdr->addr2));
293                 }
294                 return -1;
295         }
296 #endif
297
298         atomic_inc(&crypt->refcnt);
299         res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
300         atomic_dec(&crypt->refcnt);
301         if (res < 0) {
302                 IEEE80211_DEBUG_DROP(
303                         "decryption failed (SA=" MAC_FMT
304                         ") res=%d\n", MAC_ARG(hdr->addr2), res);
305                 if (res == -2)
306                         IEEE80211_DEBUG_DROP("Decryption failed ICV "
307                                              "mismatch (key %d)\n",
308                                              skb->data[hdrlen + 3] >> 6);
309                 ieee->ieee_stats.rx_discards_undecryptable++;
310                 return -1;
311         }
312
313         return res;
314 }
315
316
317 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
318 static inline int
319 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
320                              int keyidx, struct ieee80211_crypt_data *crypt)
321 {
322         struct ieee80211_hdr *hdr;
323         int res, hdrlen;
324
325         if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
326                 return 0;
327
328         hdr = (struct ieee80211_hdr *) skb->data;
329         hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
330
331         atomic_inc(&crypt->refcnt);
332         res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
333         atomic_dec(&crypt->refcnt);
334         if (res < 0) {
335                 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
336                        " (SA=" MAC_FMT " keyidx=%d)\n",
337                        ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
338                 return -1;
339         }
340
341         return 0;
342 }
343
344
345 /* All received frames are sent to this function. @skb contains the frame in
346  * IEEE 802.11 format, i.e., in the format it was sent over air.
347  * This function is called only as a tasklet (software IRQ). */
348 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
349                  struct ieee80211_rx_stats *rx_stats)
350 {
351         struct net_device *dev = ieee->dev;
352         struct ieee80211_hdr *hdr;
353         size_t hdrlen;
354         u16 fc, type, stype, sc;
355         struct net_device_stats *stats;
356         unsigned int frag;
357         u8 *payload;
358         u16 ethertype;
359 #ifdef NOT_YET
360         struct net_device *wds = NULL;
361         struct sk_buff *skb2 = NULL;
362         struct net_device *wds = NULL;
363         int frame_authorized = 0;
364         int from_assoc_ap = 0;
365         void *sta = NULL;
366 #endif
367         u8 dst[ETH_ALEN];
368         u8 src[ETH_ALEN];
369         struct ieee80211_crypt_data *crypt = NULL;
370         int keyidx = 0;
371
372         hdr = (struct ieee80211_hdr *)skb->data;
373         stats = &ieee->stats;
374
375         if (skb->len < 10) {
376                 printk(KERN_INFO "%s: SKB length < 10\n",
377                        dev->name);
378                 goto rx_dropped;
379         }
380
381         fc = le16_to_cpu(hdr->frame_ctl);
382         type = WLAN_FC_GET_TYPE(fc);
383         stype = WLAN_FC_GET_STYPE(fc);
384         sc = le16_to_cpu(hdr->seq_ctl);
385         frag = WLAN_GET_SEQ_FRAG(sc);
386         hdrlen = ieee80211_get_hdrlen(fc);
387
388 #ifdef NOT_YET
389 #if WIRELESS_EXT > 15
390         /* Put this code here so that we avoid duplicating it in all
391          * Rx paths. - Jean II */
392 #ifdef IW_WIRELESS_SPY          /* defined in iw_handler.h */
393         /* If spy monitoring on */
394         if (iface->spy_data.spy_number > 0) {
395                 struct iw_quality wstats;
396                 wstats.level = rx_stats->signal;
397                 wstats.noise = rx_stats->noise;
398                 wstats.updated = 6;     /* No qual value */
399                 /* Update spy records */
400                 wireless_spy_update(dev, hdr->addr2, &wstats);
401         }
402 #endif /* IW_WIRELESS_SPY */
403 #endif /* WIRELESS_EXT > 15 */
404         hostap_update_rx_stats(local->ap, hdr, rx_stats);
405 #endif
406
407 #if WIRELESS_EXT > 15
408         if (ieee->iw_mode == IW_MODE_MONITOR) {
409                 ieee80211_monitor_rx(ieee, skb, rx_stats);
410                 stats->rx_packets++;
411                 stats->rx_bytes += skb->len;
412                 return 1;
413         }
414 #endif
415
416         if (ieee->host_decrypt) {
417                 int idx = 0;
418                 if (skb->len >= hdrlen + 3)
419                         idx = skb->data[hdrlen + 3] >> 6;
420                 crypt = ieee->crypt[idx];
421 #ifdef NOT_YET
422                 sta = NULL;
423
424                 /* Use station specific key to override default keys if the
425                  * receiver address is a unicast address ("individual RA"). If
426                  * bcrx_sta_key parameter is set, station specific key is used
427                  * even with broad/multicast targets (this is against IEEE
428                  * 802.11, but makes it easier to use different keys with
429                  * stations that do not support WEP key mapping). */
430
431                 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
432                         (void) hostap_handle_sta_crypto(local, hdr, &crypt,
433                                                         &sta);
434 #endif
435
436                 /* allow NULL decrypt to indicate an station specific override
437                  * for default encryption */
438                 if (crypt && (crypt->ops == NULL ||
439                               crypt->ops->decrypt_mpdu == NULL))
440                         crypt = NULL;
441
442                 if (!crypt && (fc & IEEE80211_FCTL_WEP)) {
443                         /* This seems to be triggered by some (multicast?)
444                          * frames from other than current BSS, so just drop the
445                          * frames silently instead of filling system log with
446                          * these reports. */
447                         IEEE80211_DEBUG_DROP("Decryption failed (not set)"
448                                              " (SA=" MAC_FMT ")\n",
449                                              MAC_ARG(hdr->addr2));
450                         ieee->ieee_stats.rx_discards_undecryptable++;
451                         goto rx_dropped;
452                 }
453         }
454
455 #ifdef NOT_YET
456         if (type != WLAN_FC_TYPE_DATA) {
457                 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
458                     fc & IEEE80211_FCTL_WEP && ieee->host_decrypt &&
459                     (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0)
460                 {
461                         printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
462                                "from " MAC_FMT "\n", dev->name,
463                                MAC_ARG(hdr->addr2));
464                         /* TODO: could inform hostapd about this so that it
465                          * could send auth failure report */
466                         goto rx_dropped;
467                 }
468
469                 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
470                         goto rx_dropped;
471                 else
472                         goto rx_exit;
473         }
474 #endif
475
476         /* Data frame - extract src/dst addresses */
477         if (skb->len < IEEE80211_3ADDR_LEN)
478                 goto rx_dropped;
479
480         switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
481         case IEEE80211_FCTL_FROMDS:
482                 memcpy(dst, hdr->addr1, ETH_ALEN);
483                 memcpy(src, hdr->addr3, ETH_ALEN);
484                 break;
485         case IEEE80211_FCTL_TODS:
486                 memcpy(dst, hdr->addr3, ETH_ALEN);
487                 memcpy(src, hdr->addr2, ETH_ALEN);
488                 break;
489         case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
490                 if (skb->len < IEEE80211_4ADDR_LEN)
491                         goto rx_dropped;
492                 memcpy(dst, hdr->addr3, ETH_ALEN);
493                 memcpy(src, hdr->addr4, ETH_ALEN);
494                 break;
495         case 0:
496                 memcpy(dst, hdr->addr1, ETH_ALEN);
497                 memcpy(src, hdr->addr2, ETH_ALEN);
498                 break;
499         }
500
501 #ifdef NOT_YET
502         if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
503                 goto rx_dropped;
504         if (wds) {
505                 skb->dev = dev = wds;
506                 stats = hostap_get_stats(dev);
507         }
508
509         if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
510             (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
511             ieee->stadev &&
512             memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
513                 /* Frame from BSSID of the AP for which we are a client */
514                 skb->dev = dev = ieee->stadev;
515                 stats = hostap_get_stats(dev);
516                 from_assoc_ap = 1;
517         }
518 #endif
519
520         dev->last_rx = jiffies;
521
522 #ifdef NOT_YET
523         if ((ieee->iw_mode == IW_MODE_MASTER ||
524              ieee->iw_mode == IW_MODE_REPEAT) &&
525             !from_assoc_ap) {
526                 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
527                                              wds != NULL)) {
528                 case AP_RX_CONTINUE_NOT_AUTHORIZED:
529                         frame_authorized = 0;
530                         break;
531                 case AP_RX_CONTINUE:
532                         frame_authorized = 1;
533                         break;
534                 case AP_RX_DROP:
535                         goto rx_dropped;
536                 case AP_RX_EXIT:
537                         goto rx_exit;
538                 }
539         }
540 #endif
541
542         /* Nullfunc frames may have PS-bit set, so they must be passed to
543          * hostap_handle_sta_rx() before being dropped here. */
544         if (stype != IEEE80211_STYPE_DATA &&
545             stype != IEEE80211_STYPE_DATA_CFACK &&
546             stype != IEEE80211_STYPE_DATA_CFPOLL &&
547             stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
548                 if (stype != IEEE80211_STYPE_NULLFUNC)
549                         IEEE80211_DEBUG_DROP(
550                                 "RX: dropped data frame "
551                                 "with no data (type=0x%02x, "
552                                 "subtype=0x%02x, len=%d)\n",
553                                 type, stype, skb->len);
554                 goto rx_dropped;
555         }
556
557         /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
558
559         if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
560             (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
561                 goto rx_dropped;
562
563         hdr = (struct ieee80211_hdr *) skb->data;
564
565         /* skb: hdr + (possibly fragmented) plaintext payload */
566         // PR: FIXME: hostap has additional conditions in the "if" below:
567         // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
568         if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
569                 int flen;
570                 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
571                 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
572
573                 if (!frag_skb) {
574                         IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
575                                         "Rx cannot get skb from fragment "
576                                         "cache (morefrag=%d seq=%u frag=%u)\n",
577                                         (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
578                                         WLAN_GET_SEQ_SEQ(sc), frag);
579                         goto rx_dropped;
580                 }
581
582                 flen = skb->len;
583                 if (frag != 0)
584                         flen -= hdrlen;
585
586                 if (frag_skb->tail + flen > frag_skb->end) {
587                         printk(KERN_WARNING "%s: host decrypted and "
588                                "reassembled frame did not fit skb\n",
589                                dev->name);
590                         ieee80211_frag_cache_invalidate(ieee, hdr);
591                         goto rx_dropped;
592                 }
593
594                 if (frag == 0) {
595                         /* copy first fragment (including full headers) into
596                          * beginning of the fragment cache skb */
597                         memcpy(skb_put(frag_skb, flen), skb->data, flen);
598                 } else {
599                         /* append frame payload to the end of the fragment
600                          * cache skb */
601                         memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
602                                flen);
603                 }
604                 dev_kfree_skb_any(skb);
605                 skb = NULL;
606
607                 if (fc & IEEE80211_FCTL_MOREFRAGS) {
608                         /* more fragments expected - leave the skb in fragment
609                          * cache for now; it will be delivered to upper layers
610                          * after all fragments have been received */
611                         goto rx_exit;
612                 }
613
614                 /* this was the last fragment and the frame will be
615                  * delivered, so remove skb from fragment cache */
616                 skb = frag_skb;
617                 hdr = (struct ieee80211_hdr *) skb->data;
618                 ieee80211_frag_cache_invalidate(ieee, hdr);
619         }
620
621         /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
622          * encrypted/authenticated */
623         if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
624             ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
625                 goto rx_dropped;
626
627         hdr = (struct ieee80211_hdr *) skb->data;
628         if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
629                 if (/*ieee->ieee802_1x &&*/
630                     ieee80211_is_eapol_frame(ieee, skb)) {
631 #ifdef CONFIG_IEEE80211_DEBUG
632                         /* pass unencrypted EAPOL frames even if encryption is
633                          * configured */
634                         struct eapol *eap = (struct eapol *)(skb->data +
635                                 24);
636                         IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
637                                                 eap_get_type(eap->type));
638 #endif
639                 } else {
640                         IEEE80211_DEBUG_DROP(
641                                 "encryption configured, but RX "
642                                 "frame not encrypted (SA=" MAC_FMT ")\n",
643                                 MAC_ARG(hdr->addr2));
644                         goto rx_dropped;
645                 }
646         }
647
648 #ifdef CONFIG_IEEE80211_DEBUG
649         if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
650             ieee80211_is_eapol_frame(ieee, skb)) {
651                         struct eapol *eap = (struct eapol *)(skb->data +
652                                 24);
653                         IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
654                                                 eap_get_type(eap->type));
655         }
656 #endif
657
658         if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep &&
659             !ieee80211_is_eapol_frame(ieee, skb)) {
660                 IEEE80211_DEBUG_DROP(
661                         "dropped unencrypted RX data "
662                         "frame from " MAC_FMT
663                         " (drop_unencrypted=1)\n",
664                         MAC_ARG(hdr->addr2));
665                 goto rx_dropped;
666         }
667
668         /* skb: hdr + (possible reassembled) full plaintext payload */
669
670         payload = skb->data + hdrlen;
671         ethertype = (payload[6] << 8) | payload[7];
672
673 #ifdef NOT_YET
674         /* If IEEE 802.1X is used, check whether the port is authorized to send
675          * the received frame. */
676         if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
677                 if (ethertype == ETH_P_PAE) {
678                         printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
679                                dev->name);
680                         if (ieee->hostapd && ieee->apdev) {
681                                 /* Send IEEE 802.1X frames to the user
682                                  * space daemon for processing */
683                                 prism2_rx_80211(ieee->apdev, skb, rx_stats,
684                                                 PRISM2_RX_MGMT);
685                                 ieee->apdevstats.rx_packets++;
686                                 ieee->apdevstats.rx_bytes += skb->len;
687                                 goto rx_exit;
688                         }
689                 } else if (!frame_authorized) {
690                         printk(KERN_DEBUG "%s: dropped frame from "
691                                "unauthorized port (IEEE 802.1X): "
692                                "ethertype=0x%04x\n",
693                                dev->name, ethertype);
694                         goto rx_dropped;
695                 }
696         }
697 #endif
698
699         /* convert hdr + possible LLC headers into Ethernet header */
700         if (skb->len - hdrlen >= 8 &&
701             ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
702               ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
703              memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
704                 /* remove RFC1042 or Bridge-Tunnel encapsulation and
705                  * replace EtherType */
706                 skb_pull(skb, hdrlen + SNAP_SIZE);
707                 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
708                 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
709         } else {
710                 u16 len;
711                 /* Leave Ethernet header part of hdr and full payload */
712                 skb_pull(skb, hdrlen);
713                 len = htons(skb->len);
714                 memcpy(skb_push(skb, 2), &len, 2);
715                 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
716                 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
717         }
718
719 #ifdef NOT_YET
720         if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
721                     IEEE80211_FCTL_TODS) &&
722             skb->len >= ETH_HLEN + ETH_ALEN) {
723                 /* Non-standard frame: get addr4 from its bogus location after
724                  * the payload */
725                 memcpy(skb->data + ETH_ALEN,
726                        skb->data + skb->len - ETH_ALEN, ETH_ALEN);
727                 skb_trim(skb, skb->len - ETH_ALEN);
728         }
729 #endif
730
731         stats->rx_packets++;
732         stats->rx_bytes += skb->len;
733
734 #ifdef NOT_YET
735         if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
736             ieee->ap->bridge_packets) {
737                 if (dst[0] & 0x01) {
738                         /* copy multicast frame both to the higher layers and
739                          * to the wireless media */
740                         ieee->ap->bridged_multicast++;
741                         skb2 = skb_clone(skb, GFP_ATOMIC);
742                         if (skb2 == NULL)
743                                 printk(KERN_DEBUG "%s: skb_clone failed for "
744                                        "multicast frame\n", dev->name);
745                 } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
746                         /* send frame directly to the associated STA using
747                          * wireless media and not passing to higher layers */
748                         ieee->ap->bridged_unicast++;
749                         skb2 = skb;
750                         skb = NULL;
751                 }
752         }
753
754         if (skb2 != NULL) {
755                 /* send to wireless media */
756                 skb2->protocol = __constant_htons(ETH_P_802_3);
757                 skb2->mac.raw = skb2->nh.raw = skb2->data;
758                 /* skb2->nh.raw = skb2->data + ETH_HLEN; */
759                 skb2->dev = dev;
760                 dev_queue_xmit(skb2);
761         }
762
763 #endif
764
765         if (skb) {
766                 skb->protocol = eth_type_trans(skb, dev);
767                 memset(skb->cb, 0, sizeof(skb->cb));
768                 skb->dev = dev;
769                 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
770                 netif_rx(skb);
771         }
772
773  rx_exit:
774 #ifdef NOT_YET
775         if (sta)
776                 hostap_handle_sta_release(sta);
777 #endif
778         return 1;
779
780  rx_dropped:
781         stats->rx_dropped++;
782
783         /* Returning 0 indicates to caller that we have not handled the SKB--
784          * so it is still allocated and can be used again by underlying
785          * hardware as a DMA target */
786         return 0;
787 }
788
789 #define MGMT_FRAME_FIXED_PART_LENGTH            0x24
790
791 static inline int ieee80211_is_ofdm_rate(u8 rate)
792 {
793         switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
794         case IEEE80211_OFDM_RATE_6MB:
795         case IEEE80211_OFDM_RATE_9MB:
796         case IEEE80211_OFDM_RATE_12MB:
797         case IEEE80211_OFDM_RATE_18MB:
798         case IEEE80211_OFDM_RATE_24MB:
799         case IEEE80211_OFDM_RATE_36MB:
800         case IEEE80211_OFDM_RATE_48MB:
801         case IEEE80211_OFDM_RATE_54MB:
802                 return 1;
803         }
804         return 0;
805 }
806
807
808 static inline int ieee80211_network_init(
809         struct ieee80211_device *ieee,
810         struct ieee80211_probe_response *beacon,
811         struct ieee80211_network *network,
812         struct ieee80211_rx_stats *stats)
813 {
814 #ifdef CONFIG_IEEE80211_DEBUG
815         char rates_str[64];
816         char *p;
817 #endif
818         struct ieee80211_info_element *info_element;
819         u16 left;
820         u8 i;
821
822         /* Pull out fixed field data */
823         memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
824         network->capability = beacon->capability;
825         network->last_scanned = jiffies;
826         network->time_stamp[0] = beacon->time_stamp[0];
827         network->time_stamp[1] = beacon->time_stamp[1];
828         network->beacon_interval = beacon->beacon_interval;
829         /* Where to pull this? beacon->listen_interval;*/
830         network->listen_interval = 0x0A;
831         network->rates_len = network->rates_ex_len = 0;
832         network->last_associate = 0;
833         network->ssid_len = 0;
834         network->flags = 0;
835         network->atim_window = 0;
836
837         if (stats->freq == IEEE80211_52GHZ_BAND) {
838                 /* for A band (No DS info) */
839                 network->channel = stats->received_channel;
840         } else
841                 network->flags |= NETWORK_HAS_CCK;
842
843         network->wpa_ie_len = 0;
844         network->rsn_ie_len = 0;
845
846         info_element = &beacon->info_element;
847         left = stats->len - ((void *)info_element - (void *)beacon);
848         while (left >= sizeof(struct ieee80211_info_element_hdr)) {
849                 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
850                         IEEE80211_DEBUG_SCAN("SCAN: parse failed: info_element->len + 2 > left : info_element->len+2=%d left=%d.\n",
851                                              info_element->len + sizeof(struct ieee80211_info_element),
852                                              left);
853                         return 1;
854                 }
855
856                 switch (info_element->id) {
857                 case MFIE_TYPE_SSID:
858                         if (ieee80211_is_empty_essid(info_element->data,
859                                                      info_element->len)) {
860                                 network->flags |= NETWORK_EMPTY_ESSID;
861                                 break;
862                         }
863
864                         network->ssid_len = min(info_element->len,
865                                                 (u8)IW_ESSID_MAX_SIZE);
866                         memcpy(network->ssid, info_element->data, network->ssid_len);
867                         if (network->ssid_len < IW_ESSID_MAX_SIZE)
868                                 memset(network->ssid + network->ssid_len, 0,
869                                        IW_ESSID_MAX_SIZE - network->ssid_len);
870
871                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_SSID: '%s' len=%d.\n",
872                                              network->ssid, network->ssid_len);
873                         break;
874
875                 case MFIE_TYPE_RATES:
876 #ifdef CONFIG_IEEE80211_DEBUG
877                         p = rates_str;
878 #endif
879                         network->rates_len = min(info_element->len, MAX_RATES_LENGTH);
880                         for (i = 0; i < network->rates_len; i++) {
881                                 network->rates[i] = info_element->data[i];
882 #ifdef CONFIG_IEEE80211_DEBUG
883                                 p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
884 #endif
885                                 if (ieee80211_is_ofdm_rate(info_element->data[i])) {
886                                         network->flags |= NETWORK_HAS_OFDM;
887                                         if (info_element->data[i] &
888                                             IEEE80211_BASIC_RATE_MASK)
889                                                 network->flags &=
890                                                         ~NETWORK_HAS_CCK;
891                                 }
892                         }
893
894                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES: '%s' (%d)\n",
895                                              rates_str, network->rates_len);
896                         break;
897
898                 case MFIE_TYPE_RATES_EX:
899 #ifdef CONFIG_IEEE80211_DEBUG
900                         p = rates_str;
901 #endif
902                         network->rates_ex_len = min(info_element->len, MAX_RATES_EX_LENGTH);
903                         for (i = 0; i < network->rates_ex_len; i++) {
904                                 network->rates_ex[i] = info_element->data[i];
905 #ifdef CONFIG_IEEE80211_DEBUG
906                                 p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
907 #endif
908                                 if (ieee80211_is_ofdm_rate(info_element->data[i])) {
909                                         network->flags |= NETWORK_HAS_OFDM;
910                                         if (info_element->data[i] &
911                                             IEEE80211_BASIC_RATE_MASK)
912                                                 network->flags &=
913                                                         ~NETWORK_HAS_CCK;
914                                 }
915                         }
916
917                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
918                                              rates_str, network->rates_ex_len);
919                         break;
920
921                 case MFIE_TYPE_DS_SET:
922                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_DS_SET: %d\n",
923                                              info_element->data[0]);
924                         if (stats->freq == IEEE80211_24GHZ_BAND)
925                                 network->channel = info_element->data[0];
926                         break;
927
928                 case MFIE_TYPE_FH_SET:
929                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_FH_SET: ignored\n");
930                         break;
931
932                 case MFIE_TYPE_CF_SET:
933                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_CF_SET: ignored\n");
934                         break;
935
936                 case MFIE_TYPE_TIM:
937                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_TIM: ignored\n");
938                         break;
939
940                 case MFIE_TYPE_IBSS_SET:
941                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_IBSS_SET: ignored\n");
942                         break;
943
944                 case MFIE_TYPE_CHALLENGE:
945                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_CHALLENGE: ignored\n");
946                         break;
947
948                 case MFIE_TYPE_GENERIC:
949                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n",
950                                              info_element->len);
951                         if (info_element->len >= 4  &&
952                             info_element->data[0] == 0x00 &&
953                             info_element->data[1] == 0x50 &&
954                             info_element->data[2] == 0xf2 &&
955                             info_element->data[3] == 0x01) {
956                                 network->wpa_ie_len = min(info_element->len + 2,
957                                                          MAX_WPA_IE_LEN);
958                                 memcpy(network->wpa_ie, info_element,
959                                        network->wpa_ie_len);
960                         }
961                         break;
962
963                 case MFIE_TYPE_RSN:
964                         IEEE80211_DEBUG_SCAN("MFIE_TYPE_RSN: %d bytes\n",
965                                              info_element->len);
966                         network->rsn_ie_len = min(info_element->len + 2,
967                                                  MAX_WPA_IE_LEN);
968                         memcpy(network->rsn_ie, info_element,
969                                network->rsn_ie_len);
970                         break;
971
972                 default:
973                         IEEE80211_DEBUG_SCAN("unsupported IE %d\n",
974                                              info_element->id);
975                         break;
976                 }
977
978                 left -= sizeof(struct ieee80211_info_element_hdr) +
979                         info_element->len;
980                 info_element = (struct ieee80211_info_element *)
981                         &info_element->data[info_element->len];
982         }
983
984         network->mode = 0;
985         if (stats->freq == IEEE80211_52GHZ_BAND)
986                 network->mode = IEEE_A;
987         else {
988                 if (network->flags & NETWORK_HAS_OFDM)
989                         network->mode |= IEEE_G;
990                 if (network->flags & NETWORK_HAS_CCK)
991                         network->mode |= IEEE_B;
992         }
993
994         if (network->mode == 0) {
995                 IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
996                                      "network.\n",
997                                      escape_essid(network->ssid,
998                                                   network->ssid_len),
999                                      MAC_ARG(network->bssid));
1000                 return 1;
1001         }
1002
1003         if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
1004                 network->flags |= NETWORK_EMPTY_ESSID;
1005
1006         memcpy(&network->stats, stats, sizeof(network->stats));
1007
1008         return 0;
1009 }
1010
1011 static inline int is_same_network(struct ieee80211_network *src,
1012                                   struct ieee80211_network *dst)
1013 {
1014         /* A network is only a duplicate if the channel, BSSID, and ESSID
1015          * all match.  We treat all <hidden> with the same BSSID and channel
1016          * as one network */
1017         return ((src->ssid_len == dst->ssid_len) &&
1018                 (src->channel == dst->channel) &&
1019                 !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
1020                 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1021 }
1022
1023 static inline void update_network(struct ieee80211_network *dst,
1024                                   struct ieee80211_network *src)
1025 {
1026         memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
1027         dst->capability = src->capability;
1028         memcpy(dst->rates, src->rates, src->rates_len);
1029         dst->rates_len = src->rates_len;
1030         memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1031         dst->rates_ex_len = src->rates_ex_len;
1032
1033         dst->mode = src->mode;
1034         dst->flags = src->flags;
1035         dst->time_stamp[0] = src->time_stamp[0];
1036         dst->time_stamp[1] = src->time_stamp[1];
1037
1038         dst->beacon_interval = src->beacon_interval;
1039         dst->listen_interval = src->listen_interval;
1040         dst->atim_window = src->atim_window;
1041
1042         memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1043         dst->wpa_ie_len = src->wpa_ie_len;
1044         memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1045         dst->rsn_ie_len = src->rsn_ie_len;
1046
1047         dst->last_scanned = jiffies;
1048         /* dst->last_associate is not overwritten */
1049 }
1050
1051 static inline void ieee80211_process_probe_response(
1052         struct ieee80211_device *ieee,
1053         struct ieee80211_probe_response *beacon,
1054         struct ieee80211_rx_stats *stats)
1055 {
1056         struct ieee80211_network network;
1057         struct ieee80211_network *target;
1058         struct ieee80211_network *oldest = NULL;
1059 #ifdef CONFIG_IEEE80211_DEBUG
1060         struct ieee80211_info_element *info_element = &beacon->info_element;
1061 #endif
1062         unsigned long flags;
1063
1064         IEEE80211_DEBUG_SCAN(
1065                 "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1066                 escape_essid(info_element->data, info_element->len),
1067                 MAC_ARG(beacon->header.addr3),
1068                 (beacon->capability & (1<<0xf)) ? '1' : '0',
1069                 (beacon->capability & (1<<0xe)) ? '1' : '0',
1070                 (beacon->capability & (1<<0xd)) ? '1' : '0',
1071                 (beacon->capability & (1<<0xc)) ? '1' : '0',
1072                 (beacon->capability & (1<<0xb)) ? '1' : '0',
1073                 (beacon->capability & (1<<0xa)) ? '1' : '0',
1074                 (beacon->capability & (1<<0x9)) ? '1' : '0',
1075                 (beacon->capability & (1<<0x8)) ? '1' : '0',
1076                 (beacon->capability & (1<<0x7)) ? '1' : '0',
1077                 (beacon->capability & (1<<0x6)) ? '1' : '0',
1078                 (beacon->capability & (1<<0x5)) ? '1' : '0',
1079                 (beacon->capability & (1<<0x4)) ? '1' : '0',
1080                 (beacon->capability & (1<<0x3)) ? '1' : '0',
1081                 (beacon->capability & (1<<0x2)) ? '1' : '0',
1082                 (beacon->capability & (1<<0x1)) ? '1' : '0',
1083                 (beacon->capability & (1<<0x0)) ? '1' : '0');
1084
1085         if (ieee80211_network_init(ieee, beacon, &network, stats)) {
1086                 IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
1087                                      escape_essid(info_element->data,
1088                                                   info_element->len),
1089                                      MAC_ARG(beacon->header.addr3),
1090                                      WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1091                                      IEEE80211_STYPE_PROBE_RESP ?
1092                                      "PROBE RESPONSE" : "BEACON");
1093                 return;
1094         }
1095
1096         /* The network parsed correctly -- so now we scan our known networks
1097          * to see if we can find it in our list.
1098          *
1099          * NOTE:  This search is definitely not optimized.  Once its doing
1100          *        the "right thing" we'll optimize it for efficiency if
1101          *        necessary */
1102
1103         /* Search for this entry in the list and update it if it is
1104          * already there. */
1105
1106         spin_lock_irqsave(&ieee->lock, flags);
1107
1108         list_for_each_entry(target, &ieee->network_list, list) {
1109                 if (is_same_network(target, &network))
1110                         break;
1111
1112                 if ((oldest == NULL) ||
1113                     (target->last_scanned < oldest->last_scanned))
1114                         oldest = target;
1115         }
1116
1117         /* If we didn't find a match, then get a new network slot to initialize
1118          * with this beacon's information */
1119         if (&target->list == &ieee->network_list) {
1120                 if (list_empty(&ieee->network_free_list)) {
1121                         /* If there are no more slots, expire the oldest */
1122                         list_del(&oldest->list);
1123                         target = oldest;
1124                         IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
1125                                              "network list.\n",
1126                                              escape_essid(target->ssid,
1127                                                           target->ssid_len),
1128                                              MAC_ARG(target->bssid));
1129                 } else {
1130                         /* Otherwise just pull from the free list */
1131                         target = list_entry(ieee->network_free_list.next,
1132                                             struct ieee80211_network, list);
1133                         list_del(ieee->network_free_list.next);
1134                 }
1135
1136
1137 #ifdef CONFIG_IEEE80211_DEBUG
1138                 IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
1139                                      escape_essid(network.ssid,
1140                                                   network.ssid_len),
1141                                      MAC_ARG(network.bssid),
1142                                      WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1143                                      IEEE80211_STYPE_PROBE_RESP ?
1144                                      "PROBE RESPONSE" : "BEACON");
1145 #endif
1146                 memcpy(target, &network, sizeof(*target));
1147                 list_add_tail(&target->list, &ieee->network_list);
1148         } else {
1149                 IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
1150                                      escape_essid(target->ssid,
1151                                                   target->ssid_len),
1152                                      MAC_ARG(target->bssid),
1153                                      WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
1154                                      IEEE80211_STYPE_PROBE_RESP ?
1155                                      "PROBE RESPONSE" : "BEACON");
1156                 update_network(target, &network);
1157         }
1158
1159         spin_unlock_irqrestore(&ieee->lock, flags);
1160 }
1161
1162 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1163                       struct ieee80211_hdr *header,
1164                       struct ieee80211_rx_stats *stats)
1165 {
1166         switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
1167         case IEEE80211_STYPE_ASSOC_RESP:
1168                 IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
1169                                      WLAN_FC_GET_STYPE(header->frame_ctl));
1170                 break;
1171
1172         case IEEE80211_STYPE_REASSOC_RESP:
1173                 IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
1174                                      WLAN_FC_GET_STYPE(header->frame_ctl));
1175                 break;
1176
1177         case IEEE80211_STYPE_PROBE_RESP:
1178                 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1179                                      WLAN_FC_GET_STYPE(header->frame_ctl));
1180                 IEEE80211_DEBUG_SCAN("Probe response\n");
1181                 ieee80211_process_probe_response(
1182                         ieee, (struct ieee80211_probe_response *)header, stats);
1183                 break;
1184
1185         case IEEE80211_STYPE_BEACON:
1186                 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
1187                                      WLAN_FC_GET_STYPE(header->frame_ctl));
1188                 IEEE80211_DEBUG_SCAN("Beacon\n");
1189                 ieee80211_process_probe_response(
1190                         ieee, (struct ieee80211_probe_response *)header, stats);
1191                 break;
1192
1193         default:
1194                 IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
1195                                      WLAN_FC_GET_STYPE(header->frame_ctl));
1196                 IEEE80211_WARNING("%s: Unknown management packet: %d\n",
1197                                   ieee->dev->name,
1198                                   WLAN_FC_GET_STYPE(header->frame_ctl));
1199                 break;
1200         }
1201 }
1202
1203
1204 EXPORT_SYMBOL(ieee80211_rx_mgt);
1205 EXPORT_SYMBOL(ieee80211_rx);