libiwinfo: support txpwrlist(), freqlist() and countrylist() for radioX pseudodevices...
[project/luci.git] / contrib / package / iwinfo / src / iwinfo_wl.c
index 1a7d586..cb778fe 100644 (file)
@@ -30,7 +30,10 @@ static int wl_ioctl(const char *name, int cmd, void *buf, int len)
 
        /* prepare socket */
        if( ioctl_socket == -1 )
+       {
                ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
+               fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC);
+       }
 
        /* do it */
        ioc.cmd = cmd;
@@ -72,6 +75,12 @@ int wl_probe(const char *ifname)
        return 0;
 }
 
+void wl_close(void)
+{
+       if( ioctl_socket > -1 )
+               close(ioctl_socket);
+}
+
 int wl_get_mode(const char *ifname, char *buf)
 {
        int ret = -1;
@@ -482,8 +491,23 @@ int wl_get_freqlist(const char *ifname, char *buf, int *len)
 
 int wl_get_country(const char *ifname, char *buf)
 {
-       if( !wl_ioctl(ifname, WLC_GET_COUNTRY, buf, WLC_CNTRY_BUF_SZ) )
+       char ccode[WLC_CNTRY_BUF_SZ];
+
+       if( !wl_ioctl(ifname, WLC_GET_COUNTRY, ccode, WLC_CNTRY_BUF_SZ) )
+       {
+               /* IL0 -> World */
+               if( !strcmp(ccode, "IL0") )
+                       sprintf(buf, "00");
+
+               /* YU -> RS */
+               else if( !strcmp(ccode, "YU") )
+                       sprintf(buf, "RS");
+
+               else
+                       memcpy(buf, ccode, 2);
+
                return 0;
+       }
 
        return -1;
 }