diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-09 17:55:24 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-09 17:55:24 +0000 |
commit | 64600a27ee42298c44867e9af67ac69797e7b5e1 (patch) | |
tree | 0029e6a8fb1a43a882d5fc0a7bdcd30ed25a5c64 /libs/luanet/src/iwconfig.c | |
parent | 011a89028cb83544d2224359f5a20543cf39e4d0 (diff) |
libs/luanet: add wifi channel enumeration
Diffstat (limited to 'libs/luanet/src/iwconfig.c')
-rw-r--r-- | libs/luanet/src/iwconfig.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/libs/luanet/src/iwconfig.c b/libs/luanet/src/iwconfig.c index 5fc65b607..707116928 100644 --- a/libs/luanet/src/iwconfig.c +++ b/libs/luanet/src/iwconfig.c @@ -13,6 +13,7 @@ * * Copyright (C) 2008 John Crispin <blogic@openwrt.org> * Copyright (C) 2008 Steven Barth <steven@midlink.org> + * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> */ #include <net/if.h> @@ -827,3 +828,54 @@ realloc: free(buffer); return 0; } + +int iwc_frequencies(lua_State *L) +{ + int i; + int has_range; + char *ifname; + struct iw_range range; + + if(lua_gettop(L) != 1) + { + lua_pushstring(L, "invalid arg list"); + lua_error(L); + return 0; + } + + ifname = (char *)lua_tostring (L, 1); + + /* Get range stuff */ + has_range = (iw_get_range_info(sock_iwconfig, ifname, &range) >= 0); + + /* Check if the interface could support scanning. */ + if((!has_range) || (range.we_version_compiled < 14)) + { + lua_pushstring(L, "interface does not support frequency enumeration"); + lua_error(L); + } + else + { + lua_newtable(L); + + for(i = 0; i < range.num_frequency; i++) + { + lua_pushnumber(L, i + 1); + lua_newtable(L); + + lua_pushinteger(L, 1); + lua_pushinteger(L, (int)range.freq[i].i); + lua_settable(L, -3); + + lua_pushinteger(L, 2); + lua_pushnumber(L, iw_freq2float(&(range.freq[i]))); + lua_settable(L, -3); + + lua_settable(L, -3); + } + + return 1; + } + + return 0; +} |