return _ubuswificache
end
+local function _wifi_state_by_sid(sid)
+ local t1, n1 = _uci:get("wireless", sid)
+ if t1 == "wifi-iface" and n1 ~= nil then
+ local radioname, radiostate
+ for radioname, radiostate in pairs(_wifi_state()) do
+ if type(radiostate) == "table" and
+ type(radiostate.interfaces) == "table"
+ then
+ local netidx, netstate
+ for netidx, netstate in ipairs(radiostate.interfaces) do
+ if type(netstate) == "table" and
+ type(netstate.section) == "string"
+ then
+ local t2, n2 = _uci:get("wireless", netstate.section)
+ if t1 == t2 and n1 == n2 then
+ return radioname, radiostate, netstate
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+local function _wifi_state_by_ifname(ifname)
+ if type(ifname) == "string" then
+ local radioname, radiostate
+ for radioname, radiostate in pairs(_wifi_state()) do
+ if type(radiostate) == "table" and
+ type(radiostate.interfaces) == "table"
+ then
+ local netidx, netstate
+ for netidx, netstate in ipairs(radiostate.interfaces) do
+ if type(netstate) == "table" and
+ type(netstate.ifname) == "string" and
+ netstate.ifname == ifname
+ then
+ return radioname, radiostate, netstate
+ end
+ end
+ end
+ end
+ end
+end
+
function _wifi_iface(x)
local _, p
for _, p in ipairs(IFACE_PATTERNS_WIRELESS) do
return netid
end
-local function _wifi_state_by_sid(sid)
- local t1, n1 = _uci:get("wireless", sid)
- if t1 == "wifi-iface" and n1 ~= nil then
- local radioname, radiostate
- for radioname, radiostate in pairs(_wifi_state()) do
- if type(radiostate) == "table" and
- type(radiostate.interfaces) == "table"
- then
- local netidx, netstate
- for netidx, netstate in ipairs(radiostate.interfaces) do
- if type(netstate) == "table" and
- type(netstate.section) == "string"
- then
- local t2, n2 = _uci:get("wireless", netstate.section)
- if t1 == t2 and n1 == n2 then
- return radioname, radiostate, netstate
- end
- end
- end
- end
- end
- end
-end
-
-local function _wifi_state_by_ifname(ifname)
- if type(ifname) == "string" then
- local radioname, radiostate
- for radioname, radiostate in pairs(_wifi_state()) do
- if type(radiostate) == "table" and
- type(radiostate.interfaces) == "table"
- then
- local netidx, netstate
- for netidx, netstate in ipairs(radiostate.interfaces) do
- if type(netstate) == "table" and
- type(netstate.ifname) == "string" and
- netstate.ifname == ifname
- then
- return radioname, radiostate, netstate
- end
- end
- end
- end
- end
-end
-
function _iface_virtual(x)
local _, p
for _, p in ipairs(IFACE_PATTERNS_VIRTUAL) do
if i.family == "packet" then
_interfaces[name].flags = i.flags
_interfaces[name].stats = i.data
- _interfaces[name].macaddr = i.addr
+ _interfaces[name].macaddr = ipc.checkmac(i.addr)
elseif i.family == "inet" then
_interfaces[name].ipaddrs[#_interfaces[name].ipaddrs+1] = ipc.IPv4(i.addr, i.netmask)
elseif i.family == "inet6" then
function del_network(self, n)
local r = _uci:delete("network", n)
if r then
+ _uci:delete_all("luci", "ifstate",
+ function(s) return (s.interface == n) end)
+
_uci:delete_all("network", "alias",
function(s) return (s.interface == n) end)
if _interfaces[i] or _wifi_iface(i) then
return interface(i)
else
- local netid = _wifi_netid_by_netname(i)
+ local netid = _wifi_netid_by_sid(i)
return netid and interface(netid)
end
end
if type(addrs) == "table" then
for n, addr in ipairs(addrs) do
- rv[#rv+1] = "%s1/%d" %{ addr.address, addr.mask }
+ if type(addr["local-address"]) == "table" and
+ type(addr["local-address"].mask) == "number" and
+ type(addr["local-address"].address) == "string"
+ then
+ rv[#rv+1] = "%s/%d" %{
+ addr["local-address"].address,
+ addr["local-address"].mask
+ }
+ end
end
end
end
function interface.mac(self)
- local mac = self:_ubus("macaddr")
- return mac and mac:upper()
+ return ipc.checkmac(self:_ubus("macaddr"))
end
function interface.ipaddrs(self)
end
function wifidev.get_i18n(self)
- local t = "Generic"
+ local t = self.iwinfo.hardware_name or "Generic"
if self.iwinfo.type == "wl" then
t = "Broadcom"
end