0a18edbdfcb5bd38d36dc433d27503b10b5b226a
[sfrench/cifs-2.6.git] / 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  * <j@w1.fi>
7  * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
8  * Copyright (c) 2004-2005, 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/errno.h>
18 #include <linux/if_arp.h>
19 #include <linux/in6.h>
20 #include <linux/in.h>
21 #include <linux/ip.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/netdevice.h>
25 #include <linux/proc_fs.h>
26 #include <linux/skbuff.h>
27 #include <linux/slab.h>
28 #include <linux/tcp.h>
29 #include <linux/types.h>
30 #include <linux/wireless.h>
31 #include <linux/etherdevice.h>
32 #include <asm/uaccess.h>
33 #include <linux/ctype.h>
34
35 #include <net/ieee80211.h>
36
37 static void ieee80211_monitor_rx(struct ieee80211_device *ieee,
38                                         struct sk_buff *skb,
39                                         struct ieee80211_rx_stats *rx_stats)
40 {
41         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
42         u16 fc = le16_to_cpu(hdr->frame_ctl);
43
44         skb->dev = ieee->dev;
45         skb_reset_mac_header(skb);
46         skb_pull(skb, ieee80211_get_hdrlen(fc));
47         skb->pkt_type = PACKET_OTHERHOST;
48         skb->protocol = htons(ETH_P_80211_RAW);
49         memset(skb->cb, 0, sizeof(skb->cb));
50         netif_rx(skb);
51 }
52
53 /* Called only as a tasklet (software IRQ) */
54 static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct
55                                                               ieee80211_device
56                                                               *ieee,
57                                                               unsigned int seq,
58                                                               unsigned int frag,
59                                                               u8 * src,
60                                                               u8 * dst)
61 {
62         struct ieee80211_frag_entry *entry;
63         int i;
64
65         for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
66                 entry = &ieee->frag_cache[i];
67                 if (entry->skb != NULL &&
68                     time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
69                         IEEE80211_DEBUG_FRAG("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                     !compare_ether_addr(entry->src_addr, src) &&
79                     !compare_ether_addr(entry->dst_addr, dst))
80                         return entry;
81         }
82
83         return NULL;
84 }
85
86 /* Called only as a tasklet (software IRQ) */
87 static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee,
88                                                 struct ieee80211_hdr_4addr *hdr)
89 {
90         struct sk_buff *skb = NULL;
91         u16 sc;
92         unsigned int frag, seq;
93         struct ieee80211_frag_entry *entry;
94
95         sc = le16_to_cpu(hdr->seq_ctl);
96         frag = WLAN_GET_SEQ_FRAG(sc);
97         seq = WLAN_GET_SEQ_SEQ(sc);
98
99         if (frag == 0) {
100                 /* Reserve enough space to fit maximum frame length */
101                 skb = dev_alloc_skb(ieee->dev->mtu +
102                                     sizeof(struct ieee80211_hdr_4addr) +
103                                     8 /* LLC */  +
104                                     2 /* alignment */  +
105                                     8 /* WEP */  + ETH_ALEN /* WDS */ );
106                 if (skb == NULL)
107                         return NULL;
108
109                 entry = &ieee->frag_cache[ieee->frag_next_idx];
110                 ieee->frag_next_idx++;
111                 if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
112                         ieee->frag_next_idx = 0;
113
114                 if (entry->skb != NULL)
115                         dev_kfree_skb_any(entry->skb);
116
117                 entry->first_frag_time = jiffies;
118                 entry->seq = seq;
119                 entry->last_frag = frag;
120                 entry->skb = skb;
121                 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
122                 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
123         } else {
124                 /* received a fragment of a frame for which the head fragment
125                  * should have already been received */
126                 entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
127                                                   hdr->addr1);
128                 if (entry != NULL) {
129                         entry->last_frag = frag;
130                         skb = entry->skb;
131                 }
132         }
133
134         return skb;
135 }
136
137 /* Called only as a tasklet (software IRQ) */
138 static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
139                                            struct ieee80211_hdr_4addr *hdr)
140 {
141         u16 sc;
142         unsigned int seq;
143         struct ieee80211_frag_entry *entry;
144
145         sc = le16_to_cpu(hdr->seq_ctl);
146         seq = WLAN_GET_SEQ_SEQ(sc);
147
148         entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
149                                           hdr->addr1);
150
151         if (entry == NULL) {
152                 IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
153                                      "entry (seq=%u)\n", seq);
154                 return -1;
155         }
156
157         entry->skb = NULL;
158         return 0;
159 }
160
161 #ifdef NOT_YET
162 /* ieee80211_rx_frame_mgtmt
163  *
164  * Responsible for handling management control frames
165  *
166  * Called by ieee80211_rx */
167 static int
168 ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
169                         struct ieee80211_rx_stats *rx_stats, u16 type,
170                         u16 stype)
171 {
172         if (ieee->iw_mode == IW_MODE_MASTER) {
173                 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
174                        ieee->dev->name);
175                 return 0;
176 /*
177   hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
178   skb->data);*/
179         }
180
181         if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
182                 if (stype == WLAN_FC_STYPE_BEACON &&
183                     ieee->iw_mode == IW_MODE_MASTER) {
184                         struct sk_buff *skb2;
185                         /* Process beacon frames also in kernel driver to
186                          * update STA(AP) table statistics */
187                         skb2 = skb_clone(skb, GFP_ATOMIC);
188                         if (skb2)
189                                 hostap_rx(skb2->dev, skb2, rx_stats);
190                 }
191
192                 /* send management frames to the user space daemon for
193                  * processing */
194                 ieee->apdevstats.rx_packets++;
195                 ieee->apdevstats.rx_bytes += skb->len;
196                 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
197                 return 0;
198         }
199
200         if (ieee->iw_mode == IW_MODE_MASTER) {
201                 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
202                         printk(KERN_DEBUG "%s: unknown management frame "
203                                "(type=0x%02x, stype=0x%02x) dropped\n",
204                                skb->dev->name, type, stype);
205                         return -1;
206                 }
207
208                 hostap_rx(skb->dev, skb, rx_stats);
209                 return 0;
210         }
211
212         printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
213                "received in non-Host AP mode\n", skb->dev->name);
214         return -1;
215 }
216 #endif
217
218 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
219 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
220 static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
221
222 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
223 static unsigned char bridge_tunnel_header[] =
224     { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
225 /* No encapsulation header if EtherType < 0x600 (=length) */
226
227 /* Called by ieee80211_rx_frame_decrypt */
228 static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
229                                     struct sk_buff *skb)
230 {
231         struct net_device *dev = ieee->dev;
232         u16 fc, ethertype;
233         struct ieee80211_hdr_3addr *hdr;
234         u8 *pos;
235
236         if (skb->len < 24)
237                 return 0;
238
239         hdr = (struct ieee80211_hdr_3addr *)skb->data;
240         fc = le16_to_cpu(hdr->frame_ctl);
241
242         /* check that the frame is unicast frame to us */
243         if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
244             IEEE80211_FCTL_TODS &&
245             !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
246             !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
247                 /* ToDS frame with own addr BSSID and DA */
248         } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
249                    IEEE80211_FCTL_FROMDS &&
250                    !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
251                 /* FromDS frame with own addr as DA */
252         } else
253                 return 0;
254
255         if (skb->len < 24 + 8)
256                 return 0;
257
258         /* check for port access entity Ethernet type */
259         pos = skb->data + 24;
260         ethertype = (pos[6] << 8) | pos[7];
261         if (ethertype == ETH_P_PAE)
262                 return 1;
263
264         return 0;
265 }
266
267 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
268 static int
269 ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
270                            struct ieee80211_crypt_data *crypt)
271 {
272         struct ieee80211_hdr_3addr *hdr;
273         int res, hdrlen;
274         DECLARE_MAC_BUF(mac);
275
276         if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
277                 return 0;
278
279         hdr = (struct ieee80211_hdr_3addr *)skb->data;
280         hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
281
282         atomic_inc(&crypt->refcnt);
283         res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
284         atomic_dec(&crypt->refcnt);
285         if (res < 0) {
286                 IEEE80211_DEBUG_DROP("decryption failed (SA=%s"
287                                      ") res=%d\n", print_mac(mac, hdr->addr2), res);
288                 if (res == -2)
289                         IEEE80211_DEBUG_DROP("Decryption failed ICV "
290                                              "mismatch (key %d)\n",
291                                              skb->data[hdrlen + 3] >> 6);
292                 ieee->ieee_stats.rx_discards_undecryptable++;
293                 return -1;
294         }
295
296         return res;
297 }
298
299 /* Called only as a tasklet (software IRQ), by ieee80211_rx */
300 static int
301 ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
302                                 struct sk_buff *skb, int keyidx,
303                                 struct ieee80211_crypt_data *crypt)
304 {
305         struct ieee80211_hdr_3addr *hdr;
306         int res, hdrlen;
307         DECLARE_MAC_BUF(mac);
308
309         if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
310                 return 0;
311
312         hdr = (struct ieee80211_hdr_3addr *)skb->data;
313         hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
314
315         atomic_inc(&crypt->refcnt);
316         res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
317         atomic_dec(&crypt->refcnt);
318         if (res < 0) {
319                 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
320                        " (SA=%s keyidx=%d)\n",
321                        ieee->dev->name, print_mac(mac, hdr->addr2), keyidx);
322                 return -1;
323         }
324
325         return 0;
326 }
327
328 /* All received frames are sent to this function. @skb contains the frame in
329  * IEEE 802.11 format, i.e., in the format it was sent over air.
330  * This function is called only as a tasklet (software IRQ). */
331 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
332                  struct ieee80211_rx_stats *rx_stats)
333 {
334         struct net_device *dev = ieee->dev;
335         struct ieee80211_hdr_4addr *hdr;
336         size_t hdrlen;
337         u16 fc, type, stype, sc;
338         struct net_device_stats *stats;
339         unsigned int frag;
340         u8 *payload;
341         u16 ethertype;
342 #ifdef NOT_YET
343         struct net_device *wds = NULL;
344         struct sk_buff *skb2 = NULL;
345         struct net_device *wds = NULL;
346         int frame_authorized = 0;
347         int from_assoc_ap = 0;
348         void *sta = NULL;
349 #endif
350         u8 dst[ETH_ALEN];
351         u8 src[ETH_ALEN];
352         struct ieee80211_crypt_data *crypt = NULL;
353         int keyidx = 0;
354         int can_be_decrypted = 0;
355         DECLARE_MAC_BUF(mac);
356
357         hdr = (struct ieee80211_hdr_4addr *)skb->data;
358         stats = &ieee->stats;
359
360         if (skb->len < 10) {
361                 printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
362                 goto rx_dropped;
363         }
364
365         fc = le16_to_cpu(hdr->frame_ctl);
366         type = WLAN_FC_GET_TYPE(fc);
367         stype = WLAN_FC_GET_STYPE(fc);
368         sc = le16_to_cpu(hdr->seq_ctl);
369         frag = WLAN_GET_SEQ_FRAG(sc);
370         hdrlen = ieee80211_get_hdrlen(fc);
371
372         if (skb->len < hdrlen) {
373                 printk(KERN_INFO "%s: invalid SKB length %d\n",
374                         dev->name, skb->len);
375                 goto rx_dropped;
376         }
377
378         /* Put this code here so that we avoid duplicating it in all
379          * Rx paths. - Jean II */
380 #ifdef CONFIG_WIRELESS_EXT
381 #ifdef IW_WIRELESS_SPY          /* defined in iw_handler.h */
382         /* If spy monitoring on */
383         if (ieee->spy_data.spy_number > 0) {
384                 struct iw_quality wstats;
385
386                 wstats.updated = 0;
387                 if (rx_stats->mask & IEEE80211_STATMASK_RSSI) {
388                         wstats.level = rx_stats->rssi;
389                         wstats.updated |= IW_QUAL_LEVEL_UPDATED;
390                 } else
391                         wstats.updated |= IW_QUAL_LEVEL_INVALID;
392
393                 if (rx_stats->mask & IEEE80211_STATMASK_NOISE) {
394                         wstats.noise = rx_stats->noise;
395                         wstats.updated |= IW_QUAL_NOISE_UPDATED;
396                 } else
397                         wstats.updated |= IW_QUAL_NOISE_INVALID;
398
399                 if (rx_stats->mask & IEEE80211_STATMASK_SIGNAL) {
400                         wstats.qual = rx_stats->signal;
401                         wstats.updated |= IW_QUAL_QUAL_UPDATED;
402                 } else
403                         wstats.updated |= IW_QUAL_QUAL_INVALID;
404
405                 /* Update spy records */
406                 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
407         }
408 #endif                          /* IW_WIRELESS_SPY */
409 #endif                          /* CONFIG_WIRELESS_EXT */
410
411 #ifdef NOT_YET
412         hostap_update_rx_stats(local->ap, hdr, rx_stats);
413 #endif
414
415         if (ieee->iw_mode == IW_MODE_MONITOR) {
416                 stats->rx_packets++;
417                 stats->rx_bytes += skb->len;
418                 ieee80211_monitor_rx(ieee, skb, rx_stats);
419                 return 1;
420         }
421
422         can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
423                             is_broadcast_ether_addr(hdr->addr2)) ?
424             ieee->host_mc_decrypt : ieee->host_decrypt;
425
426         if (can_be_decrypted) {
427                 if (skb->len >= hdrlen + 3) {
428                         /* Top two-bits of byte 3 are the key index */
429                         keyidx = skb->data[hdrlen + 3] >> 6;
430                 }
431
432                 /* ieee->crypt[] is WEP_KEY (4) in length.  Given that keyidx
433                  * is only allowed 2-bits of storage, no value of keyidx can
434                  * be provided via above code that would result in keyidx
435                  * being out of range */
436                 crypt = ieee->crypt[keyidx];
437
438 #ifdef NOT_YET
439                 sta = NULL;
440
441                 /* Use station specific key to override default keys if the
442                  * receiver address is a unicast address ("individual RA"). If
443                  * bcrx_sta_key parameter is set, station specific key is used
444                  * even with broad/multicast targets (this is against IEEE
445                  * 802.11, but makes it easier to use different keys with
446                  * stations that do not support WEP key mapping). */
447
448                 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
449                         (void)hostap_handle_sta_crypto(local, hdr, &crypt,
450                                                        &sta);
451 #endif
452
453                 /* allow NULL decrypt to indicate an station specific override
454                  * for default encryption */
455                 if (crypt && (crypt->ops == NULL ||
456                               crypt->ops->decrypt_mpdu == NULL))
457                         crypt = NULL;
458
459                 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
460                         /* This seems to be triggered by some (multicast?)
461                          * frames from other than current BSS, so just drop the
462                          * frames silently instead of filling system log with
463                          * these reports. */
464                         IEEE80211_DEBUG_DROP("Decryption failed (not set)"
465                                              " (SA=%s)\n",
466                                              print_mac(mac, hdr->addr2));
467                         ieee->ieee_stats.rx_discards_undecryptable++;
468                         goto rx_dropped;
469                 }
470         }
471 #ifdef NOT_YET
472         if (type != WLAN_FC_TYPE_DATA) {
473                 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
474                     fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
475                     (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
476                         printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
477                                "from %s\n", dev->name,
478                                print_mac(mac, hdr->addr2));
479                         /* TODO: could inform hostapd about this so that it
480                          * could send auth failure report */
481                         goto rx_dropped;
482                 }
483
484                 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
485                         goto rx_dropped;
486                 else
487                         goto rx_exit;
488         }
489 #endif
490         /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
491         if (sc == ieee->prev_seq_ctl)
492                 goto rx_dropped;
493         else
494                 ieee->prev_seq_ctl = sc;
495
496         /* Data frame - extract src/dst addresses */
497         if (skb->len < IEEE80211_3ADDR_LEN)
498                 goto rx_dropped;
499
500         switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
501         case IEEE80211_FCTL_FROMDS:
502                 memcpy(dst, hdr->addr1, ETH_ALEN);
503                 memcpy(src, hdr->addr3, ETH_ALEN);
504                 break;
505         case IEEE80211_FCTL_TODS:
506                 memcpy(dst, hdr->addr3, ETH_ALEN);
507                 memcpy(src, hdr->addr2, ETH_ALEN);
508                 break;
509         case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
510                 if (skb->len < IEEE80211_4ADDR_LEN)
511                         goto rx_dropped;
512                 memcpy(dst, hdr->addr3, ETH_ALEN);
513                 memcpy(src, hdr->addr4, ETH_ALEN);
514                 break;
515         case 0:
516                 memcpy(dst, hdr->addr1, ETH_ALEN);
517                 memcpy(src, hdr->addr2, ETH_ALEN);
518                 break;
519         }
520
521 #ifdef NOT_YET
522         if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
523                 goto rx_dropped;
524         if (wds) {
525                 skb->dev = dev = wds;
526                 stats = hostap_get_stats(dev);
527         }
528
529         if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
530             (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
531             IEEE80211_FCTL_FROMDS && ieee->stadev
532             && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
533                 /* Frame from BSSID of the AP for which we are a client */
534                 skb->dev = dev = ieee->stadev;
535                 stats = hostap_get_stats(dev);
536                 from_assoc_ap = 1;
537         }
538 #endif
539
540         dev->last_rx = jiffies;
541
542 #ifdef NOT_YET
543         if ((ieee->iw_mode == IW_MODE_MASTER ||
544              ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
545                 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
546                                              wds != NULL)) {
547                 case AP_RX_CONTINUE_NOT_AUTHORIZED:
548                         frame_authorized = 0;
549                         break;
550                 case AP_RX_CONTINUE:
551                         frame_authorized = 1;
552                         break;
553                 case AP_RX_DROP:
554                         goto rx_dropped;
555                 case AP_RX_EXIT:
556                         goto rx_exit;
557                 }
558         }
559 #endif
560
561         /* Nullfunc frames may have PS-bit set, so they must be passed to
562          * hostap_handle_sta_rx() before being dropped here. */
563
564         stype &= ~IEEE80211_STYPE_QOS_DATA;
565
566         if (stype != IEEE80211_STYPE_DATA &&
567             stype != IEEE80211_STYPE_DATA_CFACK &&
568             stype != IEEE80211_STYPE_DATA_CFPOLL &&
569             stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
570                 if (stype != IEEE80211_STYPE_NULLFUNC)
571                         IEEE80211_DEBUG_DROP("RX: dropped data frame "
572                                              "with no data (type=0x%02x, "
573                                              "subtype=0x%02x, len=%d)\n",
574                                              type, stype, skb->len);
575                 goto rx_dropped;
576         }
577
578         /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
579
580         if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
581             (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
582                 goto rx_dropped;
583
584         hdr = (struct ieee80211_hdr_4addr *)skb->data;
585
586         /* skb: hdr + (possibly fragmented) plaintext payload */
587         // PR: FIXME: hostap has additional conditions in the "if" below:
588         // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
589         if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
590                 int flen;
591                 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
592                 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
593
594                 if (!frag_skb) {
595                         IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
596                                         "Rx cannot get skb from fragment "
597                                         "cache (morefrag=%d seq=%u frag=%u)\n",
598                                         (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
599                                         WLAN_GET_SEQ_SEQ(sc), frag);
600                         goto rx_dropped;
601                 }
602
603                 flen = skb->len;
604                 if (frag != 0)
605                         flen -= hdrlen;
606
607                 if (frag_skb->tail + flen > frag_skb->end) {
608                         printk(KERN_WARNING "%s: host decrypted and "
609                                "reassembled frame did not fit skb\n",
610                                dev->name);
611                         ieee80211_frag_cache_invalidate(ieee, hdr);
612                         goto rx_dropped;
613                 }
614
615                 if (frag == 0) {
616                         /* copy first fragment (including full headers) into
617                          * beginning of the fragment cache skb */
618                         skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
619                 } else {
620                         /* append frame payload to the end of the fragment
621                          * cache skb */
622                         skb_copy_from_linear_data_offset(skb, hdrlen,
623                                       skb_put(frag_skb, flen), flen);
624                 }
625                 dev_kfree_skb_any(skb);
626                 skb = NULL;
627
628                 if (fc & IEEE80211_FCTL_MOREFRAGS) {
629                         /* more fragments expected - leave the skb in fragment
630                          * cache for now; it will be delivered to upper layers
631                          * after all fragments have been received */
632                         goto rx_exit;
633                 }
634
635                 /* this was the last fragment and the frame will be
636                  * delivered, so remove skb from fragment cache */
637                 skb = frag_skb;
638                 hdr = (struct ieee80211_hdr_4addr *)skb->data;
639                 ieee80211_frag_cache_invalidate(ieee, hdr);
640         }
641
642         /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
643          * encrypted/authenticated */
644         if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
645             ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
646                 goto rx_dropped;
647
648         hdr = (struct ieee80211_hdr_4addr *)skb->data;
649         if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
650                 if (            /*ieee->ieee802_1x && */
651                            ieee80211_is_eapol_frame(ieee, skb)) {
652                         /* pass unencrypted EAPOL frames even if encryption is
653                          * configured */
654                 } else {
655                         IEEE80211_DEBUG_DROP("encryption configured, but RX "
656                                              "frame not encrypted (SA=%s"
657                                              ")\n", print_mac(mac, hdr->addr2));
658                         goto rx_dropped;
659                 }
660         }
661
662         if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
663             !ieee80211_is_eapol_frame(ieee, skb)) {
664                 IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
665                                      "frame from %s"
666                                      " (drop_unencrypted=1)\n",
667                                      print_mac(mac, hdr->addr2));
668                 goto rx_dropped;
669         }
670
671         /* If the frame was decrypted in hardware, we may need to strip off
672          * any security data (IV, ICV, etc) that was left behind */
673         if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
674             ieee->host_strip_iv_icv) {
675                 int trimlen = 0;
676
677                 /* Top two-bits of byte 3 are the key index */
678                 if (skb->len >= hdrlen + 3)
679                         keyidx = skb->data[hdrlen + 3] >> 6;
680
681                 /* To strip off any security data which appears before the
682                  * payload, we simply increase hdrlen (as the header gets
683                  * chopped off immediately below). For the security data which
684                  * appears after the payload, we use skb_trim. */
685
686                 switch (ieee->sec.encode_alg[keyidx]) {
687                 case SEC_ALG_WEP:
688                         /* 4 byte IV */
689                         hdrlen += 4;
690                         /* 4 byte ICV */
691                         trimlen = 4;
692                         break;
693                 case SEC_ALG_TKIP:
694                         /* 4 byte IV, 4 byte ExtIV */
695                         hdrlen += 8;
696                         /* 8 byte MIC, 4 byte ICV */
697                         trimlen = 12;
698                         break;
699                 case SEC_ALG_CCMP:
700                         /* 8 byte CCMP header */
701                         hdrlen += 8;
702                         /* 8 byte MIC */
703                         trimlen = 8;
704                         break;
705                 }
706
707                 if (skb->len < trimlen)
708                         goto rx_dropped;
709
710                 __skb_trim(skb, skb->len - trimlen);
711
712                 if (skb->len < hdrlen)
713                         goto rx_dropped;
714         }
715
716         /* skb: hdr + (possible reassembled) full plaintext payload */
717
718         payload = skb->data + hdrlen;
719         ethertype = (payload[6] << 8) | payload[7];
720
721 #ifdef NOT_YET
722         /* If IEEE 802.1X is used, check whether the port is authorized to send
723          * the received frame. */
724         if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
725                 if (ethertype == ETH_P_PAE) {
726                         printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
727                                dev->name);
728                         if (ieee->hostapd && ieee->apdev) {
729                                 /* Send IEEE 802.1X frames to the user
730                                  * space daemon for processing */
731                                 prism2_rx_80211(ieee->apdev, skb, rx_stats,
732                                                 PRISM2_RX_MGMT);
733                                 ieee->apdevstats.rx_packets++;
734                                 ieee->apdevstats.rx_bytes += skb->len;
735                                 goto rx_exit;
736                         }
737                 } else if (!frame_authorized) {
738                         printk(KERN_DEBUG "%s: dropped frame from "
739                                "unauthorized port (IEEE 802.1X): "
740                                "ethertype=0x%04x\n", dev->name, ethertype);
741                         goto rx_dropped;
742                 }
743         }
744 #endif
745
746         /* convert hdr + possible LLC headers into Ethernet header */
747         if (skb->len - hdrlen >= 8 &&
748             ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
749               ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
750              memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
751                 /* remove RFC1042 or Bridge-Tunnel encapsulation and
752                  * replace EtherType */
753                 skb_pull(skb, hdrlen + SNAP_SIZE);
754                 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
755                 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
756         } else {
757                 u16 len;
758                 /* Leave Ethernet header part of hdr and full payload */
759                 skb_pull(skb, hdrlen);
760                 len = htons(skb->len);
761                 memcpy(skb_push(skb, 2), &len, 2);
762                 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
763                 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
764         }
765
766 #ifdef NOT_YET
767         if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
768                     IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
769                 /* Non-standard frame: get addr4 from its bogus location after
770                  * the payload */
771                 skb_copy_to_linear_data_offset(skb, ETH_ALEN,
772                                                skb->data + skb->len - ETH_ALEN,
773                                                ETH_ALEN);
774                 skb_trim(skb, skb->len - ETH_ALEN);
775         }
776 #endif
777
778         stats->rx_packets++;
779         stats->rx_bytes += skb->len;
780
781 #ifdef NOT_YET
782         if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
783                 if (dst[0] & 0x01) {
784                         /* copy multicast frame both to the higher layers and
785                          * to the wireless media */
786                         ieee->ap->bridged_multicast++;
787                         skb2 = skb_clone(skb, GFP_ATOMIC);
788                         if (skb2 == NULL)
789                                 printk(KERN_DEBUG "%s: skb_clone failed for "
790                                        "multicast frame\n", dev->name);
791                 } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
792                         /* send frame directly to the associated STA using
793                          * wireless media and not passing to higher layers */
794                         ieee->ap->bridged_unicast++;
795                         skb2 = skb;
796                         skb = NULL;
797                 }
798         }
799
800         if (skb2 != NULL) {
801                 /* send to wireless media */
802                 skb2->dev = dev;
803                 skb2->protocol = htons(ETH_P_802_3);
804                 skb_reset_mac_header(skb2);
805                 skb_reset_network_header(skb2);
806                 /* skb2->network_header += ETH_HLEN; */
807                 dev_queue_xmit(skb2);
808         }
809 #endif
810
811         if (skb) {
812                 skb->protocol = eth_type_trans(skb, dev);
813                 memset(skb->cb, 0, sizeof(skb->cb));
814                 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
815                 if (netif_rx(skb) == NET_RX_DROP) {
816                         /* netif_rx always succeeds, but it might drop
817                          * the packet.  If it drops the packet, we log that
818                          * in our stats. */
819                         IEEE80211_DEBUG_DROP
820                             ("RX: netif_rx dropped the packet\n");
821                         stats->rx_dropped++;
822                 }
823         }
824
825       rx_exit:
826 #ifdef NOT_YET
827         if (sta)
828                 hostap_handle_sta_release(sta);
829 #endif
830         return 1;
831
832       rx_dropped:
833         stats->rx_dropped++;
834
835         /* Returning 0 indicates to caller that we have not handled the SKB--
836          * so it is still allocated and can be used again by underlying
837          * hardware as a DMA target */
838         return 0;
839 }
840
841 /* Filter out unrelated packets, call ieee80211_rx[_mgt]
842  * This function takes over the skb, it should not be used again after calling
843  * this function. */
844 void ieee80211_rx_any(struct ieee80211_device *ieee,
845                      struct sk_buff *skb, struct ieee80211_rx_stats *stats)
846 {
847         struct ieee80211_hdr_4addr *hdr;
848         int is_packet_for_us;
849         u16 fc;
850
851         if (ieee->iw_mode == IW_MODE_MONITOR) {
852                 if (!ieee80211_rx(ieee, skb, stats))
853                         dev_kfree_skb_irq(skb);
854                 return;
855         }
856
857         if (skb->len < sizeof(struct ieee80211_hdr))
858                 goto drop_free;
859
860         hdr = (struct ieee80211_hdr_4addr *)skb->data;
861         fc = le16_to_cpu(hdr->frame_ctl);
862
863         if ((fc & IEEE80211_FCTL_VERS) != 0)
864                 goto drop_free;
865
866         switch (fc & IEEE80211_FCTL_FTYPE) {
867         case IEEE80211_FTYPE_MGMT:
868                 if (skb->len < sizeof(struct ieee80211_hdr_3addr))
869                         goto drop_free;
870                 ieee80211_rx_mgt(ieee, hdr, stats);
871                 dev_kfree_skb_irq(skb);
872                 return;
873         case IEEE80211_FTYPE_DATA:
874                 break;
875         case IEEE80211_FTYPE_CTL:
876                 return;
877         default:
878                 return;
879         }
880
881         is_packet_for_us = 0;
882         switch (ieee->iw_mode) {
883         case IW_MODE_ADHOC:
884                 /* our BSS and not from/to DS */
885                 if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0)
886                 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
887                         /* promisc: get all */
888                         if (ieee->dev->flags & IFF_PROMISC)
889                                 is_packet_for_us = 1;
890                         /* to us */
891                         else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
892                                 is_packet_for_us = 1;
893                         /* mcast */
894                         else if (is_multicast_ether_addr(hdr->addr1))
895                                 is_packet_for_us = 1;
896                 }
897                 break;
898         case IW_MODE_INFRA:
899                 /* our BSS (== from our AP) and from DS */
900                 if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0)
901                 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
902                         /* promisc: get all */
903                         if (ieee->dev->flags & IFF_PROMISC)
904                                 is_packet_for_us = 1;
905                         /* to us */
906                         else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
907                                 is_packet_for_us = 1;
908                         /* mcast */
909                         else if (is_multicast_ether_addr(hdr->addr1)) {
910                                 /* not our own packet bcasted from AP */
911                                 if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN))
912                                         is_packet_for_us = 1;
913                         }
914                 }
915                 break;
916         default:
917                 /* ? */
918                 break;
919         }
920
921         if (is_packet_for_us)
922                 if (!ieee80211_rx(ieee, skb, stats))
923                         dev_kfree_skb_irq(skb);
924         return;
925
926 drop_free:
927         dev_kfree_skb_irq(skb);
928         ieee->stats.rx_dropped++;
929         return;
930 }
931
932 #define MGMT_FRAME_FIXED_PART_LENGTH            0x24
933
934 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
935
936 /*
937 * Make ther structure we read from the beacon packet has
938 * the right values
939 */
940 static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
941                                      *info_element, int sub_type)
942 {
943
944         if (info_element->qui_subtype != sub_type)
945                 return -1;
946         if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
947                 return -1;
948         if (info_element->qui_type != QOS_OUI_TYPE)
949                 return -1;
950         if (info_element->version != QOS_VERSION_1)
951                 return -1;
952
953         return 0;
954 }
955
956 /*
957  * Parse a QoS parameter element
958  */
959 static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
960                                             *element_param, struct ieee80211_info_element
961                                             *info_element)
962 {
963         int ret = 0;
964         u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
965
966         if ((info_element == NULL) || (element_param == NULL))
967                 return -1;
968
969         if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
970                 memcpy(element_param->info_element.qui, info_element->data,
971                        info_element->len);
972                 element_param->info_element.elementID = info_element->id;
973                 element_param->info_element.length = info_element->len;
974         } else
975                 ret = -1;
976         if (ret == 0)
977                 ret = ieee80211_verify_qos_info(&element_param->info_element,
978                                                 QOS_OUI_PARAM_SUB_TYPE);
979         return ret;
980 }
981
982 /*
983  * Parse a QoS information element
984  */
985 static int ieee80211_read_qos_info_element(struct
986                                            ieee80211_qos_information_element
987                                            *element_info, struct ieee80211_info_element
988                                            *info_element)
989 {
990         int ret = 0;
991         u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
992
993         if (element_info == NULL)
994                 return -1;
995         if (info_element == NULL)
996                 return -1;
997
998         if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
999                 memcpy(element_info->qui, info_element->data,
1000                        info_element->len);
1001                 element_info->elementID = info_element->id;
1002                 element_info->length = info_element->len;
1003         } else
1004                 ret = -1;
1005
1006         if (ret == 0)
1007                 ret = ieee80211_verify_qos_info(element_info,
1008                                                 QOS_OUI_INFO_SUB_TYPE);
1009         return ret;
1010 }
1011
1012 /*
1013  * Write QoS parameters from the ac parameters.
1014  */
1015 static int ieee80211_qos_convert_ac_to_parameters(struct
1016                                                   ieee80211_qos_parameter_info
1017                                                   *param_elm, struct
1018                                                   ieee80211_qos_parameters
1019                                                   *qos_param)
1020 {
1021         int rc = 0;
1022         int i;
1023         struct ieee80211_qos_ac_parameter *ac_params;
1024         u32 txop;
1025         u8 cw_min;
1026         u8 cw_max;
1027
1028         for (i = 0; i < QOS_QUEUE_NUM; i++) {
1029                 ac_params = &(param_elm->ac_params_record[i]);
1030
1031                 qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
1032                 qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
1033
1034                 cw_min = ac_params->ecw_min_max & 0x0F;
1035                 qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
1036
1037                 cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
1038                 qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
1039
1040                 qos_param->flag[i] =
1041                     (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1042
1043                 txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
1044                 qos_param->tx_op_limit[i] = cpu_to_le16(txop);
1045         }
1046         return rc;
1047 }
1048
1049 /*
1050  * we have a generic data element which it may contain QoS information or
1051  * parameters element. check the information element length to decide
1052  * which type to read
1053  */
1054 static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1055                                              *info_element,
1056                                              struct ieee80211_network *network)
1057 {
1058         int rc = 0;
1059         struct ieee80211_qos_parameters *qos_param = NULL;
1060         struct ieee80211_qos_information_element qos_info_element;
1061
1062         rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1063
1064         if (rc == 0) {
1065                 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1066                 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1067         } else {
1068                 struct ieee80211_qos_parameter_info param_element;
1069
1070                 rc = ieee80211_read_qos_param_element(&param_element,
1071                                                       info_element);
1072                 if (rc == 0) {
1073                         qos_param = &(network->qos_data.parameters);
1074                         ieee80211_qos_convert_ac_to_parameters(&param_element,
1075                                                                qos_param);
1076                         network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1077                         network->qos_data.param_count =
1078                             param_element.info_element.ac_info & 0x0F;
1079                 }
1080         }
1081
1082         if (rc == 0) {
1083                 IEEE80211_DEBUG_QOS("QoS is supported\n");
1084                 network->qos_data.supported = 1;
1085         }
1086         return rc;
1087 }
1088
1089 #ifdef CONFIG_IEEE80211_DEBUG
1090 #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1091
1092 static const char *get_info_element_string(u16 id)
1093 {
1094         switch (id) {
1095                 MFIE_STRING(SSID);
1096                 MFIE_STRING(RATES);
1097                 MFIE_STRING(FH_SET);
1098                 MFIE_STRING(DS_SET);
1099                 MFIE_STRING(CF_SET);
1100                 MFIE_STRING(TIM);
1101                 MFIE_STRING(IBSS_SET);
1102                 MFIE_STRING(COUNTRY);
1103                 MFIE_STRING(HOP_PARAMS);
1104                 MFIE_STRING(HOP_TABLE);
1105                 MFIE_STRING(REQUEST);
1106                 MFIE_STRING(CHALLENGE);
1107                 MFIE_STRING(POWER_CONSTRAINT);
1108                 MFIE_STRING(POWER_CAPABILITY);
1109                 MFIE_STRING(TPC_REQUEST);
1110                 MFIE_STRING(TPC_REPORT);
1111                 MFIE_STRING(SUPP_CHANNELS);
1112                 MFIE_STRING(CSA);
1113                 MFIE_STRING(MEASURE_REQUEST);
1114                 MFIE_STRING(MEASURE_REPORT);
1115                 MFIE_STRING(QUIET);
1116                 MFIE_STRING(IBSS_DFS);
1117                 MFIE_STRING(ERP_INFO);
1118                 MFIE_STRING(RSN);
1119                 MFIE_STRING(RATES_EX);
1120                 MFIE_STRING(GENERIC);
1121                 MFIE_STRING(QOS_PARAMETER);
1122         default:
1123                 return "UNKNOWN";
1124         }
1125 }
1126 #endif
1127
1128 static int ieee80211_parse_info_param(struct ieee80211_info_element
1129                                       *info_element, u16 length,
1130                                       struct ieee80211_network *network)
1131 {
1132         u8 i;
1133 #ifdef CONFIG_IEEE80211_DEBUG
1134         char rates_str[64];
1135         char *p;
1136 #endif
1137
1138         while (length >= sizeof(*info_element)) {
1139                 if (sizeof(*info_element) + info_element->len > length) {
1140                         IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1141                                              "info_element->len + 2 > left : "
1142                                              "info_element->len+2=%zd left=%d, id=%d.\n",
1143                                              info_element->len +
1144                                              sizeof(*info_element),
1145                                              length, info_element->id);
1146                         /* We stop processing but don't return an error here
1147                          * because some misbehaviour APs break this rule. ie.
1148                          * Orinoco AP1000. */
1149                         break;
1150                 }
1151
1152                 switch (info_element->id) {
1153                 case MFIE_TYPE_SSID:
1154                         if (ieee80211_is_empty_essid(info_element->data,
1155                                                      info_element->len)) {
1156                                 network->flags |= NETWORK_EMPTY_ESSID;
1157                                 break;
1158                         }
1159
1160                         network->ssid_len = min(info_element->len,
1161                                                 (u8) IW_ESSID_MAX_SIZE);
1162                         memcpy(network->ssid, info_element->data,
1163                                network->ssid_len);
1164                         if (network->ssid_len < IW_ESSID_MAX_SIZE)
1165                                 memset(network->ssid + network->ssid_len, 0,
1166                                        IW_ESSID_MAX_SIZE - network->ssid_len);
1167
1168                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
1169                                              network->ssid, network->ssid_len);
1170                         break;
1171
1172                 case MFIE_TYPE_RATES:
1173 #ifdef CONFIG_IEEE80211_DEBUG
1174                         p = rates_str;
1175 #endif
1176                         network->rates_len = min(info_element->len,
1177                                                  MAX_RATES_LENGTH);
1178                         for (i = 0; i < network->rates_len; i++) {
1179                                 network->rates[i] = info_element->data[i];
1180 #ifdef CONFIG_IEEE80211_DEBUG
1181                                 p += snprintf(p, sizeof(rates_str) -
1182                                               (p - rates_str), "%02X ",
1183                                               network->rates[i]);
1184 #endif
1185                                 if (ieee80211_is_ofdm_rate
1186                                     (info_element->data[i])) {
1187                                         network->flags |= NETWORK_HAS_OFDM;
1188                                         if (info_element->data[i] &
1189                                             IEEE80211_BASIC_RATE_MASK)
1190                                                 network->flags &=
1191                                                     ~NETWORK_HAS_CCK;
1192                                 }
1193                         }
1194
1195                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1196                                              rates_str, network->rates_len);
1197                         break;
1198
1199                 case MFIE_TYPE_RATES_EX:
1200 #ifdef CONFIG_IEEE80211_DEBUG
1201                         p = rates_str;
1202 #endif
1203                         network->rates_ex_len = min(info_element->len,
1204                                                     MAX_RATES_EX_LENGTH);
1205                         for (i = 0; i < network->rates_ex_len; i++) {
1206                                 network->rates_ex[i] = info_element->data[i];
1207 #ifdef CONFIG_IEEE80211_DEBUG
1208                                 p += snprintf(p, sizeof(rates_str) -
1209                                               (p - rates_str), "%02X ",
1210                                               network->rates[i]);
1211 #endif
1212                                 if (ieee80211_is_ofdm_rate
1213                                     (info_element->data[i])) {
1214                                         network->flags |= NETWORK_HAS_OFDM;
1215                                         if (info_element->data[i] &
1216                                             IEEE80211_BASIC_RATE_MASK)
1217                                                 network->flags &=
1218                                                     ~NETWORK_HAS_CCK;
1219                                 }
1220                         }
1221
1222                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1223                                              rates_str, network->rates_ex_len);
1224                         break;
1225
1226                 case MFIE_TYPE_DS_SET:
1227                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1228                                              info_element->data[0]);
1229                         network->channel = info_element->data[0];
1230                         break;
1231
1232                 case MFIE_TYPE_FH_SET:
1233                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1234                         break;
1235
1236                 case MFIE_TYPE_CF_SET:
1237                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1238                         break;
1239
1240                 case MFIE_TYPE_TIM:
1241                         network->tim.tim_count = info_element->data[0];
1242                         network->tim.tim_period = info_element->data[1];
1243                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1244                         break;
1245
1246                 case MFIE_TYPE_ERP_INFO:
1247                         network->erp_value = info_element->data[0];
1248                         network->flags |= NETWORK_HAS_ERP_VALUE;
1249                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1250                                              network->erp_value);
1251                         break;
1252
1253                 case MFIE_TYPE_IBSS_SET:
1254                         network->atim_window = info_element->data[0];
1255                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1256                                              network->atim_window);
1257                         break;
1258
1259                 case MFIE_TYPE_CHALLENGE:
1260                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
1261                         break;
1262
1263                 case MFIE_TYPE_GENERIC:
1264                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1265                                              info_element->len);
1266                         if (!ieee80211_parse_qos_info_param_IE(info_element,
1267                                                                network))
1268                                 break;
1269
1270                         if (info_element->len >= 4 &&
1271                             info_element->data[0] == 0x00 &&
1272                             info_element->data[1] == 0x50 &&
1273                             info_element->data[2] == 0xf2 &&
1274                             info_element->data[3] == 0x01) {
1275                                 network->wpa_ie_len = min(info_element->len + 2,
1276                                                           MAX_WPA_IE_LEN);
1277                                 memcpy(network->wpa_ie, info_element,
1278                                        network->wpa_ie_len);
1279                         }
1280                         break;
1281
1282                 case MFIE_TYPE_RSN:
1283                         IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1284                                              info_element->len);
1285                         network->rsn_ie_len = min(info_element->len + 2,
1286                                                   MAX_WPA_IE_LEN);
1287                         memcpy(network->rsn_ie, info_element,
1288                                network->rsn_ie_len);
1289                         break;
1290
1291                 case MFIE_TYPE_QOS_PARAMETER:
1292                         printk(KERN_ERR
1293                                "QoS Error need to parse QOS_PARAMETER IE\n");
1294                         break;
1295                         /* 802.11h */
1296                 case MFIE_TYPE_POWER_CONSTRAINT:
1297                         network->power_constraint = info_element->data[0];
1298                         network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
1299                         break;
1300
1301                 case MFIE_TYPE_CSA:
1302                         network->power_constraint = info_element->data[0];
1303                         network->flags |= NETWORK_HAS_CSA;
1304                         break;
1305
1306                 case MFIE_TYPE_QUIET:
1307                         network->quiet.count = info_element->data[0];
1308                         network->quiet.period = info_element->data[1];
1309                         network->quiet.duration = info_element->data[2];
1310                         network->quiet.offset = info_element->data[3];
1311                         network->flags |= NETWORK_HAS_QUIET;
1312                         break;
1313
1314                 case MFIE_TYPE_IBSS_DFS:
1315                         if (network->ibss_dfs)
1316                                 break;
1317                         network->ibss_dfs = kmemdup(info_element->data,
1318                                                     info_element->len,
1319                                                     GFP_ATOMIC);
1320                         if (!network->ibss_dfs)
1321                                 return 1;
1322                         network->flags |= NETWORK_HAS_IBSS_DFS;
1323                         break;
1324
1325                 case MFIE_TYPE_TPC_REPORT:
1326                         network->tpc_report.transmit_power =
1327                             info_element->data[0];
1328                         network->tpc_report.link_margin = info_element->data[1];
1329                         network->flags |= NETWORK_HAS_TPC_REPORT;
1330                         break;
1331
1332                 default:
1333                         IEEE80211_DEBUG_MGMT
1334                             ("Unsupported info element: %s (%d)\n",
1335                              get_info_element_string(info_element->id),
1336                              info_element->id);
1337                         break;
1338                 }
1339
1340                 length -= sizeof(*info_element) + info_element->len;
1341                 info_element =
1342                     (struct ieee80211_info_element *)&info_element->
1343                     data[info_element->len];
1344         }
1345
1346         return 0;
1347 }
1348
1349 static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
1350                                        *frame, struct ieee80211_rx_stats *stats)
1351 {
1352         struct ieee80211_network network_resp = {
1353                 .ibss_dfs = NULL,
1354         };
1355         struct ieee80211_network *network = &network_resp;
1356         struct net_device *dev = ieee->dev;
1357
1358         network->flags = 0;
1359         network->qos_data.active = 0;
1360         network->qos_data.supported = 0;
1361         network->qos_data.param_count = 0;
1362         network->qos_data.old_param_count = 0;
1363
1364         //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1365         network->atim_window = le16_to_cpu(frame->aid);
1366         network->listen_interval = le16_to_cpu(frame->status);
1367         memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
1368         network->capability = le16_to_cpu(frame->capability);
1369         network->last_scanned = jiffies;
1370         network->rates_len = network->rates_ex_len = 0;
1371         network->last_associate = 0;
1372         network->ssid_len = 0;
1373         network->erp_value =
1374             (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
1375
1376         if (stats->freq == IEEE80211_52GHZ_BAND) {
1377                 /* for A band (No DS info) */
1378                 network->channel = stats->received_channel;
1379         } else
1380                 network->flags |= NETWORK_HAS_CCK;
1381
1382         network->wpa_ie_len = 0;
1383         network->rsn_ie_len = 0;
1384
1385         if (ieee80211_parse_info_param
1386             (frame->info_element, stats->len - sizeof(*frame), network))
1387                 return 1;
1388
1389         network->mode = 0;
1390         if (stats->freq == IEEE80211_52GHZ_BAND)
1391                 network->mode = IEEE_A;
1392         else {
1393                 if (network->flags & NETWORK_HAS_OFDM)
1394                         network->mode |= IEEE_G;
1395                 if (network->flags & NETWORK_HAS_CCK)
1396                         network->mode |= IEEE_B;
1397         }
1398
1399         if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
1400                 network->flags |= NETWORK_EMPTY_ESSID;
1401
1402         memcpy(&network->stats, stats, sizeof(network->stats));
1403
1404         if (ieee->handle_assoc_response != NULL)
1405                 ieee->handle_assoc_response(dev, frame, network);
1406
1407         return 0;
1408 }
1409
1410 /***************************************************/
1411
1412 static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
1413                                          *beacon,
1414                                          struct ieee80211_network *network,
1415                                          struct ieee80211_rx_stats *stats)
1416 {
1417         DECLARE_MAC_BUF(mac);
1418
1419         network->qos_data.active = 0;
1420         network->qos_data.supported = 0;
1421         network->qos_data.param_count = 0;
1422         network->qos_data.old_param_count = 0;
1423
1424         /* Pull out fixed field data */
1425         memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
1426         network->capability = le16_to_cpu(beacon->capability);
1427         network->last_scanned = jiffies;
1428         network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
1429         network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
1430         network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
1431         /* Where to pull this? beacon->listen_interval; */
1432         network->listen_interval = 0x0A;
1433         network->rates_len = network->rates_ex_len = 0;
1434         network->last_associate = 0;
1435         network->ssid_len = 0;
1436         network->flags = 0;
1437         network->atim_window = 0;
1438         network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
1439             0x3 : 0x0;
1440
1441         if (stats->freq == IEEE80211_52GHZ_BAND) {
1442                 /* for A band (No DS info) */
1443                 network->channel = stats->received_channel;
1444         } else
1445                 network->flags |= NETWORK_HAS_CCK;
1446
1447         network->wpa_ie_len = 0;
1448         network->rsn_ie_len = 0;
1449
1450         if (ieee80211_parse_info_param
1451             (beacon->info_element, stats->len - sizeof(*beacon), network))
1452                 return 1;
1453
1454         network->mode = 0;
1455         if (stats->freq == IEEE80211_52GHZ_BAND)
1456                 network->mode = IEEE_A;
1457         else {
1458                 if (network->flags & NETWORK_HAS_OFDM)
1459                         network->mode |= IEEE_G;
1460                 if (network->flags & NETWORK_HAS_CCK)
1461                         network->mode |= IEEE_B;
1462         }
1463
1464         if (network->mode == 0) {
1465                 IEEE80211_DEBUG_SCAN("Filtered out '%s (%s)' "
1466                                      "network.\n",
1467                                      escape_essid(network->ssid,
1468                                                   network->ssid_len),
1469                                      print_mac(mac, network->bssid));
1470                 return 1;
1471         }
1472
1473         if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
1474                 network->flags |= NETWORK_EMPTY_ESSID;
1475
1476         memcpy(&network->stats, stats, sizeof(network->stats));
1477
1478         return 0;
1479 }
1480
1481 static inline int is_same_network(struct ieee80211_network *src,
1482                                   struct ieee80211_network *dst)
1483 {
1484         /* A network is only a duplicate if the channel, BSSID, and ESSID
1485          * all match.  We treat all <hidden> with the same BSSID and channel
1486          * as one network */
1487         return ((src->ssid_len == dst->ssid_len) &&
1488                 (src->channel == dst->channel) &&
1489                 !compare_ether_addr(src->bssid, dst->bssid) &&
1490                 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1491 }
1492
1493 static void update_network(struct ieee80211_network *dst,
1494                                   struct ieee80211_network *src)
1495 {
1496         int qos_active;
1497         u8 old_param;
1498         DECLARE_MAC_BUF(mac);
1499
1500         ieee80211_network_reset(dst);
1501         dst->ibss_dfs = src->ibss_dfs;
1502
1503         /* We only update the statistics if they were created by receiving
1504          * the network information on the actual channel the network is on.
1505          *
1506          * This keeps beacons received on neighbor channels from bringing
1507          * down the signal level of an AP. */
1508         if (dst->channel == src->stats.received_channel)
1509                 memcpy(&dst->stats, &src->stats,
1510                        sizeof(struct ieee80211_rx_stats));
1511         else
1512                 IEEE80211_DEBUG_SCAN("Network %s info received "
1513                         "off channel (%d vs. %d)\n", print_mac(mac, src->bssid),
1514                         dst->channel, src->stats.received_channel);
1515
1516         dst->capability = src->capability;
1517         memcpy(dst->rates, src->rates, src->rates_len);
1518         dst->rates_len = src->rates_len;
1519         memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1520         dst->rates_ex_len = src->rates_ex_len;
1521
1522         dst->mode = src->mode;
1523         dst->flags = src->flags;
1524         dst->time_stamp[0] = src->time_stamp[0];
1525         dst->time_stamp[1] = src->time_stamp[1];
1526
1527         dst->beacon_interval = src->beacon_interval;
1528         dst->listen_interval = src->listen_interval;
1529         dst->atim_window = src->atim_window;
1530         dst->erp_value = src->erp_value;
1531         dst->tim = src->tim;
1532
1533         memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1534         dst->wpa_ie_len = src->wpa_ie_len;
1535         memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1536         dst->rsn_ie_len = src->rsn_ie_len;
1537
1538         dst->last_scanned = jiffies;
1539         qos_active = src->qos_data.active;
1540         old_param = dst->qos_data.old_param_count;
1541         if (dst->flags & NETWORK_HAS_QOS_MASK)
1542                 memcpy(&dst->qos_data, &src->qos_data,
1543                        sizeof(struct ieee80211_qos_data));
1544         else {
1545                 dst->qos_data.supported = src->qos_data.supported;
1546                 dst->qos_data.param_count = src->qos_data.param_count;
1547         }
1548
1549         if (dst->qos_data.supported == 1) {
1550                 if (dst->ssid_len)
1551                         IEEE80211_DEBUG_QOS
1552                             ("QoS the network %s is QoS supported\n",
1553                              dst->ssid);
1554                 else
1555                         IEEE80211_DEBUG_QOS
1556                             ("QoS the network is QoS supported\n");
1557         }
1558         dst->qos_data.active = qos_active;
1559         dst->qos_data.old_param_count = old_param;
1560
1561         /* dst->last_associate is not overwritten */
1562 }
1563
1564 static inline int is_beacon(__le16 fc)
1565 {
1566         return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
1567 }
1568
1569 static void ieee80211_process_probe_response(struct ieee80211_device
1570                                                     *ieee, struct
1571                                                     ieee80211_probe_response
1572                                                     *beacon, struct ieee80211_rx_stats
1573                                                     *stats)
1574 {
1575         struct net_device *dev = ieee->dev;
1576         struct ieee80211_network network = {
1577                 .ibss_dfs = NULL,
1578         };
1579         struct ieee80211_network *target;
1580         struct ieee80211_network *oldest = NULL;
1581 #ifdef CONFIG_IEEE80211_DEBUG
1582         struct ieee80211_info_element *info_element = beacon->info_element;
1583 #endif
1584         unsigned long flags;
1585         DECLARE_MAC_BUF(mac);
1586
1587         IEEE80211_DEBUG_SCAN("'%s' (%s"
1588                              "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1589                              escape_essid(info_element->data,
1590                                           info_element->len),
1591                              print_mac(mac, beacon->header.addr3),
1592                              (beacon->capability & (1 << 0xf)) ? '1' : '0',
1593                              (beacon->capability & (1 << 0xe)) ? '1' : '0',
1594                              (beacon->capability & (1 << 0xd)) ? '1' : '0',
1595                              (beacon->capability & (1 << 0xc)) ? '1' : '0',
1596                              (beacon->capability & (1 << 0xb)) ? '1' : '0',
1597                              (beacon->capability & (1 << 0xa)) ? '1' : '0',
1598                              (beacon->capability & (1 << 0x9)) ? '1' : '0',
1599                              (beacon->capability & (1 << 0x8)) ? '1' : '0',
1600                              (beacon->capability & (1 << 0x7)) ? '1' : '0',
1601                              (beacon->capability & (1 << 0x6)) ? '1' : '0',
1602                              (beacon->capability & (1 << 0x5)) ? '1' : '0',
1603                              (beacon->capability & (1 << 0x4)) ? '1' : '0',
1604                              (beacon->capability & (1 << 0x3)) ? '1' : '0',
1605                              (beacon->capability & (1 << 0x2)) ? '1' : '0',
1606                              (beacon->capability & (1 << 0x1)) ? '1' : '0',
1607                              (beacon->capability & (1 << 0x0)) ? '1' : '0');
1608
1609         if (ieee80211_network_init(ieee, beacon, &network, stats)) {
1610                 IEEE80211_DEBUG_SCAN("Dropped '%s' (%s) via %s.\n",
1611                                      escape_essid(info_element->data,
1612                                                   info_element->len),
1613                                      print_mac(mac, beacon->header.addr3),
1614                                      is_beacon(beacon->header.frame_ctl) ?
1615                                      "BEACON" : "PROBE RESPONSE");
1616                 return;
1617         }
1618
1619         /* The network parsed correctly -- so now we scan our known networks
1620          * to see if we can find it in our list.
1621          *
1622          * NOTE:  This search is definitely not optimized.  Once its doing
1623          *        the "right thing" we'll optimize it for efficiency if
1624          *        necessary */
1625
1626         /* Search for this entry in the list and update it if it is
1627          * already there. */
1628
1629         spin_lock_irqsave(&ieee->lock, flags);
1630
1631         list_for_each_entry(target, &ieee->network_list, list) {
1632                 if (is_same_network(target, &network))
1633                         break;
1634
1635                 if ((oldest == NULL) ||
1636                     (target->last_scanned < oldest->last_scanned))
1637                         oldest = target;
1638         }
1639
1640         /* If we didn't find a match, then get a new network slot to initialize
1641          * with this beacon's information */
1642         if (&target->list == &ieee->network_list) {
1643                 if (list_empty(&ieee->network_free_list)) {
1644                         /* If there are no more slots, expire the oldest */
1645                         list_del(&oldest->list);
1646                         target = oldest;
1647                         IEEE80211_DEBUG_SCAN("Expired '%s' (%s) from "
1648                                              "network list.\n",
1649                                              escape_essid(target->ssid,
1650                                                           target->ssid_len),
1651                                              print_mac(mac, target->bssid));
1652                         ieee80211_network_reset(target);
1653                 } else {
1654                         /* Otherwise just pull from the free list */
1655                         target = list_entry(ieee->network_free_list.next,
1656                                             struct ieee80211_network, list);
1657                         list_del(ieee->network_free_list.next);
1658                 }
1659
1660 #ifdef CONFIG_IEEE80211_DEBUG
1661                 IEEE80211_DEBUG_SCAN("Adding '%s' (%s) via %s.\n",
1662                                      escape_essid(network.ssid,
1663                                                   network.ssid_len),
1664                                      print_mac(mac, network.bssid),
1665                                      is_beacon(beacon->header.frame_ctl) ?
1666                                      "BEACON" : "PROBE RESPONSE");
1667 #endif
1668                 memcpy(target, &network, sizeof(*target));
1669                 network.ibss_dfs = NULL;
1670                 list_add_tail(&target->list, &ieee->network_list);
1671         } else {
1672                 IEEE80211_DEBUG_SCAN("Updating '%s' (%s) via %s.\n",
1673                                      escape_essid(target->ssid,
1674                                                   target->ssid_len),
1675                                      print_mac(mac, target->bssid),
1676                                      is_beacon(beacon->header.frame_ctl) ?
1677                                      "BEACON" : "PROBE RESPONSE");
1678                 update_network(target, &network);
1679                 network.ibss_dfs = NULL;
1680         }
1681
1682         spin_unlock_irqrestore(&ieee->lock, flags);
1683
1684         if (is_beacon(beacon->header.frame_ctl)) {
1685                 if (ieee->handle_beacon != NULL)
1686                         ieee->handle_beacon(dev, beacon, target);
1687         } else {
1688                 if (ieee->handle_probe_response != NULL)
1689                         ieee->handle_probe_response(dev, beacon, target);
1690         }
1691 }
1692
1693 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1694                       struct ieee80211_hdr_4addr *header,
1695                       struct ieee80211_rx_stats *stats)
1696 {
1697         switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
1698         case IEEE80211_STYPE_ASSOC_RESP:
1699                 IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
1700                                      WLAN_FC_GET_STYPE(le16_to_cpu
1701                                                        (header->frame_ctl)));
1702                 ieee80211_handle_assoc_resp(ieee,
1703                                             (struct ieee80211_assoc_response *)
1704                                             header, stats);
1705                 break;
1706
1707         case IEEE80211_STYPE_REASSOC_RESP:
1708                 IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
1709                                      WLAN_FC_GET_STYPE(le16_to_cpu
1710                                                        (header->frame_ctl)));
1711                 break;
1712
1713         case IEEE80211_STYPE_PROBE_REQ:
1714                 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
1715                                      WLAN_FC_GET_STYPE(le16_to_cpu
1716                                                        (header->frame_ctl)));
1717
1718                 if (ieee->handle_probe_request != NULL)
1719                         ieee->handle_probe_request(ieee->dev,
1720                                                    (struct
1721                                                     ieee80211_probe_request *)
1722                                                    header, stats);
1723                 break;
1724
1725         case IEEE80211_STYPE_PROBE_RESP:
1726                 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
1727                                      WLAN_FC_GET_STYPE(le16_to_cpu
1728                                                        (header->frame_ctl)));
1729                 IEEE80211_DEBUG_SCAN("Probe response\n");
1730                 ieee80211_process_probe_response(ieee,
1731                                                  (struct
1732                                                   ieee80211_probe_response *)
1733                                                  header, stats);
1734                 break;
1735
1736         case IEEE80211_STYPE_BEACON:
1737                 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
1738                                      WLAN_FC_GET_STYPE(le16_to_cpu
1739                                                        (header->frame_ctl)));
1740                 IEEE80211_DEBUG_SCAN("Beacon\n");
1741                 ieee80211_process_probe_response(ieee,
1742                                                  (struct
1743                                                   ieee80211_probe_response *)
1744                                                  header, stats);
1745                 break;
1746         case IEEE80211_STYPE_AUTH:
1747
1748                 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
1749                                      WLAN_FC_GET_STYPE(le16_to_cpu
1750                                                        (header->frame_ctl)));
1751
1752                 if (ieee->handle_auth != NULL)
1753                         ieee->handle_auth(ieee->dev,
1754                                           (struct ieee80211_auth *)header);
1755                 break;
1756
1757         case IEEE80211_STYPE_DISASSOC:
1758                 if (ieee->handle_disassoc != NULL)
1759                         ieee->handle_disassoc(ieee->dev,
1760                                               (struct ieee80211_disassoc *)
1761                                               header);
1762                 break;
1763
1764         case IEEE80211_STYPE_ACTION:
1765                 IEEE80211_DEBUG_MGMT("ACTION\n");
1766                 if (ieee->handle_action)
1767                         ieee->handle_action(ieee->dev,
1768                                             (struct ieee80211_action *)
1769                                             header, stats);
1770                 break;
1771
1772         case IEEE80211_STYPE_REASSOC_REQ:
1773                 IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
1774                                      WLAN_FC_GET_STYPE(le16_to_cpu
1775                                                        (header->frame_ctl)));
1776
1777                 IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
1778                                      ieee->dev->name);
1779                 if (ieee->handle_reassoc_request != NULL)
1780                         ieee->handle_reassoc_request(ieee->dev,
1781                                                     (struct ieee80211_reassoc_request *)
1782                                                      header);
1783                 break;
1784
1785         case IEEE80211_STYPE_ASSOC_REQ:
1786                 IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
1787                                      WLAN_FC_GET_STYPE(le16_to_cpu
1788                                                        (header->frame_ctl)));
1789
1790                 IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
1791                                      ieee->dev->name);
1792                 if (ieee->handle_assoc_request != NULL)
1793                         ieee->handle_assoc_request(ieee->dev);
1794                 break;
1795
1796         case IEEE80211_STYPE_DEAUTH:
1797                 IEEE80211_DEBUG_MGMT("DEAUTH\n");
1798                 if (ieee->handle_deauth != NULL)
1799                         ieee->handle_deauth(ieee->dev,
1800                                             (struct ieee80211_deauth *)
1801                                             header);
1802                 break;
1803         default:
1804                 IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
1805                                      WLAN_FC_GET_STYPE(le16_to_cpu
1806                                                        (header->frame_ctl)));
1807                 IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1808                                      ieee->dev->name,
1809                                      WLAN_FC_GET_STYPE(le16_to_cpu
1810                                                        (header->frame_ctl)));
1811                 break;
1812         }
1813 }
1814
1815 EXPORT_SYMBOL_GPL(ieee80211_rx_any);
1816 EXPORT_SYMBOL(ieee80211_rx_mgt);
1817 EXPORT_SYMBOL(ieee80211_rx);