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 for c, f in luci.util.kspairs(luci.sys.wifi.channels()) do
43 ch:value(c, "%i (%.3f GHz)" %{ c, f })
46 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
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")).rmempty = false
71 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
72 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
74 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
77 ant:value("horizontal")
80 s:option(Value, "distance", translate("wifi_distance"),
81 translate("wifi_distance_desc")).optional = true
82 s:option(Value, "regdomain", translate("wifi_regdomain")).optional = true
83 s:option(Value, "country", translate("wifi_country")).optional = true
84 s:option(Flag, "outdoor", translate("wifi_outdoor")).optional = true
86 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
91 ------------------- Broadcom Device ------------------
93 if hwtype == "broadcom" then
94 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
97 mp:value("allow", translate("wifi_whitelist"))
98 mp:value("deny", translate("wifi_blacklist"))
99 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
100 ml:depends({macfilter="allow"})
101 ml:depends({macfilter="deny"})
103 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
104 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
106 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
108 s:option(Value, "distance", translate("wifi_distance")).optional = true
109 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
111 s:option(Value, "country", translate("wifi_country")).optional = true
112 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
116 ----------------------- Interface -----------------------
118 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
121 s:depends("device", arg[1])
122 s.defaults.device = arg[1]
124 s:option(Value, "ssid", translate("wifi_essid"))
126 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
127 network.rmempty = true
129 network.combobox_manual = translate("a_w_netmanual")
130 luci.tools.webadmin.cbi_add_networks(network)
132 function network.write(self, section, value)
133 if not m.uci:get("network", value) then
134 -- avoid "value not defined in enum" because network is not known yet
135 s.override_scheme = true
138 m.uci:set("network", value, "interface")
139 Value.write(self, section, value)
141 if m.uci:get("network", value) == "interface" then
142 Value.write(self, section, value)
148 mode = s:option(ListValue, "mode", translate("mode"))
149 mode.override_values = true
150 mode:value("ap", translate("a_w_ap"))
151 mode:value("adhoc", translate("a_w_adhoc"))
152 mode:value("sta", translate("a_w_client"))
154 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
157 -------------------- MAC80211 Interface ----------------------
159 if hwtype == "mac80211" then
160 if luci.fs.mtime("/usr/sbin/iw") then
161 mode:value("mesh", "802.11s")
164 mode:value("ahdemo", translate("a_w_ahdemo"))
165 mode:value("monitor", translate("a_w_monitor"))
166 bssid:depends({mode="adhoc"})
168 s:option(Value, "frag", translate("wifi_frag")).optional = true
169 s:option(Value, "rts", translate("wifi_rts")).optional = true
174 -------------------- Madwifi Interface ----------------------
176 if hwtype == "atheros" then
177 mode:value("ahdemo", translate("a_w_ahdemo"))
178 mode:value("monitor", translate("a_w_monitor"))
180 bssid:depends({mode="adhoc"})
181 bssid:depends({mode="ahdemo"})
183 wds = s:option(Flag, "wds", translate("a_w_wds"))
184 wds:depends({mode="ap"})
185 wds:depends({mode="sta"})
187 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
188 wdssep:depends({mode="ap", wds="1"})
189 wdssep.optional = true
191 s:option(Flag, "doth", "802.11h").optional = true
192 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
193 hidden:depends({mode="ap"})
194 hidden:depends({mode="adhoc"})
195 hidden:depends({mode="wds"})
196 hidden.optional = true
197 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
198 translate("wifi_isolate_desc"))
199 isolate:depends({mode="ap"})
200 isolate.optional = true
201 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
203 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
206 mp:value("deny", translate("wifi_whitelist"))
207 mp:value("allow", translate("wifi_blacklist"))
208 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
209 ml:depends({macpolicy="allow"})
210 ml:depends({macpolicy="deny"})
212 s:option(Value, "rate", translate("wifi_rate")).optional = true
213 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
214 s:option(Value, "frag", translate("wifi_frag")).optional = true
215 s:option(Value, "rts", translate("wifi_rts")).optional = true
216 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
217 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
218 s:option(Flag, "compression", translate("wifi_compression")).optional = true
220 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
221 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
222 s:option(Flag, "ff", translate("wifi_ff")).optional = true
224 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
225 s:option(Flag, "xr", translate("wifi_xr")).optional = true
226 s:option(Flag, "ar", translate("wifi_ar")).optional = true
228 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
229 swm:depends({mode="adhoc"})
232 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
233 nos:depends({mode="sta"})
236 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
237 probereq.optional = true
238 probereq.enabled = "0"
239 probereq.disabled = "1"
243 -------------------- Broadcom Interface ----------------------
245 if hwtype == "broadcom" then
246 mode:value("wds", translate("a_w_wds"))
247 mode:value("monitor", translate("a_w_monitor"))
249 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
250 hidden:depends({mode="ap"})
251 hidden:depends({mode="adhoc"})
252 hidden:depends({mode="wds"})
253 hidden.optional = true
255 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
256 translate("wifi_isolate_desc"))
257 isolate:depends({mode="ap"})
258 isolate.optional = true
260 bssid:depends({mode="wds"})
261 bssid:depends({mode="adhoc"})
266 ------------------- WiFI-Encryption -------------------
268 encr = s:option(ListValue, "encryption", translate("encryption"))
269 encr.override_values = true
270 encr:depends({mode="ap"})
271 encr:depends({mode="sta"})
272 encr:depends({mode="adhoc"})
273 encr:depends({mode="ahdemo"})
274 encr:depends({mode="wds"})
275 encr:depends({mode="mesh"})
277 encr:value("none", "No Encryption")
278 encr:value("wep", "WEP")
280 if hwtype == "atheros" or hwtype == "mac80211" then
281 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
282 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
284 if hostapd and supplicant then
285 encr:value("psk", "WPA-PSK")
286 encr:value("psk2", "WPA2-PSK")
287 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
288 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
289 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
290 elseif hostapd and not supplicant then
291 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
292 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
293 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
294 encr:value("wpa", "WPA-EAP", {mode="ap"})
295 encr:value("wpa2", "WPA2-EAP", {mode="ap"})
296 encr.description = translate("wifi_wpareq")
297 elseif not hostapd and supplicant then
298 encr:value("psk", "WPA-PSK", {mode="sta"})
299 encr:value("psk2", "WPA2-PSK", {mode="sta"})
300 encr:value("mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
301 encr:value("wpa", "WPA-EAP", {mode="sta"})
302 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
303 encr.description = translate("wifi_wpareq")
305 encr.description = translate("wifi_wpareq")
307 elseif hwtype == "broadcom" then
308 encr:value("psk", "WPA-PSK")
309 encr:value("psk2", "WPA2-PSK")
310 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
313 encr:depends("mode", "ap")
314 encr:depends("mode", "sta")
315 encr:depends("mode", "wds")
317 server = s:option(Value, "server", translate("a_w_radiussrv"))
318 server:depends({mode="ap", encryption="wpa"})
319 server:depends({mode="ap", encryption="wpa2"})
320 server.rmempty = true
322 port = s:option(Value, "port", translate("a_w_radiusport"))
323 port:depends({mode="ap", encryption="wpa"})
324 port:depends({mode="ap", encryption="wpa2"})
327 key = s:option(Value, "key", translate("key"))
328 key:depends("encryption", "wep")
329 key:depends("encryption", "psk")
330 key:depends({mode="ap", encryption="wpa"})
331 key:depends("encryption", "psk2")
332 key:depends({mode="ap", encryption="wpa2"})
335 if hwtype == "atheros" or hwtype == "mac80211" then
336 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
337 nasid:depends({mode="ap", encryption="wpa"})
338 nasid:depends({mode="ap", encryption="wpa2"})
341 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
343 eaptype:value("TTLS")
344 eaptype:value("PEAP")
345 eaptype:depends({mode="sta", encryption="wpa"})
346 eaptype:depends({mode="sta", encryption="wpa2"})
348 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
349 cacert:depends({mode="sta", encryption="wpa"})
350 cacert:depends({mode="sta", encryption="wpa2"})
352 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
353 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
354 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
356 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
357 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
358 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
361 auth = s:option(Value, "auth", translate("a_w_peapauth"))
365 auth:value("MSCHAPV2")
366 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
367 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
368 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
369 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
372 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
373 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
374 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
375 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
376 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
378 password = s:option(Value, "password", translate("a_w_peappassword"))
379 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
380 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
381 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
382 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})