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 back = s:option(DummyValue, "_overview", translate("overview"))
24 back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
27 en = s:option(Flag, "disabled", translate("enable"))
32 function en.cfgvalue(self, section)
33 return Flag.cfgvalue(self, section) or "0"
36 s:option(DummyValue, "type", translate("type"))
37 local hwtype = m:get(arg[1], "type")
39 local nsantenna = m:get(arg[1], "antenna")
41 ch = s:option(Value, "channel", translate("a_w_channel"))
42 ch:value("auto", translate("wifi_auto"))
43 for c, f in luci.util.kspairs(luci.sys.wifi.channels()) do
44 ch:value(c, "%i (%.3f GHz)" %{ c, f })
48 ------------------- MAC80211 Device ------------------
50 if hwtype == "mac80211" then
51 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
55 ------------------- Madwifi Device ------------------
57 if hwtype == "atheros" then
58 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
60 mode = s:option(ListValue, "hwmode", translate("mode"))
61 mode:value("", translate("wifi_auto"))
62 mode:value("11b", "802.11b")
63 mode:value("11g", "802.11g")
64 mode:value("11a", "802.11a")
65 mode:value("11bg", "802.11b+g")
66 mode:value("11gst", "802.11g + Turbo")
67 mode:value("11ast", "802.11a + Turbo")
68 mode:value("fh", translate("wifi_fh"))
70 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
73 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
74 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
76 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
79 ant:value("horizontal")
82 s:option(Value, "distance", translate("wifi_distance"),
83 translate("wifi_distance_desc")).optional = true
84 s:option(Value, "regdomain", translate("wifi_regdomain")).optional = true
85 s:option(Value, "country", translate("wifi_country")).optional = true
86 s:option(Flag, "outdoor", translate("wifi_outdoor")).optional = true
88 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
93 ------------------- Broadcom Device ------------------
95 if hwtype == "broadcom" then
96 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
98 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
101 mp:value("allow", translate("wifi_whitelist"))
102 mp:value("deny", translate("wifi_blacklist"))
103 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
104 ml:depends({macfilter="allow"})
105 ml:depends({macfilter="deny"})
107 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
108 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
110 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
112 s:option(Value, "distance", translate("wifi_distance")).optional = true
113 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
115 s:option(Value, "country", translate("wifi_country")).optional = true
116 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
120 --------------------- HostAP Device ---------------------
122 if hwtype == "prism2" then
123 s:option(Value, "txpower", translate("a_w_txpwr"), "att units").rmempty = true
125 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
127 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
128 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
132 ----------------------- Interface -----------------------
134 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
137 s:depends("device", arg[1])
138 s.defaults.device = arg[1]
140 s:option(Value, "ssid", translate("wifi_essid"))
142 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
143 network.rmempty = true
145 network.combobox_manual = translate("a_w_netmanual")
146 luci.tools.webadmin.cbi_add_networks(network)
148 function network.write(self, section, value)
149 if not m.uci:get("network", value) then
150 -- avoid "value not defined in enum" because network is not known yet
151 s.override_scheme = true
154 m.uci:set("network", value, "interface")
155 Value.write(self, section, value)
157 if m.uci:get("network", value) == "interface" then
158 Value.write(self, section, value)
164 mode = s:option(ListValue, "mode", translate("mode"))
165 mode.override_values = true
166 mode:value("ap", translate("a_w_ap"))
167 mode:value("adhoc", translate("a_w_adhoc"))
168 mode:value("sta", translate("a_w_client"))
170 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
173 -------------------- MAC80211 Interface ----------------------
175 if hwtype == "mac80211" then
176 if luci.fs.mtime("/usr/sbin/iw") then
177 mode:value("mesh", "802.11s")
180 mode:value("ahdemo", translate("a_w_ahdemo"))
181 mode:value("monitor", translate("a_w_monitor"))
182 bssid:depends({mode="adhoc"})
184 s:option(Value, "frag", translate("wifi_frag")).optional = true
185 s:option(Value, "rts", translate("wifi_rts")).optional = true
190 -------------------- Madwifi Interface ----------------------
192 if hwtype == "atheros" then
193 mode:value("ahdemo", translate("a_w_ahdemo"))
194 mode:value("monitor", translate("a_w_monitor"))
196 bssid:depends({mode="adhoc"})
197 bssid:depends({mode="ahdemo"})
199 wds = s:option(Flag, "wds", translate("a_w_wds"))
200 wds:depends({mode="ap"})
201 wds:depends({mode="sta"})
203 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
204 wdssep:depends({mode="ap", wds="1"})
205 wdssep.optional = true
207 s:option(Flag, "doth", "802.11h").optional = true
208 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
209 hidden:depends({mode="ap"})
210 hidden:depends({mode="adhoc"})
211 hidden:depends({mode="wds"})
212 hidden.optional = true
213 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
214 translate("wifi_isolate_desc"))
215 isolate:depends({mode="ap"})
216 isolate.optional = true
217 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
219 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
222 mp:value("deny", translate("wifi_whitelist"))
223 mp:value("allow", translate("wifi_blacklist"))
224 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
225 ml:depends({macpolicy="allow"})
226 ml:depends({macpolicy="deny"})
228 s:option(Value, "rate", translate("wifi_rate")).optional = true
229 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
230 s:option(Value, "frag", translate("wifi_frag")).optional = true
231 s:option(Value, "rts", translate("wifi_rts")).optional = true
232 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
233 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
234 s:option(Flag, "compression", translate("wifi_compression")).optional = true
236 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
237 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
238 s:option(Flag, "ff", translate("wifi_ff")).optional = true
240 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
241 s:option(Flag, "xr", translate("wifi_xr")).optional = true
242 s:option(Flag, "ar", translate("wifi_ar")).optional = true
244 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
245 swm:depends({mode="adhoc"})
248 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
249 nos:depends({mode="sta"})
252 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
253 probereq.optional = true
254 probereq.enabled = "0"
255 probereq.disabled = "1"
259 -------------------- Broadcom Interface ----------------------
261 if hwtype == "broadcom" then
262 mode:value("wds", translate("a_w_wds"))
263 mode:value("monitor", translate("a_w_monitor"))
265 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
266 hidden:depends({mode="ap"})
267 hidden:depends({mode="adhoc"})
268 hidden:depends({mode="wds"})
269 hidden.optional = true
271 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
272 translate("wifi_isolate_desc"))
273 isolate:depends({mode="ap"})
274 isolate.optional = true
276 bssid:depends({mode="wds"})
277 bssid:depends({mode="adhoc"})
281 ----------------------- HostAP Interface ---------------------
283 if hwtype == "prism2" then
284 mode:value("wds", translate("a_w_wds"))
285 mode:value("monitor", translate("a_w_monitor"))
287 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
288 hidden:depends({mode="ap"})
289 hidden:depends({mode="adhoc"})
290 hidden:depends({mode="wds"})
291 hidden.optional = true
293 bssid:depends({mode="sta"})
295 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
298 mp:value("deny", translate("wifi_whitelist"))
299 mp:value("allow", translate("wifi_blacklist"))
300 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
301 ml:depends({macpolicy="allow"})
302 ml:depends({macpolicy="deny"})
304 s:option(Value, "rate", translate("wifi_rate")).optional = true
305 s:option(Value, "frag", translate("wifi_frag")).optional = true
306 s:option(Value, "rts", translate("wifi_rts")).optional = true
310 ------------------- WiFI-Encryption -------------------
312 encr = s:option(ListValue, "encryption", translate("encryption"))
313 encr.override_values = true
314 encr:depends({mode="ap"})
315 encr:depends({mode="sta"})
316 encr:depends({mode="adhoc"})
317 encr:depends({mode="ahdemo"})
318 encr:depends({mode="wds"})
319 encr:depends({mode="mesh"})
321 encr:value("none", "No Encryption")
322 encr:value("wep", "WEP")
324 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
325 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
326 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
328 if hostapd and supplicant then
329 encr:value("psk", "WPA-PSK")
330 encr:value("psk2", "WPA2-PSK")
331 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
332 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
333 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
334 elseif hostapd and not supplicant then
335 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
336 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
337 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
338 encr:value("wpa", "WPA-EAP", {mode="ap"})
339 encr:value("wpa2", "WPA2-EAP", {mode="ap"})
340 encr.description = translate("wifi_wpareq")
341 elseif not hostapd and supplicant then
342 encr:value("psk", "WPA-PSK", {mode="sta"})
343 encr:value("psk2", "WPA2-PSK", {mode="sta"})
344 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
345 encr:value("wpa", "WPA-EAP", {mode="sta"})
346 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
347 encr.description = translate("wifi_wpareq")
349 encr.description = translate("wifi_wpareq")
351 elseif hwtype == "broadcom" then
352 encr:value("psk", "WPA-PSK")
353 encr:value("psk2", "WPA2-PSK")
354 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
357 encr:depends("mode", "ap")
358 encr:depends("mode", "sta")
359 encr:depends("mode", "wds")
361 server = s:option(Value, "server", translate("a_w_radiussrv"))
362 server:depends({mode="ap", encryption="wpa"})
363 server:depends({mode="ap", encryption="wpa2"})
364 server.rmempty = true
366 port = s:option(Value, "port", translate("a_w_radiusport"))
367 port:depends({mode="ap", encryption="wpa"})
368 port:depends({mode="ap", encryption="wpa2"})
371 key = s:option(Value, "key", translate("key"))
372 key:depends("encryption", "wep")
373 key:depends("encryption", "psk")
374 key:depends("encryption", "psk2")
375 key:depends("encryption", "psk+psk2")
376 key:depends("encryption", "mixed")
377 key:depends({mode="ap", encryption="wpa"})
378 key:depends({mode="ap", encryption="wpa2"})
382 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
383 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
384 nasid:depends({mode="ap", encryption="wpa"})
385 nasid:depends({mode="ap", encryption="wpa2"})
388 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
390 eaptype:value("TTLS")
391 eaptype:value("PEAP")
392 eaptype:depends({mode="sta", encryption="wpa"})
393 eaptype:depends({mode="sta", encryption="wpa2"})
395 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
396 cacert:depends({mode="sta", encryption="wpa"})
397 cacert:depends({mode="sta", encryption="wpa2"})
399 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
400 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
401 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
403 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
404 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
405 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
408 auth = s:option(Value, "auth", translate("a_w_peapauth"))
412 auth:value("MSCHAPV2")
413 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
414 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
415 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
416 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
419 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
420 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
421 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
422 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
423 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
425 password = s:option(Value, "password", translate("a_w_peappassword"))
426 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
427 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
428 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
429 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})