modules/admin-mini: use getiwinfo() instead of getiwconfig()
[project/luci.git] / modules / admin-mini / luasrc / model / cbi / mini / wifi.lua
index a062dff..a18c072 100644 (file)
@@ -27,7 +27,6 @@ end
 
 local wlcursor = luci.model.uci.cursor_state()
 local wireless = wlcursor:get_all("wireless")
-local wifidata = sys.wifi.getiwconfig()
 local wifidevs = {}
 local ifaces = {}
 
@@ -55,7 +54,8 @@ s = m:section(Table, ifaces, translate("Networks"))
 link = s:option(DummyValue, "_link", translate("Link"))
 function link.cfgvalue(self, section)
        local ifname = self.map:get(section, "ifname")
-       return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
+       local iwinfo = sys.wifi.getiwinfo(ifname)
+       return iwinfo and "%d/%d" %{ iwinfo.quality, iwinfo.quality_max } or "-"
 end
 
 essid = s:option(DummyValue, "ssid", "ESSID")
@@ -63,8 +63,8 @@ essid = s:option(DummyValue, "ssid", "ESSID")
 bssid = s:option(DummyValue, "_bsiid", "BSSID")
 function bssid.cfgvalue(self, section)
        local ifname = self.map:get(section, "ifname")
-       return (wifidata[ifname] and (wifidata[ifname].Cell
-        or wifidata[ifname]["Access Point"])) or "-"
+       local iwinfo = sys.wifi.getiwinfo(ifname)
+       return iwinfo and iwinfo.bssid or "-"
 end
 
 channel = s:option(DummyValue, "channel", translate("Channel"))
@@ -84,7 +84,8 @@ encryption = s:option(DummyValue, "encryption", translate("<abbr title=\"Encrypt
 power = s:option(DummyValue, "_power", translate("Power"))
 function power.cfgvalue(self, section)
        local ifname = self.map:get(section, "ifname")
-       return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
+       local iwinfo = sys.wifi.getiwinfo(ifname)
+       return iwinfo and "%d dBm" % iwinfo.txpower or "-"
 end
 
 scan = s:option(Button, "_scan", translate("Scan"))
@@ -102,7 +103,21 @@ function scan.write(self, section)
        m.autoapply = false
        t2.render = t2._render
        local ifname = self.map:get(section, "ifname")
-       luci.util.update(t2.data, sys.wifi.iwscan(ifname))
+       local iwinfo = sys.wifi.getiwinfo(ifname)
+       if iwinfo then
+               local _, cell
+               for _, cell in ipairs(iwinfo.scanlist) do
+                       t2.data[#t2.data+1] = {
+                               Quality = "%d/%d" %{ cell.quality, cell.quality_max },
+                               ESSID   = cell.ssid,
+                               Address = cell.bssid,
+                               Mode    = cell.mode,
+                               ["Encryption key"] = cell.encryption.enabled and "On" or "Off",
+                               ["Signal level"]   = "%d dBm" % cell.signal,
+                               ["Noise level"]    = "%d dBm" % iwinfo.noise
+                       }
+               end
+       end
 end
 
 t2._render = t2.render
@@ -236,16 +251,25 @@ if hwtype == "atheros" or hwtype == "mac80211" then
                encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"})
                encr:value("wpa", "WPA-Radius", {mode="ap"})
                encr:value("wpa2", "WPA2-Radius", {mode="ap"})
-               encr.description = translate("wifi_wpareq")
+               encr.description = translate(
+                       "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
+                       "and ad-hoc mode) to be installed."
+               )
        elseif not hostapd and supplicant then
                encr:value("psk", "WPA-PSK", {mode="sta"})
                encr:value("psk2", "WPA2-PSK", {mode="sta"})
                encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
                encr:value("wpa", "WPA-EAP", {mode="sta"})
                encr:value("wpa2", "WPA2-EAP", {mode="sta"})
-               encr.description = translate("wifi_wpareq")
+               encr.description = translate(
+                       "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
+                       "and ad-hoc mode) to be installed."
+               )               
        else
-               encr.description = translate("wifi_wpareq")
+               encr.description = translate(
+                       "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
+                       "and ad-hoc mode) to be installed."
+               )
        end
 elseif hwtype == "broadcom" then
        encr:value("psk", "WPA-PSK")
@@ -264,7 +288,7 @@ key:depends({mode="ap", encryption="wpa2"})
 key.rmempty = true
 key.password = true
 
-server = s:option(Value, "server", translate("RadiusServer"))
+server = s:option(Value, "server", translate("Radius-Server"))
 server:depends({mode="ap", encryption="wpa"})
 server:depends({mode="ap", encryption="wpa2"})
 server.rmempty = true