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
15 local wa = require "luci.tools.webadmin"
16 local fs = require "nixio.fs"
20 m = Map("wireless", translate("networks"), translate("a_w_networks1"))
22 s = m:section(NamedSection, arg[1], "wifi-device", translate("device") .. " " .. arg[1])
25 back = s:option(DummyValue, "_overview", translate("overview"))
27 back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
30 en = s:option(Flag, "disabled", translate("enable"))
35 function en.cfgvalue(self, section)
36 return Flag.cfgvalue(self, section) or "0"
39 s:option(DummyValue, "type", translate("type"))
40 local hwtype = m:get(arg[1], "type")
42 local nsantenna = m:get(arg[1], "antenna")
44 ch = s:option(Value, "channel", translate("a_w_channel"))
45 ch:value("auto", translate("wifi_auto"))
46 for c, f in luci.util.kspairs(luci.sys.wifi.channels()) do
47 ch:value(c, "%i (%.3f GHz)" %{ c, f })
51 ------------------- MAC80211 Device ------------------
53 if hwtype == "mac80211" then
54 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
58 ------------------- Madwifi Device ------------------
60 if hwtype == "atheros" then
61 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
63 mode = s:option(ListValue, "hwmode", translate("mode"))
64 mode:value("", translate("wifi_auto"))
65 mode:value("11b", "802.11b")
66 mode:value("11g", "802.11g")
67 mode:value("11a", "802.11a")
68 mode:value("11bg", "802.11b+g")
69 mode:value("11gst", "802.11g + Turbo")
70 mode:value("11ast", "802.11a + Turbo")
71 mode:value("fh", translate("wifi_fh"))
73 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
76 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
77 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
79 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
82 ant:value("horizontal")
85 s:option(Value, "distance", translate("wifi_distance"),
86 translate("wifi_distance_desc")).optional = true
87 s:option(Value, "regdomain", translate("wifi_regdomain")).optional = true
88 s:option(Value, "country", translate("wifi_country")).optional = true
89 s:option(Flag, "outdoor", translate("wifi_outdoor")).optional = true
91 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
96 ------------------- Broadcom Device ------------------
98 if hwtype == "broadcom" then
99 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
101 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
104 mp:value("allow", translate("wifi_whitelist"))
105 mp:value("deny", translate("wifi_blacklist"))
106 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
107 ml:depends({macfilter="allow"})
108 ml:depends({macfilter="deny"})
110 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
111 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
113 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
115 s:option(Value, "distance", translate("wifi_distance")).optional = true
116 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
118 s:option(Value, "country", translate("wifi_country")).optional = true
119 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
123 --------------------- HostAP Device ---------------------
125 if hwtype == "prism2" then
126 s:option(Value, "txpower", translate("a_w_txpwr"), "att units").rmempty = true
128 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
130 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
131 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
135 ----------------------- Interface -----------------------
137 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
140 s:depends("device", arg[1])
141 s.defaults.device = arg[1]
143 s:option(Value, "ssid", translate("wifi_essid"))
145 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
146 network.rmempty = true
148 network.combobox_manual = translate("a_w_netmanual")
149 wa.cbi_add_networks(network)
151 function network.write(self, section, value)
152 if not m.uci:get("network", value) then
153 -- avoid "value not defined in enum" because network is not known yet
154 s.override_scheme = true
157 m.uci:set("network", value, "interface")
158 Value.write(self, section, value)
160 if m.uci:get("network", value) == "interface" then
161 Value.write(self, section, value)
167 mode = s:option(ListValue, "mode", translate("mode"))
168 mode.override_values = true
169 mode:value("ap", translate("a_w_ap"))
170 mode:value("adhoc", translate("a_w_adhoc"))
171 mode:value("sta", translate("a_w_client"))
173 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
176 -------------------- MAC80211 Interface ----------------------
178 if hwtype == "mac80211" then
179 if fs.access("/usr/sbin/iw") then
180 mode:value("mesh", "802.11s")
183 mode:value("ahdemo", translate("a_w_ahdemo"))
184 mode:value("monitor", translate("a_w_monitor"))
185 bssid:depends({mode="adhoc"})
187 s:option(Value, "frag", translate("wifi_frag")).optional = true
188 s:option(Value, "rts", translate("wifi_rts")).optional = true
193 -------------------- Madwifi Interface ----------------------
195 if hwtype == "atheros" then
196 mode:value("ahdemo", translate("a_w_ahdemo"))
197 mode:value("monitor", translate("a_w_monitor"))
199 bssid:depends({mode="adhoc"})
200 bssid:depends({mode="ahdemo"})
202 wds = s:option(Flag, "wds", translate("a_w_wds"))
203 wds:depends({mode="ap"})
204 wds:depends({mode="sta"})
206 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
207 wdssep:depends({mode="ap", wds="1"})
208 wdssep.optional = true
210 s:option(Flag, "doth", "802.11h").optional = true
211 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
212 hidden:depends({mode="ap"})
213 hidden:depends({mode="adhoc"})
214 hidden:depends({mode="wds"})
215 hidden.optional = true
216 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
217 translate("wifi_isolate_desc"))
218 isolate:depends({mode="ap"})
219 isolate.optional = true
220 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
222 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
225 mp:value("deny", translate("wifi_whitelist"))
226 mp:value("allow", translate("wifi_blacklist"))
227 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
228 ml:depends({macpolicy="allow"})
229 ml:depends({macpolicy="deny"})
231 s:option(Value, "rate", translate("wifi_rate")).optional = true
232 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
233 s:option(Value, "frag", translate("wifi_frag")).optional = true
234 s:option(Value, "rts", translate("wifi_rts")).optional = true
235 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
236 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
237 s:option(Flag, "compression", translate("wifi_compression")).optional = true
239 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
240 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
241 s:option(Flag, "ff", translate("wifi_ff")).optional = true
243 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
244 s:option(Flag, "xr", translate("wifi_xr")).optional = true
245 s:option(Flag, "ar", translate("wifi_ar")).optional = true
247 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
248 swm:depends({mode="adhoc"})
251 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
252 nos:depends({mode="sta"})
255 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
256 probereq.optional = true
257 probereq.enabled = "0"
258 probereq.disabled = "1"
262 -------------------- Broadcom Interface ----------------------
264 if hwtype == "broadcom" then
265 mode:value("wds", translate("a_w_wds"))
266 mode:value("monitor", translate("a_w_monitor"))
268 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
269 hidden:depends({mode="ap"})
270 hidden:depends({mode="adhoc"})
271 hidden:depends({mode="wds"})
272 hidden.optional = true
274 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
275 translate("wifi_isolate_desc"))
276 isolate:depends({mode="ap"})
277 isolate.optional = true
279 bssid:depends({mode="wds"})
280 bssid:depends({mode="adhoc"})
284 ----------------------- HostAP Interface ---------------------
286 if hwtype == "prism2" then
287 mode:value("wds", translate("a_w_wds"))
288 mode:value("monitor", translate("a_w_monitor"))
290 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
291 hidden:depends({mode="ap"})
292 hidden:depends({mode="adhoc"})
293 hidden:depends({mode="wds"})
294 hidden.optional = true
296 bssid:depends({mode="sta"})
298 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
301 mp:value("deny", translate("wifi_whitelist"))
302 mp:value("allow", translate("wifi_blacklist"))
303 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
304 ml:depends({macpolicy="allow"})
305 ml:depends({macpolicy="deny"})
307 s:option(Value, "rate", translate("wifi_rate")).optional = true
308 s:option(Value, "frag", translate("wifi_frag")).optional = true
309 s:option(Value, "rts", translate("wifi_rts")).optional = true
313 ------------------- WiFI-Encryption -------------------
315 encr = s:option(ListValue, "encryption", translate("encryption"))
316 encr.override_values = true
317 encr:depends({mode="ap"})
318 encr:depends({mode="sta"})
319 encr:depends({mode="adhoc"})
320 encr:depends({mode="ahdemo"})
321 encr:depends({mode="wds"})
322 encr:depends({mode="mesh"})
324 encr:value("none", "No Encryption")
325 encr:value("wep", "WEP")
327 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
328 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
329 local hostapd = fs.access("/usr/sbin/hostapd")
331 if hostapd and supplicant then
332 encr:value("psk", "WPA-PSK")
333 encr:value("psk2", "WPA2-PSK")
334 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
335 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
336 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
337 elseif hostapd and not supplicant then
338 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
339 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
340 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
341 encr:value("wpa", "WPA-EAP", {mode="ap"})
342 encr:value("wpa2", "WPA2-EAP", {mode="ap"})
343 encr.description = translate("wifi_wpareq")
344 elseif not hostapd and supplicant then
345 encr:value("psk", "WPA-PSK", {mode="sta"})
346 encr:value("psk2", "WPA2-PSK", {mode="sta"})
347 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
348 encr:value("wpa", "WPA-EAP", {mode="sta"})
349 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
350 encr.description = translate("wifi_wpareq")
352 encr.description = translate("wifi_wpareq")
354 elseif hwtype == "broadcom" then
355 encr:value("psk", "WPA-PSK")
356 encr:value("psk2", "WPA2-PSK")
357 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
360 encr:depends("mode", "ap")
361 encr:depends("mode", "sta")
362 encr:depends("mode", "wds")
364 server = s:option(Value, "server", translate("a_w_radiussrv"))
365 server:depends({mode="ap", encryption="wpa"})
366 server:depends({mode="ap", encryption="wpa2"})
367 server.rmempty = true
369 port = s:option(Value, "port", translate("a_w_radiusport"))
370 port:depends({mode="ap", encryption="wpa"})
371 port:depends({mode="ap", encryption="wpa2"})
374 key = s:option(Value, "key", translate("key"))
375 key:depends("encryption", "wep")
376 key:depends("encryption", "psk")
377 key:depends("encryption", "psk2")
378 key:depends("encryption", "psk+psk2")
379 key:depends("encryption", "mixed")
380 key:depends({mode="ap", encryption="wpa"})
381 key:depends({mode="ap", encryption="wpa2"})
385 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
386 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
387 nasid:depends({mode="ap", encryption="wpa"})
388 nasid:depends({mode="ap", encryption="wpa2"})
391 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
393 eaptype:value("TTLS")
394 eaptype:value("PEAP")
395 eaptype:depends({mode="sta", encryption="wpa"})
396 eaptype:depends({mode="sta", encryption="wpa2"})
398 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
399 cacert:depends({mode="sta", encryption="wpa"})
400 cacert:depends({mode="sta", encryption="wpa2"})
402 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
403 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
404 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
406 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
407 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
408 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
411 auth = s:option(Value, "auth", translate("a_w_peapauth"))
415 auth:value("MSCHAPV2")
416 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
417 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
418 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
419 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
422 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
423 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
424 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
425 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
426 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
428 password = s:option(Value, "password", translate("a_w_peappassword"))
429 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
430 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
431 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
432 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})