AP configuration
[project/luci.git] / modules / niu / luasrc / model / cbi / niu / wireless / ap1.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2009 Steven Barth <steven@midlink.org>
5 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 local fs = require "nixio.fs"
17 local sys = require "luci.sys"
18 local cursor = require "luci.model.uci".inst
19 local state = require "luci.model.uci".inst_state
20 cursor:unload("wireless")
21
22 local device = cursor:get("wireless", "ap", "device")
23 local hwtype = cursor:get("wireless", device, "type")
24
25 local nsantenna = cursor:get("wireless", device, "antenna")
26
27 local iw = nil
28 local tx_powers = nil
29 local chan = sys.wifi.channels()
30
31 state:foreach("wireless", "wifi-iface",
32 function(s)
33 if s.device == device and not iw then
34 iw = sys.wifi.getiwinfo(s.ifname or s.device)
35 chan = sys.wifi.channels(s.ifname or s.device)
36 tx_powers = iw.txpwrlist or { }
37 end
38 end)
39
40 m = Map("wireless", "Configure Access Point",
41 "The private Access Point is about to be created. You only need to provide "..
42 "a network name and a password to finish this step and - if you like - tweak "..
43 "some of the advanced settings.")
44
45 --- Device Settings ---
46 s = m:section(NamedSection, device, "wifi-device", "Device Configuration")
47 s.addremove = false
48
49 s:tab("general", translate("General Settings"))
50
51 ch = s:taboption("general", Value, "channel", translate("Channel"))
52 ch:value("auto", translate("automatic"))
53 for _, f in ipairs(chan) do
54 ch:value(f.channel, "%i (%.3f GHz)" %{ f.channel, f.mhz })
55 end
56
57
58
59 s:tab("expert", translate("Expert Settings"))
60 if hwtype == "mac80211" then
61 tp = s:taboption("expert",
62 (tx_powers and #tx_powers > 0) and ListValue or Value,
63 "txpower", translate("Transmission Power"), "dBm")
64
65 tp.rmempty = true
66 tp:value("", translate("automatic"))
67 for _, p in ipairs(iw and iw.txpwrlist or {}) do
68 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
69 end
70 elseif hwtype == "atheros" then
71 tp = s:taboption("expert",
72 (#tx_powers > 0) and ListValue or Value,
73 "txpower", translate("Transmission Power"), "dBm")
74
75 tp.rmempty = true
76 tp:value("", translate("automatic"))
77 for _, p in ipairs(iw.txpwrlist) do
78 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
79 end
80
81 mode = s:taboption("expert", ListValue, "hwmode", translate("Communication Protocol"))
82 mode:value("", translate("automatic"))
83 mode:value("11g", "802.11g")
84 mode:value("11b", "802.11b")
85 mode:value("11bg", "802.11b+g")
86 mode:value("11a", "802.11a")
87 mode:value("11gst", "802.11g + Turbo")
88 mode:value("11ast", "802.11a + Turbo")
89
90 if nsantenna then -- NanoFoo
91 local ant = s:taboption("expert", ListValue, "antenna", translate("Transmitter Antenna"))
92 ant:value("auto")
93 ant:value("vertical")
94 ant:value("horizontal")
95 ant:value("external")
96 ant.default = "auto"
97 end
98 elseif hwtype == "broadcom" then
99 tp = s:taboption("expert",
100 (#tx_powers > 0) and ListValue or Value,
101 "txpower", translate("Transmit Power"), "dBm")
102
103 tp.rmempty = true
104 tp:value("", translate("automatic"))
105 for _, p in ipairs(iw.txpwrlist) do
106 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
107 end
108
109 mp = s:taboption("expert", ListValue, "macfilter", translate("MAC-Address Filter"))
110 mp:value("", translate("disable"))
111 mp:value("allow", translate("Allow listed only"))
112 mp:value("deny", translate("Allow all except listed"))
113 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
114 ml:depends({macfilter="allow"})
115 ml:depends({macfilter="deny"})
116
117 s:taboption("expert", Flag, "frameburst", translate("Allow Burst Transmissions"))
118 elseif hwtype == "prism2" then
119 s:taboption("expert", Value, "txpower", translate("Transmission Power"), "att units").rmempty = true
120 end
121
122
123
124
125 s = m:section(NamedSection, "ap", "wifi-iface", "Access Point Details")
126 s.addremove = false
127
128 s:tab("general", translate("General Settings"))
129 s:tab("expert", translate("Expert Settings"))
130
131 s:taboption("general", Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
132
133 mode = s:taboption("expert", ListValue, "mode", translate("Operating Mode"))
134 mode.override_values = true
135 mode:value("ap", translate("Access Point"))
136
137 encr = s:taboption("expert", ListValue, "encryption", translate("Encryption"))
138
139
140 if hwtype == "mac80211" then
141 -- Empty
142 elseif hwtype == "atheros" then
143 mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
144 mode:value("wds", translate("Static WDS"))
145
146 function mode.write(self, section, value)
147 if value == "ap-wds" then
148 ListValue.write(self, section, "ap")
149 self.map:set(section, "wds", 1)
150 else
151 ListValue.write(self, section, value)
152 self.map:del(section, "wds")
153 end
154 end
155
156 function mode.cfgvalue(self, section)
157 local mode = ListValue.cfgvalue(self, section)
158 local wds = self.map:get(section, "wds") == "1"
159 return mode == "ap" and wds and "ap-wds" or mode
160 end
161
162 mp = s:taboption("expert", ListValue, "macpolicy", translate("MAC-Address Filter"))
163 mp:value("", translate("disable"))
164 mp:value("deny", translate("Allow listed only"))
165 mp:value("allow", translate("Allow all except listed"))
166 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
167 ml:depends({macpolicy="allow"})
168 ml:depends({macpolicy="deny"})
169
170
171 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
172 hidden:depends({mode="ap"})
173 hidden:depends({mode="ap-wds"})
174
175 isolate = s:taboption("expert", Flag, "isolate", translate("Prevent communication between clients"))
176 isolate:depends({mode="ap"})
177
178 s:taboption("expert", Flag, "bursting", translate("Allow Burst Transmissions"))
179 elseif hwtype == "broadcom" then
180 mode:value("wds", translate("WDS"))
181
182 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
183 hidden:depends({mode="ap"})
184 hidden:depends({mode="wds"})
185
186 isolate = s:taboption("expert", Flag, "isolate", translate("Prevent communication between clients"))
187 isolate:depends({mode="ap"})
188 elseif hwtype == "prism2" then
189 mode:value("wds", translate("WDS"))
190
191 mp = s:taboption("expert", ListValue, "macpolicy", translate("MAC-Address Filter"))
192 mp:value("", translate("disable"))
193 mp:value("deny", translate("Allow listed only"))
194 mp:value("allow", translate("Allow all except listed"))
195
196 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
197 ml:depends({macpolicy="allow"})
198 ml:depends({macpolicy="deny"})
199
200 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
201 hidden:depends({mode="ap"})
202 hidden:depends({mode="wds"})
203 end
204
205 -- Encryption --
206
207
208 encr.override_values = true
209 encr.override_depends = true
210 encr:value("none", "No Encryption")
211 encr:value("wep", "WEP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"})
212
213 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
214 local hostapd = fs.access("/usr/sbin/hostapd") or os.getenv("LUCI_SYSROOT")
215
216 if hostapd then
217 --s:taboption("expert", Flag, "_alloweap", "Allow EAP / 802.11i authentication")
218
219 encr:value("psk", "WPA", {mode="ap"}, {mode="ap-wds"})
220 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="ap-wds"})
221 encr:value("psk-mixed", "WPA + WPA2", {mode="ap"}, {mode="ap-wds"})
222 encr:value("psk2", "WPA2", {mode="ap"}, {mode="ap-wds"})
223 encr:value("wpa2", "WPA2-EAP (802.11i)", {mode="ap"}, {mode="ap-wds"})
224 encr.default = "psk-mixed"
225 end
226 elseif hwtype == "broadcom" then
227 encr:value("psk", "WPA")
228 encr:value("psk+psk2", "WPA + WPA2")
229 encr:value("psk2", "WPA2")
230 encr.default = "psk+psk2"
231 end
232
233 server = s:taboption("general", Value, "server", translate("Radius-Server"))
234 server:depends({mode="ap", encryption="wpa"})
235 server:depends({mode="ap", encryption="wpa2"})
236 server:depends({mode="ap-wds", encryption="wpa"})
237 server:depends({mode="ap-wds", encryption="wpa2"})
238 server.rmempty = true
239
240 port = s:taboption("general", Value, "port", translate("Radius-Port"))
241 port:depends({mode="ap", encryption="wpa"})
242 port:depends({mode="ap", encryption="wpa2"})
243 port:depends({mode="ap-wds", encryption="wpa"})
244 port:depends({mode="ap-wds", encryption="wpa2"})
245 port.rmempty = true
246
247 key = s:taboption("general", Value, "key", translate("Password"))
248 key:depends("encryption", "wep")
249 key:depends("encryption", "psk")
250 key:depends("encryption", "psk2")
251 key:depends("encryption", "psk+psk2")
252 key:depends("encryption", "psk-mixed")
253 key:depends({mode="ap", encryption="wpa"})
254 key:depends({mode="ap", encryption="wpa2"})
255 key:depends({mode="ap-wds", encryption="wpa"})
256 key:depends({mode="ap-wds", encryption="wpa2"})
257 key.rmempty = true
258 key.password = true
259
260 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
261 nasid = s:taboption("general", Value, "nasid", translate("NAS ID"))
262 nasid:depends({mode="ap", encryption="wpa"})
263 nasid:depends({mode="ap", encryption="wpa2"})
264 nasid:depends({mode="ap-wds", encryption="wpa"})
265 nasid:depends({mode="ap-wds", encryption="wpa2"})
266 nasid.rmempty = true
267 end
268 return m