replace device in wlcompat(non-debug), add wlcompat.h and refuse to load wlcompat.o if a wireless extension already exists

SVN-Revision: 882
This commit is contained in:
Felix Fietkau 2005-05-13 19:01:32 +00:00
parent 2ab5d1e15c
commit 5a5a839dc6
2 changed files with 82 additions and 49 deletions

View File

@ -0,0 +1,32 @@
/*
* wlcompat.h
*
* Copyright (C) 2005 Felix Fietkau <nbd@vd-s.ath.cx>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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.
*
* $Id$
*/
#include <linux/wireless.h>
#ifndef WLCOMPAT_H
#define WLCOMPAT_H
#define WLCOMPAT_SET_MONITOR SIOCIWFIRSTPRIV + 0
#define WLCOMPAT_GET_MONITOR SIOCIWFIRSTPRIV + 1
#define WLCOMPAT_SET_TXPWR_LIMIT SIOCIWFIRSTPRIV + 2
#define WLCOMPAT_GET_TXPWR_LIMIT SIOCIWFIRSTPRIV + 3
#endif

View File

@ -31,6 +31,7 @@
#include <net/iw_handler.h> #include <net/iw_handler.h>
#include <wlioctl.h> #include <wlioctl.h>
#include <wlcompat.h>
static struct net_device *dev; static struct net_device *dev;
char buf[WLC_IOCTL_MAXLEN]; char buf[WLC_IOCTL_MAXLEN];
@ -549,35 +550,6 @@ static const iw_handler wlcompat_handler[] = {
wlcompat_ioctl, /* SIOCGIWENCODE */ wlcompat_ioctl, /* SIOCGIWENCODE */
}; };
#define PRIV_SET_MONITOR SIOCIWFIRSTPRIV + 0
#define PRIV_GET_MONITOR SIOCIWFIRSTPRIV + 1
#define PRIV_SET_TXPWR_LIMIT SIOCIWFIRSTPRIV + 2
#define PRIV_GET_TXPWR_LIMIT SIOCIWFIRSTPRIV + 3
static const struct iw_priv_args wlcompat_private_args[] =
{
{ PRIV_SET_MONITOR,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
0,
"set_monitor"
},
{ PRIV_GET_MONITOR,
0,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
"get_monitor"
},
{ PRIV_SET_TXPWR_LIMIT,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
0,
"set_txpwr_force"
},
{ PRIV_GET_TXPWR_LIMIT,
0,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
"get_txpwr_force"
}
};
static int wlcompat_private_ioctl(struct net_device *dev, static int wlcompat_private_ioctl(struct net_device *dev,
struct iw_request_info *info, struct iw_request_info *info,
union iwreq_data *wrqu, union iwreq_data *wrqu,
@ -586,21 +558,21 @@ static int wlcompat_private_ioctl(struct net_device *dev,
int *value = (int *) wrqu->name; int *value = (int *) wrqu->name;
switch (info->cmd) { switch (info->cmd) {
case PRIV_SET_MONITOR: case WLCOMPAT_SET_MONITOR:
{ {
if (wl_ioctl(dev, WLC_SET_MONITOR, value, sizeof(int)) < 0) if (wl_ioctl(dev, WLC_SET_MONITOR, value, sizeof(int)) < 0)
return -EINVAL; return -EINVAL;
break; break;
} }
case PRIV_GET_MONITOR: case WLCOMPAT_GET_MONITOR:
{ {
if (wl_ioctl(dev, WLC_GET_MONITOR, extra, sizeof(int)) < 0) if (wl_ioctl(dev, WLC_GET_MONITOR, extra, sizeof(int)) < 0)
return -EINVAL; return -EINVAL;
break; break;
} }
case PRIV_SET_TXPWR_LIMIT: case WLCOMPAT_SET_TXPWR_LIMIT:
{ {
int val; int val;
@ -618,7 +590,7 @@ static int wlcompat_private_ioctl(struct net_device *dev,
break; break;
} }
case PRIV_GET_TXPWR_LIMIT: case WLCOMPAT_GET_TXPWR_LIMIT:
{ {
if (wl_get_val(dev, "qtxpower", value, sizeof(int)) < 0) if (wl_get_val(dev, "qtxpower", value, sizeof(int)) < 0)
return -EINVAL; return -EINVAL;
@ -636,13 +608,34 @@ static int wlcompat_private_ioctl(struct net_device *dev,
return 0; return 0;
} }
static const struct iw_priv_args wlcompat_private_args[] =
{
{ WLCOMPAT_SET_MONITOR,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
0,
"set_monitor"
},
{ WLCOMPAT_GET_MONITOR,
0,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
"get_monitor"
},
{ WLCOMPAT_SET_TXPWR_LIMIT,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
0,
"set_txpwr_force"
},
{ WLCOMPAT_GET_TXPWR_LIMIT,
0,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
"get_txpwr_force"
}
};
static const iw_handler wlcompat_private[] = static const iw_handler wlcompat_private[] =
{ {
wlcompat_private_ioctl, wlcompat_private_ioctl,
wlcompat_private_ioctl, NULL
wlcompat_private_ioctl,
wlcompat_private_ioctl
}; };
@ -651,14 +644,13 @@ static const struct iw_handler_def wlcompat_handler_def =
.standard = (iw_handler *) wlcompat_handler, .standard = (iw_handler *) wlcompat_handler,
.num_standard = sizeof(wlcompat_handler)/sizeof(iw_handler), .num_standard = sizeof(wlcompat_handler)/sizeof(iw_handler),
.private = wlcompat_private, .private = wlcompat_private,
.num_private = sizeof(wlcompat_private)/sizeof(iw_handler), .num_private = 1,
.private_args = wlcompat_private_args, .private_args = wlcompat_private_args,
.num_private_args = sizeof(wlcompat_private_args)/sizeof(struct iw_priv_args), .num_private_args = sizeof(wlcompat_private_args) / sizeof(wlcompat_private_args[0])
}; };
#ifdef DEBUG #ifdef DEBUG
static int (*old_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
void print_buffer(int len, unsigned char *buf) { void print_buffer(int len, unsigned char *buf) {
int x; int x;
if (buf != NULL) { if (buf != NULL) {
@ -673,10 +665,23 @@ void print_buffer(int len, unsigned char *buf) {
printk("\n"); printk("\n");
} }
#endif
static int (*old_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {
int ret = 0; int ret = 0;
struct iwreq *iwr = (struct iwreq *) ifr;
struct iw_request_info info;
#ifdef DEBUG
printk("dev: %s ioctl: 0x%04x\n",dev->name,cmd); printk("dev: %s ioctl: 0x%04x\n",dev->name,cmd);
if (cmd==SIOCDEVPRIVATE) { #endif
if (cmd >= SIOCIWFIRSTPRIV) {
info.cmd = cmd;
info.flags = 0;
ret = wlcompat_private_ioctl(dev, &info, &(iwr->u), (char *) &(iwr->u));
#ifdef DEBUG
} else if (cmd==SIOCDEVPRIVATE) {
wl_ioctl_t *ioc = (wl_ioctl_t *)ifr->ifr_data; wl_ioctl_t *ioc = (wl_ioctl_t *)ifr->ifr_data;
unsigned char *buf = ioc->buf; unsigned char *buf = ioc->buf;
printk(" cmd: %d buf: 0x%08x len: %d\n",ioc->cmd,&(ioc->buf),ioc->len); printk(" cmd: %d buf: 0x%08x len: %d\n",ioc->cmd,&(ioc->buf),ioc->len);
@ -686,12 +691,12 @@ static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {
printk(" recv: ->"); printk(" recv: ->");
print_buffer(ioc->len, buf); print_buffer(ioc->len, buf);
printk(" ret: %d\n", ret); printk(" ret: %d\n", ret);
#endif
} else { } else {
ret = old_ioctl(dev,ifr,cmd); ret = old_ioctl(dev,ifr,cmd);
} }
return ret; return ret;
} }
#endif
static int __init wlcompat_init() static int __init wlcompat_init()
{ {
@ -699,7 +704,7 @@ static int __init wlcompat_init()
char *devname = "eth0"; char *devname = "eth0";
while (!found && (dev = dev_get_by_name(devname))) { while (!found && (dev = dev_get_by_name(devname))) {
if ((wl_ioctl(dev, WLC_GET_MAGIC, &i, sizeof(i)) == 0) && i == WLC_IOCTL_MAGIC) if ((dev->wireless_handlers == NULL) && ((wl_ioctl(dev, WLC_GET_MAGIC, &i, sizeof(i)) == 0) && i == WLC_IOCTL_MAGIC))
found = 1; found = 1;
devname[3]++; devname[3]++;
} }
@ -710,10 +715,8 @@ static int __init wlcompat_init()
} }
#ifdef DEBUG
old_ioctl = dev->do_ioctl; old_ioctl = dev->do_ioctl;
dev->do_ioctl = new_ioctl; dev->do_ioctl = new_ioctl;
#endif
dev->wireless_handlers = (struct iw_handler_def *)&wlcompat_handler_def; dev->wireless_handlers = (struct iw_handler_def *)&wlcompat_handler_def;
return 0; return 0;
} }
@ -721,9 +724,7 @@ static int __init wlcompat_init()
static void __exit wlcompat_exit() static void __exit wlcompat_exit()
{ {
dev->wireless_handlers = NULL; dev->wireless_handlers = NULL;
#ifdef DEBUG
dev->do_ioctl = old_ioctl; dev->do_ioctl = old_ioctl;
#endif
return; return;
} }