Fix disabling of WiFi
[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 for i=1, 14 do
43         ch:value(i, i .. " (2.4 GHz)")
44 end
45 for i=36, 64, 4 do
46         ch:value(i, i .. " (5 GHz)")
47 end
48 for i=100, 140, 4 do
49         ch:value(i, i .. " (5 GHz)")
50 end
51 ch:value(147, 147 .. " (5 GHz)")
52 ch:value(151, 151 .. " (5 GHz)")
53 ch:value(155, 155 .. " (5 GHz)")
54 ch:value(167, 167 .. " (5 GHz)")
55
56 ------------------- MAC80211 Device ------------------
57
58 if hwtype == "mac80211" then
59
60 end
61
62
63 ------------------- Madwifi Device ------------------
64
65 if hwtype == "atheros" then
66         mode = s:option(ListValue, "hwmode", translate("mode"))
67         mode:value("", translate("wifi_auto"))
68         mode:value("11b", "802.11b")
69         mode:value("11g", "802.11g")
70         mode:value("11a", "802.11a")
71         mode:value("11bg", "802.11b+g")
72         mode:value("11gdt", "802.11adt")
73         mode:value("11adt", "802.11adt")
74         mode:value("fh", translate("wifi_fh"))
75
76         s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
77
78         if not nsantenna then
79                 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
80                 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
81         else -- NanoFoo
82                 local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
83                 ant:value("auto")
84                 ant:value("vertical")
85                 ant:value("horizontal")
86                 ant:value("external")
87         end
88         s:option(Value, "distance", translate("wifi_distance"),
89                 translate("wifi_distance_desc")).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         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 ----------------------- Interface -----------------------
122
123 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
124 s.addremove = true
125 s.anonymous = true
126 s:depends("device", arg[1])
127 s.defaults.device = arg[1]
128
129 s:option(Value, "ssid", translate("wifi_essid"))
130
131 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
132 network.rmempty = true
133 network:value("")
134 network.combobox_manual = translate("a_w_netmanual")
135 luci.tools.webadmin.cbi_add_networks(network)
136
137 function network.write(self, section, value)
138         if not m.uci:get("network", value) then
139                 -- avoid "value not defined in enum" because network is not known yet
140                 s.override_scheme = true
141
142                 m:chain("network")
143                 m.uci:set("network", value, "interface")
144                 Value.write(self, section, value)
145         else
146                 if m.uci:get("network", value) == "interface" then
147                         Value.write(self, section, value)
148                 end
149         end
150 end
151
152
153 mode = s:option(ListValue, "mode", translate("mode"))
154 mode.override_values = true
155 mode:value("ap", translate("a_w_ap"))
156 mode:value("adhoc", translate("a_w_adhoc"))
157 mode:value("sta", translate("a_w_client"))
158
159 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
160
161
162 -------------------- MAC80211 Interface ----------------------
163
164 if hwtype == "mac80211" then
165         mode:value("ahdemo", translate("a_w_ahdemo"))
166         mode:value("monitor", translate("a_w_monitor"))
167         bssid:depends({mode="adhoc"})
168
169         s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
170         s:option(Value, "frag", translate("wifi_frag")).optional = true
171         s:option(Value, "rts", translate("wifi_rts")).optional = true
172 end
173
174
175
176 -------------------- Madwifi Interface ----------------------
177
178 if hwtype == "atheros" then
179         mode:value("ahdemo", translate("a_w_ahdemo"))
180         mode:value("monitor", translate("a_w_monitor"))
181
182         bssid:depends({mode="adhoc"})
183         bssid:depends({mode="ahdemo"})
184
185         wds = s:option(Flag, "wds", translate("a_w_wds"))
186         wds:depends({mode="ap"})
187         wds:depends({mode="sta"})
188         wds.rmempty = true
189         wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
190         wdssep:depends({mode="ap", wds="1"})
191         wdssep.optional = true
192
193         s:option(Flag, "doth", "802.11h").optional = true
194         s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
195         hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
196         hidden:depends({mode="ap"})
197         hidden:depends({mode="adhoc"})
198         hidden:depends({mode="wds"})
199         hidden.optional = true
200         isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
201          translate("wifi_isolate_desc"))
202         isolate:depends({mode="ap"})
203         isolate.optional = true
204         s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
205
206         mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
207         mp.optional = true
208         mp:value("")
209         mp:value("deny", translate("wifi_whitelist"))
210         mp:value("allow", translate("wifi_blacklist"))
211         ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
212         ml:depends({macpolicy="allow"})
213         ml:depends({macpolicy="deny"})
214
215         s:option(Value, "rate", translate("wifi_rate")).optional = true
216         s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
217         s:option(Value, "frag", translate("wifi_frag")).optional = true
218         s:option(Value, "rts", translate("wifi_rts")).optional = true
219         s:option(Value, "minrate", translate("wifi_minrate")).optional = true
220         s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
221         s:option(Flag, "compression", translate("wifi_compression")).optional = true
222
223         s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
224         s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
225         s:option(Value, "ff", translate("wifi_ff")).optional = true
226
227         s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
228         s:option(Flag, "xr", translate("wifi_xr")).optional = true
229         s:option(Flag, "ar", translate("wifi_ar")).optional = true
230
231         local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
232         swm:depends({mode="adhoc"})
233         swm.optional = true
234
235         local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
236         nos:depends({mode="sta"})
237         nos.optional = true
238
239         local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
240         probereq.optional = true
241         probereq.enabled  = "0"
242         probereq.disabled = "1"
243 end
244
245
246 -------------------- Broadcom Interface ----------------------
247
248 if hwtype == "broadcom" then
249         mode:value("wds", translate("a_w_wds"))
250         mode:value("monitor", translate("a_w_monitor"))
251
252         s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
253
254         hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
255         hidden:depends({mode="ap"})
256         hidden:depends({mode="adhoc"})
257         hidden:depends({mode="wds"})
258         hidden.optional = true
259
260         isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
261          translate("wifi_isolate_desc"))
262         isolate:depends({mode="ap"})
263         isolate.optional = true
264
265         bssid:depends({mode="wds"})
266 end
267
268
269
270 ------------------- WiFI-Encryption -------------------
271
272 encr = s:option(ListValue, "encryption", translate("encryption"))
273 encr.override_values = true
274 encr:depends({mode="ap"})
275 encr:depends({mode="sta"})
276 encr:depends({mode="adhoc"})
277 encr:depends({mode="ahdemo"})
278 encr:depends({mode="wds"})
279
280 encr:value("none", "No Encryption")
281 encr:value("wep", "WEP")
282
283 if hwtype == "atheros" or hwtype == "mac80211" then
284         local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
285         local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
286
287         if hostapd and supplicant then
288                 encr:value("psk", "WPA-PSK")
289                 encr:value("psk2", "WPA2-PSK")
290                 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
291                 encr:value("wpa2i", "WPA2-EAP", {mode="ap"}, {mode="sta"})
292         elseif hostapd and not supplicant then
293                 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
294                 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
295                 encr:value("wpa", "WPA-EAP", {mode="ap"})
296                 encr:value("wpa2i", "WPA2-EAP", {mode="ap"})
297                 encr.description = translate("wifi_wpareq")
298         elseif not hostapd and supplicant then
299                 encr:value("psk", "WPA-PSK", {mode="sta"})
300                 encr:value("psk2", "WPA2-PSK", {mode="sta"})
301                 encr:value("wpa", "WPA-EAP", {mode="sta"})
302                 encr:value("wpa2i", "WPA2-EAP", {mode="sta"})
303                 encr.description = translate("wifi_wpareq")
304         else
305                 encr.description = translate("wifi_wpareq")
306         end
307 elseif hwtype == "broadcom" then
308         encr:value("psk", "WPA-PSK")
309         encr:value("psk2", "WPA2-PSK")
310 end
311
312 encr:depends("mode", "ap")
313 encr:depends("mode", "sta")
314 encr:depends("mode", "wds")
315
316 server = s:option(Value, "server", translate("a_w_radiussrv"))
317 server:depends({mode="ap", encryption="wpa"})
318 server:depends({mode="ap", encryption="wpa2i"})
319 server.rmempty = true
320
321 port = s:option(Value, "port", translate("a_w_radiusport"))
322 port:depends({mode="ap", encryption="wpa"})
323 port:depends({mode="ap", encryption="wpa2i"})
324 port.rmempty = true
325
326 key = s:option(Value, "key", translate("key"))
327 key:depends("encryption", "wep")
328 key:depends("encryption", "psk")
329 key:depends({mode="ap", encryption="wpa"})
330 key:depends("encryption", "psk2")
331 key:depends({mode="ap", encryption="wpa2i"})
332 key.rmempty = true
333
334 if hwtype == "atheros" or hwtype == "mac80211" then
335         nasid = s:option(Value, "nasid", translate("a_w_nasid"))
336         nasid:depends({mode="ap", encryption="wpa"})
337         nasid:depends({mode="ap", encryption="wpa2i"})
338         nasid.rmempty = true
339
340         eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
341         eaptype:value("TLS")
342         eaptype:value("PEAP")
343         eaptype:depends({mode="sta", encryption="wpa"})
344         eaptype:depends({mode="sta", encryption="wpa2i"})
345
346         cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
347         cacert:depends({mode="sta", encryption="wpa"})
348         cacert:depends({mode="sta", encryption="wpa2i"})
349
350         privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
351         privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
352         privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
353
354         privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
355         privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
356         privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
357
358
359         auth = s:option(Value, "auth", translate("a_w_peapauth"))
360         auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
361         auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
362
363         identity = s:option(Value, "identity", translate("a_w_peapidentity"))
364         identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
365         identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
366
367         password = s:option(Value, "password", translate("a_w_peappassword"))
368         password:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
369         password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
370 end
371
372
373 return m