blob: a91ef8475467f072d7942c11d21af7741502e974 [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;
John W. Linville72118012008-09-30 21:43:03 -040043 u16 fc = le16_to_cpu(hdr->frame_control);
Jeff Garzikb4538722005-05-12 22:48:20 -040044
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{
John W. Linville9387b7c2008-09-30 20:59:05 -04001127 DECLARE_SSID_BUF(ssid);
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001128 u8 i;
1129#ifdef CONFIG_IEEE80211_DEBUG
1130 char rates_str[64];
1131 char *p;
1132#endif
James Ketrenos9e8571a2005-09-21 11:56:33 -05001133
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001134 while (length >= sizeof(*info_element)) {
1135 if (sizeof(*info_element) + info_element->len > length) {
Jiri Bencaec41a02006-10-18 19:34:40 +02001136 IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
1137 "info_element->len + 2 > left : "
1138 "info_element->len+2=%zd left=%d, id=%d.\n",
1139 info_element->len +
1140 sizeof(*info_element),
1141 length, info_element->id);
Zhu Yif09fc442006-08-21 11:34:19 +08001142 /* We stop processing but don't return an error here
1143 * because some misbehaviour APs break this rule. ie.
1144 * Orinoco AP1000. */
1145 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001146 }
1147
1148 switch (info_element->id) {
1149 case MFIE_TYPE_SSID:
James Ketrenos9e8571a2005-09-21 11:56:33 -05001150 network->ssid_len = min(info_element->len,
1151 (u8) IW_ESSID_MAX_SIZE);
1152 memcpy(network->ssid, info_element->data,
1153 network->ssid_len);
1154 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1155 memset(network->ssid + network->ssid_len, 0,
1156 IW_ESSID_MAX_SIZE - network->ssid_len);
1157
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001158 IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001159 print_ssid(ssid, network->ssid,
1160 network->ssid_len),
John W. Linvillec5d3dce2008-09-30 17:17:26 -04001161 network->ssid_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001162 break;
1163
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001164 case MFIE_TYPE_RATES:
1165#ifdef CONFIG_IEEE80211_DEBUG
1166 p = rates_str;
1167#endif
1168 network->rates_len = min(info_element->len,
1169 MAX_RATES_LENGTH);
1170 for (i = 0; i < network->rates_len; i++) {
1171 network->rates[i] = info_element->data[i];
1172#ifdef CONFIG_IEEE80211_DEBUG
1173 p += snprintf(p, sizeof(rates_str) -
1174 (p - rates_str), "%02X ",
1175 network->rates[i]);
1176#endif
1177 if (ieee80211_is_ofdm_rate
1178 (info_element->data[i])) {
1179 network->flags |= NETWORK_HAS_OFDM;
1180 if (info_element->data[i] &
1181 IEEE80211_BASIC_RATE_MASK)
1182 network->flags &=
1183 ~NETWORK_HAS_CCK;
1184 }
1185 }
1186
1187 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
1188 rates_str, network->rates_len);
1189 break;
1190
1191 case MFIE_TYPE_RATES_EX:
1192#ifdef CONFIG_IEEE80211_DEBUG
1193 p = rates_str;
1194#endif
1195 network->rates_ex_len = min(info_element->len,
1196 MAX_RATES_EX_LENGTH);
1197 for (i = 0; i < network->rates_ex_len; i++) {
1198 network->rates_ex[i] = info_element->data[i];
1199#ifdef CONFIG_IEEE80211_DEBUG
1200 p += snprintf(p, sizeof(rates_str) -
1201 (p - rates_str), "%02X ",
1202 network->rates[i]);
1203#endif
1204 if (ieee80211_is_ofdm_rate
1205 (info_element->data[i])) {
1206 network->flags |= NETWORK_HAS_OFDM;
1207 if (info_element->data[i] &
1208 IEEE80211_BASIC_RATE_MASK)
1209 network->flags &=
1210 ~NETWORK_HAS_CCK;
1211 }
1212 }
1213
1214 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
1215 rates_str, network->rates_ex_len);
1216 break;
1217
1218 case MFIE_TYPE_DS_SET:
1219 IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
1220 info_element->data[0]);
1221 network->channel = info_element->data[0];
1222 break;
1223
1224 case MFIE_TYPE_FH_SET:
1225 IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
1226 break;
1227
1228 case MFIE_TYPE_CF_SET:
1229 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
1230 break;
1231
James Ketrenos9e8571a2005-09-21 11:56:33 -05001232 case MFIE_TYPE_TIM:
Zhu Yi41a25c62006-01-19 16:22:23 +08001233 network->tim.tim_count = info_element->data[0];
1234 network->tim.tim_period = info_element->data[1];
1235 IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001236 break;
1237
1238 case MFIE_TYPE_ERP_INFO:
1239 network->erp_value = info_element->data[0];
Daniel Draked8e2be92006-07-18 21:30:34 +01001240 network->flags |= NETWORK_HAS_ERP_VALUE;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001241 IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
1242 network->erp_value);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001243 break;
1244
1245 case MFIE_TYPE_IBSS_SET:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001246 network->atim_window = info_element->data[0];
1247 IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
1248 network->atim_window);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001249 break;
1250
1251 case MFIE_TYPE_CHALLENGE:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001252 IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001253 break;
1254
1255 case MFIE_TYPE_GENERIC:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001256 IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
1257 info_element->len);
1258 if (!ieee80211_parse_qos_info_param_IE(info_element,
1259 network))
1260 break;
1261
1262 if (info_element->len >= 4 &&
1263 info_element->data[0] == 0x00 &&
1264 info_element->data[1] == 0x50 &&
1265 info_element->data[2] == 0xf2 &&
1266 info_element->data[3] == 0x01) {
1267 network->wpa_ie_len = min(info_element->len + 2,
1268 MAX_WPA_IE_LEN);
1269 memcpy(network->wpa_ie, info_element,
1270 network->wpa_ie_len);
1271 }
James Ketrenos9e8571a2005-09-21 11:56:33 -05001272 break;
1273
1274 case MFIE_TYPE_RSN:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001275 IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
1276 info_element->len);
1277 network->rsn_ie_len = min(info_element->len + 2,
1278 MAX_WPA_IE_LEN);
1279 memcpy(network->rsn_ie, info_element,
1280 network->rsn_ie_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001281 break;
1282
1283 case MFIE_TYPE_QOS_PARAMETER:
James Ketrenosff0037b2005-10-03 10:23:42 -05001284 printk(KERN_ERR
1285 "QoS Error need to parse QOS_PARAMETER IE\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001286 break;
Zhu Yid1b46b02006-01-19 16:22:15 +08001287 /* 802.11h */
1288 case MFIE_TYPE_POWER_CONSTRAINT:
1289 network->power_constraint = info_element->data[0];
1290 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
1291 break;
1292
1293 case MFIE_TYPE_CSA:
1294 network->power_constraint = info_element->data[0];
1295 network->flags |= NETWORK_HAS_CSA;
1296 break;
1297
1298 case MFIE_TYPE_QUIET:
1299 network->quiet.count = info_element->data[0];
1300 network->quiet.period = info_element->data[1];
1301 network->quiet.duration = info_element->data[2];
1302 network->quiet.offset = info_element->data[3];
1303 network->flags |= NETWORK_HAS_QUIET;
1304 break;
1305
1306 case MFIE_TYPE_IBSS_DFS:
1307 if (network->ibss_dfs)
1308 break;
Arnaldo Carvalho de Melo571d6ee2006-11-21 01:26:49 -02001309 network->ibss_dfs = kmemdup(info_element->data,
1310 info_element->len,
1311 GFP_ATOMIC);
Zhu Yid1b46b02006-01-19 16:22:15 +08001312 if (!network->ibss_dfs)
1313 return 1;
Zhu Yid1b46b02006-01-19 16:22:15 +08001314 network->flags |= NETWORK_HAS_IBSS_DFS;
1315 break;
1316
1317 case MFIE_TYPE_TPC_REPORT:
1318 network->tpc_report.transmit_power =
1319 info_element->data[0];
1320 network->tpc_report.link_margin = info_element->data[1];
1321 network->flags |= NETWORK_HAS_TPC_REPORT;
1322 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001323
1324 default:
Zhu Yid1b46b02006-01-19 16:22:15 +08001325 IEEE80211_DEBUG_MGMT
1326 ("Unsupported info element: %s (%d)\n",
1327 get_info_element_string(info_element->id),
1328 info_element->id);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001329 break;
1330 }
1331
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001332 length -= sizeof(*info_element) + info_element->len;
James Ketrenosff0037b2005-10-03 10:23:42 -05001333 info_element =
1334 (struct ieee80211_info_element *)&info_element->
1335 data[info_element->len];
James Ketrenos9e8571a2005-09-21 11:56:33 -05001336 }
1337
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001338 return 0;
1339}
1340
1341static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
1342 *frame, struct ieee80211_rx_stats *stats)
1343{
Zhu Yid1b46b02006-01-19 16:22:15 +08001344 struct ieee80211_network network_resp = {
1345 .ibss_dfs = NULL,
1346 };
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001347 struct ieee80211_network *network = &network_resp;
1348 struct net_device *dev = ieee->dev;
1349
1350 network->flags = 0;
1351 network->qos_data.active = 0;
1352 network->qos_data.supported = 0;
1353 network->qos_data.param_count = 0;
1354 network->qos_data.old_param_count = 0;
1355
1356 //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1357 network->atim_window = le16_to_cpu(frame->aid);
1358 network->listen_interval = le16_to_cpu(frame->status);
Ivo van Doornc1bda442005-10-03 10:20:47 -05001359 memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
1360 network->capability = le16_to_cpu(frame->capability);
1361 network->last_scanned = jiffies;
1362 network->rates_len = network->rates_ex_len = 0;
1363 network->last_associate = 0;
1364 network->ssid_len = 0;
James Ketrenosff0037b2005-10-03 10:23:42 -05001365 network->erp_value =
1366 (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001367
1368 if (stats->freq == IEEE80211_52GHZ_BAND) {
1369 /* for A band (No DS info) */
1370 network->channel = stats->received_channel;
1371 } else
1372 network->flags |= NETWORK_HAS_CCK;
1373
1374 network->wpa_ie_len = 0;
1375 network->rsn_ie_len = 0;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001376
James Ketrenosff0037b2005-10-03 10:23:42 -05001377 if (ieee80211_parse_info_param
1378 (frame->info_element, stats->len - sizeof(*frame), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001379 return 1;
1380
Ivo van Doornc1bda442005-10-03 10:20:47 -05001381 network->mode = 0;
1382 if (stats->freq == IEEE80211_52GHZ_BAND)
1383 network->mode = IEEE_A;
1384 else {
1385 if (network->flags & NETWORK_HAS_OFDM)
1386 network->mode |= IEEE_G;
1387 if (network->flags & NETWORK_HAS_CCK)
1388 network->mode |= IEEE_B;
1389 }
1390
Ivo van Doornc1bda442005-10-03 10:20:47 -05001391 memcpy(&network->stats, stats, sizeof(network->stats));
1392
James Ketrenos9e8571a2005-09-21 11:56:33 -05001393 if (ieee->handle_assoc_response != NULL)
1394 ieee->handle_assoc_response(dev, frame, network);
1395
1396 return 0;
1397}
1398
1399/***************************************************/
1400
Arjan van de Ven858119e2006-01-14 13:20:43 -08001401static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001402 *beacon,
1403 struct ieee80211_network *network,
1404 struct ieee80211_rx_stats *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001405{
John W. Linville9387b7c2008-09-30 20:59:05 -04001406 DECLARE_SSID_BUF(ssid);
1407
James Ketrenos9e8571a2005-09-21 11:56:33 -05001408 network->qos_data.active = 0;
1409 network->qos_data.supported = 0;
1410 network->qos_data.param_count = 0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001411 network->qos_data.old_param_count = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001412
1413 /* Pull out fixed field data */
1414 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
James Ketrenosfd278172005-09-13 17:25:51 -05001415 network->capability = le16_to_cpu(beacon->capability);
Jeff Garzikb4538722005-05-12 22:48:20 -04001416 network->last_scanned = jiffies;
James Ketrenosfd278172005-09-13 17:25:51 -05001417 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
1418 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
1419 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001420 /* Where to pull this? beacon->listen_interval; */
Jeff Garzikb4538722005-05-12 22:48:20 -04001421 network->listen_interval = 0x0A;
1422 network->rates_len = network->rates_ex_len = 0;
1423 network->last_associate = 0;
1424 network->ssid_len = 0;
1425 network->flags = 0;
1426 network->atim_window = 0;
James Ketrenos42c94e42005-09-21 11:58:29 -05001427 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
James Ketrenosccd0fda2005-09-21 11:58:32 -05001428 0x3 : 0x0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001429
1430 if (stats->freq == IEEE80211_52GHZ_BAND) {
1431 /* for A band (No DS info) */
1432 network->channel = stats->received_channel;
1433 } else
1434 network->flags |= NETWORK_HAS_CCK;
1435
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001436 network->wpa_ie_len = 0;
1437 network->rsn_ie_len = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001438
James Ketrenosff0037b2005-10-03 10:23:42 -05001439 if (ieee80211_parse_info_param
1440 (beacon->info_element, stats->len - sizeof(*beacon), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001441 return 1;
Jeff Garzikb4538722005-05-12 22:48:20 -04001442
1443 network->mode = 0;
1444 if (stats->freq == IEEE80211_52GHZ_BAND)
1445 network->mode = IEEE_A;
1446 else {
1447 if (network->flags & NETWORK_HAS_OFDM)
1448 network->mode |= IEEE_G;
1449 if (network->flags & NETWORK_HAS_CCK)
1450 network->mode |= IEEE_B;
1451 }
1452
1453 if (network->mode == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07001454 IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
Jeff Garzikb4538722005-05-12 22:48:20 -04001455 "network.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001456 print_ssid(ssid, network->ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001457 network->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001458 network->bssid);
Jeff Garzikb4538722005-05-12 22:48:20 -04001459 return 1;
1460 }
1461
Jeff Garzikb4538722005-05-12 22:48:20 -04001462 memcpy(&network->stats, stats, sizeof(network->stats));
1463
1464 return 0;
1465}
1466
1467static inline int is_same_network(struct ieee80211_network *src,
1468 struct ieee80211_network *dst)
1469{
1470 /* A network is only a duplicate if the channel, BSSID, and ESSID
1471 * all match. We treat all <hidden> with the same BSSID and channel
1472 * as one network */
1473 return ((src->ssid_len == dst->ssid_len) &&
1474 (src->channel == dst->channel) &&
Kris Katterjohnd3f4a682006-01-09 16:01:43 -08001475 !compare_ether_addr(src->bssid, dst->bssid) &&
Jeff Garzikb4538722005-05-12 22:48:20 -04001476 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1477}
1478
Arjan van de Ven858119e2006-01-14 13:20:43 -08001479static void update_network(struct ieee80211_network *dst,
Jeff Garzikb4538722005-05-12 22:48:20 -04001480 struct ieee80211_network *src)
1481{
James Ketrenos9e8571a2005-09-21 11:56:33 -05001482 int qos_active;
1483 u8 old_param;
1484
Zhu Yid1b46b02006-01-19 16:22:15 +08001485 ieee80211_network_reset(dst);
1486 dst->ibss_dfs = src->ibss_dfs;
1487
James Ketrenosf44349f2006-03-08 13:14:45 -06001488 /* We only update the statistics if they were created by receiving
1489 * the network information on the actual channel the network is on.
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +09001490 *
James Ketrenosf44349f2006-03-08 13:14:45 -06001491 * This keeps beacons received on neighbor channels from bringing
1492 * down the signal level of an AP. */
1493 if (dst->channel == src->stats.received_channel)
1494 memcpy(&dst->stats, &src->stats,
1495 sizeof(struct ieee80211_rx_stats));
1496 else
Johannes Berge1749612008-10-27 15:59:26 -07001497 IEEE80211_DEBUG_SCAN("Network %pM info received "
1498 "off channel (%d vs. %d)\n", src->bssid,
James Ketrenosf44349f2006-03-08 13:14:45 -06001499 dst->channel, src->stats.received_channel);
1500
Jeff Garzikb4538722005-05-12 22:48:20 -04001501 dst->capability = src->capability;
1502 memcpy(dst->rates, src->rates, src->rates_len);
1503 dst->rates_len = src->rates_len;
1504 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1505 dst->rates_ex_len = src->rates_ex_len;
1506
1507 dst->mode = src->mode;
1508 dst->flags = src->flags;
1509 dst->time_stamp[0] = src->time_stamp[0];
1510 dst->time_stamp[1] = src->time_stamp[1];
1511
1512 dst->beacon_interval = src->beacon_interval;
1513 dst->listen_interval = src->listen_interval;
1514 dst->atim_window = src->atim_window;
James Ketrenos42c94e42005-09-21 11:58:29 -05001515 dst->erp_value = src->erp_value;
Zhu Yi41a25c62006-01-19 16:22:23 +08001516 dst->tim = src->tim;
Jeff Garzikb4538722005-05-12 22:48:20 -04001517
1518 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1519 dst->wpa_ie_len = src->wpa_ie_len;
1520 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1521 dst->rsn_ie_len = src->rsn_ie_len;
1522
1523 dst->last_scanned = jiffies;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001524 qos_active = src->qos_data.active;
1525 old_param = dst->qos_data.old_param_count;
1526 if (dst->flags & NETWORK_HAS_QOS_MASK)
1527 memcpy(&dst->qos_data, &src->qos_data,
1528 sizeof(struct ieee80211_qos_data));
1529 else {
1530 dst->qos_data.supported = src->qos_data.supported;
1531 dst->qos_data.param_count = src->qos_data.param_count;
1532 }
1533
1534 if (dst->qos_data.supported == 1) {
1535 if (dst->ssid_len)
1536 IEEE80211_DEBUG_QOS
1537 ("QoS the network %s is QoS supported\n",
1538 dst->ssid);
1539 else
1540 IEEE80211_DEBUG_QOS
1541 ("QoS the network is QoS supported\n");
1542 }
1543 dst->qos_data.active = qos_active;
1544 dst->qos_data.old_param_count = old_param;
1545
Jeff Garzikb4538722005-05-12 22:48:20 -04001546 /* dst->last_associate is not overwritten */
1547}
1548
Pete Zaitcev48328432006-02-26 23:43:20 -08001549static inline int is_beacon(__le16 fc)
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001550{
1551 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
1552}
1553
Arjan van de Ven858119e2006-01-14 13:20:43 -08001554static void ieee80211_process_probe_response(struct ieee80211_device
James Ketrenos74079fd2005-09-13 17:35:21 -05001555 *ieee, struct
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001556 ieee80211_probe_response
James Ketrenos74079fd2005-09-13 17:35:21 -05001557 *beacon, struct ieee80211_rx_stats
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001558 *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001559{
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001560 struct net_device *dev = ieee->dev;
Zhu Yid1b46b02006-01-19 16:22:15 +08001561 struct ieee80211_network network = {
1562 .ibss_dfs = NULL,
1563 };
Jeff Garzikb4538722005-05-12 22:48:20 -04001564 struct ieee80211_network *target;
1565 struct ieee80211_network *oldest = NULL;
1566#ifdef CONFIG_IEEE80211_DEBUG
James Ketrenos68e4e032005-09-13 17:37:22 -05001567 struct ieee80211_info_element *info_element = beacon->info_element;
Jeff Garzikb4538722005-05-12 22:48:20 -04001568#endif
1569 unsigned long flags;
John W. Linville9387b7c2008-09-30 20:59:05 -04001570 DECLARE_SSID_BUF(ssid);
Jeff Garzikb4538722005-05-12 22:48:20 -04001571
Johannes Berge1749612008-10-27 15:59:26 -07001572 IEEE80211_DEBUG_SCAN("'%s' (%pM"
Al Viro8524f592007-12-29 05:03:35 -05001573 "): %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 -04001574 print_ssid(ssid, info_element->data, info_element->len),
Johannes Berge1749612008-10-27 15:59:26 -07001575 beacon->header.addr3,
Al Viro8524f592007-12-29 05:03:35 -05001576 (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
1577 (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
1578 (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
1579 (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
1580 (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
1581 (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
1582 (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
1583 (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
1584 (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
1585 (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
1586 (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
1587 (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
1588 (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
1589 (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
1590 (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
1591 (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
Jeff Garzikb4538722005-05-12 22:48:20 -04001592
1593 if (ieee80211_network_init(ieee, beacon, &network, stats)) {
Johannes Berge1749612008-10-27 15:59:26 -07001594 IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001595 print_ssid(ssid, info_element->data,
John W. Linville7e272fc2008-09-24 18:13:14 -04001596 info_element->len),
Johannes Berge1749612008-10-27 15:59:26 -07001597 beacon->header.addr3,
Pete Zaitcev48328432006-02-26 23:43:20 -08001598 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001599 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001600 return;
1601 }
1602
1603 /* The network parsed correctly -- so now we scan our known networks
1604 * to see if we can find it in our list.
1605 *
1606 * NOTE: This search is definitely not optimized. Once its doing
1607 * the "right thing" we'll optimize it for efficiency if
1608 * necessary */
1609
1610 /* Search for this entry in the list and update it if it is
1611 * already there. */
1612
1613 spin_lock_irqsave(&ieee->lock, flags);
1614
1615 list_for_each_entry(target, &ieee->network_list, list) {
1616 if (is_same_network(target, &network))
1617 break;
1618
1619 if ((oldest == NULL) ||
1620 (target->last_scanned < oldest->last_scanned))
1621 oldest = target;
1622 }
1623
1624 /* If we didn't find a match, then get a new network slot to initialize
1625 * with this beacon's information */
1626 if (&target->list == &ieee->network_list) {
1627 if (list_empty(&ieee->network_free_list)) {
1628 /* If there are no more slots, expire the oldest */
1629 list_del(&oldest->list);
1630 target = oldest;
Johannes Berge1749612008-10-27 15:59:26 -07001631 IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
Jeff Garzikb4538722005-05-12 22:48:20 -04001632 "network list.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001633 print_ssid(ssid, target->ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001634 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001635 target->bssid);
Zhu Yid1b46b02006-01-19 16:22:15 +08001636 ieee80211_network_reset(target);
Jeff Garzikb4538722005-05-12 22:48:20 -04001637 } else {
1638 /* Otherwise just pull from the free list */
1639 target = list_entry(ieee->network_free_list.next,
1640 struct ieee80211_network, list);
1641 list_del(ieee->network_free_list.next);
1642 }
1643
Jeff Garzikb4538722005-05-12 22:48:20 -04001644#ifdef CONFIG_IEEE80211_DEBUG
Johannes Berge1749612008-10-27 15:59:26 -07001645 IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001646 print_ssid(ssid, network.ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001647 network.ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001648 network.bssid,
Pete Zaitcev48328432006-02-26 23:43:20 -08001649 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001650 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001651#endif
1652 memcpy(target, &network, sizeof(*target));
Zhu Yid1b46b02006-01-19 16:22:15 +08001653 network.ibss_dfs = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -04001654 list_add_tail(&target->list, &ieee->network_list);
1655 } else {
Johannes Berge1749612008-10-27 15:59:26 -07001656 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001657 print_ssid(ssid, target->ssid,
John W. Linville7e272fc2008-09-24 18:13:14 -04001658 target->ssid_len),
Johannes Berge1749612008-10-27 15:59:26 -07001659 target->bssid,
Pete Zaitcev48328432006-02-26 23:43:20 -08001660 is_beacon(beacon->header.frame_ctl) ?
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001661 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001662 update_network(target, &network);
Zhu Yid1b46b02006-01-19 16:22:15 +08001663 network.ibss_dfs = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -04001664 }
1665
1666 spin_unlock_irqrestore(&ieee->lock, flags);
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001667
Pete Zaitcev48328432006-02-26 23:43:20 -08001668 if (is_beacon(beacon->header.frame_ctl)) {
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001669 if (ieee->handle_beacon != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001670 ieee->handle_beacon(dev, beacon, target);
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001671 } else {
1672 if (ieee->handle_probe_response != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001673 ieee->handle_probe_response(dev, beacon, target);
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001674 }
Jeff Garzikb4538722005-05-12 22:48:20 -04001675}
1676
1677void ieee80211_rx_mgt(struct ieee80211_device *ieee,
James Ketrenosee34af32005-09-21 11:54:36 -05001678 struct ieee80211_hdr_4addr *header,
Jeff Garzikb4538722005-05-12 22:48:20 -04001679 struct ieee80211_rx_stats *stats)
1680{
James Ketrenosfd278172005-09-13 17:25:51 -05001681 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
Jeff Garzikb4538722005-05-12 22:48:20 -04001682 case IEEE80211_STYPE_ASSOC_RESP:
1683 IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001684 WLAN_FC_GET_STYPE(le16_to_cpu
1685 (header->frame_ctl)));
James Ketrenos9e8571a2005-09-21 11:56:33 -05001686 ieee80211_handle_assoc_resp(ieee,
1687 (struct ieee80211_assoc_response *)
1688 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001689 break;
1690
1691 case IEEE80211_STYPE_REASSOC_RESP:
1692 IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001693 WLAN_FC_GET_STYPE(le16_to_cpu
1694 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001695 break;
1696
James Ketrenos42c94e42005-09-21 11:58:29 -05001697 case IEEE80211_STYPE_PROBE_REQ:
Larry Finger1a1fedf2006-01-30 09:42:24 -06001698 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos42c94e42005-09-21 11:58:29 -05001699 WLAN_FC_GET_STYPE(le16_to_cpu
1700 (header->frame_ctl)));
1701
1702 if (ieee->handle_probe_request != NULL)
1703 ieee->handle_probe_request(ieee->dev,
1704 (struct
1705 ieee80211_probe_request *)
1706 header, stats);
1707 break;
1708
Jeff Garzikb4538722005-05-12 22:48:20 -04001709 case IEEE80211_STYPE_PROBE_RESP:
1710 IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001711 WLAN_FC_GET_STYPE(le16_to_cpu
1712 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001713 IEEE80211_DEBUG_SCAN("Probe response\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001714 ieee80211_process_probe_response(ieee,
1715 (struct
1716 ieee80211_probe_response *)
1717 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001718 break;
1719
1720 case IEEE80211_STYPE_BEACON:
1721 IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001722 WLAN_FC_GET_STYPE(le16_to_cpu
1723 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001724 IEEE80211_DEBUG_SCAN("Beacon\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001725 ieee80211_process_probe_response(ieee,
1726 (struct
1727 ieee80211_probe_response *)
1728 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001729 break;
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001730 case IEEE80211_STYPE_AUTH:
1731
Larry Finger1a1fedf2006-01-30 09:42:24 -06001732 IEEE80211_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001733 WLAN_FC_GET_STYPE(le16_to_cpu
1734 (header->frame_ctl)));
1735
1736 if (ieee->handle_auth != NULL)
1737 ieee->handle_auth(ieee->dev,
1738 (struct ieee80211_auth *)header);
1739 break;
1740
1741 case IEEE80211_STYPE_DISASSOC:
1742 if (ieee->handle_disassoc != NULL)
1743 ieee->handle_disassoc(ieee->dev,
1744 (struct ieee80211_disassoc *)
1745 header);
1746 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001747
Zhu Yid1b46b02006-01-19 16:22:15 +08001748 case IEEE80211_STYPE_ACTION:
1749 IEEE80211_DEBUG_MGMT("ACTION\n");
1750 if (ieee->handle_action)
1751 ieee->handle_action(ieee->dev,
1752 (struct ieee80211_action *)
1753 header, stats);
1754 break;
1755
Larry Finger2f633db2006-01-30 23:25:10 -06001756 case IEEE80211_STYPE_REASSOC_REQ:
1757 IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
1758 WLAN_FC_GET_STYPE(le16_to_cpu
1759 (header->frame_ctl)));
1760
Zhu Yi7736b5b2006-04-13 17:17:47 +08001761 IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
1762 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001763 if (ieee->handle_reassoc_request != NULL)
1764 ieee->handle_reassoc_request(ieee->dev,
1765 (struct ieee80211_reassoc_request *)
1766 header);
1767 break;
1768
1769 case IEEE80211_STYPE_ASSOC_REQ:
1770 IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
1771 WLAN_FC_GET_STYPE(le16_to_cpu
1772 (header->frame_ctl)));
1773
Zhu Yi7736b5b2006-04-13 17:17:47 +08001774 IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
1775 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001776 if (ieee->handle_assoc_request != NULL)
1777 ieee->handle_assoc_request(ieee->dev);
1778 break;
1779
James Ketrenos31b59ea2005-09-21 11:58:49 -05001780 case IEEE80211_STYPE_DEAUTH:
Zhu Yid1b46b02006-01-19 16:22:15 +08001781 IEEE80211_DEBUG_MGMT("DEAUTH\n");
James Ketrenos31b59ea2005-09-21 11:58:49 -05001782 if (ieee->handle_deauth != NULL)
Zhu Yid1b46b02006-01-19 16:22:15 +08001783 ieee->handle_deauth(ieee->dev,
1784 (struct ieee80211_deauth *)
James Ketrenos31b59ea2005-09-21 11:58:49 -05001785 header);
1786 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001787 default:
1788 IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001789 WLAN_FC_GET_STYPE(le16_to_cpu
1790 (header->frame_ctl)));
Zhu Yi7736b5b2006-04-13 17:17:47 +08001791 IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
1792 ieee->dev->name,
1793 WLAN_FC_GET_STYPE(le16_to_cpu
1794 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001795 break;
1796 }
1797}
1798
Daniel Drakef2060f032006-07-18 21:38:05 +01001799EXPORT_SYMBOL_GPL(ieee80211_rx_any);
Jeff Garzikb4538722005-05-12 22:48:20 -04001800EXPORT_SYMBOL(ieee80211_rx_mgt);
1801EXPORT_SYMBOL(ieee80211_rx);