2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
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
10 http://www.apache.org/licenses/LICENSE-2.0
14 require("luci.tools.webadmin")
17 m = Map("wireless", translate("networks"), translate("a_w_networks1"))
19 s = m:section(NamedSection, arg[1], "wifi-device", translate("device") .. " " .. arg[1])
22 back = s:option(DummyValue, "_overview", translate("overview"))
24 back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
27 en = s:option(Flag, "disabled", translate("enable"))
31 function en.cfgvalue(self, section)
32 return Flag.cfgvalue(self, section) or "0"
35 s:option(DummyValue, "type", translate("type"))
36 local hwtype = m:get(arg[1], "type")
38 ch = s:option(Value, "channel", translate("a_w_channel"))
40 ch:value(i, i .. " (2.4 GHz)")
43 ch:value(i, i .. " (5 GHz)")
46 ch:value(i, i .. " (5 GHz)")
48 ch:value(147, 147 .. " (5 GHz)")
49 ch:value(151, 151 .. " (5 GHz)")
50 ch:value(155, 155 .. " (5 GHz)")
51 ch:value(167, 167 .. " (5 GHz)")
53 ------------------- MAC80211 Device ------------------
55 if hwtype == "mac80211" then
60 ------------------- Madwifi Device ------------------
62 if hwtype == "atheros" then
63 mode = s:option(ListValue, "mode", translate("mode"))
64 mode:value("", translate("wifi_auto"))
65 mode:value("11b", "802.11b")
66 mode:value("11g", "802.11g")
67 mode:value("11a", "802.11a")
68 mode:value("11bg", "802.11b+g")
69 mode:value("11gdt", "802.11adt")
70 mode:value("11adt", "802.11adt")
71 mode:value("fh", translate("wifi_fh"))
73 s:option(Flag, "diversity", translate("wifi_diversity"))
74 s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
75 s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
76 s:option(Value, "distance", translate("wifi_distance"),
77 translate("wifi_distance_desc")).optional = true
79 --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
84 ------------------- Broadcom Device ------------------
86 if hwtype == "broadcom" then
87 mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
90 mp:value("deny", translate("wifi_whitelist"))
91 mp:value("allow", translate("wifi_blacklist"))
92 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
93 ml:depends({macfilter="allow"})
94 ml:depends({macfilter="deny"})
96 s:option(Value, "txant", translate("wifi_txantenna")).optional = true
97 s:option(Value, "rxant", translate("wifi_rxantenna")).optional = true
99 s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
101 s:option(Value, "distance", translate("wifi_distance")).optional = true
102 --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
104 s:option(Value, "country", translate("wifi_country")).optional = true
105 s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
109 ----------------------- Interface -----------------------
111 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
114 s:depends("device", arg[1])
115 s.defaults.device = arg[1]
117 s:option(Value, "ssid", translate("wifi_essid"))
119 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
120 network.rmempty = true
122 network.combobox_manual = translate("a_w_netmanual")
123 luci.tools.webadmin.cbi_add_networks(network)
125 function network.write(self, section, value)
126 if not m.uci:get("network", value) then
127 -- avoid "value not defined in enum" because network is not known yet
128 s.override_scheme = true
131 m.uci:set("network", value, "interface")
132 Value.write(self, section, value)
134 if m.uci:get("network", value) == "interface" then
135 Value.write(self, section, value)
141 mode = s:option(ListValue, "mode", translate("mode"))
142 mode.override_values = true
143 mode:value("ap", translate("a_w_ap"))
144 mode:value("adhoc", translate("a_w_adhoc"))
145 mode:value("sta", translate("a_w_client"))
147 bssid = s:option(Value, "bssid", translate("wifi_bssid"))
150 -------------------- MAC80211 Interface ----------------------
152 if hwtype == "mac80211" then
153 mode:value("monitor", translate("a_w_monitor"))
154 bssid:depends({mode="adhoc"})
156 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
157 s:option(Value, "frag", translate("wifi_frag")).optional = true
158 s:option(Value, "rts", translate("wifi_rts")).optional = true
163 -------------------- Madwifi Interface ----------------------
165 if hwtype == "atheros" then
166 mode:value("ahdemo", translate("a_w_ahdemo"))
167 mode:value("monitor", translate("a_w_monitor"))
169 bssid:depends({mode="adhoc"})
170 bssid:depends({mode="ahdemo"})
172 wds = s:option(Flag, "wds", translate("a_w_wds"))
173 wds:depends({mode="ap"})
174 wds:depends({mode="sta"})
176 wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
177 wdssep:depends({mode="ap", wds="1"})
178 wdssep.optional = true
180 s:option(Flag, "doth", "802.11h").optional = true
181 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
182 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
183 hidden:depends({mode="ap"})
184 hidden:depends({mode="adhoc"})
185 hidden:depends({mode="wds"})
186 hidden.optional = true
187 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
188 translate("wifi_isolate_desc"))
189 isolate:depends({mode="ap"})
190 isolate.optional = true
191 s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
193 mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
196 mp:value("deny", translate("wifi_whitelist"))
197 mp:value("allow", translate("wifi_blacklist"))
198 ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
199 ml:depends({macpolicy="allow"})
200 ml:depends({macpolicy="deny"})
202 s:option(Value, "rate", translate("wifi_rate")).optional = true
203 s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
204 s:option(Value, "frag", translate("wifi_frag")).optional = true
205 s:option(Value, "rts", translate("wifi_rts")).optional = true
206 s:option(Value, "minrate", translate("wifi_minrate")).optional = true
207 s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
208 s:option(Flag, "compression", translate("wifi_compression")).optional = true
210 s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
211 s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
212 s:option(Value, "ff", translate("wifi_ff")).optional = true
214 s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
215 s:option(Flag, "xr", translate("wifi_xr")).optional = true
216 s:option(Flag, "ar", translate("wifi_ar")).optional = true
220 -------------------- Broadcom Interface ----------------------
222 if hwtype == "broadcom" then
223 mode:value("wds", translate("a_w_wds"))
224 mode:value("monitor", translate("a_w_monitor"))
226 hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
227 hidden:depends({mode="ap"})
228 hidden:depends({mode="adhoc"})
229 hidden:depends({mode="wds"})
230 hidden.optional = true
232 isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
233 translate("wifi_isolate_desc"))
234 isolate:depends({mode="ap"})
235 isolate.optional = true
237 bssid:depends({mode="wds"})
242 ------------------- WiFI-Encryption -------------------
244 encr = s:option(ListValue, "encryption", translate("encryption"))
245 encr.override_values = true
246 encr:depends({mode="ap"})
247 encr:depends({mode="sta"})
248 encr:depends({mode="adhoc"})
249 encr:depends({mode="ahdemo"})
250 encr:depends({mode="wds"})
252 encr:value("none", "No Encryption")
253 encr:value("wep", "WEP")
255 if hwtype == "atheros" or hwtype == "mac80211" then
256 local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant")
257 local hostapd = luci.fs.mtime("/usr/sbin/hostapd")
259 if hostapd and supplicant then
260 encr:value("psk", "WPA-PSK")
261 encr:value("psk2", "WPA2-PSK")
262 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
263 encr:value("wpa2i", "WPA2-EAP", {mode="ap"}, {mode="sta"})
264 elseif hostapd and not supplicant then
265 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
266 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
267 encr:value("wpa", "WPA-EAP", {mode="ap"})
268 encr:value("wpa2i", "WPA2-EAP", {mode="ap"})
269 encr.description = translate("wifi_wpareq")
270 elseif not hostapd and supplicant then
271 encr:value("psk", "WPA-PSK", {mode="sta"})
272 encr:value("psk2", "WPA2-PSK", {mode="sta"})
273 encr:value("wpa", "WPA-EAP", {mode="sta"})
274 encr:value("wpa2i", "WPA2-EAP", {mode="sta"})
275 encr.description = translate("wifi_wpareq")
277 encr.description = translate("wifi_wpareq")
279 elseif hwtype == "broadcom" then
280 encr:value("psk", "WPA-PSK")
281 encr:value("psk2", "WPA2-PSK")
284 encr:depends("mode", "ap")
285 encr:depends("mode", "sta")
286 encr:depends("mode", "wds")
288 server = s:option(Value, "server", translate("a_w_radiussrv"))
289 server:depends({mode="ap", encryption="wpa"})
290 server:depends({mode="ap", encryption="wpa2i"})
291 server.rmempty = true
293 port = s:option(Value, "port", translate("a_w_radiusport"))
294 port:depends({mode="ap", encryption="wpa"})
295 port:depends({mode="ap", encryption="wpa2i"})
298 key = s:option(Value, "key", translate("key"))
299 key:depends("encryption", "wep")
300 key:depends("encryption", "psk")
301 key:depends({mode="ap", encryption="wpa"})
302 key:depends("encryption", "psk2")
303 key:depends({mode="ap", encryption="wpa2i"})
306 if hwtype == "atheros" or hwtype == "mac80211" then
307 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
308 nasid:depends({mode="ap", encryption="wpa"})
309 nasid:depends({mode="ap", encryption="wpa2i"})
312 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
314 eaptype:value("PEAP")
315 eaptype:depends({mode="sta", encryption="wpa"})
316 eaptype:depends({mode="sta", encryption="wpa2i"})
318 cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
319 cacert:depends({mode="sta", encryption="wpa"})
320 cacert:depends({mode="sta", encryption="wpa2i"})
322 privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
323 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
324 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
326 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
327 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2i"})
328 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
331 auth = s:option(Value, "auth", translate("a_w_peapauth"))
332 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
333 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
335 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
336 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
337 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
339 password = s:option(Value, "password", translate("a_w_peappassword"))
340 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2i"})
341 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})