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