admin-full: Override UVL values for mode field
[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.override_values = true
138 mode:value("ap", translate("a_w_ap"))
139 mode:value("adhoc", translate("a_w_adhoc"))
140 mode:value("sta", translate("a_w_client"))
141
142 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
143
144
145 -------------------- MAC80211 Interface ----------------------
146
147 if hwtype == "mac80211" then
148 mode:value("monitor", translate("a_w_monitor"))
149 bssid:depends({mode="adhoc"})
150
151 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
152 s:option(Value, "frag", translate("wifi_frag")).optional = true
153 s:option(Value, "rts", translate("wifi_rts")).optional = true
154 end
155
156
157
158 -------------------- Madwifi Interface ----------------------
159
160 if hwtype == "atheros" then
161 mode:value("ahdemo", translate("a_w_ahdemo"))
162 mode:value("monitor", translate("a_w_monitor"))
163
164 bssid:depends({mode="adhoc"})
165 bssid:depends({mode="ahdemo"})
166
167 wds = s:option(Flag, "wds", translate("a_w_wds"))
168 wds:depends({mode="ap"})
169 wds:depends({mode="sta"})
170 wds.rmempty = true
171 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
172 wdssep:depends({mode="ap", wds="1"})
173 wdssep.optional = true
174
175 s:option(Flag, "doth", "802.11h").optional = true
176 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
177 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
178 hidden:depends({mode="ap"})
179 hidden:depends({mode="adhoc"})
180 hidden:depends({mode="wds"})
181 hidden.optional = true
182 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
183 translate("wifi_isolate_desc"))
184 isolate:depends({mode="ap"})
185 isolate.optional = true
186 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
187
188 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
189 mp.optional = true
190 mp:value("")
191 mp:value("deny", translate("wifi_whitelist"))
192 mp:value("allow", translate("wifi_blacklist"))
193 ml = s:option(Value, "maclist", translate("wifi_maclist"))
194 ml:depends({macpolicy="allow"})
195 ml:depends({macpolicy="deny"})
196
197 s:option(Value, "rate", translate("wifi_rate")).optional = true
198 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
199 s:option(Value, "frag", translate("wifi_frag")).optional = true
200 s:option(Value, "rts", translate("wifi_rts")).optional = true
201 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
202 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
203 s:option(Flag, "compression", translate("wifi_compression")).optional = true
204
205 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
206 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
207 s:option(Value, "ff", translate("wifi_ff")).optional = true
208
209 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
210 s:option(Flag, "xr", translate("wifi_xr")).optional = true
211 s:option(Flag, "ar", translate("wifi_ar")).optional = true
212 end
213
214
215 -------------------- Broadcom Interface ----------------------
216
217 if hwtype == "broadcom" then
218 mode:value("wds", translate("a_w_wds"))
219 mode:value("monitor", translate("a_w_monitor"))
220
221 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
222 hidden:depends({mode="ap"})
223 hidden:depends({mode="adhoc"})
224 hidden:depends({mode="wds"})
225 hidden.optional = true
226
227 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
228 translate("wifi_isolate_desc"))
229 isolate:depends({mode="ap"})
230 isolate.optional = true
231
232 bssid:depends({mode="wds"})
233 end
234
235
236
237 ------------------- WiFI-Encryption -------------------
238
239 encr = s:option(ListValue, "encryption", translate("encryption"))
240 encr.override_values = true
241 encr:depends({mode="ap"})
242 encr:depends({mode="sta"})
243 encr:depends({mode="adhoc"})
244 encr:depends({mode="ahdemo"})
245 encr:depends({mode="wds"})
246
247 encr:value("none", "No Encryption")
248 encr:value("wep", "WEP")
249
250 if hwtype == "atheros" or hwtype == "mac80211" then
251 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
252 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
253
254 if hostapd and supplicant then
255 encr:value("psk", "WPA-PSK")
256 encr:value("psk2", "WPA2-PSK")
257 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
258 encr:value("wpa2i", "WPA2-EAP", {mode="ap"}, {mode="sta"})
259 elseif hostapd and not supplicant then
260 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
261 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
262 encr:value("wpa", "WPA-EAP", {mode="ap"})
263 encr:value("wpa2i", "WPA2-EAP", {mode="ap"})
264 encr.description = translate("wifi_wpareq")
265 elseif not hostapd and supplicant then
266 encr:value("psk", "WPA-PSK", {mode="sta"})
267 encr:value("psk2", "WPA2-PSK", {mode="sta"})
268 encr:value("wpa", "WPA-EAP", {mode="sta"})
269 encr:value("wpa2i", "WPA2-EAP", {mode="sta"})
270 encr.description = translate("wifi_wpareq")
271 else
272 encr.description = translate("wifi_wpareq")
273 end
274 elseif hwtype == "broadcom" then
275 encr:value("psk", "WPA-PSK")
276 encr:value("psk2", "WPA2-PSK")
277 end
278
279 encr:depends("mode", "ap")
280 encr:depends("mode", "sta")
281 encr:depends("mode", "wds")
282
283 server = s:option(Value, "server", translate("a_w_radiussrv"))
284 server:depends({mode="ap", encryption="wpa"})
285 server:depends({mode="ap", encryption="wpa2i"})
286 server.rmempty = true
287
288 port = s:option(Value, "port", translate("a_w_radiusport"))
289 port:depends({mode="ap", encryption="wpa"})
290 port:depends({mode="ap", encryption="wpa2i"})
291 port.rmempty = true
292
293 key = s:option(Value, "key", translate("key"))
294 key:depends("encryption", "wep")
295 key:depends("encryption", "psk")
296 key:depends({mode="ap", encryption="wpa"})
297 key:depends("encryption", "psk2")
298 key:depends({mode="ap", encryption="wpa2i"})
299 key.rmempty = true
300
301 if hwtype == "atheros" or hwtype == "mac80211" then
302 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
303 nasid:depends({mode="ap", encryption="wpa"})
304 nasid:depends({mode="ap", encryption="wpa2i"})
305 nasid.rmempty = true
306
307 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
308 eaptype:value("TLS")
309 eaptype:value("PEAP")
310 eaptype:depends({mode="sta", encryption="wpa"})
311 eaptype:depends({mode="sta", encryption="wpa2i"})
312
313 cacert = s:option(Value, "ca_cert", translate("a_w_cacert"))
314 cacert:depends({mode="sta", encryption="wpa"})
315 cacert:depends({mode="sta", encryption="wpa2i"})
316
317 privkey = s:option(Value, "priv_key", translate("a_w_tlsprivkey"))
318 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
319 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
320
321 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
322 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
323 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
324
325
326 auth = s:option(Value, "auth", translate("a_w_peapauth"))
327 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
328 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
329
330 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
331 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
332 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
333
334 password = s:option(Value, "password", translate("a_w_peappassword"))
335 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
336 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
337 end
338
339
340 return m