diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-13 18:42:53 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-13 18:42:53 +0000 |
commit | 98996e380a7301ec5127de83e047d0bf8cf3df43 (patch) | |
tree | c622ac0ec843511e22dead730219517a7359d46c /libs/sys/luasrc/sys.lua | |
parent | 750a6910ed31451b88f8958c3982113d22c9de79 (diff) |
libs/sys: implement luci.sys.wifi.channels()
modules/admin-full: only display available channels
Diffstat (limited to 'libs/sys/luasrc/sys.lua')
-rw-r--r-- | libs/sys/luasrc/sys.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index 1ecd5d25a9..3412b32b70 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -681,6 +681,36 @@ function wifi.iwscan(iface) return iface and (iws[iface] or {}) or iws end +--- Get available channels from given wireless iface. +-- @param iface Wireless interface (optional) +-- @return Table of available channels +function wifi.channels(iface) + local cmd = "iwlist " .. ( iface or "" ) .. " freq 2>/dev/null" + local cns = { } + + local fd = io.popen(cmd) + if fd then + local ln, c, f + repeat + ln = fd:read("*l") or "" + c, f = ln:match("Channel (%d+) : (%d+%.%d+) GHz") + if c and f then + cns[tonumber(c)] = tonumber(f) + end + until not ( #ln > 0 ) + fd:close() + end + + if #cns == 0 then + cms = { + 2.412, 2.417, 2.422, 2.427, 2.432, 2.437, + 2.442, 2.447, 2.452, 2.457, 2.462 + } + end + + return cns +end + --- LuCI system utilities / init related functions. -- @class module |