*
* 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>
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;
+}
*
* 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>
*/
#ifndef _IWCONFIG_H__
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
*
* 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 <stdio.h>
{"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},
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")