blob: 6df19f03355af346f702d629c37fcc4ece4a5032 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/gfp.h>
Jeff Garzikb4538722005-05-12 22:48:20 -040021#include <linux/in.h>
22#include <linux/ip.h>
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/netdevice.h>
Jeff Garzikb4538722005-05-12 22:48:20 -040026#include <linux/proc_fs.h>
27#include <linux/skbuff.h>
Jeff Garzikb4538722005-05-12 22:48:20 -040028#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>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080032#include <linux/uaccess.h>
Jeff Garzikb4538722005-05-12 22:48:20 -040033#include <linux/ctype.h>
34
John W. Linville7e272fc2008-09-24 18:13:14 -040035#include <net/lib80211.h>
Dan Williamsf3734ee2009-02-12 12:32:55 -050036
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040037#include "libipw.h"
Jeff Garzikb4538722005-05-12 22:48:20 -040038
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040039static void libipw_monitor_rx(struct libipw_device *ieee,
Jeff Garzikb4538722005-05-12 22:48:20 -040040 struct sk_buff *skb,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040041 struct libipw_rx_stats *rx_stats)
Jeff Garzikb4538722005-05-12 22:48:20 -040042{
43 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
John W. Linville72118012008-09-30 21:43:03 -040044 u16 fc = le16_to_cpu(hdr->frame_control);
Jeff Garzikb4538722005-05-12 22:48:20 -040045
46 skb->dev = ieee->dev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -070047 skb_reset_mac_header(skb);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040048 skb_pull(skb, libipw_get_hdrlen(fc));
Jeff Garzikb4538722005-05-12 22:48:20 -040049 skb->pkt_type = PACKET_OTHERHOST;
YOSHIFUJI Hideaki4e394302007-12-12 03:52:26 +090050 skb->protocol = htons(ETH_P_80211_RAW);
Jeff Garzikb4538722005-05-12 22:48:20 -040051 memset(skb->cb, 0, sizeof(skb->cb));
52 netif_rx(skb);
53}
54
Jeff Garzikb4538722005-05-12 22:48:20 -040055/* Called only as a tasklet (software IRQ) */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040056static struct libipw_frag_entry *libipw_frag_cache_find(struct
57 libipw_device
Jeff Garzik0edd5b42005-09-07 00:48:31 -040058 *ieee,
59 unsigned int seq,
60 unsigned int frag,
61 u8 * src,
62 u8 * dst)
Jeff Garzikb4538722005-05-12 22:48:20 -040063{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040064 struct libipw_frag_entry *entry;
Jeff Garzikb4538722005-05-12 22:48:20 -040065 int i;
66
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040067 for (i = 0; i < LIBIPW_FRAG_CACHE_LEN; i++) {
Jeff Garzikb4538722005-05-12 22:48:20 -040068 entry = &ieee->frag_cache[i];
69 if (entry->skb != NULL &&
70 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040071 LIBIPW_DEBUG_FRAG("expiring fragment cache entry "
Jeff Garzik0edd5b42005-09-07 00:48:31 -040072 "seq=%u last_frag=%u\n",
73 entry->seq, entry->last_frag);
Jeff Garzikb4538722005-05-12 22:48:20 -040074 dev_kfree_skb_any(entry->skb);
75 entry->skb = NULL;
76 }
77
78 if (entry->skb != NULL && entry->seq == seq &&
79 (entry->last_frag + 1 == frag || frag == -1) &&
Joe Perches2e42e472012-05-09 17:17:46 +000080 ether_addr_equal(entry->src_addr, src) &&
81 ether_addr_equal(entry->dst_addr, dst))
Jeff Garzikb4538722005-05-12 22:48:20 -040082 return entry;
83 }
84
85 return NULL;
86}
87
88/* Called only as a tasklet (software IRQ) */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040089static struct sk_buff *libipw_frag_cache_get(struct libipw_device *ieee,
90 struct libipw_hdr_4addr *hdr)
Jeff Garzikb4538722005-05-12 22:48:20 -040091{
92 struct sk_buff *skb = NULL;
93 u16 sc;
94 unsigned int frag, seq;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -040095 struct libipw_frag_entry *entry;
Jeff Garzikb4538722005-05-12 22:48:20 -040096
97 sc = le16_to_cpu(hdr->seq_ctl);
98 frag = WLAN_GET_SEQ_FRAG(sc);
99 seq = WLAN_GET_SEQ_SEQ(sc);
100
101 if (frag == 0) {
102 /* Reserve enough space to fit maximum frame length */
103 skb = dev_alloc_skb(ieee->dev->mtu +
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400104 sizeof(struct libipw_hdr_4addr) +
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400105 8 /* LLC */ +
106 2 /* alignment */ +
107 8 /* WEP */ + ETH_ALEN /* WDS */ );
Jeff Garzikb4538722005-05-12 22:48:20 -0400108 if (skb == NULL)
109 return NULL;
110
111 entry = &ieee->frag_cache[ieee->frag_next_idx];
112 ieee->frag_next_idx++;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400113 if (ieee->frag_next_idx >= LIBIPW_FRAG_CACHE_LEN)
Jeff Garzikb4538722005-05-12 22:48:20 -0400114 ieee->frag_next_idx = 0;
115
116 if (entry->skb != NULL)
117 dev_kfree_skb_any(entry->skb);
118
119 entry->first_frag_time = jiffies;
120 entry->seq = seq;
121 entry->last_frag = frag;
122 entry->skb = skb;
123 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
124 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
125 } else {
126 /* received a fragment of a frame for which the head fragment
127 * should have already been received */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400128 entry = libipw_frag_cache_find(ieee, seq, frag, hdr->addr2,
Jeff Garzikb4538722005-05-12 22:48:20 -0400129 hdr->addr1);
130 if (entry != NULL) {
131 entry->last_frag = frag;
132 skb = entry->skb;
133 }
134 }
135
136 return skb;
137}
138
Jeff Garzikb4538722005-05-12 22:48:20 -0400139/* Called only as a tasklet (software IRQ) */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400140static int libipw_frag_cache_invalidate(struct libipw_device *ieee,
141 struct libipw_hdr_4addr *hdr)
Jeff Garzikb4538722005-05-12 22:48:20 -0400142{
143 u16 sc;
144 unsigned int seq;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400145 struct libipw_frag_entry *entry;
Jeff Garzikb4538722005-05-12 22:48:20 -0400146
147 sc = le16_to_cpu(hdr->seq_ctl);
148 seq = WLAN_GET_SEQ_SEQ(sc);
149
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400150 entry = libipw_frag_cache_find(ieee, seq, -1, hdr->addr2,
Jeff Garzikb4538722005-05-12 22:48:20 -0400151 hdr->addr1);
152
153 if (entry == NULL) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400154 LIBIPW_DEBUG_FRAG("could not invalidate fragment cache "
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400155 "entry (seq=%u)\n", seq);
Jeff Garzikb4538722005-05-12 22:48:20 -0400156 return -1;
157 }
158
159 entry->skb = NULL;
160 return 0;
161}
162
Jeff Garzikb4538722005-05-12 22:48:20 -0400163#ifdef NOT_YET
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400164/* libipw_rx_frame_mgtmt
Jeff Garzikb4538722005-05-12 22:48:20 -0400165 *
166 * Responsible for handling management control frames
167 *
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400168 * Called by libipw_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800169static int
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400170libipw_rx_frame_mgmt(struct libipw_device *ieee, struct sk_buff *skb,
171 struct libipw_rx_stats *rx_stats, u16 type,
Jeff Garzikb4538722005-05-12 22:48:20 -0400172 u16 stype)
173{
174 if (ieee->iw_mode == IW_MODE_MASTER) {
Masanari Iida5718b132012-01-30 22:52:10 +0900175 printk(KERN_DEBUG "%s: Master mode not yet supported.\n",
Jeff Garzikb4538722005-05-12 22:48:20 -0400176 ieee->dev->name);
177 return 0;
178/*
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400179 hostap_update_sta_ps(ieee, (struct hostap_libipw_hdr_4addr *)
Jeff Garzikb4538722005-05-12 22:48:20 -0400180 skb->data);*/
181 }
182
183 if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
184 if (stype == WLAN_FC_STYPE_BEACON &&
185 ieee->iw_mode == IW_MODE_MASTER) {
186 struct sk_buff *skb2;
187 /* Process beacon frames also in kernel driver to
188 * update STA(AP) table statistics */
189 skb2 = skb_clone(skb, GFP_ATOMIC);
190 if (skb2)
191 hostap_rx(skb2->dev, skb2, rx_stats);
192 }
193
194 /* send management frames to the user space daemon for
195 * processing */
196 ieee->apdevstats.rx_packets++;
197 ieee->apdevstats.rx_bytes += skb->len;
198 prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
199 return 0;
200 }
201
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400202 if (ieee->iw_mode == IW_MODE_MASTER) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400203 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
204 printk(KERN_DEBUG "%s: unknown management frame "
205 "(type=0x%02x, stype=0x%02x) dropped\n",
206 skb->dev->name, type, stype);
207 return -1;
208 }
209
210 hostap_rx(skb->dev, skb, rx_stats);
211 return 0;
212 }
213
214 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
215 "received in non-Host AP mode\n", skb->dev->name);
216 return -1;
217}
218#endif
219
Jeff Garzikb4538722005-05-12 22:48:20 -0400220/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
221/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400222static unsigned char libipw_rfc1042_header[] =
223 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400224
Jeff Garzikb4538722005-05-12 22:48:20 -0400225/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400226static unsigned char libipw_bridge_tunnel_header[] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400227 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
Jeff Garzikb4538722005-05-12 22:48:20 -0400228/* No encapsulation header if EtherType < 0x600 (=length) */
229
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400230/* Called by libipw_rx_frame_decrypt */
231static int libipw_is_eapol_frame(struct libipw_device *ieee,
Jeff Garzikb4538722005-05-12 22:48:20 -0400232 struct sk_buff *skb)
233{
234 struct net_device *dev = ieee->dev;
235 u16 fc, ethertype;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400236 struct libipw_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400237 u8 *pos;
238
239 if (skb->len < 24)
240 return 0;
241
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400242 hdr = (struct libipw_hdr_3addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400243 fc = le16_to_cpu(hdr->frame_ctl);
244
245 /* check that the frame is unicast frame to us */
246 if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
247 IEEE80211_FCTL_TODS &&
Joe Perches2e42e472012-05-09 17:17:46 +0000248 ether_addr_equal(hdr->addr1, dev->dev_addr) &&
249 ether_addr_equal(hdr->addr3, dev->dev_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400250 /* ToDS frame with own addr BSSID and DA */
251 } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
252 IEEE80211_FCTL_FROMDS &&
Joe Perches2e42e472012-05-09 17:17:46 +0000253 ether_addr_equal(hdr->addr1, dev->dev_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400254 /* FromDS frame with own addr as DA */
255 } else
256 return 0;
257
258 if (skb->len < 24 + 8)
259 return 0;
260
261 /* check for port access entity Ethernet type */
262 pos = skb->data + 24;
263 ethertype = (pos[6] << 8) | pos[7];
264 if (ethertype == ETH_P_PAE)
265 return 1;
266
267 return 0;
268}
269
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400270/* Called only as a tasklet (software IRQ), by libipw_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800271static int
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400272libipw_rx_frame_decrypt(struct libipw_device *ieee, struct sk_buff *skb,
John W. Linville274bfb82008-10-29 11:35:05 -0400273 struct lib80211_crypt_data *crypt)
Jeff Garzikb4538722005-05-12 22:48:20 -0400274{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400275 struct libipw_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400276 int res, hdrlen;
277
278 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
279 return 0;
280
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400281 hdr = (struct libipw_hdr_3addr *)skb->data;
282 hdrlen = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
Jeff Garzikb4538722005-05-12 22:48:20 -0400283
Jeff Garzikb4538722005-05-12 22:48:20 -0400284 atomic_inc(&crypt->refcnt);
285 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
286 atomic_dec(&crypt->refcnt);
287 if (res < 0) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400288 LIBIPW_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
Johannes Berge1749612008-10-27 15:59:26 -0700289 hdr->addr2, res);
Jeff Garzikb4538722005-05-12 22:48:20 -0400290 if (res == -2)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400291 LIBIPW_DEBUG_DROP("Decryption failed ICV "
Jeff Garzikb4538722005-05-12 22:48:20 -0400292 "mismatch (key %d)\n",
293 skb->data[hdrlen + 3] >> 6);
294 ieee->ieee_stats.rx_discards_undecryptable++;
295 return -1;
296 }
297
298 return res;
299}
300
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400301/* Called only as a tasklet (software IRQ), by libipw_rx */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800302static int
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400303libipw_rx_frame_decrypt_msdu(struct libipw_device *ieee,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400304 struct sk_buff *skb, int keyidx,
John W. Linville274bfb82008-10-29 11:35:05 -0400305 struct lib80211_crypt_data *crypt)
Jeff Garzikb4538722005-05-12 22:48:20 -0400306{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400307 struct libipw_hdr_3addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400308 int res, hdrlen;
309
310 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
311 return 0;
312
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400313 hdr = (struct libipw_hdr_3addr *)skb->data;
314 hdrlen = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
Jeff Garzikb4538722005-05-12 22:48:20 -0400315
316 atomic_inc(&crypt->refcnt);
317 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
318 atomic_dec(&crypt->refcnt);
319 if (res < 0) {
320 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
Johannes Berge1749612008-10-27 15:59:26 -0700321 " (SA=%pM keyidx=%d)\n", ieee->dev->name, hdr->addr2,
David S. Miller21f644f2008-04-08 16:50:44 -0700322 keyidx);
Jeff Garzikb4538722005-05-12 22:48:20 -0400323 return -1;
324 }
325
326 return 0;
327}
328
Jeff Garzikb4538722005-05-12 22:48:20 -0400329/* All received frames are sent to this function. @skb contains the frame in
330 * IEEE 802.11 format, i.e., in the format it was sent over air.
331 * This function is called only as a tasklet (software IRQ). */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400332int libipw_rx(struct libipw_device *ieee, struct sk_buff *skb,
333 struct libipw_rx_stats *rx_stats)
Jeff Garzikb4538722005-05-12 22:48:20 -0400334{
335 struct net_device *dev = ieee->dev;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400336 struct libipw_hdr_4addr *hdr;
Jeff Garzikb4538722005-05-12 22:48:20 -0400337 size_t hdrlen;
338 u16 fc, type, stype, sc;
Jeff Garzikb4538722005-05-12 22:48:20 -0400339 unsigned int frag;
340 u8 *payload;
341 u16 ethertype;
342#ifdef NOT_YET
343 struct net_device *wds = NULL;
344 struct sk_buff *skb2 = NULL;
345 struct net_device *wds = NULL;
346 int frame_authorized = 0;
347 int from_assoc_ap = 0;
348 void *sta = NULL;
349#endif
350 u8 dst[ETH_ALEN];
351 u8 src[ETH_ALEN];
John W. Linville274bfb82008-10-29 11:35:05 -0400352 struct lib80211_crypt_data *crypt = NULL;
Jeff Garzikb4538722005-05-12 22:48:20 -0400353 int keyidx = 0;
Zhu Yib6daa252006-01-19 16:20:42 +0800354 int can_be_decrypted = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -0400355
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400356 hdr = (struct libipw_hdr_4addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400357 if (skb->len < 10) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400358 printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
Jeff Garzikb4538722005-05-12 22:48:20 -0400359 goto rx_dropped;
360 }
361
362 fc = le16_to_cpu(hdr->frame_ctl);
363 type = WLAN_FC_GET_TYPE(fc);
364 stype = WLAN_FC_GET_STYPE(fc);
365 sc = le16_to_cpu(hdr->seq_ctl);
366 frag = WLAN_GET_SEQ_FRAG(sc);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400367 hdrlen = libipw_get_hdrlen(fc);
Jeff Garzikb4538722005-05-12 22:48:20 -0400368
John W. Linville04045f92007-10-01 21:03:54 -0700369 if (skb->len < hdrlen) {
370 printk(KERN_INFO "%s: invalid SKB length %d\n",
371 dev->name, skb->len);
372 goto rx_dropped;
373 }
374
Jeff Garzikb4538722005-05-12 22:48:20 -0400375 /* Put this code here so that we avoid duplicating it in all
376 * Rx paths. - Jean II */
Horms8f7eb4072006-06-26 17:44:38 +0900377#ifdef CONFIG_WIRELESS_EXT
Jeff Garzikb4538722005-05-12 22:48:20 -0400378#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
379 /* If spy monitoring on */
James Ketrenos74079fd2005-09-13 17:35:21 -0500380 if (ieee->spy_data.spy_number > 0) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400381 struct iw_quality wstats;
James Ketrenos74079fd2005-09-13 17:35:21 -0500382
383 wstats.updated = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400384 if (rx_stats->mask & LIBIPW_STATMASK_RSSI) {
Bruno Randolf566bfe52008-05-08 19:15:40 +0200385 wstats.level = rx_stats->signal;
James Ketrenos74079fd2005-09-13 17:35:21 -0500386 wstats.updated |= IW_QUAL_LEVEL_UPDATED;
387 } else
388 wstats.updated |= IW_QUAL_LEVEL_INVALID;
389
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400390 if (rx_stats->mask & LIBIPW_STATMASK_NOISE) {
James Ketrenos74079fd2005-09-13 17:35:21 -0500391 wstats.noise = rx_stats->noise;
392 wstats.updated |= IW_QUAL_NOISE_UPDATED;
393 } else
394 wstats.updated |= IW_QUAL_NOISE_INVALID;
395
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400396 if (rx_stats->mask & LIBIPW_STATMASK_SIGNAL) {
James Ketrenos74079fd2005-09-13 17:35:21 -0500397 wstats.qual = rx_stats->signal;
398 wstats.updated |= IW_QUAL_QUAL_UPDATED;
399 } else
400 wstats.updated |= IW_QUAL_QUAL_INVALID;
401
Jeff Garzikb4538722005-05-12 22:48:20 -0400402 /* Update spy records */
James Ketrenos74079fd2005-09-13 17:35:21 -0500403 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
Jeff Garzikb4538722005-05-12 22:48:20 -0400404 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400405#endif /* IW_WIRELESS_SPY */
Horms8f7eb4072006-06-26 17:44:38 +0900406#endif /* CONFIG_WIRELESS_EXT */
James Ketrenos74079fd2005-09-13 17:35:21 -0500407
408#ifdef NOT_YET
Jeff Garzikb4538722005-05-12 22:48:20 -0400409 hostap_update_rx_stats(local->ap, hdr, rx_stats);
410#endif
411
Jeff Garzikb4538722005-05-12 22:48:20 -0400412 if (ieee->iw_mode == IW_MODE_MONITOR) {
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000413 dev->stats.rx_packets++;
414 dev->stats.rx_bytes += skb->len;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400415 libipw_monitor_rx(ieee, skb, rx_stats);
Jeff Garzikb4538722005-05-12 22:48:20 -0400416 return 1;
417 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400418
Zhu Yib6daa252006-01-19 16:20:42 +0800419 can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
420 is_broadcast_ether_addr(hdr->addr2)) ?
421 ieee->host_mc_decrypt : ieee->host_decrypt;
422
423 if (can_be_decrypted) {
Zhu Yib6daa252006-01-19 16:20:42 +0800424 if (skb->len >= hdrlen + 3) {
425 /* Top two-bits of byte 3 are the key index */
Daniel Drakec9308b02006-09-27 03:50:31 +0100426 keyidx = skb->data[hdrlen + 3] >> 6;
Zhu Yib6daa252006-01-19 16:20:42 +0800427 }
428
Daniel Drakec9308b02006-09-27 03:50:31 +0100429 /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
430 * is only allowed 2-bits of storage, no value of keyidx can
431 * be provided via above code that would result in keyidx
Zhu Yib6daa252006-01-19 16:20:42 +0800432 * being out of range */
John W. Linville274bfb82008-10-29 11:35:05 -0400433 crypt = ieee->crypt_info.crypt[keyidx];
Zhu Yib6daa252006-01-19 16:20:42 +0800434
Jeff Garzikb4538722005-05-12 22:48:20 -0400435#ifdef NOT_YET
436 sta = NULL;
437
438 /* Use station specific key to override default keys if the
439 * receiver address is a unicast address ("individual RA"). If
440 * bcrx_sta_key parameter is set, station specific key is used
441 * even with broad/multicast targets (this is against IEEE
442 * 802.11, but makes it easier to use different keys with
443 * stations that do not support WEP key mapping). */
444
Tobias Klauserd4d2d282011-07-04 00:00:22 +0000445 if (is_unicast_ether_addr(hdr->addr1) || local->bcrx_sta_key)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400446 (void)hostap_handle_sta_crypto(local, hdr, &crypt,
447 &sta);
Jeff Garzikb4538722005-05-12 22:48:20 -0400448#endif
449
450 /* allow NULL decrypt to indicate an station specific override
451 * for default encryption */
452 if (crypt && (crypt->ops == NULL ||
453 crypt->ops->decrypt_mpdu == NULL))
454 crypt = NULL;
455
Jiri Bencf13baae2005-08-25 20:11:46 -0400456 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400457 /* This seems to be triggered by some (multicast?)
458 * frames from other than current BSS, so just drop the
459 * frames silently instead of filling system log with
460 * these reports. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400461 LIBIPW_DEBUG_DROP("Decryption failed (not set)"
Johannes Berge1749612008-10-27 15:59:26 -0700462 " (SA=%pM)\n", hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400463 ieee->ieee_stats.rx_discards_undecryptable++;
464 goto rx_dropped;
465 }
466 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400467#ifdef NOT_YET
468 if (type != WLAN_FC_TYPE_DATA) {
469 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
Jiri Bencf13baae2005-08-25 20:11:46 -0400470 fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400471 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400472 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
Johannes Berge1749612008-10-27 15:59:26 -0700473 "from %pM\n", dev->name, hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400474 /* TODO: could inform hostapd about this so that it
475 * could send auth failure report */
476 goto rx_dropped;
477 }
478
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400479 if (libipw_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
Jeff Garzikb4538722005-05-12 22:48:20 -0400480 goto rx_dropped;
481 else
482 goto rx_exit;
483 }
484#endif
Larry Finger837925d2006-10-03 18:49:32 -0500485 /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
486 if (sc == ieee->prev_seq_ctl)
487 goto rx_dropped;
488 else
489 ieee->prev_seq_ctl = sc;
Jeff Garzikb4538722005-05-12 22:48:20 -0400490
491 /* Data frame - extract src/dst addresses */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400492 if (skb->len < LIBIPW_3ADDR_LEN)
Jeff Garzikb4538722005-05-12 22:48:20 -0400493 goto rx_dropped;
494
495 switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
496 case IEEE80211_FCTL_FROMDS:
497 memcpy(dst, hdr->addr1, ETH_ALEN);
498 memcpy(src, hdr->addr3, ETH_ALEN);
499 break;
500 case IEEE80211_FCTL_TODS:
501 memcpy(dst, hdr->addr3, ETH_ALEN);
502 memcpy(src, hdr->addr2, ETH_ALEN);
503 break;
504 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400505 if (skb->len < LIBIPW_4ADDR_LEN)
Jeff Garzikb4538722005-05-12 22:48:20 -0400506 goto rx_dropped;
507 memcpy(dst, hdr->addr3, ETH_ALEN);
508 memcpy(src, hdr->addr4, ETH_ALEN);
509 break;
Arnd Bergmann10f33662016-10-24 17:38:35 +0200510 default:
Jeff Garzikb4538722005-05-12 22:48:20 -0400511 memcpy(dst, hdr->addr1, ETH_ALEN);
512 memcpy(src, hdr->addr2, ETH_ALEN);
513 break;
514 }
515
516#ifdef NOT_YET
517 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
518 goto rx_dropped;
519 if (wds) {
520 skb->dev = dev = wds;
521 stats = hostap_get_stats(dev);
522 }
523
524 if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400525 (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
Joe Perches2e42e472012-05-09 17:17:46 +0000526 IEEE80211_FCTL_FROMDS && ieee->stadev &&
527 ether_addr_equal(hdr->addr2, ieee->assoc_ap_addr)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400528 /* Frame from BSSID of the AP for which we are a client */
529 skb->dev = dev = ieee->stadev;
530 stats = hostap_get_stats(dev);
531 from_assoc_ap = 1;
532 }
533#endif
534
Jeff Garzikb4538722005-05-12 22:48:20 -0400535#ifdef NOT_YET
536 if ((ieee->iw_mode == IW_MODE_MASTER ||
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400537 ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400538 switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
539 wds != NULL)) {
540 case AP_RX_CONTINUE_NOT_AUTHORIZED:
541 frame_authorized = 0;
542 break;
543 case AP_RX_CONTINUE:
544 frame_authorized = 1;
545 break;
546 case AP_RX_DROP:
547 goto rx_dropped;
548 case AP_RX_EXIT:
549 goto rx_exit;
550 }
551 }
552#endif
553
554 /* Nullfunc frames may have PS-bit set, so they must be passed to
555 * hostap_handle_sta_rx() before being dropped here. */
James Ketrenos9e8571a2005-09-21 11:56:33 -0500556
557 stype &= ~IEEE80211_STYPE_QOS_DATA;
558
Jeff Garzikb4538722005-05-12 22:48:20 -0400559 if (stype != IEEE80211_STYPE_DATA &&
560 stype != IEEE80211_STYPE_DATA_CFACK &&
561 stype != IEEE80211_STYPE_DATA_CFPOLL &&
562 stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
563 if (stype != IEEE80211_STYPE_NULLFUNC)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400564 LIBIPW_DEBUG_DROP("RX: dropped data frame "
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400565 "with no data (type=0x%02x, "
566 "subtype=0x%02x, len=%d)\n",
567 type, stype, skb->len);
Jeff Garzikb4538722005-05-12 22:48:20 -0400568 goto rx_dropped;
569 }
570
571 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
572
Zhu Yib6daa252006-01-19 16:20:42 +0800573 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400574 (keyidx = libipw_rx_frame_decrypt(ieee, skb, crypt)) < 0)
Jeff Garzikb4538722005-05-12 22:48:20 -0400575 goto rx_dropped;
576
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400577 hdr = (struct libipw_hdr_4addr *)skb->data;
Jeff Garzikb4538722005-05-12 22:48:20 -0400578
579 /* skb: hdr + (possibly fragmented) plaintext payload */
580 // PR: FIXME: hostap has additional conditions in the "if" below:
Jiri Bencf13baae2005-08-25 20:11:46 -0400581 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
Denis Vlasenko9eafe762006-01-22 13:57:10 +0200582 if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400583 int flen;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400584 struct sk_buff *frag_skb = libipw_frag_cache_get(ieee, hdr);
585 LIBIPW_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
Jeff Garzikb4538722005-05-12 22:48:20 -0400586
587 if (!frag_skb) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400588 LIBIPW_DEBUG(LIBIPW_DL_RX | LIBIPW_DL_FRAG,
Jeff Garzikb4538722005-05-12 22:48:20 -0400589 "Rx cannot get skb from fragment "
590 "cache (morefrag=%d seq=%u frag=%u)\n",
591 (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
592 WLAN_GET_SEQ_SEQ(sc), frag);
593 goto rx_dropped;
594 }
595
596 flen = skb->len;
597 if (frag != 0)
598 flen -= hdrlen;
599
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700600 if (frag_skb->tail + flen > frag_skb->end) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400601 printk(KERN_WARNING "%s: host decrypted and "
602 "reassembled frame did not fit skb\n",
603 dev->name);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400604 libipw_frag_cache_invalidate(ieee, hdr);
Jeff Garzikb4538722005-05-12 22:48:20 -0400605 goto rx_dropped;
606 }
607
608 if (frag == 0) {
609 /* copy first fragment (including full headers) into
610 * beginning of the fragment cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300611 skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
Jeff Garzikb4538722005-05-12 22:48:20 -0400612 } else {
613 /* append frame payload to the end of the fragment
614 * cache skb */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300615 skb_copy_from_linear_data_offset(skb, hdrlen,
616 skb_put(frag_skb, flen), flen);
Jeff Garzikb4538722005-05-12 22:48:20 -0400617 }
618 dev_kfree_skb_any(skb);
619 skb = NULL;
620
621 if (fc & IEEE80211_FCTL_MOREFRAGS) {
622 /* more fragments expected - leave the skb in fragment
623 * cache for now; it will be delivered to upper layers
624 * after all fragments have been received */
625 goto rx_exit;
626 }
627
628 /* this was the last fragment and the frame will be
629 * delivered, so remove skb from fragment cache */
630 skb = frag_skb;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400631 hdr = (struct libipw_hdr_4addr *)skb->data;
632 libipw_frag_cache_invalidate(ieee, hdr);
Jeff Garzikb4538722005-05-12 22:48:20 -0400633 }
634
635 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
636 * encrypted/authenticated */
Zhu Yib6daa252006-01-19 16:20:42 +0800637 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400638 libipw_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
Jeff Garzikb4538722005-05-12 22:48:20 -0400639 goto rx_dropped;
640
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400641 hdr = (struct libipw_hdr_4addr *)skb->data;
Jiri Bencf13baae2005-08-25 20:11:46 -0400642 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400643 if ( /*ieee->ieee802_1x && */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400644 libipw_is_eapol_frame(ieee, skb)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400645 /* pass unencrypted EAPOL frames even if encryption is
646 * configured */
Jeff Garzikb4538722005-05-12 22:48:20 -0400647 } else {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400648 LIBIPW_DEBUG_DROP("encryption configured, but RX "
Johannes Berge1749612008-10-27 15:59:26 -0700649 "frame not encrypted (SA=%pM)\n",
650 hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400651 goto rx_dropped;
652 }
653 }
654
Jiri Bencf13baae2005-08-25 20:11:46 -0400655 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400656 !libipw_is_eapol_frame(ieee, skb)) {
657 LIBIPW_DEBUG_DROP("dropped unencrypted RX data "
Johannes Berge1749612008-10-27 15:59:26 -0700658 "frame from %pM (drop_unencrypted=1)\n",
659 hdr->addr2);
Jeff Garzikb4538722005-05-12 22:48:20 -0400660 goto rx_dropped;
661 }
662
Daniel Drakec9308b02006-09-27 03:50:31 +0100663 /* If the frame was decrypted in hardware, we may need to strip off
664 * any security data (IV, ICV, etc) that was left behind */
665 if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
666 ieee->host_strip_iv_icv) {
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900667 int trimlen = 0;
Daniel Drakec9308b02006-09-27 03:50:31 +0100668
669 /* Top two-bits of byte 3 are the key index */
670 if (skb->len >= hdrlen + 3)
671 keyidx = skb->data[hdrlen + 3] >> 6;
672
673 /* To strip off any security data which appears before the
674 * payload, we simply increase hdrlen (as the header gets
675 * chopped off immediately below). For the security data which
676 * appears after the payload, we use skb_trim. */
677
678 switch (ieee->sec.encode_alg[keyidx]) {
679 case SEC_ALG_WEP:
680 /* 4 byte IV */
681 hdrlen += 4;
682 /* 4 byte ICV */
683 trimlen = 4;
684 break;
685 case SEC_ALG_TKIP:
686 /* 4 byte IV, 4 byte ExtIV */
687 hdrlen += 8;
688 /* 8 byte MIC, 4 byte ICV */
689 trimlen = 12;
690 break;
691 case SEC_ALG_CCMP:
692 /* 8 byte CCMP header */
693 hdrlen += 8;
694 /* 8 byte MIC */
695 trimlen = 8;
696 break;
697 }
698
699 if (skb->len < trimlen)
700 goto rx_dropped;
701
702 __skb_trim(skb, skb->len - trimlen);
703
704 if (skb->len < hdrlen)
705 goto rx_dropped;
706 }
707
Jeff Garzikb4538722005-05-12 22:48:20 -0400708 /* skb: hdr + (possible reassembled) full plaintext payload */
709
710 payload = skb->data + hdrlen;
711 ethertype = (payload[6] << 8) | payload[7];
712
713#ifdef NOT_YET
714 /* If IEEE 802.1X is used, check whether the port is authorized to send
715 * the received frame. */
716 if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
717 if (ethertype == ETH_P_PAE) {
718 printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
719 dev->name);
720 if (ieee->hostapd && ieee->apdev) {
721 /* Send IEEE 802.1X frames to the user
722 * space daemon for processing */
723 prism2_rx_80211(ieee->apdev, skb, rx_stats,
724 PRISM2_RX_MGMT);
725 ieee->apdevstats.rx_packets++;
726 ieee->apdevstats.rx_bytes += skb->len;
727 goto rx_exit;
728 }
729 } else if (!frame_authorized) {
730 printk(KERN_DEBUG "%s: dropped frame from "
731 "unauthorized port (IEEE 802.1X): "
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400732 "ethertype=0x%04x\n", dev->name, ethertype);
Jeff Garzikb4538722005-05-12 22:48:20 -0400733 goto rx_dropped;
734 }
735 }
736#endif
737
738 /* convert hdr + possible LLC headers into Ethernet header */
739 if (skb->len - hdrlen >= 8 &&
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400740 ((memcmp(payload, libipw_rfc1042_header, SNAP_SIZE) == 0 &&
Jeff Garzikb4538722005-05-12 22:48:20 -0400741 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400742 memcmp(payload, libipw_bridge_tunnel_header, SNAP_SIZE) == 0)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400743 /* remove RFC1042 or Bridge-Tunnel encapsulation and
744 * replace EtherType */
745 skb_pull(skb, hdrlen + SNAP_SIZE);
746 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
747 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
748 } else {
Al Virod9e94d52007-12-29 05:01:07 -0500749 __be16 len;
Jeff Garzikb4538722005-05-12 22:48:20 -0400750 /* Leave Ethernet header part of hdr and full payload */
751 skb_pull(skb, hdrlen);
752 len = htons(skb->len);
753 memcpy(skb_push(skb, 2), &len, 2);
754 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
755 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
756 }
757
758#ifdef NOT_YET
759 if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400760 IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400761 /* Non-standard frame: get addr4 from its bogus location after
762 * the payload */
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300763 skb_copy_to_linear_data_offset(skb, ETH_ALEN,
764 skb->data + skb->len - ETH_ALEN,
765 ETH_ALEN);
Jeff Garzikb4538722005-05-12 22:48:20 -0400766 skb_trim(skb, skb->len - ETH_ALEN);
767 }
768#endif
769
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000770 dev->stats.rx_packets++;
771 dev->stats.rx_bytes += skb->len;
Jeff Garzikb4538722005-05-12 22:48:20 -0400772
773#ifdef NOT_YET
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400774 if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
Tobias Klauserd4d2d282011-07-04 00:00:22 +0000775 if (is_multicast_ether_addr(dst)) {
Jeff Garzikb4538722005-05-12 22:48:20 -0400776 /* copy multicast frame both to the higher layers and
777 * to the wireless media */
778 ieee->ap->bridged_multicast++;
779 skb2 = skb_clone(skb, GFP_ATOMIC);
780 if (skb2 == NULL)
781 printk(KERN_DEBUG "%s: skb_clone failed for "
782 "multicast frame\n", dev->name);
783 } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
784 /* send frame directly to the associated STA using
785 * wireless media and not passing to higher layers */
786 ieee->ap->bridged_unicast++;
787 skb2 = skb;
788 skb = NULL;
789 }
790 }
791
792 if (skb2 != NULL) {
793 /* send to wireless media */
Jeff Garzikb4538722005-05-12 22:48:20 -0400794 skb2->dev = dev;
YOSHIFUJI Hideaki4e394302007-12-12 03:52:26 +0900795 skb2->protocol = htons(ETH_P_802_3);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700796 skb_reset_mac_header(skb2);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700797 skb_reset_network_header(skb2);
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700798 /* skb2->network_header += ETH_HLEN; */
Jeff Garzikb4538722005-05-12 22:48:20 -0400799 dev_queue_xmit(skb2);
800 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400801#endif
802
803 if (skb) {
804 skb->protocol = eth_type_trans(skb, dev);
805 memset(skb->cb, 0, sizeof(skb->cb));
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400806 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
Zhu Yid6529232006-01-19 16:20:49 +0800807 if (netif_rx(skb) == NET_RX_DROP) {
808 /* netif_rx always succeeds, but it might drop
809 * the packet. If it drops the packet, we log that
810 * in our stats. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400811 LIBIPW_DEBUG_DROP
Zhu Yid6529232006-01-19 16:20:49 +0800812 ("RX: netif_rx dropped the packet\n");
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000813 dev->stats.rx_dropped++;
Zhu Yid6529232006-01-19 16:20:49 +0800814 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400815 }
816
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400817 rx_exit:
Jeff Garzikb4538722005-05-12 22:48:20 -0400818#ifdef NOT_YET
819 if (sta)
820 hostap_handle_sta_release(sta);
821#endif
822 return 1;
823
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400824 rx_dropped:
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000825 dev->stats.rx_dropped++;
Jeff Garzikb4538722005-05-12 22:48:20 -0400826
827 /* Returning 0 indicates to caller that we have not handled the SKB--
828 * so it is still allocated and can be used again by underlying
829 * hardware as a DMA target */
830 return 0;
831}
832
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400833/* Filter out unrelated packets, call libipw_rx[_mgt]
Daniel Drakef2060f032006-07-18 21:38:05 +0100834 * This function takes over the skb, it should not be used again after calling
835 * this function. */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400836void libipw_rx_any(struct libipw_device *ieee,
837 struct sk_buff *skb, struct libipw_rx_stats *stats)
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200838{
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400839 struct libipw_hdr_4addr *hdr;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200840 int is_packet_for_us;
841 u16 fc;
842
Daniel Drakef2060f032006-07-18 21:38:05 +0100843 if (ieee->iw_mode == IW_MODE_MONITOR) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400844 if (!libipw_rx(ieee, skb, stats))
Daniel Drakef2060f032006-07-18 21:38:05 +0100845 dev_kfree_skb_irq(skb);
846 return;
847 }
848
849 if (skb->len < sizeof(struct ieee80211_hdr))
850 goto drop_free;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200851
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400852 hdr = (struct libipw_hdr_4addr *)skb->data;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200853 fc = le16_to_cpu(hdr->frame_ctl);
854
855 if ((fc & IEEE80211_FCTL_VERS) != 0)
Daniel Drakef2060f032006-07-18 21:38:05 +0100856 goto drop_free;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900857
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200858 switch (fc & IEEE80211_FCTL_FTYPE) {
859 case IEEE80211_FTYPE_MGMT:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400860 if (skb->len < sizeof(struct libipw_hdr_3addr))
Daniel Drakef2060f032006-07-18 21:38:05 +0100861 goto drop_free;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400862 libipw_rx_mgt(ieee, hdr, stats);
Daniel Drakef2060f032006-07-18 21:38:05 +0100863 dev_kfree_skb_irq(skb);
864 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200865 case IEEE80211_FTYPE_DATA:
866 break;
867 case IEEE80211_FTYPE_CTL:
Daniel Drakef2060f032006-07-18 21:38:05 +0100868 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200869 default:
Daniel Drakef2060f032006-07-18 21:38:05 +0100870 return;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200871 }
872
873 is_packet_for_us = 0;
874 switch (ieee->iw_mode) {
875 case IW_MODE_ADHOC:
876 /* our BSS and not from/to DS */
dingtianhong36325f32013-12-26 19:41:23 +0800877 if (ether_addr_equal(hdr->addr3, ieee->bssid))
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200878 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
879 /* promisc: get all */
880 if (ieee->dev->flags & IFF_PROMISC)
881 is_packet_for_us = 1;
882 /* to us */
dingtianhong36325f32013-12-26 19:41:23 +0800883 else if (ether_addr_equal(hdr->addr1, ieee->dev->dev_addr))
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200884 is_packet_for_us = 1;
885 /* mcast */
886 else if (is_multicast_ether_addr(hdr->addr1))
887 is_packet_for_us = 1;
888 }
889 break;
890 case IW_MODE_INFRA:
891 /* our BSS (== from our AP) and from DS */
dingtianhong36325f32013-12-26 19:41:23 +0800892 if (ether_addr_equal(hdr->addr2, ieee->bssid))
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200893 if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
894 /* promisc: get all */
895 if (ieee->dev->flags & IFF_PROMISC)
896 is_packet_for_us = 1;
897 /* to us */
dingtianhong36325f32013-12-26 19:41:23 +0800898 else if (ether_addr_equal(hdr->addr1, ieee->dev->dev_addr))
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200899 is_packet_for_us = 1;
900 /* mcast */
901 else if (is_multicast_ether_addr(hdr->addr1)) {
902 /* not our own packet bcasted from AP */
dingtianhong36325f32013-12-26 19:41:23 +0800903 if (!ether_addr_equal(hdr->addr3, ieee->dev->dev_addr))
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200904 is_packet_for_us = 1;
905 }
906 }
907 break;
908 default:
909 /* ? */
910 break;
911 }
912
913 if (is_packet_for_us)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400914 if (!libipw_rx(ieee, skb, stats))
Daniel Drakef2060f032006-07-18 21:38:05 +0100915 dev_kfree_skb_irq(skb);
916 return;
917
918drop_free:
919 dev_kfree_skb_irq(skb);
Stephen Hemmingerce55cba2009-03-20 19:36:38 +0000920 ieee->dev->stats.rx_dropped++;
Denis Vlasenko1a995b452006-01-24 16:57:11 +0200921}
922
Jeff Garzikb4538722005-05-12 22:48:20 -0400923#define MGMT_FRAME_FIXED_PART_LENGTH 0x24
924
James Ketrenos9e8571a2005-09-21 11:56:33 -0500925static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
926
927/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300928* Make the structure we read from the beacon packet to have
James Ketrenos9e8571a2005-09-21 11:56:33 -0500929* the right values
930*/
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400931static int libipw_verify_qos_info(struct libipw_qos_information_element
James Ketrenos9e8571a2005-09-21 11:56:33 -0500932 *info_element, int sub_type)
933{
934
935 if (info_element->qui_subtype != sub_type)
936 return -1;
937 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
938 return -1;
939 if (info_element->qui_type != QOS_OUI_TYPE)
940 return -1;
941 if (info_element->version != QOS_VERSION_1)
942 return -1;
943
944 return 0;
945}
946
947/*
948 * Parse a QoS parameter element
949 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400950static int libipw_read_qos_param_element(struct libipw_qos_parameter_info
951 *element_param, struct libipw_info_element
James Ketrenos9e8571a2005-09-21 11:56:33 -0500952 *info_element)
953{
954 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400955 u16 size = sizeof(struct libipw_qos_parameter_info) - 2;
James Ketrenos9e8571a2005-09-21 11:56:33 -0500956
957 if ((info_element == NULL) || (element_param == NULL))
958 return -1;
959
960 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
961 memcpy(element_param->info_element.qui, info_element->data,
962 info_element->len);
963 element_param->info_element.elementID = info_element->id;
964 element_param->info_element.length = info_element->len;
965 } else
966 ret = -1;
967 if (ret == 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400968 ret = libipw_verify_qos_info(&element_param->info_element,
James Ketrenos9e8571a2005-09-21 11:56:33 -0500969 QOS_OUI_PARAM_SUB_TYPE);
970 return ret;
971}
972
973/*
974 * Parse a QoS information element
975 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400976static int libipw_read_qos_info_element(struct
977 libipw_qos_information_element
978 *element_info, struct libipw_info_element
James Ketrenos9e8571a2005-09-21 11:56:33 -0500979 *info_element)
980{
981 int ret = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400982 u16 size = sizeof(struct libipw_qos_information_element) - 2;
James Ketrenos9e8571a2005-09-21 11:56:33 -0500983
984 if (element_info == NULL)
985 return -1;
986 if (info_element == NULL)
987 return -1;
988
989 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
990 memcpy(element_info->qui, info_element->data,
991 info_element->len);
992 element_info->elementID = info_element->id;
993 element_info->length = info_element->len;
994 } else
995 ret = -1;
996
997 if (ret == 0)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -0400998 ret = libipw_verify_qos_info(element_info,
James Ketrenos9e8571a2005-09-21 11:56:33 -0500999 QOS_OUI_INFO_SUB_TYPE);
1000 return ret;
1001}
1002
1003/*
1004 * Write QoS parameters from the ac parameters.
1005 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001006static int libipw_qos_convert_ac_to_parameters(struct
1007 libipw_qos_parameter_info
James Ketrenos9e8571a2005-09-21 11:56:33 -05001008 *param_elm, struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001009 libipw_qos_parameters
James Ketrenos9e8571a2005-09-21 11:56:33 -05001010 *qos_param)
1011{
1012 int rc = 0;
1013 int i;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001014 struct libipw_qos_ac_parameter *ac_params;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001015 u32 txop;
1016 u8 cw_min;
1017 u8 cw_max;
1018
1019 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1020 ac_params = &(param_elm->ac_params_record[i]);
1021
1022 qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
1023 qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
1024
1025 cw_min = ac_params->ecw_min_max & 0x0F;
Al Viro8fffc152007-12-27 01:25:40 -05001026 qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001027
1028 cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
Al Viro8fffc152007-12-27 01:25:40 -05001029 qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001030
1031 qos_param->flag[i] =
1032 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1033
1034 txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
Al Viro8fffc152007-12-27 01:25:40 -05001035 qos_param->tx_op_limit[i] = cpu_to_le16(txop);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001036 }
1037 return rc;
1038}
1039
1040/*
1041 * we have a generic data element which it may contain QoS information or
1042 * parameters element. check the information element length to decide
1043 * which type to read
1044 */
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001045static int libipw_parse_qos_info_param_IE(struct libipw_info_element
James Ketrenos9e8571a2005-09-21 11:56:33 -05001046 *info_element,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001047 struct libipw_network *network)
James Ketrenos9e8571a2005-09-21 11:56:33 -05001048{
1049 int rc = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001050 struct libipw_qos_parameters *qos_param = NULL;
1051 struct libipw_qos_information_element qos_info_element;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001052
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001053 rc = libipw_read_qos_info_element(&qos_info_element, info_element);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001054
1055 if (rc == 0) {
1056 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1057 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1058 } else {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001059 struct libipw_qos_parameter_info param_element;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001060
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001061 rc = libipw_read_qos_param_element(&param_element,
James Ketrenos9e8571a2005-09-21 11:56:33 -05001062 info_element);
1063 if (rc == 0) {
1064 qos_param = &(network->qos_data.parameters);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001065 libipw_qos_convert_ac_to_parameters(&param_element,
James Ketrenos9e8571a2005-09-21 11:56:33 -05001066 qos_param);
1067 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1068 network->qos_data.param_count =
1069 param_element.info_element.ac_info & 0x0F;
1070 }
1071 }
1072
1073 if (rc == 0) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001074 LIBIPW_DEBUG_QOS("QoS is supported\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001075 network->qos_data.supported = 1;
1076 }
1077 return rc;
1078}
1079
Helmut Schaa37561622009-03-06 12:02:25 +01001080#ifdef CONFIG_LIBIPW_DEBUG
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001081#define MFIE_STRING(x) case WLAN_EID_ ##x: return #x
Zhu Yid1b46b02006-01-19 16:22:15 +08001082
1083static const char *get_info_element_string(u16 id)
1084{
1085 switch (id) {
1086 MFIE_STRING(SSID);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001087 MFIE_STRING(SUPP_RATES);
1088 MFIE_STRING(FH_PARAMS);
1089 MFIE_STRING(DS_PARAMS);
1090 MFIE_STRING(CF_PARAMS);
Zhu Yid1b46b02006-01-19 16:22:15 +08001091 MFIE_STRING(TIM);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001092 MFIE_STRING(IBSS_PARAMS);
Zhu Yid1b46b02006-01-19 16:22:15 +08001093 MFIE_STRING(COUNTRY);
Zhu Yid1b46b02006-01-19 16:22:15 +08001094 MFIE_STRING(REQUEST);
1095 MFIE_STRING(CHALLENGE);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001096 MFIE_STRING(PWR_CONSTRAINT);
1097 MFIE_STRING(PWR_CAPABILITY);
Zhu Yid1b46b02006-01-19 16:22:15 +08001098 MFIE_STRING(TPC_REQUEST);
1099 MFIE_STRING(TPC_REPORT);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001100 MFIE_STRING(SUPPORTED_CHANNELS);
1101 MFIE_STRING(CHANNEL_SWITCH);
Zhu Yid1b46b02006-01-19 16:22:15 +08001102 MFIE_STRING(MEASURE_REQUEST);
1103 MFIE_STRING(MEASURE_REPORT);
1104 MFIE_STRING(QUIET);
1105 MFIE_STRING(IBSS_DFS);
1106 MFIE_STRING(ERP_INFO);
1107 MFIE_STRING(RSN);
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001108 MFIE_STRING(EXT_SUPP_RATES);
Arend van Spriel04b23122012-10-12 12:28:14 +02001109 MFIE_STRING(VENDOR_SPECIFIC);
Zhu Yid1b46b02006-01-19 16:22:15 +08001110 MFIE_STRING(QOS_PARAMETER);
1111 default:
1112 return "UNKNOWN";
1113 }
1114}
1115#endif
1116
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001117static int libipw_parse_info_param(struct libipw_info_element
James Ketrenosff0037b2005-10-03 10:23:42 -05001118 *info_element, u16 length,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001119 struct libipw_network *network)
James Ketrenos9e8571a2005-09-21 11:56:33 -05001120{
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001121 u8 i;
Helmut Schaa37561622009-03-06 12:02:25 +01001122#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001123 char rates_str[64];
1124 char *p;
1125#endif
James Ketrenos9e8571a2005-09-21 11:56:33 -05001126
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001127 while (length >= sizeof(*info_element)) {
1128 if (sizeof(*info_element) + info_element->len > length) {
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001129 LIBIPW_DEBUG_MGMT("Info elem: parse failed: "
Jiri Bencaec41a02006-10-18 19:34:40 +02001130 "info_element->len + 2 > left : "
1131 "info_element->len+2=%zd left=%d, id=%d.\n",
1132 info_element->len +
1133 sizeof(*info_element),
1134 length, info_element->id);
Zhu Yif09fc442006-08-21 11:34:19 +08001135 /* We stop processing but don't return an error here
1136 * because some misbehaviour APs break this rule. ie.
1137 * Orinoco AP1000. */
1138 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001139 }
1140
1141 switch (info_element->id) {
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001142 case WLAN_EID_SSID:
James Ketrenos9e8571a2005-09-21 11:56:33 -05001143 network->ssid_len = min(info_element->len,
1144 (u8) IW_ESSID_MAX_SIZE);
1145 memcpy(network->ssid, info_element->data,
1146 network->ssid_len);
1147 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1148 memset(network->ssid + network->ssid_len, 0,
1149 IW_ESSID_MAX_SIZE - network->ssid_len);
1150
Andy Shevchenko4b4890c2014-10-13 15:55:22 -07001151 LIBIPW_DEBUG_MGMT("WLAN_EID_SSID: '%*pE' len=%d.\n",
1152 network->ssid_len, network->ssid,
1153 network->ssid_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001154 break;
1155
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001156 case WLAN_EID_SUPP_RATES:
Helmut Schaa37561622009-03-06 12:02:25 +01001157#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001158 p = rates_str;
1159#endif
1160 network->rates_len = min(info_element->len,
1161 MAX_RATES_LENGTH);
1162 for (i = 0; i < network->rates_len; i++) {
1163 network->rates[i] = info_element->data[i];
Helmut Schaa37561622009-03-06 12:02:25 +01001164#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001165 p += snprintf(p, sizeof(rates_str) -
1166 (p - rates_str), "%02X ",
1167 network->rates[i]);
1168#endif
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001169 if (libipw_is_ofdm_rate
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001170 (info_element->data[i])) {
1171 network->flags |= NETWORK_HAS_OFDM;
1172 if (info_element->data[i] &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001173 LIBIPW_BASIC_RATE_MASK)
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001174 network->flags &=
1175 ~NETWORK_HAS_CCK;
1176 }
1177 }
1178
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001179 LIBIPW_DEBUG_MGMT("WLAN_EID_SUPP_RATES: '%s' (%d)\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001180 rates_str, network->rates_len);
1181 break;
1182
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001183 case WLAN_EID_EXT_SUPP_RATES:
Helmut Schaa37561622009-03-06 12:02:25 +01001184#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001185 p = rates_str;
1186#endif
1187 network->rates_ex_len = min(info_element->len,
1188 MAX_RATES_EX_LENGTH);
1189 for (i = 0; i < network->rates_ex_len; i++) {
1190 network->rates_ex[i] = info_element->data[i];
Helmut Schaa37561622009-03-06 12:02:25 +01001191#ifdef CONFIG_LIBIPW_DEBUG
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001192 p += snprintf(p, sizeof(rates_str) -
1193 (p - rates_str), "%02X ",
Dan Carpenter428e3cf2013-06-21 15:26:20 +03001194 network->rates_ex[i]);
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001195#endif
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001196 if (libipw_is_ofdm_rate
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001197 (info_element->data[i])) {
1198 network->flags |= NETWORK_HAS_OFDM;
1199 if (info_element->data[i] &
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001200 LIBIPW_BASIC_RATE_MASK)
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001201 network->flags &=
1202 ~NETWORK_HAS_CCK;
1203 }
1204 }
1205
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001206 LIBIPW_DEBUG_MGMT("WLAN_EID_EXT_SUPP_RATES: '%s' (%d)\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001207 rates_str, network->rates_ex_len);
1208 break;
1209
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001210 case WLAN_EID_DS_PARAMS:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001211 LIBIPW_DEBUG_MGMT("WLAN_EID_DS_PARAMS: %d\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001212 info_element->data[0]);
1213 network->channel = info_element->data[0];
1214 break;
1215
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001216 case WLAN_EID_FH_PARAMS:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001217 LIBIPW_DEBUG_MGMT("WLAN_EID_FH_PARAMS: ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001218 break;
1219
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001220 case WLAN_EID_CF_PARAMS:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001221 LIBIPW_DEBUG_MGMT("WLAN_EID_CF_PARAMS: ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001222 break;
1223
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001224 case WLAN_EID_TIM:
Zhu Yi41a25c62006-01-19 16:22:23 +08001225 network->tim.tim_count = info_element->data[0];
1226 network->tim.tim_period = info_element->data[1];
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001227 LIBIPW_DEBUG_MGMT("WLAN_EID_TIM: partially ignored\n");
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001228 break;
1229
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001230 case WLAN_EID_ERP_INFO:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001231 network->erp_value = info_element->data[0];
Daniel Draked8e2be92006-07-18 21:30:34 +01001232 network->flags |= NETWORK_HAS_ERP_VALUE;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001233 LIBIPW_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001234 network->erp_value);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001235 break;
1236
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001237 case WLAN_EID_IBSS_PARAMS:
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001238 network->atim_window = info_element->data[0];
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001239 LIBIPW_DEBUG_MGMT("WLAN_EID_IBSS_PARAMS: %d\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001240 network->atim_window);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001241 break;
1242
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001243 case WLAN_EID_CHALLENGE:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001244 LIBIPW_DEBUG_MGMT("WLAN_EID_CHALLENGE: ignored\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001245 break;
1246
Arend van Spriel04b23122012-10-12 12:28:14 +02001247 case WLAN_EID_VENDOR_SPECIFIC:
1248 LIBIPW_DEBUG_MGMT("WLAN_EID_VENDOR_SPECIFIC: %d bytes\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001249 info_element->len);
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001250 if (!libipw_parse_qos_info_param_IE(info_element,
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001251 network))
1252 break;
1253
1254 if (info_element->len >= 4 &&
1255 info_element->data[0] == 0x00 &&
1256 info_element->data[1] == 0x50 &&
1257 info_element->data[2] == 0xf2 &&
1258 info_element->data[3] == 0x01) {
1259 network->wpa_ie_len = min(info_element->len + 2,
1260 MAX_WPA_IE_LEN);
1261 memcpy(network->wpa_ie, info_element,
1262 network->wpa_ie_len);
1263 }
James Ketrenos9e8571a2005-09-21 11:56:33 -05001264 break;
1265
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001266 case WLAN_EID_RSN:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001267 LIBIPW_DEBUG_MGMT("WLAN_EID_RSN: %d bytes\n",
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001268 info_element->len);
1269 network->rsn_ie_len = min(info_element->len + 2,
1270 MAX_WPA_IE_LEN);
1271 memcpy(network->rsn_ie, info_element,
1272 network->rsn_ie_len);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001273 break;
1274
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001275 case WLAN_EID_QOS_PARAMETER:
James Ketrenosff0037b2005-10-03 10:23:42 -05001276 printk(KERN_ERR
1277 "QoS Error need to parse QOS_PARAMETER IE\n");
James Ketrenos9e8571a2005-09-21 11:56:33 -05001278 break;
Zhu Yid1b46b02006-01-19 16:22:15 +08001279 /* 802.11h */
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001280 case WLAN_EID_PWR_CONSTRAINT:
Zhu Yid1b46b02006-01-19 16:22:15 +08001281 network->power_constraint = info_element->data[0];
1282 network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
1283 break;
1284
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001285 case WLAN_EID_CHANNEL_SWITCH:
Zhu Yid1b46b02006-01-19 16:22:15 +08001286 network->power_constraint = info_element->data[0];
1287 network->flags |= NETWORK_HAS_CSA;
1288 break;
1289
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001290 case WLAN_EID_QUIET:
Zhu Yid1b46b02006-01-19 16:22:15 +08001291 network->quiet.count = info_element->data[0];
1292 network->quiet.period = info_element->data[1];
1293 network->quiet.duration = info_element->data[2];
1294 network->quiet.offset = info_element->data[3];
1295 network->flags |= NETWORK_HAS_QUIET;
1296 break;
1297
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001298 case WLAN_EID_IBSS_DFS:
Zhu Yid1b46b02006-01-19 16:22:15 +08001299 network->flags |= NETWORK_HAS_IBSS_DFS;
1300 break;
1301
Helmut Schaad74cc9a2009-03-06 15:32:26 +01001302 case WLAN_EID_TPC_REPORT:
Zhu Yid1b46b02006-01-19 16:22:15 +08001303 network->tpc_report.transmit_power =
1304 info_element->data[0];
1305 network->tpc_report.link_margin = info_element->data[1];
1306 network->flags |= NETWORK_HAS_TPC_REPORT;
1307 break;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001308
1309 default:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001310 LIBIPW_DEBUG_MGMT
Zhu Yid1b46b02006-01-19 16:22:15 +08001311 ("Unsupported info element: %s (%d)\n",
1312 get_info_element_string(info_element->id),
1313 info_element->id);
James Ketrenos9e8571a2005-09-21 11:56:33 -05001314 break;
1315 }
1316
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001317 length -= sizeof(*info_element) + info_element->len;
James Ketrenosff0037b2005-10-03 10:23:42 -05001318 info_element =
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001319 (struct libipw_info_element *)&info_element->
James Ketrenosff0037b2005-10-03 10:23:42 -05001320 data[info_element->len];
James Ketrenos9e8571a2005-09-21 11:56:33 -05001321 }
1322
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001323 return 0;
1324}
1325
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001326static int libipw_handle_assoc_resp(struct libipw_device *ieee, struct libipw_assoc_response
1327 *frame, struct libipw_rx_stats *stats)
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001328{
Dan Carpenter2aa01652014-10-09 12:57:42 +03001329 struct libipw_network network_resp = { };
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001330 struct libipw_network *network = &network_resp;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001331 struct net_device *dev = ieee->dev;
1332
1333 network->flags = 0;
1334 network->qos_data.active = 0;
1335 network->qos_data.supported = 0;
1336 network->qos_data.param_count = 0;
1337 network->qos_data.old_param_count = 0;
1338
1339 //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
1340 network->atim_window = le16_to_cpu(frame->aid);
1341 network->listen_interval = le16_to_cpu(frame->status);
Ivo van Doornc1bda442005-10-03 10:20:47 -05001342 memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
1343 network->capability = le16_to_cpu(frame->capability);
1344 network->last_scanned = jiffies;
1345 network->rates_len = network->rates_ex_len = 0;
1346 network->last_associate = 0;
1347 network->ssid_len = 0;
James Ketrenosff0037b2005-10-03 10:23:42 -05001348 network->erp_value =
1349 (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001350
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001351 if (stats->freq == LIBIPW_52GHZ_BAND) {
Ivo van Doornc1bda442005-10-03 10:20:47 -05001352 /* for A band (No DS info) */
1353 network->channel = stats->received_channel;
1354 } else
1355 network->flags |= NETWORK_HAS_CCK;
1356
1357 network->wpa_ie_len = 0;
1358 network->rsn_ie_len = 0;
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001359
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001360 if (libipw_parse_info_param
James Ketrenosff0037b2005-10-03 10:23:42 -05001361 (frame->info_element, stats->len - sizeof(*frame), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001362 return 1;
1363
Ivo van Doornc1bda442005-10-03 10:20:47 -05001364 network->mode = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001365 if (stats->freq == LIBIPW_52GHZ_BAND)
Ivo van Doornc1bda442005-10-03 10:20:47 -05001366 network->mode = IEEE_A;
1367 else {
1368 if (network->flags & NETWORK_HAS_OFDM)
1369 network->mode |= IEEE_G;
1370 if (network->flags & NETWORK_HAS_CCK)
1371 network->mode |= IEEE_B;
1372 }
1373
Ivo van Doornc1bda442005-10-03 10:20:47 -05001374 memcpy(&network->stats, stats, sizeof(network->stats));
1375
James Ketrenos9e8571a2005-09-21 11:56:33 -05001376 if (ieee->handle_assoc_response != NULL)
1377 ieee->handle_assoc_response(dev, frame, network);
1378
1379 return 0;
1380}
1381
1382/***************************************************/
1383
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001384static int libipw_network_init(struct libipw_device *ieee, struct libipw_probe_response
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001385 *beacon,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001386 struct libipw_network *network,
1387 struct libipw_rx_stats *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001388{
James Ketrenos9e8571a2005-09-21 11:56:33 -05001389 network->qos_data.active = 0;
1390 network->qos_data.supported = 0;
1391 network->qos_data.param_count = 0;
Ivo van Doornc1bda442005-10-03 10:20:47 -05001392 network->qos_data.old_param_count = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001393
1394 /* Pull out fixed field data */
1395 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
James Ketrenosfd278172005-09-13 17:25:51 -05001396 network->capability = le16_to_cpu(beacon->capability);
Jeff Garzikb4538722005-05-12 22:48:20 -04001397 network->last_scanned = jiffies;
James Ketrenosfd278172005-09-13 17:25:51 -05001398 network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
1399 network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
1400 network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001401 /* Where to pull this? beacon->listen_interval; */
Jeff Garzikb4538722005-05-12 22:48:20 -04001402 network->listen_interval = 0x0A;
1403 network->rates_len = network->rates_ex_len = 0;
1404 network->last_associate = 0;
1405 network->ssid_len = 0;
1406 network->flags = 0;
1407 network->atim_window = 0;
James Ketrenos42c94e42005-09-21 11:58:29 -05001408 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
James Ketrenosccd0fda2005-09-21 11:58:32 -05001409 0x3 : 0x0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001410
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001411 if (stats->freq == LIBIPW_52GHZ_BAND) {
Jeff Garzikb4538722005-05-12 22:48:20 -04001412 /* for A band (No DS info) */
1413 network->channel = stats->received_channel;
1414 } else
1415 network->flags |= NETWORK_HAS_CCK;
1416
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001417 network->wpa_ie_len = 0;
1418 network->rsn_ie_len = 0;
Jeff Garzikb4538722005-05-12 22:48:20 -04001419
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001420 if (libipw_parse_info_param
James Ketrenosff0037b2005-10-03 10:23:42 -05001421 (beacon->info_element, stats->len - sizeof(*beacon), network))
Ivo van Doornff9e00f2005-10-03 10:19:25 -05001422 return 1;
Jeff Garzikb4538722005-05-12 22:48:20 -04001423
1424 network->mode = 0;
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001425 if (stats->freq == LIBIPW_52GHZ_BAND)
Jeff Garzikb4538722005-05-12 22:48:20 -04001426 network->mode = IEEE_A;
1427 else {
1428 if (network->flags & NETWORK_HAS_OFDM)
1429 network->mode |= IEEE_G;
1430 if (network->flags & NETWORK_HAS_CCK)
1431 network->mode |= IEEE_B;
1432 }
1433
1434 if (network->mode == 0) {
Andy Shevchenko4b4890c2014-10-13 15:55:22 -07001435 LIBIPW_DEBUG_SCAN("Filtered out '%*pE (%pM)' network.\n",
1436 network->ssid_len, network->ssid,
1437 network->bssid);
Jeff Garzikb4538722005-05-12 22:48:20 -04001438 return 1;
1439 }
1440
Jeff Garzikb4538722005-05-12 22:48:20 -04001441 memcpy(&network->stats, stats, sizeof(network->stats));
1442
1443 return 0;
1444}
1445
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001446static inline int is_same_network(struct libipw_network *src,
1447 struct libipw_network *dst)
Jeff Garzikb4538722005-05-12 22:48:20 -04001448{
1449 /* A network is only a duplicate if the channel, BSSID, and ESSID
1450 * all match. We treat all <hidden> with the same BSSID and channel
1451 * as one network */
1452 return ((src->ssid_len == dst->ssid_len) &&
1453 (src->channel == dst->channel) &&
Julia Lawall103671f2013-12-30 19:15:05 +01001454 ether_addr_equal_64bits(src->bssid, dst->bssid) &&
Jeff Garzikb4538722005-05-12 22:48:20 -04001455 !memcmp(src->ssid, dst->ssid, src->ssid_len));
1456}
1457
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001458static void update_network(struct libipw_network *dst,
1459 struct libipw_network *src)
Jeff Garzikb4538722005-05-12 22:48:20 -04001460{
James Ketrenos9e8571a2005-09-21 11:56:33 -05001461 int qos_active;
1462 u8 old_param;
1463
James Ketrenosf44349f2006-03-08 13:14:45 -06001464 /* We only update the statistics if they were created by receiving
1465 * the network information on the actual channel the network is on.
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +09001466 *
James Ketrenosf44349f2006-03-08 13:14:45 -06001467 * This keeps beacons received on neighbor channels from bringing
1468 * down the signal level of an AP. */
1469 if (dst->channel == src->stats.received_channel)
1470 memcpy(&dst->stats, &src->stats,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001471 sizeof(struct libipw_rx_stats));
James Ketrenosf44349f2006-03-08 13:14:45 -06001472 else
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001473 LIBIPW_DEBUG_SCAN("Network %pM info received "
Johannes Berge1749612008-10-27 15:59:26 -07001474 "off channel (%d vs. %d)\n", src->bssid,
James Ketrenosf44349f2006-03-08 13:14:45 -06001475 dst->channel, src->stats.received_channel);
1476
Jeff Garzikb4538722005-05-12 22:48:20 -04001477 dst->capability = src->capability;
1478 memcpy(dst->rates, src->rates, src->rates_len);
1479 dst->rates_len = src->rates_len;
1480 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
1481 dst->rates_ex_len = src->rates_ex_len;
1482
1483 dst->mode = src->mode;
1484 dst->flags = src->flags;
1485 dst->time_stamp[0] = src->time_stamp[0];
1486 dst->time_stamp[1] = src->time_stamp[1];
1487
1488 dst->beacon_interval = src->beacon_interval;
1489 dst->listen_interval = src->listen_interval;
1490 dst->atim_window = src->atim_window;
James Ketrenos42c94e42005-09-21 11:58:29 -05001491 dst->erp_value = src->erp_value;
Zhu Yi41a25c62006-01-19 16:22:23 +08001492 dst->tim = src->tim;
Jeff Garzikb4538722005-05-12 22:48:20 -04001493
1494 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
1495 dst->wpa_ie_len = src->wpa_ie_len;
1496 memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
1497 dst->rsn_ie_len = src->rsn_ie_len;
1498
1499 dst->last_scanned = jiffies;
James Ketrenos9e8571a2005-09-21 11:56:33 -05001500 qos_active = src->qos_data.active;
1501 old_param = dst->qos_data.old_param_count;
1502 if (dst->flags & NETWORK_HAS_QOS_MASK)
1503 memcpy(&dst->qos_data, &src->qos_data,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001504 sizeof(struct libipw_qos_data));
James Ketrenos9e8571a2005-09-21 11:56:33 -05001505 else {
1506 dst->qos_data.supported = src->qos_data.supported;
1507 dst->qos_data.param_count = src->qos_data.param_count;
1508 }
1509
1510 if (dst->qos_data.supported == 1) {
1511 if (dst->ssid_len)
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001512 LIBIPW_DEBUG_QOS
James Ketrenos9e8571a2005-09-21 11:56:33 -05001513 ("QoS the network %s is QoS supported\n",
1514 dst->ssid);
1515 else
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001516 LIBIPW_DEBUG_QOS
James Ketrenos9e8571a2005-09-21 11:56:33 -05001517 ("QoS the network is QoS supported\n");
1518 }
1519 dst->qos_data.active = qos_active;
1520 dst->qos_data.old_param_count = old_param;
1521
Jeff Garzikb4538722005-05-12 22:48:20 -04001522 /* dst->last_associate is not overwritten */
1523}
1524
Pete Zaitcev48328432006-02-26 23:43:20 -08001525static inline int is_beacon(__le16 fc)
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001526{
1527 return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
1528}
1529
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001530static void libipw_process_probe_response(struct libipw_device
James Ketrenos74079fd2005-09-13 17:35:21 -05001531 *ieee, struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001532 libipw_probe_response
1533 *beacon, struct libipw_rx_stats
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001534 *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001535{
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001536 struct net_device *dev = ieee->dev;
Dan Carpenter2aa01652014-10-09 12:57:42 +03001537 struct libipw_network network = { };
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001538 struct libipw_network *target;
1539 struct libipw_network *oldest = NULL;
Helmut Schaa37561622009-03-06 12:02:25 +01001540#ifdef CONFIG_LIBIPW_DEBUG
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001541 struct libipw_info_element *info_element = beacon->info_element;
Jeff Garzikb4538722005-05-12 22:48:20 -04001542#endif
1543 unsigned long flags;
1544
Andy Shevchenko4b4890c2014-10-13 15:55:22 -07001545 LIBIPW_DEBUG_SCAN("'%*pE' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1546 info_element->len, info_element->data,
Johannes Berge1749612008-10-27 15:59:26 -07001547 beacon->header.addr3,
Al Viro8524f592007-12-29 05:03:35 -05001548 (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
1549 (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
1550 (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
1551 (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
1552 (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
1553 (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
1554 (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
1555 (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
1556 (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
1557 (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
1558 (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
1559 (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
1560 (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
1561 (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
1562 (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
1563 (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
Jeff Garzikb4538722005-05-12 22:48:20 -04001564
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001565 if (libipw_network_init(ieee, beacon, &network, stats)) {
Andy Shevchenko4b4890c2014-10-13 15:55:22 -07001566 LIBIPW_DEBUG_SCAN("Dropped '%*pE' (%pM) via %s.\n",
1567 info_element->len, info_element->data,
1568 beacon->header.addr3,
1569 is_beacon(beacon->header.frame_ctl) ?
1570 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001571 return;
1572 }
1573
1574 /* The network parsed correctly -- so now we scan our known networks
1575 * to see if we can find it in our list.
1576 *
1577 * NOTE: This search is definitely not optimized. Once its doing
1578 * the "right thing" we'll optimize it for efficiency if
1579 * necessary */
1580
1581 /* Search for this entry in the list and update it if it is
1582 * already there. */
1583
1584 spin_lock_irqsave(&ieee->lock, flags);
1585
1586 list_for_each_entry(target, &ieee->network_list, list) {
1587 if (is_same_network(target, &network))
1588 break;
1589
1590 if ((oldest == NULL) ||
Dan Williamsc3d72b92009-02-11 13:26:06 -05001591 time_before(target->last_scanned, oldest->last_scanned))
Jeff Garzikb4538722005-05-12 22:48:20 -04001592 oldest = target;
1593 }
1594
1595 /* If we didn't find a match, then get a new network slot to initialize
1596 * with this beacon's information */
1597 if (&target->list == &ieee->network_list) {
1598 if (list_empty(&ieee->network_free_list)) {
1599 /* If there are no more slots, expire the oldest */
1600 list_del(&oldest->list);
1601 target = oldest;
Andy Shevchenko4b4890c2014-10-13 15:55:22 -07001602 LIBIPW_DEBUG_SCAN("Expired '%*pE' (%pM) from network list.\n",
1603 target->ssid_len, target->ssid,
1604 target->bssid);
Jeff Garzikb4538722005-05-12 22:48:20 -04001605 } else {
1606 /* Otherwise just pull from the free list */
1607 target = list_entry(ieee->network_free_list.next,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001608 struct libipw_network, list);
Jeff Garzikb4538722005-05-12 22:48:20 -04001609 list_del(ieee->network_free_list.next);
1610 }
1611
Helmut Schaa37561622009-03-06 12:02:25 +01001612#ifdef CONFIG_LIBIPW_DEBUG
Andy Shevchenko4b4890c2014-10-13 15:55:22 -07001613 LIBIPW_DEBUG_SCAN("Adding '%*pE' (%pM) via %s.\n",
1614 network.ssid_len, network.ssid,
1615 network.bssid,
1616 is_beacon(beacon->header.frame_ctl) ?
1617 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001618#endif
1619 memcpy(target, &network, sizeof(*target));
1620 list_add_tail(&target->list, &ieee->network_list);
1621 } else {
Andy Shevchenko4b4890c2014-10-13 15:55:22 -07001622 LIBIPW_DEBUG_SCAN("Updating '%*pE' (%pM) via %s.\n",
1623 target->ssid_len, target->ssid,
1624 target->bssid,
1625 is_beacon(beacon->header.frame_ctl) ?
1626 "BEACON" : "PROBE RESPONSE");
Jeff Garzikb4538722005-05-12 22:48:20 -04001627 update_network(target, &network);
1628 }
1629
1630 spin_unlock_irqrestore(&ieee->lock, flags);
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001631
Pete Zaitcev48328432006-02-26 23:43:20 -08001632 if (is_beacon(beacon->header.frame_ctl)) {
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001633 if (ieee->handle_beacon != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001634 ieee->handle_beacon(dev, beacon, target);
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001635 } else {
1636 if (ieee->handle_probe_response != NULL)
Hong Liu72df16f2006-03-08 10:50:20 +08001637 ieee->handle_probe_response(dev, beacon, target);
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001638 }
Jeff Garzikb4538722005-05-12 22:48:20 -04001639}
1640
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001641void libipw_rx_mgt(struct libipw_device *ieee,
1642 struct libipw_hdr_4addr *header,
1643 struct libipw_rx_stats *stats)
Jeff Garzikb4538722005-05-12 22:48:20 -04001644{
James Ketrenosfd278172005-09-13 17:25:51 -05001645 switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
Jeff Garzikb4538722005-05-12 22:48:20 -04001646 case IEEE80211_STYPE_ASSOC_RESP:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001647 LIBIPW_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001648 WLAN_FC_GET_STYPE(le16_to_cpu
1649 (header->frame_ctl)));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001650 libipw_handle_assoc_resp(ieee,
1651 (struct libipw_assoc_response *)
James Ketrenos9e8571a2005-09-21 11:56:33 -05001652 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001653 break;
1654
1655 case IEEE80211_STYPE_REASSOC_RESP:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001656 LIBIPW_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001657 WLAN_FC_GET_STYPE(le16_to_cpu
1658 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001659 break;
1660
James Ketrenos42c94e42005-09-21 11:58:29 -05001661 case IEEE80211_STYPE_PROBE_REQ:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001662 LIBIPW_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos42c94e42005-09-21 11:58:29 -05001663 WLAN_FC_GET_STYPE(le16_to_cpu
1664 (header->frame_ctl)));
1665
1666 if (ieee->handle_probe_request != NULL)
1667 ieee->handle_probe_request(ieee->dev,
1668 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001669 libipw_probe_request *)
James Ketrenos42c94e42005-09-21 11:58:29 -05001670 header, stats);
1671 break;
1672
Jeff Garzikb4538722005-05-12 22:48:20 -04001673 case IEEE80211_STYPE_PROBE_RESP:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001674 LIBIPW_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001675 WLAN_FC_GET_STYPE(le16_to_cpu
1676 (header->frame_ctl)));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001677 LIBIPW_DEBUG_SCAN("Probe response\n");
1678 libipw_process_probe_response(ieee,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001679 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001680 libipw_probe_response *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001681 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001682 break;
1683
1684 case IEEE80211_STYPE_BEACON:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001685 LIBIPW_DEBUG_MGMT("received BEACON (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001686 WLAN_FC_GET_STYPE(le16_to_cpu
1687 (header->frame_ctl)));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001688 LIBIPW_DEBUG_SCAN("Beacon\n");
1689 libipw_process_probe_response(ieee,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001690 (struct
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001691 libipw_probe_response *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001692 header, stats);
Jeff Garzikb4538722005-05-12 22:48:20 -04001693 break;
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001694 case IEEE80211_STYPE_AUTH:
1695
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001696 LIBIPW_DEBUG_MGMT("received auth (%d)\n",
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001697 WLAN_FC_GET_STYPE(le16_to_cpu
1698 (header->frame_ctl)));
1699
1700 if (ieee->handle_auth != NULL)
1701 ieee->handle_auth(ieee->dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001702 (struct libipw_auth *)header);
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001703 break;
1704
1705 case IEEE80211_STYPE_DISASSOC:
1706 if (ieee->handle_disassoc != NULL)
1707 ieee->handle_disassoc(ieee->dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001708 (struct libipw_disassoc *)
James Ketrenos3f552bbf2005-09-21 11:54:47 -05001709 header);
1710 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001711
Zhu Yid1b46b02006-01-19 16:22:15 +08001712 case IEEE80211_STYPE_ACTION:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001713 LIBIPW_DEBUG_MGMT("ACTION\n");
Zhu Yid1b46b02006-01-19 16:22:15 +08001714 if (ieee->handle_action)
1715 ieee->handle_action(ieee->dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001716 (struct libipw_action *)
Zhu Yid1b46b02006-01-19 16:22:15 +08001717 header, stats);
1718 break;
1719
Larry Finger2f633db2006-01-30 23:25:10 -06001720 case IEEE80211_STYPE_REASSOC_REQ:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001721 LIBIPW_DEBUG_MGMT("received reassoc (%d)\n",
Larry Finger2f633db2006-01-30 23:25:10 -06001722 WLAN_FC_GET_STYPE(le16_to_cpu
1723 (header->frame_ctl)));
1724
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001725 LIBIPW_DEBUG_MGMT("%s: LIBIPW_REASSOC_REQ received\n",
Zhu Yi7736b5b2006-04-13 17:17:47 +08001726 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001727 if (ieee->handle_reassoc_request != NULL)
1728 ieee->handle_reassoc_request(ieee->dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001729 (struct libipw_reassoc_request *)
Larry Finger2f633db2006-01-30 23:25:10 -06001730 header);
1731 break;
1732
1733 case IEEE80211_STYPE_ASSOC_REQ:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001734 LIBIPW_DEBUG_MGMT("received assoc (%d)\n",
Larry Finger2f633db2006-01-30 23:25:10 -06001735 WLAN_FC_GET_STYPE(le16_to_cpu
1736 (header->frame_ctl)));
1737
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001738 LIBIPW_DEBUG_MGMT("%s: LIBIPW_ASSOC_REQ received\n",
Zhu Yi7736b5b2006-04-13 17:17:47 +08001739 ieee->dev->name);
Larry Finger2f633db2006-01-30 23:25:10 -06001740 if (ieee->handle_assoc_request != NULL)
1741 ieee->handle_assoc_request(ieee->dev);
1742 break;
1743
James Ketrenos31b59ea2005-09-21 11:58:49 -05001744 case IEEE80211_STYPE_DEAUTH:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001745 LIBIPW_DEBUG_MGMT("DEAUTH\n");
James Ketrenos31b59ea2005-09-21 11:58:49 -05001746 if (ieee->handle_deauth != NULL)
Zhu Yid1b46b02006-01-19 16:22:15 +08001747 ieee->handle_deauth(ieee->dev,
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001748 (struct libipw_deauth *)
James Ketrenos31b59ea2005-09-21 11:58:49 -05001749 header);
1750 break;
Jeff Garzikb4538722005-05-12 22:48:20 -04001751 default:
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001752 LIBIPW_DEBUG_MGMT("received UNKNOWN (%d)\n",
James Ketrenosfd278172005-09-13 17:25:51 -05001753 WLAN_FC_GET_STYPE(le16_to_cpu
1754 (header->frame_ctl)));
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001755 LIBIPW_DEBUG_MGMT("%s: Unknown management packet: %d\n",
Zhu Yi7736b5b2006-04-13 17:17:47 +08001756 ieee->dev->name,
1757 WLAN_FC_GET_STYPE(le16_to_cpu
1758 (header->frame_ctl)));
Jeff Garzikb4538722005-05-12 22:48:20 -04001759 break;
1760 }
1761}
1762
John W. Linvilleb0a4e7d2009-08-20 14:48:03 -04001763EXPORT_SYMBOL_GPL(libipw_rx_any);
1764EXPORT_SYMBOL(libipw_rx_mgt);
1765EXPORT_SYMBOL(libipw_rx);