libs/core: fix undefined tostring() in network model
[project/luci.git] / libs / core / luasrc / model / network.lua
index dd2bdfb..d682aa9 100644 (file)
@@ -17,8 +17,11 @@ limitations under the License.
 
 ]]--
 
-local type, next, pairs, ipairs, loadfile, table, tonumber, math, i18n
-       = type, next, pairs, ipairs, loadfile, table, tonumber, math, luci.i18n
+local type, next, pairs, ipairs, loadfile, table
+       = type, next, pairs, ipairs, loadfile, table
+
+local tonumber, tostring, math, i18n
+       = tonumber, tostring, math, luci.i18n
 
 local require = require
 
@@ -847,7 +850,7 @@ function protocol.get_interface(self)
                                if s.device then
                                        num[s.device] = num[s.device] and num[s.device] + 1 or 1
                                        if s.network == self.sid then
-                                               ifn = s.ifname or "%s.network%d" %{ s.device, num[s.device] }
+                                               ifn = "%s.network%d" %{ s.device, num[s.device] }
                                                return false
                                        end
                                end
@@ -927,7 +930,10 @@ interface = utl.class()
 
 function interface.__init__(self, ifname, network)
        local wif = _wifi_lookup(ifname)
-       if wif then self.wif = wifinet(wif) end
+       if wif then 
+               self.wif    = wifinet(wif) 
+               self.ifname = _uci_state:get("wireless", wif, "ifname")
+       end
 
        self.ifname  = self.ifname or ifname
        self.dev     = _interfaces[self.ifname]
@@ -1357,7 +1363,12 @@ function wifinet.country(self)
 end
 
 function wifinet.txpower(self)
-       return self.iwinfo.txpower or 0
+       local pwr = (self.iwinfo.txpower or 0)
+       return pwr + self:txpower_offset()
+end
+
+function wifinet.txpower_offset(self)
+       return self.iwinfo.txpower_offset or 0
 end
 
 function wifinet.signal_level(self, s, n)
@@ -1408,8 +1419,9 @@ function wifinet.adminlink(self)
 end
 
 function wifinet.get_network(self)
-       if _uci_real:get("network", self.iwdata.network) == "interface" then
-               return network(self.iwdata.network)
+       local net = tostring(self.iwdata.network)
+       if net and _uci_real:get("network", net) == "interface" then
+               return network(net)
        end
 end