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