blob: dae4b8e4d8e9a3cf9c965e3e6ed0a2661f1c5865 [file] [log] [blame]
Jeff Garzikb4538722005-05-12 22:48:20 -04001/*
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
Jouni Malinen85d32e72007-03-24 17:15:30 -07006 * <j@w1.fi>
7 * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
James Ketrenosebeaddc2005-09-21 11:58:43 -05008 * Copyright (c) 2004-2005, Intel Corporation
Jeff Garzikb4538722005-05-12 22:48:20 -04009 *
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>
Jeff Garzikb4538722005-05-12 22:48:20 -040017#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>
Jeff Garzikb4538722005-05-12 22:48:20 -040025#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>
Jeff Garzikb4538722005-05-12 22:48:20 -040030#include <linux/wireless.h>
31#include <linux/etherdevice.h>
32#include <asm/uaccess.h>
33#include <linux/ctype.h>
34
John W. Linville7e272fc2008-09-24 18:13:14 -040035#include <net/lib80211.h>
Dan Williamsf3734ee2009-02-12 12:32:55 -050036
37#include "ieee80211.h"
Jeff Garzikb4538722005-05-12 22:48:20 -040038
Arjan van de Ven858119e2006-01-14 13:20:43 -080039static void ieee80211_monitor_rx(struct ieee80211_device *ieee,
Jeff Garzikb4538722005-05-12 22:48:20 -040040 struct sk_buff *skb,
41 struct ieee80211_rx_stats *rx_stats)
42{
43 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -040044 u16 fc = le16_to_cpu(hdr->frame_control);
Jeff Garzikb4538722005-05-12 22:48:20 -040045
46 skb->dev = ieee->dev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -070047 skb_reset_mac_header(skb);
Jeff Garzikb4538722005-05-12 22:48:20 -040048 skb_pull(skb, ieee80211_get_hdrlen(fc));
49 skb->pkt_type = PACKET_OTHERHOST;
YOSHIFUJI Hideaki4e394302007-12-12 03:52:26 +090050 skb->protocol = htons(ETH_P_80211_RAW);
Jeff Garzikb4538722005-05-12 22:48:20 -040051 memset(skb->cb, 0, sizeof(skb->cb));
52 netif_rx(skb);
53}
54
Jeff Garzikb4538722005-05-12 22:48:20 -040055/* Called only as a tasklet (software IRQ) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040056static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct
57 ieee80211_device
58 *ieee,
59 unsigned int seq,
60 unsigned int frag,
61 u8 * src,
62 u8 * dst)
Jeff Garzikb4538722005-05-12 22:48:20 -040063{
64 struct ieee80211_frag_entry *entry;
65 int i;
66
67 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
68 entry = &ieee->frag_cache[i];
69 if (entry->skb != NULL &&
70 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040071 IEEE80211_DEBUG_FRAG("expiring fragment cache entry "
72 "seq=%u last_frag=%u\n",
73 entry->seq, entry->last_frag);
Jeff Garzikb4538722005-05-12 22:48:20 -040074 dev_kfree_skb_any(entry->skb);
75 entry->skb = NULL;
76 }
77
78 if (entry->skb != NULL && entry->seq == seq &&
79 (entry->last_frag + 1 == frag || frag == -1) &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -080080 !compare_ether_addr(entry->src_addr, src) &&
81 !compare_ether_addr(entry->dst_addr, dst))
Jeff Garzikb4538722005-05-12 22:48:20 -040082 return entry;
83 }
84
85 return NULL;
86}
87
88/* Called only as a tasklet (software IRQ) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040089static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee,
James Ketrenosee34af32005-09-21 11:54:36 -050090 struct ieee80211_hdr_4addr *hdr)
Jeff Garzikb4538722005-05-12 22:48:20 -040091{
92 struct sk_buff *skb = NULL;
93 u16 sc;
94 unsigned int frag, seq;
95 struct ieee80211_frag_entry *entry;
96
97 sc = le16_to_cpu(hdr->seq_ctl);
98 frag = WLAN_GET_SEQ_FRAG(sc);
99 seq = WLAN_GET_SEQ_SEQ(sc);
100
101 if (frag == 0) {
102 /* Reserve enough space to fit maximum frame length */
103 skb = dev_alloc_skb(ieee->dev->mtu +
James Ketrenosee34af32005-09-21 11:54:36 -0500104 sizeof(struct ieee80211_hdr_4addr) +
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400105 8 /* LLC */ +
106 2 /* alignment */ +
107 8 /* WEP */ + ETH_ALEN /* WDS */ );
Jeff Garzikb4538722005-05-12 22:48:20 -0400108 if (skb == NULL)
109 return NULL;
110
111 entry = &ieee->frag_cache[ieee->frag_next_idx];
112 ieee->frag_next_idx++;
113 if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
114 ieee->frag_next_idx = 0;
115
116 if (entry->skb != NULL)
117 dev_kfree_skb_any(entry->skb);
118
119 entry->first_frag_time = jiffies;
120 entry->seq = seq;
121 entry->last_frag = frag;
122 entry->skb = skb;
123 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
124 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
125 } else {
126 /* received a fragment of a frame for which the head fragment
127 * should have already been received */
128 entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
129 hdr->addr1);
130 if (entry != NULL) {
131 entry->last_frag = frag;
132 skb = entry->skb;
133 }
134 }
135
136 return skb;
137}
138
Jeff Garzikb4538722005-05-12 22:48:20 -0400139/* Called only as a tasklet (software IRQ) */
140static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
James Ketrenosee34af32005-09-21 11:54:36 -0500141 struct ieee80211_hdr_4addr *hdr)
Jeff Garzikb4538722005-05-12 22:48:20 -0400142{
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) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400154 IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
155 "entry (seq=%u)\n", seq);
Jeff Garzikb4538722005-05-12 22:48:20 -0400156 return -1;
157 }
158
159 entry->skb = NULL;
160 return 0;
161}
162
Jeff Garzikb4538722005-05-12 22:48:20 -0400163#ifdef NOT_YET
164/* ieee80211_rx_frame_mgtmt
165 *
166 * Responsible for handling management control frames
167 *
168 * Called by ieee80211_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800169static int
Jeff Garzikb4538722005-05-12 22:48:20 -0400170ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
171 struct ieee80211_rx_stats *rx_stats, u16 type,
172 u16 stype)
173{
174 if (ieee->iw_mode == IW_MODE_MASTER) {
175 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
176 ieee->dev->name);
177 return 0;
178/*
James Ketrenosee34af32005-09-21 11:54:36 -0500179 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
Jeff Garzikb4538722005-05-12 22:48:20 -0400180 skb->data);*/
181 }
182
183 if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
184 if (stype == WLAN_FC_STYPE_BEACON &&
185 ieee->iw_mode == IW_MODE_MASTER) {
186 struct sk_buff *skb2;
187 /* Process beacon frames also in kernel driver to
188 * update STA(AP) table statistics */
189 skb2 = skb_clone(skb, GFP_ATOMIC);
190 if (skb2)
191 hostap_rx(skb2->dev, skb2, rx_stats);
192 }
193
194 /* send management frames to the user space daemon for
195 * processing */
196 ieee->apdevstats.rx_packets++;
197 ieee->apdevstats.rx_bytes += skb->len;
198 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
199 return 0;
200 }
201
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400202 if (ieee->iw_mode == IW_MODE_MASTER) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400203 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
204 printk(KERN_DEBUG "%s: unknown management frame "
205 "(type=0x%02x, stype=0x%02x) dropped\n",
206 skb->dev->name, type, stype);
207 return -1;
208 }
209
210 hostap_rx(skb->dev, skb, rx_stats);
211 return 0;
212 }
213
214 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
215 "received in non-Host AP mode\n", skb->dev->name);
216 return -1;
217}
218#endif
219
Jeff Garzikb4538722005-05-12 22:48:20 -0400220/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
221/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400222static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
223
Jeff Garzikb4538722005-05-12 22:48:20 -0400224/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
225static unsigned char bridge_tunnel_header[] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400226 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
Jeff Garzikb4538722005-05-12 22:48:20 -0400227/* No encapsulation header if EtherType < 0x600 (=length) */
228
229/* Called by ieee80211_rx_frame_decrypt */
230static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
231 struct sk_buff *skb)
232{
233 struct net_device *dev = ieee->dev;
234 u16 fc, ethertype;
James Ketrenosee34af32005-09-21 11:54:36 -0500235 struct ieee80211_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400236 u8 *pos;
237
238 if (skb->len < 24)
239 return 0;
240
James Ketrenosee34af32005-09-21 11:54:36 -0500241 hdr = (struct ieee80211_hdr_3addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400242 fc = le16_to_cpu(hdr->frame_ctl);
243
244 /* check that the frame is unicast frame to us */
245 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
246 IEEE80211_FCTL_TODS &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -0800247 !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
248 !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400249 /* ToDS frame with own addr BSSID and DA */
250 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
251 IEEE80211_FCTL_FROMDS &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -0800252 !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400253 /* FromDS frame with own addr as DA */
254 } else
255 return 0;
256
257 if (skb->len < 24 + 8)
258 return 0;
259
260 /* check for port access entity Ethernet type */
261 pos = skb->data + 24;
262 ethertype = (pos[6] << 8) | pos[7];
263 if (ethertype == ETH_P_PAE)
264 return 1;
265
266 return 0;
267}
268
269/* Called only as a tasklet (software IRQ), by ieee80211_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800270static int
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400271ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
John W. Linville274bfb82008-10-29 11:35:05 -0400272 struct lib80211_crypt_data *crypt)
Jeff Garzikb4538722005-05-12 22:48:20 -0400273{
James Ketrenosee34af32005-09-21 11:54:36 -0500274 struct ieee80211_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400275 int res, hdrlen;
276
277 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
278 return 0;
279
James Ketrenosee34af32005-09-21 11:54:36 -0500280 hdr = (struct ieee80211_hdr_3addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400281 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
282
Jeff Garzikb4538722005-05-12 22:48:20 -0400283 atomic_inc(&crypt->refcnt);
284 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
285 atomic_dec(&crypt->refcnt);
286 if (res < 0) {
Johannes Berge1749612008-10-27 15:59:26 -0700287 IEEE80211_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
288 hdr->addr2, res);
Jeff Garzikb4538722005-05-12 22:48:20 -0400289 if (res == -2)
290 IEEE80211_DEBUG_DROP("Decryption failed ICV "
291 "mismatch (key %d)\n",
292 skb->data[hdrlen + 3] >> 6);
293 ieee->ieee_stats.rx_discards_undecryptable++;
294 return -1;
295 }
296
297 return res;
298}
299
Jeff Garzikb4538722005-05-12 22:48:20 -0400300/* Called only as a tasklet (software IRQ), by ieee80211_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800301static int
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400302ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
303 struct sk_buff *skb, int keyidx,
John W. Linville274bfb82008-10-29 11:35:05 -0400304 struct lib80211_crypt_data *crypt)
Jeff Garzikb4538722005-05-12 22:48:20 -0400305{
James Ketrenosee34af32005-09-21 11:54:36 -0500306 struct ieee80211_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400307 int res, hdrlen;
308
309 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
310 return 0;
311
James Ketrenosee34af32005-09-21 11:54:36 -0500312 hdr = (struct ieee80211_hdr_3addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400313 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"
Johannes Berge1749612008-10-27 15:59:26 -0700320 " (SA=%pM keyidx=%d)\n", ieee->dev->name, hdr->addr2,
David S. Miller21f644f2008-04-08 16:50:44 -0700321 keyidx);
Jeff Garzikb4538722005-05-12 22:48:20 -0400322 return -1;
323 }
324
325 return 0;
326}
327
Jeff Garzikb4538722005-05-12 22:48:20 -0400328/* 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). */
331int 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;
James Ketrenosee34af32005-09-21 11:54:36 -0500335 struct ieee80211_hdr_4addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400336 size_t hdrlen;
337 u16 fc, type, stype, sc;
Jeff Garzikb4538722005-05-12 22:48:20 -0400338 unsigned int frag;
339 u8 *payload;
340 u16 ethertype;
341#ifdef NOT_YET
342 struct net_device *wds = NULL;
343 struct sk_buff *skb2 = NULL;
344 struct net_device *wds = NULL;
345 int frame_authorized = 0;
346 int from_assoc_ap = 0;
347 void *sta = NULL;
348#endif
349 u8 dst[ETH_ALEN];
350 u8 src[ETH_ALEN];
John W. Linville274bfb82008-10-29 11:35:05 -0400351 struct lib80211_crypt_data *crypt = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -0400352 int keyidx = 0;
Zhu Yib6daa252006-01-19 16:20:42 +0800353 int can_be_decrypted = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -0400354
James Ketrenosee34af32005-09-21 11:54:36 -0500355 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400356 if (skb->len < 10) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400357 printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
Jeff Garzikb4538722005-05-12 22:48:20 -0400358 goto rx_dropped;
359 }
360
361 fc = le16_to_cpu(hdr->frame_ctl);
362 type = WLAN_FC_GET_TYPE(fc);
363 stype = WLAN_FC_GET_STYPE(fc);
364 sc = le16_to_cpu(hdr->seq_ctl);
365 frag = WLAN_GET_SEQ_FRAG(sc);
366 hdrlen = ieee80211_get_hdrlen(fc);
367
John W. Linville04045f92007-10-01 21:03:54 -0700368 if (skb->len < hdrlen) {
369 printk(KERN_INFO "%s: invalid SKB length %d\n",
370 dev->name, skb->len);
371 goto rx_dropped;
372 }
373
Jeff Garzikb4538722005-05-12 22:48:20 -0400374 /* Put this code here so that we avoid duplicating it in all
375 * Rx paths. - Jean II */
Horms8f7eb4072006-06-26 17:44:38 +0900376#ifdef CONFIG_WIRELESS_EXT
Jeff Garzikb4538722005-05-12 22:48:20 -0400377#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
378 /* If spy monitoring on */
James Ketrenos74079fd2005-09-13 17:35:21 -0500379 if (ieee->spy_data.spy_number > 0) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400380 struct iw_quality wstats;
James Ketrenos74079fd2005-09-13 17:35:21 -0500381
382 wstats.updated = 0;
383 if (rx_stats->mask & IEEE80211_STATMASK_RSSI) {
Bruno Randolf566bfe52008-05-08 19:15:40 +0200384 wstats.level = rx_stats->signal;
James Ketrenos74079fd2005-09-13 17:35:21 -0500385 wstats.updated |= IW_QUAL_LEVEL_UPDATED;
386 } else
387 wstats.updated |= IW_QUAL_LEVEL_INVALID;
388
389 if (rx_stats->mask & IEEE80211_STATMASK_NOISE) {
390 wstats.noise = rx_stats->noise;
391 wstats.updated |= IW_QUAL_NOISE_UPDATED;
392 } else
393 wstats.updated |= IW_QUAL_NOISE_INVALID;
394
395 if (rx_stats->mask & IEEE80211_STATMASK_SIGNAL) {
396 wstats.qual = rx_stats->signal;
397 wstats.updated |= IW_QUAL_QUAL_UPDATED;
398 } else
399 wstats.updated |= IW_QUAL_QUAL_INVALID;
400
Jeff Garzikb4538722005-05-12 22:48:20 -0400401 /* Update spy records */
James Ketrenos74079fd2005-09-13 17:35:21 -0500402 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
Jeff Garzikb4538722005-05-12 22:48:20 -0400403 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400404#endif /* IW_WIRELESS_SPY */
Horms8f7eb4072006-06-26 17:44:38 +0900405#endif /* CONFIG_WIRELESS_EXT */
James Ketrenos74079fd2005-09-13 17:35:21 -0500406
407#ifdef NOT_YET
Jeff Garzikb4538722005-05-12 22:48:20 -0400408 hostap_update_rx_stats(local->ap, hdr, rx_stats);
409#endif
410
Jeff Garzikb4538722005-05-12 22:48:20 -0400411 if (ieee->iw_mode == IW_MODE_MONITOR) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000412 dev->stats.rx_packets++;
413 dev->stats.rx_bytes += skb->len;
Eric Sesterhenn60d48f12006-06-21 21:05:58 +0200414 ieee80211_monitor_rx(ieee, skb, rx_stats);
Jeff Garzikb4538722005-05-12 22:48:20 -0400415 return 1;
416 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400417
Zhu Yib6daa252006-01-19 16:20:42 +0800418 can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
419 is_broadcast_ether_addr(hdr->addr2)) ?
420 ieee->host_mc_decrypt : ieee->host_decrypt;
421
422 if (can_be_decrypted) {
Zhu Yib6daa252006-01-19 16:20:42 +0800423 if (skb->len >= hdrlen + 3) {
424 /* Top two-bits of byte 3 are the key index */
Daniel Drakec9308b02006-09-27 03:50:31 +0100425 keyidx = skb->data[hdrlen + 3] >> 6;
Zhu Yib6daa252006-01-19 16:20:42 +0800426 }
427
Daniel Drakec9308b02006-09-27 03:50:31 +0100428 /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
429 * is only allowed 2-bits of storage, no value of keyidx can
430 * be provided via above code that would result in keyidx
Zhu Yib6daa252006-01-19 16:20:42 +0800431 * being out of range */
John W. Linville274bfb82008-10-29 11:35:05 -0400432 crypt = ieee->crypt_info.crypt[keyidx];
Zhu Yib6daa252006-01-19 16:20:42 +0800433
Jeff Garzikb4538722005-05-12 22:48:20 -0400434#ifdef NOT_YET
435 sta = NULL;
436
437 /* Use station specific key to override default keys if the
438 * receiver address is a unicast address ("individual RA"). If
439 * bcrx_sta_key parameter is set, station specific key is used
440 * even with broad/multicast targets (this is against IEEE
441 * 802.11, but makes it easier to use different keys with
442 * stations that do not support WEP key mapping). */
443
444 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400445 (void)hostap_handle_sta_crypto(local, hdr, &crypt,
446 &sta);
Jeff Garzikb4538722005-05-12 22:48:20 -0400447#endif
448
449 /* allow NULL decrypt to indicate an station specific override
450 * for default encryption */
451 if (crypt && (crypt->ops == NULL ||
452 crypt->ops->decrypt_mpdu == NULL))
453 crypt = NULL;
454
Jiri Bencf13baae2005-08-25 20:11:46 -0400455 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400456 /* This seems to be triggered by some (multicast?)
457 * frames from other than current BSS, so just drop the
458 * frames silently instead of filling system log with
459 * these reports. */
460 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
Johannes Berge1749612008-10-27 15:59:26 -0700461 " (SA=%pM)\n", hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400462 ieee->ieee_stats.rx_discards_undecryptable++;
463 goto rx_dropped;
464 }
465 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400466#ifdef NOT_YET
467 if (type != WLAN_FC_TYPE_DATA) {
468 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
Jiri Bencf13baae2005-08-25 20:11:46 -0400469 fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400470 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400471 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
Johannes Berge1749612008-10-27 15:59:26 -0700472 "from %pM\n", dev->name, hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400473 /* TODO: could inform hostapd about this so that it
474 * could send auth failure report */
475 goto rx_dropped;
476 }
477
478 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
479 goto rx_dropped;
480 else
481 goto rx_exit;
482 }
483#endif
Larry Finger837925d2006-10-03 18:49:32 -0500484 /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
485 if (sc == ieee->prev_seq_ctl)
486 goto rx_dropped;
487 else
488 ieee->prev_seq_ctl = sc;
Jeff Garzikb4538722005-05-12 22:48:20 -0400489
490 /* Data frame - extract src/dst addresses */
Jiri Benc286d9742005-05-24 15:10:18 +0200491 if (skb->len < IEEE80211_3ADDR_LEN)
Jeff Garzikb4538722005-05-12 22:48:20 -0400492 goto rx_dropped;
493
494 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
495 case IEEE80211_FCTL_FROMDS:
496 memcpy(dst, hdr->addr1, ETH_ALEN);
497 memcpy(src, hdr->addr3, ETH_ALEN);
498 break;
499 case IEEE80211_FCTL_TODS:
500 memcpy(dst, hdr->addr3, ETH_ALEN);
501 memcpy(src, hdr->addr2, ETH_ALEN);
502 break;
503 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
Jiri Benc286d9742005-05-24 15:10:18 +0200504 if (skb->len < IEEE80211_4ADDR_LEN)
Jeff Garzikb4538722005-05-12 22:48:20 -0400505 goto rx_dropped;
506 memcpy(dst, hdr->addr3, ETH_ALEN);
507 memcpy(src, hdr->addr4, ETH_ALEN);
508 break;
509 case 0:
510 memcpy(dst, hdr->addr1, ETH_ALEN);
511 memcpy(src, hdr->addr2, ETH_ALEN);
512 break;
513 }
514
515#ifdef NOT_YET
516 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
517 goto rx_dropped;
518 if (wds) {
519 skb->dev = dev = wds;
520 stats = hostap_get_stats(dev);
521 }
522
523 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400524 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
525 IEEE80211_FCTL_FROMDS && ieee->stadev
Kris Katterjohnd3f4a682006-01-09 16:01:43 -0800526 && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400527 /* Frame from BSSID of the AP for which we are a client */
528 skb->dev = dev = ieee->stadev;
529 stats = hostap_get_stats(dev);
530 from_assoc_ap = 1;
531 }
532#endif
533
Jeff Garzikb4538722005-05-12 22:48:20 -0400534#ifdef NOT_YET
535 if ((ieee->iw_mode == IW_MODE_MASTER ||
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400536 ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400537 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
538 wds != NULL)) {
539 case AP_RX_CONTINUE_NOT_AUTHORIZED:
540 frame_authorized = 0;
541 break;
542 case AP_RX_CONTINUE:
543 frame_authorized = 1;
544 break;
545 case AP_RX_DROP:
546 goto rx_dropped;
547 case AP_RX_EXIT:
548 goto rx_exit;
549 }
550 }
551#endif
552
553 /* Nullfunc frames may have PS-bit set, so they must be passed to
554 * hostap_handle_sta_rx() before being dropped here. */
James Ketrenos9e8571a2005-09-21 11:56:33 -0500555
556 stype &= ~IEEE80211_STYPE_QOS_DATA;
557
Jeff Garzikb4538722005-05-12 22:48:20 -0400558 if (stype != IEEE80211_STYPE_DATA &&
559 stype != IEEE80211_STYPE_DATA_CFACK &&
560 stype != IEEE80211_STYPE_DATA_CFPOLL &&
561 stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
562 if (stype != IEEE80211_STYPE_NULLFUNC)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400563 IEEE80211_DEBUG_DROP("RX: dropped data frame "
564 "with no data (type=0x%02x, "
565 "subtype=0x%02x, len=%d)\n",
566 type, stype, skb->len);
Jeff Garzikb4538722005-05-12 22:48:20 -0400567 goto rx_dropped;
568 }
569
570 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
571
Zhu Yib6daa252006-01-19 16:20:42 +0800572 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
Jeff Garzikb4538722005-05-12 22:48:20 -0400573 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
574 goto rx_dropped;
575
James Ketrenosee34af32005-09-21 11:54:36 -0500576 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400577
578 /* skb: hdr + (possibly fragmented) plaintext payload */
579 // PR: FIXME: hostap has additional conditions in the "if" below:
Jiri Bencf13baae2005-08-25 20:11:46 -0400580 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
Denis Vlasenko9eafe762006-01-22 13:57:10 +0200581 if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400582 int flen;
583 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
584 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
585
586 if (!frag_skb) {
587 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
588 "Rx cannot get skb from fragment "
589 "cache (morefrag=%d seq=%u frag=%u)\n",
590 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
591 WLAN_GET_SEQ_SEQ(sc), frag);
592 goto rx_dropped;
593 }
594
595 flen = skb->len;
596 if (frag != 0)
597 flen -= hdrlen;
598
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700599 if (frag_skb->tail + flen > frag_skb->end) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400600 printk(KERN_WARNING "%s: host decrypted and "
601 "reassembled frame did not fit skb\n",
602 dev->name);
603 ieee80211_frag_cache_invalidate(ieee, hdr);
604 goto rx_dropped;
605 }
606
607 if (frag == 0) {
608 /* copy first fragment (including full headers) into
609 * beginning of the fragment cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300610 skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
Jeff Garzikb4538722005-05-12 22:48:20 -0400611 } else {
612 /* append frame payload to the end of the fragment
613 * cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300614 skb_copy_from_linear_data_offset(skb, hdrlen,
615 skb_put(frag_skb, flen), flen);
Jeff Garzikb4538722005-05-12 22:48:20 -0400616 }
617 dev_kfree_skb_any(skb);
618 skb = NULL;
619
620 if (fc & IEEE80211_FCTL_MOREFRAGS) {
621 /* more fragments expected - leave the skb in fragment
622 * cache for now; it will be delivered to upper layers
623 * after all fragments have been received */
624 goto rx_exit;
625 }
626
627 /* this was the last fragment and the frame will be
628 * delivered, so remove skb from fragment cache */
629 skb = frag_skb;
James Ketrenosee34af32005-09-21 11:54:36 -0500630 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400631 ieee80211_frag_cache_invalidate(ieee, hdr);
632 }
633
634 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
635 * encrypted/authenticated */
Zhu Yib6daa252006-01-19 16:20:42 +0800636 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
Jeff Garzikb4538722005-05-12 22:48:20 -0400637 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
638 goto rx_dropped;
639
James Ketrenosee34af32005-09-21 11:54:36 -0500640 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Jiri Bencf13baae2005-08-25 20:11:46 -0400641 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400642 if ( /*ieee->ieee802_1x && */
643 ieee80211_is_eapol_frame(ieee, skb)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400644 /* pass unencrypted EAPOL frames even if encryption is
645 * configured */
Jeff Garzikb4538722005-05-12 22:48:20 -0400646 } else {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400647 IEEE80211_DEBUG_DROP("encryption configured, but RX "
Johannes Berge1749612008-10-27 15:59:26 -0700648 "frame not encrypted (SA=%pM)\n",
649 hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400650 goto rx_dropped;
651 }
652 }
653
Jiri Bencf13baae2005-08-25 20:11:46 -0400654 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
Jeff Garzikb4538722005-05-12 22:48:20 -0400655 !ieee80211_is_eapol_frame(ieee, skb)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400656 IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
Johannes Berge1749612008-10-27 15:59:26 -0700657 "frame from %pM (drop_unencrypted=1)\n",
658 hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400659 goto rx_dropped;
660 }
661
Daniel Drakec9308b02006-09-27 03:50:31 +0100662 /* If the frame was decrypted in hardware, we may need to strip off
663 * any security data (IV, ICV, etc) that was left behind */
664 if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
665 ieee->host_strip_iv_icv) {
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900666 int trimlen = 0;
Daniel Drakec9308b02006-09-27 03:50:31 +0100667
668 /* Top two-bits of byte 3 are the key index */
669 if (skb->len >= hdrlen + 3)
670 keyidx = skb->data[hdrlen + 3] >> 6;
671
672 /* To strip off any security data which appears before the
673 * payload, we simply increase hdrlen (as the header gets
674 * chopped off immediately below). For the security data which
675 * appears after the payload, we use skb_trim. */
676
677 switch (ieee->sec.encode_alg[keyidx]) {
678 case SEC_ALG_WEP:
679 /* 4 byte IV */
680 hdrlen += 4;
681 /* 4 byte ICV */
682 trimlen = 4;
683 break;
684 case SEC_ALG_TKIP:
685 /* 4 byte IV, 4 byte ExtIV */
686 hdrlen += 8;
687 /* 8 byte MIC, 4 byte ICV */
688 trimlen = 12;
689 break;
690 case SEC_ALG_CCMP:
691 /* 8 byte CCMP header */
692 hdrlen += 8;
693 /* 8 byte MIC */
694 trimlen = 8;
695 break;
696 }
697
698 if (skb->len < trimlen)
699 goto rx_dropped;
700
701 __skb_trim(skb, skb->len - trimlen);
702
703 if (skb->len < hdrlen)
704 goto rx_dropped;
705 }
706
Jeff Garzikb4538722005-05-12 22:48:20 -0400707 /* skb: hdr + (possible reassembled) full plaintext payload */
708
709 payload = skb->data + hdrlen;
710 ethertype = (payload[6] << 8) | payload[7];
711
712#ifdef NOT_YET
713 /* If IEEE 802.1X is used, check whether the port is authorized to send
714 * the received frame. */
715 if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
716 if (ethertype == ETH_P_PAE) {
717 printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
718 dev->name);
719 if (ieee->hostapd && ieee->apdev) {
720 /* Send IEEE 802.1X frames to the user
721 * space daemon for processing */
722 prism2_rx_80211(ieee->apdev, skb, rx_stats,
723 PRISM2_RX_MGMT);
724 ieee->apdevstats.rx_packets++;
725 ieee->apdevstats.rx_bytes += skb->len;
726 goto rx_exit;
727 }
728 } else if (!frame_authorized) {
729 printk(KERN_DEBUG "%s: dropped frame from "
730 "unauthorized port (IEEE 802.1X): "
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400731 "ethertype=0x%04x\n", dev->name, ethertype);
Jeff Garzikb4538722005-05-12 22:48:20 -0400732 goto rx_dropped;
733 }
734 }
735#endif
736
737 /* convert hdr + possible LLC headers into Ethernet header */
738 if (skb->len - hdrlen >= 8 &&
739 ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
740 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
741 memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
742 /* remove RFC1042 or Bridge-Tunnel encapsulation and
743 * replace EtherType */
744 skb_pull(skb, hdrlen + SNAP_SIZE);
745 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
746 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
747 } else {
Al Virod9e94d52007-12-29 05:01:07 -0500748 __be16 len;
Jeff Garzikb4538722005-05-12 22:48:20 -0400749 /* Leave Ethernet header part of hdr and full payload */
750 skb_pull(skb, hdrlen);
751 len = htons(skb->len);
752 memcpy(skb_push(skb, 2), &len, 2);
753 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
754 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
755 }
756
757#ifdef NOT_YET
758 if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400759 IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400760 /* Non-standard frame: get addr4 from its bogus location after
761 * the payload */
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300762 skb_copy_to_linear_data_offset(skb, ETH_ALEN,
763 skb->data + skb->len - ETH_ALEN,
764 ETH_ALEN);
Jeff Garzikb4538722005-05-12 22:48:20 -0400765 skb_trim(skb, skb->len - ETH_ALEN);
766 }
767#endif
768
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000769 dev->stats.rx_packets++;
770 dev->stats.rx_bytes += skb->len;
Jeff Garzikb4538722005-05-12 22:48:20 -0400771
772#ifdef NOT_YET
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400773 if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400774 if (dst[0] & 0x01) {
775 /* copy multicast frame both to the higher layers and
776 * to the wireless media */
777 ieee->ap->bridged_multicast++;
778 skb2 = skb_clone(skb, GFP_ATOMIC);
779 if (skb2 == NULL)
780 printk(KERN_DEBUG "%s: skb_clone failed for "
781 "multicast frame\n", dev->name);
782 } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
783 /* send frame directly to the associated STA using
784 * wireless media and not passing to higher layers */
785 ieee->ap->bridged_unicast++;
786 skb2 = skb;
787 skb = NULL;
788 }
789 }
790
791 if (skb2 != NULL) {
792 /* send to wireless media */
Jeff Garzikb4538722005-05-12 22:48:20 -0400793 skb2->dev = dev;
YOSHIFUJI Hideaki4e394302007-12-12 03:52:26 +0900794 skb2->protocol = htons(ETH_P_802_3);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700795 skb_reset_mac_header(skb2);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700796 skb_reset_network_header(skb2);
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700797 /* skb2->network_header += ETH_HLEN; */
Jeff Garzikb4538722005-05-12 22:48:20 -0400798 dev_queue_xmit(skb2);
799 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400800#endif
801
802 if (skb) {
803 skb->protocol = eth_type_trans(skb, dev);
804 memset(skb->cb, 0, sizeof(skb->cb));
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400805 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
Zhu Yid6529232006-01-19 16:20:49 +0800806 if (netif_rx(skb) == NET_RX_DROP) {
807 /* netif_rx always succeeds, but it might drop
808 * the packet. If it drops the packet, we log that
809 * in our stats. */
810 IEEE80211_DEBUG_DROP
811 ("RX: netif_rx dropped the packet\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000812 dev->stats.rx_dropped++;
Zhu Yid6529232006-01-19 16:20:49 +0800813 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400814 }
815
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400816 rx_exit:
Jeff Garzikb4538722005-05-12 22:48:20 -0400817#ifdef NOT_YET
818 if (sta)
819 hostap_handle_sta_release(sta);
820#endif
821 return 1;
822
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400823 rx_dropped:
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000824 dev->stats.rx_dropped++;
Jeff Garzikb4538722005-05-12 22:48:20 -0400825
826 /* Returning 0 indicates to caller that we have not handled the SKB--
827 * so it is still allocated and can be used again by underlying
828 * hardware as a DMA target */
829 return 0;
830}
831
Daniel Drakef2060f032006-07-18 21:38:05 +0100832/* Filter out unrelated packets, call ieee80211_rx[_mgt]
833 * This function takes over the skb, it should not be used again after calling
834 * this function. */
835void ieee80211_rx_any(struct ieee80211_device *ieee,
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200836 struct sk_buff *skb, struct ieee80211_rx_stats *stats)
837{
838 struct ieee80211_hdr_4addr *hdr;
839 int is_packet_for_us;
840 u16 fc;
841
Daniel Drakef2060f032006-07-18 21:38:05 +0100842 if (ieee->iw_mode == IW_MODE_MONITOR) {
843 if (!ieee80211_rx(ieee, skb, stats))
844 dev_kfree_skb_irq(skb);
845 return;
846 }
847
848 if (skb->len < sizeof(struct ieee80211_hdr))
849 goto drop_free;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200850
851 hdr = (struct ieee80211_hdr_4addr *)skb->data;
852 fc = le16_to_cpu(hdr->frame_ctl);
853
854 if ((fc & IEEE80211_FCTL_VERS) != 0)
Daniel Drakef2060f032006-07-18 21:38:05 +0100855 goto drop_free;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900856
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200857 switch (fc & IEEE80211_FCTL_FTYPE) {
858 case IEEE80211_FTYPE_MGMT:
Daniel Drakef2060f032006-07-18 21:38:05 +0100859 if (skb->len < sizeof(struct ieee80211_hdr_3addr))
860 goto drop_free;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200861 ieee80211_rx_mgt(ieee, hdr, stats);
Daniel Drakef2060f032006-07-18 21:38:05 +0100862 dev_kfree_skb_irq(skb);
863 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200864 case IEEE80211_FTYPE_DATA:
865 break;
866 case IEEE80211_FTYPE_CTL:
Daniel Drakef2060f032006-07-18 21:38:05 +0100867 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200868 default:
Daniel Drakef2060f032006-07-18 21:38:05 +0100869 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200870 }
871
872 is_packet_for_us = 0;
873 switch (ieee->iw_mode) {
874 case IW_MODE_ADHOC:
875 /* our BSS and not from/to DS */
876 if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0)
877 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
878 /* promisc: get all */
879 if (ieee->dev->flags & IFF_PROMISC)
880 is_packet_for_us = 1;
881 /* to us */
882 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
883 is_packet_for_us = 1;
884 /* mcast */
885 else if (is_multicast_ether_addr(hdr->addr1))
886 is_packet_for_us = 1;
887 }
888 break;
889 case IW_MODE_INFRA:
890 /* our BSS (== from our AP) and from DS */
891 if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0)
892 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
893 /* promisc: get all */
894 if (ieee->dev->flags & IFF_PROMISC)
895 is_packet_for_us = 1;
896 /* to us */
897 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
898 is_packet_for_us = 1;
899 /* mcast */
900 else if (is_multicast_ether_addr(hdr->addr1)) {
901 /* not our own packet bcasted from AP */
902 if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN))
903 is_packet_for_us = 1;
904 }
905 }
906 break;
907 default:
908 /* ? */
909 break;
910 }
911
912 if (is_packet_for_us)
Daniel Drakef2060f032006-07-18 21:38:05 +0100913 if (!ieee80211_rx(ieee, skb, stats))
914 dev_kfree_skb_irq(skb);
915 return;
916
917drop_free:
918 dev_kfree_skb_irq(skb);
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000919 ieee->dev->stats.rx_dropped++;
Daniel Drakef2060f032006-07-18 21:38:05 +0100920 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200921}
922
Jeff Garzikb4538722005-05-12 22:48:20 -0400923#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
924
James Ketrenos9e8571a2005-09-21 11:56:33 -0500925static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
926
927/*
928* Make ther structure we read from the beacon packet has
929* the right values
930*/
931static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
932 *info_element, int sub_type)
933{
934
935 if (info_element->qui_subtype != sub_type)
936 return -1;
937 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
938 return -1;
939 if (info_element->qui_type != QOS_OUI_TYPE)
940 return -1;
941 if (info_element->version != QOS_VERSION_1)
942 return -1;
943
944 return 0;
945}
946
947/*
948 * Parse a QoS parameter element
949 */
950static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
951 *element_param, struct ieee80211_info_element
952 *info_element)
953{
954 int ret = 0;
955 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
956
957 if ((info_element == NULL) || (element_param == NULL))
958 return -1;
959
960 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
961 memcpy(element_param->info_element.qui, info_element->data,
962 info_element->len);
963 element_param->info_element.elementID = info_element->id;
964 element_param->info_element.length = info_element->len;
965 } else
966 ret = -1;
967 if (ret == 0)
968 ret = ieee80211_verify_qos_info(&element_param->info_element,
969 QOS_OUI_PARAM_SUB_TYPE);
970 return ret;
971}
972
973/*
974 * Parse a QoS information element
975 */
976static int ieee80211_read_qos_info_element(struct
977 ieee80211_qos_information_element
978 *element_info, struct ieee80211_info_element
979 *info_element)
980{
981 int ret = 0;
982 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
983
984 if (element_info == NULL)
985 return -1;
986 if (info_element == NULL)
987 return -1;
988
989 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
990 memcpy(element_info->qui, info_element->data,
991 info_element->len);
992 element_info->elementID = info_element->id;
993 element_info->length = info_element->len;
994 } else
995 ret = -1;
996
997 if (ret == 0)
998 ret = ieee80211_verify_qos_info(element_info,
999 QOS_OUI_INFO_SUB_TYPE);
1000 return ret;
1001}
1002
1003/*
1004 * Write QoS parameters from the ac parameters.
1005 */
1006static int ieee80211_qos_convert_ac_to_parameters(struct
1007 ieee80211_qos_parameter_info
1008 *param_elm, struct
1009 ieee80211_qos_parameters
1010 *qos_param)
1011{
1012 int rc = 0;
1013 int i;
1014 struct ieee80211_qos_ac_parameter *ac_params;
1015 u32 txop;
1016 u8 cw_min;
1017 u8 cw_max;
1018
1019 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1020 ac_params = &(param_elm->ac_params_record[i]);
1021
1022 qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
1023 qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
1024
1025 cw_min = ac_params->ecw_min_max & 0x0F;
Al Viro8fffc152007-12-27 01:25:40 -05001026 qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001027
1028 cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
Al Viro8fffc152007-12-27 01:25:40 -05001029 qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001030
1031 qos_param->flag[i] =
1032 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1033
1034 txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
Al Viro8fffc152007-12-27 01:25:40 -05001035 qos_param->tx_op_limit[i] = cpu_to_le16(txop);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001036 }
1037 return rc;
1038}
1039
1040/*
1041 * we have a generic data element which it may contain QoS information or
1042 * parameters element. check the information element length to decide
1043 * which type to read
1044 */
1045static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1046 *info_element,
1047 struct ieee80211_network *network)
1048{
1049 int rc = 0;
1050 struct ieee80211_qos_parameters *qos_param = NULL;
1051 struct ieee80211_qos_information_element qos_info_element;
1052
1053 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1054
1055 if (rc == 0) {
1056 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1057 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1058 } else {
1059 struct ieee80211_qos_parameter_info param_element;
1060
1061 rc = ieee80211_read_qos_param_element(&param_element,
1062 info_element);
1063 if (rc == 0) {
1064 qos_param = &(network->qos_data.parameters);
1065 ieee80211_qos_convert_ac_to_parameters(&param_element,
1066 qos_param);
1067 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1068 network->qos_data.param_count =
1069 param_element.info_element.ac_info & 0x0F;
1070 }
1071 }
1072
1073 if (rc == 0) {
1074 IEEE80211_DEBUG_QOS("QoS is supported\n");
1075 network->qos_data.supported = 1;
1076 }
1077 return rc;
1078}
1079
Helmut Schaa37561622009-03-06 12:02:25 +01001080#ifdef CONFIG_LIBIPW_DEBUG
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001081#define MFIE_STRING(x) case WLAN_EID_ ##x: return #x
Zhu Yid1b46b02006-01-19 16:22:15 +08001082
1083static const char *get_info_element_string(u16 id)
1084{
1085 switch (id) {
1086 MFIE_STRING(SSID);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001087 MFIE_STRING(SUPP_RATES);
1088 MFIE_STRING(FH_PARAMS);
1089 MFIE_STRING(DS_PARAMS);
1090 MFIE_STRING(CF_PARAMS);
Zhu Yid1b46b02006-01-19 16:22:15 +08001091 MFIE_STRING(TIM);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001092 MFIE_STRING(IBSS_PARAMS);
Zhu Yid1b46b02006-01-19 16:22:15 +08001093 MFIE_STRING(COUNTRY);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001094 MFIE_STRING(HP_PARAMS);
1095 MFIE_STRING(HP_TABLE);
Zhu Yid1b46b02006-01-19 16:22:15 +08001096 MFIE_STRING(REQUEST);
1097 MFIE_STRING(CHALLENGE);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001098 MFIE_STRING(PWR_CONSTRAINT);
1099 MFIE_STRING(PWR_CAPABILITY);
Zhu Yid1b46b02006-01-19 16:22:15 +08001100 MFIE_STRING(TPC_REQUEST);
1101 MFIE_STRING(TPC_REPORT);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001102 MFIE_STRING(SUPPORTED_CHANNELS);
1103 MFIE_STRING(CHANNEL_SWITCH);
Zhu Yid1b46b02006-01-19 16:22:15 +08001104 MFIE_STRING(MEASURE_REQUEST);
1105 MFIE_STRING(MEASURE_REPORT);
1106 MFIE_STRING(QUIET);
1107 MFIE_STRING(IBSS_DFS);
1108 MFIE_STRING(ERP_INFO);
1109 MFIE_STRING(RSN);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001110 MFIE_STRING(EXT_SUPP_RATES);
Zhu Yid1b46b02006-01-19 16:22:15 +08001111 MFIE_STRING(GENERIC);
1112 MFIE_STRING(QOS_PARAMETER);
1113 default:
1114 return "UNKNOWN";
1115 }
1116}
1117#endif
1118
James Ketrenosff0037b2005-10-03 10:23:42 -05001119static int ieee80211_parse_info_param(struct ieee80211_info_element
1120 *info_element, u16 length,
1121 struct ieee80211_network *network)
James Ketrenos9e8571a2005-09-21 11:56:33 -05001122{
John W. Linville9387b7c2008-09-30 20:59:05 -04001123 DECLARE_SSID_BUF(ssid);
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001124 u8 i;
Helmut Schaa37561622009-03-06 12:02:25 +01001125#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001126 char rates_str[64];
1127 char *p;
1128#endif
James Ketrenos9e8571a2005-09-21 11:56:33 -05001129
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001130 while (length >= sizeof(*info_element)) {
1131 if (sizeof(*info_element) + info_element->len > length) {
Jiri Bencaec41a02006-10-18 19:34:40 +02001132 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1133 "info_element->len + 2 > left : "
1134 "info_element->len+2=%zd left=%d, id=%d.\n",
1135 info_element->len +
1136 sizeof(*info_element),
1137 length, info_element->id);
Zhu Yif09fc442006-08-21 11:34:19 +08001138 /* We stop processing but don't return an error here
1139 * because some misbehaviour APs break this rule. ie.
1140 * Orinoco AP1000. */
1141 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001142 }
1143
1144 switch (info_element->id) {
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001145 case WLAN_EID_SSID:
James Ketrenos9e8571a2005-09-21 11:56:33 -05001146 network->ssid_len = min(info_element->len,
1147 (u8) IW_ESSID_MAX_SIZE);
1148 memcpy(network->ssid, info_element->data,
1149 network->ssid_len);
1150 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1151 memset(network->ssid + network->ssid_len, 0,
1152 IW_ESSID_MAX_SIZE - network->ssid_len);
1153
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001154 IEEE80211_DEBUG_MGMT("WLAN_EID_SSID: '%s' len=%d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001155 print_ssid(ssid, network->ssid,
1156 network->ssid_len),
John W. Linvillec5d3dce2008-09-30 17:17:26 -04001157 network->ssid_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001158 break;
1159
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001160 case WLAN_EID_SUPP_RATES:
Helmut Schaa37561622009-03-06 12:02:25 +01001161#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001162 p = rates_str;
1163#endif
1164 network->rates_len = min(info_element->len,
1165 MAX_RATES_LENGTH);
1166 for (i = 0; i < network->rates_len; i++) {
1167 network->rates[i] = info_element->data[i];
Helmut Schaa37561622009-03-06 12:02:25 +01001168#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001169 p += snprintf(p, sizeof(rates_str) -
1170 (p - rates_str), "%02X ",
1171 network->rates[i]);
1172#endif
1173 if (ieee80211_is_ofdm_rate
1174 (info_element->data[i])) {
1175 network->flags |= NETWORK_HAS_OFDM;
1176 if (info_element->data[i] &
1177 IEEE80211_BASIC_RATE_MASK)
1178 network->flags &=
1179 ~NETWORK_HAS_CCK;
1180 }
1181 }
1182
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001183 IEEE80211_DEBUG_MGMT("WLAN_EID_SUPP_RATES: '%s' (%d)\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001184 rates_str, network->rates_len);
1185 break;
1186
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001187 case WLAN_EID_EXT_SUPP_RATES:
Helmut Schaa37561622009-03-06 12:02:25 +01001188#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001189 p = rates_str;
1190#endif
1191 network->rates_ex_len = min(info_element->len,
1192 MAX_RATES_EX_LENGTH);
1193 for (i = 0; i < network->rates_ex_len; i++) {
1194 network->rates_ex[i] = info_element->data[i];
Helmut Schaa37561622009-03-06 12:02:25 +01001195#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001196 p += snprintf(p, sizeof(rates_str) -
1197 (p - rates_str), "%02X ",
1198 network->rates[i]);
1199#endif
1200 if (ieee80211_is_ofdm_rate
1201 (info_element->data[i])) {
1202 network->flags |= NETWORK_HAS_OFDM;
1203 if (info_element->data[i] &
1204 IEEE80211_BASIC_RATE_MASK)
1205 network->flags &=
1206 ~NETWORK_HAS_CCK;
1207 }
1208 }
1209
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001210 IEEE80211_DEBUG_MGMT("WLAN_EID_EXT_SUPP_RATES: '%s' (%d)\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001211 rates_str, network->rates_ex_len);
1212 break;
1213
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001214 case WLAN_EID_DS_PARAMS:
1215 IEEE80211_DEBUG_MGMT("WLAN_EID_DS_PARAMS: %d\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001216 info_element->data[0]);
1217 network->channel = info_element->data[0];
1218 break;
1219
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001220 case WLAN_EID_FH_PARAMS:
1221 IEEE80211_DEBUG_MGMT("WLAN_EID_FH_PARAMS: ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001222 break;
1223
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001224 case WLAN_EID_CF_PARAMS:
1225 IEEE80211_DEBUG_MGMT("WLAN_EID_CF_PARAMS: ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001226 break;
1227
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001228 case WLAN_EID_TIM:
Zhu Yi41a25c62006-01-19 16:22:23 +08001229 network->tim.tim_count = info_element->data[0];
1230 network->tim.tim_period = info_element->data[1];
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001231 IEEE80211_DEBUG_MGMT("WLAN_EID_TIM: partially ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001232 break;
1233
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001234 case WLAN_EID_ERP_INFO:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001235 network->erp_value = info_element->data[0];
Daniel Draked8e2be92006-07-18 21:30:34 +01001236 network->flags |= NETWORK_HAS_ERP_VALUE;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001237 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1238 network->erp_value);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001239 break;
1240
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001241 case WLAN_EID_IBSS_PARAMS:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001242 network->atim_window = info_element->data[0];
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001243 IEEE80211_DEBUG_MGMT("WLAN_EID_IBSS_PARAMS: %d\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001244 network->atim_window);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001245 break;
1246
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001247 case WLAN_EID_CHALLENGE:
1248 IEEE80211_DEBUG_MGMT("WLAN_EID_CHALLENGE: ignored\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001249 break;
1250
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001251 case WLAN_EID_GENERIC:
1252 IEEE80211_DEBUG_MGMT("WLAN_EID_GENERIC: %d bytes\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001253 info_element->len);
1254 if (!ieee80211_parse_qos_info_param_IE(info_element,
1255 network))
1256 break;
1257
1258 if (info_element->len >= 4 &&
1259 info_element->data[0] == 0x00 &&
1260 info_element->data[1] == 0x50 &&
1261 info_element->data[2] == 0xf2 &&
1262 info_element->data[3] == 0x01) {
1263 network->wpa_ie_len = min(info_element->len + 2,
1264 MAX_WPA_IE_LEN);
1265 memcpy(network->wpa_ie, info_element,
1266 network->wpa_ie_len);
1267 }
James Ketrenos9e8571a2005-09-21 11:56:33 -05001268 break;
1269
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001270 case WLAN_EID_RSN:
1271 IEEE80211_DEBUG_MGMT("WLAN_EID_RSN: %d bytes\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001272 info_element->len);
1273 network->rsn_ie_len = min(info_element->len + 2,
1274 MAX_WPA_IE_LEN);
1275 memcpy(network->rsn_ie, info_element,
1276 network->rsn_ie_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001277 break;
1278
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001279 case WLAN_EID_QOS_PARAMETER:
James Ketrenosff0037b2005-10-03 10:23:42 -05001280 printk(KERN_ERR
1281 "QoS Error need to parse QOS_PARAMETER IE\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001282 break;
Zhu Yid1b46b02006-01-19 16:22:15 +08001283 /* 802.11h */
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001284 case WLAN_EID_PWR_CONSTRAINT:
Zhu Yid1b46b02006-01-19 16:22:15 +08001285 network->power_constraint = info_element->data[0];
1286 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
1287 break;
1288
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001289 case WLAN_EID_CHANNEL_SWITCH:
Zhu Yid1b46b02006-01-19 16:22:15 +08001290 network->power_constraint = info_element->data[0];
1291 network->flags |= NETWORK_HAS_CSA;
1292 break;
1293
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001294 case WLAN_EID_QUIET:
Zhu Yid1b46b02006-01-19 16:22:15 +08001295 network->quiet.count = info_element->data[0];
1296 network->quiet.period = info_element->data[1];
1297 network->quiet.duration = info_element->data[2];
1298 network->quiet.offset = info_element->data[3];
1299 network->flags |= NETWORK_HAS_QUIET;
1300 break;
1301
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001302 case WLAN_EID_IBSS_DFS:
Zhu Yid1b46b02006-01-19 16:22:15 +08001303 if (network->ibss_dfs)
1304 break;
Arnaldo Carvalho de Melo571d6ee2006-11-21 01:26:49 -02001305 network->ibss_dfs = kmemdup(info_element->data,
1306 info_element->len,
1307 GFP_ATOMIC);
Zhu Yid1b46b02006-01-19 16:22:15 +08001308 if (!network->ibss_dfs)
1309 return 1;
Zhu Yid1b46b02006-01-19 16:22:15 +08001310 network->flags |= NETWORK_HAS_IBSS_DFS;
1311 break;
1312
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001313 case WLAN_EID_TPC_REPORT:
Zhu Yid1b46b02006-01-19 16:22:15 +08001314 network->tpc_report.transmit_power =
1315 info_element->data[0];
1316 network->tpc_report.link_margin = info_element->data[1];
1317 network->flags |= NETWORK_HAS_TPC_REPORT;
1318 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001319
1320 default:
Zhu Yid1b46b02006-01-19 16:22:15 +08001321 IEEE80211_DEBUG_MGMT
1322 ("Unsupported info element: %s (%d)\n",
1323 get_info_element_string(info_element->id),
1324 info_element->id);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001325 break;
1326 }
1327
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001328 length -= sizeof(*info_element) + info_element->len;
James Ketrenosff0037b2005-10-03 10:23:42 -05001329 info_element =
1330 (struct ieee80211_info_element *)&info_element->
1331 data[info_element->len];
James Ketrenos9e8571a2005-09-21 11:56:33 -05001332 }
1333
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001334 return 0;
1335}
1336
1337static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
1338 *frame, struct ieee80211_rx_stats *stats)
1339{
Zhu Yid1b46b02006-01-19 16:22:15 +08001340 struct ieee80211_network network_resp = {
1341 .ibss_dfs = NULL,
1342 };
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001343 struct ieee80211_network *network = &network_resp;
1344 struct net_device *dev = ieee->dev;
1345
1346 network->flags = 0;
1347 network->qos_data.active = 0;
1348 network->qos_data.supported = 0;
1349 network->qos_data.param_count = 0;
1350 network->qos_data.old_param_count = 0;
1351
1352 //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1353 network->atim_window = le16_to_cpu(frame->aid);
1354 network->listen_interval = le16_to_cpu(frame->status);
Ivo van Doornc1bda442005-10-03 10:20:47 -05001355 memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
1356 network->capability = le16_to_cpu(frame->capability);
1357 network->last_scanned = jiffies;
1358 network->rates_len = network->rates_ex_len = 0;
1359 network->last_associate = 0;
1360 network->ssid_len = 0;
James Ketrenosff0037b2005-10-03 10:23:42 -05001361 network->erp_value =
1362 (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001363
1364 if (stats->freq == IEEE80211_52GHZ_BAND) {
1365 /* for A band (No DS info) */
1366 network->channel = stats->received_channel;
1367 } else
1368 network->flags |= NETWORK_HAS_CCK;
1369
1370 network->wpa_ie_len = 0;
1371 network->rsn_ie_len = 0;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001372
James Ketrenosff0037b2005-10-03 10:23:42 -05001373 if (ieee80211_parse_info_param
1374 (frame->info_element, stats->len - sizeof(*frame), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001375 return 1;
1376
Ivo van Doornc1bda442005-10-03 10:20:47 -05001377 network->mode = 0;
1378 if (stats->freq == IEEE80211_52GHZ_BAND)
1379 network->mode = IEEE_A;
1380 else {
1381 if (network->flags & NETWORK_HAS_OFDM)
1382 network->mode |= IEEE_G;
1383 if (network->flags & NETWORK_HAS_CCK)
1384 network->mode |= IEEE_B;
1385 }
1386
Ivo van Doornc1bda442005-10-03 10:20:47 -05001387 memcpy(&network->stats, stats, sizeof(network->stats));
1388
James Ketrenos9e8571a2005-09-21 11:56:33 -05001389 if (ieee->handle_assoc_response != NULL)
1390 ieee->handle_assoc_response(dev, frame, network);
1391
1392 return 0;
1393}
1394
1395/***************************************************/
1396
Arjan van de Ven858119e2006-01-14 13:20:43 -08001397static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001398 *beacon,
1399 struct ieee80211_network *network,
1400 struct ieee80211_rx_stats *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001401{
John W. Linville9387b7c2008-09-30 20:59:05 -04001402 DECLARE_SSID_BUF(ssid);
1403
James Ketrenos9e8571a2005-09-21 11:56:33 -05001404 network->qos_data.active = 0;
1405 network->qos_data.supported = 0;
1406 network->qos_data.param_count = 0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001407 network->qos_data.old_param_count = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001408
1409 /* Pull out fixed field data */
1410 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
James Ketrenosfd278172005-09-13 17:25:51 -05001411 network->capability = le16_to_cpu(beacon->capability);
Jeff Garzikb4538722005-05-12 22:48:20 -04001412 network->last_scanned = jiffies;
James Ketrenosfd278172005-09-13 17:25:51 -05001413 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
1414 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
1415 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001416 /* Where to pull this? beacon->listen_interval; */
Jeff Garzikb4538722005-05-12 22:48:20 -04001417 network->listen_interval = 0x0A;
1418 network->rates_len = network->rates_ex_len = 0;
1419 network->last_associate = 0;
1420 network->ssid_len = 0;
1421 network->flags = 0;
1422 network->atim_window = 0;
James Ketrenos42c94e42005-09-21 11:58:29 -05001423 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
James Ketrenosccd0fda2005-09-21 11:58:32 -05001424 0x3 : 0x0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001425
1426 if (stats->freq == IEEE80211_52GHZ_BAND) {
1427 /* for A band (No DS info) */
1428 network->channel = stats->received_channel;
1429 } else
1430 network->flags |= NETWORK_HAS_CCK;
1431
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001432 network->wpa_ie_len = 0;
1433 network->rsn_ie_len = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001434
James Ketrenosff0037b2005-10-03 10:23:42 -05001435 if (ieee80211_parse_info_param
1436 (beacon->info_element, stats->len - sizeof(*beacon), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001437 return 1;
Jeff Garzikb4538722005-05-12 22:48:20 -04001438
1439 network->mode = 0;
1440 if (stats->freq == IEEE80211_52GHZ_BAND)
1441 network->mode = IEEE_A;
1442 else {
1443 if (network->flags & NETWORK_HAS_OFDM)
1444 network->mode |= IEEE_G;
1445 if (network->flags & NETWORK_HAS_CCK)
1446 network->mode |= IEEE_B;
1447 }
1448
1449 if (network->mode == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07001450 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
Jeff Garzikb4538722005-05-12 22:48:20 -04001451 "network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001452 print_ssid(ssid, network->ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001453 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001454 network->bssid);
Jeff Garzikb4538722005-05-12 22:48:20 -04001455 return 1;
1456 }
1457
Jeff Garzikb4538722005-05-12 22:48:20 -04001458 memcpy(&network->stats, stats, sizeof(network->stats));
1459
1460 return 0;
1461}
1462
1463static inline int is_same_network(struct ieee80211_network *src,
1464 struct ieee80211_network *dst)
1465{
1466 /* A network is only a duplicate if the channel, BSSID, and ESSID
1467 * all match. We treat all <hidden> with the same BSSID and channel
1468 * as one network */
1469 return ((src->ssid_len == dst->ssid_len) &&
1470 (src->channel == dst->channel) &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -08001471 !compare_ether_addr(src->bssid, dst->bssid) &&
Jeff Garzikb4538722005-05-12 22:48:20 -04001472 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1473}
1474
Arjan van de Ven858119e2006-01-14 13:20:43 -08001475static void update_network(struct ieee80211_network *dst,
Jeff Garzikb4538722005-05-12 22:48:20 -04001476 struct ieee80211_network *src)
1477{
James Ketrenos9e8571a2005-09-21 11:56:33 -05001478 int qos_active;
1479 u8 old_param;
1480
Zhu Yid1b46b02006-01-19 16:22:15 +08001481 ieee80211_network_reset(dst);
1482 dst->ibss_dfs = src->ibss_dfs;
1483
James Ketrenosf44349f2006-03-08 13:14:45 -06001484 /* We only update the statistics if they were created by receiving
1485 * the network information on the actual channel the network is on.
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +09001486 *
James Ketrenosf44349f2006-03-08 13:14:45 -06001487 * This keeps beacons received on neighbor channels from bringing
1488 * down the signal level of an AP. */
1489 if (dst->channel == src->stats.received_channel)
1490 memcpy(&dst->stats, &src->stats,
1491 sizeof(struct ieee80211_rx_stats));
1492 else
Johannes Berge1749612008-10-27 15:59:26 -07001493 IEEE80211_DEBUG_SCAN("Network %pM info received "
1494 "off channel (%d vs. %d)\n", src->bssid,
James Ketrenosf44349f2006-03-08 13:14:45 -06001495 dst->channel, src->stats.received_channel);
1496
Jeff Garzikb4538722005-05-12 22:48:20 -04001497 dst->capability = src->capability;
1498 memcpy(dst->rates, src->rates, src->rates_len);
1499 dst->rates_len = src->rates_len;
1500 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1501 dst->rates_ex_len = src->rates_ex_len;
1502
1503 dst->mode = src->mode;
1504 dst->flags = src->flags;
1505 dst->time_stamp[0] = src->time_stamp[0];
1506 dst->time_stamp[1] = src->time_stamp[1];
1507
1508 dst->beacon_interval = src->beacon_interval;
1509 dst->listen_interval = src->listen_interval;
1510 dst->atim_window = src->atim_window;
James Ketrenos42c94e42005-09-21 11:58:29 -05001511 dst->erp_value = src->erp_value;
Zhu Yi41a25c62006-01-19 16:22:23 +08001512 dst->tim = src->tim;
Jeff Garzikb4538722005-05-12 22:48:20 -04001513
1514 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1515 dst->wpa_ie_len = src->wpa_ie_len;
1516 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1517 dst->rsn_ie_len = src->rsn_ie_len;
1518
1519 dst->last_scanned = jiffies;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001520 qos_active = src->qos_data.active;
1521 old_param = dst->qos_data.old_param_count;
1522 if (dst->flags & NETWORK_HAS_QOS_MASK)
1523 memcpy(&dst->qos_data, &src->qos_data,
1524 sizeof(struct ieee80211_qos_data));
1525 else {
1526 dst->qos_data.supported = src->qos_data.supported;
1527 dst->qos_data.param_count = src->qos_data.param_count;
1528 }
1529
1530 if (dst->qos_data.supported == 1) {
1531 if (dst->ssid_len)
1532 IEEE80211_DEBUG_QOS
1533 ("QoS the network %s is QoS supported\n",
1534 dst->ssid);
1535 else
1536 IEEE80211_DEBUG_QOS
1537 ("QoS the network is QoS supported\n");
1538 }
1539 dst->qos_data.active = qos_active;
1540 dst->qos_data.old_param_count = old_param;
1541
Jeff Garzikb4538722005-05-12 22:48:20 -04001542 /* dst->last_associate is not overwritten */
1543}
1544
Pete Zaitcev48328432006-02-26 23:43:20 -08001545static inline int is_beacon(__le16 fc)
James Ketrenos3f552bb2005-09-21 11:54:47 -05001546{
1547 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
1548}
1549
Arjan van de Ven858119e2006-01-14 13:20:43 -08001550static void ieee80211_process_probe_response(struct ieee80211_device
James Ketrenos74079fd2005-09-13 17:35:21 -05001551 *ieee, struct
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001552 ieee80211_probe_response
James Ketrenos74079fd2005-09-13 17:35:21 -05001553 *beacon, struct ieee80211_rx_stats
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001554 *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001555{
James Ketrenos3f552bb2005-09-21 11:54:47 -05001556 struct net_device *dev = ieee->dev;
Zhu Yid1b46b02006-01-19 16:22:15 +08001557 struct ieee80211_network network = {
1558 .ibss_dfs = NULL,
1559 };
Jeff Garzikb4538722005-05-12 22:48:20 -04001560 struct ieee80211_network *target;
1561 struct ieee80211_network *oldest = NULL;
Helmut Schaa37561622009-03-06 12:02:25 +01001562#ifdef CONFIG_LIBIPW_DEBUG
James Ketrenos68e4e032005-09-13 17:37:22 -05001563 struct ieee80211_info_element *info_element = beacon->info_element;
Jeff Garzikb4538722005-05-12 22:48:20 -04001564#endif
1565 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04001566 DECLARE_SSID_BUF(ssid);
Jeff Garzikb4538722005-05-12 22:48:20 -04001567
Johannes Berge1749612008-10-27 15:59:26 -07001568 IEEE80211_DEBUG_SCAN("'%s' (%pM"
Al Viro8524f592007-12-29 05:03:35 -05001569 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001570 print_ssid(ssid, info_element->data, info_element->len),
Johannes Berge1749612008-10-27 15:59:26 -07001571 beacon->header.addr3,
Al Viro8524f592007-12-29 05:03:35 -05001572 (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
1573 (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
1574 (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
1575 (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
1576 (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
1577 (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
1578 (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
1579 (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
1580 (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
1581 (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
1582 (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
1583 (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
1584 (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
1585 (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
1586 (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
1587 (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
Jeff Garzikb4538722005-05-12 22:48:20 -04001588
1589 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
Johannes Berge1749612008-10-27 15:59:26 -07001590 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001591 print_ssid(ssid, info_element->data,
John W. Linville7e272fc2008-09-24 18:13:14 -04001592 info_element->len),
Johannes Berge1749612008-10-27 15:59:26 -07001593 beacon->header.addr3,
Pete Zaitcev48328432006-02-26 23:43:20 -08001594 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bb2005-09-21 11:54:47 -05001595 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001596 return;
1597 }
1598
1599 /* The network parsed correctly -- so now we scan our known networks
1600 * to see if we can find it in our list.
1601 *
1602 * NOTE: This search is definitely not optimized. Once its doing
1603 * the "right thing" we'll optimize it for efficiency if
1604 * necessary */
1605
1606 /* Search for this entry in the list and update it if it is
1607 * already there. */
1608
1609 spin_lock_irqsave(&ieee->lock, flags);
1610
1611 list_for_each_entry(target, &ieee->network_list, list) {
1612 if (is_same_network(target, &network))
1613 break;
1614
1615 if ((oldest == NULL) ||
Dan Williamsc3d72b92009-02-11 13:26:06 -05001616 time_before(target->last_scanned, oldest->last_scanned))
Jeff Garzikb4538722005-05-12 22:48:20 -04001617 oldest = target;
1618 }
1619
1620 /* If we didn't find a match, then get a new network slot to initialize
1621 * with this beacon's information */
1622 if (&target->list == &ieee->network_list) {
1623 if (list_empty(&ieee->network_free_list)) {
1624 /* If there are no more slots, expire the oldest */
1625 list_del(&oldest->list);
1626 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07001627 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
Jeff Garzikb4538722005-05-12 22:48:20 -04001628 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001629 print_ssid(ssid, target->ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001630 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001631 target->bssid);
Zhu Yid1b46b02006-01-19 16:22:15 +08001632 ieee80211_network_reset(target);
Jeff Garzikb4538722005-05-12 22:48:20 -04001633 } else {
1634 /* Otherwise just pull from the free list */
1635 target = list_entry(ieee->network_free_list.next,
1636 struct ieee80211_network, list);
1637 list_del(ieee->network_free_list.next);
1638 }
1639
Helmut Schaa37561622009-03-06 12:02:25 +01001640#ifdef CONFIG_LIBIPW_DEBUG
Johannes Berge1749612008-10-27 15:59:26 -07001641 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001642 print_ssid(ssid, network.ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001643 network.ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001644 network.bssid,
Pete Zaitcev48328432006-02-26 23:43:20 -08001645 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bb2005-09-21 11:54:47 -05001646 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001647#endif
1648 memcpy(target, &network, sizeof(*target));
Zhu Yid1b46b02006-01-19 16:22:15 +08001649 network.ibss_dfs = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -04001650 list_add_tail(&target->list, &ieee->network_list);
1651 } else {
Johannes Berge1749612008-10-27 15:59:26 -07001652 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001653 print_ssid(ssid, target->ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001654 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001655 target->bssid,
Pete Zaitcev48328432006-02-26 23:43:20 -08001656 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bb2005-09-21 11:54:47 -05001657 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001658 update_network(target, &network);
Zhu Yid1b46b02006-01-19 16:22:15 +08001659 network.ibss_dfs = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -04001660 }
1661
1662 spin_unlock_irqrestore(&ieee->lock, flags);
James Ketrenos3f552bb2005-09-21 11:54:47 -05001663
Pete Zaitcev48328432006-02-26 23:43:20 -08001664 if (is_beacon(beacon->header.frame_ctl)) {
James Ketrenos3f552bb2005-09-21 11:54:47 -05001665 if (ieee->handle_beacon != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001666 ieee->handle_beacon(dev, beacon, target);
James Ketrenos3f552bb2005-09-21 11:54:47 -05001667 } else {
1668 if (ieee->handle_probe_response != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001669 ieee->handle_probe_response(dev, beacon, target);
James Ketrenos3f552bb2005-09-21 11:54:47 -05001670 }
Jeff Garzikb4538722005-05-12 22:48:20 -04001671}
1672
1673void ieee80211_rx_mgt(struct ieee80211_device *ieee,
James Ketrenosee34af32005-09-21 11:54:36 -05001674 struct ieee80211_hdr_4addr *header,
Jeff Garzikb4538722005-05-12 22:48:20 -04001675 struct ieee80211_rx_stats *stats)
1676{
James Ketrenosfd278172005-09-13 17:25:51 -05001677 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
Jeff Garzikb4538722005-05-12 22:48:20 -04001678 case IEEE80211_STYPE_ASSOC_RESP:
1679 IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001680 WLAN_FC_GET_STYPE(le16_to_cpu
1681 (header->frame_ctl)));
James Ketrenos9e8571a2005-09-21 11:56:33 -05001682 ieee80211_handle_assoc_resp(ieee,
1683 (struct ieee80211_assoc_response *)
1684 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001685 break;
1686
1687 case IEEE80211_STYPE_REASSOC_RESP:
1688 IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001689 WLAN_FC_GET_STYPE(le16_to_cpu
1690 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001691 break;
1692
James Ketrenos42c94e42005-09-21 11:58:29 -05001693 case IEEE80211_STYPE_PROBE_REQ:
Larry Finger1a1fedf2006-01-30 09:42:24 -06001694 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos42c94e42005-09-21 11:58:29 -05001695 WLAN_FC_GET_STYPE(le16_to_cpu
1696 (header->frame_ctl)));
1697
1698 if (ieee->handle_probe_request != NULL)
1699 ieee->handle_probe_request(ieee->dev,
1700 (struct
1701 ieee80211_probe_request *)
1702 header, stats);
1703 break;
1704
Jeff Garzikb4538722005-05-12 22:48:20 -04001705 case IEEE80211_STYPE_PROBE_RESP:
1706 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001707 WLAN_FC_GET_STYPE(le16_to_cpu
1708 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001709 IEEE80211_DEBUG_SCAN("Probe response\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001710 ieee80211_process_probe_response(ieee,
1711 (struct
1712 ieee80211_probe_response *)
1713 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001714 break;
1715
1716 case IEEE80211_STYPE_BEACON:
1717 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001718 WLAN_FC_GET_STYPE(le16_to_cpu
1719 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001720 IEEE80211_DEBUG_SCAN("Beacon\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001721 ieee80211_process_probe_response(ieee,
1722 (struct
1723 ieee80211_probe_response *)
1724 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001725 break;
James Ketrenos3f552bb2005-09-21 11:54:47 -05001726 case IEEE80211_STYPE_AUTH:
1727
Larry Finger1a1fedf2006-01-30 09:42:24 -06001728 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos3f552bb2005-09-21 11:54:47 -05001729 WLAN_FC_GET_STYPE(le16_to_cpu
1730 (header->frame_ctl)));
1731
1732 if (ieee->handle_auth != NULL)
1733 ieee->handle_auth(ieee->dev,
1734 (struct ieee80211_auth *)header);
1735 break;
1736
1737 case IEEE80211_STYPE_DISASSOC:
1738 if (ieee->handle_disassoc != NULL)
1739 ieee->handle_disassoc(ieee->dev,
1740 (struct ieee80211_disassoc *)
1741 header);
1742 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001743
Zhu Yid1b46b02006-01-19 16:22:15 +08001744 case IEEE80211_STYPE_ACTION:
1745 IEEE80211_DEBUG_MGMT("ACTION\n");
1746 if (ieee->handle_action)
1747 ieee->handle_action(ieee->dev,
1748 (struct ieee80211_action *)
1749 header, stats);
1750 break;
1751
Larry Finger2f633db2006-01-30 23:25:10 -06001752 case IEEE80211_STYPE_REASSOC_REQ:
1753 IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
1754 WLAN_FC_GET_STYPE(le16_to_cpu
1755 (header->frame_ctl)));
1756
Zhu Yi7736b5b2006-04-13 17:17:47 +08001757 IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
1758 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001759 if (ieee->handle_reassoc_request != NULL)
1760 ieee->handle_reassoc_request(ieee->dev,
1761 (struct ieee80211_reassoc_request *)
1762 header);
1763 break;
1764
1765 case IEEE80211_STYPE_ASSOC_REQ:
1766 IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
1767 WLAN_FC_GET_STYPE(le16_to_cpu
1768 (header->frame_ctl)));
1769
Zhu Yi7736b5b2006-04-13 17:17:47 +08001770 IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
1771 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001772 if (ieee->handle_assoc_request != NULL)
1773 ieee->handle_assoc_request(ieee->dev);
1774 break;
1775
James Ketrenos31b59ea2005-09-21 11:58:49 -05001776 case IEEE80211_STYPE_DEAUTH:
Zhu Yid1b46b02006-01-19 16:22:15 +08001777 IEEE80211_DEBUG_MGMT("DEAUTH\n");
James Ketrenos31b59ea2005-09-21 11:58:49 -05001778 if (ieee->handle_deauth != NULL)
Zhu Yid1b46b02006-01-19 16:22:15 +08001779 ieee->handle_deauth(ieee->dev,
1780 (struct ieee80211_deauth *)
James Ketrenos31b59ea2005-09-21 11:58:49 -05001781 header);
1782 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001783 default:
1784 IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001785 WLAN_FC_GET_STYPE(le16_to_cpu
1786 (header->frame_ctl)));
Zhu Yi7736b5b2006-04-13 17:17:47 +08001787 IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1788 ieee->dev->name,
1789 WLAN_FC_GET_STYPE(le16_to_cpu
1790 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001791 break;
1792 }
1793}
1794
Daniel Drakef2060f032006-07-18 21:38:05 +01001795EXPORT_SYMBOL_GPL(ieee80211_rx_any);
Jeff Garzikb4538722005-05-12 22:48:20 -04001796EXPORT_SYMBOL(ieee80211_rx_mgt);
1797EXPORT_SYMBOL(ieee80211_rx);