Remove .la libtool library files
[openwrt.git] / package / openwrt / wlcompat.c
index 11757e5..5245ab5 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/init.h>
 #include <linux/if_arp.h>
 #include <asm/uaccess.h>
+#include <linux/wireless.h>
 
 #include <net/iw_handler.h>
 #include <wlioctl.h>
 
 static struct net_device *dev;
 
+/* The frequency of each channel in MHz */
+const long channel_frequency[] = {
+       2412, 2417, 2422, 2427, 2432, 2437, 2442,
+       2447, 2452, 2457, 2462, 2467, 2472, 2484
+};
+#define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
+
 static int wl_ioctl(struct net_device *dev, int cmd, void *buf, int len)
 {
        mm_segment_t old_fs = get_fs();
@@ -31,6 +39,51 @@ static int wl_ioctl(struct net_device *dev, int cmd, void *buf, int len)
        return ret;
 }
 
+static int wlcompat_ioctl_getiwrange(struct net_device *dev,
+                                   char *extra)
+{
+       int i, k;
+       struct iw_range *range;
+
+       range = (struct iw_range *) extra;
+
+       range->we_version_compiled = WIRELESS_EXT;
+       range->we_version_source = WIRELESS_EXT;
+       
+       range->min_nwid = range->max_nwid = 0;
+       
+       range->num_channels = NUM_CHANNELS;
+       k = 0;
+       for (i = 0; i < NUM_CHANNELS; i++) {
+               range->freq[k].i = i + 1;
+               range->freq[k].m = channel_frequency[i] * 100000;
+               range->freq[k].e = 1;
+               k++;
+               if (k >= IW_MAX_FREQUENCIES)
+                       break;
+       }
+       range->num_frequency = k;
+       range->sensitivity = 3;
+
+       /* nbd: don't know what this means, but other drivers set it this way */
+       range->pmp_flags = IW_POWER_PERIOD;
+       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->txpower_capa = IW_TXPOW_MWATT;
+
+       return 0;
+}
 
 static int wlcompat_ioctl(struct net_device *dev,
                         struct iw_request_info *info,
@@ -44,67 +97,128 @@ 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;
                }
+               case SIOCSIWFREQ:
+               {
+                       if (wrqu->freq.e == 1) {
+                               int channel = 0;
+                               int f = wrqu->freq.m / 100000;
+                               while ((channel < NUM_CHANNELS + 1) && (f != channel_frequency[channel]))
+                                       channel++;
+                               
+                               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)) {
+                               if (wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int)) < 0)
+                                       return -EINVAL;
+                       } else {
+                               return -EINVAL;
+                       }
+               }
                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);
                        break;
                }
+               case SIOCSIWESSID:
+               {
+                       wlc_ssid_t ssid;
+                       memset(&ssid, 0, sizeof(ssid));
+                       ssid.SSID_len = strlen(extra);
+                       if (ssid.SSID_len > WLC_ESSID_MAX_SIZE)
+                               ssid.SSID_len = WLC_ESSID_MAX_SIZE;
+                       memcpy(ssid.SSID, extra, ssid.SSID_len);
+                       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 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 SIOCGIWTXPOW:
                {
                        wrqu->txpower.value = 0;
-                       wl_ioctl(dev,WLC_GET_TXPWR, &(wrqu->txpower.value), sizeof(int));
+                       if (wl_ioctl(dev,WLC_GET_TXPWR, &(wrqu->txpower.value), sizeof(int)) < 0)
+                               return -EINVAL;
                        wrqu->txpower.fixed = 0;
                        wrqu->txpower.disabled = 0;
                        wrqu->txpower.flags = IW_TXPOW_MWATT;
                        break;
                }
+               case SIOCSIWTXPOW:
+               {
+                       if (wrqu->txpower.flags != IW_TXPOW_MWATT)
+                               return -EINVAL;
+
+                       if (wl_ioctl(dev, WLC_SET_TXPWR, &wrqu->txpower.value, sizeof(int)) < 0)
+                               return -EINVAL;
+               }
                case SIOCGIWENCODE:
                {
                        wrqu->data.flags = IW_ENCODE_DISABLED;
                        break;
                }
+               case SIOCGIWRANGE:
+               {
+                       return wlcompat_ioctl_getiwrange(dev, extra);
+                       break;
+               }
+               default:
+               {
+                       return -EINVAL;
+               }
        }
+       
        return 0;
 }
 
 static const iw_handler         wlcompat_handler[] = {
-       NULL,                   /* SIOCSIWNAME */
+       NULL,                   /* SIOCSIWCOMMIT */
        wlcompat_ioctl,         /* SIOCGIWNAME */
        NULL,                   /* SIOCSIWNWID */
        NULL,                   /* SIOCGIWNWID */
-       NULL,                   /* SIOCSIWFREQ */
+       wlcompat_ioctl,         /* SIOCSIWFREQ */
        wlcompat_ioctl,         /* SIOCGIWFREQ */
        NULL,                   /* SIOCSIWMODE */
        NULL,                   /* SIOCGIWMODE */
        NULL,                   /* SIOCSIWSENS */
        NULL,                   /* SIOCGIWSENS */
        NULL,                   /* SIOCSIWRANGE */
-       NULL,                   /* SIOCGIWRANGE */
+       wlcompat_ioctl,         /* SIOCGIWRANGE */
        NULL,                   /* SIOCSIWPRIV */
        NULL,                   /* SIOCGIWPRIV */
        NULL,                   /* SIOCSIWSTATS */
@@ -119,7 +233,7 @@ static const iw_handler      wlcompat_handler[] = {
        NULL,                   /* SIOCGIWAPLIST */
        NULL,                   /* -- hole -- */
        NULL,                   /* -- hole -- */
-       NULL,                   /* SIOCSIWESSID */
+       wlcompat_ioctl,         /* SIOCSIWESSID */
        wlcompat_ioctl,         /* SIOCGIWESSID */
        NULL,                   /* SIOCSIWNICKN */
        NULL,                   /* SIOCGIWNICKN */
@@ -131,7 +245,7 @@ static const iw_handler      wlcompat_handler[] = {
        wlcompat_ioctl,         /* SIOCGIWRTS */
        NULL,                   /* SIOCSIWFRAG */
        wlcompat_ioctl,         /* SIOCGIWFRAG */
-       NULL,                   /* SIOCSIWTXPOW */
+       wlcompat_ioctl,         /* SIOCSIWTXPOW */
        wlcompat_ioctl,         /* SIOCGIWTXPOW */
        NULL,                   /* SIOCSIWRETRY */
        NULL,                   /* SIOCGIWRETRY */
This page took 0.031815 seconds and 4 git commands to generate.