libs/sys: resolve pseudo ifaces in luci.sys.wifi.getiwinfo()
This commit is contained in:
parent
66736c8574
commit
cca45d0bdb
1 changed files with 41 additions and 9 deletions
|
@ -31,6 +31,7 @@ local table = require "table"
|
||||||
local nixio = require "nixio"
|
local nixio = require "nixio"
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
local iwinfo = require "iwinfo"
|
local iwinfo = require "iwinfo"
|
||||||
|
local uci = require "luci.model.uci"
|
||||||
|
|
||||||
local luci = {}
|
local luci = {}
|
||||||
luci.util = require "luci.util"
|
luci.util = require "luci.util"
|
||||||
|
@ -638,16 +639,47 @@ wifi = {}
|
||||||
-- @param ifname String containing the interface name
|
-- @param ifname String containing the interface name
|
||||||
-- @return A wrapped iwinfo object instance
|
-- @return A wrapped iwinfo object instance
|
||||||
function wifi.getiwinfo(ifname)
|
function wifi.getiwinfo(ifname)
|
||||||
|
if ifname then
|
||||||
|
local c = 0
|
||||||
|
local u = uci.cursor_state()
|
||||||
|
local d, n = ifname:match("^(%w+)%.network(%d+)")
|
||||||
|
if d and n then
|
||||||
|
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 = iwinfo.type(ifname)
|
local t = iwinfo.type(ifname)
|
||||||
if t then
|
if t then
|
||||||
local x = iwinfo[t]
|
local x = iwinfo[t]
|
||||||
return setmetatable({}, {
|
return setmetatable({}, {
|
||||||
__index = function(t, k)
|
__index = function(t, k)
|
||||||
if x[k] then return x[k](ifname) end
|
if k == "ifname" then
|
||||||
|
return ifname
|
||||||
|
elseif x[k] then
|
||||||
|
return x[k](ifname)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Get iwconfig output for all wireless devices.
|
--- Get iwconfig output for all wireless devices.
|
||||||
-- @return Table of tables containing the iwconfing output for each wifi device
|
-- @return Table of tables containing the iwconfing output for each wifi device
|
||||||
|
@ -705,7 +737,7 @@ end
|
||||||
function wifi.channels(iface)
|
function wifi.channels(iface)
|
||||||
local t = iwinfo.type(iface or "")
|
local t = iwinfo.type(iface or "")
|
||||||
local cns
|
local cns
|
||||||
if t and iwinfo[t] then
|
if iface and t and iwinfo[t] then
|
||||||
cns = iwinfo[t].freqlist(iface)
|
cns = iwinfo[t].freqlist(iface)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue