X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/d2f4cca420ecfa2410a7c8149dd342ab3901848e..2f2baa370c8842267f137d38c8c79ebd06a3ab00:/package/openwrt/wlcompat.c diff --git a/package/openwrt/wlcompat.c b/package/openwrt/wlcompat.c index fdcb36cc9..01bfb0b43 100644 --- a/package/openwrt/wlcompat.c +++ b/package/openwrt/wlcompat.c @@ -31,6 +31,7 @@ #include #include +#include static struct net_device *dev; char buf[WLC_IOCTL_MAXLEN]; @@ -42,6 +43,8 @@ const long channel_frequency[] = { }; #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) ) + + static int wlcompat_private_ioctl(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, @@ -100,6 +103,13 @@ static int wl_get_val(struct net_device *dev, char *var, void *val, int len) return 0; } +int read_shmem(struct net_device *dev, int offset) +{ + if (wl_ioctl(dev, WLC_GET_SHMEM, &offset, sizeof(offset)) < 0) + return -EINVAL; + + return offset; +} static int wlcompat_ioctl_getiwrange(struct net_device *dev, char *extra) @@ -396,17 +406,43 @@ static int wlcompat_ioctl(struct net_device *dev, } case SIOCGIWENCODE: { - int val = 0; + int val; + if (wl_ioctl(dev, WLC_GET_WEP, &val, sizeof(val)) < 0) return -EINVAL; + if (val > 0) { - wrqu->data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; + int key; + + for (key = val = 0; (key < 4) && (val == 0); key++) { + val = key; + if (wl_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val)) < 0) + return -EINVAL; + } + + wrqu->data.flags = IW_ENCODE_ENABLED; + if (key-- > 0) { + int magic_offset; + int16 buffer[8]; + + magic_offset = read_shmem(dev, 0x56) * 2; + + wrqu->data.flags |= key + 1; + wrqu->data.length = 16; + + for (val = 0; val < 8; val++) { + buffer[val] = read_shmem(dev, magic_offset + (key * 16) + val * 2); + } + + memset(extra, 0, 16); + memcpy(extra, buffer, 16); + } else { + wrqu->data.flags |= IW_ENCODE_NOKEY; + } } else { wrqu->data.flags = IW_ENCODE_DISABLED; } - - break; } @@ -549,35 +585,6 @@ static const iw_handler wlcompat_handler[] = { 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_limit" - }, - { PRIV_GET_TXPWR_LIMIT, - 0, - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, - "get_txpwr_limit" - } -}; - static int wlcompat_private_ioctl(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, @@ -586,21 +593,21 @@ static int wlcompat_private_ioctl(struct net_device *dev, int *value = (int *) wrqu->name; switch (info->cmd) { - case PRIV_SET_MONITOR: + case WLCOMPAT_SET_MONITOR: { if (wl_ioctl(dev, WLC_SET_MONITOR, value, sizeof(int)) < 0) return -EINVAL; break; } - case PRIV_GET_MONITOR: + case WLCOMPAT_GET_MONITOR: { if (wl_ioctl(dev, WLC_GET_MONITOR, extra, sizeof(int)) < 0) return -EINVAL; break; } - case PRIV_SET_TXPWR_LIMIT: + case WLCOMPAT_SET_TXPWR_LIMIT: { int val; @@ -618,7 +625,7 @@ static int wlcompat_private_ioctl(struct net_device *dev, break; } - case PRIV_GET_TXPWR_LIMIT: + case WLCOMPAT_GET_TXPWR_LIMIT: { if (wl_get_val(dev, "qtxpower", value, sizeof(int)) < 0) return -EINVAL; @@ -627,6 +634,34 @@ static int wlcompat_private_ioctl(struct net_device *dev, break; } + case WLCOMPAT_SET_ANTDIV: + { + if (wl_ioctl(dev, WLC_SET_ANTDIV, value, sizeof(int)) < 0) + return -EINVAL; + + break; + } + case WLCOMPAT_GET_ANTDIV: + { + if (wl_ioctl(dev, WLC_GET_ANTDIV, extra, sizeof(int)) < 0) + return -EINVAL; + + break; + } + case WLCOMPAT_SET_TXANT: + { + if (wl_ioctl(dev, WLC_SET_TXANT, value, sizeof(int)) < 0) + return -EINVAL; + + break; + } + case WLCOMPAT_GET_TXANT: + { + if (wl_ioctl(dev, WLC_GET_TXANT, extra, sizeof(int)) < 0) + return -EINVAL; + + break; + } default: { return -EINVAL; @@ -636,29 +671,69 @@ static int wlcompat_private_ioctl(struct net_device *dev, 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" + }, + { WLCOMPAT_SET_ANTDIV, + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, + 0, + "set_antdiv" + }, + { WLCOMPAT_GET_ANTDIV, + 0, + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, + "get_antdiv" + }, + { WLCOMPAT_SET_TXANT, + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, + 0, + "set_txant" + }, + { WLCOMPAT_GET_TXANT, + 0, + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, + "get_txant" + }, +}; -static const iw_handler wlcompat_private[] = +static const iw_handler wlcompat_private[] = { wlcompat_private_ioctl, - wlcompat_private_ioctl, - wlcompat_private_ioctl, - wlcompat_private_ioctl + NULL }; -static const struct iw_handler_def wlcompat_handler_def = +static const struct iw_handler_def wlcompat_handler_def = { .standard = (iw_handler *) wlcompat_handler, .num_standard = sizeof(wlcompat_handler)/sizeof(iw_handler), .private = wlcompat_private, - .num_private = sizeof(wlcompat_private)/sizeof(iw_handler), - .private_args = wlcompat_private_args, - .num_private_args = sizeof(wlcompat_private_args)/sizeof(struct iw_priv_args), + .num_private = 1, + .private_args = wlcompat_private_args, + .num_private_args = sizeof(wlcompat_private_args) / sizeof(wlcompat_private_args[0]) }; #ifdef DEBUG -static int (*old_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); void print_buffer(int len, unsigned char *buf) { int x; if (buf != NULL) { @@ -673,10 +748,23 @@ void print_buffer(int len, unsigned char *buf) { 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) { 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); - 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; unsigned char *buf = ioc->buf; printk(" cmd: %d buf: 0x%08x len: %d\n",ioc->cmd,&(ioc->buf),ioc->len); @@ -686,20 +774,32 @@ static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { printk(" recv: ->"); print_buffer(ioc->len, buf); printk(" ret: %d\n", ret); +#endif } else { ret = old_ioctl(dev,ifr,cmd); } return ret; } -#endif static int __init wlcompat_init() { - dev = dev_get_by_name("eth1"); -#ifdef DEBUG + int found = 0, i; + char *devname = "eth0"; + + while (!found && (dev = dev_get_by_name(devname))) { + if ((dev->wireless_handlers == NULL) && ((wl_ioctl(dev, WLC_GET_MAGIC, &i, sizeof(i)) == 0) && i == WLC_IOCTL_MAGIC)) + found = 1; + devname[3]++; + } + + if (!found) { + printk("No Broadcom devices found.\n"); + return -ENODEV; + } + + old_ioctl = dev->do_ioctl; dev->do_ioctl = new_ioctl; -#endif dev->wireless_handlers = (struct iw_handler_def *)&wlcompat_handler_def; return 0; } @@ -707,9 +807,7 @@ static int __init wlcompat_init() static void __exit wlcompat_exit() { dev->wireless_handlers = NULL; -#ifdef DEBUG dev->do_ioctl = old_ioctl; -#endif return; }