diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-08-24 05:54:38 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-08-24 05:54:38 +0000 |
commit | 12f582bcc7dc8ab447c01e2cfa939caa7dfa321b (patch) | |
tree | ac2f8917d2dbbd4413f68c09a1c19d3b4ae21ebe /libs/iwinfo/src/iwinfo_lualib.c | |
parent | 1c8db37e8b93855530102ded098daa95076f981b (diff) |
libs/iwinfo: implement wifi scans
Diffstat (limited to 'libs/iwinfo/src/iwinfo_lualib.c')
-rw-r--r-- | libs/iwinfo/src/iwinfo_lualib.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/libs/iwinfo/src/iwinfo_lualib.c b/libs/iwinfo/src/iwinfo_lualib.c index e63eeabd4..1a0d71b99 100644 --- a/libs/iwinfo/src/iwinfo_lualib.c +++ b/libs/iwinfo/src/iwinfo_lualib.c @@ -107,6 +107,100 @@ static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, in return 1; } +/* Wrapper for scan list */ +static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int *)) +{ + int i, j, x, y, len; + char rv[IWINFO_BUFSIZE]; + char macstr[18]; + const char *ifname = luaL_checkstring(L, 1); + struct iwinfo_scanlist_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_scanlist_entry), x++ ) + { + e = (struct iwinfo_scanlist_entry *) &rv[i]; + + lua_newtable(L); + + /* BSSID */ + sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X", + e->mac[0], e->mac[1], e->mac[2], + e->mac[3], e->mac[4], e->mac[5]); + + lua_pushstring(L, macstr); + lua_setfield(L, -2, "mac"); + + /* ESSID */ + if( e->ssid[0] ) + { + lua_pushstring(L, (char *) e->ssid); + lua_setfield(L, -2, "ssid"); + } + + /* Channel */ + lua_pushinteger(L, e->channel); + lua_setfield(L, -2, "channel"); + + /* Mode */ + lua_pushstring(L, (char *) e->mode); + lua_setfield(L, -2, "mode"); + + /* Crypto */ + lua_pushinteger(L, e->crypto.wpa_version); + lua_setfield(L, -2, "wpa_version"); + + lua_newtable(L); + for( j = 0, y = 1; j < sizeof(e->crypto.group_ciphers); j++ ) + { + if( e->crypto.group_ciphers[j] ) + { + lua_pushstring(L, (j < IW_IE_CYPHER_NUM) + ? iw_ie_cypher_name[j] : "Proprietary"); + + lua_rawseti(L, -2, y++); + } + } + 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_pushstring(L, (j < IW_IE_CYPHER_NUM) + ? iw_ie_cypher_name[j] : "Proprietary"); + + lua_rawseti(L, -2, y++); + } + } + 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_pushstring(L, (j < IW_IE_KEY_MGMT_NUM) + ? iw_ie_key_mgmt_name[j] : "Proprietary"); + + lua_rawseti(L, -2, y++); + } + } + lua_setfield(L, -2, "auth_suites"); + + lua_rawseti(L, -2, x); + } + } + + return 1; +} + + /* Broadcom */ LUA_WRAP_INT(wl,channel) LUA_WRAP_INT(wl,frequency) @@ -122,6 +216,7 @@ LUA_WRAP_STRING(wl,bssid) LUA_WRAP_STRING(wl,enctype) LUA_WRAP_LIST(wl,assoclist) LUA_WRAP_LIST(wl,txpwrlist) +LUA_WRAP_LIST(wl,scanlist) /* Madwifi */ LUA_WRAP_INT(madwifi,channel) @@ -138,6 +233,7 @@ LUA_WRAP_STRING(madwifi,bssid) LUA_WRAP_STRING(madwifi,enctype) LUA_WRAP_LIST(madwifi,assoclist) LUA_WRAP_LIST(madwifi,txpwrlist) +LUA_WRAP_LIST(madwifi,scanlist) /* Wext */ LUA_WRAP_INT(wext,channel) @@ -154,6 +250,7 @@ LUA_WRAP_STRING(wext,bssid) LUA_WRAP_STRING(wext,enctype) LUA_WRAP_LIST(wext,assoclist) LUA_WRAP_LIST(wext,txpwrlist) +LUA_WRAP_LIST(wext,scanlist) /* Broadcom table */ static const luaL_reg R_wl[] = { @@ -170,6 +267,7 @@ static const luaL_reg R_wl[] = { LUA_REG(wl,enctype), LUA_REG(wl,assoclist), LUA_REG(wl,txpwrlist), + LUA_REG(wl,scanlist), LUA_REG(wl,mbssid_support), { NULL, NULL } }; @@ -189,6 +287,7 @@ static const luaL_reg R_madwifi[] = { LUA_REG(madwifi,enctype), LUA_REG(madwifi,assoclist), LUA_REG(madwifi,txpwrlist), + LUA_REG(madwifi,scanlist), LUA_REG(madwifi,mbssid_support), { NULL, NULL } }; @@ -208,6 +307,7 @@ static const luaL_reg R_wext[] = { LUA_REG(wext,enctype), LUA_REG(wext,assoclist), LUA_REG(wext,txpwrlist), + LUA_REG(wext,scanlist), LUA_REG(wext,mbssid_support), { NULL, NULL } }; |