2005-05-13 10:48:20 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2005-09-22 00:58:43 +08:00
|
|
|
Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
Portions of this file are based on the WEP enablement code provided by the
|
|
|
|
Host AP project hostap-drivers v0.1.3
|
|
|
|
Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
|
2007-03-25 08:15:30 +08:00
|
|
|
<j@w1.fi>
|
|
|
|
Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of version 2 of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
The full GNU General Public License is included in this distribution in the
|
|
|
|
file called LICENSE.
|
|
|
|
|
|
|
|
Contact Information:
|
2009-08-22 04:34:26 +08:00
|
|
|
Intel Linux Wireless <ilw@linux.intel.com>
|
2005-05-13 10:48:20 +08:00
|
|
|
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/in6.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/wireless.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <asm/uaccess.h>
|
2007-09-12 18:01:34 +08:00
|
|
|
#include <net/net_namespace.h>
|
2005-05-13 10:48:20 +08:00
|
|
|
#include <net/arp.h>
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
#include "libipw.h"
|
2005-05-13 10:48:20 +08:00
|
|
|
|
2005-09-22 00:58:46 +08:00
|
|
|
#define DRV_DESCRIPTION "802.11 data/management/control stack"
|
|
|
|
#define DRV_NAME "ieee80211"
|
2009-08-21 02:48:03 +08:00
|
|
|
#define DRV_VERSION LIBIPW_VERSION
|
2005-09-22 00:58:46 +08:00
|
|
|
#define DRV_COPYRIGHT "Copyright (C) 2004-2005 Intel Corporation <jketreno@linux.intel.com>"
|
|
|
|
|
|
|
|
MODULE_VERSION(DRV_VERSION);
|
|
|
|
MODULE_DESCRIPTION(DRV_DESCRIPTION);
|
|
|
|
MODULE_AUTHOR(DRV_COPYRIGHT);
|
2005-05-13 10:48:20 +08:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
static int libipw_networks_allocate(struct libipw_device *ieee)
|
2005-05-13 10:48:20 +08:00
|
|
|
{
|
|
|
|
if (ieee->networks)
|
|
|
|
return 0;
|
|
|
|
|
2005-09-07 12:48:31 +08:00
|
|
|
ieee->networks =
|
2009-08-21 02:48:03 +08:00
|
|
|
kzalloc(MAX_NETWORK_COUNT * sizeof(struct libipw_network),
|
2005-09-07 12:48:31 +08:00
|
|
|
GFP_KERNEL);
|
2005-05-13 10:48:20 +08:00
|
|
|
if (!ieee->networks) {
|
|
|
|
printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
|
|
|
|
ieee->dev->name);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
void libipw_network_reset(struct libipw_network *network)
|
2006-01-19 16:21:35 +08:00
|
|
|
{
|
|
|
|
if (!network)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (network->ibss_dfs) {
|
|
|
|
kfree(network->ibss_dfs);
|
|
|
|
network->ibss_dfs = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
static inline void libipw_networks_free(struct libipw_device *ieee)
|
2005-05-13 10:48:20 +08:00
|
|
|
{
|
2006-01-19 16:21:35 +08:00
|
|
|
int i;
|
|
|
|
|
2005-05-13 10:48:20 +08:00
|
|
|
if (!ieee->networks)
|
|
|
|
return;
|
2006-01-19 16:21:35 +08:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_NETWORK_COUNT; i++)
|
|
|
|
if (ieee->networks[i].ibss_dfs)
|
|
|
|
kfree(ieee->networks[i].ibss_dfs);
|
|
|
|
|
2005-05-13 10:48:20 +08:00
|
|
|
kfree(ieee->networks);
|
|
|
|
ieee->networks = NULL;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
void libipw_networks_age(struct libipw_device *ieee,
|
2009-02-12 02:26:06 +08:00
|
|
|
unsigned long age_secs)
|
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
struct libipw_network *network = NULL;
|
2009-02-12 02:26:06 +08:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ieee->lock, flags);
|
|
|
|
list_for_each_entry(network, &ieee->network_list, list) {
|
|
|
|
network->last_scanned -= age_jiffies;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&ieee->lock, flags);
|
|
|
|
}
|
2009-08-21 02:48:03 +08:00
|
|
|
EXPORT_SYMBOL(libipw_networks_age);
|
2009-02-12 02:26:06 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
static void libipw_networks_initialize(struct libipw_device *ieee)
|
2005-05-13 10:48:20 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ieee->network_free_list);
|
|
|
|
INIT_LIST_HEAD(&ieee->network_list);
|
|
|
|
for (i = 0; i < MAX_NETWORK_COUNT; i++)
|
2005-09-07 12:48:31 +08:00
|
|
|
list_add_tail(&ieee->networks[i].list,
|
|
|
|
&ieee->network_free_list);
|
2005-05-13 10:48:20 +08:00
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
int libipw_change_mtu(struct net_device *dev, int new_mtu)
|
2006-09-29 01:57:25 +08:00
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
if ((new_mtu < 68) || (new_mtu > LIBIPW_DATA_LEN))
|
2006-09-29 01:57:25 +08:00
|
|
|
return -EINVAL;
|
|
|
|
dev->mtu = new_mtu;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-21 02:48:03 +08:00
|
|
|
EXPORT_SYMBOL(libipw_change_mtu);
|
2006-09-29 01:57:25 +08:00
|
|
|
|
2009-11-14 05:56:13 +08:00
|
|
|
struct net_device *alloc_ieee80211(int sizeof_priv)
|
2005-05-13 10:48:20 +08:00
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
struct libipw_device *ieee;
|
2005-05-13 10:48:20 +08:00
|
|
|
struct net_device *dev;
|
|
|
|
int err;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
LIBIPW_DEBUG_INFO("Initializing...\n");
|
2005-05-13 10:48:20 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
dev = alloc_etherdev(sizeof(struct libipw_device) + sizeof_priv);
|
2005-05-13 10:48:20 +08:00
|
|
|
if (!dev) {
|
2009-08-21 02:48:03 +08:00
|
|
|
LIBIPW_ERROR("Unable to allocate network device.\n");
|
2005-05-13 10:48:20 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
ieee = netdev_priv(dev);
|
|
|
|
|
|
|
|
ieee->dev = dev;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
err = libipw_networks_allocate(ieee);
|
2005-05-13 10:48:20 +08:00
|
|
|
if (err) {
|
2009-08-21 02:48:03 +08:00
|
|
|
LIBIPW_ERROR("Unable to allocate beacon storage: %d\n", err);
|
2009-11-14 05:56:13 +08:00
|
|
|
goto failed_free_netdev;
|
2005-05-13 10:48:20 +08:00
|
|
|
}
|
2009-08-21 02:48:03 +08:00
|
|
|
libipw_networks_initialize(ieee);
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
/* Default fragmentation threshold is maximum payload size */
|
|
|
|
ieee->fts = DEFAULT_FTS;
|
2005-09-22 00:54:43 +08:00
|
|
|
ieee->rts = DEFAULT_FTS;
|
2005-05-13 10:48:20 +08:00
|
|
|
ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
|
|
|
|
ieee->open_wep = 1;
|
|
|
|
|
|
|
|
/* Default to enabling full open WEP with host based encrypt/decrypt */
|
|
|
|
ieee->host_encrypt = 1;
|
|
|
|
ieee->host_decrypt = 1;
|
2005-09-22 00:58:32 +08:00
|
|
|
ieee->host_mc_decrypt = 1;
|
|
|
|
|
2005-09-22 00:54:53 +08:00
|
|
|
/* Host fragementation in Open mode. Default is enabled.
|
|
|
|
* Note: host fragmentation is always enabled if host encryption
|
|
|
|
* is enabled. For cards can do hardware encryption, they must do
|
|
|
|
* hardware fragmentation as well. So we don't need a variable
|
|
|
|
* like host_enc_frag. */
|
|
|
|
ieee->host_open_frag = 1;
|
2005-09-07 12:48:31 +08:00
|
|
|
ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
spin_lock_init(&ieee->lock);
|
|
|
|
|
2008-11-12 05:00:06 +08:00
|
|
|
lib80211_crypt_info_init(&ieee->crypt_info, dev->name, &ieee->lock);
|
2008-10-29 23:35:05 +08:00
|
|
|
|
2005-09-07 12:48:31 +08:00
|
|
|
ieee->wpa_enabled = 0;
|
|
|
|
ieee->drop_unencrypted = 0;
|
|
|
|
ieee->privacy_invoked = 0;
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
return dev;
|
|
|
|
|
2008-07-16 22:34:54 +08:00
|
|
|
failed_free_netdev:
|
|
|
|
free_netdev(dev);
|
|
|
|
failed:
|
2005-05-13 10:48:20 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-14 05:56:13 +08:00
|
|
|
void free_ieee80211(struct net_device *dev)
|
2005-05-13 10:48:20 +08:00
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
struct libipw_device *ieee = netdev_priv(dev);
|
2005-05-13 10:48:20 +08:00
|
|
|
|
2008-11-12 05:00:06 +08:00
|
|
|
lib80211_crypt_info_free(&ieee->crypt_info);
|
2005-05-13 10:48:20 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
libipw_networks_free(ieee);
|
2005-05-13 10:48:20 +08:00
|
|
|
free_netdev(dev);
|
|
|
|
}
|
|
|
|
|
2009-03-06 19:02:25 +08:00
|
|
|
#ifdef CONFIG_LIBIPW_DEBUG
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
static int debug = 0;
|
2009-08-21 02:48:03 +08:00
|
|
|
u32 libipw_debug_level = 0;
|
|
|
|
EXPORT_SYMBOL_GPL(libipw_debug_level);
|
|
|
|
static struct proc_dir_entry *libipw_proc = NULL;
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
static int show_debug_level(char *page, char **start, off_t offset,
|
|
|
|
int count, int *eof, void *data)
|
|
|
|
{
|
2009-08-21 02:48:03 +08:00
|
|
|
return snprintf(page, count, "0x%08X\n", libipw_debug_level);
|
2005-05-13 10:48:20 +08:00
|
|
|
}
|
|
|
|
|
2005-09-07 12:48:31 +08:00
|
|
|
static int store_debug_level(struct file *file, const char __user * buffer,
|
2005-05-13 10:48:20 +08:00
|
|
|
unsigned long count, void *data)
|
|
|
|
{
|
2005-09-14 06:42:53 +08:00
|
|
|
char buf[] = "0x00000000\n";
|
|
|
|
unsigned long len = min((unsigned long)sizeof(buf) - 1, count);
|
2005-05-13 10:48:20 +08:00
|
|
|
unsigned long val;
|
|
|
|
|
2005-09-14 06:42:53 +08:00
|
|
|
if (copy_from_user(buf, buffer, len))
|
2005-05-13 10:48:20 +08:00
|
|
|
return count;
|
2005-09-14 06:42:53 +08:00
|
|
|
buf[len] = 0;
|
|
|
|
if (sscanf(buf, "%li", &val) != 1)
|
2005-05-13 10:48:20 +08:00
|
|
|
printk(KERN_INFO DRV_NAME
|
|
|
|
": %s is not in hex or decimal form.\n", buf);
|
|
|
|
else
|
2009-08-21 02:48:03 +08:00
|
|
|
libipw_debug_level = val;
|
2005-05-13 10:48:20 +08:00
|
|
|
|
2005-09-14 06:42:53 +08:00
|
|
|
return strnlen(buf, len);
|
2005-05-13 10:48:20 +08:00
|
|
|
}
|
2009-03-06 19:02:25 +08:00
|
|
|
#endif /* CONFIG_LIBIPW_DEBUG */
|
2005-05-13 10:48:20 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
static int __init libipw_init(void)
|
2005-05-13 10:48:20 +08:00
|
|
|
{
|
2009-03-06 19:02:25 +08:00
|
|
|
#ifdef CONFIG_LIBIPW_DEBUG
|
2005-05-13 10:48:20 +08:00
|
|
|
struct proc_dir_entry *e;
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
libipw_debug_level = debug;
|
|
|
|
libipw_proc = proc_mkdir(DRV_NAME, init_net.proc_net);
|
|
|
|
if (libipw_proc == NULL) {
|
|
|
|
LIBIPW_ERROR("Unable to create " DRV_NAME
|
2005-05-13 10:48:20 +08:00
|
|
|
" proc directory\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
e = create_proc_entry("debug_level", S_IFREG | S_IRUGO | S_IWUSR,
|
2009-08-21 02:48:03 +08:00
|
|
|
libipw_proc);
|
2005-05-13 10:48:20 +08:00
|
|
|
if (!e) {
|
2007-09-12 18:01:34 +08:00
|
|
|
remove_proc_entry(DRV_NAME, init_net.proc_net);
|
2009-08-21 02:48:03 +08:00
|
|
|
libipw_proc = NULL;
|
2005-05-13 10:48:20 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
e->read_proc = show_debug_level;
|
|
|
|
e->write_proc = store_debug_level;
|
|
|
|
e->data = NULL;
|
2009-03-06 19:02:25 +08:00
|
|
|
#endif /* CONFIG_LIBIPW_DEBUG */
|
2005-09-22 00:58:46 +08:00
|
|
|
|
|
|
|
printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
|
|
|
|
printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
static void __exit libipw_exit(void)
|
2005-05-13 10:48:20 +08:00
|
|
|
{
|
2009-03-06 19:02:25 +08:00
|
|
|
#ifdef CONFIG_LIBIPW_DEBUG
|
2009-08-21 02:48:03 +08:00
|
|
|
if (libipw_proc) {
|
|
|
|
remove_proc_entry("debug_level", libipw_proc);
|
2007-09-12 18:01:34 +08:00
|
|
|
remove_proc_entry(DRV_NAME, init_net.proc_net);
|
2009-08-21 02:48:03 +08:00
|
|
|
libipw_proc = NULL;
|
2005-05-13 10:48:20 +08:00
|
|
|
}
|
2009-03-06 19:02:25 +08:00
|
|
|
#endif /* CONFIG_LIBIPW_DEBUG */
|
2005-05-13 10:48:20 +08:00
|
|
|
}
|
|
|
|
|
2009-03-06 19:02:25 +08:00
|
|
|
#ifdef CONFIG_LIBIPW_DEBUG
|
2005-05-13 10:48:20 +08:00
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
module_param(debug, int, 0444);
|
|
|
|
MODULE_PARM_DESC(debug, "debug output mask");
|
2009-03-06 19:02:25 +08:00
|
|
|
#endif /* CONFIG_LIBIPW_DEBUG */
|
2005-05-13 10:48:20 +08:00
|
|
|
|
2009-08-21 02:48:03 +08:00
|
|
|
module_exit(libipw_exit);
|
|
|
|
module_init(libipw_init);
|
2005-05-13 10:48:20 +08:00
|
|
|
|
|
|
|
EXPORT_SYMBOL(alloc_ieee80211);
|
|
|
|
EXPORT_SYMBOL(free_ieee80211);
|