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 ch = s:option(Value, "channel", translate("a_w_channel"))
141 ch:value(i, i .. " (2.4 GHz)")
145 s = m:section(TypedSection, "wifi-iface", translate("m_n_local"))
148 s:option(Value, "ssid", translate("a_w_netid")).maxlength = 32
151 luci.model.uci.foreach("wireless", "wifi-device",
153 table.insert(devs, section[".name"])
157 device = s:option(DummyValue, "device", translate("device"))
159 s.defaults.device = devs[1]
162 mode = s:option(ListValue, "mode", translate("mode"))
163 mode:value("ap", translate("m_w_ap"))
164 mode:value("adhoc", translate("m_w_adhoc"))
165 mode:value("sta", translate("m_w_client"))
167 function mode.write(self, section, value)
168 if value == "sta" then
169 -- ToDo: Move this away
170 if not luci.model.uci.get("network", "wan") then
171 luci.model.uci.set("network", "wan", "proto", "none")
172 luci.model.uci.set("network", "wan", "ifname", " ")
175 local oldif = luci.model.uci.get("network", "wan", "ifname")
176 if oldif and oldif ~= " " then
177 luci.model.uci.set("network", "wan", "_ifname", oldif)
179 luci.model.uci.set("network", "wan", "ifname", " ")
181 self.map:set(section, "network", "wan")
183 if luci.model.uci.get("network", "wan", "_ifname") then
184 luci.model.uci.set("network", "wan", "ifname", luci.model.uci.get("network", "wan", "_ifname"))
186 self.map:set(section, "network", "lan")
189 return ListValue.write(self, section, value)
192 encr = s:option(ListValue, "encryption", translate("encryption"))
193 encr:value("none", "keine")
194 encr:value("wep", "WEP")
195 encr:value("psk", "WPA-PSK")
196 encr:value("wpa", "WPA-Radius")
197 encr:value("psk2", "WPA2-PSK")
198 encr:value("wpa2", "WPA2-Radius")
200 key = s:option(Value, "key", translate("key"))
201 key:depends("encryption", "wep")
202 key:depends("encryption", "psk")
203 key:depends("encryption", "wpa")
204 key:depends("encryption", "psk2")
205 key:depends("encryption", "wpa2")
208 server = s:option(Value, "server", translate("a_w_radiussrv"))
209 server:depends("encryption", "wpa")
210 server:depends("encryption", "wpa2")
211 server.rmempty = true
213 port = s:option(Value, "port", translate("a_w_radiusport"))
214 port:depends("encryption", "wpa")
215 port:depends("encryption", "wpa2")
218 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
220 iso:depends("mode", "ap")
222 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
224 hide:depends("mode", "ap")