]]--
-local type, pairs, ipairs, loadfile, table, tonumber, math, i18n
- = type, pairs, ipairs, loadfile, table, tonumber, math, luci.i18n
+local type, next, pairs, ipairs, loadfile, table, tonumber, math, i18n
+ = type, next, pairs, ipairs, loadfile, table, tonumber, math, luci.i18n
local nxo = require "nixio"
local ipc = require "luci.ip"
end
end
+function _iface_virtual(x)
+ return (
+ x:match("^6in4-%w") or x:match("^6to4-%w") or x:match("^3g-%w") or
+ x:match("^ppp-%w") or x:match("^pppoe-%w") or x:match("^pppoa-%w") or
+ x:match("^relay-%w")
+ )
+end
+
function _iface_ignore(x)
return (
x:match("^wmaster%d") or x:match("^wifi%d") or x:match("^hwsim%d") or
- x:match("^imq%d") or x:match("^mon.wlan%d") or x:match("^6in4-%w") or
- x:match("^6to4-%w") or x:match("^3g-%w") or x:match("^ppp-%w") or
- x:match("^pppoe-%w") or x:match("^pppoa-%w") or x == "sit0" or x == "lo"
+ x:match("^imq%d") or x:match("^mon.wlan%d") or
+ x == "sit0" or x == "lo" or _iface_virtual(x)
)
end
local name = i.name:match("[^:]+")
local prnt = name:match("^([^%.]+)%.")
- if not _iface_ignore(name) then
+ if _iface_virtual(name) or not _iface_ignore(name) then
ifs[name] = ifs[name] or {
idx = i.ifindex or n,
name = name,
local p = self:proto()
if self:is_bridge() then
return "br-" .. self.sid
+ elseif self:proto() == "relay" then
+ return uci_s:get("network", self.sid, "up") == "1" and "lo" or nil
elseif self:is_virtual() then
return p .. "-" .. self.sid
else
dev = (type(dev) == "table") and dev[1] or dev
end
- return dev
+ for dev in utl.imatch(dev) do
+ return dev
+ end
end
function network.proto(self)
local p = self:proto()
return (
p == "3g" or p == "6in4" or p == "6to4" or p == "ppp" or
- p == "pppoe" or p == "pppoa"
+ p == "pppoe" or p == "pppoa" or p == "relay"
)
end
wifidev = utl.class()
function wifidev.__init__(self, dev)
- self.sid = dev
+ self.sid = dev
+ self.iwinfo = dev and sys.wifi.getiwinfo(dev) or { }
end
function wifidev.get(self, opt)
return self.sid
end
+function wifidev.hwmodes(self)
+ local l = self.iwinfo.hwmodelist
+ if l and next(l) then
+ return l
+ else
+ return { b = true, g = true }
+ end
+end
+
+function wifidev.get_i18n(self)
+ local t = "Generic"
+ if self.iwinfo.type == "wl" then
+ t = "Broadcom"
+ elseif self.iwinfo.type == "madwifi" then
+ t = "Atheros"
+ end
+
+ local m = ""
+ local l = self:hwmodes()
+ if l.a then m = m .. "a" end
+ if l.b then m = m .. "b" end
+ if l.g then m = m .. "g" end
+ if l.n then m = m .. "n" end
+
+ return "%s 802.11%s Wireless Controller (%s)" %{ t, m, self:name() }
+end
+
function wifidev.is_up(self)
local up = false
return uci_s:get("wifinet", self.sid, "network")
end
+function wifinet.id(self)
+ return self.netid
+end
+
function wifinet.name(self)
return self.sid
end
return self.iwinfo.noise or 0
end
+function wifinet.country(self)
+ return self.iwinfo.country or "00"
+end
+
+function wifinet.txpower(self)
+ return self.iwinfo.txpower or 0
+end
+
function wifinet.signal_level(self, s, n)
if self:active_bssid() ~= "00:00:00:00:00:00" then
local signal = s or self:signal()