2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
14 require("luci.tools.webadmin")
17 m = Map("wireless", translate("networks"), translate("a_w_networks1"))
19 s = m:section(NamedSection, arg[1], "wifi-device", translate("device") .. " " .. arg[1])
22 en = s:option(Flag, "disabled", translate("enable"))
26 function en.cfgvalue(self, section)
27 return Flag.cfgvalue(self, section) or "0"
30 s:option(DummyValue, "type", translate("type"))
31 local hwtype = m:get(arg[1], "type")
33 ch = s:option(Value, "channel", translate("a_w_channel"))
35 ch:value(i, i .. " (2.4 GHz)")
38 ch:value(i, i .. " (5 GHz)")
41 ch:value(i, i .. " (5 GHz)")
43 ch:value(147, 147 .. " (5 GHz)")
44 ch:value(151, 151 .. " (5 GHz)")
45 ch:value(155, 155 .. " (5 GHz)")
46 ch:value(167, 167 .. " (5 GHz)")
48 ------------------- MAC80211 Device ------------------
50 if hwtype == "mac80211" then
55 ------------------- Madwifi Device ------------------
57 if hwtype == "atheros" then
58 mode = s:option(ListValue, "mode", translate("mode"))
59 mode:value("", translate("wifi_auto"))
60 mode:value("11b", "802.11b")
61 mode:value("11g", "802.11g")
62 mode:value("11a", "802.11a")
63 mode:value("11bg", "802.11b+g")
64 mode:value("11gdt", "802.11adt")
65 mode:value("11adt", "802.11adt")
66 mode:value("fh", translate("wifi_fh"))
68 s:option(Flag, "diversity", translate("wifi_diversity"))
69 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
70 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
71 s:option(Value, "distance", translate("wifi_distance"),
72 translate("wifi_distance_desc")).optional = true
74 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
79 ------------------- Broadcom Device ------------------
81 if hwtype == "broadcom" then
82 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
85 mp:value("deny", translate("wifi_whitelist"))
86 mp:value("allow", translate("wifi_blacklist"))
87 ml = s:option(Value, "maclist", translate("wifi_maclist"))
88 ml:depends({macpolicy="allow"})
89 ml:depends({macpolicy="deny"})
91 s:option(Value, "txant", translate("wifi_txantenna")).optional = true
92 s:option(Value, "rxant", translate("wifi_rxantenna")).optional = true
94 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
96 s:option(Value, "distance", translate("wifi_distance")).optional = true
97 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
99 s:option(Value, "country", translate("wifi_country")).optional = true
100 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
104 ----------------------- Interface -----------------------
106 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
109 s:depends("device", arg[1])
110 s.defaults.device = arg[1]
112 s:option(Value, "ssid", translate("wifi_essid"))
114 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
115 network.rmempty = true
117 network.combobox_manual = translate("a_w_netmanual")
118 luci.tools.webadmin.cbi_add_networks(network)
120 function network.write(self, section, value)
121 if not m.uci:get("network", value) then
122 -- avoid "value not defined in enum" because network is not known yet
123 s.override_scheme = true
126 m.uci:set("network", value, "interface")
127 Value.write(self, section, value)
129 if m.uci:get("network", value) == "interface" then
130 Value.write(self, section, value)
136 mode = s:option(ListValue, "mode", translate("mode"))
137 mode.override_values = true
138 mode:value("ap", translate("a_w_ap"))
139 mode:value("adhoc", translate("a_w_adhoc"))
140 mode:value("sta", translate("a_w_client"))
142 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
145 -------------------- MAC80211 Interface ----------------------
147 if hwtype == "mac80211" then
148 mode:value("monitor", translate("a_w_monitor"))
149 bssid:depends({mode="adhoc"})
151 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
152 s:option(Value, "frag", translate("wifi_frag")).optional = true
153 s:option(Value, "rts", translate("wifi_rts")).optional = true
158 -------------------- Madwifi Interface ----------------------
160 if hwtype == "atheros" then
161 mode:value("ahdemo", translate("a_w_ahdemo"))
162 mode:value("monitor", translate("a_w_monitor"))
164 bssid:depends({mode="adhoc"})
165 bssid:depends({mode="ahdemo"})
167 wds = s:option(Flag, "wds", translate("a_w_wds"))
168 wds:depends({mode="ap"})
169 wds:depends({mode="sta"})
171 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
172 wdssep:depends({mode="ap", wds="1"})
173 wdssep.optional = true
175 s:option(Flag, "doth", "802.11h").optional = true
176 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
177 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
178 hidden:depends({mode="ap"})
179 hidden:depends({mode="adhoc"})
180 hidden:depends({mode="wds"})
181 hidden.optional = true
182 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
183 translate("wifi_isolate_desc"))
184 isolate:depends({mode="ap"})
185 isolate.optional = true
186 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
188 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
191 mp:value("deny", translate("wifi_whitelist"))
192 mp:value("allow", translate("wifi_blacklist"))
193 ml = s:option(Value, "maclist", translate("wifi_maclist"))
194 ml:depends({macpolicy="allow"})
195 ml:depends({macpolicy="deny"})
197 s:option(Value, "rate", translate("wifi_rate")).optional = true
198 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
199 s:option(Value, "frag", translate("wifi_frag")).optional = true
200 s:option(Value, "rts", translate("wifi_rts")).optional = true
201 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
202 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
203 s:option(Flag, "compression", translate("wifi_compression")).optional = true
205 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
206 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
207 s:option(Value, "ff", translate("wifi_ff")).optional = true
209 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
210 s:option(Flag, "xr", translate("wifi_xr")).optional = true
211 s:option(Flag, "ar", translate("wifi_ar")).optional = true
215 -------------------- Broadcom Interface ----------------------
217 if hwtype == "broadcom" then
218 mode:value("wds", translate("a_w_wds"))
219 mode:value("monitor", translate("a_w_monitor"))
221 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
222 hidden:depends({mode="ap"})
223 hidden:depends({mode="adhoc"})
224 hidden:depends({mode="wds"})
225 hidden.optional = true
227 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
228 translate("wifi_isolate_desc"))
229 isolate:depends({mode="ap"})
230 isolate.optional = true
232 bssid:depends({mode="wds"})
237 ------------------- WiFI-Encryption -------------------
239 encr = s:option(ListValue, "encryption", translate("encryption"))
240 encr.override_values = true
241 encr:depends({mode="ap"})
242 encr:depends({mode="sta"})
243 encr:depends({mode="adhoc"})
244 encr:depends({mode="ahdemo"})
245 encr:depends({mode="wds"})
247 encr:value("none", "No Encryption")
248 encr:value("wep", "WEP")
250 if hwtype == "atheros" or hwtype == "mac80211" then
251 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
252 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
254 if hostapd and supplicant then
255 encr:value("psk", "WPA-PSK")
256 encr:value("psk2", "WPA2-PSK")
257 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
258 encr:value("wpa2i", "WPA2-EAP", {mode="ap"}, {mode="sta"})
259 elseif hostapd and not supplicant then
260 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
261 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
262 encr:value("wpa", "WPA-EAP", {mode="ap"})
263 encr:value("wpa2i", "WPA2-EAP", {mode="ap"})
264 encr.description = translate("wifi_wpareq")
265 elseif not hostapd and supplicant then
266 encr:value("psk", "WPA-PSK", {mode="sta"})
267 encr:value("psk2", "WPA2-PSK", {mode="sta"})
268 encr:value("wpa", "WPA-EAP", {mode="sta"})
269 encr:value("wpa2i", "WPA2-EAP", {mode="sta"})
270 encr.description = translate("wifi_wpareq")
272 encr.description = translate("wifi_wpareq")
274 elseif hwtype == "broadcom" then
275 encr:value("psk", "WPA-PSK")
276 encr:value("psk2", "WPA2-PSK")
279 encr:depends("mode", "ap")
280 encr:depends("mode", "sta")
281 encr:depends("mode", "wds")
283 server = s:option(Value, "server", translate("a_w_radiussrv"))
284 server:depends({mode="ap", encryption="wpa"})
285 server:depends({mode="ap", encryption="wpa2i"})
286 server.rmempty = true
288 port = s:option(Value, "port", translate("a_w_radiusport"))
289 port:depends({mode="ap", encryption="wpa"})
290 port:depends({mode="ap", encryption="wpa2i"})
293 key = s:option(Value, "key", translate("key"))
294 key:depends("encryption", "wep")
295 key:depends("encryption", "psk")
296 key:depends({mode="ap", encryption="wpa"})
297 key:depends("encryption", "psk2")
298 key:depends({mode="ap", encryption="wpa2i"})
301 if hwtype == "atheros" or hwtype == "mac80211" then
302 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
303 nasid:depends({mode="ap", encryption="wpa"})
304 nasid:depends({mode="ap", encryption="wpa2i"})
307 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
309 eaptype:value("PEAP")
310 eaptype:depends({mode="sta", encryption="wpa"})
311 eaptype:depends({mode="sta", encryption="wpa2i"})
313 cacert = s:option(Value, "ca_cert", translate("a_w_cacert"))
314 cacert:depends({mode="sta", encryption="wpa"})
315 cacert:depends({mode="sta", encryption="wpa2i"})
317 privkey = s:option(Value, "priv_key", translate("a_w_tlsprivkey"))
318 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
319 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
321 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
322 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
323 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
326 auth = s:option(Value, "auth", translate("a_w_peapauth"))
327 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
328 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
330 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
331 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
332 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
334 password = s:option(Value, "password", translate("a_w_peappassword"))
335 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
336 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})