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 luci.model.uci.load_state("wireless")
19 local wireless = luci.model.uci.get_all("wireless")
20 luci.model.uci.unload("wireless")
22 local wifidata = luci.sys.wifi.getiwconfig()
25 for k, v in pairs(wireless) do
26 if v[".type"] == "wifi-iface" then
27 table.insert(ifaces, v)
34 m = Map("wireless", translate("wifi"), translate("a_w_devices1"))
39 s = m:section(Table, ifaces, translate("networks"))
41 link = s:option(DummyValue, "_link", translate("link"))
42 function link.cfgvalue(self, section)
43 local ifname = self.map:get(section, "ifname")
44 return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
47 essid = s:option(DummyValue, "ssid", "ESSID")
49 bssid = s:option(DummyValue, "_bsiid", "BSSID")
50 function bssid.cfgvalue(self, section)
51 local ifname = self.map:get(section, "ifname")
52 return (wifidata[ifname] and (wifidata[ifname].Cell
53 or wifidata[ifname]["Access Point"])) or "-"
56 channel = s:option(DummyValue, "channel", translate("channel"))
57 function channel.cfgvalue(self, section)
58 return wireless[self.map:get(section, "device")].channel
61 protocol = s:option(DummyValue, "_mode", translate("protocol"))
62 function protocol.cfgvalue(self, section)
63 local mode = wireless[self.map:get(section, "device")].mode
64 return mode and "802." .. mode
67 mode = s:option(DummyValue, "mode", translate("mode"))
68 encryption = s:option(DummyValue, "encryption", translate("iwscan_encr"))
70 power = s:option(DummyValue, "_power", translate("power"))
71 function power.cfgvalue(self, section)
72 local ifname = self.map:get(section, "ifname")
73 return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
76 scan = s:option(Button, "_scan", translate("scan"))
77 scan.inputstyle = "find"
79 function scan.cfgvalue(self, section)
80 return self.map:get(section, "ifname") or false
85 t2 = m:section(Table, {}, translate("iwscan"), translate("iwscan1"))
87 function scan.write(self, section)
88 t2.render = t2._render
89 local ifname = self.map:get(section, "ifname")
90 luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname))
93 t2._render = t2.render
94 t2.render = function() end
96 t2:option(DummyValue, "Quality", translate("iwscan_link"))
97 essid = t2:option(DummyValue, "ESSID", "ESSID")
98 function essid.cfgvalue(self, section)
99 return luci.util.pcdata(self.map:get(section, "ESSID"))
102 t2:option(DummyValue, "Address", "BSSID")
103 t2:option(DummyValue, "Mode", translate("mode"))
104 chan = t2:option(DummyValue, "channel", translate("channel"))
105 function chan.cfgvalue(self, section)
106 return self.map:get(section, "Channel")
107 or self.map:get(section, "Frequency")
111 t2:option(DummyValue, "Encryption key", translate("iwscan_encr"))
113 t2:option(DummyValue, "Signal level", translate("iwscan_signal"))
115 t2:option(DummyValue, "Noise level", translate("iwscan_noise"))
120 s = m:section(TypedSection, "wifi-device", translate("devices"))
122 en = s:option(Flag, "disabled", translate("enable"))
126 function en.cfgvalue(self, section)
127 return Flag.cfgvalue(self, section) or "0"
131 mode = s:option(ListValue, "mode", translate("mode"))
132 mode:value("", "standard")
133 mode:value("11b", "802.11b")
134 mode:value("11g", "802.11g")
135 mode:value("11a", "802.11a")
136 mode:value("11bg", "802.11b+g")
139 s:option(Value, "channel", translate("a_w_channel"))
143 s = m:section(TypedSection, "wifi-iface", translate("m_n_local"))
146 s:option(Value, "ssid", translate("a_w_netid")).maxlength = 32
149 luci.model.uci.foreach("wireless", "wifi-device",
151 table.insert(devs, section[".name"])
155 device = s:option(DummyValue, "device", translate("device"))
157 s.defaults.device = devs[1]
160 mode = s:option(ListValue, "mode", translate("mode"))
161 mode:value("ap", translate("m_w_ap"))
162 mode:value("adhoc", translate("m_w_adhoc"))
163 mode:value("sta", translate("m_w_client"))
165 function mode.write(self, section, value)
166 if value == "sta" then
167 -- ToDo: Move this away
168 if not luci.model.uci.get("network", "wan") then
169 luci.model.uci.set("network", "wan", "proto", "none")
170 luci.model.uci.set("network", "wan", "ifname", " ")
173 local oldif = luci.model.uci.get("network", "wan", "ifname")
174 if oldif and oldif ~= " " then
175 luci.model.uci.set("network", "wan", "_ifname", oldif)
177 luci.model.uci.set("network", "wan", "ifname", " ")
179 self.map:set(section, "network", "wan")
181 if luci.model.uci.get("network", "wan", "_ifname") then
182 luci.model.uci.set("network", "wan", "ifname", luci.model.uci.get("network", "wan", "_ifname"))
184 self.map:set(section, "network", "lan")
187 return ListValue.write(self, section, value)
190 encr = s:option(ListValue, "encryption", translate("encryption"))
191 encr:value("none", "keine")
192 encr:value("wep", "WEP")
193 encr:value("psk", "WPA-PSK")
194 encr:value("wpa", "WPA-Radius")
195 encr:value("psk2", "WPA2-PSK")
196 encr:value("wpa2", "WPA2-Radius")
198 key = s:option(Value, "key", translate("key"))
199 key:depends("encryption", "wep")
200 key:depends("encryption", "psk")
201 key:depends("encryption", "wpa")
202 key:depends("encryption", "psk2")
203 key:depends("encryption", "wpa2")
206 server = s:option(Value, "server", translate("a_w_radiussrv"))
207 server:depends("encryption", "wpa")
208 server:depends("encryption", "wpa2")
209 server.rmempty = true
211 port = s:option(Value, "port", translate("a_w_radiusport"))
212 port:depends("encryption", "wpa")
213 port:depends("encryption", "wpa2")
216 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
218 iso:depends("mode", "ap")
220 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
222 hide:depends("mode", "ap")