add SIOCSIWFRAG and SIOCSIWRTS
[openwrt.git] / package / openwrt / wlcompat.c
index e120ee1..0dc3829 100644 (file)
@@ -71,9 +71,13 @@ static int wlcompat_ioctl_getiwrange(struct net_device *dev,
        range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
 
        range->min_rts = 0;
-       range->max_rts = 2347;
+       if (wl_ioctl(dev, WLC_GET_RTS, &range->max_rts, sizeof(int)) < 0)
+               range->max_rts = 2347;
+
        range->min_frag = 256;
-       range->max_frag = 2346;
+       
+       if (wl_ioctl(dev, WLC_GET_FRAG, &range->max_frag, sizeof(int)) < 0)
+               range->max_frag = 2346;
 
        range->min_pmp = 0;
        range->max_pmp = 65535000;
@@ -90,8 +94,6 @@ static int wlcompat_ioctl(struct net_device *dev,
                         union iwreq_data *wrqu,
                         char *extra)
 {
-       int err = 0;
-       
        switch (info->cmd) {
                case SIOCGIWNAME:
                        strcpy(wrqu->name, "IEEE 802.11-DS");
@@ -99,7 +101,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 +117,34 @@ 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 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,28 +158,52 @@ 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_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;
@@ -177,17 +211,91 @@ static int wlcompat_ioctl(struct net_device *dev,
                }
                case SIOCGIWRANGE:
                {
-                       err = wlcompat_ioctl_getiwrange(dev, extra);
+                       return wlcompat_ioctl_getiwrange(dev, extra);
                        break;
                }
-               default:
+               case SIOCSIWMODE:
                {
-                       err = -EINVAL;
+                       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:
+               {
+                       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:
+               {
+                       return -EINVAL;
                }
        }
        
-       return err;
+       return 0;
 }
 
 static const iw_handler         wlcompat_handler[] = {
@@ -197,11 +305,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 */
@@ -225,11 +333,11 @@ 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 */
-       NULL,                   /* SIOCSIWTXPOW */
+       wlcompat_ioctl,         /* SIOCSIWTXPOW */
        wlcompat_ioctl,         /* SIOCGIWTXPOW */
        NULL,                   /* SIOCSIWRETRY */
        NULL,                   /* SIOCGIWRETRY */
This page took 0.034902 seconds and 4 git commands to generate.