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