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
56 mode = s:option(ListValue, "hwmode", translate("mode"))
57 mode:value("", translate("auto"))
58 mode:value("11b", "802.11b")
59 mode:value("11g", "802.11g")
60 mode:value("11a", "802.11a")
61 mode:value("11ng", "802.11g+n")
62 mode:value("11na", "802.11a+n")
64 htmode = s:option(ListValue, "htmode", translate("wifi_htmode", "HT mode"))
65 htmode:depends("hwmode", "11na")
66 htmode:depends("hwmode", "11ng")
67 htmode:value("HT20", "20MHz")
68 htmode:value("HT40-", translate("wifi_ht40m", "40MHz - 2nd channel below"))
69 htmode:value("HT40+", translate("wifi_ht40p", "40MHz - 2nd channel above"))
71 --htcapab = s:option(DynamicList, "ht_capab", translate("wifi_htcapab", "HT capabilities"))
72 --htcapab:depends("hwmode", "11na")
73 --htcapab:depends("hwmode", "11ng")
75 s:option(Value, "country", translate("wifi_country", "Country Code"),
76 translate("wifi_country_iso3166", "Use ISO/IEC 3166 alpha2 country codes.")).optional = true
78 s:option(Value, "distance", translate("wifi_distance", "Distance Optimization"),
79 translate("wifi_distance_desc", "Distance to farthest network member in meters.")).optional = true
83 ------------------- Madwifi Device ------------------
85 if hwtype == "atheros" then
86 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
88 mode = s:option(ListValue, "hwmode", translate("mode"))
89 mode:value("", translate("wifi_auto"))
90 mode:value("11b", "802.11b")
91 mode:value("11g", "802.11g")
92 mode:value("11a", "802.11a")
93 mode:value("11bg", "802.11b+g")
94 mode:value("11gst", "802.11g + Turbo")
95 mode:value("11ast", "802.11a + Turbo")
96 mode:value("fh", translate("wifi_fh"))
98 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
100 if not nsantenna then
101 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
102 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
104 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
106 ant:value("vertical")
107 ant:value("horizontal")
108 ant:value("external")
110 s:option(Value, "distance", translate("wifi_distance"),
111 translate("wifi_distance_desc")).optional = true
112 s:option(Value, "regdomain", translate("wifi_regdomain")).optional = true
113 s:option(Value, "country", translate("wifi_country")).optional = true
114 s:option(Flag, "outdoor", translate("wifi_outdoor")).optional = true
116 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
121 ------------------- Broadcom Device ------------------
123 if hwtype == "broadcom" then
124 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
126 mode = s:option(ListValue, "hwmode", translate("mode"))
127 mode:value("11bg", "802.11b+g")
128 mode:value("11b", "802.11b")
129 mode:value("11g", "802.11g")
130 mode:value("11gst", "802.11g + Turbo")
132 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
135 mp:value("allow", translate("wifi_whitelist"))
136 mp:value("deny", translate("wifi_blacklist"))
137 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
138 ml:depends({macfilter="allow"})
139 ml:depends({macfilter="deny"})
141 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
142 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
144 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
146 s:option(Value, "distance", translate("wifi_distance")).optional = true
147 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
149 s:option(Value, "country", translate("wifi_country")).optional = true
150 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
154 --------------------- HostAP Device ---------------------
156 if hwtype == "prism2" then
157 s:option(Value, "txpower", translate("a_w_txpwr"), "att units").rmempty = true
159 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
161 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
162 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
166 ----------------------- Interface -----------------------
168 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
171 s:depends("device", arg[1])
172 s.defaults.device = arg[1]
174 s:option(Value, "ssid", translate("wifi_essid"))
176 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
177 network.rmempty = true
179 network.combobox_manual = translate("a_w_netmanual")
180 wa.cbi_add_networks(network)
182 function network.write(self, section, value)
183 if not m.uci:get("network", value) then
184 -- avoid "value not defined in enum" because network is not known yet
185 s.override_scheme = true
188 m.uci:set("network", value, "interface")
189 Value.write(self, section, value)
191 if m.uci:get("network", value) == "interface" then
192 Value.write(self, section, value)
198 mode = s:option(ListValue, "mode", translate("mode"))
199 mode.override_values = true
200 mode:value("ap", translate("a_w_ap"))
201 mode:value("adhoc", translate("a_w_adhoc"))
202 mode:value("sta", translate("a_w_client"))
204 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
207 -------------------- MAC80211 Interface ----------------------
209 if hwtype == "mac80211" then
210 if fs.access("/usr/sbin/iw") then
211 mode:value("mesh", "802.11s")
214 mode:value("monitor", translate("a_w_monitor"))
215 bssid:depends({mode="adhoc"})
217 mode:value("ap-wds", "%s (WDS)" % translate("a_w_ap"))
218 mode:value("sta-wds", "%s (WDS)" % translate("a_w_client"))
220 function mode.write(self, section, value)
221 if value == "ap-wds" then
222 ListValue.write(self, section, "ap")
223 m.uci:set("wireless", section, "wds", 1)
224 elseif value == "sta-wds" then
225 ListValue.write(self, section, "sta")
226 m.uci:set("wireless", section, "wds", 1)
228 ListValue.write(self, section, value)
229 m.uci:delete("wireless", section, "wds")
233 function mode.cfgvalue(self, section)
234 local mode = ListValue.cfgvalue(self, section)
235 local wds = m.uci:get("wireless", section, "wds") == "1"
237 if mode == "ap" and wds then
239 elseif mode == "sta" and wds then
246 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
247 hidden:depends({mode="ap"})
248 hidden:depends({mode="ap-wds"})
249 hidden.optional = true
251 s:option(Value, "frag", translate("wifi_frag")).optional = true
252 s:option(Value, "rts", translate("wifi_rts")).optional = true
257 -------------------- Madwifi Interface ----------------------
259 if hwtype == "atheros" then
260 mode:value("ahdemo", translate("a_w_ahdemo"))
261 mode:value("monitor", translate("a_w_monitor"))
263 bssid:depends({mode="adhoc"})
264 bssid:depends({mode="ahdemo"})
266 mode:value("ap-wds", "%s (WDS)" % translate("a_w_ap"))
267 mode:value("sta-wds", "%s (WDS)" % translate("a_w_client"))
269 function mode.write(self, section, value)
270 if value == "ap-wds" then
271 ListValue.write(self, section, "ap")
272 m.uci:set("wireless", section, "wds", 1)
273 elseif value == "sta-wds" then
274 ListValue.write(self, section, "sta")
275 m.uci:set("wireless", section, "wds", 1)
277 ListValue.write(self, section, value)
278 m.uci:delete("wireless", section, "wds")
282 function mode.cfgvalue(self, section)
283 local mode = ListValue.cfgvalue(self, section)
284 local wds = m.uci:get("wireless", section, "wds") == "1"
286 if mode == "ap" and wds then
288 elseif mode == "sta" and wds then
295 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
296 wdssep:depends({mode="ap-wds"})
297 wdssep.optional = true
299 s:option(Flag, "doth", "802.11h").optional = true
301 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
302 hidden:depends({mode="ap"})
303 hidden:depends({mode="adhoc"})
304 hidden:depends({mode="wds"})
305 hidden:depends({mode="ap-wds"})
306 hidden.optional = true
308 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
309 translate("wifi_isolate_desc"))
310 isolate:depends({mode="ap"})
311 isolate.optional = true
312 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
314 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
317 mp:value("allow", translate("wifi_whitelist"))
318 mp:value("deny", translate("wifi_blacklist"))
319 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
320 ml:depends({macpolicy="allow"})
321 ml:depends({macpolicy="deny"})
323 s:option(Value, "rate", translate("wifi_rate")).optional = true
324 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
325 s:option(Value, "frag", translate("wifi_frag")).optional = true
326 s:option(Value, "rts", translate("wifi_rts")).optional = true
327 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
328 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
329 s:option(Flag, "compression", translate("wifi_compression")).optional = true
331 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
332 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
333 s:option(Flag, "ff", translate("wifi_ff")).optional = true
335 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
336 s:option(Flag, "xr", translate("wifi_xr")).optional = true
337 s:option(Flag, "ar", translate("wifi_ar")).optional = true
339 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
340 swm:depends({mode="adhoc"})
343 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
344 nos:depends({mode="sta"})
347 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
348 probereq.optional = true
349 probereq.enabled = "0"
350 probereq.disabled = "1"
354 -------------------- Broadcom Interface ----------------------
356 if hwtype == "broadcom" then
357 mode:value("wds", translate("a_w_wds"))
358 mode:value("monitor", translate("a_w_monitor"))
360 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
361 hidden:depends({mode="ap"})
362 hidden:depends({mode="adhoc"})
363 hidden:depends({mode="wds"})
364 hidden.optional = true
366 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
367 translate("wifi_isolate_desc"))
368 isolate:depends({mode="ap"})
369 isolate.optional = true
371 bssid:depends({mode="wds"})
372 bssid:depends({mode="adhoc"})
376 ----------------------- HostAP Interface ---------------------
378 if hwtype == "prism2" then
379 mode:value("wds", translate("a_w_wds"))
380 mode:value("monitor", translate("a_w_monitor"))
382 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
383 hidden:depends({mode="ap"})
384 hidden:depends({mode="adhoc"})
385 hidden:depends({mode="wds"})
386 hidden.optional = true
388 bssid:depends({mode="sta"})
390 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
393 mp:value("allow", translate("wifi_whitelist"))
394 mp:value("deny", translate("wifi_blacklist"))
395 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
396 ml:depends({macpolicy="allow"})
397 ml:depends({macpolicy="deny"})
399 s:option(Value, "rate", translate("wifi_rate")).optional = true
400 s:option(Value, "frag", translate("wifi_frag")).optional = true
401 s:option(Value, "rts", translate("wifi_rts")).optional = true
405 ------------------- WiFI-Encryption -------------------
407 encr = s:option(ListValue, "encryption", translate("encryption"))
408 encr.override_values = true
409 encr:depends({mode="ap"})
410 encr:depends({mode="sta"})
411 encr:depends({mode="adhoc"})
412 encr:depends({mode="ahdemo"})
413 encr:depends({mode="ap-wds"})
414 encr:depends({mode="sta-wds"})
415 encr:depends({mode="wds"})
416 encr:depends({mode="mesh"})
418 encr:value("none", "No Encryption")
419 encr:value("wep", "WEP")
421 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
422 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
423 local hostapd = fs.access("/usr/sbin/hostapd")
425 if hostapd and supplicant then
426 encr:value("psk", "WPA-PSK")
427 encr:value("psk2", "WPA2-PSK")
428 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
429 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
430 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
431 elseif hostapd and not supplicant then
432 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
433 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
434 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
435 encr:value("wpa", "WPA-EAP", {mode="ap"})
436 encr:value("wpa2", "WPA2-EAP", {mode="ap"})
437 encr.description = translate("wifi_wpareq")
438 elseif not hostapd and supplicant then
439 encr:value("psk", "WPA-PSK", {mode="sta"})
440 encr:value("psk2", "WPA2-PSK", {mode="sta"})
441 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
442 encr:value("wpa", "WPA-EAP", {mode="sta"})
443 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
444 encr.description = translate("wifi_wpareq")
446 encr.description = translate("wifi_wpareq")
448 elseif hwtype == "broadcom" then
449 encr:value("psk", "WPA-PSK")
450 encr:value("psk2", "WPA2-PSK")
451 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
454 encr:depends("mode", "ap")
455 encr:depends("mode", "sta")
456 encr:depends("mode", "wds")
458 server = s:option(Value, "server", translate("a_w_radiussrv"))
459 server:depends({mode="ap", encryption="wpa"})
460 server:depends({mode="ap", encryption="wpa2"})
461 server.rmempty = true
463 port = s:option(Value, "port", translate("a_w_radiusport"))
464 port:depends({mode="ap", encryption="wpa"})
465 port:depends({mode="ap", encryption="wpa2"})
468 key = s:option(Value, "key", translate("key"))
469 key:depends("encryption", "wep")
470 key:depends("encryption", "psk")
471 key:depends("encryption", "psk2")
472 key:depends("encryption", "psk+psk2")
473 key:depends("encryption", "psk-mixed")
474 key:depends({mode="ap", encryption="wpa"})
475 key:depends({mode="ap", encryption="wpa2"})
479 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
480 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
481 nasid:depends({mode="ap", encryption="wpa"})
482 nasid:depends({mode="ap", encryption="wpa2"})
485 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
487 eaptype:value("TTLS")
488 eaptype:value("PEAP")
489 eaptype:depends({mode="sta", encryption="wpa"})
490 eaptype:depends({mode="sta", encryption="wpa2"})
492 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
493 cacert:depends({mode="sta", encryption="wpa"})
494 cacert:depends({mode="sta", encryption="wpa2"})
496 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
497 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
498 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
500 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
501 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
502 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
505 auth = s:option(Value, "auth", translate("a_w_peapauth"))
509 auth:value("MSCHAPV2")
510 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
511 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
512 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
513 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
516 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
517 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
518 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
519 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
520 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
522 password = s:option(Value, "password", translate("a_w_peappassword"))
523 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
524 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
525 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
526 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})