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