From 64600a27ee42298c44867e9af67ac69797e7b5e1 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 9 May 2009 17:55:24 +0000 Subject: libs/luanet: add wifi channel enumeration --- libs/luanet/src/iwconfig.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ libs/luanet/src/iwconfig.h | 2 ++ libs/luanet/src/main.c | 2 ++ libs/luanet/src/test.lua | 9 ++++++++ 4 files changed, 65 insertions(+) (limited to 'libs/luanet') 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 * Copyright (C) 2008 Steven Barth + * Copyright (C) 2009 Jo-Philipp Wich */ #include @@ -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; +} diff --git a/libs/luanet/src/iwconfig.h b/libs/luanet/src/iwconfig.h index 59240d570..9c0870e48 100644 --- a/libs/luanet/src/iwconfig.h +++ b/libs/luanet/src/iwconfig.h @@ -13,6 +13,7 @@ * * Copyright (C) 2008 John Crispin * Copyright (C) 2008 Steven Barth + * Copyright (C) 2009 Jo-Philipp Wich */ #ifndef _IWCONFIG_H__ @@ -25,4 +26,5 @@ int iwc_set_essid(lua_State *L); int iwc_set_mode(lua_State *L); int iwc_set_channel(lua_State *L); int iwc_scan(lua_State *L); +int iwc_frequencies(lua_State *L); #endif diff --git a/libs/luanet/src/main.c b/libs/luanet/src/main.c index 0a42276cb..3193c722c 100644 --- a/libs/luanet/src/main.c +++ b/libs/luanet/src/main.c @@ -13,6 +13,7 @@ * * Copyright (C) 2008 John Crispin * Copyright (C) 2008 Steven Barth + * Copyright (C) 2009 Jo-Philipp Wich */ #include @@ -63,6 +64,7 @@ static luaL_reg func[] = { {"iwc_set_mode", iwc_set_mode}, {"iwc_set_channel", iwc_set_channel}, {"iwc_scan", iwc_scan}, + {"iwc_frequencies", iwc_frequencies}, {"vlan_getall", vlan_getall}, {"vlan_add", vlan_add}, {"vlan_del", vlan_del}, diff --git a/libs/luanet/src/test.lua b/libs/luanet/src/test.lua index 713836b55..23429aea9 100755 --- a/libs/luanet/src/test.lua +++ b/libs/luanet/src/test.lua @@ -93,6 +93,15 @@ if scan then end end end +local freq = luanet.iwc_frequencies("wlan0") +print("\nfrequencies on wlan0") +if freq then + for _,f in ipairs(freq) do + print(" channel -> "..f[1]) + print(" frequency -> "..f[2]) + print("") + end +end print("\n\n---vlan---\n") -- cgit v1.2.3