blob: 876a004918b0961c52972e1cc875773535784a08 [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>
Jeff Garzikb4538722005-05-12 22:48:20 -040036#include <net/ieee80211.h>
37
Arjan van de Ven858119e2006-01-14 13:20:43 -080038static void ieee80211_monitor_rx(struct ieee80211_device *ieee,
Jeff Garzikb4538722005-05-12 22:48:20 -040039 struct sk_buff *skb,
40 struct ieee80211_rx_stats *rx_stats)
41{
42 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
43 u16 fc = le16_to_cpu(hdr->frame_ctl);
44
45 skb->dev = ieee->dev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -070046 skb_reset_mac_header(skb);
Jeff Garzikb4538722005-05-12 22:48:20 -040047 skb_pull(skb, ieee80211_get_hdrlen(fc));
48 skb->pkt_type = PACKET_OTHERHOST;
YOSHIFUJI Hideaki4e394302007-12-12 03:52:26 +090049 skb->protocol = htons(ETH_P_80211_RAW);
Jeff Garzikb4538722005-05-12 22:48:20 -040050 memset(skb->cb, 0, sizeof(skb->cb));
51 netif_rx(skb);
52}
53
Jeff Garzikb4538722005-05-12 22:48:20 -040054/* Called only as a tasklet (software IRQ) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040055static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct
56 ieee80211_device
57 *ieee,
58 unsigned int seq,
59 unsigned int frag,
60 u8 * src,
61 u8 * dst)
Jeff Garzikb4538722005-05-12 22:48:20 -040062{
63 struct ieee80211_frag_entry *entry;
64 int i;
65
66 for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
67 entry = &ieee->frag_cache[i];
68 if (entry->skb != NULL &&
69 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -040070 IEEE80211_DEBUG_FRAG("expiring fragment cache entry "
71 "seq=%u last_frag=%u\n",
72 entry->seq, entry->last_frag);
Jeff Garzikb4538722005-05-12 22:48:20 -040073 dev_kfree_skb_any(entry->skb);
74 entry->skb = NULL;
75 }
76
77 if (entry->skb != NULL && entry->seq == seq &&
78 (entry->last_frag + 1 == frag || frag == -1) &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -080079 !compare_ether_addr(entry->src_addr, src) &&
80 !compare_ether_addr(entry->dst_addr, dst))
Jeff Garzikb4538722005-05-12 22:48:20 -040081 return entry;
82 }
83
84 return NULL;
85}
86
87/* Called only as a tasklet (software IRQ) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040088static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee,
James Ketrenosee34af32005-09-21 11:54:36 -050089 struct ieee80211_hdr_4addr *hdr)
Jeff Garzikb4538722005-05-12 22:48:20 -040090{
91 struct sk_buff *skb = NULL;
92 u16 sc;
93 unsigned int frag, seq;
94 struct ieee80211_frag_entry *entry;
95
96 sc = le16_to_cpu(hdr->seq_ctl);
97 frag = WLAN_GET_SEQ_FRAG(sc);
98 seq = WLAN_GET_SEQ_SEQ(sc);
99
100 if (frag == 0) {
101 /* Reserve enough space to fit maximum frame length */
102 skb = dev_alloc_skb(ieee->dev->mtu +
James Ketrenosee34af32005-09-21 11:54:36 -0500103 sizeof(struct ieee80211_hdr_4addr) +
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400104 8 /* LLC */ +
105 2 /* alignment */ +
106 8 /* WEP */ + ETH_ALEN /* WDS */ );
Jeff Garzikb4538722005-05-12 22:48:20 -0400107 if (skb == NULL)
108 return NULL;
109
110 entry = &ieee->frag_cache[ieee->frag_next_idx];
111 ieee->frag_next_idx++;
112 if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
113 ieee->frag_next_idx = 0;
114
115 if (entry->skb != NULL)
116 dev_kfree_skb_any(entry->skb);
117
118 entry->first_frag_time = jiffies;
119 entry->seq = seq;
120 entry->last_frag = frag;
121 entry->skb = skb;
122 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
123 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
124 } else {
125 /* received a fragment of a frame for which the head fragment
126 * should have already been received */
127 entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
128 hdr->addr1);
129 if (entry != NULL) {
130 entry->last_frag = frag;
131 skb = entry->skb;
132 }
133 }
134
135 return skb;
136}
137
Jeff Garzikb4538722005-05-12 22:48:20 -0400138/* Called only as a tasklet (software IRQ) */
139static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
James Ketrenosee34af32005-09-21 11:54:36 -0500140 struct ieee80211_hdr_4addr *hdr)
Jeff Garzikb4538722005-05-12 22:48:20 -0400141{
142 u16 sc;
143 unsigned int seq;
144 struct ieee80211_frag_entry *entry;
145
146 sc = le16_to_cpu(hdr->seq_ctl);
147 seq = WLAN_GET_SEQ_SEQ(sc);
148
149 entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
150 hdr->addr1);
151
152 if (entry == NULL) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400153 IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
154 "entry (seq=%u)\n", seq);
Jeff Garzikb4538722005-05-12 22:48:20 -0400155 return -1;
156 }
157
158 entry->skb = NULL;
159 return 0;
160}
161
Jeff Garzikb4538722005-05-12 22:48:20 -0400162#ifdef NOT_YET
163/* ieee80211_rx_frame_mgtmt
164 *
165 * Responsible for handling management control frames
166 *
167 * Called by ieee80211_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800168static int
Jeff Garzikb4538722005-05-12 22:48:20 -0400169ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
170 struct ieee80211_rx_stats *rx_stats, u16 type,
171 u16 stype)
172{
173 if (ieee->iw_mode == IW_MODE_MASTER) {
174 printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
175 ieee->dev->name);
176 return 0;
177/*
James Ketrenosee34af32005-09-21 11:54:36 -0500178 hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
Jeff Garzikb4538722005-05-12 22:48:20 -0400179 skb->data);*/
180 }
181
182 if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
183 if (stype == WLAN_FC_STYPE_BEACON &&
184 ieee->iw_mode == IW_MODE_MASTER) {
185 struct sk_buff *skb2;
186 /* Process beacon frames also in kernel driver to
187 * update STA(AP) table statistics */
188 skb2 = skb_clone(skb, GFP_ATOMIC);
189 if (skb2)
190 hostap_rx(skb2->dev, skb2, rx_stats);
191 }
192
193 /* send management frames to the user space daemon for
194 * processing */
195 ieee->apdevstats.rx_packets++;
196 ieee->apdevstats.rx_bytes += skb->len;
197 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
198 return 0;
199 }
200
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400201 if (ieee->iw_mode == IW_MODE_MASTER) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400202 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
203 printk(KERN_DEBUG "%s: unknown management frame "
204 "(type=0x%02x, stype=0x%02x) dropped\n",
205 skb->dev->name, type, stype);
206 return -1;
207 }
208
209 hostap_rx(skb->dev, skb, rx_stats);
210 return 0;
211 }
212
213 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
214 "received in non-Host AP mode\n", skb->dev->name);
215 return -1;
216}
217#endif
218
Jeff Garzikb4538722005-05-12 22:48:20 -0400219/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
220/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400221static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
222
Jeff Garzikb4538722005-05-12 22:48:20 -0400223/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
224static unsigned char bridge_tunnel_header[] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400225 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
Jeff Garzikb4538722005-05-12 22:48:20 -0400226/* No encapsulation header if EtherType < 0x600 (=length) */
227
228/* Called by ieee80211_rx_frame_decrypt */
229static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
230 struct sk_buff *skb)
231{
232 struct net_device *dev = ieee->dev;
233 u16 fc, ethertype;
James Ketrenosee34af32005-09-21 11:54:36 -0500234 struct ieee80211_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400235 u8 *pos;
236
237 if (skb->len < 24)
238 return 0;
239
James Ketrenosee34af32005-09-21 11:54:36 -0500240 hdr = (struct ieee80211_hdr_3addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400241 fc = le16_to_cpu(hdr->frame_ctl);
242
243 /* check that the frame is unicast frame to us */
244 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
245 IEEE80211_FCTL_TODS &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -0800246 !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
247 !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400248 /* ToDS frame with own addr BSSID and DA */
249 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
250 IEEE80211_FCTL_FROMDS &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -0800251 !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400252 /* FromDS frame with own addr as DA */
253 } else
254 return 0;
255
256 if (skb->len < 24 + 8)
257 return 0;
258
259 /* check for port access entity Ethernet type */
260 pos = skb->data + 24;
261 ethertype = (pos[6] << 8) | pos[7];
262 if (ethertype == ETH_P_PAE)
263 return 1;
264
265 return 0;
266}
267
268/* Called only as a tasklet (software IRQ), by ieee80211_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800269static int
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400270ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
Jeff Garzikb4538722005-05-12 22:48:20 -0400271 struct ieee80211_crypt_data *crypt)
272{
James Ketrenosee34af32005-09-21 11:54:36 -0500273 struct ieee80211_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400274 int res, hdrlen;
275
276 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
277 return 0;
278
James Ketrenosee34af32005-09-21 11:54:36 -0500279 hdr = (struct ieee80211_hdr_3addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400280 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
281
Jeff Garzikb4538722005-05-12 22:48:20 -0400282 atomic_inc(&crypt->refcnt);
283 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
284 atomic_dec(&crypt->refcnt);
285 if (res < 0) {
Johannes Berge1749612008-10-27 15:59:26 -0700286 IEEE80211_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
287 hdr->addr2, res);
Jeff Garzikb4538722005-05-12 22:48:20 -0400288 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
Jeff Garzikb4538722005-05-12 22:48:20 -0400299/* Called only as a tasklet (software IRQ), by ieee80211_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800300static int
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400301ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
302 struct sk_buff *skb, int keyidx,
303 struct ieee80211_crypt_data *crypt)
Jeff Garzikb4538722005-05-12 22:48:20 -0400304{
James Ketrenosee34af32005-09-21 11:54:36 -0500305 struct ieee80211_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400306 int res, hdrlen;
307
308 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
309 return 0;
310
James Ketrenosee34af32005-09-21 11:54:36 -0500311 hdr = (struct ieee80211_hdr_3addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400312 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
313
314 atomic_inc(&crypt->refcnt);
315 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
316 atomic_dec(&crypt->refcnt);
317 if (res < 0) {
318 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
Johannes Berge1749612008-10-27 15:59:26 -0700319 " (SA=%pM keyidx=%d)\n", ieee->dev->name, hdr->addr2,
David S. Miller21f644f2008-04-08 16:50:44 -0700320 keyidx);
Jeff Garzikb4538722005-05-12 22:48:20 -0400321 return -1;
322 }
323
324 return 0;
325}
326
Jeff Garzikb4538722005-05-12 22:48:20 -0400327/* All received frames are sent to this function. @skb contains the frame in
328 * IEEE 802.11 format, i.e., in the format it was sent over air.
329 * This function is called only as a tasklet (software IRQ). */
330int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
331 struct ieee80211_rx_stats *rx_stats)
332{
333 struct net_device *dev = ieee->dev;
James Ketrenosee34af32005-09-21 11:54:36 -0500334 struct ieee80211_hdr_4addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400335 size_t hdrlen;
336 u16 fc, type, stype, sc;
337 struct net_device_stats *stats;
338 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];
351 struct ieee80211_crypt_data *crypt = NULL;
352 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 stats = &ieee->stats;
357
358 if (skb->len < 10) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400359 printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
Jeff Garzikb4538722005-05-12 22:48:20 -0400360 goto rx_dropped;
361 }
362
363 fc = le16_to_cpu(hdr->frame_ctl);
364 type = WLAN_FC_GET_TYPE(fc);
365 stype = WLAN_FC_GET_STYPE(fc);
366 sc = le16_to_cpu(hdr->seq_ctl);
367 frag = WLAN_GET_SEQ_FRAG(sc);
368 hdrlen = ieee80211_get_hdrlen(fc);
369
John W. Linville04045f92007-10-01 21:03:54 -0700370 if (skb->len < hdrlen) {
371 printk(KERN_INFO "%s: invalid SKB length %d\n",
372 dev->name, skb->len);
373 goto rx_dropped;
374 }
375
Jeff Garzikb4538722005-05-12 22:48:20 -0400376 /* Put this code here so that we avoid duplicating it in all
377 * Rx paths. - Jean II */
Horms8f7eb4072006-06-26 17:44:38 +0900378#ifdef CONFIG_WIRELESS_EXT
Jeff Garzikb4538722005-05-12 22:48:20 -0400379#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
380 /* If spy monitoring on */
James Ketrenos74079fd2005-09-13 17:35:21 -0500381 if (ieee->spy_data.spy_number > 0) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400382 struct iw_quality wstats;
James Ketrenos74079fd2005-09-13 17:35:21 -0500383
384 wstats.updated = 0;
385 if (rx_stats->mask & IEEE80211_STATMASK_RSSI) {
Bruno Randolf566bfe52008-05-08 19:15:40 +0200386 wstats.level = rx_stats->signal;
James Ketrenos74079fd2005-09-13 17:35:21 -0500387 wstats.updated |= IW_QUAL_LEVEL_UPDATED;
388 } else
389 wstats.updated |= IW_QUAL_LEVEL_INVALID;
390
391 if (rx_stats->mask & IEEE80211_STATMASK_NOISE) {
392 wstats.noise = rx_stats->noise;
393 wstats.updated |= IW_QUAL_NOISE_UPDATED;
394 } else
395 wstats.updated |= IW_QUAL_NOISE_INVALID;
396
397 if (rx_stats->mask & IEEE80211_STATMASK_SIGNAL) {
398 wstats.qual = rx_stats->signal;
399 wstats.updated |= IW_QUAL_QUAL_UPDATED;
400 } else
401 wstats.updated |= IW_QUAL_QUAL_INVALID;
402
Jeff Garzikb4538722005-05-12 22:48:20 -0400403 /* Update spy records */
James Ketrenos74079fd2005-09-13 17:35:21 -0500404 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
Jeff Garzikb4538722005-05-12 22:48:20 -0400405 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400406#endif /* IW_WIRELESS_SPY */
Horms8f7eb4072006-06-26 17:44:38 +0900407#endif /* CONFIG_WIRELESS_EXT */
James Ketrenos74079fd2005-09-13 17:35:21 -0500408
409#ifdef NOT_YET
Jeff Garzikb4538722005-05-12 22:48:20 -0400410 hostap_update_rx_stats(local->ap, hdr, rx_stats);
411#endif
412
Jeff Garzikb4538722005-05-12 22:48:20 -0400413 if (ieee->iw_mode == IW_MODE_MONITOR) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400414 stats->rx_packets++;
415 stats->rx_bytes += skb->len;
Eric Sesterhenn60d48f12006-06-21 21:05:58 +0200416 ieee80211_monitor_rx(ieee, skb, rx_stats);
Jeff Garzikb4538722005-05-12 22:48:20 -0400417 return 1;
418 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400419
Zhu Yib6daa252006-01-19 16:20:42 +0800420 can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
421 is_broadcast_ether_addr(hdr->addr2)) ?
422 ieee->host_mc_decrypt : ieee->host_decrypt;
423
424 if (can_be_decrypted) {
Zhu Yib6daa252006-01-19 16:20:42 +0800425 if (skb->len >= hdrlen + 3) {
426 /* Top two-bits of byte 3 are the key index */
Daniel Drakec9308b02006-09-27 03:50:31 +0100427 keyidx = skb->data[hdrlen + 3] >> 6;
Zhu Yib6daa252006-01-19 16:20:42 +0800428 }
429
Daniel Drakec9308b02006-09-27 03:50:31 +0100430 /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
431 * is only allowed 2-bits of storage, no value of keyidx can
432 * be provided via above code that would result in keyidx
Zhu Yib6daa252006-01-19 16:20:42 +0800433 * being out of range */
Daniel Drakec9308b02006-09-27 03:50:31 +0100434 crypt = ieee->crypt[keyidx];
Zhu Yib6daa252006-01-19 16:20:42 +0800435
Jeff Garzikb4538722005-05-12 22:48:20 -0400436#ifdef NOT_YET
437 sta = NULL;
438
439 /* Use station specific key to override default keys if the
440 * receiver address is a unicast address ("individual RA"). If
441 * bcrx_sta_key parameter is set, station specific key is used
442 * even with broad/multicast targets (this is against IEEE
443 * 802.11, but makes it easier to use different keys with
444 * stations that do not support WEP key mapping). */
445
446 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400447 (void)hostap_handle_sta_crypto(local, hdr, &crypt,
448 &sta);
Jeff Garzikb4538722005-05-12 22:48:20 -0400449#endif
450
451 /* allow NULL decrypt to indicate an station specific override
452 * for default encryption */
453 if (crypt && (crypt->ops == NULL ||
454 crypt->ops->decrypt_mpdu == NULL))
455 crypt = NULL;
456
Jiri Bencf13baae2005-08-25 20:11:46 -0400457 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400458 /* This seems to be triggered by some (multicast?)
459 * frames from other than current BSS, so just drop the
460 * frames silently instead of filling system log with
461 * these reports. */
462 IEEE80211_DEBUG_DROP("Decryption failed (not set)"
Johannes Berge1749612008-10-27 15:59:26 -0700463 " (SA=%pM)\n", hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400464 ieee->ieee_stats.rx_discards_undecryptable++;
465 goto rx_dropped;
466 }
467 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400468#ifdef NOT_YET
469 if (type != WLAN_FC_TYPE_DATA) {
470 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
Jiri Bencf13baae2005-08-25 20:11:46 -0400471 fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400472 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400473 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
Johannes Berge1749612008-10-27 15:59:26 -0700474 "from %pM\n", dev->name, hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400475 /* TODO: could inform hostapd about this so that it
476 * could send auth failure report */
477 goto rx_dropped;
478 }
479
480 if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
481 goto rx_dropped;
482 else
483 goto rx_exit;
484 }
485#endif
Larry Finger837925d2006-10-03 18:49:32 -0500486 /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
487 if (sc == ieee->prev_seq_ctl)
488 goto rx_dropped;
489 else
490 ieee->prev_seq_ctl = sc;
Jeff Garzikb4538722005-05-12 22:48:20 -0400491
492 /* Data frame - extract src/dst addresses */
Jiri Benc286d9742005-05-24 15:10:18 +0200493 if (skb->len < IEEE80211_3ADDR_LEN)
Jeff Garzikb4538722005-05-12 22:48:20 -0400494 goto rx_dropped;
495
496 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
497 case IEEE80211_FCTL_FROMDS:
498 memcpy(dst, hdr->addr1, ETH_ALEN);
499 memcpy(src, hdr->addr3, ETH_ALEN);
500 break;
501 case IEEE80211_FCTL_TODS:
502 memcpy(dst, hdr->addr3, ETH_ALEN);
503 memcpy(src, hdr->addr2, ETH_ALEN);
504 break;
505 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
Jiri Benc286d9742005-05-24 15:10:18 +0200506 if (skb->len < IEEE80211_4ADDR_LEN)
Jeff Garzikb4538722005-05-12 22:48:20 -0400507 goto rx_dropped;
508 memcpy(dst, hdr->addr3, ETH_ALEN);
509 memcpy(src, hdr->addr4, ETH_ALEN);
510 break;
511 case 0:
512 memcpy(dst, hdr->addr1, ETH_ALEN);
513 memcpy(src, hdr->addr2, ETH_ALEN);
514 break;
515 }
516
517#ifdef NOT_YET
518 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
519 goto rx_dropped;
520 if (wds) {
521 skb->dev = dev = wds;
522 stats = hostap_get_stats(dev);
523 }
524
525 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400526 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
527 IEEE80211_FCTL_FROMDS && ieee->stadev
Kris Katterjohnd3f4a682006-01-09 16:01:43 -0800528 && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400529 /* Frame from BSSID of the AP for which we are a client */
530 skb->dev = dev = ieee->stadev;
531 stats = hostap_get_stats(dev);
532 from_assoc_ap = 1;
533 }
534#endif
535
536 dev->last_rx = jiffies;
537
538#ifdef NOT_YET
539 if ((ieee->iw_mode == IW_MODE_MASTER ||
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400540 ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400541 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
542 wds != NULL)) {
543 case AP_RX_CONTINUE_NOT_AUTHORIZED:
544 frame_authorized = 0;
545 break;
546 case AP_RX_CONTINUE:
547 frame_authorized = 1;
548 break;
549 case AP_RX_DROP:
550 goto rx_dropped;
551 case AP_RX_EXIT:
552 goto rx_exit;
553 }
554 }
555#endif
556
557 /* Nullfunc frames may have PS-bit set, so they must be passed to
558 * hostap_handle_sta_rx() before being dropped here. */
James Ketrenos9e8571a2005-09-21 11:56:33 -0500559
560 stype &= ~IEEE80211_STYPE_QOS_DATA;
561
Jeff Garzikb4538722005-05-12 22:48:20 -0400562 if (stype != IEEE80211_STYPE_DATA &&
563 stype != IEEE80211_STYPE_DATA_CFACK &&
564 stype != IEEE80211_STYPE_DATA_CFPOLL &&
565 stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
566 if (stype != IEEE80211_STYPE_NULLFUNC)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400567 IEEE80211_DEBUG_DROP("RX: dropped data frame "
568 "with no data (type=0x%02x, "
569 "subtype=0x%02x, len=%d)\n",
570 type, stype, skb->len);
Jeff Garzikb4538722005-05-12 22:48:20 -0400571 goto rx_dropped;
572 }
573
574 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
575
Zhu Yib6daa252006-01-19 16:20:42 +0800576 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
Jeff Garzikb4538722005-05-12 22:48:20 -0400577 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
578 goto rx_dropped;
579
James Ketrenosee34af32005-09-21 11:54:36 -0500580 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400581
582 /* skb: hdr + (possibly fragmented) plaintext payload */
583 // PR: FIXME: hostap has additional conditions in the "if" below:
Jiri Bencf13baae2005-08-25 20:11:46 -0400584 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
Denis Vlasenko9eafe762006-01-22 13:57:10 +0200585 if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400586 int flen;
587 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
588 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
589
590 if (!frag_skb) {
591 IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
592 "Rx cannot get skb from fragment "
593 "cache (morefrag=%d seq=%u frag=%u)\n",
594 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
595 WLAN_GET_SEQ_SEQ(sc), frag);
596 goto rx_dropped;
597 }
598
599 flen = skb->len;
600 if (frag != 0)
601 flen -= hdrlen;
602
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700603 if (frag_skb->tail + flen > frag_skb->end) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400604 printk(KERN_WARNING "%s: host decrypted and "
605 "reassembled frame did not fit skb\n",
606 dev->name);
607 ieee80211_frag_cache_invalidate(ieee, hdr);
608 goto rx_dropped;
609 }
610
611 if (frag == 0) {
612 /* copy first fragment (including full headers) into
613 * beginning of the fragment cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300614 skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
Jeff Garzikb4538722005-05-12 22:48:20 -0400615 } else {
616 /* append frame payload to the end of the fragment
617 * cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300618 skb_copy_from_linear_data_offset(skb, hdrlen,
619 skb_put(frag_skb, flen), flen);
Jeff Garzikb4538722005-05-12 22:48:20 -0400620 }
621 dev_kfree_skb_any(skb);
622 skb = NULL;
623
624 if (fc & IEEE80211_FCTL_MOREFRAGS) {
625 /* more fragments expected - leave the skb in fragment
626 * cache for now; it will be delivered to upper layers
627 * after all fragments have been received */
628 goto rx_exit;
629 }
630
631 /* this was the last fragment and the frame will be
632 * delivered, so remove skb from fragment cache */
633 skb = frag_skb;
James Ketrenosee34af32005-09-21 11:54:36 -0500634 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400635 ieee80211_frag_cache_invalidate(ieee, hdr);
636 }
637
638 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
639 * encrypted/authenticated */
Zhu Yib6daa252006-01-19 16:20:42 +0800640 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
Jeff Garzikb4538722005-05-12 22:48:20 -0400641 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
642 goto rx_dropped;
643
James Ketrenosee34af32005-09-21 11:54:36 -0500644 hdr = (struct ieee80211_hdr_4addr *)skb->data;
Jiri Bencf13baae2005-08-25 20:11:46 -0400645 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400646 if ( /*ieee->ieee802_1x && */
647 ieee80211_is_eapol_frame(ieee, skb)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400648 /* pass unencrypted EAPOL frames even if encryption is
649 * configured */
Jeff Garzikb4538722005-05-12 22:48:20 -0400650 } else {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400651 IEEE80211_DEBUG_DROP("encryption configured, but RX "
Johannes Berge1749612008-10-27 15:59:26 -0700652 "frame not encrypted (SA=%pM)\n",
653 hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400654 goto rx_dropped;
655 }
656 }
657
Jiri Bencf13baae2005-08-25 20:11:46 -0400658 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
Jeff Garzikb4538722005-05-12 22:48:20 -0400659 !ieee80211_is_eapol_frame(ieee, skb)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400660 IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
Johannes Berge1749612008-10-27 15:59:26 -0700661 "frame from %pM (drop_unencrypted=1)\n",
662 hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400663 goto rx_dropped;
664 }
665
Daniel Drakec9308b02006-09-27 03:50:31 +0100666 /* If the frame was decrypted in hardware, we may need to strip off
667 * any security data (IV, ICV, etc) that was left behind */
668 if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
669 ieee->host_strip_iv_icv) {
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900670 int trimlen = 0;
Daniel Drakec9308b02006-09-27 03:50:31 +0100671
672 /* Top two-bits of byte 3 are the key index */
673 if (skb->len >= hdrlen + 3)
674 keyidx = skb->data[hdrlen + 3] >> 6;
675
676 /* To strip off any security data which appears before the
677 * payload, we simply increase hdrlen (as the header gets
678 * chopped off immediately below). For the security data which
679 * appears after the payload, we use skb_trim. */
680
681 switch (ieee->sec.encode_alg[keyidx]) {
682 case SEC_ALG_WEP:
683 /* 4 byte IV */
684 hdrlen += 4;
685 /* 4 byte ICV */
686 trimlen = 4;
687 break;
688 case SEC_ALG_TKIP:
689 /* 4 byte IV, 4 byte ExtIV */
690 hdrlen += 8;
691 /* 8 byte MIC, 4 byte ICV */
692 trimlen = 12;
693 break;
694 case SEC_ALG_CCMP:
695 /* 8 byte CCMP header */
696 hdrlen += 8;
697 /* 8 byte MIC */
698 trimlen = 8;
699 break;
700 }
701
702 if (skb->len < trimlen)
703 goto rx_dropped;
704
705 __skb_trim(skb, skb->len - trimlen);
706
707 if (skb->len < hdrlen)
708 goto rx_dropped;
709 }
710
Jeff Garzikb4538722005-05-12 22:48:20 -0400711 /* skb: hdr + (possible reassembled) full plaintext payload */
712
713 payload = skb->data + hdrlen;
714 ethertype = (payload[6] << 8) | payload[7];
715
716#ifdef NOT_YET
717 /* If IEEE 802.1X is used, check whether the port is authorized to send
718 * the received frame. */
719 if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
720 if (ethertype == ETH_P_PAE) {
721 printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
722 dev->name);
723 if (ieee->hostapd && ieee->apdev) {
724 /* Send IEEE 802.1X frames to the user
725 * space daemon for processing */
726 prism2_rx_80211(ieee->apdev, skb, rx_stats,
727 PRISM2_RX_MGMT);
728 ieee->apdevstats.rx_packets++;
729 ieee->apdevstats.rx_bytes += skb->len;
730 goto rx_exit;
731 }
732 } else if (!frame_authorized) {
733 printk(KERN_DEBUG "%s: dropped frame from "
734 "unauthorized port (IEEE 802.1X): "
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400735 "ethertype=0x%04x\n", dev->name, ethertype);
Jeff Garzikb4538722005-05-12 22:48:20 -0400736 goto rx_dropped;
737 }
738 }
739#endif
740
741 /* convert hdr + possible LLC headers into Ethernet header */
742 if (skb->len - hdrlen >= 8 &&
743 ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
744 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
745 memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
746 /* remove RFC1042 or Bridge-Tunnel encapsulation and
747 * replace EtherType */
748 skb_pull(skb, hdrlen + SNAP_SIZE);
749 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
750 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
751 } else {
Al Virod9e94d52007-12-29 05:01:07 -0500752 __be16 len;
Jeff Garzikb4538722005-05-12 22:48:20 -0400753 /* Leave Ethernet header part of hdr and full payload */
754 skb_pull(skb, hdrlen);
755 len = htons(skb->len);
756 memcpy(skb_push(skb, 2), &len, 2);
757 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
758 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
759 }
760
761#ifdef NOT_YET
762 if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400763 IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400764 /* Non-standard frame: get addr4 from its bogus location after
765 * the payload */
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300766 skb_copy_to_linear_data_offset(skb, ETH_ALEN,
767 skb->data + skb->len - ETH_ALEN,
768 ETH_ALEN);
Jeff Garzikb4538722005-05-12 22:48:20 -0400769 skb_trim(skb, skb->len - ETH_ALEN);
770 }
771#endif
772
773 stats->rx_packets++;
774 stats->rx_bytes += skb->len;
775
776#ifdef NOT_YET
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400777 if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400778 if (dst[0] & 0x01) {
779 /* copy multicast frame both to the higher layers and
780 * to the wireless media */
781 ieee->ap->bridged_multicast++;
782 skb2 = skb_clone(skb, GFP_ATOMIC);
783 if (skb2 == NULL)
784 printk(KERN_DEBUG "%s: skb_clone failed for "
785 "multicast frame\n", dev->name);
786 } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
787 /* send frame directly to the associated STA using
788 * wireless media and not passing to higher layers */
789 ieee->ap->bridged_unicast++;
790 skb2 = skb;
791 skb = NULL;
792 }
793 }
794
795 if (skb2 != NULL) {
796 /* send to wireless media */
Jeff Garzikb4538722005-05-12 22:48:20 -0400797 skb2->dev = dev;
YOSHIFUJI Hideaki4e394302007-12-12 03:52:26 +0900798 skb2->protocol = htons(ETH_P_802_3);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700799 skb_reset_mac_header(skb2);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700800 skb_reset_network_header(skb2);
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700801 /* skb2->network_header += ETH_HLEN; */
Jeff Garzikb4538722005-05-12 22:48:20 -0400802 dev_queue_xmit(skb2);
803 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400804#endif
805
806 if (skb) {
807 skb->protocol = eth_type_trans(skb, dev);
808 memset(skb->cb, 0, sizeof(skb->cb));
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400809 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
Zhu Yid6529232006-01-19 16:20:49 +0800810 if (netif_rx(skb) == NET_RX_DROP) {
811 /* netif_rx always succeeds, but it might drop
812 * the packet. If it drops the packet, we log that
813 * in our stats. */
814 IEEE80211_DEBUG_DROP
815 ("RX: netif_rx dropped the packet\n");
816 stats->rx_dropped++;
817 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400818 }
819
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400820 rx_exit:
Jeff Garzikb4538722005-05-12 22:48:20 -0400821#ifdef NOT_YET
822 if (sta)
823 hostap_handle_sta_release(sta);
824#endif
825 return 1;
826
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400827 rx_dropped:
Jeff Garzikb4538722005-05-12 22:48:20 -0400828 stats->rx_dropped++;
829
830 /* Returning 0 indicates to caller that we have not handled the SKB--
831 * so it is still allocated and can be used again by underlying
832 * hardware as a DMA target */
833 return 0;
834}
835
Daniel Drakef2060f032006-07-18 21:38:05 +0100836/* Filter out unrelated packets, call ieee80211_rx[_mgt]
837 * This function takes over the skb, it should not be used again after calling
838 * this function. */
839void ieee80211_rx_any(struct ieee80211_device *ieee,
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200840 struct sk_buff *skb, struct ieee80211_rx_stats *stats)
841{
842 struct ieee80211_hdr_4addr *hdr;
843 int is_packet_for_us;
844 u16 fc;
845
Daniel Drakef2060f032006-07-18 21:38:05 +0100846 if (ieee->iw_mode == IW_MODE_MONITOR) {
847 if (!ieee80211_rx(ieee, skb, stats))
848 dev_kfree_skb_irq(skb);
849 return;
850 }
851
852 if (skb->len < sizeof(struct ieee80211_hdr))
853 goto drop_free;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200854
855 hdr = (struct ieee80211_hdr_4addr *)skb->data;
856 fc = le16_to_cpu(hdr->frame_ctl);
857
858 if ((fc & IEEE80211_FCTL_VERS) != 0)
Daniel Drakef2060f032006-07-18 21:38:05 +0100859 goto drop_free;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900860
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200861 switch (fc & IEEE80211_FCTL_FTYPE) {
862 case IEEE80211_FTYPE_MGMT:
Daniel Drakef2060f032006-07-18 21:38:05 +0100863 if (skb->len < sizeof(struct ieee80211_hdr_3addr))
864 goto drop_free;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200865 ieee80211_rx_mgt(ieee, hdr, stats);
Daniel Drakef2060f032006-07-18 21:38:05 +0100866 dev_kfree_skb_irq(skb);
867 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200868 case IEEE80211_FTYPE_DATA:
869 break;
870 case IEEE80211_FTYPE_CTL:
Daniel Drakef2060f032006-07-18 21:38:05 +0100871 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200872 default:
Daniel Drakef2060f032006-07-18 21:38:05 +0100873 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200874 }
875
876 is_packet_for_us = 0;
877 switch (ieee->iw_mode) {
878 case IW_MODE_ADHOC:
879 /* our BSS and not from/to DS */
880 if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0)
881 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
882 /* promisc: get all */
883 if (ieee->dev->flags & IFF_PROMISC)
884 is_packet_for_us = 1;
885 /* to us */
886 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
887 is_packet_for_us = 1;
888 /* mcast */
889 else if (is_multicast_ether_addr(hdr->addr1))
890 is_packet_for_us = 1;
891 }
892 break;
893 case IW_MODE_INFRA:
894 /* our BSS (== from our AP) and from DS */
895 if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0)
896 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
897 /* promisc: get all */
898 if (ieee->dev->flags & IFF_PROMISC)
899 is_packet_for_us = 1;
900 /* to us */
901 else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
902 is_packet_for_us = 1;
903 /* mcast */
904 else if (is_multicast_ether_addr(hdr->addr1)) {
905 /* not our own packet bcasted from AP */
906 if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN))
907 is_packet_for_us = 1;
908 }
909 }
910 break;
911 default:
912 /* ? */
913 break;
914 }
915
916 if (is_packet_for_us)
Daniel Drakef2060f032006-07-18 21:38:05 +0100917 if (!ieee80211_rx(ieee, skb, stats))
918 dev_kfree_skb_irq(skb);
919 return;
920
921drop_free:
922 dev_kfree_skb_irq(skb);
923 ieee->stats.rx_dropped++;
924 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200925}
926
Jeff Garzikb4538722005-05-12 22:48:20 -0400927#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
928
James Ketrenos9e8571a2005-09-21 11:56:33 -0500929static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
930
931/*
932* Make ther structure we read from the beacon packet has
933* the right values
934*/
935static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
936 *info_element, int sub_type)
937{
938
939 if (info_element->qui_subtype != sub_type)
940 return -1;
941 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
942 return -1;
943 if (info_element->qui_type != QOS_OUI_TYPE)
944 return -1;
945 if (info_element->version != QOS_VERSION_1)
946 return -1;
947
948 return 0;
949}
950
951/*
952 * Parse a QoS parameter element
953 */
954static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
955 *element_param, struct ieee80211_info_element
956 *info_element)
957{
958 int ret = 0;
959 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
960
961 if ((info_element == NULL) || (element_param == NULL))
962 return -1;
963
964 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
965 memcpy(element_param->info_element.qui, info_element->data,
966 info_element->len);
967 element_param->info_element.elementID = info_element->id;
968 element_param->info_element.length = info_element->len;
969 } else
970 ret = -1;
971 if (ret == 0)
972 ret = ieee80211_verify_qos_info(&element_param->info_element,
973 QOS_OUI_PARAM_SUB_TYPE);
974 return ret;
975}
976
977/*
978 * Parse a QoS information element
979 */
980static int ieee80211_read_qos_info_element(struct
981 ieee80211_qos_information_element
982 *element_info, struct ieee80211_info_element
983 *info_element)
984{
985 int ret = 0;
986 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
987
988 if (element_info == NULL)
989 return -1;
990 if (info_element == NULL)
991 return -1;
992
993 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
994 memcpy(element_info->qui, info_element->data,
995 info_element->len);
996 element_info->elementID = info_element->id;
997 element_info->length = info_element->len;
998 } else
999 ret = -1;
1000
1001 if (ret == 0)
1002 ret = ieee80211_verify_qos_info(element_info,
1003 QOS_OUI_INFO_SUB_TYPE);
1004 return ret;
1005}
1006
1007/*
1008 * Write QoS parameters from the ac parameters.
1009 */
1010static int ieee80211_qos_convert_ac_to_parameters(struct
1011 ieee80211_qos_parameter_info
1012 *param_elm, struct
1013 ieee80211_qos_parameters
1014 *qos_param)
1015{
1016 int rc = 0;
1017 int i;
1018 struct ieee80211_qos_ac_parameter *ac_params;
1019 u32 txop;
1020 u8 cw_min;
1021 u8 cw_max;
1022
1023 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1024 ac_params = &(param_elm->ac_params_record[i]);
1025
1026 qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
1027 qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
1028
1029 cw_min = ac_params->ecw_min_max & 0x0F;
Al Viro8fffc152007-12-27 01:25:40 -05001030 qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001031
1032 cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
Al Viro8fffc152007-12-27 01:25:40 -05001033 qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001034
1035 qos_param->flag[i] =
1036 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1037
1038 txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
Al Viro8fffc152007-12-27 01:25:40 -05001039 qos_param->tx_op_limit[i] = cpu_to_le16(txop);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001040 }
1041 return rc;
1042}
1043
1044/*
1045 * we have a generic data element which it may contain QoS information or
1046 * parameters element. check the information element length to decide
1047 * which type to read
1048 */
1049static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1050 *info_element,
1051 struct ieee80211_network *network)
1052{
1053 int rc = 0;
1054 struct ieee80211_qos_parameters *qos_param = NULL;
1055 struct ieee80211_qos_information_element qos_info_element;
1056
1057 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1058
1059 if (rc == 0) {
1060 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1061 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1062 } else {
1063 struct ieee80211_qos_parameter_info param_element;
1064
1065 rc = ieee80211_read_qos_param_element(&param_element,
1066 info_element);
1067 if (rc == 0) {
1068 qos_param = &(network->qos_data.parameters);
1069 ieee80211_qos_convert_ac_to_parameters(&param_element,
1070 qos_param);
1071 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1072 network->qos_data.param_count =
1073 param_element.info_element.ac_info & 0x0F;
1074 }
1075 }
1076
1077 if (rc == 0) {
1078 IEEE80211_DEBUG_QOS("QoS is supported\n");
1079 network->qos_data.supported = 1;
1080 }
1081 return rc;
1082}
1083
Zhu Yid1b46b02006-01-19 16:22:15 +08001084#ifdef CONFIG_IEEE80211_DEBUG
1085#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1086
1087static const char *get_info_element_string(u16 id)
1088{
1089 switch (id) {
1090 MFIE_STRING(SSID);
1091 MFIE_STRING(RATES);
1092 MFIE_STRING(FH_SET);
1093 MFIE_STRING(DS_SET);
1094 MFIE_STRING(CF_SET);
1095 MFIE_STRING(TIM);
1096 MFIE_STRING(IBSS_SET);
1097 MFIE_STRING(COUNTRY);
1098 MFIE_STRING(HOP_PARAMS);
1099 MFIE_STRING(HOP_TABLE);
1100 MFIE_STRING(REQUEST);
1101 MFIE_STRING(CHALLENGE);
1102 MFIE_STRING(POWER_CONSTRAINT);
1103 MFIE_STRING(POWER_CAPABILITY);
1104 MFIE_STRING(TPC_REQUEST);
1105 MFIE_STRING(TPC_REPORT);
1106 MFIE_STRING(SUPP_CHANNELS);
1107 MFIE_STRING(CSA);
1108 MFIE_STRING(MEASURE_REQUEST);
1109 MFIE_STRING(MEASURE_REPORT);
1110 MFIE_STRING(QUIET);
1111 MFIE_STRING(IBSS_DFS);
1112 MFIE_STRING(ERP_INFO);
1113 MFIE_STRING(RSN);
1114 MFIE_STRING(RATES_EX);
1115 MFIE_STRING(GENERIC);
1116 MFIE_STRING(QOS_PARAMETER);
1117 default:
1118 return "UNKNOWN";
1119 }
1120}
1121#endif
1122
James Ketrenosff0037b2005-10-03 10:23:42 -05001123static int ieee80211_parse_info_param(struct ieee80211_info_element
1124 *info_element, u16 length,
1125 struct ieee80211_network *network)
James Ketrenos9e8571a2005-09-21 11:56:33 -05001126{
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001127 u8 i;
1128#ifdef CONFIG_IEEE80211_DEBUG
1129 char rates_str[64];
1130 char *p;
1131#endif
James Ketrenos9e8571a2005-09-21 11:56:33 -05001132
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001133 while (length >= sizeof(*info_element)) {
1134 if (sizeof(*info_element) + info_element->len > length) {
Jiri Bencaec41a02006-10-18 19:34:40 +02001135 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1136 "info_element->len + 2 > left : "
1137 "info_element->len+2=%zd left=%d, id=%d.\n",
1138 info_element->len +
1139 sizeof(*info_element),
1140 length, info_element->id);
Zhu Yif09fc442006-08-21 11:34:19 +08001141 /* We stop processing but don't return an error here
1142 * because some misbehaviour APs break this rule. ie.
1143 * Orinoco AP1000. */
1144 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001145 }
1146
1147 switch (info_element->id) {
1148 case MFIE_TYPE_SSID:
John W. Linville7e272fc2008-09-24 18:13:14 -04001149 if (is_empty_ssid(info_element->data,
1150 info_element->len)) {
James Ketrenos9e8571a2005-09-21 11:56:33 -05001151 network->flags |= NETWORK_EMPTY_ESSID;
1152 break;
1153 }
1154
1155 network->ssid_len = min(info_element->len,
1156 (u8) IW_ESSID_MAX_SIZE);
1157 memcpy(network->ssid, info_element->data,
1158 network->ssid_len);
1159 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1160 memset(network->ssid + network->ssid_len, 0,
1161 IW_ESSID_MAX_SIZE - network->ssid_len);
1162
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001163 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
James Ketrenosff0037b2005-10-03 10:23:42 -05001164 network->ssid, network->ssid_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001165 break;
1166
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001167 case MFIE_TYPE_RATES:
1168#ifdef CONFIG_IEEE80211_DEBUG
1169 p = rates_str;
1170#endif
1171 network->rates_len = min(info_element->len,
1172 MAX_RATES_LENGTH);
1173 for (i = 0; i < network->rates_len; i++) {
1174 network->rates[i] = info_element->data[i];
1175#ifdef CONFIG_IEEE80211_DEBUG
1176 p += snprintf(p, sizeof(rates_str) -
1177 (p - rates_str), "%02X ",
1178 network->rates[i]);
1179#endif
1180 if (ieee80211_is_ofdm_rate
1181 (info_element->data[i])) {
1182 network->flags |= NETWORK_HAS_OFDM;
1183 if (info_element->data[i] &
1184 IEEE80211_BASIC_RATE_MASK)
1185 network->flags &=
1186 ~NETWORK_HAS_CCK;
1187 }
1188 }
1189
1190 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1191 rates_str, network->rates_len);
1192 break;
1193
1194 case MFIE_TYPE_RATES_EX:
1195#ifdef CONFIG_IEEE80211_DEBUG
1196 p = rates_str;
1197#endif
1198 network->rates_ex_len = min(info_element->len,
1199 MAX_RATES_EX_LENGTH);
1200 for (i = 0; i < network->rates_ex_len; i++) {
1201 network->rates_ex[i] = info_element->data[i];
1202#ifdef CONFIG_IEEE80211_DEBUG
1203 p += snprintf(p, sizeof(rates_str) -
1204 (p - rates_str), "%02X ",
1205 network->rates[i]);
1206#endif
1207 if (ieee80211_is_ofdm_rate
1208 (info_element->data[i])) {
1209 network->flags |= NETWORK_HAS_OFDM;
1210 if (info_element->data[i] &
1211 IEEE80211_BASIC_RATE_MASK)
1212 network->flags &=
1213 ~NETWORK_HAS_CCK;
1214 }
1215 }
1216
1217 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1218 rates_str, network->rates_ex_len);
1219 break;
1220
1221 case MFIE_TYPE_DS_SET:
1222 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1223 info_element->data[0]);
1224 network->channel = info_element->data[0];
1225 break;
1226
1227 case MFIE_TYPE_FH_SET:
1228 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1229 break;
1230
1231 case MFIE_TYPE_CF_SET:
1232 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1233 break;
1234
James Ketrenos9e8571a2005-09-21 11:56:33 -05001235 case MFIE_TYPE_TIM:
Zhu Yi41a25c62006-01-19 16:22:23 +08001236 network->tim.tim_count = info_element->data[0];
1237 network->tim.tim_period = info_element->data[1];
1238 IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001239 break;
1240
1241 case MFIE_TYPE_ERP_INFO:
1242 network->erp_value = info_element->data[0];
Daniel Draked8e2be92006-07-18 21:30:34 +01001243 network->flags |= NETWORK_HAS_ERP_VALUE;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001244 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1245 network->erp_value);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001246 break;
1247
1248 case MFIE_TYPE_IBSS_SET:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001249 network->atim_window = info_element->data[0];
1250 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1251 network->atim_window);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001252 break;
1253
1254 case MFIE_TYPE_CHALLENGE:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001255 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001256 break;
1257
1258 case MFIE_TYPE_GENERIC:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001259 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1260 info_element->len);
1261 if (!ieee80211_parse_qos_info_param_IE(info_element,
1262 network))
1263 break;
1264
1265 if (info_element->len >= 4 &&
1266 info_element->data[0] == 0x00 &&
1267 info_element->data[1] == 0x50 &&
1268 info_element->data[2] == 0xf2 &&
1269 info_element->data[3] == 0x01) {
1270 network->wpa_ie_len = min(info_element->len + 2,
1271 MAX_WPA_IE_LEN);
1272 memcpy(network->wpa_ie, info_element,
1273 network->wpa_ie_len);
1274 }
James Ketrenos9e8571a2005-09-21 11:56:33 -05001275 break;
1276
1277 case MFIE_TYPE_RSN:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001278 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1279 info_element->len);
1280 network->rsn_ie_len = min(info_element->len + 2,
1281 MAX_WPA_IE_LEN);
1282 memcpy(network->rsn_ie, info_element,
1283 network->rsn_ie_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001284 break;
1285
1286 case MFIE_TYPE_QOS_PARAMETER:
James Ketrenosff0037b2005-10-03 10:23:42 -05001287 printk(KERN_ERR
1288 "QoS Error need to parse QOS_PARAMETER IE\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001289 break;
Zhu Yid1b46b02006-01-19 16:22:15 +08001290 /* 802.11h */
1291 case MFIE_TYPE_POWER_CONSTRAINT:
1292 network->power_constraint = info_element->data[0];
1293 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
1294 break;
1295
1296 case MFIE_TYPE_CSA:
1297 network->power_constraint = info_element->data[0];
1298 network->flags |= NETWORK_HAS_CSA;
1299 break;
1300
1301 case MFIE_TYPE_QUIET:
1302 network->quiet.count = info_element->data[0];
1303 network->quiet.period = info_element->data[1];
1304 network->quiet.duration = info_element->data[2];
1305 network->quiet.offset = info_element->data[3];
1306 network->flags |= NETWORK_HAS_QUIET;
1307 break;
1308
1309 case MFIE_TYPE_IBSS_DFS:
1310 if (network->ibss_dfs)
1311 break;
Arnaldo Carvalho de Melo571d6ee2006-11-21 01:26:49 -02001312 network->ibss_dfs = kmemdup(info_element->data,
1313 info_element->len,
1314 GFP_ATOMIC);
Zhu Yid1b46b02006-01-19 16:22:15 +08001315 if (!network->ibss_dfs)
1316 return 1;
Zhu Yid1b46b02006-01-19 16:22:15 +08001317 network->flags |= NETWORK_HAS_IBSS_DFS;
1318 break;
1319
1320 case MFIE_TYPE_TPC_REPORT:
1321 network->tpc_report.transmit_power =
1322 info_element->data[0];
1323 network->tpc_report.link_margin = info_element->data[1];
1324 network->flags |= NETWORK_HAS_TPC_REPORT;
1325 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001326
1327 default:
Zhu Yid1b46b02006-01-19 16:22:15 +08001328 IEEE80211_DEBUG_MGMT
1329 ("Unsupported info element: %s (%d)\n",
1330 get_info_element_string(info_element->id),
1331 info_element->id);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001332 break;
1333 }
1334
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001335 length -= sizeof(*info_element) + info_element->len;
James Ketrenosff0037b2005-10-03 10:23:42 -05001336 info_element =
1337 (struct ieee80211_info_element *)&info_element->
1338 data[info_element->len];
James Ketrenos9e8571a2005-09-21 11:56:33 -05001339 }
1340
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001341 return 0;
1342}
1343
1344static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
1345 *frame, struct ieee80211_rx_stats *stats)
1346{
Zhu Yid1b46b02006-01-19 16:22:15 +08001347 struct ieee80211_network network_resp = {
1348 .ibss_dfs = NULL,
1349 };
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001350 struct ieee80211_network *network = &network_resp;
1351 struct net_device *dev = ieee->dev;
1352
1353 network->flags = 0;
1354 network->qos_data.active = 0;
1355 network->qos_data.supported = 0;
1356 network->qos_data.param_count = 0;
1357 network->qos_data.old_param_count = 0;
1358
1359 //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1360 network->atim_window = le16_to_cpu(frame->aid);
1361 network->listen_interval = le16_to_cpu(frame->status);
Ivo van Doornc1bda442005-10-03 10:20:47 -05001362 memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
1363 network->capability = le16_to_cpu(frame->capability);
1364 network->last_scanned = jiffies;
1365 network->rates_len = network->rates_ex_len = 0;
1366 network->last_associate = 0;
1367 network->ssid_len = 0;
James Ketrenosff0037b2005-10-03 10:23:42 -05001368 network->erp_value =
1369 (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001370
1371 if (stats->freq == IEEE80211_52GHZ_BAND) {
1372 /* for A band (No DS info) */
1373 network->channel = stats->received_channel;
1374 } else
1375 network->flags |= NETWORK_HAS_CCK;
1376
1377 network->wpa_ie_len = 0;
1378 network->rsn_ie_len = 0;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001379
James Ketrenosff0037b2005-10-03 10:23:42 -05001380 if (ieee80211_parse_info_param
1381 (frame->info_element, stats->len - sizeof(*frame), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001382 return 1;
1383
Ivo van Doornc1bda442005-10-03 10:20:47 -05001384 network->mode = 0;
1385 if (stats->freq == IEEE80211_52GHZ_BAND)
1386 network->mode = IEEE_A;
1387 else {
1388 if (network->flags & NETWORK_HAS_OFDM)
1389 network->mode |= IEEE_G;
1390 if (network->flags & NETWORK_HAS_CCK)
1391 network->mode |= IEEE_B;
1392 }
1393
John W. Linville7e272fc2008-09-24 18:13:14 -04001394 if (is_empty_ssid(network->ssid, network->ssid_len))
Ivo van Doornc1bda442005-10-03 10:20:47 -05001395 network->flags |= NETWORK_EMPTY_ESSID;
1396
1397 memcpy(&network->stats, stats, sizeof(network->stats));
1398
James Ketrenos9e8571a2005-09-21 11:56:33 -05001399 if (ieee->handle_assoc_response != NULL)
1400 ieee->handle_assoc_response(dev, frame, network);
1401
1402 return 0;
1403}
1404
1405/***************************************************/
1406
Arjan van de Ven858119e2006-01-14 13:20:43 -08001407static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001408 *beacon,
1409 struct ieee80211_network *network,
1410 struct ieee80211_rx_stats *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001411{
James Ketrenos9e8571a2005-09-21 11:56:33 -05001412 network->qos_data.active = 0;
1413 network->qos_data.supported = 0;
1414 network->qos_data.param_count = 0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001415 network->qos_data.old_param_count = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001416
1417 /* Pull out fixed field data */
1418 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
James Ketrenosfd278172005-09-13 17:25:51 -05001419 network->capability = le16_to_cpu(beacon->capability);
Jeff Garzikb4538722005-05-12 22:48:20 -04001420 network->last_scanned = jiffies;
James Ketrenosfd278172005-09-13 17:25:51 -05001421 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
1422 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
1423 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001424 /* Where to pull this? beacon->listen_interval; */
Jeff Garzikb4538722005-05-12 22:48:20 -04001425 network->listen_interval = 0x0A;
1426 network->rates_len = network->rates_ex_len = 0;
1427 network->last_associate = 0;
1428 network->ssid_len = 0;
1429 network->flags = 0;
1430 network->atim_window = 0;
James Ketrenos42c94e42005-09-21 11:58:29 -05001431 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
James Ketrenosccd0fda2005-09-21 11:58:32 -05001432 0x3 : 0x0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001433
1434 if (stats->freq == IEEE80211_52GHZ_BAND) {
1435 /* for A band (No DS info) */
1436 network->channel = stats->received_channel;
1437 } else
1438 network->flags |= NETWORK_HAS_CCK;
1439
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001440 network->wpa_ie_len = 0;
1441 network->rsn_ie_len = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001442
James Ketrenosff0037b2005-10-03 10:23:42 -05001443 if (ieee80211_parse_info_param
1444 (beacon->info_element, stats->len - sizeof(*beacon), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001445 return 1;
Jeff Garzikb4538722005-05-12 22:48:20 -04001446
1447 network->mode = 0;
1448 if (stats->freq == IEEE80211_52GHZ_BAND)
1449 network->mode = IEEE_A;
1450 else {
1451 if (network->flags & NETWORK_HAS_OFDM)
1452 network->mode |= IEEE_G;
1453 if (network->flags & NETWORK_HAS_CCK)
1454 network->mode |= IEEE_B;
1455 }
1456
1457 if (network->mode == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07001458 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
Jeff Garzikb4538722005-05-12 22:48:20 -04001459 "network.\n",
John W. Linville7e272fc2008-09-24 18:13:14 -04001460 escape_ssid(network->ssid,
1461 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001462 network->bssid);
Jeff Garzikb4538722005-05-12 22:48:20 -04001463 return 1;
1464 }
1465
John W. Linville7e272fc2008-09-24 18:13:14 -04001466 if (is_empty_ssid(network->ssid, network->ssid_len))
Jeff Garzikb4538722005-05-12 22:48:20 -04001467 network->flags |= NETWORK_EMPTY_ESSID;
1468
1469 memcpy(&network->stats, stats, sizeof(network->stats));
1470
1471 return 0;
1472}
1473
1474static inline int is_same_network(struct ieee80211_network *src,
1475 struct ieee80211_network *dst)
1476{
1477 /* A network is only a duplicate if the channel, BSSID, and ESSID
1478 * all match. We treat all <hidden> with the same BSSID and channel
1479 * as one network */
1480 return ((src->ssid_len == dst->ssid_len) &&
1481 (src->channel == dst->channel) &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -08001482 !compare_ether_addr(src->bssid, dst->bssid) &&
Jeff Garzikb4538722005-05-12 22:48:20 -04001483 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1484}
1485
Arjan van de Ven858119e2006-01-14 13:20:43 -08001486static void update_network(struct ieee80211_network *dst,
Jeff Garzikb4538722005-05-12 22:48:20 -04001487 struct ieee80211_network *src)
1488{
James Ketrenos9e8571a2005-09-21 11:56:33 -05001489 int qos_active;
1490 u8 old_param;
1491
Zhu Yid1b46b02006-01-19 16:22:15 +08001492 ieee80211_network_reset(dst);
1493 dst->ibss_dfs = src->ibss_dfs;
1494
James Ketrenosf44349f2006-03-08 13:14:45 -06001495 /* We only update the statistics if they were created by receiving
1496 * the network information on the actual channel the network is on.
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +09001497 *
James Ketrenosf44349f2006-03-08 13:14:45 -06001498 * This keeps beacons received on neighbor channels from bringing
1499 * down the signal level of an AP. */
1500 if (dst->channel == src->stats.received_channel)
1501 memcpy(&dst->stats, &src->stats,
1502 sizeof(struct ieee80211_rx_stats));
1503 else
Johannes Berge1749612008-10-27 15:59:26 -07001504 IEEE80211_DEBUG_SCAN("Network %pM info received "
1505 "off channel (%d vs. %d)\n", src->bssid,
James Ketrenosf44349f2006-03-08 13:14:45 -06001506 dst->channel, src->stats.received_channel);
1507
Jeff Garzikb4538722005-05-12 22:48:20 -04001508 dst->capability = src->capability;
1509 memcpy(dst->rates, src->rates, src->rates_len);
1510 dst->rates_len = src->rates_len;
1511 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1512 dst->rates_ex_len = src->rates_ex_len;
1513
1514 dst->mode = src->mode;
1515 dst->flags = src->flags;
1516 dst->time_stamp[0] = src->time_stamp[0];
1517 dst->time_stamp[1] = src->time_stamp[1];
1518
1519 dst->beacon_interval = src->beacon_interval;
1520 dst->listen_interval = src->listen_interval;
1521 dst->atim_window = src->atim_window;
James Ketrenos42c94e42005-09-21 11:58:29 -05001522 dst->erp_value = src->erp_value;
Zhu Yi41a25c62006-01-19 16:22:23 +08001523 dst->tim = src->tim;
Jeff Garzikb4538722005-05-12 22:48:20 -04001524
1525 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1526 dst->wpa_ie_len = src->wpa_ie_len;
1527 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1528 dst->rsn_ie_len = src->rsn_ie_len;
1529
1530 dst->last_scanned = jiffies;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001531 qos_active = src->qos_data.active;
1532 old_param = dst->qos_data.old_param_count;
1533 if (dst->flags & NETWORK_HAS_QOS_MASK)
1534 memcpy(&dst->qos_data, &src->qos_data,
1535 sizeof(struct ieee80211_qos_data));
1536 else {
1537 dst->qos_data.supported = src->qos_data.supported;
1538 dst->qos_data.param_count = src->qos_data.param_count;
1539 }
1540
1541 if (dst->qos_data.supported == 1) {
1542 if (dst->ssid_len)
1543 IEEE80211_DEBUG_QOS
1544 ("QoS the network %s is QoS supported\n",
1545 dst->ssid);
1546 else
1547 IEEE80211_DEBUG_QOS
1548 ("QoS the network is QoS supported\n");
1549 }
1550 dst->qos_data.active = qos_active;
1551 dst->qos_data.old_param_count = old_param;
1552
Jeff Garzikb4538722005-05-12 22:48:20 -04001553 /* dst->last_associate is not overwritten */
1554}
1555
Pete Zaitcev48328432006-02-26 23:43:20 -08001556static inline int is_beacon(__le16 fc)
James Ketrenos3f552bb2005-09-21 11:54:47 -05001557{
1558 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
1559}
1560
Arjan van de Ven858119e2006-01-14 13:20:43 -08001561static void ieee80211_process_probe_response(struct ieee80211_device
James Ketrenos74079fd2005-09-13 17:35:21 -05001562 *ieee, struct
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001563 ieee80211_probe_response
James Ketrenos74079fd2005-09-13 17:35:21 -05001564 *beacon, struct ieee80211_rx_stats
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001565 *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001566{
James Ketrenos3f552bb2005-09-21 11:54:47 -05001567 struct net_device *dev = ieee->dev;
Zhu Yid1b46b02006-01-19 16:22:15 +08001568 struct ieee80211_network network = {
1569 .ibss_dfs = NULL,
1570 };
Jeff Garzikb4538722005-05-12 22:48:20 -04001571 struct ieee80211_network *target;
1572 struct ieee80211_network *oldest = NULL;
1573#ifdef CONFIG_IEEE80211_DEBUG
James Ketrenos68e4e032005-09-13 17:37:22 -05001574 struct ieee80211_info_element *info_element = beacon->info_element;
Jeff Garzikb4538722005-05-12 22:48:20 -04001575#endif
1576 unsigned long flags;
1577
Johannes Berge1749612008-10-27 15:59:26 -07001578 IEEE80211_DEBUG_SCAN("'%s' (%pM"
Al Viro8524f592007-12-29 05:03:35 -05001579 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
John W. Linville7e272fc2008-09-24 18:13:14 -04001580 escape_ssid(info_element->data, info_element->len),
Johannes Berge1749612008-10-27 15:59:26 -07001581 beacon->header.addr3,
Al Viro8524f592007-12-29 05:03:35 -05001582 (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
1583 (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
1584 (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
1585 (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
1586 (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
1587 (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
1588 (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
1589 (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
1590 (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
1591 (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
1592 (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
1593 (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
1594 (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
1595 (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
1596 (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
1597 (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
Jeff Garzikb4538722005-05-12 22:48:20 -04001598
1599 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
Johannes Berge1749612008-10-27 15:59:26 -07001600 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
John W. Linville7e272fc2008-09-24 18:13:14 -04001601 escape_ssid(info_element->data,
1602 info_element->len),
Johannes Berge1749612008-10-27 15:59:26 -07001603 beacon->header.addr3,
Pete Zaitcev48328432006-02-26 23:43:20 -08001604 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bb2005-09-21 11:54:47 -05001605 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001606 return;
1607 }
1608
1609 /* The network parsed correctly -- so now we scan our known networks
1610 * to see if we can find it in our list.
1611 *
1612 * NOTE: This search is definitely not optimized. Once its doing
1613 * the "right thing" we'll optimize it for efficiency if
1614 * necessary */
1615
1616 /* Search for this entry in the list and update it if it is
1617 * already there. */
1618
1619 spin_lock_irqsave(&ieee->lock, flags);
1620
1621 list_for_each_entry(target, &ieee->network_list, list) {
1622 if (is_same_network(target, &network))
1623 break;
1624
1625 if ((oldest == NULL) ||
1626 (target->last_scanned < oldest->last_scanned))
1627 oldest = target;
1628 }
1629
1630 /* If we didn't find a match, then get a new network slot to initialize
1631 * with this beacon's information */
1632 if (&target->list == &ieee->network_list) {
1633 if (list_empty(&ieee->network_free_list)) {
1634 /* If there are no more slots, expire the oldest */
1635 list_del(&oldest->list);
1636 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07001637 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
Jeff Garzikb4538722005-05-12 22:48:20 -04001638 "network list.\n",
John W. Linville7e272fc2008-09-24 18:13:14 -04001639 escape_ssid(target->ssid,
1640 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001641 target->bssid);
Zhu Yid1b46b02006-01-19 16:22:15 +08001642 ieee80211_network_reset(target);
Jeff Garzikb4538722005-05-12 22:48:20 -04001643 } else {
1644 /* Otherwise just pull from the free list */
1645 target = list_entry(ieee->network_free_list.next,
1646 struct ieee80211_network, list);
1647 list_del(ieee->network_free_list.next);
1648 }
1649
Jeff Garzikb4538722005-05-12 22:48:20 -04001650#ifdef CONFIG_IEEE80211_DEBUG
Johannes Berge1749612008-10-27 15:59:26 -07001651 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
John W. Linville7e272fc2008-09-24 18:13:14 -04001652 escape_ssid(network.ssid,
1653 network.ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001654 network.bssid,
Pete Zaitcev48328432006-02-26 23:43:20 -08001655 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bb2005-09-21 11:54:47 -05001656 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001657#endif
1658 memcpy(target, &network, sizeof(*target));
Zhu Yid1b46b02006-01-19 16:22:15 +08001659 network.ibss_dfs = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -04001660 list_add_tail(&target->list, &ieee->network_list);
1661 } else {
Johannes Berge1749612008-10-27 15:59:26 -07001662 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
John W. Linville7e272fc2008-09-24 18:13:14 -04001663 escape_ssid(target->ssid,
1664 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001665 target->bssid,
Pete Zaitcev48328432006-02-26 23:43:20 -08001666 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bb2005-09-21 11:54:47 -05001667 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001668 update_network(target, &network);
Zhu Yid1b46b02006-01-19 16:22:15 +08001669 network.ibss_dfs = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -04001670 }
1671
1672 spin_unlock_irqrestore(&ieee->lock, flags);
James Ketrenos3f552bb2005-09-21 11:54:47 -05001673
Pete Zaitcev48328432006-02-26 23:43:20 -08001674 if (is_beacon(beacon->header.frame_ctl)) {
James Ketrenos3f552bb2005-09-21 11:54:47 -05001675 if (ieee->handle_beacon != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001676 ieee->handle_beacon(dev, beacon, target);
James Ketrenos3f552bb2005-09-21 11:54:47 -05001677 } else {
1678 if (ieee->handle_probe_response != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001679 ieee->handle_probe_response(dev, beacon, target);
James Ketrenos3f552bb2005-09-21 11:54:47 -05001680 }
Jeff Garzikb4538722005-05-12 22:48:20 -04001681}
1682
1683void ieee80211_rx_mgt(struct ieee80211_device *ieee,
James Ketrenosee34af32005-09-21 11:54:36 -05001684 struct ieee80211_hdr_4addr *header,
Jeff Garzikb4538722005-05-12 22:48:20 -04001685 struct ieee80211_rx_stats *stats)
1686{
James Ketrenosfd278172005-09-13 17:25:51 -05001687 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
Jeff Garzikb4538722005-05-12 22:48:20 -04001688 case IEEE80211_STYPE_ASSOC_RESP:
1689 IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001690 WLAN_FC_GET_STYPE(le16_to_cpu
1691 (header->frame_ctl)));
James Ketrenos9e8571a2005-09-21 11:56:33 -05001692 ieee80211_handle_assoc_resp(ieee,
1693 (struct ieee80211_assoc_response *)
1694 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001695 break;
1696
1697 case IEEE80211_STYPE_REASSOC_RESP:
1698 IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001699 WLAN_FC_GET_STYPE(le16_to_cpu
1700 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001701 break;
1702
James Ketrenos42c94e42005-09-21 11:58:29 -05001703 case IEEE80211_STYPE_PROBE_REQ:
Larry Finger1a1fedf2006-01-30 09:42:24 -06001704 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos42c94e42005-09-21 11:58:29 -05001705 WLAN_FC_GET_STYPE(le16_to_cpu
1706 (header->frame_ctl)));
1707
1708 if (ieee->handle_probe_request != NULL)
1709 ieee->handle_probe_request(ieee->dev,
1710 (struct
1711 ieee80211_probe_request *)
1712 header, stats);
1713 break;
1714
Jeff Garzikb4538722005-05-12 22:48:20 -04001715 case IEEE80211_STYPE_PROBE_RESP:
1716 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001717 WLAN_FC_GET_STYPE(le16_to_cpu
1718 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001719 IEEE80211_DEBUG_SCAN("Probe response\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001720 ieee80211_process_probe_response(ieee,
1721 (struct
1722 ieee80211_probe_response *)
1723 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001724 break;
1725
1726 case IEEE80211_STYPE_BEACON:
1727 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001728 WLAN_FC_GET_STYPE(le16_to_cpu
1729 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001730 IEEE80211_DEBUG_SCAN("Beacon\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001731 ieee80211_process_probe_response(ieee,
1732 (struct
1733 ieee80211_probe_response *)
1734 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001735 break;
James Ketrenos3f552bb2005-09-21 11:54:47 -05001736 case IEEE80211_STYPE_AUTH:
1737
Larry Finger1a1fedf2006-01-30 09:42:24 -06001738 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos3f552bb2005-09-21 11:54:47 -05001739 WLAN_FC_GET_STYPE(le16_to_cpu
1740 (header->frame_ctl)));
1741
1742 if (ieee->handle_auth != NULL)
1743 ieee->handle_auth(ieee->dev,
1744 (struct ieee80211_auth *)header);
1745 break;
1746
1747 case IEEE80211_STYPE_DISASSOC:
1748 if (ieee->handle_disassoc != NULL)
1749 ieee->handle_disassoc(ieee->dev,
1750 (struct ieee80211_disassoc *)
1751 header);
1752 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001753
Zhu Yid1b46b02006-01-19 16:22:15 +08001754 case IEEE80211_STYPE_ACTION:
1755 IEEE80211_DEBUG_MGMT("ACTION\n");
1756 if (ieee->handle_action)
1757 ieee->handle_action(ieee->dev,
1758 (struct ieee80211_action *)
1759 header, stats);
1760 break;
1761
Larry Finger2f633db2006-01-30 23:25:10 -06001762 case IEEE80211_STYPE_REASSOC_REQ:
1763 IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
1764 WLAN_FC_GET_STYPE(le16_to_cpu
1765 (header->frame_ctl)));
1766
Zhu Yi7736b5b2006-04-13 17:17:47 +08001767 IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
1768 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001769 if (ieee->handle_reassoc_request != NULL)
1770 ieee->handle_reassoc_request(ieee->dev,
1771 (struct ieee80211_reassoc_request *)
1772 header);
1773 break;
1774
1775 case IEEE80211_STYPE_ASSOC_REQ:
1776 IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
1777 WLAN_FC_GET_STYPE(le16_to_cpu
1778 (header->frame_ctl)));
1779
Zhu Yi7736b5b2006-04-13 17:17:47 +08001780 IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
1781 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001782 if (ieee->handle_assoc_request != NULL)
1783 ieee->handle_assoc_request(ieee->dev);
1784 break;
1785
James Ketrenos31b59ea2005-09-21 11:58:49 -05001786 case IEEE80211_STYPE_DEAUTH:
Zhu Yid1b46b02006-01-19 16:22:15 +08001787 IEEE80211_DEBUG_MGMT("DEAUTH\n");
James Ketrenos31b59ea2005-09-21 11:58:49 -05001788 if (ieee->handle_deauth != NULL)
Zhu Yid1b46b02006-01-19 16:22:15 +08001789 ieee->handle_deauth(ieee->dev,
1790 (struct ieee80211_deauth *)
James Ketrenos31b59ea2005-09-21 11:58:49 -05001791 header);
1792 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001793 default:
1794 IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001795 WLAN_FC_GET_STYPE(le16_to_cpu
1796 (header->frame_ctl)));
Zhu Yi7736b5b2006-04-13 17:17:47 +08001797 IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1798 ieee->dev->name,
1799 WLAN_FC_GET_STYPE(le16_to_cpu
1800 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001801 break;
1802 }
1803}
1804
Daniel Drakef2060f032006-07-18 21:38:05 +01001805EXPORT_SYMBOL_GPL(ieee80211_rx_any);
Jeff Garzikb4538722005-05-12 22:48:20 -04001806EXPORT_SYMBOL(ieee80211_rx_mgt);
1807EXPORT_SYMBOL(ieee80211_rx);