shorter syntax
[openwrt.git] / package / openwrt / wlcompat.c
index 80242e1..74dcdf2 100644 (file)
@@ -1,5 +1,26 @@
-// insert header here
-// mbm. gpl.
+/*
+ * wlcompat.c
+ *
+ * Copyright (C) 2005 Mike Baker,
+ *                    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/config.h>
 #include <linux/module.h>
@@ -11,9 +32,8 @@
 #include <net/iw_handler.h>
 #include <wlioctl.h>
 
-#define DEBUG
-
 static struct net_device *dev;
+char buf[WLC_IOCTL_MAXLEN];
 
 /* The frequency of each channel in MHz */
 const long channel_frequency[] = {
@@ -22,6 +42,11 @@ 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,
+                        char *extra);
+
 static int wl_ioctl(struct net_device *dev, int cmd, void *buf, int len)
 {
        mm_segment_t old_fs = get_fs();
@@ -39,6 +64,43 @@ static int wl_ioctl(struct net_device *dev, int cmd, void *buf, int len)
        return ret;
 }
 
+static int wl_set_val(struct net_device *dev, char *var, void *val, int len)
+{
+       char buf[128];
+       int buf_len;
+
+       /* check for overflow */
+       if ((buf_len = strlen(var)) + 1 + len > sizeof(buf))
+               return -1;
+       
+       strcpy(buf, var);
+       buf_len += 1;
+
+       /* append int value onto the end of the name string */
+       memcpy(&buf[buf_len], val, len);
+       buf_len += len;
+
+       return wl_ioctl(dev, WLC_SET_VAR, buf, buf_len);
+}
+
+static int wl_get_val(struct net_device *dev, char *var, void *val, int len)
+{
+       char buf[128];
+       int ret;
+
+       /* check for overflow */
+       if (strlen(var) + 1 > sizeof(buf) || len > sizeof(buf))
+               return -1;
+       
+       strcpy(buf, var);
+       if ((ret = wl_ioctl(dev, WLC_GET_VAR, buf, sizeof(buf))))
+               return ret;
+
+       memcpy(val, buf, len);
+       return 0;
+}
+
+
 static int wlcompat_ioctl_getiwrange(struct net_device *dev,
                                    char *extra)
 {
@@ -70,28 +132,139 @@ static int wlcompat_ioctl_getiwrange(struct net_device *dev,
        range->pmt_flags = IW_POWER_TIMEOUT;
        range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
 
-       range->min_rts = 0;
-       range->max_rts = 2347;
-       range->min_frag = 256;
-       range->max_frag = 2346;
-
        range->min_pmp = 0;
        range->max_pmp = 65535000;
        range->min_pmt = 0;
        range->max_pmt = 65535 * 1000;
 
+       range->min_rts = 0;
+       if (wl_ioctl(dev, WLC_GET_RTS, &range->max_rts, sizeof(int)) < 0)
+               range->max_rts = 2347;
+
+       range->min_frag = 256;
+       
+       if (wl_ioctl(dev, WLC_GET_FRAG, &range->max_frag, sizeof(int)) < 0)
+               range->max_frag = 2346;
+
        range->txpower_capa = IW_TXPOW_MWATT;
 
        return 0;
 }
 
-static int wlcompat_ioctl(struct net_device *dev,
+
+static int wlcompat_set_scan(struct net_device *dev,
                         struct iw_request_info *info,
                         union iwreq_data *wrqu,
                         char *extra)
 {
-       int err = 0;
+       int ap = 0, oldap = 0;
+       wl_scan_params_t params;
+
+       memset(&params, 0, sizeof(params));
+
+       /* use defaults (same parameters as wl scan) */
+       memset(&params.bssid, 0xff, sizeof(params.bssid));
+       params.bss_type = DOT11_BSSTYPE_ANY;
+       params.scan_type = -1;
+       params.nprobes = -1;
+       params.active_time = -1;
+       params.passive_time = -1;
+       params.home_time = -1;
+       
+       /* can only scan in STA mode */
+       wl_ioctl(dev, WLC_GET_AP, &oldap, sizeof(oldap));
+       if (oldap > 0)
+               wl_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap));
        
+       if (wl_ioctl(dev, WLC_SCAN, &params, 64) < 0)
+               return -EINVAL;
+       
+       if (oldap > 0)
+               wl_ioctl(dev, WLC_SET_AP, &oldap, sizeof(oldap));
+
+       return 0;
+}
+
+
+static int wlcompat_get_scan(struct net_device *dev,
+                        struct iw_request_info *info,
+                        union iwreq_data *wrqu,
+                        char *extra)
+{
+       wl_scan_results_t *results = (wl_scan_results_t *) buf;
+       wl_bss_info_t *bss_info;
+       char *info_ptr;
+       char *current_ev = extra;
+       char *current_val;
+       char *end_buf = extra + IW_SCAN_MAX_DATA;
+       struct iw_event iwe;
+       int i, j;
+
+       if (wl_ioctl(dev, WLC_SCAN_RESULTS, buf, WLC_IOCTL_MAXLEN) < 0)
+               return -EAGAIN;
+       
+       bss_info = &(results->bss_info[0]);
+       info_ptr = (char *) bss_info;
+       for (i = 0; i < results->count; i++) {
+
+               /* send the cell address (must be sent first) */
+               iwe.cmd = SIOCGIWAP;
+               iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
+               memcpy(&iwe.u.ap_addr.sa_data, &bss_info->BSSID, sizeof(bss_info->BSSID));
+               current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
+               
+               /* send the ESSID */
+               iwe.cmd = SIOCGIWESSID;
+               iwe.u.data.length = bss_info->SSID_len;
+               if (iwe.u.data.length > IW_ESSID_MAX_SIZE)
+                       iwe.u.data.length = IW_ESSID_MAX_SIZE;
+               iwe.u.data.flags = 1;
+               current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss_info->SSID);
+
+               /* send frequency/channel info */
+               iwe.cmd = SIOCGIWFREQ;
+               iwe.u.freq.e = 0;
+               iwe.u.freq.m = bss_info->channel;
+               current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
+
+               /* add quality statistics */
+               iwe.cmd = IWEVQUAL;
+               iwe.u.qual.level = bss_info->RSSI;
+               iwe.u.qual.noise = bss_info->phy_noise;
+               iwe.u.qual.qual = 0;
+               current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
+       
+               /* send rate information */
+               iwe.cmd = SIOCGIWRATE;
+               current_val = current_ev + IW_EV_LCP_LEN;
+               iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
+               
+               for(j = 0 ; j < bss_info->rateset.count ; j++) {
+                       iwe.u.bitrate.value = ((bss_info->rateset.rates[j] & 0x7f) * 500000);
+                       current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
+               }
+               if((current_val - current_ev) > IW_EV_LCP_LEN)
+                       current_ev = current_val;
+
+               info_ptr += sizeof(wl_bss_info_t);
+               if (bss_info->ie_length % 4)
+                       info_ptr += bss_info->ie_length + 4 - (bss_info->ie_length % 4);
+               else
+                       info_ptr += bss_info->ie_length;
+               bss_info = (wl_bss_info_t *) info_ptr;
+       }
+       
+       wrqu->data.length = (current_ev - extra);
+       wrqu->data.flags = 0;
+
+       return 0;
+}
+
+static int wlcompat_ioctl(struct net_device *dev,
+                        struct iw_request_info *info,
+                        union iwreq_data *wrqu,
+                        char *extra)
+{
        switch (info->cmd) {
                case SIOCGIWNAME:
                        strcpy(wrqu->name, "IEEE 802.11-DS");
@@ -99,7 +272,10 @@ static int wlcompat_ioctl(struct net_device *dev,
                case SIOCGIWFREQ:
                {
                        channel_info_t ci;
-                       wl_ioctl(dev,WLC_GET_CHANNEL, &ci, sizeof(ci));
+
+                       if (wl_ioctl(dev,WLC_GET_CHANNEL, &ci, sizeof(ci)) < 0)
+                               return -EINVAL;
+
                        wrqu->freq.m = ci.target_channel;
                        wrqu->freq.e = 0;
                        break;
@@ -112,29 +288,44 @@ static int wlcompat_ioctl(struct net_device *dev,
                                while ((channel < NUM_CHANNELS + 1) && (f != channel_frequency[channel]))
                                        channel++;
                                
-                               if (channel == NUM_CHANNELS) { // channel not found
-                                       err = -EINVAL;
-                               } else {
-                                       wrqu->freq.e = 0;
-                                       wrqu->freq.m = channel + 1;
-                               }
+                               if (channel == NUM_CHANNELS) // channel not found
+                                       return -EINVAL;
+
+                               wrqu->freq.e = 0;
+                               wrqu->freq.m = channel + 1;
                        }
                        if ((wrqu->freq.e == 0) && (wrqu->freq.m < 1000)) {
-                               wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int));
+                               if (wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int)) < 0)
+                                       return -EINVAL;
                        } else {
-                               err = -EINVAL;
+                               return -EINVAL;
                        }
+                       break;
+               }
+               case SIOCSIWAP:
+               {
+                       if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
+                               return -EINVAL;
+
+                       if (wl_ioctl(dev,WLC_SET_BSSID,wrqu->ap_addr.sa_data,6) < 0)
+                               return -EINVAL;
+
+                       break;
                }
                case SIOCGIWAP:
                {
                        wrqu->ap_addr.sa_family = ARPHRD_ETHER;
-                       wl_ioctl(dev,WLC_GET_BSSID,wrqu->ap_addr.sa_data,6);
+                       if (wl_ioctl(dev,WLC_GET_BSSID,wrqu->ap_addr.sa_data,6) < 0)
+                               return -EINVAL;
                        break;
                }
                case SIOCGIWESSID:
                {
                        wlc_ssid_t ssid;
-                       wl_ioctl(dev,WLC_GET_SSID, &ssid, sizeof(wlc_ssid_t));
+                       
+                       if (wl_ioctl(dev,WLC_GET_SSID, &ssid, sizeof(wlc_ssid_t)) < 0)
+                               return -EINVAL;
+
                        wrqu->essid.flags = wrqu->data.flags = 1;
                        wrqu->essid.length = wrqu->data.length = ssid.SSID_len + 1;
                        memcpy(extra,ssid.SSID,ssid.SSID_len + 1);
@@ -148,23 +339,41 @@ static int wlcompat_ioctl(struct net_device *dev,
                        if (ssid.SSID_len > WLC_ESSID_MAX_SIZE)
                                ssid.SSID_len = WLC_ESSID_MAX_SIZE;
                        memcpy(ssid.SSID, extra, ssid.SSID_len);
-                       wl_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid));
+                       if (wl_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid)) < 0)
+                               return -EINVAL;
                        break;
                }
                case SIOCGIWRTS:
                {
-                       wl_ioctl(dev,WLC_GET_RTS,&(wrqu->rts.value),sizeof(int));
+                       if (wl_ioctl(dev,WLC_GET_RTS,&(wrqu->rts.value),sizeof(int)) < 0) 
+                               return -EINVAL;
+                       break;
+               }
+               case SIOCSIWRTS:
+               {
+                       if (wl_ioctl(dev,WLC_SET_RTS,&(wrqu->rts.value),sizeof(int)) < 0) 
+                               return -EINVAL;
                        break;
                }
                case SIOCGIWFRAG:
                {
-                       wl_ioctl(dev,WLC_GET_FRAG,&(wrqu->frag.value),sizeof(int));
+                       if (wl_ioctl(dev,WLC_GET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
+                               return -EINVAL;
+                       break;
+               }
+               case SIOCSIWFRAG:
+               {
+                       if (wl_ioctl(dev,WLC_SET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
+                               return -EINVAL;
                        break;
                }
                case SIOCGIWTXPOW:
                {
-                       wrqu->txpower.value = 0;
-                       wl_ioctl(dev,WLC_GET_TXPWR, &(wrqu->txpower.value), sizeof(int));
+                       if (wl_get_val(dev, "qtxpower", &(wrqu->txpower.value), sizeof(int)) < 0)
+                               return -EINVAL;
+                       
+                       wrqu->txpower.value &= ~WL_TXPWR_OVERRIDE;
+                               
                        wrqu->txpower.fixed = 0;
                        wrqu->txpower.disabled = 0;
                        wrqu->txpower.flags = IW_TXPOW_MWATT;
@@ -172,30 +381,125 @@ static int wlcompat_ioctl(struct net_device *dev,
                }
                case SIOCSIWTXPOW:
                {
-                       if (wrqu->txpower.flags != IW_TXPOW_MWATT) {
-                               err = -EINVAL;
-                       } else {
-                               wl_ioctl(dev, WLC_SET_TXPWR, &wrqu->txpower.value, sizeof(int));
-                       }
+                       int override;
+                       
+                       if (wl_get_val(dev, "qtxpower", &override, sizeof(int)) < 0)
+                               return -EINVAL;
+                       
+                       wrqu->txpower.value |= override & WL_TXPWR_OVERRIDE;
+                       
+                       if (wrqu->txpower.flags != IW_TXPOW_MWATT)
+                               return -EINVAL;
+
+                       if (wl_set_val(dev, "qtxpower", &wrqu->txpower.value, sizeof(int)) < 0)
+                               return -EINVAL;
                }
                case SIOCGIWENCODE:
                {
-                       wrqu->data.flags = IW_ENCODE_DISABLED;
+                       int val = 0;
+                       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;
+                       } else {
+                               wrqu->data.flags = IW_ENCODE_DISABLED;
+                       }
+                               
+                               
+                       
                        break;
                }
                case SIOCGIWRANGE:
                {
-                       err = wlcompat_ioctl_getiwrange(dev, extra);
+                       return wlcompat_ioctl_getiwrange(dev, extra);
                        break;
                }
-               default:
+               case SIOCSIWMODE:
+               {
+                       int ap = -1, infra = -1, passive = 0, wet = 0;
+                       
+                       switch (wrqu->mode) {
+                               case IW_MODE_MONITOR:
+                                       passive = 1;
+                                       break;
+                               case IW_MODE_ADHOC:
+                                       infra = 0;
+                                       ap = 0;
+                                       break;
+                               case IW_MODE_MASTER:
+                                       infra = 1;
+                                       ap = 1;
+                                       break;
+                               case IW_MODE_INFRA:
+                                       infra = 1;
+                                       ap = 0;
+                                       break;
+                               case IW_MODE_REPEAT:
+                                       infra = 1;
+                                       ap = 0;
+                                       wet = 1;
+                                       break;
+                               default:
+                                       return -EINVAL;
+                       }
+                       
+                       if (wl_ioctl(dev, WLC_SET_PASSIVE, &passive, sizeof(passive)) < 0)
+                               return -EINVAL;
+                       if (wl_ioctl(dev, WLC_SET_MONITOR, &passive, sizeof(passive)) < 0)
+                               return -EINVAL;
+                       if (wl_ioctl(dev, WLC_SET_WET, &wet, sizeof(wet)) < 0)
+                               return -EINVAL;
+                       if (ap >= 0)
+                               if (wl_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap)) < 0)
+                                       return -EINVAL;
+                       if (infra >= 0)
+                               if (wl_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra)) < 0)
+                                       return -EINVAL;
+
+                       break;
+                                               
+               }
+               case SIOCGIWMODE:
                {
-                       err = -EINVAL;
+                       int ap, infra, wet, passive;
+
+                       if (wl_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap)) < 0)
+                               return -EINVAL;
+                       if (wl_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra)) < 0)
+                               return -EINVAL;
+                       if (wl_ioctl(dev, WLC_GET_PASSIVE, &passive, sizeof(passive)) < 0)
+                               return -EINVAL;
+                       if (wl_ioctl(dev, WLC_GET_WET, &wet, sizeof(wet)) < 0)
+                               return -EINVAL;
+
+                       if (passive) {
+                               wrqu->mode = IW_MODE_MONITOR;
+                       } else if (!infra) {
+                               wrqu->mode = IW_MODE_ADHOC;
+                       } else {
+                               if (ap) {
+                                       wrqu->mode = IW_MODE_MASTER;
+                               } else {
+                                       if (wet) {
+                                               wrqu->mode = IW_MODE_REPEAT;
+                                       } else {
+                                               wrqu->mode = IW_MODE_INFRA;
+                                       }
+                               }
+                       }
                        break;
                }
+               default:
+               {
+                       if (info->cmd >= SIOCIWFIRSTPRIV)
+                               return wlcompat_private_ioctl(dev, info, wrqu, extra);
+
+                       return -EINVAL;
+               }
        }
        
-       return err;
+       return 0;
 }
 
 static const iw_handler         wlcompat_handler[] = {
@@ -205,11 +509,11 @@ static const iw_handler    wlcompat_handler[] = {
        NULL,                   /* SIOCGIWNWID */
        wlcompat_ioctl,         /* SIOCSIWFREQ */
        wlcompat_ioctl,         /* SIOCGIWFREQ */
-       NULL,                   /* SIOCSIWMODE */
-       NULL,                   /* SIOCGIWMODE */
+       wlcompat_ioctl,         /* SIOCSIWMODE */
+       wlcompat_ioctl,         /* SIOCGIWMODE */
        NULL,                   /* SIOCSIWSENS */
        NULL,                   /* SIOCGIWSENS */
-       NULL,                   /* SIOCSIWRANGE */
+       NULL,                   /* SIOCSIWRANGE, unused */
        wlcompat_ioctl,         /* SIOCGIWRANGE */
        NULL,                   /* SIOCSIWPRIV */
        NULL,                   /* SIOCGIWPRIV */
@@ -219,12 +523,12 @@ static const iw_handler    wlcompat_handler[] = {
        iw_handler_get_spy,     /* SIOCGIWSPY */
        iw_handler_set_thrspy,  /* SIOCSIWTHRSPY */
        iw_handler_get_thrspy,  /* SIOCGIWTHRSPY */
-       NULL,                   /* SIOCSIWAP */
+       wlcompat_ioctl,         /* SIOCSIWAP */
        wlcompat_ioctl,         /* SIOCGIWAP */
        NULL,                   /* -- hole -- */
        NULL,                   /* SIOCGIWAPLIST */
-       NULL,                   /* -- hole -- */
-       NULL,                   /* -- hole -- */
+       wlcompat_set_scan,      /* SIOCSIWSCAN */
+       wlcompat_get_scan,      /* SIOCGIWSCAN */
        wlcompat_ioctl,         /* SIOCSIWESSID */
        wlcompat_ioctl,         /* SIOCGIWESSID */
        NULL,                   /* SIOCSIWNICKN */
@@ -233,9 +537,9 @@ static const iw_handler      wlcompat_handler[] = {
        NULL,                   /* -- hole -- */
        NULL,                   /* SIOCSIWRATE */
        NULL,                   /* SIOCGIWRATE */
-       NULL,                   /* SIOCSIWRTS */
+       wlcompat_ioctl,         /* SIOCSIWRTS */
        wlcompat_ioctl,         /* SIOCGIWRTS */
-       NULL,                   /* SIOCSIWFRAG */
+       wlcompat_ioctl,         /* SIOCSIWFRAG */
        wlcompat_ioctl,         /* SIOCGIWFRAG */
        wlcompat_ioctl,         /* SIOCSIWTXPOW */
        wlcompat_ioctl,         /* SIOCGIWTXPOW */
@@ -245,31 +549,145 @@ 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_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,
+                        struct iw_request_info *info,
+                        union iwreq_data *wrqu,
+                        char *extra)
+{
+       int *value = (int *) wrqu->name;
+
+       switch (info->cmd) {
+               case PRIV_SET_MONITOR:
+               {
+                       if (wl_ioctl(dev, WLC_SET_MONITOR, value, sizeof(int)) < 0)
+                               return -EINVAL;
+
+                       break;
+               }
+               case PRIV_GET_MONITOR:
+               {
+                       if (wl_ioctl(dev, WLC_GET_MONITOR, extra, sizeof(int)) < 0)
+                               return -EINVAL;
+
+                       break;
+               }
+               case PRIV_SET_TXPWR_LIMIT:
+               {
+                       int val;
+                       
+
+                       if (wl_get_val(dev, "qtxpower", &val, sizeof(int)) < 0)
+                               return -EINVAL;
+                       
+                       if (*extra > 0)
+                               val |= WL_TXPWR_OVERRIDE;
+                       else
+                               val &= ~WL_TXPWR_OVERRIDE;
+                       
+                       if (wl_set_val(dev, "qtxpower", &val, sizeof(int)) < 0)
+                               return -EINVAL;
+                       
+                       break;
+               }
+               case PRIV_GET_TXPWR_LIMIT:
+               {
+                       if (wl_get_val(dev, "qtxpower", value, sizeof(int)) < 0)
+                               return -EINVAL;
+
+                       *value = ((*value & WL_TXPWR_OVERRIDE) == WL_TXPWR_OVERRIDE ? 1 : 0);
+
+                       break;
+               }
+               default:
+               {
+                       return -EINVAL;
+               }
+                       
+       }
+       return 0;
+}
+
+
+static const iw_handler        wlcompat_private[] = 
+{
+       wlcompat_private_ioctl,
+       wlcompat_private_ioctl,
+       wlcompat_private_ioctl,
+       wlcompat_private_ioctl
+};
+
+
 static const struct iw_handler_def      wlcompat_handler_def =
 {
        .standard       = (iw_handler *) wlcompat_handler,
        .num_standard   = sizeof(wlcompat_handler)/sizeof(iw_handler),
-       .private        = NULL,
-       .num_private    = 0,
-       .private_args   = NULL
-       .num_private_args = 0,
+       .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),
 };
 
+
 #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) {
+               for (x=0;x<len && x<180 ;x++) {
+                       if ((x % 4) == 0)
+                               printk(" ");
+                       printk("%02X",buf[x]);
+               }
+       } else {
+               printk(" NULL");
+       }
+       printk("\n");
+
+}
 static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {
-       int ret = old_ioctl(dev,ifr,cmd);
+       int ret = 0;
        printk("dev: %s ioctl: 0x%04x\n",dev->name,cmd);
        if (cmd==SIOCDEVPRIVATE) {
-               int x;
                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);
-               printk("   ->");
-               for (x=0;x<ioc->len && x<128 ;x++) {
-                       printk("%02X",buf[x]);
-               }
-               printk("\n");
+               printk("   send: ->");
+               print_buffer(ioc->len, buf);
+               ret = old_ioctl(dev,ifr,cmd);
+               printk("   recv: ->");
+               print_buffer(ioc->len, buf);
+               printk("   ret: %d\n", ret);
+       } else {
+               ret = old_ioctl(dev,ifr,cmd);
        }
        return ret;
 }
@@ -277,7 +695,23 @@ static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {
 
 static int __init wlcompat_init()
 {
-       dev = dev_get_by_name("eth1");
+       int found = 0, i;
+       char *devname = "eth0";
+       
+       while (!found && devname[3] < '3') {
+               devname[3]++;
+               
+               dev = dev_get_by_name(devname);
+               if ((wl_ioctl(dev, WLC_GET_MAGIC, &i, sizeof(i)) == 0) && i == WLC_IOCTL_MAGIC)
+                       found = 1;
+       }
+       
+       if (!found) {
+               printk("No Broadcom devices found.\n");
+               return -ENODEV;
+       }
+               
+
 #ifdef DEBUG
        old_ioctl = dev->do_ioctl;
        dev->do_ioctl = new_ioctl;
This page took 0.035192 seconds and 4 git commands to generate.