fa3ad753b31ee4149b373079801d73599cfd2cee
[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, "txant", translate("wifi_txantenna")).optional = true
108 s:option(Value, "rxant", translate("wifi_rxantenna")).optional = true
109
110 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
111
112 s:option(Value, "distance", translate("wifi_distance")).optional = true
113 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
114
115 s:option(Value, "country", translate("wifi_country")).optional = true
116 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
117 end
118
119
120 ----------------------- Interface -----------------------
121
122 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
123 s.addremove = true
124 s.anonymous = true
125 s:depends("device", arg[1])
126 s.defaults.device = arg[1]
127
128 s:option(Value, "ssid", translate("wifi_essid"))
129
130 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
131 network.rmempty = true
132 network:value("")
133 network.combobox_manual = translate("a_w_netmanual")
134 luci.tools.webadmin.cbi_add_networks(network)
135
136 function network.write(self, section, value)
137 if not m.uci:get("network", value) then
138 -- avoid "value not defined in enum" because network is not known yet
139 s.override_scheme = true
140
141 m:chain("network")
142 m.uci:set("network", value, "interface")
143 Value.write(self, section, value)
144 else
145 if m.uci:get("network", value) == "interface" then
146 Value.write(self, section, value)
147 end
148 end
149 end
150
151
152 mode = s:option(ListValue, "mode", translate("mode"))
153 mode.override_values = true
154 mode:value("ap", translate("a_w_ap"))
155 mode:value("adhoc", translate("a_w_adhoc"))
156 mode:value("sta", translate("a_w_client"))
157
158 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
159
160
161 -------------------- MAC80211 Interface ----------------------
162
163 if hwtype == "mac80211" then
164 mode:value("monitor", translate("a_w_monitor"))
165 bssid:depends({mode="adhoc"})
166
167 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
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 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
193 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
194 hidden:depends({mode="ap"})
195 hidden:depends({mode="adhoc"})
196 hidden:depends({mode="wds"})
197 hidden.optional = true
198 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
199 translate("wifi_isolate_desc"))
200 isolate:depends({mode="ap"})
201 isolate.optional = true
202 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
203
204 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
205 mp.optional = true
206 mp:value("")
207 mp:value("deny", translate("wifi_whitelist"))
208 mp:value("allow", translate("wifi_blacklist"))
209 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
210 ml:depends({macpolicy="allow"})
211 ml:depends({macpolicy="deny"})
212
213 s:option(Value, "rate", translate("wifi_rate")).optional = true
214 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
215 s:option(Value, "frag", translate("wifi_frag")).optional = true
216 s:option(Value, "rts", translate("wifi_rts")).optional = true
217 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
218 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
219 s:option(Flag, "compression", translate("wifi_compression")).optional = true
220
221 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
222 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
223 s:option(Value, "ff", translate("wifi_ff")).optional = true
224
225 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
226 s:option(Flag, "xr", translate("wifi_xr")).optional = true
227 s:option(Flag, "ar", translate("wifi_ar")).optional = true
228 end
229
230
231 -------------------- Broadcom Interface ----------------------
232
233 if hwtype == "broadcom" then
234 mode:value("wds", translate("a_w_wds"))
235 mode:value("monitor", translate("a_w_monitor"))
236
237 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
238 hidden:depends({mode="ap"})
239 hidden:depends({mode="adhoc"})
240 hidden:depends({mode="wds"})
241 hidden.optional = true
242
243 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
244 translate("wifi_isolate_desc"))
245 isolate:depends({mode="ap"})
246 isolate.optional = true
247
248 bssid:depends({mode="wds"})
249 end
250
251
252
253 ------------------- WiFI-Encryption -------------------
254
255 encr = s:option(ListValue, "encryption", translate("encryption"))
256 encr.override_values = true
257 encr:depends({mode="ap"})
258 encr:depends({mode="sta"})
259 encr:depends({mode="adhoc"})
260 encr:depends({mode="ahdemo"})
261 encr:depends({mode="wds"})
262
263 encr:value("none", "No Encryption")
264 encr:value("wep", "WEP")
265
266 if hwtype == "atheros" or hwtype == "mac80211" then
267 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
268 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
269
270 if hostapd and supplicant then
271 encr:value("psk", "WPA-PSK")
272 encr:value("psk2", "WPA2-PSK")
273 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
274 encr:value("wpa2i", "WPA2-EAP", {mode="ap"}, {mode="sta"})
275 elseif hostapd and not supplicant then
276 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
277 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
278 encr:value("wpa", "WPA-EAP", {mode="ap"})
279 encr:value("wpa2i", "WPA2-EAP", {mode="ap"})
280 encr.description = translate("wifi_wpareq")
281 elseif not hostapd and supplicant then
282 encr:value("psk", "WPA-PSK", {mode="sta"})
283 encr:value("psk2", "WPA2-PSK", {mode="sta"})
284 encr:value("wpa", "WPA-EAP", {mode="sta"})
285 encr:value("wpa2i", "WPA2-EAP", {mode="sta"})
286 encr.description = translate("wifi_wpareq")
287 else
288 encr.description = translate("wifi_wpareq")
289 end
290 elseif hwtype == "broadcom" then
291 encr:value("psk", "WPA-PSK")
292 encr:value("psk2", "WPA2-PSK")
293 end
294
295 encr:depends("mode", "ap")
296 encr:depends("mode", "sta")
297 encr:depends("mode", "wds")
298
299 server = s:option(Value, "server", translate("a_w_radiussrv"))
300 server:depends({mode="ap", encryption="wpa"})
301 server:depends({mode="ap", encryption="wpa2i"})
302 server.rmempty = true
303
304 port = s:option(Value, "port", translate("a_w_radiusport"))
305 port:depends({mode="ap", encryption="wpa"})
306 port:depends({mode="ap", encryption="wpa2i"})
307 port.rmempty = true
308
309 key = s:option(Value, "key", translate("key"))
310 key:depends("encryption", "wep")
311 key:depends("encryption", "psk")
312 key:depends({mode="ap", encryption="wpa"})
313 key:depends("encryption", "psk2")
314 key:depends({mode="ap", encryption="wpa2i"})
315 key.rmempty = true
316
317 if hwtype == "atheros" or hwtype == "mac80211" then
318 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
319 nasid:depends({mode="ap", encryption="wpa"})
320 nasid:depends({mode="ap", encryption="wpa2i"})
321 nasid.rmempty = true
322
323 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
324 eaptype:value("TLS")
325 eaptype:value("PEAP")
326 eaptype:depends({mode="sta", encryption="wpa"})
327 eaptype:depends({mode="sta", encryption="wpa2i"})
328
329 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
330 cacert:depends({mode="sta", encryption="wpa"})
331 cacert:depends({mode="sta", encryption="wpa2i"})
332
333 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
334 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
335 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
336
337 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
338 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
339 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
340
341
342 auth = s:option(Value, "auth", translate("a_w_peapauth"))
343 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
344 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
345
346 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
347 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
348 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
349
350 password = s:option(Value, "password", translate("a_w_peappassword"))
351 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
352 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
353 end
354
355
356 return m