diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-10-27 14:11:11 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-10-27 14:13:05 +0100 |
commit | 927dc1aff9973e781af742be7835e499bb701a60 (patch) | |
tree | cb84a4b4ee87bfb891fbe8837580c3ac4b250033 /modules/luci-base/luasrc | |
parent | 57ba1922b7ad34886c96a1afcc364472568db462 (diff) |
luci-base: eliminiate use of uci state vars in luci.sys
Rewrite `luci.sys.wifi.getiwinfo()` to use the ubus wireless state instead of
depreacated uci state vars in order to map abstract network notation to
wireless ifnames.
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r-- | modules/luci-base/luasrc/sys.lua | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/modules/luci-base/luasrc/sys.lua b/modules/luci-base/luasrc/sys.lua index 3977da3eda..77f4d44a54 100644 --- a/modules/luci-base/luasrc/sys.lua +++ b/modules/luci-base/luasrc/sys.lua @@ -581,30 +581,20 @@ function wifi.getiwinfo(ifname) local stat, iwinfo = pcall(require, "iwinfo") if ifname then - local c = 0 - local u = uci.cursor_state() local d, n = ifname:match("^(%w+)%.network(%d+)") - if d and n then + local wstate = luci.util.ubus("network.wireless", "status") or { } + + d = d or ifname + n = n and tonumber(n) or 1 + + if type(wstate[d]) == "table" and + type(wstate[d].interfaces) == "table" and + type(wstate[d].interfaces[n]) == "table" and + type(wstate[d].interfaces[n].ifname) == "string" + then + ifname = wstate[d].interfaces[n].ifname + else ifname = d - n = tonumber(n) - u:foreach("wireless", "wifi-iface", - function(s) - if s.device == d then - c = c + 1 - if c == n then - ifname = s.ifname or s.device - return false - end - end - end) - elseif u:get("wireless", ifname) == "wifi-device" then - u:foreach("wireless", "wifi-iface", - function(s) - if s.device == ifname and s.ifname then - ifname = s.ifname - return false - end - end) end local t = stat and iwinfo.type(ifname) |