a1d676ac0aedb987a692066de3953715c78dd7ef
[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 = true
21
22 en = s:option(Flag, "disabled", translate("enable"))
23 en.enabled = "0"
24 en.disabled = "1"
25
26 function en.cfgvalue(self, section)
27         return Flag.cfgvalue(self, section) or "0"
28 end
29
30 s:option(DummyValue, "type", translate("type"))
31 local hwtype = m:get(arg[1], "type")
32
33 mode = s:option(ListValue, "mode", translate("mode"))
34 mode:value("", "standard")
35 mode:value("11b", "802.11b")
36 mode:value("11g", "802.11g")
37 mode:value("11a", "802.11a")
38 mode:value("11bg", "802.11b+g")
39
40 if hwtype == "atheros" then
41         mode:value("11gdt", "802.11adt")
42         mode:value("11adt", "802.11adt")
43         mode:value("fh", "fh")
44 end
45
46
47 mode.rmempty = true
48
49 ch = s:option(Value, "channel", translate("a_w_channel"))
50 for i=1, 14 do
51         ch:value(i, i .. " (2.4 GHz)")
52 end
53 for i=36, 64, 4 do
54         ch:value(i, i .. " (5 GHz)")
55 end
56 for i=100, 140, 4 do
57         ch:value(i, i .. " (5 GHz)")
58 end
59 ch:value(147, 147 .. " (5 GHz)")
60 ch:value(151, 151 .. " (5 GHz)")
61 ch:value(155, 155 .. " (5 GHz)")
62 ch:value(167, 167 .. " (5 GHz)")
63
64 s:option(Value, "txantenna", translate("a_w_txantenna")).optional = true
65
66 s:option(Value, "rxantenna", translate("a_w_rxantenna")).optional = true
67
68 s:option(Value, "distance", translate("distance"),
69         translate("a_w_distance1")).optional = true
70
71 s:option(Value, "diversity", translate("a_w_diversity")):depends("type", "atheros")
72         
73 country = s:option(Value, "country", translate("a_w_countrycode"))
74 country.optional = true
75 country:depends("type", "broadcom")
76
77 maxassoc = s:option(Value, "maxassoc", translate("a_w_connlimit"))
78 maxassoc:depends("type", "broadcom")
79 maxassoc.optional = true
80
81
82
83 ----------------------- Interface -----------------------
84
85 s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
86 s.addremove = true
87 s.anonymous = true
88 s:depends("device", arg[1])
89 s.defaults.device = arg[1]
90
91 s:option(Value, "ssid", translate("a_w_netid")).maxlength = 32
92
93 network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
94 network.rmempty = true
95 network:value("")
96 network.combobox_manual = translate("a_w_netmanual")
97 luci.tools.webadmin.cbi_add_networks(network)
98
99 function network.write(self, section, value)    
100         if not m.uci:get("network", value) then 
101                 m:chain("network")
102                 m.uci:set("network", value, "interface")
103                 Value.write(self, section, value)
104         else
105                 if m.uci:get("network", value) == "interface" then
106                         Value.write(self, section, value)
107                 end
108         end
109 end
110
111 mode = s:option(ListValue, "mode", translate("mode"))
112 mode:value("ap", translate("a_w_ap"))
113 mode:value("adhoc", translate("a_w_adhoc"))
114 mode:value("ahdemo", translate("a_w_ahdemo"))
115 mode:value("sta", translate("a_w_client"))
116 mode:value("monitor", translate("a_w_monitor"))
117
118 if hwtype ~= "atheros" then
119         mode:value("wds", translate("a_w_wds"))
120 end
121
122 if hwtype == "atheros" then
123         s:option(Flag, "wds", translate("a_w_wds"))
124 end
125
126 s:option(Value, "bssid", "BSSID").optional = true
127
128 s:option(Value, "txpower", translate("a_w_txpwr"), "dbm").rmempty = true
129
130 s:option(Flag, "frameburst", translate("a_w_brcmburst")).optional = true
131 s:option(Flag, "bursting", translate("a_w_athburst")).optional = true
132
133
134 encr = s:option(ListValue, "encryption", translate("encryption"))
135 encr:value("none", "keine")
136 encr:value("wep", "WEP")
137 encr:value("PSK", "WPA-PSK")
138 encr:value("WPA", "WPA-EAP", {mode="ap"}, {mode="sta"})
139 encr:value("PSK2", "WPA2-PSK")
140 encr:value("WPA2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
141 encr:depends("mode", "ap")
142 encr:depends("mode", "sta")
143 encr:depends("mode", "wds")
144
145 server = s:option(Value, "server", translate("a_w_radiussrv"))
146 server:depends({mode="ap", encryption="WPA"})
147 server:depends({mode="ap", encryption="WPA2"})
148 server.rmempty = true
149
150 port = s:option(Value, "port", translate("a_w_radiusport"))
151 port:depends({mode="ap", encryption="WPA"})
152 port:depends({mode="ap", encryption="WPA2"})
153 port.rmempty = true
154
155 key = s:option(Value, "key", translate("key"))
156 key:depends("encryption", "wep")
157 key:depends("encryption", "PSK")
158 key:depends({mode="ap", encryption="WPA"})
159 key:depends("encryption", "PSK2")
160 key:depends({mode="ap", encryption="WPA2"})
161 key.rmempty = true
162
163 nasid = s:option(Value, "nasid", translate("a_w_nasid"))
164 nasid:depends({mode="ap", encryption="WPA"})
165 nasid:depends({mode="ap", encryption="WPA2"})
166 nasid.rmempty = true
167
168 eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
169 eaptype:value("TLS")
170 eaptype:value("PEAP")
171 eaptype:depends({mode="sta", encryption="WPA"})
172 eaptype:depends({mode="sta", encryption="WPA2"})
173
174 cacert = s:option(Value, "ca_cert", translate("a_w_cacert"))
175 cacert:depends({mode="sta", encryption="WPA"})
176 cacert:depends({mode="sta", encryption="WPA2"})
177
178 privkey = s:option(Value, "priv_key", translate("a_w_tlsprivkey"))
179 privkey:depends({mode="sta", eap_type="TLS", encryption="WPA2"})
180 privkey:depends({mode="sta", eap_type="TLS", encryption="WPA"})
181
182 privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
183 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="WPA2"})
184 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="WPA"})
185
186
187 auth = s:option(Value, "auth", translate("a_w_peapauth"))
188 auth:depends({mode="sta", eap_type="PEAP", encryption="WPA2"})
189 auth:depends({mode="sta", eap_type="PEAP", encryption="WPA"})
190
191 identity = s:option(Value, "identity", translate("a_w_peapidentity"))
192 identity:depends({mode="sta", eap_type="PEAP", encryption="WPA2"})
193 identity:depends({mode="sta", eap_type="PEAP", encryption="WPA"})
194
195 password = s:option(Value, "password", translate("a_w_peappassword"))
196 password:depends({mode="sta", eap_type="PEAP", encryption="WPA2"})
197 password:depends({mode="sta", eap_type="PEAP", encryption="WPA"})
198
199
200
201
202 s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1")).optional = true
203
204 s:option(Flag, "hidden", translate("a_w_hideessid")).optional = true
205
206
207
208 return m