libiwinfo:
[project/luci.git] / contrib / package / iwinfo / src / iwinfo_lualib.c
index 1377ffe..516b11f 100644 (file)
@@ -308,6 +308,22 @@ static int iwinfo_L_type(lua_State *L)
        return 1;
 }
 
+/* Shutdown backends */
+static int iwinfo_L__gc(lua_State *L)
+{
+#ifdef USE_WL
+       wl_close();
+#endif
+#ifdef USE_MADWIFI
+       madwifi_close();
+#endif
+#ifdef USE_NL80211
+       nl80211_close();
+#endif
+       wext_close();
+       iwinfo_close();
+}
+
 /*
  * Build a short textual description of the crypto info
  */
@@ -401,22 +417,29 @@ static char * iwinfo_crypto_desc(struct iwinfo_crypto_entry *c)
                                        case 3:
                                                sprintf(desc, "mixed WPA/WPA2 %s (%s)",
                                                        iwinfo_crypto_print_suites(c->auth_suites),
-                                                       iwinfo_crypto_print_ciphers(c->pair_ciphers));
+                                                       iwinfo_crypto_print_ciphers(
+                                                               c->pair_ciphers & c->group_ciphers));
                                                break;
 
                                        case 2:
                                                sprintf(desc, "WPA2 %s (%s)",
                                                        iwinfo_crypto_print_suites(c->auth_suites),
-                                                       iwinfo_crypto_print_ciphers(c->pair_ciphers));
+                                                       iwinfo_crypto_print_ciphers(
+                                                               c->pair_ciphers & c->group_ciphers));
                                                break;
 
                                        case 1:
                                                sprintf(desc, "WPA %s (%s)",
                                                        iwinfo_crypto_print_suites(c->auth_suites),
-                                                       iwinfo_crypto_print_ciphers(c->pair_ciphers));
+                                                       iwinfo_crypto_print_ciphers(
+                                                               c->pair_ciphers & c->group_ciphers));
                                                break;
                                }
                        }
+                       else
+                       {
+                               sprintf(desc, "None");
+                       }
                }
                else
                {
@@ -656,6 +679,10 @@ static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int
                        lua_pushinteger(L, e->channel);
                        lua_setfield(L, -2, "channel");
 
+                       /* Restricted (DFS/TPC/Radar) */
+                       lua_pushboolean(L, e->restricted);
+                       lua_setfield(L, -2, "restricted");
+
                        lua_rawseti(L, -2, x);
                }
        }
@@ -675,7 +702,53 @@ static int iwinfo_L_encryption(lua_State *L, int (*func)(const char *, char *))
                return 1;
        }
 
-       return 0;
+       lua_pushnil(L);
+       return 1;
+}
+
+/* Wrapper for hwmode list */
+static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
+{
+       const char *ifname = luaL_checkstring(L, 1);
+       int hwmodes = 0;
+
+       if( !(*func)(ifname, &hwmodes) )
+       {
+               lua_newtable(L);
+
+               lua_pushboolean(L, hwmodes & IWINFO_80211_A);
+               lua_setfield(L, -2, "a");
+
+               lua_pushboolean(L, hwmodes & IWINFO_80211_B);
+               lua_setfield(L, -2, "b");
+
+               lua_pushboolean(L, hwmodes & IWINFO_80211_G);
+               lua_setfield(L, -2, "g");
+
+               lua_pushboolean(L, hwmodes & IWINFO_80211_N);
+               lua_setfield(L, -2, "n");
+
+               return 1;
+       }
+
+       lua_pushnil(L);
+       return 1;
+}
+
+/* Wrapper for mbbsid_support */
+static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
+{
+       const char *ifname = luaL_checkstring(L, 1);
+       int support = 0;
+
+       if( !(*func)(ifname, &support) )
+       {
+               lua_pushboolean(L, support);
+               return 1;
+       }
+
+       lua_pushnil(L);
+       return 1;
 }
 
 /* Wrapper for country list */
@@ -745,7 +818,6 @@ LUA_WRAP_INT(wl,signal)
 LUA_WRAP_INT(wl,noise)
 LUA_WRAP_INT(wl,quality)
 LUA_WRAP_INT(wl,quality_max)
-LUA_WRAP_INT(wl,mbssid_support)
 LUA_WRAP_STRING(wl,mode)
 LUA_WRAP_STRING(wl,ssid)
 LUA_WRAP_STRING(wl,bssid)
@@ -755,7 +827,9 @@ LUA_WRAP_LIST(wl,txpwrlist)
 LUA_WRAP_LIST(wl,scanlist)
 LUA_WRAP_LIST(wl,freqlist)
 LUA_WRAP_LIST(wl,countrylist)
+LUA_WRAP_LIST(wl,hwmodelist)
 LUA_WRAP_LIST(wl,encryption)
+LUA_WRAP_LIST(wl,mbssid_support)
 #endif
 
 #ifdef USE_MADWIFI
@@ -768,7 +842,6 @@ LUA_WRAP_INT(madwifi,signal)
 LUA_WRAP_INT(madwifi,noise)
 LUA_WRAP_INT(madwifi,quality)
 LUA_WRAP_INT(madwifi,quality_max)
-LUA_WRAP_INT(madwifi,mbssid_support)
 LUA_WRAP_STRING(madwifi,mode)
 LUA_WRAP_STRING(madwifi,ssid)
 LUA_WRAP_STRING(madwifi,bssid)
@@ -778,7 +851,9 @@ LUA_WRAP_LIST(madwifi,txpwrlist)
 LUA_WRAP_LIST(madwifi,scanlist)
 LUA_WRAP_LIST(madwifi,freqlist)
 LUA_WRAP_LIST(madwifi,countrylist)
+LUA_WRAP_LIST(madwifi,hwmodelist)
 LUA_WRAP_LIST(madwifi,encryption)
+LUA_WRAP_LIST(madwifi,mbssid_support)
 #endif
 
 #ifdef USE_NL80211
@@ -791,7 +866,6 @@ LUA_WRAP_INT(nl80211,signal)
 LUA_WRAP_INT(nl80211,noise)
 LUA_WRAP_INT(nl80211,quality)
 LUA_WRAP_INT(nl80211,quality_max)
-LUA_WRAP_INT(nl80211,mbssid_support)
 LUA_WRAP_STRING(nl80211,mode)
 LUA_WRAP_STRING(nl80211,ssid)
 LUA_WRAP_STRING(nl80211,bssid)
@@ -801,7 +875,9 @@ LUA_WRAP_LIST(nl80211,txpwrlist)
 LUA_WRAP_LIST(nl80211,scanlist)
 LUA_WRAP_LIST(nl80211,freqlist)
 LUA_WRAP_LIST(nl80211,countrylist)
+LUA_WRAP_LIST(nl80211,hwmodelist)
 LUA_WRAP_LIST(nl80211,encryption)
+LUA_WRAP_LIST(nl80211,mbssid_support)
 #endif
 
 /* Wext */
@@ -813,7 +889,6 @@ LUA_WRAP_INT(wext,signal)
 LUA_WRAP_INT(wext,noise)
 LUA_WRAP_INT(wext,quality)
 LUA_WRAP_INT(wext,quality_max)
-LUA_WRAP_INT(wext,mbssid_support)
 LUA_WRAP_STRING(wext,mode)
 LUA_WRAP_STRING(wext,ssid)
 LUA_WRAP_STRING(wext,bssid)
@@ -823,7 +898,9 @@ LUA_WRAP_LIST(wext,txpwrlist)
 LUA_WRAP_LIST(wext,scanlist)
 LUA_WRAP_LIST(wext,freqlist)
 LUA_WRAP_LIST(wext,countrylist)
+LUA_WRAP_LIST(wext,hwmodelist)
 LUA_WRAP_LIST(wext,encryption)
+LUA_WRAP_LIST(wext,mbssid_support)
 
 #ifdef USE_WL
 /* Broadcom table */
@@ -845,6 +922,7 @@ static const luaL_reg R_wl[] = {
        LUA_REG(wl,scanlist),
        LUA_REG(wl,freqlist),
        LUA_REG(wl,countrylist),
+       LUA_REG(wl,hwmodelist),
        LUA_REG(wl,encryption),
        LUA_REG(wl,mbssid_support),
        { NULL, NULL }
@@ -871,6 +949,7 @@ static const luaL_reg R_madwifi[] = {
        LUA_REG(madwifi,scanlist),
        LUA_REG(madwifi,freqlist),
        LUA_REG(madwifi,countrylist),
+       LUA_REG(madwifi,hwmodelist),
        LUA_REG(madwifi,encryption),
        LUA_REG(madwifi,mbssid_support),
        { NULL, NULL }
@@ -897,6 +976,7 @@ static const luaL_reg R_nl80211[] = {
        LUA_REG(nl80211,scanlist),
        LUA_REG(nl80211,freqlist),
        LUA_REG(nl80211,countrylist),
+       LUA_REG(nl80211,hwmodelist),
        LUA_REG(nl80211,encryption),
        LUA_REG(nl80211,mbssid_support),
        { NULL, NULL }
@@ -922,6 +1002,7 @@ static const luaL_reg R_wext[] = {
        LUA_REG(wext,scanlist),
        LUA_REG(wext,freqlist),
        LUA_REG(wext,countrylist),
+       LUA_REG(wext,hwmodelist),
        LUA_REG(wext,encryption),
        LUA_REG(wext,mbssid_support),
        { NULL, NULL }
@@ -930,6 +1011,7 @@ static const luaL_reg R_wext[] = {
 /* Common */
 static const luaL_reg R_common[] = {
        { "type", iwinfo_L_type },
+       { "__gc", iwinfo_L__gc  },
        { NULL, NULL }
 };