contrib: remove hard dependency on libiwinfo, madwifi scan fixes
[project/luci.git] / contrib / package / iwinfo / src / iwinfo_madwifi.c
index cb21ac5..a607013 100644 (file)
@@ -292,14 +292,23 @@ static char * madwifi_ifadd(const char *ifname)
                snprintf(nif, sizeof(nif), "tmp.%s", ifname);
 
                strncpy(cp.icp_name, nif, IFNAMSIZ);
-               cp.icp_opmode = IEEE80211_M_MONITOR;
+               cp.icp_opmode = IEEE80211_M_STA;
                cp.icp_flags  = IEEE80211_CLONE_BSSID;
 
                strncpy(ifr.ifr_name, wifidev, IFNAMSIZ);
                ifr.ifr_data  = (void *)&cp;
 
                if( !iwinfo_ioctl(SIOC80211IFCREATE, &ifr) )
+               {
                        return nif;
+               }
+               else
+               {
+                       cp.icp_opmode = IEEE80211_M_MONITOR;
+
+                       if( !iwinfo_ioctl(SIOC80211IFCREATE, &ifr) )
+                               return nif;
+               }
        }
 
        return NULL;
@@ -539,7 +548,7 @@ int madwifi_get_quality_max(const char *ifname, int *buf)
 
 int madwifi_get_encryption(const char *ifname, char *buf)
 {
-       int ciphers = 0, key_type = 0, key_len = 0;
+       int ciphers = 0, key_len = 0;
        struct iwinfo_crypto_entry *c = (struct iwinfo_crypto_entry *)buf;
        struct iwreq wrq;
        struct ieee80211req_key wk;
@@ -548,16 +557,6 @@ int madwifi_get_encryption(const char *ifname, char *buf)
        memset(&wk, 0, sizeof(wk));
        memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
 
-       /* Get key information */
-       if( get80211priv(ifname, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk)) >= 0 )
-       {
-               key_type = wk.ik_type;
-
-               /* Type 0 == WEP */
-               if( key_type == 0 )
-                       c->auth_algs = (IWINFO_AUTH_OPEN | IWINFO_AUTH_SHARED);
-       }
-
        /* Get wpa protocol version */
        wrq.u.mode = IEEE80211_PARAM_WPA;
        if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 )
@@ -576,12 +575,28 @@ int madwifi_get_encryption(const char *ifname, char *buf)
                                c->auth_suites |= IWINFO_KMGMT_PSK;
                                break;
 
+                       case IEEE80211_AUTH_OPEN:
+                               c->auth_algs |= IWINFO_AUTH_OPEN;
+                               break;
+
+                       case IEEE80211_AUTH_SHARED:
+                               c->auth_algs |= IWINFO_AUTH_SHARED;
+                               break;
+
                        default:
                                c->auth_suites |= IWINFO_KMGMT_NONE;
                                break;
                }
        }
 
+       /* Get key information */
+       if( get80211priv(ifname, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk)) >= 0 )
+       {
+               /* Type 0 == WEP */
+               if( (wk.ik_type == 0) && (c->auth_algs == 0) )
+                       c->auth_algs = (IWINFO_AUTH_OPEN | IWINFO_AUTH_SHARED);
+       }
+
        /* Get group key length */
        wrq.u.mode = IEEE80211_PARAM_MCASTKEYLEN;
        if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 )
@@ -772,7 +787,15 @@ int madwifi_get_scanlist(const char *ifname, char *buf, int *len)
                        if( (res = madwifi_ifadd(ifname)) != NULL )
                        {
                                if( iwinfo_ifup(res) )
+                               {
+                                       wext_get_scanlist(res, buf, len);
+                                       sleep(1);
+
+                                       wext_get_scanlist(res, buf, len);
+                                       sleep(1);
+
                                        ret = wext_get_scanlist(res, buf, len);
+                               }
 
                                iwinfo_ifdown(res);
                                madwifi_ifdel(res);