Add fix from whiterussian
[openwrt.git] / openwrt / package / wificonf / wificonf.c
index ecf08c0..7a9cde5 100644 (file)
        do { \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    too few arguments.\n"); \
        do { \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    too few arguments.\n"); \
-               return; \
        } while(0)
 
 #define ABORT_ARG_TYPE(rname, request, arg) \
        do { \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    invalid argument \"%s\".\n", arg); \
        } while(0)
 
 #define ABORT_ARG_TYPE(rname, request, arg) \
        do { \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    invalid argument \"%s\".\n", arg); \
-               return; \
        } while(0)
 
 #define ABORT_ARG_SIZE(rname, request, max) \
        do { \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    argument too big (max %d)\n", max); \
        } while(0)
 
 #define ABORT_ARG_SIZE(rname, request, max) \
        do { \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    argument too big (max %d)\n", max); \
-               return; \
        } while(0)
 
 /*------------------------------------------------------------------*/
        } while(0)
 
 /*------------------------------------------------------------------*/
@@ -64,7 +61,6 @@
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    SET failed on device %-1.16s ; %s.\n", \
                        ifname, strerror(errno)); \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    SET failed on device %-1.16s ; %s.\n", \
                        ifname, strerror(errno)); \
-               return; \
        } } while(0)
 
 /*------------------------------------------------------------------*/
        } } while(0)
 
 /*------------------------------------------------------------------*/
@@ -78,7 +74,6 @@
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    GET failed on device %-1.16s ; %s.\n", \
                        ifname, strerror(errno)); \
                ERR_SET_EXT(rname, request); \
                fprintf(stderr, "    GET failed on device %-1.16s ; %s.\n", \
                        ifname, strerror(errno)); \
-               return; \
        } } while(0)
 
 char *prefix;
        } } while(0)
 
 char *prefix;
@@ -115,8 +110,6 @@ int bcom_ioctl(int skfd, char *ifname, int cmd, void *buf, int len)
        strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
 
        ret = ioctl(skfd, SIOCDEVPRIVATE, &ifr);
        strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
 
        ret = ioctl(skfd, SIOCDEVPRIVATE, &ifr);
-       if (ret < 0)
-               fprintf(stderr, "bcom_ioctl [cmd=%d, buf=%08x, len=%d] failed: %d\n", cmd, buf, len, ret);
 
        return ret;
 }
 
        return ret;
 }
@@ -146,6 +139,8 @@ int bcom_set_int(int skfd, char *ifname, char *var, int val)
 void setup_bcom(int skfd, char *ifname)
 {
        int val = 0;
 void setup_bcom(int skfd, char *ifname)
 {
        int val = 0;
+       char buf[8192];
+       char wbuf[80];
        char *v;
        
        if (bcom_ioctl(skfd, ifname, WLC_GET_MAGIC, &val, sizeof(val)) < 0)
        char *v;
        
        if (bcom_ioctl(skfd, ifname, WLC_GET_MAGIC, &val, sizeof(val)) < 0)
@@ -153,20 +148,22 @@ void setup_bcom(int skfd, char *ifname)
 
        bcom_ioctl(skfd, ifname, WLC_DOWN, NULL, 0);
        
 
        bcom_ioctl(skfd, ifname, WLC_DOWN, NULL, 0);
        
-       /* Set up WPA */
-       if (nvram_match(wl_var("crypto"), "tkip"))
-               val = TKIP_ENABLED;
-       else if (nvram_match(wl_var("crypto"), "aes"))
-               val = AES_ENABLED;
-       else if (nvram_match(wl_var("crypto"), "tkip+aes"))
-               val = TKIP_ENABLED | AES_ENABLED;
-       else
-               val = 0;
-       bcom_ioctl(skfd, ifname, WLC_SET_WSEC, &val, sizeof(val));
-
-       if (val && nvram_get(wl_var("wpa_psk"))) {
-               val = 1;
-               bcom_ioctl(skfd, ifname, WLC_SET_EAP_RESTRICT, &val, sizeof(val));
+       if (nvram_match(wl_var("auth_mode"), "wpa") || nvram_match(wl_var("auth_mode"), "psk") || (nvram_get(wl_var("akm")) && !nvram_disabled(wl_var("akm")))) {
+               /* Set up WPA */
+               if (nvram_match(wl_var("crypto"), "tkip"))
+                       val = TKIP_ENABLED;
+               else if (nvram_match(wl_var("crypto"), "aes"))
+                       val = AES_ENABLED;
+               else if (nvram_match(wl_var("crypto"), "tkip+aes"))
+                       val = TKIP_ENABLED | AES_ENABLED;
+               else
+                       val = 0;
+               bcom_ioctl(skfd, ifname, WLC_SET_WSEC, &val, sizeof(val));
+
+               if (val && nvram_get(wl_var("wpa_psk"))) {
+                       val = 1;
+                       bcom_ioctl(skfd, ifname, WLC_SET_EAP_RESTRICT, &val, sizeof(val));
+               }
        }
 
        /* Set up afterburner */
        }
 
        /* Set up afterburner */
@@ -178,20 +175,34 @@ void setup_bcom(int skfd, char *ifname)
        bcom_set_val(skfd, ifname, "afterburner_override", &val, sizeof(val));
        
        /* Set other options */
        bcom_set_val(skfd, ifname, "afterburner_override", &val, sizeof(val));
        
        /* Set other options */
-       val = atoi(nvram_safe_get(wl_var("lazywds")));
-       bcom_ioctl(skfd, ifname, WLC_SET_LAZYWDS, &val, sizeof(val));
-       val = atoi(nvram_safe_get(wl_var("frag")));
-       bcom_ioctl(skfd, ifname, WLC_SET_FRAG, &val, sizeof(val));
-       val = atoi(nvram_safe_get(wl_var("dtim")));
-       bcom_ioctl(skfd, ifname, WLC_SET_DTIMPRD, &val, sizeof(val));
-       val = atoi(nvram_safe_get(wl_var("bcn")));
-       bcom_ioctl(skfd, ifname, WLC_SET_BCNPRD, &val, sizeof(val));
-       val = atoi(nvram_safe_get(wl_var("rts")));
-       bcom_ioctl(skfd, ifname, WLC_SET_RTS, &val, sizeof(val));
-       val = atoi(nvram_safe_get(wl_var("antdiv")));
-       bcom_ioctl(skfd, ifname, WLC_SET_ANTDIV, &val, sizeof(val));
-       val = atoi(nvram_safe_get(wl_var("txant")));
-       bcom_ioctl(skfd, ifname, WLC_SET_TXANT, &val, sizeof(val));
+       if (v = nvram_get(wl_var("lazywds"))) {
+               val = atoi(v);
+               bcom_ioctl(skfd, ifname, WLC_SET_LAZYWDS, &val, sizeof(val));
+       }
+       if (v = nvram_get(wl_var("frag"))) {
+               val = atoi(v);
+               bcom_ioctl(skfd, ifname, WLC_SET_FRAG, &val, sizeof(val));
+       }
+       if (v = nvram_get(wl_var("dtim"))) {
+               val = atoi(v);
+               bcom_ioctl(skfd, ifname, WLC_SET_DTIMPRD, &val, sizeof(val));
+       }
+       if (v = nvram_get(wl_var("bcn"))) {
+               val = atoi(v);
+               bcom_ioctl(skfd, ifname, WLC_SET_BCNPRD, &val, sizeof(val));
+       }
+       if (v = nvram_get(wl_var("rts"))) {
+               val = atoi(v);
+               bcom_ioctl(skfd, ifname, WLC_SET_RTS, &val, sizeof(val));
+       }
+       if (v = nvram_get(wl_var("antdiv"))) {
+               val = atoi(v);
+               bcom_ioctl(skfd, ifname, WLC_SET_ANTDIV, &val, sizeof(val));
+       }
+       if (v = nvram_get(wl_var("txant"))) {
+               val = atoi(v);
+               bcom_ioctl(skfd, ifname, WLC_SET_TXANT, &val, sizeof(val));
+       }
        
        val = nvram_enabled(wl_var("closed"));
        bcom_ioctl(skfd, ifname, WLC_SET_CLOSED, &val, sizeof(val));
        
        val = nvram_enabled(wl_var("closed"));
        bcom_ioctl(skfd, ifname, WLC_SET_CLOSED, &val, sizeof(val));
@@ -211,8 +222,6 @@ void setup_bcom(int skfd, char *ifname)
                val = WLC_MACMODE_DISABLED;
 
        if ((val != WLC_MACMODE_DISABLED) && (v = nvram_get(wl_var("maclist")))) {
                val = WLC_MACMODE_DISABLED;
 
        if ((val != WLC_MACMODE_DISABLED) && (v = nvram_get(wl_var("maclist")))) {
-               char buf[8192];
-               char wbuf[80];
                struct maclist *mac_list;
                struct ether_addr *addr;
                char *next;
                struct maclist *mac_list;
                struct ether_addr *addr;
                char *next;
@@ -221,7 +230,7 @@ void setup_bcom(int skfd, char *ifname)
                mac_list = (struct maclist *) buf;
                addr = mac_list->ea;
                
                mac_list = (struct maclist *) buf;
                addr = mac_list->ea;
                
-               foreach(wbuf, nvram_safe_get(wl_var("maclist")), next) {
+               foreach(wbuf, v, next) {
                        if (ether_atoe(wbuf, addr->ether_addr_octet)) {
                                mac_list->count++;
                                addr++;
                        if (ether_atoe(wbuf, addr->ether_addr_octet)) {
                                mac_list->count++;
                                addr++;
@@ -232,6 +241,21 @@ void setup_bcom(int skfd, char *ifname)
                val = WLC_MACMODE_DISABLED;
        }
        bcom_ioctl(skfd, ifname, WLC_SET_MACMODE, &val, sizeof(val));
                val = WLC_MACMODE_DISABLED;
        }
        bcom_ioctl(skfd, ifname, WLC_SET_MACMODE, &val, sizeof(val));
+
+       if (v = nvram_get(wl_var("wds"))) {
+               struct maclist *wdslist = (struct maclist *) buf;
+               struct ether_addr *addr = wdslist->ea;
+               char *next;
+
+               memset(buf, 0, 8192);
+               foreach(wbuf, v, next) {
+                       if (ether_atoe(wbuf, addr->ether_addr_octet)) {
+                               wdslist->count++;
+                               addr++;
+                       }
+               }
+               bcom_ioctl(skfd, ifname, WLC_SET_WDSLIST, buf, sizeof(buf));
+       }
        
        /* Set up G mode */
        bcom_ioctl(skfd, ifname, WLC_GET_PHYTYPE, &val, sizeof(val));
        
        /* Set up G mode */
        bcom_ioctl(skfd, ifname, WLC_GET_PHYTYPE, &val, sizeof(val));
@@ -239,9 +263,14 @@ void setup_bcom(int skfd, char *ifname)
                int override = WLC_G_PROTECTION_OFF;
                int control = WLC_G_PROTECTION_CTL_OFF;
                
                int override = WLC_G_PROTECTION_OFF;
                int control = WLC_G_PROTECTION_CTL_OFF;
                
-               val = atoi(nvram_safe_get(wl_var("gmode")));
+               if (v = nvram_get(wl_var("gmode"))) 
+                       val = atoi(v);
+               else
+                       val = 1;
+
                if (val > 5)
                        val = 1;
                if (val > 5)
                        val = 1;
+
                bcom_ioctl(skfd, ifname, WLC_SET_GMODE, &val, sizeof(val));
                
                if (nvram_match(wl_var("gmode_protection"), "auto")) {
                bcom_ioctl(skfd, ifname, WLC_SET_GMODE, &val, sizeof(val));
                
                if (nvram_match(wl_var("gmode_protection"), "auto")) {
@@ -254,7 +283,17 @@ void setup_bcom(int skfd, char *ifname)
                }
                bcom_ioctl(skfd, ifname, WLC_SET_GMODE_PROTECTION_CONTROL, &override, sizeof(control));
                bcom_ioctl(skfd, ifname, WLC_SET_GMODE_PROTECTION_OVERRIDE, &override, sizeof(override));
                }
                bcom_ioctl(skfd, ifname, WLC_SET_GMODE_PROTECTION_CONTROL, &override, sizeof(control));
                bcom_ioctl(skfd, ifname, WLC_SET_GMODE_PROTECTION_OVERRIDE, &override, sizeof(override));
+
+               if (val = 0) {
+                       if (nvram_match(wl_var("plcphdr"), "long"))
+                               val = WLC_PLCP_AUTO;
+                       else
+                               val = WLC_PLCP_SHORT;
+
+                       bcom_ioctl(skfd, ifname, WLC_SET_PLCPHDR, &val, sizeof(val));
+               }
        }
        }
+
 }
 
 void set_wext_ssid(int skfd, char *ifname)
 }
 
 void set_wext_ssid(int skfd, char *ifname)
@@ -339,8 +378,8 @@ void setup_wext(int skfd, char *ifname)
        if (channel > 0) {
                wrq.u.freq.flags = IW_FREQ_FIXED;
                wrq.u.freq.m = channel;
        if (channel > 0) {
                wrq.u.freq.flags = IW_FREQ_FIXED;
                wrq.u.freq.m = channel;
+               IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFREQ, &wrq, "Set Frequency");
        }
        }
-       IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFREQ, &wrq, "Set Frequency");
        
        /* Set operation mode */
        int ap = 0, infra = 0, wet = 0;
        
        /* Set operation mode */
        int ap = 0, infra = 0, wet = 0;
@@ -357,7 +396,7 @@ void setup_wext(int skfd, char *ifname)
 
        wrq.u.txpower.value = -1;
        wrq.u.txpower.fixed = 1;
 
        wrq.u.txpower.value = -1;
        wrq.u.txpower.fixed = 1;
-       wrq.u.txpower.flags = IW_TXPOW_MWATT;
+       wrq.u.txpower.flags = IW_TXPOW_DBM;
        IW_SET_EXT_ERR(skfd, ifname, SIOCSIWTXPOW, &wrq, "Set Tx Power");
 
        /* Set up WEP */
        IW_SET_EXT_ERR(skfd, ifname, SIOCSIWTXPOW, &wrq, "Set Tx Power");
 
        /* Set up WEP */
This page took 0.027505 seconds and 4 git commands to generate.