X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fluanet%2Fsrc%2Fiwconfig.c;h=707116928c2cac8d93756fdf03c2104156fd3ecd;hb=64600a27ee42298c44867e9af67ac69797e7b5e1;hp=5fc65b607a41e03cede9c38ac96a19563c9862f5;hpb=011a89028cb83544d2224359f5a20543cf39e4d0;p=project%2Fluci.git 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; +}