Overall CBI-UVL ineraction fixes
[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 = true
21
22 en = s:option(Flag, "disabled", translate("enable"))
23 en.enabled = "0"
24 en.disabled = "1"
25
26 function en.cfgvalue(self, section)
27         return Flag.cfgvalue(self, section) or "0"
28 end
29
30 s:option(DummyValue, "type", translate("type"))
31 local hwtype = m:get(arg[1], "type")
32
33 ch = s:option(Value, "channel", translate("a_w_channel"))
34 for i=1, 14 do
35         ch:value(i, i .. " (2.4 GHz)")
36 end
37 for i=36, 64, 4 do
38         ch:value(i, i .. " (5 GHz)")
39 end
40 for i=100, 140, 4 do
41         ch:value(i, i .. " (5 GHz)")
42 end
43 ch:value(147, 147 .. " (5 GHz)")
44 ch:value(151, 151 .. " (5 GHz)")
45 ch:value(155, 155 .. " (5 GHz)")
46 ch:value(167, 167 .. " (5 GHz)")
47
48 ------------------- MAC80211 Device ------------------
49
50 if hwtype == "mac80211" then
51
52 end
53
54
55 ------------------- Madwifi Device ------------------
56
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"))
67
68         s:option(Flag, "diversity", translate("wifi_diversity"))
69         s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
70         s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
71         s:option(Value, "distance", translate("wifi_distance"),
72                 translate("wifi_distance_desc")).optional = true
73
74         --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
75 end
76
77
78
79 ------------------- Broadcom Device ------------------
80
81 if hwtype == "broadcom" then
82         mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
83         mp.optional = true
84         mp:value("")
85         mp:value("deny", translate("wifi_whitelist"))
86         mp:value("allow", translate("wifi_blacklist"))
87         ml = s:option(Value, "maclist", translate("wifi_maclist"))
88         ml:depends({macpolicy="allow"})
89         ml:depends({macpolicy="deny"})
90
91         s:option(Value, "txant", translate("wifi_txantenna")).optional = true
92         s:option(Value, "rxant", translate("wifi_rxantenna")).optional = true
93
94         s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
95
96         s:option(Value, "distance", translate("wifi_distance")).optional = true
97         --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
98
99         s:option(Value, "country", translate("wifi_country")).optional = true
100         s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
101 end
102
103
104 ----------------------- Interface -----------------------
105
106 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
107 s.addremove = true
108 s.anonymous = true
109 s:depends("device", arg[1])
110 s.defaults.device = arg[1]
111
112 s:option(Value, "ssid", translate("wifi_essid"))
113
114 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
115 network.rmempty = true
116 network:value("")
117 network.combobox_manual = translate("a_w_netmanual")
118 luci.tools.webadmin.cbi_add_networks(network)
119
120 function network.write(self, section, value)
121         if not m.uci:get("network", value) then
122                 -- avoid "value not defined in enum" because network is not known yet
123                 s.override_scheme = true
124                 
125                 m:chain("network")
126                 m.uci:set("network", value, "interface")
127                 Value.write(self, section, value)
128         else
129                 if m.uci:get("network", value) == "interface" then
130                         Value.write(self, section, value)
131                 end
132         end
133 end
134
135
136 mode = s:option(ListValue, "mode", translate("mode"))
137 mode:value("ap", translate("a_w_ap"))
138 mode:value("adhoc", translate("a_w_adhoc"))
139 mode:value("sta", translate("a_w_client"))
140
141 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
142
143
144 -------------------- MAC80211 Interface ----------------------
145
146 if hwtype == "mac80211" then
147         mode:value("monitor", translate("a_w_monitor"))
148         bssid:depends({mode="adhoc"})
149
150         s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
151         s:option(Value, "frag", translate("wifi_frag")).optional = true
152         s:option(Value, "rts", translate("wifi_rts")).optional = true
153 end
154
155
156
157 -------------------- Madwifi Interface ----------------------
158
159 if hwtype == "atheros" then
160         mode:value("ahdemo", translate("a_w_ahdemo"))
161         mode:value("monitor", translate("a_w_monitor"))
162
163         bssid:depends({mode="adhoc"})
164         bssid:depends({mode="ahdemo"})
165
166         wds = s:option(Flag, "wds", translate("a_w_wds"))
167         wds:depends({mode="ap"})
168         wds:depends({mode="sta"})
169         wds.rmempty = true
170         wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
171         wdssep:depends({mode="ap", wds="1"})
172         wdssep.optional = true
173
174         s:option(Flag, "doth", "802.11h").optional = true
175         s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
176         hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
177         hidden:depends({mode="ap"})
178         hidden:depends({mode="adhoc"})
179         hidden:depends({mode="wds"})
180         hidden.optional = true
181         isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
182          translate("wifi_isolate_desc"))
183         isolate:depends({mode="ap"})
184         isolate.optional = true
185         s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
186
187         mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
188         mp.optional = true
189         mp:value("")
190         mp:value("deny", translate("wifi_whitelist"))
191         mp:value("allow", translate("wifi_blacklist"))
192         ml = s:option(Value, "maclist", translate("wifi_maclist"))
193         ml:depends({macpolicy="allow"})
194         ml:depends({macpolicy="deny"})
195
196         s:option(Value, "rate", translate("wifi_rate")).optional = true
197         s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
198         s:option(Value, "frag", translate("wifi_frag")).optional = true
199         s:option(Value, "rts", translate("wifi_rts")).optional = true
200         s:option(Value, "minrate", translate("wifi_minrate")).optional = true
201         s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
202         s:option(Flag, "compression", translate("wifi_compression")).optional = true
203
204         s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
205         s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
206         s:option(Value, "ff", translate("wifi_ff")).optional = true
207
208         s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
209         s:option(Flag, "xr", translate("wifi_xr")).optional = true
210         s:option(Flag, "ar", translate("wifi_ar")).optional = true
211 end
212
213
214 -------------------- Broadcom Interface ----------------------
215
216 if hwtype == "broadcom" then
217         mode:value("wds", translate("a_w_wds"))
218         mode:value("monitor", translate("a_w_monitor"))
219
220         hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
221         hidden:depends({mode="ap"})
222         hidden:depends({mode="adhoc"})
223         hidden:depends({mode="wds"})
224         hidden.optional = true
225
226         isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
227          translate("wifi_isolate_desc"))
228         isolate:depends({mode="ap"})
229         isolate.optional = true
230
231         bssid:depends({mode="wds"})
232 end
233
234
235
236 ------------------- WiFI-Encryption -------------------
237
238 encr = s:option(ListValue, "encryption", translate("encryption"))
239 encr.override_values = true
240 encr:depends({mode="ap"})
241 encr:depends({mode="sta"})
242 encr:depends({mode="adhoc"})
243 encr:depends({mode="ahdemo"})
244 encr:depends({mode="wds"})
245
246 encr:value("none", "No Encryption")
247 encr:value("wep", "WEP")
248
249 if hwtype == "atheros" or hwtype == "mac80211" then
250         local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
251         local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
252
253         if hostapd and supplicant then
254                 encr:value("psk", "WPA-PSK")
255                 encr:value("psk2", "WPA2-PSK")
256                 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
257                 encr:value("wpa2i", "WPA2-EAP", {mode="ap"}, {mode="sta"})
258         elseif hostapd and not supplicant then
259                 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
260                 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
261                 encr:value("wpa", "WPA-EAP", {mode="ap"})
262                 encr:value("wpa2i", "WPA2-EAP", {mode="ap"})
263                 encr.description = translate("wifi_wpareq")
264         elseif not hostapd and supplicant then
265                 encr:value("psk", "WPA-PSK", {mode="sta"})
266                 encr:value("psk2", "WPA2-PSK", {mode="sta"})
267                 encr:value("wpa", "WPA-EAP", {mode="sta"})
268                 encr:value("wpa2i", "WPA2-EAP", {mode="sta"})
269                 encr.description = translate("wifi_wpareq")
270         else
271                 encr.description = translate("wifi_wpareq")
272         end
273 elseif hwtype == "broadcom" then
274         encr:value("psk", "WPA-PSK")
275         encr:value("psk2", "WPA2-PSK")
276 end
277
278 encr:depends("mode", "ap")
279 encr:depends("mode", "sta")
280 encr:depends("mode", "wds")
281
282 server = s:option(Value, "server", translate("a_w_radiussrv"))
283 server:depends({mode="ap", encryption="wpa"})
284 server:depends({mode="ap", encryption="wpa2i"})
285 server.rmempty = true
286
287 port = s:option(Value, "port", translate("a_w_radiusport"))
288 port:depends({mode="ap", encryption="wpa"})
289 port:depends({mode="ap", encryption="wpa2i"})
290 port.rmempty = true
291
292 key = s:option(Value, "key", translate("key"))
293 key:depends("encryption", "wep")
294 key:depends("encryption", "psk")
295 key:depends({mode="ap", encryption="wpa"})
296 key:depends("encryption", "psk2")
297 key:depends({mode="ap", encryption="wpa2i"})
298 key.rmempty = true
299
300 if hwtype == "atheros" or hwtype == "mac80211" then
301         nasid = s:option(Value, "nasid", translate("a_w_nasid"))
302         nasid:depends({mode="ap", encryption="wpa"})
303         nasid:depends({mode="ap", encryption="wpa2i"})
304         nasid.rmempty = true
305
306         eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
307         eaptype:value("TLS")
308         eaptype:value("PEAP")
309         eaptype:depends({mode="sta", encryption="wpa"})
310         eaptype:depends({mode="sta", encryption="wpa2i"})
311
312         cacert = s:option(Value, "ca_cert", translate("a_w_cacert"))
313         cacert:depends({mode="sta", encryption="wpa"})
314         cacert:depends({mode="sta", encryption="wpa2i"})
315
316         privkey = s:option(Value, "priv_key", translate("a_w_tlsprivkey"))
317         privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
318         privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
319
320         privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
321         privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
322         privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
323
324
325         auth = s:option(Value, "auth", translate("a_w_peapauth"))
326         auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
327         auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
328
329         identity = s:option(Value, "identity", translate("a_w_peapidentity"))
330         identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
331         identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
332
333         password = s:option(Value, "password", translate("a_w_peappassword"))
334         password:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
335         password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
336 end
337
338
339 return m