libiwinfo: clear buffer in nl80211_ifname2phy(), prevents running operations against...
[project/luci.git] / contrib / package / iwinfo / src / iwinfo_wl.c
index 7c1904b..1691e4b 100644 (file)
  * You should have received a copy of the GNU General Public License along
  * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
  *
- * This code is based on the wlc.c utility published by OpenWrt.org . 
+ * This code is based on the wlc.c utility published by OpenWrt.org .
  */
 
 #include "iwinfo_wl.h"
 #include "iwinfo_wext.h"
 
-static int ioctl_socket = -1;
-
 static int wl_ioctl(const char *name, int cmd, void *buf, int len)
 {
        struct ifreq ifr;
        wl_ioctl_t ioc;
 
-       /* prepare socket */
-       if( ioctl_socket == -1 )
-               ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
-
        /* do it */
        ioc.cmd = cmd;
        ioc.buf = buf;
        ioc.len = len;
+
        strncpy(ifr.ifr_name, name, IFNAMSIZ);
        ifr.ifr_data = (caddr_t) &ioc;
 
-       return ioctl(ioctl_socket, SIOCDEVPRIVATE, &ifr);
+       return iwinfo_ioctl(SIOCDEVPRIVATE, &ifr);
 }
 
 static struct wl_maclist * wl_read_assoclist(const char *ifname)
@@ -72,6 +67,11 @@ int wl_probe(const char *ifname)
        return 0;
 }
 
+void wl_close(void)
+{
+       /* Nop */
+}
+
 int wl_get_mode(const char *ifname, char *buf)
 {
        int ret = -1;
@@ -480,6 +480,66 @@ int wl_get_freqlist(const char *ifname, char *buf, int *len)
        return wext_get_freqlist(ifname, buf, len);
 }
 
+int wl_get_country(const char *ifname, char *buf)
+{
+       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;
+}
+
+int wl_get_countrylist(const char *ifname, char *buf, int *len)
+{
+       int i, count;
+       char cdata[WLC_IOCTL_MAXLEN];
+       struct iwinfo_country_entry *c = (struct iwinfo_country_entry *)buf;
+       wl_country_list_t *cl = (wl_country_list_t *)cdata;
+
+       cl->buflen = sizeof(cdata);
+
+       if( !wl_ioctl(ifname, WLC_GET_COUNTRY_LIST, cl, cl->buflen) )
+       {
+               for( i = 0, count = 0; i < cl->count; i++, c++ )
+               {
+                       sprintf(c->ccode, &cl->country_abbrev[i * WLC_CNTRY_BUF_SZ]);
+                       c->iso3166 = c->ccode[0] * 256 + c->ccode[1];
+
+                       /* IL0 -> World */
+                       if( !strcmp(c->ccode, "IL0") )
+                               c->iso3166 = 0x3030;
+
+                       /* YU -> RS */
+                       else if( !strcmp(c->ccode, "YU") )
+                               c->iso3166 = 0x5253;
+               }
+
+               *len = (i * sizeof(struct iwinfo_country_entry));
+               return 0;
+       }
+
+       return -1;
+}
+
+int wl_get_hwmodelist(const char *ifname, int *buf)
+{
+       return wext_get_hwmodelist(ifname, buf);
+}
+
 int wl_get_mbssid_support(const char *ifname, int *buf)
 {
        wlc_rev_info_t revinfo;
@@ -496,4 +556,3 @@ int wl_get_mbssid_support(const char *ifname, int *buf)
 
        return -1;
 }
-