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