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 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
129 mp:value("allow", translate("wifi_whitelist"))
130 mp:value("deny", translate("wifi_blacklist"))
131 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
132 ml:depends({macfilter="allow"})
133 ml:depends({macfilter="deny"})
135 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
136 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
138 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
140 s:option(Value, "distance", translate("wifi_distance")).optional = true
141 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
143 s:option(Value, "country", translate("wifi_country")).optional = true
144 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
148 --------------------- HostAP Device ---------------------
150 if hwtype == "prism2" then
151 s:option(Value, "txpower", translate("a_w_txpwr"), "att units").rmempty = true
153 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
155 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
156 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
160 ----------------------- Interface -----------------------
162 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
165 s:depends("device", arg[1])
166 s.defaults.device = arg[1]
168 s:option(Value, "ssid", translate("wifi_essid"))
170 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
171 network.rmempty = true
173 network.combobox_manual = translate("a_w_netmanual")
174 wa.cbi_add_networks(network)
176 function network.write(self, section, value)
177 if not m.uci:get("network", value) then
178 -- avoid "value not defined in enum" because network is not known yet
179 s.override_scheme = true
182 m.uci:set("network", value, "interface")
183 Value.write(self, section, value)
185 if m.uci:get("network", value) == "interface" then
186 Value.write(self, section, value)
192 mode = s:option(ListValue, "mode", translate("mode"))
193 mode.override_values = true
194 mode:value("ap", translate("a_w_ap"))
195 mode:value("adhoc", translate("a_w_adhoc"))
196 mode:value("sta", translate("a_w_client"))
198 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
201 -------------------- MAC80211 Interface ----------------------
203 if hwtype == "mac80211" then
204 if fs.access("/usr/sbin/iw") then
205 mode:value("mesh", "802.11s")
208 mode:value("monitor", translate("a_w_monitor"))
209 bssid:depends({mode="adhoc"})
211 mode:value("ap-wds", "%s (WDS)" % translate("a_w_ap"))
212 mode:value("sta-wds", "%s (WDS)" % translate("a_w_client"))
214 function mode.write(self, section, value)
215 if value == "ap-wds" then
216 ListValue.write(self, section, "ap")
217 m.uci:set("wireless", section, "wds", 1)
218 elseif value == "sta-wds" then
219 ListValue.write(self, section, "sta")
220 m.uci:set("wireless", section, "wds", 1)
222 ListValue.write(self, section, value)
223 m.uci:delete("wireless", section, "wds")
227 function mode.cfgvalue(self, section)
228 local mode = ListValue.cfgvalue(self, section)
229 local wds = m.uci:get("wireless", section, "wds") == "1"
231 if mode == "ap" and wds then
233 elseif mode == "sta" and wds then
240 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
241 hidden:depends({mode="ap"})
242 hidden:depends({mode="ap-wds"})
243 hidden.optional = true
245 s:option(Value, "frag", translate("wifi_frag")).optional = true
246 s:option(Value, "rts", translate("wifi_rts")).optional = true
251 -------------------- Madwifi Interface ----------------------
253 if hwtype == "atheros" then
254 mode:value("ahdemo", translate("a_w_ahdemo"))
255 mode:value("monitor", translate("a_w_monitor"))
257 bssid:depends({mode="adhoc"})
258 bssid:depends({mode="ahdemo"})
260 mode:value("ap-wds", "%s (WDS)" % translate("a_w_ap"))
261 mode:value("sta-wds", "%s (WDS)" % translate("a_w_client"))
263 function mode.write(self, section, value)
264 if value == "ap-wds" then
265 ListValue.write(self, section, "ap")
266 m.uci:set("wireless", section, "wds", 1)
267 elseif value == "sta-wds" then
268 ListValue.write(self, section, "sta")
269 m.uci:set("wireless", section, "wds", 1)
271 ListValue.write(self, section, value)
272 m.uci:delete("wireless", section, "wds")
276 function mode.cfgvalue(self, section)
277 local mode = ListValue.cfgvalue(self, section)
278 local wds = m.uci:get("wireless", section, "wds") == "1"
280 if mode == "ap" and wds then
282 elseif mode == "sta" and wds then
289 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
290 wdssep:depends({mode="ap-wds"})
291 wdssep.optional = true
293 s:option(Flag, "doth", "802.11h").optional = true
295 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
296 hidden:depends({mode="ap"})
297 hidden:depends({mode="adhoc"})
298 hidden:depends({mode="wds"})
299 hidden:depends({mode="ap-wds"})
300 hidden.optional = true
302 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
303 translate("wifi_isolate_desc"))
304 isolate:depends({mode="ap"})
305 isolate.optional = true
306 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
308 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
311 mp:value("allow", translate("wifi_whitelist"))
312 mp:value("deny", translate("wifi_blacklist"))
313 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
314 ml:depends({macpolicy="allow"})
315 ml:depends({macpolicy="deny"})
317 s:option(Value, "rate", translate("wifi_rate")).optional = true
318 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
319 s:option(Value, "frag", translate("wifi_frag")).optional = true
320 s:option(Value, "rts", translate("wifi_rts")).optional = true
321 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
322 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
323 s:option(Flag, "compression", translate("wifi_compression")).optional = true
325 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
326 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
327 s:option(Flag, "ff", translate("wifi_ff")).optional = true
329 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
330 s:option(Flag, "xr", translate("wifi_xr")).optional = true
331 s:option(Flag, "ar", translate("wifi_ar")).optional = true
333 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
334 swm:depends({mode="adhoc"})
337 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
338 nos:depends({mode="sta"})
341 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
342 probereq.optional = true
343 probereq.enabled = "0"
344 probereq.disabled = "1"
348 -------------------- Broadcom Interface ----------------------
350 if hwtype == "broadcom" then
351 mode:value("wds", translate("a_w_wds"))
352 mode:value("monitor", translate("a_w_monitor"))
354 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
355 hidden:depends({mode="ap"})
356 hidden:depends({mode="adhoc"})
357 hidden:depends({mode="wds"})
358 hidden.optional = true
360 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
361 translate("wifi_isolate_desc"))
362 isolate:depends({mode="ap"})
363 isolate.optional = true
365 bssid:depends({mode="wds"})
366 bssid:depends({mode="adhoc"})
370 ----------------------- HostAP Interface ---------------------
372 if hwtype == "prism2" then
373 mode:value("wds", translate("a_w_wds"))
374 mode:value("monitor", translate("a_w_monitor"))
376 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
377 hidden:depends({mode="ap"})
378 hidden:depends({mode="adhoc"})
379 hidden:depends({mode="wds"})
380 hidden.optional = true
382 bssid:depends({mode="sta"})
384 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
387 mp:value("allow", translate("wifi_whitelist"))
388 mp:value("deny", translate("wifi_blacklist"))
389 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
390 ml:depends({macpolicy="allow"})
391 ml:depends({macpolicy="deny"})
393 s:option(Value, "rate", translate("wifi_rate")).optional = true
394 s:option(Value, "frag", translate("wifi_frag")).optional = true
395 s:option(Value, "rts", translate("wifi_rts")).optional = true
399 ------------------- WiFI-Encryption -------------------
401 encr = s:option(ListValue, "encryption", translate("encryption"))
402 encr.override_values = true
403 encr:depends({mode="ap"})
404 encr:depends({mode="sta"})
405 encr:depends({mode="adhoc"})
406 encr:depends({mode="ahdemo"})
407 encr:depends({mode="ap-wds"})
408 encr:depends({mode="sta-wds"})
409 encr:depends({mode="wds"})
410 encr:depends({mode="mesh"})
412 encr:value("none", "No Encryption")
413 encr:value("wep", "WEP")
415 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
416 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
417 local hostapd = fs.access("/usr/sbin/hostapd")
419 if hostapd and supplicant then
420 encr:value("psk", "WPA-PSK")
421 encr:value("psk2", "WPA2-PSK")
422 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
423 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
424 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
425 elseif hostapd and not supplicant then
426 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
427 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
428 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
429 encr:value("wpa", "WPA-EAP", {mode="ap"})
430 encr:value("wpa2", "WPA2-EAP", {mode="ap"})
431 encr.description = translate("wifi_wpareq")
432 elseif not hostapd and supplicant then
433 encr:value("psk", "WPA-PSK", {mode="sta"})
434 encr:value("psk2", "WPA2-PSK", {mode="sta"})
435 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
436 encr:value("wpa", "WPA-EAP", {mode="sta"})
437 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
438 encr.description = translate("wifi_wpareq")
440 encr.description = translate("wifi_wpareq")
442 elseif hwtype == "broadcom" then
443 encr:value("psk", "WPA-PSK")
444 encr:value("psk2", "WPA2-PSK")
445 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
448 encr:depends("mode", "ap")
449 encr:depends("mode", "sta")
450 encr:depends("mode", "wds")
452 server = s:option(Value, "server", translate("a_w_radiussrv"))
453 server:depends({mode="ap", encryption="wpa"})
454 server:depends({mode="ap", encryption="wpa2"})
455 server.rmempty = true
457 port = s:option(Value, "port", translate("a_w_radiusport"))
458 port:depends({mode="ap", encryption="wpa"})
459 port:depends({mode="ap", encryption="wpa2"})
462 key = s:option(Value, "key", translate("key"))
463 key:depends("encryption", "wep")
464 key:depends("encryption", "psk")
465 key:depends("encryption", "psk2")
466 key:depends("encryption", "psk+psk2")
467 key:depends("encryption", "psk-mixed")
468 key:depends({mode="ap", encryption="wpa"})
469 key:depends({mode="ap", encryption="wpa2"})
473 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
474 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
475 nasid:depends({mode="ap", encryption="wpa"})
476 nasid:depends({mode="ap", encryption="wpa2"})
479 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
481 eaptype:value("TTLS")
482 eaptype:value("PEAP")
483 eaptype:depends({mode="sta", encryption="wpa"})
484 eaptype:depends({mode="sta", encryption="wpa2"})
486 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
487 cacert:depends({mode="sta", encryption="wpa"})
488 cacert:depends({mode="sta", encryption="wpa2"})
490 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
491 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
492 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
494 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
495 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
496 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
499 auth = s:option(Value, "auth", translate("a_w_peapauth"))
503 auth:value("MSCHAPV2")
504 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
505 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
506 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
507 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
510 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
511 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
512 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
513 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
514 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
516 password = s:option(Value, "password", translate("a_w_peappassword"))
517 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
518 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
519 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
520 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})