dfa71b194b03ed57209a6b111285aaeded5c6396
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / wifi.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14
15 local wa = require "luci.tools.webadmin"
16 local fs = require "nixio.fs"
17
18 arg[1] = arg[1] or ""
19
20 m = Map("wireless", translate("networks"), translate("a_w_networks1"))
21
22 s = m:section(NamedSection, arg[1], "wifi-device", translate("device") .. " " .. arg[1])
23 s.addremove = false
24
25 back = s:option(DummyValue, "_overview", translate("overview"))
26 back.value = ""
27 back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
28
29
30 en = s:option(Flag, "disabled", translate("enable"))
31 en.enabled = "0"
32 en.disabled = "1"
33 en.rmempty = false
34
35 function en.cfgvalue(self, section)
36 return Flag.cfgvalue(self, section) or "0"
37 end
38
39 s:option(DummyValue, "type", translate("type"))
40 local hwtype = m:get(arg[1], "type")
41 -- NanoFoo
42 local nsantenna = m:get(arg[1], "antenna")
43
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 })
48 end
49
50
51 ------------------- MAC80211 Device ------------------
52
53 if hwtype == "mac80211" then
54 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
55 end
56
57
58 ------------------- Madwifi Device ------------------
59
60 if hwtype == "atheros" then
61 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
62
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"))
72
73 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
74
75 if not nsantenna then
76 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
77 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
78 else -- NanoFoo
79 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
80 ant:value("auto")
81 ant:value("vertical")
82 ant:value("horizontal")
83 ant:value("external")
84 end
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
90
91 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
92 end
93
94
95
96 ------------------- Broadcom Device ------------------
97
98 if hwtype == "broadcom" then
99 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
100
101 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
102 mp.optional = true
103 mp:value("")
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"})
109
110 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
111 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
112
113 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
114
115 s:option(Value, "distance", translate("wifi_distance")).optional = true
116 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
117
118 s:option(Value, "country", translate("wifi_country")).optional = true
119 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
120 end
121
122
123 --------------------- HostAP Device ---------------------
124
125 if hwtype == "prism2" then
126 s:option(Value, "txpower", translate("a_w_txpwr"), "att units").rmempty = true
127
128 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
129
130 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
131 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
132 end
133
134
135 ----------------------- Interface -----------------------
136
137 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
138 s.addremove = true
139 s.anonymous = true
140 s:depends("device", arg[1])
141 s.defaults.device = arg[1]
142
143 s:option(Value, "ssid", translate("wifi_essid"))
144
145 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
146 network.rmempty = true
147 network:value("")
148 network.combobox_manual = translate("a_w_netmanual")
149 wa.cbi_add_networks(network)
150
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
155
156 m:chain("network")
157 m.uci:set("network", value, "interface")
158 Value.write(self, section, value)
159 else
160 if m.uci:get("network", value) == "interface" then
161 Value.write(self, section, value)
162 end
163 end
164 end
165
166
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"))
172
173 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
174
175
176 -------------------- MAC80211 Interface ----------------------
177
178 if hwtype == "mac80211" then
179 if fs.access("/usr/sbin/iw") then
180 mode:value("mesh", "802.11s")
181 end
182
183 mode:value("ahdemo", translate("a_w_ahdemo"))
184 mode:value("monitor", translate("a_w_monitor"))
185 bssid:depends({mode="adhoc"})
186
187 s:option(Value, "frag", translate("wifi_frag")).optional = true
188 s:option(Value, "rts", translate("wifi_rts")).optional = true
189 end
190
191
192
193 -------------------- Madwifi Interface ----------------------
194
195 if hwtype == "atheros" then
196 mode:value("ahdemo", translate("a_w_ahdemo"))
197 mode:value("monitor", translate("a_w_monitor"))
198
199 bssid:depends({mode="adhoc"})
200 bssid:depends({mode="ahdemo"})
201
202 wds = s:option(Flag, "wds", translate("a_w_wds"))
203 wds:depends({mode="ap"})
204 wds:depends({mode="sta"})
205 wds.rmempty = true
206 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
207 wdssep:depends({mode="ap", wds="1"})
208 wdssep.optional = true
209
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
221
222 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
223 mp.optional = true
224 mp:value("")
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"})
230
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
238
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
242
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
246
247 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
248 swm:depends({mode="adhoc"})
249 swm.optional = true
250
251 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
252 nos:depends({mode="sta"})
253 nos.optional = true
254
255 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
256 probereq.optional = true
257 probereq.enabled = "0"
258 probereq.disabled = "1"
259 end
260
261
262 -------------------- Broadcom Interface ----------------------
263
264 if hwtype == "broadcom" then
265 mode:value("wds", translate("a_w_wds"))
266 mode:value("monitor", translate("a_w_monitor"))
267
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
273
274 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
275 translate("wifi_isolate_desc"))
276 isolate:depends({mode="ap"})
277 isolate.optional = true
278
279 bssid:depends({mode="wds"})
280 bssid:depends({mode="adhoc"})
281 end
282
283
284 ----------------------- HostAP Interface ---------------------
285
286 if hwtype == "prism2" then
287 mode:value("wds", translate("a_w_wds"))
288 mode:value("monitor", translate("a_w_monitor"))
289
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
295
296 bssid:depends({mode="sta"})
297
298 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
299 mp.optional = true
300 mp:value("")
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"})
306
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
310 end
311
312
313 ------------------- WiFI-Encryption -------------------
314
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"})
323
324 encr:value("none", "No Encryption")
325 encr:value("wep", "WEP")
326
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")
330
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")
351 else
352 encr.description = translate("wifi_wpareq")
353 end
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")
358 end
359
360 encr:depends("mode", "ap")
361 encr:depends("mode", "sta")
362 encr:depends("mode", "wds")
363
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
368
369 port = s:option(Value, "port", translate("a_w_radiusport"))
370 port:depends({mode="ap", encryption="wpa"})
371 port:depends({mode="ap", encryption="wpa2"})
372 port.rmempty = true
373
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"})
382 key.rmempty = true
383 key.password = true
384
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"})
389 nasid.rmempty = true
390
391 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
392 eaptype:value("TLS")
393 eaptype:value("TTLS")
394 eaptype:value("PEAP")
395 eaptype:depends({mode="sta", encryption="wpa"})
396 eaptype:depends({mode="sta", encryption="wpa2"})
397
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"})
401
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"})
405
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"})
409
410
411 auth = s:option(Value, "auth", translate("a_w_peapauth"))
412 auth:value("PAP")
413 auth:value("CHAP")
414 auth:value("MSCHAP")
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"})
420
421
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"})
427
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"})
433 end
434
435
436 return m