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 wlcursor = luci.model.uci.cursor_state()
19 local wireless = wlcursor:get_all("wireless")
20 local wifidata = luci.sys.wifi.getiwconfig()
24 for k, v in pairs(wireless) do
25 if v[".type"] == "wifi-iface" then
26 table.insert(ifaces, v)
30 wlcursor:foreach("wireless", "wifi-device",
32 table.insert(wifidevs, section[".name"])
38 m = Map("wireless", translate("wifi"), translate("a_w_devices1"))
43 s = m:section(Table, ifaces, translate("networks"))
45 link = s:option(DummyValue, "_link", translate("link"))
46 function link.cfgvalue(self, section)
47 local ifname = self.map:get(section, "ifname")
48 return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
51 essid = s:option(DummyValue, "ssid", "ESSID")
53 bssid = s:option(DummyValue, "_bsiid", "BSSID")
54 function bssid.cfgvalue(self, section)
55 local ifname = self.map:get(section, "ifname")
56 return (wifidata[ifname] and (wifidata[ifname].Cell
57 or wifidata[ifname]["Access Point"])) or "-"
60 channel = s:option(DummyValue, "channel", translate("channel"))
61 function channel.cfgvalue(self, section)
62 return wireless[self.map:get(section, "device")].channel
65 protocol = s:option(DummyValue, "_mode", translate("protocol"))
66 function protocol.cfgvalue(self, section)
67 local mode = wireless[self.map:get(section, "device")].mode
68 return mode and "802." .. mode
71 mode = s:option(DummyValue, "mode", translate("mode"))
72 encryption = s:option(DummyValue, "encryption", translate("iwscan_encr"))
74 power = s:option(DummyValue, "_power", translate("power"))
75 function power.cfgvalue(self, section)
76 local ifname = self.map:get(section, "ifname")
77 return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
80 scan = s:option(Button, "_scan", translate("scan"))
81 scan.inputstyle = "find"
83 function scan.cfgvalue(self, section)
84 return self.map:get(section, "ifname") or false
89 t2 = m:section(Table, {}, translate("iwscan"), translate("iwscan1"))
91 function scan.write(self, section)
92 t2.render = t2._render
93 local ifname = self.map:get(section, "ifname")
94 luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname))
97 t2._render = t2.render
98 t2.render = function() end
100 t2:option(DummyValue, "Quality", translate("iwscan_link"))
101 essid = t2:option(DummyValue, "ESSID", "ESSID")
102 function essid.cfgvalue(self, section)
103 return self.map:get(section, "ESSID")
106 t2:option(DummyValue, "Address", "BSSID")
107 t2:option(DummyValue, "Mode", translate("mode"))
108 chan = t2:option(DummyValue, "channel", translate("channel"))
109 function chan.cfgvalue(self, section)
110 return self.map:get(section, "Channel")
111 or self.map:get(section, "Frequency")
115 t2:option(DummyValue, "Encryption key", translate("iwscan_encr"))
117 t2:option(DummyValue, "Signal level", translate("iwscan_signal"))
119 t2:option(DummyValue, "Noise level", translate("iwscan_noise"))
123 if #wifidevs < 1 then
129 s = m:section(NamedSection, wifidevs[1], "wifi-device", translate("devices"))
131 en = s:option(Flag, "disabled", translate("enable"))
135 function en.cfgvalue(self, section)
136 return Flag.cfgvalue(self, section) or "0"
140 local hwtype = m:get(wifidevs[1], "type")
142 if hwtype == "atheros" then
143 mode = s:option(ListValue, "mode", translate("mode"))
144 mode:value("", "auto")
145 mode:value("11b", "802.11b")
146 mode:value("11g", "802.11g")
147 mode:value("11a", "802.11a")
148 mode:value("11bg", "802.11b+g")
153 ch = s:option(Value, "channel", translate("a_w_channel"))
155 ch:value(i, i .. " (2.4 GHz)")
159 s = m:section(TypedSection, "wifi-iface", translate("m_n_local"))
162 s:option(Value, "ssid", translate("a_w_netid"))
164 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
167 luci.model.uci.cursor():foreach("wireless", "wifi-device",
169 table.insert(devs, section[".name"])
173 device = s:option(DummyValue, "device", translate("device"))
175 s.defaults.device = devs[1]
178 mode = s:option(ListValue, "mode", translate("mode"))
179 mode:value("ap", translate("m_w_ap"))
180 mode:value("adhoc", translate("m_w_adhoc"))
181 mode:value("sta", translate("m_w_client"))
183 function mode.write(self, section, value)
184 if value == "sta" then
185 -- ToDo: Move this away
186 if not m.uci:get("network", "wan") then
187 m.uci:set("network", "wan", "proto", "none")
188 m.uci:set("network", "wan", "ifname", " ")
191 local oldif = m.uci:get("network", "wan", "ifname")
192 if oldif and oldif ~= " " then
193 m.uci:set("network", "wan", "_ifname", oldif)
195 m.uci:set("network", "wan", "ifname", " ")
197 self.map:set(section, "network", "wan")
199 if m.uci:get("network", "wan", "_ifname") then
200 m.uci:set("network", "wan", "ifname", m.uci:get("network", "wan", "_ifname"))
202 self.map:set(section, "network", "lan")
205 return ListValue.write(self, section, value)
208 encr = s:option(ListValue, "encryption", translate("encryption"))
209 encr:value("none", "keine")
210 encr:value("wep", "WEP")
211 encr:value("psk", "WPA-PSK")
212 encr:value("wpa", "WPA-Radius", {mode="ap"})
213 encr:value("psk2", "WPA2-PSK")
214 encr:value("wpa2", "WPA2-Radius", {mode="ap"})
216 key = s:option(Value, "key", translate("key"))
217 key:depends("encryption", "wep")
218 key:depends("encryption", "psk")
219 key:depends("encryption", "wpa")
220 key:depends("encryption", "psk2")
221 key:depends("encryption", "wpa2")
224 server = s:option(Value, "server", translate("a_w_radiussrv"))
225 server:depends("encryption", "wpa")
226 server:depends("encryption", "wpa2")
227 server.rmempty = true
229 port = s:option(Value, "port", translate("a_w_radiusport"))
230 port:depends("encryption", "wpa")
231 port:depends("encryption", "wpa2")
235 if hwtype == "atheros" or hwtype == "broadcom" then
236 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
238 iso:depends("mode", "ap")
240 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
242 hide:depends("mode", "ap")
245 if hwtype == "mac80211" or hwtype == "atheros" then
246 bssid:depends({mode="adhoc"})
249 if hwtype == "broadcom" then
250 bssid:depends({mode="wds"})