luci-0.8: merge r4476, r4477, r4585 and r4587
[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 require("luci.tools.webadmin")
15 arg[1] = arg[1] or ""
16
17 m = Map("wireless", translate("networks"), translate("a_w_networks1"))
18
19 s = m:section(NamedSection, arg[1], "wifi-device", translate("device") .. " " .. arg[1])
20 s.addremove = false
21
22 back = s:option(DummyValue, "_overview", translate("overview"))
23 back.value = ""
24 back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
25
26
27 en = s:option(Flag, "disabled", translate("enable"))
28 en.enabled = "0"
29 en.disabled = "1"
30 en.rmempty = false
31
32 function en.cfgvalue(self, section)
33 return Flag.cfgvalue(self, section) or "0"
34 end
35
36 s:option(DummyValue, "type", translate("type"))
37 local hwtype = m:get(arg[1], "type")
38 -- NanoFoo
39 local nsantenna = m:get(arg[1], "antenna")
40
41 ch = s:option(Value, "channel", translate("a_w_channel"))
42 ch:value("auto", translate("wifi_auto"))
43 for c, f in luci.util.kspairs(luci.sys.wifi.channels()) do
44 ch:value(c, "%i (%.3f GHz)" %{ c, f })
45 end
46
47
48
49 ------------------- MAC80211 Device ------------------
50
51 if hwtype == "mac80211" then
52 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
53 end
54
55
56 ------------------- Madwifi Device ------------------
57
58 if hwtype == "atheros" then
59 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
60
61 mode = s:option(ListValue, "mode", translate("mode"))
62 mode:value("", translate("wifi_auto"))
63 mode:value("11b", "802.11b")
64 mode:value("11g", "802.11g")
65 mode:value("11a", "802.11a")
66 mode:value("11bg", "802.11b+g")
67 mode:value("11gst", "802.11g + Turbo")
68 mode:value("11ast", "802.11a + Turbo")
69 mode:value("fh", translate("wifi_fh"))
70
71 s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
72
73 if not nsantenna then
74 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
75 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
76 else -- NanoFoo
77 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
78 ant:value("auto")
79 ant:value("vertical")
80 ant:value("horizontal")
81 ant:value("external")
82 end
83 s:option(Value, "distance", translate("wifi_distance"),
84 translate("wifi_distance_desc")).optional = true
85 --s:option(Value, "regdomain", translate("wifi_regdomain")).optional = true
86 s:option(Value, "country", translate("wifi_country")).optional = true
87 s:option(Flag, "outdoor", translate("wifi_outdoor")).optional = true
88
89 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
90 end
91
92
93
94 ------------------- Broadcom Device ------------------
95
96 if hwtype == "broadcom" then
97 s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
98
99 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
100 mp.optional = true
101 mp:value("")
102 mp:value("allow", translate("wifi_whitelist"))
103 mp:value("deny", translate("wifi_blacklist"))
104 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
105 ml:depends({macfilter="allow"})
106 ml:depends({macfilter="deny"})
107
108 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
109 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
110
111 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
112
113 s:option(Value, "distance", translate("wifi_distance")).optional = true
114 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
115
116 s:option(Value, "country", translate("wifi_country")).optional = true
117 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
118 end
119
120
121 --------------------- HostAP Device ---------------------
122
123 if hwtype == "prism2" then
124 s:option(Value, "txpower", translate("a_w_txpwr"), "att units").rmempty = true
125
126 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
127 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
128 end
129
130
131 ----------------------- Interface -----------------------
132
133 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
134 s.addremove = true
135 s.anonymous = true
136 s:depends("device", arg[1])
137 s.defaults.device = arg[1]
138
139 s:option(Value, "ssid", translate("wifi_essid"))
140
141 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
142 network.rmempty = true
143 network:value("")
144 network.combobox_manual = translate("a_w_netmanual")
145 luci.tools.webadmin.cbi_add_networks(network)
146
147 function network.write(self, section, value)
148 if not m.uci:get("network", value) then
149 -- avoid "value not defined in enum" because network is not known yet
150 s.override_scheme = true
151
152 m:chain("network")
153 m.uci:set("network", value, "interface")
154 Value.write(self, section, value)
155 else
156 if m.uci:get("network", value) == "interface" then
157 Value.write(self, section, value)
158 end
159 end
160 end
161
162
163 mode = s:option(ListValue, "mode", translate("mode"))
164 mode.override_values = true
165 mode:value("ap", translate("a_w_ap"))
166 mode:value("adhoc", translate("a_w_adhoc"))
167 mode:value("sta", translate("a_w_client"))
168
169 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
170
171
172 -------------------- MAC80211 Interface ----------------------
173
174 if hwtype == "mac80211" then
175 mode:value("ahdemo", translate("a_w_ahdemo"))
176 mode:value("monitor", translate("a_w_monitor"))
177 bssid:depends({mode="adhoc"})
178
179 s:option(Value, "frag", translate("wifi_frag")).optional = true
180 s:option(Value, "rts", translate("wifi_rts")).optional = true
181 end
182
183
184
185 -------------------- Madwifi Interface ----------------------
186
187 if hwtype == "atheros" then
188 mode:value("ahdemo", translate("a_w_ahdemo"))
189 mode:value("monitor", translate("a_w_monitor"))
190
191 bssid:depends({mode="adhoc"})
192 bssid:depends({mode="ahdemo"})
193
194 wds = s:option(Flag, "wds", translate("a_w_wds"))
195 wds:depends({mode="ap"})
196 wds:depends({mode="sta"})
197 wds.rmempty = true
198 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
199 wdssep:depends({mode="ap", wds="1"})
200 wdssep.optional = true
201
202 s:option(Flag, "doth", "802.11h").optional = true
203 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
204 hidden:depends({mode="ap"})
205 hidden:depends({mode="adhoc"})
206 hidden:depends({mode="wds"})
207 hidden.optional = true
208 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
209 translate("wifi_isolate_desc"))
210 isolate:depends({mode="ap"})
211 isolate.optional = true
212 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
213
214 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
215 mp.optional = true
216 mp:value("")
217 mp:value("deny", translate("wifi_whitelist"))
218 mp:value("allow", translate("wifi_blacklist"))
219 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
220 ml:depends({macpolicy="allow"})
221 ml:depends({macpolicy="deny"})
222
223 s:option(Value, "rate", translate("wifi_rate")).optional = true
224 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
225 s:option(Value, "frag", translate("wifi_frag")).optional = true
226 s:option(Value, "rts", translate("wifi_rts")).optional = true
227 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
228 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
229 s:option(Flag, "compression", translate("wifi_compression")).optional = true
230
231 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
232 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
233 s:option(Flag, "ff", translate("wifi_ff")).optional = true
234
235 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
236 s:option(Flag, "xr", translate("wifi_xr")).optional = true
237 s:option(Flag, "ar", translate("wifi_ar")).optional = true
238
239 local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
240 swm:depends({mode="adhoc"})
241 swm.optional = true
242
243 local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
244 nos:depends({mode="sta"})
245 nos.optional = true
246
247 local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
248 probereq.optional = true
249 probereq.enabled = "0"
250 probereq.disabled = "1"
251 end
252
253
254 -------------------- Broadcom Interface ----------------------
255
256 if hwtype == "broadcom" then
257 mode:value("wds", translate("a_w_wds"))
258 mode:value("monitor", translate("a_w_monitor"))
259
260 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
261 hidden:depends({mode="ap"})
262 hidden:depends({mode="adhoc"})
263 hidden:depends({mode="wds"})
264 hidden.optional = true
265
266 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
267 translate("wifi_isolate_desc"))
268 isolate:depends({mode="ap"})
269 isolate.optional = true
270
271 bssid:depends({mode="wds"})
272 bssid:depends({mode="adhoc"})
273 end
274
275
276 ----------------------- HostAP Interface ---------------------
277
278 if hwtype == "prism2" then
279 mode:value("wds", translate("a_w_wds"))
280 mode:value("monitor", translate("a_w_monitor"))
281
282 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
283 hidden:depends({mode="ap"})
284 hidden:depends({mode="adhoc"})
285 hidden:depends({mode="wds"})
286 hidden.optional = true
287
288 bssid:depends({mode="sta"})
289
290 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
291 mp.optional = true
292 mp:value("")
293 mp:value("deny", translate("wifi_whitelist"))
294 mp:value("allow", translate("wifi_blacklist"))
295 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
296 ml:depends({macpolicy="allow"})
297 ml:depends({macpolicy="deny"})
298
299 s:option(Value, "rate", translate("wifi_rate")).optional = true
300 s:option(Value, "frag", translate("wifi_frag")).optional = true
301 s:option(Value, "rts", translate("wifi_rts")).optional = true
302 end
303
304
305 ------------------- WiFI-Encryption -------------------
306
307 encr = s:option(ListValue, "encryption", translate("encryption"))
308 encr.override_values = true
309 encr:depends({mode="ap"})
310 encr:depends({mode="sta"})
311 encr:depends({mode="adhoc"})
312 encr:depends({mode="ahdemo"})
313 encr:depends({mode="wds"})
314
315 encr:value("none", "No Encryption")
316 encr:value("wep", "WEP")
317
318 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
319 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
320 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
321
322 if hostapd and supplicant then
323 encr:value("psk", "WPA-PSK")
324 encr:value("psk2", "WPA2-PSK")
325 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
326 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
327 elseif hostapd and not supplicant then
328 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
329 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
330 encr:value("wpa", "WPA-EAP", {mode="ap"})
331 encr:value("wpa2", "WPA2-EAP", {mode="ap"})
332 encr.description = translate("wifi_wpareq")
333 elseif not hostapd and supplicant then
334 encr:value("psk", "WPA-PSK", {mode="sta"})
335 encr:value("psk2", "WPA2-PSK", {mode="sta"})
336 encr:value("wpa", "WPA-EAP", {mode="sta"})
337 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
338 encr.description = translate("wifi_wpareq")
339 else
340 encr.description = translate("wifi_wpareq")
341 end
342 elseif hwtype == "broadcom" then
343 encr:value("psk", "WPA-PSK")
344 encr:value("psk2", "WPA2-PSK")
345 end
346
347 encr:depends("mode", "ap")
348 encr:depends("mode", "sta")
349 encr:depends("mode", "wds")
350
351 server = s:option(Value, "server", translate("a_w_radiussrv"))
352 server:depends({mode="ap", encryption="wpa"})
353 server:depends({mode="ap", encryption="wpa2"})
354 server.rmempty = true
355
356 port = s:option(Value, "port", translate("a_w_radiusport"))
357 port:depends({mode="ap", encryption="wpa"})
358 port:depends({mode="ap", encryption="wpa2"})
359 port.rmempty = true
360
361 key = s:option(Value, "key", translate("key"))
362 key:depends("encryption", "wep")
363 key:depends("encryption", "psk")
364 key:depends({mode="ap", encryption="wpa"})
365 key:depends("encryption", "psk2")
366 key:depends({mode="ap", encryption="wpa2"})
367 key.rmempty = true
368
369 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
370 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
371 nasid:depends({mode="ap", encryption="wpa"})
372 nasid:depends({mode="ap", encryption="wpa2"})
373 nasid.rmempty = true
374
375 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
376 eaptype:value("TLS")
377 eaptype:value("TTLS")
378 eaptype:value("PEAP")
379 eaptype:depends({mode="sta", encryption="wpa"})
380 eaptype:depends({mode="sta", encryption="wpa2"})
381
382 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
383 cacert:depends({mode="sta", encryption="wpa"})
384 cacert:depends({mode="sta", encryption="wpa2"})
385
386 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
387 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
388 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
389
390 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
391 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
392 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
393
394
395 auth = s:option(Value, "auth", translate("a_w_peapauth"))
396 auth:value("PAP")
397 auth:value("CHAP")
398 auth:value("MSCHAP")
399 auth:value("MSCHAPV2")
400 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
401 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
402 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
403 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
404
405
406 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
407 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
408 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
409 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
410 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
411
412 password = s:option(Value, "password", translate("a_w_peappassword"))
413 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
414 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
415 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
416 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
417 end
418
419
420 return m