2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
18 local uci = luci.model.uci.cursor()
19 if not uci:get("network", "wan") then
20 uci:section("network", "interface", "wan", {proto="none", ifname=" "})
25 local wlcursor = luci.model.uci.cursor_state()
26 local wireless = wlcursor:get_all("wireless")
27 local wifidata = luci.sys.wifi.getiwconfig()
31 for k, v in pairs(wireless) do
32 if v[".type"] == "wifi-iface" then
33 table.insert(ifaces, v)
37 wlcursor:foreach("wireless", "wifi-device",
39 table.insert(wifidevs, section[".name"])
45 m = Map("wireless", translate("wifi"), translate("a_w_devices1"))
50 s = m:section(Table, ifaces, translate("networks"))
52 link = s:option(DummyValue, "_link", translate("link"))
53 function link.cfgvalue(self, section)
54 local ifname = self.map:get(section, "ifname")
55 return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
58 essid = s:option(DummyValue, "ssid", "ESSID")
60 bssid = s:option(DummyValue, "_bsiid", "BSSID")
61 function bssid.cfgvalue(self, section)
62 local ifname = self.map:get(section, "ifname")
63 return (wifidata[ifname] and (wifidata[ifname].Cell
64 or wifidata[ifname]["Access Point"])) or "-"
67 channel = s:option(DummyValue, "channel", translate("channel"))
68 function channel.cfgvalue(self, section)
69 return wireless[self.map:get(section, "device")].channel
72 protocol = s:option(DummyValue, "_mode", translate("protocol"))
73 function protocol.cfgvalue(self, section)
74 local mode = wireless[self.map:get(section, "device")].mode
75 return mode and "802." .. mode
78 mode = s:option(DummyValue, "mode", translate("mode"))
79 encryption = s:option(DummyValue, "encryption", translate("iwscan_encr"))
81 power = s:option(DummyValue, "_power", translate("power"))
82 function power.cfgvalue(self, section)
83 local ifname = self.map:get(section, "ifname")
84 return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
87 scan = s:option(Button, "_scan", translate("scan"))
88 scan.inputstyle = "find"
90 function scan.cfgvalue(self, section)
91 return self.map:get(section, "ifname") or false
96 t2 = m:section(Table, {}, translate("iwscan"), translate("iwscan1"))
98 function scan.write(self, section)
100 t2.render = t2._render
101 local ifname = self.map:get(section, "ifname")
102 luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname))
105 t2._render = t2.render
106 t2.render = function() end
108 t2:option(DummyValue, "Quality", translate("iwscan_link"))
109 essid = t2:option(DummyValue, "ESSID", "ESSID")
110 function essid.cfgvalue(self, section)
111 return self.map:get(section, "ESSID")
114 t2:option(DummyValue, "Address", "BSSID")
115 t2:option(DummyValue, "Mode", translate("mode"))
116 chan = t2:option(DummyValue, "channel", translate("channel"))
117 function chan.cfgvalue(self, section)
118 return self.map:get(section, "Channel")
119 or self.map:get(section, "Frequency")
123 t2:option(DummyValue, "Encryption key", translate("iwscan_encr"))
125 t2:option(DummyValue, "Signal level", translate("iwscan_signal"))
127 t2:option(DummyValue, "Noise level", translate("iwscan_noise"))
131 if #wifidevs < 1 then
137 s = m:section(NamedSection, wifidevs[1], "wifi-device", translate("devices"))
140 en = s:option(Flag, "disabled", translate("enable"))
145 function en.cfgvalue(self, section)
146 return Flag.cfgvalue(self, section) or "0"
150 local hwtype = m:get(wifidevs[1], "type")
152 if hwtype == "atheros" then
153 mode = s:option(ListValue, "hwmode", translate("mode"))
154 mode.override_values = true
155 mode:value("", "auto")
156 mode:value("11b", "802.11b")
157 mode:value("11g", "802.11g")
158 mode:value("11a", "802.11a")
159 mode:value("11bg", "802.11b+g")
164 ch = s:option(Value, "channel", translate("a_w_channel"))
166 ch:value(i, i .. " (2.4 GHz)")
170 s = m:section(TypedSection, "wifi-iface", translate("m_n_local"))
174 s:option(Value, "ssid", translate("a_w_netid"))
176 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
179 luci.model.uci.cursor():foreach("wireless", "wifi-device",
181 table.insert(devs, section[".name"])
185 device = s:option(DummyValue, "device", translate("device"))
187 s.defaults.device = devs[1]
190 mode = s:option(ListValue, "mode", translate("mode"))
191 mode.override_values = true
192 mode:value("ap", translate("m_w_ap"))
193 mode:value("adhoc", translate("m_w_adhoc"))
194 mode:value("sta", translate("m_w_client"))
196 function mode.write(self, section, value)
197 if value == "sta" then
198 local oldif = m.uci:get("network", "wan", "ifname")
199 if oldif and oldif ~= " " then
200 m.uci:set("network", "wan", "_ifname", oldif)
202 m.uci:set("network", "wan", "ifname", " ")
204 self.map:set(section, "network", "wan")
206 if m.uci:get("network", "wan", "_ifname") then
207 m.uci:set("network", "wan", "ifname", m.uci:get("network", "wan", "_ifname"))
209 self.map:set(section, "network", "lan")
212 return ListValue.write(self, section, value)
215 encr = s:option(ListValue, "encryption", translate("encryption"))
216 encr.override_values = true
217 encr:value("none", "No Encryption")
218 encr:value("wep", "WEP")
220 if hwtype == "atheros" or hwtype == "mac80211" then
221 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
222 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
224 if hostapd and supplicant then
225 encr:value("psk", "WPA-PSK")
226 encr:value("psk2", "WPA2-PSK")
227 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
228 encr:value("wpa", "WPA-Radius", {mode="ap"})
229 encr:value("wpa2i", "WPA2-Radius", {mode="ap"})
230 elseif hostapd and not supplicant then
231 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"})
232 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"})
233 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"})
234 encr:value("wpa", "WPA-Radius", {mode="ap"})
235 encr:value("wpa2i", "WPA2-Radius", {mode="ap"})
236 encr.description = translate("wifi_wpareq")
237 elseif not hostapd and supplicant then
238 encr:value("psk", "WPA-PSK", {mode="sta"})
239 encr:value("psk2", "WPA2-PSK", {mode="sta"})
240 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
241 encr.description = translate("wifi_wpareq")
243 encr.description = translate("wifi_wpareq")
245 elseif hwtype == "broadcom" then
246 encr:value("psk", "WPA-PSK")
247 encr:value("psk2", "WPA2-PSK")
248 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
251 key = s:option(Value, "key", translate("key"))
252 key:depends("encryption", "wep")
253 key:depends("encryption", "psk")
254 key:depends("encryption", "wpa")
255 key:depends("encryption", "psk2")
256 key:depends("encryption", "wpa2i")
259 server = s:option(Value, "server", translate("a_w_radiussrv"))
260 server:depends("encryption", "wpa")
261 server:depends("encryption", "wpa2i")
262 server.rmempty = true
264 port = s:option(Value, "port", translate("a_w_radiusport"))
265 port:depends("encryption", "wpa")
266 port:depends("encryption", "wpa2i")
270 if hwtype == "atheros" or hwtype == "broadcom" then
271 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
273 iso:depends("mode", "ap")
275 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
277 hide:depends("mode", "ap")
280 if hwtype == "mac80211" or hwtype == "atheros" then
281 bssid:depends({mode="adhoc"})
284 if hwtype == "broadcom" then
285 bssid:depends({mode="wds"})