libiwinfo: implement hwmodelist()
[project/luci.git] / contrib / package / iwinfo / src / iwinfo_wext.c
index 8fe0305..5eecd0d 100644 (file)
@@ -89,7 +89,10 @@ static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq)
 {
        /* 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);
+       }
 
        if( !strncmp(ifname, "mon.", 4) )
                strncpy(wrq->ifr_name, &ifname[4], IFNAMSIZ);
@@ -110,6 +113,14 @@ int wext_probe(const char *ifname)
        return 0;
 }
 
+void wext_close(void)
+{
+       wext_scan_close();
+
+       if( ioctl_socket > -1 )
+               close(ioctl_socket);
+}
+
 int wext_get_mode(const char *ifname, char *buf)
 {
        struct iwreq wrq;
@@ -433,8 +444,9 @@ int wext_get_freqlist(const char *ifname, char *buf, int *len)
 
                for(i = 0; i < range.num_frequency; i++)
                {
-                       entry.mhz     = wext_freq2mhz(&range.freq[i]);
-                       entry.channel = range.freq[i].i;
+                       entry.mhz        = wext_freq2mhz(&range.freq[i]);
+                       entry.channel    = range.freq[i].i;
+                       entry.restricted = 0;
 
                        memcpy(&buf[bl], &entry, sizeof(struct iwinfo_freqlist_entry));
                        bl += sizeof(struct iwinfo_freqlist_entry);
@@ -459,6 +471,33 @@ int wext_get_countrylist(const char *ifname, char *buf, int *len)
        return -1;
 }
 
+int wext_get_hwmodelist(const char *ifname, int *buf)
+{
+       char chans[IWINFO_BUFSIZE] = { 0 };
+       struct iwinfo_freqlist_entry *e = NULL;
+       int len = 0;
+
+       if( !wext_get_freqlist(ifname, chans, &len) )
+       {
+               for( e = (struct iwinfo_freqlist_entry *)chans; e->channel; e++ )
+               {
+                       if( e->channel <= 14 )
+                       {
+                               *buf |= IWINFO_80211_B;
+                               *buf |= IWINFO_80211_G;
+                       }
+                       else
+                       {
+                               *buf |= IWINFO_80211_A;
+                       }
+               }
+
+               return 0;
+       }
+
+       return -1;
+}
+
 int wext_get_encryption(const char *ifname, char *buf)
 {
        /* No reliable crypto info in wext */