libs/iwinfo: probe madwifi first, poking wifi0 with wl ioctls results in bus error
[project/luci.git] / libs / iwinfo / src / iwinfo_lualib.c
index 1a0d71b..8eb4ad5 100644 (file)
@@ -23,12 +23,12 @@ static int iwinfo_L_type(lua_State *L)
 {
        const char *ifname = luaL_checkstring(L, 1);
 
-       if( wl_probe(ifname) )
-               lua_pushstring(L, "wl");
-
-       else if( madwifi_probe(ifname) )
+       if( madwifi_probe(ifname) )
                lua_pushstring(L, "madwifi");
 
+       else if( wl_probe(ifname) )
+               lua_pushstring(L, "wl");
+
        else if( wext_probe(ifname) )
                lua_pushstring(L, "wext");
 
@@ -133,7 +133,7 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int
                                e->mac[3], e->mac[4], e->mac[5]);
 
                        lua_pushstring(L, macstr);
-                       lua_setfield(L, -2, "mac");
+                       lua_setfield(L, -2, "bssid");
 
                        /* ESSID */
                        if( e->ssid[0] )
@@ -150,48 +150,58 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int
                        lua_pushstring(L, (char *) e->mode);
                        lua_setfield(L, -2, "mode");
 
+                       /* Quality, Signal */
+                       lua_pushinteger(L, e->quality);
+                       lua_setfield(L, -2, "quality");
+
+                       lua_pushinteger(L, e->quality_max);
+                       lua_setfield(L, -2, "quality_max");
+
+                       lua_pushnumber(L, (e->signal - 0x100));
+                       lua_setfield(L, -2, "signal");
+
                        /* Crypto */
-                       lua_pushinteger(L, e->crypto.wpa_version);
-                       lua_setfield(L, -2, "wpa_version");
+                       lua_pushboolean(L, (!e->crypto.wpa_version && e->crypto.enabled));
+                       lua_setfield(L, -2, "wep");
 
-                       lua_newtable(L);
-                       for( j = 0, y = 1; j < sizeof(e->crypto.group_ciphers); j++ )
+                       if( e->crypto.wpa_version )
                        {
-                               if( e->crypto.group_ciphers[j] )
-                               {
-                                       lua_pushstring(L, (j < IW_IE_CYPHER_NUM)
-                                               ? iw_ie_cypher_name[j] : "Proprietary");
+                               lua_pushinteger(L, e->crypto.wpa_version);
+                               lua_setfield(L, -2, "wpa");
 
-                                       lua_rawseti(L, -2, y++);
+                               lua_newtable(L);
+                               for( j = 0, y = 1; j < IW_IE_CYPHER_NUM; j++ )
+                               {
+                                       if( e->crypto.group_ciphers & (1<<j) )
+                                       {
+                                               lua_pushstring(L, iw_ie_cypher_name[j]);
+                                               lua_rawseti(L, -2, y++);
+                                       }
                                }
-                       }
-                       lua_setfield(L, -2, "group_ciphers");
+                               lua_setfield(L, -2, "group_ciphers");
 
-                       lua_newtable(L);
-                       for( j = 0, y = 1; j < sizeof(e->crypto.pair_ciphers); j++ )
-                       {
-                               if( e->crypto.pair_ciphers[j] )
+                               lua_newtable(L);
+                               for( j = 0, y = 1; j < IW_IE_CYPHER_NUM; j++ )
                                {
-                                       lua_pushstring(L, (j < IW_IE_CYPHER_NUM)
-                                               ? iw_ie_cypher_name[j] : "Proprietary");
-
-                                       lua_rawseti(L, -2, y++);
+                                       if( e->crypto.pair_ciphers & (1<<j) )
+                                       {
+                                               lua_pushstring(L, iw_ie_cypher_name[j]);
+                                               lua_rawseti(L, -2, y++);
+                                       }
                                }
-                       }
-                       lua_setfield(L, -2, "pair_ciphers");
+                               lua_setfield(L, -2, "pair_ciphers");
 
-                       lua_newtable(L);
-                       for( j = 0, y = 1; j < sizeof(e->crypto.auth_suites); j++ )
-                       {
-                               if( e->crypto.auth_suites[j] )
+                               lua_newtable(L);
+                               for( j = 0, y = 1; j < IW_IE_KEY_MGMT_NUM; j++ )
                                {
-                                       lua_pushstring(L, (j < IW_IE_KEY_MGMT_NUM)
-                                               ? iw_ie_key_mgmt_name[j] : "Proprietary");
-
-                                       lua_rawseti(L, -2, y++);
+                                       if( e->crypto.auth_suites & (1<<j) )
+                                       {
+                                               lua_pushstring(L, iw_ie_key_mgmt_name[j]);
+                                               lua_rawseti(L, -2, y++);
+                                       }
                                }
+                               lua_setfield(L, -2, "auth_suites");
                        }
-                       lua_setfield(L, -2, "auth_suites");
 
                        lua_rawseti(L, -2, x);
                }