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