libs: remove cbi folder
[project/luci.git] / libs / iwinfo / src / iwinfo_lualib.c
index a798d77..5509f4b 100644 (file)
@@ -23,13 +23,19 @@ static int iwinfo_L_type(lua_State *L)
 {
        const char *ifname = luaL_checkstring(L, 1);
 
+#ifdef USE_MADWIFI
+       if( madwifi_probe(ifname) )
+               lua_pushstring(L, "madwifi");
+       else
+#endif
+
+#ifdef USE_WL
        if( wl_probe(ifname) )
                lua_pushstring(L, "wl");
+       else
+#endif
 
-       else if( madwifi_probe(ifname) )
-               lua_pushstring(L, "madwifi");
-
-       else if( wext_probe(ifname) )
+       if( wext_probe(ifname) )
                lua_pushstring(L, "wext");
 
        else
@@ -161,44 +167,47 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int
                        lua_setfield(L, -2, "signal");
 
                        /* Crypto */
-                       lua_pushinteger(L, e->crypto.wpa_version);
-                       lua_setfield(L, -2, "wpa");
-
                        lua_pushboolean(L, (!e->crypto.wpa_version && e->crypto.enabled));
                        lua_setfield(L, -2, "wep");
 
-                       lua_newtable(L);
-                       for( j = 0, y = 1; j < IW_IE_CYPHER_NUM; j++ )
+                       if( e->crypto.wpa_version )
                        {
-                               if( e->crypto.group_ciphers & (1<<j) )
+                               lua_pushinteger(L, e->crypto.wpa_version);
+                               lua_setfield(L, -2, "wpa");
+
+                               lua_newtable(L);
+                               for( j = 0, y = 1; j < IW_IE_CYPHER_NUM; j++ )
                                {
-                                       lua_pushstring(L, iw_ie_cypher_name[j]);
-                                       lua_rawseti(L, -2, y++);
+                                       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 < IW_IE_CYPHER_NUM; j++ )
-                       {
-                               if( e->crypto.pair_ciphers & (1<<j) )
+                               lua_newtable(L);
+                               for( j = 0, y = 1; j < IW_IE_CYPHER_NUM; j++ )
                                {
-                                       lua_pushstring(L, iw_ie_cypher_name[j]);
-                                       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 < IW_IE_KEY_MGMT_NUM; j++ )
-                       {
-                               if( e->crypto.auth_suites & (1<<j) )
+                               lua_newtable(L);
+                               for( j = 0, y = 1; j < IW_IE_KEY_MGMT_NUM; j++ )
                                {
-                                       lua_pushstring(L, iw_ie_key_mgmt_name[j]);
-                                       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);
                }
@@ -207,7 +216,41 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int
        return 1;
 }
 
+/* Wrapper for frequency list */
+static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int *))
+{
+       int i, x, len;
+       char rv[IWINFO_BUFSIZE];
+       const char *ifname = luaL_checkstring(L, 1);
+       struct iwinfo_freqlist_entry *e;
+
+       lua_newtable(L);
+       memset(rv, 0, sizeof(rv));
+
+       if( !(*func)(ifname, rv, &len) )
+       {
+               for( i = 0, x = 1; i < len; i += sizeof(struct iwinfo_freqlist_entry), x++ )
+               {
+                       e = (struct iwinfo_freqlist_entry *) &rv[i];
+
+                       lua_newtable(L);
+
+                       /* MHz */
+                       lua_pushinteger(L, e->mhz);
+                       lua_setfield(L, -2, "mhz");
+
+                       /* Channel */
+                       lua_pushinteger(L, e->channel);
+                       lua_setfield(L, -2, "channel");
+
+                       lua_rawseti(L, -2, x);
+               }
+       }
+
+       return 1;
+}
 
+#ifdef USE_WL
 /* Broadcom */
 LUA_WRAP_INT(wl,channel)
 LUA_WRAP_INT(wl,frequency)
@@ -224,7 +267,10 @@ LUA_WRAP_STRING(wl,enctype)
 LUA_WRAP_LIST(wl,assoclist)
 LUA_WRAP_LIST(wl,txpwrlist)
 LUA_WRAP_LIST(wl,scanlist)
+LUA_WRAP_LIST(wl,freqlist)
+#endif
 
+#ifdef USE_MADWIFI
 /* Madwifi */
 LUA_WRAP_INT(madwifi,channel)
 LUA_WRAP_INT(madwifi,frequency)
@@ -241,6 +287,8 @@ LUA_WRAP_STRING(madwifi,enctype)
 LUA_WRAP_LIST(madwifi,assoclist)
 LUA_WRAP_LIST(madwifi,txpwrlist)
 LUA_WRAP_LIST(madwifi,scanlist)
+LUA_WRAP_LIST(madwifi,freqlist)
+#endif
 
 /* Wext */
 LUA_WRAP_INT(wext,channel)
@@ -258,7 +306,9 @@ LUA_WRAP_STRING(wext,enctype)
 LUA_WRAP_LIST(wext,assoclist)
 LUA_WRAP_LIST(wext,txpwrlist)
 LUA_WRAP_LIST(wext,scanlist)
+LUA_WRAP_LIST(wext,freqlist)
 
+#ifdef USE_WL
 /* Broadcom table */
 static const luaL_reg R_wl[] = {
        LUA_REG(wl,channel),
@@ -275,10 +325,13 @@ static const luaL_reg R_wl[] = {
        LUA_REG(wl,assoclist),
        LUA_REG(wl,txpwrlist),
        LUA_REG(wl,scanlist),
+       LUA_REG(wl,freqlist),
        LUA_REG(wl,mbssid_support),
        { NULL, NULL }
 };
+#endif
 
+#ifdef USE_MADWIFI
 /* Madwifi table */
 static const luaL_reg R_madwifi[] = {
        LUA_REG(madwifi,channel),
@@ -295,9 +348,11 @@ static const luaL_reg R_madwifi[] = {
        LUA_REG(madwifi,assoclist),
        LUA_REG(madwifi,txpwrlist),
        LUA_REG(madwifi,scanlist),
+       LUA_REG(madwifi,freqlist),
        LUA_REG(madwifi,mbssid_support),
        { NULL, NULL }
 };
+#endif
 
 /* Wext table */
 static const luaL_reg R_wext[] = {
@@ -315,6 +370,7 @@ static const luaL_reg R_wext[] = {
        LUA_REG(wext,assoclist),
        LUA_REG(wext,txpwrlist),
        LUA_REG(wext,scanlist),
+       LUA_REG(wext,freqlist),
        LUA_REG(wext,mbssid_support),
        { NULL, NULL }
 };
@@ -329,17 +385,21 @@ static const luaL_reg R_common[] = {
 LUALIB_API int luaopen_iwinfo(lua_State *L) {
        luaL_register(L, IWINFO_META, R_common);
 
+#ifdef USE_WL
        luaL_newmetatable(L, IWINFO_WL_META);
        luaL_register(L, NULL, R_wl);
        lua_pushvalue(L, -1);
        lua_setfield(L, -2, "__index");
        lua_setfield(L, -2, "wl");
+#endif
 
+#ifdef USE_MADWIFI
        luaL_newmetatable(L, IWINFO_MADWIFI_META);
        luaL_register(L, NULL, R_madwifi);
        lua_pushvalue(L, -1);
        lua_setfield(L, -2, "__index");
        lua_setfield(L, -2, "madwifi");
+#endif
 
        luaL_newmetatable(L, IWINFO_WEXT_META);
        luaL_register(L, NULL, R_wext);