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
49 ------------------- MAC80211 Device ------------------
51 if hwtype == "mac80211" then
56 ------------------- Madwifi Device ------------------
58 if hwtype == "atheros" then
59 mode = s:option(ListValue, "mode", translate("mode"))
60 mode:value("", translate("wifi_auto"))
61 mode:value("11b", "802.11b")
62 mode:value("11g", "802.11g")
63 mode:value("11a", "802.11a")
64 mode:value("11bg", "802.11b+g")
65 mode:value("11gst", "802.11g + Turbo")
66 mode:value("11ast", "802.11a + Turbo")
67 mode:value("fh", translate("wifi_fh"))
69 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
72 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
73 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
75 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
78 ant:value("horizontal")
81 s:option(Value, "distance", translate("wifi_distance"),
82 translate("wifi_distance_desc")).optional = true
84 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
89 ------------------- Broadcom Device ------------------
91 if hwtype == "broadcom" then
92 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
95 mp:value("allow", translate("wifi_whitelist"))
96 mp:value("deny", translate("wifi_blacklist"))
97 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
98 ml:depends({macfilter="allow"})
99 ml:depends({macfilter="deny"})
101 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
102 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
104 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
106 s:option(Value, "distance", translate("wifi_distance")).optional = true
107 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
109 s:option(Value, "country", translate("wifi_country")).optional = true
110 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
114 ----------------------- Interface -----------------------
116 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
119 s:depends("device", arg[1])
120 s.defaults.device = arg[1]
122 s:option(Value, "ssid", translate("wifi_essid"))
124 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
125 network.rmempty = true
127 network.combobox_manual = translate("a_w_netmanual")
128 luci.tools.webadmin.cbi_add_networks(network)
130 function network.write(self, section, value)
131 if not m.uci:get("network", value) then
132 -- avoid "value not defined in enum" because network is not known yet
133 s.override_scheme = true
136 m.uci:set("network", value, "interface")
137 Value.write(self, section, value)
139 if m.uci:get("network", value) == "interface" then
140 Value.write(self, section, value)
146 mode = s:option(ListValue, "mode", translate("mode"))
147 mode.override_values = true
148 mode:value("ap", translate("a_w_ap"))
149 mode:value("adhoc", translate("a_w_adhoc"))
150 mode:value("sta", translate("a_w_client"))
152 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
155 -------------------- MAC80211 Interface ----------------------
157 if hwtype == "mac80211" then
158 mode:value("ahdemo", translate("a_w_ahdemo"))
159 mode:value("monitor", translate("a_w_monitor"))
160 bssid:depends({mode="adhoc"})
162 s:option(Value, "frag", translate("wifi_frag")).optional = true
163 s:option(Value, "rts", translate("wifi_rts")).optional = true
168 -------------------- Madwifi Interface ----------------------
170 if hwtype == "atheros" then
171 mode:value("ahdemo", translate("a_w_ahdemo"))
172 mode:value("monitor", translate("a_w_monitor"))
174 bssid:depends({mode="adhoc"})
175 bssid:depends({mode="ahdemo"})
177 wds = s:option(Flag, "wds", translate("a_w_wds"))
178 wds:depends({mode="ap"})
179 wds:depends({mode="sta"})
181 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
182 wdssep:depends({mode="ap", wds="1"})
183 wdssep.optional = true
185 s:option(Flag, "doth", "802.11h").optional = true
186 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
187 hidden:depends({mode="ap"})
188 hidden:depends({mode="adhoc"})
189 hidden:depends({mode="wds"})
190 hidden.optional = true
191 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
192 translate("wifi_isolate_desc"))
193 isolate:depends({mode="ap"})
194 isolate.optional = true
195 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
197 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
200 mp:value("deny", translate("wifi_whitelist"))
201 mp:value("allow", translate("wifi_blacklist"))
202 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
203 ml:depends({macpolicy="allow"})
204 ml:depends({macpolicy="deny"})
206 s:option(Value, "rate", translate("wifi_rate")).optional = true
207 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
208 s:option(Value, "frag", translate("wifi_frag")).optional = true
209 s:option(Value, "rts", translate("wifi_rts")).optional = true
210 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
211 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
212 s:option(Flag, "compression", translate("wifi_compression")).optional = true
214 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
215 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
216 s:option(Value, "ff", translate("wifi_ff")).optional = true
218 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
219 s:option(Flag, "xr", translate("wifi_xr")).optional = true
220 s:option(Flag, "ar", translate("wifi_ar")).optional = true
222 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
223 swm:depends({mode="adhoc"})
226 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
227 nos:depends({mode="sta"})
230 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
231 probereq.optional = true
232 probereq.enabled = "0"
233 probereq.disabled = "1"
237 -------------------- Broadcom Interface ----------------------
239 if hwtype == "broadcom" then
240 mode:value("wds", translate("a_w_wds"))
241 mode:value("monitor", translate("a_w_monitor"))
243 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
244 hidden:depends({mode="ap"})
245 hidden:depends({mode="adhoc"})
246 hidden:depends({mode="wds"})
247 hidden.optional = true
249 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
250 translate("wifi_isolate_desc"))
251 isolate:depends({mode="ap"})
252 isolate.optional = true
254 bssid:depends({mode="wds"})
255 bssid:depends({mode="adhoc"})
260 ------------------- WiFI-Encryption -------------------
262 encr = s:option(ListValue, "encryption", translate("encryption"))
263 encr.override_values = true
264 encr:depends({mode="ap"})
265 encr:depends({mode="sta"})
266 encr:depends({mode="adhoc"})
267 encr:depends({mode="ahdemo"})
268 encr:depends({mode="wds"})
270 encr:value("none", "No Encryption")
271 encr:value("wep", "WEP")
273 if hwtype == "atheros" or hwtype == "mac80211" then
274 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
275 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
277 if hostapd and supplicant then
278 encr:value("psk", "WPA-PSK")
279 encr:value("psk2", "WPA2-PSK")
280 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
281 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
282 elseif hostapd and not supplicant then
283 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
284 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
285 encr:value("wpa", "WPA-EAP", {mode="ap"})
286 encr:value("wpa2", "WPA2-EAP", {mode="ap"})
287 encr.description = translate("wifi_wpareq")
288 elseif not hostapd and supplicant then
289 encr:value("psk", "WPA-PSK", {mode="sta"})
290 encr:value("psk2", "WPA2-PSK", {mode="sta"})
291 encr:value("wpa", "WPA-EAP", {mode="sta"})
292 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
293 encr.description = translate("wifi_wpareq")
295 encr.description = translate("wifi_wpareq")
297 elseif hwtype == "broadcom" then
298 encr:value("psk", "WPA-PSK")
299 encr:value("psk2", "WPA2-PSK")
302 encr:depends("mode", "ap")
303 encr:depends("mode", "sta")
304 encr:depends("mode", "wds")
306 server = s:option(Value, "server", translate("a_w_radiussrv"))
307 server:depends({mode="ap", encryption="wpa"})
308 server:depends({mode="ap", encryption="wpa2"})
309 server.rmempty = true
311 port = s:option(Value, "port", translate("a_w_radiusport"))
312 port:depends({mode="ap", encryption="wpa"})
313 port:depends({mode="ap", encryption="wpa2"})
316 key = s:option(Value, "key", translate("key"))
317 key:depends("encryption", "wep")
318 key:depends("encryption", "psk")
319 key:depends({mode="ap", encryption="wpa"})
320 key:depends("encryption", "psk2")
321 key:depends({mode="ap", encryption="wpa2"})
324 if hwtype == "atheros" or hwtype == "mac80211" then
325 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
326 nasid:depends({mode="ap", encryption="wpa"})
327 nasid:depends({mode="ap", encryption="wpa2"})
330 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
332 eaptype:value("TTLS")
333 eaptype:value("PEAP")
334 eaptype:depends({mode="sta", encryption="wpa"})
335 eaptype:depends({mode="sta", encryption="wpa2"})
337 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
338 cacert:depends({mode="sta", encryption="wpa"})
339 cacert:depends({mode="sta", encryption="wpa2"})
341 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
342 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
343 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
345 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
346 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
347 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
350 auth = s:option(Value, "auth", translate("a_w_peapauth"))
354 auth:value("MSCHAPV2")
355 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
356 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
357 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
358 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
361 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
362 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
363 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
364 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
365 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
367 password = s:option(Value, "password", translate("a_w_peappassword"))
368 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
369 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
370 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
371 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})